Skip to content

Commit 8c37e3e

Browse files
authored
[RISCV] Only set Zca flag for EF_RISCV_RVC in ELFObjectFileBase::getRISCVFeatures(). (#80928)
This code appears to be a hack to set the features to include compressed instructions if the ELF EFLAGS flags bit is present, but the ELF attribute for the ISA string is no present or not accurate. We can't remove the hack because llvm-mc doesn't create ELF attributes by default so a lot of tests fail to disassembler properly. Using clang as the assembler does set the attributes. This patch changes the hack to only set Zca since that is the minimum implied by the flag. Setting anything else potentially conflicts with the ISA string containing Zcmp or Zcmt. JITLink also needs to be updated to recognize Zca in addition to C.
1 parent 934ba0d commit 8c37e3e

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

Diff for: llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ static RelaxAux initRelaxAux(LinkGraph &G) {
525525
RelaxAux Aux;
526526
Aux.Config.IsRV32 = G.getTargetTriple().isRISCV32();
527527
const auto &Features = G.getFeatures().getFeatures();
528-
Aux.Config.HasRVC = llvm::is_contained(Features, "+c");
528+
Aux.Config.HasRVC = llvm::is_contained(Features, "+c") ||
529+
llvm::is_contained(Features, "+zca");
529530

530531
for (auto &S : G.sections()) {
531532
if (!shouldRelax(S))

Diff for: llvm/lib/Object/ELFObjectFile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures() const {
292292
unsigned PlatformFlags = getPlatformFlags();
293293

294294
if (PlatformFlags & ELF::EF_RISCV_RVC) {
295-
Features.AddFeature("c");
295+
Features.AddFeature("zca");
296296
}
297297

298298
RISCVAttributeParser Attributes;

Diff for: llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_align_rvc.s

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
# RUN: -slab-allocate 100Kb -slab-address 0x0 -slab-page-size 4096 \
1111
# RUN: -check %s %t.rv64
1212

13+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax,+zca %s -o %t.rv32zca
14+
# RUN: llvm-jitlink -noexec \
15+
# RUN: -slab-allocate 100Kb -slab-address 0x0 -slab-page-size 4096 \
16+
# RUN: -check %s %t.rv32zca
17+
18+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax,+zca %s -o %t.rv64zca
19+
# RUN: llvm-jitlink -noexec \
20+
# RUN: -slab-allocate 100Kb -slab-address 0x0 -slab-page-size 4096 \
21+
# RUN: -check %s %t.rv64zca
22+
1323
.globl main,align2,align4,align8,align16,align32
1424
.type main,@function
1525
main:

Diff for: llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_boundary.s

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
1212
# RUN: -check %s %t.rv64
1313

14+
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax,+zca %s -o %t.rv32zca
15+
# RUN: llvm-jitlink -noexec \
16+
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
17+
# RUN: -check %s %t.rv32zca
18+
19+
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax,+zca %s -o %t.rv64zca
20+
# RUN: llvm-jitlink -noexec \
21+
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
22+
# RUN: -check %s %t.rv64zca
23+
1424
.globl main
1525
.type main,@function
1626
main:

Diff for: llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_rvc.s

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99
# RUN: -debug-only=jitlink -check %s -check-name=jitlink-check-rv32 %t.rv32 \
1010
# RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV32 %s
1111

12+
# RUN: llvm-mc -triple=riscv64 -mattr=+relax,+c -filetype=obj -o %t.rv64 %s
13+
# RUN: llvm-jitlink -noexec \
14+
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
15+
# RUN: -debug-only=jitlink -check %s %t.rv64 \
16+
# RUN: 2>&1 | FileCheck %s
17+
# RUN: llvm-jitlink -noexec \
18+
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
19+
# RUN: -debug-only=jitlink -check %s -check-name=jitlink-check-rv64 %t.rv64 \
20+
# RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV64 %s
21+
22+
# RUN: llvm-mc -triple=riscv32 -mattr=+relax,+zca -filetype=obj -o %t.rv32zca %s
23+
# RUN: llvm-jitlink -noexec \
24+
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
25+
# RUN: -debug-only=jitlink -check %s %t.rv32zca \
26+
# RUN: 2>&1 | FileCheck %s
27+
# RUN: llvm-jitlink -noexec \
28+
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
29+
# RUN: -debug-only=jitlink -check %s -check-name=jitlink-check-rv32 %t.rv32zca \
30+
# RUN: 2>&1 | FileCheck -check-prefix=CHECK-RV32 %s
31+
1232
# RUN: llvm-mc -triple=riscv64 -mattr=+relax,+c -filetype=obj -o %t.rv64 %s
1333
# RUN: llvm-jitlink -noexec \
1434
# RUN: -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \

0 commit comments

Comments
 (0)