[llvm] [llvm-readobj][ELF][RISCV] Dump .note.gnu.property section contents (PR #125642)
Ming-Yi Lai via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 6 01:34:41 PST 2025
https://github.com/mylai-mtk updated https://github.com/llvm/llvm-project/pull/125642
>From fcc7bc07f229d789ab49968a24147b181dcc7688 Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Fri, 24 Jan 2025 17:53:35 +0800
Subject: [PATCH 1/7] [llvm-readobj][ELF][RISCV] Dump .note.gnu.property
section contents
RISCV Zicfilp/Zicfiss extensions uses the `.note.gnu.property` section to store
flags indicating the adoption of features based on these extensions. This
patch enables the llvm-readobj/llvm-readelf tools to dump these flags with the
`--note` flag
---
llvm/include/llvm/BinaryFormat/ELF.h | 8 +++
...scv32-note-gnu-property-zicfilp-func-sig.s | 37 +++++++++++++
...cv32-note-gnu-property-zicfilp-unlabeled.s | 37 +++++++++++++
.../RISCV/riscv32-note-gnu-property-zicfiss.s | 37 +++++++++++++
...scv64-note-gnu-property-zicfilp-func-sig.s | 37 +++++++++++++
...cv64-note-gnu-property-zicfilp-unlabeled.s | 37 +++++++++++++
.../RISCV/riscv64-note-gnu-property-zicfiss.s | 37 +++++++++++++
llvm/tools/llvm-readobj/ELFDumper.cpp | 52 ++++++++++++++-----
8 files changed, 269 insertions(+), 13 deletions(-)
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 8853c4a88b0b593..37fb982bbef4323 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1798,6 +1798,7 @@ enum : unsigned {
GNU_PROPERTY_AARCH64_FEATURE_1_AND = 0xc0000000,
GNU_PROPERTY_AARCH64_FEATURE_PAUTH = 0xc0000001,
GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002,
+ GNU_PROPERTY_RISCV_FEATURE_1_AND = 0xc0000000,
GNU_PROPERTY_X86_UINT32_OR_LO = 0xc0008000,
GNU_PROPERTY_X86_FEATURE_2_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 1,
@@ -1862,6 +1863,13 @@ enum : unsigned {
GNU_PROPERTY_X86_ISA_1_V4 = 1 << 3,
};
+// riscv processor feature bits.
+enum : unsigned {
+ GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED = 1 << 0,
+ GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS = 1 << 1,
+ GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG = 1 << 2,
+};
+
// FreeBSD note types.
enum {
NT_FREEBSD_ABI_TAG = 1,
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s
new file mode 100644
index 000000000000000..1bd9856398dda63
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
+// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
+
+// GNU: Displaying notes found in: .note.gnu.property
+// GNU-NEXT: Owner Data size Description
+// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+// GNU-NEXT: Properties: riscv feature: ZICFILP-func-sig
+
+// LLVM: NoteSections [
+// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
+// LLVM-NEXT: Offset:
+// LLVM-NEXT: Size:
+// LLVM-NEXT: Notes [
+// LLVM-NEXT: {
+// LLVM-NEXT: Owner: GNU
+// LLVM-NEXT: Data size:
+// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+// LLVM-NEXT: Property [
+// LLVM-NEXT: riscv feature: ZICFILP-func-sig
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+
+.section ".note.gnu.property", "a"
+ .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
+ .long end - begin /* n_descsz */
+ .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU" /* n_name */
+begin:
+ .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
+ .long 4 /* pr_datasz */
+ .long 4 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG */
+ .p2align 2 /* pr_padding */
+end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s
new file mode 100644
index 000000000000000..adf893c5dba9d93
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
+// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
+
+// GNU: Displaying notes found in: .note.gnu.property
+// GNU-NEXT: Owner Data size Description
+// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+// GNU-NEXT: Properties: riscv feature: ZICFILP-unlabeled
+
+// LLVM: NoteSections [
+// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
+// LLVM-NEXT: Offset:
+// LLVM-NEXT: Size:
+// LLVM-NEXT: Notes [
+// LLVM-NEXT: {
+// LLVM-NEXT: Owner: GNU
+// LLVM-NEXT: Data size:
+// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+// LLVM-NEXT: Property [
+// LLVM-NEXT: riscv feature: ZICFILP-unlabeled
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+
+.section ".note.gnu.property", "a"
+ .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
+ .long end - begin /* n_descsz */
+ .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU" /* n_name */
+begin:
+ .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
+ .long 4 /* pr_datasz */
+ .long 1 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED */
+ .p2align 2 /* pr_padding */
+end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s
new file mode 100644
index 000000000000000..7ce06ba70daafde
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfiss %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
+// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfiss %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
+
+// GNU: Displaying notes found in: .note.gnu.property
+// GNU-NEXT: Owner Data size Description
+// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+// GNU-NEXT: Properties: riscv feature: ZICFISS
+
+// LLVM: NoteSections [
+// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
+// LLVM-NEXT: Offset:
+// LLVM-NEXT: Size:
+// LLVM-NEXT: Notes [
+// LLVM-NEXT: {
+// LLVM-NEXT: Owner: GNU
+// LLVM-NEXT: Data size:
+// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+// LLVM-NEXT: Property [
+// LLVM-NEXT: riscv feature: ZICFISS
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+
+.section ".note.gnu.property", "a"
+ .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
+ .long end - begin /* n_descsz */
+ .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU" /* n_name */
+begin:
+ .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
+ .long 4 /* pr_datasz */
+ .long 2 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS */
+ .p2align 2 /* pr_padding */
+end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s
new file mode 100644
index 000000000000000..b1a39fe35630e00
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
+// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
+
+// GNU: Displaying notes found in: .note.gnu.property
+// GNU-NEXT: Owner Data size Description
+// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+// GNU-NEXT: Properties: riscv feature: ZICFILP-func-sig
+
+// LLVM: NoteSections [
+// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
+// LLVM-NEXT: Offset:
+// LLVM-NEXT: Size:
+// LLVM-NEXT: Notes [
+// LLVM-NEXT: {
+// LLVM-NEXT: Owner: GNU
+// LLVM-NEXT: Data size:
+// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+// LLVM-NEXT: Property [
+// LLVM-NEXT: riscv feature: ZICFILP-func-sig
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+
+.section ".note.gnu.property", "a"
+ .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
+ .long end - begin /* n_descsz */
+ .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU" /* n_name */
+begin:
+ .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
+ .long 4 /* pr_datasz */
+ .long 4 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG */
+ .p2align 3 /* pr_padding */
+end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s
new file mode 100644
index 000000000000000..175eb08a152ff64
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
+// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
+
+// GNU: Displaying notes found in: .note.gnu.property
+// GNU-NEXT: Owner Data size Description
+// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+// GNU-NEXT: Properties: riscv feature: ZICFILP-unlabeled
+
+// LLVM: NoteSections [
+// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
+// LLVM-NEXT: Offset:
+// LLVM-NEXT: Size:
+// LLVM-NEXT: Notes [
+// LLVM-NEXT: {
+// LLVM-NEXT: Owner: GNU
+// LLVM-NEXT: Data size:
+// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+// LLVM-NEXT: Property [
+// LLVM-NEXT: riscv feature: ZICFILP-unlabeled
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+
+.section ".note.gnu.property", "a"
+ .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
+ .long end - begin /* n_descsz */
+ .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU" /* n_name */
+begin:
+ .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
+ .long 4 /* pr_datasz */
+ .long 1 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED */
+ .p2align 3 /* pr_padding */
+end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s
new file mode 100644
index 000000000000000..dc6d8d83e1ce000
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s
@@ -0,0 +1,37 @@
+// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
+// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
+
+// GNU: Displaying notes found in: .note.gnu.property
+// GNU-NEXT: Owner Data size Description
+// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+// GNU-NEXT: Properties: riscv feature: ZICFISS
+
+// LLVM: NoteSections [
+// LLVM-NEXT: NoteSection {
+// LLVM-NEXT: Name: .note.gnu.property
+// LLVM-NEXT: Offset:
+// LLVM-NEXT: Size:
+// LLVM-NEXT: Notes [
+// LLVM-NEXT: {
+// LLVM-NEXT: Owner: GNU
+// LLVM-NEXT: Data size:
+// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+// LLVM-NEXT: Property [
+// LLVM-NEXT: riscv feature: ZICFISS
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+// LLVM-NEXT: }
+// LLVM-NEXT: ]
+
+.section ".note.gnu.property", "a"
+ .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
+ .long end - begin /* n_descsz */
+ .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU" /* n_name */
+begin:
+ .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
+ .long 4 /* pr_datasz */
+ .long 2 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS */
+ .p2align 3 /* pr_padding */
+end:
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index bfca65aad52b443..c2e74c7c5e7797e 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5333,7 +5333,7 @@ static bool printAArch64PAuthABICoreInfo(raw_ostream &OS, uint32_t DataSize,
template <typename ELFT>
static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
- ArrayRef<uint8_t> Data) {
+ ArrayRef<uint8_t> Data, uint16_t Target) {
std::string str;
raw_string_ostream OS(str);
uint32_t PrData;
@@ -5366,8 +5366,24 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
return str;
case GNU_PROPERTY_AARCH64_FEATURE_1_AND:
case GNU_PROPERTY_X86_FEATURE_1_AND:
- OS << ((Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) ? "aarch64 feature: "
- : "x86 feature: ");
+ static_assert(GNU_PROPERTY_AARCH64_FEATURE_1_AND ==
+ GNU_PROPERTY_RISCV_FEATURE_1_AND,
+ "GNU_PROPERTY_RISCV_FEATURE_1_AND should equal "
+ "GNU_PROPERTY_AARCH64_FEATURE_1_AND, otherwise "
+ "GNU_PROPERTY_RISCV_FEATURE_1_AND would be skipped!");
+
+ if (Target == EM_AARCH64 && Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
+ OS << "aarch64 feature: ";
+ } else if (Target == EM_RISCV && Type == GNU_PROPERTY_RISCV_FEATURE_1_AND) {
+ OS << "riscv feature: ";
+ } else if ((Target == EM_386 || Target == EM_X86_64) &&
+ Type == GNU_PROPERTY_X86_FEATURE_1_AND) {
+ OS << "x86 feature: ";
+ } else {
+ OS << format("<application-specific type 0x%x>", Type);
+ return str;
+ }
+
if (DataSize != 4) {
OS << format("<corrupt length: 0x%x>", DataSize);
return str;
@@ -5377,14 +5393,20 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
OS << "<None>";
return str;
}
- if (Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
+
+ if (Target == EM_AARCH64) {
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_BTI, "BTI");
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_PAC, "PAC");
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_GCS, "GCS");
+ } else if (Target == EM_RISCV) {
+ DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED, "ZICFILP-unlabeled");
+ DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS, "ZICFISS");
+ DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG, "ZICFILP-func-sig");
} else {
DumpBit(GNU_PROPERTY_X86_FEATURE_1_IBT, "IBT");
DumpBit(GNU_PROPERTY_X86_FEATURE_1_SHSTK, "SHSTK");
}
+
if (PrData)
OS << format("<unknown flags: 0x%x>", PrData);
return str;
@@ -5441,7 +5463,8 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
}
template <typename ELFT>
-static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr) {
+static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr,
+ uint16_t Target) {
using Elf_Word = typename ELFT::Word;
SmallVector<std::string, 4> Properties;
@@ -5459,8 +5482,8 @@ static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr) {
Properties.push_back(str);
break;
}
- Properties.push_back(
- getGNUProperty<ELFT>(Type, DataSize, Arr.take_front(PaddedSize)));
+ Properties.push_back(getGNUProperty<ELFT>(
+ Type, DataSize, Arr.take_front(PaddedSize), Target));
Arr = Arr.drop_front(PaddedSize);
}
@@ -5512,7 +5535,7 @@ static StringRef getDescAsStringRef(ArrayRef<uint8_t> Desc) {
template <typename ELFT>
static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
- ArrayRef<uint8_t> Desc) {
+ ArrayRef<uint8_t> Desc, uint16_t Target) {
// Return true if we were able to pretty-print the note, false otherwise.
switch (NoteType) {
default:
@@ -5534,7 +5557,7 @@ static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
OS << " Properties:";
- for (const std::string &Property : getGNUPropertyList<ELFT>(Desc))
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, Target))
OS << " " << Property << "\n";
break;
}
@@ -6223,10 +6246,12 @@ template <class ELFT> void GNUELFDumper<ELFT>::printNotes() {
else
OS << "Unknown note type: (" << format_hex(Type, 10) << ")\n";
+ const uint16_t Target = this->Obj.getHeader().e_machine;
+
// Print the description, or fallback to printing raw bytes for unknown
// owners/if we fail to pretty-print the contents.
if (Name == "GNU") {
- if (printGNUNote<ELFT>(OS, Type, Descriptor))
+ if (printGNUNote<ELFT>(OS, Type, Descriptor, Target))
return Error::success();
} else if (Name == "FreeBSD") {
if (std::optional<FreeBSDNote> N =
@@ -7913,7 +7938,7 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printAddrsig() {
template <typename ELFT>
static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
- ScopedPrinter &W) {
+ ScopedPrinter &W, uint16_t Target) {
// Return true if we were able to pretty-print the note, false otherwise.
switch (NoteType) {
default:
@@ -7938,7 +7963,7 @@ static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
ListScope D(W, "Property");
- for (const std::string &Property : getGNUPropertyList<ELFT>(Desc))
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, Target))
W.printString(Property);
break;
}
@@ -8057,10 +8082,11 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printNotes() {
W.printString("Type",
"Unknown (" + to_string(format_hex(Type, 10)) + ")");
+ const uint16_t Target = this->Obj.getHeader().e_machine;
// Print the description, or fallback to printing raw bytes for unknown
// owners/if we fail to pretty-print the contents.
if (Name == "GNU") {
- if (printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W))
+ if (printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W, Target))
return Error::success();
} else if (Name == "FreeBSD") {
if (std::optional<FreeBSDNote> N =
>From 430a1526369bb36e55441c0795789349d7674376 Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Tue, 4 Feb 2025 14:28:11 +0800
Subject: [PATCH 2/7] fixup: clang-format
---
llvm/tools/llvm-readobj/ELFDumper.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index c2e74c7c5e7797e..6ea6677a8100d43 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5367,7 +5367,7 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
case GNU_PROPERTY_AARCH64_FEATURE_1_AND:
case GNU_PROPERTY_X86_FEATURE_1_AND:
static_assert(GNU_PROPERTY_AARCH64_FEATURE_1_AND ==
- GNU_PROPERTY_RISCV_FEATURE_1_AND,
+ GNU_PROPERTY_RISCV_FEATURE_1_AND,
"GNU_PROPERTY_RISCV_FEATURE_1_AND should equal "
"GNU_PROPERTY_AARCH64_FEATURE_1_AND, otherwise "
"GNU_PROPERTY_RISCV_FEATURE_1_AND would be skipped!");
@@ -5399,7 +5399,8 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_PAC, "PAC");
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_GCS, "GCS");
} else if (Target == EM_RISCV) {
- DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED, "ZICFILP-unlabeled");
+ DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED,
+ "ZICFILP-unlabeled");
DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS, "ZICFISS");
DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG, "ZICFILP-func-sig");
} else {
>From 402d59993925d6ee28b944bd00a957abd2d793f5 Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Thu, 6 Feb 2025 14:41:18 +0800
Subject: [PATCH 3/7] fixup: Merge tests into a single file
---
.../ELF/RISCV/note-gnu-property.yaml | 44 +++++++++++++++++++
...scv32-note-gnu-property-zicfilp-func-sig.s | 37 ----------------
...cv32-note-gnu-property-zicfilp-unlabeled.s | 37 ----------------
.../RISCV/riscv32-note-gnu-property-zicfiss.s | 37 ----------------
4 files changed, 44 insertions(+), 111 deletions(-)
create mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/note-gnu-property.yaml
delete mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s
delete mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s
delete mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/note-gnu-property.yaml b/llvm/test/tools/llvm-readobj/ELF/RISCV/note-gnu-property.yaml
new file mode 100644
index 000000000000000..10407b5c5b6e196
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/RISCV/note-gnu-property.yaml
@@ -0,0 +1,44 @@
+# RUN: yaml2obj --docnum=1 %s -DBITS=32 -DPR_PADDING= -o %t1
+# RUN: llvm-readelf --notes %t1 | FileCheck %s --check-prefix=GNU
+# RUN: llvm-readobj --notes %t1 | FileCheck %s --check-prefix=LLVM
+# RUN: yaml2obj --docnum=1 %s -DBITS=64 -DPR_PADDING=00000000 -o %t2
+# RUN: llvm-readelf --notes %t2 | FileCheck %s --check-prefix=GNU
+# RUN: llvm-readobj --notes %t2 | FileCheck %s --check-prefix=LLVM
+
+# GNU: Displaying notes found in: .note.gnu.property
+# GNU-NEXT: Owner Data size Description
+# GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
+# GNU-NEXT: Properties: riscv feature: ZICFILP-unlabeled, ZICFISS, ZICFILP-func-sig
+
+# LLVM: NoteSections [
+# LLVM-NEXT: NoteSection {
+# LLVM-NEXT: Name: .note.gnu.property
+# LLVM-NEXT: Offset:
+# LLVM-NEXT: Size:
+# LLVM-NEXT: Notes [
+# LLVM-NEXT: {
+# LLVM-NEXT: Owner: GNU
+# LLVM-NEXT: Data size:
+# LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
+# LLVM-NEXT: Property [
+# LLVM-NEXT: riscv feature: ZICFILP-unlabeled, ZICFISS, ZICFILP-func-sig
+# LLVM-NEXT: ]
+# LLVM-NEXT: }
+# LLVM-NEXT: ]
+# LLVM-NEXT: }
+# LLVM-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS[[BITS]]
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_RISCV
+Sections:
+ - Name: .note.gnu.property
+ Type: SHT_NOTE
+ Flags: [ SHF_ALLOC ]
+ Notes:
+ - Name: 'GNU'
+ Desc: '000000c00400000007000000[[PR_PADDING]]'
+ Type: 5 # NT_GNU_PROPERTY_TYPE_0
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s
deleted file mode 100644
index 1bd9856398dda63..000000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-func-sig.s
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
-// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
-
-// GNU: Displaying notes found in: .note.gnu.property
-// GNU-NEXT: Owner Data size Description
-// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
-// GNU-NEXT: Properties: riscv feature: ZICFILP-func-sig
-
-// LLVM: NoteSections [
-// LLVM-NEXT: NoteSection {
-// LLVM-NEXT: Name: .note.gnu.property
-// LLVM-NEXT: Offset:
-// LLVM-NEXT: Size:
-// LLVM-NEXT: Notes [
-// LLVM-NEXT: {
-// LLVM-NEXT: Owner: GNU
-// LLVM-NEXT: Data size:
-// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-// LLVM-NEXT: Property [
-// LLVM-NEXT: riscv feature: ZICFILP-func-sig
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-
-.section ".note.gnu.property", "a"
- .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
- .long end - begin /* n_descsz */
- .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
- .asciz "GNU" /* n_name */
-begin:
- .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
- .long 4 /* pr_datasz */
- .long 4 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG */
- .p2align 2 /* pr_padding */
-end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s
deleted file mode 100644
index adf893c5dba9d93..000000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfilp-unlabeled.s
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
-// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
-
-// GNU: Displaying notes found in: .note.gnu.property
-// GNU-NEXT: Owner Data size Description
-// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
-// GNU-NEXT: Properties: riscv feature: ZICFILP-unlabeled
-
-// LLVM: NoteSections [
-// LLVM-NEXT: NoteSection {
-// LLVM-NEXT: Name: .note.gnu.property
-// LLVM-NEXT: Offset:
-// LLVM-NEXT: Size:
-// LLVM-NEXT: Notes [
-// LLVM-NEXT: {
-// LLVM-NEXT: Owner: GNU
-// LLVM-NEXT: Data size:
-// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-// LLVM-NEXT: Property [
-// LLVM-NEXT: riscv feature: ZICFILP-unlabeled
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-
-.section ".note.gnu.property", "a"
- .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
- .long end - begin /* n_descsz */
- .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
- .asciz "GNU" /* n_name */
-begin:
- .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
- .long 4 /* pr_datasz */
- .long 1 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED */
- .p2align 2 /* pr_padding */
-end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s
deleted file mode 100644
index 7ce06ba70daafde..000000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv32-note-gnu-property-zicfiss.s
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfiss %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
-// RUN: llvm-mc -filetype=obj -triple riscv32-unknown-linux-gnu -mattr=+experimental-zicfiss %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
-
-// GNU: Displaying notes found in: .note.gnu.property
-// GNU-NEXT: Owner Data size Description
-// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
-// GNU-NEXT: Properties: riscv feature: ZICFISS
-
-// LLVM: NoteSections [
-// LLVM-NEXT: NoteSection {
-// LLVM-NEXT: Name: .note.gnu.property
-// LLVM-NEXT: Offset:
-// LLVM-NEXT: Size:
-// LLVM-NEXT: Notes [
-// LLVM-NEXT: {
-// LLVM-NEXT: Owner: GNU
-// LLVM-NEXT: Data size:
-// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-// LLVM-NEXT: Property [
-// LLVM-NEXT: riscv feature: ZICFISS
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-
-.section ".note.gnu.property", "a"
- .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
- .long end - begin /* n_descsz */
- .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
- .asciz "GNU" /* n_name */
-begin:
- .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
- .long 4 /* pr_datasz */
- .long 2 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS */
- .p2align 2 /* pr_padding */
-end:
>From c70ce16d1c8b88327a9ff6ee67c06a80cf7b9cc1 Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Thu, 6 Feb 2025 14:48:49 +0800
Subject: [PATCH 4/7] fixup: Change riscv to RISC-V in comment
---
llvm/include/llvm/BinaryFormat/ELF.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h
index 37fb982bbef4323..4b826bbf58f177d 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1863,7 +1863,7 @@ enum : unsigned {
GNU_PROPERTY_X86_ISA_1_V4 = 1 << 3,
};
-// riscv processor feature bits.
+// RISC-V processor feature bits.
enum : unsigned {
GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED = 1 << 0,
GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS = 1 << 1,
>From 0866bf16a7b89fa3b2ea9588e49d5623467f4936 Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Thu, 6 Feb 2025 14:59:27 +0800
Subject: [PATCH 5/7] fixup: Clarify `Target` is `e_machine`
---
llvm/tools/llvm-readobj/ELFDumper.cpp | 37 +++++++++++++++------------
1 file changed, 20 insertions(+), 17 deletions(-)
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 6ea6677a8100d43..d4fceaacd52b3bf 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5333,7 +5333,8 @@ static bool printAArch64PAuthABICoreInfo(raw_ostream &OS, uint32_t DataSize,
template <typename ELFT>
static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
- ArrayRef<uint8_t> Data, uint16_t Target) {
+ ArrayRef<uint8_t> Data,
+ typename ELFT::Half EMachine) {
std::string str;
raw_string_ostream OS(str);
uint32_t PrData;
@@ -5372,11 +5373,12 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
"GNU_PROPERTY_AARCH64_FEATURE_1_AND, otherwise "
"GNU_PROPERTY_RISCV_FEATURE_1_AND would be skipped!");
- if (Target == EM_AARCH64 && Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
+ if (EMachine == EM_AARCH64 && Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
OS << "aarch64 feature: ";
- } else if (Target == EM_RISCV && Type == GNU_PROPERTY_RISCV_FEATURE_1_AND) {
+ } else if (EMachine == EM_RISCV &&
+ Type == GNU_PROPERTY_RISCV_FEATURE_1_AND) {
OS << "riscv feature: ";
- } else if ((Target == EM_386 || Target == EM_X86_64) &&
+ } else if ((EMachine == EM_386 || EMachine == EM_X86_64) &&
Type == GNU_PROPERTY_X86_FEATURE_1_AND) {
OS << "x86 feature: ";
} else {
@@ -5394,11 +5396,11 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
return str;
}
- if (Target == EM_AARCH64) {
+ if (EMachine == EM_AARCH64) {
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_BTI, "BTI");
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_PAC, "PAC");
DumpBit(GNU_PROPERTY_AARCH64_FEATURE_1_GCS, "GCS");
- } else if (Target == EM_RISCV) {
+ } else if (EMachine == EM_RISCV) {
DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED,
"ZICFILP-unlabeled");
DumpBit(GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS, "ZICFISS");
@@ -5464,8 +5466,8 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
}
template <typename ELFT>
-static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr,
- uint16_t Target) {
+static SmallVector<std::string, 4>
+getGNUPropertyList(ArrayRef<uint8_t> Arr, typename ELFT::Half EMachine) {
using Elf_Word = typename ELFT::Word;
SmallVector<std::string, 4> Properties;
@@ -5484,7 +5486,7 @@ static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr,
break;
}
Properties.push_back(getGNUProperty<ELFT>(
- Type, DataSize, Arr.take_front(PaddedSize), Target));
+ Type, DataSize, Arr.take_front(PaddedSize), EMachine));
Arr = Arr.drop_front(PaddedSize);
}
@@ -5536,7 +5538,7 @@ static StringRef getDescAsStringRef(ArrayRef<uint8_t> Desc) {
template <typename ELFT>
static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
- ArrayRef<uint8_t> Desc, uint16_t Target) {
+ ArrayRef<uint8_t> Desc, typename ELFT::Half EMachine) {
// Return true if we were able to pretty-print the note, false otherwise.
switch (NoteType) {
default:
@@ -5558,7 +5560,7 @@ static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
OS << " Properties:";
- for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, Target))
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, EMachine))
OS << " " << Property << "\n";
break;
}
@@ -6247,12 +6249,12 @@ template <class ELFT> void GNUELFDumper<ELFT>::printNotes() {
else
OS << "Unknown note type: (" << format_hex(Type, 10) << ")\n";
- const uint16_t Target = this->Obj.getHeader().e_machine;
+ const typename ELFT::Half EMachine = this->Obj.getHeader().e_machine;
// Print the description, or fallback to printing raw bytes for unknown
// owners/if we fail to pretty-print the contents.
if (Name == "GNU") {
- if (printGNUNote<ELFT>(OS, Type, Descriptor, Target))
+ if (printGNUNote<ELFT>(OS, Type, Descriptor, EMachine))
return Error::success();
} else if (Name == "FreeBSD") {
if (std::optional<FreeBSDNote> N =
@@ -7939,7 +7941,8 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printAddrsig() {
template <typename ELFT>
static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
- ScopedPrinter &W, uint16_t Target) {
+ ScopedPrinter &W,
+ typename ELFT::Half EMachine) {
// Return true if we were able to pretty-print the note, false otherwise.
switch (NoteType) {
default:
@@ -7964,7 +7967,7 @@ static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
ListScope D(W, "Property");
- for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, Target))
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, EMachine))
W.printString(Property);
break;
}
@@ -8083,11 +8086,11 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printNotes() {
W.printString("Type",
"Unknown (" + to_string(format_hex(Type, 10)) + ")");
- const uint16_t Target = this->Obj.getHeader().e_machine;
+ const typename ELFT::Half EMachine = this->Obj.getHeader().e_machine;
// Print the description, or fallback to printing raw bytes for unknown
// owners/if we fail to pretty-print the contents.
if (Name == "GNU") {
- if (printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W, Target))
+ if (printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W, EMachine))
return Error::success();
} else if (Name == "FreeBSD") {
if (std::optional<FreeBSDNote> N =
>From b57ab5f8d46a5a99e02eddffab921623a39258a2 Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Thu, 6 Feb 2025 16:39:32 +0800
Subject: [PATCH 6/7] fixup: Remove redundant tests
---
...scv64-note-gnu-property-zicfilp-func-sig.s | 37 -------------------
...cv64-note-gnu-property-zicfilp-unlabeled.s | 37 -------------------
.../RISCV/riscv64-note-gnu-property-zicfiss.s | 37 -------------------
3 files changed, 111 deletions(-)
delete mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s
delete mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s
delete mode 100644 llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s
deleted file mode 100644
index b1a39fe35630e00..000000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-func-sig.s
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
-// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
-
-// GNU: Displaying notes found in: .note.gnu.property
-// GNU-NEXT: Owner Data size Description
-// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
-// GNU-NEXT: Properties: riscv feature: ZICFILP-func-sig
-
-// LLVM: NoteSections [
-// LLVM-NEXT: NoteSection {
-// LLVM-NEXT: Name: .note.gnu.property
-// LLVM-NEXT: Offset:
-// LLVM-NEXT: Size:
-// LLVM-NEXT: Notes [
-// LLVM-NEXT: {
-// LLVM-NEXT: Owner: GNU
-// LLVM-NEXT: Data size:
-// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-// LLVM-NEXT: Property [
-// LLVM-NEXT: riscv feature: ZICFILP-func-sig
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-
-.section ".note.gnu.property", "a"
- .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
- .long end - begin /* n_descsz */
- .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
- .asciz "GNU" /* n_name */
-begin:
- .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
- .long 4 /* pr_datasz */
- .long 4 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG */
- .p2align 3 /* pr_padding */
-end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s
deleted file mode 100644
index 175eb08a152ff64..000000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfilp-unlabeled.s
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
-// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
-
-// GNU: Displaying notes found in: .note.gnu.property
-// GNU-NEXT: Owner Data size Description
-// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
-// GNU-NEXT: Properties: riscv feature: ZICFILP-unlabeled
-
-// LLVM: NoteSections [
-// LLVM-NEXT: NoteSection {
-// LLVM-NEXT: Name: .note.gnu.property
-// LLVM-NEXT: Offset:
-// LLVM-NEXT: Size:
-// LLVM-NEXT: Notes [
-// LLVM-NEXT: {
-// LLVM-NEXT: Owner: GNU
-// LLVM-NEXT: Data size:
-// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-// LLVM-NEXT: Property [
-// LLVM-NEXT: riscv feature: ZICFILP-unlabeled
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-
-.section ".note.gnu.property", "a"
- .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
- .long end - begin /* n_descsz */
- .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
- .asciz "GNU" /* n_name */
-begin:
- .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
- .long 4 /* pr_datasz */
- .long 1 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED */
- .p2align 3 /* pr_padding */
-end:
diff --git a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s b/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s
deleted file mode 100644
index dc6d8d83e1ce000..000000000000000
--- a/llvm/test/tools/llvm-readobj/ELF/RISCV/riscv64-note-gnu-property-zicfiss.s
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readelf --notes - | FileCheck %s --check-prefix=GNU
-// RUN: llvm-mc -filetype=obj -triple riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp %s -o - | llvm-readobj --notes - | FileCheck %s --check-prefix=LLVM
-
-// GNU: Displaying notes found in: .note.gnu.property
-// GNU-NEXT: Owner Data size Description
-// GNU-NEXT: GNU 0x{{([0-9a-z]{8})}} NT_GNU_PROPERTY_TYPE_0 (property note)
-// GNU-NEXT: Properties: riscv feature: ZICFISS
-
-// LLVM: NoteSections [
-// LLVM-NEXT: NoteSection {
-// LLVM-NEXT: Name: .note.gnu.property
-// LLVM-NEXT: Offset:
-// LLVM-NEXT: Size:
-// LLVM-NEXT: Notes [
-// LLVM-NEXT: {
-// LLVM-NEXT: Owner: GNU
-// LLVM-NEXT: Data size:
-// LLVM-NEXT: Type: NT_GNU_PROPERTY_TYPE_0 (property note)
-// LLVM-NEXT: Property [
-// LLVM-NEXT: riscv feature: ZICFISS
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-// LLVM-NEXT: }
-// LLVM-NEXT: ]
-
-.section ".note.gnu.property", "a"
- .long 4 /* n_namsz: always 4 (sizeof("GNU")) */
- .long end - begin /* n_descsz */
- .long 5 /* n_type: NT_GNU_PROPERTY_TYPE_0 */
- .asciz "GNU" /* n_name */
-begin:
- .long 0xc0000000 /* pr_type: GNU_PROPERTY_RISCV_FEATURE_1_AND */
- .long 4 /* pr_datasz */
- .long 2 /* pr_data: GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS */
- .p2align 3 /* pr_padding */
-end:
>From 31484c90dabaf61f6ee73158985a4cf33e3f67ef Mon Sep 17 00:00:00 2001
From: Ming-Yi Lai <ming-yi.lai at mediatek.com>
Date: Thu, 6 Feb 2025 17:32:57 +0800
Subject: [PATCH 7/7] fixup: Drop extraneous new line
---
llvm/tools/llvm-readobj/ELFDumper.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index d4fceaacd52b3bf..d1496971d0ef55a 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5409,7 +5409,6 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
DumpBit(GNU_PROPERTY_X86_FEATURE_1_IBT, "IBT");
DumpBit(GNU_PROPERTY_X86_FEATURE_1_SHSTK, "SHSTK");
}
-
if (PrData)
OS << format("<unknown flags: 0x%x>", PrData);
return str;
More information about the llvm-commits
mailing list