diff --git a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-flags.yaml b/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-flags.yaml deleted file mode 100644 --- a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-flags.yaml +++ /dev/null @@ -1,76 +0,0 @@ -## For implicit string table sections, the `Flags` field can also -## be specified in YAML. Here we test the behavior in different cases. - -## When flags are not explicitly specified, yaml2obj assigns no flags -## for .strtab and the SHF_ALLOC flag for .dynstr by default. - -# RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-readobj %t1 -S | FileCheck %s --check-prefix=CASE1 - -# CASE1: Name: .strtab -# CASE1-NEXT: Type: SHT_STRTAB -# CASE1-NEXT: Flags [ -# CASE1-NEXT: ] -# CASE1: Name: .dynstr -# CASE1-NEXT: Type: SHT_STRTAB -# CASE1-NEXT: Flags [ -# CASE1-NEXT: SHF_ALLOC -# CASE1-NEXT: ] - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB - - Name: .dynstr - Type: SHT_STRTAB - -## Check we can set arbitrary flags for .strtab/.dynstr. - -# RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: llvm-readobj %t2 -S | FileCheck %s --check-prefix=CASE2 - -# CASE2: Name: .strtab -# CASE2-NEXT: Type: SHT_STRTAB -# CASE2-NEXT: Flags [ -# CASE2-NEXT: SHF_ALLOC -# CASE2-NEXT: SHF_STRINGS -# CASE2-NEXT: ] -# CASE2: Name: .dynstr -# CASE2-NEXT: Type: SHT_STRTAB -# CASE2-NEXT: Flags [ -# CASE2-NEXT: SHF_STRINGS -# CASE2-NEXT: ] - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB - Flags: [ SHF_ALLOC, SHF_STRINGS ] - - Name: .dynstr - Type: SHT_STRTAB - Flags: [ SHF_STRINGS ] - -## Check no flags are set by default for .strtab when it is not -## described in the YAML. - -# RUN: yaml2obj --docnum=3 %s -o %t3 -# RUN: llvm-readobj %t3 -S | FileCheck %s --check-prefix=CASE3 - -# CASE3: Name: .strtab -# CASE3-NEXT: Type: SHT_STRTAB -# CASE3-NEXT: Flags [ -# CASE3-NEXT: ] - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN diff --git a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-size-content.yaml b/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-size-content.yaml deleted file mode 100644 --- a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-size-content.yaml +++ /dev/null @@ -1,162 +0,0 @@ -## For implicit string table sections, `Size` and/or `Content` fields can also -## be specified in YAML. Here we test the behavior in different cases. - -## When no `Size` or `Content` is specified for a string table section, -## yaml2obj writes the default content. - -# RUN: yaml2obj --docnum=1 %s -o %t1 -# RUN: llvm-objdump %t1 -s | FileCheck %s --check-prefix=CASE1 - -# CASE1: Contents of section .strtab: -# CASE1-NEXT: 0000 00666f6f 00 .foo. - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB -## Used to trigger adding string `foo` to the string table section. -Symbols: - - Name: foo - -## For string table sections, `Size` can be used to override the -## implicit string table data. The content is filled with zeroes in this case. - -# RUN: yaml2obj --docnum=2 %s -o %t2 -# RUN: llvm-readobj --section-data -S %t2 | FileCheck %s --check-prefix=CASE2 - -# CASE2: Name: .strtab -# CASE2-NEXT: Type: SHT_STRTAB -# CASE2-NEXT: Flags [ -# CASE2-NEXT: ] -# CASE2-NEXT: Address: 0x0 -# CASE2-NEXT: Offset: 0x40 -# CASE2-NEXT: Size: 2 -# CASE2-NEXT: Link: 0 -# CASE2-NEXT: Info: 0 -# CASE2-NEXT: AddressAlignment: 0 -# CASE2-NEXT: EntrySize: 0 -# CASE2-NEXT: SectionData ( -# CASE2-NEXT: 0000: 0000 -# CASE2-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB - Size: 2 -## Used to trigger adding string `foo` to the string table section. -Symbols: - - Name: foo - -## For string table sections, `Content` can be used to override the -## implicit string table data. - -# RUN: yaml2obj --docnum=3 %s -o %t3 -# RUN: llvm-readobj --section-data -S %t3 | FileCheck %s --check-prefix=CASE3 - -# CASE3: Name: .strtab -# CASE3-NEXT: Type: SHT_STRTAB -# CASE3-NEXT: Flags [ -# CASE3-NEXT: ] -# CASE3-NEXT: Address: 0x0 -# CASE3-NEXT: Offset: 0x40 -# CASE3-NEXT: Size: 2 -# CASE3-NEXT: Link: 0 -# CASE3-NEXT: Info: 0 -# CASE3-NEXT: AddressAlignment: 0 -# CASE3-NEXT: EntrySize: 0 -# CASE3-NEXT: SectionData ( -# CASE3-NEXT: 0000: 0102 -# CASE3-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB - Content: "0102" -## Used to trigger adding string `foo` to the string table section. -Symbols: - - Name: foo - -## For string table sections, check we can specify both `Size` and `Content` -## when size is greater than content size. In this case zeroes are -## added as padding after the specified content. - -# RUN: yaml2obj --docnum=4 %s -o %t4 -# RUN: llvm-readobj --section-data -S %t4 | FileCheck %s --check-prefix=CASE4 - -# CASE4: Name: .strtab -# CASE4-NEXT: Type: SHT_STRTAB -# CASE4-NEXT: Flags [ -# CASE4-NEXT: ] -# CASE4-NEXT: Address: 0x0 -# CASE4-NEXT: Offset: 0x40 -# CASE4-NEXT: Size: 3 -# CASE4-NEXT: Link: 0 -# CASE4-NEXT: Info: 0 -# CASE4-NEXT: AddressAlignment: 0 -# CASE4-NEXT: EntrySize: 0 -# CASE4-NEXT: SectionData ( -# CASE4-NEXT: 0000: 010200 -# CASE4-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB - Content: "0102" - Size: 3 -## Used to trigger adding string `foo` to the string table section. -Symbols: - - Name: foo - -## For string table sections, check we can specify both `Size` and `Content` -## when size is equal to content size. - -# RUN: yaml2obj --docnum=5 %s -o %t5 -# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5 - -# CASE5: Name: .strtab -# CASE5-NEXT: Type: SHT_STRTAB -# CASE5-NEXT: Flags [ (0x0) -# CASE5-NEXT: ] -# CASE5-NEXT: Address: 0x0 -# CASE5-NEXT: Offset: 0x40 -# CASE5-NEXT: Size: 2 -# CASE5-NEXT: Link: 0 -# CASE5-NEXT: Info: 0 -# CASE5-NEXT: AddressAlignment: 0 -# CASE5-NEXT: EntrySize: 0 -# CASE5-NEXT: SectionData ( -# CASE5-NEXT: 0000: 0102 -# CASE5-NEXT: ) - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_DYN -Sections: - - Name: .strtab - Type: SHT_STRTAB - Content: "0102" - Size: 2 -## Used to trigger adding string `foo` to the string table section. -Symbols: - - Name: foo diff --git a/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml b/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections.yaml @@ -0,0 +1,205 @@ +## Check how we produce implicit SHT_STRTAB sections. + +## For implicit string table sections, the `Flags` field can also +## be specified in YAML. Here we test the behavior in different cases. + +## When flags are not explicitly specified, yaml2obj assigns no flags +## for .strtab/.shstrtab and the SHF_ALLOC flag for .dynstr by default. + +# RUN: yaml2obj --docnum=1 %s -o %t1 +# RUN: llvm-readelf %t1 --sections | FileCheck %s --check-prefix=CASE1 + +# CASE1: [Nr] Name Type {{.*}} Flg Lk +# CASE1: [ 1] .strtab STRTAB {{.*}} 0 +# CASE1-NEXT: [ 2] .shstrtab STRTAB {{.*}} 0 +# CASE1-NEXT: [ 3] .dynstr STRTAB {{.*}} A 0 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .strtab + Type: SHT_STRTAB + Flags: [[STRTABFLAGS=]] + - Name: .shstrtab + Type: SHT_STRTAB + Flags: [[SHSTRTABFLAGS=]] + - Name: .dynstr + Type: SHT_STRTAB + Flags: [[DYNSTRFLAGS=]] + +## Check we can set arbitrary flags for .strtab/.dynstr. + +# RUN: yaml2obj --docnum=1 \ +# RUN: -DSTRTABFLAGS="[ SHF_ALLOC, SHF_STRINGS ]" \ +# RUN: -DSHSTRTABFLAGS="[ SHF_ALLOC, SHF_WRITE ]" \ +# RUN: -DDYNSTRFLAGS="[ SHF_STRINGS ]" %s -o %t2 +# RUN: llvm-readelf %t2 --sections | FileCheck %s --check-prefix=CASE2 + +# CASE2: [Nr] Name Type {{.*}} Flg Lk +# CASE2: [ 1] .strtab STRTAB {{.*}} AS 0 +# CASE2-NEXT: [ 2] .shstrtab STRTAB {{.*}} WA 0 +# CASE2-NEXT: [ 3] .dynstr STRTAB {{.*}} S 0 + +## Check no flags are set by default for implicit string table sections +## when they are not described in the YAML. + +# RUN: yaml2obj --docnum=2 %s -o %t3 +# RUN: llvm-readelf %t3 --sections | FileCheck %s --check-prefix=CASE3 + +# CASE3: [Nr] Name Type {{.*}} ES Flg Lk +# CASE3: [ 1] .strtab STRTAB {{.*}} 00 0 +# CASE3-NEXT: [ 2] .shstrtab STRTAB {{.*}} 00 0 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + +## For implicit string table sections, `Size` and/or `Content` fields can also +## be specified in YAML. Here we test the behavior in different cases. + +## When no `Size` or `Content` is specified for a string table section, +## yaml2obj writes the default content. + +# RUN: yaml2obj --docnum=3 %s -o %t4 +# RUN: llvm-objdump %t4 -s | FileCheck %s --check-prefix=CASE4 + +# CASE4: Contents of section .strtab: +# CASE4-NEXT: 0000 00666f6f 00 .foo. +# CASE4-NEXT: Contents of section .shstrtab: +# CASE4-NEXT: 0000 002e6479 6e737472 002e6479 6e73796d ..dynstr..dynsym +# CASE4-NEXT: 0010 002e7368 73747274 6162002e 73747274 ..shstrtab..strt +# CASE4-NEXT: 0020 6162002e 73796d74 616200 ab..symtab. +# CASE4-NEXT: Contents of section .dynstr: +# CASE4-NEXT: 0030 00626172 00 .bar. + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN +Sections: + - Name: .strtab + Type: SHT_STRTAB + Size: [[STRTABSIZE=]] + Content: [[STRTABCONTENT=]] + - Name: .shstrtab + Type: SHT_STRTAB + Size: [[SHSTRTABSIZE=]] + Content: [[SHSTRTABCONTENT=]] + - Name: .dynstr + Type: SHT_STRTAB + Size: [[DYNSTRSIZE=]] + Content: [[DYNSTRCONTENT=]] +## Used to trigger adding string `foo` to the string table section. +Symbols: + - Name: foo +DynamicSymbols: + - Name: bar + +## For string table sections, `Size` can be used to override the +## implicit string table data. The content is filled with zeroes in this case. + +# RUN: yaml2obj --docnum=3 -DSTRTABSIZE=2 -DSHSTRTABSIZE=0x30 -DDYNSTRSIZE=4 %s -o %t5 +# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5 + +# CASE5: Index: 1 +# CASE5-NEXT: Name: (27) +# CASE5-NEXT: Type: SHT_STRTAB +# CASE5: SectionData ( +# CASE5-NEXT: 0000: 0000 | +# CASE5-NEXT: ) +# CASE5: Index: 2 +# CASE5-NEXT: Name: (17) +# CASE5-NEXT: Type: SHT_STRTAB (0x3) +# CASE5: SectionData ( +# CASE5-NEXT: 0000: 00000000 00000000 00000000 00000000 | +# CASE5-NEXT: 0010: 00000000 00000000 00000000 00000000 | +# CASE5-NEXT: 0020: 00000000 00000000 00000000 00000000 | +# CASE5-NEXT: ) +# CASE5: Index: 3 +# CASE5-NEXT: Name: (1) +# CASE5-NEXT: Type: SHT_STRTAB (0x3) +# CASE5: SectionData ( +# CASE5-NEXT: 0000: 00000000 | +# CASE5-NEXT: ) + +## For string table sections, `Content` can be used to override the +## implicit string table data. + +# RUN: yaml2obj --docnum=3 %s \ +# RUN: -DSTRTABCONTENT="01020304" \ +# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" \ +# RUN: -DDYNSTRCONTENT="eeddaabb" -o %t6 +# RUN: llvm-readobj --section-data -S %t6 | FileCheck %s --check-prefix=CASE6 + +# CASE6: Index: 1 +# CASE6-NEXT: Name: bcdefggi (27) +# CASE6: SectionData ( +# CASE6-NEXT: 0000: 01020304 | +# CASE6-NEXT: ) +# CASE6: Index: 2 +# CASE6-NEXT: Name: rstuvwxyzabcdefggi (17) +# CASE6: SectionData ( +# CASE6-NEXT: 0000: 61626364 65666767 696A6B6C 6D6E6F70 | +# CASE6-NEXT: 0010: 71727374 75767778 797A6162 63646566 | +# CASE6-NEXT: 0020: 67676900 | +# CASE6-NEXT: ) +# CASE6: Index: 3 +# CASE6-NEXT: Name: bcdefggijklmnopqrstuvwxyzabcdefggi (1) +# CASE6: SectionData ( +# CASE6-NEXT: 0000: EEDDAABB | +# CASE6-NEXT: ) + +## For string table sections, check we can specify both `Size` and `Content` +## when size is greater than content size. In this case zeroes are +## added as padding after the specified content. + +# RUN: yaml2obj --docnum=3 %s \ +# RUN: -DSTRTABCONTENT="01020304" -DSTRTABSIZE=5 \ +# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" -DSHSTRTABSIZE=0x26 \ +# RUN: -DDYNSTRCONTENT="eeddaabb" -DDYNSTRSIZE=7 -o %t7 +# RUN: llvm-readobj --section-data -S %t7 | FileCheck %s --check-prefix=CASE7 + +# CASE7: Index: 1 +# CASE7-NEXT: Name: bcdefggi (27) +# CASE7: SectionData ( +# CASE7-NEXT: 0000: 01020304 00 | +# CASE7-NEXT: ) +# CASE7: Index: 2 +# CASE7-NEXT: Name: rstuvwxyzabcdefggi (17) +# CASE7: SectionData ( +# CASE7-NEXT: 0000: 61626364 65666767 696A6B6C 6D6E6F70 | +# CASE7-NEXT: 0010: 71727374 75767778 797A6162 63646566 | +# CASE7-NEXT: 0020: 67676900 0000 | +# CASE7-NEXT: ) +# CASE7: Index: 3 +# CASE7-NEXT: Name: bcdefggijklmnopqrstuvwxyzabcdefggi (1) +# CASE7: SectionData ( +# CASE7-NEXT: 0000: EEDDAABB 000000 | +# CASE7-NEXT: ) + +## For string table sections, check we can specify both `Size` and `Content` +## when size is equal to content size. + +# RUN: yaml2obj --docnum=3 %s \ +# RUN: -DSTRTABCONTENT="01020304" -DSTRTABSIZE=4 \ +# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" -DSHSTRTABSIZE=0x24 \ +# RUN: -DDYNSTRCONTENT="eeddaabb" -DDYNSTRSIZE=4 -o %t8 +# RUN: llvm-readobj --section-data -S %t8 | FileCheck %s --check-prefix=CASE6 + +## Check that we report an error when the the value of "Size" is less than the content size. + +# RUN: not yaml2obj --docnum=3 %s -DSTRTABCONTENT="01020304" -DSTRTABSIZE=3 2>&1 \ +# RUN: | FileCheck %s --check-prefix=CASE8 +# RUN: not yaml2obj --docnum=3 %s \ +# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" -DSHSTRTABSIZE=0x23 2>&1 \ +# RUN: | FileCheck %s --check-prefix=CASE8 +# RUN: not yaml2obj --docnum=3 %s -DDYNSTRCONTENT="eeddaabb" -DDYNSTRSIZE=0x3 2>&1 \ +# RUN: | FileCheck %s --check-prefix=CASE8 + +# CASE8: Section size must be greater than or equal to the content size