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. */
2039 unsigned int bfd_count
;
2041 asection
**input_list
;
2042 Elf_Internal_Sym
**all_local_syms
;
2044 /* Short-cuts to get to dynamic linker sections. */
2057 unsigned int stub_error
;
2059 /* Flag set when small branches are detected. Used to
2060 select suitable defaults for the stub group size. */
2061 unsigned int has_14bit_branch
;
2063 /* Set if we detect a reference undefined weak symbol. */
2064 unsigned int have_undefweak
;
2066 /* Incremented every time we size stubs. */
2067 unsigned int stub_iteration
;
2069 /* Small local sym to section mapping cache. */
2070 struct sym_sec_cache sym_sec
;
2073 static struct bfd_hash_entry
*stub_hash_newfunc
2074 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2075 static struct bfd_hash_entry
*branch_hash_newfunc
2076 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2077 static struct bfd_hash_entry
*link_hash_newfunc
2078 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2079 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
2081 static void ppc64_elf_link_hash_table_free
2082 PARAMS ((struct bfd_link_hash_table
*));
2083 static char *ppc_stub_name
2084 PARAMS ((const asection
*, const asection
*,
2085 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
2086 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
2087 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
2088 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
2089 static struct ppc_stub_hash_entry
*ppc_add_stub
2090 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
2091 static boolean create_linkage_sections
2092 PARAMS ((bfd
*, struct bfd_link_info
*));
2093 static boolean create_got_section
2094 PARAMS ((bfd
*, struct bfd_link_info
*));
2095 static boolean ppc64_elf_create_dynamic_sections
2096 PARAMS ((bfd
*, struct bfd_link_info
*));
2097 static void ppc64_elf_copy_indirect_symbol
2098 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
2099 static boolean ppc64_elf_check_relocs
2100 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2101 const Elf_Internal_Rela
*));
2102 static asection
* ppc64_elf_gc_mark_hook
2103 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
2104 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
2105 static boolean ppc64_elf_gc_sweep_hook
2106 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2107 const Elf_Internal_Rela
*));
2108 static boolean func_desc_adjust
2109 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2110 static boolean ppc64_elf_func_desc_adjust
2111 PARAMS ((bfd
*, struct bfd_link_info
*));
2112 static boolean ppc64_elf_adjust_dynamic_symbol
2113 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
2114 static void ppc64_elf_hide_symbol
2115 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, boolean
));
2116 static boolean edit_opd
2117 PARAMS ((bfd
*, struct bfd_link_info
*));
2118 static boolean allocate_dynrelocs
2119 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2120 static boolean readonly_dynrelocs
2121 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2122 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2123 PARAMS ((const Elf_Internal_Rela
*));
2124 static boolean ppc64_elf_size_dynamic_sections
2125 PARAMS ((bfd
*, struct bfd_link_info
*));
2126 static INLINE
enum ppc_stub_type ppc_type_of_stub
2127 PARAMS ((asection
*, const Elf_Internal_Rela
*,
2128 struct ppc_link_hash_entry
**, bfd_vma
));
2129 static bfd_byte
*build_plt_stub
2130 PARAMS ((bfd
*, bfd_byte
*, int, int));
2131 static boolean ppc_build_one_stub
2132 PARAMS ((struct bfd_hash_entry
*, PTR
));
2133 static boolean ppc_size_one_stub
2134 PARAMS ((struct bfd_hash_entry
*, PTR
));
2135 static void group_sections
2136 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, boolean
));
2137 static boolean get_local_syms
2138 PARAMS ((bfd
*, struct ppc_link_hash_table
*));
2139 static boolean ppc64_elf_fake_sections
2140 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*));
2141 static boolean ppc64_elf_relocate_section
2142 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
2143 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
2145 static boolean ppc64_elf_finish_dynamic_symbol
2146 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
2147 Elf_Internal_Sym
*));
2148 static boolean ppc64_elf_finish_dynamic_sections
2149 PARAMS ((bfd
*, struct bfd_link_info
*));
2151 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2153 #define ppc_hash_table(p) \
2154 ((struct ppc_link_hash_table *) ((p)->hash))
2156 #define ppc_stub_hash_lookup(table, string, create, copy) \
2157 ((struct ppc_stub_hash_entry *) \
2158 bfd_hash_lookup ((table), (string), (create), (copy)))
2160 #define ppc_branch_hash_lookup(table, string, create, copy) \
2161 ((struct ppc_branch_hash_entry *) \
2162 bfd_hash_lookup ((table), (string), (create), (copy)))
2164 /* Create an entry in the stub hash table. */
2166 static struct bfd_hash_entry
*
2167 stub_hash_newfunc (entry
, table
, string
)
2168 struct bfd_hash_entry
*entry
;
2169 struct bfd_hash_table
*table
;
2172 /* Allocate the structure if it has not already been allocated by a
2176 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2181 /* Call the allocation method of the superclass. */
2182 entry
= bfd_hash_newfunc (entry
, table
, string
);
2185 struct ppc_stub_hash_entry
*eh
;
2187 /* Initialize the local fields. */
2188 eh
= (struct ppc_stub_hash_entry
*) entry
;
2189 eh
->stub_sec
= NULL
;
2190 eh
->stub_offset
= 0;
2191 eh
->target_value
= 0;
2192 eh
->target_section
= NULL
;
2193 eh
->stub_type
= ppc_stub_none
;
2201 /* Create an entry in the branch hash table. */
2203 static struct bfd_hash_entry
*
2204 branch_hash_newfunc (entry
, table
, string
)
2205 struct bfd_hash_entry
*entry
;
2206 struct bfd_hash_table
*table
;
2209 /* Allocate the structure if it has not already been allocated by a
2213 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2218 /* Call the allocation method of the superclass. */
2219 entry
= bfd_hash_newfunc (entry
, table
, string
);
2222 struct ppc_branch_hash_entry
*eh
;
2224 /* Initialize the local fields. */
2225 eh
= (struct ppc_branch_hash_entry
*) entry
;
2233 /* Create an entry in a ppc64 ELF linker hash table. */
2235 static struct bfd_hash_entry
*
2236 link_hash_newfunc (entry
, table
, string
)
2237 struct bfd_hash_entry
*entry
;
2238 struct bfd_hash_table
*table
;
2241 /* Allocate the structure if it has not already been allocated by a
2245 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2250 /* Call the allocation method of the superclass. */
2251 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2254 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2256 eh
->stub_cache
= NULL
;
2257 eh
->dyn_relocs
= NULL
;
2260 eh
->is_func_descriptor
= 0;
2267 /* Create a ppc64 ELF linker hash table. */
2269 static struct bfd_link_hash_table
*
2270 ppc64_elf_link_hash_table_create (abfd
)
2273 struct ppc_link_hash_table
*htab
;
2274 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2276 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2280 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2286 /* Init the stub hash table too. */
2287 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2290 /* And the branch hash table. */
2291 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2294 htab
->stub_bfd
= NULL
;
2295 htab
->add_stub_section
= NULL
;
2296 htab
->layout_sections_again
= NULL
;
2297 htab
->stub_group
= NULL
;
2298 htab
->all_local_syms
= NULL
;
2300 htab
->srelgot
= NULL
;
2302 htab
->srelplt
= NULL
;
2303 htab
->sdynbss
= NULL
;
2304 htab
->srelbss
= NULL
;
2305 htab
->sglink
= NULL
;
2308 htab
->srelbrlt
= NULL
;
2309 htab
->stub_error
= 0;
2310 htab
->has_14bit_branch
= 0;
2311 htab
->have_undefweak
= 0;
2312 htab
->stub_iteration
= 0;
2313 htab
->sym_sec
.abfd
= NULL
;
2315 return &htab
->elf
.root
;
2318 /* Free the derived linker hash table. */
2321 ppc64_elf_link_hash_table_free (hash
)
2322 struct bfd_link_hash_table
*hash
;
2324 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
2326 bfd_hash_table_free (&ret
->stub_hash_table
);
2327 bfd_hash_table_free (&ret
->branch_hash_table
);
2328 _bfd_generic_link_hash_table_free (hash
);
2331 /* Build a name for an entry in the stub hash table. */
2334 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
2335 const asection
*input_section
;
2336 const asection
*sym_sec
;
2337 const struct ppc_link_hash_entry
*h
;
2338 const Elf_Internal_Rela
*rel
;
2343 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2344 offsets from a sym as a branch target? In fact, we could
2345 probably assume the addend is always zero. */
2346 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
2350 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
2351 stub_name
= bfd_malloc (len
);
2352 if (stub_name
!= NULL
)
2354 sprintf (stub_name
, "%08x_%s+%x",
2355 input_section
->id
& 0xffffffff,
2356 h
->elf
.root
.root
.string
,
2357 (int) rel
->r_addend
& 0xffffffff);
2362 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2363 stub_name
= bfd_malloc (len
);
2364 if (stub_name
!= NULL
)
2366 sprintf (stub_name
, "%08x_%x:%x+%x",
2367 input_section
->id
& 0xffffffff,
2368 sym_sec
->id
& 0xffffffff,
2369 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
2370 (int) rel
->r_addend
& 0xffffffff);
2376 /* Look up an entry in the stub hash. Stub entries are cached because
2377 creating the stub name takes a bit of time. */
2379 static struct ppc_stub_hash_entry
*
2380 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
2381 const asection
*input_section
;
2382 const asection
*sym_sec
;
2383 struct elf_link_hash_entry
*hash
;
2384 const Elf_Internal_Rela
*rel
;
2385 struct ppc_link_hash_table
*htab
;
2387 struct ppc_stub_hash_entry
*stub_entry
;
2388 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
2389 const asection
*id_sec
;
2391 /* If this input section is part of a group of sections sharing one
2392 stub section, then use the id of the first section in the group.
2393 Stub names need to include a section id, as there may well be
2394 more than one stub used to reach say, printf, and we need to
2395 distinguish between them. */
2396 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
2398 if (h
!= NULL
&& h
->stub_cache
!= NULL
2399 && h
->stub_cache
->h
== h
2400 && h
->stub_cache
->id_sec
== id_sec
)
2402 stub_entry
= h
->stub_cache
;
2408 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
2409 if (stub_name
== NULL
)
2412 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
2413 stub_name
, false, false);
2415 h
->stub_cache
= stub_entry
;
2423 /* Add a new stub entry to the stub hash. Not all fields of the new
2424 stub entry are initialised. */
2426 static struct ppc_stub_hash_entry
*
2427 ppc_add_stub (stub_name
, section
, htab
)
2428 const char *stub_name
;
2430 struct ppc_link_hash_table
*htab
;
2434 struct ppc_stub_hash_entry
*stub_entry
;
2436 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
2437 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
2438 if (stub_sec
== NULL
)
2440 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
2441 if (stub_sec
== NULL
)
2447 namelen
= strlen (link_sec
->name
);
2448 len
= namelen
+ sizeof (STUB_SUFFIX
);
2449 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
2453 memcpy (s_name
, link_sec
->name
, namelen
);
2454 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
2455 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
2456 if (stub_sec
== NULL
)
2458 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
2460 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
2463 /* Enter this entry into the linker stub hash table. */
2464 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
2466 if (stub_entry
== NULL
)
2468 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
2469 bfd_archive_filename (section
->owner
),
2474 stub_entry
->stub_sec
= stub_sec
;
2475 stub_entry
->stub_offset
= 0;
2476 stub_entry
->id_sec
= link_sec
;
2480 /* Create sections for linker generated code. */
2483 create_linkage_sections (dynobj
, info
)
2485 struct bfd_link_info
*info
;
2487 struct ppc_link_hash_table
*htab
;
2490 htab
= ppc_hash_table (info
);
2492 /* Create .sfpr for code to save and restore fp regs. */
2493 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
2494 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2495 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
2496 if (htab
->sfpr
== NULL
2497 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
2498 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
2501 /* Create .glink for lazy dynamic linking support. */
2502 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
2503 if (htab
->sglink
== NULL
2504 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
2505 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
2508 /* Create .branch_lt for plt_branch stubs. */
2509 flags
= (SEC_ALLOC
| SEC_LOAD
2510 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2511 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
2512 if (htab
->sbrlt
== NULL
2513 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
2514 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
2519 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2520 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2521 htab
->srelbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
2523 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
2524 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
2530 /* Create .got and .rela.got sections in DYNOBJ, and set up
2531 shortcuts to them in our hash table. */
2534 create_got_section (dynobj
, info
)
2536 struct bfd_link_info
*info
;
2538 struct ppc_link_hash_table
*htab
;
2540 if (! _bfd_elf_create_got_section (dynobj
, info
))
2543 htab
= ppc_hash_table (info
);
2544 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
2548 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
2550 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
2551 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2552 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2554 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
2559 /* Create the dynamic sections, and set up shortcuts. */
2562 ppc64_elf_create_dynamic_sections (dynobj
, info
)
2564 struct bfd_link_info
*info
;
2566 struct ppc_link_hash_table
*htab
;
2568 htab
= ppc_hash_table (info
);
2569 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
2572 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
2575 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
2576 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2577 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
2579 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2581 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
2582 || (!info
->shared
&& !htab
->srelbss
))
2588 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2591 ppc64_elf_copy_indirect_symbol (dir
, ind
)
2592 struct elf_link_hash_entry
*dir
, *ind
;
2594 struct ppc_link_hash_entry
*edir
, *eind
;
2596 edir
= (struct ppc_link_hash_entry
*) dir
;
2597 eind
= (struct ppc_link_hash_entry
*) ind
;
2599 if (eind
->dyn_relocs
!= NULL
)
2601 if (edir
->dyn_relocs
!= NULL
)
2603 struct ppc_dyn_relocs
**pp
;
2604 struct ppc_dyn_relocs
*p
;
2606 if (ind
->root
.type
== bfd_link_hash_indirect
)
2609 /* Add reloc counts against the weak sym to the strong sym
2610 list. Merge any entries against the same section. */
2611 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2613 struct ppc_dyn_relocs
*q
;
2615 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2616 if (q
->sec
== p
->sec
)
2618 q
->pc_count
+= p
->pc_count
;
2619 q
->count
+= p
->count
;
2626 *pp
= edir
->dyn_relocs
;
2629 edir
->dyn_relocs
= eind
->dyn_relocs
;
2630 eind
->dyn_relocs
= NULL
;
2633 edir
->is_func
|= eind
->is_func
;
2634 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
2635 edir
->is_entry
|= eind
->is_entry
;
2637 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
2640 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2641 symbols undefined on the command-line. */
2644 ppc64_elf_mark_entry_syms (info
)
2645 struct bfd_link_info
*info
;
2647 struct ppc_link_hash_table
*htab
;
2648 struct bfd_sym_chain
*sym
;
2650 htab
= ppc_hash_table (info
);
2651 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
2653 struct elf_link_hash_entry
*h
;
2655 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, false, false, false);
2657 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
2662 /* Look through the relocs for a section during the first phase, and
2663 calculate needed space in the global offset table, procedure
2664 linkage table, and dynamic reloc sections. */
2667 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
2669 struct bfd_link_info
*info
;
2671 const Elf_Internal_Rela
*relocs
;
2673 struct ppc_link_hash_table
*htab
;
2674 Elf_Internal_Shdr
*symtab_hdr
;
2675 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2676 const Elf_Internal_Rela
*rel
;
2677 const Elf_Internal_Rela
*rel_end
;
2679 asection
**opd_sym_map
;
2681 if (info
->relocateable
)
2684 htab
= ppc_hash_table (info
);
2685 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2687 sym_hashes
= elf_sym_hashes (abfd
);
2688 sym_hashes_end
= (sym_hashes
2689 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
2690 - symtab_hdr
->sh_info
);
2694 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
2696 /* Garbage collection needs some extra help with .opd sections.
2697 We don't want to necessarily keep everything referenced by
2698 relocs in .opd, as that would keep all functions. Instead,
2699 if we reference an .opd symbol (a function descriptor), we
2700 want to keep the function code symbol's section. This is
2701 easy for global symbols, but for local syms we need to keep
2702 information about the associated function section. Later, if
2703 edit_opd deletes entries, we'll use this array to adjust
2704 local syms in .opd. */
2706 asection
*func_section
;
2711 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
2712 opd_sym_map
= (asection
**) bfd_zalloc (abfd
, amt
);
2713 if (opd_sym_map
== NULL
)
2715 elf_section_data (sec
)->tdata
= opd_sym_map
;
2718 if (htab
->elf
.dynobj
== NULL
)
2719 htab
->elf
.dynobj
= abfd
;
2720 if (htab
->sfpr
== NULL
2721 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
2724 rel_end
= relocs
+ sec
->reloc_count
;
2725 for (rel
= relocs
; rel
< rel_end
; rel
++)
2727 unsigned long r_symndx
;
2728 struct elf_link_hash_entry
*h
;
2729 enum elf_ppc_reloc_type r_type
;
2731 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2732 if (r_symndx
< symtab_hdr
->sh_info
)
2735 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2737 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2740 /* GOT16 relocations */
2742 case R_PPC64_GOT16_DS
:
2743 case R_PPC64_GOT16_HA
:
2744 case R_PPC64_GOT16_HI
:
2745 case R_PPC64_GOT16_LO
:
2746 case R_PPC64_GOT16_LO_DS
:
2748 /* This symbol requires a global offset table entry. */
2749 if (htab
->sgot
== NULL
2750 && !create_got_section (htab
->elf
.dynobj
, info
))
2755 h
->got
.refcount
+= 1;
2759 bfd_signed_vma
*local_got_refcounts
;
2761 /* This is a global offset table entry for a local symbol. */
2762 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2763 if (local_got_refcounts
== NULL
)
2767 size
= symtab_hdr
->sh_info
;
2768 size
*= sizeof (bfd_signed_vma
);
2769 local_got_refcounts
= ((bfd_signed_vma
*)
2770 bfd_zalloc (abfd
, size
));
2771 if (local_got_refcounts
== NULL
)
2773 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2775 local_got_refcounts
[r_symndx
] += 1;
2779 case R_PPC64_PLT16_HA
:
2780 case R_PPC64_PLT16_HI
:
2781 case R_PPC64_PLT16_LO
:
2784 /* This symbol requires a procedure linkage table entry. We
2785 actually build the entry in adjust_dynamic_symbol,
2786 because this might be a case of linking PIC code without
2787 linking in any dynamic objects, in which case we don't
2788 need to generate a procedure linkage table after all. */
2791 /* It does not make sense to have a procedure linkage
2792 table entry for a local symbol. */
2793 bfd_set_error (bfd_error_bad_value
);
2797 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2798 h
->plt
.refcount
+= 1;
2799 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2802 /* The following relocations don't need to propagate the
2803 relocation if linking a shared object since they are
2804 section relative. */
2805 case R_PPC64_SECTOFF
:
2806 case R_PPC64_SECTOFF_LO
:
2807 case R_PPC64_SECTOFF_HI
:
2808 case R_PPC64_SECTOFF_HA
:
2809 case R_PPC64_SECTOFF_DS
:
2810 case R_PPC64_SECTOFF_LO_DS
:
2812 case R_PPC64_TOC16_LO
:
2813 case R_PPC64_TOC16_HI
:
2814 case R_PPC64_TOC16_HA
:
2815 case R_PPC64_TOC16_DS
:
2816 case R_PPC64_TOC16_LO_DS
:
2819 /* This relocation describes the C++ object vtable hierarchy.
2820 Reconstruct it for later use during GC. */
2821 case R_PPC64_GNU_VTINHERIT
:
2822 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2826 /* This relocation describes which C++ vtable entries are actually
2827 used. Record for later use during GC. */
2828 case R_PPC64_GNU_VTENTRY
:
2829 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2834 case R_PPC64_REL14_BRTAKEN
:
2835 case R_PPC64_REL14_BRNTAKEN
:
2836 htab
->has_14bit_branch
= 1;
2841 && h
->root
.root
.string
[0] == '.'
2842 && h
->root
.root
.string
[1] != 0)
2844 /* We may need a .plt entry if the function this reloc
2845 refers to is in a shared lib. */
2846 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2847 h
->plt
.refcount
+= 1;
2848 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2852 case R_PPC64_ADDR64
:
2853 if (opd_sym_map
!= NULL
2855 && h
->root
.root
.string
[0] == '.'
2856 && h
->root
.root
.string
[1] != 0)
2858 struct elf_link_hash_entry
*fdh
;
2860 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
2861 false, false, false);
2864 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
2865 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
2866 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
2867 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
2870 if (opd_sym_map
!= NULL
2872 && rel
+ 1 < rel_end
2873 && ((enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
)
2878 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
2883 opd_sym_map
[rel
->r_offset
/ 24] = s
;
2889 case R_PPC64_ADDR14
:
2890 case R_PPC64_ADDR14_BRNTAKEN
:
2891 case R_PPC64_ADDR14_BRTAKEN
:
2892 case R_PPC64_ADDR16
:
2893 case R_PPC64_ADDR16_DS
:
2894 case R_PPC64_ADDR16_HA
:
2895 case R_PPC64_ADDR16_HI
:
2896 case R_PPC64_ADDR16_HIGHER
:
2897 case R_PPC64_ADDR16_HIGHERA
:
2898 case R_PPC64_ADDR16_HIGHEST
:
2899 case R_PPC64_ADDR16_HIGHESTA
:
2900 case R_PPC64_ADDR16_LO
:
2901 case R_PPC64_ADDR16_LO_DS
:
2902 case R_PPC64_ADDR24
:
2903 case R_PPC64_ADDR30
:
2904 case R_PPC64_ADDR32
:
2905 case R_PPC64_UADDR16
:
2906 case R_PPC64_UADDR32
:
2907 case R_PPC64_UADDR64
:
2909 /* Don't propagate .opd relocs. */
2910 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
2913 /* If we are creating a shared library, and this is a reloc
2914 against a global symbol, or a non PC relative reloc
2915 against a local symbol, then we need to copy the reloc
2916 into the shared library. However, if we are linking with
2917 -Bsymbolic, we do not need to copy a reloc against a
2918 global symbol which is defined in an object we are
2919 including in the link (i.e., DEF_REGULAR is set). At
2920 this point we have not seen all the input files, so it is
2921 possible that DEF_REGULAR is not set now but will be set
2922 later (it is never cleared). In case of a weak definition,
2923 DEF_REGULAR may be cleared later by a strong definition in
2924 a shared library. We account for that possibility below by
2925 storing information in the relocs_copied field of the hash
2926 table entry. A similar situation occurs when creating
2927 shared libraries and symbol visibility changes render the
2930 If on the other hand, we are creating an executable, we
2931 may need to keep relocations for symbols satisfied by a
2932 dynamic library if we manage to avoid copy relocs for the
2935 && (sec
->flags
& SEC_ALLOC
) != 0
2936 && (IS_ABSOLUTE_RELOC (r_type
)
2938 && (! info
->symbolic
2939 || h
->root
.type
== bfd_link_hash_defweak
2940 || (h
->elf_link_hash_flags
2941 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2943 && (sec
->flags
& SEC_ALLOC
) != 0
2945 && (h
->root
.type
== bfd_link_hash_defweak
2946 || (h
->elf_link_hash_flags
2947 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2949 struct ppc_dyn_relocs
*p
;
2950 struct ppc_dyn_relocs
**head
;
2952 /* We must copy these reloc types into the output file.
2953 Create a reloc section in dynobj and make room for
2960 name
= (bfd_elf_string_from_elf_section
2962 elf_elfheader (abfd
)->e_shstrndx
,
2963 elf_section_data (sec
)->rel_hdr
.sh_name
));
2967 if (strncmp (name
, ".rela", 5) != 0
2968 || strcmp (bfd_get_section_name (abfd
, sec
),
2971 (*_bfd_error_handler
)
2972 (_("%s: bad relocation section name `%s\'"),
2973 bfd_archive_filename (abfd
), name
);
2974 bfd_set_error (bfd_error_bad_value
);
2977 dynobj
= htab
->elf
.dynobj
;
2978 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2983 sreloc
= bfd_make_section (dynobj
, name
);
2984 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2985 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2986 if ((sec
->flags
& SEC_ALLOC
) != 0)
2987 flags
|= SEC_ALLOC
| SEC_LOAD
;
2989 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2990 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2993 elf_section_data (sec
)->sreloc
= sreloc
;
2996 /* If this is a global symbol, we count the number of
2997 relocations we need for this symbol. */
3000 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
3004 /* Track dynamic relocs needed for local syms too.
3005 We really need local syms available to do this
3009 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3014 head
= ((struct ppc_dyn_relocs
**)
3015 &elf_section_data (s
)->local_dynrel
);
3019 if (p
== NULL
|| p
->sec
!= sec
)
3021 p
= ((struct ppc_dyn_relocs
*)
3022 bfd_alloc (htab
->elf
.dynobj
,
3023 (bfd_size_type
) sizeof *p
));
3034 if (!IS_ABSOLUTE_RELOC (r_type
))
3047 /* Return the section that should be marked against GC for a given
3051 ppc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
3053 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3054 Elf_Internal_Rela
*rel
;
3055 struct elf_link_hash_entry
*h
;
3056 Elf_Internal_Sym
*sym
;
3058 asection
*rsec
= NULL
;
3062 enum elf_ppc_reloc_type r_type
;
3063 struct ppc_link_hash_entry
*fdh
;
3065 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3068 case R_PPC64_GNU_VTINHERIT
:
3069 case R_PPC64_GNU_VTENTRY
:
3073 switch (h
->root
.type
)
3075 case bfd_link_hash_defined
:
3076 case bfd_link_hash_defweak
:
3077 fdh
= (struct ppc_link_hash_entry
*) h
;
3079 /* Function descriptor syms cause the associated
3080 function code sym section to be marked. */
3081 if (fdh
->is_func_descriptor
)
3082 rsec
= fdh
->oh
->root
.u
.def
.section
;
3084 /* Function entry syms return NULL if they are in .opd
3085 and are not ._start (or others undefined on the ld
3086 command line). Thus we avoid marking all function
3087 sections, as all functions are referenced in .opd. */
3088 else if ((fdh
->oh
!= NULL
3089 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
3090 || elf_section_data (sec
)->tdata
== NULL
)
3091 rsec
= h
->root
.u
.def
.section
;
3094 case bfd_link_hash_common
:
3095 rsec
= h
->root
.u
.c
.p
->section
;
3105 asection
**opd_sym_section
;
3107 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3108 opd_sym_section
= (asection
**) elf_section_data (rsec
)->tdata
;
3109 if (opd_sym_section
!= NULL
)
3110 rsec
= opd_sym_section
[sym
->st_value
/ 24];
3111 else if (elf_section_data (sec
)->tdata
!= NULL
)
3118 /* Update the .got, .plt. and dynamic reloc reference counts for the
3119 section being removed. */
3122 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
3124 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3126 const Elf_Internal_Rela
*relocs
;
3128 Elf_Internal_Shdr
*symtab_hdr
;
3129 struct elf_link_hash_entry
**sym_hashes
;
3130 bfd_signed_vma
*local_got_refcounts
;
3131 const Elf_Internal_Rela
*rel
, *relend
;
3133 elf_section_data (sec
)->local_dynrel
= NULL
;
3135 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3136 sym_hashes
= elf_sym_hashes (abfd
);
3137 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3139 relend
= relocs
+ sec
->reloc_count
;
3140 for (rel
= relocs
; rel
< relend
; rel
++)
3142 unsigned long r_symndx
;
3143 enum elf_ppc_reloc_type r_type
;
3144 struct elf_link_hash_entry
*h
;
3146 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3147 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3151 case R_PPC64_GOT16_DS
:
3152 case R_PPC64_GOT16_HA
:
3153 case R_PPC64_GOT16_HI
:
3154 case R_PPC64_GOT16_LO
:
3155 case R_PPC64_GOT16_LO_DS
:
3156 if (r_symndx
>= symtab_hdr
->sh_info
)
3158 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3159 if (h
->got
.refcount
> 0)
3164 if (local_got_refcounts
[r_symndx
] > 0)
3165 local_got_refcounts
[r_symndx
]--;
3169 case R_PPC64_PLT16_HA
:
3170 case R_PPC64_PLT16_HI
:
3171 case R_PPC64_PLT16_LO
:
3174 if (r_symndx
>= symtab_hdr
->sh_info
)
3176 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3177 if (h
->plt
.refcount
> 0)
3183 case R_PPC64_REL14_BRNTAKEN
:
3184 case R_PPC64_REL14_BRTAKEN
:
3186 if (r_symndx
>= symtab_hdr
->sh_info
)
3188 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3189 if (h
->plt
.refcount
> 0)
3196 if (r_symndx
>= symtab_hdr
->sh_info
)
3198 struct ppc_link_hash_entry
*eh
;
3199 struct ppc_dyn_relocs
**pp
;
3200 struct ppc_dyn_relocs
*p
;
3202 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3203 eh
= (struct ppc_link_hash_entry
*) h
;
3205 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3217 case R_PPC64_ADDR14
:
3218 case R_PPC64_ADDR14_BRNTAKEN
:
3219 case R_PPC64_ADDR14_BRTAKEN
:
3220 case R_PPC64_ADDR16
:
3221 case R_PPC64_ADDR16_DS
:
3222 case R_PPC64_ADDR16_HA
:
3223 case R_PPC64_ADDR16_HI
:
3224 case R_PPC64_ADDR16_HIGHER
:
3225 case R_PPC64_ADDR16_HIGHERA
:
3226 case R_PPC64_ADDR16_HIGHEST
:
3227 case R_PPC64_ADDR16_HIGHESTA
:
3228 case R_PPC64_ADDR16_LO
:
3229 case R_PPC64_ADDR16_LO_DS
:
3230 case R_PPC64_ADDR24
:
3231 case R_PPC64_ADDR30
:
3232 case R_PPC64_ADDR32
:
3233 case R_PPC64_ADDR64
:
3234 case R_PPC64_UADDR16
:
3235 case R_PPC64_UADDR32
:
3236 case R_PPC64_UADDR64
:
3238 if (r_symndx
>= symtab_hdr
->sh_info
)
3240 struct ppc_link_hash_entry
*eh
;
3241 struct ppc_dyn_relocs
**pp
;
3242 struct ppc_dyn_relocs
*p
;
3244 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3245 eh
= (struct ppc_link_hash_entry
*) h
;
3247 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3265 /* Called via elf_link_hash_traverse to transfer dynamic linking
3266 information on function code symbol entries to their corresponding
3267 function descriptor symbol entries. */
3269 func_desc_adjust (h
, inf
)
3270 struct elf_link_hash_entry
*h
;
3273 struct bfd_link_info
*info
;
3274 struct ppc_link_hash_table
*htab
;
3276 if (h
->root
.type
== bfd_link_hash_indirect
)
3279 if (h
->root
.type
== bfd_link_hash_warning
)
3280 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3282 info
= (struct bfd_link_info
*) inf
;
3283 htab
= ppc_hash_table (info
);
3285 /* If this is a function code symbol, transfer dynamic linking
3286 information to the function descriptor symbol. */
3287 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
3290 if (h
->root
.type
== bfd_link_hash_undefweak
3291 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
3292 htab
->have_undefweak
= true;
3294 if (h
->plt
.refcount
> 0
3295 && h
->root
.root
.string
[0] == '.'
3296 && h
->root
.root
.string
[1] != '\0')
3298 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3299 boolean force_local
;
3301 /* Find the corresponding function descriptor symbol. Create it
3302 as undefined if necessary. */
3305 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3306 false, false, true);
3310 && (h
->root
.type
== bfd_link_hash_undefined
3311 || h
->root
.type
== bfd_link_hash_undefweak
))
3316 abfd
= h
->root
.u
.undef
.abfd
;
3317 newsym
= bfd_make_empty_symbol (abfd
);
3318 newsym
->name
= h
->root
.root
.string
+ 1;
3319 newsym
->section
= bfd_und_section_ptr
;
3321 newsym
->flags
= BSF_OBJECT
;
3322 if (h
->root
.type
== bfd_link_hash_undefweak
)
3323 newsym
->flags
|= BSF_WEAK
;
3325 if ( !(_bfd_generic_link_add_one_symbol
3326 (info
, abfd
, newsym
->name
, newsym
->flags
,
3327 newsym
->section
, newsym
->value
, NULL
, false, false,
3328 (struct bfd_link_hash_entry
**) &fdh
)))
3332 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
3336 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
3338 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3339 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3341 if (fdh
->dynindx
== -1)
3342 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
3344 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
3345 & (ELF_LINK_HASH_REF_REGULAR
3346 | ELF_LINK_HASH_REF_DYNAMIC
3347 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3348 | ELF_LINK_NON_GOT_REF
));
3349 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3351 fdh
->plt
.refcount
= h
->plt
.refcount
;
3352 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3354 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3355 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3356 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3359 /* Now that the info is on the function descriptor, clear the
3360 function code sym info. Any function code syms for which we
3361 don't have a definition in a regular file, we force local.
3362 This prevents a shared library from exporting syms that have
3363 been imported from another library. Function code syms that
3364 are really in the library we must leave global to prevent the
3365 linker dragging in a definition from a static library. */
3366 force_local
= (info
->shared
3367 && ((h
->elf_link_hash_flags
3368 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3370 || (fdh
->elf_link_hash_flags
3371 & ELF_LINK_HASH_DEF_REGULAR
) == 0
3372 || (fdh
->elf_link_hash_flags
3373 & ELF_LINK_FORCED_LOCAL
) != 0));
3374 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3380 #define MIN_SAVE_FPR 14
3381 #define MAX_SAVE_FPR 31
3383 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3384 this hook to a) provide some gcc support functions, and b) transfer
3385 dynamic linking information gathered so far on function code symbol
3386 entries, to their corresponding function descriptor symbol entries. */
3388 ppc64_elf_func_desc_adjust (obfd
, info
)
3389 bfd
*obfd ATTRIBUTE_UNUSED
;
3390 struct bfd_link_info
*info
;
3392 struct ppc_link_hash_table
*htab
;
3393 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
3394 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
3396 struct elf_link_hash_entry
*h
;
3400 htab
= ppc_hash_table (info
);
3402 if (htab
->sfpr
== NULL
)
3403 /* We don't have any relocs. */
3406 /* First provide any missing ._savef* and ._restf* functions. */
3407 memcpy (sym
, "._savef14", 10);
3408 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3410 sym
[7] = i
/ 10 + '0';
3411 sym
[8] = i
% 10 + '0';
3412 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3414 && h
->root
.type
== bfd_link_hash_undefined
)
3416 if (lowest_savef
> i
)
3418 h
->root
.type
= bfd_link_hash_defined
;
3419 h
->root
.u
.def
.section
= htab
->sfpr
;
3420 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
3422 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3423 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3427 memcpy (sym
, "._restf14", 10);
3428 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
3430 sym
[7] = i
/ 10 + '0';
3431 sym
[8] = i
% 10 + '0';
3432 h
= elf_link_hash_lookup (&htab
->elf
, sym
, false, false, true);
3434 && h
->root
.type
== bfd_link_hash_undefined
)
3436 if (lowest_restf
> i
)
3438 h
->root
.type
= bfd_link_hash_defined
;
3439 h
->root
.u
.def
.section
= htab
->sfpr
;
3440 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3441 + (i
- lowest_restf
) * 4);
3443 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3444 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
3448 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
3450 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
3451 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
3453 if (htab
->sfpr
->_raw_size
== 0)
3455 if (!htab
->have_undefweak
)
3457 _bfd_strip_section_from_output (info
, htab
->sfpr
);
3461 htab
->sfpr
->_raw_size
= 4;
3464 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
3467 htab
->sfpr
->contents
= p
;
3469 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
3471 unsigned int fpr
= i
<< 21;
3472 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3473 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3476 if (lowest_savef
<= MAX_SAVE_FPR
)
3478 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3482 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
3484 unsigned int fpr
= i
<< 21;
3485 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
3486 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
3489 if (lowest_restf
<= MAX_SAVE_FPR
3490 || htab
->sfpr
->_raw_size
== 4)
3492 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
3498 /* Adjust a symbol defined by a dynamic object and referenced by a
3499 regular object. The current definition is in some section of the
3500 dynamic object, but we're not including those sections. We have to
3501 change the definition to something the rest of the link can
3505 ppc64_elf_adjust_dynamic_symbol (info
, h
)
3506 struct bfd_link_info
*info
;
3507 struct elf_link_hash_entry
*h
;
3509 struct ppc_link_hash_table
*htab
;
3510 struct ppc_link_hash_entry
* eh
;
3511 struct ppc_dyn_relocs
*p
;
3513 unsigned int power_of_two
;
3515 htab
= ppc_hash_table (info
);
3517 /* Deal with function syms. */
3518 if (h
->type
== STT_FUNC
3519 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
3521 /* Clear procedure linkage table information for any symbol that
3522 won't need a .plt entry. */
3523 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
3524 || h
->plt
.refcount
<= 0
3525 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
3527 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3528 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
3530 h
->plt
.offset
= (bfd_vma
) -1;
3531 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3536 h
->plt
.offset
= (bfd_vma
) -1;
3538 /* If this is a weak symbol, and there is a real definition, the
3539 processor independent code will have arranged for us to see the
3540 real definition first, and we can just use the same value. */
3541 if (h
->weakdef
!= NULL
)
3543 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
3544 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
3545 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
3546 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
3550 /* This is a reference to a symbol defined by a dynamic object which
3551 is not a function. */
3553 /* If we are creating a shared library, we must presume that the
3554 only references to the symbol are via the global offset table.
3555 For such cases we need not do anything here; the relocations will
3556 be handled correctly by relocate_section. */
3560 /* If there are no references to this symbol that do not use the
3561 GOT, we don't need to generate a copy reloc. */
3562 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
3565 eh
= (struct ppc_link_hash_entry
*) h
;
3566 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3568 s
= p
->sec
->output_section
;
3569 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3573 /* If we didn't find any dynamic relocs in read-only sections, then
3574 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3577 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
3581 /* We must allocate the symbol in our .dynbss section, which will
3582 become part of the .bss section of the executable. There will be
3583 an entry for this symbol in the .dynsym section. The dynamic
3584 object will contain position independent code, so all references
3585 from the dynamic object to this symbol will go through the global
3586 offset table. The dynamic linker will use the .dynsym entry to
3587 determine the address it must put in the global offset table, so
3588 both the dynamic object and the regular object will refer to the
3589 same memory location for the variable. */
3591 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3592 copy the initial value out of the dynamic object and into the
3593 runtime process image. We need to remember the offset into the
3594 .rela.bss section we are going to use. */
3595 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3597 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
3598 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3601 /* We need to figure out the alignment required for this symbol. I
3602 have no idea how ELF linkers handle this. */
3603 power_of_two
= bfd_log2 (h
->size
);
3604 if (power_of_two
> 4)
3607 /* Apply the required alignment. */
3609 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
3610 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3612 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3616 /* Define the symbol as being at this point in the section. */
3617 h
->root
.u
.def
.section
= s
;
3618 h
->root
.u
.def
.value
= s
->_raw_size
;
3620 /* Increment the section size to make room for the symbol. */
3621 s
->_raw_size
+= h
->size
;
3626 /* If given a function descriptor symbol, hide both the function code
3627 sym and the descriptor. */
3629 ppc64_elf_hide_symbol (info
, h
, force_local
)
3630 struct bfd_link_info
*info
;
3631 struct elf_link_hash_entry
*h
;
3632 boolean force_local
;
3634 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3636 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
3638 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
3643 struct ppc_link_hash_table
*htab
;
3646 /* We aren't supposed to use alloca in BFD because on
3647 systems which do not have alloca the version in libiberty
3648 calls xmalloc, which might cause the program to crash
3649 when it runs out of memory. This function doesn't have a
3650 return status, so there's no way to gracefully return an
3651 error. So cheat. We know that string[-1] can be safely
3652 dereferenced; It's either a string in an ELF string
3653 table, or allocated in an objalloc structure. */
3655 p
= h
->root
.root
.string
- 1;
3658 htab
= ppc_hash_table (info
);
3659 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3662 /* Unfortunately, if it so happens that the string we were
3663 looking for was allocated immediately before this string,
3664 then we overwrote the string terminator. That's the only
3665 reason the lookup should fail. */
3668 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
3669 while (q
>= h
->root
.root
.string
&& *q
== *p
)
3671 if (q
< h
->root
.root
.string
&& *p
== '.')
3672 fh
= elf_link_hash_lookup (&htab
->elf
, p
, false, false, false);
3676 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
3677 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
3681 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
3686 edit_opd (obfd
, info
)
3688 struct bfd_link_info
*info
;
3691 unsigned int bfd_indx
;
3692 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3694 for (bfd_indx
= 0, ibfd
= info
->input_bfds
;
3696 ibfd
= ibfd
->link_next
, bfd_indx
++)
3699 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3700 Elf_Internal_Shdr
*symtab_hdr
;
3701 struct elf_link_hash_entry
**sym_hashes
;
3706 sec
= bfd_get_section_by_name (ibfd
, ".opd");
3710 adjust
= (long *) elf_section_data (sec
)->tdata
;
3711 BFD_ASSERT (adjust
!= NULL
);
3712 memset (adjust
, 0, (size_t) sec
->_raw_size
* sizeof (long) / 24);
3714 if (sec
->output_section
== bfd_abs_section_ptr
)
3717 /* Look through the section relocs. */
3718 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
3721 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3722 sym_hashes
= elf_sym_hashes (ibfd
);
3724 /* Read the relocations. */
3725 relstart
= _bfd_elf64_link_read_relocs (obfd
, sec
, (PTR
) NULL
,
3726 (Elf_Internal_Rela
*) NULL
,
3728 if (relstart
== NULL
)
3731 /* First run through the relocs to check they are sane, and to
3732 determine whether we need to edit this opd section. */
3735 relend
= relstart
+ sec
->reloc_count
;
3736 for (rel
= relstart
; rel
< relend
; rel
++)
3738 enum elf_ppc_reloc_type r_type
;
3739 unsigned long r_symndx
;
3741 struct elf_link_hash_entry
*h
;
3742 Elf_Internal_Sym
*sym
;
3744 /* .opd contains a regular array of 24 byte entries. We're
3745 only interested in the reloc pointing to a function entry
3747 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3748 if (r_type
== R_PPC64_TOC
)
3751 if (r_type
!= R_PPC64_ADDR64
)
3753 (*_bfd_error_handler
)
3754 (_("%s: unexpected reloc type %u in .opd section"),
3755 bfd_archive_filename (ibfd
), r_type
);
3760 if (rel
+ 1 >= relend
)
3762 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
);
3763 if (r_type
!= R_PPC64_TOC
)
3766 if (rel
->r_offset
!= offset
)
3768 /* If someone messes with .opd alignment then after a
3769 "ld -r" we might have padding in the middle of .opd.
3770 Also, there's nothing to prevent someone putting
3771 something silly in .opd with the assembler. No .opd
3772 optimization for them! */
3773 (*_bfd_error_handler
)
3774 (_("%s: .opd is not a regular array of opd entries"),
3775 bfd_archive_filename (ibfd
));
3780 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3784 if (r_symndx
>= symtab_hdr
->sh_info
)
3786 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3787 while (h
->root
.type
== bfd_link_hash_indirect
3788 || h
->root
.type
== bfd_link_hash_warning
)
3789 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3790 if (h
->root
.type
== bfd_link_hash_defined
3791 || h
->root
.type
== bfd_link_hash_defweak
)
3792 sym_sec
= h
->root
.u
.def
.section
;
3796 sym
= htab
->all_local_syms
[bfd_indx
] + r_symndx
;
3797 if ((sym
->st_shndx
!= SHN_UNDEF
3798 && sym
->st_shndx
< SHN_LORESERVE
)
3799 || sym
->st_shndx
> SHN_HIRESERVE
)
3800 sym_sec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
3803 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
3805 (*_bfd_error_handler
)
3806 (_("%s: undefined sym `%s' in .opd section"),
3807 bfd_archive_filename (ibfd
),
3808 h
!= NULL
? h
->root
.root
.string
: "<local symbol>");
3813 if (sym_sec
->output_section
== bfd_abs_section_ptr
)
3815 /* OK, we've found a function that's excluded from the
3825 Elf_Internal_Rela
*write_rel
;
3826 bfd_byte
*rptr
, *wptr
;
3829 /* This seems a waste of time as input .opd sections are all
3830 zeros as generated by gcc, but I suppose there's no reason
3831 this will always be so. We might start putting something in
3832 the third word of .opd entries. */
3833 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
3835 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
3838 if (! bfd_get_section_contents (ibfd
, sec
, loc
, (bfd_vma
) 0,
3841 sec
->contents
= loc
;
3842 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
3845 elf_section_data (sec
)->relocs
= relstart
;
3847 wptr
= sec
->contents
;
3848 rptr
= sec
->contents
;
3849 write_rel
= relstart
;
3852 for (rel
= relstart
; rel
< relend
; rel
++)
3854 if (rel
->r_offset
== offset
)
3856 unsigned long r_symndx
;
3858 struct elf_link_hash_entry
*h
;
3859 Elf_Internal_Sym
*sym
;
3861 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3865 if (r_symndx
>= symtab_hdr
->sh_info
)
3867 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3868 while (h
->root
.type
== bfd_link_hash_indirect
3869 || h
->root
.type
== bfd_link_hash_warning
)
3870 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3871 if (h
->root
.type
== bfd_link_hash_defined
3872 || h
->root
.type
== bfd_link_hash_defweak
)
3873 sym_sec
= h
->root
.u
.def
.section
;
3877 sym
= htab
->all_local_syms
[bfd_indx
] + r_symndx
;
3878 if ((sym
->st_shndx
!= SHN_UNDEF
3879 && sym
->st_shndx
< SHN_LORESERVE
)
3880 || sym
->st_shndx
> SHN_HIRESERVE
)
3881 sym_sec
= bfd_section_from_elf_index (ibfd
,
3885 skip
= sym_sec
->output_section
== bfd_abs_section_ptr
;
3888 /* We'll be keeping this opd entry. */
3892 /* Redefine the function descriptor symbol
3893 to this location in the opd section.
3894 We've checked above that opd relocs are
3896 struct elf_link_hash_entry
*fdh
;
3897 struct ppc_link_hash_entry
*fh
;
3899 fh
= (struct ppc_link_hash_entry
*) h
;
3900 BFD_ASSERT (fh
->is_func
);
3902 fdh
->root
.u
.def
.value
= wptr
- sec
->contents
;
3906 /* Local syms are a bit tricky. Other parts
3907 of the linker re-read them so it's not
3908 possible to tweak local sym values. In
3909 any case, we'd need to look through the
3910 local syms for the function descriptor
3911 sym which we don't have at the moment.
3912 So keep an array of adjustments. */
3913 adjust
[(rel
->r_offset
+ wptr
- rptr
) / 24]
3918 memcpy (wptr
, rptr
, 24);
3925 /* We need to adjust any reloc offsets to point to the
3926 new opd entries. While we're at it, we may as well
3927 remove redundant relocs. */
3930 rel
->r_offset
+= wptr
- rptr
;
3931 if (write_rel
!= rel
)
3932 memcpy (write_rel
, rel
, sizeof (*rel
));
3937 sec
->_cooked_size
= wptr
- sec
->contents
;
3938 sec
->reloc_count
= write_rel
- relstart
;
3940 else if (elf_section_data (sec
)->relocs
== NULL
)
3947 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3948 will be called from elflink.h. If elflink.h doesn't call our
3949 finish_dynamic_symbol routine, we'll need to do something about
3950 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3951 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3953 && ((INFO)->shared \
3954 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3955 && ((H)->dynindx != -1 \
3956 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3958 /* Allocate space in .plt, .got and associated reloc sections for
3962 allocate_dynrelocs (h
, inf
)
3963 struct elf_link_hash_entry
*h
;
3966 struct bfd_link_info
*info
;
3967 struct ppc_link_hash_table
*htab
;
3969 struct ppc_link_hash_entry
*eh
;
3970 struct ppc_dyn_relocs
*p
;
3972 if (h
->root
.type
== bfd_link_hash_indirect
)
3975 if (h
->root
.type
== bfd_link_hash_warning
)
3976 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3978 info
= (struct bfd_link_info
*) inf
;
3979 htab
= ppc_hash_table (info
);
3981 if (htab
->elf
.dynamic_sections_created
3982 && h
->plt
.refcount
> 0
3983 && h
->dynindx
!= -1)
3985 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
3987 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
3989 /* If this is the first .plt entry, make room for the special
3992 if (s
->_raw_size
== 0)
3993 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3995 h
->plt
.offset
= s
->_raw_size
;
3997 /* Make room for this entry. */
3998 s
->_raw_size
+= PLT_ENTRY_SIZE
;
4000 /* Make room for the .glink code. */
4002 if (s
->_raw_size
== 0)
4003 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
4004 /* We need bigger stubs past index 32767. */
4005 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
4007 s
->_raw_size
+= 2*4;
4009 /* We also need to make an entry in the .rela.plt section. */
4011 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
4015 h
->plt
.offset
= (bfd_vma
) -1;
4016 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4021 h
->plt
.offset
= (bfd_vma
) -1;
4022 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4025 if (h
->got
.refcount
> 0)
4029 /* Make sure this symbol is output as a dynamic symbol.
4030 Undefined weak syms won't yet be marked as dynamic. */
4031 if (h
->dynindx
== -1
4032 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4034 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
4039 h
->got
.offset
= s
->_raw_size
;
4041 dyn
= htab
->elf
.dynamic_sections_created
;
4042 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
4043 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
4046 h
->got
.offset
= (bfd_vma
) -1;
4048 eh
= (struct ppc_link_hash_entry
*) h
;
4049 if (eh
->dyn_relocs
== NULL
)
4052 /* In the shared -Bsymbolic case, discard space allocated for
4053 dynamic pc-relative relocs against symbols which turn out to be
4054 defined in regular objects. For the normal shared case, discard
4055 space for relocs that have become local due to symbol visibility
4060 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
4061 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
4064 struct ppc_dyn_relocs
**pp
;
4066 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
4068 p
->count
-= p
->pc_count
;
4079 /* For the non-shared case, discard space for relocs against
4080 symbols which turn out to need copy relocs or are not
4083 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
4084 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4085 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4086 || (htab
->elf
.dynamic_sections_created
4087 && (h
->root
.type
== bfd_link_hash_undefweak
4088 || h
->root
.type
== bfd_link_hash_undefined
))))
4090 /* Make sure this symbol is output as a dynamic symbol.
4091 Undefined weak syms won't yet be marked as dynamic. */
4092 if (h
->dynindx
== -1
4093 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
4095 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
4099 /* If that succeeded, we know we'll be keeping all the
4101 if (h
->dynindx
!= -1)
4105 eh
->dyn_relocs
= NULL
;
4110 /* Finally, allocate space. */
4111 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4113 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
4114 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4120 /* Find any dynamic relocs that apply to read-only sections. */
4123 readonly_dynrelocs (h
, inf
)
4124 struct elf_link_hash_entry
*h
;
4127 struct ppc_link_hash_entry
*eh
;
4128 struct ppc_dyn_relocs
*p
;
4130 if (h
->root
.type
== bfd_link_hash_warning
)
4131 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4133 eh
= (struct ppc_link_hash_entry
*) h
;
4134 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4136 asection
*s
= p
->sec
->output_section
;
4138 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4140 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
4142 info
->flags
|= DF_TEXTREL
;
4144 /* Not an error, just cut short the traversal. */
4151 /* Set the sizes of the dynamic sections. */
4154 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
4155 bfd
*output_bfd ATTRIBUTE_UNUSED
;
4156 struct bfd_link_info
*info
;
4158 struct ppc_link_hash_table
*htab
;
4164 htab
= ppc_hash_table (info
);
4165 dynobj
= htab
->elf
.dynobj
;
4169 if (htab
->elf
.dynamic_sections_created
)
4171 /* Set the contents of the .interp section to the interpreter. */
4174 s
= bfd_get_section_by_name (dynobj
, ".interp");
4177 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
4178 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
4182 /* Set up .got offsets for local syms, and space for local dynamic
4184 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4186 bfd_signed_vma
*local_got
;
4187 bfd_signed_vma
*end_local_got
;
4188 bfd_size_type locsymcount
;
4189 Elf_Internal_Shdr
*symtab_hdr
;
4192 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
4195 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
4197 struct ppc_dyn_relocs
*p
;
4199 for (p
= *((struct ppc_dyn_relocs
**)
4200 &elf_section_data (s
)->local_dynrel
);
4204 if (!bfd_is_abs_section (p
->sec
)
4205 && bfd_is_abs_section (p
->sec
->output_section
))
4207 /* Input section has been discarded, either because
4208 it is a copy of a linkonce section or due to
4209 linker script /DISCARD/, so we'll be discarding
4212 else if (p
->count
!= 0)
4214 srel
= elf_section_data (p
->sec
)->sreloc
;
4215 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
4216 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
4217 info
->flags
|= DF_TEXTREL
;
4222 local_got
= elf_local_got_refcounts (ibfd
);
4226 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4227 locsymcount
= symtab_hdr
->sh_info
;
4228 end_local_got
= local_got
+ locsymcount
;
4230 srel
= htab
->srelgot
;
4231 for (; local_got
< end_local_got
; ++local_got
)
4235 *local_got
= s
->_raw_size
;
4238 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
4241 *local_got
= (bfd_vma
) -1;
4245 if (!get_local_syms (info
->input_bfds
, htab
))
4248 if (!edit_opd (output_bfd
, info
))
4251 /* Allocate global sym .plt and .got entries, and space for global
4252 sym dynamic relocs. */
4253 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
4255 /* We now have determined the sizes of the various dynamic sections.
4256 Allocate memory for them. */
4258 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
4260 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
4263 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
4264 /* These haven't been allocated yet; don't strip. */
4266 else if (s
== htab
->splt
4268 || s
== htab
->sglink
)
4270 /* Strip this section if we don't need it; see the
4273 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
4275 if (s
->_raw_size
== 0)
4277 /* If we don't need this section, strip it from the
4278 output file. This is mostly to handle .rela.bss and
4279 .rela.plt. We must create both sections in
4280 create_dynamic_sections, because they must be created
4281 before the linker maps input sections to output
4282 sections. The linker does that before
4283 adjust_dynamic_symbol is called, and it is that
4284 function which decides whether anything needs to go
4285 into these sections. */
4289 if (s
!= htab
->srelplt
)
4292 /* We use the reloc_count field as a counter if we need
4293 to copy relocs into the output file. */
4299 /* It's not one of our sections, so don't allocate space. */
4303 if (s
->_raw_size
== 0)
4305 _bfd_strip_section_from_output (info
, s
);
4309 /* .plt is in the bss section. We don't initialise it. */
4310 if ((s
->flags
& SEC_LOAD
) == 0)
4313 /* Allocate memory for the section contents. We use bfd_zalloc
4314 here in case unused entries are not reclaimed before the
4315 section's contents are written out. This should not happen,
4316 but this way if it does, we get a R_PPC64_NONE reloc instead
4318 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
4319 if (s
->contents
== NULL
)
4323 if (htab
->elf
.dynamic_sections_created
)
4325 /* Add some entries to the .dynamic section. We fill in the
4326 values later, in ppc64_elf_finish_dynamic_sections, but we
4327 must add the entries now so that we get the correct size for
4328 the .dynamic section. The DT_DEBUG entry is filled in by the
4329 dynamic linker and used by the debugger. */
4330 #define add_dynamic_entry(TAG, VAL) \
4331 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4335 if (!add_dynamic_entry (DT_DEBUG
, 0))
4339 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
4341 if (!add_dynamic_entry (DT_PLTGOT
, 0)
4342 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
4343 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
4344 || !add_dynamic_entry (DT_JMPREL
, 0)
4345 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
4351 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
4352 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
4358 if (!add_dynamic_entry (DT_RELA
, 0)
4359 || !add_dynamic_entry (DT_RELASZ
, 0)
4360 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
4363 /* If any dynamic relocs apply to a read-only section,
4364 then we need a DT_TEXTREL entry. */
4365 if ((info
->flags
& DF_TEXTREL
) == 0)
4366 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
4369 if ((info
->flags
& DF_TEXTREL
) != 0)
4371 if (!add_dynamic_entry (DT_TEXTREL
, 0))
4376 #undef add_dynamic_entry
4381 /* Determine the type of stub needed, if any, for a call. */
4383 static INLINE
enum ppc_stub_type
4384 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
4385 asection
*input_sec
;
4386 const Elf_Internal_Rela
*rel
;
4387 struct ppc_link_hash_entry
**hash
;
4388 bfd_vma destination
;
4390 struct ppc_link_hash_entry
*h
= *hash
;
4392 bfd_vma branch_offset
;
4393 bfd_vma max_branch_offset
;
4394 unsigned int r_type
;
4399 && h
->oh
->plt
.offset
!= (bfd_vma
) -1
4400 && h
->oh
->dynindx
!= -1)
4402 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
4403 return ppc_stub_plt_call
;
4406 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
4407 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
4408 return ppc_stub_none
;
4411 /* Determine where the call point is. */
4412 location
= (input_sec
->output_offset
4413 + input_sec
->output_section
->vma
4416 branch_offset
= destination
- location
;
4417 r_type
= ELF64_R_TYPE (rel
->r_info
);
4419 /* Determine if a long branch stub is needed. */
4420 max_branch_offset
= 1 << 25;
4421 if (r_type
!= (unsigned int) R_PPC64_REL24
)
4422 max_branch_offset
= 1 << 15;
4424 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
4425 /* We need a stub. Figure out whether a long_branch or plt_branch
4427 return ppc_stub_long_branch
;
4429 return ppc_stub_none
;
4432 /* Build a .plt call stub. */
4435 build_plt_stub (obfd
, p
, offset
, glink
)
4441 #define PPC_LO(v) ((v) & 0xffff)
4442 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4443 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4446 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
4447 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
4449 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
4450 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4451 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4452 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4454 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
4455 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
4456 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
4458 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
4459 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
4460 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
4465 ppc_build_one_stub (gen_entry
, in_arg
)
4466 struct bfd_hash_entry
*gen_entry
;
4469 struct ppc_stub_hash_entry
*stub_entry
;
4470 struct ppc_branch_hash_entry
*br_entry
;
4471 struct bfd_link_info
*info
;
4472 struct ppc_link_hash_table
*htab
;
4481 /* Massage our args to the form they really have. */
4482 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4483 info
= (struct bfd_link_info
*) in_arg
;
4485 htab
= ppc_hash_table (info
);
4486 stub_sec
= stub_entry
->stub_sec
;
4488 /* Make a note of the offset within the stubs for this entry. */
4489 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
4490 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
4492 stub_bfd
= stub_sec
->owner
;
4494 switch (stub_entry
->stub_type
)
4496 case ppc_stub_long_branch
:
4497 /* Branches are relative. This is where we are going to. */
4498 off
= (stub_entry
->target_value
4499 + stub_entry
->target_section
->output_offset
4500 + stub_entry
->target_section
->output_section
->vma
);
4502 /* And this is where we are coming from. */
4503 off
-= (stub_entry
->stub_offset
4504 + stub_sec
->output_offset
4505 + stub_sec
->output_section
->vma
);
4507 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
4509 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
4513 case ppc_stub_plt_branch
:
4514 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4515 stub_entry
->root
.string
+ 9,
4517 if (br_entry
== NULL
)
4519 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
4520 stub_entry
->root
.string
+ 9);
4521 htab
->stub_error
= true;
4525 off
= (stub_entry
->target_value
4526 + stub_entry
->target_section
->output_offset
4527 + stub_entry
->target_section
->output_section
->vma
);
4529 bfd_put_64 (htab
->sbrlt
->owner
, off
,
4530 htab
->sbrlt
->contents
+ br_entry
->offset
);
4534 /* Create a reloc for the branch lookup table entry. */
4535 Elf_Internal_Rela rela
;
4536 Elf64_External_Rela
*r
;
4538 rela
.r_offset
= (br_entry
->offset
4539 + htab
->sbrlt
->output_offset
4540 + htab
->sbrlt
->output_section
->vma
);
4541 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
4542 rela
.r_addend
= off
;
4544 r
= (Elf64_External_Rela
*) htab
->srelbrlt
->contents
;
4545 r
+= htab
->srelbrlt
->reloc_count
++;
4546 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, r
);
4549 off
= (br_entry
->offset
4550 + htab
->sbrlt
->output_offset
4551 + htab
->sbrlt
->output_section
->vma
4552 - elf_gp (htab
->sbrlt
->output_section
->owner
)
4555 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4557 (*_bfd_error_handler
)
4558 (_("linkage table error against `%s'"),
4559 stub_entry
->root
.string
);
4560 bfd_set_error (bfd_error_bad_value
);
4561 htab
->stub_error
= true;
4566 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
4567 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
4568 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
4569 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
4573 case ppc_stub_plt_call
:
4574 /* Build the .glink lazy link call stub. */
4575 p
= htab
->sglink
->contents
+ htab
->sglink
->_cooked_size
;
4576 indx
= htab
->sglink
->reloc_count
;
4579 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
4584 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
4586 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
4589 bfd_put_32 (htab
->sglink
->owner
,
4590 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
4592 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
4593 htab
->sglink
->reloc_count
+= 1;
4595 /* Do the best we can for shared libraries built without
4596 exporting ".foo" for each "foo". This can happen when symbol
4597 versioning scripts strip all bar a subset of symbols. */
4598 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
4599 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
4601 /* Point the symbol at the stub. There may be multiple stubs,
4602 we don't really care; The main thing is to make this sym
4603 defined somewhere. */
4604 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
4605 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
4606 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
4609 /* Now build the stub. */
4610 off
= stub_entry
->h
->elf
.plt
.offset
;
4611 if (off
>= (bfd_vma
) -2)
4614 off
&= ~ (bfd_vma
) 1;
4615 off
+= (htab
->splt
->output_offset
4616 + htab
->splt
->output_section
->vma
4617 - elf_gp (htab
->splt
->output_section
->owner
)
4620 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
4622 (*_bfd_error_handler
)
4623 (_("linkage table error against `%s'"),
4624 stub_entry
->h
->elf
.root
.root
.string
);
4625 bfd_set_error (bfd_error_bad_value
);
4626 htab
->stub_error
= true;
4630 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
4639 stub_sec
->_cooked_size
+= size
;
4643 /* As above, but don't actually build the stub. Just bump offset so
4644 we know stub section sizes, and select plt_branch stubs where
4645 long_branch stubs won't do. */
4648 ppc_size_one_stub (gen_entry
, in_arg
)
4649 struct bfd_hash_entry
*gen_entry
;
4652 struct ppc_stub_hash_entry
*stub_entry
;
4653 struct ppc_link_hash_table
*htab
;
4657 /* Massage our args to the form they really have. */
4658 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
4659 htab
= (struct ppc_link_hash_table
*) in_arg
;
4661 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
4663 off
= stub_entry
->h
->elf
.plt
.offset
& ~(bfd_vma
) 1;
4664 off
+= (htab
->splt
->output_offset
4665 + htab
->splt
->output_section
->vma
4666 - elf_gp (htab
->splt
->output_section
->owner
)
4670 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
4675 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4676 stub_entry
->stub_type
= ppc_stub_long_branch
;
4679 off
= (stub_entry
->target_value
4680 + stub_entry
->target_section
->output_offset
4681 + stub_entry
->target_section
->output_section
->vma
);
4682 off
-= (stub_entry
->stub_sec
->_raw_size
4683 + stub_entry
->stub_sec
->output_offset
4684 + stub_entry
->stub_sec
->output_section
->vma
);
4686 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
4688 struct ppc_branch_hash_entry
*br_entry
;
4690 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
4691 stub_entry
->root
.string
+ 9,
4693 if (br_entry
== NULL
)
4695 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
4696 stub_entry
->root
.string
+ 9);
4697 htab
->stub_error
= true;
4701 if (br_entry
->iter
!= htab
->stub_iteration
)
4703 br_entry
->iter
= htab
->stub_iteration
;
4704 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
4705 htab
->sbrlt
->_raw_size
+= 8;
4707 stub_entry
->stub_type
= ppc_stub_plt_branch
;
4712 stub_entry
->stub_sec
->_raw_size
+= size
;
4716 /* Set up various things so that we can make a list of input sections
4717 for each output section included in the link. Returns -1 on error,
4718 0 when no stubs will be needed, and 1 on success. */
4721 ppc64_elf_setup_section_lists (output_bfd
, info
)
4723 struct bfd_link_info
*info
;
4726 int top_id
, top_index
;
4728 asection
**input_list
, **list
;
4730 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4732 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
4733 || htab
->sbrlt
== NULL
)
4736 /* Find the top input section id. */
4737 for (input_bfd
= info
->input_bfds
, top_id
= 0;
4739 input_bfd
= input_bfd
->link_next
)
4741 for (section
= input_bfd
->sections
;
4743 section
= section
->next
)
4745 if (top_id
< section
->id
)
4746 top_id
= section
->id
;
4750 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
4751 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
4752 if (htab
->stub_group
== NULL
)
4755 /* We can't use output_bfd->section_count here to find the top output
4756 section index as some sections may have been removed, and
4757 _bfd_strip_section_from_output doesn't renumber the indices. */
4758 for (section
= output_bfd
->sections
, top_index
= 0;
4760 section
= section
->next
)
4762 if (top_index
< section
->index
)
4763 top_index
= section
->index
;
4766 htab
->top_index
= top_index
;
4767 amt
= sizeof (asection
*) * (top_index
+ 1);
4768 input_list
= (asection
**) bfd_malloc (amt
);
4769 htab
->input_list
= input_list
;
4770 if (input_list
== NULL
)
4773 /* For sections we aren't interested in, mark their entries with a
4774 value we can check later. */
4775 list
= input_list
+ top_index
;
4777 *list
= bfd_abs_section_ptr
;
4778 while (list
-- != input_list
);
4780 for (section
= output_bfd
->sections
;
4782 section
= section
->next
)
4784 if ((section
->flags
& SEC_CODE
) != 0)
4785 input_list
[section
->index
] = NULL
;
4791 /* The linker repeatedly calls this function for each input section,
4792 in the order that input sections are linked into output sections.
4793 Build lists of input sections to determine groupings between which
4794 we may insert linker stubs. */
4797 ppc64_elf_next_input_section (info
, isec
)
4798 struct bfd_link_info
*info
;
4801 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4803 if (isec
->output_section
->index
<= htab
->top_index
)
4805 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
4806 if (*list
!= bfd_abs_section_ptr
)
4808 /* Steal the link_sec pointer for our list. */
4809 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4810 /* This happens to make the list in reverse order,
4811 which is what we want. */
4812 PREV_SEC (isec
) = *list
;
4818 /* See whether we can group stub sections together. Grouping stub
4819 sections may result in fewer stubs. More importantly, we need to
4820 put all .init* and .fini* stubs at the beginning of the .init or
4821 .fini output sections respectively, because glibc splits the
4822 _init and _fini functions into multiple parts. Putting a stub in
4823 the middle of a function is not a good idea. */
4826 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
4827 struct ppc_link_hash_table
*htab
;
4828 bfd_size_type stub_group_size
;
4829 boolean stubs_always_before_branch
;
4831 asection
**list
= htab
->input_list
+ htab
->top_index
;
4834 asection
*tail
= *list
;
4835 if (tail
== bfd_abs_section_ptr
)
4837 while (tail
!= NULL
)
4841 bfd_size_type total
;
4844 if (tail
->_cooked_size
)
4845 total
= tail
->_cooked_size
;
4847 total
= tail
->_raw_size
;
4848 while ((prev
= PREV_SEC (curr
)) != NULL
4849 && ((total
+= curr
->output_offset
- prev
->output_offset
)
4853 /* OK, the size from the start of CURR to the end is less
4854 than stub_group_size and thus can be handled by one stub
4855 section. (or the tail section is itself larger than
4856 stub_group_size, in which case we may be toast.) We
4857 should really be keeping track of the total size of stubs
4858 added here, as stubs contribute to the final output
4859 section size. That's a little tricky, and this way will
4860 only break if stubs added make the total size more than
4861 2^25, ie. for the default stub_group_size, if stubs total
4862 more than 2834432 bytes, or over 100000 plt call stubs. */
4865 prev
= PREV_SEC (tail
);
4866 /* Set up this stub group. */
4867 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4869 while (tail
!= curr
&& (tail
= prev
) != NULL
);
4871 /* But wait, there's more! Input sections up to stub_group_size
4872 bytes before the stub section can be handled by it too. */
4873 if (!stubs_always_before_branch
)
4877 && ((total
+= tail
->output_offset
- prev
->output_offset
)
4881 prev
= PREV_SEC (tail
);
4882 htab
->stub_group
[tail
->id
].link_sec
= curr
;
4888 while (list
-- != htab
->input_list
);
4889 free (htab
->input_list
);
4893 /* Read in all local syms for all input bfds. */
4896 get_local_syms (input_bfd
, htab
)
4898 struct ppc_link_hash_table
*htab
;
4900 unsigned int bfd_indx
;
4902 Elf_Internal_Sym
*local_syms
, **all_local_syms
;
4905 if (htab
->all_local_syms
!= NULL
)
4908 /* We want to read in symbol extension records only once. To do this
4909 we need to read in the local symbols in parallel and save them for
4910 later use; so hold pointers to the local symbols in an array. */
4911 for (ibfd
= input_bfd
, bfd_indx
= 0; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4913 htab
->bfd_count
= bfd_indx
;
4914 amt
= sizeof (Elf_Internal_Sym
*) * bfd_indx
;
4915 all_local_syms
= (Elf_Internal_Sym
**) bfd_zmalloc (amt
);
4916 htab
->all_local_syms
= all_local_syms
;
4917 if (all_local_syms
== NULL
)
4920 /* Walk over all the input BFDs, swapping in local symbols. */
4923 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
4925 Elf_Internal_Shdr
*symtab_hdr
;
4926 Elf_Internal_Shdr
*shndx_hdr
;
4927 Elf_Internal_Sym
*isym
;
4928 Elf64_External_Sym
*ext_syms
, *esym
, *end_sy
;
4929 Elf_External_Sym_Shndx
*shndx_buf
, *shndx
;
4930 bfd_size_type sec_size
;
4932 if (bfd_get_flavour (input_bfd
) != bfd_target_elf_flavour
)
4935 /* We'll need the symbol table in a second. */
4936 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4937 if (symtab_hdr
->sh_info
== 0)
4940 /* We need an array of the local symbols attached to the input bfd.
4941 Unfortunately, we're going to have to read & swap them in. */
4942 sec_size
= symtab_hdr
->sh_info
;
4943 sec_size
*= sizeof (Elf_Internal_Sym
);
4944 local_syms
= (Elf_Internal_Sym
*) bfd_malloc (sec_size
);
4945 if (local_syms
== NULL
)
4948 all_local_syms
[bfd_indx
] = local_syms
;
4949 sec_size
= symtab_hdr
->sh_info
;
4950 sec_size
*= sizeof (Elf64_External_Sym
);
4951 ext_syms
= (Elf64_External_Sym
*) bfd_malloc (sec_size
);
4952 if (ext_syms
== NULL
)
4955 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
4956 || bfd_bread ((PTR
) ext_syms
, sec_size
, input_bfd
) != sec_size
)
4958 error_ret_free_ext_syms
:
4964 shndx_hdr
= &elf_tdata (input_bfd
)->symtab_shndx_hdr
;
4965 if (shndx_hdr
->sh_size
!= 0)
4967 sec_size
= symtab_hdr
->sh_info
;
4968 sec_size
*= sizeof (Elf_External_Sym_Shndx
);
4969 shndx_buf
= (Elf_External_Sym_Shndx
*) bfd_malloc (sec_size
);
4970 if (shndx_buf
== NULL
)
4971 goto error_ret_free_ext_syms
;
4973 if (bfd_seek (input_bfd
, shndx_hdr
->sh_offset
, SEEK_SET
) != 0
4974 || bfd_bread ((PTR
) shndx_buf
, sec_size
, input_bfd
) != sec_size
)
4977 goto error_ret_free_ext_syms
;
4981 /* Swap the local symbols in. */
4982 for (esym
= ext_syms
, end_sy
= esym
+ symtab_hdr
->sh_info
,
4983 isym
= local_syms
, shndx
= shndx_buf
;
4985 esym
++, isym
++, shndx
= (shndx
? shndx
+ 1 : NULL
))
4986 bfd_elf64_swap_symbol_in (input_bfd
, (const PTR
) esym
,
4987 (const PTR
) shndx
, isym
);
4989 /* Now we can free the external symbols. */
4997 /* Determine and set the size of the stub section for a final link.
4999 The basic idea here is to examine all the relocations looking for
5000 PC-relative calls to a target that is unreachable with a "bl"
5004 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
5005 add_stub_section
, layout_sections_again
)
5008 struct bfd_link_info
*info
;
5009 bfd_signed_vma group_size
;
5010 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
5011 void (*layout_sections_again
) PARAMS ((void));
5013 bfd_size_type stub_group_size
;
5014 boolean stubs_always_before_branch
;
5015 boolean ret
= false;
5016 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5018 /* Stash our params away. */
5019 htab
->stub_bfd
= stub_bfd
;
5020 htab
->add_stub_section
= add_stub_section
;
5021 htab
->layout_sections_again
= layout_sections_again
;
5022 stubs_always_before_branch
= group_size
< 0;
5024 stub_group_size
= -group_size
;
5026 stub_group_size
= group_size
;
5027 if (stub_group_size
== 1)
5029 /* Default values. */
5030 stub_group_size
= 30720000;
5031 if (htab
->has_14bit_branch
)
5032 stub_group_size
= 30000;
5035 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
5037 if (! get_local_syms (info
->input_bfds
, htab
))
5039 if (htab
->all_local_syms
)
5040 goto error_ret_free_local
;
5047 unsigned int bfd_indx
;
5049 boolean stub_changed
;
5051 htab
->stub_iteration
+= 1;
5052 stub_changed
= false;
5054 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
5056 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
5058 Elf_Internal_Shdr
*symtab_hdr
;
5060 Elf_Internal_Sym
*local_syms
;
5062 /* We'll need the symbol table in a second. */
5063 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5064 if (symtab_hdr
->sh_info
== 0)
5067 local_syms
= htab
->all_local_syms
[bfd_indx
];
5069 /* Walk over each section attached to the input bfd. */
5070 for (section
= input_bfd
->sections
;
5072 section
= section
->next
)
5074 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
5076 /* If there aren't any relocs, then there's nothing more
5078 if ((section
->flags
& SEC_RELOC
) == 0
5079 || section
->reloc_count
== 0)
5082 /* If this section is a link-once section that will be
5083 discarded, then don't create any stubs. */
5084 if (section
->output_section
== NULL
5085 || section
->output_section
->owner
!= output_bfd
)
5088 /* Get the relocs. */
5090 = _bfd_elf64_link_read_relocs (input_bfd
, section
, NULL
,
5091 (Elf_Internal_Rela
*) NULL
,
5093 if (internal_relocs
== NULL
)
5094 goto error_ret_free_local
;
5096 /* Now examine each relocation. */
5097 irela
= internal_relocs
;
5098 irelaend
= irela
+ section
->reloc_count
;
5099 for (; irela
< irelaend
; irela
++)
5101 unsigned int r_type
, r_indx
;
5102 enum ppc_stub_type stub_type
;
5103 struct ppc_stub_hash_entry
*stub_entry
;
5106 bfd_vma destination
;
5107 struct ppc_link_hash_entry
*hash
;
5109 const asection
*id_sec
;
5111 r_type
= ELF64_R_TYPE (irela
->r_info
);
5112 r_indx
= ELF64_R_SYM (irela
->r_info
);
5114 if (r_type
>= (unsigned int) R_PPC_max
)
5116 bfd_set_error (bfd_error_bad_value
);
5117 error_ret_free_internal
:
5118 if (elf_section_data (section
)->relocs
== NULL
)
5119 free (internal_relocs
);
5120 goto error_ret_free_local
;
5123 /* Only look for stubs on branch instructions. */
5124 if (r_type
!= (unsigned int) R_PPC64_REL24
5125 && r_type
!= (unsigned int) R_PPC64_REL14
5126 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
5127 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
5130 /* Now determine the call target, its name, value,
5136 if (r_indx
< symtab_hdr
->sh_info
)
5138 /* It's a local symbol. */
5139 Elf_Internal_Sym
*sym
;
5140 Elf_Internal_Shdr
*hdr
;
5142 sym
= local_syms
+ r_indx
;
5143 hdr
= elf_elfsections (input_bfd
)[sym
->st_shndx
];
5144 sym_sec
= hdr
->bfd_section
;
5145 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
)
5146 sym_value
= sym
->st_value
;
5147 destination
= (sym_value
+ irela
->r_addend
5148 + sym_sec
->output_offset
5149 + sym_sec
->output_section
->vma
);
5153 /* It's an external symbol. */
5156 e_indx
= r_indx
- symtab_hdr
->sh_info
;
5157 hash
= ((struct ppc_link_hash_entry
*)
5158 elf_sym_hashes (input_bfd
)[e_indx
]);
5160 while (hash
->elf
.root
.type
== bfd_link_hash_indirect
5161 || hash
->elf
.root
.type
== bfd_link_hash_warning
)
5162 hash
= ((struct ppc_link_hash_entry
*)
5163 hash
->elf
.root
.u
.i
.link
);
5165 if (hash
->elf
.root
.type
== bfd_link_hash_defined
5166 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
5168 sym_sec
= hash
->elf
.root
.u
.def
.section
;
5169 sym_value
= hash
->elf
.root
.u
.def
.value
;
5170 if (sym_sec
->output_section
!= NULL
)
5171 destination
= (sym_value
+ irela
->r_addend
5172 + sym_sec
->output_offset
5173 + sym_sec
->output_section
->vma
);
5175 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
5177 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
5181 bfd_set_error (bfd_error_bad_value
);
5182 goto error_ret_free_internal
;
5186 /* Determine what (if any) linker stub is needed. */
5187 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
5189 if (stub_type
== ppc_stub_none
)
5192 /* Support for grouping stub sections. */
5193 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
5195 /* Get the name of this stub. */
5196 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
5198 goto error_ret_free_internal
;
5200 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
5201 stub_name
, false, false);
5202 if (stub_entry
!= NULL
)
5204 /* The proper stub has already been created. */
5209 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
5210 if (stub_entry
== NULL
)
5213 goto error_ret_free_internal
;
5216 stub_entry
->target_value
= sym_value
;
5217 stub_entry
->target_section
= sym_sec
;
5218 stub_entry
->stub_type
= stub_type
;
5219 stub_entry
->h
= hash
;
5220 stub_changed
= true;
5223 /* We're done with the internal relocs, free them. */
5224 if (elf_section_data (section
)->relocs
== NULL
)
5225 free (internal_relocs
);
5232 /* OK, we've added some stubs. Find out the new size of the
5234 for (stub_sec
= htab
->stub_bfd
->sections
;
5236 stub_sec
= stub_sec
->next
)
5238 stub_sec
->_raw_size
= 0;
5239 stub_sec
->_cooked_size
= 0;
5241 htab
->sbrlt
->_raw_size
= 0;
5242 htab
->sbrlt
->_cooked_size
= 0;
5244 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
5246 /* Ask the linker to do its stuff. */
5247 (*htab
->layout_sections_again
) ();
5250 /* It would be nice to strip .branch_lt from the output if the
5251 section is empty, but it's too late. If we strip sections here,
5252 the dynamic symbol table is corrupted since the section symbol
5253 for the stripped section isn't written. */
5257 error_ret_free_local
:
5258 while (htab
->bfd_count
-- > 0)
5259 if (htab
->all_local_syms
[htab
->bfd_count
])
5260 free (htab
->all_local_syms
[htab
->bfd_count
]);
5261 free (htab
->all_local_syms
);
5266 /* Called after we have determined section placement. If sections
5267 move, we'll be called again. Provide a value for TOCstart. */
5270 ppc64_elf_toc (obfd
)
5276 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5277 order. The TOC starts where the first of these sections starts. */
5278 s
= bfd_get_section_by_name (obfd
, ".got");
5280 s
= bfd_get_section_by_name (obfd
, ".toc");
5282 s
= bfd_get_section_by_name (obfd
, ".tocbss");
5284 s
= bfd_get_section_by_name (obfd
, ".plt");
5287 /* This may happen for
5288 o references to TOC base (SYM@toc / TOC[tc0]) without a
5291 o --gc-sections and empty TOC sections
5293 FIXME: Warn user? */
5295 /* Look for a likely section. We probably won't even be
5297 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5298 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
5299 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5302 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5303 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
5304 == (SEC_ALLOC
| SEC_SMALL_DATA
))
5307 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5308 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
5311 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
5312 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
5318 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
5323 /* Build all the stubs associated with the current output file.
5324 The stubs are kept in a hash table attached to the main linker
5325 hash table. This function is called via gldelf64ppc_finish. */
5328 ppc64_elf_build_stubs (info
)
5329 struct bfd_link_info
*info
;
5331 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5336 for (stub_sec
= htab
->stub_bfd
->sections
;
5338 stub_sec
= stub_sec
->next
)
5342 /* Allocate memory to hold the linker stubs. */
5343 size
= stub_sec
->_raw_size
;
5346 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
5347 if (stub_sec
->contents
== NULL
)
5350 stub_sec
->_cooked_size
= 0;
5353 if (htab
->splt
!= NULL
)
5355 /* Build the .glink plt call stub. */
5356 plt_r2
= (htab
->splt
->output_offset
5357 + htab
->splt
->output_section
->vma
5358 - elf_gp (htab
->splt
->output_section
->owner
)
5360 p
= htab
->sglink
->contents
;
5361 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
5362 while (p
- htab
->sglink
->contents
< GLINK_CALL_STUB_SIZE
)
5364 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
5367 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
5369 /* Use reloc_count to count entries. */
5370 htab
->sglink
->reloc_count
= 0;
5373 if (htab
->sbrlt
->_raw_size
!= 0)
5375 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
5376 htab
->sbrlt
->_raw_size
);
5377 if (htab
->sbrlt
->contents
== NULL
)
5381 /* Build the stubs as directed by the stub hash table. */
5382 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
5383 htab
->sglink
->reloc_count
= 0;
5385 for (stub_sec
= htab
->stub_bfd
->sections
;
5387 stub_sec
= stub_sec
->next
)
5389 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
5393 if (stub_sec
!= NULL
5394 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
5396 htab
->stub_error
= true;
5397 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
5400 return !htab
->stub_error
;
5403 /* Set up any other section flags and such that may be necessary. */
5406 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
5407 bfd
*abfd ATTRIBUTE_UNUSED
;
5408 Elf64_Internal_Shdr
*shdr
;
5411 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
5412 shdr
->sh_flags
|= SHF_EXCLUDE
;
5414 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
5415 shdr
->sh_type
= SHT_ORDERED
;
5420 /* The RELOCATE_SECTION function is called by the ELF backend linker
5421 to handle the relocations for a section.
5423 The relocs are always passed as Rela structures; if the section
5424 actually uses Rel structures, the r_addend field will always be
5427 This function is responsible for adjust the section contents as
5428 necessary, and (if using Rela relocs and generating a
5429 relocateable output file) adjusting the reloc addend as
5432 This function does not have to worry about setting the reloc
5433 address or the reloc symbol index.
5435 LOCAL_SYMS is a pointer to the swapped in local symbols.
5437 LOCAL_SECTIONS is an array giving the section in the input file
5438 corresponding to the st_shndx field of each local symbol.
5440 The global hash table entry for the global symbols can be found
5441 via elf_sym_hashes (input_bfd).
5443 When generating relocateable output, this function must handle
5444 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5445 going to be the section symbol corresponding to the output
5446 section, which means that the addend must be adjusted
5450 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
5451 contents
, relocs
, local_syms
, local_sections
)
5453 struct bfd_link_info
*info
;
5455 asection
*input_section
;
5457 Elf_Internal_Rela
*relocs
;
5458 Elf_Internal_Sym
*local_syms
;
5459 asection
**local_sections
;
5461 struct ppc_link_hash_table
*htab
;
5462 Elf_Internal_Shdr
*symtab_hdr
;
5463 struct elf_link_hash_entry
**sym_hashes
;
5464 Elf_Internal_Rela
*rel
;
5465 Elf_Internal_Rela
*relend
;
5466 bfd_vma
*local_got_offsets
;
5470 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5471 boolean is_power4
= false;
5473 if (info
->relocateable
)
5476 /* Initialize howto table if needed. */
5477 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5480 htab
= ppc_hash_table (info
);
5481 local_got_offsets
= elf_local_got_offsets (input_bfd
);
5482 TOCstart
= elf_gp (output_bfd
);
5483 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5484 sym_hashes
= elf_sym_hashes (input_bfd
);
5485 is_opd
= elf_section_data (input_section
)->tdata
!= NULL
;
5488 relend
= relocs
+ input_section
->reloc_count
;
5489 for (; rel
< relend
; rel
++)
5491 enum elf_ppc_reloc_type r_type
;
5494 bfd_reloc_status_type r
;
5495 Elf_Internal_Sym
*sym
;
5497 struct elf_link_hash_entry
*h
;
5498 struct elf_link_hash_entry
*fdh
;
5499 const char *sym_name
;
5500 unsigned long r_symndx
;
5502 boolean unresolved_reloc
;
5505 struct ppc_stub_hash_entry
*stub_entry
;
5506 bfd_vma max_br_offset
;
5509 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5510 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5511 offset
= rel
->r_offset
;
5512 addend
= rel
->r_addend
;
5513 r
= bfd_reloc_other
;
5514 sym
= (Elf_Internal_Sym
*) 0;
5515 sec
= (asection
*) 0;
5516 h
= (struct elf_link_hash_entry
*) 0;
5517 sym_name
= (const char *) 0;
5518 unresolved_reloc
= false;
5521 if (r_type
== R_PPC64_TOC
)
5523 /* Relocation value is TOC base. Symbol is ignored. */
5524 relocation
= TOCstart
+ TOC_BASE_OFF
;
5526 else if (r_symndx
< symtab_hdr
->sh_info
)
5528 /* It's a local symbol. */
5529 sym
= local_syms
+ r_symndx
;
5530 sec
= local_sections
[r_symndx
];
5531 sym_name
= "<local symbol>";
5533 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
5534 /* rel may have changed, update our copy of addend. */
5535 addend
= rel
->r_addend
;
5537 if (elf_section_data (sec
) != NULL
)
5539 long *opd_sym_adjust
;
5541 opd_sym_adjust
= (long *) elf_section_data (sec
)->tdata
;
5542 if (opd_sym_adjust
!= NULL
&& sym
->st_value
% 24 == 0)
5543 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
5548 /* It's a global symbol. */
5549 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5550 while (h
->root
.type
== bfd_link_hash_indirect
5551 || h
->root
.type
== bfd_link_hash_warning
)
5552 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5553 sym_name
= h
->root
.root
.string
;
5555 if (h
->root
.type
== bfd_link_hash_defined
5556 || h
->root
.type
== bfd_link_hash_defweak
)
5558 sec
= h
->root
.u
.def
.section
;
5559 if (sec
->output_section
== NULL
)
5560 /* Set a flag that will be cleared later if we find a
5561 relocation value for this symbol. output_section
5562 is typically NULL for symbols satisfied by a shared
5564 unresolved_reloc
= true;
5566 relocation
= (h
->root
.u
.def
.value
5567 + sec
->output_section
->vma
5568 + sec
->output_offset
);
5570 else if (h
->root
.type
== bfd_link_hash_undefweak
)
5572 else if (info
->shared
5573 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
5574 && !info
->no_undefined
5575 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5579 if (! ((*info
->callbacks
->undefined_symbol
)
5580 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5581 offset
, (!info
->shared
5582 || info
->no_undefined
5583 || ELF_ST_VISIBILITY (h
->other
)))))
5589 /* First handle relocations that tweak non-addend part of insn. */
5596 /* Branch taken prediction relocations. */
5597 case R_PPC64_ADDR14_BRTAKEN
:
5598 case R_PPC64_REL14_BRTAKEN
:
5599 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5602 /* Branch not taken prediction relocations. */
5603 case R_PPC64_ADDR14_BRNTAKEN
:
5604 case R_PPC64_REL14_BRNTAKEN
:
5605 insn
|= bfd_get_32 (output_bfd
, contents
+ offset
) & ~(0x01 << 21);
5608 /* Set 'a' bit. This is 0b00010 in BO field for branch
5609 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5610 for branch on CTR insns (BO == 1a00t or 1a01t). */
5611 if ((insn
& (0x14 << 21)) == (0x04 << 21))
5613 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
5621 + input_section
->output_offset
5622 + input_section
->output_section
->vma
);
5624 /* Invert 'y' bit if not the default. */
5625 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
5629 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
5633 /* A REL24 branching to a linkage function is followed by a
5634 nop. We replace the nop with a ld in order to restore
5635 the TOC base pointer. Only calls to shared objects need
5636 to alter the TOC base. These are recognized by their
5637 need for a PLT entry. */
5639 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
5640 && fdh
->plt
.offset
!= (bfd_vma
) -1
5641 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
5642 rel
, htab
)) != NULL
)
5644 boolean can_plt_call
= 0;
5646 if (offset
+ 8 <= input_section
->_cooked_size
)
5648 insn
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
5650 || insn
== CROR_151515
|| insn
== CROR_313131
)
5652 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
5653 contents
+ offset
+ 4);
5660 /* If this is a plain branch rather than a branch
5661 and link, don't require a nop. */
5662 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
5663 if ((insn
& 1) == 0)
5669 relocation
= (stub_entry
->stub_offset
5670 + stub_entry
->stub_sec
->output_offset
5671 + stub_entry
->stub_sec
->output_section
->vma
);
5673 unresolved_reloc
= false;
5678 && h
->root
.type
== bfd_link_hash_undefweak
5682 /* Tweak calls to undefined weak functions to point at a
5683 blr. We can thus call a weak function without first
5684 checking whether the function is defined. We have a
5685 blr at the end of .sfpr. */
5686 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
5687 relocation
= (htab
->sfpr
->_raw_size
- 4
5688 + htab
->sfpr
->output_offset
5689 + htab
->sfpr
->output_section
->vma
);
5691 + input_section
->output_offset
5692 + input_section
->output_section
->vma
);
5694 /* But let's not be silly about it. If the blr isn't in
5695 reach, just go to the next instruction. */
5696 if (relocation
- from
+ (1 << 25) >= (1 << 26)
5697 || htab
->sfpr
->_raw_size
== 0)
5698 relocation
= from
+ 4;
5707 (*_bfd_error_handler
)
5708 (_("%s: unknown relocation type %d for symbol %s"),
5709 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5711 bfd_set_error (bfd_error_bad_value
);
5716 case R_PPC_GNU_VTINHERIT
:
5717 case R_PPC_GNU_VTENTRY
:
5720 /* GOT16 relocations. Like an ADDR16 using the symbol's
5721 address in the GOT as relocation value instead of the
5722 symbols value itself. Also, create a GOT entry for the
5723 symbol and put the symbol value there. */
5725 case R_PPC64_GOT16_LO
:
5726 case R_PPC64_GOT16_HI
:
5727 case R_PPC64_GOT16_HA
:
5728 case R_PPC64_GOT16_DS
:
5729 case R_PPC64_GOT16_LO_DS
:
5731 /* Relocation is to the entry for this symbol in the global
5735 if (htab
->sgot
== NULL
)
5742 off
= h
->got
.offset
;
5743 dyn
= htab
->elf
.dynamic_sections_created
;
5744 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
5748 || (h
->elf_link_hash_flags
5749 & ELF_LINK_FORCED_LOCAL
))
5750 && (h
->elf_link_hash_flags
5751 & ELF_LINK_HASH_DEF_REGULAR
)))
5753 /* This is actually a static link, or it is a
5754 -Bsymbolic link and the symbol is defined
5755 locally, or the symbol was forced to be local
5756 because of a version file. We must initialize
5757 this entry in the global offset table. Since the
5758 offset must always be a multiple of 8, we use the
5759 least significant bit to record whether we have
5760 initialized it already.
5762 When doing a dynamic link, we create a .rel.got
5763 relocation entry to initialize the value. This
5764 is done in the finish_dynamic_symbol routine. */
5769 bfd_put_64 (output_bfd
, relocation
,
5770 htab
->sgot
->contents
+ off
);
5775 unresolved_reloc
= false;
5779 if (local_got_offsets
== NULL
)
5782 off
= local_got_offsets
[r_symndx
];
5784 /* The offset must always be a multiple of 8. We use
5785 the least significant bit to record whether we have
5786 already processed this entry. */
5791 bfd_put_64 (output_bfd
, relocation
,
5792 htab
->sgot
->contents
+ off
);
5796 Elf_Internal_Rela outrel
;
5797 Elf64_External_Rela
*loc
;
5799 /* We need to generate a R_PPC64_RELATIVE reloc
5800 for the dynamic linker. */
5801 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
5802 + htab
->sgot
->output_offset
5804 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
5805 outrel
.r_addend
= relocation
;
5806 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
5807 loc
+= htab
->srelgot
->reloc_count
++;
5808 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
5811 local_got_offsets
[r_symndx
] |= 1;
5815 if (off
>= (bfd_vma
) -2)
5818 relocation
= htab
->sgot
->output_offset
+ off
;
5820 /* TOC base (r2) is TOC start plus 0x8000. */
5821 addend
-= TOC_BASE_OFF
;
5825 case R_PPC64_PLT16_HA
:
5826 case R_PPC64_PLT16_HI
:
5827 case R_PPC64_PLT16_LO
:
5830 /* Relocation is to the entry for this symbol in the
5831 procedure linkage table. */
5833 /* Resolve a PLT reloc against a local symbol directly,
5834 without using the procedure linkage table. */
5838 if (h
->plt
.offset
== (bfd_vma
) -1
5839 || htab
->splt
== NULL
)
5841 /* We didn't make a PLT entry for this symbol. This
5842 happens when statically linking PIC code, or when
5843 using -Bsymbolic. */
5847 relocation
= (htab
->splt
->output_section
->vma
5848 + htab
->splt
->output_offset
5850 unresolved_reloc
= false;
5853 /* TOC16 relocs. We want the offset relative to the TOC base,
5854 which is the address of the start of the TOC plus 0x8000.
5855 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5858 case R_PPC64_TOC16_LO
:
5859 case R_PPC64_TOC16_HI
:
5860 case R_PPC64_TOC16_DS
:
5861 case R_PPC64_TOC16_LO_DS
:
5862 case R_PPC64_TOC16_HA
:
5863 addend
-= TOCstart
+ TOC_BASE_OFF
;
5866 /* Relocate against the beginning of the section. */
5867 case R_PPC64_SECTOFF
:
5868 case R_PPC64_SECTOFF_LO
:
5869 case R_PPC64_SECTOFF_HI
:
5870 case R_PPC64_SECTOFF_DS
:
5871 case R_PPC64_SECTOFF_LO_DS
:
5872 case R_PPC64_SECTOFF_HA
:
5873 if (sec
!= (asection
*) 0)
5874 addend
-= sec
->output_section
->vma
;
5878 case R_PPC64_REL14_BRNTAKEN
:
5879 case R_PPC64_REL14_BRTAKEN
:
5883 /* Relocations that may need to be propagated if this is a
5887 case R_PPC64_ADDR14
:
5888 case R_PPC64_ADDR14_BRNTAKEN
:
5889 case R_PPC64_ADDR14_BRTAKEN
:
5890 case R_PPC64_ADDR16
:
5891 case R_PPC64_ADDR16_DS
:
5892 case R_PPC64_ADDR16_HA
:
5893 case R_PPC64_ADDR16_HI
:
5894 case R_PPC64_ADDR16_HIGHER
:
5895 case R_PPC64_ADDR16_HIGHERA
:
5896 case R_PPC64_ADDR16_HIGHEST
:
5897 case R_PPC64_ADDR16_HIGHESTA
:
5898 case R_PPC64_ADDR16_LO
:
5899 case R_PPC64_ADDR16_LO_DS
:
5900 case R_PPC64_ADDR24
:
5901 case R_PPC64_ADDR30
:
5902 case R_PPC64_ADDR32
:
5903 case R_PPC64_ADDR64
:
5904 case R_PPC64_UADDR16
:
5905 case R_PPC64_UADDR32
:
5906 case R_PPC64_UADDR64
:
5907 /* r_symndx will be zero only for relocs against symbols
5908 from removed linkonce sections, or sections discarded by
5915 if ((input_section
->flags
& SEC_ALLOC
) == 0)
5918 if (NO_OPD_RELOCS
&& is_opd
)
5922 && (IS_ABSOLUTE_RELOC (r_type
)
5925 && (! info
->symbolic
5926 || (h
->elf_link_hash_flags
5927 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5931 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5932 && (((h
->elf_link_hash_flags
5933 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5934 && (h
->elf_link_hash_flags
5935 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
5936 || h
->root
.type
== bfd_link_hash_undefweak
5937 || h
->root
.type
== bfd_link_hash_undefined
)))
5939 Elf_Internal_Rela outrel
;
5940 boolean skip
, relocate
;
5942 Elf64_External_Rela
*loc
;
5944 /* When generating a dynamic object, these relocations
5945 are copied into the output file to be resolved at run
5952 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5954 if (outrel
.r_offset
== (bfd_vma
) -1)
5956 else if (outrel
.r_offset
== (bfd_vma
) -2)
5957 skip
= true, relocate
= true;
5958 outrel
.r_offset
+= (input_section
->output_section
->vma
5959 + input_section
->output_offset
);
5960 outrel
.r_addend
= addend
;
5963 memset (&outrel
, 0, sizeof outrel
);
5967 && (!IS_ABSOLUTE_RELOC (r_type
)
5970 || (h
->elf_link_hash_flags
5971 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
5972 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
5975 /* This symbol is local, or marked to become local,
5976 or this is an opd section reloc which must point
5977 at a local function. */
5978 outrel
.r_addend
+= relocation
;
5980 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5982 if (is_opd
&& h
!= NULL
)
5984 /* Lie about opd entries. This case occurs
5985 when building shared libraries and we
5986 reference a function in another shared
5987 lib. The same thing happens for a weak
5988 definition in an application that's
5989 overridden by a strong definition in a
5990 shared lib. (I believe this is a generic
5991 bug in binutils handling of weak syms.)
5992 In these cases we won't use the opd
5993 entry in this lib. */
5994 unresolved_reloc
= false;
5996 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6002 if (bfd_is_abs_section (sec
))
6004 else if (sec
== NULL
|| sec
->owner
== NULL
)
6006 bfd_set_error (bfd_error_bad_value
);
6013 osec
= sec
->output_section
;
6014 indx
= elf_section_data (osec
)->dynindx
;
6016 /* We are turning this relocation into one
6017 against a section symbol, so subtract out
6018 the output section's address but not the
6019 offset of the input section in the output
6021 outrel
.r_addend
-= osec
->vma
;
6024 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
6028 sreloc
= elf_section_data (input_section
)->sreloc
;
6032 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
6033 loc
+= sreloc
->reloc_count
++;
6034 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
6036 /* If this reloc is against an external symbol, it will
6037 be computed at runtime, so there's no need to do
6045 case R_PPC64_GLOB_DAT
:
6046 case R_PPC64_JMP_SLOT
:
6047 case R_PPC64_RELATIVE
:
6048 /* We shouldn't ever see these dynamic relocs in relocatable
6052 case R_PPC64_PLTGOT16
:
6053 case R_PPC64_PLTGOT16_DS
:
6054 case R_PPC64_PLTGOT16_HA
:
6055 case R_PPC64_PLTGOT16_HI
:
6056 case R_PPC64_PLTGOT16_LO
:
6057 case R_PPC64_PLTGOT16_LO_DS
:
6058 case R_PPC64_PLTREL32
:
6059 case R_PPC64_PLTREL64
:
6060 /* These ones haven't been implemented yet. */
6062 (*_bfd_error_handler
)
6063 (_("%s: Relocation %s is not supported for symbol %s."),
6064 bfd_archive_filename (input_bfd
),
6065 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
6067 bfd_set_error (bfd_error_invalid_operation
);
6072 /* Do any further special processing. */
6078 case R_PPC64_ADDR16_HA
:
6079 case R_PPC64_ADDR16_HIGHERA
:
6080 case R_PPC64_ADDR16_HIGHESTA
:
6081 case R_PPC64_PLT16_HA
:
6082 case R_PPC64_TOC16_HA
:
6083 case R_PPC64_SECTOFF_HA
:
6084 /* It's just possible that this symbol is a weak symbol
6085 that's not actually defined anywhere. In that case,
6086 'sec' would be NULL, and we should leave the symbol
6087 alone (it will be set to zero elsewhere in the link). */
6089 /* Add 0x10000 if sign bit in 0:15 is set. */
6090 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
6093 case R_PPC64_ADDR16_DS
:
6094 case R_PPC64_ADDR16_LO_DS
:
6095 case R_PPC64_GOT16_DS
:
6096 case R_PPC64_GOT16_LO_DS
:
6097 case R_PPC64_PLT16_LO_DS
:
6098 case R_PPC64_SECTOFF_DS
:
6099 case R_PPC64_SECTOFF_LO_DS
:
6100 case R_PPC64_TOC16_DS
:
6101 case R_PPC64_TOC16_LO_DS
:
6102 case R_PPC64_PLTGOT16_DS
:
6103 case R_PPC64_PLTGOT16_LO_DS
:
6104 if (((relocation
+ addend
) & 3) != 0)
6106 (*_bfd_error_handler
)
6107 (_("%s: error: relocation %s not a multiple of 4"),
6108 bfd_archive_filename (input_bfd
),
6109 ppc64_elf_howto_table
[(int) r_type
]->name
);
6110 bfd_set_error (bfd_error_bad_value
);
6117 case R_PPC64_REL14_BRNTAKEN
:
6118 case R_PPC64_REL14_BRTAKEN
:
6119 max_br_offset
= 1 << 15;
6123 max_br_offset
= 1 << 25;
6126 /* If the branch is out of reach, then redirect the
6127 call to the local stub for this function. */
6129 + input_section
->output_offset
6130 + input_section
->output_section
->vma
);
6131 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
6132 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
6133 rel
, htab
)) != NULL
)
6135 /* Munge up the value and addend so that we call the stub
6136 rather than the procedure directly. */
6137 relocation
= (stub_entry
->stub_offset
6138 + stub_entry
->stub_sec
->output_offset
6139 + stub_entry
->stub_sec
->output_section
->vma
);
6145 /* FIXME: Why do we allow debugging sections to escape this error?
6146 More importantly, why do we not emit dynamic relocs above in
6147 debugging sections (which are ! SEC_ALLOC)? If we had
6148 emitted the dynamic reloc, we could remove the fudge here. */
6149 if (unresolved_reloc
6151 && (input_section
->flags
& SEC_DEBUGGING
) != 0
6152 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
6154 (*_bfd_error_handler
)
6155 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
6156 bfd_archive_filename (input_bfd
),
6157 bfd_get_section_name (input_bfd
, input_section
),
6158 (long) rel
->r_offset
,
6159 h
->root
.root
.string
);
6163 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
6171 if (r
!= bfd_reloc_ok
)
6177 if (h
->root
.type
== bfd_link_hash_undefweak
6178 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
6180 /* Assume this is a call protected by other code that
6181 detects the symbol is undefined. If this is the case,
6182 we can safely ignore the overflow. If not, the
6183 program is hosed anyway, and a little warning isn't
6189 name
= h
->root
.root
.string
;
6193 name
= bfd_elf_string_from_elf_section (input_bfd
,
6194 symtab_hdr
->sh_link
,
6199 name
= bfd_section_name (input_bfd
, sec
);
6202 if (r
== bfd_reloc_overflow
)
6206 if (!((*info
->callbacks
->reloc_overflow
)
6207 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
6208 rel
->r_addend
, input_bfd
, input_section
, offset
)))
6213 (*_bfd_error_handler
)
6214 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
6215 bfd_archive_filename (input_bfd
),
6216 bfd_get_section_name (input_bfd
, input_section
),
6217 (long) rel
->r_offset
, name
, (int) r
);
6226 /* Finish up dynamic symbol handling. We set the contents of various
6227 dynamic sections here. */
6230 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
6232 struct bfd_link_info
*info
;
6233 struct elf_link_hash_entry
*h
;
6234 Elf_Internal_Sym
*sym
;
6236 struct ppc_link_hash_table
*htab
;
6239 htab
= ppc_hash_table (info
);
6240 dynobj
= htab
->elf
.dynobj
;
6242 if (h
->plt
.offset
!= (bfd_vma
) -1
6243 && ((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
6245 Elf_Internal_Rela rela
;
6246 Elf64_External_Rela
*loc
;
6248 /* This symbol has an entry in the procedure linkage table. Set
6251 if (htab
->splt
== NULL
6252 || htab
->srelplt
== NULL
6253 || htab
->sglink
== NULL
)
6256 /* Create a JMP_SLOT reloc to inform the dynamic linker to
6257 fill in the PLT entry. */
6259 rela
.r_offset
= (htab
->splt
->output_section
->vma
6260 + htab
->splt
->output_offset
6262 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
6265 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
6266 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
6267 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6270 if (h
->got
.offset
!= (bfd_vma
) -1)
6272 Elf_Internal_Rela rela
;
6273 Elf64_External_Rela
*loc
;
6275 /* This symbol has an entry in the global offset table. Set it
6278 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
6281 rela
.r_offset
= (htab
->sgot
->output_section
->vma
6282 + htab
->sgot
->output_offset
6283 + (h
->got
.offset
&~ (bfd_vma
) 1));
6285 /* If this is a static link, or it is a -Bsymbolic link and the
6286 symbol is defined locally or was forced to be local because
6287 of a version file, we just want to emit a RELATIVE reloc.
6288 The entry in the global offset table will already have been
6289 initialized in the relocate_section function. */
6293 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
6294 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
6296 BFD_ASSERT((h
->got
.offset
& 1) != 0);
6297 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6298 rela
.r_addend
= (h
->root
.u
.def
.value
6299 + h
->root
.u
.def
.section
->output_section
->vma
6300 + h
->root
.u
.def
.section
->output_offset
);
6304 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
6305 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
6306 htab
->sgot
->contents
+ h
->got
.offset
);
6307 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
6311 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
6312 loc
+= htab
->srelgot
->reloc_count
++;
6313 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6316 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
6318 Elf_Internal_Rela rela
;
6319 Elf64_External_Rela
*loc
;
6321 /* This symbol needs a copy reloc. Set it up. */
6323 if (h
->dynindx
== -1
6324 || (h
->root
.type
!= bfd_link_hash_defined
6325 && h
->root
.type
!= bfd_link_hash_defweak
)
6326 || htab
->srelbss
== NULL
)
6329 rela
.r_offset
= (h
->root
.u
.def
.value
6330 + h
->root
.u
.def
.section
->output_section
->vma
6331 + h
->root
.u
.def
.section
->output_offset
);
6332 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
6334 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
6335 loc
+= htab
->srelbss
->reloc_count
++;
6336 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
6339 /* Mark some specially defined symbols as absolute. */
6340 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
6341 sym
->st_shndx
= SHN_ABS
;
6346 /* Used to decide how to sort relocs in an optimal manner for the
6347 dynamic linker, before writing them out. */
6349 static enum elf_reloc_type_class
6350 ppc64_elf_reloc_type_class (rela
)
6351 const Elf_Internal_Rela
*rela
;
6353 enum elf_ppc_reloc_type r_type
;
6355 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
6358 case R_PPC64_RELATIVE
:
6359 return reloc_class_relative
;
6360 case R_PPC64_JMP_SLOT
:
6361 return reloc_class_plt
;
6363 return reloc_class_copy
;
6365 return reloc_class_normal
;
6369 /* Finish up the dynamic sections. */
6372 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
6374 struct bfd_link_info
*info
;
6376 struct ppc_link_hash_table
*htab
;
6380 htab
= ppc_hash_table (info
);
6381 dynobj
= htab
->elf
.dynobj
;
6382 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
6384 if (htab
->elf
.dynamic_sections_created
)
6386 Elf64_External_Dyn
*dyncon
, *dynconend
;
6388 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
6391 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
6392 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
6393 for (; dyncon
< dynconend
; dyncon
++)
6395 Elf_Internal_Dyn dyn
;
6398 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
6405 case DT_PPC64_GLINK
:
6406 dyn
.d_un
.d_ptr
= (htab
->sglink
->output_section
->vma
6407 + htab
->sglink
->output_offset
);
6411 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6413 dyn
.d_un
.d_ptr
= s
->vma
;
6416 case DT_PPC64_OPDSZ
:
6417 s
= bfd_get_section_by_name (output_bfd
, ".opd");
6419 dyn
.d_un
.d_val
= s
->_raw_size
;
6423 dyn
.d_un
.d_ptr
= (htab
->splt
->output_section
->vma
6424 + htab
->splt
->output_offset
);
6428 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
6429 + htab
->srelplt
->output_offset
);
6433 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
6437 /* Don't count procedure linkage table relocs in the
6438 overall reloc count. */
6439 if (htab
->srelplt
!= NULL
)
6440 dyn
.d_un
.d_val
-= htab
->srelplt
->_raw_size
;
6444 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
6448 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
6450 /* Fill in the first entry in the global offset table.
6451 We use it to hold the link-time TOCbase. */
6452 bfd_put_64 (output_bfd
,
6453 elf_gp (output_bfd
) + TOC_BASE_OFF
,
6454 htab
->sgot
->contents
);
6456 /* Set .got entry size. */
6457 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
6460 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
6462 /* Set .plt entry size. */
6463 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
6470 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6471 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6472 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6473 #define TARGET_BIG_NAME "elf64-powerpc"
6474 #define ELF_ARCH bfd_arch_powerpc
6475 #define ELF_MACHINE_CODE EM_PPC64
6476 #define ELF_MAXPAGESIZE 0x10000
6477 #define elf_info_to_howto ppc64_elf_info_to_howto
6479 #ifdef EM_CYGNUS_POWERPC
6480 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6484 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6487 #define elf_backend_want_got_sym 0
6488 #define elf_backend_want_plt_sym 0
6489 #define elf_backend_plt_alignment 3
6490 #define elf_backend_plt_not_loaded 1
6491 #define elf_backend_got_symbol_offset 0
6492 #define elf_backend_got_header_size 8
6493 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6494 #define elf_backend_can_gc_sections 1
6495 #define elf_backend_can_refcount 1
6496 #define elf_backend_rela_normal 1
6498 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6499 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
6500 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6501 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6502 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6503 #define bfd_elf64_get_symbol_info ppc64_elf_get_symbol_info
6505 #define elf_backend_object_p ppc64_elf_object_p
6506 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
6507 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6508 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6509 #define elf_backend_check_relocs ppc64_elf_check_relocs
6510 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6511 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6512 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6513 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6514 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6515 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6516 #define elf_backend_fake_sections ppc64_elf_fake_sections
6517 #define elf_backend_relocate_section ppc64_elf_relocate_section
6518 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6519 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6520 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6522 #include "elf64-target.h"