1 ## Check how we can use the "Excluded" key of the "SectionHeaderTable" tag to exclude
2 ## entries from the section header table.
4 ## Check we can use the "Excluded" key to omit a section from the section header table.
5 ## Check we do not include the name of the excluded section in the string table.
6 # RUN: yaml2obj %s -DINCLUDED=.foo -DEXCLUDED=.bar --docnum=1 -o %t1
7 # RUN: llvm-readelf --section-headers -p .shstrtab %t1 | \
8 # RUN: FileCheck %s -DSEC=.foo --check-prefixes=INCLUDE-SEC,INCLUDE-FOO
9 # RUN: yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.foo --docnum=1 -o %t2
10 # RUN: llvm-readelf --section-headers -p .shstrtab %t2 | \
11 # RUN: FileCheck %s -DSEC=.bar --check-prefixes=INCLUDE-SEC,INCLUDE-BAR
13 # INCLUDE-SEC: [Nr] Name
14 # INCLUDE-SEC: [ 1] [[SEC]]
15 # INCLUDE-SEC-NEXT: [ 2] .strtab
16 # INCLUDE-SEC-NEXT: [ 3] .shstrtab
18 # INCLUDE-SEC: String dump of section '.shstrtab':
19 # INCLUDE-FOO-NEXT: [ 1] .foo
20 # INCLUDE-BAR-NEXT: [ 1] .bar
21 # INCLUDE-SEC-NEXT: [ 6] .shstrtab
22 # INCLUDE-SEC-NEXT: [ 10] .strtab
23 # INCLUDE-SEC-NOT: {{.}}
35 - Type: SectionHeaderTable
43 ## Check we report an error when a section is in both the "Sections" and "Excluded" lists at the same time.
44 ## Also check that we report an error if a section is missing from the lists.
45 # RUN: not yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.strtab --docnum=1 -o /dev/null 2>&1 | \
46 # RUN: FileCheck %s --check-prefix=EXCLUDE-INCLUDED
48 # EXCLUDE-INCLUDED: error: repeated section name: '.strtab' in the section header description
49 # EXCLUDE-INCLUDED: error: section '.foo' should be present in the 'Sections' or 'Excluded' lists
51 ## Check we report an error when the `Excluded` key mentions an unknown section.
52 # RUN: not yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.unknown --docnum=1 -o /dev/null 2>&1 | \
53 # RUN: FileCheck %s --check-prefix=EXCLUDE-UNKNOWN
55 # EXCLUDE-UNKNOWN: error: section '.foo' should be present in the 'Sections' or 'Excluded' lists
56 # EXCLUDE-UNKNOWN: error: section header contains undefined section '.unknown'
58 ## Check we report an error when the `Excluded` key mentions a section more than once.
59 # RUN: not yaml2obj %s --docnum=2 -o /dev/null 2>&1 | FileCheck %s --check-prefix=EXCLUDE-TWICE
61 # EXCLUDE-TWICE: error: repeated section name: '.strtab' in the section header description
62 # EXCLUDE-TWICE: error: repeated section name: '.strtab' in the section header description
70 - Type: SectionHeaderTable
78 ## Check that we are able to exclude all sections, except the implicit
79 ## null section, with the use of the "Excluded" key.
81 ## Case A: the "Sections" key is present, but empty.
82 # RUN: yaml2obj %s --docnum=3 -o %t3
83 # RUN: llvm-readelf --section-headers %t3 | FileCheck %s --check-prefix=NO-SECTIONS
85 # NO-SECTIONS: There are 1 section headers, starting at offset 0x48:
86 # NO-SECTIONS: Section Headers:
87 # NO-SECTIONS-NEXT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
88 # NO-SECTIONS-NEXT: [ 0] <no-strings> NULL 0000000000000000 000000 000000 00 0 0 0
96 - Type: SectionHeaderTable
102 ## Case B: the "Sections" key is not present.
103 # RUN: yaml2obj %s --docnum=4 -o %t4
104 # RUN: llvm-readelf --section-headers %t4 | FileCheck %s --check-prefix=NO-SECTIONS
112 - Type: SectionHeaderTable
117 ## Check how we handle cases when a section is excluded, but its section index is needed.
118 ## The general rule is: when a section is explicitly linked with another section, which is
119 ## excluded, then we report an error. In the case when it is linked implicitly with an excluded
120 ## section, we use 0 as index value.
122 ## Case A: check we report an error when a regular section has a Link field which
123 ## points to an excluded section.
124 # RUN: not yaml2obj %s --docnum=5 -o /dev/null 2>&1 | \
125 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.foo -DTARGET=.bar
127 # LINK: error: unable to link '[[SEC]]' to excluded section '[[TARGET]]'
140 - Type: SectionHeaderTable
148 ## Case B.1: check we report an error when a symbol table section has a Link field which
149 ## points to an excluded section.
150 # RUN: not yaml2obj %s --docnum=6 -DNAME=.symtab -DTYPE=SHT_SYMTAB -o /dev/null 2>&1 | \
151 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.symtab -DTARGET=.foo
152 # RUN: not yaml2obj %s --docnum=6 -DNAME=.dynsym -DTYPE=SHT_DYNSYM -o /dev/null 2>&1 | \
153 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.dynsym -DTARGET=.foo
166 - Type: SectionHeaderTable
174 ## Case B.2: check we do not link .dynsym with .dynstr implicitly when the latter is excluded.
175 # RUN: yaml2obj %s --docnum=7 -o %t5
176 # RUN: llvm-readelf %t5 --section-headers | FileCheck %s --check-prefix=LINK-DYNSYM
178 # LINK-DYNSYM: [Nr] Name Type Address Off Size ES Flg Lk
179 # LINK-DYNSYM: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 0
191 - Type: SectionHeaderTable
199 ## Case B.3: check we do not link .symtab with .strtab implicitly when the latter is excluded.
200 # RUN: yaml2obj %s --docnum=8 -o %t6
201 # RUN: llvm-readelf %t6 --section-headers | FileCheck %s --check-prefix=LINK-SYMTAB
203 # LINK-SYMTAB: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
204 # LINK-SYMTAB: [ 1] .symtab SYMTAB 0000000000000000 000040 000018 18 0 1 0
216 - Type: SectionHeaderTable
223 ## Case C: check we report an error when a debug section has a Link field which
224 ## points to an excluded section.
225 # RUN: not yaml2obj %s --docnum=9 -o /dev/null 2>&1 | \
226 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.debug_unknown -DTARGET=.strtab
234 - Name: .debug_unknown
237 - Type: SectionHeaderTable
239 - Name: .debug_unknown
244 ## Case D.1: check we report an error when a relocatable section has an Info field which
245 ## points to an excluded section.
246 # RUN: not yaml2obj %s --docnum=10 -o /dev/null 2>&1 | \
247 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.rela -DTARGET=.strtab
259 - Type: SectionHeaderTable
266 ## Case D.2: check we report an error when the SHT_REL[A] section is linked
267 ## with an excluded section explicitly.
268 # RUN: not yaml2obj %s --docnum=11 -o /dev/null 2>&1 | \
269 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.rela -DTARGET=.symtab
283 - Type: SectionHeaderTable
291 ## Case E: check we report an error when a symbol references an excluded section.
292 # RUN: not yaml2obj %s --docnum=12 -o /dev/null 2>&1 | \
293 # RUN: FileCheck %s --check-prefix=SYMBOL-SECTION
295 # SYMBOL-SECTION: error: excluded section referenced: '.foo' by symbol 'foo'
305 - Type: SectionHeaderTable
317 ## Case F.1: check we report an error when a group section
318 ## contains an excluded section member.
319 # RUN: not yaml2obj %s --docnum=13 -o /dev/null 2>&1 | \
320 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.group -DTARGET=.strtab
331 - SectionOrType: .strtab
332 - Type: SectionHeaderTable
339 ## Case F.2: check we report an error when the group section is linked
340 ## to an excluded section explicitly.
341 # RUN: not yaml2obj %s --docnum=14 -o /dev/null 2>&1 | \
342 # RUN: FileCheck %s --check-prefix=LINK -DSEC=.group -DTARGET=.symtab
356 - Type: SectionHeaderTable
364 ## Case G: check we do not link SHT_LLVM_CALL_GRAPH_PROFILE/SHT_LLVM_ADDRSIG/SHT_GROUP/SHT_REL[A] sections
365 ## with .symtab implicitly when the latter is excluded.
366 # RUN: yaml2obj %s --docnum=15 -o %t7
367 # RUN: llvm-readelf %t7 --section-headers | FileCheck %s --check-prefix=LINK-IMPLICIT
369 # LINK-IMPLICIT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
370 # LINK-IMPLICIT: [ 1] .cgp LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 08 0 0 0
371 # LINK-IMPLICIT-NEXT: [ 2] .llvm_addrsig LLVM_ADDRSIG 0000000000000000 000040 000000 00 0 0 0
372 # LINK-IMPLICIT-NEXT: [ 3] .group GROUP 0000000000000000 000040 000000 04 0 0 0
373 # LINK-IMPLICIT-NEXT: [ 4] .rela RELA 0000000000000000 000040 000000 18 0 0 0
382 Type: SHT_LLVM_CALL_GRAPH_PROFILE
384 - Name: .llvm_addrsig
385 Type: SHT_LLVM_ADDRSIG
395 - Type: SectionHeaderTable
398 - Name: .llvm_addrsig
406 ## Case H: check we do not link SHT_HASH/SHT_GNU_HASH sections with .dynsym
407 ## implicitly when the latter is excluded.
408 # RUN: yaml2obj %s --docnum=16 -o %t8
409 # RUN: llvm-readelf %t8 --section-headers | FileCheck %s --check-prefix=LINK-HASH
411 # LINK-HASH: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
412 # LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 04 0 0 0
413 # LINK-HASH-NEXT: [ 2] .gnu_hash GNU_HASH 0000000000000000 000040 000000 00 0 0 0
429 - Type: SectionHeaderTable
438 ## Case I: document the case when an excluded section is explicitly linked to another excluded section.
439 ## We report an error in this case, because:
440 ## 1) It is a reasonable behavior, as it is perhaps usually a result of a mistake
441 ## in a YAML description.
442 ## 2) Helps to keep the code simpler.
443 # RUN: not yaml2obj %s --docnum=17 -o /dev/null 2>&1 | FileCheck %s --check-prefix=CROSS-LINK
445 # CROSS-LINK: error: unable to link '.foo' to excluded section '.bar'
446 # CROSS-LINK-NEXT: error: unable to link '.bar' to excluded section '.foo'
460 - Type: SectionHeaderTable
468 ## Check we set e_shstrndx field to 0 when the section header string table is excluded.
469 ## Check that the e_shnum field is adjusted properly when a section is removed.
470 # RUN: yaml2obj --docnum=18 %s -o %t9
471 # RUN: llvm-readelf --file-headers %t9 | FileCheck %s --check-prefix=SHSTRTAB
473 # SHSTRTAB: Number of section headers: 2
474 # SHSTRTAB: Section header string table index: 0
482 - Type: SectionHeaderTable
488 ## Check we do not allow using "Excluded" together with "NoHeaders".
489 # RUN: not yaml2obj %s --docnum=19 -DNOHEADERS=true -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOHEADERS
490 # RUN: not yaml2obj %s --docnum=19 -DNOHEADERS=false -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOHEADERS
491 # NOHEADERS: NoHeaders can't be used together with Offset/Sections/Excluded
499 - Type: SectionHeaderTable
500 NoHeaders: [[NOHEADERS]]