brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.4 KiB · e768e13 Raw
327 lines · plain
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 %t16# RUN: llvm-readobj -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-LLVM --implicit-check-not="warning:" -DFILE=%t17# RUN: llvm-readelf -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-GNU --implicit-check-not="warning:" -DFILE=%t18 9# INVALID-LINK-LLVM: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 25510 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: 25513# INVALID-LINK-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 255 (<corrupt>)14 15--- !ELF16FileHeader:17  Class: ELFCLASS6418  Data:  ELFDATA2LSB19  Type:  ET_DYN20Sections:21  - Name:    .gnu.version_d22    Type:    SHT_GNU_verdef23    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 %t229# RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t230# RUN: llvm-readelf -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t231 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_NULL33 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 %t337# RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t338# RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t339 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--- !ELF43FileHeader:44  Class: ELFCLASS6445  Data:  ELFDATA2LSB46  Type:  ET_DYN47Sections:48  - Name:     .gnu.version_d49    Type:     SHT_GNU_verdef50    Entries:  []51    ShOffset: [[SHOFFSET=<none>]]52    ShName:   [[SHNAME=<none>]]53  - Name:   .dynstr54    Type:   SHT_STRTAB55    ShName: [[DYNSTRNAME=<none>]]56DynamicSymbols:57  - Name: foo58 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.name62# 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 table71# 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 of75## the section linked with the SHT_GNU_verdef section (usually ".dynstr").76 77# RUN: yaml2obj %s --docnum=2 -DDYNSTRNAME=0xFF -o %t.invalid.name278# 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 table85# 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 definition88## that goes past the end of the section.89 90# RUN: yaml2obj %s --docnum=3 -o %t491# RUN: llvm-readobj -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t492# RUN: llvm-readelf -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t493 94# DEF-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 goes past the end of the section95 96--- !ELF97FileHeader:98  Class: ELFCLASS6499  Data:  ELFDATA2LSB100  Type:  ET_DYN101Sections:102  - Name: .gnu.version_d103    Type: SHT_GNU_verdef104    Entries:105      - Names:106          - FOO107    ShSize: 1108DynamicSymbols:109  - Name: foo110 111## Check that we report a warning when a SHT_GNU_verdef section contains a version definition112## that refers to an auxiliary entry that goes past the end of the section.113 114# RUN: yaml2obj %s --docnum=4 -o %t5115# RUN: llvm-readobj -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5116# RUN: llvm-readelf -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5117 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 section119 120--- !ELF121FileHeader:122  Class: ELFCLASS64123  Data:  ELFDATA2LSB124  Type:  ET_DYN125Sections:126  - Name: .gnu.version_d127    Type: SHT_GNU_verdef128    Entries:129      - Names:130          - FOO131    ## The correct sh_size is 28.132    ShSize: 27133DynamicSymbols:134  - Name: foo135 136## Check that we can dump a SHT_GNU_verdef section properly even if it contains version names strings137## that overrun the linked string table.138 139# RUN: yaml2obj %s --docnum=5 -o %t6140# RUN: llvm-readobj -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-LLVM --implicit-check-not="warning:" -DFILE=%t6141# RUN: llvm-readelf -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-GNU --implicit-check-not="warning:" -DFILE=%t6142 143# PAST-STRTAB-END-LLVM:      VersionDefinitions [144# PAST-STRTAB-END-LLVM-NEXT:   Definition {145# PAST-STRTAB-END-LLVM-NEXT:     Version: 1146# PAST-STRTAB-END-LLVM-NEXT:     Flags [ (0x0)147# PAST-STRTAB-END-LLVM-NEXT:     ]148# PAST-STRTAB-END-LLVM-NEXT:     Index: 0149# PAST-STRTAB-END-LLVM-NEXT:     Hash: 0150# PAST-STRTAB-END-LLVM-NEXT:     Name: <invalid vda_name: 5>151# PAST-STRTAB-END-LLVM-NEXT:     Predecessors: []152# PAST-STRTAB-END-LLVM-NEXT:   }153# PAST-STRTAB-END-LLVM-NEXT: ]154 155# PAST-STRTAB-END-GNU:      Version definition section '.gnu.version_d' contains 1 entries:156# PAST-STRTAB-END-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 2 (.strtab)157# PAST-STRTAB-END-GNU-NEXT:   0x0000: Rev: 1  Flags: none  Index: 0  Cnt: 1  Name: <invalid vda_name: 5>158 159--- !ELF160FileHeader:161  Class: ELFCLASS64162  Data:  ELFDATA2LSB163  Type:  ET_DYN164Sections:165  - Name: .gnu.version_d166    Type: SHT_GNU_verdef167    Link: .strtab168    Entries:169      - Names:170          - FOO171  - Name: .strtab172    Type: SHT_STRTAB173DynamicSymbols:174  - Name: BAR175 176## Check we report a warning when a version definition is not correctly aligned in memory.177 178# RUN: yaml2obj %s --docnum=6 -o %t7179# RUN: llvm-readobj -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7180# RUN: llvm-readelf -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7181 182# MISALIGNED-DEF: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned version definition entry at offset 0x0183 184--- !ELF185FileHeader:186  Class: ELFCLASS64187  Data:  ELFDATA2LSB188  Type:  ET_DYN189Sections:190  - Type: Fill191    Size: 0x1192  - Name: .gnu.version_d193    Type: SHT_GNU_verdef194    Link: .dynstr195    Info: 0x1196    Entries:197      - Names:198          - FOO199DynamicSymbols:200  - Name: foo201 202## Check we report a warning when an auxiliary entry is not correctly aligned in memory.203 204# RUN: yaml2obj %s --docnum=7 -o %t8205# RUN: llvm-readobj -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8206# RUN: llvm-readelf -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8207 208# MISALIGNED-AUX: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned auxiliary entry at offset 0x13209 210--- !ELF211FileHeader:212  Class: ELFCLASS64213  Data:  ELFDATA2LSB214  Type:  ET_DYN215Sections:216  - Name:  .gnu.version_d217    Type:  SHT_GNU_verdef218    Flags: [ SHF_ALLOC ]219    Link:  .dynstr220    Info:  0x1221## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory.222    Content: "0100000000000100000000001300000000000000"223DynamicSymbols:224  - Name:    foo225    Binding: STB_GLOBAL226 227## Check how we handle a version definition entry with an unsupported version.228 229# RUN: yaml2obj %s --docnum=8 -o %t9230# RUN: llvm-readobj -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9231# RUN: llvm-readelf -V %t9 2>&1 | FileCheck %s --check-prefix=UNSUPPORTED-VERSION -DFILE=%t9232 233# UNSUPPORTED-VERSION: warning: '[[FILE]]': unable to dump SHT_GNU_verdef section with index 1: version 65278 is not yet supported234 235--- !ELF236FileHeader:237  Class: ELFCLASS64238  Data:  ELFDATA2LSB239  Type:  ET_DYN240Sections:241  - Name: .gnu.version_d242    Type: SHT_GNU_verdef243    Link: .dynstr244    Info: 0x1245    Entries:246      - Version: 0xfefe247        Names: []248DynamicSymbols:249  - Name: foo250 251## Check we report a warning when trying to print version symbols, but SHT_GNU_verdef252## is invalid due to any reason.253 254# RUN: yaml2obj %s --docnum=9 -o %t10255# RUN: llvm-readobj -V %t10 2>&1 | FileCheck %s --check-prefix=INVALID-VERDEF-LLVM -DFILE=%t10256# RUN: llvm-readelf -V %t10 2>&1 | FileCheck %s --check-prefix=INVALID-VERDEF-GNU -DFILE=%t10257 258# INVALID-VERDEF-LLVM:      VersionSymbols [259# INVALID-VERDEF-LLVM-NEXT:    Symbol {260# INVALID-VERDEF-LLVM-NEXT:      Version: 0261# INVALID-VERDEF-LLVM-NEXT:      Name: {{$}}262# INVALID-VERDEF-LLVM-NEXT:    }263# INVALID-VERDEF-LLVM-NEXT:    Symbol {264# INVALID-VERDEF-LLVM-NEXT:    Version: 2265# INVALID-VERDEF-LLVM-NEXT:  warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section266# INVALID-VERDEF-LLVM-NEXT:    Name: foo@<corrupt>267 268# INVALID-VERDEF-GNU:      Version symbols section '.gnu.version' contains 2 entries:269# INVALID-VERDEF-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 3 (.dynsym)270# INVALID-VERDEF-GNU-NEXT: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 2: version definition 1 goes past the end of the section271# INVALID-VERDEF-GNU-NEXT:   000: 0 (*local*) 2 (<corrupt>)272 273--- !ELF274FileHeader:275  Class: ELFCLASS64276  Data:  ELFDATA2LSB277  Type:  ET_DYN278Sections:279  - Name:         .gnu.version280    Type:         SHT_GNU_versym281    Flags:        [ SHF_ALLOC ]282    AddressAlign: 0x0000000000000002283    EntSize:      0x0000000000000002284    Entries:      [ 0, 2 ]285  - Name:         .gnu.version_d286    Type:         SHT_GNU_verdef287    Flags:        [ SHF_ALLOC ]288    AddressAlign: 0x4289    Info:         0x1290    Entries: []291DynamicSymbols:292  - Name:    foo293    Binding: STB_GLOBAL294 295## Check we report "invalid vda_name" when vda_name = size(.dynstr)296 297# RUN: yaml2obj %s --docnum=10 -o %t11298# RUN: llvm-readobj -V %t11 2>&1 | FileCheck %s --check-prefix=VDANAME-PAST-END-LLVM -DFILE=%t11 --implicit-check-not=warning:299# RUN: llvm-readelf -V %t11 2>&1 | FileCheck %s --check-prefix=VDANAME-PAST-END-GNU -DFILE=%t11 --implicit-check-not=warning:300 301# VDANAME-PAST-END-LLVM:      Name: V0302# VDANAME-PAST-END-LLVM-NEXT: Predecessors: [<invalid vda_name: 7>]303 304# VDANAME-PAST-END-GNU:      Version definition section '.gnu.version_d' contains 1 entries:305# VDANAME-PAST-END-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 3 (.dynstr)306# VDANAME-PAST-END-GNU-NEXT:   0x0000: Rev: 1  Flags: none  Index: 0  Cnt: 2  Name: V0307# VDANAME-PAST-END-GNU-NEXT:   0x001c: Parent 1: <invalid vda_name: 7>308 309--- !ELF310FileHeader:311  Class: ELFCLASS64312  Data:  ELFDATA2LSB313  Type:  ET_DYN314Sections:315  - Name:  .gnu.version_d316    Type:  SHT_GNU_verdef317    Flags: [ SHF_ALLOC ]318    Link:  .dynstr319    Info:  0x1320## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory.321    Content: "010000000000020000000000140000000000000004000000080000000700000000000000"322DynamicSymbols:323  - Name:    V1324    Binding: STB_GLOBAL325  - Name:    V0326    Binding: STB_GLOBAL327