1## Test that yaml2obj emits a .debug_rnglists section when requested.
2
3## a) Generate and verify a little endian DWARF32 .debug_rnglists section in a 64-bit object file.
4
5# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.le.dwarf32.o
6# RUN: llvm-readobj --sections --section-data %t1.le.dwarf32.o | \
7# RUN:   FileCheck -DSIZE=99 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-LE
8
9#            SHDR: Index: 1
10#       SHDR-NEXT: Name: .debug_rnglists (1)
11#       SHDR-NEXT: Type: SHT_PROGBITS (0x1)
12#       SHDR-NEXT: Flags [ (0x0)
13#       SHDR-NEXT: ]
14#       SHDR-NEXT: Address: 0x0
15#       SHDR-NEXT: Offset: 0x40
16#       SHDR-NEXT: Size: [[SIZE]]
17#       SHDR-NEXT: Link: 0
18#       SHDR-NEXT: Info: 0
19#       SHDR-NEXT: AddressAlignment: [[ADDRALIGN]]
20#       SHDR-NEXT: EntrySize: 0
21# DWARF32-LE-NEXT: SectionData (
22# DWARF32-LE-NEXT:   0000: 24000000 05000800 02000000 08000000  |$...............|
23##                         ^-------                             unit_length (4-byte)
24##                                  ^---                        version (2-byte)
25##                                      ^-                      address_size (1-byte)
26##                                        ^-                    segment_selector_size (1-byte)
27##                                           ^-------           offset_entry_count (4-byte)
28##                                                    ^-------  offsets[0] (4-byte)
29# DWARF32-LE-NEXT:   0010: 11000000 01B42402 B424B424 0003B424  |......$..$.$...$|
30##                         ^-------                             offsets[1] (4-byte)
31##                                  ^-                          DW_RLE_base_addressx (1-byte)
32##                                    ^---                      operands[0] (ULEB128) 0x1234
33##                                        ^-                    DW_RLE_startx_endx (1-byte)
34##                                           ^---               operands[0] (ULEB128) 0x1234
35##                                               ^---           operands[1] (ULEB128) 0x1234
36##                                                    ^-        DW_RLE_end_of_list (1-byte)
37##                                                      ^-      DW_RLE_startx_length (1-byte)
38##                                                        ^---  operands[0] (ULEB128) 0x1234
39# DWARF32-LE-NEXT:   0020: B42404B4 24B42400 37000000 05000800  |.$..$.$.7.......|
40##                         ^---                                 operands[1] (ULEB128) 0x1234
41##                             ^-                               DW_RLE_offset_pair (1-byte)
42##                               ^----                          operands[0] (ULEB128) 0x1234
43##                                    ^---                      operands[1] (ULEB128) 0x1234
44##                                        ^-                    DW_RLE_end_of_list (1-byte)
45##                                           ^-------           unit_length (4-byte)
46##                                                    ^---      version (2-byte)
47##                                                        ^-    address_size (1-byte)
48##                                                          ^-  segment_selector_size (1-byte)
49# DWARF32-LE-NEXT:   0030: 02000000 08000000 23000000 05341200  |........#....4..|
50##                         ^-------                             offset_entry_count (4-byte)
51##                                  ^-------                    offsets[0] (4-byte)
52##                                           ^-------           offsets[1] (4-byte)
53##                                                    ^-        DW_RLE_base_address (1-byte)
54##                                                      ^-----  operands[0] (8-byte)
55# DWARF32-LE-NEXT:   0040: 00000000 00063412 00000000 00003412  |......4.......4.|
56##                         -----------
57##                                    ^-                        DW_RLE_start_end (1-byte)
58##                                      ^-----------------      operands[0] (8-byte)
59##                                                        ^---  operands[1] (8-byte)
60# DWARF32-LE-NEXT:   0050: 00000000 00000007 34120000 00000000  |........4.......|
61##                         -------------
62##                                      ^-                      DW_RLE_end_of_list (1-byte)
63##                                        ^-                    DW_RLE_start_length (1-byte)
64##                                           ^----------------  operands[0] (8-byte)
65# DWARF32-LE-NEXT:   0060: B42400                               |.$.|
66##                         ^---                                 operands[1] (ULEB128) 0x1234
67##                             ^-                               DW_RLE_end_of_list (1-byte)
68# DWARF32-LE-NEXT: )
69
70--- !ELF
71FileHeader:
72  Class: ELFCLASS64
73  Data:  [[ENDIAN]]
74  Type:  ET_EXEC
75DWARF:
76  debug_rnglists:
77    - Lists:
78        - Entries:
79            - Operator: DW_RLE_base_addressx
80              Values:   [ 0x1234 ]
81            - Operator: DW_RLE_startx_endx
82              Values:   [ 0x1234, 0x1234 ]
83            - Operator: DW_RLE_end_of_list
84        - Entries:
85            - Operator: DW_RLE_startx_length
86              Values:   [ 0x1234, 0x1234 ]
87            - Operator: DW_RLE_offset_pair
88              Values:   [ 0x1234, 0x1234 ]
89            - Operator: DW_RLE_end_of_list
90    - Lists:
91        - Entries:
92            - Operator: DW_RLE_base_address
93              Values:   [ 0x1234 ]
94            - Operator: DW_RLE_start_end
95              Values:   [ 0x1234, 0x1234 ]
96            - Operator: DW_RLE_end_of_list
97        - Entries:
98            - Operator: DW_RLE_start_length
99              Values:   [ 0x1234, 0x1234 ]
100            - Operator: DW_RLE_end_of_list
101
102## b) Generate and verify a big endian DWARF32 .debug_rnglists section in a 64-bit object file.
103
104# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t1.be.dwarf32.o
105# RUN: llvm-readobj --sections --section-data %t1.be.dwarf32.o | \
106# RUN:   FileCheck -DSIZE=99 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-BE
107
108# DWARF32-BE-NEXT: SectionData (
109# DWARF32-BE-NEXT:   0000: 00000024 00050800 00000002 00000008  |...$............|
110##                         ^-------                             unit_length (4-byte)
111##                                  ^---                        version (2-byte)
112##                                      ^-                      address_size (1-byte)
113##                                        ^-                    segment_selector_size (1-byte)
114##                                           ^-------           offset_entry_count (4-byte)
115##                                                    ^-------  offsets[0] (4-byte)
116# DWARF32-BE-NEXT:   0010: 00000011 01B42402 B424B424 0003B424  |......$..$.$...$|
117##                         ^-------                             offsets[1] (4-byte)
118##                                  ^-                          DW_RLE_base_addressx (1-byte)
119##                                    ^---                      operands[0] (ULEB128) 0x1234
120##                                        ^-                    DW_RLE_startx_endx (1-byte)
121##                                           ^---               operands[0] (ULEB128) 0x1234
122##                                               ^---           operands[1] (ULEB128) 0x1234
123##                                                    ^-        DW_RLE_end_of_list (1-byte)
124##                                                      ^-      DW_RLE_startx_length (1-byte)
125##                                                        ^---  operands[0] (ULEB128) 0x1234
126# DWARF32-BE-NEXT:   0020: B42404B4 24B42400 00000037 00050800  |.$..$.$....7....|
127##                         ^---                                 operands[1] (ULEB128) 0x1234
128##                             ^-                               DW_RLE_offset_pair (1-byte)
129##                               ^----                          operands[0] (ULEB128) 0x1234
130##                                    ^---                      operands[1] (ULEB128) 0x1234
131##                                        ^-                    DW_RLE_end_of_list (1-byte)
132##                                           ^-------           unit_length (4-byte)
133##                                                    ^---      version (2-byte)
134##                                                        ^-    address_size (1-byte)
135##                                                          ^-  segment_selector_size (1-byte)
136# DWARF32-BE-NEXT:   0030: 00000002 00000008 00000023 05000000  |...........#....|
137##                         ^-------                             offset_entry_count (4-byte)
138##                                  ^-------                    offsets[0] (4-byte)
139##                                           ^-------           offsets[1] (4-byte)
140##                                                    ^-        DW_RLE_base_address (1-byte)
141##                                                      ^-----  operands[0] (8-byte)
142# DWARF32-BE-NEXT:   0040: 00000012 34060000 00000000 12340000  |....4........4..|
143##                         -----------
144##                                    ^-                        DW_RLE_start_end (1-byte)
145##                                      ^-----------------      operands[0] (8-byte)
146##                                                        ^---  operands[1] (8-byte)
147# DWARF32-BE-NEXT:   0050: 00000000 12340007 00000000 00001234  |.....4.........4|
148##                         -------------
149##                                      ^-                      DW_RLE_end_of_list (1-byte)
150##                                        ^-                    DW_RLE_start_length (1-byte)
151##                                           ^----------------  operands[0] (8-byte)
152# DWARF32-BE-NEXT:   0060: B42400                               |.$.|
153##                         ^---                                 operands[1] (ULEB128) 0x1234
154##                             ^-                               DW_RLE_end_of_list (1-byte)
155# DWARF32-BE-NEXT: )
156
157## c) Generate and verify a little endian DWARF64 .debug_rnglists section in a 64-bit object file.
158
159# RUN: yaml2obj --docnum=2 -DENDIAN=ELFDATA2LSB %s -o %t2.le.dwarf64.o
160# RUN: llvm-readobj --sections --section-data %t2.le.dwarf64.o | \
161# RUN:   FileCheck -DSIZE=38 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-LE
162
163# DWARF64-LE-NEXT: SectionData (
164# DWARF64-LE-NEXT:   0000: FFFFFFFF 1A000000 00000000 05000800  |................|
165##                         ^-------------------------           unit_length (12-byte)
166##                                                    ^---      version (2-byte)
167##                                                        ^-    address_size (1-byte)
168##                                                          ^-  segment_selector_size (1-byte)
169# DWARF64-LE-NEXT:   0010: 02000000 10000000 00000000 11000000  |................|
170##                         ^-------                             offset_entry_count (4-byte)
171##                                  ^----------------           offsets[0] (8-byte)
172##                                                    ^-------  offsets[1] (8-byte)
173# DWARF64-LE-NEXT:   0020: 00000000 0000                        |......|
174##                         --------
175##                                  ^-                          DW_RLE_end_of_list (1-byte)
176##                                    ^-                        DW_RLE_end_of_list (1-byte)
177# DWARF64-LE-NEXT: )
178
179--- !ELF
180FileHeader:
181  Class: ELFCLASS64
182  Data:  [[ENDIAN]]
183  Type:  ET_EXEC
184DWARF:
185  debug_rnglists:
186    - Format:  DWARF64
187      Lists:
188        - Entries:
189            - Operator: DW_RLE_end_of_list
190        - Entries:
191            - Operator: DW_RLE_end_of_list
192
193## d) Generate and verify a big endian DWARF64 .debug_rnglists section in a 64-bit object file.
194
195# RUN: yaml2obj --docnum=2 -DENDIAN=ELFDATA2MSB %s -o %t2.be.dwarf64.o
196# RUN: llvm-readobj --sections --section-data %t2.be.dwarf64.o | \
197# RUN:   FileCheck -DSIZE=38 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-BE
198
199# DWARF64-BE-NEXT: SectionData (
200# DWARF64-BE-NEXT:   0000: FFFFFFFF 00000000 0000001A 00050800  |................|
201##                         ^-------------------------           unit_length (12-byte)
202##                                                    ^---      version (2-byte)
203##                                                        ^-    address_size (1-byte)
204##                                                          ^-  segment_selector_size (1-byte)
205# DWARF64-BE-NEXT:   0010: 00000002 00000000 00000010 00000000  |................|
206##                         ^-------                             offset_entry_count (4-byte)
207##                                  ^----------------           offsets[0] (8-byte)
208##                                                    ^-------  offsets[1] (8-byte)
209# DWARF64-BE-NEXT:   0020: 00000011 0000                        |......|
210##                         --------
211##                                  ^-                          DW_RLE_end_of_list (1-byte)
212##                                    ^-                        DW_RLE_end_of_list (1-byte)
213# DWARF64-BE-NEXT: )
214
215## e) Test that the length, version, segment_selector_size, address_size, offset_entry_count
216## and offsets fields can be specified manually.
217
218# RUN: yaml2obj --docnum=3 %s -o %t3.o
219# RUN: llvm-readelf --hex-dump=.debug_rnglists %t3.o | \
220# RUN:   FileCheck %s --check-prefix=OVERWRITE
221
222#      OVERWRITE: Hex dump of section '.debug_rnglists':
223# OVERWRITE-NEXT: 0x00000000 34120000 06000303 04000000 01000000 4...............
224##                           ^-------                            unit_length (4-byte)
225##                                    ^---                       version (2-byte)
226##                                        ^-                     address_size (1-byte)
227##                                          ^-                   segment_selector_size (1-byte)
228##                                             ^-------          offset_entry_count (4-byte)
229##                                                      ^------- offsets[0] (4-byte)
230# OVERWRITE-NEXT: 0x00000010 0000                                ..
231
232--- !ELF
233FileHeader:
234  Class: ELFCLASS64
235  Data:  ELFDATA2LSB
236  Type:  ET_EXEC
237DWARF:
238  debug_rnglists:
239    - Length:              0x1234
240      Version:             6
241      AddressSize:         3
242      SegmentSelectorSize: 3
243      OffsetEntryCount:    4
244      Offsets:             [ 0x01 ]
245      Lists:
246        - Entries:
247            - Operator: DW_RLE_end_of_list
248        - Entries:
249            - Operator: DW_RLE_end_of_list
250
251## f) Test that the default value of the address_size field in a 32-bit object file is 4.
252
253# RUN: yaml2obj --docnum=4 %s -o %t4.o
254# RUN: llvm-readelf --hex-dump=.debug_rnglists %t4.o | \
255# RUN:   FileCheck %s --check-prefix=ADDRSIZE32
256
257#      ADDRSIZE32: Hex dump of section '.debug_rnglists':
258# ADDRSIZE32-NEXT: 0x00000000 22000000 05000400 01000000 04000000 "...............
259##                                         ^-                     address_size (1-byte)
260# ADDRSIZE32-NEXT: 0x00000010 05341200 00063412 00002143 00000734 .4....4...!C...4
261##                            ^-                                  DW_RLE_base_address (1-byte)
262##                              ^--------                         operands[0] (4-byte)
263##                                       ^-                       DW_RLE_start_end (1-byte)
264##                                         ^--------              operands[0] (4-byte)
265##                                                  ^--------     operands[1] (4-byte)
266##                                                           ^-   DW_RLE_start_length (1-byte)
267##                                                             ^- operands[0] (4-byte)
268# ADDRSIZE32-NEXT: 0x00000020 120000a1 8601                       ......
269##                            ------
270##                                  ^------                       operands[1] (ULEB128) 0x4321
271
272--- !ELF
273FileHeader:
274  Class: ELFCLASS32
275  Data:  ELFDATA2LSB
276  Type:  ET_EXEC
277DWARF:
278  debug_rnglists:
279    - Lists:
280        - Entries:
281            - Operator: DW_RLE_base_address
282              Values:   [ 0x1234 ]
283            - Operator: DW_RLE_start_end
284              Values:   [ 0x1234, 0x4321 ]
285            - Operator: DW_RLE_start_length
286              Values:   [ 0x1234, 0x4321 ]
287
288## g) Test that the address_size field can be specified manually and the size of
289## corresponding operands will be changed accordingly.
290
291# RUN: yaml2obj --docnum=5 %s -o %t5.o
292# RUN: llvm-readelf --hex-dump=.debug_rnglists %t5.o | \
293# RUN:   FileCheck %s --check-prefix=ADDRSIZE
294
295#      ADDRSIZE: Hex dump of section '.debug_rnglists':
296# ADDRSIZE-NEXT: 0x00000000 22000000 05000400 01000000 04000000 "...............
297##                                       ^-                     address_size 0x04
298# ADDRSIZE-NEXT: 0x00000010 05341200 00063412 00002143 00000734 .4....4...!C...4
299##                          ^-                                  DW_RLE_base_address
300##                            ^--------                         operands[0] (4-byte)
301##                                     ^-                       DW_RLE_start_end
302##                                       ^--------              operands[0] (4-byte)
303##                                                ^--------     operands[1] (4-byte)
304##                                                         ^-   DW_RLE_start_length
305##                                                           ^- operands[0] (4-byte)
306# ADDRSIZE-NEXT: 0x00000020 120000b4 2400                       ....$.
307##                          ------
308##                                ^----                         operands[1] (ULEB128)
309##                                     ^-                       DW_RLE_end_of_list
310
311--- !ELF
312FileHeader:
313  Class: ELFCLASS64
314  Data:  ELFDATA2LSB
315  Type:  ET_EXEC
316DWARF:
317  debug_rnglists:
318    - AddressSize: 4
319      Lists:
320        - Entries:
321            - Operator: DW_RLE_base_address
322              Values:   [ 0x1234 ]
323            - Operator: DW_RLE_start_end
324              Values:   [ 0x1234, 0x4321 ]
325            - Operator: DW_RLE_start_length
326              Values:   [ 0x1234, 0x1234 ]
327            - Operator: DW_RLE_end_of_list
328
329## h) Test that yaml2obj emits an error message if we try to assign an invalid value to
330## 'AddressSize' when there is an entry whose operands contain address.
331
332# RUN: not yaml2obj -DOPERATOR=base_address -DVALUES=[0x01] --docnum=6 %s 2>&1 | \
333# RUN:   FileCheck -DOPERATOR=base_address %s --check-prefix=INVALID-ADDRSIZE
334
335# RUN: not yaml2obj -DOPERATOR=start_end -DVALUES=[0x01,0x02] --docnum=6 %s 2>&1 | \
336# RUN:   FileCheck -DOPERATOR=start_end %s --check-prefix=INVALID-ADDRSIZE
337
338# RUN: not yaml2obj -DOPERATOR=start_length -DVALUES=[0x01,0x02] --docnum=6 %s 2>&1 | \
339# RUN:   FileCheck -DOPERATOR=start_length %s --check-prefix=INVALID-ADDRSIZE
340
341# INVALID-ADDRSIZE: yaml2obj: error: unable to write address for the operator DW_RLE_[[OPERATOR]]: invalid integer write size: 3
342
343--- !ELF
344FileHeader:
345  Class: ELFCLASS64
346  Data:  ELFDATA2LSB
347  Type:  ET_EXEC
348DWARF:
349  debug_rnglists:
350    - AddressSize: 3
351      Lists:
352        - Entries:
353            - Operator: DW_RLE_[[OPERATOR]]
354              Values:   [[VALUES]]
355
356## i) Test that an invalid address_size can be used when there are no address-using operators.
357
358# RUN: yaml2obj --docnum=7 %s -o %t7.o
359# RUN: llvm-readelf --hex-dump=.debug_rnglists %t7.o | \
360# RUN:   FileCheck %s --check-prefix=ADDRSIZE-NOERROR
361
362#      ADDRSIZE-NOERROR: Hex dump of section '.debug_rnglists':
363# ADDRSIZE-NOERROR-NEXT: 0x00000000 0e000000 05000300 01000000 04000000 ................
364##                                               ^-                     address_size (1-byte) 0x03
365# ADDRSIZE-NOERROR-NEXT: 0x00000010 0101                                ..
366
367--- !ELF
368FileHeader:
369  Class: ELFCLASS64
370  Data:  ELFDATA2LSB
371  Type:  ET_EXEC
372DWARF:
373  debug_rnglists:
374    - AddressSize: 3
375      Lists:
376        - Entries:
377            - Operator: DW_RLE_base_addressx
378              Values:   [ 0x01 ]
379
380## j) Test that yaml2obj emits an error message if we specify invalid numbers of operands
381## for an operator.
382
383# RUN: not yaml2obj -DOPERATOR=end_of_list -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
384# RUN:   FileCheck -DOPERATOR=end_of_list -DACTUAL=1 -DEXPECTED=0 %s --check-prefix=INVALID-OPERANDS
385
386# RUN: not yaml2obj -DOPERATOR=base_addressx -DVALUES=[] --docnum=8 %s 2>&1 | \
387# RUN:   FileCheck -DOPERATOR=base_addressx -DACTUAL=0 -DEXPECTED=1 %s --check-prefix=INVALID-OPERANDS
388
389# RUN: not yaml2obj -DOPERATOR=startx_endx -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
390# RUN:   FileCheck -DOPERATOR=startx_endx -DACTUAL=1 -DEXPECTED=2 %s --check-prefix=INVALID-OPERANDS
391
392# RUN: not yaml2obj -DOPERATOR=startx_length -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
393# RUN:   FileCheck -DOPERATOR=startx_length -DACTUAL=1 -DEXPECTED=2 %s --check-prefix=INVALID-OPERANDS
394
395# RUN: not yaml2obj -DOPERATOR=offset_pair -DVALUES=[] --docnum=8 %s 2>&1 | \
396# RUN:   FileCheck -DOPERATOR=offset_pair -DACTUAL=0 -DEXPECTED=2 %s --check-prefix=INVALID-OPERANDS
397
398# RUN: not yaml2obj -DOPERATOR=base_address -DVALUES=[0x01,0x02] --docnum=8 %s 2>&1 | \
399# RUN:   FileCheck -DOPERATOR=base_address -DACTUAL=2 -DEXPECTED=1 %s --check-prefix=INVALID-OPERANDS
400
401# RUN: not yaml2obj -DOPERATOR=start_end -DVALUES=[0x01,0x02,0x03] --docnum=8 %s 2>&1 | \
402# RUN:   FileCheck -DOPERATOR=start_end -DACTUAL=3 -DEXPECTED=2 %s --check-prefix=INVALID-OPERANDS
403
404# RUN: not yaml2obj -DOPERATOR=start_length -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
405# RUN:   FileCheck -DOPERATOR=start_length -DACTUAL=1 -DEXPECTED=2 %s --check-prefix=INVALID-OPERANDS
406
407# INVALID-OPERANDS: yaml2obj: error: invalid number ([[ACTUAL]]) of operands for the operator: DW_RLE_[[OPERATOR]], [[EXPECTED]] expected
408
409--- !ELF
410FileHeader:
411  Class: ELFCLASS64
412  Data:  ELFDATA2LSB
413  Type:  ET_EXEC
414DWARF:
415  debug_rnglists:
416    - AddressSize: 3
417      Lists:
418        - Entries:
419            - Operator: DW_RLE_[[OPERATOR]]
420              Values:   [[VALUES]]
421
422## k) Test that an empty list is allowed for a range list table.
423
424# RUN: yaml2obj --docnum=9 %s -o %t9.o
425# RUN: llvm-readelf --hex-dump=.debug_rnglists %t9.o | \
426# RUN:   FileCheck %s --check-prefix=EMPTY-LIST
427
428#      EMPTY-LIST: Hex dump of section '.debug_rnglists':
429# EMPTY-LIST-NEXT: 0x00000000 08000000 05000800 00000000          ............
430##                            ^-------                            unit_length (4-byte)
431##                                     ^---                       version (2-byte)
432##                                         ^---                   address_size (1-byte)
433##                                              ^-------          offset_entry_count (4-byte)
434
435--- !ELF
436FileHeader:
437  Class: ELFCLASS64
438  Data:  ELFDATA2LSB
439  Type:  ET_EXEC
440DWARF:
441  debug_rnglists:
442    - Lists: []
443
444## l) Generate the .debug_rnglists section from raw section content.
445
446# RUN: yaml2obj --docnum=10 %s -o %t10.o
447# RUN: llvm-readobj --sections --section-data %t10.o | \
448# RUN:   FileCheck %s -DSIZE=3 -DADDRALIGN=0 --check-prefixes=SHDR,ARBITRARY-CONTENT
449
450#      ARBITRARY-CONTENT: SectionData (
451# ARBITRARY-CONTENT-NEXT:   0000: 112233
452# ARBITRARY-CONTENT-NEXT: )
453
454--- !ELF
455FileHeader:
456  Class: ELFCLASS64
457  Data:  ELFDATA2LSB
458  Type:  ET_EXEC
459Sections:
460  - Name:    .debug_rnglists
461    Type:    SHT_PROGBITS
462    Content: "112233"
463
464## m) Generate the .debug_rnglists section when the "Size" is specified.
465
466# RUN: yaml2obj --docnum=11 %s -o %t11.o
467# RUN: llvm-readelf --hex-dump=.debug_rnglists %t11.o | \
468# RUN:   FileCheck %s --check-prefix=SIZE
469
470#       SIZE: Hex dump of section '.debug_rnglists':
471#  SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................
472# SIZE-EMPTY:
473
474--- !ELF
475FileHeader:
476  Class: ELFCLASS64
477  Data:  ELFDATA2LSB
478  Type:  ET_EXEC
479Sections:
480  - Name: .debug_rnglists
481    Type: SHT_PROGBITS
482    Size: 0x10
483
484## n) Test that yaml2obj emits an error message when both the "Size" and the
485## "debug_rnglists" entry are specified at the same time.
486
487# RUN: not yaml2obj --docnum=12 %s 2>&1 | FileCheck %s --check-prefix=ERROR
488
489# ERROR: yaml2obj: error: cannot specify section '.debug_rnglists' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
490
491--- !ELF
492FileHeader:
493  Class: ELFCLASS64
494  Data:  ELFDATA2LSB
495  Type:  ET_EXEC
496Sections:
497  - Name: .debug_rnglists
498    Type: SHT_PROGBITS
499    Size: 0x10
500DWARF:
501  debug_rnglists:
502    - Lists: []
503
504## o) Test that yaml2obj emits an error message when both the "Content" and the
505## "debug_rnglists" entry are specified at the same time.
506
507# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=ERROR
508
509--- !ELF
510FileHeader:
511  Class: ELFCLASS64
512  Data:  ELFDATA2LSB
513  Type:  ET_EXEC
514Sections:
515  - Name:    .debug_rnglists
516    Type:    SHT_PROGBITS
517    Content: "00"
518DWARF:
519  debug_rnglists:
520    - Lists: []
521
522## p) Test that all the properties can be overridden by the section header when
523## the "debug_rnglists" entry doesn't exist.
524
525# RUN: yaml2obj --docnum=14 %s -o %t14.o
526# RUN: llvm-readelf --sections %t14.o | FileCheck %s --check-prefix=OVERRIDDEN
527
528#      OVERRIDDEN: [Nr] Name            Type   Address          Off    Size   ES Flg Lk Inf Al
529#      OVERRIDDEN: [ 1] .debug_rnglists STRTAB 0000000000002020 000050 00000c 01   A  2   1  2
530# OVERRIDDEN-NEXT: [ 2] .sec            STRTAB 0000000000000000 00005c 000000 00      0   0  0
531
532--- !ELF
533FileHeader:
534  Class: ELFCLASS64
535  Data:  ELFDATA2LSB
536  Type:  ET_EXEC
537Sections:
538  - Name:         .debug_rnglists
539    Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
540    Flags:        [SHF_ALLOC] ## 0 by default.
541    Link:         .sec        ## 0 by default.
542    EntSize:      1           ## 0 by default.
543    Info:         1           ## 0 by default.
544    AddressAlign: 2           ## 0 by default.
545    Address:      0x2020      ## 0x00 by default.
546    Offset:       0x50        ## 0x40 for the first section.
547    Size:         0x0c        ## Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
548  - Name:         .sec        ## Linked by .debug_rnglists.
549    Type:         SHT_STRTAB
550
551## q) Test that all the properties can be overridden by the section header when
552## the "debug_rnglists" entry exists.
553
554# RUN: yaml2obj --docnum=15 %s -o %t15.o
555# RUN: llvm-readelf --sections %t15.o | FileCheck %s --check-prefix=OVERRIDDEN
556
557--- !ELF
558FileHeader:
559  Class: ELFCLASS64
560  Data:  ELFDATA2LSB
561  Type:  ET_EXEC
562Sections:
563  - Name:         .debug_rnglists
564    Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
565    Flags:        [SHF_ALLOC] ## 0 by default.
566    Link:         .sec        ## 0 by default.
567    EntSize:      1           ## 0 by default.
568    Info:         1           ## 0 by default.
569    AddressAlign: 2           ## 1 by default.
570    Address:      0x2020      ## 0x00 by default.
571    Offset:       0x50        ## 0x40 for the first section.
572  - Name:         .sec        ## Linked by .debug_rnglists.
573    Type:         SHT_STRTAB
574DWARF:
575  debug_rnglists:
576    - Lists: []
577
578## r) Test that the .debug_rnglists section header is emitted if the "debug_rnglists"
579## entry is empty.
580
581# RUN: yaml2obj --docnum=16 %s -o %t16.o
582# RUN: llvm-readobj --sections --section-data %t16.o | \
583# RUN:   FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefixes=SHDR,EMPTY-CONTENT
584
585# EMPTY-CONTENT-NEXT: SectionData (
586# EMPTY-CONTENT-NEXT: )
587
588--- !ELF
589FileHeader:
590  Class: ELFCLASS64
591  Data:  ELFDATA2LSB
592  Type:  ET_EXEC
593DWARF:
594  debug_rnglists: []
595
596## s) Test that we are able to generate a range list via raw binary data.
597
598# RUN: yaml2obj --docnum=17 %s -o %t17.o
599# RUN: llvm-readelf --hex-dump=.debug_rnglists %t17.o | \
600# RUN:   FileCheck %s --check-prefix=CUSTOM-LIST
601
602#      CUSTOM-LIST: Hex dump of section '.debug_rnglists':
603# CUSTOM-LIST-NEXT: 0x00000000 29000000 05000800 03000000 0c000000 )...............
604##                             ^-------                            unit_length (4-byte)
605##                                      ^---                       version (2-byte)
606##                                          ^-                     address_size (1-byte)
607##                                            ^-                   segment_selector_size (1-byte)
608##                                               ^-------          offset_entry_count (4-byte)
609##                                                        ^------- offsets[0] (4-byte)
610# CUSTOM-LIST-NEXT: 0x00000010 11000000 19000000 02b424b4 24123456 ..........$.$.4V
611##                             ^-------                            offsets[1] (4-byte)
612##                                      ^-------                   offsets[2] (4-byte)
613##                                               ^-                DW_RLE_startx_endx
614##                                                 ^---            operands[0] (ULEB128) 0x1234
615##                                                     ^----       operands[1] (ULEB128) 0x1234
616##                                                          ^----- custom list content
617# CUSTOM-LIST-NEXT: 0x00000020 7890abcd efabcdef 12345678 90       x........4Vx.
618##                             -----------
619##                                        ^-----------------       custom list content
620
621--- !ELF
622FileHeader:
623  Class: ELFCLASS64
624  Data:  ELFDATA2LSB
625  Type:  ET_EXEC
626DWARF:
627  debug_rnglists:
628    - Lists:
629        - Entries:
630            - Operator: DW_RLE_startx_endx
631              Values:   [ 0x1234, 0x1234 ]
632        - Content: '1234567890abcdef'
633        - Content: 'abcdef1234567890'
634
635## t) Test that yaml2obj emits an error message when 'Content' and 'Entries' are specified
636## at the same time.
637
638# RUN: not yaml2obj --docnum=18 %s 2>&1 | FileCheck %s --check-prefix=ERR
639
640#      ERR: YAML:{{.*}}: error: Entries and Content can't be used together
641# ERR-NEXT:         - Entries: []
642# ERR-NEXT:           ^
643
644--- !ELF
645FileHeader:
646  Class: ELFCLASS64
647  Data:  ELFDATA2LSB
648  Type:  ET_EXEC
649DWARF:
650  debug_rnglists:
651    - Lists:
652        - Entries: []
653          Content: ''
654
655## u) Test that when the "OffsetEntryCount" is specified to be 0 and "Offsets" is not specified,
656## the offsets array is not emitted.
657
658# RUN: yaml2obj --docnum=19 -DENTRYCOUNT=0 %s -o %t19.o
659# RUN: llvm-readelf --hex-dump=.debug_rnglists %t19.o | \
660# RUN:   FileCheck %s --check-prefix=NO-OFFSETS
661
662#      NO-OFFSETS: Hex dump of section '.debug_rnglists':
663# NO-OFFSETS-NEXT: 0x00000000 0e000000 05000800 00000000 02010202 ................
664##                                              ^-------          offset_entry_count (4-byte)
665##                                                       ^-       DW_RLE_startx_endx
666##                                                         ^-     operands[0] (ULEB128) 0x01
667##                                                           ^-   operands[1] (ULEB128) 0x02
668##                                                             ^- DW_RLE_startx_endx
669# NO-OFFSETS-NEXT: 0x00000010 0102                                ..
670##                            ^-                                  operands[0] (ULEB128) 0x01
671##                              ^-                                operands[1] (ULEB128) 0x02
672
673--- !ELF
674FileHeader:
675  Class: ELFCLASS64
676  Data:  ELFDATA2LSB
677  Type:  ET_EXEC
678DWARF:
679  debug_rnglists:
680    - OffsetEntryCount: [[ENTRYCOUNT=<none>]]
681      Offsets:          [[OFFSETS=<none>]]
682      Lists:
683        - Entries:
684            - Operator: DW_RLE_startx_endx
685              Values:   [ 0x01, 0x02 ]
686        - Entries:
687            - Operator: DW_RLE_startx_endx
688              Values:   [ 0x01, 0x02 ]
689
690## v) Test that when the "Offsets" entry is specified to be empty and the "OffsetEntryCount" is not specified,
691## the offsets array will be omitted.
692
693# RUN: yaml2obj --docnum=19 -DOFFSETS=[] %s -o %t20.o
694# RUN: llvm-readelf --hex-dump=.debug_rnglists %t20.o | \
695# RUN:   FileCheck %s --check-prefix=NO-OFFSETS
696
697## w) Test that if "Offsets" is specified, the offsets array will be emitted accordingly, even when
698## the "OffsetEntryCount" is specified to be 0.
699
700# RUN: yaml2obj --docnum=19 -DOFFSETS=[0x01,0x02,0x03] -DENTRYCOUNT=0 %s -o %t21.o
701# RUN: llvm-readelf --hex-dump=.debug_rnglists %t21.o | \
702# RUN:   FileCheck %s --check-prefix=OFFSETS
703
704#      OFFSETS: Hex dump of section '.debug_rnglists':
705# OFFSETS-NEXT: 0x00000000 0e000000 05000800 00000000 01000000 ................
706##                                           ^-------          offset_entry_count (4-byte)
707##                                                    ^------- offsets[0] (4-byte)
708# OFFSETS-NEXT: 0x00000010 02000000 03000000 02010202 0102     ..............
709##                         ^-------                            offsets[1] (4-byte)
710##                                  ^-------                   offsets[2] (4-byte)
711##                                           ^-                DW_RLE_startx_endx
712##                                             ^-              operands[0] (ULEB128) 0x01
713##                                               ^-            operands[1] (ULEB128) 0x02
714##                                                 ^-          DW_RLE_startx_endx
715##                                                    ^-       operands[0] (ULEB128) 0x01
716##                                                      ^-     operands[1] (ULEB128) 0x02
717