Index: llvm/trunk/include/llvm/BinaryFormat/ELF.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/ELF.h +++ llvm/trunk/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. Index: llvm/trunk/test/tools/llvm-readobj/note-gnu-property.s =================================================================== --- llvm/trunk/test/tools/llvm-readobj/note-gnu-property.s +++ llvm/trunk/test/tools/llvm-readobj/note-gnu-property.s @@ -0,0 +1,68 @@ +// 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 0x00000070: +// CHECK-NEXT: Owner Data size Description +// CHECK-NEXT: GNU 0x00000060 NT_GNU_PROPERTY_TYPE_0 (property note) +// CHECK-NEXT: Properties: stack size: 0x100 +// CHECK-NEXT: stack size: 0x100 +// CHECK-NEXT: no copy on protected +// CHECK-NEXT: +// CHECK-NEXT: stack size: +// CHECK-NEXT: stack size: +// CHECK-NEXT: no copy on protected +// CHECK-NEXT: + +.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 8 /* 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_STACK_SIZE with data size 4 (should be 8) */ + .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 */ + + /* 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: llvm/trunk/test/tools/llvm-readobj/note-gnu-property2.s =================================================================== --- llvm/trunk/test/tools/llvm-readobj/note-gnu-property2.s +++ llvm/trunk/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: + +// 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: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp @@ -3412,6 +3412,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) @@ -3476,8 +3477,35 @@ } template +static void printGNUProperty(raw_ostream &OS, uint32_t Type, uint32_t DataSize, + ArrayRef Data) { + switch (Type) { + default: + OS << format(" \n", Type); + return; + case GNU_PROPERTY_STACK_SIZE: { + OS << " stack size: "; + if (DataSize == sizeof(typename ELFT::uint)) + OS << format("0x%x\n", + (uint64_t)(*(const typename ELFT::Addr *)Data.data())); + else + OS << format("\n", DataSize); + break; + } + case GNU_PROPERTY_NO_COPY_ON_PROTECTED: + OS << " no copy on protected"; + if (DataSize) + OS << format(" ", DataSize); + OS << "\n"; + break; + } +} + +template static void printGNUNote(raw_ostream &OS, uint32_t NoteType, ArrayRef Words, size_t Size) { + using Elf_Word = typename ELFT::Word; + switch (NoteType) { default: return; @@ -3509,8 +3537,31 @@ OS << " Version: " << StringRef(reinterpret_cast(Words.data()), Size); break; - } + case ELF::NT_GNU_PROPERTY_TYPE_0: + OS << " Properties:"; + ArrayRef Arr(reinterpret_cast(Words.data()), + Size); + while (Arr.size() >= 8) { + uint32_t Type = *reinterpret_cast(Arr.data()); + uint32_t DataSize = *reinterpret_cast(Arr.data() + 4); + 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 << format(" \n", Type, + DataSize); + break; + } + printGNUProperty(OS, Type, DataSize, Arr.take_front(PaddedSize)); + Arr = Arr.drop_front(PaddedSize); + } + + if (!Arr.empty()) + OS << " "; + break; + } OS << '\n'; }