1## Test how we create SHT_GNU_verdef sections. 2 3## Check that we link the SHT_GNU_verdef section to 4## the `.dynstr` section by default. 5## Check that we set the value of `sh_info` field to the 6## number of version definitions by default. 7 8# RUN: yaml2obj --docnum=1 %s -o %t1 9# RUN: llvm-readobj -V %t1 | FileCheck %s 10# RUN: llvm-readelf --sections %t1 | \ 11# RUN: FileCheck %s -DLINK=3 -DINFO=4 --check-prefix=FIELDS 12 13# FIELDS: [Nr] Name Type {{.*}} Flg Lk Inf 14# FIELDS: [ 1] .gnu.version_d VERDEF {{.*}} A [[LINK]] [[INFO]] 15# FIELDS: [ 3] .dynstr 16 17# CHECK: VersionDefinitions [ 18# CHECK-NEXT: Definition { 19# CHECK-NEXT: Version: 1 20# CHECK-NEXT: Flags [ (0x0) 21# CHECK-NEXT: ] 22# CHECK-NEXT: Index: 0 23# CHECK-NEXT: Hash: 0 24# CHECK-NEXT: Name: 25# CHECK-NEXT: Predecessors: [] 26# CHECK-NEXT: } 27# CHECK-NEXT: Definition { 28# CHECK-NEXT: Version: 1 29# CHECK-NEXT: Flags [ (0x1) 30# CHECK-NEXT: Base (0x1) 31# CHECK-NEXT: ] 32# CHECK-NEXT: Index: 1 33# CHECK-NEXT: Hash: 170240160 34# CHECK-NEXT: Name: dso.so.0 35# CHECK-NEXT: Predecessors: [] 36# CHECK-NEXT: } 37# CHECK-NEXT: Definition { 38# CHECK-NEXT: Version: 1 39# CHECK-NEXT: Flags [ (0x2) 40# CHECK-NEXT: Weak (0x2) 41# CHECK-NEXT: ] 42# CHECK-NEXT: Index: 2 43# CHECK-NEXT: Hash: 108387921 44# CHECK-NEXT: Name: VERSION_1 45# CHECK-NEXT: Predecessors: [] 46# CHECK-NEXT: } 47# CHECK-NEXT: Definition { 48# CHECK-NEXT: Version: 1 49# CHECK-NEXT: Flags [ (0xFFFF) 50# CHECK-NEXT: Base (0x1) 51# CHECK-NEXT: Info (0x4) 52# CHECK-NEXT: Weak (0x2) 53# CHECK-NEXT: ] 54# CHECK-NEXT: Index: 3 55# CHECK-NEXT: Hash: 108387922 56# CHECK-NEXT: Name: VERSION_2 57# CHECK-NEXT: Predecessors: [VERSION_3, VERSION_4] 58# CHECK-NEXT: } 59# CHECK-NEXT: ] 60 61--- !ELF 62FileHeader: 63 Class: ELFCLASS64 64 Data: ELFDATA2LSB 65 Type: ET_DYN 66Sections: 67 - Name: .gnu.version_d 68 Type: SHT_GNU_verdef 69 Flags: [ SHF_ALLOC ] 70 Info: [[INFO=<none>]] 71 Link: [[LINK=<none>]] 72 Entries: 73## Case 1: an entry that has no Version, Flags, VersionNdx or Hash fields set. 74## Used to check values that are written by default. Also shows 75## that we are able to use the "=<none>" syntax for these fields. 76 - Version: [[VERSION=<none>]] 77 Flags: [[FLAGS=<none>]] 78 VersionNdx: [[VERNDX=<none>]] 79 Hash: [[HASH=<none>]] 80 Names: [] 81## Case 2: an arbitrary entry. 82 - Flags: 1 83 VersionNdx: 1 84 Hash: 170240160 85 Names: 86 - dso.so.0 87## Case 3: one more arbitrary entry with different values. 88 - Flags: 2 89 VersionNdx: 2 90 Hash: 108387921 91 Names: 92 - VERSION_1 93## Case 4: an entry that has version predecessors. Also, it sets 94## all known flags as well as few unknown. 95 - Flags: 0xffff 96 VersionNdx: 3 97 Hash: 108387922 98 Names: 99 - VERSION_2 100 - VERSION_3 101 - VERSION_4 102DynamicSymbols: 103 - Name: foo 104 Binding: STB_GLOBAL 105 106## Check that we are able to set sh_info and sh_link fields to arbitrary values. 107 108# RUN: yaml2obj --docnum=1 -DINFO=123 -DLINK=234 %s -o %t1.fields 109# RUN: llvm-readelf --sections %t1.fields | \ 110# RUN: FileCheck %s -DINFO=123 -DLINK=234 --check-prefix=FIELDS 111 112## Check we are able to emit a version definition which has a version revision 113## (vd_version) field value that is not equal to 1. 114 115# RUN: yaml2obj --docnum=1 -DVERSION=2 %s -o %t.version 116# RUN: llvm-readobj -V %t.version 2>&1 | FileCheck %s --check-prefix=VERSION-ERR 117 118# VERSION-ERR: unable to dump SHT_GNU_verdef section with index 1: version 2 is not yet supported 119 120## Check we can use "Content" to describe the content. 121## Check we set the sh_link field to 0 when there is no .dynstr section. 122 123# RUN: yaml2obj --docnum=2 %s -o %t2 124# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=CONTENT 125 126# CONTENT: Name: .gnu.version_d 127# CONTENT-NEXT: Type: SHT_GNU_verdef 128# CONTENT-NEXT: Flags [ (0x2) 129# CONTENT-NEXT: SHF_ALLOC (0x2) 130# CONTENT-NEXT: ] 131# CONTENT-NEXT: Address: 0x0 132# CONTENT-NEXT: Offset: 0x40 133# CONTENT-NEXT: Size: 3 134# CONTENT-NEXT: Link: 0 135# CONTENT-NEXT: Info: 0 136# CONTENT-NEXT: AddressAlignment: 137# CONTENT-NEXT: EntrySize: 138# CONTENT-NEXT: SectionData ( 139# CONTENT-NEXT: 0000: 112233 140# CONTENT-NEXT: ) 141 142--- !ELF 143FileHeader: 144 Class: ELFCLASS64 145 Data: ELFDATA2LSB 146 Type: ET_DYN 147Sections: 148 - Name: .gnu.version_d 149 Type: SHT_GNU_verdef 150 Flags: [ SHF_ALLOC ] 151 Content: "112233" 152 153## Check we can omit "Content" and "Entries" fields to produce an empty SHT_GNU_verdef section. 154 155# RUN: yaml2obj --docnum=3 %s -o %t3 156# RUN: llvm-readelf --sections %t3 | FileCheck %s --check-prefix=NO-PROPS 157 158# NO-PROPS: [Nr] Name Type Address Off Size ES Flg Lk Inf Al 159# NO-PROPS: [ 1] .gnu.version_d VERDEF 0000000000000000 000040 000000 00 A 0 0 0 160 161--- !ELF 162FileHeader: 163 Class: ELFCLASS64 164 Data: ELFDATA2LSB 165 Type: ET_DYN 166Sections: 167 - Name: .gnu.version_d 168 Type: SHT_GNU_verdef 169 Flags: [ SHF_ALLOC ] 170 171## Check we can use the "Content" key with the "Size" key when the size is greater 172## than or equal to the content size. 173 174# RUN: not yaml2obj --docnum=4 -DSIZE=1 -DCONTENT="'0011'" %s 2>&1 | \ 175# RUN: FileCheck %s --check-prefix=CONTENT-SIZE-ERR 176 177# CONTENT-SIZE-ERR: error: Section size must be greater than or equal to the content size 178 179--- !ELF 180FileHeader: 181 Class: ELFCLASS64 182 Data: ELFDATA2LSB 183 Type: ET_DYN 184Sections: 185 - Name: .gnu.version_d 186 Type: SHT_GNU_verdef 187 Size: [[SIZE=<none>]] 188 Content: [[CONTENT=<none>]] 189 Entries: [[ENTRIES=<none>]] 190 191# RUN: yaml2obj --docnum=4 -DSIZE=2 -DCONTENT="'0011'" %s -o %t.cont.size.eq.o 192# RUN: llvm-readobj --sections --section-data %t.cont.size.eq.o | \ 193# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="0011" 194 195# RUN: yaml2obj --docnum=4 -DSIZE=3 -DCONTENT="'0011'" %s -o %t.cont.size.gr.o 196# RUN: llvm-readobj --sections --section-data %t.cont.size.gr.o | \ 197# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="001100" 198 199# CHECK-CONTENT: Name: .gnu.version_d 200# CHECK-CONTENT: SectionData ( 201# CHECK-CONTENT-NEXT: 0000: [[DATA]] | 202# CHECK-CONTENT-NEXT: ) 203 204## Check we can use the "Size" key alone to create the section. 205 206# RUN: yaml2obj --docnum=4 -DSIZE=3 %s -o %t.size.o 207# RUN: llvm-readobj --sections --section-data %t.size.o | \ 208# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="000000" 209 210## Check we can use the "Content" key alone to create the section. 211 212# RUN: yaml2obj --docnum=4 -DCONTENT="'112233'" %s -o %t.content.o 213# RUN: llvm-readobj --sections --section-data %t.content.o | \ 214# RUN: FileCheck %s --check-prefix=CHECK-CONTENT -DDATA="112233" 215 216## Check we can't use the "Entries" key together with the "Content" or "Size" keys. 217 218# RUN: not yaml2obj --docnum=4 -DSIZE=0 -DENTRIES="[]" %s 2>&1 | \ 219# RUN: FileCheck %s --check-prefix=ENTRIES-ERR 220# RUN: not yaml2obj --docnum=4 -DCONTENT="'00'" -DENTRIES="[]" %s 2>&1 | \ 221# RUN: FileCheck %s --check-prefix=ENTRIES-ERR 222 223# ENTRIES-ERR: error: "Entries" cannot be used with "Content" or "Size" 224 225## Check we set the sh_link field to 0 when the .dynstr section is excluded 226## from the section header table. 227 228# RUN: yaml2obj --docnum=5 %s -o %t5 229# RUN: llvm-readelf --sections %t5 | FileCheck %s --check-prefix=EXCLUDED 230 231# EXCLUDED: [Nr] Name {{.*}} ES Flg Lk Inf 232# EXCLUDED: [ 1] .gnu.version_d {{.*}} 00 0 0 233 234--- !ELF 235FileHeader: 236 Class: ELFCLASS64 237 Data: ELFDATA2LSB 238 Type: ET_DYN 239Sections: 240 - Name: .gnu.version_d 241 Type: SHT_GNU_verdef 242 - Name: .dynstr 243 Type: SHT_STRTAB 244 - Type: SectionHeaderTable 245 Sections: 246 - Name: .gnu.version_d 247 - Name: .strtab 248 - Name: .shstrtab 249 Excluded: 250 - Name: .dynstr 251