brintos

brintos / llvm-project-archived public Read only

0
0
Text · 15.8 KiB · f80dd6d Raw
424 lines · yaml
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.o8# RUN: llvm-readobj --sections --section-data %t.le.o | \9# RUN:   FileCheck %s -DSIZE=120 -DADDRALIGN=1 --check-prefixes=DWARF-HEADER,DWARF-LE-CONTENT10 11#          DWARF-HEADER: Index: 112#     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: 0x017#     DWARF-HEADER-NEXT: Offset: 0x4018#     DWARF-HEADER-NEXT: Size: [[SIZE]]19#     DWARF-HEADER-NEXT: Link: 020#     DWARF-HEADER-NEXT: Info: 021#     DWARF-HEADER-NEXT: AddressAlignment: [[ADDRALIGN]]22#     DWARF-HEADER-NEXT: EntrySize: 023# DWARF-LE-CONTENT-NEXT: SectionData (24# DWARF-LE-CONTENT-NEXT:   0000: 10000000 20000000 30000000 4000000025##                               |        |        |        |26##                               |        |        |        +------- HighOffset (4-byte) 0x4027##                               |        |        +------- LowOffset (4-byte) 0x3028##                               |        +------- HighOffset (4-byte) 0x2029##                               +------- LowOffset (4-byte) 0x1030##31# DWARF-LE-CONTENT-NEXT:   0010: FFFFFFFF 10000000 00000000 0000000032##                               |        |        |        |33##                               |        |        |        +------- HighOffset (4-byte) 0x0034##                               |        |        +------- LowOffset (4-byte) 0x0035##                               |        +------- Base Address (4-byte) 0x1036##                               +------- Base Address Entry (4-byte) UINT32_MAX37##38# DWARF-LE-CONTENT-NEXT:   0020: 00000000 00000000 10000000 0000000039##                               |                 |40##                               |                 +---------------- LowOffset (8-byte) 0x1041##                               +---------------- Terminating Entry (8-byte)42##43# DWARF-LE-CONTENT-NEXT:   0030: 20000000 00000000 30000000 0000000044##                               |                 |45##                               |                 +---------------- LowOffset (8-byte) 0x3046##                               +---------------- HighOffset (8-byte) 0x2047##48# DWARF-LE-CONTENT-NEXT:   0040: 40000000 00000000 FFFFFFFF FFFFFFFF49##                               |                 |50##                               |                 +---------------- Base Address Entry (8-byte) UINT64_MAX51##                               +---------------- HighOffset (8-byte) 0x4052##53# DWARF-LE-CONTENT-NEXT:   0050: 10000000 00000000 00000000 0000000054##                               |                 |55##                               |                 +---------------- LowOffset (8-byte) 0x0056##                               +---------------- Base Address (8-byte) 0x1057##58# DWARF-LE-CONTENT-NEXT:   0060: 00000000 00000000 00000000 0000000059##                               |                 |60##                               |                 +---------------- Terminating Entry (16-byte)61##                               +---------------- HighOffset (8-byte) 0x0062##63# DWARF-LE-CONTENT-NEXT:   0070: 00000000 0000000064##                               |65##                               +---------------- Terminating Entry (lower 8-byte)66##67# DWARF-LE-CONTENT-NEXT: )68 69--- !ELF70FileHeader:71  Class: ELFCLASS6472  Data:  [[ENDIAN]]73  Type:  ET_EXEC74DWARF:75  debug_ranges:76    - AddrSize: 0x0477      Entries:78        - LowOffset:  0x0000001079          HighOffset: 0x0000002080        - LowOffset:  0x0000003081          HighOffset: 0x0000004082        - LowOffset:  0xffffffff83          HighOffset: 0x0000001084        - LowOffset:  0x0000000085          HighOffset: 0x0000000086    - Entries:87        - LowOffset:  0x000000000000001088          HighOffset: 0x000000000000002089        - LowOffset:  0x000000000000003090          HighOffset: 0x000000000000004091        - LowOffset:  0xffffffffffffffff92          HighOffset: 0x000000000000001093        - LowOffset:  0x000000000000000094          HighOffset: 0x000000000000000095 96## Generate and verify a big endian .debug_ranges section.97 98# RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.be.o99# RUN: llvm-readobj --sections --section-data %t.be.o | \100# RUN:   FileCheck %s -DSIZE=120 -DADDRALIGN=1 --check-prefixes=DWARF-HEADER,DWARF-BE-CONTENT101 102# DWARF-BE-CONTENT-NEXT: SectionData (103# DWARF-BE-CONTENT-NEXT: 0000: 00000010 00000020 00000030 00000040104##                             |        |        |        |105##                             |        |        |        +------- HighOffset (4-byte) 0x40106##                             |        |        +------- LowOffset (4-byte) 0x30107##                             |        +------- HighOffset (4-byte) 0x20108##                             +------- LowOffset (4-byte) 0x10109##110# DWARF-BE-CONTENT-NEXT: 0010: FFFFFFFF 00000010 00000000 00000000111##                             |        |        |        |112##                             |        |        |        +------- HighOffset (4-byte) 0x00113##                             |        |        +------- LowOffset (4-byte) 0x00114##                             |        +------- Base Address (4-byte) 0x10115##                             +------- Base Address Entry (4-byte) UINT32_MAX116##117# DWARF-BE-CONTENT-NEXT: 0020: 00000000 00000000 00000000 00000010118##                             |                 |119##                             |                 +---------------- LowOffset (8-byte) 0x10120##                             +---------------- Terminating Entry (8-byte)121##122# DWARF-BE-CONTENT-NEXT: 0030: 00000000 00000020 00000000 00000030123##                             |                 |124##                             |                 +---------------- LowOffset (8-byte) 0x30125##                             +---------------- HighOffset (8-byte) 0x20126##127# DWARF-BE-CONTENT-NEXT: 0040: 00000000 00000040 FFFFFFFF FFFFFFFF128##                             |                 |129##                             |                 +---------------- Base Address Entry (8-byte) UINT64_MAX130##                             +---------------- HighOffset (8-byte) 0x40131##132# DWARF-BE-CONTENT-NEXT: 0050: 00000000 00000010 00000000 00000000133##                             |                 |134##                             |                 +---------------- LowOffset (8-byte) 0x00135##                             +---------------- Base Address (8-byte) 0x10136##137# DWARF-BE-CONTENT-NEXT: 0060: 00000000 00000000 00000000 00000000138##                             |                 |139##                             |                 +---------------- Terminating Entry (16-byte)140##                             +---------------- HighOffset (8-byte) 0x00141##142# DWARF-BE-CONTENT-NEXT: 0070: 00000000 00000000143##                             |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.o151# RUN: llvm-readobj --sections --section-data %t2.o | \152# RUN:   FileCheck %s -DSIZE=3 -DADDRALIGN=0 --check-prefixes=DWARF-HEADER,ARBITRARY-CONTENT153 154#      ARBITRARY-CONTENT: SectionData (155# ARBITRARY-CONTENT-NEXT:   0000: 112233156# ARBITRARY-CONTENT-NEXT: )157 158--- !ELF159FileHeader:160  Class: ELFCLASS64161  Data:  ELFDATA2LSB162  Type:  ET_EXEC163Sections:164  - Name:    .debug_ranges165    Type:    SHT_PROGBITS166    Content: "112233"167 168## c) Generate the .debug_ranges section when the "Size" is specified.169 170# RUN: yaml2obj --docnum=3 %s -o %t3.o171# RUN: llvm-readobj --hex-dump=.debug_ranges %t3.o | FileCheck %s --check-prefix=SIZE172 173#       SIZE: Hex dump of section '.debug_ranges':174#  SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................175# SIZE-EMPTY:176 177--- !ELF178FileHeader:179  Class: ELFCLASS64180  Data:  ELFDATA2LSB181  Type:  ET_EXEC182Sections:183  - Name: .debug_ranges184    Type: SHT_PROGBITS185    Size: 0x10186 187## d) Test that yaml2obj emits an error message when both the "Size" and the188## "debug_ranges" entry are specified at the same time.189 190# RUN: not yaml2obj --docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERROR191 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 time193 194--- !ELF195FileHeader:196  Class: ELFCLASS64197  Data:  ELFDATA2LSB198  Type:  ET_EXEC199Sections:200  - Name: .debug_ranges201    Type: SHT_PROGBITS202    Size: 0x10203DWARF:204  debug_ranges:205    - Entries:206        - LowOffset:  0x0000000000000001207          HighOffset: 0x0000000000000002208 209## e) Test that yaml2obj emits an error message when both the "Content" and the210## "debug_ranges" entry are specified at the same time.211 212# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERROR213 214--- !ELF215FileHeader:216  Class: ELFCLASS64217  Data:  ELFDATA2LSB218  Type:  ET_EXEC219Sections:220  - Name:    .debug_ranges221    Type:    SHT_PROGBITS222    Content: "00"223DWARF:224  debug_ranges:225    - Entries:226        - LowOffset:  0x0000000000000001227          HighOffset: 0x0000000000000002228 229## f) Test that all the properties can be overridden by the section header when230## the "debug_ranges" entry doesn't exist.231 232# RUN: yaml2obj --docnum=6 %s -o %t6.o233# RUN: llvm-readelf --sections %t6.o | FileCheck %s --check-prefix=OVERRIDDEN234 235#      OVERRIDDEN: [Nr] Name          Type   Address          Off    Size   ES Flg Lk Inf Al236#      OVERRIDDEN: [ 1] .debug_ranges STRTAB 0000000000002020 000050 000020 01   A  2   1  2237# OVERRIDDEN-NEXT: [ 2] .sec          STRTAB 0000000000000000 000070 000000 00      0   0  0238 239--- !ELF240FileHeader:241  Class: ELFCLASS64242  Data:  ELFDATA2LSB243  Type:  ET_EXEC244Sections:245  - Name:         .debug_ranges246    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_STRTAB257 258## g) Test that all the properties can be overridden by the section header when259## the "debug_ranges" entry exists.260 261# RUN: yaml2obj --docnum=7 %s -o %t7.o262# RUN: llvm-readelf --sections %t7.o | FileCheck %s --check-prefix=OVERRIDDEN263 264--- !ELF265FileHeader:266  Class: ELFCLASS64267  Data:  ELFDATA2LSB268  Type:  ET_EXEC269Sections:270  - Name:         .debug_ranges271    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_STRTAB281DWARF:282  debug_ranges:283    - Entries:284        - LowOffset:  0x0000000000000001285          HighOffset: 0x0000000000000002286 287## h) Test that yaml2obj automatically pads zeros if we try to assign an offset that288## is greater than or equal to the number of bytes written already.289 290# RUN: yaml2obj --docnum=8 %s -o %t8.o291# RUN: llvm-readelf --hex-dump=.debug_ranges %t8.o | FileCheck %s --check-prefix=PADDED292 293#      PADDED: Hex dump of section '.debug_ranges':294# PADDED-NEXT: 0x00000000 01000000 00000000 02000000 00000000295##                        |                 |296##                        |                 +---------------- HighOffset (8-byte) 0x02297##                        +---------------- LowOffset (8-byte) 0x01298##299# PADDED-NEXT: 0x00000010 00000000 00000000 00000000 00000000300##                        |301##                        +---------------------------------- Terminating Entry (16-byte) 0x00302##303# PADDED-NEXT: 0x00000020 00010000 00000000 00020000 00000000304##                        |  |                 |305##                        |  |                 +------------- HighOffset (8-byte) 0x02306##                        |  +----------------- LowOffset (8-byte) 0x01307##                        +- Padded zeros (1-byte) 0x00308##309# PADDED-NEXT: 0x00000030 00000000 00000000 00000000 00000000310##                        | |311##                        | +-------------------------------- Terminating Entry (16-byte) 0x00312##                        +- higher byte(s) of HighOffset313##314# PADDED-NEXT: 0x00000040 00010000 00000000 00020000 00000000315##                        | |                 |316##                        | |                 +-------------- HighOffset (8-byte) 0x02317##                        | +----------------- LowOffset (8-byte) 0x01318##                        +- the last byte of terminating entry.319##320# PADDED-NEXT: 0x00000050 00000000 00000000 00000000 00000000321##                        | |322##                        | +-------------------------------- Terminating Entry (16-byte) 0x00323##                        +- higher byte(s) of HighOffset324##325# PADDED-NEXT: 0x00000060 00326##                        |327##                        +- the last byte of terminating entry.328 329--- !ELF330FileHeader:331  Class: ELFCLASS64332  Data:  ELFDATA2LSB333  Type:  ET_EXEC334DWARF:335  debug_ranges:336    - Entries:337        - LowOffset:  0x01338          HighOffset: 0x02339    - Offset:   0x21  ## There are 0x20 bytes before this entry.340      Entries:341        - LowOffset:  0x01342          HighOffset: 0x02343    - Offset:   0x41  ## There are 0x41 bytes before this entry.344      Entries:345        - LowOffset:  0x01346          HighOffset: 0x02347 348## i) Test that yaml2obj emits an error message if we try to assign an invalid offset to an349## entry of the '.debug_ranges' section.350 351# RUN: not yaml2obj --docnum=9 %s -o %t9.o 2>&1 | FileCheck %s --check-prefix=INVALID-OFFSET352 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--- !ELF356FileHeader:357  Class: ELFCLASS64358  Data:  ELFDATA2LSB359  Type:  ET_EXEC360DWARF:361  debug_ranges:362    - Entries:363        - LowOffset:  0x01364          HighOffset: 0x02365    - Offset:   0x1F ## Must be greater than or equal to 0x20.366      Entries:367        - LowOffset:  0x01368          HighOffset: 0x02369 370## j) Test that yaml2obj still generates a .debug_ranges section if we assign an invalid value371## to 'AddrSize' when the 'Entries' list is empty.372 373# RUN: yaml2obj --docnum=10 %s -o %t10.o374# RUN: llvm-readelf --hex-dump=.debug_ranges %t10.o | \375# RUN:   FileCheck %s --check-prefix=ADDRSIZE376 377#      ADDRSIZE: Hex dump of section '.debug_ranges':378# ADDRSIZE-NEXT: 0x00000000 00000000 00000000 00000000 0000379##                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ terminating entry (2*AddrSize=14-byte)380 381--- !ELF382FileHeader:383  Class: ELFCLASS64384  Data:  ELFDATA2LSB385  Type:  ET_EXEC386DWARF:387  debug_ranges:388    - AddrSize: 0x07389      Entries:  []390 391## k) Test that yaml2obj emits an error message if we try to assign an invalid value to392## '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-SIZE396 397# INVALID-SIZE: yaml2obj: error: unable to write debug_ranges address offset: invalid integer write size: 7398 399--- !ELF400FileHeader:401  Class: ELFCLASS64402  Data:  ELFDATA2LSB403  Type:  ET_EXEC404DWARF:405  debug_ranges:406    - AddrSize: 0x07407      Entries:408        - LowOffset:  0x1234409          HighOffset: 0x5678410 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.o415# RUN: llvm-readobj -S %t12.o | FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefix=DWARF-HEADER416 417--- !ELF418FileHeader:419  Class: ELFCLASS64420  Data:  ELFDATA2LSB421  Type:  ET_EXEC422DWARF:423  debug_ranges: []424