1 ## Show that llvm-readobj prints symbol shndxes correctly, for valid indexes,
2 ## invalid indexes (i.e. section indexes that don't correspond to a real
3 ## section), reserved values and processor/os-specific index values, for both GNU
6 # RUN: yaml2obj --docnum=1 %s -o %t1
7 # RUN: llvm-readobj --symbols %t1 | FileCheck %s --check-prefix=LLVM1
8 # RUN: llvm-readelf --symbols %t1 | FileCheck %s --check-prefix=GNU1
12 # LLVM1-SAME: Undefined (0x0)
15 # LLVM1-SAME: .text (0x1)
18 # LLVM1-SAME: Common (0xFFF2)
19 # LLVM1: Name: absolute
21 # LLVM1-SAME: Absolute (0xFFF1)
24 # LLVM1-SAME: Processor Specific (0xFF01)
27 # LLVM1-SAME: Operating System Specific (0xFF21)
28 # LLVM1: Name: reserved
30 # LLVM1-SAME: Reserved (0xFFFE)
35 # GNU1: Symbol table '.symtab' contains 9 entries:
36 # GNU1-NEXT: Num: {{.*}} Ndx Name
37 # GNU1-NEXT: 0: {{.*}} UND
38 # GNU1-NEXT: 1: {{.*}} UND undef
39 # GNU1-NEXT: 2: {{.*}} 1 normal
40 # GNU1-NEXT: 3: {{.*}} COM common
41 # GNU1-NEXT: 4: {{.*}} ABS absolute
42 # GNU1-NEXT: 5: {{.*}} PRC[0xff01] proc
43 # GNU1-NEXT: 6: {{.*}} OS[0xff21] os
44 # GNU1-NEXT: 7: {{.*}} RSV[0xfffe] reserved
45 # GNU1-NEXT: 8: {{.*}} 1 xindex
56 Type: SHT_SYMTAB_SHNDX
58 Entries: [ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
60 - Name: [[NAME=undef]]
62 Type: [[TYPE=STT_NOTYPE]]
63 - Name: [[NAME=normal]]
66 Type: [[TYPE=STT_NOTYPE]]
67 - Name: [[NAME=common]]
70 Type: [[TYPE=STT_NOTYPE]]
71 - Name: [[NAME=absolute]]
74 Type: [[TYPE=STT_NOTYPE]]
78 Type: [[TYPE=STT_NOTYPE]]
82 Type: [[TYPE=STT_NOTYPE]]
83 - Name: [[NAME=reserved]]
86 Type: [[TYPE=STT_NOTYPE]]
87 - Name: [[NAME=xindex]]
90 Type: [[TYPE=STT_NOTYPE]]
92 ## Check the behavior for section symbols.
93 # RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION %s -o %t1-sec
94 # RUN: llvm-readobj --symbols %t1-sec | FileCheck %s --check-prefix=LLVM1
95 # RUN: llvm-readelf --symbols %t1-sec | FileCheck %s --check-prefix=GNU1
97 ## Check the behavior for unnamed section symbols.
98 # RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION -DNAME="''" %s -o %t1-sec-unnamed
99 # RUN: llvm-readobj --symbols %t1-sec-unnamed 2>&1 | \
100 # RUN: FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=LLVM1-SEC-SYMS
101 # RUN: llvm-readelf --symbols %t1-sec-unnamed 2>&1 | \
102 # RUN: FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=GNU1-SEC-SYMS
104 # LLVM1-SEC-SYMS: Symbols [
105 # LLVM1-SEC-SYMS-NEXT: Symbol {
106 # LLVM1-SEC-SYMS-NEXT: Name: (0)
107 # LLVM1-SEC-SYMS: Section: Undefined (0x0)
108 # LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
109 # LLVM1-SEC-SYMS-NEXT: Symbol {
110 # LLVM1-SEC-SYMS-NEXT: Name: <?> (0)
111 # LLVM1-SEC-SYMS: Section: Undefined (0x0)
112 # LLVM1-SEC-SYMS: Symbol {
113 # LLVM1-SEC-SYMS-NEXT: Name: .text (0)
114 # LLVM1-SEC-SYMS: Section: .text (0x1)
115 # LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
116 # LLVM1-SEC-SYMS-NEXT: Symbol {
117 # LLVM1-SEC-SYMS-NEXT: Name: <?> (0)
118 # LLVM1-SEC-SYMS: Section: Common (0xFFF2)
119 # LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
120 # LLVM1-SEC-SYMS-NEXT: Symbol {
121 # LLVM1-SEC-SYMS-NEXT: Name: <?> (0)
122 # LLVM1-SEC-SYMS: Section: Absolute (0xFFF1)
123 # LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff01 (SHN_LOPROC+0x1)
124 # LLVM1-SEC-SYMS-NEXT: Symbol {
125 # LLVM1-SEC-SYMS-NEXT: Name: <?> (0)
126 # LLVM1-SEC-SYMS: Section: Processor Specific (0xFF01)
127 # LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff21 (SHN_LOOS+0x1)
128 # LLVM1-SEC-SYMS-NEXT: Symbol {
129 # LLVM1-SEC-SYMS-NEXT: Name: <?> (0)
130 # LLVM1-SEC-SYMS: Section: Operating System Specific (0xFF21)
131 # LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfffe (SHN_LORESERVE+0xfe)
132 # LLVM1-SEC-SYMS-NEXT: Symbol {
133 # LLVM1-SEC-SYMS-NEXT: Name: <?> (0)
134 # LLVM1-SEC-SYMS: Section: Reserved (0xFFFE)
135 # LLVM1-SEC-SYMS: Symbol {
136 # LLVM1-SEC-SYMS-NEXT: Name: .text (0)
137 # LLVM1-SEC-SYMS: Section: .text (0x1)
139 # GNU1-SEC-SYMS: Num: {{.*}} Ndx Name
140 # GNU1-SEC-SYMS-NEXT: 0: {{.*}} UND {{$}}
141 # GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
142 # GNU1-SEC-SYMS-NEXT: 1: {{.*}} UND <?>
143 # GNU1-SEC-SYMS-NEXT: 2: {{.*}} 1 .text
144 # GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
145 # GNU1-SEC-SYMS-NEXT: 3: {{.*}} COM <?>
146 # GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
147 # GNU1-SEC-SYMS-NEXT: 4: {{.*}} ABS <?>
148 # GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff01 (SHN_LOPROC+0x1)
149 # GNU1-SEC-SYMS-NEXT: 5: {{.*}} PRC[0xff01] <?>
150 # GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff21 (SHN_LOOS+0x1)
151 # GNU1-SEC-SYMS-NEXT: 6: {{.*}} OS[0xff21] <?>
152 # GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfffe (SHN_LORESERVE+0xfe)
153 # GNU1-SEC-SYMS-NEXT: 7: {{.*}} RSV[0xfffe] <?>
154 # GNU1-SEC-SYMS-NEXT: 8: {{.*}} 1 .text
156 ## In this case, the index does not correspond to a real section. Check that GNU
157 ## style just prints the section index as normal and LLVM style prints a warning
158 ## (but only once for each warning).
159 # RUN: yaml2obj --docnum=2 %s -o %t2
160 # RUN: llvm-readobj --symbols %t2 2> %t2.llvm.err | FileCheck %s --check-prefix=LLVM2
161 # RUN: FileCheck %s --input-file=%t2.llvm.err --check-prefix=BAD-SHNDX --implicit-check-not=warning
162 # RUN: llvm-readelf --symbols %t2 2> %t2.gnu.err | FileCheck %s --check-prefix=GNU2
163 # RUN: FileCheck %s --input-file=%t2.gnu.err --allow-empty --implicit-check-not={{.}}
167 # LLVM2-SAME: <?> (0x42)
170 # LLVM2-SAME: <?> (0x42)
173 # LLVM2-SAME: <?> (0x43)
174 # LLVM2: Name: invalid_shndx
176 # LLVM2-SAME: <?> (0x9)
177 # LLVM2: Name: invalid_shndx2
179 # LLVM2-SAME: <?> (0x9)
180 # LLVM2: Name: invalid_shndx3
182 # LLVM2-SAME: <?> (0xA)
184 # GNU2: Symbol table '.symtab' contains 7 entries:
185 # GNU2-NEXT: Num: {{.*}} Ndx Name
186 # GNU2-NEXT: 0: {{.*}} UND
187 # GNU2-NEXT: 1: {{.*}} 66 bad
188 # GNU2-NEXT: 2: {{.*}} 66 bad2
189 # GNU2-NEXT: 3: {{.*}} 67 bad3
190 # GNU2-NEXT: 4: {{.*}} 9 invalid_shndx
191 # GNU2-NEXT: 5: {{.*}} 9 invalid_shndx2
192 # GNU2-NEXT: 6: {{.*}} 10 invalid_shndx3
194 # BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 66
195 # BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 67
196 # BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 9
197 # BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 10
205 - Name: .symtab_shndx
206 Type: SHT_SYMTAB_SHNDX
208 Entries: [ 0, 0, 0, 0, 9, 9, 10 ]
216 - Name: invalid_shndx
218 - Name: invalid_shndx2
220 - Name: invalid_shndx3
223 ## In this case, the symtab shndx section is missing, so symbols with section
224 ## indexes of SHN_XINDEX print as Reserved symbols.
225 # RUN: yaml2obj --docnum=3 %s -o %t3
226 # RUN: llvm-readobj --symbols %t3 2> %t3.llvm.err | FileCheck %s --check-prefix=LLVM3
227 # RUN: FileCheck %s --input-file=%t3.llvm.err --check-prefix=NO-SYMTAB-SHNDX --implicit-check-not=warning
228 # RUN: llvm-readelf --symbols %t3 2> %t3.gnu.err | FileCheck %s --check-prefix=GNU3
229 # RUN: FileCheck %s --input-file=%t3.gnu.err --check-prefix=NO-SYMTAB-SHNDX --implicit-check-not=warning
231 # LLVM3: Name: no_shndx
233 # LLVM3-SAME: Reserved (0xFFFF)
234 # LLVM3: Name: no_shndx2
236 # LLVM3-SAME: Reserved (0xFFFF)
238 # GNU3: Symbol table '.symtab' contains 3 entries:
239 # GNU3-NEXT: Num: {{.*}} Ndx Name
240 # GNU3-NEXT: 0: {{.*}} UND
241 # GNU3-NEXT: 1: {{.*}} RSV[0xffff] no_shndx
242 # GNU3-NEXT: 2: {{.*}} RSV[0xffff] no_shndx2
244 # NO-SYMTAB-SHNDX: warning: '{{.*}}tmp3': found an extended symbol index (1), but unable to locate the extended symbol index table
245 # NO-SYMTAB-SHNDX: warning: '{{.*}}tmp3': found an extended symbol index (2), but unable to locate the extended symbol index table
258 ## Check we can dump symbols even when the number of entries in the
259 ## SHT_SYMTAB_SHNDX section doesn't match the number of symbols in the symbol table.
261 # RUN: yaml2obj --docnum=4 %s -o %t4
262 # RUN: llvm-readelf --symbols %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=SHNDX-ERR-GNU
263 # RUN: llvm-readobj --symbols %t4 2>&1 | FileCheck %s -DFILE=%t4 --check-prefix=SHNDX-ERR-LLVM
265 # SHNDX-ERR-GNU: warning: '[[FILE]]': SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2
266 # SHNDX-ERR-GNU-EMPTY:
267 # SHNDX-ERR-GNU-NEXT: Symbol table '.symtab' contains 2 entries:
268 # SHNDX-ERR-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
269 # SHNDX-ERR-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
270 # SHNDX-ERR-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
271 # SHNDX-ERR-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT RSV[0xffff]
272 # SHNDX-ERR-GNU-EMPTY:
273 # SHNDX-ERR-GNU-NOT:{{.}}
275 # SHNDX-ERR-LLVM: warning: '[[FILE]]': SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2
276 # SHNDX-ERR-LLVM: Format: elf64-unknown
277 # SHNDX-ERR-LLVM-NEXT: Arch: unknown
278 # SHNDX-ERR-LLVM-NEXT: AddressSize: 64bit
279 # SHNDX-ERR-LLVM-NEXT: LoadName: <Not found>
280 # SHNDX-ERR-LLVM-NEXT: Symbols [
281 # SHNDX-ERR-LLVM-NEXT: Symbol {
282 # SHNDX-ERR-LLVM-NEXT: Name: (0)
283 # SHNDX-ERR-LLVM-NEXT: Value: 0x0
284 # SHNDX-ERR-LLVM-NEXT: Size: 0
285 # SHNDX-ERR-LLVM-NEXT: Binding: Local (0x0)
286 # SHNDX-ERR-LLVM-NEXT: Type: None (0x0)
287 # SHNDX-ERR-LLVM-NEXT: Other: 0
288 # SHNDX-ERR-LLVM-NEXT: Section: Undefined (0x0)
289 # SHNDX-ERR-LLVM-NEXT: }
290 # SHNDX-ERR-LLVM-NEXT: Symbol {
291 # SHNDX-ERR-LLVM-NEXT: Name: (0)
292 # SHNDX-ERR-LLVM-NEXT: Value: 0x0
293 # SHNDX-ERR-LLVM-NEXT: Size: 0
294 # SHNDX-ERR-LLVM-NEXT: Binding: Local (0x0)
295 # SHNDX-ERR-LLVM-NEXT: Type: None (0x0)
296 # SHNDX-ERR-LLVM-NEXT: Other: 0
297 # SHNDX-ERR-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
298 # SHNDX-ERR-LLVM-NEXT: Section: Reserved (0xFFFF)
299 # SHNDX-ERR-LLVM-NEXT: }
300 # SHNDX-ERR-LLVM-NEXT: ]
308 - Name: .symtab_shndx
309 Type: SHT_SYMTAB_SHNDX