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_set_private_flags
59 PARAMS ((bfd *, flagword));
60 static boolean ppc64_elf_merge_private_bfd_data
61 PARAMS ((bfd *, bfd *));
62 static boolean ppc64_elf_section_from_shdr
63 PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
66 /* Mask to set RA in memory instructions. */
67 #define RA_REGISTER_MASK 0x001f0000
69 /* Value to shift register by to insert RA. */
70 #define RA_REGISTER_SHIFT 16
72 /* The name of the dynamic interpreter. This is put in the .interp
74 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
76 /* The size in bytes of an entry in the procedure linkage table. */
77 #define PLT_ENTRY_SIZE 24
79 /* The initial size of the plt reserved for the dynamic linker. */
80 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
82 /* TOC base pointers offset from start of TOC. */
83 #define TOC_BASE_OFF (0x8000)
85 /* .plt call stub instructions. */
86 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
87 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
88 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
89 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
90 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
91 /* ld %r11,xxx+16@l(%r12) */
92 #define BCTR 0x4e800420 /* bctr */
94 /* The normal stub is this size. */
95 #define PLT_CALL_STUB_SIZE (7*4)
97 /* But sometimes the .plt entry crosses a 64k boundary, and we need
98 to adjust the high word with this insn. */
99 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
101 /* The .glink fixup call stub is the same as the .plt call stub, but
102 the first instruction restores r2, and the std is omitted. */
103 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
105 /* Always allow this much space. */
106 #define GLINK_CALL_STUB_SIZE (8*4)
109 #define NOP 0x60000000
111 /* Some other nops. */
112 #define CROR_151515 0x4def7b82
113 #define CROR_313131 0x4ffffb82
115 /* .glink entries for the first 32k functions are two instructions. */
116 #define LI_R0_0 0x38000000 /* li %r0,0 */
117 #define B_DOT 0x48000000 /* b . */
119 /* After that, we need two instructions to load the index, followed by
121 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
122 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
124 /* Instructions to save and restore floating point regs. */
125 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
126 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
127 #define BLR 0x4e800020 /* blr */
129 /* Since .opd is an array of descriptors and each entry will end up
130 with identical R_PPC64_RELATIVE relocs, there is really no need to
131 propagate .opd relocs; The dynamic linker should be taught to
132 relocate .opd without reloc entries. FIXME: .opd should be trimmed
134 #ifndef NO_OPD_RELOCS
135 #define NO_OPD_RELOCS 0
138 /* Relocation HOWTO's. */
139 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
141 static reloc_howto_type ppc64_elf_howto_raw[] = {
142 /* This reloc does nothing. */
143 HOWTO (R_PPC64_NONE, /* type */
145 2, /* size (0 = byte, 1 = short, 2 = long) */
147 false, /* pc_relative */
149 complain_overflow_bitfield, /* complain_on_overflow */
150 bfd_elf_generic_reloc, /* special_function */
151 "R_PPC64_NONE", /* name */
152 false, /* partial_inplace */
155 false), /* pcrel_offset */
157 /* A standard 32 bit relocation. */
158 HOWTO (R_PPC64_ADDR32, /* type */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 false, /* pc_relative */
164 complain_overflow_bitfield, /* complain_on_overflow */
165 bfd_elf_generic_reloc, /* special_function */
166 "R_PPC64_ADDR32", /* name */
167 false, /* partial_inplace */
169 0xffffffff, /* dst_mask */
170 false), /* pcrel_offset */
172 /* An absolute 26 bit branch; the lower two bits must be zero.
173 FIXME: we don't check that, we just clear them. */
174 HOWTO (R_PPC64_ADDR24, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 false, /* pc_relative */
180 complain_overflow_bitfield, /* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_PPC64_ADDR24", /* name */
183 false, /* partial_inplace */
185 0x3fffffc, /* dst_mask */
186 false), /* pcrel_offset */
188 /* A standard 16 bit relocation. */
189 HOWTO (R_PPC64_ADDR16, /* type */
191 1, /* size (0 = byte, 1 = short, 2 = long) */
193 false, /* pc_relative */
195 complain_overflow_bitfield, /* complain_on_overflow */
196 bfd_elf_generic_reloc, /* special_function */
197 "R_PPC64_ADDR16", /* name */
198 false, /* partial_inplace */
200 0xffff, /* dst_mask */
201 false), /* pcrel_offset */
203 /* A 16 bit relocation without overflow. */
204 HOWTO (R_PPC64_ADDR16_LO, /* type */
206 1, /* size (0 = byte, 1 = short, 2 = long) */
208 false, /* pc_relative */
210 complain_overflow_dont,/* complain_on_overflow */
211 bfd_elf_generic_reloc, /* special_function */
212 "R_PPC64_ADDR16_LO", /* name */
213 false, /* partial_inplace */
215 0xffff, /* dst_mask */
216 false), /* pcrel_offset */
218 /* Bits 16-31 of an address. */
219 HOWTO (R_PPC64_ADDR16_HI, /* type */
221 1, /* size (0 = byte, 1 = short, 2 = long) */
223 false, /* pc_relative */
225 complain_overflow_dont, /* complain_on_overflow */
226 bfd_elf_generic_reloc, /* special_function */
227 "R_PPC64_ADDR16_HI", /* name */
228 false, /* partial_inplace */
230 0xffff, /* dst_mask */
231 false), /* pcrel_offset */
233 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
234 bits, treated as a signed number, is negative. */
235 HOWTO (R_PPC64_ADDR16_HA, /* type */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
239 false, /* pc_relative */
241 complain_overflow_dont, /* complain_on_overflow */
242 ppc64_elf_ha_reloc, /* special_function */
243 "R_PPC64_ADDR16_HA", /* name */
244 false, /* partial_inplace */
246 0xffff, /* dst_mask */
247 false), /* pcrel_offset */
249 /* An absolute 16 bit branch; the lower two bits must be zero.
250 FIXME: we don't check that, we just clear them. */
251 HOWTO (R_PPC64_ADDR14, /* type */
253 2, /* size (0 = byte, 1 = short, 2 = long) */
255 false, /* pc_relative */
257 complain_overflow_bitfield, /* complain_on_overflow */
258 bfd_elf_generic_reloc, /* special_function */
259 "R_PPC64_ADDR14", /* name */
260 false, /* partial_inplace */
262 0xfffc, /* dst_mask */
263 false), /* pcrel_offset */
265 /* An absolute 16 bit branch, for which bit 10 should be set to
266 indicate that the branch is expected to be taken. The lower two
267 bits must be zero. */
268 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
272 false, /* pc_relative */
274 complain_overflow_bitfield, /* complain_on_overflow */
275 ppc64_elf_brtaken_reloc, /* special_function */
276 "R_PPC64_ADDR14_BRTAKEN",/* name */
277 false, /* partial_inplace */
279 0xfffc, /* dst_mask */
280 false), /* pcrel_offset */
282 /* An absolute 16 bit branch, for which bit 10 should be set to
283 indicate that the branch is not expected to be taken. The lower
284 two bits must be zero. */
285 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
287 2, /* size (0 = byte, 1 = short, 2 = long) */
289 false, /* pc_relative */
291 complain_overflow_bitfield, /* complain_on_overflow */
292 ppc64_elf_brtaken_reloc, /* special_function */
293 "R_PPC64_ADDR14_BRNTAKEN",/* name */
294 false, /* partial_inplace */
296 0xfffc, /* dst_mask */
297 false), /* pcrel_offset */
299 /* A relative 26 bit branch; the lower two bits must be zero. */
300 HOWTO (R_PPC64_REL24, /* type */
302 2, /* size (0 = byte, 1 = short, 2 = long) */
304 true, /* pc_relative */
306 complain_overflow_signed, /* complain_on_overflow */
307 bfd_elf_generic_reloc, /* special_function */
308 "R_PPC64_REL24", /* name */
309 false, /* partial_inplace */
311 0x3fffffc, /* dst_mask */
312 true), /* pcrel_offset */
314 /* A relative 16 bit branch; the lower two bits must be zero. */
315 HOWTO (R_PPC64_REL14, /* type */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
319 true, /* pc_relative */
321 complain_overflow_signed, /* complain_on_overflow */
322 bfd_elf_generic_reloc, /* special_function */
323 "R_PPC64_REL14", /* name */
324 false, /* partial_inplace */
326 0xfffc, /* dst_mask */
327 true), /* pcrel_offset */
329 /* A relative 16 bit branch. Bit 10 should be set to indicate that
330 the branch is expected to be taken. The lower two bits must be
332 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
334 2, /* size (0 = byte, 1 = short, 2 = long) */
336 true, /* pc_relative */
338 complain_overflow_signed, /* complain_on_overflow */
339 ppc64_elf_brtaken_reloc, /* special_function */
340 "R_PPC64_REL14_BRTAKEN", /* name */
341 false, /* partial_inplace */
343 0xfffc, /* dst_mask */
344 true), /* pcrel_offset */
346 /* A relative 16 bit branch. Bit 10 should be set to indicate that
347 the branch is not expected to be taken. The lower two bits must
349 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 true, /* pc_relative */
355 complain_overflow_signed, /* complain_on_overflow */
356 ppc64_elf_brtaken_reloc, /* special_function */
357 "R_PPC64_REL14_BRNTAKEN",/* name */
358 false, /* partial_inplace */
360 0xfffc, /* dst_mask */
361 true), /* pcrel_offset */
363 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
365 HOWTO (R_PPC64_GOT16, /* type */
367 1, /* size (0 = byte, 1 = short, 2 = long) */
369 false, /* pc_relative */
371 complain_overflow_signed, /* complain_on_overflow */
372 ppc64_elf_unhandled_reloc, /* special_function */
373 "R_PPC64_GOT16", /* name */
374 false, /* partial_inplace */
376 0xffff, /* dst_mask */
377 false), /* pcrel_offset */
379 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
381 HOWTO (R_PPC64_GOT16_LO, /* type */
383 1, /* size (0 = byte, 1 = short, 2 = long) */
385 false, /* pc_relative */
387 complain_overflow_dont, /* complain_on_overflow */
388 ppc64_elf_unhandled_reloc, /* special_function */
389 "R_PPC64_GOT16_LO", /* name */
390 false, /* partial_inplace */
392 0xffff, /* dst_mask */
393 false), /* pcrel_offset */
395 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
397 HOWTO (R_PPC64_GOT16_HI, /* type */
399 1, /* size (0 = byte, 1 = short, 2 = long) */
401 false, /* pc_relative */
403 complain_overflow_dont,/* complain_on_overflow */
404 ppc64_elf_unhandled_reloc, /* special_function */
405 "R_PPC64_GOT16_HI", /* name */
406 false, /* partial_inplace */
408 0xffff, /* dst_mask */
409 false), /* pcrel_offset */
411 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
413 HOWTO (R_PPC64_GOT16_HA, /* type */
415 1, /* size (0 = byte, 1 = short, 2 = long) */
417 false, /* pc_relative */
419 complain_overflow_dont,/* complain_on_overflow */
420 ppc64_elf_unhandled_reloc, /* special_function */
421 "R_PPC64_GOT16_HA", /* name */
422 false, /* partial_inplace */
424 0xffff, /* dst_mask */
425 false), /* pcrel_offset */
427 /* This is used only by the dynamic linker. The symbol should exist
428 both in the object being run and in some shared library. The
429 dynamic linker copies the data addressed by the symbol from the
430 shared library into the object, because the object being
431 run has to have the data at some particular address. */
432 HOWTO (R_PPC64_COPY, /* type */
434 2, /* size (0 = byte, 1 = short, 2 = long) */
436 false, /* pc_relative */
438 complain_overflow_bitfield, /* complain_on_overflow */
439 ppc64_elf_unhandled_reloc, /* special_function */
440 "R_PPC64_COPY", /* name */
441 false, /* partial_inplace */
444 false), /* pcrel_offset */
446 /* Like R_PPC64_ADDR64, but used when setting global offset table
448 HOWTO (R_PPC64_GLOB_DAT, /* type */
450 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
452 false, /* pc_relative */
454 complain_overflow_dont, /* complain_on_overflow */
455 ppc64_elf_unhandled_reloc, /* special_function */
456 "R_PPC64_GLOB_DAT", /* name */
457 false, /* partial_inplace */
459 0xffffffffffffffff, /* dst_mask */
460 false), /* pcrel_offset */
462 /* Created by the link editor. Marks a procedure linkage table
463 entry for a symbol. */
464 HOWTO (R_PPC64_JMP_SLOT, /* type */
466 0, /* size (0 = byte, 1 = short, 2 = long) */
468 false, /* pc_relative */
470 complain_overflow_dont, /* complain_on_overflow */
471 ppc64_elf_unhandled_reloc, /* special_function */
472 "R_PPC64_JMP_SLOT", /* name */
473 false, /* partial_inplace */
476 false), /* pcrel_offset */
478 /* Used only by the dynamic linker. When the object is run, this
479 doubleword64 is set to the load address of the object, plus the
481 HOWTO (R_PPC64_RELATIVE, /* type */
483 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
485 true, /* pc_relative */
487 complain_overflow_dont, /* complain_on_overflow */
488 bfd_elf_generic_reloc, /* special_function */
489 "R_PPC64_RELATIVE", /* name */
490 false, /* partial_inplace */
492 0xffffffffffffffff, /* dst_mask */
493 true), /* pcrel_offset */
495 /* Like R_PPC64_ADDR32, but may be unaligned. */
496 HOWTO (R_PPC64_UADDR32, /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 false, /* pc_relative */
502 complain_overflow_bitfield, /* complain_on_overflow */
503 bfd_elf_generic_reloc, /* special_function */
504 "R_PPC64_UADDR32", /* name */
505 false, /* partial_inplace */
507 0xffffffff, /* dst_mask */
508 false), /* pcrel_offset */
510 /* Like R_PPC64_ADDR16, but may be unaligned. */
511 HOWTO (R_PPC64_UADDR16, /* type */
513 1, /* size (0 = byte, 1 = short, 2 = long) */
515 false, /* pc_relative */
517 complain_overflow_bitfield, /* complain_on_overflow */
518 bfd_elf_generic_reloc, /* special_function */
519 "R_PPC64_UADDR16", /* name */
520 false, /* partial_inplace */
522 0xffff, /* dst_mask */
523 false), /* pcrel_offset */
525 /* 32-bit PC relative. */
526 HOWTO (R_PPC64_REL32, /* type */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 true, /* pc_relative */
532 /* FIXME: Verify. Was complain_overflow_bitfield. */
533 complain_overflow_signed, /* complain_on_overflow */
534 bfd_elf_generic_reloc, /* special_function */
535 "R_PPC64_REL32", /* name */
536 false, /* partial_inplace */
538 0xffffffff, /* dst_mask */
539 true), /* pcrel_offset */
541 /* 32-bit relocation to the symbol's procedure linkage table. */
542 HOWTO (R_PPC64_PLT32, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 false, /* pc_relative */
548 complain_overflow_bitfield, /* complain_on_overflow */
549 ppc64_elf_unhandled_reloc, /* special_function */
550 "R_PPC64_PLT32", /* name */
551 false, /* partial_inplace */
554 false), /* pcrel_offset */
556 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
557 FIXME: R_PPC64_PLTREL32 not supported. */
558 HOWTO (R_PPC64_PLTREL32, /* type */
560 2, /* size (0 = byte, 1 = short, 2 = long) */
562 true, /* pc_relative */
564 complain_overflow_signed, /* complain_on_overflow */
565 bfd_elf_generic_reloc, /* special_function */
566 "R_PPC64_PLTREL32", /* name */
567 false, /* partial_inplace */
570 true), /* pcrel_offset */
572 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
574 HOWTO (R_PPC64_PLT16_LO, /* type */
576 1, /* size (0 = byte, 1 = short, 2 = long) */
578 false, /* pc_relative */
580 complain_overflow_dont, /* complain_on_overflow */
581 ppc64_elf_unhandled_reloc, /* special_function */
582 "R_PPC64_PLT16_LO", /* name */
583 false, /* partial_inplace */
585 0xffff, /* dst_mask */
586 false), /* pcrel_offset */
588 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
590 HOWTO (R_PPC64_PLT16_HI, /* type */
592 1, /* size (0 = byte, 1 = short, 2 = long) */
594 false, /* pc_relative */
596 complain_overflow_dont, /* complain_on_overflow */
597 ppc64_elf_unhandled_reloc, /* special_function */
598 "R_PPC64_PLT16_HI", /* name */
599 false, /* partial_inplace */
601 0xffff, /* dst_mask */
602 false), /* pcrel_offset */
604 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
606 HOWTO (R_PPC64_PLT16_HA, /* type */
608 1, /* size (0 = byte, 1 = short, 2 = long) */
610 false, /* pc_relative */
612 complain_overflow_dont, /* complain_on_overflow */
613 ppc64_elf_unhandled_reloc, /* special_function */
614 "R_PPC64_PLT16_HA", /* name */
615 false, /* partial_inplace */
617 0xffff, /* dst_mask */
618 false), /* pcrel_offset */
620 /* 32-bit section relative relocation. */
621 HOWTO (R_PPC64_SECTOFF, /* type */
623 2, /* size (0 = byte, 1 = short, 2 = long) */
625 false, /* pc_relative */
627 complain_overflow_bitfield, /* complain_on_overflow */
628 ppc64_elf_sectoff_reloc, /* special_function */
629 "R_PPC64_SECTOFF", /* name */
630 false, /* partial_inplace */
632 0xffffffff, /* dst_mask */
633 false), /* pcrel_offset */
635 /* 16-bit lower half section relative relocation. */
636 HOWTO (R_PPC64_SECTOFF_LO, /* type */
638 1, /* size (0 = byte, 1 = short, 2 = long) */
640 false, /* pc_relative */
642 complain_overflow_dont, /* complain_on_overflow */
643 ppc64_elf_sectoff_reloc, /* special_function */
644 "R_PPC64_SECTOFF_LO", /* name */
645 false, /* partial_inplace */
647 0xffff, /* dst_mask */
648 false), /* pcrel_offset */
650 /* 16-bit upper half section relative relocation. */
651 HOWTO (R_PPC64_SECTOFF_HI, /* type */
653 1, /* size (0 = byte, 1 = short, 2 = long) */
655 false, /* pc_relative */
657 complain_overflow_dont, /* complain_on_overflow */
658 ppc64_elf_sectoff_reloc, /* special_function */
659 "R_PPC64_SECTOFF_HI", /* name */
660 false, /* partial_inplace */
662 0xffff, /* dst_mask */
663 false), /* pcrel_offset */
665 /* 16-bit upper half adjusted section relative relocation. */
666 HOWTO (R_PPC64_SECTOFF_HA, /* type */
668 1, /* size (0 = byte, 1 = short, 2 = long) */
670 false, /* pc_relative */
672 complain_overflow_dont, /* complain_on_overflow */
673 ppc64_elf_sectoff_ha_reloc, /* special_function */
674 "R_PPC64_SECTOFF_HA", /* name */
675 false, /* partial_inplace */
677 0xffff, /* dst_mask */
678 false), /* pcrel_offset */
680 /* Like R_PPC64_REL24 without touching the two least significant
681 bits. Should have been named R_PPC64_REL30! */
682 HOWTO (R_PPC64_ADDR30, /* type */
684 2, /* size (0 = byte, 1 = short, 2 = long) */
686 true, /* pc_relative */
688 complain_overflow_dont, /* complain_on_overflow */
689 bfd_elf_generic_reloc, /* special_function */
690 "R_PPC64_ADDR30", /* name */
691 false, /* partial_inplace */
693 0xfffffffc, /* dst_mask */
694 true), /* pcrel_offset */
696 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
698 /* A standard 64-bit relocation. */
699 HOWTO (R_PPC64_ADDR64, /* type */
701 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
703 false, /* pc_relative */
705 complain_overflow_dont, /* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_PPC64_ADDR64", /* name */
708 false, /* partial_inplace */
710 0xffffffffffffffff, /* dst_mask */
711 false), /* pcrel_offset */
713 /* The bits 32-47 of an address. */
714 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
716 1, /* size (0 = byte, 1 = short, 2 = long) */
718 false, /* pc_relative */
720 complain_overflow_dont, /* complain_on_overflow */
721 bfd_elf_generic_reloc, /* special_function */
722 "R_PPC64_ADDR16_HIGHER", /* name */
723 false, /* partial_inplace */
725 0xffff, /* dst_mask */
726 false), /* pcrel_offset */
728 /* The bits 32-47 of an address, plus 1 if the contents of the low
729 16 bits, treated as a signed number, is negative. */
730 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
732 1, /* size (0 = byte, 1 = short, 2 = long) */
734 false, /* pc_relative */
736 complain_overflow_dont, /* complain_on_overflow */
737 ppc64_elf_ha_reloc, /* special_function */
738 "R_PPC64_ADDR16_HIGHERA", /* name */
739 false, /* partial_inplace */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
744 /* The bits 48-63 of an address. */
745 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
747 1, /* size (0 = byte, 1 = short, 2 = long) */
749 false, /* pc_relative */
751 complain_overflow_dont, /* complain_on_overflow */
752 bfd_elf_generic_reloc, /* special_function */
753 "R_PPC64_ADDR16_HIGHEST", /* name */
754 false, /* partial_inplace */
756 0xffff, /* dst_mask */
757 false), /* pcrel_offset */
759 /* The bits 48-63 of an address, plus 1 if the contents of the low
760 16 bits, treated as a signed number, is negative. */
761 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
763 1, /* size (0 = byte, 1 = short, 2 = long) */
765 false, /* pc_relative */
767 complain_overflow_dont, /* complain_on_overflow */
768 ppc64_elf_ha_reloc, /* special_function */
769 "R_PPC64_ADDR16_HIGHESTA", /* name */
770 false, /* partial_inplace */
772 0xffff, /* dst_mask */
773 false), /* pcrel_offset */
775 /* Like ADDR64, but may be unaligned. */
776 HOWTO (R_PPC64_UADDR64, /* type */
778 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
780 false, /* pc_relative */
782 complain_overflow_dont, /* complain_on_overflow */
783 bfd_elf_generic_reloc, /* special_function */
784 "R_PPC64_UADDR64", /* name */
785 false, /* partial_inplace */
787 0xffffffffffffffff, /* dst_mask */
788 false), /* pcrel_offset */
790 /* 64-bit relative relocation. */
791 HOWTO (R_PPC64_REL64, /* type */
793 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
795 true, /* pc_relative */
797 complain_overflow_dont, /* complain_on_overflow */
798 bfd_elf_generic_reloc, /* special_function */
799 "R_PPC64_REL64", /* name */
800 false, /* partial_inplace */
802 0xffffffffffffffff, /* dst_mask */
803 true), /* pcrel_offset */
805 /* 64-bit relocation to the symbol's procedure linkage table. */
806 HOWTO (R_PPC64_PLT64, /* type */
808 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
810 false, /* pc_relative */
812 complain_overflow_dont, /* complain_on_overflow */
813 ppc64_elf_unhandled_reloc, /* special_function */
814 "R_PPC64_PLT64", /* name */
815 false, /* partial_inplace */
818 false), /* pcrel_offset */
820 /* 64-bit PC relative relocation to the symbol's procedure linkage
822 /* FIXME: R_PPC64_PLTREL64 not supported. */
823 HOWTO (R_PPC64_PLTREL64, /* type */
825 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
827 true, /* pc_relative */
829 complain_overflow_dont, /* complain_on_overflow */
830 ppc64_elf_unhandled_reloc, /* special_function */
831 "R_PPC64_PLTREL64", /* name */
832 false, /* partial_inplace */
835 true), /* pcrel_offset */
837 /* 16 bit TOC-relative relocation. */
839 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
840 HOWTO (R_PPC64_TOC16, /* type */
842 1, /* size (0 = byte, 1 = short, 2 = long) */
844 false, /* pc_relative */
846 complain_overflow_signed, /* complain_on_overflow */
847 ppc64_elf_toc_reloc, /* special_function */
848 "R_PPC64_TOC16", /* name */
849 false, /* partial_inplace */
851 0xffff, /* dst_mask */
852 false), /* pcrel_offset */
854 /* 16 bit TOC-relative relocation without overflow. */
856 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
857 HOWTO (R_PPC64_TOC16_LO, /* type */
859 1, /* size (0 = byte, 1 = short, 2 = long) */
861 false, /* pc_relative */
863 complain_overflow_dont, /* complain_on_overflow */
864 ppc64_elf_toc_reloc, /* special_function */
865 "R_PPC64_TOC16_LO", /* name */
866 false, /* partial_inplace */
868 0xffff, /* dst_mask */
869 false), /* pcrel_offset */
871 /* 16 bit TOC-relative relocation, high 16 bits. */
873 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
874 HOWTO (R_PPC64_TOC16_HI, /* type */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
878 false, /* pc_relative */
880 complain_overflow_dont, /* complain_on_overflow */
881 ppc64_elf_toc_reloc, /* special_function */
882 "R_PPC64_TOC16_HI", /* name */
883 false, /* partial_inplace */
885 0xffff, /* dst_mask */
886 false), /* pcrel_offset */
888 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
889 contents of the low 16 bits, treated as a signed number, is
892 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
893 HOWTO (R_PPC64_TOC16_HA, /* type */
895 1, /* size (0 = byte, 1 = short, 2 = long) */
897 false, /* pc_relative */
899 complain_overflow_dont, /* complain_on_overflow */
900 ppc64_elf_toc_ha_reloc, /* special_function */
901 "R_PPC64_TOC16_HA", /* name */
902 false, /* partial_inplace */
904 0xffff, /* dst_mask */
905 false), /* pcrel_offset */
907 /* 64-bit relocation; insert value of TOC base (.TOC.). */
909 /* R_PPC64_TOC 51 doubleword64 .TOC. */
910 HOWTO (R_PPC64_TOC, /* type */
912 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
914 false, /* pc_relative */
916 complain_overflow_bitfield, /* complain_on_overflow */
917 ppc64_elf_toc64_reloc, /* special_function */
918 "R_PPC64_TOC", /* name */
919 false, /* partial_inplace */
921 0xffffffffffffffff, /* dst_mask */
922 false), /* pcrel_offset */
924 /* Like R_PPC64_GOT16, but also informs the link editor that the
925 value to relocate may (!) refer to a PLT entry which the link
926 editor (a) may replace with the symbol value. If the link editor
927 is unable to fully resolve the symbol, it may (b) create a PLT
928 entry and store the address to the new PLT entry in the GOT.
929 This permits lazy resolution of function symbols at run time.
930 The link editor may also skip all of this and just (c) emit a
931 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
932 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
933 HOWTO (R_PPC64_PLTGOT16, /* type */
935 1, /* size (0 = byte, 1 = short, 2 = long) */
937 false, /* pc_relative */
939 complain_overflow_signed, /* complain_on_overflow */
940 ppc64_elf_unhandled_reloc, /* special_function */
941 "R_PPC64_PLTGOT16", /* name */
942 false, /* partial_inplace */
944 0xffff, /* dst_mask */
945 false), /* pcrel_offset */
947 /* Like R_PPC64_PLTGOT16, but without overflow. */
948 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
949 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
951 1, /* size (0 = byte, 1 = short, 2 = long) */
953 false, /* pc_relative */
955 complain_overflow_dont, /* complain_on_overflow */
956 ppc64_elf_unhandled_reloc, /* special_function */
957 "R_PPC64_PLTGOT16_LO", /* name */
958 false, /* partial_inplace */
960 0xffff, /* dst_mask */
961 false), /* pcrel_offset */
963 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
964 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
965 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
967 1, /* size (0 = byte, 1 = short, 2 = long) */
969 false, /* pc_relative */
971 complain_overflow_dont, /* complain_on_overflow */
972 ppc64_elf_unhandled_reloc, /* special_function */
973 "R_PPC64_PLTGOT16_HI", /* name */
974 false, /* partial_inplace */
976 0xffff, /* dst_mask */
977 false), /* pcrel_offset */
979 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
980 1 if the contents of the low 16 bits, treated as a signed number,
982 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
983 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
985 1, /* size (0 = byte, 1 = short, 2 = long) */
987 false, /* pc_relative */
989 complain_overflow_dont,/* complain_on_overflow */
990 ppc64_elf_unhandled_reloc, /* special_function */
991 "R_PPC64_PLTGOT16_HA", /* name */
992 false, /* partial_inplace */
994 0xffff, /* dst_mask */
995 false), /* pcrel_offset */
997 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
998 HOWTO (R_PPC64_ADDR16_DS, /* type */
1000 1, /* size (0 = byte, 1 = short, 2 = long) */
1002 false, /* pc_relative */
1004 complain_overflow_bitfield, /* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 "R_PPC64_ADDR16_DS", /* name */
1007 false, /* partial_inplace */
1009 0xfffc, /* dst_mask */
1010 false), /* pcrel_offset */
1012 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1013 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1015 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 false, /* pc_relative */
1019 complain_overflow_dont,/* complain_on_overflow */
1020 bfd_elf_generic_reloc, /* special_function */
1021 "R_PPC64_ADDR16_LO_DS",/* name */
1022 false, /* partial_inplace */
1024 0xfffc, /* dst_mask */
1025 false), /* pcrel_offset */
1027 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1028 HOWTO (R_PPC64_GOT16_DS, /* type */
1030 1, /* size (0 = byte, 1 = short, 2 = long) */
1032 false, /* pc_relative */
1034 complain_overflow_signed, /* complain_on_overflow */
1035 ppc64_elf_unhandled_reloc, /* special_function */
1036 "R_PPC64_GOT16_DS", /* name */
1037 false, /* partial_inplace */
1039 0xfffc, /* dst_mask */
1040 false), /* pcrel_offset */
1042 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1043 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1045 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 false, /* pc_relative */
1049 complain_overflow_dont, /* complain_on_overflow */
1050 ppc64_elf_unhandled_reloc, /* special_function */
1051 "R_PPC64_GOT16_LO_DS", /* name */
1052 false, /* partial_inplace */
1054 0xfffc, /* dst_mask */
1055 false), /* pcrel_offset */
1057 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1058 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 false, /* pc_relative */
1064 complain_overflow_dont, /* complain_on_overflow */
1065 ppc64_elf_unhandled_reloc, /* special_function */
1066 "R_PPC64_PLT16_LO_DS", /* name */
1067 false, /* partial_inplace */
1069 0xfffc, /* dst_mask */
1070 false), /* pcrel_offset */
1072 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1073 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 false, /* pc_relative */
1079 complain_overflow_bitfield, /* complain_on_overflow */
1080 ppc64_elf_sectoff_reloc, /* special_function */
1081 "R_PPC64_SECTOFF_DS", /* name */
1082 false, /* partial_inplace */
1084 0xfffffffc, /* dst_mask */
1085 false), /* pcrel_offset */
1087 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1088 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 false, /* pc_relative */
1094 complain_overflow_dont, /* complain_on_overflow */
1095 ppc64_elf_sectoff_reloc, /* special_function */
1096 "R_PPC64_SECTOFF_LO_DS",/* name */
1097 false, /* partial_inplace */
1099 0xfffc, /* dst_mask */
1100 false), /* pcrel_offset */
1102 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1103 HOWTO (R_PPC64_TOC16_DS, /* type */
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 false, /* pc_relative */
1109 complain_overflow_signed, /* complain_on_overflow */
1110 ppc64_elf_toc_reloc, /* special_function */
1111 "R_PPC64_TOC16_DS", /* name */
1112 false, /* partial_inplace */
1114 0xfffc, /* dst_mask */
1115 false), /* pcrel_offset */
1117 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1118 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1120 1, /* size (0 = byte, 1 = short, 2 = long) */
1122 false, /* pc_relative */
1124 complain_overflow_dont, /* complain_on_overflow */
1125 ppc64_elf_toc_reloc, /* special_function */
1126 "R_PPC64_TOC16_LO_DS", /* name */
1127 false, /* partial_inplace */
1129 0xfffc, /* dst_mask */
1130 false), /* pcrel_offset */
1132 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1133 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1134 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1136 1, /* size (0 = byte, 1 = short, 2 = long) */
1138 false, /* pc_relative */
1140 complain_overflow_signed, /* complain_on_overflow */
1141 ppc64_elf_unhandled_reloc, /* special_function */
1142 "R_PPC64_PLTGOT16_DS", /* name */
1143 false, /* partial_inplace */
1145 0xfffc, /* dst_mask */
1146 false), /* pcrel_offset */
1148 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1149 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1150 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 false, /* pc_relative */
1156 complain_overflow_dont, /* complain_on_overflow */
1157 ppc64_elf_unhandled_reloc, /* special_function */
1158 "R_PPC64_PLTGOT16_LO_DS",/* name */
1159 false, /* partial_inplace */
1161 0xfffc, /* dst_mask */
1162 false), /* pcrel_offset */
1164 /* GNU extension to record C++ vtable hierarchy. */
1165 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1167 0, /* size (0 = byte, 1 = short, 2 = long) */
1169 false, /* pc_relative */
1171 complain_overflow_dont, /* complain_on_overflow */
1172 NULL, /* special_function */
1173 "R_PPC64_GNU_VTINHERIT", /* name */
1174 false, /* partial_inplace */
1177 false), /* pcrel_offset */
1179 /* GNU extension to record C++ vtable member usage. */
1180 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1182 0, /* size (0 = byte, 1 = short, 2 = long) */
1184 false, /* pc_relative */
1186 complain_overflow_dont, /* complain_on_overflow */
1187 NULL, /* special_function */
1188 "R_PPC64_GNU_VTENTRY", /* name */
1189 false, /* partial_inplace */
1192 false), /* pcrel_offset */
1196 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1202 unsigned int i, type;
1205 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1208 type = ppc64_elf_howto_raw[i].type;
1209 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1210 / sizeof (ppc64_elf_howto_table[0])));
1211 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1215 static reloc_howto_type *
1216 ppc64_elf_reloc_type_lookup (abfd, code)
1217 bfd *abfd ATTRIBUTE_UNUSED;
1218 bfd_reloc_code_real_type code;
1220 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1222 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1223 /* Initialize howto table if needed. */
1229 return (reloc_howto_type *) NULL;
1231 case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1233 case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1235 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1237 case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1239 case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1241 case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1243 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1245 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1247 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1249 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1251 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1253 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1255 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1257 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1259 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1261 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1263 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1265 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1267 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1269 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1271 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1273 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1275 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1277 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1279 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1281 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1283 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1285 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1287 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1289 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1291 case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64;
1293 case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1295 case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1297 case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1299 case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1301 case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1303 case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1305 case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1307 case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1309 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1311 case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1313 case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1315 case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1317 case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1319 case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1321 case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1323 case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1325 case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1327 case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1329 case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1331 case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1333 case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1335 case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1337 case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1339 case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1341 case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1343 case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1345 case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1347 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1349 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1351 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1355 return ppc64_elf_howto_table[(int) ppc_reloc];
1358 /* Set the howto pointer for a PowerPC ELF reloc. */
1361 ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1362 bfd *abfd ATTRIBUTE_UNUSED;
1364 Elf64_Internal_Rela *dst;
1368 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1369 /* Initialize howto table if needed. */
1372 type = ELF64_R_TYPE (dst->r_info);
1373 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1374 / sizeof (ppc64_elf_howto_table[0])));
1375 cache_ptr->howto = ppc64_elf_howto_table[type];
1378 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1380 static bfd_reloc_status_type
1381 ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data,
1382 input_section, output_bfd, error_message)
1384 arelent *reloc_entry;
1387 asection *input_section;
1389 char **error_message;
1391 /* If this is a relocatable link (output_bfd test tells us), just
1392 call the generic function. Any adjustment will be done at final
1394 if (output_bfd != NULL)
1395 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1396 input_section, output_bfd, error_message);
1398 /* Adjust the addend for sign extension of the low 16 bits.
1399 We won't actually be using the low 16 bits, so trashing them
1401 reloc_entry->addend += 0x8000;
1402 return bfd_reloc_continue;
1405 static bfd_reloc_status_type
1406 ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data,
1407 input_section, output_bfd, error_message)
1409 arelent *reloc_entry;
1412 asection *input_section;
1414 char **error_message;
1417 enum elf_ppc_reloc_type r_type;
1418 bfd_size_type octets;
1419 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1420 boolean is_power4 = false;
1422 /* If this is a relocatable link (output_bfd test tells us), just
1423 call the generic function. Any adjustment will be done at final
1425 if (output_bfd != NULL)
1426 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1427 input_section, output_bfd, error_message);
1429 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1430 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
1431 insn &= ~(0x01 << 21);
1432 r_type = (enum elf_ppc_reloc_type) reloc_entry->howto->type;
1433 if (r_type == R_PPC64_ADDR14_BRTAKEN
1434 || r_type == R_PPC64_REL14_BRTAKEN)
1435 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1439 /* Set 'a' bit. This is 0b00010 in BO field for branch
1440 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1441 for branch on CTR insns (BO == 1a00t or 1a01t). */
1442 if ((insn & (0x14 << 21)) == (0x04 << 21))
1444 else if ((insn & (0x14 << 21)) == (0x10 << 21))
1447 return bfd_reloc_continue;
1454 if (!bfd_is_com_section (symbol->section))
1455 target = symbol->value;
1456 target += symbol->section->output_section->vma;
1457 target += symbol->section->output_offset;
1458 target += reloc_entry->addend;
1460 from = (reloc_entry->address
1461 + input_section->output_offset
1462 + input_section->output_section->vma);
1464 /* Invert 'y' bit if not the default. */
1465 if ((bfd_signed_vma) (target - from) < 0)
1468 bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets);
1469 return bfd_reloc_continue;
1472 static bfd_reloc_status_type
1473 ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data,
1474 input_section, output_bfd, error_message)
1476 arelent *reloc_entry;
1479 asection *input_section;
1481 char **error_message;
1483 /* If this is a relocatable link (output_bfd test tells us), just
1484 call the generic function. Any adjustment will be done at final
1486 if (output_bfd != NULL)
1487 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1488 input_section, output_bfd, error_message);
1490 /* Subtract the symbol section base address. */
1491 reloc_entry->addend -= symbol->section->output_section->vma;
1492 return bfd_reloc_continue;
1495 static bfd_reloc_status_type
1496 ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data,
1497 input_section, output_bfd, error_message)
1499 arelent *reloc_entry;
1502 asection *input_section;
1504 char **error_message;
1506 /* If this is a relocatable link (output_bfd test tells us), just
1507 call the generic function. Any adjustment will be done at final
1509 if (output_bfd != NULL)
1510 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1511 input_section, output_bfd, error_message);
1513 /* Subtract the symbol section base address. */
1514 reloc_entry->addend -= symbol->section->output_section->vma;
1516 /* Adjust the addend for sign extension of the low 16 bits. */
1517 reloc_entry->addend += 0x8000;
1518 return bfd_reloc_continue;
1521 static bfd_reloc_status_type
1522 ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data,
1523 input_section, output_bfd, error_message)
1525 arelent *reloc_entry;
1528 asection *input_section;
1530 char **error_message;
1534 /* If this is a relocatable link (output_bfd test tells us), just
1535 call the generic function. Any adjustment will be done at final
1537 if (output_bfd != NULL)
1538 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1539 input_section, output_bfd, error_message);
1541 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1543 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1545 /* Subtract the TOC base address. */
1546 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1547 return bfd_reloc_continue;
1550 static bfd_reloc_status_type
1551 ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data,
1552 input_section, output_bfd, error_message)
1554 arelent *reloc_entry;
1557 asection *input_section;
1559 char **error_message;
1563 /* If this is a relocatable link (output_bfd test tells us), just
1564 call the generic function. Any adjustment will be done at final
1566 if (output_bfd != NULL)
1567 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1568 input_section, output_bfd, error_message);
1570 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1572 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1574 /* Subtract the TOC base address. */
1575 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1577 /* Adjust the addend for sign extension of the low 16 bits. */
1578 reloc_entry->addend += 0x8000;
1579 return bfd_reloc_continue;
1582 static bfd_reloc_status_type
1583 ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data,
1584 input_section, output_bfd, error_message)
1586 arelent *reloc_entry;
1589 asection *input_section;
1591 char **error_message;
1594 bfd_size_type octets;
1596 /* If this is a relocatable link (output_bfd test tells us), just
1597 call the generic function. Any adjustment will be done at final
1599 if (output_bfd != NULL)
1600 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1601 input_section, output_bfd, error_message);
1603 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1605 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1607 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1608 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
1609 return bfd_reloc_ok;
1612 static bfd_reloc_status_type
1613 ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
1614 input_section, output_bfd, error_message)
1616 arelent *reloc_entry;
1619 asection *input_section;
1621 char **error_message;
1623 /* If this is a relocatable link (output_bfd test tells us), just
1624 call the generic function. Any adjustment will be done at final
1626 if (output_bfd != NULL)
1627 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1628 input_section, output_bfd, error_message);
1630 if (error_message != NULL)
1632 static char buf[60];
1633 sprintf (buf, "generic linker can't handle %s",
1634 reloc_entry->howto->name);
1635 *error_message = buf;
1637 return bfd_reloc_dangerous;
1640 /* Function to set whether a module needs the -mrelocatable bit set. */
1643 ppc64_elf_set_private_flags (abfd, flags)
1647 BFD_ASSERT (!elf_flags_init (abfd)
1648 || elf_elfheader (abfd)->e_flags == flags);
1650 elf_elfheader (abfd)->e_flags = flags;
1651 elf_flags_init (abfd) = true;
1655 /* Merge backend specific data from an object file to the output
1656 object file when linking. */
1658 ppc64_elf_merge_private_bfd_data (ibfd, obfd)
1666 /* Check if we have the same endianess. */
1667 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1668 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1672 if (bfd_big_endian (ibfd))
1673 msg = _("%s: compiled for a big endian system and target is little endian");
1675 msg = _("%s: compiled for a little endian system and target is big endian");
1677 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
1679 bfd_set_error (bfd_error_wrong_format);
1683 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1684 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1687 new_flags = elf_elfheader (ibfd)->e_flags;
1688 old_flags = elf_elfheader (obfd)->e_flags;
1689 if (!elf_flags_init (obfd))
1691 /* First call, no flags set. */
1692 elf_flags_init (obfd) = true;
1693 elf_elfheader (obfd)->e_flags = new_flags;
1696 else if (new_flags == old_flags)
1697 /* Compatible flags are ok. */
1702 /* Incompatible flags. Warn about -mrelocatable mismatch.
1703 Allow -mrelocatable-lib to be linked with either. */
1705 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1706 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1709 (*_bfd_error_handler)
1710 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1711 bfd_archive_filename (ibfd));
1713 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1714 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1717 (*_bfd_error_handler)
1718 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1719 bfd_archive_filename (ibfd));
1722 /* The output is -mrelocatable-lib iff both the input files are. */
1723 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1724 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1726 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1727 but each input file is either -mrelocatable or -mrelocatable-lib. */
1728 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1729 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1730 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1731 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1733 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1734 if any module uses it. */
1735 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1737 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1738 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1740 /* Warn about any other mismatches. */
1741 if (new_flags != old_flags)
1744 (*_bfd_error_handler)
1745 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1746 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
1751 bfd_set_error (bfd_error_bad_value);
1759 /* Handle a PowerPC specific section when reading an object file. This
1760 is called when elfcode.h finds a section with an unknown type. */
1763 ppc64_elf_section_from_shdr (abfd, hdr, name)
1765 Elf64_Internal_Shdr *hdr;
1771 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1774 newsect = hdr->bfd_section;
1775 flags = bfd_get_section_flags (abfd, newsect);
1776 if (hdr->sh_flags & SHF_EXCLUDE)
1777 flags |= SEC_EXCLUDE;
1779 if (hdr->sh_type == SHT_ORDERED)
1780 flags |= SEC_SORT_ENTRIES;
1782 bfd_set_section_flags (abfd, newsect, flags);
1786 /* The following functions are specific to the ELF linker, while
1787 functions above are used generally. Those named ppc64_elf_* are
1788 called by the main ELF linker code. They appear in this file more
1789 or less in the order in which they are called. eg.
1790 ppc64_elf_check_relocs is called early in the link process,
1791 ppc64_elf_finish_dynamic_sections is one of the last functions
1794 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1795 functions have both a function code symbol and a function descriptor
1796 symbol. A call to foo in a relocatable object file looks like:
1803 The function definition in another object file might be:
1807 . .quad .TOC.@tocbase
1813 When the linker resolves the call during a static link, the branch
1814 unsurprisingly just goes to .foo and the .opd information is unused.
1815 If the function definition is in a shared library, things are a little
1816 different: The call goes via a plt call stub, the opd information gets
1817 copied to the plt, and the linker patches the nop.
1825 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1826 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1827 . std 2,40(1) # this is the general idea
1835 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1837 The "reloc ()" notation is supposed to indicate that the linker emits
1838 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1841 What are the difficulties here? Well, firstly, the relocations
1842 examined by the linker in check_relocs are against the function code
1843 sym .foo, while the dynamic relocation in the plt is emitted against
1844 the function descriptor symbol, foo. Somewhere along the line, we need
1845 to carefully copy dynamic link information from one symbol to the other.
1846 Secondly, the generic part of the elf linker will make .foo a dynamic
1847 symbol as is normal for most other backends. We need foo dynamic
1848 instead, at least for an application final link. However, when
1849 creating a shared library containing foo, we need to have both symbols
1850 dynamic so that references to .foo are satisfied during the early
1851 stages of linking. Otherwise the linker might decide to pull in a
1852 definition from some other object, eg. a static library. */
1854 /* The linker needs to keep track of the number of relocs that it
1855 decides to copy as dynamic relocs in check_relocs for each symbol.
1856 This is so that it can later discard them if they are found to be
1857 unnecessary. We store the information in a field extending the
1858 regular ELF linker hash table. */
1860 struct ppc_dyn_relocs
1862 struct ppc_dyn_relocs *next;
1864 /* The input section of the reloc. */
1867 /* Total number of relocs copied for the input section. */
1868 bfd_size_type count;
1870 /* Number of pc-relative relocs copied for the input section. */
1871 bfd_size_type pc_count;
1874 /* Of those relocs that might be copied as dynamic relocs, this macro
1875 selects between relative and absolute types. */
1877 #define IS_ABSOLUTE_RELOC(RTYPE) \
1878 ((RTYPE) != R_PPC64_REL32 \
1879 && (RTYPE) != R_PPC64_REL64 \
1880 && (RTYPE) != R_PPC64_ADDR30)
1882 /* Section name for stubs is the associated section name plus this
1884 #define STUB_SUFFIX ".stub"
1887 ppc_stub_long_branch:
1888 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1889 destination, but a 24 bit branch in a stub section will reach.
1892 ppc_stub_plt_branch:
1893 Similar to the above, but a 24 bit branch in the stub section won't
1894 reach its destination.
1895 . addis %r12,%r2,xxx@ha
1896 . ld %r11,xxx@l(%r12)
1901 Used to call a function in a shared library.
1902 . addis %r12,%r2,xxx@ha
1904 . ld %r11,xxx+0@l(%r12)
1905 . ld %r2,xxx+8@l(%r12)
1907 . ld %r11,xxx+16@l(%r12)
1911 enum ppc_stub_type {
1913 ppc_stub_long_branch,
1914 ppc_stub_plt_branch,
1918 struct ppc_stub_hash_entry {
1920 /* Base hash table entry structure. */
1921 struct bfd_hash_entry root;
1923 /* The stub section. */
1926 /* Offset within stub_sec of the beginning of this stub. */
1927 bfd_vma stub_offset;
1929 /* Given the symbol's value and its section we can determine its final
1930 value when building the stubs (so the stub knows where to jump. */
1931 bfd_vma target_value;
1932 asection *target_section;
1934 enum ppc_stub_type stub_type;
1936 /* The symbol table entry, if any, that this was derived from. */
1937 struct ppc_link_hash_entry *h;
1939 /* Where this stub is being called from, or, in the case of combined
1940 stub sections, the first input section in the group. */
1944 struct ppc_branch_hash_entry {
1946 /* Base hash table entry structure. */
1947 struct bfd_hash_entry root;
1949 /* Offset within .branch_lt. */
1950 unsigned int offset;
1952 /* Generation marker. */
1956 struct ppc_link_hash_entry
1958 struct elf_link_hash_entry elf;
1960 /* A pointer to the most recently used stub hash entry against this
1962 struct ppc_stub_hash_entry *stub_cache;
1964 /* Track dynamic relocs copied for this symbol. */
1965 struct ppc_dyn_relocs *dyn_relocs;
1967 /* Link between function code and descriptor symbols. */
1968 struct elf_link_hash_entry *oh;
1970 /* Flag function code and descriptor symbols. */
1971 unsigned int is_func:1;
1972 unsigned int is_func_descriptor:1;
1975 /* ppc64 ELF linker hash table. */
1977 struct ppc_link_hash_table
1979 struct elf_link_hash_table elf;
1981 /* The stub hash table. */
1982 struct bfd_hash_table stub_hash_table;
1984 /* Another hash table for plt_branch stubs. */
1985 struct bfd_hash_table branch_hash_table;
1987 /* Linker stub bfd. */
1990 /* Linker call-backs. */
1991 asection * (*add_stub_section) PARAMS ((const char *, asection *));
1992 void (*layout_sections_again) PARAMS ((void));
1994 /* Array to keep track of which stub sections have been created, and
1995 information on stub grouping. */
1997 /* This is the section to which stubs in the group will be attached. */
1999 /* The stub section. */
2003 /* Assorted information used by ppc64_elf_size_stubs. */
2004 unsigned int bfd_count;
2006 asection **input_list;
2007 Elf_Internal_Sym **all_local_syms;
2009 /* Short-cuts to get to dynamic linker sections. */
2022 unsigned int stub_error;
2024 /* Flag set when small branches are detected. Used to
2025 select suitable defaults for the stub group size. */
2026 unsigned int has_14bit_branch;
2028 /* Set if we detect a reference undefined weak symbol. */
2029 unsigned int have_undefweak;
2031 /* Incremented every time we size stubs. */
2032 unsigned int stub_iteration;
2034 /* Small local sym to section mapping cache. */
2035 struct sym_sec_cache sym_sec;
2038 static struct bfd_hash_entry *stub_hash_newfunc
2039 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2040 static struct bfd_hash_entry *branch_hash_newfunc
2041 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2042 static struct bfd_hash_entry *link_hash_newfunc
2043 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2044 static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
2046 static void ppc64_elf_link_hash_table_free
2047 PARAMS ((struct bfd_link_hash_table *));
2048 static char *ppc_stub_name
2049 PARAMS ((const asection *, const asection *,
2050 const struct ppc_link_hash_entry *, const Elf_Internal_Rela *));
2051 static struct ppc_stub_hash_entry *ppc_get_stub_entry
2052 PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *,
2053 const Elf_Internal_Rela *, struct ppc_link_hash_table *));
2054 static struct ppc_stub_hash_entry *ppc_add_stub
2055 PARAMS ((const char *, asection *, struct ppc_link_hash_table *));
2056 static boolean create_linkage_sections
2057 PARAMS ((bfd *, struct bfd_link_info *));
2058 static boolean create_got_section
2059 PARAMS ((bfd *, struct bfd_link_info *));
2060 static boolean ppc64_elf_create_dynamic_sections
2061 PARAMS ((bfd *, struct bfd_link_info *));
2062 static void ppc64_elf_copy_indirect_symbol
2063 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
2064 static boolean ppc64_elf_check_relocs
2065 PARAMS ((bfd *, struct bfd_link_info *, asection *,
2066 const Elf_Internal_Rela *));
2067 static asection * ppc64_elf_gc_mark_hook
2068 PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel,
2069 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
2070 static boolean ppc64_elf_gc_sweep_hook
2071 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
2072 const Elf_Internal_Rela *relocs));
2073 static boolean func_desc_adjust
2074 PARAMS ((struct elf_link_hash_entry *, PTR));
2075 static boolean ppc64_elf_func_desc_adjust
2076 PARAMS ((bfd *, struct bfd_link_info *));
2077 static boolean ppc64_elf_adjust_dynamic_symbol
2078 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
2079 static void ppc64_elf_hide_symbol
2080 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
2081 static boolean allocate_dynrelocs
2082 PARAMS ((struct elf_link_hash_entry *, PTR));
2083 static boolean readonly_dynrelocs
2084 PARAMS ((struct elf_link_hash_entry *, PTR));
2085 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2086 PARAMS ((const Elf_Internal_Rela *));
2087 static boolean ppc64_elf_size_dynamic_sections
2088 PARAMS ((bfd *, struct bfd_link_info *));
2089 static INLINE enum ppc_stub_type ppc_type_of_stub
2090 PARAMS ((asection *, const Elf_Internal_Rela *,
2091 struct ppc_link_hash_entry **, bfd_vma));
2092 static bfd_byte *build_plt_stub
2093 PARAMS ((bfd *, bfd_byte *, int, int));
2094 static boolean ppc_build_one_stub
2095 PARAMS ((struct bfd_hash_entry *, PTR));
2096 static boolean ppc_size_one_stub
2097 PARAMS ((struct bfd_hash_entry *, PTR));
2098 static void group_sections
2099 PARAMS ((struct ppc_link_hash_table *, bfd_size_type, boolean));
2100 static boolean get_local_syms
2101 PARAMS ((bfd *, struct ppc_link_hash_table *));
2102 static boolean ppc64_elf_fake_sections
2103 PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *));
2104 static boolean ppc64_elf_relocate_section
2105 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
2106 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
2108 static boolean ppc64_elf_finish_dynamic_symbol
2109 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
2110 Elf_Internal_Sym *));
2111 static boolean ppc64_elf_finish_dynamic_sections
2112 PARAMS ((bfd *, struct bfd_link_info *));
2114 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2116 #define ppc_hash_table(p) \
2117 ((struct ppc_link_hash_table *) ((p)->hash))
2119 #define ppc_stub_hash_lookup(table, string, create, copy) \
2120 ((struct ppc_stub_hash_entry *) \
2121 bfd_hash_lookup ((table), (string), (create), (copy)))
2123 #define ppc_branch_hash_lookup(table, string, create, copy) \
2124 ((struct ppc_branch_hash_entry *) \
2125 bfd_hash_lookup ((table), (string), (create), (copy)))
2127 /* Create an entry in the stub hash table. */
2129 static struct bfd_hash_entry *
2130 stub_hash_newfunc (entry, table, string)
2131 struct bfd_hash_entry *entry;
2132 struct bfd_hash_table *table;
2135 /* Allocate the structure if it has not already been allocated by a
2139 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2144 /* Call the allocation method of the superclass. */
2145 entry = bfd_hash_newfunc (entry, table, string);
2148 struct ppc_stub_hash_entry *eh;
2150 /* Initialize the local fields. */
2151 eh = (struct ppc_stub_hash_entry *) entry;
2152 eh->stub_sec = NULL;
2153 eh->stub_offset = 0;
2154 eh->target_value = 0;
2155 eh->target_section = NULL;
2156 eh->stub_type = ppc_stub_none;
2164 /* Create an entry in the branch hash table. */
2166 static struct bfd_hash_entry *
2167 branch_hash_newfunc (entry, table, string)
2168 struct bfd_hash_entry *entry;
2169 struct bfd_hash_table *table;
2172 /* Allocate the structure if it has not already been allocated by a
2176 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2181 /* Call the allocation method of the superclass. */
2182 entry = bfd_hash_newfunc (entry, table, string);
2185 struct ppc_branch_hash_entry *eh;
2187 /* Initialize the local fields. */
2188 eh = (struct ppc_branch_hash_entry *) entry;
2196 /* Create an entry in a ppc64 ELF linker hash table. */
2198 static struct bfd_hash_entry *
2199 link_hash_newfunc (entry, table, string)
2200 struct bfd_hash_entry *entry;
2201 struct bfd_hash_table *table;
2204 /* Allocate the structure if it has not already been allocated by a
2208 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2213 /* Call the allocation method of the superclass. */
2214 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2217 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2219 eh->stub_cache = NULL;
2220 eh->dyn_relocs = NULL;
2223 eh->is_func_descriptor = 0;
2229 /* Create a ppc64 ELF linker hash table. */
2231 static struct bfd_link_hash_table *
2232 ppc64_elf_link_hash_table_create (abfd)
2235 struct ppc_link_hash_table *htab;
2236 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
2238 htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
2242 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
2248 /* Init the stub hash table too. */
2249 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
2252 /* And the branch hash table. */
2253 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
2256 htab->stub_bfd = NULL;
2257 htab->add_stub_section = NULL;
2258 htab->layout_sections_again = NULL;
2259 htab->stub_group = NULL;
2261 htab->srelgot = NULL;
2263 htab->srelplt = NULL;
2264 htab->sdynbss = NULL;
2265 htab->srelbss = NULL;
2266 htab->sglink = NULL;
2269 htab->srelbrlt = NULL;
2270 htab->stub_error = 0;
2271 htab->has_14bit_branch = 0;
2272 htab->have_undefweak = 0;
2273 htab->stub_iteration = 0;
2274 htab->sym_sec.abfd = NULL;
2276 return &htab->elf.root;
2279 /* Free the derived linker hash table. */
2282 ppc64_elf_link_hash_table_free (hash)
2283 struct bfd_link_hash_table *hash;
2285 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
2287 bfd_hash_table_free (&ret->stub_hash_table);
2288 bfd_hash_table_free (&ret->branch_hash_table);
2289 _bfd_generic_link_hash_table_free (hash);
2292 /* Build a name for an entry in the stub hash table. */
2295 ppc_stub_name (input_section, sym_sec, h, rel)
2296 const asection *input_section;
2297 const asection *sym_sec;
2298 const struct ppc_link_hash_entry *h;
2299 const Elf_Internal_Rela *rel;
2304 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2305 offsets from a sym as a branch target? In fact, we could
2306 probably assume the addend is always zero. */
2307 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
2311 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
2312 stub_name = bfd_malloc (len);
2313 if (stub_name != NULL)
2315 sprintf (stub_name, "%08x_%s+%x",
2316 input_section->id & 0xffffffff,
2317 h->elf.root.root.string,
2318 (int) rel->r_addend & 0xffffffff);
2323 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2324 stub_name = bfd_malloc (len);
2325 if (stub_name != NULL)
2327 sprintf (stub_name, "%08x_%x:%x+%x",
2328 input_section->id & 0xffffffff,
2329 sym_sec->id & 0xffffffff,
2330 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
2331 (int) rel->r_addend & 0xffffffff);
2337 /* Look up an entry in the stub hash. Stub entries are cached because
2338 creating the stub name takes a bit of time. */
2340 static struct ppc_stub_hash_entry *
2341 ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab)
2342 const asection *input_section;
2343 const asection *sym_sec;
2344 struct elf_link_hash_entry *hash;
2345 const Elf_Internal_Rela *rel;
2346 struct ppc_link_hash_table *htab;
2348 struct ppc_stub_hash_entry *stub_entry;
2349 struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
2350 const asection *id_sec;
2352 /* If this input section is part of a group of sections sharing one
2353 stub section, then use the id of the first section in the group.
2354 Stub names need to include a section id, as there may well be
2355 more than one stub used to reach say, printf, and we need to
2356 distinguish between them. */
2357 id_sec = htab->stub_group[input_section->id].link_sec;
2359 if (h != NULL && h->stub_cache != NULL
2360 && h->stub_cache->h == h
2361 && h->stub_cache->id_sec == id_sec)
2363 stub_entry = h->stub_cache;
2369 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
2370 if (stub_name == NULL)
2373 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
2374 stub_name, false, false);
2376 h->stub_cache = stub_entry;
2384 /* Add a new stub entry to the stub hash. Not all fields of the new
2385 stub entry are initialised. */
2387 static struct ppc_stub_hash_entry *
2388 ppc_add_stub (stub_name, section, htab)
2389 const char *stub_name;
2391 struct ppc_link_hash_table *htab;
2395 struct ppc_stub_hash_entry *stub_entry;
2397 link_sec = htab->stub_group[section->id].link_sec;
2398 stub_sec = htab->stub_group[section->id].stub_sec;
2399 if (stub_sec == NULL)
2401 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2402 if (stub_sec == NULL)
2407 len = strlen (link_sec->name) + sizeof (STUB_SUFFIX);
2408 s_name = bfd_alloc (htab->stub_bfd, len);
2412 strcpy (s_name, link_sec->name);
2413 strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX);
2414 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2415 if (stub_sec == NULL)
2417 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2419 htab->stub_group[section->id].stub_sec = stub_sec;
2422 /* Enter this entry into the linker stub hash table. */
2423 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2425 if (stub_entry == NULL)
2427 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2428 bfd_archive_filename (section->owner),
2433 stub_entry->stub_sec = stub_sec;
2434 stub_entry->stub_offset = 0;
2435 stub_entry->id_sec = link_sec;
2439 /* Create sections for linker generated code. */
2442 create_linkage_sections (dynobj, info)
2444 struct bfd_link_info *info;
2446 struct ppc_link_hash_table *htab;
2449 htab = ppc_hash_table (info);
2451 /* Create .sfpr for code to save and restore fp regs. */
2452 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
2453 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2454 htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
2455 if (htab->sfpr == NULL
2456 || ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
2457 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
2460 /* Create .glink for lazy dynamic linking support. */
2461 htab->sglink = bfd_make_section_anyway (dynobj, ".glink");
2462 if (htab->sglink == NULL
2463 || ! bfd_set_section_flags (dynobj, htab->sglink, flags)
2464 || ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
2467 /* Create .branch_lt for plt_branch stubs. */
2468 flags = (SEC_ALLOC | SEC_LOAD
2469 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2470 htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt");
2471 if (htab->sbrlt == NULL
2472 || ! bfd_set_section_flags (dynobj, htab->sbrlt, flags)
2473 || ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3))
2478 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2479 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2480 htab->srelbrlt = bfd_make_section (dynobj, ".rela.branch_lt");
2482 || ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags)
2483 || ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3))
2489 /* Create .got and .rela.got sections in DYNOBJ, and set up
2490 shortcuts to them in our hash table. */
2493 create_got_section (dynobj, info)
2495 struct bfd_link_info *info;
2497 struct ppc_link_hash_table *htab;
2499 if (! _bfd_elf_create_got_section (dynobj, info))
2502 htab = ppc_hash_table (info);
2503 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2507 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
2509 || ! bfd_set_section_flags (dynobj, htab->srelgot,
2510 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2511 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2513 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
2518 /* Create the dynamic sections, and set up shortcuts. */
2521 ppc64_elf_create_dynamic_sections (dynobj, info)
2523 struct bfd_link_info *info;
2525 struct ppc_link_hash_table *htab;
2527 htab = ppc_hash_table (info);
2528 if (!htab->sgot && !create_got_section (dynobj, info))
2531 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2534 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2535 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
2536 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2538 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
2540 if (!htab->splt || !htab->srelplt || !htab->sdynbss
2541 || (!info->shared && !htab->srelbss))
2547 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2550 ppc64_elf_copy_indirect_symbol (dir, ind)
2551 struct elf_link_hash_entry *dir, *ind;
2553 struct ppc_link_hash_entry *edir, *eind;
2555 edir = (struct ppc_link_hash_entry *) dir;
2556 eind = (struct ppc_link_hash_entry *) ind;
2558 if (eind->dyn_relocs != NULL)
2560 if (edir->dyn_relocs != NULL)
2562 struct ppc_dyn_relocs **pp;
2563 struct ppc_dyn_relocs *p;
2565 if (ind->root.type == bfd_link_hash_indirect)
2568 /* Add reloc counts against the weak sym to the strong sym
2569 list. Merge any entries against the same section. */
2570 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2572 struct ppc_dyn_relocs *q;
2574 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2575 if (q->sec == p->sec)
2577 q->pc_count += p->pc_count;
2578 q->count += p->count;
2585 *pp = edir->dyn_relocs;
2588 edir->dyn_relocs = eind->dyn_relocs;
2589 eind->dyn_relocs = NULL;
2592 edir->is_func |= eind->is_func;
2593 edir->is_func_descriptor |= eind->is_func_descriptor;
2595 _bfd_elf_link_hash_copy_indirect (dir, ind);
2598 /* Look through the relocs for a section during the first phase, and
2599 calculate needed space in the global offset table, procedure
2600 linkage table, and dynamic reloc sections. */
2603 ppc64_elf_check_relocs (abfd, info, sec, relocs)
2605 struct bfd_link_info *info;
2607 const Elf_Internal_Rela *relocs;
2609 struct ppc_link_hash_table *htab;
2610 Elf_Internal_Shdr *symtab_hdr;
2611 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2612 const Elf_Internal_Rela *rel;
2613 const Elf_Internal_Rela *rel_end;
2617 if (info->relocateable)
2620 htab = ppc_hash_table (info);
2621 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2623 sym_hashes = elf_sym_hashes (abfd);
2624 sym_hashes_end = (sym_hashes
2625 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym));
2626 if (!elf_bad_symtab (abfd))
2627 sym_hashes_end -= symtab_hdr->sh_info;
2630 is_opd = strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0;
2632 if (htab->elf.dynobj == NULL)
2633 htab->elf.dynobj = abfd;
2634 if (htab->sfpr == NULL
2635 && !create_linkage_sections (htab->elf.dynobj, info))
2638 rel_end = relocs + sec->reloc_count;
2639 for (rel = relocs; rel < rel_end; rel++)
2641 unsigned long r_symndx;
2642 struct elf_link_hash_entry *h;
2643 enum elf_ppc_reloc_type r_type;
2645 r_symndx = ELF64_R_SYM (rel->r_info);
2646 if (r_symndx < symtab_hdr->sh_info)
2649 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2651 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2654 /* GOT16 relocations */
2656 case R_PPC64_GOT16_DS:
2657 case R_PPC64_GOT16_HA:
2658 case R_PPC64_GOT16_HI:
2659 case R_PPC64_GOT16_LO:
2660 case R_PPC64_GOT16_LO_DS:
2662 /* This symbol requires a global offset table entry. */
2663 if (htab->sgot == NULL
2664 && !create_got_section (htab->elf.dynobj, info))
2669 h->got.refcount += 1;
2673 bfd_signed_vma *local_got_refcounts;
2675 /* This is a global offset table entry for a local symbol. */
2676 local_got_refcounts = elf_local_got_refcounts (abfd);
2677 if (local_got_refcounts == NULL)
2681 size = symtab_hdr->sh_info;
2682 size *= sizeof (bfd_signed_vma);
2683 local_got_refcounts = ((bfd_signed_vma *)
2684 bfd_zalloc (abfd, size));
2685 if (local_got_refcounts == NULL)
2687 elf_local_got_refcounts (abfd) = local_got_refcounts;
2689 local_got_refcounts[r_symndx] += 1;
2693 case R_PPC64_PLT16_HA:
2694 case R_PPC64_PLT16_HI:
2695 case R_PPC64_PLT16_LO:
2698 /* This symbol requires a procedure linkage table entry. We
2699 actually build the entry in adjust_dynamic_symbol,
2700 because this might be a case of linking PIC code without
2701 linking in any dynamic objects, in which case we don't
2702 need to generate a procedure linkage table after all. */
2705 /* It does not make sense to have a procedure linkage
2706 table entry for a local symbol. */
2707 bfd_set_error (bfd_error_bad_value);
2711 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2712 h->plt.refcount += 1;
2713 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2716 /* The following relocations don't need to propagate the
2717 relocation if linking a shared object since they are
2718 section relative. */
2719 case R_PPC64_SECTOFF:
2720 case R_PPC64_SECTOFF_LO:
2721 case R_PPC64_SECTOFF_HI:
2722 case R_PPC64_SECTOFF_HA:
2723 case R_PPC64_SECTOFF_DS:
2724 case R_PPC64_SECTOFF_LO_DS:
2726 case R_PPC64_TOC16_LO:
2727 case R_PPC64_TOC16_HI:
2728 case R_PPC64_TOC16_HA:
2729 case R_PPC64_TOC16_DS:
2730 case R_PPC64_TOC16_LO_DS:
2733 /* This relocation describes the C++ object vtable hierarchy.
2734 Reconstruct it for later use during GC. */
2735 case R_PPC64_GNU_VTINHERIT:
2736 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2740 /* This relocation describes which C++ vtable entries are actually
2741 used. Record for later use during GC. */
2742 case R_PPC64_GNU_VTENTRY:
2743 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2748 case R_PPC64_REL14_BRTAKEN:
2749 case R_PPC64_REL14_BRNTAKEN:
2750 htab->has_14bit_branch = 1;
2755 && h->root.root.string[0] == '.'
2756 && h->root.root.string[1] != 0)
2758 /* We may need a .plt entry if the function this reloc
2759 refers to is in a shared lib. */
2760 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2761 h->plt.refcount += 1;
2762 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2766 case R_PPC64_ADDR64:
2769 && h->root.root.string[0] == '.'
2770 && h->root.root.string[1] != 0)
2772 struct elf_link_hash_entry *fdh;
2774 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
2775 false, false, false);
2778 /* Ensure the function descriptor symbol string is
2779 part of the code symbol string. We aren't
2780 changing the name here, just allowing some tricks
2781 in ppc64_elf_hide_symbol. */
2782 fdh->root.root.string = h->root.root.string + 1;
2783 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
2784 ((struct ppc_link_hash_entry *) fdh)->oh = h;
2785 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2786 ((struct ppc_link_hash_entry *) h)->oh = fdh;
2793 case R_PPC64_ADDR14:
2794 case R_PPC64_ADDR14_BRNTAKEN:
2795 case R_PPC64_ADDR14_BRTAKEN:
2796 case R_PPC64_ADDR16:
2797 case R_PPC64_ADDR16_DS:
2798 case R_PPC64_ADDR16_HA:
2799 case R_PPC64_ADDR16_HI:
2800 case R_PPC64_ADDR16_HIGHER:
2801 case R_PPC64_ADDR16_HIGHERA:
2802 case R_PPC64_ADDR16_HIGHEST:
2803 case R_PPC64_ADDR16_HIGHESTA:
2804 case R_PPC64_ADDR16_LO:
2805 case R_PPC64_ADDR16_LO_DS:
2806 case R_PPC64_ADDR24:
2807 case R_PPC64_ADDR30:
2808 case R_PPC64_ADDR32:
2809 case R_PPC64_UADDR16:
2810 case R_PPC64_UADDR32:
2811 case R_PPC64_UADDR64:
2813 /* Don't propagate .opd relocs. */
2814 if (NO_OPD_RELOCS && is_opd)
2817 /* If we are creating a shared library, and this is a reloc
2818 against a global symbol, or a non PC relative reloc
2819 against a local symbol, then we need to copy the reloc
2820 into the shared library. However, if we are linking with
2821 -Bsymbolic, we do not need to copy a reloc against a
2822 global symbol which is defined in an object we are
2823 including in the link (i.e., DEF_REGULAR is set). At
2824 this point we have not seen all the input files, so it is
2825 possible that DEF_REGULAR is not set now but will be set
2826 later (it is never cleared). In case of a weak definition,
2827 DEF_REGULAR may be cleared later by a strong definition in
2828 a shared library. We account for that possibility below by
2829 storing information in the relocs_copied field of the hash
2830 table entry. A similar situation occurs when creating
2831 shared libraries and symbol visibility changes render the
2834 If on the other hand, we are creating an executable, we
2835 may need to keep relocations for symbols satisfied by a
2836 dynamic library if we manage to avoid copy relocs for the
2839 && (sec->flags & SEC_ALLOC) != 0
2840 && (IS_ABSOLUTE_RELOC (r_type)
2842 && (! info->symbolic
2843 || h->root.type == bfd_link_hash_defweak
2844 || (h->elf_link_hash_flags
2845 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2847 && (sec->flags & SEC_ALLOC) != 0
2849 && (h->root.type == bfd_link_hash_defweak
2850 || (h->elf_link_hash_flags
2851 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
2853 struct ppc_dyn_relocs *p;
2854 struct ppc_dyn_relocs **head;
2856 /* We must copy these reloc types into the output file.
2857 Create a reloc section in dynobj and make room for
2864 name = (bfd_elf_string_from_elf_section
2866 elf_elfheader (abfd)->e_shstrndx,
2867 elf_section_data (sec)->rel_hdr.sh_name));
2871 if (strncmp (name, ".rela", 5) != 0
2872 || strcmp (bfd_get_section_name (abfd, sec),
2875 (*_bfd_error_handler)
2876 (_("%s: bad relocation section name `%s\'"),
2877 bfd_archive_filename (abfd), name);
2878 bfd_set_error (bfd_error_bad_value);
2881 dynobj = htab->elf.dynobj;
2882 sreloc = bfd_get_section_by_name (dynobj, name);
2887 sreloc = bfd_make_section (dynobj, name);
2888 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2889 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2890 if ((sec->flags & SEC_ALLOC) != 0)
2891 flags |= SEC_ALLOC | SEC_LOAD;
2893 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2894 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
2897 elf_section_data (sec)->sreloc = sreloc;
2900 /* If this is a global symbol, we count the number of
2901 relocations we need for this symbol. */
2904 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
2908 /* Track dynamic relocs needed for local syms too.
2909 We really need local syms available to do this
2913 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
2918 head = ((struct ppc_dyn_relocs **)
2919 &elf_section_data (s)->local_dynrel);
2923 if (p == NULL || p->sec != sec)
2925 p = ((struct ppc_dyn_relocs *)
2926 bfd_alloc (htab->elf.dynobj,
2927 (bfd_size_type) sizeof *p));
2938 if (!IS_ABSOLUTE_RELOC (r_type))
2951 /* Return the section that should be marked against GC for a given
2955 ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym)
2957 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2958 Elf_Internal_Rela *rel;
2959 struct elf_link_hash_entry *h;
2960 Elf_Internal_Sym *sym;
2964 enum elf_ppc_reloc_type r_type;
2966 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2969 case R_PPC64_GNU_VTINHERIT:
2970 case R_PPC64_GNU_VTENTRY:
2974 switch (h->root.type)
2976 case bfd_link_hash_defined:
2977 case bfd_link_hash_defweak:
2978 return h->root.u.def.section;
2980 case bfd_link_hash_common:
2981 return h->root.u.c.p->section;
2990 return bfd_section_from_elf_index (abfd, sym->st_shndx);
2996 /* Update the .got, .plt. and dynamic reloc reference counts for the
2997 section being removed. */
3000 ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
3002 struct bfd_link_info *info ATTRIBUTE_UNUSED;
3004 const Elf_Internal_Rela *relocs;
3006 Elf_Internal_Shdr *symtab_hdr;
3007 struct elf_link_hash_entry **sym_hashes;
3008 bfd_signed_vma *local_got_refcounts;
3009 const Elf_Internal_Rela *rel, *relend;
3011 elf_section_data (sec)->local_dynrel = NULL;
3013 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3014 sym_hashes = elf_sym_hashes (abfd);
3015 local_got_refcounts = elf_local_got_refcounts (abfd);
3017 relend = relocs + sec->reloc_count;
3018 for (rel = relocs; rel < relend; rel++)
3020 unsigned long r_symndx;
3021 enum elf_ppc_reloc_type r_type;
3022 struct elf_link_hash_entry *h;
3024 r_symndx = ELF64_R_SYM (rel->r_info);
3025 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3029 case R_PPC64_GOT16_DS:
3030 case R_PPC64_GOT16_HA:
3031 case R_PPC64_GOT16_HI:
3032 case R_PPC64_GOT16_LO:
3033 case R_PPC64_GOT16_LO_DS:
3034 if (r_symndx >= symtab_hdr->sh_info)
3036 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3037 if (h->got.refcount > 0)
3042 if (local_got_refcounts[r_symndx] > 0)
3043 local_got_refcounts[r_symndx]--;
3047 case R_PPC64_PLT16_HA:
3048 case R_PPC64_PLT16_HI:
3049 case R_PPC64_PLT16_LO:
3052 if (r_symndx >= symtab_hdr->sh_info)
3054 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3055 if (h->plt.refcount > 0)
3061 case R_PPC64_REL14_BRNTAKEN:
3062 case R_PPC64_REL14_BRTAKEN:
3064 if (r_symndx >= symtab_hdr->sh_info)
3066 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3067 if (h->plt.refcount > 0)
3074 if (r_symndx >= symtab_hdr->sh_info)
3076 struct ppc_link_hash_entry *eh;
3077 struct ppc_dyn_relocs **pp;
3078 struct ppc_dyn_relocs *p;
3080 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3081 eh = (struct ppc_link_hash_entry *) h;
3083 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3095 case R_PPC64_ADDR14:
3096 case R_PPC64_ADDR14_BRNTAKEN:
3097 case R_PPC64_ADDR14_BRTAKEN:
3098 case R_PPC64_ADDR16:
3099 case R_PPC64_ADDR16_DS:
3100 case R_PPC64_ADDR16_HA:
3101 case R_PPC64_ADDR16_HI:
3102 case R_PPC64_ADDR16_HIGHER:
3103 case R_PPC64_ADDR16_HIGHERA:
3104 case R_PPC64_ADDR16_HIGHEST:
3105 case R_PPC64_ADDR16_HIGHESTA:
3106 case R_PPC64_ADDR16_LO:
3107 case R_PPC64_ADDR16_LO_DS:
3108 case R_PPC64_ADDR24:
3109 case R_PPC64_ADDR30:
3110 case R_PPC64_ADDR32:
3111 case R_PPC64_ADDR64:
3112 case R_PPC64_UADDR16:
3113 case R_PPC64_UADDR32:
3114 case R_PPC64_UADDR64:
3116 if (r_symndx >= symtab_hdr->sh_info)
3118 struct ppc_link_hash_entry *eh;
3119 struct ppc_dyn_relocs **pp;
3120 struct ppc_dyn_relocs *p;
3122 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3123 eh = (struct ppc_link_hash_entry *) h;
3125 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3143 /* Called via elf_link_hash_traverse to transfer dynamic linking
3144 information on function code symbol entries to their corresponding
3145 function descriptor symbol entries. */
3147 func_desc_adjust (h, inf)
3148 struct elf_link_hash_entry *h;
3151 struct bfd_link_info *info;
3152 struct ppc_link_hash_table *htab;
3154 if (h->root.type == bfd_link_hash_indirect)
3157 if (h->root.type == bfd_link_hash_warning)
3158 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3160 info = (struct bfd_link_info *) inf;
3161 htab = ppc_hash_table (info);
3163 /* If this is a function code symbol, transfer dynamic linking
3164 information to the function descriptor symbol. */
3165 if (!((struct ppc_link_hash_entry *) h)->is_func)
3168 if (h->root.type == bfd_link_hash_undefweak
3169 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
3170 htab->have_undefweak = true;
3172 if (h->plt.refcount > 0
3173 && h->root.root.string[0] == '.'
3174 && h->root.root.string[1] != '\0')
3176 struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh;
3177 boolean force_local;
3179 /* Find the corresponding function descriptor symbol. Create it
3180 as undefined if necessary. */
3183 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
3184 false, false, true);
3188 && (h->root.type == bfd_link_hash_undefined
3189 || h->root.type == bfd_link_hash_undefweak))
3194 abfd = h->root.u.undef.abfd;
3195 newsym = bfd_make_empty_symbol (abfd);
3196 newsym->name = h->root.root.string + 1;
3197 newsym->section = bfd_und_section_ptr;
3199 newsym->flags = BSF_OBJECT;
3200 if (h->root.type == bfd_link_hash_undefweak)
3201 newsym->flags |= BSF_WEAK;
3203 if ( !(_bfd_generic_link_add_one_symbol
3204 (info, abfd, newsym->name, newsym->flags,
3205 newsym->section, newsym->value, NULL, false, false,
3206 (struct bfd_link_hash_entry **) &fdh)))
3210 fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
3214 && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
3216 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3217 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
3219 if (fdh->dynindx == -1)
3220 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
3222 fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
3223 & (ELF_LINK_HASH_REF_REGULAR
3224 | ELF_LINK_HASH_REF_DYNAMIC
3225 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3226 | ELF_LINK_NON_GOT_REF));
3227 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3229 fdh->plt.refcount = h->plt.refcount;
3230 fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3232 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
3233 ((struct ppc_link_hash_entry *) fdh)->oh = h;
3234 fdh->root.root.string = h->root.root.string + 1;
3235 ((struct ppc_link_hash_entry *) h)->oh = fdh;
3238 /* Now that the info is on the function descriptor, clear the
3239 function code sym info. Any function code syms for which we
3240 don't have a definition in a regular file, we force local.
3241 This prevents a shared library from exporting syms that have
3242 been imported from another library. Function code syms that
3243 are really in the library we must leave global to prevent the
3244 linker dragging in a definition from a static library. */
3245 force_local = ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
3247 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3253 #define MIN_SAVE_FPR 14
3254 #define MAX_SAVE_FPR 31
3256 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3257 this hook to a) provide some gcc support functions, and b) transfer
3258 dynamic linking information gathered so far on function code symbol
3259 entries, to their corresponding function descriptor symbol entries. */
3261 ppc64_elf_func_desc_adjust (obfd, info)
3262 bfd *obfd ATTRIBUTE_UNUSED;
3263 struct bfd_link_info *info;
3265 struct ppc_link_hash_table *htab;
3266 unsigned int lowest_savef = MAX_SAVE_FPR + 2;
3267 unsigned int lowest_restf = MAX_SAVE_FPR + 2;
3269 struct elf_link_hash_entry *h;
3273 htab = ppc_hash_table (info);
3275 if (htab->sfpr == NULL)
3276 /* We don't have any relocs. */
3279 /* First provide any missing ._savef* and ._restf* functions. */
3280 memcpy (sym, "._savef14", 10);
3281 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3283 sym[7] = i / 10 + '0';
3284 sym[8] = i % 10 + '0';
3285 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3287 && h->root.type == bfd_link_hash_undefined)
3289 if (lowest_savef > i)
3291 h->root.type = bfd_link_hash_defined;
3292 h->root.u.def.section = htab->sfpr;
3293 h->root.u.def.value = (i - lowest_savef) * 4;
3295 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3296 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3300 memcpy (sym, "._restf14", 10);
3301 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3303 sym[7] = i / 10 + '0';
3304 sym[8] = i % 10 + '0';
3305 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3307 && h->root.type == bfd_link_hash_undefined)
3309 if (lowest_restf > i)
3311 h->root.type = bfd_link_hash_defined;
3312 h->root.u.def.section = htab->sfpr;
3313 h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3314 + (i - lowest_restf) * 4);
3316 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3317 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3321 elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
3323 htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3324 + (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
3326 if (htab->sfpr->_raw_size == 0)
3328 if (!htab->have_undefweak)
3330 _bfd_strip_section_from_output (info, htab->sfpr);
3334 htab->sfpr->_raw_size = 4;
3337 p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size);
3340 htab->sfpr->contents = p;
3342 for (i = lowest_savef; 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, STFD_FR0_0R1 + fpr + stackoff, p);
3349 if (lowest_savef <= MAX_SAVE_FPR)
3351 bfd_put_32 (htab->elf.dynobj, BLR, p);
3355 for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
3357 unsigned int fpr = i << 21;
3358 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3359 bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
3362 if (lowest_restf <= MAX_SAVE_FPR
3363 || htab->sfpr->_raw_size == 4)
3365 bfd_put_32 (htab->elf.dynobj, BLR, p);
3371 /* Adjust a symbol defined by a dynamic object and referenced by a
3372 regular object. The current definition is in some section of the
3373 dynamic object, but we're not including those sections. We have to
3374 change the definition to something the rest of the link can
3378 ppc64_elf_adjust_dynamic_symbol (info, h)
3379 struct bfd_link_info *info;
3380 struct elf_link_hash_entry *h;
3382 struct ppc_link_hash_table *htab;
3383 struct ppc_link_hash_entry * eh;
3384 struct ppc_dyn_relocs *p;
3386 unsigned int power_of_two;
3388 htab = ppc_hash_table (info);
3390 /* Deal with function syms. */
3391 if (h->type == STT_FUNC
3392 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3394 /* Clear procedure linkage table information for any symbol that
3395 won't need a .plt entry. */
3396 if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
3397 || h->plt.refcount <= 0
3398 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3400 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3401 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
3403 h->plt.offset = (bfd_vma) -1;
3404 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3409 h->plt.offset = (bfd_vma) -1;
3411 /* If this is a weak symbol, and there is a real definition, the
3412 processor independent code will have arranged for us to see the
3413 real definition first, and we can just use the same value. */
3414 if (h->weakdef != NULL)
3416 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3417 || h->weakdef->root.type == bfd_link_hash_defweak);
3418 h->root.u.def.section = h->weakdef->root.u.def.section;
3419 h->root.u.def.value = h->weakdef->root.u.def.value;
3423 /* This is a reference to a symbol defined by a dynamic object which
3424 is not a function. */
3426 /* If we are creating a shared library, we must presume that the
3427 only references to the symbol are via the global offset table.
3428 For such cases we need not do anything here; the relocations will
3429 be handled correctly by relocate_section. */
3433 /* If there are no references to this symbol that do not use the
3434 GOT, we don't need to generate a copy reloc. */
3435 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3438 eh = (struct ppc_link_hash_entry *) h;
3439 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3441 s = p->sec->output_section;
3442 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3446 /* If we didn't find any dynamic relocs in read-only sections, then
3447 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3450 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3454 /* We must allocate the symbol in our .dynbss section, which will
3455 become part of the .bss section of the executable. There will be
3456 an entry for this symbol in the .dynsym section. The dynamic
3457 object will contain position independent code, so all references
3458 from the dynamic object to this symbol will go through the global
3459 offset table. The dynamic linker will use the .dynsym entry to
3460 determine the address it must put in the global offset table, so
3461 both the dynamic object and the regular object will refer to the
3462 same memory location for the variable. */
3464 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3465 copy the initial value out of the dynamic object and into the
3466 runtime process image. We need to remember the offset into the
3467 .rela.bss section we are going to use. */
3468 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3470 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
3471 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3474 /* We need to figure out the alignment required for this symbol. I
3475 have no idea how ELF linkers handle this. */
3476 power_of_two = bfd_log2 (h->size);
3477 if (power_of_two > 4)
3480 /* Apply the required alignment. */
3482 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3483 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3485 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3489 /* Define the symbol as being at this point in the section. */
3490 h->root.u.def.section = s;
3491 h->root.u.def.value = s->_raw_size;
3493 /* Increment the section size to make room for the symbol. */
3494 s->_raw_size += h->size;
3499 /* If given a function descriptor symbol, hide both the function code
3500 sym and the descriptor. */
3502 ppc64_elf_hide_symbol (info, h, force_local)
3503 struct bfd_link_info *info;
3504 struct elf_link_hash_entry *h;
3505 boolean force_local;
3507 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3509 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
3512 struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh;
3513 struct ppc_link_hash_table *htab;
3515 name = h->root.root.string - 1;
3516 htab = ppc_hash_table (info);
3518 fh = elf_link_hash_lookup (&htab->elf, name, false, false, false);
3520 _bfd_elf_link_hash_hide_symbol (info, fh, force_local);
3524 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3525 will be called from elflink.h. If elflink.h doesn't call our
3526 finish_dynamic_symbol routine, we'll need to do something about
3527 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3528 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3530 && ((INFO)->shared \
3531 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3532 && ((H)->dynindx != -1 \
3533 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3535 /* Allocate space in .plt, .got and associated reloc sections for
3539 allocate_dynrelocs (h, inf)
3540 struct elf_link_hash_entry *h;
3543 struct bfd_link_info *info;
3544 struct ppc_link_hash_table *htab;
3546 struct ppc_link_hash_entry *eh;
3547 struct ppc_dyn_relocs *p;
3549 if (h->root.type == bfd_link_hash_indirect)
3552 if (h->root.type == bfd_link_hash_warning)
3553 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3555 info = (struct bfd_link_info *) inf;
3556 htab = ppc_hash_table (info);
3558 if (htab->elf.dynamic_sections_created
3559 && h->plt.refcount > 0
3560 && h->dynindx != -1)
3562 BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
3564 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
3566 /* If this is the first .plt entry, make room for the special
3569 if (s->_raw_size == 0)
3570 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
3572 h->plt.offset = s->_raw_size;
3574 /* Make room for this entry. */
3575 s->_raw_size += PLT_ENTRY_SIZE;
3577 /* Make room for the .glink code. */
3579 if (s->_raw_size == 0)
3580 s->_raw_size += GLINK_CALL_STUB_SIZE;
3581 /* We need bigger stubs past index 32767. */
3582 if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
3584 s->_raw_size += 2*4;
3586 /* We also need to make an entry in the .rela.plt section. */
3588 s->_raw_size += sizeof (Elf64_External_Rela);
3592 h->plt.offset = (bfd_vma) -1;
3593 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3598 h->plt.offset = (bfd_vma) -1;
3599 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3602 if (h->got.refcount > 0)
3606 /* Make sure this symbol is output as a dynamic symbol.
3607 Undefined weak syms won't yet be marked as dynamic. */
3608 if (h->dynindx == -1
3609 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3611 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3616 h->got.offset = s->_raw_size;
3618 dyn = htab->elf.dynamic_sections_created;
3619 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
3620 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
3623 h->got.offset = (bfd_vma) -1;
3625 eh = (struct ppc_link_hash_entry *) h;
3626 if (eh->dyn_relocs == NULL)
3629 /* In the shared -Bsymbolic case, discard space allocated for
3630 dynamic pc-relative relocs against symbols which turn out to be
3631 defined in regular objects. For the normal shared case, discard
3632 space for relocs that have become local due to symbol visibility
3637 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
3638 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3641 struct ppc_dyn_relocs **pp;
3643 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3645 p->count -= p->pc_count;
3656 /* For the non-shared case, discard space for relocs against
3657 symbols which turn out to need copy relocs or are not
3660 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3661 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3662 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3663 || (htab->elf.dynamic_sections_created
3664 && (h->root.type == bfd_link_hash_undefweak
3665 || h->root.type == bfd_link_hash_undefined))))
3667 /* Make sure this symbol is output as a dynamic symbol.
3668 Undefined weak syms won't yet be marked as dynamic. */
3669 if (h->dynindx == -1
3670 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3672 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3676 /* If that succeeded, we know we'll be keeping all the
3678 if (h->dynindx != -1)
3682 eh->dyn_relocs = NULL;
3687 /* Finally, allocate space. */
3688 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3690 asection *sreloc = elf_section_data (p->sec)->sreloc;
3691 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
3697 /* Find any dynamic relocs that apply to read-only sections. */
3700 readonly_dynrelocs (h, inf)
3701 struct elf_link_hash_entry *h;
3704 struct ppc_link_hash_entry *eh;
3705 struct ppc_dyn_relocs *p;
3707 if (h->root.type == bfd_link_hash_warning)
3708 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3710 eh = (struct ppc_link_hash_entry *) h;
3711 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3713 asection *s = p->sec->output_section;
3715 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3717 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3719 info->flags |= DF_TEXTREL;
3721 /* Not an error, just cut short the traversal. */
3728 /* Set the sizes of the dynamic sections. */
3731 ppc64_elf_size_dynamic_sections (output_bfd, info)
3732 bfd *output_bfd ATTRIBUTE_UNUSED;
3733 struct bfd_link_info *info;
3735 struct ppc_link_hash_table *htab;
3741 htab = ppc_hash_table (info);
3742 dynobj = htab->elf.dynobj;
3746 if (htab->elf.dynamic_sections_created)
3748 /* Set the contents of the .interp section to the interpreter. */
3751 s = bfd_get_section_by_name (dynobj, ".interp");
3754 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3755 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3759 /* Set up .got offsets for local syms, and space for local dynamic
3761 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3763 bfd_signed_vma *local_got;
3764 bfd_signed_vma *end_local_got;
3765 bfd_size_type locsymcount;
3766 Elf_Internal_Shdr *symtab_hdr;
3769 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3772 for (s = ibfd->sections; s != NULL; s = s->next)
3774 struct ppc_dyn_relocs *p;
3776 for (p = *((struct ppc_dyn_relocs **)
3777 &elf_section_data (s)->local_dynrel);
3781 if (!bfd_is_abs_section (p->sec)
3782 && bfd_is_abs_section (p->sec->output_section))
3784 /* Input section has been discarded, either because
3785 it is a copy of a linkonce section or due to
3786 linker script /DISCARD/, so we'll be discarding
3789 else if (p->count != 0)
3791 srel = elf_section_data (p->sec)->sreloc;
3792 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
3793 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3794 info->flags |= DF_TEXTREL;
3799 local_got = elf_local_got_refcounts (ibfd);
3803 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3804 locsymcount = symtab_hdr->sh_info;
3805 end_local_got = local_got + locsymcount;
3807 srel = htab->srelgot;
3808 for (; local_got < end_local_got; ++local_got)
3812 *local_got = s->_raw_size;
3815 srel->_raw_size += sizeof (Elf64_External_Rela);
3818 *local_got = (bfd_vma) -1;
3822 /* Allocate global sym .plt and .got entries, and space for global
3823 sym dynamic relocs. */
3824 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
3826 /* We now have determined the sizes of the various dynamic sections.
3827 Allocate memory for them. */
3829 for (s = dynobj->sections; s != NULL; s = s->next)
3831 if ((s->flags & SEC_LINKER_CREATED) == 0)
3834 if (s == htab->sbrlt || s == htab->srelbrlt)
3835 /* These haven't been allocated yet; don't strip. */
3837 else if (s == htab->splt
3839 || s == htab->sglink)
3841 /* Strip this section if we don't need it; see the
3844 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
3846 if (s->_raw_size == 0)
3848 /* If we don't need this section, strip it from the
3849 output file. This is mostly to handle .rela.bss and
3850 .rela.plt. We must create both sections in
3851 create_dynamic_sections, because they must be created
3852 before the linker maps input sections to output
3853 sections. The linker does that before
3854 adjust_dynamic_symbol is called, and it is that
3855 function which decides whether anything needs to go
3856 into these sections. */
3860 if (s != htab->srelplt)
3863 /* We use the reloc_count field as a counter if we need
3864 to copy relocs into the output file. */
3870 /* It's not one of our sections, so don't allocate space. */
3874 if (s->_raw_size == 0)
3876 _bfd_strip_section_from_output (info, s);
3880 /* Allocate memory for the section contents. We use bfd_zalloc
3881 here in case unused entries are not reclaimed before the
3882 section's contents are written out. This should not happen,
3883 but this way if it does, we get a R_PPC64_NONE reloc instead
3885 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
3886 if (s->contents == NULL)
3890 if (htab->elf.dynamic_sections_created)
3892 /* Add some entries to the .dynamic section. We fill in the
3893 values later, in ppc64_elf_finish_dynamic_sections, but we
3894 must add the entries now so that we get the correct size for
3895 the .dynamic section. The DT_DEBUG entry is filled in by the
3896 dynamic linker and used by the debugger. */
3897 #define add_dynamic_entry(TAG, VAL) \
3898 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3902 if (!add_dynamic_entry (DT_DEBUG, 0))
3906 if (htab->splt->_raw_size != 0)
3908 if (!add_dynamic_entry (DT_PLTGOT, 0)
3909 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3910 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3911 || !add_dynamic_entry (DT_JMPREL, 0)
3912 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
3918 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
3919 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
3925 if (!add_dynamic_entry (DT_RELA, 0)
3926 || !add_dynamic_entry (DT_RELASZ, 0)
3927 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
3930 /* If any dynamic relocs apply to a read-only section,
3931 then we need a DT_TEXTREL entry. */
3932 if ((info->flags & DF_TEXTREL) == 0)
3933 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
3936 if ((info->flags & DF_TEXTREL) != 0)
3938 if (!add_dynamic_entry (DT_TEXTREL, 0))
3943 #undef add_dynamic_entry
3948 /* Determine the type of stub needed, if any, for a call. */
3950 static INLINE enum ppc_stub_type
3951 ppc_type_of_stub (input_sec, rel, hash, destination)
3952 asection *input_sec;
3953 const Elf_Internal_Rela *rel;
3954 struct ppc_link_hash_entry **hash;
3955 bfd_vma destination;
3957 struct ppc_link_hash_entry *h = *hash;
3959 bfd_vma branch_offset;
3960 bfd_vma max_branch_offset;
3961 unsigned int r_type;
3966 && h->oh->plt.offset != (bfd_vma) -1
3967 && h->oh->dynindx != -1)
3969 *hash = (struct ppc_link_hash_entry *) h->oh;
3970 return ppc_stub_plt_call;
3973 if (h->elf.root.type == bfd_link_hash_undefweak
3974 || h->elf.root.type == bfd_link_hash_undefined)
3975 return ppc_stub_none;
3978 /* Determine where the call point is. */
3979 location = (input_sec->output_offset
3980 + input_sec->output_section->vma
3983 branch_offset = destination - location;
3984 r_type = ELF64_R_TYPE (rel->r_info);
3986 /* Determine if a long branch stub is needed. */
3987 max_branch_offset = 1 << 25;
3988 if (r_type != (unsigned int) R_PPC64_REL24)
3989 max_branch_offset = 1 << 15;
3991 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
3992 /* We need a stub. Figure out whether a long_branch or plt_branch
3994 return ppc_stub_long_branch;
3996 return ppc_stub_none;
3999 /* Build a .plt call stub. */
4002 build_plt_stub (obfd, p, offset, glink)
4008 #define PPC_LO(v) ((v) & 0xffff)
4009 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4010 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4013 bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
4014 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
4016 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
4017 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4018 if (PPC_HA (offset + 8) != PPC_HA (offset))
4019 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4021 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
4022 if (PPC_HA (offset + 8) != PPC_HA (offset))
4023 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4025 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
4026 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4027 bfd_put_32 (obfd, BCTR, p), p += 4;
4032 ppc_build_one_stub (gen_entry, in_arg)
4033 struct bfd_hash_entry *gen_entry;
4036 struct ppc_stub_hash_entry *stub_entry;
4037 struct ppc_branch_hash_entry *br_entry;
4038 struct bfd_link_info *info;
4039 struct ppc_link_hash_table *htab;
4048 /* Massage our args to the form they really have. */
4049 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4050 info = (struct bfd_link_info *) in_arg;
4052 htab = ppc_hash_table (info);
4053 stub_sec = stub_entry->stub_sec;
4055 /* Make a note of the offset within the stubs for this entry. */
4056 stub_entry->stub_offset = stub_sec->_cooked_size;
4057 loc = stub_sec->contents + stub_entry->stub_offset;
4059 stub_bfd = stub_sec->owner;
4061 switch (stub_entry->stub_type)
4063 case ppc_stub_long_branch:
4064 /* Branches are relative. This is where we are going to. */
4065 off = (stub_entry->target_value
4066 + stub_entry->target_section->output_offset
4067 + stub_entry->target_section->output_section->vma);
4069 /* And this is where we are coming from. */
4070 off -= (stub_entry->stub_offset
4071 + stub_sec->output_offset
4072 + stub_sec->output_section->vma);
4074 BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
4076 bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc);
4080 case ppc_stub_plt_branch:
4081 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4082 stub_entry->root.string + 9,
4084 if (br_entry == NULL)
4086 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
4087 stub_entry->root.string + 9);
4088 htab->stub_error = true;
4092 off = (stub_entry->target_value
4093 + stub_entry->target_section->output_offset
4094 + stub_entry->target_section->output_section->vma);
4096 bfd_put_64 (htab->sbrlt->owner, off,
4097 htab->sbrlt->contents + br_entry->offset);
4101 /* Create a reloc for the branch lookup table entry. */
4102 Elf_Internal_Rela rela;
4103 Elf64_External_Rela *r;
4105 rela.r_offset = (br_entry->offset
4106 + htab->sbrlt->output_offset
4107 + htab->sbrlt->output_section->vma);
4108 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
4109 rela.r_addend = off;
4111 r = (Elf64_External_Rela *) htab->srelbrlt->contents;
4112 r += htab->srelbrlt->reloc_count++;
4113 bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, r);
4116 off = (br_entry->offset
4117 + htab->sbrlt->output_offset
4118 + htab->sbrlt->output_section->vma
4119 - elf_gp (htab->sbrlt->output_section->owner)
4122 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4124 (*_bfd_error_handler)
4125 (_("linkage table error against `%s'"),
4126 stub_entry->root.string);
4127 bfd_set_error (bfd_error_bad_value);
4128 htab->stub_error = true;
4133 bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc);
4134 bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4);
4135 bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8);
4136 bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12);
4140 case ppc_stub_plt_call:
4141 /* Build the .glink lazy link call stub. */
4142 p = htab->sglink->contents + htab->sglink->_cooked_size;
4143 indx = htab->sglink->reloc_count;
4146 bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p);
4151 bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p);
4153 bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
4156 bfd_put_32 (htab->sglink->owner,
4157 B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p);
4159 htab->sglink->_cooked_size = p - htab->sglink->contents;
4160 htab->sglink->reloc_count += 1;
4162 /* Now build the stub. */
4163 off = stub_entry->h->elf.plt.offset;
4164 if (off >= (bfd_vma) -2)
4167 off &= ~ (bfd_vma) 1;
4168 off += (htab->splt->output_offset
4169 + htab->splt->output_section->vma
4170 - elf_gp (htab->splt->output_section->owner)
4173 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4175 (*_bfd_error_handler)
4176 (_("linkage table error against `%s'"),
4177 stub_entry->h->elf.root.root.string);
4178 bfd_set_error (bfd_error_bad_value);
4179 htab->stub_error = true;
4183 p = build_plt_stub (stub_bfd, loc, (int) off, 0);
4192 stub_sec->_cooked_size += size;
4196 /* As above, but don't actually build the stub. Just bump offset so
4197 we know stub section sizes, and select plt_branch stubs where
4198 long_branch stubs won't do. */
4201 ppc_size_one_stub (gen_entry, in_arg)
4202 struct bfd_hash_entry *gen_entry;
4205 struct ppc_stub_hash_entry *stub_entry;
4206 struct ppc_link_hash_table *htab;
4210 /* Massage our args to the form they really have. */
4211 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4212 htab = (struct ppc_link_hash_table *) in_arg;
4214 if (stub_entry->stub_type == ppc_stub_plt_call)
4216 off = stub_entry->h->elf.plt.offset & ~(bfd_vma) 1;
4217 off += (htab->splt->output_offset
4218 + htab->splt->output_section->vma
4219 - elf_gp (htab->splt->output_section->owner)
4223 if (PPC_HA ((int) off + 16) != PPC_HA ((int) off))
4228 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4229 stub_entry->stub_type = ppc_stub_long_branch;
4232 off = (stub_entry->target_value
4233 + stub_entry->target_section->output_offset
4234 + stub_entry->target_section->output_section->vma);
4235 off -= (stub_entry->stub_sec->_raw_size
4236 + stub_entry->stub_sec->output_offset
4237 + stub_entry->stub_sec->output_section->vma);
4239 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
4241 struct ppc_branch_hash_entry *br_entry;
4243 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4244 stub_entry->root.string + 9,
4246 if (br_entry == NULL)
4248 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
4249 stub_entry->root.string + 9);
4250 htab->stub_error = true;
4254 if (br_entry->iter != htab->stub_iteration)
4256 br_entry->iter = htab->stub_iteration;
4257 br_entry->offset = htab->sbrlt->_raw_size;
4258 htab->sbrlt->_raw_size += 8;
4260 stub_entry->stub_type = ppc_stub_plt_branch;
4265 stub_entry->stub_sec->_raw_size += size;
4269 /* Set up various things so that we can make a list of input sections
4270 for each output section included in the link. Returns -1 on error,
4271 0 when no stubs will be needed, and 1 on success. */
4274 ppc64_elf_setup_section_lists (output_bfd, info)
4276 struct bfd_link_info *info;
4279 unsigned int bfd_count;
4280 int top_id, top_index;
4282 asection **input_list, **list;
4284 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4286 if (htab->elf.root.creator->flavour != bfd_target_elf_flavour
4287 || htab->sbrlt == NULL)
4290 /* Count the number of input BFDs and find the top input section id. */
4291 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
4293 input_bfd = input_bfd->link_next)
4296 for (section = input_bfd->sections;
4298 section = section->next)
4300 if (top_id < section->id)
4301 top_id = section->id;
4304 htab->bfd_count = bfd_count;
4306 amt = sizeof (struct map_stub) * (top_id + 1);
4307 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4308 if (htab->stub_group == NULL)
4311 /* We can't use output_bfd->section_count here to find the top output
4312 section index as some sections may have been removed, and
4313 _bfd_strip_section_from_output doesn't renumber the indices. */
4314 for (section = output_bfd->sections, top_index = 0;
4316 section = section->next)
4318 if (top_index < section->index)
4319 top_index = section->index;
4322 htab->top_index = top_index;
4323 amt = sizeof (asection *) * (top_index + 1);
4324 input_list = (asection **) bfd_malloc (amt);
4325 htab->input_list = input_list;
4326 if (input_list == NULL)
4329 /* For sections we aren't interested in, mark their entries with a
4330 value we can check later. */
4331 list = input_list + top_index;
4333 *list = bfd_abs_section_ptr;
4334 while (list-- != input_list);
4336 for (section = output_bfd->sections;
4338 section = section->next)
4340 if ((section->flags & SEC_CODE) != 0)
4341 input_list[section->index] = NULL;
4347 /* The linker repeatedly calls this function for each input section,
4348 in the order that input sections are linked into output sections.
4349 Build lists of input sections to determine groupings between which
4350 we may insert linker stubs. */
4353 ppc64_elf_next_input_section (info, isec)
4354 struct bfd_link_info *info;
4357 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4359 if (isec->output_section->index <= htab->top_index)
4361 asection **list = htab->input_list + isec->output_section->index;
4362 if (*list != bfd_abs_section_ptr)
4364 /* Steal the link_sec pointer for our list. */
4365 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4366 /* This happens to make the list in reverse order,
4367 which is what we want. */
4368 PREV_SEC (isec) = *list;
4374 /* See whether we can group stub sections together. Grouping stub
4375 sections may result in fewer stubs. More importantly, we need to
4376 put all .init* and .fini* stubs at the beginning of the .init or
4377 .fini output sections respectively, because glibc splits the
4378 _init and _fini functions into multiple parts. Putting a stub in
4379 the middle of a function is not a good idea. */
4382 group_sections (htab, stub_group_size, stubs_always_before_branch)
4383 struct ppc_link_hash_table *htab;
4384 bfd_size_type stub_group_size;
4385 boolean stubs_always_before_branch;
4387 asection **list = htab->input_list + htab->top_index;
4390 asection *tail = *list;
4391 if (tail == bfd_abs_section_ptr)
4393 while (tail != NULL)
4397 bfd_size_type total;
4400 if (tail->_cooked_size)
4401 total = tail->_cooked_size;
4403 total = tail->_raw_size;
4404 while ((prev = PREV_SEC (curr)) != NULL
4405 && ((total += curr->output_offset - prev->output_offset)
4409 /* OK, the size from the start of CURR to the end is less
4410 than stub_group_size and thus can be handled by one stub
4411 section. (or the tail section is itself larger than
4412 stub_group_size, in which case we may be toast.) We
4413 should really be keeping track of the total size of stubs
4414 added here, as stubs contribute to the final output
4415 section size. That's a little tricky, and this way will
4416 only break if stubs added make the total size more than
4417 2^25, ie. for the default stub_group_size, if stubs total
4418 more than 2834432 bytes, or over 100000 plt call stubs. */
4421 prev = PREV_SEC (tail);
4422 /* Set up this stub group. */
4423 htab->stub_group[tail->id].link_sec = curr;
4425 while (tail != curr && (tail = prev) != NULL);
4427 /* But wait, there's more! Input sections up to stub_group_size
4428 bytes before the stub section can be handled by it too. */
4429 if (!stubs_always_before_branch)
4433 && ((total += tail->output_offset - prev->output_offset)
4437 prev = PREV_SEC (tail);
4438 htab->stub_group[tail->id].link_sec = curr;
4444 while (list-- != htab->input_list);
4445 free (htab->input_list);
4449 /* Read in all local syms for all input bfds. */
4452 get_local_syms (input_bfd, htab)
4454 struct ppc_link_hash_table *htab;
4456 unsigned int bfd_indx;
4457 Elf_Internal_Sym *local_syms, **all_local_syms;
4459 /* We want to read in symbol extension records only once. To do this
4460 we need to read in the local symbols in parallel and save them for
4461 later use; so hold pointers to the local symbols in an array. */
4462 bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count;
4463 all_local_syms = (Elf_Internal_Sym **) bfd_zmalloc (amt);
4464 htab->all_local_syms = all_local_syms;
4465 if (all_local_syms == NULL)
4468 /* Walk over all the input BFDs, swapping in local symbols.
4469 If we are creating a shared library, create hash entries for the
4473 input_bfd = input_bfd->link_next, bfd_indx++)
4475 Elf_Internal_Shdr *symtab_hdr;
4476 Elf_Internal_Shdr *shndx_hdr;
4477 Elf_Internal_Sym *isym;
4478 Elf64_External_Sym *ext_syms, *esym, *end_sy;
4479 Elf_External_Sym_Shndx *shndx_buf, *shndx;
4480 bfd_size_type sec_size;
4482 /* We'll need the symbol table in a second. */
4483 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4484 if (symtab_hdr->sh_info == 0)
4487 /* We need an array of the local symbols attached to the input bfd.
4488 Unfortunately, we're going to have to read & swap them in. */
4489 sec_size = symtab_hdr->sh_info;
4490 sec_size *= sizeof (Elf_Internal_Sym);
4491 local_syms = (Elf_Internal_Sym *) bfd_malloc (sec_size);
4492 if (local_syms == NULL)
4495 all_local_syms[bfd_indx] = local_syms;
4496 sec_size = symtab_hdr->sh_info;
4497 sec_size *= sizeof (Elf64_External_Sym);
4498 ext_syms = (Elf64_External_Sym *) bfd_malloc (sec_size);
4499 if (ext_syms == NULL)
4502 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
4503 || bfd_bread ((PTR) ext_syms, sec_size, input_bfd) != sec_size)
4505 error_ret_free_ext_syms:
4511 shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
4512 if (shndx_hdr->sh_size != 0)
4514 sec_size = symtab_hdr->sh_info;
4515 sec_size *= sizeof (Elf_External_Sym_Shndx);
4516 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (sec_size);
4517 if (shndx_buf == NULL)
4518 goto error_ret_free_ext_syms;
4520 if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
4521 || bfd_bread ((PTR) shndx_buf, sec_size, input_bfd) != sec_size)
4524 goto error_ret_free_ext_syms;
4528 /* Swap the local symbols in. */
4529 for (esym = ext_syms, end_sy = esym + symtab_hdr->sh_info,
4530 isym = local_syms, shndx = shndx_buf;
4532 esym++, isym++, shndx = (shndx ? shndx + 1 : NULL))
4533 bfd_elf64_swap_symbol_in (input_bfd, esym, shndx, isym);
4535 /* Now we can free the external symbols. */
4543 /* Determine and set the size of the stub section for a final link.
4545 The basic idea here is to examine all the relocations looking for
4546 PC-relative calls to a target that is unreachable with a "bl"
4550 ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size,
4551 add_stub_section, layout_sections_again)
4554 struct bfd_link_info *info;
4555 bfd_signed_vma group_size;
4556 asection * (*add_stub_section) PARAMS ((const char *, asection *));
4557 void (*layout_sections_again) PARAMS ((void));
4559 bfd_size_type stub_group_size;
4560 boolean stubs_always_before_branch;
4561 boolean ret = false;
4562 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4564 /* Stash our params away. */
4565 htab->stub_bfd = stub_bfd;
4566 htab->add_stub_section = add_stub_section;
4567 htab->layout_sections_again = layout_sections_again;
4568 stubs_always_before_branch = group_size < 0;
4570 stub_group_size = -group_size;
4572 stub_group_size = group_size;
4573 if (stub_group_size == 1)
4575 /* Default values. */
4576 stub_group_size = 30720000;
4577 if (htab->has_14bit_branch)
4578 stub_group_size = 30000;
4581 group_sections (htab, stub_group_size, stubs_always_before_branch);
4583 if (! get_local_syms (info->input_bfds, htab))
4585 if (htab->all_local_syms)
4586 goto error_ret_free_local;
4593 unsigned int bfd_indx;
4595 boolean stub_changed;
4597 htab->stub_iteration += 1;
4598 stub_changed = false;
4600 for (input_bfd = info->input_bfds, bfd_indx = 0;
4602 input_bfd = input_bfd->link_next, bfd_indx++)
4604 Elf_Internal_Shdr *symtab_hdr;
4606 Elf_Internal_Sym *local_syms;
4608 /* We'll need the symbol table in a second. */
4609 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4610 if (symtab_hdr->sh_info == 0)
4613 local_syms = htab->all_local_syms[bfd_indx];
4615 /* Walk over each section attached to the input bfd. */
4616 for (section = input_bfd->sections;
4618 section = section->next)
4620 Elf_Internal_Shdr *input_rel_hdr;
4621 Elf64_External_Rela *external_relocs, *erelaend, *erela;
4622 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4625 /* If there aren't any relocs, then there's nothing more
4627 if ((section->flags & SEC_RELOC) == 0
4628 || section->reloc_count == 0)
4631 /* If this section is a link-once section that will be
4632 discarded, then don't create any stubs. */
4633 if (section->output_section == NULL
4634 || section->output_section->owner != output_bfd)
4637 /* Allocate space for the external relocations. */
4638 amt = section->reloc_count;
4639 amt *= sizeof (Elf64_External_Rela);
4640 external_relocs = (Elf64_External_Rela *) bfd_malloc (amt);
4641 if (external_relocs == NULL)
4643 goto error_ret_free_local;
4646 /* Likewise for the internal relocations. */
4647 amt = section->reloc_count;
4648 amt *= sizeof (Elf_Internal_Rela);
4649 internal_relocs = (Elf_Internal_Rela *) bfd_malloc (amt);
4650 if (internal_relocs == NULL)
4652 free (external_relocs);
4653 goto error_ret_free_local;
4656 /* Read in the external relocs. */
4657 input_rel_hdr = &elf_section_data (section)->rel_hdr;
4658 if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0
4659 || bfd_bread ((PTR) external_relocs,
4660 input_rel_hdr->sh_size,
4661 input_bfd) != input_rel_hdr->sh_size)
4663 free (external_relocs);
4664 error_ret_free_internal:
4665 free (internal_relocs);
4666 goto error_ret_free_local;
4669 /* Swap in the relocs. */
4670 erela = external_relocs;
4671 erelaend = erela + section->reloc_count;
4672 irela = internal_relocs;
4673 for (; erela < erelaend; erela++, irela++)
4674 bfd_elf64_swap_reloca_in (input_bfd, erela, irela);
4676 /* We're done with the external relocs, free them. */
4677 free (external_relocs);
4679 /* Now examine each relocation. */
4680 irela = internal_relocs;
4681 irelaend = irela + section->reloc_count;
4682 for (; irela < irelaend; irela++)
4684 unsigned int r_type, r_indx;
4685 enum ppc_stub_type stub_type;
4686 struct ppc_stub_hash_entry *stub_entry;
4689 bfd_vma destination;
4690 struct ppc_link_hash_entry *hash;
4692 const asection *id_sec;
4694 r_type = ELF64_R_TYPE (irela->r_info);
4695 r_indx = ELF64_R_SYM (irela->r_info);
4697 if (r_type >= (unsigned int) R_PPC_max)
4699 bfd_set_error (bfd_error_bad_value);
4700 goto error_ret_free_internal;
4703 /* Only look for stubs on branch instructions. */
4704 if (r_type != (unsigned int) R_PPC64_REL24
4705 && r_type != (unsigned int) R_PPC64_REL14
4706 && r_type != (unsigned int) R_PPC64_REL14_BRTAKEN
4707 && r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN)
4710 /* Now determine the call target, its name, value,
4716 if (r_indx < symtab_hdr->sh_info)
4718 /* It's a local symbol. */
4719 Elf_Internal_Sym *sym;
4720 Elf_Internal_Shdr *hdr;
4722 sym = local_syms + r_indx;
4723 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4724 sym_sec = hdr->bfd_section;
4725 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4726 sym_value = sym->st_value;
4727 destination = (sym_value + irela->r_addend
4728 + sym_sec->output_offset
4729 + sym_sec->output_section->vma);
4733 /* It's an external symbol. */
4736 e_indx = r_indx - symtab_hdr->sh_info;
4737 hash = ((struct ppc_link_hash_entry *)
4738 elf_sym_hashes (input_bfd)[e_indx]);
4740 while (hash->elf.root.type == bfd_link_hash_indirect
4741 || hash->elf.root.type == bfd_link_hash_warning)
4742 hash = ((struct ppc_link_hash_entry *)
4743 hash->elf.root.u.i.link);
4745 if (hash->elf.root.type == bfd_link_hash_defined
4746 || hash->elf.root.type == bfd_link_hash_defweak)
4748 sym_sec = hash->elf.root.u.def.section;
4749 sym_value = hash->elf.root.u.def.value;
4750 if (sym_sec->output_section != NULL)
4751 destination = (sym_value + irela->r_addend
4752 + sym_sec->output_offset
4753 + sym_sec->output_section->vma);
4755 else if (hash->elf.root.type == bfd_link_hash_undefweak)
4757 else if (hash->elf.root.type == bfd_link_hash_undefined)
4761 bfd_set_error (bfd_error_bad_value);
4762 goto error_ret_free_internal;
4766 /* Determine what (if any) linker stub is needed. */
4767 stub_type = ppc_type_of_stub (section, irela, &hash,
4769 if (stub_type == ppc_stub_none)
4772 /* Support for grouping stub sections. */
4773 id_sec = htab->stub_group[section->id].link_sec;
4775 /* Get the name of this stub. */
4776 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
4778 goto error_ret_free_internal;
4780 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4781 stub_name, false, false);
4782 if (stub_entry != NULL)
4784 /* The proper stub has already been created. */
4789 stub_entry = ppc_add_stub (stub_name, section, htab);
4790 if (stub_entry == NULL)
4793 goto error_ret_free_local;
4796 stub_entry->target_value = sym_value;
4797 stub_entry->target_section = sym_sec;
4798 stub_entry->stub_type = stub_type;
4799 stub_entry->h = hash;
4800 stub_changed = true;
4803 /* We're done with the internal relocs, free them. */
4804 free (internal_relocs);
4811 /* OK, we've added some stubs. Find out the new size of the
4813 for (stub_sec = htab->stub_bfd->sections;
4815 stub_sec = stub_sec->next)
4817 stub_sec->_raw_size = 0;
4818 stub_sec->_cooked_size = 0;
4820 htab->sbrlt->_raw_size = 0;
4821 htab->sbrlt->_cooked_size = 0;
4823 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab);
4825 /* Ask the linker to do its stuff. */
4826 (*htab->layout_sections_again) ();
4829 if (htab->sbrlt->_raw_size == 0)
4831 _bfd_strip_section_from_output (info, htab->sbrlt);
4832 if (htab->srelbrlt != NULL)
4833 _bfd_strip_section_from_output (info, htab->srelbrlt);
4838 error_ret_free_local:
4839 while (htab->bfd_count-- > 0)
4840 if (htab->all_local_syms[htab->bfd_count])
4841 free (htab->all_local_syms[htab->bfd_count]);
4842 free (htab->all_local_syms);
4847 /* Called after we have determined section placement. If sections
4848 move, we'll be called again. Provide a value for TOCstart. */
4851 ppc64_elf_toc (obfd)
4857 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
4858 order. The TOC starts where the first of these sections starts. */
4859 s = bfd_get_section_by_name (obfd, ".got");
4861 s = bfd_get_section_by_name (obfd, ".toc");
4863 s = bfd_get_section_by_name (obfd, ".tocbss");
4865 s = bfd_get_section_by_name (obfd, ".plt");
4868 /* This may happen for
4869 o references to TOC base (SYM@toc / TOC[tc0]) without a
4872 o --gc-sections and empty TOC sections
4874 FIXME: Warn user? */
4876 /* Look for a likely section. We probably won't even be
4878 for (s = obfd->sections; s != NULL; s = s->next)
4879 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
4880 == (SEC_ALLOC | SEC_SMALL_DATA))
4883 for (s = obfd->sections; s != NULL; s = s->next)
4884 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
4885 == (SEC_ALLOC | SEC_SMALL_DATA))
4888 for (s = obfd->sections; s != NULL; s = s->next)
4889 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
4892 for (s = obfd->sections; s != NULL; s = s->next)
4893 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
4899 TOCstart = s->output_section->vma + s->output_offset;
4904 /* Build all the stubs associated with the current output file.
4905 The stubs are kept in a hash table attached to the main linker
4906 hash table. This function is called via gldelf64ppc_finish. */
4909 ppc64_elf_build_stubs (info)
4910 struct bfd_link_info *info;
4912 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4917 for (stub_sec = htab->stub_bfd->sections;
4919 stub_sec = stub_sec->next)
4923 /* Allocate memory to hold the linker stubs. */
4924 size = stub_sec->_raw_size;
4927 stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size);
4928 if (stub_sec->contents == NULL)
4931 stub_sec->_cooked_size = 0;
4934 if (htab->splt != NULL)
4936 /* Build the .glink plt call stub. */
4937 plt_r2 = (htab->splt->output_offset
4938 + htab->splt->output_section->vma
4939 - elf_gp (htab->splt->output_section->owner)
4941 p = htab->sglink->contents;
4942 p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
4943 while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE)
4945 bfd_put_32 (htab->sglink->owner, NOP, p);
4948 htab->sglink->_cooked_size = p - htab->sglink->contents;
4950 /* Use reloc_count to count entries. */
4951 htab->sglink->reloc_count = 0;
4954 if (htab->sbrlt->_raw_size != 0)
4956 htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner,
4957 htab->sbrlt->_raw_size);
4958 if (htab->sbrlt->contents == NULL)
4962 /* Build the stubs as directed by the stub hash table. */
4963 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
4964 htab->sglink->reloc_count = 0;
4966 for (stub_sec = htab->stub_bfd->sections;
4968 stub_sec = stub_sec->next)
4970 if (stub_sec->_raw_size != stub_sec->_cooked_size)
4974 if (stub_sec != NULL
4975 || htab->sglink->_raw_size != htab->sglink->_cooked_size)
4977 htab->stub_error = true;
4978 (*_bfd_error_handler) (_("stubs don't match calculated size"));
4981 return !htab->stub_error;
4984 /* Set up any other section flags and such that may be necessary. */
4987 ppc64_elf_fake_sections (abfd, shdr, asect)
4988 bfd *abfd ATTRIBUTE_UNUSED;
4989 Elf64_Internal_Shdr *shdr;
4992 if ((asect->flags & SEC_EXCLUDE) != 0)
4993 shdr->sh_flags |= SHF_EXCLUDE;
4995 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
4996 shdr->sh_type = SHT_ORDERED;
5001 /* The RELOCATE_SECTION function is called by the ELF backend linker
5002 to handle the relocations for a section.
5004 The relocs are always passed as Rela structures; if the section
5005 actually uses Rel structures, the r_addend field will always be
5008 This function is responsible for adjust the section contents as
5009 necessary, and (if using Rela relocs and generating a
5010 relocateable output file) adjusting the reloc addend as
5013 This function does not have to worry about setting the reloc
5014 address or the reloc symbol index.
5016 LOCAL_SYMS is a pointer to the swapped in local symbols.
5018 LOCAL_SECTIONS is an array giving the section in the input file
5019 corresponding to the st_shndx field of each local symbol.
5021 The global hash table entry for the global symbols can be found
5022 via elf_sym_hashes (input_bfd).
5024 When generating relocateable output, this function must handle
5025 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5026 going to be the section symbol corresponding to the output
5027 section, which means that the addend must be adjusted
5031 ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
5032 contents, relocs, local_syms, local_sections)
5034 struct bfd_link_info *info;
5036 asection *input_section;
5038 Elf_Internal_Rela *relocs;
5039 Elf_Internal_Sym *local_syms;
5040 asection **local_sections;
5042 struct ppc_link_hash_table *htab;
5043 Elf_Internal_Shdr *symtab_hdr;
5044 struct elf_link_hash_entry **sym_hashes;
5045 Elf_Internal_Rela *rel;
5046 Elf_Internal_Rela *relend;
5047 bfd_vma *local_got_offsets;
5051 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5052 boolean is_power4 = false;
5054 /* Initialize howto table if needed. */
5055 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5058 htab = ppc_hash_table (info);
5059 local_got_offsets = elf_local_got_offsets (input_bfd);
5060 TOCstart = elf_gp (output_bfd);
5061 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5062 sym_hashes = elf_sym_hashes (input_bfd);
5063 is_opd = strcmp (bfd_get_section_name (abfd, input_section), ".opd") == 0;
5066 relend = relocs + input_section->reloc_count;
5067 for (; rel < relend; rel++)
5069 enum elf_ppc_reloc_type r_type;
5072 bfd_reloc_status_type r;
5073 Elf_Internal_Sym *sym;
5075 struct elf_link_hash_entry *h;
5076 struct elf_link_hash_entry *fdh;
5077 const char *sym_name;
5078 unsigned long r_symndx;
5080 boolean unresolved_reloc;
5082 struct ppc_stub_hash_entry *stub_entry;
5083 bfd_vma max_br_offset;
5086 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
5087 r_symndx = ELF64_R_SYM (rel->r_info);
5089 if (info->relocateable)
5091 /* This is a relocatable link. We don't have to change
5092 anything, unless the reloc is against a section symbol,
5093 in which case we have to adjust according to where the
5094 section symbol winds up in the output section. */
5095 if (r_symndx < symtab_hdr->sh_info)
5097 sym = local_syms + r_symndx;
5098 if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5100 sec = local_sections[r_symndx];
5101 rel->r_addend += sec->output_offset + sym->st_value;
5107 /* This is a final link. */
5109 offset = rel->r_offset;
5110 addend = rel->r_addend;
5111 r = bfd_reloc_other;
5112 sym = (Elf_Internal_Sym *) 0;
5113 sec = (asection *) 0;
5114 h = (struct elf_link_hash_entry *) 0;
5115 sym_name = (const char *) 0;
5116 unresolved_reloc = false;
5118 if (r_type == R_PPC64_TOC)
5120 /* Relocation value is TOC base. Symbol is ignored. */
5121 relocation = TOCstart + TOC_BASE_OFF;
5123 else if (r_symndx < symtab_hdr->sh_info)
5125 /* It's a local symbol. */
5126 sym = local_syms + r_symndx;
5127 sec = local_sections[r_symndx];
5128 sym_name = "<local symbol>";
5130 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
5134 /* It's a global symbol. */
5135 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5136 while (h->root.type == bfd_link_hash_indirect
5137 || h->root.type == bfd_link_hash_warning)
5138 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5139 sym_name = h->root.root.string;
5141 if (h->root.type == bfd_link_hash_defined
5142 || h->root.type == bfd_link_hash_defweak)
5144 sec = h->root.u.def.section;
5145 if (sec->output_section == NULL)
5146 /* Set a flag that will be cleared later if we find a
5147 relocation value for this symbol. output_section
5148 is typically NULL for symbols satisfied by a shared
5150 unresolved_reloc = true;
5152 relocation = (h->root.u.def.value
5153 + sec->output_section->vma
5154 + sec->output_offset);
5156 else if (h->root.type == bfd_link_hash_undefweak)
5158 else if (info->shared
5159 && (!info->symbolic || info->allow_shlib_undefined)
5160 && !info->no_undefined
5161 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
5165 if (! ((*info->callbacks->undefined_symbol)
5166 (info, h->root.root.string, input_bfd, input_section,
5167 offset, (!info->shared
5168 || info->no_undefined
5169 || ELF_ST_VISIBILITY (h->other)))))
5174 /* First handle relocations that tweak non-addend part of insn. */
5181 /* Branch taken prediction relocations. */
5182 case R_PPC64_ADDR14_BRTAKEN:
5183 case R_PPC64_REL14_BRTAKEN:
5184 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5187 /* Branch not taken prediction relocations. */
5188 case R_PPC64_ADDR14_BRNTAKEN:
5189 case R_PPC64_REL14_BRNTAKEN:
5190 insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
5193 /* Set 'a' bit. This is 0b00010 in BO field for branch
5194 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5195 for branch on CTR insns (BO == 1a00t or 1a01t). */
5196 if ((insn & (0x14 << 21)) == (0x04 << 21))
5198 else if ((insn & (0x14 << 21)) == (0x10 << 21))
5206 + input_section->output_offset
5207 + input_section->output_section->vma);
5209 /* Invert 'y' bit if not the default. */
5210 if ((bfd_signed_vma) (relocation + addend - from) < 0)
5214 bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
5218 /* A REL24 branching to a linkage function is followed by a
5219 nop. We replace the nop with a ld in order to restore
5220 the TOC base pointer. Only calls to shared objects need
5221 to alter the TOC base. These are recognized by their
5222 need for a PLT entry. */
5224 && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL
5225 && fdh->plt.offset != (bfd_vma) -1
5226 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
5227 rel, htab)) != NULL)
5229 boolean can_plt_call = 0;
5231 if (offset + 8 <= input_section->_cooked_size)
5233 insn = bfd_get_32 (input_bfd, contents + offset + 4);
5235 || insn == CROR_151515 || insn == CROR_313131)
5237 bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1,
5238 contents + offset + 4);
5245 /* If this is a plain branch rather than a branch
5246 and link, don't require a nop. */
5247 insn = bfd_get_32 (input_bfd, contents + offset);
5248 if ((insn & 1) == 0)
5254 relocation = (stub_entry->stub_offset
5255 + stub_entry->stub_sec->output_offset
5256 + stub_entry->stub_sec->output_section->vma);
5258 unresolved_reloc = false;
5263 && h->root.type == bfd_link_hash_undefweak
5267 /* Tweak calls to undefined weak functions to point at a
5268 blr. We can thus call a weak function without first
5269 checking whether the function is defined. We have a
5270 blr at the end of .sfpr. */
5271 BFD_ASSERT (htab->sfpr->_raw_size != 0);
5272 relocation = (htab->sfpr->_raw_size - 4
5273 + htab->sfpr->output_offset
5274 + htab->sfpr->output_section->vma);
5276 + input_section->output_offset
5277 + input_section->output_section->vma);
5279 /* But let's not be silly about it. If the blr isn't in
5280 reach, just go to the next instruction. */
5281 if (relocation - from + (1 << 25) >= (1 << 26)
5282 || htab->sfpr->_raw_size == 0)
5283 relocation = from + 4;
5292 (*_bfd_error_handler)
5293 (_("%s: unknown relocation type %d for symbol %s"),
5294 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
5296 bfd_set_error (bfd_error_bad_value);
5301 case R_PPC_GNU_VTINHERIT:
5302 case R_PPC_GNU_VTENTRY:
5305 /* GOT16 relocations. Like an ADDR16 using the symbol's
5306 address in the GOT as relocation value instead of the
5307 symbols value itself. Also, create a GOT entry for the
5308 symbol and put the symbol value there. */
5310 case R_PPC64_GOT16_LO:
5311 case R_PPC64_GOT16_HI:
5312 case R_PPC64_GOT16_HA:
5313 case R_PPC64_GOT16_DS:
5314 case R_PPC64_GOT16_LO_DS:
5316 /* Relocation is to the entry for this symbol in the global
5320 if (htab->sgot == NULL)
5327 off = h->got.offset;
5328 dyn = htab->elf.dynamic_sections_created;
5329 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
5333 || (h->elf_link_hash_flags
5334 & ELF_LINK_FORCED_LOCAL))
5335 && (h->elf_link_hash_flags
5336 & ELF_LINK_HASH_DEF_REGULAR)))
5338 /* This is actually a static link, or it is a
5339 -Bsymbolic link and the symbol is defined
5340 locally, or the symbol was forced to be local
5341 because of a version file. We must initialize
5342 this entry in the global offset table. Since the
5343 offset must always be a multiple of 8, we use the
5344 least significant bit to record whether we have
5345 initialized it already.
5347 When doing a dynamic link, we create a .rel.got
5348 relocation entry to initialize the value. This
5349 is done in the finish_dynamic_symbol routine. */
5354 bfd_put_64 (output_bfd, relocation,
5355 htab->sgot->contents + off);
5360 unresolved_reloc = false;
5364 if (local_got_offsets == NULL)
5367 off = local_got_offsets[r_symndx];
5369 /* The offset must always be a multiple of 8. We use
5370 the least significant bit to record whether we have
5371 already processed this entry. */
5376 bfd_put_64 (output_bfd, relocation,
5377 htab->sgot->contents + off);
5381 Elf_Internal_Rela outrel;
5382 Elf64_External_Rela *loc;
5384 /* We need to generate a R_PPC64_RELATIVE reloc
5385 for the dynamic linker. */
5386 outrel.r_offset = (htab->sgot->output_section->vma
5387 + htab->sgot->output_offset
5389 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5390 outrel.r_addend = relocation;
5391 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5392 loc += htab->srelgot->reloc_count++;
5393 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5396 local_got_offsets[r_symndx] |= 1;
5400 if (off >= (bfd_vma) -2)
5403 relocation = htab->sgot->output_offset + off;
5405 /* TOC base (r2) is TOC start plus 0x8000. */
5406 addend -= TOC_BASE_OFF;
5410 case R_PPC64_PLT16_HA:
5411 case R_PPC64_PLT16_HI:
5412 case R_PPC64_PLT16_LO:
5415 /* Relocation is to the entry for this symbol in the
5416 procedure linkage table. */
5418 /* Resolve a PLT reloc against a local symbol directly,
5419 without using the procedure linkage table. */
5423 if (h->plt.offset == (bfd_vma) -1
5424 || htab->splt == NULL)
5426 /* We didn't make a PLT entry for this symbol. This
5427 happens when statically linking PIC code, or when
5428 using -Bsymbolic. */
5432 relocation = (htab->splt->output_section->vma
5433 + htab->splt->output_offset
5435 unresolved_reloc = false;
5438 /* TOC16 relocs. We want the offset relative to the TOC base,
5439 which is the address of the start of the TOC plus 0x8000.
5440 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5443 case R_PPC64_TOC16_LO:
5444 case R_PPC64_TOC16_HI:
5445 case R_PPC64_TOC16_DS:
5446 case R_PPC64_TOC16_LO_DS:
5447 case R_PPC64_TOC16_HA:
5448 addend -= TOCstart + TOC_BASE_OFF;
5451 /* Relocate against the beginning of the section. */
5452 case R_PPC64_SECTOFF:
5453 case R_PPC64_SECTOFF_LO:
5454 case R_PPC64_SECTOFF_HI:
5455 case R_PPC64_SECTOFF_DS:
5456 case R_PPC64_SECTOFF_LO_DS:
5457 case R_PPC64_SECTOFF_HA:
5458 if (sec != (asection *) 0)
5459 addend -= sec->output_section->vma;
5463 case R_PPC64_REL14_BRNTAKEN:
5464 case R_PPC64_REL14_BRTAKEN:
5468 /* Relocations that may need to be propagated if this is a
5472 case R_PPC64_ADDR14:
5473 case R_PPC64_ADDR14_BRNTAKEN:
5474 case R_PPC64_ADDR14_BRTAKEN:
5475 case R_PPC64_ADDR16:
5476 case R_PPC64_ADDR16_DS:
5477 case R_PPC64_ADDR16_HA:
5478 case R_PPC64_ADDR16_HI:
5479 case R_PPC64_ADDR16_HIGHER:
5480 case R_PPC64_ADDR16_HIGHERA:
5481 case R_PPC64_ADDR16_HIGHEST:
5482 case R_PPC64_ADDR16_HIGHESTA:
5483 case R_PPC64_ADDR16_LO:
5484 case R_PPC64_ADDR16_LO_DS:
5485 case R_PPC64_ADDR24:
5486 case R_PPC64_ADDR30:
5487 case R_PPC64_ADDR32:
5488 case R_PPC64_ADDR64:
5489 case R_PPC64_UADDR16:
5490 case R_PPC64_UADDR32:
5491 case R_PPC64_UADDR64:
5492 /* r_symndx will be zero only for relocs against symbols
5493 from removed linkonce sections, or sections discarded by
5500 if ((input_section->flags & SEC_ALLOC) == 0)
5503 if (NO_OPD_RELOCS && is_opd)
5507 && (IS_ABSOLUTE_RELOC (r_type)
5510 && (! info->symbolic
5511 || (h->elf_link_hash_flags
5512 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
5516 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5517 && (((h->elf_link_hash_flags
5518 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5519 && (h->elf_link_hash_flags
5520 & ELF_LINK_HASH_DEF_REGULAR) == 0)
5521 || h->root.type == bfd_link_hash_undefweak
5522 || h->root.type == bfd_link_hash_undefined)))
5524 Elf_Internal_Rela outrel;
5525 boolean skip, relocate;
5527 Elf64_External_Rela *loc;
5529 /* When generating a dynamic object, these relocations
5530 are copied into the output file to be resolved at run
5537 _bfd_elf_section_offset (output_bfd, info, input_section,
5539 if (outrel.r_offset == (bfd_vma) -1)
5541 else if (outrel.r_offset == (bfd_vma) -2)
5542 skip = true, relocate = true;
5543 outrel.r_offset += (input_section->output_section->vma
5544 + input_section->output_offset);
5545 outrel.r_addend = addend;
5548 memset (&outrel, 0, sizeof outrel);
5552 && (!IS_ABSOLUTE_RELOC (r_type)
5555 || (h->elf_link_hash_flags
5556 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5557 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
5560 /* This symbol is local, or marked to become local,
5561 or this is an opd section reloc which must point
5562 at a local function. */
5563 outrel.r_addend += relocation;
5565 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
5567 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5573 if (bfd_is_abs_section (sec))
5575 else if (sec == NULL || sec->owner == NULL)
5577 bfd_set_error (bfd_error_bad_value);
5584 osec = sec->output_section;
5585 indx = elf_section_data (osec)->dynindx;
5587 /* We are turning this relocation into one
5588 against a section symbol, so subtract out
5589 the output section's address but not the
5590 offset of the input section in the output
5592 outrel.r_addend -= osec->vma;
5595 outrel.r_info = ELF64_R_INFO (indx, r_type);
5599 sreloc = elf_section_data (input_section)->sreloc;
5603 loc = (Elf64_External_Rela *) sreloc->contents;
5604 loc += sreloc->reloc_count++;
5605 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5607 /* If this reloc is against an external symbol, it will
5608 be computed at runtime, so there's no need to do
5616 case R_PPC64_GLOB_DAT:
5617 case R_PPC64_JMP_SLOT:
5618 case R_PPC64_RELATIVE:
5619 /* We shouldn't ever see these dynamic relocs in relocatable
5623 case R_PPC64_PLTGOT16:
5624 case R_PPC64_PLTGOT16_DS:
5625 case R_PPC64_PLTGOT16_HA:
5626 case R_PPC64_PLTGOT16_HI:
5627 case R_PPC64_PLTGOT16_LO:
5628 case R_PPC64_PLTGOT16_LO_DS:
5629 case R_PPC64_PLTREL32:
5630 case R_PPC64_PLTREL64:
5631 /* These ones haven't been implemented yet. */
5633 (*_bfd_error_handler)
5634 (_("%s: Relocation %s is not supported for symbol %s."),
5635 bfd_archive_filename (input_bfd),
5636 ppc64_elf_howto_table[(int) r_type]->name, sym_name);
5638 bfd_set_error (bfd_error_invalid_operation);
5643 /* Do any further special processing. */
5649 case R_PPC64_ADDR16_HA:
5650 case R_PPC64_ADDR16_HIGHERA:
5651 case R_PPC64_ADDR16_HIGHESTA:
5652 case R_PPC64_PLT16_HA:
5653 case R_PPC64_TOC16_HA:
5654 case R_PPC64_SECTOFF_HA:
5655 /* It's just possible that this symbol is a weak symbol
5656 that's not actually defined anywhere. In that case,
5657 'sec' would be NULL, and we should leave the symbol
5658 alone (it will be set to zero elsewhere in the link). */
5660 /* Add 0x10000 if sign bit in 0:15 is set. */
5661 addend += ((relocation + addend) & 0x8000) << 1;
5664 case R_PPC64_ADDR16_DS:
5665 case R_PPC64_ADDR16_LO_DS:
5666 case R_PPC64_GOT16_DS:
5667 case R_PPC64_GOT16_LO_DS:
5668 case R_PPC64_PLT16_LO_DS:
5669 case R_PPC64_SECTOFF_DS:
5670 case R_PPC64_SECTOFF_LO_DS:
5671 case R_PPC64_TOC16_DS:
5672 case R_PPC64_TOC16_LO_DS:
5673 case R_PPC64_PLTGOT16_DS:
5674 case R_PPC64_PLTGOT16_LO_DS:
5675 if (((relocation + addend) & 3) != 0)
5677 (*_bfd_error_handler)
5678 (_("%s: error: relocation %s not a multiple of 4"),
5679 bfd_archive_filename (input_bfd),
5680 ppc64_elf_howto_table[(int) r_type]->name);
5681 bfd_set_error (bfd_error_bad_value);
5688 case R_PPC64_REL14_BRNTAKEN:
5689 case R_PPC64_REL14_BRTAKEN:
5690 max_br_offset = 1 << 15;
5694 max_br_offset = 1 << 25;
5697 /* If the branch is out of reach, then redirect the
5698 call to the local stub for this function. */
5700 + input_section->output_offset
5701 + input_section->output_section->vma);
5702 if (relocation + addend - from + max_br_offset >= 2 * max_br_offset
5703 && (stub_entry = ppc_get_stub_entry (input_section, sec, h,
5704 rel, htab)) != NULL)
5706 /* Munge up the value and addend so that we call the stub
5707 rather than the procedure directly. */
5708 relocation = (stub_entry->stub_offset
5709 + stub_entry->stub_sec->output_offset
5710 + stub_entry->stub_sec->output_section->vma);
5716 /* FIXME: Why do we allow debugging sections to escape this error?
5717 More importantly, why do we not emit dynamic relocs above in
5718 debugging sections (which are ! SEC_ALLOC)? If we had
5719 emitted the dynamic reloc, we could remove the fudge here. */
5720 if (unresolved_reloc
5722 && (input_section->flags & SEC_DEBUGGING) != 0
5723 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5724 (*_bfd_error_handler)
5725 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5726 bfd_archive_filename (input_bfd),
5727 bfd_get_section_name (input_bfd, input_section),
5728 (long) rel->r_offset,
5729 h->root.root.string);
5731 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
5739 if (r == bfd_reloc_ok)
5741 else if (r == bfd_reloc_overflow)
5747 if (h->root.type == bfd_link_hash_undefweak
5748 && ppc64_elf_howto_table[(int) r_type]->pc_relative)
5750 /* Assume this is a call protected by other code that
5751 detects the symbol is undefined. If this is the case,
5752 we can safely ignore the overflow. If not, the
5753 program is hosed anyway, and a little warning isn't
5759 name = h->root.root.string;
5763 name = bfd_elf_string_from_elf_section (input_bfd,
5764 symtab_hdr->sh_link,
5769 name = bfd_section_name (input_bfd, sec);
5772 if (! ((*info->callbacks->reloc_overflow)
5773 (info, name, ppc64_elf_howto_table[(int) r_type]->name,
5774 (bfd_vma) 0, input_bfd, input_section, offset)))
5784 /* Finish up dynamic symbol handling. We set the contents of various
5785 dynamic sections here. */
5788 ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5790 struct bfd_link_info *info;
5791 struct elf_link_hash_entry *h;
5792 Elf_Internal_Sym *sym;
5794 struct ppc_link_hash_table *htab;
5797 htab = ppc_hash_table (info);
5798 dynobj = htab->elf.dynobj;
5800 if (h->plt.offset != (bfd_vma) -1
5801 && ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
5803 Elf_Internal_Rela rela;
5804 Elf64_External_Rela *loc;
5806 /* This symbol has an entry in the procedure linkage table. Set
5809 if (htab->splt == NULL
5810 || htab->srelplt == NULL
5811 || htab->sglink == NULL)
5814 /* Create a JMP_SLOT reloc to inform the dynamic linker to
5815 fill in the PLT entry. */
5817 rela.r_offset = (htab->splt->output_section->vma
5818 + htab->splt->output_offset
5820 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
5823 loc = (Elf64_External_Rela *) htab->srelplt->contents;
5824 loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
5825 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5828 if (h->got.offset != (bfd_vma) -1)
5830 Elf_Internal_Rela rela;
5831 Elf64_External_Rela *loc;
5833 /* This symbol has an entry in the global offset table. Set it
5836 if (htab->sgot == NULL || htab->srelgot == NULL)
5839 rela.r_offset = (htab->sgot->output_section->vma
5840 + htab->sgot->output_offset
5841 + (h->got.offset &~ (bfd_vma) 1));
5843 /* If this is a static link, or it is a -Bsymbolic link and the
5844 symbol is defined locally or was forced to be local because
5845 of a version file, we just want to emit a RELATIVE reloc.
5846 The entry in the global offset table will already have been
5847 initialized in the relocate_section function. */
5851 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
5852 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
5854 BFD_ASSERT((h->got.offset & 1) != 0);
5855 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5856 rela.r_addend = (h->root.u.def.value
5857 + h->root.u.def.section->output_section->vma
5858 + h->root.u.def.section->output_offset);
5862 BFD_ASSERT ((h->got.offset & 1) == 0);
5863 bfd_put_64 (output_bfd, (bfd_vma) 0,
5864 htab->sgot->contents + h->got.offset);
5865 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
5869 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5870 loc += htab->srelgot->reloc_count++;
5871 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5874 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
5876 Elf_Internal_Rela rela;
5877 Elf64_External_Rela *loc;
5879 /* This symbol needs a copy reloc. Set it up. */
5881 if (h->dynindx == -1
5882 || (h->root.type != bfd_link_hash_defined
5883 && h->root.type != bfd_link_hash_defweak)
5884 || htab->srelbss == NULL)
5887 rela.r_offset = (h->root.u.def.value
5888 + h->root.u.def.section->output_section->vma
5889 + h->root.u.def.section->output_offset);
5890 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
5892 loc = (Elf64_External_Rela *) htab->srelbss->contents;
5893 loc += htab->srelbss->reloc_count++;
5894 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5897 /* Mark some specially defined symbols as absolute. */
5898 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
5899 sym->st_shndx = SHN_ABS;
5904 /* Used to decide how to sort relocs in an optimal manner for the
5905 dynamic linker, before writing them out. */
5907 static enum elf_reloc_type_class
5908 ppc64_elf_reloc_type_class (rela)
5909 const Elf_Internal_Rela *rela;
5911 enum elf_ppc_reloc_type r_type;
5913 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
5916 case R_PPC64_RELATIVE:
5917 return reloc_class_relative;
5918 case R_PPC64_JMP_SLOT:
5919 return reloc_class_plt;
5921 return reloc_class_copy;
5923 return reloc_class_normal;
5927 /* Finish up the dynamic sections. */
5930 ppc64_elf_finish_dynamic_sections (output_bfd, info)
5932 struct bfd_link_info *info;
5934 struct ppc_link_hash_table *htab;
5938 htab = ppc_hash_table (info);
5939 dynobj = htab->elf.dynobj;
5940 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5942 if (htab->elf.dynamic_sections_created)
5944 Elf64_External_Dyn *dyncon, *dynconend;
5946 if (sdyn == NULL || htab->sgot == NULL)
5949 dyncon = (Elf64_External_Dyn *) sdyn->contents;
5950 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
5951 for (; dyncon < dynconend; dyncon++)
5953 Elf_Internal_Dyn dyn;
5956 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
5963 case DT_PPC64_GLINK:
5964 dyn.d_un.d_ptr = (htab->sglink->output_section->vma
5965 + htab->sglink->output_offset);
5969 s = bfd_get_section_by_name (output_bfd, ".opd");
5971 dyn.d_un.d_ptr = s->vma;
5974 case DT_PPC64_OPDSZ:
5975 s = bfd_get_section_by_name (output_bfd, ".opd");
5977 dyn.d_un.d_val = s->_raw_size;
5981 dyn.d_un.d_ptr = (htab->splt->output_section->vma
5982 + htab->splt->output_offset);
5986 dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
5987 + htab->srelplt->output_offset);
5991 dyn.d_un.d_val = htab->srelplt->_raw_size;
5995 /* Don't count procedure linkage table relocs in the
5996 overall reloc count. */
5997 if (htab->srelplt != NULL)
5998 dyn.d_un.d_val -= htab->srelplt->_raw_size;
6002 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
6006 if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
6008 /* Fill in the first entry in the global offset table.
6009 We use it to hold the link-time TOCbase. */
6010 bfd_put_64 (output_bfd,
6011 elf_gp (output_bfd) + TOC_BASE_OFF,
6012 htab->sgot->contents);
6014 /* Set .got entry size. */
6015 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
6018 if (htab->splt != NULL && htab->splt->_raw_size != 0)
6020 /* Set .plt entry size. */
6021 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
6028 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6029 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6030 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6031 #define TARGET_BIG_NAME "elf64-powerpc"
6032 #define ELF_ARCH bfd_arch_powerpc
6033 #define ELF_MACHINE_CODE EM_PPC64
6034 #define ELF_MAXPAGESIZE 0x10000
6035 #define elf_info_to_howto ppc64_elf_info_to_howto
6037 #ifdef EM_CYGNUS_POWERPC
6038 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6042 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6045 #define elf_backend_want_got_sym 0
6046 #define elf_backend_want_plt_sym 0
6047 #define elf_backend_plt_alignment 3
6048 #define elf_backend_plt_not_loaded 1
6049 #define elf_backend_got_symbol_offset 0
6050 #define elf_backend_got_header_size 8
6051 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6052 #define elf_backend_can_gc_sections 1
6053 #define elf_backend_can_refcount 1
6055 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6056 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
6057 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6058 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6059 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6061 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
6062 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6063 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6064 #define elf_backend_check_relocs ppc64_elf_check_relocs
6065 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6066 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6067 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6068 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6069 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6070 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6071 #define elf_backend_fake_sections ppc64_elf_fake_sections
6072 #define elf_backend_relocate_section ppc64_elf_relocate_section
6073 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6074 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6075 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6077 #include "elf64-target.h"