1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
## Check how the GNU Hash section is dumped with --gnu-hash-table.
# RUN: yaml2obj --docnum=1 -DBITS=64 %s -o %t.x64
# RUN: yaml2obj --docnum=1 -DBITS=32 %s -o %t.x32
# RUN: llvm-readobj --gnu-hash-table %t.x64 | FileCheck %s
# RUN: llvm-readelf --gnu-hash-table %t.x64 | FileCheck %s
# RUN: llvm-readobj --gnu-hash-table %t.x32 | FileCheck %s
# RUN: llvm-readelf --gnu-hash-table %t.x32 | FileCheck %s
# CHECK: GnuHashTable {
# CHECK-NEXT: Num Buckets: 3
# CHECK-NEXT: First Hashed Symbol Index: 1
# CHECK-NEXT: Num Mask Words: 2
# CHECK-NEXT: Shift Count: 2
# CHECK-NEXT: Bloom Filter: [0x3, 0x4]
# CHECK-NEXT: Buckets: [5, 6, 7]
# CHECK-NEXT: Values: [0x8, 0x9, 0xA, 0xB]
# CHECK-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS[[BITS]]
Data: ELFDATA2LSB
Type: ET_DYN
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
Header:
SymNdx: 0x1
Shift2: 0x2
## The number of words in the Bloom filter. The value of 2 is no-op.
MaskWords: [[MASKWORDS=2]]
## The number of hash buckets. The value of 3 is no-op.
NBuckets: [[NBUCKETS=3]]
BloomFilter: [0x3, 0x4]
HashBuckets: [0x5, 0x6, 0x7]
HashValues: [0x8, 0x9, 0xA, 0xB]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Link: .dynstr
Entries:
- Tag: DT_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
DynamicSymbols:
- Name: aaa
Binding: STB_GLOBAL
- Name: bbb
Binding: STB_GLOBAL
- Name: ccc
Binding: STB_GLOBAL
- Name: ddd
Binding: STB_GLOBAL
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
FirstSec: .gnu.hash
LastSec: .dynamic
## Check we report a warning if there is no dynamic symbol section in the object.
# RUN: yaml2obj --docnum=2 %s -o %t.nodynsym
# RUN: llvm-readobj --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM
# RUN: llvm-readelf --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM
# NODYNSYM: GnuHashTable {
# NODYNSYM-NEXT: Num Buckets: 1
# NODYNSYM-NEXT: First Hashed Symbol Index: 0
# NODYNSYM-NEXT: Num Mask Words: 1
# NODYNSYM-NEXT: Shift Count: 0
# NODYNSYM-NEXT: Bloom Filter: [0x0]
# NODYNSYM-NEXT: Buckets: [0]
# NODYNSYM-NEXT: warning: '[[FILE]]': unable to dump 'Values' for the SHT_GNU_HASH section: no dynamic symbol table found
# NODYNSYM-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
Header:
SymNdx: 0x0
Shift2: 0x0
BloomFilter: [ 0x0 ]
HashBuckets: [ 0x0 ]
HashValues: [ 0x0 ]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Entries:
- Tag: DT_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
FirstSec: .gnu.hash
LastSec: .dynamic
## Check what we do when the index of the first symbol in the dynamic symbol table
## included in the hash table is larger than the number of dynamic symbols.
# RUN: yaml2obj --docnum=3 %s -o %t.brokensymndx
# RUN: llvm-readobj --gnu-hash-table %t.brokensymndx 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX
# RUN: llvm-readelf --gnu-hash-table %t.brokensymndx 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX
# SYMNDX: GnuHashTable {
# SYMNDX-NEXT: Num Buckets: 1
# SYMNDX-NEXT: First Hashed Symbol Index: 2
# SYMNDX-NEXT: Num Mask Words: 1
# SYMNDX-NEXT: Shift Count: 0
# SYMNDX-NEXT: Bloom Filter: [0x1]
# SYMNDX-NEXT: Buckets: [2]
# 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)
# SYMNDX-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
Header:
SymNdx: 0x2
Shift2: 0x0
BloomFilter: [ 0x1 ]
HashBuckets: [ 0x2 ]
HashValues: [ 0x3 ]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Link: 0
Entries:
- Tag: DT_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
DynamicSymbols:
- Name: aaa
Binding: STB_GLOBAL
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
FirstSec: .gnu.hash
LastSec: .dynamic
## Check we emit a warning when the dynamic symbol table is empty.
## A valid dynamic symbol table should have at least one symbol: the symbol with index 0.
# RUN: yaml2obj --docnum=4 %s -o %t.emptydynsym
# RUN: llvm-readobj --gnu-hash-table %t.emptydynsym 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM
# RUN: llvm-readelf --gnu-hash-table %t.emptydynsym 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM
# EMPTY-DYNSYM: GnuHashTable {
# EMPTY-DYNSYM-NEXT: Num Buckets: 1
# EMPTY-DYNSYM-NEXT: First Hashed Symbol Index: 0
# EMPTY-DYNSYM-NEXT: Num Mask Words: 1
# EMPTY-DYNSYM-NEXT: Shift Count: 0
# EMPTY-DYNSYM-NEXT: Bloom Filter: [0x0]
# EMPTY-DYNSYM-NEXT: Buckets: [0]
# EMPTY-DYNSYM-NEXT: warning: '[[FILE]]': unable to dump 'Values' for the SHT_GNU_HASH section: the dynamic symbol table is empty
# EMPTY-DYNSYM-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
Header:
SymNdx: 0x0
Shift2: 0x0
BloomFilter: [ 0x0 ]
HashBuckets: [ 0x0 ]
HashValues: [ 0x0 ]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Link: 0
Entries:
- Tag: DT_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
- Name: .dynsym
Type: SHT_DYNSYM
Size: 0
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
FirstSec: .gnu.hash
LastSec: .dynamic
## Linkers might produce an empty no-op SHT_GNU_HASH section when
## there are no dynamic symbols or when all dynamic symbols are undefined.
## Such sections normally have a single zero entry in the bloom
## filter, a single zero entry in the hash bucket and no values.
##
## The index of the first symbol in the dynamic symbol table
## included in the hash table can be set to the number of dynamic symbols,
## which is one larger than the index of the last dynamic symbol.
## For empty tables however, this value is unimportant and can be ignored.
## Case A: set the index of the first symbol in the dynamic symbol table to
## the number of dynamic symbols.
# RUN: yaml2obj --docnum=5 -DSYMNDX=0x1 %s -o %t.empty.1
# RUN: llvm-readobj --gnu-hash-table %t.empty.1 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.empty.1 -DSYMNDX=1 --check-prefix=EMPTY --implicit-check-not="warning:"
# RUN: llvm-readelf --gnu-hash-table %t.empty.1 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.empty.1 -DSYMNDX=1 --check-prefix=EMPTY --implicit-check-not="warning:"
## Case B: set the index of the first symbol in the dynamic symbol table to
## an arbitrary value that is larger than the number of dynamic symbols.
# RUN: yaml2obj --docnum=5 -DSYMNDX=0x2 %s -o %t.empty.2
# RUN: llvm-readobj --gnu-hash-table %t.empty.2 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.empty.2 -DSYMNDX=2 --check-prefix=EMPTY --implicit-check-not="warning:"
# RUN: llvm-readelf --gnu-hash-table %t.empty.2 2>&1 \
# RUN: | FileCheck %s -DFILE=%t.empty.2 -DSYMNDX=2 --check-prefix=EMPTY --implicit-check-not="warning:"
# EMPTY: GnuHashTable {
# EMPTY-NEXT: Num Buckets: 1
# EMPTY-NEXT: First Hashed Symbol Index: [[SYMNDX]]
# EMPTY-NEXT: Num Mask Words: 1
# EMPTY-NEXT: Shift Count: 0
# EMPTY-NEXT: Bloom Filter: [0x0]
# EMPTY-NEXT: Buckets: [0]
# EMPTY-NEXT: Values: []
# EMPTY-NEXT: }
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Sections:
- Name: .gnu.hash
Type: SHT_GNU_HASH
Flags: [ SHF_ALLOC ]
Header:
SymNdx: [[SYMNDX]]
Shift2: 0x0
BloomFilter: [ 0x0 ]
HashBuckets: [ 0x0 ]
HashValues: [ ]
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [ SHF_ALLOC ]
Link: 0
Entries:
- Tag: DT_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
DynamicSymbols: []
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_R, PF_X ]
FirstSec: .gnu.hash
LastSec: .dynamic
## Check we report a proper warning when a hash table goes past the end of the file.
## Case A: the 'maskwords' field is set so that the table goes past the end of the file.
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D MASKWORDS=4294967295 %s -o %t.err.maskwords
# RUN: llvm-readobj --gnu-hash-table %t.err.maskwords 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.maskwords -DMASKWORDS=4294967295 -DNBUCKETS=3 --check-prefix=ERR
# RUN: llvm-readelf --gnu-hash-table %t.err.maskwords 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.maskwords -DMASKWORDS=4294967295 -DNBUCKETS=3 --check-prefix=ERR
## Case B: the 'nbuckets' field is set so that the table goes past the end of the file.
# RUN: yaml2obj --docnum=1 -DBITS=64 -DMACHINE=EM_X86_64 -D NBUCKETS=4294967295 %s -o %t.err.nbuckets
# RUN: llvm-readobj --gnu-hash-table %t.err.nbuckets 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR
# RUN: llvm-readelf --gnu-hash-table %t.err.nbuckets 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR
# ERR: GnuHashTable {
# ERR-NEXT: Num Buckets: [[NBUCKETS]]
# ERR-NEXT: First Hashed Symbol Index: 1
# ERR-NEXT: Num Mask Words: [[MASKWORDS]]
# ERR-NEXT: Shift Count: 2
# ERR-NEXT: warning: '[[FILE]]': unable to dump the SHT_GNU_HASH section at 0x78: it goes past the end of the file
# ERR-NEXT: }
## Check we report a single warning about the broken GNU hash table when both
## --gnu-hash-table and --elf-hash-histogram options are requested.
# RUN: llvm-readelf --gnu-hash-table --elf-hash-histogram %t.err.nbuckets 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.err.nbuckets -DMASKWORDS=2 -DNBUCKETS=4294967295 --check-prefix=ERR --implicit-check-not=warning
|