[PATCH] D44469: [llvm-readobj] - Teach llvm-readobj to dump .note.gnu.property sections.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 14 10:18:53 PDT 2018
Have these been found in the wild? If not I would probably wait until
someone wants to use them.
Cheers,
Rafael
George Rimar via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:
> grimar updated this revision to Diff 138390.
> grimar added a comment.
>
> - Fixed padding handling, added comments and test cases.
>
>
> https://reviews.llvm.org/D44469
>
> Files:
> include/llvm/BinaryFormat/ELF.h
> test/tools/llvm-readobj/note-gnu-property.s
> test/tools/llvm-readobj/note-gnu-property2.s
> tools/llvm-readobj/ELFDumper.cpp
>
> Index: tools/llvm-readobj/ELFDumper.cpp
> ===================================================================
> --- tools/llvm-readobj/ELFDumper.cpp
> +++ tools/llvm-readobj/ELFDumper.cpp
> @@ -2510,13 +2510,13 @@
>
> StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
> StringRef Signature = StrTable.data() + Sym->st_name;
> - Ret.push_back({Name,
> - Signature,
> - Sec.sh_name,
> + Ret.push_back({Name,
> + Signature,
> + Sec.sh_name,
> I - 1,
> Sec.sh_link,
> Sec.sh_info,
> - Data[0],
> + Data[0],
> {}});
>
> std::vector<GroupMember> &GM = Ret.back().Members;
> @@ -3411,6 +3411,7 @@
> {ELF::NT_GNU_HWCAP, "NT_GNU_HWCAP (DSO-supplied software HWCAP info)"},
> {ELF::NT_GNU_BUILD_ID, "NT_GNU_BUILD_ID (unique build ID bitstring)"},
> {ELF::NT_GNU_GOLD_VERSION, "NT_GNU_GOLD_VERSION (gold version)"},
> + {ELF::NT_GNU_PROPERTY_TYPE_0, "NT_GNU_PROPERTY_TYPE_0 (property note)"},
> };
>
> for (const auto &Note : Notes)
> @@ -3475,8 +3476,40 @@
> }
>
> template <typename ELFT>
> +static void printGNUProperty(raw_ostream &OS, uint32_t Type, uint32_t DataSize,
> + ArrayRef<uint8_t> Data) {
> + const endianness E = ELFT::TargetEndianness;
> +
> + switch (Type) {
> + default:
> + OS << format(" unknown property type: 0x%04x\n", Type);
> + return;
> + case GNU_PROPERTY_STACK_SIZE: {
> + OS << " stack size: ";
> + if (Data.size() >= sizeof(typename ELFT::uint)) {
> + uint64_t StackSize = ELFT::Is64Bits
> + ? support::endian::read64(Data.data(), E)
> + : support::endian::read32(Data.data(), E);
> + OS << format("0x%08x\n", StackSize);
> + } else {
> + OS << format("pr_datasz is corrupted (0x%08x) \n", DataSize);
> + }
> + break;
> + }
> + case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
> + OS << " no copy on protected";
> + if (DataSize)
> + OS << format(": pr_datasz (0x%08x) is corrupted", DataSize);
> + OS << "\n";
> + break;
> + }
> +}
> +
> +template <typename ELFT>
> static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
> ArrayRef<typename ELFT::Word> Words, size_t Size) {
> + const endianness E = ELFT::TargetEndianness;
> +
> switch (NoteType) {
> default:
> return;
> @@ -3508,8 +3541,30 @@
> OS << " Version: "
> << StringRef(reinterpret_cast<const char *>(Words.data()), Size);
> break;
> - }
> + case ELF::NT_GNU_PROPERTY_TYPE_0:
> + OS << " Properties:\n";
>
> + ArrayRef<uint8_t> Arr(reinterpret_cast<const uint8_t *>(Words.data()),
> + Size);
> + while (Arr.size() >= 8) {
> + uint32_t Type = support::endian::read32(Arr.data(), E);
> + uint32_t DataSize = support::endian::read32(Arr.data() + 4, E);
> + Arr = Arr.drop_front(8);
> +
> + // Take padding size into account if present.
> + uint64_t PaddedSize = alignTo(DataSize, sizeof(typename ELFT::uint));
> + if (Arr.size() < PaddedSize) {
> + OS << " <unexpected end of property declaration>";
> + break;
> + }
> + printGNUProperty<ELFT>(OS, Type, DataSize, Arr.take_front(PaddedSize));
> + Arr = Arr.drop_front(PaddedSize);
> + }
> +
> + if (!Arr.empty())
> + OS << " <corrupted GNU_PROPERTY_TYPE_0>";
> + break;
> + }
> OS << '\n';
> }
>
> Index: test/tools/llvm-readobj/note-gnu-property2.s
> ===================================================================
> --- test/tools/llvm-readobj/note-gnu-property2.s
> +++ test/tools/llvm-readobj/note-gnu-property2.s
> @@ -0,0 +1,22 @@
> +// REQUIRES: x86-registered-target
> +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
> +// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
> +
> +// CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000014:
> +// CHECK-NEXT: Owner Data size Description
> +// CHECK-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
> +// CHECK-NEXT: Properties:
> +// CHECK-NEXT: <corrupted GNU_PROPERTY_TYPE_0>
> +
> +// Section below is broken, check we report that.
> +
> +.section ".note.gnu.property", "a"
> +.align 4
> + .long 4 /* Name length is always 4 ("GNU") */
> + .long end - begin /* Data length */
> + .long 5 /* Type: NT_GNU_PROPERTY_TYPE_0 */
> + .asciz "GNU" /* Name */
> + .p2align 3
> +begin:
> + .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
> +end:
> Index: test/tools/llvm-readobj/note-gnu-property.s
> ===================================================================
> --- test/tools/llvm-readobj/note-gnu-property.s
> +++ test/tools/llvm-readobj/note-gnu-property.s
> @@ -0,0 +1,62 @@
> +// REQUIRES: x86-registered-target
> +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
> +// RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
> +
> +// CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000060:
> +// CHECK-NEXT: Owner Data size Description
> +// CHECK-NEXT: GNU 0x00000050 NT_GNU_PROPERTY_TYPE_0 (property note)
> +// CHECK-NEXT: Properties:
> +// CHECK-NEXT: stack size: 0x00000100
> +// CHECK-NEXT: stack size: 0x00000100
> +// CHECK-NEXT: no copy on protected
> +// CHECK-NEXT: unknown property type: 0xfefefefe
> +// CHECK-NEXT: stack size: pr_datasz is corrupted (0x00000000)
> +// CHECK-NEXT: no copy on protected: pr_datasz (0x00000001) is corrupted
> +// CHECK-NEXT: <unexpected end of property declaration>
> +
> +.section ".note.gnu.property", "a"
> +.align 4
> + .long 4 /* Name length is always 4 ("GNU") */
> + .long end - begin /* Data length */
> + .long 5 /* Type: NT_GNU_PROPERTY_TYPE_0 */
> + .asciz "GNU" /* Name */
> + .p2align 3
> +begin:
> + .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
> + .long 8 /* Data size */
> + .quad 0x100 /* Data (stack size) */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +
> + /* Test we handle alignment properly */
> + .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
> + .long 4 /* Data size */
> + .long 0x100 /* Data (stack size) */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +
> + .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
> + .long 0 /* Data size */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +
> + /* All notes below are broken. Test we are able to report them. */
> +
> + /* Broken note type */
> + .long 0xfefefefe /* Invalid type for testing */
> + .long 0 /* Data size */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +
> + /* GNU_PROPERTY_STACK_SIZE with zero stack size */
> + .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
> + .long 0 /* Data size */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +
> + /* GNU_PROPERTY_NO_COPY_ON_PROTECTED with pr_datasz and some data */
> + .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
> + .long 1 /* Data size (corrupted) */
> + .byte 1 /* Data */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +
> + /* GNU_PROPERTY_NO_COPY_ON_PROTECTED with pr_datasz and without data */
> + .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
> + .long 1 /* Data size (corrupted) */
> + .p2align 3 /* Align to 8 byte for 64 bit */
> +end:
> Index: include/llvm/BinaryFormat/ELF.h
> ===================================================================
> --- include/llvm/BinaryFormat/ELF.h
> +++ include/llvm/BinaryFormat/ELF.h
> @@ -1440,6 +1440,13 @@
> NT_GNU_HWCAP = 2,
> NT_GNU_BUILD_ID = 3,
> NT_GNU_GOLD_VERSION = 4,
> + NT_GNU_PROPERTY_TYPE_0 = 5,
> +};
> +
> +// Property types used in GNU_PROPERTY_TYPE_0 notes.
> +enum {
> + GNU_PROPERTY_STACK_SIZE = 1,
> + GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
> };
>
> // AMDGPU specific notes.
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list