1## Check how we produce implicit SHT_STRTAB sections. 2 3## For implicit string table sections, the `Flags` field can also 4## be specified in YAML. Here we test the behavior in different cases. 5 6## When flags are not explicitly specified, yaml2obj assigns no flags 7## for .strtab/.shstrtab and the SHF_ALLOC flag for .dynstr by default. 8 9# RUN: yaml2obj --docnum=1 %s -o %t1 10# RUN: llvm-readelf %t1 --sections | FileCheck %s --check-prefix=CASE1 11 12# CASE1: [Nr] Name Type {{.*}} Flg Lk 13# CASE1: [ 1] .strtab STRTAB {{.*}} 0 14# CASE1-NEXT: [ 2] .shstrtab STRTAB {{.*}} 0 15# CASE1-NEXT: [ 3] .dynstr STRTAB {{.*}} A 0 16 17--- !ELF 18FileHeader: 19 Class: ELFCLASS64 20 Data: ELFDATA2LSB 21 Type: ET_DYN 22Sections: 23 - Name: .strtab 24 Type: SHT_STRTAB 25 Flags: [[STRTABFLAGS=<none>]] 26 Offset: [[STRTABOFFSET=<none>]] 27 - Name: .shstrtab 28 Type: SHT_STRTAB 29 Flags: [[SHSTRTABFLAGS=<none>]] 30 Offset: [[SHSTRTABOFFSET=<none>]] 31 - Name: .dynstr 32 Type: SHT_STRTAB 33 Flags: [[DYNSTRFLAGS=<none>]] 34 Offset: [[DYNSTROFFSET=<none>]] 35 36## Check we can set arbitrary flags and offsets for 37## implicit string table sections. 38 39# RUN: yaml2obj --docnum=1 \ 40# RUN: -DSTRTABFLAGS="[ SHF_ALLOC, SHF_STRINGS ]" -DSTRTABOFFSET=0x100 \ 41# RUN: -DSHSTRTABFLAGS="[ SHF_ALLOC, SHF_WRITE ]" -DSHSTRTABOFFSET=0x200 \ 42# RUN: -DDYNSTRFLAGS="[ SHF_STRINGS ]" -DDYNSTROFFSET=0x300 %s -o %t2 43# RUN: llvm-readelf %t2 --sections | FileCheck %s --check-prefix=CASE2 44 45# CASE2: [Nr] Name Type Address Off {{.*}} Flg Lk 46# CASE2: [ 1] .strtab STRTAB 0000000000000000 000100 {{.*}} AS 0 47# CASE2-NEXT: [ 2] .shstrtab STRTAB 0000000000000001 000200 {{.*}} WA 0 48# CASE2-NEXT: [ 3] .dynstr STRTAB 0000000000000000 000300 {{.*}} S 0 49 50## Check no flags are set by default for implicit string table sections 51## when they are not described in the YAML. 52 53# RUN: yaml2obj --docnum=2 %s -o %t3 54# RUN: llvm-readelf %t3 --sections | FileCheck %s --check-prefix=CASE3 55 56# CASE3: [Nr] Name Type {{.*}} ES Flg Lk 57# CASE3: [ 1] .strtab STRTAB {{.*}} 00 0 58# CASE3-NEXT: [ 2] .shstrtab STRTAB {{.*}} 00 0 59 60--- !ELF 61FileHeader: 62 Class: ELFCLASS64 63 Data: ELFDATA2LSB 64 Type: ET_DYN 65 66## For implicit string table sections, `Size` and/or `Content` fields can also 67## be specified in YAML. Here we test the behavior in different cases. 68 69## When no `Size` or `Content` is specified for a string table section, 70## yaml2obj writes the default content. 71 72# RUN: yaml2obj --docnum=3 %s -o %t4 73# RUN: llvm-objdump %t4 -s | FileCheck %s --check-prefix=CASE4 74 75# CASE4: Contents of section .strtab: 76# CASE4-NEXT: 0000 00666f6f 00 .foo. 77# CASE4-NEXT: Contents of section .shstrtab: 78# CASE4-NEXT: 0000 002e6479 6e737472 002e6479 6e73796d ..dynstr..dynsym 79# CASE4-NEXT: 0010 002e7368 73747274 6162002e 73747274 ..shstrtab..strt 80# CASE4-NEXT: 0020 6162002e 73796d74 616200 ab..symtab. 81# CASE4-NEXT: Contents of section .dynstr: 82# CASE4-NEXT: 0030 00626172 00 .bar. 83 84--- !ELF 85FileHeader: 86 Class: ELFCLASS64 87 Data: ELFDATA2LSB 88 Type: ET_DYN 89Sections: 90 - Name: .strtab 91 Type: SHT_STRTAB 92 Size: [[STRTABSIZE=<none>]] 93 Content: [[STRTABCONTENT=<none>]] 94 - Name: .shstrtab 95 Type: SHT_STRTAB 96 Size: [[SHSTRTABSIZE=<none>]] 97 Content: [[SHSTRTABCONTENT=<none>]] 98 - Name: .dynstr 99 Type: SHT_STRTAB 100 Size: [[DYNSTRSIZE=<none>]] 101 Content: [[DYNSTRCONTENT=<none>]] 102## Used to trigger adding string `foo` to the string table section. 103Symbols: 104 - Name: foo 105DynamicSymbols: 106 - Name: bar 107 108## For string table sections, `Size` can be used to override the 109## implicit string table data. The content is filled with zeroes in this case. 110 111# RUN: yaml2obj --docnum=3 -DSTRTABSIZE=2 -DSHSTRTABSIZE=0x30 -DDYNSTRSIZE=4 %s -o %t5 112# RUN: llvm-readobj --section-data -S %t5 | FileCheck %s --check-prefix=CASE5 113 114# CASE5: Index: 1 115# CASE5-NEXT: Name: (27) 116# CASE5-NEXT: Type: SHT_STRTAB 117# CASE5: SectionData ( 118# CASE5-NEXT: 0000: 0000 | 119# CASE5-NEXT: ) 120# CASE5: Index: 2 121# CASE5-NEXT: Name: (17) 122# CASE5-NEXT: Type: SHT_STRTAB (0x3) 123# CASE5: SectionData ( 124# CASE5-NEXT: 0000: 00000000 00000000 00000000 00000000 | 125# CASE5-NEXT: 0010: 00000000 00000000 00000000 00000000 | 126# CASE5-NEXT: 0020: 00000000 00000000 00000000 00000000 | 127# CASE5-NEXT: ) 128# CASE5: Index: 3 129# CASE5-NEXT: Name: (1) 130# CASE5-NEXT: Type: SHT_STRTAB (0x3) 131# CASE5: SectionData ( 132# CASE5-NEXT: 0000: 00000000 | 133# CASE5-NEXT: ) 134 135## For string table sections, `Content` can be used to override the 136## implicit string table data. 137 138# RUN: yaml2obj --docnum=3 %s \ 139# RUN: -DSTRTABCONTENT="01020304" \ 140# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" \ 141# RUN: -DDYNSTRCONTENT="eeddaabb" -o %t6 142# RUN: llvm-readobj --section-data -S %t6 | FileCheck %s --check-prefix=CASE6 143 144# CASE6: Index: 1 145# CASE6-NEXT: Name: bcdefggi (27) 146# CASE6: SectionData ( 147# CASE6-NEXT: 0000: 01020304 | 148# CASE6-NEXT: ) 149# CASE6: Index: 2 150# CASE6-NEXT: Name: rstuvwxyzabcdefggi (17) 151# CASE6: SectionData ( 152# CASE6-NEXT: 0000: 61626364 65666767 696A6B6C 6D6E6F70 | 153# CASE6-NEXT: 0010: 71727374 75767778 797A6162 63646566 | 154# CASE6-NEXT: 0020: 67676900 | 155# CASE6-NEXT: ) 156# CASE6: Index: 3 157# CASE6-NEXT: Name: bcdefggijklmnopqrstuvwxyzabcdefggi (1) 158# CASE6: SectionData ( 159# CASE6-NEXT: 0000: EEDDAABB | 160# CASE6-NEXT: ) 161 162## For string table sections, check we can specify both `Size` and `Content` 163## when size is greater than content size. In this case zeroes are 164## added as padding after the specified content. 165 166# RUN: yaml2obj --docnum=3 %s \ 167# RUN: -DSTRTABCONTENT="01020304" -DSTRTABSIZE=5 \ 168# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" -DSHSTRTABSIZE=0x26 \ 169# RUN: -DDYNSTRCONTENT="eeddaabb" -DDYNSTRSIZE=7 -o %t7 170# RUN: llvm-readobj --section-data -S %t7 | FileCheck %s --check-prefix=CASE7 171 172# CASE7: Index: 1 173# CASE7-NEXT: Name: bcdefggi (27) 174# CASE7: SectionData ( 175# CASE7-NEXT: 0000: 01020304 00 | 176# CASE7-NEXT: ) 177# CASE7: Index: 2 178# CASE7-NEXT: Name: rstuvwxyzabcdefggi (17) 179# CASE7: SectionData ( 180# CASE7-NEXT: 0000: 61626364 65666767 696A6B6C 6D6E6F70 | 181# CASE7-NEXT: 0010: 71727374 75767778 797A6162 63646566 | 182# CASE7-NEXT: 0020: 67676900 0000 | 183# CASE7-NEXT: ) 184# CASE7: Index: 3 185# CASE7-NEXT: Name: bcdefggijklmnopqrstuvwxyzabcdefggi (1) 186# CASE7: SectionData ( 187# CASE7-NEXT: 0000: EEDDAABB 000000 | 188# CASE7-NEXT: ) 189 190## For string table sections, check we can specify both `Size` and `Content` 191## when size is equal to content size. 192 193# RUN: yaml2obj --docnum=3 %s \ 194# RUN: -DSTRTABCONTENT="01020304" -DSTRTABSIZE=4 \ 195# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" -DSHSTRTABSIZE=0x24 \ 196# RUN: -DDYNSTRCONTENT="eeddaabb" -DDYNSTRSIZE=4 -o %t8 197# RUN: llvm-readobj --section-data -S %t8 | FileCheck %s --check-prefix=CASE6 198 199## Check that we report an error when the the value of "Size" is less than the content size. 200 201# RUN: not yaml2obj --docnum=3 %s -DSTRTABCONTENT="01020304" -DSTRTABSIZE=3 2>&1 \ 202# RUN: | FileCheck %s --check-prefix=CASE8 203# RUN: not yaml2obj --docnum=3 %s \ 204# RUN: -DSHSTRTABCONTENT="6162636465666767696a6b6c6d6e6f707172737475767778797a61626364656667676900" -DSHSTRTABSIZE=0x23 2>&1 \ 205# RUN: | FileCheck %s --check-prefix=CASE8 206# RUN: not yaml2obj --docnum=3 %s -DDYNSTRCONTENT="eeddaabb" -DDYNSTRSIZE=0x3 2>&1 \ 207# RUN: | FileCheck %s --check-prefix=CASE8 208 209# CASE8: Section size must be greater than or equal to the content size 210