| 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.o |
| 6 |
# RUN: llvm-readobj --sections --section-data %t1.le.o | \ |
| 7 |
# RUN: FileCheck -DSIZE=48 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF-LE |
| 8 |
|
| 9 |
# SHDR: Index: 1 |
| 10 |
# 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: 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 |
# 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 |
--- !ELF |
| 38 |
FileHeader: |
| 39 |
Class: ELFCLASS64 |
| 40 |
Data: [[ENDIAN]] |
| 41 |
Type: ET_EXEC |
| 42 |
DWARF: |
| 43 |
debug_str_offsets: |
| 44 |
- Offsets: |
| 45 |
- 0x12345678 |
| 46 |
- 0x87654321 |
| 47 |
- Format: DWARF64 |
| 48 |
Offsets: |
| 49 |
- 0x123456789abcdef0 |
| 50 |
- 0xabcdef0123456789 |
| 51 |
|
| 52 |
## b) Generate and verify a big endian .debug_str_offsets section. |
| 53 |
|
| 54 |
# RUN: yaml2obj -DENDIAN=ELFDATA2MSB --docnum=1 %s -o %t1.be.o |
| 55 |
# RUN: llvm-readobj --sections --section-data %t1.be.o | \ |
| 56 |
# RUN: FileCheck -DSIZE=48 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF-BE |
| 57 |
|
| 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.o |
| 77 |
# RUN: llvm-readelf --hex-dump=.debug_str_offsets %t2.o | \ |
| 78 |
# RUN: FileCheck %s --check-prefix=OVERWRITE |
| 79 |
|
| 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 |
--- !ELF |
| 87 |
FileHeader: |
| 88 |
Class: ELFCLASS64 |
| 89 |
Data: ELFDATA2LSB |
| 90 |
Type: ET_EXEC |
| 91 |
DWARF: |
| 92 |
debug_str_offsets: |
| 93 |
- Length: 0x1234 |
| 94 |
Version: 6 |
| 95 |
Padding: 0x12 |
| 96 |
|
| 97 |
## d) Test that an empty 'Offsets' field is allowed. |
| 98 |
|
| 99 |
# RUN: yaml2obj --docnum=3 %s -o %t3.o |
| 100 |
# RUN: llvm-readelf --hex-dump=.debug_str_offsets %t3.o | \ |
| 101 |
# RUN: FileCheck %s --check-prefix=EMPTY-OFFSETS |
| 102 |
|
| 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 |
--- !ELF |
| 110 |
FileHeader: |
| 111 |
Class: ELFCLASS64 |
| 112 |
Data: ELFDATA2LSB |
| 113 |
Type: ET_EXEC |
| 114 |
DWARF: |
| 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.o |
| 121 |
# RUN: llvm-readobj --sections --section-data %t4.o | \ |
| 122 |
# RUN: FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefixes=SHDR,EMPTY-CONTENT |
| 123 |
|
| 124 |
# EMPTY-CONTENT-NEXT: SectionData ( |
| 125 |
# EMPTY-CONTENT-NEXT: ) |
| 126 |
|
| 127 |
--- !ELF |
| 128 |
FileHeader: |
| 129 |
Class: ELFCLASS64 |
| 130 |
Data: ELFDATA2LSB |
| 131 |
Type: ET_EXEC |
| 132 |
DWARF: |
| 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.o |
| 138 |
# RUN: llvm-readobj --sections --section-data %t5.o | \ |
| 139 |
# RUN: FileCheck %s -DADDRALIGN=0 -DSIZE=3 --check-prefixes=SHDR,ARBITRARY-CONTENT |
| 140 |
|
| 141 |
# ARBITRARY-CONTENT: SectionData ( |
| 142 |
# ARBITRARY-CONTENT-NEXT: 0000: 112233 |
| 143 |
# ARBITRARY-CONTENT-NEXT: ) |
| 144 |
|
| 145 |
--- !ELF |
| 146 |
FileHeader: |
| 147 |
Class: ELFCLASS64 |
| 148 |
Data: ELFDATA2LSB |
| 149 |
Type: ET_EXEC |
| 150 |
Sections: |
| 151 |
- Name: .debug_str_offsets |
| 152 |
Type: SHT_PROGBITS |
| 153 |
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.o |
| 158 |
# RUN: llvm-readelf --hex-dump=.debug_str_offsets %t6.o | \ |
| 159 |
# RUN: FileCheck %s --check-prefix=SIZE |
| 160 |
|
| 161 |
# SIZE: Hex dump of section '.debug_str_offsets': |
| 162 |
# SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................ |
| 163 |
# SIZE-EMPTY: |
| 164 |
|
| 165 |
--- !ELF |
| 166 |
FileHeader: |
| 167 |
Class: ELFCLASS64 |
| 168 |
Data: ELFDATA2LSB |
| 169 |
Type: ET_EXEC |
| 170 |
Sections: |
| 171 |
- Name: .debug_str_offsets |
| 172 |
Type: SHT_PROGBITS |
| 173 |
Size: 0x10 |
| 174 |
|
| 175 |
## h) Test that yaml2obj emits an error message when both the "Size" and the |
| 176 |
## "debug_str_offsets" entry are specified at the same time. |
| 177 |
|
| 178 |
# RUN: not yaml2obj --docnum=7 %s 2>&1 | FileCheck %s --check-prefix=ERROR |
| 179 |
|
| 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 time |
| 181 |
|
| 182 |
--- !ELF |
| 183 |
FileHeader: |
| 184 |
Class: ELFCLASS64 |
| 185 |
Data: ELFDATA2LSB |
| 186 |
Type: ET_EXEC |
| 187 |
Sections: |
| 188 |
- Name: .debug_str_offsets |
| 189 |
Type: SHT_PROGBITS |
| 190 |
Size: 0x10 |
| 191 |
DWARF: |
| 192 |
debug_str_offsets: |
| 193 |
- Offsets: [] |
| 194 |
|
| 195 |
## i) Test that yaml2obj emits an error message when both the "Content" and the |
| 196 |
## "debug_str_offsets" entry are specified at the same time. |
| 197 |
|
| 198 |
# RUN: not yaml2obj --docnum=8 %s 2>&1 | FileCheck %s --check-prefix=ERROR |
| 199 |
|
| 200 |
--- !ELF |
| 201 |
FileHeader: |
| 202 |
Class: ELFCLASS64 |
| 203 |
Data: ELFDATA2LSB |
| 204 |
Type: ET_EXEC |
| 205 |
Sections: |
| 206 |
- Name: .debug_str_offsets |
| 207 |
Type: SHT_PROGBITS |
| 208 |
Content: "00" |
| 209 |
DWARF: |
| 210 |
debug_str_offsets: |
| 211 |
- Offsets: [] |
| 212 |
|
| 213 |
## j) Test that all the properties can be overridden by the section header when |
| 214 |
## the "debug_str_offsets" entry doesn't exist. |
| 215 |
|
| 216 |
# RUN: yaml2obj --docnum=9 %s -o %t9.o |
| 217 |
# RUN: llvm-readelf --sections %t9.o | FileCheck %s --check-prefix=OVERRIDDEN |
| 218 |
|
| 219 |
# OVERRIDDEN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al |
| 220 |
# OVERRIDDEN: [ 1] .debug_str_offsets STRTAB 0000000000002020 000050 000008 01 A 2 1 2 |
| 221 |
# OVERRIDDEN-NEXT: [ 2] .sec STRTAB 0000000000000000 000058 000000 00 0 0 0 |
| 222 |
|
| 223 |
--- !ELF |
| 224 |
FileHeader: |
| 225 |
Class: ELFCLASS64 |
| 226 |
Data: ELFDATA2LSB |
| 227 |
Type: ET_EXEC |
| 228 |
Sections: |
| 229 |
- Name: .debug_str_offsets |
| 230 |
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_STRTAB |
| 241 |
|
| 242 |
## k) Test that all the properties can be overridden by the section header when |
| 243 |
## the "debug_str_offsets" entry exists. |
| 244 |
|
| 245 |
# RUN: yaml2obj --docnum=10 %s -o %t10.o |
| 246 |
# RUN: llvm-readelf --sections %t10.o | FileCheck %s --check-prefix=OVERRIDDEN |
| 247 |
|
| 248 |
--- !ELF |
| 249 |
FileHeader: |
| 250 |
Class: ELFCLASS64 |
| 251 |
Data: ELFDATA2LSB |
| 252 |
Type: ET_EXEC |
| 253 |
Sections: |
| 254 |
- Name: .debug_str_offsets |
| 255 |
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_STRTAB |
| 265 |
DWARF: |
| 266 |
debug_str_offsets: |
| 267 |
- Offsets: [] |