1 ## Test that yaml2obj emits .debug_ranges section.
3 ## a) Generate the .debug_ranges section from the "DWARF" entry.
5 ## Generate and verify a little endian .debug_ranges section.
7 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t.le.o
8 # RUN: llvm-readobj --sections --section-data %t.le.o | \
9 # RUN: FileCheck %s -DSIZE=120 -DADDRALIGN=1 --check-prefixes=DWARF-HEADER,DWARF-LE-CONTENT
11 # DWARF-HEADER: Index: 1
12 # DWARF-HEADER-NEXT: Name: .debug_ranges (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-LE-CONTENT-NEXT: SectionData (
24 # DWARF-LE-CONTENT-NEXT: 0000: 10000000 20000000 30000000 40000000
26 ## | | | +------- HighOffset (4-byte) 0x40
27 ## | | +------- LowOffset (4-byte) 0x30
28 ## | +------- HighOffset (4-byte) 0x20
29 ## +------- LowOffset (4-byte) 0x10
31 # DWARF-LE-CONTENT-NEXT: 0010: FFFFFFFF 10000000 00000000 00000000
33 ## | | | +------- HighOffset (4-byte) 0x00
34 ## | | +------- LowOffset (4-byte) 0x00
35 ## | +------- Base Address (4-byte) 0x10
36 ## +------- Base Address Entry (4-byte) UINT32_MAX
38 # DWARF-LE-CONTENT-NEXT: 0020: 00000000 00000000 10000000 00000000
40 ## | +---------------- LowOffset (8-byte) 0x10
41 ## +---------------- Terminating Entry (8-byte)
43 # DWARF-LE-CONTENT-NEXT: 0030: 20000000 00000000 30000000 00000000
45 ## | +---------------- LowOffset (8-byte) 0x30
46 ## +---------------- HighOffset (8-byte) 0x20
48 # DWARF-LE-CONTENT-NEXT: 0040: 40000000 00000000 FFFFFFFF FFFFFFFF
50 ## | +---------------- Base Address Entry (8-byte) UINT64_MAX
51 ## +---------------- HighOffset (8-byte) 0x40
53 # DWARF-LE-CONTENT-NEXT: 0050: 10000000 00000000 00000000 00000000
55 ## | +---------------- LowOffset (8-byte) 0x00
56 ## +---------------- Base Address (8-byte) 0x10
58 # DWARF-LE-CONTENT-NEXT: 0060: 00000000 00000000 00000000 00000000
60 ## | +---------------- Terminating Entry (16-byte)
61 ## +---------------- HighOffset (8-byte) 0x00
63 # DWARF-LE-CONTENT-NEXT: 0070: 00000000 00000000
65 ## +---------------- Terminating Entry (lower 8-byte)
67 # DWARF-LE-CONTENT-NEXT: )
78 - LowOffset: 0x00000010
79 HighOffset: 0x00000020
80 - LowOffset: 0x00000030
81 HighOffset: 0x00000040
82 - LowOffset: 0xffffffff
83 HighOffset: 0x00000010
84 - LowOffset: 0x00000000
85 HighOffset: 0x00000000
87 - LowOffset: 0x0000000000000010
88 HighOffset: 0x0000000000000020
89 - LowOffset: 0x0000000000000030
90 HighOffset: 0x0000000000000040
91 - LowOffset: 0xffffffffffffffff
92 HighOffset: 0x0000000000000010
93 - LowOffset: 0x0000000000000000
94 HighOffset: 0x0000000000000000
96 ## Generate and verify a big endian .debug_ranges section.
98 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.be.o
99 # RUN: llvm-readobj --sections --section-data %t.be.o | \
100 # RUN: FileCheck %s -DSIZE=120 -DADDRALIGN=1 --check-prefixes=DWARF-HEADER,DWARF-BE-CONTENT
102 # DWARF-BE-CONTENT-NEXT: SectionData (
103 # DWARF-BE-CONTENT-NEXT: 0000: 00000010 00000020 00000030 00000040
105 ## | | | +------- HighOffset (4-byte) 0x40
106 ## | | +------- LowOffset (4-byte) 0x30
107 ## | +------- HighOffset (4-byte) 0x20
108 ## +------- LowOffset (4-byte) 0x10
110 # DWARF-BE-CONTENT-NEXT: 0010: FFFFFFFF 00000010 00000000 00000000
112 ## | | | +------- HighOffset (4-byte) 0x00
113 ## | | +------- LowOffset (4-byte) 0x00
114 ## | +------- Base Address (4-byte) 0x10
115 ## +------- Base Address Entry (4-byte) UINT32_MAX
117 # DWARF-BE-CONTENT-NEXT: 0020: 00000000 00000000 00000000 00000010
119 ## | +---------------- LowOffset (8-byte) 0x10
120 ## +---------------- Terminating Entry (8-byte)
122 # DWARF-BE-CONTENT-NEXT: 0030: 00000000 00000020 00000000 00000030
124 ## | +---------------- LowOffset (8-byte) 0x30
125 ## +---------------- HighOffset (8-byte) 0x20
127 # DWARF-BE-CONTENT-NEXT: 0040: 00000000 00000040 FFFFFFFF FFFFFFFF
129 ## | +---------------- Base Address Entry (8-byte) UINT64_MAX
130 ## +---------------- HighOffset (8-byte) 0x40
132 # DWARF-BE-CONTENT-NEXT: 0050: 00000000 00000010 00000000 00000000
134 ## | +---------------- LowOffset (8-byte) 0x00
135 ## +---------------- Base Address (8-byte) 0x10
137 # DWARF-BE-CONTENT-NEXT: 0060: 00000000 00000000 00000000 00000000
139 ## | +---------------- Terminating Entry (16-byte)
140 ## +---------------- HighOffset (8-byte) 0x00
142 # DWARF-BE-CONTENT-NEXT: 0070: 00000000 00000000
144 ## +---------------- Terminating Entry (lower 8-byte)
146 # DWARF-BE-CONTENT-NEXT: )
148 ## b) Generate the .debug_ranges section from raw section content.
150 # RUN: yaml2obj --docnum=2 %s -o %t2.o
151 # RUN: llvm-readobj --sections --section-data %t2.o | \
152 # RUN: FileCheck %s -DSIZE=3 -DADDRALIGN=0 --check-prefixes=DWARF-HEADER,ARBITRARY-CONTENT
154 # ARBITRARY-CONTENT: SectionData (
155 # ARBITRARY-CONTENT-NEXT: 0000: 112233
156 # ARBITRARY-CONTENT-NEXT: )
164 - Name: .debug_ranges
168 ## c) Generate the .debug_ranges section when the "Size" is specified.
170 # RUN: yaml2obj --docnum=3 %s -o %t3.o
171 # RUN: llvm-readobj --hex-dump=.debug_ranges %t3.o | FileCheck %s --check-prefix=SIZE
173 # SIZE: Hex dump of section '.debug_ranges':
174 # SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................
183 - Name: .debug_ranges
187 ## d) Test that yaml2obj emits an error message when both the "Size" and the
188 ## "debug_ranges" entry are specified at the same time.
190 # RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR
192 # ERROR: yaml2obj: error: cannot specify section '.debug_ranges' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
200 - Name: .debug_ranges
206 - LowOffset: 0x0000000000000001
207 HighOffset: 0x0000000000000002
209 ## e) Test that yaml2obj emits an error message when both the "Content" and the
210 ## "debug_ranges" entry are specified at the same time.
212 # RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR
220 - Name: .debug_ranges
226 - LowOffset: 0x0000000000000001
227 HighOffset: 0x0000000000000002
229 ## f) Test that all the properties can be overridden by the section header when
230 ## the "debug_ranges" entry doesn't exist.
232 # RUN: yaml2obj --docnum=6 %s -o %t6.o
233 # RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN
235 # OVERRIDDEN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
236 # OVERRIDDEN: [ 1] .debug_ranges STRTAB 0000000000002020 000050 000020 01 A 2 1 2
237 # OVERRIDDEN-NEXT: [ 2] .sec STRTAB 0000000000000000 000070 000000 00 0 0 0
245 - Name: .debug_ranges
246 Type: SHT_STRTAB # SHT_PROGBITS by default.
247 Flags: [SHF_ALLOC] # 0 by default.
248 Link: .sec # 0 by default.
249 EntSize: 1 # 0 by default.
250 Info: 1 # 0 by default.
251 AddressAlign: 2 # 0 by default.
252 Address: 0x2020 # 0x00 by default.
253 Offset: 0x50 # 0x40 for the first section.
254 Size: 0x20 # Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
255 - Name: .sec # Linked by .debug_ranges.
258 ## g) Test that all the properties can be overridden by the section header when
259 ## the "debug_ranges" entry exists.
261 # RUN: yaml2obj --docnum=7 %s -o %t7.o
262 # RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN
270 - Name: .debug_ranges
271 Type: SHT_STRTAB # SHT_PROGBITS by default.
272 Flags: [SHF_ALLOC] # 0 by default.
273 Link: .sec # 0 by default.
274 EntSize: 1 # 0 by default.
275 Info: 1 # 0 by default.
276 AddressAlign: 2 # 1 by default.
277 Address: 0x2020 # 0x00 by default.
278 Offset: 0x50 # 0x40 for the first section.
279 - Name: .sec # Linked by .debug_ranges.
284 - LowOffset: 0x0000000000000001
285 HighOffset: 0x0000000000000002
287 ## h) Test that yaml2obj automatically pads zeros if we try to assign an offset that
288 ## is greater than or equal to the number of bytes written already.
290 # RUN: yaml2obj --docnum=8 %s -o %t8.o
291 # RUN: llvm-readelf --hex-dump=.debug_ranges %t8.o | FileCheck %s --check-prefix=PADDED
293 # PADDED: Hex dump of section '.debug_ranges':
294 # PADDED-NEXT: 0x00000000 01000000 00000000 02000000 00000000
296 ## | +---------------- HighOffset (8-byte) 0x02
297 ## +---------------- LowOffset (8-byte) 0x01
299 # PADDED-NEXT: 0x00000010 00000000 00000000 00000000 00000000
301 ## +---------------------------------- Terminating Entry (16-byte) 0x00
303 # PADDED-NEXT: 0x00000020 00010000 00000000 00020000 00000000
305 ## | | +------------- HighOffset (8-byte) 0x02
306 ## | +----------------- LowOffset (8-byte) 0x01
307 ## +- Padded zeros (1-byte) 0x00
309 # PADDED-NEXT: 0x00000030 00000000 00000000 00000000 00000000
311 ## | +-------------------------------- Terminating Entry (16-byte) 0x00
312 ## +- higher byte(s) of HighOffset
314 # PADDED-NEXT: 0x00000040 00010000 00000000 00020000 00000000
316 ## | | +-------------- HighOffset (8-byte) 0x02
317 ## | +----------------- LowOffset (8-byte) 0x01
318 ## +- the last byte of terminating entry.
320 # PADDED-NEXT: 0x00000050 00000000 00000000 00000000 00000000
322 ## | +-------------------------------- Terminating Entry (16-byte) 0x00
323 ## +- higher byte(s) of HighOffset
325 # PADDED-NEXT: 0x00000060 00
327 ## +- the last byte of terminating entry.
339 - Offset: 0x21 ## There are 0x20 bytes before this entry.
343 - Offset: 0x41 ## There are 0x41 bytes before this entry.
348 ## i) Test that yaml2obj emits an error message if we try to assign an invalid offset to an
349 ## entry of the '.debug_ranges' section.
351 # RUN: not yaml2obj --docnum=9 %s -o %t9.o 2>&1 | FileCheck %s --check-prefix=INVALID-OFFSET
353 # INVALID-OFFSET: yaml2obj: error: 'Offset' for 'debug_ranges' with index 1 must be greater than or equal to the number of bytes written already (0x20)
365 - Offset: 0x1F ## Must be greater than or equal to 0x20.
370 ## j) Test that yaml2obj still generates a .debug_ranges section if we assign an invalid value
371 ## to 'AddrSize' when the 'Entries' list is empty.
373 # RUN: yaml2obj --docnum=10 %s -o %t10.o
374 # RUN: llvm-readelf --hex-dump=.debug_ranges %t10.o | \
375 # RUN: FileCheck %s --check-prefix=ADDRSIZE
377 # ADDRSIZE: Hex dump of section '.debug_ranges':
378 # ADDRSIZE-NEXT: 0x00000000 00000000 00000000 00000000 0000
379 ## ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ terminating entry (2*AddrSize=14-byte)
391 ## k) Test that yaml2obj emits an error message if we try to assign an invalid value to
392 ## 'AddrSize' when the 'Entries' list isn't empty.
394 # RUN: not yaml2obj --docnum=11 %s 2>&1 | \
395 # RUN: FileCheck %s --check-prefix=INVALID-SIZE
397 # INVALID-SIZE: yaml2obj: error: unable to write debug_ranges address offset: invalid integer write size: 7
411 ## l) Test that the .debug_ranges section header is emitted if the "debug_ranges"
414 # RUN: yaml2obj --docnum=12 %s -o %t12.o
415 # RUN: llvm-readobj -S %t12.o | FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefix=DWARF-HEADER