1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
31 #include "elf64-ppc.h"
33 #define USE_RELA /* we want RELA relocations, not REL. */
36 static void ppc_howto_init
38 static reloc_howto_type *ppc64_elf_reloc_type_lookup
39 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
40 static void ppc64_elf_info_to_howto
41 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst));
42 static bfd_reloc_status_type ppc64_elf_ha_reloc
43 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
44 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
45 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
46 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
47 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
48 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
49 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
50 static bfd_reloc_status_type ppc64_elf_toc_reloc
51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
53 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
54 static bfd_reloc_status_type ppc64_elf_toc64_reloc
55 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static boolean ppc64_elf_set_private_flags
59 PARAMS ((bfd *, flagword));
60 static boolean ppc64_elf_merge_private_bfd_data
61 PARAMS ((bfd *, bfd *));
62 static boolean ppc64_elf_section_from_shdr
63 PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
66 /* The name of the dynamic interpreter. This is put in the .interp
68 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
70 /* The size in bytes of an entry in the procedure linkage table. */
71 #define PLT_ENTRY_SIZE 24
73 /* The initial size of the plt reserved for the dynamic linker. */
74 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
76 /* TOC base pointers offset from start of TOC. */
77 #define TOC_BASE_OFF (0x8000)
79 /* .plt call stub instructions. */
80 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
81 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
82 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
83 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
84 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
85 /* ld %r11,xxx+16@l(%r12) */
86 #define BCTR 0x4e800420 /* bctr */
88 /* The normal stub is this size. */
89 #define PLT_CALL_STUB_SIZE (7*4)
91 /* But sometimes the .plt entry crosses a 64k boundary, and we need
92 to adjust the high word with this insn. */
93 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
95 /* The .glink fixup call stub is the same as the .plt call stub, but
96 the first instruction restores r2, and the std is omitted. */
97 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
99 /* Always allow this much space. */
100 #define GLINK_CALL_STUB_SIZE (8*4)
103 #define NOP 0x60000000
105 /* Some other nops. */
106 #define CROR_151515 0x4def7b82
107 #define CROR_313131 0x4ffffb82
109 /* .glink entries for the first 32k functions are two instructions. */
110 #define LI_R0_0 0x38000000 /* li %r0,0 */
111 #define B_DOT 0x48000000 /* b . */
113 /* After that, we need two instructions to load the index, followed by
115 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
116 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
118 /* Instructions to save and restore floating point regs. */
119 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
120 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
121 #define BLR 0x4e800020 /* blr */
123 /* Since .opd is an array of descriptors and each entry will end up
124 with identical R_PPC64_RELATIVE relocs, there is really no need to
125 propagate .opd relocs; The dynamic linker should be taught to
126 relocate .opd without reloc entries. FIXME: .opd should be trimmed
128 #ifndef NO_OPD_RELOCS
129 #define NO_OPD_RELOCS 0
132 /* Relocation HOWTO's. */
133 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
135 static reloc_howto_type ppc64_elf_howto_raw[] = {
136 /* This reloc does nothing. */
137 HOWTO (R_PPC64_NONE, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 false, /* pc_relative */
143 complain_overflow_bitfield, /* complain_on_overflow */
144 bfd_elf_generic_reloc, /* special_function */
145 "R_PPC64_NONE", /* name */
146 false, /* partial_inplace */
149 false), /* pcrel_offset */
151 /* A standard 32 bit relocation. */
152 HOWTO (R_PPC64_ADDR32, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 false, /* pc_relative */
158 complain_overflow_bitfield, /* complain_on_overflow */
159 bfd_elf_generic_reloc, /* special_function */
160 "R_PPC64_ADDR32", /* name */
161 false, /* partial_inplace */
163 0xffffffff, /* dst_mask */
164 false), /* pcrel_offset */
166 /* An absolute 26 bit branch; the lower two bits must be zero.
167 FIXME: we don't check that, we just clear them. */
168 HOWTO (R_PPC64_ADDR24, /* type */
170 2, /* size (0 = byte, 1 = short, 2 = long) */
172 false, /* pc_relative */
174 complain_overflow_bitfield, /* complain_on_overflow */
175 bfd_elf_generic_reloc, /* special_function */
176 "R_PPC64_ADDR24", /* name */
177 false, /* partial_inplace */
179 0x3fffffc, /* dst_mask */
180 false), /* pcrel_offset */
182 /* A standard 16 bit relocation. */
183 HOWTO (R_PPC64_ADDR16, /* type */
185 1, /* size (0 = byte, 1 = short, 2 = long) */
187 false, /* pc_relative */
189 complain_overflow_bitfield, /* complain_on_overflow */
190 bfd_elf_generic_reloc, /* special_function */
191 "R_PPC64_ADDR16", /* name */
192 false, /* partial_inplace */
194 0xffff, /* dst_mask */
195 false), /* pcrel_offset */
197 /* A 16 bit relocation without overflow. */
198 HOWTO (R_PPC64_ADDR16_LO, /* type */
200 1, /* size (0 = byte, 1 = short, 2 = long) */
202 false, /* pc_relative */
204 complain_overflow_dont,/* complain_on_overflow */
205 bfd_elf_generic_reloc, /* special_function */
206 "R_PPC64_ADDR16_LO", /* name */
207 false, /* partial_inplace */
209 0xffff, /* dst_mask */
210 false), /* pcrel_offset */
212 /* Bits 16-31 of an address. */
213 HOWTO (R_PPC64_ADDR16_HI, /* type */
215 1, /* size (0 = byte, 1 = short, 2 = long) */
217 false, /* pc_relative */
219 complain_overflow_dont, /* complain_on_overflow */
220 bfd_elf_generic_reloc, /* special_function */
221 "R_PPC64_ADDR16_HI", /* name */
222 false, /* partial_inplace */
224 0xffff, /* dst_mask */
225 false), /* pcrel_offset */
227 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
228 bits, treated as a signed number, is negative. */
229 HOWTO (R_PPC64_ADDR16_HA, /* type */
231 1, /* size (0 = byte, 1 = short, 2 = long) */
233 false, /* pc_relative */
235 complain_overflow_dont, /* complain_on_overflow */
236 ppc64_elf_ha_reloc, /* special_function */
237 "R_PPC64_ADDR16_HA", /* name */
238 false, /* partial_inplace */
240 0xffff, /* dst_mask */
241 false), /* pcrel_offset */
243 /* An absolute 16 bit branch; the lower two bits must be zero.
244 FIXME: we don't check that, we just clear them. */
245 HOWTO (R_PPC64_ADDR14, /* type */
247 2, /* size (0 = byte, 1 = short, 2 = long) */
249 false, /* pc_relative */
251 complain_overflow_bitfield, /* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_PPC64_ADDR14", /* name */
254 false, /* partial_inplace */
256 0xfffc, /* dst_mask */
257 false), /* pcrel_offset */
259 /* An absolute 16 bit branch, for which bit 10 should be set to
260 indicate that the branch is expected to be taken. The lower two
261 bits must be zero. */
262 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
266 false, /* pc_relative */
268 complain_overflow_bitfield, /* complain_on_overflow */
269 ppc64_elf_brtaken_reloc, /* special_function */
270 "R_PPC64_ADDR14_BRTAKEN",/* name */
271 false, /* partial_inplace */
273 0xfffc, /* dst_mask */
274 false), /* pcrel_offset */
276 /* An absolute 16 bit branch, for which bit 10 should be set to
277 indicate that the branch is not expected to be taken. The lower
278 two bits must be zero. */
279 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 false, /* pc_relative */
285 complain_overflow_bitfield, /* complain_on_overflow */
286 ppc64_elf_brtaken_reloc, /* special_function */
287 "R_PPC64_ADDR14_BRNTAKEN",/* name */
288 false, /* partial_inplace */
290 0xfffc, /* dst_mask */
291 false), /* pcrel_offset */
293 /* A relative 26 bit branch; the lower two bits must be zero. */
294 HOWTO (R_PPC64_REL24, /* type */
296 2, /* size (0 = byte, 1 = short, 2 = long) */
298 true, /* pc_relative */
300 complain_overflow_signed, /* complain_on_overflow */
301 bfd_elf_generic_reloc, /* special_function */
302 "R_PPC64_REL24", /* name */
303 false, /* partial_inplace */
305 0x3fffffc, /* dst_mask */
306 true), /* pcrel_offset */
308 /* A relative 16 bit branch; the lower two bits must be zero. */
309 HOWTO (R_PPC64_REL14, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 true, /* pc_relative */
315 complain_overflow_signed, /* complain_on_overflow */
316 bfd_elf_generic_reloc, /* special_function */
317 "R_PPC64_REL14", /* name */
318 false, /* partial_inplace */
320 0xfffc, /* dst_mask */
321 true), /* pcrel_offset */
323 /* A relative 16 bit branch. Bit 10 should be set to indicate that
324 the branch is expected to be taken. The lower two bits must be
326 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 true, /* pc_relative */
332 complain_overflow_signed, /* complain_on_overflow */
333 ppc64_elf_brtaken_reloc, /* special_function */
334 "R_PPC64_REL14_BRTAKEN", /* name */
335 false, /* partial_inplace */
337 0xfffc, /* dst_mask */
338 true), /* pcrel_offset */
340 /* A relative 16 bit branch. Bit 10 should be set to indicate that
341 the branch is not expected to be taken. The lower two bits must
343 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 true, /* pc_relative */
349 complain_overflow_signed, /* complain_on_overflow */
350 ppc64_elf_brtaken_reloc, /* special_function */
351 "R_PPC64_REL14_BRNTAKEN",/* name */
352 false, /* partial_inplace */
354 0xfffc, /* dst_mask */
355 true), /* pcrel_offset */
357 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
359 HOWTO (R_PPC64_GOT16, /* type */
361 1, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_signed, /* complain_on_overflow */
366 ppc64_elf_unhandled_reloc, /* special_function */
367 "R_PPC64_GOT16", /* name */
368 false, /* partial_inplace */
370 0xffff, /* dst_mask */
371 false), /* pcrel_offset */
373 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
375 HOWTO (R_PPC64_GOT16_LO, /* type */
377 1, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_dont, /* complain_on_overflow */
382 ppc64_elf_unhandled_reloc, /* special_function */
383 "R_PPC64_GOT16_LO", /* name */
384 false, /* partial_inplace */
386 0xffff, /* dst_mask */
387 false), /* pcrel_offset */
389 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
391 HOWTO (R_PPC64_GOT16_HI, /* type */
393 1, /* size (0 = byte, 1 = short, 2 = long) */
395 false, /* pc_relative */
397 complain_overflow_dont,/* complain_on_overflow */
398 ppc64_elf_unhandled_reloc, /* special_function */
399 "R_PPC64_GOT16_HI", /* name */
400 false, /* partial_inplace */
402 0xffff, /* dst_mask */
403 false), /* pcrel_offset */
405 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
407 HOWTO (R_PPC64_GOT16_HA, /* type */
409 1, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_dont,/* complain_on_overflow */
414 ppc64_elf_unhandled_reloc, /* special_function */
415 "R_PPC64_GOT16_HA", /* name */
416 false, /* partial_inplace */
418 0xffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* This is used only by the dynamic linker. The symbol should exist
422 both in the object being run and in some shared library. The
423 dynamic linker copies the data addressed by the symbol from the
424 shared library into the object, because the object being
425 run has to have the data at some particular address. */
426 HOWTO (R_PPC64_COPY, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_bitfield, /* complain_on_overflow */
433 ppc64_elf_unhandled_reloc, /* special_function */
434 "R_PPC64_COPY", /* name */
435 false, /* partial_inplace */
438 false), /* pcrel_offset */
440 /* Like R_PPC64_ADDR64, but used when setting global offset table
442 HOWTO (R_PPC64_GLOB_DAT, /* type */
444 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
446 false, /* pc_relative */
448 complain_overflow_dont, /* complain_on_overflow */
449 ppc64_elf_unhandled_reloc, /* special_function */
450 "R_PPC64_GLOB_DAT", /* name */
451 false, /* partial_inplace */
453 0xffffffffffffffff, /* dst_mask */
454 false), /* pcrel_offset */
456 /* Created by the link editor. Marks a procedure linkage table
457 entry for a symbol. */
458 HOWTO (R_PPC64_JMP_SLOT, /* type */
460 0, /* size (0 = byte, 1 = short, 2 = long) */
462 false, /* pc_relative */
464 complain_overflow_dont, /* complain_on_overflow */
465 ppc64_elf_unhandled_reloc, /* special_function */
466 "R_PPC64_JMP_SLOT", /* name */
467 false, /* partial_inplace */
470 false), /* pcrel_offset */
472 /* Used only by the dynamic linker. When the object is run, this
473 doubleword64 is set to the load address of the object, plus the
475 HOWTO (R_PPC64_RELATIVE, /* type */
477 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
479 false, /* pc_relative */
481 complain_overflow_dont, /* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_PPC64_RELATIVE", /* name */
484 false, /* partial_inplace */
486 0xffffffffffffffff, /* dst_mask */
487 false), /* pcrel_offset */
489 /* Like R_PPC64_ADDR32, but may be unaligned. */
490 HOWTO (R_PPC64_UADDR32, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 false, /* pc_relative */
496 complain_overflow_bitfield, /* complain_on_overflow */
497 bfd_elf_generic_reloc, /* special_function */
498 "R_PPC64_UADDR32", /* name */
499 false, /* partial_inplace */
501 0xffffffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* Like R_PPC64_ADDR16, but may be unaligned. */
505 HOWTO (R_PPC64_UADDR16, /* type */
507 1, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield, /* complain_on_overflow */
512 bfd_elf_generic_reloc, /* special_function */
513 "R_PPC64_UADDR16", /* name */
514 false, /* partial_inplace */
516 0xffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* 32-bit PC relative. */
520 HOWTO (R_PPC64_REL32, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 true, /* pc_relative */
526 /* FIXME: Verify. Was complain_overflow_bitfield. */
527 complain_overflow_signed, /* complain_on_overflow */
528 bfd_elf_generic_reloc, /* special_function */
529 "R_PPC64_REL32", /* name */
530 false, /* partial_inplace */
532 0xffffffff, /* dst_mask */
533 true), /* pcrel_offset */
535 /* 32-bit relocation to the symbol's procedure linkage table. */
536 HOWTO (R_PPC64_PLT32, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_bitfield, /* complain_on_overflow */
543 ppc64_elf_unhandled_reloc, /* special_function */
544 "R_PPC64_PLT32", /* name */
545 false, /* partial_inplace */
548 false), /* pcrel_offset */
550 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
551 FIXME: R_PPC64_PLTREL32 not supported. */
552 HOWTO (R_PPC64_PLTREL32, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 true, /* pc_relative */
558 complain_overflow_signed, /* complain_on_overflow */
559 bfd_elf_generic_reloc, /* special_function */
560 "R_PPC64_PLTREL32", /* name */
561 false, /* partial_inplace */
564 true), /* pcrel_offset */
566 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
568 HOWTO (R_PPC64_PLT16_LO, /* type */
570 1, /* size (0 = byte, 1 = short, 2 = long) */
572 false, /* pc_relative */
574 complain_overflow_dont, /* complain_on_overflow */
575 ppc64_elf_unhandled_reloc, /* special_function */
576 "R_PPC64_PLT16_LO", /* name */
577 false, /* partial_inplace */
579 0xffff, /* dst_mask */
580 false), /* pcrel_offset */
582 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
584 HOWTO (R_PPC64_PLT16_HI, /* type */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_dont, /* complain_on_overflow */
591 ppc64_elf_unhandled_reloc, /* special_function */
592 "R_PPC64_PLT16_HI", /* name */
593 false, /* partial_inplace */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
600 HOWTO (R_PPC64_PLT16_HA, /* type */
602 1, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_dont, /* complain_on_overflow */
607 ppc64_elf_unhandled_reloc, /* special_function */
608 "R_PPC64_PLT16_HA", /* name */
609 false, /* partial_inplace */
611 0xffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* 16-bit section relative relocation. */
615 HOWTO (R_PPC64_SECTOFF, /* type */
617 1, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_bitfield, /* complain_on_overflow */
622 ppc64_elf_sectoff_reloc, /* special_function */
623 "R_PPC64_SECTOFF", /* name */
624 false, /* partial_inplace */
626 0xffff, /* dst_mask */
627 false), /* pcrel_offset */
629 /* Like R_PPC64_SECTOFF, but no overflow warning. */
630 HOWTO (R_PPC64_SECTOFF_LO, /* type */
632 1, /* size (0 = byte, 1 = short, 2 = long) */
634 false, /* pc_relative */
636 complain_overflow_dont, /* complain_on_overflow */
637 ppc64_elf_sectoff_reloc, /* special_function */
638 "R_PPC64_SECTOFF_LO", /* name */
639 false, /* partial_inplace */
641 0xffff, /* dst_mask */
642 false), /* pcrel_offset */
644 /* 16-bit upper half section relative relocation. */
645 HOWTO (R_PPC64_SECTOFF_HI, /* type */
647 1, /* size (0 = byte, 1 = short, 2 = long) */
649 false, /* pc_relative */
651 complain_overflow_dont, /* complain_on_overflow */
652 ppc64_elf_sectoff_reloc, /* special_function */
653 "R_PPC64_SECTOFF_HI", /* name */
654 false, /* partial_inplace */
656 0xffff, /* dst_mask */
657 false), /* pcrel_offset */
659 /* 16-bit upper half adjusted section relative relocation. */
660 HOWTO (R_PPC64_SECTOFF_HA, /* type */
662 1, /* size (0 = byte, 1 = short, 2 = long) */
664 false, /* pc_relative */
666 complain_overflow_dont, /* complain_on_overflow */
667 ppc64_elf_sectoff_ha_reloc, /* special_function */
668 "R_PPC64_SECTOFF_HA", /* name */
669 false, /* partial_inplace */
671 0xffff, /* dst_mask */
672 false), /* pcrel_offset */
674 /* Like R_PPC64_REL24 without touching the two least significant
675 bits. Should have been named R_PPC64_REL30! */
676 HOWTO (R_PPC64_ADDR30, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 true, /* pc_relative */
682 complain_overflow_dont, /* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 "R_PPC64_ADDR30", /* name */
685 false, /* partial_inplace */
687 0xfffffffc, /* dst_mask */
688 true), /* pcrel_offset */
690 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
692 /* A standard 64-bit relocation. */
693 HOWTO (R_PPC64_ADDR64, /* type */
695 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
697 false, /* pc_relative */
699 complain_overflow_dont, /* complain_on_overflow */
700 bfd_elf_generic_reloc, /* special_function */
701 "R_PPC64_ADDR64", /* name */
702 false, /* partial_inplace */
704 0xffffffffffffffff, /* dst_mask */
705 false), /* pcrel_offset */
707 /* The bits 32-47 of an address. */
708 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
710 1, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_dont, /* complain_on_overflow */
715 bfd_elf_generic_reloc, /* special_function */
716 "R_PPC64_ADDR16_HIGHER", /* name */
717 false, /* partial_inplace */
719 0xffff, /* dst_mask */
720 false), /* pcrel_offset */
722 /* The bits 32-47 of an address, plus 1 if the contents of the low
723 16 bits, treated as a signed number, is negative. */
724 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
726 1, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_dont, /* complain_on_overflow */
731 ppc64_elf_ha_reloc, /* special_function */
732 "R_PPC64_ADDR16_HIGHERA", /* name */
733 false, /* partial_inplace */
735 0xffff, /* dst_mask */
736 false), /* pcrel_offset */
738 /* The bits 48-63 of an address. */
739 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
741 1, /* size (0 = byte, 1 = short, 2 = long) */
743 false, /* pc_relative */
745 complain_overflow_dont, /* complain_on_overflow */
746 bfd_elf_generic_reloc, /* special_function */
747 "R_PPC64_ADDR16_HIGHEST", /* name */
748 false, /* partial_inplace */
750 0xffff, /* dst_mask */
751 false), /* pcrel_offset */
753 /* The bits 48-63 of an address, plus 1 if the contents of the low
754 16 bits, treated as a signed number, is negative. */
755 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_dont, /* complain_on_overflow */
762 ppc64_elf_ha_reloc, /* special_function */
763 "R_PPC64_ADDR16_HIGHESTA", /* name */
764 false, /* partial_inplace */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* Like ADDR64, but may be unaligned. */
770 HOWTO (R_PPC64_UADDR64, /* type */
772 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
774 false, /* pc_relative */
776 complain_overflow_dont, /* complain_on_overflow */
777 bfd_elf_generic_reloc, /* special_function */
778 "R_PPC64_UADDR64", /* name */
779 false, /* partial_inplace */
781 0xffffffffffffffff, /* dst_mask */
782 false), /* pcrel_offset */
784 /* 64-bit relative relocation. */
785 HOWTO (R_PPC64_REL64, /* type */
787 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
789 true, /* pc_relative */
791 complain_overflow_dont, /* complain_on_overflow */
792 bfd_elf_generic_reloc, /* special_function */
793 "R_PPC64_REL64", /* name */
794 false, /* partial_inplace */
796 0xffffffffffffffff, /* dst_mask */
797 true), /* pcrel_offset */
799 /* 64-bit relocation to the symbol's procedure linkage table. */
800 HOWTO (R_PPC64_PLT64, /* type */
802 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
804 false, /* pc_relative */
806 complain_overflow_dont, /* complain_on_overflow */
807 ppc64_elf_unhandled_reloc, /* special_function */
808 "R_PPC64_PLT64", /* name */
809 false, /* partial_inplace */
812 false), /* pcrel_offset */
814 /* 64-bit PC relative relocation to the symbol's procedure linkage
816 /* FIXME: R_PPC64_PLTREL64 not supported. */
817 HOWTO (R_PPC64_PLTREL64, /* type */
819 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
821 true, /* pc_relative */
823 complain_overflow_dont, /* complain_on_overflow */
824 ppc64_elf_unhandled_reloc, /* special_function */
825 "R_PPC64_PLTREL64", /* name */
826 false, /* partial_inplace */
829 true), /* pcrel_offset */
831 /* 16 bit TOC-relative relocation. */
833 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
834 HOWTO (R_PPC64_TOC16, /* type */
836 1, /* size (0 = byte, 1 = short, 2 = long) */
838 false, /* pc_relative */
840 complain_overflow_signed, /* complain_on_overflow */
841 ppc64_elf_toc_reloc, /* special_function */
842 "R_PPC64_TOC16", /* name */
843 false, /* partial_inplace */
845 0xffff, /* dst_mask */
846 false), /* pcrel_offset */
848 /* 16 bit TOC-relative relocation without overflow. */
850 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
851 HOWTO (R_PPC64_TOC16_LO, /* type */
853 1, /* size (0 = byte, 1 = short, 2 = long) */
855 false, /* pc_relative */
857 complain_overflow_dont, /* complain_on_overflow */
858 ppc64_elf_toc_reloc, /* special_function */
859 "R_PPC64_TOC16_LO", /* name */
860 false, /* partial_inplace */
862 0xffff, /* dst_mask */
863 false), /* pcrel_offset */
865 /* 16 bit TOC-relative relocation, high 16 bits. */
867 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
868 HOWTO (R_PPC64_TOC16_HI, /* type */
870 1, /* size (0 = byte, 1 = short, 2 = long) */
872 false, /* pc_relative */
874 complain_overflow_dont, /* complain_on_overflow */
875 ppc64_elf_toc_reloc, /* special_function */
876 "R_PPC64_TOC16_HI", /* name */
877 false, /* partial_inplace */
879 0xffff, /* dst_mask */
880 false), /* pcrel_offset */
882 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
883 contents of the low 16 bits, treated as a signed number, is
886 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
887 HOWTO (R_PPC64_TOC16_HA, /* type */
889 1, /* size (0 = byte, 1 = short, 2 = long) */
891 false, /* pc_relative */
893 complain_overflow_dont, /* complain_on_overflow */
894 ppc64_elf_toc_ha_reloc, /* special_function */
895 "R_PPC64_TOC16_HA", /* name */
896 false, /* partial_inplace */
898 0xffff, /* dst_mask */
899 false), /* pcrel_offset */
901 /* 64-bit relocation; insert value of TOC base (.TOC.). */
903 /* R_PPC64_TOC 51 doubleword64 .TOC. */
904 HOWTO (R_PPC64_TOC, /* type */
906 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
908 false, /* pc_relative */
910 complain_overflow_bitfield, /* complain_on_overflow */
911 ppc64_elf_toc64_reloc, /* special_function */
912 "R_PPC64_TOC", /* name */
913 false, /* partial_inplace */
915 0xffffffffffffffff, /* dst_mask */
916 false), /* pcrel_offset */
918 /* Like R_PPC64_GOT16, but also informs the link editor that the
919 value to relocate may (!) refer to a PLT entry which the link
920 editor (a) may replace with the symbol value. If the link editor
921 is unable to fully resolve the symbol, it may (b) create a PLT
922 entry and store the address to the new PLT entry in the GOT.
923 This permits lazy resolution of function symbols at run time.
924 The link editor may also skip all of this and just (c) emit a
925 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
926 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
927 HOWTO (R_PPC64_PLTGOT16, /* type */
929 1, /* size (0 = byte, 1 = short, 2 = long) */
931 false, /* pc_relative */
933 complain_overflow_signed, /* complain_on_overflow */
934 ppc64_elf_unhandled_reloc, /* special_function */
935 "R_PPC64_PLTGOT16", /* name */
936 false, /* partial_inplace */
938 0xffff, /* dst_mask */
939 false), /* pcrel_offset */
941 /* Like R_PPC64_PLTGOT16, but without overflow. */
942 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
943 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
945 1, /* size (0 = byte, 1 = short, 2 = long) */
947 false, /* pc_relative */
949 complain_overflow_dont, /* complain_on_overflow */
950 ppc64_elf_unhandled_reloc, /* special_function */
951 "R_PPC64_PLTGOT16_LO", /* name */
952 false, /* partial_inplace */
954 0xffff, /* dst_mask */
955 false), /* pcrel_offset */
957 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
958 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
959 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
961 1, /* size (0 = byte, 1 = short, 2 = long) */
963 false, /* pc_relative */
965 complain_overflow_dont, /* complain_on_overflow */
966 ppc64_elf_unhandled_reloc, /* special_function */
967 "R_PPC64_PLTGOT16_HI", /* name */
968 false, /* partial_inplace */
970 0xffff, /* dst_mask */
971 false), /* pcrel_offset */
973 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
974 1 if the contents of the low 16 bits, treated as a signed number,
976 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
977 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
979 1, /* size (0 = byte, 1 = short, 2 = long) */
981 false, /* pc_relative */
983 complain_overflow_dont,/* complain_on_overflow */
984 ppc64_elf_unhandled_reloc, /* special_function */
985 "R_PPC64_PLTGOT16_HA", /* name */
986 false, /* partial_inplace */
988 0xffff, /* dst_mask */
989 false), /* pcrel_offset */
991 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
992 HOWTO (R_PPC64_ADDR16_DS, /* type */
994 1, /* size (0 = byte, 1 = short, 2 = long) */
996 false, /* pc_relative */
998 complain_overflow_bitfield, /* complain_on_overflow */
999 bfd_elf_generic_reloc, /* special_function */
1000 "R_PPC64_ADDR16_DS", /* name */
1001 false, /* partial_inplace */
1003 0xfffc, /* dst_mask */
1004 false), /* pcrel_offset */
1006 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1007 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1009 1, /* size (0 = byte, 1 = short, 2 = long) */
1011 false, /* pc_relative */
1013 complain_overflow_dont,/* complain_on_overflow */
1014 bfd_elf_generic_reloc, /* special_function */
1015 "R_PPC64_ADDR16_LO_DS",/* name */
1016 false, /* partial_inplace */
1018 0xfffc, /* dst_mask */
1019 false), /* pcrel_offset */
1021 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1022 HOWTO (R_PPC64_GOT16_DS, /* type */
1024 1, /* size (0 = byte, 1 = short, 2 = long) */
1026 false, /* pc_relative */
1028 complain_overflow_signed, /* complain_on_overflow */
1029 ppc64_elf_unhandled_reloc, /* special_function */
1030 "R_PPC64_GOT16_DS", /* name */
1031 false, /* partial_inplace */
1033 0xfffc, /* dst_mask */
1034 false), /* pcrel_offset */
1036 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1037 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1039 1, /* size (0 = byte, 1 = short, 2 = long) */
1041 false, /* pc_relative */
1043 complain_overflow_dont, /* complain_on_overflow */
1044 ppc64_elf_unhandled_reloc, /* special_function */
1045 "R_PPC64_GOT16_LO_DS", /* name */
1046 false, /* partial_inplace */
1048 0xfffc, /* dst_mask */
1049 false), /* pcrel_offset */
1051 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1052 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1054 1, /* size (0 = byte, 1 = short, 2 = long) */
1056 false, /* pc_relative */
1058 complain_overflow_dont, /* complain_on_overflow */
1059 ppc64_elf_unhandled_reloc, /* special_function */
1060 "R_PPC64_PLT16_LO_DS", /* name */
1061 false, /* partial_inplace */
1063 0xfffc, /* dst_mask */
1064 false), /* pcrel_offset */
1066 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1067 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1069 1, /* size (0 = byte, 1 = short, 2 = long) */
1071 false, /* pc_relative */
1073 complain_overflow_bitfield, /* complain_on_overflow */
1074 ppc64_elf_sectoff_reloc, /* special_function */
1075 "R_PPC64_SECTOFF_DS", /* name */
1076 false, /* partial_inplace */
1078 0xfffc, /* dst_mask */
1079 false), /* pcrel_offset */
1081 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1082 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1084 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 false, /* pc_relative */
1088 complain_overflow_dont, /* complain_on_overflow */
1089 ppc64_elf_sectoff_reloc, /* special_function */
1090 "R_PPC64_SECTOFF_LO_DS",/* name */
1091 false, /* partial_inplace */
1093 0xfffc, /* dst_mask */
1094 false), /* pcrel_offset */
1096 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1097 HOWTO (R_PPC64_TOC16_DS, /* type */
1099 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 false, /* pc_relative */
1103 complain_overflow_signed, /* complain_on_overflow */
1104 ppc64_elf_toc_reloc, /* special_function */
1105 "R_PPC64_TOC16_DS", /* name */
1106 false, /* partial_inplace */
1108 0xfffc, /* dst_mask */
1109 false), /* pcrel_offset */
1111 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1112 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1114 1, /* size (0 = byte, 1 = short, 2 = long) */
1116 false, /* pc_relative */
1118 complain_overflow_dont, /* complain_on_overflow */
1119 ppc64_elf_toc_reloc, /* special_function */
1120 "R_PPC64_TOC16_LO_DS", /* name */
1121 false, /* partial_inplace */
1123 0xfffc, /* dst_mask */
1124 false), /* pcrel_offset */
1126 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1127 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1128 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1130 1, /* size (0 = byte, 1 = short, 2 = long) */
1132 false, /* pc_relative */
1134 complain_overflow_signed, /* complain_on_overflow */
1135 ppc64_elf_unhandled_reloc, /* special_function */
1136 "R_PPC64_PLTGOT16_DS", /* name */
1137 false, /* partial_inplace */
1139 0xfffc, /* dst_mask */
1140 false), /* pcrel_offset */
1142 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1143 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1144 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1146 1, /* size (0 = byte, 1 = short, 2 = long) */
1148 false, /* pc_relative */
1150 complain_overflow_dont, /* complain_on_overflow */
1151 ppc64_elf_unhandled_reloc, /* special_function */
1152 "R_PPC64_PLTGOT16_LO_DS",/* name */
1153 false, /* partial_inplace */
1155 0xfffc, /* dst_mask */
1156 false), /* pcrel_offset */
1158 /* GNU extension to record C++ vtable hierarchy. */
1159 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1161 0, /* size (0 = byte, 1 = short, 2 = long) */
1163 false, /* pc_relative */
1165 complain_overflow_dont, /* complain_on_overflow */
1166 NULL, /* special_function */
1167 "R_PPC64_GNU_VTINHERIT", /* name */
1168 false, /* partial_inplace */
1171 false), /* pcrel_offset */
1173 /* GNU extension to record C++ vtable member usage. */
1174 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1176 0, /* size (0 = byte, 1 = short, 2 = long) */
1178 false, /* pc_relative */
1180 complain_overflow_dont, /* complain_on_overflow */
1181 NULL, /* special_function */
1182 "R_PPC64_GNU_VTENTRY", /* name */
1183 false, /* partial_inplace */
1186 false), /* pcrel_offset */
1190 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1196 unsigned int i, type;
1199 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1202 type = ppc64_elf_howto_raw[i].type;
1203 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1204 / sizeof (ppc64_elf_howto_table[0])));
1205 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1209 static reloc_howto_type *
1210 ppc64_elf_reloc_type_lookup (abfd, code)
1211 bfd *abfd ATTRIBUTE_UNUSED;
1212 bfd_reloc_code_real_type code;
1214 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1216 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1217 /* Initialize howto table if needed. */
1223 return (reloc_howto_type *) NULL;
1225 case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1227 case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1229 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1231 case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1233 case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1235 case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1237 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1239 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1241 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1243 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1245 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1247 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1249 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1251 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1253 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1255 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1257 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1259 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1261 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1263 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1265 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1267 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1269 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1271 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1273 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1275 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1277 case BFD_RELOC_16_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1279 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1281 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1283 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1285 case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64;
1287 case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1289 case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1291 case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1293 case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1295 case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1297 case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1299 case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1301 case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1303 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1305 case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1307 case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1309 case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1311 case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1313 case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1315 case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1317 case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1319 case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1321 case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1323 case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1325 case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1327 case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1329 case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1331 case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1333 case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1335 case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1337 case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1339 case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1341 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1343 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1345 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1349 return ppc64_elf_howto_table[(int) ppc_reloc];
1352 /* Set the howto pointer for a PowerPC ELF reloc. */
1355 ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1356 bfd *abfd ATTRIBUTE_UNUSED;
1358 Elf64_Internal_Rela *dst;
1362 /* Initialize howto table if needed. */
1363 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1366 type = ELF64_R_TYPE (dst->r_info);
1367 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1368 / sizeof (ppc64_elf_howto_table[0])));
1369 cache_ptr->howto = ppc64_elf_howto_table[type];
1372 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1374 static bfd_reloc_status_type
1375 ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data,
1376 input_section, output_bfd, error_message)
1378 arelent *reloc_entry;
1381 asection *input_section;
1383 char **error_message;
1385 /* If this is a relocatable link (output_bfd test tells us), just
1386 call the generic function. Any adjustment will be done at final
1388 if (output_bfd != NULL)
1389 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1390 input_section, output_bfd, error_message);
1392 /* Adjust the addend for sign extension of the low 16 bits.
1393 We won't actually be using the low 16 bits, so trashing them
1395 reloc_entry->addend += 0x8000;
1396 return bfd_reloc_continue;
1399 static bfd_reloc_status_type
1400 ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data,
1401 input_section, output_bfd, error_message)
1403 arelent *reloc_entry;
1406 asection *input_section;
1408 char **error_message;
1411 enum elf_ppc_reloc_type r_type;
1412 bfd_size_type octets;
1413 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1414 boolean is_power4 = false;
1416 /* If this is a relocatable link (output_bfd test tells us), just
1417 call the generic function. Any adjustment will be done at final
1419 if (output_bfd != NULL)
1420 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1421 input_section, output_bfd, error_message);
1423 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1424 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
1425 insn &= ~(0x01 << 21);
1426 r_type = (enum elf_ppc_reloc_type) reloc_entry->howto->type;
1427 if (r_type == R_PPC64_ADDR14_BRTAKEN
1428 || r_type == R_PPC64_REL14_BRTAKEN)
1429 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1433 /* Set 'a' bit. This is 0b00010 in BO field for branch
1434 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1435 for branch on CTR insns (BO == 1a00t or 1a01t). */
1436 if ((insn & (0x14 << 21)) == (0x04 << 21))
1438 else if ((insn & (0x14 << 21)) == (0x10 << 21))
1441 return bfd_reloc_continue;
1448 if (!bfd_is_com_section (symbol->section))
1449 target = symbol->value;
1450 target += symbol->section->output_section->vma;
1451 target += symbol->section->output_offset;
1452 target += reloc_entry->addend;
1454 from = (reloc_entry->address
1455 + input_section->output_offset
1456 + input_section->output_section->vma);
1458 /* Invert 'y' bit if not the default. */
1459 if ((bfd_signed_vma) (target - from) < 0)
1462 bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets);
1463 return bfd_reloc_continue;
1466 static bfd_reloc_status_type
1467 ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data,
1468 input_section, output_bfd, error_message)
1470 arelent *reloc_entry;
1473 asection *input_section;
1475 char **error_message;
1477 /* If this is a relocatable link (output_bfd test tells us), just
1478 call the generic function. Any adjustment will be done at final
1480 if (output_bfd != NULL)
1481 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1482 input_section, output_bfd, error_message);
1484 /* Subtract the symbol section base address. */
1485 reloc_entry->addend -= symbol->section->output_section->vma;
1486 return bfd_reloc_continue;
1489 static bfd_reloc_status_type
1490 ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data,
1491 input_section, output_bfd, error_message)
1493 arelent *reloc_entry;
1496 asection *input_section;
1498 char **error_message;
1500 /* If this is a relocatable link (output_bfd test tells us), just
1501 call the generic function. Any adjustment will be done at final
1503 if (output_bfd != NULL)
1504 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1505 input_section, output_bfd, error_message);
1507 /* Subtract the symbol section base address. */
1508 reloc_entry->addend -= symbol->section->output_section->vma;
1510 /* Adjust the addend for sign extension of the low 16 bits. */
1511 reloc_entry->addend += 0x8000;
1512 return bfd_reloc_continue;
1515 static bfd_reloc_status_type
1516 ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data,
1517 input_section, output_bfd, error_message)
1519 arelent *reloc_entry;
1522 asection *input_section;
1524 char **error_message;
1528 /* If this is a relocatable link (output_bfd test tells us), just
1529 call the generic function. Any adjustment will be done at final
1531 if (output_bfd != NULL)
1532 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1533 input_section, output_bfd, error_message);
1535 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1537 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1539 /* Subtract the TOC base address. */
1540 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1541 return bfd_reloc_continue;
1544 static bfd_reloc_status_type
1545 ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data,
1546 input_section, output_bfd, error_message)
1548 arelent *reloc_entry;
1551 asection *input_section;
1553 char **error_message;
1557 /* If this is a relocatable link (output_bfd test tells us), just
1558 call the generic function. Any adjustment will be done at final
1560 if (output_bfd != NULL)
1561 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1562 input_section, output_bfd, error_message);
1564 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1566 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1568 /* Subtract the TOC base address. */
1569 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1571 /* Adjust the addend for sign extension of the low 16 bits. */
1572 reloc_entry->addend += 0x8000;
1573 return bfd_reloc_continue;
1576 static bfd_reloc_status_type
1577 ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data,
1578 input_section, output_bfd, error_message)
1580 arelent *reloc_entry;
1583 asection *input_section;
1585 char **error_message;
1588 bfd_size_type octets;
1590 /* If this is a relocatable link (output_bfd test tells us), just
1591 call the generic function. Any adjustment will be done at final
1593 if (output_bfd != NULL)
1594 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1595 input_section, output_bfd, error_message);
1597 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1599 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1601 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1602 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
1603 return bfd_reloc_ok;
1606 static bfd_reloc_status_type
1607 ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
1608 input_section, output_bfd, error_message)
1610 arelent *reloc_entry;
1613 asection *input_section;
1615 char **error_message;
1617 /* If this is a relocatable link (output_bfd test tells us), just
1618 call the generic function. Any adjustment will be done at final
1620 if (output_bfd != NULL)
1621 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1622 input_section, output_bfd, error_message);
1624 if (error_message != NULL)
1626 static char buf[60];
1627 sprintf (buf, "generic linker can't handle %s",
1628 reloc_entry->howto->name);
1629 *error_message = buf;
1631 return bfd_reloc_dangerous;
1634 /* Function to set whether a module needs the -mrelocatable bit set. */
1637 ppc64_elf_set_private_flags (abfd, flags)
1641 BFD_ASSERT (!elf_flags_init (abfd)
1642 || elf_elfheader (abfd)->e_flags == flags);
1644 elf_elfheader (abfd)->e_flags = flags;
1645 elf_flags_init (abfd) = true;
1649 /* Merge backend specific data from an object file to the output
1650 object file when linking. */
1652 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);
1677 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1678 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1681 new_flags = elf_elfheader (ibfd)->e_flags;
1682 old_flags = elf_elfheader (obfd)->e_flags;
1683 if (!elf_flags_init (obfd))
1685 /* First call, no flags set. */
1686 elf_flags_init (obfd) = true;
1687 elf_elfheader (obfd)->e_flags = new_flags;
1690 else if (new_flags == old_flags)
1691 /* Compatible flags are ok. */
1696 /* Incompatible flags. Warn about -mrelocatable mismatch.
1697 Allow -mrelocatable-lib to be linked with either. */
1699 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1700 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1703 (*_bfd_error_handler)
1704 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1705 bfd_archive_filename (ibfd));
1707 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1708 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1711 (*_bfd_error_handler)
1712 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1713 bfd_archive_filename (ibfd));
1716 /* The output is -mrelocatable-lib iff both the input files are. */
1717 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1718 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1720 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1721 but each input file is either -mrelocatable or -mrelocatable-lib. */
1722 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1723 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1724 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1725 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1727 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1728 if any module uses it. */
1729 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1731 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1732 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1734 /* Warn about any other mismatches. */
1735 if (new_flags != old_flags)
1738 (*_bfd_error_handler)
1739 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1740 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
1745 bfd_set_error (bfd_error_bad_value);
1753 /* Handle a PowerPC specific section when reading an object file. This
1754 is called when elfcode.h finds a section with an unknown type. */
1757 ppc64_elf_section_from_shdr (abfd, hdr, name)
1759 Elf64_Internal_Shdr *hdr;
1765 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1768 newsect = hdr->bfd_section;
1769 flags = bfd_get_section_flags (abfd, newsect);
1770 if (hdr->sh_flags & SHF_EXCLUDE)
1771 flags |= SEC_EXCLUDE;
1773 if (hdr->sh_type == SHT_ORDERED)
1774 flags |= SEC_SORT_ENTRIES;
1776 bfd_set_section_flags (abfd, newsect, flags);
1780 /* The following functions are specific to the ELF linker, while
1781 functions above are used generally. Those named ppc64_elf_* are
1782 called by the main ELF linker code. They appear in this file more
1783 or less in the order in which they are called. eg.
1784 ppc64_elf_check_relocs is called early in the link process,
1785 ppc64_elf_finish_dynamic_sections is one of the last functions
1788 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1789 functions have both a function code symbol and a function descriptor
1790 symbol. A call to foo in a relocatable object file looks like:
1797 The function definition in another object file might be:
1801 . .quad .TOC.@tocbase
1807 When the linker resolves the call during a static link, the branch
1808 unsurprisingly just goes to .foo and the .opd information is unused.
1809 If the function definition is in a shared library, things are a little
1810 different: The call goes via a plt call stub, the opd information gets
1811 copied to the plt, and the linker patches the nop.
1819 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1820 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1821 . std 2,40(1) # this is the general idea
1829 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1831 The "reloc ()" notation is supposed to indicate that the linker emits
1832 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1835 What are the difficulties here? Well, firstly, the relocations
1836 examined by the linker in check_relocs are against the function code
1837 sym .foo, while the dynamic relocation in the plt is emitted against
1838 the function descriptor symbol, foo. Somewhere along the line, we need
1839 to carefully copy dynamic link information from one symbol to the other.
1840 Secondly, the generic part of the elf linker will make .foo a dynamic
1841 symbol as is normal for most other backends. We need foo dynamic
1842 instead, at least for an application final link. However, when
1843 creating a shared library containing foo, we need to have both symbols
1844 dynamic so that references to .foo are satisfied during the early
1845 stages of linking. Otherwise the linker might decide to pull in a
1846 definition from some other object, eg. a static library. */
1848 /* The linker needs to keep track of the number of relocs that it
1849 decides to copy as dynamic relocs in check_relocs for each symbol.
1850 This is so that it can later discard them if they are found to be
1851 unnecessary. We store the information in a field extending the
1852 regular ELF linker hash table. */
1854 struct ppc_dyn_relocs
1856 struct ppc_dyn_relocs *next;
1858 /* The input section of the reloc. */
1861 /* Total number of relocs copied for the input section. */
1862 bfd_size_type count;
1864 /* Number of pc-relative relocs copied for the input section. */
1865 bfd_size_type pc_count;
1868 /* Of those relocs that might be copied as dynamic relocs, this macro
1869 selects between relative and absolute types. */
1871 #define IS_ABSOLUTE_RELOC(RTYPE) \
1872 ((RTYPE) != R_PPC64_REL32 \
1873 && (RTYPE) != R_PPC64_REL64 \
1874 && (RTYPE) != R_PPC64_ADDR30)
1876 /* Section name for stubs is the associated section name plus this
1878 #define STUB_SUFFIX ".stub"
1881 ppc_stub_long_branch:
1882 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1883 destination, but a 24 bit branch in a stub section will reach.
1886 ppc_stub_plt_branch:
1887 Similar to the above, but a 24 bit branch in the stub section won't
1888 reach its destination.
1889 . addis %r12,%r2,xxx@ha
1890 . ld %r11,xxx@l(%r12)
1895 Used to call a function in a shared library.
1896 . addis %r12,%r2,xxx@ha
1898 . ld %r11,xxx+0@l(%r12)
1899 . ld %r2,xxx+8@l(%r12)
1901 . ld %r11,xxx+16@l(%r12)
1905 enum ppc_stub_type {
1907 ppc_stub_long_branch,
1908 ppc_stub_plt_branch,
1912 struct ppc_stub_hash_entry {
1914 /* Base hash table entry structure. */
1915 struct bfd_hash_entry root;
1917 /* The stub section. */
1920 /* Offset within stub_sec of the beginning of this stub. */
1921 bfd_vma stub_offset;
1923 /* Given the symbol's value and its section we can determine its final
1924 value when building the stubs (so the stub knows where to jump. */
1925 bfd_vma target_value;
1926 asection *target_section;
1928 enum ppc_stub_type stub_type;
1930 /* The symbol table entry, if any, that this was derived from. */
1931 struct ppc_link_hash_entry *h;
1933 /* Where this stub is being called from, or, in the case of combined
1934 stub sections, the first input section in the group. */
1938 struct ppc_branch_hash_entry {
1940 /* Base hash table entry structure. */
1941 struct bfd_hash_entry root;
1943 /* Offset within .branch_lt. */
1944 unsigned int offset;
1946 /* Generation marker. */
1950 struct ppc_link_hash_entry
1952 struct elf_link_hash_entry elf;
1954 /* A pointer to the most recently used stub hash entry against this
1956 struct ppc_stub_hash_entry *stub_cache;
1958 /* Track dynamic relocs copied for this symbol. */
1959 struct ppc_dyn_relocs *dyn_relocs;
1961 /* Link between function code and descriptor symbols. */
1962 struct elf_link_hash_entry *oh;
1964 /* Flag function code and descriptor symbols. */
1965 unsigned int is_func:1;
1966 unsigned int is_func_descriptor:1;
1969 /* ppc64 ELF linker hash table. */
1971 struct ppc_link_hash_table
1973 struct elf_link_hash_table elf;
1975 /* The stub hash table. */
1976 struct bfd_hash_table stub_hash_table;
1978 /* Another hash table for plt_branch stubs. */
1979 struct bfd_hash_table branch_hash_table;
1981 /* Linker stub bfd. */
1984 /* Linker call-backs. */
1985 asection * (*add_stub_section) PARAMS ((const char *, asection *));
1986 void (*layout_sections_again) PARAMS ((void));
1988 /* Array to keep track of which stub sections have been created, and
1989 information on stub grouping. */
1991 /* This is the section to which stubs in the group will be attached. */
1993 /* The stub section. */
1997 /* Assorted information used by ppc64_elf_size_stubs. */
1998 unsigned int bfd_count;
2000 asection **input_list;
2001 Elf_Internal_Sym **all_local_syms;
2003 /* Short-cuts to get to dynamic linker sections. */
2016 unsigned int stub_error;
2018 /* Flag set when small branches are detected. Used to
2019 select suitable defaults for the stub group size. */
2020 unsigned int has_14bit_branch;
2022 /* Set if we detect a reference undefined weak symbol. */
2023 unsigned int have_undefweak;
2025 /* Incremented every time we size stubs. */
2026 unsigned int stub_iteration;
2028 /* Small local sym to section mapping cache. */
2029 struct sym_sec_cache sym_sec;
2032 static struct bfd_hash_entry *stub_hash_newfunc
2033 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2034 static struct bfd_hash_entry *branch_hash_newfunc
2035 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2036 static struct bfd_hash_entry *link_hash_newfunc
2037 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2038 static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
2040 static void ppc64_elf_link_hash_table_free
2041 PARAMS ((struct bfd_link_hash_table *));
2042 static char *ppc_stub_name
2043 PARAMS ((const asection *, const asection *,
2044 const struct ppc_link_hash_entry *, const Elf_Internal_Rela *));
2045 static struct ppc_stub_hash_entry *ppc_get_stub_entry
2046 PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *,
2047 const Elf_Internal_Rela *, struct ppc_link_hash_table *));
2048 static struct ppc_stub_hash_entry *ppc_add_stub
2049 PARAMS ((const char *, asection *, struct ppc_link_hash_table *));
2050 static boolean create_linkage_sections
2051 PARAMS ((bfd *, struct bfd_link_info *));
2052 static boolean create_got_section
2053 PARAMS ((bfd *, struct bfd_link_info *));
2054 static boolean ppc64_elf_create_dynamic_sections
2055 PARAMS ((bfd *, struct bfd_link_info *));
2056 static void ppc64_elf_copy_indirect_symbol
2057 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
2058 static boolean ppc64_elf_check_relocs
2059 PARAMS ((bfd *, struct bfd_link_info *, asection *,
2060 const Elf_Internal_Rela *));
2061 static asection * ppc64_elf_gc_mark_hook
2062 PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel,
2063 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
2064 static boolean ppc64_elf_gc_sweep_hook
2065 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
2066 const Elf_Internal_Rela *relocs));
2067 static boolean func_desc_adjust
2068 PARAMS ((struct elf_link_hash_entry *, PTR));
2069 static boolean ppc64_elf_func_desc_adjust
2070 PARAMS ((bfd *, struct bfd_link_info *));
2071 static boolean ppc64_elf_adjust_dynamic_symbol
2072 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
2073 static void ppc64_elf_hide_symbol
2074 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
2075 static boolean allocate_dynrelocs
2076 PARAMS ((struct elf_link_hash_entry *, PTR));
2077 static boolean readonly_dynrelocs
2078 PARAMS ((struct elf_link_hash_entry *, PTR));
2079 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2080 PARAMS ((const Elf_Internal_Rela *));
2081 static boolean ppc64_elf_size_dynamic_sections
2082 PARAMS ((bfd *, struct bfd_link_info *));
2083 static INLINE enum ppc_stub_type ppc_type_of_stub
2084 PARAMS ((asection *, const Elf_Internal_Rela *,
2085 struct ppc_link_hash_entry **, bfd_vma));
2086 static bfd_byte *build_plt_stub
2087 PARAMS ((bfd *, bfd_byte *, int, int));
2088 static boolean ppc_build_one_stub
2089 PARAMS ((struct bfd_hash_entry *, PTR));
2090 static boolean ppc_size_one_stub
2091 PARAMS ((struct bfd_hash_entry *, PTR));
2092 static void group_sections
2093 PARAMS ((struct ppc_link_hash_table *, bfd_size_type, boolean));
2094 static boolean get_local_syms
2095 PARAMS ((bfd *, struct ppc_link_hash_table *));
2096 static boolean ppc64_elf_fake_sections
2097 PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *));
2098 static boolean ppc64_elf_relocate_section
2099 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
2100 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
2102 static boolean ppc64_elf_finish_dynamic_symbol
2103 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
2104 Elf_Internal_Sym *));
2105 static boolean ppc64_elf_finish_dynamic_sections
2106 PARAMS ((bfd *, struct bfd_link_info *));
2108 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2110 #define ppc_hash_table(p) \
2111 ((struct ppc_link_hash_table *) ((p)->hash))
2113 #define ppc_stub_hash_lookup(table, string, create, copy) \
2114 ((struct ppc_stub_hash_entry *) \
2115 bfd_hash_lookup ((table), (string), (create), (copy)))
2117 #define ppc_branch_hash_lookup(table, string, create, copy) \
2118 ((struct ppc_branch_hash_entry *) \
2119 bfd_hash_lookup ((table), (string), (create), (copy)))
2121 /* Create an entry in the stub hash table. */
2123 static struct bfd_hash_entry *
2124 stub_hash_newfunc (entry, table, string)
2125 struct bfd_hash_entry *entry;
2126 struct bfd_hash_table *table;
2129 /* Allocate the structure if it has not already been allocated by a
2133 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2138 /* Call the allocation method of the superclass. */
2139 entry = bfd_hash_newfunc (entry, table, string);
2142 struct ppc_stub_hash_entry *eh;
2144 /* Initialize the local fields. */
2145 eh = (struct ppc_stub_hash_entry *) entry;
2146 eh->stub_sec = NULL;
2147 eh->stub_offset = 0;
2148 eh->target_value = 0;
2149 eh->target_section = NULL;
2150 eh->stub_type = ppc_stub_none;
2158 /* Create an entry in the branch hash table. */
2160 static struct bfd_hash_entry *
2161 branch_hash_newfunc (entry, table, string)
2162 struct bfd_hash_entry *entry;
2163 struct bfd_hash_table *table;
2166 /* Allocate the structure if it has not already been allocated by a
2170 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2175 /* Call the allocation method of the superclass. */
2176 entry = bfd_hash_newfunc (entry, table, string);
2179 struct ppc_branch_hash_entry *eh;
2181 /* Initialize the local fields. */
2182 eh = (struct ppc_branch_hash_entry *) entry;
2190 /* Create an entry in a ppc64 ELF linker hash table. */
2192 static struct bfd_hash_entry *
2193 link_hash_newfunc (entry, table, string)
2194 struct bfd_hash_entry *entry;
2195 struct bfd_hash_table *table;
2198 /* Allocate the structure if it has not already been allocated by a
2202 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2207 /* Call the allocation method of the superclass. */
2208 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2211 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2213 eh->stub_cache = NULL;
2214 eh->dyn_relocs = NULL;
2217 eh->is_func_descriptor = 0;
2223 /* Create a ppc64 ELF linker hash table. */
2225 static struct bfd_link_hash_table *
2226 ppc64_elf_link_hash_table_create (abfd)
2229 struct ppc_link_hash_table *htab;
2230 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
2232 htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
2236 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
2242 /* Init the stub hash table too. */
2243 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
2246 /* And the branch hash table. */
2247 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
2250 htab->stub_bfd = NULL;
2251 htab->add_stub_section = NULL;
2252 htab->layout_sections_again = NULL;
2253 htab->stub_group = NULL;
2255 htab->srelgot = NULL;
2257 htab->srelplt = NULL;
2258 htab->sdynbss = NULL;
2259 htab->srelbss = NULL;
2260 htab->sglink = NULL;
2263 htab->srelbrlt = NULL;
2264 htab->stub_error = 0;
2265 htab->has_14bit_branch = 0;
2266 htab->have_undefweak = 0;
2267 htab->stub_iteration = 0;
2268 htab->sym_sec.abfd = NULL;
2270 return &htab->elf.root;
2273 /* Free the derived linker hash table. */
2276 ppc64_elf_link_hash_table_free (hash)
2277 struct bfd_link_hash_table *hash;
2279 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
2281 bfd_hash_table_free (&ret->stub_hash_table);
2282 bfd_hash_table_free (&ret->branch_hash_table);
2283 _bfd_generic_link_hash_table_free (hash);
2286 /* Build a name for an entry in the stub hash table. */
2289 ppc_stub_name (input_section, sym_sec, h, rel)
2290 const asection *input_section;
2291 const asection *sym_sec;
2292 const struct ppc_link_hash_entry *h;
2293 const Elf_Internal_Rela *rel;
2298 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2299 offsets from a sym as a branch target? In fact, we could
2300 probably assume the addend is always zero. */
2301 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
2305 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
2306 stub_name = bfd_malloc (len);
2307 if (stub_name != NULL)
2309 sprintf (stub_name, "%08x_%s+%x",
2310 input_section->id & 0xffffffff,
2311 h->elf.root.root.string,
2312 (int) rel->r_addend & 0xffffffff);
2317 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2318 stub_name = bfd_malloc (len);
2319 if (stub_name != NULL)
2321 sprintf (stub_name, "%08x_%x:%x+%x",
2322 input_section->id & 0xffffffff,
2323 sym_sec->id & 0xffffffff,
2324 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
2325 (int) rel->r_addend & 0xffffffff);
2331 /* Look up an entry in the stub hash. Stub entries are cached because
2332 creating the stub name takes a bit of time. */
2334 static struct ppc_stub_hash_entry *
2335 ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab)
2336 const asection *input_section;
2337 const asection *sym_sec;
2338 struct elf_link_hash_entry *hash;
2339 const Elf_Internal_Rela *rel;
2340 struct ppc_link_hash_table *htab;
2342 struct ppc_stub_hash_entry *stub_entry;
2343 struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
2344 const asection *id_sec;
2346 /* If this input section is part of a group of sections sharing one
2347 stub section, then use the id of the first section in the group.
2348 Stub names need to include a section id, as there may well be
2349 more than one stub used to reach say, printf, and we need to
2350 distinguish between them. */
2351 id_sec = htab->stub_group[input_section->id].link_sec;
2353 if (h != NULL && h->stub_cache != NULL
2354 && h->stub_cache->h == h
2355 && h->stub_cache->id_sec == id_sec)
2357 stub_entry = h->stub_cache;
2363 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
2364 if (stub_name == NULL)
2367 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
2368 stub_name, false, false);
2370 h->stub_cache = stub_entry;
2378 /* Add a new stub entry to the stub hash. Not all fields of the new
2379 stub entry are initialised. */
2381 static struct ppc_stub_hash_entry *
2382 ppc_add_stub (stub_name, section, htab)
2383 const char *stub_name;
2385 struct ppc_link_hash_table *htab;
2389 struct ppc_stub_hash_entry *stub_entry;
2391 link_sec = htab->stub_group[section->id].link_sec;
2392 stub_sec = htab->stub_group[section->id].stub_sec;
2393 if (stub_sec == NULL)
2395 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2396 if (stub_sec == NULL)
2401 len = strlen (link_sec->name) + sizeof (STUB_SUFFIX);
2402 s_name = bfd_alloc (htab->stub_bfd, len);
2406 strcpy (s_name, link_sec->name);
2407 strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX);
2408 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2409 if (stub_sec == NULL)
2411 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2413 htab->stub_group[section->id].stub_sec = stub_sec;
2416 /* Enter this entry into the linker stub hash table. */
2417 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2419 if (stub_entry == NULL)
2421 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2422 bfd_archive_filename (section->owner),
2427 stub_entry->stub_sec = stub_sec;
2428 stub_entry->stub_offset = 0;
2429 stub_entry->id_sec = link_sec;
2433 /* Create sections for linker generated code. */
2436 create_linkage_sections (dynobj, info)
2438 struct bfd_link_info *info;
2440 struct ppc_link_hash_table *htab;
2443 htab = ppc_hash_table (info);
2445 /* Create .sfpr for code to save and restore fp regs. */
2446 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
2447 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2448 htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
2449 if (htab->sfpr == NULL
2450 || ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
2451 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
2454 /* Create .glink for lazy dynamic linking support. */
2455 htab->sglink = bfd_make_section_anyway (dynobj, ".glink");
2456 if (htab->sglink == NULL
2457 || ! bfd_set_section_flags (dynobj, htab->sglink, flags)
2458 || ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
2461 /* Create .branch_lt for plt_branch stubs. */
2462 flags = (SEC_ALLOC | SEC_LOAD
2463 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2464 htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt");
2465 if (htab->sbrlt == NULL
2466 || ! bfd_set_section_flags (dynobj, htab->sbrlt, flags)
2467 || ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3))
2472 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2473 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2474 htab->srelbrlt = bfd_make_section (dynobj, ".rela.branch_lt");
2476 || ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags)
2477 || ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3))
2483 /* Create .got and .rela.got sections in DYNOBJ, and set up
2484 shortcuts to them in our hash table. */
2487 create_got_section (dynobj, info)
2489 struct bfd_link_info *info;
2491 struct ppc_link_hash_table *htab;
2493 if (! _bfd_elf_create_got_section (dynobj, info))
2496 htab = ppc_hash_table (info);
2497 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2501 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
2503 || ! bfd_set_section_flags (dynobj, htab->srelgot,
2504 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2505 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2507 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
2512 /* Create the dynamic sections, and set up shortcuts. */
2515 ppc64_elf_create_dynamic_sections (dynobj, info)
2517 struct bfd_link_info *info;
2519 struct ppc_link_hash_table *htab;
2521 htab = ppc_hash_table (info);
2522 if (!htab->sgot && !create_got_section (dynobj, info))
2525 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2528 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2529 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
2530 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2532 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
2534 if (!htab->splt || !htab->srelplt || !htab->sdynbss
2535 || (!info->shared && !htab->srelbss))
2541 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2544 ppc64_elf_copy_indirect_symbol (dir, ind)
2545 struct elf_link_hash_entry *dir, *ind;
2547 struct ppc_link_hash_entry *edir, *eind;
2549 edir = (struct ppc_link_hash_entry *) dir;
2550 eind = (struct ppc_link_hash_entry *) ind;
2552 if (eind->dyn_relocs != NULL)
2554 if (edir->dyn_relocs != NULL)
2556 struct ppc_dyn_relocs **pp;
2557 struct ppc_dyn_relocs *p;
2559 if (ind->root.type == bfd_link_hash_indirect)
2562 /* Add reloc counts against the weak sym to the strong sym
2563 list. Merge any entries against the same section. */
2564 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2566 struct ppc_dyn_relocs *q;
2568 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2569 if (q->sec == p->sec)
2571 q->pc_count += p->pc_count;
2572 q->count += p->count;
2579 *pp = edir->dyn_relocs;
2582 edir->dyn_relocs = eind->dyn_relocs;
2583 eind->dyn_relocs = NULL;
2586 edir->is_func |= eind->is_func;
2587 edir->is_func_descriptor |= eind->is_func_descriptor;
2589 _bfd_elf_link_hash_copy_indirect (dir, ind);
2592 /* Look through the relocs for a section during the first phase, and
2593 calculate needed space in the global offset table, procedure
2594 linkage table, and dynamic reloc sections. */
2597 ppc64_elf_check_relocs (abfd, info, sec, relocs)
2599 struct bfd_link_info *info;
2601 const Elf_Internal_Rela *relocs;
2603 struct ppc_link_hash_table *htab;
2604 Elf_Internal_Shdr *symtab_hdr;
2605 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2606 const Elf_Internal_Rela *rel;
2607 const Elf_Internal_Rela *rel_end;
2611 if (info->relocateable)
2614 htab = ppc_hash_table (info);
2615 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2617 sym_hashes = elf_sym_hashes (abfd);
2618 sym_hashes_end = (sym_hashes
2619 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym));
2620 if (!elf_bad_symtab (abfd))
2621 sym_hashes_end -= symtab_hdr->sh_info;
2624 is_opd = strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0;
2626 if (htab->elf.dynobj == NULL)
2627 htab->elf.dynobj = abfd;
2628 if (htab->sfpr == NULL
2629 && !create_linkage_sections (htab->elf.dynobj, info))
2632 rel_end = relocs + sec->reloc_count;
2633 for (rel = relocs; rel < rel_end; rel++)
2635 unsigned long r_symndx;
2636 struct elf_link_hash_entry *h;
2637 enum elf_ppc_reloc_type r_type;
2639 r_symndx = ELF64_R_SYM (rel->r_info);
2640 if (r_symndx < symtab_hdr->sh_info)
2643 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2645 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2648 /* GOT16 relocations */
2650 case R_PPC64_GOT16_DS:
2651 case R_PPC64_GOT16_HA:
2652 case R_PPC64_GOT16_HI:
2653 case R_PPC64_GOT16_LO:
2654 case R_PPC64_GOT16_LO_DS:
2656 /* This symbol requires a global offset table entry. */
2657 if (htab->sgot == NULL
2658 && !create_got_section (htab->elf.dynobj, info))
2663 h->got.refcount += 1;
2667 bfd_signed_vma *local_got_refcounts;
2669 /* This is a global offset table entry for a local symbol. */
2670 local_got_refcounts = elf_local_got_refcounts (abfd);
2671 if (local_got_refcounts == NULL)
2675 size = symtab_hdr->sh_info;
2676 size *= sizeof (bfd_signed_vma);
2677 local_got_refcounts = ((bfd_signed_vma *)
2678 bfd_zalloc (abfd, size));
2679 if (local_got_refcounts == NULL)
2681 elf_local_got_refcounts (abfd) = local_got_refcounts;
2683 local_got_refcounts[r_symndx] += 1;
2687 case R_PPC64_PLT16_HA:
2688 case R_PPC64_PLT16_HI:
2689 case R_PPC64_PLT16_LO:
2692 /* This symbol requires a procedure linkage table entry. We
2693 actually build the entry in adjust_dynamic_symbol,
2694 because this might be a case of linking PIC code without
2695 linking in any dynamic objects, in which case we don't
2696 need to generate a procedure linkage table after all. */
2699 /* It does not make sense to have a procedure linkage
2700 table entry for a local symbol. */
2701 bfd_set_error (bfd_error_bad_value);
2705 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2706 h->plt.refcount += 1;
2707 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2710 /* The following relocations don't need to propagate the
2711 relocation if linking a shared object since they are
2712 section relative. */
2713 case R_PPC64_SECTOFF:
2714 case R_PPC64_SECTOFF_LO:
2715 case R_PPC64_SECTOFF_HI:
2716 case R_PPC64_SECTOFF_HA:
2717 case R_PPC64_SECTOFF_DS:
2718 case R_PPC64_SECTOFF_LO_DS:
2720 case R_PPC64_TOC16_LO:
2721 case R_PPC64_TOC16_HI:
2722 case R_PPC64_TOC16_HA:
2723 case R_PPC64_TOC16_DS:
2724 case R_PPC64_TOC16_LO_DS:
2727 /* This relocation describes the C++ object vtable hierarchy.
2728 Reconstruct it for later use during GC. */
2729 case R_PPC64_GNU_VTINHERIT:
2730 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2734 /* This relocation describes which C++ vtable entries are actually
2735 used. Record for later use during GC. */
2736 case R_PPC64_GNU_VTENTRY:
2737 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2742 case R_PPC64_REL14_BRTAKEN:
2743 case R_PPC64_REL14_BRNTAKEN:
2744 htab->has_14bit_branch = 1;
2749 && h->root.root.string[0] == '.'
2750 && h->root.root.string[1] != 0)
2752 /* We may need a .plt entry if the function this reloc
2753 refers to is in a shared lib. */
2754 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2755 h->plt.refcount += 1;
2756 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2760 case R_PPC64_ADDR64:
2763 && h->root.root.string[0] == '.'
2764 && h->root.root.string[1] != 0)
2766 struct elf_link_hash_entry *fdh;
2768 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
2769 false, false, false);
2772 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
2773 ((struct ppc_link_hash_entry *) fdh)->oh = h;
2774 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2775 ((struct ppc_link_hash_entry *) h)->oh = fdh;
2782 case R_PPC64_ADDR14:
2783 case R_PPC64_ADDR14_BRNTAKEN:
2784 case R_PPC64_ADDR14_BRTAKEN:
2785 case R_PPC64_ADDR16:
2786 case R_PPC64_ADDR16_DS:
2787 case R_PPC64_ADDR16_HA:
2788 case R_PPC64_ADDR16_HI:
2789 case R_PPC64_ADDR16_HIGHER:
2790 case R_PPC64_ADDR16_HIGHERA:
2791 case R_PPC64_ADDR16_HIGHEST:
2792 case R_PPC64_ADDR16_HIGHESTA:
2793 case R_PPC64_ADDR16_LO:
2794 case R_PPC64_ADDR16_LO_DS:
2795 case R_PPC64_ADDR24:
2796 case R_PPC64_ADDR30:
2797 case R_PPC64_ADDR32:
2798 case R_PPC64_UADDR16:
2799 case R_PPC64_UADDR32:
2800 case R_PPC64_UADDR64:
2802 /* Don't propagate .opd relocs. */
2803 if (NO_OPD_RELOCS && is_opd)
2806 /* If we are creating a shared library, and this is a reloc
2807 against a global symbol, or a non PC relative reloc
2808 against a local symbol, then we need to copy the reloc
2809 into the shared library. However, if we are linking with
2810 -Bsymbolic, we do not need to copy a reloc against a
2811 global symbol which is defined in an object we are
2812 including in the link (i.e., DEF_REGULAR is set). At
2813 this point we have not seen all the input files, so it is
2814 possible that DEF_REGULAR is not set now but will be set
2815 later (it is never cleared). In case of a weak definition,
2816 DEF_REGULAR may be cleared later by a strong definition in
2817 a shared library. We account for that possibility below by
2818 storing information in the relocs_copied field of the hash
2819 table entry. A similar situation occurs when creating
2820 shared libraries and symbol visibility changes render the
2823 If on the other hand, we are creating an executable, we
2824 may need to keep relocations for symbols satisfied by a
2825 dynamic library if we manage to avoid copy relocs for the
2828 && (sec->flags & SEC_ALLOC) != 0
2829 && (IS_ABSOLUTE_RELOC (r_type)
2831 && (! info->symbolic
2832 || h->root.type == bfd_link_hash_defweak
2833 || (h->elf_link_hash_flags
2834 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2836 && (sec->flags & SEC_ALLOC) != 0
2838 && (h->root.type == bfd_link_hash_defweak
2839 || (h->elf_link_hash_flags
2840 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
2842 struct ppc_dyn_relocs *p;
2843 struct ppc_dyn_relocs **head;
2845 /* We must copy these reloc types into the output file.
2846 Create a reloc section in dynobj and make room for
2853 name = (bfd_elf_string_from_elf_section
2855 elf_elfheader (abfd)->e_shstrndx,
2856 elf_section_data (sec)->rel_hdr.sh_name));
2860 if (strncmp (name, ".rela", 5) != 0
2861 || strcmp (bfd_get_section_name (abfd, sec),
2864 (*_bfd_error_handler)
2865 (_("%s: bad relocation section name `%s\'"),
2866 bfd_archive_filename (abfd), name);
2867 bfd_set_error (bfd_error_bad_value);
2870 dynobj = htab->elf.dynobj;
2871 sreloc = bfd_get_section_by_name (dynobj, name);
2876 sreloc = bfd_make_section (dynobj, name);
2877 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2878 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2879 if ((sec->flags & SEC_ALLOC) != 0)
2880 flags |= SEC_ALLOC | SEC_LOAD;
2882 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2883 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
2886 elf_section_data (sec)->sreloc = sreloc;
2889 /* If this is a global symbol, we count the number of
2890 relocations we need for this symbol. */
2893 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
2897 /* Track dynamic relocs needed for local syms too.
2898 We really need local syms available to do this
2902 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
2907 head = ((struct ppc_dyn_relocs **)
2908 &elf_section_data (s)->local_dynrel);
2912 if (p == NULL || p->sec != sec)
2914 p = ((struct ppc_dyn_relocs *)
2915 bfd_alloc (htab->elf.dynobj,
2916 (bfd_size_type) sizeof *p));
2927 if (!IS_ABSOLUTE_RELOC (r_type))
2940 /* Return the section that should be marked against GC for a given
2944 ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym)
2946 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2947 Elf_Internal_Rela *rel;
2948 struct elf_link_hash_entry *h;
2949 Elf_Internal_Sym *sym;
2953 enum elf_ppc_reloc_type r_type;
2955 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2958 case R_PPC64_GNU_VTINHERIT:
2959 case R_PPC64_GNU_VTENTRY:
2963 switch (h->root.type)
2965 case bfd_link_hash_defined:
2966 case bfd_link_hash_defweak:
2967 return h->root.u.def.section;
2969 case bfd_link_hash_common:
2970 return h->root.u.c.p->section;
2979 return bfd_section_from_elf_index (abfd, sym->st_shndx);
2985 /* Update the .got, .plt. and dynamic reloc reference counts for the
2986 section being removed. */
2989 ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
2991 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2993 const Elf_Internal_Rela *relocs;
2995 Elf_Internal_Shdr *symtab_hdr;
2996 struct elf_link_hash_entry **sym_hashes;
2997 bfd_signed_vma *local_got_refcounts;
2998 const Elf_Internal_Rela *rel, *relend;
3000 elf_section_data (sec)->local_dynrel = NULL;
3002 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3003 sym_hashes = elf_sym_hashes (abfd);
3004 local_got_refcounts = elf_local_got_refcounts (abfd);
3006 relend = relocs + sec->reloc_count;
3007 for (rel = relocs; rel < relend; rel++)
3009 unsigned long r_symndx;
3010 enum elf_ppc_reloc_type r_type;
3011 struct elf_link_hash_entry *h;
3013 r_symndx = ELF64_R_SYM (rel->r_info);
3014 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3018 case R_PPC64_GOT16_DS:
3019 case R_PPC64_GOT16_HA:
3020 case R_PPC64_GOT16_HI:
3021 case R_PPC64_GOT16_LO:
3022 case R_PPC64_GOT16_LO_DS:
3023 if (r_symndx >= symtab_hdr->sh_info)
3025 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3026 if (h->got.refcount > 0)
3031 if (local_got_refcounts[r_symndx] > 0)
3032 local_got_refcounts[r_symndx]--;
3036 case R_PPC64_PLT16_HA:
3037 case R_PPC64_PLT16_HI:
3038 case R_PPC64_PLT16_LO:
3041 if (r_symndx >= symtab_hdr->sh_info)
3043 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3044 if (h->plt.refcount > 0)
3050 case R_PPC64_REL14_BRNTAKEN:
3051 case R_PPC64_REL14_BRTAKEN:
3053 if (r_symndx >= symtab_hdr->sh_info)
3055 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3056 if (h->plt.refcount > 0)
3063 if (r_symndx >= symtab_hdr->sh_info)
3065 struct ppc_link_hash_entry *eh;
3066 struct ppc_dyn_relocs **pp;
3067 struct ppc_dyn_relocs *p;
3069 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3070 eh = (struct ppc_link_hash_entry *) h;
3072 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3084 case R_PPC64_ADDR14:
3085 case R_PPC64_ADDR14_BRNTAKEN:
3086 case R_PPC64_ADDR14_BRTAKEN:
3087 case R_PPC64_ADDR16:
3088 case R_PPC64_ADDR16_DS:
3089 case R_PPC64_ADDR16_HA:
3090 case R_PPC64_ADDR16_HI:
3091 case R_PPC64_ADDR16_HIGHER:
3092 case R_PPC64_ADDR16_HIGHERA:
3093 case R_PPC64_ADDR16_HIGHEST:
3094 case R_PPC64_ADDR16_HIGHESTA:
3095 case R_PPC64_ADDR16_LO:
3096 case R_PPC64_ADDR16_LO_DS:
3097 case R_PPC64_ADDR24:
3098 case R_PPC64_ADDR30:
3099 case R_PPC64_ADDR32:
3100 case R_PPC64_ADDR64:
3101 case R_PPC64_UADDR16:
3102 case R_PPC64_UADDR32:
3103 case R_PPC64_UADDR64:
3105 if (r_symndx >= symtab_hdr->sh_info)
3107 struct ppc_link_hash_entry *eh;
3108 struct ppc_dyn_relocs **pp;
3109 struct ppc_dyn_relocs *p;
3111 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3112 eh = (struct ppc_link_hash_entry *) h;
3114 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3132 /* Called via elf_link_hash_traverse to transfer dynamic linking
3133 information on function code symbol entries to their corresponding
3134 function descriptor symbol entries. */
3136 func_desc_adjust (h, inf)
3137 struct elf_link_hash_entry *h;
3140 struct bfd_link_info *info;
3141 struct ppc_link_hash_table *htab;
3143 if (h->root.type == bfd_link_hash_indirect)
3146 if (h->root.type == bfd_link_hash_warning)
3147 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3149 info = (struct bfd_link_info *) inf;
3150 htab = ppc_hash_table (info);
3152 /* If this is a function code symbol, transfer dynamic linking
3153 information to the function descriptor symbol. */
3154 if (!((struct ppc_link_hash_entry *) h)->is_func)
3157 if (h->root.type == bfd_link_hash_undefweak
3158 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
3159 htab->have_undefweak = true;
3161 if (h->plt.refcount > 0
3162 && h->root.root.string[0] == '.'
3163 && h->root.root.string[1] != '\0')
3165 struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh;
3166 boolean force_local;
3168 /* Find the corresponding function descriptor symbol. Create it
3169 as undefined if necessary. */
3172 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
3173 false, false, true);
3177 && (h->root.type == bfd_link_hash_undefined
3178 || h->root.type == bfd_link_hash_undefweak))
3183 abfd = h->root.u.undef.abfd;
3184 newsym = bfd_make_empty_symbol (abfd);
3185 newsym->name = h->root.root.string + 1;
3186 newsym->section = bfd_und_section_ptr;
3188 newsym->flags = BSF_OBJECT;
3189 if (h->root.type == bfd_link_hash_undefweak)
3190 newsym->flags |= BSF_WEAK;
3192 if ( !(_bfd_generic_link_add_one_symbol
3193 (info, abfd, newsym->name, newsym->flags,
3194 newsym->section, newsym->value, NULL, false, false,
3195 (struct bfd_link_hash_entry **) &fdh)))
3199 fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
3203 && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
3205 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3206 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
3208 if (fdh->dynindx == -1)
3209 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
3211 fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
3212 & (ELF_LINK_HASH_REF_REGULAR
3213 | ELF_LINK_HASH_REF_DYNAMIC
3214 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3215 | ELF_LINK_NON_GOT_REF));
3216 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3218 fdh->plt.refcount = h->plt.refcount;
3219 fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3221 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
3222 ((struct ppc_link_hash_entry *) fdh)->oh = h;
3223 ((struct ppc_link_hash_entry *) h)->oh = fdh;
3226 /* Now that the info is on the function descriptor, clear the
3227 function code sym info. Any function code syms for which we
3228 don't have a definition in a regular file, we force local.
3229 This prevents a shared library from exporting syms that have
3230 been imported from another library. Function code syms that
3231 are really in the library we must leave global to prevent the
3232 linker dragging in a definition from a static library. */
3233 force_local = (info->shared
3234 && ((h->elf_link_hash_flags
3235 & ELF_LINK_HASH_DEF_REGULAR) == 0
3237 || (fdh->elf_link_hash_flags
3238 & ELF_LINK_HASH_DEF_REGULAR) == 0
3239 || (fdh->elf_link_hash_flags
3240 & ELF_LINK_FORCED_LOCAL) != 0));
3241 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3247 #define MIN_SAVE_FPR 14
3248 #define MAX_SAVE_FPR 31
3250 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3251 this hook to a) provide some gcc support functions, and b) transfer
3252 dynamic linking information gathered so far on function code symbol
3253 entries, to their corresponding function descriptor symbol entries. */
3255 ppc64_elf_func_desc_adjust (obfd, info)
3256 bfd *obfd ATTRIBUTE_UNUSED;
3257 struct bfd_link_info *info;
3259 struct ppc_link_hash_table *htab;
3260 unsigned int lowest_savef = MAX_SAVE_FPR + 2;
3261 unsigned int lowest_restf = MAX_SAVE_FPR + 2;
3263 struct elf_link_hash_entry *h;
3267 htab = ppc_hash_table (info);
3269 if (htab->sfpr == NULL)
3270 /* We don't have any relocs. */
3273 /* First provide any missing ._savef* and ._restf* functions. */
3274 memcpy (sym, "._savef14", 10);
3275 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3277 sym[7] = i / 10 + '0';
3278 sym[8] = i % 10 + '0';
3279 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3281 && h->root.type == bfd_link_hash_undefined)
3283 if (lowest_savef > i)
3285 h->root.type = bfd_link_hash_defined;
3286 h->root.u.def.section = htab->sfpr;
3287 h->root.u.def.value = (i - lowest_savef) * 4;
3289 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3290 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3294 memcpy (sym, "._restf14", 10);
3295 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3297 sym[7] = i / 10 + '0';
3298 sym[8] = i % 10 + '0';
3299 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3301 && h->root.type == bfd_link_hash_undefined)
3303 if (lowest_restf > i)
3305 h->root.type = bfd_link_hash_defined;
3306 h->root.u.def.section = htab->sfpr;
3307 h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3308 + (i - lowest_restf) * 4);
3310 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3311 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3315 elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
3317 htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3318 + (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
3320 if (htab->sfpr->_raw_size == 0)
3322 if (!htab->have_undefweak)
3324 _bfd_strip_section_from_output (info, htab->sfpr);
3328 htab->sfpr->_raw_size = 4;
3331 p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size);
3334 htab->sfpr->contents = p;
3336 for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
3338 unsigned int fpr = i << 21;
3339 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3340 bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
3343 if (lowest_savef <= MAX_SAVE_FPR)
3345 bfd_put_32 (htab->elf.dynobj, BLR, p);
3349 for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
3351 unsigned int fpr = i << 21;
3352 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3353 bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
3356 if (lowest_restf <= MAX_SAVE_FPR
3357 || htab->sfpr->_raw_size == 4)
3359 bfd_put_32 (htab->elf.dynobj, BLR, p);
3365 /* Adjust a symbol defined by a dynamic object and referenced by a
3366 regular object. The current definition is in some section of the
3367 dynamic object, but we're not including those sections. We have to
3368 change the definition to something the rest of the link can
3372 ppc64_elf_adjust_dynamic_symbol (info, h)
3373 struct bfd_link_info *info;
3374 struct elf_link_hash_entry *h;
3376 struct ppc_link_hash_table *htab;
3377 struct ppc_link_hash_entry * eh;
3378 struct ppc_dyn_relocs *p;
3380 unsigned int power_of_two;
3382 htab = ppc_hash_table (info);
3384 /* Deal with function syms. */
3385 if (h->type == STT_FUNC
3386 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3388 /* Clear procedure linkage table information for any symbol that
3389 won't need a .plt entry. */
3390 if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
3391 || h->plt.refcount <= 0
3392 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3394 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3395 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
3397 h->plt.offset = (bfd_vma) -1;
3398 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3403 h->plt.offset = (bfd_vma) -1;
3405 /* If this is a weak symbol, and there is a real definition, the
3406 processor independent code will have arranged for us to see the
3407 real definition first, and we can just use the same value. */
3408 if (h->weakdef != NULL)
3410 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3411 || h->weakdef->root.type == bfd_link_hash_defweak);
3412 h->root.u.def.section = h->weakdef->root.u.def.section;
3413 h->root.u.def.value = h->weakdef->root.u.def.value;
3417 /* This is a reference to a symbol defined by a dynamic object which
3418 is not a function. */
3420 /* If we are creating a shared library, we must presume that the
3421 only references to the symbol are via the global offset table.
3422 For such cases we need not do anything here; the relocations will
3423 be handled correctly by relocate_section. */
3427 /* If there are no references to this symbol that do not use the
3428 GOT, we don't need to generate a copy reloc. */
3429 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3432 eh = (struct ppc_link_hash_entry *) h;
3433 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3435 s = p->sec->output_section;
3436 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3440 /* If we didn't find any dynamic relocs in read-only sections, then
3441 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3444 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3448 /* We must allocate the symbol in our .dynbss section, which will
3449 become part of the .bss section of the executable. There will be
3450 an entry for this symbol in the .dynsym section. The dynamic
3451 object will contain position independent code, so all references
3452 from the dynamic object to this symbol will go through the global
3453 offset table. The dynamic linker will use the .dynsym entry to
3454 determine the address it must put in the global offset table, so
3455 both the dynamic object and the regular object will refer to the
3456 same memory location for the variable. */
3458 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3459 copy the initial value out of the dynamic object and into the
3460 runtime process image. We need to remember the offset into the
3461 .rela.bss section we are going to use. */
3462 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3464 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
3465 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3468 /* We need to figure out the alignment required for this symbol. I
3469 have no idea how ELF linkers handle this. */
3470 power_of_two = bfd_log2 (h->size);
3471 if (power_of_two > 4)
3474 /* Apply the required alignment. */
3476 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3477 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3479 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3483 /* Define the symbol as being at this point in the section. */
3484 h->root.u.def.section = s;
3485 h->root.u.def.value = s->_raw_size;
3487 /* Increment the section size to make room for the symbol. */
3488 s->_raw_size += h->size;
3493 /* If given a function descriptor symbol, hide both the function code
3494 sym and the descriptor. */
3496 ppc64_elf_hide_symbol (info, h, force_local)
3497 struct bfd_link_info *info;
3498 struct elf_link_hash_entry *h;
3499 boolean force_local;
3501 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3503 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
3505 struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh;
3510 struct ppc_link_hash_table *htab;
3513 /* We aren't supposed to use alloca in BFD because on
3514 systems which do not have alloca the version in libiberty
3515 calls xmalloc, which might cause the program to crash
3516 when it runs out of memory. This function doesn't have a
3517 return status, so there's no way to gracefully return an
3518 error. So cheat. We know that string[-1] can be safely
3519 dereferenced; It's either a string in an ELF string
3520 table, or allocated in an objalloc structure. */
3522 p = h->root.root.string - 1;
3525 htab = ppc_hash_table (info);
3526 fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3529 /* Unfortunately, if it so happens that the string we were
3530 looking for was allocated immediately before this string,
3531 then we overwrote the string terminator. That's the only
3532 reason the lookup should fail. */
3535 q = h->root.root.string + strlen (h->root.root.string);
3536 while (q >= h->root.root.string && *q == *p)
3538 if (q < h->root.root.string && *p == '.')
3539 fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3543 ((struct ppc_link_hash_entry *) h)->oh = fh;
3544 ((struct ppc_link_hash_entry *) fh)->oh = h;
3548 _bfd_elf_link_hash_hide_symbol (info, fh, force_local);
3552 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3553 will be called from elflink.h. If elflink.h doesn't call our
3554 finish_dynamic_symbol routine, we'll need to do something about
3555 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3556 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3558 && ((INFO)->shared \
3559 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3560 && ((H)->dynindx != -1 \
3561 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3563 /* Allocate space in .plt, .got and associated reloc sections for
3567 allocate_dynrelocs (h, inf)
3568 struct elf_link_hash_entry *h;
3571 struct bfd_link_info *info;
3572 struct ppc_link_hash_table *htab;
3574 struct ppc_link_hash_entry *eh;
3575 struct ppc_dyn_relocs *p;
3577 if (h->root.type == bfd_link_hash_indirect)
3580 if (h->root.type == bfd_link_hash_warning)
3581 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3583 info = (struct bfd_link_info *) inf;
3584 htab = ppc_hash_table (info);
3586 if (htab->elf.dynamic_sections_created
3587 && h->plt.refcount > 0
3588 && h->dynindx != -1)
3590 BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
3592 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
3594 /* If this is the first .plt entry, make room for the special
3597 if (s->_raw_size == 0)
3598 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
3600 h->plt.offset = s->_raw_size;
3602 /* Make room for this entry. */
3603 s->_raw_size += PLT_ENTRY_SIZE;
3605 /* Make room for the .glink code. */
3607 if (s->_raw_size == 0)
3608 s->_raw_size += GLINK_CALL_STUB_SIZE;
3609 /* We need bigger stubs past index 32767. */
3610 if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
3612 s->_raw_size += 2*4;
3614 /* We also need to make an entry in the .rela.plt section. */
3616 s->_raw_size += sizeof (Elf64_External_Rela);
3620 h->plt.offset = (bfd_vma) -1;
3621 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3626 h->plt.offset = (bfd_vma) -1;
3627 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3630 if (h->got.refcount > 0)
3634 /* Make sure this symbol is output as a dynamic symbol.
3635 Undefined weak syms won't yet be marked as dynamic. */
3636 if (h->dynindx == -1
3637 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3639 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3644 h->got.offset = s->_raw_size;
3646 dyn = htab->elf.dynamic_sections_created;
3647 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
3648 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
3651 h->got.offset = (bfd_vma) -1;
3653 eh = (struct ppc_link_hash_entry *) h;
3654 if (eh->dyn_relocs == NULL)
3657 /* In the shared -Bsymbolic case, discard space allocated for
3658 dynamic pc-relative relocs against symbols which turn out to be
3659 defined in regular objects. For the normal shared case, discard
3660 space for relocs that have become local due to symbol visibility
3665 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
3666 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3669 struct ppc_dyn_relocs **pp;
3671 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3673 p->count -= p->pc_count;
3684 /* For the non-shared case, discard space for relocs against
3685 symbols which turn out to need copy relocs or are not
3688 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3689 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3690 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3691 || (htab->elf.dynamic_sections_created
3692 && (h->root.type == bfd_link_hash_undefweak
3693 || h->root.type == bfd_link_hash_undefined))))
3695 /* Make sure this symbol is output as a dynamic symbol.
3696 Undefined weak syms won't yet be marked as dynamic. */
3697 if (h->dynindx == -1
3698 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3700 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3704 /* If that succeeded, we know we'll be keeping all the
3706 if (h->dynindx != -1)
3710 eh->dyn_relocs = NULL;
3715 /* Finally, allocate space. */
3716 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3718 asection *sreloc = elf_section_data (p->sec)->sreloc;
3719 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
3725 /* Find any dynamic relocs that apply to read-only sections. */
3728 readonly_dynrelocs (h, inf)
3729 struct elf_link_hash_entry *h;
3732 struct ppc_link_hash_entry *eh;
3733 struct ppc_dyn_relocs *p;
3735 if (h->root.type == bfd_link_hash_warning)
3736 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3738 eh = (struct ppc_link_hash_entry *) h;
3739 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3741 asection *s = p->sec->output_section;
3743 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3745 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3747 info->flags |= DF_TEXTREL;
3749 /* Not an error, just cut short the traversal. */
3756 /* Set the sizes of the dynamic sections. */
3759 ppc64_elf_size_dynamic_sections (output_bfd, info)
3760 bfd *output_bfd ATTRIBUTE_UNUSED;
3761 struct bfd_link_info *info;
3763 struct ppc_link_hash_table *htab;
3769 htab = ppc_hash_table (info);
3770 dynobj = htab->elf.dynobj;
3774 if (htab->elf.dynamic_sections_created)
3776 /* Set the contents of the .interp section to the interpreter. */
3779 s = bfd_get_section_by_name (dynobj, ".interp");
3782 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3783 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3787 /* Set up .got offsets for local syms, and space for local dynamic
3789 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3791 bfd_signed_vma *local_got;
3792 bfd_signed_vma *end_local_got;
3793 bfd_size_type locsymcount;
3794 Elf_Internal_Shdr *symtab_hdr;
3797 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3800 for (s = ibfd->sections; s != NULL; s = s->next)
3802 struct ppc_dyn_relocs *p;
3804 for (p = *((struct ppc_dyn_relocs **)
3805 &elf_section_data (s)->local_dynrel);
3809 if (!bfd_is_abs_section (p->sec)
3810 && bfd_is_abs_section (p->sec->output_section))
3812 /* Input section has been discarded, either because
3813 it is a copy of a linkonce section or due to
3814 linker script /DISCARD/, so we'll be discarding
3817 else if (p->count != 0)
3819 srel = elf_section_data (p->sec)->sreloc;
3820 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
3821 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3822 info->flags |= DF_TEXTREL;
3827 local_got = elf_local_got_refcounts (ibfd);
3831 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3832 locsymcount = symtab_hdr->sh_info;
3833 end_local_got = local_got + locsymcount;
3835 srel = htab->srelgot;
3836 for (; local_got < end_local_got; ++local_got)
3840 *local_got = s->_raw_size;
3843 srel->_raw_size += sizeof (Elf64_External_Rela);
3846 *local_got = (bfd_vma) -1;
3850 /* Allocate global sym .plt and .got entries, and space for global
3851 sym dynamic relocs. */
3852 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
3854 /* We now have determined the sizes of the various dynamic sections.
3855 Allocate memory for them. */
3857 for (s = dynobj->sections; s != NULL; s = s->next)
3859 if ((s->flags & SEC_LINKER_CREATED) == 0)
3862 if (s == htab->sbrlt || s == htab->srelbrlt)
3863 /* These haven't been allocated yet; don't strip. */
3865 else if (s == htab->splt
3867 || s == htab->sglink)
3869 /* Strip this section if we don't need it; see the
3872 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
3874 if (s->_raw_size == 0)
3876 /* If we don't need this section, strip it from the
3877 output file. This is mostly to handle .rela.bss and
3878 .rela.plt. We must create both sections in
3879 create_dynamic_sections, because they must be created
3880 before the linker maps input sections to output
3881 sections. The linker does that before
3882 adjust_dynamic_symbol is called, and it is that
3883 function which decides whether anything needs to go
3884 into these sections. */
3888 if (s != htab->srelplt)
3891 /* We use the reloc_count field as a counter if we need
3892 to copy relocs into the output file. */
3898 /* It's not one of our sections, so don't allocate space. */
3902 if (s->_raw_size == 0)
3904 _bfd_strip_section_from_output (info, s);
3908 /* Allocate memory for the section contents. We use bfd_zalloc
3909 here in case unused entries are not reclaimed before the
3910 section's contents are written out. This should not happen,
3911 but this way if it does, we get a R_PPC64_NONE reloc instead
3913 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
3914 if (s->contents == NULL)
3918 if (htab->elf.dynamic_sections_created)
3920 /* Add some entries to the .dynamic section. We fill in the
3921 values later, in ppc64_elf_finish_dynamic_sections, but we
3922 must add the entries now so that we get the correct size for
3923 the .dynamic section. The DT_DEBUG entry is filled in by the
3924 dynamic linker and used by the debugger. */
3925 #define add_dynamic_entry(TAG, VAL) \
3926 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3930 if (!add_dynamic_entry (DT_DEBUG, 0))
3934 if (htab->splt != NULL && htab->splt->_raw_size != 0)
3936 if (!add_dynamic_entry (DT_PLTGOT, 0)
3937 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3938 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3939 || !add_dynamic_entry (DT_JMPREL, 0)
3940 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
3946 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
3947 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
3953 if (!add_dynamic_entry (DT_RELA, 0)
3954 || !add_dynamic_entry (DT_RELASZ, 0)
3955 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
3958 /* If any dynamic relocs apply to a read-only section,
3959 then we need a DT_TEXTREL entry. */
3960 if ((info->flags & DF_TEXTREL) == 0)
3961 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
3964 if ((info->flags & DF_TEXTREL) != 0)
3966 if (!add_dynamic_entry (DT_TEXTREL, 0))
3971 #undef add_dynamic_entry
3976 /* Determine the type of stub needed, if any, for a call. */
3978 static INLINE enum ppc_stub_type
3979 ppc_type_of_stub (input_sec, rel, hash, destination)
3980 asection *input_sec;
3981 const Elf_Internal_Rela *rel;
3982 struct ppc_link_hash_entry **hash;
3983 bfd_vma destination;
3985 struct ppc_link_hash_entry *h = *hash;
3987 bfd_vma branch_offset;
3988 bfd_vma max_branch_offset;
3989 unsigned int r_type;
3994 && h->oh->plt.offset != (bfd_vma) -1
3995 && h->oh->dynindx != -1)
3997 *hash = (struct ppc_link_hash_entry *) h->oh;
3998 return ppc_stub_plt_call;
4001 if (h->elf.root.type == bfd_link_hash_undefweak
4002 || h->elf.root.type == bfd_link_hash_undefined)
4003 return ppc_stub_none;
4006 /* Determine where the call point is. */
4007 location = (input_sec->output_offset
4008 + input_sec->output_section->vma
4011 branch_offset = destination - location;
4012 r_type = ELF64_R_TYPE (rel->r_info);
4014 /* Determine if a long branch stub is needed. */
4015 max_branch_offset = 1 << 25;
4016 if (r_type != (unsigned int) R_PPC64_REL24)
4017 max_branch_offset = 1 << 15;
4019 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
4020 /* We need a stub. Figure out whether a long_branch or plt_branch
4022 return ppc_stub_long_branch;
4024 return ppc_stub_none;
4027 /* Build a .plt call stub. */
4030 build_plt_stub (obfd, p, offset, glink)
4036 #define PPC_LO(v) ((v) & 0xffff)
4037 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4038 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4041 bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
4042 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
4044 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
4045 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4046 if (PPC_HA (offset + 8) != PPC_HA (offset))
4047 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4049 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
4050 if (PPC_HA (offset + 8) != PPC_HA (offset))
4051 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4053 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
4054 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4055 bfd_put_32 (obfd, BCTR, p), p += 4;
4060 ppc_build_one_stub (gen_entry, in_arg)
4061 struct bfd_hash_entry *gen_entry;
4064 struct ppc_stub_hash_entry *stub_entry;
4065 struct ppc_branch_hash_entry *br_entry;
4066 struct bfd_link_info *info;
4067 struct ppc_link_hash_table *htab;
4076 /* Massage our args to the form they really have. */
4077 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4078 info = (struct bfd_link_info *) in_arg;
4080 htab = ppc_hash_table (info);
4081 stub_sec = stub_entry->stub_sec;
4083 /* Make a note of the offset within the stubs for this entry. */
4084 stub_entry->stub_offset = stub_sec->_cooked_size;
4085 loc = stub_sec->contents + stub_entry->stub_offset;
4087 stub_bfd = stub_sec->owner;
4089 switch (stub_entry->stub_type)
4091 case ppc_stub_long_branch:
4092 /* Branches are relative. This is where we are going to. */
4093 off = (stub_entry->target_value
4094 + stub_entry->target_section->output_offset
4095 + stub_entry->target_section->output_section->vma);
4097 /* And this is where we are coming from. */
4098 off -= (stub_entry->stub_offset
4099 + stub_sec->output_offset
4100 + stub_sec->output_section->vma);
4102 BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
4104 bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc);
4108 case ppc_stub_plt_branch:
4109 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4110 stub_entry->root.string + 9,
4112 if (br_entry == NULL)
4114 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
4115 stub_entry->root.string + 9);
4116 htab->stub_error = true;
4120 off = (stub_entry->target_value
4121 + stub_entry->target_section->output_offset
4122 + stub_entry->target_section->output_section->vma);
4124 bfd_put_64 (htab->sbrlt->owner, off,
4125 htab->sbrlt->contents + br_entry->offset);
4129 /* Create a reloc for the branch lookup table entry. */
4130 Elf_Internal_Rela rela;
4131 Elf64_External_Rela *r;
4133 rela.r_offset = (br_entry->offset
4134 + htab->sbrlt->output_offset
4135 + htab->sbrlt->output_section->vma);
4136 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
4137 rela.r_addend = off;
4139 r = (Elf64_External_Rela *) htab->srelbrlt->contents;
4140 r += htab->srelbrlt->reloc_count++;
4141 bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, r);
4144 off = (br_entry->offset
4145 + htab->sbrlt->output_offset
4146 + htab->sbrlt->output_section->vma
4147 - elf_gp (htab->sbrlt->output_section->owner)
4150 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4152 (*_bfd_error_handler)
4153 (_("linkage table error against `%s'"),
4154 stub_entry->root.string);
4155 bfd_set_error (bfd_error_bad_value);
4156 htab->stub_error = true;
4161 bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc);
4162 bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4);
4163 bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8);
4164 bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12);
4168 case ppc_stub_plt_call:
4169 /* Build the .glink lazy link call stub. */
4170 p = htab->sglink->contents + htab->sglink->_cooked_size;
4171 indx = htab->sglink->reloc_count;
4174 bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p);
4179 bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p);
4181 bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
4184 bfd_put_32 (htab->sglink->owner,
4185 B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p);
4187 htab->sglink->_cooked_size = p - htab->sglink->contents;
4188 htab->sglink->reloc_count += 1;
4190 /* Do the best we can for shared libraries built without
4191 exporting ".foo" for each "foo". This can happen when symbol
4192 versioning scripts strip all bar a subset of symbols. */
4193 if (stub_entry->h->oh->root.type != bfd_link_hash_defined
4194 && stub_entry->h->oh->root.type != bfd_link_hash_defweak)
4196 /* Point the symbol at the stub. There may be multiple stubs,
4197 we don't really care; The main thing is to make this sym
4198 defined somewhere. */
4199 stub_entry->h->oh->root.type = bfd_link_hash_defined;
4200 stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec;
4201 stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset;
4204 /* Now build the stub. */
4205 off = stub_entry->h->elf.plt.offset;
4206 if (off >= (bfd_vma) -2)
4209 off &= ~ (bfd_vma) 1;
4210 off += (htab->splt->output_offset
4211 + htab->splt->output_section->vma
4212 - elf_gp (htab->splt->output_section->owner)
4215 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4217 (*_bfd_error_handler)
4218 (_("linkage table error against `%s'"),
4219 stub_entry->h->elf.root.root.string);
4220 bfd_set_error (bfd_error_bad_value);
4221 htab->stub_error = true;
4225 p = build_plt_stub (stub_bfd, loc, (int) off, 0);
4234 stub_sec->_cooked_size += size;
4238 /* As above, but don't actually build the stub. Just bump offset so
4239 we know stub section sizes, and select plt_branch stubs where
4240 long_branch stubs won't do. */
4243 ppc_size_one_stub (gen_entry, in_arg)
4244 struct bfd_hash_entry *gen_entry;
4247 struct ppc_stub_hash_entry *stub_entry;
4248 struct ppc_link_hash_table *htab;
4252 /* Massage our args to the form they really have. */
4253 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4254 htab = (struct ppc_link_hash_table *) in_arg;
4256 if (stub_entry->stub_type == ppc_stub_plt_call)
4258 off = stub_entry->h->elf.plt.offset & ~(bfd_vma) 1;
4259 off += (htab->splt->output_offset
4260 + htab->splt->output_section->vma
4261 - elf_gp (htab->splt->output_section->owner)
4265 if (PPC_HA ((int) off + 16) != PPC_HA ((int) off))
4270 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4271 stub_entry->stub_type = ppc_stub_long_branch;
4274 off = (stub_entry->target_value
4275 + stub_entry->target_section->output_offset
4276 + stub_entry->target_section->output_section->vma);
4277 off -= (stub_entry->stub_sec->_raw_size
4278 + stub_entry->stub_sec->output_offset
4279 + stub_entry->stub_sec->output_section->vma);
4281 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
4283 struct ppc_branch_hash_entry *br_entry;
4285 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4286 stub_entry->root.string + 9,
4288 if (br_entry == NULL)
4290 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
4291 stub_entry->root.string + 9);
4292 htab->stub_error = true;
4296 if (br_entry->iter != htab->stub_iteration)
4298 br_entry->iter = htab->stub_iteration;
4299 br_entry->offset = htab->sbrlt->_raw_size;
4300 htab->sbrlt->_raw_size += 8;
4302 stub_entry->stub_type = ppc_stub_plt_branch;
4307 stub_entry->stub_sec->_raw_size += size;
4311 /* Set up various things so that we can make a list of input sections
4312 for each output section included in the link. Returns -1 on error,
4313 0 when no stubs will be needed, and 1 on success. */
4316 ppc64_elf_setup_section_lists (output_bfd, info)
4318 struct bfd_link_info *info;
4321 unsigned int bfd_count;
4322 int top_id, top_index;
4324 asection **input_list, **list;
4326 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4328 if (htab->elf.root.creator->flavour != bfd_target_elf_flavour
4329 || htab->sbrlt == NULL)
4332 /* Count the number of input BFDs and find the top input section id. */
4333 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
4335 input_bfd = input_bfd->link_next)
4338 for (section = input_bfd->sections;
4340 section = section->next)
4342 if (top_id < section->id)
4343 top_id = section->id;
4346 htab->bfd_count = bfd_count;
4348 amt = sizeof (struct map_stub) * (top_id + 1);
4349 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4350 if (htab->stub_group == NULL)
4353 /* We can't use output_bfd->section_count here to find the top output
4354 section index as some sections may have been removed, and
4355 _bfd_strip_section_from_output doesn't renumber the indices. */
4356 for (section = output_bfd->sections, top_index = 0;
4358 section = section->next)
4360 if (top_index < section->index)
4361 top_index = section->index;
4364 htab->top_index = top_index;
4365 amt = sizeof (asection *) * (top_index + 1);
4366 input_list = (asection **) bfd_malloc (amt);
4367 htab->input_list = input_list;
4368 if (input_list == NULL)
4371 /* For sections we aren't interested in, mark their entries with a
4372 value we can check later. */
4373 list = input_list + top_index;
4375 *list = bfd_abs_section_ptr;
4376 while (list-- != input_list);
4378 for (section = output_bfd->sections;
4380 section = section->next)
4382 if ((section->flags & SEC_CODE) != 0)
4383 input_list[section->index] = NULL;
4389 /* The linker repeatedly calls this function for each input section,
4390 in the order that input sections are linked into output sections.
4391 Build lists of input sections to determine groupings between which
4392 we may insert linker stubs. */
4395 ppc64_elf_next_input_section (info, isec)
4396 struct bfd_link_info *info;
4399 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4401 if (isec->output_section->index <= htab->top_index)
4403 asection **list = htab->input_list + isec->output_section->index;
4404 if (*list != bfd_abs_section_ptr)
4406 /* Steal the link_sec pointer for our list. */
4407 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4408 /* This happens to make the list in reverse order,
4409 which is what we want. */
4410 PREV_SEC (isec) = *list;
4416 /* See whether we can group stub sections together. Grouping stub
4417 sections may result in fewer stubs. More importantly, we need to
4418 put all .init* and .fini* stubs at the beginning of the .init or
4419 .fini output sections respectively, because glibc splits the
4420 _init and _fini functions into multiple parts. Putting a stub in
4421 the middle of a function is not a good idea. */
4424 group_sections (htab, stub_group_size, stubs_always_before_branch)
4425 struct ppc_link_hash_table *htab;
4426 bfd_size_type stub_group_size;
4427 boolean stubs_always_before_branch;
4429 asection **list = htab->input_list + htab->top_index;
4432 asection *tail = *list;
4433 if (tail == bfd_abs_section_ptr)
4435 while (tail != NULL)
4439 bfd_size_type total;
4442 if (tail->_cooked_size)
4443 total = tail->_cooked_size;
4445 total = tail->_raw_size;
4446 while ((prev = PREV_SEC (curr)) != NULL
4447 && ((total += curr->output_offset - prev->output_offset)
4451 /* OK, the size from the start of CURR to the end is less
4452 than stub_group_size and thus can be handled by one stub
4453 section. (or the tail section is itself larger than
4454 stub_group_size, in which case we may be toast.) We
4455 should really be keeping track of the total size of stubs
4456 added here, as stubs contribute to the final output
4457 section size. That's a little tricky, and this way will
4458 only break if stubs added make the total size more than
4459 2^25, ie. for the default stub_group_size, if stubs total
4460 more than 2834432 bytes, or over 100000 plt call stubs. */
4463 prev = PREV_SEC (tail);
4464 /* Set up this stub group. */
4465 htab->stub_group[tail->id].link_sec = curr;
4467 while (tail != curr && (tail = prev) != NULL);
4469 /* But wait, there's more! Input sections up to stub_group_size
4470 bytes before the stub section can be handled by it too. */
4471 if (!stubs_always_before_branch)
4475 && ((total += tail->output_offset - prev->output_offset)
4479 prev = PREV_SEC (tail);
4480 htab->stub_group[tail->id].link_sec = curr;
4486 while (list-- != htab->input_list);
4487 free (htab->input_list);
4491 /* Read in all local syms for all input bfds. */
4494 get_local_syms (input_bfd, htab)
4496 struct ppc_link_hash_table *htab;
4498 unsigned int bfd_indx;
4499 Elf_Internal_Sym *local_syms, **all_local_syms;
4501 /* We want to read in symbol extension records only once. To do this
4502 we need to read in the local symbols in parallel and save them for
4503 later use; so hold pointers to the local symbols in an array. */
4504 bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count;
4505 all_local_syms = (Elf_Internal_Sym **) bfd_zmalloc (amt);
4506 htab->all_local_syms = all_local_syms;
4507 if (all_local_syms == NULL)
4510 /* Walk over all the input BFDs, swapping in local symbols.
4511 If we are creating a shared library, create hash entries for the
4515 input_bfd = input_bfd->link_next, bfd_indx++)
4517 Elf_Internal_Shdr *symtab_hdr;
4518 Elf_Internal_Shdr *shndx_hdr;
4519 Elf_Internal_Sym *isym;
4520 Elf64_External_Sym *ext_syms, *esym, *end_sy;
4521 Elf_External_Sym_Shndx *shndx_buf, *shndx;
4522 bfd_size_type sec_size;
4524 /* We'll need the symbol table in a second. */
4525 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4526 if (symtab_hdr->sh_info == 0)
4529 /* We need an array of the local symbols attached to the input bfd.
4530 Unfortunately, we're going to have to read & swap them in. */
4531 sec_size = symtab_hdr->sh_info;
4532 sec_size *= sizeof (Elf_Internal_Sym);
4533 local_syms = (Elf_Internal_Sym *) bfd_malloc (sec_size);
4534 if (local_syms == NULL)
4537 all_local_syms[bfd_indx] = local_syms;
4538 sec_size = symtab_hdr->sh_info;
4539 sec_size *= sizeof (Elf64_External_Sym);
4540 ext_syms = (Elf64_External_Sym *) bfd_malloc (sec_size);
4541 if (ext_syms == NULL)
4544 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
4545 || bfd_bread ((PTR) ext_syms, sec_size, input_bfd) != sec_size)
4547 error_ret_free_ext_syms:
4553 shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
4554 if (shndx_hdr->sh_size != 0)
4556 sec_size = symtab_hdr->sh_info;
4557 sec_size *= sizeof (Elf_External_Sym_Shndx);
4558 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (sec_size);
4559 if (shndx_buf == NULL)
4560 goto error_ret_free_ext_syms;
4562 if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
4563 || bfd_bread ((PTR) shndx_buf, sec_size, input_bfd) != sec_size)
4566 goto error_ret_free_ext_syms;
4570 /* Swap the local symbols in. */
4571 for (esym = ext_syms, end_sy = esym + symtab_hdr->sh_info,
4572 isym = local_syms, shndx = shndx_buf;
4574 esym++, isym++, shndx = (shndx ? shndx + 1 : NULL))
4575 bfd_elf64_swap_symbol_in (input_bfd, esym, shndx, isym);
4577 /* Now we can free the external symbols. */
4585 /* Determine and set the size of the stub section for a final link.
4587 The basic idea here is to examine all the relocations looking for
4588 PC-relative calls to a target that is unreachable with a "bl"
4592 ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size,
4593 add_stub_section, layout_sections_again)
4596 struct bfd_link_info *info;
4597 bfd_signed_vma group_size;
4598 asection * (*add_stub_section) PARAMS ((const char *, asection *));
4599 void (*layout_sections_again) PARAMS ((void));
4601 bfd_size_type stub_group_size;
4602 boolean stubs_always_before_branch;
4603 boolean ret = false;
4604 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4606 /* Stash our params away. */
4607 htab->stub_bfd = stub_bfd;
4608 htab->add_stub_section = add_stub_section;
4609 htab->layout_sections_again = layout_sections_again;
4610 stubs_always_before_branch = group_size < 0;
4612 stub_group_size = -group_size;
4614 stub_group_size = group_size;
4615 if (stub_group_size == 1)
4617 /* Default values. */
4618 stub_group_size = 30720000;
4619 if (htab->has_14bit_branch)
4620 stub_group_size = 30000;
4623 group_sections (htab, stub_group_size, stubs_always_before_branch);
4625 if (! get_local_syms (info->input_bfds, htab))
4627 if (htab->all_local_syms)
4628 goto error_ret_free_local;
4635 unsigned int bfd_indx;
4637 boolean stub_changed;
4639 htab->stub_iteration += 1;
4640 stub_changed = false;
4642 for (input_bfd = info->input_bfds, bfd_indx = 0;
4644 input_bfd = input_bfd->link_next, bfd_indx++)
4646 Elf_Internal_Shdr *symtab_hdr;
4648 Elf_Internal_Sym *local_syms;
4650 /* We'll need the symbol table in a second. */
4651 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4652 if (symtab_hdr->sh_info == 0)
4655 local_syms = htab->all_local_syms[bfd_indx];
4657 /* Walk over each section attached to the input bfd. */
4658 for (section = input_bfd->sections;
4660 section = section->next)
4662 Elf_Internal_Shdr *input_rel_hdr;
4663 Elf64_External_Rela *external_relocs, *erelaend, *erela;
4664 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4667 /* If there aren't any relocs, then there's nothing more
4669 if ((section->flags & SEC_RELOC) == 0
4670 || section->reloc_count == 0)
4673 /* If this section is a link-once section that will be
4674 discarded, then don't create any stubs. */
4675 if (section->output_section == NULL
4676 || section->output_section->owner != output_bfd)
4679 /* Allocate space for the external relocations. */
4680 amt = section->reloc_count;
4681 amt *= sizeof (Elf64_External_Rela);
4682 external_relocs = (Elf64_External_Rela *) bfd_malloc (amt);
4683 if (external_relocs == NULL)
4685 goto error_ret_free_local;
4688 /* Likewise for the internal relocations. */
4689 amt = section->reloc_count;
4690 amt *= sizeof (Elf_Internal_Rela);
4691 internal_relocs = (Elf_Internal_Rela *) bfd_malloc (amt);
4692 if (internal_relocs == NULL)
4694 free (external_relocs);
4695 goto error_ret_free_local;
4698 /* Read in the external relocs. */
4699 input_rel_hdr = &elf_section_data (section)->rel_hdr;
4700 if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0
4701 || bfd_bread ((PTR) external_relocs,
4702 input_rel_hdr->sh_size,
4703 input_bfd) != input_rel_hdr->sh_size)
4705 free (external_relocs);
4706 error_ret_free_internal:
4707 free (internal_relocs);
4708 goto error_ret_free_local;
4711 /* Swap in the relocs. */
4712 erela = external_relocs;
4713 erelaend = erela + section->reloc_count;
4714 irela = internal_relocs;
4715 for (; erela < erelaend; erela++, irela++)
4716 bfd_elf64_swap_reloca_in (input_bfd, erela, irela);
4718 /* We're done with the external relocs, free them. */
4719 free (external_relocs);
4721 /* Now examine each relocation. */
4722 irela = internal_relocs;
4723 irelaend = irela + section->reloc_count;
4724 for (; irela < irelaend; irela++)
4726 unsigned int r_type, r_indx;
4727 enum ppc_stub_type stub_type;
4728 struct ppc_stub_hash_entry *stub_entry;
4731 bfd_vma destination;
4732 struct ppc_link_hash_entry *hash;
4734 const asection *id_sec;
4736 r_type = ELF64_R_TYPE (irela->r_info);
4737 r_indx = ELF64_R_SYM (irela->r_info);
4739 if (r_type >= (unsigned int) R_PPC_max)
4741 bfd_set_error (bfd_error_bad_value);
4742 goto error_ret_free_internal;
4745 /* Only look for stubs on branch instructions. */
4746 if (r_type != (unsigned int) R_PPC64_REL24
4747 && r_type != (unsigned int) R_PPC64_REL14
4748 && r_type != (unsigned int) R_PPC64_REL14_BRTAKEN
4749 && r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN)
4752 /* Now determine the call target, its name, value,
4758 if (r_indx < symtab_hdr->sh_info)
4760 /* It's a local symbol. */
4761 Elf_Internal_Sym *sym;
4762 Elf_Internal_Shdr *hdr;
4764 sym = local_syms + r_indx;
4765 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4766 sym_sec = hdr->bfd_section;
4767 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4768 sym_value = sym->st_value;
4769 destination = (sym_value + irela->r_addend
4770 + sym_sec->output_offset
4771 + sym_sec->output_section->vma);
4775 /* It's an external symbol. */
4778 e_indx = r_indx - symtab_hdr->sh_info;
4779 hash = ((struct ppc_link_hash_entry *)
4780 elf_sym_hashes (input_bfd)[e_indx]);
4782 while (hash->elf.root.type == bfd_link_hash_indirect
4783 || hash->elf.root.type == bfd_link_hash_warning)
4784 hash = ((struct ppc_link_hash_entry *)
4785 hash->elf.root.u.i.link);
4787 if (hash->elf.root.type == bfd_link_hash_defined
4788 || hash->elf.root.type == bfd_link_hash_defweak)
4790 sym_sec = hash->elf.root.u.def.section;
4791 sym_value = hash->elf.root.u.def.value;
4792 if (sym_sec->output_section != NULL)
4793 destination = (sym_value + irela->r_addend
4794 + sym_sec->output_offset
4795 + sym_sec->output_section->vma);
4797 else if (hash->elf.root.type == bfd_link_hash_undefweak)
4799 else if (hash->elf.root.type == bfd_link_hash_undefined)
4803 bfd_set_error (bfd_error_bad_value);
4804 goto error_ret_free_internal;
4808 /* Determine what (if any) linker stub is needed. */
4809 stub_type = ppc_type_of_stub (section, irela, &hash,
4811 if (stub_type == ppc_stub_none)
4814 /* Support for grouping stub sections. */
4815 id_sec = htab->stub_group[section->id].link_sec;
4817 /* Get the name of this stub. */
4818 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
4820 goto error_ret_free_internal;
4822 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4823 stub_name, false, false);
4824 if (stub_entry != NULL)
4826 /* The proper stub has already been created. */
4831 stub_entry = ppc_add_stub (stub_name, section, htab);
4832 if (stub_entry == NULL)
4835 goto error_ret_free_local;
4838 stub_entry->target_value = sym_value;
4839 stub_entry->target_section = sym_sec;
4840 stub_entry->stub_type = stub_type;
4841 stub_entry->h = hash;
4842 stub_changed = true;
4845 /* We're done with the internal relocs, free them. */
4846 free (internal_relocs);
4853 /* OK, we've added some stubs. Find out the new size of the
4855 for (stub_sec = htab->stub_bfd->sections;
4857 stub_sec = stub_sec->next)
4859 stub_sec->_raw_size = 0;
4860 stub_sec->_cooked_size = 0;
4862 htab->sbrlt->_raw_size = 0;
4863 htab->sbrlt->_cooked_size = 0;
4865 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab);
4867 /* Ask the linker to do its stuff. */
4868 (*htab->layout_sections_again) ();
4871 /* It would be nice to strip .branch_lt from the output if the
4872 section is empty, but it's too late. If we strip sections here,
4873 the dynamic symbol table is corrupted since the section symbol
4874 for the stripped section isn't written. */
4878 error_ret_free_local:
4879 while (htab->bfd_count-- > 0)
4880 if (htab->all_local_syms[htab->bfd_count])
4881 free (htab->all_local_syms[htab->bfd_count]);
4882 free (htab->all_local_syms);
4887 /* Called after we have determined section placement. If sections
4888 move, we'll be called again. Provide a value for TOCstart. */
4891 ppc64_elf_toc (obfd)
4897 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
4898 order. The TOC starts where the first of these sections starts. */
4899 s = bfd_get_section_by_name (obfd, ".got");
4901 s = bfd_get_section_by_name (obfd, ".toc");
4903 s = bfd_get_section_by_name (obfd, ".tocbss");
4905 s = bfd_get_section_by_name (obfd, ".plt");
4908 /* This may happen for
4909 o references to TOC base (SYM@toc / TOC[tc0]) without a
4912 o --gc-sections and empty TOC sections
4914 FIXME: Warn user? */
4916 /* Look for a likely section. We probably won't even be
4918 for (s = obfd->sections; s != NULL; s = s->next)
4919 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
4920 == (SEC_ALLOC | SEC_SMALL_DATA))
4923 for (s = obfd->sections; s != NULL; s = s->next)
4924 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
4925 == (SEC_ALLOC | SEC_SMALL_DATA))
4928 for (s = obfd->sections; s != NULL; s = s->next)
4929 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
4932 for (s = obfd->sections; s != NULL; s = s->next)
4933 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
4939 TOCstart = s->output_section->vma + s->output_offset;
4944 /* Build all the stubs associated with the current output file.
4945 The stubs are kept in a hash table attached to the main linker
4946 hash table. This function is called via gldelf64ppc_finish. */
4949 ppc64_elf_build_stubs (info)
4950 struct bfd_link_info *info;
4952 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4957 for (stub_sec = htab->stub_bfd->sections;
4959 stub_sec = stub_sec->next)
4963 /* Allocate memory to hold the linker stubs. */
4964 size = stub_sec->_raw_size;
4967 stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size);
4968 if (stub_sec->contents == NULL)
4971 stub_sec->_cooked_size = 0;
4974 if (htab->splt != NULL)
4976 /* Build the .glink plt call stub. */
4977 plt_r2 = (htab->splt->output_offset
4978 + htab->splt->output_section->vma
4979 - elf_gp (htab->splt->output_section->owner)
4981 p = htab->sglink->contents;
4982 p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
4983 while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE)
4985 bfd_put_32 (htab->sglink->owner, NOP, p);
4988 htab->sglink->_cooked_size = p - htab->sglink->contents;
4990 /* Use reloc_count to count entries. */
4991 htab->sglink->reloc_count = 0;
4994 if (htab->sbrlt->_raw_size != 0)
4996 htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner,
4997 htab->sbrlt->_raw_size);
4998 if (htab->sbrlt->contents == NULL)
5002 /* Build the stubs as directed by the stub hash table. */
5003 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
5004 htab->sglink->reloc_count = 0;
5006 for (stub_sec = htab->stub_bfd->sections;
5008 stub_sec = stub_sec->next)
5010 if (stub_sec->_raw_size != stub_sec->_cooked_size)
5014 if (stub_sec != NULL
5015 || htab->sglink->_raw_size != htab->sglink->_cooked_size)
5017 htab->stub_error = true;
5018 (*_bfd_error_handler) (_("stubs don't match calculated size"));
5021 return !htab->stub_error;
5024 /* Set up any other section flags and such that may be necessary. */
5027 ppc64_elf_fake_sections (abfd, shdr, asect)
5028 bfd *abfd ATTRIBUTE_UNUSED;
5029 Elf64_Internal_Shdr *shdr;
5032 if ((asect->flags & SEC_EXCLUDE) != 0)
5033 shdr->sh_flags |= SHF_EXCLUDE;
5035 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
5036 shdr->sh_type = SHT_ORDERED;
5041 /* The RELOCATE_SECTION function is called by the ELF backend linker
5042 to handle the relocations for a section.
5044 The relocs are always passed as Rela structures; if the section
5045 actually uses Rel structures, the r_addend field will always be
5048 This function is responsible for adjust the section contents as
5049 necessary, and (if using Rela relocs and generating a
5050 relocateable output file) adjusting the reloc addend as
5053 This function does not have to worry about setting the reloc
5054 address or the reloc symbol index.
5056 LOCAL_SYMS is a pointer to the swapped in local symbols.
5058 LOCAL_SECTIONS is an array giving the section in the input file
5059 corresponding to the st_shndx field of each local symbol.
5061 The global hash table entry for the global symbols can be found
5062 via elf_sym_hashes (input_bfd).
5064 When generating relocateable output, this function must handle
5065 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5066 going to be the section symbol corresponding to the output
5067 section, which means that the addend must be adjusted
5071 ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
5072 contents, relocs, local_syms, local_sections)
5074 struct bfd_link_info *info;
5076 asection *input_section;
5078 Elf_Internal_Rela *relocs;
5079 Elf_Internal_Sym *local_syms;
5080 asection **local_sections;
5082 struct ppc_link_hash_table *htab;
5083 Elf_Internal_Shdr *symtab_hdr;
5084 struct elf_link_hash_entry **sym_hashes;
5085 Elf_Internal_Rela *rel;
5086 Elf_Internal_Rela *relend;
5087 bfd_vma *local_got_offsets;
5091 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5092 boolean is_power4 = false;
5094 if (info->relocateable)
5097 /* Initialize howto table if needed. */
5098 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5101 htab = ppc_hash_table (info);
5102 local_got_offsets = elf_local_got_offsets (input_bfd);
5103 TOCstart = elf_gp (output_bfd);
5104 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5105 sym_hashes = elf_sym_hashes (input_bfd);
5106 is_opd = strcmp (bfd_get_section_name (abfd, input_section), ".opd") == 0;
5109 relend = relocs + input_section->reloc_count;
5110 for (; rel < relend; rel++)
5112 enum elf_ppc_reloc_type r_type;
5115 bfd_reloc_status_type r;
5116 Elf_Internal_Sym *sym;
5118 struct elf_link_hash_entry *h;
5119 struct elf_link_hash_entry *fdh;
5120 const char *sym_name;
5121 unsigned long r_symndx;
5123 boolean unresolved_reloc;
5126 struct ppc_stub_hash_entry *stub_entry;
5127 bfd_vma max_br_offset;
5130 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
5131 r_symndx = ELF64_R_SYM (rel->r_info);
5132 offset = rel->r_offset;
5133 addend = rel->r_addend;
5134 r = bfd_reloc_other;
5135 sym = (Elf_Internal_Sym *) 0;
5136 sec = (asection *) 0;
5137 h = (struct elf_link_hash_entry *) 0;
5138 sym_name = (const char *) 0;
5139 unresolved_reloc = false;
5142 if (r_type == R_PPC64_TOC)
5144 /* Relocation value is TOC base. Symbol is ignored. */
5145 relocation = TOCstart + TOC_BASE_OFF;
5147 else if (r_symndx < symtab_hdr->sh_info)
5149 /* It's a local symbol. */
5150 sym = local_syms + r_symndx;
5151 sec = local_sections[r_symndx];
5152 sym_name = "<local symbol>";
5154 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
5155 /* rel may have changed, update our copy of addend. */
5156 addend = rel->r_addend;
5160 /* It's a global symbol. */
5161 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5162 while (h->root.type == bfd_link_hash_indirect
5163 || h->root.type == bfd_link_hash_warning)
5164 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5165 sym_name = h->root.root.string;
5167 if (h->root.type == bfd_link_hash_defined
5168 || h->root.type == bfd_link_hash_defweak)
5170 sec = h->root.u.def.section;
5171 if (sec->output_section == NULL)
5172 /* Set a flag that will be cleared later if we find a
5173 relocation value for this symbol. output_section
5174 is typically NULL for symbols satisfied by a shared
5176 unresolved_reloc = true;
5178 relocation = (h->root.u.def.value
5179 + sec->output_section->vma
5180 + sec->output_offset);
5182 else if (h->root.type == bfd_link_hash_undefweak)
5184 else if (info->shared
5185 && (!info->symbolic || info->allow_shlib_undefined)
5186 && !info->no_undefined
5187 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
5191 if (! ((*info->callbacks->undefined_symbol)
5192 (info, h->root.root.string, input_bfd, input_section,
5193 offset, (!info->shared
5194 || info->no_undefined
5195 || ELF_ST_VISIBILITY (h->other)))))
5201 /* First handle relocations that tweak non-addend part of insn. */
5208 /* Branch taken prediction relocations. */
5209 case R_PPC64_ADDR14_BRTAKEN:
5210 case R_PPC64_REL14_BRTAKEN:
5211 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5214 /* Branch not taken prediction relocations. */
5215 case R_PPC64_ADDR14_BRNTAKEN:
5216 case R_PPC64_REL14_BRNTAKEN:
5217 insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
5220 /* Set 'a' bit. This is 0b00010 in BO field for branch
5221 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5222 for branch on CTR insns (BO == 1a00t or 1a01t). */
5223 if ((insn & (0x14 << 21)) == (0x04 << 21))
5225 else if ((insn & (0x14 << 21)) == (0x10 << 21))
5233 + input_section->output_offset
5234 + input_section->output_section->vma);
5236 /* Invert 'y' bit if not the default. */
5237 if ((bfd_signed_vma) (relocation + addend - from) < 0)
5241 bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
5245 /* A REL24 branching to a linkage function is followed by a
5246 nop. We replace the nop with a ld in order to restore
5247 the TOC base pointer. Only calls to shared objects need
5248 to alter the TOC base. These are recognized by their
5249 need for a PLT entry. */
5251 && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL
5252 && fdh->plt.offset != (bfd_vma) -1
5253 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
5254 rel, htab)) != NULL)
5256 boolean can_plt_call = 0;
5258 if (offset + 8 <= input_section->_cooked_size)
5260 insn = bfd_get_32 (input_bfd, contents + offset + 4);
5262 || insn == CROR_151515 || insn == CROR_313131)
5264 bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1,
5265 contents + offset + 4);
5272 /* If this is a plain branch rather than a branch
5273 and link, don't require a nop. */
5274 insn = bfd_get_32 (input_bfd, contents + offset);
5275 if ((insn & 1) == 0)
5281 relocation = (stub_entry->stub_offset
5282 + stub_entry->stub_sec->output_offset
5283 + stub_entry->stub_sec->output_section->vma);
5285 unresolved_reloc = false;
5290 && h->root.type == bfd_link_hash_undefweak
5294 /* Tweak calls to undefined weak functions to point at a
5295 blr. We can thus call a weak function without first
5296 checking whether the function is defined. We have a
5297 blr at the end of .sfpr. */
5298 BFD_ASSERT (htab->sfpr->_raw_size != 0);
5299 relocation = (htab->sfpr->_raw_size - 4
5300 + htab->sfpr->output_offset
5301 + htab->sfpr->output_section->vma);
5303 + input_section->output_offset
5304 + input_section->output_section->vma);
5306 /* But let's not be silly about it. If the blr isn't in
5307 reach, just go to the next instruction. */
5308 if (relocation - from + (1 << 25) >= (1 << 26)
5309 || htab->sfpr->_raw_size == 0)
5310 relocation = from + 4;
5319 (*_bfd_error_handler)
5320 (_("%s: unknown relocation type %d for symbol %s"),
5321 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
5323 bfd_set_error (bfd_error_bad_value);
5328 case R_PPC_GNU_VTINHERIT:
5329 case R_PPC_GNU_VTENTRY:
5332 /* GOT16 relocations. Like an ADDR16 using the symbol's
5333 address in the GOT as relocation value instead of the
5334 symbols value itself. Also, create a GOT entry for the
5335 symbol and put the symbol value there. */
5337 case R_PPC64_GOT16_LO:
5338 case R_PPC64_GOT16_HI:
5339 case R_PPC64_GOT16_HA:
5340 case R_PPC64_GOT16_DS:
5341 case R_PPC64_GOT16_LO_DS:
5343 /* Relocation is to the entry for this symbol in the global
5347 if (htab->sgot == NULL)
5354 off = h->got.offset;
5355 dyn = htab->elf.dynamic_sections_created;
5356 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
5360 || (h->elf_link_hash_flags
5361 & ELF_LINK_FORCED_LOCAL))
5362 && (h->elf_link_hash_flags
5363 & ELF_LINK_HASH_DEF_REGULAR)))
5365 /* This is actually a static link, or it is a
5366 -Bsymbolic link and the symbol is defined
5367 locally, or the symbol was forced to be local
5368 because of a version file. We must initialize
5369 this entry in the global offset table. Since the
5370 offset must always be a multiple of 8, we use the
5371 least significant bit to record whether we have
5372 initialized it already.
5374 When doing a dynamic link, we create a .rel.got
5375 relocation entry to initialize the value. This
5376 is done in the finish_dynamic_symbol routine. */
5381 bfd_put_64 (output_bfd, relocation,
5382 htab->sgot->contents + off);
5387 unresolved_reloc = false;
5391 if (local_got_offsets == NULL)
5394 off = local_got_offsets[r_symndx];
5396 /* The offset must always be a multiple of 8. We use
5397 the least significant bit to record whether we have
5398 already processed this entry. */
5403 bfd_put_64 (output_bfd, relocation,
5404 htab->sgot->contents + off);
5408 Elf_Internal_Rela outrel;
5409 Elf64_External_Rela *loc;
5411 /* We need to generate a R_PPC64_RELATIVE reloc
5412 for the dynamic linker. */
5413 outrel.r_offset = (htab->sgot->output_section->vma
5414 + htab->sgot->output_offset
5416 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5417 outrel.r_addend = relocation;
5418 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5419 loc += htab->srelgot->reloc_count++;
5420 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5423 local_got_offsets[r_symndx] |= 1;
5427 if (off >= (bfd_vma) -2)
5430 relocation = htab->sgot->output_offset + off;
5432 /* TOC base (r2) is TOC start plus 0x8000. */
5433 addend -= TOC_BASE_OFF;
5437 case R_PPC64_PLT16_HA:
5438 case R_PPC64_PLT16_HI:
5439 case R_PPC64_PLT16_LO:
5442 /* Relocation is to the entry for this symbol in the
5443 procedure linkage table. */
5445 /* Resolve a PLT reloc against a local symbol directly,
5446 without using the procedure linkage table. */
5450 if (h->plt.offset == (bfd_vma) -1
5451 || htab->splt == NULL)
5453 /* We didn't make a PLT entry for this symbol. This
5454 happens when statically linking PIC code, or when
5455 using -Bsymbolic. */
5459 relocation = (htab->splt->output_section->vma
5460 + htab->splt->output_offset
5462 unresolved_reloc = false;
5465 /* TOC16 relocs. We want the offset relative to the TOC base,
5466 which is the address of the start of the TOC plus 0x8000.
5467 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5470 case R_PPC64_TOC16_LO:
5471 case R_PPC64_TOC16_HI:
5472 case R_PPC64_TOC16_DS:
5473 case R_PPC64_TOC16_LO_DS:
5474 case R_PPC64_TOC16_HA:
5475 addend -= TOCstart + TOC_BASE_OFF;
5478 /* Relocate against the beginning of the section. */
5479 case R_PPC64_SECTOFF:
5480 case R_PPC64_SECTOFF_LO:
5481 case R_PPC64_SECTOFF_HI:
5482 case R_PPC64_SECTOFF_DS:
5483 case R_PPC64_SECTOFF_LO_DS:
5484 case R_PPC64_SECTOFF_HA:
5485 if (sec != (asection *) 0)
5486 addend -= sec->output_section->vma;
5490 case R_PPC64_REL14_BRNTAKEN:
5491 case R_PPC64_REL14_BRTAKEN:
5495 /* Relocations that may need to be propagated if this is a
5499 case R_PPC64_ADDR14:
5500 case R_PPC64_ADDR14_BRNTAKEN:
5501 case R_PPC64_ADDR14_BRTAKEN:
5502 case R_PPC64_ADDR16:
5503 case R_PPC64_ADDR16_DS:
5504 case R_PPC64_ADDR16_HA:
5505 case R_PPC64_ADDR16_HI:
5506 case R_PPC64_ADDR16_HIGHER:
5507 case R_PPC64_ADDR16_HIGHERA:
5508 case R_PPC64_ADDR16_HIGHEST:
5509 case R_PPC64_ADDR16_HIGHESTA:
5510 case R_PPC64_ADDR16_LO:
5511 case R_PPC64_ADDR16_LO_DS:
5512 case R_PPC64_ADDR24:
5513 case R_PPC64_ADDR30:
5514 case R_PPC64_ADDR32:
5515 case R_PPC64_ADDR64:
5516 case R_PPC64_UADDR16:
5517 case R_PPC64_UADDR32:
5518 case R_PPC64_UADDR64:
5519 /* r_symndx will be zero only for relocs against symbols
5520 from removed linkonce sections, or sections discarded by
5527 if ((input_section->flags & SEC_ALLOC) == 0)
5530 if (NO_OPD_RELOCS && is_opd)
5534 && (IS_ABSOLUTE_RELOC (r_type)
5537 && (! info->symbolic
5538 || (h->elf_link_hash_flags
5539 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
5543 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5544 && (((h->elf_link_hash_flags
5545 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5546 && (h->elf_link_hash_flags
5547 & ELF_LINK_HASH_DEF_REGULAR) == 0)
5548 || h->root.type == bfd_link_hash_undefweak
5549 || h->root.type == bfd_link_hash_undefined)))
5551 Elf_Internal_Rela outrel;
5552 boolean skip, relocate;
5554 Elf64_External_Rela *loc;
5556 /* When generating a dynamic object, these relocations
5557 are copied into the output file to be resolved at run
5564 _bfd_elf_section_offset (output_bfd, info, input_section,
5566 if (outrel.r_offset == (bfd_vma) -1)
5568 else if (outrel.r_offset == (bfd_vma) -2)
5569 skip = true, relocate = true;
5570 outrel.r_offset += (input_section->output_section->vma
5571 + input_section->output_offset);
5572 outrel.r_addend = addend;
5575 memset (&outrel, 0, sizeof outrel);
5579 && (!IS_ABSOLUTE_RELOC (r_type)
5582 || (h->elf_link_hash_flags
5583 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5584 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
5587 /* This symbol is local, or marked to become local,
5588 or this is an opd section reloc which must point
5589 at a local function. */
5590 outrel.r_addend += relocation;
5592 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
5594 if (is_opd && h != NULL && info->shared)
5596 /* Lie about opd entries. This case occurs
5597 when building shared libraries and we
5598 reference a function in another shared
5599 lib. In that case we won't use the opd
5600 entry in this lib; We ought to edit the
5601 opd section to remove unused entries. */
5602 unresolved_reloc = false;
5604 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5610 if (bfd_is_abs_section (sec))
5612 else if (sec == NULL || sec->owner == NULL)
5614 bfd_set_error (bfd_error_bad_value);
5621 osec = sec->output_section;
5622 indx = elf_section_data (osec)->dynindx;
5624 /* We are turning this relocation into one
5625 against a section symbol, so subtract out
5626 the output section's address but not the
5627 offset of the input section in the output
5629 outrel.r_addend -= osec->vma;
5632 outrel.r_info = ELF64_R_INFO (indx, r_type);
5636 sreloc = elf_section_data (input_section)->sreloc;
5640 loc = (Elf64_External_Rela *) sreloc->contents;
5641 loc += sreloc->reloc_count++;
5642 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5644 /* If this reloc is against an external symbol, it will
5645 be computed at runtime, so there's no need to do
5653 case R_PPC64_GLOB_DAT:
5654 case R_PPC64_JMP_SLOT:
5655 case R_PPC64_RELATIVE:
5656 /* We shouldn't ever see these dynamic relocs in relocatable
5660 case R_PPC64_PLTGOT16:
5661 case R_PPC64_PLTGOT16_DS:
5662 case R_PPC64_PLTGOT16_HA:
5663 case R_PPC64_PLTGOT16_HI:
5664 case R_PPC64_PLTGOT16_LO:
5665 case R_PPC64_PLTGOT16_LO_DS:
5666 case R_PPC64_PLTREL32:
5667 case R_PPC64_PLTREL64:
5668 /* These ones haven't been implemented yet. */
5670 (*_bfd_error_handler)
5671 (_("%s: Relocation %s is not supported for symbol %s."),
5672 bfd_archive_filename (input_bfd),
5673 ppc64_elf_howto_table[(int) r_type]->name, sym_name);
5675 bfd_set_error (bfd_error_invalid_operation);
5680 /* Do any further special processing. */
5686 case R_PPC64_ADDR16_HA:
5687 case R_PPC64_ADDR16_HIGHERA:
5688 case R_PPC64_ADDR16_HIGHESTA:
5689 case R_PPC64_PLT16_HA:
5690 case R_PPC64_TOC16_HA:
5691 case R_PPC64_SECTOFF_HA:
5692 /* It's just possible that this symbol is a weak symbol
5693 that's not actually defined anywhere. In that case,
5694 'sec' would be NULL, and we should leave the symbol
5695 alone (it will be set to zero elsewhere in the link). */
5697 /* Add 0x10000 if sign bit in 0:15 is set. */
5698 addend += ((relocation + addend) & 0x8000) << 1;
5701 case R_PPC64_ADDR16_DS:
5702 case R_PPC64_ADDR16_LO_DS:
5703 case R_PPC64_GOT16_DS:
5704 case R_PPC64_GOT16_LO_DS:
5705 case R_PPC64_PLT16_LO_DS:
5706 case R_PPC64_SECTOFF_DS:
5707 case R_PPC64_SECTOFF_LO_DS:
5708 case R_PPC64_TOC16_DS:
5709 case R_PPC64_TOC16_LO_DS:
5710 case R_PPC64_PLTGOT16_DS:
5711 case R_PPC64_PLTGOT16_LO_DS:
5712 if (((relocation + addend) & 3) != 0)
5714 (*_bfd_error_handler)
5715 (_("%s: error: relocation %s not a multiple of 4"),
5716 bfd_archive_filename (input_bfd),
5717 ppc64_elf_howto_table[(int) r_type]->name);
5718 bfd_set_error (bfd_error_bad_value);
5725 case R_PPC64_REL14_BRNTAKEN:
5726 case R_PPC64_REL14_BRTAKEN:
5727 max_br_offset = 1 << 15;
5731 max_br_offset = 1 << 25;
5734 /* If the branch is out of reach, then redirect the
5735 call to the local stub for this function. */
5737 + input_section->output_offset
5738 + input_section->output_section->vma);
5739 if (relocation + addend - from + max_br_offset >= 2 * max_br_offset
5740 && (stub_entry = ppc_get_stub_entry (input_section, sec, h,
5741 rel, htab)) != NULL)
5743 /* Munge up the value and addend so that we call the stub
5744 rather than the procedure directly. */
5745 relocation = (stub_entry->stub_offset
5746 + stub_entry->stub_sec->output_offset
5747 + stub_entry->stub_sec->output_section->vma);
5753 /* FIXME: Why do we allow debugging sections to escape this error?
5754 More importantly, why do we not emit dynamic relocs above in
5755 debugging sections (which are ! SEC_ALLOC)? If we had
5756 emitted the dynamic reloc, we could remove the fudge here. */
5757 if (unresolved_reloc
5759 && (input_section->flags & SEC_DEBUGGING) != 0
5760 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5762 (*_bfd_error_handler)
5763 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5764 bfd_archive_filename (input_bfd),
5765 bfd_get_section_name (input_bfd, input_section),
5766 (long) rel->r_offset,
5767 h->root.root.string);
5771 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
5779 if (r != bfd_reloc_ok)
5785 if (h->root.type == bfd_link_hash_undefweak
5786 && ppc64_elf_howto_table[(int) r_type]->pc_relative)
5788 /* Assume this is a call protected by other code that
5789 detects the symbol is undefined. If this is the case,
5790 we can safely ignore the overflow. If not, the
5791 program is hosed anyway, and a little warning isn't
5797 name = h->root.root.string;
5801 name = bfd_elf_string_from_elf_section (input_bfd,
5802 symtab_hdr->sh_link,
5807 name = bfd_section_name (input_bfd, sec);
5810 if (r == bfd_reloc_overflow)
5814 if (!((*info->callbacks->reloc_overflow)
5815 (info, name, ppc64_elf_howto_table[(int) r_type]->name,
5816 rel->r_addend, input_bfd, input_section, offset)))
5821 (*_bfd_error_handler)
5822 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
5823 bfd_archive_filename (input_bfd),
5824 bfd_get_section_name (input_bfd, input_section),
5825 (long) rel->r_offset, name, (int) r);
5834 /* Finish up dynamic symbol handling. We set the contents of various
5835 dynamic sections here. */
5838 ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5840 struct bfd_link_info *info;
5841 struct elf_link_hash_entry *h;
5842 Elf_Internal_Sym *sym;
5844 struct ppc_link_hash_table *htab;
5847 htab = ppc_hash_table (info);
5848 dynobj = htab->elf.dynobj;
5850 if (h->plt.offset != (bfd_vma) -1
5851 && ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
5853 Elf_Internal_Rela rela;
5854 Elf64_External_Rela *loc;
5856 /* This symbol has an entry in the procedure linkage table. Set
5859 if (htab->splt == NULL
5860 || htab->srelplt == NULL
5861 || htab->sglink == NULL)
5864 /* Create a JMP_SLOT reloc to inform the dynamic linker to
5865 fill in the PLT entry. */
5867 rela.r_offset = (htab->splt->output_section->vma
5868 + htab->splt->output_offset
5870 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
5873 loc = (Elf64_External_Rela *) htab->srelplt->contents;
5874 loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
5875 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5878 if (h->got.offset != (bfd_vma) -1)
5880 Elf_Internal_Rela rela;
5881 Elf64_External_Rela *loc;
5883 /* This symbol has an entry in the global offset table. Set it
5886 if (htab->sgot == NULL || htab->srelgot == NULL)
5889 rela.r_offset = (htab->sgot->output_section->vma
5890 + htab->sgot->output_offset
5891 + (h->got.offset &~ (bfd_vma) 1));
5893 /* If this is a static link, or it is a -Bsymbolic link and the
5894 symbol is defined locally or was forced to be local because
5895 of a version file, we just want to emit a RELATIVE reloc.
5896 The entry in the global offset table will already have been
5897 initialized in the relocate_section function. */
5901 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
5902 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
5904 BFD_ASSERT((h->got.offset & 1) != 0);
5905 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5906 rela.r_addend = (h->root.u.def.value
5907 + h->root.u.def.section->output_section->vma
5908 + h->root.u.def.section->output_offset);
5912 BFD_ASSERT ((h->got.offset & 1) == 0);
5913 bfd_put_64 (output_bfd, (bfd_vma) 0,
5914 htab->sgot->contents + h->got.offset);
5915 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
5919 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5920 loc += htab->srelgot->reloc_count++;
5921 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5924 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
5926 Elf_Internal_Rela rela;
5927 Elf64_External_Rela *loc;
5929 /* This symbol needs a copy reloc. Set it up. */
5931 if (h->dynindx == -1
5932 || (h->root.type != bfd_link_hash_defined
5933 && h->root.type != bfd_link_hash_defweak)
5934 || htab->srelbss == NULL)
5937 rela.r_offset = (h->root.u.def.value
5938 + h->root.u.def.section->output_section->vma
5939 + h->root.u.def.section->output_offset);
5940 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
5942 loc = (Elf64_External_Rela *) htab->srelbss->contents;
5943 loc += htab->srelbss->reloc_count++;
5944 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5947 /* Mark some specially defined symbols as absolute. */
5948 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
5949 sym->st_shndx = SHN_ABS;
5954 /* Used to decide how to sort relocs in an optimal manner for the
5955 dynamic linker, before writing them out. */
5957 static enum elf_reloc_type_class
5958 ppc64_elf_reloc_type_class (rela)
5959 const Elf_Internal_Rela *rela;
5961 enum elf_ppc_reloc_type r_type;
5963 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
5966 case R_PPC64_RELATIVE:
5967 return reloc_class_relative;
5968 case R_PPC64_JMP_SLOT:
5969 return reloc_class_plt;
5971 return reloc_class_copy;
5973 return reloc_class_normal;
5977 /* Finish up the dynamic sections. */
5980 ppc64_elf_finish_dynamic_sections (output_bfd, info)
5982 struct bfd_link_info *info;
5984 struct ppc_link_hash_table *htab;
5988 htab = ppc_hash_table (info);
5989 dynobj = htab->elf.dynobj;
5990 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5992 if (htab->elf.dynamic_sections_created)
5994 Elf64_External_Dyn *dyncon, *dynconend;
5996 if (sdyn == NULL || htab->sgot == NULL)
5999 dyncon = (Elf64_External_Dyn *) sdyn->contents;
6000 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
6001 for (; dyncon < dynconend; dyncon++)
6003 Elf_Internal_Dyn dyn;
6006 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
6013 case DT_PPC64_GLINK:
6014 dyn.d_un.d_ptr = (htab->sglink->output_section->vma
6015 + htab->sglink->output_offset);
6019 s = bfd_get_section_by_name (output_bfd, ".opd");
6021 dyn.d_un.d_ptr = s->vma;
6024 case DT_PPC64_OPDSZ:
6025 s = bfd_get_section_by_name (output_bfd, ".opd");
6027 dyn.d_un.d_val = s->_raw_size;
6031 dyn.d_un.d_ptr = (htab->splt->output_section->vma
6032 + htab->splt->output_offset);
6036 dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
6037 + htab->srelplt->output_offset);
6041 dyn.d_un.d_val = htab->srelplt->_raw_size;
6045 /* Don't count procedure linkage table relocs in the
6046 overall reloc count. */
6047 if (htab->srelplt != NULL)
6048 dyn.d_un.d_val -= htab->srelplt->_raw_size;
6052 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
6056 if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
6058 /* Fill in the first entry in the global offset table.
6059 We use it to hold the link-time TOCbase. */
6060 bfd_put_64 (output_bfd,
6061 elf_gp (output_bfd) + TOC_BASE_OFF,
6062 htab->sgot->contents);
6064 /* Set .got entry size. */
6065 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
6068 if (htab->splt != NULL && htab->splt->_raw_size != 0)
6070 /* Set .plt entry size. */
6071 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
6078 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6079 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6080 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6081 #define TARGET_BIG_NAME "elf64-powerpc"
6082 #define ELF_ARCH bfd_arch_powerpc
6083 #define ELF_MACHINE_CODE EM_PPC64
6084 #define ELF_MAXPAGESIZE 0x10000
6085 #define elf_info_to_howto ppc64_elf_info_to_howto
6087 #ifdef EM_CYGNUS_POWERPC
6088 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6092 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6095 #define elf_backend_want_got_sym 0
6096 #define elf_backend_want_plt_sym 0
6097 #define elf_backend_plt_alignment 3
6098 #define elf_backend_plt_not_loaded 1
6099 #define elf_backend_got_symbol_offset 0
6100 #define elf_backend_got_header_size 8
6101 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6102 #define elf_backend_can_gc_sections 1
6103 #define elf_backend_can_refcount 1
6104 #define elf_backend_rela_normal 1
6106 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6107 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
6108 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6109 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6110 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6112 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
6113 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6114 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6115 #define elf_backend_check_relocs ppc64_elf_check_relocs
6116 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6117 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6118 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6119 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6120 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6121 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6122 #define elf_backend_fake_sections ppc64_elf_fake_sections
6123 #define elf_backend_relocate_section ppc64_elf_relocate_section
6124 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6125 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6126 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6128 #include "elf64-target.h"