1 ## Check llvm-readobj and llvm-readelf print relocations as expected.
3 ## Show that ELF64 is dumped correctly.
4 # RUN: yaml2obj %s --docnum=1 -o %t64
5 # RUN: llvm-readobj -r %t64 \
6 # RUN: | FileCheck %s --check-prefix=LLVM-64 --strict-whitespace --match-full-lines
7 # RUN: llvm-readobj --relocs %t64 \
8 # RUN: | FileCheck %s --check-prefix=LLVM-64 --strict-whitespace --match-full-lines
9 # RUN: llvm-readobj --relocations %t64 \
10 # RUN: | FileCheck %s --check-prefix=LLVM-64 --strict-whitespace --match-full-lines
12 # LLVM-64:Relocations [
13 # LLVM-64-NEXT: Section (2) .rel.text {
14 # LLVM-64-NEXT: 0x0 R_X86_64_NONE rel_0
15 # LLVM-64-NEXT: 0x1 R_X86_64_PC32 rel_neg
16 # LLVM-64-NEXT: 0x5 R_X86_64_PLT32 rel_pos
17 # LLVM-64-NEXT: 0x9 R_X86_64_64 rel_64
19 # LLVM-64-NEXT: Section (3) .rela.text {
20 # LLVM-64-NEXT: 0x0 R_X86_64_NONE rela_0 0x0
21 # LLVM-64-NEXT: 0x1 R_X86_64_PC32 rela_neg 0xFFFFFFFFFFFFFFFF
22 # LLVM-64-NEXT: 0x5 R_X86_64_PLT32 rela_pos 0x2
23 # LLVM-64-NEXT: 0xFFFFFFFFFFFFFFFF R_X86_64_64 rela_minneg 0x8000000000000000
24 # LLVM-64-NEXT: 0x9 R_X86_64_32S rela_maxpos 0x7FFFFFFFFFFFFFFF
28 # RUN: llvm-readelf -r %t64 \
29 # RUN: | FileCheck %s --check-prefix=GNU-64 --strict-whitespace --match-full-lines
30 # RUN: llvm-readelf --relocs %t64 \
31 # RUN: | FileCheck %s --check-prefix=GNU-64 --strict-whitespace --match-full-lines
32 # RUN: llvm-readelf --relocations %t64 \
33 # RUN: | FileCheck %s --check-prefix=GNU-64 --strict-whitespace --match-full-lines
35 # GNU-64:Relocation section '.rel.text' at offset 0x51 contains 4 entries:
36 # GNU-64-NEXT: Offset Info Type Symbol's Value Symbol's Name
37 # GNU-64-NEXT:0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 rel_0
38 # GNU-64-NEXT:0000000000000001 0000000200000002 R_X86_64_PC32 0000000000000001 rel_neg
39 # GNU-64-NEXT:0000000000000005 0000000300000004 R_X86_64_PLT32 0000000000000002 rel_pos
40 # GNU-64-NEXT:0000000000000009 0000000400000001 R_X86_64_64 ffffffffffffffff rel_64
42 # GNU-64-NEXT:Relocation section '.rela.text' at offset 0x91 contains 5 entries:
43 # GNU-64-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
44 # GNU-64-NEXT:0000000000000000 0000000500000000 R_X86_64_NONE 0000000000000000 rela_0 + 0
45 # GNU-64-NEXT:0000000000000001 0000000600000002 R_X86_64_PC32 0000000000000001 rela_neg - 1
46 # GNU-64-NEXT:0000000000000005 0000000700000004 R_X86_64_PLT32 0000000000000002 rela_pos + 2
47 # GNU-64-NEXT:ffffffffffffffff 0000000800000001 R_X86_64_64 0000000000000003 rela_minneg - 8000000000000000
48 # GNU-64-NEXT:0000000000000009 000000090000000b R_X86_64_32S ffffffffffffffff rela_maxpos + 7fffffffffffffff
50 ## Show that --expand-relocs expands the relocation dump for LLVM style and not GNU.
51 # RUN: llvm-readobj -r --expand-relocs %t64 \
52 # RUN: | FileCheck %s --check-prefix=LLVM-EXPAND-64 --match-full-lines --strict-whitespace
53 # RUN: llvm-readelf -r --expand-relocs %t64 \
54 # RUN: | FileCheck %s --check-prefix=GNU-64 --match-full-lines --strict-whitespace
56 # LLVM-EXPAND-64:Relocations [
57 # LLVM-EXPAND-64-NEXT: Section (2) .rel.text {
58 # LLVM-EXPAND-64-NEXT: Relocation {
59 # LLVM-EXPAND-64-NEXT: Offset: 0x0
60 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_NONE (0)
61 # LLVM-EXPAND-64-NEXT: Symbol: rel_0 (1)
62 # LLVM-EXPAND-64-NEXT: }
63 # LLVM-EXPAND-64-NEXT: Relocation {
64 # LLVM-EXPAND-64-NEXT: Offset: 0x1
65 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_PC32 (2)
66 # LLVM-EXPAND-64-NEXT: Symbol: rel_neg (2)
67 # LLVM-EXPAND-64-NEXT: }
68 # LLVM-EXPAND-64-NEXT: Relocation {
69 # LLVM-EXPAND-64-NEXT: Offset: 0x5
70 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_PLT32 (4)
71 # LLVM-EXPAND-64-NEXT: Symbol: rel_pos (3)
72 # LLVM-EXPAND-64-NEXT: }
73 # LLVM-EXPAND-64-NEXT: Relocation {
74 # LLVM-EXPAND-64-NEXT: Offset: 0x9
75 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_64 (1)
76 # LLVM-EXPAND-64-NEXT: Symbol: rel_64 (4)
77 # LLVM-EXPAND-64-NEXT: }
78 # LLVM-EXPAND-64-NEXT: }
79 # LLVM-EXPAND-64-NEXT: Section (3) .rela.text {
80 # LLVM-EXPAND-64-NEXT: Relocation {
81 # LLVM-EXPAND-64-NEXT: Offset: 0x0
82 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_NONE (0)
83 # LLVM-EXPAND-64-NEXT: Symbol: rela_0 (5)
84 # LLVM-EXPAND-64-NEXT: Addend: 0x0
85 # LLVM-EXPAND-64-NEXT: }
86 # LLVM-EXPAND-64-NEXT: Relocation {
87 # LLVM-EXPAND-64-NEXT: Offset: 0x1
88 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_PC32 (2)
89 # LLVM-EXPAND-64-NEXT: Symbol: rela_neg (6)
90 # LLVM-EXPAND-64-NEXT: Addend: 0xFFFFFFFFFFFFFFFF
91 # LLVM-EXPAND-64-NEXT: }
92 # LLVM-EXPAND-64-NEXT: Relocation {
93 # LLVM-EXPAND-64-NEXT: Offset: 0x5
94 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_PLT32 (4)
95 # LLVM-EXPAND-64-NEXT: Symbol: rela_pos (7)
96 # LLVM-EXPAND-64-NEXT: Addend: 0x2
97 # LLVM-EXPAND-64-NEXT: }
98 # LLVM-EXPAND-64-NEXT: Relocation {
99 # LLVM-EXPAND-64-NEXT: Offset: 0xFFFFFFFFFFFFFFFF
100 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_64 (1)
101 # LLVM-EXPAND-64-NEXT: Symbol: rela_minneg (8)
102 # LLVM-EXPAND-64-NEXT: Addend: 0x8000000000000000
103 # LLVM-EXPAND-64-NEXT: }
104 # LLVM-EXPAND-64-NEXT: Relocation {
105 # LLVM-EXPAND-64-NEXT: Offset: 0x9
106 # LLVM-EXPAND-64-NEXT: Type: R_X86_64_32S (11)
107 # LLVM-EXPAND-64-NEXT: Symbol: rela_maxpos (9)
108 # LLVM-EXPAND-64-NEXT: Addend: 0x7FFFFFFFFFFFFFFF
109 # LLVM-EXPAND-64-NEXT: }
110 # LLVM-EXPAND-64-NEXT: }
111 # LLVM-EXPAND-64-NEXT:]
113 ## Show that JSON relocations are always expanded.
114 # RUN: llvm-readobj -r %t64 --elf-output-style=JSON --pretty-print \
115 # RUN: | FileCheck %s --check-prefix=JSON-EXPAND-64
116 # RUN: llvm-readobj -r --expand-relocs %t64 --elf-output-style=JSON --pretty-print \
117 # RUN: | FileCheck %s --check-prefix=JSON-EXPAND-64
119 # JSON-EXPAND-64: "Relocations": [
120 # JSON-EXPAND-64-NEXT: {
121 # JSON-EXPAND-64-NEXT: "SectionIndex": 2
122 # JSON-EXPAND-64-NEXT: "Relocs": [
123 # JSON-EXPAND-64-NEXT: {
124 # JSON-EXPAND-64-NEXT: "Relocation": {
125 # JSON-EXPAND-64-NEXT: "Offset": 0,
126 # JSON-EXPAND-64-NEXT: "Type": {
127 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_NONE",
128 # JSON-EXPAND-64-NEXT: "Value": 0
129 # JSON-EXPAND-64-NEXT: },
130 # JSON-EXPAND-64-NEXT: "Symbol": {
131 # JSON-EXPAND-64-NEXT: "Name": "rel_0",
132 # JSON-EXPAND-64-NEXT: "Value": 1
133 # JSON-EXPAND-64-NEXT: }
134 # JSON-EXPAND-64-NEXT: }
135 # JSON-EXPAND-64-NEXT: },
136 # JSON-EXPAND-64-NEXT: {
137 # JSON-EXPAND-64-NEXT: "Relocation": {
138 # JSON-EXPAND-64-NEXT: "Offset": 1,
139 # JSON-EXPAND-64-NEXT: "Type": {
140 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PC32",
141 # JSON-EXPAND-64-NEXT: "Value": 2
142 # JSON-EXPAND-64-NEXT: },
143 # JSON-EXPAND-64-NEXT: "Symbol": {
144 # JSON-EXPAND-64-NEXT: "Name": "rel_neg",
145 # JSON-EXPAND-64-NEXT: "Value": 2
146 # JSON-EXPAND-64-NEXT: }
147 # JSON-EXPAND-64-NEXT: }
148 # JSON-EXPAND-64-NEXT: },
149 # JSON-EXPAND-64-NEXT: {
150 # JSON-EXPAND-64-NEXT: "Relocation": {
151 # JSON-EXPAND-64-NEXT: "Offset": 5,
152 # JSON-EXPAND-64-NEXT: "Type": {
153 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PLT32",
154 # JSON-EXPAND-64-NEXT: "Value": 4
155 # JSON-EXPAND-64-NEXT: },
156 # JSON-EXPAND-64-NEXT: "Symbol": {
157 # JSON-EXPAND-64-NEXT: "Name": "rel_pos",
158 # JSON-EXPAND-64-NEXT: "Value": 3
159 # JSON-EXPAND-64-NEXT: }
160 # JSON-EXPAND-64-NEXT: }
161 # JSON-EXPAND-64-NEXT: },
162 # JSON-EXPAND-64-NEXT: {
163 # JSON-EXPAND-64-NEXT: "Relocation": {
164 # JSON-EXPAND-64-NEXT: "Offset": 9,
165 # JSON-EXPAND-64-NEXT: "Type": {
166 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_64",
167 # JSON-EXPAND-64-NEXT: "Value": 1
168 # JSON-EXPAND-64-NEXT: },
169 # JSON-EXPAND-64-NEXT: "Symbol": {
170 # JSON-EXPAND-64-NEXT: "Name": "rel_64",
171 # JSON-EXPAND-64-NEXT: "Value": 4
172 # JSON-EXPAND-64-NEXT: }
173 # JSON-EXPAND-64-NEXT: }
174 # JSON-EXPAND-64-NEXT: }
175 # JSON-EXPAND-64-NEXT: ]
176 # JSON-EXPAND-64-NEXT: },
177 # JSON-EXPAND-64-NEXT: {
178 # JSON-EXPAND-64-NEXT: "SectionIndex": 3,
179 # JSON-EXPAND-64-NEXT: "Relocs": [
180 # JSON-EXPAND-64-NEXT: {
181 # JSON-EXPAND-64-NEXT: "Relocation": {
182 # JSON-EXPAND-64-NEXT: "Offset": 0,
183 # JSON-EXPAND-64-NEXT: "Type": {
184 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_NONE",
185 # JSON-EXPAND-64-NEXT: "Value": 0
186 # JSON-EXPAND-64-NEXT: },
187 # JSON-EXPAND-64-NEXT: "Symbol": {
188 # JSON-EXPAND-64-NEXT: "Name": "rela_0",
189 # JSON-EXPAND-64-NEXT: "Value": 5
190 # JSON-EXPAND-64-NEXT: },
191 # JSON-EXPAND-64-NEXT: "Addend": 0
192 # JSON-EXPAND-64-NEXT: }
193 # JSON-EXPAND-64-NEXT: },
194 # JSON-EXPAND-64-NEXT: {
195 # JSON-EXPAND-64-NEXT: "Relocation": {
196 # JSON-EXPAND-64-NEXT: "Offset": 1,
197 # JSON-EXPAND-64-NEXT: "Type": {
198 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PC32",
199 # JSON-EXPAND-64-NEXT: "Value": 2
200 # JSON-EXPAND-64-NEXT: },
201 # JSON-EXPAND-64-NEXT: "Symbol": {
202 # JSON-EXPAND-64-NEXT: "Name": "rela_neg",
203 # JSON-EXPAND-64-NEXT: "Value": 6
204 # JSON-EXPAND-64-NEXT: },
205 # JSON-EXPAND-64-NEXT: "Addend": 18446744073709551615
206 # JSON-EXPAND-64-NEXT: }
207 # JSON-EXPAND-64-NEXT: },
208 # JSON-EXPAND-64-NEXT: {
209 # JSON-EXPAND-64-NEXT: "Relocation": {
210 # JSON-EXPAND-64-NEXT: "Offset": 5,
211 # JSON-EXPAND-64-NEXT: "Type": {
212 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_PLT32",
213 # JSON-EXPAND-64-NEXT: "Value": 4
214 # JSON-EXPAND-64-NEXT: },
215 # JSON-EXPAND-64-NEXT: "Symbol": {
216 # JSON-EXPAND-64-NEXT: "Name": "rela_pos",
217 # JSON-EXPAND-64-NEXT: "Value": 7
218 # JSON-EXPAND-64-NEXT: },
219 # JSON-EXPAND-64-NEXT: "Addend": 2
220 # JSON-EXPAND-64-NEXT: }
221 # JSON-EXPAND-64-NEXT: },
222 # JSON-EXPAND-64-NEXT: {
223 # JSON-EXPAND-64-NEXT: "Relocation": {
224 # JSON-EXPAND-64-NEXT: "Offset": 18446744073709551615,
225 # JSON-EXPAND-64-NEXT: "Type": {
226 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_64",
227 # JSON-EXPAND-64-NEXT: "Value": 1
228 # JSON-EXPAND-64-NEXT: },
229 # JSON-EXPAND-64-NEXT: "Symbol": {
230 # JSON-EXPAND-64-NEXT: "Name": "rela_minneg",
231 # JSON-EXPAND-64-NEXT: "Value": 8
232 # JSON-EXPAND-64-NEXT: },
233 # JSON-EXPAND-64-NEXT: "Addend": 9223372036854775808
234 # JSON-EXPAND-64-NEXT: }
235 # JSON-EXPAND-64-NEXT: },
236 # JSON-EXPAND-64-NEXT: {
237 # JSON-EXPAND-64-NEXT: "Relocation": {
238 # JSON-EXPAND-64-NEXT: "Offset": 9,
239 # JSON-EXPAND-64-NEXT: "Type": {
240 # JSON-EXPAND-64-NEXT: "Name": "R_X86_64_32S",
241 # JSON-EXPAND-64-NEXT: "Value": 11
242 # JSON-EXPAND-64-NEXT: },
243 # JSON-EXPAND-64-NEXT: "Symbol": {
244 # JSON-EXPAND-64-NEXT: "Name": "rela_maxpos",
245 # JSON-EXPAND-64-NEXT: "Value": 9
246 # JSON-EXPAND-64-NEXT: },
247 # JSON-EXPAND-64-NEXT: "Addend": 9223372036854775807
248 # JSON-EXPAND-64-NEXT: }
249 # JSON-EXPAND-64-NEXT: }
250 # JSON-EXPAND-64-NEXT: ]
251 # JSON-EXPAND-64-NEXT: }
252 # JSON-EXPAND-64-NEXT: ]
263 Content: '00FFFFFFFF020000001234567890ABCDEF'
267 Link: [[LINK=.symtab]]
268 ShName: [[SHNAME=<none>]]
269 EntSize: [[ENTSIZEREL=<none>]]
285 Link: [[LINK=.symtab]]
286 ShName: [[SHNAME=<none>]]
287 EntSize: [[ENTSIZERELA=<none>]]
300 - Offset: 0xFFFFFFFFFFFFFFFF
303 Addend: -9223372036854775808 ## Min 64-bit signed.
307 Addend: 9223372036854775807 ## Max 64-bit signed.
320 Value: 0xFFFFFFFFFFFFFFFF
335 Value: 0xFFFFFFFFFFFFFFFF
337 ## Check we report a warning when we are unable to dump relocations for a section.
338 ## Check we continue dumping other relocation sections if any.
340 ## Case A: check the case when relocations can't be read from an SHT_REL section.
341 ## because of broken sh_entsize field.
342 # RUN: yaml2obj %s --docnum=1 -DENTSIZEREL=1 -o %t.broken.rel
343 # RUN: llvm-readobj --relocations %t.broken.rel 2>&1 \
344 # RUN: | FileCheck %s -DFILE=%t.broken.rel --check-prefix=BROKEN-REL-LLVM
345 # RUN: llvm-readelf --relocations %t.broken.rel 2>&1 \
346 # RUN: | FileCheck %s -DFILE=%t.broken.rel --check-prefix=BROKEN-REL-GNU
348 # BROKEN-REL-LLVM: Relocations [
349 # BROKEN-REL-LLVM-NEXT: Section (2) .rel.text {
350 # BROKEN-REL-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_REL section with index 2: section [index 2] has invalid sh_entsize: expected 16, but got 1
351 # BROKEN-REL-LLVM-NEXT: }
352 # BROKEN-REL-LLVM-NEXT: Section (3) .rela.text {
353 # BROKEN-REL-LLVM-NEXT: 0x0 R_X86_64_NONE rela_0 0x0
354 # BROKEN-REL-LLVM-NEXT: 0x1 R_X86_64_PC32 rela_neg 0xFFFFFFFFFFFFFFFF
355 # BROKEN-REL-LLVM-NEXT: 0x5 R_X86_64_PLT32 rela_pos 0x2
356 # BROKEN-REL-LLVM-NEXT: 0xFFFFFFFFFFFFFFFF R_X86_64_64 rela_minneg 0x8000000000000000
357 # BROKEN-REL-LLVM-NEXT: 0x9 R_X86_64_32S rela_maxpos 0x7FFFFFFFFFFFFFFF
358 # BROKEN-REL-LLVM-NEXT: }
359 # BROKEN-REL-LLVM-NEXT: ]
361 # BROKEN-REL-GNU: Relocation section '.rel.text' at offset 0x51 contains 64 entries:
362 # BROKEN-REL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
363 # BROKEN-REL-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_REL section with index 2: section [index 2] has invalid sh_entsize: expected 16, but got 1
364 # BROKEN-REL-GNU: Relocation section '.rela.text' at offset 0x91 contains 5 entries:
365 # BROKEN-REL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
366 # BROKEN-REL-GNU-NEXT: 0000000000000000 0000000500000000 R_X86_64_NONE 0000000000000000 rela_0 + 0
367 # BROKEN-REL-GNU-NEXT: 0000000000000001 0000000600000002 R_X86_64_PC32 0000000000000001 rela_neg - 1
368 # BROKEN-REL-GNU-NEXT: 0000000000000005 0000000700000004 R_X86_64_PLT32 0000000000000002 rela_pos + 2
369 # BROKEN-REL-GNU-NEXT: ffffffffffffffff 0000000800000001 R_X86_64_64 0000000000000003 rela_minneg - 8000000000000000
370 # BROKEN-REL-GNU-NEXT: 0000000000000009 000000090000000b R_X86_64_32S ffffffffffffffff rela_maxpos + 7fffffffffffffff
372 ## Case B: check the case when relocations can't be read from an SHT_RELA section.
373 ## because of broken sh_entsize field.
374 # RUN: yaml2obj %s --docnum=1 -DENTSIZERELA=1 -o %t.broken.rela
375 # RUN: llvm-readobj --relocations %t.broken.rela 2>&1 \
376 # RUN: | FileCheck %s -DFILE=%t.broken.rela --check-prefix=BROKEN-RELA-LLVM
377 # RUN: llvm-readelf --relocations %t.broken.rela 2>&1 \
378 # RUN: | FileCheck %s -DFILE=%t.broken.rela --check-prefix=BROKEN-RELA-GNU
380 # BROKEN-RELA-LLVM: Relocations [
381 # BROKEN-RELA-LLVM-NEXT: Section (2) .rel.text {
382 # BROKEN-RELA-LLVM-NEXT: 0x0 R_X86_64_NONE rel_0{{$}}
383 # BROKEN-RELA-LLVM-NEXT: 0x1 R_X86_64_PC32 rel_neg{{$}}
384 # BROKEN-RELA-LLVM-NEXT: 0x5 R_X86_64_PLT32 rel_pos{{$}}
385 # BROKEN-RELA-LLVM-NEXT: 0x9 R_X86_64_64 rel_64{{$}}
386 # BROKEN-RELA-LLVM-NEXT: }
387 # BROKEN-RELA-LLVM-NEXT: Section (3) .rela.text {
388 # BROKEN-RELA-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_RELA section with index 3: section [index 3] has invalid sh_entsize: expected 24, but got 1
389 # BROKEN-RELA-LLVM-NEXT: }
390 # BROKEN-RELA-LLVM-NEXT: ]
392 # BROKEN-RELA-GNU: Relocation section '.rel.text' at offset 0x51 contains 4 entries:
393 # BROKEN-RELA-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
394 # BROKEN-RELA-GNU-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 rel_0
395 # BROKEN-RELA-GNU-NEXT: 0000000000000001 0000000200000002 R_X86_64_PC32 0000000000000001 rel_neg
396 # BROKEN-RELA-GNU-NEXT: 0000000000000005 0000000300000004 R_X86_64_PLT32 0000000000000002 rel_pos
397 # BROKEN-RELA-GNU-NEXT: 0000000000000009 0000000400000001 R_X86_64_64 ffffffffffffffff rel_64
398 # BROKEN-RELA-GNU-EMPTY:
399 # BROKEN-RELA-GNU-NEXT: Relocation section '.rela.text' at offset 0x91 contains 120 entries:
400 # BROKEN-RELA-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
401 # BROKEN-RELA-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from SHT_RELA section with index 3: section [index 3] has invalid sh_entsize: expected 24, but got 1
403 ## Case C: check the case when relocations can't be read from SHT_REL/SHT_RELA sections
404 ## because of broken sh_link fields.
405 # RUN: yaml2obj %s --docnum=1 -DLINK=0xffff -o %t.broken.link
406 # RUN: llvm-readobj --relocations %t.broken.link 2>&1 \
407 # RUN: | FileCheck %s -DFILE=%t.broken.link --check-prefix=BROKEN-LINK-LLVM
408 # RUN: llvm-readelf --relocations %t.broken.link 2>&1 \
409 # RUN: | FileCheck %s -DFILE=%t.broken.link --check-prefix=BROKEN-LINK-GNU
411 # BROKEN-LINK-LLVM: Relocations [
412 # BROKEN-LINK-LLVM-NEXT: Section (2) .rel.text {
413 # BROKEN-LINK-LLVM-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_REL section with index 2: invalid section index: 65535
414 # BROKEN-LINK-LLVM-NEXT: }
415 # BROKEN-LINK-LLVM-NEXT: Section (3) .rela.text {
416 # BROKEN-LINK-LLVM-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_RELA section with index 3: invalid section index: 65535
417 # BROKEN-LINK-LLVM-NEXT: }
418 # BROKEN-LINK-LLVM-NEXT: ]
420 # BROKEN-LINK-GNU: Relocation section '.rel.text' at offset 0x51 contains 4 entries:
421 # BROKEN-LINK-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
422 # BROKEN-LINK-GNU-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_REL section with index 2: invalid section index: 65535
423 # BROKEN-LINK-GNU-EMPTY:
424 # BROKEN-LINK-GNU-NEXT: Relocation section '.rela.text' at offset 0x91 contains 5 entries:
425 # BROKEN-LINK-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
426 # BROKEN-LINK-GNU-NEXT: warning: '[[FILE]]': unable to locate a symbol table for SHT_RELA section with index 3: invalid section index: 65535
428 ## Show that ELF32 is dumped correctly.
429 # RUN: yaml2obj %s --docnum=2 -o %t32
430 # RUN: llvm-readobj -r %t32 \
431 # RUN: | FileCheck %s --check-prefix=LLVM-32 --strict-whitespace --match-full-lines
432 # RUN: llvm-readobj --relocs %t32 \
433 # RUN: | FileCheck %s --check-prefix=LLVM-32 --strict-whitespace --match-full-lines
434 # RUN: llvm-readobj --relocations %t32 \
435 # RUN: | FileCheck %s --check-prefix=LLVM-32 --strict-whitespace --match-full-lines
437 # LLVM-32:Relocations [
438 # LLVM-32-NEXT: Section (2) .rel.text {
439 # LLVM-32-NEXT: 0x0 R_386_NONE rel_0
440 # LLVM-32-NEXT: 0x1 R_386_PC32 rel_neg
441 # LLVM-32-NEXT: 0x5 R_386_PLT32 rel_pos
443 # LLVM-32-NEXT: Section (3) .rela.text {
444 # LLVM-32-NEXT: 0x0 R_386_NONE rela_0 0x0
445 # LLVM-32-NEXT: 0x1 R_386_PC32 rela_neg 0xFFFFFFFF
446 # LLVM-32-NEXT: 0x5 R_386_PLT32 rela_pos 0x2
447 # LLVM-32-NEXT: 0xFFFFFFFF R_386_32 rela_minneg 0x80000000
448 # LLVM-32-NEXT: 0x9 R_386_GOT32 rela_maxpos 0x7FFFFFFF
452 # RUN: llvm-readelf -r %t32 \
453 # RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines
454 # RUN: llvm-readelf --relocs %t32 \
455 # RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines
456 # RUN: llvm-readelf --relocations %t32 \
457 # RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines
459 # GNU-32:Relocation section '.rel.text' at offset 0x3d contains 3 entries:
460 # GNU-32-NEXT: Offset Info Type Sym. Value Symbol's Name
461 # GNU-32-NEXT:00000000 00000100 R_386_NONE 00000000 rel_0
462 # GNU-32-NEXT:00000001 00000202 R_386_PC32 00000001 rel_neg
463 # GNU-32-NEXT:00000005 00000304 R_386_PLT32 ffffffff rel_pos
465 # GNU-32-NEXT:Relocation section '.rela.text' at offset 0x55 contains 5 entries:
466 # GNU-32-NEXT: Offset Info Type Sym. Value Symbol's Name + Addend
467 # GNU-32-NEXT:00000000 00000400 R_386_NONE 00000000 rela_0 + 0
468 # GNU-32-NEXT:00000001 00000502 R_386_PC32 00000001 rela_neg - 1
469 # GNU-32-NEXT:00000005 00000604 R_386_PLT32 00000002 rela_pos + 2
470 # GNU-32-NEXT:ffffffff 00000701 R_386_32 00000003 rela_minneg - 80000000
471 # GNU-32-NEXT:00000009 00000803 R_386_GOT32 ffffffff rela_maxpos + 7fffffff
473 ## Show that --expand-relocs expands the relocation dump for LLVM style and not GNU.
474 # RUN: llvm-readobj -r --expand-relocs %t32 \
475 # RUN: | FileCheck %s --check-prefix=LLVM-EXPAND-32 --strict-whitespace --match-full-lines
476 # RUN: llvm-readelf -r --expand-relocs %t32 \
477 # RUN: | FileCheck %s --check-prefix=GNU-32 --strict-whitespace --match-full-lines
479 # LLVM-EXPAND-32:Relocations [
480 # LLVM-EXPAND-32-NEXT: Section (2) .rel.text {
481 # LLVM-EXPAND-32-NEXT: Relocation {
482 # LLVM-EXPAND-32-NEXT: Offset: 0x0
483 # LLVM-EXPAND-32-NEXT: Type: R_386_NONE (0)
484 # LLVM-EXPAND-32-NEXT: Symbol: rel_0 (1)
485 # LLVM-EXPAND-32-NEXT: }
486 # LLVM-EXPAND-32-NEXT: Relocation {
487 # LLVM-EXPAND-32-NEXT: Offset: 0x1
488 # LLVM-EXPAND-32-NEXT: Type: R_386_PC32 (2)
489 # LLVM-EXPAND-32-NEXT: Symbol: rel_neg (2)
490 # LLVM-EXPAND-32-NEXT: }
491 # LLVM-EXPAND-32-NEXT: Relocation {
492 # LLVM-EXPAND-32-NEXT: Offset: 0x5
493 # LLVM-EXPAND-32-NEXT: Type: R_386_PLT32 (4)
494 # LLVM-EXPAND-32-NEXT: Symbol: rel_pos (3)
495 # LLVM-EXPAND-32-NEXT: }
496 # LLVM-EXPAND-32-NEXT: }
497 # LLVM-EXPAND-32-NEXT: Section (3) .rela.text {
498 # LLVM-EXPAND-32-NEXT: Relocation {
499 # LLVM-EXPAND-32-NEXT: Offset: 0x0
500 # LLVM-EXPAND-32-NEXT: Type: R_386_NONE (0)
501 # LLVM-EXPAND-32-NEXT: Symbol: rela_0 (4)
502 # LLVM-EXPAND-32-NEXT: Addend: 0x0
503 # LLVM-EXPAND-32-NEXT: }
504 # LLVM-EXPAND-32-NEXT: Relocation {
505 # LLVM-EXPAND-32-NEXT: Offset: 0x1
506 # LLVM-EXPAND-32-NEXT: Type: R_386_PC32 (2)
507 # LLVM-EXPAND-32-NEXT: Symbol: rela_neg (5)
508 # LLVM-EXPAND-32-NEXT: Addend: 0xFFFFFFFF
509 # LLVM-EXPAND-32-NEXT: }
510 # LLVM-EXPAND-32-NEXT: Relocation {
511 # LLVM-EXPAND-32-NEXT: Offset: 0x5
512 # LLVM-EXPAND-32-NEXT: Type: R_386_PLT32 (4)
513 # LLVM-EXPAND-32-NEXT: Symbol: rela_pos (6)
514 # LLVM-EXPAND-32-NEXT: Addend: 0x2
515 # LLVM-EXPAND-32-NEXT: }
516 # LLVM-EXPAND-32-NEXT: Relocation {
517 # LLVM-EXPAND-32-NEXT: Offset: 0xFFFFFFFF
518 # LLVM-EXPAND-32-NEXT: Type: R_386_32 (1)
519 # LLVM-EXPAND-32-NEXT: Symbol: rela_minneg (7)
520 # LLVM-EXPAND-32-NEXT: Addend: 0x80000000
521 # LLVM-EXPAND-32-NEXT: }
522 # LLVM-EXPAND-32-NEXT: Relocation {
523 # LLVM-EXPAND-32-NEXT: Offset: 0x9
524 # LLVM-EXPAND-32-NEXT: Type: R_386_GOT32 (3)
525 # LLVM-EXPAND-32-NEXT: Symbol: rela_maxpos (8)
526 # LLVM-EXPAND-32-NEXT: Addend: 0x7FFFFFFF
527 # LLVM-EXPAND-32-NEXT: }
528 # LLVM-EXPAND-32-NEXT: }
529 # LLVM-EXPAND-32-NEXT:]
540 Content: '00FFFFFFFF02000000'
571 Addend: -2147483648 ## Min 32-bit signed.
575 Addend: 2147483647 ## Max 32-bit signed.
602 ## Check we report a warning when the name of a relocation section can't be read. Check we continue dumping.
603 # RUN: yaml2obj %s --docnum=1 -DSHNAME=0xffffffff -o %tshname
604 # RUN: llvm-readobj --relocs %tshname 2>&1 | FileCheck %s -DFILE=%tshname --check-prefix=LLVM-SHNAME
605 # RUN: llvm-readelf --relocs %tshname 2>&1 | FileCheck %s -DFILE=%tshname --check-prefix=GNU-SHNAME
607 # LLVM-SHNAME: Relocations [
608 # LLVM-SHNAME-NEXT: warning: '[[FILE]]': unable to get the name of SHT_REL section with index 2: a section [index 2] has an invalid sh_name (0xffffffff) offset which goes past the end of the section name string table
609 # LLVM-SHNAME-NEXT: Section (2) <?> {
610 # LLVM-SHNAME-NEXT: 0x0 R_X86_64_NONE rel_0{{$}}
611 # LLVM-SHNAME-NEXT: 0x1 R_X86_64_PC32 rel_neg{{$}}
612 # LLVM-SHNAME-NEXT: 0x5 R_X86_64_PLT32 rel_pos{{$}}
613 # LLVM-SHNAME-NEXT: 0x9 R_X86_64_64 rel_64{{$}}
614 # LLVM-SHNAME-NEXT: }
615 # LLVM-SHNAME-NEXT: warning: '[[FILE]]': unable to get the name of SHT_RELA section with index 3: a section [index 3] has an invalid sh_name (0xffffffff) offset which goes past the end of the section name string table
616 # LLVM-SHNAME-NEXT: Section (3) <?> {
617 # LLVM-SHNAME-NEXT: 0x0 R_X86_64_NONE rela_0 0x0
618 # LLVM-SHNAME-NEXT: 0x1 R_X86_64_PC32 rela_neg 0xFFFFFFFFFFFFFFFF
619 # LLVM-SHNAME-NEXT: 0x5 R_X86_64_PLT32 rela_pos 0x2
620 # LLVM-SHNAME-NEXT: 0xFFFFFFFFFFFFFFFF R_X86_64_64 rela_minneg 0x8000000000000000
621 # LLVM-SHNAME-NEXT: 0x9 R_X86_64_32S rela_maxpos 0x7FFFFFFFFFFFFFFF
622 # LLVM-SHNAME-NEXT: }
623 # LLVM-SHNAME-NEXT: ]
625 # GNU-SHNAME: warning: '[[FILE]]': unable to get the name of SHT_REL section with index 2: a section [index 2] has an invalid sh_name (0xffffffff) offset which goes past the end of the section name string table
626 # GNU-SHNAME: Relocation section '<?>' at offset 0x51 contains 4 entries:
627 # GNU-SHNAME-NEXT: Offset Info Type Symbol's Value Symbol's Name
628 # GNU-SHNAME-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 rel_0
629 # GNU-SHNAME-NEXT: 0000000000000001 0000000200000002 R_X86_64_PC32 0000000000000001 rel_neg
630 # GNU-SHNAME-NEXT: 0000000000000005 0000000300000004 R_X86_64_PLT32 0000000000000002 rel_pos
631 # GNU-SHNAME-NEXT: 0000000000000009 0000000400000001 R_X86_64_64 ffffffffffffffff rel_64
632 # GNU-SHNAME: warning: '[[FILE]]': unable to get the name of SHT_RELA section with index 3: a section [index 3] has an invalid sh_name (0xffffffff) offset which goes past the end of the section name string table
633 # GNU-SHNAME: Relocation section '<?>' at offset 0x91 contains 5 entries:
634 # GNU-SHNAME-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
635 # GNU-SHNAME-NEXT: 0000000000000000 0000000500000000 R_X86_64_NONE 0000000000000000 rela_0 + 0
636 # GNU-SHNAME-NEXT: 0000000000000001 0000000600000002 R_X86_64_PC32 0000000000000001 rela_neg - 1
637 # GNU-SHNAME-NEXT: 0000000000000005 0000000700000004 R_X86_64_PLT32 0000000000000002 rela_pos + 2
638 # GNU-SHNAME-NEXT: ffffffffffffffff 0000000800000001 R_X86_64_64 0000000000000003 rela_minneg - 8000000000000000
639 # GNU-SHNAME-NEXT: 0000000000000009 000000090000000b R_X86_64_32S ffffffffffffffff rela_maxpos + 7fffffffffffffff
641 ## Check that we report a warning when a relocation has a
642 ## symbol index past the end of the symbol table
644 # RUN: yaml2obj %s --docnum=3 -o %t3
645 # RUN: llvm-readobj --relocs %t3 2>&1 | \
646 # RUN: FileCheck %s --implicit-check-not=warning: -DFILE=%t3 --check-prefix=LLVM-SYMNDX
647 # RUN: llvm-readelf --relocs %t3 2>&1 | \
648 # RUN: FileCheck %s --implicit-check-not=warning: -DFILE=%t3 --check-prefix=GNU-SYMNDX
650 # LLVM-SYMNDX: Relocations [
651 # LLVM-SYMNDX-NEXT: Section (1) .rela.text {
652 # LLVM-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 1: unable to read an entry with index 2 from SHT_SYMTAB section with index 2: can't read an entry at 0x30: it goes past the end of the section (0x30)
653 # LLVM-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 1: unable to read an entry with index 3 from SHT_SYMTAB section with index 2: can't read an entry at 0x48: it goes past the end of the section (0x30)
654 # LLVM-SYMNDX-NEXT: }
655 # LLVM-SYMNDX-NEXT: ]
657 # GNU-SYMNDX: Relocation section '.rela.text' at offset 0x40 contains 2 entries:
658 # GNU-SYMNDX-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
659 # GNU-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 1: unable to read an entry with index 2 from SHT_SYMTAB section with index 2: can't read an entry at 0x30: it goes past the end of the section (0x30)
660 # GNU-SYMNDX-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 1: unable to read an entry with index 3 from SHT_SYMTAB section with index 2: can't read an entry at 0x48: it goes past the end of the section (0x30)
672 - Type: R_X86_64_NONE
674 - Type: R_X86_64_NONE