[llvm] [SPARC][Utilities] Add names for SPARC ELF flags in llvm-readobj (PR #102843)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 11 20:04:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Koakuma (koachan)
<details>
<summary>Changes</summary>
This allows us to print readable names in llvm-readobj output.
---
Full diff: https://github.com/llvm/llvm-project/pull/102843.diff
2 Files Affected:
- (added) llvm/test/MC/Sparc/elf-sparc-flags.s (+20)
- (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+18)
``````````diff
diff --git a/llvm/test/MC/Sparc/elf-sparc-flags.s b/llvm/test/MC/Sparc/elf-sparc-flags.s
new file mode 100644
index 00000000000000..f250aadfc61203
--- /dev/null
+++ b/llvm/test/MC/Sparc/elf-sparc-flags.s
@@ -0,0 +1,20 @@
+## Emit correct flags depending on triple, cpu, and memory model options.
+## - `-triple sparc` sets the flag field to 0x0
+## - `-triple sparc -mattr=+v8plus` adds an EF_SPARC_32PLUS (0x100)
+## - Currently, for sparc64 we always compile for TSO memory model, so
+## `-triple sparcv9` sets the memory model flag to EF_SPARCV9_TSO (0x0)
+## (i.e the last two bits have to be a zero).
+
+# RUN: llvm-mc -filetype=obj -triple sparc %s -o - | llvm-readobj -h - | FileCheck --check-prefixes=SPARC %s
+# RUN: llvm-mc -filetype=obj -triple sparc -mattr=+v8plus %s -o - | llvm-readobj -h - | FileCheck --check-prefixes=SPARC32PLUS %s
+# RUN: llvm-mc -filetype=obj -triple sparcv9 %s -o - | llvm-readobj -h - | FileCheck --check-prefixes=SPARCV9 %s
+
+# SPARC: Flags [ (0x0)
+# SPARC-NEXT: ]
+
+# SPARC32PLUS: Flags [ (0x100)
+# SPARC32PLUS-NEXT: EF_SPARC_32PLUS (0x100)
+# SPARC32PLUS-NEXT: ]
+
+# SPARCV9: Flags [ (0x0)
+# SPARCV9-NEXT: ]
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 1457ae8cb41733..3cc87e8b49fb2a 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1684,6 +1684,18 @@ const EnumEntry<unsigned> ElfHeaderRISCVFlags[] = {
ENUM_ENT(EF_RISCV_TSO, "TSO"),
};
+const EnumEntry<unsigned> ElfHeaderSPARCFlags[] = {
+ ENUM_ENT(EF_SPARC_EXT_MASK, "SPARC extension mask"),
+ ENUM_ENT(EF_SPARC_32PLUS, "V8+ ABI"),
+ ENUM_ENT(EF_SPARC_SUN_US1, "Sun UltraSPARC I extensions"),
+ ENUM_ENT(EF_SPARC_HAL_R1, "HAL/Fujitsu R1 extensions"),
+ ENUM_ENT(EF_SPARC_SUN_US3, "Sun UltraSPARC III extensions"),
+ ENUM_ENT(EF_SPARCV9_MM, "SPARC memory model mask"),
+ ENUM_ENT(EF_SPARCV9_TSO, "Total Store Ordering"),
+ ENUM_ENT(EF_SPARCV9_PSO, "Partial Store Ordering"),
+ ENUM_ENT(EF_SPARCV9_RMO, "Relaxed Memory Ordering"),
+};
+
const EnumEntry<unsigned> ElfHeaderAVRFlags[] = {
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR1),
LLVM_READOBJ_ENUM_ENT(ELF, EF_AVR_ARCH_AVR2),
@@ -3625,6 +3637,9 @@ template <class ELFT> void GNUELFDumper<ELFT>::printFileHeaders() {
unsigned(ELF::EF_MIPS_ABI), unsigned(ELF::EF_MIPS_MACH));
else if (e.e_machine == EM_RISCV)
ElfFlags = printFlags(e.e_flags, ArrayRef(ElfHeaderRISCVFlags));
+ else if (e.e_machine == EM_SPARC || e.e_machine == EM_SPARC32PLUS ||
+ e.e_machine == EM_SPARCV9)
+ ElfFlags = printFlags(e.e_flags, ArrayRef(ElfHeaderSPARCFlags));
else if (e.e_machine == EM_AVR)
ElfFlags = printFlags(e.e_flags, ArrayRef(ElfHeaderAVRFlags),
unsigned(ELF::EF_AVR_ARCH_MASK));
@@ -7117,6 +7132,9 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printFileHeaders() {
}
} else if (E.e_machine == EM_RISCV)
W.printFlags("Flags", E.e_flags, ArrayRef(ElfHeaderRISCVFlags));
+ else if (E.e_machine == EM_SPARC || E.e_machine == EM_SPARC32PLUS ||
+ E.e_machine == EM_SPARCV9)
+ W.printFlags("Flags", E.e_flags, ArrayRef(ElfHeaderSPARCFlags));
else if (E.e_machine == EM_AVR)
W.printFlags("Flags", E.e_flags, ArrayRef(ElfHeaderAVRFlags),
unsigned(ELF::EF_AVR_ARCH_MASK));
``````````
</details>
https://github.com/llvm/llvm-project/pull/102843
More information about the llvm-commits
mailing list