1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003 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. */
30 #include "elf/ppc64.h"
31 #include "elf64-ppc.h"
33 static void ppc_howto_init
35 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
36 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
37 static void ppc64_elf_info_to_howto
38 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
));
39 static bfd_reloc_status_type ppc64_elf_ha_reloc
40 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
41 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
42 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
43 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
44 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
45 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
46 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
47 static bfd_reloc_status_type ppc64_elf_toc_reloc
48 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
49 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
50 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
51 static bfd_reloc_status_type ppc64_elf_toc64_reloc
52 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
53 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
54 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
55 static bfd_boolean ppc64_elf_object_p
57 static bfd_boolean ppc64_elf_merge_private_bfd_data
58 PARAMS ((bfd
*, bfd
*));
59 static bfd_boolean ppc64_elf_new_section_hook
60 PARAMS ((bfd
*, asection
*));
63 /* The name of the dynamic interpreter. This is put in the .interp
65 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
67 /* The size in bytes of an entry in the procedure linkage table. */
68 #define PLT_ENTRY_SIZE 24
70 /* The initial size of the plt reserved for the dynamic linker. */
71 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
73 /* TOC base pointers offset from start of TOC. */
74 #define TOC_BASE_OFF 0x8000
76 /* Offset of tp and dtp pointers from start of TLS block. */
77 #define TP_OFFSET 0x7000
78 #define DTP_OFFSET 0x8000
80 /* .plt call stub instructions. */
81 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
82 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
83 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
84 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
85 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
86 /* ld %r11,xxx+16@l(%r12) */
87 #define BCTR 0x4e800420 /* bctr */
89 /* The normal stub is this size. */
90 #define PLT_CALL_STUB_SIZE (7*4)
92 /* But sometimes the .plt entry crosses a 64k boundary, and we need
93 to adjust the high word with this insn. */
94 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
96 /* The .glink fixup call stub is the same as the .plt call stub, but
97 the first instruction restores r2, and the std is omitted. */
98 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
100 /* Always allow this much space. */
101 #define GLINK_CALL_STUB_SIZE (8*4)
104 #define NOP 0x60000000
106 /* Some other nops. */
107 #define CROR_151515 0x4def7b82
108 #define CROR_313131 0x4ffffb82
110 /* .glink entries for the first 32k functions are two instructions. */
111 #define LI_R0_0 0x38000000 /* li %r0,0 */
112 #define B_DOT 0x48000000 /* b . */
114 /* After that, we need two instructions to load the index, followed by
116 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
117 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
119 /* Instructions to save and restore floating point regs. */
120 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
121 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
122 #define BLR 0x4e800020 /* blr */
124 /* Since .opd is an array of descriptors and each entry will end up
125 with identical R_PPC64_RELATIVE relocs, there is really no need to
126 propagate .opd relocs; The dynamic linker should be taught to
127 relocate .opd without reloc entries. */
128 #ifndef NO_OPD_RELOCS
129 #define NO_OPD_RELOCS 0
132 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
134 /* Relocation HOWTO's. */
135 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
137 static reloc_howto_type ppc64_elf_howto_raw
[] = {
138 /* This reloc does nothing. */
139 HOWTO (R_PPC64_NONE
, /* type */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
143 FALSE
, /* pc_relative */
145 complain_overflow_dont
, /* complain_on_overflow */
146 bfd_elf_generic_reloc
, /* special_function */
147 "R_PPC64_NONE", /* name */
148 FALSE
, /* partial_inplace */
151 FALSE
), /* pcrel_offset */
153 /* A standard 32 bit relocation. */
154 HOWTO (R_PPC64_ADDR32
, /* type */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
158 FALSE
, /* pc_relative */
160 complain_overflow_bitfield
, /* complain_on_overflow */
161 bfd_elf_generic_reloc
, /* special_function */
162 "R_PPC64_ADDR32", /* name */
163 FALSE
, /* partial_inplace */
165 0xffffffff, /* dst_mask */
166 FALSE
), /* pcrel_offset */
168 /* An absolute 26 bit branch; the lower two bits must be zero.
169 FIXME: we don't check that, we just clear them. */
170 HOWTO (R_PPC64_ADDR24
, /* type */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
174 FALSE
, /* pc_relative */
176 complain_overflow_bitfield
, /* complain_on_overflow */
177 bfd_elf_generic_reloc
, /* special_function */
178 "R_PPC64_ADDR24", /* name */
179 FALSE
, /* partial_inplace */
181 0x03fffffc, /* dst_mask */
182 FALSE
), /* pcrel_offset */
184 /* A standard 16 bit relocation. */
185 HOWTO (R_PPC64_ADDR16
, /* type */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
189 FALSE
, /* pc_relative */
191 complain_overflow_bitfield
, /* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_PPC64_ADDR16", /* name */
194 FALSE
, /* partial_inplace */
196 0xffff, /* dst_mask */
197 FALSE
), /* pcrel_offset */
199 /* A 16 bit relocation without overflow. */
200 HOWTO (R_PPC64_ADDR16_LO
, /* type */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
204 FALSE
, /* pc_relative */
206 complain_overflow_dont
,/* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_PPC64_ADDR16_LO", /* name */
209 FALSE
, /* partial_inplace */
211 0xffff, /* dst_mask */
212 FALSE
), /* pcrel_offset */
214 /* Bits 16-31 of an address. */
215 HOWTO (R_PPC64_ADDR16_HI
, /* type */
217 1, /* size (0 = byte, 1 = short, 2 = long) */
219 FALSE
, /* pc_relative */
221 complain_overflow_dont
, /* complain_on_overflow */
222 bfd_elf_generic_reloc
, /* special_function */
223 "R_PPC64_ADDR16_HI", /* name */
224 FALSE
, /* partial_inplace */
226 0xffff, /* dst_mask */
227 FALSE
), /* pcrel_offset */
229 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
230 bits, treated as a signed number, is negative. */
231 HOWTO (R_PPC64_ADDR16_HA
, /* type */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
235 FALSE
, /* pc_relative */
237 complain_overflow_dont
, /* complain_on_overflow */
238 ppc64_elf_ha_reloc
, /* special_function */
239 "R_PPC64_ADDR16_HA", /* name */
240 FALSE
, /* partial_inplace */
242 0xffff, /* dst_mask */
243 FALSE
), /* pcrel_offset */
245 /* An absolute 16 bit branch; the lower two bits must be zero.
246 FIXME: we don't check that, we just clear them. */
247 HOWTO (R_PPC64_ADDR14
, /* type */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
251 FALSE
, /* pc_relative */
253 complain_overflow_bitfield
, /* complain_on_overflow */
254 bfd_elf_generic_reloc
, /* special_function */
255 "R_PPC64_ADDR14", /* name */
256 FALSE
, /* partial_inplace */
258 0x0000fffc, /* dst_mask */
259 FALSE
), /* pcrel_offset */
261 /* An absolute 16 bit branch, for which bit 10 should be set to
262 indicate that the branch is expected to be taken. The lower two
263 bits must be zero. */
264 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
266 2, /* size (0 = byte, 1 = short, 2 = long) */
268 FALSE
, /* pc_relative */
270 complain_overflow_bitfield
, /* complain_on_overflow */
271 ppc64_elf_brtaken_reloc
, /* special_function */
272 "R_PPC64_ADDR14_BRTAKEN",/* name */
273 FALSE
, /* partial_inplace */
275 0x0000fffc, /* dst_mask */
276 FALSE
), /* pcrel_offset */
278 /* An absolute 16 bit branch, for which bit 10 should be set to
279 indicate that the branch is not expected to be taken. The lower
280 two bits must be zero. */
281 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
285 FALSE
, /* pc_relative */
287 complain_overflow_bitfield
, /* complain_on_overflow */
288 ppc64_elf_brtaken_reloc
, /* special_function */
289 "R_PPC64_ADDR14_BRNTAKEN",/* name */
290 FALSE
, /* partial_inplace */
292 0x0000fffc, /* dst_mask */
293 FALSE
), /* pcrel_offset */
295 /* A relative 26 bit branch; the lower two bits must be zero. */
296 HOWTO (R_PPC64_REL24
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 TRUE
, /* pc_relative */
302 complain_overflow_signed
, /* complain_on_overflow */
303 bfd_elf_generic_reloc
, /* special_function */
304 "R_PPC64_REL24", /* name */
305 FALSE
, /* partial_inplace */
307 0x03fffffc, /* dst_mask */
308 TRUE
), /* pcrel_offset */
310 /* A relative 16 bit branch; the lower two bits must be zero. */
311 HOWTO (R_PPC64_REL14
, /* type */
313 2, /* size (0 = byte, 1 = short, 2 = long) */
315 TRUE
, /* pc_relative */
317 complain_overflow_signed
, /* complain_on_overflow */
318 bfd_elf_generic_reloc
, /* special_function */
319 "R_PPC64_REL14", /* name */
320 FALSE
, /* partial_inplace */
322 0x0000fffc, /* dst_mask */
323 TRUE
), /* pcrel_offset */
325 /* A relative 16 bit branch. Bit 10 should be set to indicate that
326 the branch is expected to be taken. The lower two bits must be
328 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 TRUE
, /* pc_relative */
334 complain_overflow_signed
, /* complain_on_overflow */
335 ppc64_elf_brtaken_reloc
, /* special_function */
336 "R_PPC64_REL14_BRTAKEN", /* name */
337 FALSE
, /* partial_inplace */
339 0x0000fffc, /* dst_mask */
340 TRUE
), /* pcrel_offset */
342 /* A relative 16 bit branch. Bit 10 should be set to indicate that
343 the branch is not expected to be taken. The lower two bits must
345 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
349 TRUE
, /* pc_relative */
351 complain_overflow_signed
, /* complain_on_overflow */
352 ppc64_elf_brtaken_reloc
, /* special_function */
353 "R_PPC64_REL14_BRNTAKEN",/* name */
354 FALSE
, /* partial_inplace */
356 0x0000fffc, /* dst_mask */
357 TRUE
), /* pcrel_offset */
359 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
361 HOWTO (R_PPC64_GOT16
, /* type */
363 1, /* size (0 = byte, 1 = short, 2 = long) */
365 FALSE
, /* pc_relative */
367 complain_overflow_signed
, /* complain_on_overflow */
368 ppc64_elf_unhandled_reloc
, /* special_function */
369 "R_PPC64_GOT16", /* name */
370 FALSE
, /* partial_inplace */
372 0xffff, /* dst_mask */
373 FALSE
), /* pcrel_offset */
375 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
377 HOWTO (R_PPC64_GOT16_LO
, /* type */
379 1, /* size (0 = byte, 1 = short, 2 = long) */
381 FALSE
, /* pc_relative */
383 complain_overflow_dont
, /* complain_on_overflow */
384 ppc64_elf_unhandled_reloc
, /* special_function */
385 "R_PPC64_GOT16_LO", /* name */
386 FALSE
, /* partial_inplace */
388 0xffff, /* dst_mask */
389 FALSE
), /* pcrel_offset */
391 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
393 HOWTO (R_PPC64_GOT16_HI
, /* type */
395 1, /* size (0 = byte, 1 = short, 2 = long) */
397 FALSE
, /* pc_relative */
399 complain_overflow_dont
,/* complain_on_overflow */
400 ppc64_elf_unhandled_reloc
, /* special_function */
401 "R_PPC64_GOT16_HI", /* name */
402 FALSE
, /* partial_inplace */
404 0xffff, /* dst_mask */
405 FALSE
), /* pcrel_offset */
407 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
409 HOWTO (R_PPC64_GOT16_HA
, /* type */
411 1, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_dont
,/* complain_on_overflow */
416 ppc64_elf_unhandled_reloc
, /* special_function */
417 "R_PPC64_GOT16_HA", /* name */
418 FALSE
, /* partial_inplace */
420 0xffff, /* dst_mask */
421 FALSE
), /* pcrel_offset */
423 /* This is used only by the dynamic linker. The symbol should exist
424 both in the object being run and in some shared library. The
425 dynamic linker copies the data addressed by the symbol from the
426 shared library into the object, because the object being
427 run has to have the data at some particular address. */
428 HOWTO (R_PPC64_COPY
, /* type */
430 0, /* this one is variable size */
432 FALSE
, /* pc_relative */
434 complain_overflow_dont
, /* complain_on_overflow */
435 ppc64_elf_unhandled_reloc
, /* special_function */
436 "R_PPC64_COPY", /* name */
437 FALSE
, /* partial_inplace */
440 FALSE
), /* pcrel_offset */
442 /* Like R_PPC64_ADDR64, but used when setting global offset table
444 HOWTO (R_PPC64_GLOB_DAT
, /* type */
446 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
448 FALSE
, /* pc_relative */
450 complain_overflow_dont
, /* complain_on_overflow */
451 ppc64_elf_unhandled_reloc
, /* special_function */
452 "R_PPC64_GLOB_DAT", /* name */
453 FALSE
, /* partial_inplace */
455 ONES (64), /* dst_mask */
456 FALSE
), /* pcrel_offset */
458 /* Created by the link editor. Marks a procedure linkage table
459 entry for a symbol. */
460 HOWTO (R_PPC64_JMP_SLOT
, /* type */
462 0, /* size (0 = byte, 1 = short, 2 = long) */
464 FALSE
, /* pc_relative */
466 complain_overflow_dont
, /* complain_on_overflow */
467 ppc64_elf_unhandled_reloc
, /* special_function */
468 "R_PPC64_JMP_SLOT", /* name */
469 FALSE
, /* partial_inplace */
472 FALSE
), /* pcrel_offset */
474 /* Used only by the dynamic linker. When the object is run, this
475 doubleword64 is set to the load address of the object, plus the
477 HOWTO (R_PPC64_RELATIVE
, /* type */
479 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
481 FALSE
, /* pc_relative */
483 complain_overflow_dont
, /* complain_on_overflow */
484 bfd_elf_generic_reloc
, /* special_function */
485 "R_PPC64_RELATIVE", /* name */
486 FALSE
, /* partial_inplace */
488 ONES (64), /* dst_mask */
489 FALSE
), /* pcrel_offset */
491 /* Like R_PPC64_ADDR32, but may be unaligned. */
492 HOWTO (R_PPC64_UADDR32
, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE
, /* pc_relative */
498 complain_overflow_bitfield
, /* complain_on_overflow */
499 bfd_elf_generic_reloc
, /* special_function */
500 "R_PPC64_UADDR32", /* name */
501 FALSE
, /* partial_inplace */
503 0xffffffff, /* dst_mask */
504 FALSE
), /* pcrel_offset */
506 /* Like R_PPC64_ADDR16, but may be unaligned. */
507 HOWTO (R_PPC64_UADDR16
, /* type */
509 1, /* size (0 = byte, 1 = short, 2 = long) */
511 FALSE
, /* pc_relative */
513 complain_overflow_bitfield
, /* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_PPC64_UADDR16", /* name */
516 FALSE
, /* partial_inplace */
518 0xffff, /* dst_mask */
519 FALSE
), /* pcrel_offset */
521 /* 32-bit PC relative. */
522 HOWTO (R_PPC64_REL32
, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 TRUE
, /* pc_relative */
528 /* FIXME: Verify. Was complain_overflow_bitfield. */
529 complain_overflow_signed
, /* complain_on_overflow */
530 bfd_elf_generic_reloc
, /* special_function */
531 "R_PPC64_REL32", /* name */
532 FALSE
, /* partial_inplace */
534 0xffffffff, /* dst_mask */
535 TRUE
), /* pcrel_offset */
537 /* 32-bit relocation to the symbol's procedure linkage table. */
538 HOWTO (R_PPC64_PLT32
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 FALSE
, /* pc_relative */
544 complain_overflow_bitfield
, /* complain_on_overflow */
545 ppc64_elf_unhandled_reloc
, /* special_function */
546 "R_PPC64_PLT32", /* name */
547 FALSE
, /* partial_inplace */
549 0xffffffff, /* dst_mask */
550 FALSE
), /* pcrel_offset */
552 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
553 FIXME: R_PPC64_PLTREL32 not supported. */
554 HOWTO (R_PPC64_PLTREL32
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 TRUE
, /* pc_relative */
560 complain_overflow_signed
, /* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 "R_PPC64_PLTREL32", /* name */
563 FALSE
, /* partial_inplace */
565 0xffffffff, /* dst_mask */
566 TRUE
), /* pcrel_offset */
568 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
570 HOWTO (R_PPC64_PLT16_LO
, /* type */
572 1, /* size (0 = byte, 1 = short, 2 = long) */
574 FALSE
, /* pc_relative */
576 complain_overflow_dont
, /* complain_on_overflow */
577 ppc64_elf_unhandled_reloc
, /* special_function */
578 "R_PPC64_PLT16_LO", /* name */
579 FALSE
, /* partial_inplace */
581 0xffff, /* dst_mask */
582 FALSE
), /* pcrel_offset */
584 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
586 HOWTO (R_PPC64_PLT16_HI
, /* type */
588 1, /* size (0 = byte, 1 = short, 2 = long) */
590 FALSE
, /* pc_relative */
592 complain_overflow_dont
, /* complain_on_overflow */
593 ppc64_elf_unhandled_reloc
, /* special_function */
594 "R_PPC64_PLT16_HI", /* name */
595 FALSE
, /* partial_inplace */
597 0xffff, /* dst_mask */
598 FALSE
), /* pcrel_offset */
600 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
602 HOWTO (R_PPC64_PLT16_HA
, /* type */
604 1, /* size (0 = byte, 1 = short, 2 = long) */
606 FALSE
, /* pc_relative */
608 complain_overflow_dont
, /* complain_on_overflow */
609 ppc64_elf_unhandled_reloc
, /* special_function */
610 "R_PPC64_PLT16_HA", /* name */
611 FALSE
, /* partial_inplace */
613 0xffff, /* dst_mask */
614 FALSE
), /* pcrel_offset */
616 /* 16-bit section relative relocation. */
617 HOWTO (R_PPC64_SECTOFF
, /* type */
619 1, /* size (0 = byte, 1 = short, 2 = long) */
621 FALSE
, /* pc_relative */
623 complain_overflow_bitfield
, /* complain_on_overflow */
624 ppc64_elf_sectoff_reloc
, /* special_function */
625 "R_PPC64_SECTOFF", /* name */
626 FALSE
, /* partial_inplace */
628 0xffff, /* dst_mask */
629 FALSE
), /* pcrel_offset */
631 /* Like R_PPC64_SECTOFF, but no overflow warning. */
632 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
634 1, /* size (0 = byte, 1 = short, 2 = long) */
636 FALSE
, /* pc_relative */
638 complain_overflow_dont
, /* complain_on_overflow */
639 ppc64_elf_sectoff_reloc
, /* special_function */
640 "R_PPC64_SECTOFF_LO", /* name */
641 FALSE
, /* partial_inplace */
643 0xffff, /* dst_mask */
644 FALSE
), /* pcrel_offset */
646 /* 16-bit upper half section relative relocation. */
647 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 FALSE
, /* pc_relative */
653 complain_overflow_dont
, /* complain_on_overflow */
654 ppc64_elf_sectoff_reloc
, /* special_function */
655 "R_PPC64_SECTOFF_HI", /* name */
656 FALSE
, /* partial_inplace */
658 0xffff, /* dst_mask */
659 FALSE
), /* pcrel_offset */
661 /* 16-bit upper half adjusted section relative relocation. */
662 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
664 1, /* size (0 = byte, 1 = short, 2 = long) */
666 FALSE
, /* pc_relative */
668 complain_overflow_dont
, /* complain_on_overflow */
669 ppc64_elf_sectoff_ha_reloc
, /* special_function */
670 "R_PPC64_SECTOFF_HA", /* name */
671 FALSE
, /* partial_inplace */
673 0xffff, /* dst_mask */
674 FALSE
), /* pcrel_offset */
676 /* Like R_PPC64_REL24 without touching the two least significant bits. */
677 HOWTO (R_PPC64_REL30
, /* type */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
681 TRUE
, /* pc_relative */
683 complain_overflow_dont
, /* complain_on_overflow */
684 bfd_elf_generic_reloc
, /* special_function */
685 "R_PPC64_REL30", /* name */
686 FALSE
, /* partial_inplace */
688 0xfffffffc, /* dst_mask */
689 TRUE
), /* pcrel_offset */
691 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
693 /* A standard 64-bit relocation. */
694 HOWTO (R_PPC64_ADDR64
, /* type */
696 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
698 FALSE
, /* pc_relative */
700 complain_overflow_dont
, /* complain_on_overflow */
701 bfd_elf_generic_reloc
, /* special_function */
702 "R_PPC64_ADDR64", /* name */
703 FALSE
, /* partial_inplace */
705 ONES (64), /* dst_mask */
706 FALSE
), /* pcrel_offset */
708 /* The bits 32-47 of an address. */
709 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
711 1, /* size (0 = byte, 1 = short, 2 = long) */
713 FALSE
, /* pc_relative */
715 complain_overflow_dont
, /* complain_on_overflow */
716 bfd_elf_generic_reloc
, /* special_function */
717 "R_PPC64_ADDR16_HIGHER", /* name */
718 FALSE
, /* partial_inplace */
720 0xffff, /* dst_mask */
721 FALSE
), /* pcrel_offset */
723 /* The bits 32-47 of an address, plus 1 if the contents of the low
724 16 bits, treated as a signed number, is negative. */
725 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE
, /* pc_relative */
731 complain_overflow_dont
, /* complain_on_overflow */
732 ppc64_elf_ha_reloc
, /* special_function */
733 "R_PPC64_ADDR16_HIGHERA", /* name */
734 FALSE
, /* partial_inplace */
736 0xffff, /* dst_mask */
737 FALSE
), /* pcrel_offset */
739 /* The bits 48-63 of an address. */
740 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE
, /* pc_relative */
746 complain_overflow_dont
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 "R_PPC64_ADDR16_HIGHEST", /* name */
749 FALSE
, /* partial_inplace */
751 0xffff, /* dst_mask */
752 FALSE
), /* pcrel_offset */
754 /* The bits 48-63 of an address, plus 1 if the contents of the low
755 16 bits, treated as a signed number, is negative. */
756 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
758 1, /* size (0 = byte, 1 = short, 2 = long) */
760 FALSE
, /* pc_relative */
762 complain_overflow_dont
, /* complain_on_overflow */
763 ppc64_elf_ha_reloc
, /* special_function */
764 "R_PPC64_ADDR16_HIGHESTA", /* name */
765 FALSE
, /* partial_inplace */
767 0xffff, /* dst_mask */
768 FALSE
), /* pcrel_offset */
770 /* Like ADDR64, but may be unaligned. */
771 HOWTO (R_PPC64_UADDR64
, /* type */
773 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
775 FALSE
, /* pc_relative */
777 complain_overflow_dont
, /* complain_on_overflow */
778 bfd_elf_generic_reloc
, /* special_function */
779 "R_PPC64_UADDR64", /* name */
780 FALSE
, /* partial_inplace */
782 ONES (64), /* dst_mask */
783 FALSE
), /* pcrel_offset */
785 /* 64-bit relative relocation. */
786 HOWTO (R_PPC64_REL64
, /* type */
788 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
790 TRUE
, /* pc_relative */
792 complain_overflow_dont
, /* complain_on_overflow */
793 bfd_elf_generic_reloc
, /* special_function */
794 "R_PPC64_REL64", /* name */
795 FALSE
, /* partial_inplace */
797 ONES (64), /* dst_mask */
798 TRUE
), /* pcrel_offset */
800 /* 64-bit relocation to the symbol's procedure linkage table. */
801 HOWTO (R_PPC64_PLT64
, /* type */
803 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
805 FALSE
, /* pc_relative */
807 complain_overflow_dont
, /* complain_on_overflow */
808 ppc64_elf_unhandled_reloc
, /* special_function */
809 "R_PPC64_PLT64", /* name */
810 FALSE
, /* partial_inplace */
812 ONES (64), /* dst_mask */
813 FALSE
), /* pcrel_offset */
815 /* 64-bit PC relative relocation to the symbol's procedure linkage
817 /* FIXME: R_PPC64_PLTREL64 not supported. */
818 HOWTO (R_PPC64_PLTREL64
, /* type */
820 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
822 TRUE
, /* pc_relative */
824 complain_overflow_dont
, /* complain_on_overflow */
825 ppc64_elf_unhandled_reloc
, /* special_function */
826 "R_PPC64_PLTREL64", /* name */
827 FALSE
, /* partial_inplace */
829 ONES (64), /* dst_mask */
830 TRUE
), /* pcrel_offset */
832 /* 16 bit TOC-relative relocation. */
834 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
835 HOWTO (R_PPC64_TOC16
, /* type */
837 1, /* size (0 = byte, 1 = short, 2 = long) */
839 FALSE
, /* pc_relative */
841 complain_overflow_signed
, /* complain_on_overflow */
842 ppc64_elf_toc_reloc
, /* special_function */
843 "R_PPC64_TOC16", /* name */
844 FALSE
, /* partial_inplace */
846 0xffff, /* dst_mask */
847 FALSE
), /* pcrel_offset */
849 /* 16 bit TOC-relative relocation without overflow. */
851 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
852 HOWTO (R_PPC64_TOC16_LO
, /* type */
854 1, /* size (0 = byte, 1 = short, 2 = long) */
856 FALSE
, /* pc_relative */
858 complain_overflow_dont
, /* complain_on_overflow */
859 ppc64_elf_toc_reloc
, /* special_function */
860 "R_PPC64_TOC16_LO", /* name */
861 FALSE
, /* partial_inplace */
863 0xffff, /* dst_mask */
864 FALSE
), /* pcrel_offset */
866 /* 16 bit TOC-relative relocation, high 16 bits. */
868 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
869 HOWTO (R_PPC64_TOC16_HI
, /* type */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
873 FALSE
, /* pc_relative */
875 complain_overflow_dont
, /* complain_on_overflow */
876 ppc64_elf_toc_reloc
, /* special_function */
877 "R_PPC64_TOC16_HI", /* name */
878 FALSE
, /* partial_inplace */
880 0xffff, /* dst_mask */
881 FALSE
), /* pcrel_offset */
883 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
884 contents of the low 16 bits, treated as a signed number, is
887 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
888 HOWTO (R_PPC64_TOC16_HA
, /* type */
890 1, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_dont
, /* complain_on_overflow */
895 ppc64_elf_toc_ha_reloc
, /* special_function */
896 "R_PPC64_TOC16_HA", /* name */
897 FALSE
, /* partial_inplace */
899 0xffff, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 /* 64-bit relocation; insert value of TOC base (.TOC.). */
904 /* R_PPC64_TOC 51 doubleword64 .TOC. */
905 HOWTO (R_PPC64_TOC
, /* type */
907 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
909 FALSE
, /* pc_relative */
911 complain_overflow_bitfield
, /* complain_on_overflow */
912 ppc64_elf_toc64_reloc
, /* special_function */
913 "R_PPC64_TOC", /* name */
914 FALSE
, /* partial_inplace */
916 ONES (64), /* dst_mask */
917 FALSE
), /* pcrel_offset */
919 /* Like R_PPC64_GOT16, but also informs the link editor that the
920 value to relocate may (!) refer to a PLT entry which the link
921 editor (a) may replace with the symbol value. If the link editor
922 is unable to fully resolve the symbol, it may (b) create a PLT
923 entry and store the address to the new PLT entry in the GOT.
924 This permits lazy resolution of function symbols at run time.
925 The link editor may also skip all of this and just (c) emit a
926 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
927 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
928 HOWTO (R_PPC64_PLTGOT16
, /* type */
930 1, /* size (0 = byte, 1 = short, 2 = long) */
932 FALSE
, /* pc_relative */
934 complain_overflow_signed
, /* complain_on_overflow */
935 ppc64_elf_unhandled_reloc
, /* special_function */
936 "R_PPC64_PLTGOT16", /* name */
937 FALSE
, /* partial_inplace */
939 0xffff, /* dst_mask */
940 FALSE
), /* pcrel_offset */
942 /* Like R_PPC64_PLTGOT16, but without overflow. */
943 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
944 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
946 1, /* size (0 = byte, 1 = short, 2 = long) */
948 FALSE
, /* pc_relative */
950 complain_overflow_dont
, /* complain_on_overflow */
951 ppc64_elf_unhandled_reloc
, /* special_function */
952 "R_PPC64_PLTGOT16_LO", /* name */
953 FALSE
, /* partial_inplace */
955 0xffff, /* dst_mask */
956 FALSE
), /* pcrel_offset */
958 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
959 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
960 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
962 1, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_dont
, /* complain_on_overflow */
967 ppc64_elf_unhandled_reloc
, /* special_function */
968 "R_PPC64_PLTGOT16_HI", /* name */
969 FALSE
, /* partial_inplace */
971 0xffff, /* dst_mask */
972 FALSE
), /* pcrel_offset */
974 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
975 1 if the contents of the low 16 bits, treated as a signed number,
977 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
978 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
980 1, /* size (0 = byte, 1 = short, 2 = long) */
982 FALSE
, /* pc_relative */
984 complain_overflow_dont
,/* complain_on_overflow */
985 ppc64_elf_unhandled_reloc
, /* special_function */
986 "R_PPC64_PLTGOT16_HA", /* name */
987 FALSE
, /* partial_inplace */
989 0xffff, /* dst_mask */
990 FALSE
), /* pcrel_offset */
992 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
993 HOWTO (R_PPC64_ADDR16_DS
, /* type */
995 1, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE
, /* pc_relative */
999 complain_overflow_bitfield
, /* complain_on_overflow */
1000 bfd_elf_generic_reloc
, /* special_function */
1001 "R_PPC64_ADDR16_DS", /* name */
1002 FALSE
, /* partial_inplace */
1004 0xfffc, /* dst_mask */
1005 FALSE
), /* pcrel_offset */
1007 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1008 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1010 1, /* size (0 = byte, 1 = short, 2 = long) */
1012 FALSE
, /* pc_relative */
1014 complain_overflow_dont
,/* complain_on_overflow */
1015 bfd_elf_generic_reloc
, /* special_function */
1016 "R_PPC64_ADDR16_LO_DS",/* name */
1017 FALSE
, /* partial_inplace */
1019 0xfffc, /* dst_mask */
1020 FALSE
), /* pcrel_offset */
1022 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1023 HOWTO (R_PPC64_GOT16_DS
, /* type */
1025 1, /* size (0 = byte, 1 = short, 2 = long) */
1027 FALSE
, /* pc_relative */
1029 complain_overflow_signed
, /* complain_on_overflow */
1030 ppc64_elf_unhandled_reloc
, /* special_function */
1031 "R_PPC64_GOT16_DS", /* name */
1032 FALSE
, /* partial_inplace */
1034 0xfffc, /* dst_mask */
1035 FALSE
), /* pcrel_offset */
1037 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1038 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1040 1, /* size (0 = byte, 1 = short, 2 = long) */
1042 FALSE
, /* pc_relative */
1044 complain_overflow_dont
, /* complain_on_overflow */
1045 ppc64_elf_unhandled_reloc
, /* special_function */
1046 "R_PPC64_GOT16_LO_DS", /* name */
1047 FALSE
, /* partial_inplace */
1049 0xfffc, /* dst_mask */
1050 FALSE
), /* pcrel_offset */
1052 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1053 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1055 1, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE
, /* pc_relative */
1059 complain_overflow_dont
, /* complain_on_overflow */
1060 ppc64_elf_unhandled_reloc
, /* special_function */
1061 "R_PPC64_PLT16_LO_DS", /* name */
1062 FALSE
, /* partial_inplace */
1064 0xfffc, /* dst_mask */
1065 FALSE
), /* pcrel_offset */
1067 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1068 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1070 1, /* size (0 = byte, 1 = short, 2 = long) */
1072 FALSE
, /* pc_relative */
1074 complain_overflow_bitfield
, /* complain_on_overflow */
1075 ppc64_elf_sectoff_reloc
, /* special_function */
1076 "R_PPC64_SECTOFF_DS", /* name */
1077 FALSE
, /* partial_inplace */
1079 0xfffc, /* dst_mask */
1080 FALSE
), /* pcrel_offset */
1082 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1083 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1085 1, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE
, /* pc_relative */
1089 complain_overflow_dont
, /* complain_on_overflow */
1090 ppc64_elf_sectoff_reloc
, /* special_function */
1091 "R_PPC64_SECTOFF_LO_DS",/* name */
1092 FALSE
, /* partial_inplace */
1094 0xfffc, /* dst_mask */
1095 FALSE
), /* pcrel_offset */
1097 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1098 HOWTO (R_PPC64_TOC16_DS
, /* type */
1100 1, /* size (0 = byte, 1 = short, 2 = long) */
1102 FALSE
, /* pc_relative */
1104 complain_overflow_signed
, /* complain_on_overflow */
1105 ppc64_elf_toc_reloc
, /* special_function */
1106 "R_PPC64_TOC16_DS", /* name */
1107 FALSE
, /* partial_inplace */
1109 0xfffc, /* dst_mask */
1110 FALSE
), /* pcrel_offset */
1112 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1113 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1115 1, /* size (0 = byte, 1 = short, 2 = long) */
1117 FALSE
, /* pc_relative */
1119 complain_overflow_dont
, /* complain_on_overflow */
1120 ppc64_elf_toc_reloc
, /* special_function */
1121 "R_PPC64_TOC16_LO_DS", /* name */
1122 FALSE
, /* partial_inplace */
1124 0xfffc, /* dst_mask */
1125 FALSE
), /* pcrel_offset */
1127 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1128 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1129 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1131 1, /* size (0 = byte, 1 = short, 2 = long) */
1133 FALSE
, /* pc_relative */
1135 complain_overflow_signed
, /* complain_on_overflow */
1136 ppc64_elf_unhandled_reloc
, /* special_function */
1137 "R_PPC64_PLTGOT16_DS", /* name */
1138 FALSE
, /* partial_inplace */
1140 0xfffc, /* dst_mask */
1141 FALSE
), /* pcrel_offset */
1143 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1144 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1145 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1147 1, /* size (0 = byte, 1 = short, 2 = long) */
1149 FALSE
, /* pc_relative */
1151 complain_overflow_dont
, /* complain_on_overflow */
1152 ppc64_elf_unhandled_reloc
, /* special_function */
1153 "R_PPC64_PLTGOT16_LO_DS",/* name */
1154 FALSE
, /* partial_inplace */
1156 0xfffc, /* dst_mask */
1157 FALSE
), /* pcrel_offset */
1159 /* Marker reloc for TLS. */
1162 2, /* size (0 = byte, 1 = short, 2 = long) */
1164 FALSE
, /* pc_relative */
1166 complain_overflow_dont
, /* complain_on_overflow */
1167 bfd_elf_generic_reloc
, /* special_function */
1168 "R_PPC64_TLS", /* name */
1169 FALSE
, /* partial_inplace */
1172 FALSE
), /* pcrel_offset */
1174 /* Computes the load module index of the load module that contains the
1175 definition of its TLS sym. */
1176 HOWTO (R_PPC64_DTPMOD64
,
1178 4, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE
, /* pc_relative */
1182 complain_overflow_dont
, /* complain_on_overflow */
1183 ppc64_elf_unhandled_reloc
, /* special_function */
1184 "R_PPC64_DTPMOD64", /* name */
1185 FALSE
, /* partial_inplace */
1187 ONES (64), /* dst_mask */
1188 FALSE
), /* pcrel_offset */
1190 /* Computes a dtv-relative displacement, the difference between the value
1191 of sym+add and the base address of the thread-local storage block that
1192 contains the definition of sym, minus 0x8000. */
1193 HOWTO (R_PPC64_DTPREL64
,
1195 4, /* size (0 = byte, 1 = short, 2 = long) */
1197 FALSE
, /* pc_relative */
1199 complain_overflow_dont
, /* complain_on_overflow */
1200 ppc64_elf_unhandled_reloc
, /* special_function */
1201 "R_PPC64_DTPREL64", /* name */
1202 FALSE
, /* partial_inplace */
1204 ONES (64), /* dst_mask */
1205 FALSE
), /* pcrel_offset */
1207 /* A 16 bit dtprel reloc. */
1208 HOWTO (R_PPC64_DTPREL16
,
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE
, /* pc_relative */
1214 complain_overflow_signed
, /* complain_on_overflow */
1215 ppc64_elf_unhandled_reloc
, /* special_function */
1216 "R_PPC64_DTPREL16", /* name */
1217 FALSE
, /* partial_inplace */
1219 0xffff, /* dst_mask */
1220 FALSE
), /* pcrel_offset */
1222 /* Like DTPREL16, but no overflow. */
1223 HOWTO (R_PPC64_DTPREL16_LO
,
1225 1, /* size (0 = byte, 1 = short, 2 = long) */
1227 FALSE
, /* pc_relative */
1229 complain_overflow_dont
, /* complain_on_overflow */
1230 ppc64_elf_unhandled_reloc
, /* special_function */
1231 "R_PPC64_DTPREL16_LO", /* name */
1232 FALSE
, /* partial_inplace */
1234 0xffff, /* dst_mask */
1235 FALSE
), /* pcrel_offset */
1237 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1238 HOWTO (R_PPC64_DTPREL16_HI
,
1239 16, /* rightshift */
1240 1, /* size (0 = byte, 1 = short, 2 = long) */
1242 FALSE
, /* pc_relative */
1244 complain_overflow_dont
, /* complain_on_overflow */
1245 ppc64_elf_unhandled_reloc
, /* special_function */
1246 "R_PPC64_DTPREL16_HI", /* name */
1247 FALSE
, /* partial_inplace */
1249 0xffff, /* dst_mask */
1250 FALSE
), /* pcrel_offset */
1252 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1253 HOWTO (R_PPC64_DTPREL16_HA
,
1254 16, /* rightshift */
1255 1, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE
, /* pc_relative */
1259 complain_overflow_dont
, /* complain_on_overflow */
1260 ppc64_elf_unhandled_reloc
, /* special_function */
1261 "R_PPC64_DTPREL16_HA", /* name */
1262 FALSE
, /* partial_inplace */
1264 0xffff, /* dst_mask */
1265 FALSE
), /* pcrel_offset */
1267 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1268 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1269 32, /* rightshift */
1270 1, /* size (0 = byte, 1 = short, 2 = long) */
1272 FALSE
, /* pc_relative */
1274 complain_overflow_dont
, /* complain_on_overflow */
1275 ppc64_elf_unhandled_reloc
, /* special_function */
1276 "R_PPC64_DTPREL16_HIGHER", /* name */
1277 FALSE
, /* partial_inplace */
1279 0xffff, /* dst_mask */
1280 FALSE
), /* pcrel_offset */
1282 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1283 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1284 32, /* rightshift */
1285 1, /* size (0 = byte, 1 = short, 2 = long) */
1287 FALSE
, /* pc_relative */
1289 complain_overflow_dont
, /* complain_on_overflow */
1290 ppc64_elf_unhandled_reloc
, /* special_function */
1291 "R_PPC64_DTPREL16_HIGHERA", /* name */
1292 FALSE
, /* partial_inplace */
1294 0xffff, /* dst_mask */
1295 FALSE
), /* pcrel_offset */
1297 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1298 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1299 48, /* rightshift */
1300 1, /* size (0 = byte, 1 = short, 2 = long) */
1302 FALSE
, /* pc_relative */
1304 complain_overflow_dont
, /* complain_on_overflow */
1305 ppc64_elf_unhandled_reloc
, /* special_function */
1306 "R_PPC64_DTPREL16_HIGHEST", /* name */
1307 FALSE
, /* partial_inplace */
1309 0xffff, /* dst_mask */
1310 FALSE
), /* pcrel_offset */
1312 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1313 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1314 48, /* rightshift */
1315 1, /* size (0 = byte, 1 = short, 2 = long) */
1317 FALSE
, /* pc_relative */
1319 complain_overflow_dont
, /* complain_on_overflow */
1320 ppc64_elf_unhandled_reloc
, /* special_function */
1321 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1322 FALSE
, /* partial_inplace */
1324 0xffff, /* dst_mask */
1325 FALSE
), /* pcrel_offset */
1327 /* Like DTPREL16, but for insns with a DS field. */
1328 HOWTO (R_PPC64_DTPREL16_DS
,
1330 1, /* size (0 = byte, 1 = short, 2 = long) */
1332 FALSE
, /* pc_relative */
1334 complain_overflow_signed
, /* complain_on_overflow */
1335 ppc64_elf_unhandled_reloc
, /* special_function */
1336 "R_PPC64_DTPREL16_DS", /* name */
1337 FALSE
, /* partial_inplace */
1339 0xfffc, /* dst_mask */
1340 FALSE
), /* pcrel_offset */
1342 /* Like DTPREL16_DS, but no overflow. */
1343 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1345 1, /* size (0 = byte, 1 = short, 2 = long) */
1347 FALSE
, /* pc_relative */
1349 complain_overflow_dont
, /* complain_on_overflow */
1350 ppc64_elf_unhandled_reloc
, /* special_function */
1351 "R_PPC64_DTPREL16_LO_DS", /* name */
1352 FALSE
, /* partial_inplace */
1354 0xfffc, /* dst_mask */
1355 FALSE
), /* pcrel_offset */
1357 /* Computes a tp-relative displacement, the difference between the value of
1358 sym+add and the value of the thread pointer (r13). */
1359 HOWTO (R_PPC64_TPREL64
,
1361 4, /* size (0 = byte, 1 = short, 2 = long) */
1363 FALSE
, /* pc_relative */
1365 complain_overflow_dont
, /* complain_on_overflow */
1366 ppc64_elf_unhandled_reloc
, /* special_function */
1367 "R_PPC64_TPREL64", /* name */
1368 FALSE
, /* partial_inplace */
1370 ONES (64), /* dst_mask */
1371 FALSE
), /* pcrel_offset */
1373 /* A 16 bit tprel reloc. */
1374 HOWTO (R_PPC64_TPREL16
,
1376 1, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE
, /* pc_relative */
1380 complain_overflow_signed
, /* complain_on_overflow */
1381 ppc64_elf_unhandled_reloc
, /* special_function */
1382 "R_PPC64_TPREL16", /* name */
1383 FALSE
, /* partial_inplace */
1385 0xffff, /* dst_mask */
1386 FALSE
), /* pcrel_offset */
1388 /* Like TPREL16, but no overflow. */
1389 HOWTO (R_PPC64_TPREL16_LO
,
1391 1, /* size (0 = byte, 1 = short, 2 = long) */
1393 FALSE
, /* pc_relative */
1395 complain_overflow_dont
, /* complain_on_overflow */
1396 ppc64_elf_unhandled_reloc
, /* special_function */
1397 "R_PPC64_TPREL16_LO", /* name */
1398 FALSE
, /* partial_inplace */
1400 0xffff, /* dst_mask */
1401 FALSE
), /* pcrel_offset */
1403 /* Like TPREL16_LO, but next higher group of 16 bits. */
1404 HOWTO (R_PPC64_TPREL16_HI
,
1405 16, /* rightshift */
1406 1, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE
, /* pc_relative */
1410 complain_overflow_dont
, /* complain_on_overflow */
1411 ppc64_elf_unhandled_reloc
, /* special_function */
1412 "R_PPC64_TPREL16_HI", /* name */
1413 FALSE
, /* partial_inplace */
1415 0xffff, /* dst_mask */
1416 FALSE
), /* pcrel_offset */
1418 /* Like TPREL16_HI, but adjust for low 16 bits. */
1419 HOWTO (R_PPC64_TPREL16_HA
,
1420 16, /* rightshift */
1421 1, /* size (0 = byte, 1 = short, 2 = long) */
1423 FALSE
, /* pc_relative */
1425 complain_overflow_dont
, /* complain_on_overflow */
1426 ppc64_elf_unhandled_reloc
, /* special_function */
1427 "R_PPC64_TPREL16_HA", /* name */
1428 FALSE
, /* partial_inplace */
1430 0xffff, /* dst_mask */
1431 FALSE
), /* pcrel_offset */
1433 /* Like TPREL16_HI, but next higher group of 16 bits. */
1434 HOWTO (R_PPC64_TPREL16_HIGHER
,
1435 32, /* rightshift */
1436 1, /* size (0 = byte, 1 = short, 2 = long) */
1438 FALSE
, /* pc_relative */
1440 complain_overflow_dont
, /* complain_on_overflow */
1441 ppc64_elf_unhandled_reloc
, /* special_function */
1442 "R_PPC64_TPREL16_HIGHER", /* name */
1443 FALSE
, /* partial_inplace */
1445 0xffff, /* dst_mask */
1446 FALSE
), /* pcrel_offset */
1448 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1449 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1450 32, /* rightshift */
1451 1, /* size (0 = byte, 1 = short, 2 = long) */
1453 FALSE
, /* pc_relative */
1455 complain_overflow_dont
, /* complain_on_overflow */
1456 ppc64_elf_unhandled_reloc
, /* special_function */
1457 "R_PPC64_TPREL16_HIGHERA", /* name */
1458 FALSE
, /* partial_inplace */
1460 0xffff, /* dst_mask */
1461 FALSE
), /* pcrel_offset */
1463 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1464 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1465 48, /* rightshift */
1466 1, /* size (0 = byte, 1 = short, 2 = long) */
1468 FALSE
, /* pc_relative */
1470 complain_overflow_dont
, /* complain_on_overflow */
1471 ppc64_elf_unhandled_reloc
, /* special_function */
1472 "R_PPC64_TPREL16_HIGHEST", /* name */
1473 FALSE
, /* partial_inplace */
1475 0xffff, /* dst_mask */
1476 FALSE
), /* pcrel_offset */
1478 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1479 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1480 48, /* rightshift */
1481 1, /* size (0 = byte, 1 = short, 2 = long) */
1483 FALSE
, /* pc_relative */
1485 complain_overflow_dont
, /* complain_on_overflow */
1486 ppc64_elf_unhandled_reloc
, /* special_function */
1487 "R_PPC64_TPREL16_HIGHESTA", /* name */
1488 FALSE
, /* partial_inplace */
1490 0xffff, /* dst_mask */
1491 FALSE
), /* pcrel_offset */
1493 /* Like TPREL16, but for insns with a DS field. */
1494 HOWTO (R_PPC64_TPREL16_DS
,
1496 1, /* size (0 = byte, 1 = short, 2 = long) */
1498 FALSE
, /* pc_relative */
1500 complain_overflow_signed
, /* complain_on_overflow */
1501 ppc64_elf_unhandled_reloc
, /* special_function */
1502 "R_PPC64_TPREL16_DS", /* name */
1503 FALSE
, /* partial_inplace */
1505 0xfffc, /* dst_mask */
1506 FALSE
), /* pcrel_offset */
1508 /* Like TPREL16_DS, but no overflow. */
1509 HOWTO (R_PPC64_TPREL16_LO_DS
,
1511 1, /* size (0 = byte, 1 = short, 2 = long) */
1513 FALSE
, /* pc_relative */
1515 complain_overflow_dont
, /* complain_on_overflow */
1516 ppc64_elf_unhandled_reloc
, /* special_function */
1517 "R_PPC64_TPREL16_LO_DS", /* name */
1518 FALSE
, /* partial_inplace */
1520 0xfffc, /* dst_mask */
1521 FALSE
), /* pcrel_offset */
1523 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1524 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1525 to the first entry relative to the TOC base (r2). */
1526 HOWTO (R_PPC64_GOT_TLSGD16
,
1528 1, /* size (0 = byte, 1 = short, 2 = long) */
1530 FALSE
, /* pc_relative */
1532 complain_overflow_signed
, /* complain_on_overflow */
1533 ppc64_elf_unhandled_reloc
, /* special_function */
1534 "R_PPC64_GOT_TLSGD16", /* name */
1535 FALSE
, /* partial_inplace */
1537 0xffff, /* dst_mask */
1538 FALSE
), /* pcrel_offset */
1540 /* Like GOT_TLSGD16, but no overflow. */
1541 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1543 1, /* size (0 = byte, 1 = short, 2 = long) */
1545 FALSE
, /* pc_relative */
1547 complain_overflow_dont
, /* complain_on_overflow */
1548 ppc64_elf_unhandled_reloc
, /* special_function */
1549 "R_PPC64_GOT_TLSGD16_LO", /* name */
1550 FALSE
, /* partial_inplace */
1552 0xffff, /* dst_mask */
1553 FALSE
), /* pcrel_offset */
1555 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1556 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1557 16, /* rightshift */
1558 1, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE
, /* pc_relative */
1562 complain_overflow_dont
, /* complain_on_overflow */
1563 ppc64_elf_unhandled_reloc
, /* special_function */
1564 "R_PPC64_GOT_TLSGD16_HI", /* name */
1565 FALSE
, /* partial_inplace */
1567 0xffff, /* dst_mask */
1568 FALSE
), /* pcrel_offset */
1570 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1571 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1572 16, /* rightshift */
1573 1, /* size (0 = byte, 1 = short, 2 = long) */
1575 FALSE
, /* pc_relative */
1577 complain_overflow_dont
, /* complain_on_overflow */
1578 ppc64_elf_unhandled_reloc
, /* special_function */
1579 "R_PPC64_GOT_TLSGD16_HA", /* name */
1580 FALSE
, /* partial_inplace */
1582 0xffff, /* dst_mask */
1583 FALSE
), /* pcrel_offset */
1585 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1586 with values (sym+add)@dtpmod and zero, and computes the offset to the
1587 first entry relative to the TOC base (r2). */
1588 HOWTO (R_PPC64_GOT_TLSLD16
,
1590 1, /* size (0 = byte, 1 = short, 2 = long) */
1592 FALSE
, /* pc_relative */
1594 complain_overflow_signed
, /* complain_on_overflow */
1595 ppc64_elf_unhandled_reloc
, /* special_function */
1596 "R_PPC64_GOT_TLSLD16", /* name */
1597 FALSE
, /* partial_inplace */
1599 0xffff, /* dst_mask */
1600 FALSE
), /* pcrel_offset */
1602 /* Like GOT_TLSLD16, but no overflow. */
1603 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1605 1, /* size (0 = byte, 1 = short, 2 = long) */
1607 FALSE
, /* pc_relative */
1609 complain_overflow_dont
, /* complain_on_overflow */
1610 ppc64_elf_unhandled_reloc
, /* special_function */
1611 "R_PPC64_GOT_TLSLD16_LO", /* name */
1612 FALSE
, /* partial_inplace */
1614 0xffff, /* dst_mask */
1615 FALSE
), /* pcrel_offset */
1617 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1618 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1619 16, /* rightshift */
1620 1, /* size (0 = byte, 1 = short, 2 = long) */
1622 FALSE
, /* pc_relative */
1624 complain_overflow_dont
, /* complain_on_overflow */
1625 ppc64_elf_unhandled_reloc
, /* special_function */
1626 "R_PPC64_GOT_TLSLD16_HI", /* name */
1627 FALSE
, /* partial_inplace */
1629 0xffff, /* dst_mask */
1630 FALSE
), /* pcrel_offset */
1632 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1633 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1634 16, /* rightshift */
1635 1, /* size (0 = byte, 1 = short, 2 = long) */
1637 FALSE
, /* pc_relative */
1639 complain_overflow_dont
, /* complain_on_overflow */
1640 ppc64_elf_unhandled_reloc
, /* special_function */
1641 "R_PPC64_GOT_TLSLD16_HA", /* name */
1642 FALSE
, /* partial_inplace */
1644 0xffff, /* dst_mask */
1645 FALSE
), /* pcrel_offset */
1647 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1648 the offset to the entry relative to the TOC base (r2). */
1649 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1651 1, /* size (0 = byte, 1 = short, 2 = long) */
1653 FALSE
, /* pc_relative */
1655 complain_overflow_signed
, /* complain_on_overflow */
1656 ppc64_elf_unhandled_reloc
, /* special_function */
1657 "R_PPC64_GOT_DTPREL16_DS", /* name */
1658 FALSE
, /* partial_inplace */
1660 0xfffc, /* dst_mask */
1661 FALSE
), /* pcrel_offset */
1663 /* Like GOT_DTPREL16_DS, but no overflow. */
1664 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1666 1, /* size (0 = byte, 1 = short, 2 = long) */
1668 FALSE
, /* pc_relative */
1670 complain_overflow_dont
, /* complain_on_overflow */
1671 ppc64_elf_unhandled_reloc
, /* special_function */
1672 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1673 FALSE
, /* partial_inplace */
1675 0xfffc, /* dst_mask */
1676 FALSE
), /* pcrel_offset */
1678 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1679 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1680 16, /* rightshift */
1681 1, /* size (0 = byte, 1 = short, 2 = long) */
1683 FALSE
, /* pc_relative */
1685 complain_overflow_dont
, /* complain_on_overflow */
1686 ppc64_elf_unhandled_reloc
, /* special_function */
1687 "R_PPC64_GOT_DTPREL16_HI", /* name */
1688 FALSE
, /* partial_inplace */
1690 0xffff, /* dst_mask */
1691 FALSE
), /* pcrel_offset */
1693 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1694 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1695 16, /* rightshift */
1696 1, /* size (0 = byte, 1 = short, 2 = long) */
1698 FALSE
, /* pc_relative */
1700 complain_overflow_dont
, /* complain_on_overflow */
1701 ppc64_elf_unhandled_reloc
, /* special_function */
1702 "R_PPC64_GOT_DTPREL16_HA", /* name */
1703 FALSE
, /* partial_inplace */
1705 0xffff, /* dst_mask */
1706 FALSE
), /* pcrel_offset */
1708 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1709 offset to the entry relative to the TOC base (r2). */
1710 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1712 1, /* size (0 = byte, 1 = short, 2 = long) */
1714 FALSE
, /* pc_relative */
1716 complain_overflow_signed
, /* complain_on_overflow */
1717 ppc64_elf_unhandled_reloc
, /* special_function */
1718 "R_PPC64_GOT_TPREL16_DS", /* name */
1719 FALSE
, /* partial_inplace */
1721 0xffff, /* dst_mask */
1722 FALSE
), /* pcrel_offset */
1724 /* Like GOT_TPREL16_DS, but no overflow. */
1725 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1727 1, /* size (0 = byte, 1 = short, 2 = long) */
1729 FALSE
, /* pc_relative */
1731 complain_overflow_dont
, /* complain_on_overflow */
1732 ppc64_elf_unhandled_reloc
, /* special_function */
1733 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1734 FALSE
, /* partial_inplace */
1736 0xffff, /* dst_mask */
1737 FALSE
), /* pcrel_offset */
1739 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1740 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1741 16, /* rightshift */
1742 1, /* size (0 = byte, 1 = short, 2 = long) */
1744 FALSE
, /* pc_relative */
1746 complain_overflow_dont
, /* complain_on_overflow */
1747 ppc64_elf_unhandled_reloc
, /* special_function */
1748 "R_PPC64_GOT_TPREL16_HI", /* name */
1749 FALSE
, /* partial_inplace */
1751 0xffff, /* dst_mask */
1752 FALSE
), /* pcrel_offset */
1754 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1755 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1756 16, /* rightshift */
1757 1, /* size (0 = byte, 1 = short, 2 = long) */
1759 FALSE
, /* pc_relative */
1761 complain_overflow_dont
, /* complain_on_overflow */
1762 ppc64_elf_unhandled_reloc
, /* special_function */
1763 "R_PPC64_GOT_TPREL16_HA", /* name */
1764 FALSE
, /* partial_inplace */
1766 0xffff, /* dst_mask */
1767 FALSE
), /* pcrel_offset */
1769 /* GNU extension to record C++ vtable hierarchy. */
1770 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1772 0, /* size (0 = byte, 1 = short, 2 = long) */
1774 FALSE
, /* pc_relative */
1776 complain_overflow_dont
, /* complain_on_overflow */
1777 NULL
, /* special_function */
1778 "R_PPC64_GNU_VTINHERIT", /* name */
1779 FALSE
, /* partial_inplace */
1782 FALSE
), /* pcrel_offset */
1784 /* GNU extension to record C++ vtable member usage. */
1785 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1787 0, /* size (0 = byte, 1 = short, 2 = long) */
1789 FALSE
, /* pc_relative */
1791 complain_overflow_dont
, /* complain_on_overflow */
1792 NULL
, /* special_function */
1793 "R_PPC64_GNU_VTENTRY", /* name */
1794 FALSE
, /* partial_inplace */
1797 FALSE
), /* pcrel_offset */
1801 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1807 unsigned int i
, type
;
1810 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1813 type
= ppc64_elf_howto_raw
[i
].type
;
1814 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1815 / sizeof (ppc64_elf_howto_table
[0])));
1816 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1820 static reloc_howto_type
*
1821 ppc64_elf_reloc_type_lookup (abfd
, code
)
1822 bfd
*abfd ATTRIBUTE_UNUSED
;
1823 bfd_reloc_code_real_type code
;
1825 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1827 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1828 /* Initialize howto table if needed. */
1834 return (reloc_howto_type
*) NULL
;
1836 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1838 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1840 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1842 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1844 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1846 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1848 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1850 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1852 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1854 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1856 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1858 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1860 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1862 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1864 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1866 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1868 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1870 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1872 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1874 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1876 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1878 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1880 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1882 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1884 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1886 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1888 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1890 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1892 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1894 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1896 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1898 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1900 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1902 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1904 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1906 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1908 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1910 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1912 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1914 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1916 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1918 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1920 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1922 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1924 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1926 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1928 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1930 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1932 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1934 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1936 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1938 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1940 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1942 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1944 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1946 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1948 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1950 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1952 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1954 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1956 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1958 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1960 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1962 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1964 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1966 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1968 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1970 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1972 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1974 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1976 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1978 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1980 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1982 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1984 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1986 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1988 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1990 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1992 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1994 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1996 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1998 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2000 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2002 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2004 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2006 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2008 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2010 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2012 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2014 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2016 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2018 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2020 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2022 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2024 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2026 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2028 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2030 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2032 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2034 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2036 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2040 return ppc64_elf_howto_table
[(int) r
];
2043 /* Set the howto pointer for a PowerPC ELF reloc. */
2046 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
2047 bfd
*abfd ATTRIBUTE_UNUSED
;
2049 Elf_Internal_Rela
*dst
;
2053 /* Initialize howto table if needed. */
2054 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2057 type
= ELF64_R_TYPE (dst
->r_info
);
2058 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
2059 / sizeof (ppc64_elf_howto_table
[0])));
2060 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2063 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2065 static bfd_reloc_status_type
2066 ppc64_elf_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
2067 input_section
, output_bfd
, error_message
)
2069 arelent
*reloc_entry
;
2072 asection
*input_section
;
2074 char **error_message
;
2076 /* If this is a relocatable link (output_bfd test tells us), just
2077 call the generic function. Any adjustment will be done at final
2079 if (output_bfd
!= NULL
)
2080 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2081 input_section
, output_bfd
, error_message
);
2083 /* Adjust the addend for sign extension of the low 16 bits.
2084 We won't actually be using the low 16 bits, so trashing them
2086 reloc_entry
->addend
+= 0x8000;
2087 return bfd_reloc_continue
;
2090 static bfd_reloc_status_type
2091 ppc64_elf_brtaken_reloc (abfd
, reloc_entry
, symbol
, data
,
2092 input_section
, output_bfd
, error_message
)
2094 arelent
*reloc_entry
;
2097 asection
*input_section
;
2099 char **error_message
;
2102 enum elf_ppc64_reloc_type r_type
;
2103 bfd_size_type octets
;
2104 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2105 bfd_boolean is_power4
= FALSE
;
2107 /* If this is a relocatable link (output_bfd test tells us), just
2108 call the generic function. Any adjustment will be done at final
2110 if (output_bfd
!= NULL
)
2111 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2112 input_section
, output_bfd
, error_message
);
2114 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2115 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2116 insn
&= ~(0x01 << 21);
2117 r_type
= (enum elf_ppc64_reloc_type
) reloc_entry
->howto
->type
;
2118 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2119 || r_type
== R_PPC64_REL14_BRTAKEN
)
2120 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2124 /* Set 'a' bit. This is 0b00010 in BO field for branch
2125 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2126 for branch on CTR insns (BO == 1a00t or 1a01t). */
2127 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2129 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2132 return bfd_reloc_continue
;
2139 if (!bfd_is_com_section (symbol
->section
))
2140 target
= symbol
->value
;
2141 target
+= symbol
->section
->output_section
->vma
;
2142 target
+= symbol
->section
->output_offset
;
2143 target
+= reloc_entry
->addend
;
2145 from
= (reloc_entry
->address
2146 + input_section
->output_offset
2147 + input_section
->output_section
->vma
);
2149 /* Invert 'y' bit if not the default. */
2150 if ((bfd_signed_vma
) (target
- from
) < 0)
2153 bfd_put_32 (abfd
, (bfd_vma
) insn
, (bfd_byte
*) data
+ octets
);
2154 return bfd_reloc_continue
;
2157 static bfd_reloc_status_type
2158 ppc64_elf_sectoff_reloc (abfd
, reloc_entry
, symbol
, data
,
2159 input_section
, output_bfd
, error_message
)
2161 arelent
*reloc_entry
;
2164 asection
*input_section
;
2166 char **error_message
;
2168 /* If this is a relocatable link (output_bfd test tells us), just
2169 call the generic function. Any adjustment will be done at final
2171 if (output_bfd
!= NULL
)
2172 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2173 input_section
, output_bfd
, error_message
);
2175 /* Subtract the symbol section base address. */
2176 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2177 return bfd_reloc_continue
;
2180 static bfd_reloc_status_type
2181 ppc64_elf_sectoff_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
2182 input_section
, output_bfd
, error_message
)
2184 arelent
*reloc_entry
;
2187 asection
*input_section
;
2189 char **error_message
;
2191 /* If this is a relocatable link (output_bfd test tells us), just
2192 call the generic function. Any adjustment will be done at final
2194 if (output_bfd
!= NULL
)
2195 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2196 input_section
, output_bfd
, error_message
);
2198 /* Subtract the symbol section base address. */
2199 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2201 /* Adjust the addend for sign extension of the low 16 bits. */
2202 reloc_entry
->addend
+= 0x8000;
2203 return bfd_reloc_continue
;
2206 static bfd_reloc_status_type
2207 ppc64_elf_toc_reloc (abfd
, reloc_entry
, symbol
, data
,
2208 input_section
, output_bfd
, error_message
)
2210 arelent
*reloc_entry
;
2213 asection
*input_section
;
2215 char **error_message
;
2219 /* If this is a relocatable link (output_bfd test tells us), just
2220 call the generic function. Any adjustment will be done at final
2222 if (output_bfd
!= NULL
)
2223 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2224 input_section
, output_bfd
, error_message
);
2226 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2228 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2230 /* Subtract the TOC base address. */
2231 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2232 return bfd_reloc_continue
;
2235 static bfd_reloc_status_type
2236 ppc64_elf_toc_ha_reloc (abfd
, reloc_entry
, symbol
, data
,
2237 input_section
, output_bfd
, error_message
)
2239 arelent
*reloc_entry
;
2242 asection
*input_section
;
2244 char **error_message
;
2248 /* If this is a relocatable link (output_bfd test tells us), just
2249 call the generic function. Any adjustment will be done at final
2251 if (output_bfd
!= NULL
)
2252 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2253 input_section
, output_bfd
, error_message
);
2255 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2257 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2259 /* Subtract the TOC base address. */
2260 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2262 /* Adjust the addend for sign extension of the low 16 bits. */
2263 reloc_entry
->addend
+= 0x8000;
2264 return bfd_reloc_continue
;
2267 static bfd_reloc_status_type
2268 ppc64_elf_toc64_reloc (abfd
, reloc_entry
, symbol
, data
,
2269 input_section
, output_bfd
, error_message
)
2271 arelent
*reloc_entry
;
2274 asection
*input_section
;
2276 char **error_message
;
2279 bfd_size_type octets
;
2281 /* If this is a relocatable link (output_bfd test tells us), just
2282 call the generic function. Any adjustment will be done at final
2284 if (output_bfd
!= NULL
)
2285 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2286 input_section
, output_bfd
, error_message
);
2288 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2290 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2292 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2293 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2294 return bfd_reloc_ok
;
2297 static bfd_reloc_status_type
2298 ppc64_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
2299 input_section
, output_bfd
, error_message
)
2301 arelent
*reloc_entry
;
2304 asection
*input_section
;
2306 char **error_message
;
2308 /* If this is a relocatable link (output_bfd test tells us), just
2309 call the generic function. Any adjustment will be done at final
2311 if (output_bfd
!= NULL
)
2312 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2313 input_section
, output_bfd
, error_message
);
2315 if (error_message
!= NULL
)
2317 static char buf
[60];
2318 sprintf (buf
, "generic linker can't handle %s",
2319 reloc_entry
->howto
->name
);
2320 *error_message
= buf
;
2322 return bfd_reloc_dangerous
;
2325 /* Fix bad default arch selected for a 64 bit input bfd when the
2326 default is 32 bit. */
2329 ppc64_elf_object_p (abfd
)
2332 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2334 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2336 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2338 /* Relies on arch after 32 bit default being 64 bit default. */
2339 abfd
->arch_info
= abfd
->arch_info
->next
;
2340 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2346 /* Merge backend specific data from an object file to the output
2347 object file when linking. */
2350 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
2354 /* Check if we have the same endianess. */
2355 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2356 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2357 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2361 if (bfd_big_endian (ibfd
))
2362 msg
= _("%s: compiled for a big endian system and target is little endian");
2364 msg
= _("%s: compiled for a little endian system and target is big endian");
2366 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
2368 bfd_set_error (bfd_error_wrong_format
);
2375 struct _ppc64_elf_section_data
2377 struct bfd_elf_section_data elf
;
2379 /* An array with one entry for each opd function descriptor. */
2382 /* Points to the function code section for local opd entries. */
2383 asection
**func_sec
;
2384 /* After editing .opd, adjust references to opd local syms. */
2388 /* An array for toc sections, indexed by offset/8.
2389 Specifies the relocation symbol index used at a given toc offset. */
2393 #define ppc64_elf_section_data(sec) \
2394 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2397 ppc64_elf_new_section_hook (abfd
, sec
)
2401 struct _ppc64_elf_section_data
*sdata
;
2402 bfd_size_type amt
= sizeof (*sdata
);
2404 sdata
= (struct _ppc64_elf_section_data
*) bfd_zalloc (abfd
, amt
);
2407 sec
->used_by_bfd
= (PTR
) sdata
;
2409 return _bfd_elf_new_section_hook (abfd
, sec
);
2412 /* The following functions are specific to the ELF linker, while
2413 functions above are used generally. Those named ppc64_elf_* are
2414 called by the main ELF linker code. They appear in this file more
2415 or less in the order in which they are called. eg.
2416 ppc64_elf_check_relocs is called early in the link process,
2417 ppc64_elf_finish_dynamic_sections is one of the last functions
2420 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2421 functions have both a function code symbol and a function descriptor
2422 symbol. A call to foo in a relocatable object file looks like:
2429 The function definition in another object file might be:
2433 . .quad .TOC.@tocbase
2439 When the linker resolves the call during a static link, the branch
2440 unsurprisingly just goes to .foo and the .opd information is unused.
2441 If the function definition is in a shared library, things are a little
2442 different: The call goes via a plt call stub, the opd information gets
2443 copied to the plt, and the linker patches the nop.
2451 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
2452 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
2453 . std 2,40(1) # this is the general idea
2461 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2463 The "reloc ()" notation is supposed to indicate that the linker emits
2464 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2467 What are the difficulties here? Well, firstly, the relocations
2468 examined by the linker in check_relocs are against the function code
2469 sym .foo, while the dynamic relocation in the plt is emitted against
2470 the function descriptor symbol, foo. Somewhere along the line, we need
2471 to carefully copy dynamic link information from one symbol to the other.
2472 Secondly, the generic part of the elf linker will make .foo a dynamic
2473 symbol as is normal for most other backends. We need foo dynamic
2474 instead, at least for an application final link. However, when
2475 creating a shared library containing foo, we need to have both symbols
2476 dynamic so that references to .foo are satisfied during the early
2477 stages of linking. Otherwise the linker might decide to pull in a
2478 definition from some other object, eg. a static library. */
2480 /* The linker needs to keep track of the number of relocs that it
2481 decides to copy as dynamic relocs in check_relocs for each symbol.
2482 This is so that it can later discard them if they are found to be
2483 unnecessary. We store the information in a field extending the
2484 regular ELF linker hash table. */
2486 struct ppc_dyn_relocs
2488 struct ppc_dyn_relocs
*next
;
2490 /* The input section of the reloc. */
2493 /* Total number of relocs copied for the input section. */
2494 bfd_size_type count
;
2496 /* Number of pc-relative relocs copied for the input section. */
2497 bfd_size_type pc_count
;
2500 /* Track GOT entries needed for a given symbol. We might need more
2501 than one got entry per symbol. */
2504 struct got_entry
*next
;
2506 /* The symbol addend that we'll be placing in the GOT. */
2509 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2512 bfd_signed_vma refcount
;
2516 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2517 TLS_TPREL or TLS_DTPREL for tls entries. */
2521 /* The same for PLT. */
2524 struct plt_entry
*next
;
2530 bfd_signed_vma refcount
;
2535 /* Of those relocs that might be copied as dynamic relocs, this macro
2536 selects those that must be copied when linking a shared library,
2537 even when the symbol is local. */
2539 #define MUST_BE_DYN_RELOC(RTYPE) \
2540 ((RTYPE) != R_PPC64_REL32 \
2541 && (RTYPE) != R_PPC64_REL64 \
2542 && (RTYPE) != R_PPC64_REL30)
2544 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2545 copying dynamic variables from a shared lib into an app's dynbss
2546 section, and instead use a dynamic relocation to point into the
2548 #define ELIMINATE_COPY_RELOCS 1
2550 /* Section name for stubs is the associated section name plus this
2552 #define STUB_SUFFIX ".stub"
2555 ppc_stub_long_branch:
2556 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2557 destination, but a 24 bit branch in a stub section will reach.
2560 ppc_stub_plt_branch:
2561 Similar to the above, but a 24 bit branch in the stub section won't
2562 reach its destination.
2563 . addis %r12,%r2,xxx@toc@ha
2564 . ld %r11,xxx@toc@l(%r12)
2569 Used to call a function in a shared library.
2570 . addis %r12,%r2,xxx@toc@ha
2572 . ld %r11,xxx+0@toc@l(%r12)
2573 . ld %r2,xxx+8@toc@l(%r12)
2575 . ld %r11,xxx+16@toc@l(%r12)
2579 enum ppc_stub_type
{
2581 ppc_stub_long_branch
,
2582 ppc_stub_plt_branch
,
2586 struct ppc_stub_hash_entry
{
2588 /* Base hash table entry structure. */
2589 struct bfd_hash_entry root
;
2591 /* The stub section. */
2594 /* Offset within stub_sec of the beginning of this stub. */
2595 bfd_vma stub_offset
;
2597 /* Given the symbol's value and its section we can determine its final
2598 value when building the stubs (so the stub knows where to jump. */
2599 bfd_vma target_value
;
2600 asection
*target_section
;
2602 enum ppc_stub_type stub_type
;
2604 /* The symbol table entry, if any, that this was derived from. */
2605 struct ppc_link_hash_entry
*h
;
2607 /* And the reloc addend that this was derived from. */
2610 /* Where this stub is being called from, or, in the case of combined
2611 stub sections, the first input section in the group. */
2615 struct ppc_branch_hash_entry
{
2617 /* Base hash table entry structure. */
2618 struct bfd_hash_entry root
;
2620 /* Offset within .branch_lt. */
2621 unsigned int offset
;
2623 /* Generation marker. */
2627 struct ppc_link_hash_entry
2629 struct elf_link_hash_entry elf
;
2631 /* A pointer to the most recently used stub hash entry against this
2633 struct ppc_stub_hash_entry
*stub_cache
;
2635 /* Track dynamic relocs copied for this symbol. */
2636 struct ppc_dyn_relocs
*dyn_relocs
;
2638 /* Link between function code and descriptor symbols. */
2639 struct elf_link_hash_entry
*oh
;
2641 /* Flag function code and descriptor symbols. */
2642 unsigned int is_func
:1;
2643 unsigned int is_func_descriptor
:1;
2644 unsigned int is_entry
:1;
2646 /* Contexts in which symbol is used in the GOT (or TOC).
2647 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
2648 corresponding relocs are encountered during check_relocs.
2649 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2650 indicate the corresponding GOT entry type is not needed.
2651 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
2652 a TPREL one. We use a separate flag rather than setting TPREL
2653 just for convenience in distinguishing the two cases. */
2654 #define TLS_GD 1 /* GD reloc. */
2655 #define TLS_LD 2 /* LD reloc. */
2656 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2657 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2658 #define TLS_TLS 16 /* Any TLS reloc. */
2659 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
2660 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2664 /* ppc64 ELF linker hash table. */
2666 struct ppc_link_hash_table
2668 struct elf_link_hash_table elf
;
2670 /* The stub hash table. */
2671 struct bfd_hash_table stub_hash_table
;
2673 /* Another hash table for plt_branch stubs. */
2674 struct bfd_hash_table branch_hash_table
;
2676 /* Linker stub bfd. */
2679 /* Linker call-backs. */
2680 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
2681 void (*layout_sections_again
) PARAMS ((void));
2683 /* Array to keep track of which stub sections have been created, and
2684 information on stub grouping. */
2686 /* This is the section to which stubs in the group will be attached. */
2688 /* The stub section. */
2692 /* Assorted information used by ppc64_elf_size_stubs. */
2694 asection
**input_list
;
2696 /* Short-cuts to get to dynamic linker sections. */
2708 /* Short-cut to first output tls section. */
2711 /* Shortcut to .__tls_get_addr. */
2712 struct elf_link_hash_entry
*tls_get_addr
;
2714 /* TLS local dynamic got entry handling. */
2716 bfd_signed_vma refcount
;
2721 unsigned int stub_error
;
2723 /* Flag set when small branches are detected. Used to
2724 select suitable defaults for the stub group size. */
2725 unsigned int has_14bit_branch
;
2727 /* Set if we detect a reference undefined weak symbol. */
2728 unsigned int have_undefweak
;
2730 /* Incremented every time we size stubs. */
2731 unsigned int stub_iteration
;
2733 /* Small local sym to section mapping cache. */
2734 struct sym_sec_cache sym_sec
;
2737 static struct bfd_hash_entry
*stub_hash_newfunc
2738 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2739 static struct bfd_hash_entry
*branch_hash_newfunc
2740 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2741 static struct bfd_hash_entry
*link_hash_newfunc
2742 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
2743 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
2745 static void ppc64_elf_link_hash_table_free
2746 PARAMS ((struct bfd_link_hash_table
*));
2747 static char *ppc_stub_name
2748 PARAMS ((const asection
*, const asection
*,
2749 const struct ppc_link_hash_entry
*, const Elf_Internal_Rela
*));
2750 static struct ppc_stub_hash_entry
*ppc_get_stub_entry
2751 PARAMS ((const asection
*, const asection
*, struct elf_link_hash_entry
*,
2752 const Elf_Internal_Rela
*, struct ppc_link_hash_table
*));
2753 static struct ppc_stub_hash_entry
*ppc_add_stub
2754 PARAMS ((const char *, asection
*, struct ppc_link_hash_table
*));
2755 static bfd_boolean create_linkage_sections
2756 PARAMS ((bfd
*, struct bfd_link_info
*));
2757 static bfd_boolean create_got_section
2758 PARAMS ((bfd
*, struct bfd_link_info
*));
2759 static bfd_boolean ppc64_elf_create_dynamic_sections
2760 PARAMS ((bfd
*, struct bfd_link_info
*));
2761 static void ppc64_elf_copy_indirect_symbol
2762 PARAMS ((struct elf_backend_data
*, struct elf_link_hash_entry
*,
2763 struct elf_link_hash_entry
*));
2764 static bfd_boolean update_local_sym_info
2765 PARAMS ((bfd
*, Elf_Internal_Shdr
*, unsigned long, bfd_vma
, int));
2766 static bfd_boolean update_plt_info
2767 PARAMS ((bfd
*, struct ppc_link_hash_entry
*, bfd_vma
));
2768 static bfd_boolean ppc64_elf_check_relocs
2769 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2770 const Elf_Internal_Rela
*));
2771 static asection
* ppc64_elf_gc_mark_hook
2772 PARAMS ((asection
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
2773 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
2774 static bfd_boolean ppc64_elf_gc_sweep_hook
2775 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
2776 const Elf_Internal_Rela
*));
2777 static bfd_boolean func_desc_adjust
2778 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2779 static bfd_boolean ppc64_elf_func_desc_adjust
2780 PARAMS ((bfd
*, struct bfd_link_info
*));
2781 static bfd_boolean ppc64_elf_adjust_dynamic_symbol
2782 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
2783 static void ppc64_elf_hide_symbol
2784 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*, bfd_boolean
));
2785 static bfd_boolean get_sym_h
2786 PARAMS ((struct elf_link_hash_entry
**, Elf_Internal_Sym
**, asection
**,
2787 char **, Elf_Internal_Sym
**, unsigned long, bfd
*));
2788 static int get_tls_mask
2789 PARAMS ((char **, Elf_Internal_Sym
**, const Elf_Internal_Rela
*, bfd
*));
2790 static bfd_boolean allocate_dynrelocs
2791 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2792 static bfd_boolean readonly_dynrelocs
2793 PARAMS ((struct elf_link_hash_entry
*, PTR
));
2794 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2795 PARAMS ((const Elf_Internal_Rela
*));
2796 static bfd_boolean ppc64_elf_size_dynamic_sections
2797 PARAMS ((bfd
*, struct bfd_link_info
*));
2798 static enum ppc_stub_type ppc_type_of_stub
2799 PARAMS ((asection
*, const Elf_Internal_Rela
*,
2800 struct ppc_link_hash_entry
**, bfd_vma
));
2801 static bfd_byte
*build_plt_stub
2802 PARAMS ((bfd
*, bfd_byte
*, int, int));
2803 static bfd_boolean ppc_build_one_stub
2804 PARAMS ((struct bfd_hash_entry
*, PTR
));
2805 static bfd_boolean ppc_size_one_stub
2806 PARAMS ((struct bfd_hash_entry
*, PTR
));
2807 static void group_sections
2808 PARAMS ((struct ppc_link_hash_table
*, bfd_size_type
, bfd_boolean
));
2809 static bfd_boolean ppc64_elf_relocate_section
2810 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
2811 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
2813 static bfd_boolean ppc64_elf_finish_dynamic_symbol
2814 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
2815 Elf_Internal_Sym
*));
2816 static bfd_boolean ppc64_elf_finish_dynamic_sections
2817 PARAMS ((bfd
*, struct bfd_link_info
*));
2819 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2821 #define ppc_hash_table(p) \
2822 ((struct ppc_link_hash_table *) ((p)->hash))
2824 #define ppc_stub_hash_lookup(table, string, create, copy) \
2825 ((struct ppc_stub_hash_entry *) \
2826 bfd_hash_lookup ((table), (string), (create), (copy)))
2828 #define ppc_branch_hash_lookup(table, string, create, copy) \
2829 ((struct ppc_branch_hash_entry *) \
2830 bfd_hash_lookup ((table), (string), (create), (copy)))
2832 /* Create an entry in the stub hash table. */
2834 static struct bfd_hash_entry
*
2835 stub_hash_newfunc (entry
, table
, string
)
2836 struct bfd_hash_entry
*entry
;
2837 struct bfd_hash_table
*table
;
2840 /* Allocate the structure if it has not already been allocated by a
2844 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2849 /* Call the allocation method of the superclass. */
2850 entry
= bfd_hash_newfunc (entry
, table
, string
);
2853 struct ppc_stub_hash_entry
*eh
;
2855 /* Initialize the local fields. */
2856 eh
= (struct ppc_stub_hash_entry
*) entry
;
2857 eh
->stub_sec
= NULL
;
2858 eh
->stub_offset
= 0;
2859 eh
->target_value
= 0;
2860 eh
->target_section
= NULL
;
2861 eh
->stub_type
= ppc_stub_none
;
2869 /* Create an entry in the branch hash table. */
2871 static struct bfd_hash_entry
*
2872 branch_hash_newfunc (entry
, table
, string
)
2873 struct bfd_hash_entry
*entry
;
2874 struct bfd_hash_table
*table
;
2877 /* Allocate the structure if it has not already been allocated by a
2881 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2886 /* Call the allocation method of the superclass. */
2887 entry
= bfd_hash_newfunc (entry
, table
, string
);
2890 struct ppc_branch_hash_entry
*eh
;
2892 /* Initialize the local fields. */
2893 eh
= (struct ppc_branch_hash_entry
*) entry
;
2901 /* Create an entry in a ppc64 ELF linker hash table. */
2903 static struct bfd_hash_entry
*
2904 link_hash_newfunc (entry
, table
, string
)
2905 struct bfd_hash_entry
*entry
;
2906 struct bfd_hash_table
*table
;
2909 /* Allocate the structure if it has not already been allocated by a
2913 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2918 /* Call the allocation method of the superclass. */
2919 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2922 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2924 eh
->stub_cache
= NULL
;
2925 eh
->dyn_relocs
= NULL
;
2928 eh
->is_func_descriptor
= 0;
2936 /* Create a ppc64 ELF linker hash table. */
2938 static struct bfd_link_hash_table
*
2939 ppc64_elf_link_hash_table_create (abfd
)
2942 struct ppc_link_hash_table
*htab
;
2943 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2945 htab
= (struct ppc_link_hash_table
*) bfd_malloc (amt
);
2949 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
2955 /* Init the stub hash table too. */
2956 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
2959 /* And the branch hash table. */
2960 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
2963 htab
->stub_bfd
= NULL
;
2964 htab
->add_stub_section
= NULL
;
2965 htab
->layout_sections_again
= NULL
;
2966 htab
->stub_group
= NULL
;
2968 htab
->srelgot
= NULL
;
2970 htab
->srelplt
= NULL
;
2971 htab
->sdynbss
= NULL
;
2972 htab
->srelbss
= NULL
;
2973 htab
->sglink
= NULL
;
2976 htab
->srelbrlt
= NULL
;
2977 htab
->tls_sec
= NULL
;
2978 htab
->tls_get_addr
= NULL
;
2979 htab
->tlsld_got
.refcount
= 0;
2980 htab
->stub_error
= 0;
2981 htab
->has_14bit_branch
= 0;
2982 htab
->have_undefweak
= 0;
2983 htab
->stub_iteration
= 0;
2984 htab
->sym_sec
.abfd
= NULL
;
2985 /* Initializing two fields of the union is just cosmetic. We really
2986 only care about glist, but when compiled on a 32-bit host the
2987 bfd_vma fields are larger. Setting the bfd_vma to zero makes
2988 debugger inspection of these fields look nicer. */
2989 htab
->elf
.init_refcount
.refcount
= 0;
2990 htab
->elf
.init_refcount
.glist
= NULL
;
2991 htab
->elf
.init_offset
.offset
= 0;
2992 htab
->elf
.init_offset
.glist
= NULL
;
2994 return &htab
->elf
.root
;
2997 /* Free the derived linker hash table. */
3000 ppc64_elf_link_hash_table_free (hash
)
3001 struct bfd_link_hash_table
*hash
;
3003 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3005 bfd_hash_table_free (&ret
->stub_hash_table
);
3006 bfd_hash_table_free (&ret
->branch_hash_table
);
3007 _bfd_generic_link_hash_table_free (hash
);
3010 /* Build a name for an entry in the stub hash table. */
3013 ppc_stub_name (input_section
, sym_sec
, h
, rel
)
3014 const asection
*input_section
;
3015 const asection
*sym_sec
;
3016 const struct ppc_link_hash_entry
*h
;
3017 const Elf_Internal_Rela
*rel
;
3022 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3023 offsets from a sym as a branch target? In fact, we could
3024 probably assume the addend is always zero. */
3025 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3029 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3030 stub_name
= bfd_malloc (len
);
3031 if (stub_name
!= NULL
)
3033 sprintf (stub_name
, "%08x_%s+%x",
3034 input_section
->id
& 0xffffffff,
3035 h
->elf
.root
.root
.string
,
3036 (int) rel
->r_addend
& 0xffffffff);
3041 len
= 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
3042 stub_name
= bfd_malloc (len
);
3043 if (stub_name
!= NULL
)
3045 sprintf (stub_name
, "%08x_%x:%x+%x",
3046 input_section
->id
& 0xffffffff,
3047 sym_sec
->id
& 0xffffffff,
3048 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3049 (int) rel
->r_addend
& 0xffffffff);
3055 /* Look up an entry in the stub hash. Stub entries are cached because
3056 creating the stub name takes a bit of time. */
3058 static struct ppc_stub_hash_entry
*
3059 ppc_get_stub_entry (input_section
, sym_sec
, hash
, rel
, htab
)
3060 const asection
*input_section
;
3061 const asection
*sym_sec
;
3062 struct elf_link_hash_entry
*hash
;
3063 const Elf_Internal_Rela
*rel
;
3064 struct ppc_link_hash_table
*htab
;
3066 struct ppc_stub_hash_entry
*stub_entry
;
3067 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
3068 const asection
*id_sec
;
3070 /* If this input section is part of a group of sections sharing one
3071 stub section, then use the id of the first section in the group.
3072 Stub names need to include a section id, as there may well be
3073 more than one stub used to reach say, printf, and we need to
3074 distinguish between them. */
3075 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3077 if (h
!= NULL
&& h
->stub_cache
!= NULL
3078 && h
->stub_cache
->h
== h
3079 && h
->stub_cache
->id_sec
== id_sec
)
3081 stub_entry
= h
->stub_cache
;
3087 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
3088 if (stub_name
== NULL
)
3091 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3092 stub_name
, FALSE
, FALSE
);
3094 h
->stub_cache
= stub_entry
;
3102 /* Add a new stub entry to the stub hash. Not all fields of the new
3103 stub entry are initialised. */
3105 static struct ppc_stub_hash_entry
*
3106 ppc_add_stub (stub_name
, section
, htab
)
3107 const char *stub_name
;
3109 struct ppc_link_hash_table
*htab
;
3113 struct ppc_stub_hash_entry
*stub_entry
;
3115 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3116 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3117 if (stub_sec
== NULL
)
3119 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3120 if (stub_sec
== NULL
)
3126 namelen
= strlen (link_sec
->name
);
3127 len
= namelen
+ sizeof (STUB_SUFFIX
);
3128 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3132 memcpy (s_name
, link_sec
->name
, namelen
);
3133 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3134 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3135 if (stub_sec
== NULL
)
3137 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3139 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3142 /* Enter this entry into the linker stub hash table. */
3143 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3145 if (stub_entry
== NULL
)
3147 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3148 bfd_archive_filename (section
->owner
),
3153 stub_entry
->stub_sec
= stub_sec
;
3154 stub_entry
->stub_offset
= 0;
3155 stub_entry
->id_sec
= link_sec
;
3159 /* Create sections for linker generated code. */
3162 create_linkage_sections (dynobj
, info
)
3164 struct bfd_link_info
*info
;
3166 struct ppc_link_hash_table
*htab
;
3169 htab
= ppc_hash_table (info
);
3171 /* Create .sfpr for code to save and restore fp regs. */
3172 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3173 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3174 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
3175 if (htab
->sfpr
== NULL
3176 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
3177 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3180 /* Create .glink for lazy dynamic linking support. */
3181 htab
->sglink
= bfd_make_section_anyway (dynobj
, ".glink");
3182 if (htab
->sglink
== NULL
3183 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
3184 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 2))
3187 /* Create .branch_lt for plt_branch stubs. */
3188 flags
= (SEC_ALLOC
| SEC_LOAD
3189 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3190 htab
->sbrlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
3191 if (htab
->sbrlt
== NULL
3192 || ! bfd_set_section_flags (dynobj
, htab
->sbrlt
, flags
)
3193 || ! bfd_set_section_alignment (dynobj
, htab
->sbrlt
, 3))
3198 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3199 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3200 htab
->srelbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
3202 || ! bfd_set_section_flags (dynobj
, htab
->srelbrlt
, flags
)
3203 || ! bfd_set_section_alignment (dynobj
, htab
->srelbrlt
, 3))
3209 /* Create .got and .rela.got sections in DYNOBJ, and set up
3210 shortcuts to them in our hash table. */
3213 create_got_section (dynobj
, info
)
3215 struct bfd_link_info
*info
;
3217 struct ppc_link_hash_table
*htab
;
3219 if (! _bfd_elf_create_got_section (dynobj
, info
))
3222 htab
= ppc_hash_table (info
);
3223 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
3227 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
3229 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
3230 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
3231 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
3233 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
3238 /* Create the dynamic sections, and set up shortcuts. */
3241 ppc64_elf_create_dynamic_sections (dynobj
, info
)
3243 struct bfd_link_info
*info
;
3245 struct ppc_link_hash_table
*htab
;
3247 htab
= ppc_hash_table (info
);
3248 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
3251 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3254 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
3255 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3256 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3258 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3260 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
3261 || (!info
->shared
&& !htab
->srelbss
))
3267 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3270 ppc64_elf_copy_indirect_symbol (bed
, dir
, ind
)
3271 struct elf_backend_data
*bed ATTRIBUTE_UNUSED
;
3272 struct elf_link_hash_entry
*dir
, *ind
;
3274 struct ppc_link_hash_entry
*edir
, *eind
;
3277 edir
= (struct ppc_link_hash_entry
*) dir
;
3278 eind
= (struct ppc_link_hash_entry
*) ind
;
3280 /* Copy over any dynamic relocs we may have on the indirect sym. */
3281 if (eind
->dyn_relocs
!= NULL
)
3283 if (edir
->dyn_relocs
!= NULL
)
3285 struct ppc_dyn_relocs
**pp
;
3286 struct ppc_dyn_relocs
*p
;
3288 if (eind
->elf
.root
.type
== bfd_link_hash_indirect
)
3291 /* Add reloc counts against the weak sym to the strong sym
3292 list. Merge any entries against the same section. */
3293 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3295 struct ppc_dyn_relocs
*q
;
3297 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3298 if (q
->sec
== p
->sec
)
3300 q
->pc_count
+= p
->pc_count
;
3301 q
->count
+= p
->count
;
3308 *pp
= edir
->dyn_relocs
;
3311 edir
->dyn_relocs
= eind
->dyn_relocs
;
3312 eind
->dyn_relocs
= NULL
;
3315 edir
->is_func
|= eind
->is_func
;
3316 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3317 edir
->is_entry
|= eind
->is_entry
;
3318 edir
->tls_mask
|= eind
->tls_mask
;
3320 mask
= (ELF_LINK_HASH_REF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
3321 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
| ELF_LINK_NON_GOT_REF
);
3322 /* If called to transfer flags for a weakdef during processing
3323 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
3324 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3325 if (ELIMINATE_COPY_RELOCS
3326 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
3327 && (edir
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
3328 mask
&= ~ELF_LINK_NON_GOT_REF
;
3330 edir
->elf
.elf_link_hash_flags
|= eind
->elf
.elf_link_hash_flags
& mask
;
3332 /* If we were called to copy over info for a weak sym, that's all. */
3333 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3336 /* Copy over got entries that we may have already seen to the
3337 symbol which just became indirect. */
3338 if (eind
->elf
.got
.glist
!= NULL
)
3340 if (edir
->elf
.got
.glist
!= NULL
)
3342 struct got_entry
**entp
;
3343 struct got_entry
*ent
;
3345 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3347 struct got_entry
*dent
;
3349 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3350 if (dent
->addend
== ent
->addend
3351 && dent
->tls_type
== ent
->tls_type
)
3353 dent
->got
.refcount
+= ent
->got
.refcount
;
3360 *entp
= edir
->elf
.got
.glist
;
3363 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3364 eind
->elf
.got
.glist
= NULL
;
3367 /* And plt entries. */
3368 if (eind
->elf
.plt
.plist
!= NULL
)
3370 if (edir
->elf
.plt
.plist
!= NULL
)
3372 struct plt_entry
**entp
;
3373 struct plt_entry
*ent
;
3375 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3377 struct plt_entry
*dent
;
3379 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3380 if (dent
->addend
== ent
->addend
)
3382 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3389 *entp
= edir
->elf
.plt
.plist
;
3392 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
3393 eind
->elf
.plt
.plist
= NULL
;
3396 if (edir
->elf
.dynindx
== -1)
3398 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3399 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3400 eind
->elf
.dynindx
= -1;
3401 eind
->elf
.dynstr_index
= 0;
3404 BFD_ASSERT (eind
->elf
.dynindx
== -1);
3407 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
3408 symbols undefined on the command-line. */
3411 ppc64_elf_mark_entry_syms (info
)
3412 struct bfd_link_info
*info
;
3414 struct ppc_link_hash_table
*htab
;
3415 struct bfd_sym_chain
*sym
;
3417 htab
= ppc_hash_table (info
);
3418 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
3420 struct elf_link_hash_entry
*h
;
3422 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
3424 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
3430 update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, r_addend
, tls_type
)
3432 Elf_Internal_Shdr
*symtab_hdr
;
3433 unsigned long r_symndx
;
3437 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
3438 char *local_got_tls_masks
;
3440 if (local_got_ents
== NULL
)
3442 bfd_size_type size
= symtab_hdr
->sh_info
;
3444 size
*= sizeof (*local_got_ents
) + sizeof (*local_got_tls_masks
);
3445 local_got_ents
= (struct got_entry
**) bfd_zalloc (abfd
, size
);
3446 if (local_got_ents
== NULL
)
3448 elf_local_got_ents (abfd
) = local_got_ents
;
3451 if ((tls_type
& TLS_EXPLICIT
) == 0)
3453 struct got_entry
*ent
;
3455 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
3456 if (ent
->addend
== r_addend
&& ent
->tls_type
== tls_type
)
3460 bfd_size_type amt
= sizeof (*ent
);
3461 ent
= (struct got_entry
*) bfd_alloc (abfd
, amt
);
3464 ent
->next
= local_got_ents
[r_symndx
];
3465 ent
->addend
= r_addend
;
3466 ent
->tls_type
= tls_type
;
3467 ent
->got
.refcount
= 0;
3468 local_got_ents
[r_symndx
] = ent
;
3470 ent
->got
.refcount
+= 1;
3473 local_got_tls_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
3474 local_got_tls_masks
[r_symndx
] |= tls_type
;
3479 update_plt_info (abfd
, eh
, addend
)
3481 struct ppc_link_hash_entry
*eh
;
3484 struct plt_entry
*ent
;
3486 for (ent
= eh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
3487 if (ent
->addend
== addend
)
3491 bfd_size_type amt
= sizeof (*ent
);
3492 ent
= (struct plt_entry
*) bfd_alloc (abfd
, amt
);
3495 ent
->next
= eh
->elf
.plt
.plist
;
3496 ent
->addend
= addend
;
3497 ent
->plt
.refcount
= 0;
3498 eh
->elf
.plt
.plist
= ent
;
3500 ent
->plt
.refcount
+= 1;
3501 eh
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3506 /* Look through the relocs for a section during the first phase, and
3507 calculate needed space in the global offset table, procedure
3508 linkage table, and dynamic reloc sections. */
3511 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
3513 struct bfd_link_info
*info
;
3515 const Elf_Internal_Rela
*relocs
;
3517 struct ppc_link_hash_table
*htab
;
3518 Elf_Internal_Shdr
*symtab_hdr
;
3519 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
3520 const Elf_Internal_Rela
*rel
;
3521 const Elf_Internal_Rela
*rel_end
;
3523 asection
**opd_sym_map
;
3525 if (info
->relocateable
)
3528 htab
= ppc_hash_table (info
);
3529 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3531 sym_hashes
= elf_sym_hashes (abfd
);
3532 sym_hashes_end
= (sym_hashes
3533 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
3534 - symtab_hdr
->sh_info
);
3538 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
3540 /* Garbage collection needs some extra help with .opd sections.
3541 We don't want to necessarily keep everything referenced by
3542 relocs in .opd, as that would keep all functions. Instead,
3543 if we reference an .opd symbol (a function descriptor), we
3544 want to keep the function code symbol's section. This is
3545 easy for global symbols, but for local syms we need to keep
3546 information about the associated function section. Later, if
3547 edit_opd deletes entries, we'll use this array to adjust
3548 local syms in .opd. */
3550 asection
*func_section
;
3555 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
3556 opd_sym_map
= (asection
**) bfd_zalloc (abfd
, amt
);
3557 if (opd_sym_map
== NULL
)
3559 ppc64_elf_section_data (sec
)->opd
.func_sec
= opd_sym_map
;
3562 if (htab
->elf
.dynobj
== NULL
)
3563 htab
->elf
.dynobj
= abfd
;
3564 if (htab
->sfpr
== NULL
3565 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
3568 rel_end
= relocs
+ sec
->reloc_count
;
3569 for (rel
= relocs
; rel
< rel_end
; rel
++)
3571 unsigned long r_symndx
;
3572 struct elf_link_hash_entry
*h
;
3573 enum elf_ppc64_reloc_type r_type
;
3576 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3577 if (r_symndx
< symtab_hdr
->sh_info
)
3580 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3582 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3585 case R_PPC64_GOT_TLSLD16
:
3586 case R_PPC64_GOT_TLSLD16_LO
:
3587 case R_PPC64_GOT_TLSLD16_HI
:
3588 case R_PPC64_GOT_TLSLD16_HA
:
3589 htab
->tlsld_got
.refcount
+= 1;
3590 tls_type
= TLS_TLS
| TLS_LD
;
3593 case R_PPC64_GOT_TLSGD16
:
3594 case R_PPC64_GOT_TLSGD16_LO
:
3595 case R_PPC64_GOT_TLSGD16_HI
:
3596 case R_PPC64_GOT_TLSGD16_HA
:
3597 tls_type
= TLS_TLS
| TLS_GD
;
3600 case R_PPC64_GOT_TPREL16_DS
:
3601 case R_PPC64_GOT_TPREL16_LO_DS
:
3602 case R_PPC64_GOT_TPREL16_HI
:
3603 case R_PPC64_GOT_TPREL16_HA
:
3605 info
->flags
|= DF_STATIC_TLS
;
3606 tls_type
= TLS_TLS
| TLS_TPREL
;
3609 case R_PPC64_GOT_DTPREL16_DS
:
3610 case R_PPC64_GOT_DTPREL16_LO_DS
:
3611 case R_PPC64_GOT_DTPREL16_HI
:
3612 case R_PPC64_GOT_DTPREL16_HA
:
3613 tls_type
= TLS_TLS
| TLS_DTPREL
;
3615 sec
->has_tls_reloc
= 1;
3619 case R_PPC64_GOT16_DS
:
3620 case R_PPC64_GOT16_HA
:
3621 case R_PPC64_GOT16_HI
:
3622 case R_PPC64_GOT16_LO
:
3623 case R_PPC64_GOT16_LO_DS
:
3624 /* This symbol requires a global offset table entry. */
3625 if (htab
->sgot
== NULL
3626 && !create_got_section (htab
->elf
.dynobj
, info
))
3631 struct ppc_link_hash_entry
*eh
;
3632 struct got_entry
*ent
;
3634 eh
= (struct ppc_link_hash_entry
*) h
;
3635 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
3636 if (ent
->addend
== rel
->r_addend
3637 && ent
->tls_type
== tls_type
)
3641 bfd_size_type amt
= sizeof (*ent
);
3642 ent
= (struct got_entry
*) bfd_alloc (abfd
, amt
);
3645 ent
->next
= eh
->elf
.got
.glist
;
3646 ent
->addend
= rel
->r_addend
;
3647 ent
->tls_type
= tls_type
;
3648 ent
->got
.refcount
= 0;
3649 eh
->elf
.got
.glist
= ent
;
3651 ent
->got
.refcount
+= 1;
3652 eh
->tls_mask
|= tls_type
;
3655 /* This is a global offset table entry for a local symbol. */
3656 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3657 rel
->r_addend
, tls_type
))
3661 case R_PPC64_PLT16_HA
:
3662 case R_PPC64_PLT16_HI
:
3663 case R_PPC64_PLT16_LO
:
3666 /* This symbol requires a procedure linkage table entry. We
3667 actually build the entry in adjust_dynamic_symbol,
3668 because this might be a case of linking PIC code without
3669 linking in any dynamic objects, in which case we don't
3670 need to generate a procedure linkage table after all. */
3673 /* It does not make sense to have a procedure linkage
3674 table entry for a local symbol. */
3675 bfd_set_error (bfd_error_bad_value
);
3679 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
3684 /* The following relocations don't need to propagate the
3685 relocation if linking a shared object since they are
3686 section relative. */
3687 case R_PPC64_SECTOFF
:
3688 case R_PPC64_SECTOFF_LO
:
3689 case R_PPC64_SECTOFF_HI
:
3690 case R_PPC64_SECTOFF_HA
:
3691 case R_PPC64_SECTOFF_DS
:
3692 case R_PPC64_SECTOFF_LO_DS
:
3694 case R_PPC64_TOC16_LO
:
3695 case R_PPC64_TOC16_HI
:
3696 case R_PPC64_TOC16_HA
:
3697 case R_PPC64_TOC16_DS
:
3698 case R_PPC64_TOC16_LO_DS
:
3699 case R_PPC64_DTPREL16
:
3700 case R_PPC64_DTPREL16_LO
:
3701 case R_PPC64_DTPREL16_HI
:
3702 case R_PPC64_DTPREL16_HA
:
3703 case R_PPC64_DTPREL16_DS
:
3704 case R_PPC64_DTPREL16_LO_DS
:
3705 case R_PPC64_DTPREL16_HIGHER
:
3706 case R_PPC64_DTPREL16_HIGHERA
:
3707 case R_PPC64_DTPREL16_HIGHEST
:
3708 case R_PPC64_DTPREL16_HIGHESTA
:
3711 /* This relocation describes the C++ object vtable hierarchy.
3712 Reconstruct it for later use during GC. */
3713 case R_PPC64_GNU_VTINHERIT
:
3714 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3718 /* This relocation describes which C++ vtable entries are actually
3719 used. Record for later use during GC. */
3720 case R_PPC64_GNU_VTENTRY
:
3721 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3726 case R_PPC64_REL14_BRTAKEN
:
3727 case R_PPC64_REL14_BRNTAKEN
:
3728 htab
->has_14bit_branch
= 1;
3733 && h
->root
.root
.string
[0] == '.'
3734 && h
->root
.root
.string
[1] != 0)
3736 /* We may need a .plt entry if the function this reloc
3737 refers to is in a shared lib. */
3738 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
3741 if (h
== htab
->tls_get_addr
)
3742 sec
->has_tls_reloc
= 1;
3743 else if ((strncmp (h
->root
.root
.string
, ".__tls_get_addr", 15)
3745 && (h
->root
.root
.string
[15] == 0
3746 || h
->root
.root
.string
[15] == '@'))
3748 htab
->tls_get_addr
= h
;
3749 sec
->has_tls_reloc
= 1;
3754 case R_PPC64_TPREL64
:
3755 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
3757 info
->flags
|= DF_STATIC_TLS
;
3760 case R_PPC64_DTPMOD64
:
3761 if (rel
+ 1 < rel_end
3762 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
3763 && rel
[1].r_offset
== rel
->r_offset
+ 8)
3764 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
3766 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
3769 case R_PPC64_DTPREL64
:
3770 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
3772 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
3773 && rel
[-1].r_offset
== rel
->r_offset
- 8)
3774 /* This is the second reloc of a dtpmod, dtprel pair.
3775 Don't mark with TLS_DTPREL. */
3779 sec
->has_tls_reloc
= 1;
3782 struct ppc_link_hash_entry
*eh
;
3783 eh
= (struct ppc_link_hash_entry
*) h
;
3784 eh
->tls_mask
|= tls_type
;
3787 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3788 rel
->r_addend
, tls_type
))
3791 if (ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
3793 /* One extra to simplify get_tls_mask. */
3794 bfd_size_type amt
= sec
->_raw_size
* sizeof (unsigned) / 8 + 1;
3795 ppc64_elf_section_data (sec
)->t_symndx
3796 = (unsigned *) bfd_zalloc (abfd
, amt
);
3797 if (ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
3800 BFD_ASSERT (rel
->r_offset
% 8 == 0);
3801 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8] = r_symndx
;
3803 /* Mark the second slot of a GD or LD entry.
3804 -1 to indicate GD and -2 to indicate LD. */
3805 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
3806 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8 + 1] = -1;
3807 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
3808 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8 + 1] = -2;
3811 case R_PPC64_TPREL16
:
3812 case R_PPC64_TPREL16_LO
:
3813 case R_PPC64_TPREL16_HI
:
3814 case R_PPC64_TPREL16_HA
:
3815 case R_PPC64_TPREL16_DS
:
3816 case R_PPC64_TPREL16_LO_DS
:
3817 case R_PPC64_TPREL16_HIGHER
:
3818 case R_PPC64_TPREL16_HIGHERA
:
3819 case R_PPC64_TPREL16_HIGHEST
:
3820 case R_PPC64_TPREL16_HIGHESTA
:
3823 info
->flags
|= DF_STATIC_TLS
;
3828 case R_PPC64_ADDR64
:
3829 if (opd_sym_map
!= NULL
3831 && h
->root
.root
.string
[0] == '.'
3832 && h
->root
.root
.string
[1] != 0)
3834 struct elf_link_hash_entry
*fdh
;
3836 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
3837 FALSE
, FALSE
, FALSE
);
3840 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
3841 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
3842 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
3843 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
3846 if (opd_sym_map
!= NULL
3848 && rel
+ 1 < rel_end
3849 && ((enum elf_ppc64_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
)
3854 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
3859 opd_sym_map
[rel
->r_offset
/ 24] = s
;
3866 case R_PPC64_ADDR14
:
3867 case R_PPC64_ADDR14_BRNTAKEN
:
3868 case R_PPC64_ADDR14_BRTAKEN
:
3869 case R_PPC64_ADDR16
:
3870 case R_PPC64_ADDR16_DS
:
3871 case R_PPC64_ADDR16_HA
:
3872 case R_PPC64_ADDR16_HI
:
3873 case R_PPC64_ADDR16_HIGHER
:
3874 case R_PPC64_ADDR16_HIGHERA
:
3875 case R_PPC64_ADDR16_HIGHEST
:
3876 case R_PPC64_ADDR16_HIGHESTA
:
3877 case R_PPC64_ADDR16_LO
:
3878 case R_PPC64_ADDR16_LO_DS
:
3879 case R_PPC64_ADDR24
:
3880 case R_PPC64_ADDR32
:
3881 case R_PPC64_UADDR16
:
3882 case R_PPC64_UADDR32
:
3883 case R_PPC64_UADDR64
:
3885 if (h
!= NULL
&& !info
->shared
)
3886 /* We may need a copy reloc. */
3887 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3889 /* Don't propagate .opd relocs. */
3890 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
3893 /* Don't propagate relocs that the dynamic linker won't relocate. */
3894 if ((sec
->flags
& SEC_ALLOC
) == 0)
3897 /* If we are creating a shared library, and this is a reloc
3898 against a global symbol, or a non PC relative reloc
3899 against a local symbol, then we need to copy the reloc
3900 into the shared library. However, if we are linking with
3901 -Bsymbolic, we do not need to copy a reloc against a
3902 global symbol which is defined in an object we are
3903 including in the link (i.e., DEF_REGULAR is set). At
3904 this point we have not seen all the input files, so it is
3905 possible that DEF_REGULAR is not set now but will be set
3906 later (it is never cleared). In case of a weak definition,
3907 DEF_REGULAR may be cleared later by a strong definition in
3908 a shared library. We account for that possibility below by
3909 storing information in the dyn_relocs field of the hash
3910 table entry. A similar situation occurs when creating
3911 shared libraries and symbol visibility changes render the
3914 If on the other hand, we are creating an executable, we
3915 may need to keep relocations for symbols satisfied by a
3916 dynamic library if we manage to avoid copy relocs for the
3920 && (MUST_BE_DYN_RELOC (r_type
)
3922 && (! info
->symbolic
3923 || h
->root
.type
== bfd_link_hash_defweak
3924 || (h
->elf_link_hash_flags
3925 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3926 || (ELIMINATE_COPY_RELOCS
3929 && (h
->root
.type
== bfd_link_hash_defweak
3930 || (h
->elf_link_hash_flags
3931 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3933 struct ppc_dyn_relocs
*p
;
3934 struct ppc_dyn_relocs
**head
;
3936 /* We must copy these reloc types into the output file.
3937 Create a reloc section in dynobj and make room for
3944 name
= (bfd_elf_string_from_elf_section
3946 elf_elfheader (abfd
)->e_shstrndx
,
3947 elf_section_data (sec
)->rel_hdr
.sh_name
));
3951 if (strncmp (name
, ".rela", 5) != 0
3952 || strcmp (bfd_get_section_name (abfd
, sec
),
3955 (*_bfd_error_handler
)
3956 (_("%s: bad relocation section name `%s\'"),
3957 bfd_archive_filename (abfd
), name
);
3958 bfd_set_error (bfd_error_bad_value
);
3961 dynobj
= htab
->elf
.dynobj
;
3962 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3967 sreloc
= bfd_make_section (dynobj
, name
);
3968 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3969 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3970 if ((sec
->flags
& SEC_ALLOC
) != 0)
3971 flags
|= SEC_ALLOC
| SEC_LOAD
;
3973 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
3974 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
3977 elf_section_data (sec
)->sreloc
= sreloc
;
3980 /* If this is a global symbol, we count the number of
3981 relocations we need for this symbol. */
3984 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
3988 /* Track dynamic relocs needed for local syms too.
3989 We really need local syms available to do this
3993 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3998 head
= ((struct ppc_dyn_relocs
**)
3999 &elf_section_data (s
)->local_dynrel
);
4003 if (p
== NULL
|| p
->sec
!= sec
)
4005 p
= ((struct ppc_dyn_relocs
*)
4006 bfd_alloc (htab
->elf
.dynobj
,
4007 (bfd_size_type
) sizeof *p
));
4018 if (!MUST_BE_DYN_RELOC (r_type
))
4031 /* Return the section that should be marked against GC for a given
4035 ppc64_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
4037 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
4038 Elf_Internal_Rela
*rel
;
4039 struct elf_link_hash_entry
*h
;
4040 Elf_Internal_Sym
*sym
;
4042 asection
*rsec
= NULL
;
4046 enum elf_ppc64_reloc_type r_type
;
4047 struct ppc_link_hash_entry
*fdh
;
4049 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
4052 case R_PPC64_GNU_VTINHERIT
:
4053 case R_PPC64_GNU_VTENTRY
:
4057 switch (h
->root
.type
)
4059 case bfd_link_hash_defined
:
4060 case bfd_link_hash_defweak
:
4061 fdh
= (struct ppc_link_hash_entry
*) h
;
4063 /* Function descriptor syms cause the associated
4064 function code sym section to be marked. */
4065 if (fdh
->is_func_descriptor
)
4066 rsec
= fdh
->oh
->root
.u
.def
.section
;
4068 /* Function entry syms return NULL if they are in .opd
4069 and are not ._start (or others undefined on the ld
4070 command line). Thus we avoid marking all function
4071 sections, as all functions are referenced in .opd. */
4072 else if ((fdh
->oh
!= NULL
4073 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
4074 || ppc64_elf_section_data (sec
)->opd
.func_sec
== NULL
)
4075 rsec
= h
->root
.u
.def
.section
;
4078 case bfd_link_hash_common
:
4079 rsec
= h
->root
.u
.c
.p
->section
;
4089 asection
**opd_sym_section
;
4091 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4092 opd_sym_section
= ppc64_elf_section_data (rsec
)->opd
.func_sec
;
4093 if (opd_sym_section
!= NULL
)
4094 rsec
= opd_sym_section
[sym
->st_value
/ 24];
4095 else if (ppc64_elf_section_data (sec
)->opd
.func_sec
!= NULL
)
4102 /* Update the .got, .plt. and dynamic reloc reference counts for the
4103 section being removed. */
4106 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
4108 struct bfd_link_info
*info
;
4110 const Elf_Internal_Rela
*relocs
;
4112 struct ppc_link_hash_table
*htab
;
4113 Elf_Internal_Shdr
*symtab_hdr
;
4114 struct elf_link_hash_entry
**sym_hashes
;
4115 struct got_entry
**local_got_ents
;
4116 const Elf_Internal_Rela
*rel
, *relend
;
4118 elf_section_data (sec
)->local_dynrel
= NULL
;
4120 htab
= ppc_hash_table (info
);
4121 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4122 sym_hashes
= elf_sym_hashes (abfd
);
4123 local_got_ents
= elf_local_got_ents (abfd
);
4125 relend
= relocs
+ sec
->reloc_count
;
4126 for (rel
= relocs
; rel
< relend
; rel
++)
4128 unsigned long r_symndx
;
4129 enum elf_ppc64_reloc_type r_type
;
4130 struct elf_link_hash_entry
*h
= NULL
;
4133 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4134 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
4135 if (r_symndx
>= symtab_hdr
->sh_info
)
4137 struct ppc_link_hash_entry
*eh
;
4138 struct ppc_dyn_relocs
**pp
;
4139 struct ppc_dyn_relocs
*p
;
4141 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4142 eh
= (struct ppc_link_hash_entry
*) h
;
4144 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4147 /* Everything must go for SEC. */
4155 case R_PPC64_GOT_TLSLD16
:
4156 case R_PPC64_GOT_TLSLD16_LO
:
4157 case R_PPC64_GOT_TLSLD16_HI
:
4158 case R_PPC64_GOT_TLSLD16_HA
:
4159 htab
->tlsld_got
.refcount
-= 1;
4160 tls_type
= TLS_TLS
| TLS_LD
;
4163 case R_PPC64_GOT_TLSGD16
:
4164 case R_PPC64_GOT_TLSGD16_LO
:
4165 case R_PPC64_GOT_TLSGD16_HI
:
4166 case R_PPC64_GOT_TLSGD16_HA
:
4167 tls_type
= TLS_TLS
| TLS_GD
;
4170 case R_PPC64_GOT_TPREL16_DS
:
4171 case R_PPC64_GOT_TPREL16_LO_DS
:
4172 case R_PPC64_GOT_TPREL16_HI
:
4173 case R_PPC64_GOT_TPREL16_HA
:
4174 tls_type
= TLS_TLS
| TLS_TPREL
;
4177 case R_PPC64_GOT_DTPREL16_DS
:
4178 case R_PPC64_GOT_DTPREL16_LO_DS
:
4179 case R_PPC64_GOT_DTPREL16_HI
:
4180 case R_PPC64_GOT_DTPREL16_HA
:
4181 tls_type
= TLS_TLS
| TLS_DTPREL
;
4185 case R_PPC64_GOT16_DS
:
4186 case R_PPC64_GOT16_HA
:
4187 case R_PPC64_GOT16_HI
:
4188 case R_PPC64_GOT16_LO
:
4189 case R_PPC64_GOT16_LO_DS
:
4192 struct got_entry
*ent
;
4197 ent
= local_got_ents
[r_symndx
];
4199 for (; ent
!= NULL
; ent
= ent
->next
)
4200 if (ent
->addend
== rel
->r_addend
4201 && ent
->tls_type
== tls_type
)
4205 if (ent
->got
.refcount
> 0)
4206 ent
->got
.refcount
-= 1;
4210 case R_PPC64_PLT16_HA
:
4211 case R_PPC64_PLT16_HI
:
4212 case R_PPC64_PLT16_LO
:
4216 case R_PPC64_REL14_BRNTAKEN
:
4217 case R_PPC64_REL14_BRTAKEN
:
4221 struct plt_entry
*ent
;
4223 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4224 if (ent
->addend
== rel
->r_addend
)
4228 if (ent
->plt
.refcount
> 0)
4229 ent
->plt
.refcount
-= 1;
4240 /* Called via elf_link_hash_traverse to transfer dynamic linking
4241 information on function code symbol entries to their corresponding
4242 function descriptor symbol entries. */
4244 func_desc_adjust (h
, inf
)
4245 struct elf_link_hash_entry
*h
;
4248 struct bfd_link_info
*info
;
4249 struct ppc_link_hash_table
*htab
;
4250 struct plt_entry
*ent
;
4252 if (h
->root
.type
== bfd_link_hash_indirect
)
4255 if (h
->root
.type
== bfd_link_hash_warning
)
4256 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4258 info
= (struct bfd_link_info
*) inf
;
4259 htab
= ppc_hash_table (info
);
4261 /* If this is a function code symbol, transfer dynamic linking
4262 information to the function descriptor symbol. */
4263 if (!((struct ppc_link_hash_entry
*) h
)->is_func
)
4266 if (h
->root
.type
== bfd_link_hash_undefweak
4267 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
4268 htab
->have_undefweak
= TRUE
;
4270 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4271 if (ent
->plt
.refcount
> 0)
4274 && h
->root
.root
.string
[0] == '.'
4275 && h
->root
.root
.string
[1] != '\0')
4277 struct elf_link_hash_entry
*fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
4278 bfd_boolean force_local
;
4280 /* Find the corresponding function descriptor symbol. Create it
4281 as undefined if necessary. */
4284 fdh
= elf_link_hash_lookup (&htab
->elf
, h
->root
.root
.string
+ 1,
4285 FALSE
, FALSE
, TRUE
);
4289 && (h
->root
.type
== bfd_link_hash_undefined
4290 || h
->root
.type
== bfd_link_hash_undefweak
))
4294 struct bfd_link_hash_entry
*bh
;
4296 abfd
= h
->root
.u
.undef
.abfd
;
4297 newsym
= bfd_make_empty_symbol (abfd
);
4298 newsym
->name
= h
->root
.root
.string
+ 1;
4299 newsym
->section
= bfd_und_section_ptr
;
4301 newsym
->flags
= BSF_OBJECT
;
4302 if (h
->root
.type
== bfd_link_hash_undefweak
)
4303 newsym
->flags
|= BSF_WEAK
;
4306 if ( !(_bfd_generic_link_add_one_symbol
4307 (info
, abfd
, newsym
->name
, newsym
->flags
,
4308 newsym
->section
, newsym
->value
, NULL
, FALSE
, FALSE
, &bh
)))
4312 fdh
= (struct elf_link_hash_entry
*) bh
;
4313 fdh
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4317 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
4319 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4320 || (fdh
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
4322 if (fdh
->dynindx
== -1)
4323 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
4325 fdh
->elf_link_hash_flags
|= (h
->elf_link_hash_flags
4326 & (ELF_LINK_HASH_REF_REGULAR
4327 | ELF_LINK_HASH_REF_DYNAMIC
4328 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
4329 | ELF_LINK_NON_GOT_REF
));
4330 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4332 fdh
->plt
.plist
= h
->plt
.plist
;
4333 fdh
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4335 ((struct ppc_link_hash_entry
*) fdh
)->is_func_descriptor
= 1;
4336 ((struct ppc_link_hash_entry
*) fdh
)->oh
= h
;
4337 ((struct ppc_link_hash_entry
*) h
)->oh
= fdh
;
4340 /* Now that the info is on the function descriptor, clear the
4341 function code sym info. Any function code syms for which we
4342 don't have a definition in a regular file, we force local.
4343 This prevents a shared library from exporting syms that have
4344 been imported from another library. Function code syms that
4345 are really in the library we must leave global to prevent the
4346 linker dragging in a definition from a static library. */
4347 force_local
= (info
->shared
4348 && ((h
->elf_link_hash_flags
4349 & ELF_LINK_HASH_DEF_REGULAR
) == 0
4351 || (fdh
->elf_link_hash_flags
4352 & ELF_LINK_HASH_DEF_REGULAR
) == 0
4353 || (fdh
->elf_link_hash_flags
4354 & ELF_LINK_FORCED_LOCAL
) != 0));
4355 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
4361 #define MIN_SAVE_FPR 14
4362 #define MAX_SAVE_FPR 31
4364 /* Called near the start of bfd_elf_size_dynamic_sections. We use
4365 this hook to a) provide some gcc support functions, and b) transfer
4366 dynamic linking information gathered so far on function code symbol
4367 entries, to their corresponding function descriptor symbol entries. */
4369 ppc64_elf_func_desc_adjust (obfd
, info
)
4370 bfd
*obfd ATTRIBUTE_UNUSED
;
4371 struct bfd_link_info
*info
;
4373 struct ppc_link_hash_table
*htab
;
4374 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
4375 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
4377 struct elf_link_hash_entry
*h
;
4381 htab
= ppc_hash_table (info
);
4383 if (htab
->sfpr
== NULL
)
4384 /* We don't have any relocs. */
4387 /* First provide any missing ._savef* and ._restf* functions. */
4388 memcpy (sym
, "._savef14", 10);
4389 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
4391 sym
[7] = i
/ 10 + '0';
4392 sym
[8] = i
% 10 + '0';
4393 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
4395 && h
->root
.type
== bfd_link_hash_undefined
)
4397 if (lowest_savef
> i
)
4399 h
->root
.type
= bfd_link_hash_defined
;
4400 h
->root
.u
.def
.section
= htab
->sfpr
;
4401 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
4403 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4404 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
4408 memcpy (sym
, "._restf14", 10);
4409 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
4411 sym
[7] = i
/ 10 + '0';
4412 sym
[8] = i
% 10 + '0';
4413 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
4415 && h
->root
.type
== bfd_link_hash_undefined
)
4417 if (lowest_restf
> i
)
4419 h
->root
.type
= bfd_link_hash_defined
;
4420 h
->root
.u
.def
.section
= htab
->sfpr
;
4421 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
4422 + (i
- lowest_restf
) * 4);
4424 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4425 _bfd_elf_link_hash_hide_symbol (info
, h
, info
->shared
);
4429 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, (PTR
) info
);
4431 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
4432 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
4434 if (htab
->sfpr
->_raw_size
== 0)
4436 if (!htab
->have_undefweak
)
4438 _bfd_strip_section_from_output (info
, htab
->sfpr
);
4442 htab
->sfpr
->_raw_size
= 4;
4445 p
= (bfd_byte
*) bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
4448 htab
->sfpr
->contents
= p
;
4450 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
4452 unsigned int fpr
= i
<< 21;
4453 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
4454 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
4457 if (lowest_savef
<= MAX_SAVE_FPR
)
4459 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
4463 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
4465 unsigned int fpr
= i
<< 21;
4466 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
4467 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
4470 if (lowest_restf
<= MAX_SAVE_FPR
4471 || htab
->sfpr
->_raw_size
== 4)
4473 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
4479 /* Adjust a symbol defined by a dynamic object and referenced by a
4480 regular object. The current definition is in some section of the
4481 dynamic object, but we're not including those sections. We have to
4482 change the definition to something the rest of the link can
4486 ppc64_elf_adjust_dynamic_symbol (info
, h
)
4487 struct bfd_link_info
*info
;
4488 struct elf_link_hash_entry
*h
;
4490 struct ppc_link_hash_table
*htab
;
4492 unsigned int power_of_two
;
4494 htab
= ppc_hash_table (info
);
4496 /* Deal with function syms. */
4497 if (h
->type
== STT_FUNC
4498 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4500 /* Clear procedure linkage table information for any symbol that
4501 won't need a .plt entry. */
4502 struct plt_entry
*ent
;
4503 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4504 if (ent
->plt
.refcount
> 0)
4506 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
4508 || SYMBOL_CALLS_LOCAL (info
, h
)
4509 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4510 && h
->root
.type
== bfd_link_hash_undefweak
))
4512 h
->plt
.plist
= NULL
;
4513 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4517 h
->plt
.plist
= NULL
;
4519 /* If this is a weak symbol, and there is a real definition, the
4520 processor independent code will have arranged for us to see the
4521 real definition first, and we can just use the same value. */
4522 if (h
->weakdef
!= NULL
)
4524 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4525 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4526 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4527 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4528 if (ELIMINATE_COPY_RELOCS
)
4529 h
->elf_link_hash_flags
4530 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
4531 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
4535 /* This is a reference to a symbol defined by a dynamic object which
4536 is not a function. */
4538 /* If we are creating a shared library, we must presume that the
4539 only references to the symbol are via the global offset table.
4540 For such cases we need not do anything here; the relocations will
4541 be handled correctly by relocate_section. */
4545 /* If there are no references to this symbol that do not use the
4546 GOT, we don't need to generate a copy reloc. */
4547 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
4550 if (ELIMINATE_COPY_RELOCS
)
4552 struct ppc_link_hash_entry
* eh
;
4553 struct ppc_dyn_relocs
*p
;
4555 eh
= (struct ppc_link_hash_entry
*) h
;
4556 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4558 s
= p
->sec
->output_section
;
4559 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4563 /* If we didn't find any dynamic relocs in read-only sections, then
4564 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4567 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4572 /* We must allocate the symbol in our .dynbss section, which will
4573 become part of the .bss section of the executable. There will be
4574 an entry for this symbol in the .dynsym section. The dynamic
4575 object will contain position independent code, so all references
4576 from the dynamic object to this symbol will go through the global
4577 offset table. The dynamic linker will use the .dynsym entry to
4578 determine the address it must put in the global offset table, so
4579 both the dynamic object and the regular object will refer to the
4580 same memory location for the variable. */
4582 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
4583 to copy the initial value out of the dynamic object and into the
4584 runtime process image. We need to remember the offset into the
4585 .rela.bss section we are going to use. */
4586 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4588 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
4589 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
4592 /* We need to figure out the alignment required for this symbol. I
4593 have no idea how ELF linkers handle this. */
4594 power_of_two
= bfd_log2 (h
->size
);
4595 if (power_of_two
> 4)
4598 /* Apply the required alignment. */
4600 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
4601 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
4603 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
4607 /* Define the symbol as being at this point in the section. */
4608 h
->root
.u
.def
.section
= s
;
4609 h
->root
.u
.def
.value
= s
->_raw_size
;
4611 /* Increment the section size to make room for the symbol. */
4612 s
->_raw_size
+= h
->size
;
4617 /* If given a function descriptor symbol, hide both the function code
4618 sym and the descriptor. */
4620 ppc64_elf_hide_symbol (info
, h
, force_local
)
4621 struct bfd_link_info
*info
;
4622 struct elf_link_hash_entry
*h
;
4623 bfd_boolean force_local
;
4625 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
4627 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
4629 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
4634 struct ppc_link_hash_table
*htab
;
4637 /* We aren't supposed to use alloca in BFD because on
4638 systems which do not have alloca the version in libiberty
4639 calls xmalloc, which might cause the program to crash
4640 when it runs out of memory. This function doesn't have a
4641 return status, so there's no way to gracefully return an
4642 error. So cheat. We know that string[-1] can be safely
4643 dereferenced; It's either a string in an ELF string
4644 table, or allocated in an objalloc structure. */
4646 p
= h
->root
.root
.string
- 1;
4649 htab
= ppc_hash_table (info
);
4650 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
4653 /* Unfortunately, if it so happens that the string we were
4654 looking for was allocated immediately before this string,
4655 then we overwrote the string terminator. That's the only
4656 reason the lookup should fail. */
4659 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
4660 while (q
>= h
->root
.root
.string
&& *q
== *p
)
4662 if (q
< h
->root
.root
.string
&& *p
== '.')
4663 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
4667 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
4668 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
4672 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
4677 get_sym_h (hp
, symp
, symsecp
, tls_maskp
, locsymsp
, r_symndx
, ibfd
)
4678 struct elf_link_hash_entry
**hp
;
4679 Elf_Internal_Sym
**symp
;
4682 Elf_Internal_Sym
**locsymsp
;
4683 unsigned long r_symndx
;
4686 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4688 if (r_symndx
>= symtab_hdr
->sh_info
)
4690 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4691 struct elf_link_hash_entry
*h
;
4693 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4694 while (h
->root
.type
== bfd_link_hash_indirect
4695 || h
->root
.type
== bfd_link_hash_warning
)
4696 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4704 if (symsecp
!= NULL
)
4706 asection
*symsec
= NULL
;
4707 if (h
->root
.type
== bfd_link_hash_defined
4708 || h
->root
.type
== bfd_link_hash_defweak
)
4709 symsec
= h
->root
.u
.def
.section
;
4713 if (tls_maskp
!= NULL
)
4715 struct ppc_link_hash_entry
*eh
;
4717 eh
= (struct ppc_link_hash_entry
*) h
;
4718 *tls_maskp
= &eh
->tls_mask
;
4723 Elf_Internal_Sym
*sym
;
4724 Elf_Internal_Sym
*locsyms
= *locsymsp
;
4726 if (locsyms
== NULL
)
4728 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4729 if (locsyms
== NULL
)
4730 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4731 symtab_hdr
->sh_info
,
4732 0, NULL
, NULL
, NULL
);
4733 if (locsyms
== NULL
)
4735 *locsymsp
= locsyms
;
4737 sym
= locsyms
+ r_symndx
;
4745 if (symsecp
!= NULL
)
4747 asection
*symsec
= NULL
;
4748 if ((sym
->st_shndx
!= SHN_UNDEF
4749 && sym
->st_shndx
< SHN_LORESERVE
)
4750 || sym
->st_shndx
> SHN_HIRESERVE
)
4751 symsec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
4755 if (tls_maskp
!= NULL
)
4757 struct got_entry
**lgot_ents
;
4761 lgot_ents
= elf_local_got_ents (ibfd
);
4762 if (lgot_ents
!= NULL
)
4764 char *lgot_masks
= (char *) (lgot_ents
+ symtab_hdr
->sh_info
);
4765 tls_mask
= &lgot_masks
[r_symndx
];
4767 *tls_maskp
= tls_mask
;
4773 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
4774 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
4775 type suitable for optimization, and 1 otherwise. */
4778 get_tls_mask (tls_maskp
, locsymsp
, rel
, ibfd
)
4780 Elf_Internal_Sym
**locsymsp
;
4781 const Elf_Internal_Rela
*rel
;
4784 unsigned long r_symndx
;
4785 unsigned int next_r
;
4786 struct elf_link_hash_entry
*h
;
4787 Elf_Internal_Sym
*sym
;
4791 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4792 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
4795 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
4797 || ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
4800 /* Look inside a TOC section too. */
4803 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
4804 off
= h
->root
.u
.def
.value
;
4807 off
= sym
->st_value
;
4808 off
+= rel
->r_addend
;
4809 BFD_ASSERT (off
% 8 == 0);
4810 r_symndx
= ppc64_elf_section_data (sec
)->t_symndx
[off
/ 8];
4811 next_r
= ppc64_elf_section_data (sec
)->t_symndx
[off
/ 8 + 1];
4812 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
4815 || h
->root
.type
== bfd_link_hash_defined
4816 || h
->root
.type
== bfd_link_hash_defweak
)
4818 if (next_r
== (unsigned) -1)
4820 if (next_r
== (unsigned) -2
4822 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4829 ppc64_elf_edit_opd (obfd
, info
)
4831 struct bfd_link_info
*info
;
4835 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4838 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4839 Elf_Internal_Shdr
*symtab_hdr
;
4840 Elf_Internal_Sym
*local_syms
;
4841 struct elf_link_hash_entry
**sym_hashes
;
4845 bfd_boolean need_edit
;
4847 sec
= bfd_get_section_by_name (ibfd
, ".opd");
4851 amt
= sec
->_raw_size
* sizeof (long) / 24;
4852 adjust
= ppc64_elf_section_data (sec
)->opd
.adjust
;
4855 /* Must be a ld -r link. ie. check_relocs hasn't been
4857 adjust
= (long *) bfd_zalloc (obfd
, amt
);
4858 ppc64_elf_section_data (sec
)->opd
.adjust
= adjust
;
4860 memset (adjust
, 0, (size_t) amt
);
4862 if (sec
->output_section
== bfd_abs_section_ptr
)
4865 /* Look through the section relocs. */
4866 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
4870 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4871 sym_hashes
= elf_sym_hashes (ibfd
);
4873 /* Read the relocations. */
4874 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, (PTR
) NULL
,
4875 (Elf_Internal_Rela
*) NULL
,
4877 if (relstart
== NULL
)
4880 /* First run through the relocs to check they are sane, and to
4881 determine whether we need to edit this opd section. */
4884 relend
= relstart
+ sec
->reloc_count
;
4885 for (rel
= relstart
; rel
< relend
; rel
++)
4887 enum elf_ppc64_reloc_type r_type
;
4888 unsigned long r_symndx
;
4890 struct elf_link_hash_entry
*h
;
4891 Elf_Internal_Sym
*sym
;
4893 /* .opd contains a regular array of 24 byte entries. We're
4894 only interested in the reloc pointing to a function entry
4896 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
4897 if (r_type
== R_PPC64_TOC
)
4900 if (r_type
!= R_PPC64_ADDR64
)
4902 (*_bfd_error_handler
)
4903 (_("%s: unexpected reloc type %u in .opd section"),
4904 bfd_archive_filename (ibfd
), r_type
);
4909 if (rel
+ 1 >= relend
)
4911 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE ((rel
+ 1)->r_info
);
4912 if (r_type
!= R_PPC64_TOC
)
4915 if (rel
->r_offset
!= offset
)
4917 /* If someone messes with .opd alignment then after a
4918 "ld -r" we might have padding in the middle of .opd.
4919 Also, there's nothing to prevent someone putting
4920 something silly in .opd with the assembler. No .opd
4921 optimization for them! */
4922 (*_bfd_error_handler
)
4923 (_("%s: .opd is not a regular array of opd entries"),
4924 bfd_archive_filename (ibfd
));
4929 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4930 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
4932 goto error_free_rel
;
4934 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
4936 const char *sym_name
;
4938 sym_name
= h
->root
.root
.string
;
4940 sym_name
= bfd_elf_local_sym_name (ibfd
, sym
);
4942 (*_bfd_error_handler
)
4943 (_("%s: undefined sym `%s' in .opd section"),
4944 bfd_archive_filename (ibfd
),
4950 /* opd entries are always for functions defined in the
4951 current input bfd. If the symbol isn't defined in the
4952 input bfd, then we won't be using the function in this
4953 bfd; It must be defined in a linkonce section in another
4954 bfd, or is weak. It's also possible that we are
4955 discarding the function due to a linker script /DISCARD/,
4956 which we test for via the output_section. */
4957 if (sym_sec
->owner
!= ibfd
4958 || sym_sec
->output_section
== bfd_abs_section_ptr
)
4966 Elf_Internal_Rela
*write_rel
;
4967 bfd_byte
*rptr
, *wptr
;
4970 /* This seems a waste of time as input .opd sections are all
4971 zeros as generated by gcc, but I suppose there's no reason
4972 this will always be so. We might start putting something in
4973 the third word of .opd entries. */
4974 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
4976 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
4978 || !bfd_get_section_contents (ibfd
, sec
, loc
, (bfd_vma
) 0,
4981 if (local_syms
!= NULL
4982 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
4985 if (elf_section_data (sec
)->relocs
!= relstart
)
4989 sec
->contents
= loc
;
4990 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
4993 elf_section_data (sec
)->relocs
= relstart
;
4995 wptr
= sec
->contents
;
4996 rptr
= sec
->contents
;
4997 write_rel
= relstart
;
5000 for (rel
= relstart
; rel
< relend
; rel
++)
5002 if (rel
->r_offset
== offset
)
5004 unsigned long r_symndx
;
5006 struct elf_link_hash_entry
*h
;
5007 Elf_Internal_Sym
*sym
;
5009 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5010 get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
5013 skip
= (sym_sec
->owner
!= ibfd
5014 || sym_sec
->output_section
== bfd_abs_section_ptr
);
5017 if (h
!= NULL
&& sym_sec
->owner
== ibfd
)
5019 /* Arrange for the function descriptor sym
5021 struct ppc_link_hash_entry
*fdh
;
5022 struct ppc_link_hash_entry
*fh
;
5024 fh
= (struct ppc_link_hash_entry
*) h
;
5025 fdh
= (struct ppc_link_hash_entry
*) fh
->oh
;
5028 const char *fd_name
;
5029 struct ppc_link_hash_table
*htab
;
5031 fd_name
= h
->root
.root
.string
+ 1;
5032 htab
= ppc_hash_table (info
);
5033 fdh
= (struct ppc_link_hash_entry
*)
5034 elf_link_hash_lookup (&htab
->elf
, fd_name
,
5035 FALSE
, FALSE
, FALSE
);
5036 fdh
->is_func_descriptor
= 1;
5042 fdh
->elf
.root
.u
.def
.value
= 0;
5043 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
5048 /* We'll be keeping this opd entry. */
5052 /* Redefine the function descriptor symbol
5053 to this location in the opd section.
5054 We've checked above that opd relocs are
5056 struct ppc_link_hash_entry
*fdh
;
5057 struct ppc_link_hash_entry
*fh
;
5059 fh
= (struct ppc_link_hash_entry
*) h
;
5060 fdh
= (struct ppc_link_hash_entry
*) fh
->oh
;
5063 const char *fd_name
;
5064 struct ppc_link_hash_table
*htab
;
5066 fd_name
= h
->root
.root
.string
+ 1;
5067 htab
= ppc_hash_table (info
);
5068 fdh
= (struct ppc_link_hash_entry
*)
5069 elf_link_hash_lookup (&htab
->elf
, fd_name
,
5070 FALSE
, FALSE
, FALSE
);
5071 fdh
->is_func_descriptor
= 1;
5077 fdh
->elf
.root
.u
.def
.value
= wptr
- sec
->contents
;
5081 /* Local syms are a bit tricky. We could
5082 tweak them as they can be cached, but
5083 we'd need to look through the local syms
5084 for the function descriptor sym which we
5085 don't have at the moment. So keep an
5086 array of adjustments. */
5087 adjust
[rel
->r_offset
/ 24] = wptr
- rptr
;
5091 memcpy (wptr
, rptr
, 24);
5098 /* We need to adjust any reloc offsets to point to the
5099 new opd entries. While we're at it, we may as well
5100 remove redundant relocs. */
5103 rel
->r_offset
+= wptr
- rptr
;
5104 if (write_rel
!= rel
)
5105 memcpy (write_rel
, rel
, sizeof (*rel
));
5110 sec
->_cooked_size
= wptr
- sec
->contents
;
5111 sec
->reloc_count
= write_rel
- relstart
;
5112 /* Fudge the size too, as this is used later in
5113 elf_bfd_final_link if we are emitting relocs. */
5114 elf_section_data (sec
)->rel_hdr
.sh_size
5115 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
5116 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
5118 else if (elf_section_data (sec
)->relocs
!= relstart
)
5121 if (local_syms
!= NULL
5122 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5124 if (!info
->keep_memory
)
5127 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5134 /* Set htab->tls_sec. */
5137 ppc64_elf_tls_setup (obfd
, info
)
5139 struct bfd_link_info
*info
;
5142 struct ppc_link_hash_table
*htab
;
5144 for (tls
= obfd
->sections
; tls
!= NULL
; tls
= tls
->next
)
5145 if ((tls
->flags
& (SEC_THREAD_LOCAL
| SEC_LOAD
))
5146 == (SEC_THREAD_LOCAL
| SEC_LOAD
))
5149 htab
= ppc_hash_table (info
);
5150 htab
->tls_sec
= tls
;
5152 if (htab
->tls_get_addr
!= NULL
)
5154 struct elf_link_hash_entry
*h
= htab
->tls_get_addr
;
5156 while (h
->root
.type
== bfd_link_hash_indirect
5157 || h
->root
.type
== bfd_link_hash_warning
)
5158 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5160 htab
->tls_get_addr
= h
;
5166 /* Run through all the TLS relocs looking for optimization
5167 opportunities. The linker has been hacked (see ppc64elf.em) to do
5168 a preliminary section layout so that we know the TLS segment
5169 offsets. We can't optimize earlier because some optimizations need
5170 to know the tp offset, and we need to optimize before allocating
5171 dynamic relocations. */
5174 ppc64_elf_tls_optimize (obfd
, info
)
5175 bfd
*obfd ATTRIBUTE_UNUSED
;
5176 struct bfd_link_info
*info
;
5180 struct ppc_link_hash_table
*htab
;
5182 if (info
->relocateable
|| info
->shared
)
5185 htab
= ppc_hash_table (info
);
5186 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5188 Elf_Internal_Sym
*locsyms
= NULL
;
5190 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5191 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
5193 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
5194 int expecting_tls_get_addr
;
5196 /* Read the relocations. */
5197 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, (PTR
) NULL
,
5198 (Elf_Internal_Rela
*) NULL
,
5200 if (relstart
== NULL
)
5203 expecting_tls_get_addr
= 0;
5204 relend
= relstart
+ sec
->reloc_count
;
5205 for (rel
= relstart
; rel
< relend
; rel
++)
5207 enum elf_ppc64_reloc_type r_type
;
5208 unsigned long r_symndx
;
5209 struct elf_link_hash_entry
*h
;
5210 Elf_Internal_Sym
*sym
;
5213 char tls_set
, tls_clear
, tls_type
= 0;
5215 bfd_boolean ok_tprel
, is_local
;
5217 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5218 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
5222 if (elf_section_data (sec
)->relocs
!= relstart
)
5225 && (elf_tdata (ibfd
)->symtab_hdr
.contents
5226 != (unsigned char *) locsyms
))
5233 if (h
->root
.type
!= bfd_link_hash_defined
5234 && h
->root
.type
!= bfd_link_hash_defweak
)
5236 value
= h
->root
.u
.def
.value
;
5239 value
= sym
->st_value
;
5244 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
5247 value
+= sym_sec
->output_offset
;
5248 value
+= sym_sec
->output_section
->vma
;
5249 value
-= htab
->tls_sec
->vma
;
5250 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
5251 < (bfd_vma
) 1 << 32);
5255 = (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
5258 case R_PPC64_GOT_TLSLD16
:
5259 case R_PPC64_GOT_TLSLD16_LO
:
5260 case R_PPC64_GOT_TLSLD16_HI
:
5261 case R_PPC64_GOT_TLSLD16_HA
:
5262 /* These relocs should never be against a symbol
5263 defined in a shared lib. Leave them alone if
5264 that turns out to be the case. */
5265 htab
->tlsld_got
.refcount
-= 1;
5272 tls_type
= TLS_TLS
| TLS_LD
;
5273 expecting_tls_get_addr
= 1;
5276 case R_PPC64_GOT_TLSGD16
:
5277 case R_PPC64_GOT_TLSGD16_LO
:
5278 case R_PPC64_GOT_TLSGD16_HI
:
5279 case R_PPC64_GOT_TLSGD16_HA
:
5285 tls_set
= TLS_TLS
| TLS_TPRELGD
;
5287 tls_type
= TLS_TLS
| TLS_GD
;
5288 expecting_tls_get_addr
= 1;
5291 case R_PPC64_GOT_TPREL16_DS
:
5292 case R_PPC64_GOT_TPREL16_LO_DS
:
5293 case R_PPC64_GOT_TPREL16_HI
:
5294 case R_PPC64_GOT_TPREL16_HA
:
5295 expecting_tls_get_addr
= 0;
5300 tls_clear
= TLS_TPREL
;
5301 tls_type
= TLS_TLS
| TLS_TPREL
;
5308 case R_PPC64_REL14_BRTAKEN
:
5309 case R_PPC64_REL14_BRNTAKEN
:
5312 && h
== htab
->tls_get_addr
)
5314 if (!expecting_tls_get_addr
5316 && ((ELF64_R_TYPE (rel
[-1].r_info
)
5318 || (ELF64_R_TYPE (rel
[-1].r_info
)
5319 == R_PPC64_TOC16_LO
)))
5321 /* Check for toc tls entries. */
5325 retval
= get_tls_mask (&toc_tls
, &locsyms
,
5329 if (toc_tls
!= NULL
)
5330 expecting_tls_get_addr
= retval
> 1;
5333 if (expecting_tls_get_addr
)
5335 struct plt_entry
*ent
;
5336 for (ent
= h
->plt
.plist
; ent
; ent
= ent
->next
)
5337 if (ent
->addend
== 0)
5339 if (ent
->plt
.refcount
> 0)
5340 ent
->plt
.refcount
-= 1;
5345 expecting_tls_get_addr
= 0;
5348 case R_PPC64_TPREL64
:
5349 expecting_tls_get_addr
= 0;
5353 tls_set
= TLS_EXPLICIT
;
5354 tls_clear
= TLS_TPREL
;
5360 case R_PPC64_DTPMOD64
:
5361 expecting_tls_get_addr
= 0;
5362 if (rel
+ 1 < relend
5364 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
5365 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5369 tls_set
= TLS_EXPLICIT
| TLS_GD
;
5372 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
5381 tls_set
= TLS_EXPLICIT
;
5387 expecting_tls_get_addr
= 0;
5391 if ((tls_set
& TLS_EXPLICIT
) == 0)
5393 struct got_entry
*ent
;
5395 /* Adjust got entry for this reloc. */
5399 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
5401 for (; ent
!= NULL
; ent
= ent
->next
)
5402 if (ent
->addend
== rel
->r_addend
5403 && ent
->tls_type
== tls_type
)
5410 /* We managed to get rid of a got entry. */
5411 if (ent
->got
.refcount
> 0)
5412 ent
->got
.refcount
-= 1;
5417 struct ppc_link_hash_entry
* eh
;
5418 struct ppc_dyn_relocs
**pp
;
5419 struct ppc_dyn_relocs
*p
;
5421 /* Adjust dynamic relocs. */
5422 eh
= (struct ppc_link_hash_entry
*) h
;
5423 for (pp
= &eh
->dyn_relocs
;
5428 /* If we got rid of a DTPMOD/DTPREL reloc
5429 pair then we'll lose one or two dyn
5431 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
5440 *tls_mask
|= tls_set
;
5441 *tls_mask
&= ~tls_clear
;
5444 if (elf_section_data (sec
)->relocs
!= relstart
)
5449 && (elf_tdata (ibfd
)->symtab_hdr
.contents
5450 != (unsigned char *) locsyms
))
5452 if (!info
->keep_memory
)
5455 elf_tdata (ibfd
)->symtab_hdr
.contents
= (unsigned char *) locsyms
;
5461 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
5462 will be called from elflink.h. If elflink.h doesn't call our
5463 finish_dynamic_symbol routine, we'll need to do something about
5464 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
5465 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
5468 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
5469 && ((H)->dynindx != -1 \
5470 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
5472 /* Allocate space in .plt, .got and associated reloc sections for
5476 allocate_dynrelocs (h
, inf
)
5477 struct elf_link_hash_entry
*h
;
5480 struct bfd_link_info
*info
;
5481 struct ppc_link_hash_table
*htab
;
5483 struct ppc_link_hash_entry
*eh
;
5484 struct ppc_dyn_relocs
*p
;
5485 struct got_entry
*gent
;
5487 if (h
->root
.type
== bfd_link_hash_indirect
)
5490 if (h
->root
.type
== bfd_link_hash_warning
)
5491 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5493 info
= (struct bfd_link_info
*) inf
;
5494 htab
= ppc_hash_table (info
);
5496 if (htab
->elf
.dynamic_sections_created
5498 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
5500 struct plt_entry
*pent
;
5501 bfd_boolean doneone
= FALSE
;
5502 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
5503 if (pent
->plt
.refcount
> 0)
5505 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
5507 /* If this is the first .plt entry, make room for the special
5510 if (s
->_raw_size
== 0)
5511 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
5513 pent
->plt
.offset
= s
->_raw_size
;
5515 /* Make room for this entry. */
5516 s
->_raw_size
+= PLT_ENTRY_SIZE
;
5518 /* Make room for the .glink code. */
5520 if (s
->_raw_size
== 0)
5521 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
5522 /* We need bigger stubs past index 32767. */
5523 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
5525 s
->_raw_size
+= 2*4;
5527 /* We also need to make an entry in the .rela.plt section. */
5529 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
5533 pent
->plt
.offset
= (bfd_vma
) -1;
5536 h
->plt
.plist
= NULL
;
5537 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
5542 h
->plt
.plist
= NULL
;
5543 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
5546 eh
= (struct ppc_link_hash_entry
*) h
;
5547 /* Run through the TLS GD got entries first if we're changing them
5549 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
5550 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
5551 if (gent
->got
.refcount
> 0
5552 && (gent
->tls_type
& TLS_GD
) != 0)
5554 /* This was a GD entry that has been converted to TPREL. If
5555 there happens to be a TPREL entry we can use that one. */
5556 struct got_entry
*ent
;
5557 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5558 if (ent
->got
.refcount
> 0
5559 && (ent
->tls_type
& TLS_TPREL
) != 0
5560 && ent
->addend
== gent
->addend
)
5562 gent
->got
.refcount
= 0;
5566 /* If not, then we'll be using our own TPREL entry. */
5567 if (gent
->got
.refcount
!= 0)
5568 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
5571 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
5572 if (gent
->got
.refcount
> 0)
5576 /* Make sure this symbol is output as a dynamic symbol.
5577 Undefined weak syms won't yet be marked as dynamic,
5578 nor will all TLS symbols. */
5579 if (h
->dynindx
== -1
5580 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5582 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5586 if ((gent
->tls_type
& TLS_LD
) != 0
5587 && !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
5589 gent
->got
.offset
= htab
->tlsld_got
.offset
;
5594 gent
->got
.offset
= s
->_raw_size
;
5596 += (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)) ? 16 : 8;
5597 dyn
= htab
->elf
.dynamic_sections_created
;
5599 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
5600 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5601 || h
->root
.type
!= bfd_link_hash_undefweak
))
5602 htab
->srelgot
->_raw_size
5603 += (gent
->tls_type
& eh
->tls_mask
& TLS_GD
5604 ? 2 * sizeof (Elf64_External_Rela
)
5605 : sizeof (Elf64_External_Rela
));
5608 gent
->got
.offset
= (bfd_vma
) -1;
5610 if (eh
->dyn_relocs
== NULL
)
5613 /* In the shared -Bsymbolic case, discard space allocated for
5614 dynamic pc-relative relocs against symbols which turn out to be
5615 defined in regular objects. For the normal shared case, discard
5616 space for relocs that have become local due to symbol visibility
5621 /* Relocs that use pc_count are those that appear on a call insn,
5622 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
5623 generated via assembly. We want calls to protected symbols to
5624 resolve directly to the function rather than going via the plt.
5625 If people want function pointer comparisons to work as expected
5626 then they should avoid writing weird assembly. */
5627 if (SYMBOL_CALLS_LOCAL (info
, h
))
5629 struct ppc_dyn_relocs
**pp
;
5631 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5633 p
->count
-= p
->pc_count
;
5642 /* Also discard relocs on undefined weak syms with non-default
5644 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5645 && h
->root
.type
== bfd_link_hash_undefweak
)
5646 eh
->dyn_relocs
= NULL
;
5648 else if (ELIMINATE_COPY_RELOCS
)
5650 /* For the non-shared case, discard space for relocs against
5651 symbols which turn out to need copy relocs or are not
5654 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5655 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5656 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5658 /* Make sure this symbol is output as a dynamic symbol.
5659 Undefined weak syms won't yet be marked as dynamic. */
5660 if (h
->dynindx
== -1
5661 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5663 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5667 /* If that succeeded, we know we'll be keeping all the
5669 if (h
->dynindx
!= -1)
5673 eh
->dyn_relocs
= NULL
;
5678 /* Finally, allocate space. */
5679 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5681 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5682 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
5688 /* Find any dynamic relocs that apply to read-only sections. */
5691 readonly_dynrelocs (h
, inf
)
5692 struct elf_link_hash_entry
*h
;
5695 struct ppc_link_hash_entry
*eh
;
5696 struct ppc_dyn_relocs
*p
;
5698 if (h
->root
.type
== bfd_link_hash_warning
)
5699 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5701 eh
= (struct ppc_link_hash_entry
*) h
;
5702 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5704 asection
*s
= p
->sec
->output_section
;
5706 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5708 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5710 info
->flags
|= DF_TEXTREL
;
5712 /* Not an error, just cut short the traversal. */
5719 /* Set the sizes of the dynamic sections. */
5722 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
5723 bfd
*output_bfd ATTRIBUTE_UNUSED
;
5724 struct bfd_link_info
*info
;
5726 struct ppc_link_hash_table
*htab
;
5732 htab
= ppc_hash_table (info
);
5733 dynobj
= htab
->elf
.dynobj
;
5737 if (htab
->elf
.dynamic_sections_created
)
5739 /* Set the contents of the .interp section to the interpreter. */
5740 if (info
->executable
)
5742 s
= bfd_get_section_by_name (dynobj
, ".interp");
5745 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5746 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5750 if (htab
->tlsld_got
.refcount
> 0)
5752 htab
->tlsld_got
.offset
= htab
->sgot
->_raw_size
;
5753 htab
->sgot
->_raw_size
+= 16;
5755 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
5758 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
5760 /* Set up .got offsets for local syms, and space for local dynamic
5762 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5764 struct got_entry
**lgot_ents
;
5765 struct got_entry
**end_lgot_ents
;
5767 bfd_size_type locsymcount
;
5768 Elf_Internal_Shdr
*symtab_hdr
;
5771 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
5774 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5776 struct ppc_dyn_relocs
*p
;
5778 for (p
= *((struct ppc_dyn_relocs
**)
5779 &elf_section_data (s
)->local_dynrel
);
5783 if (!bfd_is_abs_section (p
->sec
)
5784 && bfd_is_abs_section (p
->sec
->output_section
))
5786 /* Input section has been discarded, either because
5787 it is a copy of a linkonce section or due to
5788 linker script /DISCARD/, so we'll be discarding
5791 else if (p
->count
!= 0)
5793 srel
= elf_section_data (p
->sec
)->sreloc
;
5794 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
5795 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
5796 info
->flags
|= DF_TEXTREL
;
5801 lgot_ents
= elf_local_got_ents (ibfd
);
5805 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
5806 locsymcount
= symtab_hdr
->sh_info
;
5807 end_lgot_ents
= lgot_ents
+ locsymcount
;
5808 lgot_masks
= (char *) end_lgot_ents
;
5810 srel
= htab
->srelgot
;
5811 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
5813 struct got_entry
*ent
;
5815 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
5816 if (ent
->got
.refcount
> 0)
5818 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
5820 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
5822 htab
->tlsld_got
.offset
= s
->_raw_size
;
5825 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5827 ent
->got
.offset
= htab
->tlsld_got
.offset
;
5831 ent
->got
.offset
= s
->_raw_size
;
5832 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
5836 srel
->_raw_size
+= 2 * sizeof (Elf64_External_Rela
);
5842 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5847 ent
->got
.offset
= (bfd_vma
) -1;
5851 /* Allocate global sym .plt and .got entries, and space for global
5852 sym dynamic relocs. */
5853 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
5855 /* We now have determined the sizes of the various dynamic sections.
5856 Allocate memory for them. */
5858 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5860 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5863 /* Reset _cooked_size since prelim layout will set it wrongly,
5864 and a non-zero _cooked_size sticks. */
5865 s
->_cooked_size
= 0;
5867 if (s
== htab
->sbrlt
|| s
== htab
->srelbrlt
)
5868 /* These haven't been allocated yet; don't strip. */
5870 else if (s
== htab
->splt
5872 || s
== htab
->sglink
)
5874 /* Strip this section if we don't need it; see the
5877 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
5879 if (s
->_raw_size
== 0)
5881 /* If we don't need this section, strip it from the
5882 output file. This is mostly to handle .rela.bss and
5883 .rela.plt. We must create both sections in
5884 create_dynamic_sections, because they must be created
5885 before the linker maps input sections to output
5886 sections. The linker does that before
5887 adjust_dynamic_symbol is called, and it is that
5888 function which decides whether anything needs to go
5889 into these sections. */
5893 if (s
!= htab
->srelplt
)
5896 /* We use the reloc_count field as a counter if we need
5897 to copy relocs into the output file. */
5903 /* It's not one of our sections, so don't allocate space. */
5907 if (s
->_raw_size
== 0)
5909 _bfd_strip_section_from_output (info
, s
);
5913 /* .plt is in the bss section. We don't initialise it. */
5914 if ((s
->flags
& SEC_LOAD
) == 0)
5917 /* Allocate memory for the section contents. We use bfd_zalloc
5918 here in case unused entries are not reclaimed before the
5919 section's contents are written out. This should not happen,
5920 but this way if it does we get a R_PPC64_NONE reloc in .rela
5921 sections instead of garbage.
5922 We also rely on the section contents being zero when writing
5924 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
5925 if (s
->contents
== NULL
)
5929 if (htab
->elf
.dynamic_sections_created
)
5931 /* Add some entries to the .dynamic section. We fill in the
5932 values later, in ppc64_elf_finish_dynamic_sections, but we
5933 must add the entries now so that we get the correct size for
5934 the .dynamic section. The DT_DEBUG entry is filled in by the
5935 dynamic linker and used by the debugger. */
5936 #define add_dynamic_entry(TAG, VAL) \
5937 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
5939 if (info
->executable
)
5941 if (!add_dynamic_entry (DT_DEBUG
, 0))
5945 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
5947 if (!add_dynamic_entry (DT_PLTGOT
, 0)
5948 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
5949 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
5950 || !add_dynamic_entry (DT_JMPREL
, 0)
5951 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
5957 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
5958 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
5964 if (!add_dynamic_entry (DT_RELA
, 0)
5965 || !add_dynamic_entry (DT_RELASZ
, 0)
5966 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
5969 /* If any dynamic relocs apply to a read-only section,
5970 then we need a DT_TEXTREL entry. */
5971 if ((info
->flags
& DF_TEXTREL
) == 0)
5972 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
,
5975 if ((info
->flags
& DF_TEXTREL
) != 0)
5977 if (!add_dynamic_entry (DT_TEXTREL
, 0))
5982 #undef add_dynamic_entry
5987 /* Determine the type of stub needed, if any, for a call. */
5989 static INLINE
enum ppc_stub_type
5990 ppc_type_of_stub (input_sec
, rel
, hash
, destination
)
5991 asection
*input_sec
;
5992 const Elf_Internal_Rela
*rel
;
5993 struct ppc_link_hash_entry
**hash
;
5994 bfd_vma destination
;
5996 struct ppc_link_hash_entry
*h
= *hash
;
5998 bfd_vma branch_offset
;
5999 bfd_vma max_branch_offset
;
6000 unsigned int r_type
;
6005 && h
->oh
->dynindx
!= -1)
6007 struct plt_entry
*ent
;
6008 for (ent
= h
->oh
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6009 if (ent
->addend
== rel
->r_addend
6010 && ent
->plt
.offset
!= (bfd_vma
) -1)
6012 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
6013 return ppc_stub_plt_call
;
6017 if (h
->elf
.root
.type
== bfd_link_hash_undefweak
6018 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
6019 return ppc_stub_none
;
6022 /* Determine where the call point is. */
6023 location
= (input_sec
->output_offset
6024 + input_sec
->output_section
->vma
6027 branch_offset
= destination
- location
;
6028 r_type
= ELF64_R_TYPE (rel
->r_info
);
6030 /* Determine if a long branch stub is needed. */
6031 max_branch_offset
= 1 << 25;
6032 if (r_type
!= (unsigned int) R_PPC64_REL24
)
6033 max_branch_offset
= 1 << 15;
6035 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
6036 /* We need a stub. Figure out whether a long_branch or plt_branch
6038 return ppc_stub_long_branch
;
6040 return ppc_stub_none
;
6043 /* Build a .plt call stub. */
6046 build_plt_stub (obfd
, p
, offset
, glink
)
6052 #define PPC_LO(v) ((v) & 0xffff)
6053 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6054 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6057 bfd_put_32 (obfd
, LD_R2_40R1
, p
), p
+= 4;
6058 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
6060 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
6061 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
6062 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
6063 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
6065 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
6066 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
6067 bfd_put_32 (obfd
, ADDIS_R12_R12_1
, p
), p
+= 4;
6069 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
6070 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
6071 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
6076 ppc_build_one_stub (gen_entry
, in_arg
)
6077 struct bfd_hash_entry
*gen_entry
;
6080 struct ppc_stub_hash_entry
*stub_entry
;
6081 struct ppc_branch_hash_entry
*br_entry
;
6082 struct bfd_link_info
*info
;
6083 struct ppc_link_hash_table
*htab
;
6089 struct plt_entry
*ent
;
6093 /* Massage our args to the form they really have. */
6094 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
6095 info
= (struct bfd_link_info
*) in_arg
;
6097 htab
= ppc_hash_table (info
);
6098 stub_sec
= stub_entry
->stub_sec
;
6100 /* Make a note of the offset within the stubs for this entry. */
6101 stub_entry
->stub_offset
= stub_sec
->_cooked_size
;
6102 loc
= stub_sec
->contents
+ stub_entry
->stub_offset
;
6104 stub_bfd
= stub_sec
->owner
;
6106 switch (stub_entry
->stub_type
)
6108 case ppc_stub_long_branch
:
6109 /* Branches are relative. This is where we are going to. */
6110 off
= (stub_entry
->target_value
6111 + stub_entry
->target_section
->output_offset
6112 + stub_entry
->target_section
->output_section
->vma
);
6114 /* And this is where we are coming from. */
6115 off
-= (stub_entry
->stub_offset
6116 + stub_sec
->output_offset
6117 + stub_sec
->output_section
->vma
);
6119 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
6121 bfd_put_32 (stub_bfd
, (bfd_vma
) B_DOT
| (off
& 0x3fffffc), loc
);
6125 case ppc_stub_plt_branch
:
6126 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
6127 stub_entry
->root
.string
+ 9,
6129 if (br_entry
== NULL
)
6131 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
6132 stub_entry
->root
.string
+ 9);
6133 htab
->stub_error
= TRUE
;
6137 off
= (stub_entry
->target_value
6138 + stub_entry
->target_section
->output_offset
6139 + stub_entry
->target_section
->output_section
->vma
);
6141 bfd_put_64 (htab
->sbrlt
->owner
, off
,
6142 htab
->sbrlt
->contents
+ br_entry
->offset
);
6146 /* Create a reloc for the branch lookup table entry. */
6147 Elf_Internal_Rela rela
;
6150 rela
.r_offset
= (br_entry
->offset
6151 + htab
->sbrlt
->output_offset
6152 + htab
->sbrlt
->output_section
->vma
);
6153 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6154 rela
.r_addend
= off
;
6156 loc
= htab
->srelbrlt
->contents
;
6157 loc
+= htab
->srelbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
6158 bfd_elf64_swap_reloca_out (htab
->srelbrlt
->owner
, &rela
, loc
);
6161 off
= (br_entry
->offset
6162 + htab
->sbrlt
->output_offset
6163 + htab
->sbrlt
->output_section
->vma
6164 - elf_gp (htab
->sbrlt
->output_section
->owner
)
6167 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
6169 (*_bfd_error_handler
)
6170 (_("linkage table error against `%s'"),
6171 stub_entry
->root
.string
);
6172 bfd_set_error (bfd_error_bad_value
);
6173 htab
->stub_error
= TRUE
;
6178 bfd_put_32 (stub_bfd
, (bfd_vma
) ADDIS_R12_R2
| PPC_HA (indx
), loc
);
6179 bfd_put_32 (stub_bfd
, (bfd_vma
) LD_R11_0R12
| PPC_LO (indx
), loc
+ 4);
6180 bfd_put_32 (stub_bfd
, (bfd_vma
) MTCTR_R11
, loc
+ 8);
6181 bfd_put_32 (stub_bfd
, (bfd_vma
) BCTR
, loc
+ 12);
6185 case ppc_stub_plt_call
:
6186 /* Do the best we can for shared libraries built without
6187 exporting ".foo" for each "foo". This can happen when symbol
6188 versioning scripts strip all bar a subset of symbols. */
6189 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
6190 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
6192 /* Point the symbol at the stub. There may be multiple stubs,
6193 we don't really care; The main thing is to make this sym
6194 defined somewhere. */
6195 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
6196 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
6197 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
6200 /* Now build the stub. */
6202 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6203 if (ent
->addend
== stub_entry
->addend
)
6205 off
= ent
->plt
.offset
;
6208 if (off
>= (bfd_vma
) -2)
6211 off
&= ~ (bfd_vma
) 1;
6212 off
+= (htab
->splt
->output_offset
6213 + htab
->splt
->output_section
->vma
6214 - elf_gp (htab
->splt
->output_section
->owner
)
6217 if (off
+ 0x80000000 > 0xffffffff || (off
& 7) != 0)
6219 (*_bfd_error_handler
)
6220 (_("linkage table error against `%s'"),
6221 stub_entry
->h
->elf
.root
.root
.string
);
6222 bfd_set_error (bfd_error_bad_value
);
6223 htab
->stub_error
= TRUE
;
6227 p
= build_plt_stub (stub_bfd
, loc
, (int) off
, 0);
6236 stub_sec
->_cooked_size
+= size
;
6240 /* As above, but don't actually build the stub. Just bump offset so
6241 we know stub section sizes, and select plt_branch stubs where
6242 long_branch stubs won't do. */
6245 ppc_size_one_stub (gen_entry
, in_arg
)
6246 struct bfd_hash_entry
*gen_entry
;
6249 struct ppc_stub_hash_entry
*stub_entry
;
6250 struct ppc_link_hash_table
*htab
;
6254 /* Massage our args to the form they really have. */
6255 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
6256 htab
= (struct ppc_link_hash_table
*) in_arg
;
6258 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
6260 struct plt_entry
*ent
;
6262 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6263 if (ent
->addend
== stub_entry
->addend
)
6265 off
= ent
->plt
.offset
& ~(bfd_vma
) 1;
6268 if (off
>= (bfd_vma
) -2)
6270 off
+= (htab
->splt
->output_offset
6271 + htab
->splt
->output_section
->vma
6272 - elf_gp (htab
->splt
->output_section
->owner
)
6276 if (PPC_HA ((int) off
+ 16) != PPC_HA ((int) off
))
6281 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
6282 stub_entry
->stub_type
= ppc_stub_long_branch
;
6285 off
= (stub_entry
->target_value
6286 + stub_entry
->target_section
->output_offset
6287 + stub_entry
->target_section
->output_section
->vma
);
6288 off
-= (stub_entry
->stub_sec
->_raw_size
6289 + stub_entry
->stub_sec
->output_offset
6290 + stub_entry
->stub_sec
->output_section
->vma
);
6292 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
6294 struct ppc_branch_hash_entry
*br_entry
;
6296 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
6297 stub_entry
->root
.string
+ 9,
6299 if (br_entry
== NULL
)
6301 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
6302 stub_entry
->root
.string
+ 9);
6303 htab
->stub_error
= TRUE
;
6307 if (br_entry
->iter
!= htab
->stub_iteration
)
6309 br_entry
->iter
= htab
->stub_iteration
;
6310 br_entry
->offset
= htab
->sbrlt
->_raw_size
;
6311 htab
->sbrlt
->_raw_size
+= 8;
6313 stub_entry
->stub_type
= ppc_stub_plt_branch
;
6318 stub_entry
->stub_sec
->_raw_size
+= size
;
6322 /* Set up various things so that we can make a list of input sections
6323 for each output section included in the link. Returns -1 on error,
6324 0 when no stubs will be needed, and 1 on success. */
6327 ppc64_elf_setup_section_lists (output_bfd
, info
)
6329 struct bfd_link_info
*info
;
6332 int top_id
, top_index
;
6334 asection
**input_list
, **list
;
6336 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6338 if (htab
->elf
.root
.creator
->flavour
!= bfd_target_elf_flavour
6339 || htab
->sbrlt
== NULL
)
6342 /* Find the top input section id. */
6343 for (input_bfd
= info
->input_bfds
, top_id
= 0;
6345 input_bfd
= input_bfd
->link_next
)
6347 for (section
= input_bfd
->sections
;
6349 section
= section
->next
)
6351 if (top_id
< section
->id
)
6352 top_id
= section
->id
;
6356 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
6357 htab
->stub_group
= (struct map_stub
*) bfd_zmalloc (amt
);
6358 if (htab
->stub_group
== NULL
)
6361 /* We can't use output_bfd->section_count here to find the top output
6362 section index as some sections may have been removed, and
6363 _bfd_strip_section_from_output doesn't renumber the indices. */
6364 for (section
= output_bfd
->sections
, top_index
= 0;
6366 section
= section
->next
)
6368 if (top_index
< section
->index
)
6369 top_index
= section
->index
;
6372 htab
->top_index
= top_index
;
6373 amt
= sizeof (asection
*) * (top_index
+ 1);
6374 input_list
= (asection
**) bfd_malloc (amt
);
6375 htab
->input_list
= input_list
;
6376 if (input_list
== NULL
)
6379 /* For sections we aren't interested in, mark their entries with a
6380 value we can check later. */
6381 list
= input_list
+ top_index
;
6383 *list
= bfd_abs_section_ptr
;
6384 while (list
-- != input_list
);
6386 for (section
= output_bfd
->sections
;
6388 section
= section
->next
)
6390 if ((section
->flags
& SEC_CODE
) != 0)
6391 input_list
[section
->index
] = NULL
;
6397 /* The linker repeatedly calls this function for each input section,
6398 in the order that input sections are linked into output sections.
6399 Build lists of input sections to determine groupings between which
6400 we may insert linker stubs. */
6403 ppc64_elf_next_input_section (info
, isec
)
6404 struct bfd_link_info
*info
;
6407 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6409 if (isec
->output_section
->index
<= htab
->top_index
)
6411 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
6412 if (*list
!= bfd_abs_section_ptr
)
6414 /* Steal the link_sec pointer for our list. */
6415 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
6416 /* This happens to make the list in reverse order,
6417 which is what we want. */
6418 PREV_SEC (isec
) = *list
;
6424 /* See whether we can group stub sections together. Grouping stub
6425 sections may result in fewer stubs. More importantly, we need to
6426 put all .init* and .fini* stubs at the beginning of the .init or
6427 .fini output sections respectively, because glibc splits the
6428 _init and _fini functions into multiple parts. Putting a stub in
6429 the middle of a function is not a good idea. */
6432 group_sections (htab
, stub_group_size
, stubs_always_before_branch
)
6433 struct ppc_link_hash_table
*htab
;
6434 bfd_size_type stub_group_size
;
6435 bfd_boolean stubs_always_before_branch
;
6437 asection
**list
= htab
->input_list
+ htab
->top_index
;
6440 asection
*tail
= *list
;
6441 if (tail
== bfd_abs_section_ptr
)
6443 while (tail
!= NULL
)
6447 bfd_size_type total
;
6448 bfd_boolean big_sec
;
6451 if (tail
->_cooked_size
)
6452 total
= tail
->_cooked_size
;
6454 total
= tail
->_raw_size
;
6455 big_sec
= total
>= stub_group_size
;
6457 while ((prev
= PREV_SEC (curr
)) != NULL
6458 && ((total
+= curr
->output_offset
- prev
->output_offset
)
6462 /* OK, the size from the start of CURR to the end is less
6463 than stub_group_size and thus can be handled by one stub
6464 section. (or the tail section is itself larger than
6465 stub_group_size, in which case we may be toast.) We
6466 should really be keeping track of the total size of stubs
6467 added here, as stubs contribute to the final output
6468 section size. That's a little tricky, and this way will
6469 only break if stubs added make the total size more than
6470 2^25, ie. for the default stub_group_size, if stubs total
6471 more than 2097152 bytes, or nearly 75000 plt call stubs. */
6474 prev
= PREV_SEC (tail
);
6475 /* Set up this stub group. */
6476 htab
->stub_group
[tail
->id
].link_sec
= curr
;
6478 while (tail
!= curr
&& (tail
= prev
) != NULL
);
6480 /* But wait, there's more! Input sections up to stub_group_size
6481 bytes before the stub section can be handled by it too.
6482 Don't do this if we have a really large section after the
6483 stubs, as adding more stubs increases the chance that
6484 branches may not reach into the stub section. */
6485 if (!stubs_always_before_branch
&& !big_sec
)
6489 && ((total
+= tail
->output_offset
- prev
->output_offset
)
6493 prev
= PREV_SEC (tail
);
6494 htab
->stub_group
[tail
->id
].link_sec
= curr
;
6500 while (list
-- != htab
->input_list
);
6501 free (htab
->input_list
);
6505 /* Determine and set the size of the stub section for a final link.
6507 The basic idea here is to examine all the relocations looking for
6508 PC-relative calls to a target that is unreachable with a "bl"
6512 ppc64_elf_size_stubs (output_bfd
, stub_bfd
, info
, group_size
,
6513 add_stub_section
, layout_sections_again
)
6516 struct bfd_link_info
*info
;
6517 bfd_signed_vma group_size
;
6518 asection
* (*add_stub_section
) PARAMS ((const char *, asection
*));
6519 void (*layout_sections_again
) PARAMS ((void));
6521 bfd_size_type stub_group_size
;
6522 bfd_boolean stubs_always_before_branch
;
6523 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6525 /* Stash our params away. */
6526 htab
->stub_bfd
= stub_bfd
;
6527 htab
->add_stub_section
= add_stub_section
;
6528 htab
->layout_sections_again
= layout_sections_again
;
6529 stubs_always_before_branch
= group_size
< 0;
6531 stub_group_size
= -group_size
;
6533 stub_group_size
= group_size
;
6534 if (stub_group_size
== 1)
6536 /* Default values. */
6537 if (stubs_always_before_branch
)
6539 stub_group_size
= 0x1e00000;
6540 if (htab
->has_14bit_branch
)
6541 stub_group_size
= 0x7800;
6545 stub_group_size
= 0x1c00000;
6546 if (htab
->has_14bit_branch
)
6547 stub_group_size
= 0x7000;
6551 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
6556 unsigned int bfd_indx
;
6558 bfd_boolean stub_changed
;
6560 htab
->stub_iteration
+= 1;
6561 stub_changed
= FALSE
;
6563 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
6565 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
6567 Elf_Internal_Shdr
*symtab_hdr
;
6569 Elf_Internal_Sym
*local_syms
= NULL
;
6571 /* We'll need the symbol table in a second. */
6572 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6573 if (symtab_hdr
->sh_info
== 0)
6576 /* Walk over each section attached to the input bfd. */
6577 for (section
= input_bfd
->sections
;
6579 section
= section
->next
)
6581 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
6583 /* If there aren't any relocs, then there's nothing more
6585 if ((section
->flags
& SEC_RELOC
) == 0
6586 || section
->reloc_count
== 0)
6589 /* If this section is a link-once section that will be
6590 discarded, then don't create any stubs. */
6591 if (section
->output_section
== NULL
6592 || section
->output_section
->owner
!= output_bfd
)
6595 /* Get the relocs. */
6597 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
,
6598 (Elf_Internal_Rela
*) NULL
,
6600 if (internal_relocs
== NULL
)
6601 goto error_ret_free_local
;
6603 /* Now examine each relocation. */
6604 irela
= internal_relocs
;
6605 irelaend
= irela
+ section
->reloc_count
;
6606 for (; irela
< irelaend
; irela
++)
6608 unsigned int r_type
, r_indx
;
6609 enum ppc_stub_type stub_type
;
6610 struct ppc_stub_hash_entry
*stub_entry
;
6613 bfd_vma destination
;
6614 struct ppc_link_hash_entry
*hash
;
6615 struct elf_link_hash_entry
*h
;
6616 Elf_Internal_Sym
*sym
;
6618 const asection
*id_sec
;
6620 r_type
= ELF64_R_TYPE (irela
->r_info
);
6621 r_indx
= ELF64_R_SYM (irela
->r_info
);
6623 if (r_type
>= (unsigned int) R_PPC64_max
)
6625 bfd_set_error (bfd_error_bad_value
);
6626 goto error_ret_free_internal
;
6629 /* Only look for stubs on branch instructions. */
6630 if (r_type
!= (unsigned int) R_PPC64_REL24
6631 && r_type
!= (unsigned int) R_PPC64_REL14
6632 && r_type
!= (unsigned int) R_PPC64_REL14_BRTAKEN
6633 && r_type
!= (unsigned int) R_PPC64_REL14_BRNTAKEN
)
6636 /* Now determine the call target, its name, value,
6639 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6641 goto error_ret_free_internal
;
6642 hash
= (struct ppc_link_hash_entry
*) h
;
6646 /* It's a local symbol. */
6647 sym_value
= sym
->st_value
;
6648 destination
= (sym_value
+ irela
->r_addend
6649 + sym_sec
->output_offset
6650 + sym_sec
->output_section
->vma
);
6654 /* It's an external symbol. */
6656 if (hash
->elf
.root
.type
== bfd_link_hash_defined
6657 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
6659 sym_value
= hash
->elf
.root
.u
.def
.value
;
6660 if (sym_sec
->output_section
!= NULL
)
6661 destination
= (sym_value
+ irela
->r_addend
6662 + sym_sec
->output_offset
6663 + sym_sec
->output_section
->vma
);
6665 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
6667 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
6671 bfd_set_error (bfd_error_bad_value
);
6672 goto error_ret_free_internal
;
6676 /* Determine what (if any) linker stub is needed. */
6677 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
6679 if (stub_type
== ppc_stub_none
)
6682 /* __tls_get_addr calls might be eliminated. */
6683 if (stub_type
!= ppc_stub_plt_call
6685 && &hash
->elf
== htab
->tls_get_addr
6686 && section
->has_tls_reloc
6687 && irela
!= internal_relocs
)
6692 if (!get_tls_mask (&tls_mask
, &local_syms
,
6693 irela
- 1, input_bfd
))
6694 goto error_ret_free_internal
;
6699 /* Support for grouping stub sections. */
6700 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
6702 /* Get the name of this stub. */
6703 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
6705 goto error_ret_free_internal
;
6707 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
6708 stub_name
, FALSE
, FALSE
);
6709 if (stub_entry
!= NULL
)
6711 /* The proper stub has already been created. */
6716 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
6717 if (stub_entry
== NULL
)
6720 error_ret_free_internal
:
6721 if (elf_section_data (section
)->relocs
== NULL
)
6722 free (internal_relocs
);
6723 error_ret_free_local
:
6724 if (local_syms
!= NULL
6725 && (symtab_hdr
->contents
6726 != (unsigned char *) local_syms
))
6731 stub_entry
->target_value
= sym_value
;
6732 stub_entry
->target_section
= sym_sec
;
6733 stub_entry
->stub_type
= stub_type
;
6734 stub_entry
->h
= hash
;
6735 stub_entry
->addend
= irela
->r_addend
;
6736 stub_changed
= TRUE
;
6739 /* We're done with the internal relocs, free them. */
6740 if (elf_section_data (section
)->relocs
!= internal_relocs
)
6741 free (internal_relocs
);
6744 if (local_syms
!= NULL
6745 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6747 if (!info
->keep_memory
)
6750 symtab_hdr
->contents
= (unsigned char *) local_syms
;
6757 /* OK, we've added some stubs. Find out the new size of the
6759 for (stub_sec
= htab
->stub_bfd
->sections
;
6761 stub_sec
= stub_sec
->next
)
6763 stub_sec
->_raw_size
= 0;
6764 stub_sec
->_cooked_size
= 0;
6766 htab
->sbrlt
->_raw_size
= 0;
6767 htab
->sbrlt
->_cooked_size
= 0;
6769 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, htab
);
6771 /* Ask the linker to do its stuff. */
6772 (*htab
->layout_sections_again
) ();
6775 /* It would be nice to strip .branch_lt from the output if the
6776 section is empty, but it's too late. If we strip sections here,
6777 the dynamic symbol table is corrupted since the section symbol
6778 for the stripped section isn't written. */
6783 /* Called after we have determined section placement. If sections
6784 move, we'll be called again. Provide a value for TOCstart. */
6787 ppc64_elf_toc (obfd
)
6793 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
6794 order. The TOC starts where the first of these sections starts. */
6795 s
= bfd_get_section_by_name (obfd
, ".got");
6797 s
= bfd_get_section_by_name (obfd
, ".toc");
6799 s
= bfd_get_section_by_name (obfd
, ".tocbss");
6801 s
= bfd_get_section_by_name (obfd
, ".plt");
6804 /* This may happen for
6805 o references to TOC base (SYM@toc / TOC[tc0]) without a
6808 o --gc-sections and empty TOC sections
6810 FIXME: Warn user? */
6812 /* Look for a likely section. We probably won't even be
6814 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
6815 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
6816 == (SEC_ALLOC
| SEC_SMALL_DATA
))
6819 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
6820 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
6821 == (SEC_ALLOC
| SEC_SMALL_DATA
))
6824 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
6825 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
6828 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
6829 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
6835 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
6840 /* Build all the stubs associated with the current output file.
6841 The stubs are kept in a hash table attached to the main linker
6842 hash table. This function is called via gldelf64ppc_finish. */
6845 ppc64_elf_build_stubs (info
)
6846 struct bfd_link_info
*info
;
6848 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6853 for (stub_sec
= htab
->stub_bfd
->sections
;
6855 stub_sec
= stub_sec
->next
)
6859 /* Allocate memory to hold the linker stubs. */
6860 size
= stub_sec
->_raw_size
;
6863 stub_sec
->contents
= (bfd_byte
*) bfd_zalloc (htab
->stub_bfd
, size
);
6864 if (stub_sec
->contents
== NULL
)
6867 stub_sec
->_cooked_size
= 0;
6870 if (htab
->splt
!= NULL
)
6874 /* Build the .glink plt call stub. */
6875 plt_r2
= (htab
->splt
->output_offset
6876 + htab
->splt
->output_section
->vma
6877 - elf_gp (htab
->splt
->output_section
->owner
)
6879 p
= htab
->sglink
->contents
;
6880 p
= build_plt_stub (htab
->sglink
->owner
, p
, (int) plt_r2
, 1);
6881 while (p
< htab
->sglink
->contents
+ GLINK_CALL_STUB_SIZE
)
6883 bfd_put_32 (htab
->sglink
->owner
, NOP
, p
);
6887 /* Build the .glink lazy link call stubs. */
6889 while (p
< htab
->sglink
->contents
+ htab
->sglink
->_raw_size
)
6893 bfd_put_32 (htab
->sglink
->owner
, LI_R0_0
| indx
, p
);
6898 bfd_put_32 (htab
->sglink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
6900 bfd_put_32 (htab
->sglink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
6903 bfd_put_32 (htab
->sglink
->owner
,
6904 B_DOT
| ((htab
->sglink
->contents
- p
) & 0x3fffffc), p
);
6908 htab
->sglink
->_cooked_size
= p
- htab
->sglink
->contents
;
6911 if (htab
->sbrlt
->_raw_size
!= 0)
6913 htab
->sbrlt
->contents
= (bfd_byte
*) bfd_zalloc (htab
->sbrlt
->owner
,
6914 htab
->sbrlt
->_raw_size
);
6915 if (htab
->sbrlt
->contents
== NULL
)
6919 /* Build the stubs as directed by the stub hash table. */
6920 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
6922 for (stub_sec
= htab
->stub_bfd
->sections
;
6924 stub_sec
= stub_sec
->next
)
6926 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
6930 if (stub_sec
!= NULL
6931 || htab
->sglink
->_raw_size
!= htab
->sglink
->_cooked_size
)
6933 htab
->stub_error
= TRUE
;
6934 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
6937 return !htab
->stub_error
;
6940 /* The RELOCATE_SECTION function is called by the ELF backend linker
6941 to handle the relocations for a section.
6943 The relocs are always passed as Rela structures; if the section
6944 actually uses Rel structures, the r_addend field will always be
6947 This function is responsible for adjust the section contents as
6948 necessary, and (if using Rela relocs and generating a
6949 relocateable output file) adjusting the reloc addend as
6952 This function does not have to worry about setting the reloc
6953 address or the reloc symbol index.
6955 LOCAL_SYMS is a pointer to the swapped in local symbols.
6957 LOCAL_SECTIONS is an array giving the section in the input file
6958 corresponding to the st_shndx field of each local symbol.
6960 The global hash table entry for the global symbols can be found
6961 via elf_sym_hashes (input_bfd).
6963 When generating relocateable output, this function must handle
6964 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6965 going to be the section symbol corresponding to the output
6966 section, which means that the addend must be adjusted
6970 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
6971 contents
, relocs
, local_syms
, local_sections
)
6973 struct bfd_link_info
*info
;
6975 asection
*input_section
;
6977 Elf_Internal_Rela
*relocs
;
6978 Elf_Internal_Sym
*local_syms
;
6979 asection
**local_sections
;
6981 struct ppc_link_hash_table
*htab
;
6982 Elf_Internal_Shdr
*symtab_hdr
;
6983 struct elf_link_hash_entry
**sym_hashes
;
6984 Elf_Internal_Rela
*rel
;
6985 Elf_Internal_Rela
*relend
;
6986 Elf_Internal_Rela outrel
;
6988 struct got_entry
**local_got_ents
;
6990 bfd_boolean ret
= TRUE
;
6992 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
6993 bfd_boolean is_power4
= FALSE
;
6995 if (info
->relocateable
)
6998 /* Initialize howto table if needed. */
6999 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
7002 htab
= ppc_hash_table (info
);
7003 local_got_ents
= elf_local_got_ents (input_bfd
);
7004 TOCstart
= elf_gp (output_bfd
);
7005 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
7006 sym_hashes
= elf_sym_hashes (input_bfd
);
7007 is_opd
= ppc64_elf_section_data (input_section
)->opd
.adjust
!= NULL
;
7010 relend
= relocs
+ input_section
->reloc_count
;
7011 for (; rel
< relend
; rel
++)
7013 enum elf_ppc64_reloc_type r_type
;
7015 bfd_reloc_status_type r
;
7016 Elf_Internal_Sym
*sym
;
7018 struct elf_link_hash_entry
*h
;
7019 struct elf_link_hash_entry
*fdh
;
7020 const char *sym_name
;
7021 unsigned long r_symndx
;
7022 char tls_mask
, tls_gd
, tls_type
;
7024 bfd_boolean unresolved_reloc
;
7027 struct ppc_stub_hash_entry
*stub_entry
;
7028 bfd_vma max_br_offset
;
7031 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
7032 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7033 sym
= (Elf_Internal_Sym
*) 0;
7034 sec
= (asection
*) 0;
7035 h
= (struct elf_link_hash_entry
*) 0;
7036 sym_name
= (const char *) 0;
7037 unresolved_reloc
= FALSE
;
7040 if (r_type
== R_PPC64_TOC
)
7042 /* Relocation value is TOC base. Symbol is ignored. */
7043 relocation
= TOCstart
+ TOC_BASE_OFF
;
7045 else if (r_symndx
< symtab_hdr
->sh_info
)
7047 /* It's a local symbol. */
7048 sym
= local_syms
+ r_symndx
;
7049 sec
= local_sections
[r_symndx
];
7050 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
7051 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
7052 if (elf_section_data (sec
) != NULL
)
7054 long *opd_sym_adjust
;
7056 opd_sym_adjust
= ppc64_elf_section_data (sec
)->opd
.adjust
;
7057 if (opd_sym_adjust
!= NULL
&& sym
->st_value
% 24 == 0)
7058 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
7063 /* It's a global symbol. */
7064 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7065 while (h
->root
.type
== bfd_link_hash_indirect
7066 || h
->root
.type
== bfd_link_hash_warning
)
7067 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7068 sym_name
= h
->root
.root
.string
;
7070 if (h
->root
.type
== bfd_link_hash_defined
7071 || h
->root
.type
== bfd_link_hash_defweak
)
7073 sec
= h
->root
.u
.def
.section
;
7074 if (sec
->output_section
== NULL
)
7075 /* Set a flag that will be cleared later if we find a
7076 relocation value for this symbol. output_section
7077 is typically NULL for symbols satisfied by a shared
7079 unresolved_reloc
= TRUE
;
7081 relocation
= (h
->root
.u
.def
.value
7082 + sec
->output_section
->vma
7083 + sec
->output_offset
);
7085 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7087 else if (info
->shared
7088 && !info
->no_undefined
7089 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
7093 if (! ((*info
->callbacks
->undefined_symbol
)
7094 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
7095 rel
->r_offset
, (!info
->shared
7096 || info
->no_undefined
7097 || ELF_ST_VISIBILITY (h
->other
)))))
7103 /* TLS optimizations. Replace instruction sequences and relocs
7104 based on information we collected in tls_optimize. We edit
7105 RELOCS so that --emit-relocs will output something sensible
7106 for the final instruction stream. */
7109 if (IS_PPC64_TLS_RELOC (r_type
))
7112 tls_mask
= ((struct ppc_link_hash_entry
*) h
)->tls_mask
;
7113 else if (local_got_ents
!= NULL
)
7116 lgot_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
7117 tls_mask
= lgot_masks
[r_symndx
];
7121 /* Ensure reloc mapping code below stays sane. */
7122 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
7123 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
7124 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
7125 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
7126 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
7127 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
7128 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
7129 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
7130 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
7131 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
7139 case R_PPC64_TOC16_LO
:
7140 case R_PPC64_TOC16_DS
:
7141 case R_PPC64_TOC16_LO_DS
:
7143 /* Check for toc tls entries. */
7147 retval
= get_tls_mask (&toc_tls
, &local_syms
, rel
, input_bfd
);
7153 tls_mask
= *toc_tls
;
7154 if (r_type
== R_PPC64_TOC16_DS
7155 || r_type
== R_PPC64_TOC16_LO_DS
)
7159 /* If we found a GD reloc pair, then we might be
7160 doing a GD->IE transition. */
7163 tls_gd
= TLS_TPRELGD
;
7164 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7165 goto tls_get_addr_check
;
7167 else if (retval
== 3)
7169 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7170 goto tls_get_addr_check
;
7177 case R_PPC64_GOT_TPREL16_DS
:
7178 case R_PPC64_GOT_TPREL16_LO_DS
:
7181 && (tls_mask
& TLS_TPREL
) == 0)
7184 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
7186 insn
|= 0x3c0d0000; /* addis 0,13,0 */
7187 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
7188 r_type
= R_PPC64_TPREL16_HA
;
7189 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7196 /* Check for toc tls entries. */
7199 if (!get_tls_mask (&toc_tls
, &local_syms
, rel
, input_bfd
))
7203 tls_mask
= *toc_tls
;
7206 && (tls_mask
& TLS_TPREL
) == 0)
7209 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7210 if ((insn
& ((31 << 26) | (31 << 11)))
7211 == ((31 << 26) | (13 << 11)))
7212 rtra
= insn
& ((1 << 26) - (1 << 16));
7213 else if ((insn
& ((31 << 26) | (31 << 16)))
7214 == ((31 << 26) | (13 << 16)))
7215 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
7218 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
7221 else if ((insn
& (31 << 1)) == 23 << 1
7222 && ((insn
& (31 << 6)) < 14 << 6
7223 || ((insn
& (31 << 6)) >= 16 << 6
7224 && (insn
& (31 << 6)) < 24 << 6)))
7225 /* load and store indexed -> dform. */
7226 insn
= (32 | ((insn
>> 6) & 31)) << 26;
7227 else if ((insn
& (31 << 1)) == 21 << 1
7228 && (insn
& (0x1a << 6)) == 0)
7229 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
7230 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
7231 | ((insn
>> 6) & 1));
7232 else if ((insn
& (31 << 1)) == 21 << 1
7233 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
7235 insn
= (58 << 26) | 2;
7239 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7240 r_type
= R_PPC64_TPREL16_LO
;
7241 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7242 /* Was PPC64_TLS which sits on insn boundary, now
7243 PPC64_TPREL16_LO which is at insn+2. */
7248 case R_PPC64_GOT_TLSGD16_HI
:
7249 case R_PPC64_GOT_TLSGD16_HA
:
7250 tls_gd
= TLS_TPRELGD
;
7251 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7255 case R_PPC64_GOT_TLSLD16_HI
:
7256 case R_PPC64_GOT_TLSLD16_HA
:
7257 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7260 if ((tls_mask
& tls_gd
) != 0)
7261 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
7262 + R_PPC64_GOT_TPREL16_DS
);
7265 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
7267 r_type
= R_PPC64_NONE
;
7269 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7273 case R_PPC64_GOT_TLSGD16
:
7274 case R_PPC64_GOT_TLSGD16_LO
:
7275 tls_gd
= TLS_TPRELGD
;
7276 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7277 goto tls_get_addr_check
;
7280 case R_PPC64_GOT_TLSLD16
:
7281 case R_PPC64_GOT_TLSLD16_LO
:
7282 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7285 if (rel
+ 1 < relend
)
7287 enum elf_ppc64_reloc_type r_type2
;
7288 unsigned long r_symndx2
;
7289 struct elf_link_hash_entry
*h2
;
7290 bfd_vma insn1
, insn2
, insn3
;
7293 /* The next instruction should be a call to
7294 __tls_get_addr. Peek at the reloc to be sure. */
7296 = (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rel
[1].r_info
);
7297 r_symndx2
= ELF64_R_SYM (rel
[1].r_info
);
7298 if (r_symndx2
< symtab_hdr
->sh_info
7299 || (r_type2
!= R_PPC64_REL14
7300 && r_type2
!= R_PPC64_REL14_BRTAKEN
7301 && r_type2
!= R_PPC64_REL14_BRNTAKEN
7302 && r_type2
!= R_PPC64_REL24
))
7305 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
7306 while (h2
->root
.type
== bfd_link_hash_indirect
7307 || h2
->root
.type
== bfd_link_hash_warning
)
7308 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
7309 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
7312 /* OK, it checks out. Replace the call. */
7313 offset
= rel
[1].r_offset
;
7314 insn1
= bfd_get_32 (output_bfd
,
7315 contents
+ rel
->r_offset
- 2);
7316 insn3
= bfd_get_32 (output_bfd
,
7317 contents
+ offset
+ 4);
7318 if ((tls_mask
& tls_gd
) != 0)
7321 insn1
&= (1 << 26) - (1 << 2);
7322 insn1
|= 58 << 26; /* ld */
7323 insn2
= 0x7c636a14; /* add 3,3,13 */
7324 rel
[1].r_info
= ELF64_R_INFO (r_symndx2
, R_PPC64_NONE
);
7325 if ((tls_mask
& TLS_EXPLICIT
) == 0)
7326 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
7327 + R_PPC64_GOT_TPREL16_DS
);
7329 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
7330 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7335 insn1
= 0x3c6d0000; /* addis 3,13,0 */
7336 insn2
= 0x38630000; /* addi 3,3,0 */
7339 /* Was an LD reloc. */
7341 rel
->r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
7342 rel
[1].r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
7344 r_type
= R_PPC64_TPREL16_HA
;
7345 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7346 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
7347 R_PPC64_TPREL16_LO
);
7348 rel
[1].r_offset
+= 2;
7351 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
7355 rel
[1].r_offset
+= 4;
7357 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
7358 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7359 bfd_put_32 (output_bfd
, insn3
, contents
+ offset
+ 4);
7362 /* We changed the symbol on an LD reloc. Start over
7363 in order to get h, sym, sec etc. right. */
7371 case R_PPC64_DTPMOD64
:
7372 if (rel
+ 1 < relend
7373 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
7374 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7376 if ((tls_mask
& TLS_GD
) == 0)
7378 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
7379 if ((tls_mask
& TLS_TPRELGD
) != 0)
7380 r_type
= R_PPC64_TPREL64
;
7383 bfd_put_64 (output_bfd
, (bfd_vma
) 1,
7384 contents
+ rel
->r_offset
);
7385 r_type
= R_PPC64_NONE
;
7387 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7392 if ((tls_mask
& TLS_LD
) == 0)
7394 bfd_put_64 (output_bfd
, (bfd_vma
) 1,
7395 contents
+ rel
->r_offset
);
7396 r_type
= R_PPC64_NONE
;
7397 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7402 case R_PPC64_TPREL64
:
7403 if ((tls_mask
& TLS_TPREL
) == 0)
7405 r_type
= R_PPC64_NONE
;
7406 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7411 /* Handle other relocations that tweak non-addend part of insn. */
7418 /* Branch taken prediction relocations. */
7419 case R_PPC64_ADDR14_BRTAKEN
:
7420 case R_PPC64_REL14_BRTAKEN
:
7421 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
7424 /* Branch not taken prediction relocations. */
7425 case R_PPC64_ADDR14_BRNTAKEN
:
7426 case R_PPC64_REL14_BRNTAKEN
:
7427 insn
|= bfd_get_32 (output_bfd
,
7428 contents
+ rel
->r_offset
) & ~(0x01 << 21);
7431 /* Set 'a' bit. This is 0b00010 in BO field for branch
7432 on CR(BI) insns (BO == 001at or 011at), and 0b01000
7433 for branch on CTR insns (BO == 1a00t or 1a01t). */
7434 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7436 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7443 from
= (rel
->r_offset
7444 + input_section
->output_offset
7445 + input_section
->output_section
->vma
);
7447 /* Invert 'y' bit if not the default. */
7448 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
7452 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ rel
->r_offset
);
7456 /* A REL24 branching to a linkage function is followed by a
7457 nop. We replace the nop with a ld in order to restore
7458 the TOC base pointer. Only calls to shared objects need
7459 to alter the TOC base. These are recognized by their
7460 need for a PLT entry. */
7462 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
7463 && fdh
->plt
.plist
!= NULL
7464 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
7465 rel
, htab
)) != NULL
)
7467 bfd_boolean can_plt_call
= 0;
7469 if (rel
->r_offset
+ 8 <= input_section
->_cooked_size
)
7471 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
7473 || insn
== CROR_151515
|| insn
== CROR_313131
)
7475 bfd_put_32 (input_bfd
, (bfd_vma
) LD_R2_40R1
,
7476 contents
+ rel
->r_offset
+ 4);
7483 /* If this is a plain branch rather than a branch
7484 and link, don't require a nop. */
7485 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7486 if ((insn
& 1) == 0)
7492 relocation
= (stub_entry
->stub_offset
7493 + stub_entry
->stub_sec
->output_offset
7494 + stub_entry
->stub_sec
->output_section
->vma
);
7495 unresolved_reloc
= FALSE
;
7500 && h
->root
.type
== bfd_link_hash_undefweak
7502 && rel
->r_addend
== 0)
7504 /* Tweak calls to undefined weak functions to point at a
7505 blr. We can thus call a weak function without first
7506 checking whether the function is defined. We have a
7507 blr at the end of .sfpr. */
7508 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
7509 relocation
= (htab
->sfpr
->_raw_size
- 4
7510 + htab
->sfpr
->output_offset
7511 + htab
->sfpr
->output_section
->vma
);
7512 from
= (rel
->r_offset
7513 + input_section
->output_offset
7514 + input_section
->output_section
->vma
);
7516 /* But let's not be silly about it. If the blr isn't in
7517 reach, just go to the next instruction. */
7518 if (relocation
- from
+ (1 << 25) >= (1 << 26)
7519 || htab
->sfpr
->_raw_size
== 0)
7520 relocation
= from
+ 4;
7527 addend
= rel
->r_addend
;
7531 (*_bfd_error_handler
)
7532 (_("%s: unknown relocation type %d for symbol %s"),
7533 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
7535 bfd_set_error (bfd_error_bad_value
);
7541 case R_PPC64_GNU_VTINHERIT
:
7542 case R_PPC64_GNU_VTENTRY
:
7545 /* GOT16 relocations. Like an ADDR16 using the symbol's
7546 address in the GOT as relocation value instead of the
7547 symbol's value itself. Also, create a GOT entry for the
7548 symbol and put the symbol value there. */
7549 case R_PPC64_GOT_TLSGD16
:
7550 case R_PPC64_GOT_TLSGD16_LO
:
7551 case R_PPC64_GOT_TLSGD16_HI
:
7552 case R_PPC64_GOT_TLSGD16_HA
:
7553 tls_type
= TLS_TLS
| TLS_GD
;
7556 case R_PPC64_GOT_TLSLD16
:
7557 case R_PPC64_GOT_TLSLD16_LO
:
7558 case R_PPC64_GOT_TLSLD16_HI
:
7559 case R_PPC64_GOT_TLSLD16_HA
:
7560 tls_type
= TLS_TLS
| TLS_LD
;
7563 case R_PPC64_GOT_TPREL16_DS
:
7564 case R_PPC64_GOT_TPREL16_LO_DS
:
7565 case R_PPC64_GOT_TPREL16_HI
:
7566 case R_PPC64_GOT_TPREL16_HA
:
7567 tls_type
= TLS_TLS
| TLS_TPREL
;
7570 case R_PPC64_GOT_DTPREL16_DS
:
7571 case R_PPC64_GOT_DTPREL16_LO_DS
:
7572 case R_PPC64_GOT_DTPREL16_HI
:
7573 case R_PPC64_GOT_DTPREL16_HA
:
7574 tls_type
= TLS_TLS
| TLS_DTPREL
;
7578 case R_PPC64_GOT16_LO
:
7579 case R_PPC64_GOT16_HI
:
7580 case R_PPC64_GOT16_HA
:
7581 case R_PPC64_GOT16_DS
:
7582 case R_PPC64_GOT16_LO_DS
:
7585 /* Relocation is to the entry for this symbol in the global
7589 unsigned long indx
= 0;
7591 if (htab
->sgot
== NULL
)
7594 if (tls_type
== (TLS_TLS
| TLS_LD
)
7596 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
7597 offp
= &htab
->tlsld_got
.offset
;
7600 struct got_entry
*ent
;
7604 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
7605 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
7607 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
7608 /* This is actually a static link, or it is a
7609 -Bsymbolic link and the symbol is defined
7610 locally, or the symbol was forced to be local
7611 because of a version file. */
7616 unresolved_reloc
= FALSE
;
7622 if (local_got_ents
== NULL
)
7624 ent
= local_got_ents
[r_symndx
];
7627 for (; ent
!= NULL
; ent
= ent
->next
)
7628 if (ent
->addend
== rel
->r_addend
7629 && ent
->tls_type
== tls_type
)
7633 offp
= &ent
->got
.offset
;
7636 /* The offset must always be a multiple of 8. We use the
7637 least significant bit to record whether we have already
7638 processed this entry. */
7644 /* Generate relocs for the dynamic linker, except in
7645 the case of TLSLD where we'll use one entry per
7648 if ((info
->shared
|| indx
!= 0)
7650 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7651 || h
->root
.type
!= bfd_link_hash_undefweak
))
7653 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
7654 + htab
->sgot
->output_offset
7656 if (tls_type
& (TLS_LD
| TLS_GD
))
7658 outrel
.r_addend
= 0;
7659 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
7660 if (tls_type
== (TLS_TLS
| TLS_GD
))
7662 loc
= htab
->srelgot
->contents
;
7663 loc
+= (htab
->srelgot
->reloc_count
++
7664 * sizeof (Elf64_External_Rela
));
7665 bfd_elf64_swap_reloca_out (output_bfd
,
7667 outrel
.r_offset
+= 8;
7669 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
7672 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
7673 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
7674 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
7675 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
7677 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_RELATIVE
);
7679 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
7680 outrel
.r_addend
= rel
->r_addend
;
7683 outrel
.r_addend
+= relocation
;
7684 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
7685 outrel
.r_addend
-= htab
->tls_sec
->vma
;
7687 loc
= htab
->srelgot
->contents
;
7688 loc
+= (htab
->srelgot
->reloc_count
++
7689 * sizeof (Elf64_External_Rela
));
7690 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
7693 /* Init the .got section contents if we're not
7694 emitting a reloc. */
7697 relocation
+= rel
->r_addend
;
7698 if (tls_type
== (TLS_TLS
| TLS_LD
))
7700 else if (tls_type
!= 0)
7702 relocation
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
7703 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
7704 relocation
+= DTP_OFFSET
- TP_OFFSET
;
7706 if (tls_type
== (TLS_TLS
| TLS_GD
))
7708 bfd_put_64 (output_bfd
, relocation
,
7709 htab
->sgot
->contents
+ off
+ 8);
7714 bfd_put_64 (output_bfd
, relocation
,
7715 htab
->sgot
->contents
+ off
);
7719 if (off
>= (bfd_vma
) -2)
7722 relocation
= htab
->sgot
->output_offset
+ off
;
7724 /* TOC base (r2) is TOC start plus 0x8000. */
7725 addend
= - TOC_BASE_OFF
;
7729 case R_PPC64_PLT16_HA
:
7730 case R_PPC64_PLT16_HI
:
7731 case R_PPC64_PLT16_LO
:
7734 /* Relocation is to the entry for this symbol in the
7735 procedure linkage table. */
7737 /* Resolve a PLT reloc against a local symbol directly,
7738 without using the procedure linkage table. */
7742 /* It's possible that we didn't make a PLT entry for this
7743 symbol. This happens when statically linking PIC code,
7744 or when using -Bsymbolic. Go find a match if there is a
7746 if (htab
->splt
!= NULL
)
7748 struct plt_entry
*ent
;
7749 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7750 if (ent
->addend
== rel
->r_addend
7751 && ent
->plt
.offset
!= (bfd_vma
) -1)
7753 relocation
= (htab
->splt
->output_section
->vma
7754 + htab
->splt
->output_offset
7756 unresolved_reloc
= FALSE
;
7761 /* TOC16 relocs. We want the offset relative to the TOC base,
7762 which is the address of the start of the TOC plus 0x8000.
7763 The TOC consists of sections .got, .toc, .tocbss, and .plt,
7766 case R_PPC64_TOC16_LO
:
7767 case R_PPC64_TOC16_HI
:
7768 case R_PPC64_TOC16_DS
:
7769 case R_PPC64_TOC16_LO_DS
:
7770 case R_PPC64_TOC16_HA
:
7771 addend
-= TOCstart
+ TOC_BASE_OFF
;
7774 /* Relocate against the beginning of the section. */
7775 case R_PPC64_SECTOFF
:
7776 case R_PPC64_SECTOFF_LO
:
7777 case R_PPC64_SECTOFF_HI
:
7778 case R_PPC64_SECTOFF_DS
:
7779 case R_PPC64_SECTOFF_LO_DS
:
7780 case R_PPC64_SECTOFF_HA
:
7781 if (sec
!= (asection
*) 0)
7782 addend
-= sec
->output_section
->vma
;
7786 case R_PPC64_REL14_BRNTAKEN
:
7787 case R_PPC64_REL14_BRTAKEN
:
7791 case R_PPC64_TPREL16
:
7792 case R_PPC64_TPREL16_LO
:
7793 case R_PPC64_TPREL16_HI
:
7794 case R_PPC64_TPREL16_HA
:
7795 case R_PPC64_TPREL16_DS
:
7796 case R_PPC64_TPREL16_LO_DS
:
7797 case R_PPC64_TPREL16_HIGHER
:
7798 case R_PPC64_TPREL16_HIGHERA
:
7799 case R_PPC64_TPREL16_HIGHEST
:
7800 case R_PPC64_TPREL16_HIGHESTA
:
7801 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
7803 /* The TPREL16 relocs shouldn't really be used in shared
7804 libs as they will result in DT_TEXTREL being set, but
7805 support them anyway. */
7809 case R_PPC64_DTPREL16
:
7810 case R_PPC64_DTPREL16_LO
:
7811 case R_PPC64_DTPREL16_HI
:
7812 case R_PPC64_DTPREL16_HA
:
7813 case R_PPC64_DTPREL16_DS
:
7814 case R_PPC64_DTPREL16_LO_DS
:
7815 case R_PPC64_DTPREL16_HIGHER
:
7816 case R_PPC64_DTPREL16_HIGHERA
:
7817 case R_PPC64_DTPREL16_HIGHEST
:
7818 case R_PPC64_DTPREL16_HIGHESTA
:
7819 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
7822 case R_PPC64_DTPMOD64
:
7827 case R_PPC64_TPREL64
:
7828 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
7831 case R_PPC64_DTPREL64
:
7832 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
7835 /* Relocations that may need to be propagated if this is a
7840 case R_PPC64_ADDR14
:
7841 case R_PPC64_ADDR14_BRNTAKEN
:
7842 case R_PPC64_ADDR14_BRTAKEN
:
7843 case R_PPC64_ADDR16
:
7844 case R_PPC64_ADDR16_DS
:
7845 case R_PPC64_ADDR16_HA
:
7846 case R_PPC64_ADDR16_HI
:
7847 case R_PPC64_ADDR16_HIGHER
:
7848 case R_PPC64_ADDR16_HIGHERA
:
7849 case R_PPC64_ADDR16_HIGHEST
:
7850 case R_PPC64_ADDR16_HIGHESTA
:
7851 case R_PPC64_ADDR16_LO
:
7852 case R_PPC64_ADDR16_LO_DS
:
7853 case R_PPC64_ADDR24
:
7854 case R_PPC64_ADDR32
:
7855 case R_PPC64_ADDR64
:
7856 case R_PPC64_UADDR16
:
7857 case R_PPC64_UADDR32
:
7858 case R_PPC64_UADDR64
:
7859 /* r_symndx will be zero only for relocs against symbols
7860 from removed linkonce sections, or sections discarded by
7868 if ((input_section
->flags
& SEC_ALLOC
) == 0)
7871 if (NO_OPD_RELOCS
&& is_opd
)
7876 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7877 || h
->root
.type
!= bfd_link_hash_undefweak
)
7878 && (MUST_BE_DYN_RELOC (r_type
)
7880 && !SYMBOL_CALLS_LOCAL (info
, h
))))
7881 || (ELIMINATE_COPY_RELOCS
7885 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
7886 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
7887 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
7889 Elf_Internal_Rela outrel
;
7890 bfd_boolean skip
, relocate
;
7894 /* When generating a dynamic object, these relocations
7895 are copied into the output file to be resolved at run
7902 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
7904 if (outrel
.r_offset
== (bfd_vma
) -1)
7906 else if (outrel
.r_offset
== (bfd_vma
) -2)
7907 skip
= TRUE
, relocate
= TRUE
;
7908 outrel
.r_offset
+= (input_section
->output_section
->vma
7909 + input_section
->output_offset
);
7910 outrel
.r_addend
= rel
->r_addend
;
7913 memset (&outrel
, 0, sizeof outrel
);
7915 && !SYMBOL_REFERENCES_LOCAL (info
, h
)
7917 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
7920 /* This symbol is local, or marked to become local,
7921 or this is an opd section reloc which must point
7922 at a local function. */
7923 outrel
.r_addend
+= relocation
;
7926 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
7928 if (is_opd
&& h
!= NULL
)
7930 /* Lie about opd entries. This case occurs
7931 when building shared libraries and we
7932 reference a function in another shared
7933 lib. The same thing happens for a weak
7934 definition in an application that's
7935 overridden by a strong definition in a
7936 shared lib. (I believe this is a generic
7937 bug in binutils handling of weak syms.)
7938 In these cases we won't use the opd
7939 entry in this lib. */
7940 unresolved_reloc
= FALSE
;
7942 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
7948 if (bfd_is_abs_section (sec
))
7950 else if (sec
== NULL
|| sec
->owner
== NULL
)
7952 bfd_set_error (bfd_error_bad_value
);
7959 osec
= sec
->output_section
;
7960 indx
= elf_section_data (osec
)->dynindx
;
7962 /* We are turning this relocation into one
7963 against a section symbol, so subtract out
7964 the output section's address but not the
7965 offset of the input section in the output
7967 outrel
.r_addend
-= osec
->vma
;
7970 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
7974 sreloc
= elf_section_data (input_section
)->sreloc
;
7978 loc
= sreloc
->contents
;
7979 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
7980 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
7982 /* If this reloc is against an external symbol, it will
7983 be computed at runtime, so there's no need to do
7991 case R_PPC64_GLOB_DAT
:
7992 case R_PPC64_JMP_SLOT
:
7993 case R_PPC64_RELATIVE
:
7994 /* We shouldn't ever see these dynamic relocs in relocatable
7998 case R_PPC64_PLTGOT16
:
7999 case R_PPC64_PLTGOT16_DS
:
8000 case R_PPC64_PLTGOT16_HA
:
8001 case R_PPC64_PLTGOT16_HI
:
8002 case R_PPC64_PLTGOT16_LO
:
8003 case R_PPC64_PLTGOT16_LO_DS
:
8004 case R_PPC64_PLTREL32
:
8005 case R_PPC64_PLTREL64
:
8006 /* These ones haven't been implemented yet. */
8008 (*_bfd_error_handler
)
8009 (_("%s: relocation %s is not supported for symbol %s."),
8010 bfd_archive_filename (input_bfd
),
8011 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
8013 bfd_set_error (bfd_error_invalid_operation
);
8018 /* Do any further special processing. */
8024 case R_PPC64_ADDR16_HA
:
8025 case R_PPC64_ADDR16_HIGHERA
:
8026 case R_PPC64_ADDR16_HIGHESTA
:
8027 case R_PPC64_GOT16_HA
:
8028 case R_PPC64_PLTGOT16_HA
:
8029 case R_PPC64_PLT16_HA
:
8030 case R_PPC64_TOC16_HA
:
8031 case R_PPC64_SECTOFF_HA
:
8032 case R_PPC64_TPREL16_HA
:
8033 case R_PPC64_DTPREL16_HA
:
8034 case R_PPC64_GOT_TLSGD16_HA
:
8035 case R_PPC64_GOT_TLSLD16_HA
:
8036 case R_PPC64_GOT_TPREL16_HA
:
8037 case R_PPC64_GOT_DTPREL16_HA
:
8038 case R_PPC64_TPREL16_HIGHER
:
8039 case R_PPC64_TPREL16_HIGHERA
:
8040 case R_PPC64_TPREL16_HIGHEST
:
8041 case R_PPC64_TPREL16_HIGHESTA
:
8042 case R_PPC64_DTPREL16_HIGHER
:
8043 case R_PPC64_DTPREL16_HIGHERA
:
8044 case R_PPC64_DTPREL16_HIGHEST
:
8045 case R_PPC64_DTPREL16_HIGHESTA
:
8046 /* It's just possible that this symbol is a weak symbol
8047 that's not actually defined anywhere. In that case,
8048 'sec' would be NULL, and we should leave the symbol
8049 alone (it will be set to zero elsewhere in the link). */
8051 /* Add 0x10000 if sign bit in 0:15 is set.
8052 Bits 0:15 are not used. */
8056 case R_PPC64_ADDR16_DS
:
8057 case R_PPC64_ADDR16_LO_DS
:
8058 case R_PPC64_GOT16_DS
:
8059 case R_PPC64_GOT16_LO_DS
:
8060 case R_PPC64_PLT16_LO_DS
:
8061 case R_PPC64_SECTOFF_DS
:
8062 case R_PPC64_SECTOFF_LO_DS
:
8063 case R_PPC64_TOC16_DS
:
8064 case R_PPC64_TOC16_LO_DS
:
8065 case R_PPC64_PLTGOT16_DS
:
8066 case R_PPC64_PLTGOT16_LO_DS
:
8067 case R_PPC64_GOT_TPREL16_DS
:
8068 case R_PPC64_GOT_TPREL16_LO_DS
:
8069 case R_PPC64_GOT_DTPREL16_DS
:
8070 case R_PPC64_GOT_DTPREL16_LO_DS
:
8071 case R_PPC64_TPREL16_DS
:
8072 case R_PPC64_TPREL16_LO_DS
:
8073 case R_PPC64_DTPREL16_DS
:
8074 case R_PPC64_DTPREL16_LO_DS
:
8075 if (((relocation
+ addend
) & 3) != 0)
8077 (*_bfd_error_handler
)
8078 (_("%s: error: relocation %s not a multiple of 4"),
8079 bfd_archive_filename (input_bfd
),
8080 ppc64_elf_howto_table
[(int) r_type
]->name
);
8081 bfd_set_error (bfd_error_bad_value
);
8088 case R_PPC64_REL14_BRNTAKEN
:
8089 case R_PPC64_REL14_BRTAKEN
:
8090 max_br_offset
= 1 << 15;
8094 max_br_offset
= 1 << 25;
8097 /* If the branch is out of reach, then redirect the
8098 call to the local stub for this function. */
8099 from
= (rel
->r_offset
8100 + input_section
->output_offset
8101 + input_section
->output_section
->vma
);
8102 if (relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
8103 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
8104 rel
, htab
)) != NULL
)
8106 /* Munge up the value and addend so that we call the stub
8107 rather than the procedure directly. */
8108 relocation
= (stub_entry
->stub_offset
8109 + stub_entry
->stub_sec
->output_offset
8110 + stub_entry
->stub_sec
->output_section
->vma
);
8116 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8117 because such sections are not SEC_ALLOC and thus ld.so will
8118 not process them. */
8119 if (unresolved_reloc
8120 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8121 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
8123 (*_bfd_error_handler
)
8124 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
8125 bfd_archive_filename (input_bfd
),
8126 bfd_get_section_name (input_bfd
, input_section
),
8127 (long) rel
->r_offset
,
8128 ppc64_elf_howto_table
[(int) r_type
]->name
,
8129 h
->root
.root
.string
);
8133 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
8141 if (r
!= bfd_reloc_ok
)
8143 if (sym_name
== NULL
)
8144 sym_name
= "(null)";
8145 if (r
== bfd_reloc_overflow
)
8150 && h
->root
.type
== bfd_link_hash_undefweak
8151 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
8153 /* Assume this is a call protected by other code that
8154 detects the symbol is undefined. If this is the case,
8155 we can safely ignore the overflow. If not, the
8156 program is hosed anyway, and a little warning isn't
8162 if (!((*info
->callbacks
->reloc_overflow
)
8163 (info
, sym_name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
8164 rel
->r_addend
, input_bfd
, input_section
, rel
->r_offset
)))
8169 (*_bfd_error_handler
)
8170 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
8171 bfd_archive_filename (input_bfd
),
8172 bfd_get_section_name (input_bfd
, input_section
),
8173 (long) rel
->r_offset
,
8174 ppc64_elf_howto_table
[(int) r_type
]->name
,
8185 /* Finish up dynamic symbol handling. We set the contents of various
8186 dynamic sections here. */
8189 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
8191 struct bfd_link_info
*info
;
8192 struct elf_link_hash_entry
*h
;
8193 Elf_Internal_Sym
*sym
;
8195 struct ppc_link_hash_table
*htab
;
8198 htab
= ppc_hash_table (info
);
8199 dynobj
= htab
->elf
.dynobj
;
8201 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
8203 struct plt_entry
*ent
;
8204 Elf_Internal_Rela rela
;
8207 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8208 if (ent
->plt
.offset
!= (bfd_vma
) -1)
8210 /* This symbol has an entry in the procedure linkage
8211 table. Set it up. */
8213 if (htab
->splt
== NULL
8214 || htab
->srelplt
== NULL
8215 || htab
->sglink
== NULL
)
8218 /* Create a JMP_SLOT reloc to inform the dynamic linker to
8219 fill in the PLT entry. */
8220 rela
.r_offset
= (htab
->splt
->output_section
->vma
8221 + htab
->splt
->output_offset
8223 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
8224 rela
.r_addend
= ent
->addend
;
8226 loc
= htab
->srelplt
->contents
;
8227 loc
+= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
8228 * sizeof (Elf64_External_Rela
));
8229 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
8233 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
8235 Elf_Internal_Rela rela
;
8238 /* This symbol needs a copy reloc. Set it up. */
8240 if (h
->dynindx
== -1
8241 || (h
->root
.type
!= bfd_link_hash_defined
8242 && h
->root
.type
!= bfd_link_hash_defweak
)
8243 || htab
->srelbss
== NULL
)
8246 rela
.r_offset
= (h
->root
.u
.def
.value
8247 + h
->root
.u
.def
.section
->output_section
->vma
8248 + h
->root
.u
.def
.section
->output_offset
);
8249 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
8251 loc
= htab
->srelbss
->contents
;
8252 loc
+= htab
->srelbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8253 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
8256 /* Mark some specially defined symbols as absolute. */
8257 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
8258 sym
->st_shndx
= SHN_ABS
;
8263 /* Used to decide how to sort relocs in an optimal manner for the
8264 dynamic linker, before writing them out. */
8266 static enum elf_reloc_type_class
8267 ppc64_elf_reloc_type_class (rela
)
8268 const Elf_Internal_Rela
*rela
;
8270 enum elf_ppc64_reloc_type r_type
;
8272 r_type
= (enum elf_ppc64_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
8275 case R_PPC64_RELATIVE
:
8276 return reloc_class_relative
;
8277 case R_PPC64_JMP_SLOT
:
8278 return reloc_class_plt
;
8280 return reloc_class_copy
;
8282 return reloc_class_normal
;
8286 /* Finish up the dynamic sections. */
8289 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
8291 struct bfd_link_info
*info
;
8293 struct ppc_link_hash_table
*htab
;
8297 htab
= ppc_hash_table (info
);
8298 dynobj
= htab
->elf
.dynobj
;
8299 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8301 if (htab
->elf
.dynamic_sections_created
)
8303 Elf64_External_Dyn
*dyncon
, *dynconend
;
8305 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
8308 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
8309 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
8310 for (; dyncon
< dynconend
; dyncon
++)
8312 Elf_Internal_Dyn dyn
;
8315 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8322 case DT_PPC64_GLINK
:
8324 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8328 s
= bfd_get_section_by_name (output_bfd
, ".opd");
8331 dyn
.d_un
.d_ptr
= s
->vma
;
8334 case DT_PPC64_OPDSZ
:
8335 s
= bfd_get_section_by_name (output_bfd
, ".opd");
8338 dyn
.d_un
.d_val
= s
->_raw_size
;
8343 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8348 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8352 dyn
.d_un
.d_val
= htab
->srelplt
->_raw_size
;
8356 /* Don't count procedure linkage table relocs in the
8357 overall reloc count. */
8361 dyn
.d_un
.d_val
-= s
->_raw_size
;
8365 /* We may not be using the standard ELF linker script.
8366 If .rela.plt is the first .rela section, we adjust
8367 DT_RELA to not include it. */
8371 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
8373 dyn
.d_un
.d_ptr
+= s
->_raw_size
;
8377 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8381 if (htab
->sgot
!= NULL
&& htab
->sgot
->_raw_size
!= 0)
8383 /* Fill in the first entry in the global offset table.
8384 We use it to hold the link-time TOCbase. */
8385 bfd_put_64 (output_bfd
,
8386 elf_gp (output_bfd
) + TOC_BASE_OFF
,
8387 htab
->sgot
->contents
);
8389 /* Set .got entry size. */
8390 elf_section_data (htab
->sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
8393 if (htab
->splt
!= NULL
&& htab
->splt
->_raw_size
!= 0)
8395 /* Set .plt entry size. */
8396 elf_section_data (htab
->splt
->output_section
)->this_hdr
.sh_entsize
8403 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
8404 #define TARGET_LITTLE_NAME "elf64-powerpcle"
8405 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
8406 #define TARGET_BIG_NAME "elf64-powerpc"
8407 #define ELF_ARCH bfd_arch_powerpc
8408 #define ELF_MACHINE_CODE EM_PPC64
8409 #define ELF_MAXPAGESIZE 0x10000
8410 #define elf_info_to_howto ppc64_elf_info_to_howto
8412 #ifdef EM_CYGNUS_POWERPC
8413 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
8417 #define ELF_MACHINE_ALT2 EM_PPC_OLD
8420 #define elf_backend_want_got_sym 0
8421 #define elf_backend_want_plt_sym 0
8422 #define elf_backend_plt_alignment 3
8423 #define elf_backend_plt_not_loaded 1
8424 #define elf_backend_got_symbol_offset 0
8425 #define elf_backend_got_header_size 8
8426 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
8427 #define elf_backend_can_gc_sections 1
8428 #define elf_backend_can_refcount 1
8429 #define elf_backend_rela_normal 1
8431 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
8432 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
8433 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
8434 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
8435 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
8437 #define elf_backend_object_p ppc64_elf_object_p
8438 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
8439 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
8440 #define elf_backend_check_relocs ppc64_elf_check_relocs
8441 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
8442 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
8443 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
8444 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
8445 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
8446 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
8447 #define elf_backend_relocate_section ppc64_elf_relocate_section
8448 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
8449 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
8450 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
8452 #include "elf64-target.h"