1## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_verdef sections. 2 3## Check that we report a warning when sh_link references a non-existent section. 4 5# RUN: yaml2obj %s --docnum=1 -DLINK=0xFF -o %t1 6# RUN: llvm-readobj -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-LLVM --implicit-check-not="warning:" -DFILE=%t1 7# RUN: llvm-readelf -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-GNU --implicit-check-not="warning:" -DFILE=%t1 8 9# INVALID-LINK-LLVM: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 255 10 11# INVALID-LINK-GNU: Version definition section '.gnu.version_d' contains 0 entries: 12# INVALID-LINK-GNU: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 255 13# INVALID-LINK-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 255 (<corrupt>) 14 15--- !ELF 16FileHeader: 17 Class: ELFCLASS64 18 Data: ELFDATA2LSB 19 Type: ET_DYN 20Sections: 21 - Name: .gnu.version_d 22 Type: SHT_GNU_verdef 23 Link: [[LINK]] 24 Entries: [] 25 26## Check that we report a warning when the sh_link field of a SHT_GNU_verdef section references a non-string table section. 27 28# RUN: yaml2obj %s --docnum=1 -DLINK=0x0 -o %t2 29# RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t2 30# RUN: llvm-readelf -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t2 31 32# INVALID-STRING-TABLE: warning: '[[FILE]]': invalid string table linked to SHT_GNU_verdef section with index 1: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL 33 34## Check that we report a warning when we can't read the content of the SHT_GNU_verdef section. 35 36# RUN: yaml2obj %s --docnum=2 -DSHOFFSET=0xFFFFFFFF -o %t3 37# RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3 38# RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3 39 40# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verdef section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that is greater than the file size (0x230) 41 42--- !ELF 43FileHeader: 44 Class: ELFCLASS64 45 Data: ELFDATA2LSB 46 Type: ET_DYN 47Sections: 48 - Name: .gnu.version_d 49 Type: SHT_GNU_verdef 50 Entries: [] 51 ShOffset: [[SHOFFSET=<none>]] 52 ShName: [[SHNAME=<none>]] 53 - Name: .dynstr 54 Type: SHT_STRTAB 55 ShName: [[DYNSTRNAME=<none>]] 56DynamicSymbols: 57 - Name: foo 58 59## Check that llvm-readelf reports a warning when the name of the SHT_GNU_verdef section can't be read. 60 61# RUN: yaml2obj %s --docnum=2 -DSHNAME=0xFF -o %t.invalid.name 62# RUN: llvm-readobj -V %t.invalid.name 2>&1 | \ 63# RUN: FileCheck %s --check-prefix=INVALID-NAME-LLVM -DFILE=%t.invalid.name --implicit-check-not=warning: 64# RUN: llvm-readelf -V %t.invalid.name 2>&1 | \ 65# RUN: FileCheck %s --check-prefix=INVALID-NAME-GNU -DFILE=%t.invalid.name --implicit-check-not=warning: 66 67# INVALID-NAME-LLVM: VersionDefinitions [ 68# INVALID-NAME-LLVM-NEXT: ] 69 70# INVALID-NAME-GNU: warning: '[[FILE]]': unable to get the name of SHT_GNU_verdef section with index 1: a section [index 1] has an invalid sh_name (0xff) offset which goes past the end of the section name string table 71# INVALID-NAME-GNU-NEXT: Version definition section '<?>' contains 0 entries: 72# INVALID-NAME-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynstr) 73 74## Check that llvm-readelf reports a warning when we are unable to read the name of 75## the section linked with the SHT_GNU_verdef section (usually ".dynstr"). 76 77# RUN: yaml2obj %s --docnum=2 -DDYNSTRNAME=0xFF -o %t.invalid.name2 78# RUN: llvm-readobj -V %t.invalid.name2 2>&1 | \ 79# RUN: FileCheck %s --check-prefix=INVALID-NAME-LLVM -DFILE=%t.invalid.name2 --implicit-check-not=warning: 80# RUN: llvm-readelf -V %t.invalid.name2 2>&1 | \ 81# RUN: FileCheck %s --check-prefix=INVALID-NAME2-GNU -DFILE=%t.invalid.name2 --implicit-check-not=warning: 82 83# INVALID-NAME2-GNU: Version definition section '.gnu.version_d' contains 0 entries: 84# INVALID-NAME2-GNU-NEXT: warning: '[[FILE]]': unable to get the name of SHT_STRTAB section with index 2: a section [index 2] has an invalid sh_name (0xff) offset which goes past the end of the section name string table 85# INVALID-NAME2-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (<?>) 86 87## Check that we report a warning when a SHT_GNU_verdef section contains a version definition 88## that goes past the end of the section. 89 90# RUN: yaml2obj %s --docnum=3 -o %t4 91# RUN: llvm-readobj -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t4 92# RUN: llvm-readelf -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t4 93 94# DEF-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 goes past the end of the section 95 96--- !ELF 97FileHeader: 98 Class: ELFCLASS64 99 Data: ELFDATA2LSB 100 Type: ET_DYN 101Sections: 102 - Name: .gnu.version_d 103 Type: SHT_GNU_verdef 104 Entries: 105 - Names: 106 - FOO 107 ShSize: 1 108DynamicSymbols: 109 - Name: foo 110 111## Check that we report a warning when a SHT_GNU_verdef section contains a version definition 112## that refers to an auxiliary entry that goes past the end of the section. 113 114# RUN: yaml2obj %s --docnum=4 -o %t5 115# RUN: llvm-readobj -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5 116# RUN: llvm-readelf -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5 117 118# AUX-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 refers to an auxiliary entry that goes past the end of the section 119 120--- !ELF 121FileHeader: 122 Class: ELFCLASS64 123 Data: ELFDATA2LSB 124 Type: ET_DYN 125Sections: 126 - Name: .gnu.version_d 127 Type: SHT_GNU_verdef 128 Entries: 129 - Names: 130 - FOO 131 ShSize: 21 132DynamicSymbols: 133 - Name: foo 134 135## Check that we can dump a SHT_GNU_verdef section properly even if it contains version names strings 136## that overrun the linked string table. 137 138# RUN: yaml2obj %s --docnum=5 -o %t6 139# RUN: llvm-readobj -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-LLVM --implicit-check-not="warning:" -DFILE=%t6 140# RUN: llvm-readelf -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-GNU --implicit-check-not="warning:" -DFILE=%t6 141 142# PAST-STRTAB-END-LLVM: VersionDefinitions [ 143# PAST-STRTAB-END-LLVM-NEXT: Definition { 144# PAST-STRTAB-END-LLVM-NEXT: Version: 1 145# PAST-STRTAB-END-LLVM-NEXT: Flags [ (0x0) 146# PAST-STRTAB-END-LLVM-NEXT: ] 147# PAST-STRTAB-END-LLVM-NEXT: Index: 0 148# PAST-STRTAB-END-LLVM-NEXT: Hash: 0 149# PAST-STRTAB-END-LLVM-NEXT: Name: <invalid vda_name: 5> 150# PAST-STRTAB-END-LLVM-NEXT: Predecessors: [] 151# PAST-STRTAB-END-LLVM-NEXT: } 152# PAST-STRTAB-END-LLVM-NEXT: ] 153 154# PAST-STRTAB-END-GNU: Version definition section '.gnu.version_d' contains 1 entries: 155# PAST-STRTAB-END-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.strtab) 156# PAST-STRTAB-END-GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 0 Cnt: 1 Name: <invalid vda_name: 5> 157 158--- !ELF 159FileHeader: 160 Class: ELFCLASS64 161 Data: ELFDATA2LSB 162 Type: ET_DYN 163Sections: 164 - Name: .gnu.version_d 165 Type: SHT_GNU_verdef 166 Link: .strtab 167 Entries: 168 - Names: 169 - FOO 170 - Name: .strtab 171 Type: SHT_STRTAB 172DynamicSymbols: 173 - Name: BAR 174 175## Check we report a warning when a version definition is not correctly aligned in memory. 176 177# RUN: yaml2obj %s --docnum=6 -o %t7 178# RUN: llvm-readobj -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7 179# RUN: llvm-readelf -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7 180 181# MISALIGNED-DEF: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned version definition entry at offset 0x0 182 183--- !ELF 184FileHeader: 185 Class: ELFCLASS64 186 Data: ELFDATA2LSB 187 Type: ET_DYN 188Sections: 189 - Type: Fill 190 Size: 0x1 191 - Name: .gnu.version_d 192 Type: SHT_GNU_verdef 193 Link: .dynstr 194 Info: 0x1 195 Entries: 196 - Names: 197 - FOO 198DynamicSymbols: 199 - Name: foo 200 201## Check we report a warning when an auxiliary entry is not correctly aligned in memory. 202 203# RUN: yaml2obj %s --docnum=7 -o %t8 204# RUN: llvm-readobj -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8 205# RUN: llvm-readelf -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8 206 207# MISALIGNED-AUX: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned auxiliary entry at offset 0x13 208 209--- !ELF 210FileHeader: 211 Class: ELFCLASS64 212 Data: ELFDATA2LSB 213 Type: ET_DYN 214Sections: 215 - Name: .gnu.version_d 216 Type: SHT_GNU_verdef 217 Flags: [ SHF_ALLOC ] 218 Link: .dynstr 219 Info: 0x1 220## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory. 221 Content: "0100000000000100000000001300000000000000" 222DynamicSymbols: 223 - Name: foo 224 Binding: STB_GLOBAL 225 226## Check how we handle a version definition entry with an unsupported version. 227 228# RUN: yaml2obj %s --docnum=8 -o %t9 229# RUN: llvm-readobj -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9 230# RUN: llvm-readelf -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9 231 232# UNSUPPORTED-VERSION: warning: '[[FILE]]': unable to dump SHT_GNU_verdef section with index 1: version 65278 is not yet supported 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 Link: .dynstr 243 Info: 0x1 244 Entries: 245 - Version: 0xfefe 246 Names: [] 247DynamicSymbols: 248 - Name: foo 249 250## Check we report a warning when trying to print version symbols, but SHT_GNU_verdef 251## is invalid due to any reason. 252 253# RUN: yaml2obj %s --docnum=9 -o %t10 254# RUN: llvm-readobj -V %t10 2>&1 | FileCheck %s --check-prefix=INVALID-VERDEF-LLVM -DFILE=%t10 255# RUN: llvm-readelf -V %t10 2>&1 | FileCheck %s --check-prefix=INVALID-VERDEF-GNU -DFILE=%t10 256 257# INVALID-VERDEF-LLVM: VersionSymbols [ 258# INVALID-VERDEF-LLVM-NEXT: Symbol { 259# INVALID-VERDEF-LLVM-NEXT: Version: 0 260# INVALID-VERDEF-LLVM-NEXT: Name: {{$}} 261# INVALID-VERDEF-LLVM-NEXT: } 262# INVALID-VERDEF-LLVM-NEXT: Symbol { 263# INVALID-VERDEF-LLVM-NEXT: Version: 2 264# INVALID-VERDEF-LLVM-NEXT: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section 265# INVALID-VERDEF-LLVM-NEXT: Name: foo@<corrupt> 266 267# INVALID-VERDEF-GNU: Version symbols section '.gnu.version' contains 2 entries: 268# INVALID-VERDEF-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym) 269# INVALID-VERDEF-GNU-NEXT: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section 270# INVALID-VERDEF-GNU-NEXT: 000: 0 (*local*) 2 (<corrupt>) 271 272--- !ELF 273FileHeader: 274 Class: ELFCLASS64 275 Data: ELFDATA2LSB 276 Type: ET_DYN 277Sections: 278 - Name: .gnu.version 279 Type: SHT_GNU_versym 280 Flags: [ SHF_ALLOC ] 281 AddressAlign: 0x0000000000000002 282 EntSize: 0x0000000000000002 283 Entries: [ 0, 2 ] 284 - Name: .gnu.version_d 285 Type: SHT_GNU_verdef 286 Flags: [ SHF_ALLOC ] 287 AddressAlign: 0x4 288 Info: 0x1 289 Entries: [] 290DynamicSymbols: 291 - Name: foo 292 Binding: STB_GLOBAL 293