brintos

brintos / llvm-project-archived public Read only

0
0
Text · 25.5 KiB · 22f3452 Raw
722 lines · plain
1## Check llvm-readelf is able to dump the content of hash sections correctly.2 3## Check the output when both .hash and .gnu.hash sections are present.4 5# RUN: yaml2obj --docnum=1 -DBITS=32 %s -o %t1-32.so6# RUN: llvm-readelf --hash-symbols %t1-32.so \7# RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix HASH-328 9# RUN: yaml2obj --docnum=1 -DBITS=64 %s -o %t1-64.so10# RUN: llvm-readelf --hash-symbols %t1-64.so | FileCheck %s --check-prefix HASH-6411 12# HASH-32: Symbol table of .hash for image:13# HASH-32-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name14# HASH-32-NEXT:    1   0: 00000000     0 NOTYPE  GLOBAL DEFAULT UND ccc15# HASH-32-NEXT:    5   0: 00001001     0 NOTYPE  WEAK   DEFAULT   1 bbb16# HASH-32-NEXT:    3   0: 00000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd17# HASH-32-NEXT:    2   0: 00001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa18# HASH-32-NEXT:    4   0: 00000000     0 NOTYPE  GLOBAL DEFAULT   2 eee19# HASH-32-EMPTY:20# HASH-32: Symbol table of .gnu.hash for image:21# HASH-32-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name22# HASH-32-NEXT:    2   1: 00001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa23# HASH-32-NEXT:    3   1: 00000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd24# HASH-32-NEXT:    4   2: 00000000     0 NOTYPE  GLOBAL DEFAULT   2 eee25# HASH-32-NEXT:    5   2: 00001001     0 NOTYPE  WEAK   DEFAULT   1 bbb26# HASH-32-NOT: {{.}}27 28# HASH-64:      Symbol table of .hash for image:29# HASH-64-NEXT:  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name30# HASH-64-NEXT:    1   0: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND ccc31# HASH-64-NEXT:    5   0: 0000000000001001     0 NOTYPE  WEAK   DEFAULT   1 bbb32# HASH-64-NEXT:    3   0: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd33# HASH-64-NEXT:    2   0: 0000000000001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa34# HASH-64-NEXT:    4   0: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   2 eee35# HASH-64-EMPTY:36# HASH-64-NEXT: Symbol table of .gnu.hash for image:37# HASH-64-NEXT:  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name38# HASH-64-NEXT:    2   1: 0000000000001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa39# HASH-64-NEXT:    3   1: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd40# HASH-64-NEXT:    4   2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT   2 eee41# HASH-64-NEXT:    5   2: 0000000000001001     0 NOTYPE  WEAK   DEFAULT   1 bbb42# HASH-64-NOT: {{.}}43 44--- !ELF45FileHeader:46  Class: ELFCLASS[[BITS]]47  Data:  ELFDATA2LSB48  Type:  ET_DYN49Sections:50  - Name:    .hash51    Type:    SHT_HASH52    Flags:   [ SHF_ALLOC ]53    Link:    .dynsym54    Bucket:  [ 1, 0, 0 ]55    Chain:   [ 0, 5, 4, 2, 0, 3 ]56  - Name:    .gnu.hash57    Type:    SHT_GNU_HASH58    Flags:   [ SHF_ALLOC ]59    Link:    .dynsym60    Header:61      SymNdx: 0x262      Shift2: 0x063    BloomFilter: [ 0x0 ]64    HashBuckets: [ 0x0, 0x2, 0x4 ]65    HashValues:  [ 0x0B885C68, 0x0B886991, 0x0B886DF4, 0x0B8860CB ]66  - Name:  .dynamic67    Type:  SHT_DYNAMIC68    Flags: [ SHF_ALLOC ]69    Link:  .dynstr70    Entries:71## PT_LOAD's p_vaddr is 0x0. DT_HASH value is 0x0. 72## llvm-readelf will read .hash content from PT_LOAD's p_offset + (DT_HASH value - p_vaddr).73## This matches the file offset of the .hash section.74      - Tag:   DT_HASH75        Value: 0x000000000000000076      - Tag:   DT_GNU_HASH77## PT_LOAD's p_vaddr is 0x0. DT_GNU_HASH value is 0x2c (size of .hash = 0x2c).78## llvm-readelf will read .gnu.hash content from PT_LOAD's p_offset + (DT_GNU_HASH value - p_vaddr).79## This matches the file offset of the .gnu.hash section.80        Value: 0x000000000000002C81      - Tag:   DT_NULL82        Value: 0x000000000000000083DynamicSymbols:84  - Name:    [[NAME=ccc]]85    Binding: STB_GLOBAL86    Type:    [[TYPE=STT_NOTYPE]]87  - Name:    [[NAME=aaa]]88    Section: .hash89    Binding: STB_GLOBAL90    Value:   0x000000000000100091    Type:    [[TYPE=STT_NOTYPE]]92  - Name:    [[NAME=ddd]]93    Index:   SHN_ABS94    Binding: STB_GLOBAL95    Value:   0x000000000000000196    Type:    [[TYPE=STT_NOTYPE]]97  - Name:    [[NAME=eee]]98    Section: .gnu.hash99    Binding: STB_GLOBAL100    Type:    [[TYPE=STT_NOTYPE]]101  - Name:    [[NAME=bbb]]102    Section: .hash103    Binding: STB_WEAK104    Value:   0x0000000000001001105    Type:    [[TYPE=STT_NOTYPE]]106ProgramHeaders:107  - Type:      PT_LOAD108    Flags:     [ PF_R, PF_X ]109    FirstSec:  .hash110    LastSec:   .dynamic111 112## Check what we print for unnamed section symbols.113# RUN: yaml2obj --docnum=1 -DBITS=64 -DTYPE=STT_SECTION -DNAME="''" %s -o %t1-sec-syms.so114# RUN: llvm-readelf --hash-symbols %t1-sec-syms.so 2>&1 | \115# RUN:   FileCheck %s -DFILE=%t1-sec-syms.so --check-prefix=UNNAMED-SEC-SYMS116 117# UNNAMED-SEC-SYMS:      Symbol table of .hash for image:118# UNNAMED-SEC-SYMS-NEXT:  Num   {{.*}} Ndx Name119# UNNAMED-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)120# UNNAMED-SEC-SYMS-NEXT:    1   {{.*}} UND <?>121# UNNAMED-SEC-SYMS-NEXT:    5   {{.*}}   1 .hash122# UNNAMED-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)123# UNNAMED-SEC-SYMS-NEXT:    3   {{.*}} ABS <?>124# UNNAMED-SEC-SYMS-NEXT:    2   {{.*}}   1 .hash125# UNNAMED-SEC-SYMS-NEXT:    4   {{.*}}   2 .gnu.hash126# UNNAMED-SEC-SYMS-EMPTY:127# UNNAMED-SEC-SYMS:      Symbol table of .gnu.hash for image:128# UNNAMED-SEC-SYMS-NEXT:  Num {{.*}} Ndx Name129# UNNAMED-SEC-SYMS-NEXT:    2 {{.*}}   1 .hash130# UNNAMED-SEC-SYMS-NEXT:    3 {{.*}} ABS <?>131# UNNAMED-SEC-SYMS-NEXT:    4 {{.*}}   2 .gnu.hash132# UNNAMED-SEC-SYMS-NEXT:    5 {{.*}}   1 .hash133 134## Check the output when only .hash section is present.135 136# RUN: yaml2obj --docnum=2 %s -o %t2-32.so137# RUN: llvm-readelf --hash-symbols %t2-32.so \138# RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ONLY-HASH-32139 140# ONLY-HASH-32: Symbol table of .hash for image:141# ONLY-HASH-32-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name142# ONLY-HASH-32-NEXT:    1   0: 00000000     0 NOTYPE  GLOBAL DEFAULT UND ccc143# ONLY-HASH-32-NEXT:    5   0: 00001001     0 NOTYPE  WEAK   DEFAULT   1 bbb144# ONLY-HASH-32-NEXT:    3   0: 00000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd145# ONLY-HASH-32-NEXT:    2   0: 00001000     0 NOTYPE  GLOBAL DEFAULT   1 aaa146# ONLY-HASH-32-NEXT:    4   0: 00000000     0 NOTYPE  GLOBAL DEFAULT   2 eee147# ONLY-HASH-32-NOT: {{.}}148 149--- !ELF150FileHeader:151  Class: ELFCLASS32152  Data:  ELFDATA2LSB153  Type:  ET_DYN154Sections:155  - Name:    .hash156    Type:    SHT_HASH157    Flags:   [ SHF_ALLOC ]158    Link:    .dynsym159    Bucket: [ 1, 0, 0 ]160    Chain:  [ 0, 5, 4, 2, 0, 3 ]161  - Name:  .dynamic162    Type:  SHT_DYNAMIC163    Flags: [ SHF_ALLOC ]164    Link:  .dynstr165    Entries:166      - Tag:   DT_HASH167        Value: 0x0000000000000000168      - Tag:   DT_NULL169        Value: 0x0000000000000000170DynamicSymbols:171  - Name:    ccc172    Binding: STB_GLOBAL173  - Name:    aaa174    Section: .hash175    Binding: STB_GLOBAL176    Value:   0x0000000000001000177  - Name:    ddd178    Index:   SHN_ABS179    Binding: STB_GLOBAL180    Value:   0x0000000000000001181  - Name:    eee182    Section: .dynamic183    Binding: STB_GLOBAL184  - Name:    bbb185    Section: .hash186    Binding: STB_WEAK187    Value:   0x0000000000001001188ProgramHeaders:189  - Type:     PT_LOAD190    Flags:    [ PF_R, PF_X ]191    FirstSec: .hash192    LastSec:  .dynamic193 194## Check the output when only .gnu.hash section is present.195 196# RUN: yaml2obj --docnum=3 %s -o %t3-32.so197# RUN: llvm-readelf --hash-symbols %t3-32.so \198# RUN:   | FileCheck %s --strict-whitespace --match-full-lines --check-prefix ONLY-GNUHASH-32199 200# ONLY-GNUHASH-32: Symbol table of .gnu.hash for image:201# ONLY-GNUHASH-32-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name202# ONLY-GNUHASH-32-NEXT:    2   1: 00001000     0 NOTYPE  GLOBAL DEFAULT   2 aaa203# ONLY-GNUHASH-32-NEXT:    3   1: 00000001     0 NOTYPE  GLOBAL DEFAULT ABS ddd204# ONLY-GNUHASH-32-NEXT:    4   2: 00000000     0 NOTYPE  GLOBAL DEFAULT   1 eee205# ONLY-GNUHASH-32-NEXT:    5   2: 00001001     0 NOTYPE  WEAK   DEFAULT   2 bbb206# ONLY-GNUHASH-32-NOT: {{.}}207 208--- !ELF209FileHeader:210  Class: ELFCLASS32211  Data:  ELFDATA2LSB212  Type:  ET_DYN213Sections:214  - Name:    .gnu.hash215    Type:    SHT_GNU_HASH216    Flags:   [ SHF_ALLOC ]217    Link:    .dynsym218    Header:219      SymNdx: 0x2220      Shift2: 0x0221    BloomFilter: [ 0x0 ]222    HashBuckets: [ 0x0, 0x2, 0x4 ]223    HashValues:  [ 0x0B885C68, 0x0B886991, 0x0B886DF4, 0x0B8860CB ]224  - Name:  .dynamic225    Type:  SHT_DYNAMIC226    Flags: [ SHF_ALLOC ]227    Link:  .dynstr228    Entries:229      - Tag:   DT_GNU_HASH230        Value: 0x0000000000000000231      - Tag:   DT_NULL232        Value: 0x0000000000000000233DynamicSymbols:234  - Name:    ccc235    Binding: STB_GLOBAL236  - Name:    aaa237    Section: .dynamic238    Binding: STB_GLOBAL239    Value:   0x0000000000001000240  - Name:    ddd241    Index:   SHN_ABS242    Binding: STB_GLOBAL243    Value:   0x0000000000000001244  - Name:    eee245    Section: .gnu.hash246    Binding: STB_GLOBAL247  - Name:    bbb248    Section: .dynamic249    Binding: STB_WEAK250    Value:   0x0000000000001001251ProgramHeaders:252  - Type:     PT_LOAD253    Flags:    [ PF_R, PF_X ]254    FirstSec: .gnu.hash255    LastSec:  .dynamic256 257## Show that if there are no hash sections, we do not print anything.258# RUN: yaml2obj --docnum=4 %s -o %t4.so259# RUN: llvm-readelf --hash-symbols %t4.so \260# RUN:   | FileCheck %s --check-prefix NO-HASH --allow-empty261 262# NO-HASH-NOT: {{.}}263 264## Check that we can still find the dynamic symbols (i.e. the above test265## doesn't pass due to a mistake in the dynamic section).266# RUN: llvm-readelf --dyn-symbols %t4.so | FileCheck %s --check-prefix DYNSYMS267 268# DYNSYMS: Symbol table '.dynsym' contains 2 entries:269 270--- !ELF271FileHeader:272  Class: ELFCLASS64273  Data:  ELFDATA2LSB274  Type:  ET_DYN275Sections:276  - Name:         .dynstr277    Type:         SHT_STRTAB278    Flags:        [ SHF_ALLOC ]279    AddressAlign: 0x100280    EntSize:      0x1281  - Name:         .dynsym282    Type:         SHT_DYNSYM283    Flags:        [ SHF_ALLOC ]284    Link:         .dynstr285    Address:      0x100286    AddressAlign: 0x100287    EntSize:      0x18288  - Name:         .dynamic289    Type:         SHT_DYNAMIC290    Flags:        [ SHF_ALLOC ]291    Address:      0x0000000000001000292    Link:         .dynstr293    AddressAlign: 0x0000000000001000294    EntSize:      0x0000000000000010295    Entries:296      - Tag:   DT_STRTAB297        Value: 0x0000000000000000298      - Tag:   DT_STRSZ299        Value: 0x0000000000000009300      - Tag:   DT_SYMTAB301        Value: 0x0000000000000100302      - Tag:   DT_SYMENT303        Value: 0x0000000000000018304      - Tag:   DT_NULL305        Value: 0x0000000000000000306  - Name:  .text.foo307    Type:  SHT_PROGBITS308    Flags: [ SHF_ALLOC, SHF_EXECINSTR, SHF_GROUP ]309    Size:  0x40310    Address: 0x2000311    AddressAlign: 0x2000312DynamicSymbols:313  - Name:    _Z3fooi314    Binding: STB_GLOBAL315ProgramHeaders:316  - Type:     PT_LOAD317    Flags:    [ PF_R, PF_X ]318    VAddr:    0x0319    FirstSec: .dynstr320    LastSec:  .text.foo321  - Type:     PT_DYNAMIC322    Flags:    [ PF_R ]323    VAddr:    0x1000324    FirstSec: .dynamic325    LastSec:  .dynamic326 327## Show that we report a warning for a hash table which contains an entry of328## the bucket array pointing to a cycle.329 330# RUN: yaml2obj --docnum=5 %s -o %t5.so331# RUN: llvm-readelf --hash-symbols %t5.so 2>&1 | \332# RUN:   FileCheck %s -DFILE=%t5.so --check-prefix=BROKEN --implicit-check-not=warning:333 334# BROKEN:      Symbol table of .hash for image:335# BROKEN-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name336# BROKEN-NEXT:    1   0: 00000000     0 NOTYPE  LOCAL  DEFAULT UND aaa337# BROKEN: warning: '[[FILE]]': .hash section is invalid: bucket 1: a cycle was detected in the linked chain338# BROKEN-NEXT:    1   1: 00000000     0 NOTYPE  LOCAL  DEFAULT UND aaa339# BROKEN-NOT: {{.}}340 341--- !ELF342FileHeader:343  Class: ELFCLASS32344  Data:  ELFDATA2LSB345  Type:  ET_DYN346Sections:347  - Name:    .hash348    Type:    SHT_HASH349    Link:    .dynsym350    Bucket:  [ 1, 1 ]351    Chain:   [ 1, 1 ]352  - Name:  .dynamic353    Type:  SHT_DYNAMIC354    Entries:355## llvm-readelf will read the hash table from the file offset356## p_offset + (p_vaddr - DT_HASH) = p_offset + (0 - 0) = p_offset,357## which is the start of PT_LOAD, i.e. the file offset of .hash.358      - Tag:   DT_HASH359        Value: 0x0360DynamicSymbols:361  - Name: aaa362ProgramHeaders:363  - Type:     PT_LOAD364    FirstSec: .hash365    LastSec:  .dynamic366 367## Each SHT_HASH section starts with two 32-bit fields: nbucket and nchain.368## Check we report an error when a DT_HASH value points to data that has size less than 8 bytes.369 370# RUN: yaml2obj --docnum=6 %s -o %t6.o371# RUN: llvm-readelf --hash-symbols %t6.o 2>&1 | FileCheck %s --check-prefix=ERR1 -DFILE=%t6.o372 373# ERR1: warning: '[[FILE]]': the hash table at offset 0x2b1 goes past the end of the file (0x2b8){{$}}374 375--- !ELF376FileHeader:377  Class: ELFCLASS64378  Data:  ELFDATA2LSB379  Type:  ET_DYN380Sections:381  - Name:   .hash382    Type:   SHT_HASH383    Flags:  [ SHF_ALLOC ]384    Bucket: [ 0 ]385    Chain:  [ 0 ]386  - Name:  .dynamic387    Type:  SHT_DYNAMIC388    Flags: [ SHF_WRITE, SHF_ALLOC ]389    Entries:390      - Tag:   DT_HASH391        Value: 0x239392      - Tag:   DT_NULL393        Value: 0x0394DynamicSymbols: []395ProgramHeaders:396  - Type:     PT_LOAD397    FileSize: 0x23a398    FirstSec: .hash399    LastSec:  .dynamic400 401## Check we report a warning when the hash table goes past the end of the file.402 403## Case A.1: the hash table ends right before the EOF. We have a broken nbucket404##           field that has a value larger than the number of buckets.405# RUN: yaml2obj --docnum=7 %s -o %t7.1.o -DNBUCKET=0x5d406# RUN: llvm-readelf --hash-symbols %t7.1.o 2>&1 | FileCheck %s --check-prefix=NOERR1407# NOERR1:            Symbol table of .hash for image:408# NOERR1-NEXT:         Num Buc:    Value  Size   Type   Bind Vis      Ndx Name409# NOERR1-NEXT-EMPTY:410 411## Case A.2: the hash table ends 1 byte past the EOF. We have a broken nbucket412##           field that has a value larger than the number of buckets.413# RUN: yaml2obj --docnum=7 %s -o %t7.2.o -DNBUCKET=0x5e414# RUN: llvm-readelf --hash-symbols %t7.2.o 2>&1 | FileCheck %s --check-prefix=ERR2 -DFILE=%t7.2.o415# ERR2:      Symbol table of .hash for image:416# ERR2-NEXT: warning: '[[FILE]]': the hash table at offset 0x54 goes past the end of the file (0x1d4), nbucket = 94, nchain = 1{{$}}417# ERR2-NOT:  {{.}}418 419## Case B.1: the hash table ends right before the EOF. We have a broken nchain420##           field that has a value larger than the number of chains.421# RUN: yaml2obj --docnum=7 %s -o %t7.3.o -DNCHAIN=0x5d422# RUN: llvm-readelf --hash-symbols %t7.3.o 2>&1 | \423# RUN:   FileCheck %s --implicit-check-not="warning:" --check-prefix=NOERR2 -DFILE=%t7.3.o424# NOERR2:      warning: '[[FILE]]': hash table nchain (93) differs from symbol count derived from SHT_DYNSYM section header (1)425# NOERR2:      warning: '[[FILE]]': the size (0x5d0) of the dynamic symbol table at 0x78, derived from the hash table, goes past the end of the file (0x1d4) and will be ignored426# NOERR2:      Symbol table of .hash for image:427# NOERR2-NEXT: Num Buc: Value Size Type Bind Vis Ndx Name428# NOERR2-NOT:  {{.}}429 430## Case B.2: the hash table ends 1 byte past the EOF. We have a broken nchain431##           field that has a value larger than the number of chains.432# RUN: yaml2obj --docnum=7 %s -o %t7.4.o -DNCHAIN=0x5e433# RUN: llvm-readelf --hash-symbols %t7.4.o 2>&1 | FileCheck %s --check-prefix=ERR3 -DFILE=%t7.4.o434# ERR3:      Symbol table of .hash for image:435# ERR3-NEXT: warning: '[[FILE]]': the hash table at offset 0x54 goes past the end of the file (0x1d4), nbucket = 1, nchain = 94{{$}}436# ERR3-NOT:  {{.}}437 438--- !ELF439FileHeader:440  Class: ELFCLASS32441  Data:  ELFDATA2LSB442  Type:  ET_DYN443Sections:444  - Name:    .hash445    Type:    SHT_HASH446    Flags:   [ SHF_ALLOC ]447    Bucket:  [ 0 ]448    NBucket: [[NBUCKET=1]]449    Chain:   [ 0 ]450    NChain:  [[NCHAIN=1]]451  - Name:  .dynamic452    Type:  SHT_DYNAMIC453    Flags: [ SHF_WRITE, SHF_ALLOC ]454    Entries:455      - Tag:   DT_HASH456        Value: 0x0457      - Tag:   DT_NULL458        Value: 0x0459DynamicSymbols: []460ProgramHeaders:461  - Type:     PT_LOAD462    FirstSec: .hash463    LastSec:  .dynamic464 465## Check we report a proper warning when a GNU hash table goes past the end of the file.466 467## Case A: the 'maskwords' field is set so that the table goes past the end of the file.468# RUN: yaml2obj --docnum=8 -D MASKWORDS=4294967295 %s -o %t.err.maskwords469# RUN: llvm-readelf --hash-symbols %t.err.maskwords 2>&1 | \470# RUN:   FileCheck %s -DFILE=%t.err.maskwords --check-prefix=ERR4471 472# ERR4:      Symbol table of .gnu.hash for image:473# ERR4-NEXT:  Num Buc: Value Size Type Bind Vis Ndx Name474# ERR4-NEXT: warning: '[[FILE]]': unable to dump the SHT_GNU_HASH section at 0x78: it goes past the end of the file475 476## Case B: the 'nbuckets' field is set so that the table goes past the end of the file.477# RUN: yaml2obj --docnum=8 -D NBUCKETS=4294967295 %s -o %t.err.nbuckets478# RUN: llvm-readelf --hash-symbols %t.err.nbuckets 2>&1 | \479# RUN:   FileCheck %s -DFILE=%t.err.nbuckets --check-prefix=ERR4480 481--- !ELF482FileHeader:483  Class: ELFCLASS64484  Data:  ELFDATA2LSB485  Type:  ET_DYN486Sections:487  - Name:  .gnu.hash488    Type:  SHT_GNU_HASH489    Flags: [ SHF_ALLOC ]490    Header:491      SymNdx: 0x1492      Shift2: 0x2493## The number of words in the Bloom filter. The value of 2 is no-op.494      MaskWords: [[MASKWORDS=2]]495## The number of hash buckets. The value of 3 is no-op.496      NBuckets:  [[NBUCKETS=3]]497    BloomFilter: [0x3, 0x4]498    HashBuckets: [0x5, 0x6, 0x7]499    HashValues:  [0x8, 0x9, 0xA, 0xB]500  - Name:  .dynamic501    Type:  SHT_DYNAMIC502    Flags: [ SHF_ALLOC ]503    Link:  .dynstr504    Entries:505      - Tag:   DT_GNU_HASH506        Value: 0x0507      - Tag:   DT_NULL508        Value: 0x0509DynamicSymbols:510  - Name:    aaa511    Binding: STB_GLOBAL512  - Name:    bbb513    Binding: STB_GLOBAL514  - Name:    ccc515    Binding: STB_GLOBAL516  - Name:    ddd517    Binding: STB_GLOBAL518ProgramHeaders:519  - Type:     PT_LOAD520    Flags:    [ PF_R, PF_X ]521    FirstSec: .gnu.hash522    LastSec:  .dynamic523 524## Check the behavior when the dynamic symbol table is empty or not found.525 526## Case A.1: Check we report a warning when the dynamic symbol table is empty and we attempt to print hash symbols527##         from the .hash table. The number of symbols in the dynamic symbol table can be calculated from its size528##         or derived from the Chain vector of the .hash table. Make both ways to return a zero to do the check.529# RUN: yaml2obj --docnum=9 %s -o %t9.1.so530# RUN: llvm-readelf --hash-symbols %t9.1.so 2>&1 | FileCheck %s -DFILE=%t9.1.so --check-prefix=DYNSYM-EMPTY-HASH531 532# DYNSYM-EMPTY-HASH:      Symbol table of .hash for image:533# DYNSYM-EMPTY-HASH-NEXT:   Num Buc:    Value  Size   Type   Bind Vis      Ndx Name534# DYNSYM-EMPTY-HASH-NEXT: warning: '[[FILE]]': unable to print symbols for the .hash table: the dynamic symbol table is empty535# DYNSYM-EMPTY-HASH-NOT:  {{.}}536 537--- !ELF538FileHeader:539  Class: ELFCLASS32540  Data:  ELFDATA2LSB541  Type:  ET_DYN542Sections:543  - Name:   .hash544    Type:   SHT_HASH545    Flags:  [ SHF_ALLOC ]546    Bucket: [ 0 ]547    Chain:  [ ]548  - Name:  .dynamic549    Type:  SHT_DYNAMIC550    Flags: [ SHF_ALLOC ]551    Entries:552      - Tag:   DT_HASH553        Value: 0x0554      - Tag:   DT_STRTAB555## PT_LOAD p_offset == .hash offset == 0x54.556## 0x54 + 0x2c == 0x80 == .dynstr offset.557        Value: 0x2c558      - Tag:   DT_STRSZ559        Value: 0x1560      - Tag:   DT_NULL561        Value: 0x0562  - Name:  .dynstr563    Type:  SHT_STRTAB564    Flags: [ SHF_ALLOC ]565  - Name:  .dynsym566    Type:  [[DYNSYMTYPE=SHT_DYNSYM]]567    Flags: [ SHF_ALLOC ]568    Size:  0569ProgramHeaders:570  - Type:     PT_LOAD571    Flags:    [ PF_R, PF_X ]572    FirstSec: .hash573    LastSec:  .dynstr574 575## Case A.2: similar to A.1, but now check that we report a warning when the dynamic symbol table was not found.576##           To do that, set the type of the .dynsym to SHT_PROGBITS to hide it.577# RUN: yaml2obj --docnum=9 -DDYNSYMTYPE=SHT_PROGBITS %s -o %t9.2.so578# RUN: llvm-readelf --hash-symbols %t9.2.so 2>&1 | FileCheck %s -DFILE=%t9.2.so --check-prefix=DYNSYM-NOTFOUND-HASH579 580# DYNSYM-NOTFOUND-HASH:      Symbol table of .hash for image:581# DYNSYM-NOTFOUND-HASH-NEXT:   Num Buc:    Value  Size   Type   Bind Vis      Ndx Name582# DYNSYM-NOTFOUND-HASH-NEXT: warning: '[[FILE]]': unable to print symbols for the .hash table: the dynamic symbol table was not found583# DYNSYM-NOTFOUND-HASH-NOT:  {{.}}584 585## Case B.1: Check we report a warning when the dynamic symbol table is empty and we attempt to print586##           hash symbols from the .gnu.hash table.587# RUN: yaml2obj --docnum=10 %s -o %t10.1.so588# RUN: llvm-readelf --hash-symbols %t10.1.so 2>&1 | FileCheck %s -DFILE=%t10.1.so --check-prefix=DYNSYM-EMPTY-GNUHASH589 590# DYNSYM-EMPTY-GNUHASH:      Symbol table of .gnu.hash for image:591# DYNSYM-EMPTY-GNUHASH-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name592# DYNSYM-EMPTY-GNUHASH-NEXT: warning: '[[FILE]]': unable to print symbols for the .gnu.hash table: the dynamic symbol table is empty593# DYNSYM-EMPTY-GNUHASH-NOT:  {{.}}594 595## Case B.2: similar to B.1, but now check that we report a warning when the dynamic symbol table was not found.596##           To do that, set the type of the .dynsym to SHT_PROGBITS to hide it.597# RUN: yaml2obj --docnum=10 -DDYNSYMTYPE=SHT_PROGBITS %s -o %t10.2.so598# RUN: llvm-readelf --hash-symbols %t10.2.so 2>&1 | FileCheck %s -DFILE=%t10.2.so --check-prefix=DYNSYM-NOTFOUND-GNUHASH599 600# DYNSYM-NOTFOUND-GNUHASH:      Symbol table of .gnu.hash for image:601# DYNSYM-NOTFOUND-GNUHASH-NEXT:  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name602# DYNSYM-NOTFOUND-GNUHASH-NEXT: warning: '[[FILE]]': unable to print symbols for the .gnu.hash table: the dynamic symbol table was not found603# DYNSYM-NOTFOUND-GNUHASH-NOT:  {{.}}604 605--- !ELF606FileHeader:607  Class: ELFCLASS32608  Data:  ELFDATA2LSB609  Type:  ET_DYN610Sections:611  - Name:  .gnu.hash612    Type:  SHT_GNU_HASH613    Flags: [ SHF_ALLOC ]614    Header:615      SymNdx: 0x0616      Shift2: 0x0617    BloomFilter: [ 0x0 ]618    HashBuckets: [ 0x1 ]619    HashValues:  [ 0x0 ]620  - Name:  .dynamic621    Type:  SHT_DYNAMIC622    Flags: [ SHF_ALLOC ]623    Entries:624      - Tag:   DT_GNU_HASH625        Value: 0x0626      - Tag:   DT_STRTAB627## PT_LOAD p_offset == .hash offset == 0x54.628## 0x54 + 0x3c == 0x80 == .dynstr offset.629        Value: 0x3c630      - Tag:   DT_STRSZ631        Value: 0x1632      - Tag:   DT_NULL633        Value: 0x0634  - Name: .dynstr635    Type: SHT_STRTAB636  - Name:  .dynsym637    Type:  [[DYNSYMTYPE=SHT_DYNSYM]]638    Flags: [ SHF_ALLOC ]639    Size:  0640ProgramHeaders:641  - Type:     PT_LOAD642    Flags:    [ PF_R, PF_X ]643    FirstSec: .gnu.hash644    LastSec:  .dynstr645 646## In this case we have a broken value in the hash buckets array. Normally it contains an647## index into the dynamic symbol table and also is used to get a hash value from the hash values array.648## llvm-readelf attempts to read a symbol that is past the end of the dynamic symbol table.649 650# RUN: yaml2obj --docnum=11 -DVALUE=0x2 %s -o %t11.past.dynsym.so651# RUN: llvm-readelf --hash-symbols %t11.past.dynsym.so 2>&1 | \652# RUN:   FileCheck %s -DFILE=%t11.past.dynsym.so --check-prefix=BUCKET-PAST-DYNSYM653 654# BUCKET-PAST-DYNSYM:      Symbol table of .gnu.hash for image:655# BUCKET-PAST-DYNSYM-NEXT:   Num Buc:    Value          Size   Type   Bind Vis      Ndx Name656# BUCKET-PAST-DYNSYM-NEXT: warning: '[[FILE]]': unable to print hashed symbol with index 2, which is greater than or equal to the number of dynamic symbols (2)657# BUCKET-PAST-DYNSYM-NEXT:     1   2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND foo658# BUCKET-PAST-DYNSYM-NOT:  {{.}}659 660--- !ELF661FileHeader:662  Class: ELFCLASS64663  Data:  ELFDATA2LSB664  Type:  ET_DYN665Sections:666  - Name:  .gnu.hash667    Type:  SHT_GNU_HASH668    Flags: [ SHF_ALLOC ]669    Link:  .dynsym670    Header:671      SymNdx: [[SYMNDX=0x0]]672      Shift2: 0x0673    BloomFilter: [ 0x0 ]674    HashBuckets: [ 0x0, [[VALUE]], 0x1 ]675    HashValues:  [ 0x0 ]676  - Name:  .dynamic677    Type:  SHT_DYNAMIC678    Flags: [ SHF_ALLOC ]679    Link:  .dynstr680    Entries:681      - Tag:   DT_GNU_HASH682        Value: 0x0683      - Tag:   DT_NULL684        Value: 0x0685DynamicSymbols:686  - Name:    foo687    Binding: STB_GLOBAL688ProgramHeaders:689  - Type:     PT_LOAD690    Flags:    [ PF_R, PF_X ]691    FirstSec: .gnu.hash692    LastSec:  .dynamic693 694## In this case we are unable to read a hash value for a symbol with695## an index that is less than the index of the first hashed symbol.696 697# RUN: yaml2obj --docnum=11 -DSYMNDX=0x2 -DVALUE=0x1 %s -o %t11.first.hashed.so698# RUN: llvm-readelf --hash-symbols %t11.first.hashed.so 2>&1 | \699# RUN:   FileCheck %s -DFILE=%t11.first.hashed.so --check-prefix=FIRST-HASHED700 701# FIRST-HASHED:      Symbol table of .gnu.hash for image:702# FIRST-HASHED-NEXT:   Num Buc:    Value          Size   Type   Bind Vis      Ndx Name703# FIRST-HASHED-NEXT: warning: '[[FILE]]': unable to get hash values for the SHT_GNU_HASH section: the first hashed symbol index (2) is greater than or equal to the number of dynamic symbols (2)704# FIRST-HASHED-NEXT:     1   1: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND foo705# FIRST-HASHED-NEXT: warning: '[[FILE]]': unable to read the hash value for symbol with index 1, which is less than the index of the first hashed symbol (2)706# FIRST-HASHED-NEXT:     1   2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND foo707# FIRST-HASHED-NOT:  {{.}}708 709## In this case one of the chain values doesn't end with a stopper bit and llvm-readelf attempts to read710## a dynamic symbol with an index that is equal to the number of dynamic symbols.711 712# RUN: yaml2obj --docnum=11 -DSYMNDX=0x1 -DVALUE=0x1 %s -o %t11.chain.bit.so713# RUN: llvm-readelf --hash-symbols %t11.chain.bit.so 2>&1 | \714# RUN:   FileCheck %s -DFILE=%t11.chain.bit.so --check-prefix=CHAIN-BIT715 716# CHAIN-BIT:      Symbol table of .gnu.hash for image:717# CHAIN-BIT-NEXT:   Num Buc:    Value          Size   Type   Bind Vis      Ndx Name718# CHAIN-BIT-NEXT:     1   1: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND foo719# CHAIN-BIT-NEXT: warning: '[[FILE]]': unable to print hashed symbol with index 2, which is greater than or equal to the number of dynamic symbols (2)720# CHAIN-BIT-NEXT:     1   2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND foo721# CHAIN-BIT-NOT:  {{.}}722