xref: /llvm-project/llvm/test/tools/obj2yaml/ELF/shstrtab.yaml (revision b9ce8ea4542fdc57e34e23fc285752d899a01030)
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.
5
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
10
11# CUSTOM:      --- !ELF
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
17# CUSTOM-NEXT: ...
18
19--- !ELF
20FileHeader:
21  Class: ELFCLASS64
22  Data:  ELFDATA2LSB
23  Type:  ET_EXEC
24  SectionHeaderStringTable: .foo
25
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
31
32--- !ELF
33FileHeader:
34  Class:     ELFCLASS64
35  Data:      ELFDATA2LSB
36  Type:      ET_EXEC
37  EShStrNdx: 0xffff
38  SectionHeaderStringTable: .foo
39Sections:
40  - Type: SHT_NULL
41    Link: .foo
42
43# XINDEX:      --- !ELF
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
53# XINDEX-NEXT: ...
54
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
60
61# STRTAB:      --- !ELF
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
69# STRTAB-NEXT: ...
70
71--- !ELF
72FileHeader:
73  Class: ELFCLASS64
74  Data:  ELFDATA2LSB
75  Type:  ET_EXEC
76  SectionHeaderStringTable: ".strtab"
77Symbols:
78  - Name: boz
79
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
88
89# DYNSTR:      --- !ELF
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
108# DYNSTR-NEXT: ...
109
110--- !ELF
111FileHeader:
112  Class: ELFCLASS64
113  Data:  ELFDATA2LSB
114  Type:  ET_EXEC
115  SectionHeaderStringTable: ".dynstr"
116DynamicSymbols:
117  - Name: boz
118
119## Show the case when the name is the default ".shstrtab" (the key should not be
120## set).
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
124
125# DEFAULT:      --- !ELF
126# DEFAULT-NEXT: FileHeader:
127# DEFAULT-NEXT:   Class:           ELFCLASS64
128# DEFAULT-NEXT:   Data:            ELFDATA2LSB
129# DEFAULT-NEXT:   Type:            ET_EXEC
130# DEFAULT-NEXT: ...
131
132--- !ELF
133FileHeader:
134  Class: ELFCLASS64
135  Data:  ELFDATA2LSB
136  Type:  ET_EXEC
137
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
143
144--- !ELF
145FileHeader:
146  Class:     ELFCLASS64
147  Data:      ELFDATA2LSB
148  Type:      ET_EXEC
149  EShStrNdx: 0xffff
150Sections:
151  - Type: SHT_NULL
152    Link: .shstrtab
153
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: ...
164
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
169
170--- !ELF
171FileHeader:
172  Class: ELFCLASS64
173  Data:  ELFDATA2LSB
174  Type:  ET_EXEC
175Sections:
176  - Type: SectionHeaderTable
177    NoHeaders: true
178
179# NOHDRS:      --- !ELF
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.
185# NOHDRS-NEXT: ...
186
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
192
193# REORDER:      --- !ELF
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
212# REORDER-NEXT: ...
213
214--- !ELF
215FileHeader:
216  Class: ELFCLASS64
217  Data:  ELFDATA2LSB
218  Type:  ET_EXEC
219  SectionHeaderStringTable: .foo
220Sections:
221  - Type: SectionHeaderTable
222    Sections:
223      - Name: .baz
224      - Name: .foo
225      - Name: .bar
226      ## FIXME: we shouldn't need a .strtab section if there are no symbols.
227      - Name: .strtab
228  - Name: .baz
229    Type: SHT_PROGBITS
230  - Name: .bar
231    Type: SHT_PROGBITS
232
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
240
241# PLACED:      --- !ELF
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
252
253--- !ELF
254FileHeader:
255  Class: ELFCLASS64
256  Data:  ELFDATA2LSB
257  Type:  ET_EXEC
258  SectionHeaderStringTable: .foo
259Sections:
260  - Name: .baz
261    Type: SHT_PROGBITS
262  - Name: .foo
263    Type: SHT_STRTAB
264  - Name: .bar
265    Type: SHT_PROGBITS
266
267## Show that a custom-named section header string table can be given different
268## properties.
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
272
273# PROPS:      --- !ELF
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 ]
283# PROPS-NEXT: ...
284
285--- !ELF
286FileHeader:
287  Class: ELFCLASS64
288  Data:  ELFDATA2LSB
289  Type:  ET_EXEC
290  SectionHeaderStringTable: .foo
291Sections:
292  - Name:  .foo
293    Type:  SHT_STRTAB
294    Flags: [ SHF_ALLOC ]
295
296## Show that an error is reported if the section header string table name cannot
297## be read.
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
300
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
302
303--- !ELF
304FileHeader:
305  Class: ELFCLASS64
306  Data:  ELFDATA2LSB
307  Type:  ET_EXEC
308Sections:
309  - Name:  .shstrtab
310    Type:  SHT_STRTAB
311    ShName: 0x10000
312
313## Show that the name is uniquified if necessary.
314
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
319
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: ...
330
331--- !ELF
332FileHeader:
333  Class: ELFCLASS64
334  Data:  ELFDATA2LSB
335  Type:  ET_EXEC
336  SectionHeaderStringTable: '.strings (1)'
337Sections:
338  - Name: '.strings (2)'
339    Type: SHT_PROGBITS
340
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
346
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: ...
356
357--- !ELF
358FileHeader:
359  Class: ELFCLASS64
360  Data:  ELFDATA2LSB
361  Type:  ET_EXEC
362  SectionHeaderStringTable: [[NAME]]
363Symbols:
364  - Name: foo
365
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
371
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
377
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: ...
400
401--- !ELF
402FileHeader:
403  Class: ELFCLASS64
404  Data:  ELFDATA2LSB
405  Type:  ET_EXEC
406  SectionHeaderStringTable: [[NAME]]
407DynamicSymbols:
408  - Name: foo
409
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
415
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
425
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: ...
438
439--- !ELF
440FileHeader:
441  Class: ELFCLASS64
442  Data:  ELFDATA2LSB
443  Type:  ET_EXEC
444  SectionHeaderStringTable: '.debug_str (1)'
445DWARF:
446  debug_str:
447    - string
448