llvm.org GIT mirror llvm / 980b901
[llvm-readobj] Support GNU_PROPERTY_X86_FEATURE_1_AND notes in .note.gnu.property This patch allows parsing GNU_PROPERTY_X86_FEATURE_1_AND notes in .note.gnu.property sections. These notes indicate that the object file is built to support Intel CET. patch by mike.dvoretsky Differential Revision: https://reviews.llvm.org/D47473 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333424 91177308-0d34-0410-b5e6-96231b3b80d8 Alexander Ivchenko 2 years ago
3 changed file(s) with 74 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
13071307 enum {
13081308 GNU_PROPERTY_STACK_SIZE = 1,
13091309 GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
1310 GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002
1311 };
1312
1313 // CET properties
1314 enum {
1315 GNU_PROPERTY_X86_FEATURE_1_IBT = 1 << 0,
1316 GNU_PROPERTY_X86_FEATURE_1_SHSTK = 1 << 1
13101317 };
13111318
13121319 // AMDGPU specific notes.
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t
22 // RUN: llvm-readobj -elf-output-style GNU --notes %t | FileCheck %s
33
4 // CHECK: Displaying notes found at file offset 0x00000040 with length 0x00000070:
4 // CHECK: Displaying notes found at file offset 0x00000040 with length 0x000000b8:
55 // CHECK-NEXT: Owner Data size Description
6 // CHECK-NEXT: GNU 0x00000060 NT_GNU_PROPERTY_TYPE_0 (property note)
6 // CHECK-NEXT: GNU 0x000000a8 NT_GNU_PROPERTY_TYPE_0 (property note)
77 // CHECK-NEXT: Properties: stack size: 0x100
88 // CHECK-NEXT: stack size: 0x100
99 // CHECK-NEXT: no copy on protected
10 // CHECK-NEXT: X86 features: SHSTK
11 // CHECK-NEXT: X86 features: IBT, SHSTK
12 // CHECK-NEXT: X86 features: none
1013 // CHECK-NEXT:
1114 // CHECK-NEXT: stack size:
1215 // CHECK-NEXT: stack size:
1316 // CHECK-NEXT: no copy on protected
17 // CHECK-NEXT: X86 features:
18 // CHECK-NEXT: X86 features: IBT,
1419 // CHECK-NEXT:
1520
1621 .section ".note.gnu.property", "a"
2530 .long 8 /* Data size */
2631 .quad 0x100 /* Data (stack size) */
2732 .p2align 3 /* Align to 8 byte for 64 bit */
28
33
2934 /* Test we handle alignment properly */
3035 .long 1 /* Type: GNU_PROPERTY_STACK_SIZE */
3136 .long 8 /* Data size */
3439
3540 .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
3641 .long 0 /* Data size */
42 .p2align 3 /* Align to 8 byte for 64 bit */
43
44 /* CET property note */
45 .long 0xc0000002 /* Type: GNU_PROPERTY_X86_FEATURE_1_AND */
46 .long 8 /* Data size */
47 .quad 2 /* GNU_PROPERTY_X86_FEATURE_1_SHSTK */
48 .p2align 3 /* Align to 8 byte for 64 bit */
49
50 /* CET property note with padding */
51 .long 0xc0000002 /* Type: GNU_PROPERTY_X86_FEATURE_1_AND */
52 .long 4 /* Data size */
53 .long 3 /* Full CET support */
54 .p2align 3 /* Align to 8 byte for 64 bit */
55
56 .long 0xc0000002 /* Type: GNU_PROPERTY_X86_FEATURE_1_AND */
57 .long 8 /* Data size */
58 .quad 0 /* Empty flags, not an error */
3759 .p2align 3 /* Align to 8 byte for 64 bit */
3860
3961 /* All notes below are broken. Test we are able to report them. */
5981 .long 1 /* Data size (corrupted) */
6082 .byte 1 /* Data */
6183 .p2align 3 /* Align to 8 byte for 64 bit */
84
85 /* CET note with size zero */
86 .long 0xc0000002 /* Type: GNU_PROPERTY_X86_FEATURE_1_AND */
87 .long 0 /* Data size */
88 .p2align 3 /* Align to 8 byte for 64 bit */
89
90 /* CET note with bad flags */
91 .long 0xc0000002 /* Type: GNU_PROPERTY_X86_FEATURE_1_AND */
92 .long 8 /* Data size */
93 .quad 0xf000f000f000f001 /* GNU_PROPERTY_X86_FEATURE_1_IBT and bad bits */
94 .p2align 3 /* Align to 8 byte for 64 bit */
6295
6396 /* GNU_PROPERTY_NO_COPY_ON_PROTECTED with pr_datasz and without data */
6497 .long 2 /* Type: GNU_PROPERTY_NO_COPY_ON_PROTECTED */
34563456 case GNU_PROPERTY_STACK_SIZE: {
34573457 OS << " stack size: ";
34583458 if (DataSize == sizeof(typename ELFT::uint))
3459 OS << format("0x%x\n",
3459 OS << format("0x%lx\n",
34603460 (uint64_t)(*(const typename ELFT::Addr *)Data.data()));
34613461 else
34623462 OS << format("\n", DataSize);
34663466 OS << " no copy on protected";
34673467 if (DataSize)
34683468 OS << format(" ", DataSize);
3469 OS << "\n";
3470 break;
3471 case GNU_PROPERTY_X86_FEATURE_1_AND:
3472 OS << " X86 features: ";
3473 if (DataSize != 4 && DataSize != 8) {
3474 OS << format("\n", DataSize);
3475 break;
3476 }
3477 uint64_t CFProtection =
3478 (DataSize == 4)
3479 ? support::endian::read32(Data.data())
3480 : support::endian::read64(Data.data());
3481 if (CFProtection == 0) {
3482 OS << "none\n";
3483 break;
3484 }
3485 if (CFProtection & GNU_PROPERTY_X86_FEATURE_1_IBT) {
3486 OS << "IBT";
3487 CFProtection &= ~GNU_PROPERTY_X86_FEATURE_1_IBT;
3488 if (CFProtection)
3489 OS << ", ";
3490 }
3491 if (CFProtection & GNU_PROPERTY_X86_FEATURE_1_SHSTK) {
3492 OS << "SHSTK";
3493 CFProtection &= ~GNU_PROPERTY_X86_FEATURE_1_SHSTK;
3494 if (CFProtection)
3495 OS << ", ";
3496 }
3497 if (CFProtection)
3498 OS << format("", CFProtection);
34693499 OS << "\n";
34703500 break;
34713501 }