1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
31 #include "elf64-ppc.h"
33 #define USE_RELA /* we want RELA relocations, not REL. */
36 static void ppc_howto_init
38 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
39 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
40 static void ppc64_elf_info_to_howto
41 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf64_Internal_Rela
*dst
));
42 static bfd_reloc_status_type ppc64_elf_ha_reloc
43 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
44 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
47 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
48 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
49 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
50 static bfd_reloc_status_type ppc64_elf_toc_reloc
51 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
52 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
53 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
54 static bfd_reloc_status_type ppc64_elf_toc64_reloc
55 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
56 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
58 static boolean ppc64_elf_set_private_flags
59 PARAMS ((bfd
*, flagword
));
60 static boolean ppc64_elf_merge_private_bfd_data
61 PARAMS ((bfd
*, bfd
*));
62 static boolean ppc64_elf_section_from_shdr
63 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, char *));
66 /* The name of the dynamic interpreter. This is put in the .interp
68 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
70 /* The size in bytes of an entry in the procedure linkage table. */
71 #define PLT_ENTRY_SIZE 24
73 /* The initial size of the plt reserved for the dynamic linker. */
74 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
76 /* TOC base pointers offset from start of TOC. */
77 #define TOC_BASE_OFF (0x8000)
79 /* .plt call stub instructions. */
80 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
81 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
82 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
83 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
84 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
85 /* ld %r11,xxx+16@l(%r12) */
86 #define BCTR 0x4e800420 /* bctr */
88 /* The normal stub is this size. */
89 #define PLT_CALL_STUB_SIZE (7*4)
91 /* But sometimes the .plt entry crosses a 64k boundary, and we need
92 to adjust the high word with this insn. */
93 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
95 /* The .glink fixup call stub is the same as the .plt call stub, but
96 the first instruction restores r2, and the std is omitted. */
97 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
99 /* Always allow this much space. */
100 #define GLINK_CALL_STUB_SIZE (8*4)
103 #define NOP 0x60000000
105 /* Some other nops. */
106 #define CROR_151515 0x4def7b82
107 #define CROR_313131 0x4ffffb82
109 /* .glink entries for the first 32k functions are two instructions. */
110 #define LI_R0_0 0x38000000 /* li %r0,0 */
111 #define B_DOT 0x48000000 /* b . */
113 /* After that, we need two instructions to load the index, followed by
115 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
116 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
118 /* Instructions to save and restore floating point regs. */
119 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
120 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
121 #define BLR 0x4e800020 /* blr */
123 /* Since .opd is an array of descriptors and each entry will end up
124 with identical R_PPC64_RELATIVE relocs, there is really no need to
125 propagate .opd relocs; The dynamic linker should be taught to
126 relocate .opd without reloc entries. FIXME: .opd should be trimmed
128 #ifndef NO_OPD_RELOCS
129 #define NO_OPD_RELOCS 0
132 /* Relocation HOWTO's. */
133 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
135 static reloc_howto_type ppc64_elf_howto_raw
[] = {
136 /* This reloc does nothing. */
137 HOWTO (R_PPC64_NONE
, /* type */
139 2, /* size (0 = byte, 1 = short, 2 = long) */
141 false, /* pc_relative */
143 complain_overflow_bitfield
, /* complain_on_overflow */
144 bfd_elf_generic_reloc
, /* special_function */
145 "R_PPC64_NONE", /* name */
146 false, /* partial_inplace */
149 false), /* pcrel_offset */
151 /* A standard 32 bit relocation. */
152 HOWTO (R_PPC64_ADDR32
, /* type */
154 2, /* size (0 = byte, 1 = short, 2 = long) */
156 false, /* pc_relative */
158 complain_overflow_bitfield
, /* complain_on_overflow */
159 bfd_elf_generic_reloc
, /* special_function */
160 "R_PPC64_ADDR32", /* name */
161 false, /* partial_inplace */
163 0xffffffff, /* dst_mask */
164 false), /* pcrel_offset */
166 /* An absolute 26 bit branch; the lower two bits must be zero.
167 FIXME: we don't check that, we just clear them. */
168 HOWTO (R_PPC64_ADDR24
, /* type */
170 2, /* size (0 = byte, 1 = short, 2 = long) */
172 false, /* pc_relative */
174 complain_overflow_bitfield
, /* complain_on_overflow */
175 bfd_elf_generic_reloc
, /* special_function */
176 "R_PPC64_ADDR24", /* name */
177 false, /* partial_inplace */
179 0x3fffffc, /* dst_mask */
180 false), /* pcrel_offset */
182 /* A standard 16 bit relocation. */
183 HOWTO (R_PPC64_ADDR16
, /* type */
185 1, /* size (0 = byte, 1 = short, 2 = long) */
187 false, /* pc_relative */
189 complain_overflow_bitfield
, /* complain_on_overflow */
190 bfd_elf_generic_reloc
, /* special_function */
191 "R_PPC64_ADDR16", /* name */
192 false, /* partial_inplace */
194 0xffff, /* dst_mask */
195 false), /* pcrel_offset */
197 /* A 16 bit relocation without overflow. */
198 HOWTO (R_PPC64_ADDR16_LO
, /* type */
200 1, /* size (0 = byte, 1 = short, 2 = long) */
202 false, /* pc_relative */
204 complain_overflow_dont
,/* complain_on_overflow */
205 bfd_elf_generic_reloc
, /* special_function */
206 "R_PPC64_ADDR16_LO", /* name */
207 false, /* partial_inplace */
209 0xffff, /* dst_mask */
210 false), /* pcrel_offset */
212 /* Bits 16-31 of an address. */
213 HOWTO (R_PPC64_ADDR16_HI
, /* type */
215 1, /* size (0 = byte, 1 = short, 2 = long) */
217 false, /* pc_relative */
219 complain_overflow_dont
, /* complain_on_overflow */
220 bfd_elf_generic_reloc
, /* special_function */
221 "R_PPC64_ADDR16_HI", /* name */
222 false, /* partial_inplace */
224 0xffff, /* dst_mask */
225 false), /* pcrel_offset */
227 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
228 bits, treated as a signed number, is negative. */
229 HOWTO (R_PPC64_ADDR16_HA
, /* type */
231 1, /* size (0 = byte, 1 = short, 2 = long) */
233 false, /* pc_relative */
235 complain_overflow_dont
, /* complain_on_overflow */
236 ppc64_elf_ha_reloc
, /* special_function */
237 "R_PPC64_ADDR16_HA", /* name */
238 false, /* partial_inplace */
240 0xffff, /* dst_mask */
241 false), /* pcrel_offset */
243 /* An absolute 16 bit branch; the lower two bits must be zero.
244 FIXME: we don't check that, we just clear them. */
245 HOWTO (R_PPC64_ADDR14
, /* type */
247 2, /* size (0 = byte, 1 = short, 2 = long) */
249 false, /* pc_relative */
251 complain_overflow_bitfield
, /* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_PPC64_ADDR14", /* name */
254 false, /* partial_inplace */
256 0xfffc, /* dst_mask */
257 false), /* pcrel_offset */
259 /* An absolute 16 bit branch, for which bit 10 should be set to
260 indicate that the branch is expected to be taken. The lower two
261 bits must be zero. */
262 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
266 false, /* pc_relative */
268 complain_overflow_bitfield
, /* complain_on_overflow */
269 ppc64_elf_brtaken_reloc
, /* special_function */
270 "R_PPC64_ADDR14_BRTAKEN",/* name */
271 false, /* partial_inplace */
273 0xfffc, /* dst_mask */
274 false), /* pcrel_offset */
276 /* An absolute 16 bit branch, for which bit 10 should be set to
277 indicate that the branch is not expected to be taken. The lower
278 two bits must be zero. */
279 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 false, /* pc_relative */
285 complain_overflow_bitfield
, /* complain_on_overflow */
286 ppc64_elf_brtaken_reloc
, /* special_function */
287 "R_PPC64_ADDR14_BRNTAKEN",/* name */
288 false, /* partial_inplace */
290 0xfffc, /* dst_mask */
291 false), /* pcrel_offset */
293 /* A relative 26 bit branch; the lower two bits must be zero. */
294 HOWTO (R_PPC64_REL24
, /* type */
296 2, /* size (0 = byte, 1 = short, 2 = long) */
298 true, /* pc_relative */
300 complain_overflow_signed
, /* complain_on_overflow */
301 bfd_elf_generic_reloc
, /* special_function */
302 "R_PPC64_REL24", /* name */
303 false, /* partial_inplace */
305 0x3fffffc, /* dst_mask */
306 true), /* pcrel_offset */
308 /* A relative 16 bit branch; the lower two bits must be zero. */
309 HOWTO (R_PPC64_REL14
, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 true, /* pc_relative */
315 complain_overflow_signed
, /* complain_on_overflow */
316 bfd_elf_generic_reloc
, /* special_function */
317 "R_PPC64_REL14", /* name */
318 false, /* partial_inplace */
320 0xfffc, /* dst_mask */
321 true), /* pcrel_offset */
323 /* A relative 16 bit branch. Bit 10 should be set to indicate that
324 the branch is expected to be taken. The lower two bits must be
326 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 true, /* pc_relative */
332 complain_overflow_signed
, /* complain_on_overflow */
333 ppc64_elf_brtaken_reloc
, /* special_function */
334 "R_PPC64_REL14_BRTAKEN", /* name */
335 false, /* partial_inplace */
337 0xfffc, /* dst_mask */
338 true), /* pcrel_offset */
340 /* A relative 16 bit branch. Bit 10 should be set to indicate that
341 the branch is not expected to be taken. The lower two bits must
343 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 true, /* pc_relative */
349 complain_overflow_signed
, /* complain_on_overflow */
350 ppc64_elf_brtaken_reloc
, /* special_function */
351 "R_PPC64_REL14_BRNTAKEN",/* name */
352 false, /* partial_inplace */
354 0xfffc, /* dst_mask */
355 true), /* pcrel_offset */
357 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
359 HOWTO (R_PPC64_GOT16
, /* type */
361 1, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_signed
, /* complain_on_overflow */
366 ppc64_elf_unhandled_reloc
, /* special_function */
367 "R_PPC64_GOT16", /* name */
368 false, /* partial_inplace */
370 0xffff, /* dst_mask */
371 false), /* pcrel_offset */
373 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
375 HOWTO (R_PPC64_GOT16_LO
, /* type */
377 1, /* size (0 = byte, 1 = short, 2 = long) */
379 false, /* pc_relative */
381 complain_overflow_dont
, /* complain_on_overflow */
382 ppc64_elf_unhandled_reloc
, /* special_function */
383 "R_PPC64_GOT16_LO", /* name */
384 false, /* partial_inplace */
386 0xffff, /* dst_mask */
387 false), /* pcrel_offset */
389 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
391 HOWTO (R_PPC64_GOT16_HI
, /* type */
393 1, /* size (0 = byte, 1 = short, 2 = long) */
395 false, /* pc_relative */
397 complain_overflow_dont
,/* complain_on_overflow */
398 ppc64_elf_unhandled_reloc
, /* special_function */
399 "R_PPC64_GOT16_HI", /* name */
400 false, /* partial_inplace */
402 0xffff, /* dst_mask */
403 false), /* pcrel_offset */
405 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
407 HOWTO (R_PPC64_GOT16_HA
, /* type */
409 1, /* size (0 = byte, 1 = short, 2 = long) */
411 false, /* pc_relative */
413 complain_overflow_dont
,/* complain_on_overflow */
414 ppc64_elf_unhandled_reloc
, /* special_function */
415 "R_PPC64_GOT16_HA", /* name */
416 false, /* partial_inplace */
418 0xffff, /* dst_mask */
419 false), /* pcrel_offset */
421 /* This is used only by the dynamic linker. The symbol should exist
422 both in the object being run and in some shared library. The
423 dynamic linker copies the data addressed by the symbol from the
424 shared library into the object, because the object being
425 run has to have the data at some particular address. */
426 HOWTO (R_PPC64_COPY
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 false, /* pc_relative */
432 complain_overflow_bitfield
, /* complain_on_overflow */
433 ppc64_elf_unhandled_reloc
, /* special_function */
434 "R_PPC64_COPY", /* name */
435 false, /* partial_inplace */
438 false), /* pcrel_offset */
440 /* Like R_PPC64_ADDR64, but used when setting global offset table
442 HOWTO (R_PPC64_GLOB_DAT
, /* type */
444 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
446 false, /* pc_relative */
448 complain_overflow_dont
, /* complain_on_overflow */
449 ppc64_elf_unhandled_reloc
, /* special_function */
450 "R_PPC64_GLOB_DAT", /* name */
451 false, /* partial_inplace */
453 0xffffffffffffffff, /* dst_mask */
454 false), /* pcrel_offset */
456 /* Created by the link editor. Marks a procedure linkage table
457 entry for a symbol. */
458 HOWTO (R_PPC64_JMP_SLOT
, /* type */
460 0, /* size (0 = byte, 1 = short, 2 = long) */
462 false, /* pc_relative */
464 complain_overflow_dont
, /* complain_on_overflow */
465 ppc64_elf_unhandled_reloc
, /* special_function */
466 "R_PPC64_JMP_SLOT", /* name */
467 false, /* partial_inplace */
470 false), /* pcrel_offset */
472 /* Used only by the dynamic linker. When the object is run, this
473 doubleword64 is set to the load address of the object, plus the
475 HOWTO (R_PPC64_RELATIVE
, /* type */
477 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
479 false, /* pc_relative */
481 complain_overflow_dont
, /* complain_on_overflow */
482 bfd_elf_generic_reloc
, /* special_function */
483 "R_PPC64_RELATIVE", /* name */
484 false, /* partial_inplace */
486 0xffffffffffffffff, /* dst_mask */
487 false), /* pcrel_offset */
489 /* Like R_PPC64_ADDR32, but may be unaligned. */
490 HOWTO (R_PPC64_UADDR32
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 false, /* pc_relative */
496 complain_overflow_bitfield
, /* complain_on_overflow */
497 bfd_elf_generic_reloc
, /* special_function */
498 "R_PPC64_UADDR32", /* name */
499 false, /* partial_inplace */
501 0xffffffff, /* dst_mask */
502 false), /* pcrel_offset */
504 /* Like R_PPC64_ADDR16, but may be unaligned. */
505 HOWTO (R_PPC64_UADDR16
, /* type */
507 1, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield
, /* complain_on_overflow */
512 bfd_elf_generic_reloc
, /* special_function */
513 "R_PPC64_UADDR16", /* name */
514 false, /* partial_inplace */
516 0xffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* 32-bit PC relative. */
520 HOWTO (R_PPC64_REL32
, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 true, /* pc_relative */
526 /* FIXME: Verify. Was complain_overflow_bitfield. */
527 complain_overflow_signed
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_PPC64_REL32", /* name */
530 false, /* partial_inplace */
532 0xffffffff, /* dst_mask */
533 true), /* pcrel_offset */
535 /* 32-bit relocation to the symbol's procedure linkage table. */
536 HOWTO (R_PPC64_PLT32
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_bitfield
, /* complain_on_overflow */
543 ppc64_elf_unhandled_reloc
, /* special_function */
544 "R_PPC64_PLT32", /* name */
545 false, /* partial_inplace */
548 false), /* pcrel_offset */
550 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
551 FIXME: R_PPC64_PLTREL32 not supported. */
552 HOWTO (R_PPC64_PLTREL32
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 true, /* pc_relative */
558 complain_overflow_signed
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_PPC64_PLTREL32", /* name */
561 false, /* partial_inplace */
564 true), /* pcrel_offset */
566 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
568 HOWTO (R_PPC64_PLT16_LO
, /* type */
570 1, /* size (0 = byte, 1 = short, 2 = long) */
572 false, /* pc_relative */
574 complain_overflow_dont
, /* complain_on_overflow */
575 ppc64_elf_unhandled_reloc
, /* special_function */
576 "R_PPC64_PLT16_LO", /* name */
577 false, /* partial_inplace */
579 0xffff, /* dst_mask */
580 false), /* pcrel_offset */
582 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
584 HOWTO (R_PPC64_PLT16_HI
, /* type */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_dont
, /* complain_on_overflow */
591 ppc64_elf_unhandled_reloc
, /* special_function */
592 "R_PPC64_PLT16_HI", /* name */
593 false, /* partial_inplace */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
600 HOWTO (R_PPC64_PLT16_HA
, /* type */
602 1, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_dont
, /* complain_on_overflow */
607 ppc64_elf_unhandled_reloc
, /* special_function */
608 "R_PPC64_PLT16_HA", /* name */
609 false, /* partial_inplace */
611 0xffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* 16-bit section relative relocation. */
615 HOWTO (R_PPC64_SECTOFF
, /* type */
617 1, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_bitfield
, /* complain_on_overflow */
622 ppc64_elf_sectoff_reloc
, /* special_function */
623 "R_PPC64_SECTOFF", /* name */
624 false, /* partial_inplace */
626 0xffff, /* dst_mask */
627 false), /* pcrel_offset */
629 /* Like R_PPC64_SECTOFF, but no overflow warning. */
630 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
632 1, /* size (0 = byte, 1 = short, 2 = long) */
634 false, /* pc_relative */
636 complain_overflow_dont
, /* complain_on_overflow */
637 ppc64_elf_sectoff_reloc
, /* special_function */
638 "R_PPC64_SECTOFF_LO", /* name */
639 false, /* partial_inplace */
641 0xffff, /* dst_mask */
642 false), /* pcrel_offset */
644 /* 16-bit upper half section relative relocation. */
645 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
647 1, /* size (0 = byte, 1 = short, 2 = long) */
649 false, /* pc_relative */
651 complain_overflow_dont
, /* complain_on_overflow */
652 ppc64_elf_sectoff_reloc
, /* special_function */
653 "R_PPC64_SECTOFF_HI", /* name */
654 false, /* partial_inplace */
656 0xffff, /* dst_mask */
657 false), /* pcrel_offset */
659 /* 16-bit upper half adjusted section relative relocation. */
660 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
662 1, /* size (0 = byte, 1 = short, 2 = long) */
664 false, /* pc_relative */
666 complain_overflow_dont
, /* complain_on_overflow */
667 ppc64_elf_sectoff_ha_reloc
, /* special_function */
668 "R_PPC64_SECTOFF_HA", /* name */
669 false, /* partial_inplace */
671 0xffff, /* dst_mask */
672 false), /* pcrel_offset */
674 /* Like R_PPC64_REL24 without touching the two least significant
675 bits. Should have been named R_PPC64_REL30! */
676 HOWTO (R_PPC64_ADDR30
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 true, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 bfd_elf_generic_reloc
, /* special_function */
684 "R_PPC64_ADDR30", /* name */
685 false, /* partial_inplace */
687 0xfffffffc, /* dst_mask */
688 true), /* pcrel_offset */
690 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
692 /* A standard 64-bit relocation. */
693 HOWTO (R_PPC64_ADDR64
, /* type */
695 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
697 false, /* pc_relative */
699 complain_overflow_dont
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_PPC64_ADDR64", /* name */
702 false, /* partial_inplace */
704 0xffffffffffffffff, /* dst_mask */
705 false), /* pcrel_offset */
707 /* The bits 32-47 of an address. */
708 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
710 1, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_dont
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_PPC64_ADDR16_HIGHER", /* name */
717 false, /* partial_inplace */
719 0xffff, /* dst_mask */
720 false), /* pcrel_offset */
722 /* The bits 32-47 of an address, plus 1 if the contents of the low
723 16 bits, treated as a signed number, is negative. */
724 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
726 1, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_dont
, /* complain_on_overflow */
731 ppc64_elf_ha_reloc
, /* special_function */
732 "R_PPC64_ADDR16_HIGHERA", /* name */
733 false, /* partial_inplace */
735 0xffff, /* dst_mask */
736 false), /* pcrel_offset */
738 /* The bits 48-63 of an address. */
739 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
741 1, /* size (0 = byte, 1 = short, 2 = long) */
743 false, /* pc_relative */
745 complain_overflow_dont
, /* complain_on_overflow */
746 bfd_elf_generic_reloc
, /* special_function */
747 "R_PPC64_ADDR16_HIGHEST", /* name */
748 false, /* partial_inplace */
750 0xffff, /* dst_mask */
751 false), /* pcrel_offset */
753 /* The bits 48-63 of an address, plus 1 if the contents of the low
754 16 bits, treated as a signed number, is negative. */
755 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_dont
, /* complain_on_overflow */
762 ppc64_elf_ha_reloc
, /* special_function */
763 "R_PPC64_ADDR16_HIGHESTA", /* name */
764 false, /* partial_inplace */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* Like ADDR64, but may be unaligned. */
770 HOWTO (R_PPC64_UADDR64
, /* type */
772 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
774 false, /* pc_relative */
776 complain_overflow_dont
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 "R_PPC64_UADDR64", /* name */
779 false, /* partial_inplace */
781 0xffffffffffffffff, /* dst_mask */
782 false), /* pcrel_offset */
784 /* 64-bit relative relocation. */
785 HOWTO (R_PPC64_REL64
, /* type */
787 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
789 true, /* pc_relative */
791 complain_overflow_dont
, /* complain_on_overflow */
792 bfd_elf_generic_reloc
, /* special_function */
793 "R_PPC64_REL64", /* name */
794 false, /* partial_inplace */
796 0xffffffffffffffff, /* dst_mask */
797 true), /* pcrel_offset */
799 /* 64-bit relocation to the symbol's procedure linkage table. */
800 HOWTO (R_PPC64_PLT64
, /* type */
802 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
804 false, /* pc_relative */
806 complain_overflow_dont
, /* complain_on_overflow */
807 ppc64_elf_unhandled_reloc
, /* special_function */
808 "R_PPC64_PLT64", /* name */
809 false, /* partial_inplace */
812 false), /* pcrel_offset */
814 /* 64-bit PC relative relocation to the symbol's procedure linkage
816 /* FIXME: R_PPC64_PLTREL64 not supported. */
817 HOWTO (R_PPC64_PLTREL64
, /* type */
819 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
821 true, /* pc_relative */
823 complain_overflow_dont
, /* complain_on_overflow */
824 ppc64_elf_unhandled_reloc
, /* special_function */
825 "R_PPC64_PLTREL64", /* name */
826 false, /* partial_inplace */
829 true), /* pcrel_offset */
831 /* 16 bit TOC-relative relocation. */
833 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
834 HOWTO (R_PPC64_TOC16
, /* type */
836 1, /* size (0 = byte, 1 = short, 2 = long) */
838 false, /* pc_relative */
840 complain_overflow_signed
, /* complain_on_overflow */
841 ppc64_elf_toc_reloc
, /* special_function */
842 "R_PPC64_TOC16", /* name */
843 false, /* partial_inplace */
845 0xffff, /* dst_mask */
846 false), /* pcrel_offset */
848 /* 16 bit TOC-relative relocation without overflow. */
850 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
851 HOWTO (R_PPC64_TOC16_LO
, /* type */
853 1, /* size (0 = byte, 1 = short, 2 = long) */
855 false, /* pc_relative */
857 complain_overflow_dont
, /* complain_on_overflow */
858 ppc64_elf_toc_reloc
, /* special_function */
859 "R_PPC64_TOC16_LO", /* name */
860 false, /* partial_inplace */
862 0xffff, /* dst_mask */
863 false), /* pcrel_offset */
865 /* 16 bit TOC-relative relocation, high 16 bits. */
867 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
868 HOWTO (R_PPC64_TOC16_HI
, /* type */
870 1, /* size (0 = byte, 1 = short, 2 = long) */
872 false, /* pc_relative */
874 complain_overflow_dont
, /* complain_on_overflow */
875 ppc64_elf_toc_reloc
, /* special_function */
876 "R_PPC64_TOC16_HI", /* name */
877 false, /* partial_inplace */
879 0xffff, /* dst_mask */
880 false), /* pcrel_offset */
882 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
883 contents of the low 16 bits, treated as a signed number, is
886 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
887 HOWTO (R_PPC64_TOC16_HA
, /* type */
889 1, /* size (0 = byte, 1 = short, 2 = long) */
891 false, /* pc_relative */
893 complain_overflow_dont
, /* complain_on_overflow */
894 ppc64_elf_toc_ha_reloc
, /* special_function */
895 "R_PPC64_TOC16_HA", /* name */
896 false, /* partial_inplace */
898 0xffff, /* dst_mask */
899 false), /* pcrel_offset */
901 /* 64-bit relocation; insert value of TOC base (.TOC.). */
903 /* R_PPC64_TOC 51 doubleword64 .TOC. */
904 HOWTO (R_PPC64_TOC
, /* type */
906 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
908 false, /* pc_relative */
910 complain_overflow_bitfield
, /* complain_on_overflow */
911 ppc64_elf_toc64_reloc
, /* special_function */
912 "R_PPC64_TOC", /* name */
913 false, /* partial_inplace */
915 0xffffffffffffffff, /* dst_mask */
916 false), /* pcrel_offset */
918 /* Like R_PPC64_GOT16, but also informs the link editor that the
919 value to relocate may (!) refer to a PLT entry which the link
920 editor (a) may replace with the symbol value. If the link editor
921 is unable to fully resolve the symbol, it may (b) create a PLT
922 entry and store the address to the new PLT entry in the GOT.
923 This permits lazy resolution of function symbols at run time.
924 The link editor may also skip all of this and just (c) emit a
925 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
926 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
927 HOWTO (R_PPC64_PLTGOT16
, /* type */
929 1, /* size (0 = byte, 1 = short, 2 = long) */
931 false, /* pc_relative */
933 complain_overflow_signed
, /* complain_on_overflow */
934 ppc64_elf_unhandled_reloc
, /* special_function */
935 "R_PPC64_PLTGOT16", /* name */
936 false, /* partial_inplace */
938 0xffff, /* dst_mask */
939 false), /* pcrel_offset */
941 /* Like R_PPC64_PLTGOT16, but without overflow. */
942 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
943 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
945 1, /* size (0 = byte, 1 = short, 2 = long) */
947 false, /* pc_relative */
949 complain_overflow_dont
, /* complain_on_overflow */
950 ppc64_elf_unhandled_reloc
, /* special_function */
951 "R_PPC64_PLTGOT16_LO", /* name */
952 false, /* partial_inplace */
954 0xffff, /* dst_mask */
955 false), /* pcrel_offset */
957 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
958 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
959 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
961 1, /* size (0 = byte, 1 = short, 2 = long) */
963 false, /* pc_relative */
965 complain_overflow_dont
, /* complain_on_overflow */
966 ppc64_elf_unhandled_reloc
, /* special_function */
967 "R_PPC64_PLTGOT16_HI", /* name */
968 false, /* partial_inplace */
970 0xffff, /* dst_mask */
971 false), /* pcrel_offset */
973 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
974 1 if the contents of the low 16 bits, treated as a signed number,
976 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
977 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
979 1, /* size (0 = byte, 1 = short, 2 = long) */
981 false, /* pc_relative */
983 complain_overflow_dont
,/* complain_on_overflow */
984 ppc64_elf_unhandled_reloc
, /* special_function */
985 "R_PPC64_PLTGOT16_HA", /* name */
986 false, /* partial_inplace */
988 0xffff, /* dst_mask */
989 false), /* pcrel_offset */
991 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
992 HOWTO (R_PPC64_ADDR16_DS
, /* type */
994 1, /* size (0 = byte, 1 = short, 2 = long) */
996 false, /* pc_relative */
998 complain_overflow_bitfield
, /* complain_on_overflow */
999 bfd_elf_generic_reloc
, /* special_function */
1000 "R_PPC64_ADDR16_DS", /* name */
1001 false, /* partial_inplace */
1003 0xfffc, /* dst_mask */
1004 false), /* pcrel_offset */
1006 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1007 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1009 1, /* size (0 = byte, 1 = short, 2 = long) */
1011 false, /* pc_relative */
1013 complain_overflow_dont
,/* complain_on_overflow */
1014 bfd_elf_generic_reloc
, /* special_function */
1015 "R_PPC64_ADDR16_LO_DS",/* name */
1016 false, /* partial_inplace */
1018 0xfffc, /* dst_mask */
1019 false), /* pcrel_offset */
1021 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1022 HOWTO (R_PPC64_GOT16_DS
, /* type */
1024 1, /* size (0 = byte, 1 = short, 2 = long) */
1026 false, /* pc_relative */
1028 complain_overflow_signed
, /* complain_on_overflow */
1029 ppc64_elf_unhandled_reloc
, /* special_function */
1030 "R_PPC64_GOT16_DS", /* name */
1031 false, /* partial_inplace */
1033 0xfffc, /* dst_mask */
1034 false), /* pcrel_offset */
1036 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1037 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1039 1, /* size (0 = byte, 1 = short, 2 = long) */
1041 false, /* pc_relative */
1043 complain_overflow_dont
, /* complain_on_overflow */
1044 ppc64_elf_unhandled_reloc
, /* special_function */
1045 "R_PPC64_GOT16_LO_DS", /* name */
1046 false, /* partial_inplace */
1048 0xfffc, /* dst_mask */
1049 false), /* pcrel_offset */
1051 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1052 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1054 1, /* size (0 = byte, 1 = short, 2 = long) */
1056 false, /* pc_relative */
1058 complain_overflow_dont
, /* complain_on_overflow */
1059 ppc64_elf_unhandled_reloc
, /* special_function */
1060 "R_PPC64_PLT16_LO_DS", /* name */
1061 false, /* partial_inplace */
1063 0xfffc, /* dst_mask */
1064 false), /* pcrel_offset */
1066 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1067 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1069 1, /* size (0 = byte, 1 = short, 2 = long) */
1071 false, /* pc_relative */
1073 complain_overflow_bitfield
, /* complain_on_overflow */
1074 ppc64_elf_sectoff_reloc
, /* special_function */
1075 "R_PPC64_SECTOFF_DS", /* name */
1076 false, /* partial_inplace */
1078 0xfffc, /* dst_mask */
1079 false), /* pcrel_offset */
1081 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1082 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1084 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 false, /* pc_relative */
1088 complain_overflow_dont
, /* complain_on_overflow */
1089 ppc64_elf_sectoff_reloc
, /* special_function */
1090 "R_PPC64_SECTOFF_LO_DS",/* name */
1091 false, /* partial_inplace */
1093 0xfffc, /* dst_mask */
1094 false), /* pcrel_offset */
1096 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1097 HOWTO (R_PPC64_TOC16_DS
, /* type */
1099 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 false, /* pc_relative */
1103 complain_overflow_signed
, /* complain_on_overflow */
1104 ppc64_elf_toc_reloc
, /* special_function */
1105 "R_PPC64_TOC16_DS", /* name */
1106 false, /* partial_inplace */
1108 0xfffc, /* dst_mask */
1109 false), /* pcrel_offset */
1111 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1112 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1114 1, /* size (0 = byte, 1 = short, 2 = long) */
1116 false, /* pc_relative */
1118 complain_overflow_dont
, /* complain_on_overflow */
1119 ppc64_elf_toc_reloc
, /* special_function */
1120 "R_PPC64_TOC16_LO_DS", /* name */
1121 false, /* partial_inplace */
1123 0xfffc, /* dst_mask */
1124 false), /* pcrel_offset */
1126 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1127 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1128 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1130 1, /* size (0 = byte, 1 = short, 2 = long) */
1132 false, /* pc_relative */
1134 complain_overflow_signed
, /* complain_on_overflow */
1135 ppc64_elf_unhandled_reloc
, /* special_function */
1136 "R_PPC64_PLTGOT16_DS", /* name */
1137 false, /* partial_inplace */
1139 0xfffc, /* dst_mask */
1140 false), /* pcrel_offset */
1142 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1143 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1144 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1146 1, /* size (0 = byte, 1 = short, 2 = long) */
1148 false, /* pc_relative */
1150 complain_overflow_dont
, /* complain_on_overflow */
1151 ppc64_elf_unhandled_reloc
, /* special_function */
1152 "R_PPC64_PLTGOT16_LO_DS",/* name */
1153 false, /* partial_inplace */
1155 0xfffc, /* dst_mask */
1156 false), /* pcrel_offset */
1158 /* GNU extension to record C++ vtable hierarchy. */
1159 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1161 0, /* size (0 = byte, 1 = short, 2 = long) */
1163 false, /* pc_relative */
1165 complain_overflow_dont
, /* complain_on_overflow */
1166 NULL
, /* special_function */
1167 "R_PPC64_GNU_VTINHERIT", /* name */
1168 false, /* partial_inplace */
1171 false), /* pcrel_offset */
1173 /* GNU extension to record C++ vtable member usage. */
1174 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1176 0, /* size (0 = byte, 1 = short, 2 = long) */
1178 false, /* pc_relative */
1180 complain_overflow_dont
, /* complain_on_overflow */
1181 NULL
, /* special_function */
1182 "R_PPC64_GNU_VTENTRY", /* name */
1183 false, /* partial_inplace */
1186 false), /* pcrel_offset */
1190 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1196 unsigned int i
, type
;
1199 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1202 type
= ppc64_elf_howto_raw
[i
].type
;
1203 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1204 / sizeof (ppc64_elf_howto_table
[0])));
1205 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1209 static reloc_howto_type
*
1210 ppc64_elf_reloc_type_lookup (abfd
, code
)
1211 bfd
*abfd ATTRIBUTE_UNUSED
;
1212 bfd_reloc_code_real_type code
;
1214 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1216 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1217 /* Initialize howto table if needed. */
1223 return (reloc_howto_type
*) NULL
;
1225 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1227 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1229 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1231 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1233 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1235 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1237 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1239 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1241 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1243 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1245 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1247 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1249 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1251 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1253 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1255 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1257 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1259 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1261 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1263 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1265 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1267 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1269 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1271 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1273 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1275 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1277 case BFD_RELOC_16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1279 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1281 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1283 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1285 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR64
;
1287 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1289 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1291 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1293 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1295 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1297 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1299 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1301 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1303 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1305 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1307 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1309 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1311 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1313 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1315 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1317 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1319 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1321 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1323 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1325 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1327 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1329 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1331 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1333 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1335 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1337 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1339 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1341 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1343 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1345 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1349 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1352 /* Set the howto pointer for a PowerPC ELF reloc. */
1355 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1356 bfd
*abfd ATTRIBUTE_UNUSED
;
1358 Elf64_Internal_Rela
*dst
;
1362 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1363 /* Initialize howto table if needed. */
1366 type
= ELF64_R_TYPE (dst
->r_info
);
1367 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1368 / sizeof (ppc64_elf_howto_table
[0])));
1369 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1372 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1374 static bfd_reloc_status_type
1375 ppc64_elf_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1376 input_section
, output_bfd
, error_message
)
1378 arelent
*reloc_entry
;
1381 asection
*input_section
;
1383 char **error_message
;
1385 /* If this is a relocatable link (output_bfd test tells us), just
1386 call the generic function. Any adjustment will be done at final
1388 if (output_bfd
!= NULL
)
1389 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1390 input_section
, output_bfd
, error_message
);
1392 /* Adjust the addend for sign extension of the low 16 bits.
1393 We won't actually be using the low 16 bits, so trashing them
1395 reloc_entry
->addend
+= 0x8000;
1396 return bfd_reloc_continue
;
1399 static bfd_reloc_status_type
1400 ppc64_elf_brtaken_reloc (abfd
, reloc_entry
, symbol
, data
,
1401 input_section
, output_bfd
, error_message
)
1403 arelent
*reloc_entry
;
1406 asection
*input_section
;
1408 char **error_message
;
1411 enum elf_ppc_reloc_type r_type
;
1412 bfd_size_type octets
;
1413 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1414 boolean is_power4
= false;
1416 /* If this is a relocatable link (output_bfd test tells us), just
1417 call the generic function. Any adjustment will be done at final
1419 if (output_bfd
!= NULL
)
1420 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1421 input_section
, output_bfd
, error_message
);
1423 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1424 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1425 insn
&= ~(0x01 << 21);
1426 r_type
= (enum elf_ppc_reloc_type
) reloc_entry
->howto
->type
;
1427 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1428 || r_type
== R_PPC64_REL14_BRTAKEN
)
1429 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1433 /* Set 'a' bit. This is 0b00010 in BO field for branch
1434 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1435 for branch on CTR insns (BO == 1a00t or 1a01t). */
1436 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1438 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1441 return bfd_reloc_continue
;
1448 if (!bfd_is_com_section (symbol
->section
))
1449 target
= symbol
->value
;
1450 target
+= symbol
->section
->output_section
->vma
;
1451 target
+= symbol
->section
->output_offset
;
1452 target
+= reloc_entry
->addend
;
1454 from
= (reloc_entry
->address
1455 + input_section
->output_offset
1456 + input_section
->output_section
->vma
);
1458 /* Invert 'y' bit if not the default. */
1459 if ((bfd_signed_vma
) (target
- from
) < 0)
1462 bfd_put_32 (abfd
, (bfd_vma
) insn
, (bfd_byte
*) data
+ octets
);
1463 return bfd_reloc_continue
;
1466 static bfd_reloc_status_type
1467 ppc64_elf_sectoff_reloc (abfd
, reloc_entry
, symbol
, data
,
1468 input_section
, output_bfd
, error_message
)
1470 arelent
*reloc_entry
;
1473 asection
*input_section
;
1475 char **error_message
;
1477 /* If this is a relocatable link (output_bfd test tells us), just
1478 call the generic function. Any adjustment will be done at final
1480 if (output_bfd
!= NULL
)
1481 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1482 input_section
, output_bfd
, error_message
);
1484 /* Subtract the symbol section base address. */
1485 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1486 return bfd_reloc_continue
;
1489 static bfd_reloc_status_type
1490 ppc64_elf_sectoff_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1491 input_section
, output_bfd
, error_message
)
1493 arelent
*reloc_entry
;
1496 asection
*input_section
;
1498 char **error_message
;
1500 /* If this is a relocatable link (output_bfd test tells us), just
1501 call the generic function. Any adjustment will be done at final
1503 if (output_bfd
!= NULL
)
1504 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1505 input_section
, output_bfd
, error_message
);
1507 /* Subtract the symbol section base address. */
1508 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1510 /* Adjust the addend for sign extension of the low 16 bits. */
1511 reloc_entry
->addend
+= 0x8000;
1512 return bfd_reloc_continue
;
1515 static bfd_reloc_status_type
1516 ppc64_elf_toc_reloc (abfd
, reloc_entry
, symbol
, data
,
1517 input_section
, output_bfd
, error_message
)
1519 arelent
*reloc_entry
;
1522 asection
*input_section
;
1524 char **error_message
;
1528 /* If this is a relocatable link (output_bfd test tells us), just
1529 call the generic function. Any adjustment will be done at final
1531 if (output_bfd
!= NULL
)
1532 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1533 input_section
, output_bfd
, error_message
);
1535 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1537 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1539 /* Subtract the TOC base address. */
1540 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1541 return bfd_reloc_continue
;
1544 static bfd_reloc_status_type
1545 ppc64_elf_toc_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1546 input_section
, output_bfd
, error_message
)
1548 arelent
*reloc_entry
;
1551 asection
*input_section
;
1553 char **error_message
;
1557 /* If this is a relocatable link (output_bfd test tells us), just
1558 call the generic function. Any adjustment will be done at final
1560 if (output_bfd
!= NULL
)
1561 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1562 input_section
, output_bfd
, error_message
);
1564 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1566 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1568 /* Subtract the TOC base address. */
1569 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1571 /* Adjust the addend for sign extension of the low 16 bits. */
1572 reloc_entry
->addend
+= 0x8000;
1573 return bfd_reloc_continue
;
1576 static bfd_reloc_status_type
1577 ppc64_elf_toc64_reloc (abfd
, reloc_entry
, symbol
, data
,
1578 input_section
, output_bfd
, error_message
)
1580 arelent
*reloc_entry
;
1583 asection
*input_section
;
1585 char **error_message
;
1588 bfd_size_type octets
;
1590 /* If this is a relocatable link (output_bfd test tells us), just
1591 call the generic function. Any adjustment will be done at final
1593 if (output_bfd
!= NULL
)
1594 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1595 input_section
, output_bfd
, error_message
);
1597 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1599 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1601 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1602 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1603 return bfd_reloc_ok
;
1606 static bfd_reloc_status_type
1607 ppc64_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
1608 input_section
, output_bfd
, error_message
)
1610 arelent
*reloc_entry
;
1613 asection
*input_section
;
1615 char **error_message
;
1617 /* If this is a relocatable link (output_bfd test tells us), just
1618 call the generic function. Any adjustment will be done at final
1620 if (output_bfd
!= NULL
)
1621 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1622 input_section
, output_bfd
, error_message
);
1624 if (error_message
!= NULL
)
1626 static char buf
[60];
1627 sprintf (buf
, "generic linker can't handle %s",
1628 reloc_entry
->howto
->name
);
1629 *error_message
= buf
;
1631 return bfd_reloc_dangerous
;
1634 /* Function to set whether a module needs the -mrelocatable bit set. */
1637 ppc64_elf_set_private_flags (abfd
, flags
)
1641 BFD_ASSERT (!elf_flags_init (abfd
)
1642 || elf_elfheader (abfd
)->e_flags
== flags
);
1644 elf_elfheader (abfd
)->e_flags
= flags
;
1645 elf_flags_init (abfd
) = true;
1649 /* Merge backend specific data from an object file to the output
1650 object file when linking. */
1652 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1660 /* Check if we have the same endianess. */
1661 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1662 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1666 if (bfd_big_endian (ibfd
))
1667 msg
= _("%s: compiled for a big endian system and target is little endian");
1669 msg
= _("%s: compiled for a little endian system and target is big endian");
1671 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1673 bfd_set_error (bfd_error_wrong_format
);
1677 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1678 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1681 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1682 old_flags
= elf_elfheader (obfd
)->e_flags
;
1683 if (!elf_flags_init (obfd
))
1685 /* First call, no flags set. */
1686 elf_flags_init (obfd
) = true;
1687 elf_elfheader (obfd
)->e_flags
= new_flags
;
1690 else if (new_flags
== old_flags
)
1691 /* Compatible flags are ok. */
1696 /* Incompatible flags. Warn about -mrelocatable mismatch.
1697 Allow -mrelocatable-lib to be linked with either. */
1699 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1700 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1703 (*_bfd_error_handler
)
1704 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1705 bfd_archive_filename (ibfd
));
1707 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1708 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1711 (*_bfd_error_handler
)
1712 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1713 bfd_archive_filename (ibfd
));
1716 /* The output is -mrelocatable-lib iff both the input files are. */
1717 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1718 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1720 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1721 but each input file is either -mrelocatable or -mrelocatable-lib. */
1722 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1723 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1724 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1725 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1727 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1728 if any module uses it. */
1729 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1731 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1732 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1734 /* Warn about any other mismatches. */
1735 if (new_flags
!= old_flags
)
1738 (*_bfd_error_handler
)
1739 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1740 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1745 bfd_set_error (bfd_error_bad_value
);
1753 /* Handle a PowerPC specific section when reading an object file. This
1754 is called when elfcode.h finds a section with an unknown type. */
1757 ppc64_elf_section_from_shdr (abfd
, hdr
, name
)
1759 Elf64_Internal_Shdr
*hdr
;
1765 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1768 newsect
= hdr
->bfd_section
;
1769 flags
= bfd_get_section_flags (abfd
, newsect
);
1770 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1771 flags
|= SEC_EXCLUDE
;
1773 if (hdr
->sh_type
== SHT_ORDERED
)
1774 flags
|= SEC_SORT_ENTRIES
;
1776 bfd_set_section_flags (abfd
, newsect
, flags
);
1780 /* The following functions are specific to the ELF linker, while
1781 functions above are used generally. Those named ppc64_elf_* are
1782 called by the main ELF linker code. They appear in this file more
1783 or less in the order in which they are called. eg.
1784 ppc64_elf_check_relocs is called early in the link process,
1785 ppc64_elf_finish_dynamic_sections is one of the last functions
1788 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1789 functions have both a function code symbol and a function descriptor
1790 symbol. A call to foo in a relocatable object file looks like:
1797 The function definition in another object file might be:
1801 . .quad .TOC.@tocbase
1807 When the linker resolves the call during a static link, the branch
1808 unsurprisingly just goes to .foo and the .opd information is unused.
1809 If the function definition is in a shared library, things are a little
1810 different: The call goes via a plt call stub, the opd information gets
1811 copied to the plt, and the linker patches the nop.
1819 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1820 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1821 . std 2,40(1) # this is the general idea
1829 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1831 The "reloc ()" notation is supposed to indicate that the linker emits
1832 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1835 What are the difficulties here? Well, firstly, the relocations
1836 examined by the linker in check_relocs are against the function code
1837 sym .foo, while the dynamic relocation in the plt is emitted against
1838 the function descriptor symbol, foo. Somewhere along the line, we need
1839 to carefully copy dynamic link information from one symbol to the other.
1840 Secondly, the generic part of the elf linker will make .foo a dynamic
1841 symbol as is normal for most other backends. We need foo dynamic
1842 instead, at least for an application final link. However, when
1843 creating a shared library containing foo, we need to have both symbols
1844 dynamic so that references to .foo are satisfied during the early
1845 stages of linking. Otherwise the linker might decide to pull in a
1846 definition from some other object, eg. a static library. */
1848 /* The linker needs to keep track of the number of relocs that it
1849 decides to copy as dynamic relocs in check_relocs for each symbol.
1850 This is so that it can later discard them if they are found to be
1851 unnecessary. We store the information in a field extending the
1852 regular ELF linker hash table. */
1854 struct ppc_dyn_relocs
1856 struct ppc_dyn_relocs
*next
;
1858 /* The input section of the reloc. */
1861 /* Total number of relocs copied for the input section. */
1862 bfd_size_type count
;
1864 /* Number of pc-relative relocs copied for the input section. */
1865 bfd_size_type pc_count
;
1868 /* Of those relocs that might be copied as dynamic relocs, this macro
1869 selects between relative and absolute types. */
1871 #define IS_ABSOLUTE_RELOC(RTYPE) \
1872 ((RTYPE) != R_PPC64_REL32 \
1873 && (RTYPE) != R_PPC64_REL64 \
1874 && (RTYPE) != R_PPC64_ADDR30)
1876 /* Section name for stubs is the associated section name plus this
1878 #define STUB_SUFFIX ".stub"
1881 ppc_stub_long_branch:
1882 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1883 destination, but a 24 bit branch in a stub section will reach.
1886 ppc_stub_plt_branch:
1887 Similar to the above, but a 24 bit branch in the stub section won't
1888 reach its destination.
1889 . addis %r12,%r2,xxx@ha
1890 . ld %r11,xxx@l(%r12)
1895 Used to call a function in a shared library.
1896 . addis %r12,%r2,xxx@ha
1898 . ld %r11,xxx+0@l(%r12)
1899 . ld %r2,xxx+8@l(%r12)
1901 . ld %r11,xxx+16@l(%r12)
1905 enum ppc_stub_type
{
1907 ppc_stub_long_branch
,
1908 ppc_stub_plt_branch
,
1912 struct ppc_stub_hash_entry
{
1914 /* Base hash table entry structure. */
1915 struct bfd_hash_entry root
;
1917 /* The stub section. */
1920 /* Offset within stub_sec of the beginning of this stub. */
1921 bfd_vma stub_offset
;
1923 /* Given the symbol's value and its section we can determine its final
1924 value when building the stubs (so the stub knows where to jump. */
1925 bfd_vma target_value
;
1926 asection
*target_section
;
1928 enum ppc_stub_type stub_type
;
1930 /* The symbol table entry, if any, that this was derived from. */
1931 struct ppc_link_hash_entry
*h
;
1933 /* Where this stub is being called from, or, in the case of combined
1934 stub sections, the first input section in the group. */
1938 struct ppc_branch_hash_entry
{
1940 /* Base hash table entry structure. */
1941 struct bfd_hash_entry root
;
1943 /* Offset within .branch_lt. */
1944 unsigned int offset
;
1946 /* Generation marker. */
1950 struct ppc_link_hash_entry
1952 struct elf_link_hash_entry elf
;
1954 /* A pointer to the most recently used stub hash entry against this
1956 struct ppc_stub_hash_entry
*stub_cache
;
1958 /* Track dynamic relocs copied for this symbol. */
1959 struct ppc_dyn_relocs
*dyn_relocs
;
1961 /* Link between function code and descriptor symbols. */
1962 struct elf_link_hash_entry
*oh
;
1964 /* Flag function code and descriptor symbols. */
1965 unsigned int is_func
:1;
1966 unsigned int is_func_descriptor
:1;
1969 /* ppc64 ELF linker hash table. */
1971 struct ppc_link_hash_table
1973 struct elf_link_hash_table elf
;
1975 /* The stub hash table. */
1976 struct bfd_hash_table stub_hash_table
;
1978 /* Another hash table for plt_branch stubs. */
1979 struct bfd_hash_table branch_hash_table
;
1981 /* Linker stub bfd. */
1984 /* Linker call-backs. */
1985 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
1986 void (*layout_sections_again
) PARAMS ((void));
1988 /* Array to keep track of which stub sections have been created, and
1989 information on stub grouping. */
1991 /* This is the section to which stubs in the group will be attached. */
1993 /* The stub section. */
1997 /* Assorted information used by ppc64_elf_size_stubs. */
1998 unsigned int bfd_count
;
2000 asection
**input_list
;
2001 Elf_Internal_Sym
**all_local_syms
;
2003 /* Short-cuts to get to dynamic linker sections. */
2016 unsigned int stub_error
;
2018 /* Flag set when small branches are detected. Used to
2019 select suitable defaults for the stub group size. */
2020 unsigned int has_14bit_branch
;
2022 /* Set if we detect a reference undefined weak symbol. */
2023 unsigned int have_undefweak
;
2025 /* Incremented every time we size stubs. */
2026 unsigned int stub_iteration
;
2028 /* Small local sym to section mapping cache. */
2029 struct sym_sec_cache sym_sec
;
2032 static struct bfd_hash_entry
*stub_hash_newfunc
2033 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2034 static struct bfd_hash_entry
*branch_hash_newfunc
2035 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2036 static struct bfd_hash_entry
*link_hash_newfunc
2037 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2038 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
2040 static void ppc64_elf_link_hash_table_free
2041 PARAMS ((struct bfd_link_hash_table
*));
2042 static char *ppc_stub_name
2043 PARAMS ((const asection
*, const asection
*,
2044 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
2045 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
2046 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
2047 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
2048 static struct ppc_stub_hash_entry
*ppc_add_stub
2049 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
2050 static boolean create_linkage_sections
2051 PARAMS ((bfd
*, struct bfd_link_info
*));
2052 static boolean create_got_section
2053 PARAMS ((bfd
*, struct bfd_link_info
*));
2054 static boolean ppc64_elf_create_dynamic_sections
2055 PARAMS ((bfd
*, struct bfd_link_info
*));
2056 static void ppc64_elf_copy_indirect_symbol
2057 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
2058 static boolean ppc64_elf_check_relocs
2059 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2060 const Elf_Internal_Rela
*));
2061 static asection
* ppc64_elf_gc_mark_hook
2062 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, Elf_Internal_Rela
*rel
,
2063 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
2064 static boolean ppc64_elf_gc_sweep_hook
2065 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
2066 const Elf_Internal_Rela
*relocs
));
2067 static boolean func_desc_adjust
2068 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2069 static boolean ppc64_elf_func_desc_adjust
2070 PARAMS ((bfd
*, struct bfd_link_info
*));
2071 static boolean ppc64_elf_adjust_dynamic_symbol
2072 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
2073 static void ppc64_elf_hide_symbol
2074 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, boolean
));
2075 static boolean allocate_dynrelocs
2076 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2077 static boolean readonly_dynrelocs
2078 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2079 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2080 PARAMS ((const Elf_Internal_Rela
*));
2081 static boolean ppc64_elf_size_dynamic_sections
2082 PARAMS ((bfd
*, struct bfd_link_info
*));
2083 static INLINE
enum ppc_stub_type ppc_type_of_stub
2084 PARAMS ((asection
*, const Elf_Internal_Rela
*,
2085 struct ppc_link_hash_entry
**, bfd_vma
));
2086 static bfd_byte
*build_plt_stub
2087 PARAMS ((bfd
*, bfd_byte
*, int, int));
2088 static boolean ppc_build_one_stub
2089 PARAMS ((struct bfd_hash_entry
*, PTR
));
2090 static boolean ppc_size_one_stub
2091 PARAMS ((struct bfd_hash_entry
*, PTR
));
2092 static void group_sections
2093 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, boolean
));
2094 static boolean get_local_syms
2095 PARAMS ((bfd
*, struct ppc_link_hash_table
*));
2096 static boolean ppc64_elf_fake_sections
2097 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*));
2098 static boolean ppc64_elf_relocate_section
2099 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
2100 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
2102 static boolean ppc64_elf_finish_dynamic_symbol
2103 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
2104 Elf_Internal_Sym
*));
2105 static boolean ppc64_elf_finish_dynamic_sections
2106 PARAMS ((bfd
*, struct bfd_link_info
*));
2108 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2110 #define ppc_hash_table(p) \
2111 ((struct ppc_link_hash_table *) ((p)->hash))
2113 #define ppc_stub_hash_lookup(table, string, create, copy) \
2114 ((struct ppc_stub_hash_entry *) \
2115 bfd_hash_lookup ((table), (string), (create), (copy)))
2117 #define ppc_branch_hash_lookup(table, string, create, copy) \
2118 ((struct ppc_branch_hash_entry *) \
2119 bfd_hash_lookup ((table), (string), (create), (copy)))
2121 /* Create an entry in the stub hash table. */
2123 static struct bfd_hash_entry
*
2124 stub_hash_newfunc (entry
, table
, string
)
2125 struct bfd_hash_entry
*entry
;
2126 struct bfd_hash_table
*table
;
2129 /* Allocate the structure if it has not already been allocated by a
2133 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2138 /* Call the allocation method of the superclass. */
2139 entry
= bfd_hash_newfunc (entry
, table
, string
);
2142 struct ppc_stub_hash_entry
*eh
;
2144 /* Initialize the local fields. */
2145 eh
= (struct ppc_stub_hash_entry
*) entry
;
2146 eh
->stub_sec
= NULL
;
2147 eh
->stub_offset
= 0;
2148 eh
->target_value
= 0;
2149 eh
->target_section
= NULL
;
2150 eh
->stub_type
= ppc_stub_none
;
2158 /* Create an entry in the branch hash table. */
2160 static struct bfd_hash_entry
*
2161 branch_hash_newfunc (entry
, table
, string
)
2162 struct bfd_hash_entry
*entry
;
2163 struct bfd_hash_table
*table
;
2166 /* Allocate the structure if it has not already been allocated by a
2170 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2175 /* Call the allocation method of the superclass. */
2176 entry
= bfd_hash_newfunc (entry
, table
, string
);
2179 struct ppc_branch_hash_entry
*eh
;
2181 /* Initialize the local fields. */
2182 eh
= (struct ppc_branch_hash_entry
*) entry
;
2190 /* Create an entry in a ppc64 ELF linker hash table. */
2192 static struct bfd_hash_entry
*
2193 link_hash_newfunc (entry
, table
, string
)
2194 struct bfd_hash_entry
*entry
;
2195 struct bfd_hash_table
*table
;
2198 /* Allocate the structure if it has not already been allocated by a
2202 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2207 /* Call the allocation method of the superclass. */
2208 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2211 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2213 eh
->stub_cache
= NULL
;
2214 eh
->dyn_relocs
= NULL
;
2217 eh
->is_func_descriptor
= 0;
2223 /* Create a ppc64 ELF linker hash table. */
2225 static struct bfd_link_hash_table
*
2226 ppc64_elf_link_hash_table_create (abfd
)
2229 struct ppc_link_hash_table
*htab
;
2230 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2232 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2236 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2242 /* Init the stub hash table too. */
2243 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2246 /* And the branch hash table. */
2247 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2250 htab
->stub_bfd
= NULL
;
2251 htab
->add_stub_section
= NULL
;
2252 htab
->layout_sections_again
= NULL
;
2253 htab
->stub_group
= NULL
;
2255 htab
->srelgot
= NULL
;
2257 htab
->srelplt
= NULL
;
2258 htab
->sdynbss
= NULL
;
2259 htab
->srelbss
= NULL
;
2260 htab
->sglink
= NULL
;
2263 htab
->srelbrlt
= NULL
;
2264 htab
->stub_error
= 0;
2265 htab
->has_14bit_branch
= 0;
2266 htab
->have_undefweak
= 0;
2267 htab
->stub_iteration
= 0;
2268 htab
->sym_sec
.abfd
= NULL
;
2270 return &htab
->elf
.root
;
2273 /* Free the derived linker hash table. */
2276 ppc64_elf_link_hash_table_free (hash
)
2277 struct bfd_link_hash_table
*hash
;
2279 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2281 bfd_hash_table_free (&ret
->stub_hash_table
);
2282 bfd_hash_table_free (&ret
->branch_hash_table
);
2283 _bfd_generic_link_hash_table_free (hash
);
2286 /* Build a name for an entry in the stub hash table. */
2289 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2290 const asection
*input_section
;
2291 const asection
*sym_sec
;
2292 const struct ppc_link_hash_entry
*h
;
2293 const Elf_Internal_Rela
*rel
;
2298 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2299 offsets from a sym as a branch target? In fact, we could
2300 probably assume the addend is always zero. */
2301 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2305 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2306 stub_name
= bfd_malloc (len
);
2307 if (stub_name
!= NULL
)
2309 sprintf (stub_name
, "%08x_%s+%x",
2310 input_section
->id
& 0xffffffff,
2311 h
->elf
.root
.root
.string
,
2312 (int) rel
->r_addend
& 0xffffffff);
2317 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2318 stub_name
= bfd_malloc (len
);
2319 if (stub_name
!= NULL
)
2321 sprintf (stub_name
, "%08x_%x:%x+%x",
2322 input_section
->id
& 0xffffffff,
2323 sym_sec
->id
& 0xffffffff,
2324 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2325 (int) rel
->r_addend
& 0xffffffff);
2331 /* Look up an entry in the stub hash. Stub entries are cached because
2332 creating the stub name takes a bit of time. */
2334 static struct ppc_stub_hash_entry
*
2335 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2336 const asection
*input_section
;
2337 const asection
*sym_sec
;
2338 struct elf_link_hash_entry
*hash
;
2339 const Elf_Internal_Rela
*rel
;
2340 struct ppc_link_hash_table
*htab
;
2342 struct ppc_stub_hash_entry
*stub_entry
;
2343 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2344 const asection
*id_sec
;
2346 /* If this input section is part of a group of sections sharing one
2347 stub section, then use the id of the first section in the group.
2348 Stub names need to include a section id, as there may well be
2349 more than one stub used to reach say, printf, and we need to
2350 distinguish between them. */
2351 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2353 if (h
!= NULL
&& h
->stub_cache
!= NULL
2354 && h
->stub_cache
->h
== h
2355 && h
->stub_cache
->id_sec
== id_sec
)
2357 stub_entry
= h
->stub_cache
;
2363 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2364 if (stub_name
== NULL
)
2367 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2368 stub_name
, false, false);
2370 h
->stub_cache
= stub_entry
;
2378 /* Add a new stub entry to the stub hash. Not all fields of the new
2379 stub entry are initialised. */
2381 static struct ppc_stub_hash_entry
*
2382 ppc_add_stub (stub_name
, section
, htab
)
2383 const char *stub_name
;
2385 struct ppc_link_hash_table
*htab
;
2389 struct ppc_stub_hash_entry
*stub_entry
;
2391 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2392 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2393 if (stub_sec
== NULL
)
2395 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2396 if (stub_sec
== NULL
)
2401 len
= strlen (link_sec
->name
) + sizeof (STUB_SUFFIX
);
2402 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2406 strcpy (s_name
, link_sec
->name
);
2407 strcpy (s_name
+ len
- sizeof (STUB_SUFFIX
), STUB_SUFFIX
);
2408 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2409 if (stub_sec
== NULL
)
2411 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2413 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2416 /* Enter this entry into the linker stub hash table. */
2417 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2419 if (stub_entry
== NULL
)
2421 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2422 bfd_archive_filename (section
->owner
),
2427 stub_entry
->stub_sec
= stub_sec
;
2428 stub_entry
->stub_offset
= 0;
2429 stub_entry
->id_sec
= link_sec
;
2433 /* Create sections for linker generated code. */
2436 create_linkage_sections (dynobj
, info
)
2438 struct bfd_link_info
*info
;
2440 struct ppc_link_hash_table
*htab
;
2443 htab
= ppc_hash_table (info
);
2445 /* Create .sfpr for code to save and restore fp regs. */
2446 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2447 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2448 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2449 if (htab
->sfpr
== NULL
2450 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2451 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2454 /* Create .glink for lazy dynamic linking support. */
2455 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2456 if (htab
->sglink
== NULL
2457 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2458 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2461 /* Create .branch_lt for plt_branch stubs. */
2462 flags
= (SEC_ALLOC
| SEC_LOAD
2463 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2464 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2465 if (htab
->sbrlt
== NULL
2466 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2467 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2472 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2473 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2474 htab
->srelbrlt
= bfd_make_section (dynobj
, ".rela.branch_lt");
2476 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2477 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2483 /* Create .got and .rela.got sections in DYNOBJ, and set up
2484 shortcuts to them in our hash table. */
2487 create_got_section (dynobj
, info
)
2489 struct bfd_link_info
*info
;
2491 struct ppc_link_hash_table
*htab
;
2493 if (! _bfd_elf_create_got_section (dynobj
, info
))
2496 htab
= ppc_hash_table (info
);
2497 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2501 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2503 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2504 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2505 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2507 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2512 /* Create the dynamic sections, and set up shortcuts. */
2515 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2517 struct bfd_link_info
*info
;
2519 struct ppc_link_hash_table
*htab
;
2521 htab
= ppc_hash_table (info
);
2522 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2525 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2528 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2529 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2530 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2532 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2534 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2535 || (!info
->shared
&& !htab
->srelbss
))
2541 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2544 ppc64_elf_copy_indirect_symbol (dir
, ind
)
2545 struct elf_link_hash_entry
*dir
, *ind
;
2547 struct ppc_link_hash_entry
*edir
, *eind
;
2549 edir
= (struct ppc_link_hash_entry
*) dir
;
2550 eind
= (struct ppc_link_hash_entry
*) ind
;
2552 if (eind
->dyn_relocs
!= NULL
)
2554 if (edir
->dyn_relocs
!= NULL
)
2556 struct ppc_dyn_relocs
**pp
;
2557 struct ppc_dyn_relocs
*p
;
2559 if (ind
->root
.type
== bfd_link_hash_indirect
)
2562 /* Add reloc counts against the weak sym to the strong sym
2563 list. Merge any entries against the same section. */
2564 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2566 struct ppc_dyn_relocs
*q
;
2568 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2569 if (q
->sec
== p
->sec
)
2571 q
->pc_count
+= p
->pc_count
;
2572 q
->count
+= p
->count
;
2579 *pp
= edir
->dyn_relocs
;
2582 edir
->dyn_relocs
= eind
->dyn_relocs
;
2583 eind
->dyn_relocs
= NULL
;
2586 edir
->is_func
|= eind
->is_func
;
2587 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2589 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
2592 /* Look through the relocs for a section during the first phase, and
2593 calculate needed space in the global offset table, procedure
2594 linkage table, and dynamic reloc sections. */
2597 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2599 struct bfd_link_info
*info
;
2601 const Elf_Internal_Rela
*relocs
;
2603 struct ppc_link_hash_table
*htab
;
2604 Elf_Internal_Shdr
*symtab_hdr
;
2605 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2606 const Elf_Internal_Rela
*rel
;
2607 const Elf_Internal_Rela
*rel_end
;
2611 if (info
->relocateable
)
2614 htab
= ppc_hash_table (info
);
2615 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2617 sym_hashes
= elf_sym_hashes (abfd
);
2618 sym_hashes_end
= (sym_hashes
2619 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
));
2620 if (!elf_bad_symtab (abfd
))
2621 sym_hashes_end
-= symtab_hdr
->sh_info
;
2624 is_opd
= strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0;
2626 if (htab
->elf
.dynobj
== NULL
)
2627 htab
->elf
.dynobj
= abfd
;
2628 if (htab
->sfpr
== NULL
2629 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2632 rel_end
= relocs
+ sec
->reloc_count
;
2633 for (rel
= relocs
; rel
< rel_end
; rel
++)
2635 unsigned long r_symndx
;
2636 struct elf_link_hash_entry
*h
;
2637 enum elf_ppc_reloc_type r_type
;
2639 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2640 if (r_symndx
< symtab_hdr
->sh_info
)
2643 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2645 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2648 /* GOT16 relocations */
2650 case R_PPC64_GOT16_DS
:
2651 case R_PPC64_GOT16_HA
:
2652 case R_PPC64_GOT16_HI
:
2653 case R_PPC64_GOT16_LO
:
2654 case R_PPC64_GOT16_LO_DS
:
2656 /* This symbol requires a global offset table entry. */
2657 if (htab
->sgot
== NULL
2658 && !create_got_section (htab
->elf
.dynobj
, info
))
2663 h
->got
.refcount
+= 1;
2667 bfd_signed_vma
*local_got_refcounts
;
2669 /* This is a global offset table entry for a local symbol. */
2670 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2671 if (local_got_refcounts
== NULL
)
2675 size
= symtab_hdr
->sh_info
;
2676 size
*= sizeof (bfd_signed_vma
);
2677 local_got_refcounts
= ((bfd_signed_vma
*)
2678 bfd_zalloc (abfd
, size
));
2679 if (local_got_refcounts
== NULL
)
2681 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2683 local_got_refcounts
[r_symndx
] += 1;
2687 case R_PPC64_PLT16_HA
:
2688 case R_PPC64_PLT16_HI
:
2689 case R_PPC64_PLT16_LO
:
2692 /* This symbol requires a procedure linkage table entry. We
2693 actually build the entry in adjust_dynamic_symbol,
2694 because this might be a case of linking PIC code without
2695 linking in any dynamic objects, in which case we don't
2696 need to generate a procedure linkage table after all. */
2699 /* It does not make sense to have a procedure linkage
2700 table entry for a local symbol. */
2701 bfd_set_error (bfd_error_bad_value
);
2705 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2706 h
->plt
.refcount
+= 1;
2707 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2710 /* The following relocations don't need to propagate the
2711 relocation if linking a shared object since they are
2712 section relative. */
2713 case R_PPC64_SECTOFF
:
2714 case R_PPC64_SECTOFF_LO
:
2715 case R_PPC64_SECTOFF_HI
:
2716 case R_PPC64_SECTOFF_HA
:
2717 case R_PPC64_SECTOFF_DS
:
2718 case R_PPC64_SECTOFF_LO_DS
:
2720 case R_PPC64_TOC16_LO
:
2721 case R_PPC64_TOC16_HI
:
2722 case R_PPC64_TOC16_HA
:
2723 case R_PPC64_TOC16_DS
:
2724 case R_PPC64_TOC16_LO_DS
:
2727 /* This relocation describes the C++ object vtable hierarchy.
2728 Reconstruct it for later use during GC. */
2729 case R_PPC64_GNU_VTINHERIT
:
2730 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2734 /* This relocation describes which C++ vtable entries are actually
2735 used. Record for later use during GC. */
2736 case R_PPC64_GNU_VTENTRY
:
2737 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2742 case R_PPC64_REL14_BRTAKEN
:
2743 case R_PPC64_REL14_BRNTAKEN
:
2744 htab
->has_14bit_branch
= 1;
2749 && h
->root
.root
.string
[0] == '.'
2750 && h
->root
.root
.string
[1] != 0)
2752 /* We may need a .plt entry if the function this reloc
2753 refers to is in a shared lib. */
2754 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2755 h
->plt
.refcount
+= 1;
2756 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2760 case R_PPC64_ADDR64
:
2763 && h
->root
.root
.string
[0] == '.'
2764 && h
->root
.root
.string
[1] != 0)
2766 struct elf_link_hash_entry
*fdh
;
2768 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2769 false, false, false);
2772 /* Ensure the function descriptor symbol string is
2773 part of the code symbol string. We aren't
2774 changing the name here, just allowing some tricks
2775 in ppc64_elf_hide_symbol. */
2776 fdh
->root
.root
.string
= h
->root
.root
.string
+ 1;
2777 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2778 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2779 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2780 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2787 case R_PPC64_ADDR14
:
2788 case R_PPC64_ADDR14_BRNTAKEN
:
2789 case R_PPC64_ADDR14_BRTAKEN
:
2790 case R_PPC64_ADDR16
:
2791 case R_PPC64_ADDR16_DS
:
2792 case R_PPC64_ADDR16_HA
:
2793 case R_PPC64_ADDR16_HI
:
2794 case R_PPC64_ADDR16_HIGHER
:
2795 case R_PPC64_ADDR16_HIGHERA
:
2796 case R_PPC64_ADDR16_HIGHEST
:
2797 case R_PPC64_ADDR16_HIGHESTA
:
2798 case R_PPC64_ADDR16_LO
:
2799 case R_PPC64_ADDR16_LO_DS
:
2800 case R_PPC64_ADDR24
:
2801 case R_PPC64_ADDR30
:
2802 case R_PPC64_ADDR32
:
2803 case R_PPC64_UADDR16
:
2804 case R_PPC64_UADDR32
:
2805 case R_PPC64_UADDR64
:
2807 /* Don't propagate .opd relocs. */
2808 if (NO_OPD_RELOCS
&& is_opd
)
2811 /* If we are creating a shared library, and this is a reloc
2812 against a global symbol, or a non PC relative reloc
2813 against a local symbol, then we need to copy the reloc
2814 into the shared library. However, if we are linking with
2815 -Bsymbolic, we do not need to copy a reloc against a
2816 global symbol which is defined in an object we are
2817 including in the link (i.e., DEF_REGULAR is set). At
2818 this point we have not seen all the input files, so it is
2819 possible that DEF_REGULAR is not set now but will be set
2820 later (it is never cleared). In case of a weak definition,
2821 DEF_REGULAR may be cleared later by a strong definition in
2822 a shared library. We account for that possibility below by
2823 storing information in the relocs_copied field of the hash
2824 table entry. A similar situation occurs when creating
2825 shared libraries and symbol visibility changes render the
2828 If on the other hand, we are creating an executable, we
2829 may need to keep relocations for symbols satisfied by a
2830 dynamic library if we manage to avoid copy relocs for the
2833 && (sec
->flags
& SEC_ALLOC
) != 0
2834 && (IS_ABSOLUTE_RELOC (r_type
)
2836 && (! info
->symbolic
2837 || h
->root
.type
== bfd_link_hash_defweak
2838 || (h
->elf_link_hash_flags
2839 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2841 && (sec
->flags
& SEC_ALLOC
) != 0
2843 && (h
->root
.type
== bfd_link_hash_defweak
2844 || (h
->elf_link_hash_flags
2845 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2847 struct ppc_dyn_relocs
*p
;
2848 struct ppc_dyn_relocs
**head
;
2850 /* We must copy these reloc types into the output file.
2851 Create a reloc section in dynobj and make room for
2858 name
= (bfd_elf_string_from_elf_section
2860 elf_elfheader (abfd
)->e_shstrndx
,
2861 elf_section_data (sec
)->rel_hdr
.sh_name
));
2865 if (strncmp (name
, ".rela", 5) != 0
2866 || strcmp (bfd_get_section_name (abfd
, sec
),
2869 (*_bfd_error_handler
)
2870 (_("%s: bad relocation section name `%s\'"),
2871 bfd_archive_filename (abfd
), name
);
2872 bfd_set_error (bfd_error_bad_value
);
2875 dynobj
= htab
->elf
.dynobj
;
2876 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2881 sreloc
= bfd_make_section (dynobj
, name
);
2882 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2883 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2884 if ((sec
->flags
& SEC_ALLOC
) != 0)
2885 flags
|= SEC_ALLOC
| SEC_LOAD
;
2887 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2888 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2891 elf_section_data (sec
)->sreloc
= sreloc
;
2894 /* If this is a global symbol, we count the number of
2895 relocations we need for this symbol. */
2898 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
2902 /* Track dynamic relocs needed for local syms too.
2903 We really need local syms available to do this
2907 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
2912 head
= ((struct ppc_dyn_relocs
**)
2913 &elf_section_data (s
)->local_dynrel
);
2917 if (p
== NULL
|| p
->sec
!= sec
)
2919 p
= ((struct ppc_dyn_relocs
*)
2920 bfd_alloc (htab
->elf
.dynobj
,
2921 (bfd_size_type
) sizeof *p
));
2932 if (!IS_ABSOLUTE_RELOC (r_type
))
2945 /* Return the section that should be marked against GC for a given
2949 ppc64_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2951 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2952 Elf_Internal_Rela
*rel
;
2953 struct elf_link_hash_entry
*h
;
2954 Elf_Internal_Sym
*sym
;
2958 enum elf_ppc_reloc_type r_type
;
2960 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2963 case R_PPC64_GNU_VTINHERIT
:
2964 case R_PPC64_GNU_VTENTRY
:
2968 switch (h
->root
.type
)
2970 case bfd_link_hash_defined
:
2971 case bfd_link_hash_defweak
:
2972 return h
->root
.u
.def
.section
;
2974 case bfd_link_hash_common
:
2975 return h
->root
.u
.c
.p
->section
;
2984 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2990 /* Update the .got, .plt. and dynamic reloc reference counts for the
2991 section being removed. */
2994 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2996 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2998 const Elf_Internal_Rela
*relocs
;
3000 Elf_Internal_Shdr
*symtab_hdr
;
3001 struct elf_link_hash_entry
**sym_hashes
;
3002 bfd_signed_vma
*local_got_refcounts
;
3003 const Elf_Internal_Rela
*rel
, *relend
;
3005 elf_section_data (sec
)->local_dynrel
= NULL
;
3007 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3008 sym_hashes
= elf_sym_hashes (abfd
);
3009 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3011 relend
= relocs
+ sec
->reloc_count
;
3012 for (rel
= relocs
; rel
< relend
; rel
++)
3014 unsigned long r_symndx
;
3015 enum elf_ppc_reloc_type r_type
;
3016 struct elf_link_hash_entry
*h
;
3018 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3019 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3023 case R_PPC64_GOT16_DS
:
3024 case R_PPC64_GOT16_HA
:
3025 case R_PPC64_GOT16_HI
:
3026 case R_PPC64_GOT16_LO
:
3027 case R_PPC64_GOT16_LO_DS
:
3028 if (r_symndx
>= symtab_hdr
->sh_info
)
3030 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3031 if (h
->got
.refcount
> 0)
3036 if (local_got_refcounts
[r_symndx
] > 0)
3037 local_got_refcounts
[r_symndx
]--;
3041 case R_PPC64_PLT16_HA
:
3042 case R_PPC64_PLT16_HI
:
3043 case R_PPC64_PLT16_LO
:
3046 if (r_symndx
>= symtab_hdr
->sh_info
)
3048 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3049 if (h
->plt
.refcount
> 0)
3055 case R_PPC64_REL14_BRNTAKEN
:
3056 case R_PPC64_REL14_BRTAKEN
:
3058 if (r_symndx
>= symtab_hdr
->sh_info
)
3060 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3061 if (h
->plt
.refcount
> 0)
3068 if (r_symndx
>= symtab_hdr
->sh_info
)
3070 struct ppc_link_hash_entry
*eh
;
3071 struct ppc_dyn_relocs
**pp
;
3072 struct ppc_dyn_relocs
*p
;
3074 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3075 eh
= (struct ppc_link_hash_entry
*) h
;
3077 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3089 case R_PPC64_ADDR14
:
3090 case R_PPC64_ADDR14_BRNTAKEN
:
3091 case R_PPC64_ADDR14_BRTAKEN
:
3092 case R_PPC64_ADDR16
:
3093 case R_PPC64_ADDR16_DS
:
3094 case R_PPC64_ADDR16_HA
:
3095 case R_PPC64_ADDR16_HI
:
3096 case R_PPC64_ADDR16_HIGHER
:
3097 case R_PPC64_ADDR16_HIGHERA
:
3098 case R_PPC64_ADDR16_HIGHEST
:
3099 case R_PPC64_ADDR16_HIGHESTA
:
3100 case R_PPC64_ADDR16_LO
:
3101 case R_PPC64_ADDR16_LO_DS
:
3102 case R_PPC64_ADDR24
:
3103 case R_PPC64_ADDR30
:
3104 case R_PPC64_ADDR32
:
3105 case R_PPC64_ADDR64
:
3106 case R_PPC64_UADDR16
:
3107 case R_PPC64_UADDR32
:
3108 case R_PPC64_UADDR64
:
3110 if (r_symndx
>= symtab_hdr
->sh_info
)
3112 struct ppc_link_hash_entry
*eh
;
3113 struct ppc_dyn_relocs
**pp
;
3114 struct ppc_dyn_relocs
*p
;
3116 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3117 eh
= (struct ppc_link_hash_entry
*) h
;
3119 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3137 /* Called via elf_link_hash_traverse to transfer dynamic linking
3138 information on function code symbol entries to their corresponding
3139 function descriptor symbol entries. */
3141 func_desc_adjust (h
, inf
)
3142 struct elf_link_hash_entry
*h
;
3145 struct bfd_link_info
*info
;
3146 struct ppc_link_hash_table
*htab
;
3148 if (h
->root
.type
== bfd_link_hash_indirect
)
3151 if (h
->root
.type
== bfd_link_hash_warning
)
3152 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3154 info
= (struct bfd_link_info
*) inf
;
3155 htab
= ppc_hash_table (info
);
3157 /* If this is a function code symbol, transfer dynamic linking
3158 information to the function descriptor symbol. */
3159 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
3162 if (h
->root
.type
== bfd_link_hash_undefweak
3163 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
3164 htab
->have_undefweak
= true;
3166 if (h
->plt
.refcount
> 0
3167 && h
->root
.root
.string
[0] == '.'
3168 && h
->root
.root
.string
[1] != '\0')
3170 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3171 boolean force_local
;
3173 /* Find the corresponding function descriptor symbol. Create it
3174 as undefined if necessary. */
3177 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3178 false, false, true);
3182 && (h
->root
.type
== bfd_link_hash_undefined
3183 || h
->root
.type
== bfd_link_hash_undefweak
))
3188 abfd
= h
->root
.u
.undef
.abfd
;
3189 newsym
= bfd_make_empty_symbol (abfd
);
3190 newsym
->name
= h
->root
.root
.string
+ 1;
3191 newsym
->section
= bfd_und_section_ptr
;
3193 newsym
->flags
= BSF_OBJECT
;
3194 if (h
->root
.type
== bfd_link_hash_undefweak
)
3195 newsym
->flags
|= BSF_WEAK
;
3197 if ( !(_bfd_generic_link_add_one_symbol
3198 (info
, abfd
, newsym
->name
, newsym
->flags
,
3199 newsym
->section
, newsym
->value
, NULL
, false, false,
3200 (struct bfd_link_hash_entry
**) &fdh
)))
3204 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3208 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
3210 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3211 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3213 if (fdh
->dynindx
== -1)
3214 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
3216 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
3217 & (ELF_LINK_HASH_REF_REGULAR
3218 | ELF_LINK_HASH_REF_DYNAMIC
3219 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3220 | ELF_LINK_NON_GOT_REF
));
3221 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3223 fdh
->plt
.refcount
= h
->plt
.refcount
;
3224 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3226 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3227 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3228 fdh
->root
.root
.string
= h
->root
.root
.string
+ 1;
3229 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3232 /* Now that the info is on the function descriptor, clear the
3233 function code sym info. Any function code syms for which we
3234 don't have a definition in a regular file, we force local.
3235 This prevents a shared library from exporting syms that have
3236 been imported from another library. Function code syms that
3237 are really in the library we must leave global to prevent the
3238 linker dragging in a definition from a static library. */
3239 force_local
= ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3241 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3247 #define MIN_SAVE_FPR 14
3248 #define MAX_SAVE_FPR 31
3250 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3251 this hook to a) provide some gcc support functions, and b) transfer
3252 dynamic linking information gathered so far on function code symbol
3253 entries, to their corresponding function descriptor symbol entries. */
3255 ppc64_elf_func_desc_adjust (obfd
, info
)
3256 bfd
*obfd ATTRIBUTE_UNUSED
;
3257 struct bfd_link_info
*info
;
3259 struct ppc_link_hash_table
*htab
;
3260 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3261 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3263 struct elf_link_hash_entry
*h
;
3267 htab
= ppc_hash_table (info
);
3269 if (htab
->sfpr
== NULL
)
3270 /* We don't have any relocs. */
3273 /* First provide any missing ._savef* and ._restf* functions. */
3274 memcpy (sym
, "._savef14", 10);
3275 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3277 sym
[7] = i
/ 10 + '0';
3278 sym
[8] = i
% 10 + '0';
3279 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3281 && h
->root
.type
== bfd_link_hash_undefined
)
3283 if (lowest_savef
> i
)
3285 h
->root
.type
= bfd_link_hash_defined
;
3286 h
->root
.u
.def
.section
= htab
->sfpr
;
3287 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3289 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3290 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3294 memcpy (sym
, "._restf14", 10);
3295 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3297 sym
[7] = i
/ 10 + '0';
3298 sym
[8] = i
% 10 + '0';
3299 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3301 && h
->root
.type
== bfd_link_hash_undefined
)
3303 if (lowest_restf
> i
)
3305 h
->root
.type
= bfd_link_hash_defined
;
3306 h
->root
.u
.def
.section
= htab
->sfpr
;
3307 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3308 + (i
- lowest_restf
) * 4);
3310 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3311 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3315 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3317 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3318 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3320 if (htab
->sfpr
->_raw_size
== 0)
3322 if (!htab
->have_undefweak
)
3324 _bfd_strip_section_from_output (info
, htab
->sfpr
);
3328 htab
->sfpr
->_raw_size
= 4;
3331 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3334 htab
->sfpr
->contents
= p
;
3336 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3338 unsigned int fpr
= i
<< 21;
3339 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3340 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3343 if (lowest_savef
<= MAX_SAVE_FPR
)
3345 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3349 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3351 unsigned int fpr
= i
<< 21;
3352 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3353 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3356 if (lowest_restf
<= MAX_SAVE_FPR
3357 || htab
->sfpr
->_raw_size
== 4)
3359 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3365 /* Adjust a symbol defined by a dynamic object and referenced by a
3366 regular object. The current definition is in some section of the
3367 dynamic object, but we're not including those sections. We have to
3368 change the definition to something the rest of the link can
3372 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3373 struct bfd_link_info
*info
;
3374 struct elf_link_hash_entry
*h
;
3376 struct ppc_link_hash_table
*htab
;
3377 struct ppc_link_hash_entry
* eh
;
3378 struct ppc_dyn_relocs
*p
;
3380 unsigned int power_of_two
;
3382 htab
= ppc_hash_table (info
);
3384 /* Deal with function syms. */
3385 if (h
->type
== STT_FUNC
3386 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3388 /* Clear procedure linkage table information for any symbol that
3389 won't need a .plt entry. */
3390 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3391 || h
->plt
.refcount
<= 0
3392 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3394 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3395 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3397 h
->plt
.offset
= (bfd_vma
) -1;
3398 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3403 h
->plt
.offset
= (bfd_vma
) -1;
3405 /* If this is a weak symbol, and there is a real definition, the
3406 processor independent code will have arranged for us to see the
3407 real definition first, and we can just use the same value. */
3408 if (h
->weakdef
!= NULL
)
3410 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3411 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3412 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3413 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3417 /* This is a reference to a symbol defined by a dynamic object which
3418 is not a function. */
3420 /* If we are creating a shared library, we must presume that the
3421 only references to the symbol are via the global offset table.
3422 For such cases we need not do anything here; the relocations will
3423 be handled correctly by relocate_section. */
3427 /* If there are no references to this symbol that do not use the
3428 GOT, we don't need to generate a copy reloc. */
3429 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3432 eh
= (struct ppc_link_hash_entry
*) h
;
3433 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3435 s
= p
->sec
->output_section
;
3436 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3440 /* If we didn't find any dynamic relocs in read-only sections, then
3441 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3444 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3448 /* We must allocate the symbol in our .dynbss section, which will
3449 become part of the .bss section of the executable. There will be
3450 an entry for this symbol in the .dynsym section. The dynamic
3451 object will contain position independent code, so all references
3452 from the dynamic object to this symbol will go through the global
3453 offset table. The dynamic linker will use the .dynsym entry to
3454 determine the address it must put in the global offset table, so
3455 both the dynamic object and the regular object will refer to the
3456 same memory location for the variable. */
3458 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3459 copy the initial value out of the dynamic object and into the
3460 runtime process image. We need to remember the offset into the
3461 .rela.bss section we are going to use. */
3462 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3464 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3465 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3468 /* We need to figure out the alignment required for this symbol. I
3469 have no idea how ELF linkers handle this. */
3470 power_of_two
= bfd_log2 (h
->size
);
3471 if (power_of_two
> 4)
3474 /* Apply the required alignment. */
3476 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3477 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3479 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3483 /* Define the symbol as being at this point in the section. */
3484 h
->root
.u
.def
.section
= s
;
3485 h
->root
.u
.def
.value
= s
->_raw_size
;
3487 /* Increment the section size to make room for the symbol. */
3488 s
->_raw_size
+= h
->size
;
3493 /* If given a function descriptor symbol, hide both the function code
3494 sym and the descriptor. */
3496 ppc64_elf_hide_symbol (info
, h
, force_local
)
3497 struct bfd_link_info
*info
;
3498 struct elf_link_hash_entry
*h
;
3499 boolean force_local
;
3501 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3503 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3506 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3507 struct ppc_link_hash_table
*htab
;
3509 name
= h
->root
.root
.string
- 1;
3510 htab
= ppc_hash_table (info
);
3512 fh
= elf_link_hash_lookup (&htab
->elf
, name
, false, false, false);
3514 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3518 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3519 will be called from elflink.h. If elflink.h doesn't call our
3520 finish_dynamic_symbol routine, we'll need to do something about
3521 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3522 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3524 && ((INFO)->shared \
3525 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3526 && ((H)->dynindx != -1 \
3527 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3529 /* Allocate space in .plt, .got and associated reloc sections for
3533 allocate_dynrelocs (h
, inf
)
3534 struct elf_link_hash_entry
*h
;
3537 struct bfd_link_info
*info
;
3538 struct ppc_link_hash_table
*htab
;
3540 struct ppc_link_hash_entry
*eh
;
3541 struct ppc_dyn_relocs
*p
;
3543 if (h
->root
.type
== bfd_link_hash_indirect
)
3546 if (h
->root
.type
== bfd_link_hash_warning
)
3547 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3549 info
= (struct bfd_link_info
*) inf
;
3550 htab
= ppc_hash_table (info
);
3552 if (htab
->elf
.dynamic_sections_created
3553 && h
->plt
.refcount
> 0
3554 && h
->dynindx
!= -1)
3556 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
3558 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3560 /* If this is the first .plt entry, make room for the special
3563 if (s
->_raw_size
== 0)
3564 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3566 h
->plt
.offset
= s
->_raw_size
;
3568 /* Make room for this entry. */
3569 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3571 /* Make room for the .glink code. */
3573 if (s
->_raw_size
== 0)
3574 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
3575 /* We need bigger stubs past index 32767. */
3576 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
3578 s
->_raw_size
+= 2*4;
3580 /* We also need to make an entry in the .rela.plt section. */
3582 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
3586 h
->plt
.offset
= (bfd_vma
) -1;
3587 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3592 h
->plt
.offset
= (bfd_vma
) -1;
3593 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3596 if (h
->got
.refcount
> 0)
3600 /* Make sure this symbol is output as a dynamic symbol.
3601 Undefined weak syms won't yet be marked as dynamic. */
3602 if (h
->dynindx
== -1
3603 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3605 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3610 h
->got
.offset
= s
->_raw_size
;
3612 dyn
= htab
->elf
.dynamic_sections_created
;
3613 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
3614 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
3617 h
->got
.offset
= (bfd_vma
) -1;
3619 eh
= (struct ppc_link_hash_entry
*) h
;
3620 if (eh
->dyn_relocs
== NULL
)
3623 /* In the shared -Bsymbolic case, discard space allocated for
3624 dynamic pc-relative relocs against symbols which turn out to be
3625 defined in regular objects. For the normal shared case, discard
3626 space for relocs that have become local due to symbol visibility
3631 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3632 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3635 struct ppc_dyn_relocs
**pp
;
3637 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3639 p
->count
-= p
->pc_count
;
3650 /* For the non-shared case, discard space for relocs against
3651 symbols which turn out to need copy relocs or are not
3654 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3655 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3656 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3657 || (htab
->elf
.dynamic_sections_created
3658 && (h
->root
.type
== bfd_link_hash_undefweak
3659 || h
->root
.type
== bfd_link_hash_undefined
))))
3661 /* Make sure this symbol is output as a dynamic symbol.
3662 Undefined weak syms won't yet be marked as dynamic. */
3663 if (h
->dynindx
== -1
3664 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3666 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3670 /* If that succeeded, we know we'll be keeping all the
3672 if (h
->dynindx
!= -1)
3676 eh
->dyn_relocs
= NULL
;
3681 /* Finally, allocate space. */
3682 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3684 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3685 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
3691 /* Find any dynamic relocs that apply to read-only sections. */
3694 readonly_dynrelocs (h
, inf
)
3695 struct elf_link_hash_entry
*h
;
3698 struct ppc_link_hash_entry
*eh
;
3699 struct ppc_dyn_relocs
*p
;
3701 if (h
->root
.type
== bfd_link_hash_warning
)
3702 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3704 eh
= (struct ppc_link_hash_entry
*) h
;
3705 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3707 asection
*s
= p
->sec
->output_section
;
3709 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3711 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
3713 info
->flags
|= DF_TEXTREL
;
3715 /* Not an error, just cut short the traversal. */
3722 /* Set the sizes of the dynamic sections. */
3725 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
3726 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3727 struct bfd_link_info
*info
;
3729 struct ppc_link_hash_table
*htab
;
3735 htab
= ppc_hash_table (info
);
3736 dynobj
= htab
->elf
.dynobj
;
3740 if (htab
->elf
.dynamic_sections_created
)
3742 /* Set the contents of the .interp section to the interpreter. */
3745 s
= bfd_get_section_by_name (dynobj
, ".interp");
3748 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3749 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3753 /* Set up .got offsets for local syms, and space for local dynamic
3755 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3757 bfd_signed_vma
*local_got
;
3758 bfd_signed_vma
*end_local_got
;
3759 bfd_size_type locsymcount
;
3760 Elf_Internal_Shdr
*symtab_hdr
;
3763 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3766 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3768 struct ppc_dyn_relocs
*p
;
3770 for (p
= *((struct ppc_dyn_relocs
**)
3771 &elf_section_data (s
)->local_dynrel
);
3775 if (!bfd_is_abs_section (p
->sec
)
3776 && bfd_is_abs_section (p
->sec
->output_section
))
3778 /* Input section has been discarded, either because
3779 it is a copy of a linkonce section or due to
3780 linker script /DISCARD/, so we'll be discarding
3783 else if (p
->count
!= 0)
3785 srel
= elf_section_data (p
->sec
)->sreloc
;
3786 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
3787 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
3788 info
->flags
|= DF_TEXTREL
;
3793 local_got
= elf_local_got_refcounts (ibfd
);
3797 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3798 locsymcount
= symtab_hdr
->sh_info
;
3799 end_local_got
= local_got
+ locsymcount
;
3801 srel
= htab
->srelgot
;
3802 for (; local_got
< end_local_got
; ++local_got
)
3806 *local_got
= s
->_raw_size
;
3809 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
3812 *local_got
= (bfd_vma
) -1;
3816 /* Allocate global sym .plt and .got entries, and space for global
3817 sym dynamic relocs. */
3818 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
3820 /* We now have determined the sizes of the various dynamic sections.
3821 Allocate memory for them. */
3823 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3825 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3828 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
3829 /* These haven't been allocated yet; don't strip. */
3831 else if (s
== htab
->splt
3833 || s
== htab
->sglink
)
3835 /* Strip this section if we don't need it; see the
3838 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3840 if (s
->_raw_size
== 0)
3842 /* If we don't need this section, strip it from the
3843 output file. This is mostly to handle .rela.bss and
3844 .rela.plt. We must create both sections in
3845 create_dynamic_sections, because they must be created
3846 before the linker maps input sections to output
3847 sections. The linker does that before
3848 adjust_dynamic_symbol is called, and it is that
3849 function which decides whether anything needs to go
3850 into these sections. */
3854 if (s
!= htab
->srelplt
)
3857 /* We use the reloc_count field as a counter if we need
3858 to copy relocs into the output file. */
3864 /* It's not one of our sections, so don't allocate space. */
3868 if (s
->_raw_size
== 0)
3870 _bfd_strip_section_from_output (info
, s
);
3874 /* Allocate memory for the section contents. We use bfd_zalloc
3875 here in case unused entries are not reclaimed before the
3876 section's contents are written out. This should not happen,
3877 but this way if it does, we get a R_PPC64_NONE reloc instead
3879 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
3880 if (s
->contents
== NULL
)
3884 if (htab
->elf
.dynamic_sections_created
)
3886 /* Add some entries to the .dynamic section. We fill in the
3887 values later, in ppc64_elf_finish_dynamic_sections, but we
3888 must add the entries now so that we get the correct size for
3889 the .dynamic section. The DT_DEBUG entry is filled in by the
3890 dynamic linker and used by the debugger. */
3891 #define add_dynamic_entry(TAG, VAL) \
3892 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3896 if (!add_dynamic_entry (DT_DEBUG
, 0))
3900 if (htab
->splt
->_raw_size
!= 0)
3902 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3903 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3904 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3905 || !add_dynamic_entry (DT_JMPREL
, 0)
3906 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
3912 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
3913 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
3919 if (!add_dynamic_entry (DT_RELA
, 0)
3920 || !add_dynamic_entry (DT_RELASZ
, 0)
3921 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
3924 /* If any dynamic relocs apply to a read-only section,
3925 then we need a DT_TEXTREL entry. */
3926 if ((info
->flags
& DF_TEXTREL
) == 0)
3927 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
3930 if ((info
->flags
& DF_TEXTREL
) != 0)
3932 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3937 #undef add_dynamic_entry
3942 /* Determine the type of stub needed, if any, for a call. */
3944 static INLINE
enum ppc_stub_type
3945 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
3946 asection
*input_sec
;
3947 const Elf_Internal_Rela
*rel
;
3948 struct ppc_link_hash_entry
**hash
;
3949 bfd_vma destination
;
3951 struct ppc_link_hash_entry
*h
= *hash
;
3953 bfd_vma branch_offset
;
3954 bfd_vma max_branch_offset
;
3955 unsigned int r_type
;
3960 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
3961 && h
->oh
->dynindx
!= -1)
3963 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
3964 return ppc_stub_plt_call
;
3967 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
3968 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
3969 return ppc_stub_none
;
3972 /* Determine where the call point is. */
3973 location
= (input_sec
->output_offset
3974 + input_sec
->output_section
->vma
3977 branch_offset
= destination
- location
;
3978 r_type
= ELF64_R_TYPE (rel
->r_info
);
3980 /* Determine if a long branch stub is needed. */
3981 max_branch_offset
= 1 << 25;
3982 if (r_type
!= (unsigned int) R_PPC64_REL24
)
3983 max_branch_offset
= 1 << 15;
3985 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
3986 /* We need a stub. Figure out whether a long_branch or plt_branch
3988 return ppc_stub_long_branch
;
3990 return ppc_stub_none
;
3993 /* Build a .plt call stub. */
3996 build_plt_stub (obfd
, p
, offset
, glink
)
4002 #define PPC_LO(v) ((v) & 0xffff)
4003 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4004 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4007 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
4008 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
4010 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
4011 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4012 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4013 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4015 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
4016 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4017 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4019 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
4020 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4021 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
4026 ppc_build_one_stub (gen_entry
, in_arg
)
4027 struct bfd_hash_entry
*gen_entry
;
4030 struct ppc_stub_hash_entry
*stub_entry
;
4031 struct ppc_branch_hash_entry
*br_entry
;
4032 struct bfd_link_info
*info
;
4033 struct ppc_link_hash_table
*htab
;
4042 /* Massage our args to the form they really have. */
4043 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4044 info
= (struct bfd_link_info
*) in_arg
;
4046 htab
= ppc_hash_table (info
);
4047 stub_sec
= stub_entry
->stub_sec
;
4049 /* Make a note of the offset within the stubs for this entry. */
4050 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
4051 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4053 stub_bfd
= stub_sec
->owner
;
4055 switch (stub_entry
->stub_type
)
4057 case ppc_stub_long_branch
:
4058 /* Branches are relative. This is where we are going to. */
4059 off
= (stub_entry
->target_value
4060 + stub_entry
->target_section
->output_offset
4061 + stub_entry
->target_section
->output_section
->vma
);
4063 /* And this is where we are coming from. */
4064 off
-= (stub_entry
->stub_offset
4065 + stub_sec
->output_offset
4066 + stub_sec
->output_section
->vma
);
4068 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
4070 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
4074 case ppc_stub_plt_branch
:
4075 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4076 stub_entry
->root
.string
+ 9,
4078 if (br_entry
== NULL
)
4080 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
4081 stub_entry
->root
.string
+ 9);
4082 htab
->stub_error
= true;
4086 off
= (stub_entry
->target_value
4087 + stub_entry
->target_section
->output_offset
4088 + stub_entry
->target_section
->output_section
->vma
);
4090 bfd_put_64 (htab
->sbrlt
->owner
, off
,
4091 htab
->sbrlt
->contents
+ br_entry
->offset
);
4095 /* Create a reloc for the branch lookup table entry. */
4096 Elf_Internal_Rela rela
;
4097 Elf64_External_Rela
*r
;
4099 rela
.r_offset
= (br_entry
->offset
4100 + htab
->sbrlt
->output_offset
4101 + htab
->sbrlt
->output_section
->vma
);
4102 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
4103 rela
.r_addend
= off
;
4105 r
= (Elf64_External_Rela
*) htab
->srelbrlt
->contents
;
4106 r
+= htab
->srelbrlt
->reloc_count
++;
4107 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, r
);
4110 off
= (br_entry
->offset
4111 + htab
->sbrlt
->output_offset
4112 + htab
->sbrlt
->output_section
->vma
4113 - elf_gp (htab
->sbrlt
->output_section
->owner
)
4116 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4118 (*_bfd_error_handler
)
4119 (_("linkage table error against `%s'"),
4120 stub_entry
->root
.string
);
4121 bfd_set_error (bfd_error_bad_value
);
4122 htab
->stub_error
= true;
4127 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
4128 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
4129 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
4130 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
4134 case ppc_stub_plt_call
:
4135 /* Build the .glink lazy link call stub. */
4136 p
= htab
->sglink
->contents
+ htab
->sglink
->_cooked_size
;
4137 indx
= htab
->sglink
->reloc_count
;
4140 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
4145 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
4147 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
4150 bfd_put_32 (htab
->sglink
->owner
,
4151 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
4153 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
4154 htab
->sglink
->reloc_count
+= 1;
4156 /* Now build the stub. */
4157 off
= stub_entry
->h
->elf
.plt
.offset
;
4158 if (off
>= (bfd_vma
) -2)
4161 off
&= ~ (bfd_vma
) 1;
4162 off
+= (htab
->splt
->output_offset
4163 + htab
->splt
->output_section
->vma
4164 - elf_gp (htab
->splt
->output_section
->owner
)
4167 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4169 (*_bfd_error_handler
)
4170 (_("linkage table error against `%s'"),
4171 stub_entry
->h
->elf
.root
.root
.string
);
4172 bfd_set_error (bfd_error_bad_value
);
4173 htab
->stub_error
= true;
4177 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
4186 stub_sec
->_cooked_size
+= size
;
4190 /* As above, but don't actually build the stub. Just bump offset so
4191 we know stub section sizes, and select plt_branch stubs where
4192 long_branch stubs won't do. */
4195 ppc_size_one_stub (gen_entry
, in_arg
)
4196 struct bfd_hash_entry
*gen_entry
;
4199 struct ppc_stub_hash_entry
*stub_entry
;
4200 struct ppc_link_hash_table
*htab
;
4204 /* Massage our args to the form they really have. */
4205 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4206 htab
= (struct ppc_link_hash_table
*) in_arg
;
4208 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
4210 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
4211 off
+= (htab
->splt
->output_offset
4212 + htab
->splt
->output_section
->vma
4213 - elf_gp (htab
->splt
->output_section
->owner
)
4217 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
4222 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4223 stub_entry
->stub_type
= ppc_stub_long_branch
;
4226 off
= (stub_entry
->target_value
4227 + stub_entry
->target_section
->output_offset
4228 + stub_entry
->target_section
->output_section
->vma
);
4229 off
-= (stub_entry
->stub_sec
->_raw_size
4230 + stub_entry
->stub_sec
->output_offset
4231 + stub_entry
->stub_sec
->output_section
->vma
);
4233 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
4235 struct ppc_branch_hash_entry
*br_entry
;
4237 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4238 stub_entry
->root
.string
+ 9,
4240 if (br_entry
== NULL
)
4242 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4243 stub_entry
->root
.string
+ 9);
4244 htab
->stub_error
= true;
4248 if (br_entry
->iter
!= htab
->stub_iteration
)
4250 br_entry
->iter
= htab
->stub_iteration
;
4251 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4252 htab
->sbrlt
->_raw_size
+= 8;
4254 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4259 stub_entry
->stub_sec
->_raw_size
+= size
;
4263 /* Set up various things so that we can make a list of input sections
4264 for each output section included in the link. Returns -1 on error,
4265 0 when no stubs will be needed, and 1 on success. */
4268 ppc64_elf_setup_section_lists (output_bfd
, info
)
4270 struct bfd_link_info
*info
;
4273 unsigned int bfd_count
;
4274 int top_id
, top_index
;
4276 asection
**input_list
, **list
;
4278 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4280 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
4281 || htab
->sbrlt
== NULL
)
4284 /* Count the number of input BFDs and find the top input section id. */
4285 for (input_bfd
= info
->input_bfds
, bfd_count
= 0, top_id
= 0;
4287 input_bfd
= input_bfd
->link_next
)
4290 for (section
= input_bfd
->sections
;
4292 section
= section
->next
)
4294 if (top_id
< section
->id
)
4295 top_id
= section
->id
;
4298 htab
->bfd_count
= bfd_count
;
4300 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4301 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4302 if (htab
->stub_group
== NULL
)
4305 /* We can't use output_bfd->section_count here to find the top output
4306 section index as some sections may have been removed, and
4307 _bfd_strip_section_from_output doesn't renumber the indices. */
4308 for (section
= output_bfd
->sections
, top_index
= 0;
4310 section
= section
->next
)
4312 if (top_index
< section
->index
)
4313 top_index
= section
->index
;
4316 htab
->top_index
= top_index
;
4317 amt
= sizeof (asection
*) * (top_index
+ 1);
4318 input_list
= (asection
**) bfd_malloc (amt
);
4319 htab
->input_list
= input_list
;
4320 if (input_list
== NULL
)
4323 /* For sections we aren't interested in, mark their entries with a
4324 value we can check later. */
4325 list
= input_list
+ top_index
;
4327 *list
= bfd_abs_section_ptr
;
4328 while (list
-- != input_list
);
4330 for (section
= output_bfd
->sections
;
4332 section
= section
->next
)
4334 if ((section
->flags
& SEC_CODE
) != 0)
4335 input_list
[section
->index
] = NULL
;
4341 /* The linker repeatedly calls this function for each input section,
4342 in the order that input sections are linked into output sections.
4343 Build lists of input sections to determine groupings between which
4344 we may insert linker stubs. */
4347 ppc64_elf_next_input_section (info
, isec
)
4348 struct bfd_link_info
*info
;
4351 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4353 if (isec
->output_section
->index
<= htab
->top_index
)
4355 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4356 if (*list
!= bfd_abs_section_ptr
)
4358 /* Steal the link_sec pointer for our list. */
4359 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4360 /* This happens to make the list in reverse order,
4361 which is what we want. */
4362 PREV_SEC (isec
) = *list
;
4368 /* See whether we can group stub sections together. Grouping stub
4369 sections may result in fewer stubs. More importantly, we need to
4370 put all .init* and .fini* stubs at the beginning of the .init or
4371 .fini output sections respectively, because glibc splits the
4372 _init and _fini functions into multiple parts. Putting a stub in
4373 the middle of a function is not a good idea. */
4376 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4377 struct ppc_link_hash_table
*htab
;
4378 bfd_size_type stub_group_size
;
4379 boolean stubs_always_before_branch
;
4381 asection
**list
= htab
->input_list
+ htab
->top_index
;
4384 asection
*tail
= *list
;
4385 if (tail
== bfd_abs_section_ptr
)
4387 while (tail
!= NULL
)
4391 bfd_size_type total
;
4394 if (tail
->_cooked_size
)
4395 total
= tail
->_cooked_size
;
4397 total
= tail
->_raw_size
;
4398 while ((prev
= PREV_SEC (curr
)) != NULL
4399 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4403 /* OK, the size from the start of CURR to the end is less
4404 than stub_group_size and thus can be handled by one stub
4405 section. (or the tail section is itself larger than
4406 stub_group_size, in which case we may be toast.) We
4407 should really be keeping track of the total size of stubs
4408 added here, as stubs contribute to the final output
4409 section size. That's a little tricky, and this way will
4410 only break if stubs added make the total size more than
4411 2^25, ie. for the default stub_group_size, if stubs total
4412 more than 2834432 bytes, or over 100000 plt call stubs. */
4415 prev
= PREV_SEC (tail
);
4416 /* Set up this stub group. */
4417 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4419 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4421 /* But wait, there's more! Input sections up to stub_group_size
4422 bytes before the stub section can be handled by it too. */
4423 if (!stubs_always_before_branch
)
4427 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4431 prev
= PREV_SEC (tail
);
4432 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4438 while (list
-- != htab
->input_list
);
4439 free (htab
->input_list
);
4443 /* Read in all local syms for all input bfds. */
4446 get_local_syms (input_bfd
, htab
)
4448 struct ppc_link_hash_table
*htab
;
4450 unsigned int bfd_indx
;
4451 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
4453 /* We want to read in symbol extension records only once. To do this
4454 we need to read in the local symbols in parallel and save them for
4455 later use; so hold pointers to the local symbols in an array. */
4456 bfd_size_type amt
= sizeof (Elf_Internal_Sym
*) * htab
->bfd_count
;
4457 all_local_syms
= (Elf_Internal_Sym
**) bfd_zmalloc (amt
);
4458 htab
->all_local_syms
= all_local_syms
;
4459 if (all_local_syms
== NULL
)
4462 /* Walk over all the input BFDs, swapping in local symbols.
4463 If we are creating a shared library, create hash entries for the
4467 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4469 Elf_Internal_Shdr
*symtab_hdr
;
4470 Elf_Internal_Shdr
*shndx_hdr
;
4471 Elf_Internal_Sym
*isym
;
4472 Elf64_External_Sym
*ext_syms
, *esym
, *end_sy
;
4473 Elf_External_Sym_Shndx
*shndx_buf
, *shndx
;
4474 bfd_size_type sec_size
;
4476 /* We'll need the symbol table in a second. */
4477 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4478 if (symtab_hdr
->sh_info
== 0)
4481 /* We need an array of the local symbols attached to the input bfd.
4482 Unfortunately, we're going to have to read & swap them in. */
4483 sec_size
= symtab_hdr
->sh_info
;
4484 sec_size
*= sizeof (Elf_Internal_Sym
);
4485 local_syms
= (Elf_Internal_Sym
*) bfd_malloc (sec_size
);
4486 if (local_syms
== NULL
)
4489 all_local_syms
[bfd_indx
] = local_syms
;
4490 sec_size
= symtab_hdr
->sh_info
;
4491 sec_size
*= sizeof (Elf64_External_Sym
);
4492 ext_syms
= (Elf64_External_Sym
*) bfd_malloc (sec_size
);
4493 if (ext_syms
== NULL
)
4496 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
4497 || bfd_bread ((PTR
) ext_syms
, sec_size
, input_bfd
) != sec_size
)
4499 error_ret_free_ext_syms
:
4505 shndx_hdr
= &elf_tdata (input_bfd
)->symtab_shndx_hdr
;
4506 if (shndx_hdr
->sh_size
!= 0)
4508 sec_size
= symtab_hdr
->sh_info
;
4509 sec_size
*= sizeof (Elf_External_Sym_Shndx
);
4510 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (sec_size
);
4511 if (shndx_buf
== NULL
)
4512 goto error_ret_free_ext_syms
;
4514 if (bfd_seek (input_bfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
4515 || bfd_bread ((PTR
) shndx_buf
, sec_size
, input_bfd
) != sec_size
)
4518 goto error_ret_free_ext_syms
;
4522 /* Swap the local symbols in. */
4523 for (esym
= ext_syms
, end_sy
= esym
+ symtab_hdr
->sh_info
,
4524 isym
= local_syms
, shndx
= shndx_buf
;
4526 esym
++, isym
++, shndx
= (shndx
? shndx
+ 1 : NULL
))
4527 bfd_elf64_swap_symbol_in (input_bfd
, esym
, shndx
, isym
);
4529 /* Now we can free the external symbols. */
4537 /* Determine and set the size of the stub section for a final link.
4539 The basic idea here is to examine all the relocations looking for
4540 PC-relative calls to a target that is unreachable with a "bl"
4544 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
4545 add_stub_section
, layout_sections_again
)
4548 struct bfd_link_info
*info
;
4549 bfd_signed_vma group_size
;
4550 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
4551 void (*layout_sections_again
) PARAMS ((void));
4553 bfd_size_type stub_group_size
;
4554 boolean stubs_always_before_branch
;
4555 boolean ret
= false;
4556 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4558 /* Stash our params away. */
4559 htab
->stub_bfd
= stub_bfd
;
4560 htab
->add_stub_section
= add_stub_section
;
4561 htab
->layout_sections_again
= layout_sections_again
;
4562 stubs_always_before_branch
= group_size
< 0;
4564 stub_group_size
= -group_size
;
4566 stub_group_size
= group_size
;
4567 if (stub_group_size
== 1)
4569 /* Default values. */
4570 stub_group_size
= 30720000;
4571 if (htab
->has_14bit_branch
)
4572 stub_group_size
= 30000;
4575 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4577 if (! get_local_syms (info
->input_bfds
, htab
))
4579 if (htab
->all_local_syms
)
4580 goto error_ret_free_local
;
4587 unsigned int bfd_indx
;
4589 boolean stub_changed
;
4591 htab
->stub_iteration
+= 1;
4592 stub_changed
= false;
4594 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4596 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4598 Elf_Internal_Shdr
*symtab_hdr
;
4600 Elf_Internal_Sym
*local_syms
;
4602 /* We'll need the symbol table in a second. */
4603 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4604 if (symtab_hdr
->sh_info
== 0)
4607 local_syms
= htab
->all_local_syms
[bfd_indx
];
4609 /* Walk over each section attached to the input bfd. */
4610 for (section
= input_bfd
->sections
;
4612 section
= section
->next
)
4614 Elf_Internal_Shdr
*input_rel_hdr
;
4615 Elf64_External_Rela
*external_relocs
, *erelaend
, *erela
;
4616 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4619 /* If there aren't any relocs, then there's nothing more
4621 if ((section
->flags
& SEC_RELOC
) == 0
4622 || section
->reloc_count
== 0)
4625 /* If this section is a link-once section that will be
4626 discarded, then don't create any stubs. */
4627 if (section
->output_section
== NULL
4628 || section
->output_section
->owner
!= output_bfd
)
4631 /* Allocate space for the external relocations. */
4632 amt
= section
->reloc_count
;
4633 amt
*= sizeof (Elf64_External_Rela
);
4634 external_relocs
= (Elf64_External_Rela
*) bfd_malloc (amt
);
4635 if (external_relocs
== NULL
)
4637 goto error_ret_free_local
;
4640 /* Likewise for the internal relocations. */
4641 amt
= section
->reloc_count
;
4642 amt
*= sizeof (Elf_Internal_Rela
);
4643 internal_relocs
= (Elf_Internal_Rela
*) bfd_malloc (amt
);
4644 if (internal_relocs
== NULL
)
4646 free (external_relocs
);
4647 goto error_ret_free_local
;
4650 /* Read in the external relocs. */
4651 input_rel_hdr
= &elf_section_data (section
)->rel_hdr
;
4652 if (bfd_seek (input_bfd
, input_rel_hdr
->sh_offset
, SEEK_SET
) != 0
4653 || bfd_bread ((PTR
) external_relocs
,
4654 input_rel_hdr
->sh_size
,
4655 input_bfd
) != input_rel_hdr
->sh_size
)
4657 free (external_relocs
);
4658 error_ret_free_internal
:
4659 free (internal_relocs
);
4660 goto error_ret_free_local
;
4663 /* Swap in the relocs. */
4664 erela
= external_relocs
;
4665 erelaend
= erela
+ section
->reloc_count
;
4666 irela
= internal_relocs
;
4667 for (; erela
< erelaend
; erela
++, irela
++)
4668 bfd_elf64_swap_reloca_in (input_bfd
, erela
, irela
);
4670 /* We're done with the external relocs, free them. */
4671 free (external_relocs
);
4673 /* Now examine each relocation. */
4674 irela
= internal_relocs
;
4675 irelaend
= irela
+ section
->reloc_count
;
4676 for (; irela
< irelaend
; irela
++)
4678 unsigned int r_type
, r_indx
;
4679 enum ppc_stub_type stub_type
;
4680 struct ppc_stub_hash_entry
*stub_entry
;
4683 bfd_vma destination
;
4684 struct ppc_link_hash_entry
*hash
;
4686 const asection
*id_sec
;
4688 r_type
= ELF64_R_TYPE (irela
->r_info
);
4689 r_indx
= ELF64_R_SYM (irela
->r_info
);
4691 if (r_type
>= (unsigned int) R_PPC_max
)
4693 bfd_set_error (bfd_error_bad_value
);
4694 goto error_ret_free_internal
;
4697 /* Only look for stubs on branch instructions. */
4698 if (r_type
!= (unsigned int) R_PPC64_REL24
4699 && r_type
!= (unsigned int) R_PPC64_REL14
4700 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
4701 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
4704 /* Now determine the call target, its name, value,
4710 if (r_indx
< symtab_hdr
->sh_info
)
4712 /* It's a local symbol. */
4713 Elf_Internal_Sym
*sym
;
4714 Elf_Internal_Shdr
*hdr
;
4716 sym
= local_syms
+ r_indx
;
4717 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
4718 sym_sec
= hdr
->bfd_section
;
4719 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4720 sym_value
= sym
->st_value
;
4721 destination
= (sym_value
+ irela
->r_addend
4722 + sym_sec
->output_offset
4723 + sym_sec
->output_section
->vma
);
4727 /* It's an external symbol. */
4730 e_indx
= r_indx
- symtab_hdr
->sh_info
;
4731 hash
= ((struct ppc_link_hash_entry
*)
4732 elf_sym_hashes (input_bfd
)[e_indx
]);
4734 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
4735 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
4736 hash
= ((struct ppc_link_hash_entry
*)
4737 hash
->elf
.root
.u
.i
.link
);
4739 if (hash
->elf
.root
.type
== bfd_link_hash_defined
4740 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
4742 sym_sec
= hash
->elf
.root
.u
.def
.section
;
4743 sym_value
= hash
->elf
.root
.u
.def
.value
;
4744 if (sym_sec
->output_section
!= NULL
)
4745 destination
= (sym_value
+ irela
->r_addend
4746 + sym_sec
->output_offset
4747 + sym_sec
->output_section
->vma
);
4749 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
4751 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
4755 bfd_set_error (bfd_error_bad_value
);
4756 goto error_ret_free_internal
;
4760 /* Determine what (if any) linker stub is needed. */
4761 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
4763 if (stub_type
== ppc_stub_none
)
4766 /* Support for grouping stub sections. */
4767 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
4769 /* Get the name of this stub. */
4770 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
4772 goto error_ret_free_internal
;
4774 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4775 stub_name
, false, false);
4776 if (stub_entry
!= NULL
)
4778 /* The proper stub has already been created. */
4783 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
4784 if (stub_entry
== NULL
)
4787 goto error_ret_free_local
;
4790 stub_entry
->target_value
= sym_value
;
4791 stub_entry
->target_section
= sym_sec
;
4792 stub_entry
->stub_type
= stub_type
;
4793 stub_entry
->h
= hash
;
4794 stub_changed
= true;
4797 /* We're done with the internal relocs, free them. */
4798 free (internal_relocs
);
4805 /* OK, we've added some stubs. Find out the new size of the
4807 for (stub_sec
= htab
->stub_bfd
->sections
;
4809 stub_sec
= stub_sec
->next
)
4811 stub_sec
->_raw_size
= 0;
4812 stub_sec
->_cooked_size
= 0;
4814 htab
->sbrlt
->_raw_size
= 0;
4815 htab
->sbrlt
->_cooked_size
= 0;
4817 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
4819 /* Ask the linker to do its stuff. */
4820 (*htab
->layout_sections_again
) ();
4823 if (htab
->sbrlt
->_raw_size
== 0)
4825 _bfd_strip_section_from_output (info
, htab
->sbrlt
);
4826 if (htab
->srelbrlt
!= NULL
)
4827 _bfd_strip_section_from_output (info
, htab
->srelbrlt
);
4832 error_ret_free_local
:
4833 while (htab
->bfd_count
-- > 0)
4834 if (htab
->all_local_syms
[htab
->bfd_count
])
4835 free (htab
->all_local_syms
[htab
->bfd_count
]);
4836 free (htab
->all_local_syms
);
4841 /* Called after we have determined section placement. If sections
4842 move, we'll be called again. Provide a value for TOCstart. */
4845 ppc64_elf_toc (obfd
)
4851 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
4852 order. The TOC starts where the first of these sections starts. */
4853 s
= bfd_get_section_by_name (obfd
, ".got");
4855 s
= bfd_get_section_by_name (obfd
, ".toc");
4857 s
= bfd_get_section_by_name (obfd
, ".tocbss");
4859 s
= bfd_get_section_by_name (obfd
, ".plt");
4862 /* This may happen for
4863 o references to TOC base (SYM@toc / TOC[tc0]) without a
4866 o --gc-sections and empty TOC sections
4868 FIXME: Warn user? */
4870 /* Look for a likely section. We probably won't even be
4872 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4873 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
4874 == (SEC_ALLOC
| SEC_SMALL_DATA
))
4877 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4878 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
4879 == (SEC_ALLOC
| SEC_SMALL_DATA
))
4882 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4883 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
4886 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
4887 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
4893 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
4898 /* Build all the stubs associated with the current output file.
4899 The stubs are kept in a hash table attached to the main linker
4900 hash table. This function is called via gldelf64ppc_finish. */
4903 ppc64_elf_build_stubs (info
)
4904 struct bfd_link_info
*info
;
4906 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4911 for (stub_sec
= htab
->stub_bfd
->sections
;
4913 stub_sec
= stub_sec
->next
)
4917 /* Allocate memory to hold the linker stubs. */
4918 size
= stub_sec
->_raw_size
;
4921 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
4922 if (stub_sec
->contents
== NULL
)
4925 stub_sec
->_cooked_size
= 0;
4928 if (htab
->splt
!= NULL
)
4930 /* Build the .glink plt call stub. */
4931 plt_r2
= (htab
->splt
->output_offset
4932 + htab
->splt
->output_section
->vma
4933 - elf_gp (htab
->splt
->output_section
->owner
)
4935 p
= htab
->sglink
->contents
;
4936 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
4937 while (p
- htab
->sglink
->contents
< GLINK_CALL_STUB_SIZE
)
4939 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
4942 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
4944 /* Use reloc_count to count entries. */
4945 htab
->sglink
->reloc_count
= 0;
4948 if (htab
->sbrlt
->_raw_size
!= 0)
4950 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
4951 htab
->sbrlt
->_raw_size
);
4952 if (htab
->sbrlt
->contents
== NULL
)
4956 /* Build the stubs as directed by the stub hash table. */
4957 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
4958 htab
->sglink
->reloc_count
= 0;
4960 for (stub_sec
= htab
->stub_bfd
->sections
;
4962 stub_sec
= stub_sec
->next
)
4964 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
4968 if (stub_sec
!= NULL
4969 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
4971 htab
->stub_error
= true;
4972 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
4975 return !htab
->stub_error
;
4978 /* Set up any other section flags and such that may be necessary. */
4981 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
4982 bfd
*abfd ATTRIBUTE_UNUSED
;
4983 Elf64_Internal_Shdr
*shdr
;
4986 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
4987 shdr
->sh_flags
|= SHF_EXCLUDE
;
4989 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
4990 shdr
->sh_type
= SHT_ORDERED
;
4995 /* The RELOCATE_SECTION function is called by the ELF backend linker
4996 to handle the relocations for a section.
4998 The relocs are always passed as Rela structures; if the section
4999 actually uses Rel structures, the r_addend field will always be
5002 This function is responsible for adjust the section contents as
5003 necessary, and (if using Rela relocs and generating a
5004 relocateable output file) adjusting the reloc addend as
5007 This function does not have to worry about setting the reloc
5008 address or the reloc symbol index.
5010 LOCAL_SYMS is a pointer to the swapped in local symbols.
5012 LOCAL_SECTIONS is an array giving the section in the input file
5013 corresponding to the st_shndx field of each local symbol.
5015 The global hash table entry for the global symbols can be found
5016 via elf_sym_hashes (input_bfd).
5018 When generating relocateable output, this function must handle
5019 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5020 going to be the section symbol corresponding to the output
5021 section, which means that the addend must be adjusted
5025 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5026 contents
, relocs
, local_syms
, local_sections
)
5028 struct bfd_link_info
*info
;
5030 asection
*input_section
;
5032 Elf_Internal_Rela
*relocs
;
5033 Elf_Internal_Sym
*local_syms
;
5034 asection
**local_sections
;
5036 struct ppc_link_hash_table
*htab
;
5037 Elf_Internal_Shdr
*symtab_hdr
;
5038 struct elf_link_hash_entry
**sym_hashes
;
5039 Elf_Internal_Rela
*rel
;
5040 Elf_Internal_Rela
*relend
;
5041 bfd_vma
*local_got_offsets
;
5045 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5046 boolean is_power4
= false;
5048 if (info
->relocateable
)
5051 /* Initialize howto table if needed. */
5052 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5055 htab
= ppc_hash_table (info
);
5056 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5057 TOCstart
= elf_gp (output_bfd
);
5058 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5059 sym_hashes
= elf_sym_hashes (input_bfd
);
5060 is_opd
= strcmp (bfd_get_section_name (abfd
, input_section
), ".opd") == 0;
5063 relend
= relocs
+ input_section
->reloc_count
;
5064 for (; rel
< relend
; rel
++)
5066 enum elf_ppc_reloc_type r_type
;
5069 bfd_reloc_status_type r
;
5070 Elf_Internal_Sym
*sym
;
5072 struct elf_link_hash_entry
*h
;
5073 struct elf_link_hash_entry
*fdh
;
5074 const char *sym_name
;
5075 unsigned long r_symndx
;
5077 boolean unresolved_reloc
;
5079 struct ppc_stub_hash_entry
*stub_entry
;
5080 bfd_vma max_br_offset
;
5083 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5084 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5085 offset
= rel
->r_offset
;
5086 addend
= rel
->r_addend
;
5087 r
= bfd_reloc_other
;
5088 sym
= (Elf_Internal_Sym
*) 0;
5089 sec
= (asection
*) 0;
5090 h
= (struct elf_link_hash_entry
*) 0;
5091 sym_name
= (const char *) 0;
5092 unresolved_reloc
= false;
5094 if (r_type
== R_PPC64_TOC
)
5096 /* Relocation value is TOC base. Symbol is ignored. */
5097 relocation
= TOCstart
+ TOC_BASE_OFF
;
5099 else if (r_symndx
< symtab_hdr
->sh_info
)
5101 /* It's a local symbol. */
5102 sym
= local_syms
+ r_symndx
;
5103 sec
= local_sections
[r_symndx
];
5104 sym_name
= "<local symbol>";
5106 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
5107 /* rel may have changed, update our copy of addend. */
5108 addend
= rel
->r_addend
;
5112 /* It's a global symbol. */
5113 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5114 while (h
->root
.type
== bfd_link_hash_indirect
5115 || h
->root
.type
== bfd_link_hash_warning
)
5116 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5117 sym_name
= h
->root
.root
.string
;
5119 if (h
->root
.type
== bfd_link_hash_defined
5120 || h
->root
.type
== bfd_link_hash_defweak
)
5122 sec
= h
->root
.u
.def
.section
;
5123 if (sec
->output_section
== NULL
)
5124 /* Set a flag that will be cleared later if we find a
5125 relocation value for this symbol. output_section
5126 is typically NULL for symbols satisfied by a shared
5128 unresolved_reloc
= true;
5130 relocation
= (h
->root
.u
.def
.value
5131 + sec
->output_section
->vma
5132 + sec
->output_offset
);
5134 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5136 else if (info
->shared
5137 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
5138 && !info
->no_undefined
5139 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5143 if (! ((*info
->callbacks
->undefined_symbol
)
5144 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5145 offset
, (!info
->shared
5146 || info
->no_undefined
5147 || ELF_ST_VISIBILITY (h
->other
)))))
5152 /* First handle relocations that tweak non-addend part of insn. */
5159 /* Branch taken prediction relocations. */
5160 case R_PPC64_ADDR14_BRTAKEN
:
5161 case R_PPC64_REL14_BRTAKEN
:
5162 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5165 /* Branch not taken prediction relocations. */
5166 case R_PPC64_ADDR14_BRNTAKEN
:
5167 case R_PPC64_REL14_BRNTAKEN
:
5168 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
5171 /* Set 'a' bit. This is 0b00010 in BO field for branch
5172 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5173 for branch on CTR insns (BO == 1a00t or 1a01t). */
5174 if ((insn
& (0x14 << 21)) == (0x04 << 21))
5176 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
5184 + input_section
->output_offset
5185 + input_section
->output_section
->vma
);
5187 /* Invert 'y' bit if not the default. */
5188 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
5192 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
5196 /* A REL24 branching to a linkage function is followed by a
5197 nop. We replace the nop with a ld in order to restore
5198 the TOC base pointer. Only calls to shared objects need
5199 to alter the TOC base. These are recognized by their
5200 need for a PLT entry. */
5202 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
5203 && fdh
->plt
.offset
!= (bfd_vma
) -1
5204 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
5205 rel
, htab
)) != NULL
)
5207 boolean can_plt_call
= 0;
5209 if (offset
+ 8 <= input_section
->_cooked_size
)
5211 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
5213 || insn
== CROR_151515
|| insn
== CROR_313131
)
5215 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
5216 contents
+ offset
+ 4);
5223 /* If this is a plain branch rather than a branch
5224 and link, don't require a nop. */
5225 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5226 if ((insn
& 1) == 0)
5232 relocation
= (stub_entry
->stub_offset
5233 + stub_entry
->stub_sec
->output_offset
5234 + stub_entry
->stub_sec
->output_section
->vma
);
5236 unresolved_reloc
= false;
5241 && h
->root
.type
== bfd_link_hash_undefweak
5245 /* Tweak calls to undefined weak functions to point at a
5246 blr. We can thus call a weak function without first
5247 checking whether the function is defined. We have a
5248 blr at the end of .sfpr. */
5249 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
5250 relocation
= (htab
->sfpr
->_raw_size
- 4
5251 + htab
->sfpr
->output_offset
5252 + htab
->sfpr
->output_section
->vma
);
5254 + input_section
->output_offset
5255 + input_section
->output_section
->vma
);
5257 /* But let's not be silly about it. If the blr isn't in
5258 reach, just go to the next instruction. */
5259 if (relocation
- from
+ (1 << 25) >= (1 << 26)
5260 || htab
->sfpr
->_raw_size
== 0)
5261 relocation
= from
+ 4;
5270 (*_bfd_error_handler
)
5271 (_("%s: unknown relocation type %d for symbol %s"),
5272 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5274 bfd_set_error (bfd_error_bad_value
);
5279 case R_PPC_GNU_VTINHERIT
:
5280 case R_PPC_GNU_VTENTRY
:
5283 /* GOT16 relocations. Like an ADDR16 using the symbol's
5284 address in the GOT as relocation value instead of the
5285 symbols value itself. Also, create a GOT entry for the
5286 symbol and put the symbol value there. */
5288 case R_PPC64_GOT16_LO
:
5289 case R_PPC64_GOT16_HI
:
5290 case R_PPC64_GOT16_HA
:
5291 case R_PPC64_GOT16_DS
:
5292 case R_PPC64_GOT16_LO_DS
:
5294 /* Relocation is to the entry for this symbol in the global
5298 if (htab
->sgot
== NULL
)
5305 off
= h
->got
.offset
;
5306 dyn
= htab
->elf
.dynamic_sections_created
;
5307 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5311 || (h
->elf_link_hash_flags
5312 & ELF_LINK_FORCED_LOCAL
))
5313 && (h
->elf_link_hash_flags
5314 & ELF_LINK_HASH_DEF_REGULAR
)))
5316 /* This is actually a static link, or it is a
5317 -Bsymbolic link and the symbol is defined
5318 locally, or the symbol was forced to be local
5319 because of a version file. We must initialize
5320 this entry in the global offset table. Since the
5321 offset must always be a multiple of 8, we use the
5322 least significant bit to record whether we have
5323 initialized it already.
5325 When doing a dynamic link, we create a .rel.got
5326 relocation entry to initialize the value. This
5327 is done in the finish_dynamic_symbol routine. */
5332 bfd_put_64 (output_bfd
, relocation
,
5333 htab
->sgot
->contents
+ off
);
5338 unresolved_reloc
= false;
5342 if (local_got_offsets
== NULL
)
5345 off
= local_got_offsets
[r_symndx
];
5347 /* The offset must always be a multiple of 8. We use
5348 the least significant bit to record whether we have
5349 already processed this entry. */
5354 bfd_put_64 (output_bfd
, relocation
,
5355 htab
->sgot
->contents
+ off
);
5359 Elf_Internal_Rela outrel
;
5360 Elf64_External_Rela
*loc
;
5362 /* We need to generate a R_PPC64_RELATIVE reloc
5363 for the dynamic linker. */
5364 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5365 + htab
->sgot
->output_offset
5367 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5368 outrel
.r_addend
= relocation
;
5369 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5370 loc
+= htab
->srelgot
->reloc_count
++;
5371 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5374 local_got_offsets
[r_symndx
] |= 1;
5378 if (off
>= (bfd_vma
) -2)
5381 relocation
= htab
->sgot
->output_offset
+ off
;
5383 /* TOC base (r2) is TOC start plus 0x8000. */
5384 addend
-= TOC_BASE_OFF
;
5388 case R_PPC64_PLT16_HA
:
5389 case R_PPC64_PLT16_HI
:
5390 case R_PPC64_PLT16_LO
:
5393 /* Relocation is to the entry for this symbol in the
5394 procedure linkage table. */
5396 /* Resolve a PLT reloc against a local symbol directly,
5397 without using the procedure linkage table. */
5401 if (h
->plt
.offset
== (bfd_vma
) -1
5402 || htab
->splt
== NULL
)
5404 /* We didn't make a PLT entry for this symbol. This
5405 happens when statically linking PIC code, or when
5406 using -Bsymbolic. */
5410 relocation
= (htab
->splt
->output_section
->vma
5411 + htab
->splt
->output_offset
5413 unresolved_reloc
= false;
5416 /* TOC16 relocs. We want the offset relative to the TOC base,
5417 which is the address of the start of the TOC plus 0x8000.
5418 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5421 case R_PPC64_TOC16_LO
:
5422 case R_PPC64_TOC16_HI
:
5423 case R_PPC64_TOC16_DS
:
5424 case R_PPC64_TOC16_LO_DS
:
5425 case R_PPC64_TOC16_HA
:
5426 addend
-= TOCstart
+ TOC_BASE_OFF
;
5429 /* Relocate against the beginning of the section. */
5430 case R_PPC64_SECTOFF
:
5431 case R_PPC64_SECTOFF_LO
:
5432 case R_PPC64_SECTOFF_HI
:
5433 case R_PPC64_SECTOFF_DS
:
5434 case R_PPC64_SECTOFF_LO_DS
:
5435 case R_PPC64_SECTOFF_HA
:
5436 if (sec
!= (asection
*) 0)
5437 addend
-= sec
->output_section
->vma
;
5441 case R_PPC64_REL14_BRNTAKEN
:
5442 case R_PPC64_REL14_BRTAKEN
:
5446 /* Relocations that may need to be propagated if this is a
5450 case R_PPC64_ADDR14
:
5451 case R_PPC64_ADDR14_BRNTAKEN
:
5452 case R_PPC64_ADDR14_BRTAKEN
:
5453 case R_PPC64_ADDR16
:
5454 case R_PPC64_ADDR16_DS
:
5455 case R_PPC64_ADDR16_HA
:
5456 case R_PPC64_ADDR16_HI
:
5457 case R_PPC64_ADDR16_HIGHER
:
5458 case R_PPC64_ADDR16_HIGHERA
:
5459 case R_PPC64_ADDR16_HIGHEST
:
5460 case R_PPC64_ADDR16_HIGHESTA
:
5461 case R_PPC64_ADDR16_LO
:
5462 case R_PPC64_ADDR16_LO_DS
:
5463 case R_PPC64_ADDR24
:
5464 case R_PPC64_ADDR30
:
5465 case R_PPC64_ADDR32
:
5466 case R_PPC64_ADDR64
:
5467 case R_PPC64_UADDR16
:
5468 case R_PPC64_UADDR32
:
5469 case R_PPC64_UADDR64
:
5470 /* r_symndx will be zero only for relocs against symbols
5471 from removed linkonce sections, or sections discarded by
5478 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5481 if (NO_OPD_RELOCS
&& is_opd
)
5485 && (IS_ABSOLUTE_RELOC (r_type
)
5488 && (! info
->symbolic
5489 || (h
->elf_link_hash_flags
5490 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5494 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5495 && (((h
->elf_link_hash_flags
5496 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5497 && (h
->elf_link_hash_flags
5498 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5499 || h
->root
.type
== bfd_link_hash_undefweak
5500 || h
->root
.type
== bfd_link_hash_undefined
)))
5502 Elf_Internal_Rela outrel
;
5503 boolean skip
, relocate
;
5505 Elf64_External_Rela
*loc
;
5507 /* When generating a dynamic object, these relocations
5508 are copied into the output file to be resolved at run
5515 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5517 if (outrel
.r_offset
== (bfd_vma
) -1)
5519 else if (outrel
.r_offset
== (bfd_vma
) -2)
5520 skip
= true, relocate
= true;
5521 outrel
.r_offset
+= (input_section
->output_section
->vma
5522 + input_section
->output_offset
);
5523 outrel
.r_addend
= addend
;
5526 memset (&outrel
, 0, sizeof outrel
);
5530 && (!IS_ABSOLUTE_RELOC (r_type
)
5533 || (h
->elf_link_hash_flags
5534 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5535 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5538 /* This symbol is local, or marked to become local,
5539 or this is an opd section reloc which must point
5540 at a local function. */
5541 outrel
.r_addend
+= relocation
;
5543 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5545 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5551 if (bfd_is_abs_section (sec
))
5553 else if (sec
== NULL
|| sec
->owner
== NULL
)
5555 bfd_set_error (bfd_error_bad_value
);
5562 osec
= sec
->output_section
;
5563 indx
= elf_section_data (osec
)->dynindx
;
5565 /* We are turning this relocation into one
5566 against a section symbol, so subtract out
5567 the output section's address but not the
5568 offset of the input section in the output
5570 outrel
.r_addend
-= osec
->vma
;
5573 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
5577 sreloc
= elf_section_data (input_section
)->sreloc
;
5581 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
5582 loc
+= sreloc
->reloc_count
++;
5583 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5585 /* If this reloc is against an external symbol, it will
5586 be computed at runtime, so there's no need to do
5594 case R_PPC64_GLOB_DAT
:
5595 case R_PPC64_JMP_SLOT
:
5596 case R_PPC64_RELATIVE
:
5597 /* We shouldn't ever see these dynamic relocs in relocatable
5601 case R_PPC64_PLTGOT16
:
5602 case R_PPC64_PLTGOT16_DS
:
5603 case R_PPC64_PLTGOT16_HA
:
5604 case R_PPC64_PLTGOT16_HI
:
5605 case R_PPC64_PLTGOT16_LO
:
5606 case R_PPC64_PLTGOT16_LO_DS
:
5607 case R_PPC64_PLTREL32
:
5608 case R_PPC64_PLTREL64
:
5609 /* These ones haven't been implemented yet. */
5611 (*_bfd_error_handler
)
5612 (_("%s: Relocation %s is not supported for symbol %s."),
5613 bfd_archive_filename (input_bfd
),
5614 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
5616 bfd_set_error (bfd_error_invalid_operation
);
5621 /* Do any further special processing. */
5627 case R_PPC64_ADDR16_HA
:
5628 case R_PPC64_ADDR16_HIGHERA
:
5629 case R_PPC64_ADDR16_HIGHESTA
:
5630 case R_PPC64_PLT16_HA
:
5631 case R_PPC64_TOC16_HA
:
5632 case R_PPC64_SECTOFF_HA
:
5633 /* It's just possible that this symbol is a weak symbol
5634 that's not actually defined anywhere. In that case,
5635 'sec' would be NULL, and we should leave the symbol
5636 alone (it will be set to zero elsewhere in the link). */
5638 /* Add 0x10000 if sign bit in 0:15 is set. */
5639 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
5642 case R_PPC64_ADDR16_DS
:
5643 case R_PPC64_ADDR16_LO_DS
:
5644 case R_PPC64_GOT16_DS
:
5645 case R_PPC64_GOT16_LO_DS
:
5646 case R_PPC64_PLT16_LO_DS
:
5647 case R_PPC64_SECTOFF_DS
:
5648 case R_PPC64_SECTOFF_LO_DS
:
5649 case R_PPC64_TOC16_DS
:
5650 case R_PPC64_TOC16_LO_DS
:
5651 case R_PPC64_PLTGOT16_DS
:
5652 case R_PPC64_PLTGOT16_LO_DS
:
5653 if (((relocation
+ addend
) & 3) != 0)
5655 (*_bfd_error_handler
)
5656 (_("%s: error: relocation %s not a multiple of 4"),
5657 bfd_archive_filename (input_bfd
),
5658 ppc64_elf_howto_table
[(int) r_type
]->name
);
5659 bfd_set_error (bfd_error_bad_value
);
5666 case R_PPC64_REL14_BRNTAKEN
:
5667 case R_PPC64_REL14_BRTAKEN
:
5668 max_br_offset
= 1 << 15;
5672 max_br_offset
= 1 << 25;
5675 /* If the branch is out of reach, then redirect the
5676 call to the local stub for this function. */
5678 + input_section
->output_offset
5679 + input_section
->output_section
->vma
);
5680 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
5681 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
5682 rel
, htab
)) != NULL
)
5684 /* Munge up the value and addend so that we call the stub
5685 rather than the procedure directly. */
5686 relocation
= (stub_entry
->stub_offset
5687 + stub_entry
->stub_sec
->output_offset
5688 + stub_entry
->stub_sec
->output_section
->vma
);
5694 /* FIXME: Why do we allow debugging sections to escape this error?
5695 More importantly, why do we not emit dynamic relocs above in
5696 debugging sections (which are ! SEC_ALLOC)? If we had
5697 emitted the dynamic reloc, we could remove the fudge here. */
5698 if (unresolved_reloc
5700 && (input_section
->flags
& SEC_DEBUGGING
) != 0
5701 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5702 (*_bfd_error_handler
)
5703 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5704 bfd_archive_filename (input_bfd
),
5705 bfd_get_section_name (input_bfd
, input_section
),
5706 (long) rel
->r_offset
,
5707 h
->root
.root
.string
);
5709 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
5717 if (r
== bfd_reloc_ok
)
5719 else if (r
== bfd_reloc_overflow
)
5725 if (h
->root
.type
== bfd_link_hash_undefweak
5726 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
5728 /* Assume this is a call protected by other code that
5729 detects the symbol is undefined. If this is the case,
5730 we can safely ignore the overflow. If not, the
5731 program is hosed anyway, and a little warning isn't
5737 name
= h
->root
.root
.string
;
5741 name
= bfd_elf_string_from_elf_section (input_bfd
,
5742 symtab_hdr
->sh_link
,
5747 name
= bfd_section_name (input_bfd
, sec
);
5750 if (! ((*info
->callbacks
->reloc_overflow
)
5751 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
5752 (bfd_vma
) 0, input_bfd
, input_section
, offset
)))
5762 /* Finish up dynamic symbol handling. We set the contents of various
5763 dynamic sections here. */
5766 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
5768 struct bfd_link_info
*info
;
5769 struct elf_link_hash_entry
*h
;
5770 Elf_Internal_Sym
*sym
;
5772 struct ppc_link_hash_table
*htab
;
5775 htab
= ppc_hash_table (info
);
5776 dynobj
= htab
->elf
.dynobj
;
5778 if (h
->plt
.offset
!= (bfd_vma
) -1
5779 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
5781 Elf_Internal_Rela rela
;
5782 Elf64_External_Rela
*loc
;
5784 /* This symbol has an entry in the procedure linkage table. Set
5787 if (htab
->splt
== NULL
5788 || htab
->srelplt
== NULL
5789 || htab
->sglink
== NULL
)
5792 /* Create a JMP_SLOT reloc to inform the dynamic linker to
5793 fill in the PLT entry. */
5795 rela
.r_offset
= (htab
->splt
->output_section
->vma
5796 + htab
->splt
->output_offset
5798 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
5801 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
5802 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
5803 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
5806 if (h
->got
.offset
!= (bfd_vma
) -1)
5808 Elf_Internal_Rela rela
;
5809 Elf64_External_Rela
*loc
;
5811 /* This symbol has an entry in the global offset table. Set it
5814 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
5817 rela
.r_offset
= (htab
->sgot
->output_section
->vma
5818 + htab
->sgot
->output_offset
5819 + (h
->got
.offset
&~ (bfd_vma
) 1));
5821 /* If this is a static link, or it is a -Bsymbolic link and the
5822 symbol is defined locally or was forced to be local because
5823 of a version file, we just want to emit a RELATIVE reloc.
5824 The entry in the global offset table will already have been
5825 initialized in the relocate_section function. */
5829 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
5830 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
5832 BFD_ASSERT((h
->got
.offset
& 1) != 0);
5833 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5834 rela
.r_addend
= (h
->root
.u
.def
.value
5835 + h
->root
.u
.def
.section
->output_section
->vma
5836 + h
->root
.u
.def
.section
->output_offset
);
5840 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
5841 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
5842 htab
->sgot
->contents
+ h
->got
.offset
);
5843 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
5847 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5848 loc
+= htab
->srelgot
->reloc_count
++;
5849 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
5852 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
5854 Elf_Internal_Rela rela
;
5855 Elf64_External_Rela
*loc
;
5857 /* This symbol needs a copy reloc. Set it up. */
5859 if (h
->dynindx
== -1
5860 || (h
->root
.type
!= bfd_link_hash_defined
5861 && h
->root
.type
!= bfd_link_hash_defweak
)
5862 || htab
->srelbss
== NULL
)
5865 rela
.r_offset
= (h
->root
.u
.def
.value
5866 + h
->root
.u
.def
.section
->output_section
->vma
5867 + h
->root
.u
.def
.section
->output_offset
);
5868 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
5870 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
5871 loc
+= htab
->srelbss
->reloc_count
++;
5872 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
5875 /* Mark some specially defined symbols as absolute. */
5876 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
5877 sym
->st_shndx
= SHN_ABS
;
5882 /* Used to decide how to sort relocs in an optimal manner for the
5883 dynamic linker, before writing them out. */
5885 static enum elf_reloc_type_class
5886 ppc64_elf_reloc_type_class (rela
)
5887 const Elf_Internal_Rela
*rela
;
5889 enum elf_ppc_reloc_type r_type
;
5891 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
5894 case R_PPC64_RELATIVE
:
5895 return reloc_class_relative
;
5896 case R_PPC64_JMP_SLOT
:
5897 return reloc_class_plt
;
5899 return reloc_class_copy
;
5901 return reloc_class_normal
;
5905 /* Finish up the dynamic sections. */
5908 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
5910 struct bfd_link_info
*info
;
5912 struct ppc_link_hash_table
*htab
;
5916 htab
= ppc_hash_table (info
);
5917 dynobj
= htab
->elf
.dynobj
;
5918 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
5920 if (htab
->elf
.dynamic_sections_created
)
5922 Elf64_External_Dyn
*dyncon
, *dynconend
;
5924 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
5927 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
5928 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
5929 for (; dyncon
< dynconend
; dyncon
++)
5931 Elf_Internal_Dyn dyn
;
5934 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5941 case DT_PPC64_GLINK
:
5942 dyn
.d_un
.d_ptr
= (htab
->sglink
->output_section
->vma
5943 + htab
->sglink
->output_offset
);
5947 s
= bfd_get_section_by_name (output_bfd
, ".opd");
5949 dyn
.d_un
.d_ptr
= s
->vma
;
5952 case DT_PPC64_OPDSZ
:
5953 s
= bfd_get_section_by_name (output_bfd
, ".opd");
5955 dyn
.d_un
.d_val
= s
->_raw_size
;
5959 dyn
.d_un
.d_ptr
= (htab
->splt
->output_section
->vma
5960 + htab
->splt
->output_offset
);
5964 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
5965 + htab
->srelplt
->output_offset
);
5969 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
5973 /* Don't count procedure linkage table relocs in the
5974 overall reloc count. */
5975 if (htab
->srelplt
!= NULL
)
5976 dyn
.d_un
.d_val
-= htab
->srelplt
->_raw_size
;
5980 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
5984 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
5986 /* Fill in the first entry in the global offset table.
5987 We use it to hold the link-time TOCbase. */
5988 bfd_put_64 (output_bfd
,
5989 elf_gp (output_bfd
) + TOC_BASE_OFF
,
5990 htab
->sgot
->contents
);
5992 /* Set .got entry size. */
5993 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
5996 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
5998 /* Set .plt entry size. */
5999 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
6006 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6007 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6008 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6009 #define TARGET_BIG_NAME "elf64-powerpc"
6010 #define ELF_ARCH bfd_arch_powerpc
6011 #define ELF_MACHINE_CODE EM_PPC64
6012 #define ELF_MAXPAGESIZE 0x10000
6013 #define elf_info_to_howto ppc64_elf_info_to_howto
6015 #ifdef EM_CYGNUS_POWERPC
6016 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6020 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6023 #define elf_backend_want_got_sym 0
6024 #define elf_backend_want_plt_sym 0
6025 #define elf_backend_plt_alignment 3
6026 #define elf_backend_plt_not_loaded 1
6027 #define elf_backend_got_symbol_offset 0
6028 #define elf_backend_got_header_size 8
6029 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6030 #define elf_backend_can_gc_sections 1
6031 #define elf_backend_can_refcount 1
6032 #define elf_backend_rela_normal 1
6034 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6035 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
6036 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6037 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6038 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6040 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
6041 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6042 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6043 #define elf_backend_check_relocs ppc64_elf_check_relocs
6044 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6045 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6046 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6047 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6048 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6049 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6050 #define elf_backend_fake_sections ppc64_elf_fake_sections
6051 #define elf_backend_relocate_section ppc64_elf_relocate_section
6052 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6053 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6054 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6056 #include "elf64-target.h"