296 lines · plain
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 %t16# RUN: llvm-readelf -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=GNU-INVALID-LINK7# RUN: llvm-readobj -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=LLVM-INVALID-LINK8 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: 25511# 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: 25515# LLVM-INVALID-LINK-NEXT: ]16 17--- !ELF18FileHeader:19 Class: ELFCLASS6420 Data: ELFDATA2LSB21 Type: ET_EXEC22Sections:23 - Name: .gnu.version24 Type: SHT_GNU_versym25 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 reference29## a dynamic symbol table section.30 31# RUN: yaml2obj --docnum=1 -DLINK=0x0 %s -o %t232# RUN: llvm-readelf -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-GNU33# RUN: llvm-readobj -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-LLVM34 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_NULL38# 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_NULL42# 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 that45## 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 %t349# RUN: llvm-readelf -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-GNU50# RUN: llvm-readobj -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-LLVM51 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_NULL55# 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_NULL59# INVALID-STRING-TABLE-LLVM-NEXT: ]60 61--- !ELF62FileHeader:63 Class: ELFCLASS6464 Data: ELFDATA2LSB65 Type: ET_EXEC66Sections:67 - Name: .gnu.version68 Type: SHT_GNU_versym69 Entries: [ 0 ]70 - Name: .dynstr71 Type: SHT_NULL72DynamicSymbols: []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 %t477# RUN: llvm-readelf -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-GNU78# RUN: llvm-readobj -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-LLVM79 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 misaligned83 84# MISALIGNED-LLVM: VersionSymbols [85# MISALIGNED-LLVM-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned86# MISALIGNED-LLVM-NEXT: ]87 88--- !ELF89FileHeader:90 Class: ELFCLASS6491 Data: ELFDATA2LSB92 Type: ET_EXEC93Sections:94 - Name: .gnu.version95 Type: SHT_GNU_versym96 Entries: [ 0 ]97 ShOffset: [[SHOFFSET=<none>]]98 ShName: [[SHNAME=<none>]]99 - Name: .dynsym100 Type: SHT_DYNSYM101 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.name107# 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: 0115# 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 table120# 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 of125## the section linked with the SHT_GNU_verneed section (usually ".dynsym").126 127# RUN: yaml2obj %s --docnum=3 -DDYNSYMNAME=0xFF -o %t.invalid.name2128# 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 table135# 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 %t5141# RUN: llvm-readelf -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-GNU142# RUN: llvm-readobj -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-LLVM143 144# INVALID-ENT-SIZE-GNU: Symbol table '.dynsym' contains 2 entries:145# INVALID-ENT-SIZE-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name146# INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3147# 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 3152 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 3155# INVALID-ENT-SIZE-LLVM-NEXT: Symbol {156# INVALID-ENT-SIZE-LLVM-NEXT: Name: @<corrupt> (0)157# INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0158# INVALID-ENT-SIZE-LLVM-NEXT: Size: 0159# INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0)160# INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0)161# INVALID-ENT-SIZE-LLVM-NEXT: Other: 0162# 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: 0x0167# INVALID-ENT-SIZE-LLVM-NEXT: Size: 0168# INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0)169# INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0)170# INVALID-ENT-SIZE-LLVM-NEXT: Other: 0171# 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 3176# INVALID-ENT-SIZE-LLVM-NEXT: ]177 178--- !ELF179FileHeader:180 Class: ELFCLASS64181 Data: ELFDATA2LSB182 Type: ET_EXEC183Sections:184 - Name: .gnu.version185 Type: SHT_GNU_versym186 Entries: [ 0 ]187 EntSize: 3188DynamicSymbols:189 - Name: foo190 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 %t6194# RUN: llvm-readelf -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-GNU195# RUN: llvm-readobj -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-LLVM196 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 2200# 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 2204# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: ]205 206--- !ELF207FileHeader:208 Class: ELFCLASS64209 Data: ELFDATA2LSB210 Type: ET_EXEC211Sections:212 - Name: .gnu.version213 Type: SHT_GNU_versym214 Entries: [ 0, 1 ]215DynamicSymbols:216 - Name: foo217 - Name: bar218 219## Check we can dump a SHT_GNU_versym section when it is linked to a custom dynamic symbol220## table that is not called ".dynsym".221 222# RUN: yaml2obj --docnum=6 %s -o %t7223# RUN: llvm-readelf -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-GNU224# RUN: llvm-readobj -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-LLVM225 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: 0233# CUSTOM-SYMTAB-LLVM-NEXT: Name:234# CUSTOM-SYMTAB-LLVM-NEXT: }235# CUSTOM-SYMTAB-LLVM-NEXT: ]236 237--- !ELF238FileHeader:239 Class: ELFCLASS64240 Data: ELFDATA2LSB241 Type: ET_EXEC242Sections:243 - Name: .gnu.version244 Type: SHT_GNU_versym245 Link: .foo.dynsym246 Entries: [ 0 ]247## A custom empty dynamic symbol table with a null entry.248 - Name: .foo.dynsym249 Type: SHT_DYNSYM250 Link: .dynstr251 EntSize: 24252 Size: 24253DynamicSymbols:254 - Name: foo255 - Name: bar256 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 %t8261# RUN: llvm-readobj --dyn-syms %t8 2>&1 \262# RUN: | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-LLVM %s263# RUN: llvm-readelf --dyn-syms %t8 2>&1 \264# RUN: | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-GNU %s265 266# VERSION-OVERFLOW-LLVM: DynamicSymbols [267# VERSION-OVERFLOW-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing268# 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 missing271# 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 Name278# VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing279# 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 missing281# 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@<corrupt283 284--- !ELF285FileHeader:286 Class: ELFCLASS64287 Data: ELFDATA2LSB288 Type: ET_DYN289Sections:290 - Name: .gnu.version291 Type: SHT_GNU_versym292 Entries: [ 0xFF, 0xFE, 0xFF ]293DynamicSymbols:294 - Name: foo295 - Name: bar296