1## Test how we dump the .debug_aranges section.
2
3## a) Test dumping the DWARF32/64 address range table from 32/64-bit, little/big endian object files.
4## The .debug_aranges should be written to the 'DWARF' entry and the 'Sections' entry should remain empty.
5
6# RUN: yaml2obj --docnum=1 -DBITS=32 -DENDIAN=LSB %s | obj2yaml | \
7# RUN:   FileCheck %s --check-prefix=BASIC --implicit-check-not=Sections \
8# RUN:     -DLENGTH1=24 -DLENGTH2=24 -DADDRSIZE=0x4 \
9# RUN:     -DVARADDR=0x1234 -DVARLEN=0x5678
10
11# RUN: yaml2obj --docnum=1 -DBITS=32 -DENDIAN=MSB %s | obj2yaml | \
12# RUN:   FileCheck %s --check-prefix=BASIC --implicit-check-not=Sections \
13# RUN:     -DLENGTH1=24 -DLENGTH2=24 -DADDRSIZE=0x4 \
14# RUN:     -DVARADDR=0x1234 -DVARLEN=0x5678
15
16# RUN: yaml2obj --docnum=1 -DBITS=64 -DENDIAN=LSB %s | obj2yaml | \
17# RUN:   FileCheck %s --check-prefix=BASIC --implicit-check-not=Sections \
18# RUN:     -DLENGTH1=3C -DLENGTH2=44 -DADDRSIZE=0x8 \
19# RUN:     -DVARADDR=0x1234 -DVARLEN=0x5678
20
21# RUN: yaml2obj --docnum=1 -DBITS=64 -DENDIAN=MSB %s | obj2yaml | \
22# RUN:   FileCheck  %s --check-prefix=BASIC --implicit-check-not=Sections \
23# RUN:     -DLENGTH1=3C -DLENGTH2=44 -DADDRSIZE=0x8 \
24# RUN:     -DVARADDR=0x1234 -DVARLEN=0x5678
25
26#      BASIC: DWARF:
27# BASIC-NEXT:   debug_aranges:
28# BASIC-NEXT:     - Length:      0x[[LENGTH1]]
29# BASIC-NEXT:       Version:     2
30# BASIC-NEXT:       CuOffset:    0x1234
31# BASIC-NEXT:       AddressSize: [[ADDRSIZE]]
32# BASIC-NEXT:       Descriptors:
33# BASIC-NEXT:         - Address: 0x1234
34# BASIC-NEXT:           Length:  0x5678
35# BASIC-NEXT:         - Address: 0x1234
36# BASIC-NEXT:           Length:  0x5678
37# BASIC-NEXT:     - Format:      DWARF64
38# BASIC-NEXT:       Length:      0x[[LENGTH2]]
39# BASIC-NEXT:       Version:     2
40# BASIC-NEXT:       CuOffset:    0x1234567890ABCDEF
41# BASIC-NEXT:       AddressSize: [[ADDRSIZE]]
42# BASIC-NEXT:       Descriptors:
43# BASIC-NEXT:         - Address: [[VARADDR]]
44# BASIC-NEXT:           Length:  [[VARLEN]]
45# BASIC-NEXT:         - Address: 0x1234
46# BASIC-NEXT:           Length:  0x5678
47# BASIC-NEXT: ...
48
49--- !ELF
50FileHeader:
51  Class: ELFCLASS[[BITS]]
52  Data:  ELFDATA2[[ENDIAN]]
53  Type:  ET_EXEC
54DWARF:
55  debug_aranges:
56    - Version:  2
57      CuOffset: 0x1234
58      Descriptors:
59        - Address: 0x1234
60          Length:  0x5678
61        - Address: 0x1234
62          Length:  0x5678
63    - Format:   DWARF64
64      Version:  2
65      CuOffset: 0x1234567890abcdef
66      Descriptors:
67        - Address: [[ADDR=0x1234]]
68          Length:  [[LENGTH=0x5678]]
69        - Address: 0x1234
70          Length:  0x5678
71
72## b) Test dumping an .debug_aranges section whose section header properties are overridden.
73
74# RUN: yaml2obj --docnum=2 -DTYPE=SHT_STRTAB %s | obj2yaml | FileCheck %s -DTYPE=STRTAB --check-prefixes=ARANGE,SHDR
75# RUN: yaml2obj --docnum=2 -DFLAGS=[SHF_ALLOC] %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=ARANGE,SHDR,FLAGS
76# RUN: yaml2obj --docnum=2 -DLINK='.sec' %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=ARANGE,SHDR,LINK
77# RUN: yaml2obj --docnum=2 -DENTSIZE=3 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=ARANGE,SHDR,ENTSIZE
78# RUN: yaml2obj --docnum=2 -DINFO=3 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=ARANGE,SHDR,INFO
79# RUN: yaml2obj --docnum=2 -DADDRALIGN=3 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=ARANGE,SHDR,ADDRALIGN
80# RUN: yaml2obj --docnum=2 -DADDRESS=0x2020 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=ARANGE,SHDR,ADDRESS
81
82#           SHDR: - Name:         .debug_aranges
83#      SHDR-NEXT:   Type:         SHT_[[TYPE]]
84#     FLAGS-NEXT:   Flags:        [ SHF_ALLOC ]
85#      LINK-NEXT:   Link:         .sec
86#   ENTSIZE-NEXT:   EntSize:      0x3
87#      INFO-NEXT:   Info:         0x3
88# ADDRALIGN-NEXT:   AddressAlign: 0x3
89#   ADDRESS-NEXT:   Address:      0x2020
90
91#      ARANGE: DWARF:
92# ARANGE-NEXT:   debug_aranges:
93# ARANGE-NEXT:     - Length:      0x1C
94# ARANGE-NEXT:       Version:     2
95# ARANGE-NEXT:       CuOffset:    0x1234
96# ARANGE-NEXT:       AddressSize: 0x8
97# ARANGE-NEXT: ...
98
99--- !ELF
100FileHeader:
101  Class: ELFCLASS64
102  Data:  ELFDATA2LSB
103  Type:  ET_EXEC
104Sections:
105  - Name:         .debug_aranges
106    Type:         [[TYPE=SHT_PROGBITS]]
107    Flags:        [[FLAGS=<none>]]
108    Link:         [[LINK=<none>]]
109    EntSize:      [[ENTSIZE=<none>]]
110    Info:         [[INFO=<none>]]
111    AddressAlign: [[ADDRALIGN=0]]
112    Address:      [[ADDRESS=<none>]]
113  - Name:         .sec
114    Type:         SHT_PROGBITS
115DWARF:
116  debug_aranges:
117    - Version:  2
118      CuOffset: 0x1234
119
120## c) Test dumping a .debug_aranges section whose address_size doesn't match the
121## object file's address size.
122
123# RUN: yaml2obj --docnum=3 %s | obj2yaml | \
124# RUN:   FileCheck %s -DLENGTH=0x1C -DADDRSIZE=0x4 -DADDRLEN=0x12345678 --check-prefix=ADDRSIZE
125
126#      ADDRSIZE: DWARF:
127# ADDRSIZE-NEXT:   debug_aranges:
128# ADDRSIZE-NEXT:     - Length:      [[LENGTH]]
129# ADDRSIZE-NEXT:       Version:     2
130# ADDRSIZE-NEXT:       CuOffset:    0x1234
131# ADDRSIZE-NEXT:       AddressSize: [[ADDRSIZE]]
132# ADDRSIZE-NEXT:       Descriptors:
133# ADDRSIZE-NEXT:         - Address: [[ADDRLEN]]
134# ADDRSIZE-NEXT:           Length:  [[ADDRLEN]]
135# ADDRSIZE-NEXT: ...
136
137--- !ELF
138FileHeader:
139  Class: ELFCLASS[[BITS=64]]
140  Data:  ELFDATA2LSB
141  Type:  ET_EXEC
142DWARF:
143  debug_aranges:
144    - Version:     2
145      CuOffset:    0x1234
146      AddressSize: [[ADDRSIZE=0x4]]
147      Descriptors:
148        - Address: [[ADDRLEN=0x12345678]]
149          Length:  [[ADDRLEN=0x12345678]]
150
151# RUN: yaml2obj --docnum=3 -DBITS=32 -DADDRSIZE=0x8 -DADDRLEN=0x1234567890abcdef %s | \
152# RUN:   obj2yaml | \
153# RUN:   FileCheck %s -DLENGTH=0x2C -DADDRSIZE=0x8 -DADDRLEN=0x1234567890ABCDEF --check-prefix=ADDRSIZE
154
155## d) Test dumping a .debug_aranges section whose length field doesn't match the actual length.
156## This makes the DWARF parser fail to parse it and we will dump it as a raw content section.
157
158# RUN: yaml2obj --docnum=4 %s | obj2yaml | FileCheck %s --check-prefix=RAW-CONTENT
159
160#      RAW-CONTENT: Sections:
161# RAW-CONTENT-NEXT:   - Name:            .debug_aranges
162# RAW-CONTENT-NEXT:     Type:            SHT_PROGBITS
163# RAW-CONTENT-NEXT:     AddressAlign:    0x1
164# RAW-CONTENT-NEXT:     Content:         '3412000002003412000008000000000000000000000000000000000000000000'
165# RAW-CONTENT-NEXT: ...
166
167--- !ELF
168FileHeader:
169  Class: ELFCLASS64
170  Data:  ELFDATA2LSB
171  Type:  ET_EXEC
172DWARF:
173  debug_aranges:
174    - Length:   0x1234
175      Version:  2
176      CuOffset: 0x1234
177
178## e) Test dumping an empty .debug_aranges section.
179
180# RUN: yaml2obj --docnum=5 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY-CONTENT
181
182#      EMPTY-CONTENT: DWARF:
183# EMPTY-CONTENT-NEXT:   debug_aranges:   []
184# EMPTY-CONTENT-NEXT: ...
185
186--- !ELF
187FileHeader:
188  Class: ELFCLASS64
189  Data:  ELFDATA2LSB
190  Type:  ET_EXEC
191DWARF:
192  debug_aranges: []
193
194## f) Show that dumping a table with a premature terminator entry still uses the
195## DWARF tag.
196
197# RUN: yaml2obj --docnum=1 %s -DADDR=0 -DLENGTH=0 -DBITS=64 -DENDIAN=LSB | obj2yaml | \
198# RUN:   FileCheck %s --check-prefix=BASIC --implicit-check-not=Sections \
199# RUN:     -DLENGTH1=3C -DLENGTH2=44 -DADDRSIZE=0x8 -DVARADDR=0x0 -DVARLEN=0x0
200