summaryrefslogtreecommitdiffstats
path: root/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
blob: 62d7a975d87210072b2abaecc17cdf4c0f889935 (plain)
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
## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_versym sections.

## Check that we report a warning when sh_link references a non-existent section.

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readelf -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=GNU-INVALID-LINK
# RUN: llvm-readobj -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=LLVM-INVALID-LINK

# GNU-INVALID-LINK:      Version symbols section '.gnu.version' contains 0 entries:
# GNU-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255
# GNU-INVALID-LINK-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 255 (<corrupt>)

# LLVM-INVALID-LINK:      VersionSymbols [
# LLVM-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255
# LLVM-INVALID-LINK-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Link:    0xFF
    Entries: [ ]

## Check that we report a warning when the sh_link field of a SHT_GNU_versym section does not reference
## a dynamic symbol table section.

# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readelf -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-GNU
# RUN: llvm-readobj -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-LLVM

# INVALID-SYMBOL-TABLE-GNU:      Version symbols section '.gnu.version' contains 1 entries:
# INVALID-SYMBOL-TABLE-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 0 ()
# INVALID-SYMBOL-TABLE-GNU-NEXT:  warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: expected SHT_DYNSYM, but got SHT_NULL
# INVALID-SYMBOL-TABLE-GNU-NEXT:  000:   0 (*local*)

# INVALID-SYMBOL-TABLE-LLVM:      VersionSymbols [
# INVALID-SYMBOL-TABLE-LLVM-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: expected SHT_DYNSYM, but got SHT_NULL
# INVALID-SYMBOL-TABLE-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Link:    0x0
    Entries: [ 0 ]

## Check we report a warning when something is wrong with a string table linked to a symbol table that
## is linked with SHT_GNU_versym. In this case we are unable to produce LLVM style output,
## but GNU style is fine because it does not need that string table.

# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readelf -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-GNU
# RUN: llvm-readobj -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-LLVM

# INVALID-STRING-TABLE-GNU:      Version symbols section '.gnu.version' contains 1 entries:
# INVALID-STRING-TABLE-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 5 (.dynsym)
# INVALID-STRING-TABLE-GNU-NEXT:  warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 5: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL
# INVALID-STRING-TABLE-GNU-NEXT:  000:   0 (*local*)

# INVALID-STRING-TABLE-LLVM:      VersionSymbols [
# INVALID-STRING-TABLE-LLVM-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 5: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL
# INVALID-STRING-TABLE-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Link:    .dynsym
    Entries: [ 0 ]
  - Name:    .dynstr
    Type:    SHT_NULL
DynamicSymbols: []

## Check we report a warning when a SHT_GNU_versym section is not correctly aligned in memory.

# RUN: yaml2obj --docnum=4 %s -o %t4
# RUN: llvm-readelf -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-GNU
# RUN: llvm-readobj -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-LLVM

# MISALIGNED-GNU:      Version symbols section '.gnu.version' contains 0 entries:
# MISALIGNED-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x00ffff  Link: 0 ()
# MISALIGNED-GNU-NEXT:  warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned

# MISALIGNED-LLVM:      VersionSymbols [
# MISALIGNED-LLVM-NEXT:  warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned
# MISALIGNED-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Entries: [ ]
    ShOffset: 0xffff

## Check we report a warning when a SHT_GNU_versym section has an invalid entry size.

# RUN: yaml2obj --docnum=5 %s -o %t5
# RUN: llvm-readelf -V %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-GNU
# RUN: llvm-readobj -V %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-LLVM

# INVALID-ENT-SIZE-GNU:      Version symbols section '.gnu.version' contains 1 entries:
# INVALID-ENT-SIZE-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 0 ()
# INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_entsize: 3

# INVALID-ENT-SIZE-LLVM:      VersionSymbols [
# INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_entsize: 3
# INVALID-ENT-SIZE-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Entries: [ 0 ]
    EntSize: 3

## Check we report a warning when the number of version entries does not match the number of symbols in the associated symbol table.

# RUN: yaml2obj --docnum=6 %s -o %t6
# RUN: llvm-readelf -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-GNU
# RUN: llvm-readobj -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-LLVM

# SYMBOLS-NUM-MISMATCH-GNU:      Version symbols section '.gnu.version' contains 2 entries:
# SYMBOLS-NUM-MISMATCH-GNU-NEXT:  Addr: 0000000000000000  Offset: 0x000040  Link: 4 (.dynsym)
# SYMBOLS-NUM-MISMATCH-GNU-NEXT:  warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 4
# SYMBOLS-NUM-MISMATCH-GNU-NEXT:   000:   0 (*local*)       1 (*global*)

# SYMBOLS-NUM-MISMATCH-LLVM:      VersionSymbols [
# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 4
# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Entries: [ 0, 1 ]
    Link:   .dynsym
DynamicSymbols:
  - Name: foo
  - Name: bar

## Check we can dump a SHT_GNU_versym section when it is linked to a custom dynamic symbol
## table that is not called ".dynsym".

# RUN: yaml2obj --docnum=7 %s -o %t7
# RUN: llvm-readelf -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-GNU
# RUN: llvm-readobj -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-LLVM

# CUSTOM-SYMTAB-GNU:      Version symbols section '.gnu.version' contains 1 entries:
# CUSTOM-SYMTAB-GNU-NEXT:   Addr: 0000000000000000  Offset: 0x000040  Link: 2 (.foo.dynsym)
# CUSTOM-SYMTAB-GNU-NEXT:    000:   0 (*local*)

# CUSTOM-SYMTAB-LLVM:      VersionSymbols [
# CUSTOM-SYMTAB-LLVM-NEXT:  Symbol {
# CUSTOM-SYMTAB-LLVM-NEXT:    Version: 0
# CUSTOM-SYMTAB-LLVM-NEXT:    Name:
# CUSTOM-SYMTAB-LLVM-NEXT:  }
# CUSTOM-SYMTAB-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_EXEC
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Link:    .foo.dynsym
    Entries: [ 0 ]
## A custom empty dynamic symbol table with a null entry.
  - Name:    .foo.dynsym
    Type:    SHT_DYNSYM
    Link:    .dynstr
    EntSize: 24
    Size:    24
DynamicSymbols:
  - Name: foo
  - Name: bar

## Version index in a SHT_GNU_versym section overflows the version map.
## Check we report it when trying to dump dynamic symbols.

# RUN: yaml2obj %s --docnum=8 -o %t8
# RUN: llvm-readobj --dyn-syms %t8 2>&1 \
# RUN:   | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-LLVM %s
# RUN: llvm-readelf --dyn-syms %t8 2>&1 \
# RUN:   | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-GNU %s

# VERSION-OVERFLOW-LLVM:      DynamicSymbols [
# VERSION-OVERFLOW-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing
# VERSION-OVERFLOW-LLVM-NEXT:   Symbol {
# VERSION-OVERFLOW-LLVM-NEXT:     Name: @<corrupt> (0)
# VERSION-OVERFLOW-LLVM:      warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 254 which is missing
# VERSION-OVERFLOW-LLVM-NEXT:   Symbol {
# VERSION-OVERFLOW-LLVM-NEXT:     Name: foo@<corrupt> (5)
# VERSION-OVERFLOW-LLVM:        Symbol {
# VERSION-OVERFLOW-LLVM-NEXT:     Name: bar@<corrupt> (1)

# VERSION-OVERFLOW-GNU:      Symbol table '.dynsym' contains 3 entries:
# VERSION-OVERFLOW-GNU-NEXT:  Num:    Value          Size Type    Bind   Vis       Ndx Name
# VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing
# VERSION-OVERFLOW-GNU-NEXT:     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND @<corrupt>
# VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 254 which is missing
# VERSION-OVERFLOW-GNU-NEXT:     1: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND foo@<corrupt>
# VERSION-OVERFLOW-GNU-NEXT:     2: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND bar@<corrupt

--- !ELF
FileHeader:
  Class:   ELFCLASS64
  Data:    ELFDATA2LSB
  Type:    ET_DYN
  Machine: EM_X86_64
Sections:
  - Name:    .gnu.version
    Type:    SHT_GNU_versym
    Entries: [ 0xFF, 0xFE, 0xFF ]
DynamicSymbols:
  - Name: foo
  - Name: bar
OpenPOWER on IntegriCloud