1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
31 #include "elf64-ppc.h"
33 #define USE_RELA /* we want RELA relocations, not REL. */
36 static void ppc_howto_init
38 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
39 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
40 static void ppc64_elf_info_to_howto
41 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf64_Internal_Rela
*dst
));
42 static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc
43 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
44 static boolean ppc64_elf_set_private_flags
45 PARAMS ((bfd
*, flagword
));
46 static boolean ppc64_elf_merge_private_bfd_data
47 PARAMS ((bfd
*, bfd
*));
48 static boolean ppc64_elf_section_from_shdr
49 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, char *));
52 /* Mask to set RA in memory instructions. */
53 #define RA_REGISTER_MASK 0x001f0000
55 /* Value to shift register by to insert RA. */
56 #define RA_REGISTER_SHIFT 16
58 /* The name of the dynamic interpreter. This is put in the .interp
60 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
62 /* The size in bytes of an entry in the procedure linkage table. */
63 #define PLT_ENTRY_SIZE 24
65 /* The initial size of the plt reserved for the dynamic linker. */
66 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
68 /* TOC base pointers offset from start of TOC. */
69 #define TOC_BASE_OFF (0x8000)
71 /* .plt call stub instructions. */
72 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
73 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
74 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
75 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
76 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
77 /* ld %r11,xxx+16@l(%r12) */
78 #define BCTR 0x4e800420 /* bctr */
80 /* The normal stub is this size. */
81 #define PLT_CALL_STUB_SIZE (7*4)
83 /* But sometimes the .plt entry crosses a 64k boundary, and we need
84 to adjust the high word with this insn. */
85 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
87 /* The .glink fixup call stub is the same as the .plt call stub, but
88 the first instruction restores r2, and the std is omitted. */
89 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
91 /* Always allow this much space. */
92 #define GLINK_CALL_STUB_SIZE (8*4)
95 #define NOP 0x60000000
97 /* Some other nops. */
98 #define CROR_151515 0x4def7b82
99 #define CROR_313131 0x4ffffb82
101 /* .glink entries for the first 32k functions are two instructions. */
102 #define LI_R0_0 0x38000000 /* li %r0,0 */
103 #define B_DOT 0x48000000 /* b . */
105 /* After that, we need two instructions to load the index, followed by
107 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
108 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
110 /* Instructions to save and restore floating point regs. */
111 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
112 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
113 #define BLR 0x4e800020 /* blr */
115 /* Since .opd is an array of descriptors and each entry will end up
116 with identical R_PPC64_RELATIVE relocs, there is really no need to
117 propagate .opd relocs; The dynamic linker should be taught to
118 relocate .opd without reloc entries. FIXME: .opd should be trimmed
120 #ifndef NO_OPD_RELOCS
121 #define NO_OPD_RELOCS 0
124 /* Relocation HOWTO's. */
125 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
127 static reloc_howto_type ppc64_elf_howto_raw
[] = {
128 /* This reloc does nothing. */
129 HOWTO (R_PPC64_NONE
, /* type */
131 2, /* size (0 = byte, 1 = short, 2 = long) */
133 false, /* pc_relative */
135 complain_overflow_bitfield
, /* complain_on_overflow */
136 bfd_elf_generic_reloc
, /* special_function */
137 "R_PPC64_NONE", /* name */
138 false, /* partial_inplace */
141 false), /* pcrel_offset */
143 /* A standard 32 bit relocation. */
144 HOWTO (R_PPC64_ADDR32
, /* type */
146 2, /* size (0 = byte, 1 = short, 2 = long) */
148 false, /* pc_relative */
150 complain_overflow_bitfield
, /* complain_on_overflow */
151 bfd_elf_generic_reloc
, /* special_function */
152 "R_PPC64_ADDR32", /* name */
153 false, /* partial_inplace */
155 0xffffffff, /* dst_mask */
156 false), /* pcrel_offset */
158 /* An absolute 26 bit branch; the lower two bits must be zero.
159 FIXME: we don't check that, we just clear them. */
160 HOWTO (R_PPC64_ADDR24
, /* type */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
164 false, /* pc_relative */
166 complain_overflow_bitfield
, /* complain_on_overflow */
167 bfd_elf_generic_reloc
, /* special_function */
168 "R_PPC64_ADDR24", /* name */
169 false, /* partial_inplace */
171 0x3fffffc, /* dst_mask */
172 false), /* pcrel_offset */
174 /* A standard 16 bit relocation. */
175 HOWTO (R_PPC64_ADDR16
, /* type */
177 1, /* size (0 = byte, 1 = short, 2 = long) */
179 false, /* pc_relative */
181 complain_overflow_bitfield
, /* complain_on_overflow */
182 bfd_elf_generic_reloc
, /* special_function */
183 "R_PPC64_ADDR16", /* name */
184 false, /* partial_inplace */
186 0xffff, /* dst_mask */
187 false), /* pcrel_offset */
189 /* A 16 bit relocation without overflow. */
190 HOWTO (R_PPC64_ADDR16_LO
, /* type */
192 1, /* size (0 = byte, 1 = short, 2 = long) */
194 false, /* pc_relative */
196 complain_overflow_dont
,/* complain_on_overflow */
197 bfd_elf_generic_reloc
, /* special_function */
198 "R_PPC64_ADDR16_LO", /* name */
199 false, /* partial_inplace */
201 0xffff, /* dst_mask */
202 false), /* pcrel_offset */
204 /* Bits 16-31 of an address. */
205 HOWTO (R_PPC64_ADDR16_HI
, /* type */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
209 false, /* pc_relative */
211 complain_overflow_dont
, /* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_PPC64_ADDR16_HI", /* name */
214 false, /* partial_inplace */
216 0xffff, /* dst_mask */
217 false), /* pcrel_offset */
219 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
220 bits, treated as a signed number, is negative. */
221 HOWTO (R_PPC64_ADDR16_HA
, /* type */
223 1, /* size (0 = byte, 1 = short, 2 = long) */
225 false, /* pc_relative */
227 complain_overflow_dont
, /* complain_on_overflow */
228 ppc64_elf_addr16_ha_reloc
, /* special_function */
229 "R_PPC64_ADDR16_HA", /* name */
230 false, /* partial_inplace */
232 0xffff, /* dst_mask */
233 false), /* pcrel_offset */
235 /* An absolute 16 bit branch; the lower two bits must be zero.
236 FIXME: we don't check that, we just clear them. */
237 HOWTO (R_PPC64_ADDR14
, /* type */
239 2, /* size (0 = byte, 1 = short, 2 = long) */
241 false, /* pc_relative */
243 complain_overflow_bitfield
, /* complain_on_overflow */
244 bfd_elf_generic_reloc
, /* special_function */
245 "R_PPC64_ADDR14", /* name */
246 false, /* partial_inplace */
248 0xfffc, /* dst_mask */
249 false), /* pcrel_offset */
251 /* An absolute 16 bit branch, for which bit 10 should be set to
252 indicate that the branch is expected to be taken. The lower two
253 bits must be zero. */
254 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
256 2, /* size (0 = byte, 1 = short, 2 = long) */
258 false, /* pc_relative */
260 complain_overflow_bitfield
, /* complain_on_overflow */
261 bfd_elf_generic_reloc
, /* special_function */
262 "R_PPC64_ADDR14_BRTAKEN",/* name */
263 false, /* partial_inplace */
265 0xfffc, /* dst_mask */
266 false), /* pcrel_offset */
268 /* An absolute 16 bit branch, for which bit 10 should be set to
269 indicate that the branch is not expected to be taken. The lower
270 two bits must be zero. */
271 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
273 2, /* size (0 = byte, 1 = short, 2 = long) */
275 false, /* pc_relative */
277 complain_overflow_bitfield
, /* complain_on_overflow */
278 bfd_elf_generic_reloc
, /* special_function */
279 "R_PPC64_ADDR14_BRNTAKEN",/* name */
280 false, /* partial_inplace */
282 0xfffc, /* dst_mask */
283 false), /* pcrel_offset */
285 /* A relative 26 bit branch; the lower two bits must be zero. */
286 HOWTO (R_PPC64_REL24
, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 true, /* pc_relative */
292 complain_overflow_signed
, /* complain_on_overflow */
293 bfd_elf_generic_reloc
, /* special_function */
294 "R_PPC64_REL24", /* name */
295 false, /* partial_inplace */
297 0x3fffffc, /* dst_mask */
298 true), /* pcrel_offset */
300 /* A relative 16 bit branch; the lower two bits must be zero. */
301 HOWTO (R_PPC64_REL14
, /* type */
303 2, /* size (0 = byte, 1 = short, 2 = long) */
305 true, /* pc_relative */
307 complain_overflow_signed
, /* complain_on_overflow */
308 bfd_elf_generic_reloc
, /* special_function */
309 "R_PPC64_REL14", /* name */
310 false, /* partial_inplace */
312 0xfffc, /* dst_mask */
313 true), /* pcrel_offset */
315 /* A relative 16 bit branch. Bit 10 should be set to indicate that
316 the branch is expected to be taken. The lower two bits must be
318 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 true, /* pc_relative */
324 complain_overflow_signed
, /* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_PPC64_REL14_BRTAKEN", /* name */
327 false, /* partial_inplace */
329 0xfffc, /* dst_mask */
330 true), /* pcrel_offset */
332 /* A relative 16 bit branch. Bit 10 should be set to indicate that
333 the branch is not expected to be taken. The lower two bits must
335 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
339 true, /* pc_relative */
341 complain_overflow_signed
, /* complain_on_overflow */
342 bfd_elf_generic_reloc
, /* special_function */
343 "R_PPC64_REL14_BRNTAKEN",/* name */
344 false, /* partial_inplace */
346 0xfffc, /* dst_mask */
347 true), /* pcrel_offset */
349 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
351 HOWTO (R_PPC64_GOT16
, /* type */
353 1, /* size (0 = byte, 1 = short, 2 = long) */
355 false, /* pc_relative */
357 complain_overflow_signed
, /* complain_on_overflow */
358 bfd_elf_generic_reloc
, /* special_function */
359 "R_PPC64_GOT16", /* name */
360 false, /* partial_inplace */
362 0xffff, /* dst_mask */
363 false), /* pcrel_offset */
365 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
367 HOWTO (R_PPC64_GOT16_LO
, /* type */
369 1, /* size (0 = byte, 1 = short, 2 = long) */
371 false, /* pc_relative */
373 complain_overflow_dont
, /* complain_on_overflow */
374 bfd_elf_generic_reloc
, /* special_function */
375 "R_PPC64_GOT16_LO", /* name */
376 false, /* partial_inplace */
378 0xffff, /* dst_mask */
379 false), /* pcrel_offset */
381 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
383 HOWTO (R_PPC64_GOT16_HI
, /* type */
385 1, /* size (0 = byte, 1 = short, 2 = long) */
387 false, /* pc_relative */
389 complain_overflow_dont
,/* complain_on_overflow */
390 bfd_elf_generic_reloc
, /* special_function */
391 "R_PPC64_GOT16_HI", /* name */
392 false, /* partial_inplace */
394 0xffff, /* dst_mask */
395 false), /* pcrel_offset */
397 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
399 HOWTO (R_PPC64_GOT16_HA
, /* type */
401 1, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_dont
,/* complain_on_overflow */
406 ppc64_elf_addr16_ha_reloc
, /* special_function */
407 "R_PPC64_GOT16_HA", /* name */
408 false, /* partial_inplace */
410 0xffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* This is used only by the dynamic linker. The symbol should exist
414 both in the object being run and in some shared library. The
415 dynamic linker copies the data addressed by the symbol from the
416 shared library into the object, because the object being
417 run has to have the data at some particular address. */
418 HOWTO (R_PPC64_COPY
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 false, /* pc_relative */
424 complain_overflow_bitfield
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_PPC64_COPY", /* name */
427 false, /* partial_inplace */
430 false), /* pcrel_offset */
432 /* Like R_PPC64_ADDR64, but used when setting global offset table
434 HOWTO (R_PPC64_GLOB_DAT
, /* type */
436 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
438 false, /* pc_relative */
440 complain_overflow_dont
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 "R_PPC64_GLOB_DAT", /* name */
443 false, /* partial_inplace */
445 0xffffffffffffffff, /* dst_mask */
446 false), /* pcrel_offset */
448 /* Created by the link editor. Marks a procedure linkage table
449 entry for a symbol. */
450 HOWTO (R_PPC64_JMP_SLOT
, /* type */
452 0, /* size (0 = byte, 1 = short, 2 = long) */
454 false, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_PPC64_JMP_SLOT", /* name */
459 false, /* partial_inplace */
462 false), /* pcrel_offset */
464 /* Used only by the dynamic linker. When the object is run, this
465 doubleword64 is set to the load address of the object, plus the
467 HOWTO (R_PPC64_RELATIVE
, /* type */
469 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
471 false, /* pc_relative */
473 complain_overflow_dont
, /* complain_on_overflow */
474 bfd_elf_generic_reloc
, /* special_function */
475 "R_PPC64_RELATIVE", /* name */
476 false, /* partial_inplace */
478 0xffffffffffffffff, /* dst_mask */
479 false), /* pcrel_offset */
481 /* Like R_PPC64_ADDR32, but may be unaligned. */
482 HOWTO (R_PPC64_UADDR32
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 false, /* pc_relative */
488 complain_overflow_bitfield
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_PPC64_UADDR32", /* name */
491 false, /* partial_inplace */
493 0xffffffff, /* dst_mask */
494 false), /* pcrel_offset */
496 /* Like R_PPC64_ADDR16, but may be unaligned. */
497 HOWTO (R_PPC64_UADDR16
, /* type */
499 1, /* size (0 = byte, 1 = short, 2 = long) */
501 false, /* pc_relative */
503 complain_overflow_bitfield
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_PPC64_UADDR16", /* name */
506 false, /* partial_inplace */
508 0xffff, /* dst_mask */
509 false), /* pcrel_offset */
511 /* 32-bit PC relative. */
512 HOWTO (R_PPC64_REL32
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 true, /* pc_relative */
518 /* FIXME: Verify. Was complain_overflow_bitfield. */
519 complain_overflow_signed
, /* complain_on_overflow */
520 bfd_elf_generic_reloc
, /* special_function */
521 "R_PPC64_REL32", /* name */
522 false, /* partial_inplace */
524 0xffffffff, /* dst_mask */
525 true), /* pcrel_offset */
527 /* 32-bit relocation to the symbol's procedure linkage table. */
528 HOWTO (R_PPC64_PLT32
, /* type */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
532 false, /* pc_relative */
534 complain_overflow_bitfield
, /* complain_on_overflow */
535 bfd_elf_generic_reloc
, /* special_function */
536 "R_PPC64_PLT32", /* name */
537 false, /* partial_inplace */
540 false), /* pcrel_offset */
542 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
543 FIXME: R_PPC64_PLTREL32 not supported. */
544 HOWTO (R_PPC64_PLTREL32
, /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 true, /* pc_relative */
550 complain_overflow_signed
, /* complain_on_overflow */
551 bfd_elf_generic_reloc
, /* special_function */
552 "R_PPC64_PLTREL32", /* name */
553 false, /* partial_inplace */
556 true), /* pcrel_offset */
558 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
560 HOWTO (R_PPC64_PLT16_LO
, /* type */
562 1, /* size (0 = byte, 1 = short, 2 = long) */
564 false, /* pc_relative */
566 complain_overflow_dont
, /* complain_on_overflow */
567 bfd_elf_generic_reloc
, /* special_function */
568 "R_PPC64_PLT16_LO", /* name */
569 false, /* partial_inplace */
571 0xffff, /* dst_mask */
572 false), /* pcrel_offset */
574 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
576 HOWTO (R_PPC64_PLT16_HI
, /* type */
578 1, /* size (0 = byte, 1 = short, 2 = long) */
580 false, /* pc_relative */
582 complain_overflow_dont
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 "R_PPC64_PLT16_HI", /* name */
585 false, /* partial_inplace */
587 0xffff, /* dst_mask */
588 false), /* pcrel_offset */
590 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
592 HOWTO (R_PPC64_PLT16_HA
, /* type */
594 1, /* size (0 = byte, 1 = short, 2 = long) */
596 false, /* pc_relative */
598 complain_overflow_dont
, /* complain_on_overflow */
599 ppc64_elf_addr16_ha_reloc
, /* special_function */
600 "R_PPC64_PLT16_HA", /* name */
601 false, /* partial_inplace */
603 0xffff, /* dst_mask */
604 false), /* pcrel_offset */
606 /* 32-bit section relative relocation. */
607 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
609 HOWTO (R_PPC64_SECTOFF
, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 true, /* pc_relative */
615 complain_overflow_bitfield
, /* complain_on_overflow */
616 bfd_elf_generic_reloc
, /* special_function */
617 "R_PPC64_SECTOFF", /* name */
618 false, /* partial_inplace */
621 true), /* pcrel_offset */
623 /* 16-bit lower half section relative relocation. */
624 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
626 1, /* size (0 = byte, 1 = short, 2 = long) */
628 false, /* pc_relative */
630 complain_overflow_dont
, /* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 "R_PPC64_SECTOFF_LO", /* name */
633 false, /* partial_inplace */
635 0xffff, /* dst_mask */
636 false), /* pcrel_offset */
638 /* 16-bit upper half section relative relocation. */
639 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
641 1, /* size (0 = byte, 1 = short, 2 = long) */
643 false, /* pc_relative */
645 complain_overflow_dont
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 "R_PPC64_SECTOFF_HI", /* name */
648 false, /* partial_inplace */
650 0xffff, /* dst_mask */
651 false), /* pcrel_offset */
653 /* 16-bit upper half adjusted section relative relocation. */
654 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
656 1, /* size (0 = byte, 1 = short, 2 = long) */
658 false, /* pc_relative */
660 complain_overflow_dont
, /* complain_on_overflow */
661 ppc64_elf_addr16_ha_reloc
, /* special_function */
662 "R_PPC64_SECTOFF_HA", /* name */
663 false, /* partial_inplace */
665 0xffff, /* dst_mask */
666 false), /* pcrel_offset */
668 /* Like R_PPC64_REL24 without touching the two least significant
670 /* FIXME: Verify R_PPC64_ADDR30. */
671 HOWTO (R_PPC64_ADDR30
, /* 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_ADDR30", /* 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 0xffffffffffffffff, /* 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_addr16_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_addr16_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 0xffffffffffffffff, /* 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 0xffffffffffffffff, /* 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 bfd_elf_generic_reloc
, /* special_function */
803 "R_PPC64_PLT64", /* name */
804 false, /* partial_inplace */
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 bfd_elf_generic_reloc
, /* special_function */
820 "R_PPC64_PLTREL64", /* name */
821 false, /* partial_inplace */
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 bfd_elf_generic_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 bfd_elf_generic_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 bfd_elf_generic_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_addr16_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 bfd_elf_generic_reloc
, /* special_function */
907 "R_PPC64_TOC", /* name */
908 false, /* partial_inplace */
910 0xffffffffffffffff, /* 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 bfd_elf_generic_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 bfd_elf_generic_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 bfd_elf_generic_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_addr16_ha_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 bfd_elf_generic_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 bfd_elf_generic_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 bfd_elf_generic_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 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
1064 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1066 2, /* size (0 = byte, 1 = short, 2 = long) */
1068 true, /* pc_relative */
1070 complain_overflow_bitfield
, /* complain_on_overflow */
1071 bfd_elf_generic_reloc
, /* special_function */
1072 "R_PPC64_SECTOFF_DS", /* name */
1073 false, /* partial_inplace */
1076 true), /* pcrel_offset */
1078 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1079 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1081 1, /* size (0 = byte, 1 = short, 2 = long) */
1083 false, /* pc_relative */
1085 complain_overflow_dont
, /* complain_on_overflow */
1086 bfd_elf_generic_reloc
, /* special_function */
1087 "R_PPC64_SECTOFF_LO_DS",/* name */
1088 false, /* partial_inplace */
1090 0xfffc, /* dst_mask */
1091 false), /* pcrel_offset */
1093 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1094 HOWTO (R_PPC64_TOC16_DS
, /* type */
1096 1, /* size (0 = byte, 1 = short, 2 = long) */
1098 false, /* pc_relative */
1100 complain_overflow_signed
, /* complain_on_overflow */
1101 bfd_elf_generic_reloc
, /* special_function */
1102 "R_PPC64_TOC16_DS", /* name */
1103 false, /* partial_inplace */
1105 0xfffc, /* dst_mask */
1106 false), /* pcrel_offset */
1108 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1109 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1111 1, /* size (0 = byte, 1 = short, 2 = long) */
1113 false, /* pc_relative */
1115 complain_overflow_dont
, /* complain_on_overflow */
1116 bfd_elf_generic_reloc
, /* special_function */
1117 "R_PPC64_TOC16_LO_DS", /* name */
1118 false, /* partial_inplace */
1120 0xfffc, /* dst_mask */
1121 false), /* pcrel_offset */
1123 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1124 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1125 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1127 1, /* size (0 = byte, 1 = short, 2 = long) */
1129 false, /* pc_relative */
1131 complain_overflow_signed
, /* complain_on_overflow */
1132 bfd_elf_generic_reloc
, /* special_function */
1133 "R_PPC64_PLTGOT16_DS", /* name */
1134 false, /* partial_inplace */
1136 0xfffc, /* dst_mask */
1137 false), /* pcrel_offset */
1139 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1140 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1141 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1143 1, /* size (0 = byte, 1 = short, 2 = long) */
1145 false, /* pc_relative */
1147 complain_overflow_dont
, /* complain_on_overflow */
1148 bfd_elf_generic_reloc
, /* special_function */
1149 "R_PPC64_PLTGOT16_LO_DS",/* name */
1150 false, /* partial_inplace */
1152 0xfffc, /* dst_mask */
1153 false), /* pcrel_offset */
1155 /* GNU extension to record C++ vtable hierarchy. */
1156 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1158 0, /* size (0 = byte, 1 = short, 2 = long) */
1160 false, /* pc_relative */
1162 complain_overflow_dont
, /* complain_on_overflow */
1163 NULL
, /* special_function */
1164 "R_PPC64_GNU_VTINHERIT", /* name */
1165 false, /* partial_inplace */
1168 false), /* pcrel_offset */
1170 /* GNU extension to record C++ vtable member usage. */
1171 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1173 0, /* size (0 = byte, 1 = short, 2 = long) */
1175 false, /* pc_relative */
1177 complain_overflow_dont
, /* complain_on_overflow */
1178 NULL
, /* special_function */
1179 "R_PPC64_GNU_VTENTRY", /* name */
1180 false, /* partial_inplace */
1183 false), /* pcrel_offset */
1187 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1193 unsigned int i
, type
;
1196 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1199 type
= ppc64_elf_howto_raw
[i
].type
;
1200 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1201 / sizeof (ppc64_elf_howto_table
[0])));
1202 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1206 static reloc_howto_type
*
1207 ppc64_elf_reloc_type_lookup (abfd
, code
)
1208 bfd
*abfd ATTRIBUTE_UNUSED
;
1209 bfd_reloc_code_real_type code
;
1211 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1213 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1214 /* Initialize howto table if needed. */
1220 return (reloc_howto_type
*) NULL
;
1222 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1224 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1226 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1228 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1230 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1232 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1234 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1236 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1238 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1240 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1242 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1244 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1246 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1248 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1250 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1252 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1254 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1256 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1258 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1260 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1262 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1264 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1266 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1268 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1270 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1272 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1274 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1276 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1278 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1280 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1282 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR64
;
1284 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1286 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1288 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1290 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1292 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1294 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1296 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1298 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1300 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1302 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1304 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1306 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1308 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1310 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1312 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1314 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1316 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1318 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1320 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1322 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1324 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1326 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1328 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1330 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1332 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1334 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1336 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1338 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1340 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1342 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1346 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1349 /* Set the howto pointer for a PowerPC ELF reloc. */
1352 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1353 bfd
*abfd ATTRIBUTE_UNUSED
;
1355 Elf64_Internal_Rela
*dst
;
1359 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1360 /* Initialize howto table if needed. */
1363 type
= ELF64_R_TYPE (dst
->r_info
);
1364 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1365 / sizeof (ppc64_elf_howto_table
[0])));
1366 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1369 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1371 static bfd_reloc_status_type
1372 ppc64_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1373 output_bfd
, error_message
)
1374 bfd
*abfd ATTRIBUTE_UNUSED
;
1375 arelent
*reloc_entry
;
1377 PTR data ATTRIBUTE_UNUSED
;
1378 asection
*input_section
;
1380 char **error_message ATTRIBUTE_UNUSED
;
1384 if (output_bfd
!= NULL
)
1386 reloc_entry
->address
+= input_section
->output_offset
;
1387 return bfd_reloc_ok
;
1390 if (reloc_entry
->address
> input_section
->_cooked_size
)
1391 return bfd_reloc_outofrange
;
1393 if (bfd_is_com_section (symbol
->section
))
1396 relocation
= symbol
->value
;
1398 relocation
+= symbol
->section
->output_section
->vma
;
1399 relocation
+= symbol
->section
->output_offset
;
1400 relocation
+= reloc_entry
->addend
;
1402 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1404 return bfd_reloc_continue
;
1407 /* Function to set whether a module needs the -mrelocatable bit set. */
1410 ppc64_elf_set_private_flags (abfd
, flags
)
1414 BFD_ASSERT (!elf_flags_init (abfd
)
1415 || elf_elfheader (abfd
)->e_flags
== flags
);
1417 elf_elfheader (abfd
)->e_flags
= flags
;
1418 elf_flags_init (abfd
) = true;
1422 /* Merge backend specific data from an object file to the output
1423 object file when linking. */
1425 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1433 /* Check if we have the same endianess. */
1434 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1435 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1439 if (bfd_big_endian (ibfd
))
1440 msg
= _("%s: compiled for a big endian system and target is little endian");
1442 msg
= _("%s: compiled for a little endian system and target is big endian");
1444 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1446 bfd_set_error (bfd_error_wrong_format
);
1450 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1451 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1454 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1455 old_flags
= elf_elfheader (obfd
)->e_flags
;
1456 if (!elf_flags_init (obfd
))
1458 /* First call, no flags set. */
1459 elf_flags_init (obfd
) = true;
1460 elf_elfheader (obfd
)->e_flags
= new_flags
;
1463 else if (new_flags
== old_flags
)
1464 /* Compatible flags are ok. */
1469 /* Incompatible flags. Warn about -mrelocatable mismatch.
1470 Allow -mrelocatable-lib to be linked with either. */
1472 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1473 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1476 (*_bfd_error_handler
)
1477 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1478 bfd_archive_filename (ibfd
));
1480 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1481 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1484 (*_bfd_error_handler
)
1485 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1486 bfd_archive_filename (ibfd
));
1489 /* The output is -mrelocatable-lib iff both the input files are. */
1490 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1491 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1493 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1494 but each input file is either -mrelocatable or -mrelocatable-lib. */
1495 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1496 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1497 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1498 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1500 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1501 if any module uses it. */
1502 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1504 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1505 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1507 /* Warn about any other mismatches. */
1508 if (new_flags
!= old_flags
)
1511 (*_bfd_error_handler
)
1512 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1513 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1518 bfd_set_error (bfd_error_bad_value
);
1526 /* Handle a PowerPC specific section when reading an object file. This
1527 is called when elfcode.h finds a section with an unknown type. */
1530 ppc64_elf_section_from_shdr (abfd
, hdr
, name
)
1532 Elf64_Internal_Shdr
*hdr
;
1538 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1541 newsect
= hdr
->bfd_section
;
1542 flags
= bfd_get_section_flags (abfd
, newsect
);
1543 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1544 flags
|= SEC_EXCLUDE
;
1546 if (hdr
->sh_type
== SHT_ORDERED
)
1547 flags
|= SEC_SORT_ENTRIES
;
1549 bfd_set_section_flags (abfd
, newsect
, flags
);
1553 /* The following functions are specific to the ELF linker, while
1554 functions above are used generally. Those named ppc64_elf_* are
1555 called by the main ELF linker code. They appear in this file more
1556 or less in the order in which they are called. eg.
1557 ppc64_elf_check_relocs is called early in the link process,
1558 ppc64_elf_finish_dynamic_sections is one of the last functions
1561 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1562 functions have both a function code symbol and a function descriptor
1563 symbol. A call to foo in a relocatable object file looks like:
1570 The function definition in another object file might be:
1574 . .quad .TOC.@tocbase
1580 When the linker resolves the call during a static link, the branch
1581 unsurprisingly just goes to .foo and the .opd information is unused.
1582 If the function definition is in a shared library, things are a little
1583 different: The call goes via a plt call stub, the opd information gets
1584 copied to the plt, and the linker patches the nop.
1592 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1593 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1594 . std 2,40(1) # this is the general idea
1602 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1604 The "reloc ()" notation is supposed to indicate that the linker emits
1605 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1608 What are the difficulties here? Well, firstly, the relocations
1609 examined by the linker in check_relocs are against the function code
1610 sym .foo, while the dynamic relocation in the plt is emitted against
1611 the function descriptor symbol, foo. Somewhere along the line, we need
1612 to carefully copy dynamic link information from one symbol to the other.
1613 Secondly, the generic part of the elf linker will make .foo a dynamic
1614 symbol as is normal for most other backends. We need foo dynamic
1615 instead, at least for an application final link. However, when
1616 creating a shared library containing foo, we need to have both symbols
1617 dynamic so that references to .foo are satisfied during the early
1618 stages of linking. Otherwise the linker might decide to pull in a
1619 definition from some other object, eg. a static library. */
1621 /* The linker needs to keep track of the number of relocs that it
1622 decides to copy as dynamic relocs in check_relocs for each symbol.
1623 This is so that it can later discard them if they are found to be
1624 unnecessary. We store the information in a field extending the
1625 regular ELF linker hash table. */
1627 struct ppc_dyn_relocs
1629 struct ppc_dyn_relocs
*next
;
1631 /* The input section of the reloc. */
1634 /* Total number of relocs copied for the input section. */
1635 bfd_size_type count
;
1637 /* Number of pc-relative relocs copied for the input section. */
1638 bfd_size_type pc_count
;
1641 /* Of those relocs that might be copied as dynamic relocs, this macro
1642 selects between relative and absolute types. */
1644 #define IS_ABSOLUTE_RELOC(RTYPE) \
1645 ((RTYPE) != R_PPC64_REL14 \
1646 && (RTYPE) != R_PPC64_REL14_BRNTAKEN \
1647 && (RTYPE) != R_PPC64_REL14_BRTAKEN \
1648 && (RTYPE) != R_PPC64_REL24 \
1649 && (RTYPE) != R_PPC64_REL32 \
1650 && (RTYPE) != R_PPC64_REL64)
1652 /* Section name for stubs is the associated section name plus this
1654 #define STUB_SUFFIX ".stub"
1657 ppc_stub_long_branch:
1658 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1659 destination, but a 24 bit branch in a stub section will reach.
1662 ppc_stub_plt_branch:
1663 Similar to the above, but a 24 bit branch in the stub section won't
1664 reach its destination.
1665 . addis %r12,%r2,xxx@ha
1666 . ld %r11,xxx@l(%r12)
1671 Used to call a function in a shared library.
1672 . addis %r12,%r2,xxx@ha
1674 . ld %r11,xxx+0@l(%r12)
1675 . ld %r2,xxx+8@l(%r12)
1677 . ld %r11,xxx+16@l(%r12)
1681 enum ppc_stub_type
{
1683 ppc_stub_long_branch
,
1684 ppc_stub_plt_branch
,
1688 struct ppc_stub_hash_entry
{
1690 /* Base hash table entry structure. */
1691 struct bfd_hash_entry root
;
1693 /* The stub section. */
1696 /* Offset within stub_sec of the beginning of this stub. */
1697 bfd_vma stub_offset
;
1699 /* Given the symbol's value and its section we can determine its final
1700 value when building the stubs (so the stub knows where to jump. */
1701 bfd_vma target_value
;
1702 asection
*target_section
;
1704 enum ppc_stub_type stub_type
;
1706 /* The symbol table entry, if any, that this was derived from. */
1707 struct ppc_link_hash_entry
*h
;
1709 /* Where this stub is being called from, or, in the case of combined
1710 stub sections, the first input section in the group. */
1714 struct ppc_branch_hash_entry
{
1716 /* Base hash table entry structure. */
1717 struct bfd_hash_entry root
;
1719 /* Offset within .branch_lt. */
1720 unsigned int offset
;
1722 /* Generation marker. */
1726 struct ppc_link_hash_entry
1728 struct elf_link_hash_entry elf
;
1730 /* A pointer to the most recently used stub hash entry against this
1732 struct ppc_stub_hash_entry
*stub_cache
;
1734 /* Track dynamic relocs copied for this symbol. */
1735 struct ppc_dyn_relocs
*dyn_relocs
;
1737 /* Link between function code and descriptor symbols. */
1738 struct elf_link_hash_entry
*oh
;
1740 /* Flag function code and descriptor symbols. */
1741 unsigned int is_func
:1;
1742 unsigned int is_func_descriptor
:1;
1745 /* ppc64 ELF linker hash table. */
1747 struct ppc_link_hash_table
1749 struct elf_link_hash_table elf
;
1751 /* The stub hash table. */
1752 struct bfd_hash_table stub_hash_table
;
1754 /* Another hash table for plt_branch stubs. */
1755 struct bfd_hash_table branch_hash_table
;
1757 /* Linker stub bfd. */
1760 /* Linker call-backs. */
1761 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
1762 void (*layout_sections_again
) PARAMS ((void));
1764 /* Array to keep track of which stub sections have been created, and
1765 information on stub grouping. */
1767 /* This is the section to which stubs in the group will be attached. */
1769 /* The stub section. */
1773 /* Assorted information used by ppc64_elf_size_stubs. */
1774 unsigned int bfd_count
;
1776 asection
**input_list
;
1777 Elf_Internal_Sym
**all_local_syms
;
1779 /* Short-cuts to get to dynamic linker sections. */
1792 unsigned int stub_error
;
1794 /* Flag set when small branches are detected. Used to
1795 select suitable defaults for the stub group size. */
1796 unsigned int has_14bit_branch
;
1798 /* Incremented every time we size stubs. */
1799 unsigned int stub_iteration
;
1801 /* Small local sym to section mapping cache. */
1802 struct sym_sec_cache sym_sec
;
1805 static struct bfd_hash_entry
*stub_hash_newfunc
1806 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1807 static struct bfd_hash_entry
*branch_hash_newfunc
1808 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1809 static struct bfd_hash_entry
*link_hash_newfunc
1810 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1811 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
1813 static void ppc64_elf_link_hash_table_free
1814 PARAMS ((struct bfd_link_hash_table
*));
1815 static char *ppc_stub_name
1816 PARAMS ((const asection
*, const asection
*,
1817 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
1818 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
1819 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
1820 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
1821 static struct ppc_stub_hash_entry
*ppc_add_stub
1822 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
1823 static boolean create_linkage_sections
1824 PARAMS ((bfd
*, struct bfd_link_info
*));
1825 static boolean create_got_section
1826 PARAMS ((bfd
*, struct bfd_link_info
*));
1827 static boolean ppc64_elf_create_dynamic_sections
1828 PARAMS ((bfd
*, struct bfd_link_info
*));
1829 static void ppc64_elf_copy_indirect_symbol
1830 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
1831 static boolean ppc64_elf_check_relocs
1832 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1833 const Elf_Internal_Rela
*));
1834 static asection
* ppc64_elf_gc_mark_hook
1835 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, Elf_Internal_Rela
*rel
,
1836 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
1837 static boolean ppc64_elf_gc_sweep_hook
1838 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
1839 const Elf_Internal_Rela
*relocs
));
1840 static boolean func_desc_adjust
1841 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1842 static boolean ppc64_elf_func_desc_adjust
1843 PARAMS ((bfd
*, struct bfd_link_info
*));
1844 static boolean ppc64_elf_adjust_dynamic_symbol
1845 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
1846 static void ppc64_elf_hide_symbol
1847 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, boolean
));
1848 static boolean allocate_dynrelocs
1849 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1850 static boolean readonly_dynrelocs
1851 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1852 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
1853 PARAMS ((const Elf_Internal_Rela
*));
1854 static boolean ppc64_elf_size_dynamic_sections
1855 PARAMS ((bfd
*, struct bfd_link_info
*));
1856 static INLINE
enum ppc_stub_type ppc_type_of_stub
1857 PARAMS ((asection
*, const Elf_Internal_Rela
*,
1858 struct ppc_link_hash_entry
**, bfd_vma
));
1859 static bfd_byte
*build_plt_stub
1860 PARAMS ((bfd
*, bfd_byte
*, int, int));
1861 static boolean ppc_build_one_stub
1862 PARAMS ((struct bfd_hash_entry
*, PTR
));
1863 static boolean ppc_size_one_stub
1864 PARAMS ((struct bfd_hash_entry
*, PTR
));
1865 static void group_sections
1866 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, boolean
));
1867 static boolean get_local_syms
1868 PARAMS ((bfd
*, struct ppc_link_hash_table
*));
1869 static boolean ppc64_elf_fake_sections
1870 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*));
1871 static boolean ppc64_elf_relocate_section
1872 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
1873 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
1875 static boolean ppc64_elf_finish_dynamic_symbol
1876 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
1877 Elf_Internal_Sym
*));
1878 static boolean ppc64_elf_finish_dynamic_sections
1879 PARAMS ((bfd
*, struct bfd_link_info
*));
1881 /* Get the ppc64 ELF linker hash table from a link_info structure. */
1883 #define ppc_hash_table(p) \
1884 ((struct ppc_link_hash_table *) ((p)->hash))
1886 #define ppc_stub_hash_lookup(table, string, create, copy) \
1887 ((struct ppc_stub_hash_entry *) \
1888 bfd_hash_lookup ((table), (string), (create), (copy)))
1890 #define ppc_branch_hash_lookup(table, string, create, copy) \
1891 ((struct ppc_branch_hash_entry *) \
1892 bfd_hash_lookup ((table), (string), (create), (copy)))
1894 /* Create an entry in the stub hash table. */
1896 static struct bfd_hash_entry
*
1897 stub_hash_newfunc (entry
, table
, string
)
1898 struct bfd_hash_entry
*entry
;
1899 struct bfd_hash_table
*table
;
1902 /* Allocate the structure if it has not already been allocated by a
1906 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
1911 /* Call the allocation method of the superclass. */
1912 entry
= bfd_hash_newfunc (entry
, table
, string
);
1915 struct ppc_stub_hash_entry
*eh
;
1917 /* Initialize the local fields. */
1918 eh
= (struct ppc_stub_hash_entry
*) entry
;
1919 eh
->stub_sec
= NULL
;
1920 eh
->stub_offset
= 0;
1921 eh
->target_value
= 0;
1922 eh
->target_section
= NULL
;
1923 eh
->stub_type
= ppc_stub_none
;
1931 /* Create an entry in the branch hash table. */
1933 static struct bfd_hash_entry
*
1934 branch_hash_newfunc (entry
, table
, string
)
1935 struct bfd_hash_entry
*entry
;
1936 struct bfd_hash_table
*table
;
1939 /* Allocate the structure if it has not already been allocated by a
1943 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
1948 /* Call the allocation method of the superclass. */
1949 entry
= bfd_hash_newfunc (entry
, table
, string
);
1952 struct ppc_branch_hash_entry
*eh
;
1954 /* Initialize the local fields. */
1955 eh
= (struct ppc_branch_hash_entry
*) entry
;
1963 /* Create an entry in a ppc64 ELF linker hash table. */
1965 static struct bfd_hash_entry
*
1966 link_hash_newfunc (entry
, table
, string
)
1967 struct bfd_hash_entry
*entry
;
1968 struct bfd_hash_table
*table
;
1971 /* Allocate the structure if it has not already been allocated by a
1975 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
1980 /* Call the allocation method of the superclass. */
1981 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1984 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
1986 eh
->stub_cache
= NULL
;
1987 eh
->dyn_relocs
= NULL
;
1990 eh
->is_func_descriptor
= 0;
1996 /* Create a ppc64 ELF linker hash table. */
1998 static struct bfd_link_hash_table
*
1999 ppc64_elf_link_hash_table_create (abfd
)
2002 struct ppc_link_hash_table
*htab
;
2003 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2005 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2009 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2015 /* Init the stub hash table too. */
2016 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2019 /* And the branch hash table. */
2020 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2023 htab
->stub_bfd
= NULL
;
2024 htab
->add_stub_section
= NULL
;
2025 htab
->layout_sections_again
= NULL
;
2026 htab
->stub_group
= NULL
;
2028 htab
->srelgot
= NULL
;
2030 htab
->srelplt
= NULL
;
2031 htab
->sdynbss
= NULL
;
2032 htab
->srelbss
= NULL
;
2033 htab
->sglink
= NULL
;
2036 htab
->srelbrlt
= NULL
;
2037 htab
->stub_error
= 0;
2038 htab
->has_14bit_branch
= 0;
2039 htab
->stub_iteration
= 0;
2040 htab
->sym_sec
.abfd
= NULL
;
2042 return &htab
->elf
.root
;
2045 /* Free the derived linker hash table. */
2048 ppc64_elf_link_hash_table_free (hash
)
2049 struct bfd_link_hash_table
*hash
;
2051 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2053 bfd_hash_table_free (&ret
->stub_hash_table
);
2054 bfd_hash_table_free (&ret
->branch_hash_table
);
2055 _bfd_generic_link_hash_table_free (hash
);
2058 /* Build a name for an entry in the stub hash table. */
2061 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2062 const asection
*input_section
;
2063 const asection
*sym_sec
;
2064 const struct ppc_link_hash_entry
*h
;
2065 const Elf_Internal_Rela
*rel
;
2070 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2071 offsets from a sym as a branch target? In fact, we could
2072 probably assume the addend is always zero. */
2073 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2077 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2078 stub_name
= bfd_malloc (len
);
2079 if (stub_name
!= NULL
)
2081 sprintf (stub_name
, "%08x_%s+%x",
2082 input_section
->id
& 0xffffffff,
2083 h
->elf
.root
.root
.string
,
2084 (int) rel
->r_addend
& 0xffffffff);
2089 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2090 stub_name
= bfd_malloc (len
);
2091 if (stub_name
!= NULL
)
2093 sprintf (stub_name
, "%08x_%x:%x+%x",
2094 input_section
->id
& 0xffffffff,
2095 sym_sec
->id
& 0xffffffff,
2096 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2097 (int) rel
->r_addend
& 0xffffffff);
2103 /* Look up an entry in the stub hash. Stub entries are cached because
2104 creating the stub name takes a bit of time. */
2106 static struct ppc_stub_hash_entry
*
2107 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2108 const asection
*input_section
;
2109 const asection
*sym_sec
;
2110 struct elf_link_hash_entry
*hash
;
2111 const Elf_Internal_Rela
*rel
;
2112 struct ppc_link_hash_table
*htab
;
2114 struct ppc_stub_hash_entry
*stub_entry
;
2115 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2116 const asection
*id_sec
;
2118 /* If this input section is part of a group of sections sharing one
2119 stub section, then use the id of the first section in the group.
2120 Stub names need to include a section id, as there may well be
2121 more than one stub used to reach say, printf, and we need to
2122 distinguish between them. */
2123 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2125 if (h
!= NULL
&& h
->stub_cache
!= NULL
2126 && h
->stub_cache
->h
== h
2127 && h
->stub_cache
->id_sec
== id_sec
)
2129 stub_entry
= h
->stub_cache
;
2135 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2136 if (stub_name
== NULL
)
2139 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2140 stub_name
, false, false);
2142 h
->stub_cache
= stub_entry
;
2150 /* Add a new stub entry to the stub hash. Not all fields of the new
2151 stub entry are initialised. */
2153 static struct ppc_stub_hash_entry
*
2154 ppc_add_stub (stub_name
, section
, htab
)
2155 const char *stub_name
;
2157 struct ppc_link_hash_table
*htab
;
2161 struct ppc_stub_hash_entry
*stub_entry
;
2163 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2164 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2165 if (stub_sec
== NULL
)
2167 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2168 if (stub_sec
== NULL
)
2173 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
2174 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2178 strcpy (s_name
, link_sec
->name
);
2179 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
2180 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2181 if (stub_sec
== NULL
)
2183 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2185 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2188 /* Enter this entry into the linker stub hash table. */
2189 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2191 if (stub_entry
== NULL
)
2193 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2194 bfd_archive_filename (section
->owner
),
2199 stub_entry
->stub_sec
= stub_sec
;
2200 stub_entry
->stub_offset
= 0;
2201 stub_entry
->id_sec
= link_sec
;
2205 /* Create sections for linker generated code. */
2208 create_linkage_sections (dynobj
, info
)
2210 struct bfd_link_info
*info
;
2212 struct ppc_link_hash_table
*htab
;
2215 htab
= ppc_hash_table (info
);
2217 /* Create .sfpr for code to save and restore fp regs. */
2218 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2219 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2220 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2221 if (htab
->sfpr
== NULL
2222 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2223 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2226 /* Create .glink for lazy dynamic linking support. */
2227 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2228 if (htab
->sglink
== NULL
2229 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2230 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2233 /* Create .branch_lt for plt_branch stubs. */
2234 flags
= (SEC_ALLOC
| SEC_LOAD
2235 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2236 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2237 if (htab
->sbrlt
== NULL
2238 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2239 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2244 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2245 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2246 htab
->srelbrlt
= bfd_make_section (dynobj
, ".rela.branch_lt");
2248 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2249 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2255 /* Create .got and .rela.got sections in DYNOBJ, and set up
2256 shortcuts to them in our hash table. */
2259 create_got_section (dynobj
, info
)
2261 struct bfd_link_info
*info
;
2263 struct ppc_link_hash_table
*htab
;
2265 if (! _bfd_elf_create_got_section (dynobj
, info
))
2268 htab
= ppc_hash_table (info
);
2269 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2273 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2275 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2276 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2277 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2279 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2284 /* Create the dynamic sections, and set up shortcuts. */
2287 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2289 struct bfd_link_info
*info
;
2291 struct ppc_link_hash_table
*htab
;
2293 htab
= ppc_hash_table (info
);
2294 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2297 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2300 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2301 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2302 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2304 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2306 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2307 || (!info
->shared
&& !htab
->srelbss
))
2313 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2316 ppc64_elf_copy_indirect_symbol (dir
, ind
)
2317 struct elf_link_hash_entry
*dir
, *ind
;
2319 struct ppc_link_hash_entry
*edir
, *eind
;
2321 edir
= (struct ppc_link_hash_entry
*) dir
;
2322 eind
= (struct ppc_link_hash_entry
*) ind
;
2324 if (eind
->dyn_relocs
!= NULL
)
2326 if (edir
->dyn_relocs
!= NULL
)
2328 struct ppc_dyn_relocs
**pp
;
2329 struct ppc_dyn_relocs
*p
;
2331 if (ind
->root
.type
== bfd_link_hash_indirect
)
2334 /* Add reloc counts against the weak sym to the strong sym
2335 list. Merge any entries against the same section. */
2336 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2338 struct ppc_dyn_relocs
*q
;
2340 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2341 if (q
->sec
== p
->sec
)
2343 q
->pc_count
+= p
->pc_count
;
2344 q
->count
+= p
->count
;
2351 *pp
= edir
->dyn_relocs
;
2354 edir
->dyn_relocs
= eind
->dyn_relocs
;
2355 eind
->dyn_relocs
= NULL
;
2358 edir
->is_func
|= eind
->is_func
;
2359 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2361 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
2364 /* Look through the relocs for a section during the first phase, and
2365 calculate needed space in the global offset table, procedure
2366 linkage table, and dynamic reloc sections. */
2369 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2371 struct bfd_link_info
*info
;
2373 const Elf_Internal_Rela
*relocs
;
2375 struct ppc_link_hash_table
*htab
;
2376 Elf_Internal_Shdr
*symtab_hdr
;
2377 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2378 const Elf_Internal_Rela
*rel
;
2379 const Elf_Internal_Rela
*rel_end
;
2383 if (info
->relocateable
)
2386 htab
= ppc_hash_table (info
);
2387 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2389 sym_hashes
= elf_sym_hashes (abfd
);
2390 sym_hashes_end
= (sym_hashes
2391 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
));
2392 if (!elf_bad_symtab (abfd
))
2393 sym_hashes_end
-= symtab_hdr
->sh_info
;
2396 is_opd
= strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0;
2398 if (htab
->elf
.dynobj
== NULL
)
2399 htab
->elf
.dynobj
= abfd
;
2400 if (htab
->sfpr
== NULL
2401 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2404 rel_end
= relocs
+ sec
->reloc_count
;
2405 for (rel
= relocs
; rel
< rel_end
; rel
++)
2407 unsigned long r_symndx
;
2408 struct elf_link_hash_entry
*h
;
2409 enum elf_ppc_reloc_type r_type
;
2411 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2412 if (r_symndx
< symtab_hdr
->sh_info
)
2415 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2417 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2420 /* GOT16 relocations */
2422 case R_PPC64_GOT16_DS
:
2423 case R_PPC64_GOT16_HA
:
2424 case R_PPC64_GOT16_HI
:
2425 case R_PPC64_GOT16_LO
:
2426 case R_PPC64_GOT16_LO_DS
:
2428 /* This symbol requires a global offset table entry. */
2429 if (htab
->sgot
== NULL
2430 && !create_got_section (htab
->elf
.dynobj
, info
))
2435 h
->got
.refcount
+= 1;
2439 bfd_signed_vma
*local_got_refcounts
;
2441 /* This is a global offset table entry for a local symbol. */
2442 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2443 if (local_got_refcounts
== NULL
)
2447 size
= symtab_hdr
->sh_info
;
2448 size
*= sizeof (bfd_signed_vma
);
2449 local_got_refcounts
= ((bfd_signed_vma
*)
2450 bfd_zalloc (abfd
, size
));
2451 if (local_got_refcounts
== NULL
)
2453 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2455 local_got_refcounts
[r_symndx
] += 1;
2459 case R_PPC64_PLT16_HA
:
2460 case R_PPC64_PLT16_HI
:
2461 case R_PPC64_PLT16_LO
:
2464 /* This symbol requires a procedure linkage table entry. We
2465 actually build the entry in adjust_dynamic_symbol,
2466 because this might be a case of linking PIC code without
2467 linking in any dynamic objects, in which case we don't
2468 need to generate a procedure linkage table after all. */
2471 /* It does not make sense to have a procedure linkage
2472 table entry for a local symbol. */
2473 bfd_set_error (bfd_error_bad_value
);
2477 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2478 h
->plt
.refcount
+= 1;
2479 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2482 /* The following relocations don't need to propagate the
2483 relocation if linking a shared object since they are
2484 section relative. */
2485 case R_PPC64_SECTOFF
:
2486 case R_PPC64_SECTOFF_LO
:
2487 case R_PPC64_SECTOFF_HI
:
2488 case R_PPC64_SECTOFF_HA
:
2489 case R_PPC64_SECTOFF_DS
:
2490 case R_PPC64_SECTOFF_LO_DS
:
2492 case R_PPC64_TOC16_LO
:
2493 case R_PPC64_TOC16_HI
:
2494 case R_PPC64_TOC16_HA
:
2495 case R_PPC64_TOC16_DS
:
2496 case R_PPC64_TOC16_LO_DS
:
2499 /* This relocation describes the C++ object vtable hierarchy.
2500 Reconstruct it for later use during GC. */
2501 case R_PPC64_GNU_VTINHERIT
:
2502 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2506 /* This relocation describes which C++ vtable entries are actually
2507 used. Record for later use during GC. */
2508 case R_PPC64_GNU_VTENTRY
:
2509 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2514 case R_PPC64_REL14_BRTAKEN
:
2515 case R_PPC64_REL14_BRNTAKEN
:
2516 htab
->has_14bit_branch
= 1;
2521 && h
->root
.root
.string
[0] == '.'
2522 && h
->root
.root
.string
[1] != 0)
2524 /* We may need a .plt entry if the function this reloc
2525 refers to is in a shared lib. */
2526 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2527 h
->plt
.refcount
+= 1;
2528 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2532 case R_PPC64_ADDR64
:
2535 && h
->root
.root
.string
[0] == '.'
2536 && h
->root
.root
.string
[1] != 0)
2538 struct elf_link_hash_entry
*fdh
;
2540 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2541 false, false, false);
2544 /* Ensure the function descriptor symbol string is
2545 part of the code symbol string. We aren't
2546 changing the name here, just allowing some tricks
2547 in ppc64_elf_hide_symbol. */
2548 fdh
->root
.root
.string
= h
->root
.root
.string
+ 1;
2549 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2550 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2551 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2552 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2559 case R_PPC64_ADDR14
:
2560 case R_PPC64_ADDR14_BRNTAKEN
:
2561 case R_PPC64_ADDR14_BRTAKEN
:
2562 case R_PPC64_ADDR16
:
2563 case R_PPC64_ADDR16_DS
:
2564 case R_PPC64_ADDR16_HA
:
2565 case R_PPC64_ADDR16_HI
:
2566 case R_PPC64_ADDR16_HIGHER
:
2567 case R_PPC64_ADDR16_HIGHERA
:
2568 case R_PPC64_ADDR16_HIGHEST
:
2569 case R_PPC64_ADDR16_HIGHESTA
:
2570 case R_PPC64_ADDR16_LO
:
2571 case R_PPC64_ADDR16_LO_DS
:
2572 case R_PPC64_ADDR24
:
2573 case R_PPC64_ADDR30
:
2574 case R_PPC64_ADDR32
:
2575 case R_PPC64_UADDR16
:
2576 case R_PPC64_UADDR32
:
2577 case R_PPC64_UADDR64
:
2579 /* Don't propagate .opd relocs. */
2580 if (NO_OPD_RELOCS
&& is_opd
)
2583 /* If we are creating a shared library, and this is a reloc
2584 against a global symbol, or a non PC relative reloc
2585 against a local symbol, then we need to copy the reloc
2586 into the shared library. However, if we are linking with
2587 -Bsymbolic, we do not need to copy a reloc against a
2588 global symbol which is defined in an object we are
2589 including in the link (i.e., DEF_REGULAR is set). At
2590 this point we have not seen all the input files, so it is
2591 possible that DEF_REGULAR is not set now but will be set
2592 later (it is never cleared). In case of a weak definition,
2593 DEF_REGULAR may be cleared later by a strong definition in
2594 a shared library. We account for that possibility below by
2595 storing information in the relocs_copied field of the hash
2596 table entry. A similar situation occurs when creating
2597 shared libraries and symbol visibility changes render the
2600 If on the other hand, we are creating an executable, we
2601 may need to keep relocations for symbols satisfied by a
2602 dynamic library if we manage to avoid copy relocs for the
2605 && (sec
->flags
& SEC_ALLOC
) != 0
2606 && (IS_ABSOLUTE_RELOC (r_type
)
2608 && (! info
->symbolic
2609 || h
->root
.type
== bfd_link_hash_defweak
2610 || (h
->elf_link_hash_flags
2611 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2613 && (sec
->flags
& SEC_ALLOC
) != 0
2615 && (h
->root
.type
== bfd_link_hash_defweak
2616 || (h
->elf_link_hash_flags
2617 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2619 struct ppc_dyn_relocs
*p
;
2620 struct ppc_dyn_relocs
**head
;
2622 /* We must copy these reloc types into the output file.
2623 Create a reloc section in dynobj and make room for
2630 name
= (bfd_elf_string_from_elf_section
2632 elf_elfheader (abfd
)->e_shstrndx
,
2633 elf_section_data (sec
)->rel_hdr
.sh_name
));
2637 if (strncmp (name
, ".rela", 5) != 0
2638 || strcmp (bfd_get_section_name (abfd
, sec
),
2641 (*_bfd_error_handler
)
2642 (_("%s: bad relocation section name `%s\'"),
2643 bfd_archive_filename (abfd
), name
);
2644 bfd_set_error (bfd_error_bad_value
);
2647 dynobj
= htab
->elf
.dynobj
;
2648 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2653 sreloc
= bfd_make_section (dynobj
, name
);
2654 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2655 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2656 if ((sec
->flags
& SEC_ALLOC
) != 0)
2657 flags
|= SEC_ALLOC
| SEC_LOAD
;
2659 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2660 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2663 elf_section_data (sec
)->sreloc
= sreloc
;
2666 /* If this is a global symbol, we count the number of
2667 relocations we need for this symbol. */
2670 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
2674 /* Track dynamic relocs needed for local syms too.
2675 We really need local syms available to do this
2679 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
2684 head
= ((struct ppc_dyn_relocs
**)
2685 &elf_section_data (s
)->local_dynrel
);
2689 if (p
== NULL
|| p
->sec
!= sec
)
2691 p
= ((struct ppc_dyn_relocs
*)
2692 bfd_alloc (htab
->elf
.dynobj
,
2693 (bfd_size_type
) sizeof *p
));
2704 if (!IS_ABSOLUTE_RELOC (r_type
))
2717 /* Return the section that should be marked against GC for a given
2721 ppc64_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2723 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2724 Elf_Internal_Rela
*rel
;
2725 struct elf_link_hash_entry
*h
;
2726 Elf_Internal_Sym
*sym
;
2730 enum elf_ppc_reloc_type r_type
;
2732 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2735 case R_PPC64_GNU_VTINHERIT
:
2736 case R_PPC64_GNU_VTENTRY
:
2740 switch (h
->root
.type
)
2742 case bfd_link_hash_defined
:
2743 case bfd_link_hash_defweak
:
2744 return h
->root
.u
.def
.section
;
2746 case bfd_link_hash_common
:
2747 return h
->root
.u
.c
.p
->section
;
2756 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2762 /* Update the .got, .plt. and dynamic reloc reference counts for the
2763 section being removed. */
2766 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2768 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2770 const Elf_Internal_Rela
*relocs
;
2772 Elf_Internal_Shdr
*symtab_hdr
;
2773 struct elf_link_hash_entry
**sym_hashes
;
2774 bfd_signed_vma
*local_got_refcounts
;
2775 const Elf_Internal_Rela
*rel
, *relend
;
2777 elf_section_data (sec
)->local_dynrel
= NULL
;
2779 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2780 sym_hashes
= elf_sym_hashes (abfd
);
2781 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2783 relend
= relocs
+ sec
->reloc_count
;
2784 for (rel
= relocs
; rel
< relend
; rel
++)
2786 unsigned long r_symndx
;
2787 enum elf_ppc_reloc_type r_type
;
2788 struct elf_link_hash_entry
*h
;
2790 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2791 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2795 case R_PPC64_GOT16_DS
:
2796 case R_PPC64_GOT16_HA
:
2797 case R_PPC64_GOT16_HI
:
2798 case R_PPC64_GOT16_LO
:
2799 case R_PPC64_GOT16_LO_DS
:
2800 if (r_symndx
>= symtab_hdr
->sh_info
)
2802 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2803 if (h
->got
.refcount
> 0)
2808 if (local_got_refcounts
[r_symndx
] > 0)
2809 local_got_refcounts
[r_symndx
]--;
2813 case R_PPC64_PLT16_HA
:
2814 case R_PPC64_PLT16_HI
:
2815 case R_PPC64_PLT16_LO
:
2818 if (r_symndx
>= symtab_hdr
->sh_info
)
2820 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2821 if (h
->plt
.refcount
> 0)
2827 case R_PPC64_REL14_BRNTAKEN
:
2828 case R_PPC64_REL14_BRTAKEN
:
2830 if (r_symndx
>= symtab_hdr
->sh_info
)
2832 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2833 if (h
->plt
.refcount
> 0)
2840 if (r_symndx
>= symtab_hdr
->sh_info
)
2842 struct ppc_link_hash_entry
*eh
;
2843 struct ppc_dyn_relocs
**pp
;
2844 struct ppc_dyn_relocs
*p
;
2846 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2847 eh
= (struct ppc_link_hash_entry
*) h
;
2849 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2861 case R_PPC64_ADDR14
:
2862 case R_PPC64_ADDR14_BRNTAKEN
:
2863 case R_PPC64_ADDR14_BRTAKEN
:
2864 case R_PPC64_ADDR16
:
2865 case R_PPC64_ADDR16_DS
:
2866 case R_PPC64_ADDR16_HA
:
2867 case R_PPC64_ADDR16_HI
:
2868 case R_PPC64_ADDR16_HIGHER
:
2869 case R_PPC64_ADDR16_HIGHERA
:
2870 case R_PPC64_ADDR16_HIGHEST
:
2871 case R_PPC64_ADDR16_HIGHESTA
:
2872 case R_PPC64_ADDR16_LO
:
2873 case R_PPC64_ADDR16_LO_DS
:
2874 case R_PPC64_ADDR24
:
2875 case R_PPC64_ADDR30
:
2876 case R_PPC64_ADDR32
:
2877 case R_PPC64_ADDR64
:
2878 case R_PPC64_UADDR16
:
2879 case R_PPC64_UADDR32
:
2880 case R_PPC64_UADDR64
:
2882 if (r_symndx
>= symtab_hdr
->sh_info
)
2884 struct ppc_link_hash_entry
*eh
;
2885 struct ppc_dyn_relocs
**pp
;
2886 struct ppc_dyn_relocs
*p
;
2888 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2889 eh
= (struct ppc_link_hash_entry
*) h
;
2891 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2909 /* Called via elf_link_hash_traverse to transfer dynamic linking
2910 information on function code symbol entries to their corresponding
2911 function descriptor symbol entries. */
2913 func_desc_adjust (h
, inf
)
2914 struct elf_link_hash_entry
*h
;
2917 struct bfd_link_info
*info
;
2918 struct ppc_link_hash_table
*htab
;
2920 if (h
->root
.type
== bfd_link_hash_indirect
)
2923 if (h
->root
.type
== bfd_link_hash_warning
)
2924 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2926 info
= (struct bfd_link_info
*) inf
;
2927 htab
= ppc_hash_table (info
);
2929 /* If this is a function code symbol, transfer dynamic linking
2930 information to the function descriptor symbol. */
2931 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
2934 if (h
->plt
.refcount
> 0
2935 && h
->root
.root
.string
[0] == '.'
2936 && h
->root
.root
.string
[1] != '\0')
2938 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
2939 boolean force_local
;
2941 /* Find the corresponding function descriptor symbol. Create it
2942 as undefined if necessary. */
2945 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2946 false, false, true);
2950 && (h
->root
.type
== bfd_link_hash_undefined
2951 || h
->root
.type
== bfd_link_hash_undefweak
))
2956 abfd
= h
->root
.u
.undef
.abfd
;
2957 newsym
= bfd_make_empty_symbol (abfd
);
2958 newsym
->name
= h
->root
.root
.string
+ 1;
2959 newsym
->section
= bfd_und_section_ptr
;
2961 newsym
->flags
= BSF_OBJECT
;
2962 if (h
->root
.type
== bfd_link_hash_undefweak
)
2963 newsym
->flags
|= BSF_WEAK
;
2965 if ( !(_bfd_generic_link_add_one_symbol
2966 (info
, abfd
, newsym
->name
, newsym
->flags
,
2967 newsym
->section
, newsym
->value
, NULL
, false, false,
2968 (struct bfd_link_hash_entry
**) &fdh
)))
2972 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
2976 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
2978 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2979 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
2981 if (fdh
->dynindx
== -1)
2982 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
2984 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
2985 & (ELF_LINK_HASH_REF_REGULAR
2986 | ELF_LINK_HASH_REF_DYNAMIC
2987 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
2988 | ELF_LINK_NON_GOT_REF
));
2989 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2991 fdh
->plt
.refcount
= h
->plt
.refcount
;
2992 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2994 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2995 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2996 fdh
->root
.root
.string
= h
->root
.root
.string
+ 1;
2997 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3000 /* Now that the info is on the function descriptor, clear the
3001 function code sym info. Any function code syms for which we
3002 don't have a definition in a regular file, we force local.
3003 This prevents a shared library from exporting syms that have
3004 been imported from another library. Function code syms that
3005 are really in the library we must leave global to prevent the
3006 linker dragging in a definition from a static library. */
3007 force_local
= ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3009 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3015 #define MIN_SAVE_FPR 14
3016 #define MAX_SAVE_FPR 31
3018 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3019 this hook to a) provide some gcc support functions, and b) transfer
3020 dynamic linking information gathered so far on function code symbol
3021 entries, to their corresponding function descriptor symbol entries. */
3023 ppc64_elf_func_desc_adjust (obfd
, info
)
3024 bfd
*obfd ATTRIBUTE_UNUSED
;
3025 struct bfd_link_info
*info
;
3027 struct ppc_link_hash_table
*htab
;
3028 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3029 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3031 struct elf_link_hash_entry
*h
;
3035 htab
= ppc_hash_table (info
);
3037 if (htab
->sfpr
== NULL
)
3038 /* We don't have any relocs. */
3041 /* First provide any missing ._savef* and ._restf* functions. */
3042 memcpy (sym
, "._savef14", 10);
3043 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3045 sym
[7] = i
/ 10 + '0';
3046 sym
[8] = i
% 10 + '0';
3047 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3049 && h
->root
.type
== bfd_link_hash_undefined
)
3051 if (lowest_savef
> i
)
3053 h
->root
.type
= bfd_link_hash_defined
;
3054 h
->root
.u
.def
.section
= htab
->sfpr
;
3055 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3057 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3058 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3062 memcpy (sym
, "._restf14", 10);
3063 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3065 sym
[7] = i
/ 10 + '0';
3066 sym
[8] = i
% 10 + '0';
3067 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3069 && h
->root
.type
== bfd_link_hash_undefined
)
3071 if (lowest_restf
> i
)
3073 h
->root
.type
= bfd_link_hash_defined
;
3074 h
->root
.u
.def
.section
= htab
->sfpr
;
3075 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3076 + (i
- lowest_restf
) * 4);
3078 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3079 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3083 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3084 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3086 if (htab
->sfpr
->_raw_size
== 0)
3087 htab
->sfpr
->_raw_size
= 4;
3089 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3092 htab
->sfpr
->contents
= p
;
3094 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3096 unsigned int fpr
= i
<< 21;
3097 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3098 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3101 if (lowest_savef
<= MAX_SAVE_FPR
)
3103 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3107 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3109 unsigned int fpr
= i
<< 21;
3110 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3111 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3114 if (lowest_restf
<= MAX_SAVE_FPR
3115 || htab
->sfpr
->_raw_size
== 4)
3117 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3120 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3124 /* Adjust a symbol defined by a dynamic object and referenced by a
3125 regular object. The current definition is in some section of the
3126 dynamic object, but we're not including those sections. We have to
3127 change the definition to something the rest of the link can
3131 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3132 struct bfd_link_info
*info
;
3133 struct elf_link_hash_entry
*h
;
3135 struct ppc_link_hash_table
*htab
;
3136 struct ppc_link_hash_entry
* eh
;
3137 struct ppc_dyn_relocs
*p
;
3139 unsigned int power_of_two
;
3141 htab
= ppc_hash_table (info
);
3143 /* Deal with function syms. */
3144 if (h
->type
== STT_FUNC
3145 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3147 /* Clear procedure linkage table information for any symbol that
3148 won't need a .plt entry. */
3149 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3150 || h
->plt
.refcount
<= 0
3151 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3153 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3154 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3156 h
->plt
.offset
= (bfd_vma
) -1;
3157 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3162 h
->plt
.offset
= (bfd_vma
) -1;
3164 /* If this is a weak symbol, and there is a real definition, the
3165 processor independent code will have arranged for us to see the
3166 real definition first, and we can just use the same value. */
3167 if (h
->weakdef
!= NULL
)
3169 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3170 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3171 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3172 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3176 /* This is a reference to a symbol defined by a dynamic object which
3177 is not a function. */
3179 /* If we are creating a shared library, we must presume that the
3180 only references to the symbol are via the global offset table.
3181 For such cases we need not do anything here; the relocations will
3182 be handled correctly by relocate_section. */
3186 /* If there are no references to this symbol that do not use the
3187 GOT, we don't need to generate a copy reloc. */
3188 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3191 eh
= (struct ppc_link_hash_entry
*) h
;
3192 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3194 s
= p
->sec
->output_section
;
3195 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3199 /* If we didn't find any dynamic relocs in read-only sections, then
3200 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3203 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3207 /* We must allocate the symbol in our .dynbss section, which will
3208 become part of the .bss section of the executable. There will be
3209 an entry for this symbol in the .dynsym section. The dynamic
3210 object will contain position independent code, so all references
3211 from the dynamic object to this symbol will go through the global
3212 offset table. The dynamic linker will use the .dynsym entry to
3213 determine the address it must put in the global offset table, so
3214 both the dynamic object and the regular object will refer to the
3215 same memory location for the variable. */
3217 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3218 copy the initial value out of the dynamic object and into the
3219 runtime process image. We need to remember the offset into the
3220 .rela.bss section we are going to use. */
3221 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3223 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3224 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3227 /* We need to figure out the alignment required for this symbol. I
3228 have no idea how ELF linkers handle this. */
3229 power_of_two
= bfd_log2 (h
->size
);
3230 if (power_of_two
> 4)
3233 /* Apply the required alignment. */
3235 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3236 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3238 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3242 /* Define the symbol as being at this point in the section. */
3243 h
->root
.u
.def
.section
= s
;
3244 h
->root
.u
.def
.value
= s
->_raw_size
;
3246 /* Increment the section size to make room for the symbol. */
3247 s
->_raw_size
+= h
->size
;
3252 /* If given a function descriptor symbol, hide both the function code
3253 sym and the descriptor. */
3255 ppc64_elf_hide_symbol (info
, h
, force_local
)
3256 struct bfd_link_info
*info
;
3257 struct elf_link_hash_entry
*h
;
3258 boolean force_local
;
3260 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3262 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3265 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3266 struct ppc_link_hash_table
*htab
;
3268 name
= h
->root
.root
.string
- 1;
3269 htab
= ppc_hash_table (info
);
3271 fh
= elf_link_hash_lookup (&htab
->elf
, name
, false, false, false);
3273 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3277 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3278 will be called from elflink.h. If elflink.h doesn't call our
3279 finish_dynamic_symbol routine, we'll need to do something about
3280 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3281 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3283 && ((INFO)->shared \
3284 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3285 && ((H)->dynindx != -1 \
3286 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3288 /* Allocate space in .plt, .got and associated reloc sections for
3292 allocate_dynrelocs (h
, inf
)
3293 struct elf_link_hash_entry
*h
;
3296 struct bfd_link_info
*info
;
3297 struct ppc_link_hash_table
*htab
;
3299 struct ppc_link_hash_entry
*eh
;
3300 struct ppc_dyn_relocs
*p
;
3302 if (h
->root
.type
== bfd_link_hash_indirect
)
3305 if (h
->root
.type
== bfd_link_hash_warning
)
3306 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3308 info
= (struct bfd_link_info
*) inf
;
3309 htab
= ppc_hash_table (info
);
3311 if (htab
->elf
.dynamic_sections_created
3312 && h
->plt
.refcount
> 0
3313 && h
->dynindx
!= -1)
3315 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
3317 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3319 /* If this is the first .plt entry, make room for the special
3322 if (s
->_raw_size
== 0)
3323 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3325 h
->plt
.offset
= s
->_raw_size
;
3327 /* Make room for this entry. */
3328 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3330 /* Make room for the .glink code. */
3332 if (s
->_raw_size
== 0)
3333 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
3334 /* We need bigger stubs past index 32767. */
3335 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
3337 s
->_raw_size
+= 2*4;
3339 /* We also need to make an entry in the .rela.plt section. */
3341 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3345 h
->plt
.offset
= (bfd_vma
) -1;
3346 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3351 h
->plt
.offset
= (bfd_vma
) -1;
3352 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3355 if (h
->got
.refcount
> 0)
3359 /* Make sure this symbol is output as a dynamic symbol.
3360 Undefined weak syms won't yet be marked as dynamic. */
3361 if (h
->dynindx
== -1
3362 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3364 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3369 h
->got
.offset
= s
->_raw_size
;
3371 dyn
= htab
->elf
.dynamic_sections_created
;
3372 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
3373 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
3376 h
->got
.offset
= (bfd_vma
) -1;
3378 eh
= (struct ppc_link_hash_entry
*) h
;
3379 if (eh
->dyn_relocs
== NULL
)
3382 /* In the shared -Bsymbolic case, discard space allocated for
3383 dynamic pc-relative relocs against symbols which turn out to be
3384 defined in regular objects. For the normal shared case, discard
3385 space for relocs that have become local due to symbol visibility
3390 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3391 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3394 struct ppc_dyn_relocs
**pp
;
3396 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3398 p
->count
-= p
->pc_count
;
3409 /* For the non-shared case, discard space for relocs against
3410 symbols which turn out to need copy relocs or are not
3413 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3414 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3415 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3416 || (htab
->elf
.dynamic_sections_created
3417 && (h
->root
.type
== bfd_link_hash_undefweak
3418 || h
->root
.type
== bfd_link_hash_undefined
))))
3420 /* Make sure this symbol is output as a dynamic symbol.
3421 Undefined weak syms won't yet be marked as dynamic. */
3422 if (h
->dynindx
== -1
3423 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3425 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3429 /* If that succeeded, we know we'll be keeping all the
3431 if (h
->dynindx
!= -1)
3435 eh
->dyn_relocs
= NULL
;
3440 /* Finally, allocate space. */
3441 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3443 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3444 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
3450 /* Find any dynamic relocs that apply to read-only sections. */
3453 readonly_dynrelocs (h
, inf
)
3454 struct elf_link_hash_entry
*h
;
3457 struct ppc_link_hash_entry
*eh
;
3458 struct ppc_dyn_relocs
*p
;
3460 if (h
->root
.type
== bfd_link_hash_warning
)
3461 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3463 eh
= (struct ppc_link_hash_entry
*) h
;
3464 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3466 asection
*s
= p
->sec
->output_section
;
3468 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3470 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3472 info
->flags
|= DF_TEXTREL
;
3474 /* Not an error, just cut short the traversal. */
3481 /* Set the sizes of the dynamic sections. */
3484 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
3485 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3486 struct bfd_link_info
*info
;
3488 struct ppc_link_hash_table
*htab
;
3494 htab
= ppc_hash_table (info
);
3495 dynobj
= htab
->elf
.dynobj
;
3499 if (htab
->elf
.dynamic_sections_created
)
3501 /* Set the contents of the .interp section to the interpreter. */
3504 s
= bfd_get_section_by_name (dynobj
, ".interp");
3507 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3508 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3512 /* Set up .got offsets for local syms, and space for local dynamic
3514 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3516 bfd_signed_vma
*local_got
;
3517 bfd_signed_vma
*end_local_got
;
3518 bfd_size_type locsymcount
;
3519 Elf_Internal_Shdr
*symtab_hdr
;
3522 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3525 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3527 struct ppc_dyn_relocs
*p
;
3529 for (p
= *((struct ppc_dyn_relocs
**)
3530 &elf_section_data (s
)->local_dynrel
);
3534 if (!bfd_is_abs_section (p
->sec
)
3535 && bfd_is_abs_section (p
->sec
->output_section
))
3537 /* Input section has been discarded, either because
3538 it is a copy of a linkonce section or due to
3539 linker script /DISCARD/, so we'll be discarding
3542 else if (p
->count
!= 0)
3544 srel
= elf_section_data (p
->sec
)->sreloc
;
3545 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
3546 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3547 info
->flags
|= DF_TEXTREL
;
3552 local_got
= elf_local_got_refcounts (ibfd
);
3556 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3557 locsymcount
= symtab_hdr
->sh_info
;
3558 end_local_got
= local_got
+ locsymcount
;
3560 srel
= htab
->srelgot
;
3561 for (; local_got
< end_local_got
; ++local_got
)
3565 *local_got
= s
->_raw_size
;
3568 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
3571 *local_got
= (bfd_vma
) -1;
3575 /* Allocate global sym .plt and .got entries, and space for global
3576 sym dynamic relocs. */
3577 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
3579 /* We now have determined the sizes of the various dynamic sections.
3580 Allocate memory for them. */
3582 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3584 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3587 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
3588 /* These haven't been allocated yet; don't strip. */
3590 else if (s
== htab
->splt
3592 || s
== htab
->sglink
)
3594 /* Strip this section if we don't need it; see the
3597 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3599 if (s
->_raw_size
== 0)
3601 /* If we don't need this section, strip it from the
3602 output file. This is mostly to handle .rela.bss and
3603 .rela.plt. We must create both sections in
3604 create_dynamic_sections, because they must be created
3605 before the linker maps input sections to output
3606 sections. The linker does that before
3607 adjust_dynamic_symbol is called, and it is that
3608 function which decides whether anything needs to go
3609 into these sections. */
3613 if (s
!= htab
->srelplt
)
3616 /* We use the reloc_count field as a counter if we need
3617 to copy relocs into the output file. */
3623 /* It's not one of our sections, so don't allocate space. */
3627 if (s
->_raw_size
== 0)
3629 _bfd_strip_section_from_output (info
, s
);
3633 /* Allocate memory for the section contents. We use bfd_zalloc
3634 here in case unused entries are not reclaimed before the
3635 section's contents are written out. This should not happen,
3636 but this way if it does, we get a R_PPC64_NONE reloc instead
3638 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3639 if (s
->contents
== NULL
)
3643 if (htab
->elf
.dynamic_sections_created
)
3645 /* Add some entries to the .dynamic section. We fill in the
3646 values later, in ppc64_elf_finish_dynamic_sections, but we
3647 must add the entries now so that we get the correct size for
3648 the .dynamic section. The DT_DEBUG entry is filled in by the
3649 dynamic linker and used by the debugger. */
3650 #define add_dynamic_entry(TAG, VAL) \
3651 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3655 if (!add_dynamic_entry (DT_DEBUG
, 0))
3659 if (htab
->splt
->_raw_size
!= 0)
3661 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3662 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3663 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3664 || !add_dynamic_entry (DT_JMPREL
, 0)
3665 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
3671 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
3672 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
3678 if (!add_dynamic_entry (DT_RELA
, 0)
3679 || !add_dynamic_entry (DT_RELASZ
, 0)
3680 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
3683 /* If any dynamic relocs apply to a read-only section,
3684 then we need a DT_TEXTREL entry. */
3685 if ((info
->flags
& DF_TEXTREL
) == 0)
3686 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
3689 if ((info
->flags
& DF_TEXTREL
) != 0)
3691 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3696 #undef add_dynamic_entry
3701 /* Determine the type of stub needed, if any, for a call. */
3703 static INLINE
enum ppc_stub_type
3704 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
3705 asection
*input_sec
;
3706 const Elf_Internal_Rela
*rel
;
3707 struct ppc_link_hash_entry
**hash
;
3708 bfd_vma destination
;
3710 struct ppc_link_hash_entry
*h
= *hash
;
3712 bfd_vma branch_offset
;
3713 bfd_vma max_branch_offset
;
3714 unsigned int r_type
;
3719 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
3720 && h
->oh
->dynindx
!= -1)
3722 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
3723 return ppc_stub_plt_call
;
3726 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
3727 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
3728 return ppc_stub_none
;
3731 /* Determine where the call point is. */
3732 location
= (input_sec
->output_offset
3733 + input_sec
->output_section
->vma
3736 branch_offset
= destination
- location
;
3737 r_type
= ELF64_R_TYPE (rel
->r_info
);
3739 /* Determine if a long branch stub is needed. */
3740 max_branch_offset
= 1 << 25;
3741 if (r_type
!= (unsigned int) R_PPC64_REL24
)
3742 max_branch_offset
= 1 << 15;
3744 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
3745 /* We need a stub. Figure out whether a long_branch or plt_branch
3747 return ppc_stub_long_branch
;
3749 return ppc_stub_none
;
3752 /* Build a .plt call stub. */
3755 build_plt_stub (obfd
, p
, offset
, glink
)
3761 #define PPC_LO(v) ((v) & 0xffff)
3762 #define PPC_HI(v) (((v) >> 16) & 0xffff)
3763 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
3766 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
3767 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
3769 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
3770 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
3771 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
3772 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
3774 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
3775 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
3776 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
3778 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
3779 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
3780 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
3785 ppc_build_one_stub (gen_entry
, in_arg
)
3786 struct bfd_hash_entry
*gen_entry
;
3789 struct ppc_stub_hash_entry
*stub_entry
;
3790 struct ppc_branch_hash_entry
*br_entry
;
3791 struct bfd_link_info
*info
;
3792 struct ppc_link_hash_table
*htab
;
3801 /* Massage our args to the form they really have. */
3802 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
3803 info
= (struct bfd_link_info
*) in_arg
;
3805 htab
= ppc_hash_table (info
);
3806 stub_sec
= stub_entry
->stub_sec
;
3808 /* Make a note of the offset within the stubs for this entry. */
3809 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
3810 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
3812 stub_bfd
= stub_sec
->owner
;
3814 switch (stub_entry
->stub_type
)
3816 case ppc_stub_long_branch
:
3817 /* Branches are relative. This is where we are going to. */
3818 off
= (stub_entry
->target_value
3819 + stub_entry
->target_section
->output_offset
3820 + stub_entry
->target_section
->output_section
->vma
);
3822 /* And this is where we are coming from. */
3823 off
-= (stub_entry
->stub_offset
3824 + stub_sec
->output_offset
3825 + stub_sec
->output_section
->vma
);
3827 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
3829 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
3833 case ppc_stub_plt_branch
:
3834 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
3835 stub_entry
->root
.string
+ 9,
3837 if (br_entry
== NULL
)
3839 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
3840 stub_entry
->root
.string
+ 9);
3841 htab
->stub_error
= true;
3845 off
= (stub_entry
->target_value
3846 + stub_entry
->target_section
->output_offset
3847 + stub_entry
->target_section
->output_section
->vma
);
3849 bfd_put_64 (htab
->sbrlt
->owner
, off
,
3850 htab
->sbrlt
->contents
+ br_entry
->offset
);
3854 /* Create a reloc for the branch lookup table entry. */
3855 Elf_Internal_Rela rela
;
3856 Elf64_External_Rela
*r
;
3858 rela
.r_offset
= (br_entry
->offset
3859 + htab
->sbrlt
->output_offset
3860 + htab
->sbrlt
->output_section
->vma
);
3861 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3862 rela
.r_addend
= off
;
3864 r
= (Elf64_External_Rela
*) htab
->srelbrlt
->contents
;
3865 r
+= htab
->srelbrlt
->reloc_count
++;
3866 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, r
);
3869 off
= (br_entry
->offset
3870 + htab
->sbrlt
->output_offset
3871 + htab
->sbrlt
->output_section
->vma
3872 - elf_gp (htab
->sbrlt
->output_section
->owner
)
3875 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
3877 (*_bfd_error_handler
)
3878 (_("linkage table error against `%s'"),
3879 stub_entry
->root
.string
);
3880 bfd_set_error (bfd_error_bad_value
);
3881 htab
->stub_error
= true;
3886 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
3887 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
3888 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
3889 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
3893 case ppc_stub_plt_call
:
3894 /* Build the .glink lazy link call stub. */
3895 p
= htab
->sglink
->contents
+ htab
->sglink
->_cooked_size
;
3896 indx
= htab
->sglink
->reloc_count
;
3899 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
3904 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
3906 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
3909 bfd_put_32 (htab
->sglink
->owner
,
3910 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
3912 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
3913 htab
->sglink
->reloc_count
+= 1;
3915 /* Now build the stub. */
3916 off
= stub_entry
->h
->elf
.plt
.offset
;
3917 if (off
>= (bfd_vma
) -2)
3920 off
&= ~ (bfd_vma
) 1;
3921 off
+= (htab
->splt
->output_offset
3922 + htab
->splt
->output_section
->vma
3923 - elf_gp (htab
->splt
->output_section
->owner
)
3926 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
3928 (*_bfd_error_handler
)
3929 (_("linkage table error against `%s'"),
3930 stub_entry
->h
->elf
.root
.root
.string
);
3931 bfd_set_error (bfd_error_bad_value
);
3932 htab
->stub_error
= true;
3936 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
3945 stub_sec
->_cooked_size
+= size
;
3949 /* As above, but don't actually build the stub. Just bump offset so
3950 we know stub section sizes, and select plt_branch stubs where
3951 long_branch stubs won't do. */
3954 ppc_size_one_stub (gen_entry
, in_arg
)
3955 struct bfd_hash_entry
*gen_entry
;
3958 struct ppc_stub_hash_entry
*stub_entry
;
3959 struct ppc_link_hash_table
*htab
;
3963 /* Massage our args to the form they really have. */
3964 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
3965 htab
= (struct ppc_link_hash_table
*) in_arg
;
3967 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
3969 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
3970 off
+= (htab
->splt
->output_offset
3971 + htab
->splt
->output_section
->vma
3972 - elf_gp (htab
->splt
->output_section
->owner
)
3976 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
3981 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
3982 stub_entry
->stub_type
= ppc_stub_long_branch
;
3985 off
= (stub_entry
->target_value
3986 + stub_entry
->target_section
->output_offset
3987 + stub_entry
->target_section
->output_section
->vma
);
3988 off
-= (stub_entry
->stub_sec
->_raw_size
3989 + stub_entry
->stub_sec
->output_offset
3990 + stub_entry
->stub_sec
->output_section
->vma
);
3992 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
3994 struct ppc_branch_hash_entry
*br_entry
;
3996 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
3997 stub_entry
->root
.string
+ 9,
3999 if (br_entry
== NULL
)
4001 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4002 stub_entry
->root
.string
+ 9);
4003 htab
->stub_error
= true;
4007 if (br_entry
->iter
!= htab
->stub_iteration
)
4009 br_entry
->iter
= htab
->stub_iteration
;
4010 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4011 htab
->sbrlt
->_raw_size
+= 8;
4013 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4018 stub_entry
->stub_sec
->_raw_size
+= size
;
4022 /* Set up various things so that we can make a list of input sections
4023 for each output section included in the link. Returns -1 on error,
4024 0 when no stubs will be needed, and 1 on success. */
4027 ppc64_elf_setup_section_lists (output_bfd
, info
)
4029 struct bfd_link_info
*info
;
4032 unsigned int bfd_count
;
4033 int top_id
, top_index
;
4035 asection
**input_list
, **list
;
4037 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4039 if (htab
->sbrlt
== NULL
)
4042 /* Count the number of input BFDs and find the top input section id. */
4043 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
4045 input_bfd
= input_bfd
->link_next
)
4048 for (section
= input_bfd
->sections
;
4050 section
= section
->next
)
4052 if (top_id
< section
->id
)
4053 top_id
= section
->id
;
4056 htab
->bfd_count
= bfd_count
;
4058 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4059 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4060 if (htab
->stub_group
== NULL
)
4063 /* We can't use output_bfd->section_count here to find the top output
4064 section index as some sections may have been removed, and
4065 _bfd_strip_section_from_output doesn't renumber the indices. */
4066 for (section
= output_bfd
->sections
, top_index
= 0;
4068 section
= section
->next
)
4070 if (top_index
< section
->index
)
4071 top_index
= section
->index
;
4074 htab
->top_index
= top_index
;
4075 amt
= sizeof (asection
*) * (top_index
+ 1);
4076 input_list
= (asection
**) bfd_malloc (amt
);
4077 htab
->input_list
= input_list
;
4078 if (input_list
== NULL
)
4081 /* For sections we aren't interested in, mark their entries with a
4082 value we can check later. */
4083 list
= input_list
+ top_index
;
4085 *list
= bfd_abs_section_ptr
;
4086 while (list
-- != input_list
);
4088 for (section
= output_bfd
->sections
;
4090 section
= section
->next
)
4092 if ((section
->flags
& SEC_CODE
) != 0)
4093 input_list
[section
->index
] = NULL
;
4099 /* The linker repeatedly calls this function for each input section,
4100 in the order that input sections are linked into output sections.
4101 Build lists of input sections to determine groupings between which
4102 we may insert linker stubs. */
4105 ppc64_elf_next_input_section (output_bfd
, info
, isec
)
4107 struct bfd_link_info
*info
;
4110 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4112 if (isec
->output_section
!= NULL
4113 && isec
->output_section
->owner
== output_bfd
4114 && isec
->output_section
->index
<= htab
->top_index
)
4116 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4117 if (*list
!= bfd_abs_section_ptr
)
4119 /* Steal the link_sec pointer for our list. */
4120 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4121 /* This happens to make the list in reverse order,
4122 which is what we want. */
4123 PREV_SEC (isec
) = *list
;
4129 /* See whether we can group stub sections together. Grouping stub
4130 sections may result in fewer stubs. More importantly, we need to
4131 put all .init* and .fini* stubs at the beginning of the .init or
4132 .fini output sections respectively, because glibc splits the
4133 _init and _fini functions into multiple parts. Putting a stub in
4134 the middle of a function is not a good idea. */
4137 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4138 struct ppc_link_hash_table
*htab
;
4139 bfd_size_type stub_group_size
;
4140 boolean stubs_always_before_branch
;
4142 asection
**list
= htab
->input_list
+ htab
->top_index
;
4145 asection
*tail
= *list
;
4146 if (tail
== bfd_abs_section_ptr
)
4148 while (tail
!= NULL
)
4152 bfd_size_type total
;
4155 if (tail
->_cooked_size
)
4156 total
= tail
->_cooked_size
;
4158 total
= tail
->_raw_size
;
4159 while ((prev
= PREV_SEC (curr
)) != NULL
4160 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4164 /* OK, the size from the start of CURR to the end is less
4165 than stub_group_size and thus can be handled by one stub
4166 section. (or the tail section is itself larger than
4167 stub_group_size, in which case we may be toast.) We
4168 should really be keeping track of the total size of stubs
4169 added here, as stubs contribute to the final output
4170 section size. That's a little tricky, and this way will
4171 only break if stubs added make the total size more than
4172 2^25, ie. for the default stub_group_size, if stubs total
4173 more than 2834432 bytes, or over 100000 plt call stubs. */
4176 prev
= PREV_SEC (tail
);
4177 /* Set up this stub group. */
4178 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4180 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4182 /* But wait, there's more! Input sections up to stub_group_size
4183 bytes before the stub section can be handled by it too. */
4184 if (!stubs_always_before_branch
)
4188 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4192 prev
= PREV_SEC (tail
);
4193 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4199 while (list
-- != htab
->input_list
);
4200 free (htab
->input_list
);
4204 /* Read in all local syms for all input bfds. */
4207 get_local_syms (input_bfd
, htab
)
4209 struct ppc_link_hash_table
*htab
;
4211 unsigned int bfd_indx
;
4212 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
4214 /* We want to read in symbol extension records only once. To do this
4215 we need to read in the local symbols in parallel and save them for
4216 later use; so hold pointers to the local symbols in an array. */
4217 bfd_size_type amt
= sizeof (Elf_Internal_Sym
*) * htab
->bfd_count
;
4218 all_local_syms
= (Elf_Internal_Sym
**) bfd_zmalloc (amt
);
4219 htab
->all_local_syms
= all_local_syms
;
4220 if (all_local_syms
== NULL
)
4223 /* Walk over all the input BFDs, swapping in local symbols.
4224 If we are creating a shared library, create hash entries for the
4228 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4230 Elf_Internal_Shdr
*symtab_hdr
;
4231 Elf_Internal_Shdr
*shndx_hdr
;
4232 Elf_Internal_Sym
*isym
;
4233 Elf64_External_Sym
*ext_syms
, *esym
, *end_sy
;
4234 Elf_External_Sym_Shndx
*shndx_buf
, *shndx
;
4235 bfd_size_type sec_size
;
4237 /* We'll need the symbol table in a second. */
4238 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4239 if (symtab_hdr
->sh_info
== 0)
4242 /* We need an array of the local symbols attached to the input bfd.
4243 Unfortunately, we're going to have to read & swap them in. */
4244 sec_size
= symtab_hdr
->sh_info
;
4245 sec_size
*= sizeof (Elf_Internal_Sym
);
4246 local_syms
= (Elf_Internal_Sym
*) bfd_malloc (sec_size
);
4247 if (local_syms
== NULL
)
4250 all_local_syms
[bfd_indx
] = local_syms
;
4251 sec_size
= symtab_hdr
->sh_info
;
4252 sec_size
*= sizeof (Elf64_External_Sym
);
4253 ext_syms
= (Elf64_External_Sym
*) bfd_malloc (sec_size
);
4254 if (ext_syms
== NULL
)
4257 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
4258 || bfd_bread ((PTR
) ext_syms
, sec_size
, input_bfd
) != sec_size
)
4260 error_ret_free_ext_syms
:
4266 shndx_hdr
= &elf_tdata (input_bfd
)->symtab_shndx_hdr
;
4267 if (shndx_hdr
->sh_size
!= 0)
4269 sec_size
= symtab_hdr
->sh_info
;
4270 sec_size
*= sizeof (Elf_External_Sym_Shndx
);
4271 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (sec_size
);
4272 if (shndx_buf
== NULL
)
4273 goto error_ret_free_ext_syms
;
4275 if (bfd_seek (input_bfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
4276 || bfd_bread ((PTR
) shndx_buf
, sec_size
, input_bfd
) != sec_size
)
4279 goto error_ret_free_ext_syms
;
4283 /* Swap the local symbols in. */
4284 for (esym
= ext_syms
, end_sy
= esym
+ symtab_hdr
->sh_info
,
4285 isym
= local_syms
, shndx
= shndx_buf
;
4287 esym
++, isym
++, shndx
= (shndx
? shndx
+ 1 : NULL
))
4288 bfd_elf64_swap_symbol_in (input_bfd
, esym
, shndx
, isym
);
4290 /* Now we can free the external symbols. */
4298 /* Determine and set the size of the stub section for a final link.
4300 The basic idea here is to examine all the relocations looking for
4301 PC-relative calls to a target that is unreachable with a "bl"
4305 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
4306 add_stub_section
, layout_sections_again
)
4309 struct bfd_link_info
*info
;
4310 bfd_signed_vma group_size
;
4311 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
4312 void (*layout_sections_again
) PARAMS ((void));
4314 bfd_size_type stub_group_size
;
4315 boolean stubs_always_before_branch
;
4316 boolean ret
= false;
4317 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4319 /* Stash our params away. */
4320 htab
->stub_bfd
= stub_bfd
;
4321 htab
->add_stub_section
= add_stub_section
;
4322 htab
->layout_sections_again
= layout_sections_again
;
4323 stubs_always_before_branch
= group_size
< 0;
4325 stub_group_size
= -group_size
;
4327 stub_group_size
= group_size
;
4328 if (stub_group_size
== 1)
4330 /* Default values. */
4331 stub_group_size
= 30720000;
4332 if (htab
->has_14bit_branch
)
4333 stub_group_size
= 30000;
4336 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4338 if (! get_local_syms (info
->input_bfds
, htab
))
4340 if (htab
->all_local_syms
)
4341 goto error_ret_free_local
;
4348 unsigned int bfd_indx
;
4350 boolean stub_changed
;
4352 htab
->stub_iteration
+= 1;
4353 stub_changed
= false;
4355 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4357 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4359 Elf_Internal_Shdr
*symtab_hdr
;
4361 Elf_Internal_Sym
*local_syms
;
4363 /* We'll need the symbol table in a second. */
4364 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4365 if (symtab_hdr
->sh_info
== 0)
4368 local_syms
= htab
->all_local_syms
[bfd_indx
];
4370 /* Walk over each section attached to the input bfd. */
4371 for (section
= input_bfd
->sections
;
4373 section
= section
->next
)
4375 Elf_Internal_Shdr
*input_rel_hdr
;
4376 Elf64_External_Rela
*external_relocs
, *erelaend
, *erela
;
4377 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4380 /* If there aren't any relocs, then there's nothing more
4382 if ((section
->flags
& SEC_RELOC
) == 0
4383 || section
->reloc_count
== 0)
4386 /* If this section is a link-once section that will be
4387 discarded, then don't create any stubs. */
4388 if (section
->output_section
== NULL
4389 || section
->output_section
->owner
!= output_bfd
)
4392 /* Allocate space for the external relocations. */
4393 amt
= section
->reloc_count
;
4394 amt
*= sizeof (Elf64_External_Rela
);
4395 external_relocs
= (Elf64_External_Rela
*) bfd_malloc (amt
);
4396 if (external_relocs
== NULL
)
4398 goto error_ret_free_local
;
4401 /* Likewise for the internal relocations. */
4402 amt
= section
->reloc_count
;
4403 amt
*= sizeof (Elf_Internal_Rela
);
4404 internal_relocs
= (Elf_Internal_Rela
*) bfd_malloc (amt
);
4405 if (internal_relocs
== NULL
)
4407 free (external_relocs
);
4408 goto error_ret_free_local
;
4411 /* Read in the external relocs. */
4412 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
4413 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
4414 || bfd_bread ((PTR
) external_relocs
,
4415 input_rel_hdr
->sh_size
,
4416 input_bfd
) != input_rel_hdr
->sh_size
)
4418 free (external_relocs
);
4419 error_ret_free_internal
:
4420 free (internal_relocs
);
4421 goto error_ret_free_local
;
4424 /* Swap in the relocs. */
4425 erela
= external_relocs
;
4426 erelaend
= erela
+ section
->reloc_count
;
4427 irela
= internal_relocs
;
4428 for (; erela
< erelaend
; erela
++, irela
++)
4429 bfd_elf64_swap_reloca_in (input_bfd
, erela
, irela
);
4431 /* We're done with the external relocs, free them. */
4432 free (external_relocs
);
4434 /* Now examine each relocation. */
4435 irela
= internal_relocs
;
4436 irelaend
= irela
+ section
->reloc_count
;
4437 for (; irela
< irelaend
; irela
++)
4439 unsigned int r_type
, r_indx
;
4440 enum ppc_stub_type stub_type
;
4441 struct ppc_stub_hash_entry
*stub_entry
;
4444 bfd_vma destination
;
4445 struct ppc_link_hash_entry
*hash
;
4447 const asection
*id_sec
;
4449 r_type
= ELF64_R_TYPE (irela
->r_info
);
4450 r_indx
= ELF64_R_SYM (irela
->r_info
);
4452 if (r_type
>= (unsigned int) R_PPC_max
)
4454 bfd_set_error (bfd_error_bad_value
);
4455 goto error_ret_free_internal
;
4458 /* Only look for stubs on branch instructions. */
4459 if (r_type
!= (unsigned int) R_PPC64_REL24
4460 && r_type
!= (unsigned int) R_PPC64_REL14
4461 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
4462 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
4465 /* Now determine the call target, its name, value,
4471 if (r_indx
< symtab_hdr
->sh_info
)
4473 /* It's a local symbol. */
4474 Elf_Internal_Sym
*sym
;
4475 Elf_Internal_Shdr
*hdr
;
4477 sym
= local_syms
+ r_indx
;
4478 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4479 sym_sec
= hdr
->bfd_section
;
4480 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4481 sym_value
= sym
->st_value
;
4482 destination
= (sym_value
+ irela
->r_addend
4483 + sym_sec
->output_offset
4484 + sym_sec
->output_section
->vma
);
4488 /* It's an external symbol. */
4491 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4492 hash
= ((struct ppc_link_hash_entry
*)
4493 elf_sym_hashes (input_bfd
)[e_indx
]);
4495 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
4496 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
4497 hash
= ((struct ppc_link_hash_entry
*)
4498 hash
->elf
.root
.u
.i
.link
);
4500 if (hash
->elf
.root
.type
== bfd_link_hash_defined
4501 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
4503 sym_sec
= hash
->elf
.root
.u
.def
.section
;
4504 sym_value
= hash
->elf
.root
.u
.def
.value
;
4505 if (sym_sec
->output_section
!= NULL
)
4506 destination
= (sym_value
+ irela
->r_addend
4507 + sym_sec
->output_offset
4508 + sym_sec
->output_section
->vma
);
4510 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
4512 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
4516 bfd_set_error (bfd_error_bad_value
);
4517 goto error_ret_free_internal
;
4521 /* Determine what (if any) linker stub is needed. */
4522 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
4524 if (stub_type
== ppc_stub_none
)
4527 /* Support for grouping stub sections. */
4528 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4530 /* Get the name of this stub. */
4531 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
4533 goto error_ret_free_internal
;
4535 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4536 stub_name
, false, false);
4537 if (stub_entry
!= NULL
)
4539 /* The proper stub has already been created. */
4544 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
4545 if (stub_entry
== NULL
)
4548 goto error_ret_free_local
;
4551 stub_entry
->target_value
= sym_value
;
4552 stub_entry
->target_section
= sym_sec
;
4553 stub_entry
->stub_type
= stub_type
;
4554 stub_entry
->h
= hash
;
4555 stub_changed
= true;
4558 /* We're done with the internal relocs, free them. */
4559 free (internal_relocs
);
4566 /* OK, we've added some stubs. Find out the new size of the
4568 for (stub_sec
= htab
->stub_bfd
->sections
;
4570 stub_sec
= stub_sec
->next
)
4572 stub_sec
->_raw_size
= 0;
4573 stub_sec
->_cooked_size
= 0;
4575 htab
->sbrlt
->_raw_size
= 0;
4576 htab
->sbrlt
->_cooked_size
= 0;
4578 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
4580 /* Ask the linker to do its stuff. */
4581 (*htab
->layout_sections_again
) ();
4584 if (htab
->sbrlt
->_raw_size
== 0)
4586 _bfd_strip_section_from_output (info
, htab
->sbrlt
);
4587 if (htab
->srelbrlt
!= NULL
)
4588 _bfd_strip_section_from_output (info
, htab
->srelbrlt
);
4593 error_ret_free_local
:
4594 while (htab
->bfd_count
-- > 0)
4595 if (htab
->all_local_syms
[htab
->bfd_count
])
4596 free (htab
->all_local_syms
[htab
->bfd_count
]);
4597 free (htab
->all_local_syms
);
4602 /* Called after we have determined section placement. If sections
4603 move, we'll be called again. Provide a value for TOCstart, and
4604 store in the output bfd elf_gp. */
4607 ppc64_elf_set_toc (obfd
, info
)
4609 struct bfd_link_info
*info
;
4611 if (!info
->relocateable
)
4616 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
4617 order. The TOC starts where the first of these sections starts. */
4618 s
= bfd_get_section_by_name (obfd
, ".got");
4620 s
= bfd_get_section_by_name (obfd
, ".toc");
4622 s
= bfd_get_section_by_name (obfd
, ".tocbss");
4624 s
= bfd_get_section_by_name (obfd
, ".plt");
4627 /* This may happen for
4628 o references to TOC base (SYM@toc / TOC[tc0]) without a
4631 o --gc-sections and empty TOC sections
4633 FIXME: Warn user? */
4635 /* Look for a likely section. We probably won't even be
4637 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4638 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
4639 == (SEC_ALLOC
| SEC_SMALL_DATA
))
4642 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4643 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
4644 == (SEC_ALLOC
| SEC_SMALL_DATA
))
4647 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4648 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
4651 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4652 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
4658 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
4660 elf_gp (obfd
) = TOCstart
;
4665 /* Build all the stubs associated with the current output file.
4666 The stubs are kept in a hash table attached to the main linker
4667 hash table. This function is called via gldelf64ppc_finish. */
4670 ppc64_elf_build_stubs (info
)
4671 struct bfd_link_info
*info
;
4673 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4678 for (stub_sec
= htab
->stub_bfd
->sections
;
4680 stub_sec
= stub_sec
->next
)
4684 /* Allocate memory to hold the linker stubs. */
4685 size
= stub_sec
->_raw_size
;
4688 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
4689 if (stub_sec
->contents
== NULL
)
4692 stub_sec
->_cooked_size
= 0;
4695 if (htab
->splt
!= NULL
)
4697 /* Build the .glink plt call stub. */
4698 plt_r2
= (htab
->splt
->output_offset
4699 + htab
->splt
->output_section
->vma
4700 - elf_gp (htab
->splt
->output_section
->owner
)
4702 p
= htab
->sglink
->contents
;
4703 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
4704 while (p
- htab
->sglink
->contents
< GLINK_CALL_STUB_SIZE
)
4706 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
4709 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
4711 /* Use reloc_count to count entries. */
4712 htab
->sglink
->reloc_count
= 0;
4715 if (htab
->sbrlt
->_raw_size
!= 0)
4717 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
4718 htab
->sbrlt
->_raw_size
);
4719 if (htab
->sbrlt
->contents
== NULL
)
4723 /* Build the stubs as directed by the stub hash table. */
4724 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
4725 htab
->sglink
->reloc_count
= 0;
4727 for (stub_sec
= htab
->stub_bfd
->sections
;
4729 stub_sec
= stub_sec
->next
)
4731 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
4735 if (stub_sec
!= NULL
4736 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
4738 htab
->stub_error
= true;
4739 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
4742 return !htab
->stub_error
;
4745 /* Set up any other section flags and such that may be necessary. */
4748 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
4749 bfd
*abfd ATTRIBUTE_UNUSED
;
4750 Elf64_Internal_Shdr
*shdr
;
4753 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
4754 shdr
->sh_flags
|= SHF_EXCLUDE
;
4756 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
4757 shdr
->sh_type
= SHT_ORDERED
;
4762 /* The RELOCATE_SECTION function is called by the ELF backend linker
4763 to handle the relocations for a section.
4765 The relocs are always passed as Rela structures; if the section
4766 actually uses Rel structures, the r_addend field will always be
4769 This function is responsible for adjust the section contents as
4770 necessary, and (if using Rela relocs and generating a
4771 relocateable output file) adjusting the reloc addend as
4774 This function does not have to worry about setting the reloc
4775 address or the reloc symbol index.
4777 LOCAL_SYMS is a pointer to the swapped in local symbols.
4779 LOCAL_SECTIONS is an array giving the section in the input file
4780 corresponding to the st_shndx field of each local symbol.
4782 The global hash table entry for the global symbols can be found
4783 via elf_sym_hashes (input_bfd).
4785 When generating relocateable output, this function must handle
4786 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4787 going to be the section symbol corresponding to the output
4788 section, which means that the addend must be adjusted
4792 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4793 contents
, relocs
, local_syms
, local_sections
)
4795 struct bfd_link_info
*info
;
4797 asection
*input_section
;
4799 Elf_Internal_Rela
*relocs
;
4800 Elf_Internal_Sym
*local_syms
;
4801 asection
**local_sections
;
4803 struct ppc_link_hash_table
*htab
;
4804 Elf_Internal_Shdr
*symtab_hdr
;
4805 struct elf_link_hash_entry
**sym_hashes
;
4806 Elf_Internal_Rela
*rel
;
4807 Elf_Internal_Rela
*relend
;
4808 bfd_vma
*local_got_offsets
;
4812 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
4813 boolean is_power4
= false;
4815 /* Initialize howto table if needed. */
4816 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
4819 htab
= ppc_hash_table (info
);
4820 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4821 TOCstart
= elf_gp (output_bfd
);
4822 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4823 sym_hashes
= elf_sym_hashes (input_bfd
);
4824 is_opd
= strcmp (bfd_get_section_name (abfd
, input_section
), ".opd") == 0;
4827 relend
= relocs
+ input_section
->reloc_count
;
4828 for (; rel
< relend
; rel
++)
4830 enum elf_ppc_reloc_type r_type
;
4833 bfd_reloc_status_type r
;
4834 Elf_Internal_Sym
*sym
;
4836 struct elf_link_hash_entry
*h
;
4837 struct elf_link_hash_entry
*fdh
;
4838 const char *sym_name
;
4839 unsigned long r_symndx
;
4841 boolean unresolved_reloc
;
4843 struct ppc_stub_hash_entry
*stub_entry
;
4844 bfd_vma max_br_offset
;
4847 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
4848 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4850 if (info
->relocateable
)
4852 /* This is a relocatable link. We don't have to change
4853 anything, unless the reloc is against a section symbol,
4854 in which case we have to adjust according to where the
4855 section symbol winds up in the output section. */
4856 if (r_symndx
< symtab_hdr
->sh_info
)
4858 sym
= local_syms
+ r_symndx
;
4859 if ((unsigned) ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4861 sec
= local_sections
[r_symndx
];
4862 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
4868 /* This is a final link. */
4870 offset
= rel
->r_offset
;
4871 addend
= rel
->r_addend
;
4872 r
= bfd_reloc_other
;
4873 sym
= (Elf_Internal_Sym
*) 0;
4874 sec
= (asection
*) 0;
4875 h
= (struct elf_link_hash_entry
*) 0;
4876 sym_name
= (const char *) 0;
4877 unresolved_reloc
= false;
4879 if (r_type
== R_PPC64_TOC
)
4881 /* Relocation value is TOC base. Symbol is ignored. */
4882 relocation
= TOCstart
+ TOC_BASE_OFF
;
4884 else if (r_symndx
< symtab_hdr
->sh_info
)
4886 /* It's a local symbol. */
4887 sym
= local_syms
+ r_symndx
;
4888 sec
= local_sections
[r_symndx
];
4889 sym_name
= "<local symbol>";
4891 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4895 /* It's a global symbol. */
4896 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4897 while (h
->root
.type
== bfd_link_hash_indirect
4898 || h
->root
.type
== bfd_link_hash_warning
)
4899 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4900 sym_name
= h
->root
.root
.string
;
4902 if (h
->root
.type
== bfd_link_hash_defined
4903 || h
->root
.type
== bfd_link_hash_defweak
)
4905 sec
= h
->root
.u
.def
.section
;
4906 if (sec
->output_section
== NULL
)
4907 /* Set a flag that will be cleared later if we find a
4908 relocation value for this symbol. output_section
4909 is typically NULL for symbols satisfied by a shared
4911 unresolved_reloc
= true;
4913 relocation
= (h
->root
.u
.def
.value
4914 + sec
->output_section
->vma
4915 + sec
->output_offset
);
4917 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4919 else if (info
->shared
4920 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
4921 && !info
->no_undefined
4922 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4926 if (! ((*info
->callbacks
->undefined_symbol
)
4927 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
4928 offset
, (!info
->shared
4929 || info
->no_undefined
4930 || ELF_ST_VISIBILITY (h
->other
)))))
4935 /* First handle relocations that tweak non-addend part of insn. */
4942 /* Branch taken prediction relocations. */
4943 case R_PPC64_ADDR14_BRTAKEN
:
4944 case R_PPC64_REL14_BRTAKEN
:
4945 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
4948 /* Branch not taken prediction relocations. */
4949 case R_PPC64_ADDR14_BRNTAKEN
:
4950 case R_PPC64_REL14_BRNTAKEN
:
4951 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
4954 /* Set 'a' bit. This is 0b00010 in BO field for branch
4955 on CR(BI) insns (BO == 001at or 011at), and 0b01000
4956 for branch on CTR insns (BO == 1a00t or 1a01t). */
4957 if ((insn
& (0x14 << 21)) == (0x04 << 21))
4959 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
4966 /* Invert 'y' bit if not the default. */
4967 if ((bfd_signed_vma
) (relocation
- offset
) < 0)
4971 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
4975 /* A REL24 branching to a linkage function is followed by a
4976 nop. We replace the nop with a ld in order to restore
4977 the TOC base pointer. Only calls to shared objects need
4978 to alter the TOC base. These are recognized by their
4979 need for a PLT entry. */
4981 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
4982 && fdh
->plt
.offset
!= (bfd_vma
) -1
4983 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
4984 rel
, htab
)) != NULL
)
4986 boolean can_plt_call
= 0;
4988 if (offset
+ 8 <= input_section
->_cooked_size
)
4990 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
4992 || insn
== CROR_151515
|| insn
== CROR_313131
)
4994 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
4995 contents
+ offset
+ 4);
5002 /* If this is a plain branch rather than a branch
5003 and link, don't require a nop. */
5004 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5005 if ((insn
& 1) == 0)
5011 relocation
= (stub_entry
->stub_offset
5012 + stub_entry
->stub_sec
->output_offset
5013 + stub_entry
->stub_sec
->output_section
->vma
);
5015 unresolved_reloc
= false;
5020 && h
->root
.type
== bfd_link_hash_undefweak
5024 /* Tweak calls to undefined weak functions to point at a
5025 blr. We can thus call a weak function without first
5026 checking whether the function is defined. We have a
5027 blr at the end of .sfpr. */
5028 relocation
= (htab
->sfpr
->_raw_size
- 4
5029 + htab
->sfpr
->output_offset
5030 + htab
->sfpr
->output_section
->vma
);
5032 + input_section
->output_offset
5033 + input_section
->output_section
->vma
);
5034 /* But let's not be silly about it. If the blr isn't in
5035 reach, just go to the next instruction. */
5036 if (relocation
- from
+ (1 << 25) >= (1 << 26))
5037 relocation
= from
+ 4;
5046 (*_bfd_error_handler
)
5047 (_("%s: unknown relocation type %d for symbol %s"),
5048 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5050 bfd_set_error (bfd_error_bad_value
);
5055 case R_PPC_GNU_VTINHERIT
:
5056 case R_PPC_GNU_VTENTRY
:
5059 /* GOT16 relocations. Like an ADDR16 using the symbol's
5060 address in the GOT as relocation value instead of the
5061 symbols value itself. Also, create a GOT entry for the
5062 symbol and put the symbol value there. */
5064 case R_PPC64_GOT16_LO
:
5065 case R_PPC64_GOT16_HI
:
5066 case R_PPC64_GOT16_HA
:
5067 case R_PPC64_GOT16_DS
:
5068 case R_PPC64_GOT16_LO_DS
:
5070 /* Relocation is to the entry for this symbol in the global
5074 if (htab
->sgot
== NULL
)
5081 off
= h
->got
.offset
;
5082 dyn
= htab
->elf
.dynamic_sections_created
;
5083 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5087 || (h
->elf_link_hash_flags
5088 & ELF_LINK_FORCED_LOCAL
))
5089 && (h
->elf_link_hash_flags
5090 & ELF_LINK_HASH_DEF_REGULAR
)))
5092 /* This is actually a static link, or it is a
5093 -Bsymbolic link and the symbol is defined
5094 locally, or the symbol was forced to be local
5095 because of a version file. We must initialize
5096 this entry in the global offset table. Since the
5097 offset must always be a multiple of 8, we use the
5098 least significant bit to record whether we have
5099 initialized it already.
5101 When doing a dynamic link, we create a .rel.got
5102 relocation entry to initialize the value. This
5103 is done in the finish_dynamic_symbol routine. */
5108 bfd_put_64 (output_bfd
, relocation
,
5109 htab
->sgot
->contents
+ off
);
5114 unresolved_reloc
= false;
5118 if (local_got_offsets
== NULL
)
5121 off
= local_got_offsets
[r_symndx
];
5123 /* The offset must always be a multiple of 8. We use
5124 the least significant bit to record whether we have
5125 already processed this entry. */
5130 bfd_put_64 (output_bfd
, relocation
,
5131 htab
->sgot
->contents
+ off
);
5135 Elf_Internal_Rela outrel
;
5136 Elf64_External_Rela
*loc
;
5138 /* We need to generate a R_PPC64_RELATIVE reloc
5139 for the dynamic linker. */
5140 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5141 + htab
->sgot
->output_offset
5143 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5144 outrel
.r_addend
= relocation
;
5145 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5146 loc
+= htab
->srelgot
->reloc_count
++;
5147 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5150 local_got_offsets
[r_symndx
] |= 1;
5154 if (off
>= (bfd_vma
) -2)
5157 relocation
= htab
->sgot
->output_offset
+ off
;
5159 /* TOC base (r2) is TOC start plus 0x8000. */
5160 addend
-= TOC_BASE_OFF
;
5164 case R_PPC64_PLT16_HA
:
5165 case R_PPC64_PLT16_HI
:
5166 case R_PPC64_PLT16_LO
:
5169 /* Relocation is to the entry for this symbol in the
5170 procedure linkage table. */
5172 /* Resolve a PLT reloc against a local symbol directly,
5173 without using the procedure linkage table. */
5177 if (h
->plt
.offset
== (bfd_vma
) -1
5178 || htab
->splt
== NULL
)
5180 /* We didn't make a PLT entry for this symbol. This
5181 happens when statically linking PIC code, or when
5182 using -Bsymbolic. */
5186 relocation
= (htab
->splt
->output_section
->vma
5187 + htab
->splt
->output_offset
5189 unresolved_reloc
= false;
5192 /* TOC16 relocs. We want the offset relative to the TOC base,
5193 which is the address of the start of the TOC plus 0x8000.
5194 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5197 case R_PPC64_TOC16_LO
:
5198 case R_PPC64_TOC16_HI
:
5199 case R_PPC64_TOC16_DS
:
5200 case R_PPC64_TOC16_LO_DS
:
5201 case R_PPC64_TOC16_HA
:
5202 addend
-= TOCstart
+ TOC_BASE_OFF
;
5205 /* Relocate against the beginning of the section. */
5206 case R_PPC64_SECTOFF
:
5207 case R_PPC64_SECTOFF_LO
:
5208 case R_PPC64_SECTOFF_HI
:
5209 case R_PPC64_SECTOFF_DS
:
5210 case R_PPC64_SECTOFF_LO_DS
:
5211 case R_PPC64_SECTOFF_HA
:
5212 if (sec
!= (asection
*) 0)
5213 addend
-= sec
->output_section
->vma
;
5217 case R_PPC64_REL14_BRNTAKEN
:
5218 case R_PPC64_REL14_BRTAKEN
:
5222 /* Relocations that may need to be propagated if this is a
5226 case R_PPC64_ADDR14
:
5227 case R_PPC64_ADDR14_BRNTAKEN
:
5228 case R_PPC64_ADDR14_BRTAKEN
:
5229 case R_PPC64_ADDR16
:
5230 case R_PPC64_ADDR16_DS
:
5231 case R_PPC64_ADDR16_HA
:
5232 case R_PPC64_ADDR16_HI
:
5233 case R_PPC64_ADDR16_HIGHER
:
5234 case R_PPC64_ADDR16_HIGHERA
:
5235 case R_PPC64_ADDR16_HIGHEST
:
5236 case R_PPC64_ADDR16_HIGHESTA
:
5237 case R_PPC64_ADDR16_LO
:
5238 case R_PPC64_ADDR16_LO_DS
:
5239 case R_PPC64_ADDR24
:
5240 case R_PPC64_ADDR30
:
5241 case R_PPC64_ADDR32
:
5242 case R_PPC64_ADDR64
:
5243 case R_PPC64_UADDR16
:
5244 case R_PPC64_UADDR32
:
5245 case R_PPC64_UADDR64
:
5246 /* r_symndx will be zero only for relocs against symbols
5247 from removed linkonce sections, or sections discarded by
5254 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5257 if (NO_OPD_RELOCS
&& is_opd
)
5261 && (IS_ABSOLUTE_RELOC (r_type
)
5264 && (! info
->symbolic
5265 || (h
->elf_link_hash_flags
5266 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5270 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5271 && (((h
->elf_link_hash_flags
5272 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5273 && (h
->elf_link_hash_flags
5274 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5275 || h
->root
.type
== bfd_link_hash_undefweak
5276 || h
->root
.type
== bfd_link_hash_undefined
)))
5278 Elf_Internal_Rela outrel
;
5279 boolean skip
, relocate
;
5281 Elf64_External_Rela
*loc
;
5283 /* When generating a dynamic object, these relocations
5284 are copied into the output file to be resolved at run
5291 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5293 if (outrel
.r_offset
== (bfd_vma
) -1)
5295 else if (outrel
.r_offset
== (bfd_vma
) -2)
5296 skip
= true, relocate
= true;
5297 outrel
.r_offset
+= (input_section
->output_section
->vma
5298 + input_section
->output_offset
);
5299 outrel
.r_addend
= addend
;
5302 memset (&outrel
, 0, sizeof outrel
);
5306 && (!IS_ABSOLUTE_RELOC (r_type
)
5309 || (h
->elf_link_hash_flags
5310 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5311 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5314 /* This symbol is local, or marked to become local,
5315 or this is an opd section reloc which must point
5316 at a local function. */
5317 outrel
.r_addend
+= relocation
;
5319 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5321 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5327 if (bfd_is_abs_section (sec
))
5329 else if (sec
== NULL
|| sec
->owner
== NULL
)
5331 bfd_set_error (bfd_error_bad_value
);
5338 osec
= sec
->output_section
;
5339 indx
= elf_section_data (osec
)->dynindx
;
5341 /* We are turning this relocation into one
5342 against a section symbol, so subtract out
5343 the output section's address but not the
5344 offset of the input section in the output
5346 outrel
.r_addend
-= osec
->vma
;
5349 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
5353 sreloc
= elf_section_data (input_section
)->sreloc
;
5357 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
5358 loc
+= sreloc
->reloc_count
++;
5359 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5361 /* If this reloc is against an external symbol, it will
5362 be computed at runtime, so there's no need to do
5370 case R_PPC64_GLOB_DAT
:
5371 case R_PPC64_JMP_SLOT
:
5372 case R_PPC64_RELATIVE
:
5373 /* We shouldn't ever see these dynamic relocs in relocatable
5377 case R_PPC64_PLTGOT16
:
5378 case R_PPC64_PLTGOT16_DS
:
5379 case R_PPC64_PLTGOT16_HA
:
5380 case R_PPC64_PLTGOT16_HI
:
5381 case R_PPC64_PLTGOT16_LO
:
5382 case R_PPC64_PLTGOT16_LO_DS
:
5383 case R_PPC64_PLTREL32
:
5384 case R_PPC64_PLTREL64
:
5385 /* These ones haven't been implemented yet. */
5387 (*_bfd_error_handler
)
5388 (_("%s: Relocation %s is not supported for symbol %s."),
5389 bfd_archive_filename (input_bfd
),
5390 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
5392 bfd_set_error (bfd_error_invalid_operation
);
5397 /* Do any further special processing. */
5403 case R_PPC64_ADDR16_HA
:
5404 case R_PPC64_ADDR16_HIGHERA
:
5405 case R_PPC64_ADDR16_HIGHESTA
:
5406 case R_PPC64_PLT16_HA
:
5407 case R_PPC64_TOC16_HA
:
5408 case R_PPC64_SECTOFF_HA
:
5409 /* It's just possible that this symbol is a weak symbol
5410 that's not actually defined anywhere. In that case,
5411 'sec' would be NULL, and we should leave the symbol
5412 alone (it will be set to zero elsewhere in the link). */
5414 /* Add 0x10000 if sign bit in 0:15 is set. */
5415 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
5418 case R_PPC64_ADDR16_DS
:
5419 case R_PPC64_ADDR16_LO_DS
:
5420 case R_PPC64_GOT16_DS
:
5421 case R_PPC64_GOT16_LO_DS
:
5422 case R_PPC64_PLT16_LO_DS
:
5423 case R_PPC64_SECTOFF_DS
:
5424 case R_PPC64_SECTOFF_LO_DS
:
5425 case R_PPC64_TOC16_DS
:
5426 case R_PPC64_TOC16_LO_DS
:
5427 case R_PPC64_PLTGOT16_DS
:
5428 case R_PPC64_PLTGOT16_LO_DS
:
5429 if (((relocation
+ addend
) & 3) != 0)
5431 (*_bfd_error_handler
)
5432 (_("%s: error: relocation %s not a multiple of 4"),
5433 bfd_archive_filename (input_bfd
),
5434 ppc64_elf_howto_table
[(int) r_type
]->name
);
5435 bfd_set_error (bfd_error_bad_value
);
5442 case R_PPC64_REL14_BRNTAKEN
:
5443 case R_PPC64_REL14_BRTAKEN
:
5444 max_br_offset
= 1 << 15;
5448 max_br_offset
= 1 << 25;
5451 /* If the branch is out of reach, then redirect the
5452 call to the local stub for this function. */
5454 + input_section
->output_offset
5455 + input_section
->output_section
->vma
);
5456 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
5457 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
5458 rel
, htab
)) != NULL
)
5460 /* Munge up the value and addend so that we call the stub
5461 rather than the procedure directly. */
5462 relocation
= (stub_entry
->stub_offset
5463 + stub_entry
->stub_sec
->output_offset
5464 + stub_entry
->stub_sec
->output_section
->vma
);
5470 /* FIXME: Why do we allow debugging sections to escape this error?
5471 More importantly, why do we not emit dynamic relocs above in
5472 debugging sections (which are ! SEC_ALLOC)? If we had
5473 emitted the dynamic reloc, we could remove the fudge here. */
5474 if (unresolved_reloc
5476 && (input_section
->flags
& SEC_DEBUGGING
) != 0
5477 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5478 (*_bfd_error_handler
)
5479 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5480 bfd_archive_filename (input_bfd
),
5481 bfd_get_section_name (input_bfd
, input_section
),
5482 (long) rel
->r_offset
,
5483 h
->root
.root
.string
);
5485 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
5493 if (r
== bfd_reloc_ok
)
5495 else if (r
== bfd_reloc_overflow
)
5501 if (h
->root
.type
== bfd_link_hash_undefweak
5502 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
5504 /* Assume this is a call protected by other code that
5505 detects the symbol is undefined. If this is the case,
5506 we can safely ignore the overflow. If not, the
5507 program is hosed anyway, and a little warning isn't
5513 name
= h
->root
.root
.string
;
5517 name
= bfd_elf_string_from_elf_section (input_bfd
,
5518 symtab_hdr
->sh_link
,
5523 name
= bfd_section_name (input_bfd
, sec
);
5526 if (! ((*info
->callbacks
->reloc_overflow
)
5527 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
5528 (bfd_vma
) 0, input_bfd
, input_section
, offset
)))
5538 /* Finish up dynamic symbol handling. We set the contents of various
5539 dynamic sections here. */
5542 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5544 struct bfd_link_info
*info
;
5545 struct elf_link_hash_entry
*h
;
5546 Elf_Internal_Sym
*sym
;
5548 struct ppc_link_hash_table
*htab
;
5551 htab
= ppc_hash_table (info
);
5552 dynobj
= htab
->elf
.dynobj
;
5554 if (h
->plt
.offset
!= (bfd_vma
) -1
5555 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
5557 Elf_Internal_Rela rela
;
5558 Elf64_External_Rela
*loc
;
5560 /* This symbol has an entry in the procedure linkage table. Set
5563 if (htab
->splt
== NULL
5564 || htab
->srelplt
== NULL
5565 || htab
->sglink
== NULL
)
5568 /* Create a JMP_SLOT reloc to inform the dynamic linker to
5569 fill in the PLT entry. */
5571 rela
.r_offset
= (htab
->splt
->output_section
->vma
5572 + htab
->splt
->output_offset
5574 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
5577 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
5578 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
5579 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
5582 if (h
->got
.offset
!= (bfd_vma
) -1)
5584 Elf_Internal_Rela rela
;
5585 Elf64_External_Rela
*loc
;
5587 /* This symbol has an entry in the global offset table. Set it
5590 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
5593 rela
.r_offset
= (htab
->sgot
->output_section
->vma
5594 + htab
->sgot
->output_offset
5595 + (h
->got
.offset
&~ (bfd_vma
) 1));
5597 /* If this is a static link, or it is a -Bsymbolic link and the
5598 symbol is defined locally or was forced to be local because
5599 of a version file, we just want to emit a RELATIVE reloc.
5600 The entry in the global offset table will already have been
5601 initialized in the relocate_section function. */
5605 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
5606 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
5608 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5609 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5610 rela
.r_addend
= (h
->root
.u
.def
.value
5611 + h
->root
.u
.def
.section
->output_section
->vma
5612 + h
->root
.u
.def
.section
->output_offset
);
5616 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
5617 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5618 htab
->sgot
->contents
+ h
->got
.offset
);
5619 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
5623 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5624 loc
+= htab
->srelgot
->reloc_count
++;
5625 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
5628 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
5630 Elf_Internal_Rela rela
;
5631 Elf64_External_Rela
*loc
;
5633 /* This symbol needs a copy reloc. Set it up. */
5635 if (h
->dynindx
== -1
5636 || (h
->root
.type
!= bfd_link_hash_defined
5637 && h
->root
.type
!= bfd_link_hash_defweak
)
5638 || htab
->srelbss
== NULL
)
5641 rela
.r_offset
= (h
->root
.u
.def
.value
5642 + h
->root
.u
.def
.section
->output_section
->vma
5643 + h
->root
.u
.def
.section
->output_offset
);
5644 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
5646 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
5647 loc
+= htab
->srelbss
->reloc_count
++;
5648 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
5651 /* Mark some specially defined symbols as absolute. */
5652 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
5653 sym
->st_shndx
= SHN_ABS
;
5658 /* Used to decide how to sort relocs in an optimal manner for the
5659 dynamic linker, before writing them out. */
5661 static enum elf_reloc_type_class
5662 ppc64_elf_reloc_type_class (rela
)
5663 const Elf_Internal_Rela
*rela
;
5665 enum elf_ppc_reloc_type r_type
;
5667 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
5670 case R_PPC64_RELATIVE
:
5671 return reloc_class_relative
;
5672 case R_PPC64_JMP_SLOT
:
5673 return reloc_class_plt
;
5675 return reloc_class_copy
;
5677 return reloc_class_normal
;
5681 /* Finish up the dynamic sections. */
5684 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
5686 struct bfd_link_info
*info
;
5688 struct ppc_link_hash_table
*htab
;
5692 htab
= ppc_hash_table (info
);
5693 dynobj
= htab
->elf
.dynobj
;
5694 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5696 if (htab
->elf
.dynamic_sections_created
)
5698 Elf64_External_Dyn
*dyncon
, *dynconend
;
5700 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
5703 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
5704 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5705 for (; dyncon
< dynconend
; dyncon
++)
5707 Elf_Internal_Dyn dyn
;
5710 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5717 case DT_PPC64_GLINK
:
5718 dyn
.d_un
.d_ptr
= (htab
->sglink
->output_section
->vma
5719 + htab
->sglink
->output_offset
);
5723 s
= bfd_get_section_by_name (output_bfd
, ".opd");
5725 dyn
.d_un
.d_ptr
= s
->vma
;
5728 case DT_PPC64_OPDSZ
:
5729 s
= bfd_get_section_by_name (output_bfd
, ".opd");
5731 dyn
.d_un
.d_val
= s
->_raw_size
;
5735 dyn
.d_un
.d_ptr
= (htab
->splt
->output_section
->vma
5736 + htab
->splt
->output_offset
);
5740 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
5741 + htab
->srelplt
->output_offset
);
5745 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
5749 /* Don't count procedure linkage table relocs in the
5750 overall reloc count. */
5751 if (htab
->srelplt
!= NULL
)
5752 dyn
.d_un
.d_val
-= htab
->srelplt
->_raw_size
;
5756 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5760 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
5762 /* Fill in the first entry in the global offset table.
5763 We use it to hold the link-time TOCbase. */
5764 bfd_put_64 (output_bfd
,
5765 elf_gp (output_bfd
) + TOC_BASE_OFF
,
5766 htab
->sgot
->contents
);
5768 /* Set .got entry size. */
5769 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
5772 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
5774 /* Set .plt entry size. */
5775 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
5782 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
5783 #define TARGET_LITTLE_NAME "elf64-powerpcle"
5784 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
5785 #define TARGET_BIG_NAME "elf64-powerpc"
5786 #define ELF_ARCH bfd_arch_powerpc
5787 #define ELF_MACHINE_CODE EM_PPC64
5788 #define ELF_MAXPAGESIZE 0x10000
5789 #define elf_info_to_howto ppc64_elf_info_to_howto
5791 #ifdef EM_CYGNUS_POWERPC
5792 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
5796 #define ELF_MACHINE_ALT2 EM_PPC_OLD
5799 #define elf_backend_want_got_sym 0
5800 #define elf_backend_want_plt_sym 0
5801 #define elf_backend_plt_alignment 3
5802 #define elf_backend_plt_not_loaded 1
5803 #define elf_backend_got_symbol_offset 0
5804 #define elf_backend_got_header_size 8
5805 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
5806 #define elf_backend_can_gc_sections 1
5807 #define elf_backend_can_refcount 1
5809 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
5810 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
5811 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
5812 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
5813 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
5815 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
5816 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
5817 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
5818 #define elf_backend_check_relocs ppc64_elf_check_relocs
5819 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
5820 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
5821 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
5822 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
5823 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
5824 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
5825 #define elf_backend_fake_sections ppc64_elf_fake_sections
5826 #define elf_backend_relocate_section ppc64_elf_relocate_section
5827 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
5828 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
5829 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
5831 #include "elf64-target.h"