1 ## A user should be able to specify any arbitrary string table as the section
2 ## header string table, including the symbol string table. This test covers
3 ## various cases to do with this.
5 ## Case 1: custom name specified for string table.
6 # RUN: yaml2obj --docnum=1 %s -o %t1 -DSHSTRTAB=.strings
7 # RUN: llvm-readelf -S -p .strings %t1 | FileCheck %s --check-prefix=CASE1
9 # CASE1: There are 5 section headers
11 # CASE1-NEXT: Section Headers:
12 # CASE1-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
13 # CASE1-NEXT: [ 0] NULL
14 # CASE1-NEXT: [ 1] .foo{{ }}
15 # CASE1-NEXT: [ 2] .bar{{ }}
16 # CASE1-NEXT: [ 3] .strtab{{ }}
17 # CASE1-NEXT: [ 4] .strings STRTAB 0000000000000000 [[#%x,]] 00001c 00 0 0 1
19 # CASE1: String dump of section '.strings':
20 # CASE1-NEXT: [ 1] .strings{{$}}
21 # CASE1-NEXT: [ a] .bar{{$}}
22 # CASE1-NEXT: [ f] .foo{{$}}
23 # CASE1-NEXT: [ 14] .strtab{{$}}
31 SectionHeaderStringTable: [[SHSTRTAB=<none>]]
35 - Name: [[OTHER=.bar]]
38 ## Case 2: reuse symbol string table.
39 # RUN: yaml2obj --docnum=2 %s -o %t2 -DSHSTRTAB=.strtab
40 # RUN: llvm-readelf -S -s -p .strtab %t2 | FileCheck %s --check-prefix=CASE2
42 # CASE2: There are 5 section headers
44 # CASE2-NEXT: Section Headers:
45 # CASE2-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
46 # CASE2-NEXT: [ 0] NULL
47 # CASE2-NEXT: [ 1] .foo{{ }}
48 # CASE2-NEXT: [ 2] .bar{{ }}
49 # CASE2-NEXT: [ 3] .symtab{{ }}
50 # CASE2-NEXT: [ 4] .strtab STRTAB 0000000000000000 [[#%x,]] 000023 00 0 0 1
52 # CASE2: Symbol table '.symtab' contains 3 entries:
53 # CASE2-NEXT: Num: {{.*}} Ndx Name
54 # CASE2-NEXT: 0: {{.*}} UND {{$}}
55 # CASE2-NEXT: 1: {{.*}} baz{{$}}
56 # CASE2-NEXT: 2: {{.*}} bob{{$}}
58 # CASE2: String dump of section '.strtab':
59 # CASE2-NEXT: [ 1] baz{{$}}
60 # CASE2-NEXT: [ 5] .bar{{$}}
61 # CASE2-NEXT: [ a] .foo{{$}}
62 # CASE2-NEXT: [ f] bob{{$}}
63 # CASE2-NEXT: [ 13] .strtab{{$}}
64 # CASE2-NEXT: [ 1b] .symtab{{$}}
72 SectionHeaderStringTable: [[SHSTRTAB]]
82 ## Case 3: reuse dynamic string table.
83 # RUN: yaml2obj --docnum=3 %s -o %t3 -DSHSTRTAB=.dynstr
84 # RUN: llvm-readelf -S --dyn-syms -p .dynstr %t3 | FileCheck %s --check-prefix=CASE3
91 SectionHeaderStringTable: [[SHSTRTAB]]
101 # CASE3: There are 6 section headers
103 # CASE3-NEXT: Section Headers:
104 # CASE3-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
105 # CASE3-NEXT: [ 0] NULL
106 # CASE3-NEXT: [ 1] .foo{{ }}
107 # CASE3-NEXT: [ 2] .bar{{ }}
108 # CASE3-NEXT: [ 3] .dynsym{{ }}
109 # CASE3-NEXT: [ 4] .dynstr STRTAB 0000000000000048 [[#%x,]] 00002b 00 A 0 0 1
110 # CASE3-NEXT: [ 5] .strtab{{ }}
112 # CASE3: Symbol table '.dynsym' contains 3 entries:
113 # CASE3-NEXT: Num: {{.*}} Ndx Name
114 # CASE3-NEXT: 0: {{.*}} UND {{$}}
115 # CASE3-NEXT: 1: {{.*}} baz{{$}}
116 # CASE3-NEXT: 2: {{.*}} bob{{$}}
118 # CASE3: String dump of section '.dynstr':
119 # CASE3-NEXT: [ 1] baz{{$}}
120 # CASE3-NEXT: [ 5] .dynstr{{$}}
121 # CASE3-NEXT: [ d] .bar{{$}}
122 # CASE3-NEXT: [ 12] .foo{{$}}
123 # CASE3-NEXT: [ 17] .dynsym{{$}}
124 # CASE3-NEXT: [ 1f] bob{{$}}
125 # CASE3-NEXT: [ 23] .strtab{{$}}
128 ## Case 4: shstrtab specified to be otherwise ungenerated non-strtab implicit
130 # RUN: yaml2obj --docnum=1 %s -o %t4 -DSHSTRTAB=.symtab
131 # RUN: llvm-readelf -S -p .symtab %t4 | FileCheck %s --check-prefix=CASE4
133 # CASE4: There are 5 section headers
135 # CASE4-NEXT: Section Headers:
136 # CASE4-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
137 # CASE4-NEXT: [ 0] NULL
138 # CASE4-NEXT: [ 1] .foo{{ }}
139 # CASE4-NEXT: [ 2] .bar{{ }}
140 # CASE4-NEXT: [ 3] .strtab{{ }}
141 # CASE4-NEXT: [ 4] .symtab STRTAB 0000000000000000 [[#%x,]] 00001b 00 0 0 1
143 # CASE4: String dump of section '.symtab':
144 # CASE4-NEXT: [ 1] .bar{{$}}
145 # CASE4-NEXT: [ 6] .foo{{$}}
146 # CASE4-NEXT: [ b] .strtab{{$}}
147 # CASE4-NEXT: [ 13] .symtab{{$}}
149 ## Case 5: shstrtab specified to be otherwise ungenerated .dynstr section. In
150 ## this case, the SHF_ALLOC flag will be set.
151 # RUN: yaml2obj --docnum=1 %s -o %t5 -DSHSTRTAB=.dynstr
152 # RUN: llvm-readelf -S -p .dynstr %t5 | FileCheck %s --check-prefix=CASE5
154 # CASE5: There are 5 section headers
156 # CASE5-NEXT: Section Headers:
157 # CASE5-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
158 # CASE5-NEXT: [ 0] NULL
159 # CASE5-NEXT: [ 1] .foo{{ }}
160 # CASE5-NEXT: [ 2] .bar{{ }}
161 # CASE5-NEXT: [ 3] .strtab{{ }}
162 # CASE5-NEXT: [ 4] .dynstr STRTAB 0000000000000001 [[#%x,]] 00001b 00 A 0 0 1
164 # CASE5: String dump of section '.dynstr':
165 # CASE5-NEXT: [ 1] .dynstr{{$}}
166 # CASE5-NEXT: [ 9] .bar{{$}}
167 # CASE5-NEXT: [ e] .foo{{$}}
168 # CASE5-NEXT: [ 13] .strtab{{$}}
170 ## Case 6: shstrtab specified to be otherwise ungenerated .debug_str section. In
171 ## this case, the sh_entsize will be set to 1.
172 # RUN: yaml2obj --docnum=1 %s -o %t6 -DSHSTRTAB=.debug_str
173 # RUN: llvm-readelf -S -p .debug_str %t6 | FileCheck %s --check-prefix=CASE6
175 # CASE6: There are 5 section headers
177 # CASE6-NEXT: Section Headers:
178 # CASE6-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
179 # CASE6-NEXT: [ 0] NULL
180 # CASE6-NEXT: [ 1] .foo{{ }}
181 # CASE6-NEXT: [ 2] .bar{{ }}
182 # CASE6-NEXT: [ 3] .strtab{{ }}
183 # CASE6-NEXT: [ 4] .debug_str STRTAB 0000000000000000 [[#%x,]] 00001e 01 0 0 1
185 # CASE6: String dump of section '.debug_str':
186 # CASE6-NEXT: [ 1] .debug_str{{$}}
187 # CASE6-NEXT: [ c] .bar{{$}}
188 # CASE6-NEXT: [ 11] .foo{{$}}
189 # CASE6-NEXT: [ 16] .strtab{{$}}
191 ## Case 7: shstrtab specified to be the .symtab section, when there are symbols.
192 ## This triggers an error (since the symbols cannot be represented in the
193 ## section as section names).
194 # RUN: not yaml2obj --docnum=2 %s -o %t7 -DSHSTRTAB=.symtab 2>&1 | FileCheck %s --check-prefix=ERR1
196 # ERR1: error: cannot use '.symtab' as the section header name table when there are symbols
198 ## Case 8: shstrtab specified to be the .dynsym section, when there are dynamic
199 ## symbols. This triggers an error (since the symbols cannot be represented in
200 ## the section as section names).
201 # RUN: not yaml2obj --docnum=3 %s -o %t8 -DSHSTRTAB=.dynsym 2>&1 | FileCheck %s --check-prefix=ERR2
203 # ERR2: error: cannot use '.dynsym' as the section header name table when there are dynamic symbols
205 ## Case 9: shstrtab specified to be the .debug_str section, when there are DWARF
206 ## debug strings. This triggers an error.
207 # RUN: not yaml2obj --docnum=4 %s -o %t9 2>&1 | FileCheck %s --check-prefix=ERR3
209 # ERR3: error: cannot use '.debug_str' as the section header name table when it is needed for DWARF output
216 SectionHeaderStringTable: .debug_str
221 ## Case 10: can explicitly specifiy ".shstrtab" as shstrtab. Output will be the
222 ## same as if it wasn't sepcified at all.
223 # RUN: yaml2obj --docnum=1 %s -o %t10 -DSHSTRTAB=.shstrtab
224 # RUN: llvm-readelf -S -p .shstrtab %t10 | FileCheck %s --check-prefix=CASE10
225 # RUN: yaml2obj --docnum=1 %s -o %t10.default
226 # RUN: cmp %t10 %t10.default
228 # CASE10: There are 5 section headers
230 # CASE10-NEXT: Section Headers:
231 # CASE10-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
232 # CASE10-NEXT: [ 0] NULL
233 # CASE10-NEXT: [ 1] .foo{{ }}
234 # CASE10-NEXT: [ 2] .bar{{ }}
235 # CASE10-NEXT: [ 3] .strtab{{ }}
236 # CASE10-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 [[#%x,]] 00001d 00 0 0 1
238 # CASE10: String dump of section '.shstrtab':
239 # CASE10-NEXT: [ 1] .bar{{$}}
240 # CASE10-NEXT: [ 6] .foo{{$}}
241 # CASE10-NEXT: [ b] .shstrtab{{$}}
242 # CASE10-NEXT: [ 15] .strtab{{$}}
245 ## Case 11: can specify custom shstrtab properties.
246 ## FIXME: when the section is listed explicitly, the sh_addralign value is 0 if
247 ## not overwritten, which is inconsistent with when the section is not
249 # RUN: yaml2obj --docnum=5 %s -o %t11 -DENTSIZE=2
250 # RUN: llvm-readelf -S -p .strings %t11 | FileCheck %s --check-prefix=CASE11
252 # CASE11: There are 5 section headers
254 # CASE11-NEXT: Section Headers:
255 # CASE11-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
256 # CASE11-NEXT: [ 0] NULL
257 # CASE11-NEXT: [ 1] .foo{{ }}
258 # CASE11-NEXT: [ 2] .strings STRTAB 0000000000000000 [[#%x,]] 00001c 02 0 0 0
259 # CASE11-NEXT: [ 3] .bar{{ }}
260 # CASE11-NEXT: [ 4] .strtab{{ }}
262 # CASE11: String dump of section '.strings':
263 # CASE11-NEXT: [ 1] .strings{{$}}
264 # CASE11-NEXT: [ a] .bar{{$}}
265 # CASE11-NEXT: [ f] .foo{{$}}
266 # CASE11-NEXT: [ 14] .strtab{{$}}
274 SectionHeaderStringTable: .strings
279 Type: [[TYPE=SHT_STRTAB]]
280 EntSize: [[ENTSIZE=<none>]]
281 Size: [[SIZE=<none>]]
282 Content: [[CONTENT=<none>]]
286 ## Case 12: shstrtab does not have SHT_STRTAB type. Default properties will be
287 ## derived from the specified section type.
288 # RUN: yaml2obj --docnum=5 %s -o %t12 -DTYPE=SHT_RELA
289 # RUN: llvm-readelf -S %t12 | FileCheck %s --check-prefix=CASE12
291 # CASE12: There are 5 section headers
293 # CASE12-NEXT: Section Headers:
294 # CASE12-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
295 # CASE12-NEXT: [ 0] NULL
296 # CASE12-NEXT: [ 1] .foo{{ }}
297 # CASE12-NEXT: [ 2] .strings RELA 0000000000000000 [[#%x,]] 00001c 18 0 0 0
298 # CASE12-NEXT: [ 3] .bar{{ }}
299 # CASE12-NEXT: [ 4] .strtab{{ }}
301 ## Case 13: shstrtab has specified Content. The specified content overrides the
302 ## implicitly generated content.
303 # RUN: yaml2obj --docnum=5 %s -o %t13 -DCONTENT="00616263646566676800696a6b6c006d6e6f70007172737475767700787a7b7c00"
304 # RUN: llvm-readelf -S %t13 | FileCheck %s --check-prefix=CASE13
306 # CASE13: There are 5 section headers
308 # CASE13-NEXT: Section Headers:
309 # CASE13-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
310 # CASE13-NEXT: [ 0] NULL
311 # CASE13-NEXT: [ 1] mnop{{ }}
312 # CASE13-NEXT: [ 2] abcdefgh STRTAB 0000000000000000 [[#%x,]] 000021 00 0 0 0
313 # CASE13-NEXT: [ 3] ijkl{{ }}
314 # CASE13-NEXT: [ 4] qrstuvw{{ }}
316 ## Case 14: shstrtab has specified Size. The section will be filled with zeros
317 ## to the requested size.
318 # RUN: yaml2obj --docnum=5 %s -o %t14 -DSIZE=32
319 # RUN: llvm-readelf -S -p 2 %t14 | FileCheck %s --check-prefix=CASE14
321 # CASE14: There are 5 section headers
323 # CASE14-NEXT: Section Headers:
324 # CASE14-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
325 # CASE14-NEXT: [ 0] NULL
326 # CASE14-NEXT: [ 1] PROGBITS
327 # CASE14-NEXT: [ 2] STRTAB 0000000000000000 [[#%x,]] 000020 00 0 0 0
328 # CASE14-NEXT: [ 3] PROGBITS
329 # CASE14-NEXT: [ 4] STRTAB
331 # CASE14: String dump of section '':
334 ## Case 15: custom shstrtab and no section header table. The section header
335 ## names shouldn't appear anywhere in the output file.
336 # RUN: yaml2obj --docnum=6 %s -o %t15
337 # RUN: FileCheck %s --input-file=%t15 \
338 # RUN: --implicit-check-not=.strings --implicit-check-not=.foo \
339 # RUN: --implicit-check-not=.bar
346 SectionHeaderStringTable: .strings
352 - Type: SectionHeaderTable
355 ## Case 16: custom shstrtab can be reordered in the section header table.
356 # RUN: yaml2obj --docnum=7 %s -o %t16
357 # RUN: llvm-readelf -S %t16 | FileCheck %s --check-prefix=CASE16
359 # CASE16: There are 5 section headers
361 # CASE16-NEXT: Section Headers:
362 # CASE16-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
363 # CASE16-NEXT: [ 0] NULL
364 # CASE16-NEXT: [ 1] .foo{{ }}
365 # CASE16-NEXT: [ 2] .strings STRTAB 0000000000000000 [[#%x,]] 00001c 00 0 0 1
366 # CASE16-NEXT: [ 3] .bar{{ }}
367 # CASE16-NEXT: [ 4] .strtab{{ }}
374 SectionHeaderStringTable: .strings
380 - Type: SectionHeaderTable
387 ## Case 17: custom shstrtab section header can be excluded.
388 # RUN: yaml2obj --docnum=8 %s -o %t17
389 # RUN: llvm-readelf -h -S %t17 | FileCheck %s --check-prefix=CASE17
391 # CASE17: Section header string table index: 0
392 # CASE17: There are 4 section headers
394 # CASE17-NEXT: Section Headers:
395 # CASE17-NEXT: [Nr] Name Type
396 # CASE17-NEXT: [ 0] <no-strings> NULL
397 # CASE17-NEXT: [ 1] <no-strings> PROGBITS
398 # CASE17-NEXT: [ 2] <no-strings> PROGBITS
399 # CASE17-NEXT: [ 3] <no-strings> STRTAB
406 SectionHeaderStringTable: .strings
412 - Type: SectionHeaderTable
420 ## Case 18: section name for excluded section does not appear in custom
422 # RUN: yaml2obj --docnum=9 %s -o %t18
423 # RUN: llvm-readelf -S -p .strings %t18 | FileCheck %s --check-prefix=CASE18
425 # CASE18: There are 4 section headers
427 # CASE18-NEXT: Section Headers:
428 # CASE18-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
429 # CASE18-NEXT: [ 0] NULL
430 # CASE18-NEXT: [ 1] .foo{{ }}
431 # CASE18-NEXT: [ 2] .strings STRTAB 0000000000000000 [[#%x,]] 000017 00 0 0 1
432 # CASE18-NEXT: [ 3] .strtab{{ }}
434 # CASE18: String dump of section '.strings':
435 # CASE18-NEXT: [ 1] .strings
436 # CASE18-NEXT: [ a] .foo
437 # CASE18-NEXT: [ f] .strtab
445 SectionHeaderStringTable: .strings
451 - Type: SectionHeaderTable
459 ## Case 19: custom shstrtab can have a uniqued name.
460 # RUN: yaml2obj --docnum=1 %s -o %t19 '-DSHSTRTAB=.strings (1)' '-DOTHER=.strings (0)'
461 # RUN: llvm-readelf -S -p 4 %t19 | FileCheck %s --check-prefix=CASE19
463 # CASE19: There are 5 section headers
465 # CASE19-NEXT: Section Headers:
466 # CASE19-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
467 # CASE19-NEXT: [ 0] NULL
468 # CASE19-NEXT: [ 1] .foo{{ }}
469 # CASE19-NEXT: [ 2] .strings PROGBITS
470 # CASE19-NEXT: [ 3] .strtab{{ }}
471 # CASE19-NEXT: [ 4] .strings STRTAB 0000000000000000 [[#%x,]] 000017 00 0 0 1
473 # CASE19: String dump of section '.strings':
474 # CASE19-NEXT: [ 1] .strings{{$}}
475 # CASE19-NEXT: [ a] .foo{{$}}
476 # CASE19-NEXT: [ f] .strtab{{$}}
479 ## Case 20: custom shstrtab named ".strtab" with uniquifying ID.
480 # RUN: yaml2obj --docnum=2 %s -o %t20 '-DSHSTRTAB=.strtab (1)'
481 # RUN: llvm-readelf -S -s -p 4 -p 5 %t20 | FileCheck %s --check-prefix=CASE20
483 # CASE20: There are 6 section headers
485 # CASE20-NEXT: Section Headers:
486 # CASE20-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
487 # CASE20-NEXT: [ 0] NULL
488 # CASE20-NEXT: [ 1] .foo{{ }}
489 # CASE20-NEXT: [ 2] .bar{{ }}
490 # CASE20-NEXT: [ 3] .symtab{{ }}
491 # CASE20-NEXT: [ 4] .strtab STRTAB [[#%x,]] [[#%x,]] 000009 00 0 0 1
492 # CASE20-NEXT: [ 5] .strtab STRTAB 0000000000000000 [[#%x,]] 00001b 00 0 0 1
494 # CASE20: Symbol table '.symtab' contains 3 entries:
495 # CASE20-NEXT: Num: {{.*}} Ndx Name
496 # CASE20-NEXT: 0: {{.*}} UND {{$}}
497 # CASE20-NEXT: 1: {{.*}} baz{{$}}
498 # CASE20-NEXT: 2: {{.*}} bob{{$}}
500 # CASE20: String dump of section '.strtab':
501 # CASE20-NEXT: [ 1] baz
502 # CASE20-NEXT: [ 5] bob
505 # CASE20: String dump of section '.strtab':
506 # CASE20-NEXT: [ 1] .bar{{$}}
507 # CASE20-NEXT: [ 6] .foo{{$}}
508 # CASE20-NEXT: [ b] .strtab{{$}}
509 # CASE20-NEXT: [ 13] .symtab{{$}}
512 ## Case 21: custom shstrtab named ".dynstr" with uniquifying ID.
513 # RUN: yaml2obj --docnum=3 %s -o %t21 '-DSHSTRTAB=.dynstr (1)'
514 # RUN: llvm-readelf -S --dyn-syms -p 4 -p 6 %t21 | FileCheck %s --check-prefix=CASE21
516 # CASE21: There are 7 section headers
518 # CASE21-NEXT: Section Headers:
519 # CASE21-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
520 # CASE21-NEXT: [ 0] NULL
521 # CASE21-NEXT: [ 1] .foo{{ }}
522 # CASE21-NEXT: [ 2] .bar{{ }}
523 # CASE21-NEXT: [ 3] .dynsym{{ }}
524 # CASE21-NEXT: [ 4] .dynstr STRTAB [[#%x,]] [[#%x,]] 000009 00 A 0 0 1
525 # CASE21-NEXT: [ 5] .strtab{{ }}
526 # CASE21-NEXT: [ 6] .dynstr STRTAB 0000000000000000 [[#%x,]] 000023 00 0 0 1
528 # CASE21: Symbol table '.dynsym' contains 3 entries:
529 # CASE21-NEXT: Num: {{.*}} Ndx Name
530 # CASE21-NEXT: 0: {{.*}} UND {{$}}
531 # CASE21-NEXT: 1: {{.*}} baz{{$}}
532 # CASE21-NEXT: 2: {{.*}} bob{{$}}
534 # CASE21: String dump of section '.dynstr':
535 # CASE21-NEXT: [ 1] baz
536 # CASE21-NEXT: [ 5] bob
539 # CASE21: String dump of section '.dynstr':
540 # CASE21-NEXT: [ 1] .dynstr{{$}}
541 # CASE21-NEXT: [ 9] .bar{{$}}
542 # CASE21-NEXT: [ e] .foo{{$}}
543 # CASE21-NEXT: [ 13] .dynsym{{$}}
544 # CASE21-NEXT: [ 1b] .strtab{{$}}