File: symbol-shndx.test

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (313 lines) | stat: -rw-r--r-- 12,203 bytes parent folder | download | duplicates (19)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
## Show that llvm-readobj prints symbol shndxes correctly, for valid indexes,
## invalid indexes (i.e. section indexes that don't correspond to a real
## section), reserved values and processor/os-specific index values, for both GNU
## and LLVM styles.

# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readobj --symbols %t1 | FileCheck %s --check-prefix=LLVM1
# RUN: llvm-readelf --symbols %t1 | FileCheck %s --check-prefix=GNU1

# LLVM1: Name:    undef
# LLVM1: Section:
# LLVM1-SAME:     Undefined (0x0)
# LLVM1: Name:    normal
# LLVM1: Section:
# LLVM1-SAME:     .text (0x1)
# LLVM1: Name:    common
# LLVM1: Section:
# LLVM1-SAME:     Common (0xFFF2)
# LLVM1: Name:    absolute
# LLVM1: Section:
# LLVM1-SAME:     Absolute (0xFFF1)
# LLVM1: Name:    proc
# LLVM1: Section:
# LLVM1-SAME:     Processor Specific (0xFF01)
# LLVM1: Name:    os
# LLVM1: Section:
# LLVM1-SAME:     Operating System Specific (0xFF21)
# LLVM1: Name:    reserved
# LLVM1: Section:
# LLVM1-SAME:     Reserved (0xFFFE)
# LLVM1: Name:    xindex
# LLVM1: Section:
# LLVM1:          .text (0x1)

# GNU1:      Symbol table '.symtab' contains 9 entries:
# GNU1-NEXT:   Num: {{.*}} Ndx Name
# GNU1-NEXT:     0: {{.*}} UND
# GNU1-NEXT:     1: {{.*}} UND undef
# GNU1-NEXT:     2: {{.*}}   1 normal
# GNU1-NEXT:     3: {{.*}} COM common
# GNU1-NEXT:     4: {{.*}} ABS absolute
# GNU1-NEXT:     5: {{.*}} PRC[0xff01] proc
# GNU1-NEXT:     6: {{.*}} OS[0xff21] os
# GNU1-NEXT:     7: {{.*}} RSV[0xfffe] reserved
# GNU1-NEXT:     8: {{.*}}   1 xindex

--- !ELF
FileHeader:
  Class: ELFCLASS32
  Data:  ELFDATA2LSB
  Type:  ET_REL
Sections:
  - Name: .text
    Type: SHT_PROGBITS
  - Name: .symtab_shndx
    Type: SHT_SYMTAB_SHNDX
    Link: .symtab
    Entries: [ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
Symbols:
  - Name:    [[NAME=undef]]
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=normal]]
    Section: .text
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=common]]
    Index:   SHN_COMMON
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=absolute]]
    Index:   SHN_ABS
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=proc]]
    Index:   0xff01
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=os]]
    Index:   0xff21
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=reserved]]
    Index:   0xfffe
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]
  - Name:    [[NAME=xindex]]
    Index:   SHN_XINDEX
    Binding: STB_GLOBAL
    Type:    [[TYPE=STT_NOTYPE]]

## Check the behavior for section symbols.
# RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION %s -o %t1-sec
# RUN: llvm-readobj --symbols %t1-sec | FileCheck %s --check-prefix=LLVM1
# RUN: llvm-readelf --symbols %t1-sec | FileCheck %s --check-prefix=GNU1

## Check the behavior for unnamed section symbols.
# RUN: yaml2obj --docnum=1 -DTYPE=STT_SECTION -DNAME="''" %s -o %t1-sec-unnamed
# RUN: llvm-readobj --symbols %t1-sec-unnamed 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=LLVM1-SEC-SYMS
# RUN: llvm-readelf --symbols %t1-sec-unnamed 2>&1 | \
# RUN:   FileCheck %s -DFILE=%t1-sec-unnamed --check-prefix=GNU1-SEC-SYMS

# LLVM1-SEC-SYMS:      Symbols [
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name:  (0)
# LLVM1-SEC-SYMS:          Section: Undefined (0x0)
# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)
# LLVM1-SEC-SYMS:          Section: Undefined (0x0)
# LLVM1-SEC-SYMS:        Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: .text (0)
# LLVM1-SEC-SYMS:          Section: .text (0x1)
# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)
# LLVM1-SEC-SYMS:          Section: Common (0xFFF2)
# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)
# LLVM1-SEC-SYMS:          Section: Absolute (0xFFF1)
# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff01 (SHN_LOPROC+0x1)
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)
# LLVM1-SEC-SYMS:          Section: Processor Specific (0xFF01)
# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff21 (SHN_LOOS+0x1)
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)
# LLVM1-SEC-SYMS:          Section: Operating System Specific (0xFF21)
# LLVM1-SEC-SYMS: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfffe (SHN_LORESERVE+0xfe)
# LLVM1-SEC-SYMS-NEXT:   Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: <?> (0)
# LLVM1-SEC-SYMS:          Section: Reserved (0xFFFE)
# LLVM1-SEC-SYMS:        Symbol {
# LLVM1-SEC-SYMS-NEXT:     Name: .text (0)
# LLVM1-SEC-SYMS:          Section: .text (0x1)

# GNU1-SEC-SYMS:      Num: {{.*}} Ndx Name
# GNU1-SEC-SYMS-NEXT:   0: {{.*}} UND {{$}}
# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
# GNU1-SEC-SYMS-NEXT:   1: {{.*}} UND <?>
# GNU1-SEC-SYMS-NEXT:   2: {{.*}}   1 .text
# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff2 (SHN_COMMON)
# GNU1-SEC-SYMS-NEXT:   3: {{.*}} COM <?>
# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfff1 (SHN_ABS)
# GNU1-SEC-SYMS-NEXT:   4: {{.*}} ABS <?>
# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff01 (SHN_LOPROC+0x1)
# GNU1-SEC-SYMS-NEXT:   5: {{.*}} PRC[0xff01] <?>
# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xff21 (SHN_LOOS+0x1)
# GNU1-SEC-SYMS-NEXT:   6: {{.*}} OS[0xff21] <?>
# GNU1-SEC-SYMS-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0xfffe (SHN_LORESERVE+0xfe)
# GNU1-SEC-SYMS-NEXT:   7: {{.*}} RSV[0xfffe] <?>
# GNU1-SEC-SYMS-NEXT:   8: {{.*}}   1 .text

## In this case, the index does not correspond to a real section. Check that GNU
## style just prints the section index as normal and LLVM style prints a warning
## (but only once for each warning).
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-readobj --symbols %t2 2> %t2.llvm.err | FileCheck %s --check-prefix=LLVM2
# RUN: FileCheck %s --input-file=%t2.llvm.err --check-prefix=BAD-SHNDX --implicit-check-not=warning
# RUN: llvm-readelf --symbols %t2 2> %t2.gnu.err | FileCheck %s --check-prefix=GNU2
# RUN: FileCheck %s --input-file=%t2.gnu.err --allow-empty --implicit-check-not={{.}}

# LLVM2: Name: bad
# LLVM2: Section:
# LLVM2-SAME:     <?> (0x42)
# LLVM2: Name: bad2
# LLVM2: Section:
# LLVM2-SAME:     <?> (0x42)
# LLVM2: Name: bad3
# LLVM2: Section:
# LLVM2-SAME:     <?> (0x43)
# LLVM2: Name: invalid_shndx
# LLVM2: Section:
# LLVM2-SAME:     <?> (0x9)
# LLVM2: Name: invalid_shndx2
# LLVM2: Section:
# LLVM2-SAME:     <?> (0x9)
# LLVM2: Name: invalid_shndx3
# LLVM2: Section:
# LLVM2-SAME:     <?> (0xA)

# GNU2:      Symbol table '.symtab' contains 7 entries:
# GNU2-NEXT:   Num: {{.*}} Ndx Name
# GNU2-NEXT:     0: {{.*}} UND
# GNU2-NEXT:     1: {{.*}}  66 bad
# GNU2-NEXT:     2: {{.*}}  66 bad2
# GNU2-NEXT:     3: {{.*}}  67 bad3
# GNU2-NEXT:     4: {{.*}}   9 invalid_shndx
# GNU2-NEXT:     5: {{.*}}   9 invalid_shndx2
# GNU2-NEXT:     6: {{.*}}  10 invalid_shndx3

# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 66
# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 67
# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 9
# BAD-SHNDX: warning: '{{.*}}tmp2': invalid section index: 10

--- !ELF
FileHeader:
  Class: ELFCLASS32
  Data:  ELFDATA2LSB
  Type:  ET_REL
Sections:
  - Name: .symtab_shndx
    Type: SHT_SYMTAB_SHNDX
    Link: .symtab
    Entries: [ 0, 0, 0, 0, 9, 9, 10 ]
Symbols:
  - Name:    bad
    Index:   0x42
  - Name:    bad2
    Index:   0x42
  - Name:    bad3
    Index:   0x43
  - Name:    invalid_shndx
    Index:   SHN_XINDEX
  - Name:    invalid_shndx2
    Index:   SHN_XINDEX
  - Name:    invalid_shndx3
    Index:   SHN_XINDEX

## In this case, the symtab shndx section is missing, so symbols with section
## indexes of SHN_XINDEX print as Reserved symbols.
# RUN: yaml2obj --docnum=3 %s -o %t3
# RUN: llvm-readobj --symbols %t3 2> %t3.llvm.err | FileCheck %s --check-prefix=LLVM3
# RUN: FileCheck %s --input-file=%t3.llvm.err --check-prefix=NO-SYMTAB-SHNDX --implicit-check-not=warning
# RUN: llvm-readelf --symbols %t3 2> %t3.gnu.err | FileCheck %s --check-prefix=GNU3
# RUN: FileCheck %s --input-file=%t3.gnu.err --check-prefix=NO-SYMTAB-SHNDX --implicit-check-not=warning

# LLVM3: Name: no_shndx
# LLVM3: Section:
# LLVM3-SAME:     Reserved (0xFFFF)
# LLVM3: Name: no_shndx2
# LLVM3: Section:
# LLVM3-SAME:     Reserved (0xFFFF)

# GNU3:      Symbol table '.symtab' contains 3 entries:
# GNU3-NEXT:   Num: {{.*}} Ndx Name
# GNU3-NEXT:     0: {{.*}} UND
# GNU3-NEXT:     1: {{.*}} RSV[0xffff] no_shndx
# GNU3-NEXT:     2: {{.*}} RSV[0xffff] no_shndx2

# NO-SYMTAB-SHNDX: warning: '{{.*}}tmp3': found an extended symbol index (1), but unable to locate the extended symbol index table
# NO-SYMTAB-SHNDX: warning: '{{.*}}tmp3': found an extended symbol index (2), but unable to locate the extended symbol index table

--- !ELF
FileHeader:
  Class: ELFCLASS32
  Data:  ELFDATA2LSB
  Type:  ET_REL
Symbols:
  - Name:  no_shndx
    Index: SHN_XINDEX
  - Name:  no_shndx2
    Index: SHN_XINDEX

## Check we can dump symbols even when the number of entries in the
## SHT_SYMTAB_SHNDX section doesn't match the number of symbols in the symbol table.

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

#       SHNDX-ERR-GNU: warning: '[[FILE]]': SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2
# SHNDX-ERR-GNU-EMPTY:
#  SHNDX-ERR-GNU-NEXT: Symbol table '.symtab' contains 2 entries:
#  SHNDX-ERR-GNU-NEXT:    Num:    Value          Size Type    Bind   Vis       Ndx Name
#  SHNDX-ERR-GNU-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND
#  SHNDX-ERR-GNU-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
#  SHNDX-ERR-GNU-NEXT:      1: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   RSV[0xffff]
# SHNDX-ERR-GNU-EMPTY:
#   SHNDX-ERR-GNU-NOT:{{.}}

# SHNDX-ERR-LLVM: warning: '[[FILE]]': SHT_SYMTAB_SHNDX has 3 entries, but the symbol table associated has 2
# SHNDX-ERR-LLVM:      Format: elf64-unknown
# SHNDX-ERR-LLVM-NEXT: Arch: unknown
# SHNDX-ERR-LLVM-NEXT: AddressSize: 64bit
# SHNDX-ERR-LLVM-NEXT: LoadName: <Not found>
# SHNDX-ERR-LLVM-NEXT: Symbols [
# SHNDX-ERR-LLVM-NEXT:   Symbol {
# SHNDX-ERR-LLVM-NEXT:     Name:  (0)
# SHNDX-ERR-LLVM-NEXT:     Value: 0x0
# SHNDX-ERR-LLVM-NEXT:     Size: 0
# SHNDX-ERR-LLVM-NEXT:     Binding: Local (0x0)
# SHNDX-ERR-LLVM-NEXT:     Type: None (0x0)
# SHNDX-ERR-LLVM-NEXT:     Other: 0
# SHNDX-ERR-LLVM-NEXT:     Section: Undefined (0x0)
# SHNDX-ERR-LLVM-NEXT:   }
# SHNDX-ERR-LLVM-NEXT:   Symbol {
# SHNDX-ERR-LLVM-NEXT:     Name:  (0)
# SHNDX-ERR-LLVM-NEXT:     Value: 0x0
# SHNDX-ERR-LLVM-NEXT:     Size: 0
# SHNDX-ERR-LLVM-NEXT:     Binding: Local (0x0)
# SHNDX-ERR-LLVM-NEXT:     Type: None (0x0)
# SHNDX-ERR-LLVM-NEXT:     Other: 0
# SHNDX-ERR-LLVM-NEXT: warning: '[[FILE]]': found an extended symbol index (1), but unable to locate the extended symbol index table
# SHNDX-ERR-LLVM-NEXT:     Section: Reserved (0xFFFF)
# SHNDX-ERR-LLVM-NEXT:   }
# SHNDX-ERR-LLVM-NEXT: ]

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_REL
Sections:
  - Name:    .symtab_shndx
    Type:    SHT_SYMTAB_SHNDX
    Entries: [ 0, 1, 2 ]
    Link:    .symtab
Symbols:
  - Index: SHN_XINDEX