llvm.org GIT mirror llvm / a48ab92
[llvm-readobj] - Teach llvm-readobj to dump .note.gnu.property sections. NT_GNU_PROPERTY_TYPE_0 is a recently added type of .note.gnu.property section specified in Linux Extensions to gABI. (https://github.com/hjl-tools/linux-abi/wiki/Linux-Extensions-to-gABI) Patch teach tool to print such notes properly. Differential revision: https://reviews.llvm.org/D44469 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328078 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 2 years ago
4 changed file(s) with 150 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
14391439 NT_GNU_HWCAP = 2,
14401440 NT_GNU_BUILD_ID = 3,
14411441 NT_GNU_GOLD_VERSION = 4,
1442 NT_GNU_PROPERTY_TYPE_0 = 5,
1443 };
1444
1445 // Property types used in GNU_PROPERTY_TYPE_0 notes.
1446 enum {
1447 GNU_PROPERTY_STACK_SIZE = 1,
1448 GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
14421449 };
14431450
14441451 // AMDGPU specific notes.
0 // REQUIRES: x86-registered-target
1 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
2 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
3
4 // CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000070:
5 // CHECK-NEXT: Owner Data size Description
6 // CHECK-NEXT: GNU 0x00000060 NT_GNU_PROPERTY_TYPE_0 (property note)
7 // CHECK-NEXT: Properties: stack size: 0x100
8 // CHECK-NEXT: stack size: 0x100
9 // CHECK-NEXT: no copy on protected
10 // CHECK-NEXT:
11 // CHECK-NEXT: stack size:
12 // CHECK-NEXT: stack size:
13 // CHECK-NEXT: no copy on protected
14 // CHECK-NEXT:
15
16 .section ".note.gnu.property", "a"
17 .align 4
18 .long 4 /* Name length is always 4 ("GNU") */
19 .long end - begin /* Data length */
20 .long 5 /* Type: NT_GNU_PROPERTY_TYPE_0 */
21 .asciz "GNU" /* Name */
22 .p2align 3
23 begin:
24 .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
25 .long 8 /* Data size */
26 .quad 0x100 /* Data (stack size) */
27 .p2align 3 /* Align to 8 byte for 64 bit */
28
29 /* Test we handle alignment properly */
30 .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
31 .long 8 /* Data size */
32 .long 0x100 /* Data (stack size) */
33 .p2align 3 /* Align to 8 byte for 64 bit */
34
35 .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
36 .long 0 /* Data size */
37 .p2align 3 /* Align to 8 byte for 64 bit */
38
39 /* All notes below are broken. Test we are able to report them. */
40
41 /* Broken note type */
42 .long 0xfefefefe /* Invalid type for testing */
43 .long 0 /* Data size */
44 .p2align 3 /* Align to 8 byte for 64 bit */
45
46 /* GNU_PROPERTY_STACK_SIZE with zero stack size */
47 .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
48 .long 0 /* Data size */
49 .p2align 3 /* Align to 8 byte for 64 bit */
50
51 /* GNU_PROPERTY_STACK_SIZE with data size 4 (should be 8) */
52 .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
53 .long 4 /* Data size */
54 .long 0x100 /* Data (stack size) */
55 .p2align 3 /* Align to 8 byte for 64 bit */
56
57 /* GNU_PROPERTY_NO_COPY_ON_PROTECTED with pr_datasz and some data */
58 .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
59 .long 1 /* Data size (corrupted) */
60 .byte 1 /* Data */
61 .p2align 3 /* Align to 8 byte for 64 bit */
62
63 /* GNU_PROPERTY_NO_COPY_ON_PROTECTED with pr_datasz and without data */
64 .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
65 .long 1 /* Data size (corrupted) */
66 .p2align 3 /* Align to 8 byte for 64 bit */
67 end:
0 // REQUIRES: x86-registered-target
1 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
2 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
3
4 // CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000014:
5 // CHECK-NEXT: Owner Data size Description
6 // CHECK-NEXT: GNU 0x00000004 NT_GNU_PROPERTY_TYPE_0 (property note)
7 // CHECK-NEXT: Properties:
8 // CHECK-NEXT:
9
10 // Section below is broken, check we report that.
11
12 .section ".note.gnu.property", "a"
13 .align 4
14 .long 4 /* Name length is always 4 ("GNU") */
15 .long end - begin /* Data length */
16 .long 5 /* Type: NT_GNU_PROPERTY_TYPE_0 */
17 .asciz "GNU" /* Name */
18 .p2align 3
19 begin:
20 .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
21 end:
34113411 {ELF::NT_GNU_HWCAP, "NT_GNU_HWCAP (DSO-supplied software HWCAP info)"},
34123412 {ELF::NT_GNU_BUILD_ID, "NT_GNU_BUILD_ID (unique build ID bitstring)"},
34133413 {ELF::NT_GNU_GOLD_VERSION, "NT_GNU_GOLD_VERSION (gold version)"},
3414 {ELF::NT_GNU_PROPERTY_TYPE_0, "NT_GNU_PROPERTY_TYPE_0 (property note)"},
34143415 };
34153416
34163417 for (const auto &Note : Notes)
34753476 }
34763477
34773478 template
3479 static void printGNUProperty(raw_ostream &OS, uint32_t Type, uint32_t DataSize,
3480 ArrayRef Data) {
3481 switch (Type) {
3482 default:
3483 OS << format(" \n", Type);
3484 return;
3485 case GNU_PROPERTY_STACK_SIZE: {
3486 OS << " stack size: ";
3487 if (DataSize == sizeof(typename ELFT::uint))
3488 OS << format("0x%x\n",
3489 (uint64_t)(*(const typename ELFT::Addr *)Data.data()));
3490 else
3491 OS << format("\n", DataSize);
3492 break;
3493 }
3494 case GNU_PROPERTY_NO_COPY_ON_PROTECTED:
3495 OS << " no copy on protected";
3496 if (DataSize)
3497 OS << format(" ", DataSize);
3498 OS << "\n";
3499 break;
3500 }
3501 }
3502
3503 template
34783504 static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
34793505 ArrayRef Words, size_t Size) {
3506 using Elf_Word = typename ELFT::Word;
3507
34803508 switch (NoteType) {
34813509 default:
34823510 return;
35083536 OS << " Version: "
35093537 << StringRef(reinterpret_cast(Words.data()), Size);
35103538 break;
3511 }
3512
3539 case ELF::NT_GNU_PROPERTY_TYPE_0:
3540 OS << " Properties:";
3541
3542 ArrayRef Arr(reinterpret_cast(Words.data()),
3543 Size);
3544 while (Arr.size() >= 8) {
3545 uint32_t Type = *reinterpret_cast(Arr.data());
3546 uint32_t DataSize = *reinterpret_cast(Arr.data() + 4);
3547 Arr = Arr.drop_front(8);
3548
3549 // Take padding size into account if present.
3550 uint64_t PaddedSize = alignTo(DataSize, sizeof(typename ELFT::uint));
3551 if (Arr.size() < PaddedSize) {
3552 OS << format(" \n", Type,
3553 DataSize);
3554 break;
3555 }
3556 printGNUProperty(OS, Type, DataSize, Arr.take_front(PaddedSize));
3557 Arr = Arr.drop_front(PaddedSize);
3558 }
3559
3560 if (!Arr.empty())
3561 OS << " ";
3562 break;
3563 }
35133564 OS << '\n';
35143565 }
35153566