forked from OSchip/llvm-project
210 lines
6.9 KiB
Plaintext
210 lines
6.9 KiB
Plaintext
## Here we test the --elf-hash-histogram command line option.
|
|
|
|
## This test case checks how we built histograms for hash sections.
|
|
|
|
# RUN: yaml2obj --docnum=1 -D BITS=32 %s -o %t1-32.o
|
|
# RUN: llvm-readelf --elf-hash-histogram %t1-32.o | FileCheck %s --check-prefix=HIST
|
|
|
|
## Test --histogram and -I aliases.
|
|
# RUN: llvm-readelf --histogram %t1-32.o | FileCheck %s --check-prefix=HIST
|
|
# RUN: llvm-readelf -I %t1-32.o | FileCheck %s --check-prefix=HIST
|
|
|
|
# RUN: yaml2obj --docnum=1 -D BITS=64 %s -o %t1-64.o
|
|
# RUN: llvm-readelf --elf-hash-histogram %t1-64.o | FileCheck %s --check-prefix=HIST
|
|
|
|
# HIST: Histogram for bucket list length (total of 3 buckets)
|
|
# HIST-NEXT: Length Number % of total Coverage
|
|
# HIST-NEXT: 0 2 ( 66.7%) 0.0%
|
|
# HIST-NEXT: 1 0 ( 0.0%) 0.0%
|
|
# HIST-NEXT: 2 0 ( 0.0%) 0.0%
|
|
# HIST-NEXT: 3 1 ( 33.3%) 100.0%
|
|
# HIST-NEXT: Histogram for `.gnu.hash' bucket list length (total of 3 buckets)
|
|
# HIST-NEXT: Length Number % of total Coverage
|
|
# HIST-NEXT: 0 1 ( 33.3%) 0.0%
|
|
# HIST-NEXT: 1 1 ( 33.3%) 25.0%
|
|
# HIST-NEXT: 2 0 ( 0.0%) 25.0%
|
|
# HIST-NEXT: 3 1 ( 33.3%) 100.0%
|
|
# HIST-NOT: {{.}}
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS[[BITS]]
|
|
Data: ELFDATA2LSB
|
|
Type: ET_DYN
|
|
Machine: EM_386
|
|
Sections:
|
|
- Name: .hash
|
|
Type: SHT_HASH
|
|
Flags: [ SHF_ALLOC ]
|
|
Bucket: [ 6, 4, 5 ]
|
|
Chain: [ 0, 0, 1, 0, 2 ]
|
|
- Name: .gnu.hash
|
|
Type: SHT_GNU_HASH
|
|
Flags: [ SHF_ALLOC ]
|
|
Header:
|
|
SymNdx: 0x1
|
|
Shift2: 0x0
|
|
BloomFilter: [ 0x0 ]
|
|
HashBuckets: [ 0x00000001, 0x00000004, 0x00000000 ]
|
|
HashValues: [ 0x0B887388, 0xECD54542, 0x7C92E3BB, 0x1C5871D9 ]
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Flags: [ SHF_WRITE, SHF_ALLOC ]
|
|
Entries:
|
|
- Tag: DT_HASH
|
|
Value: 0x0
|
|
- Tag: DT_GNU_HASH
|
|
## sizeof(.hash) == 0x28.
|
|
Value: 0x28
|
|
- Tag: DT_NULL
|
|
Value: 0x0
|
|
DynamicSymbols:
|
|
- Name: a
|
|
- Name: b
|
|
- Name: c
|
|
- Name: d
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
Sections:
|
|
- Section: .hash
|
|
- Section: .gnu.hash
|
|
- Section: .dynamic
|
|
|
|
## Show that we report a warning for a hash table which contains an entry of
|
|
## the bucket array pointing to a cycle.
|
|
|
|
# RUN: yaml2obj --docnum=2 %s -o %t2.o
|
|
# RUN: llvm-readelf --elf-hash-histogram 2>&1 %t2.o | FileCheck -DFILE=%t2.o %s --check-prefix=BROKEN
|
|
|
|
# BROKEN: warning: '[[FILE]]': .hash section is invalid: bucket 1: a cycle was detected in the linked chain
|
|
# BROKEN: Histogram for bucket list length (total of 1 buckets)
|
|
# BROKEN-NEXT: Length Number % of total Coverage
|
|
# BROKEN-NEXT: 0 0 ( 0.0%) 0.0%
|
|
# BROKEN-NEXT: 1 1 (100.0%) 100.0%
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS32
|
|
Data: ELFDATA2LSB
|
|
Type: ET_REL
|
|
Machine: EM_386
|
|
Sections:
|
|
- Name: .hash
|
|
Type: SHT_HASH
|
|
Link: .dynsym
|
|
Bucket: [ 1 ]
|
|
Chain: [ 0, 1 ]
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Flags: [ SHF_ALLOC ]
|
|
Entries:
|
|
## llvm-readelf will read the hash table from the file offset
|
|
## p_offset + (p_vaddr - DT_HASH) = p_offset + (0 - 0) = p_offset,
|
|
## which is the start of PT_LOAD, i.e. the file offset of .hash.
|
|
- Tag: DT_HASH
|
|
Value: 0x0
|
|
- Tag: DT_NULL
|
|
Value: 0
|
|
DynamicSymbols:
|
|
- Name: foo
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
Sections:
|
|
- Section: .hash
|
|
- Section: .dynamic
|
|
|
|
## Each SHT_HASH section starts with two 32-bit fields: nbucket and nchain.
|
|
## Check we report an error when a DT_HASH value points to data that has size less than 8 bytes.
|
|
|
|
# RUN: yaml2obj --docnum=3 %s -o %t3.o
|
|
# RUN: llvm-readelf --elf-hash-histogram %t3.o 2>&1 | FileCheck %s --check-prefix=ERR1 -DFILE=%t3.o
|
|
|
|
# ERR1: warning: '[[FILE]]': the hash table at offset 0x2b1 goes past the end of the file (0x2b8){{$}}
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS64
|
|
Data: ELFDATA2LSB
|
|
Type: ET_DYN
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .hash
|
|
Type: SHT_HASH
|
|
Flags: [ SHF_ALLOC ]
|
|
Bucket: [ 0 ]
|
|
Chain: [ 0 ]
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Flags: [ SHF_WRITE, SHF_ALLOC ]
|
|
Entries:
|
|
- Tag: DT_HASH
|
|
Value: 0x239
|
|
- Tag: DT_NULL
|
|
Value: 0x0
|
|
DynamicSymbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
FileSize: 0x23a
|
|
Sections:
|
|
- Section: .hash
|
|
- Section: .dynamic
|
|
|
|
## Check we report a warning when the hash table goes past the end of the file.
|
|
|
|
## Case A.1: the hash table ends right before the EOF. We have a broken nbucket
|
|
## field that has a value larger than the number of buckets.
|
|
# RUN: yaml2obj --docnum=4 %s -o %t4.1.o -DNBUCKET=0x5d -DNCHAIN=0x1
|
|
# RUN: llvm-readelf --elf-hash-histogram %t4.1.o 2>&1 | \
|
|
# RUN: FileCheck %s --implicit-check-not={{.}} --allow-empty
|
|
|
|
## Case A.2: the hash table ends 1 byte past the EOF. We have a broken nbucket
|
|
## field that has a value larger than the number of buckets.
|
|
# RUN: yaml2obj --docnum=4 %s -o %t4.2.o -DNBUCKET=0x5e -DNCHAIN=0x1
|
|
# RUN: llvm-readelf --elf-hash-histogram %t4.2.o 2>&1 | \
|
|
# RUN: FileCheck %s --check-prefix=ERR2 -DFILE=%t4.2.o --implicit-check-not="warning:"
|
|
# ERR2: warning: '[[FILE]]': the hash table at offset 0x54 goes past the end of the file (0x1d4), nbucket = 94, nchain = 1{{$}}
|
|
|
|
## Case B.1: the hash table ends right before the EOF. We have a broken nchain
|
|
## field that has a value larger than the number of chains.
|
|
# RUN: yaml2obj --docnum=4 %s -o %t4.3.o -DNBUCKET=0x1 -DNCHAIN=0x5d
|
|
# RUN: llvm-readelf --elf-hash-histogram %t4.3.o 2>&1 | \
|
|
# RUN: FileCheck %s --check-prefix=ERR3 -DFILE=%t4.3.o --implicit-check-not="warning:"
|
|
# ERR3: warning: '[[FILE]]': hash table nchain (93) differs from symbol count derived from SHT_DYNSYM section header (1){{$}}
|
|
|
|
## Case B.2: the hash table ends 1 byte past the EOF. We have a broken nchain
|
|
## field that has a value larger than the number of chains.
|
|
# RUN: yaml2obj --docnum=4 %s -o %t4.4.o -DNBUCKET=0x1 -DNCHAIN=0x5e
|
|
# RUN: llvm-readelf --elf-hash-histogram %t4.4.o 2>&1 | \
|
|
# RUN: FileCheck %s --check-prefix=ERR4 -DFILE=%t4.4.o --implicit-check-not="warning:"
|
|
# ERR4: warning: '[[FILE]]': hash table nchain (94) differs from symbol count derived from SHT_DYNSYM section header (1){{$}}
|
|
# ERR4: warning: '[[FILE]]': the hash table at offset 0x54 goes past the end of the file (0x1d4), nbucket = 1, nchain = 94{{$}}
|
|
|
|
--- !ELF
|
|
FileHeader:
|
|
Class: ELFCLASS32
|
|
Data: ELFDATA2LSB
|
|
Type: ET_DYN
|
|
Machine: EM_X86_64
|
|
Sections:
|
|
- Name: .hash
|
|
Type: SHT_HASH
|
|
Flags: [ SHF_ALLOC ]
|
|
Bucket: [ 0 ]
|
|
NBucket: [[NBUCKET]]
|
|
Chain: [ 0 ]
|
|
NChain: [[NCHAIN]]
|
|
- Name: .dynamic
|
|
Type: SHT_DYNAMIC
|
|
Flags: [ SHF_WRITE, SHF_ALLOC ]
|
|
Entries:
|
|
- Tag: DT_HASH
|
|
Value: 0x0
|
|
- Tag: DT_NULL
|
|
Value: 0x0
|
|
DynamicSymbols: []
|
|
ProgramHeaders:
|
|
- Type: PT_LOAD
|
|
Sections:
|
|
- Section: .hash
|
|
- Section: .dynamic
|