1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003 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. */
30 #include "elf/ppc64.h"
31 #include "elf64-ppc.h"
33 static void ppc_howto_init
35 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
36 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
37 static void ppc64_elf_info_to_howto
38 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
));
39 static bfd_reloc_status_type ppc64_elf_ha_reloc
40 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
41 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
42 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
43 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
44 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
45 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
46 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
47 static bfd_reloc_status_type ppc64_elf_toc_reloc
48 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
49 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
50 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
51 static bfd_reloc_status_type ppc64_elf_toc64_reloc
52 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
53 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
54 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
55 static bfd_boolean ppc64_elf_object_p
57 static bfd_boolean ppc64_elf_merge_private_bfd_data
58 PARAMS ((bfd
*, bfd
*));
61 /* The name of the dynamic interpreter. This is put in the .interp
63 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
65 /* The size in bytes of an entry in the procedure linkage table. */
66 #define PLT_ENTRY_SIZE 24
68 /* The initial size of the plt reserved for the dynamic linker. */
69 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
71 /* TOC base pointers offset from start of TOC. */
72 #define TOC_BASE_OFF (0x8000)
74 /* .plt call stub instructions. */
75 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
76 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
77 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
78 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
79 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
80 /* ld %r11,xxx+16@l(%r12) */
81 #define BCTR 0x4e800420 /* bctr */
83 /* The normal stub is this size. */
84 #define PLT_CALL_STUB_SIZE (7*4)
86 /* But sometimes the .plt entry crosses a 64k boundary, and we need
87 to adjust the high word with this insn. */
88 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
90 /* The .glink fixup call stub is the same as the .plt call stub, but
91 the first instruction restores r2, and the std is omitted. */
92 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
94 /* Always allow this much space. */
95 #define GLINK_CALL_STUB_SIZE (8*4)
98 #define NOP 0x60000000
100 /* Some other nops. */
101 #define CROR_151515 0x4def7b82
102 #define CROR_313131 0x4ffffb82
104 /* .glink entries for the first 32k functions are two instructions. */
105 #define LI_R0_0 0x38000000 /* li %r0,0 */
106 #define B_DOT 0x48000000 /* b . */
108 /* After that, we need two instructions to load the index, followed by
110 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
111 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
113 /* Instructions to save and restore floating point regs. */
114 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
115 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
116 #define BLR 0x4e800020 /* blr */
118 /* Since .opd is an array of descriptors and each entry will end up
119 with identical R_PPC64_RELATIVE relocs, there is really no need to
120 propagate .opd relocs; The dynamic linker should be taught to
121 relocate .opd without reloc entries. */
122 #ifndef NO_OPD_RELOCS
123 #define NO_OPD_RELOCS 0
126 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
128 /* Relocation HOWTO's. */
129 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
131 static reloc_howto_type ppc64_elf_howto_raw
[] = {
132 /* This reloc does nothing. */
133 HOWTO (R_PPC64_NONE
, /* type */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
137 FALSE
, /* pc_relative */
139 complain_overflow_dont
, /* complain_on_overflow */
140 bfd_elf_generic_reloc
, /* special_function */
141 "R_PPC64_NONE", /* name */
142 FALSE
, /* partial_inplace */
145 FALSE
), /* pcrel_offset */
147 /* A standard 32 bit relocation. */
148 HOWTO (R_PPC64_ADDR32
, /* type */
150 2, /* size (0 = byte, 1 = short, 2 = long) */
152 FALSE
, /* pc_relative */
154 complain_overflow_bitfield
, /* complain_on_overflow */
155 bfd_elf_generic_reloc
, /* special_function */
156 "R_PPC64_ADDR32", /* name */
157 FALSE
, /* partial_inplace */
159 0xffffffff, /* dst_mask */
160 FALSE
), /* pcrel_offset */
162 /* An absolute 26 bit branch; the lower two bits must be zero.
163 FIXME: we don't check that, we just clear them. */
164 HOWTO (R_PPC64_ADDR24
, /* type */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
168 FALSE
, /* pc_relative */
170 complain_overflow_bitfield
, /* complain_on_overflow */
171 bfd_elf_generic_reloc
, /* special_function */
172 "R_PPC64_ADDR24", /* name */
173 FALSE
, /* partial_inplace */
175 0x03fffffc, /* dst_mask */
176 FALSE
), /* pcrel_offset */
178 /* A standard 16 bit relocation. */
179 HOWTO (R_PPC64_ADDR16
, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 FALSE
, /* pc_relative */
185 complain_overflow_bitfield
, /* complain_on_overflow */
186 bfd_elf_generic_reloc
, /* special_function */
187 "R_PPC64_ADDR16", /* name */
188 FALSE
, /* partial_inplace */
190 0xffff, /* dst_mask */
191 FALSE
), /* pcrel_offset */
193 /* A 16 bit relocation without overflow. */
194 HOWTO (R_PPC64_ADDR16_LO
, /* type */
196 1, /* size (0 = byte, 1 = short, 2 = long) */
198 FALSE
, /* pc_relative */
200 complain_overflow_dont
,/* complain_on_overflow */
201 bfd_elf_generic_reloc
, /* special_function */
202 "R_PPC64_ADDR16_LO", /* name */
203 FALSE
, /* partial_inplace */
205 0xffff, /* dst_mask */
206 FALSE
), /* pcrel_offset */
208 /* Bits 16-31 of an address. */
209 HOWTO (R_PPC64_ADDR16_HI
, /* type */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
213 FALSE
, /* pc_relative */
215 complain_overflow_dont
, /* complain_on_overflow */
216 bfd_elf_generic_reloc
, /* special_function */
217 "R_PPC64_ADDR16_HI", /* name */
218 FALSE
, /* partial_inplace */
220 0xffff, /* dst_mask */
221 FALSE
), /* pcrel_offset */
223 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
224 bits, treated as a signed number, is negative. */
225 HOWTO (R_PPC64_ADDR16_HA
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 FALSE
, /* pc_relative */
231 complain_overflow_dont
, /* complain_on_overflow */
232 ppc64_elf_ha_reloc
, /* special_function */
233 "R_PPC64_ADDR16_HA", /* name */
234 FALSE
, /* partial_inplace */
236 0xffff, /* dst_mask */
237 FALSE
), /* pcrel_offset */
239 /* An absolute 16 bit branch; the lower two bits must be zero.
240 FIXME: we don't check that, we just clear them. */
241 HOWTO (R_PPC64_ADDR14
, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 FALSE
, /* pc_relative */
247 complain_overflow_bitfield
, /* complain_on_overflow */
248 bfd_elf_generic_reloc
, /* special_function */
249 "R_PPC64_ADDR14", /* name */
250 FALSE
, /* partial_inplace */
252 0x0000fffc, /* dst_mask */
253 FALSE
), /* pcrel_offset */
255 /* An absolute 16 bit branch, for which bit 10 should be set to
256 indicate that the branch is expected to be taken. The lower two
257 bits must be zero. */
258 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 FALSE
, /* pc_relative */
264 complain_overflow_bitfield
, /* complain_on_overflow */
265 ppc64_elf_brtaken_reloc
, /* special_function */
266 "R_PPC64_ADDR14_BRTAKEN",/* name */
267 FALSE
, /* partial_inplace */
269 0x0000fffc, /* dst_mask */
270 FALSE
), /* pcrel_offset */
272 /* An absolute 16 bit branch, for which bit 10 should be set to
273 indicate that the branch is not expected to be taken. The lower
274 two bits must be zero. */
275 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE
, /* pc_relative */
281 complain_overflow_bitfield
, /* complain_on_overflow */
282 ppc64_elf_brtaken_reloc
, /* special_function */
283 "R_PPC64_ADDR14_BRNTAKEN",/* name */
284 FALSE
, /* partial_inplace */
286 0x0000fffc, /* dst_mask */
287 FALSE
), /* pcrel_offset */
289 /* A relative 26 bit branch; the lower two bits must be zero. */
290 HOWTO (R_PPC64_REL24
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 TRUE
, /* pc_relative */
296 complain_overflow_signed
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_PPC64_REL24", /* name */
299 FALSE
, /* partial_inplace */
301 0x03fffffc, /* dst_mask */
302 TRUE
), /* pcrel_offset */
304 /* A relative 16 bit branch; the lower two bits must be zero. */
305 HOWTO (R_PPC64_REL14
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 TRUE
, /* pc_relative */
311 complain_overflow_signed
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_PPC64_REL14", /* name */
314 FALSE
, /* partial_inplace */
316 0x0000fffc, /* dst_mask */
317 TRUE
), /* pcrel_offset */
319 /* A relative 16 bit branch. Bit 10 should be set to indicate that
320 the branch is expected to be taken. The lower two bits must be
322 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 TRUE
, /* pc_relative */
328 complain_overflow_signed
, /* complain_on_overflow */
329 ppc64_elf_brtaken_reloc
, /* special_function */
330 "R_PPC64_REL14_BRTAKEN", /* name */
331 FALSE
, /* partial_inplace */
333 0x0000fffc, /* dst_mask */
334 TRUE
), /* pcrel_offset */
336 /* A relative 16 bit branch. Bit 10 should be set to indicate that
337 the branch is not expected to be taken. The lower two bits must
339 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 TRUE
, /* pc_relative */
345 complain_overflow_signed
, /* complain_on_overflow */
346 ppc64_elf_brtaken_reloc
, /* special_function */
347 "R_PPC64_REL14_BRNTAKEN",/* name */
348 FALSE
, /* partial_inplace */
350 0x0000fffc, /* dst_mask */
351 TRUE
), /* pcrel_offset */
353 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
355 HOWTO (R_PPC64_GOT16
, /* type */
357 1, /* size (0 = byte, 1 = short, 2 = long) */
359 FALSE
, /* pc_relative */
361 complain_overflow_signed
, /* complain_on_overflow */
362 ppc64_elf_unhandled_reloc
, /* special_function */
363 "R_PPC64_GOT16", /* name */
364 FALSE
, /* partial_inplace */
366 0xffff, /* dst_mask */
367 FALSE
), /* pcrel_offset */
369 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
371 HOWTO (R_PPC64_GOT16_LO
, /* type */
373 1, /* size (0 = byte, 1 = short, 2 = long) */
375 FALSE
, /* pc_relative */
377 complain_overflow_dont
, /* complain_on_overflow */
378 ppc64_elf_unhandled_reloc
, /* special_function */
379 "R_PPC64_GOT16_LO", /* name */
380 FALSE
, /* partial_inplace */
382 0xffff, /* dst_mask */
383 FALSE
), /* pcrel_offset */
385 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
387 HOWTO (R_PPC64_GOT16_HI
, /* type */
389 1, /* size (0 = byte, 1 = short, 2 = long) */
391 FALSE
, /* pc_relative */
393 complain_overflow_dont
,/* complain_on_overflow */
394 ppc64_elf_unhandled_reloc
, /* special_function */
395 "R_PPC64_GOT16_HI", /* name */
396 FALSE
, /* partial_inplace */
398 0xffff, /* dst_mask */
399 FALSE
), /* pcrel_offset */
401 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
403 HOWTO (R_PPC64_GOT16_HA
, /* type */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
407 FALSE
, /* pc_relative */
409 complain_overflow_dont
,/* complain_on_overflow */
410 ppc64_elf_unhandled_reloc
, /* special_function */
411 "R_PPC64_GOT16_HA", /* name */
412 FALSE
, /* partial_inplace */
414 0xffff, /* dst_mask */
415 FALSE
), /* pcrel_offset */
417 /* This is used only by the dynamic linker. The symbol should exist
418 both in the object being run and in some shared library. The
419 dynamic linker copies the data addressed by the symbol from the
420 shared library into the object, because the object being
421 run has to have the data at some particular address. */
422 HOWTO (R_PPC64_COPY
, /* type */
424 0, /* this one is variable size */
426 FALSE
, /* pc_relative */
428 complain_overflow_dont
, /* complain_on_overflow */
429 ppc64_elf_unhandled_reloc
, /* special_function */
430 "R_PPC64_COPY", /* name */
431 FALSE
, /* partial_inplace */
434 FALSE
), /* pcrel_offset */
436 /* Like R_PPC64_ADDR64, but used when setting global offset table
438 HOWTO (R_PPC64_GLOB_DAT
, /* type */
440 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
442 FALSE
, /* pc_relative */
444 complain_overflow_dont
, /* complain_on_overflow */
445 ppc64_elf_unhandled_reloc
, /* special_function */
446 "R_PPC64_GLOB_DAT", /* name */
447 FALSE
, /* partial_inplace */
449 ONES (64), /* dst_mask */
450 FALSE
), /* pcrel_offset */
452 /* Created by the link editor. Marks a procedure linkage table
453 entry for a symbol. */
454 HOWTO (R_PPC64_JMP_SLOT
, /* type */
456 0, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE
, /* pc_relative */
460 complain_overflow_dont
, /* complain_on_overflow */
461 ppc64_elf_unhandled_reloc
, /* special_function */
462 "R_PPC64_JMP_SLOT", /* name */
463 FALSE
, /* partial_inplace */
466 FALSE
), /* pcrel_offset */
468 /* Used only by the dynamic linker. When the object is run, this
469 doubleword64 is set to the load address of the object, plus the
471 HOWTO (R_PPC64_RELATIVE
, /* type */
473 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
475 FALSE
, /* pc_relative */
477 complain_overflow_dont
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_PPC64_RELATIVE", /* name */
480 FALSE
, /* partial_inplace */
482 ONES (64), /* dst_mask */
483 FALSE
), /* pcrel_offset */
485 /* Like R_PPC64_ADDR32, but may be unaligned. */
486 HOWTO (R_PPC64_UADDR32
, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 FALSE
, /* pc_relative */
492 complain_overflow_bitfield
, /* complain_on_overflow */
493 bfd_elf_generic_reloc
, /* special_function */
494 "R_PPC64_UADDR32", /* name */
495 FALSE
, /* partial_inplace */
497 0xffffffff, /* dst_mask */
498 FALSE
), /* pcrel_offset */
500 /* Like R_PPC64_ADDR16, but may be unaligned. */
501 HOWTO (R_PPC64_UADDR16
, /* type */
503 1, /* size (0 = byte, 1 = short, 2 = long) */
505 FALSE
, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_PPC64_UADDR16", /* name */
510 FALSE
, /* partial_inplace */
512 0xffff, /* dst_mask */
513 FALSE
), /* pcrel_offset */
515 /* 32-bit PC relative. */
516 HOWTO (R_PPC64_REL32
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 TRUE
, /* pc_relative */
522 /* FIXME: Verify. Was complain_overflow_bitfield. */
523 complain_overflow_signed
, /* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_PPC64_REL32", /* name */
526 FALSE
, /* partial_inplace */
528 0xffffffff, /* dst_mask */
529 TRUE
), /* pcrel_offset */
531 /* 32-bit relocation to the symbol's procedure linkage table. */
532 HOWTO (R_PPC64_PLT32
, /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 FALSE
, /* pc_relative */
538 complain_overflow_bitfield
, /* complain_on_overflow */
539 ppc64_elf_unhandled_reloc
, /* special_function */
540 "R_PPC64_PLT32", /* name */
541 FALSE
, /* partial_inplace */
543 0xffffffff, /* dst_mask */
544 FALSE
), /* pcrel_offset */
546 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
547 FIXME: R_PPC64_PLTREL32 not supported. */
548 HOWTO (R_PPC64_PLTREL32
, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 TRUE
, /* pc_relative */
554 complain_overflow_signed
, /* complain_on_overflow */
555 bfd_elf_generic_reloc
, /* special_function */
556 "R_PPC64_PLTREL32", /* name */
557 FALSE
, /* partial_inplace */
559 0xffffffff, /* dst_mask */
560 TRUE
), /* pcrel_offset */
562 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
564 HOWTO (R_PPC64_PLT16_LO
, /* type */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
568 FALSE
, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 ppc64_elf_unhandled_reloc
, /* special_function */
572 "R_PPC64_PLT16_LO", /* name */
573 FALSE
, /* partial_inplace */
575 0xffff, /* dst_mask */
576 FALSE
), /* pcrel_offset */
578 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
580 HOWTO (R_PPC64_PLT16_HI
, /* type */
582 1, /* size (0 = byte, 1 = short, 2 = long) */
584 FALSE
, /* pc_relative */
586 complain_overflow_dont
, /* complain_on_overflow */
587 ppc64_elf_unhandled_reloc
, /* special_function */
588 "R_PPC64_PLT16_HI", /* name */
589 FALSE
, /* partial_inplace */
591 0xffff, /* dst_mask */
592 FALSE
), /* pcrel_offset */
594 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
596 HOWTO (R_PPC64_PLT16_HA
, /* type */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE
, /* pc_relative */
602 complain_overflow_dont
, /* complain_on_overflow */
603 ppc64_elf_unhandled_reloc
, /* special_function */
604 "R_PPC64_PLT16_HA", /* name */
605 FALSE
, /* partial_inplace */
607 0xffff, /* dst_mask */
608 FALSE
), /* pcrel_offset */
610 /* 16-bit section relative relocation. */
611 HOWTO (R_PPC64_SECTOFF
, /* type */
613 1, /* size (0 = byte, 1 = short, 2 = long) */
615 FALSE
, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 ppc64_elf_sectoff_reloc
, /* special_function */
619 "R_PPC64_SECTOFF", /* name */
620 FALSE
, /* partial_inplace */
622 0xffff, /* dst_mask */
623 FALSE
), /* pcrel_offset */
625 /* Like R_PPC64_SECTOFF, but no overflow warning. */
626 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
628 1, /* size (0 = byte, 1 = short, 2 = long) */
630 FALSE
, /* pc_relative */
632 complain_overflow_dont
, /* complain_on_overflow */
633 ppc64_elf_sectoff_reloc
, /* special_function */
634 "R_PPC64_SECTOFF_LO", /* name */
635 FALSE
, /* partial_inplace */
637 0xffff, /* dst_mask */
638 FALSE
), /* pcrel_offset */
640 /* 16-bit upper half section relative relocation. */
641 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
643 1, /* size (0 = byte, 1 = short, 2 = long) */
645 FALSE
, /* pc_relative */
647 complain_overflow_dont
, /* complain_on_overflow */
648 ppc64_elf_sectoff_reloc
, /* special_function */
649 "R_PPC64_SECTOFF_HI", /* name */
650 FALSE
, /* partial_inplace */
652 0xffff, /* dst_mask */
653 FALSE
), /* pcrel_offset */
655 /* 16-bit upper half adjusted section relative relocation. */
656 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
658 1, /* size (0 = byte, 1 = short, 2 = long) */
660 FALSE
, /* pc_relative */
662 complain_overflow_dont
, /* complain_on_overflow */
663 ppc64_elf_sectoff_ha_reloc
, /* special_function */
664 "R_PPC64_SECTOFF_HA", /* name */
665 FALSE
, /* partial_inplace */
667 0xffff, /* dst_mask */
668 FALSE
), /* pcrel_offset */
670 /* Like R_PPC64_REL24 without touching the two least significant bits. */
671 HOWTO (R_PPC64_REL30
, /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 TRUE
, /* pc_relative */
677 complain_overflow_dont
, /* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 "R_PPC64_REL30", /* name */
680 FALSE
, /* partial_inplace */
682 0xfffffffc, /* dst_mask */
683 TRUE
), /* pcrel_offset */
685 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
687 /* A standard 64-bit relocation. */
688 HOWTO (R_PPC64_ADDR64
, /* type */
690 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
692 FALSE
, /* pc_relative */
694 complain_overflow_dont
, /* complain_on_overflow */
695 bfd_elf_generic_reloc
, /* special_function */
696 "R_PPC64_ADDR64", /* name */
697 FALSE
, /* partial_inplace */
699 ONES (64), /* dst_mask */
700 FALSE
), /* pcrel_offset */
702 /* The bits 32-47 of an address. */
703 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
705 1, /* size (0 = byte, 1 = short, 2 = long) */
707 FALSE
, /* pc_relative */
709 complain_overflow_dont
, /* complain_on_overflow */
710 bfd_elf_generic_reloc
, /* special_function */
711 "R_PPC64_ADDR16_HIGHER", /* name */
712 FALSE
, /* partial_inplace */
714 0xffff, /* dst_mask */
715 FALSE
), /* pcrel_offset */
717 /* The bits 32-47 of an address, plus 1 if the contents of the low
718 16 bits, treated as a signed number, is negative. */
719 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
721 1, /* size (0 = byte, 1 = short, 2 = long) */
723 FALSE
, /* pc_relative */
725 complain_overflow_dont
, /* complain_on_overflow */
726 ppc64_elf_ha_reloc
, /* special_function */
727 "R_PPC64_ADDR16_HIGHERA", /* name */
728 FALSE
, /* partial_inplace */
730 0xffff, /* dst_mask */
731 FALSE
), /* pcrel_offset */
733 /* The bits 48-63 of an address. */
734 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
736 1, /* size (0 = byte, 1 = short, 2 = long) */
738 FALSE
, /* pc_relative */
740 complain_overflow_dont
, /* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_PPC64_ADDR16_HIGHEST", /* name */
743 FALSE
, /* partial_inplace */
745 0xffff, /* dst_mask */
746 FALSE
), /* pcrel_offset */
748 /* The bits 48-63 of an address, plus 1 if the contents of the low
749 16 bits, treated as a signed number, is negative. */
750 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
752 1, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE
, /* pc_relative */
756 complain_overflow_dont
, /* complain_on_overflow */
757 ppc64_elf_ha_reloc
, /* special_function */
758 "R_PPC64_ADDR16_HIGHESTA", /* name */
759 FALSE
, /* partial_inplace */
761 0xffff, /* dst_mask */
762 FALSE
), /* pcrel_offset */
764 /* Like ADDR64, but may be unaligned. */
765 HOWTO (R_PPC64_UADDR64
, /* type */
767 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
769 FALSE
, /* pc_relative */
771 complain_overflow_dont
, /* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 "R_PPC64_UADDR64", /* name */
774 FALSE
, /* partial_inplace */
776 ONES (64), /* dst_mask */
777 FALSE
), /* pcrel_offset */
779 /* 64-bit relative relocation. */
780 HOWTO (R_PPC64_REL64
, /* type */
782 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
784 TRUE
, /* pc_relative */
786 complain_overflow_dont
, /* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* special_function */
788 "R_PPC64_REL64", /* name */
789 FALSE
, /* partial_inplace */
791 ONES (64), /* dst_mask */
792 TRUE
), /* pcrel_offset */
794 /* 64-bit relocation to the symbol's procedure linkage table. */
795 HOWTO (R_PPC64_PLT64
, /* type */
797 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
799 FALSE
, /* pc_relative */
801 complain_overflow_dont
, /* complain_on_overflow */
802 ppc64_elf_unhandled_reloc
, /* special_function */
803 "R_PPC64_PLT64", /* name */
804 FALSE
, /* partial_inplace */
806 ONES (64), /* dst_mask */
807 FALSE
), /* pcrel_offset */
809 /* 64-bit PC relative relocation to the symbol's procedure linkage
811 /* FIXME: R_PPC64_PLTREL64 not supported. */
812 HOWTO (R_PPC64_PLTREL64
, /* type */
814 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
816 TRUE
, /* pc_relative */
818 complain_overflow_dont
, /* complain_on_overflow */
819 ppc64_elf_unhandled_reloc
, /* special_function */
820 "R_PPC64_PLTREL64", /* name */
821 FALSE
, /* partial_inplace */
823 ONES (64), /* dst_mask */
824 TRUE
), /* pcrel_offset */
826 /* 16 bit TOC-relative relocation. */
828 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
829 HOWTO (R_PPC64_TOC16
, /* type */
831 1, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_signed
, /* complain_on_overflow */
836 ppc64_elf_toc_reloc
, /* special_function */
837 "R_PPC64_TOC16", /* name */
838 FALSE
, /* partial_inplace */
840 0xffff, /* dst_mask */
841 FALSE
), /* pcrel_offset */
843 /* 16 bit TOC-relative relocation without overflow. */
845 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
846 HOWTO (R_PPC64_TOC16_LO
, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE
, /* pc_relative */
852 complain_overflow_dont
, /* complain_on_overflow */
853 ppc64_elf_toc_reloc
, /* special_function */
854 "R_PPC64_TOC16_LO", /* name */
855 FALSE
, /* partial_inplace */
857 0xffff, /* dst_mask */
858 FALSE
), /* pcrel_offset */
860 /* 16 bit TOC-relative relocation, high 16 bits. */
862 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
863 HOWTO (R_PPC64_TOC16_HI
, /* type */
865 1, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE
, /* pc_relative */
869 complain_overflow_dont
, /* complain_on_overflow */
870 ppc64_elf_toc_reloc
, /* special_function */
871 "R_PPC64_TOC16_HI", /* name */
872 FALSE
, /* partial_inplace */
874 0xffff, /* dst_mask */
875 FALSE
), /* pcrel_offset */
877 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
878 contents of the low 16 bits, treated as a signed number, is
881 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
882 HOWTO (R_PPC64_TOC16_HA
, /* type */
884 1, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE
, /* pc_relative */
888 complain_overflow_dont
, /* complain_on_overflow */
889 ppc64_elf_toc_ha_reloc
, /* special_function */
890 "R_PPC64_TOC16_HA", /* name */
891 FALSE
, /* partial_inplace */
893 0xffff, /* dst_mask */
894 FALSE
), /* pcrel_offset */
896 /* 64-bit relocation; insert value of TOC base (.TOC.). */
898 /* R_PPC64_TOC 51 doubleword64 .TOC. */
899 HOWTO (R_PPC64_TOC
, /* type */
901 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
903 FALSE
, /* pc_relative */
905 complain_overflow_bitfield
, /* complain_on_overflow */
906 ppc64_elf_toc64_reloc
, /* special_function */
907 "R_PPC64_TOC", /* name */
908 FALSE
, /* partial_inplace */
910 ONES (64), /* dst_mask */
911 FALSE
), /* pcrel_offset */
913 /* Like R_PPC64_GOT16, but also informs the link editor that the
914 value to relocate may (!) refer to a PLT entry which the link
915 editor (a) may replace with the symbol value. If the link editor
916 is unable to fully resolve the symbol, it may (b) create a PLT
917 entry and store the address to the new PLT entry in the GOT.
918 This permits lazy resolution of function symbols at run time.
919 The link editor may also skip all of this and just (c) emit a
920 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
921 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
922 HOWTO (R_PPC64_PLTGOT16
, /* type */
924 1, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE
, /* pc_relative */
928 complain_overflow_signed
, /* complain_on_overflow */
929 ppc64_elf_unhandled_reloc
, /* special_function */
930 "R_PPC64_PLTGOT16", /* name */
931 FALSE
, /* partial_inplace */
933 0xffff, /* dst_mask */
934 FALSE
), /* pcrel_offset */
936 /* Like R_PPC64_PLTGOT16, but without overflow. */
937 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
938 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
940 1, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_dont
, /* complain_on_overflow */
945 ppc64_elf_unhandled_reloc
, /* special_function */
946 "R_PPC64_PLTGOT16_LO", /* name */
947 FALSE
, /* partial_inplace */
949 0xffff, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
953 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
954 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
956 1, /* size (0 = byte, 1 = short, 2 = long) */
958 FALSE
, /* pc_relative */
960 complain_overflow_dont
, /* complain_on_overflow */
961 ppc64_elf_unhandled_reloc
, /* special_function */
962 "R_PPC64_PLTGOT16_HI", /* name */
963 FALSE
, /* partial_inplace */
965 0xffff, /* dst_mask */
966 FALSE
), /* pcrel_offset */
968 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
969 1 if the contents of the low 16 bits, treated as a signed number,
971 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
972 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
974 1, /* size (0 = byte, 1 = short, 2 = long) */
976 FALSE
, /* pc_relative */
978 complain_overflow_dont
,/* complain_on_overflow */
979 ppc64_elf_unhandled_reloc
, /* special_function */
980 "R_PPC64_PLTGOT16_HA", /* name */
981 FALSE
, /* partial_inplace */
983 0xffff, /* dst_mask */
984 FALSE
), /* pcrel_offset */
986 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
987 HOWTO (R_PPC64_ADDR16_DS
, /* type */
989 1, /* size (0 = byte, 1 = short, 2 = long) */
991 FALSE
, /* pc_relative */
993 complain_overflow_bitfield
, /* complain_on_overflow */
994 bfd_elf_generic_reloc
, /* special_function */
995 "R_PPC64_ADDR16_DS", /* name */
996 FALSE
, /* partial_inplace */
998 0xfffc, /* dst_mask */
999 FALSE
), /* pcrel_offset */
1001 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1002 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1004 1, /* size (0 = byte, 1 = short, 2 = long) */
1006 FALSE
, /* pc_relative */
1008 complain_overflow_dont
,/* complain_on_overflow */
1009 bfd_elf_generic_reloc
, /* special_function */
1010 "R_PPC64_ADDR16_LO_DS",/* name */
1011 FALSE
, /* partial_inplace */
1013 0xfffc, /* dst_mask */
1014 FALSE
), /* pcrel_offset */
1016 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1017 HOWTO (R_PPC64_GOT16_DS
, /* type */
1019 1, /* size (0 = byte, 1 = short, 2 = long) */
1021 FALSE
, /* pc_relative */
1023 complain_overflow_signed
, /* complain_on_overflow */
1024 ppc64_elf_unhandled_reloc
, /* special_function */
1025 "R_PPC64_GOT16_DS", /* name */
1026 FALSE
, /* partial_inplace */
1028 0xfffc, /* dst_mask */
1029 FALSE
), /* pcrel_offset */
1031 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1032 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1034 1, /* size (0 = byte, 1 = short, 2 = long) */
1036 FALSE
, /* pc_relative */
1038 complain_overflow_dont
, /* complain_on_overflow */
1039 ppc64_elf_unhandled_reloc
, /* special_function */
1040 "R_PPC64_GOT16_LO_DS", /* name */
1041 FALSE
, /* partial_inplace */
1043 0xfffc, /* dst_mask */
1044 FALSE
), /* pcrel_offset */
1046 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1047 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1049 1, /* size (0 = byte, 1 = short, 2 = long) */
1051 FALSE
, /* pc_relative */
1053 complain_overflow_dont
, /* complain_on_overflow */
1054 ppc64_elf_unhandled_reloc
, /* special_function */
1055 "R_PPC64_PLT16_LO_DS", /* name */
1056 FALSE
, /* partial_inplace */
1058 0xfffc, /* dst_mask */
1059 FALSE
), /* pcrel_offset */
1061 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1062 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1064 1, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE
, /* pc_relative */
1068 complain_overflow_bitfield
, /* complain_on_overflow */
1069 ppc64_elf_sectoff_reloc
, /* special_function */
1070 "R_PPC64_SECTOFF_DS", /* name */
1071 FALSE
, /* partial_inplace */
1073 0xfffc, /* dst_mask */
1074 FALSE
), /* pcrel_offset */
1076 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1077 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1079 1, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE
, /* pc_relative */
1083 complain_overflow_dont
, /* complain_on_overflow */
1084 ppc64_elf_sectoff_reloc
, /* special_function */
1085 "R_PPC64_SECTOFF_LO_DS",/* name */
1086 FALSE
, /* partial_inplace */
1088 0xfffc, /* dst_mask */
1089 FALSE
), /* pcrel_offset */
1091 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1092 HOWTO (R_PPC64_TOC16_DS
, /* type */
1094 1, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE
, /* pc_relative */
1098 complain_overflow_signed
, /* complain_on_overflow */
1099 ppc64_elf_toc_reloc
, /* special_function */
1100 "R_PPC64_TOC16_DS", /* name */
1101 FALSE
, /* partial_inplace */
1103 0xfffc, /* dst_mask */
1104 FALSE
), /* pcrel_offset */
1106 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1107 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1109 1, /* size (0 = byte, 1 = short, 2 = long) */
1111 FALSE
, /* pc_relative */
1113 complain_overflow_dont
, /* complain_on_overflow */
1114 ppc64_elf_toc_reloc
, /* special_function */
1115 "R_PPC64_TOC16_LO_DS", /* name */
1116 FALSE
, /* partial_inplace */
1118 0xfffc, /* dst_mask */
1119 FALSE
), /* pcrel_offset */
1121 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1122 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1123 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1125 1, /* size (0 = byte, 1 = short, 2 = long) */
1127 FALSE
, /* pc_relative */
1129 complain_overflow_signed
, /* complain_on_overflow */
1130 ppc64_elf_unhandled_reloc
, /* special_function */
1131 "R_PPC64_PLTGOT16_DS", /* name */
1132 FALSE
, /* partial_inplace */
1134 0xfffc, /* dst_mask */
1135 FALSE
), /* pcrel_offset */
1137 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1138 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1139 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1141 1, /* size (0 = byte, 1 = short, 2 = long) */
1143 FALSE
, /* pc_relative */
1145 complain_overflow_dont
, /* complain_on_overflow */
1146 ppc64_elf_unhandled_reloc
, /* special_function */
1147 "R_PPC64_PLTGOT16_LO_DS",/* name */
1148 FALSE
, /* partial_inplace */
1150 0xfffc, /* dst_mask */
1151 FALSE
), /* pcrel_offset */
1153 /* GNU extension to record C++ vtable hierarchy. */
1154 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1156 0, /* size (0 = byte, 1 = short, 2 = long) */
1158 FALSE
, /* pc_relative */
1160 complain_overflow_dont
, /* complain_on_overflow */
1161 NULL
, /* special_function */
1162 "R_PPC64_GNU_VTINHERIT", /* name */
1163 FALSE
, /* partial_inplace */
1166 FALSE
), /* pcrel_offset */
1168 /* GNU extension to record C++ vtable member usage. */
1169 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1171 0, /* size (0 = byte, 1 = short, 2 = long) */
1173 FALSE
, /* pc_relative */
1175 complain_overflow_dont
, /* complain_on_overflow */
1176 NULL
, /* special_function */
1177 "R_PPC64_GNU_VTENTRY", /* name */
1178 FALSE
, /* partial_inplace */
1181 FALSE
), /* pcrel_offset */
1185 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1191 unsigned int i
, type
;
1194 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1197 type
= ppc64_elf_howto_raw
[i
].type
;
1198 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1199 / sizeof (ppc64_elf_howto_table
[0])));
1200 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1204 static reloc_howto_type
*
1205 ppc64_elf_reloc_type_lookup (abfd
, code
)
1206 bfd
*abfd ATTRIBUTE_UNUSED
;
1207 bfd_reloc_code_real_type code
;
1209 enum elf_ppc64_reloc_type ppc_reloc
= R_PPC64_NONE
;
1211 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1212 /* Initialize howto table if needed. */
1218 return (reloc_howto_type
*) NULL
;
1220 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1222 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1224 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1226 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1228 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1230 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1232 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1234 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1236 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1238 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1240 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1242 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1244 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1246 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1248 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1250 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1252 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1254 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1256 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1258 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1260 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1262 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1264 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1266 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1268 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1270 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1272 case BFD_RELOC_16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1274 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1276 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1278 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1280 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR64
;
1282 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1284 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1286 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1288 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1290 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1292 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1294 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1296 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1298 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1300 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1302 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1304 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1306 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1308 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1310 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1312 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1314 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1316 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1318 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1320 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1322 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1324 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1326 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1328 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1330 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1332 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1334 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1336 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1338 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1340 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1344 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1347 /* Set the howto pointer for a PowerPC ELF reloc. */
1350 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1351 bfd
*abfd ATTRIBUTE_UNUSED
;
1353 Elf_Internal_Rela
*dst
;
1357 /* Initialize howto table if needed. */
1358 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1361 type
= ELF64_R_TYPE (dst
->r_info
);
1362 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1363 / sizeof (ppc64_elf_howto_table
[0])));
1364 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1367 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1369 static bfd_reloc_status_type
1370 ppc64_elf_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1371 input_section
, output_bfd
, error_message
)
1373 arelent
*reloc_entry
;
1376 asection
*input_section
;
1378 char **error_message
;
1380 /* If this is a relocatable link (output_bfd test tells us), just
1381 call the generic function. Any adjustment will be done at final
1383 if (output_bfd
!= NULL
)
1384 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1385 input_section
, output_bfd
, error_message
);
1387 /* Adjust the addend for sign extension of the low 16 bits.
1388 We won't actually be using the low 16 bits, so trashing them
1390 reloc_entry
->addend
+= 0x8000;
1391 return bfd_reloc_continue
;
1394 static bfd_reloc_status_type
1395 ppc64_elf_brtaken_reloc (abfd
, reloc_entry
, symbol
, data
,
1396 input_section
, output_bfd
, error_message
)
1398 arelent
*reloc_entry
;
1401 asection
*input_section
;
1403 char **error_message
;
1406 enum elf_ppc64_reloc_type r_type
;
1407 bfd_size_type octets
;
1408 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1409 bfd_boolean is_power4
= FALSE
;
1411 /* If this is a relocatable link (output_bfd test tells us), just
1412 call the generic function. Any adjustment will be done at final
1414 if (output_bfd
!= NULL
)
1415 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1416 input_section
, output_bfd
, error_message
);
1418 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1419 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1420 insn
&= ~(0x01 << 21);
1421 r_type
= (enum elf_ppc64_reloc_type
) reloc_entry
->howto
->type
;
1422 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1423 || r_type
== R_PPC64_REL14_BRTAKEN
)
1424 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1428 /* Set 'a' bit. This is 0b00010 in BO field for branch
1429 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1430 for branch on CTR insns (BO == 1a00t or 1a01t). */
1431 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1433 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1436 return bfd_reloc_continue
;
1443 if (!bfd_is_com_section (symbol
->section
))
1444 target
= symbol
->value
;
1445 target
+= symbol
->section
->output_section
->vma
;
1446 target
+= symbol
->section
->output_offset
;
1447 target
+= reloc_entry
->addend
;
1449 from
= (reloc_entry
->address
1450 + input_section
->output_offset
1451 + input_section
->output_section
->vma
);
1453 /* Invert 'y' bit if not the default. */
1454 if ((bfd_signed_vma
) (target
- from
) < 0)
1457 bfd_put_32 (abfd
, (bfd_vma
) insn
, (bfd_byte
*) data
+ octets
);
1458 return bfd_reloc_continue
;
1461 static bfd_reloc_status_type
1462 ppc64_elf_sectoff_reloc (abfd
, reloc_entry
, symbol
, data
,
1463 input_section
, output_bfd
, error_message
)
1465 arelent
*reloc_entry
;
1468 asection
*input_section
;
1470 char **error_message
;
1472 /* If this is a relocatable link (output_bfd test tells us), just
1473 call the generic function. Any adjustment will be done at final
1475 if (output_bfd
!= NULL
)
1476 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1477 input_section
, output_bfd
, error_message
);
1479 /* Subtract the symbol section base address. */
1480 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1481 return bfd_reloc_continue
;
1484 static bfd_reloc_status_type
1485 ppc64_elf_sectoff_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1486 input_section
, output_bfd
, error_message
)
1488 arelent
*reloc_entry
;
1491 asection
*input_section
;
1493 char **error_message
;
1495 /* If this is a relocatable link (output_bfd test tells us), just
1496 call the generic function. Any adjustment will be done at final
1498 if (output_bfd
!= NULL
)
1499 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1500 input_section
, output_bfd
, error_message
);
1502 /* Subtract the symbol section base address. */
1503 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1505 /* Adjust the addend for sign extension of the low 16 bits. */
1506 reloc_entry
->addend
+= 0x8000;
1507 return bfd_reloc_continue
;
1510 static bfd_reloc_status_type
1511 ppc64_elf_toc_reloc (abfd
, reloc_entry
, symbol
, data
,
1512 input_section
, output_bfd
, error_message
)
1514 arelent
*reloc_entry
;
1517 asection
*input_section
;
1519 char **error_message
;
1523 /* If this is a relocatable link (output_bfd test tells us), just
1524 call the generic function. Any adjustment will be done at final
1526 if (output_bfd
!= NULL
)
1527 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1528 input_section
, output_bfd
, error_message
);
1530 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1532 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1534 /* Subtract the TOC base address. */
1535 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1536 return bfd_reloc_continue
;
1539 static bfd_reloc_status_type
1540 ppc64_elf_toc_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1541 input_section
, output_bfd
, error_message
)
1543 arelent
*reloc_entry
;
1546 asection
*input_section
;
1548 char **error_message
;
1552 /* If this is a relocatable link (output_bfd test tells us), just
1553 call the generic function. Any adjustment will be done at final
1555 if (output_bfd
!= NULL
)
1556 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1557 input_section
, output_bfd
, error_message
);
1559 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1561 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1563 /* Subtract the TOC base address. */
1564 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1566 /* Adjust the addend for sign extension of the low 16 bits. */
1567 reloc_entry
->addend
+= 0x8000;
1568 return bfd_reloc_continue
;
1571 static bfd_reloc_status_type
1572 ppc64_elf_toc64_reloc (abfd
, reloc_entry
, symbol
, data
,
1573 input_section
, output_bfd
, error_message
)
1575 arelent
*reloc_entry
;
1578 asection
*input_section
;
1580 char **error_message
;
1583 bfd_size_type octets
;
1585 /* If this is a relocatable link (output_bfd test tells us), just
1586 call the generic function. Any adjustment will be done at final
1588 if (output_bfd
!= NULL
)
1589 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1590 input_section
, output_bfd
, error_message
);
1592 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1594 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1596 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1597 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1598 return bfd_reloc_ok
;
1601 static bfd_reloc_status_type
1602 ppc64_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
1603 input_section
, output_bfd
, error_message
)
1605 arelent
*reloc_entry
;
1608 asection
*input_section
;
1610 char **error_message
;
1612 /* If this is a relocatable link (output_bfd test tells us), just
1613 call the generic function. Any adjustment will be done at final
1615 if (output_bfd
!= NULL
)
1616 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1617 input_section
, output_bfd
, error_message
);
1619 if (error_message
!= NULL
)
1621 static char buf
[60];
1622 sprintf (buf
, "generic linker can't handle %s",
1623 reloc_entry
->howto
->name
);
1624 *error_message
= buf
;
1626 return bfd_reloc_dangerous
;
1629 /* Fix bad default arch selected for a 64 bit input bfd when the
1630 default is 32 bit. */
1633 ppc64_elf_object_p (abfd
)
1636 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
1638 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1640 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1642 /* Relies on arch after 32 bit default being 64 bit default. */
1643 abfd
->arch_info
= abfd
->arch_info
->next
;
1644 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1650 /* Merge backend specific data from an object file to the output
1651 object file when linking. */
1654 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1658 /* Check if we have the same endianess. */
1659 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1660 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
1661 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1665 if (bfd_big_endian (ibfd
))
1666 msg
= _("%s: compiled for a big endian system and target is little endian");
1668 msg
= _("%s: compiled for a little endian system and target is big endian");
1670 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1672 bfd_set_error (bfd_error_wrong_format
);
1679 /* The following functions are specific to the ELF linker, while
1680 functions above are used generally. Those named ppc64_elf_* are
1681 called by the main ELF linker code. They appear in this file more
1682 or less in the order in which they are called. eg.
1683 ppc64_elf_check_relocs is called early in the link process,
1684 ppc64_elf_finish_dynamic_sections is one of the last functions
1687 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1688 functions have both a function code symbol and a function descriptor
1689 symbol. A call to foo in a relocatable object file looks like:
1696 The function definition in another object file might be:
1700 . .quad .TOC.@tocbase
1706 When the linker resolves the call during a static link, the branch
1707 unsurprisingly just goes to .foo and the .opd information is unused.
1708 If the function definition is in a shared library, things are a little
1709 different: The call goes via a plt call stub, the opd information gets
1710 copied to the plt, and the linker patches the nop.
1718 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1719 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1720 . std 2,40(1) # this is the general idea
1728 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1730 The "reloc ()" notation is supposed to indicate that the linker emits
1731 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1734 What are the difficulties here? Well, firstly, the relocations
1735 examined by the linker in check_relocs are against the function code
1736 sym .foo, while the dynamic relocation in the plt is emitted against
1737 the function descriptor symbol, foo. Somewhere along the line, we need
1738 to carefully copy dynamic link information from one symbol to the other.
1739 Secondly, the generic part of the elf linker will make .foo a dynamic
1740 symbol as is normal for most other backends. We need foo dynamic
1741 instead, at least for an application final link. However, when
1742 creating a shared library containing foo, we need to have both symbols
1743 dynamic so that references to .foo are satisfied during the early
1744 stages of linking. Otherwise the linker might decide to pull in a
1745 definition from some other object, eg. a static library. */
1747 /* The linker needs to keep track of the number of relocs that it
1748 decides to copy as dynamic relocs in check_relocs for each symbol.
1749 This is so that it can later discard them if they are found to be
1750 unnecessary. We store the information in a field extending the
1751 regular ELF linker hash table. */
1753 struct ppc_dyn_relocs
1755 struct ppc_dyn_relocs
*next
;
1757 /* The input section of the reloc. */
1760 /* Total number of relocs copied for the input section. */
1761 bfd_size_type count
;
1763 /* Number of pc-relative relocs copied for the input section. */
1764 bfd_size_type pc_count
;
1767 /* Of those relocs that might be copied as dynamic relocs, this macro
1768 selects between relative and absolute types. */
1770 #define IS_ABSOLUTE_RELOC(RTYPE) \
1771 ((RTYPE) != R_PPC64_REL32 \
1772 && (RTYPE) != R_PPC64_REL64 \
1773 && (RTYPE) != R_PPC64_REL30)
1775 /* Section name for stubs is the associated section name plus this
1777 #define STUB_SUFFIX ".stub"
1780 ppc_stub_long_branch:
1781 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1782 destination, but a 24 bit branch in a stub section will reach.
1785 ppc_stub_plt_branch:
1786 Similar to the above, but a 24 bit branch in the stub section won't
1787 reach its destination.
1788 . addis %r12,%r2,xxx@toc@ha
1789 . ld %r11,xxx@toc@l(%r12)
1794 Used to call a function in a shared library.
1795 . addis %r12,%r2,xxx@toc@ha
1797 . ld %r11,xxx+0@toc@l(%r12)
1798 . ld %r2,xxx+8@toc@l(%r12)
1800 . ld %r11,xxx+16@toc@l(%r12)
1804 enum ppc_stub_type
{
1806 ppc_stub_long_branch
,
1807 ppc_stub_plt_branch
,
1811 struct ppc_stub_hash_entry
{
1813 /* Base hash table entry structure. */
1814 struct bfd_hash_entry root
;
1816 /* The stub section. */
1819 /* Offset within stub_sec of the beginning of this stub. */
1820 bfd_vma stub_offset
;
1822 /* Given the symbol's value and its section we can determine its final
1823 value when building the stubs (so the stub knows where to jump. */
1824 bfd_vma target_value
;
1825 asection
*target_section
;
1827 enum ppc_stub_type stub_type
;
1829 /* The symbol table entry, if any, that this was derived from. */
1830 struct ppc_link_hash_entry
*h
;
1832 /* Where this stub is being called from, or, in the case of combined
1833 stub sections, the first input section in the group. */
1837 struct ppc_branch_hash_entry
{
1839 /* Base hash table entry structure. */
1840 struct bfd_hash_entry root
;
1842 /* Offset within .branch_lt. */
1843 unsigned int offset
;
1845 /* Generation marker. */
1849 struct ppc_link_hash_entry
1851 struct elf_link_hash_entry elf
;
1853 /* A pointer to the most recently used stub hash entry against this
1855 struct ppc_stub_hash_entry
*stub_cache
;
1857 /* Track dynamic relocs copied for this symbol. */
1858 struct ppc_dyn_relocs
*dyn_relocs
;
1860 /* Link between function code and descriptor symbols. */
1861 struct elf_link_hash_entry
*oh
;
1863 /* Flag function code and descriptor symbols. */
1864 unsigned int is_func
:1;
1865 unsigned int is_func_descriptor
:1;
1866 unsigned int is_entry
:1;
1869 /* ppc64 ELF linker hash table. */
1871 struct ppc_link_hash_table
1873 struct elf_link_hash_table elf
;
1875 /* The stub hash table. */
1876 struct bfd_hash_table stub_hash_table
;
1878 /* Another hash table for plt_branch stubs. */
1879 struct bfd_hash_table branch_hash_table
;
1881 /* Linker stub bfd. */
1884 /* Linker call-backs. */
1885 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
1886 void (*layout_sections_again
) PARAMS ((void));
1888 /* Array to keep track of which stub sections have been created, and
1889 information on stub grouping. */
1891 /* This is the section to which stubs in the group will be attached. */
1893 /* The stub section. */
1897 /* Assorted information used by ppc64_elf_size_stubs. */
1899 asection
**input_list
;
1901 /* Short-cuts to get to dynamic linker sections. */
1914 unsigned int stub_error
;
1916 /* Flag set when small branches are detected. Used to
1917 select suitable defaults for the stub group size. */
1918 unsigned int has_14bit_branch
;
1920 /* Set if we detect a reference undefined weak symbol. */
1921 unsigned int have_undefweak
;
1923 /* Incremented every time we size stubs. */
1924 unsigned int stub_iteration
;
1926 /* Small local sym to section mapping cache. */
1927 struct sym_sec_cache sym_sec
;
1930 static struct bfd_hash_entry
*stub_hash_newfunc
1931 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1932 static struct bfd_hash_entry
*branch_hash_newfunc
1933 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1934 static struct bfd_hash_entry
*link_hash_newfunc
1935 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1936 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
1938 static void ppc64_elf_link_hash_table_free
1939 PARAMS ((struct bfd_link_hash_table
*));
1940 static char *ppc_stub_name
1941 PARAMS ((const asection
*, const asection
*,
1942 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
1943 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
1944 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
1945 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
1946 static struct ppc_stub_hash_entry
*ppc_add_stub
1947 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
1948 static bfd_boolean create_linkage_sections
1949 PARAMS ((bfd
*, struct bfd_link_info
*));
1950 static bfd_boolean create_got_section
1951 PARAMS ((bfd
*, struct bfd_link_info
*));
1952 static bfd_boolean ppc64_elf_create_dynamic_sections
1953 PARAMS ((bfd
*, struct bfd_link_info
*));
1954 static void ppc64_elf_copy_indirect_symbol
1955 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
1956 struct elf_link_hash_entry
*));
1957 static bfd_boolean ppc64_elf_check_relocs
1958 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1959 const Elf_Internal_Rela
*));
1960 static asection
* ppc64_elf_gc_mark_hook
1961 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
1962 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
1963 static bfd_boolean ppc64_elf_gc_sweep_hook
1964 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1965 const Elf_Internal_Rela
*));
1966 static bfd_boolean func_desc_adjust
1967 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1968 static bfd_boolean ppc64_elf_func_desc_adjust
1969 PARAMS ((bfd
*, struct bfd_link_info
*));
1970 static bfd_boolean ppc64_elf_adjust_dynamic_symbol
1971 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
1972 static void ppc64_elf_hide_symbol
1973 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, bfd_boolean
));
1974 static bfd_boolean allocate_dynrelocs
1975 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1976 static bfd_boolean readonly_dynrelocs
1977 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1978 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
1979 PARAMS ((const Elf_Internal_Rela
*));
1980 static bfd_boolean ppc64_elf_size_dynamic_sections
1981 PARAMS ((bfd
*, struct bfd_link_info
*));
1982 static INLINE
enum ppc_stub_type ppc_type_of_stub
1983 PARAMS ((asection
*, const Elf_Internal_Rela
*,
1984 struct ppc_link_hash_entry
**, bfd_vma
));
1985 static bfd_byte
*build_plt_stub
1986 PARAMS ((bfd
*, bfd_byte
*, int, int));
1987 static bfd_boolean ppc_build_one_stub
1988 PARAMS ((struct bfd_hash_entry
*, PTR
));
1989 static bfd_boolean ppc_size_one_stub
1990 PARAMS ((struct bfd_hash_entry
*, PTR
));
1991 static void group_sections
1992 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, bfd_boolean
));
1993 static bfd_boolean ppc64_elf_relocate_section
1994 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
1995 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
1997 static bfd_boolean ppc64_elf_finish_dynamic_symbol
1998 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
1999 Elf_Internal_Sym
*));
2000 static bfd_boolean ppc64_elf_finish_dynamic_sections
2001 PARAMS ((bfd
*, struct bfd_link_info
*));
2003 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2005 #define ppc_hash_table(p) \
2006 ((struct ppc_link_hash_table *) ((p)->hash))
2008 #define ppc_stub_hash_lookup(table, string, create, copy) \
2009 ((struct ppc_stub_hash_entry *) \
2010 bfd_hash_lookup ((table), (string), (create), (copy)))
2012 #define ppc_branch_hash_lookup(table, string, create, copy) \
2013 ((struct ppc_branch_hash_entry *) \
2014 bfd_hash_lookup ((table), (string), (create), (copy)))
2016 /* Create an entry in the stub hash table. */
2018 static struct bfd_hash_entry
*
2019 stub_hash_newfunc (entry
, table
, string
)
2020 struct bfd_hash_entry
*entry
;
2021 struct bfd_hash_table
*table
;
2024 /* Allocate the structure if it has not already been allocated by a
2028 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2033 /* Call the allocation method of the superclass. */
2034 entry
= bfd_hash_newfunc (entry
, table
, string
);
2037 struct ppc_stub_hash_entry
*eh
;
2039 /* Initialize the local fields. */
2040 eh
= (struct ppc_stub_hash_entry
*) entry
;
2041 eh
->stub_sec
= NULL
;
2042 eh
->stub_offset
= 0;
2043 eh
->target_value
= 0;
2044 eh
->target_section
= NULL
;
2045 eh
->stub_type
= ppc_stub_none
;
2053 /* Create an entry in the branch hash table. */
2055 static struct bfd_hash_entry
*
2056 branch_hash_newfunc (entry
, table
, string
)
2057 struct bfd_hash_entry
*entry
;
2058 struct bfd_hash_table
*table
;
2061 /* Allocate the structure if it has not already been allocated by a
2065 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2070 /* Call the allocation method of the superclass. */
2071 entry
= bfd_hash_newfunc (entry
, table
, string
);
2074 struct ppc_branch_hash_entry
*eh
;
2076 /* Initialize the local fields. */
2077 eh
= (struct ppc_branch_hash_entry
*) entry
;
2085 /* Create an entry in a ppc64 ELF linker hash table. */
2087 static struct bfd_hash_entry
*
2088 link_hash_newfunc (entry
, table
, string
)
2089 struct bfd_hash_entry
*entry
;
2090 struct bfd_hash_table
*table
;
2093 /* Allocate the structure if it has not already been allocated by a
2097 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2102 /* Call the allocation method of the superclass. */
2103 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2106 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2108 eh
->stub_cache
= NULL
;
2109 eh
->dyn_relocs
= NULL
;
2112 eh
->is_func_descriptor
= 0;
2119 /* Create a ppc64 ELF linker hash table. */
2121 static struct bfd_link_hash_table
*
2122 ppc64_elf_link_hash_table_create (abfd
)
2125 struct ppc_link_hash_table
*htab
;
2126 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2128 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2132 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2138 /* Init the stub hash table too. */
2139 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2142 /* And the branch hash table. */
2143 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2146 htab
->stub_bfd
= NULL
;
2147 htab
->add_stub_section
= NULL
;
2148 htab
->layout_sections_again
= NULL
;
2149 htab
->stub_group
= NULL
;
2151 htab
->srelgot
= NULL
;
2153 htab
->srelplt
= NULL
;
2154 htab
->sdynbss
= NULL
;
2155 htab
->srelbss
= NULL
;
2156 htab
->sglink
= NULL
;
2159 htab
->srelbrlt
= NULL
;
2160 htab
->stub_error
= 0;
2161 htab
->has_14bit_branch
= 0;
2162 htab
->have_undefweak
= 0;
2163 htab
->stub_iteration
= 0;
2164 htab
->sym_sec
.abfd
= NULL
;
2166 return &htab
->elf
.root
;
2169 /* Free the derived linker hash table. */
2172 ppc64_elf_link_hash_table_free (hash
)
2173 struct bfd_link_hash_table
*hash
;
2175 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2177 bfd_hash_table_free (&ret
->stub_hash_table
);
2178 bfd_hash_table_free (&ret
->branch_hash_table
);
2179 _bfd_generic_link_hash_table_free (hash
);
2182 /* Build a name for an entry in the stub hash table. */
2185 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2186 const asection
*input_section
;
2187 const asection
*sym_sec
;
2188 const struct ppc_link_hash_entry
*h
;
2189 const Elf_Internal_Rela
*rel
;
2194 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2195 offsets from a sym as a branch target? In fact, we could
2196 probably assume the addend is always zero. */
2197 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2201 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2202 stub_name
= bfd_malloc (len
);
2203 if (stub_name
!= NULL
)
2205 sprintf (stub_name
, "%08x_%s+%x",
2206 input_section
->id
& 0xffffffff,
2207 h
->elf
.root
.root
.string
,
2208 (int) rel
->r_addend
& 0xffffffff);
2213 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2214 stub_name
= bfd_malloc (len
);
2215 if (stub_name
!= NULL
)
2217 sprintf (stub_name
, "%08x_%x:%x+%x",
2218 input_section
->id
& 0xffffffff,
2219 sym_sec
->id
& 0xffffffff,
2220 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2221 (int) rel
->r_addend
& 0xffffffff);
2227 /* Look up an entry in the stub hash. Stub entries are cached because
2228 creating the stub name takes a bit of time. */
2230 static struct ppc_stub_hash_entry
*
2231 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2232 const asection
*input_section
;
2233 const asection
*sym_sec
;
2234 struct elf_link_hash_entry
*hash
;
2235 const Elf_Internal_Rela
*rel
;
2236 struct ppc_link_hash_table
*htab
;
2238 struct ppc_stub_hash_entry
*stub_entry
;
2239 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2240 const asection
*id_sec
;
2242 /* If this input section is part of a group of sections sharing one
2243 stub section, then use the id of the first section in the group.
2244 Stub names need to include a section id, as there may well be
2245 more than one stub used to reach say, printf, and we need to
2246 distinguish between them. */
2247 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2249 if (h
!= NULL
&& h
->stub_cache
!= NULL
2250 && h
->stub_cache
->h
== h
2251 && h
->stub_cache
->id_sec
== id_sec
)
2253 stub_entry
= h
->stub_cache
;
2259 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2260 if (stub_name
== NULL
)
2263 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2264 stub_name
, FALSE
, FALSE
);
2266 h
->stub_cache
= stub_entry
;
2274 /* Add a new stub entry to the stub hash. Not all fields of the new
2275 stub entry are initialised. */
2277 static struct ppc_stub_hash_entry
*
2278 ppc_add_stub (stub_name
, section
, htab
)
2279 const char *stub_name
;
2281 struct ppc_link_hash_table
*htab
;
2285 struct ppc_stub_hash_entry
*stub_entry
;
2287 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2288 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2289 if (stub_sec
== NULL
)
2291 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2292 if (stub_sec
== NULL
)
2298 namelen
= strlen (link_sec
->name
);
2299 len
= namelen
+ sizeof (STUB_SUFFIX
);
2300 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2304 memcpy (s_name
, link_sec
->name
, namelen
);
2305 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2306 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2307 if (stub_sec
== NULL
)
2309 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2311 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2314 /* Enter this entry into the linker stub hash table. */
2315 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2317 if (stub_entry
== NULL
)
2319 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2320 bfd_archive_filename (section
->owner
),
2325 stub_entry
->stub_sec
= stub_sec
;
2326 stub_entry
->stub_offset
= 0;
2327 stub_entry
->id_sec
= link_sec
;
2331 /* Create sections for linker generated code. */
2334 create_linkage_sections (dynobj
, info
)
2336 struct bfd_link_info
*info
;
2338 struct ppc_link_hash_table
*htab
;
2341 htab
= ppc_hash_table (info
);
2343 /* Create .sfpr for code to save and restore fp regs. */
2344 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2345 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2346 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2347 if (htab
->sfpr
== NULL
2348 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2349 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2352 /* Create .glink for lazy dynamic linking support. */
2353 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2354 if (htab
->sglink
== NULL
2355 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2356 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2359 /* Create .branch_lt for plt_branch stubs. */
2360 flags
= (SEC_ALLOC
| SEC_LOAD
2361 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2362 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2363 if (htab
->sbrlt
== NULL
2364 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2365 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2370 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2371 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2372 htab
->srelbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
2374 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2375 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2381 /* Create .got and .rela.got sections in DYNOBJ, and set up
2382 shortcuts to them in our hash table. */
2385 create_got_section (dynobj
, info
)
2387 struct bfd_link_info
*info
;
2389 struct ppc_link_hash_table
*htab
;
2391 if (! _bfd_elf_create_got_section (dynobj
, info
))
2394 htab
= ppc_hash_table (info
);
2395 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2399 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2401 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2402 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2403 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2405 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2410 /* Create the dynamic sections, and set up shortcuts. */
2413 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2415 struct bfd_link_info
*info
;
2417 struct ppc_link_hash_table
*htab
;
2419 htab
= ppc_hash_table (info
);
2420 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2423 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2426 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2427 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2428 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2430 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2432 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2433 || (!info
->shared
&& !htab
->srelbss
))
2439 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2442 ppc64_elf_copy_indirect_symbol (bed
, dir
, ind
)
2443 struct elf_backend_data
*bed
;
2444 struct elf_link_hash_entry
*dir
, *ind
;
2446 struct ppc_link_hash_entry
*edir
, *eind
;
2448 edir
= (struct ppc_link_hash_entry
*) dir
;
2449 eind
= (struct ppc_link_hash_entry
*) ind
;
2451 if (eind
->dyn_relocs
!= NULL
)
2453 if (edir
->dyn_relocs
!= NULL
)
2455 struct ppc_dyn_relocs
**pp
;
2456 struct ppc_dyn_relocs
*p
;
2458 if (ind
->root
.type
== bfd_link_hash_indirect
)
2461 /* Add reloc counts against the weak sym to the strong sym
2462 list. Merge any entries against the same section. */
2463 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2465 struct ppc_dyn_relocs
*q
;
2467 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2468 if (q
->sec
== p
->sec
)
2470 q
->pc_count
+= p
->pc_count
;
2471 q
->count
+= p
->count
;
2478 *pp
= edir
->dyn_relocs
;
2481 edir
->dyn_relocs
= eind
->dyn_relocs
;
2482 eind
->dyn_relocs
= NULL
;
2485 edir
->is_func
|= eind
->is_func
;
2486 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2487 edir
->is_entry
|= eind
->is_entry
;
2489 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
2492 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2493 symbols undefined on the command-line. */
2496 ppc64_elf_mark_entry_syms (info
)
2497 struct bfd_link_info
*info
;
2499 struct ppc_link_hash_table
*htab
;
2500 struct bfd_sym_chain
*sym
;
2502 htab
= ppc_hash_table (info
);
2503 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
2505 struct elf_link_hash_entry
*h
;
2507 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
2509 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
2514 /* Look through the relocs for a section during the first phase, and
2515 calculate needed space in the global offset table, procedure
2516 linkage table, and dynamic reloc sections. */
2519 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2521 struct bfd_link_info
*info
;
2523 const Elf_Internal_Rela
*relocs
;
2525 struct ppc_link_hash_table
*htab
;
2526 Elf_Internal_Shdr
*symtab_hdr
;
2527 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2528 const Elf_Internal_Rela
*rel
;
2529 const Elf_Internal_Rela
*rel_end
;
2531 asection
**opd_sym_map
;
2533 if (info
->relocateable
)
2536 htab
= ppc_hash_table (info
);
2537 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2539 sym_hashes
= elf_sym_hashes (abfd
);
2540 sym_hashes_end
= (sym_hashes
2541 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
2542 - symtab_hdr
->sh_info
);
2546 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
2548 /* Garbage collection needs some extra help with .opd sections.
2549 We don't want to necessarily keep everything referenced by
2550 relocs in .opd, as that would keep all functions. Instead,
2551 if we reference an .opd symbol (a function descriptor), we
2552 want to keep the function code symbol's section. This is
2553 easy for global symbols, but for local syms we need to keep
2554 information about the associated function section. Later, if
2555 edit_opd deletes entries, we'll use this array to adjust
2556 local syms in .opd. */
2558 asection
*func_section
;
2563 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
2564 opd_sym_map
= (asection
**) bfd_zalloc (abfd
, amt
);
2565 if (opd_sym_map
== NULL
)
2567 elf_section_data (sec
)->tdata
= opd_sym_map
;
2570 if (htab
->elf
.dynobj
== NULL
)
2571 htab
->elf
.dynobj
= abfd
;
2572 if (htab
->sfpr
== NULL
2573 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2576 rel_end
= relocs
+ sec
->reloc_count
;
2577 for (rel
= relocs
; rel
< rel_end
; rel
++)
2579 unsigned long r_symndx
;
2580 struct elf_link_hash_entry
*h
;
2581 enum elf_ppc64_reloc_type r_type
;
2583 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2584 if (r_symndx
< symtab_hdr
->sh_info
)
2587 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2589 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2592 /* GOT16 relocations */
2594 case R_PPC64_GOT16_DS
:
2595 case R_PPC64_GOT16_HA
:
2596 case R_PPC64_GOT16_HI
:
2597 case R_PPC64_GOT16_LO
:
2598 case R_PPC64_GOT16_LO_DS
:
2600 /* This symbol requires a global offset table entry. */
2601 if (htab
->sgot
== NULL
2602 && !create_got_section (htab
->elf
.dynobj
, info
))
2607 h
->got
.refcount
+= 1;
2611 bfd_signed_vma
*local_got_refcounts
;
2613 /* This is a global offset table entry for a local symbol. */
2614 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2615 if (local_got_refcounts
== NULL
)
2619 size
= symtab_hdr
->sh_info
;
2620 size
*= sizeof (bfd_signed_vma
);
2621 local_got_refcounts
= ((bfd_signed_vma
*)
2622 bfd_zalloc (abfd
, size
));
2623 if (local_got_refcounts
== NULL
)
2625 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2627 local_got_refcounts
[r_symndx
] += 1;
2631 case R_PPC64_PLT16_HA
:
2632 case R_PPC64_PLT16_HI
:
2633 case R_PPC64_PLT16_LO
:
2636 /* This symbol requires a procedure linkage table entry. We
2637 actually build the entry in adjust_dynamic_symbol,
2638 because this might be a case of linking PIC code without
2639 linking in any dynamic objects, in which case we don't
2640 need to generate a procedure linkage table after all. */
2643 /* It does not make sense to have a procedure linkage
2644 table entry for a local symbol. */
2645 bfd_set_error (bfd_error_bad_value
);
2649 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2650 h
->plt
.refcount
+= 1;
2651 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2654 /* The following relocations don't need to propagate the
2655 relocation if linking a shared object since they are
2656 section relative. */
2657 case R_PPC64_SECTOFF
:
2658 case R_PPC64_SECTOFF_LO
:
2659 case R_PPC64_SECTOFF_HI
:
2660 case R_PPC64_SECTOFF_HA
:
2661 case R_PPC64_SECTOFF_DS
:
2662 case R_PPC64_SECTOFF_LO_DS
:
2664 case R_PPC64_TOC16_LO
:
2665 case R_PPC64_TOC16_HI
:
2666 case R_PPC64_TOC16_HA
:
2667 case R_PPC64_TOC16_DS
:
2668 case R_PPC64_TOC16_LO_DS
:
2671 /* This relocation describes the C++ object vtable hierarchy.
2672 Reconstruct it for later use during GC. */
2673 case R_PPC64_GNU_VTINHERIT
:
2674 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2678 /* This relocation describes which C++ vtable entries are actually
2679 used. Record for later use during GC. */
2680 case R_PPC64_GNU_VTENTRY
:
2681 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2686 case R_PPC64_REL14_BRTAKEN
:
2687 case R_PPC64_REL14_BRNTAKEN
:
2688 htab
->has_14bit_branch
= 1;
2693 && h
->root
.root
.string
[0] == '.'
2694 && h
->root
.root
.string
[1] != 0)
2696 /* We may need a .plt entry if the function this reloc
2697 refers to is in a shared lib. */
2698 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2699 h
->plt
.refcount
+= 1;
2700 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2704 case R_PPC64_ADDR64
:
2705 if (opd_sym_map
!= NULL
2707 && h
->root
.root
.string
[0] == '.'
2708 && h
->root
.root
.string
[1] != 0)
2710 struct elf_link_hash_entry
*fdh
;
2712 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2713 FALSE
, FALSE
, FALSE
);
2716 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2717 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2718 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2719 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2722 if (opd_sym_map
!= NULL
2724 && rel
+ 1 < rel_end
2725 && ((enum elf_ppc64_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
)
2730 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
2735 opd_sym_map
[rel
->r_offset
/ 24] = s
;
2742 case R_PPC64_ADDR14
:
2743 case R_PPC64_ADDR14_BRNTAKEN
:
2744 case R_PPC64_ADDR14_BRTAKEN
:
2745 case R_PPC64_ADDR16
:
2746 case R_PPC64_ADDR16_DS
:
2747 case R_PPC64_ADDR16_HA
:
2748 case R_PPC64_ADDR16_HI
:
2749 case R_PPC64_ADDR16_HIGHER
:
2750 case R_PPC64_ADDR16_HIGHERA
:
2751 case R_PPC64_ADDR16_HIGHEST
:
2752 case R_PPC64_ADDR16_HIGHESTA
:
2753 case R_PPC64_ADDR16_LO
:
2754 case R_PPC64_ADDR16_LO_DS
:
2755 case R_PPC64_ADDR24
:
2756 case R_PPC64_ADDR32
:
2757 case R_PPC64_UADDR16
:
2758 case R_PPC64_UADDR32
:
2759 case R_PPC64_UADDR64
:
2761 /* Don't propagate .opd relocs. */
2762 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
2765 /* If we are creating a shared library, and this is a reloc
2766 against a global symbol, or a non PC relative reloc
2767 against a local symbol, then we need to copy the reloc
2768 into the shared library. However, if we are linking with
2769 -Bsymbolic, we do not need to copy a reloc against a
2770 global symbol which is defined in an object we are
2771 including in the link (i.e., DEF_REGULAR is set). At
2772 this point we have not seen all the input files, so it is
2773 possible that DEF_REGULAR is not set now but will be set
2774 later (it is never cleared). In case of a weak definition,
2775 DEF_REGULAR may be cleared later by a strong definition in
2776 a shared library. We account for that possibility below by
2777 storing information in the relocs_copied field of the hash
2778 table entry. A similar situation occurs when creating
2779 shared libraries and symbol visibility changes render the
2782 If on the other hand, we are creating an executable, we
2783 may need to keep relocations for symbols satisfied by a
2784 dynamic library if we manage to avoid copy relocs for the
2787 && (sec
->flags
& SEC_ALLOC
) != 0
2788 && (IS_ABSOLUTE_RELOC (r_type
)
2790 && (! info
->symbolic
2791 || h
->root
.type
== bfd_link_hash_defweak
2792 || (h
->elf_link_hash_flags
2793 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2795 && (sec
->flags
& SEC_ALLOC
) != 0
2797 && (h
->root
.type
== bfd_link_hash_defweak
2798 || (h
->elf_link_hash_flags
2799 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2801 struct ppc_dyn_relocs
*p
;
2802 struct ppc_dyn_relocs
**head
;
2804 /* We must copy these reloc types into the output file.
2805 Create a reloc section in dynobj and make room for
2812 name
= (bfd_elf_string_from_elf_section
2814 elf_elfheader (abfd
)->e_shstrndx
,
2815 elf_section_data (sec
)->rel_hdr
.sh_name
));
2819 if (strncmp (name
, ".rela", 5) != 0
2820 || strcmp (bfd_get_section_name (abfd
, sec
),
2823 (*_bfd_error_handler
)
2824 (_("%s: bad relocation section name `%s\'"),
2825 bfd_archive_filename (abfd
), name
);
2826 bfd_set_error (bfd_error_bad_value
);
2829 dynobj
= htab
->elf
.dynobj
;
2830 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2835 sreloc
= bfd_make_section (dynobj
, name
);
2836 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2837 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2838 if ((sec
->flags
& SEC_ALLOC
) != 0)
2839 flags
|= SEC_ALLOC
| SEC_LOAD
;
2841 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2842 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2845 elf_section_data (sec
)->sreloc
= sreloc
;
2848 /* If this is a global symbol, we count the number of
2849 relocations we need for this symbol. */
2852 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
2856 /* Track dynamic relocs needed for local syms too.
2857 We really need local syms available to do this
2861 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
2866 head
= ((struct ppc_dyn_relocs
**)
2867 &elf_section_data (s
)->local_dynrel
);
2871 if (p
== NULL
|| p
->sec
!= sec
)
2873 p
= ((struct ppc_dyn_relocs
*)
2874 bfd_alloc (htab
->elf
.dynobj
,
2875 (bfd_size_type
) sizeof *p
));
2886 if (!IS_ABSOLUTE_RELOC (r_type
))
2899 /* Return the section that should be marked against GC for a given
2903 ppc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2905 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2906 Elf_Internal_Rela
*rel
;
2907 struct elf_link_hash_entry
*h
;
2908 Elf_Internal_Sym
*sym
;
2910 asection
*rsec
= NULL
;
2914 enum elf_ppc64_reloc_type r_type
;
2915 struct ppc_link_hash_entry
*fdh
;
2917 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2920 case R_PPC64_GNU_VTINHERIT
:
2921 case R_PPC64_GNU_VTENTRY
:
2925 switch (h
->root
.type
)
2927 case bfd_link_hash_defined
:
2928 case bfd_link_hash_defweak
:
2929 fdh
= (struct ppc_link_hash_entry
*) h
;
2931 /* Function descriptor syms cause the associated
2932 function code sym section to be marked. */
2933 if (fdh
->is_func_descriptor
)
2934 rsec
= fdh
->oh
->root
.u
.def
.section
;
2936 /* Function entry syms return NULL if they are in .opd
2937 and are not ._start (or others undefined on the ld
2938 command line). Thus we avoid marking all function
2939 sections, as all functions are referenced in .opd. */
2940 else if ((fdh
->oh
!= NULL
2941 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
2942 || elf_section_data (sec
)->tdata
== NULL
)
2943 rsec
= h
->root
.u
.def
.section
;
2946 case bfd_link_hash_common
:
2947 rsec
= h
->root
.u
.c
.p
->section
;
2957 asection
**opd_sym_section
;
2959 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2960 opd_sym_section
= (asection
**) elf_section_data (rsec
)->tdata
;
2961 if (opd_sym_section
!= NULL
)
2962 rsec
= opd_sym_section
[sym
->st_value
/ 24];
2963 else if (elf_section_data (sec
)->tdata
!= NULL
)
2970 /* Update the .got, .plt. and dynamic reloc reference counts for the
2971 section being removed. */
2974 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2976 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2978 const Elf_Internal_Rela
*relocs
;
2980 Elf_Internal_Shdr
*symtab_hdr
;
2981 struct elf_link_hash_entry
**sym_hashes
;
2982 bfd_signed_vma
*local_got_refcounts
;
2983 const Elf_Internal_Rela
*rel
, *relend
;
2985 elf_section_data (sec
)->local_dynrel
= NULL
;
2987 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2988 sym_hashes
= elf_sym_hashes (abfd
);
2989 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2991 relend
= relocs
+ sec
->reloc_count
;
2992 for (rel
= relocs
; rel
< relend
; rel
++)
2994 unsigned long r_symndx
;
2995 enum elf_ppc64_reloc_type r_type
;
2996 struct elf_link_hash_entry
*h
;
2998 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2999 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3003 case R_PPC64_GOT16_DS
:
3004 case R_PPC64_GOT16_HA
:
3005 case R_PPC64_GOT16_HI
:
3006 case R_PPC64_GOT16_LO
:
3007 case R_PPC64_GOT16_LO_DS
:
3008 if (r_symndx
>= symtab_hdr
->sh_info
)
3010 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3011 if (h
->got
.refcount
> 0)
3016 if (local_got_refcounts
[r_symndx
] > 0)
3017 local_got_refcounts
[r_symndx
]--;
3021 case R_PPC64_PLT16_HA
:
3022 case R_PPC64_PLT16_HI
:
3023 case R_PPC64_PLT16_LO
:
3026 if (r_symndx
>= symtab_hdr
->sh_info
)
3028 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3029 if (h
->plt
.refcount
> 0)
3035 case R_PPC64_REL14_BRNTAKEN
:
3036 case R_PPC64_REL14_BRTAKEN
:
3038 if (r_symndx
>= symtab_hdr
->sh_info
)
3040 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3041 if (h
->plt
.refcount
> 0)
3049 if (r_symndx
>= symtab_hdr
->sh_info
)
3051 struct ppc_link_hash_entry
*eh
;
3052 struct ppc_dyn_relocs
**pp
;
3053 struct ppc_dyn_relocs
*p
;
3055 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3056 eh
= (struct ppc_link_hash_entry
*) h
;
3058 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3070 case R_PPC64_ADDR14
:
3071 case R_PPC64_ADDR14_BRNTAKEN
:
3072 case R_PPC64_ADDR14_BRTAKEN
:
3073 case R_PPC64_ADDR16
:
3074 case R_PPC64_ADDR16_DS
:
3075 case R_PPC64_ADDR16_HA
:
3076 case R_PPC64_ADDR16_HI
:
3077 case R_PPC64_ADDR16_HIGHER
:
3078 case R_PPC64_ADDR16_HIGHERA
:
3079 case R_PPC64_ADDR16_HIGHEST
:
3080 case R_PPC64_ADDR16_HIGHESTA
:
3081 case R_PPC64_ADDR16_LO
:
3082 case R_PPC64_ADDR16_LO_DS
:
3083 case R_PPC64_ADDR24
:
3084 case R_PPC64_ADDR32
:
3085 case R_PPC64_ADDR64
:
3086 case R_PPC64_UADDR16
:
3087 case R_PPC64_UADDR32
:
3088 case R_PPC64_UADDR64
:
3090 if (r_symndx
>= symtab_hdr
->sh_info
)
3092 struct ppc_link_hash_entry
*eh
;
3093 struct ppc_dyn_relocs
**pp
;
3094 struct ppc_dyn_relocs
*p
;
3096 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3097 eh
= (struct ppc_link_hash_entry
*) h
;
3099 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3117 /* Called via elf_link_hash_traverse to transfer dynamic linking
3118 information on function code symbol entries to their corresponding
3119 function descriptor symbol entries. */
3121 func_desc_adjust (h
, inf
)
3122 struct elf_link_hash_entry
*h
;
3125 struct bfd_link_info
*info
;
3126 struct ppc_link_hash_table
*htab
;
3128 if (h
->root
.type
== bfd_link_hash_indirect
)
3131 if (h
->root
.type
== bfd_link_hash_warning
)
3132 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3134 info
= (struct bfd_link_info
*) inf
;
3135 htab
= ppc_hash_table (info
);
3137 /* If this is a function code symbol, transfer dynamic linking
3138 information to the function descriptor symbol. */
3139 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
3142 if (h
->root
.type
== bfd_link_hash_undefweak
3143 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
3144 htab
->have_undefweak
= TRUE
;
3146 if (h
->plt
.refcount
> 0
3147 && h
->root
.root
.string
[0] == '.'
3148 && h
->root
.root
.string
[1] != '\0')
3150 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3151 bfd_boolean force_local
;
3153 /* Find the corresponding function descriptor symbol. Create it
3154 as undefined if necessary. */
3157 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3158 FALSE
, FALSE
, TRUE
);
3162 && (h
->root
.type
== bfd_link_hash_undefined
3163 || h
->root
.type
== bfd_link_hash_undefweak
))
3167 struct bfd_link_hash_entry
*bh
;
3169 abfd
= h
->root
.u
.undef
.abfd
;
3170 newsym
= bfd_make_empty_symbol (abfd
);
3171 newsym
->name
= h
->root
.root
.string
+ 1;
3172 newsym
->section
= bfd_und_section_ptr
;
3174 newsym
->flags
= BSF_OBJECT
;
3175 if (h
->root
.type
== bfd_link_hash_undefweak
)
3176 newsym
->flags
|= BSF_WEAK
;
3179 if ( !(_bfd_generic_link_add_one_symbol
3180 (info
, abfd
, newsym
->name
, newsym
->flags
,
3181 newsym
->section
, newsym
->value
, NULL
, FALSE
, FALSE
, &bh
)))
3185 fdh
= (struct elf_link_hash_entry
*) bh
;
3186 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3190 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
3192 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3193 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3195 if (fdh
->dynindx
== -1)
3196 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
3198 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
3199 & (ELF_LINK_HASH_REF_REGULAR
3200 | ELF_LINK_HASH_REF_DYNAMIC
3201 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3202 | ELF_LINK_NON_GOT_REF
));
3203 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3205 fdh
->plt
.refcount
= h
->plt
.refcount
;
3206 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3208 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3209 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3210 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3213 /* Now that the info is on the function descriptor, clear the
3214 function code sym info. Any function code syms for which we
3215 don't have a definition in a regular file, we force local.
3216 This prevents a shared library from exporting syms that have
3217 been imported from another library. Function code syms that
3218 are really in the library we must leave global to prevent the
3219 linker dragging in a definition from a static library. */
3220 force_local
= (info
->shared
3221 && ((h
->elf_link_hash_flags
3222 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3224 || (fdh
->elf_link_hash_flags
3225 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3226 || (fdh
->elf_link_hash_flags
3227 & ELF_LINK_FORCED_LOCAL
) != 0));
3228 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3234 #define MIN_SAVE_FPR 14
3235 #define MAX_SAVE_FPR 31
3237 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3238 this hook to a) provide some gcc support functions, and b) transfer
3239 dynamic linking information gathered so far on function code symbol
3240 entries, to their corresponding function descriptor symbol entries. */
3242 ppc64_elf_func_desc_adjust (obfd
, info
)
3243 bfd
*obfd ATTRIBUTE_UNUSED
;
3244 struct bfd_link_info
*info
;
3246 struct ppc_link_hash_table
*htab
;
3247 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3248 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3250 struct elf_link_hash_entry
*h
;
3254 htab
= ppc_hash_table (info
);
3256 if (htab
->sfpr
== NULL
)
3257 /* We don't have any relocs. */
3260 /* First provide any missing ._savef* and ._restf* functions. */
3261 memcpy (sym
, "._savef14", 10);
3262 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3264 sym
[7] = i
/ 10 + '0';
3265 sym
[8] = i
% 10 + '0';
3266 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
3268 && h
->root
.type
== bfd_link_hash_undefined
)
3270 if (lowest_savef
> i
)
3272 h
->root
.type
= bfd_link_hash_defined
;
3273 h
->root
.u
.def
.section
= htab
->sfpr
;
3274 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3276 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3277 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3281 memcpy (sym
, "._restf14", 10);
3282 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3284 sym
[7] = i
/ 10 + '0';
3285 sym
[8] = i
% 10 + '0';
3286 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
3288 && h
->root
.type
== bfd_link_hash_undefined
)
3290 if (lowest_restf
> i
)
3292 h
->root
.type
= bfd_link_hash_defined
;
3293 h
->root
.u
.def
.section
= htab
->sfpr
;
3294 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3295 + (i
- lowest_restf
) * 4);
3297 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3298 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3302 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3304 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3305 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3307 if (htab
->sfpr
->_raw_size
== 0)
3309 if (!htab
->have_undefweak
)
3311 _bfd_strip_section_from_output (info
, htab
->sfpr
);
3315 htab
->sfpr
->_raw_size
= 4;
3318 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3321 htab
->sfpr
->contents
= p
;
3323 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3325 unsigned int fpr
= i
<< 21;
3326 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3327 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3330 if (lowest_savef
<= MAX_SAVE_FPR
)
3332 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3336 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3338 unsigned int fpr
= i
<< 21;
3339 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3340 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3343 if (lowest_restf
<= MAX_SAVE_FPR
3344 || htab
->sfpr
->_raw_size
== 4)
3346 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3352 /* Adjust a symbol defined by a dynamic object and referenced by a
3353 regular object. The current definition is in some section of the
3354 dynamic object, but we're not including those sections. We have to
3355 change the definition to something the rest of the link can
3359 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3360 struct bfd_link_info
*info
;
3361 struct elf_link_hash_entry
*h
;
3363 struct ppc_link_hash_table
*htab
;
3364 struct ppc_link_hash_entry
* eh
;
3365 struct ppc_dyn_relocs
*p
;
3367 unsigned int power_of_two
;
3369 htab
= ppc_hash_table (info
);
3371 /* Deal with function syms. */
3372 if (h
->type
== STT_FUNC
3373 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3375 /* Clear procedure linkage table information for any symbol that
3376 won't need a .plt entry. */
3377 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3378 || h
->plt
.refcount
<= 0
3379 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3381 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3382 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3384 h
->plt
.offset
= (bfd_vma
) -1;
3385 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3390 h
->plt
.offset
= (bfd_vma
) -1;
3392 /* If this is a weak symbol, and there is a real definition, the
3393 processor independent code will have arranged for us to see the
3394 real definition first, and we can just use the same value. */
3395 if (h
->weakdef
!= NULL
)
3397 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3398 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3399 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3400 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3404 /* This is a reference to a symbol defined by a dynamic object which
3405 is not a function. */
3407 /* If we are creating a shared library, we must presume that the
3408 only references to the symbol are via the global offset table.
3409 For such cases we need not do anything here; the relocations will
3410 be handled correctly by relocate_section. */
3414 /* If there are no references to this symbol that do not use the
3415 GOT, we don't need to generate a copy reloc. */
3416 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3419 eh
= (struct ppc_link_hash_entry
*) h
;
3420 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3422 s
= p
->sec
->output_section
;
3423 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3427 /* If we didn't find any dynamic relocs in read-only sections, then
3428 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3431 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3435 /* We must allocate the symbol in our .dynbss section, which will
3436 become part of the .bss section of the executable. There will be
3437 an entry for this symbol in the .dynsym section. The dynamic
3438 object will contain position independent code, so all references
3439 from the dynamic object to this symbol will go through the global
3440 offset table. The dynamic linker will use the .dynsym entry to
3441 determine the address it must put in the global offset table, so
3442 both the dynamic object and the regular object will refer to the
3443 same memory location for the variable. */
3445 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
3446 to copy the initial value out of the dynamic object and into the
3447 runtime process image. We need to remember the offset into the
3448 .rela.bss section we are going to use. */
3449 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3451 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3452 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3455 /* We need to figure out the alignment required for this symbol. I
3456 have no idea how ELF linkers handle this. */
3457 power_of_two
= bfd_log2 (h
->size
);
3458 if (power_of_two
> 4)
3461 /* Apply the required alignment. */
3463 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3464 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3466 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3470 /* Define the symbol as being at this point in the section. */
3471 h
->root
.u
.def
.section
= s
;
3472 h
->root
.u
.def
.value
= s
->_raw_size
;
3474 /* Increment the section size to make room for the symbol. */
3475 s
->_raw_size
+= h
->size
;
3480 /* If given a function descriptor symbol, hide both the function code
3481 sym and the descriptor. */
3483 ppc64_elf_hide_symbol (info
, h
, force_local
)
3484 struct bfd_link_info
*info
;
3485 struct elf_link_hash_entry
*h
;
3486 bfd_boolean force_local
;
3488 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3490 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3492 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3497 struct ppc_link_hash_table
*htab
;
3500 /* We aren't supposed to use alloca in BFD because on
3501 systems which do not have alloca the version in libiberty
3502 calls xmalloc, which might cause the program to crash
3503 when it runs out of memory. This function doesn't have a
3504 return status, so there's no way to gracefully return an
3505 error. So cheat. We know that string[-1] can be safely
3506 dereferenced; It's either a string in an ELF string
3507 table, or allocated in an objalloc structure. */
3509 p
= h
->root
.root
.string
- 1;
3512 htab
= ppc_hash_table (info
);
3513 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
3516 /* Unfortunately, if it so happens that the string we were
3517 looking for was allocated immediately before this string,
3518 then we overwrote the string terminator. That's the only
3519 reason the lookup should fail. */
3522 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
3523 while (q
>= h
->root
.root
.string
&& *q
== *p
)
3525 if (q
< h
->root
.root
.string
&& *p
== '.')
3526 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
3530 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
3531 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
3535 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3540 ppc64_elf_edit_opd (obfd
, info
)
3542 struct bfd_link_info
*info
;
3545 unsigned int bfd_indx
;
3547 for (bfd_indx
= 0, ibfd
= info
->input_bfds
;
3549 ibfd
= ibfd
->link_next
, bfd_indx
++)
3552 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3553 Elf_Internal_Shdr
*symtab_hdr
;
3554 Elf_Internal_Sym
*local_syms
;
3555 struct elf_link_hash_entry
**sym_hashes
;
3559 bfd_boolean need_edit
;
3561 sec
= bfd_get_section_by_name (ibfd
, ".opd");
3565 amt
= sec
->_raw_size
* sizeof (long) / 24;
3566 adjust
= (long *) elf_section_data (sec
)->tdata
;
3569 /* Must be a ld -r link. ie. check_relocs hasn't been
3571 adjust
= (long *) bfd_zalloc (obfd
, amt
);
3572 elf_section_data (sec
)->tdata
= adjust
;
3574 memset (adjust
, 0, (size_t) amt
);
3576 if (sec
->output_section
== bfd_abs_section_ptr
)
3579 /* Look through the section relocs. */
3580 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
3584 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3585 sym_hashes
= elf_sym_hashes (ibfd
);
3587 /* Read the relocations. */
3588 relstart
= _bfd_elf64_link_read_relocs (ibfd
, sec
, (PTR
) NULL
,
3589 (Elf_Internal_Rela
*) NULL
,
3591 if (relstart
== NULL
)
3594 /* First run through the relocs to check they are sane, and to
3595 determine whether we need to edit this opd section. */
3598 relend
= relstart
+ sec
->reloc_count
;
3599 for (rel
= relstart
; rel
< relend
; rel
++)
3601 enum elf_ppc64_reloc_type r_type
;
3602 unsigned long r_symndx
;
3604 struct elf_link_hash_entry
*h
;
3605 Elf_Internal_Sym
*sym
;
3607 /* .opd contains a regular array of 24 byte entries. We're
3608 only interested in the reloc pointing to a function entry
3610 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3611 if (r_type
== R_PPC64_TOC
)
3614 if (r_type
!= R_PPC64_ADDR64
)
3616 (*_bfd_error_handler
)
3617 (_("%s: unexpected reloc type %u in .opd section"),
3618 bfd_archive_filename (ibfd
), r_type
);
3623 if (rel
+ 1 >= relend
)
3625 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
);
3626 if (r_type
!= R_PPC64_TOC
)
3629 if (rel
->r_offset
!= offset
)
3631 /* If someone messes with .opd alignment then after a
3632 "ld -r" we might have padding in the middle of .opd.
3633 Also, there's nothing to prevent someone putting
3634 something silly in .opd with the assembler. No .opd
3635 optimization for them! */
3636 (*_bfd_error_handler
)
3637 (_("%s: .opd is not a regular array of opd entries"),
3638 bfd_archive_filename (ibfd
));
3643 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3647 if (r_symndx
>= symtab_hdr
->sh_info
)
3649 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3650 while (h
->root
.type
== bfd_link_hash_indirect
3651 || h
->root
.type
== bfd_link_hash_warning
)
3652 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3653 if (h
->root
.type
== bfd_link_hash_defined
3654 || h
->root
.type
== bfd_link_hash_defweak
)
3655 sym_sec
= h
->root
.u
.def
.section
;
3659 if (local_syms
== NULL
)
3661 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3662 if (local_syms
== NULL
)
3663 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3664 symtab_hdr
->sh_info
, 0,
3666 if (local_syms
== NULL
)
3667 goto error_free_rel
;
3669 sym
= local_syms
+ r_symndx
;
3670 if ((sym
->st_shndx
!= SHN_UNDEF
3671 && sym
->st_shndx
< SHN_LORESERVE
)
3672 || sym
->st_shndx
> SHN_HIRESERVE
)
3673 sym_sec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
3676 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
3678 (*_bfd_error_handler
)
3679 (_("%s: undefined sym `%s' in .opd section"),
3680 bfd_archive_filename (ibfd
),
3681 h
!= NULL
? h
->root
.root
.string
: "<local symbol>");
3686 /* opd entries are always for functions defined in the
3687 current input bfd. If the symbol isn't defined in the
3688 input bfd, then we won't be using the function in this
3689 bfd; It must be defined in a linkonce section in another
3690 bfd, or is weak. It's also possible that we are
3691 discarding the function due to a linker script /DISCARD/,
3692 which we test for via the output_section. */
3693 if (sym_sec
->owner
!= ibfd
3694 || sym_sec
->output_section
== bfd_abs_section_ptr
)
3702 Elf_Internal_Rela
*write_rel
;
3703 bfd_byte
*rptr
, *wptr
;
3706 /* This seems a waste of time as input .opd sections are all
3707 zeros as generated by gcc, but I suppose there's no reason
3708 this will always be so. We might start putting something in
3709 the third word of .opd entries. */
3710 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
3712 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
3714 || !bfd_get_section_contents (ibfd
, sec
, loc
, (bfd_vma
) 0,
3717 if (local_syms
!= NULL
3718 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3721 if (elf_section_data (sec
)->relocs
!= relstart
)
3725 sec
->contents
= loc
;
3726 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
3729 elf_section_data (sec
)->relocs
= relstart
;
3731 wptr
= sec
->contents
;
3732 rptr
= sec
->contents
;
3733 write_rel
= relstart
;
3736 for (rel
= relstart
; rel
< relend
; rel
++)
3738 if (rel
->r_offset
== offset
)
3740 unsigned long r_symndx
;
3742 struct elf_link_hash_entry
*h
;
3743 Elf_Internal_Sym
*sym
;
3745 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3749 if (r_symndx
>= symtab_hdr
->sh_info
)
3751 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3752 while (h
->root
.type
== bfd_link_hash_indirect
3753 || h
->root
.type
== bfd_link_hash_warning
)
3754 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3755 if (h
->root
.type
== bfd_link_hash_defined
3756 || h
->root
.type
== bfd_link_hash_defweak
)
3757 sym_sec
= h
->root
.u
.def
.section
;
3761 sym
= local_syms
+ r_symndx
;
3762 if ((sym
->st_shndx
!= SHN_UNDEF
3763 && sym
->st_shndx
< SHN_LORESERVE
)
3764 || sym
->st_shndx
> SHN_HIRESERVE
)
3765 sym_sec
= bfd_section_from_elf_index (ibfd
,
3769 skip
= (sym_sec
->owner
!= ibfd
3770 || sym_sec
->output_section
== bfd_abs_section_ptr
);
3773 if (h
!= NULL
&& sym_sec
->owner
== ibfd
)
3775 /* Arrange for the function descriptor sym
3777 struct ppc_link_hash_entry
*fdh
;
3778 struct ppc_link_hash_entry
*fh
;
3780 fh
= (struct ppc_link_hash_entry
*) h
;
3781 fdh
= (struct ppc_link_hash_entry
*) fh
->oh
;
3784 const char *fd_name
;
3785 struct ppc_link_hash_table
*htab
;
3787 fd_name
= h
->root
.root
.string
+ 1;
3788 htab
= ppc_hash_table (info
);
3789 fdh
= (struct ppc_link_hash_entry
*)
3790 elf_link_hash_lookup (&htab
->elf
, fd_name
,
3791 FALSE
, FALSE
, FALSE
);
3792 fdh
->is_func_descriptor
= 1;
3798 fdh
->elf
.root
.u
.def
.value
= 0;
3799 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
3804 /* We'll be keeping this opd entry. */
3808 /* Redefine the function descriptor symbol
3809 to this location in the opd section.
3810 We've checked above that opd relocs are
3812 struct ppc_link_hash_entry
*fdh
;
3813 struct ppc_link_hash_entry
*fh
;
3815 fh
= (struct ppc_link_hash_entry
*) h
;
3816 fdh
= (struct ppc_link_hash_entry
*) fh
->oh
;
3819 const char *fd_name
;
3820 struct ppc_link_hash_table
*htab
;
3822 fd_name
= h
->root
.root
.string
+ 1;
3823 htab
= ppc_hash_table (info
);
3824 fdh
= (struct ppc_link_hash_entry
*)
3825 elf_link_hash_lookup (&htab
->elf
, fd_name
,
3826 FALSE
, FALSE
, FALSE
);
3827 fdh
->is_func_descriptor
= 1;
3833 fdh
->elf
.root
.u
.def
.value
= wptr
- sec
->contents
;
3837 /* Local syms are a bit tricky. We could
3838 tweak them as they can be cached, but
3839 we'd need to look through the local syms
3840 for the function descriptor sym which we
3841 don't have at the moment. So keep an
3842 array of adjustments. */
3843 adjust
[rel
->r_offset
/ 24] = wptr
- rptr
;
3847 memcpy (wptr
, rptr
, 24);
3854 /* We need to adjust any reloc offsets to point to the
3855 new opd entries. While we're at it, we may as well
3856 remove redundant relocs. */
3859 rel
->r_offset
+= wptr
- rptr
;
3860 if (write_rel
!= rel
)
3861 memcpy (write_rel
, rel
, sizeof (*rel
));
3866 sec
->_cooked_size
= wptr
- sec
->contents
;
3867 sec
->reloc_count
= write_rel
- relstart
;
3868 /* Fudge the size too, as this is used later in
3869 elf_bfd_final_link if we are emitting relocs. */
3870 elf_section_data (sec
)->rel_hdr
.sh_size
3871 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
3872 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
3874 else if (elf_section_data (sec
)->relocs
!= relstart
)
3877 if (local_syms
!= NULL
3878 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3880 if (!info
->keep_memory
)
3883 symtab_hdr
->contents
= (unsigned char *) local_syms
;
3890 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3891 will be called from elflink.h. If elflink.h doesn't call our
3892 finish_dynamic_symbol routine, we'll need to do something about
3893 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3894 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3896 && ((INFO)->shared \
3897 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3898 && ((H)->dynindx != -1 \
3899 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3901 /* Allocate space in .plt, .got and associated reloc sections for
3905 allocate_dynrelocs (h
, inf
)
3906 struct elf_link_hash_entry
*h
;
3909 struct bfd_link_info
*info
;
3910 struct ppc_link_hash_table
*htab
;
3912 struct ppc_link_hash_entry
*eh
;
3913 struct ppc_dyn_relocs
*p
;
3915 if (h
->root
.type
== bfd_link_hash_indirect
)
3918 if (h
->root
.type
== bfd_link_hash_warning
)
3919 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3921 info
= (struct bfd_link_info
*) inf
;
3922 htab
= ppc_hash_table (info
);
3924 if (htab
->elf
.dynamic_sections_created
3925 && h
->plt
.refcount
> 0
3926 && h
->dynindx
!= -1)
3928 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
3930 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3932 /* If this is the first .plt entry, make room for the special
3935 if (s
->_raw_size
== 0)
3936 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3938 h
->plt
.offset
= s
->_raw_size
;
3940 /* Make room for this entry. */
3941 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3943 /* Make room for the .glink code. */
3945 if (s
->_raw_size
== 0)
3946 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
3947 /* We need bigger stubs past index 32767. */
3948 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
3950 s
->_raw_size
+= 2*4;
3952 /* We also need to make an entry in the .rela.plt section. */
3954 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3958 h
->plt
.offset
= (bfd_vma
) -1;
3959 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3964 h
->plt
.offset
= (bfd_vma
) -1;
3965 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3968 if (h
->got
.refcount
> 0)
3972 /* Make sure this symbol is output as a dynamic symbol.
3973 Undefined weak syms won't yet be marked as dynamic. */
3974 if (h
->dynindx
== -1
3975 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3977 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3982 h
->got
.offset
= s
->_raw_size
;
3984 dyn
= htab
->elf
.dynamic_sections_created
;
3985 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
3986 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
3989 h
->got
.offset
= (bfd_vma
) -1;
3991 eh
= (struct ppc_link_hash_entry
*) h
;
3992 if (eh
->dyn_relocs
== NULL
)
3995 /* In the shared -Bsymbolic case, discard space allocated for
3996 dynamic pc-relative relocs against symbols which turn out to be
3997 defined in regular objects. For the normal shared case, discard
3998 space for relocs that have become local due to symbol visibility
4003 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
4004 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
4007 struct ppc_dyn_relocs
**pp
;
4009 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4011 p
->count
-= p
->pc_count
;
4022 /* For the non-shared case, discard space for relocs against
4023 symbols which turn out to need copy relocs or are not
4026 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4027 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4028 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4029 || (htab
->elf
.dynamic_sections_created
4030 && (h
->root
.type
== bfd_link_hash_undefweak
4031 || h
->root
.type
== bfd_link_hash_undefined
))))
4033 /* Make sure this symbol is output as a dynamic symbol.
4034 Undefined weak syms won't yet be marked as dynamic. */
4035 if (h
->dynindx
== -1
4036 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4038 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
4042 /* If that succeeded, we know we'll be keeping all the
4044 if (h
->dynindx
!= -1)
4048 eh
->dyn_relocs
= NULL
;
4053 /* Finally, allocate space. */
4054 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4056 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4057 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4063 /* Find any dynamic relocs that apply to read-only sections. */
4066 readonly_dynrelocs (h
, inf
)
4067 struct elf_link_hash_entry
*h
;
4070 struct ppc_link_hash_entry
*eh
;
4071 struct ppc_dyn_relocs
*p
;
4073 if (h
->root
.type
== bfd_link_hash_warning
)
4074 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4076 eh
= (struct ppc_link_hash_entry
*) h
;
4077 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4079 asection
*s
= p
->sec
->output_section
;
4081 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4083 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4085 info
->flags
|= DF_TEXTREL
;
4087 /* Not an error, just cut short the traversal. */
4094 /* Set the sizes of the dynamic sections. */
4097 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
4098 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4099 struct bfd_link_info
*info
;
4101 struct ppc_link_hash_table
*htab
;
4107 htab
= ppc_hash_table (info
);
4108 dynobj
= htab
->elf
.dynobj
;
4112 if (htab
->elf
.dynamic_sections_created
)
4114 /* Set the contents of the .interp section to the interpreter. */
4117 s
= bfd_get_section_by_name (dynobj
, ".interp");
4120 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4121 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4125 /* Set up .got offsets for local syms, and space for local dynamic
4127 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4129 bfd_signed_vma
*local_got
;
4130 bfd_signed_vma
*end_local_got
;
4131 bfd_size_type locsymcount
;
4132 Elf_Internal_Shdr
*symtab_hdr
;
4135 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4138 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4140 struct ppc_dyn_relocs
*p
;
4142 for (p
= *((struct ppc_dyn_relocs
**)
4143 &elf_section_data (s
)->local_dynrel
);
4147 if (!bfd_is_abs_section (p
->sec
)
4148 && bfd_is_abs_section (p
->sec
->output_section
))
4150 /* Input section has been discarded, either because
4151 it is a copy of a linkonce section or due to
4152 linker script /DISCARD/, so we'll be discarding
4155 else if (p
->count
!= 0)
4157 srel
= elf_section_data (p
->sec
)->sreloc
;
4158 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4159 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4160 info
->flags
|= DF_TEXTREL
;
4165 local_got
= elf_local_got_refcounts (ibfd
);
4169 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4170 locsymcount
= symtab_hdr
->sh_info
;
4171 end_local_got
= local_got
+ locsymcount
;
4173 srel
= htab
->srelgot
;
4174 for (; local_got
< end_local_got
; ++local_got
)
4178 *local_got
= s
->_raw_size
;
4181 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
4184 *local_got
= (bfd_vma
) -1;
4188 /* Allocate global sym .plt and .got entries, and space for global
4189 sym dynamic relocs. */
4190 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
4192 /* We now have determined the sizes of the various dynamic sections.
4193 Allocate memory for them. */
4195 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4197 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4200 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
4201 /* These haven't been allocated yet; don't strip. */
4203 else if (s
== htab
->splt
4205 || s
== htab
->sglink
)
4207 /* Strip this section if we don't need it; see the
4210 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4212 if (s
->_raw_size
== 0)
4214 /* If we don't need this section, strip it from the
4215 output file. This is mostly to handle .rela.bss and
4216 .rela.plt. We must create both sections in
4217 create_dynamic_sections, because they must be created
4218 before the linker maps input sections to output
4219 sections. The linker does that before
4220 adjust_dynamic_symbol is called, and it is that
4221 function which decides whether anything needs to go
4222 into these sections. */
4226 if (s
!= htab
->srelplt
)
4229 /* We use the reloc_count field as a counter if we need
4230 to copy relocs into the output file. */
4236 /* It's not one of our sections, so don't allocate space. */
4240 if (s
->_raw_size
== 0)
4242 _bfd_strip_section_from_output (info
, s
);
4246 /* .plt is in the bss section. We don't initialise it. */
4247 if ((s
->flags
& SEC_LOAD
) == 0)
4250 /* Allocate memory for the section contents. We use bfd_zalloc
4251 here in case unused entries are not reclaimed before the
4252 section's contents are written out. This should not happen,
4253 but this way if it does, we get a R_PPC64_NONE reloc instead
4255 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4256 if (s
->contents
== NULL
)
4260 if (htab
->elf
.dynamic_sections_created
)
4262 /* Add some entries to the .dynamic section. We fill in the
4263 values later, in ppc64_elf_finish_dynamic_sections, but we
4264 must add the entries now so that we get the correct size for
4265 the .dynamic section. The DT_DEBUG entry is filled in by the
4266 dynamic linker and used by the debugger. */
4267 #define add_dynamic_entry(TAG, VAL) \
4268 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4272 if (!add_dynamic_entry (DT_DEBUG
, 0))
4276 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
4278 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4279 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4280 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4281 || !add_dynamic_entry (DT_JMPREL
, 0)
4282 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
4288 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
4289 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
4295 if (!add_dynamic_entry (DT_RELA
, 0)
4296 || !add_dynamic_entry (DT_RELASZ
, 0)
4297 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4300 /* If any dynamic relocs apply to a read-only section,
4301 then we need a DT_TEXTREL entry. */
4302 if ((info
->flags
& DF_TEXTREL
) == 0)
4303 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
4306 if ((info
->flags
& DF_TEXTREL
) != 0)
4308 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4313 #undef add_dynamic_entry
4318 /* Determine the type of stub needed, if any, for a call. */
4320 static INLINE
enum ppc_stub_type
4321 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
4322 asection
*input_sec
;
4323 const Elf_Internal_Rela
*rel
;
4324 struct ppc_link_hash_entry
**hash
;
4325 bfd_vma destination
;
4327 struct ppc_link_hash_entry
*h
= *hash
;
4329 bfd_vma branch_offset
;
4330 bfd_vma max_branch_offset
;
4331 unsigned int r_type
;
4336 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
4337 && h
->oh
->dynindx
!= -1)
4339 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
4340 return ppc_stub_plt_call
;
4343 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
4344 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
4345 return ppc_stub_none
;
4348 /* Determine where the call point is. */
4349 location
= (input_sec
->output_offset
4350 + input_sec
->output_section
->vma
4353 branch_offset
= destination
- location
;
4354 r_type
= ELF64_R_TYPE (rel
->r_info
);
4356 /* Determine if a long branch stub is needed. */
4357 max_branch_offset
= 1 << 25;
4358 if (r_type
!= (unsigned int) R_PPC64_REL24
)
4359 max_branch_offset
= 1 << 15;
4361 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
4362 /* We need a stub. Figure out whether a long_branch or plt_branch
4364 return ppc_stub_long_branch
;
4366 return ppc_stub_none
;
4369 /* Build a .plt call stub. */
4372 build_plt_stub (obfd
, p
, offset
, glink
)
4378 #define PPC_LO(v) ((v) & 0xffff)
4379 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4380 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4383 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
4384 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
4386 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
4387 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4388 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4389 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4391 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
4392 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4393 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4395 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
4396 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4397 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
4402 ppc_build_one_stub (gen_entry
, in_arg
)
4403 struct bfd_hash_entry
*gen_entry
;
4406 struct ppc_stub_hash_entry
*stub_entry
;
4407 struct ppc_branch_hash_entry
*br_entry
;
4408 struct bfd_link_info
*info
;
4409 struct ppc_link_hash_table
*htab
;
4418 /* Massage our args to the form they really have. */
4419 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4420 info
= (struct bfd_link_info
*) in_arg
;
4422 htab
= ppc_hash_table (info
);
4423 stub_sec
= stub_entry
->stub_sec
;
4425 /* Make a note of the offset within the stubs for this entry. */
4426 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
4427 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4429 stub_bfd
= stub_sec
->owner
;
4431 switch (stub_entry
->stub_type
)
4433 case ppc_stub_long_branch
:
4434 /* Branches are relative. This is where we are going to. */
4435 off
= (stub_entry
->target_value
4436 + stub_entry
->target_section
->output_offset
4437 + stub_entry
->target_section
->output_section
->vma
);
4439 /* And this is where we are coming from. */
4440 off
-= (stub_entry
->stub_offset
4441 + stub_sec
->output_offset
4442 + stub_sec
->output_section
->vma
);
4444 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
4446 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
4450 case ppc_stub_plt_branch
:
4451 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4452 stub_entry
->root
.string
+ 9,
4454 if (br_entry
== NULL
)
4456 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
4457 stub_entry
->root
.string
+ 9);
4458 htab
->stub_error
= TRUE
;
4462 off
= (stub_entry
->target_value
4463 + stub_entry
->target_section
->output_offset
4464 + stub_entry
->target_section
->output_section
->vma
);
4466 bfd_put_64 (htab
->sbrlt
->owner
, off
,
4467 htab
->sbrlt
->contents
+ br_entry
->offset
);
4471 /* Create a reloc for the branch lookup table entry. */
4472 Elf_Internal_Rela rela
;
4475 rela
.r_offset
= (br_entry
->offset
4476 + htab
->sbrlt
->output_offset
4477 + htab
->sbrlt
->output_section
->vma
);
4478 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
4479 rela
.r_addend
= off
;
4481 loc
= htab
->srelbrlt
->contents
;
4482 loc
+= htab
->srelbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
4483 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, loc
);
4486 off
= (br_entry
->offset
4487 + htab
->sbrlt
->output_offset
4488 + htab
->sbrlt
->output_section
->vma
4489 - elf_gp (htab
->sbrlt
->output_section
->owner
)
4492 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4494 (*_bfd_error_handler
)
4495 (_("linkage table error against `%s'"),
4496 stub_entry
->root
.string
);
4497 bfd_set_error (bfd_error_bad_value
);
4498 htab
->stub_error
= TRUE
;
4503 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
4504 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
4505 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
4506 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
4510 case ppc_stub_plt_call
:
4511 /* Do the best we can for shared libraries built without
4512 exporting ".foo" for each "foo". This can happen when symbol
4513 versioning scripts strip all bar a subset of symbols. */
4514 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
4515 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
4517 /* Point the symbol at the stub. There may be multiple stubs,
4518 we don't really care; The main thing is to make this sym
4519 defined somewhere. */
4520 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
4521 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
4522 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
4525 /* Now build the stub. */
4526 off
= stub_entry
->h
->elf
.plt
.offset
;
4527 if (off
>= (bfd_vma
) -2)
4530 off
&= ~ (bfd_vma
) 1;
4531 off
+= (htab
->splt
->output_offset
4532 + htab
->splt
->output_section
->vma
4533 - elf_gp (htab
->splt
->output_section
->owner
)
4536 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4538 (*_bfd_error_handler
)
4539 (_("linkage table error against `%s'"),
4540 stub_entry
->h
->elf
.root
.root
.string
);
4541 bfd_set_error (bfd_error_bad_value
);
4542 htab
->stub_error
= TRUE
;
4546 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
4555 stub_sec
->_cooked_size
+= size
;
4559 /* As above, but don't actually build the stub. Just bump offset so
4560 we know stub section sizes, and select plt_branch stubs where
4561 long_branch stubs won't do. */
4564 ppc_size_one_stub (gen_entry
, in_arg
)
4565 struct bfd_hash_entry
*gen_entry
;
4568 struct ppc_stub_hash_entry
*stub_entry
;
4569 struct ppc_link_hash_table
*htab
;
4573 /* Massage our args to the form they really have. */
4574 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4575 htab
= (struct ppc_link_hash_table
*) in_arg
;
4577 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
4579 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
4580 off
+= (htab
->splt
->output_offset
4581 + htab
->splt
->output_section
->vma
4582 - elf_gp (htab
->splt
->output_section
->owner
)
4586 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
4591 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4592 stub_entry
->stub_type
= ppc_stub_long_branch
;
4595 off
= (stub_entry
->target_value
4596 + stub_entry
->target_section
->output_offset
4597 + stub_entry
->target_section
->output_section
->vma
);
4598 off
-= (stub_entry
->stub_sec
->_raw_size
4599 + stub_entry
->stub_sec
->output_offset
4600 + stub_entry
->stub_sec
->output_section
->vma
);
4602 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
4604 struct ppc_branch_hash_entry
*br_entry
;
4606 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4607 stub_entry
->root
.string
+ 9,
4609 if (br_entry
== NULL
)
4611 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4612 stub_entry
->root
.string
+ 9);
4613 htab
->stub_error
= TRUE
;
4617 if (br_entry
->iter
!= htab
->stub_iteration
)
4619 br_entry
->iter
= htab
->stub_iteration
;
4620 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4621 htab
->sbrlt
->_raw_size
+= 8;
4623 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4628 stub_entry
->stub_sec
->_raw_size
+= size
;
4632 /* Set up various things so that we can make a list of input sections
4633 for each output section included in the link. Returns -1 on error,
4634 0 when no stubs will be needed, and 1 on success. */
4637 ppc64_elf_setup_section_lists (output_bfd
, info
)
4639 struct bfd_link_info
*info
;
4642 int top_id
, top_index
;
4644 asection
**input_list
, **list
;
4646 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4648 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
4649 || htab
->sbrlt
== NULL
)
4652 /* Find the top input section id. */
4653 for (input_bfd
= info
->input_bfds
, top_id
= 0;
4655 input_bfd
= input_bfd
->link_next
)
4657 for (section
= input_bfd
->sections
;
4659 section
= section
->next
)
4661 if (top_id
< section
->id
)
4662 top_id
= section
->id
;
4666 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4667 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4668 if (htab
->stub_group
== NULL
)
4671 /* We can't use output_bfd->section_count here to find the top output
4672 section index as some sections may have been removed, and
4673 _bfd_strip_section_from_output doesn't renumber the indices. */
4674 for (section
= output_bfd
->sections
, top_index
= 0;
4676 section
= section
->next
)
4678 if (top_index
< section
->index
)
4679 top_index
= section
->index
;
4682 htab
->top_index
= top_index
;
4683 amt
= sizeof (asection
*) * (top_index
+ 1);
4684 input_list
= (asection
**) bfd_malloc (amt
);
4685 htab
->input_list
= input_list
;
4686 if (input_list
== NULL
)
4689 /* For sections we aren't interested in, mark their entries with a
4690 value we can check later. */
4691 list
= input_list
+ top_index
;
4693 *list
= bfd_abs_section_ptr
;
4694 while (list
-- != input_list
);
4696 for (section
= output_bfd
->sections
;
4698 section
= section
->next
)
4700 if ((section
->flags
& SEC_CODE
) != 0)
4701 input_list
[section
->index
] = NULL
;
4707 /* The linker repeatedly calls this function for each input section,
4708 in the order that input sections are linked into output sections.
4709 Build lists of input sections to determine groupings between which
4710 we may insert linker stubs. */
4713 ppc64_elf_next_input_section (info
, isec
)
4714 struct bfd_link_info
*info
;
4717 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4719 if (isec
->output_section
->index
<= htab
->top_index
)
4721 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4722 if (*list
!= bfd_abs_section_ptr
)
4724 /* Steal the link_sec pointer for our list. */
4725 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4726 /* This happens to make the list in reverse order,
4727 which is what we want. */
4728 PREV_SEC (isec
) = *list
;
4734 /* See whether we can group stub sections together. Grouping stub
4735 sections may result in fewer stubs. More importantly, we need to
4736 put all .init* and .fini* stubs at the beginning of the .init or
4737 .fini output sections respectively, because glibc splits the
4738 _init and _fini functions into multiple parts. Putting a stub in
4739 the middle of a function is not a good idea. */
4742 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4743 struct ppc_link_hash_table
*htab
;
4744 bfd_size_type stub_group_size
;
4745 bfd_boolean stubs_always_before_branch
;
4747 asection
**list
= htab
->input_list
+ htab
->top_index
;
4750 asection
*tail
= *list
;
4751 if (tail
== bfd_abs_section_ptr
)
4753 while (tail
!= NULL
)
4757 bfd_size_type total
;
4760 if (tail
->_cooked_size
)
4761 total
= tail
->_cooked_size
;
4763 total
= tail
->_raw_size
;
4764 while ((prev
= PREV_SEC (curr
)) != NULL
4765 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4769 /* OK, the size from the start of CURR to the end is less
4770 than stub_group_size and thus can be handled by one stub
4771 section. (or the tail section is itself larger than
4772 stub_group_size, in which case we may be toast.) We
4773 should really be keeping track of the total size of stubs
4774 added here, as stubs contribute to the final output
4775 section size. That's a little tricky, and this way will
4776 only break if stubs added make the total size more than
4777 2^25, ie. for the default stub_group_size, if stubs total
4778 more than 2834432 bytes, or over 100000 plt call stubs. */
4781 prev
= PREV_SEC (tail
);
4782 /* Set up this stub group. */
4783 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4785 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4787 /* But wait, there's more! Input sections up to stub_group_size
4788 bytes before the stub section can be handled by it too. */
4789 if (!stubs_always_before_branch
)
4793 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4797 prev
= PREV_SEC (tail
);
4798 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4804 while (list
-- != htab
->input_list
);
4805 free (htab
->input_list
);
4809 /* Determine and set the size of the stub section for a final link.
4811 The basic idea here is to examine all the relocations looking for
4812 PC-relative calls to a target that is unreachable with a "bl"
4816 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
4817 add_stub_section
, layout_sections_again
)
4820 struct bfd_link_info
*info
;
4821 bfd_signed_vma group_size
;
4822 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
4823 void (*layout_sections_again
) PARAMS ((void));
4825 bfd_size_type stub_group_size
;
4826 bfd_boolean stubs_always_before_branch
;
4827 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4829 /* Stash our params away. */
4830 htab
->stub_bfd
= stub_bfd
;
4831 htab
->add_stub_section
= add_stub_section
;
4832 htab
->layout_sections_again
= layout_sections_again
;
4833 stubs_always_before_branch
= group_size
< 0;
4835 stub_group_size
= -group_size
;
4837 stub_group_size
= group_size
;
4838 if (stub_group_size
== 1)
4840 /* Default values. */
4841 stub_group_size
= 30720000;
4842 if (htab
->has_14bit_branch
)
4843 stub_group_size
= 30000;
4846 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4851 unsigned int bfd_indx
;
4853 bfd_boolean stub_changed
;
4855 htab
->stub_iteration
+= 1;
4856 stub_changed
= FALSE
;
4858 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4860 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4862 Elf_Internal_Shdr
*symtab_hdr
;
4864 Elf_Internal_Sym
*local_syms
= NULL
;
4866 /* We'll need the symbol table in a second. */
4867 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4868 if (symtab_hdr
->sh_info
== 0)
4871 /* Walk over each section attached to the input bfd. */
4872 for (section
= input_bfd
->sections
;
4874 section
= section
->next
)
4876 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4878 /* If there aren't any relocs, then there's nothing more
4880 if ((section
->flags
& SEC_RELOC
) == 0
4881 || section
->reloc_count
== 0)
4884 /* If this section is a link-once section that will be
4885 discarded, then don't create any stubs. */
4886 if (section
->output_section
== NULL
4887 || section
->output_section
->owner
!= output_bfd
)
4890 /* Get the relocs. */
4892 = _bfd_elf64_link_read_relocs (input_bfd
, section
, NULL
,
4893 (Elf_Internal_Rela
*) NULL
,
4895 if (internal_relocs
== NULL
)
4896 goto error_ret_free_local
;
4898 /* Now examine each relocation. */
4899 irela
= internal_relocs
;
4900 irelaend
= irela
+ section
->reloc_count
;
4901 for (; irela
< irelaend
; irela
++)
4903 unsigned int r_type
, r_indx
;
4904 enum ppc_stub_type stub_type
;
4905 struct ppc_stub_hash_entry
*stub_entry
;
4908 bfd_vma destination
;
4909 struct ppc_link_hash_entry
*hash
;
4911 const asection
*id_sec
;
4913 r_type
= ELF64_R_TYPE (irela
->r_info
);
4914 r_indx
= ELF64_R_SYM (irela
->r_info
);
4916 if (r_type
>= (unsigned int) R_PPC64_max
)
4918 bfd_set_error (bfd_error_bad_value
);
4919 goto error_ret_free_internal
;
4922 /* Only look for stubs on branch instructions. */
4923 if (r_type
!= (unsigned int) R_PPC64_REL24
4924 && r_type
!= (unsigned int) R_PPC64_REL14
4925 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
4926 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
4929 /* Now determine the call target, its name, value,
4935 if (r_indx
< symtab_hdr
->sh_info
)
4937 /* It's a local symbol. */
4938 Elf_Internal_Sym
*sym
;
4939 Elf_Internal_Shdr
*hdr
;
4941 if (local_syms
== NULL
)
4944 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4945 if (local_syms
== NULL
)
4947 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4948 symtab_hdr
->sh_info
, 0,
4950 if (local_syms
== NULL
)
4951 goto error_ret_free_internal
;
4953 sym
= local_syms
+ r_indx
;
4954 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4955 sym_sec
= hdr
->bfd_section
;
4956 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4957 sym_value
= sym
->st_value
;
4958 destination
= (sym_value
+ irela
->r_addend
4959 + sym_sec
->output_offset
4960 + sym_sec
->output_section
->vma
);
4964 /* It's an external symbol. */
4967 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4968 hash
= ((struct ppc_link_hash_entry
*)
4969 elf_sym_hashes (input_bfd
)[e_indx
]);
4971 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
4972 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
4973 hash
= ((struct ppc_link_hash_entry
*)
4974 hash
->elf
.root
.u
.i
.link
);
4976 if (hash
->elf
.root
.type
== bfd_link_hash_defined
4977 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
4979 sym_sec
= hash
->elf
.root
.u
.def
.section
;
4980 sym_value
= hash
->elf
.root
.u
.def
.value
;
4981 if (sym_sec
->output_section
!= NULL
)
4982 destination
= (sym_value
+ irela
->r_addend
4983 + sym_sec
->output_offset
4984 + sym_sec
->output_section
->vma
);
4986 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
4988 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
4992 bfd_set_error (bfd_error_bad_value
);
4993 goto error_ret_free_internal
;
4997 /* Determine what (if any) linker stub is needed. */
4998 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
5000 if (stub_type
== ppc_stub_none
)
5003 /* Support for grouping stub sections. */
5004 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5006 /* Get the name of this stub. */
5007 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
5009 goto error_ret_free_internal
;
5011 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
5012 stub_name
, FALSE
, FALSE
);
5013 if (stub_entry
!= NULL
)
5015 /* The proper stub has already been created. */
5020 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
5021 if (stub_entry
== NULL
)
5024 error_ret_free_internal
:
5025 if (elf_section_data (section
)->relocs
== NULL
)
5026 free (internal_relocs
);
5027 error_ret_free_local
:
5028 if (local_syms
!= NULL
5029 && (symtab_hdr
->contents
5030 != (unsigned char *) local_syms
))
5035 stub_entry
->target_value
= sym_value
;
5036 stub_entry
->target_section
= sym_sec
;
5037 stub_entry
->stub_type
= stub_type
;
5038 stub_entry
->h
= hash
;
5039 stub_changed
= TRUE
;
5042 /* We're done with the internal relocs, free them. */
5043 if (elf_section_data (section
)->relocs
!= internal_relocs
)
5044 free (internal_relocs
);
5047 if (local_syms
!= NULL
5048 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5050 if (!info
->keep_memory
)
5053 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5060 /* OK, we've added some stubs. Find out the new size of the
5062 for (stub_sec
= htab
->stub_bfd
->sections
;
5064 stub_sec
= stub_sec
->next
)
5066 stub_sec
->_raw_size
= 0;
5067 stub_sec
->_cooked_size
= 0;
5069 htab
->sbrlt
->_raw_size
= 0;
5070 htab
->sbrlt
->_cooked_size
= 0;
5072 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
5074 /* Ask the linker to do its stuff. */
5075 (*htab
->layout_sections_again
) ();
5078 /* It would be nice to strip .branch_lt from the output if the
5079 section is empty, but it's too late. If we strip sections here,
5080 the dynamic symbol table is corrupted since the section symbol
5081 for the stripped section isn't written. */
5086 /* Called after we have determined section placement. If sections
5087 move, we'll be called again. Provide a value for TOCstart. */
5090 ppc64_elf_toc (obfd
)
5096 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5097 order. The TOC starts where the first of these sections starts. */
5098 s
= bfd_get_section_by_name (obfd
, ".got");
5100 s
= bfd_get_section_by_name (obfd
, ".toc");
5102 s
= bfd_get_section_by_name (obfd
, ".tocbss");
5104 s
= bfd_get_section_by_name (obfd
, ".plt");
5107 /* This may happen for
5108 o references to TOC base (SYM@toc / TOC[tc0]) without a
5111 o --gc-sections and empty TOC sections
5113 FIXME: Warn user? */
5115 /* Look for a likely section. We probably won't even be
5117 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5118 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
5119 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5122 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5123 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
5124 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5127 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5128 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
5131 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5132 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
5138 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
5143 /* Build all the stubs associated with the current output file.
5144 The stubs are kept in a hash table attached to the main linker
5145 hash table. This function is called via gldelf64ppc_finish. */
5148 ppc64_elf_build_stubs (info
)
5149 struct bfd_link_info
*info
;
5151 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5156 for (stub_sec
= htab
->stub_bfd
->sections
;
5158 stub_sec
= stub_sec
->next
)
5162 /* Allocate memory to hold the linker stubs. */
5163 size
= stub_sec
->_raw_size
;
5166 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
5167 if (stub_sec
->contents
== NULL
)
5170 stub_sec
->_cooked_size
= 0;
5173 if (htab
->splt
!= NULL
)
5177 /* Build the .glink plt call stub. */
5178 plt_r2
= (htab
->splt
->output_offset
5179 + htab
->splt
->output_section
->vma
5180 - elf_gp (htab
->splt
->output_section
->owner
)
5182 p
= htab
->sglink
->contents
;
5183 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
5184 while (p
< htab
->sglink
->contents
+ GLINK_CALL_STUB_SIZE
)
5186 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
5190 /* Build the .glink lazy link call stubs. */
5192 while (p
< htab
->sglink
->contents
+ htab
->sglink
->_raw_size
)
5196 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
5201 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
5203 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
5206 bfd_put_32 (htab
->sglink
->owner
,
5207 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
5211 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
5214 if (htab
->sbrlt
->_raw_size
!= 0)
5216 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
5217 htab
->sbrlt
->_raw_size
);
5218 if (htab
->sbrlt
->contents
== NULL
)
5222 /* Build the stubs as directed by the stub hash table. */
5223 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
5225 for (stub_sec
= htab
->stub_bfd
->sections
;
5227 stub_sec
= stub_sec
->next
)
5229 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
5233 if (stub_sec
!= NULL
5234 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
5236 htab
->stub_error
= TRUE
;
5237 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
5240 return !htab
->stub_error
;
5243 /* The RELOCATE_SECTION function is called by the ELF backend linker
5244 to handle the relocations for a section.
5246 The relocs are always passed as Rela structures; if the section
5247 actually uses Rel structures, the r_addend field will always be
5250 This function is responsible for adjust the section contents as
5251 necessary, and (if using Rela relocs and generating a
5252 relocateable output file) adjusting the reloc addend as
5255 This function does not have to worry about setting the reloc
5256 address or the reloc symbol index.
5258 LOCAL_SYMS is a pointer to the swapped in local symbols.
5260 LOCAL_SECTIONS is an array giving the section in the input file
5261 corresponding to the st_shndx field of each local symbol.
5263 The global hash table entry for the global symbols can be found
5264 via elf_sym_hashes (input_bfd).
5266 When generating relocateable output, this function must handle
5267 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5268 going to be the section symbol corresponding to the output
5269 section, which means that the addend must be adjusted
5273 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5274 contents
, relocs
, local_syms
, local_sections
)
5276 struct bfd_link_info
*info
;
5278 asection
*input_section
;
5280 Elf_Internal_Rela
*relocs
;
5281 Elf_Internal_Sym
*local_syms
;
5282 asection
**local_sections
;
5284 struct ppc_link_hash_table
*htab
;
5285 Elf_Internal_Shdr
*symtab_hdr
;
5286 struct elf_link_hash_entry
**sym_hashes
;
5287 Elf_Internal_Rela
*rel
;
5288 Elf_Internal_Rela
*relend
;
5289 bfd_vma
*local_got_offsets
;
5291 bfd_boolean ret
= TRUE
;
5293 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5294 bfd_boolean is_power4
= FALSE
;
5296 if (info
->relocateable
)
5299 /* Initialize howto table if needed. */
5300 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5303 htab
= ppc_hash_table (info
);
5304 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5305 TOCstart
= elf_gp (output_bfd
);
5306 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5307 sym_hashes
= elf_sym_hashes (input_bfd
);
5308 is_opd
= elf_section_data (input_section
)->tdata
!= NULL
;
5311 relend
= relocs
+ input_section
->reloc_count
;
5312 for (; rel
< relend
; rel
++)
5314 enum elf_ppc64_reloc_type r_type
;
5317 bfd_reloc_status_type r
;
5318 Elf_Internal_Sym
*sym
;
5320 struct elf_link_hash_entry
*h
;
5321 struct elf_link_hash_entry
*fdh
;
5322 const char *sym_name
;
5323 unsigned long r_symndx
;
5325 bfd_boolean unresolved_reloc
;
5328 struct ppc_stub_hash_entry
*stub_entry
;
5329 bfd_vma max_br_offset
;
5332 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5333 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5334 offset
= rel
->r_offset
;
5335 addend
= rel
->r_addend
;
5336 r
= bfd_reloc_other
;
5337 sym
= (Elf_Internal_Sym
*) 0;
5338 sec
= (asection
*) 0;
5339 h
= (struct elf_link_hash_entry
*) 0;
5340 sym_name
= (const char *) 0;
5341 unresolved_reloc
= FALSE
;
5344 if (r_type
== R_PPC64_TOC
)
5346 /* Relocation value is TOC base. Symbol is ignored. */
5347 relocation
= TOCstart
+ TOC_BASE_OFF
;
5349 else if (r_symndx
< symtab_hdr
->sh_info
)
5351 /* It's a local symbol. */
5352 sym
= local_syms
+ r_symndx
;
5353 sec
= local_sections
[r_symndx
];
5354 sym_name
= "<local symbol>";
5356 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
5357 /* rel may have changed, update our copy of addend. */
5358 addend
= rel
->r_addend
;
5360 if (elf_section_data (sec
) != NULL
)
5362 long *opd_sym_adjust
;
5364 opd_sym_adjust
= (long *) elf_section_data (sec
)->tdata
;
5365 if (opd_sym_adjust
!= NULL
&& sym
->st_value
% 24 == 0)
5366 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
5371 /* It's a global symbol. */
5372 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5373 while (h
->root
.type
== bfd_link_hash_indirect
5374 || h
->root
.type
== bfd_link_hash_warning
)
5375 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5376 sym_name
= h
->root
.root
.string
;
5378 if (h
->root
.type
== bfd_link_hash_defined
5379 || h
->root
.type
== bfd_link_hash_defweak
)
5381 sec
= h
->root
.u
.def
.section
;
5382 if (sec
->output_section
== NULL
)
5383 /* Set a flag that will be cleared later if we find a
5384 relocation value for this symbol. output_section
5385 is typically NULL for symbols satisfied by a shared
5387 unresolved_reloc
= TRUE
;
5389 relocation
= (h
->root
.u
.def
.value
5390 + sec
->output_section
->vma
5391 + sec
->output_offset
);
5393 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5395 else if (info
->shared
5396 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
5397 && !info
->no_undefined
5398 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5402 if (! ((*info
->callbacks
->undefined_symbol
)
5403 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5404 offset
, (!info
->shared
5405 || info
->no_undefined
5406 || ELF_ST_VISIBILITY (h
->other
)))))
5412 /* First handle relocations that tweak non-addend part of insn. */
5419 /* Branch taken prediction relocations. */
5420 case R_PPC64_ADDR14_BRTAKEN
:
5421 case R_PPC64_REL14_BRTAKEN
:
5422 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5425 /* Branch not taken prediction relocations. */
5426 case R_PPC64_ADDR14_BRNTAKEN
:
5427 case R_PPC64_REL14_BRNTAKEN
:
5428 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
5431 /* Set 'a' bit. This is 0b00010 in BO field for branch
5432 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5433 for branch on CTR insns (BO == 1a00t or 1a01t). */
5434 if ((insn
& (0x14 << 21)) == (0x04 << 21))
5436 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
5444 + input_section
->output_offset
5445 + input_section
->output_section
->vma
);
5447 /* Invert 'y' bit if not the default. */
5448 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
5452 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
5456 /* A REL24 branching to a linkage function is followed by a
5457 nop. We replace the nop with a ld in order to restore
5458 the TOC base pointer. Only calls to shared objects need
5459 to alter the TOC base. These are recognized by their
5460 need for a PLT entry. */
5462 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
5463 && fdh
->plt
.offset
!= (bfd_vma
) -1
5464 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
5465 rel
, htab
)) != NULL
)
5467 bfd_boolean can_plt_call
= 0;
5469 if (offset
+ 8 <= input_section
->_cooked_size
)
5471 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
5473 || insn
== CROR_151515
|| insn
== CROR_313131
)
5475 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
5476 contents
+ offset
+ 4);
5483 /* If this is a plain branch rather than a branch
5484 and link, don't require a nop. */
5485 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5486 if ((insn
& 1) == 0)
5492 relocation
= (stub_entry
->stub_offset
5493 + stub_entry
->stub_sec
->output_offset
5494 + stub_entry
->stub_sec
->output_section
->vma
);
5496 unresolved_reloc
= FALSE
;
5501 && h
->root
.type
== bfd_link_hash_undefweak
5505 /* Tweak calls to undefined weak functions to point at a
5506 blr. We can thus call a weak function without first
5507 checking whether the function is defined. We have a
5508 blr at the end of .sfpr. */
5509 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
5510 relocation
= (htab
->sfpr
->_raw_size
- 4
5511 + htab
->sfpr
->output_offset
5512 + htab
->sfpr
->output_section
->vma
);
5514 + input_section
->output_offset
5515 + input_section
->output_section
->vma
);
5517 /* But let's not be silly about it. If the blr isn't in
5518 reach, just go to the next instruction. */
5519 if (relocation
- from
+ (1 << 25) >= (1 << 26)
5520 || htab
->sfpr
->_raw_size
== 0)
5521 relocation
= from
+ 4;
5530 (*_bfd_error_handler
)
5531 (_("%s: unknown relocation type %d for symbol %s"),
5532 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5534 bfd_set_error (bfd_error_bad_value
);
5539 case R_PPC64_GNU_VTINHERIT
:
5540 case R_PPC64_GNU_VTENTRY
:
5543 /* GOT16 relocations. Like an ADDR16 using the symbol's
5544 address in the GOT as relocation value instead of the
5545 symbols value itself. Also, create a GOT entry for the
5546 symbol and put the symbol value there. */
5548 case R_PPC64_GOT16_LO
:
5549 case R_PPC64_GOT16_HI
:
5550 case R_PPC64_GOT16_HA
:
5551 case R_PPC64_GOT16_DS
:
5552 case R_PPC64_GOT16_LO_DS
:
5554 /* Relocation is to the entry for this symbol in the global
5558 if (htab
->sgot
== NULL
)
5565 off
= h
->got
.offset
;
5566 dyn
= htab
->elf
.dynamic_sections_created
;
5567 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5571 || (h
->elf_link_hash_flags
5572 & ELF_LINK_FORCED_LOCAL
))
5573 && (h
->elf_link_hash_flags
5574 & ELF_LINK_HASH_DEF_REGULAR
)))
5576 /* This is actually a static link, or it is a
5577 -Bsymbolic link and the symbol is defined
5578 locally, or the symbol was forced to be local
5579 because of a version file. We must initialize
5580 this entry in the global offset table. Since the
5581 offset must always be a multiple of 8, we use the
5582 least significant bit to record whether we have
5583 initialized it already.
5585 When doing a dynamic link, we create a .rel.got
5586 relocation entry to initialize the value. This
5587 is done in the finish_dynamic_symbol routine. */
5592 bfd_put_64 (output_bfd
, relocation
,
5593 htab
->sgot
->contents
+ off
);
5598 unresolved_reloc
= FALSE
;
5602 if (local_got_offsets
== NULL
)
5605 off
= local_got_offsets
[r_symndx
];
5607 /* The offset must always be a multiple of 8. We use
5608 the least significant bit to record whether we have
5609 already processed this entry. */
5614 bfd_put_64 (output_bfd
, relocation
,
5615 htab
->sgot
->contents
+ off
);
5619 Elf_Internal_Rela outrel
;
5622 /* We need to generate a R_PPC64_RELATIVE reloc
5623 for the dynamic linker. */
5624 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5625 + htab
->sgot
->output_offset
5627 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5628 outrel
.r_addend
= relocation
;
5629 loc
= htab
->srelgot
->contents
;
5630 loc
+= (htab
->srelgot
->reloc_count
++
5631 * sizeof (Elf64_External_Rela
));
5632 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5635 local_got_offsets
[r_symndx
] |= 1;
5639 if (off
>= (bfd_vma
) -2)
5642 relocation
= htab
->sgot
->output_offset
+ off
;
5644 /* TOC base (r2) is TOC start plus 0x8000. */
5645 addend
-= TOC_BASE_OFF
;
5649 case R_PPC64_PLT16_HA
:
5650 case R_PPC64_PLT16_HI
:
5651 case R_PPC64_PLT16_LO
:
5654 /* Relocation is to the entry for this symbol in the
5655 procedure linkage table. */
5657 /* Resolve a PLT reloc against a local symbol directly,
5658 without using the procedure linkage table. */
5662 if (h
->plt
.offset
== (bfd_vma
) -1
5663 || htab
->splt
== NULL
)
5665 /* We didn't make a PLT entry for this symbol. This
5666 happens when statically linking PIC code, or when
5667 using -Bsymbolic. */
5671 relocation
= (htab
->splt
->output_section
->vma
5672 + htab
->splt
->output_offset
5674 unresolved_reloc
= FALSE
;
5677 /* TOC16 relocs. We want the offset relative to the TOC base,
5678 which is the address of the start of the TOC plus 0x8000.
5679 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5682 case R_PPC64_TOC16_LO
:
5683 case R_PPC64_TOC16_HI
:
5684 case R_PPC64_TOC16_DS
:
5685 case R_PPC64_TOC16_LO_DS
:
5686 case R_PPC64_TOC16_HA
:
5687 addend
-= TOCstart
+ TOC_BASE_OFF
;
5690 /* Relocate against the beginning of the section. */
5691 case R_PPC64_SECTOFF
:
5692 case R_PPC64_SECTOFF_LO
:
5693 case R_PPC64_SECTOFF_HI
:
5694 case R_PPC64_SECTOFF_DS
:
5695 case R_PPC64_SECTOFF_LO_DS
:
5696 case R_PPC64_SECTOFF_HA
:
5697 if (sec
!= (asection
*) 0)
5698 addend
-= sec
->output_section
->vma
;
5702 case R_PPC64_REL14_BRNTAKEN
:
5703 case R_PPC64_REL14_BRTAKEN
:
5707 /* Relocations that may need to be propagated if this is a
5712 case R_PPC64_ADDR14
:
5713 case R_PPC64_ADDR14_BRNTAKEN
:
5714 case R_PPC64_ADDR14_BRTAKEN
:
5715 case R_PPC64_ADDR16
:
5716 case R_PPC64_ADDR16_DS
:
5717 case R_PPC64_ADDR16_HA
:
5718 case R_PPC64_ADDR16_HI
:
5719 case R_PPC64_ADDR16_HIGHER
:
5720 case R_PPC64_ADDR16_HIGHERA
:
5721 case R_PPC64_ADDR16_HIGHEST
:
5722 case R_PPC64_ADDR16_HIGHESTA
:
5723 case R_PPC64_ADDR16_LO
:
5724 case R_PPC64_ADDR16_LO_DS
:
5725 case R_PPC64_ADDR24
:
5726 case R_PPC64_ADDR32
:
5727 case R_PPC64_ADDR64
:
5728 case R_PPC64_UADDR16
:
5729 case R_PPC64_UADDR32
:
5730 case R_PPC64_UADDR64
:
5731 /* r_symndx will be zero only for relocs against symbols
5732 from removed linkonce sections, or sections discarded by
5739 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5742 if (NO_OPD_RELOCS
&& is_opd
)
5746 && (IS_ABSOLUTE_RELOC (r_type
)
5749 && (! info
->symbolic
5750 || (h
->elf_link_hash_flags
5751 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5755 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5756 && (((h
->elf_link_hash_flags
5757 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5758 && (h
->elf_link_hash_flags
5759 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5760 || h
->root
.type
== bfd_link_hash_undefweak
5761 || h
->root
.type
== bfd_link_hash_undefined
)))
5763 Elf_Internal_Rela outrel
;
5764 bfd_boolean skip
, relocate
;
5768 /* When generating a dynamic object, these relocations
5769 are copied into the output file to be resolved at run
5776 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5778 if (outrel
.r_offset
== (bfd_vma
) -1)
5780 else if (outrel
.r_offset
== (bfd_vma
) -2)
5781 skip
= TRUE
, relocate
= TRUE
;
5782 outrel
.r_offset
+= (input_section
->output_section
->vma
5783 + input_section
->output_offset
);
5784 outrel
.r_addend
= addend
;
5787 memset (&outrel
, 0, sizeof outrel
);
5791 && (!IS_ABSOLUTE_RELOC (r_type
)
5794 || (h
->elf_link_hash_flags
5795 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5796 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5799 /* This symbol is local, or marked to become local,
5800 or this is an opd section reloc which must point
5801 at a local function. */
5802 outrel
.r_addend
+= relocation
;
5804 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5806 if (is_opd
&& h
!= NULL
)
5808 /* Lie about opd entries. This case occurs
5809 when building shared libraries and we
5810 reference a function in another shared
5811 lib. The same thing happens for a weak
5812 definition in an application that's
5813 overridden by a strong definition in a
5814 shared lib. (I believe this is a generic
5815 bug in binutils handling of weak syms.)
5816 In these cases we won't use the opd
5817 entry in this lib. */
5818 unresolved_reloc
= FALSE
;
5820 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5826 if (bfd_is_abs_section (sec
))
5828 else if (sec
== NULL
|| sec
->owner
== NULL
)
5830 bfd_set_error (bfd_error_bad_value
);
5837 osec
= sec
->output_section
;
5838 indx
= elf_section_data (osec
)->dynindx
;
5840 /* We are turning this relocation into one
5841 against a section symbol, so subtract out
5842 the output section's address but not the
5843 offset of the input section in the output
5845 outrel
.r_addend
-= osec
->vma
;
5848 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
5852 sreloc
= elf_section_data (input_section
)->sreloc
;
5856 loc
= sreloc
->contents
;
5857 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
5858 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5860 /* If this reloc is against an external symbol, it will
5861 be computed at runtime, so there's no need to do
5869 case R_PPC64_GLOB_DAT
:
5870 case R_PPC64_JMP_SLOT
:
5871 case R_PPC64_RELATIVE
:
5872 /* We shouldn't ever see these dynamic relocs in relocatable
5876 case R_PPC64_PLTGOT16
:
5877 case R_PPC64_PLTGOT16_DS
:
5878 case R_PPC64_PLTGOT16_HA
:
5879 case R_PPC64_PLTGOT16_HI
:
5880 case R_PPC64_PLTGOT16_LO
:
5881 case R_PPC64_PLTGOT16_LO_DS
:
5882 case R_PPC64_PLTREL32
:
5883 case R_PPC64_PLTREL64
:
5884 /* These ones haven't been implemented yet. */
5886 (*_bfd_error_handler
)
5887 (_("%s: Relocation %s is not supported for symbol %s."),
5888 bfd_archive_filename (input_bfd
),
5889 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
5891 bfd_set_error (bfd_error_invalid_operation
);
5896 /* Do any further special processing. */
5902 case R_PPC64_ADDR16_HA
:
5903 case R_PPC64_ADDR16_HIGHERA
:
5904 case R_PPC64_ADDR16_HIGHESTA
:
5905 case R_PPC64_GOT16_HA
:
5906 case R_PPC64_PLTGOT16_HA
:
5907 case R_PPC64_PLT16_HA
:
5908 case R_PPC64_TOC16_HA
:
5909 case R_PPC64_SECTOFF_HA
:
5910 /* It's just possible that this symbol is a weak symbol
5911 that's not actually defined anywhere. In that case,
5912 'sec' would be NULL, and we should leave the symbol
5913 alone (it will be set to zero elsewhere in the link). */
5915 /* Add 0x10000 if sign bit in 0:15 is set. */
5916 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
5919 case R_PPC64_ADDR16_DS
:
5920 case R_PPC64_ADDR16_LO_DS
:
5921 case R_PPC64_GOT16_DS
:
5922 case R_PPC64_GOT16_LO_DS
:
5923 case R_PPC64_PLT16_LO_DS
:
5924 case R_PPC64_SECTOFF_DS
:
5925 case R_PPC64_SECTOFF_LO_DS
:
5926 case R_PPC64_TOC16_DS
:
5927 case R_PPC64_TOC16_LO_DS
:
5928 case R_PPC64_PLTGOT16_DS
:
5929 case R_PPC64_PLTGOT16_LO_DS
:
5930 if (((relocation
+ addend
) & 3) != 0)
5932 (*_bfd_error_handler
)
5933 (_("%s: error: relocation %s not a multiple of 4"),
5934 bfd_archive_filename (input_bfd
),
5935 ppc64_elf_howto_table
[(int) r_type
]->name
);
5936 bfd_set_error (bfd_error_bad_value
);
5943 case R_PPC64_REL14_BRNTAKEN
:
5944 case R_PPC64_REL14_BRTAKEN
:
5945 max_br_offset
= 1 << 15;
5949 max_br_offset
= 1 << 25;
5952 /* If the branch is out of reach, then redirect the
5953 call to the local stub for this function. */
5955 + input_section
->output_offset
5956 + input_section
->output_section
->vma
);
5957 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
5958 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
5959 rel
, htab
)) != NULL
)
5961 /* Munge up the value and addend so that we call the stub
5962 rather than the procedure directly. */
5963 relocation
= (stub_entry
->stub_offset
5964 + stub_entry
->stub_sec
->output_offset
5965 + stub_entry
->stub_sec
->output_section
->vma
);
5971 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5972 because such sections are not SEC_ALLOC and thus ld.so will
5973 not process them. */
5974 if (unresolved_reloc
5975 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5976 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5978 (*_bfd_error_handler
)
5979 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5980 bfd_archive_filename (input_bfd
),
5981 bfd_get_section_name (input_bfd
, input_section
),
5982 (long) rel
->r_offset
,
5983 h
->root
.root
.string
);
5987 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
5995 if (r
!= bfd_reloc_ok
)
6001 if (h
->root
.type
== bfd_link_hash_undefweak
6002 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
6004 /* Assume this is a call protected by other code that
6005 detects the symbol is undefined. If this is the case,
6006 we can safely ignore the overflow. If not, the
6007 program is hosed anyway, and a little warning isn't
6013 name
= h
->root
.root
.string
;
6017 name
= bfd_elf_string_from_elf_section (input_bfd
,
6018 symtab_hdr
->sh_link
,
6023 name
= bfd_section_name (input_bfd
, sec
);
6026 if (r
== bfd_reloc_overflow
)
6030 if (!((*info
->callbacks
->reloc_overflow
)
6031 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
6032 rel
->r_addend
, input_bfd
, input_section
, offset
)))
6037 (*_bfd_error_handler
)
6038 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
6039 bfd_archive_filename (input_bfd
),
6040 bfd_get_section_name (input_bfd
, input_section
),
6041 (long) rel
->r_offset
, name
, (int) r
);
6050 /* Finish up dynamic symbol handling. We set the contents of various
6051 dynamic sections here. */
6054 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6056 struct bfd_link_info
*info
;
6057 struct elf_link_hash_entry
*h
;
6058 Elf_Internal_Sym
*sym
;
6060 struct ppc_link_hash_table
*htab
;
6063 htab
= ppc_hash_table (info
);
6064 dynobj
= htab
->elf
.dynobj
;
6066 if (h
->plt
.offset
!= (bfd_vma
) -1
6067 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
6069 Elf_Internal_Rela rela
;
6072 /* This symbol has an entry in the procedure linkage table. Set
6075 if (htab
->splt
== NULL
6076 || htab
->srelplt
== NULL
6077 || htab
->sglink
== NULL
)
6080 /* Create a JMP_SLOT reloc to inform the dynamic linker to
6081 fill in the PLT entry. */
6083 rela
.r_offset
= (htab
->splt
->output_section
->vma
6084 + htab
->splt
->output_offset
6086 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
6089 loc
= htab
->srelplt
->contents
;
6090 loc
+= ((h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
6091 * sizeof (Elf64_External_Rela
));
6092 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6095 if (h
->got
.offset
!= (bfd_vma
) -1)
6097 Elf_Internal_Rela rela
;
6100 /* This symbol has an entry in the global offset table. Set it
6103 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
6106 rela
.r_offset
= (htab
->sgot
->output_section
->vma
6107 + htab
->sgot
->output_offset
6108 + (h
->got
.offset
&~ (bfd_vma
) 1));
6110 /* If this is a static link, or it is a -Bsymbolic link and the
6111 symbol is defined locally or was forced to be local because
6112 of a version file, we just want to emit a RELATIVE reloc.
6113 The entry in the global offset table will already have been
6114 initialized in the relocate_section function. */
6118 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6119 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6121 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6122 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6123 rela
.r_addend
= (h
->root
.u
.def
.value
6124 + h
->root
.u
.def
.section
->output_section
->vma
6125 + h
->root
.u
.def
.section
->output_offset
);
6129 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6130 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6131 htab
->sgot
->contents
+ h
->got
.offset
);
6132 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
6136 loc
= htab
->srelgot
->contents
;
6137 loc
+= htab
->srelgot
->reloc_count
++ * sizeof (Elf64_External_Rela
);
6138 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6141 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6143 Elf_Internal_Rela rela
;
6146 /* This symbol needs a copy reloc. Set it up. */
6148 if (h
->dynindx
== -1
6149 || (h
->root
.type
!= bfd_link_hash_defined
6150 && h
->root
.type
!= bfd_link_hash_defweak
)
6151 || htab
->srelbss
== NULL
)
6154 rela
.r_offset
= (h
->root
.u
.def
.value
6155 + h
->root
.u
.def
.section
->output_section
->vma
6156 + h
->root
.u
.def
.section
->output_offset
);
6157 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
6159 loc
= htab
->srelbss
->contents
;
6160 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
6161 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6164 /* Mark some specially defined symbols as absolute. */
6165 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
6166 sym
->st_shndx
= SHN_ABS
;
6171 /* Used to decide how to sort relocs in an optimal manner for the
6172 dynamic linker, before writing them out. */
6174 static enum elf_reloc_type_class
6175 ppc64_elf_reloc_type_class (rela
)
6176 const Elf_Internal_Rela
*rela
;
6178 enum elf_ppc64_reloc_type r_type
;
6180 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
6183 case R_PPC64_RELATIVE
:
6184 return reloc_class_relative
;
6185 case R_PPC64_JMP_SLOT
:
6186 return reloc_class_plt
;
6188 return reloc_class_copy
;
6190 return reloc_class_normal
;
6194 /* Finish up the dynamic sections. */
6197 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
6199 struct bfd_link_info
*info
;
6201 struct ppc_link_hash_table
*htab
;
6205 htab
= ppc_hash_table (info
);
6206 dynobj
= htab
->elf
.dynobj
;
6207 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6209 if (htab
->elf
.dynamic_sections_created
)
6211 Elf64_External_Dyn
*dyncon
, *dynconend
;
6213 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
6216 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
6217 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6218 for (; dyncon
< dynconend
; dyncon
++)
6220 Elf_Internal_Dyn dyn
;
6223 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6230 case DT_PPC64_GLINK
:
6232 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6236 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6239 dyn
.d_un
.d_ptr
= s
->vma
;
6242 case DT_PPC64_OPDSZ
:
6243 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6246 dyn
.d_un
.d_val
= s
->_raw_size
;
6251 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6256 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
6260 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
6264 /* Don't count procedure linkage table relocs in the
6265 overall reloc count. */
6269 dyn
.d_un
.d_val
-= s
->_raw_size
;
6273 /* We may not be using the standard ELF linker script.
6274 If .rela.plt is the first .rela section, we adjust
6275 DT_RELA to not include it. */
6279 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
6281 dyn
.d_un
.d_ptr
+= s
->_raw_size
;
6285 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6289 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
6291 /* Fill in the first entry in the global offset table.
6292 We use it to hold the link-time TOCbase. */
6293 bfd_put_64 (output_bfd
,
6294 elf_gp (output_bfd
) + TOC_BASE_OFF
,
6295 htab
->sgot
->contents
);
6297 /* Set .got entry size. */
6298 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
6301 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
6303 /* Set .plt entry size. */
6304 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
6311 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6312 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6313 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6314 #define TARGET_BIG_NAME "elf64-powerpc"
6315 #define ELF_ARCH bfd_arch_powerpc
6316 #define ELF_MACHINE_CODE EM_PPC64
6317 #define ELF_MAXPAGESIZE 0x10000
6318 #define elf_info_to_howto ppc64_elf_info_to_howto
6320 #ifdef EM_CYGNUS_POWERPC
6321 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6325 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6328 #define elf_backend_want_got_sym 0
6329 #define elf_backend_want_plt_sym 0
6330 #define elf_backend_plt_alignment 3
6331 #define elf_backend_plt_not_loaded 1
6332 #define elf_backend_got_symbol_offset 0
6333 #define elf_backend_got_header_size 8
6334 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6335 #define elf_backend_can_gc_sections 1
6336 #define elf_backend_can_refcount 1
6337 #define elf_backend_rela_normal 1
6339 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6340 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6341 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6342 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6344 #define elf_backend_object_p ppc64_elf_object_p
6345 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6346 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6347 #define elf_backend_check_relocs ppc64_elf_check_relocs
6348 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6349 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6350 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6351 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6352 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6353 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6354 #define elf_backend_relocate_section ppc64_elf_relocate_section
6355 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6356 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6357 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6359 #include "elf64-target.h"