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 static void ppc_howto_init
35 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
36 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
37 static void ppc64_elf_info_to_howto
38 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf64_Internal_Rela
*dst
));
39 static bfd_reloc_status_type ppc64_elf_ha_reloc
40 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
41 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
42 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
43 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
44 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
45 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
46 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
47 static bfd_reloc_status_type ppc64_elf_toc_reloc
48 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
49 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
50 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
51 static bfd_reloc_status_type ppc64_elf_toc64_reloc
52 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
53 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
54 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
55 static boolean ppc64_elf_object_p
57 static boolean ppc64_elf_merge_private_bfd_data
58 PARAMS ((bfd
*, bfd
*));
61 /* The name of the dynamic interpreter. This is put in the .interp
63 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
65 /* The size in bytes of an entry in the procedure linkage table. */
66 #define PLT_ENTRY_SIZE 24
68 /* The initial size of the plt reserved for the dynamic linker. */
69 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
71 /* TOC base pointers offset from start of TOC. */
72 #define TOC_BASE_OFF (0x8000)
74 /* .plt call stub instructions. */
75 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
76 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
77 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
78 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
79 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
80 /* ld %r11,xxx+16@l(%r12) */
81 #define BCTR 0x4e800420 /* bctr */
83 /* The normal stub is this size. */
84 #define PLT_CALL_STUB_SIZE (7*4)
86 /* But sometimes the .plt entry crosses a 64k boundary, and we need
87 to adjust the high word with this insn. */
88 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
90 /* The .glink fixup call stub is the same as the .plt call stub, but
91 the first instruction restores r2, and the std is omitted. */
92 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
94 /* Always allow this much space. */
95 #define GLINK_CALL_STUB_SIZE (8*4)
98 #define NOP 0x60000000
100 /* Some other nops. */
101 #define CROR_151515 0x4def7b82
102 #define CROR_313131 0x4ffffb82
104 /* .glink entries for the first 32k functions are two instructions. */
105 #define LI_R0_0 0x38000000 /* li %r0,0 */
106 #define B_DOT 0x48000000 /* b . */
108 /* After that, we need two instructions to load the index, followed by
110 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
111 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
113 /* Instructions to save and restore floating point regs. */
114 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
115 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
116 #define BLR 0x4e800020 /* blr */
118 /* Since .opd is an array of descriptors and each entry will end up
119 with identical R_PPC64_RELATIVE relocs, there is really no need to
120 propagate .opd relocs; The dynamic linker should be taught to
121 relocate .opd without reloc entries. */
122 #ifndef NO_OPD_RELOCS
123 #define NO_OPD_RELOCS 0
126 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
128 /* Relocation HOWTO's. */
129 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
131 static reloc_howto_type ppc64_elf_howto_raw
[] = {
132 /* This reloc does nothing. */
133 HOWTO (R_PPC64_NONE
, /* type */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
137 false, /* pc_relative */
139 complain_overflow_dont
, /* complain_on_overflow */
140 bfd_elf_generic_reloc
, /* special_function */
141 "R_PPC64_NONE", /* name */
142 false, /* partial_inplace */
145 false), /* pcrel_offset */
147 /* A standard 32 bit relocation. */
148 HOWTO (R_PPC64_ADDR32
, /* type */
150 2, /* size (0 = byte, 1 = short, 2 = long) */
152 false, /* pc_relative */
154 complain_overflow_bitfield
, /* complain_on_overflow */
155 bfd_elf_generic_reloc
, /* special_function */
156 "R_PPC64_ADDR32", /* name */
157 false, /* partial_inplace */
159 0xffffffff, /* dst_mask */
160 false), /* pcrel_offset */
162 /* An absolute 26 bit branch; the lower two bits must be zero.
163 FIXME: we don't check that, we just clear them. */
164 HOWTO (R_PPC64_ADDR24
, /* type */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
168 false, /* pc_relative */
170 complain_overflow_bitfield
, /* complain_on_overflow */
171 bfd_elf_generic_reloc
, /* special_function */
172 "R_PPC64_ADDR24", /* name */
173 false, /* partial_inplace */
175 0x03fffffc, /* dst_mask */
176 false), /* pcrel_offset */
178 /* A standard 16 bit relocation. */
179 HOWTO (R_PPC64_ADDR16
, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 false, /* pc_relative */
185 complain_overflow_bitfield
, /* complain_on_overflow */
186 bfd_elf_generic_reloc
, /* special_function */
187 "R_PPC64_ADDR16", /* name */
188 false, /* partial_inplace */
190 0xffff, /* dst_mask */
191 false), /* pcrel_offset */
193 /* A 16 bit relocation without overflow. */
194 HOWTO (R_PPC64_ADDR16_LO
, /* type */
196 1, /* size (0 = byte, 1 = short, 2 = long) */
198 false, /* pc_relative */
200 complain_overflow_dont
,/* complain_on_overflow */
201 bfd_elf_generic_reloc
, /* special_function */
202 "R_PPC64_ADDR16_LO", /* name */
203 false, /* partial_inplace */
205 0xffff, /* dst_mask */
206 false), /* pcrel_offset */
208 /* Bits 16-31 of an address. */
209 HOWTO (R_PPC64_ADDR16_HI
, /* type */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
213 false, /* pc_relative */
215 complain_overflow_dont
, /* complain_on_overflow */
216 bfd_elf_generic_reloc
, /* special_function */
217 "R_PPC64_ADDR16_HI", /* name */
218 false, /* partial_inplace */
220 0xffff, /* dst_mask */
221 false), /* pcrel_offset */
223 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
224 bits, treated as a signed number, is negative. */
225 HOWTO (R_PPC64_ADDR16_HA
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_dont
, /* complain_on_overflow */
232 ppc64_elf_ha_reloc
, /* special_function */
233 "R_PPC64_ADDR16_HA", /* name */
234 false, /* partial_inplace */
236 0xffff, /* dst_mask */
237 false), /* pcrel_offset */
239 /* An absolute 16 bit branch; the lower two bits must be zero.
240 FIXME: we don't check that, we just clear them. */
241 HOWTO (R_PPC64_ADDR14
, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 false, /* pc_relative */
247 complain_overflow_bitfield
, /* complain_on_overflow */
248 bfd_elf_generic_reloc
, /* special_function */
249 "R_PPC64_ADDR14", /* name */
250 false, /* partial_inplace */
252 0x0000fffc, /* dst_mask */
253 false), /* pcrel_offset */
255 /* An absolute 16 bit branch, for which bit 10 should be set to
256 indicate that the branch is expected to be taken. The lower two
257 bits must be zero. */
258 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 false, /* pc_relative */
264 complain_overflow_bitfield
, /* complain_on_overflow */
265 ppc64_elf_brtaken_reloc
, /* special_function */
266 "R_PPC64_ADDR14_BRTAKEN",/* name */
267 false, /* partial_inplace */
269 0x0000fffc, /* dst_mask */
270 false), /* pcrel_offset */
272 /* An absolute 16 bit branch, for which bit 10 should be set to
273 indicate that the branch is not expected to be taken. The lower
274 two bits must be zero. */
275 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 false, /* pc_relative */
281 complain_overflow_bitfield
, /* complain_on_overflow */
282 ppc64_elf_brtaken_reloc
, /* special_function */
283 "R_PPC64_ADDR14_BRNTAKEN",/* name */
284 false, /* partial_inplace */
286 0x0000fffc, /* dst_mask */
287 false), /* pcrel_offset */
289 /* A relative 26 bit branch; the lower two bits must be zero. */
290 HOWTO (R_PPC64_REL24
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 true, /* pc_relative */
296 complain_overflow_signed
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_PPC64_REL24", /* name */
299 false, /* partial_inplace */
301 0x03fffffc, /* dst_mask */
302 true), /* pcrel_offset */
304 /* A relative 16 bit branch; the lower two bits must be zero. */
305 HOWTO (R_PPC64_REL14
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 true, /* pc_relative */
311 complain_overflow_signed
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_PPC64_REL14", /* name */
314 false, /* partial_inplace */
316 0x0000fffc, /* dst_mask */
317 true), /* pcrel_offset */
319 /* A relative 16 bit branch. Bit 10 should be set to indicate that
320 the branch is expected to be taken. The lower two bits must be
322 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 true, /* pc_relative */
328 complain_overflow_signed
, /* complain_on_overflow */
329 ppc64_elf_brtaken_reloc
, /* special_function */
330 "R_PPC64_REL14_BRTAKEN", /* name */
331 false, /* partial_inplace */
333 0x0000fffc, /* dst_mask */
334 true), /* pcrel_offset */
336 /* A relative 16 bit branch. Bit 10 should be set to indicate that
337 the branch is not expected to be taken. The lower two bits must
339 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 true, /* pc_relative */
345 complain_overflow_signed
, /* complain_on_overflow */
346 ppc64_elf_brtaken_reloc
, /* special_function */
347 "R_PPC64_REL14_BRNTAKEN",/* name */
348 false, /* partial_inplace */
350 0x0000fffc, /* dst_mask */
351 true), /* pcrel_offset */
353 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
355 HOWTO (R_PPC64_GOT16
, /* type */
357 1, /* size (0 = byte, 1 = short, 2 = long) */
359 false, /* pc_relative */
361 complain_overflow_signed
, /* complain_on_overflow */
362 ppc64_elf_unhandled_reloc
, /* special_function */
363 "R_PPC64_GOT16", /* name */
364 false, /* partial_inplace */
366 0xffff, /* dst_mask */
367 false), /* pcrel_offset */
369 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
371 HOWTO (R_PPC64_GOT16_LO
, /* type */
373 1, /* size (0 = byte, 1 = short, 2 = long) */
375 false, /* pc_relative */
377 complain_overflow_dont
, /* complain_on_overflow */
378 ppc64_elf_unhandled_reloc
, /* special_function */
379 "R_PPC64_GOT16_LO", /* name */
380 false, /* partial_inplace */
382 0xffff, /* dst_mask */
383 false), /* pcrel_offset */
385 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
387 HOWTO (R_PPC64_GOT16_HI
, /* type */
389 1, /* size (0 = byte, 1 = short, 2 = long) */
391 false, /* pc_relative */
393 complain_overflow_dont
,/* complain_on_overflow */
394 ppc64_elf_unhandled_reloc
, /* special_function */
395 "R_PPC64_GOT16_HI", /* name */
396 false, /* partial_inplace */
398 0xffff, /* dst_mask */
399 false), /* pcrel_offset */
401 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
403 HOWTO (R_PPC64_GOT16_HA
, /* type */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
407 false, /* pc_relative */
409 complain_overflow_dont
,/* complain_on_overflow */
410 ppc64_elf_unhandled_reloc
, /* special_function */
411 "R_PPC64_GOT16_HA", /* name */
412 false, /* partial_inplace */
414 0xffff, /* dst_mask */
415 false), /* pcrel_offset */
417 /* This is used only by the dynamic linker. The symbol should exist
418 both in the object being run and in some shared library. The
419 dynamic linker copies the data addressed by the symbol from the
420 shared library into the object, because the object being
421 run has to have the data at some particular address. */
422 HOWTO (R_PPC64_COPY
, /* type */
424 0, /* this one is variable size */
426 false, /* pc_relative */
428 complain_overflow_dont
, /* complain_on_overflow */
429 ppc64_elf_unhandled_reloc
, /* special_function */
430 "R_PPC64_COPY", /* name */
431 false, /* partial_inplace */
434 false), /* pcrel_offset */
436 /* Like R_PPC64_ADDR64, but used when setting global offset table
438 HOWTO (R_PPC64_GLOB_DAT
, /* type */
440 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
442 false, /* pc_relative */
444 complain_overflow_dont
, /* complain_on_overflow */
445 ppc64_elf_unhandled_reloc
, /* special_function */
446 "R_PPC64_GLOB_DAT", /* name */
447 false, /* partial_inplace */
449 ONES (64), /* dst_mask */
450 false), /* pcrel_offset */
452 /* Created by the link editor. Marks a procedure linkage table
453 entry for a symbol. */
454 HOWTO (R_PPC64_JMP_SLOT
, /* type */
456 0, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_dont
, /* complain_on_overflow */
461 ppc64_elf_unhandled_reloc
, /* special_function */
462 "R_PPC64_JMP_SLOT", /* name */
463 false, /* partial_inplace */
466 false), /* pcrel_offset */
468 /* Used only by the dynamic linker. When the object is run, this
469 doubleword64 is set to the load address of the object, plus the
471 HOWTO (R_PPC64_RELATIVE
, /* type */
473 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
475 false, /* pc_relative */
477 complain_overflow_dont
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_PPC64_RELATIVE", /* name */
480 false, /* partial_inplace */
482 ONES (64), /* dst_mask */
483 false), /* pcrel_offset */
485 /* Like R_PPC64_ADDR32, but may be unaligned. */
486 HOWTO (R_PPC64_UADDR32
, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 false, /* pc_relative */
492 complain_overflow_bitfield
, /* complain_on_overflow */
493 bfd_elf_generic_reloc
, /* special_function */
494 "R_PPC64_UADDR32", /* name */
495 false, /* partial_inplace */
497 0xffffffff, /* dst_mask */
498 false), /* pcrel_offset */
500 /* Like R_PPC64_ADDR16, but may be unaligned. */
501 HOWTO (R_PPC64_UADDR16
, /* type */
503 1, /* size (0 = byte, 1 = short, 2 = long) */
505 false, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_PPC64_UADDR16", /* name */
510 false, /* partial_inplace */
512 0xffff, /* dst_mask */
513 false), /* pcrel_offset */
515 /* 32-bit PC relative. */
516 HOWTO (R_PPC64_REL32
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 true, /* pc_relative */
522 /* FIXME: Verify. Was complain_overflow_bitfield. */
523 complain_overflow_signed
, /* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_PPC64_REL32", /* name */
526 false, /* partial_inplace */
528 0xffffffff, /* dst_mask */
529 true), /* pcrel_offset */
531 /* 32-bit relocation to the symbol's procedure linkage table. */
532 HOWTO (R_PPC64_PLT32
, /* type */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
536 false, /* pc_relative */
538 complain_overflow_bitfield
, /* complain_on_overflow */
539 ppc64_elf_unhandled_reloc
, /* special_function */
540 "R_PPC64_PLT32", /* name */
541 false, /* partial_inplace */
543 0xffffffff, /* dst_mask */
544 false), /* pcrel_offset */
546 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
547 FIXME: R_PPC64_PLTREL32 not supported. */
548 HOWTO (R_PPC64_PLTREL32
, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 true, /* pc_relative */
554 complain_overflow_signed
, /* complain_on_overflow */
555 bfd_elf_generic_reloc
, /* special_function */
556 "R_PPC64_PLTREL32", /* name */
557 false, /* partial_inplace */
559 0xffffffff, /* dst_mask */
560 true), /* pcrel_offset */
562 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
564 HOWTO (R_PPC64_PLT16_LO
, /* type */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_dont
, /* complain_on_overflow */
571 ppc64_elf_unhandled_reloc
, /* special_function */
572 "R_PPC64_PLT16_LO", /* name */
573 false, /* partial_inplace */
575 0xffff, /* dst_mask */
576 false), /* pcrel_offset */
578 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
580 HOWTO (R_PPC64_PLT16_HI
, /* type */
582 1, /* size (0 = byte, 1 = short, 2 = long) */
584 false, /* pc_relative */
586 complain_overflow_dont
, /* complain_on_overflow */
587 ppc64_elf_unhandled_reloc
, /* special_function */
588 "R_PPC64_PLT16_HI", /* name */
589 false, /* partial_inplace */
591 0xffff, /* dst_mask */
592 false), /* pcrel_offset */
594 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
596 HOWTO (R_PPC64_PLT16_HA
, /* type */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
600 false, /* pc_relative */
602 complain_overflow_dont
, /* complain_on_overflow */
603 ppc64_elf_unhandled_reloc
, /* special_function */
604 "R_PPC64_PLT16_HA", /* name */
605 false, /* partial_inplace */
607 0xffff, /* dst_mask */
608 false), /* pcrel_offset */
610 /* 16-bit section relative relocation. */
611 HOWTO (R_PPC64_SECTOFF
, /* type */
613 1, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 ppc64_elf_sectoff_reloc
, /* special_function */
619 "R_PPC64_SECTOFF", /* name */
620 false, /* partial_inplace */
622 0xffff, /* dst_mask */
623 false), /* pcrel_offset */
625 /* Like R_PPC64_SECTOFF, but no overflow warning. */
626 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
628 1, /* size (0 = byte, 1 = short, 2 = long) */
630 false, /* pc_relative */
632 complain_overflow_dont
, /* complain_on_overflow */
633 ppc64_elf_sectoff_reloc
, /* special_function */
634 "R_PPC64_SECTOFF_LO", /* name */
635 false, /* partial_inplace */
637 0xffff, /* dst_mask */
638 false), /* pcrel_offset */
640 /* 16-bit upper half section relative relocation. */
641 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
643 1, /* size (0 = byte, 1 = short, 2 = long) */
645 false, /* pc_relative */
647 complain_overflow_dont
, /* complain_on_overflow */
648 ppc64_elf_sectoff_reloc
, /* special_function */
649 "R_PPC64_SECTOFF_HI", /* name */
650 false, /* partial_inplace */
652 0xffff, /* dst_mask */
653 false), /* pcrel_offset */
655 /* 16-bit upper half adjusted section relative relocation. */
656 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
658 1, /* size (0 = byte, 1 = short, 2 = long) */
660 false, /* pc_relative */
662 complain_overflow_dont
, /* complain_on_overflow */
663 ppc64_elf_sectoff_ha_reloc
, /* special_function */
664 "R_PPC64_SECTOFF_HA", /* name */
665 false, /* partial_inplace */
667 0xffff, /* dst_mask */
668 false), /* pcrel_offset */
670 /* Like R_PPC64_REL24 without touching the two least significant
671 bits. Should have been named R_PPC64_REL30! */
672 HOWTO (R_PPC64_ADDR30
, /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 true, /* pc_relative */
678 complain_overflow_dont
, /* complain_on_overflow */
679 bfd_elf_generic_reloc
, /* special_function */
680 "R_PPC64_ADDR30", /* name */
681 false, /* partial_inplace */
683 0xfffffffc, /* dst_mask */
684 true), /* pcrel_offset */
686 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
688 /* A standard 64-bit relocation. */
689 HOWTO (R_PPC64_ADDR64
, /* type */
691 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
693 false, /* pc_relative */
695 complain_overflow_dont
, /* complain_on_overflow */
696 bfd_elf_generic_reloc
, /* special_function */
697 "R_PPC64_ADDR64", /* name */
698 false, /* partial_inplace */
700 ONES (64), /* dst_mask */
701 false), /* pcrel_offset */
703 /* The bits 32-47 of an address. */
704 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
706 1, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_dont
, /* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_PPC64_ADDR16_HIGHER", /* name */
713 false, /* partial_inplace */
715 0xffff, /* dst_mask */
716 false), /* pcrel_offset */
718 /* The bits 32-47 of an address, plus 1 if the contents of the low
719 16 bits, treated as a signed number, is negative. */
720 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
722 1, /* size (0 = byte, 1 = short, 2 = long) */
724 false, /* pc_relative */
726 complain_overflow_dont
, /* complain_on_overflow */
727 ppc64_elf_ha_reloc
, /* special_function */
728 "R_PPC64_ADDR16_HIGHERA", /* name */
729 false, /* partial_inplace */
731 0xffff, /* dst_mask */
732 false), /* pcrel_offset */
734 /* The bits 48-63 of an address. */
735 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
737 1, /* size (0 = byte, 1 = short, 2 = long) */
739 false, /* pc_relative */
741 complain_overflow_dont
, /* complain_on_overflow */
742 bfd_elf_generic_reloc
, /* special_function */
743 "R_PPC64_ADDR16_HIGHEST", /* name */
744 false, /* partial_inplace */
746 0xffff, /* dst_mask */
747 false), /* pcrel_offset */
749 /* The bits 48-63 of an address, plus 1 if the contents of the low
750 16 bits, treated as a signed number, is negative. */
751 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
753 1, /* size (0 = byte, 1 = short, 2 = long) */
755 false, /* pc_relative */
757 complain_overflow_dont
, /* complain_on_overflow */
758 ppc64_elf_ha_reloc
, /* special_function */
759 "R_PPC64_ADDR16_HIGHESTA", /* name */
760 false, /* partial_inplace */
762 0xffff, /* dst_mask */
763 false), /* pcrel_offset */
765 /* Like ADDR64, but may be unaligned. */
766 HOWTO (R_PPC64_UADDR64
, /* type */
768 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
770 false, /* pc_relative */
772 complain_overflow_dont
, /* complain_on_overflow */
773 bfd_elf_generic_reloc
, /* special_function */
774 "R_PPC64_UADDR64", /* name */
775 false, /* partial_inplace */
777 ONES (64), /* dst_mask */
778 false), /* pcrel_offset */
780 /* 64-bit relative relocation. */
781 HOWTO (R_PPC64_REL64
, /* type */
783 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
785 true, /* pc_relative */
787 complain_overflow_dont
, /* complain_on_overflow */
788 bfd_elf_generic_reloc
, /* special_function */
789 "R_PPC64_REL64", /* name */
790 false, /* partial_inplace */
792 ONES (64), /* dst_mask */
793 true), /* pcrel_offset */
795 /* 64-bit relocation to the symbol's procedure linkage table. */
796 HOWTO (R_PPC64_PLT64
, /* type */
798 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
800 false, /* pc_relative */
802 complain_overflow_dont
, /* complain_on_overflow */
803 ppc64_elf_unhandled_reloc
, /* special_function */
804 "R_PPC64_PLT64", /* name */
805 false, /* partial_inplace */
807 ONES (64), /* dst_mask */
808 false), /* pcrel_offset */
810 /* 64-bit PC relative relocation to the symbol's procedure linkage
812 /* FIXME: R_PPC64_PLTREL64 not supported. */
813 HOWTO (R_PPC64_PLTREL64
, /* type */
815 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
817 true, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 ppc64_elf_unhandled_reloc
, /* special_function */
821 "R_PPC64_PLTREL64", /* name */
822 false, /* partial_inplace */
824 ONES (64), /* dst_mask */
825 true), /* pcrel_offset */
827 /* 16 bit TOC-relative relocation. */
829 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
830 HOWTO (R_PPC64_TOC16
, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 false, /* pc_relative */
836 complain_overflow_signed
, /* complain_on_overflow */
837 ppc64_elf_toc_reloc
, /* special_function */
838 "R_PPC64_TOC16", /* name */
839 false, /* partial_inplace */
841 0xffff, /* dst_mask */
842 false), /* pcrel_offset */
844 /* 16 bit TOC-relative relocation without overflow. */
846 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
847 HOWTO (R_PPC64_TOC16_LO
, /* type */
849 1, /* size (0 = byte, 1 = short, 2 = long) */
851 false, /* pc_relative */
853 complain_overflow_dont
, /* complain_on_overflow */
854 ppc64_elf_toc_reloc
, /* special_function */
855 "R_PPC64_TOC16_LO", /* name */
856 false, /* partial_inplace */
858 0xffff, /* dst_mask */
859 false), /* pcrel_offset */
861 /* 16 bit TOC-relative relocation, high 16 bits. */
863 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
864 HOWTO (R_PPC64_TOC16_HI
, /* type */
866 1, /* size (0 = byte, 1 = short, 2 = long) */
868 false, /* pc_relative */
870 complain_overflow_dont
, /* complain_on_overflow */
871 ppc64_elf_toc_reloc
, /* special_function */
872 "R_PPC64_TOC16_HI", /* name */
873 false, /* partial_inplace */
875 0xffff, /* dst_mask */
876 false), /* pcrel_offset */
878 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
879 contents of the low 16 bits, treated as a signed number, is
882 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
883 HOWTO (R_PPC64_TOC16_HA
, /* type */
885 1, /* size (0 = byte, 1 = short, 2 = long) */
887 false, /* pc_relative */
889 complain_overflow_dont
, /* complain_on_overflow */
890 ppc64_elf_toc_ha_reloc
, /* special_function */
891 "R_PPC64_TOC16_HA", /* name */
892 false, /* partial_inplace */
894 0xffff, /* dst_mask */
895 false), /* pcrel_offset */
897 /* 64-bit relocation; insert value of TOC base (.TOC.). */
899 /* R_PPC64_TOC 51 doubleword64 .TOC. */
900 HOWTO (R_PPC64_TOC
, /* type */
902 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
904 false, /* pc_relative */
906 complain_overflow_bitfield
, /* complain_on_overflow */
907 ppc64_elf_toc64_reloc
, /* special_function */
908 "R_PPC64_TOC", /* name */
909 false, /* partial_inplace */
911 ONES (64), /* dst_mask */
912 false), /* pcrel_offset */
914 /* Like R_PPC64_GOT16, but also informs the link editor that the
915 value to relocate may (!) refer to a PLT entry which the link
916 editor (a) may replace with the symbol value. If the link editor
917 is unable to fully resolve the symbol, it may (b) create a PLT
918 entry and store the address to the new PLT entry in the GOT.
919 This permits lazy resolution of function symbols at run time.
920 The link editor may also skip all of this and just (c) emit a
921 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
922 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
923 HOWTO (R_PPC64_PLTGOT16
, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 false, /* pc_relative */
929 complain_overflow_signed
, /* complain_on_overflow */
930 ppc64_elf_unhandled_reloc
, /* special_function */
931 "R_PPC64_PLTGOT16", /* name */
932 false, /* partial_inplace */
934 0xffff, /* dst_mask */
935 false), /* pcrel_offset */
937 /* Like R_PPC64_PLTGOT16, but without overflow. */
938 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
939 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
941 1, /* size (0 = byte, 1 = short, 2 = long) */
943 false, /* pc_relative */
945 complain_overflow_dont
, /* complain_on_overflow */
946 ppc64_elf_unhandled_reloc
, /* special_function */
947 "R_PPC64_PLTGOT16_LO", /* name */
948 false, /* partial_inplace */
950 0xffff, /* dst_mask */
951 false), /* pcrel_offset */
953 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
954 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
955 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
957 1, /* size (0 = byte, 1 = short, 2 = long) */
959 false, /* pc_relative */
961 complain_overflow_dont
, /* complain_on_overflow */
962 ppc64_elf_unhandled_reloc
, /* special_function */
963 "R_PPC64_PLTGOT16_HI", /* name */
964 false, /* partial_inplace */
966 0xffff, /* dst_mask */
967 false), /* pcrel_offset */
969 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
970 1 if the contents of the low 16 bits, treated as a signed number,
972 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
973 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
975 1, /* size (0 = byte, 1 = short, 2 = long) */
977 false, /* pc_relative */
979 complain_overflow_dont
,/* complain_on_overflow */
980 ppc64_elf_unhandled_reloc
, /* special_function */
981 "R_PPC64_PLTGOT16_HA", /* name */
982 false, /* partial_inplace */
984 0xffff, /* dst_mask */
985 false), /* pcrel_offset */
987 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
988 HOWTO (R_PPC64_ADDR16_DS
, /* type */
990 1, /* size (0 = byte, 1 = short, 2 = long) */
992 false, /* pc_relative */
994 complain_overflow_bitfield
, /* complain_on_overflow */
995 bfd_elf_generic_reloc
, /* special_function */
996 "R_PPC64_ADDR16_DS", /* name */
997 false, /* partial_inplace */
999 0xfffc, /* dst_mask */
1000 false), /* pcrel_offset */
1002 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1003 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1005 1, /* size (0 = byte, 1 = short, 2 = long) */
1007 false, /* pc_relative */
1009 complain_overflow_dont
,/* complain_on_overflow */
1010 bfd_elf_generic_reloc
, /* special_function */
1011 "R_PPC64_ADDR16_LO_DS",/* name */
1012 false, /* partial_inplace */
1014 0xfffc, /* dst_mask */
1015 false), /* pcrel_offset */
1017 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1018 HOWTO (R_PPC64_GOT16_DS
, /* type */
1020 1, /* size (0 = byte, 1 = short, 2 = long) */
1022 false, /* pc_relative */
1024 complain_overflow_signed
, /* complain_on_overflow */
1025 ppc64_elf_unhandled_reloc
, /* special_function */
1026 "R_PPC64_GOT16_DS", /* name */
1027 false, /* partial_inplace */
1029 0xfffc, /* dst_mask */
1030 false), /* pcrel_offset */
1032 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1033 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 false, /* pc_relative */
1039 complain_overflow_dont
, /* complain_on_overflow */
1040 ppc64_elf_unhandled_reloc
, /* special_function */
1041 "R_PPC64_GOT16_LO_DS", /* name */
1042 false, /* partial_inplace */
1044 0xfffc, /* dst_mask */
1045 false), /* pcrel_offset */
1047 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1048 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1050 1, /* size (0 = byte, 1 = short, 2 = long) */
1052 false, /* pc_relative */
1054 complain_overflow_dont
, /* complain_on_overflow */
1055 ppc64_elf_unhandled_reloc
, /* special_function */
1056 "R_PPC64_PLT16_LO_DS", /* name */
1057 false, /* partial_inplace */
1059 0xfffc, /* dst_mask */
1060 false), /* pcrel_offset */
1062 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1063 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1065 1, /* size (0 = byte, 1 = short, 2 = long) */
1067 false, /* pc_relative */
1069 complain_overflow_bitfield
, /* complain_on_overflow */
1070 ppc64_elf_sectoff_reloc
, /* special_function */
1071 "R_PPC64_SECTOFF_DS", /* name */
1072 false, /* partial_inplace */
1074 0xfffc, /* dst_mask */
1075 false), /* pcrel_offset */
1077 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1078 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1080 1, /* size (0 = byte, 1 = short, 2 = long) */
1082 false, /* pc_relative */
1084 complain_overflow_dont
, /* complain_on_overflow */
1085 ppc64_elf_sectoff_reloc
, /* special_function */
1086 "R_PPC64_SECTOFF_LO_DS",/* name */
1087 false, /* partial_inplace */
1089 0xfffc, /* dst_mask */
1090 false), /* pcrel_offset */
1092 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1093 HOWTO (R_PPC64_TOC16_DS
, /* type */
1095 1, /* size (0 = byte, 1 = short, 2 = long) */
1097 false, /* pc_relative */
1099 complain_overflow_signed
, /* complain_on_overflow */
1100 ppc64_elf_toc_reloc
, /* special_function */
1101 "R_PPC64_TOC16_DS", /* name */
1102 false, /* partial_inplace */
1104 0xfffc, /* dst_mask */
1105 false), /* pcrel_offset */
1107 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1108 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1110 1, /* size (0 = byte, 1 = short, 2 = long) */
1112 false, /* pc_relative */
1114 complain_overflow_dont
, /* complain_on_overflow */
1115 ppc64_elf_toc_reloc
, /* special_function */
1116 "R_PPC64_TOC16_LO_DS", /* name */
1117 false, /* partial_inplace */
1119 0xfffc, /* dst_mask */
1120 false), /* pcrel_offset */
1122 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1123 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1124 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1126 1, /* size (0 = byte, 1 = short, 2 = long) */
1128 false, /* pc_relative */
1130 complain_overflow_signed
, /* complain_on_overflow */
1131 ppc64_elf_unhandled_reloc
, /* special_function */
1132 "R_PPC64_PLTGOT16_DS", /* name */
1133 false, /* partial_inplace */
1135 0xfffc, /* dst_mask */
1136 false), /* pcrel_offset */
1138 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1139 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1140 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1142 1, /* size (0 = byte, 1 = short, 2 = long) */
1144 false, /* pc_relative */
1146 complain_overflow_dont
, /* complain_on_overflow */
1147 ppc64_elf_unhandled_reloc
, /* special_function */
1148 "R_PPC64_PLTGOT16_LO_DS",/* name */
1149 false, /* partial_inplace */
1151 0xfffc, /* dst_mask */
1152 false), /* pcrel_offset */
1154 /* GNU extension to record C++ vtable hierarchy. */
1155 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1157 0, /* size (0 = byte, 1 = short, 2 = long) */
1159 false, /* pc_relative */
1161 complain_overflow_dont
, /* complain_on_overflow */
1162 NULL
, /* special_function */
1163 "R_PPC64_GNU_VTINHERIT", /* name */
1164 false, /* partial_inplace */
1167 false), /* pcrel_offset */
1169 /* GNU extension to record C++ vtable member usage. */
1170 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1172 0, /* size (0 = byte, 1 = short, 2 = long) */
1174 false, /* pc_relative */
1176 complain_overflow_dont
, /* complain_on_overflow */
1177 NULL
, /* special_function */
1178 "R_PPC64_GNU_VTENTRY", /* name */
1179 false, /* partial_inplace */
1182 false), /* pcrel_offset */
1186 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1192 unsigned int i
, type
;
1195 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1198 type
= ppc64_elf_howto_raw
[i
].type
;
1199 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1200 / sizeof (ppc64_elf_howto_table
[0])));
1201 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1205 static reloc_howto_type
*
1206 ppc64_elf_reloc_type_lookup (abfd
, code
)
1207 bfd
*abfd ATTRIBUTE_UNUSED
;
1208 bfd_reloc_code_real_type code
;
1210 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1212 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1213 /* Initialize howto table if needed. */
1219 return (reloc_howto_type
*) NULL
;
1221 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1223 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1225 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1227 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1229 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1231 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1233 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1235 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1237 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1239 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1241 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1243 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1245 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1247 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1249 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1251 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1253 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1255 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1257 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1259 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1261 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1263 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1265 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1267 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1269 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1271 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1273 case BFD_RELOC_16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1275 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1277 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1279 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1281 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR64
;
1283 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1285 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1287 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1289 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1291 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1293 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1295 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1297 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1299 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1301 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1303 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1305 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1307 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1309 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1311 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1313 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1315 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1317 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1319 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1321 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1323 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1325 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1327 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1329 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1331 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1333 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1335 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1337 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1339 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1341 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1345 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1348 /* Set the howto pointer for a PowerPC ELF reloc. */
1351 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1352 bfd
*abfd ATTRIBUTE_UNUSED
;
1354 Elf64_Internal_Rela
*dst
;
1358 /* Initialize howto table if needed. */
1359 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1362 type
= ELF64_R_TYPE (dst
->r_info
);
1363 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1364 / sizeof (ppc64_elf_howto_table
[0])));
1365 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1368 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1370 static bfd_reloc_status_type
1371 ppc64_elf_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1372 input_section
, output_bfd
, error_message
)
1374 arelent
*reloc_entry
;
1377 asection
*input_section
;
1379 char **error_message
;
1381 /* If this is a relocatable link (output_bfd test tells us), just
1382 call the generic function. Any adjustment will be done at final
1384 if (output_bfd
!= NULL
)
1385 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1386 input_section
, output_bfd
, error_message
);
1388 /* Adjust the addend for sign extension of the low 16 bits.
1389 We won't actually be using the low 16 bits, so trashing them
1391 reloc_entry
->addend
+= 0x8000;
1392 return bfd_reloc_continue
;
1395 static bfd_reloc_status_type
1396 ppc64_elf_brtaken_reloc (abfd
, reloc_entry
, symbol
, data
,
1397 input_section
, output_bfd
, error_message
)
1399 arelent
*reloc_entry
;
1402 asection
*input_section
;
1404 char **error_message
;
1407 enum elf_ppc_reloc_type r_type
;
1408 bfd_size_type octets
;
1409 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1410 boolean is_power4
= false;
1412 /* If this is a relocatable link (output_bfd test tells us), just
1413 call the generic function. Any adjustment will be done at final
1415 if (output_bfd
!= NULL
)
1416 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1417 input_section
, output_bfd
, error_message
);
1419 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1420 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1421 insn
&= ~(0x01 << 21);
1422 r_type
= (enum elf_ppc_reloc_type
) reloc_entry
->howto
->type
;
1423 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1424 || r_type
== R_PPC64_REL14_BRTAKEN
)
1425 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1429 /* Set 'a' bit. This is 0b00010 in BO field for branch
1430 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1431 for branch on CTR insns (BO == 1a00t or 1a01t). */
1432 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1434 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1437 return bfd_reloc_continue
;
1444 if (!bfd_is_com_section (symbol
->section
))
1445 target
= symbol
->value
;
1446 target
+= symbol
->section
->output_section
->vma
;
1447 target
+= symbol
->section
->output_offset
;
1448 target
+= reloc_entry
->addend
;
1450 from
= (reloc_entry
->address
1451 + input_section
->output_offset
1452 + input_section
->output_section
->vma
);
1454 /* Invert 'y' bit if not the default. */
1455 if ((bfd_signed_vma
) (target
- from
) < 0)
1458 bfd_put_32 (abfd
, (bfd_vma
) insn
, (bfd_byte
*) data
+ octets
);
1459 return bfd_reloc_continue
;
1462 static bfd_reloc_status_type
1463 ppc64_elf_sectoff_reloc (abfd
, reloc_entry
, symbol
, data
,
1464 input_section
, output_bfd
, error_message
)
1466 arelent
*reloc_entry
;
1469 asection
*input_section
;
1471 char **error_message
;
1473 /* If this is a relocatable link (output_bfd test tells us), just
1474 call the generic function. Any adjustment will be done at final
1476 if (output_bfd
!= NULL
)
1477 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1478 input_section
, output_bfd
, error_message
);
1480 /* Subtract the symbol section base address. */
1481 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1482 return bfd_reloc_continue
;
1485 static bfd_reloc_status_type
1486 ppc64_elf_sectoff_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1487 input_section
, output_bfd
, error_message
)
1489 arelent
*reloc_entry
;
1492 asection
*input_section
;
1494 char **error_message
;
1496 /* If this is a relocatable link (output_bfd test tells us), just
1497 call the generic function. Any adjustment will be done at final
1499 if (output_bfd
!= NULL
)
1500 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1501 input_section
, output_bfd
, error_message
);
1503 /* Subtract the symbol section base address. */
1504 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1506 /* Adjust the addend for sign extension of the low 16 bits. */
1507 reloc_entry
->addend
+= 0x8000;
1508 return bfd_reloc_continue
;
1511 static bfd_reloc_status_type
1512 ppc64_elf_toc_reloc (abfd
, reloc_entry
, symbol
, data
,
1513 input_section
, output_bfd
, error_message
)
1515 arelent
*reloc_entry
;
1518 asection
*input_section
;
1520 char **error_message
;
1524 /* If this is a relocatable link (output_bfd test tells us), just
1525 call the generic function. Any adjustment will be done at final
1527 if (output_bfd
!= NULL
)
1528 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1529 input_section
, output_bfd
, error_message
);
1531 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1533 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1535 /* Subtract the TOC base address. */
1536 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1537 return bfd_reloc_continue
;
1540 static bfd_reloc_status_type
1541 ppc64_elf_toc_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1542 input_section
, output_bfd
, error_message
)
1544 arelent
*reloc_entry
;
1547 asection
*input_section
;
1549 char **error_message
;
1553 /* If this is a relocatable link (output_bfd test tells us), just
1554 call the generic function. Any adjustment will be done at final
1556 if (output_bfd
!= NULL
)
1557 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1558 input_section
, output_bfd
, error_message
);
1560 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1562 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1564 /* Subtract the TOC base address. */
1565 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1567 /* Adjust the addend for sign extension of the low 16 bits. */
1568 reloc_entry
->addend
+= 0x8000;
1569 return bfd_reloc_continue
;
1572 static bfd_reloc_status_type
1573 ppc64_elf_toc64_reloc (abfd
, reloc_entry
, symbol
, data
,
1574 input_section
, output_bfd
, error_message
)
1576 arelent
*reloc_entry
;
1579 asection
*input_section
;
1581 char **error_message
;
1584 bfd_size_type octets
;
1586 /* If this is a relocatable link (output_bfd test tells us), just
1587 call the generic function. Any adjustment will be done at final
1589 if (output_bfd
!= NULL
)
1590 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1591 input_section
, output_bfd
, error_message
);
1593 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1595 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1597 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1598 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1599 return bfd_reloc_ok
;
1602 static bfd_reloc_status_type
1603 ppc64_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
1604 input_section
, output_bfd
, error_message
)
1606 arelent
*reloc_entry
;
1609 asection
*input_section
;
1611 char **error_message
;
1613 /* If this is a relocatable link (output_bfd test tells us), just
1614 call the generic function. Any adjustment will be done at final
1616 if (output_bfd
!= NULL
)
1617 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1618 input_section
, output_bfd
, error_message
);
1620 if (error_message
!= NULL
)
1622 static char buf
[60];
1623 sprintf (buf
, "generic linker can't handle %s",
1624 reloc_entry
->howto
->name
);
1625 *error_message
= buf
;
1627 return bfd_reloc_dangerous
;
1630 /* Fix bad default arch selected for a 64 bit input bfd when the
1631 default is 32 bit. */
1634 ppc64_elf_object_p (abfd
)
1637 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
1639 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1641 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1643 /* Relies on arch after 32 bit default being 64 bit default. */
1644 abfd
->arch_info
= abfd
->arch_info
->next
;
1645 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1651 /* Merge backend specific data from an object file to the output
1652 object file when linking. */
1655 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1659 /* Check if we have the same endianess. */
1660 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1661 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
1662 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1666 if (bfd_big_endian (ibfd
))
1667 msg
= _("%s: compiled for a big endian system and target is little endian");
1669 msg
= _("%s: compiled for a little endian system and target is big endian");
1671 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1673 bfd_set_error (bfd_error_wrong_format
);
1680 /* The following functions are specific to the ELF linker, while
1681 functions above are used generally. Those named ppc64_elf_* are
1682 called by the main ELF linker code. They appear in this file more
1683 or less in the order in which they are called. eg.
1684 ppc64_elf_check_relocs is called early in the link process,
1685 ppc64_elf_finish_dynamic_sections is one of the last functions
1688 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1689 functions have both a function code symbol and a function descriptor
1690 symbol. A call to foo in a relocatable object file looks like:
1697 The function definition in another object file might be:
1701 . .quad .TOC.@tocbase
1707 When the linker resolves the call during a static link, the branch
1708 unsurprisingly just goes to .foo and the .opd information is unused.
1709 If the function definition is in a shared library, things are a little
1710 different: The call goes via a plt call stub, the opd information gets
1711 copied to the plt, and the linker patches the nop.
1719 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1720 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1721 . std 2,40(1) # this is the general idea
1729 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1731 The "reloc ()" notation is supposed to indicate that the linker emits
1732 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1735 What are the difficulties here? Well, firstly, the relocations
1736 examined by the linker in check_relocs are against the function code
1737 sym .foo, while the dynamic relocation in the plt is emitted against
1738 the function descriptor symbol, foo. Somewhere along the line, we need
1739 to carefully copy dynamic link information from one symbol to the other.
1740 Secondly, the generic part of the elf linker will make .foo a dynamic
1741 symbol as is normal for most other backends. We need foo dynamic
1742 instead, at least for an application final link. However, when
1743 creating a shared library containing foo, we need to have both symbols
1744 dynamic so that references to .foo are satisfied during the early
1745 stages of linking. Otherwise the linker might decide to pull in a
1746 definition from some other object, eg. a static library. */
1748 /* The linker needs to keep track of the number of relocs that it
1749 decides to copy as dynamic relocs in check_relocs for each symbol.
1750 This is so that it can later discard them if they are found to be
1751 unnecessary. We store the information in a field extending the
1752 regular ELF linker hash table. */
1754 struct ppc_dyn_relocs
1756 struct ppc_dyn_relocs
*next
;
1758 /* The input section of the reloc. */
1761 /* Total number of relocs copied for the input section. */
1762 bfd_size_type count
;
1764 /* Number of pc-relative relocs copied for the input section. */
1765 bfd_size_type pc_count
;
1768 /* Of those relocs that might be copied as dynamic relocs, this macro
1769 selects between relative and absolute types. */
1771 #define IS_ABSOLUTE_RELOC(RTYPE) \
1772 ((RTYPE) != R_PPC64_REL32 \
1773 && (RTYPE) != R_PPC64_REL64 \
1774 && (RTYPE) != R_PPC64_ADDR30)
1776 /* Section name for stubs is the associated section name plus this
1778 #define STUB_SUFFIX ".stub"
1781 ppc_stub_long_branch:
1782 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1783 destination, but a 24 bit branch in a stub section will reach.
1786 ppc_stub_plt_branch:
1787 Similar to the above, but a 24 bit branch in the stub section won't
1788 reach its destination.
1789 . addis %r12,%r2,xxx@toc@ha
1790 . ld %r11,xxx@toc@l(%r12)
1795 Used to call a function in a shared library.
1796 . addis %r12,%r2,xxx@toc@ha
1798 . ld %r11,xxx+0@toc@l(%r12)
1799 . ld %r2,xxx+8@toc@l(%r12)
1801 . ld %r11,xxx+16@toc@l(%r12)
1805 enum ppc_stub_type
{
1807 ppc_stub_long_branch
,
1808 ppc_stub_plt_branch
,
1812 struct ppc_stub_hash_entry
{
1814 /* Base hash table entry structure. */
1815 struct bfd_hash_entry root
;
1817 /* The stub section. */
1820 /* Offset within stub_sec of the beginning of this stub. */
1821 bfd_vma stub_offset
;
1823 /* Given the symbol's value and its section we can determine its final
1824 value when building the stubs (so the stub knows where to jump. */
1825 bfd_vma target_value
;
1826 asection
*target_section
;
1828 enum ppc_stub_type stub_type
;
1830 /* The symbol table entry, if any, that this was derived from. */
1831 struct ppc_link_hash_entry
*h
;
1833 /* Where this stub is being called from, or, in the case of combined
1834 stub sections, the first input section in the group. */
1838 struct ppc_branch_hash_entry
{
1840 /* Base hash table entry structure. */
1841 struct bfd_hash_entry root
;
1843 /* Offset within .branch_lt. */
1844 unsigned int offset
;
1846 /* Generation marker. */
1850 struct ppc_link_hash_entry
1852 struct elf_link_hash_entry elf
;
1854 /* A pointer to the most recently used stub hash entry against this
1856 struct ppc_stub_hash_entry
*stub_cache
;
1858 /* Track dynamic relocs copied for this symbol. */
1859 struct ppc_dyn_relocs
*dyn_relocs
;
1861 /* Link between function code and descriptor symbols. */
1862 struct elf_link_hash_entry
*oh
;
1864 /* Flag function code and descriptor symbols. */
1865 unsigned int is_func
:1;
1866 unsigned int is_func_descriptor
:1;
1867 unsigned int is_entry
:1;
1870 /* ppc64 ELF linker hash table. */
1872 struct ppc_link_hash_table
1874 struct elf_link_hash_table elf
;
1876 /* The stub hash table. */
1877 struct bfd_hash_table stub_hash_table
;
1879 /* Another hash table for plt_branch stubs. */
1880 struct bfd_hash_table branch_hash_table
;
1882 /* Linker stub bfd. */
1885 /* Linker call-backs. */
1886 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
1887 void (*layout_sections_again
) PARAMS ((void));
1889 /* Array to keep track of which stub sections have been created, and
1890 information on stub grouping. */
1892 /* This is the section to which stubs in the group will be attached. */
1894 /* The stub section. */
1898 /* Assorted information used by ppc64_elf_size_stubs. */
1900 asection
**input_list
;
1902 /* Short-cuts to get to dynamic linker sections. */
1915 unsigned int stub_error
;
1917 /* Flag set when small branches are detected. Used to
1918 select suitable defaults for the stub group size. */
1919 unsigned int has_14bit_branch
;
1921 /* Set if we detect a reference undefined weak symbol. */
1922 unsigned int have_undefweak
;
1924 /* Incremented every time we size stubs. */
1925 unsigned int stub_iteration
;
1927 /* Small local sym to section mapping cache. */
1928 struct sym_sec_cache sym_sec
;
1931 static struct bfd_hash_entry
*stub_hash_newfunc
1932 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1933 static struct bfd_hash_entry
*branch_hash_newfunc
1934 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1935 static struct bfd_hash_entry
*link_hash_newfunc
1936 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
1937 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
1939 static void ppc64_elf_link_hash_table_free
1940 PARAMS ((struct bfd_link_hash_table
*));
1941 static char *ppc_stub_name
1942 PARAMS ((const asection
*, const asection
*,
1943 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
1944 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
1945 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
1946 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
1947 static struct ppc_stub_hash_entry
*ppc_add_stub
1948 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
1949 static boolean create_linkage_sections
1950 PARAMS ((bfd
*, struct bfd_link_info
*));
1951 static boolean create_got_section
1952 PARAMS ((bfd
*, struct bfd_link_info
*));
1953 static boolean ppc64_elf_create_dynamic_sections
1954 PARAMS ((bfd
*, struct bfd_link_info
*));
1955 static void ppc64_elf_copy_indirect_symbol
1956 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
1957 struct elf_link_hash_entry
*));
1958 static boolean ppc64_elf_check_relocs
1959 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1960 const Elf_Internal_Rela
*));
1961 static asection
* ppc64_elf_gc_mark_hook
1962 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
1963 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
1964 static boolean ppc64_elf_gc_sweep_hook
1965 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
1966 const Elf_Internal_Rela
*));
1967 static boolean func_desc_adjust
1968 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1969 static boolean ppc64_elf_func_desc_adjust
1970 PARAMS ((bfd
*, struct bfd_link_info
*));
1971 static boolean ppc64_elf_adjust_dynamic_symbol
1972 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
1973 static void ppc64_elf_hide_symbol
1974 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, boolean
));
1975 static boolean edit_opd
1976 PARAMS ((bfd
*, struct bfd_link_info
*));
1977 static boolean allocate_dynrelocs
1978 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1979 static boolean readonly_dynrelocs
1980 PARAMS ((struct elf_link_hash_entry
*, PTR
));
1981 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
1982 PARAMS ((const Elf_Internal_Rela
*));
1983 static boolean ppc64_elf_size_dynamic_sections
1984 PARAMS ((bfd
*, struct bfd_link_info
*));
1985 static INLINE
enum ppc_stub_type ppc_type_of_stub
1986 PARAMS ((asection
*, const Elf_Internal_Rela
*,
1987 struct ppc_link_hash_entry
**, bfd_vma
));
1988 static bfd_byte
*build_plt_stub
1989 PARAMS ((bfd
*, bfd_byte
*, int, int));
1990 static boolean ppc_build_one_stub
1991 PARAMS ((struct bfd_hash_entry
*, PTR
));
1992 static boolean ppc_size_one_stub
1993 PARAMS ((struct bfd_hash_entry
*, PTR
));
1994 static void group_sections
1995 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, boolean
));
1996 static boolean ppc64_elf_relocate_section
1997 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
1998 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
2000 static boolean ppc64_elf_finish_dynamic_symbol
2001 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
2002 Elf_Internal_Sym
*));
2003 static boolean ppc64_elf_finish_dynamic_sections
2004 PARAMS ((bfd
*, struct bfd_link_info
*));
2006 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2008 #define ppc_hash_table(p) \
2009 ((struct ppc_link_hash_table *) ((p)->hash))
2011 #define ppc_stub_hash_lookup(table, string, create, copy) \
2012 ((struct ppc_stub_hash_entry *) \
2013 bfd_hash_lookup ((table), (string), (create), (copy)))
2015 #define ppc_branch_hash_lookup(table, string, create, copy) \
2016 ((struct ppc_branch_hash_entry *) \
2017 bfd_hash_lookup ((table), (string), (create), (copy)))
2019 /* Create an entry in the stub hash table. */
2021 static struct bfd_hash_entry
*
2022 stub_hash_newfunc (entry
, table
, string
)
2023 struct bfd_hash_entry
*entry
;
2024 struct bfd_hash_table
*table
;
2027 /* Allocate the structure if it has not already been allocated by a
2031 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2036 /* Call the allocation method of the superclass. */
2037 entry
= bfd_hash_newfunc (entry
, table
, string
);
2040 struct ppc_stub_hash_entry
*eh
;
2042 /* Initialize the local fields. */
2043 eh
= (struct ppc_stub_hash_entry
*) entry
;
2044 eh
->stub_sec
= NULL
;
2045 eh
->stub_offset
= 0;
2046 eh
->target_value
= 0;
2047 eh
->target_section
= NULL
;
2048 eh
->stub_type
= ppc_stub_none
;
2056 /* Create an entry in the branch hash table. */
2058 static struct bfd_hash_entry
*
2059 branch_hash_newfunc (entry
, table
, string
)
2060 struct bfd_hash_entry
*entry
;
2061 struct bfd_hash_table
*table
;
2064 /* Allocate the structure if it has not already been allocated by a
2068 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2073 /* Call the allocation method of the superclass. */
2074 entry
= bfd_hash_newfunc (entry
, table
, string
);
2077 struct ppc_branch_hash_entry
*eh
;
2079 /* Initialize the local fields. */
2080 eh
= (struct ppc_branch_hash_entry
*) entry
;
2088 /* Create an entry in a ppc64 ELF linker hash table. */
2090 static struct bfd_hash_entry
*
2091 link_hash_newfunc (entry
, table
, string
)
2092 struct bfd_hash_entry
*entry
;
2093 struct bfd_hash_table
*table
;
2096 /* Allocate the structure if it has not already been allocated by a
2100 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2105 /* Call the allocation method of the superclass. */
2106 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2109 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2111 eh
->stub_cache
= NULL
;
2112 eh
->dyn_relocs
= NULL
;
2115 eh
->is_func_descriptor
= 0;
2122 /* Create a ppc64 ELF linker hash table. */
2124 static struct bfd_link_hash_table
*
2125 ppc64_elf_link_hash_table_create (abfd
)
2128 struct ppc_link_hash_table
*htab
;
2129 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2131 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2135 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2141 /* Init the stub hash table too. */
2142 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2145 /* And the branch hash table. */
2146 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2149 htab
->stub_bfd
= NULL
;
2150 htab
->add_stub_section
= NULL
;
2151 htab
->layout_sections_again
= NULL
;
2152 htab
->stub_group
= NULL
;
2154 htab
->srelgot
= NULL
;
2156 htab
->srelplt
= NULL
;
2157 htab
->sdynbss
= NULL
;
2158 htab
->srelbss
= NULL
;
2159 htab
->sglink
= NULL
;
2162 htab
->srelbrlt
= NULL
;
2163 htab
->stub_error
= 0;
2164 htab
->has_14bit_branch
= 0;
2165 htab
->have_undefweak
= 0;
2166 htab
->stub_iteration
= 0;
2167 htab
->sym_sec
.abfd
= NULL
;
2169 return &htab
->elf
.root
;
2172 /* Free the derived linker hash table. */
2175 ppc64_elf_link_hash_table_free (hash
)
2176 struct bfd_link_hash_table
*hash
;
2178 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2180 bfd_hash_table_free (&ret
->stub_hash_table
);
2181 bfd_hash_table_free (&ret
->branch_hash_table
);
2182 _bfd_generic_link_hash_table_free (hash
);
2185 /* Build a name for an entry in the stub hash table. */
2188 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2189 const asection
*input_section
;
2190 const asection
*sym_sec
;
2191 const struct ppc_link_hash_entry
*h
;
2192 const Elf_Internal_Rela
*rel
;
2197 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2198 offsets from a sym as a branch target? In fact, we could
2199 probably assume the addend is always zero. */
2200 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2204 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2205 stub_name
= bfd_malloc (len
);
2206 if (stub_name
!= NULL
)
2208 sprintf (stub_name
, "%08x_%s+%x",
2209 input_section
->id
& 0xffffffff,
2210 h
->elf
.root
.root
.string
,
2211 (int) rel
->r_addend
& 0xffffffff);
2216 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2217 stub_name
= bfd_malloc (len
);
2218 if (stub_name
!= NULL
)
2220 sprintf (stub_name
, "%08x_%x:%x+%x",
2221 input_section
->id
& 0xffffffff,
2222 sym_sec
->id
& 0xffffffff,
2223 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2224 (int) rel
->r_addend
& 0xffffffff);
2230 /* Look up an entry in the stub hash. Stub entries are cached because
2231 creating the stub name takes a bit of time. */
2233 static struct ppc_stub_hash_entry
*
2234 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2235 const asection
*input_section
;
2236 const asection
*sym_sec
;
2237 struct elf_link_hash_entry
*hash
;
2238 const Elf_Internal_Rela
*rel
;
2239 struct ppc_link_hash_table
*htab
;
2241 struct ppc_stub_hash_entry
*stub_entry
;
2242 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2243 const asection
*id_sec
;
2245 /* If this input section is part of a group of sections sharing one
2246 stub section, then use the id of the first section in the group.
2247 Stub names need to include a section id, as there may well be
2248 more than one stub used to reach say, printf, and we need to
2249 distinguish between them. */
2250 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2252 if (h
!= NULL
&& h
->stub_cache
!= NULL
2253 && h
->stub_cache
->h
== h
2254 && h
->stub_cache
->id_sec
== id_sec
)
2256 stub_entry
= h
->stub_cache
;
2262 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2263 if (stub_name
== NULL
)
2266 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2267 stub_name
, false, false);
2269 h
->stub_cache
= stub_entry
;
2277 /* Add a new stub entry to the stub hash. Not all fields of the new
2278 stub entry are initialised. */
2280 static struct ppc_stub_hash_entry
*
2281 ppc_add_stub (stub_name
, section
, htab
)
2282 const char *stub_name
;
2284 struct ppc_link_hash_table
*htab
;
2288 struct ppc_stub_hash_entry
*stub_entry
;
2290 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2291 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2292 if (stub_sec
== NULL
)
2294 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2295 if (stub_sec
== NULL
)
2301 namelen
= strlen (link_sec
->name
);
2302 len
= namelen
+ sizeof (STUB_SUFFIX
);
2303 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2307 memcpy (s_name
, link_sec
->name
, namelen
);
2308 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2309 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2310 if (stub_sec
== NULL
)
2312 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2314 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2317 /* Enter this entry into the linker stub hash table. */
2318 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2320 if (stub_entry
== NULL
)
2322 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2323 bfd_archive_filename (section
->owner
),
2328 stub_entry
->stub_sec
= stub_sec
;
2329 stub_entry
->stub_offset
= 0;
2330 stub_entry
->id_sec
= link_sec
;
2334 /* Create sections for linker generated code. */
2337 create_linkage_sections (dynobj
, info
)
2339 struct bfd_link_info
*info
;
2341 struct ppc_link_hash_table
*htab
;
2344 htab
= ppc_hash_table (info
);
2346 /* Create .sfpr for code to save and restore fp regs. */
2347 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2348 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2349 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2350 if (htab
->sfpr
== NULL
2351 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2352 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2355 /* Create .glink for lazy dynamic linking support. */
2356 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2357 if (htab
->sglink
== NULL
2358 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2359 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2362 /* Create .branch_lt for plt_branch stubs. */
2363 flags
= (SEC_ALLOC
| SEC_LOAD
2364 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2365 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2366 if (htab
->sbrlt
== NULL
2367 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2368 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2373 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2374 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2375 htab
->srelbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
2377 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2378 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2384 /* Create .got and .rela.got sections in DYNOBJ, and set up
2385 shortcuts to them in our hash table. */
2388 create_got_section (dynobj
, info
)
2390 struct bfd_link_info
*info
;
2392 struct ppc_link_hash_table
*htab
;
2394 if (! _bfd_elf_create_got_section (dynobj
, info
))
2397 htab
= ppc_hash_table (info
);
2398 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2402 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2404 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2405 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2406 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2408 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2413 /* Create the dynamic sections, and set up shortcuts. */
2416 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2418 struct bfd_link_info
*info
;
2420 struct ppc_link_hash_table
*htab
;
2422 htab
= ppc_hash_table (info
);
2423 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2426 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2429 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2430 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2431 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2433 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2435 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2436 || (!info
->shared
&& !htab
->srelbss
))
2442 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2445 ppc64_elf_copy_indirect_symbol (bed
, dir
, ind
)
2446 struct elf_backend_data
*bed
;
2447 struct elf_link_hash_entry
*dir
, *ind
;
2449 struct ppc_link_hash_entry
*edir
, *eind
;
2451 edir
= (struct ppc_link_hash_entry
*) dir
;
2452 eind
= (struct ppc_link_hash_entry
*) ind
;
2454 if (eind
->dyn_relocs
!= NULL
)
2456 if (edir
->dyn_relocs
!= NULL
)
2458 struct ppc_dyn_relocs
**pp
;
2459 struct ppc_dyn_relocs
*p
;
2461 if (ind
->root
.type
== bfd_link_hash_indirect
)
2464 /* Add reloc counts against the weak sym to the strong sym
2465 list. Merge any entries against the same section. */
2466 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2468 struct ppc_dyn_relocs
*q
;
2470 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2471 if (q
->sec
== p
->sec
)
2473 q
->pc_count
+= p
->pc_count
;
2474 q
->count
+= p
->count
;
2481 *pp
= edir
->dyn_relocs
;
2484 edir
->dyn_relocs
= eind
->dyn_relocs
;
2485 eind
->dyn_relocs
= NULL
;
2488 edir
->is_func
|= eind
->is_func
;
2489 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2490 edir
->is_entry
|= eind
->is_entry
;
2492 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
2495 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2496 symbols undefined on the command-line. */
2499 ppc64_elf_mark_entry_syms (info
)
2500 struct bfd_link_info
*info
;
2502 struct ppc_link_hash_table
*htab
;
2503 struct bfd_sym_chain
*sym
;
2505 htab
= ppc_hash_table (info
);
2506 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
2508 struct elf_link_hash_entry
*h
;
2510 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, false, false, false);
2512 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
2517 /* Look through the relocs for a section during the first phase, and
2518 calculate needed space in the global offset table, procedure
2519 linkage table, and dynamic reloc sections. */
2522 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2524 struct bfd_link_info
*info
;
2526 const Elf_Internal_Rela
*relocs
;
2528 struct ppc_link_hash_table
*htab
;
2529 Elf_Internal_Shdr
*symtab_hdr
;
2530 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2531 const Elf_Internal_Rela
*rel
;
2532 const Elf_Internal_Rela
*rel_end
;
2534 asection
**opd_sym_map
;
2536 if (info
->relocateable
)
2539 htab
= ppc_hash_table (info
);
2540 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2542 sym_hashes
= elf_sym_hashes (abfd
);
2543 sym_hashes_end
= (sym_hashes
2544 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
2545 - symtab_hdr
->sh_info
);
2549 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
2551 /* Garbage collection needs some extra help with .opd sections.
2552 We don't want to necessarily keep everything referenced by
2553 relocs in .opd, as that would keep all functions. Instead,
2554 if we reference an .opd symbol (a function descriptor), we
2555 want to keep the function code symbol's section. This is
2556 easy for global symbols, but for local syms we need to keep
2557 information about the associated function section. Later, if
2558 edit_opd deletes entries, we'll use this array to adjust
2559 local syms in .opd. */
2561 asection
*func_section
;
2566 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
2567 opd_sym_map
= (asection
**) bfd_zalloc (abfd
, amt
);
2568 if (opd_sym_map
== NULL
)
2570 elf_section_data (sec
)->tdata
= opd_sym_map
;
2573 if (htab
->elf
.dynobj
== NULL
)
2574 htab
->elf
.dynobj
= abfd
;
2575 if (htab
->sfpr
== NULL
2576 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2579 rel_end
= relocs
+ sec
->reloc_count
;
2580 for (rel
= relocs
; rel
< rel_end
; rel
++)
2582 unsigned long r_symndx
;
2583 struct elf_link_hash_entry
*h
;
2584 enum elf_ppc_reloc_type r_type
;
2586 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2587 if (r_symndx
< symtab_hdr
->sh_info
)
2590 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2592 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2595 /* GOT16 relocations */
2597 case R_PPC64_GOT16_DS
:
2598 case R_PPC64_GOT16_HA
:
2599 case R_PPC64_GOT16_HI
:
2600 case R_PPC64_GOT16_LO
:
2601 case R_PPC64_GOT16_LO_DS
:
2603 /* This symbol requires a global offset table entry. */
2604 if (htab
->sgot
== NULL
2605 && !create_got_section (htab
->elf
.dynobj
, info
))
2610 h
->got
.refcount
+= 1;
2614 bfd_signed_vma
*local_got_refcounts
;
2616 /* This is a global offset table entry for a local symbol. */
2617 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2618 if (local_got_refcounts
== NULL
)
2622 size
= symtab_hdr
->sh_info
;
2623 size
*= sizeof (bfd_signed_vma
);
2624 local_got_refcounts
= ((bfd_signed_vma
*)
2625 bfd_zalloc (abfd
, size
));
2626 if (local_got_refcounts
== NULL
)
2628 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2630 local_got_refcounts
[r_symndx
] += 1;
2634 case R_PPC64_PLT16_HA
:
2635 case R_PPC64_PLT16_HI
:
2636 case R_PPC64_PLT16_LO
:
2639 /* This symbol requires a procedure linkage table entry. We
2640 actually build the entry in adjust_dynamic_symbol,
2641 because this might be a case of linking PIC code without
2642 linking in any dynamic objects, in which case we don't
2643 need to generate a procedure linkage table after all. */
2646 /* It does not make sense to have a procedure linkage
2647 table entry for a local symbol. */
2648 bfd_set_error (bfd_error_bad_value
);
2652 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2653 h
->plt
.refcount
+= 1;
2654 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2657 /* The following relocations don't need to propagate the
2658 relocation if linking a shared object since they are
2659 section relative. */
2660 case R_PPC64_SECTOFF
:
2661 case R_PPC64_SECTOFF_LO
:
2662 case R_PPC64_SECTOFF_HI
:
2663 case R_PPC64_SECTOFF_HA
:
2664 case R_PPC64_SECTOFF_DS
:
2665 case R_PPC64_SECTOFF_LO_DS
:
2667 case R_PPC64_TOC16_LO
:
2668 case R_PPC64_TOC16_HI
:
2669 case R_PPC64_TOC16_HA
:
2670 case R_PPC64_TOC16_DS
:
2671 case R_PPC64_TOC16_LO_DS
:
2674 /* This relocation describes the C++ object vtable hierarchy.
2675 Reconstruct it for later use during GC. */
2676 case R_PPC64_GNU_VTINHERIT
:
2677 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2681 /* This relocation describes which C++ vtable entries are actually
2682 used. Record for later use during GC. */
2683 case R_PPC64_GNU_VTENTRY
:
2684 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2689 case R_PPC64_REL14_BRTAKEN
:
2690 case R_PPC64_REL14_BRNTAKEN
:
2691 htab
->has_14bit_branch
= 1;
2696 && h
->root
.root
.string
[0] == '.'
2697 && h
->root
.root
.string
[1] != 0)
2699 /* We may need a .plt entry if the function this reloc
2700 refers to is in a shared lib. */
2701 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2702 h
->plt
.refcount
+= 1;
2703 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2707 case R_PPC64_ADDR64
:
2708 if (opd_sym_map
!= NULL
2710 && h
->root
.root
.string
[0] == '.'
2711 && h
->root
.root
.string
[1] != 0)
2713 struct elf_link_hash_entry
*fdh
;
2715 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2716 false, false, false);
2719 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2720 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2721 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2722 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2725 if (opd_sym_map
!= NULL
2727 && rel
+ 1 < rel_end
2728 && ((enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
)
2733 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
2738 opd_sym_map
[rel
->r_offset
/ 24] = s
;
2744 case R_PPC64_ADDR14
:
2745 case R_PPC64_ADDR14_BRNTAKEN
:
2746 case R_PPC64_ADDR14_BRTAKEN
:
2747 case R_PPC64_ADDR16
:
2748 case R_PPC64_ADDR16_DS
:
2749 case R_PPC64_ADDR16_HA
:
2750 case R_PPC64_ADDR16_HI
:
2751 case R_PPC64_ADDR16_HIGHER
:
2752 case R_PPC64_ADDR16_HIGHERA
:
2753 case R_PPC64_ADDR16_HIGHEST
:
2754 case R_PPC64_ADDR16_HIGHESTA
:
2755 case R_PPC64_ADDR16_LO
:
2756 case R_PPC64_ADDR16_LO_DS
:
2757 case R_PPC64_ADDR24
:
2758 case R_PPC64_ADDR30
:
2759 case R_PPC64_ADDR32
:
2760 case R_PPC64_UADDR16
:
2761 case R_PPC64_UADDR32
:
2762 case R_PPC64_UADDR64
:
2764 /* Don't propagate .opd relocs. */
2765 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
2768 /* If we are creating a shared library, and this is a reloc
2769 against a global symbol, or a non PC relative reloc
2770 against a local symbol, then we need to copy the reloc
2771 into the shared library. However, if we are linking with
2772 -Bsymbolic, we do not need to copy a reloc against a
2773 global symbol which is defined in an object we are
2774 including in the link (i.e., DEF_REGULAR is set). At
2775 this point we have not seen all the input files, so it is
2776 possible that DEF_REGULAR is not set now but will be set
2777 later (it is never cleared). In case of a weak definition,
2778 DEF_REGULAR may be cleared later by a strong definition in
2779 a shared library. We account for that possibility below by
2780 storing information in the relocs_copied field of the hash
2781 table entry. A similar situation occurs when creating
2782 shared libraries and symbol visibility changes render the
2785 If on the other hand, we are creating an executable, we
2786 may need to keep relocations for symbols satisfied by a
2787 dynamic library if we manage to avoid copy relocs for the
2790 && (sec
->flags
& SEC_ALLOC
) != 0
2791 && (IS_ABSOLUTE_RELOC (r_type
)
2793 && (! info
->symbolic
2794 || h
->root
.type
== bfd_link_hash_defweak
2795 || (h
->elf_link_hash_flags
2796 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2798 && (sec
->flags
& SEC_ALLOC
) != 0
2800 && (h
->root
.type
== bfd_link_hash_defweak
2801 || (h
->elf_link_hash_flags
2802 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2804 struct ppc_dyn_relocs
*p
;
2805 struct ppc_dyn_relocs
**head
;
2807 /* We must copy these reloc types into the output file.
2808 Create a reloc section in dynobj and make room for
2815 name
= (bfd_elf_string_from_elf_section
2817 elf_elfheader (abfd
)->e_shstrndx
,
2818 elf_section_data (sec
)->rel_hdr
.sh_name
));
2822 if (strncmp (name
, ".rela", 5) != 0
2823 || strcmp (bfd_get_section_name (abfd
, sec
),
2826 (*_bfd_error_handler
)
2827 (_("%s: bad relocation section name `%s\'"),
2828 bfd_archive_filename (abfd
), name
);
2829 bfd_set_error (bfd_error_bad_value
);
2832 dynobj
= htab
->elf
.dynobj
;
2833 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2838 sreloc
= bfd_make_section (dynobj
, name
);
2839 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2840 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2841 if ((sec
->flags
& SEC_ALLOC
) != 0)
2842 flags
|= SEC_ALLOC
| SEC_LOAD
;
2844 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2845 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2848 elf_section_data (sec
)->sreloc
= sreloc
;
2851 /* If this is a global symbol, we count the number of
2852 relocations we need for this symbol. */
2855 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
2859 /* Track dynamic relocs needed for local syms too.
2860 We really need local syms available to do this
2864 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
2869 head
= ((struct ppc_dyn_relocs
**)
2870 &elf_section_data (s
)->local_dynrel
);
2874 if (p
== NULL
|| p
->sec
!= sec
)
2876 p
= ((struct ppc_dyn_relocs
*)
2877 bfd_alloc (htab
->elf
.dynobj
,
2878 (bfd_size_type
) sizeof *p
));
2889 if (!IS_ABSOLUTE_RELOC (r_type
))
2902 /* Return the section that should be marked against GC for a given
2906 ppc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2908 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2909 Elf_Internal_Rela
*rel
;
2910 struct elf_link_hash_entry
*h
;
2911 Elf_Internal_Sym
*sym
;
2913 asection
*rsec
= NULL
;
2917 enum elf_ppc_reloc_type r_type
;
2918 struct ppc_link_hash_entry
*fdh
;
2920 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2923 case R_PPC64_GNU_VTINHERIT
:
2924 case R_PPC64_GNU_VTENTRY
:
2928 switch (h
->root
.type
)
2930 case bfd_link_hash_defined
:
2931 case bfd_link_hash_defweak
:
2932 fdh
= (struct ppc_link_hash_entry
*) h
;
2934 /* Function descriptor syms cause the associated
2935 function code sym section to be marked. */
2936 if (fdh
->is_func_descriptor
)
2937 rsec
= fdh
->oh
->root
.u
.def
.section
;
2939 /* Function entry syms return NULL if they are in .opd
2940 and are not ._start (or others undefined on the ld
2941 command line). Thus we avoid marking all function
2942 sections, as all functions are referenced in .opd. */
2943 else if ((fdh
->oh
!= NULL
2944 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
2945 || elf_section_data (sec
)->tdata
== NULL
)
2946 rsec
= h
->root
.u
.def
.section
;
2949 case bfd_link_hash_common
:
2950 rsec
= h
->root
.u
.c
.p
->section
;
2960 asection
**opd_sym_section
;
2962 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2963 opd_sym_section
= (asection
**) elf_section_data (rsec
)->tdata
;
2964 if (opd_sym_section
!= NULL
)
2965 rsec
= opd_sym_section
[sym
->st_value
/ 24];
2966 else if (elf_section_data (sec
)->tdata
!= NULL
)
2973 /* Update the .got, .plt. and dynamic reloc reference counts for the
2974 section being removed. */
2977 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2979 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2981 const Elf_Internal_Rela
*relocs
;
2983 Elf_Internal_Shdr
*symtab_hdr
;
2984 struct elf_link_hash_entry
**sym_hashes
;
2985 bfd_signed_vma
*local_got_refcounts
;
2986 const Elf_Internal_Rela
*rel
, *relend
;
2988 elf_section_data (sec
)->local_dynrel
= NULL
;
2990 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2991 sym_hashes
= elf_sym_hashes (abfd
);
2992 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2994 relend
= relocs
+ sec
->reloc_count
;
2995 for (rel
= relocs
; rel
< relend
; rel
++)
2997 unsigned long r_symndx
;
2998 enum elf_ppc_reloc_type r_type
;
2999 struct elf_link_hash_entry
*h
;
3001 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3002 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3006 case R_PPC64_GOT16_DS
:
3007 case R_PPC64_GOT16_HA
:
3008 case R_PPC64_GOT16_HI
:
3009 case R_PPC64_GOT16_LO
:
3010 case R_PPC64_GOT16_LO_DS
:
3011 if (r_symndx
>= symtab_hdr
->sh_info
)
3013 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3014 if (h
->got
.refcount
> 0)
3019 if (local_got_refcounts
[r_symndx
] > 0)
3020 local_got_refcounts
[r_symndx
]--;
3024 case R_PPC64_PLT16_HA
:
3025 case R_PPC64_PLT16_HI
:
3026 case R_PPC64_PLT16_LO
:
3029 if (r_symndx
>= symtab_hdr
->sh_info
)
3031 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3032 if (h
->plt
.refcount
> 0)
3038 case R_PPC64_REL14_BRNTAKEN
:
3039 case R_PPC64_REL14_BRTAKEN
:
3041 if (r_symndx
>= symtab_hdr
->sh_info
)
3043 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3044 if (h
->plt
.refcount
> 0)
3051 if (r_symndx
>= symtab_hdr
->sh_info
)
3053 struct ppc_link_hash_entry
*eh
;
3054 struct ppc_dyn_relocs
**pp
;
3055 struct ppc_dyn_relocs
*p
;
3057 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3058 eh
= (struct ppc_link_hash_entry
*) h
;
3060 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3072 case R_PPC64_ADDR14
:
3073 case R_PPC64_ADDR14_BRNTAKEN
:
3074 case R_PPC64_ADDR14_BRTAKEN
:
3075 case R_PPC64_ADDR16
:
3076 case R_PPC64_ADDR16_DS
:
3077 case R_PPC64_ADDR16_HA
:
3078 case R_PPC64_ADDR16_HI
:
3079 case R_PPC64_ADDR16_HIGHER
:
3080 case R_PPC64_ADDR16_HIGHERA
:
3081 case R_PPC64_ADDR16_HIGHEST
:
3082 case R_PPC64_ADDR16_HIGHESTA
:
3083 case R_PPC64_ADDR16_LO
:
3084 case R_PPC64_ADDR16_LO_DS
:
3085 case R_PPC64_ADDR24
:
3086 case R_PPC64_ADDR30
:
3087 case R_PPC64_ADDR32
:
3088 case R_PPC64_ADDR64
:
3089 case R_PPC64_UADDR16
:
3090 case R_PPC64_UADDR32
:
3091 case R_PPC64_UADDR64
:
3093 if (r_symndx
>= symtab_hdr
->sh_info
)
3095 struct ppc_link_hash_entry
*eh
;
3096 struct ppc_dyn_relocs
**pp
;
3097 struct ppc_dyn_relocs
*p
;
3099 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3100 eh
= (struct ppc_link_hash_entry
*) h
;
3102 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3120 /* Called via elf_link_hash_traverse to transfer dynamic linking
3121 information on function code symbol entries to their corresponding
3122 function descriptor symbol entries. */
3124 func_desc_adjust (h
, inf
)
3125 struct elf_link_hash_entry
*h
;
3128 struct bfd_link_info
*info
;
3129 struct ppc_link_hash_table
*htab
;
3131 if (h
->root
.type
== bfd_link_hash_indirect
)
3134 if (h
->root
.type
== bfd_link_hash_warning
)
3135 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3137 info
= (struct bfd_link_info
*) inf
;
3138 htab
= ppc_hash_table (info
);
3140 /* If this is a function code symbol, transfer dynamic linking
3141 information to the function descriptor symbol. */
3142 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
3145 if (h
->root
.type
== bfd_link_hash_undefweak
3146 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
3147 htab
->have_undefweak
= true;
3149 if (h
->plt
.refcount
> 0
3150 && h
->root
.root
.string
[0] == '.'
3151 && h
->root
.root
.string
[1] != '\0')
3153 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3154 boolean force_local
;
3156 /* Find the corresponding function descriptor symbol. Create it
3157 as undefined if necessary. */
3160 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3161 false, false, true);
3165 && (h
->root
.type
== bfd_link_hash_undefined
3166 || h
->root
.type
== bfd_link_hash_undefweak
))
3170 struct bfd_link_hash_entry
*bh
;
3172 abfd
= h
->root
.u
.undef
.abfd
;
3173 newsym
= bfd_make_empty_symbol (abfd
);
3174 newsym
->name
= h
->root
.root
.string
+ 1;
3175 newsym
->section
= bfd_und_section_ptr
;
3177 newsym
->flags
= BSF_OBJECT
;
3178 if (h
->root
.type
== bfd_link_hash_undefweak
)
3179 newsym
->flags
|= BSF_WEAK
;
3182 if ( !(_bfd_generic_link_add_one_symbol
3183 (info
, abfd
, newsym
->name
, newsym
->flags
,
3184 newsym
->section
, newsym
->value
, NULL
, false, false, &bh
)))
3188 fdh
= (struct elf_link_hash_entry
*) bh
;
3189 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3193 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
3195 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3196 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3198 if (fdh
->dynindx
== -1)
3199 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
3201 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
3202 & (ELF_LINK_HASH_REF_REGULAR
3203 | ELF_LINK_HASH_REF_DYNAMIC
3204 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3205 | ELF_LINK_NON_GOT_REF
));
3206 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3208 fdh
->plt
.refcount
= h
->plt
.refcount
;
3209 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3211 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3212 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3213 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3216 /* Now that the info is on the function descriptor, clear the
3217 function code sym info. Any function code syms for which we
3218 don't have a definition in a regular file, we force local.
3219 This prevents a shared library from exporting syms that have
3220 been imported from another library. Function code syms that
3221 are really in the library we must leave global to prevent the
3222 linker dragging in a definition from a static library. */
3223 force_local
= (info
->shared
3224 && ((h
->elf_link_hash_flags
3225 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3227 || (fdh
->elf_link_hash_flags
3228 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3229 || (fdh
->elf_link_hash_flags
3230 & ELF_LINK_FORCED_LOCAL
) != 0));
3231 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3237 #define MIN_SAVE_FPR 14
3238 #define MAX_SAVE_FPR 31
3240 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3241 this hook to a) provide some gcc support functions, and b) transfer
3242 dynamic linking information gathered so far on function code symbol
3243 entries, to their corresponding function descriptor symbol entries. */
3245 ppc64_elf_func_desc_adjust (obfd
, info
)
3246 bfd
*obfd ATTRIBUTE_UNUSED
;
3247 struct bfd_link_info
*info
;
3249 struct ppc_link_hash_table
*htab
;
3250 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3251 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3253 struct elf_link_hash_entry
*h
;
3257 htab
= ppc_hash_table (info
);
3259 if (htab
->sfpr
== NULL
)
3260 /* We don't have any relocs. */
3263 /* First provide any missing ._savef* and ._restf* functions. */
3264 memcpy (sym
, "._savef14", 10);
3265 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3267 sym
[7] = i
/ 10 + '0';
3268 sym
[8] = i
% 10 + '0';
3269 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3271 && h
->root
.type
== bfd_link_hash_undefined
)
3273 if (lowest_savef
> i
)
3275 h
->root
.type
= bfd_link_hash_defined
;
3276 h
->root
.u
.def
.section
= htab
->sfpr
;
3277 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3279 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3280 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3284 memcpy (sym
, "._restf14", 10);
3285 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3287 sym
[7] = i
/ 10 + '0';
3288 sym
[8] = i
% 10 + '0';
3289 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3291 && h
->root
.type
== bfd_link_hash_undefined
)
3293 if (lowest_restf
> i
)
3295 h
->root
.type
= bfd_link_hash_defined
;
3296 h
->root
.u
.def
.section
= htab
->sfpr
;
3297 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3298 + (i
- lowest_restf
) * 4);
3300 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3301 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3305 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3307 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3308 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3310 if (htab
->sfpr
->_raw_size
== 0)
3312 if (!htab
->have_undefweak
)
3314 _bfd_strip_section_from_output (info
, htab
->sfpr
);
3318 htab
->sfpr
->_raw_size
= 4;
3321 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3324 htab
->sfpr
->contents
= p
;
3326 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3328 unsigned int fpr
= i
<< 21;
3329 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3330 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3333 if (lowest_savef
<= MAX_SAVE_FPR
)
3335 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3339 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3341 unsigned int fpr
= i
<< 21;
3342 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3343 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3346 if (lowest_restf
<= MAX_SAVE_FPR
3347 || htab
->sfpr
->_raw_size
== 4)
3349 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3355 /* Adjust a symbol defined by a dynamic object and referenced by a
3356 regular object. The current definition is in some section of the
3357 dynamic object, but we're not including those sections. We have to
3358 change the definition to something the rest of the link can
3362 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3363 struct bfd_link_info
*info
;
3364 struct elf_link_hash_entry
*h
;
3366 struct ppc_link_hash_table
*htab
;
3367 struct ppc_link_hash_entry
* eh
;
3368 struct ppc_dyn_relocs
*p
;
3370 unsigned int power_of_two
;
3372 htab
= ppc_hash_table (info
);
3374 /* Deal with function syms. */
3375 if (h
->type
== STT_FUNC
3376 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3378 /* Clear procedure linkage table information for any symbol that
3379 won't need a .plt entry. */
3380 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3381 || h
->plt
.refcount
<= 0
3382 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3384 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3385 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3387 h
->plt
.offset
= (bfd_vma
) -1;
3388 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3393 h
->plt
.offset
= (bfd_vma
) -1;
3395 /* If this is a weak symbol, and there is a real definition, the
3396 processor independent code will have arranged for us to see the
3397 real definition first, and we can just use the same value. */
3398 if (h
->weakdef
!= NULL
)
3400 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3401 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3402 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3403 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3407 /* This is a reference to a symbol defined by a dynamic object which
3408 is not a function. */
3410 /* If we are creating a shared library, we must presume that the
3411 only references to the symbol are via the global offset table.
3412 For such cases we need not do anything here; the relocations will
3413 be handled correctly by relocate_section. */
3417 /* If there are no references to this symbol that do not use the
3418 GOT, we don't need to generate a copy reloc. */
3419 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3422 eh
= (struct ppc_link_hash_entry
*) h
;
3423 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3425 s
= p
->sec
->output_section
;
3426 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3430 /* If we didn't find any dynamic relocs in read-only sections, then
3431 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3434 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3438 /* We must allocate the symbol in our .dynbss section, which will
3439 become part of the .bss section of the executable. There will be
3440 an entry for this symbol in the .dynsym section. The dynamic
3441 object will contain position independent code, so all references
3442 from the dynamic object to this symbol will go through the global
3443 offset table. The dynamic linker will use the .dynsym entry to
3444 determine the address it must put in the global offset table, so
3445 both the dynamic object and the regular object will refer to the
3446 same memory location for the variable. */
3448 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3449 copy the initial value out of the dynamic object and into the
3450 runtime process image. We need to remember the offset into the
3451 .rela.bss section we are going to use. */
3452 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3454 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3455 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3458 /* We need to figure out the alignment required for this symbol. I
3459 have no idea how ELF linkers handle this. */
3460 power_of_two
= bfd_log2 (h
->size
);
3461 if (power_of_two
> 4)
3464 /* Apply the required alignment. */
3466 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3467 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3469 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3473 /* Define the symbol as being at this point in the section. */
3474 h
->root
.u
.def
.section
= s
;
3475 h
->root
.u
.def
.value
= s
->_raw_size
;
3477 /* Increment the section size to make room for the symbol. */
3478 s
->_raw_size
+= h
->size
;
3483 /* If given a function descriptor symbol, hide both the function code
3484 sym and the descriptor. */
3486 ppc64_elf_hide_symbol (info
, h
, force_local
)
3487 struct bfd_link_info
*info
;
3488 struct elf_link_hash_entry
*h
;
3489 boolean force_local
;
3491 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3493 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3495 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3500 struct ppc_link_hash_table
*htab
;
3503 /* We aren't supposed to use alloca in BFD because on
3504 systems which do not have alloca the version in libiberty
3505 calls xmalloc, which might cause the program to crash
3506 when it runs out of memory. This function doesn't have a
3507 return status, so there's no way to gracefully return an
3508 error. So cheat. We know that string[-1] can be safely
3509 dereferenced; It's either a string in an ELF string
3510 table, or allocated in an objalloc structure. */
3512 p
= h
->root
.root
.string
- 1;
3515 htab
= ppc_hash_table (info
);
3516 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3519 /* Unfortunately, if it so happens that the string we were
3520 looking for was allocated immediately before this string,
3521 then we overwrote the string terminator. That's the only
3522 reason the lookup should fail. */
3525 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
3526 while (q
>= h
->root
.root
.string
&& *q
== *p
)
3528 if (q
< h
->root
.root
.string
&& *p
== '.')
3529 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3533 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
3534 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
3538 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3543 edit_opd (obfd
, info
)
3545 struct bfd_link_info
*info
;
3548 unsigned int bfd_indx
;
3550 for (bfd_indx
= 0, ibfd
= info
->input_bfds
;
3552 ibfd
= ibfd
->link_next
, bfd_indx
++)
3555 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3556 Elf_Internal_Shdr
*symtab_hdr
;
3557 Elf_Internal_Sym
*local_syms
;
3558 struct elf_link_hash_entry
**sym_hashes
;
3563 sec
= bfd_get_section_by_name (ibfd
, ".opd");
3567 adjust
= (long *) elf_section_data (sec
)->tdata
;
3568 BFD_ASSERT (adjust
!= NULL
);
3569 memset (adjust
, 0, (size_t) sec
->_raw_size
* sizeof (long) / 24);
3571 if (sec
->output_section
== bfd_abs_section_ptr
)
3574 /* Look through the section relocs. */
3575 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
3579 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3580 sym_hashes
= elf_sym_hashes (ibfd
);
3582 /* Read the relocations. */
3583 relstart
= _bfd_elf64_link_read_relocs (obfd
, sec
, (PTR
) NULL
,
3584 (Elf_Internal_Rela
*) NULL
,
3586 if (relstart
== NULL
)
3589 /* First run through the relocs to check they are sane, and to
3590 determine whether we need to edit this opd section. */
3593 relend
= relstart
+ sec
->reloc_count
;
3594 for (rel
= relstart
; rel
< relend
; rel
++)
3596 enum elf_ppc_reloc_type r_type
;
3597 unsigned long r_symndx
;
3599 struct elf_link_hash_entry
*h
;
3600 Elf_Internal_Sym
*sym
;
3602 /* .opd contains a regular array of 24 byte entries. We're
3603 only interested in the reloc pointing to a function entry
3605 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3606 if (r_type
== R_PPC64_TOC
)
3609 if (r_type
!= R_PPC64_ADDR64
)
3611 (*_bfd_error_handler
)
3612 (_("%s: unexpected reloc type %u in .opd section"),
3613 bfd_archive_filename (ibfd
), r_type
);
3618 if (rel
+ 1 >= relend
)
3620 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
);
3621 if (r_type
!= R_PPC64_TOC
)
3624 if (rel
->r_offset
!= offset
)
3626 /* If someone messes with .opd alignment then after a
3627 "ld -r" we might have padding in the middle of .opd.
3628 Also, there's nothing to prevent someone putting
3629 something silly in .opd with the assembler. No .opd
3630 optimization for them! */
3631 (*_bfd_error_handler
)
3632 (_("%s: .opd is not a regular array of opd entries"),
3633 bfd_archive_filename (ibfd
));
3638 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3642 if (r_symndx
>= symtab_hdr
->sh_info
)
3644 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3645 while (h
->root
.type
== bfd_link_hash_indirect
3646 || h
->root
.type
== bfd_link_hash_warning
)
3647 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3648 if (h
->root
.type
== bfd_link_hash_defined
3649 || h
->root
.type
== bfd_link_hash_defweak
)
3650 sym_sec
= h
->root
.u
.def
.section
;
3654 if (local_syms
== NULL
)
3656 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3657 if (local_syms
== NULL
)
3658 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3659 symtab_hdr
->sh_info
, 0,
3661 if (local_syms
== NULL
)
3662 goto error_free_rel
;
3664 sym
= local_syms
+ r_symndx
;
3665 if ((sym
->st_shndx
!= SHN_UNDEF
3666 && sym
->st_shndx
< SHN_LORESERVE
)
3667 || sym
->st_shndx
> SHN_HIRESERVE
)
3668 sym_sec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
3671 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
3673 (*_bfd_error_handler
)
3674 (_("%s: undefined sym `%s' in .opd section"),
3675 bfd_archive_filename (ibfd
),
3676 h
!= NULL
? h
->root
.root
.string
: "<local symbol>");
3681 /* opd entries are always for functions defined in the
3682 current input bfd. If the symbol isn't defined in the
3683 input bfd, then we won't be using the function in this
3684 bfd; It must be defined in a linkonce section in another
3685 bfd, or is weak. It's also possible that we are
3686 discarding the function due to a linker script /DISCARD/,
3687 which we test for via the output_section. */
3688 if (sym_sec
->owner
!= ibfd
3689 || sym_sec
->output_section
== bfd_abs_section_ptr
)
3697 Elf_Internal_Rela
*write_rel
;
3698 bfd_byte
*rptr
, *wptr
;
3701 /* This seems a waste of time as input .opd sections are all
3702 zeros as generated by gcc, but I suppose there's no reason
3703 this will always be so. We might start putting something in
3704 the third word of .opd entries. */
3705 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
3707 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
3709 || !bfd_get_section_contents (ibfd
, sec
, loc
, (bfd_vma
) 0,
3712 if (local_syms
!= NULL
3713 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3716 if (elf_section_data (sec
)->relocs
!= relstart
)
3720 sec
->contents
= loc
;
3721 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
3724 elf_section_data (sec
)->relocs
= relstart
;
3726 wptr
= sec
->contents
;
3727 rptr
= sec
->contents
;
3728 write_rel
= relstart
;
3731 for (rel
= relstart
; rel
< relend
; rel
++)
3733 if (rel
->r_offset
== offset
)
3735 unsigned long r_symndx
;
3737 struct elf_link_hash_entry
*h
;
3738 Elf_Internal_Sym
*sym
;
3740 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3744 if (r_symndx
>= symtab_hdr
->sh_info
)
3746 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3747 while (h
->root
.type
== bfd_link_hash_indirect
3748 || h
->root
.type
== bfd_link_hash_warning
)
3749 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3750 if (h
->root
.type
== bfd_link_hash_defined
3751 || h
->root
.type
== bfd_link_hash_defweak
)
3752 sym_sec
= h
->root
.u
.def
.section
;
3756 sym
= local_syms
+ r_symndx
;
3757 if ((sym
->st_shndx
!= SHN_UNDEF
3758 && sym
->st_shndx
< SHN_LORESERVE
)
3759 || sym
->st_shndx
> SHN_HIRESERVE
)
3760 sym_sec
= bfd_section_from_elf_index (ibfd
,
3764 skip
= (sym_sec
->owner
!= ibfd
3765 || sym_sec
->output_section
== bfd_abs_section_ptr
);
3768 if (h
!= NULL
&& sym_sec
->owner
== ibfd
)
3770 /* Arrange for the function descriptor sym
3772 struct elf_link_hash_entry
*fdh
;
3773 struct ppc_link_hash_entry
*fh
;
3775 fh
= (struct ppc_link_hash_entry
*) h
;
3776 BFD_ASSERT (fh
->is_func
);
3778 fdh
->root
.u
.def
.value
= 0;
3779 fdh
->root
.u
.def
.section
= sym_sec
;
3784 /* We'll be keeping this opd entry. */
3788 /* Redefine the function descriptor symbol
3789 to this location in the opd section.
3790 We've checked above that opd relocs are
3792 struct elf_link_hash_entry
*fdh
;
3793 struct ppc_link_hash_entry
*fh
;
3795 fh
= (struct ppc_link_hash_entry
*) h
;
3796 BFD_ASSERT (fh
->is_func
);
3798 fdh
->root
.u
.def
.value
= wptr
- sec
->contents
;
3802 /* Local syms are a bit tricky. We could
3803 tweak them as they can be cached, but
3804 we'd need to look through the local syms
3805 for the function descriptor sym which we
3806 don't have at the moment. So keep an
3807 array of adjustments. */
3808 adjust
[rel
->r_offset
/ 24] = wptr
- rptr
;
3812 memcpy (wptr
, rptr
, 24);
3819 /* We need to adjust any reloc offsets to point to the
3820 new opd entries. While we're at it, we may as well
3821 remove redundant relocs. */
3824 rel
->r_offset
+= wptr
- rptr
;
3825 if (write_rel
!= rel
)
3826 memcpy (write_rel
, rel
, sizeof (*rel
));
3831 sec
->_cooked_size
= wptr
- sec
->contents
;
3832 sec
->reloc_count
= write_rel
- relstart
;
3834 else if (elf_section_data (sec
)->relocs
!= relstart
)
3837 if (local_syms
!= NULL
3838 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3840 if (!info
->keep_memory
)
3843 symtab_hdr
->contents
= (unsigned char *) local_syms
;
3850 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3851 will be called from elflink.h. If elflink.h doesn't call our
3852 finish_dynamic_symbol routine, we'll need to do something about
3853 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3854 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3856 && ((INFO)->shared \
3857 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3858 && ((H)->dynindx != -1 \
3859 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3861 /* Allocate space in .plt, .got and associated reloc sections for
3865 allocate_dynrelocs (h
, inf
)
3866 struct elf_link_hash_entry
*h
;
3869 struct bfd_link_info
*info
;
3870 struct ppc_link_hash_table
*htab
;
3872 struct ppc_link_hash_entry
*eh
;
3873 struct ppc_dyn_relocs
*p
;
3875 if (h
->root
.type
== bfd_link_hash_indirect
)
3878 if (h
->root
.type
== bfd_link_hash_warning
)
3879 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3881 info
= (struct bfd_link_info
*) inf
;
3882 htab
= ppc_hash_table (info
);
3884 if (htab
->elf
.dynamic_sections_created
3885 && h
->plt
.refcount
> 0
3886 && h
->dynindx
!= -1)
3888 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
3890 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3892 /* If this is the first .plt entry, make room for the special
3895 if (s
->_raw_size
== 0)
3896 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3898 h
->plt
.offset
= s
->_raw_size
;
3900 /* Make room for this entry. */
3901 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3903 /* Make room for the .glink code. */
3905 if (s
->_raw_size
== 0)
3906 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
3907 /* We need bigger stubs past index 32767. */
3908 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
3910 s
->_raw_size
+= 2*4;
3912 /* We also need to make an entry in the .rela.plt section. */
3914 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3918 h
->plt
.offset
= (bfd_vma
) -1;
3919 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3924 h
->plt
.offset
= (bfd_vma
) -1;
3925 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3928 if (h
->got
.refcount
> 0)
3932 /* Make sure this symbol is output as a dynamic symbol.
3933 Undefined weak syms won't yet be marked as dynamic. */
3934 if (h
->dynindx
== -1
3935 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3937 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3942 h
->got
.offset
= s
->_raw_size
;
3944 dyn
= htab
->elf
.dynamic_sections_created
;
3945 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
3946 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
3949 h
->got
.offset
= (bfd_vma
) -1;
3951 eh
= (struct ppc_link_hash_entry
*) h
;
3952 if (eh
->dyn_relocs
== NULL
)
3955 /* In the shared -Bsymbolic case, discard space allocated for
3956 dynamic pc-relative relocs against symbols which turn out to be
3957 defined in regular objects. For the normal shared case, discard
3958 space for relocs that have become local due to symbol visibility
3963 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3964 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3967 struct ppc_dyn_relocs
**pp
;
3969 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3971 p
->count
-= p
->pc_count
;
3982 /* For the non-shared case, discard space for relocs against
3983 symbols which turn out to need copy relocs or are not
3986 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3987 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3988 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3989 || (htab
->elf
.dynamic_sections_created
3990 && (h
->root
.type
== bfd_link_hash_undefweak
3991 || h
->root
.type
== bfd_link_hash_undefined
))))
3993 /* Make sure this symbol is output as a dynamic symbol.
3994 Undefined weak syms won't yet be marked as dynamic. */
3995 if (h
->dynindx
== -1
3996 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3998 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
4002 /* If that succeeded, we know we'll be keeping all the
4004 if (h
->dynindx
!= -1)
4008 eh
->dyn_relocs
= NULL
;
4013 /* Finally, allocate space. */
4014 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4016 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4017 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4023 /* Find any dynamic relocs that apply to read-only sections. */
4026 readonly_dynrelocs (h
, inf
)
4027 struct elf_link_hash_entry
*h
;
4030 struct ppc_link_hash_entry
*eh
;
4031 struct ppc_dyn_relocs
*p
;
4033 if (h
->root
.type
== bfd_link_hash_warning
)
4034 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4036 eh
= (struct ppc_link_hash_entry
*) h
;
4037 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4039 asection
*s
= p
->sec
->output_section
;
4041 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4043 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4045 info
->flags
|= DF_TEXTREL
;
4047 /* Not an error, just cut short the traversal. */
4054 /* Set the sizes of the dynamic sections. */
4057 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
4058 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4059 struct bfd_link_info
*info
;
4061 struct ppc_link_hash_table
*htab
;
4067 htab
= ppc_hash_table (info
);
4068 dynobj
= htab
->elf
.dynobj
;
4072 if (htab
->elf
.dynamic_sections_created
)
4074 /* Set the contents of the .interp section to the interpreter. */
4077 s
= bfd_get_section_by_name (dynobj
, ".interp");
4080 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4081 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4085 /* Set up .got offsets for local syms, and space for local dynamic
4087 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4089 bfd_signed_vma
*local_got
;
4090 bfd_signed_vma
*end_local_got
;
4091 bfd_size_type locsymcount
;
4092 Elf_Internal_Shdr
*symtab_hdr
;
4095 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4098 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4100 struct ppc_dyn_relocs
*p
;
4102 for (p
= *((struct ppc_dyn_relocs
**)
4103 &elf_section_data (s
)->local_dynrel
);
4107 if (!bfd_is_abs_section (p
->sec
)
4108 && bfd_is_abs_section (p
->sec
->output_section
))
4110 /* Input section has been discarded, either because
4111 it is a copy of a linkonce section or due to
4112 linker script /DISCARD/, so we'll be discarding
4115 else if (p
->count
!= 0)
4117 srel
= elf_section_data (p
->sec
)->sreloc
;
4118 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4119 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4120 info
->flags
|= DF_TEXTREL
;
4125 local_got
= elf_local_got_refcounts (ibfd
);
4129 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4130 locsymcount
= symtab_hdr
->sh_info
;
4131 end_local_got
= local_got
+ locsymcount
;
4133 srel
= htab
->srelgot
;
4134 for (; local_got
< end_local_got
; ++local_got
)
4138 *local_got
= s
->_raw_size
;
4141 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
4144 *local_got
= (bfd_vma
) -1;
4148 if (!edit_opd (output_bfd
, info
))
4151 /* Allocate global sym .plt and .got entries, and space for global
4152 sym dynamic relocs. */
4153 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
4155 /* We now have determined the sizes of the various dynamic sections.
4156 Allocate memory for them. */
4158 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4160 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4163 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
4164 /* These haven't been allocated yet; don't strip. */
4166 else if (s
== htab
->splt
4168 || s
== htab
->sglink
)
4170 /* Strip this section if we don't need it; see the
4173 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4175 if (s
->_raw_size
== 0)
4177 /* If we don't need this section, strip it from the
4178 output file. This is mostly to handle .rela.bss and
4179 .rela.plt. We must create both sections in
4180 create_dynamic_sections, because they must be created
4181 before the linker maps input sections to output
4182 sections. The linker does that before
4183 adjust_dynamic_symbol is called, and it is that
4184 function which decides whether anything needs to go
4185 into these sections. */
4189 if (s
!= htab
->srelplt
)
4192 /* We use the reloc_count field as a counter if we need
4193 to copy relocs into the output file. */
4199 /* It's not one of our sections, so don't allocate space. */
4203 if (s
->_raw_size
== 0)
4205 _bfd_strip_section_from_output (info
, s
);
4209 /* .plt is in the bss section. We don't initialise it. */
4210 if ((s
->flags
& SEC_LOAD
) == 0)
4213 /* Allocate memory for the section contents. We use bfd_zalloc
4214 here in case unused entries are not reclaimed before the
4215 section's contents are written out. This should not happen,
4216 but this way if it does, we get a R_PPC64_NONE reloc instead
4218 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4219 if (s
->contents
== NULL
)
4223 if (htab
->elf
.dynamic_sections_created
)
4225 /* Add some entries to the .dynamic section. We fill in the
4226 values later, in ppc64_elf_finish_dynamic_sections, but we
4227 must add the entries now so that we get the correct size for
4228 the .dynamic section. The DT_DEBUG entry is filled in by the
4229 dynamic linker and used by the debugger. */
4230 #define add_dynamic_entry(TAG, VAL) \
4231 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4235 if (!add_dynamic_entry (DT_DEBUG
, 0))
4239 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
4241 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4242 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4243 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4244 || !add_dynamic_entry (DT_JMPREL
, 0)
4245 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
4251 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
4252 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
4258 if (!add_dynamic_entry (DT_RELA
, 0)
4259 || !add_dynamic_entry (DT_RELASZ
, 0)
4260 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4263 /* If any dynamic relocs apply to a read-only section,
4264 then we need a DT_TEXTREL entry. */
4265 if ((info
->flags
& DF_TEXTREL
) == 0)
4266 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
4269 if ((info
->flags
& DF_TEXTREL
) != 0)
4271 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4276 #undef add_dynamic_entry
4281 /* Determine the type of stub needed, if any, for a call. */
4283 static INLINE
enum ppc_stub_type
4284 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
4285 asection
*input_sec
;
4286 const Elf_Internal_Rela
*rel
;
4287 struct ppc_link_hash_entry
**hash
;
4288 bfd_vma destination
;
4290 struct ppc_link_hash_entry
*h
= *hash
;
4292 bfd_vma branch_offset
;
4293 bfd_vma max_branch_offset
;
4294 unsigned int r_type
;
4299 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
4300 && h
->oh
->dynindx
!= -1)
4302 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
4303 return ppc_stub_plt_call
;
4306 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
4307 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
4308 return ppc_stub_none
;
4311 /* Determine where the call point is. */
4312 location
= (input_sec
->output_offset
4313 + input_sec
->output_section
->vma
4316 branch_offset
= destination
- location
;
4317 r_type
= ELF64_R_TYPE (rel
->r_info
);
4319 /* Determine if a long branch stub is needed. */
4320 max_branch_offset
= 1 << 25;
4321 if (r_type
!= (unsigned int) R_PPC64_REL24
)
4322 max_branch_offset
= 1 << 15;
4324 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
4325 /* We need a stub. Figure out whether a long_branch or plt_branch
4327 return ppc_stub_long_branch
;
4329 return ppc_stub_none
;
4332 /* Build a .plt call stub. */
4335 build_plt_stub (obfd
, p
, offset
, glink
)
4341 #define PPC_LO(v) ((v) & 0xffff)
4342 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4343 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4346 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
4347 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
4349 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
4350 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4351 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4352 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4354 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
4355 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4356 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4358 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
4359 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4360 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
4365 ppc_build_one_stub (gen_entry
, in_arg
)
4366 struct bfd_hash_entry
*gen_entry
;
4369 struct ppc_stub_hash_entry
*stub_entry
;
4370 struct ppc_branch_hash_entry
*br_entry
;
4371 struct bfd_link_info
*info
;
4372 struct ppc_link_hash_table
*htab
;
4381 /* Massage our args to the form they really have. */
4382 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4383 info
= (struct bfd_link_info
*) in_arg
;
4385 htab
= ppc_hash_table (info
);
4386 stub_sec
= stub_entry
->stub_sec
;
4388 /* Make a note of the offset within the stubs for this entry. */
4389 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
4390 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4392 stub_bfd
= stub_sec
->owner
;
4394 switch (stub_entry
->stub_type
)
4396 case ppc_stub_long_branch
:
4397 /* Branches are relative. This is where we are going to. */
4398 off
= (stub_entry
->target_value
4399 + stub_entry
->target_section
->output_offset
4400 + stub_entry
->target_section
->output_section
->vma
);
4402 /* And this is where we are coming from. */
4403 off
-= (stub_entry
->stub_offset
4404 + stub_sec
->output_offset
4405 + stub_sec
->output_section
->vma
);
4407 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
4409 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
4413 case ppc_stub_plt_branch
:
4414 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4415 stub_entry
->root
.string
+ 9,
4417 if (br_entry
== NULL
)
4419 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
4420 stub_entry
->root
.string
+ 9);
4421 htab
->stub_error
= true;
4425 off
= (stub_entry
->target_value
4426 + stub_entry
->target_section
->output_offset
4427 + stub_entry
->target_section
->output_section
->vma
);
4429 bfd_put_64 (htab
->sbrlt
->owner
, off
,
4430 htab
->sbrlt
->contents
+ br_entry
->offset
);
4434 /* Create a reloc for the branch lookup table entry. */
4435 Elf_Internal_Rela rela
;
4436 Elf64_External_Rela
*r
;
4438 rela
.r_offset
= (br_entry
->offset
4439 + htab
->sbrlt
->output_offset
4440 + htab
->sbrlt
->output_section
->vma
);
4441 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
4442 rela
.r_addend
= off
;
4444 r
= (Elf64_External_Rela
*) htab
->srelbrlt
->contents
;
4445 r
+= htab
->srelbrlt
->reloc_count
++;
4446 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, r
);
4449 off
= (br_entry
->offset
4450 + htab
->sbrlt
->output_offset
4451 + htab
->sbrlt
->output_section
->vma
4452 - elf_gp (htab
->sbrlt
->output_section
->owner
)
4455 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4457 (*_bfd_error_handler
)
4458 (_("linkage table error against `%s'"),
4459 stub_entry
->root
.string
);
4460 bfd_set_error (bfd_error_bad_value
);
4461 htab
->stub_error
= true;
4466 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
4467 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
4468 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
4469 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
4473 case ppc_stub_plt_call
:
4474 /* Do the best we can for shared libraries built without
4475 exporting ".foo" for each "foo". This can happen when symbol
4476 versioning scripts strip all bar a subset of symbols. */
4477 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
4478 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
4480 /* Point the symbol at the stub. There may be multiple stubs,
4481 we don't really care; The main thing is to make this sym
4482 defined somewhere. */
4483 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
4484 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
4485 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
4488 /* Now build the stub. */
4489 off
= stub_entry
->h
->elf
.plt
.offset
;
4490 if (off
>= (bfd_vma
) -2)
4493 off
&= ~ (bfd_vma
) 1;
4494 off
+= (htab
->splt
->output_offset
4495 + htab
->splt
->output_section
->vma
4496 - elf_gp (htab
->splt
->output_section
->owner
)
4499 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4501 (*_bfd_error_handler
)
4502 (_("linkage table error against `%s'"),
4503 stub_entry
->h
->elf
.root
.root
.string
);
4504 bfd_set_error (bfd_error_bad_value
);
4505 htab
->stub_error
= true;
4509 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
4518 stub_sec
->_cooked_size
+= size
;
4522 /* As above, but don't actually build the stub. Just bump offset so
4523 we know stub section sizes, and select plt_branch stubs where
4524 long_branch stubs won't do. */
4527 ppc_size_one_stub (gen_entry
, in_arg
)
4528 struct bfd_hash_entry
*gen_entry
;
4531 struct ppc_stub_hash_entry
*stub_entry
;
4532 struct ppc_link_hash_table
*htab
;
4536 /* Massage our args to the form they really have. */
4537 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4538 htab
= (struct ppc_link_hash_table
*) in_arg
;
4540 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
4542 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
4543 off
+= (htab
->splt
->output_offset
4544 + htab
->splt
->output_section
->vma
4545 - elf_gp (htab
->splt
->output_section
->owner
)
4549 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
4554 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4555 stub_entry
->stub_type
= ppc_stub_long_branch
;
4558 off
= (stub_entry
->target_value
4559 + stub_entry
->target_section
->output_offset
4560 + stub_entry
->target_section
->output_section
->vma
);
4561 off
-= (stub_entry
->stub_sec
->_raw_size
4562 + stub_entry
->stub_sec
->output_offset
4563 + stub_entry
->stub_sec
->output_section
->vma
);
4565 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
4567 struct ppc_branch_hash_entry
*br_entry
;
4569 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4570 stub_entry
->root
.string
+ 9,
4572 if (br_entry
== NULL
)
4574 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4575 stub_entry
->root
.string
+ 9);
4576 htab
->stub_error
= true;
4580 if (br_entry
->iter
!= htab
->stub_iteration
)
4582 br_entry
->iter
= htab
->stub_iteration
;
4583 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4584 htab
->sbrlt
->_raw_size
+= 8;
4586 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4591 stub_entry
->stub_sec
->_raw_size
+= size
;
4595 /* Set up various things so that we can make a list of input sections
4596 for each output section included in the link. Returns -1 on error,
4597 0 when no stubs will be needed, and 1 on success. */
4600 ppc64_elf_setup_section_lists (output_bfd
, info
)
4602 struct bfd_link_info
*info
;
4605 int top_id
, top_index
;
4607 asection
**input_list
, **list
;
4609 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4611 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
4612 || htab
->sbrlt
== NULL
)
4615 /* Find the top input section id. */
4616 for (input_bfd
= info
->input_bfds
, top_id
= 0;
4618 input_bfd
= input_bfd
->link_next
)
4620 for (section
= input_bfd
->sections
;
4622 section
= section
->next
)
4624 if (top_id
< section
->id
)
4625 top_id
= section
->id
;
4629 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4630 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4631 if (htab
->stub_group
== NULL
)
4634 /* We can't use output_bfd->section_count here to find the top output
4635 section index as some sections may have been removed, and
4636 _bfd_strip_section_from_output doesn't renumber the indices. */
4637 for (section
= output_bfd
->sections
, top_index
= 0;
4639 section
= section
->next
)
4641 if (top_index
< section
->index
)
4642 top_index
= section
->index
;
4645 htab
->top_index
= top_index
;
4646 amt
= sizeof (asection
*) * (top_index
+ 1);
4647 input_list
= (asection
**) bfd_malloc (amt
);
4648 htab
->input_list
= input_list
;
4649 if (input_list
== NULL
)
4652 /* For sections we aren't interested in, mark their entries with a
4653 value we can check later. */
4654 list
= input_list
+ top_index
;
4656 *list
= bfd_abs_section_ptr
;
4657 while (list
-- != input_list
);
4659 for (section
= output_bfd
->sections
;
4661 section
= section
->next
)
4663 if ((section
->flags
& SEC_CODE
) != 0)
4664 input_list
[section
->index
] = NULL
;
4670 /* The linker repeatedly calls this function for each input section,
4671 in the order that input sections are linked into output sections.
4672 Build lists of input sections to determine groupings between which
4673 we may insert linker stubs. */
4676 ppc64_elf_next_input_section (info
, isec
)
4677 struct bfd_link_info
*info
;
4680 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4682 if (isec
->output_section
->index
<= htab
->top_index
)
4684 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4685 if (*list
!= bfd_abs_section_ptr
)
4687 /* Steal the link_sec pointer for our list. */
4688 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4689 /* This happens to make the list in reverse order,
4690 which is what we want. */
4691 PREV_SEC (isec
) = *list
;
4697 /* See whether we can group stub sections together. Grouping stub
4698 sections may result in fewer stubs. More importantly, we need to
4699 put all .init* and .fini* stubs at the beginning of the .init or
4700 .fini output sections respectively, because glibc splits the
4701 _init and _fini functions into multiple parts. Putting a stub in
4702 the middle of a function is not a good idea. */
4705 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4706 struct ppc_link_hash_table
*htab
;
4707 bfd_size_type stub_group_size
;
4708 boolean stubs_always_before_branch
;
4710 asection
**list
= htab
->input_list
+ htab
->top_index
;
4713 asection
*tail
= *list
;
4714 if (tail
== bfd_abs_section_ptr
)
4716 while (tail
!= NULL
)
4720 bfd_size_type total
;
4723 if (tail
->_cooked_size
)
4724 total
= tail
->_cooked_size
;
4726 total
= tail
->_raw_size
;
4727 while ((prev
= PREV_SEC (curr
)) != NULL
4728 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4732 /* OK, the size from the start of CURR to the end is less
4733 than stub_group_size and thus can be handled by one stub
4734 section. (or the tail section is itself larger than
4735 stub_group_size, in which case we may be toast.) We
4736 should really be keeping track of the total size of stubs
4737 added here, as stubs contribute to the final output
4738 section size. That's a little tricky, and this way will
4739 only break if stubs added make the total size more than
4740 2^25, ie. for the default stub_group_size, if stubs total
4741 more than 2834432 bytes, or over 100000 plt call stubs. */
4744 prev
= PREV_SEC (tail
);
4745 /* Set up this stub group. */
4746 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4748 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4750 /* But wait, there's more! Input sections up to stub_group_size
4751 bytes before the stub section can be handled by it too. */
4752 if (!stubs_always_before_branch
)
4756 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4760 prev
= PREV_SEC (tail
);
4761 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4767 while (list
-- != htab
->input_list
);
4768 free (htab
->input_list
);
4772 /* Determine and set the size of the stub section for a final link.
4774 The basic idea here is to examine all the relocations looking for
4775 PC-relative calls to a target that is unreachable with a "bl"
4779 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
4780 add_stub_section
, layout_sections_again
)
4783 struct bfd_link_info
*info
;
4784 bfd_signed_vma group_size
;
4785 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
4786 void (*layout_sections_again
) PARAMS ((void));
4788 bfd_size_type stub_group_size
;
4789 boolean stubs_always_before_branch
;
4790 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4792 /* Stash our params away. */
4793 htab
->stub_bfd
= stub_bfd
;
4794 htab
->add_stub_section
= add_stub_section
;
4795 htab
->layout_sections_again
= layout_sections_again
;
4796 stubs_always_before_branch
= group_size
< 0;
4798 stub_group_size
= -group_size
;
4800 stub_group_size
= group_size
;
4801 if (stub_group_size
== 1)
4803 /* Default values. */
4804 stub_group_size
= 30720000;
4805 if (htab
->has_14bit_branch
)
4806 stub_group_size
= 30000;
4809 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4814 unsigned int bfd_indx
;
4816 boolean stub_changed
;
4818 htab
->stub_iteration
+= 1;
4819 stub_changed
= false;
4821 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4823 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4825 Elf_Internal_Shdr
*symtab_hdr
;
4827 Elf_Internal_Sym
*local_syms
= NULL
;
4829 /* We'll need the symbol table in a second. */
4830 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4831 if (symtab_hdr
->sh_info
== 0)
4834 /* Walk over each section attached to the input bfd. */
4835 for (section
= input_bfd
->sections
;
4837 section
= section
->next
)
4839 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4841 /* If there aren't any relocs, then there's nothing more
4843 if ((section
->flags
& SEC_RELOC
) == 0
4844 || section
->reloc_count
== 0)
4847 /* If this section is a link-once section that will be
4848 discarded, then don't create any stubs. */
4849 if (section
->output_section
== NULL
4850 || section
->output_section
->owner
!= output_bfd
)
4853 /* Get the relocs. */
4855 = _bfd_elf64_link_read_relocs (input_bfd
, section
, NULL
,
4856 (Elf_Internal_Rela
*) NULL
,
4858 if (internal_relocs
== NULL
)
4859 goto error_ret_free_local
;
4861 /* Now examine each relocation. */
4862 irela
= internal_relocs
;
4863 irelaend
= irela
+ section
->reloc_count
;
4864 for (; irela
< irelaend
; irela
++)
4866 unsigned int r_type
, r_indx
;
4867 enum ppc_stub_type stub_type
;
4868 struct ppc_stub_hash_entry
*stub_entry
;
4871 bfd_vma destination
;
4872 struct ppc_link_hash_entry
*hash
;
4874 const asection
*id_sec
;
4876 r_type
= ELF64_R_TYPE (irela
->r_info
);
4877 r_indx
= ELF64_R_SYM (irela
->r_info
);
4879 if (r_type
>= (unsigned int) R_PPC_max
)
4881 bfd_set_error (bfd_error_bad_value
);
4882 goto error_ret_free_internal
;
4885 /* Only look for stubs on branch instructions. */
4886 if (r_type
!= (unsigned int) R_PPC64_REL24
4887 && r_type
!= (unsigned int) R_PPC64_REL14
4888 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
4889 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
4892 /* Now determine the call target, its name, value,
4898 if (r_indx
< symtab_hdr
->sh_info
)
4900 /* It's a local symbol. */
4901 Elf_Internal_Sym
*sym
;
4902 Elf_Internal_Shdr
*hdr
;
4904 if (local_syms
== NULL
)
4907 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4908 if (local_syms
== NULL
)
4910 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
4911 symtab_hdr
->sh_info
, 0,
4913 if (local_syms
== NULL
)
4914 goto error_ret_free_internal
;
4916 sym
= local_syms
+ r_indx
;
4917 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4918 sym_sec
= hdr
->bfd_section
;
4919 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4920 sym_value
= sym
->st_value
;
4921 destination
= (sym_value
+ irela
->r_addend
4922 + sym_sec
->output_offset
4923 + sym_sec
->output_section
->vma
);
4927 /* It's an external symbol. */
4930 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4931 hash
= ((struct ppc_link_hash_entry
*)
4932 elf_sym_hashes (input_bfd
)[e_indx
]);
4934 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
4935 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
4936 hash
= ((struct ppc_link_hash_entry
*)
4937 hash
->elf
.root
.u
.i
.link
);
4939 if (hash
->elf
.root
.type
== bfd_link_hash_defined
4940 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
4942 sym_sec
= hash
->elf
.root
.u
.def
.section
;
4943 sym_value
= hash
->elf
.root
.u
.def
.value
;
4944 if (sym_sec
->output_section
!= NULL
)
4945 destination
= (sym_value
+ irela
->r_addend
4946 + sym_sec
->output_offset
4947 + sym_sec
->output_section
->vma
);
4949 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
4951 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
4955 bfd_set_error (bfd_error_bad_value
);
4956 goto error_ret_free_internal
;
4960 /* Determine what (if any) linker stub is needed. */
4961 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
4963 if (stub_type
== ppc_stub_none
)
4966 /* Support for grouping stub sections. */
4967 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4969 /* Get the name of this stub. */
4970 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
4972 goto error_ret_free_internal
;
4974 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4975 stub_name
, false, false);
4976 if (stub_entry
!= NULL
)
4978 /* The proper stub has already been created. */
4983 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
4984 if (stub_entry
== NULL
)
4987 error_ret_free_internal
:
4988 if (elf_section_data (section
)->relocs
== NULL
)
4989 free (internal_relocs
);
4990 error_ret_free_local
:
4991 if (local_syms
!= NULL
4992 && (symtab_hdr
->contents
4993 != (unsigned char *) local_syms
))
4998 stub_entry
->target_value
= sym_value
;
4999 stub_entry
->target_section
= sym_sec
;
5000 stub_entry
->stub_type
= stub_type
;
5001 stub_entry
->h
= hash
;
5002 stub_changed
= true;
5005 /* We're done with the internal relocs, free them. */
5006 if (elf_section_data (section
)->relocs
!= internal_relocs
)
5007 free (internal_relocs
);
5010 if (local_syms
!= NULL
5011 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5013 if (!info
->keep_memory
)
5016 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5023 /* OK, we've added some stubs. Find out the new size of the
5025 for (stub_sec
= htab
->stub_bfd
->sections
;
5027 stub_sec
= stub_sec
->next
)
5029 stub_sec
->_raw_size
= 0;
5030 stub_sec
->_cooked_size
= 0;
5032 htab
->sbrlt
->_raw_size
= 0;
5033 htab
->sbrlt
->_cooked_size
= 0;
5035 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
5037 /* Ask the linker to do its stuff. */
5038 (*htab
->layout_sections_again
) ();
5041 /* It would be nice to strip .branch_lt from the output if the
5042 section is empty, but it's too late. If we strip sections here,
5043 the dynamic symbol table is corrupted since the section symbol
5044 for the stripped section isn't written. */
5049 /* Called after we have determined section placement. If sections
5050 move, we'll be called again. Provide a value for TOCstart. */
5053 ppc64_elf_toc (obfd
)
5059 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5060 order. The TOC starts where the first of these sections starts. */
5061 s
= bfd_get_section_by_name (obfd
, ".got");
5063 s
= bfd_get_section_by_name (obfd
, ".toc");
5065 s
= bfd_get_section_by_name (obfd
, ".tocbss");
5067 s
= bfd_get_section_by_name (obfd
, ".plt");
5070 /* This may happen for
5071 o references to TOC base (SYM@toc / TOC[tc0]) without a
5074 o --gc-sections and empty TOC sections
5076 FIXME: Warn user? */
5078 /* Look for a likely section. We probably won't even be
5080 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5081 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
5082 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5085 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5086 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
5087 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5090 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5091 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
5094 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5095 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
5101 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
5106 /* Build all the stubs associated with the current output file.
5107 The stubs are kept in a hash table attached to the main linker
5108 hash table. This function is called via gldelf64ppc_finish. */
5111 ppc64_elf_build_stubs (info
)
5112 struct bfd_link_info
*info
;
5114 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5119 for (stub_sec
= htab
->stub_bfd
->sections
;
5121 stub_sec
= stub_sec
->next
)
5125 /* Allocate memory to hold the linker stubs. */
5126 size
= stub_sec
->_raw_size
;
5129 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
5130 if (stub_sec
->contents
== NULL
)
5133 stub_sec
->_cooked_size
= 0;
5136 if (htab
->splt
!= NULL
)
5140 /* Build the .glink plt call stub. */
5141 plt_r2
= (htab
->splt
->output_offset
5142 + htab
->splt
->output_section
->vma
5143 - elf_gp (htab
->splt
->output_section
->owner
)
5145 p
= htab
->sglink
->contents
;
5146 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
5147 while (p
< htab
->sglink
->contents
+ GLINK_CALL_STUB_SIZE
)
5149 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
5153 /* Build the .glink lazy link call stubs. */
5155 while (p
< htab
->sglink
->contents
+ htab
->sglink
->_raw_size
)
5159 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
5164 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
5166 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
5169 bfd_put_32 (htab
->sglink
->owner
,
5170 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
5174 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
5177 if (htab
->sbrlt
->_raw_size
!= 0)
5179 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
5180 htab
->sbrlt
->_raw_size
);
5181 if (htab
->sbrlt
->contents
== NULL
)
5185 /* Build the stubs as directed by the stub hash table. */
5186 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
5188 for (stub_sec
= htab
->stub_bfd
->sections
;
5190 stub_sec
= stub_sec
->next
)
5192 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
5196 if (stub_sec
!= NULL
5197 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
5199 htab
->stub_error
= true;
5200 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
5203 return !htab
->stub_error
;
5206 /* The RELOCATE_SECTION function is called by the ELF backend linker
5207 to handle the relocations for a section.
5209 The relocs are always passed as Rela structures; if the section
5210 actually uses Rel structures, the r_addend field will always be
5213 This function is responsible for adjust the section contents as
5214 necessary, and (if using Rela relocs and generating a
5215 relocateable output file) adjusting the reloc addend as
5218 This function does not have to worry about setting the reloc
5219 address or the reloc symbol index.
5221 LOCAL_SYMS is a pointer to the swapped in local symbols.
5223 LOCAL_SECTIONS is an array giving the section in the input file
5224 corresponding to the st_shndx field of each local symbol.
5226 The global hash table entry for the global symbols can be found
5227 via elf_sym_hashes (input_bfd).
5229 When generating relocateable output, this function must handle
5230 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5231 going to be the section symbol corresponding to the output
5232 section, which means that the addend must be adjusted
5236 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5237 contents
, relocs
, local_syms
, local_sections
)
5239 struct bfd_link_info
*info
;
5241 asection
*input_section
;
5243 Elf_Internal_Rela
*relocs
;
5244 Elf_Internal_Sym
*local_syms
;
5245 asection
**local_sections
;
5247 struct ppc_link_hash_table
*htab
;
5248 Elf_Internal_Shdr
*symtab_hdr
;
5249 struct elf_link_hash_entry
**sym_hashes
;
5250 Elf_Internal_Rela
*rel
;
5251 Elf_Internal_Rela
*relend
;
5252 bfd_vma
*local_got_offsets
;
5256 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5257 boolean is_power4
= false;
5259 if (info
->relocateable
)
5262 /* Initialize howto table if needed. */
5263 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5266 htab
= ppc_hash_table (info
);
5267 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5268 TOCstart
= elf_gp (output_bfd
);
5269 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5270 sym_hashes
= elf_sym_hashes (input_bfd
);
5271 is_opd
= elf_section_data (input_section
)->tdata
!= NULL
;
5274 relend
= relocs
+ input_section
->reloc_count
;
5275 for (; rel
< relend
; rel
++)
5277 enum elf_ppc_reloc_type r_type
;
5280 bfd_reloc_status_type r
;
5281 Elf_Internal_Sym
*sym
;
5283 struct elf_link_hash_entry
*h
;
5284 struct elf_link_hash_entry
*fdh
;
5285 const char *sym_name
;
5286 unsigned long r_symndx
;
5288 boolean unresolved_reloc
;
5291 struct ppc_stub_hash_entry
*stub_entry
;
5292 bfd_vma max_br_offset
;
5295 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5296 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5297 offset
= rel
->r_offset
;
5298 addend
= rel
->r_addend
;
5299 r
= bfd_reloc_other
;
5300 sym
= (Elf_Internal_Sym
*) 0;
5301 sec
= (asection
*) 0;
5302 h
= (struct elf_link_hash_entry
*) 0;
5303 sym_name
= (const char *) 0;
5304 unresolved_reloc
= false;
5307 if (r_type
== R_PPC64_TOC
)
5309 /* Relocation value is TOC base. Symbol is ignored. */
5310 relocation
= TOCstart
+ TOC_BASE_OFF
;
5312 else if (r_symndx
< symtab_hdr
->sh_info
)
5314 /* It's a local symbol. */
5315 sym
= local_syms
+ r_symndx
;
5316 sec
= local_sections
[r_symndx
];
5317 sym_name
= "<local symbol>";
5319 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
5320 /* rel may have changed, update our copy of addend. */
5321 addend
= rel
->r_addend
;
5323 if (elf_section_data (sec
) != NULL
)
5325 long *opd_sym_adjust
;
5327 opd_sym_adjust
= (long *) elf_section_data (sec
)->tdata
;
5328 if (opd_sym_adjust
!= NULL
&& sym
->st_value
% 24 == 0)
5329 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
5334 /* It's a global symbol. */
5335 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5336 while (h
->root
.type
== bfd_link_hash_indirect
5337 || h
->root
.type
== bfd_link_hash_warning
)
5338 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5339 sym_name
= h
->root
.root
.string
;
5341 if (h
->root
.type
== bfd_link_hash_defined
5342 || h
->root
.type
== bfd_link_hash_defweak
)
5344 sec
= h
->root
.u
.def
.section
;
5345 if (sec
->output_section
== NULL
)
5346 /* Set a flag that will be cleared later if we find a
5347 relocation value for this symbol. output_section
5348 is typically NULL for symbols satisfied by a shared
5350 unresolved_reloc
= true;
5352 relocation
= (h
->root
.u
.def
.value
5353 + sec
->output_section
->vma
5354 + sec
->output_offset
);
5356 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5358 else if (info
->shared
5359 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
5360 && !info
->no_undefined
5361 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5365 if (! ((*info
->callbacks
->undefined_symbol
)
5366 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5367 offset
, (!info
->shared
5368 || info
->no_undefined
5369 || ELF_ST_VISIBILITY (h
->other
)))))
5375 /* First handle relocations that tweak non-addend part of insn. */
5382 /* Branch taken prediction relocations. */
5383 case R_PPC64_ADDR14_BRTAKEN
:
5384 case R_PPC64_REL14_BRTAKEN
:
5385 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5388 /* Branch not taken prediction relocations. */
5389 case R_PPC64_ADDR14_BRNTAKEN
:
5390 case R_PPC64_REL14_BRNTAKEN
:
5391 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
5394 /* Set 'a' bit. This is 0b00010 in BO field for branch
5395 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5396 for branch on CTR insns (BO == 1a00t or 1a01t). */
5397 if ((insn
& (0x14 << 21)) == (0x04 << 21))
5399 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
5407 + input_section
->output_offset
5408 + input_section
->output_section
->vma
);
5410 /* Invert 'y' bit if not the default. */
5411 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
5415 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
5419 /* A REL24 branching to a linkage function is followed by a
5420 nop. We replace the nop with a ld in order to restore
5421 the TOC base pointer. Only calls to shared objects need
5422 to alter the TOC base. These are recognized by their
5423 need for a PLT entry. */
5425 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
5426 && fdh
->plt
.offset
!= (bfd_vma
) -1
5427 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
5428 rel
, htab
)) != NULL
)
5430 boolean can_plt_call
= 0;
5432 if (offset
+ 8 <= input_section
->_cooked_size
)
5434 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
5436 || insn
== CROR_151515
|| insn
== CROR_313131
)
5438 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
5439 contents
+ offset
+ 4);
5446 /* If this is a plain branch rather than a branch
5447 and link, don't require a nop. */
5448 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5449 if ((insn
& 1) == 0)
5455 relocation
= (stub_entry
->stub_offset
5456 + stub_entry
->stub_sec
->output_offset
5457 + stub_entry
->stub_sec
->output_section
->vma
);
5459 unresolved_reloc
= false;
5464 && h
->root
.type
== bfd_link_hash_undefweak
5468 /* Tweak calls to undefined weak functions to point at a
5469 blr. We can thus call a weak function without first
5470 checking whether the function is defined. We have a
5471 blr at the end of .sfpr. */
5472 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
5473 relocation
= (htab
->sfpr
->_raw_size
- 4
5474 + htab
->sfpr
->output_offset
5475 + htab
->sfpr
->output_section
->vma
);
5477 + input_section
->output_offset
5478 + input_section
->output_section
->vma
);
5480 /* But let's not be silly about it. If the blr isn't in
5481 reach, just go to the next instruction. */
5482 if (relocation
- from
+ (1 << 25) >= (1 << 26)
5483 || htab
->sfpr
->_raw_size
== 0)
5484 relocation
= from
+ 4;
5493 (*_bfd_error_handler
)
5494 (_("%s: unknown relocation type %d for symbol %s"),
5495 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5497 bfd_set_error (bfd_error_bad_value
);
5502 case R_PPC_GNU_VTINHERIT
:
5503 case R_PPC_GNU_VTENTRY
:
5506 /* GOT16 relocations. Like an ADDR16 using the symbol's
5507 address in the GOT as relocation value instead of the
5508 symbols value itself. Also, create a GOT entry for the
5509 symbol and put the symbol value there. */
5511 case R_PPC64_GOT16_LO
:
5512 case R_PPC64_GOT16_HI
:
5513 case R_PPC64_GOT16_HA
:
5514 case R_PPC64_GOT16_DS
:
5515 case R_PPC64_GOT16_LO_DS
:
5517 /* Relocation is to the entry for this symbol in the global
5521 if (htab
->sgot
== NULL
)
5528 off
= h
->got
.offset
;
5529 dyn
= htab
->elf
.dynamic_sections_created
;
5530 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5534 || (h
->elf_link_hash_flags
5535 & ELF_LINK_FORCED_LOCAL
))
5536 && (h
->elf_link_hash_flags
5537 & ELF_LINK_HASH_DEF_REGULAR
)))
5539 /* This is actually a static link, or it is a
5540 -Bsymbolic link and the symbol is defined
5541 locally, or the symbol was forced to be local
5542 because of a version file. We must initialize
5543 this entry in the global offset table. Since the
5544 offset must always be a multiple of 8, we use the
5545 least significant bit to record whether we have
5546 initialized it already.
5548 When doing a dynamic link, we create a .rel.got
5549 relocation entry to initialize the value. This
5550 is done in the finish_dynamic_symbol routine. */
5555 bfd_put_64 (output_bfd
, relocation
,
5556 htab
->sgot
->contents
+ off
);
5561 unresolved_reloc
= false;
5565 if (local_got_offsets
== NULL
)
5568 off
= local_got_offsets
[r_symndx
];
5570 /* The offset must always be a multiple of 8. We use
5571 the least significant bit to record whether we have
5572 already processed this entry. */
5577 bfd_put_64 (output_bfd
, relocation
,
5578 htab
->sgot
->contents
+ off
);
5582 Elf_Internal_Rela outrel
;
5583 Elf64_External_Rela
*loc
;
5585 /* We need to generate a R_PPC64_RELATIVE reloc
5586 for the dynamic linker. */
5587 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5588 + htab
->sgot
->output_offset
5590 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5591 outrel
.r_addend
= relocation
;
5592 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5593 loc
+= htab
->srelgot
->reloc_count
++;
5594 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5597 local_got_offsets
[r_symndx
] |= 1;
5601 if (off
>= (bfd_vma
) -2)
5604 relocation
= htab
->sgot
->output_offset
+ off
;
5606 /* TOC base (r2) is TOC start plus 0x8000. */
5607 addend
-= TOC_BASE_OFF
;
5611 case R_PPC64_PLT16_HA
:
5612 case R_PPC64_PLT16_HI
:
5613 case R_PPC64_PLT16_LO
:
5616 /* Relocation is to the entry for this symbol in the
5617 procedure linkage table. */
5619 /* Resolve a PLT reloc against a local symbol directly,
5620 without using the procedure linkage table. */
5624 if (h
->plt
.offset
== (bfd_vma
) -1
5625 || htab
->splt
== NULL
)
5627 /* We didn't make a PLT entry for this symbol. This
5628 happens when statically linking PIC code, or when
5629 using -Bsymbolic. */
5633 relocation
= (htab
->splt
->output_section
->vma
5634 + htab
->splt
->output_offset
5636 unresolved_reloc
= false;
5639 /* TOC16 relocs. We want the offset relative to the TOC base,
5640 which is the address of the start of the TOC plus 0x8000.
5641 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5644 case R_PPC64_TOC16_LO
:
5645 case R_PPC64_TOC16_HI
:
5646 case R_PPC64_TOC16_DS
:
5647 case R_PPC64_TOC16_LO_DS
:
5648 case R_PPC64_TOC16_HA
:
5649 addend
-= TOCstart
+ TOC_BASE_OFF
;
5652 /* Relocate against the beginning of the section. */
5653 case R_PPC64_SECTOFF
:
5654 case R_PPC64_SECTOFF_LO
:
5655 case R_PPC64_SECTOFF_HI
:
5656 case R_PPC64_SECTOFF_DS
:
5657 case R_PPC64_SECTOFF_LO_DS
:
5658 case R_PPC64_SECTOFF_HA
:
5659 if (sec
!= (asection
*) 0)
5660 addend
-= sec
->output_section
->vma
;
5664 case R_PPC64_REL14_BRNTAKEN
:
5665 case R_PPC64_REL14_BRTAKEN
:
5669 /* Relocations that may need to be propagated if this is a
5673 case R_PPC64_ADDR14
:
5674 case R_PPC64_ADDR14_BRNTAKEN
:
5675 case R_PPC64_ADDR14_BRTAKEN
:
5676 case R_PPC64_ADDR16
:
5677 case R_PPC64_ADDR16_DS
:
5678 case R_PPC64_ADDR16_HA
:
5679 case R_PPC64_ADDR16_HI
:
5680 case R_PPC64_ADDR16_HIGHER
:
5681 case R_PPC64_ADDR16_HIGHERA
:
5682 case R_PPC64_ADDR16_HIGHEST
:
5683 case R_PPC64_ADDR16_HIGHESTA
:
5684 case R_PPC64_ADDR16_LO
:
5685 case R_PPC64_ADDR16_LO_DS
:
5686 case R_PPC64_ADDR24
:
5687 case R_PPC64_ADDR30
:
5688 case R_PPC64_ADDR32
:
5689 case R_PPC64_ADDR64
:
5690 case R_PPC64_UADDR16
:
5691 case R_PPC64_UADDR32
:
5692 case R_PPC64_UADDR64
:
5693 /* r_symndx will be zero only for relocs against symbols
5694 from removed linkonce sections, or sections discarded by
5701 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5704 if (NO_OPD_RELOCS
&& is_opd
)
5708 && (IS_ABSOLUTE_RELOC (r_type
)
5711 && (! info
->symbolic
5712 || (h
->elf_link_hash_flags
5713 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5717 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5718 && (((h
->elf_link_hash_flags
5719 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5720 && (h
->elf_link_hash_flags
5721 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5722 || h
->root
.type
== bfd_link_hash_undefweak
5723 || h
->root
.type
== bfd_link_hash_undefined
)))
5725 Elf_Internal_Rela outrel
;
5726 boolean skip
, relocate
;
5728 Elf64_External_Rela
*loc
;
5730 /* When generating a dynamic object, these relocations
5731 are copied into the output file to be resolved at run
5738 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5740 if (outrel
.r_offset
== (bfd_vma
) -1)
5742 else if (outrel
.r_offset
== (bfd_vma
) -2)
5743 skip
= true, relocate
= true;
5744 outrel
.r_offset
+= (input_section
->output_section
->vma
5745 + input_section
->output_offset
);
5746 outrel
.r_addend
= addend
;
5749 memset (&outrel
, 0, sizeof outrel
);
5753 && (!IS_ABSOLUTE_RELOC (r_type
)
5756 || (h
->elf_link_hash_flags
5757 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5758 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5761 /* This symbol is local, or marked to become local,
5762 or this is an opd section reloc which must point
5763 at a local function. */
5764 outrel
.r_addend
+= relocation
;
5766 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5768 if (is_opd
&& h
!= NULL
)
5770 /* Lie about opd entries. This case occurs
5771 when building shared libraries and we
5772 reference a function in another shared
5773 lib. The same thing happens for a weak
5774 definition in an application that's
5775 overridden by a strong definition in a
5776 shared lib. (I believe this is a generic
5777 bug in binutils handling of weak syms.)
5778 In these cases we won't use the opd
5779 entry in this lib. */
5780 unresolved_reloc
= false;
5782 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5788 if (bfd_is_abs_section (sec
))
5790 else if (sec
== NULL
|| sec
->owner
== NULL
)
5792 bfd_set_error (bfd_error_bad_value
);
5799 osec
= sec
->output_section
;
5800 indx
= elf_section_data (osec
)->dynindx
;
5802 /* We are turning this relocation into one
5803 against a section symbol, so subtract out
5804 the output section's address but not the
5805 offset of the input section in the output
5807 outrel
.r_addend
-= osec
->vma
;
5810 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
5814 sreloc
= elf_section_data (input_section
)->sreloc
;
5818 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
5819 loc
+= sreloc
->reloc_count
++;
5820 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5822 /* If this reloc is against an external symbol, it will
5823 be computed at runtime, so there's no need to do
5831 case R_PPC64_GLOB_DAT
:
5832 case R_PPC64_JMP_SLOT
:
5833 case R_PPC64_RELATIVE
:
5834 /* We shouldn't ever see these dynamic relocs in relocatable
5838 case R_PPC64_PLTGOT16
:
5839 case R_PPC64_PLTGOT16_DS
:
5840 case R_PPC64_PLTGOT16_HA
:
5841 case R_PPC64_PLTGOT16_HI
:
5842 case R_PPC64_PLTGOT16_LO
:
5843 case R_PPC64_PLTGOT16_LO_DS
:
5844 case R_PPC64_PLTREL32
:
5845 case R_PPC64_PLTREL64
:
5846 /* These ones haven't been implemented yet. */
5848 (*_bfd_error_handler
)
5849 (_("%s: Relocation %s is not supported for symbol %s."),
5850 bfd_archive_filename (input_bfd
),
5851 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
5853 bfd_set_error (bfd_error_invalid_operation
);
5858 /* Do any further special processing. */
5864 case R_PPC64_ADDR16_HA
:
5865 case R_PPC64_ADDR16_HIGHERA
:
5866 case R_PPC64_ADDR16_HIGHESTA
:
5867 case R_PPC64_PLT16_HA
:
5868 case R_PPC64_TOC16_HA
:
5869 case R_PPC64_SECTOFF_HA
:
5870 /* It's just possible that this symbol is a weak symbol
5871 that's not actually defined anywhere. In that case,
5872 'sec' would be NULL, and we should leave the symbol
5873 alone (it will be set to zero elsewhere in the link). */
5875 /* Add 0x10000 if sign bit in 0:15 is set. */
5876 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
5879 case R_PPC64_ADDR16_DS
:
5880 case R_PPC64_ADDR16_LO_DS
:
5881 case R_PPC64_GOT16_DS
:
5882 case R_PPC64_GOT16_LO_DS
:
5883 case R_PPC64_PLT16_LO_DS
:
5884 case R_PPC64_SECTOFF_DS
:
5885 case R_PPC64_SECTOFF_LO_DS
:
5886 case R_PPC64_TOC16_DS
:
5887 case R_PPC64_TOC16_LO_DS
:
5888 case R_PPC64_PLTGOT16_DS
:
5889 case R_PPC64_PLTGOT16_LO_DS
:
5890 if (((relocation
+ addend
) & 3) != 0)
5892 (*_bfd_error_handler
)
5893 (_("%s: error: relocation %s not a multiple of 4"),
5894 bfd_archive_filename (input_bfd
),
5895 ppc64_elf_howto_table
[(int) r_type
]->name
);
5896 bfd_set_error (bfd_error_bad_value
);
5903 case R_PPC64_REL14_BRNTAKEN
:
5904 case R_PPC64_REL14_BRTAKEN
:
5905 max_br_offset
= 1 << 15;
5909 max_br_offset
= 1 << 25;
5912 /* If the branch is out of reach, then redirect the
5913 call to the local stub for this function. */
5915 + input_section
->output_offset
5916 + input_section
->output_section
->vma
);
5917 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
5918 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
5919 rel
, htab
)) != NULL
)
5921 /* Munge up the value and addend so that we call the stub
5922 rather than the procedure directly. */
5923 relocation
= (stub_entry
->stub_offset
5924 + stub_entry
->stub_sec
->output_offset
5925 + stub_entry
->stub_sec
->output_section
->vma
);
5931 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5932 because such sections are not SEC_ALLOC and thus ld.so will
5933 not process them. */
5934 if (unresolved_reloc
5935 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5936 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5938 (*_bfd_error_handler
)
5939 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5940 bfd_archive_filename (input_bfd
),
5941 bfd_get_section_name (input_bfd
, input_section
),
5942 (long) rel
->r_offset
,
5943 h
->root
.root
.string
);
5947 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
5955 if (r
!= bfd_reloc_ok
)
5961 if (h
->root
.type
== bfd_link_hash_undefweak
5962 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
5964 /* Assume this is a call protected by other code that
5965 detects the symbol is undefined. If this is the case,
5966 we can safely ignore the overflow. If not, the
5967 program is hosed anyway, and a little warning isn't
5973 name
= h
->root
.root
.string
;
5977 name
= bfd_elf_string_from_elf_section (input_bfd
,
5978 symtab_hdr
->sh_link
,
5983 name
= bfd_section_name (input_bfd
, sec
);
5986 if (r
== bfd_reloc_overflow
)
5990 if (!((*info
->callbacks
->reloc_overflow
)
5991 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
5992 rel
->r_addend
, input_bfd
, input_section
, offset
)))
5997 (*_bfd_error_handler
)
5998 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
5999 bfd_archive_filename (input_bfd
),
6000 bfd_get_section_name (input_bfd
, input_section
),
6001 (long) rel
->r_offset
, name
, (int) r
);
6010 /* Finish up dynamic symbol handling. We set the contents of various
6011 dynamic sections here. */
6014 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6016 struct bfd_link_info
*info
;
6017 struct elf_link_hash_entry
*h
;
6018 Elf_Internal_Sym
*sym
;
6020 struct ppc_link_hash_table
*htab
;
6023 htab
= ppc_hash_table (info
);
6024 dynobj
= htab
->elf
.dynobj
;
6026 if (h
->plt
.offset
!= (bfd_vma
) -1
6027 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
6029 Elf_Internal_Rela rela
;
6030 Elf64_External_Rela
*loc
;
6032 /* This symbol has an entry in the procedure linkage table. Set
6035 if (htab
->splt
== NULL
6036 || htab
->srelplt
== NULL
6037 || htab
->sglink
== NULL
)
6040 /* Create a JMP_SLOT reloc to inform the dynamic linker to
6041 fill in the PLT entry. */
6043 rela
.r_offset
= (htab
->splt
->output_section
->vma
6044 + htab
->splt
->output_offset
6046 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
6049 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
6050 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
6051 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6054 if (h
->got
.offset
!= (bfd_vma
) -1)
6056 Elf_Internal_Rela rela
;
6057 Elf64_External_Rela
*loc
;
6059 /* This symbol has an entry in the global offset table. Set it
6062 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
6065 rela
.r_offset
= (htab
->sgot
->output_section
->vma
6066 + htab
->sgot
->output_offset
6067 + (h
->got
.offset
&~ (bfd_vma
) 1));
6069 /* If this is a static link, or it is a -Bsymbolic link and the
6070 symbol is defined locally or was forced to be local because
6071 of a version file, we just want to emit a RELATIVE reloc.
6072 The entry in the global offset table will already have been
6073 initialized in the relocate_section function. */
6077 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6078 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6080 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6081 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6082 rela
.r_addend
= (h
->root
.u
.def
.value
6083 + h
->root
.u
.def
.section
->output_section
->vma
6084 + h
->root
.u
.def
.section
->output_offset
);
6088 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6089 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6090 htab
->sgot
->contents
+ h
->got
.offset
);
6091 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
6095 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
6096 loc
+= htab
->srelgot
->reloc_count
++;
6097 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6100 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6102 Elf_Internal_Rela rela
;
6103 Elf64_External_Rela
*loc
;
6105 /* This symbol needs a copy reloc. Set it up. */
6107 if (h
->dynindx
== -1
6108 || (h
->root
.type
!= bfd_link_hash_defined
6109 && h
->root
.type
!= bfd_link_hash_defweak
)
6110 || htab
->srelbss
== NULL
)
6113 rela
.r_offset
= (h
->root
.u
.def
.value
6114 + h
->root
.u
.def
.section
->output_section
->vma
6115 + h
->root
.u
.def
.section
->output_offset
);
6116 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
6118 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
6119 loc
+= htab
->srelbss
->reloc_count
++;
6120 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6123 /* Mark some specially defined symbols as absolute. */
6124 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
6125 sym
->st_shndx
= SHN_ABS
;
6130 /* Used to decide how to sort relocs in an optimal manner for the
6131 dynamic linker, before writing them out. */
6133 static enum elf_reloc_type_class
6134 ppc64_elf_reloc_type_class (rela
)
6135 const Elf_Internal_Rela
*rela
;
6137 enum elf_ppc_reloc_type r_type
;
6139 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
6142 case R_PPC64_RELATIVE
:
6143 return reloc_class_relative
;
6144 case R_PPC64_JMP_SLOT
:
6145 return reloc_class_plt
;
6147 return reloc_class_copy
;
6149 return reloc_class_normal
;
6153 /* Finish up the dynamic sections. */
6156 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
6158 struct bfd_link_info
*info
;
6160 struct ppc_link_hash_table
*htab
;
6164 htab
= ppc_hash_table (info
);
6165 dynobj
= htab
->elf
.dynobj
;
6166 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6168 if (htab
->elf
.dynamic_sections_created
)
6170 Elf64_External_Dyn
*dyncon
, *dynconend
;
6172 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
6175 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
6176 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6177 for (; dyncon
< dynconend
; dyncon
++)
6179 Elf_Internal_Dyn dyn
;
6182 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6189 case DT_PPC64_GLINK
:
6190 dyn
.d_un
.d_ptr
= (htab
->sglink
->output_section
->vma
6191 + htab
->sglink
->output_offset
);
6195 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6197 dyn
.d_un
.d_ptr
= s
->vma
;
6200 case DT_PPC64_OPDSZ
:
6201 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6203 dyn
.d_un
.d_val
= s
->_raw_size
;
6207 dyn
.d_un
.d_ptr
= (htab
->splt
->output_section
->vma
6208 + htab
->splt
->output_offset
);
6212 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
6213 + htab
->srelplt
->output_offset
);
6217 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
6221 /* Don't count procedure linkage table relocs in the
6222 overall reloc count. */
6223 if (htab
->srelplt
!= NULL
)
6224 dyn
.d_un
.d_val
-= htab
->srelplt
->_raw_size
;
6228 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6232 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
6234 /* Fill in the first entry in the global offset table.
6235 We use it to hold the link-time TOCbase. */
6236 bfd_put_64 (output_bfd
,
6237 elf_gp (output_bfd
) + TOC_BASE_OFF
,
6238 htab
->sgot
->contents
);
6240 /* Set .got entry size. */
6241 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
6244 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
6246 /* Set .plt entry size. */
6247 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
6254 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6255 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6256 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6257 #define TARGET_BIG_NAME "elf64-powerpc"
6258 #define ELF_ARCH bfd_arch_powerpc
6259 #define ELF_MACHINE_CODE EM_PPC64
6260 #define ELF_MAXPAGESIZE 0x10000
6261 #define elf_info_to_howto ppc64_elf_info_to_howto
6263 #ifdef EM_CYGNUS_POWERPC
6264 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6268 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6271 #define elf_backend_want_got_sym 0
6272 #define elf_backend_want_plt_sym 0
6273 #define elf_backend_plt_alignment 3
6274 #define elf_backend_plt_not_loaded 1
6275 #define elf_backend_got_symbol_offset 0
6276 #define elf_backend_got_header_size 8
6277 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6278 #define elf_backend_can_gc_sections 1
6279 #define elf_backend_can_refcount 1
6280 #define elf_backend_rela_normal 1
6282 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6283 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6284 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6285 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6287 #define elf_backend_object_p ppc64_elf_object_p
6288 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6289 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6290 #define elf_backend_check_relocs ppc64_elf_check_relocs
6291 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6292 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6293 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6294 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6295 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6296 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6297 #define elf_backend_relocate_section ppc64_elf_relocate_section
6298 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6299 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6300 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6302 #include "elf64-target.h"