Commit | Line | Data |
---|---|---|
5bd4f169 | 1 | /* PowerPC64-specific support for 64-bit ELF. |
5d1634d7 | 2 | Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
5bd4f169 AM |
3 | Written by Linus Nordberg, Swox AB <info@swox.com>, |
4 | based on elf32-ppc.c by Ian Lance Taylor. | |
5 | ||
6 | This file is part of BFD, the Binary File Descriptor library. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | /* This file is based on the 64-bit PowerPC ELF ABI. It is also based | |
23 | on the file elf32-ppc.c. */ | |
24 | ||
25 | #include "bfd.h" | |
26 | #include "sysdep.h" | |
27 | #include "bfdlink.h" | |
28 | #include "libbfd.h" | |
29 | #include "elf-bfd.h" | |
30 | #include "elf/ppc.h" | |
5d1634d7 | 31 | #include "elf64-ppc.h" |
5bd4f169 AM |
32 | |
33 | #define USE_RELA /* we want RELA relocations, not REL. */ | |
34 | ||
35 | ||
36 | static void ppc_howto_init | |
37 | PARAMS ((void)); | |
38 | static reloc_howto_type *ppc64_elf_reloc_type_lookup | |
39 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
40 | static void ppc64_elf_info_to_howto | |
41 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst)); | |
42 | static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc | |
43 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
44 | static boolean ppc64_elf_set_private_flags | |
45 | PARAMS ((bfd *, flagword)); | |
5bd4f169 AM |
46 | static boolean ppc64_elf_merge_private_bfd_data |
47 | PARAMS ((bfd *, bfd *)); | |
48 | static boolean ppc64_elf_section_from_shdr | |
49 | PARAMS ((bfd *, Elf64_Internal_Shdr *, char *)); | |
65f38f15 AM |
50 | static struct bfd_hash_entry *link_hash_newfunc |
51 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
52 | static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create | |
53 | PARAMS ((bfd *)); | |
54 | static boolean create_got_section | |
55 | PARAMS ((bfd *, struct bfd_link_info *)); | |
5bd4f169 AM |
56 | static boolean ppc64_elf_create_dynamic_sections |
57 | PARAMS ((bfd *, struct bfd_link_info *)); | |
65f38f15 AM |
58 | static void ppc64_elf_copy_indirect_symbol |
59 | PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *)); | |
5bd4f169 AM |
60 | static boolean ppc64_elf_check_relocs |
61 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
62 | const Elf_Internal_Rela *)); | |
63 | static asection * ppc64_elf_gc_mark_hook | |
64 | PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel, | |
65 | struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)); | |
66 | static boolean ppc64_elf_gc_sweep_hook | |
67 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec, | |
68 | const Elf_Internal_Rela *relocs)); | |
69 | static boolean ppc64_elf_adjust_dynamic_symbol | |
70 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
65f38f15 AM |
71 | static boolean allocate_dynrelocs |
72 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
73 | static boolean readonly_dynrelocs | |
5bd4f169 | 74 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
65f38f15 AM |
75 | static enum elf_reloc_type_class ppc64_elf_reloc_type_class |
76 | PARAMS ((const Elf_Internal_Rela *)); | |
5bd4f169 AM |
77 | static boolean ppc64_elf_size_dynamic_sections |
78 | PARAMS ((bfd *, struct bfd_link_info *)); | |
5d1634d7 AM |
79 | static bfd_byte *build_plt_stub |
80 | PARAMS ((bfd *, bfd_byte *, int, int)); | |
81 | static boolean build_one_stub | |
82 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
5bd4f169 AM |
83 | static boolean ppc64_elf_fake_sections |
84 | PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *)); | |
85 | static boolean ppc64_elf_relocate_section | |
86 | PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *, | |
87 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, | |
88 | asection **)); | |
89 | static boolean ppc64_elf_finish_dynamic_symbol | |
90 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
91 | Elf_Internal_Sym *)); | |
92 | static boolean ppc64_elf_finish_dynamic_sections | |
93 | PARAMS ((bfd *, struct bfd_link_info *)); | |
94 | ||
95 | ||
5bd4f169 AM |
96 | /* Mask to set RA in memory instructions. */ |
97 | #define RA_REGISTER_MASK 0x001f0000 | |
98 | ||
99 | /* Value to shift register by to insert RA. */ | |
100 | #define RA_REGISTER_SHIFT 16 | |
101 | ||
102 | /* The name of the dynamic interpreter. This is put in the .interp | |
103 | section. */ | |
104 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
105 | ||
106 | /* The size in bytes of an entry in the procedure linkage table. */ | |
107 | #define PLT_ENTRY_SIZE 24 | |
108 | ||
109 | /* The initial size of the plt reserved for the dynamic linker. */ | |
5d1634d7 | 110 | #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE |
5bd4f169 AM |
111 | |
112 | /* TOC base pointers offset from start of TOC. */ | |
113 | #define TOC_BASE_OFF (0x8000) | |
114 | ||
5d1634d7 AM |
115 | /* .plt call stub instructions. */ |
116 | #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ | |
117 | #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ | |
118 | #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | |
119 | #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
120 | #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | |
121 | /* ld %r11,xxx+16@l(%r12) */ | |
122 | #define BCTR 0x4e800420 /* bctr */ | |
123 | ||
124 | /* The normal stub is this size. */ | |
125 | #define PLT_CALL_STUB_SIZE (7*4) | |
126 | ||
127 | /* But sometimes the .plt entry crosses a 64k boundary, and we need | |
128 | to adjust the high word with this insn. */ | |
129 | #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */ | |
5bd4f169 | 130 | |
5d1634d7 AM |
131 | /* The .glink fixup call stub is the same as the .plt call stub, but |
132 | the first instruction restores r2, and the std is omitted. */ | |
133 | #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ | |
134 | ||
135 | /* Always allow this much space. */ | |
136 | #define GLINK_CALL_STUB_SIZE (8*4) | |
137 | ||
138 | /* Pad with this. */ | |
139 | #define NOP 0x60000000 | |
140 | ||
141 | /* .glink entries for the first 32k functions are two instructions. */ | |
142 | #define LI_R0_0 0x38000000 /* li %r0,0 */ | |
143 | #define B_DOT 0x48000000 /* b . */ | |
144 | ||
145 | /* After that, we need two instructions to load the index, followed by | |
146 | a branch. */ | |
147 | #define LIS_R0_0 0x3c000000 /* lis %r0,0 */ | |
10ed1bba | 148 | #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */ |
5bd4f169 AM |
149 | \f |
150 | /* Relocation HOWTO's. */ | |
151 | static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max]; | |
152 | ||
153 | static reloc_howto_type ppc64_elf_howto_raw[] = { | |
154 | /* This reloc does nothing. */ | |
155 | HOWTO (R_PPC64_NONE, /* type */ | |
156 | 0, /* rightshift */ | |
157 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
158 | 32, /* bitsize */ | |
159 | false, /* pc_relative */ | |
160 | 0, /* bitpos */ | |
161 | complain_overflow_bitfield, /* complain_on_overflow */ | |
162 | bfd_elf_generic_reloc, /* special_function */ | |
163 | "R_PPC64_NONE", /* name */ | |
164 | false, /* partial_inplace */ | |
165 | 0, /* src_mask */ | |
166 | 0, /* dst_mask */ | |
167 | false), /* pcrel_offset */ | |
168 | ||
169 | /* A standard 32 bit relocation. */ | |
170 | HOWTO (R_PPC64_ADDR32, /* type */ | |
171 | 0, /* rightshift */ | |
172 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
173 | 32, /* bitsize */ | |
174 | false, /* pc_relative */ | |
175 | 0, /* bitpos */ | |
176 | complain_overflow_bitfield, /* complain_on_overflow */ | |
177 | bfd_elf_generic_reloc, /* special_function */ | |
178 | "R_PPC64_ADDR32", /* name */ | |
179 | false, /* partial_inplace */ | |
180 | 0, /* src_mask */ | |
181 | 0xffffffff, /* dst_mask */ | |
182 | false), /* pcrel_offset */ | |
183 | ||
184 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
185 | FIXME: we don't check that, we just clear them. */ | |
186 | HOWTO (R_PPC64_ADDR24, /* type */ | |
187 | 0, /* rightshift */ | |
188 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
189 | 26, /* bitsize */ | |
190 | false, /* pc_relative */ | |
191 | 0, /* bitpos */ | |
192 | complain_overflow_bitfield, /* complain_on_overflow */ | |
193 | bfd_elf_generic_reloc, /* special_function */ | |
194 | "R_PPC64_ADDR24", /* name */ | |
195 | false, /* partial_inplace */ | |
196 | 0, /* src_mask */ | |
197 | 0x3fffffc, /* dst_mask */ | |
198 | false), /* pcrel_offset */ | |
199 | ||
200 | /* A standard 16 bit relocation. */ | |
201 | HOWTO (R_PPC64_ADDR16, /* type */ | |
202 | 0, /* rightshift */ | |
203 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
204 | 16, /* bitsize */ | |
205 | false, /* pc_relative */ | |
206 | 0, /* bitpos */ | |
207 | complain_overflow_bitfield, /* complain_on_overflow */ | |
208 | bfd_elf_generic_reloc, /* special_function */ | |
209 | "R_PPC64_ADDR16", /* name */ | |
210 | false, /* partial_inplace */ | |
211 | 0, /* src_mask */ | |
212 | 0xffff, /* dst_mask */ | |
213 | false), /* pcrel_offset */ | |
214 | ||
215 | /* A 16 bit relocation without overflow. */ | |
216 | HOWTO (R_PPC64_ADDR16_LO, /* type */ | |
217 | 0, /* rightshift */ | |
218 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
219 | 16, /* bitsize */ | |
220 | false, /* pc_relative */ | |
221 | 0, /* bitpos */ | |
222 | complain_overflow_dont,/* complain_on_overflow */ | |
223 | bfd_elf_generic_reloc, /* special_function */ | |
224 | "R_PPC64_ADDR16_LO", /* name */ | |
225 | false, /* partial_inplace */ | |
226 | 0, /* src_mask */ | |
227 | 0xffff, /* dst_mask */ | |
228 | false), /* pcrel_offset */ | |
229 | ||
230 | /* Bits 16-31 of an address. */ | |
231 | HOWTO (R_PPC64_ADDR16_HI, /* type */ | |
232 | 16, /* rightshift */ | |
233 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
234 | 16, /* bitsize */ | |
235 | false, /* pc_relative */ | |
236 | 0, /* bitpos */ | |
237 | complain_overflow_dont, /* complain_on_overflow */ | |
238 | bfd_elf_generic_reloc, /* special_function */ | |
239 | "R_PPC64_ADDR16_HI", /* name */ | |
240 | false, /* partial_inplace */ | |
241 | 0, /* src_mask */ | |
242 | 0xffff, /* dst_mask */ | |
243 | false), /* pcrel_offset */ | |
244 | ||
245 | /* Bits 16-31 of an address, plus 1 if the contents of the low 16 | |
246 | bits, treated as a signed number, is negative. */ | |
247 | HOWTO (R_PPC64_ADDR16_HA, /* type */ | |
248 | 16, /* rightshift */ | |
249 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
250 | 16, /* bitsize */ | |
251 | false, /* pc_relative */ | |
252 | 0, /* bitpos */ | |
253 | complain_overflow_dont, /* complain_on_overflow */ | |
254 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
255 | "R_PPC64_ADDR16_HA", /* name */ | |
256 | false, /* partial_inplace */ | |
257 | 0, /* src_mask */ | |
258 | 0xffff, /* dst_mask */ | |
259 | false), /* pcrel_offset */ | |
260 | ||
261 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
262 | FIXME: we don't check that, we just clear them. */ | |
263 | HOWTO (R_PPC64_ADDR14, /* type */ | |
264 | 0, /* rightshift */ | |
265 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
266 | 16, /* bitsize */ | |
267 | false, /* pc_relative */ | |
268 | 0, /* bitpos */ | |
269 | complain_overflow_bitfield, /* complain_on_overflow */ | |
270 | bfd_elf_generic_reloc, /* special_function */ | |
271 | "R_PPC64_ADDR14", /* name */ | |
272 | false, /* partial_inplace */ | |
273 | 0, /* src_mask */ | |
274 | 0xfffc, /* dst_mask */ | |
275 | false), /* pcrel_offset */ | |
276 | ||
277 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
278 | indicate that the branch is expected to be taken. The lower two | |
279 | bits must be zero. */ | |
280 | HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */ | |
281 | 0, /* rightshift */ | |
282 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
283 | 16, /* bitsize */ | |
284 | false, /* pc_relative */ | |
285 | 0, /* bitpos */ | |
286 | complain_overflow_bitfield, /* complain_on_overflow */ | |
287 | bfd_elf_generic_reloc, /* special_function */ | |
288 | "R_PPC64_ADDR14_BRTAKEN",/* name */ | |
289 | false, /* partial_inplace */ | |
290 | 0, /* src_mask */ | |
291 | 0xfffc, /* dst_mask */ | |
292 | false), /* pcrel_offset */ | |
293 | ||
294 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
295 | indicate that the branch is not expected to be taken. The lower | |
296 | two bits must be zero. */ | |
297 | HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */ | |
298 | 0, /* rightshift */ | |
299 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
300 | 16, /* bitsize */ | |
301 | false, /* pc_relative */ | |
302 | 0, /* bitpos */ | |
303 | complain_overflow_bitfield, /* complain_on_overflow */ | |
304 | bfd_elf_generic_reloc, /* special_function */ | |
305 | "R_PPC64_ADDR14_BRNTAKEN",/* name */ | |
306 | false, /* partial_inplace */ | |
307 | 0, /* src_mask */ | |
308 | 0xfffc, /* dst_mask */ | |
309 | false), /* pcrel_offset */ | |
310 | ||
311 | /* A relative 26 bit branch; the lower two bits must be zero. */ | |
312 | HOWTO (R_PPC64_REL24, /* type */ | |
313 | 0, /* rightshift */ | |
314 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
315 | 26, /* bitsize */ | |
316 | true, /* pc_relative */ | |
317 | 0, /* bitpos */ | |
318 | complain_overflow_signed, /* complain_on_overflow */ | |
319 | bfd_elf_generic_reloc, /* special_function */ | |
320 | "R_PPC64_REL24", /* name */ | |
321 | false, /* partial_inplace */ | |
322 | 0, /* src_mask */ | |
323 | 0x3fffffc, /* dst_mask */ | |
324 | true), /* pcrel_offset */ | |
325 | ||
326 | /* A relative 16 bit branch; the lower two bits must be zero. */ | |
327 | HOWTO (R_PPC64_REL14, /* type */ | |
328 | 0, /* rightshift */ | |
329 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
330 | 16, /* bitsize */ | |
331 | true, /* pc_relative */ | |
332 | 0, /* bitpos */ | |
333 | complain_overflow_signed, /* complain_on_overflow */ | |
334 | bfd_elf_generic_reloc, /* special_function */ | |
335 | "R_PPC64_REL14", /* name */ | |
336 | false, /* partial_inplace */ | |
337 | 0, /* src_mask */ | |
338 | 0xfffc, /* dst_mask */ | |
339 | true), /* pcrel_offset */ | |
340 | ||
341 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
342 | the branch is expected to be taken. The lower two bits must be | |
343 | zero. */ | |
344 | HOWTO (R_PPC64_REL14_BRTAKEN, /* type */ | |
345 | 0, /* rightshift */ | |
346 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
347 | 16, /* bitsize */ | |
348 | true, /* pc_relative */ | |
349 | 0, /* bitpos */ | |
350 | complain_overflow_signed, /* complain_on_overflow */ | |
351 | bfd_elf_generic_reloc, /* special_function */ | |
352 | "R_PPC64_REL14_BRTAKEN", /* name */ | |
353 | false, /* partial_inplace */ | |
354 | 0, /* src_mask */ | |
355 | 0xfffc, /* dst_mask */ | |
356 | true), /* pcrel_offset */ | |
357 | ||
358 | /* A relative 16 bit branch. Bit 10 should be set to indicate that | |
359 | the branch is not expected to be taken. The lower two bits must | |
360 | be zero. */ | |
361 | HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */ | |
362 | 0, /* rightshift */ | |
363 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
364 | 16, /* bitsize */ | |
365 | true, /* pc_relative */ | |
366 | 0, /* bitpos */ | |
367 | complain_overflow_signed, /* complain_on_overflow */ | |
368 | bfd_elf_generic_reloc, /* special_function */ | |
369 | "R_PPC64_REL14_BRNTAKEN",/* name */ | |
370 | false, /* partial_inplace */ | |
371 | 0, /* src_mask */ | |
372 | 0xfffc, /* dst_mask */ | |
373 | true), /* pcrel_offset */ | |
374 | ||
375 | /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the | |
376 | symbol. */ | |
377 | HOWTO (R_PPC64_GOT16, /* type */ | |
378 | 0, /* rightshift */ | |
379 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
380 | 16, /* bitsize */ | |
381 | false, /* pc_relative */ | |
382 | 0, /* bitpos */ | |
383 | complain_overflow_signed, /* complain_on_overflow */ | |
384 | bfd_elf_generic_reloc, /* special_function */ | |
385 | "R_PPC64_GOT16", /* name */ | |
386 | false, /* partial_inplace */ | |
387 | 0, /* src_mask */ | |
388 | 0xffff, /* dst_mask */ | |
389 | false), /* pcrel_offset */ | |
390 | ||
391 | /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for | |
392 | the symbol. */ | |
393 | HOWTO (R_PPC64_GOT16_LO, /* type */ | |
394 | 0, /* rightshift */ | |
395 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
396 | 16, /* bitsize */ | |
397 | false, /* pc_relative */ | |
398 | 0, /* bitpos */ | |
399 | complain_overflow_dont, /* complain_on_overflow */ | |
400 | bfd_elf_generic_reloc, /* special_function */ | |
401 | "R_PPC64_GOT16_LO", /* name */ | |
402 | false, /* partial_inplace */ | |
403 | 0, /* src_mask */ | |
404 | 0xffff, /* dst_mask */ | |
405 | false), /* pcrel_offset */ | |
406 | ||
407 | /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for | |
408 | the symbol. */ | |
409 | HOWTO (R_PPC64_GOT16_HI, /* type */ | |
410 | 16, /* rightshift */ | |
411 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
412 | 16, /* bitsize */ | |
413 | false, /* pc_relative */ | |
414 | 0, /* bitpos */ | |
415 | complain_overflow_dont,/* complain_on_overflow */ | |
416 | bfd_elf_generic_reloc, /* special_function */ | |
417 | "R_PPC64_GOT16_HI", /* name */ | |
418 | false, /* partial_inplace */ | |
419 | 0, /* src_mask */ | |
420 | 0xffff, /* dst_mask */ | |
421 | false), /* pcrel_offset */ | |
422 | ||
423 | /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for | |
424 | the symbol. */ | |
425 | HOWTO (R_PPC64_GOT16_HA, /* type */ | |
426 | 16, /* rightshift */ | |
427 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
428 | 16, /* bitsize */ | |
429 | false, /* pc_relative */ | |
430 | 0, /* bitpos */ | |
431 | complain_overflow_dont,/* complain_on_overflow */ | |
432 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
433 | "R_PPC64_GOT16_HA", /* name */ | |
434 | false, /* partial_inplace */ | |
435 | 0, /* src_mask */ | |
436 | 0xffff, /* dst_mask */ | |
437 | false), /* pcrel_offset */ | |
438 | ||
439 | /* This is used only by the dynamic linker. The symbol should exist | |
440 | both in the object being run and in some shared library. The | |
441 | dynamic linker copies the data addressed by the symbol from the | |
442 | shared library into the object, because the object being | |
443 | run has to have the data at some particular address. */ | |
444 | HOWTO (R_PPC64_COPY, /* type */ | |
445 | 0, /* rightshift */ | |
446 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
447 | 32, /* bitsize */ | |
448 | false, /* pc_relative */ | |
449 | 0, /* bitpos */ | |
450 | complain_overflow_bitfield, /* complain_on_overflow */ | |
451 | bfd_elf_generic_reloc, /* special_function */ | |
452 | "R_PPC64_COPY", /* name */ | |
453 | false, /* partial_inplace */ | |
454 | 0, /* src_mask */ | |
455 | 0, /* dst_mask */ | |
456 | false), /* pcrel_offset */ | |
457 | ||
458 | /* Like R_PPC64_ADDR64, but used when setting global offset table | |
459 | entries. */ | |
460 | HOWTO (R_PPC64_GLOB_DAT, /* type */ | |
461 | 0, /* rightshift */ | |
462 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
463 | 64, /* bitsize */ | |
464 | false, /* pc_relative */ | |
465 | 0, /* bitpos */ | |
466 | complain_overflow_dont, /* complain_on_overflow */ | |
467 | bfd_elf_generic_reloc, /* special_function */ | |
468 | "R_PPC64_GLOB_DAT", /* name */ | |
469 | false, /* partial_inplace */ | |
470 | 0, /* src_mask */ | |
471 | 0xffffffffffffffff, /* dst_mask */ | |
472 | false), /* pcrel_offset */ | |
473 | ||
474 | /* Created by the link editor. Marks a procedure linkage table | |
475 | entry for a symbol. */ | |
476 | HOWTO (R_PPC64_JMP_SLOT, /* type */ | |
477 | 0, /* rightshift */ | |
478 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
479 | 0, /* bitsize */ | |
480 | false, /* pc_relative */ | |
481 | 0, /* bitpos */ | |
482 | complain_overflow_dont, /* complain_on_overflow */ | |
483 | bfd_elf_generic_reloc, /* special_function */ | |
484 | "R_PPC64_JMP_SLOT", /* name */ | |
485 | false, /* partial_inplace */ | |
486 | 0, /* src_mask */ | |
487 | 0, /* dst_mask */ | |
488 | false), /* pcrel_offset */ | |
489 | ||
490 | /* Used only by the dynamic linker. When the object is run, this | |
491 | doubleword64 is set to the load address of the object, plus the | |
492 | addend. */ | |
493 | HOWTO (R_PPC64_RELATIVE, /* type */ | |
494 | 0, /* rightshift */ | |
495 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
496 | 64, /* bitsize */ | |
497 | false, /* pc_relative */ | |
498 | 0, /* bitpos */ | |
499 | complain_overflow_dont, /* complain_on_overflow */ | |
500 | bfd_elf_generic_reloc, /* special_function */ | |
501 | "R_PPC64_RELATIVE", /* name */ | |
502 | false, /* partial_inplace */ | |
503 | 0, /* src_mask */ | |
504 | 0xffffffffffffffff, /* dst_mask */ | |
505 | false), /* pcrel_offset */ | |
506 | ||
507 | /* Like R_PPC64_ADDR32, but may be unaligned. */ | |
508 | HOWTO (R_PPC64_UADDR32, /* type */ | |
509 | 0, /* rightshift */ | |
510 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
511 | 32, /* bitsize */ | |
512 | false, /* pc_relative */ | |
513 | 0, /* bitpos */ | |
514 | complain_overflow_bitfield, /* complain_on_overflow */ | |
515 | bfd_elf_generic_reloc, /* special_function */ | |
516 | "R_PPC64_UADDR32", /* name */ | |
517 | false, /* partial_inplace */ | |
518 | 0, /* src_mask */ | |
519 | 0xffffffff, /* dst_mask */ | |
520 | false), /* pcrel_offset */ | |
521 | ||
522 | /* Like R_PPC64_ADDR16, but may be unaligned. */ | |
523 | HOWTO (R_PPC64_UADDR16, /* type */ | |
524 | 0, /* rightshift */ | |
525 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
526 | 16, /* bitsize */ | |
527 | false, /* pc_relative */ | |
528 | 0, /* bitpos */ | |
529 | complain_overflow_bitfield, /* complain_on_overflow */ | |
530 | bfd_elf_generic_reloc, /* special_function */ | |
531 | "R_PPC64_UADDR16", /* name */ | |
532 | false, /* partial_inplace */ | |
533 | 0, /* src_mask */ | |
534 | 0xffff, /* dst_mask */ | |
535 | false), /* pcrel_offset */ | |
536 | ||
537 | /* 32-bit PC relative. */ | |
538 | HOWTO (R_PPC64_REL32, /* type */ | |
539 | 0, /* rightshift */ | |
540 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
541 | 32, /* bitsize */ | |
542 | true, /* pc_relative */ | |
543 | 0, /* bitpos */ | |
544 | /* FIXME: Verify. Was complain_overflow_bitfield. */ | |
545 | complain_overflow_signed, /* complain_on_overflow */ | |
546 | bfd_elf_generic_reloc, /* special_function */ | |
547 | "R_PPC64_REL32", /* name */ | |
548 | false, /* partial_inplace */ | |
549 | 0, /* src_mask */ | |
550 | 0xffffffff, /* dst_mask */ | |
551 | true), /* pcrel_offset */ | |
552 | ||
10ed1bba | 553 | /* 32-bit relocation to the symbol's procedure linkage table. */ |
5bd4f169 AM |
554 | HOWTO (R_PPC64_PLT32, /* type */ |
555 | 0, /* rightshift */ | |
556 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
557 | 32, /* bitsize */ | |
558 | false, /* pc_relative */ | |
559 | 0, /* bitpos */ | |
560 | complain_overflow_bitfield, /* complain_on_overflow */ | |
561 | bfd_elf_generic_reloc, /* special_function */ | |
562 | "R_PPC64_PLT32", /* name */ | |
563 | false, /* partial_inplace */ | |
564 | 0, /* src_mask */ | |
565 | 0, /* dst_mask */ | |
566 | false), /* pcrel_offset */ | |
567 | ||
568 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
569 | FIXME: R_PPC64_PLTREL32 not supported. */ | |
570 | HOWTO (R_PPC64_PLTREL32, /* type */ | |
571 | 0, /* rightshift */ | |
572 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
573 | 32, /* bitsize */ | |
574 | true, /* pc_relative */ | |
575 | 0, /* bitpos */ | |
576 | complain_overflow_signed, /* complain_on_overflow */ | |
577 | bfd_elf_generic_reloc, /* special_function */ | |
578 | "R_PPC64_PLTREL32", /* name */ | |
579 | false, /* partial_inplace */ | |
580 | 0, /* src_mask */ | |
581 | 0, /* dst_mask */ | |
582 | true), /* pcrel_offset */ | |
583 | ||
584 | /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for | |
585 | the symbol. */ | |
586 | HOWTO (R_PPC64_PLT16_LO, /* type */ | |
587 | 0, /* rightshift */ | |
588 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
589 | 16, /* bitsize */ | |
590 | false, /* pc_relative */ | |
591 | 0, /* bitpos */ | |
592 | complain_overflow_dont, /* complain_on_overflow */ | |
593 | bfd_elf_generic_reloc, /* special_function */ | |
594 | "R_PPC64_PLT16_LO", /* name */ | |
595 | false, /* partial_inplace */ | |
596 | 0, /* src_mask */ | |
597 | 0xffff, /* dst_mask */ | |
598 | false), /* pcrel_offset */ | |
599 | ||
600 | /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for | |
601 | the symbol. */ | |
602 | HOWTO (R_PPC64_PLT16_HI, /* type */ | |
603 | 16, /* rightshift */ | |
604 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
605 | 16, /* bitsize */ | |
606 | false, /* pc_relative */ | |
607 | 0, /* bitpos */ | |
608 | complain_overflow_dont, /* complain_on_overflow */ | |
609 | bfd_elf_generic_reloc, /* special_function */ | |
610 | "R_PPC64_PLT16_HI", /* name */ | |
611 | false, /* partial_inplace */ | |
612 | 0, /* src_mask */ | |
613 | 0xffff, /* dst_mask */ | |
614 | false), /* pcrel_offset */ | |
615 | ||
616 | /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for | |
617 | the symbol. */ | |
618 | HOWTO (R_PPC64_PLT16_HA, /* type */ | |
619 | 16, /* rightshift */ | |
620 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
621 | 16, /* bitsize */ | |
622 | false, /* pc_relative */ | |
623 | 0, /* bitpos */ | |
624 | complain_overflow_dont, /* complain_on_overflow */ | |
625 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
626 | "R_PPC64_PLT16_HA", /* name */ | |
627 | false, /* partial_inplace */ | |
628 | 0, /* src_mask */ | |
629 | 0xffff, /* dst_mask */ | |
630 | false), /* pcrel_offset */ | |
631 | ||
632 | /* 32-bit section relative relocation. */ | |
633 | /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and | |
634 | dst_mask=0. */ | |
635 | HOWTO (R_PPC64_SECTOFF, /* type */ | |
636 | 0, /* rightshift */ | |
637 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
638 | 32, /* bitsize */ | |
639 | true, /* pc_relative */ | |
640 | 0, /* bitpos */ | |
641 | complain_overflow_bitfield, /* complain_on_overflow */ | |
642 | bfd_elf_generic_reloc, /* special_function */ | |
643 | "R_PPC64_SECTOFF", /* name */ | |
644 | false, /* partial_inplace */ | |
645 | 0, /* src_mask */ | |
646 | 0, /* dst_mask */ | |
647 | true), /* pcrel_offset */ | |
648 | ||
649 | /* 16-bit lower half section relative relocation. */ | |
650 | HOWTO (R_PPC64_SECTOFF_LO, /* type */ | |
651 | 0, /* rightshift */ | |
652 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
653 | 16, /* bitsize */ | |
654 | false, /* pc_relative */ | |
655 | 0, /* bitpos */ | |
656 | complain_overflow_dont, /* complain_on_overflow */ | |
657 | bfd_elf_generic_reloc, /* special_function */ | |
658 | "R_PPC64_SECTOFF_LO", /* name */ | |
659 | false, /* partial_inplace */ | |
660 | 0, /* src_mask */ | |
661 | 0xffff, /* dst_mask */ | |
662 | false), /* pcrel_offset */ | |
663 | ||
664 | /* 16-bit upper half section relative relocation. */ | |
665 | HOWTO (R_PPC64_SECTOFF_HI, /* type */ | |
666 | 16, /* rightshift */ | |
667 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
668 | 16, /* bitsize */ | |
669 | false, /* pc_relative */ | |
670 | 0, /* bitpos */ | |
671 | complain_overflow_dont, /* complain_on_overflow */ | |
672 | bfd_elf_generic_reloc, /* special_function */ | |
673 | "R_PPC64_SECTOFF_HI", /* name */ | |
674 | false, /* partial_inplace */ | |
675 | 0, /* src_mask */ | |
676 | 0xffff, /* dst_mask */ | |
677 | false), /* pcrel_offset */ | |
678 | ||
679 | /* 16-bit upper half adjusted section relative relocation. */ | |
680 | HOWTO (R_PPC64_SECTOFF_HA, /* type */ | |
681 | 16, /* rightshift */ | |
682 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
683 | 16, /* bitsize */ | |
684 | false, /* pc_relative */ | |
685 | 0, /* bitpos */ | |
686 | complain_overflow_dont, /* complain_on_overflow */ | |
687 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
688 | "R_PPC64_SECTOFF_HA", /* name */ | |
689 | false, /* partial_inplace */ | |
690 | 0, /* src_mask */ | |
691 | 0xffff, /* dst_mask */ | |
692 | false), /* pcrel_offset */ | |
693 | ||
694 | /* Like R_PPC64_REL24 without touching the two least significant | |
695 | bits. */ | |
696 | /* FIXME: Verify R_PPC64_ADDR30. */ | |
697 | HOWTO (R_PPC64_ADDR30, /* type */ | |
698 | 2, /* rightshift */ | |
699 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
700 | 30, /* bitsize */ | |
701 | true, /* pc_relative */ | |
702 | 0, /* bitpos */ | |
703 | complain_overflow_dont, /* complain_on_overflow */ | |
704 | bfd_elf_generic_reloc, /* special_function */ | |
705 | "R_PPC64_ADDR30", /* name */ | |
706 | false, /* partial_inplace */ | |
707 | 0, /* src_mask */ | |
708 | 0xfffffffc, /* dst_mask */ | |
709 | true), /* pcrel_offset */ | |
710 | ||
711 | /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */ | |
712 | ||
713 | /* A standard 64-bit relocation. */ | |
714 | HOWTO (R_PPC64_ADDR64, /* type */ | |
715 | 0, /* rightshift */ | |
716 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
717 | 64, /* bitsize */ | |
718 | false, /* pc_relative */ | |
719 | 0, /* bitpos */ | |
720 | complain_overflow_dont, /* complain_on_overflow */ | |
721 | bfd_elf_generic_reloc, /* special_function */ | |
722 | "R_PPC64_ADDR64", /* name */ | |
723 | false, /* partial_inplace */ | |
724 | 0, /* src_mask */ | |
725 | 0xffffffffffffffff, /* dst_mask */ | |
726 | false), /* pcrel_offset */ | |
727 | ||
728 | /* The bits 32-47 of an address. */ | |
729 | HOWTO (R_PPC64_ADDR16_HIGHER, /* type */ | |
730 | 32, /* rightshift */ | |
731 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
732 | 16, /* bitsize */ | |
733 | false, /* pc_relative */ | |
734 | 0, /* bitpos */ | |
735 | complain_overflow_dont, /* complain_on_overflow */ | |
736 | bfd_elf_generic_reloc, /* special_function */ | |
737 | "R_PPC64_ADDR16_HIGHER", /* name */ | |
738 | false, /* partial_inplace */ | |
739 | 0, /* src_mask */ | |
740 | 0xffff, /* dst_mask */ | |
741 | false), /* pcrel_offset */ | |
742 | ||
743 | /* The bits 32-47 of an address, plus 1 if the contents of the low | |
744 | 16 bits, treated as a signed number, is negative. */ | |
745 | HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */ | |
746 | 32, /* rightshift */ | |
747 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
748 | 16, /* bitsize */ | |
749 | false, /* pc_relative */ | |
750 | 0, /* bitpos */ | |
751 | complain_overflow_dont, /* complain_on_overflow */ | |
752 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
753 | "R_PPC64_ADDR16_HIGHERA", /* name */ | |
754 | false, /* partial_inplace */ | |
755 | 0, /* src_mask */ | |
756 | 0xffff, /* dst_mask */ | |
757 | false), /* pcrel_offset */ | |
758 | ||
759 | /* The bits 48-63 of an address. */ | |
760 | HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */ | |
761 | 48, /* rightshift */ | |
762 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
763 | 16, /* bitsize */ | |
764 | false, /* pc_relative */ | |
765 | 0, /* bitpos */ | |
766 | complain_overflow_dont, /* complain_on_overflow */ | |
767 | bfd_elf_generic_reloc, /* special_function */ | |
768 | "R_PPC64_ADDR16_HIGHEST", /* name */ | |
769 | false, /* partial_inplace */ | |
770 | 0, /* src_mask */ | |
771 | 0xffff, /* dst_mask */ | |
772 | false), /* pcrel_offset */ | |
773 | ||
774 | /* The bits 48-63 of an address, plus 1 if the contents of the low | |
775 | 16 bits, treated as a signed number, is negative. */ | |
776 | HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */ | |
777 | 48, /* rightshift */ | |
778 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
779 | 16, /* bitsize */ | |
780 | false, /* pc_relative */ | |
781 | 0, /* bitpos */ | |
782 | complain_overflow_dont, /* complain_on_overflow */ | |
783 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
784 | "R_PPC64_ADDR16_HIGHESTA", /* name */ | |
785 | false, /* partial_inplace */ | |
786 | 0, /* src_mask */ | |
787 | 0xffff, /* dst_mask */ | |
788 | false), /* pcrel_offset */ | |
789 | ||
790 | /* Like ADDR64, but may be unaligned. */ | |
791 | HOWTO (R_PPC64_UADDR64, /* type */ | |
792 | 0, /* rightshift */ | |
793 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
794 | 64, /* bitsize */ | |
795 | false, /* pc_relative */ | |
796 | 0, /* bitpos */ | |
797 | complain_overflow_dont, /* complain_on_overflow */ | |
798 | bfd_elf_generic_reloc, /* special_function */ | |
799 | "R_PPC64_UADDR64", /* name */ | |
800 | false, /* partial_inplace */ | |
801 | 0, /* src_mask */ | |
802 | 0xffffffffffffffff, /* dst_mask */ | |
803 | false), /* pcrel_offset */ | |
804 | ||
805 | /* 64-bit relative relocation. */ | |
806 | HOWTO (R_PPC64_REL64, /* type */ | |
807 | 0, /* rightshift */ | |
808 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
809 | 64, /* bitsize */ | |
810 | true, /* pc_relative */ | |
811 | 0, /* bitpos */ | |
812 | complain_overflow_dont, /* complain_on_overflow */ | |
813 | bfd_elf_generic_reloc, /* special_function */ | |
814 | "R_PPC64_REL64", /* name */ | |
815 | false, /* partial_inplace */ | |
816 | 0, /* src_mask */ | |
817 | 0xffffffffffffffff, /* dst_mask */ | |
818 | true), /* pcrel_offset */ | |
819 | ||
820 | /* 64-bit relocation to the symbol's procedure linkage table. */ | |
5bd4f169 AM |
821 | HOWTO (R_PPC64_PLT64, /* type */ |
822 | 0, /* rightshift */ | |
823 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
824 | 64, /* bitsize */ | |
825 | false, /* pc_relative */ | |
826 | 0, /* bitpos */ | |
827 | complain_overflow_dont, /* complain_on_overflow */ | |
828 | bfd_elf_generic_reloc, /* special_function */ | |
829 | "R_PPC64_PLT64", /* name */ | |
830 | false, /* partial_inplace */ | |
831 | 0, /* src_mask */ | |
832 | 0, /* dst_mask */ | |
833 | false), /* pcrel_offset */ | |
834 | ||
835 | /* 64-bit PC relative relocation to the symbol's procedure linkage | |
836 | table. */ | |
837 | /* FIXME: R_PPC64_PLTREL64 not supported. */ | |
838 | HOWTO (R_PPC64_PLTREL64, /* type */ | |
839 | 0, /* rightshift */ | |
840 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
841 | 64, /* bitsize */ | |
842 | true, /* pc_relative */ | |
843 | 0, /* bitpos */ | |
844 | complain_overflow_dont, /* complain_on_overflow */ | |
845 | bfd_elf_generic_reloc, /* special_function */ | |
846 | "R_PPC64_PLTREL64", /* name */ | |
847 | false, /* partial_inplace */ | |
848 | 0, /* src_mask */ | |
849 | 0, /* dst_mask */ | |
850 | true), /* pcrel_offset */ | |
851 | ||
852 | /* 16 bit TOC-relative relocation. */ | |
853 | ||
854 | /* R_PPC64_TOC16 47 half16* S + A - .TOC. */ | |
855 | HOWTO (R_PPC64_TOC16, /* type */ | |
856 | 0, /* rightshift */ | |
857 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
858 | 16, /* bitsize */ | |
859 | false, /* pc_relative */ | |
860 | 0, /* bitpos */ | |
861 | complain_overflow_signed, /* complain_on_overflow */ | |
862 | bfd_elf_generic_reloc, /* special_function */ | |
863 | "R_PPC64_TOC16", /* name */ | |
864 | false, /* partial_inplace */ | |
865 | 0, /* src_mask */ | |
866 | 0xffff, /* dst_mask */ | |
867 | false), /* pcrel_offset */ | |
868 | ||
869 | /* 16 bit TOC-relative relocation without overflow. */ | |
870 | ||
871 | /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */ | |
872 | HOWTO (R_PPC64_TOC16_LO, /* type */ | |
873 | 0, /* rightshift */ | |
874 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
875 | 16, /* bitsize */ | |
876 | false, /* pc_relative */ | |
877 | 0, /* bitpos */ | |
878 | complain_overflow_dont, /* complain_on_overflow */ | |
879 | bfd_elf_generic_reloc, /* special_function */ | |
880 | "R_PPC64_TOC16_LO", /* name */ | |
881 | false, /* partial_inplace */ | |
882 | 0, /* src_mask */ | |
883 | 0xffff, /* dst_mask */ | |
884 | false), /* pcrel_offset */ | |
885 | ||
886 | /* 16 bit TOC-relative relocation, high 16 bits. */ | |
887 | ||
888 | /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */ | |
889 | HOWTO (R_PPC64_TOC16_HI, /* type */ | |
890 | 16, /* rightshift */ | |
891 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
892 | 16, /* bitsize */ | |
893 | false, /* pc_relative */ | |
894 | 0, /* bitpos */ | |
895 | complain_overflow_dont, /* complain_on_overflow */ | |
896 | bfd_elf_generic_reloc, /* special_function */ | |
897 | "R_PPC64_TOC16_HI", /* name */ | |
898 | false, /* partial_inplace */ | |
899 | 0, /* src_mask */ | |
900 | 0xffff, /* dst_mask */ | |
901 | false), /* pcrel_offset */ | |
902 | ||
903 | /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the | |
904 | contents of the low 16 bits, treated as a signed number, is | |
905 | negative. */ | |
906 | ||
907 | /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */ | |
908 | HOWTO (R_PPC64_TOC16_HA, /* type */ | |
909 | 16, /* rightshift */ | |
910 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
911 | 16, /* bitsize */ | |
912 | false, /* pc_relative */ | |
913 | 0, /* bitpos */ | |
914 | complain_overflow_dont, /* complain_on_overflow */ | |
915 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
916 | "R_PPC64_TOC16_HA", /* name */ | |
917 | false, /* partial_inplace */ | |
918 | 0, /* src_mask */ | |
919 | 0xffff, /* dst_mask */ | |
920 | false), /* pcrel_offset */ | |
921 | ||
922 | /* 64-bit relocation; insert value of TOC base (.TOC.). */ | |
923 | ||
924 | /* R_PPC64_TOC 51 doubleword64 .TOC. */ | |
925 | HOWTO (R_PPC64_TOC, /* type */ | |
926 | 0, /* rightshift */ | |
927 | 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */ | |
928 | 64, /* bitsize */ | |
929 | false, /* pc_relative */ | |
930 | 0, /* bitpos */ | |
931 | complain_overflow_bitfield, /* complain_on_overflow */ | |
932 | bfd_elf_generic_reloc, /* special_function */ | |
933 | "R_PPC64_TOC", /* name */ | |
934 | false, /* partial_inplace */ | |
935 | 0, /* src_mask */ | |
936 | 0xffffffffffffffff, /* dst_mask */ | |
937 | false), /* pcrel_offset */ | |
938 | ||
939 | /* Like R_PPC64_GOT16, but also informs the link editor that the | |
940 | value to relocate may (!) refer to a PLT entry which the link | |
941 | editor (a) may replace with the symbol value. If the link editor | |
942 | is unable to fully resolve the symbol, it may (b) create a PLT | |
943 | entry and store the address to the new PLT entry in the GOT. | |
944 | This permits lazy resolution of function symbols at run time. | |
945 | The link editor may also skip all of this and just (c) emit a | |
946 | R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */ | |
947 | /* FIXME: R_PPC64_PLTGOT16 not implemented. */ | |
948 | HOWTO (R_PPC64_PLTGOT16, /* type */ | |
949 | 0, /* rightshift */ | |
950 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
951 | 16, /* bitsize */ | |
952 | false, /* pc_relative */ | |
953 | 0, /* bitpos */ | |
954 | complain_overflow_signed, /* complain_on_overflow */ | |
955 | bfd_elf_generic_reloc, /* special_function */ | |
956 | "R_PPC64_PLTGOT16", /* name */ | |
957 | false, /* partial_inplace */ | |
958 | 0, /* src_mask */ | |
959 | 0xffff, /* dst_mask */ | |
960 | false), /* pcrel_offset */ | |
961 | ||
962 | /* Like R_PPC64_PLTGOT16, but without overflow. */ | |
963 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
964 | HOWTO (R_PPC64_PLTGOT16_LO, /* type */ | |
965 | 0, /* rightshift */ | |
966 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
967 | 16, /* bitsize */ | |
968 | false, /* pc_relative */ | |
969 | 0, /* bitpos */ | |
970 | complain_overflow_dont, /* complain_on_overflow */ | |
971 | bfd_elf_generic_reloc, /* special_function */ | |
972 | "R_PPC64_PLTGOT16_LO", /* name */ | |
973 | false, /* partial_inplace */ | |
974 | 0, /* src_mask */ | |
975 | 0xffff, /* dst_mask */ | |
976 | false), /* pcrel_offset */ | |
977 | ||
978 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */ | |
979 | /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */ | |
980 | HOWTO (R_PPC64_PLTGOT16_HI, /* type */ | |
981 | 16, /* rightshift */ | |
982 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
983 | 16, /* bitsize */ | |
984 | false, /* pc_relative */ | |
985 | 0, /* bitpos */ | |
986 | complain_overflow_dont, /* complain_on_overflow */ | |
987 | bfd_elf_generic_reloc, /* special_function */ | |
988 | "R_PPC64_PLTGOT16_HI", /* name */ | |
989 | false, /* partial_inplace */ | |
990 | 0, /* src_mask */ | |
991 | 0xffff, /* dst_mask */ | |
992 | false), /* pcrel_offset */ | |
993 | ||
994 | /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus | |
995 | 1 if the contents of the low 16 bits, treated as a signed number, | |
996 | is negative. */ | |
997 | /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */ | |
998 | HOWTO (R_PPC64_PLTGOT16_HA, /* type */ | |
999 | 16, /* rightshift */ | |
1000 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1001 | 16, /* bitsize */ | |
1002 | false, /* pc_relative */ | |
1003 | 0, /* bitpos */ | |
1004 | complain_overflow_dont,/* complain_on_overflow */ | |
1005 | ppc64_elf_addr16_ha_reloc, /* special_function */ | |
1006 | "R_PPC64_PLTGOT16_HA", /* name */ | |
1007 | false, /* partial_inplace */ | |
1008 | 0, /* src_mask */ | |
1009 | 0xffff, /* dst_mask */ | |
1010 | false), /* pcrel_offset */ | |
1011 | ||
1012 | /* Like R_PPC64_ADDR16, but for instructions with a DS field. */ | |
1013 | HOWTO (R_PPC64_ADDR16_DS, /* type */ | |
1014 | 0, /* rightshift */ | |
1015 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1016 | 16, /* bitsize */ | |
1017 | false, /* pc_relative */ | |
1018 | 0, /* bitpos */ | |
1019 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1020 | bfd_elf_generic_reloc, /* special_function */ | |
1021 | "R_PPC64_ADDR16_DS", /* name */ | |
1022 | false, /* partial_inplace */ | |
1023 | 0, /* src_mask */ | |
1024 | 0xfffc, /* dst_mask */ | |
1025 | false), /* pcrel_offset */ | |
1026 | ||
1027 | /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */ | |
1028 | HOWTO (R_PPC64_ADDR16_LO_DS, /* type */ | |
1029 | 0, /* rightshift */ | |
1030 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1031 | 16, /* bitsize */ | |
1032 | false, /* pc_relative */ | |
1033 | 0, /* bitpos */ | |
1034 | complain_overflow_dont,/* complain_on_overflow */ | |
1035 | bfd_elf_generic_reloc, /* special_function */ | |
1036 | "R_PPC64_ADDR16_LO_DS",/* name */ | |
1037 | false, /* partial_inplace */ | |
1038 | 0, /* src_mask */ | |
1039 | 0xfffc, /* dst_mask */ | |
1040 | false), /* pcrel_offset */ | |
1041 | ||
1042 | /* Like R_PPC64_GOT16, but for instructions with a DS field. */ | |
1043 | HOWTO (R_PPC64_GOT16_DS, /* type */ | |
1044 | 0, /* rightshift */ | |
1045 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1046 | 16, /* bitsize */ | |
1047 | false, /* pc_relative */ | |
1048 | 0, /* bitpos */ | |
1049 | complain_overflow_signed, /* complain_on_overflow */ | |
1050 | bfd_elf_generic_reloc, /* special_function */ | |
1051 | "R_PPC64_GOT16_DS", /* name */ | |
1052 | false, /* partial_inplace */ | |
1053 | 0, /* src_mask */ | |
1054 | 0xfffc, /* dst_mask */ | |
1055 | false), /* pcrel_offset */ | |
1056 | ||
1057 | /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */ | |
1058 | HOWTO (R_PPC64_GOT16_LO_DS, /* type */ | |
1059 | 0, /* rightshift */ | |
1060 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1061 | 16, /* bitsize */ | |
1062 | false, /* pc_relative */ | |
1063 | 0, /* bitpos */ | |
1064 | complain_overflow_dont, /* complain_on_overflow */ | |
1065 | bfd_elf_generic_reloc, /* special_function */ | |
1066 | "R_PPC64_GOT16_LO_DS", /* name */ | |
1067 | false, /* partial_inplace */ | |
1068 | 0, /* src_mask */ | |
1069 | 0xfffc, /* dst_mask */ | |
1070 | false), /* pcrel_offset */ | |
1071 | ||
1072 | /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */ | |
1073 | HOWTO (R_PPC64_PLT16_LO_DS, /* type */ | |
1074 | 0, /* rightshift */ | |
1075 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1076 | 16, /* bitsize */ | |
1077 | false, /* pc_relative */ | |
1078 | 0, /* bitpos */ | |
1079 | complain_overflow_dont, /* complain_on_overflow */ | |
1080 | bfd_elf_generic_reloc, /* special_function */ | |
1081 | "R_PPC64_PLT16_LO_DS", /* name */ | |
1082 | false, /* partial_inplace */ | |
1083 | 0, /* src_mask */ | |
1084 | 0xfffc, /* dst_mask */ | |
1085 | false), /* pcrel_offset */ | |
1086 | ||
1087 | /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */ | |
1088 | /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and | |
1089 | dst_mask=0. */ | |
1090 | HOWTO (R_PPC64_SECTOFF_DS, /* type */ | |
1091 | 0, /* rightshift */ | |
1092 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1093 | 32, /* bitsize */ | |
1094 | true, /* pc_relative */ | |
1095 | 0, /* bitpos */ | |
1096 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1097 | bfd_elf_generic_reloc, /* special_function */ | |
1098 | "R_PPC64_SECTOFF_DS", /* name */ | |
1099 | false, /* partial_inplace */ | |
1100 | 0, /* src_mask */ | |
1101 | 0, /* dst_mask */ | |
1102 | true), /* pcrel_offset */ | |
1103 | ||
1104 | /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */ | |
1105 | HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */ | |
1106 | 0, /* rightshift */ | |
1107 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1108 | 16, /* bitsize */ | |
1109 | false, /* pc_relative */ | |
1110 | 0, /* bitpos */ | |
1111 | complain_overflow_dont, /* complain_on_overflow */ | |
1112 | bfd_elf_generic_reloc, /* special_function */ | |
1113 | "R_PPC64_SECTOFF_LO_DS",/* name */ | |
1114 | false, /* partial_inplace */ | |
1115 | 0, /* src_mask */ | |
1116 | 0xfffc, /* dst_mask */ | |
1117 | false), /* pcrel_offset */ | |
1118 | ||
1119 | /* Like R_PPC64_TOC16, but for instructions with a DS field. */ | |
1120 | HOWTO (R_PPC64_TOC16_DS, /* type */ | |
1121 | 0, /* rightshift */ | |
1122 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1123 | 16, /* bitsize */ | |
1124 | false, /* pc_relative */ | |
1125 | 0, /* bitpos */ | |
1126 | complain_overflow_signed, /* complain_on_overflow */ | |
1127 | bfd_elf_generic_reloc, /* special_function */ | |
1128 | "R_PPC64_TOC16_DS", /* name */ | |
1129 | false, /* partial_inplace */ | |
1130 | 0, /* src_mask */ | |
1131 | 0xfffc, /* dst_mask */ | |
1132 | false), /* pcrel_offset */ | |
1133 | ||
1134 | /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */ | |
1135 | HOWTO (R_PPC64_TOC16_LO_DS, /* type */ | |
1136 | 0, /* rightshift */ | |
1137 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1138 | 16, /* bitsize */ | |
1139 | false, /* pc_relative */ | |
1140 | 0, /* bitpos */ | |
1141 | complain_overflow_dont, /* complain_on_overflow */ | |
1142 | bfd_elf_generic_reloc, /* special_function */ | |
1143 | "R_PPC64_TOC16_LO_DS", /* name */ | |
1144 | false, /* partial_inplace */ | |
1145 | 0, /* src_mask */ | |
1146 | 0xfffc, /* dst_mask */ | |
1147 | false), /* pcrel_offset */ | |
1148 | ||
1149 | /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */ | |
1150 | /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */ | |
1151 | HOWTO (R_PPC64_PLTGOT16_DS, /* type */ | |
1152 | 0, /* rightshift */ | |
1153 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1154 | 16, /* bitsize */ | |
1155 | false, /* pc_relative */ | |
1156 | 0, /* bitpos */ | |
1157 | complain_overflow_signed, /* complain_on_overflow */ | |
1158 | bfd_elf_generic_reloc, /* special_function */ | |
1159 | "R_PPC64_PLTGOT16_DS", /* name */ | |
1160 | false, /* partial_inplace */ | |
1161 | 0, /* src_mask */ | |
1162 | 0xfffc, /* dst_mask */ | |
1163 | false), /* pcrel_offset */ | |
1164 | ||
1165 | /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */ | |
1166 | /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */ | |
1167 | HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */ | |
1168 | 0, /* rightshift */ | |
1169 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1170 | 16, /* bitsize */ | |
1171 | false, /* pc_relative */ | |
1172 | 0, /* bitpos */ | |
1173 | complain_overflow_dont, /* complain_on_overflow */ | |
1174 | bfd_elf_generic_reloc, /* special_function */ | |
1175 | "R_PPC64_PLTGOT16_LO_DS",/* name */ | |
1176 | false, /* partial_inplace */ | |
1177 | 0, /* src_mask */ | |
1178 | 0xfffc, /* dst_mask */ | |
1179 | false), /* pcrel_offset */ | |
1180 | ||
1181 | /* GNU extension to record C++ vtable hierarchy. */ | |
1182 | HOWTO (R_PPC64_GNU_VTINHERIT, /* type */ | |
1183 | 0, /* rightshift */ | |
1184 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1185 | 0, /* bitsize */ | |
1186 | false, /* pc_relative */ | |
1187 | 0, /* bitpos */ | |
1188 | complain_overflow_dont, /* complain_on_overflow */ | |
1189 | NULL, /* special_function */ | |
1190 | "R_PPC64_GNU_VTINHERIT", /* name */ | |
1191 | false, /* partial_inplace */ | |
1192 | 0, /* src_mask */ | |
1193 | 0, /* dst_mask */ | |
1194 | false), /* pcrel_offset */ | |
1195 | ||
1196 | /* GNU extension to record C++ vtable member usage. */ | |
1197 | HOWTO (R_PPC64_GNU_VTENTRY, /* type */ | |
1198 | 0, /* rightshift */ | |
1199 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1200 | 0, /* bitsize */ | |
1201 | false, /* pc_relative */ | |
1202 | 0, /* bitpos */ | |
1203 | complain_overflow_dont, /* complain_on_overflow */ | |
1204 | NULL, /* special_function */ | |
1205 | "R_PPC64_GNU_VTENTRY", /* name */ | |
1206 | false, /* partial_inplace */ | |
1207 | 0, /* src_mask */ | |
1208 | 0, /* dst_mask */ | |
1209 | false), /* pcrel_offset */ | |
1210 | }; | |
1211 | ||
1212 | \f | |
1213 | /* Initialize the ppc64_elf_howto_table, so that linear accesses can | |
1214 | be done. */ | |
1215 | ||
1216 | static void | |
1217 | ppc_howto_init () | |
1218 | { | |
1219 | unsigned int i, type; | |
1220 | ||
1221 | for (i = 0; | |
1222 | i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]); | |
1223 | i++) | |
1224 | { | |
1225 | type = ppc64_elf_howto_raw[i].type; | |
1226 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1227 | / sizeof (ppc64_elf_howto_table[0]))); | |
1228 | ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i]; | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | static reloc_howto_type * | |
1233 | ppc64_elf_reloc_type_lookup (abfd, code) | |
1234 | bfd *abfd ATTRIBUTE_UNUSED; | |
1235 | bfd_reloc_code_real_type code; | |
1236 | { | |
1237 | enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE; | |
1238 | ||
1239 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) | |
1240 | /* Initialize howto table if needed. */ | |
1241 | ppc_howto_init (); | |
1242 | ||
1243 | switch ((int) code) | |
1244 | { | |
1245 | default: | |
1246 | return (reloc_howto_type *) NULL; | |
1247 | ||
1248 | case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE; | |
1249 | break; | |
1250 | case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32; | |
1251 | break; | |
1252 | case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24; | |
1253 | break; | |
1254 | case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16; | |
1255 | break; | |
1256 | case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO; | |
1257 | break; | |
1258 | case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI; | |
1259 | break; | |
1260 | case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA; | |
1261 | break; | |
1262 | case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14; | |
1263 | break; | |
1264 | case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN; | |
1265 | break; | |
1266 | case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN; | |
1267 | break; | |
1268 | case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24; | |
1269 | break; | |
1270 | case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14; | |
1271 | break; | |
1272 | case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN; | |
1273 | break; | |
1274 | case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN; | |
1275 | break; | |
1276 | case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16; | |
1277 | break; | |
1278 | case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO; | |
1279 | break; | |
1280 | case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI; | |
1281 | break; | |
1282 | case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA; | |
1283 | break; | |
1284 | case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY; | |
1285 | break; | |
1286 | case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT; | |
1287 | break; | |
1288 | case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32; | |
1289 | break; | |
1290 | case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32; | |
1291 | break; | |
1292 | case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32; | |
1293 | break; | |
1294 | case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO; | |
1295 | break; | |
1296 | case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI; | |
1297 | break; | |
1298 | case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA; | |
1299 | break; | |
1300 | case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC64_SECTOFF; | |
1301 | break; | |
1302 | case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO; | |
1303 | break; | |
1304 | case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI; | |
1305 | break; | |
1306 | case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA; | |
1307 | break; | |
10ed1bba | 1308 | case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64; |
5bd4f169 AM |
1309 | break; |
1310 | case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64; | |
1311 | break; | |
1312 | case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER; | |
1313 | break; | |
1314 | case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA; | |
1315 | break; | |
1316 | case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST; | |
1317 | break; | |
1318 | case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA; | |
1319 | break; | |
1320 | case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64; | |
1321 | break; | |
1322 | case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64; | |
1323 | break; | |
1324 | case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64; | |
1325 | break; | |
1326 | case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16; | |
1327 | break; | |
1328 | case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO; | |
1329 | break; | |
1330 | case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI; | |
1331 | break; | |
1332 | case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA; | |
1333 | break; | |
1334 | case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC; | |
1335 | break; | |
1336 | case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16; | |
1337 | break; | |
1338 | case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO; | |
1339 | break; | |
1340 | case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI; | |
1341 | break; | |
1342 | case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA; | |
1343 | break; | |
1344 | case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS; | |
1345 | break; | |
1346 | case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS; | |
1347 | break; | |
1348 | case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS; | |
1349 | break; | |
1350 | case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS; | |
1351 | break; | |
1352 | case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS; | |
1353 | break; | |
1354 | case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS; | |
1355 | break; | |
1356 | case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS; | |
1357 | break; | |
1358 | case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS; | |
1359 | break; | |
1360 | case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS; | |
1361 | break; | |
1362 | case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS; | |
1363 | break; | |
1364 | case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS; | |
1365 | break; | |
1366 | case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT; | |
1367 | break; | |
1368 | case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY; | |
1369 | break; | |
1370 | } | |
1371 | ||
1372 | return ppc64_elf_howto_table[(int) ppc_reloc]; | |
1373 | }; | |
1374 | ||
1375 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
1376 | ||
1377 | static void | |
1378 | ppc64_elf_info_to_howto (abfd, cache_ptr, dst) | |
1379 | bfd *abfd ATTRIBUTE_UNUSED; | |
1380 | arelent *cache_ptr; | |
1381 | Elf64_Internal_Rela *dst; | |
1382 | { | |
65f38f15 AM |
1383 | unsigned int type; |
1384 | ||
5bd4f169 AM |
1385 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
1386 | /* Initialize howto table if needed. */ | |
1387 | ppc_howto_init (); | |
1388 | ||
65f38f15 AM |
1389 | type = ELF64_R_TYPE (dst->r_info); |
1390 | BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table) | |
1391 | / sizeof (ppc64_elf_howto_table[0]))); | |
1392 | cache_ptr->howto = ppc64_elf_howto_table[type]; | |
5bd4f169 AM |
1393 | } |
1394 | ||
65f38f15 | 1395 | /* Handle the R_PPC_ADDR16_HA and similar relocs. */ |
5bd4f169 AM |
1396 | |
1397 | static bfd_reloc_status_type | |
1398 | ppc64_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section, | |
1399 | output_bfd, error_message) | |
1400 | bfd *abfd ATTRIBUTE_UNUSED; | |
1401 | arelent *reloc_entry; | |
1402 | asymbol *symbol; | |
1403 | PTR data ATTRIBUTE_UNUSED; | |
1404 | asection *input_section; | |
1405 | bfd *output_bfd; | |
1406 | char **error_message ATTRIBUTE_UNUSED; | |
1407 | { | |
1408 | bfd_vma relocation; | |
1409 | ||
1410 | if (output_bfd != NULL) | |
1411 | { | |
1412 | reloc_entry->address += input_section->output_offset; | |
1413 | return bfd_reloc_ok; | |
1414 | } | |
1415 | ||
1416 | if (reloc_entry->address > input_section->_cooked_size) | |
1417 | return bfd_reloc_outofrange; | |
1418 | ||
1419 | if (bfd_is_com_section (symbol->section)) | |
1420 | relocation = 0; | |
1421 | else | |
1422 | relocation = symbol->value; | |
1423 | ||
1424 | relocation += symbol->section->output_section->vma; | |
1425 | relocation += symbol->section->output_offset; | |
1426 | relocation += reloc_entry->addend; | |
1427 | ||
1428 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
1429 | ||
1430 | return bfd_reloc_continue; | |
1431 | } | |
1432 | ||
1433 | /* Function to set whether a module needs the -mrelocatable bit set. */ | |
1434 | ||
1435 | static boolean | |
1436 | ppc64_elf_set_private_flags (abfd, flags) | |
1437 | bfd *abfd; | |
1438 | flagword flags; | |
1439 | { | |
1440 | BFD_ASSERT (!elf_flags_init (abfd) | |
1441 | || elf_elfheader (abfd)->e_flags == flags); | |
1442 | ||
1443 | elf_elfheader (abfd)->e_flags = flags; | |
1444 | elf_flags_init (abfd) = true; | |
1445 | return true; | |
1446 | } | |
1447 | ||
5bd4f169 AM |
1448 | /* Merge backend specific data from an object file to the output |
1449 | object file when linking. */ | |
1450 | static boolean | |
1451 | ppc64_elf_merge_private_bfd_data (ibfd, obfd) | |
1452 | bfd *ibfd; | |
1453 | bfd *obfd; | |
1454 | { | |
1455 | flagword old_flags; | |
1456 | flagword new_flags; | |
1457 | boolean error; | |
1458 | ||
1459 | /* Check if we have the same endianess. */ | |
1460 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder | |
1461 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) | |
1462 | { | |
1463 | const char *msg; | |
1464 | ||
1465 | if (bfd_big_endian (ibfd)) | |
1466 | msg = _("%s: compiled for a big endian system and target is little endian"); | |
1467 | else | |
1468 | msg = _("%s: compiled for a little endian system and target is big endian"); | |
1469 | ||
8f615d07 | 1470 | (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd)); |
5bd4f169 AM |
1471 | |
1472 | bfd_set_error (bfd_error_wrong_format); | |
1473 | return false; | |
1474 | } | |
1475 | ||
1476 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
1477 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
1478 | return true; | |
1479 | ||
1480 | new_flags = elf_elfheader (ibfd)->e_flags; | |
1481 | old_flags = elf_elfheader (obfd)->e_flags; | |
1482 | if (!elf_flags_init (obfd)) | |
1483 | { | |
1484 | /* First call, no flags set. */ | |
1485 | elf_flags_init (obfd) = true; | |
1486 | elf_elfheader (obfd)->e_flags = new_flags; | |
1487 | } | |
1488 | ||
1489 | else if (new_flags == old_flags) | |
1490 | /* Compatible flags are ok. */ | |
1491 | ; | |
1492 | ||
1493 | else | |
1494 | { | |
1495 | /* Incompatible flags. Warn about -mrelocatable mismatch. | |
1496 | Allow -mrelocatable-lib to be linked with either. */ | |
1497 | error = false; | |
1498 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 | |
1499 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
1500 | { | |
1501 | error = true; | |
1502 | (*_bfd_error_handler) | |
1503 | (_("%s: compiled with -mrelocatable and linked with modules compiled normally"), | |
8f615d07 | 1504 | bfd_archive_filename (ibfd)); |
5bd4f169 AM |
1505 | } |
1506 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
1507 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
1508 | { | |
1509 | error = true; | |
1510 | (*_bfd_error_handler) | |
1511 | (_("%s: compiled normally and linked with modules compiled with -mrelocatable"), | |
8f615d07 | 1512 | bfd_archive_filename (ibfd)); |
5bd4f169 AM |
1513 | } |
1514 | ||
1515 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
1516 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
1517 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
1518 | ||
1519 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
1520 | but each input file is either -mrelocatable or -mrelocatable-lib. */ | |
1521 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) | |
1522 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
1523 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
1524 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
1525 | ||
1526 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit | |
1527 | if any module uses it. */ | |
1528 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); | |
1529 | ||
1530 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
1531 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
1532 | ||
1533 | /* Warn about any other mismatches. */ | |
1534 | if (new_flags != old_flags) | |
1535 | { | |
1536 | error = true; | |
1537 | (*_bfd_error_handler) | |
1538 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"), | |
8f615d07 | 1539 | bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags); |
5bd4f169 AM |
1540 | } |
1541 | ||
1542 | if (error) | |
1543 | { | |
1544 | bfd_set_error (bfd_error_bad_value); | |
1545 | return false; | |
1546 | } | |
1547 | } | |
1548 | ||
1549 | return true; | |
1550 | } | |
1551 | ||
1552 | /* Handle a PowerPC specific section when reading an object file. This | |
1553 | is called when elfcode.h finds a section with an unknown type. */ | |
1554 | ||
1555 | static boolean | |
1556 | ppc64_elf_section_from_shdr (abfd, hdr, name) | |
1557 | bfd *abfd; | |
1558 | Elf64_Internal_Shdr *hdr; | |
1559 | char *name; | |
1560 | { | |
1561 | asection *newsect; | |
1562 | flagword flags; | |
1563 | ||
1564 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | |
1565 | return false; | |
1566 | ||
1567 | newsect = hdr->bfd_section; | |
1568 | flags = bfd_get_section_flags (abfd, newsect); | |
1569 | if (hdr->sh_flags & SHF_EXCLUDE) | |
1570 | flags |= SEC_EXCLUDE; | |
1571 | ||
1572 | if (hdr->sh_type == SHT_ORDERED) | |
1573 | flags |= SEC_SORT_ENTRIES; | |
1574 | ||
1575 | bfd_set_section_flags (abfd, newsect, flags); | |
1576 | return true; | |
1577 | } | |
1578 | \f | |
65f38f15 AM |
1579 | /* The following functions are specific to the ELF linker, while |
1580 | functions above are used generally. Those named ppc64_elf_* are | |
1581 | called by the main ELF linker code. They appear in this file more | |
1582 | or less in the order in which they are called. eg. | |
1583 | ppc64_elf_check_relocs is called early in the link process, | |
1584 | ppc64_elf_finish_dynamic_sections is one of the last functions | |
1585 | called. */ | |
1586 | ||
1587 | /* The linker needs to keep track of the number of relocs that it | |
1588 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
1589 | This is so that it can later discard them if they are found to be | |
1590 | unnecessary. We store the information in a field extending the | |
1591 | regular ELF linker hash table. */ | |
1592 | ||
1593 | struct ppc_dyn_relocs | |
1594 | { | |
1595 | struct ppc_dyn_relocs *next; | |
1596 | ||
1597 | /* The input section of the reloc. */ | |
1598 | asection *sec; | |
1599 | ||
1600 | /* Total number of relocs copied for the input section. */ | |
1601 | bfd_size_type count; | |
1602 | ||
1603 | /* Number of pc-relative relocs copied for the input section. */ | |
1604 | bfd_size_type pc_count; | |
1605 | }; | |
1606 | ||
1607 | /* Of those relocs that might be copied as dynamic relocs, this macro | |
1608 | selects between relative and absolute types. */ | |
1609 | ||
1610 | #define IS_ABSOLUTE_RELOC(RTYPE) \ | |
1611 | ((RTYPE) != R_PPC64_REL14 \ | |
1612 | && (RTYPE) != R_PPC64_REL14_BRNTAKEN \ | |
1613 | && (RTYPE) != R_PPC64_REL14_BRTAKEN \ | |
1614 | && (RTYPE) != R_PPC64_REL24 \ | |
1615 | && (RTYPE) != R_PPC64_REL32 \ | |
1616 | && (RTYPE) != R_PPC64_REL64) | |
1617 | ||
1618 | /* ppc64 ELF linker hash entry. */ | |
1619 | ||
1620 | struct ppc_link_hash_entry | |
1621 | { | |
1622 | struct elf_link_hash_entry elf; | |
1623 | ||
1624 | /* Track dynamic relocs copied for this symbol. */ | |
1625 | struct ppc_dyn_relocs *dyn_relocs; | |
1626 | }; | |
1627 | ||
1628 | /* ppc64 ELF linker hash table. */ | |
1629 | ||
1630 | struct ppc_link_hash_table | |
1631 | { | |
1632 | struct elf_link_hash_table elf; | |
1633 | ||
1634 | /* Short-cuts to get to dynamic linker sections. */ | |
1635 | asection *sgot; | |
1636 | asection *srelgot; | |
1637 | asection *splt; | |
1638 | asection *srelplt; | |
1639 | asection *sdynbss; | |
1640 | asection *srelbss; | |
5d1634d7 | 1641 | asection *sstub; |
65f38f15 | 1642 | asection *sglink; |
ec338859 | 1643 | |
5d1634d7 AM |
1644 | /* Set on error. */ |
1645 | int plt_overflow; | |
1646 | ||
ec338859 AM |
1647 | /* Small local sym to section mapping cache. */ |
1648 | struct sym_sec_cache sym_sec; | |
65f38f15 AM |
1649 | }; |
1650 | ||
1651 | /* Get the ppc64 ELF linker hash table from a link_info structure. */ | |
1652 | ||
1653 | #define ppc_hash_table(p) \ | |
1654 | ((struct ppc_link_hash_table *) ((p)->hash)) | |
1655 | ||
1656 | /* Create an entry in a ppc64 ELF linker hash table. */ | |
1657 | ||
1658 | static struct bfd_hash_entry * | |
1659 | link_hash_newfunc (entry, table, string) | |
1660 | struct bfd_hash_entry *entry; | |
1661 | struct bfd_hash_table *table; | |
1662 | const char *string; | |
1663 | { | |
1664 | /* Allocate the structure if it has not already been allocated by a | |
1665 | subclass. */ | |
1666 | if (entry == NULL) | |
1667 | { | |
1668 | entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry)); | |
1669 | if (entry == NULL) | |
1670 | return entry; | |
1671 | } | |
1672 | ||
1673 | /* Call the allocation method of the superclass. */ | |
1674 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
1675 | if (entry != NULL) | |
1676 | { | |
1677 | struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry; | |
1678 | ||
1679 | eh->dyn_relocs = NULL; | |
1680 | } | |
1681 | ||
1682 | return entry; | |
1683 | } | |
1684 | ||
1685 | /* Create a ppc64 ELF linker hash table. */ | |
1686 | ||
1687 | static struct bfd_link_hash_table * | |
1688 | ppc64_elf_link_hash_table_create (abfd) | |
1689 | bfd *abfd; | |
1690 | { | |
1691 | struct ppc_link_hash_table *htab; | |
1692 | bfd_size_type amt = sizeof (struct ppc_link_hash_table); | |
1693 | ||
1694 | htab = (struct ppc_link_hash_table *) bfd_alloc (abfd, amt); | |
1695 | if (htab == NULL) | |
1696 | return NULL; | |
1697 | ||
1698 | if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc)) | |
1699 | { | |
1700 | bfd_release (abfd, htab); | |
1701 | return NULL; | |
1702 | } | |
1703 | ||
1704 | htab->sgot = NULL; | |
1705 | htab->srelgot = NULL; | |
1706 | htab->splt = NULL; | |
1707 | htab->srelplt = NULL; | |
1708 | htab->sdynbss = NULL; | |
1709 | htab->srelbss = NULL; | |
5d1634d7 | 1710 | htab->sstub = NULL; |
65f38f15 | 1711 | htab->sglink = NULL; |
5d1634d7 | 1712 | htab->plt_overflow = 0; |
ec338859 | 1713 | htab->sym_sec.abfd = NULL; |
65f38f15 AM |
1714 | |
1715 | return &htab->elf.root; | |
1716 | } | |
1717 | ||
1718 | /* Create .got and .rela.got sections in DYNOBJ, and set up | |
1719 | shortcuts to them in our hash table. */ | |
1720 | ||
1721 | static boolean | |
1722 | create_got_section (dynobj, info) | |
1723 | bfd *dynobj; | |
1724 | struct bfd_link_info *info; | |
1725 | { | |
1726 | struct ppc_link_hash_table *htab; | |
1727 | ||
1728 | if (! _bfd_elf_create_got_section (dynobj, info)) | |
1729 | return false; | |
1730 | ||
1731 | htab = ppc_hash_table (info); | |
1732 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); | |
1733 | if (!htab->sgot) | |
1734 | abort (); | |
1735 | ||
1736 | htab->srelgot = bfd_make_section (dynobj, ".rela.got"); | |
1737 | if (!htab->srelgot | |
1738 | || ! bfd_set_section_flags (dynobj, htab->srelgot, | |
1739 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
1740 | | SEC_IN_MEMORY | SEC_LINKER_CREATED | |
1741 | | SEC_READONLY)) | |
1742 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3)) | |
1743 | return false; | |
1744 | return true; | |
1745 | } | |
5bd4f169 | 1746 | |
5d1634d7 AM |
1747 | /* Create the .stub and .glink sections as well as the ordinary |
1748 | dynamic sections. */ | |
5bd4f169 AM |
1749 | |
1750 | static boolean | |
65f38f15 AM |
1751 | ppc64_elf_create_dynamic_sections (dynobj, info) |
1752 | bfd *dynobj; | |
5bd4f169 AM |
1753 | struct bfd_link_info *info; |
1754 | { | |
65f38f15 | 1755 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
1756 | flagword flags; |
1757 | ||
65f38f15 AM |
1758 | htab = ppc_hash_table (info); |
1759 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
5bd4f169 AM |
1760 | return false; |
1761 | ||
65f38f15 | 1762 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
5bd4f169 | 1763 | return false; |
65f38f15 AM |
1764 | |
1765 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1766 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | |
1767 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
1768 | if (!info->shared) | |
1769 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | |
1770 | ||
1771 | if (!htab->splt || !htab->srelplt || !htab->sdynbss | |
1772 | || (!info->shared && !htab->srelbss)) | |
1773 | abort (); | |
1774 | ||
5d1634d7 AM |
1775 | /* Create .stub and .glink for global linkage functions. */ |
1776 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | |
1777 | | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
1778 | htab->sstub = bfd_make_section (dynobj, ".stub"); | |
1779 | if (htab->sstub == NULL | |
1780 | || ! bfd_set_section_flags (dynobj, htab->sstub, flags) | |
1781 | || ! bfd_set_section_alignment (dynobj, htab->sstub, 2)) | |
5bd4f169 | 1782 | return false; |
65f38f15 AM |
1783 | htab->sglink = bfd_make_section (dynobj, ".glink"); |
1784 | if (htab->sglink == NULL | |
1785 | || ! bfd_set_section_flags (dynobj, htab->sglink, flags) | |
1786 | || ! bfd_set_section_alignment (dynobj, htab->sglink, 3)) | |
5bd4f169 AM |
1787 | return false; |
1788 | ||
1789 | return true; | |
1790 | } | |
1791 | ||
65f38f15 AM |
1792 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
1793 | ||
1794 | static void | |
1795 | ppc64_elf_copy_indirect_symbol (dir, ind) | |
1796 | struct elf_link_hash_entry *dir, *ind; | |
1797 | { | |
1798 | struct ppc_link_hash_entry *edir, *eind; | |
1799 | ||
1800 | edir = (struct ppc_link_hash_entry *) dir; | |
1801 | eind = (struct ppc_link_hash_entry *) ind; | |
1802 | ||
bbd7ec4a | 1803 | if (eind->dyn_relocs != NULL) |
65f38f15 | 1804 | { |
bbd7ec4a AM |
1805 | if (edir->dyn_relocs != NULL) |
1806 | { | |
1807 | struct ppc_dyn_relocs **pp; | |
1808 | struct ppc_dyn_relocs *p; | |
1809 | ||
1e370bd2 | 1810 | if (ind->root.type == bfd_link_hash_indirect) |
bbd7ec4a AM |
1811 | abort (); |
1812 | ||
1813 | /* Add reloc counts against the weak sym to the strong sym | |
1814 | list. Merge any entries against the same section. */ | |
1815 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
1816 | { | |
1817 | struct ppc_dyn_relocs *q; | |
1818 | ||
1819 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
1820 | if (q->sec == p->sec) | |
1821 | { | |
1822 | q->pc_count += p->pc_count; | |
1823 | q->count += p->count; | |
1824 | *pp = p->next; | |
1825 | break; | |
1826 | } | |
1827 | if (q == NULL) | |
1828 | pp = &p->next; | |
1829 | } | |
1830 | *pp = edir->dyn_relocs; | |
1831 | } | |
1832 | ||
65f38f15 AM |
1833 | edir->dyn_relocs = eind->dyn_relocs; |
1834 | eind->dyn_relocs = NULL; | |
1835 | } | |
65f38f15 AM |
1836 | |
1837 | _bfd_elf_link_hash_copy_indirect (dir, ind); | |
1838 | } | |
1839 | ||
5bd4f169 | 1840 | /* Look through the relocs for a section during the first phase, and |
65f38f15 | 1841 | calculate needed space in the global offset table, procedure |
5d1634d7 | 1842 | linkage table, and dynamic reloc sections. */ |
5bd4f169 AM |
1843 | |
1844 | static boolean | |
1845 | ppc64_elf_check_relocs (abfd, info, sec, relocs) | |
1846 | bfd *abfd; | |
1847 | struct bfd_link_info *info; | |
1848 | asection *sec; | |
1849 | const Elf_Internal_Rela *relocs; | |
1850 | { | |
65f38f15 | 1851 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
1852 | Elf_Internal_Shdr *symtab_hdr; |
1853 | struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; | |
1854 | const Elf_Internal_Rela *rel; | |
1855 | const Elf_Internal_Rela *rel_end; | |
5bd4f169 | 1856 | asection *sreloc; |
5bd4f169 AM |
1857 | |
1858 | if (info->relocateable) | |
1859 | return true; | |
1860 | ||
65f38f15 | 1861 | htab = ppc_hash_table (info); |
5bd4f169 | 1862 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
5bd4f169 AM |
1863 | |
1864 | sym_hashes = elf_sym_hashes (abfd); | |
1865 | sym_hashes_end = (sym_hashes | |
1866 | + symtab_hdr->sh_size / sizeof (Elf64_External_Sym)); | |
1867 | if (!elf_bad_symtab (abfd)) | |
1868 | sym_hashes_end -= symtab_hdr->sh_info; | |
1869 | ||
1870 | sreloc = NULL; | |
1871 | ||
1872 | rel_end = relocs + sec->reloc_count; | |
1873 | for (rel = relocs; rel < rel_end; rel++) | |
1874 | { | |
1875 | unsigned long r_symndx; | |
1876 | struct elf_link_hash_entry *h; | |
a33d1f77 | 1877 | enum elf_ppc_reloc_type r_type; |
5bd4f169 AM |
1878 | |
1879 | r_symndx = ELF64_R_SYM (rel->r_info); | |
1880 | if (r_symndx < symtab_hdr->sh_info) | |
1881 | h = NULL; | |
1882 | else | |
1883 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
1884 | ||
a33d1f77 AM |
1885 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); |
1886 | switch (r_type) | |
5bd4f169 AM |
1887 | { |
1888 | /* GOT16 relocations */ | |
1889 | case R_PPC64_GOT16: | |
5bd4f169 | 1890 | case R_PPC64_GOT16_DS: |
65f38f15 AM |
1891 | case R_PPC64_GOT16_HA: |
1892 | case R_PPC64_GOT16_HI: | |
1893 | case R_PPC64_GOT16_LO: | |
5bd4f169 | 1894 | case R_PPC64_GOT16_LO_DS: |
5bd4f169 | 1895 | |
65f38f15 AM |
1896 | /* This symbol requires a global offset table entry. */ |
1897 | if (htab->sgot == NULL) | |
5bd4f169 | 1898 | { |
65f38f15 AM |
1899 | if (htab->elf.dynobj == NULL) |
1900 | htab->elf.dynobj = abfd; | |
1901 | if (!create_got_section (htab->elf.dynobj, info)) | |
5bd4f169 | 1902 | return false; |
5bd4f169 AM |
1903 | } |
1904 | ||
1905 | if (h != NULL) | |
1906 | { | |
65f38f15 | 1907 | h->got.refcount += 1; |
5bd4f169 AM |
1908 | } |
1909 | else | |
1910 | { | |
65f38f15 AM |
1911 | bfd_signed_vma *local_got_refcounts; |
1912 | ||
5bd4f169 | 1913 | /* This is a global offset table entry for a local symbol. */ |
65f38f15 | 1914 | local_got_refcounts = elf_local_got_refcounts (abfd); |
5bd4f169 AM |
1915 | if (local_got_refcounts == NULL) |
1916 | { | |
dc810e39 | 1917 | bfd_size_type size; |
5bd4f169 | 1918 | |
dc810e39 AM |
1919 | size = symtab_hdr->sh_info; |
1920 | size *= sizeof (bfd_signed_vma); | |
1921 | local_got_refcounts = ((bfd_signed_vma *) | |
65f38f15 | 1922 | bfd_zalloc (abfd, size)); |
5bd4f169 AM |
1923 | if (local_got_refcounts == NULL) |
1924 | return false; | |
1925 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
5bd4f169 | 1926 | } |
65f38f15 | 1927 | local_got_refcounts[r_symndx] += 1; |
5bd4f169 AM |
1928 | } |
1929 | break; | |
1930 | ||
5bd4f169 | 1931 | case R_PPC64_PLT16_HA: |
65f38f15 AM |
1932 | case R_PPC64_PLT16_HI: |
1933 | case R_PPC64_PLT16_LO: | |
1934 | case R_PPC64_PLT32: | |
1935 | case R_PPC64_PLT64: | |
5bd4f169 AM |
1936 | /* This symbol requires a procedure linkage table entry. We |
1937 | actually build the entry in adjust_dynamic_symbol, | |
1938 | because this might be a case of linking PIC code without | |
1939 | linking in any dynamic objects, in which case we don't | |
1940 | need to generate a procedure linkage table after all. */ | |
5bd4f169 AM |
1941 | if (h == NULL) |
1942 | { | |
1943 | /* It does not make sense to have a procedure linkage | |
1944 | table entry for a local symbol. */ | |
1945 | bfd_set_error (bfd_error_bad_value); | |
1946 | return false; | |
1947 | } | |
1948 | ||
65f38f15 AM |
1949 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
1950 | h->plt.refcount += 1; | |
5bd4f169 AM |
1951 | break; |
1952 | ||
1953 | /* The following relocations don't need to propagate the | |
1954 | relocation if linking a shared object since they are | |
1955 | section relative. */ | |
1956 | case R_PPC64_SECTOFF: | |
1957 | case R_PPC64_SECTOFF_LO: | |
1958 | case R_PPC64_SECTOFF_HI: | |
1959 | case R_PPC64_SECTOFF_HA: | |
1960 | case R_PPC64_SECTOFF_DS: | |
1961 | case R_PPC64_SECTOFF_LO_DS: | |
1962 | case R_PPC64_TOC16: | |
1963 | case R_PPC64_TOC16_LO: | |
1964 | case R_PPC64_TOC16_HI: | |
1965 | case R_PPC64_TOC16_HA: | |
1966 | case R_PPC64_TOC16_DS: | |
1967 | case R_PPC64_TOC16_LO_DS: | |
1968 | break; | |
1969 | ||
1970 | /* This relocation describes the C++ object vtable hierarchy. | |
1971 | Reconstruct it for later use during GC. */ | |
1972 | case R_PPC64_GNU_VTINHERIT: | |
1973 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
1974 | return false; | |
1975 | break; | |
1976 | ||
1977 | /* This relocation describes which C++ vtable entries are actually | |
1978 | used. Record for later use during GC. */ | |
1979 | case R_PPC64_GNU_VTENTRY: | |
1980 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
1981 | return false; | |
1982 | break; | |
1983 | ||
5d1634d7 AM |
1984 | case R_PPC64_REL24: |
1985 | if (h != NULL) | |
1986 | { | |
1987 | /* We may need a .plt entry if the function this reloc | |
1988 | refers to is in a shared lib. */ | |
1989 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; | |
1990 | h->plt.refcount += 1; | |
1991 | } | |
1992 | break; | |
1993 | ||
5bd4f169 AM |
1994 | case R_PPC64_REL64: |
1995 | case R_PPC64_REL32: | |
5bd4f169 AM |
1996 | case R_PPC64_REL14: |
1997 | case R_PPC64_REL14_BRTAKEN: | |
1998 | case R_PPC64_REL14_BRNTAKEN: | |
65f38f15 AM |
1999 | case R_PPC64_ADDR14: |
2000 | case R_PPC64_ADDR14_BRNTAKEN: | |
2001 | case R_PPC64_ADDR14_BRTAKEN: | |
2002 | case R_PPC64_ADDR16: | |
2003 | case R_PPC64_ADDR16_DS: | |
2004 | case R_PPC64_ADDR16_HA: | |
2005 | case R_PPC64_ADDR16_HI: | |
2006 | case R_PPC64_ADDR16_HIGHER: | |
2007 | case R_PPC64_ADDR16_HIGHERA: | |
2008 | case R_PPC64_ADDR16_HIGHEST: | |
2009 | case R_PPC64_ADDR16_HIGHESTA: | |
2010 | case R_PPC64_ADDR16_LO: | |
2011 | case R_PPC64_ADDR16_LO_DS: | |
2012 | case R_PPC64_ADDR24: | |
2013 | case R_PPC64_ADDR30: | |
2014 | case R_PPC64_ADDR32: | |
2015 | case R_PPC64_ADDR64: | |
2016 | case R_PPC64_UADDR16: | |
2017 | case R_PPC64_UADDR32: | |
2018 | case R_PPC64_UADDR64: | |
5bd4f169 | 2019 | case R_PPC64_TOC: |
65f38f15 AM |
2020 | /* If we are creating a shared library, and this is a reloc |
2021 | against a global symbol, or a non PC relative reloc | |
2022 | against a local symbol, then we need to copy the reloc | |
2023 | into the shared library. However, if we are linking with | |
2024 | -Bsymbolic, we do not need to copy a reloc against a | |
2025 | global symbol which is defined in an object we are | |
2026 | including in the link (i.e., DEF_REGULAR is set). At | |
2027 | this point we have not seen all the input files, so it is | |
2028 | possible that DEF_REGULAR is not set now but will be set | |
2029 | later (it is never cleared). In case of a weak definition, | |
2030 | DEF_REGULAR may be cleared later by a strong definition in | |
2031 | a shared library. We account for that possibility below by | |
2032 | storing information in the relocs_copied field of the hash | |
2033 | table entry. A similar situation occurs when creating | |
2034 | shared libraries and symbol visibility changes render the | |
2035 | symbol local. | |
2036 | ||
2037 | If on the other hand, we are creating an executable, we | |
2038 | may need to keep relocations for symbols satisfied by a | |
2039 | dynamic library if we manage to avoid copy relocs for the | |
2040 | symbol. */ | |
2041 | if ((info->shared | |
2042 | && (sec->flags & SEC_ALLOC) != 0 | |
a33d1f77 | 2043 | && (IS_ABSOLUTE_RELOC (r_type) |
65f38f15 AM |
2044 | || (h != NULL |
2045 | && (! info->symbolic | |
2046 | || h->root.type == bfd_link_hash_defweak | |
2047 | || (h->elf_link_hash_flags | |
2048 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
2049 | || (!info->shared | |
2050 | && (sec->flags & SEC_ALLOC) != 0 | |
2051 | && h != NULL | |
2052 | && (h->root.type == bfd_link_hash_defweak | |
2053 | || (h->elf_link_hash_flags | |
2054 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
5bd4f169 | 2055 | { |
ec338859 AM |
2056 | struct ppc_dyn_relocs *p; |
2057 | struct ppc_dyn_relocs **head; | |
2058 | ||
5d1634d7 AM |
2059 | #if 0 |
2060 | /* Don't propagate .opd relocs. */ | |
2061 | if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0) | |
2062 | break; | |
2063 | #endif | |
2064 | ||
65f38f15 AM |
2065 | /* We must copy these reloc types into the output file. |
2066 | Create a reloc section in dynobj and make room for | |
2067 | this reloc. */ | |
5bd4f169 AM |
2068 | if (sreloc == NULL) |
2069 | { | |
2070 | const char *name; | |
65f38f15 | 2071 | bfd *dynobj; |
5bd4f169 AM |
2072 | |
2073 | name = (bfd_elf_string_from_elf_section | |
2074 | (abfd, | |
2075 | elf_elfheader (abfd)->e_shstrndx, | |
2076 | elf_section_data (sec)->rel_hdr.sh_name)); | |
2077 | if (name == NULL) | |
2078 | return false; | |
2079 | ||
65f38f15 AM |
2080 | if (strncmp (name, ".rela", 5) != 0 |
2081 | || strcmp (bfd_get_section_name (abfd, sec), | |
2082 | name + 5) != 0) | |
2083 | { | |
2084 | (*_bfd_error_handler) | |
2085 | (_("%s: bad relocation section name `%s\'"), | |
2086 | bfd_archive_filename (abfd), name); | |
5d1634d7 | 2087 | bfd_set_error (bfd_error_bad_value); |
65f38f15 AM |
2088 | } |
2089 | ||
2090 | if (htab->elf.dynobj == NULL) | |
2091 | htab->elf.dynobj = abfd; | |
5bd4f169 | 2092 | |
65f38f15 | 2093 | dynobj = htab->elf.dynobj; |
5bd4f169 AM |
2094 | sreloc = bfd_get_section_by_name (dynobj, name); |
2095 | if (sreloc == NULL) | |
2096 | { | |
2097 | flagword flags; | |
2098 | ||
2099 | sreloc = bfd_make_section (dynobj, name); | |
2100 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
2101 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
2102 | if ((sec->flags & SEC_ALLOC) != 0) | |
2103 | flags |= SEC_ALLOC | SEC_LOAD; | |
2104 | if (sreloc == NULL | |
2105 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
65f38f15 | 2106 | || ! bfd_set_section_alignment (dynobj, sreloc, 3)) |
5bd4f169 AM |
2107 | return false; |
2108 | } | |
65f38f15 | 2109 | elf_section_data (sec)->sreloc = sreloc; |
5bd4f169 AM |
2110 | } |
2111 | ||
65f38f15 AM |
2112 | /* If this is a global symbol, we count the number of |
2113 | relocations we need for this symbol. */ | |
2114 | if (h != NULL) | |
2115 | { | |
ec338859 | 2116 | head = &((struct ppc_link_hash_entry *) h)->dyn_relocs; |
65f38f15 AM |
2117 | } |
2118 | else | |
2119 | { | |
ec338859 AM |
2120 | /* Track dynamic relocs needed for local syms too. |
2121 | We really need local syms available to do this | |
2122 | easily. Oh well. */ | |
2123 | ||
2124 | asection *s; | |
2125 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
2126 | sec, r_symndx); | |
2127 | if (s == NULL) | |
2128 | return false; | |
2129 | ||
2130 | head = ((struct ppc_dyn_relocs **) | |
2131 | &elf_section_data (s)->local_dynrel); | |
65f38f15 | 2132 | } |
ec338859 AM |
2133 | |
2134 | p = *head; | |
2135 | if (p == NULL || p->sec != sec) | |
2136 | { | |
2137 | p = ((struct ppc_dyn_relocs *) | |
2138 | bfd_alloc (htab->elf.dynobj, | |
2139 | (bfd_size_type) sizeof *p)); | |
2140 | if (p == NULL) | |
2141 | return false; | |
2142 | p->next = *head; | |
2143 | *head = p; | |
2144 | p->sec = sec; | |
2145 | p->count = 0; | |
2146 | p->pc_count = 0; | |
2147 | } | |
2148 | ||
2149 | p->count += 1; | |
2150 | if (!IS_ABSOLUTE_RELOC (r_type)) | |
2151 | p->pc_count += 1; | |
65f38f15 | 2152 | } |
5bd4f169 | 2153 | break; |
65f38f15 AM |
2154 | |
2155 | default: | |
5bd4f169 AM |
2156 | } |
2157 | } | |
2158 | ||
2159 | return true; | |
2160 | } | |
2161 | ||
2162 | /* Return the section that should be marked against GC for a given | |
2163 | relocation. */ | |
2164 | ||
2165 | static asection * | |
2166 | ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym) | |
2167 | bfd *abfd; | |
2168 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
2169 | Elf_Internal_Rela *rel; | |
2170 | struct elf_link_hash_entry *h; | |
2171 | Elf_Internal_Sym *sym; | |
2172 | { | |
2173 | if (h != NULL) | |
2174 | { | |
a33d1f77 AM |
2175 | enum elf_ppc_reloc_type r_type; |
2176 | ||
2177 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
2178 | switch (r_type) | |
5bd4f169 AM |
2179 | { |
2180 | case R_PPC64_GNU_VTINHERIT: | |
2181 | case R_PPC64_GNU_VTENTRY: | |
2182 | break; | |
2183 | ||
2184 | default: | |
2185 | switch (h->root.type) | |
2186 | { | |
2187 | case bfd_link_hash_defined: | |
2188 | case bfd_link_hash_defweak: | |
2189 | return h->root.u.def.section; | |
2190 | ||
2191 | case bfd_link_hash_common: | |
2192 | return h->root.u.c.p->section; | |
2193 | ||
2194 | default: | |
2195 | break; | |
2196 | } | |
2197 | } | |
2198 | } | |
2199 | else | |
2200 | { | |
9ad5cbcf | 2201 | return bfd_section_from_elf_index (abfd, sym->st_shndx); |
5bd4f169 AM |
2202 | } |
2203 | ||
2204 | return NULL; | |
2205 | } | |
2206 | ||
65f38f15 AM |
2207 | /* Update the .got, .plt. and dynamic reloc reference counts for the |
2208 | section being removed. */ | |
5bd4f169 AM |
2209 | |
2210 | static boolean | |
2211 | ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs) | |
2212 | bfd *abfd; | |
2213 | struct bfd_link_info *info ATTRIBUTE_UNUSED; | |
2214 | asection *sec; | |
2215 | const Elf_Internal_Rela *relocs; | |
2216 | { | |
2217 | Elf_Internal_Shdr *symtab_hdr; | |
2218 | struct elf_link_hash_entry **sym_hashes; | |
2219 | bfd_signed_vma *local_got_refcounts; | |
2220 | const Elf_Internal_Rela *rel, *relend; | |
5bd4f169 | 2221 | |
ec338859 AM |
2222 | elf_section_data (sec)->local_dynrel = NULL; |
2223 | ||
5bd4f169 AM |
2224 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
2225 | sym_hashes = elf_sym_hashes (abfd); | |
2226 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
2227 | ||
2228 | relend = relocs + sec->reloc_count; | |
2229 | for (rel = relocs; rel < relend; rel++) | |
a33d1f77 AM |
2230 | { |
2231 | unsigned long r_symndx; | |
2232 | enum elf_ppc_reloc_type r_type; | |
2233 | struct elf_link_hash_entry *h; | |
5bd4f169 | 2234 | |
a33d1f77 AM |
2235 | r_symndx = ELF64_R_SYM (rel->r_info); |
2236 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
2237 | switch (r_type) | |
2238 | { | |
2239 | case R_PPC64_GOT16: | |
2240 | case R_PPC64_GOT16_DS: | |
2241 | case R_PPC64_GOT16_HA: | |
2242 | case R_PPC64_GOT16_HI: | |
2243 | case R_PPC64_GOT16_LO: | |
2244 | case R_PPC64_GOT16_LO_DS: | |
2245 | if (r_symndx >= symtab_hdr->sh_info) | |
2246 | { | |
2247 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2248 | if (h->got.refcount > 0) | |
2249 | h->got.refcount--; | |
2250 | } | |
2251 | else | |
2252 | { | |
2253 | if (local_got_refcounts[r_symndx] > 0) | |
2254 | local_got_refcounts[r_symndx]--; | |
2255 | } | |
2256 | break; | |
65f38f15 | 2257 | |
a33d1f77 AM |
2258 | case R_PPC64_PLT16_HA: |
2259 | case R_PPC64_PLT16_HI: | |
2260 | case R_PPC64_PLT16_LO: | |
2261 | case R_PPC64_PLT32: | |
2262 | case R_PPC64_PLT64: | |
2263 | if (r_symndx >= symtab_hdr->sh_info) | |
2264 | { | |
2265 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2266 | if (h->plt.refcount > 0) | |
2267 | h->plt.refcount--; | |
2268 | } | |
2269 | break; | |
65f38f15 | 2270 | |
5d1634d7 AM |
2271 | case R_PPC64_REL24: |
2272 | if (r_symndx >= symtab_hdr->sh_info) | |
2273 | { | |
2274 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2275 | if (h->plt.refcount > 0) | |
2276 | h->plt.refcount--; | |
2277 | } | |
2278 | /* Fall thru. */ | |
2279 | ||
a33d1f77 AM |
2280 | case R_PPC64_REL14: |
2281 | case R_PPC64_REL14_BRNTAKEN: | |
2282 | case R_PPC64_REL14_BRTAKEN: | |
a33d1f77 AM |
2283 | case R_PPC64_REL32: |
2284 | case R_PPC64_REL64: | |
2285 | if (r_symndx >= symtab_hdr->sh_info) | |
2286 | { | |
2287 | struct ppc_link_hash_entry *eh; | |
2288 | struct ppc_dyn_relocs **pp; | |
2289 | struct ppc_dyn_relocs *p; | |
65f38f15 | 2290 | |
a33d1f77 AM |
2291 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
2292 | eh = (struct ppc_link_hash_entry *) h; | |
65f38f15 | 2293 | |
a33d1f77 AM |
2294 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
2295 | if (p->sec == sec) | |
2296 | { | |
2297 | p->pc_count -= 1; | |
2298 | p->count -= 1; | |
2299 | if (p->count == 0) | |
2300 | *pp = p->next; | |
2301 | break; | |
2302 | } | |
2303 | } | |
2304 | break; | |
65f38f15 | 2305 | |
a33d1f77 AM |
2306 | case R_PPC64_ADDR14: |
2307 | case R_PPC64_ADDR14_BRNTAKEN: | |
2308 | case R_PPC64_ADDR14_BRTAKEN: | |
2309 | case R_PPC64_ADDR16: | |
2310 | case R_PPC64_ADDR16_DS: | |
2311 | case R_PPC64_ADDR16_HA: | |
2312 | case R_PPC64_ADDR16_HI: | |
2313 | case R_PPC64_ADDR16_HIGHER: | |
2314 | case R_PPC64_ADDR16_HIGHERA: | |
2315 | case R_PPC64_ADDR16_HIGHEST: | |
2316 | case R_PPC64_ADDR16_HIGHESTA: | |
2317 | case R_PPC64_ADDR16_LO: | |
2318 | case R_PPC64_ADDR16_LO_DS: | |
2319 | case R_PPC64_ADDR24: | |
2320 | case R_PPC64_ADDR30: | |
2321 | case R_PPC64_ADDR32: | |
2322 | case R_PPC64_ADDR64: | |
2323 | case R_PPC64_UADDR16: | |
2324 | case R_PPC64_UADDR32: | |
2325 | case R_PPC64_UADDR64: | |
2326 | case R_PPC64_TOC: | |
2327 | if (r_symndx >= symtab_hdr->sh_info) | |
2328 | { | |
2329 | struct ppc_link_hash_entry *eh; | |
2330 | struct ppc_dyn_relocs **pp; | |
2331 | struct ppc_dyn_relocs *p; | |
65f38f15 | 2332 | |
a33d1f77 AM |
2333 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
2334 | eh = (struct ppc_link_hash_entry *) h; | |
2335 | ||
2336 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
2337 | if (p->sec == sec) | |
2338 | { | |
2339 | p->count -= 1; | |
2340 | if (p->count == 0) | |
2341 | *pp = p->next; | |
2342 | break; | |
2343 | } | |
2344 | } | |
2345 | break; | |
5bd4f169 | 2346 | |
a33d1f77 AM |
2347 | default: |
2348 | break; | |
2349 | } | |
2350 | } | |
5bd4f169 AM |
2351 | return true; |
2352 | } | |
2353 | ||
2354 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
2355 | regular object. The current definition is in some section of the | |
2356 | dynamic object, but we're not including those sections. We have to | |
2357 | change the definition to something the rest of the link can | |
2358 | understand. */ | |
2359 | ||
2360 | static boolean | |
2361 | ppc64_elf_adjust_dynamic_symbol (info, h) | |
2362 | struct bfd_link_info *info; | |
2363 | struct elf_link_hash_entry *h; | |
2364 | { | |
65f38f15 AM |
2365 | struct ppc_link_hash_table *htab; |
2366 | struct ppc_link_hash_entry * eh; | |
2367 | struct ppc_dyn_relocs *p; | |
5bd4f169 AM |
2368 | asection *s; |
2369 | unsigned int power_of_two; | |
5bd4f169 | 2370 | |
65f38f15 | 2371 | htab = ppc_hash_table (info); |
5bd4f169 | 2372 | |
65f38f15 AM |
2373 | /* If this is a function, put it in the procedure linkage table. We |
2374 | will fill in the contents of the procedure linkage table later. */ | |
5bd4f169 AM |
2375 | if (h->type == STT_FUNC |
2376 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
2377 | { | |
65f38f15 AM |
2378 | struct elf_link_hash_entry *fdh; |
2379 | ||
2380 | /* If it's a function entry point, the name starts with a dot | |
2381 | unless someone has written some poor assembly code. The ABI | |
2382 | for .plt calls requires that there be a function descriptor | |
2383 | sym which has the name of the function minus the dot. */ | |
2384 | ||
2385 | if (h->plt.refcount <= 0 | |
2386 | || h->root.root.string[0] != '.' | |
2387 | || h->root.root.string[1] == '\0' | |
2388 | || (! info->shared | |
2389 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 | |
2390 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)) | |
5bd4f169 | 2391 | { |
65f38f15 AM |
2392 | /* This case can occur if we saw a PLT reloc in an input |
2393 | file, but the symbol was never referred to by a dynamic | |
2394 | object, or if all references were garbage collected. In | |
2395 | such a case, we don't actually need to build a procedure | |
2396 | linkage table entry. */ | |
5bd4f169 AM |
2397 | h->plt.offset = (bfd_vma) -1; |
2398 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
2399 | return true; | |
2400 | } | |
2401 | ||
65f38f15 AM |
2402 | /* Find the corresponding function descriptor symbol. Create it |
2403 | as undefined if necessary. ppc_elf64_finish_dynamic_symbol | |
2404 | will look it up again and create a JMP_SLOT reloc for it. */ | |
5bd4f169 | 2405 | |
65f38f15 AM |
2406 | fdh = elf_link_hash_lookup (elf_hash_table (info), |
2407 | h->root.root.string + 1, | |
2408 | false, false, false); | |
5bd4f169 | 2409 | |
65f38f15 | 2410 | if (fdh == NULL) |
5bd4f169 | 2411 | { |
65f38f15 AM |
2412 | asymbol *newsym; |
2413 | ||
2414 | /* Create it as undefined. */ | |
2415 | newsym = bfd_make_empty_symbol (htab->elf.dynobj); | |
2416 | newsym->name = h->root.root.string + 1; | |
2417 | newsym->section = bfd_und_section_ptr; | |
2418 | newsym->value = 0; | |
2419 | newsym->flags = BSF_DYNAMIC | BSF_OBJECT; | |
2420 | ||
2421 | if ( !(_bfd_generic_link_add_one_symbol | |
2422 | (info, htab->elf.dynobj, newsym->name, newsym->flags, | |
2423 | newsym->section, newsym->value, NULL, false, false, | |
2424 | (struct bfd_link_hash_entry **) &fdh))) | |
5bd4f169 | 2425 | { |
65f38f15 | 2426 | return false; |
5bd4f169 | 2427 | } |
5bd4f169 | 2428 | } |
5bd4f169 AM |
2429 | return true; |
2430 | } | |
bbd7ec4a AM |
2431 | else |
2432 | h->plt.offset = (bfd_vma) -1; | |
5bd4f169 AM |
2433 | |
2434 | /* If this is a weak symbol, and there is a real definition, the | |
2435 | processor independent code will have arranged for us to see the | |
2436 | real definition first, and we can just use the same value. */ | |
2437 | if (h->weakdef != NULL) | |
2438 | { | |
2439 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
2440 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
2441 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
2442 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
0a991dfe | 2443 | return true; |
5bd4f169 AM |
2444 | } |
2445 | ||
2446 | /* This is a reference to a symbol defined by a dynamic object which | |
2447 | is not a function. */ | |
2448 | ||
2449 | /* If we are creating a shared library, we must presume that the | |
2450 | only references to the symbol are via the global offset table. | |
2451 | For such cases we need not do anything here; the relocations will | |
2452 | be handled correctly by relocate_section. */ | |
2453 | if (info->shared) | |
2454 | return true; | |
2455 | ||
65f38f15 AM |
2456 | /* If there are no references to this symbol that do not use the |
2457 | GOT, we don't need to generate a copy reloc. */ | |
2458 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
2459 | return true; | |
2460 | ||
2461 | eh = (struct ppc_link_hash_entry *) h; | |
2462 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
2463 | { | |
2464 | s = p->sec->output_section; | |
2465 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
2466 | break; | |
2467 | } | |
2468 | ||
2469 | /* If we didn't find any dynamic relocs in read-only sections, then | |
5d1634d7 | 2470 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
65f38f15 AM |
2471 | if (p == NULL) |
2472 | { | |
2473 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
2474 | return true; | |
2475 | } | |
2476 | ||
5bd4f169 AM |
2477 | /* We must allocate the symbol in our .dynbss section, which will |
2478 | become part of the .bss section of the executable. There will be | |
2479 | an entry for this symbol in the .dynsym section. The dynamic | |
2480 | object will contain position independent code, so all references | |
2481 | from the dynamic object to this symbol will go through the global | |
2482 | offset table. The dynamic linker will use the .dynsym entry to | |
2483 | determine the address it must put in the global offset table, so | |
2484 | both the dynamic object and the regular object will refer to the | |
2485 | same memory location for the variable. */ | |
5bd4f169 AM |
2486 | |
2487 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
2488 | copy the initial value out of the dynamic object and into the | |
2489 | runtime process image. We need to remember the offset into the | |
2490 | .rela.bss section we are going to use. */ | |
2491 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
2492 | { | |
65f38f15 | 2493 | htab->srelbss->_raw_size += sizeof (Elf64_External_Rela); |
5bd4f169 AM |
2494 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
2495 | } | |
2496 | ||
2497 | /* We need to figure out the alignment required for this symbol. I | |
2498 | have no idea how ELF linkers handle this. */ | |
2499 | power_of_two = bfd_log2 (h->size); | |
2500 | if (power_of_two > 4) | |
2501 | power_of_two = 4; | |
2502 | ||
2503 | /* Apply the required alignment. */ | |
65f38f15 AM |
2504 | s = htab->sdynbss; |
2505 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); | |
2506 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) | |
5bd4f169 | 2507 | { |
65f38f15 | 2508 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
5bd4f169 AM |
2509 | return false; |
2510 | } | |
2511 | ||
2512 | /* Define the symbol as being at this point in the section. */ | |
2513 | h->root.u.def.section = s; | |
2514 | h->root.u.def.value = s->_raw_size; | |
2515 | ||
2516 | /* Increment the section size to make room for the symbol. */ | |
2517 | s->_raw_size += h->size; | |
2518 | ||
2519 | return true; | |
2520 | } | |
2521 | ||
65f38f15 AM |
2522 | /* This is the condition under which ppc64_elf_finish_dynamic_symbol |
2523 | will be called from elflink.h. If elflink.h doesn't call our | |
2524 | finish_dynamic_symbol routine, we'll need to do something about | |
2525 | initializing any .plt and .got entries in ppc64_elf_relocate_section. */ | |
2526 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ | |
2527 | ((DYN) \ | |
2528 | && ((INFO)->shared \ | |
2529 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ | |
2530 | && ((H)->dynindx != -1 \ | |
2531 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
5bd4f169 | 2532 | |
65f38f15 AM |
2533 | /* Allocate space in .plt, .got and associated reloc sections for |
2534 | dynamic relocs. */ | |
5bd4f169 AM |
2535 | |
2536 | static boolean | |
65f38f15 AM |
2537 | allocate_dynrelocs (h, inf) |
2538 | struct elf_link_hash_entry *h; | |
2539 | PTR inf; | |
5bd4f169 | 2540 | { |
65f38f15 AM |
2541 | struct bfd_link_info *info; |
2542 | struct ppc_link_hash_table *htab; | |
5bd4f169 | 2543 | asection *s; |
65f38f15 AM |
2544 | struct ppc_link_hash_entry *eh; |
2545 | struct ppc_dyn_relocs *p; | |
5bd4f169 | 2546 | |
65f38f15 AM |
2547 | if (h->root.type == bfd_link_hash_indirect |
2548 | || h->root.type == bfd_link_hash_warning) | |
2549 | return true; | |
5bd4f169 | 2550 | |
65f38f15 AM |
2551 | info = (struct bfd_link_info *) inf; |
2552 | htab = ppc_hash_table (info); | |
5bd4f169 | 2553 | |
65f38f15 AM |
2554 | if (htab->elf.dynamic_sections_created |
2555 | && h->plt.refcount > 0) | |
5bd4f169 | 2556 | { |
65f38f15 AM |
2557 | /* Make sure this symbol is output as a dynamic symbol. |
2558 | Undefined weak syms won't yet be marked as dynamic. */ | |
2559 | if (h->dynindx == -1 | |
2560 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
5bd4f169 | 2561 | { |
65f38f15 AM |
2562 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
2563 | return false; | |
5bd4f169 | 2564 | } |
5bd4f169 | 2565 | |
65f38f15 AM |
2566 | BFD_ASSERT (h->root.root.string[0] == '.' |
2567 | && h->root.root.string[1] != '\0'); | |
5bd4f169 | 2568 | |
65f38f15 AM |
2569 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) |
2570 | { | |
2571 | /* Make sure the corresponding function descriptor symbol is | |
2572 | dynamic too. */ | |
2573 | ||
2574 | if (h->dynindx != -1) | |
2575 | { | |
2576 | struct elf_link_hash_entry *fdh; | |
5bd4f169 | 2577 | |
65f38f15 AM |
2578 | fdh = elf_link_hash_lookup (elf_hash_table (info), |
2579 | h->root.root.string + 1, | |
2580 | false, false, false); | |
5bd4f169 | 2581 | |
65f38f15 AM |
2582 | if (fdh == NULL) |
2583 | abort (); | |
5bd4f169 | 2584 | |
65f38f15 AM |
2585 | if (fdh->dynindx == -1 |
2586 | && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
2587 | { | |
2588 | if (! bfd_elf64_link_record_dynamic_symbol (info, fdh)) | |
2589 | return false; | |
2590 | } | |
2591 | } | |
2592 | ||
2593 | /* If this is the first .plt entry, make room for the special | |
2594 | first entry. */ | |
2595 | s = htab->splt; | |
5bd4f169 | 2596 | if (s->_raw_size == 0) |
65f38f15 AM |
2597 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; |
2598 | ||
2599 | h->plt.offset = s->_raw_size; | |
5d1634d7 | 2600 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
65f38f15 AM |
2601 | |
2602 | /* Make room for this entry. */ | |
2603 | s->_raw_size += PLT_ENTRY_SIZE; | |
2604 | ||
5d1634d7 AM |
2605 | /* Make room for the .stub and .glink code. */ |
2606 | s = htab->sstub; | |
2607 | s->_raw_size += PLT_CALL_STUB_SIZE; | |
65f38f15 | 2608 | |
5d1634d7 AM |
2609 | s = htab->sglink; |
2610 | if (s->_raw_size == 0) | |
2611 | s->_raw_size += GLINK_CALL_STUB_SIZE; | |
2612 | /* We need bigger stubs past index 32767. */ | |
2613 | if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4) | |
2614 | s->_raw_size += 4; | |
2615 | s->_raw_size += 2*4; | |
65f38f15 AM |
2616 | |
2617 | /* We also need to make an entry in the .rela.plt section. */ | |
2618 | s = htab->srelplt; | |
2619 | s->_raw_size += sizeof (Elf64_External_Rela); | |
2620 | } | |
2621 | else | |
2622 | { | |
2623 | h->plt.offset = (bfd_vma) -1; | |
2624 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
2625 | } | |
2626 | } | |
2627 | else | |
2628 | { | |
2629 | h->plt.offset = (bfd_vma) -1; | |
2630 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
2631 | } | |
2632 | ||
2633 | if (h->got.refcount > 0) | |
2634 | { | |
2635 | boolean dyn; | |
2636 | ||
2637 | /* Make sure this symbol is output as a dynamic symbol. | |
2638 | Undefined weak syms won't yet be marked as dynamic. */ | |
2639 | if (h->dynindx == -1 | |
2640 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
2641 | { | |
2642 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
2643 | return false; | |
2644 | } | |
2645 | ||
2646 | s = htab->sgot; | |
2647 | h->got.offset = s->_raw_size; | |
2648 | s->_raw_size += 8; | |
2649 | dyn = htab->elf.dynamic_sections_created; | |
2650 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) | |
2651 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); | |
2652 | } | |
2653 | else | |
2654 | h->got.offset = (bfd_vma) -1; | |
2655 | ||
2656 | eh = (struct ppc_link_hash_entry *) h; | |
2657 | if (eh->dyn_relocs == NULL) | |
2658 | return true; | |
2659 | ||
2660 | /* In the shared -Bsymbolic case, discard space allocated for | |
2661 | dynamic pc-relative relocs against symbols which turn out to be | |
2662 | defined in regular objects. For the normal shared case, discard | |
2663 | space for relocs that have become local due to symbol visibility | |
2664 | changes. */ | |
2665 | ||
2666 | if (info->shared) | |
2667 | { | |
2668 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 | |
2669 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 | |
2670 | || info->symbolic)) | |
2671 | { | |
2672 | struct ppc_dyn_relocs **pp; | |
2673 | ||
2674 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
5bd4f169 | 2675 | { |
65f38f15 AM |
2676 | p->count -= p->pc_count; |
2677 | p->pc_count = 0; | |
2678 | if (p->count == 0) | |
2679 | *pp = p->next; | |
2680 | else | |
2681 | pp = &p->next; | |
5bd4f169 | 2682 | } |
65f38f15 AM |
2683 | } |
2684 | } | |
2685 | else | |
2686 | { | |
2687 | /* For the non-shared case, discard space for relocs against | |
2688 | symbols which turn out to need copy relocs or are not | |
2689 | dynamic. */ | |
2690 | ||
2691 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
2692 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
2693 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
2694 | || (htab->elf.dynamic_sections_created | |
2695 | && (h->root.type == bfd_link_hash_undefweak | |
2696 | || h->root.type == bfd_link_hash_undefined)))) | |
2697 | { | |
2698 | /* Make sure this symbol is output as a dynamic symbol. | |
2699 | Undefined weak syms won't yet be marked as dynamic. */ | |
2700 | if (h->dynindx == -1 | |
2701 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
2702 | { | |
ec338859 | 2703 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) |
65f38f15 AM |
2704 | return false; |
2705 | } | |
2706 | ||
2707 | /* If that succeeded, we know we'll be keeping all the | |
2708 | relocs. */ | |
2709 | if (h->dynindx != -1) | |
2710 | goto keep; | |
2711 | } | |
2712 | ||
2713 | eh->dyn_relocs = NULL; | |
2714 | ||
ec338859 | 2715 | keep: ; |
65f38f15 AM |
2716 | } |
2717 | ||
2718 | /* Finally, allocate space. */ | |
2719 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
2720 | { | |
2721 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
2722 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
2723 | } | |
2724 | ||
2725 | return true; | |
2726 | } | |
2727 | ||
2728 | /* Find any dynamic relocs that apply to read-only sections. */ | |
2729 | ||
2730 | static boolean | |
2731 | readonly_dynrelocs (h, inf) | |
2732 | struct elf_link_hash_entry *h; | |
2733 | PTR inf; | |
2734 | { | |
2735 | struct ppc_link_hash_entry *eh; | |
2736 | struct ppc_dyn_relocs *p; | |
2737 | ||
2738 | eh = (struct ppc_link_hash_entry *) h; | |
2739 | for (p = eh->dyn_relocs; p != NULL; p = p->next) | |
2740 | { | |
2741 | asection *s = p->sec->output_section; | |
2742 | ||
2743 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
2744 | { | |
2745 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
2746 | ||
2747 | info->flags |= DF_TEXTREL; | |
2748 | ||
2749 | /* Not an error, just cut short the traversal. */ | |
2750 | return false; | |
2751 | } | |
2752 | } | |
2753 | return true; | |
2754 | } | |
2755 | ||
2756 | /* Set the sizes of the dynamic sections. */ | |
2757 | ||
2758 | static boolean | |
2759 | ppc64_elf_size_dynamic_sections (output_bfd, info) | |
2760 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2761 | struct bfd_link_info *info; | |
2762 | { | |
2763 | struct ppc_link_hash_table *htab; | |
2764 | bfd *dynobj; | |
2765 | asection *s; | |
2766 | boolean relocs; | |
2767 | bfd *ibfd; | |
2768 | ||
2769 | htab = ppc_hash_table (info); | |
2770 | dynobj = htab->elf.dynobj; | |
2771 | if (dynobj == NULL) | |
2772 | abort (); | |
2773 | ||
2774 | if (htab->elf.dynamic_sections_created) | |
2775 | { | |
2776 | /* Set the contents of the .interp section to the interpreter. */ | |
2777 | if (! info->shared) | |
2778 | { | |
2779 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
2780 | if (s == NULL) | |
2781 | abort (); | |
2782 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
2783 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
2784 | } | |
2785 | } | |
2786 | ||
2787 | /* Set up .got offsets for local syms, and space for local dynamic | |
2788 | relocs. */ | |
2789 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
2790 | { | |
2791 | bfd_signed_vma *local_got; | |
2792 | bfd_signed_vma *end_local_got; | |
2793 | bfd_size_type locsymcount; | |
2794 | Elf_Internal_Shdr *symtab_hdr; | |
2795 | asection *srel; | |
2796 | ||
2797 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
2798 | continue; | |
2799 | ||
2800 | for (s = ibfd->sections; s != NULL; s = s->next) | |
2801 | { | |
ec338859 | 2802 | struct ppc_dyn_relocs *p; |
65f38f15 | 2803 | |
ec338859 AM |
2804 | for (p = *((struct ppc_dyn_relocs **) |
2805 | &elf_section_data (s)->local_dynrel); | |
2806 | p != NULL; | |
2807 | p = p->next) | |
65f38f15 | 2808 | { |
ec338859 AM |
2809 | if (!bfd_is_abs_section (p->sec) |
2810 | && bfd_is_abs_section (p->sec->output_section)) | |
2811 | { | |
2812 | /* Input section has been discarded, either because | |
2813 | it is a copy of a linkonce section or due to | |
2814 | linker script /DISCARD/, so we'll be discarding | |
2815 | the relocs too. */ | |
2816 | } | |
2817 | else | |
2818 | { | |
2819 | srel = elf_section_data (p->sec)->sreloc; | |
2820 | srel->_raw_size += p->count * sizeof (Elf64_External_Rela); | |
2821 | } | |
65f38f15 AM |
2822 | } |
2823 | } | |
2824 | ||
2825 | local_got = elf_local_got_refcounts (ibfd); | |
2826 | if (!local_got) | |
2827 | continue; | |
2828 | ||
2829 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
2830 | locsymcount = symtab_hdr->sh_info; | |
2831 | end_local_got = local_got + locsymcount; | |
2832 | s = htab->sgot; | |
2833 | srel = htab->srelgot; | |
2834 | for (; local_got < end_local_got; ++local_got) | |
2835 | { | |
2836 | if (*local_got > 0) | |
5bd4f169 | 2837 | { |
65f38f15 AM |
2838 | *local_got = s->_raw_size; |
2839 | s->_raw_size += 8; | |
2840 | if (info->shared) | |
2841 | srel->_raw_size += sizeof (Elf64_External_Rela); | |
5bd4f169 | 2842 | } |
65f38f15 AM |
2843 | else |
2844 | *local_got = (bfd_vma) -1; | |
2845 | } | |
2846 | } | |
2847 | ||
2848 | /* Allocate global sym .plt and .got entries, and space for global | |
2849 | sym dynamic relocs. */ | |
2850 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); | |
2851 | ||
2852 | /* We now have determined the sizes of the various dynamic sections. | |
2853 | Allocate memory for them. */ | |
2854 | relocs = false; | |
2855 | for (s = dynobj->sections; s != NULL; s = s->next) | |
2856 | { | |
5d1634d7 AM |
2857 | bfd_vma size; |
2858 | ||
65f38f15 AM |
2859 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
2860 | continue; | |
2861 | ||
2862 | if (s == htab->splt | |
2863 | || s == htab->sgot | |
5d1634d7 | 2864 | || s == htab->sstub |
65f38f15 AM |
2865 | || s == htab->sglink) |
2866 | { | |
2867 | /* Strip this section if we don't need it; see the | |
2868 | comment below. */ | |
5bd4f169 | 2869 | } |
65f38f15 | 2870 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
5bd4f169 AM |
2871 | { |
2872 | if (s->_raw_size == 0) | |
2873 | { | |
2874 | /* If we don't need this section, strip it from the | |
2875 | output file. This is mostly to handle .rela.bss and | |
2876 | .rela.plt. We must create both sections in | |
2877 | create_dynamic_sections, because they must be created | |
2878 | before the linker maps input sections to output | |
2879 | sections. The linker does that before | |
2880 | adjust_dynamic_symbol is called, and it is that | |
2881 | function which decides whether anything needs to go | |
2882 | into these sections. */ | |
5bd4f169 AM |
2883 | } |
2884 | else | |
2885 | { | |
65f38f15 AM |
2886 | if (s != htab->srelplt) |
2887 | relocs = true; | |
5bd4f169 AM |
2888 | |
2889 | /* We use the reloc_count field as a counter if we need | |
2890 | to copy relocs into the output file. */ | |
2891 | s->reloc_count = 0; | |
2892 | } | |
2893 | } | |
65f38f15 | 2894 | else |
5bd4f169 AM |
2895 | { |
2896 | /* It's not one of our sections, so don't allocate space. */ | |
2897 | continue; | |
2898 | } | |
2899 | ||
65f38f15 | 2900 | if (s->_raw_size == 0) |
5bd4f169 AM |
2901 | { |
2902 | _bfd_strip_section_from_output (info, s); | |
2903 | continue; | |
2904 | } | |
2905 | ||
65f38f15 AM |
2906 | /* Allocate memory for the section contents. We use bfd_zalloc |
2907 | here in case unused entries are not reclaimed before the | |
2908 | section's contents are written out. This should not happen, | |
2909 | but this way if it does, we get a R_PPC64_NONE reloc instead | |
2910 | of garbage. */ | |
5d1634d7 AM |
2911 | size = s->_raw_size; |
2912 | if (s == htab->sstub) | |
2913 | { | |
2914 | /* .stub may grow. Allocate enough for the maximum growth. */ | |
2915 | size += (size + 65536 + 65535) / 65536 * 4; | |
2916 | } | |
2917 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, size); | |
65f38f15 | 2918 | if (s->contents == NULL) |
5bd4f169 AM |
2919 | return false; |
2920 | } | |
2921 | ||
2922 | if (elf_hash_table (info)->dynamic_sections_created) | |
2923 | { | |
2924 | /* Add some entries to the .dynamic section. We fill in the | |
2925 | values later, in ppc64_elf_finish_dynamic_sections, but we | |
2926 | must add the entries now so that we get the correct size for | |
2927 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
2928 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
2929 | #define add_dynamic_entry(TAG, VAL) \ |
2930 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
2931 | ||
2932 | if (!info->shared) | |
5bd4f169 | 2933 | { |
dc810e39 | 2934 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
5bd4f169 AM |
2935 | return false; |
2936 | } | |
2937 | ||
65f38f15 | 2938 | if (htab->splt->_raw_size != 0) |
5bd4f169 | 2939 | { |
dc810e39 AM |
2940 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
2941 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
2942 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
5d1634d7 AM |
2943 | || !add_dynamic_entry (DT_JMPREL, 0) |
2944 | || !add_dynamic_entry (DT_PPC64_GLINK, 0)) | |
5bd4f169 AM |
2945 | return false; |
2946 | } | |
2947 | ||
2948 | if (relocs) | |
2949 | { | |
dc810e39 AM |
2950 | if (!add_dynamic_entry (DT_RELA, 0) |
2951 | || !add_dynamic_entry (DT_RELASZ, 0) | |
2952 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) | |
5bd4f169 | 2953 | return false; |
5bd4f169 | 2954 | |
65f38f15 AM |
2955 | /* If any dynamic relocs apply to a read-only section, |
2956 | then we need a DT_TEXTREL entry. */ | |
2957 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, (PTR) info); | |
5bd4f169 | 2958 | |
65f38f15 | 2959 | if ((info->flags & DF_TEXTREL) != 0) |
5bd4f169 | 2960 | { |
65f38f15 AM |
2961 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
2962 | return false; | |
5bd4f169 | 2963 | } |
5bd4f169 | 2964 | } |
5bd4f169 | 2965 | } |
65f38f15 | 2966 | #undef add_dynamic_entry |
5bd4f169 AM |
2967 | |
2968 | return true; | |
2969 | } | |
2970 | ||
2971 | /* Called after we have seen all the input files/sections, but before | |
2972 | final symbol resolution and section placement has been determined. | |
2973 | ||
2974 | We use this hook to provide a value for TOCstart, which we store in | |
5d1634d7 | 2975 | the output bfd elf_gp. */ |
5bd4f169 | 2976 | |
5d1634d7 AM |
2977 | boolean |
2978 | ppc64_elf_set_toc (obfd, info) | |
2979 | bfd *obfd; | |
5bd4f169 AM |
2980 | struct bfd_link_info *info; |
2981 | { | |
5d1634d7 | 2982 | if (!info->relocateable) |
5bd4f169 AM |
2983 | { |
2984 | asection *s; | |
2985 | bfd_vma TOCstart; | |
2986 | ||
5d1634d7 | 2987 | /* The TOC consists of sections .got, .toc, .tocbss, .plt in that |
5bd4f169 | 2988 | order. The TOC starts where the first of these sections starts. */ |
5d1634d7 | 2989 | s = bfd_get_section_by_name (obfd, ".got"); |
5bd4f169 | 2990 | if (s == NULL) |
5d1634d7 | 2991 | s = bfd_get_section_by_name (obfd, ".toc"); |
5bd4f169 | 2992 | if (s == NULL) |
5d1634d7 | 2993 | s = bfd_get_section_by_name (obfd, ".tocbss"); |
5bd4f169 | 2994 | if (s == NULL) |
5d1634d7 | 2995 | s = bfd_get_section_by_name (obfd, ".plt"); |
5bd4f169 AM |
2996 | if (s == NULL) |
2997 | { | |
2998 | /* This may happen for | |
2999 | o references to TOC base (SYM@toc / TOC[tc0]) without a | |
3000 | .toc directive | |
3001 | o bad linker script | |
3002 | o --gc-sections and empty TOC sections | |
3003 | ||
3004 | FIXME: Warn user? */ | |
3005 | ||
3006 | /* Look for a likely section. We probably won't even be | |
3007 | using TOCstart. */ | |
5d1634d7 | 3008 | for (s = obfd->sections; s != NULL; s = s->next) |
5bd4f169 AM |
3009 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY)) |
3010 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
3011 | break; | |
3012 | if (s == NULL) | |
5d1634d7 | 3013 | for (s = obfd->sections; s != NULL; s = s->next) |
5bd4f169 AM |
3014 | if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA)) |
3015 | == (SEC_ALLOC | SEC_SMALL_DATA)) | |
3016 | break; | |
3017 | if (s == NULL) | |
5d1634d7 | 3018 | for (s = obfd->sections; s != NULL; s = s->next) |
5bd4f169 AM |
3019 | if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC) |
3020 | break; | |
3021 | if (s == NULL) | |
5d1634d7 | 3022 | for (s = obfd->sections; s != NULL; s = s->next) |
5bd4f169 AM |
3023 | if ((s->flags & SEC_ALLOC) == SEC_ALLOC) |
3024 | break; | |
3025 | } | |
3026 | ||
3027 | TOCstart = 0; | |
3028 | if (s != NULL) | |
3029 | TOCstart = s->output_section->vma + s->output_offset; | |
3030 | ||
5d1634d7 AM |
3031 | elf_gp (obfd) = TOCstart; |
3032 | } | |
3033 | return true; | |
3034 | } | |
3035 | ||
3036 | /* PowerPC64 .plt entries are 24 bytes long, which doesn't divide | |
3037 | evenly into 64k. Sometimes with a large enough .plt, we'll need to | |
3038 | use offsets differing in the high 16 bits when accessing a .plt | |
3039 | entry from a .plt call stub. This function adjusts the size of | |
3040 | .stub to accommodate the extra stub instruction needed in such | |
3041 | cases. */ | |
3042 | ||
3043 | boolean | |
3044 | ppc64_elf_size_stubs (obfd, info, changed) | |
3045 | bfd *obfd; | |
3046 | struct bfd_link_info *info; | |
3047 | int *changed; | |
3048 | { | |
3049 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
3050 | bfd_vma plt_offset, next_64k; | |
3051 | long base, num, extra; | |
3052 | ||
3053 | /* .plt and .stub should be both present, or both absent. */ | |
3054 | if ((htab->splt == NULL || htab->splt->_raw_size == 0) | |
3055 | != (htab->sstub == NULL || htab->sstub->_raw_size == 0)) | |
3056 | abort (); | |
3057 | ||
3058 | /* If no .plt, then nothing to do. */ | |
3059 | if (htab->splt == NULL || htab->splt->_raw_size == 0) | |
3060 | return true; | |
3061 | ||
3062 | plt_offset = (htab->splt->output_section->vma | |
3063 | + htab->splt->output_offset | |
3064 | - elf_gp (obfd)); | |
3065 | next_64k = (plt_offset + 65535) & -65536; | |
3066 | ||
3067 | /* If the .plt doesn't have any entries crossing a 64k boundary, | |
3068 | then there is no need for bigger stubs. */ | |
3069 | if (next_64k <= plt_offset + htab->splt->_raw_size) | |
3070 | return true; | |
3071 | ||
3072 | /* OK, so we have at least one transition. Since .plt entries are | |
3073 | 24 bytes long, we'll strike it lucky every 3*64k, with the 64k | |
3074 | boundary between .plt entries. */ | |
3075 | base = next_64k / 65536; | |
3076 | num = (plt_offset + htab->splt->_raw_size - next_64k) / 65536; | |
3077 | extra = (base % 3 + num + 1) * 2 / 3; | |
3078 | ||
3079 | /* Allow one extra instruction for each EXTRA. The change in .stub | |
3080 | may change the location of .toc and .plt. .toc and .plt ought to | |
3081 | move as a group, but someone might be playing with eg. .plt | |
3082 | alignment, so don't allow .stub size to decrease. */ | |
3083 | if (htab->sstub->_cooked_size < htab->sstub->_raw_size + extra * 4) | |
3084 | { | |
3085 | htab->sstub->_cooked_size = htab->sstub->_raw_size + extra * 4; | |
3086 | *changed = true; | |
3087 | } | |
3088 | return true; | |
3089 | } | |
3090 | ||
3091 | /* Build a .plt call stub. */ | |
3092 | ||
3093 | static bfd_byte * | |
3094 | build_plt_stub (obfd, p, offset, glink) | |
3095 | bfd *obfd; | |
3096 | bfd_byte *p; | |
3097 | int offset; | |
3098 | int glink; | |
3099 | { | |
3100 | #define PPC_LO(v) ((v) & 0xffff) | |
3101 | #define PPC_HI(v) (((v) >> 16) & 0xffff) | |
3102 | #define PPC_HA(v) PPC_HI ((v) + 0x8000) | |
3103 | ||
3104 | if (glink) | |
3105 | bfd_put_32 (obfd, LD_R2_40R1, p), p += 4; | |
3106 | bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; | |
3107 | if (!glink) | |
3108 | bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; | |
3109 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
3110 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
3111 | bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4; | |
3112 | offset += 8; | |
3113 | bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; | |
3114 | if (PPC_HA (offset + 8) != PPC_HA (offset)) | |
3115 | bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4; | |
3116 | offset += 8; | |
3117 | bfd_put_32 (obfd, MTCTR_R11, p), p += 4; | |
3118 | bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; | |
3119 | bfd_put_32 (obfd, BCTR, p), p += 4; | |
3120 | return p; | |
3121 | } | |
3122 | ||
3123 | /* Build the stubs for one function call. */ | |
3124 | ||
3125 | static boolean | |
3126 | build_one_stub (h, inf) | |
3127 | struct elf_link_hash_entry *h; | |
3128 | PTR inf; | |
3129 | { | |
3130 | struct bfd_link_info *info; | |
3131 | struct ppc_link_hash_table *htab; | |
3132 | ||
3133 | if (h->root.type == bfd_link_hash_indirect | |
3134 | || h->root.type == bfd_link_hash_warning) | |
3135 | return true; | |
3136 | ||
3137 | info = (struct bfd_link_info *) inf; | |
3138 | htab = ppc_hash_table (info); | |
3139 | ||
3140 | if (htab->elf.dynamic_sections_created | |
3141 | && h->plt.offset != (bfd_vma) -1) | |
3142 | { | |
3143 | asection *s; | |
3144 | bfd_vma plt_r2; | |
3145 | bfd_byte *p; | |
3146 | unsigned int indx; | |
3147 | ||
3148 | /* Point the function at the linkage stub. This works because | |
3149 | the only references to the function code sym are calls. | |
3150 | Function pointer comparisons use the function descriptor. */ | |
3151 | s = htab->sstub; | |
3152 | h->root.type = bfd_link_hash_defined; | |
3153 | h->root.u.def.section = s; | |
3154 | h->root.u.def.value = s->_cooked_size; | |
3155 | ||
3156 | /* Build the .plt call stub. */ | |
3157 | plt_r2 = (htab->splt->output_section->vma | |
3158 | + htab->splt->output_offset | |
3159 | + h->plt.offset | |
3160 | - elf_gp (htab->splt->output_section->owner) | |
3161 | - TOC_BASE_OFF); | |
3162 | ||
3163 | if (plt_r2 + 0x80000000 > 0xffffffff) | |
3164 | { | |
3165 | (*_bfd_error_handler) | |
3166 | (_("linkage table overflow against `%s'"), | |
3167 | h->root.root.string); | |
3168 | bfd_set_error (bfd_error_bad_value); | |
3169 | htab->plt_overflow = true; | |
3170 | return false; | |
3171 | } | |
3172 | p = s->contents + s->_cooked_size; | |
3173 | p = build_plt_stub (s->owner, p, (int) plt_r2, 0); | |
3174 | s->_cooked_size = p - s->contents; | |
3175 | ||
3176 | /* Build the .glink lazy link call stub. */ | |
3177 | s = htab->sglink; | |
3178 | p = s->contents + s->_cooked_size; | |
3179 | indx = s->reloc_count; | |
3180 | if (indx < 0x8000) | |
3181 | { | |
3182 | bfd_put_32 (s->owner, LI_R0_0 | indx, p); | |
3183 | p += 4; | |
3184 | } | |
3185 | else | |
3186 | { | |
3187 | bfd_put_32 (s->owner, LIS_R0_0 | PPC_HI (indx), p); | |
3188 | p += 4; | |
3189 | bfd_put_32 (s->owner, ORI_R0_R0_0 | PPC_LO (indx), p); | |
3190 | p += 4; | |
3191 | } | |
3192 | bfd_put_32 (s->owner, B_DOT | ((s->contents - p) & 0x3fffffc), p); | |
3193 | p += 4; | |
3194 | s->_cooked_size = p - s->contents; | |
3195 | s->reloc_count += 1; | |
5bd4f169 | 3196 | } |
5d1634d7 AM |
3197 | return true; |
3198 | } | |
5bd4f169 | 3199 | |
5d1634d7 AM |
3200 | boolean |
3201 | ppc64_elf_build_stubs (obfd, info) | |
3202 | bfd *obfd; | |
3203 | struct bfd_link_info *info; | |
3204 | { | |
3205 | struct ppc_link_hash_table *htab = ppc_hash_table (info); | |
3206 | bfd_vma old_stub_size; | |
3207 | bfd_vma plt_r2; | |
3208 | bfd_byte *p; | |
3209 | ||
3210 | /* If no .plt stubs, then nothing to do. */ | |
3211 | if (htab->sstub == NULL || htab->sstub->_raw_size == 0) | |
3212 | return true; | |
3213 | ||
3214 | old_stub_size = htab->sstub->_cooked_size; | |
3215 | htab->sstub->_cooked_size = 0; | |
3216 | ||
3217 | /* Build the .glink plt call stub. */ | |
3218 | plt_r2 = (htab->splt->output_section->vma | |
3219 | + htab->splt->output_offset | |
3220 | - elf_gp (obfd) | |
3221 | - TOC_BASE_OFF); | |
3222 | p = htab->sglink->contents; | |
3223 | p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1); | |
3224 | while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE) | |
3225 | { | |
3226 | bfd_put_32 (htab->sglink->owner, NOP, p); | |
3227 | p += 4; | |
3228 | } | |
3229 | htab->sglink->_cooked_size = p - htab->sglink->contents; | |
3230 | ||
3231 | /* Use reloc_count to count entries. */ | |
3232 | htab->sglink->reloc_count = 0; | |
3233 | ||
3234 | elf_link_hash_traverse (&htab->elf, build_one_stub, (PTR) info); | |
3235 | htab->sglink->reloc_count = 0; | |
3236 | ||
3237 | if (htab->plt_overflow) | |
3238 | return false; | |
3239 | ||
3240 | if (old_stub_size != htab->sstub->_cooked_size | |
3241 | || htab->sglink->_raw_size != htab->sglink->_cooked_size) | |
3242 | { | |
3243 | (*_bfd_error_handler) | |
3244 | (_("stub section size doesn't match calculated size")); | |
3245 | bfd_set_error (bfd_error_bad_value); | |
3246 | return false; | |
3247 | } | |
3248 | return true; | |
5bd4f169 AM |
3249 | } |
3250 | ||
3251 | /* Set up any other section flags and such that may be necessary. */ | |
3252 | ||
3253 | static boolean | |
3254 | ppc64_elf_fake_sections (abfd, shdr, asect) | |
3255 | bfd *abfd ATTRIBUTE_UNUSED; | |
3256 | Elf64_Internal_Shdr *shdr; | |
3257 | asection *asect; | |
3258 | { | |
3259 | if ((asect->flags & SEC_EXCLUDE) != 0) | |
3260 | shdr->sh_flags |= SHF_EXCLUDE; | |
3261 | ||
3262 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
3263 | shdr->sh_type = SHT_ORDERED; | |
3264 | ||
3265 | return true; | |
3266 | } | |
3267 | ||
3268 | /* The RELOCATE_SECTION function is called by the ELF backend linker | |
3269 | to handle the relocations for a section. | |
3270 | ||
3271 | The relocs are always passed as Rela structures; if the section | |
3272 | actually uses Rel structures, the r_addend field will always be | |
3273 | zero. | |
3274 | ||
3275 | This function is responsible for adjust the section contents as | |
3276 | necessary, and (if using Rela relocs and generating a | |
3277 | relocateable output file) adjusting the reloc addend as | |
3278 | necessary. | |
3279 | ||
3280 | This function does not have to worry about setting the reloc | |
3281 | address or the reloc symbol index. | |
3282 | ||
3283 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
3284 | ||
3285 | LOCAL_SECTIONS is an array giving the section in the input file | |
3286 | corresponding to the st_shndx field of each local symbol. | |
3287 | ||
3288 | The global hash table entry for the global symbols can be found | |
3289 | via elf_sym_hashes (input_bfd). | |
3290 | ||
3291 | When generating relocateable output, this function must handle | |
3292 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
3293 | going to be the section symbol corresponding to the output | |
3294 | section, which means that the addend must be adjusted | |
3295 | accordingly. */ | |
3296 | ||
3297 | static boolean | |
3298 | ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section, | |
3299 | contents, relocs, local_syms, local_sections) | |
3300 | bfd *output_bfd; | |
3301 | struct bfd_link_info *info; | |
3302 | bfd *input_bfd; | |
3303 | asection *input_section; | |
3304 | bfd_byte *contents; | |
3305 | Elf_Internal_Rela *relocs; | |
3306 | Elf_Internal_Sym *local_syms; | |
3307 | asection **local_sections; | |
3308 | { | |
65f38f15 | 3309 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3310 | Elf_Internal_Shdr *symtab_hdr; |
3311 | struct elf_link_hash_entry **sym_hashes; | |
5bd4f169 AM |
3312 | Elf_Internal_Rela *rel; |
3313 | Elf_Internal_Rela *relend; | |
5bd4f169 AM |
3314 | bfd_vma *local_got_offsets; |
3315 | bfd_vma TOCstart; | |
3316 | boolean ret = true; | |
5bd4f169 | 3317 | |
65f38f15 | 3318 | /* Initialize howto table if needed. */ |
5bd4f169 | 3319 | if (!ppc64_elf_howto_table[R_PPC64_ADDR32]) |
5bd4f169 AM |
3320 | ppc_howto_init (); |
3321 | ||
65f38f15 | 3322 | htab = ppc_hash_table (info); |
5bd4f169 | 3323 | local_got_offsets = elf_local_got_offsets (input_bfd); |
5bd4f169 | 3324 | TOCstart = elf_gp (output_bfd); |
5bd4f169 AM |
3325 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
3326 | sym_hashes = elf_sym_hashes (input_bfd); | |
65f38f15 | 3327 | |
5bd4f169 AM |
3328 | rel = relocs; |
3329 | relend = relocs + input_section->reloc_count; | |
3330 | for (; rel < relend; rel++) | |
3331 | { | |
3332 | enum elf_ppc_reloc_type r_type; | |
3333 | bfd_vma offset; | |
3334 | bfd_vma addend; | |
3335 | bfd_reloc_status_type r; | |
3336 | Elf_Internal_Sym *sym; | |
3337 | asection *sec; | |
3338 | struct elf_link_hash_entry *h; | |
3339 | const char *sym_name; | |
5bd4f169 AM |
3340 | unsigned long r_symndx; |
3341 | bfd_vma relocation; | |
65f38f15 | 3342 | boolean unresolved_reloc; |
dc810e39 | 3343 | long insn; |
5bd4f169 AM |
3344 | |
3345 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info); | |
5bd4f169 AM |
3346 | r_symndx = ELF64_R_SYM (rel->r_info); |
3347 | ||
3348 | if (info->relocateable) | |
3349 | { | |
3350 | /* This is a relocatable link. We don't have to change | |
3351 | anything, unless the reloc is against a section symbol, | |
3352 | in which case we have to adjust according to where the | |
3353 | section symbol winds up in the output section. */ | |
3354 | if (r_symndx < symtab_hdr->sh_info) | |
3355 | { | |
3356 | sym = local_syms + r_symndx; | |
3357 | if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
3358 | { | |
3359 | sec = local_sections[r_symndx]; | |
65f38f15 | 3360 | rel->r_addend += sec->output_offset + sym->st_value; |
5bd4f169 AM |
3361 | } |
3362 | } | |
5bd4f169 AM |
3363 | continue; |
3364 | } | |
3365 | ||
3366 | /* This is a final link. */ | |
3367 | ||
65f38f15 AM |
3368 | offset = rel->r_offset; |
3369 | addend = rel->r_addend; | |
3370 | r = bfd_reloc_other; | |
3371 | sym = (Elf_Internal_Sym *) 0; | |
3372 | sec = (asection *) 0; | |
3373 | h = (struct elf_link_hash_entry *) 0; | |
3374 | sym_name = (const char *) 0; | |
3375 | unresolved_reloc = false; | |
3376 | ||
5bd4f169 AM |
3377 | if (r_type == R_PPC64_TOC) |
3378 | { | |
3379 | /* Relocation value is TOC base. Symbol is ignored. */ | |
3380 | relocation = TOCstart + TOC_BASE_OFF; | |
3381 | } | |
3382 | else if (r_symndx < symtab_hdr->sh_info) | |
3383 | { | |
3384 | /* It's a local symbol. */ | |
3385 | sym = local_syms + r_symndx; | |
3386 | sec = local_sections[r_symndx]; | |
3387 | sym_name = "<local symbol>"; | |
3388 | ||
f8df10f4 JJ |
3389 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
3390 | addend = rel->r_addend; | |
5bd4f169 AM |
3391 | } |
3392 | else | |
3393 | { | |
3394 | /* It's a global symbol. */ | |
3395 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3396 | while (h->root.type == bfd_link_hash_indirect | |
3397 | || h->root.type == bfd_link_hash_warning) | |
3398 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3399 | sym_name = h->root.root.string; | |
65f38f15 | 3400 | relocation = 0; |
5bd4f169 AM |
3401 | if (h->root.type == bfd_link_hash_defined |
3402 | || h->root.type == bfd_link_hash_defweak) | |
3403 | { | |
3404 | sec = h->root.u.def.section; | |
65f38f15 AM |
3405 | if (sec->output_section == NULL) |
3406 | /* Set a flag that will be cleared later if we find a | |
3407 | relocation value for this symbol. output_section | |
3408 | is typically NULL for symbols satisfied by a shared | |
3409 | library. */ | |
3410 | unresolved_reloc = true; | |
5bd4f169 AM |
3411 | else |
3412 | relocation = (h->root.u.def.value | |
3413 | + sec->output_section->vma | |
3414 | + sec->output_offset); | |
3415 | } | |
3416 | else if (h->root.type == bfd_link_hash_undefweak) | |
65f38f15 | 3417 | ; |
671bae9c | 3418 | else if (info->shared |
65f38f15 AM |
3419 | && (!info->symbolic || info->allow_shlib_undefined) |
3420 | && !info->no_undefined | |
3421 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) | |
3422 | ; | |
5bd4f169 AM |
3423 | else |
3424 | { | |
3425 | if (! ((*info->callbacks->undefined_symbol) | |
3426 | (info, h->root.root.string, input_bfd, input_section, | |
65f38f15 AM |
3427 | offset, (!info->shared |
3428 | || info->no_undefined | |
3429 | || ELF_ST_VISIBILITY (h->other))))) | |
5bd4f169 AM |
3430 | return false; |
3431 | relocation = 0; | |
3432 | } | |
3433 | } | |
3434 | ||
65f38f15 | 3435 | /* First handle relocations that tweak non-addend part of insn. */ |
86c76c7b | 3436 | insn = 0; |
65f38f15 | 3437 | switch (r_type) |
5bd4f169 AM |
3438 | { |
3439 | default: | |
65f38f15 | 3440 | break; |
5bd4f169 | 3441 | |
65f38f15 AM |
3442 | /* Branch taken prediction relocations. */ |
3443 | case R_PPC64_ADDR14_BRTAKEN: | |
3444 | case R_PPC64_REL14_BRTAKEN: | |
86c76c7b AM |
3445 | insn = 0x01 << 21; /* Set 't' bit, lowest bit of BO field. */ |
3446 | /* Fall thru. */ | |
65f38f15 | 3447 | |
86c76c7b | 3448 | /* Branch not taken prediction relocations. */ |
65f38f15 AM |
3449 | case R_PPC64_ADDR14_BRNTAKEN: |
3450 | case R_PPC64_REL14_BRNTAKEN: | |
86c76c7b AM |
3451 | insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21); |
3452 | /* Set 'a' bit. This is 0b00010 in BO field for branch on CR(BI) | |
3453 | insns (BO == 001at or 011at), and 0b01000 for branch on CTR | |
3454 | insns (BO == 1a00t or 1a01t). */ | |
3455 | if ((insn & (0x14 << 21)) == (0x04 << 21)) | |
3456 | insn |= 0x02 << 21; | |
3457 | else if ((insn & (0x14 << 21)) == (0x10 << 21)) | |
3458 | insn |= 0x08 << 21; | |
65f38f15 | 3459 | else |
86c76c7b AM |
3460 | break; |
3461 | ||
65f38f15 AM |
3462 | bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset); |
3463 | break; | |
5bd4f169 | 3464 | |
65f38f15 AM |
3465 | case R_PPC64_REL24: |
3466 | case R_PPC64_ADDR24: | |
5bd4f169 | 3467 | /* An ADDR24 or REL24 branching to a linkage function may be |
65f38f15 | 3468 | followed by a nop that we have to replace with a ld in |
5bd4f169 AM |
3469 | order to restore the TOC base pointer. Only calls to |
3470 | shared objects need to alter the TOC base. These are | |
3471 | recognized by their need for a PLT entry. */ | |
3472 | if (h != NULL | |
3473 | && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0 | |
3474 | /* Make sure that there really is an instruction after | |
3475 | the branch that we can decode. */ | |
65f38f15 | 3476 | && offset + 8 <= input_section->_cooked_size) |
5bd4f169 AM |
3477 | { |
3478 | bfd_byte *pnext; | |
5bd4f169 | 3479 | |
65f38f15 | 3480 | pnext = contents + offset + 4; |
5bd4f169 AM |
3481 | insn = bfd_get_32 (input_bfd, pnext); |
3482 | ||
3483 | if (insn == 0x60000000 /* nop (ori r0,r0,0) */ | |
3484 | || insn == 0x4def7b82 /* cror 15,15,15 */ | |
dc810e39 | 3485 | || insn == 0x4ffffb82) /* cror 31,31,31 */ |
5bd4f169 | 3486 | { |
dc810e39 AM |
3487 | bfd_put_32 (input_bfd, |
3488 | (bfd_vma) 0xe8410028, /* ld r2,40(r1) */ | |
3489 | pnext); | |
5bd4f169 AM |
3490 | } |
3491 | } | |
65f38f15 AM |
3492 | break; |
3493 | } | |
5bd4f169 | 3494 | |
65f38f15 AM |
3495 | /* Set `addend'. */ |
3496 | switch (r_type) | |
3497 | { | |
3498 | default: | |
3499 | (*_bfd_error_handler) | |
3500 | (_("%s: unknown relocation type %d for symbol %s"), | |
3501 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
5bd4f169 | 3502 | |
65f38f15 AM |
3503 | bfd_set_error (bfd_error_bad_value); |
3504 | ret = false; | |
3505 | continue; | |
5bd4f169 | 3506 | |
65f38f15 AM |
3507 | case R_PPC64_NONE: |
3508 | case R_PPC_GNU_VTINHERIT: | |
3509 | case R_PPC_GNU_VTENTRY: | |
3510 | continue; | |
5bd4f169 AM |
3511 | |
3512 | /* GOT16 relocations. Like an ADDR16 using the symbol's | |
3513 | address in the GOT as relocation value instead of the | |
3514 | symbols value itself. Also, create a GOT entry for the | |
3515 | symbol and put the symbol value there. */ | |
65f38f15 AM |
3516 | case R_PPC64_GOT16: |
3517 | case R_PPC64_GOT16_LO: | |
3518 | case R_PPC64_GOT16_HI: | |
3519 | case R_PPC64_GOT16_HA: | |
3520 | case R_PPC64_GOT16_DS: | |
3521 | case R_PPC64_GOT16_LO_DS: | |
5bd4f169 AM |
3522 | { |
3523 | /* Relocation is to the entry for this symbol in the global | |
3524 | offset table. */ | |
3525 | bfd_vma off; | |
65f38f15 AM |
3526 | |
3527 | if (htab->sgot == NULL) | |
3528 | abort (); | |
5bd4f169 AM |
3529 | |
3530 | if (h != NULL) | |
3531 | { | |
65f38f15 | 3532 | boolean dyn; |
5bd4f169 | 3533 | |
65f38f15 AM |
3534 | off = h->got.offset; |
3535 | dyn = htab->elf.dynamic_sections_created; | |
3536 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) | |
5bd4f169 | 3537 | || (info->shared |
65f38f15 AM |
3538 | && (info->symbolic |
3539 | || h->dynindx == -1 | |
3540 | || (h->elf_link_hash_flags | |
3541 | & ELF_LINK_FORCED_LOCAL)) | |
5bd4f169 AM |
3542 | && (h->elf_link_hash_flags |
3543 | & ELF_LINK_HASH_DEF_REGULAR))) | |
3544 | { | |
3545 | /* This is actually a static link, or it is a | |
3546 | -Bsymbolic link and the symbol is defined | |
65f38f15 AM |
3547 | locally, or the symbol was forced to be local |
3548 | because of a version file. We must initialize | |
3549 | this entry in the global offset table. Since the | |
3550 | offset must always be a multiple of 8, we use the | |
3551 | least significant bit to record whether we have | |
5bd4f169 AM |
3552 | initialized it already. |
3553 | ||
65f38f15 | 3554 | When doing a dynamic link, we create a .rel.got |
5bd4f169 AM |
3555 | relocation entry to initialize the value. This |
3556 | is done in the finish_dynamic_symbol routine. */ | |
3557 | if ((off & 1) != 0) | |
3558 | off &= ~1; | |
3559 | else | |
3560 | { | |
3561 | bfd_put_64 (output_bfd, relocation, | |
65f38f15 | 3562 | htab->sgot->contents + off); |
5bd4f169 AM |
3563 | h->got.offset |= 1; |
3564 | } | |
3565 | } | |
65f38f15 AM |
3566 | else |
3567 | unresolved_reloc = false; | |
5bd4f169 AM |
3568 | } |
3569 | else | |
3570 | { | |
65f38f15 AM |
3571 | if (local_got_offsets == NULL) |
3572 | abort (); | |
5bd4f169 AM |
3573 | |
3574 | off = local_got_offsets[r_symndx]; | |
3575 | ||
65f38f15 | 3576 | /* The offset must always be a multiple of 8. We use |
5bd4f169 AM |
3577 | the least significant bit to record whether we have |
3578 | already processed this entry. */ | |
3579 | if ((off & 1) != 0) | |
3580 | off &= ~1; | |
3581 | else | |
3582 | { | |
65f38f15 AM |
3583 | bfd_put_64 (output_bfd, relocation, |
3584 | htab->sgot->contents + off); | |
5bd4f169 AM |
3585 | |
3586 | if (info->shared) | |
3587 | { | |
5bd4f169 | 3588 | Elf_Internal_Rela outrel; |
65f38f15 | 3589 | Elf64_External_Rela *loc; |
5bd4f169 AM |
3590 | |
3591 | /* We need to generate a R_PPC64_RELATIVE reloc | |
3592 | for the dynamic linker. */ | |
65f38f15 AM |
3593 | outrel.r_offset = (htab->sgot->output_section->vma |
3594 | + htab->sgot->output_offset | |
5bd4f169 AM |
3595 | + off); |
3596 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
3597 | outrel.r_addend = relocation; | |
65f38f15 AM |
3598 | loc = (Elf64_External_Rela *) htab->srelgot->contents; |
3599 | loc += htab->srelgot->reloc_count++; | |
3600 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
5bd4f169 AM |
3601 | } |
3602 | ||
3603 | local_got_offsets[r_symndx] |= 1; | |
3604 | } | |
3605 | } | |
3606 | ||
65f38f15 AM |
3607 | if (off >= (bfd_vma) -2) |
3608 | abort (); | |
3609 | ||
3610 | relocation = htab->sgot->output_offset + off; | |
3611 | ||
5bd4f169 AM |
3612 | /* TOC base (r2) is TOC start plus 0x8000. */ |
3613 | addend -= TOC_BASE_OFF; | |
5bd4f169 | 3614 | } |
65f38f15 AM |
3615 | break; |
3616 | ||
3617 | case R_PPC64_PLT16_HA: | |
3618 | case R_PPC64_PLT16_HI: | |
3619 | case R_PPC64_PLT16_LO: | |
3620 | case R_PPC64_PLT32: | |
3621 | case R_PPC64_PLT64: | |
3622 | /* Relocation is to the entry for this symbol in the | |
3623 | procedure linkage table. */ | |
3624 | ||
3625 | /* Resolve a PLT reloc against a local symbol directly, | |
3626 | without using the procedure linkage table. */ | |
3627 | if (h == NULL) | |
3628 | break; | |
3629 | ||
3630 | if (h->plt.offset == (bfd_vma) -1 | |
3631 | || htab->splt == NULL) | |
3632 | { | |
3633 | /* We didn't make a PLT entry for this symbol. This | |
3634 | happens when statically linking PIC code, or when | |
3635 | using -Bsymbolic. */ | |
3636 | break; | |
3637 | } | |
3638 | ||
3639 | relocation = (htab->splt->output_section->vma | |
3640 | + htab->splt->output_offset | |
3641 | + h->plt.offset); | |
3642 | unresolved_reloc = false; | |
3643 | break; | |
5bd4f169 AM |
3644 | |
3645 | /* TOC16 relocs. We want the offset relative to the TOC base, | |
3646 | which is the address of the start of the TOC plus 0x8000. | |
3647 | The TOC consists of sections .got, .toc, .tocbss, and .plt, | |
3648 | in this order. */ | |
65f38f15 AM |
3649 | case R_PPC64_TOC16: |
3650 | case R_PPC64_TOC16_LO: | |
3651 | case R_PPC64_TOC16_HI: | |
3652 | case R_PPC64_TOC16_DS: | |
3653 | case R_PPC64_TOC16_LO_DS: | |
3654 | case R_PPC64_TOC16_HA: | |
5bd4f169 | 3655 | addend -= TOCstart + TOC_BASE_OFF; |
5bd4f169 AM |
3656 | break; |
3657 | ||
3658 | /* Relocate against the beginning of the section. */ | |
65f38f15 AM |
3659 | case R_PPC64_SECTOFF: |
3660 | case R_PPC64_SECTOFF_LO: | |
3661 | case R_PPC64_SECTOFF_HI: | |
3662 | case R_PPC64_SECTOFF_DS: | |
3663 | case R_PPC64_SECTOFF_LO_DS: | |
3664 | case R_PPC64_SECTOFF_HA: | |
3665 | if (sec != (asection *) 0) | |
3666 | addend -= sec->output_section->vma; | |
5bd4f169 AM |
3667 | break; |
3668 | ||
5d1634d7 AM |
3669 | case R_PPC64_REL24: |
3670 | break; | |
3671 | ||
65f38f15 AM |
3672 | /* Relocations that may need to be propagated if this is a |
3673 | dynamic object. */ | |
3674 | case R_PPC64_REL14: | |
3675 | case R_PPC64_REL14_BRNTAKEN: | |
3676 | case R_PPC64_REL14_BRTAKEN: | |
65f38f15 AM |
3677 | case R_PPC64_REL32: |
3678 | case R_PPC64_REL64: | |
3679 | case R_PPC64_ADDR14: | |
3680 | case R_PPC64_ADDR14_BRNTAKEN: | |
3681 | case R_PPC64_ADDR14_BRTAKEN: | |
3682 | case R_PPC64_ADDR16: | |
3683 | case R_PPC64_ADDR16_DS: | |
3684 | case R_PPC64_ADDR16_HA: | |
3685 | case R_PPC64_ADDR16_HI: | |
3686 | case R_PPC64_ADDR16_HIGHER: | |
3687 | case R_PPC64_ADDR16_HIGHERA: | |
3688 | case R_PPC64_ADDR16_HIGHEST: | |
3689 | case R_PPC64_ADDR16_HIGHESTA: | |
3690 | case R_PPC64_ADDR16_LO: | |
3691 | case R_PPC64_ADDR16_LO_DS: | |
3692 | case R_PPC64_ADDR24: | |
3693 | case R_PPC64_ADDR30: | |
3694 | case R_PPC64_ADDR32: | |
3695 | case R_PPC64_ADDR64: | |
3696 | case R_PPC64_UADDR16: | |
3697 | case R_PPC64_UADDR32: | |
3698 | case R_PPC64_UADDR64: | |
ec338859 AM |
3699 | /* r_symndx will be zero only for relocs against symbols |
3700 | from removed linkonce sections, or sections discarded by | |
3701 | a linker script. */ | |
5d1634d7 AM |
3702 | if (r_symndx == 0) |
3703 | break; | |
3704 | /* Fall thru. */ | |
3705 | ||
3706 | case R_PPC64_TOC: | |
3707 | if ((input_section->flags & SEC_ALLOC) == 0) | |
ec338859 AM |
3708 | break; |
3709 | ||
65f38f15 | 3710 | if ((info->shared |
65f38f15 AM |
3711 | && (IS_ABSOLUTE_RELOC (r_type) |
3712 | || (h != NULL | |
3713 | && h->dynindx != -1 | |
3714 | && (! info->symbolic | |
3715 | || (h->elf_link_hash_flags | |
3716 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
3717 | || (!info->shared | |
65f38f15 AM |
3718 | && h != NULL |
3719 | && h->dynindx != -1 | |
3720 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
3721 | && (((h->elf_link_hash_flags | |
3722 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
3723 | && (h->elf_link_hash_flags | |
3724 | & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
3725 | || h->root.type == bfd_link_hash_undefweak | |
3726 | || h->root.type == bfd_link_hash_undefined))) | |
3727 | { | |
3728 | Elf_Internal_Rela outrel; | |
3729 | boolean skip, relocate; | |
3730 | asection *sreloc; | |
3731 | Elf64_External_Rela *loc; | |
3732 | ||
5d1634d7 AM |
3733 | #if 0 |
3734 | if (strcmp (bfd_get_section_name (output_bfd, input_section), | |
3735 | ".opd") == 0) | |
3736 | break; | |
3737 | #endif | |
3738 | ||
65f38f15 AM |
3739 | /* When generating a dynamic object, these relocations |
3740 | are copied into the output file to be resolved at run | |
3741 | time. */ | |
3742 | ||
3743 | skip = false; | |
3744 | ||
c629eae0 JJ |
3745 | outrel.r_offset = |
3746 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
3747 | rel->r_offset); | |
3748 | if (outrel.r_offset == (bfd_vma) -1) | |
3749 | skip = true; | |
65f38f15 AM |
3750 | |
3751 | outrel.r_offset += (input_section->output_section->vma | |
3752 | + input_section->output_offset); | |
3753 | outrel.r_addend = addend; | |
3754 | ||
3755 | if (skip) | |
3756 | { | |
3757 | relocate = false; | |
3758 | memset (&outrel, 0, sizeof outrel); | |
3759 | } | |
3760 | else if (h != NULL | |
3761 | && h->dynindx != -1 | |
3762 | && (!IS_ABSOLUTE_RELOC (r_type) | |
3763 | || !info->shared | |
3764 | || !info->symbolic | |
3765 | || (h->elf_link_hash_flags | |
3766 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
3767 | { | |
3768 | relocate = false; | |
3769 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); | |
3770 | } | |
3771 | else | |
3772 | { | |
3773 | /* This symbol is local, or marked to become local. */ | |
3774 | outrel.r_addend += relocation; | |
3775 | relocate = true; | |
3776 | if (r_type == R_PPC64_ADDR64) | |
3777 | { | |
3778 | outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); | |
3779 | } | |
3780 | else | |
3781 | { | |
3782 | long indx = 0; | |
3783 | ||
3784 | if (r_type == R_PPC64_TOC || bfd_is_abs_section (sec)) | |
3785 | ; | |
3786 | else if (sec == NULL || sec->owner == NULL) | |
3787 | { | |
3788 | bfd_set_error (bfd_error_bad_value); | |
3789 | return false; | |
3790 | } | |
3791 | else | |
3792 | { | |
3793 | asection *osec; | |
3794 | ||
3795 | osec = sec->output_section; | |
3796 | indx = elf_section_data (osec)->dynindx; | |
3797 | ||
3798 | /* We are turning this relocation into one | |
3799 | against a section symbol, so subtract out | |
3800 | the output section's address but not the | |
3801 | offset of the input section in the output | |
3802 | section. */ | |
3803 | outrel.r_addend -= osec->vma; | |
3804 | } | |
3805 | ||
3806 | outrel.r_info = ELF64_R_INFO (indx, r_type); | |
3807 | } | |
3808 | } | |
3809 | ||
3810 | sreloc = elf_section_data (input_section)->sreloc; | |
3811 | if (sreloc == NULL) | |
3812 | abort (); | |
3813 | ||
3814 | loc = (Elf64_External_Rela *) sreloc->contents; | |
3815 | loc += sreloc->reloc_count++; | |
3816 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); | |
3817 | ||
3818 | /* If this reloc is against an external symbol, it will | |
3819 | be computed at runtime, so there's no need to do | |
3820 | anything now. */ | |
3821 | if (! relocate) | |
3822 | continue; | |
3823 | } | |
5bd4f169 AM |
3824 | break; |
3825 | ||
65f38f15 AM |
3826 | case R_PPC64_COPY: |
3827 | case R_PPC64_GLOB_DAT: | |
3828 | case R_PPC64_JMP_SLOT: | |
3829 | case R_PPC64_RELATIVE: | |
3830 | /* We shouldn't ever see these dynamic relocs in relocatable | |
3831 | files. */ | |
3832 | /* Fall thru */ | |
3833 | ||
3834 | case R_PPC64_PLTGOT16: | |
3835 | case R_PPC64_PLTGOT16_DS: | |
3836 | case R_PPC64_PLTGOT16_HA: | |
3837 | case R_PPC64_PLTGOT16_HI: | |
3838 | case R_PPC64_PLTGOT16_LO: | |
3839 | case R_PPC64_PLTGOT16_LO_DS: | |
3840 | case R_PPC64_PLTREL32: | |
3841 | case R_PPC64_PLTREL64: | |
3842 | /* These ones haven't been implemented yet. */ | |
3843 | ||
3844 | (*_bfd_error_handler) | |
3845 | (_("%s: Relocation %s is not supported for symbol %s."), | |
3846 | bfd_archive_filename (input_bfd), | |
3847 | ppc64_elf_howto_table[(int) r_type]->name, sym_name); | |
5bd4f169 AM |
3848 | |
3849 | bfd_set_error (bfd_error_invalid_operation); | |
3850 | ret = false; | |
3851 | continue; | |
65f38f15 | 3852 | } |
5bd4f169 | 3853 | |
65f38f15 AM |
3854 | /* Do any further special processing. */ |
3855 | switch (r_type) | |
3856 | { | |
3857 | default: | |
3858 | break; | |
3859 | ||
3860 | case R_PPC64_ADDR16_HA: | |
3861 | case R_PPC64_ADDR16_HIGHERA: | |
3862 | case R_PPC64_ADDR16_HIGHESTA: | |
3863 | case R_PPC64_PLT16_HA: | |
3864 | case R_PPC64_TOC16_HA: | |
3865 | case R_PPC64_SECTOFF_HA: | |
3866 | /* It's just possible that this symbol is a weak symbol | |
3867 | that's not actually defined anywhere. In that case, | |
3868 | 'sec' would be NULL, and we should leave the symbol | |
3869 | alone (it will be set to zero elsewhere in the link). */ | |
3870 | if (sec != NULL) | |
3871 | /* Add 0x10000 if sign bit in 0:15 is set. */ | |
3872 | addend += ((relocation + addend) & 0x8000) << 1; | |
3873 | break; | |
3874 | ||
3875 | case R_PPC64_ADDR16_DS: | |
3876 | case R_PPC64_ADDR16_LO_DS: | |
3877 | case R_PPC64_GOT16_DS: | |
3878 | case R_PPC64_GOT16_LO_DS: | |
3879 | case R_PPC64_PLT16_LO_DS: | |
3880 | case R_PPC64_SECTOFF_DS: | |
3881 | case R_PPC64_SECTOFF_LO_DS: | |
3882 | case R_PPC64_TOC16_DS: | |
3883 | case R_PPC64_TOC16_LO_DS: | |
3884 | case R_PPC64_PLTGOT16_DS: | |
3885 | case R_PPC64_PLTGOT16_LO_DS: | |
3886 | if (((relocation + addend) & 3) != 0) | |
3887 | { | |
3888 | (*_bfd_error_handler) | |
3889 | (_("%s: error: relocation %s not a multiple of 4"), | |
3890 | bfd_archive_filename (input_bfd), | |
3891 | ppc64_elf_howto_table[(int) r_type]->name); | |
3892 | bfd_set_error (bfd_error_bad_value); | |
3893 | ret = false; | |
3894 | continue; | |
3895 | } | |
3896 | break; | |
5bd4f169 AM |
3897 | } |
3898 | ||
65f38f15 AM |
3899 | /* FIXME: Why do we allow debugging sections to escape this error? |
3900 | More importantly, why do we not emit dynamic relocs above in | |
3901 | debugging sections (which are ! SEC_ALLOC)? If we had | |
3902 | emitted the dynamic reloc, we could remove the fudge here. */ | |
3903 | if (unresolved_reloc | |
3904 | && !(info->shared | |
3905 | && (input_section->flags & SEC_DEBUGGING) != 0 | |
3906 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) | |
3907 | (*_bfd_error_handler) | |
3908 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), | |
3909 | bfd_archive_filename (input_bfd), | |
3910 | bfd_get_section_name (input_bfd, input_section), | |
3911 | (long) rel->r_offset, | |
3912 | h->root.root.string); | |
5bd4f169 | 3913 | |
65f38f15 | 3914 | r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type], |
5bd4f169 AM |
3915 | input_bfd, |
3916 | input_section, | |
3917 | contents, | |
3918 | offset, | |
3919 | relocation, | |
3920 | addend); | |
3921 | ||
3922 | if (r == bfd_reloc_ok) | |
3923 | ; | |
3924 | else if (r == bfd_reloc_overflow) | |
3925 | { | |
3926 | const char *name; | |
3927 | ||
3928 | if (h != NULL) | |
3929 | { | |
3930 | if (h->root.type == bfd_link_hash_undefweak | |
65f38f15 | 3931 | && ppc64_elf_howto_table[(int) r_type]->pc_relative) |
5bd4f169 AM |
3932 | { |
3933 | /* Assume this is a call protected by other code that | |
3934 | detects the symbol is undefined. If this is the case, | |
3935 | we can safely ignore the overflow. If not, the | |
3936 | program is hosed anyway, and a little warning isn't | |
3937 | going to help. */ | |
3938 | ||
3939 | continue; | |
3940 | } | |
3941 | ||
3942 | name = h->root.root.string; | |
3943 | } | |
3944 | else | |
3945 | { | |
3946 | name = bfd_elf_string_from_elf_section (input_bfd, | |
3947 | symtab_hdr->sh_link, | |
3948 | sym->st_name); | |
3949 | if (name == NULL) | |
3950 | continue; | |
3951 | if (*name == '\0') | |
3952 | name = bfd_section_name (input_bfd, sec); | |
3953 | } | |
3954 | ||
65f38f15 AM |
3955 | if (! ((*info->callbacks->reloc_overflow) |
3956 | (info, name, ppc64_elf_howto_table[(int) r_type]->name, | |
3957 | (bfd_vma) 0, input_bfd, input_section, offset))) | |
5bd4f169 AM |
3958 | return false; |
3959 | } | |
3960 | else | |
3961 | ret = false; | |
3962 | } | |
3963 | ||
5bd4f169 AM |
3964 | return ret; |
3965 | } | |
3966 | ||
3967 | /* Finish up dynamic symbol handling. We set the contents of various | |
3968 | dynamic sections here. */ | |
3969 | ||
3970 | static boolean | |
3971 | ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym) | |
3972 | bfd *output_bfd; | |
3973 | struct bfd_link_info *info; | |
3974 | struct elf_link_hash_entry *h; | |
3975 | Elf_Internal_Sym *sym; | |
3976 | { | |
65f38f15 | 3977 | struct ppc_link_hash_table *htab; |
5bd4f169 AM |
3978 | bfd *dynobj; |
3979 | ||
65f38f15 AM |
3980 | htab = ppc_hash_table (info); |
3981 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
3982 | |
3983 | if (h->plt.offset != (bfd_vma) -1) | |
3984 | { | |
5bd4f169 | 3985 | struct elf_link_hash_entry *funcdesc_h; |
65f38f15 AM |
3986 | Elf_Internal_Rela rela; |
3987 | Elf64_External_Rela *loc; | |
5bd4f169 AM |
3988 | |
3989 | /* This symbol has an entry in the procedure linkage table. Set | |
3990 | it up. */ | |
3991 | ||
5d1634d7 | 3992 | if (htab->splt == NULL |
65f38f15 AM |
3993 | || htab->srelplt == NULL |
3994 | || htab->sglink == NULL | |
3995 | || h->root.root.string[0] != '.' | |
3996 | || h->root.root.string[1] == '\0') | |
3997 | abort (); | |
3998 | ||
3999 | /* Find its corresponding function descriptor. | |
5d1634d7 | 4000 | ppc64_elf_adjust_dynamic_symbol has already set it up for us. */ |
5bd4f169 | 4001 | |
65f38f15 AM |
4002 | funcdesc_h = elf_link_hash_lookup (elf_hash_table (info), |
4003 | h->root.root.string + 1, | |
4004 | false, false, false); | |
4005 | ||
4006 | if (funcdesc_h == NULL || funcdesc_h->dynindx == -1) | |
4007 | abort (); | |
4008 | ||
4009 | /* Create a JMP_SLOT reloc to inform the dynamic linker to | |
4010 | fill in the PLT entry. */ | |
5bd4f169 | 4011 | |
65f38f15 AM |
4012 | rela.r_offset = (htab->splt->output_section->vma |
4013 | + htab->splt->output_offset | |
4014 | + h->plt.offset); | |
4015 | rela.r_info = ELF64_R_INFO (funcdesc_h->dynindx, R_PPC64_JMP_SLOT); | |
4016 | rela.r_addend = 0; | |
4017 | ||
4018 | loc = (Elf64_External_Rela *) htab->srelplt->contents; | |
4019 | loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE; | |
4020 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
5bd4f169 AM |
4021 | } |
4022 | ||
4023 | if (h->got.offset != (bfd_vma) -1) | |
4024 | { | |
5bd4f169 | 4025 | Elf_Internal_Rela rela; |
65f38f15 | 4026 | Elf64_External_Rela *loc; |
5bd4f169 AM |
4027 | |
4028 | /* This symbol has an entry in the global offset table. Set it | |
4029 | up. */ | |
4030 | ||
65f38f15 AM |
4031 | if (htab->sgot == NULL || htab->srelgot == NULL) |
4032 | abort (); | |
5bd4f169 | 4033 | |
65f38f15 AM |
4034 | rela.r_offset = (htab->sgot->output_section->vma |
4035 | + htab->sgot->output_offset | |
dc810e39 | 4036 | + (h->got.offset &~ (bfd_vma) 1)); |
5bd4f169 | 4037 | |
65f38f15 AM |
4038 | /* If this is a static link, or it is a -Bsymbolic link and the |
4039 | symbol is defined locally or was forced to be local because | |
4040 | of a version file, we just want to emit a RELATIVE reloc. | |
4041 | The entry in the global offset table will already have been | |
4042 | initialized in the relocate_section function. */ | |
5bd4f169 | 4043 | if (info->shared |
65f38f15 AM |
4044 | && (info->symbolic |
4045 | || h->dynindx == -1 | |
4046 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) | |
5bd4f169 AM |
4047 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) |
4048 | { | |
65f38f15 | 4049 | BFD_ASSERT((h->got.offset & 1) != 0); |
5bd4f169 AM |
4050 | rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE); |
4051 | rela.r_addend = (h->root.u.def.value | |
4052 | + h->root.u.def.section->output_section->vma | |
4053 | + h->root.u.def.section->output_offset); | |
4054 | } | |
4055 | else | |
4056 | { | |
4057 | BFD_ASSERT ((h->got.offset & 1) == 0); | |
65f38f15 AM |
4058 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
4059 | htab->sgot->contents + h->got.offset); | |
5bd4f169 AM |
4060 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT); |
4061 | rela.r_addend = 0; | |
4062 | } | |
4063 | ||
65f38f15 AM |
4064 | loc = (Elf64_External_Rela *) htab->srelgot->contents; |
4065 | loc += htab->srelgot->reloc_count++; | |
4066 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
5bd4f169 AM |
4067 | } |
4068 | ||
4069 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
4070 | { | |
5bd4f169 | 4071 | Elf_Internal_Rela rela; |
65f38f15 | 4072 | Elf64_External_Rela *loc; |
5bd4f169 | 4073 | |
65f38f15 | 4074 | /* This symbol needs a copy reloc. Set it up. */ |
5bd4f169 | 4075 | |
65f38f15 AM |
4076 | if (h->dynindx == -1 |
4077 | || (h->root.type != bfd_link_hash_defined | |
4078 | && h->root.type != bfd_link_hash_defweak) | |
4079 | || htab->srelbss == NULL) | |
4080 | abort (); | |
5bd4f169 AM |
4081 | |
4082 | rela.r_offset = (h->root.u.def.value | |
4083 | + h->root.u.def.section->output_section->vma | |
4084 | + h->root.u.def.section->output_offset); | |
4085 | rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY); | |
4086 | rela.r_addend = 0; | |
65f38f15 AM |
4087 | loc = (Elf64_External_Rela *) htab->srelbss->contents; |
4088 | loc += htab->srelbss->reloc_count++; | |
4089 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); | |
5bd4f169 AM |
4090 | } |
4091 | ||
5bd4f169 AM |
4092 | /* Mark some specially defined symbols as absolute. */ |
4093 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0) | |
4094 | sym->st_shndx = SHN_ABS; | |
4095 | ||
4096 | return true; | |
4097 | } | |
4098 | ||
65f38f15 AM |
4099 | /* Used to decide how to sort relocs in an optimal manner for the |
4100 | dynamic linker, before writing them out. */ | |
4101 | ||
4102 | static enum elf_reloc_type_class | |
4103 | ppc64_elf_reloc_type_class (rela) | |
4104 | const Elf_Internal_Rela *rela; | |
4105 | { | |
a33d1f77 AM |
4106 | enum elf_ppc_reloc_type r_type; |
4107 | ||
4108 | r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info); | |
4109 | switch (r_type) | |
65f38f15 AM |
4110 | { |
4111 | case R_PPC64_RELATIVE: | |
4112 | return reloc_class_relative; | |
4113 | case R_PPC64_JMP_SLOT: | |
4114 | return reloc_class_plt; | |
4115 | case R_PPC64_COPY: | |
4116 | return reloc_class_copy; | |
4117 | default: | |
4118 | return reloc_class_normal; | |
4119 | } | |
4120 | } | |
4121 | ||
5bd4f169 AM |
4122 | /* Finish up the dynamic sections. */ |
4123 | ||
4124 | static boolean | |
4125 | ppc64_elf_finish_dynamic_sections (output_bfd, info) | |
4126 | bfd *output_bfd; | |
4127 | struct bfd_link_info *info; | |
4128 | { | |
65f38f15 AM |
4129 | struct ppc_link_hash_table *htab; |
4130 | bfd *dynobj; | |
5bd4f169 | 4131 | asection *sdyn; |
5bd4f169 | 4132 | |
65f38f15 AM |
4133 | htab = ppc_hash_table (info); |
4134 | dynobj = htab->elf.dynobj; | |
5bd4f169 AM |
4135 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
4136 | ||
65f38f15 | 4137 | if (htab->elf.dynamic_sections_created) |
5bd4f169 | 4138 | { |
5bd4f169 AM |
4139 | Elf64_External_Dyn *dyncon, *dynconend; |
4140 | ||
65f38f15 AM |
4141 | if (sdyn == NULL || htab->sgot == NULL) |
4142 | abort (); | |
5bd4f169 AM |
4143 | |
4144 | dyncon = (Elf64_External_Dyn *) sdyn->contents; | |
4145 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
4146 | for (; dyncon < dynconend; dyncon++) | |
4147 | { | |
4148 | Elf_Internal_Dyn dyn; | |
5bd4f169 AM |
4149 | |
4150 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); | |
4151 | ||
4152 | switch (dyn.d_tag) | |
4153 | { | |
65f38f15 AM |
4154 | default: |
4155 | continue; | |
5bd4f169 | 4156 | |
5d1634d7 AM |
4157 | case DT_PPC64_GLINK: |
4158 | dyn.d_un.d_ptr = (htab->sglink->output_section->vma | |
4159 | + htab->sglink->output_offset); | |
4160 | break; | |
4161 | ||
65f38f15 | 4162 | case DT_PLTGOT: |
5d1634d7 AM |
4163 | dyn.d_un.d_ptr = (htab->splt->output_section->vma |
4164 | + htab->splt->output_offset); | |
65f38f15 AM |
4165 | break; |
4166 | ||
4167 | case DT_JMPREL: | |
5d1634d7 AM |
4168 | dyn.d_un.d_ptr = (htab->srelplt->output_section->vma |
4169 | + htab->srelplt->output_offset); | |
65f38f15 | 4170 | break; |
5bd4f169 | 4171 | |
65f38f15 | 4172 | case DT_PLTRELSZ: |
5d1634d7 AM |
4173 | dyn.d_un.d_val = htab->srelplt->_raw_size; |
4174 | break; | |
4175 | ||
4176 | case DT_RELASZ: | |
4177 | /* Don't count procedure linkage table relocs in the | |
4178 | overall reloc count. */ | |
4179 | if (htab->srelplt != NULL) | |
4180 | dyn.d_un.d_val -= htab->srelplt->_raw_size; | |
65f38f15 | 4181 | break; |
5bd4f169 | 4182 | } |
5bd4f169 | 4183 | |
65f38f15 | 4184 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); |
5bd4f169 | 4185 | } |
5bd4f169 AM |
4186 | } |
4187 | ||
5d1634d7 AM |
4188 | if (htab->sgot != NULL && htab->sgot->_raw_size != 0) |
4189 | { | |
4190 | /* Fill in the first entry in the global offset table. | |
4191 | We use it to hold the link-time TOCbase. */ | |
4192 | bfd_put_64 (output_bfd, | |
4193 | elf_gp (output_bfd) - TOC_BASE_OFF, | |
4194 | htab->sgot->contents); | |
4195 | ||
4196 | /* Set .got entry size. */ | |
4197 | elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8; | |
4198 | } | |
4199 | ||
4200 | if (htab->splt != NULL && htab->splt->_raw_size != 0) | |
4201 | { | |
4202 | /* Set .plt entry size. */ | |
4203 | elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize | |
4204 | = PLT_ENTRY_SIZE; | |
4205 | } | |
4206 | ||
5bd4f169 AM |
4207 | return true; |
4208 | } | |
4209 | ||
4210 | #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec | |
4211 | #define TARGET_LITTLE_NAME "elf64-powerpcle" | |
4212 | #define TARGET_BIG_SYM bfd_elf64_powerpc_vec | |
4213 | #define TARGET_BIG_NAME "elf64-powerpc" | |
4214 | #define ELF_ARCH bfd_arch_powerpc | |
4215 | #define ELF_MACHINE_CODE EM_PPC64 | |
4216 | #define ELF_MAXPAGESIZE 0x10000 | |
4217 | #define elf_info_to_howto ppc64_elf_info_to_howto | |
4218 | ||
4219 | #ifdef EM_CYGNUS_POWERPC | |
4220 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
4221 | #endif | |
4222 | ||
4223 | #ifdef EM_PPC_OLD | |
4224 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
4225 | #endif | |
4226 | ||
4227 | #define elf_backend_want_got_sym 0 | |
4228 | #define elf_backend_want_plt_sym 0 | |
4229 | #define elf_backend_plt_alignment 3 | |
4230 | #define elf_backend_plt_not_loaded 1 | |
4231 | #define elf_backend_got_symbol_offset 0 | |
5d1634d7 AM |
4232 | #define elf_backend_got_header_size 8 |
4233 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE | |
5bd4f169 | 4234 | #define elf_backend_can_gc_sections 1 |
65f38f15 | 4235 | #define elf_backend_can_refcount 1 |
5bd4f169 | 4236 | |
65f38f15 AM |
4237 | #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup |
4238 | #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags | |
65f38f15 AM |
4239 | #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data |
4240 | #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create | |
65f38f15 AM |
4241 | |
4242 | #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr | |
4243 | #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections | |
4244 | #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol | |
4245 | #define elf_backend_check_relocs ppc64_elf_check_relocs | |
4246 | #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook | |
4247 | #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook | |
4248 | #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol | |
4249 | #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections | |
4250 | #define elf_backend_fake_sections ppc64_elf_fake_sections | |
4251 | #define elf_backend_relocate_section ppc64_elf_relocate_section | |
4252 | #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol | |
4253 | #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class | |
4254 | #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections | |
5bd4f169 AM |
4255 | |
4256 | #include "elf64-target.h" |