1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
31 #include "elf64-ppc.h"
33 #define USE_RELA /* we want RELA relocations, not REL. */
36 static void ppc_howto_init
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_ha_reloc
43 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
44 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
45 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
46 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
47 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
48 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
49 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
50 static bfd_reloc_status_type ppc64_elf_toc_reloc
51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
53 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
54 static bfd_reloc_status_type ppc64_elf_toc64_reloc
55 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static boolean ppc64_elf_object_p
60 static boolean ppc64_elf_merge_private_bfd_data
61 PARAMS ((bfd *, bfd *));
64 /* The name of the dynamic interpreter. This is put in the .interp
66 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
68 /* The size in bytes of an entry in the procedure linkage table. */
69 #define PLT_ENTRY_SIZE 24
71 /* The initial size of the plt reserved for the dynamic linker. */
72 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
74 /* TOC base pointers offset from start of TOC. */
75 #define TOC_BASE_OFF (0x8000)
77 /* .plt call stub instructions. */
78 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
79 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
80 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
81 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
82 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
83 /* ld %r11,xxx+16@l(%r12) */
84 #define BCTR 0x4e800420 /* bctr */
86 /* The normal stub is this size. */
87 #define PLT_CALL_STUB_SIZE (7*4)
89 /* But sometimes the .plt entry crosses a 64k boundary, and we need
90 to adjust the high word with this insn. */
91 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
93 /* The .glink fixup call stub is the same as the .plt call stub, but
94 the first instruction restores r2, and the std is omitted. */
95 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
97 /* Always allow this much space. */
98 #define GLINK_CALL_STUB_SIZE (8*4)
101 #define NOP 0x60000000
103 /* Some other nops. */
104 #define CROR_151515 0x4def7b82
105 #define CROR_313131 0x4ffffb82
107 /* .glink entries for the first 32k functions are two instructions. */
108 #define LI_R0_0 0x38000000 /* li %r0,0 */
109 #define B_DOT 0x48000000 /* b . */
111 /* After that, we need two instructions to load the index, followed by
113 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
114 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
116 /* Instructions to save and restore floating point regs. */
117 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
118 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
119 #define BLR 0x4e800020 /* blr */
121 /* Since .opd is an array of descriptors and each entry will end up
122 with identical R_PPC64_RELATIVE relocs, there is really no need to
123 propagate .opd relocs; The dynamic linker should be taught to
124 relocate .opd without reloc entries. */
125 #ifndef NO_OPD_RELOCS
126 #define NO_OPD_RELOCS 0
129 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
131 /* Relocation HOWTO's. */
132 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
134 static reloc_howto_type ppc64_elf_howto_raw[] = {
135 /* This reloc does nothing. */
136 HOWTO (R_PPC64_NONE, /* type */
138 0, /* size (0 = byte, 1 = short, 2 = long) */
140 false, /* pc_relative */
142 complain_overflow_dont, /* complain_on_overflow */
143 bfd_elf_generic_reloc, /* special_function */
144 "R_PPC64_NONE", /* name */
145 false, /* partial_inplace */
148 false), /* pcrel_offset */
150 /* A standard 32 bit relocation. */
151 HOWTO (R_PPC64_ADDR32, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 false, /* pc_relative */
157 complain_overflow_bitfield, /* complain_on_overflow */
158 bfd_elf_generic_reloc, /* special_function */
159 "R_PPC64_ADDR32", /* name */
160 false, /* partial_inplace */
162 0xffffffff, /* dst_mask */
163 false), /* pcrel_offset */
165 /* An absolute 26 bit branch; the lower two bits must be zero.
166 FIXME: we don't check that, we just clear them. */
167 HOWTO (R_PPC64_ADDR24, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 false, /* pc_relative */
173 complain_overflow_bitfield, /* complain_on_overflow */
174 bfd_elf_generic_reloc, /* special_function */
175 "R_PPC64_ADDR24", /* name */
176 false, /* partial_inplace */
178 0x03fffffc, /* dst_mask */
179 false), /* pcrel_offset */
181 /* A standard 16 bit relocation. */
182 HOWTO (R_PPC64_ADDR16, /* type */
184 1, /* size (0 = byte, 1 = short, 2 = long) */
186 false, /* pc_relative */
188 complain_overflow_bitfield, /* complain_on_overflow */
189 bfd_elf_generic_reloc, /* special_function */
190 "R_PPC64_ADDR16", /* name */
191 false, /* partial_inplace */
193 0xffff, /* dst_mask */
194 false), /* pcrel_offset */
196 /* A 16 bit relocation without overflow. */
197 HOWTO (R_PPC64_ADDR16_LO, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 false, /* pc_relative */
203 complain_overflow_dont,/* complain_on_overflow */
204 bfd_elf_generic_reloc, /* special_function */
205 "R_PPC64_ADDR16_LO", /* name */
206 false, /* partial_inplace */
208 0xffff, /* dst_mask */
209 false), /* pcrel_offset */
211 /* Bits 16-31 of an address. */
212 HOWTO (R_PPC64_ADDR16_HI, /* type */
214 1, /* size (0 = byte, 1 = short, 2 = long) */
216 false, /* pc_relative */
218 complain_overflow_dont, /* complain_on_overflow */
219 bfd_elf_generic_reloc, /* special_function */
220 "R_PPC64_ADDR16_HI", /* name */
221 false, /* partial_inplace */
223 0xffff, /* dst_mask */
224 false), /* pcrel_offset */
226 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
227 bits, treated as a signed number, is negative. */
228 HOWTO (R_PPC64_ADDR16_HA, /* type */
230 1, /* size (0 = byte, 1 = short, 2 = long) */
232 false, /* pc_relative */
234 complain_overflow_dont, /* complain_on_overflow */
235 ppc64_elf_ha_reloc, /* special_function */
236 "R_PPC64_ADDR16_HA", /* name */
237 false, /* partial_inplace */
239 0xffff, /* dst_mask */
240 false), /* pcrel_offset */
242 /* An absolute 16 bit branch; the lower two bits must be zero.
243 FIXME: we don't check that, we just clear them. */
244 HOWTO (R_PPC64_ADDR14, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 false, /* pc_relative */
250 complain_overflow_bitfield, /* complain_on_overflow */
251 bfd_elf_generic_reloc, /* special_function */
252 "R_PPC64_ADDR14", /* name */
253 false, /* partial_inplace */
255 0x0000fffc, /* dst_mask */
256 false), /* pcrel_offset */
258 /* An absolute 16 bit branch, for which bit 10 should be set to
259 indicate that the branch is expected to be taken. The lower two
260 bits must be zero. */
261 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
265 false, /* pc_relative */
267 complain_overflow_bitfield, /* complain_on_overflow */
268 ppc64_elf_brtaken_reloc, /* special_function */
269 "R_PPC64_ADDR14_BRTAKEN",/* name */
270 false, /* partial_inplace */
272 0x0000fffc, /* dst_mask */
273 false), /* pcrel_offset */
275 /* An absolute 16 bit branch, for which bit 10 should be set to
276 indicate that the branch is not expected to be taken. The lower
277 two bits must be zero. */
278 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 false, /* pc_relative */
284 complain_overflow_bitfield, /* complain_on_overflow */
285 ppc64_elf_brtaken_reloc, /* special_function */
286 "R_PPC64_ADDR14_BRNTAKEN",/* name */
287 false, /* partial_inplace */
289 0x0000fffc, /* dst_mask */
290 false), /* pcrel_offset */
292 /* A relative 26 bit branch; the lower two bits must be zero. */
293 HOWTO (R_PPC64_REL24, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 true, /* pc_relative */
299 complain_overflow_signed, /* complain_on_overflow */
300 bfd_elf_generic_reloc, /* special_function */
301 "R_PPC64_REL24", /* name */
302 false, /* partial_inplace */
304 0x03fffffc, /* dst_mask */
305 true), /* pcrel_offset */
307 /* A relative 16 bit branch; the lower two bits must be zero. */
308 HOWTO (R_PPC64_REL14, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 true, /* pc_relative */
314 complain_overflow_signed, /* complain_on_overflow */
315 bfd_elf_generic_reloc, /* special_function */
316 "R_PPC64_REL14", /* name */
317 false, /* partial_inplace */
319 0x0000fffc, /* dst_mask */
320 true), /* pcrel_offset */
322 /* A relative 16 bit branch. Bit 10 should be set to indicate that
323 the branch is expected to be taken. The lower two bits must be
325 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
327 2, /* size (0 = byte, 1 = short, 2 = long) */
329 true, /* pc_relative */
331 complain_overflow_signed, /* complain_on_overflow */
332 ppc64_elf_brtaken_reloc, /* special_function */
333 "R_PPC64_REL14_BRTAKEN", /* name */
334 false, /* partial_inplace */
336 0x0000fffc, /* dst_mask */
337 true), /* pcrel_offset */
339 /* A relative 16 bit branch. Bit 10 should be set to indicate that
340 the branch is not expected to be taken. The lower two bits must
342 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 true, /* pc_relative */
348 complain_overflow_signed, /* complain_on_overflow */
349 ppc64_elf_brtaken_reloc, /* special_function */
350 "R_PPC64_REL14_BRNTAKEN",/* name */
351 false, /* partial_inplace */
353 0x0000fffc, /* dst_mask */
354 true), /* pcrel_offset */
356 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
358 HOWTO (R_PPC64_GOT16, /* type */
360 1, /* size (0 = byte, 1 = short, 2 = long) */
362 false, /* pc_relative */
364 complain_overflow_signed, /* complain_on_overflow */
365 ppc64_elf_unhandled_reloc, /* special_function */
366 "R_PPC64_GOT16", /* name */
367 false, /* partial_inplace */
369 0xffff, /* dst_mask */
370 false), /* pcrel_offset */
372 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
374 HOWTO (R_PPC64_GOT16_LO, /* type */
376 1, /* size (0 = byte, 1 = short, 2 = long) */
378 false, /* pc_relative */
380 complain_overflow_dont, /* complain_on_overflow */
381 ppc64_elf_unhandled_reloc, /* special_function */
382 "R_PPC64_GOT16_LO", /* name */
383 false, /* partial_inplace */
385 0xffff, /* dst_mask */
386 false), /* pcrel_offset */
388 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
390 HOWTO (R_PPC64_GOT16_HI, /* type */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_dont,/* complain_on_overflow */
397 ppc64_elf_unhandled_reloc, /* special_function */
398 "R_PPC64_GOT16_HI", /* name */
399 false, /* partial_inplace */
401 0xffff, /* dst_mask */
402 false), /* pcrel_offset */
404 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
406 HOWTO (R_PPC64_GOT16_HA, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 false, /* pc_relative */
412 complain_overflow_dont,/* complain_on_overflow */
413 ppc64_elf_unhandled_reloc, /* special_function */
414 "R_PPC64_GOT16_HA", /* name */
415 false, /* partial_inplace */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
420 /* This is used only by the dynamic linker. The symbol should exist
421 both in the object being run and in some shared library. The
422 dynamic linker copies the data addressed by the symbol from the
423 shared library into the object, because the object being
424 run has to have the data at some particular address. */
425 HOWTO (R_PPC64_COPY, /* type */
427 0, /* this one is variable size */
429 false, /* pc_relative */
431 complain_overflow_dont, /* complain_on_overflow */
432 ppc64_elf_unhandled_reloc, /* special_function */
433 "R_PPC64_COPY", /* name */
434 false, /* partial_inplace */
437 false), /* pcrel_offset */
439 /* Like R_PPC64_ADDR64, but used when setting global offset table
441 HOWTO (R_PPC64_GLOB_DAT, /* type */
443 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
445 false, /* pc_relative */
447 complain_overflow_dont, /* complain_on_overflow */
448 ppc64_elf_unhandled_reloc, /* special_function */
449 "R_PPC64_GLOB_DAT", /* name */
450 false, /* partial_inplace */
452 ONES (64), /* dst_mask */
453 false), /* pcrel_offset */
455 /* Created by the link editor. Marks a procedure linkage table
456 entry for a symbol. */
457 HOWTO (R_PPC64_JMP_SLOT, /* type */
459 0, /* size (0 = byte, 1 = short, 2 = long) */
461 false, /* pc_relative */
463 complain_overflow_dont, /* complain_on_overflow */
464 ppc64_elf_unhandled_reloc, /* special_function */
465 "R_PPC64_JMP_SLOT", /* name */
466 false, /* partial_inplace */
469 false), /* pcrel_offset */
471 /* Used only by the dynamic linker. When the object is run, this
472 doubleword64 is set to the load address of the object, plus the
474 HOWTO (R_PPC64_RELATIVE, /* type */
476 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
478 false, /* pc_relative */
480 complain_overflow_dont, /* complain_on_overflow */
481 bfd_elf_generic_reloc, /* special_function */
482 "R_PPC64_RELATIVE", /* name */
483 false, /* partial_inplace */
485 ONES (64), /* dst_mask */
486 false), /* pcrel_offset */
488 /* Like R_PPC64_ADDR32, but may be unaligned. */
489 HOWTO (R_PPC64_UADDR32, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield, /* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_PPC64_UADDR32", /* name */
498 false, /* partial_inplace */
500 0xffffffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* Like R_PPC64_ADDR16, but may be unaligned. */
504 HOWTO (R_PPC64_UADDR16, /* type */
506 1, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_bitfield, /* complain_on_overflow */
511 bfd_elf_generic_reloc, /* special_function */
512 "R_PPC64_UADDR16", /* name */
513 false, /* partial_inplace */
515 0xffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* 32-bit PC relative. */
519 HOWTO (R_PPC64_REL32, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 true, /* pc_relative */
525 /* FIXME: Verify. Was complain_overflow_bitfield. */
526 complain_overflow_signed, /* complain_on_overflow */
527 bfd_elf_generic_reloc, /* special_function */
528 "R_PPC64_REL32", /* name */
529 false, /* partial_inplace */
531 0xffffffff, /* dst_mask */
532 true), /* pcrel_offset */
534 /* 32-bit relocation to the symbol's procedure linkage table. */
535 HOWTO (R_PPC64_PLT32, /* type */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
539 false, /* pc_relative */
541 complain_overflow_bitfield, /* complain_on_overflow */
542 ppc64_elf_unhandled_reloc, /* special_function */
543 "R_PPC64_PLT32", /* name */
544 false, /* partial_inplace */
546 0xffffffff, /* dst_mask */
547 false), /* pcrel_offset */
549 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
550 FIXME: R_PPC64_PLTREL32 not supported. */
551 HOWTO (R_PPC64_PLTREL32, /* type */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
555 true, /* pc_relative */
557 complain_overflow_signed, /* complain_on_overflow */
558 bfd_elf_generic_reloc, /* special_function */
559 "R_PPC64_PLTREL32", /* name */
560 false, /* partial_inplace */
562 0xffffffff, /* dst_mask */
563 true), /* pcrel_offset */
565 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
567 HOWTO (R_PPC64_PLT16_LO, /* type */
569 1, /* size (0 = byte, 1 = short, 2 = long) */
571 false, /* pc_relative */
573 complain_overflow_dont, /* complain_on_overflow */
574 ppc64_elf_unhandled_reloc, /* special_function */
575 "R_PPC64_PLT16_LO", /* name */
576 false, /* partial_inplace */
578 0xffff, /* dst_mask */
579 false), /* pcrel_offset */
581 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
583 HOWTO (R_PPC64_PLT16_HI, /* type */
585 1, /* size (0 = byte, 1 = short, 2 = long) */
587 false, /* pc_relative */
589 complain_overflow_dont, /* complain_on_overflow */
590 ppc64_elf_unhandled_reloc, /* special_function */
591 "R_PPC64_PLT16_HI", /* name */
592 false, /* partial_inplace */
594 0xffff, /* dst_mask */
595 false), /* pcrel_offset */
597 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
599 HOWTO (R_PPC64_PLT16_HA, /* type */
601 1, /* size (0 = byte, 1 = short, 2 = long) */
603 false, /* pc_relative */
605 complain_overflow_dont, /* complain_on_overflow */
606 ppc64_elf_unhandled_reloc, /* special_function */
607 "R_PPC64_PLT16_HA", /* name */
608 false, /* partial_inplace */
610 0xffff, /* dst_mask */
611 false), /* pcrel_offset */
613 /* 16-bit section relative relocation. */
614 HOWTO (R_PPC64_SECTOFF, /* type */
616 1, /* size (0 = byte, 1 = short, 2 = long) */
618 false, /* pc_relative */
620 complain_overflow_bitfield, /* complain_on_overflow */
621 ppc64_elf_sectoff_reloc, /* special_function */
622 "R_PPC64_SECTOFF", /* name */
623 false, /* partial_inplace */
625 0xffff, /* dst_mask */
626 false), /* pcrel_offset */
628 /* Like R_PPC64_SECTOFF, but no overflow warning. */
629 HOWTO (R_PPC64_SECTOFF_LO, /* type */
631 1, /* size (0 = byte, 1 = short, 2 = long) */
633 false, /* pc_relative */
635 complain_overflow_dont, /* complain_on_overflow */
636 ppc64_elf_sectoff_reloc, /* special_function */
637 "R_PPC64_SECTOFF_LO", /* name */
638 false, /* partial_inplace */
640 0xffff, /* dst_mask */
641 false), /* pcrel_offset */
643 /* 16-bit upper half section relative relocation. */
644 HOWTO (R_PPC64_SECTOFF_HI, /* type */
646 1, /* size (0 = byte, 1 = short, 2 = long) */
648 false, /* pc_relative */
650 complain_overflow_dont, /* complain_on_overflow */
651 ppc64_elf_sectoff_reloc, /* special_function */
652 "R_PPC64_SECTOFF_HI", /* name */
653 false, /* partial_inplace */
655 0xffff, /* dst_mask */
656 false), /* pcrel_offset */
658 /* 16-bit upper half adjusted section relative relocation. */
659 HOWTO (R_PPC64_SECTOFF_HA, /* type */
661 1, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_dont, /* complain_on_overflow */
666 ppc64_elf_sectoff_ha_reloc, /* special_function */
667 "R_PPC64_SECTOFF_HA", /* name */
668 false, /* partial_inplace */
670 0xffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* Like R_PPC64_REL24 without touching the two least significant
674 bits. Should have been named R_PPC64_REL30! */
675 HOWTO (R_PPC64_ADDR30, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 true, /* pc_relative */
681 complain_overflow_dont, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_PPC64_ADDR30", /* name */
684 false, /* partial_inplace */
686 0xfffffffc, /* dst_mask */
687 true), /* pcrel_offset */
689 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
691 /* A standard 64-bit relocation. */
692 HOWTO (R_PPC64_ADDR64, /* type */
694 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
696 false, /* pc_relative */
698 complain_overflow_dont, /* complain_on_overflow */
699 bfd_elf_generic_reloc, /* special_function */
700 "R_PPC64_ADDR64", /* name */
701 false, /* partial_inplace */
703 ONES (64), /* dst_mask */
704 false), /* pcrel_offset */
706 /* The bits 32-47 of an address. */
707 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 false, /* pc_relative */
713 complain_overflow_dont, /* complain_on_overflow */
714 bfd_elf_generic_reloc, /* special_function */
715 "R_PPC64_ADDR16_HIGHER", /* name */
716 false, /* partial_inplace */
718 0xffff, /* dst_mask */
719 false), /* pcrel_offset */
721 /* The bits 32-47 of an address, plus 1 if the contents of the low
722 16 bits, treated as a signed number, is negative. */
723 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
725 1, /* size (0 = byte, 1 = short, 2 = long) */
727 false, /* pc_relative */
729 complain_overflow_dont, /* complain_on_overflow */
730 ppc64_elf_ha_reloc, /* special_function */
731 "R_PPC64_ADDR16_HIGHERA", /* name */
732 false, /* partial_inplace */
734 0xffff, /* dst_mask */
735 false), /* pcrel_offset */
737 /* The bits 48-63 of an address. */
738 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
740 1, /* size (0 = byte, 1 = short, 2 = long) */
742 false, /* pc_relative */
744 complain_overflow_dont, /* complain_on_overflow */
745 bfd_elf_generic_reloc, /* special_function */
746 "R_PPC64_ADDR16_HIGHEST", /* name */
747 false, /* partial_inplace */
749 0xffff, /* dst_mask */
750 false), /* pcrel_offset */
752 /* The bits 48-63 of an address, plus 1 if the contents of the low
753 16 bits, treated as a signed number, is negative. */
754 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
756 1, /* size (0 = byte, 1 = short, 2 = long) */
758 false, /* pc_relative */
760 complain_overflow_dont, /* complain_on_overflow */
761 ppc64_elf_ha_reloc, /* special_function */
762 "R_PPC64_ADDR16_HIGHESTA", /* name */
763 false, /* partial_inplace */
765 0xffff, /* dst_mask */
766 false), /* pcrel_offset */
768 /* Like ADDR64, but may be unaligned. */
769 HOWTO (R_PPC64_UADDR64, /* type */
771 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
773 false, /* pc_relative */
775 complain_overflow_dont, /* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_PPC64_UADDR64", /* name */
778 false, /* partial_inplace */
780 ONES (64), /* dst_mask */
781 false), /* pcrel_offset */
783 /* 64-bit relative relocation. */
784 HOWTO (R_PPC64_REL64, /* type */
786 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
788 true, /* pc_relative */
790 complain_overflow_dont, /* complain_on_overflow */
791 bfd_elf_generic_reloc, /* special_function */
792 "R_PPC64_REL64", /* name */
793 false, /* partial_inplace */
795 ONES (64), /* dst_mask */
796 true), /* pcrel_offset */
798 /* 64-bit relocation to the symbol's procedure linkage table. */
799 HOWTO (R_PPC64_PLT64, /* type */
801 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
803 false, /* pc_relative */
805 complain_overflow_dont, /* complain_on_overflow */
806 ppc64_elf_unhandled_reloc, /* special_function */
807 "R_PPC64_PLT64", /* name */
808 false, /* partial_inplace */
810 ONES (64), /* dst_mask */
811 false), /* pcrel_offset */
813 /* 64-bit PC relative relocation to the symbol's procedure linkage
815 /* FIXME: R_PPC64_PLTREL64 not supported. */
816 HOWTO (R_PPC64_PLTREL64, /* type */
818 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
820 true, /* pc_relative */
822 complain_overflow_dont, /* complain_on_overflow */
823 ppc64_elf_unhandled_reloc, /* special_function */
824 "R_PPC64_PLTREL64", /* name */
825 false, /* partial_inplace */
827 ONES (64), /* dst_mask */
828 true), /* pcrel_offset */
830 /* 16 bit TOC-relative relocation. */
832 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
833 HOWTO (R_PPC64_TOC16, /* type */
835 1, /* size (0 = byte, 1 = short, 2 = long) */
837 false, /* pc_relative */
839 complain_overflow_signed, /* complain_on_overflow */
840 ppc64_elf_toc_reloc, /* special_function */
841 "R_PPC64_TOC16", /* name */
842 false, /* partial_inplace */
844 0xffff, /* dst_mask */
845 false), /* pcrel_offset */
847 /* 16 bit TOC-relative relocation without overflow. */
849 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
850 HOWTO (R_PPC64_TOC16_LO, /* type */
852 1, /* size (0 = byte, 1 = short, 2 = long) */
854 false, /* pc_relative */
856 complain_overflow_dont, /* complain_on_overflow */
857 ppc64_elf_toc_reloc, /* special_function */
858 "R_PPC64_TOC16_LO", /* name */
859 false, /* partial_inplace */
861 0xffff, /* dst_mask */
862 false), /* pcrel_offset */
864 /* 16 bit TOC-relative relocation, high 16 bits. */
866 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
867 HOWTO (R_PPC64_TOC16_HI, /* type */
869 1, /* size (0 = byte, 1 = short, 2 = long) */
871 false, /* pc_relative */
873 complain_overflow_dont, /* complain_on_overflow */
874 ppc64_elf_toc_reloc, /* special_function */
875 "R_PPC64_TOC16_HI", /* name */
876 false, /* partial_inplace */
878 0xffff, /* dst_mask */
879 false), /* pcrel_offset */
881 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
882 contents of the low 16 bits, treated as a signed number, is
885 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
886 HOWTO (R_PPC64_TOC16_HA, /* type */
888 1, /* size (0 = byte, 1 = short, 2 = long) */
890 false, /* pc_relative */
892 complain_overflow_dont, /* complain_on_overflow */
893 ppc64_elf_toc_ha_reloc, /* special_function */
894 "R_PPC64_TOC16_HA", /* name */
895 false, /* partial_inplace */
897 0xffff, /* dst_mask */
898 false), /* pcrel_offset */
900 /* 64-bit relocation; insert value of TOC base (.TOC.). */
902 /* R_PPC64_TOC 51 doubleword64 .TOC. */
903 HOWTO (R_PPC64_TOC, /* type */
905 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
907 false, /* pc_relative */
909 complain_overflow_bitfield, /* complain_on_overflow */
910 ppc64_elf_toc64_reloc, /* special_function */
911 "R_PPC64_TOC", /* name */
912 false, /* partial_inplace */
914 ONES (64), /* dst_mask */
915 false), /* pcrel_offset */
917 /* Like R_PPC64_GOT16, but also informs the link editor that the
918 value to relocate may (!) refer to a PLT entry which the link
919 editor (a) may replace with the symbol value. If the link editor
920 is unable to fully resolve the symbol, it may (b) create a PLT
921 entry and store the address to the new PLT entry in the GOT.
922 This permits lazy resolution of function symbols at run time.
923 The link editor may also skip all of this and just (c) emit a
924 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
925 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
926 HOWTO (R_PPC64_PLTGOT16, /* type */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
930 false, /* pc_relative */
932 complain_overflow_signed, /* complain_on_overflow */
933 ppc64_elf_unhandled_reloc, /* special_function */
934 "R_PPC64_PLTGOT16", /* name */
935 false, /* partial_inplace */
937 0xffff, /* dst_mask */
938 false), /* pcrel_offset */
940 /* Like R_PPC64_PLTGOT16, but without overflow. */
941 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
942 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
944 1, /* size (0 = byte, 1 = short, 2 = long) */
946 false, /* pc_relative */
948 complain_overflow_dont, /* complain_on_overflow */
949 ppc64_elf_unhandled_reloc, /* special_function */
950 "R_PPC64_PLTGOT16_LO", /* name */
951 false, /* partial_inplace */
953 0xffff, /* dst_mask */
954 false), /* pcrel_offset */
956 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
957 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
958 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
960 1, /* size (0 = byte, 1 = short, 2 = long) */
962 false, /* pc_relative */
964 complain_overflow_dont, /* complain_on_overflow */
965 ppc64_elf_unhandled_reloc, /* special_function */
966 "R_PPC64_PLTGOT16_HI", /* name */
967 false, /* partial_inplace */
969 0xffff, /* dst_mask */
970 false), /* pcrel_offset */
972 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
973 1 if the contents of the low 16 bits, treated as a signed number,
975 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
976 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
978 1, /* size (0 = byte, 1 = short, 2 = long) */
980 false, /* pc_relative */
982 complain_overflow_dont,/* complain_on_overflow */
983 ppc64_elf_unhandled_reloc, /* special_function */
984 "R_PPC64_PLTGOT16_HA", /* name */
985 false, /* partial_inplace */
987 0xffff, /* dst_mask */
988 false), /* pcrel_offset */
990 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
991 HOWTO (R_PPC64_ADDR16_DS, /* type */
993 1, /* size (0 = byte, 1 = short, 2 = long) */
995 false, /* pc_relative */
997 complain_overflow_bitfield, /* complain_on_overflow */
998 bfd_elf_generic_reloc, /* special_function */
999 "R_PPC64_ADDR16_DS", /* name */
1000 false, /* partial_inplace */
1002 0xfffc, /* dst_mask */
1003 false), /* pcrel_offset */
1005 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1006 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1008 1, /* size (0 = byte, 1 = short, 2 = long) */
1010 false, /* pc_relative */
1012 complain_overflow_dont,/* complain_on_overflow */
1013 bfd_elf_generic_reloc, /* special_function */
1014 "R_PPC64_ADDR16_LO_DS",/* name */
1015 false, /* partial_inplace */
1017 0xfffc, /* dst_mask */
1018 false), /* pcrel_offset */
1020 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1021 HOWTO (R_PPC64_GOT16_DS, /* type */
1023 1, /* size (0 = byte, 1 = short, 2 = long) */
1025 false, /* pc_relative */
1027 complain_overflow_signed, /* complain_on_overflow */
1028 ppc64_elf_unhandled_reloc, /* special_function */
1029 "R_PPC64_GOT16_DS", /* name */
1030 false, /* partial_inplace */
1032 0xfffc, /* dst_mask */
1033 false), /* pcrel_offset */
1035 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1036 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1038 1, /* size (0 = byte, 1 = short, 2 = long) */
1040 false, /* pc_relative */
1042 complain_overflow_dont, /* complain_on_overflow */
1043 ppc64_elf_unhandled_reloc, /* special_function */
1044 "R_PPC64_GOT16_LO_DS", /* name */
1045 false, /* partial_inplace */
1047 0xfffc, /* dst_mask */
1048 false), /* pcrel_offset */
1050 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1051 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1053 1, /* size (0 = byte, 1 = short, 2 = long) */
1055 false, /* pc_relative */
1057 complain_overflow_dont, /* complain_on_overflow */
1058 ppc64_elf_unhandled_reloc, /* special_function */
1059 "R_PPC64_PLT16_LO_DS", /* name */
1060 false, /* partial_inplace */
1062 0xfffc, /* dst_mask */
1063 false), /* pcrel_offset */
1065 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1066 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1068 1, /* size (0 = byte, 1 = short, 2 = long) */
1070 false, /* pc_relative */
1072 complain_overflow_bitfield, /* complain_on_overflow */
1073 ppc64_elf_sectoff_reloc, /* special_function */
1074 "R_PPC64_SECTOFF_DS", /* name */
1075 false, /* partial_inplace */
1077 0xfffc, /* dst_mask */
1078 false), /* pcrel_offset */
1080 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1081 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1085 false, /* pc_relative */
1087 complain_overflow_dont, /* complain_on_overflow */
1088 ppc64_elf_sectoff_reloc, /* special_function */
1089 "R_PPC64_SECTOFF_LO_DS",/* name */
1090 false, /* partial_inplace */
1092 0xfffc, /* dst_mask */
1093 false), /* pcrel_offset */
1095 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1096 HOWTO (R_PPC64_TOC16_DS, /* type */
1098 1, /* size (0 = byte, 1 = short, 2 = long) */
1100 false, /* pc_relative */
1102 complain_overflow_signed, /* complain_on_overflow */
1103 ppc64_elf_toc_reloc, /* special_function */
1104 "R_PPC64_TOC16_DS", /* name */
1105 false, /* partial_inplace */
1107 0xfffc, /* dst_mask */
1108 false), /* pcrel_offset */
1110 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1111 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1113 1, /* size (0 = byte, 1 = short, 2 = long) */
1115 false, /* pc_relative */
1117 complain_overflow_dont, /* complain_on_overflow */
1118 ppc64_elf_toc_reloc, /* special_function */
1119 "R_PPC64_TOC16_LO_DS", /* name */
1120 false, /* partial_inplace */
1122 0xfffc, /* dst_mask */
1123 false), /* pcrel_offset */
1125 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1126 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1127 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1129 1, /* size (0 = byte, 1 = short, 2 = long) */
1131 false, /* pc_relative */
1133 complain_overflow_signed, /* complain_on_overflow */
1134 ppc64_elf_unhandled_reloc, /* special_function */
1135 "R_PPC64_PLTGOT16_DS", /* name */
1136 false, /* partial_inplace */
1138 0xfffc, /* dst_mask */
1139 false), /* pcrel_offset */
1141 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1142 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1143 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1145 1, /* size (0 = byte, 1 = short, 2 = long) */
1147 false, /* pc_relative */
1149 complain_overflow_dont, /* complain_on_overflow */
1150 ppc64_elf_unhandled_reloc, /* special_function */
1151 "R_PPC64_PLTGOT16_LO_DS",/* name */
1152 false, /* partial_inplace */
1154 0xfffc, /* dst_mask */
1155 false), /* pcrel_offset */
1157 /* GNU extension to record C++ vtable hierarchy. */
1158 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1160 0, /* size (0 = byte, 1 = short, 2 = long) */
1162 false, /* pc_relative */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 NULL, /* special_function */
1166 "R_PPC64_GNU_VTINHERIT", /* name */
1167 false, /* partial_inplace */
1170 false), /* pcrel_offset */
1172 /* GNU extension to record C++ vtable member usage. */
1173 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1175 0, /* size (0 = byte, 1 = short, 2 = long) */
1177 false, /* pc_relative */
1179 complain_overflow_dont, /* complain_on_overflow */
1180 NULL, /* special_function */
1181 "R_PPC64_GNU_VTENTRY", /* name */
1182 false, /* partial_inplace */
1185 false), /* pcrel_offset */
1189 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1195 unsigned int i, type;
1198 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1201 type = ppc64_elf_howto_raw[i].type;
1202 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1203 / sizeof (ppc64_elf_howto_table[0])));
1204 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1208 static reloc_howto_type *
1209 ppc64_elf_reloc_type_lookup (abfd, code)
1210 bfd *abfd ATTRIBUTE_UNUSED;
1211 bfd_reloc_code_real_type code;
1213 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1215 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1216 /* Initialize howto table if needed. */
1222 return (reloc_howto_type *) NULL;
1224 case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1226 case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1228 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1230 case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1232 case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1234 case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1236 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1238 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1240 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1242 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1244 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1246 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1248 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1250 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1252 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1254 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1256 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1258 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1260 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1262 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1264 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1266 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1268 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1270 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1272 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1274 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1276 case BFD_RELOC_16_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1278 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1280 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1282 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1284 case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64;
1286 case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1288 case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1290 case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1292 case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1294 case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1296 case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1298 case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1300 case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1302 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1304 case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1306 case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1308 case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1310 case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1312 case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1314 case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1316 case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1318 case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1320 case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1322 case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1324 case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1326 case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1328 case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1330 case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1332 case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1334 case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1336 case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1338 case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1340 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1342 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1344 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1348 return ppc64_elf_howto_table[(int) ppc_reloc];
1351 /* Set the howto pointer for a PowerPC ELF reloc. */
1354 ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1355 bfd *abfd ATTRIBUTE_UNUSED;
1357 Elf64_Internal_Rela *dst;
1361 /* Initialize howto table if needed. */
1362 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1365 type = ELF64_R_TYPE (dst->r_info);
1366 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1367 / sizeof (ppc64_elf_howto_table[0])));
1368 cache_ptr->howto = ppc64_elf_howto_table[type];
1371 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1373 static bfd_reloc_status_type
1374 ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data,
1375 input_section, output_bfd, error_message)
1377 arelent *reloc_entry;
1380 asection *input_section;
1382 char **error_message;
1384 /* If this is a relocatable link (output_bfd test tells us), just
1385 call the generic function. Any adjustment will be done at final
1387 if (output_bfd != NULL)
1388 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1389 input_section, output_bfd, error_message);
1391 /* Adjust the addend for sign extension of the low 16 bits.
1392 We won't actually be using the low 16 bits, so trashing them
1394 reloc_entry->addend += 0x8000;
1395 return bfd_reloc_continue;
1398 static bfd_reloc_status_type
1399 ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data,
1400 input_section, output_bfd, error_message)
1402 arelent *reloc_entry;
1405 asection *input_section;
1407 char **error_message;
1410 enum elf_ppc_reloc_type r_type;
1411 bfd_size_type octets;
1412 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1413 boolean is_power4 = false;
1415 /* If this is a relocatable link (output_bfd test tells us), just
1416 call the generic function. Any adjustment will be done at final
1418 if (output_bfd != NULL)
1419 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1420 input_section, output_bfd, error_message);
1422 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1423 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
1424 insn &= ~(0x01 << 21);
1425 r_type = (enum elf_ppc_reloc_type) reloc_entry->howto->type;
1426 if (r_type == R_PPC64_ADDR14_BRTAKEN
1427 || r_type == R_PPC64_REL14_BRTAKEN)
1428 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1432 /* Set 'a' bit. This is 0b00010 in BO field for branch
1433 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1434 for branch on CTR insns (BO == 1a00t or 1a01t). */
1435 if ((insn & (0x14 << 21)) == (0x04 << 21))
1437 else if ((insn & (0x14 << 21)) == (0x10 << 21))
1440 return bfd_reloc_continue;
1447 if (!bfd_is_com_section (symbol->section))
1448 target = symbol->value;
1449 target += symbol->section->output_section->vma;
1450 target += symbol->section->output_offset;
1451 target += reloc_entry->addend;
1453 from = (reloc_entry->address
1454 + input_section->output_offset
1455 + input_section->output_section->vma);
1457 /* Invert 'y' bit if not the default. */
1458 if ((bfd_signed_vma) (target - from) < 0)
1461 bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets);
1462 return bfd_reloc_continue;
1465 static bfd_reloc_status_type
1466 ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data,
1467 input_section, output_bfd, error_message)
1469 arelent *reloc_entry;
1472 asection *input_section;
1474 char **error_message;
1476 /* If this is a relocatable link (output_bfd test tells us), just
1477 call the generic function. Any adjustment will be done at final
1479 if (output_bfd != NULL)
1480 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1481 input_section, output_bfd, error_message);
1483 /* Subtract the symbol section base address. */
1484 reloc_entry->addend -= symbol->section->output_section->vma;
1485 return bfd_reloc_continue;
1488 static bfd_reloc_status_type
1489 ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data,
1490 input_section, output_bfd, error_message)
1492 arelent *reloc_entry;
1495 asection *input_section;
1497 char **error_message;
1499 /* If this is a relocatable link (output_bfd test tells us), just
1500 call the generic function. Any adjustment will be done at final
1502 if (output_bfd != NULL)
1503 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1504 input_section, output_bfd, error_message);
1506 /* Subtract the symbol section base address. */
1507 reloc_entry->addend -= symbol->section->output_section->vma;
1509 /* Adjust the addend for sign extension of the low 16 bits. */
1510 reloc_entry->addend += 0x8000;
1511 return bfd_reloc_continue;
1514 static bfd_reloc_status_type
1515 ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data,
1516 input_section, output_bfd, error_message)
1518 arelent *reloc_entry;
1521 asection *input_section;
1523 char **error_message;
1527 /* If this is a relocatable link (output_bfd test tells us), just
1528 call the generic function. Any adjustment will be done at final
1530 if (output_bfd != NULL)
1531 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1532 input_section, output_bfd, error_message);
1534 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1536 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1538 /* Subtract the TOC base address. */
1539 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1540 return bfd_reloc_continue;
1543 static bfd_reloc_status_type
1544 ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data,
1545 input_section, output_bfd, error_message)
1547 arelent *reloc_entry;
1550 asection *input_section;
1552 char **error_message;
1556 /* If this is a relocatable link (output_bfd test tells us), just
1557 call the generic function. Any adjustment will be done at final
1559 if (output_bfd != NULL)
1560 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1561 input_section, output_bfd, error_message);
1563 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1565 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1567 /* Subtract the TOC base address. */
1568 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1570 /* Adjust the addend for sign extension of the low 16 bits. */
1571 reloc_entry->addend += 0x8000;
1572 return bfd_reloc_continue;
1575 static bfd_reloc_status_type
1576 ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data,
1577 input_section, output_bfd, error_message)
1579 arelent *reloc_entry;
1582 asection *input_section;
1584 char **error_message;
1587 bfd_size_type octets;
1589 /* If this is a relocatable link (output_bfd test tells us), just
1590 call the generic function. Any adjustment will be done at final
1592 if (output_bfd != NULL)
1593 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1594 input_section, output_bfd, error_message);
1596 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1598 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1600 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1601 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
1602 return bfd_reloc_ok;
1605 static bfd_reloc_status_type
1606 ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
1607 input_section, output_bfd, error_message)
1609 arelent *reloc_entry;
1612 asection *input_section;
1614 char **error_message;
1616 /* If this is a relocatable link (output_bfd test tells us), just
1617 call the generic function. Any adjustment will be done at final
1619 if (output_bfd != NULL)
1620 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1621 input_section, output_bfd, error_message);
1623 if (error_message != NULL)
1625 static char buf[60];
1626 sprintf (buf, "generic linker can't handle %s",
1627 reloc_entry->howto->name);
1628 *error_message = buf;
1630 return bfd_reloc_dangerous;
1633 /* Fix bad default arch selected for a 64 bit input bfd when the
1634 default is 32 bit. */
1637 ppc64_elf_object_p (abfd)
1640 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
1642 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
1644 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
1646 /* Relies on arch after 32 bit default being 64 bit default. */
1647 abfd->arch_info = abfd->arch_info->next;
1648 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
1654 /* Merge backend specific data from an object file to the output
1655 object file when linking. */
1658 ppc64_elf_merge_private_bfd_data (ibfd, obfd)
1662 /* Check if we have the same endianess. */
1663 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1664 && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
1665 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1669 if (bfd_big_endian (ibfd))
1670 msg = _("%s: compiled for a big endian system and target is little endian");
1672 msg = _("%s: compiled for a little endian system and target is big endian");
1674 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
1676 bfd_set_error (bfd_error_wrong_format);
1683 /* The following functions are specific to the ELF linker, while
1684 functions above are used generally. Those named ppc64_elf_* are
1685 called by the main ELF linker code. They appear in this file more
1686 or less in the order in which they are called. eg.
1687 ppc64_elf_check_relocs is called early in the link process,
1688 ppc64_elf_finish_dynamic_sections is one of the last functions
1691 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1692 functions have both a function code symbol and a function descriptor
1693 symbol. A call to foo in a relocatable object file looks like:
1700 The function definition in another object file might be:
1704 . .quad .TOC.@tocbase
1710 When the linker resolves the call during a static link, the branch
1711 unsurprisingly just goes to .foo and the .opd information is unused.
1712 If the function definition is in a shared library, things are a little
1713 different: The call goes via a plt call stub, the opd information gets
1714 copied to the plt, and the linker patches the nop.
1722 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1723 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1724 . std 2,40(1) # this is the general idea
1732 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1734 The "reloc ()" notation is supposed to indicate that the linker emits
1735 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1738 What are the difficulties here? Well, firstly, the relocations
1739 examined by the linker in check_relocs are against the function code
1740 sym .foo, while the dynamic relocation in the plt is emitted against
1741 the function descriptor symbol, foo. Somewhere along the line, we need
1742 to carefully copy dynamic link information from one symbol to the other.
1743 Secondly, the generic part of the elf linker will make .foo a dynamic
1744 symbol as is normal for most other backends. We need foo dynamic
1745 instead, at least for an application final link. However, when
1746 creating a shared library containing foo, we need to have both symbols
1747 dynamic so that references to .foo are satisfied during the early
1748 stages of linking. Otherwise the linker might decide to pull in a
1749 definition from some other object, eg. a static library. */
1751 /* The linker needs to keep track of the number of relocs that it
1752 decides to copy as dynamic relocs in check_relocs for each symbol.
1753 This is so that it can later discard them if they are found to be
1754 unnecessary. We store the information in a field extending the
1755 regular ELF linker hash table. */
1757 struct ppc_dyn_relocs
1759 struct ppc_dyn_relocs *next;
1761 /* The input section of the reloc. */
1764 /* Total number of relocs copied for the input section. */
1765 bfd_size_type count;
1767 /* Number of pc-relative relocs copied for the input section. */
1768 bfd_size_type pc_count;
1771 /* Of those relocs that might be copied as dynamic relocs, this macro
1772 selects between relative and absolute types. */
1774 #define IS_ABSOLUTE_RELOC(RTYPE) \
1775 ((RTYPE) != R_PPC64_REL32 \
1776 && (RTYPE) != R_PPC64_REL64 \
1777 && (RTYPE) != R_PPC64_ADDR30)
1779 /* Section name for stubs is the associated section name plus this
1781 #define STUB_SUFFIX ".stub"
1784 ppc_stub_long_branch:
1785 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1786 destination, but a 24 bit branch in a stub section will reach.
1789 ppc_stub_plt_branch:
1790 Similar to the above, but a 24 bit branch in the stub section won't
1791 reach its destination.
1792 . addis %r12,%r2,xxx@toc@ha
1793 . ld %r11,xxx@toc@l(%r12)
1798 Used to call a function in a shared library.
1799 . addis %r12,%r2,xxx@toc@ha
1801 . ld %r11,xxx+0@toc@l(%r12)
1802 . ld %r2,xxx+8@toc@l(%r12)
1804 . ld %r11,xxx+16@toc@l(%r12)
1808 enum ppc_stub_type {
1810 ppc_stub_long_branch,
1811 ppc_stub_plt_branch,
1815 struct ppc_stub_hash_entry {
1817 /* Base hash table entry structure. */
1818 struct bfd_hash_entry root;
1820 /* The stub section. */
1823 /* Offset within stub_sec of the beginning of this stub. */
1824 bfd_vma stub_offset;
1826 /* Given the symbol's value and its section we can determine its final
1827 value when building the stubs (so the stub knows where to jump. */
1828 bfd_vma target_value;
1829 asection *target_section;
1831 enum ppc_stub_type stub_type;
1833 /* The symbol table entry, if any, that this was derived from. */
1834 struct ppc_link_hash_entry *h;
1836 /* Where this stub is being called from, or, in the case of combined
1837 stub sections, the first input section in the group. */
1841 struct ppc_branch_hash_entry {
1843 /* Base hash table entry structure. */
1844 struct bfd_hash_entry root;
1846 /* Offset within .branch_lt. */
1847 unsigned int offset;
1849 /* Generation marker. */
1853 struct ppc_link_hash_entry
1855 struct elf_link_hash_entry elf;
1857 /* A pointer to the most recently used stub hash entry against this
1859 struct ppc_stub_hash_entry *stub_cache;
1861 /* Track dynamic relocs copied for this symbol. */
1862 struct ppc_dyn_relocs *dyn_relocs;
1864 /* Link between function code and descriptor symbols. */
1865 struct elf_link_hash_entry *oh;
1867 /* Flag function code and descriptor symbols. */
1868 unsigned int is_func:1;
1869 unsigned int is_func_descriptor:1;
1870 unsigned int is_entry:1;
1873 /* ppc64 ELF linker hash table. */
1875 struct ppc_link_hash_table
1877 struct elf_link_hash_table elf;
1879 /* The stub hash table. */
1880 struct bfd_hash_table stub_hash_table;
1882 /* Another hash table for plt_branch stubs. */
1883 struct bfd_hash_table branch_hash_table;
1885 /* Linker stub bfd. */
1888 /* Linker call-backs. */
1889 asection * (*add_stub_section) PARAMS ((const char *, asection *));
1890 void (*layout_sections_again) PARAMS ((void));
1892 /* Array to keep track of which stub sections have been created, and
1893 information on stub grouping. */
1895 /* This is the section to which stubs in the group will be attached. */
1897 /* The stub section. */
1901 /* Assorted information used by ppc64_elf_size_stubs. */
1903 asection **input_list;
1905 /* Short-cuts to get to dynamic linker sections. */
1918 unsigned int stub_error;
1920 /* Flag set when small branches are detected. Used to
1921 select suitable defaults for the stub group size. */
1922 unsigned int has_14bit_branch;
1924 /* Set if we detect a reference undefined weak symbol. */
1925 unsigned int have_undefweak;
1927 /* Incremented every time we size stubs. */
1928 unsigned int stub_iteration;
1930 /* Small local sym to section mapping cache. */
1931 struct sym_sec_cache sym_sec;
1934 static struct bfd_hash_entry *stub_hash_newfunc
1935 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1936 static struct bfd_hash_entry *branch_hash_newfunc
1937 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1938 static struct bfd_hash_entry *link_hash_newfunc
1939 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1940 static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
1942 static void ppc64_elf_link_hash_table_free
1943 PARAMS ((struct bfd_link_hash_table *));
1944 static char *ppc_stub_name
1945 PARAMS ((const asection *, const asection *,
1946 const struct ppc_link_hash_entry *, const Elf_Internal_Rela *));
1947 static struct ppc_stub_hash_entry *ppc_get_stub_entry
1948 PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *,
1949 const Elf_Internal_Rela *, struct ppc_link_hash_table *));
1950 static struct ppc_stub_hash_entry *ppc_add_stub
1951 PARAMS ((const char *, asection *, struct ppc_link_hash_table *));
1952 static boolean create_linkage_sections
1953 PARAMS ((bfd *, struct bfd_link_info *));
1954 static boolean create_got_section
1955 PARAMS ((bfd *, struct bfd_link_info *));
1956 static boolean ppc64_elf_create_dynamic_sections
1957 PARAMS ((bfd *, struct bfd_link_info *));
1958 static void ppc64_elf_copy_indirect_symbol
1959 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
1960 struct elf_link_hash_entry *));
1961 static boolean ppc64_elf_check_relocs
1962 PARAMS ((bfd *, struct bfd_link_info *, asection *,
1963 const Elf_Internal_Rela *));
1964 static asection * ppc64_elf_gc_mark_hook
1965 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
1966 struct elf_link_hash_entry *, Elf_Internal_Sym *));
1967 static boolean ppc64_elf_gc_sweep_hook
1968 PARAMS ((bfd *, struct bfd_link_info *, asection *,
1969 const Elf_Internal_Rela *));
1970 static boolean func_desc_adjust
1971 PARAMS ((struct elf_link_hash_entry *, PTR));
1972 static boolean ppc64_elf_func_desc_adjust
1973 PARAMS ((bfd *, struct bfd_link_info *));
1974 static boolean ppc64_elf_adjust_dynamic_symbol
1975 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
1976 static void ppc64_elf_hide_symbol
1977 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
1978 static boolean edit_opd
1979 PARAMS ((bfd *, struct bfd_link_info *));
1980 static boolean allocate_dynrelocs
1981 PARAMS ((struct elf_link_hash_entry *, PTR));
1982 static boolean readonly_dynrelocs
1983 PARAMS ((struct elf_link_hash_entry *, PTR));
1984 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
1985 PARAMS ((const Elf_Internal_Rela *));
1986 static boolean ppc64_elf_size_dynamic_sections
1987 PARAMS ((bfd *, struct bfd_link_info *));
1988 static INLINE enum ppc_stub_type ppc_type_of_stub
1989 PARAMS ((asection *, const Elf_Internal_Rela *,
1990 struct ppc_link_hash_entry **, bfd_vma));
1991 static bfd_byte *build_plt_stub
1992 PARAMS ((bfd *, bfd_byte *, int, int));
1993 static boolean ppc_build_one_stub
1994 PARAMS ((struct bfd_hash_entry *, PTR));
1995 static boolean ppc_size_one_stub
1996 PARAMS ((struct bfd_hash_entry *, PTR));
1997 static void group_sections
1998 PARAMS ((struct ppc_link_hash_table *, bfd_size_type, boolean));
1999 static boolean ppc64_elf_relocate_section
2000 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
2001 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
2003 static boolean ppc64_elf_finish_dynamic_symbol
2004 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
2005 Elf_Internal_Sym *));
2006 static boolean ppc64_elf_finish_dynamic_sections
2007 PARAMS ((bfd *, struct bfd_link_info *));
2009 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2011 #define ppc_hash_table(p) \
2012 ((struct ppc_link_hash_table *) ((p)->hash))
2014 #define ppc_stub_hash_lookup(table, string, create, copy) \
2015 ((struct ppc_stub_hash_entry *) \
2016 bfd_hash_lookup ((table), (string), (create), (copy)))
2018 #define ppc_branch_hash_lookup(table, string, create, copy) \
2019 ((struct ppc_branch_hash_entry *) \
2020 bfd_hash_lookup ((table), (string), (create), (copy)))
2022 /* Create an entry in the stub hash table. */
2024 static struct bfd_hash_entry *
2025 stub_hash_newfunc (entry, table, string)
2026 struct bfd_hash_entry *entry;
2027 struct bfd_hash_table *table;
2030 /* Allocate the structure if it has not already been allocated by a
2034 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2039 /* Call the allocation method of the superclass. */
2040 entry = bfd_hash_newfunc (entry, table, string);
2043 struct ppc_stub_hash_entry *eh;
2045 /* Initialize the local fields. */
2046 eh = (struct ppc_stub_hash_entry *) entry;
2047 eh->stub_sec = NULL;
2048 eh->stub_offset = 0;
2049 eh->target_value = 0;
2050 eh->target_section = NULL;
2051 eh->stub_type = ppc_stub_none;
2059 /* Create an entry in the branch hash table. */
2061 static struct bfd_hash_entry *
2062 branch_hash_newfunc (entry, table, string)
2063 struct bfd_hash_entry *entry;
2064 struct bfd_hash_table *table;
2067 /* Allocate the structure if it has not already been allocated by a
2071 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2076 /* Call the allocation method of the superclass. */
2077 entry = bfd_hash_newfunc (entry, table, string);
2080 struct ppc_branch_hash_entry *eh;
2082 /* Initialize the local fields. */
2083 eh = (struct ppc_branch_hash_entry *) entry;
2091 /* Create an entry in a ppc64 ELF linker hash table. */
2093 static struct bfd_hash_entry *
2094 link_hash_newfunc (entry, table, string)
2095 struct bfd_hash_entry *entry;
2096 struct bfd_hash_table *table;
2099 /* Allocate the structure if it has not already been allocated by a
2103 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2108 /* Call the allocation method of the superclass. */
2109 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2112 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2114 eh->stub_cache = NULL;
2115 eh->dyn_relocs = NULL;
2118 eh->is_func_descriptor = 0;
2125 /* Create a ppc64 ELF linker hash table. */
2127 static struct bfd_link_hash_table *
2128 ppc64_elf_link_hash_table_create (abfd)
2131 struct ppc_link_hash_table *htab;
2132 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
2134 htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
2138 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
2144 /* Init the stub hash table too. */
2145 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
2148 /* And the branch hash table. */
2149 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
2152 htab->stub_bfd = NULL;
2153 htab->add_stub_section = NULL;
2154 htab->layout_sections_again = NULL;
2155 htab->stub_group = NULL;
2157 htab->srelgot = NULL;
2159 htab->srelplt = NULL;
2160 htab->sdynbss = NULL;
2161 htab->srelbss = NULL;
2162 htab->sglink = NULL;
2165 htab->srelbrlt = NULL;
2166 htab->stub_error = 0;
2167 htab->has_14bit_branch = 0;
2168 htab->have_undefweak = 0;
2169 htab->stub_iteration = 0;
2170 htab->sym_sec.abfd = NULL;
2172 return &htab->elf.root;
2175 /* Free the derived linker hash table. */
2178 ppc64_elf_link_hash_table_free (hash)
2179 struct bfd_link_hash_table *hash;
2181 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
2183 bfd_hash_table_free (&ret->stub_hash_table);
2184 bfd_hash_table_free (&ret->branch_hash_table);
2185 _bfd_generic_link_hash_table_free (hash);
2188 /* Build a name for an entry in the stub hash table. */
2191 ppc_stub_name (input_section, sym_sec, h, rel)
2192 const asection *input_section;
2193 const asection *sym_sec;
2194 const struct ppc_link_hash_entry *h;
2195 const Elf_Internal_Rela *rel;
2200 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2201 offsets from a sym as a branch target? In fact, we could
2202 probably assume the addend is always zero. */
2203 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
2207 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
2208 stub_name = bfd_malloc (len);
2209 if (stub_name != NULL)
2211 sprintf (stub_name, "%08x_%s+%x",
2212 input_section->id & 0xffffffff,
2213 h->elf.root.root.string,
2214 (int) rel->r_addend & 0xffffffff);
2219 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2220 stub_name = bfd_malloc (len);
2221 if (stub_name != NULL)
2223 sprintf (stub_name, "%08x_%x:%x+%x",
2224 input_section->id & 0xffffffff,
2225 sym_sec->id & 0xffffffff,
2226 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
2227 (int) rel->r_addend & 0xffffffff);
2233 /* Look up an entry in the stub hash. Stub entries are cached because
2234 creating the stub name takes a bit of time. */
2236 static struct ppc_stub_hash_entry *
2237 ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab)
2238 const asection *input_section;
2239 const asection *sym_sec;
2240 struct elf_link_hash_entry *hash;
2241 const Elf_Internal_Rela *rel;
2242 struct ppc_link_hash_table *htab;
2244 struct ppc_stub_hash_entry *stub_entry;
2245 struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
2246 const asection *id_sec;
2248 /* If this input section is part of a group of sections sharing one
2249 stub section, then use the id of the first section in the group.
2250 Stub names need to include a section id, as there may well be
2251 more than one stub used to reach say, printf, and we need to
2252 distinguish between them. */
2253 id_sec = htab->stub_group[input_section->id].link_sec;
2255 if (h != NULL && h->stub_cache != NULL
2256 && h->stub_cache->h == h
2257 && h->stub_cache->id_sec == id_sec)
2259 stub_entry = h->stub_cache;
2265 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
2266 if (stub_name == NULL)
2269 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
2270 stub_name, false, false);
2272 h->stub_cache = stub_entry;
2280 /* Add a new stub entry to the stub hash. Not all fields of the new
2281 stub entry are initialised. */
2283 static struct ppc_stub_hash_entry *
2284 ppc_add_stub (stub_name, section, htab)
2285 const char *stub_name;
2287 struct ppc_link_hash_table *htab;
2291 struct ppc_stub_hash_entry *stub_entry;
2293 link_sec = htab->stub_group[section->id].link_sec;
2294 stub_sec = htab->stub_group[section->id].stub_sec;
2295 if (stub_sec == NULL)
2297 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2298 if (stub_sec == NULL)
2304 namelen = strlen (link_sec->name);
2305 len = namelen + sizeof (STUB_SUFFIX);
2306 s_name = bfd_alloc (htab->stub_bfd, len);
2310 memcpy (s_name, link_sec->name, namelen);
2311 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2312 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2313 if (stub_sec == NULL)
2315 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2317 htab->stub_group[section->id].stub_sec = stub_sec;
2320 /* Enter this entry into the linker stub hash table. */
2321 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2323 if (stub_entry == NULL)
2325 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2326 bfd_archive_filename (section->owner),
2331 stub_entry->stub_sec = stub_sec;
2332 stub_entry->stub_offset = 0;
2333 stub_entry->id_sec = link_sec;
2337 /* Create sections for linker generated code. */
2340 create_linkage_sections (dynobj, info)
2342 struct bfd_link_info *info;
2344 struct ppc_link_hash_table *htab;
2347 htab = ppc_hash_table (info);
2349 /* Create .sfpr for code to save and restore fp regs. */
2350 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
2351 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2352 htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
2353 if (htab->sfpr == NULL
2354 || ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
2355 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
2358 /* Create .glink for lazy dynamic linking support. */
2359 htab->sglink = bfd_make_section_anyway (dynobj, ".glink");
2360 if (htab->sglink == NULL
2361 || ! bfd_set_section_flags (dynobj, htab->sglink, flags)
2362 || ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
2365 /* Create .branch_lt for plt_branch stubs. */
2366 flags = (SEC_ALLOC | SEC_LOAD
2367 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2368 htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt");
2369 if (htab->sbrlt == NULL
2370 || ! bfd_set_section_flags (dynobj, htab->sbrlt, flags)
2371 || ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3))
2376 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2377 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2378 htab->srelbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt");
2380 || ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags)
2381 || ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3))
2387 /* Create .got and .rela.got sections in DYNOBJ, and set up
2388 shortcuts to them in our hash table. */
2391 create_got_section (dynobj, info)
2393 struct bfd_link_info *info;
2395 struct ppc_link_hash_table *htab;
2397 if (! _bfd_elf_create_got_section (dynobj, info))
2400 htab = ppc_hash_table (info);
2401 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2405 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
2407 || ! bfd_set_section_flags (dynobj, htab->srelgot,
2408 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2409 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2411 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
2416 /* Create the dynamic sections, and set up shortcuts. */
2419 ppc64_elf_create_dynamic_sections (dynobj, info)
2421 struct bfd_link_info *info;
2423 struct ppc_link_hash_table *htab;
2425 htab = ppc_hash_table (info);
2426 if (!htab->sgot && !create_got_section (dynobj, info))
2429 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2432 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2433 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
2434 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2436 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
2438 if (!htab->splt || !htab->srelplt || !htab->sdynbss
2439 || (!info->shared && !htab->srelbss))
2445 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2448 ppc64_elf_copy_indirect_symbol (bed, dir, ind)
2449 struct elf_backend_data *bed;
2450 struct elf_link_hash_entry *dir, *ind;
2452 struct ppc_link_hash_entry *edir, *eind;
2454 edir = (struct ppc_link_hash_entry *) dir;
2455 eind = (struct ppc_link_hash_entry *) ind;
2457 if (eind->dyn_relocs != NULL)
2459 if (edir->dyn_relocs != NULL)
2461 struct ppc_dyn_relocs **pp;
2462 struct ppc_dyn_relocs *p;
2464 if (ind->root.type == bfd_link_hash_indirect)
2467 /* Add reloc counts against the weak sym to the strong sym
2468 list. Merge any entries against the same section. */
2469 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2471 struct ppc_dyn_relocs *q;
2473 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2474 if (q->sec == p->sec)
2476 q->pc_count += p->pc_count;
2477 q->count += p->count;
2484 *pp = edir->dyn_relocs;
2487 edir->dyn_relocs = eind->dyn_relocs;
2488 eind->dyn_relocs = NULL;
2491 edir->is_func |= eind->is_func;
2492 edir->is_func_descriptor |= eind->is_func_descriptor;
2493 edir->is_entry |= eind->is_entry;
2495 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
2498 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2499 symbols undefined on the command-line. */
2502 ppc64_elf_mark_entry_syms (info)
2503 struct bfd_link_info *info;
2505 struct ppc_link_hash_table *htab;
2506 struct bfd_sym_chain *sym;
2508 htab = ppc_hash_table (info);
2509 for (sym = info->gc_sym_list; sym; sym = sym->next)
2511 struct elf_link_hash_entry *h;
2513 h = elf_link_hash_lookup (&htab->elf, sym->name, false, false, false);
2515 ((struct ppc_link_hash_entry *) h)->is_entry = 1;
2520 /* Look through the relocs for a section during the first phase, and
2521 calculate needed space in the global offset table, procedure
2522 linkage table, and dynamic reloc sections. */
2525 ppc64_elf_check_relocs (abfd, info, sec, relocs)
2527 struct bfd_link_info *info;
2529 const Elf_Internal_Rela *relocs;
2531 struct ppc_link_hash_table *htab;
2532 Elf_Internal_Shdr *symtab_hdr;
2533 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2534 const Elf_Internal_Rela *rel;
2535 const Elf_Internal_Rela *rel_end;
2537 asection **opd_sym_map;
2539 if (info->relocateable)
2542 htab = ppc_hash_table (info);
2543 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2545 sym_hashes = elf_sym_hashes (abfd);
2546 sym_hashes_end = (sym_hashes
2547 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym)
2548 - symtab_hdr->sh_info);
2552 if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0)
2554 /* Garbage collection needs some extra help with .opd sections.
2555 We don't want to necessarily keep everything referenced by
2556 relocs in .opd, as that would keep all functions. Instead,
2557 if we reference an .opd symbol (a function descriptor), we
2558 want to keep the function code symbol's section. This is
2559 easy for global symbols, but for local syms we need to keep
2560 information about the associated function section. Later, if
2561 edit_opd deletes entries, we'll use this array to adjust
2562 local syms in .opd. */
2564 asection *func_section;
2569 amt = sec->_raw_size * sizeof (union opd_info) / 24;
2570 opd_sym_map = (asection **) bfd_zalloc (abfd, amt);
2571 if (opd_sym_map == NULL)
2573 elf_section_data (sec)->tdata = opd_sym_map;
2576 if (htab->elf.dynobj == NULL)
2577 htab->elf.dynobj = abfd;
2578 if (htab->sfpr == NULL
2579 && !create_linkage_sections (htab->elf.dynobj, info))
2582 rel_end = relocs + sec->reloc_count;
2583 for (rel = relocs; rel < rel_end; rel++)
2585 unsigned long r_symndx;
2586 struct elf_link_hash_entry *h;
2587 enum elf_ppc_reloc_type r_type;
2589 r_symndx = ELF64_R_SYM (rel->r_info);
2590 if (r_symndx < symtab_hdr->sh_info)
2593 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2595 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2598 /* GOT16 relocations */
2600 case R_PPC64_GOT16_DS:
2601 case R_PPC64_GOT16_HA:
2602 case R_PPC64_GOT16_HI:
2603 case R_PPC64_GOT16_LO:
2604 case R_PPC64_GOT16_LO_DS:
2606 /* This symbol requires a global offset table entry. */
2607 if (htab->sgot == NULL
2608 && !create_got_section (htab->elf.dynobj, info))
2613 h->got.refcount += 1;
2617 bfd_signed_vma *local_got_refcounts;
2619 /* This is a global offset table entry for a local symbol. */
2620 local_got_refcounts = elf_local_got_refcounts (abfd);
2621 if (local_got_refcounts == NULL)
2625 size = symtab_hdr->sh_info;
2626 size *= sizeof (bfd_signed_vma);
2627 local_got_refcounts = ((bfd_signed_vma *)
2628 bfd_zalloc (abfd, size));
2629 if (local_got_refcounts == NULL)
2631 elf_local_got_refcounts (abfd) = local_got_refcounts;
2633 local_got_refcounts[r_symndx] += 1;
2637 case R_PPC64_PLT16_HA:
2638 case R_PPC64_PLT16_HI:
2639 case R_PPC64_PLT16_LO:
2642 /* This symbol requires a procedure linkage table entry. We
2643 actually build the entry in adjust_dynamic_symbol,
2644 because this might be a case of linking PIC code without
2645 linking in any dynamic objects, in which case we don't
2646 need to generate a procedure linkage table after all. */
2649 /* It does not make sense to have a procedure linkage
2650 table entry for a local symbol. */
2651 bfd_set_error (bfd_error_bad_value);
2655 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2656 h->plt.refcount += 1;
2657 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2660 /* The following relocations don't need to propagate the
2661 relocation if linking a shared object since they are
2662 section relative. */
2663 case R_PPC64_SECTOFF:
2664 case R_PPC64_SECTOFF_LO:
2665 case R_PPC64_SECTOFF_HI:
2666 case R_PPC64_SECTOFF_HA:
2667 case R_PPC64_SECTOFF_DS:
2668 case R_PPC64_SECTOFF_LO_DS:
2670 case R_PPC64_TOC16_LO:
2671 case R_PPC64_TOC16_HI:
2672 case R_PPC64_TOC16_HA:
2673 case R_PPC64_TOC16_DS:
2674 case R_PPC64_TOC16_LO_DS:
2677 /* This relocation describes the C++ object vtable hierarchy.
2678 Reconstruct it for later use during GC. */
2679 case R_PPC64_GNU_VTINHERIT:
2680 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2684 /* This relocation describes which C++ vtable entries are actually
2685 used. Record for later use during GC. */
2686 case R_PPC64_GNU_VTENTRY:
2687 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2692 case R_PPC64_REL14_BRTAKEN:
2693 case R_PPC64_REL14_BRNTAKEN:
2694 htab->has_14bit_branch = 1;
2699 && h->root.root.string[0] == '.'
2700 && h->root.root.string[1] != 0)
2702 /* We may need a .plt entry if the function this reloc
2703 refers to is in a shared lib. */
2704 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2705 h->plt.refcount += 1;
2706 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2710 case R_PPC64_ADDR64:
2711 if (opd_sym_map != NULL
2713 && h->root.root.string[0] == '.'
2714 && h->root.root.string[1] != 0)
2716 struct elf_link_hash_entry *fdh;
2718 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
2719 false, false, false);
2722 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
2723 ((struct ppc_link_hash_entry *) fdh)->oh = h;
2724 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2725 ((struct ppc_link_hash_entry *) h)->oh = fdh;
2728 if (opd_sym_map != NULL
2730 && rel + 1 < rel_end
2731 && ((enum elf_ppc_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info)
2736 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
2741 opd_sym_map[rel->r_offset / 24] = s;
2747 case R_PPC64_ADDR14:
2748 case R_PPC64_ADDR14_BRNTAKEN:
2749 case R_PPC64_ADDR14_BRTAKEN:
2750 case R_PPC64_ADDR16:
2751 case R_PPC64_ADDR16_DS:
2752 case R_PPC64_ADDR16_HA:
2753 case R_PPC64_ADDR16_HI:
2754 case R_PPC64_ADDR16_HIGHER:
2755 case R_PPC64_ADDR16_HIGHERA:
2756 case R_PPC64_ADDR16_HIGHEST:
2757 case R_PPC64_ADDR16_HIGHESTA:
2758 case R_PPC64_ADDR16_LO:
2759 case R_PPC64_ADDR16_LO_DS:
2760 case R_PPC64_ADDR24:
2761 case R_PPC64_ADDR30:
2762 case R_PPC64_ADDR32:
2763 case R_PPC64_UADDR16:
2764 case R_PPC64_UADDR32:
2765 case R_PPC64_UADDR64:
2767 /* Don't propagate .opd relocs. */
2768 if (NO_OPD_RELOCS && opd_sym_map != NULL)
2771 /* If we are creating a shared library, and this is a reloc
2772 against a global symbol, or a non PC relative reloc
2773 against a local symbol, then we need to copy the reloc
2774 into the shared library. However, if we are linking with
2775 -Bsymbolic, we do not need to copy a reloc against a
2776 global symbol which is defined in an object we are
2777 including in the link (i.e., DEF_REGULAR is set). At
2778 this point we have not seen all the input files, so it is
2779 possible that DEF_REGULAR is not set now but will be set
2780 later (it is never cleared). In case of a weak definition,
2781 DEF_REGULAR may be cleared later by a strong definition in
2782 a shared library. We account for that possibility below by
2783 storing information in the relocs_copied field of the hash
2784 table entry. A similar situation occurs when creating
2785 shared libraries and symbol visibility changes render the
2788 If on the other hand, we are creating an executable, we
2789 may need to keep relocations for symbols satisfied by a
2790 dynamic library if we manage to avoid copy relocs for the
2793 && (sec->flags & SEC_ALLOC) != 0
2794 && (IS_ABSOLUTE_RELOC (r_type)
2796 && (! info->symbolic
2797 || h->root.type == bfd_link_hash_defweak
2798 || (h->elf_link_hash_flags
2799 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2801 && (sec->flags & SEC_ALLOC) != 0
2803 && (h->root.type == bfd_link_hash_defweak
2804 || (h->elf_link_hash_flags
2805 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
2807 struct ppc_dyn_relocs *p;
2808 struct ppc_dyn_relocs **head;
2810 /* We must copy these reloc types into the output file.
2811 Create a reloc section in dynobj and make room for
2818 name = (bfd_elf_string_from_elf_section
2820 elf_elfheader (abfd)->e_shstrndx,
2821 elf_section_data (sec)->rel_hdr.sh_name));
2825 if (strncmp (name, ".rela", 5) != 0
2826 || strcmp (bfd_get_section_name (abfd, sec),
2829 (*_bfd_error_handler)
2830 (_("%s: bad relocation section name `%s\'"),
2831 bfd_archive_filename (abfd), name);
2832 bfd_set_error (bfd_error_bad_value);
2835 dynobj = htab->elf.dynobj;
2836 sreloc = bfd_get_section_by_name (dynobj, name);
2841 sreloc = bfd_make_section (dynobj, name);
2842 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2843 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2844 if ((sec->flags & SEC_ALLOC) != 0)
2845 flags |= SEC_ALLOC | SEC_LOAD;
2847 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2848 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
2851 elf_section_data (sec)->sreloc = sreloc;
2854 /* If this is a global symbol, we count the number of
2855 relocations we need for this symbol. */
2858 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
2862 /* Track dynamic relocs needed for local syms too.
2863 We really need local syms available to do this
2867 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
2872 head = ((struct ppc_dyn_relocs **)
2873 &elf_section_data (s)->local_dynrel);
2877 if (p == NULL || p->sec != sec)
2879 p = ((struct ppc_dyn_relocs *)
2880 bfd_alloc (htab->elf.dynobj,
2881 (bfd_size_type) sizeof *p));
2892 if (!IS_ABSOLUTE_RELOC (r_type))
2905 /* Return the section that should be marked against GC for a given
2909 ppc64_elf_gc_mark_hook (sec, info, rel, h, sym)
2911 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2912 Elf_Internal_Rela *rel;
2913 struct elf_link_hash_entry *h;
2914 Elf_Internal_Sym *sym;
2916 asection *rsec = NULL;
2920 enum elf_ppc_reloc_type r_type;
2921 struct ppc_link_hash_entry *fdh;
2923 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2926 case R_PPC64_GNU_VTINHERIT:
2927 case R_PPC64_GNU_VTENTRY:
2931 switch (h->root.type)
2933 case bfd_link_hash_defined:
2934 case bfd_link_hash_defweak:
2935 fdh = (struct ppc_link_hash_entry *) h;
2937 /* Function descriptor syms cause the associated
2938 function code sym section to be marked. */
2939 if (fdh->is_func_descriptor)
2940 rsec = fdh->oh->root.u.def.section;
2942 /* Function entry syms return NULL if they are in .opd
2943 and are not ._start (or others undefined on the ld
2944 command line). Thus we avoid marking all function
2945 sections, as all functions are referenced in .opd. */
2946 else if ((fdh->oh != NULL
2947 && ((struct ppc_link_hash_entry *) fdh->oh)->is_entry)
2948 || elf_section_data (sec)->tdata == NULL)
2949 rsec = h->root.u.def.section;
2952 case bfd_link_hash_common:
2953 rsec = h->root.u.c.p->section;
2963 asection **opd_sym_section;
2965 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2966 opd_sym_section = (asection **) elf_section_data (rsec)->tdata;
2967 if (opd_sym_section != NULL)
2968 rsec = opd_sym_section[sym->st_value / 24];
2969 else if (elf_section_data (sec)->tdata != NULL)
2976 /* Update the .got, .plt. and dynamic reloc reference counts for the
2977 section being removed. */
2980 ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
2982 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2984 const Elf_Internal_Rela *relocs;
2986 Elf_Internal_Shdr *symtab_hdr;
2987 struct elf_link_hash_entry **sym_hashes;
2988 bfd_signed_vma *local_got_refcounts;
2989 const Elf_Internal_Rela *rel, *relend;
2991 elf_section_data (sec)->local_dynrel = NULL;
2993 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2994 sym_hashes = elf_sym_hashes (abfd);
2995 local_got_refcounts = elf_local_got_refcounts (abfd);
2997 relend = relocs + sec->reloc_count;
2998 for (rel = relocs; rel < relend; rel++)
3000 unsigned long r_symndx;
3001 enum elf_ppc_reloc_type r_type;
3002 struct elf_link_hash_entry *h;
3004 r_symndx = ELF64_R_SYM (rel->r_info);
3005 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3009 case R_PPC64_GOT16_DS:
3010 case R_PPC64_GOT16_HA:
3011 case R_PPC64_GOT16_HI:
3012 case R_PPC64_GOT16_LO:
3013 case R_PPC64_GOT16_LO_DS:
3014 if (r_symndx >= symtab_hdr->sh_info)
3016 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3017 if (h->got.refcount > 0)
3022 if (local_got_refcounts[r_symndx] > 0)
3023 local_got_refcounts[r_symndx]--;
3027 case R_PPC64_PLT16_HA:
3028 case R_PPC64_PLT16_HI:
3029 case R_PPC64_PLT16_LO:
3032 if (r_symndx >= symtab_hdr->sh_info)
3034 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3035 if (h->plt.refcount > 0)
3041 case R_PPC64_REL14_BRNTAKEN:
3042 case R_PPC64_REL14_BRTAKEN:
3044 if (r_symndx >= symtab_hdr->sh_info)
3046 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3047 if (h->plt.refcount > 0)
3054 if (r_symndx >= symtab_hdr->sh_info)
3056 struct ppc_link_hash_entry *eh;
3057 struct ppc_dyn_relocs **pp;
3058 struct ppc_dyn_relocs *p;
3060 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3061 eh = (struct ppc_link_hash_entry *) h;
3063 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3075 case R_PPC64_ADDR14:
3076 case R_PPC64_ADDR14_BRNTAKEN:
3077 case R_PPC64_ADDR14_BRTAKEN:
3078 case R_PPC64_ADDR16:
3079 case R_PPC64_ADDR16_DS:
3080 case R_PPC64_ADDR16_HA:
3081 case R_PPC64_ADDR16_HI:
3082 case R_PPC64_ADDR16_HIGHER:
3083 case R_PPC64_ADDR16_HIGHERA:
3084 case R_PPC64_ADDR16_HIGHEST:
3085 case R_PPC64_ADDR16_HIGHESTA:
3086 case R_PPC64_ADDR16_LO:
3087 case R_PPC64_ADDR16_LO_DS:
3088 case R_PPC64_ADDR24:
3089 case R_PPC64_ADDR30:
3090 case R_PPC64_ADDR32:
3091 case R_PPC64_ADDR64:
3092 case R_PPC64_UADDR16:
3093 case R_PPC64_UADDR32:
3094 case R_PPC64_UADDR64:
3096 if (r_symndx >= symtab_hdr->sh_info)
3098 struct ppc_link_hash_entry *eh;
3099 struct ppc_dyn_relocs **pp;
3100 struct ppc_dyn_relocs *p;
3102 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3103 eh = (struct ppc_link_hash_entry *) h;
3105 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3123 /* Called via elf_link_hash_traverse to transfer dynamic linking
3124 information on function code symbol entries to their corresponding
3125 function descriptor symbol entries. */
3127 func_desc_adjust (h, inf)
3128 struct elf_link_hash_entry *h;
3131 struct bfd_link_info *info;
3132 struct ppc_link_hash_table *htab;
3134 if (h->root.type == bfd_link_hash_indirect)
3137 if (h->root.type == bfd_link_hash_warning)
3138 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3140 info = (struct bfd_link_info *) inf;
3141 htab = ppc_hash_table (info);
3143 /* If this is a function code symbol, transfer dynamic linking
3144 information to the function descriptor symbol. */
3145 if (!((struct ppc_link_hash_entry *) h)->is_func)
3148 if (h->root.type == bfd_link_hash_undefweak
3149 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
3150 htab->have_undefweak = true;
3152 if (h->plt.refcount > 0
3153 && h->root.root.string[0] == '.'
3154 && h->root.root.string[1] != '\0')
3156 struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh;
3157 boolean force_local;
3159 /* Find the corresponding function descriptor symbol. Create it
3160 as undefined if necessary. */
3163 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
3164 false, false, true);
3168 && (h->root.type == bfd_link_hash_undefined
3169 || h->root.type == bfd_link_hash_undefweak))
3173 struct bfd_link_hash_entry *bh;
3175 abfd = h->root.u.undef.abfd;
3176 newsym = bfd_make_empty_symbol (abfd);
3177 newsym->name = h->root.root.string + 1;
3178 newsym->section = bfd_und_section_ptr;
3180 newsym->flags = BSF_OBJECT;
3181 if (h->root.type == bfd_link_hash_undefweak)
3182 newsym->flags |= BSF_WEAK;
3185 if ( !(_bfd_generic_link_add_one_symbol
3186 (info, abfd, newsym->name, newsym->flags,
3187 newsym->section, newsym->value, NULL, false, false, &bh)))
3191 fdh = (struct elf_link_hash_entry *) bh;
3192 fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
3196 && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
3198 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3199 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
3201 if (fdh->dynindx == -1)
3202 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
3204 fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
3205 & (ELF_LINK_HASH_REF_REGULAR
3206 | ELF_LINK_HASH_REF_DYNAMIC
3207 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3208 | ELF_LINK_NON_GOT_REF));
3209 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3211 fdh->plt.refcount = h->plt.refcount;
3212 fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3214 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
3215 ((struct ppc_link_hash_entry *) fdh)->oh = h;
3216 ((struct ppc_link_hash_entry *) h)->oh = fdh;
3219 /* Now that the info is on the function descriptor, clear the
3220 function code sym info. Any function code syms for which we
3221 don't have a definition in a regular file, we force local.
3222 This prevents a shared library from exporting syms that have
3223 been imported from another library. Function code syms that
3224 are really in the library we must leave global to prevent the
3225 linker dragging in a definition from a static library. */
3226 force_local = (info->shared
3227 && ((h->elf_link_hash_flags
3228 & ELF_LINK_HASH_DEF_REGULAR) == 0
3230 || (fdh->elf_link_hash_flags
3231 & ELF_LINK_HASH_DEF_REGULAR) == 0
3232 || (fdh->elf_link_hash_flags
3233 & ELF_LINK_FORCED_LOCAL) != 0));
3234 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3240 #define MIN_SAVE_FPR 14
3241 #define MAX_SAVE_FPR 31
3243 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3244 this hook to a) provide some gcc support functions, and b) transfer
3245 dynamic linking information gathered so far on function code symbol
3246 entries, to their corresponding function descriptor symbol entries. */
3248 ppc64_elf_func_desc_adjust (obfd, info)
3249 bfd *obfd ATTRIBUTE_UNUSED;
3250 struct bfd_link_info *info;
3252 struct ppc_link_hash_table *htab;
3253 unsigned int lowest_savef = MAX_SAVE_FPR + 2;
3254 unsigned int lowest_restf = MAX_SAVE_FPR + 2;
3256 struct elf_link_hash_entry *h;
3260 htab = ppc_hash_table (info);
3262 if (htab->sfpr == NULL)
3263 /* We don't have any relocs. */
3266 /* First provide any missing ._savef* and ._restf* functions. */
3267 memcpy (sym, "._savef14", 10);
3268 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3270 sym[7] = i / 10 + '0';
3271 sym[8] = i % 10 + '0';
3272 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3274 && h->root.type == bfd_link_hash_undefined)
3276 if (lowest_savef > i)
3278 h->root.type = bfd_link_hash_defined;
3279 h->root.u.def.section = htab->sfpr;
3280 h->root.u.def.value = (i - lowest_savef) * 4;
3282 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3283 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3287 memcpy (sym, "._restf14", 10);
3288 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3290 sym[7] = i / 10 + '0';
3291 sym[8] = i % 10 + '0';
3292 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3294 && h->root.type == bfd_link_hash_undefined)
3296 if (lowest_restf > i)
3298 h->root.type = bfd_link_hash_defined;
3299 h->root.u.def.section = htab->sfpr;
3300 h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3301 + (i - lowest_restf) * 4);
3303 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3304 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3308 elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
3310 htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3311 + (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
3313 if (htab->sfpr->_raw_size == 0)
3315 if (!htab->have_undefweak)
3317 _bfd_strip_section_from_output (info, htab->sfpr);
3321 htab->sfpr->_raw_size = 4;
3324 p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size);
3327 htab->sfpr->contents = p;
3329 for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
3331 unsigned int fpr = i << 21;
3332 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3333 bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
3336 if (lowest_savef <= MAX_SAVE_FPR)
3338 bfd_put_32 (htab->elf.dynobj, BLR, p);
3342 for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
3344 unsigned int fpr = i << 21;
3345 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3346 bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
3349 if (lowest_restf <= MAX_SAVE_FPR
3350 || htab->sfpr->_raw_size == 4)
3352 bfd_put_32 (htab->elf.dynobj, BLR, p);
3358 /* Adjust a symbol defined by a dynamic object and referenced by a
3359 regular object. The current definition is in some section of the
3360 dynamic object, but we're not including those sections. We have to
3361 change the definition to something the rest of the link can
3365 ppc64_elf_adjust_dynamic_symbol (info, h)
3366 struct bfd_link_info *info;
3367 struct elf_link_hash_entry *h;
3369 struct ppc_link_hash_table *htab;
3370 struct ppc_link_hash_entry * eh;
3371 struct ppc_dyn_relocs *p;
3373 unsigned int power_of_two;
3375 htab = ppc_hash_table (info);
3377 /* Deal with function syms. */
3378 if (h->type == STT_FUNC
3379 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3381 /* Clear procedure linkage table information for any symbol that
3382 won't need a .plt entry. */
3383 if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
3384 || h->plt.refcount <= 0
3385 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3387 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3388 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
3390 h->plt.offset = (bfd_vma) -1;
3391 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3396 h->plt.offset = (bfd_vma) -1;
3398 /* If this is a weak symbol, and there is a real definition, the
3399 processor independent code will have arranged for us to see the
3400 real definition first, and we can just use the same value. */
3401 if (h->weakdef != NULL)
3403 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3404 || h->weakdef->root.type == bfd_link_hash_defweak);
3405 h->root.u.def.section = h->weakdef->root.u.def.section;
3406 h->root.u.def.value = h->weakdef->root.u.def.value;
3410 /* This is a reference to a symbol defined by a dynamic object which
3411 is not a function. */
3413 /* If we are creating a shared library, we must presume that the
3414 only references to the symbol are via the global offset table.
3415 For such cases we need not do anything here; the relocations will
3416 be handled correctly by relocate_section. */
3420 /* If there are no references to this symbol that do not use the
3421 GOT, we don't need to generate a copy reloc. */
3422 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3425 eh = (struct ppc_link_hash_entry *) h;
3426 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3428 s = p->sec->output_section;
3429 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3433 /* If we didn't find any dynamic relocs in read-only sections, then
3434 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3437 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3441 /* We must allocate the symbol in our .dynbss section, which will
3442 become part of the .bss section of the executable. There will be
3443 an entry for this symbol in the .dynsym section. The dynamic
3444 object will contain position independent code, so all references
3445 from the dynamic object to this symbol will go through the global
3446 offset table. The dynamic linker will use the .dynsym entry to
3447 determine the address it must put in the global offset table, so
3448 both the dynamic object and the regular object will refer to the
3449 same memory location for the variable. */
3451 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3452 copy the initial value out of the dynamic object and into the
3453 runtime process image. We need to remember the offset into the
3454 .rela.bss section we are going to use. */
3455 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3457 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
3458 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3461 /* We need to figure out the alignment required for this symbol. I
3462 have no idea how ELF linkers handle this. */
3463 power_of_two = bfd_log2 (h->size);
3464 if (power_of_two > 4)
3467 /* Apply the required alignment. */
3469 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3470 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3472 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3476 /* Define the symbol as being at this point in the section. */
3477 h->root.u.def.section = s;
3478 h->root.u.def.value = s->_raw_size;
3480 /* Increment the section size to make room for the symbol. */
3481 s->_raw_size += h->size;
3486 /* If given a function descriptor symbol, hide both the function code
3487 sym and the descriptor. */
3489 ppc64_elf_hide_symbol (info, h, force_local)
3490 struct bfd_link_info *info;
3491 struct elf_link_hash_entry *h;
3492 boolean force_local;
3494 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3496 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
3498 struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh;
3503 struct ppc_link_hash_table *htab;
3506 /* We aren't supposed to use alloca in BFD because on
3507 systems which do not have alloca the version in libiberty
3508 calls xmalloc, which might cause the program to crash
3509 when it runs out of memory. This function doesn't have a
3510 return status, so there's no way to gracefully return an
3511 error. So cheat. We know that string[-1] can be safely
3512 dereferenced; It's either a string in an ELF string
3513 table, or allocated in an objalloc structure. */
3515 p = h->root.root.string - 1;
3518 htab = ppc_hash_table (info);
3519 fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3522 /* Unfortunately, if it so happens that the string we were
3523 looking for was allocated immediately before this string,
3524 then we overwrote the string terminator. That's the only
3525 reason the lookup should fail. */
3528 q = h->root.root.string + strlen (h->root.root.string);
3529 while (q >= h->root.root.string && *q == *p)
3531 if (q < h->root.root.string && *p == '.')
3532 fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3536 ((struct ppc_link_hash_entry *) h)->oh = fh;
3537 ((struct ppc_link_hash_entry *) fh)->oh = h;
3541 _bfd_elf_link_hash_hide_symbol (info, fh, force_local);
3546 edit_opd (obfd, info)
3548 struct bfd_link_info *info;
3551 unsigned int bfd_indx;
3553 for (bfd_indx = 0, ibfd = info->input_bfds;
3555 ibfd = ibfd->link_next, bfd_indx++)
3558 Elf_Internal_Rela *relstart, *rel, *relend;
3559 Elf_Internal_Shdr *symtab_hdr;
3560 Elf_Internal_Sym *local_syms;
3561 struct elf_link_hash_entry **sym_hashes;
3566 sec = bfd_get_section_by_name (ibfd, ".opd");
3570 adjust = (long *) elf_section_data (sec)->tdata;
3571 BFD_ASSERT (adjust != NULL);
3572 memset (adjust, 0, (size_t) sec->_raw_size * sizeof (long) / 24);
3574 if (sec->output_section == bfd_abs_section_ptr)
3577 /* Look through the section relocs. */
3578 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
3582 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3583 sym_hashes = elf_sym_hashes (ibfd);
3585 /* Read the relocations. */
3586 relstart = _bfd_elf64_link_read_relocs (obfd, sec, (PTR) NULL,
3587 (Elf_Internal_Rela *) NULL,
3589 if (relstart == NULL)
3592 /* First run through the relocs to check they are sane, and to
3593 determine whether we need to edit this opd section. */
3596 relend = relstart + sec->reloc_count;
3597 for (rel = relstart; rel < relend; rel++)
3599 enum elf_ppc_reloc_type r_type;
3600 unsigned long r_symndx;
3602 struct elf_link_hash_entry *h;
3603 Elf_Internal_Sym *sym;
3605 /* .opd contains a regular array of 24 byte entries. We're
3606 only interested in the reloc pointing to a function entry
3608 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3609 if (r_type == R_PPC64_TOC)
3612 if (r_type != R_PPC64_ADDR64)
3614 (*_bfd_error_handler)
3615 (_("%s: unexpected reloc type %u in .opd section"),
3616 bfd_archive_filename (ibfd), r_type);
3621 if (rel + 1 >= relend)
3623 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info);
3624 if (r_type != R_PPC64_TOC)
3627 if (rel->r_offset != offset)
3629 /* If someone messes with .opd alignment then after a
3630 "ld -r" we might have padding in the middle of .opd.
3631 Also, there's nothing to prevent someone putting
3632 something silly in .opd with the assembler. No .opd
3633 optimization for them! */
3634 (*_bfd_error_handler)
3635 (_("%s: .opd is not a regular array of opd entries"),
3636 bfd_archive_filename (ibfd));
3641 r_symndx = ELF64_R_SYM (rel->r_info);
3645 if (r_symndx >= symtab_hdr->sh_info)
3647 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3648 while (h->root.type == bfd_link_hash_indirect
3649 || h->root.type == bfd_link_hash_warning)
3650 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3651 if (h->root.type == bfd_link_hash_defined
3652 || h->root.type == bfd_link_hash_defweak)
3653 sym_sec = h->root.u.def.section;
3657 if (local_syms == NULL)
3659 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
3660 if (local_syms == NULL)
3661 local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3662 symtab_hdr->sh_info, 0,
3664 if (local_syms == NULL)
3665 goto error_free_rel;
3667 sym = local_syms + r_symndx;
3668 if ((sym->st_shndx != SHN_UNDEF
3669 && sym->st_shndx < SHN_LORESERVE)
3670 || sym->st_shndx > SHN_HIRESERVE)
3671 sym_sec = bfd_section_from_elf_index (ibfd, sym->st_shndx);
3674 if (sym_sec == NULL || sym_sec->owner == NULL)
3676 (*_bfd_error_handler)
3677 (_("%s: undefined sym `%s' in .opd section"),
3678 bfd_archive_filename (ibfd),
3679 h != NULL ? h->root.root.string : "<local symbol>");
3684 /* opd entries are always for functions defined in the
3685 current input bfd. If the symbol isn't defined in the
3686 input bfd, then we won't be using the function in this
3687 bfd; It must be defined in a linkonce section in another
3688 bfd, or is weak. It's also possible that we are
3689 discarding the function due to a linker script /DISCARD/,
3690 which we test for via the output_section. */
3691 if (sym_sec->owner != ibfd
3692 || sym_sec->output_section == bfd_abs_section_ptr)
3700 Elf_Internal_Rela *write_rel;
3701 bfd_byte *rptr, *wptr;
3704 /* This seems a waste of time as input .opd sections are all
3705 zeros as generated by gcc, but I suppose there's no reason
3706 this will always be so. We might start putting something in
3707 the third word of .opd entries. */
3708 if ((sec->flags & SEC_IN_MEMORY) == 0)
3710 bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size);
3712 || !bfd_get_section_contents (ibfd, sec, loc, (bfd_vma) 0,
3715 if (local_syms != NULL
3716 && symtab_hdr->contents != (unsigned char *) local_syms)
3719 if (elf_section_data (sec)->relocs != relstart)
3723 sec->contents = loc;
3724 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
3727 elf_section_data (sec)->relocs = relstart;
3729 wptr = sec->contents;
3730 rptr = sec->contents;
3731 write_rel = relstart;
3734 for (rel = relstart; rel < relend; rel++)
3736 if (rel->r_offset == offset)
3738 unsigned long r_symndx;
3740 struct elf_link_hash_entry *h;
3741 Elf_Internal_Sym *sym;
3743 r_symndx = ELF64_R_SYM (rel->r_info);
3747 if (r_symndx >= symtab_hdr->sh_info)
3749 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3750 while (h->root.type == bfd_link_hash_indirect
3751 || h->root.type == bfd_link_hash_warning)
3752 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3753 if (h->root.type == bfd_link_hash_defined
3754 || h->root.type == bfd_link_hash_defweak)
3755 sym_sec = h->root.u.def.section;
3759 sym = local_syms + r_symndx;
3760 if ((sym->st_shndx != SHN_UNDEF
3761 && sym->st_shndx < SHN_LORESERVE)
3762 || sym->st_shndx > SHN_HIRESERVE)
3763 sym_sec = bfd_section_from_elf_index (ibfd,
3767 skip = (sym_sec->owner != ibfd
3768 || sym_sec->output_section == bfd_abs_section_ptr);
3771 if (h != NULL && sym_sec->owner == ibfd)
3773 /* Arrange for the function descriptor sym
3775 struct elf_link_hash_entry *fdh;
3776 struct ppc_link_hash_entry *fh;
3778 fh = (struct ppc_link_hash_entry *) h;
3779 BFD_ASSERT (fh->is_func);
3781 fdh->root.u.def.value = 0;
3782 fdh->root.u.def.section = sym_sec;
3787 /* We'll be keeping this opd entry. */
3791 /* Redefine the function descriptor symbol
3792 to this location in the opd section.
3793 We've checked above that opd relocs are
3795 struct elf_link_hash_entry *fdh;
3796 struct ppc_link_hash_entry *fh;
3798 fh = (struct ppc_link_hash_entry *) h;
3799 BFD_ASSERT (fh->is_func);
3801 fdh->root.u.def.value = wptr - sec->contents;
3805 /* Local syms are a bit tricky. We could
3806 tweak them as they can be cached, but
3807 we'd need to look through the local syms
3808 for the function descriptor sym which we
3809 don't have at the moment. So keep an
3810 array of adjustments. */
3811 adjust[rel->r_offset / 24] = wptr - rptr;
3815 memcpy (wptr, rptr, 24);
3822 /* We need to adjust any reloc offsets to point to the
3823 new opd entries. While we're at it, we may as well
3824 remove redundant relocs. */
3827 rel->r_offset += wptr - rptr;
3828 if (write_rel != rel)
3829 memcpy (write_rel, rel, sizeof (*rel));
3834 sec->_cooked_size = wptr - sec->contents;
3835 sec->reloc_count = write_rel - relstart;
3837 else if (elf_section_data (sec)->relocs != relstart)
3840 if (local_syms != NULL
3841 && symtab_hdr->contents != (unsigned char *) local_syms)
3843 if (!info->keep_memory)
3846 symtab_hdr->contents = (unsigned char *) local_syms;
3853 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3854 will be called from elflink.h. If elflink.h doesn't call our
3855 finish_dynamic_symbol routine, we'll need to do something about
3856 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3857 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3859 && ((INFO)->shared \
3860 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3861 && ((H)->dynindx != -1 \
3862 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3864 /* Allocate space in .plt, .got and associated reloc sections for
3868 allocate_dynrelocs (h, inf)
3869 struct elf_link_hash_entry *h;
3872 struct bfd_link_info *info;
3873 struct ppc_link_hash_table *htab;
3875 struct ppc_link_hash_entry *eh;
3876 struct ppc_dyn_relocs *p;
3878 if (h->root.type == bfd_link_hash_indirect)
3881 if (h->root.type == bfd_link_hash_warning)
3882 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3884 info = (struct bfd_link_info *) inf;
3885 htab = ppc_hash_table (info);
3887 if (htab->elf.dynamic_sections_created
3888 && h->plt.refcount > 0
3889 && h->dynindx != -1)
3891 BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
3893 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
3895 /* If this is the first .plt entry, make room for the special
3898 if (s->_raw_size == 0)
3899 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
3901 h->plt.offset = s->_raw_size;
3903 /* Make room for this entry. */
3904 s->_raw_size += PLT_ENTRY_SIZE;
3906 /* Make room for the .glink code. */
3908 if (s->_raw_size == 0)
3909 s->_raw_size += GLINK_CALL_STUB_SIZE;
3910 /* We need bigger stubs past index 32767. */
3911 if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
3913 s->_raw_size += 2*4;
3915 /* We also need to make an entry in the .rela.plt section. */
3917 s->_raw_size += sizeof (Elf64_External_Rela);
3921 h->plt.offset = (bfd_vma) -1;
3922 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3927 h->plt.offset = (bfd_vma) -1;
3928 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3931 if (h->got.refcount > 0)
3935 /* Make sure this symbol is output as a dynamic symbol.
3936 Undefined weak syms won't yet be marked as dynamic. */
3937 if (h->dynindx == -1
3938 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3940 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3945 h->got.offset = s->_raw_size;
3947 dyn = htab->elf.dynamic_sections_created;
3948 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
3949 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
3952 h->got.offset = (bfd_vma) -1;
3954 eh = (struct ppc_link_hash_entry *) h;
3955 if (eh->dyn_relocs == NULL)
3958 /* In the shared -Bsymbolic case, discard space allocated for
3959 dynamic pc-relative relocs against symbols which turn out to be
3960 defined in regular objects. For the normal shared case, discard
3961 space for relocs that have become local due to symbol visibility
3966 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
3967 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3970 struct ppc_dyn_relocs **pp;
3972 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3974 p->count -= p->pc_count;
3985 /* For the non-shared case, discard space for relocs against
3986 symbols which turn out to need copy relocs or are not
3989 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3990 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3991 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3992 || (htab->elf.dynamic_sections_created
3993 && (h->root.type == bfd_link_hash_undefweak
3994 || h->root.type == bfd_link_hash_undefined))))
3996 /* Make sure this symbol is output as a dynamic symbol.
3997 Undefined weak syms won't yet be marked as dynamic. */
3998 if (h->dynindx == -1
3999 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
4001 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
4005 /* If that succeeded, we know we'll be keeping all the
4007 if (h->dynindx != -1)
4011 eh->dyn_relocs = NULL;
4016 /* Finally, allocate space. */
4017 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4019 asection *sreloc = elf_section_data (p->sec)->sreloc;
4020 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
4026 /* Find any dynamic relocs that apply to read-only sections. */
4029 readonly_dynrelocs (h, inf)
4030 struct elf_link_hash_entry *h;
4033 struct ppc_link_hash_entry *eh;
4034 struct ppc_dyn_relocs *p;
4036 if (h->root.type == bfd_link_hash_warning)
4037 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4039 eh = (struct ppc_link_hash_entry *) h;
4040 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4042 asection *s = p->sec->output_section;
4044 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4046 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4048 info->flags |= DF_TEXTREL;
4050 /* Not an error, just cut short the traversal. */
4057 /* Set the sizes of the dynamic sections. */
4060 ppc64_elf_size_dynamic_sections (output_bfd, info)
4061 bfd *output_bfd ATTRIBUTE_UNUSED;
4062 struct bfd_link_info *info;
4064 struct ppc_link_hash_table *htab;
4070 htab = ppc_hash_table (info);
4071 dynobj = htab->elf.dynobj;
4075 if (htab->elf.dynamic_sections_created)
4077 /* Set the contents of the .interp section to the interpreter. */
4080 s = bfd_get_section_by_name (dynobj, ".interp");
4083 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4084 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4088 /* Set up .got offsets for local syms, and space for local dynamic
4090 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4092 bfd_signed_vma *local_got;
4093 bfd_signed_vma *end_local_got;
4094 bfd_size_type locsymcount;
4095 Elf_Internal_Shdr *symtab_hdr;
4098 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4101 for (s = ibfd->sections; s != NULL; s = s->next)
4103 struct ppc_dyn_relocs *p;
4105 for (p = *((struct ppc_dyn_relocs **)
4106 &elf_section_data (s)->local_dynrel);
4110 if (!bfd_is_abs_section (p->sec)
4111 && bfd_is_abs_section (p->sec->output_section))
4113 /* Input section has been discarded, either because
4114 it is a copy of a linkonce section or due to
4115 linker script /DISCARD/, so we'll be discarding
4118 else if (p->count != 0)
4120 srel = elf_section_data (p->sec)->sreloc;
4121 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
4122 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4123 info->flags |= DF_TEXTREL;
4128 local_got = elf_local_got_refcounts (ibfd);
4132 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4133 locsymcount = symtab_hdr->sh_info;
4134 end_local_got = local_got + locsymcount;
4136 srel = htab->srelgot;
4137 for (; local_got < end_local_got; ++local_got)
4141 *local_got = s->_raw_size;
4144 srel->_raw_size += sizeof (Elf64_External_Rela);
4147 *local_got = (bfd_vma) -1;
4151 if (!edit_opd (output_bfd, info))
4154 /* Allocate global sym .plt and .got entries, and space for global
4155 sym dynamic relocs. */
4156 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
4158 /* We now have determined the sizes of the various dynamic sections.
4159 Allocate memory for them. */
4161 for (s = dynobj->sections; s != NULL; s = s->next)
4163 if ((s->flags & SEC_LINKER_CREATED) == 0)
4166 if (s == htab->sbrlt || s == htab->srelbrlt)
4167 /* These haven't been allocated yet; don't strip. */
4169 else if (s == htab->splt
4171 || s == htab->sglink)
4173 /* Strip this section if we don't need it; see the
4176 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4178 if (s->_raw_size == 0)
4180 /* If we don't need this section, strip it from the
4181 output file. This is mostly to handle .rela.bss and
4182 .rela.plt. We must create both sections in
4183 create_dynamic_sections, because they must be created
4184 before the linker maps input sections to output
4185 sections. The linker does that before
4186 adjust_dynamic_symbol is called, and it is that
4187 function which decides whether anything needs to go
4188 into these sections. */
4192 if (s != htab->srelplt)
4195 /* We use the reloc_count field as a counter if we need
4196 to copy relocs into the output file. */
4202 /* It's not one of our sections, so don't allocate space. */
4206 if (s->_raw_size == 0)
4208 _bfd_strip_section_from_output (info, s);
4212 /* .plt is in the bss section. We don't initialise it. */
4213 if ((s->flags & SEC_LOAD) == 0)
4216 /* Allocate memory for the section contents. We use bfd_zalloc
4217 here in case unused entries are not reclaimed before the
4218 section's contents are written out. This should not happen,
4219 but this way if it does, we get a R_PPC64_NONE reloc instead
4221 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4222 if (s->contents == NULL)
4226 if (htab->elf.dynamic_sections_created)
4228 /* Add some entries to the .dynamic section. We fill in the
4229 values later, in ppc64_elf_finish_dynamic_sections, but we
4230 must add the entries now so that we get the correct size for
4231 the .dynamic section. The DT_DEBUG entry is filled in by the
4232 dynamic linker and used by the debugger. */
4233 #define add_dynamic_entry(TAG, VAL) \
4234 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4238 if (!add_dynamic_entry (DT_DEBUG, 0))
4242 if (htab->splt != NULL && htab->splt->_raw_size != 0)
4244 if (!add_dynamic_entry (DT_PLTGOT, 0)
4245 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4246 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
4247 || !add_dynamic_entry (DT_JMPREL, 0)
4248 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
4254 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
4255 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
4261 if (!add_dynamic_entry (DT_RELA, 0)
4262 || !add_dynamic_entry (DT_RELASZ, 0)
4263 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
4266 /* If any dynamic relocs apply to a read-only section,
4267 then we need a DT_TEXTREL entry. */
4268 if ((info->flags & DF_TEXTREL) == 0)
4269 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
4272 if ((info->flags & DF_TEXTREL) != 0)
4274 if (!add_dynamic_entry (DT_TEXTREL, 0))
4279 #undef add_dynamic_entry
4284 /* Determine the type of stub needed, if any, for a call. */
4286 static INLINE enum ppc_stub_type
4287 ppc_type_of_stub (input_sec, rel, hash, destination)
4288 asection *input_sec;
4289 const Elf_Internal_Rela *rel;
4290 struct ppc_link_hash_entry **hash;
4291 bfd_vma destination;
4293 struct ppc_link_hash_entry *h = *hash;
4295 bfd_vma branch_offset;
4296 bfd_vma max_branch_offset;
4297 unsigned int r_type;
4302 && h->oh->plt.offset != (bfd_vma) -1
4303 && h->oh->dynindx != -1)
4305 *hash = (struct ppc_link_hash_entry *) h->oh;
4306 return ppc_stub_plt_call;
4309 if (h->elf.root.type == bfd_link_hash_undefweak
4310 || h->elf.root.type == bfd_link_hash_undefined)
4311 return ppc_stub_none;
4314 /* Determine where the call point is. */
4315 location = (input_sec->output_offset
4316 + input_sec->output_section->vma
4319 branch_offset = destination - location;
4320 r_type = ELF64_R_TYPE (rel->r_info);
4322 /* Determine if a long branch stub is needed. */
4323 max_branch_offset = 1 << 25;
4324 if (r_type != (unsigned int) R_PPC64_REL24)
4325 max_branch_offset = 1 << 15;
4327 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
4328 /* We need a stub. Figure out whether a long_branch or plt_branch
4330 return ppc_stub_long_branch;
4332 return ppc_stub_none;
4335 /* Build a .plt call stub. */
4338 build_plt_stub (obfd, p, offset, glink)
4344 #define PPC_LO(v) ((v) & 0xffff)
4345 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4346 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4349 bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
4350 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
4352 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
4353 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4354 if (PPC_HA (offset + 8) != PPC_HA (offset))
4355 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4357 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
4358 if (PPC_HA (offset + 8) != PPC_HA (offset))
4359 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4361 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
4362 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4363 bfd_put_32 (obfd, BCTR, p), p += 4;
4368 ppc_build_one_stub (gen_entry, in_arg)
4369 struct bfd_hash_entry *gen_entry;
4372 struct ppc_stub_hash_entry *stub_entry;
4373 struct ppc_branch_hash_entry *br_entry;
4374 struct bfd_link_info *info;
4375 struct ppc_link_hash_table *htab;
4384 /* Massage our args to the form they really have. */
4385 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4386 info = (struct bfd_link_info *) in_arg;
4388 htab = ppc_hash_table (info);
4389 stub_sec = stub_entry->stub_sec;
4391 /* Make a note of the offset within the stubs for this entry. */
4392 stub_entry->stub_offset = stub_sec->_cooked_size;
4393 loc = stub_sec->contents + stub_entry->stub_offset;
4395 stub_bfd = stub_sec->owner;
4397 switch (stub_entry->stub_type)
4399 case ppc_stub_long_branch:
4400 /* Branches are relative. This is where we are going to. */
4401 off = (stub_entry->target_value
4402 + stub_entry->target_section->output_offset
4403 + stub_entry->target_section->output_section->vma);
4405 /* And this is where we are coming from. */
4406 off -= (stub_entry->stub_offset
4407 + stub_sec->output_offset
4408 + stub_sec->output_section->vma);
4410 BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
4412 bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc);
4416 case ppc_stub_plt_branch:
4417 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4418 stub_entry->root.string + 9,
4420 if (br_entry == NULL)
4422 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
4423 stub_entry->root.string + 9);
4424 htab->stub_error = true;
4428 off = (stub_entry->target_value
4429 + stub_entry->target_section->output_offset
4430 + stub_entry->target_section->output_section->vma);
4432 bfd_put_64 (htab->sbrlt->owner, off,
4433 htab->sbrlt->contents + br_entry->offset);
4437 /* Create a reloc for the branch lookup table entry. */
4438 Elf_Internal_Rela rela;
4439 Elf64_External_Rela *r;
4441 rela.r_offset = (br_entry->offset
4442 + htab->sbrlt->output_offset
4443 + htab->sbrlt->output_section->vma);
4444 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
4445 rela.r_addend = off;
4447 r = (Elf64_External_Rela *) htab->srelbrlt->contents;
4448 r += htab->srelbrlt->reloc_count++;
4449 bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, r);
4452 off = (br_entry->offset
4453 + htab->sbrlt->output_offset
4454 + htab->sbrlt->output_section->vma
4455 - elf_gp (htab->sbrlt->output_section->owner)
4458 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4460 (*_bfd_error_handler)
4461 (_("linkage table error against `%s'"),
4462 stub_entry->root.string);
4463 bfd_set_error (bfd_error_bad_value);
4464 htab->stub_error = true;
4469 bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc);
4470 bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4);
4471 bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8);
4472 bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12);
4476 case ppc_stub_plt_call:
4477 /* Do the best we can for shared libraries built without
4478 exporting ".foo" for each "foo". This can happen when symbol
4479 versioning scripts strip all bar a subset of symbols. */
4480 if (stub_entry->h->oh->root.type != bfd_link_hash_defined
4481 && stub_entry->h->oh->root.type != bfd_link_hash_defweak)
4483 /* Point the symbol at the stub. There may be multiple stubs,
4484 we don't really care; The main thing is to make this sym
4485 defined somewhere. */
4486 stub_entry->h->oh->root.type = bfd_link_hash_defined;
4487 stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec;
4488 stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset;
4491 /* Now build the stub. */
4492 off = stub_entry->h->elf.plt.offset;
4493 if (off >= (bfd_vma) -2)
4496 off &= ~ (bfd_vma) 1;
4497 off += (htab->splt->output_offset
4498 + htab->splt->output_section->vma
4499 - elf_gp (htab->splt->output_section->owner)
4502 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4504 (*_bfd_error_handler)
4505 (_("linkage table error against `%s'"),
4506 stub_entry->h->elf.root.root.string);
4507 bfd_set_error (bfd_error_bad_value);
4508 htab->stub_error = true;
4512 p = build_plt_stub (stub_bfd, loc, (int) off, 0);
4521 stub_sec->_cooked_size += size;
4525 /* As above, but don't actually build the stub. Just bump offset so
4526 we know stub section sizes, and select plt_branch stubs where
4527 long_branch stubs won't do. */
4530 ppc_size_one_stub (gen_entry, in_arg)
4531 struct bfd_hash_entry *gen_entry;
4534 struct ppc_stub_hash_entry *stub_entry;
4535 struct ppc_link_hash_table *htab;
4539 /* Massage our args to the form they really have. */
4540 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4541 htab = (struct ppc_link_hash_table *) in_arg;
4543 if (stub_entry->stub_type == ppc_stub_plt_call)
4545 off = stub_entry->h->elf.plt.offset & ~(bfd_vma) 1;
4546 off += (htab->splt->output_offset
4547 + htab->splt->output_section->vma
4548 - elf_gp (htab->splt->output_section->owner)
4552 if (PPC_HA ((int) off + 16) != PPC_HA ((int) off))
4557 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4558 stub_entry->stub_type = ppc_stub_long_branch;
4561 off = (stub_entry->target_value
4562 + stub_entry->target_section->output_offset
4563 + stub_entry->target_section->output_section->vma);
4564 off -= (stub_entry->stub_sec->_raw_size
4565 + stub_entry->stub_sec->output_offset
4566 + stub_entry->stub_sec->output_section->vma);
4568 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
4570 struct ppc_branch_hash_entry *br_entry;
4572 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4573 stub_entry->root.string + 9,
4575 if (br_entry == NULL)
4577 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
4578 stub_entry->root.string + 9);
4579 htab->stub_error = true;
4583 if (br_entry->iter != htab->stub_iteration)
4585 br_entry->iter = htab->stub_iteration;
4586 br_entry->offset = htab->sbrlt->_raw_size;
4587 htab->sbrlt->_raw_size += 8;
4589 stub_entry->stub_type = ppc_stub_plt_branch;
4594 stub_entry->stub_sec->_raw_size += size;
4598 /* Set up various things so that we can make a list of input sections
4599 for each output section included in the link. Returns -1 on error,
4600 0 when no stubs will be needed, and 1 on success. */
4603 ppc64_elf_setup_section_lists (output_bfd, info)
4605 struct bfd_link_info *info;
4608 int top_id, top_index;
4610 asection **input_list, **list;
4612 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4614 if (htab->elf.root.creator->flavour != bfd_target_elf_flavour
4615 || htab->sbrlt == NULL)
4618 /* Find the top input section id. */
4619 for (input_bfd = info->input_bfds, top_id = 0;
4621 input_bfd = input_bfd->link_next)
4623 for (section = input_bfd->sections;
4625 section = section->next)
4627 if (top_id < section->id)
4628 top_id = section->id;
4632 amt = sizeof (struct map_stub) * (top_id + 1);
4633 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4634 if (htab->stub_group == NULL)
4637 /* We can't use output_bfd->section_count here to find the top output
4638 section index as some sections may have been removed, and
4639 _bfd_strip_section_from_output doesn't renumber the indices. */
4640 for (section = output_bfd->sections, top_index = 0;
4642 section = section->next)
4644 if (top_index < section->index)
4645 top_index = section->index;
4648 htab->top_index = top_index;
4649 amt = sizeof (asection *) * (top_index + 1);
4650 input_list = (asection **) bfd_malloc (amt);
4651 htab->input_list = input_list;
4652 if (input_list == NULL)
4655 /* For sections we aren't interested in, mark their entries with a
4656 value we can check later. */
4657 list = input_list + top_index;
4659 *list = bfd_abs_section_ptr;
4660 while (list-- != input_list);
4662 for (section = output_bfd->sections;
4664 section = section->next)
4666 if ((section->flags & SEC_CODE) != 0)
4667 input_list[section->index] = NULL;
4673 /* The linker repeatedly calls this function for each input section,
4674 in the order that input sections are linked into output sections.
4675 Build lists of input sections to determine groupings between which
4676 we may insert linker stubs. */
4679 ppc64_elf_next_input_section (info, isec)
4680 struct bfd_link_info *info;
4683 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4685 if (isec->output_section->index <= htab->top_index)
4687 asection **list = htab->input_list + isec->output_section->index;
4688 if (*list != bfd_abs_section_ptr)
4690 /* Steal the link_sec pointer for our list. */
4691 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4692 /* This happens to make the list in reverse order,
4693 which is what we want. */
4694 PREV_SEC (isec) = *list;
4700 /* See whether we can group stub sections together. Grouping stub
4701 sections may result in fewer stubs. More importantly, we need to
4702 put all .init* and .fini* stubs at the beginning of the .init or
4703 .fini output sections respectively, because glibc splits the
4704 _init and _fini functions into multiple parts. Putting a stub in
4705 the middle of a function is not a good idea. */
4708 group_sections (htab, stub_group_size, stubs_always_before_branch)
4709 struct ppc_link_hash_table *htab;
4710 bfd_size_type stub_group_size;
4711 boolean stubs_always_before_branch;
4713 asection **list = htab->input_list + htab->top_index;
4716 asection *tail = *list;
4717 if (tail == bfd_abs_section_ptr)
4719 while (tail != NULL)
4723 bfd_size_type total;
4726 if (tail->_cooked_size)
4727 total = tail->_cooked_size;
4729 total = tail->_raw_size;
4730 while ((prev = PREV_SEC (curr)) != NULL
4731 && ((total += curr->output_offset - prev->output_offset)
4735 /* OK, the size from the start of CURR to the end is less
4736 than stub_group_size and thus can be handled by one stub
4737 section. (or the tail section is itself larger than
4738 stub_group_size, in which case we may be toast.) We
4739 should really be keeping track of the total size of stubs
4740 added here, as stubs contribute to the final output
4741 section size. That's a little tricky, and this way will
4742 only break if stubs added make the total size more than
4743 2^25, ie. for the default stub_group_size, if stubs total
4744 more than 2834432 bytes, or over 100000 plt call stubs. */
4747 prev = PREV_SEC (tail);
4748 /* Set up this stub group. */
4749 htab->stub_group[tail->id].link_sec = curr;
4751 while (tail != curr && (tail = prev) != NULL);
4753 /* But wait, there's more! Input sections up to stub_group_size
4754 bytes before the stub section can be handled by it too. */
4755 if (!stubs_always_before_branch)
4759 && ((total += tail->output_offset - prev->output_offset)
4763 prev = PREV_SEC (tail);
4764 htab->stub_group[tail->id].link_sec = curr;
4770 while (list-- != htab->input_list);
4771 free (htab->input_list);
4775 /* Determine and set the size of the stub section for a final link.
4777 The basic idea here is to examine all the relocations looking for
4778 PC-relative calls to a target that is unreachable with a "bl"
4782 ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size,
4783 add_stub_section, layout_sections_again)
4786 struct bfd_link_info *info;
4787 bfd_signed_vma group_size;
4788 asection * (*add_stub_section) PARAMS ((const char *, asection *));
4789 void (*layout_sections_again) PARAMS ((void));
4791 bfd_size_type stub_group_size;
4792 boolean stubs_always_before_branch;
4793 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4795 /* Stash our params away. */
4796 htab->stub_bfd = stub_bfd;
4797 htab->add_stub_section = add_stub_section;
4798 htab->layout_sections_again = layout_sections_again;
4799 stubs_always_before_branch = group_size < 0;
4801 stub_group_size = -group_size;
4803 stub_group_size = group_size;
4804 if (stub_group_size == 1)
4806 /* Default values. */
4807 stub_group_size = 30720000;
4808 if (htab->has_14bit_branch)
4809 stub_group_size = 30000;
4812 group_sections (htab, stub_group_size, stubs_always_before_branch);
4817 unsigned int bfd_indx;
4819 boolean stub_changed;
4821 htab->stub_iteration += 1;
4822 stub_changed = false;
4824 for (input_bfd = info->input_bfds, bfd_indx = 0;
4826 input_bfd = input_bfd->link_next, bfd_indx++)
4828 Elf_Internal_Shdr *symtab_hdr;
4830 Elf_Internal_Sym *local_syms = NULL;
4832 /* We'll need the symbol table in a second. */
4833 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4834 if (symtab_hdr->sh_info == 0)
4837 /* Walk over each section attached to the input bfd. */
4838 for (section = input_bfd->sections;
4840 section = section->next)
4842 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4844 /* If there aren't any relocs, then there's nothing more
4846 if ((section->flags & SEC_RELOC) == 0
4847 || section->reloc_count == 0)
4850 /* If this section is a link-once section that will be
4851 discarded, then don't create any stubs. */
4852 if (section->output_section == NULL
4853 || section->output_section->owner != output_bfd)
4856 /* Get the relocs. */
4858 = _bfd_elf64_link_read_relocs (input_bfd, section, NULL,
4859 (Elf_Internal_Rela *) NULL,
4861 if (internal_relocs == NULL)
4862 goto error_ret_free_local;
4864 /* Now examine each relocation. */
4865 irela = internal_relocs;
4866 irelaend = irela + section->reloc_count;
4867 for (; irela < irelaend; irela++)
4869 unsigned int r_type, r_indx;
4870 enum ppc_stub_type stub_type;
4871 struct ppc_stub_hash_entry *stub_entry;
4874 bfd_vma destination;
4875 struct ppc_link_hash_entry *hash;
4877 const asection *id_sec;
4879 r_type = ELF64_R_TYPE (irela->r_info);
4880 r_indx = ELF64_R_SYM (irela->r_info);
4882 if (r_type >= (unsigned int) R_PPC_max)
4884 bfd_set_error (bfd_error_bad_value);
4885 goto error_ret_free_internal;
4888 /* Only look for stubs on branch instructions. */
4889 if (r_type != (unsigned int) R_PPC64_REL24
4890 && r_type != (unsigned int) R_PPC64_REL14
4891 && r_type != (unsigned int) R_PPC64_REL14_BRTAKEN
4892 && r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN)
4895 /* Now determine the call target, its name, value,
4901 if (r_indx < symtab_hdr->sh_info)
4903 /* It's a local symbol. */
4904 Elf_Internal_Sym *sym;
4905 Elf_Internal_Shdr *hdr;
4907 if (local_syms == NULL)
4910 = (Elf_Internal_Sym *) symtab_hdr->contents;
4911 if (local_syms == NULL)
4913 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4914 symtab_hdr->sh_info, 0,
4916 if (local_syms == NULL)
4917 goto error_ret_free_internal;
4919 sym = local_syms + r_indx;
4920 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4921 sym_sec = hdr->bfd_section;
4922 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4923 sym_value = sym->st_value;
4924 destination = (sym_value + irela->r_addend
4925 + sym_sec->output_offset
4926 + sym_sec->output_section->vma);
4930 /* It's an external symbol. */
4933 e_indx = r_indx - symtab_hdr->sh_info;
4934 hash = ((struct ppc_link_hash_entry *)
4935 elf_sym_hashes (input_bfd)[e_indx]);
4937 while (hash->elf.root.type == bfd_link_hash_indirect
4938 || hash->elf.root.type == bfd_link_hash_warning)
4939 hash = ((struct ppc_link_hash_entry *)
4940 hash->elf.root.u.i.link);
4942 if (hash->elf.root.type == bfd_link_hash_defined
4943 || hash->elf.root.type == bfd_link_hash_defweak)
4945 sym_sec = hash->elf.root.u.def.section;
4946 sym_value = hash->elf.root.u.def.value;
4947 if (sym_sec->output_section != NULL)
4948 destination = (sym_value + irela->r_addend
4949 + sym_sec->output_offset
4950 + sym_sec->output_section->vma);
4952 else if (hash->elf.root.type == bfd_link_hash_undefweak)
4954 else if (hash->elf.root.type == bfd_link_hash_undefined)
4958 bfd_set_error (bfd_error_bad_value);
4959 goto error_ret_free_internal;
4963 /* Determine what (if any) linker stub is needed. */
4964 stub_type = ppc_type_of_stub (section, irela, &hash,
4966 if (stub_type == ppc_stub_none)
4969 /* Support for grouping stub sections. */
4970 id_sec = htab->stub_group[section->id].link_sec;
4972 /* Get the name of this stub. */
4973 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
4975 goto error_ret_free_internal;
4977 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4978 stub_name, false, false);
4979 if (stub_entry != NULL)
4981 /* The proper stub has already been created. */
4986 stub_entry = ppc_add_stub (stub_name, section, htab);
4987 if (stub_entry == NULL)
4990 error_ret_free_internal:
4991 if (elf_section_data (section)->relocs == NULL)
4992 free (internal_relocs);
4993 error_ret_free_local:
4994 if (local_syms != NULL
4995 && (symtab_hdr->contents
4996 != (unsigned char *) local_syms))
5001 stub_entry->target_value = sym_value;
5002 stub_entry->target_section = sym_sec;
5003 stub_entry->stub_type = stub_type;
5004 stub_entry->h = hash;
5005 stub_changed = true;
5008 /* We're done with the internal relocs, free them. */
5009 if (elf_section_data (section)->relocs != internal_relocs)
5010 free (internal_relocs);
5013 if (local_syms != NULL
5014 && symtab_hdr->contents != (unsigned char *) local_syms)
5016 if (!info->keep_memory)
5019 symtab_hdr->contents = (unsigned char *) local_syms;
5026 /* OK, we've added some stubs. Find out the new size of the
5028 for (stub_sec = htab->stub_bfd->sections;
5030 stub_sec = stub_sec->next)
5032 stub_sec->_raw_size = 0;
5033 stub_sec->_cooked_size = 0;
5035 htab->sbrlt->_raw_size = 0;
5036 htab->sbrlt->_cooked_size = 0;
5038 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab);
5040 /* Ask the linker to do its stuff. */
5041 (*htab->layout_sections_again) ();
5044 /* It would be nice to strip .branch_lt from the output if the
5045 section is empty, but it's too late. If we strip sections here,
5046 the dynamic symbol table is corrupted since the section symbol
5047 for the stripped section isn't written. */
5052 /* Called after we have determined section placement. If sections
5053 move, we'll be called again. Provide a value for TOCstart. */
5056 ppc64_elf_toc (obfd)
5062 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5063 order. The TOC starts where the first of these sections starts. */
5064 s = bfd_get_section_by_name (obfd, ".got");
5066 s = bfd_get_section_by_name (obfd, ".toc");
5068 s = bfd_get_section_by_name (obfd, ".tocbss");
5070 s = bfd_get_section_by_name (obfd, ".plt");
5073 /* This may happen for
5074 o references to TOC base (SYM@toc / TOC[tc0]) without a
5077 o --gc-sections and empty TOC sections
5079 FIXME: Warn user? */
5081 /* Look for a likely section. We probably won't even be
5083 for (s = obfd->sections; s != NULL; s = s->next)
5084 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
5085 == (SEC_ALLOC | SEC_SMALL_DATA))
5088 for (s = obfd->sections; s != NULL; s = s->next)
5089 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
5090 == (SEC_ALLOC | SEC_SMALL_DATA))
5093 for (s = obfd->sections; s != NULL; s = s->next)
5094 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
5097 for (s = obfd->sections; s != NULL; s = s->next)
5098 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
5104 TOCstart = s->output_section->vma + s->output_offset;
5109 /* Build all the stubs associated with the current output file.
5110 The stubs are kept in a hash table attached to the main linker
5111 hash table. This function is called via gldelf64ppc_finish. */
5114 ppc64_elf_build_stubs (info)
5115 struct bfd_link_info *info;
5117 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5122 for (stub_sec = htab->stub_bfd->sections;
5124 stub_sec = stub_sec->next)
5128 /* Allocate memory to hold the linker stubs. */
5129 size = stub_sec->_raw_size;
5132 stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size);
5133 if (stub_sec->contents == NULL)
5136 stub_sec->_cooked_size = 0;
5139 if (htab->splt != NULL)
5143 /* Build the .glink plt call stub. */
5144 plt_r2 = (htab->splt->output_offset
5145 + htab->splt->output_section->vma
5146 - elf_gp (htab->splt->output_section->owner)
5148 p = htab->sglink->contents;
5149 p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
5150 while (p < htab->sglink->contents + GLINK_CALL_STUB_SIZE)
5152 bfd_put_32 (htab->sglink->owner, NOP, p);
5156 /* Build the .glink lazy link call stubs. */
5158 while (p < htab->sglink->contents + htab->sglink->_raw_size)
5162 bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p);
5167 bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p);
5169 bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
5172 bfd_put_32 (htab->sglink->owner,
5173 B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p);
5177 htab->sglink->_cooked_size = p - htab->sglink->contents;
5180 if (htab->sbrlt->_raw_size != 0)
5182 htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner,
5183 htab->sbrlt->_raw_size);
5184 if (htab->sbrlt->contents == NULL)
5188 /* Build the stubs as directed by the stub hash table. */
5189 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
5191 for (stub_sec = htab->stub_bfd->sections;
5193 stub_sec = stub_sec->next)
5195 if (stub_sec->_raw_size != stub_sec->_cooked_size)
5199 if (stub_sec != NULL
5200 || htab->sglink->_raw_size != htab->sglink->_cooked_size)
5202 htab->stub_error = true;
5203 (*_bfd_error_handler) (_("stubs don't match calculated size"));
5206 return !htab->stub_error;
5209 /* The RELOCATE_SECTION function is called by the ELF backend linker
5210 to handle the relocations for a section.
5212 The relocs are always passed as Rela structures; if the section
5213 actually uses Rel structures, the r_addend field will always be
5216 This function is responsible for adjust the section contents as
5217 necessary, and (if using Rela relocs and generating a
5218 relocateable output file) adjusting the reloc addend as
5221 This function does not have to worry about setting the reloc
5222 address or the reloc symbol index.
5224 LOCAL_SYMS is a pointer to the swapped in local symbols.
5226 LOCAL_SECTIONS is an array giving the section in the input file
5227 corresponding to the st_shndx field of each local symbol.
5229 The global hash table entry for the global symbols can be found
5230 via elf_sym_hashes (input_bfd).
5232 When generating relocateable output, this function must handle
5233 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5234 going to be the section symbol corresponding to the output
5235 section, which means that the addend must be adjusted
5239 ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
5240 contents, relocs, local_syms, local_sections)
5242 struct bfd_link_info *info;
5244 asection *input_section;
5246 Elf_Internal_Rela *relocs;
5247 Elf_Internal_Sym *local_syms;
5248 asection **local_sections;
5250 struct ppc_link_hash_table *htab;
5251 Elf_Internal_Shdr *symtab_hdr;
5252 struct elf_link_hash_entry **sym_hashes;
5253 Elf_Internal_Rela *rel;
5254 Elf_Internal_Rela *relend;
5255 bfd_vma *local_got_offsets;
5259 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5260 boolean is_power4 = false;
5262 if (info->relocateable)
5265 /* Initialize howto table if needed. */
5266 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5269 htab = ppc_hash_table (info);
5270 local_got_offsets = elf_local_got_offsets (input_bfd);
5271 TOCstart = elf_gp (output_bfd);
5272 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5273 sym_hashes = elf_sym_hashes (input_bfd);
5274 is_opd = elf_section_data (input_section)->tdata != NULL;
5277 relend = relocs + input_section->reloc_count;
5278 for (; rel < relend; rel++)
5280 enum elf_ppc_reloc_type r_type;
5283 bfd_reloc_status_type r;
5284 Elf_Internal_Sym *sym;
5286 struct elf_link_hash_entry *h;
5287 struct elf_link_hash_entry *fdh;
5288 const char *sym_name;
5289 unsigned long r_symndx;
5291 boolean unresolved_reloc;
5294 struct ppc_stub_hash_entry *stub_entry;
5295 bfd_vma max_br_offset;
5298 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
5299 r_symndx = ELF64_R_SYM (rel->r_info);
5300 offset = rel->r_offset;
5301 addend = rel->r_addend;
5302 r = bfd_reloc_other;
5303 sym = (Elf_Internal_Sym *) 0;
5304 sec = (asection *) 0;
5305 h = (struct elf_link_hash_entry *) 0;
5306 sym_name = (const char *) 0;
5307 unresolved_reloc = false;
5310 if (r_type == R_PPC64_TOC)
5312 /* Relocation value is TOC base. Symbol is ignored. */
5313 relocation = TOCstart + TOC_BASE_OFF;
5315 else if (r_symndx < symtab_hdr->sh_info)
5317 /* It's a local symbol. */
5318 sym = local_syms + r_symndx;
5319 sec = local_sections[r_symndx];
5320 sym_name = "<local symbol>";
5322 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
5323 /* rel may have changed, update our copy of addend. */
5324 addend = rel->r_addend;
5326 if (elf_section_data (sec) != NULL)
5328 long *opd_sym_adjust;
5330 opd_sym_adjust = (long *) elf_section_data (sec)->tdata;
5331 if (opd_sym_adjust != NULL && sym->st_value % 24 == 0)
5332 relocation += opd_sym_adjust[sym->st_value / 24];
5337 /* It's a global symbol. */
5338 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5339 while (h->root.type == bfd_link_hash_indirect
5340 || h->root.type == bfd_link_hash_warning)
5341 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5342 sym_name = h->root.root.string;
5344 if (h->root.type == bfd_link_hash_defined
5345 || h->root.type == bfd_link_hash_defweak)
5347 sec = h->root.u.def.section;
5348 if (sec->output_section == NULL)
5349 /* Set a flag that will be cleared later if we find a
5350 relocation value for this symbol. output_section
5351 is typically NULL for symbols satisfied by a shared
5353 unresolved_reloc = true;
5355 relocation = (h->root.u.def.value
5356 + sec->output_section->vma
5357 + sec->output_offset);
5359 else if (h->root.type == bfd_link_hash_undefweak)
5361 else if (info->shared
5362 && (!info->symbolic || info->allow_shlib_undefined)
5363 && !info->no_undefined
5364 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
5368 if (! ((*info->callbacks->undefined_symbol)
5369 (info, h->root.root.string, input_bfd, input_section,
5370 offset, (!info->shared
5371 || info->no_undefined
5372 || ELF_ST_VISIBILITY (h->other)))))
5378 /* First handle relocations that tweak non-addend part of insn. */
5385 /* Branch taken prediction relocations. */
5386 case R_PPC64_ADDR14_BRTAKEN:
5387 case R_PPC64_REL14_BRTAKEN:
5388 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5391 /* Branch not taken prediction relocations. */
5392 case R_PPC64_ADDR14_BRNTAKEN:
5393 case R_PPC64_REL14_BRNTAKEN:
5394 insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
5397 /* Set 'a' bit. This is 0b00010 in BO field for branch
5398 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5399 for branch on CTR insns (BO == 1a00t or 1a01t). */
5400 if ((insn & (0x14 << 21)) == (0x04 << 21))
5402 else if ((insn & (0x14 << 21)) == (0x10 << 21))
5410 + input_section->output_offset
5411 + input_section->output_section->vma);
5413 /* Invert 'y' bit if not the default. */
5414 if ((bfd_signed_vma) (relocation + addend - from) < 0)
5418 bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
5422 /* A REL24 branching to a linkage function is followed by a
5423 nop. We replace the nop with a ld in order to restore
5424 the TOC base pointer. Only calls to shared objects need
5425 to alter the TOC base. These are recognized by their
5426 need for a PLT entry. */
5428 && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL
5429 && fdh->plt.offset != (bfd_vma) -1
5430 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
5431 rel, htab)) != NULL)
5433 boolean can_plt_call = 0;
5435 if (offset + 8 <= input_section->_cooked_size)
5437 insn = bfd_get_32 (input_bfd, contents + offset + 4);
5439 || insn == CROR_151515 || insn == CROR_313131)
5441 bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1,
5442 contents + offset + 4);
5449 /* If this is a plain branch rather than a branch
5450 and link, don't require a nop. */
5451 insn = bfd_get_32 (input_bfd, contents + offset);
5452 if ((insn & 1) == 0)
5458 relocation = (stub_entry->stub_offset
5459 + stub_entry->stub_sec->output_offset
5460 + stub_entry->stub_sec->output_section->vma);
5462 unresolved_reloc = false;
5467 && h->root.type == bfd_link_hash_undefweak
5471 /* Tweak calls to undefined weak functions to point at a
5472 blr. We can thus call a weak function without first
5473 checking whether the function is defined. We have a
5474 blr at the end of .sfpr. */
5475 BFD_ASSERT (htab->sfpr->_raw_size != 0);
5476 relocation = (htab->sfpr->_raw_size - 4
5477 + htab->sfpr->output_offset
5478 + htab->sfpr->output_section->vma);
5480 + input_section->output_offset
5481 + input_section->output_section->vma);
5483 /* But let's not be silly about it. If the blr isn't in
5484 reach, just go to the next instruction. */
5485 if (relocation - from + (1 << 25) >= (1 << 26)
5486 || htab->sfpr->_raw_size == 0)
5487 relocation = from + 4;
5496 (*_bfd_error_handler)
5497 (_("%s: unknown relocation type %d for symbol %s"),
5498 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
5500 bfd_set_error (bfd_error_bad_value);
5505 case R_PPC_GNU_VTINHERIT:
5506 case R_PPC_GNU_VTENTRY:
5509 /* GOT16 relocations. Like an ADDR16 using the symbol's
5510 address in the GOT as relocation value instead of the
5511 symbols value itself. Also, create a GOT entry for the
5512 symbol and put the symbol value there. */
5514 case R_PPC64_GOT16_LO:
5515 case R_PPC64_GOT16_HI:
5516 case R_PPC64_GOT16_HA:
5517 case R_PPC64_GOT16_DS:
5518 case R_PPC64_GOT16_LO_DS:
5520 /* Relocation is to the entry for this symbol in the global
5524 if (htab->sgot == NULL)
5531 off = h->got.offset;
5532 dyn = htab->elf.dynamic_sections_created;
5533 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
5537 || (h->elf_link_hash_flags
5538 & ELF_LINK_FORCED_LOCAL))
5539 && (h->elf_link_hash_flags
5540 & ELF_LINK_HASH_DEF_REGULAR)))
5542 /* This is actually a static link, or it is a
5543 -Bsymbolic link and the symbol is defined
5544 locally, or the symbol was forced to be local
5545 because of a version file. We must initialize
5546 this entry in the global offset table. Since the
5547 offset must always be a multiple of 8, we use the
5548 least significant bit to record whether we have
5549 initialized it already.
5551 When doing a dynamic link, we create a .rel.got
5552 relocation entry to initialize the value. This
5553 is done in the finish_dynamic_symbol routine. */
5558 bfd_put_64 (output_bfd, relocation,
5559 htab->sgot->contents + off);
5564 unresolved_reloc = false;
5568 if (local_got_offsets == NULL)
5571 off = local_got_offsets[r_symndx];
5573 /* The offset must always be a multiple of 8. We use
5574 the least significant bit to record whether we have
5575 already processed this entry. */
5580 bfd_put_64 (output_bfd, relocation,
5581 htab->sgot->contents + off);
5585 Elf_Internal_Rela outrel;
5586 Elf64_External_Rela *loc;
5588 /* We need to generate a R_PPC64_RELATIVE reloc
5589 for the dynamic linker. */
5590 outrel.r_offset = (htab->sgot->output_section->vma
5591 + htab->sgot->output_offset
5593 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5594 outrel.r_addend = relocation;
5595 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5596 loc += htab->srelgot->reloc_count++;
5597 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5600 local_got_offsets[r_symndx] |= 1;
5604 if (off >= (bfd_vma) -2)
5607 relocation = htab->sgot->output_offset + off;
5609 /* TOC base (r2) is TOC start plus 0x8000. */
5610 addend -= TOC_BASE_OFF;
5614 case R_PPC64_PLT16_HA:
5615 case R_PPC64_PLT16_HI:
5616 case R_PPC64_PLT16_LO:
5619 /* Relocation is to the entry for this symbol in the
5620 procedure linkage table. */
5622 /* Resolve a PLT reloc against a local symbol directly,
5623 without using the procedure linkage table. */
5627 if (h->plt.offset == (bfd_vma) -1
5628 || htab->splt == NULL)
5630 /* We didn't make a PLT entry for this symbol. This
5631 happens when statically linking PIC code, or when
5632 using -Bsymbolic. */
5636 relocation = (htab->splt->output_section->vma
5637 + htab->splt->output_offset
5639 unresolved_reloc = false;
5642 /* TOC16 relocs. We want the offset relative to the TOC base,
5643 which is the address of the start of the TOC plus 0x8000.
5644 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5647 case R_PPC64_TOC16_LO:
5648 case R_PPC64_TOC16_HI:
5649 case R_PPC64_TOC16_DS:
5650 case R_PPC64_TOC16_LO_DS:
5651 case R_PPC64_TOC16_HA:
5652 addend -= TOCstart + TOC_BASE_OFF;
5655 /* Relocate against the beginning of the section. */
5656 case R_PPC64_SECTOFF:
5657 case R_PPC64_SECTOFF_LO:
5658 case R_PPC64_SECTOFF_HI:
5659 case R_PPC64_SECTOFF_DS:
5660 case R_PPC64_SECTOFF_LO_DS:
5661 case R_PPC64_SECTOFF_HA:
5662 if (sec != (asection *) 0)
5663 addend -= sec->output_section->vma;
5667 case R_PPC64_REL14_BRNTAKEN:
5668 case R_PPC64_REL14_BRTAKEN:
5672 /* Relocations that may need to be propagated if this is a
5676 case R_PPC64_ADDR14:
5677 case R_PPC64_ADDR14_BRNTAKEN:
5678 case R_PPC64_ADDR14_BRTAKEN:
5679 case R_PPC64_ADDR16:
5680 case R_PPC64_ADDR16_DS:
5681 case R_PPC64_ADDR16_HA:
5682 case R_PPC64_ADDR16_HI:
5683 case R_PPC64_ADDR16_HIGHER:
5684 case R_PPC64_ADDR16_HIGHERA:
5685 case R_PPC64_ADDR16_HIGHEST:
5686 case R_PPC64_ADDR16_HIGHESTA:
5687 case R_PPC64_ADDR16_LO:
5688 case R_PPC64_ADDR16_LO_DS:
5689 case R_PPC64_ADDR24:
5690 case R_PPC64_ADDR30:
5691 case R_PPC64_ADDR32:
5692 case R_PPC64_ADDR64:
5693 case R_PPC64_UADDR16:
5694 case R_PPC64_UADDR32:
5695 case R_PPC64_UADDR64:
5696 /* r_symndx will be zero only for relocs against symbols
5697 from removed linkonce sections, or sections discarded by
5704 if ((input_section->flags & SEC_ALLOC) == 0)
5707 if (NO_OPD_RELOCS && is_opd)
5711 && (IS_ABSOLUTE_RELOC (r_type)
5714 && (! info->symbolic
5715 || (h->elf_link_hash_flags
5716 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
5720 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5721 && (((h->elf_link_hash_flags
5722 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5723 && (h->elf_link_hash_flags
5724 & ELF_LINK_HASH_DEF_REGULAR) == 0)
5725 || h->root.type == bfd_link_hash_undefweak
5726 || h->root.type == bfd_link_hash_undefined)))
5728 Elf_Internal_Rela outrel;
5729 boolean skip, relocate;
5731 Elf64_External_Rela *loc;
5733 /* When generating a dynamic object, these relocations
5734 are copied into the output file to be resolved at run
5741 _bfd_elf_section_offset (output_bfd, info, input_section,
5743 if (outrel.r_offset == (bfd_vma) -1)
5745 else if (outrel.r_offset == (bfd_vma) -2)
5746 skip = true, relocate = true;
5747 outrel.r_offset += (input_section->output_section->vma
5748 + input_section->output_offset);
5749 outrel.r_addend = addend;
5752 memset (&outrel, 0, sizeof outrel);
5756 && (!IS_ABSOLUTE_RELOC (r_type)
5759 || (h->elf_link_hash_flags
5760 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5761 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
5764 /* This symbol is local, or marked to become local,
5765 or this is an opd section reloc which must point
5766 at a local function. */
5767 outrel.r_addend += relocation;
5769 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
5771 if (is_opd && h != NULL)
5773 /* Lie about opd entries. This case occurs
5774 when building shared libraries and we
5775 reference a function in another shared
5776 lib. The same thing happens for a weak
5777 definition in an application that's
5778 overridden by a strong definition in a
5779 shared lib. (I believe this is a generic
5780 bug in binutils handling of weak syms.)
5781 In these cases we won't use the opd
5782 entry in this lib. */
5783 unresolved_reloc = false;
5785 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5791 if (bfd_is_abs_section (sec))
5793 else if (sec == NULL || sec->owner == NULL)
5795 bfd_set_error (bfd_error_bad_value);
5802 osec = sec->output_section;
5803 indx = elf_section_data (osec)->dynindx;
5805 /* We are turning this relocation into one
5806 against a section symbol, so subtract out
5807 the output section's address but not the
5808 offset of the input section in the output
5810 outrel.r_addend -= osec->vma;
5813 outrel.r_info = ELF64_R_INFO (indx, r_type);
5817 sreloc = elf_section_data (input_section)->sreloc;
5821 loc = (Elf64_External_Rela *) sreloc->contents;
5822 loc += sreloc->reloc_count++;
5823 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5825 /* If this reloc is against an external symbol, it will
5826 be computed at runtime, so there's no need to do
5834 case R_PPC64_GLOB_DAT:
5835 case R_PPC64_JMP_SLOT:
5836 case R_PPC64_RELATIVE:
5837 /* We shouldn't ever see these dynamic relocs in relocatable
5841 case R_PPC64_PLTGOT16:
5842 case R_PPC64_PLTGOT16_DS:
5843 case R_PPC64_PLTGOT16_HA:
5844 case R_PPC64_PLTGOT16_HI:
5845 case R_PPC64_PLTGOT16_LO:
5846 case R_PPC64_PLTGOT16_LO_DS:
5847 case R_PPC64_PLTREL32:
5848 case R_PPC64_PLTREL64:
5849 /* These ones haven't been implemented yet. */
5851 (*_bfd_error_handler)
5852 (_("%s: Relocation %s is not supported for symbol %s."),
5853 bfd_archive_filename (input_bfd),
5854 ppc64_elf_howto_table[(int) r_type]->name, sym_name);
5856 bfd_set_error (bfd_error_invalid_operation);
5861 /* Do any further special processing. */
5867 case R_PPC64_ADDR16_HA:
5868 case R_PPC64_ADDR16_HIGHERA:
5869 case R_PPC64_ADDR16_HIGHESTA:
5870 case R_PPC64_PLT16_HA:
5871 case R_PPC64_TOC16_HA:
5872 case R_PPC64_SECTOFF_HA:
5873 /* It's just possible that this symbol is a weak symbol
5874 that's not actually defined anywhere. In that case,
5875 'sec' would be NULL, and we should leave the symbol
5876 alone (it will be set to zero elsewhere in the link). */
5878 /* Add 0x10000 if sign bit in 0:15 is set. */
5879 addend += ((relocation + addend) & 0x8000) << 1;
5882 case R_PPC64_ADDR16_DS:
5883 case R_PPC64_ADDR16_LO_DS:
5884 case R_PPC64_GOT16_DS:
5885 case R_PPC64_GOT16_LO_DS:
5886 case R_PPC64_PLT16_LO_DS:
5887 case R_PPC64_SECTOFF_DS:
5888 case R_PPC64_SECTOFF_LO_DS:
5889 case R_PPC64_TOC16_DS:
5890 case R_PPC64_TOC16_LO_DS:
5891 case R_PPC64_PLTGOT16_DS:
5892 case R_PPC64_PLTGOT16_LO_DS:
5893 if (((relocation + addend) & 3) != 0)
5895 (*_bfd_error_handler)
5896 (_("%s: error: relocation %s not a multiple of 4"),
5897 bfd_archive_filename (input_bfd),
5898 ppc64_elf_howto_table[(int) r_type]->name);
5899 bfd_set_error (bfd_error_bad_value);
5906 case R_PPC64_REL14_BRNTAKEN:
5907 case R_PPC64_REL14_BRTAKEN:
5908 max_br_offset = 1 << 15;
5912 max_br_offset = 1 << 25;
5915 /* If the branch is out of reach, then redirect the
5916 call to the local stub for this function. */
5918 + input_section->output_offset
5919 + input_section->output_section->vma);
5920 if (relocation + addend - from + max_br_offset >= 2 * max_br_offset
5921 && (stub_entry = ppc_get_stub_entry (input_section, sec, h,
5922 rel, htab)) != NULL)
5924 /* Munge up the value and addend so that we call the stub
5925 rather than the procedure directly. */
5926 relocation = (stub_entry->stub_offset
5927 + stub_entry->stub_sec->output_offset
5928 + stub_entry->stub_sec->output_section->vma);
5934 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5935 because such sections are not SEC_ALLOC and thus ld.so will
5936 not process them. */
5937 if (unresolved_reloc
5938 && !((input_section->flags & SEC_DEBUGGING) != 0
5939 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5941 (*_bfd_error_handler)
5942 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5943 bfd_archive_filename (input_bfd),
5944 bfd_get_section_name (input_bfd, input_section),
5945 (long) rel->r_offset,
5946 h->root.root.string);
5950 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
5958 if (r != bfd_reloc_ok)
5964 if (h->root.type == bfd_link_hash_undefweak
5965 && ppc64_elf_howto_table[(int) r_type]->pc_relative)
5967 /* Assume this is a call protected by other code that
5968 detects the symbol is undefined. If this is the case,
5969 we can safely ignore the overflow. If not, the
5970 program is hosed anyway, and a little warning isn't
5976 name = h->root.root.string;
5980 name = bfd_elf_string_from_elf_section (input_bfd,
5981 symtab_hdr->sh_link,
5986 name = bfd_section_name (input_bfd, sec);
5989 if (r == bfd_reloc_overflow)
5993 if (!((*info->callbacks->reloc_overflow)
5994 (info, name, ppc64_elf_howto_table[(int) r_type]->name,
5995 rel->r_addend, input_bfd, input_section, offset)))
6000 (*_bfd_error_handler)
6001 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
6002 bfd_archive_filename (input_bfd),
6003 bfd_get_section_name (input_bfd, input_section),
6004 (long) rel->r_offset, name, (int) r);
6013 /* Finish up dynamic symbol handling. We set the contents of various
6014 dynamic sections here. */
6017 ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
6019 struct bfd_link_info *info;
6020 struct elf_link_hash_entry *h;
6021 Elf_Internal_Sym *sym;
6023 struct ppc_link_hash_table *htab;
6026 htab = ppc_hash_table (info);
6027 dynobj = htab->elf.dynobj;
6029 if (h->plt.offset != (bfd_vma) -1
6030 && ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
6032 Elf_Internal_Rela rela;
6033 Elf64_External_Rela *loc;
6035 /* This symbol has an entry in the procedure linkage table. Set
6038 if (htab->splt == NULL
6039 || htab->srelplt == NULL
6040 || htab->sglink == NULL)
6043 /* Create a JMP_SLOT reloc to inform the dynamic linker to
6044 fill in the PLT entry. */
6046 rela.r_offset = (htab->splt->output_section->vma
6047 + htab->splt->output_offset
6049 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
6052 loc = (Elf64_External_Rela *) htab->srelplt->contents;
6053 loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
6054 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
6057 if (h->got.offset != (bfd_vma) -1)
6059 Elf_Internal_Rela rela;
6060 Elf64_External_Rela *loc;
6062 /* This symbol has an entry in the global offset table. Set it
6065 if (htab->sgot == NULL || htab->srelgot == NULL)
6068 rela.r_offset = (htab->sgot->output_section->vma
6069 + htab->sgot->output_offset
6070 + (h->got.offset &~ (bfd_vma) 1));
6072 /* If this is a static link, or it is a -Bsymbolic link and the
6073 symbol is defined locally or was forced to be local because
6074 of a version file, we just want to emit a RELATIVE reloc.
6075 The entry in the global offset table will already have been
6076 initialized in the relocate_section function. */
6080 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
6081 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
6083 BFD_ASSERT((h->got.offset & 1) != 0);
6084 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
6085 rela.r_addend = (h->root.u.def.value
6086 + h->root.u.def.section->output_section->vma
6087 + h->root.u.def.section->output_offset);
6091 BFD_ASSERT ((h->got.offset & 1) == 0);
6092 bfd_put_64 (output_bfd, (bfd_vma) 0,
6093 htab->sgot->contents + h->got.offset);
6094 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
6098 loc = (Elf64_External_Rela *) htab->srelgot->contents;
6099 loc += htab->srelgot->reloc_count++;
6100 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
6103 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
6105 Elf_Internal_Rela rela;
6106 Elf64_External_Rela *loc;
6108 /* This symbol needs a copy reloc. Set it up. */
6110 if (h->dynindx == -1
6111 || (h->root.type != bfd_link_hash_defined
6112 && h->root.type != bfd_link_hash_defweak)
6113 || htab->srelbss == NULL)
6116 rela.r_offset = (h->root.u.def.value
6117 + h->root.u.def.section->output_section->vma
6118 + h->root.u.def.section->output_offset);
6119 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
6121 loc = (Elf64_External_Rela *) htab->srelbss->contents;
6122 loc += htab->srelbss->reloc_count++;
6123 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
6126 /* Mark some specially defined symbols as absolute. */
6127 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
6128 sym->st_shndx = SHN_ABS;
6133 /* Used to decide how to sort relocs in an optimal manner for the
6134 dynamic linker, before writing them out. */
6136 static enum elf_reloc_type_class
6137 ppc64_elf_reloc_type_class (rela)
6138 const Elf_Internal_Rela *rela;
6140 enum elf_ppc_reloc_type r_type;
6142 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
6145 case R_PPC64_RELATIVE:
6146 return reloc_class_relative;
6147 case R_PPC64_JMP_SLOT:
6148 return reloc_class_plt;
6150 return reloc_class_copy;
6152 return reloc_class_normal;
6156 /* Finish up the dynamic sections. */
6159 ppc64_elf_finish_dynamic_sections (output_bfd, info)
6161 struct bfd_link_info *info;
6163 struct ppc_link_hash_table *htab;
6167 htab = ppc_hash_table (info);
6168 dynobj = htab->elf.dynobj;
6169 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6171 if (htab->elf.dynamic_sections_created)
6173 Elf64_External_Dyn *dyncon, *dynconend;
6175 if (sdyn == NULL || htab->sgot == NULL)
6178 dyncon = (Elf64_External_Dyn *) sdyn->contents;
6179 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
6180 for (; dyncon < dynconend; dyncon++)
6182 Elf_Internal_Dyn dyn;
6185 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
6192 case DT_PPC64_GLINK:
6193 dyn.d_un.d_ptr = (htab->sglink->output_section->vma
6194 + htab->sglink->output_offset);
6198 s = bfd_get_section_by_name (output_bfd, ".opd");
6200 dyn.d_un.d_ptr = s->vma;
6203 case DT_PPC64_OPDSZ:
6204 s = bfd_get_section_by_name (output_bfd, ".opd");
6206 dyn.d_un.d_val = s->_raw_size;
6210 dyn.d_un.d_ptr = (htab->splt->output_section->vma
6211 + htab->splt->output_offset);
6215 dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
6216 + htab->srelplt->output_offset);
6220 dyn.d_un.d_val = htab->srelplt->_raw_size;
6224 /* Don't count procedure linkage table relocs in the
6225 overall reloc count. */
6226 if (htab->srelplt != NULL)
6227 dyn.d_un.d_val -= htab->srelplt->_raw_size;
6231 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
6235 if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
6237 /* Fill in the first entry in the global offset table.
6238 We use it to hold the link-time TOCbase. */
6239 bfd_put_64 (output_bfd,
6240 elf_gp (output_bfd) + TOC_BASE_OFF,
6241 htab->sgot->contents);
6243 /* Set .got entry size. */
6244 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
6247 if (htab->splt != NULL && htab->splt->_raw_size != 0)
6249 /* Set .plt entry size. */
6250 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
6257 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6258 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6259 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6260 #define TARGET_BIG_NAME "elf64-powerpc"
6261 #define ELF_ARCH bfd_arch_powerpc
6262 #define ELF_MACHINE_CODE EM_PPC64
6263 #define ELF_MAXPAGESIZE 0x10000
6264 #define elf_info_to_howto ppc64_elf_info_to_howto
6266 #ifdef EM_CYGNUS_POWERPC
6267 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6271 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6274 #define elf_backend_want_got_sym 0
6275 #define elf_backend_want_plt_sym 0
6276 #define elf_backend_plt_alignment 3
6277 #define elf_backend_plt_not_loaded 1
6278 #define elf_backend_got_symbol_offset 0
6279 #define elf_backend_got_header_size 8
6280 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6281 #define elf_backend_can_gc_sections 1
6282 #define elf_backend_can_refcount 1
6283 #define elf_backend_rela_normal 1
6285 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6286 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6287 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6288 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6290 #define elf_backend_object_p ppc64_elf_object_p
6291 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6292 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6293 #define elf_backend_check_relocs ppc64_elf_check_relocs
6294 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6295 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6296 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6297 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6298 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6299 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6300 #define elf_backend_relocate_section ppc64_elf_relocate_section
6301 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6302 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6303 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6305 #include "elf64-target.h"