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 25 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 0x000354 0x00001000 0x00001000 0x00003 0x00003 W 0x1
37 # ELF32-NEXT: PHDR 0x000357 0x00002000 0x00002000 0x00007 0x00007 E 0x1
38 # ELF32-NEXT: NULL 0x000357 0x00002000 0x00002000 0x00007 0x00007 E 0x1
39 # ELF32-NEXT: DYNAMIC 0x000354 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1
40 # ELF32-NEXT: INTERP 0x00035e 0x00003000 0x00003000 0x00004 0x00004 RW 0x1
41 # ELF32-NEXT: [Requesting program interpreter: ABC]
42 # ELF32-NEXT: NOTE 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
43 # ELF32-NEXT: SHLIB 0x000354 0x00001000 0x00001000 0x00001 0x00001 0x1
44 # ELF32-NEXT: TLS 0x000362 0x00004000 0x00004000 0x00001 0x00001 0x1
45 # ELF32-NEXT: <unknown>: 0x60000000 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
46 # ELF32-NEXT: GNU_EH_FRAME 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
47 # ELF32-NEXT: SUNW_UNWIND 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
48 # ELF32-NEXT: GNU_STACK 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
49 # ELF32-NEXT: GNU_RELRO 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
50 # ELF32-NEXT: GNU_PROPERTY 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
51 # ELF32-NEXT: OPENBSD_MUTABLE 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
52 # ELF32-NEXT: OPENBSD_RANDOMIZE 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
53 # ELF32-NEXT: OPENBSD_WXNEEDED 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
54 # ELF32-NEXT: OPENBSD_NOBTCFI 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
55 # ELF32-NEXT: OPENBSD_BOOTDATA 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
56 # ELF32-NEXT: <unknown>: 0x6fffffff 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
57 # ELF32-NEXT: <unknown>: 0x70000000 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
58 # ELF32-NEXT: <unknown>: 0x70000001 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
59 # ELF32-NEXT: <unknown>: 0x70000002 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
60 # ELF32-NEXT: <unknown>: 0x70000003 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
61 # ELF32-NEXT: <unknown>: 0x7fffffff 0x000354 0x00001000 0x00001000 0x00003 0x00003 0x1
64 # ELF64:There are 25 program headers, starting at offset 64
66 # ELF64-NEXT:Program Headers:
67 # ELF64-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
68 # ELF64-NEXT: PHDR 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 W 0x1
69 # ELF64-NEXT: PHDR 0x0005bb 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1
70 # ELF64-NEXT: NULL 0x0005bb 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1
71 # ELF64-NEXT: DYNAMIC 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1
72 # ELF64-NEXT: INTERP 0x0005c2 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW 0x1
73 # ELF64-NEXT: [Requesting program interpreter: ABC]
74 # ELF64-NEXT: NOTE 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
75 # ELF64-NEXT: SHLIB 0x0005b8 0x0000000000001000 0x0000000000001000 0x000001 0x000001 0x1
76 # ELF64-NEXT: TLS 0x0005c6 0x0000000000004000 0x0000000000004000 0x000001 0x000001 0x1
77 # ELF64-NEXT: <unknown>: 0x60000000 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
78 # ELF64-NEXT: GNU_EH_FRAME 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
79 # ELF64-NEXT: SUNW_UNWIND 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
80 # ELF64-NEXT: GNU_STACK 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
81 # ELF64-NEXT: GNU_RELRO 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
82 # ELF64-NEXT: GNU_PROPERTY 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
83 # ELF64-NEXT: OPENBSD_MUTABLE 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
84 # ELF64-NEXT: OPENBSD_RANDOMIZE 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
85 # ELF64-NEXT: OPENBSD_WXNEEDED 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
86 # ELF64-NEXT: OPENBSD_NOBTCFI 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
87 # ELF64-NEXT: OPENBSD_BOOTDATA 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
88 # ELF64-NEXT: <unknown>: 0x6fffffff 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
89 # ELF64-NEXT: <unknown>: 0x70000000 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
90 # ELF64-NEXT: <unknown>: 0x70000001 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
91 # ELF64-NEXT: <unknown>: 0x70000002 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
92 # ELF64-NEXT: <unknown>: 0x70000003 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
93 # ELF64-NEXT: <unknown>: 0x7fffffff 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
96 # MAPPING: Section to Segment mapping:
97 # MAPPING-NEXT: Segment Sections...
98 # MAPPING-NEXT: 00 .foo.begin .foo.end {{$}}
99 # MAPPING-NEXT: 01 .bar.begin .bar.end {{$}}
100 # MAPPING-NEXT: 02 .bar.begin .bar.end {{$}}
101 # MAPPING-NEXT: 03 .foo.begin .foo.end {{$}}
102 # MAPPING-NEXT: 04 .interp {{$}}
103 # MAPPING-NEXT: 05 .foo.begin .foo.end {{$}}
104 # MAPPING-NEXT: 06 .foo.begin {{$}}
105 # MAPPING-NEXT: 07 .tls {{$}}
106 # MAPPING-NEXT: 08 .foo.begin .foo.end {{$}}
107 # MAPPING-NEXT: 09 .foo.begin .foo.end {{$}}
108 # MAPPING-NEXT: 10 .foo.begin .foo.end {{$}}
109 # MAPPING-NEXT: 11 .foo.begin .foo.end {{$}}
110 # MAPPING-NEXT: 12 .foo.begin .foo.end {{$}}
111 # MAPPING-NEXT: 13 .foo.begin .foo.end {{$}}
112 # MAPPING-NEXT: 14 .foo.begin .foo.end {{$}}
113 # MAPPING-NEXT: 15 .foo.begin .foo.end {{$}}
114 # MAPPING-NEXT: 16 .foo.begin .foo.end {{$}}
115 # MAPPING-NEXT: 17 .foo.begin .foo.end {{$}}
116 # MAPPING-NEXT: 18 .foo.begin .foo.end {{$}}
117 # MAPPING-NEXT: 19 .foo.begin .foo.end {{$}}
118 # MAPPING-NEXT: 20 .foo.begin .foo.end {{$}}
119 # MAPPING-NEXT: 21 .foo.begin .foo.end {{$}}
120 # MAPPING-NEXT: 22 .foo.begin .foo.end {{$}}
121 # MAPPING-NEXT: 23 .foo.begin .foo.end {{$}}
122 # MAPPING-NEXT: 24 .foo.begin .foo.end {{$}}
123 # MAPPING-NEXT: None .unused .strtab .shstrtab {{$}}
125 # ELF-LLVM: ProgramHeaders [
126 # ELF-LLVM-NEXT: ProgramHeader {
127 # ELF-LLVM-NEXT: Type: PT_PHDR (0x6)
128 # ELF32-LLVM-NEXT: Offset: 0x354
129 # ELF64-LLVM-NEXT: Offset: 0x5B8
130 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
131 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
132 # ELF-LLVM-NEXT: FileSize: 3
133 # ELF-LLVM-NEXT: MemSize: 3
134 # ELF-LLVM-NEXT: Flags [ (0x2)
135 # ELF-LLVM-NEXT: PF_W (0x2)
137 # ELF-LLVM-NEXT: Alignment: 1
139 # ELF-LLVM-NEXT: ProgramHeader {
140 # ELF-LLVM-NEXT: Type: PT_PHDR (0x6)
141 # ELF32-LLVM-NEXT: Offset: 0x357
142 # ELF64-LLVM-NEXT: Offset: 0x5BB
143 # ELF-LLVM-NEXT: VirtualAddress: 0x2000
144 # ELF-LLVM-NEXT: PhysicalAddress: 0x2000
145 # ELF-LLVM-NEXT: FileSize: 7
146 # ELF-LLVM-NEXT: MemSize: 7
147 # ELF-LLVM-NEXT: Flags [ (0x1)
148 # ELF-LLVM-NEXT: PF_X (0x1)
150 # ELF-LLVM-NEXT: Alignment: 1
152 # ELF-LLVM-NEXT: ProgramHeader {
153 # ELF-LLVM-NEXT: Type: PT_NULL (0x0)
154 # ELF32-LLVM-NEXT: Offset: 0x357
155 # ELF64-LLVM-NEXT: Offset: 0x5BB
156 # ELF-LLVM-NEXT: VirtualAddress: 0x2000
157 # ELF-LLVM-NEXT: PhysicalAddress: 0x2000
158 # ELF-LLVM-NEXT: FileSize: 7
159 # ELF-LLVM-NEXT: MemSize: 7
160 # ELF-LLVM-NEXT: Flags [ (0x1)
161 # ELF-LLVM-NEXT: PF_X (0x1)
163 # ELF-LLVM-NEXT: Alignment: 1
165 # ELF-LLVM-NEXT: ProgramHeader {
166 # ELF-LLVM-NEXT: Type: PT_DYNAMIC (0x2)
167 # ELF32-LLVM-NEXT: Offset: 0x354
168 # ELF64-LLVM-NEXT: Offset: 0x5B8
169 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
170 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
171 # ELF-LLVM-NEXT: FileSize: 3
172 # ELF-LLVM-NEXT: MemSize: 3
173 # ELF-LLVM-NEXT: Flags [ (0x7)
174 # ELF-LLVM-NEXT: PF_R (0x4)
175 # ELF-LLVM-NEXT: PF_W (0x2)
176 # ELF-LLVM-NEXT: PF_X (0x1)
178 # ELF-LLVM-NEXT: Alignment: 1
180 # ELF-LLVM-NEXT: ProgramHeader {
181 # ELF-LLVM-NEXT: Type: PT_INTERP (0x3)
182 # ELF32-LLVM-NEXT: Offset: 0x35E
183 # ELF64-LLVM-NEXT: Offset: 0x5C2
184 # ELF-LLVM-NEXT: VirtualAddress: 0x3000
185 # ELF-LLVM-NEXT: PhysicalAddress: 0x3000
186 # ELF-LLVM-NEXT: FileSize: 4
187 # ELF-LLVM-NEXT: MemSize: 4
188 # ELF-LLVM-NEXT: Flags [ (0x6)
189 # ELF-LLVM-NEXT: PF_R (0x4)
190 # ELF-LLVM-NEXT: PF_W (0x2)
192 # ELF-LLVM-NEXT: Alignment: 1
194 # ELF-LLVM-NEXT: ProgramHeader {
195 # ELF-LLVM-NEXT: Type: PT_NOTE (0x4)
196 # ELF32-LLVM-NEXT: Offset: 0x354
197 # ELF64-LLVM-NEXT: Offset: 0x5B8
198 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
199 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
200 # ELF-LLVM-NEXT: FileSize: 3
201 # ELF-LLVM-NEXT: MemSize: 3
202 # ELF-LLVM-NEXT: Flags [ (0x0)
204 # ELF-LLVM-NEXT: Alignment: 1
206 # ELF-LLVM-NEXT: ProgramHeader {
207 # ELF-LLVM-NEXT: Type: PT_SHLIB (0x5)
208 # ELF32-LLVM-NEXT: Offset: 0x354
209 # ELF64-LLVM-NEXT: Offset: 0x5B8
210 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
211 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
212 # ELF-LLVM-NEXT: FileSize: 1
213 # ELF-LLVM-NEXT: MemSize: 1
214 # ELF-LLVM-NEXT: Flags [ (0x0)
216 # ELF-LLVM-NEXT: Alignment: 1
218 # ELF-LLVM-NEXT: ProgramHeader {
219 # ELF-LLVM-NEXT: Type: PT_TLS (0x7)
220 # ELF32-LLVM-NEXT: Offset: 0x362
221 # ELF64-LLVM-NEXT: Offset: 0x5C6
222 # ELF-LLVM-NEXT: VirtualAddress: 0x4000
223 # ELF-LLVM-NEXT: PhysicalAddress: 0x4000
224 # ELF-LLVM-NEXT: FileSize: 1
225 # ELF-LLVM-NEXT: MemSize: 1
226 # ELF-LLVM-NEXT: Flags [ (0x0)
228 # ELF-LLVM-NEXT: Alignment: 1
230 # ELF-LLVM-NEXT: ProgramHeader {
231 # ELF-LLVM-NEXT: Type: Unknown (0x60000000)
232 # ELF32-LLVM-NEXT: Offset: 0x354
233 # ELF64-LLVM-NEXT: Offset: 0x5B8
234 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
235 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
236 # ELF-LLVM-NEXT: FileSize: 3
237 # ELF-LLVM-NEXT: MemSize: 3
238 # ELF-LLVM-NEXT: Flags [ (0x0)
240 # ELF-LLVM-NEXT: Alignment: 1
242 # ELF-LLVM-NEXT: ProgramHeader {
243 # ELF-LLVM-NEXT: Type: PT_GNU_EH_FRAME (0x6474E550)
244 # ELF32-LLVM-NEXT: Offset: 0x354
245 # ELF64-LLVM-NEXT: Offset: 0x5B8
246 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
247 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
248 # ELF-LLVM-NEXT: FileSize: 3
249 # ELF-LLVM-NEXT: MemSize: 3
250 # ELF-LLVM-NEXT: Flags [ (0x0)
252 # ELF-LLVM-NEXT: Alignment: 1
254 # ELF-LLVM-NEXT: ProgramHeader {
255 # ELF-LLVM-NEXT: Type: PT_SUNW_UNWIND (0x6464E550)
256 # ELF32-LLVM-NEXT: Offset: 0x354
257 # ELF64-LLVM-NEXT: Offset: 0x5B8
258 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
259 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
260 # ELF-LLVM-NEXT: FileSize: 3
261 # ELF-LLVM-NEXT: MemSize: 3
262 # ELF-LLVM-NEXT: Flags [ (0x0)
264 # ELF-LLVM-NEXT: Alignment: 1
266 # ELF-LLVM-NEXT: ProgramHeader {
267 # ELF-LLVM-NEXT: Type: PT_GNU_STACK (0x6474E551)
268 # ELF32-LLVM-NEXT: Offset: 0x354
269 # ELF64-LLVM-NEXT: Offset: 0x5B8
270 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
271 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
272 # ELF-LLVM-NEXT: FileSize: 3
273 # ELF-LLVM-NEXT: MemSize: 3
274 # ELF-LLVM-NEXT: Flags [ (0x0)
276 # ELF-LLVM-NEXT: Alignment: 1
278 # ELF-LLVM-NEXT: ProgramHeader {
279 # ELF-LLVM-NEXT: Type: PT_GNU_RELRO (0x6474E552)
280 # ELF32-LLVM-NEXT: Offset: 0x354
281 # ELF64-LLVM-NEXT: Offset: 0x5B8
282 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
283 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
284 # ELF-LLVM-NEXT: FileSize: 3
285 # ELF-LLVM-NEXT: MemSize: 3
286 # ELF-LLVM-NEXT: Flags [ (0x0)
288 # ELF-LLVM-NEXT: Alignment: 1
290 # ELF-LLVM-NEXT: ProgramHeader {
291 # ELF-LLVM-NEXT: Type: PT_GNU_PROPERTY (0x6474E553)
292 # ELF32-LLVM-NEXT: Offset: 0x354
293 # ELF64-LLVM-NEXT: Offset: 0x5B8
294 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
295 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
296 # ELF-LLVM-NEXT: FileSize: 3
297 # ELF-LLVM-NEXT: MemSize: 3
298 # ELF-LLVM-NEXT: Flags [ (0x0)
300 # ELF-LLVM-NEXT: Alignment: 1
302 # ELF-LLVM-NEXT: ProgramHeader {
303 # ELF-LLVM-NEXT: Type: PT_OPENBSD_MUTABLE (0x65A3DBE5)
304 # ELF32-LLVM-NEXT: Offset: 0x354
305 # ELF64-LLVM-NEXT: Offset: 0x5B8
306 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
307 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
308 # ELF-LLVM-NEXT: FileSize: 3
309 # ELF-LLVM-NEXT: MemSize: 3
310 # ELF-LLVM-NEXT: Flags [ (0x0)
312 # ELF-LLVM-NEXT: Alignment: 1
314 # ELF-LLVM-NEXT: ProgramHeader {
315 # ELF-LLVM-NEXT: Type: PT_OPENBSD_RANDOMIZE (0x65A3DBE6)
316 # ELF32-LLVM-NEXT: Offset: 0x354
317 # ELF64-LLVM-NEXT: Offset: 0x5B8
318 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
319 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
320 # ELF-LLVM-NEXT: FileSize: 3
321 # ELF-LLVM-NEXT: MemSize: 3
322 # ELF-LLVM-NEXT: Flags [ (0x0)
324 # ELF-LLVM-NEXT: Alignment: 1
326 # ELF-LLVM-NEXT: ProgramHeader {
327 # ELF-LLVM-NEXT: Type: PT_OPENBSD_WXNEEDED (0x65A3DBE7)
328 # ELF32-LLVM-NEXT: Offset: 0x354
329 # ELF64-LLVM-NEXT: Offset: 0x5B8
330 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
331 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
332 # ELF-LLVM-NEXT: FileSize: 3
333 # ELF-LLVM-NEXT: MemSize: 3
334 # ELF-LLVM-NEXT: Flags [ (0x0)
336 # ELF-LLVM-NEXT: Alignment: 1
338 # ELF-LLVM-NEXT: ProgramHeader {
339 # ELF-LLVM-NEXT: Type: PT_OPENBSD_NOBTCFI (0x65A3DBE8)
340 # ELF32-LLVM-NEXT: Offset: 0x354
341 # ELF64-LLVM-NEXT: Offset: 0x5B8
342 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
343 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
344 # ELF-LLVM-NEXT: FileSize: 3
345 # ELF-LLVM-NEXT: MemSize: 3
346 # ELF-LLVM-NEXT: Flags [ (0x0)
348 # ELF-LLVM-NEXT: Alignment: 1
350 # ELF-LLVM-NEXT: ProgramHeader {
351 # ELF-LLVM-NEXT: Type: PT_OPENBSD_BOOTDATA (0x65A41BE6)
352 # ELF32-LLVM-NEXT: Offset: 0x354
353 # ELF64-LLVM-NEXT: Offset: 0x5B8
354 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
355 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
356 # ELF-LLVM-NEXT: FileSize: 3
357 # ELF-LLVM-NEXT: MemSize: 3
358 # ELF-LLVM-NEXT: Flags [ (0x0)
360 # ELF-LLVM-NEXT: Alignment: 1
362 # ELF-LLVM-NEXT: ProgramHeader {
363 # ELF-LLVM-NEXT: Type: Unknown (0x6FFFFFFF)
364 # ELF32-LLVM-NEXT: Offset: 0x354
365 # ELF64-LLVM-NEXT: Offset: 0x5B8
366 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
367 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
368 # ELF-LLVM-NEXT: FileSize: 3
369 # ELF-LLVM-NEXT: MemSize: 3
370 # ELF-LLVM-NEXT: Flags [ (0x0)
372 # ELF-LLVM-NEXT: Alignment: 1
374 # ELF-LLVM-NEXT: ProgramHeader {
375 # ELF-LLVM-NEXT: Type: Unknown (0x70000000)
376 # ELF32-LLVM-NEXT: Offset: 0x354
377 # ELF64-LLVM-NEXT: Offset: 0x5B8
378 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
379 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
380 # ELF-LLVM-NEXT: FileSize: 3
381 # ELF-LLVM-NEXT: MemSize: 3
382 # ELF-LLVM-NEXT: Flags [ (0x0)
384 # ELF-LLVM-NEXT: Alignment: 1
386 # ELF-LLVM-NEXT: ProgramHeader {
387 # ELF-LLVM-NEXT: Type: Unknown (0x70000001)
388 # ELF32-LLVM-NEXT: Offset: 0x354
389 # ELF64-LLVM-NEXT: Offset: 0x5B8
390 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
391 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
392 # ELF-LLVM-NEXT: FileSize: 3
393 # ELF-LLVM-NEXT: MemSize: 3
394 # ELF-LLVM-NEXT: Flags [ (0x0)
396 # ELF-LLVM-NEXT: Alignment: 1
398 # ELF-LLVM-NEXT: ProgramHeader {
399 # ELF-LLVM-NEXT: Type: Unknown (0x70000002)
400 # ELF32-LLVM-NEXT: Offset: 0x354
401 # ELF64-LLVM-NEXT: Offset: 0x5B8
402 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
403 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
404 # ELF-LLVM-NEXT: FileSize: 3
405 # ELF-LLVM-NEXT: MemSize: 3
406 # ELF-LLVM-NEXT: Flags [ (0x0)
408 # ELF-LLVM-NEXT: Alignment: 1
410 # ELF-LLVM-NEXT: ProgramHeader {
411 # ELF-LLVM-NEXT: Type: Unknown (0x70000003)
412 # ELF32-LLVM-NEXT: Offset: 0x354
413 # ELF64-LLVM-NEXT: Offset: 0x5B8
414 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
415 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
416 # ELF-LLVM-NEXT: FileSize: 3
417 # ELF-LLVM-NEXT: MemSize: 3
418 # ELF-LLVM-NEXT: Flags [ (0x0)
420 # ELF-LLVM-NEXT: Alignment: 1
422 # ELF-LLVM-NEXT: ProgramHeader {
423 # ELF-LLVM-NEXT: Type: Unknown (0x7FFFFFFF)
424 # ELF32-LLVM-NEXT: Offset: 0x354
425 # ELF64-LLVM-NEXT: Offset: 0x5B8
426 # ELF-LLVM-NEXT: VirtualAddress: 0x1000
427 # ELF-LLVM-NEXT: PhysicalAddress: 0x1000
428 # ELF-LLVM-NEXT: FileSize: 3
429 # ELF-LLVM-NEXT: MemSize: 3
430 # ELF-LLVM-NEXT: Flags [ (0x0)
432 # ELF-LLVM-NEXT: Alignment: 1
438 Class: ELFCLASS[[BITS]]
465 Content: "41424300" ## "ABC"
468 Flags: [ SHF_ALLOC, SHF_TLS ]
473 Flags: [ SHF_ALLOC, SHF_TLS ]
477 ## Case 1: an arbitrary segment with sections.
483 ## Case 2: another segment with different sections.
489 ## Case 3: the PT_NULL segment.
495 ## Case 4: the PT_DYNAMIC segment.
497 Flags: [ PF_R, PF_W, PF_X ]
501 ## Case 5: the PT_INTERP segment.
503 Flags: [ PF_R, PF_W ]
507 ## Case 6: the PT_NOTE segment.
512 ## Case 7: the PT_SHLIB segment.
517 ## Case 8: the PT_TLS segment.
522 ## Case 9: the PT_LOOS segment.
523 - Type: 0x60000000 ## PT_LOOS
527 ## Case 10: the PT_GNU_EH_FRAME segment.
528 - Type: PT_GNU_EH_FRAME
532 ## Case 11: the PT_SUNW_UNWIND segment.
533 - Type: 0x6464e550 ## PT_SUNW_UNWIND
537 ## Case 12: the PT_GNU_STACK segment.
542 ## Case 13: the PT_GNU_RELRO segment.
547 ## Case 14: the PT_GNU_PROPERTY segment.
548 - Type: PT_GNU_PROPERTY
552 ## Case 15: the PT_OPENBSD_MUTABLE segment.
553 - Type: 0x65a3dbe5 ## PT_OPENBSD_MUTABLE
557 ## Case 16: the PT_OPENBSD_RANDOMIZE segment.
558 - Type: 0x65a3dbe6 ## PT_OPENBSD_RANDOMIZE
562 ## Case 17: the PT_OPENBSD_WXNEEDED segment.
563 - Type: 0x65a3dbe7 ## PT_OPENBSD_WXNEEDED
567 ## Case 18: the PT_OPENBSD_NOBTCFI segment.
568 - Type: 0x65a3dbe8 ## PT_OPENBSD_NOBTCFI
572 ## Case 19: the PT_OPENBSD_BOOTDATA segment.
573 - Type: 0x65a41be6 ## PT_OPENBSD_BOOTDATA
577 ## Case 20: the PT_HIOS segment.
578 - Type: 0x6fffffff ## PT_HIOS
582 ## Case 21: the PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO segment.
583 - Type: 0x70000000 ## PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO
587 ## Case 22: the PT_ARM_EXIDX/PT_MIPS_RTPROC segment.
588 - Type: 0x70000001 ## PT_ARM_EXIDX, PT_MIPS_RTPROC
592 ## Case 23: the PT_MIPS_OPTIONS segment.
593 - Type: 0x70000002 ## PT_MIPS_OPTIONS
597 ## Case 24: the PT_MIPS_ABIFLAGS/PT_RISCV_ATTRIBUTES segment.
598 - Type: 0x70000003 ## PT_MIPS_ABIFLAGS/PT_RISCV_ATTRIBUTES
602 ## Case 25: the PT_HIPROC segment.
603 - Type: 0x7fffffff ## PT_HIPROC
608 ## Check how we dump ARM specific program headers.
609 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf
610 # RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-GNU
611 # RUN: llvm-readobj --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM-LLVM
613 # ARM-GNU: <unknown>: 0x70000000 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
614 # ARM-GNU-NEXT: EXIDX 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
615 # ARM-GNU-NEXT: <unknown>: 0x70000002 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
617 # ARM-LLVM: ProgramHeader {
618 # ARM-LLVM: Type: Unknown (0x70000000)
619 # ARM-LLVM: ProgramHeader {
620 # ARM-LLVM-NEXT: Type: PT_ARM_EXIDX (0x70000001)
621 # ARM-LLVM: ProgramHeader {
622 # ARM-LLVM-NEXT: Type: Unknown (0x70000002)
624 ## Check how we dump MIPS specific program headers.
625 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf
626 # RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-GNU
627 # RUN: llvm-readobj --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS-LLVM
629 # MIPS-GNU: REGINFO 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
630 # MIPS-GNU-NEXT: RTPROC 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
631 # MIPS-GNU-NEXT: OPTIONS 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
632 # MIPS-GNU-NEXT: ABIFLAGS 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
634 # MIPS-LLVM: ProgramHeader {
635 # MIPS-LLVM: Type: PT_MIPS_REGINFO (0x70000000)
636 # MIPS-LLVM: ProgramHeader {
637 # MIPS-LLVM-NEXT: Type: PT_MIPS_RTPROC (0x70000001)
638 # MIPS-LLVM: ProgramHeader {
639 # MIPS-LLVM-NEXT: Type: PT_MIPS_OPTIONS (0x70000002)
640 # MIPS-LLVM: ProgramHeader {
641 # MIPS-LLVM-NEXT: Type: PT_MIPS_ABIFLAGS (0x70000003)
643 ## CHECK how we dump RISCV specific program headers.
644 # RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_RISCV %s -o %triscv.elf
645 # RUN: llvm-readelf --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-GNU
646 # RUN: llvm-readobj --program-headers %triscv.elf | FileCheck %s --check-prefix=RISCV-LLVM
648 # RISCV-GNU: ATTRIBUTES 0x0005b8 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1
649 # RISCV-LLVM: ProgramHeader {
650 # RISCV-LLVM: Type: PT_RISCV_ATTRIBUTES (0x70000003)
652 ## Check that llvm-readelf reports a warning when a program interpreter
653 ## name is non-null-terminated or when PT_INTERP has an offset that
654 ## goes past the end of the file.
655 # RUN: yaml2obj --docnum=2 %s -o %t.err
657 ## Show the size of the output produced. It is used in the YAML below.
658 # RUN: wc -c < %t.err | FileCheck %s --check-prefix=SIZE
661 ## Write the additional 'C', '\0, 'C' bytes to the end.
662 # RUN: echo -n -e "C\x00C" >> %t.err
664 # RUN: llvm-readelf --program-headers %t.err 2>&1 | \
665 # RUN: FileCheck %s -DFILE=%t.err --check-prefix=ERROR-INTERP --implicit-check-not=warning:
667 # ERROR-INTERP: Type Offset
668 # ERROR-INTERP-NEXT: INTERP 0x000[[#%x,OFFSET:0x268]]
669 # ERROR-INTERP-NEXT: [Requesting program interpreter: C]
670 # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 1]]
671 # ERROR-INTERP-NEXT: [Requesting program interpreter: ]
672 # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 2]]
673 # ERROR-INTERP-NEXT: warning: '[[FILE]]': unable to read program interpreter name at offset 0x[[#OFFSET+2]]: it is not null-terminated
674 # ERROR-INTERP-NEXT: INTERP 0x000[[#OFFSET + 3]]
675 # 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]])
676 # ERROR-INTERP-NEXT: INTERP 0xaabbccddeeff1122
677 # 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]])
678 # ERROR-INTERP-NEXT: INTERP 0xaabbccddeeff1122
686 ## Case 1: the offset points to the first additional byte.
689 ## Case 1: the offset points to the second additional byte,
690 ## which is a null byte.
693 ## Case 3: the offset points to the third additional
694 ## byte, which is the last byte in the file.
697 ## Case 4: the offset goes 1 byte past the end of the file.
700 ## Case 5: an arbitrary large offset that goes past the end of the file.
702 Offset: 0xAABBCCDDEEFF1122
703 ## Case 6: the same as case 5. Used to demonstrate that we don't report
704 ## the same warning twice.
706 Offset: 0xAABBCCDDEEFF1122
708 ## Check we report a warning when we are unable to read program headers.
709 ## Case A: the e_phentsize field is invalid.
710 # RUN: yaml2obj --docnum=3 -DPHENTSIZE=1 %s -o %t.phdr.err
711 # RUN: llvm-readelf --program-headers %t.phdr.err 2>&1 | \
712 # RUN: FileCheck %s -DFILE=%t.phdr.err --check-prefix=WARN-PHENTSIZE-GNU
713 # RUN: llvm-readobj --program-headers %t.phdr.err 2>&1 | \
714 # RUN: FileCheck %s -DFILE=%t.phdr.err --check-prefix=WARN-PHENTSIZE-LLVM
716 # WARN-PHENTSIZE-GNU: Program Headers:
717 # WARN-PHENTSIZE-GNU-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
718 # WARN-PHENTSIZE-GNU-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
719 # WARN-PHENTSIZE-GNU: Section to Segment mapping:
720 # WARN-PHENTSIZE-GNU-NEXT: Segment Sections...
721 # WARN-PHENTSIZE-GNU-NEXT: warning: '[[FILE]]': can't read program headers to build section to segment mapping: invalid e_phentsize: 1
723 # WARN-PHENTSIZE-LLVM: ProgramHeaders [
724 # WARN-PHENTSIZE-LLVM-NEXT: warning: '[[FILE]]': unable to dump program headers: invalid e_phentsize: 1
725 # WARN-PHENTSIZE-LLVM-NEXT: ]
732 EPhEntSize: [[PHENTSIZE=<none>]]
733 EPhOff: [[PHOFF=<none>]]
742 ## Case B: the value of the e_phoff field is invalid.
744 ## Check that we do not report a warning when the program header table ends right before the end of the file.
745 ## 0x160 + size of headers (56) == file size.
746 # RUN: yaml2obj --docnum=3 -DPHOFF=0x160 %s -o %t.phdr.no.err2
747 # RUN: llvm-readelf %t.phdr.no.err2 --program-headers 2>&1 | FileCheck %s --implicit-check-not=warning:
748 # RUN: llvm-readobj %t.phdr.no.err2 --program-headers 2>&1 | FileCheck %s --implicit-check-not=warning:
750 ## Check we report a warning when e_phoff goes 1 byte past the end of the file.
751 # RUN: yaml2obj --docnum=3 -DPHOFF=0x161 %s -o %t.phdr.err2
752 # RUN: llvm-readelf --program-headers %t.phdr.err2 2>&1 | \
753 # RUN: FileCheck %s -DFILE=%t.phdr.err2 --check-prefix=WARN-PHOFF-GNU -DOFF=0x161
754 # RUN: llvm-readobj --program-headers %t.phdr.err2 2>&1 | \
755 # RUN: FileCheck %s -DFILE=%t.phdr.err2 --check-prefix=WARN-PHOFF-LLVM -DOFF=0x161
757 # WARN-PHOFF-GNU: Program Headers:
758 # WARN-PHOFF-GNU-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
759 # 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
760 # WARN-PHOFF-GNU: Section to Segment mapping:
761 # WARN-PHOFF-GNU-NEXT: Segment Sections...
762 # 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
764 # WARN-PHOFF-LLVM: ProgramHeaders [
765 # 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
766 # WARN-PHOFF-LLVM-NEXT: ]
768 ## Check we report a warning when the value of e_phoff is so large that
769 ## e_phoff + e_phnum * e_phentsize > UINT64_MAX.
770 # RUN: yaml2obj --docnum=3 -DPHOFF=0xffffffffffffffff %s -o %t.phdr.err3
771 # RUN: llvm-readelf --program-headers %t.phdr.err3 2>&1 | \
772 # RUN: FileCheck %s -DFILE=%t.phdr.err3 --check-prefix=WARN-PHOFF-GNU -DOFF=0xffffffffffffffff
773 # RUN: llvm-readobj --program-headers %t.phdr.err3 2>&1 | \
774 # RUN: FileCheck %s -DFILE=%t.phdr.err3 --check-prefix=WARN-PHOFF-LLVM -DOFF=0xffffffffffffffff