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 void ppc64_elf_get_symbol_info
59 PARAMS ((bfd
*, asymbol
*, symbol_info
*));
60 static boolean ppc64_elf_object_p
62 static boolean ppc64_elf_set_private_flags
63 PARAMS ((bfd
*, flagword
));
64 static boolean ppc64_elf_merge_private_bfd_data
65 PARAMS ((bfd
*, bfd
*));
66 static boolean ppc64_elf_section_from_shdr
67 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, const char *));
70 /* The name of the dynamic interpreter. This is put in the .interp
72 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
74 /* The size in bytes of an entry in the procedure linkage table. */
75 #define PLT_ENTRY_SIZE 24
77 /* The initial size of the plt reserved for the dynamic linker. */
78 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
80 /* TOC base pointers offset from start of TOC. */
81 #define TOC_BASE_OFF (0x8000)
83 /* .plt call stub instructions. */
84 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
85 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
86 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
87 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
88 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
89 /* ld %r11,xxx+16@l(%r12) */
90 #define BCTR 0x4e800420 /* bctr */
92 /* The normal stub is this size. */
93 #define PLT_CALL_STUB_SIZE (7*4)
95 /* But sometimes the .plt entry crosses a 64k boundary, and we need
96 to adjust the high word with this insn. */
97 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
99 /* The .glink fixup call stub is the same as the .plt call stub, but
100 the first instruction restores r2, and the std is omitted. */
101 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
103 /* Always allow this much space. */
104 #define GLINK_CALL_STUB_SIZE (8*4)
107 #define NOP 0x60000000
109 /* Some other nops. */
110 #define CROR_151515 0x4def7b82
111 #define CROR_313131 0x4ffffb82
113 /* .glink entries for the first 32k functions are two instructions. */
114 #define LI_R0_0 0x38000000 /* li %r0,0 */
115 #define B_DOT 0x48000000 /* b . */
117 /* After that, we need two instructions to load the index, followed by
119 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
120 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
122 /* Instructions to save and restore floating point regs. */
123 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
124 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
125 #define BLR 0x4e800020 /* blr */
127 /* Since .opd is an array of descriptors and each entry will end up
128 with identical R_PPC64_RELATIVE relocs, there is really no need to
129 propagate .opd relocs; The dynamic linker should be taught to
130 relocate .opd without reloc entries. */
131 #ifndef NO_OPD_RELOCS
132 #define NO_OPD_RELOCS 0
135 /* Relocation HOWTO's. */
136 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
138 static reloc_howto_type ppc64_elf_howto_raw
[] = {
139 /* This reloc does nothing. */
140 HOWTO (R_PPC64_NONE
, /* type */
142 2, /* size (0 = byte, 1 = short, 2 = long) */
144 false, /* pc_relative */
146 complain_overflow_bitfield
, /* complain_on_overflow */
147 bfd_elf_generic_reloc
, /* special_function */
148 "R_PPC64_NONE", /* name */
149 false, /* partial_inplace */
152 false), /* pcrel_offset */
154 /* A standard 32 bit relocation. */
155 HOWTO (R_PPC64_ADDR32
, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 false, /* pc_relative */
161 complain_overflow_bitfield
, /* complain_on_overflow */
162 bfd_elf_generic_reloc
, /* special_function */
163 "R_PPC64_ADDR32", /* name */
164 false, /* partial_inplace */
166 0xffffffff, /* dst_mask */
167 false), /* pcrel_offset */
169 /* An absolute 26 bit branch; the lower two bits must be zero.
170 FIXME: we don't check that, we just clear them. */
171 HOWTO (R_PPC64_ADDR24
, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 false, /* pc_relative */
177 complain_overflow_bitfield
, /* complain_on_overflow */
178 bfd_elf_generic_reloc
, /* special_function */
179 "R_PPC64_ADDR24", /* name */
180 false, /* partial_inplace */
182 0x3fffffc, /* dst_mask */
183 false), /* pcrel_offset */
185 /* A standard 16 bit relocation. */
186 HOWTO (R_PPC64_ADDR16
, /* type */
188 1, /* size (0 = byte, 1 = short, 2 = long) */
190 false, /* pc_relative */
192 complain_overflow_bitfield
, /* complain_on_overflow */
193 bfd_elf_generic_reloc
, /* special_function */
194 "R_PPC64_ADDR16", /* name */
195 false, /* partial_inplace */
197 0xffff, /* dst_mask */
198 false), /* pcrel_offset */
200 /* A 16 bit relocation without overflow. */
201 HOWTO (R_PPC64_ADDR16_LO
, /* type */
203 1, /* size (0 = byte, 1 = short, 2 = long) */
205 false, /* pc_relative */
207 complain_overflow_dont
,/* complain_on_overflow */
208 bfd_elf_generic_reloc
, /* special_function */
209 "R_PPC64_ADDR16_LO", /* name */
210 false, /* partial_inplace */
212 0xffff, /* dst_mask */
213 false), /* pcrel_offset */
215 /* Bits 16-31 of an address. */
216 HOWTO (R_PPC64_ADDR16_HI
, /* type */
218 1, /* size (0 = byte, 1 = short, 2 = long) */
220 false, /* pc_relative */
222 complain_overflow_dont
, /* complain_on_overflow */
223 bfd_elf_generic_reloc
, /* special_function */
224 "R_PPC64_ADDR16_HI", /* name */
225 false, /* partial_inplace */
227 0xffff, /* dst_mask */
228 false), /* pcrel_offset */
230 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
231 bits, treated as a signed number, is negative. */
232 HOWTO (R_PPC64_ADDR16_HA
, /* type */
234 1, /* size (0 = byte, 1 = short, 2 = long) */
236 false, /* pc_relative */
238 complain_overflow_dont
, /* complain_on_overflow */
239 ppc64_elf_ha_reloc
, /* special_function */
240 "R_PPC64_ADDR16_HA", /* name */
241 false, /* partial_inplace */
243 0xffff, /* dst_mask */
244 false), /* pcrel_offset */
246 /* An absolute 16 bit branch; the lower two bits must be zero.
247 FIXME: we don't check that, we just clear them. */
248 HOWTO (R_PPC64_ADDR14
, /* type */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 false, /* pc_relative */
254 complain_overflow_bitfield
, /* complain_on_overflow */
255 bfd_elf_generic_reloc
, /* special_function */
256 "R_PPC64_ADDR14", /* name */
257 false, /* partial_inplace */
259 0xfffc, /* dst_mask */
260 false), /* pcrel_offset */
262 /* An absolute 16 bit branch, for which bit 10 should be set to
263 indicate that the branch is expected to be taken. The lower two
264 bits must be zero. */
265 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
267 2, /* size (0 = byte, 1 = short, 2 = long) */
269 false, /* pc_relative */
271 complain_overflow_bitfield
, /* complain_on_overflow */
272 ppc64_elf_brtaken_reloc
, /* special_function */
273 "R_PPC64_ADDR14_BRTAKEN",/* name */
274 false, /* partial_inplace */
276 0xfffc, /* dst_mask */
277 false), /* pcrel_offset */
279 /* An absolute 16 bit branch, for which bit 10 should be set to
280 indicate that the branch is not expected to be taken. The lower
281 two bits must be zero. */
282 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 false, /* pc_relative */
288 complain_overflow_bitfield
, /* complain_on_overflow */
289 ppc64_elf_brtaken_reloc
, /* special_function */
290 "R_PPC64_ADDR14_BRNTAKEN",/* name */
291 false, /* partial_inplace */
293 0xfffc, /* dst_mask */
294 false), /* pcrel_offset */
296 /* A relative 26 bit branch; the lower two bits must be zero. */
297 HOWTO (R_PPC64_REL24
, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 true, /* pc_relative */
303 complain_overflow_signed
, /* complain_on_overflow */
304 bfd_elf_generic_reloc
, /* special_function */
305 "R_PPC64_REL24", /* name */
306 false, /* partial_inplace */
308 0x3fffffc, /* dst_mask */
309 true), /* pcrel_offset */
311 /* A relative 16 bit branch; the lower two bits must be zero. */
312 HOWTO (R_PPC64_REL14
, /* type */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
316 true, /* pc_relative */
318 complain_overflow_signed
, /* complain_on_overflow */
319 bfd_elf_generic_reloc
, /* special_function */
320 "R_PPC64_REL14", /* name */
321 false, /* partial_inplace */
323 0xfffc, /* dst_mask */
324 true), /* pcrel_offset */
326 /* A relative 16 bit branch. Bit 10 should be set to indicate that
327 the branch is expected to be taken. The lower two bits must be
329 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 true, /* pc_relative */
335 complain_overflow_signed
, /* complain_on_overflow */
336 ppc64_elf_brtaken_reloc
, /* special_function */
337 "R_PPC64_REL14_BRTAKEN", /* name */
338 false, /* partial_inplace */
340 0xfffc, /* dst_mask */
341 true), /* pcrel_offset */
343 /* A relative 16 bit branch. Bit 10 should be set to indicate that
344 the branch is not expected to be taken. The lower two bits must
346 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 true, /* pc_relative */
352 complain_overflow_signed
, /* complain_on_overflow */
353 ppc64_elf_brtaken_reloc
, /* special_function */
354 "R_PPC64_REL14_BRNTAKEN",/* name */
355 false, /* partial_inplace */
357 0xfffc, /* dst_mask */
358 true), /* pcrel_offset */
360 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
362 HOWTO (R_PPC64_GOT16
, /* type */
364 1, /* size (0 = byte, 1 = short, 2 = long) */
366 false, /* pc_relative */
368 complain_overflow_signed
, /* complain_on_overflow */
369 ppc64_elf_unhandled_reloc
, /* special_function */
370 "R_PPC64_GOT16", /* name */
371 false, /* partial_inplace */
373 0xffff, /* dst_mask */
374 false), /* pcrel_offset */
376 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
378 HOWTO (R_PPC64_GOT16_LO
, /* type */
380 1, /* size (0 = byte, 1 = short, 2 = long) */
382 false, /* pc_relative */
384 complain_overflow_dont
, /* complain_on_overflow */
385 ppc64_elf_unhandled_reloc
, /* special_function */
386 "R_PPC64_GOT16_LO", /* name */
387 false, /* partial_inplace */
389 0xffff, /* dst_mask */
390 false), /* pcrel_offset */
392 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
394 HOWTO (R_PPC64_GOT16_HI
, /* type */
396 1, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_dont
,/* complain_on_overflow */
401 ppc64_elf_unhandled_reloc
, /* special_function */
402 "R_PPC64_GOT16_HI", /* name */
403 false, /* partial_inplace */
405 0xffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
410 HOWTO (R_PPC64_GOT16_HA
, /* type */
412 1, /* size (0 = byte, 1 = short, 2 = long) */
414 false, /* pc_relative */
416 complain_overflow_dont
,/* complain_on_overflow */
417 ppc64_elf_unhandled_reloc
, /* special_function */
418 "R_PPC64_GOT16_HA", /* name */
419 false, /* partial_inplace */
421 0xffff, /* dst_mask */
422 false), /* pcrel_offset */
424 /* This is used only by the dynamic linker. The symbol should exist
425 both in the object being run and in some shared library. The
426 dynamic linker copies the data addressed by the symbol from the
427 shared library into the object, because the object being
428 run has to have the data at some particular address. */
429 HOWTO (R_PPC64_COPY
, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_bitfield
, /* complain_on_overflow */
436 ppc64_elf_unhandled_reloc
, /* special_function */
437 "R_PPC64_COPY", /* name */
438 false, /* partial_inplace */
441 false), /* pcrel_offset */
443 /* Like R_PPC64_ADDR64, but used when setting global offset table
445 HOWTO (R_PPC64_GLOB_DAT
, /* type */
447 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
449 false, /* pc_relative */
451 complain_overflow_dont
, /* complain_on_overflow */
452 ppc64_elf_unhandled_reloc
, /* special_function */
453 "R_PPC64_GLOB_DAT", /* name */
454 false, /* partial_inplace */
456 0xffffffffffffffff, /* dst_mask */
457 false), /* pcrel_offset */
459 /* Created by the link editor. Marks a procedure linkage table
460 entry for a symbol. */
461 HOWTO (R_PPC64_JMP_SLOT
, /* type */
463 0, /* size (0 = byte, 1 = short, 2 = long) */
465 false, /* pc_relative */
467 complain_overflow_dont
, /* complain_on_overflow */
468 ppc64_elf_unhandled_reloc
, /* special_function */
469 "R_PPC64_JMP_SLOT", /* name */
470 false, /* partial_inplace */
473 false), /* pcrel_offset */
475 /* Used only by the dynamic linker. When the object is run, this
476 doubleword64 is set to the load address of the object, plus the
478 HOWTO (R_PPC64_RELATIVE
, /* type */
480 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
482 false, /* pc_relative */
484 complain_overflow_dont
, /* complain_on_overflow */
485 bfd_elf_generic_reloc
, /* special_function */
486 "R_PPC64_RELATIVE", /* name */
487 false, /* partial_inplace */
489 0xffffffffffffffff, /* dst_mask */
490 false), /* pcrel_offset */
492 /* Like R_PPC64_ADDR32, but may be unaligned. */
493 HOWTO (R_PPC64_UADDR32
, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 false, /* pc_relative */
499 complain_overflow_bitfield
, /* complain_on_overflow */
500 bfd_elf_generic_reloc
, /* special_function */
501 "R_PPC64_UADDR32", /* name */
502 false, /* partial_inplace */
504 0xffffffff, /* dst_mask */
505 false), /* pcrel_offset */
507 /* Like R_PPC64_ADDR16, but may be unaligned. */
508 HOWTO (R_PPC64_UADDR16
, /* type */
510 1, /* size (0 = byte, 1 = short, 2 = long) */
512 false, /* pc_relative */
514 complain_overflow_bitfield
, /* complain_on_overflow */
515 bfd_elf_generic_reloc
, /* special_function */
516 "R_PPC64_UADDR16", /* name */
517 false, /* partial_inplace */
519 0xffff, /* dst_mask */
520 false), /* pcrel_offset */
522 /* 32-bit PC relative. */
523 HOWTO (R_PPC64_REL32
, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 true, /* pc_relative */
529 /* FIXME: Verify. Was complain_overflow_bitfield. */
530 complain_overflow_signed
, /* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 "R_PPC64_REL32", /* name */
533 false, /* partial_inplace */
535 0xffffffff, /* dst_mask */
536 true), /* pcrel_offset */
538 /* 32-bit relocation to the symbol's procedure linkage table. */
539 HOWTO (R_PPC64_PLT32
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 false, /* pc_relative */
545 complain_overflow_bitfield
, /* complain_on_overflow */
546 ppc64_elf_unhandled_reloc
, /* special_function */
547 "R_PPC64_PLT32", /* name */
548 false, /* partial_inplace */
551 false), /* pcrel_offset */
553 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
554 FIXME: R_PPC64_PLTREL32 not supported. */
555 HOWTO (R_PPC64_PLTREL32
, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 true, /* pc_relative */
561 complain_overflow_signed
, /* complain_on_overflow */
562 bfd_elf_generic_reloc
, /* special_function */
563 "R_PPC64_PLTREL32", /* name */
564 false, /* partial_inplace */
567 true), /* pcrel_offset */
569 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
571 HOWTO (R_PPC64_PLT16_LO
, /* type */
573 1, /* size (0 = byte, 1 = short, 2 = long) */
575 false, /* pc_relative */
577 complain_overflow_dont
, /* complain_on_overflow */
578 ppc64_elf_unhandled_reloc
, /* special_function */
579 "R_PPC64_PLT16_LO", /* name */
580 false, /* partial_inplace */
582 0xffff, /* dst_mask */
583 false), /* pcrel_offset */
585 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
587 HOWTO (R_PPC64_PLT16_HI
, /* type */
589 1, /* size (0 = byte, 1 = short, 2 = long) */
591 false, /* pc_relative */
593 complain_overflow_dont
, /* complain_on_overflow */
594 ppc64_elf_unhandled_reloc
, /* special_function */
595 "R_PPC64_PLT16_HI", /* name */
596 false, /* partial_inplace */
598 0xffff, /* dst_mask */
599 false), /* pcrel_offset */
601 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
603 HOWTO (R_PPC64_PLT16_HA
, /* type */
605 1, /* size (0 = byte, 1 = short, 2 = long) */
607 false, /* pc_relative */
609 complain_overflow_dont
, /* complain_on_overflow */
610 ppc64_elf_unhandled_reloc
, /* special_function */
611 "R_PPC64_PLT16_HA", /* name */
612 false, /* partial_inplace */
614 0xffff, /* dst_mask */
615 false), /* pcrel_offset */
617 /* 16-bit section relative relocation. */
618 HOWTO (R_PPC64_SECTOFF
, /* type */
620 1, /* size (0 = byte, 1 = short, 2 = long) */
622 false, /* pc_relative */
624 complain_overflow_bitfield
, /* complain_on_overflow */
625 ppc64_elf_sectoff_reloc
, /* special_function */
626 "R_PPC64_SECTOFF", /* name */
627 false, /* partial_inplace */
629 0xffff, /* dst_mask */
630 false), /* pcrel_offset */
632 /* Like R_PPC64_SECTOFF, but no overflow warning. */
633 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
635 1, /* size (0 = byte, 1 = short, 2 = long) */
637 false, /* pc_relative */
639 complain_overflow_dont
, /* complain_on_overflow */
640 ppc64_elf_sectoff_reloc
, /* special_function */
641 "R_PPC64_SECTOFF_LO", /* name */
642 false, /* partial_inplace */
644 0xffff, /* dst_mask */
645 false), /* pcrel_offset */
647 /* 16-bit upper half section relative relocation. */
648 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
650 1, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_dont
, /* complain_on_overflow */
655 ppc64_elf_sectoff_reloc
, /* special_function */
656 "R_PPC64_SECTOFF_HI", /* name */
657 false, /* partial_inplace */
659 0xffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* 16-bit upper half adjusted section relative relocation. */
663 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_dont
, /* complain_on_overflow */
670 ppc64_elf_sectoff_ha_reloc
, /* special_function */
671 "R_PPC64_SECTOFF_HA", /* name */
672 false, /* partial_inplace */
674 0xffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* Like R_PPC64_REL24 without touching the two least significant
678 bits. Should have been named R_PPC64_REL30! */
679 HOWTO (R_PPC64_ADDR30
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 true, /* pc_relative */
685 complain_overflow_dont
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC64_ADDR30", /* name */
688 false, /* partial_inplace */
690 0xfffffffc, /* dst_mask */
691 true), /* pcrel_offset */
693 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
695 /* A standard 64-bit relocation. */
696 HOWTO (R_PPC64_ADDR64
, /* type */
698 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
700 false, /* pc_relative */
702 complain_overflow_dont
, /* complain_on_overflow */
703 bfd_elf_generic_reloc
, /* special_function */
704 "R_PPC64_ADDR64", /* name */
705 false, /* partial_inplace */
707 0xffffffffffffffff, /* dst_mask */
708 false), /* pcrel_offset */
710 /* The bits 32-47 of an address. */
711 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
713 1, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_dont
, /* complain_on_overflow */
718 bfd_elf_generic_reloc
, /* special_function */
719 "R_PPC64_ADDR16_HIGHER", /* name */
720 false, /* partial_inplace */
722 0xffff, /* dst_mask */
723 false), /* pcrel_offset */
725 /* The bits 32-47 of an address, plus 1 if the contents of the low
726 16 bits, treated as a signed number, is negative. */
727 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
729 1, /* size (0 = byte, 1 = short, 2 = long) */
731 false, /* pc_relative */
733 complain_overflow_dont
, /* complain_on_overflow */
734 ppc64_elf_ha_reloc
, /* special_function */
735 "R_PPC64_ADDR16_HIGHERA", /* name */
736 false, /* partial_inplace */
738 0xffff, /* dst_mask */
739 false), /* pcrel_offset */
741 /* The bits 48-63 of an address. */
742 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 false, /* pc_relative */
748 complain_overflow_dont
, /* complain_on_overflow */
749 bfd_elf_generic_reloc
, /* special_function */
750 "R_PPC64_ADDR16_HIGHEST", /* name */
751 false, /* partial_inplace */
753 0xffff, /* dst_mask */
754 false), /* pcrel_offset */
756 /* The bits 48-63 of an address, plus 1 if the contents of the low
757 16 bits, treated as a signed number, is negative. */
758 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
760 1, /* size (0 = byte, 1 = short, 2 = long) */
762 false, /* pc_relative */
764 complain_overflow_dont
, /* complain_on_overflow */
765 ppc64_elf_ha_reloc
, /* special_function */
766 "R_PPC64_ADDR16_HIGHESTA", /* name */
767 false, /* partial_inplace */
769 0xffff, /* dst_mask */
770 false), /* pcrel_offset */
772 /* Like ADDR64, but may be unaligned. */
773 HOWTO (R_PPC64_UADDR64
, /* type */
775 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
777 false, /* pc_relative */
779 complain_overflow_dont
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 "R_PPC64_UADDR64", /* name */
782 false, /* partial_inplace */
784 0xffffffffffffffff, /* dst_mask */
785 false), /* pcrel_offset */
787 /* 64-bit relative relocation. */
788 HOWTO (R_PPC64_REL64
, /* type */
790 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
792 true, /* pc_relative */
794 complain_overflow_dont
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_PPC64_REL64", /* name */
797 false, /* partial_inplace */
799 0xffffffffffffffff, /* dst_mask */
800 true), /* pcrel_offset */
802 /* 64-bit relocation to the symbol's procedure linkage table. */
803 HOWTO (R_PPC64_PLT64
, /* type */
805 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
807 false, /* pc_relative */
809 complain_overflow_dont
, /* complain_on_overflow */
810 ppc64_elf_unhandled_reloc
, /* special_function */
811 "R_PPC64_PLT64", /* name */
812 false, /* partial_inplace */
815 false), /* pcrel_offset */
817 /* 64-bit PC relative relocation to the symbol's procedure linkage
819 /* FIXME: R_PPC64_PLTREL64 not supported. */
820 HOWTO (R_PPC64_PLTREL64
, /* type */
822 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
824 true, /* pc_relative */
826 complain_overflow_dont
, /* complain_on_overflow */
827 ppc64_elf_unhandled_reloc
, /* special_function */
828 "R_PPC64_PLTREL64", /* name */
829 false, /* partial_inplace */
832 true), /* pcrel_offset */
834 /* 16 bit TOC-relative relocation. */
836 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
837 HOWTO (R_PPC64_TOC16
, /* type */
839 1, /* size (0 = byte, 1 = short, 2 = long) */
841 false, /* pc_relative */
843 complain_overflow_signed
, /* complain_on_overflow */
844 ppc64_elf_toc_reloc
, /* special_function */
845 "R_PPC64_TOC16", /* name */
846 false, /* partial_inplace */
848 0xffff, /* dst_mask */
849 false), /* pcrel_offset */
851 /* 16 bit TOC-relative relocation without overflow. */
853 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
854 HOWTO (R_PPC64_TOC16_LO
, /* type */
856 1, /* size (0 = byte, 1 = short, 2 = long) */
858 false, /* pc_relative */
860 complain_overflow_dont
, /* complain_on_overflow */
861 ppc64_elf_toc_reloc
, /* special_function */
862 "R_PPC64_TOC16_LO", /* name */
863 false, /* partial_inplace */
865 0xffff, /* dst_mask */
866 false), /* pcrel_offset */
868 /* 16 bit TOC-relative relocation, high 16 bits. */
870 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
871 HOWTO (R_PPC64_TOC16_HI
, /* type */
873 1, /* size (0 = byte, 1 = short, 2 = long) */
875 false, /* pc_relative */
877 complain_overflow_dont
, /* complain_on_overflow */
878 ppc64_elf_toc_reloc
, /* special_function */
879 "R_PPC64_TOC16_HI", /* name */
880 false, /* partial_inplace */
882 0xffff, /* dst_mask */
883 false), /* pcrel_offset */
885 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
886 contents of the low 16 bits, treated as a signed number, is
889 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
890 HOWTO (R_PPC64_TOC16_HA
, /* type */
892 1, /* size (0 = byte, 1 = short, 2 = long) */
894 false, /* pc_relative */
896 complain_overflow_dont
, /* complain_on_overflow */
897 ppc64_elf_toc_ha_reloc
, /* special_function */
898 "R_PPC64_TOC16_HA", /* name */
899 false, /* partial_inplace */
901 0xffff, /* dst_mask */
902 false), /* pcrel_offset */
904 /* 64-bit relocation; insert value of TOC base (.TOC.). */
906 /* R_PPC64_TOC 51 doubleword64 .TOC. */
907 HOWTO (R_PPC64_TOC
, /* type */
909 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
911 false, /* pc_relative */
913 complain_overflow_bitfield
, /* complain_on_overflow */
914 ppc64_elf_toc64_reloc
, /* special_function */
915 "R_PPC64_TOC", /* name */
916 false, /* partial_inplace */
918 0xffffffffffffffff, /* dst_mask */
919 false), /* pcrel_offset */
921 /* Like R_PPC64_GOT16, but also informs the link editor that the
922 value to relocate may (!) refer to a PLT entry which the link
923 editor (a) may replace with the symbol value. If the link editor
924 is unable to fully resolve the symbol, it may (b) create a PLT
925 entry and store the address to the new PLT entry in the GOT.
926 This permits lazy resolution of function symbols at run time.
927 The link editor may also skip all of this and just (c) emit a
928 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
929 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
930 HOWTO (R_PPC64_PLTGOT16
, /* type */
932 1, /* size (0 = byte, 1 = short, 2 = long) */
934 false, /* pc_relative */
936 complain_overflow_signed
, /* complain_on_overflow */
937 ppc64_elf_unhandled_reloc
, /* special_function */
938 "R_PPC64_PLTGOT16", /* name */
939 false, /* partial_inplace */
941 0xffff, /* dst_mask */
942 false), /* pcrel_offset */
944 /* Like R_PPC64_PLTGOT16, but without overflow. */
945 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
946 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
948 1, /* size (0 = byte, 1 = short, 2 = long) */
950 false, /* pc_relative */
952 complain_overflow_dont
, /* complain_on_overflow */
953 ppc64_elf_unhandled_reloc
, /* special_function */
954 "R_PPC64_PLTGOT16_LO", /* name */
955 false, /* partial_inplace */
957 0xffff, /* dst_mask */
958 false), /* pcrel_offset */
960 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
961 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
962 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
964 1, /* size (0 = byte, 1 = short, 2 = long) */
966 false, /* pc_relative */
968 complain_overflow_dont
, /* complain_on_overflow */
969 ppc64_elf_unhandled_reloc
, /* special_function */
970 "R_PPC64_PLTGOT16_HI", /* name */
971 false, /* partial_inplace */
973 0xffff, /* dst_mask */
974 false), /* pcrel_offset */
976 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
977 1 if the contents of the low 16 bits, treated as a signed number,
979 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
980 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
982 1, /* size (0 = byte, 1 = short, 2 = long) */
984 false, /* pc_relative */
986 complain_overflow_dont
,/* complain_on_overflow */
987 ppc64_elf_unhandled_reloc
, /* special_function */
988 "R_PPC64_PLTGOT16_HA", /* name */
989 false, /* partial_inplace */
991 0xffff, /* dst_mask */
992 false), /* pcrel_offset */
994 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
995 HOWTO (R_PPC64_ADDR16_DS
, /* type */
997 1, /* size (0 = byte, 1 = short, 2 = long) */
999 false, /* pc_relative */
1001 complain_overflow_bitfield
, /* complain_on_overflow */
1002 bfd_elf_generic_reloc
, /* special_function */
1003 "R_PPC64_ADDR16_DS", /* name */
1004 false, /* partial_inplace */
1006 0xfffc, /* dst_mask */
1007 false), /* pcrel_offset */
1009 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1010 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1012 1, /* size (0 = byte, 1 = short, 2 = long) */
1014 false, /* pc_relative */
1016 complain_overflow_dont
,/* complain_on_overflow */
1017 bfd_elf_generic_reloc
, /* special_function */
1018 "R_PPC64_ADDR16_LO_DS",/* name */
1019 false, /* partial_inplace */
1021 0xfffc, /* dst_mask */
1022 false), /* pcrel_offset */
1024 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1025 HOWTO (R_PPC64_GOT16_DS
, /* type */
1027 1, /* size (0 = byte, 1 = short, 2 = long) */
1029 false, /* pc_relative */
1031 complain_overflow_signed
, /* complain_on_overflow */
1032 ppc64_elf_unhandled_reloc
, /* special_function */
1033 "R_PPC64_GOT16_DS", /* name */
1034 false, /* partial_inplace */
1036 0xfffc, /* dst_mask */
1037 false), /* pcrel_offset */
1039 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1040 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1042 1, /* size (0 = byte, 1 = short, 2 = long) */
1044 false, /* pc_relative */
1046 complain_overflow_dont
, /* complain_on_overflow */
1047 ppc64_elf_unhandled_reloc
, /* special_function */
1048 "R_PPC64_GOT16_LO_DS", /* name */
1049 false, /* partial_inplace */
1051 0xfffc, /* dst_mask */
1052 false), /* pcrel_offset */
1054 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1055 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1057 1, /* size (0 = byte, 1 = short, 2 = long) */
1059 false, /* pc_relative */
1061 complain_overflow_dont
, /* complain_on_overflow */
1062 ppc64_elf_unhandled_reloc
, /* special_function */
1063 "R_PPC64_PLT16_LO_DS", /* name */
1064 false, /* partial_inplace */
1066 0xfffc, /* dst_mask */
1067 false), /* pcrel_offset */
1069 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1070 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1072 1, /* size (0 = byte, 1 = short, 2 = long) */
1074 false, /* pc_relative */
1076 complain_overflow_bitfield
, /* complain_on_overflow */
1077 ppc64_elf_sectoff_reloc
, /* special_function */
1078 "R_PPC64_SECTOFF_DS", /* name */
1079 false, /* partial_inplace */
1081 0xfffc, /* dst_mask */
1082 false), /* pcrel_offset */
1084 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1085 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1087 1, /* size (0 = byte, 1 = short, 2 = long) */
1089 false, /* pc_relative */
1091 complain_overflow_dont
, /* complain_on_overflow */
1092 ppc64_elf_sectoff_reloc
, /* special_function */
1093 "R_PPC64_SECTOFF_LO_DS",/* name */
1094 false, /* partial_inplace */
1096 0xfffc, /* dst_mask */
1097 false), /* pcrel_offset */
1099 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1100 HOWTO (R_PPC64_TOC16_DS
, /* type */
1102 1, /* size (0 = byte, 1 = short, 2 = long) */
1104 false, /* pc_relative */
1106 complain_overflow_signed
, /* complain_on_overflow */
1107 ppc64_elf_toc_reloc
, /* special_function */
1108 "R_PPC64_TOC16_DS", /* name */
1109 false, /* partial_inplace */
1111 0xfffc, /* dst_mask */
1112 false), /* pcrel_offset */
1114 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1115 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1117 1, /* size (0 = byte, 1 = short, 2 = long) */
1119 false, /* pc_relative */
1121 complain_overflow_dont
, /* complain_on_overflow */
1122 ppc64_elf_toc_reloc
, /* special_function */
1123 "R_PPC64_TOC16_LO_DS", /* name */
1124 false, /* partial_inplace */
1126 0xfffc, /* dst_mask */
1127 false), /* pcrel_offset */
1129 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1130 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1131 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1133 1, /* size (0 = byte, 1 = short, 2 = long) */
1135 false, /* pc_relative */
1137 complain_overflow_signed
, /* complain_on_overflow */
1138 ppc64_elf_unhandled_reloc
, /* special_function */
1139 "R_PPC64_PLTGOT16_DS", /* name */
1140 false, /* partial_inplace */
1142 0xfffc, /* dst_mask */
1143 false), /* pcrel_offset */
1145 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1146 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1147 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1149 1, /* size (0 = byte, 1 = short, 2 = long) */
1151 false, /* pc_relative */
1153 complain_overflow_dont
, /* complain_on_overflow */
1154 ppc64_elf_unhandled_reloc
, /* special_function */
1155 "R_PPC64_PLTGOT16_LO_DS",/* name */
1156 false, /* partial_inplace */
1158 0xfffc, /* dst_mask */
1159 false), /* pcrel_offset */
1161 /* GNU extension to record C++ vtable hierarchy. */
1162 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1164 0, /* size (0 = byte, 1 = short, 2 = long) */
1166 false, /* pc_relative */
1168 complain_overflow_dont
, /* complain_on_overflow */
1169 NULL
, /* special_function */
1170 "R_PPC64_GNU_VTINHERIT", /* name */
1171 false, /* partial_inplace */
1174 false), /* pcrel_offset */
1176 /* GNU extension to record C++ vtable member usage. */
1177 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1179 0, /* size (0 = byte, 1 = short, 2 = long) */
1181 false, /* pc_relative */
1183 complain_overflow_dont
, /* complain_on_overflow */
1184 NULL
, /* special_function */
1185 "R_PPC64_GNU_VTENTRY", /* name */
1186 false, /* partial_inplace */
1189 false), /* pcrel_offset */
1193 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1199 unsigned int i
, type
;
1202 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1205 type
= ppc64_elf_howto_raw
[i
].type
;
1206 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1207 / sizeof (ppc64_elf_howto_table
[0])));
1208 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1212 static reloc_howto_type
*
1213 ppc64_elf_reloc_type_lookup (abfd
, code
)
1214 bfd
*abfd ATTRIBUTE_UNUSED
;
1215 bfd_reloc_code_real_type code
;
1217 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1219 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1220 /* Initialize howto table if needed. */
1226 return (reloc_howto_type
*) NULL
;
1228 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1230 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1232 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1234 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1236 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1238 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1240 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1242 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1244 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1246 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1248 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1250 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1252 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1254 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1256 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1258 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1260 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1262 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1264 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1266 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1268 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1270 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1272 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1274 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1276 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1278 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1280 case BFD_RELOC_16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1282 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1284 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1286 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1288 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR64
;
1290 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1292 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1294 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1296 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1298 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1300 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1302 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1304 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1306 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1308 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1310 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1312 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1314 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1316 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1318 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1320 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1322 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1324 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1326 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1328 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1330 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1332 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1334 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1336 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1338 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1340 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1342 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1344 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1346 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1348 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1352 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1355 /* Set the howto pointer for a PowerPC ELF reloc. */
1358 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1359 bfd
*abfd ATTRIBUTE_UNUSED
;
1361 Elf64_Internal_Rela
*dst
;
1365 /* Initialize howto table if needed. */
1366 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1369 type
= ELF64_R_TYPE (dst
->r_info
);
1370 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1371 / sizeof (ppc64_elf_howto_table
[0])));
1372 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1375 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1377 static bfd_reloc_status_type
1378 ppc64_elf_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1379 input_section
, output_bfd
, error_message
)
1381 arelent
*reloc_entry
;
1384 asection
*input_section
;
1386 char **error_message
;
1388 /* If this is a relocatable link (output_bfd test tells us), just
1389 call the generic function. Any adjustment will be done at final
1391 if (output_bfd
!= NULL
)
1392 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1393 input_section
, output_bfd
, error_message
);
1395 /* Adjust the addend for sign extension of the low 16 bits.
1396 We won't actually be using the low 16 bits, so trashing them
1398 reloc_entry
->addend
+= 0x8000;
1399 return bfd_reloc_continue
;
1402 static bfd_reloc_status_type
1403 ppc64_elf_brtaken_reloc (abfd
, reloc_entry
, symbol
, data
,
1404 input_section
, output_bfd
, error_message
)
1406 arelent
*reloc_entry
;
1409 asection
*input_section
;
1411 char **error_message
;
1414 enum elf_ppc_reloc_type r_type
;
1415 bfd_size_type octets
;
1416 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1417 boolean is_power4
= false;
1419 /* If this is a relocatable link (output_bfd test tells us), just
1420 call the generic function. Any adjustment will be done at final
1422 if (output_bfd
!= NULL
)
1423 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1424 input_section
, output_bfd
, error_message
);
1426 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1427 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1428 insn
&= ~(0x01 << 21);
1429 r_type
= (enum elf_ppc_reloc_type
) reloc_entry
->howto
->type
;
1430 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1431 || r_type
== R_PPC64_REL14_BRTAKEN
)
1432 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1436 /* Set 'a' bit. This is 0b00010 in BO field for branch
1437 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1438 for branch on CTR insns (BO == 1a00t or 1a01t). */
1439 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1441 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1444 return bfd_reloc_continue
;
1451 if (!bfd_is_com_section (symbol
->section
))
1452 target
= symbol
->value
;
1453 target
+= symbol
->section
->output_section
->vma
;
1454 target
+= symbol
->section
->output_offset
;
1455 target
+= reloc_entry
->addend
;
1457 from
= (reloc_entry
->address
1458 + input_section
->output_offset
1459 + input_section
->output_section
->vma
);
1461 /* Invert 'y' bit if not the default. */
1462 if ((bfd_signed_vma
) (target
- from
) < 0)
1465 bfd_put_32 (abfd
, (bfd_vma
) insn
, (bfd_byte
*) data
+ octets
);
1466 return bfd_reloc_continue
;
1469 static bfd_reloc_status_type
1470 ppc64_elf_sectoff_reloc (abfd
, reloc_entry
, symbol
, data
,
1471 input_section
, output_bfd
, error_message
)
1473 arelent
*reloc_entry
;
1476 asection
*input_section
;
1478 char **error_message
;
1480 /* If this is a relocatable link (output_bfd test tells us), just
1481 call the generic function. Any adjustment will be done at final
1483 if (output_bfd
!= NULL
)
1484 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1485 input_section
, output_bfd
, error_message
);
1487 /* Subtract the symbol section base address. */
1488 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1489 return bfd_reloc_continue
;
1492 static bfd_reloc_status_type
1493 ppc64_elf_sectoff_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1494 input_section
, output_bfd
, error_message
)
1496 arelent
*reloc_entry
;
1499 asection
*input_section
;
1501 char **error_message
;
1503 /* If this is a relocatable link (output_bfd test tells us), just
1504 call the generic function. Any adjustment will be done at final
1506 if (output_bfd
!= NULL
)
1507 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1508 input_section
, output_bfd
, error_message
);
1510 /* Subtract the symbol section base address. */
1511 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1513 /* Adjust the addend for sign extension of the low 16 bits. */
1514 reloc_entry
->addend
+= 0x8000;
1515 return bfd_reloc_continue
;
1518 static bfd_reloc_status_type
1519 ppc64_elf_toc_reloc (abfd
, reloc_entry
, symbol
, data
,
1520 input_section
, output_bfd
, error_message
)
1522 arelent
*reloc_entry
;
1525 asection
*input_section
;
1527 char **error_message
;
1531 /* If this is a relocatable link (output_bfd test tells us), just
1532 call the generic function. Any adjustment will be done at final
1534 if (output_bfd
!= NULL
)
1535 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1536 input_section
, output_bfd
, error_message
);
1538 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1540 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1542 /* Subtract the TOC base address. */
1543 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1544 return bfd_reloc_continue
;
1547 static bfd_reloc_status_type
1548 ppc64_elf_toc_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
1549 input_section
, output_bfd
, error_message
)
1551 arelent
*reloc_entry
;
1554 asection
*input_section
;
1556 char **error_message
;
1560 /* If this is a relocatable link (output_bfd test tells us), just
1561 call the generic function. Any adjustment will be done at final
1563 if (output_bfd
!= NULL
)
1564 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1565 input_section
, output_bfd
, error_message
);
1567 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1569 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1571 /* Subtract the TOC base address. */
1572 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1574 /* Adjust the addend for sign extension of the low 16 bits. */
1575 reloc_entry
->addend
+= 0x8000;
1576 return bfd_reloc_continue
;
1579 static bfd_reloc_status_type
1580 ppc64_elf_toc64_reloc (abfd
, reloc_entry
, symbol
, data
,
1581 input_section
, output_bfd
, error_message
)
1583 arelent
*reloc_entry
;
1586 asection
*input_section
;
1588 char **error_message
;
1591 bfd_size_type octets
;
1593 /* If this is a relocatable link (output_bfd test tells us), just
1594 call the generic function. Any adjustment will be done at final
1596 if (output_bfd
!= NULL
)
1597 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1598 input_section
, output_bfd
, error_message
);
1600 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1602 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
1604 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1605 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1606 return bfd_reloc_ok
;
1609 static bfd_reloc_status_type
1610 ppc64_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
1611 input_section
, output_bfd
, error_message
)
1613 arelent
*reloc_entry
;
1616 asection
*input_section
;
1618 char **error_message
;
1620 /* If this is a relocatable link (output_bfd test tells us), just
1621 call the generic function. Any adjustment will be done at final
1623 if (output_bfd
!= NULL
)
1624 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1625 input_section
, output_bfd
, error_message
);
1627 if (error_message
!= NULL
)
1629 static char buf
[60];
1630 sprintf (buf
, "generic linker can't handle %s",
1631 reloc_entry
->howto
->name
);
1632 *error_message
= buf
;
1634 return bfd_reloc_dangerous
;
1637 /* Return symbol info as per usual for ELF targets, except that
1638 symbols in .opd are given 'd' or 'D' for type. */
1641 ppc64_elf_get_symbol_info (abfd
, symbol
, ret
)
1646 _bfd_elf_get_symbol_info (abfd
, symbol
, ret
);
1647 if (ret
->type
== '?'
1648 && (symbol
->flags
& (BSF_GLOBAL
| BSF_LOCAL
)) != 0
1649 && strcmp (symbol
->section
->name
, ".opd") == 0)
1650 ret
->type
= (symbol
->flags
& BSF_GLOBAL
) != 0 ? 'D' : 'd';
1653 /* Fix bad default arch selected for a 64 bit input bfd when the
1654 default is 32 bit. */
1657 ppc64_elf_object_p (abfd
)
1660 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
1662 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1664 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1666 /* Relies on arch after 32 bit default being 64 bit default. */
1667 abfd
->arch_info
= abfd
->arch_info
->next
;
1668 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1674 /* Function to set whether a module needs the -mrelocatable bit set. */
1677 ppc64_elf_set_private_flags (abfd
, flags
)
1681 BFD_ASSERT (!elf_flags_init (abfd
)
1682 || elf_elfheader (abfd
)->e_flags
== flags
);
1684 elf_elfheader (abfd
)->e_flags
= flags
;
1685 elf_flags_init (abfd
) = true;
1689 /* Merge backend specific data from an object file to the output
1690 object file when linking. */
1692 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1700 /* Check if we have the same endianess. */
1701 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1702 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1706 if (bfd_big_endian (ibfd
))
1707 msg
= _("%s: compiled for a big endian system and target is little endian");
1709 msg
= _("%s: compiled for a little endian system and target is big endian");
1711 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1713 bfd_set_error (bfd_error_wrong_format
);
1717 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1718 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1721 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1722 old_flags
= elf_elfheader (obfd
)->e_flags
;
1723 if (!elf_flags_init (obfd
))
1725 /* First call, no flags set. */
1726 elf_flags_init (obfd
) = true;
1727 elf_elfheader (obfd
)->e_flags
= new_flags
;
1730 else if (new_flags
== old_flags
)
1731 /* Compatible flags are ok. */
1736 /* Incompatible flags. Warn about -mrelocatable mismatch.
1737 Allow -mrelocatable-lib to be linked with either. */
1739 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1740 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1743 (*_bfd_error_handler
)
1744 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1745 bfd_archive_filename (ibfd
));
1747 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1748 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1751 (*_bfd_error_handler
)
1752 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1753 bfd_archive_filename (ibfd
));
1756 /* The output is -mrelocatable-lib iff both the input files are. */
1757 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1758 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1760 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1761 but each input file is either -mrelocatable or -mrelocatable-lib. */
1762 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1763 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1764 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1765 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1767 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1768 if any module uses it. */
1769 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1771 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1772 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1774 /* Warn about any other mismatches. */
1775 if (new_flags
!= old_flags
)
1778 (*_bfd_error_handler
)
1779 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1780 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1785 bfd_set_error (bfd_error_bad_value
);
1793 /* Handle a PowerPC specific section when reading an object file. This
1794 is called when elfcode.h finds a section with an unknown type. */
1797 ppc64_elf_section_from_shdr (abfd
, hdr
, name
)
1799 Elf64_Internal_Shdr
*hdr
;
1805 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1808 newsect
= hdr
->bfd_section
;
1809 flags
= bfd_get_section_flags (abfd
, newsect
);
1810 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1811 flags
|= SEC_EXCLUDE
;
1813 if (hdr
->sh_type
== SHT_ORDERED
)
1814 flags
|= SEC_SORT_ENTRIES
;
1816 bfd_set_section_flags (abfd
, newsect
, flags
);
1820 /* The following functions are specific to the ELF linker, while
1821 functions above are used generally. Those named ppc64_elf_* are
1822 called by the main ELF linker code. They appear in this file more
1823 or less in the order in which they are called. eg.
1824 ppc64_elf_check_relocs is called early in the link process,
1825 ppc64_elf_finish_dynamic_sections is one of the last functions
1828 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1829 functions have both a function code symbol and a function descriptor
1830 symbol. A call to foo in a relocatable object file looks like:
1837 The function definition in another object file might be:
1841 . .quad .TOC.@tocbase
1847 When the linker resolves the call during a static link, the branch
1848 unsurprisingly just goes to .foo and the .opd information is unused.
1849 If the function definition is in a shared library, things are a little
1850 different: The call goes via a plt call stub, the opd information gets
1851 copied to the plt, and the linker patches the nop.
1859 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1860 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1861 . std 2,40(1) # this is the general idea
1869 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1871 The "reloc ()" notation is supposed to indicate that the linker emits
1872 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1875 What are the difficulties here? Well, firstly, the relocations
1876 examined by the linker in check_relocs are against the function code
1877 sym .foo, while the dynamic relocation in the plt is emitted against
1878 the function descriptor symbol, foo. Somewhere along the line, we need
1879 to carefully copy dynamic link information from one symbol to the other.
1880 Secondly, the generic part of the elf linker will make .foo a dynamic
1881 symbol as is normal for most other backends. We need foo dynamic
1882 instead, at least for an application final link. However, when
1883 creating a shared library containing foo, we need to have both symbols
1884 dynamic so that references to .foo are satisfied during the early
1885 stages of linking. Otherwise the linker might decide to pull in a
1886 definition from some other object, eg. a static library. */
1888 /* The linker needs to keep track of the number of relocs that it
1889 decides to copy as dynamic relocs in check_relocs for each symbol.
1890 This is so that it can later discard them if they are found to be
1891 unnecessary. We store the information in a field extending the
1892 regular ELF linker hash table. */
1894 struct ppc_dyn_relocs
1896 struct ppc_dyn_relocs
*next
;
1898 /* The input section of the reloc. */
1901 /* Total number of relocs copied for the input section. */
1902 bfd_size_type count
;
1904 /* Number of pc-relative relocs copied for the input section. */
1905 bfd_size_type pc_count
;
1908 /* Of those relocs that might be copied as dynamic relocs, this macro
1909 selects between relative and absolute types. */
1911 #define IS_ABSOLUTE_RELOC(RTYPE) \
1912 ((RTYPE) != R_PPC64_REL32 \
1913 && (RTYPE) != R_PPC64_REL64 \
1914 && (RTYPE) != R_PPC64_ADDR30)
1916 /* Section name for stubs is the associated section name plus this
1918 #define STUB_SUFFIX ".stub"
1921 ppc_stub_long_branch:
1922 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1923 destination, but a 24 bit branch in a stub section will reach.
1926 ppc_stub_plt_branch:
1927 Similar to the above, but a 24 bit branch in the stub section won't
1928 reach its destination.
1929 . addis %r12,%r2,xxx@ha
1930 . ld %r11,xxx@l(%r12)
1935 Used to call a function in a shared library.
1936 . addis %r12,%r2,xxx@ha
1938 . ld %r11,xxx+0@l(%r12)
1939 . ld %r2,xxx+8@l(%r12)
1941 . ld %r11,xxx+16@l(%r12)
1945 enum ppc_stub_type
{
1947 ppc_stub_long_branch
,
1948 ppc_stub_plt_branch
,
1952 struct ppc_stub_hash_entry
{
1954 /* Base hash table entry structure. */
1955 struct bfd_hash_entry root
;
1957 /* The stub section. */
1960 /* Offset within stub_sec of the beginning of this stub. */
1961 bfd_vma stub_offset
;
1963 /* Given the symbol's value and its section we can determine its final
1964 value when building the stubs (so the stub knows where to jump. */
1965 bfd_vma target_value
;
1966 asection
*target_section
;
1968 enum ppc_stub_type stub_type
;
1970 /* The symbol table entry, if any, that this was derived from. */
1971 struct ppc_link_hash_entry
*h
;
1973 /* Where this stub is being called from, or, in the case of combined
1974 stub sections, the first input section in the group. */
1978 struct ppc_branch_hash_entry
{
1980 /* Base hash table entry structure. */
1981 struct bfd_hash_entry root
;
1983 /* Offset within .branch_lt. */
1984 unsigned int offset
;
1986 /* Generation marker. */
1990 struct ppc_link_hash_entry
1992 struct elf_link_hash_entry elf
;
1994 /* A pointer to the most recently used stub hash entry against this
1996 struct ppc_stub_hash_entry
*stub_cache
;
1998 /* Track dynamic relocs copied for this symbol. */
1999 struct ppc_dyn_relocs
*dyn_relocs
;
2001 /* Link between function code and descriptor symbols. */
2002 struct elf_link_hash_entry
*oh
;
2004 /* Flag function code and descriptor symbols. */
2005 unsigned int is_func
:1;
2006 unsigned int is_func_descriptor
:1;
2007 unsigned int is_entry
:1;
2010 /* ppc64 ELF linker hash table. */
2012 struct ppc_link_hash_table
2014 struct elf_link_hash_table elf
;
2016 /* The stub hash table. */
2017 struct bfd_hash_table stub_hash_table
;
2019 /* Another hash table for plt_branch stubs. */
2020 struct bfd_hash_table branch_hash_table
;
2022 /* Linker stub bfd. */
2025 /* Linker call-backs. */
2026 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2027 void (*layout_sections_again
) PARAMS ((void));
2029 /* Array to keep track of which stub sections have been created, and
2030 information on stub grouping. */
2032 /* This is the section to which stubs in the group will be attached. */
2034 /* The stub section. */
2038 /* Assorted information used by ppc64_elf_size_stubs. */
2040 asection
**input_list
;
2042 /* Short-cuts to get to dynamic linker sections. */
2055 unsigned int stub_error
;
2057 /* Flag set when small branches are detected. Used to
2058 select suitable defaults for the stub group size. */
2059 unsigned int has_14bit_branch
;
2061 /* Set if we detect a reference undefined weak symbol. */
2062 unsigned int have_undefweak
;
2064 /* Incremented every time we size stubs. */
2065 unsigned int stub_iteration
;
2067 /* Small local sym to section mapping cache. */
2068 struct sym_sec_cache sym_sec
;
2071 static struct bfd_hash_entry
*stub_hash_newfunc
2072 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2073 static struct bfd_hash_entry
*branch_hash_newfunc
2074 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2075 static struct bfd_hash_entry
*link_hash_newfunc
2076 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2077 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
2079 static void ppc64_elf_link_hash_table_free
2080 PARAMS ((struct bfd_link_hash_table
*));
2081 static char *ppc_stub_name
2082 PARAMS ((const asection
*, const asection
*,
2083 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
2084 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
2085 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
2086 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
2087 static struct ppc_stub_hash_entry
*ppc_add_stub
2088 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
2089 static boolean create_linkage_sections
2090 PARAMS ((bfd
*, struct bfd_link_info
*));
2091 static boolean create_got_section
2092 PARAMS ((bfd
*, struct bfd_link_info
*));
2093 static boolean ppc64_elf_create_dynamic_sections
2094 PARAMS ((bfd
*, struct bfd_link_info
*));
2095 static void ppc64_elf_copy_indirect_symbol
2096 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
2097 static boolean ppc64_elf_check_relocs
2098 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2099 const Elf_Internal_Rela
*));
2100 static asection
* ppc64_elf_gc_mark_hook
2101 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
2102 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
2103 static boolean ppc64_elf_gc_sweep_hook
2104 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2105 const Elf_Internal_Rela
*));
2106 static boolean func_desc_adjust
2107 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2108 static boolean ppc64_elf_func_desc_adjust
2109 PARAMS ((bfd
*, struct bfd_link_info
*));
2110 static boolean ppc64_elf_adjust_dynamic_symbol
2111 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
2112 static void ppc64_elf_hide_symbol
2113 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, boolean
));
2114 static boolean edit_opd
2115 PARAMS ((bfd
*, struct bfd_link_info
*));
2116 static boolean allocate_dynrelocs
2117 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2118 static boolean readonly_dynrelocs
2119 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2120 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2121 PARAMS ((const Elf_Internal_Rela
*));
2122 static boolean ppc64_elf_size_dynamic_sections
2123 PARAMS ((bfd
*, struct bfd_link_info
*));
2124 static INLINE
enum ppc_stub_type ppc_type_of_stub
2125 PARAMS ((asection
*, const Elf_Internal_Rela
*,
2126 struct ppc_link_hash_entry
**, bfd_vma
));
2127 static bfd_byte
*build_plt_stub
2128 PARAMS ((bfd
*, bfd_byte
*, int, int));
2129 static boolean ppc_build_one_stub
2130 PARAMS ((struct bfd_hash_entry
*, PTR
));
2131 static boolean ppc_size_one_stub
2132 PARAMS ((struct bfd_hash_entry
*, PTR
));
2133 static void group_sections
2134 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, boolean
));
2135 static boolean ppc64_elf_fake_sections
2136 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*));
2137 static boolean ppc64_elf_relocate_section
2138 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
2139 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
2141 static boolean ppc64_elf_finish_dynamic_symbol
2142 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
2143 Elf_Internal_Sym
*));
2144 static boolean ppc64_elf_finish_dynamic_sections
2145 PARAMS ((bfd
*, struct bfd_link_info
*));
2147 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2149 #define ppc_hash_table(p) \
2150 ((struct ppc_link_hash_table *) ((p)->hash))
2152 #define ppc_stub_hash_lookup(table, string, create, copy) \
2153 ((struct ppc_stub_hash_entry *) \
2154 bfd_hash_lookup ((table), (string), (create), (copy)))
2156 #define ppc_branch_hash_lookup(table, string, create, copy) \
2157 ((struct ppc_branch_hash_entry *) \
2158 bfd_hash_lookup ((table), (string), (create), (copy)))
2160 /* Create an entry in the stub hash table. */
2162 static struct bfd_hash_entry
*
2163 stub_hash_newfunc (entry
, table
, string
)
2164 struct bfd_hash_entry
*entry
;
2165 struct bfd_hash_table
*table
;
2168 /* Allocate the structure if it has not already been allocated by a
2172 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2177 /* Call the allocation method of the superclass. */
2178 entry
= bfd_hash_newfunc (entry
, table
, string
);
2181 struct ppc_stub_hash_entry
*eh
;
2183 /* Initialize the local fields. */
2184 eh
= (struct ppc_stub_hash_entry
*) entry
;
2185 eh
->stub_sec
= NULL
;
2186 eh
->stub_offset
= 0;
2187 eh
->target_value
= 0;
2188 eh
->target_section
= NULL
;
2189 eh
->stub_type
= ppc_stub_none
;
2197 /* Create an entry in the branch hash table. */
2199 static struct bfd_hash_entry
*
2200 branch_hash_newfunc (entry
, table
, string
)
2201 struct bfd_hash_entry
*entry
;
2202 struct bfd_hash_table
*table
;
2205 /* Allocate the structure if it has not already been allocated by a
2209 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2214 /* Call the allocation method of the superclass. */
2215 entry
= bfd_hash_newfunc (entry
, table
, string
);
2218 struct ppc_branch_hash_entry
*eh
;
2220 /* Initialize the local fields. */
2221 eh
= (struct ppc_branch_hash_entry
*) entry
;
2229 /* Create an entry in a ppc64 ELF linker hash table. */
2231 static struct bfd_hash_entry
*
2232 link_hash_newfunc (entry
, table
, string
)
2233 struct bfd_hash_entry
*entry
;
2234 struct bfd_hash_table
*table
;
2237 /* Allocate the structure if it has not already been allocated by a
2241 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2246 /* Call the allocation method of the superclass. */
2247 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2250 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2252 eh
->stub_cache
= NULL
;
2253 eh
->dyn_relocs
= NULL
;
2256 eh
->is_func_descriptor
= 0;
2263 /* Create a ppc64 ELF linker hash table. */
2265 static struct bfd_link_hash_table
*
2266 ppc64_elf_link_hash_table_create (abfd
)
2269 struct ppc_link_hash_table
*htab
;
2270 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2272 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2276 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2282 /* Init the stub hash table too. */
2283 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2286 /* And the branch hash table. */
2287 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2290 htab
->stub_bfd
= NULL
;
2291 htab
->add_stub_section
= NULL
;
2292 htab
->layout_sections_again
= NULL
;
2293 htab
->stub_group
= NULL
;
2295 htab
->srelgot
= NULL
;
2297 htab
->srelplt
= NULL
;
2298 htab
->sdynbss
= NULL
;
2299 htab
->srelbss
= NULL
;
2300 htab
->sglink
= NULL
;
2303 htab
->srelbrlt
= NULL
;
2304 htab
->stub_error
= 0;
2305 htab
->has_14bit_branch
= 0;
2306 htab
->have_undefweak
= 0;
2307 htab
->stub_iteration
= 0;
2308 htab
->sym_sec
.abfd
= NULL
;
2310 return &htab
->elf
.root
;
2313 /* Free the derived linker hash table. */
2316 ppc64_elf_link_hash_table_free (hash
)
2317 struct bfd_link_hash_table
*hash
;
2319 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2321 bfd_hash_table_free (&ret
->stub_hash_table
);
2322 bfd_hash_table_free (&ret
->branch_hash_table
);
2323 _bfd_generic_link_hash_table_free (hash
);
2326 /* Build a name for an entry in the stub hash table. */
2329 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2330 const asection
*input_section
;
2331 const asection
*sym_sec
;
2332 const struct ppc_link_hash_entry
*h
;
2333 const Elf_Internal_Rela
*rel
;
2338 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2339 offsets from a sym as a branch target? In fact, we could
2340 probably assume the addend is always zero. */
2341 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2345 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2346 stub_name
= bfd_malloc (len
);
2347 if (stub_name
!= NULL
)
2349 sprintf (stub_name
, "%08x_%s+%x",
2350 input_section
->id
& 0xffffffff,
2351 h
->elf
.root
.root
.string
,
2352 (int) rel
->r_addend
& 0xffffffff);
2357 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2358 stub_name
= bfd_malloc (len
);
2359 if (stub_name
!= NULL
)
2361 sprintf (stub_name
, "%08x_%x:%x+%x",
2362 input_section
->id
& 0xffffffff,
2363 sym_sec
->id
& 0xffffffff,
2364 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2365 (int) rel
->r_addend
& 0xffffffff);
2371 /* Look up an entry in the stub hash. Stub entries are cached because
2372 creating the stub name takes a bit of time. */
2374 static struct ppc_stub_hash_entry
*
2375 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2376 const asection
*input_section
;
2377 const asection
*sym_sec
;
2378 struct elf_link_hash_entry
*hash
;
2379 const Elf_Internal_Rela
*rel
;
2380 struct ppc_link_hash_table
*htab
;
2382 struct ppc_stub_hash_entry
*stub_entry
;
2383 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2384 const asection
*id_sec
;
2386 /* If this input section is part of a group of sections sharing one
2387 stub section, then use the id of the first section in the group.
2388 Stub names need to include a section id, as there may well be
2389 more than one stub used to reach say, printf, and we need to
2390 distinguish between them. */
2391 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2393 if (h
!= NULL
&& h
->stub_cache
!= NULL
2394 && h
->stub_cache
->h
== h
2395 && h
->stub_cache
->id_sec
== id_sec
)
2397 stub_entry
= h
->stub_cache
;
2403 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2404 if (stub_name
== NULL
)
2407 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2408 stub_name
, false, false);
2410 h
->stub_cache
= stub_entry
;
2418 /* Add a new stub entry to the stub hash. Not all fields of the new
2419 stub entry are initialised. */
2421 static struct ppc_stub_hash_entry
*
2422 ppc_add_stub (stub_name
, section
, htab
)
2423 const char *stub_name
;
2425 struct ppc_link_hash_table
*htab
;
2429 struct ppc_stub_hash_entry
*stub_entry
;
2431 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2432 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2433 if (stub_sec
== NULL
)
2435 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2436 if (stub_sec
== NULL
)
2442 namelen
= strlen (link_sec
->name
);
2443 len
= namelen
+ sizeof (STUB_SUFFIX
);
2444 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2448 memcpy (s_name
, link_sec
->name
, namelen
);
2449 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2450 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2451 if (stub_sec
== NULL
)
2453 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2455 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2458 /* Enter this entry into the linker stub hash table. */
2459 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2461 if (stub_entry
== NULL
)
2463 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2464 bfd_archive_filename (section
->owner
),
2469 stub_entry
->stub_sec
= stub_sec
;
2470 stub_entry
->stub_offset
= 0;
2471 stub_entry
->id_sec
= link_sec
;
2475 /* Create sections for linker generated code. */
2478 create_linkage_sections (dynobj
, info
)
2480 struct bfd_link_info
*info
;
2482 struct ppc_link_hash_table
*htab
;
2485 htab
= ppc_hash_table (info
);
2487 /* Create .sfpr for code to save and restore fp regs. */
2488 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2489 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2490 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2491 if (htab
->sfpr
== NULL
2492 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2493 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2496 /* Create .glink for lazy dynamic linking support. */
2497 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2498 if (htab
->sglink
== NULL
2499 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2500 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2503 /* Create .branch_lt for plt_branch stubs. */
2504 flags
= (SEC_ALLOC
| SEC_LOAD
2505 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2506 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2507 if (htab
->sbrlt
== NULL
2508 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2509 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2514 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2515 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2516 htab
->srelbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
2518 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2519 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2525 /* Create .got and .rela.got sections in DYNOBJ, and set up
2526 shortcuts to them in our hash table. */
2529 create_got_section (dynobj
, info
)
2531 struct bfd_link_info
*info
;
2533 struct ppc_link_hash_table
*htab
;
2535 if (! _bfd_elf_create_got_section (dynobj
, info
))
2538 htab
= ppc_hash_table (info
);
2539 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2543 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2545 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2546 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2547 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2549 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2554 /* Create the dynamic sections, and set up shortcuts. */
2557 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2559 struct bfd_link_info
*info
;
2561 struct ppc_link_hash_table
*htab
;
2563 htab
= ppc_hash_table (info
);
2564 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2567 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2570 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2571 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2572 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2574 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2576 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2577 || (!info
->shared
&& !htab
->srelbss
))
2583 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2586 ppc64_elf_copy_indirect_symbol (dir
, ind
)
2587 struct elf_link_hash_entry
*dir
, *ind
;
2589 struct ppc_link_hash_entry
*edir
, *eind
;
2591 edir
= (struct ppc_link_hash_entry
*) dir
;
2592 eind
= (struct ppc_link_hash_entry
*) ind
;
2594 if (eind
->dyn_relocs
!= NULL
)
2596 if (edir
->dyn_relocs
!= NULL
)
2598 struct ppc_dyn_relocs
**pp
;
2599 struct ppc_dyn_relocs
*p
;
2601 if (ind
->root
.type
== bfd_link_hash_indirect
)
2604 /* Add reloc counts against the weak sym to the strong sym
2605 list. Merge any entries against the same section. */
2606 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2608 struct ppc_dyn_relocs
*q
;
2610 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2611 if (q
->sec
== p
->sec
)
2613 q
->pc_count
+= p
->pc_count
;
2614 q
->count
+= p
->count
;
2621 *pp
= edir
->dyn_relocs
;
2624 edir
->dyn_relocs
= eind
->dyn_relocs
;
2625 eind
->dyn_relocs
= NULL
;
2628 edir
->is_func
|= eind
->is_func
;
2629 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2630 edir
->is_entry
|= eind
->is_entry
;
2632 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
2635 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2636 symbols undefined on the command-line. */
2639 ppc64_elf_mark_entry_syms (info
)
2640 struct bfd_link_info
*info
;
2642 struct ppc_link_hash_table
*htab
;
2643 struct bfd_sym_chain
*sym
;
2645 htab
= ppc_hash_table (info
);
2646 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
2648 struct elf_link_hash_entry
*h
;
2650 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, false, false, false);
2652 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
2657 /* Look through the relocs for a section during the first phase, and
2658 calculate needed space in the global offset table, procedure
2659 linkage table, and dynamic reloc sections. */
2662 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2664 struct bfd_link_info
*info
;
2666 const Elf_Internal_Rela
*relocs
;
2668 struct ppc_link_hash_table
*htab
;
2669 Elf_Internal_Shdr
*symtab_hdr
;
2670 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2671 const Elf_Internal_Rela
*rel
;
2672 const Elf_Internal_Rela
*rel_end
;
2674 asection
**opd_sym_map
;
2676 if (info
->relocateable
)
2679 htab
= ppc_hash_table (info
);
2680 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2682 sym_hashes
= elf_sym_hashes (abfd
);
2683 sym_hashes_end
= (sym_hashes
2684 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
2685 - symtab_hdr
->sh_info
);
2689 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
2691 /* Garbage collection needs some extra help with .opd sections.
2692 We don't want to necessarily keep everything referenced by
2693 relocs in .opd, as that would keep all functions. Instead,
2694 if we reference an .opd symbol (a function descriptor), we
2695 want to keep the function code symbol's section. This is
2696 easy for global symbols, but for local syms we need to keep
2697 information about the associated function section. Later, if
2698 edit_opd deletes entries, we'll use this array to adjust
2699 local syms in .opd. */
2701 asection
*func_section
;
2706 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
2707 opd_sym_map
= (asection
**) bfd_zalloc (abfd
, amt
);
2708 if (opd_sym_map
== NULL
)
2710 elf_section_data (sec
)->tdata
= opd_sym_map
;
2713 if (htab
->elf
.dynobj
== NULL
)
2714 htab
->elf
.dynobj
= abfd
;
2715 if (htab
->sfpr
== NULL
2716 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2719 rel_end
= relocs
+ sec
->reloc_count
;
2720 for (rel
= relocs
; rel
< rel_end
; rel
++)
2722 unsigned long r_symndx
;
2723 struct elf_link_hash_entry
*h
;
2724 enum elf_ppc_reloc_type r_type
;
2726 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2727 if (r_symndx
< symtab_hdr
->sh_info
)
2730 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2732 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2735 /* GOT16 relocations */
2737 case R_PPC64_GOT16_DS
:
2738 case R_PPC64_GOT16_HA
:
2739 case R_PPC64_GOT16_HI
:
2740 case R_PPC64_GOT16_LO
:
2741 case R_PPC64_GOT16_LO_DS
:
2743 /* This symbol requires a global offset table entry. */
2744 if (htab
->sgot
== NULL
2745 && !create_got_section (htab
->elf
.dynobj
, info
))
2750 h
->got
.refcount
+= 1;
2754 bfd_signed_vma
*local_got_refcounts
;
2756 /* This is a global offset table entry for a local symbol. */
2757 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2758 if (local_got_refcounts
== NULL
)
2762 size
= symtab_hdr
->sh_info
;
2763 size
*= sizeof (bfd_signed_vma
);
2764 local_got_refcounts
= ((bfd_signed_vma
*)
2765 bfd_zalloc (abfd
, size
));
2766 if (local_got_refcounts
== NULL
)
2768 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2770 local_got_refcounts
[r_symndx
] += 1;
2774 case R_PPC64_PLT16_HA
:
2775 case R_PPC64_PLT16_HI
:
2776 case R_PPC64_PLT16_LO
:
2779 /* This symbol requires a procedure linkage table entry. We
2780 actually build the entry in adjust_dynamic_symbol,
2781 because this might be a case of linking PIC code without
2782 linking in any dynamic objects, in which case we don't
2783 need to generate a procedure linkage table after all. */
2786 /* It does not make sense to have a procedure linkage
2787 table entry for a local symbol. */
2788 bfd_set_error (bfd_error_bad_value
);
2792 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2793 h
->plt
.refcount
+= 1;
2794 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2797 /* The following relocations don't need to propagate the
2798 relocation if linking a shared object since they are
2799 section relative. */
2800 case R_PPC64_SECTOFF
:
2801 case R_PPC64_SECTOFF_LO
:
2802 case R_PPC64_SECTOFF_HI
:
2803 case R_PPC64_SECTOFF_HA
:
2804 case R_PPC64_SECTOFF_DS
:
2805 case R_PPC64_SECTOFF_LO_DS
:
2807 case R_PPC64_TOC16_LO
:
2808 case R_PPC64_TOC16_HI
:
2809 case R_PPC64_TOC16_HA
:
2810 case R_PPC64_TOC16_DS
:
2811 case R_PPC64_TOC16_LO_DS
:
2814 /* This relocation describes the C++ object vtable hierarchy.
2815 Reconstruct it for later use during GC. */
2816 case R_PPC64_GNU_VTINHERIT
:
2817 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2821 /* This relocation describes which C++ vtable entries are actually
2822 used. Record for later use during GC. */
2823 case R_PPC64_GNU_VTENTRY
:
2824 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2829 case R_PPC64_REL14_BRTAKEN
:
2830 case R_PPC64_REL14_BRNTAKEN
:
2831 htab
->has_14bit_branch
= 1;
2836 && h
->root
.root
.string
[0] == '.'
2837 && h
->root
.root
.string
[1] != 0)
2839 /* We may need a .plt entry if the function this reloc
2840 refers to is in a shared lib. */
2841 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2842 h
->plt
.refcount
+= 1;
2843 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2847 case R_PPC64_ADDR64
:
2848 if (opd_sym_map
!= NULL
2850 && h
->root
.root
.string
[0] == '.'
2851 && h
->root
.root
.string
[1] != 0)
2853 struct elf_link_hash_entry
*fdh
;
2855 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2856 false, false, false);
2859 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2860 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2861 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2862 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2865 if (opd_sym_map
!= NULL
2867 && rel
+ 1 < rel_end
2868 && ((enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
)
2873 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
2878 opd_sym_map
[rel
->r_offset
/ 24] = s
;
2884 case R_PPC64_ADDR14
:
2885 case R_PPC64_ADDR14_BRNTAKEN
:
2886 case R_PPC64_ADDR14_BRTAKEN
:
2887 case R_PPC64_ADDR16
:
2888 case R_PPC64_ADDR16_DS
:
2889 case R_PPC64_ADDR16_HA
:
2890 case R_PPC64_ADDR16_HI
:
2891 case R_PPC64_ADDR16_HIGHER
:
2892 case R_PPC64_ADDR16_HIGHERA
:
2893 case R_PPC64_ADDR16_HIGHEST
:
2894 case R_PPC64_ADDR16_HIGHESTA
:
2895 case R_PPC64_ADDR16_LO
:
2896 case R_PPC64_ADDR16_LO_DS
:
2897 case R_PPC64_ADDR24
:
2898 case R_PPC64_ADDR30
:
2899 case R_PPC64_ADDR32
:
2900 case R_PPC64_UADDR16
:
2901 case R_PPC64_UADDR32
:
2902 case R_PPC64_UADDR64
:
2904 /* Don't propagate .opd relocs. */
2905 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
2908 /* If we are creating a shared library, and this is a reloc
2909 against a global symbol, or a non PC relative reloc
2910 against a local symbol, then we need to copy the reloc
2911 into the shared library. However, if we are linking with
2912 -Bsymbolic, we do not need to copy a reloc against a
2913 global symbol which is defined in an object we are
2914 including in the link (i.e., DEF_REGULAR is set). At
2915 this point we have not seen all the input files, so it is
2916 possible that DEF_REGULAR is not set now but will be set
2917 later (it is never cleared). In case of a weak definition,
2918 DEF_REGULAR may be cleared later by a strong definition in
2919 a shared library. We account for that possibility below by
2920 storing information in the relocs_copied field of the hash
2921 table entry. A similar situation occurs when creating
2922 shared libraries and symbol visibility changes render the
2925 If on the other hand, we are creating an executable, we
2926 may need to keep relocations for symbols satisfied by a
2927 dynamic library if we manage to avoid copy relocs for the
2930 && (sec
->flags
& SEC_ALLOC
) != 0
2931 && (IS_ABSOLUTE_RELOC (r_type
)
2933 && (! info
->symbolic
2934 || h
->root
.type
== bfd_link_hash_defweak
2935 || (h
->elf_link_hash_flags
2936 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2938 && (sec
->flags
& SEC_ALLOC
) != 0
2940 && (h
->root
.type
== bfd_link_hash_defweak
2941 || (h
->elf_link_hash_flags
2942 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2944 struct ppc_dyn_relocs
*p
;
2945 struct ppc_dyn_relocs
**head
;
2947 /* We must copy these reloc types into the output file.
2948 Create a reloc section in dynobj and make room for
2955 name
= (bfd_elf_string_from_elf_section
2957 elf_elfheader (abfd
)->e_shstrndx
,
2958 elf_section_data (sec
)->rel_hdr
.sh_name
));
2962 if (strncmp (name
, ".rela", 5) != 0
2963 || strcmp (bfd_get_section_name (abfd
, sec
),
2966 (*_bfd_error_handler
)
2967 (_("%s: bad relocation section name `%s\'"),
2968 bfd_archive_filename (abfd
), name
);
2969 bfd_set_error (bfd_error_bad_value
);
2972 dynobj
= htab
->elf
.dynobj
;
2973 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2978 sreloc
= bfd_make_section (dynobj
, name
);
2979 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2980 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2981 if ((sec
->flags
& SEC_ALLOC
) != 0)
2982 flags
|= SEC_ALLOC
| SEC_LOAD
;
2984 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2985 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2988 elf_section_data (sec
)->sreloc
= sreloc
;
2991 /* If this is a global symbol, we count the number of
2992 relocations we need for this symbol. */
2995 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
2999 /* Track dynamic relocs needed for local syms too.
3000 We really need local syms available to do this
3004 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3009 head
= ((struct ppc_dyn_relocs
**)
3010 &elf_section_data (s
)->local_dynrel
);
3014 if (p
== NULL
|| p
->sec
!= sec
)
3016 p
= ((struct ppc_dyn_relocs
*)
3017 bfd_alloc (htab
->elf
.dynobj
,
3018 (bfd_size_type
) sizeof *p
));
3029 if (!IS_ABSOLUTE_RELOC (r_type
))
3042 /* Return the section that should be marked against GC for a given
3046 ppc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
3048 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3049 Elf_Internal_Rela
*rel
;
3050 struct elf_link_hash_entry
*h
;
3051 Elf_Internal_Sym
*sym
;
3053 asection
*rsec
= NULL
;
3057 enum elf_ppc_reloc_type r_type
;
3058 struct ppc_link_hash_entry
*fdh
;
3060 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3063 case R_PPC64_GNU_VTINHERIT
:
3064 case R_PPC64_GNU_VTENTRY
:
3068 switch (h
->root
.type
)
3070 case bfd_link_hash_defined
:
3071 case bfd_link_hash_defweak
:
3072 fdh
= (struct ppc_link_hash_entry
*) h
;
3074 /* Function descriptor syms cause the associated
3075 function code sym section to be marked. */
3076 if (fdh
->is_func_descriptor
)
3077 rsec
= fdh
->oh
->root
.u
.def
.section
;
3079 /* Function entry syms return NULL if they are in .opd
3080 and are not ._start (or others undefined on the ld
3081 command line). Thus we avoid marking all function
3082 sections, as all functions are referenced in .opd. */
3083 else if ((fdh
->oh
!= NULL
3084 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
3085 || elf_section_data (sec
)->tdata
== NULL
)
3086 rsec
= h
->root
.u
.def
.section
;
3089 case bfd_link_hash_common
:
3090 rsec
= h
->root
.u
.c
.p
->section
;
3100 asection
**opd_sym_section
;
3102 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3103 opd_sym_section
= (asection
**) elf_section_data (rsec
)->tdata
;
3104 if (opd_sym_section
!= NULL
)
3105 rsec
= opd_sym_section
[sym
->st_value
/ 24];
3106 else if (elf_section_data (sec
)->tdata
!= NULL
)
3113 /* Update the .got, .plt. and dynamic reloc reference counts for the
3114 section being removed. */
3117 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
3119 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3121 const Elf_Internal_Rela
*relocs
;
3123 Elf_Internal_Shdr
*symtab_hdr
;
3124 struct elf_link_hash_entry
**sym_hashes
;
3125 bfd_signed_vma
*local_got_refcounts
;
3126 const Elf_Internal_Rela
*rel
, *relend
;
3128 elf_section_data (sec
)->local_dynrel
= NULL
;
3130 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3131 sym_hashes
= elf_sym_hashes (abfd
);
3132 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3134 relend
= relocs
+ sec
->reloc_count
;
3135 for (rel
= relocs
; rel
< relend
; rel
++)
3137 unsigned long r_symndx
;
3138 enum elf_ppc_reloc_type r_type
;
3139 struct elf_link_hash_entry
*h
;
3141 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3142 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3146 case R_PPC64_GOT16_DS
:
3147 case R_PPC64_GOT16_HA
:
3148 case R_PPC64_GOT16_HI
:
3149 case R_PPC64_GOT16_LO
:
3150 case R_PPC64_GOT16_LO_DS
:
3151 if (r_symndx
>= symtab_hdr
->sh_info
)
3153 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3154 if (h
->got
.refcount
> 0)
3159 if (local_got_refcounts
[r_symndx
] > 0)
3160 local_got_refcounts
[r_symndx
]--;
3164 case R_PPC64_PLT16_HA
:
3165 case R_PPC64_PLT16_HI
:
3166 case R_PPC64_PLT16_LO
:
3169 if (r_symndx
>= symtab_hdr
->sh_info
)
3171 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3172 if (h
->plt
.refcount
> 0)
3178 case R_PPC64_REL14_BRNTAKEN
:
3179 case R_PPC64_REL14_BRTAKEN
:
3181 if (r_symndx
>= symtab_hdr
->sh_info
)
3183 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3184 if (h
->plt
.refcount
> 0)
3191 if (r_symndx
>= symtab_hdr
->sh_info
)
3193 struct ppc_link_hash_entry
*eh
;
3194 struct ppc_dyn_relocs
**pp
;
3195 struct ppc_dyn_relocs
*p
;
3197 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3198 eh
= (struct ppc_link_hash_entry
*) h
;
3200 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3212 case R_PPC64_ADDR14
:
3213 case R_PPC64_ADDR14_BRNTAKEN
:
3214 case R_PPC64_ADDR14_BRTAKEN
:
3215 case R_PPC64_ADDR16
:
3216 case R_PPC64_ADDR16_DS
:
3217 case R_PPC64_ADDR16_HA
:
3218 case R_PPC64_ADDR16_HI
:
3219 case R_PPC64_ADDR16_HIGHER
:
3220 case R_PPC64_ADDR16_HIGHERA
:
3221 case R_PPC64_ADDR16_HIGHEST
:
3222 case R_PPC64_ADDR16_HIGHESTA
:
3223 case R_PPC64_ADDR16_LO
:
3224 case R_PPC64_ADDR16_LO_DS
:
3225 case R_PPC64_ADDR24
:
3226 case R_PPC64_ADDR30
:
3227 case R_PPC64_ADDR32
:
3228 case R_PPC64_ADDR64
:
3229 case R_PPC64_UADDR16
:
3230 case R_PPC64_UADDR32
:
3231 case R_PPC64_UADDR64
:
3233 if (r_symndx
>= symtab_hdr
->sh_info
)
3235 struct ppc_link_hash_entry
*eh
;
3236 struct ppc_dyn_relocs
**pp
;
3237 struct ppc_dyn_relocs
*p
;
3239 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3240 eh
= (struct ppc_link_hash_entry
*) h
;
3242 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3260 /* Called via elf_link_hash_traverse to transfer dynamic linking
3261 information on function code symbol entries to their corresponding
3262 function descriptor symbol entries. */
3264 func_desc_adjust (h
, inf
)
3265 struct elf_link_hash_entry
*h
;
3268 struct bfd_link_info
*info
;
3269 struct ppc_link_hash_table
*htab
;
3271 if (h
->root
.type
== bfd_link_hash_indirect
)
3274 if (h
->root
.type
== bfd_link_hash_warning
)
3275 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3277 info
= (struct bfd_link_info
*) inf
;
3278 htab
= ppc_hash_table (info
);
3280 /* If this is a function code symbol, transfer dynamic linking
3281 information to the function descriptor symbol. */
3282 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
3285 if (h
->root
.type
== bfd_link_hash_undefweak
3286 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
3287 htab
->have_undefweak
= true;
3289 if (h
->plt
.refcount
> 0
3290 && h
->root
.root
.string
[0] == '.'
3291 && h
->root
.root
.string
[1] != '\0')
3293 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3294 boolean force_local
;
3296 /* Find the corresponding function descriptor symbol. Create it
3297 as undefined if necessary. */
3300 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3301 false, false, true);
3305 && (h
->root
.type
== bfd_link_hash_undefined
3306 || h
->root
.type
== bfd_link_hash_undefweak
))
3311 abfd
= h
->root
.u
.undef
.abfd
;
3312 newsym
= bfd_make_empty_symbol (abfd
);
3313 newsym
->name
= h
->root
.root
.string
+ 1;
3314 newsym
->section
= bfd_und_section_ptr
;
3316 newsym
->flags
= BSF_OBJECT
;
3317 if (h
->root
.type
== bfd_link_hash_undefweak
)
3318 newsym
->flags
|= BSF_WEAK
;
3320 if ( !(_bfd_generic_link_add_one_symbol
3321 (info
, abfd
, newsym
->name
, newsym
->flags
,
3322 newsym
->section
, newsym
->value
, NULL
, false, false,
3323 (struct bfd_link_hash_entry
**) &fdh
)))
3327 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3331 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
3333 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3334 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3336 if (fdh
->dynindx
== -1)
3337 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
3339 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
3340 & (ELF_LINK_HASH_REF_REGULAR
3341 | ELF_LINK_HASH_REF_DYNAMIC
3342 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3343 | ELF_LINK_NON_GOT_REF
));
3344 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3346 fdh
->plt
.refcount
= h
->plt
.refcount
;
3347 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3349 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3350 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3351 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3354 /* Now that the info is on the function descriptor, clear the
3355 function code sym info. Any function code syms for which we
3356 don't have a definition in a regular file, we force local.
3357 This prevents a shared library from exporting syms that have
3358 been imported from another library. Function code syms that
3359 are really in the library we must leave global to prevent the
3360 linker dragging in a definition from a static library. */
3361 force_local
= (info
->shared
3362 && ((h
->elf_link_hash_flags
3363 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3365 || (fdh
->elf_link_hash_flags
3366 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3367 || (fdh
->elf_link_hash_flags
3368 & ELF_LINK_FORCED_LOCAL
) != 0));
3369 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3375 #define MIN_SAVE_FPR 14
3376 #define MAX_SAVE_FPR 31
3378 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3379 this hook to a) provide some gcc support functions, and b) transfer
3380 dynamic linking information gathered so far on function code symbol
3381 entries, to their corresponding function descriptor symbol entries. */
3383 ppc64_elf_func_desc_adjust (obfd
, info
)
3384 bfd
*obfd ATTRIBUTE_UNUSED
;
3385 struct bfd_link_info
*info
;
3387 struct ppc_link_hash_table
*htab
;
3388 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3389 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3391 struct elf_link_hash_entry
*h
;
3395 htab
= ppc_hash_table (info
);
3397 if (htab
->sfpr
== NULL
)
3398 /* We don't have any relocs. */
3401 /* First provide any missing ._savef* and ._restf* functions. */
3402 memcpy (sym
, "._savef14", 10);
3403 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3405 sym
[7] = i
/ 10 + '0';
3406 sym
[8] = i
% 10 + '0';
3407 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3409 && h
->root
.type
== bfd_link_hash_undefined
)
3411 if (lowest_savef
> i
)
3413 h
->root
.type
= bfd_link_hash_defined
;
3414 h
->root
.u
.def
.section
= htab
->sfpr
;
3415 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3417 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3418 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3422 memcpy (sym
, "._restf14", 10);
3423 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3425 sym
[7] = i
/ 10 + '0';
3426 sym
[8] = i
% 10 + '0';
3427 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3429 && h
->root
.type
== bfd_link_hash_undefined
)
3431 if (lowest_restf
> i
)
3433 h
->root
.type
= bfd_link_hash_defined
;
3434 h
->root
.u
.def
.section
= htab
->sfpr
;
3435 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3436 + (i
- lowest_restf
) * 4);
3438 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3439 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3443 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3445 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3446 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3448 if (htab
->sfpr
->_raw_size
== 0)
3450 if (!htab
->have_undefweak
)
3452 _bfd_strip_section_from_output (info
, htab
->sfpr
);
3456 htab
->sfpr
->_raw_size
= 4;
3459 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3462 htab
->sfpr
->contents
= p
;
3464 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3466 unsigned int fpr
= i
<< 21;
3467 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3468 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3471 if (lowest_savef
<= MAX_SAVE_FPR
)
3473 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3477 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3479 unsigned int fpr
= i
<< 21;
3480 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3481 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3484 if (lowest_restf
<= MAX_SAVE_FPR
3485 || htab
->sfpr
->_raw_size
== 4)
3487 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3493 /* Adjust a symbol defined by a dynamic object and referenced by a
3494 regular object. The current definition is in some section of the
3495 dynamic object, but we're not including those sections. We have to
3496 change the definition to something the rest of the link can
3500 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3501 struct bfd_link_info
*info
;
3502 struct elf_link_hash_entry
*h
;
3504 struct ppc_link_hash_table
*htab
;
3505 struct ppc_link_hash_entry
* eh
;
3506 struct ppc_dyn_relocs
*p
;
3508 unsigned int power_of_two
;
3510 htab
= ppc_hash_table (info
);
3512 /* Deal with function syms. */
3513 if (h
->type
== STT_FUNC
3514 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3516 /* Clear procedure linkage table information for any symbol that
3517 won't need a .plt entry. */
3518 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3519 || h
->plt
.refcount
<= 0
3520 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3522 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3523 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3525 h
->plt
.offset
= (bfd_vma
) -1;
3526 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3531 h
->plt
.offset
= (bfd_vma
) -1;
3533 /* If this is a weak symbol, and there is a real definition, the
3534 processor independent code will have arranged for us to see the
3535 real definition first, and we can just use the same value. */
3536 if (h
->weakdef
!= NULL
)
3538 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3539 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3540 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3541 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3545 /* This is a reference to a symbol defined by a dynamic object which
3546 is not a function. */
3548 /* If we are creating a shared library, we must presume that the
3549 only references to the symbol are via the global offset table.
3550 For such cases we need not do anything here; the relocations will
3551 be handled correctly by relocate_section. */
3555 /* If there are no references to this symbol that do not use the
3556 GOT, we don't need to generate a copy reloc. */
3557 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3560 eh
= (struct ppc_link_hash_entry
*) h
;
3561 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3563 s
= p
->sec
->output_section
;
3564 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3568 /* If we didn't find any dynamic relocs in read-only sections, then
3569 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3572 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3576 /* We must allocate the symbol in our .dynbss section, which will
3577 become part of the .bss section of the executable. There will be
3578 an entry for this symbol in the .dynsym section. The dynamic
3579 object will contain position independent code, so all references
3580 from the dynamic object to this symbol will go through the global
3581 offset table. The dynamic linker will use the .dynsym entry to
3582 determine the address it must put in the global offset table, so
3583 both the dynamic object and the regular object will refer to the
3584 same memory location for the variable. */
3586 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3587 copy the initial value out of the dynamic object and into the
3588 runtime process image. We need to remember the offset into the
3589 .rela.bss section we are going to use. */
3590 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3592 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3593 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3596 /* We need to figure out the alignment required for this symbol. I
3597 have no idea how ELF linkers handle this. */
3598 power_of_two
= bfd_log2 (h
->size
);
3599 if (power_of_two
> 4)
3602 /* Apply the required alignment. */
3604 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3605 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3607 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3611 /* Define the symbol as being at this point in the section. */
3612 h
->root
.u
.def
.section
= s
;
3613 h
->root
.u
.def
.value
= s
->_raw_size
;
3615 /* Increment the section size to make room for the symbol. */
3616 s
->_raw_size
+= h
->size
;
3621 /* If given a function descriptor symbol, hide both the function code
3622 sym and the descriptor. */
3624 ppc64_elf_hide_symbol (info
, h
, force_local
)
3625 struct bfd_link_info
*info
;
3626 struct elf_link_hash_entry
*h
;
3627 boolean force_local
;
3629 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3631 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3633 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3638 struct ppc_link_hash_table
*htab
;
3641 /* We aren't supposed to use alloca in BFD because on
3642 systems which do not have alloca the version in libiberty
3643 calls xmalloc, which might cause the program to crash
3644 when it runs out of memory. This function doesn't have a
3645 return status, so there's no way to gracefully return an
3646 error. So cheat. We know that string[-1] can be safely
3647 dereferenced; It's either a string in an ELF string
3648 table, or allocated in an objalloc structure. */
3650 p
= h
->root
.root
.string
- 1;
3653 htab
= ppc_hash_table (info
);
3654 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3657 /* Unfortunately, if it so happens that the string we were
3658 looking for was allocated immediately before this string,
3659 then we overwrote the string terminator. That's the only
3660 reason the lookup should fail. */
3663 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
3664 while (q
>= h
->root
.root
.string
&& *q
== *p
)
3666 if (q
< h
->root
.root
.string
&& *p
== '.')
3667 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3671 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
3672 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
3676 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3681 edit_opd (obfd
, info
)
3683 struct bfd_link_info
*info
;
3686 unsigned int bfd_indx
;
3688 for (bfd_indx
= 0, ibfd
= info
->input_bfds
;
3690 ibfd
= ibfd
->link_next
, bfd_indx
++)
3693 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3694 Elf_Internal_Shdr
*symtab_hdr
;
3695 Elf_Internal_Sym
*local_syms
;
3696 struct elf_link_hash_entry
**sym_hashes
;
3701 sec
= bfd_get_section_by_name (ibfd
, ".opd");
3705 adjust
= (long *) elf_section_data (sec
)->tdata
;
3706 BFD_ASSERT (adjust
!= NULL
);
3707 memset (adjust
, 0, (size_t) sec
->_raw_size
* sizeof (long) / 24);
3709 if (sec
->output_section
== bfd_abs_section_ptr
)
3712 /* Look through the section relocs. */
3713 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
3717 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3718 sym_hashes
= elf_sym_hashes (ibfd
);
3720 /* Read the relocations. */
3721 relstart
= _bfd_elf64_link_read_relocs (obfd
, sec
, (PTR
) NULL
,
3722 (Elf_Internal_Rela
*) NULL
,
3724 if (relstart
== NULL
)
3727 /* First run through the relocs to check they are sane, and to
3728 determine whether we need to edit this opd section. */
3731 relend
= relstart
+ sec
->reloc_count
;
3732 for (rel
= relstart
; rel
< relend
; rel
++)
3734 enum elf_ppc_reloc_type r_type
;
3735 unsigned long r_symndx
;
3737 struct elf_link_hash_entry
*h
;
3738 Elf_Internal_Sym
*sym
;
3740 /* .opd contains a regular array of 24 byte entries. We're
3741 only interested in the reloc pointing to a function entry
3743 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3744 if (r_type
== R_PPC64_TOC
)
3747 if (r_type
!= R_PPC64_ADDR64
)
3749 (*_bfd_error_handler
)
3750 (_("%s: unexpected reloc type %u in .opd section"),
3751 bfd_archive_filename (ibfd
), r_type
);
3756 if (rel
+ 1 >= relend
)
3758 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
);
3759 if (r_type
!= R_PPC64_TOC
)
3762 if (rel
->r_offset
!= offset
)
3764 /* If someone messes with .opd alignment then after a
3765 "ld -r" we might have padding in the middle of .opd.
3766 Also, there's nothing to prevent someone putting
3767 something silly in .opd with the assembler. No .opd
3768 optimization for them! */
3769 (*_bfd_error_handler
)
3770 (_("%s: .opd is not a regular array of opd entries"),
3771 bfd_archive_filename (ibfd
));
3776 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3780 if (r_symndx
>= symtab_hdr
->sh_info
)
3782 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3783 while (h
->root
.type
== bfd_link_hash_indirect
3784 || h
->root
.type
== bfd_link_hash_warning
)
3785 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3786 if (h
->root
.type
== bfd_link_hash_defined
3787 || h
->root
.type
== bfd_link_hash_defweak
)
3788 sym_sec
= h
->root
.u
.def
.section
;
3792 if (local_syms
== NULL
)
3794 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3795 if (local_syms
== NULL
)
3796 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3797 symtab_hdr
->sh_info
, 0,
3799 if (local_syms
== NULL
)
3800 goto error_free_rel
;
3802 sym
= local_syms
+ r_symndx
;
3803 if ((sym
->st_shndx
!= SHN_UNDEF
3804 && sym
->st_shndx
< SHN_LORESERVE
)
3805 || sym
->st_shndx
> SHN_HIRESERVE
)
3806 sym_sec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
3809 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
3811 (*_bfd_error_handler
)
3812 (_("%s: undefined sym `%s' in .opd section"),
3813 bfd_archive_filename (ibfd
),
3814 h
!= NULL
? h
->root
.root
.string
: "<local symbol>");
3819 if (sym_sec
->output_section
== bfd_abs_section_ptr
)
3821 /* OK, we've found a function that's excluded from the
3831 Elf_Internal_Rela
*write_rel
;
3832 bfd_byte
*rptr
, *wptr
;
3835 /* This seems a waste of time as input .opd sections are all
3836 zeros as generated by gcc, but I suppose there's no reason
3837 this will always be so. We might start putting something in
3838 the third word of .opd entries. */
3839 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
3841 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
3843 || !bfd_get_section_contents (ibfd
, sec
, loc
, (bfd_vma
) 0,
3846 if (local_syms
!= NULL
3847 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3850 if (elf_section_data (sec
)->relocs
!= relstart
)
3854 sec
->contents
= loc
;
3855 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
3858 elf_section_data (sec
)->relocs
= relstart
;
3860 wptr
= sec
->contents
;
3861 rptr
= sec
->contents
;
3862 write_rel
= relstart
;
3865 for (rel
= relstart
; rel
< relend
; rel
++)
3867 if (rel
->r_offset
== offset
)
3869 unsigned long r_symndx
;
3871 struct elf_link_hash_entry
*h
;
3872 Elf_Internal_Sym
*sym
;
3874 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3878 if (r_symndx
>= symtab_hdr
->sh_info
)
3880 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3881 while (h
->root
.type
== bfd_link_hash_indirect
3882 || h
->root
.type
== bfd_link_hash_warning
)
3883 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3884 if (h
->root
.type
== bfd_link_hash_defined
3885 || h
->root
.type
== bfd_link_hash_defweak
)
3886 sym_sec
= h
->root
.u
.def
.section
;
3890 sym
= local_syms
+ r_symndx
;
3891 if ((sym
->st_shndx
!= SHN_UNDEF
3892 && sym
->st_shndx
< SHN_LORESERVE
)
3893 || sym
->st_shndx
> SHN_HIRESERVE
)
3894 sym_sec
= bfd_section_from_elf_index (ibfd
,
3898 skip
= sym_sec
->output_section
== bfd_abs_section_ptr
;
3901 /* We'll be keeping this opd entry. */
3905 /* Redefine the function descriptor symbol
3906 to this location in the opd section.
3907 We've checked above that opd relocs are
3909 struct elf_link_hash_entry
*fdh
;
3910 struct ppc_link_hash_entry
*fh
;
3912 fh
= (struct ppc_link_hash_entry
*) h
;
3913 BFD_ASSERT (fh
->is_func
);
3915 fdh
->root
.u
.def
.value
= wptr
- sec
->contents
;
3919 /* Local syms are a bit tricky. We could
3920 tweak them as they can be cached, but
3921 we'd need to look through the local syms
3922 for the function descriptor sym which we
3923 don't have at the moment. So keep an
3924 array of adjustments. */
3925 adjust
[(rel
->r_offset
+ wptr
- rptr
) / 24]
3930 memcpy (wptr
, rptr
, 24);
3937 /* We need to adjust any reloc offsets to point to the
3938 new opd entries. While we're at it, we may as well
3939 remove redundant relocs. */
3942 rel
->r_offset
+= wptr
- rptr
;
3943 if (write_rel
!= rel
)
3944 memcpy (write_rel
, rel
, sizeof (*rel
));
3949 sec
->_cooked_size
= wptr
- sec
->contents
;
3950 sec
->reloc_count
= write_rel
- relstart
;
3952 else if (elf_section_data (sec
)->relocs
!= relstart
)
3955 if (local_syms
!= NULL
3956 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
3958 if (!info
->keep_memory
)
3961 symtab_hdr
->contents
= (unsigned char *) local_syms
;
3968 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3969 will be called from elflink.h. If elflink.h doesn't call our
3970 finish_dynamic_symbol routine, we'll need to do something about
3971 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3972 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3974 && ((INFO)->shared \
3975 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3976 && ((H)->dynindx != -1 \
3977 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3979 /* Allocate space in .plt, .got and associated reloc sections for
3983 allocate_dynrelocs (h
, inf
)
3984 struct elf_link_hash_entry
*h
;
3987 struct bfd_link_info
*info
;
3988 struct ppc_link_hash_table
*htab
;
3990 struct ppc_link_hash_entry
*eh
;
3991 struct ppc_dyn_relocs
*p
;
3993 if (h
->root
.type
== bfd_link_hash_indirect
)
3996 if (h
->root
.type
== bfd_link_hash_warning
)
3997 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3999 info
= (struct bfd_link_info
*) inf
;
4000 htab
= ppc_hash_table (info
);
4002 if (htab
->elf
.dynamic_sections_created
4003 && h
->plt
.refcount
> 0
4004 && h
->dynindx
!= -1)
4006 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
4008 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
4010 /* If this is the first .plt entry, make room for the special
4013 if (s
->_raw_size
== 0)
4014 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
4016 h
->plt
.offset
= s
->_raw_size
;
4018 /* Make room for this entry. */
4019 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4021 /* Make room for the .glink code. */
4023 if (s
->_raw_size
== 0)
4024 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
4025 /* We need bigger stubs past index 32767. */
4026 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
4028 s
->_raw_size
+= 2*4;
4030 /* We also need to make an entry in the .rela.plt section. */
4032 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
4036 h
->plt
.offset
= (bfd_vma
) -1;
4037 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4042 h
->plt
.offset
= (bfd_vma
) -1;
4043 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4046 if (h
->got
.refcount
> 0)
4050 /* Make sure this symbol is output as a dynamic symbol.
4051 Undefined weak syms won't yet be marked as dynamic. */
4052 if (h
->dynindx
== -1
4053 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4055 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
4060 h
->got
.offset
= s
->_raw_size
;
4062 dyn
= htab
->elf
.dynamic_sections_created
;
4063 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4064 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
4067 h
->got
.offset
= (bfd_vma
) -1;
4069 eh
= (struct ppc_link_hash_entry
*) h
;
4070 if (eh
->dyn_relocs
== NULL
)
4073 /* In the shared -Bsymbolic case, discard space allocated for
4074 dynamic pc-relative relocs against symbols which turn out to be
4075 defined in regular objects. For the normal shared case, discard
4076 space for relocs that have become local due to symbol visibility
4081 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
4082 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
4085 struct ppc_dyn_relocs
**pp
;
4087 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4089 p
->count
-= p
->pc_count
;
4100 /* For the non-shared case, discard space for relocs against
4101 symbols which turn out to need copy relocs or are not
4104 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4105 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4106 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4107 || (htab
->elf
.dynamic_sections_created
4108 && (h
->root
.type
== bfd_link_hash_undefweak
4109 || h
->root
.type
== bfd_link_hash_undefined
))))
4111 /* Make sure this symbol is output as a dynamic symbol.
4112 Undefined weak syms won't yet be marked as dynamic. */
4113 if (h
->dynindx
== -1
4114 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4116 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
4120 /* If that succeeded, we know we'll be keeping all the
4122 if (h
->dynindx
!= -1)
4126 eh
->dyn_relocs
= NULL
;
4131 /* Finally, allocate space. */
4132 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4134 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4135 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4141 /* Find any dynamic relocs that apply to read-only sections. */
4144 readonly_dynrelocs (h
, inf
)
4145 struct elf_link_hash_entry
*h
;
4148 struct ppc_link_hash_entry
*eh
;
4149 struct ppc_dyn_relocs
*p
;
4151 if (h
->root
.type
== bfd_link_hash_warning
)
4152 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4154 eh
= (struct ppc_link_hash_entry
*) h
;
4155 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4157 asection
*s
= p
->sec
->output_section
;
4159 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4161 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4163 info
->flags
|= DF_TEXTREL
;
4165 /* Not an error, just cut short the traversal. */
4172 /* Set the sizes of the dynamic sections. */
4175 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
4176 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4177 struct bfd_link_info
*info
;
4179 struct ppc_link_hash_table
*htab
;
4185 htab
= ppc_hash_table (info
);
4186 dynobj
= htab
->elf
.dynobj
;
4190 if (htab
->elf
.dynamic_sections_created
)
4192 /* Set the contents of the .interp section to the interpreter. */
4195 s
= bfd_get_section_by_name (dynobj
, ".interp");
4198 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4199 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4203 /* Set up .got offsets for local syms, and space for local dynamic
4205 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4207 bfd_signed_vma
*local_got
;
4208 bfd_signed_vma
*end_local_got
;
4209 bfd_size_type locsymcount
;
4210 Elf_Internal_Shdr
*symtab_hdr
;
4213 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4216 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4218 struct ppc_dyn_relocs
*p
;
4220 for (p
= *((struct ppc_dyn_relocs
**)
4221 &elf_section_data (s
)->local_dynrel
);
4225 if (!bfd_is_abs_section (p
->sec
)
4226 && bfd_is_abs_section (p
->sec
->output_section
))
4228 /* Input section has been discarded, either because
4229 it is a copy of a linkonce section or due to
4230 linker script /DISCARD/, so we'll be discarding
4233 else if (p
->count
!= 0)
4235 srel
= elf_section_data (p
->sec
)->sreloc
;
4236 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4237 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4238 info
->flags
|= DF_TEXTREL
;
4243 local_got
= elf_local_got_refcounts (ibfd
);
4247 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4248 locsymcount
= symtab_hdr
->sh_info
;
4249 end_local_got
= local_got
+ locsymcount
;
4251 srel
= htab
->srelgot
;
4252 for (; local_got
< end_local_got
; ++local_got
)
4256 *local_got
= s
->_raw_size
;
4259 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
4262 *local_got
= (bfd_vma
) -1;
4266 if (!edit_opd (output_bfd
, info
))
4269 /* Allocate global sym .plt and .got entries, and space for global
4270 sym dynamic relocs. */
4271 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
4273 /* We now have determined the sizes of the various dynamic sections.
4274 Allocate memory for them. */
4276 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4278 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4281 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
4282 /* These haven't been allocated yet; don't strip. */
4284 else if (s
== htab
->splt
4286 || s
== htab
->sglink
)
4288 /* Strip this section if we don't need it; see the
4291 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4293 if (s
->_raw_size
== 0)
4295 /* If we don't need this section, strip it from the
4296 output file. This is mostly to handle .rela.bss and
4297 .rela.plt. We must create both sections in
4298 create_dynamic_sections, because they must be created
4299 before the linker maps input sections to output
4300 sections. The linker does that before
4301 adjust_dynamic_symbol is called, and it is that
4302 function which decides whether anything needs to go
4303 into these sections. */
4307 if (s
!= htab
->srelplt
)
4310 /* We use the reloc_count field as a counter if we need
4311 to copy relocs into the output file. */
4317 /* It's not one of our sections, so don't allocate space. */
4321 if (s
->_raw_size
== 0)
4323 _bfd_strip_section_from_output (info
, s
);
4327 /* .plt is in the bss section. We don't initialise it. */
4328 if ((s
->flags
& SEC_LOAD
) == 0)
4331 /* Allocate memory for the section contents. We use bfd_zalloc
4332 here in case unused entries are not reclaimed before the
4333 section's contents are written out. This should not happen,
4334 but this way if it does, we get a R_PPC64_NONE reloc instead
4336 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4337 if (s
->contents
== NULL
)
4341 if (htab
->elf
.dynamic_sections_created
)
4343 /* Add some entries to the .dynamic section. We fill in the
4344 values later, in ppc64_elf_finish_dynamic_sections, but we
4345 must add the entries now so that we get the correct size for
4346 the .dynamic section. The DT_DEBUG entry is filled in by the
4347 dynamic linker and used by the debugger. */
4348 #define add_dynamic_entry(TAG, VAL) \
4349 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4353 if (!add_dynamic_entry (DT_DEBUG
, 0))
4357 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
4359 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4360 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4361 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4362 || !add_dynamic_entry (DT_JMPREL
, 0)
4363 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
4369 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
4370 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
4376 if (!add_dynamic_entry (DT_RELA
, 0)
4377 || !add_dynamic_entry (DT_RELASZ
, 0)
4378 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4381 /* If any dynamic relocs apply to a read-only section,
4382 then we need a DT_TEXTREL entry. */
4383 if ((info
->flags
& DF_TEXTREL
) == 0)
4384 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
4387 if ((info
->flags
& DF_TEXTREL
) != 0)
4389 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4394 #undef add_dynamic_entry
4399 /* Determine the type of stub needed, if any, for a call. */
4401 static INLINE
enum ppc_stub_type
4402 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
4403 asection
*input_sec
;
4404 const Elf_Internal_Rela
*rel
;
4405 struct ppc_link_hash_entry
**hash
;
4406 bfd_vma destination
;
4408 struct ppc_link_hash_entry
*h
= *hash
;
4410 bfd_vma branch_offset
;
4411 bfd_vma max_branch_offset
;
4412 unsigned int r_type
;
4417 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
4418 && h
->oh
->dynindx
!= -1)
4420 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
4421 return ppc_stub_plt_call
;
4424 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
4425 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
4426 return ppc_stub_none
;
4429 /* Determine where the call point is. */
4430 location
= (input_sec
->output_offset
4431 + input_sec
->output_section
->vma
4434 branch_offset
= destination
- location
;
4435 r_type
= ELF64_R_TYPE (rel
->r_info
);
4437 /* Determine if a long branch stub is needed. */
4438 max_branch_offset
= 1 << 25;
4439 if (r_type
!= (unsigned int) R_PPC64_REL24
)
4440 max_branch_offset
= 1 << 15;
4442 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
4443 /* We need a stub. Figure out whether a long_branch or plt_branch
4445 return ppc_stub_long_branch
;
4447 return ppc_stub_none
;
4450 /* Build a .plt call stub. */
4453 build_plt_stub (obfd
, p
, offset
, glink
)
4459 #define PPC_LO(v) ((v) & 0xffff)
4460 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4461 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4464 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
4465 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
4467 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
4468 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4469 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4470 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4472 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
4473 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4474 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4476 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
4477 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4478 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
4483 ppc_build_one_stub (gen_entry
, in_arg
)
4484 struct bfd_hash_entry
*gen_entry
;
4487 struct ppc_stub_hash_entry
*stub_entry
;
4488 struct ppc_branch_hash_entry
*br_entry
;
4489 struct bfd_link_info
*info
;
4490 struct ppc_link_hash_table
*htab
;
4499 /* Massage our args to the form they really have. */
4500 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4501 info
= (struct bfd_link_info
*) in_arg
;
4503 htab
= ppc_hash_table (info
);
4504 stub_sec
= stub_entry
->stub_sec
;
4506 /* Make a note of the offset within the stubs for this entry. */
4507 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
4508 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4510 stub_bfd
= stub_sec
->owner
;
4512 switch (stub_entry
->stub_type
)
4514 case ppc_stub_long_branch
:
4515 /* Branches are relative. This is where we are going to. */
4516 off
= (stub_entry
->target_value
4517 + stub_entry
->target_section
->output_offset
4518 + stub_entry
->target_section
->output_section
->vma
);
4520 /* And this is where we are coming from. */
4521 off
-= (stub_entry
->stub_offset
4522 + stub_sec
->output_offset
4523 + stub_sec
->output_section
->vma
);
4525 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
4527 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
4531 case ppc_stub_plt_branch
:
4532 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4533 stub_entry
->root
.string
+ 9,
4535 if (br_entry
== NULL
)
4537 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
4538 stub_entry
->root
.string
+ 9);
4539 htab
->stub_error
= true;
4543 off
= (stub_entry
->target_value
4544 + stub_entry
->target_section
->output_offset
4545 + stub_entry
->target_section
->output_section
->vma
);
4547 bfd_put_64 (htab
->sbrlt
->owner
, off
,
4548 htab
->sbrlt
->contents
+ br_entry
->offset
);
4552 /* Create a reloc for the branch lookup table entry. */
4553 Elf_Internal_Rela rela
;
4554 Elf64_External_Rela
*r
;
4556 rela
.r_offset
= (br_entry
->offset
4557 + htab
->sbrlt
->output_offset
4558 + htab
->sbrlt
->output_section
->vma
);
4559 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
4560 rela
.r_addend
= off
;
4562 r
= (Elf64_External_Rela
*) htab
->srelbrlt
->contents
;
4563 r
+= htab
->srelbrlt
->reloc_count
++;
4564 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, r
);
4567 off
= (br_entry
->offset
4568 + htab
->sbrlt
->output_offset
4569 + htab
->sbrlt
->output_section
->vma
4570 - elf_gp (htab
->sbrlt
->output_section
->owner
)
4573 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4575 (*_bfd_error_handler
)
4576 (_("linkage table error against `%s'"),
4577 stub_entry
->root
.string
);
4578 bfd_set_error (bfd_error_bad_value
);
4579 htab
->stub_error
= true;
4584 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
4585 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
4586 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
4587 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
4591 case ppc_stub_plt_call
:
4592 /* Build the .glink lazy link call stub. */
4593 p
= htab
->sglink
->contents
+ htab
->sglink
->_cooked_size
;
4594 indx
= htab
->sglink
->reloc_count
;
4597 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
4602 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
4604 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
4607 bfd_put_32 (htab
->sglink
->owner
,
4608 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
4610 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
4611 htab
->sglink
->reloc_count
+= 1;
4613 /* Do the best we can for shared libraries built without
4614 exporting ".foo" for each "foo". This can happen when symbol
4615 versioning scripts strip all bar a subset of symbols. */
4616 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
4617 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
4619 /* Point the symbol at the stub. There may be multiple stubs,
4620 we don't really care; The main thing is to make this sym
4621 defined somewhere. */
4622 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
4623 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
4624 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
4627 /* Now build the stub. */
4628 off
= stub_entry
->h
->elf
.plt
.offset
;
4629 if (off
>= (bfd_vma
) -2)
4632 off
&= ~ (bfd_vma
) 1;
4633 off
+= (htab
->splt
->output_offset
4634 + htab
->splt
->output_section
->vma
4635 - elf_gp (htab
->splt
->output_section
->owner
)
4638 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4640 (*_bfd_error_handler
)
4641 (_("linkage table error against `%s'"),
4642 stub_entry
->h
->elf
.root
.root
.string
);
4643 bfd_set_error (bfd_error_bad_value
);
4644 htab
->stub_error
= true;
4648 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
4657 stub_sec
->_cooked_size
+= size
;
4661 /* As above, but don't actually build the stub. Just bump offset so
4662 we know stub section sizes, and select plt_branch stubs where
4663 long_branch stubs won't do. */
4666 ppc_size_one_stub (gen_entry
, in_arg
)
4667 struct bfd_hash_entry
*gen_entry
;
4670 struct ppc_stub_hash_entry
*stub_entry
;
4671 struct ppc_link_hash_table
*htab
;
4675 /* Massage our args to the form they really have. */
4676 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4677 htab
= (struct ppc_link_hash_table
*) in_arg
;
4679 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
4681 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
4682 off
+= (htab
->splt
->output_offset
4683 + htab
->splt
->output_section
->vma
4684 - elf_gp (htab
->splt
->output_section
->owner
)
4688 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
4693 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4694 stub_entry
->stub_type
= ppc_stub_long_branch
;
4697 off
= (stub_entry
->target_value
4698 + stub_entry
->target_section
->output_offset
4699 + stub_entry
->target_section
->output_section
->vma
);
4700 off
-= (stub_entry
->stub_sec
->_raw_size
4701 + stub_entry
->stub_sec
->output_offset
4702 + stub_entry
->stub_sec
->output_section
->vma
);
4704 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
4706 struct ppc_branch_hash_entry
*br_entry
;
4708 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4709 stub_entry
->root
.string
+ 9,
4711 if (br_entry
== NULL
)
4713 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4714 stub_entry
->root
.string
+ 9);
4715 htab
->stub_error
= true;
4719 if (br_entry
->iter
!= htab
->stub_iteration
)
4721 br_entry
->iter
= htab
->stub_iteration
;
4722 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4723 htab
->sbrlt
->_raw_size
+= 8;
4725 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4730 stub_entry
->stub_sec
->_raw_size
+= size
;
4734 /* Set up various things so that we can make a list of input sections
4735 for each output section included in the link. Returns -1 on error,
4736 0 when no stubs will be needed, and 1 on success. */
4739 ppc64_elf_setup_section_lists (output_bfd
, info
)
4741 struct bfd_link_info
*info
;
4744 int top_id
, top_index
;
4746 asection
**input_list
, **list
;
4748 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4750 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
4751 || htab
->sbrlt
== NULL
)
4754 /* Find the top input section id. */
4755 for (input_bfd
= info
->input_bfds
, top_id
= 0;
4757 input_bfd
= input_bfd
->link_next
)
4759 for (section
= input_bfd
->sections
;
4761 section
= section
->next
)
4763 if (top_id
< section
->id
)
4764 top_id
= section
->id
;
4768 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4769 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4770 if (htab
->stub_group
== NULL
)
4773 /* We can't use output_bfd->section_count here to find the top output
4774 section index as some sections may have been removed, and
4775 _bfd_strip_section_from_output doesn't renumber the indices. */
4776 for (section
= output_bfd
->sections
, top_index
= 0;
4778 section
= section
->next
)
4780 if (top_index
< section
->index
)
4781 top_index
= section
->index
;
4784 htab
->top_index
= top_index
;
4785 amt
= sizeof (asection
*) * (top_index
+ 1);
4786 input_list
= (asection
**) bfd_malloc (amt
);
4787 htab
->input_list
= input_list
;
4788 if (input_list
== NULL
)
4791 /* For sections we aren't interested in, mark their entries with a
4792 value we can check later. */
4793 list
= input_list
+ top_index
;
4795 *list
= bfd_abs_section_ptr
;
4796 while (list
-- != input_list
);
4798 for (section
= output_bfd
->sections
;
4800 section
= section
->next
)
4802 if ((section
->flags
& SEC_CODE
) != 0)
4803 input_list
[section
->index
] = NULL
;
4809 /* The linker repeatedly calls this function for each input section,
4810 in the order that input sections are linked into output sections.
4811 Build lists of input sections to determine groupings between which
4812 we may insert linker stubs. */
4815 ppc64_elf_next_input_section (info
, isec
)
4816 struct bfd_link_info
*info
;
4819 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4821 if (isec
->output_section
->index
<= htab
->top_index
)
4823 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4824 if (*list
!= bfd_abs_section_ptr
)
4826 /* Steal the link_sec pointer for our list. */
4827 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4828 /* This happens to make the list in reverse order,
4829 which is what we want. */
4830 PREV_SEC (isec
) = *list
;
4836 /* See whether we can group stub sections together. Grouping stub
4837 sections may result in fewer stubs. More importantly, we need to
4838 put all .init* and .fini* stubs at the beginning of the .init or
4839 .fini output sections respectively, because glibc splits the
4840 _init and _fini functions into multiple parts. Putting a stub in
4841 the middle of a function is not a good idea. */
4844 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4845 struct ppc_link_hash_table
*htab
;
4846 bfd_size_type stub_group_size
;
4847 boolean stubs_always_before_branch
;
4849 asection
**list
= htab
->input_list
+ htab
->top_index
;
4852 asection
*tail
= *list
;
4853 if (tail
== bfd_abs_section_ptr
)
4855 while (tail
!= NULL
)
4859 bfd_size_type total
;
4862 if (tail
->_cooked_size
)
4863 total
= tail
->_cooked_size
;
4865 total
= tail
->_raw_size
;
4866 while ((prev
= PREV_SEC (curr
)) != NULL
4867 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4871 /* OK, the size from the start of CURR to the end is less
4872 than stub_group_size and thus can be handled by one stub
4873 section. (or the tail section is itself larger than
4874 stub_group_size, in which case we may be toast.) We
4875 should really be keeping track of the total size of stubs
4876 added here, as stubs contribute to the final output
4877 section size. That's a little tricky, and this way will
4878 only break if stubs added make the total size more than
4879 2^25, ie. for the default stub_group_size, if stubs total
4880 more than 2834432 bytes, or over 100000 plt call stubs. */
4883 prev
= PREV_SEC (tail
);
4884 /* Set up this stub group. */
4885 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4887 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4889 /* But wait, there's more! Input sections up to stub_group_size
4890 bytes before the stub section can be handled by it too. */
4891 if (!stubs_always_before_branch
)
4895 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4899 prev
= PREV_SEC (tail
);
4900 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4906 while (list
-- != htab
->input_list
);
4907 free (htab
->input_list
);
4911 /* Determine and set the size of the stub section for a final link.
4913 The basic idea here is to examine all the relocations looking for
4914 PC-relative calls to a target that is unreachable with a "bl"
4918 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
4919 add_stub_section
, layout_sections_again
)
4922 struct bfd_link_info
*info
;
4923 bfd_signed_vma group_size
;
4924 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
4925 void (*layout_sections_again
) PARAMS ((void));
4927 bfd_size_type stub_group_size
;
4928 boolean stubs_always_before_branch
;
4929 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4931 /* Stash our params away. */
4932 htab
->stub_bfd
= stub_bfd
;
4933 htab
->add_stub_section
= add_stub_section
;
4934 htab
->layout_sections_again
= layout_sections_again
;
4935 stubs_always_before_branch
= group_size
< 0;
4937 stub_group_size
= -group_size
;
4939 stub_group_size
= group_size
;
4940 if (stub_group_size
== 1)
4942 /* Default values. */
4943 stub_group_size
= 30720000;
4944 if (htab
->has_14bit_branch
)
4945 stub_group_size
= 30000;
4948 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
4953 unsigned int bfd_indx
;
4955 boolean stub_changed
;
4957 htab
->stub_iteration
+= 1;
4958 stub_changed
= false;
4960 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
4962 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4964 Elf_Internal_Shdr
*symtab_hdr
;
4966 Elf_Internal_Sym
*local_syms
= NULL
;
4968 /* We'll need the symbol table in a second. */
4969 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4970 if (symtab_hdr
->sh_info
== 0)
4973 /* Walk over each section attached to the input bfd. */
4974 for (section
= input_bfd
->sections
;
4976 section
= section
->next
)
4978 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
4980 /* If there aren't any relocs, then there's nothing more
4982 if ((section
->flags
& SEC_RELOC
) == 0
4983 || section
->reloc_count
== 0)
4986 /* If this section is a link-once section that will be
4987 discarded, then don't create any stubs. */
4988 if (section
->output_section
== NULL
4989 || section
->output_section
->owner
!= output_bfd
)
4992 /* Get the relocs. */
4994 = _bfd_elf64_link_read_relocs (input_bfd
, section
, NULL
,
4995 (Elf_Internal_Rela
*) NULL
,
4997 if (internal_relocs
== NULL
)
4998 goto error_ret_free_local
;
5000 /* Now examine each relocation. */
5001 irela
= internal_relocs
;
5002 irelaend
= irela
+ section
->reloc_count
;
5003 for (; irela
< irelaend
; irela
++)
5005 unsigned int r_type
, r_indx
;
5006 enum ppc_stub_type stub_type
;
5007 struct ppc_stub_hash_entry
*stub_entry
;
5010 bfd_vma destination
;
5011 struct ppc_link_hash_entry
*hash
;
5013 const asection
*id_sec
;
5015 r_type
= ELF64_R_TYPE (irela
->r_info
);
5016 r_indx
= ELF64_R_SYM (irela
->r_info
);
5018 if (r_type
>= (unsigned int) R_PPC_max
)
5020 bfd_set_error (bfd_error_bad_value
);
5021 goto error_ret_free_internal
;
5024 /* Only look for stubs on branch instructions. */
5025 if (r_type
!= (unsigned int) R_PPC64_REL24
5026 && r_type
!= (unsigned int) R_PPC64_REL14
5027 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
5028 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
5031 /* Now determine the call target, its name, value,
5037 if (r_indx
< symtab_hdr
->sh_info
)
5039 /* It's a local symbol. */
5040 Elf_Internal_Sym
*sym
;
5041 Elf_Internal_Shdr
*hdr
;
5043 if (local_syms
== NULL
)
5046 = (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5047 if (local_syms
== NULL
)
5049 = bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
,
5050 symtab_hdr
->sh_info
, 0,
5052 if (local_syms
== NULL
)
5053 goto error_ret_free_internal
;
5055 sym
= local_syms
+ r_indx
;
5056 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
5057 sym_sec
= hdr
->bfd_section
;
5058 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5059 sym_value
= sym
->st_value
;
5060 destination
= (sym_value
+ irela
->r_addend
5061 + sym_sec
->output_offset
5062 + sym_sec
->output_section
->vma
);
5066 /* It's an external symbol. */
5069 e_indx
= r_indx
- symtab_hdr
->sh_info
;
5070 hash
= ((struct ppc_link_hash_entry
*)
5071 elf_sym_hashes (input_bfd
)[e_indx
]);
5073 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
5074 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
5075 hash
= ((struct ppc_link_hash_entry
*)
5076 hash
->elf
.root
.u
.i
.link
);
5078 if (hash
->elf
.root
.type
== bfd_link_hash_defined
5079 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
5081 sym_sec
= hash
->elf
.root
.u
.def
.section
;
5082 sym_value
= hash
->elf
.root
.u
.def
.value
;
5083 if (sym_sec
->output_section
!= NULL
)
5084 destination
= (sym_value
+ irela
->r_addend
5085 + sym_sec
->output_offset
5086 + sym_sec
->output_section
->vma
);
5088 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
5090 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
5094 bfd_set_error (bfd_error_bad_value
);
5095 goto error_ret_free_internal
;
5099 /* Determine what (if any) linker stub is needed. */
5100 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
5102 if (stub_type
== ppc_stub_none
)
5105 /* Support for grouping stub sections. */
5106 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5108 /* Get the name of this stub. */
5109 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
5111 goto error_ret_free_internal
;
5113 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
5114 stub_name
, false, false);
5115 if (stub_entry
!= NULL
)
5117 /* The proper stub has already been created. */
5122 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
5123 if (stub_entry
== NULL
)
5126 error_ret_free_internal
:
5127 if (elf_section_data (section
)->relocs
== NULL
)
5128 free (internal_relocs
);
5129 error_ret_free_local
:
5130 if (local_syms
!= NULL
5131 && (symtab_hdr
->contents
5132 != (unsigned char *) local_syms
))
5137 stub_entry
->target_value
= sym_value
;
5138 stub_entry
->target_section
= sym_sec
;
5139 stub_entry
->stub_type
= stub_type
;
5140 stub_entry
->h
= hash
;
5141 stub_changed
= true;
5144 /* We're done with the internal relocs, free them. */
5145 if (elf_section_data (section
)->relocs
!= internal_relocs
)
5146 free (internal_relocs
);
5149 if (local_syms
!= NULL
5150 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5152 if (!info
->keep_memory
)
5155 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5162 /* OK, we've added some stubs. Find out the new size of the
5164 for (stub_sec
= htab
->stub_bfd
->sections
;
5166 stub_sec
= stub_sec
->next
)
5168 stub_sec
->_raw_size
= 0;
5169 stub_sec
->_cooked_size
= 0;
5171 htab
->sbrlt
->_raw_size
= 0;
5172 htab
->sbrlt
->_cooked_size
= 0;
5174 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
5176 /* Ask the linker to do its stuff. */
5177 (*htab
->layout_sections_again
) ();
5180 /* It would be nice to strip .branch_lt from the output if the
5181 section is empty, but it's too late. If we strip sections here,
5182 the dynamic symbol table is corrupted since the section symbol
5183 for the stripped section isn't written. */
5188 /* Called after we have determined section placement. If sections
5189 move, we'll be called again. Provide a value for TOCstart. */
5192 ppc64_elf_toc (obfd
)
5198 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5199 order. The TOC starts where the first of these sections starts. */
5200 s
= bfd_get_section_by_name (obfd
, ".got");
5202 s
= bfd_get_section_by_name (obfd
, ".toc");
5204 s
= bfd_get_section_by_name (obfd
, ".tocbss");
5206 s
= bfd_get_section_by_name (obfd
, ".plt");
5209 /* This may happen for
5210 o references to TOC base (SYM@toc / TOC[tc0]) without a
5213 o --gc-sections and empty TOC sections
5215 FIXME: Warn user? */
5217 /* Look for a likely section. We probably won't even be
5219 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5220 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
5221 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5224 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5225 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
5226 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5229 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5230 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
5233 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5234 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
5240 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
5245 /* Build all the stubs associated with the current output file.
5246 The stubs are kept in a hash table attached to the main linker
5247 hash table. This function is called via gldelf64ppc_finish. */
5250 ppc64_elf_build_stubs (info
)
5251 struct bfd_link_info
*info
;
5253 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5258 for (stub_sec
= htab
->stub_bfd
->sections
;
5260 stub_sec
= stub_sec
->next
)
5264 /* Allocate memory to hold the linker stubs. */
5265 size
= stub_sec
->_raw_size
;
5268 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
5269 if (stub_sec
->contents
== NULL
)
5272 stub_sec
->_cooked_size
= 0;
5275 if (htab
->splt
!= NULL
)
5277 /* Build the .glink plt call stub. */
5278 plt_r2
= (htab
->splt
->output_offset
5279 + htab
->splt
->output_section
->vma
5280 - elf_gp (htab
->splt
->output_section
->owner
)
5282 p
= htab
->sglink
->contents
;
5283 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
5284 while (p
- htab
->sglink
->contents
< GLINK_CALL_STUB_SIZE
)
5286 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
5289 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
5291 /* Use reloc_count to count entries. */
5292 htab
->sglink
->reloc_count
= 0;
5295 if (htab
->sbrlt
->_raw_size
!= 0)
5297 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
5298 htab
->sbrlt
->_raw_size
);
5299 if (htab
->sbrlt
->contents
== NULL
)
5303 /* Build the stubs as directed by the stub hash table. */
5304 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
5305 htab
->sglink
->reloc_count
= 0;
5307 for (stub_sec
= htab
->stub_bfd
->sections
;
5309 stub_sec
= stub_sec
->next
)
5311 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
5315 if (stub_sec
!= NULL
5316 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
5318 htab
->stub_error
= true;
5319 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
5322 return !htab
->stub_error
;
5325 /* Set up any other section flags and such that may be necessary. */
5328 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
5329 bfd
*abfd ATTRIBUTE_UNUSED
;
5330 Elf64_Internal_Shdr
*shdr
;
5333 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
5334 shdr
->sh_flags
|= SHF_EXCLUDE
;
5336 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
5337 shdr
->sh_type
= SHT_ORDERED
;
5342 /* The RELOCATE_SECTION function is called by the ELF backend linker
5343 to handle the relocations for a section.
5345 The relocs are always passed as Rela structures; if the section
5346 actually uses Rel structures, the r_addend field will always be
5349 This function is responsible for adjust the section contents as
5350 necessary, and (if using Rela relocs and generating a
5351 relocateable output file) adjusting the reloc addend as
5354 This function does not have to worry about setting the reloc
5355 address or the reloc symbol index.
5357 LOCAL_SYMS is a pointer to the swapped in local symbols.
5359 LOCAL_SECTIONS is an array giving the section in the input file
5360 corresponding to the st_shndx field of each local symbol.
5362 The global hash table entry for the global symbols can be found
5363 via elf_sym_hashes (input_bfd).
5365 When generating relocateable output, this function must handle
5366 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5367 going to be the section symbol corresponding to the output
5368 section, which means that the addend must be adjusted
5372 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5373 contents
, relocs
, local_syms
, local_sections
)
5375 struct bfd_link_info
*info
;
5377 asection
*input_section
;
5379 Elf_Internal_Rela
*relocs
;
5380 Elf_Internal_Sym
*local_syms
;
5381 asection
**local_sections
;
5383 struct ppc_link_hash_table
*htab
;
5384 Elf_Internal_Shdr
*symtab_hdr
;
5385 struct elf_link_hash_entry
**sym_hashes
;
5386 Elf_Internal_Rela
*rel
;
5387 Elf_Internal_Rela
*relend
;
5388 bfd_vma
*local_got_offsets
;
5392 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5393 boolean is_power4
= false;
5395 if (info
->relocateable
)
5398 /* Initialize howto table if needed. */
5399 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5402 htab
= ppc_hash_table (info
);
5403 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5404 TOCstart
= elf_gp (output_bfd
);
5405 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5406 sym_hashes
= elf_sym_hashes (input_bfd
);
5407 is_opd
= elf_section_data (input_section
)->tdata
!= NULL
;
5410 relend
= relocs
+ input_section
->reloc_count
;
5411 for (; rel
< relend
; rel
++)
5413 enum elf_ppc_reloc_type r_type
;
5416 bfd_reloc_status_type r
;
5417 Elf_Internal_Sym
*sym
;
5419 struct elf_link_hash_entry
*h
;
5420 struct elf_link_hash_entry
*fdh
;
5421 const char *sym_name
;
5422 unsigned long r_symndx
;
5424 boolean unresolved_reloc
;
5427 struct ppc_stub_hash_entry
*stub_entry
;
5428 bfd_vma max_br_offset
;
5431 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5432 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5433 offset
= rel
->r_offset
;
5434 addend
= rel
->r_addend
;
5435 r
= bfd_reloc_other
;
5436 sym
= (Elf_Internal_Sym
*) 0;
5437 sec
= (asection
*) 0;
5438 h
= (struct elf_link_hash_entry
*) 0;
5439 sym_name
= (const char *) 0;
5440 unresolved_reloc
= false;
5443 if (r_type
== R_PPC64_TOC
)
5445 /* Relocation value is TOC base. Symbol is ignored. */
5446 relocation
= TOCstart
+ TOC_BASE_OFF
;
5448 else if (r_symndx
< symtab_hdr
->sh_info
)
5450 /* It's a local symbol. */
5451 sym
= local_syms
+ r_symndx
;
5452 sec
= local_sections
[r_symndx
];
5453 sym_name
= "<local symbol>";
5455 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
5456 /* rel may have changed, update our copy of addend. */
5457 addend
= rel
->r_addend
;
5459 if (elf_section_data (sec
) != NULL
)
5461 long *opd_sym_adjust
;
5463 opd_sym_adjust
= (long *) elf_section_data (sec
)->tdata
;
5464 if (opd_sym_adjust
!= NULL
&& sym
->st_value
% 24 == 0)
5465 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
5470 /* It's a global symbol. */
5471 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5472 while (h
->root
.type
== bfd_link_hash_indirect
5473 || h
->root
.type
== bfd_link_hash_warning
)
5474 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5475 sym_name
= h
->root
.root
.string
;
5477 if (h
->root
.type
== bfd_link_hash_defined
5478 || h
->root
.type
== bfd_link_hash_defweak
)
5480 sec
= h
->root
.u
.def
.section
;
5481 if (sec
->output_section
== NULL
)
5482 /* Set a flag that will be cleared later if we find a
5483 relocation value for this symbol. output_section
5484 is typically NULL for symbols satisfied by a shared
5486 unresolved_reloc
= true;
5488 relocation
= (h
->root
.u
.def
.value
5489 + sec
->output_section
->vma
5490 + sec
->output_offset
);
5492 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5494 else if (info
->shared
5495 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
5496 && !info
->no_undefined
5497 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5501 if (! ((*info
->callbacks
->undefined_symbol
)
5502 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5503 offset
, (!info
->shared
5504 || info
->no_undefined
5505 || ELF_ST_VISIBILITY (h
->other
)))))
5511 /* First handle relocations that tweak non-addend part of insn. */
5518 /* Branch taken prediction relocations. */
5519 case R_PPC64_ADDR14_BRTAKEN
:
5520 case R_PPC64_REL14_BRTAKEN
:
5521 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5524 /* Branch not taken prediction relocations. */
5525 case R_PPC64_ADDR14_BRNTAKEN
:
5526 case R_PPC64_REL14_BRNTAKEN
:
5527 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
5530 /* Set 'a' bit. This is 0b00010 in BO field for branch
5531 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5532 for branch on CTR insns (BO == 1a00t or 1a01t). */
5533 if ((insn
& (0x14 << 21)) == (0x04 << 21))
5535 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
5543 + input_section
->output_offset
5544 + input_section
->output_section
->vma
);
5546 /* Invert 'y' bit if not the default. */
5547 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
5551 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
5555 /* A REL24 branching to a linkage function is followed by a
5556 nop. We replace the nop with a ld in order to restore
5557 the TOC base pointer. Only calls to shared objects need
5558 to alter the TOC base. These are recognized by their
5559 need for a PLT entry. */
5561 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
5562 && fdh
->plt
.offset
!= (bfd_vma
) -1
5563 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
5564 rel
, htab
)) != NULL
)
5566 boolean can_plt_call
= 0;
5568 if (offset
+ 8 <= input_section
->_cooked_size
)
5570 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
5572 || insn
== CROR_151515
|| insn
== CROR_313131
)
5574 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
5575 contents
+ offset
+ 4);
5582 /* If this is a plain branch rather than a branch
5583 and link, don't require a nop. */
5584 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5585 if ((insn
& 1) == 0)
5591 relocation
= (stub_entry
->stub_offset
5592 + stub_entry
->stub_sec
->output_offset
5593 + stub_entry
->stub_sec
->output_section
->vma
);
5595 unresolved_reloc
= false;
5600 && h
->root
.type
== bfd_link_hash_undefweak
5604 /* Tweak calls to undefined weak functions to point at a
5605 blr. We can thus call a weak function without first
5606 checking whether the function is defined. We have a
5607 blr at the end of .sfpr. */
5608 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
5609 relocation
= (htab
->sfpr
->_raw_size
- 4
5610 + htab
->sfpr
->output_offset
5611 + htab
->sfpr
->output_section
->vma
);
5613 + input_section
->output_offset
5614 + input_section
->output_section
->vma
);
5616 /* But let's not be silly about it. If the blr isn't in
5617 reach, just go to the next instruction. */
5618 if (relocation
- from
+ (1 << 25) >= (1 << 26)
5619 || htab
->sfpr
->_raw_size
== 0)
5620 relocation
= from
+ 4;
5629 (*_bfd_error_handler
)
5630 (_("%s: unknown relocation type %d for symbol %s"),
5631 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5633 bfd_set_error (bfd_error_bad_value
);
5638 case R_PPC_GNU_VTINHERIT
:
5639 case R_PPC_GNU_VTENTRY
:
5642 /* GOT16 relocations. Like an ADDR16 using the symbol's
5643 address in the GOT as relocation value instead of the
5644 symbols value itself. Also, create a GOT entry for the
5645 symbol and put the symbol value there. */
5647 case R_PPC64_GOT16_LO
:
5648 case R_PPC64_GOT16_HI
:
5649 case R_PPC64_GOT16_HA
:
5650 case R_PPC64_GOT16_DS
:
5651 case R_PPC64_GOT16_LO_DS
:
5653 /* Relocation is to the entry for this symbol in the global
5657 if (htab
->sgot
== NULL
)
5664 off
= h
->got
.offset
;
5665 dyn
= htab
->elf
.dynamic_sections_created
;
5666 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5670 || (h
->elf_link_hash_flags
5671 & ELF_LINK_FORCED_LOCAL
))
5672 && (h
->elf_link_hash_flags
5673 & ELF_LINK_HASH_DEF_REGULAR
)))
5675 /* This is actually a static link, or it is a
5676 -Bsymbolic link and the symbol is defined
5677 locally, or the symbol was forced to be local
5678 because of a version file. We must initialize
5679 this entry in the global offset table. Since the
5680 offset must always be a multiple of 8, we use the
5681 least significant bit to record whether we have
5682 initialized it already.
5684 When doing a dynamic link, we create a .rel.got
5685 relocation entry to initialize the value. This
5686 is done in the finish_dynamic_symbol routine. */
5691 bfd_put_64 (output_bfd
, relocation
,
5692 htab
->sgot
->contents
+ off
);
5697 unresolved_reloc
= false;
5701 if (local_got_offsets
== NULL
)
5704 off
= local_got_offsets
[r_symndx
];
5706 /* The offset must always be a multiple of 8. We use
5707 the least significant bit to record whether we have
5708 already processed this entry. */
5713 bfd_put_64 (output_bfd
, relocation
,
5714 htab
->sgot
->contents
+ off
);
5718 Elf_Internal_Rela outrel
;
5719 Elf64_External_Rela
*loc
;
5721 /* We need to generate a R_PPC64_RELATIVE reloc
5722 for the dynamic linker. */
5723 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5724 + htab
->sgot
->output_offset
5726 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5727 outrel
.r_addend
= relocation
;
5728 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5729 loc
+= htab
->srelgot
->reloc_count
++;
5730 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5733 local_got_offsets
[r_symndx
] |= 1;
5737 if (off
>= (bfd_vma
) -2)
5740 relocation
= htab
->sgot
->output_offset
+ off
;
5742 /* TOC base (r2) is TOC start plus 0x8000. */
5743 addend
-= TOC_BASE_OFF
;
5747 case R_PPC64_PLT16_HA
:
5748 case R_PPC64_PLT16_HI
:
5749 case R_PPC64_PLT16_LO
:
5752 /* Relocation is to the entry for this symbol in the
5753 procedure linkage table. */
5755 /* Resolve a PLT reloc against a local symbol directly,
5756 without using the procedure linkage table. */
5760 if (h
->plt
.offset
== (bfd_vma
) -1
5761 || htab
->splt
== NULL
)
5763 /* We didn't make a PLT entry for this symbol. This
5764 happens when statically linking PIC code, or when
5765 using -Bsymbolic. */
5769 relocation
= (htab
->splt
->output_section
->vma
5770 + htab
->splt
->output_offset
5772 unresolved_reloc
= false;
5775 /* TOC16 relocs. We want the offset relative to the TOC base,
5776 which is the address of the start of the TOC plus 0x8000.
5777 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5780 case R_PPC64_TOC16_LO
:
5781 case R_PPC64_TOC16_HI
:
5782 case R_PPC64_TOC16_DS
:
5783 case R_PPC64_TOC16_LO_DS
:
5784 case R_PPC64_TOC16_HA
:
5785 addend
-= TOCstart
+ TOC_BASE_OFF
;
5788 /* Relocate against the beginning of the section. */
5789 case R_PPC64_SECTOFF
:
5790 case R_PPC64_SECTOFF_LO
:
5791 case R_PPC64_SECTOFF_HI
:
5792 case R_PPC64_SECTOFF_DS
:
5793 case R_PPC64_SECTOFF_LO_DS
:
5794 case R_PPC64_SECTOFF_HA
:
5795 if (sec
!= (asection
*) 0)
5796 addend
-= sec
->output_section
->vma
;
5800 case R_PPC64_REL14_BRNTAKEN
:
5801 case R_PPC64_REL14_BRTAKEN
:
5805 /* Relocations that may need to be propagated if this is a
5809 case R_PPC64_ADDR14
:
5810 case R_PPC64_ADDR14_BRNTAKEN
:
5811 case R_PPC64_ADDR14_BRTAKEN
:
5812 case R_PPC64_ADDR16
:
5813 case R_PPC64_ADDR16_DS
:
5814 case R_PPC64_ADDR16_HA
:
5815 case R_PPC64_ADDR16_HI
:
5816 case R_PPC64_ADDR16_HIGHER
:
5817 case R_PPC64_ADDR16_HIGHERA
:
5818 case R_PPC64_ADDR16_HIGHEST
:
5819 case R_PPC64_ADDR16_HIGHESTA
:
5820 case R_PPC64_ADDR16_LO
:
5821 case R_PPC64_ADDR16_LO_DS
:
5822 case R_PPC64_ADDR24
:
5823 case R_PPC64_ADDR30
:
5824 case R_PPC64_ADDR32
:
5825 case R_PPC64_ADDR64
:
5826 case R_PPC64_UADDR16
:
5827 case R_PPC64_UADDR32
:
5828 case R_PPC64_UADDR64
:
5829 /* r_symndx will be zero only for relocs against symbols
5830 from removed linkonce sections, or sections discarded by
5837 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5840 if (NO_OPD_RELOCS
&& is_opd
)
5844 && (IS_ABSOLUTE_RELOC (r_type
)
5847 && (! info
->symbolic
5848 || (h
->elf_link_hash_flags
5849 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5853 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5854 && (((h
->elf_link_hash_flags
5855 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5856 && (h
->elf_link_hash_flags
5857 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5858 || h
->root
.type
== bfd_link_hash_undefweak
5859 || h
->root
.type
== bfd_link_hash_undefined
)))
5861 Elf_Internal_Rela outrel
;
5862 boolean skip
, relocate
;
5864 Elf64_External_Rela
*loc
;
5866 /* When generating a dynamic object, these relocations
5867 are copied into the output file to be resolved at run
5874 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5876 if (outrel
.r_offset
== (bfd_vma
) -1)
5878 else if (outrel
.r_offset
== (bfd_vma
) -2)
5879 skip
= true, relocate
= true;
5880 outrel
.r_offset
+= (input_section
->output_section
->vma
5881 + input_section
->output_offset
);
5882 outrel
.r_addend
= addend
;
5885 memset (&outrel
, 0, sizeof outrel
);
5889 && (!IS_ABSOLUTE_RELOC (r_type
)
5892 || (h
->elf_link_hash_flags
5893 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5894 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5897 /* This symbol is local, or marked to become local,
5898 or this is an opd section reloc which must point
5899 at a local function. */
5900 outrel
.r_addend
+= relocation
;
5902 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5904 if (is_opd
&& h
!= NULL
)
5906 /* Lie about opd entries. This case occurs
5907 when building shared libraries and we
5908 reference a function in another shared
5909 lib. The same thing happens for a weak
5910 definition in an application that's
5911 overridden by a strong definition in a
5912 shared lib. (I believe this is a generic
5913 bug in binutils handling of weak syms.)
5914 In these cases we won't use the opd
5915 entry in this lib. */
5916 unresolved_reloc
= false;
5918 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5924 if (bfd_is_abs_section (sec
))
5926 else if (sec
== NULL
|| sec
->owner
== NULL
)
5928 bfd_set_error (bfd_error_bad_value
);
5935 osec
= sec
->output_section
;
5936 indx
= elf_section_data (osec
)->dynindx
;
5938 /* We are turning this relocation into one
5939 against a section symbol, so subtract out
5940 the output section's address but not the
5941 offset of the input section in the output
5943 outrel
.r_addend
-= osec
->vma
;
5946 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
5950 sreloc
= elf_section_data (input_section
)->sreloc
;
5954 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
5955 loc
+= sreloc
->reloc_count
++;
5956 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5958 /* If this reloc is against an external symbol, it will
5959 be computed at runtime, so there's no need to do
5967 case R_PPC64_GLOB_DAT
:
5968 case R_PPC64_JMP_SLOT
:
5969 case R_PPC64_RELATIVE
:
5970 /* We shouldn't ever see these dynamic relocs in relocatable
5974 case R_PPC64_PLTGOT16
:
5975 case R_PPC64_PLTGOT16_DS
:
5976 case R_PPC64_PLTGOT16_HA
:
5977 case R_PPC64_PLTGOT16_HI
:
5978 case R_PPC64_PLTGOT16_LO
:
5979 case R_PPC64_PLTGOT16_LO_DS
:
5980 case R_PPC64_PLTREL32
:
5981 case R_PPC64_PLTREL64
:
5982 /* These ones haven't been implemented yet. */
5984 (*_bfd_error_handler
)
5985 (_("%s: Relocation %s is not supported for symbol %s."),
5986 bfd_archive_filename (input_bfd
),
5987 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
5989 bfd_set_error (bfd_error_invalid_operation
);
5994 /* Do any further special processing. */
6000 case R_PPC64_ADDR16_HA
:
6001 case R_PPC64_ADDR16_HIGHERA
:
6002 case R_PPC64_ADDR16_HIGHESTA
:
6003 case R_PPC64_PLT16_HA
:
6004 case R_PPC64_TOC16_HA
:
6005 case R_PPC64_SECTOFF_HA
:
6006 /* It's just possible that this symbol is a weak symbol
6007 that's not actually defined anywhere. In that case,
6008 'sec' would be NULL, and we should leave the symbol
6009 alone (it will be set to zero elsewhere in the link). */
6011 /* Add 0x10000 if sign bit in 0:15 is set. */
6012 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
6015 case R_PPC64_ADDR16_DS
:
6016 case R_PPC64_ADDR16_LO_DS
:
6017 case R_PPC64_GOT16_DS
:
6018 case R_PPC64_GOT16_LO_DS
:
6019 case R_PPC64_PLT16_LO_DS
:
6020 case R_PPC64_SECTOFF_DS
:
6021 case R_PPC64_SECTOFF_LO_DS
:
6022 case R_PPC64_TOC16_DS
:
6023 case R_PPC64_TOC16_LO_DS
:
6024 case R_PPC64_PLTGOT16_DS
:
6025 case R_PPC64_PLTGOT16_LO_DS
:
6026 if (((relocation
+ addend
) & 3) != 0)
6028 (*_bfd_error_handler
)
6029 (_("%s: error: relocation %s not a multiple of 4"),
6030 bfd_archive_filename (input_bfd
),
6031 ppc64_elf_howto_table
[(int) r_type
]->name
);
6032 bfd_set_error (bfd_error_bad_value
);
6039 case R_PPC64_REL14_BRNTAKEN
:
6040 case R_PPC64_REL14_BRTAKEN
:
6041 max_br_offset
= 1 << 15;
6045 max_br_offset
= 1 << 25;
6048 /* If the branch is out of reach, then redirect the
6049 call to the local stub for this function. */
6051 + input_section
->output_offset
6052 + input_section
->output_section
->vma
);
6053 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
6054 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
6055 rel
, htab
)) != NULL
)
6057 /* Munge up the value and addend so that we call the stub
6058 rather than the procedure directly. */
6059 relocation
= (stub_entry
->stub_offset
6060 + stub_entry
->stub_sec
->output_offset
6061 + stub_entry
->stub_sec
->output_section
->vma
);
6067 /* FIXME: Why do we allow debugging sections to escape this error?
6068 More importantly, why do we not emit dynamic relocs above in
6069 debugging sections (which are ! SEC_ALLOC)? If we had
6070 emitted the dynamic reloc, we could remove the fudge here. */
6071 if (unresolved_reloc
6073 && (input_section
->flags
& SEC_DEBUGGING
) != 0
6074 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
6076 (*_bfd_error_handler
)
6077 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
6078 bfd_archive_filename (input_bfd
),
6079 bfd_get_section_name (input_bfd
, input_section
),
6080 (long) rel
->r_offset
,
6081 h
->root
.root
.string
);
6085 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
6093 if (r
!= bfd_reloc_ok
)
6099 if (h
->root
.type
== bfd_link_hash_undefweak
6100 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
6102 /* Assume this is a call protected by other code that
6103 detects the symbol is undefined. If this is the case,
6104 we can safely ignore the overflow. If not, the
6105 program is hosed anyway, and a little warning isn't
6111 name
= h
->root
.root
.string
;
6115 name
= bfd_elf_string_from_elf_section (input_bfd
,
6116 symtab_hdr
->sh_link
,
6121 name
= bfd_section_name (input_bfd
, sec
);
6124 if (r
== bfd_reloc_overflow
)
6128 if (!((*info
->callbacks
->reloc_overflow
)
6129 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
6130 rel
->r_addend
, input_bfd
, input_section
, offset
)))
6135 (*_bfd_error_handler
)
6136 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
6137 bfd_archive_filename (input_bfd
),
6138 bfd_get_section_name (input_bfd
, input_section
),
6139 (long) rel
->r_offset
, name
, (int) r
);
6148 /* Finish up dynamic symbol handling. We set the contents of various
6149 dynamic sections here. */
6152 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6154 struct bfd_link_info
*info
;
6155 struct elf_link_hash_entry
*h
;
6156 Elf_Internal_Sym
*sym
;
6158 struct ppc_link_hash_table
*htab
;
6161 htab
= ppc_hash_table (info
);
6162 dynobj
= htab
->elf
.dynobj
;
6164 if (h
->plt
.offset
!= (bfd_vma
) -1
6165 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
6167 Elf_Internal_Rela rela
;
6168 Elf64_External_Rela
*loc
;
6170 /* This symbol has an entry in the procedure linkage table. Set
6173 if (htab
->splt
== NULL
6174 || htab
->srelplt
== NULL
6175 || htab
->sglink
== NULL
)
6178 /* Create a JMP_SLOT reloc to inform the dynamic linker to
6179 fill in the PLT entry. */
6181 rela
.r_offset
= (htab
->splt
->output_section
->vma
6182 + htab
->splt
->output_offset
6184 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
6187 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
6188 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
6189 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6192 if (h
->got
.offset
!= (bfd_vma
) -1)
6194 Elf_Internal_Rela rela
;
6195 Elf64_External_Rela
*loc
;
6197 /* This symbol has an entry in the global offset table. Set it
6200 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
6203 rela
.r_offset
= (htab
->sgot
->output_section
->vma
6204 + htab
->sgot
->output_offset
6205 + (h
->got
.offset
&~ (bfd_vma
) 1));
6207 /* If this is a static link, or it is a -Bsymbolic link and the
6208 symbol is defined locally or was forced to be local because
6209 of a version file, we just want to emit a RELATIVE reloc.
6210 The entry in the global offset table will already have been
6211 initialized in the relocate_section function. */
6215 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6216 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6218 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6219 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6220 rela
.r_addend
= (h
->root
.u
.def
.value
6221 + h
->root
.u
.def
.section
->output_section
->vma
6222 + h
->root
.u
.def
.section
->output_offset
);
6226 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6227 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6228 htab
->sgot
->contents
+ h
->got
.offset
);
6229 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
6233 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
6234 loc
+= htab
->srelgot
->reloc_count
++;
6235 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6238 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6240 Elf_Internal_Rela rela
;
6241 Elf64_External_Rela
*loc
;
6243 /* This symbol needs a copy reloc. Set it up. */
6245 if (h
->dynindx
== -1
6246 || (h
->root
.type
!= bfd_link_hash_defined
6247 && h
->root
.type
!= bfd_link_hash_defweak
)
6248 || htab
->srelbss
== NULL
)
6251 rela
.r_offset
= (h
->root
.u
.def
.value
6252 + h
->root
.u
.def
.section
->output_section
->vma
6253 + h
->root
.u
.def
.section
->output_offset
);
6254 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
6256 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
6257 loc
+= htab
->srelbss
->reloc_count
++;
6258 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6261 /* Mark some specially defined symbols as absolute. */
6262 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
6263 sym
->st_shndx
= SHN_ABS
;
6268 /* Used to decide how to sort relocs in an optimal manner for the
6269 dynamic linker, before writing them out. */
6271 static enum elf_reloc_type_class
6272 ppc64_elf_reloc_type_class (rela
)
6273 const Elf_Internal_Rela
*rela
;
6275 enum elf_ppc_reloc_type r_type
;
6277 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
6280 case R_PPC64_RELATIVE
:
6281 return reloc_class_relative
;
6282 case R_PPC64_JMP_SLOT
:
6283 return reloc_class_plt
;
6285 return reloc_class_copy
;
6287 return reloc_class_normal
;
6291 /* Finish up the dynamic sections. */
6294 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
6296 struct bfd_link_info
*info
;
6298 struct ppc_link_hash_table
*htab
;
6302 htab
= ppc_hash_table (info
);
6303 dynobj
= htab
->elf
.dynobj
;
6304 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6306 if (htab
->elf
.dynamic_sections_created
)
6308 Elf64_External_Dyn
*dyncon
, *dynconend
;
6310 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
6313 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
6314 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6315 for (; dyncon
< dynconend
; dyncon
++)
6317 Elf_Internal_Dyn dyn
;
6320 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6327 case DT_PPC64_GLINK
:
6328 dyn
.d_un
.d_ptr
= (htab
->sglink
->output_section
->vma
6329 + htab
->sglink
->output_offset
);
6333 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6335 dyn
.d_un
.d_ptr
= s
->vma
;
6338 case DT_PPC64_OPDSZ
:
6339 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6341 dyn
.d_un
.d_val
= s
->_raw_size
;
6345 dyn
.d_un
.d_ptr
= (htab
->splt
->output_section
->vma
6346 + htab
->splt
->output_offset
);
6350 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
6351 + htab
->srelplt
->output_offset
);
6355 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
6359 /* Don't count procedure linkage table relocs in the
6360 overall reloc count. */
6361 if (htab
->srelplt
!= NULL
)
6362 dyn
.d_un
.d_val
-= htab
->srelplt
->_raw_size
;
6366 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6370 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
6372 /* Fill in the first entry in the global offset table.
6373 We use it to hold the link-time TOCbase. */
6374 bfd_put_64 (output_bfd
,
6375 elf_gp (output_bfd
) + TOC_BASE_OFF
,
6376 htab
->sgot
->contents
);
6378 /* Set .got entry size. */
6379 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
6382 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
6384 /* Set .plt entry size. */
6385 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
6392 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6393 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6394 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6395 #define TARGET_BIG_NAME "elf64-powerpc"
6396 #define ELF_ARCH bfd_arch_powerpc
6397 #define ELF_MACHINE_CODE EM_PPC64
6398 #define ELF_MAXPAGESIZE 0x10000
6399 #define elf_info_to_howto ppc64_elf_info_to_howto
6401 #ifdef EM_CYGNUS_POWERPC
6402 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6406 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6409 #define elf_backend_want_got_sym 0
6410 #define elf_backend_want_plt_sym 0
6411 #define elf_backend_plt_alignment 3
6412 #define elf_backend_plt_not_loaded 1
6413 #define elf_backend_got_symbol_offset 0
6414 #define elf_backend_got_header_size 8
6415 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6416 #define elf_backend_can_gc_sections 1
6417 #define elf_backend_can_refcount 1
6418 #define elf_backend_rela_normal 1
6420 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6421 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
6422 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6423 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6424 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6425 #define bfd_elf64_get_symbol_info ppc64_elf_get_symbol_info
6427 #define elf_backend_object_p ppc64_elf_object_p
6428 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
6429 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6430 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6431 #define elf_backend_check_relocs ppc64_elf_check_relocs
6432 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6433 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6434 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6435 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6436 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6437 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6438 #define elf_backend_fake_sections ppc64_elf_fake_sections
6439 #define elf_backend_relocate_section ppc64_elf_relocate_section
6440 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6441 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6442 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6444 #include "elf64-target.h"