1 ## Show that the SectionHeaderStringTable field in the document header is set,
2 ## iff the section name is not ".shstrtab".
3 ## Also show that no section appears in the Sections table for this section,
4 ## unless some property is different to the default.
6 ## Show the case when the name is a custom string (the key should be set).
7 # RUN: yaml2obj --docnum=1 %s -o %t1.o
8 # RUN: obj2yaml %t1.o > %t1.yaml
9 # RUN: FileCheck %s --input-file=%t1.yaml --check-prefix=CUSTOM
12 # CUSTOM-NEXT: FileHeader:
13 # CUSTOM-NEXT: Class: ELFCLASS64
14 # CUSTOM-NEXT: Data: ELFDATA2LSB
15 # CUSTOM-NEXT: Type: ET_EXEC
16 # CUSTOM-NEXT: SectionHeaderStringTable: .foo
24 SectionHeaderStringTable: .foo
26 ## Show the case when the e_shstrndx value is SHN_XINDEX and the name is not
27 ## ".shstrtab" (the key should be set).
28 # RUN: yaml2obj --docnum=2 %s -o %t2.o
29 # RUN: obj2yaml %t2.o > %t2.yaml
30 # RUN: FileCheck %s --input-file=%t2.yaml --check-prefix=XINDEX
38 SectionHeaderStringTable: .foo
44 # XINDEX-NEXT: FileHeader:
45 # XINDEX-NEXT: Class: ELFCLASS64
46 # XINDEX-NEXT: Data: ELFDATA2LSB
47 # XINDEX-NEXT: Type: ET_EXEC
48 # XINDEX-NEXT: SectionHeaderStringTable: .foo
49 # XINDEX-NEXT: Sections:
50 # XINDEX-NEXT: - Type: SHT_NULL
51 # XINDEX-NEXT: Link: .foo
52 # XINDEX-NEXT: Size: 0x0
55 ## Show the case when the string table section is also the symbol table's string
56 ## table (the key should be set).
57 # RUN: yaml2obj --docnum=3 %s -o %t3.o
58 # RUN: obj2yaml %t3.o > %t3.yaml
59 # RUN: FileCheck %s --input-file=%t3.yaml --check-prefix=STRTAB
62 # STRTAB-NEXT: FileHeader:
63 # STRTAB-NEXT: Class: ELFCLASS64
64 # STRTAB-NEXT: Data: ELFDATA2LSB
65 # STRTAB-NEXT: Type: ET_EXEC
66 # STRTAB-NEXT: SectionHeaderStringTable: .strtab
67 # STRTAB-NEXT: Symbols:
68 # STRTAB-NEXT: - Name: boz
76 SectionHeaderStringTable: ".strtab"
80 ## Document the case when the string table section is also the symbol table's
81 ## dynamic string table (the key should be set).
82 ## FIXME: Regardless of whether it is shared with the section header string
83 ## table or not, the dynstr (and also the dynsym) should be omitted if
84 ## they match the default behaviour.
85 # RUN: yaml2obj --docnum=4 %s -o %t4.o
86 # RUN: obj2yaml %t4.o > %t4.yaml
87 # RUN: FileCheck %s --input-file=%t4.yaml --check-prefix=DYNSTR
90 # DYNSTR-NEXT: FileHeader:
91 # DYNSTR-NEXT: Class: ELFCLASS64
92 # DYNSTR-NEXT: Data: ELFDATA2LSB
93 # DYNSTR-NEXT: Type: ET_EXEC
94 # DYNSTR-NEXT: SectionHeaderStringTable: .dynstr
95 # DYNSTR-NEXT: Sections:
96 # DYNSTR-NEXT: - Name: .dynsym
97 # DYNSTR-NEXT: Type: SHT_DYNSYM
98 # DYNSTR-NEXT: Flags: [ SHF_ALLOC ]
99 # DYNSTR-NEXT: Link: .dynstr
100 # DYNSTR-NEXT: AddressAlign: 0x8
101 # DYNSTR-NEXT: - Name: .dynstr
102 # DYNSTR-NEXT: Type: SHT_STRTAB
103 # DYNSTR-NEXT: Flags: [ SHF_ALLOC ]
104 # DYNSTR-NEXT: Address: 0x30
105 # DYNSTR-NEXT: AddressAlign: 0x1
106 # DYNSTR-NEXT: DynamicSymbols:
107 # DYNSTR-NEXT: - Name: boz
115 SectionHeaderStringTable: ".dynstr"
119 ## Show the case when the name is the default ".shstrtab" (the key should not be
121 # RUN: yaml2obj --docnum=5 %s -o %t5.o
122 # RUN: obj2yaml %t5.o > %t5.yaml
123 # RUN: FileCheck %s --input-file=%t5.yaml --check-prefix=DEFAULT
126 # DEFAULT-NEXT: FileHeader:
127 # DEFAULT-NEXT: Class: ELFCLASS64
128 # DEFAULT-NEXT: Data: ELFDATA2LSB
129 # DEFAULT-NEXT: Type: ET_EXEC
138 ## Show the case when the e_shstrndx value is 0 and the name is ".shstrtab" (the
139 ## key should not be set).
140 # RUN: yaml2obj --docnum=6 %s -o %t6.o
141 # RUN: obj2yaml %t6.o > %t6.yaml
142 # RUN: FileCheck %s --input-file=%t6.yaml --check-prefix=DEFXINDEX
154 # DEFXINDEX: --- !ELF
155 # DEFXINDEX-NEXT: FileHeader:
156 # DEFXINDEX-NEXT: Class: ELFCLASS64
157 # DEFXINDEX-NEXT: Data: ELFDATA2LSB
158 # DEFXINDEX-NEXT: Type: ET_EXEC
159 # DEFXINDEX-NEXT: Sections:
160 # DEFXINDEX-NEXT: - Type: SHT_NULL
161 # DEFXINDEX-NEXT: Link: .shstrtab
162 # DEFXINDEX-NEXT: Size: 0x0
163 # DEFXINDEX-NEXT: ...
165 ## Show that if there are no section headers, the key is not set.
166 # RUN: yaml2obj --docnum=7 %s -o %t7.o
167 # RUN: obj2yaml %t7.o > %t7.yaml
168 # RUN: FileCheck %s --input-file=%t7.yaml --check-prefix=NOHDRS
176 - Type: SectionHeaderTable
180 # NOHDRS-NEXT: FileHeader:
181 # NOHDRS-NEXT: Class: ELFCLASS64
182 # NOHDRS-NEXT: Data: ELFDATA2LSB
183 # NOHDRS-NEXT: Type: ET_EXEC
184 ## FIXME: There should be a SectionHeaderTable key as per the input.
187 ## Show that a custom-named section header string table can be in a reordered
188 ## section header table.
189 # RUN: yaml2obj --docnum=8 %s -o %t8.o
190 # RUN: obj2yaml %t8.o > %t8.yaml
191 # RUN: FileCheck %s --input-file=%t8.yaml --check-prefix=REORDER
194 # REORDER-NEXT: FileHeader:
195 # REORDER-NEXT: Class: ELFCLASS64
196 # REORDER-NEXT: Data: ELFDATA2LSB
197 # REORDER-NEXT: Type: ET_EXEC
198 # REORDER-NEXT: SectionHeaderStringTable: .foo
199 # REORDER-NEXT: Sections:
200 # REORDER-NEXT: - Name: .baz
201 # REORDER-NEXT: Type: SHT_PROGBITS
202 # REORDER-NEXT: Offset: 0x180
203 # REORDER-NEXT: - Name: .bar
204 # REORDER-NEXT: Type: SHT_PROGBITS
205 ## FIXME: This should be at the start of the sections list.
206 # REORDER-NEXT: - Type: SectionHeaderTable
207 # REORDER-NEXT: Sections:
208 # REORDER-NEXT: - Name: .baz
209 # REORDER-NEXT: - Name: .foo
210 # REORDER-NEXT: - Name: .bar
211 # REORDER-NEXT: - Name: .strtab
219 SectionHeaderStringTable: .foo
221 - Type: SectionHeaderTable
226 ## FIXME: we shouldn't need a .strtab section if there are no symbols.
233 ## Document what happens when a custom-named section header string table is
234 ## placed in between other sections.
235 ## FIXME: obj2yaml should preserve the ordering in the Sections list, but it
236 ## doesn't for custom or default named tables.
237 # RUN: yaml2obj --docnum=9 %s -o %t9.o
238 # RUN: obj2yaml %t9.o > %t9.yaml
239 # RUN: FileCheck %s --input-file=%t9.yaml --check-prefix=PLACED
242 # PLACED-NEXT: FileHeader:
243 # PLACED-NEXT: Class: ELFCLASS64
244 # PLACED-NEXT: Data: ELFDATA2LSB
245 # PLACED-NEXT: Type: ET_EXEC
246 # PLACED-NEXT: SectionHeaderStringTable: .foo
247 # PLACED-NEXT: Sections:
248 # PLACED-NEXT: - Name: .baz
249 # PLACED-NEXT: Type: SHT_PROGBITS
250 # PLACED-NEXT: - Name: .bar
251 # PLACED-NEXT: Type: SHT_PROGBITS
258 SectionHeaderStringTable: .foo
267 ## Show that a custom-named section header string table can be given different
269 # RUN: yaml2obj --docnum=10 %s -o %t10.o
270 # RUN: obj2yaml %t10.o > %t10.yaml
271 # RUN: FileCheck %s --input-file=%t10.yaml --check-prefix=PROPS
274 # PROPS-NEXT: FileHeader:
275 # PROPS-NEXT: Class: ELFCLASS64
276 # PROPS-NEXT: Data: ELFDATA2LSB
277 # PROPS-NEXT: Type: ET_EXEC
278 # PROPS-NEXT: SectionHeaderStringTable: .foo
279 # PROPS-NEXT: Sections:
280 # PROPS-NEXT: - Name: .foo
281 # PROPS-NEXT: Type: SHT_STRTAB
282 # PROPS-NEXT: Flags: [ SHF_ALLOC ]
290 SectionHeaderStringTable: .foo
296 ## Show that an error is reported if the section header string table name cannot
298 # RUN: yaml2obj --docnum=11 %s -o %t11.o
299 # RUNasda: not obj2yaml %t11.o 2>&1 | FileCheck %s --check-prefix=ERR -DFILE=%t11.o
301 # ERR: Error reading file: [[FILE]]: unable to read section header string table name: a section [index 1] has an invalid sh_name (0x10000) offset which goes past the end of the section name string table
313 ## Show that the name is uniquified if necessary.
315 ## Case 1: generic name.
316 # RUN: yaml2obj --docnum=12 %s -o %t12.o
317 # RUN: obj2yaml %t12.o > %t12.yaml
318 # RUN: FileCheck %s --input-file=%t12.yaml --check-prefix=UNIQUIFY1
320 # UNIQUIFY1: --- !ELF
321 # UNIQUIFY1-NEXT: FileHeader:
322 # UNIQUIFY1-NEXT: Class: ELFCLASS64
323 # UNIQUIFY1-NEXT: Data: ELFDATA2LSB
324 # UNIQUIFY1-NEXT: Type: ET_EXEC
325 # UNIQUIFY1-NEXT: SectionHeaderStringTable: '.strings (1)'
326 # UNIQUIFY1-NEXT: Sections:
327 # UNIQUIFY1-NEXT: - Name: .strings
328 # UNIQUIFY1-NEXT: Type: SHT_PROGBITS
329 # UNIQUIFY1-NEXT: ...
336 SectionHeaderStringTable: '.strings (1)'
338 - Name: '.strings (2)'
341 ## Case 2: '.strtab' when symbols are present.
342 # RUN: yaml2obj --docnum=13 %s -o %t13.o '-DNAME=".strtab (1)"'
343 # RUN: obj2yaml %t13.o > %t13.yaml
344 # RUN: FileCheck %s --input-file=%t13.yaml --check-prefix=UNIQUIFY2 \
345 # RUN: -DNAME=.strtab
347 # UNIQUIFY2: --- !ELF
348 # UNIQUIFY2-NEXT: FileHeader:
349 # UNIQUIFY2-NEXT: Class: ELFCLASS64
350 # UNIQUIFY2-NEXT: Data: ELFDATA2LSB
351 # UNIQUIFY2-NEXT: Type: ET_EXEC
352 # UNIQUIFY2-NEXT: SectionHeaderStringTable: '[[NAME]] (1)'
353 # UNIQUIFY2-NEXT: Symbols:
354 # UNIQUIFY2-NEXT: - Name: foo
355 # UNIQUIFY2-NEXT: ...
362 SectionHeaderStringTable: [[NAME]]
366 ## Case 3: '.symtab' when symbols are present.
367 # RUN: yaml2obj --docnum=13 %s -o %t14.o '-DNAME=".symtab (1)"'
368 # RUN: obj2yaml %t14.o > %t14.yaml
369 # RUN: FileCheck %s --input-file=%t14.yaml --check-prefix=UNIQUIFY2 \
370 # RUN: -DNAME=.symtab
372 ## Case 4: '.dynstr' when dynamic symbols are present.
373 # RUN: yaml2obj --docnum=14 %s -o %t15.o '-DNAME=".dynstr (1)"'
374 # RUN: obj2yaml %t15.o > %t15.yaml
375 # RUN: FileCheck %s --input-file=%t15.yaml --check-prefix=UNIQUIFY3 \
376 # RUN: -DNAME=.dynstr
378 # UNIQUIFY3: --- !ELF
379 # UNIQUIFY3-NEXT: FileHeader:
380 # UNIQUIFY3-NEXT: Class: ELFCLASS64
381 # UNIQUIFY3-NEXT: Data: ELFDATA2LSB
382 # UNIQUIFY3-NEXT: Type: ET_EXEC
383 # UNIQUIFY3-NEXT: SectionHeaderStringTable: '[[NAME]] (1)'
384 ## FIXME: The .dynsym and .dynstr sections shouldn't need to be emitted, since
385 ## their values are the default produced by yaml2obj.
386 # UNIQUIFY3-NEXT: Sections:
387 # UNIQUIFY3-NEXT: - Name: .dynsym
388 # UNIQUIFY3-NEXT: Type: SHT_DYNSYM
389 # UNIQUIFY3-NEXT: Flags: [ SHF_ALLOC ]
390 # UNIQUIFY3-NEXT: Link: .dynstr
391 # UNIQUIFY3-NEXT: AddressAlign: 0x8
392 # UNIQUIFY3-NEXT: - Name: .dynstr
393 # UNIQUIFY3-NEXT: Type: SHT_STRTAB
394 # UNIQUIFY3-NEXT: Flags: [ SHF_ALLOC ]
395 # UNIQUIFY3-NEXT: Address: 0x30
396 # UNIQUIFY3-NEXT: AddressAlign: 0x1
397 # UNIQUIFY3-NEXT: DynamicSymbols:
398 # UNIQUIFY3-NEXT: - Name: foo
399 # UNIQUIFY3-NEXT: ...
406 SectionHeaderStringTable: [[NAME]]
410 ## Case 5: '.dynsym' when dynamic symbols are present.
411 # RUN: yaml2obj --docnum=14 %s -o %t16.o '-DNAME=".dynsym (1)"'
412 # RUN: obj2yaml %t16.o > %t16.yaml
413 # RUN: FileCheck %s --input-file=%t16.yaml --check-prefix=UNIQUIFY3 \
414 # RUN: -DNAME=.dynsym
416 ## Case 6: Document what happens for '.debug_str' when DWARF debug strings are
417 ## requested. The dwarf2yaml code uses the last .debug_* named section
418 ## to populate the corresponding DWARF block. As a result, the original
419 ## .debug_str content is lost.
420 ## TODO: We should prevent the dwarf2yaml code from using the section header
421 ## string table to populate the DWARF block.
422 # RUN: yaml2obj --docnum=15 %s -o %t17.o
423 # RUN: obj2yaml %t17.o > %t17.yaml
424 # RUN: FileCheck %s --input-file=%t17.yaml --check-prefix=UNIQUIFY6
426 # UNIQUIFY6: --- !ELF
427 # UNIQUIFY6-NEXT: FileHeader:
428 # UNIQUIFY6-NEXT: Class: ELFCLASS64
429 # UNIQUIFY6-NEXT: Data: ELFDATA2LSB
430 # UNIQUIFY6-NEXT: Type: ET_EXEC
431 # UNIQUIFY6-NEXT: SectionHeaderStringTable: '.debug_str (1)'
432 # UNIQUIFY6-NEXT: DWARF:
433 # UNIQUIFY6-NEXT: debug_str:
434 # UNIQUIFY6-NEXT: - ''
435 # UNIQUIFY6-NEXT: - .debug_str
436 # UNIQUIFY6-NEXT: - .strtab
437 # UNIQUIFY6-NEXT: ...
444 SectionHeaderStringTable: '.debug_str (1)'