1 ## Test that yaml2obj emits .debug_addr section.
3 ## a) Generate and verify a little endian DWARF32 .debug_addr section in a 64-bit object file.
5 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.dwarf32.le.o
6 # RUN: llvm-readobj --sections --section-data %t1.dwarf32.le.o | \
7 # RUN: FileCheck %s -DSIZE=264 -DADDRALIGN=1 --check-prefixes=SHDR,DWARF32-LE
10 # SHDR-NEXT: Name: .debug_addr (1)
11 # SHDR-NEXT: Type: SHT_PROGBITS (0x1)
12 # SHDR-NEXT: Flags [ (0x0)
14 # SHDR-NEXT: Address: 0x0
15 # SHDR-NEXT: Offset: 0x40
16 # SHDR-NEXT: Size: [[SIZE]]
19 # SHDR-NEXT: AddressAlignment: [[ADDRALIGN]]
20 # SHDR-NEXT: EntrySize: 0
21 # DWARF32-LE-NEXT: SectionData (
22 # DWARF32-LE-NEXT: 0000: 0C000000 05000400 34120000 78560000
24 ## | | | | | +------- address (4-byte)
25 ## | | | | +------- address (4-byte)
26 ## | | | +- segment_selector_size (1-byte)
27 ## | | +- address_size (1-byte)
28 ## | +--- version (2-byte)
29 ## +------- 1) unit_length (4-byte)
31 # DWARF32-LE-NEXT: 0010: 14000000 05000800 21430000 00000000
33 ## | | | | +---------------- address (8-byte)
34 ## | | | +- segment_selector_size (1-byte)
35 ## | | +- address_size (1-byte)
36 ## | +--- version (2-byte)
37 ## +------- 2) unit_length (4-byte)
39 # DWARF32-LE-NEXT: 0020: 65870000 00000000 0C000000 05000004
41 ## | | | | +- segment_selector_size (1-byte)
42 ## | | | +- address_size (1-byte)
43 ## | | +--- version (2-byte)
44 ## | +------- 3) unit_length (4-byte)
45 ## +---------------- address (8-byte)
47 # DWARF32-LE-NEXT: 0030: 34120000 78560000 14000000 05000008
49 ## | | | | | +- segment_selector_size (1-byte)
50 ## | | | | +- address_size (1-byte)
51 ## | | | +--- version (2-byte)
52 ## | | +------- 4) unit_length (4-byte)
53 ## | +------- segment (4-byte)
54 ## +------- segment (4-byte)
56 # DWARF32-LE-NEXT: 0040: 21430000 00000000 65870000 00000000
58 ## | +---------------- segment (8-byte)
59 ## +---------------- segment (8-byte)
61 # DWARF32-LE-NEXT: 0050: 1C000000 05000404 34120000 78560000
63 ## | | | | | +------- address (4-byte)
64 ## | | | | +------- segment (4-byte)
65 ## | | | +- segment_selector_size (4-byte)
66 ## | | +- address_size (4-byte)
67 ## | +--- version (2-byte)
68 ## +------- 5) unit_length (4-byte)
70 # DWARF32-LE-NEXT: 0060: 21430000 00000000 00000000 21430000
72 ## | | | +------- address (4-byte)
73 ## | | +------- segment (4-byte)
74 ## | +------- address (4-byte)
75 ## +------- segment (4-byte)
77 # DWARF32-LE-NEXT: 0070: 34000000 05000808 34120000 00000000
79 ## | | | | +---------------- segment (8-byte)
80 ## | | | +- segment_size (1-byte)
81 ## | | +- address_size (1-byte)
82 ## | +--- version (2-byte)
83 ## +------- 6) unit_length (4-byte)
85 # DWARF32-LE-NEXT: 0080: 78560000 00000000 21430000 00000000
87 ## | +---------------- segment (8-byte)
88 ## +---------------- address (8-byte)
90 # DWARF32-LE-NEXT: 0090: 00000000 00000000 00000000 00000000
91 ## | +---------------- segment (8-byte)
92 ## +---------------- address (8-byte)
94 # DWARF32-LE-NEXT: 00A0: 21430000 00000000 28000000 05000408
96 ## | | | | +- segment_size (1-byte)
97 ## | | | +- address_size (1-byte)
98 ## | | +--- version (2-byte)
99 ## | +------- 7) unit_length (4-byte)
100 ## +---------------- address (8-byte)
102 # DWARF32-LE-NEXT: 00B0: 34120000 00000000 78560000 21430000
104 ## | | +------- segment (8-byte)
105 ## | +------- address (4-byte)
106 ## +---------------- segment (8-byte)
108 # DWARF32-LE-NEXT: 00C0: 00000000 00000000 00000000 00000000
109 ## | | +---------------- segment (8-byte)
110 ## | +------- address (4-btye)
111 ## +------- higher 4-byte of segment
113 # DWARF32-LE-NEXT: 00D0: 21430000 28000000 05000804 34120000
114 ## | | | | | +------- segment (4-byte)
115 ## | | | | +- segment_size (1-byte)
116 ## | | | +- address_size (1-byte)
117 ## | | +--- version (2-byte)
118 ## | +------- 8) unit_length (4-byte)
119 ## +------- address (4-byte)
121 # DWARF32-LE-NEXT: 00E0: 78560000 00000000 21430000 00000000
123 ## | | +------- address (8-byte)
124 ## | +------- segment (4-byte)
125 ## +---------------- address (8-byte)
127 # DWARF32-LE-NEXT: 00F0: 00000000 00000000 21430000 00000000
129 ## | | +---------------- address (8-byte)
130 ## | +------- segment (4-byte)
131 ## +------- higher 4-byte of address
133 # DWARF32-LE-NEXT: 0100: 34120000 02000400
135 ## | | | +- segment_size (1-byte)
136 ## | | +- address_size (1-byte)
137 ## | +--- version (2-byte)
138 ## +------- 9) unit_length (4-byte)
148 ## 1) Only address (4-byte) exists.
154 ## 2) Only address (8-byte) exists (AddressSize is derived from FileHeader).
159 ## 3) Only segment (4-byte) exists.
162 SegmentSelectorSize: 0x04
166 ## 4) Only segment (8-byte) exists.
169 SegmentSelectorSize: 0x08
173 ## 5) Both address (4-byte) and segment (4-byte) exist.
176 SegmentSelectorSize: 0x04
181 ## Segment exists, while address takes the default value 0x00.
183 ## Address exists, while segment takes the default value 0x00.
184 ## 6) Both address (8-byte) and segment (8-byte) exist (AddressSize is derived from FileHeader).
186 SegmentSelectorSize: 0x08
191 ## Segment exists, while address takes the default value 0x00.
193 ## Address exists, while segment takes the default value 0x00.
194 ## 7) Both address (4-byte) and segment (8-byte) exist.
197 SegmentSelectorSize: 0x08
202 ## Segment exists, while address takes the default value 0x00.
204 ## Address exists, while segment takes the default value 0x00.
205 ## 8) Both address (8-byte) and segment (4-byte) exist (AddressSize is derived from FileHeader).
207 SegmentSelectorSize: 0x04
212 ## Segment exists, while address takes the default value 0x00.
214 ## Address exists, while segment takes the default value 0x00.
215 ## 9) Explicitly assign a value to 'Length'.
219 SegmentSelectorSize: 0x00
222 ## b) Generate and verify a big endian DWARF32 .debug_addr section.
224 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.dwarf32.be.o
225 # RUN: llvm-readobj --sections --section-data %t1.dwarf32.be.o | \
226 # RUN: FileCheck %s -DSIZE=264 -DADDRALIGN=1 --check-prefixes=SHDR,DWARF32-BE
228 # DWARF32-BE-NEXT: SectionData (
229 # DWARF32-BE-NEXT: 0000: 0000000C 00050400 00001234 00005678
231 ## | | | | | +------- address (4-byte)
232 ## | | | | +------- address (4-byte)
233 ## | | | +- segment_selector_size (1-byte)
234 ## | | +- address_size (1-byte)
235 ## | +--- version (2-byte)
236 ## +------- 1) unit_length (4-byte)
238 # DWARF32-BE-NEXT: 0010: 00000014 00050800 00000000 00004321
240 ## | | | | +---------------- address (8-byte)
241 ## | | | +- segment_selector_size (1-byte)
242 ## | | +- address_size (1-byte)
243 ## | +--- version (2-byte)
244 ## +------- 2) unit_length (4-byte)
246 # DWARF32-BE-NEXT: 0020: 00000000 00008765 0000000C 00050004
248 ## | | | | +- segment_selector_size (1-byte)
249 ## | | | +- address_size (1-byte)
250 ## | | +--- version (2-byte)
251 ## | +------- 3) unit_length (4-byte)
252 ## +---------------- address (8-byte)
254 # DWARF32-BE-NEXT: 0030: 00001234 00005678 00000014 00050008
256 ## | | | | | +- segment_selector_size (1-byte)
257 ## | | | | +- address_size (1-byte)
258 ## | | | +--- version (2-byte)
259 ## | | +------- 4) unit_length (4-byte)
260 ## | +------- segment (4-byte)
261 ## +------- segment (4-byte)
263 # DWARF32-BE-NEXT: 0040: 00000000 00004321 00000000 00008765
265 ## | +---------------- segment (8-byte)
266 ## +---------------- segment (8-byte)
268 # DWARF32-BE-NEXT: 0050: 0000001C 00050404 00001234 00005678
270 ## | | | | | +------- address (4-byte)
271 ## | | | | +------- segment (4-byte)
272 ## | | | +- segment_selector_size (4-byte)
273 ## | | +- address_size (4-byte)
274 ## | +--- version (2-byte)
275 ## +------- 5) unit_length (4-byte)
277 # DWARF32-BE-NEXT: 0060: 00004321 00000000 00000000 00004321
279 ## | | | +------- address (4-byte)
280 ## | | +------- segment (4-byte)
281 ## | +------- address (4-byte)
282 ## +------- segment (4-byte)
284 # DWARF32-BE-NEXT: 0070: 00000034 00050808 00000000 00001234
286 ## | | | | +---------------- segment (8-byte)
287 ## | | | +- segment_size (1-byte)
288 ## | | +- address_size (1-byte)
289 ## | +--- version (2-byte)
290 ## +------- 6) unit_length (4-byte)
292 # DWARF32-BE-NEXT: 0080: 00000000 00005678 00000000 00004321
294 ## | +---------------- segment (8-byte)
295 ## +---------------- address (8-byte)
297 # DWARF32-BE-NEXT: 0090: 00000000 00000000 00000000 00000000
299 ## | +---------------- segment (8-byte)
300 ## +---------------- address (8-byte)
302 # DWARF32-BE-NEXT: 00A0: 00000000 00004321 00000028 00050408
304 ## | | | | +- segment_size (1-byte)
305 ## | | | +- address_size (1-byte)
306 ## | | +--- version (2-byte)
307 ## | +------- 7) unit_length (4-byte)
308 ## +---------------- address (8-byte)
310 # DWARF32-BE-NEXT: 00B0: 00000000 00001234 00005678 00000000
312 ## | | +------- segment (8-byte)
313 ## | +------- address (4-byte)
314 ## +---------------- segment (8-byte)
316 # DWARF32-BE-NEXT: 00C0: 00004321 00000000 00000000 00000000
318 ## | | +---------------- segment (8-byte)
319 ## | +------- address (4-btye)
320 ## +------- lower 4-byte of segment
322 # DWARF32-BE-NEXT: 00D0: 00004321 00000028 00050804 00001234
324 ## | | | | | +------- segment (4-byte)
325 ## | | | | +- segment_size (1-byte)
326 ## | | | +- address_size (1-byte)
327 ## | | +--- version (2-byte)
328 ## | +------- 8) unit_length (4-byte)
329 ## +------- address (4-byte)
331 # DWARF32-BE-NEXT: 00E0: 00000000 00005678 00004321 00000000
333 ## | | +------- address (8-byte)
334 ## | +------- segment (4-byte)
335 ## +---------------- address (8-byte)
337 # DWARF32-BE-NEXT: 00F0: 00000000 00000000 00000000 00004321
339 ## | | +---------------- address (8-byte)
340 ## | +------- segment (4-byte)
341 ## +------- lower 4-byte of address
343 # DWARF32-BE-NEXT: 0100: 00001234 00020400
345 ## | | | +- segment_size (1-byte)
346 ## | | +- address_size (1-byte)
347 ## | +--- version (2-byte)
348 ## +------- 9) unit_length (4-byte)
351 ## c) Generate and verify a little endian DWARF64 .debug_addr section.
353 # RUN: yaml2obj --docnum=2 -DENDIAN=ELFDATA2LSB %s -o %t2.dwarf64.le.o
354 # RUN: llvm-readobj --sections --section-data %t2.dwarf64.le.o | \
355 # RUN: FileCheck %s -DSIZE=56 -DADDRALIGN=1 --check-prefixes=SHDR,DWARF64-LE
357 # DWARF64-LE-NEXT: SectionData (
358 # DWARF64-LE-NEXT: 0000: FFFFFFFF 0C000000 00000000 05000400
360 ## | | | +- segment_selector_size (1-byte)
361 ## | | +- address_size (1-byte)
362 ## | +--- version (2-byte)
363 ## +------------------------- unit_length (12-byte)
365 # DWARF64-LE-NEXT: 0010: 34120000 78560000 FFFFFFFF 14000000
367 ## | | +---------------- unit_length (12-byte)
368 ## | +------- address (4-byte)
369 ## +------- address (4-byte)
371 # DWARF64-LE-NEXT: 0020: 00000000 05000800 21430000 00000000
373 ## | | | | +---------------- address (8-byte)
374 ## | | | +- segment_selector_size (1-byte)
375 ## | | +- address_size (1-byte)
376 ## | +--- version (2-byte)
377 ## +------- last 4-byte of unit_length
379 # DWARF64-LE-NEXT: 0030: 65870000 00000000
381 ## +---------------- address (8-byte)
403 ## d) Generate and verify a big endian DWARF64 .debug_addr section.
405 # RUN: yaml2obj --docnum=2 -DENDIAN=ELFDATA2MSB %s -o %t2.dwarf64.be.o
406 # RUN: llvm-readobj --sections --section-data %t2.dwarf64.be.o | \
407 # RUN: FileCheck %s -DSIZE=56 -DADDRALIGN=1 --check-prefixes=SHDR,DWARF64-BE
409 # DWARF64-BE-NEXT: SectionData (
410 # DWARF64-BE-NEXT: 0000: FFFFFFFF 00000000 0000000C 00050400
412 ## | | | +- segment_selector_size (1-byte)
413 ## | | +- address_size (1-byte)
414 ## | +--- version (2-byte)
415 ## +------------------------- unit_length (12-byte)
417 # DWARF64-BE-NEXT: 0010: 00001234 00005678 FFFFFFFF 00000000
419 ## | | +---------------- unit_length (12-byte)
420 ## | +------- address (4-byte)
421 ## +------- address (4-byte)
423 # DWARF64-BE-NEXT: 0020: 00000014 00050800 00000000 00004321
425 ## | | | | +---------------- address (8-byte)
426 ## | | | +- segment_selector_size (1-byte)
427 ## | | +- address_size (1-byte)
428 ## | +--- version (2-byte)
429 ## +------- last 4-byte of unit_length
431 # DWARF64-BE-NEXT: 0030: 00000000 00008765
433 ## +---------------- address (8-byte)
436 ## e) Test that yaml2obj emits an error message if the 'Version' fields is missing.
438 # RUN: not yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=MISSING-VERSION
440 # MISSING-VERSION: error: missing required key 'Version'
451 ## f) Generate the .debug_addr section from raw section content.
453 # RUN: yaml2obj --docnum=4 %s -o %t4.o
454 # RUN: llvm-readobj --sections --section-data %t4.o | \
455 # RUN: FileCheck %s -DADDRALIGN=0 -DSIZE=3 --check-prefixes=SHDR,ARBITRARY-CONTENT
457 # ARBITRARY-CONTENT: SectionData (
458 # ARBITRARY-CONTENT-NEXT: 0000: 112233
459 # ARBITRARY-CONTENT-NEXT: )
471 ## g) Generate the .debug_addr section when the "Size" is specified.
473 # RUN: yaml2obj --docnum=5 %s -o %t5.o
474 # RUN: llvm-readelf --hex-dump=.debug_addr %t5.o | FileCheck %s --check-prefix=SIZE
476 # SIZE: Hex dump of section '.debug_addr':
477 # SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................
490 ## h) Test that yaml2obj emits an error message when both the "Size" and the
491 ## "debug_addr" entry are specified at the same time.
493 # RUN: not yaml2obj --docnum=6 %s 2>&1 | FileCheck %s --check-prefix=ERROR
495 # ERROR: yaml2obj: error: cannot specify section '.debug_addr' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
511 ## i) Test that yaml2obj emits an error message when both the "Content" and the
512 ## "debug_addr" entry are specified at the same time.
514 # RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=ERROR
530 ## j) Test that all the properties can be overridden by the section header when
531 ## the "debug_addr" entry doesn't exist.
533 # RUN: yaml2obj --docnum=8 %s -o %t8.o
534 # RUN: llvm-readelf --sections %t8.o | FileCheck %s --check-prefix=OVERRIDDEN
536 # OVERRIDDEN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
537 # OVERRIDDEN: [ 1] .debug_addr STRTAB 0000000000002020 000050 000008 01 A 2 1 2
538 # OVERRIDDEN-NEXT: [ 2] .sec STRTAB 0000000000000000 000058 000000 00 0 0 0
547 Type: SHT_STRTAB ## SHT_PROGBITS by default.
548 Flags: [SHF_ALLOC] ## 0 by default.
549 Link: .sec ## 0 by default.
550 EntSize: 1 ## 0 by default.
551 Info: 1 ## 0 by default.
552 AddressAlign: 2 ## 0 by default.
553 Address: 0x2020 ## 0x00 by default.
554 Offset: 0x50 ## 0x40 for the first section.
555 Size: 0x08 ## Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
556 - Name: .sec ## Linked by .debug_addr.
559 ## k) Test that all the properties can be overridden by the section header when
560 ## the "debug_addr" entry exists.
562 # RUN: yaml2obj --docnum=9 %s -o %t9.o
563 # RUN: llvm-readelf --sections %t9.o | FileCheck %s --check-prefix=OVERRIDDEN
572 Type: SHT_STRTAB ## SHT_PROGBITS by default.
573 Flags: [SHF_ALLOC] ## 0 by default.
574 Link: .sec ## 0 by default.
575 EntSize: 1 ## 0 by default.
576 Info: 1 ## 0 by default.
577 AddressAlign: 2 ## 1 by default.
578 Address: 0x2020 ## 0x00 by default.
579 Offset: 0x50 ## 0x40 for the first section.
580 - Name: .sec ## Linked by .debug_addr.
587 ## l) Test that yaml2obj still generates a .debug_addr section if we assign an invalid value
588 ## to 'AddressSize' or 'SegmentSelectorSize' when the 'Entries' list is empty.
590 # RUN: yaml2obj --docnum=10 -DSIZENAME=AddressSize %s -o %t10.addr.o
591 # RUN: llvm-readelf --hex-dump=.debug_addr %t10.addr.o | \
592 # RUN: FileCheck -DADDRSIZE=03 -DSEGSIZE=00 %s --check-prefix=ADDR-SEG-SIZE
594 # RUN: yaml2obj --docnum=10 -DSIZENAME=SegmentSelectorSize %s -o %t10.seg.o
595 # RUN: llvm-readelf --hex-dump=.debug_addr %t10.seg.o | \
596 # RUN: FileCheck -DADDRSIZE=08 -DSEGSIZE=03 %s --check-prefix=ADDR-SEG-SIZE
598 # ADDR-SEG-SIZE: Hex dump of section '.debug_addr':
599 # ADDR-SEG-SIZE-NEXT: 0x00000000 04000000 0500[[ADDRSIZE]][[SEGSIZE]]
612 ## m) Test that yaml2obj emits an error message if we try to assign an invalid value to
613 ## 'AddressSize' or 'SegmentSelectorSize' when the 'Entries' list isn't empty.
615 # RUN: not yaml2obj --docnum=11 -DSIZENAME=AddressSize %s 2>&1 | \
616 # RUN: FileCheck -DFIELD=address %s --check-prefix=INVALID-SIZE
618 # RUN: not yaml2obj --docnum=11 -DSIZENAME=SegmentSelectorSize %s 2>&1 | \
619 # RUN: FileCheck -DFIELD=segment %s --check-prefix=INVALID-SIZE
621 # INVALID-SIZE: yaml2obj: error: unable to write debug_addr [[FIELD]]: invalid integer write size: 3
635 ## n) Test that the .debug_addr section header is emitted if the "debug_addr"
638 # RUN: yaml2obj --docnum=12 %s -o %t12.o
639 # RUN: llvm-readobj --sections %t12.o | \
640 # RUN: FileCheck %s -DSIZE=0 -DADDRALIGN=1 --check-prefix=SHDR