1 ## Check how the GNU Hash section is dumped with --gnu-hash-table.
3 # RUN: yaml2obj --docnum=1 -DBITS=64 %s -o %t.x64
4 # RUN: yaml2obj --docnum=1 -DBITS=32 %s -o %t.x32
6 # RUN: llvm-readobj --gnu-hash-table %t.x64 | FileCheck %s
7 # RUN: llvm-readelf --gnu-hash-table %t.x64 | FileCheck %s
9 # RUN: llvm-readobj --gnu-hash-table %t.x32 | FileCheck %s
10 # RUN: llvm-readelf --gnu-hash-table %t.x32 | FileCheck %s
12 # CHECK: GnuHashTable {
13 # CHECK-NEXT: Num Buckets: 3
14 # CHECK-NEXT: First Hashed Symbol Index: 1
15 # CHECK-NEXT: Num Mask Words: 2
16 # CHECK-NEXT: Shift Count: 2
17 # CHECK-NEXT: Bloom Filter: [0x3, 0x4]
18 # CHECK-NEXT: Buckets: [5, 6, 7]
19 # CHECK-NEXT: Values: [0x8, 0x9, 0xA, 0xB]
24 Class: ELFCLASS[[BITS]]
34 ## 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]
65 ## Check we report a warning if there is no dynamic symbol section in the object.
67 # RUN: yaml2obj --docnum=2 %s -o %t.nodynsym
68 # RUN: llvm-readobj --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM
69 # RUN: llvm-readelf --gnu-hash-table %t.nodynsym 2>&1 | FileCheck %s -DFILE=%t.nodynsym --check-prefix=NODYNSYM
71 # NODYNSYM: GnuHashTable {
72 # NODYNSYM-NEXT: Num Buckets: 1
73 # NODYNSYM-NEXT: First Hashed Symbol Index: 0
74 # NODYNSYM-NEXT: Num Mask Words: 1
75 # NODYNSYM-NEXT: Shift Count: 0
76 # 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 found
106 Flags: [ PF_R, PF_X ]
110 ## Check what we do when the index of the first symbol in the dynamic symbol table
111 ## included in the hash table is larger than the number of dynamic symbols.
113 # RUN: yaml2obj --docnum=3 %s -o %t.brokensymndx
114 # RUN: llvm-readobj --gnu-hash-table %t.brokensymndx 2>&1 \
115 # RUN: | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX
116 # RUN: llvm-readelf --gnu-hash-table %t.brokensymndx 2>&1 \
117 # RUN: | FileCheck %s -DFILE=%t.brokensymndx --check-prefix=SYMNDX
119 # SYMNDX: GnuHashTable {
120 # SYMNDX-NEXT: Num Buckets: 1
121 # SYMNDX-NEXT: First Hashed Symbol Index: 2
122 # SYMNDX-NEXT: Num Mask Words: 1
123 # SYMNDX-NEXT: Shift Count: 0
124 # 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)
158 Flags: [ PF_R, PF_X ]
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.
165 # RUN: yaml2obj --docnum=4 %s -o %t.emptydynsym
166 # RUN: llvm-readobj --gnu-hash-table %t.emptydynsym 2>&1 \
167 # RUN: | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM
168 # RUN: llvm-readelf --gnu-hash-table %t.emptydynsym 2>&1 \
169 # RUN: | FileCheck %s -DFILE=%t.emptydynsym --check-prefix=EMPTY-DYNSYM
171 # EMPTY-DYNSYM: GnuHashTable {
172 # EMPTY-DYNSYM-NEXT: Num Buckets: 1
173 # EMPTY-DYNSYM-NEXT: First Hashed Symbol Index: 0
174 # EMPTY-DYNSYM-NEXT: Num Mask Words: 1
175 # EMPTY-DYNSYM-NEXT: Shift Count: 0
176 # 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 empty
179 # EMPTY-DYNSYM-NEXT: }
210 Flags: [ PF_R, PF_X ]
214 ## Linkers might produce an empty no-op SHT_GNU_HASH section when
215 ## there are no dynamic symbols or when all dynamic symbols are undefined.
216 ## Such sections normally have a single zero entry in the bloom
217 ## filter, a single zero entry in the hash bucket and no values.
219 ## The index of the first symbol in the dynamic symbol table
220 ## 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.
224 ## Case A: set the index of the first symbol in the dynamic symbol table to
225 ## the number of dynamic symbols.
226 # RUN: yaml2obj --docnum=5 -DSYMNDX=0x1 %s -o %t.empty.1
227 # 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:"
232 ## Case B: set the index of the first symbol in the dynamic symbol table to
233 ## an arbitrary value that is larger than the number of dynamic symbols.
234 # RUN: yaml2obj --docnum=5 -DSYMNDX=0x2 %s -o %t.empty.2
235 # 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:"
240 # EMPTY: GnuHashTable {
241 # EMPTY-NEXT: Num Buckets: 1
242 # EMPTY-NEXT: First Hashed Symbol Index: [[SYMNDX]]
243 # EMPTY-NEXT: Num Mask Words: 1
244 # EMPTY-NEXT: Shift Count: 0
245 # EMPTY-NEXT: Bloom Filter: [0x0]
246 # EMPTY-NEXT: Buckets: [0]
247 # EMPTY-NEXT: Values: []
277 Flags: [ PF_R, PF_X ]
281 ## Check we report a proper warning when a hash table goes past the end of the file.
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.maskwords
285 # 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=ERR
287 # 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=ERR
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.nbuckets
292 # 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=ERR
294 # 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=ERR
297 # ERR: GnuHashTable {
298 # ERR-NEXT: Num Buckets: [[NBUCKETS]]
299 # ERR-NEXT: First Hashed Symbol Index: 1
300 # ERR-NEXT: Num Mask Words: [[MASKWORDS]]
301 # ERR-NEXT: Shift Count: 2
302 # ERR-NEXT: warning: '[[FILE]]': unable to dump the SHT_GNU_HASH section at 0x78: it goes past the end of the file
305 ## Check we report a single warning about the broken GNU hash table when both
306 ## --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=warning