[llvm] 8c37e3e - [RISCV] Only set Zca flag for EF_RISCV_RVC in ELFObjectFileBase::getRISCVFeatures(). (#80928)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 08:24:01 PST 2024


Author: Craig Topper
Date: 2024-02-07T08:23:57-08:00
New Revision: 8c37e3e64bb1432f771ec4d191837e6b3be5bf0c

URL: https://github.com/llvm/llvm-project/commit/8c37e3e64bb1432f771ec4d191837e6b3be5bf0c
DIFF: https://github.com/llvm/llvm-project/commit/8c37e3e64bb1432f771ec4d191837e6b3be5bf0c.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
    llvm/lib/Object/ELFObjectFile.cpp
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_align_rvc.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_boundary.s
    llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_rvc.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
index d0701ba08bd919..2fcdfcf9c0669e 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_riscv.cpp
@@ -525,7 +525,8 @@ static RelaxAux initRelaxAux(LinkGraph &G) {
   RelaxAux Aux;
   Aux.Config.IsRV32 = G.getTargetTriple().isRISCV32();
   const auto &Features = G.getFeatures().getFeatures();
-  Aux.Config.HasRVC = llvm::is_contained(Features, "+c");
+  Aux.Config.HasRVC = llvm::is_contained(Features, "+c") ||
+                      llvm::is_contained(Features, "+zca");
 
   for (auto &S : G.sections()) {
     if (!shouldRelax(S))

diff  --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index 8f7eead02a66c5..38a9e0e99b6b73 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -292,7 +292,7 @@ Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures() const {
   unsigned PlatformFlags = getPlatformFlags();
 
   if (PlatformFlags & ELF::EF_RISCV_RVC) {
-    Features.AddFeature("c");
+    Features.AddFeature("zca");
   }
 
   RISCVAttributeParser Attributes;

diff  --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_align_rvc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_align_rvc.s
index d022a8e573a1eb..14cc3eba6115d5 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_align_rvc.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_align_rvc.s
@@ -10,6 +10,16 @@
 # RUN:     -slab-allocate 100Kb -slab-address 0x0 -slab-page-size 4096 \
 # RUN:     -check %s %t.rv64
 
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax,+zca %s -o %t.rv32zca
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x0 -slab-page-size 4096 \
+# RUN:     -check %s %t.rv32zca
+
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax,+zca %s -o %t.rv64zca
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x0 -slab-page-size 4096 \
+# RUN:     -check %s %t.rv64zca
+
     .globl main,align2,align4,align8,align16,align32
     .type  main, at function
 main:

diff  --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_boundary.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_boundary.s
index 76dcee3921cdb0..b235c0b02fd413 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_boundary.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_boundary.s
@@ -11,6 +11,16 @@
 # RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
 # RUN:     -check %s %t.rv64
 
+# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax,+zca %s -o %t.rv32zca
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
+# RUN:     -check %s %t.rv32zca
+
+# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax,+zca %s -o %t.rv64zca
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
+# RUN:     -check %s %t.rv64zca
+
         .globl main
         .type main, at function
 main:

diff  --git a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_rvc.s b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_rvc.s
index 96ec4d40bcca72..e8a2928999f4ae 100644
--- a/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_rvc.s
+++ b/llvm/test/ExecutionEngine/JITLink/RISCV/ELF_relax_call_rvc.s
@@ -9,6 +9,26 @@
 # RUN:     -debug-only=jitlink -check %s -check-name=jitlink-check-rv32 %t.rv32 \
 # RUN:     2>&1 | FileCheck -check-prefix=CHECK-RV32 %s
 
+# RUN: llvm-mc -triple=riscv64 -mattr=+relax,+c -filetype=obj -o %t.rv64 %s
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
+# RUN:     -debug-only=jitlink -check %s %t.rv64 \
+# RUN:     2>&1 | FileCheck %s
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
+# RUN:     -debug-only=jitlink -check %s -check-name=jitlink-check-rv64 %t.rv64 \
+# RUN:     2>&1 | FileCheck -check-prefix=CHECK-RV64 %s
+
+# RUN: llvm-mc -triple=riscv32 -mattr=+relax,+zca -filetype=obj -o %t.rv32zca %s
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
+# RUN:     -debug-only=jitlink -check %s %t.rv32zca \
+# RUN:    2>&1 | FileCheck %s
+# RUN: llvm-jitlink -noexec \
+# RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \
+# RUN:     -debug-only=jitlink -check %s -check-name=jitlink-check-rv32 %t.rv32zca \
+# RUN:     2>&1 | FileCheck -check-prefix=CHECK-RV32 %s
+
 # RUN: llvm-mc -triple=riscv64 -mattr=+relax,+c -filetype=obj -o %t.rv64 %s
 # RUN: llvm-jitlink -noexec \
 # RUN:     -slab-allocate 100Kb -slab-address 0x1000 -slab-page-size 4096 \


        


More information about the llvm-commits mailing list