| 1 |
## Test that yaml2obj emits .debug_ranges section. |
| 2 |
|
| 3 |
## a) Generate the .debug_ranges section from the "DWARF" entry. |
| 4 |
|
| 5 |
## Generate and verify a little endian .debug_ranges section. |
| 6 |
|
| 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 |
| 10 |
|
| 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 |
| 25 |
## | | | | |
| 26 |
## | | | +------- HighOffset (4-byte) 0x40 |
| 27 |
## | | +------- LowOffset (4-byte) 0x30 |
| 28 |
## | +------- HighOffset (4-byte) 0x20 |
| 29 |
## +------- LowOffset (4-byte) 0x10 |
| 30 |
## |
| 31 |
# DWARF-LE-CONTENT-NEXT: 0010: FFFFFFFF 10000000 00000000 00000000 |
| 32 |
## | | | | |
| 33 |
## | | | +------- HighOffset (4-byte) 0x00 |
| 34 |
## | | +------- LowOffset (4-byte) 0x00 |
| 35 |
## | +------- Base Address (4-byte) 0x10 |
| 36 |
## +------- Base Address Entry (4-byte) UINT32_MAX |
| 37 |
## |
| 38 |
# DWARF-LE-CONTENT-NEXT: 0020: 00000000 00000000 10000000 00000000 |
| 39 |
## | | |
| 40 |
## | +---------------- LowOffset (8-byte) 0x10 |
| 41 |
## +---------------- Terminating Entry (8-byte) |
| 42 |
## |
| 43 |
# DWARF-LE-CONTENT-NEXT: 0030: 20000000 00000000 30000000 00000000 |
| 44 |
## | | |
| 45 |
## | +---------------- LowOffset (8-byte) 0x30 |
| 46 |
## +---------------- HighOffset (8-byte) 0x20 |
| 47 |
## |
| 48 |
# DWARF-LE-CONTENT-NEXT: 0040: 40000000 00000000 FFFFFFFF FFFFFFFF |
| 49 |
## | | |
| 50 |
## | +---------------- Base Address Entry (8-byte) UINT64_MAX |
| 51 |
## +---------------- HighOffset (8-byte) 0x40 |
| 52 |
## |
| 53 |
# DWARF-LE-CONTENT-NEXT: 0050: 10000000 00000000 00000000 00000000 |
| 54 |
## | | |
| 55 |
## | +---------------- LowOffset (8-byte) 0x00 |
| 56 |
## +---------------- Base Address (8-byte) 0x10 |
| 57 |
## |
| 58 |
# DWARF-LE-CONTENT-NEXT: 0060: 00000000 00000000 00000000 00000000 |
| 59 |
## | | |
| 60 |
## | +---------------- Terminating Entry (16-byte) |
| 61 |
## +---------------- HighOffset (8-byte) 0x00 |
| 62 |
## |
| 63 |
# DWARF-LE-CONTENT-NEXT: 0070: 00000000 00000000 |
| 64 |
## | |
| 65 |
## +---------------- Terminating Entry (lower 8-byte) |
| 66 |
## |
| 67 |
# DWARF-LE-CONTENT-NEXT: ) |
| 68 |
|
| 69 |
--- !ELF |
| 70 |
FileHeader: |
| 71 |
Class: ELFCLASS64 |
| 72 |
Data: [[ENDIAN]] |
| 73 |
Type: ET_EXEC |
| 74 |
DWARF: |
| 75 |
debug_ranges: |
| 76 |
- AddrSize: 0x04 |
| 77 |
Entries: |
| 78 |
- LowOffset: 0x00000010 |
| 79 |
HighOffset: 0x00000020 |
| 80 |
- LowOffset: 0x00000030 |
| 81 |
HighOffset: 0x00000040 |
| 82 |
- LowOffset: 0xffffffff |
| 83 |
HighOffset: 0x00000010 |
| 84 |
- LowOffset: 0x00000000 |
| 85 |
HighOffset: 0x00000000 |
| 86 |
- Entries: |
| 87 |
- LowOffset: 0x0000000000000010 |
| 88 |
HighOffset: 0x0000000000000020 |
| 89 |
- LowOffset: 0x0000000000000030 |
| 90 |
HighOffset: 0x0000000000000040 |
| 91 |
- LowOffset: 0xffffffffffffffff |
| 92 |
HighOffset: 0x0000000000000010 |
| 93 |
- LowOffset: 0x0000000000000000 |
| 94 |
HighOffset: 0x0000000000000000 |
| 95 |
|
| 96 |
## Generate and verify a big endian .debug_ranges section. |
| 97 |
|
| 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 |
| 101 |
|
| 102 |
# DWARF-BE-CONTENT-NEXT: SectionData ( |
| 103 |
# DWARF-BE-CONTENT-NEXT: 0000: 00000010 00000020 00000030 00000040 |
| 104 |
## | | | | |
| 105 |
## | | | +------- HighOffset (4-byte) 0x40 |
| 106 |
## | | +------- LowOffset (4-byte) 0x30 |
| 107 |
## | +------- HighOffset (4-byte) 0x20 |
| 108 |
## +------- LowOffset (4-byte) 0x10 |
| 109 |
## |
| 110 |
# DWARF-BE-CONTENT-NEXT: 0010: FFFFFFFF 00000010 00000000 00000000 |
| 111 |
## | | | | |
| 112 |
## | | | +------- HighOffset (4-byte) 0x00 |
| 113 |
## | | +------- LowOffset (4-byte) 0x00 |
| 114 |
## | +------- Base Address (4-byte) 0x10 |
| 115 |
## +------- Base Address Entry (4-byte) UINT32_MAX |
| 116 |
## |
| 117 |
# DWARF-BE-CONTENT-NEXT: 0020: 00000000 00000000 00000000 00000010 |
| 118 |
## | | |
| 119 |
## | +---------------- LowOffset (8-byte) 0x10 |
| 120 |
## +---------------- Terminating Entry (8-byte) |
| 121 |
## |
| 122 |
# DWARF-BE-CONTENT-NEXT: 0030: 00000000 00000020 00000000 00000030 |
| 123 |
## | | |
| 124 |
## | +---------------- LowOffset (8-byte) 0x30 |
| 125 |
## +---------------- HighOffset (8-byte) 0x20 |
| 126 |
## |
| 127 |
# DWARF-BE-CONTENT-NEXT: 0040: 00000000 00000040 FFFFFFFF FFFFFFFF |
| 128 |
## | | |
| 129 |
## | +---------------- Base Address Entry (8-byte) UINT64_MAX |
| 130 |
## +---------------- HighOffset (8-byte) 0x40 |
| 131 |
## |
| 132 |
# DWARF-BE-CONTENT-NEXT: 0050: 00000000 00000010 00000000 00000000 |
| 133 |
## | | |
| 134 |
## | +---------------- LowOffset (8-byte) 0x00 |
| 135 |
## +---------------- Base Address (8-byte) 0x10 |
| 136 |
## |
| 137 |
# DWARF-BE-CONTENT-NEXT: 0060: 00000000 00000000 00000000 00000000 |
| 138 |
## | | |
| 139 |
## | +---------------- Terminating Entry (16-byte) |
| 140 |
## +---------------- HighOffset (8-byte) 0x00 |
| 141 |
## |
| 142 |
# DWARF-BE-CONTENT-NEXT: 0070: 00000000 00000000 |
| 143 |
## | |
| 144 |
## +---------------- Terminating Entry (lower 8-byte) |
| 145 |
## |
| 146 |
# DWARF-BE-CONTENT-NEXT: ) |
| 147 |
|
| 148 |
## b) Generate the .debug_ranges section from raw section content. |
| 149 |
|
| 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 |
| 153 |
|
| 154 |
# ARBITRARY-CONTENT: SectionData ( |
| 155 |
# ARBITRARY-CONTENT-NEXT: 0000: 112233 |
| 156 |
# ARBITRARY-CONTENT-NEXT: ) |
| 157 |
|
| 158 |
--- !ELF |
| 159 |
FileHeader: |
| 160 |
Class: ELFCLASS64 |
| 161 |
Data: ELFDATA2LSB |
| 162 |
Type: ET_EXEC |
| 163 |
Sections: |
| 164 |
- Name: .debug_ranges |
| 165 |
Type: SHT_PROGBITS |
| 166 |
Content: "112233" |
| 167 |
|
| 168 |
## c) Generate the .debug_ranges section when the "Size" is specified. |
| 169 |
|
| 170 |
# RUN: yaml2obj --docnum=3 %s -o %t3.o |
| 171 |
# RUN: llvm-readobj --hex-dump=.debug_ranges %t3.o | FileCheck %s --check-prefix=SIZE |
| 172 |
|
| 173 |
# SIZE: Hex dump of section '.debug_ranges': |
| 174 |
# SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................ |
| 175 |
# SIZE-EMPTY: |
| 176 |
|
| 177 |
--- !ELF |
| 178 |
FileHeader: |
| 179 |
Class: ELFCLASS64 |
| 180 |
Data: ELFDATA2LSB |
| 181 |
Type: ET_EXEC |
| 182 |
Sections: |
| 183 |
- Name: .debug_ranges |
| 184 |
Type: SHT_PROGBITS |
| 185 |
Size: 0x10 |
| 186 |
|
| 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. |
| 189 |
|
| 190 |
# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR |
| 191 |
|
| 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 |
| 193 |
|
| 194 |
--- !ELF |
| 195 |
FileHeader: |
| 196 |
Class: ELFCLASS64 |
| 197 |
Data: ELFDATA2LSB |
| 198 |
Type: ET_EXEC |
| 199 |
Sections: |
| 200 |
- Name: .debug_ranges |
| 201 |
Type: SHT_PROGBITS |
| 202 |
Size: 0x10 |
| 203 |
DWARF: |
| 204 |
debug_ranges: |
| 205 |
- Entries: |
| 206 |
- LowOffset: 0x0000000000000001 |
| 207 |
HighOffset: 0x0000000000000002 |
| 208 |
|
| 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. |
| 211 |
|
| 212 |
# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR |
| 213 |
|
| 214 |
--- !ELF |
| 215 |
FileHeader: |
| 216 |
Class: ELFCLASS64 |
| 217 |
Data: ELFDATA2LSB |
| 218 |
Type: ET_EXEC |
| 219 |
Sections: |
| 220 |
- Name: .debug_ranges |
| 221 |
Type: SHT_PROGBITS |
| 222 |
Content: "00" |
| 223 |
DWARF: |
| 224 |
debug_ranges: |
| 225 |
- Entries: |
| 226 |
- LowOffset: 0x0000000000000001 |
| 227 |
HighOffset: 0x0000000000000002 |
| 228 |
|
| 229 |
## f) Test that all the properties can be overridden by the section header when |
| 230 |
## the "debug_ranges" entry doesn't exist. |
| 231 |
|
| 232 |
# RUN: yaml2obj --docnum=6 %s -o %t6.o |
| 233 |
# RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN |
| 234 |
|
| 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 |
| 238 |
|
| 239 |
--- !ELF |
| 240 |
FileHeader: |
| 241 |
Class: ELFCLASS64 |
| 242 |
Data: ELFDATA2LSB |
| 243 |
Type: ET_EXEC |
| 244 |
Sections: |
| 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. |
| 256 |
Type: SHT_STRTAB |
| 257 |
|
| 258 |
## g) Test that all the properties can be overridden by the section header when |
| 259 |
## the "debug_ranges" entry exists. |
| 260 |
|
| 261 |
# RUN: yaml2obj --docnum=7 %s -o %t7.o |
| 262 |
# RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN |
| 263 |
|
| 264 |
--- !ELF |
| 265 |
FileHeader: |
| 266 |
Class: ELFCLASS64 |
| 267 |
Data: ELFDATA2LSB |
| 268 |
Type: ET_EXEC |
| 269 |
Sections: |
| 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. |
| 280 |
Type: SHT_STRTAB |
| 281 |
DWARF: |
| 282 |
debug_ranges: |
| 283 |
- Entries: |
| 284 |
- LowOffset: 0x0000000000000001 |
| 285 |
HighOffset: 0x0000000000000002 |
| 286 |
|
| 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. |
| 289 |
|
| 290 |
# RUN: yaml2obj --docnum=8 %s -o %t8.o |
| 291 |
# RUN: llvm-readelf --hex-dump=.debug_ranges %t8.o | FileCheck %s --check-prefix=PADDED |
| 292 |
|
| 293 |
# PADDED: Hex dump of section '.debug_ranges': |
| 294 |
# PADDED-NEXT: 0x00000000 01000000 00000000 02000000 00000000 |
| 295 |
## | | |
| 296 |
## | +---------------- HighOffset (8-byte) 0x02 |
| 297 |
## +---------------- LowOffset (8-byte) 0x01 |
| 298 |
## |
| 299 |
# PADDED-NEXT: 0x00000010 00000000 00000000 00000000 00000000 |
| 300 |
## | |
| 301 |
## +---------------------------------- Terminating Entry (16-byte) 0x00 |
| 302 |
## |
| 303 |
# PADDED-NEXT: 0x00000020 00010000 00000000 00020000 00000000 |
| 304 |
## | | | |
| 305 |
## | | +------------- HighOffset (8-byte) 0x02 |
| 306 |
## | +----------------- LowOffset (8-byte) 0x01 |
| 307 |
## +- Padded zeros (1-byte) 0x00 |
| 308 |
## |
| 309 |
# PADDED-NEXT: 0x00000030 00000000 00000000 00000000 00000000 |
| 310 |
## | | |
| 311 |
## | +-------------------------------- Terminating Entry (16-byte) 0x00 |
| 312 |
## +- higher byte(s) of HighOffset |
| 313 |
## |
| 314 |
# PADDED-NEXT: 0x00000040 00010000 00000000 00020000 00000000 |
| 315 |
## | | | |
| 316 |
## | | +-------------- HighOffset (8-byte) 0x02 |
| 317 |
## | +----------------- LowOffset (8-byte) 0x01 |
| 318 |
## +- the last byte of terminating entry. |
| 319 |
## |
| 320 |
# PADDED-NEXT: 0x00000050 00000000 00000000 00000000 00000000 |
| 321 |
## | | |
| 322 |
## | +-------------------------------- Terminating Entry (16-byte) 0x00 |
| 323 |
## +- higher byte(s) of HighOffset |
| 324 |
## |
| 325 |
# PADDED-NEXT: 0x00000060 00 |
| 326 |
## | |
| 327 |
## +- the last byte of terminating entry. |
| 328 |
|
| 329 |
--- !ELF |
| 330 |
FileHeader: |
| 331 |
Class: ELFCLASS64 |
| 332 |
Data: ELFDATA2LSB |
| 333 |
Type: ET_EXEC |
| 334 |
DWARF: |
| 335 |
debug_ranges: |
| 336 |
- Entries: |
| 337 |
- LowOffset: 0x01 |
| 338 |
HighOffset: 0x02 |
| 339 |
- Offset: 0x21 ## There are 0x20 bytes before this entry. |
| 340 |
Entries: |
| 341 |
- LowOffset: 0x01 |
| 342 |
HighOffset: 0x02 |
| 343 |
- Offset: 0x41 ## There are 0x41 bytes before this entry. |
| 344 |
Entries: |
| 345 |
- LowOffset: 0x01 |
| 346 |
HighOffset: 0x02 |
| 347 |
|
| 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. |
| 350 |
|
| 351 |
# RUN: not yaml2obj --docnum=9 %s -o %t9.o 2>&1 | FileCheck %s --check-prefix=INVALID-OFFSET |
| 352 |
|
| 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) |
| 354 |
|
| 355 |
--- !ELF |
| 356 |
FileHeader: |
| 357 |
Class: ELFCLASS64 |
| 358 |
Data: ELFDATA2LSB |
| 359 |
Type: ET_EXEC |
| 360 |
DWARF: |
| 361 |
debug_ranges: |
| 362 |
- Entries: |
| 363 |
- LowOffset: 0x01 |
| 364 |
HighOffset: 0x02 |
| 365 |
- Offset: 0x1F ## Must be greater than or equal to 0x20. |
| 366 |
Entries: |
| 367 |
- LowOffset: 0x01 |
| 368 |
HighOffset: 0x02 |
| 369 |
|
| 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. |
| 372 |
|
| 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 |
| 376 |
|
| 377 |
# ADDRSIZE: Hex dump of section '.debug_ranges': |
| 378 |
# ADDRSIZE-NEXT: 0x00000000 00000000 00000000 00000000 0000 |
| 379 |
## ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ terminating entry (2*AddrSize=14-byte) |
| 380 |
|
| 381 |
--- !ELF |
| 382 |
FileHeader: |
| 383 |
Class: ELFCLASS64 |
| 384 |
Data: ELFDATA2LSB |
| 385 |
Type: ET_EXEC |
| 386 |
DWARF: |
| 387 |
debug_ranges: |
| 388 |
- AddrSize: 0x07 |
| 389 |
Entries: [] |
| 390 |
|
| 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. |
| 393 |
|
| 394 |
# RUN: not yaml2obj --docnum=11 %s 2>&1 | \ |
| 395 |
# RUN: FileCheck %s --check-prefix=INVALID-SIZE |
| 396 |
|
| 397 |
# INVALID-SIZE: yaml2obj: error: unable to write debug_ranges address offset: invalid integer write size: 7 |
| 398 |
|
| 399 |
--- !ELF |
| 400 |
FileHeader: |
| 401 |
Class: ELFCLASS64 |
| 402 |
Data: ELFDATA2LSB |
| 403 |
Type: ET_EXEC |
| 404 |
DWARF: |
| 405 |
debug_ranges: |
| 406 |
- AddrSize: 0x07 |
| 407 |
Entries: |
| 408 |
- LowOffset: 0x1234 |
| 409 |
HighOffset: 0x5678 |
| 410 |
|
| 411 |
## l) Test that the .debug_ranges section header is emitted if the "debug_ranges" |
| 412 |
## entry is empty. |
| 413 |
|
| 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 |
| 416 |
|
| 417 |
--- !ELF |
| 418 |
FileHeader: |
| 419 |
Class: ELFCLASS64 |
| 420 |
Data: ELFDATA2LSB |
| 421 |
Type: ET_EXEC |
| 422 |
DWARF: |
| 423 |
debug_ranges: [] |