1## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_versym sections. 2 3## Check that we report a warning when sh_link references a non-existent section. 4 5# RUN: yaml2obj --docnum=1 -DLINK=0xFF %s -o %t1 6# RUN: llvm-readelf -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=GNU-INVALID-LINK 7# RUN: llvm-readobj -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=LLVM-INVALID-LINK 8 9# GNU-INVALID-LINK: Version symbols section '.gnu.version' contains 1 entries: 10# GNU-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255 11# GNU-INVALID-LINK-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 255 (<corrupt>) 12 13# LLVM-INVALID-LINK: VersionSymbols [ 14# LLVM-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255 15# LLVM-INVALID-LINK-NEXT: ] 16 17--- !ELF 18FileHeader: 19 Class: ELFCLASS64 20 Data: ELFDATA2LSB 21 Type: ET_EXEC 22Sections: 23 - Name: .gnu.version 24 Type: SHT_GNU_versym 25 Link: [[LINK]] 26 Entries: [ 0 ] 27 28## Check that we report a warning when the sh_link field of a SHT_GNU_versym section does not reference 29## a dynamic symbol table section. 30 31# RUN: yaml2obj --docnum=1 -DLINK=0x0 %s -o %t2 32# RUN: llvm-readelf -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-GNU 33# RUN: llvm-readobj -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-LLVM 34 35# INVALID-SYMBOL-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries: 36# INVALID-SYMBOL-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 0 () 37# INVALID-SYMBOL-TABLE-GNU-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: expected SHT_DYNSYM, but got SHT_NULL 38# INVALID-SYMBOL-TABLE-GNU-NEXT: 000: 0 (*local*) 39 40# INVALID-SYMBOL-TABLE-LLVM: VersionSymbols [ 41# INVALID-SYMBOL-TABLE-LLVM-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: expected SHT_DYNSYM, but got SHT_NULL 42# INVALID-SYMBOL-TABLE-LLVM-NEXT: ] 43 44## Check we report a warning when something is wrong with a string table linked to a symbol table that 45## is linked with SHT_GNU_versym. In this case we are unable to produce LLVM style output, 46## but GNU style is fine because it does not need that string table. 47 48# RUN: yaml2obj --docnum=2 %s -o %t3 49# RUN: llvm-readelf -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-GNU 50# RUN: llvm-readobj -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-LLVM 51 52# INVALID-STRING-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries: 53# INVALID-STRING-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym) 54# INVALID-STRING-TABLE-GNU-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 3: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL 55# INVALID-STRING-TABLE-GNU-NEXT: 000: 0 (*local*) 56 57# INVALID-STRING-TABLE-LLVM: VersionSymbols [ 58# INVALID-STRING-TABLE-LLVM-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 3: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL 59# INVALID-STRING-TABLE-LLVM-NEXT: ] 60 61--- !ELF 62FileHeader: 63 Class: ELFCLASS64 64 Data: ELFDATA2LSB 65 Type: ET_EXEC 66Sections: 67 - Name: .gnu.version 68 Type: SHT_GNU_versym 69 Entries: [ 0 ] 70 - Name: .dynstr 71 Type: SHT_NULL 72DynamicSymbols: [] 73 74## Check we report a warning when a SHT_GNU_versym section is not correctly aligned in memory. 75 76# RUN: yaml2obj --docnum=3 %s -DSHOFFSET=0xffff -o %t4 77# RUN: llvm-readelf -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-GNU 78# RUN: llvm-readobj -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-LLVM 79 80# MISALIGNED-GNU: Version symbols section '.gnu.version' contains 1 entries: 81# MISALIGNED-GNU-NEXT: Addr: 0000000000000000 Offset: 0x00ffff Link: 2 (.dynsym) 82# MISALIGNED-GNU-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned 83 84# MISALIGNED-LLVM: VersionSymbols [ 85# MISALIGNED-LLVM-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned 86# MISALIGNED-LLVM-NEXT: ] 87 88--- !ELF 89FileHeader: 90 Class: ELFCLASS64 91 Data: ELFDATA2LSB 92 Type: ET_EXEC 93Sections: 94 - Name: .gnu.version 95 Type: SHT_GNU_versym 96 Entries: [ 0 ] 97 ShOffset: [[SHOFFSET=<none>]] 98 ShName: [[SHNAME=<none>]] 99 - Name: .dynsym 100 Type: SHT_DYNSYM 101 ShName: [[DYNSYMNAME=<none>]] 102DynamicSymbols: [] 103 104## Check that llvm-readelf reports a warning when the name of the SHT_GNU_versym section can't be read. 105 106# RUN: yaml2obj %s --docnum=3 -DSHNAME=0xFF -o %t.invalid.name 107# RUN: llvm-readobj -V %t.invalid.name 2>&1 | \ 108# RUN: FileCheck %s --check-prefix=INVALID-NAME-LLVM -DFILE=%t.invalid.name --implicit-check-not=warning: 109# RUN: llvm-readelf -V %t.invalid.name 2>&1 | \ 110# RUN: FileCheck %s --check-prefix=INVALID-NAME-GNU -DFILE=%t.invalid.name --implicit-check-not=warning: 111 112# INVALID-NAME-LLVM: VersionSymbols [ 113# INVALID-NAME-LLVM-NEXT: Symbol { 114# INVALID-NAME-LLVM-NEXT: Version: 0 115# INVALID-NAME-LLVM-NEXT: Name: 116# INVALID-NAME-LLVM-NEXT: } 117# INVALID-NAME-LLVM-NEXT: ] 118 119# INVALID-NAME-GNU: warning: '[[FILE]]': unable to get the name of SHT_GNU_versym 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 120# INVALID-NAME-GNU-NEXT: Version symbols section '<?>' contains 1 entries: 121# INVALID-NAME-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym) 122# INVALID-NAME-GNU-NEXT: 000: 0 (*local*) 123 124## Check that llvm-readelf reports a warning when we are unable to read the name of 125## the section linked with the SHT_GNU_verneed section (usually ".dynsym"). 126 127# RUN: yaml2obj %s --docnum=3 -DDYNSYMNAME=0xFF -o %t.invalid.name2 128# RUN: llvm-readobj -V %t.invalid.name2 2>&1 | \ 129# RUN: FileCheck %s --check-prefix=INVALID-NAME-LLVM -DFILE=%t.invalid.name2 --implicit-check-not=warning: 130# RUN: llvm-readelf -V %t.invalid.name2 2>&1 | \ 131# RUN: FileCheck %s --check-prefix=INVALID-NAME2-GNU -DFILE=%t.invalid.name2 --implicit-check-not=warning: 132 133# INVALID-NAME2-GNU: Version symbols section '.gnu.version' contains 1 entries: 134# INVALID-NAME2-GNU-NEXT: warning: '[[FILE]]': unable to get the name of SHT_DYNSYM 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 135# INVALID-NAME2-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (<?>) 136# INVALID-NAME2-GNU-NEXT: 000: 0 (*local*) 137 138## Check we report a warning when a SHT_GNU_versym section has an invalid entry size. 139 140# RUN: yaml2obj --docnum=4 %s -o %t5 141# RUN: llvm-readelf -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-GNU 142# RUN: llvm-readobj -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-LLVM 143 144# INVALID-ENT-SIZE-GNU: Symbol table '.dynsym' contains 2 entries: 145# INVALID-ENT-SIZE-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name 146# INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3 147# INVALID-ENT-SIZE-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @<corrupt> 148# INVALID-ENT-SIZE-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo@<corrupt> 149# INVALID-ENT-SIZE-GNU: Version symbols section '.gnu.version' contains 1 entries: 150# INVALID-ENT-SIZE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym) 151# INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has invalid sh_entsize: expected 2, but got 3 152 153# INVALID-ENT-SIZE-LLVM: DynamicSymbols [ 154# INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3 155# INVALID-ENT-SIZE-LLVM-NEXT: Symbol { 156# INVALID-ENT-SIZE-LLVM-NEXT: Name: @<corrupt> (0) 157# INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0 158# INVALID-ENT-SIZE-LLVM-NEXT: Size: 0 159# INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0) 160# INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0) 161# INVALID-ENT-SIZE-LLVM-NEXT: Other: 0 162# INVALID-ENT-SIZE-LLVM-NEXT: Section: Undefined (0x0) 163# INVALID-ENT-SIZE-LLVM-NEXT: } 164# INVALID-ENT-SIZE-LLVM-NEXT: Symbol { 165# INVALID-ENT-SIZE-LLVM-NEXT: Name: foo@<corrupt> (1) 166# INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0 167# INVALID-ENT-SIZE-LLVM-NEXT: Size: 0 168# INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0) 169# INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0) 170# INVALID-ENT-SIZE-LLVM-NEXT: Other: 0 171# INVALID-ENT-SIZE-LLVM-NEXT: Section: Undefined (0x0) 172# INVALID-ENT-SIZE-LLVM-NEXT: } 173# INVALID-ENT-SIZE-LLVM-NEXT: ] 174# INVALID-ENT-SIZE-LLVM: VersionSymbols [ 175# INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has invalid sh_entsize: expected 2, but got 3 176# INVALID-ENT-SIZE-LLVM-NEXT: ] 177 178--- !ELF 179FileHeader: 180 Class: ELFCLASS64 181 Data: ELFDATA2LSB 182 Type: ET_EXEC 183Sections: 184 - Name: .gnu.version 185 Type: SHT_GNU_versym 186 Entries: [ 0 ] 187 EntSize: 3 188DynamicSymbols: 189 - Name: foo 190 191## Check we report a warning when the number of version entries does not match the number of symbols in the associated symbol table. 192 193# RUN: yaml2obj --docnum=5 %s -o %t6 194# RUN: llvm-readelf -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-GNU 195# RUN: llvm-readobj -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-LLVM 196 197# SYMBOLS-NUM-MISMATCH-GNU: Version symbols section '.gnu.version' contains 2 entries: 198# SYMBOLS-NUM-MISMATCH-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym) 199# SYMBOLS-NUM-MISMATCH-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 2 200# SYMBOLS-NUM-MISMATCH-GNU-NEXT: 000: 0 (*local*) 1 (*global*) 201 202# SYMBOLS-NUM-MISMATCH-LLVM: VersionSymbols [ 203# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 2 204# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: ] 205 206--- !ELF 207FileHeader: 208 Class: ELFCLASS64 209 Data: ELFDATA2LSB 210 Type: ET_EXEC 211Sections: 212 - Name: .gnu.version 213 Type: SHT_GNU_versym 214 Entries: [ 0, 1 ] 215DynamicSymbols: 216 - Name: foo 217 - Name: bar 218 219## Check we can dump a SHT_GNU_versym section when it is linked to a custom dynamic symbol 220## table that is not called ".dynsym". 221 222# RUN: yaml2obj --docnum=6 %s -o %t7 223# RUN: llvm-readelf -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-GNU 224# RUN: llvm-readobj -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-LLVM 225 226# CUSTOM-SYMTAB-GNU: Version symbols section '.gnu.version' contains 1 entries: 227# CUSTOM-SYMTAB-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.foo.dynsym) 228# CUSTOM-SYMTAB-GNU-NEXT: 000: 0 (*local*) 229 230# CUSTOM-SYMTAB-LLVM: VersionSymbols [ 231# CUSTOM-SYMTAB-LLVM-NEXT: Symbol { 232# CUSTOM-SYMTAB-LLVM-NEXT: Version: 0 233# CUSTOM-SYMTAB-LLVM-NEXT: Name: 234# CUSTOM-SYMTAB-LLVM-NEXT: } 235# CUSTOM-SYMTAB-LLVM-NEXT: ] 236 237--- !ELF 238FileHeader: 239 Class: ELFCLASS64 240 Data: ELFDATA2LSB 241 Type: ET_EXEC 242Sections: 243 - Name: .gnu.version 244 Type: SHT_GNU_versym 245 Link: .foo.dynsym 246 Entries: [ 0 ] 247## A custom empty dynamic symbol table with a null entry. 248 - Name: .foo.dynsym 249 Type: SHT_DYNSYM 250 Link: .dynstr 251 EntSize: 24 252 Size: 24 253DynamicSymbols: 254 - Name: foo 255 - Name: bar 256 257## Version index in a SHT_GNU_versym section overflows the version map. 258## Check we report it when trying to dump dynamic symbols. 259 260# RUN: yaml2obj %s --docnum=7 -o %t8 261# RUN: llvm-readobj --dyn-syms %t8 2>&1 \ 262# RUN: | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-LLVM %s 263# RUN: llvm-readelf --dyn-syms %t8 2>&1 \ 264# RUN: | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-GNU %s 265 266# VERSION-OVERFLOW-LLVM: DynamicSymbols [ 267# VERSION-OVERFLOW-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing 268# VERSION-OVERFLOW-LLVM-NEXT: Symbol { 269# VERSION-OVERFLOW-LLVM-NEXT: Name: @<corrupt> (0) 270# VERSION-OVERFLOW-LLVM: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 254 which is missing 271# VERSION-OVERFLOW-LLVM-NEXT: Symbol { 272# VERSION-OVERFLOW-LLVM-NEXT: Name: foo@<corrupt> (5) 273# VERSION-OVERFLOW-LLVM: Symbol { 274# VERSION-OVERFLOW-LLVM-NEXT: Name: bar@<corrupt> (1) 275 276# VERSION-OVERFLOW-GNU: Symbol table '.dynsym' contains 3 entries: 277# VERSION-OVERFLOW-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name 278# VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing 279# VERSION-OVERFLOW-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @<corrupt> 280# VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 254 which is missing 281# VERSION-OVERFLOW-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo@<corrupt> 282# VERSION-OVERFLOW-GNU-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND bar@<corrupt 283 284--- !ELF 285FileHeader: 286 Class: ELFCLASS64 287 Data: ELFDATA2LSB 288 Type: ET_DYN 289Sections: 290 - Name: .gnu.version 291 Type: SHT_GNU_versym 292 Entries: [ 0xFF, 0xFE, 0xFF ] 293DynamicSymbols: 294 - Name: foo 295 - Name: bar 296