[llvm] [RISCV] Only set Zca flag for EF_RISCV_RVC in ELFObjectFileBase::getR… (PR #80928)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 19:02:47 PST 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/80928
…ISCVFeatures().
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.
>From 4d2c94eb40b23d964c4ce5ef864e122f16d908b5 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 6 Feb 2024 18:56:14 -0800
Subject: [PATCH] [RISCV] Only set Zca flag for EF_RISCV_RVC in
ELFObjectFileBase::getRISCVFeatures().
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.
---
.../lib/ExecutionEngine/JITLink/ELF_riscv.cpp | 3 ++-
llvm/lib/Object/ELFObjectFile.cpp | 2 +-
.../JITLink/RISCV/ELF_relax_align_rvc.s | 10 ++++++++++
.../JITLink/RISCV/ELF_relax_call_boundary.s | 10 ++++++++++
.../JITLink/RISCV/ELF_relax_call_rvc.s | 20 +++++++++++++++++++
5 files changed, 43 insertions(+), 2 deletions(-)
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