1 ## Test that yaml2obj emits .debug_aranges section.
3 ## a) Generate the .debug_aranges section from the "DWARF" entry.
5 ## Generate and verify a big endian DWARF32 .debug_aranges section.
7 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF32 %s -o %t.be.o
8 # RUN: llvm-readobj --sections --section-data %t.be.o | \
9 # RUN: FileCheck -DADDRALIGN=1 -DSIZE=96 %s --check-prefixes=DWARF-HEADER,DWARF-BE-CONTENT
11 # DWARF-HEADER: Index: 1
12 # DWARF-HEADER-NEXT: Name: .debug_aranges (1)
13 # DWARF-HEADER-NEXT: Type: SHT_PROGBITS (0x1)
14 # DWARF-HEADER-NEXT: Flags [ (0x0)
15 # DWARF-HEADER-NEXT: ]
16 # DWARF-HEADER-NEXT: Address: 0x0
17 # DWARF-HEADER-NEXT: Offset: 0x40
18 # DWARF-HEADER-NEXT: Size: [[SIZE]]
19 # DWARF-HEADER-NEXT: Link: 0
20 # DWARF-HEADER-NEXT: Info: 0
21 # DWARF-HEADER-NEXT: AddressAlignment: [[ADDRALIGN]]
22 # DWARF-HEADER-NEXT: EntrySize: 0
23 # DWARF-BE-CONTENT-NEXT: SectionData (
24 # DWARF-BE-CONTENT-NEXT: 0000: 0000002C 00020000 00000400 00000000
26 ## | | | | | +------- Padding zeros (4-byte)
27 ## | | | | +- SegSize (1-byte) 0x00
28 ## | | | +- AddrSize (1-byte) 0x04
29 ## | | +-------- CuOffset (4-byte) 0x00
30 ## | +--- Version (2-byte) 0x02
31 ## +------- InitialLength (4-byte) 0x2c
33 # DWARF-BE-CONTENT-NEXT: 0010: 00001234 00000020 00000000 00000000
35 ## | | +---------------- Terminating Entry
36 ## | +------- Length (4-byte) 0x20
37 ## +------- Address (4-byte) 0x1234
39 # DWARF-BE-CONTENT-NEXT: 0020: 0000002C 00020000 00650800 00000000
41 ## | | | | | +------- Padding zeros (4-byte)
42 ## | | | | +- SegSize (1-byte) 0x00
43 ## | | | +- AddrSize (1-byte) 0x08
44 ## | | +-------- CuOffset (4-byte) 0x00
45 ## | +--- Version (2-byte) 0x02
46 ## +------- InitialLength (4-byte) 0x2c
48 # DWARF-BE-CONTENT-NEXT: 0030: 00000000 00005678 00000000 00000020
50 ## | +---------------- Length (8-byte) 0x20
51 ## +---------------- Address (8-byte) 0x5678
53 # DWARF-BE-CONTENT-NEXT: 0040: 00000000 56780000 00000000 00000010
55 ## | +---------------- Length (8-byte) 0x10
56 ## +---------------- Address (8-byte) 0x5678
58 # DWARF-BE-CONTENT-NEXT: 0050: 00000000 00000000 00000000 00000000
60 ## +---------------------------------- Terminating entry
62 # DWARF-BE-CONTENT-NEXT: )
76 SegmentSelectorSize: 0x00
85 SegmentSelectorSize: 0x00
87 - Address: 0x0000000000005678
89 - Address: 0x0000000056780000
92 ## Generate and verify a little endian DWARF32 .debug_aranges section.
94 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF32 %s -o %t.le.o
95 # RUN: llvm-readobj --sections --section-data %t.le.o | \
96 # RUN: FileCheck -DADDRALIGN=1 -DSIZE=96 %s --check-prefixes=DWARF-HEADER,DWARF-LE-CONTENT
98 # DWARF-LE-CONTENT-NEXT: SectionData (
99 # DWARF-LE-CONTENT-NEXT: 0000: 2C000000 02000000 00000400 00000000
101 ## | | | | | +------- Padding zeros (4-byte)
102 ## | | | | +- SegSize (1-byte) 0x00
103 ## | | | +- AddrSize (1-byte) 0x04
104 ## | | +-------- CuOffset (4-byte) 0x00
105 ## | +--- Version (2-byte) 0x02
106 ## +------- InitialLength (4-byte) 0x2c
108 # DWARF-LE-CONTENT-NEXT: 0010: 34120000 20000000 00000000 00000000
110 ## | | +---------------- Terminating Entry
111 ## | +------- Length (4-byte) 0x20
112 ## +------- Address (4-byte) 0x1234
114 # DWARF-LE-CONTENT-NEXT: 0020: 2C000000 02006500 00000800 00000000
116 ## | | | | | +------- Padding zeros (4-byte)
117 ## | | | | +- SegSize (1-byte) 0x00
118 ## | | | +- AddrSize (1-byte) 0x08
119 ## | | +-------- CuOffset (4-byte) 0x00
120 ## | +--- Version (2-byte) 0x02
121 ## +------- InitialLength (4-byte) 0x2c
123 # DWARF-LE-CONTENT-NEXT: 0030: 78560000 00000000 20000000 00000000
125 ## | +---------------- Length (8-byte) 0x20
126 ## +---------------- Address (8-byte) 0x5678
128 # DWARF-LE-CONTENT-NEXT: 0040: 00007856 00000000 10000000 00000000
130 ## | +---------------- Length (8-byte) 0x10
131 ## +---------------- Address (8-byte) 0x5678
133 # DWARF-LE-CONTENT-NEXT: 0050: 00000000 00000000 00000000 00000000
135 ## +---------------------------------- Terminating entry
137 # DWARF-LE-CONTENT-NEXT: )
139 ## Generate and verify a big endian DWARF64 .debug_aranges section.
141 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB -DFORMAT=DWARF64 %s -o %t.be.dwarf64.o
142 # RUN: llvm-readobj --sections --section-data %t.be.dwarf64.o | \
143 # RUN: FileCheck -DADDRALIGN=1 -DSIZE=120 %s --check-prefixes=DWARF-HEADER,DWARF64-BE-CONTENT
145 # DWARF64-BE-CONTENT-NEXT: SectionData (
146 # DWARF64-BE-CONTENT-NEXT: 0000: FFFFFFFF 00000000 0000002C 00020000
148 ## | | | +--- CuOffset (8-byte) 0x00
149 ## | | +--- Version (2-byte) 0x02
150 ## | +---------------- Length (8-byte) 0x2c
151 ## +------- DWARF64 Prefix (4-byte) UINT32_MAX
153 # DWARF64-BE-CONTENT-NEXT: 0010: 00000000 00000400 00001234 00000020
155 ## | | | | +------- Length (4-byte) 0x20
156 ## | | | +------- Address (4-byte) 0x1234
157 ## | | +- SegSize (1-byte) 0x00
158 ## | +- AddrSize (1-byte) 0x04
159 ## +------------ Lower bytes of CuOffset
161 # DWARF64-BE-CONTENT-NEXT: 0020: 00000000 00000000 FFFFFFFF 00000000
162 ## | | +------- Length (8-byte) 0x2c
163 ## | +------- DWARF64 Prefix
164 ## +---------------- Terminating Entry (8-byte) 0x00
166 # DWARF64-BE-CONTENT-NEXT: 0030: 0000002C 00020000 00000000 00650800
168 ## | | | | +- SegSize (1-byte) 0x00
169 ## | | | +- AddrSize (1-byte) 0x08
170 ## | | +----------------- CuOffset (8-byte) 0x65
171 ## | +--- Version (2-byte) 0x02
172 ## +------- Lower bytes of Length
174 # DWARF64-BE-CONTENT-NEXT: 0040: 00000000 00000000 00000000 00005678
176 ## | +---------------- Address (8-byte) 0x5678
177 ## +---------------- Padding zeros (8-byte)
179 # DWARF64-BE-CONTENT-NEXT: 0050: 00000000 00000020 00000000 56780000
181 ## | +---------------- Address (8-byte) 0x56780000
182 ## +---------------- Length (8-byte) 0x20
184 # DWARF64-BE-CONTENT-NEXT: 0060: 00000000 00000010 00000000 00000000
186 ## | +---------------- Terminating Entry (16-byte) 0x00
187 ## +---------------- Length (8-byte) 0x10
189 # DWARF64-BE-CONTENT-NEXT: 0070: 00000000 00000000
191 ## +---------------- The last bytes of terminating entry.
192 # DWARF64-BE-CONTENT-NEXT: )
194 ## Generate and verify a little endian DWARF64 .debug_aranges section.
196 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB -DFORMAT=DWARF64 %s -o %t.le.dwarf64.o
197 # RUN: llvm-readobj --sections --section-data %t.le.dwarf64.o | \
198 # RUN: FileCheck -DADDRALIGN=1 -DSIZE=120 %s --check-prefixes=DWARF-HEADER,DWARF64-LE-CONTENT
200 # DWARF64-LE-CONTENT-NEXT: SectionData (
201 # DWARF64-LE-CONTENT-NEXT: 0000: FFFFFFFF 2C000000 00000000 02000000
203 ## | | | +--- CuOffset (8-byte) 0x00
204 ## | | +--- Version (2-byte) 0x02
205 ## | +---------------- Length (8-byte) 0x2c
206 ## +------- DWARF64 Prefix (4-byte) UINT32_MAX
208 # DWARF64-LE-CONTENT-NEXT: 0010: 00000000 00000400 34120000 20000000
210 ## | | | | +------- Length (4-byte) 0x20
211 ## | | | +------- Address (4-byte) 0x1234
212 ## | | +- SegSize (1-byte) 0x00
213 ## | +- AddrSize (1-byte) 0x04
214 ## +------------ Lower bytes of CuOffset
216 # DWARF64-LE-CONTENT-NEXT: 0020: 00000000 00000000 FFFFFFFF 2C000000
217 ## | | +------- Length (8-byte) 0x2c
218 ## | +------- DWARF64 Prefix
219 ## +---------------- Terminating Entry (8-byte) 0x00
221 # DWARF64-LE-CONTENT-NEXT: 0030: 00000000 02006500 00000000 00000800
223 ## | | | | +- SegSize (1-byte) 0x00
224 ## | | | +- AddrSize (1-byte) 0x08
225 ## | | +----------------- CuOffset (8-byte) 0x65
226 ## | +--- Version (2-byte) 0x02
227 ## +------- Lower bytes of Length
229 # DWARF64-LE-CONTENT-NEXT: 0040: 00000000 00000000 78560000 00000000
231 ## | +---------------- Address (8-byte) 0x5678
232 ## +---------------- Padding zeros (8-byte)
234 # DWARF64-LE-CONTENT-NEXT: 0050: 20000000 00000000 00007856 00000000
236 ## | +---------------- Address (8-byte) 0x56780000
237 ## +---------------- Length (8-byte) 0x20
239 # DWARF64-LE-CONTENT-NEXT: 0060: 10000000 00000000 00000000 00000000
241 ## | +---------------- Terminating Entry (16-byte) 0x00
242 ## +---------------- Length (8-byte) 0x10
244 # DWARF64-LE-CONTENT-NEXT: 0070: 00000000 00000000
246 ## +---------------- The last bytes of terminating entry.
247 # DWARF64-LE-CONTENT-NEXT: )
249 ## b) Generate the .debug_aranges section from raw section content.
251 # RUN: yaml2obj --docnum=2 %s -o %t2.o
252 # RUN: llvm-readobj --sections --section-data %t2.o | \
253 # RUN: FileCheck %s -DADDRALIGN=0 -DSIZE=3 --check-prefixes=DWARF-HEADER,ARBITRARY-CONTENT
255 # ARBITRARY-CONTENT: SectionData (
256 # ARBITRARY-CONTENT-NEXT: 0000: 112233
257 # ARBITRARY-CONTENT-NEXT: )
265 - Name: .debug_aranges
269 ## c) Generate the .debug_aranges section when the "Size" is specified.
271 # RUN: yaml2obj --docnum=3 %s -o %t3.o
272 # RUN: llvm-readobj --hex-dump=.debug_aranges %t3.o | FileCheck %s --check-prefix=SIZE
274 # SIZE: Hex dump of section '.debug_aranges':
275 # SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................
284 - Name: .debug_aranges
288 ## d) Test that yaml2obj emits an error message when both the "Size" and the
289 ## "debug_aranges" entry are specified at the same time.
291 # RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR
293 # ERROR: yaml2obj: error: cannot specify section '.debug_aranges' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
301 - Name: .debug_aranges
310 SegmentSelectorSize: 0x00
312 - Address: 0x0000000000001234
315 ## e) Test that yaml2obj emits an error message when both the "Content" and the
316 ## "debug_aranges" entry are specified at the same time.
318 # RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR
326 - Name: .debug_aranges
335 SegmentSelectorSize: 0x00
337 - Address: 0x0000000000001234
340 ## f) Test that all the properties can be overridden by the section header when
341 ## the "debug_aranges" entry doesn't exist.
343 # RUN: yaml2obj --docnum=6 %s -o %t6.o
344 # RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN
346 # OVERRIDDEN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
347 # OVERRIDDEN: [ 1] .debug_aranges STRTAB 0000000000002020 000050 000030 01 A 2 1 2
348 # OVERRIDDEN-NEXT: [ 2] .sec STRTAB 0000000000000000 000080 000000 00 0 0 0
356 - Name: .debug_aranges
357 Type: SHT_STRTAB # SHT_PROGBITS by default.
358 Flags: [SHF_ALLOC] # 0 by default.
359 Link: .sec # 0 by default.
360 EntSize: 1 # 0 by default.
361 Info: 1 # 0 by default.
362 AddressAlign: 2 # 0 by default.
363 Address: 0x0000000000002020 # 0x00 by default.
364 Offset: 0x00000050 # 0x40 for the first section.
365 Size: 0x30 # Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
366 - Name: .sec # Linked by .debug_aranges.
369 ## g) Test that all the properties can be overridden by the section header when
370 ## the "debug_aranges" entry exists.
372 # RUN: yaml2obj --docnum=7 %s -o %t7.o
373 # RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN
381 - Name: .debug_aranges
382 Type: SHT_STRTAB # SHT_PROGBITS by default.
383 Flags: [SHF_ALLOC] # 0 by default.
384 Link: .sec # 0 by default.
385 EntSize: 1 # 0 by default.
386 Info: 1 # 0 by default.
387 AddressAlign: 2 # 1 by default.
388 Address: 0x0000000000002020 # 0x00 by default.
389 Offset: 0x00000050 # 0x40 for the first section.
390 - Name: .sec # Linked by .debug_aranges.
398 SegmentSelectorSize: 0x00
400 - Address: 0x0000000000001234
403 ## h) Test that yaml2obj still generates a .debug_aranges section if we assign an invalid value
404 ## to 'AddrSize' when the 'Descriptors' list is empty.
406 # RUN: yaml2obj --docnum=8 %s -o %t8.o
407 # RUN: llvm-readelf --hex-dump=.debug_aranges %t8.o | \
408 # RUN: FileCheck %s --check-prefix=ADDR-SIZE
410 # ADDR-SIZE: Hex dump of section '.debug_aranges':
411 # ADDR-SIZE-NEXT: 0x00000000 2c000000 02000000 00000700 00000000
412 ## ^~ address_size (1-byte) 0x07
413 # ADDR-SIZE-NEXT: 0x00000010 00000000 00000000 00000000
425 AddressSize: 0x07 ## Invalid address_size.
426 SegmentSelectorSize: 0
429 ## i) Test that yaml2obj emits an error message if we try to assign an invalid value to
430 ## 'AddrSize' when the 'Descriptors' list isn't empty.
432 # RUN: not yaml2obj --docnum=9 %s 2>&1 | \
433 # RUN: FileCheck %s --check-prefix=INVALID-SIZE
435 # INVALID-SIZE: yaml2obj: error: unable to write debug_aranges address: invalid integer write size: 7
447 AddressSize: 0x07 ## Invalid address_size.
448 SegmentSelectorSize: 0
453 ## j) Test the default value of address_size and segment_selector_size in a 64/32-bit object file.
455 # RUN: yaml2obj --docnum=10 -DCLASS=ELFCLASS64 %s -o %t10.64-bit.o
456 # RUN: llvm-readelf --hex-dump=.debug_aranges %t10.64-bit.o | \
457 # RUN: FileCheck %s --check-prefix=DEFAULT64
459 # DEFAULT64: Hex dump of section '.debug_aranges':
460 # DEFAULT64-NEXT: 0x00000000 2c000000 02000000 00000800 00000000 ,...............
461 ## ^------- unit_length (4-byte)
462 ## ^--- version (2-byte)
463 ## ^-------- debug_info_offset (4-byte)
464 ## ^- address_size (1-byte)
465 ## ^- segment_selector_size (1-byte)
466 ## ^------- padding (4-byte)
467 # DEFAULT64-NEXT: 0x00000010 34120000 00000000 00100000 00000000 4...............
468 ## ^---------------- address (8-byte)
469 ## ^---------------- length (8-byte)
470 # DEFAULT64-NEXT: 0x00000020 00000000 00000000 00000000 00000000 ................
471 ## ^---------------------------------- terminating entry (16-byte)
473 # RUN: yaml2obj --docnum=10 -DCLASS=ELFCLASS32 %s -o %t10.32-bit.o
474 # RUN: llvm-readelf --hex-dump=.debug_aranges %t10.32-bit.o | \
475 # RUN: FileCheck %s --check-prefix=DEFAULT32
477 # DEFAULT32: Hex dump of section '.debug_aranges':
478 # DEFAULT32-NEXT: 0x00000000 2c000000 02000000 00000400 00000000 ,...............
479 ## ^------- unit_length (4-byte)
480 ## ^--- version (2-byte)
481 ## ^-------- debug_info_offset (4-byte)
482 ## ^- address_size (1-byte)
483 ## ^- segment_selector_size (1-byte)
484 ## ^------- padding (4-byte)
485 # DEFAULT32-NEXT: 0x00000010 34120000 00100000 00000000 00000000 4...............
486 ## ^------- address (4-byte)
487 ## ^------- length (4-byte)
488 ## ^---------------- terminating entry (8-byte)
504 ## k) Test that yaml2obj is able to determine the correct length for the address range table
505 ## if the 'Length' field isn't specified.
507 # RUN: yaml2obj --docnum=11 -DCLASS=ELFCLASS64 -DADDRSIZE=4 %s -o %t11.64-bit.o
508 # RUN: llvm-readelf --hex-dump=.debug_aranges %t11.64-bit.o | \
509 # RUN: FileCheck %s --check-prefix=LENGTH64
511 # LENGTH64: Hex dump of section '.debug_aranges':
512 # LENGTH64-NEXT: 0x00000000 2c000000 02000000 00000800 00000000 ,...............
513 ## ^------- unit_length (4-byte)
514 ## ^--- version (2-byte)
515 ## ^-------- debug_info_offset (4-byte)
516 ## ^- address_size (1-byte)
517 ## ^- segment_selector_size (1-byte)
518 ## ^------- padding (4-byte)
519 # LENGTH64-NEXT: 0x00000010 34120000 00000000 00100000 00000000 4...............
520 ## ^---------------- address (8-byte)
521 ## ^---------------- length (8-byte)
522 # LENGTH64-NEXT: 0x00000020 00000000 00000000 00000000 00000000 ................
523 ## ^---------------------------------- terminating entry (16-byte)
524 # LENGTH64-NEXT: 0x00000030 ffffffff 1c000000 00000000 02000000 ................
525 ## ^------------------------- unit_length (12-byte)
526 ## ^--- version (2-byte)
527 ## ^--- debug_info_offset (8-byte)
528 # LENGTH64-NEXT: 0x00000040 00000000 00000400 34120000 21430000 ........4...!C..
530 ## ^- address_size (1-byte)
531 ## ^- segment_selector_size (1-byte)
532 ## ^------- address (4-byte)
533 ## ^------- length (4-byte)
534 # LENGTH64-NEXT: 0x00000050 00000000 00000000 ........
535 ## ^---------------- terminating entry (8-byte)
537 # RUN: yaml2obj --docnum=11 -DCLASS=ELFCLASS32 -DADDRSIZE=8 %s -o %t11.32-bit.o
538 # RUN: llvm-readelf --hex-dump=.debug_aranges %t11.32-bit.o | \
539 # RUN: FileCheck %s --check-prefix=LENGTH32
541 # LENGTH32: Hex dump of section '.debug_aranges':
542 # LENGTH32-NEXT: 0x00000000 1c000000 02000000 00000400 00000000 ................
543 ## ^------- unit_length (4-byte)
544 ## ^--- version (2-byte)
545 ## ^-------- debug_info_offset (4-byte)
546 ## ^- address_size (1-byte)
547 ## ^- segment_selector_size (1-byte)
548 ## ^------- padding (4-byte)
549 # LENGTH32-NEXT: 0x00000010 34120000 00100000 00000000 00000000 4...............
550 ## ^------- address (4-byte)
551 ## ^------- length (4-byte)
552 ## ^---------------- terminating entry (8-byte)
553 # LENGTH32-NEXT: 0x00000020 ffffffff 34000000 00000000 02000000 ....4...........
554 ## ^------------------------- unit_length (12-byte)
555 ## ^--- version (2-byte)
556 ## ^--- debug_info_offset (8-byte)
557 # LENGTH32-NEXT: 0x00000030 00000000 00000800 00000000 00000000 ................
559 ## ^- address_size (1-byte)
560 ## ^- segment_selector_size (1-byte)
561 ## ^---------------- padding (8-byte)
562 # LENGTH32-NEXT: 0x00000040 34120000 00000000 21430000 00000000 4.......!C......
563 ## ^---------------- address (8-byte)
564 ## ^---------------- length (8-byte)
565 # LENGTH32-NEXT: 0x00000050 00000000 00000000 00000000 00000000 ................
566 ## ^---------------------------------- terminating entry (16-byte)
582 AddressSize: [[ADDRSIZE]]
588 ## l) Test that the .debug_aranges section header is emitted if the "debug_aranges"
591 # RUN: yaml2obj --docnum=12 %s -o %t12.o
592 # RUN: llvm-readobj --sections --section-data %t12.o | \
593 # RUN: FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefixes=DWARF-HEADER,EMPTY-CONTENT
595 # EMPTY-CONTENT-NEXT: SectionData (
596 # EMPTY-CONTENT-NEXT: )