[llvm] 91c6174 - [RISCV] Allow llvm-objdump to disassemble objects with unrecognised versions of known extensions
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 26 20:40:06 PDT 2023
Author: Alex Bradbury
Date: 2023-03-27T04:38:16+01:00
New Revision: 91c6174ce35969d7f0d73c645fa47b813e0d99d3
URL: https://github.com/llvm/llvm-project/commit/91c6174ce35969d7f0d73c645fa47b813e0d99d3
DIFF: https://github.com/llvm/llvm-project/commit/91c6174ce35969d7f0d73c645fa47b813e0d99d3.diff
LOG: [RISCV] Allow llvm-objdump to disassemble objects with unrecognised versions of known extensions
This Moves ELFObjectFile to using
RISCVISAInfo::parseNormalizedArchString which is not an NFC, as the test
changes show. D144353 transitioned LLD to using this function, which is
specialised to parsing arch strings in the normalised format specified
in the psABI rather than user-authored strings accepted in `-march`,
which has greater flexibility.
parseNormalizedArchString does not ignore or produce an error for ISA
extensions with a version that isn't recognised/supported by LLVM. As
current GCC is marking its objects with a higher version of the A, F,
and D extensions than LLVM (see [extension versioning
discussion](https://discourse.llvm.org/t/rfc-resolving-issues-related-to-extension-versioning-in-risc-v/68472)
this massively improves the usability of llvm-objdump with such
binaries.
Differential Revision: https://reviews.llvm.org/D146114
Added:
Modified:
llvm/lib/Object/ELFObjectFile.cpp
llvm/test/tools/llvm-objdump/ELF/RISCV/riscv-attributes.s
Removed:
################################################################################
diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index b9343d646db61..8149df5ebbfa5 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -303,12 +303,7 @@ Expected<SubtargetFeatures> ELFObjectFileBase::getRISCVFeatures() const {
std::optional<StringRef> Attr =
Attributes.getAttributeString(RISCVAttrs::ARCH);
if (Attr) {
- // Suppress version checking for experimental extensions to prevent erroring
- // when getting any unknown version of experimental extension.
- auto ParseResult = RISCVISAInfo::parseArchString(
- *Attr, /*EnableExperimentalExtension=*/true,
- /*ExperimentalExtensionVersionCheck=*/false,
- /*IgnoreUnknown=*/true);
+ auto ParseResult = RISCVISAInfo::parseNormalizedArchString(*Attr);
if (!ParseResult)
return ParseResult.takeError();
auto &ISAInfo = *ParseResult;
diff --git a/llvm/test/tools/llvm-objdump/ELF/RISCV/riscv-attributes.s b/llvm/test/tools/llvm-objdump/ELF/RISCV/riscv-attributes.s
index 9cf324ca3b2df..5a47dea0b00dd 100644
--- a/llvm/test/tools/llvm-objdump/ELF/RISCV/riscv-attributes.s
+++ b/llvm/test/tools/llvm-objdump/ELF/RISCV/riscv-attributes.s
@@ -1,10 +1,10 @@
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+m,+f,+d,+v noncanonicalized_arch.s -o noncanonicalized_arch.o
-# RUN: llvm-objdump -d noncanonicalized_arch.o | FileCheck %s --check-prefix=NONCANON
+# RUN: not llvm-objdump -d noncanonicalized_arch.o 2>&1 | FileCheck %s -DFILE=noncanonicalized_arch.o --check-prefix=NONCANON
# RUN: llvm-mc -filetype=obj -triple=riscv64 invalid_arch.s -o invalid_arch.o
-# RUN: not llvm-objdump -d invalid_arch.o 2>&1 | FileCheck %s --check-prefix=INVALID
+# RUN: not llvm-objdump -d invalid_arch.o 2>&1 | FileCheck %s -DFILE=invalid_arch.o --check-prefix=INVALID
# RUN: llvm-mc -filetype=obj -triple=riscv32 unknown_i_version.s -o unknown_i_version.o
# RUN: llvm-objdump -d unknown_i_version.o 2>&1 | FileCheck %s --check-prefix=UNKNOWN-I-VERSION
@@ -16,7 +16,8 @@
# RUN: llvm-objdump -d unknown_ext_name.o 2>&1 | FileCheck %s --check-prefix=UNKNOWN-EXT-NAME
#--- noncanonicalized_arch.s
-# NONCANON: vsetvli a3, a2, e8, m8, tu, mu
+# NONCANON: error: '[[FILE]]': arch string must begin with valid base ISA
+# NONCANON-NOT: {{.}}
vsetvli a3, a2, e8, m8, tu, mu
.section .riscv.attributes,"", at 0x70000003
@@ -31,7 +32,8 @@ vsetvli a3, a2, e8, m8, tu, mu
.Lend:
#--- invalid_arch.s
-# INVALID: string must begin with rv32{i,e,g} or rv64{i,e,g}
+# INVALID: error: '[[FILE]]': arch string must begin with valid base ISA
+# INVALID-NOT: {{.}}
nop
.section .riscv.attributes,"", at 0x70000003
@@ -61,7 +63,7 @@ nop
.Lend:
#--- unknown_ext_version.s
-# UNKNOWN-EXT-VERSION: <unknown>
+# UNKNOWN-EXT-VERSION: cbo.clean (t0)
cbo.clean (t0)
.section .riscv.attributes,"", at 0x70000003
More information about the llvm-commits
mailing list