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