Add support for .note.gnu.property notes section (#386)
[pyelftools.git] / test / testfiles_for_readelf / note_gnu_property.S
1 /**
2 * Test ELF for .note.gnu.property, built on x86-64.
3 *
4 * Object file:
5 * gcc -c note_gnu_property.S -o note_gnu_property.o.elf
6 *
7 * ELF executable (to also have a PT_GNU_PROPERTY program header):
8 * gcc -DEXE -c note_gnu_property.S -o /tmp/x.o
9 * ld /tmp/x.o -o note_gnu_property.elf
10 * strip
11 */
12
13 // https://github.com/hjl-tools/linux-abi/wiki/linux-abi-draft.pdf
14 #define NT_GNU_PROPERTY_TYPE_0 5
15 #define GNU_PROPERTY_STACK_SIZE 1
16 #define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
17 #define GNU_PROPERTY_LOPROC 0xc0000000
18 #define GNU_PROPERTY_HIPROC 0xdfffffff
19 #define GNU_PROPERTY_LOUSER 0xe0000000
20 #define GNU_PROPERTY_HIUSER 0xffffffff
21
22 // Unknown property types for testing purposes
23 #define GNU_PROPERTY_TEST_UNKNOWN 0x12345678
24 #define GNU_PROPERTY_TEST_UNKNOWN_PROC 0xc1234567
25 #define GNU_PROPERTY_TEST_UNKNOWN_USER 0xe1234567
26
27 // https://gitlab.com/x86-psABIs/x86-64-ABI/-/wikis/x86-64-psABI
28 #define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002
29 #define GNU_PROPERTY_X86_FEATURE_1_IBT 0x00000001
30 #define GNU_PROPERTY_X86_FEATURE_1_SHSTK 0x00000002
31
32 #ifdef __x86_64__
33 #define ALIGN .p2align 3
34 #else
35 #define ALIGN .p2align 2
36 #endif
37
38 .section ".text"
39 .global _start
40 _start:
41 ud2
42
43 .section ".note.gnu.property", "a"
44 ALIGN
45 .long 1f - 0f // n_namesz
46 .long end - 2f // n_descsz
47 .long NT_GNU_PROPERTY_TYPE_0 // n_type
48 0: .asciz "GNU" // n_name
49 1:
50 ALIGN
51 2: .long GNU_PROPERTY_STACK_SIZE // pr_type
52 .long 4f - 3f // pr_datasz
53 3:
54 .dc.a 0x123000
55 4:
56 ALIGN
57 .long GNU_PROPERTY_NO_COPY_ON_PROTECTED // pr_type
58 .long 0 // pr_datasz
59 ALIGN
60
61 // Avoid these if linking to executable, linkers may not recognize them
62 #ifndef EXE
63 .long GNU_PROPERTY_TEST_UNKNOWN // pr_type
64 .long 6f-5f // pr_datasz
65 5:
66 .ascii "hello world"
67 6:
68 ALIGN
69 .long GNU_PROPERTY_TEST_UNKNOWN_PROC // pr_type
70 .long 8f-7f // pr_datasz
71 7:
72 .ascii "foobar"
73 8:
74 ALIGN
75 .long GNU_PROPERTY_TEST_UNKNOWN_USER // pr_type
76 .long 10f-9f // pr_datasz
77 9:
78 .ascii "bazquuz"
79 10:
80 ALIGN
81 #endif
82
83 /* TODO: add support for these later...
84 6: .long GNU_PROPERTY_X86_FEATURE_1_AND // pr_type.
85 .long 8f - 7f // pr_datasz
86 7:
87 .long GNU_PROPERTY_X86_FEATURE_1_IBT|GNU_PROPERTY_X86_FEATURE_1_SHSTK
88 8:
89 ALIGN
90 */
91 end: