hash-histogram.test
3.5 KB
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
## Here we test the --elf-hash-histogram command line option.
## This test case checks how we built a histogram for a GNU hash section.
## We check both 32-bit and 64-bit inputs.
# RUN: yaml2obj --docnum=1 %s -o %t1-32.o
# RUN: llvm-readelf --elf-hash-histogram %t1-32.o | FileCheck %s --check-prefix=GNU-HASH
# RUN: yaml2obj --docnum=2 %s -o %t1-64.o
# RUN: llvm-readelf --elf-hash-histogram %t1-64.o | FileCheck %s --check-prefix=GNU-HASH
# GNU-HASH: Histogram for `.gnu.hash' bucket list length (total of 3 buckets)
# GNU-HASH-NEXT: Length Number % of total Coverage
# GNU-HASH-NEXT: 0 1 ( 33.3%) 0.0%
# GNU-HASH-NEXT: 1 1 ( 33.3%) 25.0%
# GNU-HASH-NEXT: 2 0 ( 0.0%) 25.0%
# GNU-HASH-NEXT: 3 1 ( 33.3%) 100.0%
--- !ELF
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_386
Sections:
- 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_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
DynamicSymbols:
- Name: a
- Name: b
- Name: c
- Name: d
ProgramHeaders:
- Type: PT_LOAD
Sections:
- Section: .gnu.hash
- Section: .dynamic
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_DYN
Machine: EM_X86_64
Sections:
- 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_GNU_HASH
Value: 0x0
- Tag: DT_NULL
Value: 0x0
DynamicSymbols:
- Name: a
- Name: b
- Name: c
- Name: d
ProgramHeaders:
- Type: PT_LOAD
Sections:
- 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=3 %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