1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Written by Linus Nordberg, Swox AB <info@swox.com>,
5 based on elf32-ppc.c by Ian Lance Taylor.
6 Largely rewritten by Alan Modra <amodra@bigpond.net.au>
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License along
21 with this program; if not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
33 #include "elf/ppc64.h"
34 #include "elf64-ppc.h"
36 static bfd_reloc_status_type ppc64_elf_ha_reloc
37 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
38 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
39 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
40 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
41 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
42 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
43 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
44 static bfd_reloc_status_type ppc64_elf_toc_reloc
45 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
46 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
47 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
48 static bfd_reloc_status_type ppc64_elf_toc64_reloc
49 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
50 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
51 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
54 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
55 #define TARGET_LITTLE_NAME "elf64-powerpcle"
56 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
57 #define TARGET_BIG_NAME "elf64-powerpc"
58 #define ELF_ARCH bfd_arch_powerpc
59 #define ELF_MACHINE_CODE EM_PPC64
60 #define ELF_MAXPAGESIZE 0x10000
61 #define elf_info_to_howto ppc64_elf_info_to_howto
63 #define elf_backend_want_got_sym 0
64 #define elf_backend_want_plt_sym 0
65 #define elf_backend_plt_alignment 3
66 #define elf_backend_plt_not_loaded 1
67 #define elf_backend_got_symbol_offset 0
68 #define elf_backend_got_header_size 8
69 #define elf_backend_can_gc_sections 1
70 #define elf_backend_can_refcount 1
71 #define elf_backend_rela_normal 1
73 #define bfd_elf64_mkobject ppc64_elf_mkobject
74 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
75 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
76 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
77 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
78 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
80 #define elf_backend_object_p ppc64_elf_object_p
81 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
82 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
83 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
84 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
85 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
86 #define elf_backend_check_relocs ppc64_elf_check_relocs
87 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
88 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
89 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
90 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
91 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
92 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
93 #define elf_backend_relocate_section ppc64_elf_relocate_section
94 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
95 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
96 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
97 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
98 #define elf_backend_special_sections ppc64_elf_special_sections
100 /* The name of the dynamic interpreter. This is put in the .interp
102 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
104 /* The size in bytes of an entry in the procedure linkage table. */
105 #define PLT_ENTRY_SIZE 24
107 /* The initial size of the plt reserved for the dynamic linker. */
108 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
110 /* TOC base pointers offset from start of TOC. */
111 #define TOC_BASE_OFF 0x8000
113 /* Offset of tp and dtp pointers from start of TLS block. */
114 #define TP_OFFSET 0x7000
115 #define DTP_OFFSET 0x8000
117 /* .plt call stub instructions. The normal stub is like this, but
118 sometimes the .plt entry crosses a 64k boundary and we need to
119 insert an addis to adjust r12. */
120 #define PLT_CALL_STUB_SIZE (7*4)
121 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
122 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
123 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
124 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
125 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
126 /* ld %r11,xxx+16@l(%r12) */
127 #define BCTR 0x4e800420 /* bctr */
130 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
131 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
133 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
135 /* glink call stub instructions. We enter with the index in R0, and the
136 address of glink entry in CTR. From that, we can calculate PLT0. */
137 #define GLINK_CALL_STUB_SIZE (16*4)
138 #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */
139 #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */
140 #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */
141 #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */
142 #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */
143 #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */
144 #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */
145 /* sub %r12,%r12,%r11 */
146 #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */
147 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
148 /* ld %r11,xxx@l(%r12) */
149 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */
152 /* ld %r11,16(%r12) */
156 #define NOP 0x60000000
158 /* Some other nops. */
159 #define CROR_151515 0x4def7b82
160 #define CROR_313131 0x4ffffb82
162 /* .glink entries for the first 32k functions are two instructions. */
163 #define LI_R0_0 0x38000000 /* li %r0,0 */
164 #define B_DOT 0x48000000 /* b . */
166 /* After that, we need two instructions to load the index, followed by
168 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
169 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
171 /* Instructions to save and restore floating point regs. */
172 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
173 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
174 #define BLR 0x4e800020 /* blr */
176 /* Since .opd is an array of descriptors and each entry will end up
177 with identical R_PPC64_RELATIVE relocs, there is really no need to
178 propagate .opd relocs; The dynamic linker should be taught to
179 relocate .opd without reloc entries. */
180 #ifndef NO_OPD_RELOCS
181 #define NO_OPD_RELOCS 0
184 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
186 /* Relocation HOWTO's. */
187 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
189 static reloc_howto_type ppc64_elf_howto_raw[] = {
190 /* This reloc does nothing. */
191 HOWTO (R_PPC64_NONE, /* type */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
195 FALSE, /* pc_relative */
197 complain_overflow_dont, /* complain_on_overflow */
198 bfd_elf_generic_reloc, /* special_function */
199 "R_PPC64_NONE", /* name */
200 FALSE, /* partial_inplace */
203 FALSE), /* pcrel_offset */
205 /* A standard 32 bit relocation. */
206 HOWTO (R_PPC64_ADDR32, /* type */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
210 FALSE, /* pc_relative */
212 complain_overflow_bitfield, /* complain_on_overflow */
213 bfd_elf_generic_reloc, /* special_function */
214 "R_PPC64_ADDR32", /* name */
215 FALSE, /* partial_inplace */
217 0xffffffff, /* dst_mask */
218 FALSE), /* pcrel_offset */
220 /* An absolute 26 bit branch; the lower two bits must be zero.
221 FIXME: we don't check that, we just clear them. */
222 HOWTO (R_PPC64_ADDR24, /* type */
224 2, /* size (0 = byte, 1 = short, 2 = long) */
226 FALSE, /* pc_relative */
228 complain_overflow_bitfield, /* complain_on_overflow */
229 bfd_elf_generic_reloc, /* special_function */
230 "R_PPC64_ADDR24", /* name */
231 FALSE, /* partial_inplace */
233 0x03fffffc, /* dst_mask */
234 FALSE), /* pcrel_offset */
236 /* A standard 16 bit relocation. */
237 HOWTO (R_PPC64_ADDR16, /* type */
239 1, /* size (0 = byte, 1 = short, 2 = long) */
241 FALSE, /* pc_relative */
243 complain_overflow_bitfield, /* complain_on_overflow */
244 bfd_elf_generic_reloc, /* special_function */
245 "R_PPC64_ADDR16", /* name */
246 FALSE, /* partial_inplace */
248 0xffff, /* dst_mask */
249 FALSE), /* pcrel_offset */
251 /* A 16 bit relocation without overflow. */
252 HOWTO (R_PPC64_ADDR16_LO, /* type */
254 1, /* size (0 = byte, 1 = short, 2 = long) */
256 FALSE, /* pc_relative */
258 complain_overflow_dont,/* complain_on_overflow */
259 bfd_elf_generic_reloc, /* special_function */
260 "R_PPC64_ADDR16_LO", /* name */
261 FALSE, /* partial_inplace */
263 0xffff, /* dst_mask */
264 FALSE), /* pcrel_offset */
266 /* Bits 16-31 of an address. */
267 HOWTO (R_PPC64_ADDR16_HI, /* type */
269 1, /* size (0 = byte, 1 = short, 2 = long) */
271 FALSE, /* pc_relative */
273 complain_overflow_dont, /* complain_on_overflow */
274 bfd_elf_generic_reloc, /* special_function */
275 "R_PPC64_ADDR16_HI", /* name */
276 FALSE, /* partial_inplace */
278 0xffff, /* dst_mask */
279 FALSE), /* pcrel_offset */
281 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
282 bits, treated as a signed number, is negative. */
283 HOWTO (R_PPC64_ADDR16_HA, /* type */
285 1, /* size (0 = byte, 1 = short, 2 = long) */
287 FALSE, /* pc_relative */
289 complain_overflow_dont, /* complain_on_overflow */
290 ppc64_elf_ha_reloc, /* special_function */
291 "R_PPC64_ADDR16_HA", /* name */
292 FALSE, /* partial_inplace */
294 0xffff, /* dst_mask */
295 FALSE), /* pcrel_offset */
297 /* An absolute 16 bit branch; the lower two bits must be zero.
298 FIXME: we don't check that, we just clear them. */
299 HOWTO (R_PPC64_ADDR14, /* type */
301 2, /* size (0 = byte, 1 = short, 2 = long) */
303 FALSE, /* pc_relative */
305 complain_overflow_bitfield, /* complain_on_overflow */
306 bfd_elf_generic_reloc, /* special_function */
307 "R_PPC64_ADDR14", /* name */
308 FALSE, /* partial_inplace */
310 0x0000fffc, /* dst_mask */
311 FALSE), /* pcrel_offset */
313 /* An absolute 16 bit branch, for which bit 10 should be set to
314 indicate that the branch is expected to be taken. The lower two
315 bits must be zero. */
316 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
320 FALSE, /* pc_relative */
322 complain_overflow_bitfield, /* complain_on_overflow */
323 ppc64_elf_brtaken_reloc, /* special_function */
324 "R_PPC64_ADDR14_BRTAKEN",/* name */
325 FALSE, /* partial_inplace */
327 0x0000fffc, /* dst_mask */
328 FALSE), /* pcrel_offset */
330 /* An absolute 16 bit branch, for which bit 10 should be set to
331 indicate that the branch is not expected to be taken. The lower
332 two bits must be zero. */
333 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 FALSE, /* pc_relative */
339 complain_overflow_bitfield, /* complain_on_overflow */
340 ppc64_elf_brtaken_reloc, /* special_function */
341 "R_PPC64_ADDR14_BRNTAKEN",/* name */
342 FALSE, /* partial_inplace */
344 0x0000fffc, /* dst_mask */
345 FALSE), /* pcrel_offset */
347 /* A relative 26 bit branch; the lower two bits must be zero. */
348 HOWTO (R_PPC64_REL24, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 TRUE, /* pc_relative */
354 complain_overflow_signed, /* complain_on_overflow */
355 bfd_elf_generic_reloc, /* special_function */
356 "R_PPC64_REL24", /* name */
357 FALSE, /* partial_inplace */
359 0x03fffffc, /* dst_mask */
360 TRUE), /* pcrel_offset */
362 /* A relative 16 bit branch; the lower two bits must be zero. */
363 HOWTO (R_PPC64_REL14, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 TRUE, /* pc_relative */
369 complain_overflow_signed, /* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_PPC64_REL14", /* name */
372 FALSE, /* partial_inplace */
374 0x0000fffc, /* dst_mask */
375 TRUE), /* pcrel_offset */
377 /* A relative 16 bit branch. Bit 10 should be set to indicate that
378 the branch is expected to be taken. The lower two bits must be
380 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 TRUE, /* pc_relative */
386 complain_overflow_signed, /* complain_on_overflow */
387 ppc64_elf_brtaken_reloc, /* special_function */
388 "R_PPC64_REL14_BRTAKEN", /* name */
389 FALSE, /* partial_inplace */
391 0x0000fffc, /* dst_mask */
392 TRUE), /* pcrel_offset */
394 /* A relative 16 bit branch. Bit 10 should be set to indicate that
395 the branch is not expected to be taken. The lower two bits must
397 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 TRUE, /* pc_relative */
403 complain_overflow_signed, /* complain_on_overflow */
404 ppc64_elf_brtaken_reloc, /* special_function */
405 "R_PPC64_REL14_BRNTAKEN",/* name */
406 FALSE, /* partial_inplace */
408 0x0000fffc, /* dst_mask */
409 TRUE), /* pcrel_offset */
411 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
413 HOWTO (R_PPC64_GOT16, /* type */
415 1, /* size (0 = byte, 1 = short, 2 = long) */
417 FALSE, /* pc_relative */
419 complain_overflow_signed, /* complain_on_overflow */
420 ppc64_elf_unhandled_reloc, /* special_function */
421 "R_PPC64_GOT16", /* name */
422 FALSE, /* partial_inplace */
424 0xffff, /* dst_mask */
425 FALSE), /* pcrel_offset */
427 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
429 HOWTO (R_PPC64_GOT16_LO, /* type */
431 1, /* size (0 = byte, 1 = short, 2 = long) */
433 FALSE, /* pc_relative */
435 complain_overflow_dont, /* complain_on_overflow */
436 ppc64_elf_unhandled_reloc, /* special_function */
437 "R_PPC64_GOT16_LO", /* name */
438 FALSE, /* partial_inplace */
440 0xffff, /* dst_mask */
441 FALSE), /* pcrel_offset */
443 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
445 HOWTO (R_PPC64_GOT16_HI, /* type */
447 1, /* size (0 = byte, 1 = short, 2 = long) */
449 FALSE, /* pc_relative */
451 complain_overflow_dont,/* complain_on_overflow */
452 ppc64_elf_unhandled_reloc, /* special_function */
453 "R_PPC64_GOT16_HI", /* name */
454 FALSE, /* partial_inplace */
456 0xffff, /* dst_mask */
457 FALSE), /* pcrel_offset */
459 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
461 HOWTO (R_PPC64_GOT16_HA, /* type */
463 1, /* size (0 = byte, 1 = short, 2 = long) */
465 FALSE, /* pc_relative */
467 complain_overflow_dont,/* complain_on_overflow */
468 ppc64_elf_unhandled_reloc, /* special_function */
469 "R_PPC64_GOT16_HA", /* name */
470 FALSE, /* partial_inplace */
472 0xffff, /* dst_mask */
473 FALSE), /* pcrel_offset */
475 /* This is used only by the dynamic linker. The symbol should exist
476 both in the object being run and in some shared library. The
477 dynamic linker copies the data addressed by the symbol from the
478 shared library into the object, because the object being
479 run has to have the data at some particular address. */
480 HOWTO (R_PPC64_COPY, /* type */
482 0, /* this one is variable size */
484 FALSE, /* pc_relative */
486 complain_overflow_dont, /* complain_on_overflow */
487 ppc64_elf_unhandled_reloc, /* special_function */
488 "R_PPC64_COPY", /* name */
489 FALSE, /* partial_inplace */
492 FALSE), /* pcrel_offset */
494 /* Like R_PPC64_ADDR64, but used when setting global offset table
496 HOWTO (R_PPC64_GLOB_DAT, /* type */
498 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
500 FALSE, /* pc_relative */
502 complain_overflow_dont, /* complain_on_overflow */
503 ppc64_elf_unhandled_reloc, /* special_function */
504 "R_PPC64_GLOB_DAT", /* name */
505 FALSE, /* partial_inplace */
507 ONES (64), /* dst_mask */
508 FALSE), /* pcrel_offset */
510 /* Created by the link editor. Marks a procedure linkage table
511 entry for a symbol. */
512 HOWTO (R_PPC64_JMP_SLOT, /* type */
514 0, /* size (0 = byte, 1 = short, 2 = long) */
516 FALSE, /* pc_relative */
518 complain_overflow_dont, /* complain_on_overflow */
519 ppc64_elf_unhandled_reloc, /* special_function */
520 "R_PPC64_JMP_SLOT", /* name */
521 FALSE, /* partial_inplace */
524 FALSE), /* pcrel_offset */
526 /* Used only by the dynamic linker. When the object is run, this
527 doubleword64 is set to the load address of the object, plus the
529 HOWTO (R_PPC64_RELATIVE, /* type */
531 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
533 FALSE, /* pc_relative */
535 complain_overflow_dont, /* complain_on_overflow */
536 bfd_elf_generic_reloc, /* special_function */
537 "R_PPC64_RELATIVE", /* name */
538 FALSE, /* partial_inplace */
540 ONES (64), /* dst_mask */
541 FALSE), /* pcrel_offset */
543 /* Like R_PPC64_ADDR32, but may be unaligned. */
544 HOWTO (R_PPC64_UADDR32, /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 FALSE, /* pc_relative */
550 complain_overflow_bitfield, /* complain_on_overflow */
551 bfd_elf_generic_reloc, /* special_function */
552 "R_PPC64_UADDR32", /* name */
553 FALSE, /* partial_inplace */
555 0xffffffff, /* dst_mask */
556 FALSE), /* pcrel_offset */
558 /* Like R_PPC64_ADDR16, but may be unaligned. */
559 HOWTO (R_PPC64_UADDR16, /* type */
561 1, /* size (0 = byte, 1 = short, 2 = long) */
563 FALSE, /* pc_relative */
565 complain_overflow_bitfield, /* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_PPC64_UADDR16", /* name */
568 FALSE, /* partial_inplace */
570 0xffff, /* dst_mask */
571 FALSE), /* pcrel_offset */
573 /* 32-bit PC relative. */
574 HOWTO (R_PPC64_REL32, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 TRUE, /* pc_relative */
580 /* FIXME: Verify. Was complain_overflow_bitfield. */
581 complain_overflow_signed, /* complain_on_overflow */
582 bfd_elf_generic_reloc, /* special_function */
583 "R_PPC64_REL32", /* name */
584 FALSE, /* partial_inplace */
586 0xffffffff, /* dst_mask */
587 TRUE), /* pcrel_offset */
589 /* 32-bit relocation to the symbol's procedure linkage table. */
590 HOWTO (R_PPC64_PLT32, /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 FALSE, /* pc_relative */
596 complain_overflow_bitfield, /* complain_on_overflow */
597 ppc64_elf_unhandled_reloc, /* special_function */
598 "R_PPC64_PLT32", /* name */
599 FALSE, /* partial_inplace */
601 0xffffffff, /* dst_mask */
602 FALSE), /* pcrel_offset */
604 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
605 FIXME: R_PPC64_PLTREL32 not supported. */
606 HOWTO (R_PPC64_PLTREL32, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 TRUE, /* pc_relative */
612 complain_overflow_signed, /* complain_on_overflow */
613 bfd_elf_generic_reloc, /* special_function */
614 "R_PPC64_PLTREL32", /* name */
615 FALSE, /* partial_inplace */
617 0xffffffff, /* dst_mask */
618 TRUE), /* pcrel_offset */
620 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
622 HOWTO (R_PPC64_PLT16_LO, /* type */
624 1, /* size (0 = byte, 1 = short, 2 = long) */
626 FALSE, /* pc_relative */
628 complain_overflow_dont, /* complain_on_overflow */
629 ppc64_elf_unhandled_reloc, /* special_function */
630 "R_PPC64_PLT16_LO", /* name */
631 FALSE, /* partial_inplace */
633 0xffff, /* dst_mask */
634 FALSE), /* pcrel_offset */
636 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
638 HOWTO (R_PPC64_PLT16_HI, /* type */
640 1, /* size (0 = byte, 1 = short, 2 = long) */
642 FALSE, /* pc_relative */
644 complain_overflow_dont, /* complain_on_overflow */
645 ppc64_elf_unhandled_reloc, /* special_function */
646 "R_PPC64_PLT16_HI", /* name */
647 FALSE, /* partial_inplace */
649 0xffff, /* dst_mask */
650 FALSE), /* pcrel_offset */
652 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
654 HOWTO (R_PPC64_PLT16_HA, /* type */
656 1, /* size (0 = byte, 1 = short, 2 = long) */
658 FALSE, /* pc_relative */
660 complain_overflow_dont, /* complain_on_overflow */
661 ppc64_elf_unhandled_reloc, /* special_function */
662 "R_PPC64_PLT16_HA", /* name */
663 FALSE, /* partial_inplace */
665 0xffff, /* dst_mask */
666 FALSE), /* pcrel_offset */
668 /* 16-bit section relative relocation. */
669 HOWTO (R_PPC64_SECTOFF, /* type */
671 1, /* size (0 = byte, 1 = short, 2 = long) */
673 FALSE, /* pc_relative */
675 complain_overflow_bitfield, /* complain_on_overflow */
676 ppc64_elf_sectoff_reloc, /* special_function */
677 "R_PPC64_SECTOFF", /* name */
678 FALSE, /* partial_inplace */
680 0xffff, /* dst_mask */
681 FALSE), /* pcrel_offset */
683 /* Like R_PPC64_SECTOFF, but no overflow warning. */
684 HOWTO (R_PPC64_SECTOFF_LO, /* type */
686 1, /* size (0 = byte, 1 = short, 2 = long) */
688 FALSE, /* pc_relative */
690 complain_overflow_dont, /* complain_on_overflow */
691 ppc64_elf_sectoff_reloc, /* special_function */
692 "R_PPC64_SECTOFF_LO", /* name */
693 FALSE, /* partial_inplace */
695 0xffff, /* dst_mask */
696 FALSE), /* pcrel_offset */
698 /* 16-bit upper half section relative relocation. */
699 HOWTO (R_PPC64_SECTOFF_HI, /* type */
701 1, /* size (0 = byte, 1 = short, 2 = long) */
703 FALSE, /* pc_relative */
705 complain_overflow_dont, /* complain_on_overflow */
706 ppc64_elf_sectoff_reloc, /* special_function */
707 "R_PPC64_SECTOFF_HI", /* name */
708 FALSE, /* partial_inplace */
710 0xffff, /* dst_mask */
711 FALSE), /* pcrel_offset */
713 /* 16-bit upper half adjusted section relative relocation. */
714 HOWTO (R_PPC64_SECTOFF_HA, /* type */
716 1, /* size (0 = byte, 1 = short, 2 = long) */
718 FALSE, /* pc_relative */
720 complain_overflow_dont, /* complain_on_overflow */
721 ppc64_elf_sectoff_ha_reloc, /* special_function */
722 "R_PPC64_SECTOFF_HA", /* name */
723 FALSE, /* partial_inplace */
725 0xffff, /* dst_mask */
726 FALSE), /* pcrel_offset */
728 /* Like R_PPC64_REL24 without touching the two least significant bits. */
729 HOWTO (R_PPC64_REL30, /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 TRUE, /* pc_relative */
735 complain_overflow_dont, /* complain_on_overflow */
736 bfd_elf_generic_reloc, /* special_function */
737 "R_PPC64_REL30", /* name */
738 FALSE, /* partial_inplace */
740 0xfffffffc, /* dst_mask */
741 TRUE), /* pcrel_offset */
743 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
745 /* A standard 64-bit relocation. */
746 HOWTO (R_PPC64_ADDR64, /* type */
748 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
750 FALSE, /* pc_relative */
752 complain_overflow_dont, /* complain_on_overflow */
753 bfd_elf_generic_reloc, /* special_function */
754 "R_PPC64_ADDR64", /* name */
755 FALSE, /* partial_inplace */
757 ONES (64), /* dst_mask */
758 FALSE), /* pcrel_offset */
760 /* The bits 32-47 of an address. */
761 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
763 1, /* size (0 = byte, 1 = short, 2 = long) */
765 FALSE, /* pc_relative */
767 complain_overflow_dont, /* complain_on_overflow */
768 bfd_elf_generic_reloc, /* special_function */
769 "R_PPC64_ADDR16_HIGHER", /* name */
770 FALSE, /* partial_inplace */
772 0xffff, /* dst_mask */
773 FALSE), /* pcrel_offset */
775 /* The bits 32-47 of an address, plus 1 if the contents of the low
776 16 bits, treated as a signed number, is negative. */
777 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
779 1, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE, /* pc_relative */
783 complain_overflow_dont, /* complain_on_overflow */
784 ppc64_elf_ha_reloc, /* special_function */
785 "R_PPC64_ADDR16_HIGHERA", /* name */
786 FALSE, /* partial_inplace */
788 0xffff, /* dst_mask */
789 FALSE), /* pcrel_offset */
791 /* The bits 48-63 of an address. */
792 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
796 FALSE, /* pc_relative */
798 complain_overflow_dont, /* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_PPC64_ADDR16_HIGHEST", /* name */
801 FALSE, /* partial_inplace */
803 0xffff, /* dst_mask */
804 FALSE), /* pcrel_offset */
806 /* The bits 48-63 of an address, plus 1 if the contents of the low
807 16 bits, treated as a signed number, is negative. */
808 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
810 1, /* size (0 = byte, 1 = short, 2 = long) */
812 FALSE, /* pc_relative */
814 complain_overflow_dont, /* complain_on_overflow */
815 ppc64_elf_ha_reloc, /* special_function */
816 "R_PPC64_ADDR16_HIGHESTA", /* name */
817 FALSE, /* partial_inplace */
819 0xffff, /* dst_mask */
820 FALSE), /* pcrel_offset */
822 /* Like ADDR64, but may be unaligned. */
823 HOWTO (R_PPC64_UADDR64, /* type */
825 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
827 FALSE, /* pc_relative */
829 complain_overflow_dont, /* complain_on_overflow */
830 bfd_elf_generic_reloc, /* special_function */
831 "R_PPC64_UADDR64", /* name */
832 FALSE, /* partial_inplace */
834 ONES (64), /* dst_mask */
835 FALSE), /* pcrel_offset */
837 /* 64-bit relative relocation. */
838 HOWTO (R_PPC64_REL64, /* type */
840 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
842 TRUE, /* pc_relative */
844 complain_overflow_dont, /* complain_on_overflow */
845 bfd_elf_generic_reloc, /* special_function */
846 "R_PPC64_REL64", /* name */
847 FALSE, /* partial_inplace */
849 ONES (64), /* dst_mask */
850 TRUE), /* pcrel_offset */
852 /* 64-bit relocation to the symbol's procedure linkage table. */
853 HOWTO (R_PPC64_PLT64, /* type */
855 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
857 FALSE, /* pc_relative */
859 complain_overflow_dont, /* complain_on_overflow */
860 ppc64_elf_unhandled_reloc, /* special_function */
861 "R_PPC64_PLT64", /* name */
862 FALSE, /* partial_inplace */
864 ONES (64), /* dst_mask */
865 FALSE), /* pcrel_offset */
867 /* 64-bit PC relative relocation to the symbol's procedure linkage
869 /* FIXME: R_PPC64_PLTREL64 not supported. */
870 HOWTO (R_PPC64_PLTREL64, /* type */
872 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
874 TRUE, /* pc_relative */
876 complain_overflow_dont, /* complain_on_overflow */
877 ppc64_elf_unhandled_reloc, /* special_function */
878 "R_PPC64_PLTREL64", /* name */
879 FALSE, /* partial_inplace */
881 ONES (64), /* dst_mask */
882 TRUE), /* pcrel_offset */
884 /* 16 bit TOC-relative relocation. */
886 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
887 HOWTO (R_PPC64_TOC16, /* type */
889 1, /* size (0 = byte, 1 = short, 2 = long) */
891 FALSE, /* pc_relative */
893 complain_overflow_signed, /* complain_on_overflow */
894 ppc64_elf_toc_reloc, /* special_function */
895 "R_PPC64_TOC16", /* name */
896 FALSE, /* partial_inplace */
898 0xffff, /* dst_mask */
899 FALSE), /* pcrel_offset */
901 /* 16 bit TOC-relative relocation without overflow. */
903 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
904 HOWTO (R_PPC64_TOC16_LO, /* type */
906 1, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE, /* pc_relative */
910 complain_overflow_dont, /* complain_on_overflow */
911 ppc64_elf_toc_reloc, /* special_function */
912 "R_PPC64_TOC16_LO", /* name */
913 FALSE, /* partial_inplace */
915 0xffff, /* dst_mask */
916 FALSE), /* pcrel_offset */
918 /* 16 bit TOC-relative relocation, high 16 bits. */
920 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
921 HOWTO (R_PPC64_TOC16_HI, /* type */
923 1, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE, /* pc_relative */
927 complain_overflow_dont, /* complain_on_overflow */
928 ppc64_elf_toc_reloc, /* special_function */
929 "R_PPC64_TOC16_HI", /* name */
930 FALSE, /* partial_inplace */
932 0xffff, /* dst_mask */
933 FALSE), /* pcrel_offset */
935 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
936 contents of the low 16 bits, treated as a signed number, is
939 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
940 HOWTO (R_PPC64_TOC16_HA, /* type */
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 FALSE, /* pc_relative */
946 complain_overflow_dont, /* complain_on_overflow */
947 ppc64_elf_toc_ha_reloc, /* special_function */
948 "R_PPC64_TOC16_HA", /* name */
949 FALSE, /* partial_inplace */
951 0xffff, /* dst_mask */
952 FALSE), /* pcrel_offset */
954 /* 64-bit relocation; insert value of TOC base (.TOC.). */
956 /* R_PPC64_TOC 51 doubleword64 .TOC. */
957 HOWTO (R_PPC64_TOC, /* type */
959 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
961 FALSE, /* pc_relative */
963 complain_overflow_bitfield, /* complain_on_overflow */
964 ppc64_elf_toc64_reloc, /* special_function */
965 "R_PPC64_TOC", /* name */
966 FALSE, /* partial_inplace */
968 ONES (64), /* dst_mask */
969 FALSE), /* pcrel_offset */
971 /* Like R_PPC64_GOT16, but also informs the link editor that the
972 value to relocate may (!) refer to a PLT entry which the link
973 editor (a) may replace with the symbol value. If the link editor
974 is unable to fully resolve the symbol, it may (b) create a PLT
975 entry and store the address to the new PLT entry in the GOT.
976 This permits lazy resolution of function symbols at run time.
977 The link editor may also skip all of this and just (c) emit a
978 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
979 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
980 HOWTO (R_PPC64_PLTGOT16, /* type */
982 1, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE, /* pc_relative */
986 complain_overflow_signed, /* complain_on_overflow */
987 ppc64_elf_unhandled_reloc, /* special_function */
988 "R_PPC64_PLTGOT16", /* name */
989 FALSE, /* partial_inplace */
991 0xffff, /* dst_mask */
992 FALSE), /* pcrel_offset */
994 /* Like R_PPC64_PLTGOT16, but without overflow. */
995 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
996 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
998 1, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE, /* pc_relative */
1002 complain_overflow_dont, /* complain_on_overflow */
1003 ppc64_elf_unhandled_reloc, /* special_function */
1004 "R_PPC64_PLTGOT16_LO", /* name */
1005 FALSE, /* partial_inplace */
1007 0xffff, /* dst_mask */
1008 FALSE), /* pcrel_offset */
1010 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1011 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1012 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
1013 16, /* rightshift */
1014 1, /* size (0 = byte, 1 = short, 2 = long) */
1016 FALSE, /* pc_relative */
1018 complain_overflow_dont, /* complain_on_overflow */
1019 ppc64_elf_unhandled_reloc, /* special_function */
1020 "R_PPC64_PLTGOT16_HI", /* name */
1021 FALSE, /* partial_inplace */
1023 0xffff, /* dst_mask */
1024 FALSE), /* pcrel_offset */
1026 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1027 1 if the contents of the low 16 bits, treated as a signed number,
1029 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1030 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1031 16, /* rightshift */
1032 1, /* size (0 = byte, 1 = short, 2 = long) */
1034 FALSE, /* pc_relative */
1036 complain_overflow_dont,/* complain_on_overflow */
1037 ppc64_elf_unhandled_reloc, /* special_function */
1038 "R_PPC64_PLTGOT16_HA", /* name */
1039 FALSE, /* partial_inplace */
1041 0xffff, /* dst_mask */
1042 FALSE), /* pcrel_offset */
1044 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1045 HOWTO (R_PPC64_ADDR16_DS, /* type */
1047 1, /* size (0 = byte, 1 = short, 2 = long) */
1049 FALSE, /* pc_relative */
1051 complain_overflow_bitfield, /* complain_on_overflow */
1052 bfd_elf_generic_reloc, /* special_function */
1053 "R_PPC64_ADDR16_DS", /* name */
1054 FALSE, /* partial_inplace */
1056 0xfffc, /* dst_mask */
1057 FALSE), /* pcrel_offset */
1059 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1060 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1062 1, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE, /* pc_relative */
1066 complain_overflow_dont,/* complain_on_overflow */
1067 bfd_elf_generic_reloc, /* special_function */
1068 "R_PPC64_ADDR16_LO_DS",/* name */
1069 FALSE, /* partial_inplace */
1071 0xfffc, /* dst_mask */
1072 FALSE), /* pcrel_offset */
1074 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1075 HOWTO (R_PPC64_GOT16_DS, /* type */
1077 1, /* size (0 = byte, 1 = short, 2 = long) */
1079 FALSE, /* pc_relative */
1081 complain_overflow_signed, /* complain_on_overflow */
1082 ppc64_elf_unhandled_reloc, /* special_function */
1083 "R_PPC64_GOT16_DS", /* name */
1084 FALSE, /* partial_inplace */
1086 0xfffc, /* dst_mask */
1087 FALSE), /* pcrel_offset */
1089 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1090 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1092 1, /* size (0 = byte, 1 = short, 2 = long) */
1094 FALSE, /* pc_relative */
1096 complain_overflow_dont, /* complain_on_overflow */
1097 ppc64_elf_unhandled_reloc, /* special_function */
1098 "R_PPC64_GOT16_LO_DS", /* name */
1099 FALSE, /* partial_inplace */
1101 0xfffc, /* dst_mask */
1102 FALSE), /* pcrel_offset */
1104 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1105 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1107 1, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE, /* pc_relative */
1111 complain_overflow_dont, /* complain_on_overflow */
1112 ppc64_elf_unhandled_reloc, /* special_function */
1113 "R_PPC64_PLT16_LO_DS", /* name */
1114 FALSE, /* partial_inplace */
1116 0xfffc, /* dst_mask */
1117 FALSE), /* pcrel_offset */
1119 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1120 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1122 1, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE, /* pc_relative */
1126 complain_overflow_bitfield, /* complain_on_overflow */
1127 ppc64_elf_sectoff_reloc, /* special_function */
1128 "R_PPC64_SECTOFF_DS", /* name */
1129 FALSE, /* partial_inplace */
1131 0xfffc, /* dst_mask */
1132 FALSE), /* pcrel_offset */
1134 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1135 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1137 1, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE, /* pc_relative */
1141 complain_overflow_dont, /* complain_on_overflow */
1142 ppc64_elf_sectoff_reloc, /* special_function */
1143 "R_PPC64_SECTOFF_LO_DS",/* name */
1144 FALSE, /* partial_inplace */
1146 0xfffc, /* dst_mask */
1147 FALSE), /* pcrel_offset */
1149 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1150 HOWTO (R_PPC64_TOC16_DS, /* type */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE, /* pc_relative */
1156 complain_overflow_signed, /* complain_on_overflow */
1157 ppc64_elf_toc_reloc, /* special_function */
1158 "R_PPC64_TOC16_DS", /* name */
1159 FALSE, /* partial_inplace */
1161 0xfffc, /* dst_mask */
1162 FALSE), /* pcrel_offset */
1164 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1165 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1167 1, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE, /* pc_relative */
1171 complain_overflow_dont, /* complain_on_overflow */
1172 ppc64_elf_toc_reloc, /* special_function */
1173 "R_PPC64_TOC16_LO_DS", /* name */
1174 FALSE, /* partial_inplace */
1176 0xfffc, /* dst_mask */
1177 FALSE), /* pcrel_offset */
1179 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1180 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1181 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1183 1, /* size (0 = byte, 1 = short, 2 = long) */
1185 FALSE, /* pc_relative */
1187 complain_overflow_signed, /* complain_on_overflow */
1188 ppc64_elf_unhandled_reloc, /* special_function */
1189 "R_PPC64_PLTGOT16_DS", /* name */
1190 FALSE, /* partial_inplace */
1192 0xfffc, /* dst_mask */
1193 FALSE), /* pcrel_offset */
1195 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1196 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1197 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1199 1, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE, /* pc_relative */
1203 complain_overflow_dont, /* complain_on_overflow */
1204 ppc64_elf_unhandled_reloc, /* special_function */
1205 "R_PPC64_PLTGOT16_LO_DS",/* name */
1206 FALSE, /* partial_inplace */
1208 0xfffc, /* dst_mask */
1209 FALSE), /* pcrel_offset */
1211 /* Marker reloc for TLS. */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE, /* pc_relative */
1218 complain_overflow_dont, /* complain_on_overflow */
1219 bfd_elf_generic_reloc, /* special_function */
1220 "R_PPC64_TLS", /* name */
1221 FALSE, /* partial_inplace */
1224 FALSE), /* pcrel_offset */
1226 /* Computes the load module index of the load module that contains the
1227 definition of its TLS sym. */
1228 HOWTO (R_PPC64_DTPMOD64,
1230 4, /* size (0 = byte, 1 = short, 2 = long) */
1232 FALSE, /* pc_relative */
1234 complain_overflow_dont, /* complain_on_overflow */
1235 ppc64_elf_unhandled_reloc, /* special_function */
1236 "R_PPC64_DTPMOD64", /* name */
1237 FALSE, /* partial_inplace */
1239 ONES (64), /* dst_mask */
1240 FALSE), /* pcrel_offset */
1242 /* Computes a dtv-relative displacement, the difference between the value
1243 of sym+add and the base address of the thread-local storage block that
1244 contains the definition of sym, minus 0x8000. */
1245 HOWTO (R_PPC64_DTPREL64,
1247 4, /* size (0 = byte, 1 = short, 2 = long) */
1249 FALSE, /* pc_relative */
1251 complain_overflow_dont, /* complain_on_overflow */
1252 ppc64_elf_unhandled_reloc, /* special_function */
1253 "R_PPC64_DTPREL64", /* name */
1254 FALSE, /* partial_inplace */
1256 ONES (64), /* dst_mask */
1257 FALSE), /* pcrel_offset */
1259 /* A 16 bit dtprel reloc. */
1260 HOWTO (R_PPC64_DTPREL16,
1262 1, /* size (0 = byte, 1 = short, 2 = long) */
1264 FALSE, /* pc_relative */
1266 complain_overflow_signed, /* complain_on_overflow */
1267 ppc64_elf_unhandled_reloc, /* special_function */
1268 "R_PPC64_DTPREL16", /* name */
1269 FALSE, /* partial_inplace */
1271 0xffff, /* dst_mask */
1272 FALSE), /* pcrel_offset */
1274 /* Like DTPREL16, but no overflow. */
1275 HOWTO (R_PPC64_DTPREL16_LO,
1277 1, /* size (0 = byte, 1 = short, 2 = long) */
1279 FALSE, /* pc_relative */
1281 complain_overflow_dont, /* complain_on_overflow */
1282 ppc64_elf_unhandled_reloc, /* special_function */
1283 "R_PPC64_DTPREL16_LO", /* name */
1284 FALSE, /* partial_inplace */
1286 0xffff, /* dst_mask */
1287 FALSE), /* pcrel_offset */
1289 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1290 HOWTO (R_PPC64_DTPREL16_HI,
1291 16, /* rightshift */
1292 1, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE, /* pc_relative */
1296 complain_overflow_dont, /* complain_on_overflow */
1297 ppc64_elf_unhandled_reloc, /* special_function */
1298 "R_PPC64_DTPREL16_HI", /* name */
1299 FALSE, /* partial_inplace */
1301 0xffff, /* dst_mask */
1302 FALSE), /* pcrel_offset */
1304 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1305 HOWTO (R_PPC64_DTPREL16_HA,
1306 16, /* rightshift */
1307 1, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE, /* pc_relative */
1311 complain_overflow_dont, /* complain_on_overflow */
1312 ppc64_elf_unhandled_reloc, /* special_function */
1313 "R_PPC64_DTPREL16_HA", /* name */
1314 FALSE, /* partial_inplace */
1316 0xffff, /* dst_mask */
1317 FALSE), /* pcrel_offset */
1319 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1320 HOWTO (R_PPC64_DTPREL16_HIGHER,
1321 32, /* rightshift */
1322 1, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE, /* pc_relative */
1326 complain_overflow_dont, /* complain_on_overflow */
1327 ppc64_elf_unhandled_reloc, /* special_function */
1328 "R_PPC64_DTPREL16_HIGHER", /* name */
1329 FALSE, /* partial_inplace */
1331 0xffff, /* dst_mask */
1332 FALSE), /* pcrel_offset */
1334 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1335 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1336 32, /* rightshift */
1337 1, /* size (0 = byte, 1 = short, 2 = long) */
1339 FALSE, /* pc_relative */
1341 complain_overflow_dont, /* complain_on_overflow */
1342 ppc64_elf_unhandled_reloc, /* special_function */
1343 "R_PPC64_DTPREL16_HIGHERA", /* name */
1344 FALSE, /* partial_inplace */
1346 0xffff, /* dst_mask */
1347 FALSE), /* pcrel_offset */
1349 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1350 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1351 48, /* rightshift */
1352 1, /* size (0 = byte, 1 = short, 2 = long) */
1354 FALSE, /* pc_relative */
1356 complain_overflow_dont, /* complain_on_overflow */
1357 ppc64_elf_unhandled_reloc, /* special_function */
1358 "R_PPC64_DTPREL16_HIGHEST", /* name */
1359 FALSE, /* partial_inplace */
1361 0xffff, /* dst_mask */
1362 FALSE), /* pcrel_offset */
1364 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1365 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1366 48, /* rightshift */
1367 1, /* size (0 = byte, 1 = short, 2 = long) */
1369 FALSE, /* pc_relative */
1371 complain_overflow_dont, /* complain_on_overflow */
1372 ppc64_elf_unhandled_reloc, /* special_function */
1373 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1374 FALSE, /* partial_inplace */
1376 0xffff, /* dst_mask */
1377 FALSE), /* pcrel_offset */
1379 /* Like DTPREL16, but for insns with a DS field. */
1380 HOWTO (R_PPC64_DTPREL16_DS,
1382 1, /* size (0 = byte, 1 = short, 2 = long) */
1384 FALSE, /* pc_relative */
1386 complain_overflow_signed, /* complain_on_overflow */
1387 ppc64_elf_unhandled_reloc, /* special_function */
1388 "R_PPC64_DTPREL16_DS", /* name */
1389 FALSE, /* partial_inplace */
1391 0xfffc, /* dst_mask */
1392 FALSE), /* pcrel_offset */
1394 /* Like DTPREL16_DS, but no overflow. */
1395 HOWTO (R_PPC64_DTPREL16_LO_DS,
1397 1, /* size (0 = byte, 1 = short, 2 = long) */
1399 FALSE, /* pc_relative */
1401 complain_overflow_dont, /* complain_on_overflow */
1402 ppc64_elf_unhandled_reloc, /* special_function */
1403 "R_PPC64_DTPREL16_LO_DS", /* name */
1404 FALSE, /* partial_inplace */
1406 0xfffc, /* dst_mask */
1407 FALSE), /* pcrel_offset */
1409 /* Computes a tp-relative displacement, the difference between the value of
1410 sym+add and the value of the thread pointer (r13). */
1411 HOWTO (R_PPC64_TPREL64,
1413 4, /* size (0 = byte, 1 = short, 2 = long) */
1415 FALSE, /* pc_relative */
1417 complain_overflow_dont, /* complain_on_overflow */
1418 ppc64_elf_unhandled_reloc, /* special_function */
1419 "R_PPC64_TPREL64", /* name */
1420 FALSE, /* partial_inplace */
1422 ONES (64), /* dst_mask */
1423 FALSE), /* pcrel_offset */
1425 /* A 16 bit tprel reloc. */
1426 HOWTO (R_PPC64_TPREL16,
1428 1, /* size (0 = byte, 1 = short, 2 = long) */
1430 FALSE, /* pc_relative */
1432 complain_overflow_signed, /* complain_on_overflow */
1433 ppc64_elf_unhandled_reloc, /* special_function */
1434 "R_PPC64_TPREL16", /* name */
1435 FALSE, /* partial_inplace */
1437 0xffff, /* dst_mask */
1438 FALSE), /* pcrel_offset */
1440 /* Like TPREL16, but no overflow. */
1441 HOWTO (R_PPC64_TPREL16_LO,
1443 1, /* size (0 = byte, 1 = short, 2 = long) */
1445 FALSE, /* pc_relative */
1447 complain_overflow_dont, /* complain_on_overflow */
1448 ppc64_elf_unhandled_reloc, /* special_function */
1449 "R_PPC64_TPREL16_LO", /* name */
1450 FALSE, /* partial_inplace */
1452 0xffff, /* dst_mask */
1453 FALSE), /* pcrel_offset */
1455 /* Like TPREL16_LO, but next higher group of 16 bits. */
1456 HOWTO (R_PPC64_TPREL16_HI,
1457 16, /* rightshift */
1458 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 FALSE, /* pc_relative */
1462 complain_overflow_dont, /* complain_on_overflow */
1463 ppc64_elf_unhandled_reloc, /* special_function */
1464 "R_PPC64_TPREL16_HI", /* name */
1465 FALSE, /* partial_inplace */
1467 0xffff, /* dst_mask */
1468 FALSE), /* pcrel_offset */
1470 /* Like TPREL16_HI, but adjust for low 16 bits. */
1471 HOWTO (R_PPC64_TPREL16_HA,
1472 16, /* rightshift */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1475 FALSE, /* pc_relative */
1477 complain_overflow_dont, /* complain_on_overflow */
1478 ppc64_elf_unhandled_reloc, /* special_function */
1479 "R_PPC64_TPREL16_HA", /* name */
1480 FALSE, /* partial_inplace */
1482 0xffff, /* dst_mask */
1483 FALSE), /* pcrel_offset */
1485 /* Like TPREL16_HI, but next higher group of 16 bits. */
1486 HOWTO (R_PPC64_TPREL16_HIGHER,
1487 32, /* rightshift */
1488 1, /* size (0 = byte, 1 = short, 2 = long) */
1490 FALSE, /* pc_relative */
1492 complain_overflow_dont, /* complain_on_overflow */
1493 ppc64_elf_unhandled_reloc, /* special_function */
1494 "R_PPC64_TPREL16_HIGHER", /* name */
1495 FALSE, /* partial_inplace */
1497 0xffff, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1500 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1501 HOWTO (R_PPC64_TPREL16_HIGHERA,
1502 32, /* rightshift */
1503 1, /* size (0 = byte, 1 = short, 2 = long) */
1505 FALSE, /* pc_relative */
1507 complain_overflow_dont, /* complain_on_overflow */
1508 ppc64_elf_unhandled_reloc, /* special_function */
1509 "R_PPC64_TPREL16_HIGHERA", /* name */
1510 FALSE, /* partial_inplace */
1512 0xffff, /* dst_mask */
1513 FALSE), /* pcrel_offset */
1515 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1516 HOWTO (R_PPC64_TPREL16_HIGHEST,
1517 48, /* rightshift */
1518 1, /* size (0 = byte, 1 = short, 2 = long) */
1520 FALSE, /* pc_relative */
1522 complain_overflow_dont, /* complain_on_overflow */
1523 ppc64_elf_unhandled_reloc, /* special_function */
1524 "R_PPC64_TPREL16_HIGHEST", /* name */
1525 FALSE, /* partial_inplace */
1527 0xffff, /* dst_mask */
1528 FALSE), /* pcrel_offset */
1530 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1531 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1532 48, /* rightshift */
1533 1, /* size (0 = byte, 1 = short, 2 = long) */
1535 FALSE, /* pc_relative */
1537 complain_overflow_dont, /* complain_on_overflow */
1538 ppc64_elf_unhandled_reloc, /* special_function */
1539 "R_PPC64_TPREL16_HIGHESTA", /* name */
1540 FALSE, /* partial_inplace */
1542 0xffff, /* dst_mask */
1543 FALSE), /* pcrel_offset */
1545 /* Like TPREL16, but for insns with a DS field. */
1546 HOWTO (R_PPC64_TPREL16_DS,
1548 1, /* size (0 = byte, 1 = short, 2 = long) */
1550 FALSE, /* pc_relative */
1552 complain_overflow_signed, /* complain_on_overflow */
1553 ppc64_elf_unhandled_reloc, /* special_function */
1554 "R_PPC64_TPREL16_DS", /* name */
1555 FALSE, /* partial_inplace */
1557 0xfffc, /* dst_mask */
1558 FALSE), /* pcrel_offset */
1560 /* Like TPREL16_DS, but no overflow. */
1561 HOWTO (R_PPC64_TPREL16_LO_DS,
1563 1, /* size (0 = byte, 1 = short, 2 = long) */
1565 FALSE, /* pc_relative */
1567 complain_overflow_dont, /* complain_on_overflow */
1568 ppc64_elf_unhandled_reloc, /* special_function */
1569 "R_PPC64_TPREL16_LO_DS", /* name */
1570 FALSE, /* partial_inplace */
1572 0xfffc, /* dst_mask */
1573 FALSE), /* pcrel_offset */
1575 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1576 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1577 to the first entry relative to the TOC base (r2). */
1578 HOWTO (R_PPC64_GOT_TLSGD16,
1580 1, /* size (0 = byte, 1 = short, 2 = long) */
1582 FALSE, /* pc_relative */
1584 complain_overflow_signed, /* complain_on_overflow */
1585 ppc64_elf_unhandled_reloc, /* special_function */
1586 "R_PPC64_GOT_TLSGD16", /* name */
1587 FALSE, /* partial_inplace */
1589 0xffff, /* dst_mask */
1590 FALSE), /* pcrel_offset */
1592 /* Like GOT_TLSGD16, but no overflow. */
1593 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1595 1, /* size (0 = byte, 1 = short, 2 = long) */
1597 FALSE, /* pc_relative */
1599 complain_overflow_dont, /* complain_on_overflow */
1600 ppc64_elf_unhandled_reloc, /* special_function */
1601 "R_PPC64_GOT_TLSGD16_LO", /* name */
1602 FALSE, /* partial_inplace */
1604 0xffff, /* dst_mask */
1605 FALSE), /* pcrel_offset */
1607 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1608 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1609 16, /* rightshift */
1610 1, /* size (0 = byte, 1 = short, 2 = long) */
1612 FALSE, /* pc_relative */
1614 complain_overflow_dont, /* complain_on_overflow */
1615 ppc64_elf_unhandled_reloc, /* special_function */
1616 "R_PPC64_GOT_TLSGD16_HI", /* name */
1617 FALSE, /* partial_inplace */
1619 0xffff, /* dst_mask */
1620 FALSE), /* pcrel_offset */
1622 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1623 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1624 16, /* rightshift */
1625 1, /* size (0 = byte, 1 = short, 2 = long) */
1627 FALSE, /* pc_relative */
1629 complain_overflow_dont, /* complain_on_overflow */
1630 ppc64_elf_unhandled_reloc, /* special_function */
1631 "R_PPC64_GOT_TLSGD16_HA", /* name */
1632 FALSE, /* partial_inplace */
1634 0xffff, /* dst_mask */
1635 FALSE), /* pcrel_offset */
1637 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1638 with values (sym+add)@dtpmod and zero, and computes the offset to the
1639 first entry relative to the TOC base (r2). */
1640 HOWTO (R_PPC64_GOT_TLSLD16,
1642 1, /* size (0 = byte, 1 = short, 2 = long) */
1644 FALSE, /* pc_relative */
1646 complain_overflow_signed, /* complain_on_overflow */
1647 ppc64_elf_unhandled_reloc, /* special_function */
1648 "R_PPC64_GOT_TLSLD16", /* name */
1649 FALSE, /* partial_inplace */
1651 0xffff, /* dst_mask */
1652 FALSE), /* pcrel_offset */
1654 /* Like GOT_TLSLD16, but no overflow. */
1655 HOWTO (R_PPC64_GOT_TLSLD16_LO,
1657 1, /* size (0 = byte, 1 = short, 2 = long) */
1659 FALSE, /* pc_relative */
1661 complain_overflow_dont, /* complain_on_overflow */
1662 ppc64_elf_unhandled_reloc, /* special_function */
1663 "R_PPC64_GOT_TLSLD16_LO", /* name */
1664 FALSE, /* partial_inplace */
1666 0xffff, /* dst_mask */
1667 FALSE), /* pcrel_offset */
1669 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1670 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1671 16, /* rightshift */
1672 1, /* size (0 = byte, 1 = short, 2 = long) */
1674 FALSE, /* pc_relative */
1676 complain_overflow_dont, /* complain_on_overflow */
1677 ppc64_elf_unhandled_reloc, /* special_function */
1678 "R_PPC64_GOT_TLSLD16_HI", /* name */
1679 FALSE, /* partial_inplace */
1681 0xffff, /* dst_mask */
1682 FALSE), /* pcrel_offset */
1684 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1685 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1686 16, /* rightshift */
1687 1, /* size (0 = byte, 1 = short, 2 = long) */
1689 FALSE, /* pc_relative */
1691 complain_overflow_dont, /* complain_on_overflow */
1692 ppc64_elf_unhandled_reloc, /* special_function */
1693 "R_PPC64_GOT_TLSLD16_HA", /* name */
1694 FALSE, /* partial_inplace */
1696 0xffff, /* dst_mask */
1697 FALSE), /* pcrel_offset */
1699 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1700 the offset to the entry relative to the TOC base (r2). */
1701 HOWTO (R_PPC64_GOT_DTPREL16_DS,
1703 1, /* size (0 = byte, 1 = short, 2 = long) */
1705 FALSE, /* pc_relative */
1707 complain_overflow_signed, /* complain_on_overflow */
1708 ppc64_elf_unhandled_reloc, /* special_function */
1709 "R_PPC64_GOT_DTPREL16_DS", /* name */
1710 FALSE, /* partial_inplace */
1712 0xfffc, /* dst_mask */
1713 FALSE), /* pcrel_offset */
1715 /* Like GOT_DTPREL16_DS, but no overflow. */
1716 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
1718 1, /* size (0 = byte, 1 = short, 2 = long) */
1720 FALSE, /* pc_relative */
1722 complain_overflow_dont, /* complain_on_overflow */
1723 ppc64_elf_unhandled_reloc, /* special_function */
1724 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1725 FALSE, /* partial_inplace */
1727 0xfffc, /* dst_mask */
1728 FALSE), /* pcrel_offset */
1730 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1731 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1732 16, /* rightshift */
1733 1, /* size (0 = byte, 1 = short, 2 = long) */
1735 FALSE, /* pc_relative */
1737 complain_overflow_dont, /* complain_on_overflow */
1738 ppc64_elf_unhandled_reloc, /* special_function */
1739 "R_PPC64_GOT_DTPREL16_HI", /* name */
1740 FALSE, /* partial_inplace */
1742 0xffff, /* dst_mask */
1743 FALSE), /* pcrel_offset */
1745 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1746 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1747 16, /* rightshift */
1748 1, /* size (0 = byte, 1 = short, 2 = long) */
1750 FALSE, /* pc_relative */
1752 complain_overflow_dont, /* complain_on_overflow */
1753 ppc64_elf_unhandled_reloc, /* special_function */
1754 "R_PPC64_GOT_DTPREL16_HA", /* name */
1755 FALSE, /* partial_inplace */
1757 0xffff, /* dst_mask */
1758 FALSE), /* pcrel_offset */
1760 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1761 offset to the entry relative to the TOC base (r2). */
1762 HOWTO (R_PPC64_GOT_TPREL16_DS,
1764 1, /* size (0 = byte, 1 = short, 2 = long) */
1766 FALSE, /* pc_relative */
1768 complain_overflow_signed, /* complain_on_overflow */
1769 ppc64_elf_unhandled_reloc, /* special_function */
1770 "R_PPC64_GOT_TPREL16_DS", /* name */
1771 FALSE, /* partial_inplace */
1773 0xfffc, /* dst_mask */
1774 FALSE), /* pcrel_offset */
1776 /* Like GOT_TPREL16_DS, but no overflow. */
1777 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1779 1, /* size (0 = byte, 1 = short, 2 = long) */
1781 FALSE, /* pc_relative */
1783 complain_overflow_dont, /* complain_on_overflow */
1784 ppc64_elf_unhandled_reloc, /* special_function */
1785 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1786 FALSE, /* partial_inplace */
1788 0xfffc, /* dst_mask */
1789 FALSE), /* pcrel_offset */
1791 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1792 HOWTO (R_PPC64_GOT_TPREL16_HI,
1793 16, /* rightshift */
1794 1, /* size (0 = byte, 1 = short, 2 = long) */
1796 FALSE, /* pc_relative */
1798 complain_overflow_dont, /* complain_on_overflow */
1799 ppc64_elf_unhandled_reloc, /* special_function */
1800 "R_PPC64_GOT_TPREL16_HI", /* name */
1801 FALSE, /* partial_inplace */
1803 0xffff, /* dst_mask */
1804 FALSE), /* pcrel_offset */
1806 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1807 HOWTO (R_PPC64_GOT_TPREL16_HA,
1808 16, /* rightshift */
1809 1, /* size (0 = byte, 1 = short, 2 = long) */
1811 FALSE, /* pc_relative */
1813 complain_overflow_dont, /* complain_on_overflow */
1814 ppc64_elf_unhandled_reloc, /* special_function */
1815 "R_PPC64_GOT_TPREL16_HA", /* name */
1816 FALSE, /* partial_inplace */
1818 0xffff, /* dst_mask */
1819 FALSE), /* pcrel_offset */
1821 /* GNU extension to record C++ vtable hierarchy. */
1822 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1824 0, /* size (0 = byte, 1 = short, 2 = long) */
1826 FALSE, /* pc_relative */
1828 complain_overflow_dont, /* complain_on_overflow */
1829 NULL, /* special_function */
1830 "R_PPC64_GNU_VTINHERIT", /* name */
1831 FALSE, /* partial_inplace */
1834 FALSE), /* pcrel_offset */
1836 /* GNU extension to record C++ vtable member usage. */
1837 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1839 0, /* size (0 = byte, 1 = short, 2 = long) */
1841 FALSE, /* pc_relative */
1843 complain_overflow_dont, /* complain_on_overflow */
1844 NULL, /* special_function */
1845 "R_PPC64_GNU_VTENTRY", /* name */
1846 FALSE, /* partial_inplace */
1849 FALSE), /* pcrel_offset */
1853 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1857 ppc_howto_init (void)
1859 unsigned int i, type;
1862 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1865 type = ppc64_elf_howto_raw[i].type;
1866 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1867 / sizeof (ppc64_elf_howto_table[0])));
1868 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1872 static reloc_howto_type *
1873 ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1874 bfd_reloc_code_real_type code)
1876 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
1878 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1879 /* Initialize howto table if needed. */
1887 case BFD_RELOC_NONE: r = R_PPC64_NONE;
1889 case BFD_RELOC_32: r = R_PPC64_ADDR32;
1891 case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
1893 case BFD_RELOC_16: r = R_PPC64_ADDR16;
1895 case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
1897 case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
1899 case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
1901 case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
1903 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
1905 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
1907 case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
1909 case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
1911 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
1913 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
1915 case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
1917 case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
1919 case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
1921 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
1923 case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
1925 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
1927 case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
1929 case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
1931 case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
1933 case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
1935 case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
1937 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
1939 case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
1941 case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
1943 case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
1945 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
1947 case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
1949 case BFD_RELOC_64: r = R_PPC64_ADDR64;
1951 case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
1953 case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
1955 case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
1957 case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
1959 case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
1961 case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
1963 case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
1965 case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
1967 case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
1969 case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
1971 case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
1973 case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
1975 case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
1977 case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
1979 case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
1981 case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
1983 case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
1985 case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
1987 case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
1989 case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
1991 case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
1993 case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
1995 case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
1997 case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
1999 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
2001 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
2003 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
2005 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
2007 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
2009 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
2011 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
2013 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
2015 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
2017 case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
2019 case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
2021 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
2023 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
2025 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
2027 case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
2029 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
2031 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
2033 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
2035 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
2037 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
2039 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
2041 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
2043 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
2045 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
2047 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
2049 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
2051 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
2053 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
2055 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
2057 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
2059 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
2061 case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
2063 case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
2065 case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
2067 case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
2069 case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
2071 case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
2073 case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
2075 case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
2077 case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
2079 case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
2081 case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
2083 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
2085 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
2087 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
2091 return ppc64_elf_howto_table[r];
2094 /* Set the howto pointer for a PowerPC ELF reloc. */
2097 ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
2098 Elf_Internal_Rela *dst)
2102 /* Initialize howto table if needed. */
2103 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2106 type = ELF64_R_TYPE (dst->r_info);
2107 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
2108 / sizeof (ppc64_elf_howto_table[0])));
2109 cache_ptr->howto = ppc64_elf_howto_table[type];
2112 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2114 static bfd_reloc_status_type
2115 ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2116 void *data, asection *input_section,
2117 bfd *output_bfd, char **error_message)
2119 /* If this is a relocatable link (output_bfd test tells us), just
2120 call the generic function. Any adjustment will be done at final
2122 if (output_bfd != NULL)
2123 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2124 input_section, output_bfd, error_message);
2126 /* Adjust the addend for sign extension of the low 16 bits.
2127 We won't actually be using the low 16 bits, so trashing them
2129 reloc_entry->addend += 0x8000;
2130 return bfd_reloc_continue;
2133 static bfd_reloc_status_type
2134 ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2135 void *data, asection *input_section,
2136 bfd *output_bfd, char **error_message)
2139 enum elf_ppc64_reloc_type r_type;
2140 bfd_size_type octets;
2141 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2142 bfd_boolean is_power4 = FALSE;
2144 /* If this is a relocatable link (output_bfd test tells us), just
2145 call the generic function. Any adjustment will be done at final
2147 if (output_bfd != NULL)
2148 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2149 input_section, output_bfd, error_message);
2151 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2152 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2153 insn &= ~(0x01 << 21);
2154 r_type = reloc_entry->howto->type;
2155 if (r_type == R_PPC64_ADDR14_BRTAKEN
2156 || r_type == R_PPC64_REL14_BRTAKEN)
2157 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2161 /* Set 'a' bit. This is 0b00010 in BO field for branch
2162 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2163 for branch on CTR insns (BO == 1a00t or 1a01t). */
2164 if ((insn & (0x14 << 21)) == (0x04 << 21))
2166 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2169 return bfd_reloc_continue;
2176 if (!bfd_is_com_section (symbol->section))
2177 target = symbol->value;
2178 target += symbol->section->output_section->vma;
2179 target += symbol->section->output_offset;
2180 target += reloc_entry->addend;
2182 from = (reloc_entry->address
2183 + input_section->output_offset
2184 + input_section->output_section->vma);
2186 /* Invert 'y' bit if not the default. */
2187 if ((bfd_signed_vma) (target - from) < 0)
2190 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2191 return bfd_reloc_continue;
2194 static bfd_reloc_status_type
2195 ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2196 void *data, asection *input_section,
2197 bfd *output_bfd, char **error_message)
2199 /* If this is a relocatable link (output_bfd test tells us), just
2200 call the generic function. Any adjustment will be done at final
2202 if (output_bfd != NULL)
2203 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2204 input_section, output_bfd, error_message);
2206 /* Subtract the symbol section base address. */
2207 reloc_entry->addend -= symbol->section->output_section->vma;
2208 return bfd_reloc_continue;
2211 static bfd_reloc_status_type
2212 ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2213 void *data, asection *input_section,
2214 bfd *output_bfd, char **error_message)
2216 /* If this is a relocatable link (output_bfd test tells us), just
2217 call the generic function. Any adjustment will be done at final
2219 if (output_bfd != NULL)
2220 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2221 input_section, output_bfd, error_message);
2223 /* Subtract the symbol section base address. */
2224 reloc_entry->addend -= symbol->section->output_section->vma;
2226 /* Adjust the addend for sign extension of the low 16 bits. */
2227 reloc_entry->addend += 0x8000;
2228 return bfd_reloc_continue;
2231 static bfd_reloc_status_type
2232 ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2233 void *data, asection *input_section,
2234 bfd *output_bfd, char **error_message)
2238 /* If this is a relocatable link (output_bfd test tells us), just
2239 call the generic function. Any adjustment will be done at final
2241 if (output_bfd != NULL)
2242 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2243 input_section, output_bfd, error_message);
2245 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2247 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2249 /* Subtract the TOC base address. */
2250 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2251 return bfd_reloc_continue;
2254 static bfd_reloc_status_type
2255 ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2256 void *data, asection *input_section,
2257 bfd *output_bfd, char **error_message)
2261 /* If this is a relocatable link (output_bfd test tells us), just
2262 call the generic function. Any adjustment will be done at final
2264 if (output_bfd != NULL)
2265 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2266 input_section, output_bfd, error_message);
2268 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2270 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2272 /* Subtract the TOC base address. */
2273 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2275 /* Adjust the addend for sign extension of the low 16 bits. */
2276 reloc_entry->addend += 0x8000;
2277 return bfd_reloc_continue;
2280 static bfd_reloc_status_type
2281 ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2282 void *data, asection *input_section,
2283 bfd *output_bfd, char **error_message)
2286 bfd_size_type octets;
2288 /* If this is a relocatable link (output_bfd test tells us), just
2289 call the generic function. Any adjustment will be done at final
2291 if (output_bfd != NULL)
2292 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2293 input_section, output_bfd, error_message);
2295 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2297 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2299 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2300 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2301 return bfd_reloc_ok;
2304 static bfd_reloc_status_type
2305 ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2306 void *data, asection *input_section,
2307 bfd *output_bfd, char **error_message)
2309 /* If this is a relocatable link (output_bfd test tells us), just
2310 call the generic function. Any adjustment will be done at final
2312 if (output_bfd != NULL)
2313 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2314 input_section, output_bfd, error_message);
2316 if (error_message != NULL)
2318 static char buf[60];
2319 sprintf (buf, "generic linker can't handle %s",
2320 reloc_entry->howto->name);
2321 *error_message = buf;
2323 return bfd_reloc_dangerous;
2326 struct ppc64_elf_obj_tdata
2328 struct elf_obj_tdata elf;
2330 /* Shortcuts to dynamic linker sections. */
2334 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2335 sections means we potentially need one of these for each input bfd. */
2337 bfd_signed_vma refcount;
2342 #define ppc64_elf_tdata(bfd) \
2343 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2345 #define ppc64_tlsld_got(bfd) \
2346 (&ppc64_elf_tdata (bfd)->tlsld_got)
2348 /* Override the generic function because we store some extras. */
2351 ppc64_elf_mkobject (bfd *abfd)
2353 bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata);
2354 abfd->tdata.any = bfd_zalloc (abfd, amt);
2355 if (abfd->tdata.any == NULL)
2360 /* Fix bad default arch selected for a 64 bit input bfd when the
2361 default is 32 bit. */
2364 ppc64_elf_object_p (bfd *abfd)
2366 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
2368 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2370 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2372 /* Relies on arch after 32 bit default being 64 bit default. */
2373 abfd->arch_info = abfd->arch_info->next;
2374 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2380 /* Support for core dump NOTE sections. */
2383 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2385 size_t offset, size;
2387 if (note->descsz != 504)
2391 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2394 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32);
2400 /* Make a ".reg/999" section. */
2401 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2402 size, note->descpos + offset);
2406 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2408 if (note->descsz != 136)
2411 elf_tdata (abfd)->core_program
2412 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2413 elf_tdata (abfd)->core_command
2414 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2419 /* Merge backend specific data from an object file to the output
2420 object file when linking. */
2423 ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
2425 /* Check if we have the same endianess. */
2426 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
2427 && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
2428 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
2432 if (bfd_big_endian (ibfd))
2433 msg = _("%s: compiled for a big endian system "
2434 "and target is little endian");
2436 msg = _("%s: compiled for a little endian system "
2437 "and target is big endian");
2439 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
2441 bfd_set_error (bfd_error_wrong_format);
2448 /* Add extra PPC sections. */
2450 static struct bfd_elf_special_section const ppc64_elf_special_sections[]=
2452 { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2453 { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2454 { ".plt", 4, 0, SHT_NOBITS, 0 },
2455 { ".toc", 4, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2456 { ".toc1", 5, 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2457 { ".tocbss", 7, 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2458 { NULL, 0, 0, 0, 0 }
2461 struct _ppc64_elf_section_data
2463 struct bfd_elf_section_data elf;
2465 /* An array with one entry for each opd function descriptor. */
2468 /* Points to the function code section for local opd entries. */
2469 asection **func_sec;
2470 /* After editing .opd, adjust references to opd local syms. */
2474 /* An array for toc sections, indexed by offset/8.
2475 Specifies the relocation symbol index used at a given toc offset. */
2479 #define ppc64_elf_section_data(sec) \
2480 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2483 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
2485 struct _ppc64_elf_section_data *sdata;
2486 bfd_size_type amt = sizeof (*sdata);
2488 sdata = bfd_zalloc (abfd, amt);
2491 sec->used_by_bfd = sdata;
2493 return _bfd_elf_new_section_hook (abfd, sec);
2497 get_opd_info (asection * sec)
2500 && ppc64_elf_section_data (sec) != NULL
2501 && ppc64_elf_section_data (sec)->opd.adjust != NULL)
2502 return ppc64_elf_section_data (sec)->opd.adjust;
2506 /* The following functions are specific to the ELF linker, while
2507 functions above are used generally. Those named ppc64_elf_* are
2508 called by the main ELF linker code. They appear in this file more
2509 or less in the order in which they are called. eg.
2510 ppc64_elf_check_relocs is called early in the link process,
2511 ppc64_elf_finish_dynamic_sections is one of the last functions
2514 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2515 functions have both a function code symbol and a function descriptor
2516 symbol. A call to foo in a relocatable object file looks like:
2523 The function definition in another object file might be:
2527 . .quad .TOC.@tocbase
2533 When the linker resolves the call during a static link, the branch
2534 unsurprisingly just goes to .foo and the .opd information is unused.
2535 If the function definition is in a shared library, things are a little
2536 different: The call goes via a plt call stub, the opd information gets
2537 copied to the plt, and the linker patches the nop.
2545 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
2546 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
2547 . std 2,40(1) # this is the general idea
2555 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2557 The "reloc ()" notation is supposed to indicate that the linker emits
2558 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2561 What are the difficulties here? Well, firstly, the relocations
2562 examined by the linker in check_relocs are against the function code
2563 sym .foo, while the dynamic relocation in the plt is emitted against
2564 the function descriptor symbol, foo. Somewhere along the line, we need
2565 to carefully copy dynamic link information from one symbol to the other.
2566 Secondly, the generic part of the elf linker will make .foo a dynamic
2567 symbol as is normal for most other backends. We need foo dynamic
2568 instead, at least for an application final link. However, when
2569 creating a shared library containing foo, we need to have both symbols
2570 dynamic so that references to .foo are satisfied during the early
2571 stages of linking. Otherwise the linker might decide to pull in a
2572 definition from some other object, eg. a static library. */
2574 /* The linker needs to keep track of the number of relocs that it
2575 decides to copy as dynamic relocs in check_relocs for each symbol.
2576 This is so that it can later discard them if they are found to be
2577 unnecessary. We store the information in a field extending the
2578 regular ELF linker hash table. */
2580 struct ppc_dyn_relocs
2582 struct ppc_dyn_relocs *next;
2584 /* The input section of the reloc. */
2587 /* Total number of relocs copied for the input section. */
2588 bfd_size_type count;
2590 /* Number of pc-relative relocs copied for the input section. */
2591 bfd_size_type pc_count;
2594 /* Track GOT entries needed for a given symbol. We might need more
2595 than one got entry per symbol. */
2598 struct got_entry *next;
2600 /* The symbol addend that we'll be placing in the GOT. */
2603 /* Unlike other ELF targets, we use separate GOT entries for the same
2604 symbol referenced from different input files. This is to support
2605 automatic multiple TOC/GOT sections, where the TOC base can vary
2606 from one input file to another.
2608 Point to the BFD owning this GOT entry. */
2611 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2612 TLS_TPREL or TLS_DTPREL for tls entries. */
2615 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2618 bfd_signed_vma refcount;
2623 /* The same for PLT. */
2626 struct plt_entry *next;
2632 bfd_signed_vma refcount;
2637 /* Of those relocs that might be copied as dynamic relocs, this macro
2638 selects those that must be copied when linking a shared library,
2639 even when the symbol is local. */
2641 #define MUST_BE_DYN_RELOC(RTYPE) \
2642 ((RTYPE) != R_PPC64_REL32 \
2643 && (RTYPE) != R_PPC64_REL64 \
2644 && (RTYPE) != R_PPC64_REL30)
2646 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2647 copying dynamic variables from a shared lib into an app's dynbss
2648 section, and instead use a dynamic relocation to point into the
2649 shared lib. With code that gcc generates, it's vital that this be
2650 enabled; In the PowerPC64 ABI, the address of a function is actually
2651 the address of a function descriptor, which resides in the .opd
2652 section. gcc uses the descriptor directly rather than going via the
2653 GOT as some other ABI's do, which means that initialized function
2654 pointers must reference the descriptor. Thus, a function pointer
2655 initialized to the address of a function in a shared library will
2656 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2657 redefines the function descriptor symbol to point to the copy. This
2658 presents a problem as a plt entry for that function is also
2659 initialized from the function descriptor symbol and the copy reloc
2660 may not be initialized first. */
2661 #define ELIMINATE_COPY_RELOCS 1
2663 /* Section name for stubs is the associated section name plus this
2665 #define STUB_SUFFIX ".stub"
2668 ppc_stub_long_branch:
2669 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2670 destination, but a 24 bit branch in a stub section will reach.
2673 ppc_stub_plt_branch:
2674 Similar to the above, but a 24 bit branch in the stub section won't
2675 reach its destination.
2676 . addis %r12,%r2,xxx@toc@ha
2677 . ld %r11,xxx@toc@l(%r12)
2682 Used to call a function in a shared library. If it so happens that
2683 the plt entry referenced crosses a 64k boundary, then an extra
2684 "addis %r12,%r12,1" will be inserted before the load at xxx+8 or
2685 xxx+16 as appropriate.
2686 . addis %r12,%r2,xxx@toc@ha
2688 . ld %r11,xxx+0@toc@l(%r12)
2689 . ld %r2,xxx+8@toc@l(%r12)
2691 . ld %r11,xxx+16@toc@l(%r12)
2694 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2695 code to adjust the value and save r2 to support multiple toc sections.
2696 A ppc_stub_long_branch with an r2 offset looks like:
2698 . addis %r2,%r2,off@ha
2699 . addi %r2,%r2,off@l
2702 A ppc_stub_plt_branch with an r2 offset looks like:
2704 . addis %r12,%r2,xxx@toc@ha
2705 . ld %r11,xxx@toc@l(%r12)
2706 . addis %r2,%r2,off@ha
2707 . addi %r2,%r2,off@l
2712 enum ppc_stub_type {
2714 ppc_stub_long_branch,
2715 ppc_stub_long_branch_r2off,
2716 ppc_stub_plt_branch,
2717 ppc_stub_plt_branch_r2off,
2721 struct ppc_stub_hash_entry {
2723 /* Base hash table entry structure. */
2724 struct bfd_hash_entry root;
2726 enum ppc_stub_type stub_type;
2728 /* The stub section. */
2731 /* Offset within stub_sec of the beginning of this stub. */
2732 bfd_vma stub_offset;
2734 /* Given the symbol's value and its section we can determine its final
2735 value when building the stubs (so the stub knows where to jump. */
2736 bfd_vma target_value;
2737 asection *target_section;
2739 /* The symbol table entry, if any, that this was derived from. */
2740 struct ppc_link_hash_entry *h;
2742 /* And the reloc addend that this was derived from. */
2745 /* Where this stub is being called from, or, in the case of combined
2746 stub sections, the first input section in the group. */
2750 struct ppc_branch_hash_entry {
2752 /* Base hash table entry structure. */
2753 struct bfd_hash_entry root;
2755 /* Offset within .branch_lt. */
2756 unsigned int offset;
2758 /* Generation marker. */
2762 struct ppc_link_hash_entry
2764 struct elf_link_hash_entry elf;
2766 /* A pointer to the most recently used stub hash entry against this
2768 struct ppc_stub_hash_entry *stub_cache;
2770 /* Track dynamic relocs copied for this symbol. */
2771 struct ppc_dyn_relocs *dyn_relocs;
2773 /* Link between function code and descriptor symbols. */
2774 struct ppc_link_hash_entry *oh;
2776 /* Flag function code and descriptor symbols. */
2777 unsigned int is_func:1;
2778 unsigned int is_func_descriptor:1;
2779 unsigned int is_entry:1;
2781 /* Whether global opd sym has been adjusted or not. */
2782 unsigned int adjust_done:1;
2784 /* Contexts in which symbol is used in the GOT (or TOC).
2785 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
2786 corresponding relocs are encountered during check_relocs.
2787 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2788 indicate the corresponding GOT entry type is not needed.
2789 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
2790 a TPREL one. We use a separate flag rather than setting TPREL
2791 just for convenience in distinguishing the two cases. */
2792 #define TLS_GD 1 /* GD reloc. */
2793 #define TLS_LD 2 /* LD reloc. */
2794 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2795 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2796 #define TLS_TLS 16 /* Any TLS reloc. */
2797 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
2798 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2802 /* ppc64 ELF linker hash table. */
2804 struct ppc_link_hash_table
2806 struct elf_link_hash_table elf;
2808 /* The stub hash table. */
2809 struct bfd_hash_table stub_hash_table;
2811 /* Another hash table for plt_branch stubs. */
2812 struct bfd_hash_table branch_hash_table;
2814 /* Linker stub bfd. */
2817 /* Linker call-backs. */
2818 asection * (*add_stub_section) (const char *, asection *);
2819 void (*layout_sections_again) (void);
2821 /* Array to keep track of which stub sections have been created, and
2822 information on stub grouping. */
2824 /* This is the section to which stubs in the group will be attached. */
2826 /* The stub section. */
2828 /* Along with elf_gp, specifies the TOC pointer used in this group. */
2832 /* Support for multiple toc sections. */
2833 unsigned int no_multi_toc;
2834 unsigned int multi_toc_needed;
2836 /* Temp used when calculating TOC pointers. */
2839 /* Highest input section id. */
2842 /* Highest output section index. */
2845 /* List of input sections for each output section. */
2846 asection **input_list;
2848 /* Short-cuts to get to dynamic linker sections. */
2859 /* Shortcut to .__tls_get_addr. */
2860 struct elf_link_hash_entry *tls_get_addr;
2863 unsigned long stub_count[ppc_stub_plt_call];
2865 /* Set if we should emit symbols for stubs. */
2866 unsigned int emit_stub_syms;
2869 unsigned int stub_error;
2871 /* Flag set when small branches are detected. Used to
2872 select suitable defaults for the stub group size. */
2873 unsigned int has_14bit_branch;
2875 /* Set if we detect a reference undefined weak symbol. */
2876 unsigned int have_undefweak;
2878 /* Incremented every time we size stubs. */
2879 unsigned int stub_iteration;
2881 /* Small local sym to section mapping cache. */
2882 struct sym_sec_cache sym_sec;
2885 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2887 #define ppc_hash_table(p) \
2888 ((struct ppc_link_hash_table *) ((p)->hash))
2890 #define ppc_stub_hash_lookup(table, string, create, copy) \
2891 ((struct ppc_stub_hash_entry *) \
2892 bfd_hash_lookup ((table), (string), (create), (copy)))
2894 #define ppc_branch_hash_lookup(table, string, create, copy) \
2895 ((struct ppc_branch_hash_entry *) \
2896 bfd_hash_lookup ((table), (string), (create), (copy)))
2898 /* Create an entry in the stub hash table. */
2900 static struct bfd_hash_entry *
2901 stub_hash_newfunc (struct bfd_hash_entry *entry,
2902 struct bfd_hash_table *table,
2905 /* Allocate the structure if it has not already been allocated by a
2909 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2914 /* Call the allocation method of the superclass. */
2915 entry = bfd_hash_newfunc (entry, table, string);
2918 struct ppc_stub_hash_entry *eh;
2920 /* Initialize the local fields. */
2921 eh = (struct ppc_stub_hash_entry *) entry;
2922 eh->stub_type = ppc_stub_none;
2923 eh->stub_sec = NULL;
2924 eh->stub_offset = 0;
2925 eh->target_value = 0;
2926 eh->target_section = NULL;
2934 /* Create an entry in the branch hash table. */
2936 static struct bfd_hash_entry *
2937 branch_hash_newfunc (struct bfd_hash_entry *entry,
2938 struct bfd_hash_table *table,
2941 /* Allocate the structure if it has not already been allocated by a
2945 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2950 /* Call the allocation method of the superclass. */
2951 entry = bfd_hash_newfunc (entry, table, string);
2954 struct ppc_branch_hash_entry *eh;
2956 /* Initialize the local fields. */
2957 eh = (struct ppc_branch_hash_entry *) entry;
2965 /* Create an entry in a ppc64 ELF linker hash table. */
2967 static struct bfd_hash_entry *
2968 link_hash_newfunc (struct bfd_hash_entry *entry,
2969 struct bfd_hash_table *table,
2972 /* Allocate the structure if it has not already been allocated by a
2976 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2981 /* Call the allocation method of the superclass. */
2982 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2985 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2987 eh->stub_cache = NULL;
2988 eh->dyn_relocs = NULL;
2991 eh->is_func_descriptor = 0;
2993 eh->adjust_done = 0;
3000 /* Create a ppc64 ELF linker hash table. */
3002 static struct bfd_link_hash_table *
3003 ppc64_elf_link_hash_table_create (bfd *abfd)
3005 struct ppc_link_hash_table *htab;
3006 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
3008 htab = bfd_zmalloc (amt);
3012 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
3018 /* Init the stub hash table too. */
3019 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
3022 /* And the branch hash table. */
3023 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
3026 /* Initializing two fields of the union is just cosmetic. We really
3027 only care about glist, but when compiled on a 32-bit host the
3028 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3029 debugger inspection of these fields look nicer. */
3030 htab->elf.init_refcount.refcount = 0;
3031 htab->elf.init_refcount.glist = NULL;
3032 htab->elf.init_offset.offset = 0;
3033 htab->elf.init_offset.glist = NULL;
3035 return &htab->elf.root;
3038 /* Free the derived linker hash table. */
3041 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
3043 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
3045 bfd_hash_table_free (&ret->stub_hash_table);
3046 bfd_hash_table_free (&ret->branch_hash_table);
3047 _bfd_generic_link_hash_table_free (hash);
3050 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3053 ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info)
3055 struct ppc_link_hash_table *htab;
3057 elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64;
3059 /* Always hook our dynamic sections into the first bfd, which is the
3060 linker created stub bfd. This ensures that the GOT header is at
3061 the start of the output TOC section. */
3062 htab = ppc_hash_table (info);
3063 htab->stub_bfd = abfd;
3064 htab->elf.dynobj = abfd;
3067 /* Build a name for an entry in the stub hash table. */
3070 ppc_stub_name (const asection *input_section,
3071 const asection *sym_sec,
3072 const struct ppc_link_hash_entry *h,
3073 const Elf_Internal_Rela *rel)
3078 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3079 offsets from a sym as a branch target? In fact, we could
3080 probably assume the addend is always zero. */
3081 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
3085 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
3086 stub_name = bfd_malloc (len);
3087 if (stub_name != NULL)
3089 sprintf (stub_name, "%08x.%s+%x",
3090 input_section->id & 0xffffffff,
3091 h->elf.root.root.string,
3092 (int) rel->r_addend & 0xffffffff);
3097 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3098 stub_name = bfd_malloc (len);
3099 if (stub_name != NULL)
3101 sprintf (stub_name, "%08x.%x:%x+%x",
3102 input_section->id & 0xffffffff,
3103 sym_sec->id & 0xffffffff,
3104 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
3105 (int) rel->r_addend & 0xffffffff);
3111 /* Look up an entry in the stub hash. Stub entries are cached because
3112 creating the stub name takes a bit of time. */
3114 static struct ppc_stub_hash_entry *
3115 ppc_get_stub_entry (const asection *input_section,
3116 const asection *sym_sec,
3117 struct elf_link_hash_entry *hash,
3118 const Elf_Internal_Rela *rel,
3119 struct ppc_link_hash_table *htab)
3121 struct ppc_stub_hash_entry *stub_entry;
3122 struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
3123 const asection *id_sec;
3125 /* If this input section is part of a group of sections sharing one
3126 stub section, then use the id of the first section in the group.
3127 Stub names need to include a section id, as there may well be
3128 more than one stub used to reach say, printf, and we need to
3129 distinguish between them. */
3130 id_sec = htab->stub_group[input_section->id].link_sec;
3132 if (h != NULL && h->stub_cache != NULL
3133 && h->stub_cache->h == h
3134 && h->stub_cache->id_sec == id_sec)
3136 stub_entry = h->stub_cache;
3142 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
3143 if (stub_name == NULL)
3146 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
3147 stub_name, FALSE, FALSE);
3149 h->stub_cache = stub_entry;
3157 /* Add a new stub entry to the stub hash. Not all fields of the new
3158 stub entry are initialised. */
3160 static struct ppc_stub_hash_entry *
3161 ppc_add_stub (const char *stub_name,
3163 struct ppc_link_hash_table *htab)
3167 struct ppc_stub_hash_entry *stub_entry;
3169 link_sec = htab->stub_group[section->id].link_sec;
3170 stub_sec = htab->stub_group[section->id].stub_sec;
3171 if (stub_sec == NULL)
3173 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3174 if (stub_sec == NULL)
3180 namelen = strlen (link_sec->name);
3181 len = namelen + sizeof (STUB_SUFFIX);
3182 s_name = bfd_alloc (htab->stub_bfd, len);
3186 memcpy (s_name, link_sec->name, namelen);
3187 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3188 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3189 if (stub_sec == NULL)
3191 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3193 htab->stub_group[section->id].stub_sec = stub_sec;
3196 /* Enter this entry into the linker stub hash table. */
3197 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3199 if (stub_entry == NULL)
3201 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3202 bfd_archive_filename (section->owner),
3207 stub_entry->stub_sec = stub_sec;
3208 stub_entry->stub_offset = 0;
3209 stub_entry->id_sec = link_sec;
3213 /* Create sections for linker generated code. */
3216 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
3218 struct ppc_link_hash_table *htab;
3221 htab = ppc_hash_table (info);
3223 /* Create .sfpr for code to save and restore fp regs. */
3224 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
3225 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3226 htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
3227 if (htab->sfpr == NULL
3228 || ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
3229 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
3232 /* Create .glink for lazy dynamic linking support. */
3233 htab->glink = bfd_make_section_anyway (dynobj, ".glink");
3234 if (htab->glink == NULL
3235 || ! bfd_set_section_flags (dynobj, htab->glink, flags)
3236 || ! bfd_set_section_alignment (dynobj, htab->glink, 2))
3239 /* Create .branch_lt for plt_branch stubs. */
3240 flags = (SEC_ALLOC | SEC_LOAD
3241 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3242 htab->brlt = bfd_make_section_anyway (dynobj, ".branch_lt");
3243 if (htab->brlt == NULL
3244 || ! bfd_set_section_flags (dynobj, htab->brlt, flags)
3245 || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
3250 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
3251 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3252 htab->relbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt");
3254 || ! bfd_set_section_flags (dynobj, htab->relbrlt, flags)
3255 || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
3261 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3262 not already done. */
3265 create_got_section (bfd *abfd, struct bfd_link_info *info)
3267 asection *got, *relgot;
3269 struct ppc_link_hash_table *htab = ppc_hash_table (info);
3273 if (! _bfd_elf_create_got_section (htab->elf.dynobj, info))
3276 htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got");
3281 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3282 | SEC_LINKER_CREATED);
3284 got = bfd_make_section (abfd, ".got");
3286 || !bfd_set_section_flags (abfd, got, flags)
3287 || !bfd_set_section_alignment (abfd, got, 3))
3290 relgot = bfd_make_section (abfd, ".rela.got");
3292 || ! bfd_set_section_flags (abfd, relgot, flags | SEC_READONLY)
3293 || ! bfd_set_section_alignment (abfd, relgot, 3))
3296 ppc64_elf_tdata (abfd)->got = got;
3297 ppc64_elf_tdata (abfd)->relgot = relgot;
3301 /* Create the dynamic sections, and set up shortcuts. */
3304 ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
3306 struct ppc_link_hash_table *htab;
3308 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
3311 htab = ppc_hash_table (info);
3313 htab->got = bfd_get_section_by_name (dynobj, ".got");
3314 htab->plt = bfd_get_section_by_name (dynobj, ".plt");
3315 htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt");
3316 htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss");
3318 htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss");
3320 if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss
3321 || (!info->shared && !htab->relbss))
3327 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3330 ppc64_elf_copy_indirect_symbol
3331 (const struct elf_backend_data *bed ATTRIBUTE_UNUSED,
3332 struct elf_link_hash_entry *dir,
3333 struct elf_link_hash_entry *ind)
3335 struct ppc_link_hash_entry *edir, *eind;
3338 edir = (struct ppc_link_hash_entry *) dir;
3339 eind = (struct ppc_link_hash_entry *) ind;
3341 /* Copy over any dynamic relocs we may have on the indirect sym. */
3342 if (eind->dyn_relocs != NULL)
3344 if (edir->dyn_relocs != NULL)
3346 struct ppc_dyn_relocs **pp;
3347 struct ppc_dyn_relocs *p;
3349 if (eind->elf.root.type == bfd_link_hash_indirect)
3352 /* Add reloc counts against the weak sym to the strong sym
3353 list. Merge any entries against the same section. */
3354 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3356 struct ppc_dyn_relocs *q;
3358 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3359 if (q->sec == p->sec)
3361 q->pc_count += p->pc_count;
3362 q->count += p->count;
3369 *pp = edir->dyn_relocs;
3372 edir->dyn_relocs = eind->dyn_relocs;
3373 eind->dyn_relocs = NULL;
3376 edir->is_func |= eind->is_func;
3377 edir->is_func_descriptor |= eind->is_func_descriptor;
3378 edir->is_entry |= eind->is_entry;
3379 edir->tls_mask |= eind->tls_mask;
3381 mask = (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_REF_REGULAR
3382 | ELF_LINK_HASH_REF_REGULAR_NONWEAK | ELF_LINK_NON_GOT_REF
3383 | ELF_LINK_HASH_NEEDS_PLT);
3384 /* If called to transfer flags for a weakdef during processing
3385 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
3386 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3387 if (ELIMINATE_COPY_RELOCS
3388 && eind->elf.root.type != bfd_link_hash_indirect
3389 && (edir->elf.elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
3390 mask &= ~ELF_LINK_NON_GOT_REF;
3392 edir->elf.elf_link_hash_flags |= eind->elf.elf_link_hash_flags & mask;
3394 /* If we were called to copy over info for a weak sym, that's all. */
3395 if (eind->elf.root.type != bfd_link_hash_indirect)
3398 /* Copy over got entries that we may have already seen to the
3399 symbol which just became indirect. */
3400 if (eind->elf.got.glist != NULL)
3402 if (edir->elf.got.glist != NULL)
3404 struct got_entry **entp;
3405 struct got_entry *ent;
3407 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
3409 struct got_entry *dent;
3411 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
3412 if (dent->addend == ent->addend
3413 && dent->owner == ent->owner
3414 && dent->tls_type == ent->tls_type)
3416 dent->got.refcount += ent->got.refcount;
3423 *entp = edir->elf.got.glist;
3426 edir->elf.got.glist = eind->elf.got.glist;
3427 eind->elf.got.glist = NULL;
3430 /* And plt entries. */
3431 if (eind->elf.plt.plist != NULL)
3433 if (edir->elf.plt.plist != NULL)
3435 struct plt_entry **entp;
3436 struct plt_entry *ent;
3438 for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
3440 struct plt_entry *dent;
3442 for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
3443 if (dent->addend == ent->addend)
3445 dent->plt.refcount += ent->plt.refcount;
3452 *entp = edir->elf.plt.plist;
3455 edir->elf.plt.plist = eind->elf.plt.plist;
3456 eind->elf.plt.plist = NULL;
3459 if (edir->elf.dynindx == -1)
3461 edir->elf.dynindx = eind->elf.dynindx;
3462 edir->elf.dynstr_index = eind->elf.dynstr_index;
3463 eind->elf.dynindx = -1;
3464 eind->elf.dynstr_index = 0;
3467 BFD_ASSERT (eind->elf.dynindx == -1);
3470 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
3471 symbols undefined on the command-line. */
3474 ppc64_elf_mark_entry_syms (struct bfd_link_info *info)
3476 struct ppc_link_hash_table *htab;
3477 struct bfd_sym_chain *sym;
3479 htab = ppc_hash_table (info);
3480 for (sym = info->gc_sym_list; sym; sym = sym->next)
3482 struct elf_link_hash_entry *h;
3484 h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE);
3486 ((struct ppc_link_hash_entry *) h)->is_entry = 1;
3491 /* Hack symbols defined in .opd sections to be function type. */
3494 ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED,
3495 struct bfd_link_info *info ATTRIBUTE_UNUSED,
3496 Elf_Internal_Sym *isym,
3497 const char **name ATTRIBUTE_UNUSED,
3498 flagword *flags ATTRIBUTE_UNUSED,
3500 bfd_vma *value ATTRIBUTE_UNUSED)
3502 if (strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0)
3503 isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
3508 update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
3509 unsigned long r_symndx, bfd_vma r_addend, int tls_type)
3511 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
3512 char *local_got_tls_masks;
3514 if (local_got_ents == NULL)
3516 bfd_size_type size = symtab_hdr->sh_info;
3518 size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks);
3519 local_got_ents = bfd_zalloc (abfd, size);
3520 if (local_got_ents == NULL)
3522 elf_local_got_ents (abfd) = local_got_ents;
3525 if ((tls_type & TLS_EXPLICIT) == 0)
3527 struct got_entry *ent;
3529 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
3530 if (ent->addend == r_addend
3531 && ent->owner == abfd
3532 && ent->tls_type == tls_type)
3536 bfd_size_type amt = sizeof (*ent);
3537 ent = bfd_alloc (abfd, amt);
3540 ent->next = local_got_ents[r_symndx];
3541 ent->addend = r_addend;
3543 ent->tls_type = tls_type;
3544 ent->got.refcount = 0;
3545 local_got_ents[r_symndx] = ent;
3547 ent->got.refcount += 1;
3550 local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
3551 local_got_tls_masks[r_symndx] |= tls_type;
3556 update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend)
3558 struct plt_entry *ent;
3560 for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next)
3561 if (ent->addend == addend)
3565 bfd_size_type amt = sizeof (*ent);
3566 ent = bfd_alloc (abfd, amt);
3569 ent->next = eh->elf.plt.plist;
3570 ent->addend = addend;
3571 ent->plt.refcount = 0;
3572 eh->elf.plt.plist = ent;
3574 ent->plt.refcount += 1;
3575 eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3580 /* Find the function descriptor hash entry from the given function code
3581 hash entry FH. Link the entries via their OH fields. */
3582 static struct ppc_link_hash_entry *
3583 get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
3585 struct ppc_link_hash_entry *fdh = fh->oh;
3589 const char *fd_name = fh->elf.root.root.string + 1;
3591 fdh = (struct ppc_link_hash_entry *)
3592 elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
3595 fdh->is_func_descriptor = 1;
3605 /* Look through the relocs for a section during the first phase, and
3606 calculate needed space in the global offset table, procedure
3607 linkage table, and dynamic reloc sections. */
3610 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
3611 asection *sec, const Elf_Internal_Rela *relocs)
3613 struct ppc_link_hash_table *htab;
3614 Elf_Internal_Shdr *symtab_hdr;
3615 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
3616 const Elf_Internal_Rela *rel;
3617 const Elf_Internal_Rela *rel_end;
3619 asection **opd_sym_map;
3621 if (info->relocatable)
3624 /* Don't do anything special with non-loaded, non-alloced sections.
3625 In particular, any relocs in such sections should not affect GOT
3626 and PLT reference counting (ie. we don't allow them to create GOT
3627 or PLT entries), there's no possibility or desire to optimize TLS
3628 relocs, and there's not much point in propagating relocs to shared
3629 libs that the dynamic linker won't relocate. */
3630 if ((sec->flags & SEC_ALLOC) == 0)
3633 htab = ppc_hash_table (info);
3634 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3636 sym_hashes = elf_sym_hashes (abfd);
3637 sym_hashes_end = (sym_hashes
3638 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym)
3639 - symtab_hdr->sh_info);
3643 if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0)
3645 /* Garbage collection needs some extra help with .opd sections.
3646 We don't want to necessarily keep everything referenced by
3647 relocs in .opd, as that would keep all functions. Instead,
3648 if we reference an .opd symbol (a function descriptor), we
3649 want to keep the function code symbol's section. This is
3650 easy for global symbols, but for local syms we need to keep
3651 information about the associated function section. Later, if
3652 edit_opd deletes entries, we'll use this array to adjust
3653 local syms in .opd. */
3655 asection *func_section;
3660 amt = sec->size * sizeof (union opd_info) / 24;
3661 opd_sym_map = bfd_zalloc (abfd, amt);
3662 if (opd_sym_map == NULL)
3664 ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map;
3667 if (htab->sfpr == NULL
3668 && !create_linkage_sections (htab->elf.dynobj, info))
3671 rel_end = relocs + sec->reloc_count;
3672 for (rel = relocs; rel < rel_end; rel++)
3674 unsigned long r_symndx;
3675 struct elf_link_hash_entry *h;
3676 enum elf_ppc64_reloc_type r_type;
3679 r_symndx = ELF64_R_SYM (rel->r_info);
3680 if (r_symndx < symtab_hdr->sh_info)
3683 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3685 r_type = ELF64_R_TYPE (rel->r_info);
3688 case R_PPC64_GOT_TLSLD16:
3689 case R_PPC64_GOT_TLSLD16_LO:
3690 case R_PPC64_GOT_TLSLD16_HI:
3691 case R_PPC64_GOT_TLSLD16_HA:
3692 ppc64_tlsld_got (abfd)->refcount += 1;
3693 tls_type = TLS_TLS | TLS_LD;
3696 case R_PPC64_GOT_TLSGD16:
3697 case R_PPC64_GOT_TLSGD16_LO:
3698 case R_PPC64_GOT_TLSGD16_HI:
3699 case R_PPC64_GOT_TLSGD16_HA:
3700 tls_type = TLS_TLS | TLS_GD;
3703 case R_PPC64_GOT_TPREL16_DS:
3704 case R_PPC64_GOT_TPREL16_LO_DS:
3705 case R_PPC64_GOT_TPREL16_HI:
3706 case R_PPC64_GOT_TPREL16_HA:
3708 info->flags |= DF_STATIC_TLS;
3709 tls_type = TLS_TLS | TLS_TPREL;
3712 case R_PPC64_GOT_DTPREL16_DS:
3713 case R_PPC64_GOT_DTPREL16_LO_DS:
3714 case R_PPC64_GOT_DTPREL16_HI:
3715 case R_PPC64_GOT_DTPREL16_HA:
3716 tls_type = TLS_TLS | TLS_DTPREL;
3718 sec->has_tls_reloc = 1;
3722 case R_PPC64_GOT16_DS:
3723 case R_PPC64_GOT16_HA:
3724 case R_PPC64_GOT16_HI:
3725 case R_PPC64_GOT16_LO:
3726 case R_PPC64_GOT16_LO_DS:
3727 /* This symbol requires a global offset table entry. */
3728 sec->has_gp_reloc = 1;
3729 if (ppc64_elf_tdata (abfd)->got == NULL
3730 && !create_got_section (abfd, info))
3735 struct ppc_link_hash_entry *eh;
3736 struct got_entry *ent;
3738 eh = (struct ppc_link_hash_entry *) h;
3739 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
3740 if (ent->addend == rel->r_addend
3741 && ent->owner == abfd
3742 && ent->tls_type == tls_type)
3746 bfd_size_type amt = sizeof (*ent);
3747 ent = bfd_alloc (abfd, amt);
3750 ent->next = eh->elf.got.glist;
3751 ent->addend = rel->r_addend;
3753 ent->tls_type = tls_type;
3754 ent->got.refcount = 0;
3755 eh->elf.got.glist = ent;
3757 ent->got.refcount += 1;
3758 eh->tls_mask |= tls_type;
3761 /* This is a global offset table entry for a local symbol. */
3762 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
3763 rel->r_addend, tls_type))
3767 case R_PPC64_PLT16_HA:
3768 case R_PPC64_PLT16_HI:
3769 case R_PPC64_PLT16_LO:
3772 /* This symbol requires a procedure linkage table entry. We
3773 actually build the entry in adjust_dynamic_symbol,
3774 because this might be a case of linking PIC code without
3775 linking in any dynamic objects, in which case we don't
3776 need to generate a procedure linkage table after all. */
3779 /* It does not make sense to have a procedure linkage
3780 table entry for a local symbol. */
3781 bfd_set_error (bfd_error_bad_value);
3785 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
3790 /* The following relocations don't need to propagate the
3791 relocation if linking a shared object since they are
3792 section relative. */
3793 case R_PPC64_SECTOFF:
3794 case R_PPC64_SECTOFF_LO:
3795 case R_PPC64_SECTOFF_HI:
3796 case R_PPC64_SECTOFF_HA:
3797 case R_PPC64_SECTOFF_DS:
3798 case R_PPC64_SECTOFF_LO_DS:
3799 case R_PPC64_DTPREL16:
3800 case R_PPC64_DTPREL16_LO:
3801 case R_PPC64_DTPREL16_HI:
3802 case R_PPC64_DTPREL16_HA:
3803 case R_PPC64_DTPREL16_DS:
3804 case R_PPC64_DTPREL16_LO_DS:
3805 case R_PPC64_DTPREL16_HIGHER:
3806 case R_PPC64_DTPREL16_HIGHERA:
3807 case R_PPC64_DTPREL16_HIGHEST:
3808 case R_PPC64_DTPREL16_HIGHESTA:
3813 case R_PPC64_TOC16_LO:
3814 case R_PPC64_TOC16_HI:
3815 case R_PPC64_TOC16_HA:
3816 case R_PPC64_TOC16_DS:
3817 case R_PPC64_TOC16_LO_DS:
3818 sec->has_gp_reloc = 1;
3821 /* This relocation describes the C++ object vtable hierarchy.
3822 Reconstruct it for later use during GC. */
3823 case R_PPC64_GNU_VTINHERIT:
3824 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3828 /* This relocation describes which C++ vtable entries are actually
3829 used. Record for later use during GC. */
3830 case R_PPC64_GNU_VTENTRY:
3831 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3836 case R_PPC64_REL14_BRTAKEN:
3837 case R_PPC64_REL14_BRNTAKEN:
3838 htab->has_14bit_branch = 1;
3843 && h->root.root.string[0] == '.'
3844 && h->root.root.string[1] != 0)
3846 /* We may need a .plt entry if the function this reloc
3847 refers to is in a shared lib. */
3848 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
3851 if (h == htab->tls_get_addr)
3852 sec->has_tls_reloc = 1;
3853 else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15)
3855 && (h->root.root.string[15] == 0
3856 || h->root.root.string[15] == '@'))
3858 htab->tls_get_addr = h;
3859 sec->has_tls_reloc = 1;
3864 case R_PPC64_TPREL64:
3865 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
3867 info->flags |= DF_STATIC_TLS;
3870 case R_PPC64_DTPMOD64:
3871 if (rel + 1 < rel_end
3872 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
3873 && rel[1].r_offset == rel->r_offset + 8)
3874 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
3876 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
3879 case R_PPC64_DTPREL64:
3880 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
3882 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
3883 && rel[-1].r_offset == rel->r_offset - 8)
3884 /* This is the second reloc of a dtpmod, dtprel pair.
3885 Don't mark with TLS_DTPREL. */
3889 sec->has_tls_reloc = 1;
3892 struct ppc_link_hash_entry *eh;
3893 eh = (struct ppc_link_hash_entry *) h;
3894 eh->tls_mask |= tls_type;
3897 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
3898 rel->r_addend, tls_type))
3901 if (ppc64_elf_section_data (sec)->t_symndx == NULL)
3903 /* One extra to simplify get_tls_mask. */
3904 bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1;
3905 ppc64_elf_section_data (sec)->t_symndx = bfd_zalloc (abfd, amt);
3906 if (ppc64_elf_section_data (sec)->t_symndx == NULL)
3909 BFD_ASSERT (rel->r_offset % 8 == 0);
3910 ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx;
3912 /* Mark the second slot of a GD or LD entry.
3913 -1 to indicate GD and -2 to indicate LD. */
3914 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
3915 ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1;
3916 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
3917 ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2;
3920 case R_PPC64_TPREL16:
3921 case R_PPC64_TPREL16_LO:
3922 case R_PPC64_TPREL16_HI:
3923 case R_PPC64_TPREL16_HA:
3924 case R_PPC64_TPREL16_DS:
3925 case R_PPC64_TPREL16_LO_DS:
3926 case R_PPC64_TPREL16_HIGHER:
3927 case R_PPC64_TPREL16_HIGHERA:
3928 case R_PPC64_TPREL16_HIGHEST:
3929 case R_PPC64_TPREL16_HIGHESTA:
3932 info->flags |= DF_STATIC_TLS;
3937 case R_PPC64_ADDR64:
3938 if (opd_sym_map != NULL
3940 && h->root.root.string[0] == '.'
3941 && h->root.root.string[1] != 0)
3942 get_fdh ((struct ppc_link_hash_entry *) h, htab);
3944 if (opd_sym_map != NULL
3946 && rel + 1 < rel_end
3947 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
3951 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
3956 opd_sym_map[rel->r_offset / 24] = s;
3963 case R_PPC64_ADDR14:
3964 case R_PPC64_ADDR14_BRNTAKEN:
3965 case R_PPC64_ADDR14_BRTAKEN:
3966 case R_PPC64_ADDR16:
3967 case R_PPC64_ADDR16_DS:
3968 case R_PPC64_ADDR16_HA:
3969 case R_PPC64_ADDR16_HI:
3970 case R_PPC64_ADDR16_HIGHER:
3971 case R_PPC64_ADDR16_HIGHERA:
3972 case R_PPC64_ADDR16_HIGHEST:
3973 case R_PPC64_ADDR16_HIGHESTA:
3974 case R_PPC64_ADDR16_LO:
3975 case R_PPC64_ADDR16_LO_DS:
3976 case R_PPC64_ADDR24:
3977 case R_PPC64_ADDR32:
3978 case R_PPC64_UADDR16:
3979 case R_PPC64_UADDR32:
3980 case R_PPC64_UADDR64:
3982 if (h != NULL && !info->shared)
3983 /* We may need a copy reloc. */
3984 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
3986 /* Don't propagate .opd relocs. */
3987 if (NO_OPD_RELOCS && opd_sym_map != NULL)
3990 /* If we are creating a shared library, and this is a reloc
3991 against a global symbol, or a non PC relative reloc
3992 against a local symbol, then we need to copy the reloc
3993 into the shared library. However, if we are linking with
3994 -Bsymbolic, we do not need to copy a reloc against a
3995 global symbol which is defined in an object we are
3996 including in the link (i.e., DEF_REGULAR is set). At
3997 this point we have not seen all the input files, so it is
3998 possible that DEF_REGULAR is not set now but will be set
3999 later (it is never cleared). In case of a weak definition,
4000 DEF_REGULAR may be cleared later by a strong definition in
4001 a shared library. We account for that possibility below by
4002 storing information in the dyn_relocs field of the hash
4003 table entry. A similar situation occurs when creating
4004 shared libraries and symbol visibility changes render the
4007 If on the other hand, we are creating an executable, we
4008 may need to keep relocations for symbols satisfied by a
4009 dynamic library if we manage to avoid copy relocs for the
4013 && (MUST_BE_DYN_RELOC (r_type)
4015 && (! info->symbolic
4016 || h->root.type == bfd_link_hash_defweak
4017 || (h->elf_link_hash_flags
4018 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
4019 || (ELIMINATE_COPY_RELOCS
4022 && (h->root.type == bfd_link_hash_defweak
4023 || (h->elf_link_hash_flags
4024 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
4026 struct ppc_dyn_relocs *p;
4027 struct ppc_dyn_relocs **head;
4029 /* We must copy these reloc types into the output file.
4030 Create a reloc section in dynobj and make room for
4037 name = (bfd_elf_string_from_elf_section
4039 elf_elfheader (abfd)->e_shstrndx,
4040 elf_section_data (sec)->rel_hdr.sh_name));
4044 if (strncmp (name, ".rela", 5) != 0
4045 || strcmp (bfd_get_section_name (abfd, sec),
4048 (*_bfd_error_handler)
4049 (_("%s: bad relocation section name `%s\'"),
4050 bfd_archive_filename (abfd), name);
4051 bfd_set_error (bfd_error_bad_value);
4054 dynobj = htab->elf.dynobj;
4055 sreloc = bfd_get_section_by_name (dynobj, name);
4060 sreloc = bfd_make_section (dynobj, name);
4061 flags = (SEC_HAS_CONTENTS | SEC_READONLY
4062 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4063 if ((sec->flags & SEC_ALLOC) != 0)
4064 flags |= SEC_ALLOC | SEC_LOAD;
4066 || ! bfd_set_section_flags (dynobj, sreloc, flags)
4067 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
4070 elf_section_data (sec)->sreloc = sreloc;
4073 /* If this is a global symbol, we count the number of
4074 relocations we need for this symbol. */
4077 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
4081 /* Track dynamic relocs needed for local syms too.
4082 We really need local syms available to do this
4086 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
4091 head = ((struct ppc_dyn_relocs **)
4092 &elf_section_data (s)->local_dynrel);
4096 if (p == NULL || p->sec != sec)
4098 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
4109 if (!MUST_BE_DYN_RELOC (r_type))
4122 /* Return the section that should be marked against GC for a given
4126 ppc64_elf_gc_mark_hook (asection *sec,
4127 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4128 Elf_Internal_Rela *rel,
4129 struct elf_link_hash_entry *h,
4130 Elf_Internal_Sym *sym)
4132 asection *rsec = NULL;
4136 enum elf_ppc64_reloc_type r_type;
4137 struct ppc_link_hash_entry *fdh;
4139 r_type = ELF64_R_TYPE (rel->r_info);
4142 case R_PPC64_GNU_VTINHERIT:
4143 case R_PPC64_GNU_VTENTRY:
4147 switch (h->root.type)
4149 case bfd_link_hash_defined:
4150 case bfd_link_hash_defweak:
4151 fdh = (struct ppc_link_hash_entry *) h;
4153 /* Function descriptor syms cause the associated
4154 function code sym section to be marked. */
4155 if (fdh->is_func_descriptor)
4156 rsec = fdh->oh->elf.root.u.def.section;
4158 /* Function entry syms return NULL if they are in .opd
4159 and are not ._start (or others undefined on the ld
4160 command line). Thus we avoid marking all function
4161 sections, as all functions are referenced in .opd. */
4162 else if ((fdh->oh != NULL && fdh->oh->is_entry)
4163 || ppc64_elf_section_data (sec)->opd.func_sec == NULL)
4164 rsec = h->root.u.def.section;
4167 case bfd_link_hash_common:
4168 rsec = h->root.u.c.p->section;
4178 asection **opd_sym_section;
4180 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4181 opd_sym_section = ppc64_elf_section_data (rsec)->opd.func_sec;
4182 if (opd_sym_section != NULL)
4183 rsec = opd_sym_section[sym->st_value / 24];
4184 else if (ppc64_elf_section_data (sec)->opd.func_sec != NULL)
4191 /* Update the .got, .plt. and dynamic reloc reference counts for the
4192 section being removed. */
4195 ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
4196 asection *sec, const Elf_Internal_Rela *relocs)
4198 struct ppc_link_hash_table *htab;
4199 Elf_Internal_Shdr *symtab_hdr;
4200 struct elf_link_hash_entry **sym_hashes;
4201 struct got_entry **local_got_ents;
4202 const Elf_Internal_Rela *rel, *relend;
4204 if ((sec->flags & SEC_ALLOC) == 0)
4207 elf_section_data (sec)->local_dynrel = NULL;
4209 htab = ppc_hash_table (info);
4210 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4211 sym_hashes = elf_sym_hashes (abfd);
4212 local_got_ents = elf_local_got_ents (abfd);
4214 relend = relocs + sec->reloc_count;
4215 for (rel = relocs; rel < relend; rel++)
4217 unsigned long r_symndx;
4218 enum elf_ppc64_reloc_type r_type;
4219 struct elf_link_hash_entry *h = NULL;
4222 r_symndx = ELF64_R_SYM (rel->r_info);
4223 r_type = ELF64_R_TYPE (rel->r_info);
4224 if (r_symndx >= symtab_hdr->sh_info)
4226 struct ppc_link_hash_entry *eh;
4227 struct ppc_dyn_relocs **pp;
4228 struct ppc_dyn_relocs *p;
4230 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4231 eh = (struct ppc_link_hash_entry *) h;
4233 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
4236 /* Everything must go for SEC. */
4244 case R_PPC64_GOT_TLSLD16:
4245 case R_PPC64_GOT_TLSLD16_LO:
4246 case R_PPC64_GOT_TLSLD16_HI:
4247 case R_PPC64_GOT_TLSLD16_HA:
4248 ppc64_tlsld_got (abfd)->refcount -= 1;
4249 tls_type = TLS_TLS | TLS_LD;
4252 case R_PPC64_GOT_TLSGD16:
4253 case R_PPC64_GOT_TLSGD16_LO:
4254 case R_PPC64_GOT_TLSGD16_HI:
4255 case R_PPC64_GOT_TLSGD16_HA:
4256 tls_type = TLS_TLS | TLS_GD;
4259 case R_PPC64_GOT_TPREL16_DS:
4260 case R_PPC64_GOT_TPREL16_LO_DS:
4261 case R_PPC64_GOT_TPREL16_HI:
4262 case R_PPC64_GOT_TPREL16_HA:
4263 tls_type = TLS_TLS | TLS_TPREL;
4266 case R_PPC64_GOT_DTPREL16_DS:
4267 case R_PPC64_GOT_DTPREL16_LO_DS:
4268 case R_PPC64_GOT_DTPREL16_HI:
4269 case R_PPC64_GOT_DTPREL16_HA:
4270 tls_type = TLS_TLS | TLS_DTPREL;
4274 case R_PPC64_GOT16_DS:
4275 case R_PPC64_GOT16_HA:
4276 case R_PPC64_GOT16_HI:
4277 case R_PPC64_GOT16_LO:
4278 case R_PPC64_GOT16_LO_DS:
4281 struct got_entry *ent;
4286 ent = local_got_ents[r_symndx];
4288 for (; ent != NULL; ent = ent->next)
4289 if (ent->addend == rel->r_addend
4290 && ent->owner == abfd
4291 && ent->tls_type == tls_type)
4295 if (ent->got.refcount > 0)
4296 ent->got.refcount -= 1;
4300 case R_PPC64_PLT16_HA:
4301 case R_PPC64_PLT16_HI:
4302 case R_PPC64_PLT16_LO:
4306 case R_PPC64_REL14_BRNTAKEN:
4307 case R_PPC64_REL14_BRTAKEN:
4311 struct plt_entry *ent;
4313 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4314 if (ent->addend == rel->r_addend)
4318 if (ent->plt.refcount > 0)
4319 ent->plt.refcount -= 1;
4330 /* Called via elf_link_hash_traverse to transfer dynamic linking
4331 information on function code symbol entries to their corresponding
4332 function descriptor symbol entries. */
4334 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
4336 struct bfd_link_info *info;
4337 struct ppc_link_hash_table *htab;
4338 struct plt_entry *ent;
4339 struct ppc_link_hash_entry *fh;
4340 struct ppc_link_hash_entry *fdh;
4341 bfd_boolean force_local;
4343 fh = (struct ppc_link_hash_entry *) h;
4344 if (fh->elf.root.type == bfd_link_hash_indirect)
4347 if (fh->elf.root.type == bfd_link_hash_warning)
4348 fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link;
4351 htab = ppc_hash_table (info);
4353 /* If this is a function code symbol, transfer dynamic linking
4354 information to the function descriptor symbol. */
4358 if (fh->elf.root.type == bfd_link_hash_undefweak
4359 && (fh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
4360 htab->have_undefweak = TRUE;
4362 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
4363 if (ent->plt.refcount > 0)
4366 || fh->elf.root.root.string[0] != '.'
4367 || fh->elf.root.root.string[1] == '\0')
4370 /* Find the corresponding function descriptor symbol. Create it
4371 as undefined if necessary. */
4373 fdh = get_fdh (fh, htab);
4375 while (fdh->elf.root.type == bfd_link_hash_indirect
4376 || fdh->elf.root.type == bfd_link_hash_warning)
4377 fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link;
4381 && (fh->elf.root.type == bfd_link_hash_undefined
4382 || fh->elf.root.type == bfd_link_hash_undefweak))
4386 struct bfd_link_hash_entry *bh;
4388 abfd = fh->elf.root.u.undef.abfd;
4389 newsym = bfd_make_empty_symbol (abfd);
4390 newsym->name = fh->elf.root.root.string + 1;
4391 newsym->section = bfd_und_section_ptr;
4393 newsym->flags = BSF_OBJECT;
4394 if (fh->elf.root.type == bfd_link_hash_undefweak)
4395 newsym->flags |= BSF_WEAK;
4397 bh = &fdh->elf.root;
4398 if ( !(_bfd_generic_link_add_one_symbol
4399 (info, abfd, newsym->name, newsym->flags,
4400 newsym->section, newsym->value, NULL, FALSE, FALSE, &bh)))
4404 fdh = (struct ppc_link_hash_entry *) bh;
4405 fdh->elf.elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
4407 fdh->elf.type = STT_OBJECT;
4411 && (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
4413 || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4414 || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
4415 || (fdh->elf.root.type == bfd_link_hash_undefweak
4416 && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT)))
4418 if (fdh->elf.dynindx == -1)
4419 if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
4421 fdh->elf.elf_link_hash_flags
4422 |= (fh->elf.elf_link_hash_flags & (ELF_LINK_HASH_REF_REGULAR
4423 | ELF_LINK_HASH_REF_DYNAMIC
4424 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
4425 | ELF_LINK_NON_GOT_REF));
4426 if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT)
4428 fdh->elf.plt.plist = fh->elf.plt.plist;
4429 fdh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
4431 fdh->is_func_descriptor = 1;
4436 /* Now that the info is on the function descriptor, clear the
4437 function code sym info. Any function code syms for which we
4438 don't have a definition in a regular file, we force local.
4439 This prevents a shared library from exporting syms that have
4440 been imported from another library. Function code syms that
4441 are really in the library we must leave global to prevent the
4442 linker dragging in a definition from a static library. */
4445 && ((fh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
4447 || (fdh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
4448 || (fdh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0));
4449 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
4454 #define MIN_SAVE_FPR 14
4455 #define MAX_SAVE_FPR 31
4457 /* Called near the start of bfd_elf_size_dynamic_sections. We use
4458 this hook to a) provide some gcc support functions, and b) transfer
4459 dynamic linking information gathered so far on function code symbol
4460 entries, to their corresponding function descriptor symbol entries. */
4462 ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
4463 struct bfd_link_info *info)
4465 struct ppc_link_hash_table *htab;
4466 unsigned int lowest_savef = MAX_SAVE_FPR + 2;
4467 unsigned int lowest_restf = MAX_SAVE_FPR + 2;
4469 struct elf_link_hash_entry *h;
4473 htab = ppc_hash_table (info);
4475 if (htab->sfpr == NULL)
4476 /* We don't have any relocs. */
4479 /* First provide any missing ._savef* and ._restf* functions. */
4480 memcpy (sym, "._savef14", 10);
4481 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
4483 sym[7] = i / 10 + '0';
4484 sym[8] = i % 10 + '0';
4485 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
4487 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4489 if (lowest_savef > i)
4491 h->root.type = bfd_link_hash_defined;
4492 h->root.u.def.section = htab->sfpr;
4493 h->root.u.def.value = (i - lowest_savef) * 4;
4495 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4496 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
4500 memcpy (sym, "._restf14", 10);
4501 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
4503 sym[7] = i / 10 + '0';
4504 sym[8] = i % 10 + '0';
4505 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
4507 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4509 if (lowest_restf > i)
4511 h->root.type = bfd_link_hash_defined;
4512 h->root.u.def.section = htab->sfpr;
4513 h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
4514 + (i - lowest_restf) * 4);
4516 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4517 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
4521 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
4523 htab->sfpr->size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
4524 + (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
4526 if (htab->sfpr->size == 0)
4528 if (!htab->have_undefweak)
4530 _bfd_strip_section_from_output (info, htab->sfpr);
4534 htab->sfpr->size = 4;
4537 p = bfd_alloc (htab->elf.dynobj, htab->sfpr->size);
4540 htab->sfpr->contents = p;
4542 for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
4544 unsigned int fpr = i << 21;
4545 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
4546 bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
4549 if (lowest_savef <= MAX_SAVE_FPR)
4551 bfd_put_32 (htab->elf.dynobj, BLR, p);
4555 for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
4557 unsigned int fpr = i << 21;
4558 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
4559 bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
4562 if (lowest_restf <= MAX_SAVE_FPR
4563 || htab->sfpr->size == 4)
4565 bfd_put_32 (htab->elf.dynobj, BLR, p);
4571 /* Adjust a symbol defined by a dynamic object and referenced by a
4572 regular object. The current definition is in some section of the
4573 dynamic object, but we're not including those sections. We have to
4574 change the definition to something the rest of the link can
4578 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4579 struct elf_link_hash_entry *h)
4581 struct ppc_link_hash_table *htab;
4583 unsigned int power_of_two;
4585 htab = ppc_hash_table (info);
4587 /* Deal with function syms. */
4588 if (h->type == STT_FUNC
4589 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4591 /* Clear procedure linkage table information for any symbol that
4592 won't need a .plt entry. */
4593 struct plt_entry *ent;
4594 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4595 if (ent->plt.refcount > 0)
4597 if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
4599 || SYMBOL_CALLS_LOCAL (info, h)
4600 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4601 && h->root.type == bfd_link_hash_undefweak))
4603 h->plt.plist = NULL;
4604 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4608 h->plt.plist = NULL;
4610 /* If this is a weak symbol, and there is a real definition, the
4611 processor independent code will have arranged for us to see the
4612 real definition first, and we can just use the same value. */
4613 if (h->weakdef != NULL)
4615 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
4616 || h->weakdef->root.type == bfd_link_hash_defweak);
4617 h->root.u.def.section = h->weakdef->root.u.def.section;
4618 h->root.u.def.value = h->weakdef->root.u.def.value;
4619 if (ELIMINATE_COPY_RELOCS)
4620 h->elf_link_hash_flags
4621 = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
4622 | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
4626 /* If we are creating a shared library, we must presume that the
4627 only references to the symbol are via the global offset table.
4628 For such cases we need not do anything here; the relocations will
4629 be handled correctly by relocate_section. */
4633 /* If there are no references to this symbol that do not use the
4634 GOT, we don't need to generate a copy reloc. */
4635 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
4638 if (ELIMINATE_COPY_RELOCS)
4640 struct ppc_link_hash_entry * eh;
4641 struct ppc_dyn_relocs *p;
4643 eh = (struct ppc_link_hash_entry *) h;
4644 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4646 s = p->sec->output_section;
4647 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4651 /* If we didn't find any dynamic relocs in read-only sections, then
4652 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4655 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
4660 if (h->plt.plist != NULL)
4662 /* We should never get here, but unfortunately there are versions
4663 of gcc out there that improperly (for this ABI) put initialized
4664 function pointers, vtable refs and suchlike in read-only
4665 sections. Allow them to proceed, but warn that this might
4666 break at runtime. */
4667 (*_bfd_error_handler)
4668 (_("copy reloc against `%s' requires lazy plt linking; "
4669 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
4670 h->root.root.string);
4673 /* This is a reference to a symbol defined by a dynamic object which
4674 is not a function. */
4676 /* We must allocate the symbol in our .dynbss section, which will
4677 become part of the .bss section of the executable. There will be
4678 an entry for this symbol in the .dynsym section. The dynamic
4679 object will contain position independent code, so all references
4680 from the dynamic object to this symbol will go through the global
4681 offset table. The dynamic linker will use the .dynsym entry to
4682 determine the address it must put in the global offset table, so
4683 both the dynamic object and the regular object will refer to the
4684 same memory location for the variable. */
4686 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
4687 to copy the initial value out of the dynamic object and into the
4688 runtime process image. We need to remember the offset into the
4689 .rela.bss section we are going to use. */
4690 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4692 htab->relbss->size += sizeof (Elf64_External_Rela);
4693 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
4696 /* We need to figure out the alignment required for this symbol. I
4697 have no idea how ELF linkers handle this. */
4698 power_of_two = bfd_log2 (h->size);
4699 if (power_of_two > 4)
4702 /* Apply the required alignment. */
4704 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4705 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
4707 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
4711 /* Define the symbol as being at this point in the section. */
4712 h->root.u.def.section = s;
4713 h->root.u.def.value = s->size;
4715 /* Increment the section size to make room for the symbol. */
4721 /* If given a function descriptor symbol, hide both the function code
4722 sym and the descriptor. */
4724 ppc64_elf_hide_symbol (struct bfd_link_info *info,
4725 struct elf_link_hash_entry *h,
4726 bfd_boolean force_local)
4728 struct ppc_link_hash_entry *eh;
4729 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
4731 eh = (struct ppc_link_hash_entry *) h;
4732 if (eh->is_func_descriptor)
4734 struct ppc_link_hash_entry *fh = eh->oh;
4739 struct ppc_link_hash_table *htab;
4742 /* We aren't supposed to use alloca in BFD because on
4743 systems which do not have alloca the version in libiberty
4744 calls xmalloc, which might cause the program to crash
4745 when it runs out of memory. This function doesn't have a
4746 return status, so there's no way to gracefully return an
4747 error. So cheat. We know that string[-1] can be safely
4748 accessed; It's either a string in an ELF string table,
4749 or allocated in an objalloc structure. */
4751 p = eh->elf.root.root.string - 1;
4754 htab = ppc_hash_table (info);
4755 fh = (struct ppc_link_hash_entry *)
4756 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
4759 /* Unfortunately, if it so happens that the string we were
4760 looking for was allocated immediately before this string,
4761 then we overwrote the string terminator. That's the only
4762 reason the lookup should fail. */
4765 q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
4766 while (q >= eh->elf.root.root.string && *q == *p)
4768 if (q < eh->elf.root.root.string && *p == '.')
4769 fh = (struct ppc_link_hash_entry *)
4770 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
4779 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
4784 get_sym_h (struct elf_link_hash_entry **hp, Elf_Internal_Sym **symp,
4785 asection **symsecp, char **tls_maskp, Elf_Internal_Sym **locsymsp,
4786 unsigned long r_symndx, bfd *ibfd)
4788 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4790 if (r_symndx >= symtab_hdr->sh_info)
4792 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
4793 struct elf_link_hash_entry *h;
4795 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4796 while (h->root.type == bfd_link_hash_indirect
4797 || h->root.type == bfd_link_hash_warning)
4798 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4806 if (symsecp != NULL)
4808 asection *symsec = NULL;
4809 if (h->root.type == bfd_link_hash_defined
4810 || h->root.type == bfd_link_hash_defweak)
4811 symsec = h->root.u.def.section;
4815 if (tls_maskp != NULL)
4817 struct ppc_link_hash_entry *eh;
4819 eh = (struct ppc_link_hash_entry *) h;
4820 *tls_maskp = &eh->tls_mask;
4825 Elf_Internal_Sym *sym;
4826 Elf_Internal_Sym *locsyms = *locsymsp;
4828 if (locsyms == NULL)
4830 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4831 if (locsyms == NULL)
4832 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4833 symtab_hdr->sh_info,
4834 0, NULL, NULL, NULL);
4835 if (locsyms == NULL)
4837 *locsymsp = locsyms;
4839 sym = locsyms + r_symndx;
4847 if (symsecp != NULL)
4849 asection *symsec = NULL;
4850 if ((sym->st_shndx != SHN_UNDEF
4851 && sym->st_shndx < SHN_LORESERVE)
4852 || sym->st_shndx > SHN_HIRESERVE)
4853 symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx);
4857 if (tls_maskp != NULL)
4859 struct got_entry **lgot_ents;
4863 lgot_ents = elf_local_got_ents (ibfd);
4864 if (lgot_ents != NULL)
4866 char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info);
4867 tls_mask = &lgot_masks[r_symndx];
4869 *tls_maskp = tls_mask;
4875 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
4876 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
4877 type suitable for optimization, and 1 otherwise. */
4880 get_tls_mask (char **tls_maskp, unsigned long *toc_symndx,
4881 Elf_Internal_Sym **locsymsp,
4882 const Elf_Internal_Rela *rel, bfd *ibfd)
4884 unsigned long r_symndx;
4886 struct elf_link_hash_entry *h;
4887 Elf_Internal_Sym *sym;
4891 r_symndx = ELF64_R_SYM (rel->r_info);
4892 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
4895 if ((*tls_maskp != NULL && **tls_maskp != 0)
4897 || ppc64_elf_section_data (sec)->t_symndx == NULL)
4900 /* Look inside a TOC section too. */
4903 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
4904 off = h->root.u.def.value;
4907 off = sym->st_value;
4908 off += rel->r_addend;
4909 BFD_ASSERT (off % 8 == 0);
4910 r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8];
4911 next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1];
4912 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
4914 if (toc_symndx != NULL)
4915 *toc_symndx = r_symndx;
4917 || ((h->root.type == bfd_link_hash_defined
4918 || h->root.type == bfd_link_hash_defweak)
4919 && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
4920 && (next_r == -1 || next_r == -2))
4925 /* Adjust all global syms defined in opd sections. In gcc generated
4926 code these will already have been done, but I suppose we have to
4927 cater for all sorts of hand written assembly. */
4930 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
4932 struct ppc_link_hash_entry *eh;
4936 if (h->root.type == bfd_link_hash_indirect)
4939 if (h->root.type == bfd_link_hash_warning)
4940 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4942 if (h->root.type != bfd_link_hash_defined
4943 && h->root.type != bfd_link_hash_defweak)
4946 eh = (struct ppc_link_hash_entry *) h;
4947 if (eh->adjust_done)
4950 sym_sec = eh->elf.root.u.def.section;
4951 opd_adjust = get_opd_info (sym_sec);
4952 if (opd_adjust != NULL)
4954 eh->elf.root.u.def.value += opd_adjust[eh->elf.root.u.def.value / 24];
4955 long adjust = opd_adjust[eh->elf.root.u.def.value / 24];
4958 /* This entry has been deleted. */
4959 eh->elf.root.u.def.value = 0;
4960 eh->elf.root.u.def.section = &bfd_abs_section;
4963 eh->elf.root.u.def.value += adjust;
4964 eh->adjust_done = 1;
4969 /* Remove unused Official Procedure Descriptor entries. Currently we
4970 only remove those associated with functions in discarded link-once
4971 sections, or weakly defined functions that have been overridden. It
4972 would be possible to remove many more entries for statically linked
4976 ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info)
4979 bfd_boolean some_edited = FALSE;
4981 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4984 Elf_Internal_Rela *relstart, *rel, *relend;
4985 Elf_Internal_Shdr *symtab_hdr;
4986 Elf_Internal_Sym *local_syms;
4987 struct elf_link_hash_entry **sym_hashes;
4991 bfd_boolean need_edit;
4993 sec = bfd_get_section_by_name (ibfd, ".opd");
4997 amt = sec->size * sizeof (long) / 24;
4998 opd_adjust = get_opd_info (sec);
4999 if (opd_adjust == NULL)
5001 /* Must be a ld -r link. ie. check_relocs hasn't been
5003 opd_adjust = bfd_zalloc (obfd, amt);
5004 ppc64_elf_section_data (sec)->opd.adjust = opd_adjust;
5006 memset (opd_adjust, 0, amt);
5008 if (sec->output_section == bfd_abs_section_ptr)
5011 /* Look through the section relocs. */
5012 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
5016 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
5017 sym_hashes = elf_sym_hashes (ibfd);
5019 /* Read the relocations. */
5020 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
5022 if (relstart == NULL)
5025 /* First run through the relocs to check they are sane, and to
5026 determine whether we need to edit this opd section. */
5029 relend = relstart + sec->reloc_count;
5030 for (rel = relstart; rel < relend; )
5032 enum elf_ppc64_reloc_type r_type;
5033 unsigned long r_symndx;
5035 struct elf_link_hash_entry *h;
5036 Elf_Internal_Sym *sym;
5038 /* .opd contains a regular array of 24 byte entries. We're
5039 only interested in the reloc pointing to a function entry
5041 if (rel->r_offset != offset
5042 || rel + 1 >= relend
5043 || (rel + 1)->r_offset != offset + 8)
5045 /* If someone messes with .opd alignment then after a
5046 "ld -r" we might have padding in the middle of .opd.
5047 Also, there's nothing to prevent someone putting
5048 something silly in .opd with the assembler. No .opd
5049 optimization for them! */
5050 (*_bfd_error_handler)
5051 (_("%s: .opd is not a regular array of opd entries"),
5052 bfd_archive_filename (ibfd));
5057 if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
5058 || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
5060 (*_bfd_error_handler)
5061 (_("%s: unexpected reloc type %u in .opd section"),
5062 bfd_archive_filename (ibfd), r_type);
5067 r_symndx = ELF64_R_SYM (rel->r_info);
5068 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
5072 if (sym_sec == NULL || sym_sec->owner == NULL)
5074 const char *sym_name;
5076 sym_name = h->root.root.string;
5078 sym_name = bfd_elf_local_sym_name (ibfd, sym);
5080 (*_bfd_error_handler)
5081 (_("%s: undefined sym `%s' in .opd section"),
5082 bfd_archive_filename (ibfd),
5088 /* opd entries are always for functions defined in the
5089 current input bfd. If the symbol isn't defined in the
5090 input bfd, then we won't be using the function in this
5091 bfd; It must be defined in a linkonce section in another
5092 bfd, or is weak. It's also possible that we are
5093 discarding the function due to a linker script /DISCARD/,
5094 which we test for via the output_section. */
5095 if (sym_sec->owner != ibfd
5096 || sym_sec->output_section == bfd_abs_section_ptr)
5101 /* Allow for the possibility of a reloc on the third word. */
5103 && rel->r_offset == offset - 8)
5109 Elf_Internal_Rela *write_rel;
5110 bfd_byte *rptr, *wptr;
5113 /* This seems a waste of time as input .opd sections are all
5114 zeros as generated by gcc, but I suppose there's no reason
5115 this will always be so. We might start putting something in
5116 the third word of .opd entries. */
5117 if ((sec->flags & SEC_IN_MEMORY) == 0)
5120 if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
5125 if (local_syms != NULL
5126 && symtab_hdr->contents != (unsigned char *) local_syms)
5128 if (elf_section_data (sec)->relocs != relstart)
5132 sec->contents = loc;
5133 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
5136 elf_section_data (sec)->relocs = relstart;
5138 wptr = sec->contents;
5139 rptr = sec->contents;
5140 write_rel = relstart;
5143 for (rel = relstart; rel < relend; rel++)
5145 unsigned long r_symndx;
5147 struct elf_link_hash_entry *h;
5148 Elf_Internal_Sym *sym;
5150 r_symndx = ELF64_R_SYM (rel->r_info);
5151 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
5155 if (rel->r_offset == offset)
5157 struct ppc_link_hash_entry *fdh = NULL;
5159 && h->root.root.string[0] == '.')
5160 fdh = get_fdh ((struct ppc_link_hash_entry *) h,
5161 ppc_hash_table (info));
5163 skip = (sym_sec->owner != ibfd
5164 || sym_sec->output_section == bfd_abs_section_ptr);
5167 if (fdh != NULL && sym_sec->owner == ibfd)
5169 /* Arrange for the function descriptor sym
5171 fdh->elf.root.u.def.value = 0;
5172 fdh->elf.root.u.def.section = sym_sec;
5174 opd_adjust[rel->r_offset / 24] = -1;
5178 /* We'll be keeping this opd entry. */
5182 /* Redefine the function descriptor symbol to
5183 this location in the opd section. It is
5184 necessary to update the value here rather
5185 than using an array of adjustments as we do
5186 for local symbols, because various places
5187 in the generic ELF code use the value
5188 stored in u.def.value. */
5189 fdh->elf.root.u.def.value = wptr - sec->contents;
5190 fdh->adjust_done = 1;
5193 /* Local syms are a bit tricky. We could
5194 tweak them as they can be cached, but
5195 we'd need to look through the local syms
5196 for the function descriptor sym which we
5197 don't have at the moment. So keep an
5198 array of adjustments. */
5199 opd_adjust[rel->r_offset / 24] = wptr - rptr;
5202 memcpy (wptr, rptr, 24);
5211 BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel->r_info)));
5214 /* We won't be needing dynamic relocs here. */
5215 struct ppc_dyn_relocs **pp;
5216 struct ppc_dyn_relocs *p;
5219 pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
5220 else if (sym_sec != NULL)
5221 pp = ((struct ppc_dyn_relocs **)
5222 &elf_section_data (sym_sec)->local_dynrel);
5224 pp = ((struct ppc_dyn_relocs **)
5225 &elf_section_data (sec)->local_dynrel);
5226 while ((p = *pp) != NULL)
5241 /* We need to adjust any reloc offsets to point to the
5242 new opd entries. While we're at it, we may as well
5243 remove redundant relocs. */
5244 rel->r_offset += wptr - rptr;
5245 if (write_rel != rel)
5246 memcpy (write_rel, rel, sizeof (*rel));
5251 sec->size = wptr - sec->contents;
5252 sec->reloc_count = write_rel - relstart;
5253 /* Fudge the size too, as this is used later in
5254 elf_bfd_final_link if we are emitting relocs. */
5255 elf_section_data (sec)->rel_hdr.sh_size
5256 = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize;
5257 BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL);
5260 else if (elf_section_data (sec)->relocs != relstart)
5263 if (local_syms != NULL
5264 && symtab_hdr->contents != (unsigned char *) local_syms)
5266 if (!info->keep_memory)
5269 symtab_hdr->contents = (unsigned char *) local_syms;
5274 elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
5279 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
5282 ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
5284 struct ppc_link_hash_table *htab;
5286 htab = ppc_hash_table (info);
5287 if (htab->tls_get_addr != NULL)
5289 struct elf_link_hash_entry *h = htab->tls_get_addr;
5291 while (h->root.type == bfd_link_hash_indirect
5292 || h->root.type == bfd_link_hash_warning)
5293 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5295 htab->tls_get_addr = h;
5298 return _bfd_elf_tls_setup (obfd, info);
5301 /* Run through all the TLS relocs looking for optimization
5302 opportunities. The linker has been hacked (see ppc64elf.em) to do
5303 a preliminary section layout so that we know the TLS segment
5304 offsets. We can't optimize earlier because some optimizations need
5305 to know the tp offset, and we need to optimize before allocating
5306 dynamic relocations. */
5309 ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
5313 struct ppc_link_hash_table *htab;
5315 if (info->relocatable || info->shared)
5318 htab = ppc_hash_table (info);
5319 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5321 Elf_Internal_Sym *locsyms = NULL;
5323 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5324 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
5326 Elf_Internal_Rela *relstart, *rel, *relend;
5327 int expecting_tls_get_addr;
5329 /* Read the relocations. */
5330 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
5332 if (relstart == NULL)
5335 expecting_tls_get_addr = 0;
5336 relend = relstart + sec->reloc_count;
5337 for (rel = relstart; rel < relend; rel++)
5339 enum elf_ppc64_reloc_type r_type;
5340 unsigned long r_symndx;
5341 struct elf_link_hash_entry *h;
5342 Elf_Internal_Sym *sym;
5345 char tls_set, tls_clear, tls_type = 0;
5347 bfd_boolean ok_tprel, is_local;
5349 r_symndx = ELF64_R_SYM (rel->r_info);
5350 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
5354 if (elf_section_data (sec)->relocs != relstart)
5357 && (elf_tdata (ibfd)->symtab_hdr.contents
5358 != (unsigned char *) locsyms))
5365 if (h->root.type != bfd_link_hash_defined
5366 && h->root.type != bfd_link_hash_defweak)
5368 value = h->root.u.def.value;
5371 /* Symbols referenced by TLS relocs must be of type
5372 STT_TLS. So no need for .opd local sym adjust. */
5373 value = sym->st_value;
5378 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
5381 value += sym_sec->output_offset;
5382 value += sym_sec->output_section->vma;
5383 value -= htab->elf.tls_sec->vma;
5384 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
5385 < (bfd_vma) 1 << 32);
5388 r_type = ELF64_R_TYPE (rel->r_info);
5391 case R_PPC64_GOT_TLSLD16:
5392 case R_PPC64_GOT_TLSLD16_LO:
5393 case R_PPC64_GOT_TLSLD16_HI:
5394 case R_PPC64_GOT_TLSLD16_HA:
5395 /* These relocs should never be against a symbol
5396 defined in a shared lib. Leave them alone if
5397 that turns out to be the case. */
5398 ppc64_tlsld_got (ibfd)->refcount -= 1;
5405 tls_type = TLS_TLS | TLS_LD;
5406 expecting_tls_get_addr = 1;
5409 case R_PPC64_GOT_TLSGD16:
5410 case R_PPC64_GOT_TLSGD16_LO:
5411 case R_PPC64_GOT_TLSGD16_HI:
5412 case R_PPC64_GOT_TLSGD16_HA:
5418 tls_set = TLS_TLS | TLS_TPRELGD;
5420 tls_type = TLS_TLS | TLS_GD;
5421 expecting_tls_get_addr = 1;
5424 case R_PPC64_GOT_TPREL16_DS:
5425 case R_PPC64_GOT_TPREL16_LO_DS:
5426 case R_PPC64_GOT_TPREL16_HI:
5427 case R_PPC64_GOT_TPREL16_HA:
5428 expecting_tls_get_addr = 0;
5433 tls_clear = TLS_TPREL;
5434 tls_type = TLS_TLS | TLS_TPREL;
5441 case R_PPC64_REL14_BRTAKEN:
5442 case R_PPC64_REL14_BRNTAKEN:
5445 && h == htab->tls_get_addr)
5447 if (!expecting_tls_get_addr
5449 && ((ELF64_R_TYPE (rel[-1].r_info)
5451 || (ELF64_R_TYPE (rel[-1].r_info)
5452 == R_PPC64_TOC16_LO)))
5454 /* Check for toc tls entries. */
5458 retval = get_tls_mask (&toc_tls, NULL, &locsyms,
5462 if (toc_tls != NULL)
5463 expecting_tls_get_addr = retval > 1;
5466 if (expecting_tls_get_addr)
5468 struct plt_entry *ent;
5469 for (ent = h->plt.plist; ent; ent = ent->next)
5470 if (ent->addend == 0)
5472 if (ent->plt.refcount > 0)
5473 ent->plt.refcount -= 1;
5478 expecting_tls_get_addr = 0;
5481 case R_PPC64_TPREL64:
5482 expecting_tls_get_addr = 0;
5486 tls_set = TLS_EXPLICIT;
5487 tls_clear = TLS_TPREL;
5493 case R_PPC64_DTPMOD64:
5494 expecting_tls_get_addr = 0;
5495 if (rel + 1 < relend
5497 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
5498 && rel[1].r_offset == rel->r_offset + 8)
5502 tls_set = TLS_EXPLICIT | TLS_GD;
5505 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
5514 tls_set = TLS_EXPLICIT;
5520 expecting_tls_get_addr = 0;
5524 if ((tls_set & TLS_EXPLICIT) == 0)
5526 struct got_entry *ent;
5528 /* Adjust got entry for this reloc. */
5532 ent = elf_local_got_ents (ibfd)[r_symndx];
5534 for (; ent != NULL; ent = ent->next)
5535 if (ent->addend == rel->r_addend
5536 && ent->owner == ibfd
5537 && ent->tls_type == tls_type)
5544 /* We managed to get rid of a got entry. */
5545 if (ent->got.refcount > 0)
5546 ent->got.refcount -= 1;
5551 struct ppc_link_hash_entry * eh;
5552 struct ppc_dyn_relocs **pp;
5553 struct ppc_dyn_relocs *p;
5555 /* Adjust dynamic relocs. */
5556 eh = (struct ppc_link_hash_entry *) h;
5557 for (pp = &eh->dyn_relocs;
5562 /* If we got rid of a DTPMOD/DTPREL reloc
5563 pair then we'll lose one or two dyn
5565 if (tls_set == (TLS_EXPLICIT | TLS_GD))
5574 *tls_mask |= tls_set;
5575 *tls_mask &= ~tls_clear;
5578 if (elf_section_data (sec)->relocs != relstart)
5583 && (elf_tdata (ibfd)->symtab_hdr.contents
5584 != (unsigned char *) locsyms))
5586 if (!info->keep_memory)
5589 elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms;
5595 /* Allocate space in .plt, .got and associated reloc sections for
5599 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
5601 struct bfd_link_info *info;
5602 struct ppc_link_hash_table *htab;
5604 struct ppc_link_hash_entry *eh;
5605 struct ppc_dyn_relocs *p;
5606 struct got_entry *gent;
5608 if (h->root.type == bfd_link_hash_indirect)
5611 if (h->root.type == bfd_link_hash_warning)
5612 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5614 info = (struct bfd_link_info *) inf;
5615 htab = ppc_hash_table (info);
5617 if (htab->elf.dynamic_sections_created
5619 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
5621 struct plt_entry *pent;
5622 bfd_boolean doneone = FALSE;
5623 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
5624 if (pent->plt.refcount > 0)
5626 BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
5628 /* If this is the first .plt entry, make room for the special
5632 s->size += PLT_INITIAL_ENTRY_SIZE;
5634 pent->plt.offset = s->size;
5636 /* Make room for this entry. */
5637 s->size += PLT_ENTRY_SIZE;
5639 /* Make room for the .glink code. */
5642 s->size += GLINK_CALL_STUB_SIZE;
5643 /* We need bigger stubs past index 32767. */
5644 if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
5648 /* We also need to make an entry in the .rela.plt section. */
5650 s->size += sizeof (Elf64_External_Rela);
5654 pent->plt.offset = (bfd_vma) -1;
5657 h->plt.plist = NULL;
5658 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
5663 h->plt.plist = NULL;
5664 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
5667 eh = (struct ppc_link_hash_entry *) h;
5668 /* Run through the TLS GD got entries first if we're changing them
5670 if ((eh->tls_mask & TLS_TPRELGD) != 0)
5671 for (gent = h->got.glist; gent != NULL; gent = gent->next)
5672 if (gent->got.refcount > 0
5673 && (gent->tls_type & TLS_GD) != 0)
5675 /* This was a GD entry that has been converted to TPREL. If
5676 there happens to be a TPREL entry we can use that one. */
5677 struct got_entry *ent;
5678 for (ent = h->got.glist; ent != NULL; ent = ent->next)
5679 if (ent->got.refcount > 0
5680 && (ent->tls_type & TLS_TPREL) != 0
5681 && ent->addend == gent->addend
5682 && ent->owner == gent->owner)
5684 gent->got.refcount = 0;
5688 /* If not, then we'll be using our own TPREL entry. */
5689 if (gent->got.refcount != 0)
5690 gent->tls_type = TLS_TLS | TLS_TPREL;
5693 for (gent = h->got.glist; gent != NULL; gent = gent->next)
5694 if (gent->got.refcount > 0)
5698 /* Make sure this symbol is output as a dynamic symbol.
5699 Undefined weak syms won't yet be marked as dynamic,
5700 nor will all TLS symbols. */
5701 if (h->dynindx == -1
5702 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
5704 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5708 if ((gent->tls_type & TLS_LD) != 0
5709 && !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
5711 gent->got.offset = ppc64_tlsld_got (gent->owner)->offset;
5715 s = ppc64_elf_tdata (gent->owner)->got;
5716 gent->got.offset = s->size;
5718 += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8;
5719 dyn = htab->elf.dynamic_sections_created;
5721 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
5722 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5723 || h->root.type != bfd_link_hash_undefweak))
5724 ppc64_elf_tdata (gent->owner)->relgot->size
5725 += (gent->tls_type & eh->tls_mask & TLS_GD
5726 ? 2 * sizeof (Elf64_External_Rela)
5727 : sizeof (Elf64_External_Rela));
5730 gent->got.offset = (bfd_vma) -1;
5732 if (eh->dyn_relocs == NULL)
5735 /* In the shared -Bsymbolic case, discard space allocated for
5736 dynamic pc-relative relocs against symbols which turn out to be
5737 defined in regular objects. For the normal shared case, discard
5738 space for relocs that have become local due to symbol visibility
5743 /* Relocs that use pc_count are those that appear on a call insn,
5744 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
5745 generated via assembly. We want calls to protected symbols to
5746 resolve directly to the function rather than going via the plt.
5747 If people want function pointer comparisons to work as expected
5748 then they should avoid writing weird assembly. */
5749 if (SYMBOL_CALLS_LOCAL (info, h))
5751 struct ppc_dyn_relocs **pp;
5753 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
5755 p->count -= p->pc_count;
5764 /* Also discard relocs on undefined weak syms with non-default
5766 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5767 && h->root.type == bfd_link_hash_undefweak)
5768 eh->dyn_relocs = NULL;
5770 else if (ELIMINATE_COPY_RELOCS)
5772 /* For the non-shared case, discard space for relocs against
5773 symbols which turn out to need copy relocs or are not
5776 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5777 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5778 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
5780 /* Make sure this symbol is output as a dynamic symbol.
5781 Undefined weak syms won't yet be marked as dynamic. */
5782 if (h->dynindx == -1
5783 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
5785 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5789 /* If that succeeded, we know we'll be keeping all the
5791 if (h->dynindx != -1)
5795 eh->dyn_relocs = NULL;
5800 /* Finally, allocate space. */
5801 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5803 asection *sreloc = elf_section_data (p->sec)->sreloc;
5804 sreloc->size += p->count * sizeof (Elf64_External_Rela);
5810 /* Find any dynamic relocs that apply to read-only sections. */
5813 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
5815 struct ppc_link_hash_entry *eh;
5816 struct ppc_dyn_relocs *p;
5818 if (h->root.type == bfd_link_hash_warning)
5819 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5821 eh = (struct ppc_link_hash_entry *) h;
5822 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5824 asection *s = p->sec->output_section;
5826 if (s != NULL && (s->flags & SEC_READONLY) != 0)
5828 struct bfd_link_info *info = inf;
5830 info->flags |= DF_TEXTREL;
5832 /* Not an error, just cut short the traversal. */
5839 /* Set the sizes of the dynamic sections. */
5842 ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5843 struct bfd_link_info *info)
5845 struct ppc_link_hash_table *htab;
5851 htab = ppc_hash_table (info);
5852 dynobj = htab->elf.dynobj;
5856 if (htab->elf.dynamic_sections_created)
5858 /* Set the contents of the .interp section to the interpreter. */
5859 if (info->executable)
5861 s = bfd_get_section_by_name (dynobj, ".interp");
5864 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5865 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5869 /* Set up .got offsets for local syms, and space for local dynamic
5871 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5873 struct got_entry **lgot_ents;
5874 struct got_entry **end_lgot_ents;
5876 bfd_size_type locsymcount;
5877 Elf_Internal_Shdr *symtab_hdr;
5880 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
5883 if (ppc64_tlsld_got (ibfd)->refcount > 0)
5885 s = ppc64_elf_tdata (ibfd)->got;
5886 ppc64_tlsld_got (ibfd)->offset = s->size;
5890 srel = ppc64_elf_tdata (ibfd)->relgot;
5891 srel->size += sizeof (Elf64_External_Rela);
5895 ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1;
5897 for (s = ibfd->sections; s != NULL; s = s->next)
5899 struct ppc_dyn_relocs *p;
5901 for (p = *((struct ppc_dyn_relocs **)
5902 &elf_section_data (s)->local_dynrel);
5906 if (!bfd_is_abs_section (p->sec)
5907 && bfd_is_abs_section (p->sec->output_section))
5909 /* Input section has been discarded, either because
5910 it is a copy of a linkonce section or due to
5911 linker script /DISCARD/, so we'll be discarding
5914 else if (p->count != 0)
5916 srel = elf_section_data (p->sec)->sreloc;
5917 srel->size += p->count * sizeof (Elf64_External_Rela);
5918 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
5919 info->flags |= DF_TEXTREL;
5924 lgot_ents = elf_local_got_ents (ibfd);
5928 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
5929 locsymcount = symtab_hdr->sh_info;
5930 end_lgot_ents = lgot_ents + locsymcount;
5931 lgot_masks = (char *) end_lgot_ents;
5932 s = ppc64_elf_tdata (ibfd)->got;
5933 srel = ppc64_elf_tdata (ibfd)->relgot;
5934 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
5936 struct got_entry *ent;
5938 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
5939 if (ent->got.refcount > 0)
5941 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
5943 if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1)
5945 ppc64_tlsld_got (ibfd)->offset = s->size;
5948 srel->size += sizeof (Elf64_External_Rela);
5950 ent->got.offset = ppc64_tlsld_got (ibfd)->offset;
5954 ent->got.offset = s->size;
5955 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
5959 srel->size += 2 * sizeof (Elf64_External_Rela);
5965 srel->size += sizeof (Elf64_External_Rela);
5970 ent->got.offset = (bfd_vma) -1;
5974 /* Allocate global sym .plt and .got entries, and space for global
5975 sym dynamic relocs. */
5976 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
5978 /* We now have determined the sizes of the various dynamic sections.
5979 Allocate memory for them. */
5981 for (s = dynobj->sections; s != NULL; s = s->next)
5983 if ((s->flags & SEC_LINKER_CREATED) == 0)
5986 if (s == htab->brlt || s == htab->relbrlt)
5987 /* These haven't been allocated yet; don't strip. */
5989 else if (s == htab->got
5991 || s == htab->glink)
5993 /* Strip this section if we don't need it; see the
5996 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
6000 /* If we don't need this section, strip it from the
6001 output file. This is mostly to handle .rela.bss and
6002 .rela.plt. We must create both sections in
6003 create_dynamic_sections, because they must be created
6004 before the linker maps input sections to output
6005 sections. The linker does that before
6006 adjust_dynamic_symbol is called, and it is that
6007 function which decides whether anything needs to go
6008 into these sections. */
6012 if (s != htab->relplt)
6015 /* We use the reloc_count field as a counter if we need
6016 to copy relocs into the output file. */
6022 /* It's not one of our sections, so don't allocate space. */
6028 _bfd_strip_section_from_output (info, s);
6032 /* .plt is in the bss section. We don't initialise it. */
6036 /* Allocate memory for the section contents. We use bfd_zalloc
6037 here in case unused entries are not reclaimed before the
6038 section's contents are written out. This should not happen,
6039 but this way if it does we get a R_PPC64_NONE reloc in .rela
6040 sections instead of garbage.
6041 We also rely on the section contents being zero when writing
6043 s->contents = bfd_zalloc (dynobj, s->size);
6044 if (s->contents == NULL)
6048 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6050 s = ppc64_elf_tdata (ibfd)->got;
6051 if (s != NULL && s != htab->got)
6054 _bfd_strip_section_from_output (info, s);
6057 s->contents = bfd_zalloc (ibfd, s->size);
6058 if (s->contents == NULL)
6062 s = ppc64_elf_tdata (ibfd)->relgot;
6066 _bfd_strip_section_from_output (info, s);
6069 s->contents = bfd_zalloc (ibfd, s->size);
6070 if (s->contents == NULL)
6078 if (htab->elf.dynamic_sections_created)
6080 /* Add some entries to the .dynamic section. We fill in the
6081 values later, in ppc64_elf_finish_dynamic_sections, but we
6082 must add the entries now so that we get the correct size for
6083 the .dynamic section. The DT_DEBUG entry is filled in by the
6084 dynamic linker and used by the debugger. */
6085 #define add_dynamic_entry(TAG, VAL) \
6086 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6088 if (info->executable)
6090 if (!add_dynamic_entry (DT_DEBUG, 0))
6094 if (htab->plt != NULL && htab->plt->size != 0)
6096 if (!add_dynamic_entry (DT_PLTGOT, 0)
6097 || !add_dynamic_entry (DT_PLTRELSZ, 0)
6098 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
6099 || !add_dynamic_entry (DT_JMPREL, 0)
6100 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
6106 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
6107 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
6113 if (!add_dynamic_entry (DT_RELA, 0)
6114 || !add_dynamic_entry (DT_RELASZ, 0)
6115 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
6118 /* If any dynamic relocs apply to a read-only section,
6119 then we need a DT_TEXTREL entry. */
6120 if ((info->flags & DF_TEXTREL) == 0)
6121 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
6123 if ((info->flags & DF_TEXTREL) != 0)
6125 if (!add_dynamic_entry (DT_TEXTREL, 0))
6130 #undef add_dynamic_entry
6135 /* Determine the type of stub needed, if any, for a call. */
6137 static inline enum ppc_stub_type
6138 ppc_type_of_stub (asection *input_sec,
6139 const Elf_Internal_Rela *rel,
6140 struct ppc_link_hash_entry **hash,
6141 bfd_vma destination)
6143 struct ppc_link_hash_entry *h = *hash;
6145 bfd_vma branch_offset;
6146 bfd_vma max_branch_offset;
6147 enum elf_ppc64_reloc_type r_type;
6152 && h->oh->elf.dynindx != -1)
6154 struct plt_entry *ent;
6155 for (ent = h->oh->elf.plt.plist; ent != NULL; ent = ent->next)
6156 if (ent->addend == rel->r_addend
6157 && ent->plt.offset != (bfd_vma) -1)
6160 return ppc_stub_plt_call;
6164 if (!(h->elf.root.type == bfd_link_hash_defined
6165 || h->elf.root.type == bfd_link_hash_defweak)
6166 || h->elf.root.u.def.section->output_section == NULL)
6167 return ppc_stub_none;
6170 /* Determine where the call point is. */
6171 location = (input_sec->output_offset
6172 + input_sec->output_section->vma
6175 branch_offset = destination - location;
6176 r_type = ELF64_R_TYPE (rel->r_info);
6178 /* Determine if a long branch stub is needed. */
6179 max_branch_offset = 1 << 25;
6180 if (r_type != R_PPC64_REL24)
6181 max_branch_offset = 1 << 15;
6183 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
6184 /* We need a stub. Figure out whether a long_branch or plt_branch
6186 return ppc_stub_long_branch;
6188 return ppc_stub_none;
6191 /* Build a .plt call stub. */
6193 static inline bfd_byte *
6194 build_plt_stub (bfd *obfd, bfd_byte *p, int offset)
6196 #define PPC_LO(v) ((v) & 0xffff)
6197 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6198 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6200 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
6201 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
6202 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
6203 if (PPC_HA (offset + 8) != PPC_HA (offset))
6204 bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4;
6206 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
6207 if (PPC_HA (offset + 8) != PPC_HA (offset))
6208 bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4;
6210 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
6211 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
6212 bfd_put_32 (obfd, BCTR, p), p += 4;
6217 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
6219 struct ppc_stub_hash_entry *stub_entry;
6220 struct ppc_branch_hash_entry *br_entry;
6221 struct bfd_link_info *info;
6222 struct ppc_link_hash_table *htab;
6226 struct plt_entry *ent;
6230 /* Massage our args to the form they really have. */
6231 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
6234 htab = ppc_hash_table (info);
6236 /* Make a note of the offset within the stubs for this entry. */
6237 stub_entry->stub_offset = stub_entry->stub_sec->size;
6238 loc = stub_entry->stub_sec->contents + stub_entry->stub_offset;
6240 htab->stub_count[stub_entry->stub_type - 1] += 1;
6241 switch (stub_entry->stub_type)
6243 case ppc_stub_long_branch:
6244 case ppc_stub_long_branch_r2off:
6245 /* Branches are relative. This is where we are going to. */
6246 off = (stub_entry->target_value
6247 + stub_entry->target_section->output_offset
6248 + stub_entry->target_section->output_section->vma);
6250 /* And this is where we are coming from. */
6251 off -= (stub_entry->stub_offset
6252 + stub_entry->stub_sec->output_offset
6253 + stub_entry->stub_sec->output_section->vma);
6255 if (stub_entry->stub_type != ppc_stub_long_branch_r2off)
6261 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off
6262 - htab->stub_group[stub_entry->id_sec->id].toc_off);
6263 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc);
6265 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
6267 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
6272 bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
6274 BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
6277 case ppc_stub_plt_branch:
6278 case ppc_stub_plt_branch_r2off:
6279 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
6280 stub_entry->root.string + 9,
6282 if (br_entry == NULL)
6284 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
6285 stub_entry->root.string + 9);
6286 htab->stub_error = TRUE;
6290 off = (stub_entry->target_value
6291 + stub_entry->target_section->output_offset
6292 + stub_entry->target_section->output_section->vma);
6294 bfd_put_64 (htab->brlt->owner, off,
6295 htab->brlt->contents + br_entry->offset);
6299 /* Create a reloc for the branch lookup table entry. */
6300 Elf_Internal_Rela rela;
6303 rela.r_offset = (br_entry->offset
6304 + htab->brlt->output_offset
6305 + htab->brlt->output_section->vma);
6306 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
6307 rela.r_addend = off;
6309 rl = htab->relbrlt->contents;
6310 rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela);
6311 bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
6314 off = (br_entry->offset
6315 + htab->brlt->output_offset
6316 + htab->brlt->output_section->vma
6317 - elf_gp (htab->brlt->output_section->owner)
6318 - htab->stub_group[stub_entry->id_sec->id].toc_off);
6320 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
6322 (*_bfd_error_handler)
6323 (_("linkage table error against `%s'"),
6324 stub_entry->root.string);
6325 bfd_set_error (bfd_error_bad_value);
6326 htab->stub_error = TRUE;
6331 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
6333 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc);
6335 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc);
6342 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off
6343 - htab->stub_group[stub_entry->id_sec->id].toc_off);
6344 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc);
6346 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc);
6348 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc);
6350 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
6352 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
6356 bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc);
6358 bfd_put_32 (htab->stub_bfd, BCTR, loc);
6361 case ppc_stub_plt_call:
6362 /* Do the best we can for shared libraries built without
6363 exporting ".foo" for each "foo". This can happen when symbol
6364 versioning scripts strip all bar a subset of symbols. */
6365 if (stub_entry->h->oh->elf.root.type != bfd_link_hash_defined
6366 && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak)
6368 /* Point the symbol at the stub. There may be multiple stubs,
6369 we don't really care; The main thing is to make this sym
6370 defined somewhere. Maybe defining the symbol in the stub
6371 section is a silly idea. If we didn't do this, htab->top_id
6373 stub_entry->h->oh->elf.root.type = bfd_link_hash_defined;
6374 stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec;
6375 stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset;
6378 /* Now build the stub. */
6380 for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
6381 if (ent->addend == stub_entry->addend)
6383 off = ent->plt.offset;
6386 if (off >= (bfd_vma) -2)
6389 off &= ~ (bfd_vma) 1;
6390 off += (htab->plt->output_offset
6391 + htab->plt->output_section->vma
6392 - elf_gp (htab->plt->output_section->owner)
6393 - htab->stub_group[stub_entry->id_sec->id].toc_off);
6395 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
6397 (*_bfd_error_handler)
6398 (_("linkage table error against `%s'"),
6399 stub_entry->h->elf.root.root.string);
6400 bfd_set_error (bfd_error_bad_value);
6401 htab->stub_error = TRUE;
6405 p = build_plt_stub (htab->stub_bfd, loc, off);
6414 stub_entry->stub_sec->size += size;
6416 if (htab->emit_stub_syms
6417 && !(stub_entry->stub_type == ppc_stub_plt_call
6418 && stub_entry->h->oh->elf.root.type == bfd_link_hash_defined
6419 && stub_entry->h->oh->elf.root.u.def.section == stub_entry->stub_sec
6420 && stub_entry->h->oh->elf.root.u.def.value == stub_entry->stub_offset))
6422 struct elf_link_hash_entry *h;
6423 h = elf_link_hash_lookup (&htab->elf, stub_entry->root.string,
6424 TRUE, FALSE, FALSE);
6427 if (h->root.type == bfd_link_hash_new)
6429 h->root.type = bfd_link_hash_defined;
6430 h->root.u.def.section = stub_entry->stub_sec;
6431 h->root.u.def.value = stub_entry->stub_offset;
6432 h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR
6433 | ELF_LINK_HASH_DEF_REGULAR
6434 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
6435 | ELF_LINK_FORCED_LOCAL);
6442 /* As above, but don't actually build the stub. Just bump offset so
6443 we know stub section sizes, and select plt_branch stubs where
6444 long_branch stubs won't do. */
6447 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
6449 struct ppc_stub_hash_entry *stub_entry;
6450 struct bfd_link_info *info;
6451 struct ppc_link_hash_table *htab;
6455 /* Massage our args to the form they really have. */
6456 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
6459 htab = ppc_hash_table (info);
6461 if (stub_entry->stub_type == ppc_stub_plt_call)
6463 struct plt_entry *ent;
6465 for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
6466 if (ent->addend == stub_entry->addend)
6468 off = ent->plt.offset & ~(bfd_vma) 1;
6471 if (off >= (bfd_vma) -2)
6473 off += (htab->plt->output_offset
6474 + htab->plt->output_section->vma
6475 - elf_gp (htab->plt->output_section->owner)
6476 - htab->stub_group[stub_entry->id_sec->id].toc_off);
6478 size = PLT_CALL_STUB_SIZE;
6479 if (PPC_HA (off + 16) != PPC_HA (off))
6484 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
6486 off = (stub_entry->target_value
6487 + stub_entry->target_section->output_offset
6488 + stub_entry->target_section->output_section->vma);
6489 off -= (stub_entry->stub_sec->size
6490 + stub_entry->stub_sec->output_offset
6491 + stub_entry->stub_sec->output_section->vma);
6493 /* Reset the stub type from the plt variant in case we now
6494 can reach with a shorter stub. */
6495 if (stub_entry->stub_type >= ppc_stub_plt_branch)
6496 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
6499 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
6505 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
6506 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
6508 struct ppc_branch_hash_entry *br_entry;
6510 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
6511 stub_entry->root.string + 9,
6513 if (br_entry == NULL)
6515 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
6516 stub_entry->root.string + 9);
6517 htab->stub_error = TRUE;
6521 if (br_entry->iter != htab->stub_iteration)
6523 br_entry->iter = htab->stub_iteration;
6524 br_entry->offset = htab->brlt->size;
6525 htab->brlt->size += 8;
6528 htab->relbrlt->size += sizeof (Elf64_External_Rela);
6531 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
6533 if (stub_entry->stub_type != ppc_stub_plt_branch)
6538 stub_entry->stub_sec->size += size;
6542 /* Set up various things so that we can make a list of input sections
6543 for each output section included in the link. Returns -1 on error,
6544 0 when no stubs will be needed, and 1 on success. */
6547 ppc64_elf_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info)
6550 int top_id, top_index, id;
6552 asection **input_list;
6554 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6556 if (htab->brlt == NULL)
6559 /* Find the top input section id. */
6560 for (input_bfd = info->input_bfds, top_id = 3;
6562 input_bfd = input_bfd->link_next)
6564 for (section = input_bfd->sections;
6566 section = section->next)
6568 if (top_id < section->id)
6569 top_id = section->id;
6573 htab->top_id = top_id;
6574 amt = sizeof (struct map_stub) * (top_id + 1);
6575 htab->stub_group = bfd_zmalloc (amt);
6576 if (htab->stub_group == NULL)
6579 /* Set toc_off for com, und, abs and ind sections. */
6580 for (id = 0; id < 3; id++)
6581 htab->stub_group[id].toc_off = TOC_BASE_OFF;
6583 elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd);
6585 /* We can't use output_bfd->section_count here to find the top output
6586 section index as some sections may have been removed, and
6587 _bfd_strip_section_from_output doesn't renumber the indices. */
6588 for (section = output_bfd->sections, top_index = 0;
6590 section = section->next)
6592 if (top_index < section->index)
6593 top_index = section->index;
6596 htab->top_index = top_index;
6597 amt = sizeof (asection *) * (top_index + 1);
6598 input_list = bfd_zmalloc (amt);
6599 htab->input_list = input_list;
6600 if (input_list == NULL)
6606 /* The linker repeatedly calls this function for each TOC input section
6607 and linker generated GOT section. Group input bfds such that the toc
6608 within a group is less than 64k in size. Will break with cute linker
6609 scripts that play games with dot in the output toc section. */
6612 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
6614 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6616 if (!htab->no_multi_toc)
6618 bfd_vma addr = isec->output_offset + isec->output_section->vma;
6619 bfd_vma off = addr - htab->toc_curr;
6620 if (off + isec->size > 0x10000)
6622 htab->toc_curr = addr;
6623 htab->multi_toc_needed = 1;
6625 elf_gp (isec->owner) = (htab->toc_curr
6626 - elf_gp (isec->output_section->owner)
6631 /* Called after the last call to the above function. */
6634 ppc64_elf_reinit_toc (bfd *output_bfd ATTRIBUTE_UNUSED,
6635 struct bfd_link_info *info)
6637 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6639 /* toc_curr tracks the TOC offset used for code sections below in
6640 ppc64_elf_next_input_section. Start off at 0x8000. */
6641 htab->toc_curr = TOC_BASE_OFF;
6644 /* No toc references were found in ISEC. If the code in ISEC makes no
6645 calls, then there's no need to use toc adjusting stubs when branching
6646 into ISEC. Actually, indirect calls from ISEC are OK as they will
6650 toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
6657 /* We know none of our code bearing sections will need toc stubs. */
6658 if ((isec->flags & SEC_LINKER_CREATED) != 0)
6661 if (isec->size == 0)
6664 /* Hack for linux kernel. .fixup contains branches, but only back to
6665 the function that hit an exception. */
6666 branch_ok = strcmp (isec->name, ".fixup") == 0;
6668 contents = elf_section_data (isec)->this_hdr.contents;
6669 if (contents == NULL)
6671 if (!bfd_malloc_and_get_section (isec->owner, isec, &contents))
6673 if (contents != NULL)
6677 if (info->keep_memory)
6678 elf_section_data (isec)->this_hdr.contents = contents;
6681 /* Code scan, because we don't necessarily have relocs on calls to
6682 static functions. */
6684 for (i = 0; i < isec->size; i += 4)
6686 unsigned long insn = bfd_get_32 (isec->owner, contents + i);
6687 /* Is this a branch? */
6688 if ((insn & (0x3f << 26)) == (18 << 26)
6689 /* If branch and link, it's a function call. */
6691 /* Sibling calls use a plain branch. I don't know a way
6692 of deciding whether a branch is really a sibling call. */
6700 if (elf_section_data (isec)->this_hdr.contents != contents)
6705 /* The linker repeatedly calls this function for each input section,
6706 in the order that input sections are linked into output sections.
6707 Build lists of input sections to determine groupings between which
6708 we may insert linker stubs. */
6711 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
6713 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6716 if ((isec->output_section->flags & SEC_CODE) != 0
6717 && isec->output_section->index <= htab->top_index)
6719 asection **list = htab->input_list + isec->output_section->index;
6720 /* Steal the link_sec pointer for our list. */
6721 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
6722 /* This happens to make the list in reverse order,
6723 which is what we want. */
6724 PREV_SEC (isec) = *list;
6728 /* If a code section has a function that uses the TOC then we need
6729 to use the right TOC (obviously). Also, make sure that .opd gets
6730 the correct TOC value for R_PPC64_TOC relocs that don't have or
6731 can't find their function symbol (shouldn't ever happen now). */
6732 if (isec->has_gp_reloc || (isec->flags & SEC_CODE) == 0)
6734 if (elf_gp (isec->owner) != 0)
6735 htab->toc_curr = elf_gp (isec->owner);
6737 else if ((ret = toc_adjusting_stub_needed (info, isec)) < 0)
6740 isec->has_gp_reloc = ret;
6742 /* Functions that don't use the TOC can belong in any TOC group.
6743 Use the last TOC base. This happens to make _init and _fini
6745 htab->stub_group[isec->id].toc_off = htab->toc_curr;
6749 /* See whether we can group stub sections together. Grouping stub
6750 sections may result in fewer stubs. More importantly, we need to
6751 put all .init* and .fini* stubs at the beginning of the .init or
6752 .fini output sections respectively, because glibc splits the
6753 _init and _fini functions into multiple parts. Putting a stub in
6754 the middle of a function is not a good idea. */
6757 group_sections (struct ppc_link_hash_table *htab,
6758 bfd_size_type stub_group_size,
6759 bfd_boolean stubs_always_before_branch)
6761 asection **list = htab->input_list + htab->top_index;
6764 asection *tail = *list;
6765 while (tail != NULL)
6769 bfd_size_type total;
6770 bfd_boolean big_sec;
6775 big_sec = total >= stub_group_size;
6776 curr_toc = htab->stub_group[tail->id].toc_off;
6778 while ((prev = PREV_SEC (curr)) != NULL
6779 && ((total += curr->output_offset - prev->output_offset)
6781 && htab->stub_group[prev->id].toc_off == curr_toc)
6784 /* OK, the size from the start of CURR to the end is less
6785 than stub_group_size and thus can be handled by one stub
6786 section. (or the tail section is itself larger than
6787 stub_group_size, in which case we may be toast.) We
6788 should really be keeping track of the total size of stubs
6789 added here, as stubs contribute to the final output
6790 section size. That's a little tricky, and this way will
6791 only break if stubs added make the total size more than
6792 2^25, ie. for the default stub_group_size, if stubs total
6793 more than 2097152 bytes, or nearly 75000 plt call stubs. */
6796 prev = PREV_SEC (tail);
6797 /* Set up this stub group. */
6798 htab->stub_group[tail->id].link_sec = curr;
6800 while (tail != curr && (tail = prev) != NULL);
6802 /* But wait, there's more! Input sections up to stub_group_size
6803 bytes before the stub section can be handled by it too.
6804 Don't do this if we have a really large section after the
6805 stubs, as adding more stubs increases the chance that
6806 branches may not reach into the stub section. */
6807 if (!stubs_always_before_branch && !big_sec)
6811 && ((total += tail->output_offset - prev->output_offset)
6813 && htab->stub_group[prev->id].toc_off == curr_toc)
6816 prev = PREV_SEC (tail);
6817 htab->stub_group[tail->id].link_sec = curr;
6823 while (list-- != htab->input_list);
6824 free (htab->input_list);
6828 /* Determine and set the size of the stub section for a final link.
6830 The basic idea here is to examine all the relocations looking for
6831 PC-relative calls to a target that is unreachable with a "bl"
6835 ppc64_elf_size_stubs (bfd *output_bfd,
6836 struct bfd_link_info *info,
6837 bfd_signed_vma group_size,
6838 asection *(*add_stub_section) (const char *, asection *),
6839 void (*layout_sections_again) (void))
6841 bfd_size_type stub_group_size;
6842 bfd_boolean stubs_always_before_branch;
6843 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6845 /* Stash our params away. */
6846 htab->add_stub_section = add_stub_section;
6847 htab->layout_sections_again = layout_sections_again;
6848 stubs_always_before_branch = group_size < 0;
6850 stub_group_size = -group_size;
6852 stub_group_size = group_size;
6853 if (stub_group_size == 1)
6855 /* Default values. */
6856 if (stubs_always_before_branch)
6858 stub_group_size = 0x1e00000;
6859 if (htab->has_14bit_branch)
6860 stub_group_size = 0x7800;
6864 stub_group_size = 0x1c00000;
6865 if (htab->has_14bit_branch)
6866 stub_group_size = 0x7000;
6870 group_sections (htab, stub_group_size, stubs_always_before_branch);
6875 unsigned int bfd_indx;
6877 bfd_boolean stub_changed;
6879 htab->stub_iteration += 1;
6880 stub_changed = FALSE;
6882 for (input_bfd = info->input_bfds, bfd_indx = 0;
6884 input_bfd = input_bfd->link_next, bfd_indx++)
6886 Elf_Internal_Shdr *symtab_hdr;
6888 Elf_Internal_Sym *local_syms = NULL;
6890 /* We'll need the symbol table in a second. */
6891 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
6892 if (symtab_hdr->sh_info == 0)
6895 /* Walk over each section attached to the input bfd. */
6896 for (section = input_bfd->sections;
6898 section = section->next)
6900 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
6902 /* If there aren't any relocs, then there's nothing more
6904 if ((section->flags & SEC_RELOC) == 0
6905 || section->reloc_count == 0)
6908 /* If this section is a link-once section that will be
6909 discarded, then don't create any stubs. */
6910 if (section->output_section == NULL
6911 || section->output_section->owner != output_bfd)
6914 /* Get the relocs. */
6916 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
6918 if (internal_relocs == NULL)
6919 goto error_ret_free_local;
6921 /* Now examine each relocation. */
6922 irela = internal_relocs;
6923 irelaend = irela + section->reloc_count;
6924 for (; irela < irelaend; irela++)
6926 enum elf_ppc64_reloc_type r_type;
6927 unsigned int r_indx;
6928 enum ppc_stub_type stub_type;
6929 struct ppc_stub_hash_entry *stub_entry;
6932 bfd_vma destination;
6933 struct ppc_link_hash_entry *hash;
6934 struct elf_link_hash_entry *h;
6935 Elf_Internal_Sym *sym;
6937 const asection *id_sec;
6939 r_type = ELF64_R_TYPE (irela->r_info);
6940 r_indx = ELF64_R_SYM (irela->r_info);
6942 if (r_type >= R_PPC64_max)
6944 bfd_set_error (bfd_error_bad_value);
6945 goto error_ret_free_internal;
6948 /* Only look for stubs on branch instructions. */
6949 if (r_type != R_PPC64_REL24
6950 && r_type != R_PPC64_REL14
6951 && r_type != R_PPC64_REL14_BRTAKEN
6952 && r_type != R_PPC64_REL14_BRNTAKEN)
6955 /* Now determine the call target, its name, value,
6958 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
6960 goto error_ret_free_internal;
6961 hash = (struct ppc_link_hash_entry *) h;
6965 /* It's a local symbol. */
6966 sym_value = sym->st_value;
6967 destination = (sym_value + irela->r_addend
6968 + sym_sec->output_offset
6969 + sym_sec->output_section->vma);
6973 /* It's an external symbol. */
6975 if (hash->elf.root.type == bfd_link_hash_defined
6976 || hash->elf.root.type == bfd_link_hash_defweak)
6978 sym_value = hash->elf.root.u.def.value;
6979 if (sym_sec->output_section != NULL)
6980 destination = (sym_value + irela->r_addend
6981 + sym_sec->output_offset
6982 + sym_sec->output_section->vma);
6984 else if (hash->elf.root.type == bfd_link_hash_undefweak)
6986 else if (hash->elf.root.type == bfd_link_hash_undefined)
6990 bfd_set_error (bfd_error_bad_value);
6991 goto error_ret_free_internal;
6995 /* Determine what (if any) linker stub is needed. */
6996 stub_type = ppc_type_of_stub (section, irela, &hash,
6999 if (stub_type != ppc_stub_plt_call)
7001 /* Check whether we need a TOC adjusting stub.
7002 Since the linker pastes together pieces from
7003 different object files when creating the
7004 _init and _fini functions, it may be that a
7005 call to what looks like a local sym is in
7006 fact a call needing a TOC adjustment. */
7008 && sym_sec->output_section != NULL
7009 && (htab->stub_group[sym_sec->id].toc_off
7010 != htab->stub_group[section->id].toc_off)
7011 && sym_sec->has_gp_reloc
7012 && section->has_gp_reloc)
7013 stub_type = ppc_stub_long_branch_r2off;
7016 if (stub_type == ppc_stub_none)
7019 /* __tls_get_addr calls might be eliminated. */
7020 if (stub_type != ppc_stub_plt_call
7022 && &hash->elf == htab->tls_get_addr
7023 && section->has_tls_reloc
7024 && irela != internal_relocs)
7029 if (!get_tls_mask (&tls_mask, NULL, &local_syms,
7030 irela - 1, input_bfd))
7031 goto error_ret_free_internal;
7036 /* Support for grouping stub sections. */
7037 id_sec = htab->stub_group[section->id].link_sec;
7039 /* Get the name of this stub. */
7040 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
7042 goto error_ret_free_internal;
7044 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
7045 stub_name, FALSE, FALSE);
7046 if (stub_entry != NULL)
7048 /* The proper stub has already been created. */
7053 stub_entry = ppc_add_stub (stub_name, section, htab);
7054 if (stub_entry == NULL)
7057 error_ret_free_internal:
7058 if (elf_section_data (section)->relocs == NULL)
7059 free (internal_relocs);
7060 error_ret_free_local:
7061 if (local_syms != NULL
7062 && (symtab_hdr->contents
7063 != (unsigned char *) local_syms))
7068 stub_entry->stub_type = stub_type;
7069 stub_entry->target_value = sym_value;
7070 stub_entry->target_section = sym_sec;
7071 stub_entry->h = hash;
7072 stub_entry->addend = irela->r_addend;
7073 stub_changed = TRUE;
7076 /* We're done with the internal relocs, free them. */
7077 if (elf_section_data (section)->relocs != internal_relocs)
7078 free (internal_relocs);
7081 if (local_syms != NULL
7082 && symtab_hdr->contents != (unsigned char *) local_syms)
7084 if (!info->keep_memory)
7087 symtab_hdr->contents = (unsigned char *) local_syms;
7094 /* OK, we've added some stubs. Find out the new size of the
7096 for (stub_sec = htab->stub_bfd->sections;
7098 stub_sec = stub_sec->next)
7099 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
7102 htab->brlt->size = 0;
7104 htab->relbrlt->size = 0;
7106 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
7108 /* Ask the linker to do its stuff. */
7109 (*htab->layout_sections_again) ();
7112 /* It would be nice to strip .branch_lt from the output if the
7113 section is empty, but it's too late. If we strip sections here,
7114 the dynamic symbol table is corrupted since the section symbol
7115 for the stripped section isn't written. */
7120 /* Called after we have determined section placement. If sections
7121 move, we'll be called again. Provide a value for TOCstart. */
7124 ppc64_elf_toc (bfd *obfd)
7129 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
7130 order. The TOC starts where the first of these sections starts. */
7131 s = bfd_get_section_by_name (obfd, ".got");
7133 s = bfd_get_section_by_name (obfd, ".toc");
7135 s = bfd_get_section_by_name (obfd, ".tocbss");
7137 s = bfd_get_section_by_name (obfd, ".plt");
7140 /* This may happen for
7141 o references to TOC base (SYM@toc / TOC[tc0]) without a
7144 o --gc-sections and empty TOC sections
7146 FIXME: Warn user? */
7148 /* Look for a likely section. We probably won't even be
7150 for (s = obfd->sections; s != NULL; s = s->next)
7151 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
7152 == (SEC_ALLOC | SEC_SMALL_DATA))
7155 for (s = obfd->sections; s != NULL; s = s->next)
7156 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
7157 == (SEC_ALLOC | SEC_SMALL_DATA))
7160 for (s = obfd->sections; s != NULL; s = s->next)
7161 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
7164 for (s = obfd->sections; s != NULL; s = s->next)
7165 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
7171 TOCstart = s->output_section->vma + s->output_offset;
7176 /* Build all the stubs associated with the current output file.
7177 The stubs are kept in a hash table attached to the main linker
7178 hash table. This function is called via gldelf64ppc_finish. */
7181 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms,
7182 struct bfd_link_info *info,
7185 struct ppc_link_hash_table *htab = ppc_hash_table (info);
7188 int stub_sec_count = 0;
7190 htab->emit_stub_syms = emit_stub_syms;
7192 /* Allocate memory to hold the linker stubs. */
7193 for (stub_sec = htab->stub_bfd->sections;
7195 stub_sec = stub_sec->next)
7196 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
7197 && stub_sec->size != 0)
7199 stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
7200 if (stub_sec->contents == NULL)
7202 /* We want to check that built size is the same as calculated
7203 size. rawsize is a convenient location to use. */
7204 stub_sec->rawsize = stub_sec->size;
7208 if (htab->plt != NULL)
7213 /* Build the .glink plt call stub. */
7214 plt0 = (htab->plt->output_section->vma
7215 + htab->plt->output_offset
7216 - (htab->glink->output_section->vma
7217 + htab->glink->output_offset
7218 + GLINK_CALL_STUB_SIZE));
7219 if (plt0 + 0x80008000 > 0xffffffff)
7221 (*_bfd_error_handler) (_(".glink and .plt too far apart"));
7222 bfd_set_error (bfd_error_bad_value);
7226 if (htab->emit_stub_syms)
7228 struct elf_link_hash_entry *h;
7229 h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE);
7232 if (h->root.type == bfd_link_hash_new)
7234 h->root.type = bfd_link_hash_defined;
7235 h->root.u.def.section = htab->glink;
7236 h->root.u.def.value = 0;
7237 h->elf_link_hash_flags = (ELF_LINK_HASH_REF_REGULAR
7238 | ELF_LINK_HASH_DEF_REGULAR
7239 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
7240 | ELF_LINK_FORCED_LOCAL);
7243 p = htab->glink->contents;
7244 bfd_put_32 (htab->glink->owner, MFCTR_R12, p);
7246 bfd_put_32 (htab->glink->owner, SLDI_R11_R0_3, p);
7248 bfd_put_32 (htab->glink->owner, ADDIC_R2_R0_32K, p);
7250 bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
7252 bfd_put_32 (htab->glink->owner, SRADI_R2_R2_63, p);
7254 bfd_put_32 (htab->glink->owner, SLDI_R11_R0_2, p);
7256 bfd_put_32 (htab->glink->owner, AND_R2_R2_R11, p);
7258 bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
7260 bfd_put_32 (htab->glink->owner, ADD_R12_R12_R2, p);
7262 bfd_put_32 (htab->glink->owner, ADDIS_R12_R12 | PPC_HA (plt0), p);
7264 bfd_put_32 (htab->glink->owner, LD_R11_0R12 | PPC_LO (plt0), p);
7266 bfd_put_32 (htab->glink->owner, ADDI_R12_R12 | PPC_LO (plt0), p);
7268 bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p);
7270 bfd_put_32 (htab->glink->owner, MTCTR_R11, p);
7272 bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p);
7274 bfd_put_32 (htab->glink->owner, BCTR, p);
7277 /* Build the .glink lazy link call stubs. */
7279 while (p < htab->glink->contents + htab->glink->size)
7283 bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
7288 bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
7290 bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
7293 bfd_put_32 (htab->glink->owner,
7294 B_DOT | ((htab->glink->contents - p) & 0x3fffffc), p);
7298 htab->glink->rawsize = p - htab->glink->contents;
7301 if (htab->brlt->size != 0)
7303 htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
7305 if (htab->brlt->contents == NULL)
7308 if (info->shared && htab->relbrlt->size != 0)
7310 htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
7311 htab->relbrlt->size);
7312 if (htab->relbrlt->contents == NULL)
7316 /* Build the stubs as directed by the stub hash table. */
7317 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
7319 for (stub_sec = htab->stub_bfd->sections;
7321 stub_sec = stub_sec->next)
7322 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
7324 stub_sec_count += 1;
7325 if (stub_sec->rawsize != stub_sec->size)
7329 if (stub_sec != NULL
7330 || htab->glink->rawsize != htab->glink->size)
7332 htab->stub_error = TRUE;
7333 (*_bfd_error_handler) (_("stubs don't match calculated size"));
7336 if (htab->stub_error)
7341 *stats = bfd_malloc (500);
7345 sprintf (*stats, _("linker stubs in %u groups\n"
7348 " long branch %lu\n"
7349 " long toc adj %lu\n"
7352 htab->stub_count[ppc_stub_long_branch - 1],
7353 htab->stub_count[ppc_stub_long_branch_r2off - 1],
7354 htab->stub_count[ppc_stub_plt_branch - 1],
7355 htab->stub_count[ppc_stub_plt_branch_r2off - 1],
7356 htab->stub_count[ppc_stub_plt_call - 1]);
7361 /* The RELOCATE_SECTION function is called by the ELF backend linker
7362 to handle the relocations for a section.
7364 The relocs are always passed as Rela structures; if the section
7365 actually uses Rel structures, the r_addend field will always be
7368 This function is responsible for adjust the section contents as
7369 necessary, and (if using Rela relocs and generating a
7370 relocatable output file) adjusting the reloc addend as
7373 This function does not have to worry about setting the reloc
7374 address or the reloc symbol index.
7376 LOCAL_SYMS is a pointer to the swapped in local symbols.
7378 LOCAL_SECTIONS is an array giving the section in the input file
7379 corresponding to the st_shndx field of each local symbol.
7381 The global hash table entry for the global symbols can be found
7382 via elf_sym_hashes (input_bfd).
7384 When generating relocatable output, this function must handle
7385 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
7386 going to be the section symbol corresponding to the output
7387 section, which means that the addend must be adjusted
7391 ppc64_elf_relocate_section (bfd *output_bfd,
7392 struct bfd_link_info *info,
7394 asection *input_section,
7396 Elf_Internal_Rela *relocs,
7397 Elf_Internal_Sym *local_syms,
7398 asection **local_sections)
7400 struct ppc_link_hash_table *htab;
7401 Elf_Internal_Shdr *symtab_hdr;
7402 struct elf_link_hash_entry **sym_hashes;
7403 Elf_Internal_Rela *rel;
7404 Elf_Internal_Rela *relend;
7405 Elf_Internal_Rela outrel;
7407 struct got_entry **local_got_ents;
7409 bfd_boolean ret = TRUE;
7411 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
7412 bfd_boolean is_power4 = FALSE;
7414 if (info->relocatable)
7417 /* Initialize howto table if needed. */
7418 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
7421 htab = ppc_hash_table (info);
7422 local_got_ents = elf_local_got_ents (input_bfd);
7423 TOCstart = elf_gp (output_bfd);
7424 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
7425 sym_hashes = elf_sym_hashes (input_bfd);
7426 is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL;
7429 relend = relocs + input_section->reloc_count;
7430 for (; rel < relend; rel++)
7432 enum elf_ppc64_reloc_type r_type;
7434 bfd_reloc_status_type r;
7435 Elf_Internal_Sym *sym;
7437 struct elf_link_hash_entry *h;
7438 struct elf_link_hash_entry *fdh;
7439 const char *sym_name;
7440 unsigned long r_symndx, toc_symndx;
7441 char tls_mask, tls_gd, tls_type;
7444 bfd_boolean unresolved_reloc;
7446 unsigned long insn, mask;
7447 struct ppc_stub_hash_entry *stub_entry;
7448 bfd_vma max_br_offset;
7451 r_type = ELF64_R_TYPE (rel->r_info);
7452 r_symndx = ELF64_R_SYM (rel->r_info);
7454 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
7455 symbol of the previous ADDR64 reloc. The symbol gives us the
7456 proper TOC base to use. */
7457 if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
7459 && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64
7461 r_symndx = ELF64_R_SYM (rel[-1].r_info);
7467 unresolved_reloc = FALSE;
7470 if (r_symndx < symtab_hdr->sh_info)
7472 /* It's a local symbol. */
7475 sym = local_syms + r_symndx;
7476 sec = local_sections[r_symndx];
7477 sym_name = bfd_elf_local_sym_name (input_bfd, sym);
7478 sym_type = ELF64_ST_TYPE (sym->st_info);
7479 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
7480 opd_adjust = get_opd_info (sec);
7481 if (opd_adjust != NULL)
7483 long adjust = opd_adjust[(sym->st_value + rel->r_addend) / 24];
7487 relocation += adjust;
7492 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
7493 r_symndx, symtab_hdr, sym_hashes,
7495 unresolved_reloc, warned);
7496 sym_name = h->root.root.string;
7500 /* TLS optimizations. Replace instruction sequences and relocs
7501 based on information we collected in tls_optimize. We edit
7502 RELOCS so that --emit-relocs will output something sensible
7503 for the final instruction stream. */
7507 if (IS_PPC64_TLS_RELOC (r_type))
7510 tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask;
7511 else if (local_got_ents != NULL)
7514 lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
7515 tls_mask = lgot_masks[r_symndx];
7517 if (tls_mask == 0 && r_type == R_PPC64_TLS)
7519 /* Check for toc tls entries. */
7522 if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms,
7527 tls_mask = *toc_tls;
7531 /* Check that tls relocs are used with tls syms, and non-tls
7532 relocs are used with non-tls syms. */
7534 && r_type != R_PPC64_NONE
7536 || h->root.type == bfd_link_hash_defined
7537 || h->root.type == bfd_link_hash_defweak)
7538 && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS))
7540 if (r_type == R_PPC64_TLS && tls_mask != 0)
7541 /* R_PPC64_TLS is OK against a symbol in the TOC. */
7544 (*_bfd_error_handler)
7545 (sym_type == STT_TLS
7546 ? _("%s(%s+0x%lx): %s used with TLS symbol %s")
7547 : _("%s(%s+0x%lx): %s used with non-TLS symbol %s"),
7548 bfd_archive_filename (input_bfd),
7549 input_section->name,
7550 (long) rel->r_offset,
7551 ppc64_elf_howto_table[r_type]->name,
7555 /* Ensure reloc mapping code below stays sane. */
7556 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
7557 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
7558 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
7559 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
7560 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
7561 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
7562 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
7563 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
7564 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
7565 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
7574 case R_PPC64_TOC16_LO:
7575 case R_PPC64_TOC16_DS:
7576 case R_PPC64_TOC16_LO_DS:
7578 /* Check for toc tls entries. */
7582 retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms,
7589 tls_mask = *toc_tls;
7590 if (r_type == R_PPC64_TOC16_DS
7591 || r_type == R_PPC64_TOC16_LO_DS)
7594 && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
7599 /* If we found a GD reloc pair, then we might be
7600 doing a GD->IE transition. */
7603 tls_gd = TLS_TPRELGD;
7604 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
7605 goto tls_get_addr_check;
7607 else if (retval == 3)
7609 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
7610 goto tls_get_addr_check;
7617 case R_PPC64_GOT_TPREL16_DS:
7618 case R_PPC64_GOT_TPREL16_LO_DS:
7620 && (tls_mask & TLS_TPREL) == 0)
7623 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
7625 insn |= 0x3c0d0000; /* addis 0,13,0 */
7626 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
7627 r_type = R_PPC64_TPREL16_HA;
7628 if (toc_symndx != 0)
7630 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
7631 /* We changed the symbol. Start over in order to
7632 get h, sym, sec etc. right. */
7637 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7643 && (tls_mask & TLS_TPREL) == 0)
7646 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
7647 if ((insn & ((0x3f << 26) | (31 << 11)))
7648 == ((31 << 26) | (13 << 11)))
7649 rtra = insn & ((1 << 26) - (1 << 16));
7650 else if ((insn & ((0x3f << 26) | (31 << 16)))
7651 == ((31 << 26) | (13 << 16)))
7652 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
7655 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
7658 else if ((insn & (31 << 1)) == 23 << 1
7659 && ((insn & (31 << 6)) < 14 << 6
7660 || ((insn & (31 << 6)) >= 16 << 6
7661 && (insn & (31 << 6)) < 24 << 6)))
7662 /* load and store indexed -> dform. */
7663 insn = (32 | ((insn >> 6) & 31)) << 26;
7664 else if ((insn & (31 << 1)) == 21 << 1
7665 && (insn & (0x1a << 6)) == 0)
7666 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
7667 insn = (((58 | ((insn >> 6) & 4)) << 26)
7668 | ((insn >> 6) & 1));
7669 else if ((insn & (31 << 1)) == 21 << 1
7670 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
7672 insn = (58 << 26) | 2;
7676 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
7677 /* Was PPC64_TLS which sits on insn boundary, now
7678 PPC64_TPREL16_LO which is at insn+2. */
7680 r_type = R_PPC64_TPREL16_LO;
7681 if (toc_symndx != 0)
7683 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
7684 /* We changed the symbol. Start over in order to
7685 get h, sym, sec etc. right. */
7690 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7694 case R_PPC64_GOT_TLSGD16_HI:
7695 case R_PPC64_GOT_TLSGD16_HA:
7696 tls_gd = TLS_TPRELGD;
7697 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
7701 case R_PPC64_GOT_TLSLD16_HI:
7702 case R_PPC64_GOT_TLSLD16_HA:
7703 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
7706 if ((tls_mask & tls_gd) != 0)
7707 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
7708 + R_PPC64_GOT_TPREL16_DS);
7711 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
7713 r_type = R_PPC64_NONE;
7715 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7719 case R_PPC64_GOT_TLSGD16:
7720 case R_PPC64_GOT_TLSGD16_LO:
7721 tls_gd = TLS_TPRELGD;
7722 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
7723 goto tls_get_addr_check;
7726 case R_PPC64_GOT_TLSLD16:
7727 case R_PPC64_GOT_TLSLD16_LO:
7728 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
7731 if (rel + 1 < relend)
7733 enum elf_ppc64_reloc_type r_type2;
7734 unsigned long r_symndx2;
7735 struct elf_link_hash_entry *h2;
7736 bfd_vma insn1, insn2, insn3;
7739 /* The next instruction should be a call to
7740 __tls_get_addr. Peek at the reloc to be sure. */
7741 r_type2 = ELF64_R_TYPE (rel[1].r_info);
7742 r_symndx2 = ELF64_R_SYM (rel[1].r_info);
7743 if (r_symndx2 < symtab_hdr->sh_info
7744 || (r_type2 != R_PPC64_REL14
7745 && r_type2 != R_PPC64_REL14_BRTAKEN
7746 && r_type2 != R_PPC64_REL14_BRNTAKEN
7747 && r_type2 != R_PPC64_REL24))
7750 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
7751 while (h2->root.type == bfd_link_hash_indirect
7752 || h2->root.type == bfd_link_hash_warning)
7753 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
7754 if (h2 == NULL || h2 != htab->tls_get_addr)
7757 /* OK, it checks out. Replace the call. */
7758 offset = rel[1].r_offset;
7759 insn1 = bfd_get_32 (output_bfd,
7760 contents + rel->r_offset - 2);
7761 insn3 = bfd_get_32 (output_bfd,
7762 contents + offset + 4);
7763 if ((tls_mask & tls_gd) != 0)
7766 insn1 &= (1 << 26) - (1 << 2);
7767 insn1 |= 58 << 26; /* ld */
7768 insn2 = 0x7c636a14; /* add 3,3,13 */
7769 rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE);
7770 if ((tls_mask & TLS_EXPLICIT) == 0)
7771 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
7772 + R_PPC64_GOT_TPREL16_DS);
7774 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
7775 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7780 insn1 = 0x3c6d0000; /* addis 3,13,0 */
7781 insn2 = 0x38630000; /* addi 3,3,0 */
7784 /* Was an LD reloc. */
7786 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
7787 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
7789 else if (toc_symndx != 0)
7790 r_symndx = toc_symndx;
7791 r_type = R_PPC64_TPREL16_HA;
7792 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7793 rel[1].r_info = ELF64_R_INFO (r_symndx,
7794 R_PPC64_TPREL16_LO);
7795 rel[1].r_offset += 2;
7798 || insn3 == CROR_151515 || insn3 == CROR_313131)
7802 rel[1].r_offset += 4;
7804 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
7805 bfd_put_32 (output_bfd, insn2, contents + offset);
7806 bfd_put_32 (output_bfd, insn3, contents + offset + 4);
7807 if (tls_gd == 0 || toc_symndx != 0)
7809 /* We changed the symbol. Start over in order
7810 to get h, sym, sec etc. right. */
7818 case R_PPC64_DTPMOD64:
7819 if (rel + 1 < relend
7820 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
7821 && rel[1].r_offset == rel->r_offset + 8)
7823 if ((tls_mask & TLS_GD) == 0)
7825 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
7826 if ((tls_mask & TLS_TPRELGD) != 0)
7827 r_type = R_PPC64_TPREL64;
7830 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
7831 r_type = R_PPC64_NONE;
7833 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7838 if ((tls_mask & TLS_LD) == 0)
7840 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
7841 r_type = R_PPC64_NONE;
7842 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7847 case R_PPC64_TPREL64:
7848 if ((tls_mask & TLS_TPREL) == 0)
7850 r_type = R_PPC64_NONE;
7851 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7856 /* Handle other relocations that tweak non-addend part of insn. */
7863 /* Branch taken prediction relocations. */
7864 case R_PPC64_ADDR14_BRTAKEN:
7865 case R_PPC64_REL14_BRTAKEN:
7866 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
7869 /* Branch not taken prediction relocations. */
7870 case R_PPC64_ADDR14_BRNTAKEN:
7871 case R_PPC64_REL14_BRNTAKEN:
7872 insn |= bfd_get_32 (output_bfd,
7873 contents + rel->r_offset) & ~(0x01 << 21);
7876 /* Set 'a' bit. This is 0b00010 in BO field for branch
7877 on CR(BI) insns (BO == 001at or 011at), and 0b01000
7878 for branch on CTR insns (BO == 1a00t or 1a01t). */
7879 if ((insn & (0x14 << 21)) == (0x04 << 21))
7881 else if ((insn & (0x14 << 21)) == (0x10 << 21))
7888 from = (rel->r_offset
7889 + input_section->output_offset
7890 + input_section->output_section->vma);
7892 /* Invert 'y' bit if not the default. */
7893 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
7897 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
7901 /* Calls to functions with a different TOC, such as calls to
7902 shared objects, need to alter the TOC pointer. This is
7903 done using a linkage stub. A REL24 branching to these
7904 linkage stubs needs to be followed by a nop, as the nop
7905 will be replaced with an instruction to restore the TOC
7908 && (fdh = &((struct ppc_link_hash_entry *) h)->oh->elf) != NULL
7909 && fdh->plt.plist != NULL)
7910 || ((fdh = h, sec) != NULL
7911 && sec->output_section != NULL
7912 && (htab->stub_group[sec->id].toc_off
7913 != htab->stub_group[input_section->id].toc_off)))
7914 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
7916 && (stub_entry->stub_type == ppc_stub_plt_call
7917 || stub_entry->stub_type == ppc_stub_plt_branch_r2off
7918 || stub_entry->stub_type == ppc_stub_long_branch_r2off))
7920 bfd_boolean can_plt_call = 0;
7922 if (rel->r_offset + 8 <= input_section->size)
7924 insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
7926 || insn == CROR_151515 || insn == CROR_313131)
7928 bfd_put_32 (input_bfd, LD_R2_40R1,
7929 contents + rel->r_offset + 4);
7936 if (stub_entry->stub_type == ppc_stub_plt_call)
7938 /* If this is a plain branch rather than a branch
7939 and link, don't require a nop. */
7940 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
7941 if ((insn & 1) == 0)
7945 && strcmp (h->root.root.string,
7946 ".__libc_start_main") == 0)
7948 /* Allow crt1 branch to go via a toc adjusting stub. */
7953 if (strcmp (input_section->output_section->name,
7955 || strcmp (input_section->output_section->name,
7957 (*_bfd_error_handler)
7958 (_("%s(%s+0x%lx): automatic multiple TOCs "
7959 "not supported using your crt files; "
7960 "recompile with -mminimal-toc or upgrade gcc"),
7961 bfd_archive_filename (input_bfd),
7962 input_section->name,
7963 (long) rel->r_offset);
7965 (*_bfd_error_handler)
7966 (_("%s(%s+0x%lx): sibling call optimization to `%s' "
7967 "does not allow automatic multiple TOCs; "
7968 "recompile with -mminimal-toc or "
7969 "-fno-optimize-sibling-calls, "
7970 "or make `%s' extern"),
7971 bfd_archive_filename (input_bfd),
7972 input_section->name,
7973 (long) rel->r_offset,
7976 bfd_set_error (bfd_error_bad_value);
7983 relocation = (stub_entry->stub_offset
7984 + stub_entry->stub_sec->output_offset
7985 + stub_entry->stub_sec->output_section->vma);
7986 if (stub_entry->stub_type == ppc_stub_plt_call)
7987 unresolved_reloc = FALSE;
7992 && h->root.type == bfd_link_hash_undefweak
7994 && rel->r_addend == 0)
7996 /* Tweak calls to undefined weak functions to point at a
7997 blr. We can thus call a weak function without first
7998 checking whether the function is defined. We have a
7999 blr at the end of .sfpr. */
8000 BFD_ASSERT (htab->sfpr->size != 0);
8001 relocation = (htab->sfpr->size - 4
8002 + htab->sfpr->output_offset
8003 + htab->sfpr->output_section->vma);
8004 from = (rel->r_offset
8005 + input_section->output_offset
8006 + input_section->output_section->vma);
8008 /* But let's not be silly about it. If the blr isn't in
8009 reach, just go to the next instruction. */
8010 if (relocation - from + (1 << 25) >= (1 << 26)
8011 || htab->sfpr->size == 0)
8012 relocation = from + 4;
8019 addend = rel->r_addend;
8023 (*_bfd_error_handler)
8024 (_("%s: unknown relocation type %d for symbol %s"),
8025 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
8027 bfd_set_error (bfd_error_bad_value);
8033 case R_PPC64_GNU_VTINHERIT:
8034 case R_PPC64_GNU_VTENTRY:
8037 /* GOT16 relocations. Like an ADDR16 using the symbol's
8038 address in the GOT as relocation value instead of the
8039 symbol's value itself. Also, create a GOT entry for the
8040 symbol and put the symbol value there. */
8041 case R_PPC64_GOT_TLSGD16:
8042 case R_PPC64_GOT_TLSGD16_LO:
8043 case R_PPC64_GOT_TLSGD16_HI:
8044 case R_PPC64_GOT_TLSGD16_HA:
8045 tls_type = TLS_TLS | TLS_GD;
8048 case R_PPC64_GOT_TLSLD16:
8049 case R_PPC64_GOT_TLSLD16_LO:
8050 case R_PPC64_GOT_TLSLD16_HI:
8051 case R_PPC64_GOT_TLSLD16_HA:
8052 tls_type = TLS_TLS | TLS_LD;
8055 case R_PPC64_GOT_TPREL16_DS:
8056 case R_PPC64_GOT_TPREL16_LO_DS:
8057 case R_PPC64_GOT_TPREL16_HI:
8058 case R_PPC64_GOT_TPREL16_HA:
8059 tls_type = TLS_TLS | TLS_TPREL;
8062 case R_PPC64_GOT_DTPREL16_DS:
8063 case R_PPC64_GOT_DTPREL16_LO_DS:
8064 case R_PPC64_GOT_DTPREL16_HI:
8065 case R_PPC64_GOT_DTPREL16_HA:
8066 tls_type = TLS_TLS | TLS_DTPREL;
8070 case R_PPC64_GOT16_LO:
8071 case R_PPC64_GOT16_HI:
8072 case R_PPC64_GOT16_HA:
8073 case R_PPC64_GOT16_DS:
8074 case R_PPC64_GOT16_LO_DS:
8077 /* Relocation is to the entry for this symbol in the global
8082 unsigned long indx = 0;
8084 if (tls_type == (TLS_TLS | TLS_LD)
8086 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
8087 offp = &ppc64_tlsld_got (input_bfd)->offset;
8090 struct got_entry *ent;
8094 bfd_boolean dyn = htab->elf.dynamic_sections_created;
8095 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8097 && SYMBOL_REFERENCES_LOCAL (info, h)))
8098 /* This is actually a static link, or it is a
8099 -Bsymbolic link and the symbol is defined
8100 locally, or the symbol was forced to be local
8101 because of a version file. */
8106 unresolved_reloc = FALSE;
8112 if (local_got_ents == NULL)
8114 ent = local_got_ents[r_symndx];
8117 for (; ent != NULL; ent = ent->next)
8118 if (ent->addend == rel->r_addend
8119 && ent->owner == input_bfd
8120 && ent->tls_type == tls_type)
8124 offp = &ent->got.offset;
8127 got = ppc64_elf_tdata (input_bfd)->got;
8131 /* The offset must always be a multiple of 8. We use the
8132 least significant bit to record whether we have already
8133 processed this entry. */
8139 /* Generate relocs for the dynamic linker, except in
8140 the case of TLSLD where we'll use one entry per
8142 asection *relgot = ppc64_elf_tdata (input_bfd)->relgot;
8145 if ((info->shared || indx != 0)
8147 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8148 || h->root.type != bfd_link_hash_undefweak))
8150 outrel.r_offset = (got->output_section->vma
8151 + got->output_offset
8153 outrel.r_addend = rel->r_addend;
8154 if (tls_type & (TLS_LD | TLS_GD))
8156 outrel.r_addend = 0;
8157 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
8158 if (tls_type == (TLS_TLS | TLS_GD))
8160 loc = relgot->contents;
8161 loc += (relgot->reloc_count++
8162 * sizeof (Elf64_External_Rela));
8163 bfd_elf64_swap_reloca_out (output_bfd,
8165 outrel.r_offset += 8;
8166 outrel.r_addend = rel->r_addend;
8168 = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
8171 else if (tls_type == (TLS_TLS | TLS_DTPREL))
8172 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
8173 else if (tls_type == (TLS_TLS | TLS_TPREL))
8174 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
8177 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE);
8179 /* Write the .got section contents for the sake
8181 loc = got->contents + off;
8182 bfd_put_64 (output_bfd, outrel.r_addend + relocation,
8186 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
8188 if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
8190 outrel.r_addend += relocation;
8191 if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
8192 outrel.r_addend -= htab->elf.tls_sec->vma;
8194 loc = relgot->contents;
8195 loc += (relgot->reloc_count++
8196 * sizeof (Elf64_External_Rela));
8197 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
8200 /* Init the .got section contents here if we're not
8201 emitting a reloc. */
8204 relocation += rel->r_addend;
8205 if (tls_type == (TLS_TLS | TLS_LD))
8207 else if (tls_type != 0)
8209 relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
8210 if (tls_type == (TLS_TLS | TLS_TPREL))
8211 relocation += DTP_OFFSET - TP_OFFSET;
8213 if (tls_type == (TLS_TLS | TLS_GD))
8215 bfd_put_64 (output_bfd, relocation,
8216 got->contents + off + 8);
8221 bfd_put_64 (output_bfd, relocation,
8222 got->contents + off);
8226 if (off >= (bfd_vma) -2)
8229 relocation = got->output_offset + off;
8231 /* TOC base (r2) is TOC start plus 0x8000. */
8232 addend = -TOC_BASE_OFF;
8236 case R_PPC64_PLT16_HA:
8237 case R_PPC64_PLT16_HI:
8238 case R_PPC64_PLT16_LO:
8241 /* Relocation is to the entry for this symbol in the
8242 procedure linkage table. */
8244 /* Resolve a PLT reloc against a local symbol directly,
8245 without using the procedure linkage table. */
8249 /* It's possible that we didn't make a PLT entry for this
8250 symbol. This happens when statically linking PIC code,
8251 or when using -Bsymbolic. Go find a match if there is a
8253 if (htab->plt != NULL)
8255 struct plt_entry *ent;
8256 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
8257 if (ent->addend == rel->r_addend
8258 && ent->plt.offset != (bfd_vma) -1)
8260 relocation = (htab->plt->output_section->vma
8261 + htab->plt->output_offset
8263 unresolved_reloc = FALSE;
8269 /* Relocation value is TOC base. */
8270 relocation = TOCstart;
8272 relocation += htab->stub_group[input_section->id].toc_off;
8273 else if (unresolved_reloc)
8275 else if (sec != NULL && sec->id <= htab->top_id)
8276 relocation += htab->stub_group[sec->id].toc_off;
8278 unresolved_reloc = TRUE;
8281 /* TOC16 relocs. We want the offset relative to the TOC base,
8282 which is the address of the start of the TOC plus 0x8000.
8283 The TOC consists of sections .got, .toc, .tocbss, and .plt,
8286 case R_PPC64_TOC16_LO:
8287 case R_PPC64_TOC16_HI:
8288 case R_PPC64_TOC16_DS:
8289 case R_PPC64_TOC16_LO_DS:
8290 case R_PPC64_TOC16_HA:
8291 addend -= TOCstart + htab->stub_group[input_section->id].toc_off;
8294 /* Relocate against the beginning of the section. */
8295 case R_PPC64_SECTOFF:
8296 case R_PPC64_SECTOFF_LO:
8297 case R_PPC64_SECTOFF_HI:
8298 case R_PPC64_SECTOFF_DS:
8299 case R_PPC64_SECTOFF_LO_DS:
8300 case R_PPC64_SECTOFF_HA:
8302 addend -= sec->output_section->vma;
8306 case R_PPC64_REL14_BRNTAKEN:
8307 case R_PPC64_REL14_BRTAKEN:
8311 case R_PPC64_TPREL16:
8312 case R_PPC64_TPREL16_LO:
8313 case R_PPC64_TPREL16_HI:
8314 case R_PPC64_TPREL16_HA:
8315 case R_PPC64_TPREL16_DS:
8316 case R_PPC64_TPREL16_LO_DS:
8317 case R_PPC64_TPREL16_HIGHER:
8318 case R_PPC64_TPREL16_HIGHERA:
8319 case R_PPC64_TPREL16_HIGHEST:
8320 case R_PPC64_TPREL16_HIGHESTA:
8321 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
8323 /* The TPREL16 relocs shouldn't really be used in shared
8324 libs as they will result in DT_TEXTREL being set, but
8325 support them anyway. */
8329 case R_PPC64_DTPREL16:
8330 case R_PPC64_DTPREL16_LO:
8331 case R_PPC64_DTPREL16_HI:
8332 case R_PPC64_DTPREL16_HA:
8333 case R_PPC64_DTPREL16_DS:
8334 case R_PPC64_DTPREL16_LO_DS:
8335 case R_PPC64_DTPREL16_HIGHER:
8336 case R_PPC64_DTPREL16_HIGHERA:
8337 case R_PPC64_DTPREL16_HIGHEST:
8338 case R_PPC64_DTPREL16_HIGHESTA:
8339 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
8342 case R_PPC64_DTPMOD64:
8347 case R_PPC64_TPREL64:
8348 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
8351 case R_PPC64_DTPREL64:
8352 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
8355 /* Relocations that may need to be propagated if this is a
8360 case R_PPC64_ADDR14:
8361 case R_PPC64_ADDR14_BRNTAKEN:
8362 case R_PPC64_ADDR14_BRTAKEN:
8363 case R_PPC64_ADDR16:
8364 case R_PPC64_ADDR16_DS:
8365 case R_PPC64_ADDR16_HA:
8366 case R_PPC64_ADDR16_HI:
8367 case R_PPC64_ADDR16_HIGHER:
8368 case R_PPC64_ADDR16_HIGHERA:
8369 case R_PPC64_ADDR16_HIGHEST:
8370 case R_PPC64_ADDR16_HIGHESTA:
8371 case R_PPC64_ADDR16_LO:
8372 case R_PPC64_ADDR16_LO_DS:
8373 case R_PPC64_ADDR24:
8374 case R_PPC64_ADDR32:
8375 case R_PPC64_ADDR64:
8376 case R_PPC64_UADDR16:
8377 case R_PPC64_UADDR32:
8378 case R_PPC64_UADDR64:
8379 /* r_symndx will be zero only for relocs against symbols
8380 from removed linkonce sections, or sections discarded by
8388 if ((input_section->flags & SEC_ALLOC) == 0)
8391 if (NO_OPD_RELOCS && is_opd)
8396 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8397 || h->root.type != bfd_link_hash_undefweak)
8398 && (MUST_BE_DYN_RELOC (r_type)
8399 || !SYMBOL_CALLS_LOCAL (info, h)))
8400 || (ELIMINATE_COPY_RELOCS
8404 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
8405 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
8406 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
8408 Elf_Internal_Rela outrel;
8409 bfd_boolean skip, relocate;
8414 /* When generating a dynamic object, these relocations
8415 are copied into the output file to be resolved at run
8421 out_off = _bfd_elf_section_offset (output_bfd, info,
8422 input_section, rel->r_offset);
8423 if (out_off == (bfd_vma) -1)
8425 else if (out_off == (bfd_vma) -2)
8426 skip = TRUE, relocate = TRUE;
8427 out_off += (input_section->output_section->vma
8428 + input_section->output_offset);
8429 outrel.r_offset = out_off;
8430 outrel.r_addend = rel->r_addend;
8432 /* Optimize unaligned reloc use. */
8433 if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
8434 || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
8435 r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
8436 else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
8437 || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
8438 r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
8439 else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
8440 || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
8441 r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
8444 memset (&outrel, 0, sizeof outrel);
8445 else if (!SYMBOL_REFERENCES_LOCAL (info, h)
8447 && r_type != R_PPC64_TOC)
8448 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
8451 /* This symbol is local, or marked to become local,
8452 or this is an opd section reloc which must point
8453 at a local function. */
8454 outrel.r_addend += relocation;
8455 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
8457 if (is_opd && h != NULL)
8459 /* Lie about opd entries. This case occurs
8460 when building shared libraries and we
8461 reference a function in another shared
8462 lib. The same thing happens for a weak
8463 definition in an application that's
8464 overridden by a strong definition in a
8465 shared lib. (I believe this is a generic
8466 bug in binutils handling of weak syms.)
8467 In these cases we won't use the opd
8468 entry in this lib. */
8469 unresolved_reloc = FALSE;
8471 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
8473 /* We need to relocate .opd contents for ld.so.
8474 Prelink also wants simple and consistent rules
8475 for relocs. This make all RELATIVE relocs have
8476 *r_offset equal to r_addend. */
8483 if (bfd_is_abs_section (sec))
8485 else if (sec == NULL || sec->owner == NULL)
8487 bfd_set_error (bfd_error_bad_value);
8494 osec = sec->output_section;
8495 indx = elf_section_data (osec)->dynindx;
8497 /* We are turning this relocation into one
8498 against a section symbol, so subtract out
8499 the output section's address but not the
8500 offset of the input section in the output
8502 outrel.r_addend -= osec->vma;
8505 outrel.r_info = ELF64_R_INFO (indx, r_type);
8509 sreloc = elf_section_data (input_section)->sreloc;
8513 loc = sreloc->contents;
8514 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
8515 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
8517 /* If this reloc is against an external symbol, it will
8518 be computed at runtime, so there's no need to do
8519 anything now. However, for the sake of prelink ensure
8520 that the section contents are a known value. */
8523 unresolved_reloc = FALSE;
8524 /* The value chosen here is quite arbitrary as ld.so
8525 ignores section contents except for the special
8526 case of .opd where the contents might be accessed
8527 before relocation. Choose zero, as that won't
8528 cause reloc overflow. */
8531 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
8532 to improve backward compatibility with older
8534 if (r_type == R_PPC64_ADDR64)
8535 addend = outrel.r_addend;
8536 /* Adjust pc_relative relocs to have zero in *r_offset. */
8537 else if (ppc64_elf_howto_table[r_type]->pc_relative)
8538 addend = (input_section->output_section->vma
8539 + input_section->output_offset
8546 case R_PPC64_GLOB_DAT:
8547 case R_PPC64_JMP_SLOT:
8548 case R_PPC64_RELATIVE:
8549 /* We shouldn't ever see these dynamic relocs in relocatable
8553 case R_PPC64_PLTGOT16:
8554 case R_PPC64_PLTGOT16_DS:
8555 case R_PPC64_PLTGOT16_HA:
8556 case R_PPC64_PLTGOT16_HI:
8557 case R_PPC64_PLTGOT16_LO:
8558 case R_PPC64_PLTGOT16_LO_DS:
8559 case R_PPC64_PLTREL32:
8560 case R_PPC64_PLTREL64:
8561 /* These ones haven't been implemented yet. */
8563 (*_bfd_error_handler)
8564 (_("%s: relocation %s is not supported for symbol %s."),
8565 bfd_archive_filename (input_bfd),
8566 ppc64_elf_howto_table[r_type]->name, sym_name);
8568 bfd_set_error (bfd_error_invalid_operation);
8573 /* Do any further special processing. */
8579 case R_PPC64_ADDR16_HA:
8580 case R_PPC64_ADDR16_HIGHERA:
8581 case R_PPC64_ADDR16_HIGHESTA:
8582 case R_PPC64_GOT16_HA:
8583 case R_PPC64_PLTGOT16_HA:
8584 case R_PPC64_PLT16_HA:
8585 case R_PPC64_TOC16_HA:
8586 case R_PPC64_SECTOFF_HA:
8587 case R_PPC64_TPREL16_HA:
8588 case R_PPC64_DTPREL16_HA:
8589 case R_PPC64_GOT_TLSGD16_HA:
8590 case R_PPC64_GOT_TLSLD16_HA:
8591 case R_PPC64_GOT_TPREL16_HA:
8592 case R_PPC64_GOT_DTPREL16_HA:
8593 case R_PPC64_TPREL16_HIGHER:
8594 case R_PPC64_TPREL16_HIGHERA:
8595 case R_PPC64_TPREL16_HIGHEST:
8596 case R_PPC64_TPREL16_HIGHESTA:
8597 case R_PPC64_DTPREL16_HIGHER:
8598 case R_PPC64_DTPREL16_HIGHERA:
8599 case R_PPC64_DTPREL16_HIGHEST:
8600 case R_PPC64_DTPREL16_HIGHESTA:
8601 /* It's just possible that this symbol is a weak symbol
8602 that's not actually defined anywhere. In that case,
8603 'sec' would be NULL, and we should leave the symbol
8604 alone (it will be set to zero elsewhere in the link). */
8606 /* Add 0x10000 if sign bit in 0:15 is set.
8607 Bits 0:15 are not used. */
8611 case R_PPC64_ADDR16_DS:
8612 case R_PPC64_ADDR16_LO_DS:
8613 case R_PPC64_GOT16_DS:
8614 case R_PPC64_GOT16_LO_DS:
8615 case R_PPC64_PLT16_LO_DS:
8616 case R_PPC64_SECTOFF_DS:
8617 case R_PPC64_SECTOFF_LO_DS:
8618 case R_PPC64_TOC16_DS:
8619 case R_PPC64_TOC16_LO_DS:
8620 case R_PPC64_PLTGOT16_DS:
8621 case R_PPC64_PLTGOT16_LO_DS:
8622 case R_PPC64_GOT_TPREL16_DS:
8623 case R_PPC64_GOT_TPREL16_LO_DS:
8624 case R_PPC64_GOT_DTPREL16_DS:
8625 case R_PPC64_GOT_DTPREL16_LO_DS:
8626 case R_PPC64_TPREL16_DS:
8627 case R_PPC64_TPREL16_LO_DS:
8628 case R_PPC64_DTPREL16_DS:
8629 case R_PPC64_DTPREL16_LO_DS:
8630 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
8632 /* If this reloc is against an lq insn, then the value must be
8633 a multiple of 16. This is somewhat of a hack, but the
8634 "correct" way to do this by defining _DQ forms of all the
8635 _DS relocs bloats all reloc switches in this file. It
8636 doesn't seem to make much sense to use any of these relocs
8637 in data, so testing the insn should be safe. */
8638 if ((insn & (0x3f << 26)) == (56u << 26))
8640 if (((relocation + addend) & mask) != 0)
8642 (*_bfd_error_handler)
8643 (_("%s: error: relocation %s not a multiple of %d"),
8644 bfd_archive_filename (input_bfd),
8645 ppc64_elf_howto_table[r_type]->name,
8647 bfd_set_error (bfd_error_bad_value);
8654 case R_PPC64_REL14_BRNTAKEN:
8655 case R_PPC64_REL14_BRTAKEN:
8656 max_br_offset = 1 << 15;
8660 max_br_offset = 1 << 25;
8663 /* If the branch is out of reach or the TOC register needs
8664 adjusting, then redirect the call to the local stub for
8666 from = (rel->r_offset
8667 + input_section->output_offset
8668 + input_section->output_section->vma);
8669 if ((relocation + addend - from + max_br_offset >= 2 * max_br_offset
8671 && sec->output_section != NULL
8672 && sec->id <= htab->top_id
8673 && (htab->stub_group[sec->id].toc_off
8674 != htab->stub_group[input_section->id].toc_off)))
8675 && (stub_entry = ppc_get_stub_entry (input_section, sec, h,
8676 rel, htab)) != NULL)
8678 /* Munge up the value and addend so that we call the stub
8679 rather than the procedure directly. */
8680 relocation = (stub_entry->stub_offset
8681 + stub_entry->stub_sec->output_offset
8682 + stub_entry->stub_sec->output_section->vma);
8688 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8689 because such sections are not SEC_ALLOC and thus ld.so will
8690 not process them. */
8691 if (unresolved_reloc
8692 && !((input_section->flags & SEC_DEBUGGING) != 0
8693 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
8695 (*_bfd_error_handler)
8696 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
8697 bfd_archive_filename (input_bfd),
8698 bfd_get_section_name (input_bfd, input_section),
8699 (long) rel->r_offset,
8700 ppc64_elf_howto_table[(int) r_type]->name,
8701 h->root.root.string);
8705 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
8713 if (r != bfd_reloc_ok)
8715 if (sym_name == NULL)
8716 sym_name = "(null)";
8717 if (r == bfd_reloc_overflow)
8722 && h->root.type == bfd_link_hash_undefweak
8723 && ppc64_elf_howto_table[r_type]->pc_relative)
8725 /* Assume this is a call protected by other code that
8726 detects the symbol is undefined. If this is the case,
8727 we can safely ignore the overflow. If not, the
8728 program is hosed anyway, and a little warning isn't
8734 if (!((*info->callbacks->reloc_overflow)
8735 (info, sym_name, ppc64_elf_howto_table[r_type]->name,
8736 rel->r_addend, input_bfd, input_section, rel->r_offset)))
8741 (*_bfd_error_handler)
8742 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
8743 bfd_archive_filename (input_bfd),
8744 bfd_get_section_name (input_bfd, input_section),
8745 (long) rel->r_offset,
8746 ppc64_elf_howto_table[r_type]->name,
8757 /* Adjust the value of any local symbols in opd sections. */
8760 ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
8761 const char *name ATTRIBUTE_UNUSED,
8762 Elf_Internal_Sym *elfsym,
8763 asection *input_sec,
8764 struct elf_link_hash_entry *h)
8766 long *opd_adjust, adjust;
8772 opd_adjust = get_opd_info (input_sec);
8773 if (opd_adjust == NULL)
8776 value = elfsym->st_value - input_sec->output_offset;
8777 if (!info->relocatable)
8778 value -= input_sec->output_section->vma;
8780 adjust = opd_adjust[value / 24];
8782 elfsym->st_value = 0;
8784 elfsym->st_value += adjust;
8788 /* Finish up dynamic symbol handling. We set the contents of various
8789 dynamic sections here. */
8792 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
8793 struct bfd_link_info *info,
8794 struct elf_link_hash_entry *h,
8795 Elf_Internal_Sym *sym)
8797 struct ppc_link_hash_table *htab;
8800 htab = ppc_hash_table (info);
8801 dynobj = htab->elf.dynobj;
8803 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
8805 struct plt_entry *ent;
8806 Elf_Internal_Rela rela;
8809 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
8810 if (ent->plt.offset != (bfd_vma) -1)
8812 /* This symbol has an entry in the procedure linkage
8813 table. Set it up. */
8815 if (htab->plt == NULL
8816 || htab->relplt == NULL
8817 || htab->glink == NULL)
8820 /* Create a JMP_SLOT reloc to inform the dynamic linker to
8821 fill in the PLT entry. */
8822 rela.r_offset = (htab->plt->output_section->vma
8823 + htab->plt->output_offset
8825 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
8826 rela.r_addend = ent->addend;
8828 loc = htab->relplt->contents;
8829 loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
8830 * sizeof (Elf64_External_Rela));
8831 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
8835 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
8837 Elf_Internal_Rela rela;
8840 /* This symbol needs a copy reloc. Set it up. */
8842 if (h->dynindx == -1
8843 || (h->root.type != bfd_link_hash_defined
8844 && h->root.type != bfd_link_hash_defweak)
8845 || htab->relbss == NULL)
8848 rela.r_offset = (h->root.u.def.value
8849 + h->root.u.def.section->output_section->vma
8850 + h->root.u.def.section->output_offset);
8851 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
8853 loc = htab->relbss->contents;
8854 loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela);
8855 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
8858 /* Mark some specially defined symbols as absolute. */
8859 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
8860 sym->st_shndx = SHN_ABS;
8865 /* Used to decide how to sort relocs in an optimal manner for the
8866 dynamic linker, before writing them out. */
8868 static enum elf_reloc_type_class
8869 ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela)
8871 enum elf_ppc64_reloc_type r_type;
8873 r_type = ELF64_R_TYPE (rela->r_info);
8876 case R_PPC64_RELATIVE:
8877 return reloc_class_relative;
8878 case R_PPC64_JMP_SLOT:
8879 return reloc_class_plt;
8881 return reloc_class_copy;
8883 return reloc_class_normal;
8887 /* Finish up the dynamic sections. */
8890 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
8891 struct bfd_link_info *info)
8893 struct ppc_link_hash_table *htab;
8897 htab = ppc_hash_table (info);
8898 dynobj = htab->elf.dynobj;
8899 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8901 if (htab->elf.dynamic_sections_created)
8903 Elf64_External_Dyn *dyncon, *dynconend;
8905 if (sdyn == NULL || htab->got == NULL)
8908 dyncon = (Elf64_External_Dyn *) sdyn->contents;
8909 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
8910 for (; dyncon < dynconend; dyncon++)
8912 Elf_Internal_Dyn dyn;
8915 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
8922 case DT_PPC64_GLINK:
8924 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8925 /* We stupidly defined DT_PPC64_GLINK to be the start
8926 of glink rather than the first entry point, which is
8927 what ld.so needs, and now have a bigger stub to
8928 support automatic multiple TOCs. */
8929 dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32;
8933 s = bfd_get_section_by_name (output_bfd, ".opd");
8936 dyn.d_un.d_ptr = s->vma;
8939 case DT_PPC64_OPDSZ:
8940 s = bfd_get_section_by_name (output_bfd, ".opd");
8943 dyn.d_un.d_val = s->size;
8948 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8953 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8957 dyn.d_un.d_val = htab->relplt->size;
8961 /* Don't count procedure linkage table relocs in the
8962 overall reloc count. */
8966 dyn.d_un.d_val -= s->size;
8970 /* We may not be using the standard ELF linker script.
8971 If .rela.plt is the first .rela section, we adjust
8972 DT_RELA to not include it. */
8976 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
8978 dyn.d_un.d_ptr += s->size;
8982 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
8986 if (htab->got != NULL && htab->got->size != 0)
8988 /* Fill in the first entry in the global offset table.
8989 We use it to hold the link-time TOCbase. */
8990 bfd_put_64 (output_bfd,
8991 elf_gp (output_bfd) + TOC_BASE_OFF,
8992 htab->got->contents);
8994 /* Set .got entry size. */
8995 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8;
8998 if (htab->plt != NULL && htab->plt->size != 0)
9000 /* Set .plt entry size. */
9001 elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize
9005 /* We need to handle writing out multiple GOT sections ourselves,
9006 since we didn't add them to DYNOBJ. */
9007 while ((dynobj = dynobj->link_next) != NULL)
9010 s = ppc64_elf_tdata (dynobj)->got;
9013 && s->output_section != bfd_abs_section_ptr
9014 && !bfd_set_section_contents (output_bfd, s->output_section,
9015 s->contents, s->output_offset,
9018 s = ppc64_elf_tdata (dynobj)->relgot;
9021 && s->output_section != bfd_abs_section_ptr
9022 && !bfd_set_section_contents (output_bfd, s->output_section,
9023 s->contents, s->output_offset,
9031 #include "elf64-target.h"