brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.1 KiB · a8c3b98 Raw
309 lines · plain
1## Check how the GNU Hash section is dumped with --gnu-hash-table.2 3# RUN: yaml2obj --docnum=1 -DBITS=64 %s -o %t.x644# RUN: yaml2obj --docnum=1 -DBITS=32 %s -o %t.x325 6# RUN: llvm-readobj --gnu-hash-table %t.x64 | FileCheck %s7# RUN: llvm-readelf --gnu-hash-table %t.x64 | FileCheck %s8 9# RUN: llvm-readobj --gnu-hash-table %t.x32 | FileCheck %s10# RUN: llvm-readelf --gnu-hash-table %t.x32 | FileCheck %s11 12# CHECK:      GnuHashTable {13# CHECK-NEXT:   Num Buckets: 314# CHECK-NEXT:   First Hashed Symbol Index: 115# CHECK-NEXT:   Num Mask Words: 216# CHECK-NEXT:   Shift Count: 217# CHECK-NEXT:   Bloom Filter: [0x3, 0x4]18# CHECK-NEXT:   Buckets: [5, 6, 7]19# CHECK-NEXT:   Values: [0x8, 0x9, 0xA, 0xB]20# CHECK-NEXT: }21 22--- !ELF23FileHeader:24  Class: ELFCLASS[[BITS]]25  Data:  ELFDATA2LSB26  Type:  ET_DYN27Sections:28  - Name:  .gnu.hash29    Type:  SHT_GNU_HASH30    Flags: [ SHF_ALLOC ]31    Header:32      SymNdx: 0x133      Shift2: 0x234## The number of words in the Bloom filter. The value of 2 is no-op.35      MaskWords: [[MASKWORDS=2]]36## The number of hash buckets. The value of 3 is no-op.37      NBuckets:  [[NBUCKETS=3]]38    BloomFilter: [0x3, 0x4]39    HashBuckets: [0x5, 0x6, 0x7]40    HashValues:  [0x8, 0x9, 0xA, 0xB]41  - Name:  .dynamic42    Type:  SHT_DYNAMIC43    Flags: [ SHF_ALLOC ]44    Link:  .dynstr45    Entries:46      - Tag:   DT_GNU_HASH47        Value: 0x048      - Tag:   DT_NULL49        Value: 0x050DynamicSymbols:51  - Name:    aaa52    Binding: STB_GLOBAL53  - Name:    bbb54    Binding: STB_GLOBAL55  - Name:    ccc56    Binding: STB_GLOBAL57  - Name:    ddd58    Binding: STB_GLOBAL59ProgramHeaders:60  - Type:     PT_LOAD61    Flags:    [ PF_R, PF_X ]62    FirstSec: .gnu.hash63    LastSec:  .dynamic64 65## Check we report a warning if there is no dynamic symbol section in the object.66 67# RUN: yaml2obj --docnum=2 %s -o %t.nodynsym68# RUN: llvm-readobj --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM69# RUN: llvm-readelf --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM70 71# NODYNSYM:      GnuHashTable {72# NODYNSYM-NEXT:   Num Buckets: 173# NODYNSYM-NEXT:   First Hashed Symbol Index: 074# NODYNSYM-NEXT:   Num Mask Words: 175# NODYNSYM-NEXT:   Shift Count: 076# NODYNSYM-NEXT:   Bloom Filter: [0x0]77# NODYNSYM-NEXT:   Buckets: [0]78# NODYNSYM-NEXT: warning: '[[FILE]]': unable to dump 'Values' for the SHT_GNU_HASH section: no dynamic symbol table found79# NODYNSYM-NEXT: }80 81--- !ELF82FileHeader:83  Class: ELFCLASS6484  Data:  ELFDATA2LSB85  Type:  ET_DYN86Sections:87  - Name:  .gnu.hash88    Type:  SHT_GNU_HASH89    Flags: [ SHF_ALLOC ]90    Header:91      SymNdx: 0x092      Shift2: 0x093    BloomFilter: [ 0x0 ]94    HashBuckets: [ 0x0 ]95    HashValues:  [ 0x0 ]96  - Name:  .dynamic97    Type:  SHT_DYNAMIC98    Flags: [ SHF_ALLOC ]99    Entries:100      - Tag:   DT_GNU_HASH101        Value: 0x0102      - Tag:   DT_NULL103        Value: 0x0104ProgramHeaders:105  - Type:     PT_LOAD106    Flags:    [ PF_R, PF_X ]107    FirstSec: .gnu.hash108    LastSec:  .dynamic109 110## Check what we do when the index of the first symbol in the dynamic symbol table111## included in the hash table is larger than the number of dynamic symbols.112 113# RUN: yaml2obj --docnum=3 %s -o %t.brokensymndx114# RUN: llvm-readobj --gnu-hash-table %t.brokensymndx 2>&1 \115# RUN:   | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX116# RUN: llvm-readelf --gnu-hash-table %t.brokensymndx 2>&1 \117# RUN:   | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX118 119# SYMNDX:      GnuHashTable {120# SYMNDX-NEXT:   Num Buckets: 1121# SYMNDX-NEXT:   First Hashed Symbol Index: 2122# SYMNDX-NEXT:   Num Mask Words: 1123# SYMNDX-NEXT:   Shift Count: 0124# SYMNDX-NEXT:   Bloom Filter: [0x1]125# SYMNDX-NEXT:   Buckets: [2]126# SYMNDX-NEXT: warning: '[[FILE]]': unable to dump '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)127# SYMNDX-NEXT: }128 129--- !ELF130FileHeader:131  Class: ELFCLASS64132  Data:  ELFDATA2LSB133  Type:  ET_DYN134Sections:135  - Name:  .gnu.hash136    Type:  SHT_GNU_HASH137    Flags: [ SHF_ALLOC ]138    Header:139      SymNdx: 0x2140      Shift2: 0x0141    BloomFilter: [ 0x1 ]142    HashBuckets: [ 0x2 ]143    HashValues:  [ 0x3 ]144  - Name:  .dynamic145    Type:  SHT_DYNAMIC146    Flags: [ SHF_ALLOC ]147    Link:  0148    Entries:149      - Tag:   DT_GNU_HASH150        Value: 0x0151      - Tag:   DT_NULL152        Value: 0x0153DynamicSymbols:154  - Name:    aaa155    Binding: STB_GLOBAL156ProgramHeaders:157  - Type:     PT_LOAD158    Flags:    [ PF_R, PF_X ]159    FirstSec: .gnu.hash160    LastSec:  .dynamic161 162## Check we emit a warning when the dynamic symbol table is empty.163## A valid dynamic symbol table should have at least one symbol: the symbol with index 0.164 165# RUN: yaml2obj --docnum=4 %s -o %t.emptydynsym166# RUN: llvm-readobj --gnu-hash-table %t.emptydynsym 2>&1 \167# RUN:   | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM168# RUN: llvm-readelf --gnu-hash-table %t.emptydynsym 2>&1 \169# RUN:   | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM170 171# EMPTY-DYNSYM:      GnuHashTable {172# EMPTY-DYNSYM-NEXT:   Num Buckets: 1173# EMPTY-DYNSYM-NEXT:   First Hashed Symbol Index: 0174# EMPTY-DYNSYM-NEXT:   Num Mask Words: 1175# EMPTY-DYNSYM-NEXT:   Shift Count: 0176# EMPTY-DYNSYM-NEXT:   Bloom Filter: [0x0]177# EMPTY-DYNSYM-NEXT:   Buckets: [0]178# EMPTY-DYNSYM-NEXT: warning: '[[FILE]]': unable to dump 'Values' for the SHT_GNU_HASH section: the dynamic symbol table is empty179# EMPTY-DYNSYM-NEXT: }180 181--- !ELF182FileHeader:183  Class: ELFCLASS64184  Data:  ELFDATA2LSB185  Type:  ET_DYN186Sections:187  - Name:  .gnu.hash188    Type:  SHT_GNU_HASH189    Flags: [ SHF_ALLOC ]190    Header:191      SymNdx: 0x0192      Shift2: 0x0193    BloomFilter: [ 0x0 ]194    HashBuckets: [ 0x0 ]195    HashValues:  [ 0x0 ]196  - Name:  .dynamic197    Type:  SHT_DYNAMIC198    Flags: [ SHF_ALLOC ]199    Link:  0200    Entries:201      - Tag:   DT_GNU_HASH202        Value: 0x0203      - Tag:   DT_NULL204        Value: 0x0205  - Name: .dynsym206    Type: SHT_DYNSYM207    Size: 0208ProgramHeaders:209  - Type:     PT_LOAD210    Flags:    [ PF_R, PF_X ]211    FirstSec: .gnu.hash212    LastSec:  .dynamic213 214## Linkers might produce an empty no-op SHT_GNU_HASH section when215## there are no dynamic symbols or when all dynamic symbols are undefined.216## Such sections normally have a single zero entry in the bloom217## filter, a single zero entry in the hash bucket and no values.218##219## The index of the first symbol in the dynamic symbol table220## included in the hash table can be set to the number of dynamic symbols,221## which is one larger than the index of the last dynamic symbol.222## For empty tables however, this value is unimportant and can be ignored.223 224## Case A: set the index of the first symbol in the dynamic symbol table to225##         the number of dynamic symbols.226# RUN: yaml2obj --docnum=5 -DSYMNDX=0x1 %s -o %t.empty.1227# RUN: llvm-readobj --gnu-hash-table %t.empty.1 2>&1 \228# RUN:   | FileCheck %s -DFILE=%t.empty.1 -DSYMNDX=1 --check-prefix=EMPTY --implicit-check-not="warning:"229# RUN: llvm-readelf --gnu-hash-table %t.empty.1 2>&1 \230# RUN:   | FileCheck %s -DFILE=%t.empty.1 -DSYMNDX=1 --check-prefix=EMPTY --implicit-check-not="warning:"231 232## Case B: set the index of the first symbol in the dynamic symbol table to233##         an arbitrary value that is larger than the number of dynamic symbols.234# RUN: yaml2obj --docnum=5 -DSYMNDX=0x2 %s -o %t.empty.2235# RUN: llvm-readobj --gnu-hash-table %t.empty.2 2>&1 \236# RUN:   | FileCheck %s -DFILE=%t.empty.2 -DSYMNDX=2 --check-prefix=EMPTY --implicit-check-not="warning:"237# RUN: llvm-readelf --gnu-hash-table %t.empty.2 2>&1 \238# RUN:   | FileCheck %s -DFILE=%t.empty.2 -DSYMNDX=2 --check-prefix=EMPTY --implicit-check-not="warning:"239 240# EMPTY:      GnuHashTable {241# EMPTY-NEXT:   Num Buckets: 1242# EMPTY-NEXT:   First Hashed Symbol Index: [[SYMNDX]]243# EMPTY-NEXT:   Num Mask Words: 1244# EMPTY-NEXT:   Shift Count: 0245# EMPTY-NEXT:   Bloom Filter: [0x0]246# EMPTY-NEXT:   Buckets: [0]247# EMPTY-NEXT:   Values: []248# EMPTY-NEXT: }249 250--- !ELF251FileHeader:252  Class: ELFCLASS64253  Data:  ELFDATA2LSB254  Type:  ET_DYN255Sections:256  - Name:  .gnu.hash257    Type:  SHT_GNU_HASH258    Flags: [ SHF_ALLOC ]259    Header:260      SymNdx: [[SYMNDX]]261      Shift2: 0x0262    BloomFilter: [ 0x0 ]263    HashBuckets: [ 0x0 ]264    HashValues:  [ ]265  - Name:  .dynamic266    Type:  SHT_DYNAMIC267    Flags: [ SHF_ALLOC ]268    Link:  0269    Entries:270      - Tag:   DT_GNU_HASH271        Value: 0x0272      - Tag:   DT_NULL273        Value: 0x0274DynamicSymbols: []275ProgramHeaders:276  - Type:     PT_LOAD277    Flags:    [ PF_R, PF_X ]278    FirstSec: .gnu.hash279    LastSec:  .dynamic280 281## Check we report a proper warning when a hash table goes past the end of the file.282 283## Case A: the 'maskwords' field is set so that the table goes past the end of the file.284# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D MASKWORDS=4294967295 %s -o %t.err.maskwords285# RUN: llvm-readobj --gnu-hash-table %t.err.maskwords 2>&1 | \286# RUN:   FileCheck %s -DFILE=%t.err.maskwords -DMASKWORDS=4294967295 -DNBUCKETS=3 --check-prefix=ERR287# RUN: llvm-readelf --gnu-hash-table %t.err.maskwords 2>&1 | \288# RUN:   FileCheck %s -DFILE=%t.err.maskwords -DMASKWORDS=4294967295 -DNBUCKETS=3 --check-prefix=ERR289 290## Case B: the 'nbuckets' field is set so that the table goes past the end of the file.291# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D NBUCKETS=4294967295 %s -o %t.err.nbuckets292# RUN: llvm-readobj --gnu-hash-table %t.err.nbuckets 2>&1 | \293# RUN:   FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR294# RUN: llvm-readelf --gnu-hash-table %t.err.nbuckets 2>&1 | \295# RUN:   FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR296 297# ERR:      GnuHashTable {298# ERR-NEXT:   Num Buckets: [[NBUCKETS]]299# ERR-NEXT:   First Hashed Symbol Index: 1300# ERR-NEXT:   Num Mask Words: [[MASKWORDS]]301# ERR-NEXT:   Shift Count: 2302# ERR-NEXT: warning: '[[FILE]]': unable to dump the SHT_GNU_HASH section at 0x78: it goes past the end of the file303# ERR-NEXT: }304 305## Check we report a single warning about the broken GNU hash table when both306## --gnu-hash-table and --elf-hash-histogram options are requested.307# RUN: llvm-readelf --gnu-hash-table --elf-hash-histogram %t.err.nbuckets 2>&1 | \308# RUN:   FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR --implicit-check-not=warning309