502 lines · yaml
1## Check how we can use the "Excluded" key of the "SectionHeaderTable" tag to exclude2## entries from the section header table.3 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 %t17# RUN: llvm-readelf --section-headers -p .shstrtab %t1 | \8# RUN: FileCheck %s -DSEC=.foo --check-prefixes=INCLUDE-SEC,INCLUDE-FOO9# RUN: yaml2obj %s -DINCLUDED=.bar -DEXCLUDED=.foo --docnum=1 -o %t210# RUN: llvm-readelf --section-headers -p .shstrtab %t2 | \11# RUN: FileCheck %s -DSEC=.bar --check-prefixes=INCLUDE-SEC,INCLUDE-BAR12 13# INCLUDE-SEC: [Nr] Name14# INCLUDE-SEC: [ 1] [[SEC]]15# INCLUDE-SEC-NEXT: [ 2] .strtab16# INCLUDE-SEC-NEXT: [ 3] .shstrtab17 18# INCLUDE-SEC: String dump of section '.shstrtab':19# INCLUDE-FOO-NEXT: [ 1] .foo20# INCLUDE-BAR-NEXT: [ 1] .bar21# INCLUDE-SEC-NEXT: [ 6] .shstrtab22# INCLUDE-SEC-NEXT: [ 10] .strtab23# INCLUDE-SEC-NOT: {{.}}24 25--- !ELF26FileHeader:27 Class: ELFCLASS6428 Data: ELFDATA2LSB29 Type: ET_REL30Sections:31 - Name: .foo32 Type: SHT_PROGBITS33 - Name: .bar34 Type: SHT_PROGBITS35 - Type: SectionHeaderTable36 Sections:37 - Name: [[INCLUDED]]38 - Name: .strtab39 - Name: .shstrtab40 Excluded:41 - Name: [[EXCLUDED]]42 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-INCLUDED47 48# EXCLUDE-INCLUDED: error: repeated section name: '.strtab' in the section header description49# EXCLUDE-INCLUDED: error: section '.foo' should be present in the 'Sections' or 'Excluded' lists50 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-UNKNOWN54 55# EXCLUDE-UNKNOWN: error: section '.foo' should be present in the 'Sections' or 'Excluded' lists56# EXCLUDE-UNKNOWN: error: section header contains undefined section '.unknown'57 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-TWICE60 61# EXCLUDE-TWICE: error: repeated section name: '.strtab' in the section header description62# EXCLUDE-TWICE: error: repeated section name: '.strtab' in the section header description63 64--- !ELF65FileHeader:66 Class: ELFCLASS6467 Data: ELFDATA2LSB68 Type: ET_REL69Sections:70 - Type: SectionHeaderTable71 Sections:72 - Name: .strtab73 - Name: .shstrtab74 Excluded:75 - Name: .strtab76 - Name: .strtab77 78## Check that we are able to exclude all sections, except the implicit79## null section, with the use of the "Excluded" key.80 81## Case A: the "Sections" key is present, but empty.82# RUN: yaml2obj %s --docnum=3 -o %t383# RUN: llvm-readelf --section-headers %t3 | FileCheck %s --check-prefix=NO-SECTIONS84 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 Al88# NO-SECTIONS-NEXT: [ 0] <no-strings> NULL 0000000000000000 000000 000000 00 0 0 089 90--- !ELF91FileHeader:92 Class: ELFCLASS6493 Data: ELFDATA2LSB94 Type: ET_REL95Sections:96 - Type: SectionHeaderTable97 Sections: []98 Excluded:99 - Name: .strtab100 - Name: .shstrtab101 102## Case B: the "Sections" key is not present.103# RUN: yaml2obj %s --docnum=4 -o %t4104# RUN: llvm-readelf --section-headers %t4 | FileCheck %s --check-prefix=NO-SECTIONS105 106--- !ELF107FileHeader:108 Class: ELFCLASS64109 Data: ELFDATA2LSB110 Type: ET_REL111Sections:112 - Type: SectionHeaderTable113 Excluded:114 - Name: .strtab115 - Name: .shstrtab116 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 is119## excluded, then we report an error. In the case when it is linked implicitly with an excluded120## section, we use 0 as index value.121 122## Case A: check we report an error when a regular section has a Link field which123## 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=.bar126 127# LINK: error: unable to link '[[SEC]]' to excluded section '[[TARGET]]'128 129--- !ELF130FileHeader:131 Class: ELFCLASS64132 Data: ELFDATA2LSB133 Type: ET_REL134Sections:135 - Name: .foo136 Type: SHT_PROGBITS137 Link: .bar138 - Name: .bar139 Type: SHT_PROGBITS140 - Type: SectionHeaderTable141 Sections:142 - Name: .foo143 - Name: .strtab144 - Name: .shstrtab145 Excluded:146 - Name: .bar147 148## Case B.1: check we report an error when a symbol table section has a Link field which149## 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=.foo152# 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=.foo154 155--- !ELF156FileHeader:157 Class: ELFCLASS64158 Data: ELFDATA2LSB159 Type: ET_DYN160Sections:161 - Name: [[NAME]]162 Type: [[TYPE]]163 Link: .foo164 - Name: .foo165 Type: SHT_PROGBITS166 - Type: SectionHeaderTable167 Sections:168 - Name: [[NAME]]169 - Name: .strtab170 - Name: .shstrtab171 Excluded:172 - Name: .foo173 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 %t5176# RUN: llvm-readelf %t5 --section-headers | FileCheck %s --check-prefix=LINK-DYNSYM177 178# LINK-DYNSYM: [Nr] Name Type Address Off Size ES Flg Lk179# LINK-DYNSYM: [ 1] .dynsym DYNSYM 0000000000000000 000040 000018 18 A 0180 181--- !ELF182FileHeader:183 Class: ELFCLASS64184 Data: ELFDATA2LSB185 Type: ET_DYN186Sections:187 - Name: .dynsym188 Type: SHT_DYNSYM189 - Name: .dynstr190 Type: SHT_PROGBITS191 - Type: SectionHeaderTable192 Sections:193 - Name: .dynsym194 - Name: .strtab195 - Name: .shstrtab196 Excluded:197 - Name: .dynstr198 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 %t6201# RUN: llvm-readelf %t6 --section-headers | FileCheck %s --check-prefix=LINK-SYMTAB202 203# LINK-SYMTAB: [Nr] Name Type Address Off Size ES Flg Lk Inf Al204# LINK-SYMTAB: [ 1] .symtab SYMTAB 0000000000000000 000040 000018 18 0 1 0205 206--- !ELF207FileHeader:208 Class: ELFCLASS64209 Data: ELFDATA2LSB210 Type: ET_DYN211Sections:212 - Name: .symtab213 Type: SHT_SYMTAB214 - Name: .strtab215 Type: SHT_PROGBITS216 - Type: SectionHeaderTable217 Sections:218 - Name: .symtab219 - Name: .shstrtab220 Excluded:221 - Name: .strtab222 223## Case C: check we report an error when a debug section has a Link field which224## 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=.strtab227 228--- !ELF229FileHeader:230 Class: ELFCLASS64231 Data: ELFDATA2LSB232 Type: ET_EXEC233Sections:234 - Name: .debug_unknown235 Type: SHT_PROGBITS236 Link: .strtab237 - Type: SectionHeaderTable238 Sections:239 - Name: .debug_unknown240 - Name: .shstrtab241 Excluded:242 - Name: .strtab243 244## Case D.1: check we report an error when a relocatable section has an Info field which245## 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=.strtab248 249--- !ELF250FileHeader:251 Class: ELFCLASS64252 Data: ELFDATA2LSB253 Type: ET_DYN254Sections:255 - Name: .rela256 Type: SHT_RELA257 Info: .strtab258 Relocations: []259 - Type: SectionHeaderTable260 Sections:261 - Name: .rela262 - Name: .shstrtab263 Excluded:264 - Name: .strtab265 266## Case D.2: check we report an error when the SHT_REL[A] section is linked267## 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=.symtab270 271--- !ELF272FileHeader:273 Class: ELFCLASS64274 Data: ELFDATA2LSB275 Type: ET_DYN276Sections:277 - Name: .rela278 Type: SHT_RELA279 Link: .symtab280 Relocations: []281 - Name: .symtab282 Type: SHT_PROGBITS283 - Type: SectionHeaderTable284 Sections:285 - Name: .rela286 - Name: .strtab287 - Name: .shstrtab288 Excluded:289 - Name: .symtab290 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-SECTION294 295# SYMBOL-SECTION: error: excluded section referenced: '.foo' by symbol 'foo'296 297--- !ELF298FileHeader:299 Class: ELFCLASS64300 Data: ELFDATA2LSB301 Type: ET_DYN302Sections:303 - Name: .foo304 Type: SHT_PROGBITS305 - Type: SectionHeaderTable306 Sections:307 - Name: .symtab308 - Name: .strtab309 - Name: .shstrtab310 Excluded:311 - Name: .foo312Symbols:313 - Name: foo314 Type: STT_OBJECT315 Section: .foo316 317## Case F.1: check we report an error when a group section318## 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=.strtab321 322--- !ELF323FileHeader:324 Class: ELFCLASS64325 Data: ELFDATA2LSB326 Type: ET_REL327Sections:328 - Name: .group329 Type: SHT_GROUP330 Members:331 - SectionOrType: .strtab332 - Type: SectionHeaderTable333 Sections:334 - Name: .group335 - Name: .shstrtab336 Excluded:337 - Name: .strtab338 339## Case F.2: check we report an error when the group section is linked340## 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=.symtab343 344--- !ELF345FileHeader:346 Class: ELFCLASS64347 Data: ELFDATA2LSB348 Type: ET_REL349Sections:350 - Name: .group351 Type: SHT_GROUP352 Link: .symtab353 Members: []354 - Name: .symtab355 Type: SHT_SYMTAB356 - Type: SectionHeaderTable357 Sections:358 - Name: .group359 - Name: .strtab360 - Name: .shstrtab361 Excluded:362 - Name: .symtab363 364## Case G: check we do not link SHT_LLVM_CALL_GRAPH_PROFILE/SHT_LLVM_ADDRSIG/SHT_GROUP/SHT_REL[A] sections365## with .symtab implicitly when the latter is excluded.366# RUN: yaml2obj %s --docnum=15 -o %t7367# RUN: llvm-readelf %t7 --section-headers | FileCheck %s --check-prefix=LINK-IMPLICIT368 369# LINK-IMPLICIT: [Nr] Name Type Address Off Size ES Flg Lk Inf Al370# LINK-IMPLICIT: [ 1] .cgp LLVM_CALL_GRAPH_PROFILE 0000000000000000 000040 000000 08 0 0 0371# LINK-IMPLICIT-NEXT: [ 2] .llvm_addrsig LLVM_ADDRSIG 0000000000000000 000040 000000 00 0 0 0372# LINK-IMPLICIT-NEXT: [ 3] .group GROUP 0000000000000000 000040 000000 04 0 0 0373# LINK-IMPLICIT-NEXT: [ 4] .rela RELA 0000000000000000 000040 000000 18 0 0 0374 375--- !ELF376FileHeader:377 Class: ELFCLASS64378 Data: ELFDATA2LSB379 Type: ET_DYN380Sections:381 - Name: .cgp382 Type: SHT_LLVM_CALL_GRAPH_PROFILE383 Content: ""384 - Name: .llvm_addrsig385 Type: SHT_LLVM_ADDRSIG386 Content: ""387 - Name: .group388 Type: SHT_GROUP389 Members: []390 - Name: .rela391 Type: SHT_RELA392 Relocations: []393 - Name: .symtab394 Type: SHT_SYMTAB395 - Type: SectionHeaderTable396 Sections:397 - Name: .cgp398 - Name: .llvm_addrsig399 - Name: .group400 - Name: .rela401 - Name: .strtab402 - Name: .shstrtab403 Excluded:404 - Name: .symtab405 406## Case H: check we do not link SHT_HASH/SHT_GNU_HASH sections with .dynsym407## implicitly when the latter is excluded.408# RUN: yaml2obj %s --docnum=16 -o %t8409# RUN: llvm-readelf %t8 --section-headers | FileCheck %s --check-prefix=LINK-HASH410 411# LINK-HASH: [Nr] Name Type Address Off Size ES Flg Lk Inf Al412# LINK-HASH: [ 1] .hash HASH 0000000000000000 000040 000000 04 0 0 0413# LINK-HASH-NEXT: [ 2] .gnu_hash GNU_HASH 0000000000000000 000040 000000 00 0 0 0414 415--- !ELF416FileHeader:417 Class: ELFCLASS64418 Data: ELFDATA2LSB419 Type: ET_DYN420Sections:421 - Name: .hash422 Type: SHT_HASH423 Content: ""424 - Name: .gnu_hash425 Type: SHT_GNU_HASH426 Content: ""427 - Name: .dynsym428 Type: SHT_DYNSYM429 - Type: SectionHeaderTable430 Sections:431 - Name: .hash432 - Name: .gnu_hash433 - Name: .strtab434 - Name: .shstrtab435 Excluded:436 - Name: .dynsym437 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 mistake441## 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-LINK444 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'447 448--- !ELF449FileHeader:450 Class: ELFCLASS64451 Data: ELFDATA2LSB452 Type: ET_REL453Sections:454 - Name: .foo455 Type: SHT_PROGBITS456 Link: .bar457 - Name: .bar458 Type: SHT_PROGBITS459 Link: .foo460 - Type: SectionHeaderTable461 Sections:462 - Name: .strtab463 - Name: .shstrtab464 Excluded:465 - Name: .foo466 - Name: .bar467 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 %t9471# RUN: llvm-readelf --file-headers %t9 | FileCheck %s --check-prefix=SHSTRTAB472 473# SHSTRTAB: Number of section headers: 2474# SHSTRTAB: Section header string table index: 0475 476--- !ELF477FileHeader:478 Class: ELFCLASS64479 Data: ELFDATA2LSB480 Type: ET_REL481Sections:482 - Type: SectionHeaderTable483 Sections:484 - Name: .strtab485 Excluded:486 - Name: .shstrtab487 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=NOHEADERS490# RUN: not yaml2obj %s --docnum=19 -DNOHEADERS=false -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOHEADERS491# NOHEADERS: NoHeaders can't be used together with Offset/Sections/Excluded492 493--- !ELF494FileHeader:495 Class: ELFCLASS64496 Data: ELFDATA2LSB497 Type: ET_REL498Sections:499 - Type: SectionHeaderTable500 NoHeaders: [[NOHEADERS]]501 Excluded: []502