1 ## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_versym sections.
3 ## Check that we report a warning when sh_link references a non-existent section.
5 # RUN: yaml2obj --docnum=1 -DLINK=0xFF %s -o %t1
6 # RUN: llvm-readelf -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=GNU-INVALID-LINK
7 # RUN: llvm-readobj -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=LLVM-INVALID-LINK
9 # GNU-INVALID-LINK: Version symbols section '.gnu.version' contains 1 entries:
10 # GNU-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255
11 # GNU-INVALID-LINK-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 255 (<corrupt>)
13 # LLVM-INVALID-LINK: VersionSymbols [
14 # LLVM-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255
15 # LLVM-INVALID-LINK-NEXT: ]
28 ## Check that we report a warning when the sh_link field of a SHT_GNU_versym section does not reference
29 ## a dynamic symbol table section.
31 # RUN: yaml2obj --docnum=1 -DLINK=0x0 %s -o %t2
32 # RUN: llvm-readelf -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-GNU
33 # RUN: llvm-readobj -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-LLVM
35 # INVALID-SYMBOL-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries:
36 # INVALID-SYMBOL-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 0 ()
37 # 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
38 # INVALID-SYMBOL-TABLE-GNU-NEXT: 000: 0 (*local*)
40 # INVALID-SYMBOL-TABLE-LLVM: VersionSymbols [
41 # 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
42 # INVALID-SYMBOL-TABLE-LLVM-NEXT: ]
44 ## Check we report a warning when something is wrong with a string table linked to a symbol table that
45 ## is linked with SHT_GNU_versym. In this case we are unable to produce LLVM style output,
46 ## but GNU style is fine because it does not need that string table.
48 # RUN: yaml2obj --docnum=2 %s -o %t3
49 # RUN: llvm-readelf -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-GNU
50 # RUN: llvm-readobj -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-LLVM
52 # INVALID-STRING-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries:
53 # INVALID-STRING-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 3 (.dynsym)
54 # 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 3: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL
55 # INVALID-STRING-TABLE-GNU-NEXT: 000: 0 (*local*)
57 # INVALID-STRING-TABLE-LLVM: VersionSymbols [
58 # 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 3: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL
59 # INVALID-STRING-TABLE-LLVM-NEXT: ]
74 ## Check we report a warning when a SHT_GNU_versym section is not correctly aligned in memory.
76 # RUN: yaml2obj --docnum=3 %s -DSHOFFSET=0xffff -o %t4
77 # RUN: llvm-readelf -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-GNU
78 # RUN: llvm-readobj -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-LLVM
80 # MISALIGNED-GNU: Version symbols section '.gnu.version' contains 1 entries:
81 # MISALIGNED-GNU-NEXT: Addr: 0000000000000000 Offset: 0x00ffff Link: 2 (.dynsym)
82 # MISALIGNED-GNU-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned
84 # MISALIGNED-LLVM: VersionSymbols [
85 # MISALIGNED-LLVM-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned
86 # MISALIGNED-LLVM-NEXT: ]
97 ShOffset: [[SHOFFSET=<none>]]
98 ShName: [[SHNAME=<none>]]
101 ShName: [[DYNSYMNAME=<none>]]
104 ## Check that llvm-readelf reports a warning when the name of the SHT_GNU_versym section can't be read.
106 # RUN: yaml2obj %s --docnum=3 -DSHNAME=0xFF -o %t.invalid.name
107 # RUN: llvm-readobj -V %t.invalid.name 2>&1 | \
108 # RUN: FileCheck %s --check-prefix=INVALID-NAME-LLVM -DFILE=%t.invalid.name --implicit-check-not=warning:
109 # RUN: llvm-readelf -V %t.invalid.name 2>&1 | \
110 # RUN: FileCheck %s --check-prefix=INVALID-NAME-GNU -DFILE=%t.invalid.name --implicit-check-not=warning:
112 # INVALID-NAME-LLVM: VersionSymbols [
113 # INVALID-NAME-LLVM-NEXT: Symbol {
114 # INVALID-NAME-LLVM-NEXT: Version: 0
115 # INVALID-NAME-LLVM-NEXT: Name:
116 # INVALID-NAME-LLVM-NEXT: }
117 # INVALID-NAME-LLVM-NEXT: ]
119 # INVALID-NAME-GNU: warning: '[[FILE]]': unable to get the name of SHT_GNU_versym section with index 1: a section [index 1] has an invalid sh_name (0xff) offset which goes past the end of the section name string table
120 # INVALID-NAME-GNU-NEXT: Version symbols section '<?>' contains 1 entries:
121 # INVALID-NAME-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym)
122 # INVALID-NAME-GNU-NEXT: 000: 0 (*local*)
124 ## Check that llvm-readelf reports a warning when we are unable to read the name of
125 ## the section linked with the SHT_GNU_verneed section (usually ".dynsym").
127 # RUN: yaml2obj %s --docnum=3 -DDYNSYMNAME=0xFF -o %t.invalid.name2
128 # RUN: llvm-readobj -V %t.invalid.name2 2>&1 | \
129 # RUN: FileCheck %s --check-prefix=INVALID-NAME-LLVM -DFILE=%t.invalid.name2 --implicit-check-not=warning:
130 # RUN: llvm-readelf -V %t.invalid.name2 2>&1 | \
131 # RUN: FileCheck %s --check-prefix=INVALID-NAME2-GNU -DFILE=%t.invalid.name2 --implicit-check-not=warning:
133 # INVALID-NAME2-GNU: Version symbols section '.gnu.version' contains 1 entries:
134 # INVALID-NAME2-GNU-NEXT: warning: '[[FILE]]': unable to get the name of SHT_DYNSYM section with index 2: a section [index 2] has an invalid sh_name (0xff) offset which goes past the end of the section name string table
135 # INVALID-NAME2-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (<?>)
136 # INVALID-NAME2-GNU-NEXT: 000: 0 (*local*)
138 ## Check we report a warning when a SHT_GNU_versym section has an invalid entry size.
140 # RUN: yaml2obj --docnum=4 %s -o %t5
141 # RUN: llvm-readelf -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-GNU
142 # RUN: llvm-readobj -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-LLVM
144 # INVALID-ENT-SIZE-GNU: Symbol table '.dynsym' contains 2 entries:
145 # INVALID-ENT-SIZE-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
146 # INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3
147 # INVALID-ENT-SIZE-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @<corrupt>
148 # INVALID-ENT-SIZE-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo@<corrupt>
149 # INVALID-ENT-SIZE-GNU: Version symbols section '.gnu.version' contains 1 entries:
150 # INVALID-ENT-SIZE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym)
151 # INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has invalid sh_entsize: expected 2, but got 3
153 # INVALID-ENT-SIZE-LLVM: DynamicSymbols [
154 # INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3
155 # INVALID-ENT-SIZE-LLVM-NEXT: Symbol {
156 # INVALID-ENT-SIZE-LLVM-NEXT: Name: @<corrupt> (0)
157 # INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0
158 # INVALID-ENT-SIZE-LLVM-NEXT: Size: 0
159 # INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0)
160 # INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0)
161 # INVALID-ENT-SIZE-LLVM-NEXT: Other: 0
162 # INVALID-ENT-SIZE-LLVM-NEXT: Section: Undefined (0x0)
163 # INVALID-ENT-SIZE-LLVM-NEXT: }
164 # INVALID-ENT-SIZE-LLVM-NEXT: Symbol {
165 # INVALID-ENT-SIZE-LLVM-NEXT: Name: foo@<corrupt> (1)
166 # INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0
167 # INVALID-ENT-SIZE-LLVM-NEXT: Size: 0
168 # INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0)
169 # INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0)
170 # INVALID-ENT-SIZE-LLVM-NEXT: Other: 0
171 # INVALID-ENT-SIZE-LLVM-NEXT: Section: Undefined (0x0)
172 # INVALID-ENT-SIZE-LLVM-NEXT: }
173 # INVALID-ENT-SIZE-LLVM-NEXT: ]
174 # INVALID-ENT-SIZE-LLVM: VersionSymbols [
175 # INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has invalid sh_entsize: expected 2, but got 3
176 # INVALID-ENT-SIZE-LLVM-NEXT: ]
191 ## Check we report a warning when the number of version entries does not match the number of symbols in the associated symbol table.
193 # RUN: yaml2obj --docnum=5 %s -o %t6
194 # RUN: llvm-readelf -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-GNU
195 # RUN: llvm-readobj -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-LLVM
197 # SYMBOLS-NUM-MISMATCH-GNU: Version symbols section '.gnu.version' contains 2 entries:
198 # SYMBOLS-NUM-MISMATCH-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.dynsym)
199 # 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 2
200 # SYMBOLS-NUM-MISMATCH-GNU-NEXT: 000: 0 (*local*) 1 (*global*)
202 # SYMBOLS-NUM-MISMATCH-LLVM: VersionSymbols [
203 # 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 2
204 # SYMBOLS-NUM-MISMATCH-LLVM-NEXT: ]
219 ## Check we can dump a SHT_GNU_versym section when it is linked to a custom dynamic symbol
220 ## table that is not called ".dynsym".
222 # RUN: yaml2obj --docnum=6 %s -o %t7
223 # RUN: llvm-readelf -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-GNU
224 # RUN: llvm-readobj -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-LLVM
226 # CUSTOM-SYMTAB-GNU: Version symbols section '.gnu.version' contains 1 entries:
227 # CUSTOM-SYMTAB-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.foo.dynsym)
228 # CUSTOM-SYMTAB-GNU-NEXT: 000: 0 (*local*)
230 # CUSTOM-SYMTAB-LLVM: VersionSymbols [
231 # CUSTOM-SYMTAB-LLVM-NEXT: Symbol {
232 # CUSTOM-SYMTAB-LLVM-NEXT: Version: 0
233 # CUSTOM-SYMTAB-LLVM-NEXT: Name:
234 # CUSTOM-SYMTAB-LLVM-NEXT: }
235 # CUSTOM-SYMTAB-LLVM-NEXT: ]
247 ## A custom empty dynamic symbol table with a null entry.
257 ## Version index in a SHT_GNU_versym section overflows the version map.
258 ## Check we report it when trying to dump dynamic symbols.
260 # RUN: yaml2obj %s --docnum=7 -o %t8
261 # RUN: llvm-readobj --dyn-syms %t8 2>&1 \
262 # RUN: | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-LLVM %s
263 # RUN: llvm-readelf --dyn-syms %t8 2>&1 \
264 # RUN: | FileCheck -DFILE=%t8 --implicit-check-not=warning --check-prefix=VERSION-OVERFLOW-GNU %s
266 # VERSION-OVERFLOW-LLVM: DynamicSymbols [
267 # VERSION-OVERFLOW-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing
268 # VERSION-OVERFLOW-LLVM-NEXT: Symbol {
269 # VERSION-OVERFLOW-LLVM-NEXT: Name: @<corrupt> (0)
270 # VERSION-OVERFLOW-LLVM: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 254 which is missing
271 # VERSION-OVERFLOW-LLVM-NEXT: Symbol {
272 # VERSION-OVERFLOW-LLVM-NEXT: Name: foo@<corrupt> (5)
273 # VERSION-OVERFLOW-LLVM: Symbol {
274 # VERSION-OVERFLOW-LLVM-NEXT: Name: bar@<corrupt> (1)
276 # VERSION-OVERFLOW-GNU: Symbol table '.dynsym' contains 3 entries:
277 # VERSION-OVERFLOW-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
278 # VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 255 which is missing
279 # VERSION-OVERFLOW-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @<corrupt>
280 # VERSION-OVERFLOW-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section refers to a version index 254 which is missing
281 # VERSION-OVERFLOW-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo@<corrupt>
282 # VERSION-OVERFLOW-GNU-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND bar@<corrupt
292 Entries: [ 0xFF, 0xFE, 0xFF ]