1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
31 #include "elf64-ppc.h"
33 #define USE_RELA /* we want RELA relocations, not REL. */
36 static void ppc_howto_init
38 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
39 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
40 static void ppc64_elf_info_to_howto
41 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf64_Internal_Rela
*dst
));
42 static bfd_reloc_status_type ppc64_elf_ha_reloc
43 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
44 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
47 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
48 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
49 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
50 static bfd_reloc_status_type ppc64_elf_toc_reloc
51 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
52 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
53 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
54 static bfd_reloc_status_type ppc64_elf_toc64_reloc
55 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
56 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
58 static boolean ppc64_elf_object_p
60 static boolean ppc64_elf_merge_private_bfd_data
61 PARAMS ((bfd
*, bfd
*));
64 /* The name of the dynamic interpreter. This is put in the .interp
66 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
68 /* The size in bytes of an entry in the procedure linkage table. */
69 #define PLT_ENTRY_SIZE 24
71 /* The initial size of the plt reserved for the dynamic linker. */
72 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
74 /* TOC base pointers offset from start of TOC. */
75 #define TOC_BASE_OFF (0x8000)
77 /* .plt call stub instructions. */
78 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
79 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
80 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
81 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
82 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
83 /* ld %r11,xxx+16@l(%r12) */
84 #define BCTR 0x4e800420 /* bctr */
86 /* The normal stub is this size. */
87 #define PLT_CALL_STUB_SIZE (7*4)
89 /* But sometimes the .plt entry crosses a 64k boundary, and we need
90 to adjust the high word with this insn. */
91 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
93 /* The .glink fixup call stub is the same as the .plt call stub, but
94 the first instruction restores r2, and the std is omitted. */
95 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
97 /* Always allow this much space. */
98 #define GLINK_CALL_STUB_SIZE (8*4)
101 #define NOP 0x60000000
103 /* Some other nops. */
104 #define CROR_151515 0x4def7b82
105 #define CROR_313131 0x4ffffb82
107 /* .glink entries for the first 32k functions are two instructions. */
108 #define LI_R0_0 0x38000000 /* li %r0,0 */
109 #define B_DOT 0x48000000 /* b . */
111 /* After that, we need two instructions to load the index, followed by
113 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
114 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
116 /* Instructions to save and restore floating point regs. */
117 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
118 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
119 #define BLR 0x4e800020 /* blr */
121 /* Since .opd is an array of descriptors and each entry will end up
122 with identical R_PPC64_RELATIVE relocs, there is really no need to
123 propagate .opd relocs; The dynamic linker should be taught to
124 relocate .opd without reloc entries. */
125 #ifndef NO_OPD_RELOCS
126 #define NO_OPD_RELOCS 0
129 /* Relocation HOWTO's. */
130 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
132 static reloc_howto_type ppc64_elf_howto_raw
[] = {
133 /* This reloc does nothing. */
134 HOWTO (R_PPC64_NONE
, /* type */
136 2, /* size (0 = byte, 1 = short, 2 = long) */
138 false, /* pc_relative */
140 complain_overflow_bitfield
, /* complain_on_overflow */
141 bfd_elf_generic_reloc
, /* special_function */
142 "R_PPC64_NONE", /* name */
143 false, /* partial_inplace */
146 false), /* pcrel_offset */
148 /* A standard 32 bit relocation. */
149 HOWTO (R_PPC64_ADDR32
, /* type */
151 2, /* size (0 = byte, 1 = short, 2 = long) */
153 false, /* pc_relative */
155 complain_overflow_bitfield
, /* complain_on_overflow */
156 bfd_elf_generic_reloc
, /* special_function */
157 "R_PPC64_ADDR32", /* name */
158 false, /* partial_inplace */
160 0xffffffff, /* dst_mask */
161 false), /* pcrel_offset */
163 /* An absolute 26 bit branch; the lower two bits must be zero.
164 FIXME: we don't check that, we just clear them. */
165 HOWTO (R_PPC64_ADDR24
, /* type */
167 2, /* size (0 = byte, 1 = short, 2 = long) */
169 false, /* pc_relative */
171 complain_overflow_bitfield
, /* complain_on_overflow */
172 bfd_elf_generic_reloc
, /* special_function */
173 "R_PPC64_ADDR24", /* name */
174 false, /* partial_inplace */
176 0x3fffffc, /* dst_mask */
177 false), /* pcrel_offset */
179 /* A standard 16 bit relocation. */
180 HOWTO (R_PPC64_ADDR16
, /* type */
182 1, /* size (0 = byte, 1 = short, 2 = long) */
184 false, /* pc_relative */
186 complain_overflow_bitfield
, /* complain_on_overflow */
187 bfd_elf_generic_reloc
, /* special_function */
188 "R_PPC64_ADDR16", /* name */
189 false, /* partial_inplace */
191 0xffff, /* dst_mask */
192 false), /* pcrel_offset */
194 /* A 16 bit relocation without overflow. */
195 HOWTO (R_PPC64_ADDR16_LO
, /* type */
197 1, /* size (0 = byte, 1 = short, 2 = long) */
199 false, /* pc_relative */
201 complain_overflow_dont
,/* complain_on_overflow */
202 bfd_elf_generic_reloc
, /* special_function */
203 "R_PPC64_ADDR16_LO", /* name */
204 false, /* partial_inplace */
206 0xffff, /* dst_mask */
207 false), /* pcrel_offset */
209 /* Bits 16-31 of an address. */
210 HOWTO (R_PPC64_ADDR16_HI
, /* type */
212 1, /* size (0 = byte, 1 = short, 2 = long) */
214 false, /* pc_relative */
216 complain_overflow_dont
, /* complain_on_overflow */
217 bfd_elf_generic_reloc
, /* special_function */
218 "R_PPC64_ADDR16_HI", /* name */
219 false, /* partial_inplace */
221 0xffff, /* dst_mask */
222 false), /* pcrel_offset */
224 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
225 bits, treated as a signed number, is negative. */
226 HOWTO (R_PPC64_ADDR16_HA
, /* type */
228 1, /* size (0 = byte, 1 = short, 2 = long) */
230 false, /* pc_relative */
232 complain_overflow_dont
, /* complain_on_overflow */
233 ppc64_elf_ha_reloc
, /* special_function */
234 "R_PPC64_ADDR16_HA", /* name */
235 false, /* partial_inplace */
237 0xffff, /* dst_mask */
238 false), /* pcrel_offset */
240 /* An absolute 16 bit branch; the lower two bits must be zero.
241 FIXME: we don't check that, we just clear them. */
242 HOWTO (R_PPC64_ADDR14
, /* type */
244 2, /* size (0 = byte, 1 = short, 2 = long) */
246 false, /* pc_relative */
248 complain_overflow_bitfield
, /* complain_on_overflow */
249 bfd_elf_generic_reloc
, /* special_function */
250 "R_PPC64_ADDR14", /* name */
251 false, /* partial_inplace */
253 0xfffc, /* dst_mask */
254 false), /* pcrel_offset */
256 /* An absolute 16 bit branch, for which bit 10 should be set to
257 indicate that the branch is expected to be taken. The lower two
258 bits must be zero. */
259 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 false, /* pc_relative */
265 complain_overflow_bitfield
, /* complain_on_overflow */
266 ppc64_elf_brtaken_reloc
, /* special_function */
267 "R_PPC64_ADDR14_BRTAKEN",/* name */
268 false, /* partial_inplace */
270 0xfffc, /* dst_mask */
271 false), /* pcrel_offset */
273 /* An absolute 16 bit branch, for which bit 10 should be set to
274 indicate that the branch is not expected to be taken. The lower
275 two bits must be zero. */
276 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
278 2, /* size (0 = byte, 1 = short, 2 = long) */
280 false, /* pc_relative */
282 complain_overflow_bitfield
, /* complain_on_overflow */
283 ppc64_elf_brtaken_reloc
, /* special_function */
284 "R_PPC64_ADDR14_BRNTAKEN",/* name */
285 false, /* partial_inplace */
287 0xfffc, /* dst_mask */
288 false), /* pcrel_offset */
290 /* A relative 26 bit branch; the lower two bits must be zero. */
291 HOWTO (R_PPC64_REL24
, /* type */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
295 true, /* pc_relative */
297 complain_overflow_signed
, /* complain_on_overflow */
298 bfd_elf_generic_reloc
, /* special_function */
299 "R_PPC64_REL24", /* name */
300 false, /* partial_inplace */
302 0x3fffffc, /* dst_mask */
303 true), /* pcrel_offset */
305 /* A relative 16 bit branch; the lower two bits must be zero. */
306 HOWTO (R_PPC64_REL14
, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 true, /* pc_relative */
312 complain_overflow_signed
, /* complain_on_overflow */
313 bfd_elf_generic_reloc
, /* special_function */
314 "R_PPC64_REL14", /* name */
315 false, /* partial_inplace */
317 0xfffc, /* dst_mask */
318 true), /* pcrel_offset */
320 /* A relative 16 bit branch. Bit 10 should be set to indicate that
321 the branch is expected to be taken. The lower two bits must be
323 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
327 true, /* pc_relative */
329 complain_overflow_signed
, /* complain_on_overflow */
330 ppc64_elf_brtaken_reloc
, /* special_function */
331 "R_PPC64_REL14_BRTAKEN", /* name */
332 false, /* partial_inplace */
334 0xfffc, /* dst_mask */
335 true), /* pcrel_offset */
337 /* A relative 16 bit branch. Bit 10 should be set to indicate that
338 the branch is not expected to be taken. The lower two bits must
340 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
342 2, /* size (0 = byte, 1 = short, 2 = long) */
344 true, /* pc_relative */
346 complain_overflow_signed
, /* complain_on_overflow */
347 ppc64_elf_brtaken_reloc
, /* special_function */
348 "R_PPC64_REL14_BRNTAKEN",/* name */
349 false, /* partial_inplace */
351 0xfffc, /* dst_mask */
352 true), /* pcrel_offset */
354 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
356 HOWTO (R_PPC64_GOT16
, /* type */
358 1, /* size (0 = byte, 1 = short, 2 = long) */
360 false, /* pc_relative */
362 complain_overflow_signed
, /* complain_on_overflow */
363 ppc64_elf_unhandled_reloc
, /* special_function */
364 "R_PPC64_GOT16", /* name */
365 false, /* partial_inplace */
367 0xffff, /* dst_mask */
368 false), /* pcrel_offset */
370 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
372 HOWTO (R_PPC64_GOT16_LO
, /* type */
374 1, /* size (0 = byte, 1 = short, 2 = long) */
376 false, /* pc_relative */
378 complain_overflow_dont
, /* complain_on_overflow */
379 ppc64_elf_unhandled_reloc
, /* special_function */
380 "R_PPC64_GOT16_LO", /* name */
381 false, /* partial_inplace */
383 0xffff, /* dst_mask */
384 false), /* pcrel_offset */
386 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
388 HOWTO (R_PPC64_GOT16_HI
, /* type */
390 1, /* size (0 = byte, 1 = short, 2 = long) */
392 false, /* pc_relative */
394 complain_overflow_dont
,/* complain_on_overflow */
395 ppc64_elf_unhandled_reloc
, /* special_function */
396 "R_PPC64_GOT16_HI", /* name */
397 false, /* partial_inplace */
399 0xffff, /* dst_mask */
400 false), /* pcrel_offset */
402 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
404 HOWTO (R_PPC64_GOT16_HA
, /* type */
406 1, /* size (0 = byte, 1 = short, 2 = long) */
408 false, /* pc_relative */
410 complain_overflow_dont
,/* complain_on_overflow */
411 ppc64_elf_unhandled_reloc
, /* special_function */
412 "R_PPC64_GOT16_HA", /* name */
413 false, /* partial_inplace */
415 0xffff, /* dst_mask */
416 false), /* pcrel_offset */
418 /* This is used only by the dynamic linker. The symbol should exist
419 both in the object being run and in some shared library. The
420 dynamic linker copies the data addressed by the symbol from the
421 shared library into the object, because the object being
422 run has to have the data at some particular address. */
423 HOWTO (R_PPC64_COPY
, /* type */
425 2, /* size (0 = byte, 1 = short, 2 = long) */
427 false, /* pc_relative */
429 complain_overflow_bitfield
, /* complain_on_overflow */
430 ppc64_elf_unhandled_reloc
, /* special_function */
431 "R_PPC64_COPY", /* name */
432 false, /* partial_inplace */
435 false), /* pcrel_offset */
437 /* Like R_PPC64_ADDR64, but used when setting global offset table
439 HOWTO (R_PPC64_GLOB_DAT
, /* type */
441 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
443 false, /* pc_relative */
445 complain_overflow_dont
, /* complain_on_overflow */
446 ppc64_elf_unhandled_reloc
, /* special_function */
447 "R_PPC64_GLOB_DAT", /* name */
448 false, /* partial_inplace */
450 0xffffffffffffffff, /* dst_mask */
451 false), /* pcrel_offset */
453 /* Created by the link editor. Marks a procedure linkage table
454 entry for a symbol. */
455 HOWTO (R_PPC64_JMP_SLOT
, /* type */
457 0, /* size (0 = byte, 1 = short, 2 = long) */
459 false, /* pc_relative */
461 complain_overflow_dont
, /* complain_on_overflow */
462 ppc64_elf_unhandled_reloc
, /* special_function */
463 "R_PPC64_JMP_SLOT", /* name */
464 false, /* partial_inplace */
467 false), /* pcrel_offset */
469 /* Used only by the dynamic linker. When the object is run, this
470 doubleword64 is set to the load address of the object, plus the
472 HOWTO (R_PPC64_RELATIVE
, /* type */
474 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
476 false, /* pc_relative */
478 complain_overflow_dont
, /* complain_on_overflow */
479 bfd_elf_generic_reloc
, /* special_function */
480 "R_PPC64_RELATIVE", /* name */
481 false, /* partial_inplace */
483 0xffffffffffffffff, /* dst_mask */
484 false), /* pcrel_offset */
486 /* Like R_PPC64_ADDR32, but may be unaligned. */
487 HOWTO (R_PPC64_UADDR32
, /* type */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
491 false, /* pc_relative */
493 complain_overflow_bitfield
, /* complain_on_overflow */
494 bfd_elf_generic_reloc
, /* special_function */
495 "R_PPC64_UADDR32", /* name */
496 false, /* partial_inplace */
498 0xffffffff, /* dst_mask */
499 false), /* pcrel_offset */
501 /* Like R_PPC64_ADDR16, but may be unaligned. */
502 HOWTO (R_PPC64_UADDR16
, /* type */
504 1, /* size (0 = byte, 1 = short, 2 = long) */
506 false, /* pc_relative */
508 complain_overflow_bitfield
, /* complain_on_overflow */
509 bfd_elf_generic_reloc
, /* special_function */
510 "R_PPC64_UADDR16", /* name */
511 false, /* partial_inplace */
513 0xffff, /* dst_mask */
514 false), /* pcrel_offset */
516 /* 32-bit PC relative. */
517 HOWTO (R_PPC64_REL32
, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 true, /* pc_relative */
523 /* FIXME: Verify. Was complain_overflow_bitfield. */
524 complain_overflow_signed
, /* complain_on_overflow */
525 bfd_elf_generic_reloc
, /* special_function */
526 "R_PPC64_REL32", /* name */
527 false, /* partial_inplace */
529 0xffffffff, /* dst_mask */
530 true), /* pcrel_offset */
532 /* 32-bit relocation to the symbol's procedure linkage table. */
533 HOWTO (R_PPC64_PLT32
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 false, /* pc_relative */
539 complain_overflow_bitfield
, /* complain_on_overflow */
540 ppc64_elf_unhandled_reloc
, /* special_function */
541 "R_PPC64_PLT32", /* name */
542 false, /* partial_inplace */
545 false), /* pcrel_offset */
547 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
548 FIXME: R_PPC64_PLTREL32 not supported. */
549 HOWTO (R_PPC64_PLTREL32
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 true, /* pc_relative */
555 complain_overflow_signed
, /* complain_on_overflow */
556 bfd_elf_generic_reloc
, /* special_function */
557 "R_PPC64_PLTREL32", /* name */
558 false, /* partial_inplace */
561 true), /* pcrel_offset */
563 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
565 HOWTO (R_PPC64_PLT16_LO
, /* type */
567 1, /* size (0 = byte, 1 = short, 2 = long) */
569 false, /* pc_relative */
571 complain_overflow_dont
, /* complain_on_overflow */
572 ppc64_elf_unhandled_reloc
, /* special_function */
573 "R_PPC64_PLT16_LO", /* name */
574 false, /* partial_inplace */
576 0xffff, /* dst_mask */
577 false), /* pcrel_offset */
579 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
581 HOWTO (R_PPC64_PLT16_HI
, /* type */
583 1, /* size (0 = byte, 1 = short, 2 = long) */
585 false, /* pc_relative */
587 complain_overflow_dont
, /* complain_on_overflow */
588 ppc64_elf_unhandled_reloc
, /* special_function */
589 "R_PPC64_PLT16_HI", /* name */
590 false, /* partial_inplace */
592 0xffff, /* dst_mask */
593 false), /* pcrel_offset */
595 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
597 HOWTO (R_PPC64_PLT16_HA
, /* type */
599 1, /* size (0 = byte, 1 = short, 2 = long) */
601 false, /* pc_relative */
603 complain_overflow_dont
, /* complain_on_overflow */
604 ppc64_elf_unhandled_reloc
, /* special_function */
605 "R_PPC64_PLT16_HA", /* name */
606 false, /* partial_inplace */
608 0xffff, /* dst_mask */
609 false), /* pcrel_offset */
611 /* 16-bit section relative relocation. */
612 HOWTO (R_PPC64_SECTOFF
, /* type */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
616 false, /* pc_relative */
618 complain_overflow_bitfield
, /* complain_on_overflow */
619 ppc64_elf_sectoff_reloc
, /* special_function */
620 "R_PPC64_SECTOFF", /* name */
621 false, /* partial_inplace */
623 0xffff, /* dst_mask */
624 false), /* pcrel_offset */
626 /* Like R_PPC64_SECTOFF, but no overflow warning. */
627 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
629 1, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_dont
, /* complain_on_overflow */
634 ppc64_elf_sectoff_reloc
, /* special_function */
635 "R_PPC64_SECTOFF_LO", /* name */
636 false, /* partial_inplace */
638 0xffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* 16-bit upper half section relative relocation. */
642 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
644 1, /* size (0 = byte, 1 = short, 2 = long) */
646 false, /* pc_relative */
648 complain_overflow_dont
, /* complain_on_overflow */
649 ppc64_elf_sectoff_reloc
, /* special_function */
650 "R_PPC64_SECTOFF_HI", /* name */
651 false, /* partial_inplace */
653 0xffff, /* dst_mask */
654 false), /* pcrel_offset */
656 /* 16-bit upper half adjusted section relative relocation. */
657 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
659 1, /* size (0 = byte, 1 = short, 2 = long) */
661 false, /* pc_relative */
663 complain_overflow_dont
, /* complain_on_overflow */
664 ppc64_elf_sectoff_ha_reloc
, /* special_function */
665 "R_PPC64_SECTOFF_HA", /* name */
666 false, /* partial_inplace */
668 0xffff, /* dst_mask */
669 false), /* pcrel_offset */
671 /* Like R_PPC64_REL24 without touching the two least significant
672 bits. Should have been named R_PPC64_REL30! */
673 HOWTO (R_PPC64_ADDR30
, /* type */
675 2, /* size (0 = byte, 1 = short, 2 = long) */
677 true, /* pc_relative */
679 complain_overflow_dont
, /* complain_on_overflow */
680 bfd_elf_generic_reloc
, /* special_function */
681 "R_PPC64_ADDR30", /* name */
682 false, /* partial_inplace */
684 0xfffffffc, /* dst_mask */
685 true), /* pcrel_offset */
687 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
689 /* A standard 64-bit relocation. */
690 HOWTO (R_PPC64_ADDR64
, /* type */
692 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
694 false, /* pc_relative */
696 complain_overflow_dont
, /* complain_on_overflow */
697 bfd_elf_generic_reloc
, /* special_function */
698 "R_PPC64_ADDR64", /* name */
699 false, /* partial_inplace */
701 0xffffffffffffffff, /* dst_mask */
702 false), /* pcrel_offset */
704 /* The bits 32-47 of an address. */
705 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
707 1, /* size (0 = byte, 1 = short, 2 = long) */
709 false, /* pc_relative */
711 complain_overflow_dont
, /* complain_on_overflow */
712 bfd_elf_generic_reloc
, /* special_function */
713 "R_PPC64_ADDR16_HIGHER", /* name */
714 false, /* partial_inplace */
716 0xffff, /* dst_mask */
717 false), /* pcrel_offset */
719 /* The bits 32-47 of an address, plus 1 if the contents of the low
720 16 bits, treated as a signed number, is negative. */
721 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
723 1, /* size (0 = byte, 1 = short, 2 = long) */
725 false, /* pc_relative */
727 complain_overflow_dont
, /* complain_on_overflow */
728 ppc64_elf_ha_reloc
, /* special_function */
729 "R_PPC64_ADDR16_HIGHERA", /* name */
730 false, /* partial_inplace */
732 0xffff, /* dst_mask */
733 false), /* pcrel_offset */
735 /* The bits 48-63 of an address. */
736 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
740 false, /* pc_relative */
742 complain_overflow_dont
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_PPC64_ADDR16_HIGHEST", /* name */
745 false, /* partial_inplace */
747 0xffff, /* dst_mask */
748 false), /* pcrel_offset */
750 /* The bits 48-63 of an address, plus 1 if the contents of the low
751 16 bits, treated as a signed number, is negative. */
752 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
754 1, /* size (0 = byte, 1 = short, 2 = long) */
756 false, /* pc_relative */
758 complain_overflow_dont
, /* complain_on_overflow */
759 ppc64_elf_ha_reloc
, /* special_function */
760 "R_PPC64_ADDR16_HIGHESTA", /* name */
761 false, /* partial_inplace */
763 0xffff, /* dst_mask */
764 false), /* pcrel_offset */
766 /* Like ADDR64, but may be unaligned. */
767 HOWTO (R_PPC64_UADDR64
, /* type */
769 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
771 false, /* pc_relative */
773 complain_overflow_dont
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 "R_PPC64_UADDR64", /* name */
776 false, /* partial_inplace */
778 0xffffffffffffffff, /* dst_mask */
779 false), /* pcrel_offset */
781 /* 64-bit relative relocation. */
782 HOWTO (R_PPC64_REL64
, /* type */
784 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
786 true, /* pc_relative */
788 complain_overflow_dont
, /* complain_on_overflow */
789 bfd_elf_generic_reloc
, /* special_function */
790 "R_PPC64_REL64", /* name */
791 false, /* partial_inplace */
793 0xffffffffffffffff, /* dst_mask */
794 true), /* pcrel_offset */
796 /* 64-bit relocation to the symbol's procedure linkage table. */
797 HOWTO (R_PPC64_PLT64
, /* type */
799 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
801 false, /* pc_relative */
803 complain_overflow_dont
, /* complain_on_overflow */
804 ppc64_elf_unhandled_reloc
, /* special_function */
805 "R_PPC64_PLT64", /* name */
806 false, /* partial_inplace */
809 false), /* pcrel_offset */
811 /* 64-bit PC relative relocation to the symbol's procedure linkage
813 /* FIXME: R_PPC64_PLTREL64 not supported. */
814 HOWTO (R_PPC64_PLTREL64
, /* type */
816 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
818 true, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 ppc64_elf_unhandled_reloc
, /* special_function */
822 "R_PPC64_PLTREL64", /* name */
823 false, /* partial_inplace */
826 true), /* pcrel_offset */
828 /* 16 bit TOC-relative relocation. */
830 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
831 HOWTO (R_PPC64_TOC16
, /* type */
833 1, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_signed
, /* complain_on_overflow */
838 ppc64_elf_toc_reloc
, /* special_function */
839 "R_PPC64_TOC16", /* name */
840 false, /* partial_inplace */
842 0xffff, /* dst_mask */
843 false), /* pcrel_offset */
845 /* 16 bit TOC-relative relocation without overflow. */
847 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
848 HOWTO (R_PPC64_TOC16_LO
, /* type */
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 false, /* pc_relative */
854 complain_overflow_dont
, /* complain_on_overflow */
855 ppc64_elf_toc_reloc
, /* special_function */
856 "R_PPC64_TOC16_LO", /* name */
857 false, /* partial_inplace */
859 0xffff, /* dst_mask */
860 false), /* pcrel_offset */
862 /* 16 bit TOC-relative relocation, high 16 bits. */
864 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
865 HOWTO (R_PPC64_TOC16_HI
, /* type */
867 1, /* size (0 = byte, 1 = short, 2 = long) */
869 false, /* pc_relative */
871 complain_overflow_dont
, /* complain_on_overflow */
872 ppc64_elf_toc_reloc
, /* special_function */
873 "R_PPC64_TOC16_HI", /* name */
874 false, /* partial_inplace */
876 0xffff, /* dst_mask */
877 false), /* pcrel_offset */
879 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
880 contents of the low 16 bits, treated as a signed number, is
883 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
884 HOWTO (R_PPC64_TOC16_HA
, /* type */
886 1, /* size (0 = byte, 1 = short, 2 = long) */
888 false, /* pc_relative */
890 complain_overflow_dont
, /* complain_on_overflow */
891 ppc64_elf_toc_ha_reloc
, /* special_function */
892 "R_PPC64_TOC16_HA", /* name */
893 false, /* partial_inplace */
895 0xffff, /* dst_mask */
896 false), /* pcrel_offset */
898 /* 64-bit relocation; insert value of TOC base (.TOC.). */
900 /* R_PPC64_TOC 51 doubleword64 .TOC. */
901 HOWTO (R_PPC64_TOC
, /* type */
903 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
905 false, /* pc_relative */
907 complain_overflow_bitfield
, /* complain_on_overflow */
908 ppc64_elf_toc64_reloc
, /* special_function */
909 "R_PPC64_TOC", /* name */
910 false, /* partial_inplace */
912 0xffffffffffffffff, /* dst_mask */
913 false), /* pcrel_offset */
915 /* Like R_PPC64_GOT16, but also informs the link editor that the
916 value to relocate may (!) refer to a PLT entry which the link
917 editor (a) may replace with the symbol value. If the link editor
918 is unable to fully resolve the symbol, it may (b) create a PLT
919 entry and store the address to the new PLT entry in the GOT.
920 This permits lazy resolution of function symbols at run time.
921 The link editor may also skip all of this and just (c) emit a
922 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
923 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
924 HOWTO (R_PPC64_PLTGOT16
, /* type */
926 1, /* size (0 = byte, 1 = short, 2 = long) */
928 false, /* pc_relative */
930 complain_overflow_signed
, /* complain_on_overflow */
931 ppc64_elf_unhandled_reloc
, /* special_function */
932 "R_PPC64_PLTGOT16", /* name */
933 false, /* partial_inplace */
935 0xffff, /* dst_mask */
936 false), /* pcrel_offset */
938 /* Like R_PPC64_PLTGOT16, but without overflow. */
939 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
940 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 false, /* pc_relative */
946 complain_overflow_dont
, /* complain_on_overflow */
947 ppc64_elf_unhandled_reloc
, /* special_function */
948 "R_PPC64_PLTGOT16_LO", /* name */
949 false, /* partial_inplace */
951 0xffff, /* dst_mask */
952 false), /* pcrel_offset */
954 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
955 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
956 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
958 1, /* size (0 = byte, 1 = short, 2 = long) */
960 false, /* pc_relative */
962 complain_overflow_dont
, /* complain_on_overflow */
963 ppc64_elf_unhandled_reloc
, /* special_function */
964 "R_PPC64_PLTGOT16_HI", /* name */
965 false, /* partial_inplace */
967 0xffff, /* dst_mask */
968 false), /* pcrel_offset */
970 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
971 1 if the contents of the low 16 bits, treated as a signed number,
973 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
974 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
976 1, /* size (0 = byte, 1 = short, 2 = long) */
978 false, /* pc_relative */
980 complain_overflow_dont
,/* complain_on_overflow */
981 ppc64_elf_unhandled_reloc
, /* special_function */
982 "R_PPC64_PLTGOT16_HA", /* name */
983 false, /* partial_inplace */
985 0xffff, /* dst_mask */
986 false), /* pcrel_offset */
988 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
989 HOWTO (R_PPC64_ADDR16_DS
, /* type */
991 1, /* size (0 = byte, 1 = short, 2 = long) */
993 false, /* pc_relative */
995 complain_overflow_bitfield
, /* complain_on_overflow */
996 bfd_elf_generic_reloc
, /* special_function */
997 "R_PPC64_ADDR16_DS", /* name */
998 false, /* partial_inplace */
1000 0xfffc, /* dst_mask */
1001 false), /* pcrel_offset */
1003 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1004 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1006 1, /* size (0 = byte, 1 = short, 2 = long) */
1008 false, /* pc_relative */
1010 complain_overflow_dont
,/* complain_on_overflow */
1011 bfd_elf_generic_reloc
, /* special_function */
1012 "R_PPC64_ADDR16_LO_DS",/* name */
1013 false, /* partial_inplace */
1015 0xfffc, /* dst_mask */
1016 false), /* pcrel_offset */
1018 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1019 HOWTO (R_PPC64_GOT16_DS
, /* type */
1021 1, /* size (0 = byte, 1 = short, 2 = long) */
1023 false, /* pc_relative */
1025 complain_overflow_signed
, /* complain_on_overflow */
1026 ppc64_elf_unhandled_reloc
, /* special_function */
1027 "R_PPC64_GOT16_DS", /* name */
1028 false, /* partial_inplace */
1030 0xfffc, /* dst_mask */
1031 false), /* pcrel_offset */
1033 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1034 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1036 1, /* size (0 = byte, 1 = short, 2 = long) */
1038 false, /* pc_relative */
1040 complain_overflow_dont
, /* complain_on_overflow */
1041 ppc64_elf_unhandled_reloc
, /* special_function */
1042 "R_PPC64_GOT16_LO_DS", /* name */
1043 false, /* partial_inplace */
1045 0xfffc, /* dst_mask */
1046 false), /* pcrel_offset */
1048 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1049 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1051 1, /* size (0 = byte, 1 = short, 2 = long) */
1053 false, /* pc_relative */
1055 complain_overflow_dont
, /* complain_on_overflow */
1056 ppc64_elf_unhandled_reloc
, /* special_function */
1057 "R_PPC64_PLT16_LO_DS", /* name */
1058 false, /* partial_inplace */
1060 0xfffc, /* dst_mask */
1061 false), /* pcrel_offset */
1063 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1064 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1066 1, /* size (0 = byte, 1 = short, 2 = long) */
1068 false, /* pc_relative */
1070 complain_overflow_bitfield
, /* complain_on_overflow */
1071 ppc64_elf_sectoff_reloc
, /* special_function */
1072 "R_PPC64_SECTOFF_DS", /* name */
1073 false, /* partial_inplace */
1075 0xfffc, /* dst_mask */
1076 false), /* 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 ppc64_elf_sectoff_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 ppc64_elf_toc_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 ppc64_elf_toc_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 ppc64_elf_unhandled_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 ppc64_elf_unhandled_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_16_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 /* Initialize howto table if needed. */
1360 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
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_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1373 input_section
, output_bfd
, error_message
)
1375 arelent
*reloc_entry
;
1378 asection
*input_section
;
1380 char **error_message
;
1382 /* If this is a relocatable link (output_bfd test tells us), just
1383 call the generic function. Any adjustment will be done at final
1385 if (output_bfd
!= NULL
)
1386 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1387 input_section
, output_bfd
, error_message
);
1389 /* Adjust the addend for sign extension of the low 16 bits.
1390 We won't actually be using the low 16 bits, so trashing them
1392 reloc_entry
->addend
+= 0x8000;
1393 return bfd_reloc_continue
;
1396 static bfd_reloc_status_type
1397 ppc64_elf_brtaken_reloc (abfd
, reloc_entry
, symbol
, data
,
1398 input_section
, output_bfd
, error_message
)
1400 arelent
*reloc_entry
;
1403 asection
*input_section
;
1405 char **error_message
;
1408 enum elf_ppc_reloc_type r_type
;
1409 bfd_size_type octets
;
1410 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1411 boolean is_power4
= false;
1413 /* If this is a relocatable link (output_bfd test tells us), just
1414 call the generic function. Any adjustment will be done at final
1416 if (output_bfd
!= NULL
)
1417 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1418 input_section
, output_bfd
, error_message
);
1420 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1421 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1422 insn
&= ~(0x01 << 21);
1423 r_type
= (enum elf_ppc_reloc_type
) reloc_entry
->howto
->type
;
1424 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1425 || r_type
== R_PPC64_REL14_BRTAKEN
)
1426 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1430 /* Set 'a' bit. This is 0b00010 in BO field for branch
1431 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1432 for branch on CTR insns (BO == 1a00t or 1a01t). */
1433 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1435 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1438 return bfd_reloc_continue
;
1445 if (!bfd_is_com_section (symbol
->section
))
1446 target
= symbol
->value
;
1447 target
+= symbol
->section
->output_section
->vma
;
1448 target
+= symbol
->section
->output_offset
;
1449 target
+= reloc_entry
->addend
;
1451 from
= (reloc_entry
->address
1452 + input_section
->output_offset
1453 + input_section
->output_section
->vma
);
1455 /* Invert 'y' bit if not the default. */
1456 if ((bfd_signed_vma
) (target
- from
) < 0)
1459 bfd_put_32 (abfd
, (bfd_vma
) insn
, (bfd_byte
*) data
+ octets
);
1460 return bfd_reloc_continue
;
1463 static bfd_reloc_status_type
1464 ppc64_elf_sectoff_reloc (abfd
, reloc_entry
, symbol
, data
,
1465 input_section
, output_bfd
, error_message
)
1467 arelent
*reloc_entry
;
1470 asection
*input_section
;
1472 char **error_message
;
1474 /* If this is a relocatable link (output_bfd test tells us), just
1475 call the generic function. Any adjustment will be done at final
1477 if (output_bfd
!= NULL
)
1478 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1479 input_section
, output_bfd
, error_message
);
1481 /* Subtract the symbol section base address. */
1482 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1483 return bfd_reloc_continue
;
1486 static bfd_reloc_status_type
1487 ppc64_elf_sectoff_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1488 input_section
, output_bfd
, error_message
)
1490 arelent
*reloc_entry
;
1493 asection
*input_section
;
1495 char **error_message
;
1497 /* If this is a relocatable link (output_bfd test tells us), just
1498 call the generic function. Any adjustment will be done at final
1500 if (output_bfd
!= NULL
)
1501 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1502 input_section
, output_bfd
, error_message
);
1504 /* Subtract the symbol section base address. */
1505 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1507 /* Adjust the addend for sign extension of the low 16 bits. */
1508 reloc_entry
->addend
+= 0x8000;
1509 return bfd_reloc_continue
;
1512 static bfd_reloc_status_type
1513 ppc64_elf_toc_reloc (abfd
, reloc_entry
, symbol
, data
,
1514 input_section
, output_bfd
, error_message
)
1516 arelent
*reloc_entry
;
1519 asection
*input_section
;
1521 char **error_message
;
1525 /* If this is a relocatable link (output_bfd test tells us), just
1526 call the generic function. Any adjustment will be done at final
1528 if (output_bfd
!= NULL
)
1529 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1530 input_section
, output_bfd
, error_message
);
1532 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1534 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1536 /* Subtract the TOC base address. */
1537 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1538 return bfd_reloc_continue
;
1541 static bfd_reloc_status_type
1542 ppc64_elf_toc_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1543 input_section
, output_bfd
, error_message
)
1545 arelent
*reloc_entry
;
1548 asection
*input_section
;
1550 char **error_message
;
1554 /* If this is a relocatable link (output_bfd test tells us), just
1555 call the generic function. Any adjustment will be done at final
1557 if (output_bfd
!= NULL
)
1558 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1559 input_section
, output_bfd
, error_message
);
1561 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1563 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1565 /* Subtract the TOC base address. */
1566 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1568 /* Adjust the addend for sign extension of the low 16 bits. */
1569 reloc_entry
->addend
+= 0x8000;
1570 return bfd_reloc_continue
;
1573 static bfd_reloc_status_type
1574 ppc64_elf_toc64_reloc (abfd
, reloc_entry
, symbol
, data
,
1575 input_section
, output_bfd
, error_message
)
1577 arelent
*reloc_entry
;
1580 asection
*input_section
;
1582 char **error_message
;
1585 bfd_size_type octets
;
1587 /* If this is a relocatable link (output_bfd test tells us), just
1588 call the generic function. Any adjustment will be done at final
1590 if (output_bfd
!= NULL
)
1591 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1592 input_section
, output_bfd
, error_message
);
1594 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1596 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1598 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1599 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1600 return bfd_reloc_ok
;
1603 static bfd_reloc_status_type
1604 ppc64_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
1605 input_section
, output_bfd
, error_message
)
1607 arelent
*reloc_entry
;
1610 asection
*input_section
;
1612 char **error_message
;
1614 /* If this is a relocatable link (output_bfd test tells us), just
1615 call the generic function. Any adjustment will be done at final
1617 if (output_bfd
!= NULL
)
1618 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1619 input_section
, output_bfd
, error_message
);
1621 if (error_message
!= NULL
)
1623 static char buf
[60];
1624 sprintf (buf
, "generic linker can't handle %s",
1625 reloc_entry
->howto
->name
);
1626 *error_message
= buf
;
1628 return bfd_reloc_dangerous
;
1631 /* Fix bad default arch selected for a 64 bit input bfd when the
1632 default is 32 bit. */
1635 ppc64_elf_object_p (abfd
)
1638 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
1640 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1642 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1644 /* Relies on arch after 32 bit default being 64 bit default. */
1645 abfd
->arch_info
= abfd
->arch_info
->next
;
1646 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1652 /* Merge backend specific data from an object file to the output
1653 object file when linking. */
1656 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1660 /* Check if we have the same endianess. */
1661 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1662 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1666 if (bfd_big_endian (ibfd
))
1667 msg
= _("%s: compiled for a big endian system and target is little endian");
1669 msg
= _("%s: compiled for a little endian system and target is big endian");
1671 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1673 bfd_set_error (bfd_error_wrong_format
);
1680 /* The following functions are specific to the ELF linker, while
1681 functions above are used generally. Those named ppc64_elf_* are
1682 called by the main ELF linker code. They appear in this file more
1683 or less in the order in which they are called. eg.
1684 ppc64_elf_check_relocs is called early in the link process,
1685 ppc64_elf_finish_dynamic_sections is one of the last functions
1688 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1689 functions have both a function code symbol and a function descriptor
1690 symbol. A call to foo in a relocatable object file looks like:
1697 The function definition in another object file might be:
1701 . .quad .TOC.@tocbase
1707 When the linker resolves the call during a static link, the branch
1708 unsurprisingly just goes to .foo and the .opd information is unused.
1709 If the function definition is in a shared library, things are a little
1710 different: The call goes via a plt call stub, the opd information gets
1711 copied to the plt, and the linker patches the nop.
1719 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1720 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1721 . std 2,40(1) # this is the general idea
1729 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1731 The "reloc ()" notation is supposed to indicate that the linker emits
1732 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1735 What are the difficulties here? Well, firstly, the relocations
1736 examined by the linker in check_relocs are against the function code
1737 sym .foo, while the dynamic relocation in the plt is emitted against
1738 the function descriptor symbol, foo. Somewhere along the line, we need
1739 to carefully copy dynamic link information from one symbol to the other.
1740 Secondly, the generic part of the elf linker will make .foo a dynamic
1741 symbol as is normal for most other backends. We need foo dynamic
1742 instead, at least for an application final link. However, when
1743 creating a shared library containing foo, we need to have both symbols
1744 dynamic so that references to .foo are satisfied during the early
1745 stages of linking. Otherwise the linker might decide to pull in a
1746 definition from some other object, eg. a static library. */
1748 /* The linker needs to keep track of the number of relocs that it
1749 decides to copy as dynamic relocs in check_relocs for each symbol.
1750 This is so that it can later discard them if they are found to be
1751 unnecessary. We store the information in a field extending the
1752 regular ELF linker hash table. */
1754 struct ppc_dyn_relocs
1756 struct ppc_dyn_relocs
*next
;
1758 /* The input section of the reloc. */
1761 /* Total number of relocs copied for the input section. */
1762 bfd_size_type count
;
1764 /* Number of pc-relative relocs copied for the input section. */
1765 bfd_size_type pc_count
;
1768 /* Of those relocs that might be copied as dynamic relocs, this macro
1769 selects between relative and absolute types. */
1771 #define IS_ABSOLUTE_RELOC(RTYPE) \
1772 ((RTYPE) != R_PPC64_REL32 \
1773 && (RTYPE) != R_PPC64_REL64 \
1774 && (RTYPE) != R_PPC64_ADDR30)
1776 /* Section name for stubs is the associated section name plus this
1778 #define STUB_SUFFIX ".stub"
1781 ppc_stub_long_branch:
1782 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1783 destination, but a 24 bit branch in a stub section will reach.
1786 ppc_stub_plt_branch:
1787 Similar to the above, but a 24 bit branch in the stub section won't
1788 reach its destination.
1789 . addis %r12,%r2,xxx@ha
1790 . ld %r11,xxx@l(%r12)
1795 Used to call a function in a shared library.
1796 . addis %r12,%r2,xxx@ha
1798 . ld %r11,xxx+0@l(%r12)
1799 . ld %r2,xxx+8@l(%r12)
1801 . ld %r11,xxx+16@l(%r12)
1805 enum ppc_stub_type
{
1807 ppc_stub_long_branch
,
1808 ppc_stub_plt_branch
,
1812 struct ppc_stub_hash_entry
{
1814 /* Base hash table entry structure. */
1815 struct bfd_hash_entry root
;
1817 /* The stub section. */
1820 /* Offset within stub_sec of the beginning of this stub. */
1821 bfd_vma stub_offset
;
1823 /* Given the symbol's value and its section we can determine its final
1824 value when building the stubs (so the stub knows where to jump. */
1825 bfd_vma target_value
;
1826 asection
*target_section
;
1828 enum ppc_stub_type stub_type
;
1830 /* The symbol table entry, if any, that this was derived from. */
1831 struct ppc_link_hash_entry
*h
;
1833 /* Where this stub is being called from, or, in the case of combined
1834 stub sections, the first input section in the group. */
1838 struct ppc_branch_hash_entry
{
1840 /* Base hash table entry structure. */
1841 struct bfd_hash_entry root
;
1843 /* Offset within .branch_lt. */
1844 unsigned int offset
;
1846 /* Generation marker. */
1850 struct ppc_link_hash_entry
1852 struct elf_link_hash_entry elf
;
1854 /* A pointer to the most recently used stub hash entry against this
1856 struct ppc_stub_hash_entry
*stub_cache
;
1858 /* Track dynamic relocs copied for this symbol. */
1859 struct ppc_dyn_relocs
*dyn_relocs
;
1861 /* Link between function code and descriptor symbols. */
1862 struct elf_link_hash_entry
*oh
;
1864 /* Flag function code and descriptor symbols. */
1865 unsigned int is_func
:1;
1866 unsigned int is_func_descriptor
:1;
1867 unsigned int is_entry
:1;
1870 /* ppc64 ELF linker hash table. */
1872 struct ppc_link_hash_table
1874 struct elf_link_hash_table elf
;
1876 /* The stub hash table. */
1877 struct bfd_hash_table stub_hash_table
;
1879 /* Another hash table for plt_branch stubs. */
1880 struct bfd_hash_table branch_hash_table
;
1882 /* Linker stub bfd. */
1885 /* Linker call-backs. */
1886 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
1887 void (*layout_sections_again
) PARAMS ((void));
1889 /* Array to keep track of which stub sections have been created, and
1890 information on stub grouping. */
1892 /* This is the section to which stubs in the group will be attached. */
1894 /* The stub section. */
1898 /* Assorted information used by ppc64_elf_size_stubs. */
1900 asection
**input_list
;
1902 /* Short-cuts to get to dynamic linker sections. */
1915 unsigned int stub_error
;
1917 /* Flag set when small branches are detected. Used to
1918 select suitable defaults for the stub group size. */
1919 unsigned int has_14bit_branch
;
1921 /* Set if we detect a reference undefined weak symbol. */
1922 unsigned int have_undefweak
;
1924 /* Incremented every time we size stubs. */
1925 unsigned int stub_iteration
;
1927 /* Small local sym to section mapping cache. */
1928 struct sym_sec_cache sym_sec
;
1931 static struct bfd_hash_entry
*stub_hash_newfunc
1932 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1933 static struct bfd_hash_entry
*branch_hash_newfunc
1934 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1935 static struct bfd_hash_entry
*link_hash_newfunc
1936 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1937 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
1939 static void ppc64_elf_link_hash_table_free
1940 PARAMS ((struct bfd_link_hash_table
*));
1941 static char *ppc_stub_name
1942 PARAMS ((const asection
*, const asection
*,
1943 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
1944 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
1945 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
1946 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
1947 static struct ppc_stub_hash_entry
*ppc_add_stub
1948 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
1949 static boolean create_linkage_sections
1950 PARAMS ((bfd
*, struct bfd_link_info
*));
1951 static boolean create_got_section
1952 PARAMS ((bfd
*, struct bfd_link_info
*));
1953 static boolean ppc64_elf_create_dynamic_sections
1954 PARAMS ((bfd
*, struct bfd_link_info
*));
1955 static void ppc64_elf_copy_indirect_symbol
1956 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
1957 static boolean ppc64_elf_check_relocs
1958 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1959 const Elf_Internal_Rela
*));
1960 static asection
* ppc64_elf_gc_mark_hook
1961 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
1962 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
1963 static boolean ppc64_elf_gc_sweep_hook
1964 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1965 const Elf_Internal_Rela
*));
1966 static boolean func_desc_adjust
1967 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1968 static boolean ppc64_elf_func_desc_adjust
1969 PARAMS ((bfd
*, struct bfd_link_info
*));
1970 static boolean ppc64_elf_adjust_dynamic_symbol
1971 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
1972 static void ppc64_elf_hide_symbol
1973 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, boolean
));
1974 static boolean edit_opd
1975 PARAMS ((bfd
*, struct bfd_link_info
*));
1976 static boolean allocate_dynrelocs
1977 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1978 static boolean readonly_dynrelocs
1979 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1980 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
1981 PARAMS ((const Elf_Internal_Rela
*));
1982 static boolean ppc64_elf_size_dynamic_sections
1983 PARAMS ((bfd
*, struct bfd_link_info
*));
1984 static INLINE
enum ppc_stub_type ppc_type_of_stub
1985 PARAMS ((asection
*, const Elf_Internal_Rela
*,
1986 struct ppc_link_hash_entry
**, bfd_vma
));
1987 static bfd_byte
*build_plt_stub
1988 PARAMS ((bfd
*, bfd_byte
*, int, int));
1989 static boolean ppc_build_one_stub
1990 PARAMS ((struct bfd_hash_entry
*, PTR
));
1991 static boolean ppc_size_one_stub
1992 PARAMS ((struct bfd_hash_entry
*, PTR
));
1993 static void group_sections
1994 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, boolean
));
1995 static boolean ppc64_elf_relocate_section
1996 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
1997 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
1999 static boolean ppc64_elf_finish_dynamic_symbol
2000 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
2001 Elf_Internal_Sym
*));
2002 static boolean ppc64_elf_finish_dynamic_sections
2003 PARAMS ((bfd
*, struct bfd_link_info
*));
2005 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2007 #define ppc_hash_table(p) \
2008 ((struct ppc_link_hash_table *) ((p)->hash))
2010 #define ppc_stub_hash_lookup(table, string, create, copy) \
2011 ((struct ppc_stub_hash_entry *) \
2012 bfd_hash_lookup ((table), (string), (create), (copy)))
2014 #define ppc_branch_hash_lookup(table, string, create, copy) \
2015 ((struct ppc_branch_hash_entry *) \
2016 bfd_hash_lookup ((table), (string), (create), (copy)))
2018 /* Create an entry in the stub hash table. */
2020 static struct bfd_hash_entry
*
2021 stub_hash_newfunc (entry
, table
, string
)
2022 struct bfd_hash_entry
*entry
;
2023 struct bfd_hash_table
*table
;
2026 /* Allocate the structure if it has not already been allocated by a
2030 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2035 /* Call the allocation method of the superclass. */
2036 entry
= bfd_hash_newfunc (entry
, table
, string
);
2039 struct ppc_stub_hash_entry
*eh
;
2041 /* Initialize the local fields. */
2042 eh
= (struct ppc_stub_hash_entry
*) entry
;
2043 eh
->stub_sec
= NULL
;
2044 eh
->stub_offset
= 0;
2045 eh
->target_value
= 0;
2046 eh
->target_section
= NULL
;
2047 eh
->stub_type
= ppc_stub_none
;
2055 /* Create an entry in the branch hash table. */
2057 static struct bfd_hash_entry
*
2058 branch_hash_newfunc (entry
, table
, string
)
2059 struct bfd_hash_entry
*entry
;
2060 struct bfd_hash_table
*table
;
2063 /* Allocate the structure if it has not already been allocated by a
2067 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2072 /* Call the allocation method of the superclass. */
2073 entry
= bfd_hash_newfunc (entry
, table
, string
);
2076 struct ppc_branch_hash_entry
*eh
;
2078 /* Initialize the local fields. */
2079 eh
= (struct ppc_branch_hash_entry
*) entry
;
2087 /* Create an entry in a ppc64 ELF linker hash table. */
2089 static struct bfd_hash_entry
*
2090 link_hash_newfunc (entry
, table
, string
)
2091 struct bfd_hash_entry
*entry
;
2092 struct bfd_hash_table
*table
;
2095 /* Allocate the structure if it has not already been allocated by a
2099 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2104 /* Call the allocation method of the superclass. */
2105 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2108 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2110 eh
->stub_cache
= NULL
;
2111 eh
->dyn_relocs
= NULL
;
2114 eh
->is_func_descriptor
= 0;
2121 /* Create a ppc64 ELF linker hash table. */
2123 static struct bfd_link_hash_table
*
2124 ppc64_elf_link_hash_table_create (abfd
)
2127 struct ppc_link_hash_table
*htab
;
2128 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2130 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2134 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2140 /* Init the stub hash table too. */
2141 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2144 /* And the branch hash table. */
2145 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2148 htab
->stub_bfd
= NULL
;
2149 htab
->add_stub_section
= NULL
;
2150 htab
->layout_sections_again
= NULL
;
2151 htab
->stub_group
= NULL
;
2153 htab
->srelgot
= NULL
;
2155 htab
->srelplt
= NULL
;
2156 htab
->sdynbss
= NULL
;
2157 htab
->srelbss
= NULL
;
2158 htab
->sglink
= NULL
;
2161 htab
->srelbrlt
= NULL
;
2162 htab
->stub_error
= 0;
2163 htab
->has_14bit_branch
= 0;
2164 htab
->have_undefweak
= 0;
2165 htab
->stub_iteration
= 0;
2166 htab
->sym_sec
.abfd
= NULL
;
2168 return &htab
->elf
.root
;
2171 /* Free the derived linker hash table. */
2174 ppc64_elf_link_hash_table_free (hash
)
2175 struct bfd_link_hash_table
*hash
;
2177 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2179 bfd_hash_table_free (&ret
->stub_hash_table
);
2180 bfd_hash_table_free (&ret
->branch_hash_table
);
2181 _bfd_generic_link_hash_table_free (hash
);
2184 /* Build a name for an entry in the stub hash table. */
2187 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2188 const asection
*input_section
;
2189 const asection
*sym_sec
;
2190 const struct ppc_link_hash_entry
*h
;
2191 const Elf_Internal_Rela
*rel
;
2196 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2197 offsets from a sym as a branch target? In fact, we could
2198 probably assume the addend is always zero. */
2199 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2203 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2204 stub_name
= bfd_malloc (len
);
2205 if (stub_name
!= NULL
)
2207 sprintf (stub_name
, "%08x_%s+%x",
2208 input_section
->id
& 0xffffffff,
2209 h
->elf
.root
.root
.string
,
2210 (int) rel
->r_addend
& 0xffffffff);
2215 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2216 stub_name
= bfd_malloc (len
);
2217 if (stub_name
!= NULL
)
2219 sprintf (stub_name
, "%08x_%x:%x+%x",
2220 input_section
->id
& 0xffffffff,
2221 sym_sec
->id
& 0xffffffff,
2222 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2223 (int) rel
->r_addend
& 0xffffffff);
2229 /* Look up an entry in the stub hash. Stub entries are cached because
2230 creating the stub name takes a bit of time. */
2232 static struct ppc_stub_hash_entry
*
2233 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2234 const asection
*input_section
;
2235 const asection
*sym_sec
;
2236 struct elf_link_hash_entry
*hash
;
2237 const Elf_Internal_Rela
*rel
;
2238 struct ppc_link_hash_table
*htab
;
2240 struct ppc_stub_hash_entry
*stub_entry
;
2241 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2242 const asection
*id_sec
;
2244 /* If this input section is part of a group of sections sharing one
2245 stub section, then use the id of the first section in the group.
2246 Stub names need to include a section id, as there may well be
2247 more than one stub used to reach say, printf, and we need to
2248 distinguish between them. */
2249 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2251 if (h
!= NULL
&& h
->stub_cache
!= NULL
2252 && h
->stub_cache
->h
== h
2253 && h
->stub_cache
->id_sec
== id_sec
)
2255 stub_entry
= h
->stub_cache
;
2261 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2262 if (stub_name
== NULL
)
2265 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2266 stub_name
, false, false);
2268 h
->stub_cache
= stub_entry
;
2276 /* Add a new stub entry to the stub hash. Not all fields of the new
2277 stub entry are initialised. */
2279 static struct ppc_stub_hash_entry
*
2280 ppc_add_stub (stub_name
, section
, htab
)
2281 const char *stub_name
;
2283 struct ppc_link_hash_table
*htab
;
2287 struct ppc_stub_hash_entry
*stub_entry
;
2289 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2290 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2291 if (stub_sec
== NULL
)
2293 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2294 if (stub_sec
== NULL
)
2300 namelen
= strlen (link_sec
->name
);
2301 len
= namelen
+ sizeof (STUB_SUFFIX
);
2302 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2306 memcpy (s_name
, link_sec
->name
, namelen
);
2307 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2308 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2309 if (stub_sec
== NULL
)
2311 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2313 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2316 /* Enter this entry into the linker stub hash table. */
2317 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2319 if (stub_entry
== NULL
)
2321 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2322 bfd_archive_filename (section
->owner
),
2327 stub_entry
->stub_sec
= stub_sec
;
2328 stub_entry
->stub_offset
= 0;
2329 stub_entry
->id_sec
= link_sec
;
2333 /* Create sections for linker generated code. */
2336 create_linkage_sections (dynobj
, info
)
2338 struct bfd_link_info
*info
;
2340 struct ppc_link_hash_table
*htab
;
2343 htab
= ppc_hash_table (info
);
2345 /* Create .sfpr for code to save and restore fp regs. */
2346 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2347 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2348 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2349 if (htab
->sfpr
== NULL
2350 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2351 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2354 /* Create .glink for lazy dynamic linking support. */
2355 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2356 if (htab
->sglink
== NULL
2357 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2358 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2361 /* Create .branch_lt for plt_branch stubs. */
2362 flags
= (SEC_ALLOC
| SEC_LOAD
2363 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2364 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2365 if (htab
->sbrlt
== NULL
2366 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2367 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2372 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2373 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2374 htab
->srelbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
2376 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2377 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2383 /* Create .got and .rela.got sections in DYNOBJ, and set up
2384 shortcuts to them in our hash table. */
2387 create_got_section (dynobj
, info
)
2389 struct bfd_link_info
*info
;
2391 struct ppc_link_hash_table
*htab
;
2393 if (! _bfd_elf_create_got_section (dynobj
, info
))
2396 htab
= ppc_hash_table (info
);
2397 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2401 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2403 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2404 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2405 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2407 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2412 /* Create the dynamic sections, and set up shortcuts. */
2415 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2417 struct bfd_link_info
*info
;
2419 struct ppc_link_hash_table
*htab
;
2421 htab
= ppc_hash_table (info
);
2422 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2425 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2428 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2429 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2430 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2432 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2434 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2435 || (!info
->shared
&& !htab
->srelbss
))
2441 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2444 ppc64_elf_copy_indirect_symbol (dir
, ind
)
2445 struct elf_link_hash_entry
*dir
, *ind
;
2447 struct ppc_link_hash_entry
*edir
, *eind
;
2449 edir
= (struct ppc_link_hash_entry
*) dir
;
2450 eind
= (struct ppc_link_hash_entry
*) ind
;
2452 if (eind
->dyn_relocs
!= NULL
)
2454 if (edir
->dyn_relocs
!= NULL
)
2456 struct ppc_dyn_relocs
**pp
;
2457 struct ppc_dyn_relocs
*p
;
2459 if (ind
->root
.type
== bfd_link_hash_indirect
)
2462 /* Add reloc counts against the weak sym to the strong sym
2463 list. Merge any entries against the same section. */
2464 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2466 struct ppc_dyn_relocs
*q
;
2468 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2469 if (q
->sec
== p
->sec
)
2471 q
->pc_count
+= p
->pc_count
;
2472 q
->count
+= p
->count
;
2479 *pp
= edir
->dyn_relocs
;
2482 edir
->dyn_relocs
= eind
->dyn_relocs
;
2483 eind
->dyn_relocs
= NULL
;
2486 edir
->is_func
|= eind
->is_func
;
2487 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2488 edir
->is_entry
|= eind
->is_entry
;
2490 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
2493 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2494 symbols undefined on the command-line. */
2497 ppc64_elf_mark_entry_syms (info
)
2498 struct bfd_link_info
*info
;
2500 struct ppc_link_hash_table
*htab
;
2501 struct bfd_sym_chain
*sym
;
2503 htab
= ppc_hash_table (info
);
2504 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
2506 struct elf_link_hash_entry
*h
;
2508 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, false, false, false);
2510 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
2515 /* Look through the relocs for a section during the first phase, and
2516 calculate needed space in the global offset table, procedure
2517 linkage table, and dynamic reloc sections. */
2520 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2522 struct bfd_link_info
*info
;
2524 const Elf_Internal_Rela
*relocs
;
2526 struct ppc_link_hash_table
*htab
;
2527 Elf_Internal_Shdr
*symtab_hdr
;
2528 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2529 const Elf_Internal_Rela
*rel
;
2530 const Elf_Internal_Rela
*rel_end
;
2532 asection
**opd_sym_map
;
2534 if (info
->relocateable
)
2537 htab
= ppc_hash_table (info
);
2538 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2540 sym_hashes
= elf_sym_hashes (abfd
);
2541 sym_hashes_end
= (sym_hashes
2542 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
2543 - symtab_hdr
->sh_info
);
2547 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
2549 /* Garbage collection needs some extra help with .opd sections.
2550 We don't want to necessarily keep everything referenced by
2551 relocs in .opd, as that would keep all functions. Instead,
2552 if we reference an .opd symbol (a function descriptor), we
2553 want to keep the function code symbol's section. This is
2554 easy for global symbols, but for local syms we need to keep
2555 information about the associated function section. Later, if
2556 edit_opd deletes entries, we'll use this array to adjust
2557 local syms in .opd. */
2559 asection
*func_section
;
2564 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
2565 opd_sym_map
= (asection
**) bfd_zalloc (abfd
, amt
);
2566 if (opd_sym_map
== NULL
)
2568 elf_section_data (sec
)->tdata
= opd_sym_map
;
2571 if (htab
->elf
.dynobj
== NULL
)
2572 htab
->elf
.dynobj
= abfd
;
2573 if (htab
->sfpr
== NULL
2574 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2577 rel_end
= relocs
+ sec
->reloc_count
;
2578 for (rel
= relocs
; rel
< rel_end
; rel
++)
2580 unsigned long r_symndx
;
2581 struct elf_link_hash_entry
*h
;
2582 enum elf_ppc_reloc_type r_type
;
2584 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2585 if (r_symndx
< symtab_hdr
->sh_info
)
2588 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2590 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2593 /* GOT16 relocations */
2595 case R_PPC64_GOT16_DS
:
2596 case R_PPC64_GOT16_HA
:
2597 case R_PPC64_GOT16_HI
:
2598 case R_PPC64_GOT16_LO
:
2599 case R_PPC64_GOT16_LO_DS
:
2601 /* This symbol requires a global offset table entry. */
2602 if (htab
->sgot
== NULL
2603 && !create_got_section (htab
->elf
.dynobj
, info
))
2608 h
->got
.refcount
+= 1;
2612 bfd_signed_vma
*local_got_refcounts
;
2614 /* This is a global offset table entry for a local symbol. */
2615 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2616 if (local_got_refcounts
== NULL
)
2620 size
= symtab_hdr
->sh_info
;
2621 size
*= sizeof (bfd_signed_vma
);
2622 local_got_refcounts
= ((bfd_signed_vma
*)
2623 bfd_zalloc (abfd
, size
));
2624 if (local_got_refcounts
== NULL
)
2626 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2628 local_got_refcounts
[r_symndx
] += 1;
2632 case R_PPC64_PLT16_HA
:
2633 case R_PPC64_PLT16_HI
:
2634 case R_PPC64_PLT16_LO
:
2637 /* This symbol requires a procedure linkage table entry. We
2638 actually build the entry in adjust_dynamic_symbol,
2639 because this might be a case of linking PIC code without
2640 linking in any dynamic objects, in which case we don't
2641 need to generate a procedure linkage table after all. */
2644 /* It does not make sense to have a procedure linkage
2645 table entry for a local symbol. */
2646 bfd_set_error (bfd_error_bad_value
);
2650 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2651 h
->plt
.refcount
+= 1;
2652 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2655 /* The following relocations don't need to propagate the
2656 relocation if linking a shared object since they are
2657 section relative. */
2658 case R_PPC64_SECTOFF
:
2659 case R_PPC64_SECTOFF_LO
:
2660 case R_PPC64_SECTOFF_HI
:
2661 case R_PPC64_SECTOFF_HA
:
2662 case R_PPC64_SECTOFF_DS
:
2663 case R_PPC64_SECTOFF_LO_DS
:
2665 case R_PPC64_TOC16_LO
:
2666 case R_PPC64_TOC16_HI
:
2667 case R_PPC64_TOC16_HA
:
2668 case R_PPC64_TOC16_DS
:
2669 case R_PPC64_TOC16_LO_DS
:
2672 /* This relocation describes the C++ object vtable hierarchy.
2673 Reconstruct it for later use during GC. */
2674 case R_PPC64_GNU_VTINHERIT
:
2675 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2679 /* This relocation describes which C++ vtable entries are actually
2680 used. Record for later use during GC. */
2681 case R_PPC64_GNU_VTENTRY
:
2682 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2687 case R_PPC64_REL14_BRTAKEN
:
2688 case R_PPC64_REL14_BRNTAKEN
:
2689 htab
->has_14bit_branch
= 1;
2694 && h
->root
.root
.string
[0] == '.'
2695 && h
->root
.root
.string
[1] != 0)
2697 /* We may need a .plt entry if the function this reloc
2698 refers to is in a shared lib. */
2699 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2700 h
->plt
.refcount
+= 1;
2701 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2705 case R_PPC64_ADDR64
:
2706 if (opd_sym_map
!= NULL
2708 && h
->root
.root
.string
[0] == '.'
2709 && h
->root
.root
.string
[1] != 0)
2711 struct elf_link_hash_entry
*fdh
;
2713 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2714 false, false, false);
2717 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2718 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2719 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2720 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2723 if (opd_sym_map
!= NULL
2725 && rel
+ 1 < rel_end
2726 && ((enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
)
2731 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
2736 opd_sym_map
[rel
->r_offset
/ 24] = s
;
2742 case R_PPC64_ADDR14
:
2743 case R_PPC64_ADDR14_BRNTAKEN
:
2744 case R_PPC64_ADDR14_BRTAKEN
:
2745 case R_PPC64_ADDR16
:
2746 case R_PPC64_ADDR16_DS
:
2747 case R_PPC64_ADDR16_HA
:
2748 case R_PPC64_ADDR16_HI
:
2749 case R_PPC64_ADDR16_HIGHER
:
2750 case R_PPC64_ADDR16_HIGHERA
:
2751 case R_PPC64_ADDR16_HIGHEST
:
2752 case R_PPC64_ADDR16_HIGHESTA
:
2753 case R_PPC64_ADDR16_LO
:
2754 case R_PPC64_ADDR16_LO_DS
:
2755 case R_PPC64_ADDR24
:
2756 case R_PPC64_ADDR30
:
2757 case R_PPC64_ADDR32
:
2758 case R_PPC64_UADDR16
:
2759 case R_PPC64_UADDR32
:
2760 case R_PPC64_UADDR64
:
2762 /* Don't propagate .opd relocs. */
2763 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
2766 /* If we are creating a shared library, and this is a reloc
2767 against a global symbol, or a non PC relative reloc
2768 against a local symbol, then we need to copy the reloc
2769 into the shared library. However, if we are linking with
2770 -Bsymbolic, we do not need to copy a reloc against a
2771 global symbol which is defined in an object we are
2772 including in the link (i.e., DEF_REGULAR is set). At
2773 this point we have not seen all the input files, so it is
2774 possible that DEF_REGULAR is not set now but will be set
2775 later (it is never cleared). In case of a weak definition,
2776 DEF_REGULAR may be cleared later by a strong definition in
2777 a shared library. We account for that possibility below by
2778 storing information in the relocs_copied field of the hash
2779 table entry. A similar situation occurs when creating
2780 shared libraries and symbol visibility changes render the
2783 If on the other hand, we are creating an executable, we
2784 may need to keep relocations for symbols satisfied by a
2785 dynamic library if we manage to avoid copy relocs for the
2788 && (sec
->flags
& SEC_ALLOC
) != 0
2789 && (IS_ABSOLUTE_RELOC (r_type
)
2791 && (! info
->symbolic
2792 || h
->root
.type
== bfd_link_hash_defweak
2793 || (h
->elf_link_hash_flags
2794 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2796 && (sec
->flags
& SEC_ALLOC
) != 0
2798 && (h
->root
.type
== bfd_link_hash_defweak
2799 || (h
->elf_link_hash_flags
2800 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2802 struct ppc_dyn_relocs
*p
;
2803 struct ppc_dyn_relocs
**head
;
2805 /* We must copy these reloc types into the output file.
2806 Create a reloc section in dynobj and make room for
2813 name
= (bfd_elf_string_from_elf_section
2815 elf_elfheader (abfd
)->e_shstrndx
,
2816 elf_section_data (sec
)->rel_hdr
.sh_name
));
2820 if (strncmp (name
, ".rela", 5) != 0
2821 || strcmp (bfd_get_section_name (abfd
, sec
),
2824 (*_bfd_error_handler
)
2825 (_("%s: bad relocation section name `%s\'"),
2826 bfd_archive_filename (abfd
), name
);
2827 bfd_set_error (bfd_error_bad_value
);
2830 dynobj
= htab
->elf
.dynobj
;
2831 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2836 sreloc
= bfd_make_section (dynobj
, name
);
2837 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2838 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2839 if ((sec
->flags
& SEC_ALLOC
) != 0)
2840 flags
|= SEC_ALLOC
| SEC_LOAD
;
2842 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2843 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2846 elf_section_data (sec
)->sreloc
= sreloc
;
2849 /* If this is a global symbol, we count the number of
2850 relocations we need for this symbol. */
2853 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
2857 /* Track dynamic relocs needed for local syms too.
2858 We really need local syms available to do this
2862 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
2867 head
= ((struct ppc_dyn_relocs
**)
2868 &elf_section_data (s
)->local_dynrel
);
2872 if (p
== NULL
|| p
->sec
!= sec
)
2874 p
= ((struct ppc_dyn_relocs
*)
2875 bfd_alloc (htab
->elf
.dynobj
,
2876 (bfd_size_type
) sizeof *p
));
2887 if (!IS_ABSOLUTE_RELOC (r_type
))
2900 /* Return the section that should be marked against GC for a given
2904 ppc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2906 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2907 Elf_Internal_Rela
*rel
;
2908 struct elf_link_hash_entry
*h
;
2909 Elf_Internal_Sym
*sym
;
2911 asection
*rsec
= NULL
;
2915 enum elf_ppc_reloc_type r_type
;
2916 struct ppc_link_hash_entry
*fdh
;
2918 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2921 case R_PPC64_GNU_VTINHERIT
:
2922 case R_PPC64_GNU_VTENTRY
:
2926 switch (h
->root
.type
)
2928 case bfd_link_hash_defined
:
2929 case bfd_link_hash_defweak
:
2930 fdh
= (struct ppc_link_hash_entry
*) h
;
2932 /* Function descriptor syms cause the associated
2933 function code sym section to be marked. */
2934 if (fdh
->is_func_descriptor
)
2935 rsec
= fdh
->oh
->root
.u
.def
.section
;
2937 /* Function entry syms return NULL if they are in .opd
2938 and are not ._start (or others undefined on the ld
2939 command line). Thus we avoid marking all function
2940 sections, as all functions are referenced in .opd. */
2941 else if ((fdh
->oh
!= NULL
2942 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
2943 || elf_section_data (sec
)->tdata
== NULL
)
2944 rsec
= h
->root
.u
.def
.section
;
2947 case bfd_link_hash_common
:
2948 rsec
= h
->root
.u
.c
.p
->section
;
2958 asection
**opd_sym_section
;
2960 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2961 opd_sym_section
= (asection
**) elf_section_data (rsec
)->tdata
;
2962 if (opd_sym_section
!= NULL
)
2963 rsec
= opd_sym_section
[sym
->st_value
/ 24];
2964 else if (elf_section_data (sec
)->tdata
!= NULL
)
2971 /* Update the .got, .plt. and dynamic reloc reference counts for the
2972 section being removed. */
2975 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2977 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2979 const Elf_Internal_Rela
*relocs
;
2981 Elf_Internal_Shdr
*symtab_hdr
;
2982 struct elf_link_hash_entry
**sym_hashes
;
2983 bfd_signed_vma
*local_got_refcounts
;
2984 const Elf_Internal_Rela
*rel
, *relend
;
2986 elf_section_data (sec
)->local_dynrel
= NULL
;
2988 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2989 sym_hashes
= elf_sym_hashes (abfd
);
2990 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2992 relend
= relocs
+ sec
->reloc_count
;
2993 for (rel
= relocs
; rel
< relend
; rel
++)
2995 unsigned long r_symndx
;
2996 enum elf_ppc_reloc_type r_type
;
2997 struct elf_link_hash_entry
*h
;
2999 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3000 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3004 case R_PPC64_GOT16_DS
:
3005 case R_PPC64_GOT16_HA
:
3006 case R_PPC64_GOT16_HI
:
3007 case R_PPC64_GOT16_LO
:
3008 case R_PPC64_GOT16_LO_DS
:
3009 if (r_symndx
>= symtab_hdr
->sh_info
)
3011 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3012 if (h
->got
.refcount
> 0)
3017 if (local_got_refcounts
[r_symndx
] > 0)
3018 local_got_refcounts
[r_symndx
]--;
3022 case R_PPC64_PLT16_HA
:
3023 case R_PPC64_PLT16_HI
:
3024 case R_PPC64_PLT16_LO
:
3027 if (r_symndx
>= symtab_hdr
->sh_info
)
3029 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3030 if (h
->plt
.refcount
> 0)
3036 case R_PPC64_REL14_BRNTAKEN
:
3037 case R_PPC64_REL14_BRTAKEN
:
3039 if (r_symndx
>= symtab_hdr
->sh_info
)
3041 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3042 if (h
->plt
.refcount
> 0)
3049 if (r_symndx
>= symtab_hdr
->sh_info
)
3051 struct ppc_link_hash_entry
*eh
;
3052 struct ppc_dyn_relocs
**pp
;
3053 struct ppc_dyn_relocs
*p
;
3055 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3056 eh
= (struct ppc_link_hash_entry
*) h
;
3058 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3070 case R_PPC64_ADDR14
:
3071 case R_PPC64_ADDR14_BRNTAKEN
:
3072 case R_PPC64_ADDR14_BRTAKEN
:
3073 case R_PPC64_ADDR16
:
3074 case R_PPC64_ADDR16_DS
:
3075 case R_PPC64_ADDR16_HA
:
3076 case R_PPC64_ADDR16_HI
:
3077 case R_PPC64_ADDR16_HIGHER
:
3078 case R_PPC64_ADDR16_HIGHERA
:
3079 case R_PPC64_ADDR16_HIGHEST
:
3080 case R_PPC64_ADDR16_HIGHESTA
:
3081 case R_PPC64_ADDR16_LO
:
3082 case R_PPC64_ADDR16_LO_DS
:
3083 case R_PPC64_ADDR24
:
3084 case R_PPC64_ADDR30
:
3085 case R_PPC64_ADDR32
:
3086 case R_PPC64_ADDR64
:
3087 case R_PPC64_UADDR16
:
3088 case R_PPC64_UADDR32
:
3089 case R_PPC64_UADDR64
:
3091 if (r_symndx
>= symtab_hdr
->sh_info
)
3093 struct ppc_link_hash_entry
*eh
;
3094 struct ppc_dyn_relocs
**pp
;
3095 struct ppc_dyn_relocs
*p
;
3097 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3098 eh
= (struct ppc_link_hash_entry
*) h
;
3100 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3118 /* Called via elf_link_hash_traverse to transfer dynamic linking
3119 information on function code symbol entries to their corresponding
3120 function descriptor symbol entries. */
3122 func_desc_adjust (h
, inf
)
3123 struct elf_link_hash_entry
*h
;
3126 struct bfd_link_info
*info
;
3127 struct ppc_link_hash_table
*htab
;
3129 if (h
->root
.type
== bfd_link_hash_indirect
)
3132 if (h
->root
.type
== bfd_link_hash_warning
)
3133 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3135 info
= (struct bfd_link_info
*) inf
;
3136 htab
= ppc_hash_table (info
);
3138 /* If this is a function code symbol, transfer dynamic linking
3139 information to the function descriptor symbol. */
3140 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
3143 if (h
->root
.type
== bfd_link_hash_undefweak
3144 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
3145 htab
->have_undefweak
= true;
3147 if (h
->plt
.refcount
> 0
3148 && h
->root
.root
.string
[0] == '.'
3149 && h
->root
.root
.string
[1] != '\0')
3151 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3152 boolean force_local
;
3154 /* Find the corresponding function descriptor symbol. Create it
3155 as undefined if necessary. */
3158 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3159 false, false, true);
3163 && (h
->root
.type
== bfd_link_hash_undefined
3164 || h
->root
.type
== bfd_link_hash_undefweak
))
3169 abfd
= h
->root
.u
.undef
.abfd
;
3170 newsym
= bfd_make_empty_symbol (abfd
);
3171 newsym
->name
= h
->root
.root
.string
+ 1;
3172 newsym
->section
= bfd_und_section_ptr
;
3174 newsym
->flags
= BSF_OBJECT
;
3175 if (h
->root
.type
== bfd_link_hash_undefweak
)
3176 newsym
->flags
|= BSF_WEAK
;
3178 if ( !(_bfd_generic_link_add_one_symbol
3179 (info
, abfd
, newsym
->name
, newsym
->flags
,
3180 newsym
->section
, newsym
->value
, NULL
, false, false,
3181 (struct bfd_link_hash_entry
**) &fdh
)))
3185 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3189 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
3191 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3192 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3194 if (fdh
->dynindx
== -1)
3195 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
3197 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
3198 & (ELF_LINK_HASH_REF_REGULAR
3199 | ELF_LINK_HASH_REF_DYNAMIC
3200 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3201 | ELF_LINK_NON_GOT_REF
));
3202 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3204 fdh
->plt
.refcount
= h
->plt
.refcount
;
3205 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3207 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3208 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3209 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3212 /* Now that the info is on the function descriptor, clear the
3213 function code sym info. Any function code syms for which we
3214 don't have a definition in a regular file, we force local.
3215 This prevents a shared library from exporting syms that have
3216 been imported from another library. Function code syms that
3217 are really in the library we must leave global to prevent the
3218 linker dragging in a definition from a static library. */
3219 force_local
= (info
->shared
3220 && ((h
->elf_link_hash_flags
3221 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3223 || (fdh
->elf_link_hash_flags
3224 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3225 || (fdh
->elf_link_hash_flags
3226 & ELF_LINK_FORCED_LOCAL
) != 0));
3227 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3233 #define MIN_SAVE_FPR 14
3234 #define MAX_SAVE_FPR 31
3236 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3237 this hook to a) provide some gcc support functions, and b) transfer
3238 dynamic linking information gathered so far on function code symbol
3239 entries, to their corresponding function descriptor symbol entries. */
3241 ppc64_elf_func_desc_adjust (obfd
, info
)
3242 bfd
*obfd ATTRIBUTE_UNUSED
;
3243 struct bfd_link_info
*info
;
3245 struct ppc_link_hash_table
*htab
;
3246 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3247 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3249 struct elf_link_hash_entry
*h
;
3253 htab
= ppc_hash_table (info
);
3255 if (htab
->sfpr
== NULL
)
3256 /* We don't have any relocs. */
3259 /* First provide any missing ._savef* and ._restf* functions. */
3260 memcpy (sym
, "._savef14", 10);
3261 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3263 sym
[7] = i
/ 10 + '0';
3264 sym
[8] = i
% 10 + '0';
3265 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3267 && h
->root
.type
== bfd_link_hash_undefined
)
3269 if (lowest_savef
> i
)
3271 h
->root
.type
= bfd_link_hash_defined
;
3272 h
->root
.u
.def
.section
= htab
->sfpr
;
3273 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3275 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3276 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3280 memcpy (sym
, "._restf14", 10);
3281 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3283 sym
[7] = i
/ 10 + '0';
3284 sym
[8] = i
% 10 + '0';
3285 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3287 && h
->root
.type
== bfd_link_hash_undefined
)
3289 if (lowest_restf
> i
)
3291 h
->root
.type
= bfd_link_hash_defined
;
3292 h
->root
.u
.def
.section
= htab
->sfpr
;
3293 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3294 + (i
- lowest_restf
) * 4);
3296 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3297 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3301 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3303 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3304 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3306 if (htab
->sfpr
->_raw_size
== 0)
3308 if (!htab
->have_undefweak
)
3310 _bfd_strip_section_from_output (info
, htab
->sfpr
);
3314 htab
->sfpr
->_raw_size
= 4;
3317 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3320 htab
->sfpr
->contents
= p
;
3322 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3324 unsigned int fpr
= i
<< 21;
3325 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3326 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3329 if (lowest_savef
<= MAX_SAVE_FPR
)
3331 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3335 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3337 unsigned int fpr
= i
<< 21;
3338 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3339 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3342 if (lowest_restf
<= MAX_SAVE_FPR
3343 || htab
->sfpr
->_raw_size
== 4)
3345 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3351 /* Adjust a symbol defined by a dynamic object and referenced by a
3352 regular object. The current definition is in some section of the
3353 dynamic object, but we're not including those sections. We have to
3354 change the definition to something the rest of the link can
3358 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3359 struct bfd_link_info
*info
;
3360 struct elf_link_hash_entry
*h
;
3362 struct ppc_link_hash_table
*htab
;
3363 struct ppc_link_hash_entry
* eh
;
3364 struct ppc_dyn_relocs
*p
;
3366 unsigned int power_of_two
;
3368 htab
= ppc_hash_table (info
);
3370 /* Deal with function syms. */
3371 if (h
->type
== STT_FUNC
3372 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3374 /* Clear procedure linkage table information for any symbol that
3375 won't need a .plt entry. */
3376 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3377 || h
->plt
.refcount
<= 0
3378 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3380 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3381 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3383 h
->plt
.offset
= (bfd_vma
) -1;
3384 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3389 h
->plt
.offset
= (bfd_vma
) -1;
3391 /* If this is a weak symbol, and there is a real definition, the
3392 processor independent code will have arranged for us to see the
3393 real definition first, and we can just use the same value. */
3394 if (h
->weakdef
!= NULL
)
3396 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3397 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3398 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3399 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3403 /* This is a reference to a symbol defined by a dynamic object which
3404 is not a function. */
3406 /* If we are creating a shared library, we must presume that the
3407 only references to the symbol are via the global offset table.
3408 For such cases we need not do anything here; the relocations will
3409 be handled correctly by relocate_section. */
3413 /* If there are no references to this symbol that do not use the
3414 GOT, we don't need to generate a copy reloc. */
3415 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3418 eh
= (struct ppc_link_hash_entry
*) h
;
3419 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3421 s
= p
->sec
->output_section
;
3422 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3426 /* If we didn't find any dynamic relocs in read-only sections, then
3427 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3430 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3434 /* We must allocate the symbol in our .dynbss section, which will
3435 become part of the .bss section of the executable. There will be
3436 an entry for this symbol in the .dynsym section. The dynamic
3437 object will contain position independent code, so all references
3438 from the dynamic object to this symbol will go through the global
3439 offset table. The dynamic linker will use the .dynsym entry to
3440 determine the address it must put in the global offset table, so
3441 both the dynamic object and the regular object will refer to the
3442 same memory location for the variable. */
3444 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3445 copy the initial value out of the dynamic object and into the
3446 runtime process image. We need to remember the offset into the
3447 .rela.bss section we are going to use. */
3448 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3450 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3451 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3454 /* We need to figure out the alignment required for this symbol. I
3455 have no idea how ELF linkers handle this. */
3456 power_of_two
= bfd_log2 (h
->size
);
3457 if (power_of_two
> 4)
3460 /* Apply the required alignment. */
3462 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3463 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3465 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3469 /* Define the symbol as being at this point in the section. */
3470 h
->root
.u
.def
.section
= s
;
3471 h
->root
.u
.def
.value
= s
->_raw_size
;
3473 /* Increment the section size to make room for the symbol. */
3474 s
->_raw_size
+= h
->size
;
3479 /* If given a function descriptor symbol, hide both the function code
3480 sym and the descriptor. */
3482 ppc64_elf_hide_symbol (info
, h
, force_local
)
3483 struct bfd_link_info
*info
;
3484 struct elf_link_hash_entry
*h
;
3485 boolean force_local
;
3487 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3489 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3491 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3496 struct ppc_link_hash_table
*htab
;
3499 /* We aren't supposed to use alloca in BFD because on
3500 systems which do not have alloca the version in libiberty
3501 calls xmalloc, which might cause the program to crash
3502 when it runs out of memory. This function doesn't have a
3503 return status, so there's no way to gracefully return an
3504 error. So cheat. We know that string[-1] can be safely
3505 dereferenced; It's either a string in an ELF string
3506 table, or allocated in an objalloc structure. */
3508 p
= h
->root
.root
.string
- 1;
3511 htab
= ppc_hash_table (info
);
3512 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3515 /* Unfortunately, if it so happens that the string we were
3516 looking for was allocated immediately before this string,
3517 then we overwrote the string terminator. That's the only
3518 reason the lookup should fail. */
3521 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
3522 while (q
>= h
->root
.root
.string
&& *q
== *p
)
3524 if (q
< h
->root
.root
.string
&& *p
== '.')
3525 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3529 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
3530 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
3534 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3539 edit_opd (obfd
, info
)
3541 struct bfd_link_info
*info
;
3544 unsigned int bfd_indx
;
3546 for (bfd_indx
= 0, ibfd
= info
->input_bfds
;
3548 ibfd
= ibfd
->link_next
, bfd_indx
++)
3551 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3552 Elf_Internal_Shdr
*symtab_hdr
;
3553 Elf_Internal_Sym
*local_syms
;
3554 struct elf_link_hash_entry
**sym_hashes
;
3559 sec
= bfd_get_section_by_name (ibfd
, ".opd");
3563 adjust
= (long *) elf_section_data (sec
)->tdata
;
3564 BFD_ASSERT (adjust
!= NULL
);
3565 memset (adjust
, 0, (size_t) sec
->_raw_size
* sizeof (long) / 24);
3567 if (sec
->output_section
== bfd_abs_section_ptr
)
3570 /* Look through the section relocs. */
3571 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
3575 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3576 sym_hashes
= elf_sym_hashes (ibfd
);
3578 /* Read the relocations. */
3579 relstart
= _bfd_elf64_link_read_relocs (obfd
, sec
, (PTR
) NULL
,
3580 (Elf_Internal_Rela
*) NULL
,
3582 if (relstart
== NULL
)
3585 /* First run through the relocs to check they are sane, and to
3586 determine whether we need to edit this opd section. */
3589 relend
= relstart
+ sec
->reloc_count
;
3590 for (rel
= relstart
; rel
< relend
; rel
++)
3592 enum elf_ppc_reloc_type r_type
;
3593 unsigned long r_symndx
;
3595 struct elf_link_hash_entry
*h
;
3596 Elf_Internal_Sym
*sym
;
3598 /* .opd contains a regular array of 24 byte entries. We're
3599 only interested in the reloc pointing to a function entry
3601 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3602 if (r_type
== R_PPC64_TOC
)
3605 if (r_type
!= R_PPC64_ADDR64
)
3607 (*_bfd_error_handler
)
3608 (_("%s: unexpected reloc type %u in .opd section"),
3609 bfd_archive_filename (ibfd
), r_type
);
3614 if (rel
+ 1 >= relend
)
3616 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
);
3617 if (r_type
!= R_PPC64_TOC
)
3620 if (rel
->r_offset
!= offset
)
3622 /* If someone messes with .opd alignment then after a
3623 "ld -r" we might have padding in the middle of .opd.
3624 Also, there's nothing to prevent someone putting
3625 something silly in .opd with the assembler. No .opd
3626 optimization for them! */
3627 (*_bfd_error_handler
)
3628 (_("%s: .opd is not a regular array of opd entries"),
3629 bfd_archive_filename (ibfd
));
3634 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3638 if (r_symndx
>= symtab_hdr
->sh_info
)
3640 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3641 while (h
->root
.type
== bfd_link_hash_indirect
3642 || h
->root
.type
== bfd_link_hash_warning
)
3643 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3644 if (h
->root
.type
== bfd_link_hash_defined
3645 || h
->root
.type
== bfd_link_hash_defweak
)
3646 sym_sec
= h
->root
.u
.def
.section
;
3650 if (local_syms
== NULL
)
3652 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3653 if (local_syms
== NULL
)
3654 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3655 symtab_hdr
->sh_info
, 0,
3657 if (local_syms
== NULL
)
3658 goto error_free_rel
;
3660 sym
= local_syms
+ r_symndx
;
3661 if ((sym
->st_shndx
!= SHN_UNDEF
3662 && sym
->st_shndx
< SHN_LORESERVE
)
3663 || sym
->st_shndx
> SHN_HIRESERVE
)
3664 sym_sec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
3667 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
3669 (*_bfd_error_handler
)
3670 (_("%s: undefined sym `%s' in .opd section"),
3671 bfd_archive_filename (ibfd
),
3672 h
!= NULL
? h
->root
.root
.string
: "<local symbol>");
3677 if (sym_sec
->output_section
== bfd_abs_section_ptr
)
3679 /* OK, we've found a function that's excluded from the
3689 Elf_Internal_Rela
*write_rel
;
3690 bfd_byte
*rptr
, *wptr
;
3693 /* This seems a waste of time as input .opd sections are all
3694 zeros as generated by gcc, but I suppose there's no reason
3695 this will always be so. We might start putting something in
3696 the third word of .opd entries. */
3697 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
3699 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
3701 || !bfd_get_section_contents (ibfd
, sec
, loc
, (bfd_vma
) 0,
3704 if (local_syms
!= NULL
3705 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3708 if (elf_section_data (sec
)->relocs
!= relstart
)
3712 sec
->contents
= loc
;
3713 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
3716 elf_section_data (sec
)->relocs
= relstart
;
3718 wptr
= sec
->contents
;
3719 rptr
= sec
->contents
;
3720 write_rel
= relstart
;
3723 for (rel
= relstart
; rel
< relend
; rel
++)
3725 if (rel
->r_offset
== offset
)
3727 unsigned long r_symndx
;
3729 struct elf_link_hash_entry
*h
;
3730 Elf_Internal_Sym
*sym
;
3732 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3736 if (r_symndx
>= symtab_hdr
->sh_info
)
3738 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3739 while (h
->root
.type
== bfd_link_hash_indirect
3740 || h
->root
.type
== bfd_link_hash_warning
)
3741 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3742 if (h
->root
.type
== bfd_link_hash_defined
3743 || h
->root
.type
== bfd_link_hash_defweak
)
3744 sym_sec
= h
->root
.u
.def
.section
;
3748 sym
= local_syms
+ r_symndx
;
3749 if ((sym
->st_shndx
!= SHN_UNDEF
3750 && sym
->st_shndx
< SHN_LORESERVE
)
3751 || sym
->st_shndx
> SHN_HIRESERVE
)
3752 sym_sec
= bfd_section_from_elf_index (ibfd
,
3756 skip
= sym_sec
->output_section
== bfd_abs_section_ptr
;
3759 /* We'll be keeping this opd entry. */
3763 /* Redefine the function descriptor symbol
3764 to this location in the opd section.
3765 We've checked above that opd relocs are
3767 struct elf_link_hash_entry
*fdh
;
3768 struct ppc_link_hash_entry
*fh
;
3770 fh
= (struct ppc_link_hash_entry
*) h
;
3771 BFD_ASSERT (fh
->is_func
);
3773 fdh
->root
.u
.def
.value
= wptr
- sec
->contents
;
3777 /* Local syms are a bit tricky. We could
3778 tweak them as they can be cached, but
3779 we'd need to look through the local syms
3780 for the function descriptor sym which we
3781 don't have at the moment. So keep an
3782 array of adjustments. */
3783 adjust
[(rel
->r_offset
+ wptr
- rptr
) / 24]
3788 memcpy (wptr
, rptr
, 24);
3795 /* We need to adjust any reloc offsets to point to the
3796 new opd entries. While we're at it, we may as well
3797 remove redundant relocs. */
3800 rel
->r_offset
+= wptr
- rptr
;
3801 if (write_rel
!= rel
)
3802 memcpy (write_rel
, rel
, sizeof (*rel
));
3807 sec
->_cooked_size
= wptr
- sec
->contents
;
3808 sec
->reloc_count
= write_rel
- relstart
;
3810 else if (elf_section_data (sec
)->relocs
!= relstart
)
3813 if (local_syms
!= NULL
3814 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3816 if (!info
->keep_memory
)
3819 symtab_hdr
->contents
= (unsigned char *) local_syms
;
3826 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3827 will be called from elflink.h. If elflink.h doesn't call our
3828 finish_dynamic_symbol routine, we'll need to do something about
3829 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3830 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3832 && ((INFO)->shared \
3833 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3834 && ((H)->dynindx != -1 \
3835 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3837 /* Allocate space in .plt, .got and associated reloc sections for
3841 allocate_dynrelocs (h
, inf
)
3842 struct elf_link_hash_entry
*h
;
3845 struct bfd_link_info
*info
;
3846 struct ppc_link_hash_table
*htab
;
3848 struct ppc_link_hash_entry
*eh
;
3849 struct ppc_dyn_relocs
*p
;
3851 if (h
->root
.type
== bfd_link_hash_indirect
)
3854 if (h
->root
.type
== bfd_link_hash_warning
)
3855 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3857 info
= (struct bfd_link_info
*) inf
;
3858 htab
= ppc_hash_table (info
);
3860 if (htab
->elf
.dynamic_sections_created
3861 && h
->plt
.refcount
> 0
3862 && h
->dynindx
!= -1)
3864 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
3866 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3868 /* If this is the first .plt entry, make room for the special
3871 if (s
->_raw_size
== 0)
3872 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3874 h
->plt
.offset
= s
->_raw_size
;
3876 /* Make room for this entry. */
3877 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3879 /* Make room for the .glink code. */
3881 if (s
->_raw_size
== 0)
3882 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
3883 /* We need bigger stubs past index 32767. */
3884 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
3886 s
->_raw_size
+= 2*4;
3888 /* We also need to make an entry in the .rela.plt section. */
3890 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3894 h
->plt
.offset
= (bfd_vma
) -1;
3895 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3900 h
->plt
.offset
= (bfd_vma
) -1;
3901 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3904 if (h
->got
.refcount
> 0)
3908 /* Make sure this symbol is output as a dynamic symbol.
3909 Undefined weak syms won't yet be marked as dynamic. */
3910 if (h
->dynindx
== -1
3911 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3913 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3918 h
->got
.offset
= s
->_raw_size
;
3920 dyn
= htab
->elf
.dynamic_sections_created
;
3921 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
3922 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
3925 h
->got
.offset
= (bfd_vma
) -1;
3927 eh
= (struct ppc_link_hash_entry
*) h
;
3928 if (eh
->dyn_relocs
== NULL
)
3931 /* In the shared -Bsymbolic case, discard space allocated for
3932 dynamic pc-relative relocs against symbols which turn out to be
3933 defined in regular objects. For the normal shared case, discard
3934 space for relocs that have become local due to symbol visibility
3939 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3940 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3943 struct ppc_dyn_relocs
**pp
;
3945 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3947 p
->count
-= p
->pc_count
;
3958 /* For the non-shared case, discard space for relocs against
3959 symbols which turn out to need copy relocs or are not
3962 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3963 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3964 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3965 || (htab
->elf
.dynamic_sections_created
3966 && (h
->root
.type
== bfd_link_hash_undefweak
3967 || h
->root
.type
== bfd_link_hash_undefined
))))
3969 /* Make sure this symbol is output as a dynamic symbol.
3970 Undefined weak syms won't yet be marked as dynamic. */
3971 if (h
->dynindx
== -1
3972 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3974 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3978 /* If that succeeded, we know we'll be keeping all the
3980 if (h
->dynindx
!= -1)
3984 eh
->dyn_relocs
= NULL
;
3989 /* Finally, allocate space. */
3990 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3992 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3993 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
3999 /* Find any dynamic relocs that apply to read-only sections. */
4002 readonly_dynrelocs (h
, inf
)
4003 struct elf_link_hash_entry
*h
;
4006 struct ppc_link_hash_entry
*eh
;
4007 struct ppc_dyn_relocs
*p
;
4009 if (h
->root
.type
== bfd_link_hash_warning
)
4010 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4012 eh
= (struct ppc_link_hash_entry
*) h
;
4013 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4015 asection
*s
= p
->sec
->output_section
;
4017 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4019 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4021 info
->flags
|= DF_TEXTREL
;
4023 /* Not an error, just cut short the traversal. */
4030 /* Set the sizes of the dynamic sections. */
4033 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
4034 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4035 struct bfd_link_info
*info
;
4037 struct ppc_link_hash_table
*htab
;
4043 htab
= ppc_hash_table (info
);
4044 dynobj
= htab
->elf
.dynobj
;
4048 if (htab
->elf
.dynamic_sections_created
)
4050 /* Set the contents of the .interp section to the interpreter. */
4053 s
= bfd_get_section_by_name (dynobj
, ".interp");
4056 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4057 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4061 /* Set up .got offsets for local syms, and space for local dynamic
4063 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4065 bfd_signed_vma
*local_got
;
4066 bfd_signed_vma
*end_local_got
;
4067 bfd_size_type locsymcount
;
4068 Elf_Internal_Shdr
*symtab_hdr
;
4071 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4074 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4076 struct ppc_dyn_relocs
*p
;
4078 for (p
= *((struct ppc_dyn_relocs
**)
4079 &elf_section_data (s
)->local_dynrel
);
4083 if (!bfd_is_abs_section (p
->sec
)
4084 && bfd_is_abs_section (p
->sec
->output_section
))
4086 /* Input section has been discarded, either because
4087 it is a copy of a linkonce section or due to
4088 linker script /DISCARD/, so we'll be discarding
4091 else if (p
->count
!= 0)
4093 srel
= elf_section_data (p
->sec
)->sreloc
;
4094 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4095 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4096 info
->flags
|= DF_TEXTREL
;
4101 local_got
= elf_local_got_refcounts (ibfd
);
4105 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4106 locsymcount
= symtab_hdr
->sh_info
;
4107 end_local_got
= local_got
+ locsymcount
;
4109 srel
= htab
->srelgot
;
4110 for (; local_got
< end_local_got
; ++local_got
)
4114 *local_got
= s
->_raw_size
;
4117 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
4120 *local_got
= (bfd_vma
) -1;
4124 if (!edit_opd (output_bfd
, info
))
4127 /* Allocate global sym .plt and .got entries, and space for global
4128 sym dynamic relocs. */
4129 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
4131 /* We now have determined the sizes of the various dynamic sections.
4132 Allocate memory for them. */
4134 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4136 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4139 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
4140 /* These haven't been allocated yet; don't strip. */
4142 else if (s
== htab
->splt
4144 || s
== htab
->sglink
)
4146 /* Strip this section if we don't need it; see the
4149 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4151 if (s
->_raw_size
== 0)
4153 /* If we don't need this section, strip it from the
4154 output file. This is mostly to handle .rela.bss and
4155 .rela.plt. We must create both sections in
4156 create_dynamic_sections, because they must be created
4157 before the linker maps input sections to output
4158 sections. The linker does that before
4159 adjust_dynamic_symbol is called, and it is that
4160 function which decides whether anything needs to go
4161 into these sections. */
4165 if (s
!= htab
->srelplt
)
4168 /* We use the reloc_count field as a counter if we need
4169 to copy relocs into the output file. */
4175 /* It's not one of our sections, so don't allocate space. */
4179 if (s
->_raw_size
== 0)
4181 _bfd_strip_section_from_output (info
, s
);
4185 /* .plt is in the bss section. We don't initialise it. */
4186 if ((s
->flags
& SEC_LOAD
) == 0)
4189 /* Allocate memory for the section contents. We use bfd_zalloc
4190 here in case unused entries are not reclaimed before the
4191 section's contents are written out. This should not happen,
4192 but this way if it does, we get a R_PPC64_NONE reloc instead
4194 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4195 if (s
->contents
== NULL
)
4199 if (htab
->elf
.dynamic_sections_created
)
4201 /* Add some entries to the .dynamic section. We fill in the
4202 values later, in ppc64_elf_finish_dynamic_sections, but we
4203 must add the entries now so that we get the correct size for
4204 the .dynamic section. The DT_DEBUG entry is filled in by the
4205 dynamic linker and used by the debugger. */
4206 #define add_dynamic_entry(TAG, VAL) \
4207 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4211 if (!add_dynamic_entry (DT_DEBUG
, 0))
4215 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
4217 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4218 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4219 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4220 || !add_dynamic_entry (DT_JMPREL
, 0)
4221 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
4227 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
4228 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
4234 if (!add_dynamic_entry (DT_RELA
, 0)
4235 || !add_dynamic_entry (DT_RELASZ
, 0)
4236 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4239 /* If any dynamic relocs apply to a read-only section,
4240 then we need a DT_TEXTREL entry. */
4241 if ((info
->flags
& DF_TEXTREL
) == 0)
4242 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
4245 if ((info
->flags
& DF_TEXTREL
) != 0)
4247 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4252 #undef add_dynamic_entry
4257 /* Determine the type of stub needed, if any, for a call. */
4259 static INLINE
enum ppc_stub_type
4260 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
4261 asection
*input_sec
;
4262 const Elf_Internal_Rela
*rel
;
4263 struct ppc_link_hash_entry
**hash
;
4264 bfd_vma destination
;
4266 struct ppc_link_hash_entry
*h
= *hash
;
4268 bfd_vma branch_offset
;
4269 bfd_vma max_branch_offset
;
4270 unsigned int r_type
;
4275 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
4276 && h
->oh
->dynindx
!= -1)
4278 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
4279 return ppc_stub_plt_call
;
4282 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
4283 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
4284 return ppc_stub_none
;
4287 /* Determine where the call point is. */
4288 location
= (input_sec
->output_offset
4289 + input_sec
->output_section
->vma
4292 branch_offset
= destination
- location
;
4293 r_type
= ELF64_R_TYPE (rel
->r_info
);
4295 /* Determine if a long branch stub is needed. */
4296 max_branch_offset
= 1 << 25;
4297 if (r_type
!= (unsigned int) R_PPC64_REL24
)
4298 max_branch_offset
= 1 << 15;
4300 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
4301 /* We need a stub. Figure out whether a long_branch or plt_branch
4303 return ppc_stub_long_branch
;
4305 return ppc_stub_none
;
4308 /* Build a .plt call stub. */
4311 build_plt_stub (obfd
, p
, offset
, glink
)
4317 #define PPC_LO(v) ((v) & 0xffff)
4318 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4319 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4322 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
4323 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
4325 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
4326 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4327 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4328 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4330 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
4331 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4332 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4334 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
4335 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4336 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
4341 ppc_build_one_stub (gen_entry
, in_arg
)
4342 struct bfd_hash_entry
*gen_entry
;
4345 struct ppc_stub_hash_entry
*stub_entry
;
4346 struct ppc_branch_hash_entry
*br_entry
;
4347 struct bfd_link_info
*info
;
4348 struct ppc_link_hash_table
*htab
;
4357 /* Massage our args to the form they really have. */
4358 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4359 info
= (struct bfd_link_info
*) in_arg
;
4361 htab
= ppc_hash_table (info
);
4362 stub_sec
= stub_entry
->stub_sec
;
4364 /* Make a note of the offset within the stubs for this entry. */
4365 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
4366 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4368 stub_bfd
= stub_sec
->owner
;
4370 switch (stub_entry
->stub_type
)
4372 case ppc_stub_long_branch
:
4373 /* Branches are relative. This is where we are going to. */
4374 off
= (stub_entry
->target_value
4375 + stub_entry
->target_section
->output_offset
4376 + stub_entry
->target_section
->output_section
->vma
);
4378 /* And this is where we are coming from. */
4379 off
-= (stub_entry
->stub_offset
4380 + stub_sec
->output_offset
4381 + stub_sec
->output_section
->vma
);
4383 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
4385 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
4389 case ppc_stub_plt_branch
:
4390 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4391 stub_entry
->root
.string
+ 9,
4393 if (br_entry
== NULL
)
4395 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
4396 stub_entry
->root
.string
+ 9);
4397 htab
->stub_error
= true;
4401 off
= (stub_entry
->target_value
4402 + stub_entry
->target_section
->output_offset
4403 + stub_entry
->target_section
->output_section
->vma
);
4405 bfd_put_64 (htab
->sbrlt
->owner
, off
,
4406 htab
->sbrlt
->contents
+ br_entry
->offset
);
4410 /* Create a reloc for the branch lookup table entry. */
4411 Elf_Internal_Rela rela
;
4412 Elf64_External_Rela
*r
;
4414 rela
.r_offset
= (br_entry
->offset
4415 + htab
->sbrlt
->output_offset
4416 + htab
->sbrlt
->output_section
->vma
);
4417 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
4418 rela
.r_addend
= off
;
4420 r
= (Elf64_External_Rela
*) htab
->srelbrlt
->contents
;
4421 r
+= htab
->srelbrlt
->reloc_count
++;
4422 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, r
);
4425 off
= (br_entry
->offset
4426 + htab
->sbrlt
->output_offset
4427 + htab
->sbrlt
->output_section
->vma
4428 - elf_gp (htab
->sbrlt
->output_section
->owner
)
4431 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4433 (*_bfd_error_handler
)
4434 (_("linkage table error against `%s'"),
4435 stub_entry
->root
.string
);
4436 bfd_set_error (bfd_error_bad_value
);
4437 htab
->stub_error
= true;
4442 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
4443 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
4444 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
4445 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
4449 case ppc_stub_plt_call
:
4450 /* Build the .glink lazy link call stub. */
4451 p
= htab
->sglink
->contents
+ htab
->sglink
->_cooked_size
;
4452 indx
= htab
->sglink
->reloc_count
;
4455 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
4460 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
4462 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
4465 bfd_put_32 (htab
->sglink
->owner
,
4466 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
4468 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
4469 htab
->sglink
->reloc_count
+= 1;
4471 /* Do the best we can for shared libraries built without
4472 exporting ".foo" for each "foo". This can happen when symbol
4473 versioning scripts strip all bar a subset of symbols. */
4474 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
4475 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
4477 /* Point the symbol at the stub. There may be multiple stubs,
4478 we don't really care; The main thing is to make this sym
4479 defined somewhere. */
4480 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
4481 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
4482 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
4485 /* Now build the stub. */
4486 off
= stub_entry
->h
->elf
.plt
.offset
;
4487 if (off
>= (bfd_vma
) -2)
4490 off
&= ~ (bfd_vma
) 1;
4491 off
+= (htab
->splt
->output_offset
4492 + htab
->splt
->output_section
->vma
4493 - elf_gp (htab
->splt
->output_section
->owner
)
4496 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4498 (*_bfd_error_handler
)
4499 (_("linkage table error against `%s'"),
4500 stub_entry
->h
->elf
.root
.root
.string
);
4501 bfd_set_error (bfd_error_bad_value
);
4502 htab
->stub_error
= true;
4506 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
4515 stub_sec
->_cooked_size
+= size
;
4519 /* As above, but don't actually build the stub. Just bump offset so
4520 we know stub section sizes, and select plt_branch stubs where
4521 long_branch stubs won't do. */
4524 ppc_size_one_stub (gen_entry
, in_arg
)
4525 struct bfd_hash_entry
*gen_entry
;
4528 struct ppc_stub_hash_entry
*stub_entry
;
4529 struct ppc_link_hash_table
*htab
;
4533 /* Massage our args to the form they really have. */
4534 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4535 htab
= (struct ppc_link_hash_table
*) in_arg
;
4537 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
4539 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
4540 off
+= (htab
->splt
->output_offset
4541 + htab
->splt
->output_section
->vma
4542 - elf_gp (htab
->splt
->output_section
->owner
)
4546 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
4551 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4552 stub_entry
->stub_type
= ppc_stub_long_branch
;
4555 off
= (stub_entry
->target_value
4556 + stub_entry
->target_section
->output_offset
4557 + stub_entry
->target_section
->output_section
->vma
);
4558 off
-= (stub_entry
->stub_sec
->_raw_size
4559 + stub_entry
->stub_sec
->output_offset
4560 + stub_entry
->stub_sec
->output_section
->vma
);
4562 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
4564 struct ppc_branch_hash_entry
*br_entry
;
4566 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4567 stub_entry
->root
.string
+ 9,
4569 if (br_entry
== NULL
)
4571 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4572 stub_entry
->root
.string
+ 9);
4573 htab
->stub_error
= true;
4577 if (br_entry
->iter
!= htab
->stub_iteration
)
4579 br_entry
->iter
= htab
->stub_iteration
;
4580 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4581 htab
->sbrlt
->_raw_size
+= 8;
4583 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4588 stub_entry
->stub_sec
->_raw_size
+= size
;
4592 /* Set up various things so that we can make a list of input sections
4593 for each output section included in the link. Returns -1 on error,
4594 0 when no stubs will be needed, and 1 on success. */
4597 ppc64_elf_setup_section_lists (output_bfd
, info
)
4599 struct bfd_link_info
*info
;
4602 int top_id
, top_index
;
4604 asection
**input_list
, **list
;
4606 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4608 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
4609 || htab
->sbrlt
== NULL
)
4612 /* Find the top input section id. */
4613 for (input_bfd
= info
->input_bfds
, top_id
= 0;
4615 input_bfd
= input_bfd
->link_next
)
4617 for (section
= input_bfd
->sections
;
4619 section
= section
->next
)
4621 if (top_id
< section
->id
)
4622 top_id
= section
->id
;
4626 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4627 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4628 if (htab
->stub_group
== NULL
)
4631 /* We can't use output_bfd->section_count here to find the top output
4632 section index as some sections may have been removed, and
4633 _bfd_strip_section_from_output doesn't renumber the indices. */
4634 for (section
= output_bfd
->sections
, top_index
= 0;
4636 section
= section
->next
)
4638 if (top_index
< section
->index
)
4639 top_index
= section
->index
;
4642 htab
->top_index
= top_index
;
4643 amt
= sizeof (asection
*) * (top_index
+ 1);
4644 input_list
= (asection
**) bfd_malloc (amt
);
4645 htab
->input_list
= input_list
;
4646 if (input_list
== NULL
)
4649 /* For sections we aren't interested in, mark their entries with a
4650 value we can check later. */
4651 list
= input_list
+ top_index
;
4653 *list
= bfd_abs_section_ptr
;
4654 while (list
-- != input_list
);
4656 for (section
= output_bfd
->sections
;
4658 section
= section
->next
)
4660 if ((section
->flags
& SEC_CODE
) != 0)
4661 input_list
[section
->index
] = NULL
;
4667 /* The linker repeatedly calls this function for each input section,
4668 in the order that input sections are linked into output sections.
4669 Build lists of input sections to determine groupings between which
4670 we may insert linker stubs. */
4673 ppc64_elf_next_input_section (info
, isec
)
4674 struct bfd_link_info
*info
;
4677 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4679 if (isec
->output_section
->index
<= htab
->top_index
)
4681 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4682 if (*list
!= bfd_abs_section_ptr
)
4684 /* Steal the link_sec pointer for our list. */
4685 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4686 /* This happens to make the list in reverse order,
4687 which is what we want. */
4688 PREV_SEC (isec
) = *list
;
4694 /* See whether we can group stub sections together. Grouping stub
4695 sections may result in fewer stubs. More importantly, we need to
4696 put all .init* and .fini* stubs at the beginning of the .init or
4697 .fini output sections respectively, because glibc splits the
4698 _init and _fini functions into multiple parts. Putting a stub in
4699 the middle of a function is not a good idea. */
4702 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4703 struct ppc_link_hash_table
*htab
;
4704 bfd_size_type stub_group_size
;
4705 boolean stubs_always_before_branch
;
4707 asection
**list
= htab
->input_list
+ htab
->top_index
;
4710 asection
*tail
= *list
;
4711 if (tail
== bfd_abs_section_ptr
)
4713 while (tail
!= NULL
)
4717 bfd_size_type total
;
4720 if (tail
->_cooked_size
)
4721 total
= tail
->_cooked_size
;
4723 total
= tail
->_raw_size
;
4724 while ((prev
= PREV_SEC (curr
)) != NULL
4725 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4729 /* OK, the size from the start of CURR to the end is less
4730 than stub_group_size and thus can be handled by one stub
4731 section. (or the tail section is itself larger than
4732 stub_group_size, in which case we may be toast.) We
4733 should really be keeping track of the total size of stubs
4734 added here, as stubs contribute to the final output
4735 section size. That's a little tricky, and this way will
4736 only break if stubs added make the total size more than
4737 2^25, ie. for the default stub_group_size, if stubs total
4738 more than 2834432 bytes, or over 100000 plt call stubs. */
4741 prev
= PREV_SEC (tail
);
4742 /* Set up this stub group. */
4743 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4745 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4747 /* But wait, there's more! Input sections up to stub_group_size
4748 bytes before the stub section can be handled by it too. */
4749 if (!stubs_always_before_branch
)
4753 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4757 prev
= PREV_SEC (tail
);
4758 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4764 while (list
-- != htab
->input_list
);
4765 free (htab
->input_list
);
4769 /* Determine and set the size of the stub section for a final link.
4771 The basic idea here is to examine all the relocations looking for
4772 PC-relative calls to a target that is unreachable with a "bl"
4776 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
4777 add_stub_section
, layout_sections_again
)
4780 struct bfd_link_info
*info
;
4781 bfd_signed_vma group_size
;
4782 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
4783 void (*layout_sections_again
) PARAMS ((void));
4785 bfd_size_type stub_group_size
;
4786 boolean stubs_always_before_branch
;
4787 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4789 /* Stash our params away. */
4790 htab
->stub_bfd
= stub_bfd
;
4791 htab
->add_stub_section
= add_stub_section
;
4792 htab
->layout_sections_again
= layout_sections_again
;
4793 stubs_always_before_branch
= group_size
< 0;
4795 stub_group_size
= -group_size
;
4797 stub_group_size
= group_size
;
4798 if (stub_group_size
== 1)
4800 /* Default values. */
4801 stub_group_size
= 30720000;
4802 if (htab
->has_14bit_branch
)
4803 stub_group_size
= 30000;
4806 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4811 unsigned int bfd_indx
;
4813 boolean stub_changed
;
4815 htab
->stub_iteration
+= 1;
4816 stub_changed
= false;
4818 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4820 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4822 Elf_Internal_Shdr
*symtab_hdr
;
4824 Elf_Internal_Sym
*local_syms
= NULL
;
4826 /* We'll need the symbol table in a second. */
4827 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4828 if (symtab_hdr
->sh_info
== 0)
4831 /* Walk over each section attached to the input bfd. */
4832 for (section
= input_bfd
->sections
;
4834 section
= section
->next
)
4836 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4838 /* If there aren't any relocs, then there's nothing more
4840 if ((section
->flags
& SEC_RELOC
) == 0
4841 || section
->reloc_count
== 0)
4844 /* If this section is a link-once section that will be
4845 discarded, then don't create any stubs. */
4846 if (section
->output_section
== NULL
4847 || section
->output_section
->owner
!= output_bfd
)
4850 /* Get the relocs. */
4852 = _bfd_elf64_link_read_relocs (input_bfd
, section
, NULL
,
4853 (Elf_Internal_Rela
*) NULL
,
4855 if (internal_relocs
== NULL
)
4856 goto error_ret_free_local
;
4858 /* Now examine each relocation. */
4859 irela
= internal_relocs
;
4860 irelaend
= irela
+ section
->reloc_count
;
4861 for (; irela
< irelaend
; irela
++)
4863 unsigned int r_type
, r_indx
;
4864 enum ppc_stub_type stub_type
;
4865 struct ppc_stub_hash_entry
*stub_entry
;
4868 bfd_vma destination
;
4869 struct ppc_link_hash_entry
*hash
;
4871 const asection
*id_sec
;
4873 r_type
= ELF64_R_TYPE (irela
->r_info
);
4874 r_indx
= ELF64_R_SYM (irela
->r_info
);
4876 if (r_type
>= (unsigned int) R_PPC_max
)
4878 bfd_set_error (bfd_error_bad_value
);
4879 goto error_ret_free_internal
;
4882 /* Only look for stubs on branch instructions. */
4883 if (r_type
!= (unsigned int) R_PPC64_REL24
4884 && r_type
!= (unsigned int) R_PPC64_REL14
4885 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
4886 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
4889 /* Now determine the call target, its name, value,
4895 if (r_indx
< symtab_hdr
->sh_info
)
4897 /* It's a local symbol. */
4898 Elf_Internal_Sym
*sym
;
4899 Elf_Internal_Shdr
*hdr
;
4901 if (local_syms
== NULL
)
4904 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4905 if (local_syms
== NULL
)
4907 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4908 symtab_hdr
->sh_info
, 0,
4910 if (local_syms
== NULL
)
4911 goto error_ret_free_internal
;
4913 sym
= local_syms
+ r_indx
;
4914 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4915 sym_sec
= hdr
->bfd_section
;
4916 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4917 sym_value
= sym
->st_value
;
4918 destination
= (sym_value
+ irela
->r_addend
4919 + sym_sec
->output_offset
4920 + sym_sec
->output_section
->vma
);
4924 /* It's an external symbol. */
4927 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4928 hash
= ((struct ppc_link_hash_entry
*)
4929 elf_sym_hashes (input_bfd
)[e_indx
]);
4931 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
4932 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
4933 hash
= ((struct ppc_link_hash_entry
*)
4934 hash
->elf
.root
.u
.i
.link
);
4936 if (hash
->elf
.root
.type
== bfd_link_hash_defined
4937 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
4939 sym_sec
= hash
->elf
.root
.u
.def
.section
;
4940 sym_value
= hash
->elf
.root
.u
.def
.value
;
4941 if (sym_sec
->output_section
!= NULL
)
4942 destination
= (sym_value
+ irela
->r_addend
4943 + sym_sec
->output_offset
4944 + sym_sec
->output_section
->vma
);
4946 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
4948 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
4952 bfd_set_error (bfd_error_bad_value
);
4953 goto error_ret_free_internal
;
4957 /* Determine what (if any) linker stub is needed. */
4958 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
4960 if (stub_type
== ppc_stub_none
)
4963 /* Support for grouping stub sections. */
4964 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4966 /* Get the name of this stub. */
4967 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
4969 goto error_ret_free_internal
;
4971 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4972 stub_name
, false, false);
4973 if (stub_entry
!= NULL
)
4975 /* The proper stub has already been created. */
4980 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
4981 if (stub_entry
== NULL
)
4984 error_ret_free_internal
:
4985 if (elf_section_data (section
)->relocs
== NULL
)
4986 free (internal_relocs
);
4987 error_ret_free_local
:
4988 if (local_syms
!= NULL
4989 && (symtab_hdr
->contents
4990 != (unsigned char *) local_syms
))
4995 stub_entry
->target_value
= sym_value
;
4996 stub_entry
->target_section
= sym_sec
;
4997 stub_entry
->stub_type
= stub_type
;
4998 stub_entry
->h
= hash
;
4999 stub_changed
= true;
5002 /* We're done with the internal relocs, free them. */
5003 if (elf_section_data (section
)->relocs
!= internal_relocs
)
5004 free (internal_relocs
);
5007 if (local_syms
!= NULL
5008 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5010 if (!info
->keep_memory
)
5013 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5020 /* OK, we've added some stubs. Find out the new size of the
5022 for (stub_sec
= htab
->stub_bfd
->sections
;
5024 stub_sec
= stub_sec
->next
)
5026 stub_sec
->_raw_size
= 0;
5027 stub_sec
->_cooked_size
= 0;
5029 htab
->sbrlt
->_raw_size
= 0;
5030 htab
->sbrlt
->_cooked_size
= 0;
5032 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
5034 /* Ask the linker to do its stuff. */
5035 (*htab
->layout_sections_again
) ();
5038 /* It would be nice to strip .branch_lt from the output if the
5039 section is empty, but it's too late. If we strip sections here,
5040 the dynamic symbol table is corrupted since the section symbol
5041 for the stripped section isn't written. */
5046 /* Called after we have determined section placement. If sections
5047 move, we'll be called again. Provide a value for TOCstart. */
5050 ppc64_elf_toc (obfd
)
5056 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5057 order. The TOC starts where the first of these sections starts. */
5058 s
= bfd_get_section_by_name (obfd
, ".got");
5060 s
= bfd_get_section_by_name (obfd
, ".toc");
5062 s
= bfd_get_section_by_name (obfd
, ".tocbss");
5064 s
= bfd_get_section_by_name (obfd
, ".plt");
5067 /* This may happen for
5068 o references to TOC base (SYM@toc / TOC[tc0]) without a
5071 o --gc-sections and empty TOC sections
5073 FIXME: Warn user? */
5075 /* Look for a likely section. We probably won't even be
5077 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5078 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
5079 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5082 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5083 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
5084 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5087 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5088 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
5091 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5092 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
5098 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
5103 /* Build all the stubs associated with the current output file.
5104 The stubs are kept in a hash table attached to the main linker
5105 hash table. This function is called via gldelf64ppc_finish. */
5108 ppc64_elf_build_stubs (info
)
5109 struct bfd_link_info
*info
;
5111 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5116 for (stub_sec
= htab
->stub_bfd
->sections
;
5118 stub_sec
= stub_sec
->next
)
5122 /* Allocate memory to hold the linker stubs. */
5123 size
= stub_sec
->_raw_size
;
5126 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
5127 if (stub_sec
->contents
== NULL
)
5130 stub_sec
->_cooked_size
= 0;
5133 if (htab
->splt
!= NULL
)
5135 /* Build the .glink plt call stub. */
5136 plt_r2
= (htab
->splt
->output_offset
5137 + htab
->splt
->output_section
->vma
5138 - elf_gp (htab
->splt
->output_section
->owner
)
5140 p
= htab
->sglink
->contents
;
5141 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
5142 while (p
- htab
->sglink
->contents
< GLINK_CALL_STUB_SIZE
)
5144 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
5147 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
5149 /* Use reloc_count to count entries. */
5150 htab
->sglink
->reloc_count
= 0;
5153 if (htab
->sbrlt
->_raw_size
!= 0)
5155 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
5156 htab
->sbrlt
->_raw_size
);
5157 if (htab
->sbrlt
->contents
== NULL
)
5161 /* Build the stubs as directed by the stub hash table. */
5162 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
5163 htab
->sglink
->reloc_count
= 0;
5165 for (stub_sec
= htab
->stub_bfd
->sections
;
5167 stub_sec
= stub_sec
->next
)
5169 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
5173 if (stub_sec
!= NULL
5174 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
5176 htab
->stub_error
= true;
5177 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
5180 return !htab
->stub_error
;
5183 /* The RELOCATE_SECTION function is called by the ELF backend linker
5184 to handle the relocations for a section.
5186 The relocs are always passed as Rela structures; if the section
5187 actually uses Rel structures, the r_addend field will always be
5190 This function is responsible for adjust the section contents as
5191 necessary, and (if using Rela relocs and generating a
5192 relocateable output file) adjusting the reloc addend as
5195 This function does not have to worry about setting the reloc
5196 address or the reloc symbol index.
5198 LOCAL_SYMS is a pointer to the swapped in local symbols.
5200 LOCAL_SECTIONS is an array giving the section in the input file
5201 corresponding to the st_shndx field of each local symbol.
5203 The global hash table entry for the global symbols can be found
5204 via elf_sym_hashes (input_bfd).
5206 When generating relocateable output, this function must handle
5207 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5208 going to be the section symbol corresponding to the output
5209 section, which means that the addend must be adjusted
5213 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5214 contents
, relocs
, local_syms
, local_sections
)
5216 struct bfd_link_info
*info
;
5218 asection
*input_section
;
5220 Elf_Internal_Rela
*relocs
;
5221 Elf_Internal_Sym
*local_syms
;
5222 asection
**local_sections
;
5224 struct ppc_link_hash_table
*htab
;
5225 Elf_Internal_Shdr
*symtab_hdr
;
5226 struct elf_link_hash_entry
**sym_hashes
;
5227 Elf_Internal_Rela
*rel
;
5228 Elf_Internal_Rela
*relend
;
5229 bfd_vma
*local_got_offsets
;
5233 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5234 boolean is_power4
= false;
5236 if (info
->relocateable
)
5239 /* Initialize howto table if needed. */
5240 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5243 htab
= ppc_hash_table (info
);
5244 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5245 TOCstart
= elf_gp (output_bfd
);
5246 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5247 sym_hashes
= elf_sym_hashes (input_bfd
);
5248 is_opd
= elf_section_data (input_section
)->tdata
!= NULL
;
5251 relend
= relocs
+ input_section
->reloc_count
;
5252 for (; rel
< relend
; rel
++)
5254 enum elf_ppc_reloc_type r_type
;
5257 bfd_reloc_status_type r
;
5258 Elf_Internal_Sym
*sym
;
5260 struct elf_link_hash_entry
*h
;
5261 struct elf_link_hash_entry
*fdh
;
5262 const char *sym_name
;
5263 unsigned long r_symndx
;
5265 boolean unresolved_reloc
;
5268 struct ppc_stub_hash_entry
*stub_entry
;
5269 bfd_vma max_br_offset
;
5272 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5273 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5274 offset
= rel
->r_offset
;
5275 addend
= rel
->r_addend
;
5276 r
= bfd_reloc_other
;
5277 sym
= (Elf_Internal_Sym
*) 0;
5278 sec
= (asection
*) 0;
5279 h
= (struct elf_link_hash_entry
*) 0;
5280 sym_name
= (const char *) 0;
5281 unresolved_reloc
= false;
5284 if (r_type
== R_PPC64_TOC
)
5286 /* Relocation value is TOC base. Symbol is ignored. */
5287 relocation
= TOCstart
+ TOC_BASE_OFF
;
5289 else if (r_symndx
< symtab_hdr
->sh_info
)
5291 /* It's a local symbol. */
5292 sym
= local_syms
+ r_symndx
;
5293 sec
= local_sections
[r_symndx
];
5294 sym_name
= "<local symbol>";
5296 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
5297 /* rel may have changed, update our copy of addend. */
5298 addend
= rel
->r_addend
;
5300 if (elf_section_data (sec
) != NULL
)
5302 long *opd_sym_adjust
;
5304 opd_sym_adjust
= (long *) elf_section_data (sec
)->tdata
;
5305 if (opd_sym_adjust
!= NULL
&& sym
->st_value
% 24 == 0)
5306 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
5311 /* It's a global symbol. */
5312 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5313 while (h
->root
.type
== bfd_link_hash_indirect
5314 || h
->root
.type
== bfd_link_hash_warning
)
5315 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5316 sym_name
= h
->root
.root
.string
;
5318 if (h
->root
.type
== bfd_link_hash_defined
5319 || h
->root
.type
== bfd_link_hash_defweak
)
5321 sec
= h
->root
.u
.def
.section
;
5322 if (sec
->output_section
== NULL
)
5323 /* Set a flag that will be cleared later if we find a
5324 relocation value for this symbol. output_section
5325 is typically NULL for symbols satisfied by a shared
5327 unresolved_reloc
= true;
5329 relocation
= (h
->root
.u
.def
.value
5330 + sec
->output_section
->vma
5331 + sec
->output_offset
);
5333 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5335 else if (info
->shared
5336 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
5337 && !info
->no_undefined
5338 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5342 if (! ((*info
->callbacks
->undefined_symbol
)
5343 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5344 offset
, (!info
->shared
5345 || info
->no_undefined
5346 || ELF_ST_VISIBILITY (h
->other
)))))
5352 /* First handle relocations that tweak non-addend part of insn. */
5359 /* Branch taken prediction relocations. */
5360 case R_PPC64_ADDR14_BRTAKEN
:
5361 case R_PPC64_REL14_BRTAKEN
:
5362 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5365 /* Branch not taken prediction relocations. */
5366 case R_PPC64_ADDR14_BRNTAKEN
:
5367 case R_PPC64_REL14_BRNTAKEN
:
5368 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
5371 /* Set 'a' bit. This is 0b00010 in BO field for branch
5372 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5373 for branch on CTR insns (BO == 1a00t or 1a01t). */
5374 if ((insn
& (0x14 << 21)) == (0x04 << 21))
5376 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
5384 + input_section
->output_offset
5385 + input_section
->output_section
->vma
);
5387 /* Invert 'y' bit if not the default. */
5388 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
5392 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
5396 /* A REL24 branching to a linkage function is followed by a
5397 nop. We replace the nop with a ld in order to restore
5398 the TOC base pointer. Only calls to shared objects need
5399 to alter the TOC base. These are recognized by their
5400 need for a PLT entry. */
5402 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
5403 && fdh
->plt
.offset
!= (bfd_vma
) -1
5404 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
5405 rel
, htab
)) != NULL
)
5407 boolean can_plt_call
= 0;
5409 if (offset
+ 8 <= input_section
->_cooked_size
)
5411 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
5413 || insn
== CROR_151515
|| insn
== CROR_313131
)
5415 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
5416 contents
+ offset
+ 4);
5423 /* If this is a plain branch rather than a branch
5424 and link, don't require a nop. */
5425 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5426 if ((insn
& 1) == 0)
5432 relocation
= (stub_entry
->stub_offset
5433 + stub_entry
->stub_sec
->output_offset
5434 + stub_entry
->stub_sec
->output_section
->vma
);
5436 unresolved_reloc
= false;
5441 && h
->root
.type
== bfd_link_hash_undefweak
5445 /* Tweak calls to undefined weak functions to point at a
5446 blr. We can thus call a weak function without first
5447 checking whether the function is defined. We have a
5448 blr at the end of .sfpr. */
5449 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
5450 relocation
= (htab
->sfpr
->_raw_size
- 4
5451 + htab
->sfpr
->output_offset
5452 + htab
->sfpr
->output_section
->vma
);
5454 + input_section
->output_offset
5455 + input_section
->output_section
->vma
);
5457 /* But let's not be silly about it. If the blr isn't in
5458 reach, just go to the next instruction. */
5459 if (relocation
- from
+ (1 << 25) >= (1 << 26)
5460 || htab
->sfpr
->_raw_size
== 0)
5461 relocation
= from
+ 4;
5470 (*_bfd_error_handler
)
5471 (_("%s: unknown relocation type %d for symbol %s"),
5472 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5474 bfd_set_error (bfd_error_bad_value
);
5479 case R_PPC_GNU_VTINHERIT
:
5480 case R_PPC_GNU_VTENTRY
:
5483 /* GOT16 relocations. Like an ADDR16 using the symbol's
5484 address in the GOT as relocation value instead of the
5485 symbols value itself. Also, create a GOT entry for the
5486 symbol and put the symbol value there. */
5488 case R_PPC64_GOT16_LO
:
5489 case R_PPC64_GOT16_HI
:
5490 case R_PPC64_GOT16_HA
:
5491 case R_PPC64_GOT16_DS
:
5492 case R_PPC64_GOT16_LO_DS
:
5494 /* Relocation is to the entry for this symbol in the global
5498 if (htab
->sgot
== NULL
)
5505 off
= h
->got
.offset
;
5506 dyn
= htab
->elf
.dynamic_sections_created
;
5507 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5511 || (h
->elf_link_hash_flags
5512 & ELF_LINK_FORCED_LOCAL
))
5513 && (h
->elf_link_hash_flags
5514 & ELF_LINK_HASH_DEF_REGULAR
)))
5516 /* This is actually a static link, or it is a
5517 -Bsymbolic link and the symbol is defined
5518 locally, or the symbol was forced to be local
5519 because of a version file. We must initialize
5520 this entry in the global offset table. Since the
5521 offset must always be a multiple of 8, we use the
5522 least significant bit to record whether we have
5523 initialized it already.
5525 When doing a dynamic link, we create a .rel.got
5526 relocation entry to initialize the value. This
5527 is done in the finish_dynamic_symbol routine. */
5532 bfd_put_64 (output_bfd
, relocation
,
5533 htab
->sgot
->contents
+ off
);
5538 unresolved_reloc
= false;
5542 if (local_got_offsets
== NULL
)
5545 off
= local_got_offsets
[r_symndx
];
5547 /* The offset must always be a multiple of 8. We use
5548 the least significant bit to record whether we have
5549 already processed this entry. */
5554 bfd_put_64 (output_bfd
, relocation
,
5555 htab
->sgot
->contents
+ off
);
5559 Elf_Internal_Rela outrel
;
5560 Elf64_External_Rela
*loc
;
5562 /* We need to generate a R_PPC64_RELATIVE reloc
5563 for the dynamic linker. */
5564 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5565 + htab
->sgot
->output_offset
5567 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5568 outrel
.r_addend
= relocation
;
5569 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5570 loc
+= htab
->srelgot
->reloc_count
++;
5571 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5574 local_got_offsets
[r_symndx
] |= 1;
5578 if (off
>= (bfd_vma
) -2)
5581 relocation
= htab
->sgot
->output_offset
+ off
;
5583 /* TOC base (r2) is TOC start plus 0x8000. */
5584 addend
-= TOC_BASE_OFF
;
5588 case R_PPC64_PLT16_HA
:
5589 case R_PPC64_PLT16_HI
:
5590 case R_PPC64_PLT16_LO
:
5593 /* Relocation is to the entry for this symbol in the
5594 procedure linkage table. */
5596 /* Resolve a PLT reloc against a local symbol directly,
5597 without using the procedure linkage table. */
5601 if (h
->plt
.offset
== (bfd_vma
) -1
5602 || htab
->splt
== NULL
)
5604 /* We didn't make a PLT entry for this symbol. This
5605 happens when statically linking PIC code, or when
5606 using -Bsymbolic. */
5610 relocation
= (htab
->splt
->output_section
->vma
5611 + htab
->splt
->output_offset
5613 unresolved_reloc
= false;
5616 /* TOC16 relocs. We want the offset relative to the TOC base,
5617 which is the address of the start of the TOC plus 0x8000.
5618 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5621 case R_PPC64_TOC16_LO
:
5622 case R_PPC64_TOC16_HI
:
5623 case R_PPC64_TOC16_DS
:
5624 case R_PPC64_TOC16_LO_DS
:
5625 case R_PPC64_TOC16_HA
:
5626 addend
-= TOCstart
+ TOC_BASE_OFF
;
5629 /* Relocate against the beginning of the section. */
5630 case R_PPC64_SECTOFF
:
5631 case R_PPC64_SECTOFF_LO
:
5632 case R_PPC64_SECTOFF_HI
:
5633 case R_PPC64_SECTOFF_DS
:
5634 case R_PPC64_SECTOFF_LO_DS
:
5635 case R_PPC64_SECTOFF_HA
:
5636 if (sec
!= (asection
*) 0)
5637 addend
-= sec
->output_section
->vma
;
5641 case R_PPC64_REL14_BRNTAKEN
:
5642 case R_PPC64_REL14_BRTAKEN
:
5646 /* Relocations that may need to be propagated if this is a
5650 case R_PPC64_ADDR14
:
5651 case R_PPC64_ADDR14_BRNTAKEN
:
5652 case R_PPC64_ADDR14_BRTAKEN
:
5653 case R_PPC64_ADDR16
:
5654 case R_PPC64_ADDR16_DS
:
5655 case R_PPC64_ADDR16_HA
:
5656 case R_PPC64_ADDR16_HI
:
5657 case R_PPC64_ADDR16_HIGHER
:
5658 case R_PPC64_ADDR16_HIGHERA
:
5659 case R_PPC64_ADDR16_HIGHEST
:
5660 case R_PPC64_ADDR16_HIGHESTA
:
5661 case R_PPC64_ADDR16_LO
:
5662 case R_PPC64_ADDR16_LO_DS
:
5663 case R_PPC64_ADDR24
:
5664 case R_PPC64_ADDR30
:
5665 case R_PPC64_ADDR32
:
5666 case R_PPC64_ADDR64
:
5667 case R_PPC64_UADDR16
:
5668 case R_PPC64_UADDR32
:
5669 case R_PPC64_UADDR64
:
5670 /* r_symndx will be zero only for relocs against symbols
5671 from removed linkonce sections, or sections discarded by
5678 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5681 if (NO_OPD_RELOCS
&& is_opd
)
5685 && (IS_ABSOLUTE_RELOC (r_type
)
5688 && (! info
->symbolic
5689 || (h
->elf_link_hash_flags
5690 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5694 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5695 && (((h
->elf_link_hash_flags
5696 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5697 && (h
->elf_link_hash_flags
5698 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5699 || h
->root
.type
== bfd_link_hash_undefweak
5700 || h
->root
.type
== bfd_link_hash_undefined
)))
5702 Elf_Internal_Rela outrel
;
5703 boolean skip
, relocate
;
5705 Elf64_External_Rela
*loc
;
5707 /* When generating a dynamic object, these relocations
5708 are copied into the output file to be resolved at run
5715 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5717 if (outrel
.r_offset
== (bfd_vma
) -1)
5719 else if (outrel
.r_offset
== (bfd_vma
) -2)
5720 skip
= true, relocate
= true;
5721 outrel
.r_offset
+= (input_section
->output_section
->vma
5722 + input_section
->output_offset
);
5723 outrel
.r_addend
= addend
;
5726 memset (&outrel
, 0, sizeof outrel
);
5730 && (!IS_ABSOLUTE_RELOC (r_type
)
5733 || (h
->elf_link_hash_flags
5734 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5735 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5738 /* This symbol is local, or marked to become local,
5739 or this is an opd section reloc which must point
5740 at a local function. */
5741 outrel
.r_addend
+= relocation
;
5743 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5745 if (is_opd
&& h
!= NULL
)
5747 /* Lie about opd entries. This case occurs
5748 when building shared libraries and we
5749 reference a function in another shared
5750 lib. The same thing happens for a weak
5751 definition in an application that's
5752 overridden by a strong definition in a
5753 shared lib. (I believe this is a generic
5754 bug in binutils handling of weak syms.)
5755 In these cases we won't use the opd
5756 entry in this lib. */
5757 unresolved_reloc
= false;
5759 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5765 if (bfd_is_abs_section (sec
))
5767 else if (sec
== NULL
|| sec
->owner
== NULL
)
5769 bfd_set_error (bfd_error_bad_value
);
5776 osec
= sec
->output_section
;
5777 indx
= elf_section_data (osec
)->dynindx
;
5779 /* We are turning this relocation into one
5780 against a section symbol, so subtract out
5781 the output section's address but not the
5782 offset of the input section in the output
5784 outrel
.r_addend
-= osec
->vma
;
5787 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
5791 sreloc
= elf_section_data (input_section
)->sreloc
;
5795 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
5796 loc
+= sreloc
->reloc_count
++;
5797 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5799 /* If this reloc is against an external symbol, it will
5800 be computed at runtime, so there's no need to do
5808 case R_PPC64_GLOB_DAT
:
5809 case R_PPC64_JMP_SLOT
:
5810 case R_PPC64_RELATIVE
:
5811 /* We shouldn't ever see these dynamic relocs in relocatable
5815 case R_PPC64_PLTGOT16
:
5816 case R_PPC64_PLTGOT16_DS
:
5817 case R_PPC64_PLTGOT16_HA
:
5818 case R_PPC64_PLTGOT16_HI
:
5819 case R_PPC64_PLTGOT16_LO
:
5820 case R_PPC64_PLTGOT16_LO_DS
:
5821 case R_PPC64_PLTREL32
:
5822 case R_PPC64_PLTREL64
:
5823 /* These ones haven't been implemented yet. */
5825 (*_bfd_error_handler
)
5826 (_("%s: Relocation %s is not supported for symbol %s."),
5827 bfd_archive_filename (input_bfd
),
5828 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
5830 bfd_set_error (bfd_error_invalid_operation
);
5835 /* Do any further special processing. */
5841 case R_PPC64_ADDR16_HA
:
5842 case R_PPC64_ADDR16_HIGHERA
:
5843 case R_PPC64_ADDR16_HIGHESTA
:
5844 case R_PPC64_PLT16_HA
:
5845 case R_PPC64_TOC16_HA
:
5846 case R_PPC64_SECTOFF_HA
:
5847 /* It's just possible that this symbol is a weak symbol
5848 that's not actually defined anywhere. In that case,
5849 'sec' would be NULL, and we should leave the symbol
5850 alone (it will be set to zero elsewhere in the link). */
5852 /* Add 0x10000 if sign bit in 0:15 is set. */
5853 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
5856 case R_PPC64_ADDR16_DS
:
5857 case R_PPC64_ADDR16_LO_DS
:
5858 case R_PPC64_GOT16_DS
:
5859 case R_PPC64_GOT16_LO_DS
:
5860 case R_PPC64_PLT16_LO_DS
:
5861 case R_PPC64_SECTOFF_DS
:
5862 case R_PPC64_SECTOFF_LO_DS
:
5863 case R_PPC64_TOC16_DS
:
5864 case R_PPC64_TOC16_LO_DS
:
5865 case R_PPC64_PLTGOT16_DS
:
5866 case R_PPC64_PLTGOT16_LO_DS
:
5867 if (((relocation
+ addend
) & 3) != 0)
5869 (*_bfd_error_handler
)
5870 (_("%s: error: relocation %s not a multiple of 4"),
5871 bfd_archive_filename (input_bfd
),
5872 ppc64_elf_howto_table
[(int) r_type
]->name
);
5873 bfd_set_error (bfd_error_bad_value
);
5880 case R_PPC64_REL14_BRNTAKEN
:
5881 case R_PPC64_REL14_BRTAKEN
:
5882 max_br_offset
= 1 << 15;
5886 max_br_offset
= 1 << 25;
5889 /* If the branch is out of reach, then redirect the
5890 call to the local stub for this function. */
5892 + input_section
->output_offset
5893 + input_section
->output_section
->vma
);
5894 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
5895 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
5896 rel
, htab
)) != NULL
)
5898 /* Munge up the value and addend so that we call the stub
5899 rather than the procedure directly. */
5900 relocation
= (stub_entry
->stub_offset
5901 + stub_entry
->stub_sec
->output_offset
5902 + stub_entry
->stub_sec
->output_section
->vma
);
5908 /* FIXME: Why do we allow debugging sections to escape this error?
5909 More importantly, why do we not emit dynamic relocs above in
5910 debugging sections (which are ! SEC_ALLOC)? If we had
5911 emitted the dynamic reloc, we could remove the fudge here. */
5912 if (unresolved_reloc
5914 && (input_section
->flags
& SEC_DEBUGGING
) != 0
5915 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5917 (*_bfd_error_handler
)
5918 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5919 bfd_archive_filename (input_bfd
),
5920 bfd_get_section_name (input_bfd
, input_section
),
5921 (long) rel
->r_offset
,
5922 h
->root
.root
.string
);
5926 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
5934 if (r
!= bfd_reloc_ok
)
5940 if (h
->root
.type
== bfd_link_hash_undefweak
5941 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
5943 /* Assume this is a call protected by other code that
5944 detects the symbol is undefined. If this is the case,
5945 we can safely ignore the overflow. If not, the
5946 program is hosed anyway, and a little warning isn't
5952 name
= h
->root
.root
.string
;
5956 name
= bfd_elf_string_from_elf_section (input_bfd
,
5957 symtab_hdr
->sh_link
,
5962 name
= bfd_section_name (input_bfd
, sec
);
5965 if (r
== bfd_reloc_overflow
)
5969 if (!((*info
->callbacks
->reloc_overflow
)
5970 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
5971 rel
->r_addend
, input_bfd
, input_section
, offset
)))
5976 (*_bfd_error_handler
)
5977 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
5978 bfd_archive_filename (input_bfd
),
5979 bfd_get_section_name (input_bfd
, input_section
),
5980 (long) rel
->r_offset
, name
, (int) r
);
5989 /* Finish up dynamic symbol handling. We set the contents of various
5990 dynamic sections here. */
5993 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5995 struct bfd_link_info
*info
;
5996 struct elf_link_hash_entry
*h
;
5997 Elf_Internal_Sym
*sym
;
5999 struct ppc_link_hash_table
*htab
;
6002 htab
= ppc_hash_table (info
);
6003 dynobj
= htab
->elf
.dynobj
;
6005 if (h
->plt
.offset
!= (bfd_vma
) -1
6006 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
6008 Elf_Internal_Rela rela
;
6009 Elf64_External_Rela
*loc
;
6011 /* This symbol has an entry in the procedure linkage table. Set
6014 if (htab
->splt
== NULL
6015 || htab
->srelplt
== NULL
6016 || htab
->sglink
== NULL
)
6019 /* Create a JMP_SLOT reloc to inform the dynamic linker to
6020 fill in the PLT entry. */
6022 rela
.r_offset
= (htab
->splt
->output_section
->vma
6023 + htab
->splt
->output_offset
6025 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
6028 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
6029 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
6030 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6033 if (h
->got
.offset
!= (bfd_vma
) -1)
6035 Elf_Internal_Rela rela
;
6036 Elf64_External_Rela
*loc
;
6038 /* This symbol has an entry in the global offset table. Set it
6041 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
6044 rela
.r_offset
= (htab
->sgot
->output_section
->vma
6045 + htab
->sgot
->output_offset
6046 + (h
->got
.offset
&~ (bfd_vma
) 1));
6048 /* If this is a static link, or it is a -Bsymbolic link and the
6049 symbol is defined locally or was forced to be local because
6050 of a version file, we just want to emit a RELATIVE reloc.
6051 The entry in the global offset table will already have been
6052 initialized in the relocate_section function. */
6056 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6057 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6059 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6060 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6061 rela
.r_addend
= (h
->root
.u
.def
.value
6062 + h
->root
.u
.def
.section
->output_section
->vma
6063 + h
->root
.u
.def
.section
->output_offset
);
6067 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6068 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6069 htab
->sgot
->contents
+ h
->got
.offset
);
6070 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
6074 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
6075 loc
+= htab
->srelgot
->reloc_count
++;
6076 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6079 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6081 Elf_Internal_Rela rela
;
6082 Elf64_External_Rela
*loc
;
6084 /* This symbol needs a copy reloc. Set it up. */
6086 if (h
->dynindx
== -1
6087 || (h
->root
.type
!= bfd_link_hash_defined
6088 && h
->root
.type
!= bfd_link_hash_defweak
)
6089 || htab
->srelbss
== NULL
)
6092 rela
.r_offset
= (h
->root
.u
.def
.value
6093 + h
->root
.u
.def
.section
->output_section
->vma
6094 + h
->root
.u
.def
.section
->output_offset
);
6095 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
6097 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
6098 loc
+= htab
->srelbss
->reloc_count
++;
6099 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6102 /* Mark some specially defined symbols as absolute. */
6103 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
6104 sym
->st_shndx
= SHN_ABS
;
6109 /* Used to decide how to sort relocs in an optimal manner for the
6110 dynamic linker, before writing them out. */
6112 static enum elf_reloc_type_class
6113 ppc64_elf_reloc_type_class (rela
)
6114 const Elf_Internal_Rela
*rela
;
6116 enum elf_ppc_reloc_type r_type
;
6118 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
6121 case R_PPC64_RELATIVE
:
6122 return reloc_class_relative
;
6123 case R_PPC64_JMP_SLOT
:
6124 return reloc_class_plt
;
6126 return reloc_class_copy
;
6128 return reloc_class_normal
;
6132 /* Finish up the dynamic sections. */
6135 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
6137 struct bfd_link_info
*info
;
6139 struct ppc_link_hash_table
*htab
;
6143 htab
= ppc_hash_table (info
);
6144 dynobj
= htab
->elf
.dynobj
;
6145 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6147 if (htab
->elf
.dynamic_sections_created
)
6149 Elf64_External_Dyn
*dyncon
, *dynconend
;
6151 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
6154 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
6155 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6156 for (; dyncon
< dynconend
; dyncon
++)
6158 Elf_Internal_Dyn dyn
;
6161 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6168 case DT_PPC64_GLINK
:
6169 dyn
.d_un
.d_ptr
= (htab
->sglink
->output_section
->vma
6170 + htab
->sglink
->output_offset
);
6174 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6176 dyn
.d_un
.d_ptr
= s
->vma
;
6179 case DT_PPC64_OPDSZ
:
6180 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6182 dyn
.d_un
.d_val
= s
->_raw_size
;
6186 dyn
.d_un
.d_ptr
= (htab
->splt
->output_section
->vma
6187 + htab
->splt
->output_offset
);
6191 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
6192 + htab
->srelplt
->output_offset
);
6196 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
6200 /* Don't count procedure linkage table relocs in the
6201 overall reloc count. */
6202 if (htab
->srelplt
!= NULL
)
6203 dyn
.d_un
.d_val
-= htab
->srelplt
->_raw_size
;
6207 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6211 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
6213 /* Fill in the first entry in the global offset table.
6214 We use it to hold the link-time TOCbase. */
6215 bfd_put_64 (output_bfd
,
6216 elf_gp (output_bfd
) + TOC_BASE_OFF
,
6217 htab
->sgot
->contents
);
6219 /* Set .got entry size. */
6220 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
6223 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
6225 /* Set .plt entry size. */
6226 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
6233 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6234 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6235 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6236 #define TARGET_BIG_NAME "elf64-powerpc"
6237 #define ELF_ARCH bfd_arch_powerpc
6238 #define ELF_MACHINE_CODE EM_PPC64
6239 #define ELF_MAXPAGESIZE 0x10000
6240 #define elf_info_to_howto ppc64_elf_info_to_howto
6242 #ifdef EM_CYGNUS_POWERPC
6243 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6247 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6250 #define elf_backend_want_got_sym 0
6251 #define elf_backend_want_plt_sym 0
6252 #define elf_backend_plt_alignment 3
6253 #define elf_backend_plt_not_loaded 1
6254 #define elf_backend_got_symbol_offset 0
6255 #define elf_backend_got_header_size 8
6256 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6257 #define elf_backend_can_gc_sections 1
6258 #define elf_backend_can_refcount 1
6259 #define elf_backend_rela_normal 1
6261 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6262 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6263 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6264 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6266 #define elf_backend_object_p ppc64_elf_object_p
6267 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6268 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6269 #define elf_backend_check_relocs ppc64_elf_check_relocs
6270 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6271 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6272 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6273 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6274 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6275 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6276 #define elf_backend_relocate_section ppc64_elf_relocate_section
6277 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6278 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6279 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6281 #include "elf64-target.h"