268 lines · yaml
1## Test that yaml2obj emits a .debug_str_offsets section when requested.2 3## a) Generate and verify a little endian .debug_str_offsets section.4 5# RUN: yaml2obj -DENDIAN=ELFDATA2LSB --docnum=1 %s -o %t1.le.o6# RUN: llvm-readobj --sections --section-data %t1.le.o | \7# RUN: FileCheck -DSIZE=48 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF-LE8 9# SHDR: Index: 110# SHDR-NEXT: Name: .debug_str_offsets (1)11# SHDR-NEXT: Type: SHT_PROGBITS (0x1)12# SHDR-NEXT: Flags [ (0x0)13# SHDR-NEXT: ]14# SHDR-NEXT: Address: 0x015# SHDR-NEXT: Offset: 0x4016# SHDR-NEXT: Size: [[SIZE]]17# SHDR-NEXT: Link: 018# SHDR-NEXT: Info: 019# SHDR-NEXT: AddressAlignment: [[ADDRALIGN]]20# SHDR-NEXT: EntrySize: 021# DWARF-LE-NEXT: SectionData (22# DWARF-LE-NEXT: 0000: 0C000000 05000000 78563412 21436587 |........xV4.!Ce.|23## ^------- unit_length (4-byte)24## ^--- version (2-byte)25## ^--- padding (2-byte)26## ^------- offsets[0] (4-byte)27## ^------- offsets[1] (4-byte)28# DWARF-LE-NEXT: 0010: FFFFFFFF 14000000 00000000 05000000 |................|29## ^------------------------- unit_length (12-byte)30## ^--- version (2-byte)31## ^--- padding (2-byte)32# DWARF-LE-NEXT: 0020: F0DEBC9A 78563412 89674523 01EFCDAB |....xV4..gE#....|33## ^---------------- offsets[0] (8-byte)34## ^---------------- offsets[1] (8-byte)35# DWARF-LE-NEXT: )36 37--- !ELF38FileHeader:39 Class: ELFCLASS6440 Data: [[ENDIAN]]41 Type: ET_EXEC42DWARF:43 debug_str_offsets:44 - Offsets:45 - 0x1234567846 - 0x8765432147 - Format: DWARF6448 Offsets:49 - 0x123456789abcdef050 - 0xabcdef012345678951 52## b) Generate and verify a big endian .debug_str_offsets section.53 54# RUN: yaml2obj -DENDIAN=ELFDATA2MSB --docnum=1 %s -o %t1.be.o55# RUN: llvm-readobj --sections --section-data %t1.be.o | \56# RUN: FileCheck -DSIZE=48 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF-BE57 58# DWARF-BE-NEXT: SectionData (59# DWARF-BE-NEXT: 0000: 0000000C 00050000 12345678 87654321 |.........4Vx.eC!|60## ^------- unit_length (4-byte)61## ^--- version (2-byte)62## ^--- padding (2-byte)63## ^------- offsets[0] (4-byte)64## ^------- offsets[1] (4-byte)65# DWARF-BE-NEXT: 0010: FFFFFFFF 00000000 00000014 00050000 |................|66## ^------------------------- unit_length (12-byte)67## ^--- version (2-byte)68## ^--- padding (2-byte)69# DWARF-BE-NEXT: 0020: 12345678 9ABCDEF0 ABCDEF01 23456789 |.4Vx........#Eg.|70## ^---------------- offsets[0] (8-byte)71## ^---------------- offsets[1] (8-byte)72# DWARF-BE-NEXT: )73 74## c) Test that the length, version and padding fields can be overwritten.75 76# RUN: yaml2obj --docnum=2 %s -o %t2.o77# RUN: llvm-readelf --hex-dump=.debug_str_offsets %t2.o | \78# RUN: FileCheck %s --check-prefix=OVERWRITE79 80# OVERWRITE: Hex dump of section '.debug_str_offsets':81# OVERWRITE-NEXT: 0x00000000 34120000 06001200 4.......82## ^------- unit_length (4-byte)83## ^--- version (2-byte)84## ^--- padding (2-bye)85 86--- !ELF87FileHeader:88 Class: ELFCLASS6489 Data: ELFDATA2LSB90 Type: ET_EXEC91DWARF:92 debug_str_offsets:93 - Length: 0x123494 Version: 695 Padding: 0x1296 97## d) Test that an empty 'Offsets' field is allowed.98 99# RUN: yaml2obj --docnum=3 %s -o %t3.o100# RUN: llvm-readelf --hex-dump=.debug_str_offsets %t3.o | \101# RUN: FileCheck %s --check-prefix=EMPTY-OFFSETS102 103# EMPTY-OFFSETS: Hex dump of section '.debug_str_offsets':104# EMPTY-OFFSETS-NEXT: 0x00000000 04000000 05000000 ........105## ^------- unit_length (4-byte)106## ^--- version (2-byte)107## ^--- padding (2-byte)108 109--- !ELF110FileHeader:111 Class: ELFCLASS64112 Data: ELFDATA2LSB113 Type: ET_EXEC114DWARF:115 debug_str_offsets:116 - Offsets: []117 118## e) Test that the .debug_str_offsets section header is emitted if the "debug_str_offsets" is empty.119 120# RUN: yaml2obj --docnum=4 %s -o %t4.o121# RUN: llvm-readobj --sections --section-data %t4.o | \122# RUN: FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefixes=SHDR,EMPTY-CONTENT123 124# EMPTY-CONTENT-NEXT: SectionData (125# EMPTY-CONTENT-NEXT: )126 127--- !ELF128FileHeader:129 Class: ELFCLASS64130 Data: ELFDATA2LSB131 Type: ET_EXEC132DWARF:133 debug_str_offsets: []134 135## f) Generate the .debug_str_offsets section from raw section content.136 137# RUN: yaml2obj --docnum=5 %s -o %t5.o138# RUN: llvm-readobj --sections --section-data %t5.o | \139# RUN: FileCheck %s -DADDRALIGN=0 -DSIZE=3 --check-prefixes=SHDR,ARBITRARY-CONTENT140 141# ARBITRARY-CONTENT: SectionData (142# ARBITRARY-CONTENT-NEXT: 0000: 112233143# ARBITRARY-CONTENT-NEXT: )144 145--- !ELF146FileHeader:147 Class: ELFCLASS64148 Data: ELFDATA2LSB149 Type: ET_EXEC150Sections:151 - Name: .debug_str_offsets152 Type: SHT_PROGBITS153 Content: "112233"154 155## g) Generate the .debug_str_offsets section when the "Size" is specified.156 157# RUN: yaml2obj --docnum=6 %s -o %t6.o158# RUN: llvm-readelf --hex-dump=.debug_str_offsets %t6.o | \159# RUN: FileCheck %s --check-prefix=SIZE160 161# SIZE: Hex dump of section '.debug_str_offsets':162# SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................163# SIZE-EMPTY:164 165--- !ELF166FileHeader:167 Class: ELFCLASS64168 Data: ELFDATA2LSB169 Type: ET_EXEC170Sections:171 - Name: .debug_str_offsets172 Type: SHT_PROGBITS173 Size: 0x10174 175## h) Test that yaml2obj emits an error message when both the "Size" and the176## "debug_str_offsets" entry are specified at the same time.177 178# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=ERROR179 180# ERROR: yaml2obj: error: cannot specify section '.debug_str_offsets' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time181 182--- !ELF183FileHeader:184 Class: ELFCLASS64185 Data: ELFDATA2LSB186 Type: ET_EXEC187Sections:188 - Name: .debug_str_offsets189 Type: SHT_PROGBITS190 Size: 0x10191DWARF:192 debug_str_offsets:193 - Offsets: []194 195## i) Test that yaml2obj emits an error message when both the "Content" and the196## "debug_str_offsets" entry are specified at the same time.197 198# RUN: not yaml2obj --docnum=8 %s 2>&1 | FileCheck %s --check-prefix=ERROR199 200--- !ELF201FileHeader:202 Class: ELFCLASS64203 Data: ELFDATA2LSB204 Type: ET_EXEC205Sections:206 - Name: .debug_str_offsets207 Type: SHT_PROGBITS208 Content: "00"209DWARF:210 debug_str_offsets:211 - Offsets: []212 213## j) Test that all the properties can be overridden by the section header when214## the "debug_str_offsets" entry doesn't exist.215 216# RUN: yaml2obj --docnum=9 %s -o %t9.o217# RUN: llvm-readelf --sections %t9.o | FileCheck %s --check-prefix=OVERRIDDEN218 219# OVERRIDDEN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al220# OVERRIDDEN: [ 1] .debug_str_offsets STRTAB 0000000000002020 000050 000008 01 A 2 1 2221# OVERRIDDEN-NEXT: [ 2] .sec STRTAB 0000000000000000 000058 000000 00 0 0 0222 223--- !ELF224FileHeader:225 Class: ELFCLASS64226 Data: ELFDATA2LSB227 Type: ET_EXEC228Sections:229 - Name: .debug_str_offsets230 Type: SHT_STRTAB ## SHT_PROGBITS by default.231 Flags: [SHF_ALLOC] ## 0 by default.232 Link: .sec ## 0 by default.233 EntSize: 1 ## 0 by default.234 Info: 1 ## 0 by default.235 AddressAlign: 2 ## 0 by default.236 Address: 0x2020 ## 0x00 by default.237 Offset: 0x50 ## 0x40 for the first section.238 Size: 0x08 ## Set the "Size" so that we can reuse the check tag "OVERRIDDEN".239 - Name: .sec ## Linked by .debug_str_offsets.240 Type: SHT_STRTAB241 242## k) Test that all the properties can be overridden by the section header when243## the "debug_str_offsets" entry exists.244 245# RUN: yaml2obj --docnum=10 %s -o %t10.o246# RUN: llvm-readelf --sections %t10.o | FileCheck %s --check-prefix=OVERRIDDEN247 248--- !ELF249FileHeader:250 Class: ELFCLASS64251 Data: ELFDATA2LSB252 Type: ET_EXEC253Sections:254 - Name: .debug_str_offsets255 Type: SHT_STRTAB ## SHT_PROGBITS by default.256 Flags: [SHF_ALLOC] ## 0 by default.257 Link: .sec ## 0 by default.258 EntSize: 1 ## 0 by default.259 Info: 1 ## 0 by default.260 AddressAlign: 2 ## 1 by default.261 Address: 0x2020 ## 0x00 by default.262 Offset: 0x50 ## 0x40 for the first section.263 - Name: .sec ## Linked by .debug_str_offsets.264 Type: SHT_STRTAB265DWARF:266 debug_str_offsets:267 - Offsets: []268