1 ## Check how we dump program headers and print sections to segments
2 ## mapping (llvm-readelf only) with -l, --program-headers and --segments options.
4 ## Check that -l, --program-headers and --segments are the same option.
6 ## Case A: test llvm-readelf tool.
7 # RUN: yaml2obj --docnum=1 -DBITS=32 -DMACHINE=EM_386 %s -o %t32.elf
8 # RUN: llvm-readelf -l %t32.elf 2>&1 > %t.readelf-l.txt
9 # RUN: llvm-readelf --program-headers %t32.elf 2>&1 > %t.readelf-pheaders.txt
10 # RUN: cmp %t.readelf-l.txt %t.readelf-pheaders.txt
11 # RUN: llvm-readelf --segments %t32.elf 2>&1 > %t.readelf-segments.txt
12 # RUN: cmp %t.readelf-l.txt %t.readelf-segments.txt
14 ## Case B: test llvm-readobj tool.
15 # RUN: llvm-readobj -l %t32.elf 2>&1 > %t.readobj-l.txt
16 # RUN: llvm-readobj --program-headers %t32.elf 2>&1 > %t.readobj-pheaders.txt
17 # RUN: cmp %t.readobj-l.txt %t.readobj-pheaders.txt
18 # RUN: llvm-readobj --segments %t32.elf 2>&1 > %t.readobj-segments.txt
19 # RUN: cmp %t.readobj-l.txt %t.readobj-segments.txt
21 ## Check we are able to print program headers of different types.
22 # RUN: FileCheck %s --check-prefixes=ELF32,MAPPING \
23 # RUN: --match-full-lines --strict-whitespace --input-file=%t.readelf-l.txt
24 # RUN: FileCheck %s --check-prefixes=ELF-LLVM,ELF32-LLVM \
25 # RUN: --match-full-lines --input-file=%t.readobj-l.txt
27 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t64.elf
28 # RUN: llvm-readelf -l %t64.elf | \
29 # RUN: FileCheck %s --check-prefixes=ELF64,MAPPING --strict-whitespace --match-full-lines
30 # RUN: llvm-readobj -l %t64.elf | FileCheck %s --check-prefixes=ELF-LLVM,ELF64-LLVM
32 # ELF32:There are 26 program headers, starting at offset 52
34 # ELF32-NEXT:Program Headers:
35 # ELF32-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
36 # ELF32-NEXT: PHDR 0x000374 0x00001000 0x00001000 0x00003 0x00003 W 0x1
37 # ELF32-NEXT: PHDR 0x000377 0x00002000 0x00002000 0x00007 0x00007 E 0x1
38 # ELF32-NEXT: NULL 0x000377 0x00002000 0x00002000 0x00007 0x00007 E 0x1
39 # ELF32-NEXT: DYNAMIC 0x000374 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1
40 # ELF32-NEXT: INTERP 0x00037e 0x00003000 0x00003000 0x00004 0x00004 RW 0x1
41 # ELF32-NEXT: [Requesting program interpreter: ABC]
42 # ELF32-NEXT: NOTE 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
43 # ELF32-NEXT: SHLIB 0x000374 0x00001000 0x00001000 0x00001 0x00001 0x1
44 # ELF32-NEXT: TLS 0x000382 0x00004000 0x00004000 0x00001 0x00001 0x1
45 # ELF32-NEXT: <unknown>: 0x60000000 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
46 # ELF32-NEXT: GNU_EH_FRAME 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
47 # ELF32-NEXT: SUNW_UNWIND 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
48 # ELF32-NEXT: GNU_STACK 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
49 # ELF32-NEXT: GNU_RELRO 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
50 # ELF32-NEXT: GNU_PROPERTY 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
51 # ELF32-NEXT: OPENBSD_MUTABLE 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
52 # ELF32-NEXT: OPENBSD_RANDOMIZE 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
53 # ELF32-NEXT: OPENBSD_WXNEEDED 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
54 # ELF32-NEXT: OPENBSD_NOBTCFI 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
55 # ELF32-NEXT: OPENBSD_SYSCALLS 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
56 # ELF32-NEXT: OPENBSD_BOOTDATA 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
57 # ELF32-NEXT: <unknown>: 0x6fffffff 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
58 # ELF32-NEXT: <unknown>: 0x70000000 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
59 # ELF32-NEXT: <unknown>: 0x70000001 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
60 # ELF32-NEXT: <unknown>: 0x70000002 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
61 # ELF32-NEXT: <unknown>: 0x70000003 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
62 # ELF32-NEXT: <unknown>: 0x7fffffff 0x000374 0x00001000 0x00001000 0x00003 0x00003 0x1
65 # ELF64:There are 26 program headers, starting at offset 64
67 # ELF64-NEXT:Program Headers:
68 # ELF64-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
69 # ELF64-NEXT: PHDR 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 W 0x1
70 # ELF64-NEXT: PHDR 0x0005f3 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1
71 # ELF64-NEXT: NULL 0x0005f3 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1
72 # ELF64-NEXT: DYNAMIC 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1
73 # ELF64-NEXT: INTERP 0x0005fa 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW 0x1
74 # ELF64-NEXT: [Requesting program interpreter: ABC]
75 # ELF64-NEXT: NOTE 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
76 # ELF64-NEXT: SHLIB 0x0005f0 0x0000000000001000 0x0000000000001000 0x000001 0x000001 0x1
77 # ELF64-NEXT: TLS 0x0005fe 0x0000000000004000 0x0000000000004000 0x000001 0x000001 0x1
78 # ELF64-NEXT: <unknown>: 0x60000000 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
79 # ELF64-NEXT: GNU_EH_FRAME 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
80 # ELF64-NEXT: SUNW_UNWIND 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
81 # ELF64-NEXT: GNU_STACK 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
82 # ELF64-NEXT: GNU_RELRO 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
83 # ELF64-NEXT: GNU_PROPERTY 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
84 # ELF64-NEXT: OPENBSD_MUTABLE 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
85 # ELF64-NEXT: OPENBSD_RANDOMIZE 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
86 # ELF64-NEXT: OPENBSD_WXNEEDED 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
87 # ELF64-NEXT: OPENBSD_NOBTCFI 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
88 # ELF64-NEXT: OPENBSD_SYSCALLS 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
89 # ELF64-NEXT: OPENBSD_BOOTDATA 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
90 # ELF64-NEXT: <unknown>: 0x6fffffff 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
91 # ELF64-NEXT: <unknown>: 0x70000000 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
92 # ELF64-NEXT: <unknown>: 0x70000001 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
93 # ELF64-NEXT: <unknown>: 0x70000002 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
94 # ELF64-NEXT: <unknown>: 0x70000003 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
95 # ELF64-NEXT: <unknown>: 0x7fffffff 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
98 # MAPPING: Section to Segment mapping:
99 # MAPPING-NEXT: Segment Sections...
100 # MAPPING-NEXT: 00 .foo.begin .foo.end {{$}}
101 # MAPPING-NEXT: 01 .bar.begin .bar.end {{$}}
102 # MAPPING-NEXT: 02 .bar.begin .bar.end {{$}}
103 # MAPPING-NEXT: 03 .foo.begin .foo.end {{$}}
104 # MAPPING-NEXT: 04 .interp {{$}}
105 # MAPPING-NEXT: 05 .foo.begin .foo.end {{$}}
106 # MAPPING-NEXT: 06 .foo.begin {{$}}
107 # MAPPING-NEXT: 07 .tls {{$}}
108 # MAPPING-NEXT: 08 .foo.begin .foo.end {{$}}
109 # MAPPING-NEXT: 09 .foo.begin .foo.end {{$}}
110 # MAPPING-NEXT: 10 .foo.begin .foo.end {{$}}
111 # MAPPING-NEXT: 11 .foo.begin .foo.end {{$}}
112 # MAPPING-NEXT: 12 .foo.begin .foo.end {{$}}
113 # MAPPING-NEXT: 13 .foo.begin .foo.end {{$}}
114 # MAPPING-NEXT: 14 .foo.begin .foo.end {{$}}
115 # MAPPING-NEXT: 15 .foo.begin .foo.end {{$}}
116 # MAPPING-NEXT: 16 .foo.begin .foo.end {{$}}
117 # MAPPING-NEXT: 17 .foo.begin .foo.end {{$}}
118 # MAPPING-NEXT: 18 .foo.begin .foo.end {{$}}
119 # MAPPING-NEXT: 19 .foo.begin .foo.end {{$}}
120 # MAPPING-NEXT: 20 .foo.begin .foo.end {{$}}
121 # MAPPING-NEXT: 21 .foo.begin .foo.end {{$}}
122 # MAPPING-NEXT: 22 .foo.begin .foo.end {{$}}
123 # MAPPING-NEXT: 23 .foo.begin .foo.end {{$}}
124 # MAPPING-NEXT: 24 .foo.begin .foo.end {{$}}
125 # MAPPING-NEXT: 25 .foo.begin .foo.end {{$}}
126 # MAPPING-NEXT: None .unused .strtab .shstrtab {{$}}
128 # ELF-LLVM: ProgramHeaders [
129 # ELF-LLVM-NEXT: ProgramHeader {
130 # ELF-LLVM-NEXT: Type: PT_PHDR (0x6)
131 # ELF32-LLVM-NEXT: Offset: 0x374
132 # ELF64-LLVM-NEXT: Offset: 0x5F0
133 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
134 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
135 # ELF-LLVM-NEXT: FileSize: 3
136 # ELF-LLVM-NEXT: MemSize: 3
137 # ELF-LLVM-NEXT: Flags [ (0x2)
138 # ELF-LLVM-NEXT: PF_W (0x2)
140 # ELF-LLVM-NEXT: Alignment: 1
142 # ELF-LLVM-NEXT: ProgramHeader {
143 # ELF-LLVM-NEXT: Type: PT_PHDR (0x6)
144 # ELF32-LLVM-NEXT: Offset: 0x377
145 # ELF64-LLVM-NEXT: Offset: 0x5F3
146 # ELF-LLVM-NEXT: VirtualAddress: 0x2000
147 # ELF-LLVM-NEXT: PhysicalAddress: 0x2000
148 # ELF-LLVM-NEXT: FileSize: 7
149 # ELF-LLVM-NEXT: MemSize: 7
150 # ELF-LLVM-NEXT: Flags [ (0x1)
151 # ELF-LLVM-NEXT: PF_X (0x1)
153 # ELF-LLVM-NEXT: Alignment: 1
155 # ELF-LLVM-NEXT: ProgramHeader {
156 # ELF-LLVM-NEXT: Type: PT_NULL (0x0)
157 # ELF32-LLVM-NEXT: Offset: 0x377
158 # ELF64-LLVM-NEXT: Offset: 0x5F3
159 # ELF-LLVM-NEXT: VirtualAddress: 0x2000
160 # ELF-LLVM-NEXT: PhysicalAddress: 0x2000
161 # ELF-LLVM-NEXT: FileSize: 7
162 # ELF-LLVM-NEXT: MemSize: 7
163 # ELF-LLVM-NEXT: Flags [ (0x1)
164 # ELF-LLVM-NEXT: PF_X (0x1)
166 # ELF-LLVM-NEXT: Alignment: 1
168 # ELF-LLVM-NEXT: ProgramHeader {
169 # ELF-LLVM-NEXT: Type: PT_DYNAMIC (0x2)
170 # ELF32-LLVM-NEXT: Offset: 0x374
171 # ELF64-LLVM-NEXT: Offset: 0x5F0
172 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
173 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
174 # ELF-LLVM-NEXT: FileSize: 3
175 # ELF-LLVM-NEXT: MemSize: 3
176 # ELF-LLVM-NEXT: Flags [ (0x7)
177 # ELF-LLVM-NEXT: PF_R (0x4)
178 # ELF-LLVM-NEXT: PF_W (0x2)
179 # ELF-LLVM-NEXT: PF_X (0x1)
181 # ELF-LLVM-NEXT: Alignment: 1
183 # ELF-LLVM-NEXT: ProgramHeader {
184 # ELF-LLVM-NEXT: Type: PT_INTERP (0x3)
185 # ELF32-LLVM-NEXT: Offset: 0x37E
186 # ELF64-LLVM-NEXT: Offset: 0x5FA
187 # ELF-LLVM-NEXT: VirtualAddress: 0x3000
188 # ELF-LLVM-NEXT: PhysicalAddress: 0x3000
189 # ELF-LLVM-NEXT: FileSize: 4
190 # ELF-LLVM-NEXT: MemSize: 4
191 # ELF-LLVM-NEXT: Flags [ (0x6)
192 # ELF-LLVM-NEXT: PF_R (0x4)
193 # ELF-LLVM-NEXT: PF_W (0x2)
195 # ELF-LLVM-NEXT: Alignment: 1
197 # ELF-LLVM-NEXT: ProgramHeader {
198 # ELF-LLVM-NEXT: Type: PT_NOTE (0x4)
199 # ELF32-LLVM-NEXT: Offset: 0x374
200 # ELF64-LLVM-NEXT: Offset: 0x5F0
201 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
202 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
203 # ELF-LLVM-NEXT: FileSize: 3
204 # ELF-LLVM-NEXT: MemSize: 3
205 # ELF-LLVM-NEXT: Flags [ (0x0)
207 # ELF-LLVM-NEXT: Alignment: 1
209 # ELF-LLVM-NEXT: ProgramHeader {
210 # ELF-LLVM-NEXT: Type: PT_SHLIB (0x5)
211 # ELF32-LLVM-NEXT: Offset: 0x374
212 # ELF64-LLVM-NEXT: Offset: 0x5F0
213 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
214 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
215 # ELF-LLVM-NEXT: FileSize: 1
216 # ELF-LLVM-NEXT: MemSize: 1
217 # ELF-LLVM-NEXT: Flags [ (0x0)
219 # ELF-LLVM-NEXT: Alignment: 1
221 # ELF-LLVM-NEXT: ProgramHeader {
222 # ELF-LLVM-NEXT: Type: PT_TLS (0x7)
223 # ELF32-LLVM-NEXT: Offset: 0x382
224 # ELF64-LLVM-NEXT: Offset: 0x5FE
225 # ELF-LLVM-NEXT: VirtualAddress: 0x4000
226 # ELF-LLVM-NEXT: PhysicalAddress: 0x4000
227 # ELF-LLVM-NEXT: FileSize: 1
228 # ELF-LLVM-NEXT: MemSize: 1
229 # ELF-LLVM-NEXT: Flags [ (0x0)
231 # ELF-LLVM-NEXT: Alignment: 1
233 # ELF-LLVM-NEXT: ProgramHeader {
234 # ELF-LLVM-NEXT: Type: Unknown (0x60000000)
235 # ELF32-LLVM-NEXT: Offset: 0x374
236 # ELF64-LLVM-NEXT: Offset: 0x5F0
237 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
238 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
239 # ELF-LLVM-NEXT: FileSize: 3
240 # ELF-LLVM-NEXT: MemSize: 3
241 # ELF-LLVM-NEXT: Flags [ (0x0)
243 # ELF-LLVM-NEXT: Alignment: 1
245 # ELF-LLVM-NEXT: ProgramHeader {
246 # ELF-LLVM-NEXT: Type: PT_GNU_EH_FRAME (0x6474E550)
247 # ELF32-LLVM-NEXT: Offset: 0x374
248 # ELF64-LLVM-NEXT: Offset: 0x5F0
249 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
250 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
251 # ELF-LLVM-NEXT: FileSize: 3
252 # ELF-LLVM-NEXT: MemSize: 3
253 # ELF-LLVM-NEXT: Flags [ (0x0)
255 # ELF-LLVM-NEXT: Alignment: 1
257 # ELF-LLVM-NEXT: ProgramHeader {
258 # ELF-LLVM-NEXT: Type: PT_SUNW_UNWIND (0x6464E550)
259 # ELF32-LLVM-NEXT: Offset: 0x374
260 # ELF64-LLVM-NEXT: Offset: 0x5F0
261 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
262 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
263 # ELF-LLVM-NEXT: FileSize: 3
264 # ELF-LLVM-NEXT: MemSize: 3
265 # ELF-LLVM-NEXT: Flags [ (0x0)
267 # ELF-LLVM-NEXT: Alignment: 1
269 # ELF-LLVM-NEXT: ProgramHeader {
270 # ELF-LLVM-NEXT: Type: PT_GNU_STACK (0x6474E551)
271 # ELF32-LLVM-NEXT: Offset: 0x374
272 # ELF64-LLVM-NEXT: Offset: 0x5F0
273 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
274 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
275 # ELF-LLVM-NEXT: FileSize: 3
276 # ELF-LLVM-NEXT: MemSize: 3
277 # ELF-LLVM-NEXT: Flags [ (0x0)
279 # ELF-LLVM-NEXT: Alignment: 1
281 # ELF-LLVM-NEXT: ProgramHeader {
282 # ELF-LLVM-NEXT: Type: PT_GNU_RELRO (0x6474E552)
283 # ELF32-LLVM-NEXT: Offset: 0x374
284 # ELF64-LLVM-NEXT: Offset: 0x5F0
285 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
286 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
287 # ELF-LLVM-NEXT: FileSize: 3
288 # ELF-LLVM-NEXT: MemSize: 3
289 # ELF-LLVM-NEXT: Flags [ (0x0)
291 # ELF-LLVM-NEXT: Alignment: 1
293 # ELF-LLVM-NEXT: ProgramHeader {
294 # ELF-LLVM-NEXT: Type: PT_GNU_PROPERTY (0x6474E553)
295 # ELF32-LLVM-NEXT: Offset: 0x374
296 # ELF64-LLVM-NEXT: Offset: 0x5F0
297 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
298 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
299 # ELF-LLVM-NEXT: FileSize: 3
300 # ELF-LLVM-NEXT: MemSize: 3
301 # ELF-LLVM-NEXT: Flags [ (0x0)
303 # ELF-LLVM-NEXT: Alignment: 1
305 # ELF-LLVM-NEXT: ProgramHeader {
306 # ELF-LLVM-NEXT: Type: PT_OPENBSD_MUTABLE (0x65A3DBE5)
307 # ELF32-LLVM-NEXT: Offset: 0x374
308 # ELF64-LLVM-NEXT: Offset: 0x5F0
309 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
310 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
311 # ELF-LLVM-NEXT: FileSize: 3
312 # ELF-LLVM-NEXT: MemSize: 3
313 # ELF-LLVM-NEXT: Flags [ (0x0)
315 # ELF-LLVM-NEXT: Alignment: 1
317 # ELF-LLVM-NEXT: ProgramHeader {
318 # ELF-LLVM-NEXT: Type: PT_OPENBSD_RANDOMIZE (0x65A3DBE6)
319 # ELF32-LLVM-NEXT: Offset: 0x374
320 # ELF64-LLVM-NEXT: Offset: 0x5F0
321 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
322 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
323 # ELF-LLVM-NEXT: FileSize: 3
324 # ELF-LLVM-NEXT: MemSize: 3
325 # ELF-LLVM-NEXT: Flags [ (0x0)
327 # ELF-LLVM-NEXT: Alignment: 1
329 # ELF-LLVM-NEXT: ProgramHeader {
330 # ELF-LLVM-NEXT: Type: PT_OPENBSD_WXNEEDED (0x65A3DBE7)
331 # ELF32-LLVM-NEXT: Offset: 0x374
332 # ELF64-LLVM-NEXT: Offset: 0x5F0
333 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
334 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
335 # ELF-LLVM-NEXT: FileSize: 3
336 # ELF-LLVM-NEXT: MemSize: 3
337 # ELF-LLVM-NEXT: Flags [ (0x0)
339 # ELF-LLVM-NEXT: Alignment: 1
341 # ELF-LLVM-NEXT: ProgramHeader {
342 # ELF-LLVM-NEXT: Type: PT_OPENBSD_NOBTCFI (0x65A3DBE8)
343 # ELF32-LLVM-NEXT: Offset: 0x374
344 # ELF64-LLVM-NEXT: Offset: 0x5F0
345 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
346 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
347 # ELF-LLVM-NEXT: FileSize: 3
348 # ELF-LLVM-NEXT: MemSize: 3
349 # ELF-LLVM-NEXT: Flags [ (0x0)
351 # ELF-LLVM-NEXT: Alignment: 1
353 # ELF-LLVM-NEXT: ProgramHeader {
354 # ELF-LLVM-NEXT: Type: PT_OPENBSD_SYSCALLS (0x65A3DBE9)
355 # ELF32-LLVM-NEXT: Offset: 0x374
356 # ELF64-LLVM-NEXT: Offset: 0x5F0
357 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
358 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
359 # ELF-LLVM-NEXT: FileSize: 3
360 # ELF-LLVM-NEXT: MemSize: 3
361 # ELF-LLVM-NEXT: Flags [ (0x0)
363 # ELF-LLVM-NEXT: Alignment: 1
365 # ELF-LLVM-NEXT: ProgramHeader {
366 # ELF-LLVM-NEXT: Type: PT_OPENBSD_BOOTDATA (0x65A41BE6)
367 # ELF32-LLVM-NEXT: Offset: 0x374
368 # ELF64-LLVM-NEXT: Offset: 0x5F0
369 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
370 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
371 # ELF-LLVM-NEXT: FileSize: 3
372 # ELF-LLVM-NEXT: MemSize: 3
373 # ELF-LLVM-NEXT: Flags [ (0x0)
375 # ELF-LLVM-NEXT: Alignment: 1
377 # ELF-LLVM-NEXT: ProgramHeader {
378 # ELF-LLVM-NEXT: Type: Unknown (0x6FFFFFFF)
379 # ELF32-LLVM-NEXT: Offset: 0x374
380 # ELF64-LLVM-NEXT: Offset: 0x5F0
381 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
382 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
383 # ELF-LLVM-NEXT: FileSize: 3
384 # ELF-LLVM-NEXT: MemSize: 3
385 # ELF-LLVM-NEXT: Flags [ (0x0)
387 # ELF-LLVM-NEXT: Alignment: 1
389 # ELF-LLVM-NEXT: ProgramHeader {
390 # ELF-LLVM-NEXT: Type: Unknown (0x70000000)
391 # ELF32-LLVM-NEXT: Offset: 0x374
392 # ELF64-LLVM-NEXT: Offset: 0x5F0
393 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
394 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
395 # ELF-LLVM-NEXT: FileSize: 3
396 # ELF-LLVM-NEXT: MemSize: 3
397 # ELF-LLVM-NEXT: Flags [ (0x0)
399 # ELF-LLVM-NEXT: Alignment: 1
401 # ELF-LLVM-NEXT: ProgramHeader {
402 # ELF-LLVM-NEXT: Type: Unknown (0x70000001)
403 # ELF32-LLVM-NEXT: Offset: 0x374
404 # ELF64-LLVM-NEXT: Offset: 0x5F0
405 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
406 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
407 # ELF-LLVM-NEXT: FileSize: 3
408 # ELF-LLVM-NEXT: MemSize: 3
409 # ELF-LLVM-NEXT: Flags [ (0x0)
411 # ELF-LLVM-NEXT: Alignment: 1
413 # ELF-LLVM-NEXT: ProgramHeader {
414 # ELF-LLVM-NEXT: Type: Unknown (0x70000002)
415 # ELF32-LLVM-NEXT: Offset: 0x374
416 # ELF64-LLVM-NEXT: Offset: 0x5F0
417 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
418 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
419 # ELF-LLVM-NEXT: FileSize: 3
420 # ELF-LLVM-NEXT: MemSize: 3
421 # ELF-LLVM-NEXT: Flags [ (0x0)
423 # ELF-LLVM-NEXT: Alignment: 1
425 # ELF-LLVM-NEXT: ProgramHeader {
426 # ELF-LLVM-NEXT: Type: Unknown (0x70000003)
427 # ELF32-LLVM-NEXT: Offset: 0x374
428 # ELF64-LLVM-NEXT: Offset: 0x5F0
429 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
430 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
431 # ELF-LLVM-NEXT: FileSize: 3
432 # ELF-LLVM-NEXT: MemSize: 3
433 # ELF-LLVM-NEXT: Flags [ (0x0)
435 # ELF-LLVM-NEXT: Alignment: 1
437 # ELF-LLVM-NEXT: ProgramHeader {
438 # ELF-LLVM-NEXT: Type: Unknown (0x7FFFFFFF)
439 # ELF32-LLVM-NEXT: Offset: 0x374
440 # ELF64-LLVM-NEXT: Offset: 0x5F0
441 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
442 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
443 # ELF-LLVM-NEXT: FileSize: 3
444 # ELF-LLVM-NEXT: MemSize: 3
445 # ELF-LLVM-NEXT: Flags [ (0x0)
447 # ELF-LLVM-NEXT: Alignment: 1
453 Class: ELFCLASS[[BITS]]
480 Content: "41424300" ## "ABC"
483 Flags: [ SHF_ALLOC, SHF_TLS ]
488 Flags: [ SHF_ALLOC, SHF_TLS ]
492 ## Case 1: an arbitrary segment with sections.
498 ## Case 2: another segment with different sections.
504 ## Case 3: the PT_NULL segment.
510 ## Case 4: the PT_DYNAMIC segment.
512 Flags: [ PF_R, PF_W, PF_X ]
516 ## Case 5: the PT_INTERP segment.
518 Flags: [ PF_R, PF_W ]
522 ## Case 6: the PT_NOTE segment.
527 ## Case 7: the PT_SHLIB segment.
532 ## Case 8: the PT_TLS segment.
537 ## Case 9: the PT_LOOS segment.
538 - Type: 0x60000000 ## PT_LOOS
542 ## Case 10: the PT_GNU_EH_FRAME segment.
543 - Type: PT_GNU_EH_FRAME
547 ## Case 11: the PT_SUNW_UNWIND segment.
548 - Type: 0x6464e550 ## PT_SUNW_UNWIND
552 ## Case 12: the PT_GNU_STACK segment.
557 ## Case 13: the PT_GNU_RELRO segment.
562 ## Case 14: the PT_GNU_PROPERTY segment.
563 - Type: PT_GNU_PROPERTY
567 ## Case 15: the PT_OPENBSD_MUTABLE segment.
568 - Type: 0x65a3dbe5 ## PT_OPENBSD_MUTABLE
572 ## Case 16: the PT_OPENBSD_RANDOMIZE segment.
573 - Type: 0x65a3dbe6 ## PT_OPENBSD_RANDOMIZE
577 ## Case 17: the PT_OPENBSD_WXNEEDED segment.
578 - Type: 0x65a3dbe7 ## PT_OPENBSD_WXNEEDED
582 ## Case 18: the PT_OPENBSD_NOBTCFI segment.
583 - Type: 0x65a3dbe8 ## PT_OPENBSD_NOBTCFI
587 ## Case 19: the PT_OPENBSD_SYSCALLS segment.
588 - Type: 0x65a3dbe9 ## PT_OPENBSD_SYSCALLS
592 ## Case 20: the PT_OPENBSD_BOOTDATA segment.
593 - Type: 0x65a41be6 ## PT_OPENBSD_BOOTDATA
597 ## Case 21: the PT_HIOS segment.
598 - Type: 0x6fffffff ## PT_HIOS
602 ## Case 22: the PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO segment.
603 - Type: 0x70000000 ## PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO
607 ## Case 23: the PT_ARM_EXIDX/PT_MIPS_RTPROC segment.
608 - Type: 0x70000001 ## PT_ARM_EXIDX, PT_MIPS_RTPROC
612 ## Case 24: the PT_MIPS_OPTIONS segment.
613 - Type: 0x70000002 ## PT_MIPS_OPTIONS
617 ## Case 25: the PT_MIPS_ABIFLAGS/PT_RISCV_ATTRIBUTES segment.
618 - Type: 0x70000003 ## PT_MIPS_ABIFLAGS/PT_RISCV_ATTRIBUTES
622 ## Case 26: the PT_HIPROC segment.
623 - Type: 0x7fffffff ## PT_HIPROC
628 ## Check how we dump ARM specific program headers.
629 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf
630 # RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-GNU
631 # RUN: llvm-readobj --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-LLVM
633 # ARM-GNU: <unknown>: 0x70000000 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
634 # ARM-GNU-NEXT: EXIDX 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
635 # ARM-GNU-NEXT: <unknown>: 0x70000002 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
637 # ARM-LLVM: ProgramHeader {
638 # ARM-LLVM: Type: Unknown (0x70000000)
639 # ARM-LLVM: ProgramHeader {
640 # ARM-LLVM-NEXT: Type: PT_ARM_EXIDX (0x70000001)
641 # ARM-LLVM: ProgramHeader {
642 # ARM-LLVM-NEXT: Type: Unknown (0x70000002)
644 ## Check how we dump MIPS specific program headers.
645 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf
646 # RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-GNU
647 # RUN: llvm-readobj --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-LLVM
649 # MIPS-GNU: REGINFO 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
650 # MIPS-GNU-NEXT: RTPROC 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
651 # MIPS-GNU-NEXT: OPTIONS 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
652 # MIPS-GNU-NEXT: ABIFLAGS 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
654 # MIPS-LLVM: ProgramHeader {
655 # MIPS-LLVM: Type: PT_MIPS_REGINFO (0x70000000)
656 # MIPS-LLVM: ProgramHeader {
657 # MIPS-LLVM-NEXT: Type: PT_MIPS_RTPROC (0x70000001)
658 # MIPS-LLVM: ProgramHeader {
659 # MIPS-LLVM-NEXT: Type: PT_MIPS_OPTIONS (0x70000002)
660 # MIPS-LLVM: ProgramHeader {
661 # MIPS-LLVM-NEXT: Type: PT_MIPS_ABIFLAGS (0x70000003)
663 ## CHECK how we dump RISCV specific program headers.
664 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_RISCV %s -o %triscv.elf
665 # RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-GNU
666 # RUN: llvm-readobj --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-LLVM
668 # RISCV-GNU: ATTRIBUTES 0x0005f0 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
669 # RISCV-LLVM: ProgramHeader {
670 # RISCV-LLVM: Type: PT_RISCV_ATTRIBUTES (0x70000003)
672 ## Check that llvm-readelf reports a warning when a program interpreter
673 ## name is non-null-terminated or when PT_INTERP has an offset that
674 ## goes past the end of the file.
675 # RUN: yaml2obj --docnum=2 %s -o %t.err
677 ## Show the size of the output produced. It is used in the YAML below.
678 # RUN: wc -c < %t.err | FileCheck %s --check-prefix=SIZE
681 ## Write the additional 'C', '\0, 'C' bytes to the end.
682 # RUN: echo -n -e "C\x00C" >> %t.err
684 # RUN: llvm-readelf --program-headers %t.err 2>&1 | \
685 # RUN: FileCheck %s -DFILE=%t.err --check-prefix=ERROR-INTERP --implicit-check-not=warning:
687 # ERROR-INTERP: Type Offset
688 # ERROR-INTERP-NEXT: INTERP 0x000[[#%x,OFFSET:0x268]]
689 # ERROR-INTERP-NEXT: [Requesting program interpreter: C]
690 # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 1]]
691 # ERROR-INTERP-NEXT: [Requesting program interpreter: ]
692 # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 2]]
693 # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+2]]: it is not null-terminated
694 # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 3]]
695 # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+3]]: it goes past the end of the file (0x[[#OFFSET + 3]])
696 # ERROR-INTERP-NEXT: INTERP 0xaabbccddeeff1122
697 # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0xaabbccddeeff1122: it goes past the end of the file (0x[[#OFFSET + 3]])
698 # ERROR-INTERP-NEXT: INTERP 0xaabbccddeeff1122
706 ## Case 1: the offset points to the first additional byte.
709 ## Case 1: the offset points to the second additional byte,
710 ## which is a null byte.
713 ## Case 3: the offset points to the third additional
714 ## byte, which is the last byte in the file.
717 ## Case 4: the offset goes 1 byte past the end of the file.
720 ## Case 5: an arbitrary large offset that goes past the end of the file.
722 Offset: 0xAABBCCDDEEFF1122
723 ## Case 6: the same as case 5. Used to demonstrate that we don't report
724 ## the same warning twice.
726 Offset: 0xAABBCCDDEEFF1122
728 ## Check we report a warning when we are unable to read program headers.
729 ## Case A: the e_phentsize field is invalid.
730 # RUN: yaml2obj --docnum=3 -DPHENTSIZE=1 %s -o %t.phdr.err
731 # RUN: llvm-readelf --program-headers %t.phdr.err 2>&1 | \
732 # RUN: FileCheck %s -DFILE=%t.phdr.err --check-prefix=WARN-PHENTSIZE-GNU
733 # RUN: llvm-readobj --program-headers %t.phdr.err 2>&1 | \
734 # RUN: FileCheck %s -DFILE=%t.phdr.err --check-prefix=WARN-PHENTSIZE-LLVM
736 # WARN-PHENTSIZE-GNU: Program Headers:
737 # WARN-PHENTSIZE-GNU-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
738 # WARN-PHENTSIZE-GNU-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
739 # WARN-PHENTSIZE-GNU: Section to Segment mapping:
740 # WARN-PHENTSIZE-GNU-NEXT: Segment Sections...
741 # WARN-PHENTSIZE-GNU-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: invalid e_phentsize: 1
743 # WARN-PHENTSIZE-LLVM: ProgramHeaders [
744 # WARN-PHENTSIZE-LLVM-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
745 # WARN-PHENTSIZE-LLVM-NEXT: ]
752 EPhEntSize: [[PHENTSIZE=<none>]]
753 EPhOff: [[PHOFF=<none>]]
762 ## Case B: the value of the e_phoff field is invalid.
764 ## Check that we do not report a warning when the program header table ends right before the end of the file.
765 ## 0x160 + size of headers (56) == file size.
766 # RUN: yaml2obj --docnum=3 -DPHOFF=0x160 %s -o %t.phdr.no.err2
767 # RUN: llvm-readelf %t.phdr.no.err2 --program-headers 2>&1 | FileCheck %s --implicit-check-not=warning:
768 # RUN: llvm-readobj %t.phdr.no.err2 --program-headers 2>&1 | FileCheck %s --implicit-check-not=warning:
770 ## Check we report a warning when e_phoff goes 1 byte past the end of the file.
771 # RUN: yaml2obj --docnum=3 -DPHOFF=0x161 %s -o %t.phdr.err2
772 # RUN: llvm-readelf --program-headers %t.phdr.err2 2>&1 | \
773 # RUN: FileCheck %s -DFILE=%t.phdr.err2 --check-prefix=WARN-PHOFF-GNU -DOFF=0x161
774 # RUN: llvm-readobj --program-headers %t.phdr.err2 2>&1 | \
775 # RUN: FileCheck %s -DFILE=%t.phdr.err2 --check-prefix=WARN-PHOFF-LLVM -DOFF=0x161
777 # WARN-PHOFF-GNU: Program Headers:
778 # WARN-PHOFF-GNU-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
779 # WARN-PHOFF-GNU-NEXT: warning: '[[FILE]]': unable to dump program headers: program headers are longer than binary of size 408: e_phoff = [[OFF]], e_phnum = 1, e_phentsize = 56
780 # WARN-PHOFF-GNU: Section to Segment mapping:
781 # WARN-PHOFF-GNU-NEXT: Segment Sections...
782 # WARN-PHOFF-GNU-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: program headers are longer than binary of size 408: e_phoff = [[OFF]], e_phnum = 1, e_phentsize = 56
784 # WARN-PHOFF-LLVM: ProgramHeaders [
785 # WARN-PHOFF-LLVM-NEXT: warning: '[[FILE]]': unable to dump program headers: program headers are longer than binary of size 408: e_phoff = [[OFF]], e_phnum = 1, e_phentsize = 56
786 # WARN-PHOFF-LLVM-NEXT: ]
788 ## Check we report a warning when the value of e_phoff is so large that
789 ## e_phoff + e_phnum * e_phentsize > UINT64_MAX.
790 # RUN: yaml2obj --docnum=3 -DPHOFF=0xffffffffffffffff %s -o %t.phdr.err3
791 # RUN: llvm-readelf --program-headers %t.phdr.err3 2>&1 | \
792 # RUN: FileCheck %s -DFILE=%t.phdr.err3 --check-prefix=WARN-PHOFF-GNU -DOFF=0xffffffffffffffff
793 # RUN: llvm-readobj --program-headers %t.phdr.err3 2>&1 | \
794 # RUN: FileCheck %s -DFILE=%t.phdr.err3 --check-prefix=WARN-PHOFF-LLVM -DOFF=0xffffffffffffffff