1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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 */
34 #include "elf/ppc64.h"
35 #include "elf64-ppc.h"
37 static bfd_reloc_status_type ppc64_elf_ha_reloc
38 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
39 static bfd_reloc_status_type ppc64_elf_branch_reloc
40 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
41 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
42 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
43 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
44 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
45 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
46 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
47 static bfd_reloc_status_type ppc64_elf_toc_reloc
48 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
49 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
50 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
51 static bfd_reloc_status_type ppc64_elf_toc64_reloc
52 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
53 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
54 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
55 static bfd_vma opd_entry_value
56 (asection *, bfd_vma, asection **, bfd_vma *);
58 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
59 #define TARGET_LITTLE_NAME "elf64-powerpcle"
60 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
61 #define TARGET_BIG_NAME "elf64-powerpc"
62 #define ELF_ARCH bfd_arch_powerpc
63 #define ELF_MACHINE_CODE EM_PPC64
64 #define ELF_MAXPAGESIZE 0x10000
65 #define ELF_COMMONPAGESIZE 0x1000
66 #define elf_info_to_howto ppc64_elf_info_to_howto
68 #define elf_backend_want_got_sym 0
69 #define elf_backend_want_plt_sym 0
70 #define elf_backend_plt_alignment 3
71 #define elf_backend_plt_not_loaded 1
72 #define elf_backend_got_header_size 8
73 #define elf_backend_can_gc_sections 1
74 #define elf_backend_can_refcount 1
75 #define elf_backend_rela_normal 1
77 #define bfd_elf64_mkobject ppc64_elf_mkobject
78 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
79 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
80 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
81 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
82 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
83 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
85 #define elf_backend_object_p ppc64_elf_object_p
86 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
87 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
88 #define elf_backend_write_core_note ppc64_elf_write_core_note
89 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
90 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
91 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
92 #define elf_backend_check_directives ppc64_elf_check_directives
93 #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup
94 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
95 #define elf_backend_check_relocs ppc64_elf_check_relocs
96 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
97 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
98 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
99 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
100 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
101 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
102 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
103 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
104 #define elf_backend_action_discarded ppc64_elf_action_discarded
105 #define elf_backend_relocate_section ppc64_elf_relocate_section
106 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
107 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
108 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
109 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
110 #define elf_backend_special_sections ppc64_elf_special_sections
112 /* The name of the dynamic interpreter. This is put in the .interp
114 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
116 /* The size in bytes of an entry in the procedure linkage table. */
117 #define PLT_ENTRY_SIZE 24
119 /* The initial size of the plt reserved for the dynamic linker. */
120 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
122 /* TOC base pointers offset from start of TOC. */
123 #define TOC_BASE_OFF 0x8000
125 /* Offset of tp and dtp pointers from start of TLS block. */
126 #define TP_OFFSET 0x7000
127 #define DTP_OFFSET 0x8000
129 /* .plt call stub instructions. The normal stub is like this, but
130 sometimes the .plt entry crosses a 64k boundary and we need to
131 insert an addis to adjust r12. */
132 #define PLT_CALL_STUB_SIZE (7*4)
133 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
134 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
135 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
136 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
137 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
138 /* ld %r11,xxx+16@l(%r12) */
139 #define BCTR 0x4e800420 /* bctr */
142 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */
143 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
144 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
146 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
148 /* glink call stub instructions. We enter with the index in R0. */
149 #define GLINK_CALL_STUB_SIZE (16*4)
153 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
154 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
156 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
157 #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */
158 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
159 #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */
167 #define NOP 0x60000000
169 /* Some other nops. */
170 #define CROR_151515 0x4def7b82
171 #define CROR_313131 0x4ffffb82
173 /* .glink entries for the first 32k functions are two instructions. */
174 #define LI_R0_0 0x38000000 /* li %r0,0 */
175 #define B_DOT 0x48000000 /* b . */
177 /* After that, we need two instructions to load the index, followed by
179 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
180 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
182 /* Instructions used by the save and restore reg functions. */
183 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
184 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
185 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
186 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
187 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
188 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
189 #define LI_R12_0 0x39800000 /* li %r12,0 */
190 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
191 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
192 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
193 #define BLR 0x4e800020 /* blr */
195 /* Since .opd is an array of descriptors and each entry will end up
196 with identical R_PPC64_RELATIVE relocs, there is really no need to
197 propagate .opd relocs; The dynamic linker should be taught to
198 relocate .opd without reloc entries. */
199 #ifndef NO_OPD_RELOCS
200 #define NO_OPD_RELOCS 0
203 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
205 /* Relocation HOWTO's. */
206 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
208 static reloc_howto_type ppc64_elf_howto_raw[] = {
209 /* This reloc does nothing. */
210 HOWTO (R_PPC64_NONE, /* type */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
214 FALSE, /* pc_relative */
216 complain_overflow_dont, /* complain_on_overflow */
217 bfd_elf_generic_reloc, /* special_function */
218 "R_PPC64_NONE", /* name */
219 FALSE, /* partial_inplace */
222 FALSE), /* pcrel_offset */
224 /* A standard 32 bit relocation. */
225 HOWTO (R_PPC64_ADDR32, /* type */
227 2, /* size (0 = byte, 1 = short, 2 = long) */
229 FALSE, /* pc_relative */
231 complain_overflow_bitfield, /* complain_on_overflow */
232 bfd_elf_generic_reloc, /* special_function */
233 "R_PPC64_ADDR32", /* name */
234 FALSE, /* partial_inplace */
236 0xffffffff, /* dst_mask */
237 FALSE), /* pcrel_offset */
239 /* An absolute 26 bit branch; the lower two bits must be zero.
240 FIXME: we don't check that, we just clear them. */
241 HOWTO (R_PPC64_ADDR24, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 FALSE, /* pc_relative */
247 complain_overflow_bitfield, /* complain_on_overflow */
248 bfd_elf_generic_reloc, /* special_function */
249 "R_PPC64_ADDR24", /* name */
250 FALSE, /* partial_inplace */
252 0x03fffffc, /* dst_mask */
253 FALSE), /* pcrel_offset */
255 /* A standard 16 bit relocation. */
256 HOWTO (R_PPC64_ADDR16, /* type */
258 1, /* size (0 = byte, 1 = short, 2 = long) */
260 FALSE, /* pc_relative */
262 complain_overflow_bitfield, /* complain_on_overflow */
263 bfd_elf_generic_reloc, /* special_function */
264 "R_PPC64_ADDR16", /* name */
265 FALSE, /* partial_inplace */
267 0xffff, /* dst_mask */
268 FALSE), /* pcrel_offset */
270 /* A 16 bit relocation without overflow. */
271 HOWTO (R_PPC64_ADDR16_LO, /* type */
273 1, /* size (0 = byte, 1 = short, 2 = long) */
275 FALSE, /* pc_relative */
277 complain_overflow_dont,/* complain_on_overflow */
278 bfd_elf_generic_reloc, /* special_function */
279 "R_PPC64_ADDR16_LO", /* name */
280 FALSE, /* partial_inplace */
282 0xffff, /* dst_mask */
283 FALSE), /* pcrel_offset */
285 /* Bits 16-31 of an address. */
286 HOWTO (R_PPC64_ADDR16_HI, /* type */
288 1, /* size (0 = byte, 1 = short, 2 = long) */
290 FALSE, /* pc_relative */
292 complain_overflow_dont, /* complain_on_overflow */
293 bfd_elf_generic_reloc, /* special_function */
294 "R_PPC64_ADDR16_HI", /* name */
295 FALSE, /* partial_inplace */
297 0xffff, /* dst_mask */
298 FALSE), /* pcrel_offset */
300 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
301 bits, treated as a signed number, is negative. */
302 HOWTO (R_PPC64_ADDR16_HA, /* type */
304 1, /* size (0 = byte, 1 = short, 2 = long) */
306 FALSE, /* pc_relative */
308 complain_overflow_dont, /* complain_on_overflow */
309 ppc64_elf_ha_reloc, /* special_function */
310 "R_PPC64_ADDR16_HA", /* name */
311 FALSE, /* partial_inplace */
313 0xffff, /* dst_mask */
314 FALSE), /* pcrel_offset */
316 /* An absolute 16 bit branch; the lower two bits must be zero.
317 FIXME: we don't check that, we just clear them. */
318 HOWTO (R_PPC64_ADDR14, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 FALSE, /* pc_relative */
324 complain_overflow_bitfield, /* complain_on_overflow */
325 ppc64_elf_branch_reloc, /* special_function */
326 "R_PPC64_ADDR14", /* name */
327 FALSE, /* partial_inplace */
329 0x0000fffc, /* dst_mask */
330 FALSE), /* pcrel_offset */
332 /* An absolute 16 bit branch, for which bit 10 should be set to
333 indicate that the branch is expected to be taken. The lower two
334 bits must be zero. */
335 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
339 FALSE, /* pc_relative */
341 complain_overflow_bitfield, /* complain_on_overflow */
342 ppc64_elf_brtaken_reloc, /* special_function */
343 "R_PPC64_ADDR14_BRTAKEN",/* name */
344 FALSE, /* partial_inplace */
346 0x0000fffc, /* dst_mask */
347 FALSE), /* pcrel_offset */
349 /* An absolute 16 bit branch, for which bit 10 should be set to
350 indicate that the branch is not expected to be taken. The lower
351 two bits must be zero. */
352 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE, /* pc_relative */
358 complain_overflow_bitfield, /* complain_on_overflow */
359 ppc64_elf_brtaken_reloc, /* special_function */
360 "R_PPC64_ADDR14_BRNTAKEN",/* name */
361 FALSE, /* partial_inplace */
363 0x0000fffc, /* dst_mask */
364 FALSE), /* pcrel_offset */
366 /* A relative 26 bit branch; the lower two bits must be zero. */
367 HOWTO (R_PPC64_REL24, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 TRUE, /* pc_relative */
373 complain_overflow_signed, /* complain_on_overflow */
374 ppc64_elf_branch_reloc, /* special_function */
375 "R_PPC64_REL24", /* name */
376 FALSE, /* partial_inplace */
378 0x03fffffc, /* dst_mask */
379 TRUE), /* pcrel_offset */
381 /* A relative 16 bit branch; the lower two bits must be zero. */
382 HOWTO (R_PPC64_REL14, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 TRUE, /* pc_relative */
388 complain_overflow_signed, /* complain_on_overflow */
389 ppc64_elf_branch_reloc, /* special_function */
390 "R_PPC64_REL14", /* name */
391 FALSE, /* partial_inplace */
393 0x0000fffc, /* dst_mask */
394 TRUE), /* pcrel_offset */
396 /* A relative 16 bit branch. Bit 10 should be set to indicate that
397 the branch is expected to be taken. The lower two bits must be
399 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
403 TRUE, /* pc_relative */
405 complain_overflow_signed, /* complain_on_overflow */
406 ppc64_elf_brtaken_reloc, /* special_function */
407 "R_PPC64_REL14_BRTAKEN", /* name */
408 FALSE, /* partial_inplace */
410 0x0000fffc, /* dst_mask */
411 TRUE), /* pcrel_offset */
413 /* A relative 16 bit branch. Bit 10 should be set to indicate that
414 the branch is not expected to be taken. The lower two bits must
416 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
418 2, /* size (0 = byte, 1 = short, 2 = long) */
420 TRUE, /* pc_relative */
422 complain_overflow_signed, /* complain_on_overflow */
423 ppc64_elf_brtaken_reloc, /* special_function */
424 "R_PPC64_REL14_BRNTAKEN",/* name */
425 FALSE, /* partial_inplace */
427 0x0000fffc, /* dst_mask */
428 TRUE), /* pcrel_offset */
430 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
432 HOWTO (R_PPC64_GOT16, /* type */
434 1, /* size (0 = byte, 1 = short, 2 = long) */
436 FALSE, /* pc_relative */
438 complain_overflow_signed, /* complain_on_overflow */
439 ppc64_elf_unhandled_reloc, /* special_function */
440 "R_PPC64_GOT16", /* name */
441 FALSE, /* partial_inplace */
443 0xffff, /* dst_mask */
444 FALSE), /* pcrel_offset */
446 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
448 HOWTO (R_PPC64_GOT16_LO, /* type */
450 1, /* size (0 = byte, 1 = short, 2 = long) */
452 FALSE, /* pc_relative */
454 complain_overflow_dont, /* complain_on_overflow */
455 ppc64_elf_unhandled_reloc, /* special_function */
456 "R_PPC64_GOT16_LO", /* name */
457 FALSE, /* partial_inplace */
459 0xffff, /* dst_mask */
460 FALSE), /* pcrel_offset */
462 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
464 HOWTO (R_PPC64_GOT16_HI, /* type */
466 1, /* size (0 = byte, 1 = short, 2 = long) */
468 FALSE, /* pc_relative */
470 complain_overflow_dont,/* complain_on_overflow */
471 ppc64_elf_unhandled_reloc, /* special_function */
472 "R_PPC64_GOT16_HI", /* name */
473 FALSE, /* partial_inplace */
475 0xffff, /* dst_mask */
476 FALSE), /* pcrel_offset */
478 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
480 HOWTO (R_PPC64_GOT16_HA, /* type */
482 1, /* size (0 = byte, 1 = short, 2 = long) */
484 FALSE, /* pc_relative */
486 complain_overflow_dont,/* complain_on_overflow */
487 ppc64_elf_unhandled_reloc, /* special_function */
488 "R_PPC64_GOT16_HA", /* name */
489 FALSE, /* partial_inplace */
491 0xffff, /* dst_mask */
492 FALSE), /* pcrel_offset */
494 /* This is used only by the dynamic linker. The symbol should exist
495 both in the object being run and in some shared library. The
496 dynamic linker copies the data addressed by the symbol from the
497 shared library into the object, because the object being
498 run has to have the data at some particular address. */
499 HOWTO (R_PPC64_COPY, /* type */
501 0, /* this one is variable size */
503 FALSE, /* pc_relative */
505 complain_overflow_dont, /* complain_on_overflow */
506 ppc64_elf_unhandled_reloc, /* special_function */
507 "R_PPC64_COPY", /* name */
508 FALSE, /* partial_inplace */
511 FALSE), /* pcrel_offset */
513 /* Like R_PPC64_ADDR64, but used when setting global offset table
515 HOWTO (R_PPC64_GLOB_DAT, /* type */
517 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
519 FALSE, /* pc_relative */
521 complain_overflow_dont, /* complain_on_overflow */
522 ppc64_elf_unhandled_reloc, /* special_function */
523 "R_PPC64_GLOB_DAT", /* name */
524 FALSE, /* partial_inplace */
526 ONES (64), /* dst_mask */
527 FALSE), /* pcrel_offset */
529 /* Created by the link editor. Marks a procedure linkage table
530 entry for a symbol. */
531 HOWTO (R_PPC64_JMP_SLOT, /* type */
533 0, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE, /* pc_relative */
537 complain_overflow_dont, /* complain_on_overflow */
538 ppc64_elf_unhandled_reloc, /* special_function */
539 "R_PPC64_JMP_SLOT", /* name */
540 FALSE, /* partial_inplace */
543 FALSE), /* pcrel_offset */
545 /* Used only by the dynamic linker. When the object is run, this
546 doubleword64 is set to the load address of the object, plus the
548 HOWTO (R_PPC64_RELATIVE, /* type */
550 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
552 FALSE, /* pc_relative */
554 complain_overflow_dont, /* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 "R_PPC64_RELATIVE", /* name */
557 FALSE, /* partial_inplace */
559 ONES (64), /* dst_mask */
560 FALSE), /* pcrel_offset */
562 /* Like R_PPC64_ADDR32, but may be unaligned. */
563 HOWTO (R_PPC64_UADDR32, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE, /* pc_relative */
569 complain_overflow_bitfield, /* complain_on_overflow */
570 bfd_elf_generic_reloc, /* special_function */
571 "R_PPC64_UADDR32", /* name */
572 FALSE, /* partial_inplace */
574 0xffffffff, /* dst_mask */
575 FALSE), /* pcrel_offset */
577 /* Like R_PPC64_ADDR16, but may be unaligned. */
578 HOWTO (R_PPC64_UADDR16, /* type */
580 1, /* size (0 = byte, 1 = short, 2 = long) */
582 FALSE, /* pc_relative */
584 complain_overflow_bitfield, /* complain_on_overflow */
585 bfd_elf_generic_reloc, /* special_function */
586 "R_PPC64_UADDR16", /* name */
587 FALSE, /* partial_inplace */
589 0xffff, /* dst_mask */
590 FALSE), /* pcrel_offset */
592 /* 32-bit PC relative. */
593 HOWTO (R_PPC64_REL32, /* type */
595 2, /* size (0 = byte, 1 = short, 2 = long) */
597 TRUE, /* pc_relative */
599 /* FIXME: Verify. Was complain_overflow_bitfield. */
600 complain_overflow_signed, /* complain_on_overflow */
601 bfd_elf_generic_reloc, /* special_function */
602 "R_PPC64_REL32", /* name */
603 FALSE, /* partial_inplace */
605 0xffffffff, /* dst_mask */
606 TRUE), /* pcrel_offset */
608 /* 32-bit relocation to the symbol's procedure linkage table. */
609 HOWTO (R_PPC64_PLT32, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 FALSE, /* pc_relative */
615 complain_overflow_bitfield, /* complain_on_overflow */
616 ppc64_elf_unhandled_reloc, /* special_function */
617 "R_PPC64_PLT32", /* name */
618 FALSE, /* partial_inplace */
620 0xffffffff, /* dst_mask */
621 FALSE), /* pcrel_offset */
623 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
624 FIXME: R_PPC64_PLTREL32 not supported. */
625 HOWTO (R_PPC64_PLTREL32, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 TRUE, /* pc_relative */
631 complain_overflow_signed, /* complain_on_overflow */
632 bfd_elf_generic_reloc, /* special_function */
633 "R_PPC64_PLTREL32", /* name */
634 FALSE, /* partial_inplace */
636 0xffffffff, /* dst_mask */
637 TRUE), /* pcrel_offset */
639 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
641 HOWTO (R_PPC64_PLT16_LO, /* type */
643 1, /* size (0 = byte, 1 = short, 2 = long) */
645 FALSE, /* pc_relative */
647 complain_overflow_dont, /* complain_on_overflow */
648 ppc64_elf_unhandled_reloc, /* special_function */
649 "R_PPC64_PLT16_LO", /* name */
650 FALSE, /* partial_inplace */
652 0xffff, /* dst_mask */
653 FALSE), /* pcrel_offset */
655 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
657 HOWTO (R_PPC64_PLT16_HI, /* type */
659 1, /* size (0 = byte, 1 = short, 2 = long) */
661 FALSE, /* pc_relative */
663 complain_overflow_dont, /* complain_on_overflow */
664 ppc64_elf_unhandled_reloc, /* special_function */
665 "R_PPC64_PLT16_HI", /* name */
666 FALSE, /* partial_inplace */
668 0xffff, /* dst_mask */
669 FALSE), /* pcrel_offset */
671 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
673 HOWTO (R_PPC64_PLT16_HA, /* type */
675 1, /* size (0 = byte, 1 = short, 2 = long) */
677 FALSE, /* pc_relative */
679 complain_overflow_dont, /* complain_on_overflow */
680 ppc64_elf_unhandled_reloc, /* special_function */
681 "R_PPC64_PLT16_HA", /* name */
682 FALSE, /* partial_inplace */
684 0xffff, /* dst_mask */
685 FALSE), /* pcrel_offset */
687 /* 16-bit section relative relocation. */
688 HOWTO (R_PPC64_SECTOFF, /* type */
690 1, /* size (0 = byte, 1 = short, 2 = long) */
692 FALSE, /* pc_relative */
694 complain_overflow_bitfield, /* complain_on_overflow */
695 ppc64_elf_sectoff_reloc, /* special_function */
696 "R_PPC64_SECTOFF", /* name */
697 FALSE, /* partial_inplace */
699 0xffff, /* dst_mask */
700 FALSE), /* pcrel_offset */
702 /* Like R_PPC64_SECTOFF, but no overflow warning. */
703 HOWTO (R_PPC64_SECTOFF_LO, /* type */
705 1, /* size (0 = byte, 1 = short, 2 = long) */
707 FALSE, /* pc_relative */
709 complain_overflow_dont, /* complain_on_overflow */
710 ppc64_elf_sectoff_reloc, /* special_function */
711 "R_PPC64_SECTOFF_LO", /* name */
712 FALSE, /* partial_inplace */
714 0xffff, /* dst_mask */
715 FALSE), /* pcrel_offset */
717 /* 16-bit upper half section relative relocation. */
718 HOWTO (R_PPC64_SECTOFF_HI, /* type */
720 1, /* size (0 = byte, 1 = short, 2 = long) */
722 FALSE, /* pc_relative */
724 complain_overflow_dont, /* complain_on_overflow */
725 ppc64_elf_sectoff_reloc, /* special_function */
726 "R_PPC64_SECTOFF_HI", /* name */
727 FALSE, /* partial_inplace */
729 0xffff, /* dst_mask */
730 FALSE), /* pcrel_offset */
732 /* 16-bit upper half adjusted section relative relocation. */
733 HOWTO (R_PPC64_SECTOFF_HA, /* type */
735 1, /* size (0 = byte, 1 = short, 2 = long) */
737 FALSE, /* pc_relative */
739 complain_overflow_dont, /* complain_on_overflow */
740 ppc64_elf_sectoff_ha_reloc, /* special_function */
741 "R_PPC64_SECTOFF_HA", /* name */
742 FALSE, /* partial_inplace */
744 0xffff, /* dst_mask */
745 FALSE), /* pcrel_offset */
747 /* Like R_PPC64_REL24 without touching the two least significant bits. */
748 HOWTO (R_PPC64_REL30, /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 TRUE, /* pc_relative */
754 complain_overflow_dont, /* complain_on_overflow */
755 bfd_elf_generic_reloc, /* special_function */
756 "R_PPC64_REL30", /* name */
757 FALSE, /* partial_inplace */
759 0xfffffffc, /* dst_mask */
760 TRUE), /* pcrel_offset */
762 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
764 /* A standard 64-bit relocation. */
765 HOWTO (R_PPC64_ADDR64, /* type */
767 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
769 FALSE, /* pc_relative */
771 complain_overflow_dont, /* complain_on_overflow */
772 bfd_elf_generic_reloc, /* special_function */
773 "R_PPC64_ADDR64", /* name */
774 FALSE, /* partial_inplace */
776 ONES (64), /* dst_mask */
777 FALSE), /* pcrel_offset */
779 /* The bits 32-47 of an address. */
780 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
782 1, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE, /* pc_relative */
786 complain_overflow_dont, /* complain_on_overflow */
787 bfd_elf_generic_reloc, /* special_function */
788 "R_PPC64_ADDR16_HIGHER", /* name */
789 FALSE, /* partial_inplace */
791 0xffff, /* dst_mask */
792 FALSE), /* pcrel_offset */
794 /* The bits 32-47 of an address, plus 1 if the contents of the low
795 16 bits, treated as a signed number, is negative. */
796 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
798 1, /* size (0 = byte, 1 = short, 2 = long) */
800 FALSE, /* pc_relative */
802 complain_overflow_dont, /* complain_on_overflow */
803 ppc64_elf_ha_reloc, /* special_function */
804 "R_PPC64_ADDR16_HIGHERA", /* name */
805 FALSE, /* partial_inplace */
807 0xffff, /* dst_mask */
808 FALSE), /* pcrel_offset */
810 /* The bits 48-63 of an address. */
811 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE, /* pc_relative */
817 complain_overflow_dont, /* complain_on_overflow */
818 bfd_elf_generic_reloc, /* special_function */
819 "R_PPC64_ADDR16_HIGHEST", /* name */
820 FALSE, /* partial_inplace */
822 0xffff, /* dst_mask */
823 FALSE), /* pcrel_offset */
825 /* The bits 48-63 of an address, plus 1 if the contents of the low
826 16 bits, treated as a signed number, is negative. */
827 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
829 1, /* size (0 = byte, 1 = short, 2 = long) */
831 FALSE, /* pc_relative */
833 complain_overflow_dont, /* complain_on_overflow */
834 ppc64_elf_ha_reloc, /* special_function */
835 "R_PPC64_ADDR16_HIGHESTA", /* name */
836 FALSE, /* partial_inplace */
838 0xffff, /* dst_mask */
839 FALSE), /* pcrel_offset */
841 /* Like ADDR64, but may be unaligned. */
842 HOWTO (R_PPC64_UADDR64, /* type */
844 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
846 FALSE, /* pc_relative */
848 complain_overflow_dont, /* complain_on_overflow */
849 bfd_elf_generic_reloc, /* special_function */
850 "R_PPC64_UADDR64", /* name */
851 FALSE, /* partial_inplace */
853 ONES (64), /* dst_mask */
854 FALSE), /* pcrel_offset */
856 /* 64-bit relative relocation. */
857 HOWTO (R_PPC64_REL64, /* type */
859 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
861 TRUE, /* pc_relative */
863 complain_overflow_dont, /* complain_on_overflow */
864 bfd_elf_generic_reloc, /* special_function */
865 "R_PPC64_REL64", /* name */
866 FALSE, /* partial_inplace */
868 ONES (64), /* dst_mask */
869 TRUE), /* pcrel_offset */
871 /* 64-bit relocation to the symbol's procedure linkage table. */
872 HOWTO (R_PPC64_PLT64, /* type */
874 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
876 FALSE, /* pc_relative */
878 complain_overflow_dont, /* complain_on_overflow */
879 ppc64_elf_unhandled_reloc, /* special_function */
880 "R_PPC64_PLT64", /* name */
881 FALSE, /* partial_inplace */
883 ONES (64), /* dst_mask */
884 FALSE), /* pcrel_offset */
886 /* 64-bit PC relative relocation to the symbol's procedure linkage
888 /* FIXME: R_PPC64_PLTREL64 not supported. */
889 HOWTO (R_PPC64_PLTREL64, /* type */
891 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
893 TRUE, /* pc_relative */
895 complain_overflow_dont, /* complain_on_overflow */
896 ppc64_elf_unhandled_reloc, /* special_function */
897 "R_PPC64_PLTREL64", /* name */
898 FALSE, /* partial_inplace */
900 ONES (64), /* dst_mask */
901 TRUE), /* pcrel_offset */
903 /* 16 bit TOC-relative relocation. */
905 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
906 HOWTO (R_PPC64_TOC16, /* type */
908 1, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE, /* pc_relative */
912 complain_overflow_signed, /* complain_on_overflow */
913 ppc64_elf_toc_reloc, /* special_function */
914 "R_PPC64_TOC16", /* name */
915 FALSE, /* partial_inplace */
917 0xffff, /* dst_mask */
918 FALSE), /* pcrel_offset */
920 /* 16 bit TOC-relative relocation without overflow. */
922 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
923 HOWTO (R_PPC64_TOC16_LO, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE, /* pc_relative */
929 complain_overflow_dont, /* complain_on_overflow */
930 ppc64_elf_toc_reloc, /* special_function */
931 "R_PPC64_TOC16_LO", /* name */
932 FALSE, /* partial_inplace */
934 0xffff, /* dst_mask */
935 FALSE), /* pcrel_offset */
937 /* 16 bit TOC-relative relocation, high 16 bits. */
939 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
940 HOWTO (R_PPC64_TOC16_HI, /* 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_reloc, /* special_function */
948 "R_PPC64_TOC16_HI", /* name */
949 FALSE, /* partial_inplace */
951 0xffff, /* dst_mask */
952 FALSE), /* pcrel_offset */
954 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
955 contents of the low 16 bits, treated as a signed number, is
958 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
959 HOWTO (R_PPC64_TOC16_HA, /* type */
961 1, /* size (0 = byte, 1 = short, 2 = long) */
963 FALSE, /* pc_relative */
965 complain_overflow_dont, /* complain_on_overflow */
966 ppc64_elf_toc_ha_reloc, /* special_function */
967 "R_PPC64_TOC16_HA", /* name */
968 FALSE, /* partial_inplace */
970 0xffff, /* dst_mask */
971 FALSE), /* pcrel_offset */
973 /* 64-bit relocation; insert value of TOC base (.TOC.). */
975 /* R_PPC64_TOC 51 doubleword64 .TOC. */
976 HOWTO (R_PPC64_TOC, /* type */
978 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
980 FALSE, /* pc_relative */
982 complain_overflow_bitfield, /* complain_on_overflow */
983 ppc64_elf_toc64_reloc, /* special_function */
984 "R_PPC64_TOC", /* name */
985 FALSE, /* partial_inplace */
987 ONES (64), /* dst_mask */
988 FALSE), /* pcrel_offset */
990 /* Like R_PPC64_GOT16, but also informs the link editor that the
991 value to relocate may (!) refer to a PLT entry which the link
992 editor (a) may replace with the symbol value. If the link editor
993 is unable to fully resolve the symbol, it may (b) create a PLT
994 entry and store the address to the new PLT entry in the GOT.
995 This permits lazy resolution of function symbols at run time.
996 The link editor may also skip all of this and just (c) emit a
997 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
998 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
999 HOWTO (R_PPC64_PLTGOT16, /* type */
1001 1, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE, /* pc_relative */
1005 complain_overflow_signed, /* complain_on_overflow */
1006 ppc64_elf_unhandled_reloc, /* special_function */
1007 "R_PPC64_PLTGOT16", /* name */
1008 FALSE, /* partial_inplace */
1010 0xffff, /* dst_mask */
1011 FALSE), /* pcrel_offset */
1013 /* Like R_PPC64_PLTGOT16, but without overflow. */
1014 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1015 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
1017 1, /* size (0 = byte, 1 = short, 2 = long) */
1019 FALSE, /* pc_relative */
1021 complain_overflow_dont, /* complain_on_overflow */
1022 ppc64_elf_unhandled_reloc, /* special_function */
1023 "R_PPC64_PLTGOT16_LO", /* name */
1024 FALSE, /* partial_inplace */
1026 0xffff, /* dst_mask */
1027 FALSE), /* pcrel_offset */
1029 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1030 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1031 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
1032 16, /* rightshift */
1033 1, /* size (0 = byte, 1 = short, 2 = long) */
1035 FALSE, /* pc_relative */
1037 complain_overflow_dont, /* complain_on_overflow */
1038 ppc64_elf_unhandled_reloc, /* special_function */
1039 "R_PPC64_PLTGOT16_HI", /* name */
1040 FALSE, /* partial_inplace */
1042 0xffff, /* dst_mask */
1043 FALSE), /* pcrel_offset */
1045 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1046 1 if the contents of the low 16 bits, treated as a signed number,
1048 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1049 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1050 16, /* rightshift */
1051 1, /* size (0 = byte, 1 = short, 2 = long) */
1053 FALSE, /* pc_relative */
1055 complain_overflow_dont,/* complain_on_overflow */
1056 ppc64_elf_unhandled_reloc, /* special_function */
1057 "R_PPC64_PLTGOT16_HA", /* name */
1058 FALSE, /* partial_inplace */
1060 0xffff, /* dst_mask */
1061 FALSE), /* pcrel_offset */
1063 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1064 HOWTO (R_PPC64_ADDR16_DS, /* type */
1066 1, /* size (0 = byte, 1 = short, 2 = long) */
1068 FALSE, /* pc_relative */
1070 complain_overflow_bitfield, /* complain_on_overflow */
1071 bfd_elf_generic_reloc, /* special_function */
1072 "R_PPC64_ADDR16_DS", /* name */
1073 FALSE, /* partial_inplace */
1075 0xfffc, /* dst_mask */
1076 FALSE), /* pcrel_offset */
1078 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1079 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1081 1, /* size (0 = byte, 1 = short, 2 = long) */
1083 FALSE, /* pc_relative */
1085 complain_overflow_dont,/* complain_on_overflow */
1086 bfd_elf_generic_reloc, /* special_function */
1087 "R_PPC64_ADDR16_LO_DS",/* name */
1088 FALSE, /* partial_inplace */
1090 0xfffc, /* dst_mask */
1091 FALSE), /* pcrel_offset */
1093 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1094 HOWTO (R_PPC64_GOT16_DS, /* type */
1096 1, /* size (0 = byte, 1 = short, 2 = long) */
1098 FALSE, /* pc_relative */
1100 complain_overflow_signed, /* complain_on_overflow */
1101 ppc64_elf_unhandled_reloc, /* special_function */
1102 "R_PPC64_GOT16_DS", /* name */
1103 FALSE, /* partial_inplace */
1105 0xfffc, /* dst_mask */
1106 FALSE), /* pcrel_offset */
1108 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1109 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1111 1, /* size (0 = byte, 1 = short, 2 = long) */
1113 FALSE, /* pc_relative */
1115 complain_overflow_dont, /* complain_on_overflow */
1116 ppc64_elf_unhandled_reloc, /* special_function */
1117 "R_PPC64_GOT16_LO_DS", /* name */
1118 FALSE, /* partial_inplace */
1120 0xfffc, /* dst_mask */
1121 FALSE), /* pcrel_offset */
1123 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1124 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1126 1, /* size (0 = byte, 1 = short, 2 = long) */
1128 FALSE, /* pc_relative */
1130 complain_overflow_dont, /* complain_on_overflow */
1131 ppc64_elf_unhandled_reloc, /* special_function */
1132 "R_PPC64_PLT16_LO_DS", /* name */
1133 FALSE, /* partial_inplace */
1135 0xfffc, /* dst_mask */
1136 FALSE), /* pcrel_offset */
1138 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1139 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1141 1, /* size (0 = byte, 1 = short, 2 = long) */
1143 FALSE, /* pc_relative */
1145 complain_overflow_bitfield, /* complain_on_overflow */
1146 ppc64_elf_sectoff_reloc, /* special_function */
1147 "R_PPC64_SECTOFF_DS", /* name */
1148 FALSE, /* partial_inplace */
1150 0xfffc, /* dst_mask */
1151 FALSE), /* pcrel_offset */
1153 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1154 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1156 1, /* size (0 = byte, 1 = short, 2 = long) */
1158 FALSE, /* pc_relative */
1160 complain_overflow_dont, /* complain_on_overflow */
1161 ppc64_elf_sectoff_reloc, /* special_function */
1162 "R_PPC64_SECTOFF_LO_DS",/* name */
1163 FALSE, /* partial_inplace */
1165 0xfffc, /* dst_mask */
1166 FALSE), /* pcrel_offset */
1168 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1169 HOWTO (R_PPC64_TOC16_DS, /* type */
1171 1, /* size (0 = byte, 1 = short, 2 = long) */
1173 FALSE, /* pc_relative */
1175 complain_overflow_signed, /* complain_on_overflow */
1176 ppc64_elf_toc_reloc, /* special_function */
1177 "R_PPC64_TOC16_DS", /* name */
1178 FALSE, /* partial_inplace */
1180 0xfffc, /* dst_mask */
1181 FALSE), /* pcrel_offset */
1183 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1184 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1186 1, /* size (0 = byte, 1 = short, 2 = long) */
1188 FALSE, /* pc_relative */
1190 complain_overflow_dont, /* complain_on_overflow */
1191 ppc64_elf_toc_reloc, /* special_function */
1192 "R_PPC64_TOC16_LO_DS", /* name */
1193 FALSE, /* partial_inplace */
1195 0xfffc, /* dst_mask */
1196 FALSE), /* pcrel_offset */
1198 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1199 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1200 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1202 1, /* size (0 = byte, 1 = short, 2 = long) */
1204 FALSE, /* pc_relative */
1206 complain_overflow_signed, /* complain_on_overflow */
1207 ppc64_elf_unhandled_reloc, /* special_function */
1208 "R_PPC64_PLTGOT16_DS", /* name */
1209 FALSE, /* partial_inplace */
1211 0xfffc, /* dst_mask */
1212 FALSE), /* pcrel_offset */
1214 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1215 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1216 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1218 1, /* size (0 = byte, 1 = short, 2 = long) */
1220 FALSE, /* pc_relative */
1222 complain_overflow_dont, /* complain_on_overflow */
1223 ppc64_elf_unhandled_reloc, /* special_function */
1224 "R_PPC64_PLTGOT16_LO_DS",/* name */
1225 FALSE, /* partial_inplace */
1227 0xfffc, /* dst_mask */
1228 FALSE), /* pcrel_offset */
1230 /* Marker reloc for TLS. */
1233 2, /* size (0 = byte, 1 = short, 2 = long) */
1235 FALSE, /* pc_relative */
1237 complain_overflow_dont, /* complain_on_overflow */
1238 bfd_elf_generic_reloc, /* special_function */
1239 "R_PPC64_TLS", /* name */
1240 FALSE, /* partial_inplace */
1243 FALSE), /* pcrel_offset */
1245 /* Computes the load module index of the load module that contains the
1246 definition of its TLS sym. */
1247 HOWTO (R_PPC64_DTPMOD64,
1249 4, /* size (0 = byte, 1 = short, 2 = long) */
1251 FALSE, /* pc_relative */
1253 complain_overflow_dont, /* complain_on_overflow */
1254 ppc64_elf_unhandled_reloc, /* special_function */
1255 "R_PPC64_DTPMOD64", /* name */
1256 FALSE, /* partial_inplace */
1258 ONES (64), /* dst_mask */
1259 FALSE), /* pcrel_offset */
1261 /* Computes a dtv-relative displacement, the difference between the value
1262 of sym+add and the base address of the thread-local storage block that
1263 contains the definition of sym, minus 0x8000. */
1264 HOWTO (R_PPC64_DTPREL64,
1266 4, /* size (0 = byte, 1 = short, 2 = long) */
1268 FALSE, /* pc_relative */
1270 complain_overflow_dont, /* complain_on_overflow */
1271 ppc64_elf_unhandled_reloc, /* special_function */
1272 "R_PPC64_DTPREL64", /* name */
1273 FALSE, /* partial_inplace */
1275 ONES (64), /* dst_mask */
1276 FALSE), /* pcrel_offset */
1278 /* A 16 bit dtprel reloc. */
1279 HOWTO (R_PPC64_DTPREL16,
1281 1, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE, /* pc_relative */
1285 complain_overflow_signed, /* complain_on_overflow */
1286 ppc64_elf_unhandled_reloc, /* special_function */
1287 "R_PPC64_DTPREL16", /* name */
1288 FALSE, /* partial_inplace */
1290 0xffff, /* dst_mask */
1291 FALSE), /* pcrel_offset */
1293 /* Like DTPREL16, but no overflow. */
1294 HOWTO (R_PPC64_DTPREL16_LO,
1296 1, /* size (0 = byte, 1 = short, 2 = long) */
1298 FALSE, /* pc_relative */
1300 complain_overflow_dont, /* complain_on_overflow */
1301 ppc64_elf_unhandled_reloc, /* special_function */
1302 "R_PPC64_DTPREL16_LO", /* name */
1303 FALSE, /* partial_inplace */
1305 0xffff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1308 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1309 HOWTO (R_PPC64_DTPREL16_HI,
1310 16, /* rightshift */
1311 1, /* size (0 = byte, 1 = short, 2 = long) */
1313 FALSE, /* pc_relative */
1315 complain_overflow_dont, /* complain_on_overflow */
1316 ppc64_elf_unhandled_reloc, /* special_function */
1317 "R_PPC64_DTPREL16_HI", /* name */
1318 FALSE, /* partial_inplace */
1320 0xffff, /* dst_mask */
1321 FALSE), /* pcrel_offset */
1323 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1324 HOWTO (R_PPC64_DTPREL16_HA,
1325 16, /* rightshift */
1326 1, /* size (0 = byte, 1 = short, 2 = long) */
1328 FALSE, /* pc_relative */
1330 complain_overflow_dont, /* complain_on_overflow */
1331 ppc64_elf_unhandled_reloc, /* special_function */
1332 "R_PPC64_DTPREL16_HA", /* name */
1333 FALSE, /* partial_inplace */
1335 0xffff, /* dst_mask */
1336 FALSE), /* pcrel_offset */
1338 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1339 HOWTO (R_PPC64_DTPREL16_HIGHER,
1340 32, /* rightshift */
1341 1, /* size (0 = byte, 1 = short, 2 = long) */
1343 FALSE, /* pc_relative */
1345 complain_overflow_dont, /* complain_on_overflow */
1346 ppc64_elf_unhandled_reloc, /* special_function */
1347 "R_PPC64_DTPREL16_HIGHER", /* name */
1348 FALSE, /* partial_inplace */
1350 0xffff, /* dst_mask */
1351 FALSE), /* pcrel_offset */
1353 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1354 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1355 32, /* rightshift */
1356 1, /* size (0 = byte, 1 = short, 2 = long) */
1358 FALSE, /* pc_relative */
1360 complain_overflow_dont, /* complain_on_overflow */
1361 ppc64_elf_unhandled_reloc, /* special_function */
1362 "R_PPC64_DTPREL16_HIGHERA", /* name */
1363 FALSE, /* partial_inplace */
1365 0xffff, /* dst_mask */
1366 FALSE), /* pcrel_offset */
1368 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1369 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1370 48, /* rightshift */
1371 1, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE, /* pc_relative */
1375 complain_overflow_dont, /* complain_on_overflow */
1376 ppc64_elf_unhandled_reloc, /* special_function */
1377 "R_PPC64_DTPREL16_HIGHEST", /* name */
1378 FALSE, /* partial_inplace */
1380 0xffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1383 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1384 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1385 48, /* rightshift */
1386 1, /* size (0 = byte, 1 = short, 2 = long) */
1388 FALSE, /* pc_relative */
1390 complain_overflow_dont, /* complain_on_overflow */
1391 ppc64_elf_unhandled_reloc, /* special_function */
1392 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1393 FALSE, /* partial_inplace */
1395 0xffff, /* dst_mask */
1396 FALSE), /* pcrel_offset */
1398 /* Like DTPREL16, but for insns with a DS field. */
1399 HOWTO (R_PPC64_DTPREL16_DS,
1401 1, /* size (0 = byte, 1 = short, 2 = long) */
1403 FALSE, /* pc_relative */
1405 complain_overflow_signed, /* complain_on_overflow */
1406 ppc64_elf_unhandled_reloc, /* special_function */
1407 "R_PPC64_DTPREL16_DS", /* name */
1408 FALSE, /* partial_inplace */
1410 0xfffc, /* dst_mask */
1411 FALSE), /* pcrel_offset */
1413 /* Like DTPREL16_DS, but no overflow. */
1414 HOWTO (R_PPC64_DTPREL16_LO_DS,
1416 1, /* size (0 = byte, 1 = short, 2 = long) */
1418 FALSE, /* pc_relative */
1420 complain_overflow_dont, /* complain_on_overflow */
1421 ppc64_elf_unhandled_reloc, /* special_function */
1422 "R_PPC64_DTPREL16_LO_DS", /* name */
1423 FALSE, /* partial_inplace */
1425 0xfffc, /* dst_mask */
1426 FALSE), /* pcrel_offset */
1428 /* Computes a tp-relative displacement, the difference between the value of
1429 sym+add and the value of the thread pointer (r13). */
1430 HOWTO (R_PPC64_TPREL64,
1432 4, /* size (0 = byte, 1 = short, 2 = long) */
1434 FALSE, /* pc_relative */
1436 complain_overflow_dont, /* complain_on_overflow */
1437 ppc64_elf_unhandled_reloc, /* special_function */
1438 "R_PPC64_TPREL64", /* name */
1439 FALSE, /* partial_inplace */
1441 ONES (64), /* dst_mask */
1442 FALSE), /* pcrel_offset */
1444 /* A 16 bit tprel reloc. */
1445 HOWTO (R_PPC64_TPREL16,
1447 1, /* size (0 = byte, 1 = short, 2 = long) */
1449 FALSE, /* pc_relative */
1451 complain_overflow_signed, /* complain_on_overflow */
1452 ppc64_elf_unhandled_reloc, /* special_function */
1453 "R_PPC64_TPREL16", /* name */
1454 FALSE, /* partial_inplace */
1456 0xffff, /* dst_mask */
1457 FALSE), /* pcrel_offset */
1459 /* Like TPREL16, but no overflow. */
1460 HOWTO (R_PPC64_TPREL16_LO,
1462 1, /* size (0 = byte, 1 = short, 2 = long) */
1464 FALSE, /* pc_relative */
1466 complain_overflow_dont, /* complain_on_overflow */
1467 ppc64_elf_unhandled_reloc, /* special_function */
1468 "R_PPC64_TPREL16_LO", /* name */
1469 FALSE, /* partial_inplace */
1471 0xffff, /* dst_mask */
1472 FALSE), /* pcrel_offset */
1474 /* Like TPREL16_LO, but next higher group of 16 bits. */
1475 HOWTO (R_PPC64_TPREL16_HI,
1476 16, /* rightshift */
1477 1, /* size (0 = byte, 1 = short, 2 = long) */
1479 FALSE, /* pc_relative */
1481 complain_overflow_dont, /* complain_on_overflow */
1482 ppc64_elf_unhandled_reloc, /* special_function */
1483 "R_PPC64_TPREL16_HI", /* name */
1484 FALSE, /* partial_inplace */
1486 0xffff, /* dst_mask */
1487 FALSE), /* pcrel_offset */
1489 /* Like TPREL16_HI, but adjust for low 16 bits. */
1490 HOWTO (R_PPC64_TPREL16_HA,
1491 16, /* rightshift */
1492 1, /* size (0 = byte, 1 = short, 2 = long) */
1494 FALSE, /* pc_relative */
1496 complain_overflow_dont, /* complain_on_overflow */
1497 ppc64_elf_unhandled_reloc, /* special_function */
1498 "R_PPC64_TPREL16_HA", /* name */
1499 FALSE, /* partial_inplace */
1501 0xffff, /* dst_mask */
1502 FALSE), /* pcrel_offset */
1504 /* Like TPREL16_HI, but next higher group of 16 bits. */
1505 HOWTO (R_PPC64_TPREL16_HIGHER,
1506 32, /* rightshift */
1507 1, /* size (0 = byte, 1 = short, 2 = long) */
1509 FALSE, /* pc_relative */
1511 complain_overflow_dont, /* complain_on_overflow */
1512 ppc64_elf_unhandled_reloc, /* special_function */
1513 "R_PPC64_TPREL16_HIGHER", /* name */
1514 FALSE, /* partial_inplace */
1516 0xffff, /* dst_mask */
1517 FALSE), /* pcrel_offset */
1519 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1520 HOWTO (R_PPC64_TPREL16_HIGHERA,
1521 32, /* rightshift */
1522 1, /* size (0 = byte, 1 = short, 2 = long) */
1524 FALSE, /* pc_relative */
1526 complain_overflow_dont, /* complain_on_overflow */
1527 ppc64_elf_unhandled_reloc, /* special_function */
1528 "R_PPC64_TPREL16_HIGHERA", /* name */
1529 FALSE, /* partial_inplace */
1531 0xffff, /* dst_mask */
1532 FALSE), /* pcrel_offset */
1534 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1535 HOWTO (R_PPC64_TPREL16_HIGHEST,
1536 48, /* rightshift */
1537 1, /* size (0 = byte, 1 = short, 2 = long) */
1539 FALSE, /* pc_relative */
1541 complain_overflow_dont, /* complain_on_overflow */
1542 ppc64_elf_unhandled_reloc, /* special_function */
1543 "R_PPC64_TPREL16_HIGHEST", /* name */
1544 FALSE, /* partial_inplace */
1546 0xffff, /* dst_mask */
1547 FALSE), /* pcrel_offset */
1549 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1550 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1551 48, /* rightshift */
1552 1, /* size (0 = byte, 1 = short, 2 = long) */
1554 FALSE, /* pc_relative */
1556 complain_overflow_dont, /* complain_on_overflow */
1557 ppc64_elf_unhandled_reloc, /* special_function */
1558 "R_PPC64_TPREL16_HIGHESTA", /* name */
1559 FALSE, /* partial_inplace */
1561 0xffff, /* dst_mask */
1562 FALSE), /* pcrel_offset */
1564 /* Like TPREL16, but for insns with a DS field. */
1565 HOWTO (R_PPC64_TPREL16_DS,
1567 1, /* size (0 = byte, 1 = short, 2 = long) */
1569 FALSE, /* pc_relative */
1571 complain_overflow_signed, /* complain_on_overflow */
1572 ppc64_elf_unhandled_reloc, /* special_function */
1573 "R_PPC64_TPREL16_DS", /* name */
1574 FALSE, /* partial_inplace */
1576 0xfffc, /* dst_mask */
1577 FALSE), /* pcrel_offset */
1579 /* Like TPREL16_DS, but no overflow. */
1580 HOWTO (R_PPC64_TPREL16_LO_DS,
1582 1, /* size (0 = byte, 1 = short, 2 = long) */
1584 FALSE, /* pc_relative */
1586 complain_overflow_dont, /* complain_on_overflow */
1587 ppc64_elf_unhandled_reloc, /* special_function */
1588 "R_PPC64_TPREL16_LO_DS", /* name */
1589 FALSE, /* partial_inplace */
1591 0xfffc, /* dst_mask */
1592 FALSE), /* pcrel_offset */
1594 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1595 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1596 to the first entry relative to the TOC base (r2). */
1597 HOWTO (R_PPC64_GOT_TLSGD16,
1599 1, /* size (0 = byte, 1 = short, 2 = long) */
1601 FALSE, /* pc_relative */
1603 complain_overflow_signed, /* complain_on_overflow */
1604 ppc64_elf_unhandled_reloc, /* special_function */
1605 "R_PPC64_GOT_TLSGD16", /* name */
1606 FALSE, /* partial_inplace */
1608 0xffff, /* dst_mask */
1609 FALSE), /* pcrel_offset */
1611 /* Like GOT_TLSGD16, but no overflow. */
1612 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1614 1, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE, /* pc_relative */
1618 complain_overflow_dont, /* complain_on_overflow */
1619 ppc64_elf_unhandled_reloc, /* special_function */
1620 "R_PPC64_GOT_TLSGD16_LO", /* name */
1621 FALSE, /* partial_inplace */
1623 0xffff, /* dst_mask */
1624 FALSE), /* pcrel_offset */
1626 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1627 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1628 16, /* rightshift */
1629 1, /* size (0 = byte, 1 = short, 2 = long) */
1631 FALSE, /* pc_relative */
1633 complain_overflow_dont, /* complain_on_overflow */
1634 ppc64_elf_unhandled_reloc, /* special_function */
1635 "R_PPC64_GOT_TLSGD16_HI", /* name */
1636 FALSE, /* partial_inplace */
1638 0xffff, /* dst_mask */
1639 FALSE), /* pcrel_offset */
1641 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1642 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1643 16, /* rightshift */
1644 1, /* size (0 = byte, 1 = short, 2 = long) */
1646 FALSE, /* pc_relative */
1648 complain_overflow_dont, /* complain_on_overflow */
1649 ppc64_elf_unhandled_reloc, /* special_function */
1650 "R_PPC64_GOT_TLSGD16_HA", /* name */
1651 FALSE, /* partial_inplace */
1653 0xffff, /* dst_mask */
1654 FALSE), /* pcrel_offset */
1656 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1657 with values (sym+add)@dtpmod and zero, and computes the offset to the
1658 first entry relative to the TOC base (r2). */
1659 HOWTO (R_PPC64_GOT_TLSLD16,
1661 1, /* size (0 = byte, 1 = short, 2 = long) */
1663 FALSE, /* pc_relative */
1665 complain_overflow_signed, /* complain_on_overflow */
1666 ppc64_elf_unhandled_reloc, /* special_function */
1667 "R_PPC64_GOT_TLSLD16", /* name */
1668 FALSE, /* partial_inplace */
1670 0xffff, /* dst_mask */
1671 FALSE), /* pcrel_offset */
1673 /* Like GOT_TLSLD16, but no overflow. */
1674 HOWTO (R_PPC64_GOT_TLSLD16_LO,
1676 1, /* size (0 = byte, 1 = short, 2 = long) */
1678 FALSE, /* pc_relative */
1680 complain_overflow_dont, /* complain_on_overflow */
1681 ppc64_elf_unhandled_reloc, /* special_function */
1682 "R_PPC64_GOT_TLSLD16_LO", /* name */
1683 FALSE, /* partial_inplace */
1685 0xffff, /* dst_mask */
1686 FALSE), /* pcrel_offset */
1688 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1689 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1690 16, /* rightshift */
1691 1, /* size (0 = byte, 1 = short, 2 = long) */
1693 FALSE, /* pc_relative */
1695 complain_overflow_dont, /* complain_on_overflow */
1696 ppc64_elf_unhandled_reloc, /* special_function */
1697 "R_PPC64_GOT_TLSLD16_HI", /* name */
1698 FALSE, /* partial_inplace */
1700 0xffff, /* dst_mask */
1701 FALSE), /* pcrel_offset */
1703 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1704 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1705 16, /* rightshift */
1706 1, /* size (0 = byte, 1 = short, 2 = long) */
1708 FALSE, /* pc_relative */
1710 complain_overflow_dont, /* complain_on_overflow */
1711 ppc64_elf_unhandled_reloc, /* special_function */
1712 "R_PPC64_GOT_TLSLD16_HA", /* name */
1713 FALSE, /* partial_inplace */
1715 0xffff, /* dst_mask */
1716 FALSE), /* pcrel_offset */
1718 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1719 the offset to the entry relative to the TOC base (r2). */
1720 HOWTO (R_PPC64_GOT_DTPREL16_DS,
1722 1, /* size (0 = byte, 1 = short, 2 = long) */
1724 FALSE, /* pc_relative */
1726 complain_overflow_signed, /* complain_on_overflow */
1727 ppc64_elf_unhandled_reloc, /* special_function */
1728 "R_PPC64_GOT_DTPREL16_DS", /* name */
1729 FALSE, /* partial_inplace */
1731 0xfffc, /* dst_mask */
1732 FALSE), /* pcrel_offset */
1734 /* Like GOT_DTPREL16_DS, but no overflow. */
1735 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
1737 1, /* size (0 = byte, 1 = short, 2 = long) */
1739 FALSE, /* pc_relative */
1741 complain_overflow_dont, /* complain_on_overflow */
1742 ppc64_elf_unhandled_reloc, /* special_function */
1743 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1744 FALSE, /* partial_inplace */
1746 0xfffc, /* dst_mask */
1747 FALSE), /* pcrel_offset */
1749 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1750 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1751 16, /* rightshift */
1752 1, /* size (0 = byte, 1 = short, 2 = long) */
1754 FALSE, /* pc_relative */
1756 complain_overflow_dont, /* complain_on_overflow */
1757 ppc64_elf_unhandled_reloc, /* special_function */
1758 "R_PPC64_GOT_DTPREL16_HI", /* name */
1759 FALSE, /* partial_inplace */
1761 0xffff, /* dst_mask */
1762 FALSE), /* pcrel_offset */
1764 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1765 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1766 16, /* rightshift */
1767 1, /* size (0 = byte, 1 = short, 2 = long) */
1769 FALSE, /* pc_relative */
1771 complain_overflow_dont, /* complain_on_overflow */
1772 ppc64_elf_unhandled_reloc, /* special_function */
1773 "R_PPC64_GOT_DTPREL16_HA", /* name */
1774 FALSE, /* partial_inplace */
1776 0xffff, /* dst_mask */
1777 FALSE), /* pcrel_offset */
1779 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1780 offset to the entry relative to the TOC base (r2). */
1781 HOWTO (R_PPC64_GOT_TPREL16_DS,
1783 1, /* size (0 = byte, 1 = short, 2 = long) */
1785 FALSE, /* pc_relative */
1787 complain_overflow_signed, /* complain_on_overflow */
1788 ppc64_elf_unhandled_reloc, /* special_function */
1789 "R_PPC64_GOT_TPREL16_DS", /* name */
1790 FALSE, /* partial_inplace */
1792 0xfffc, /* dst_mask */
1793 FALSE), /* pcrel_offset */
1795 /* Like GOT_TPREL16_DS, but no overflow. */
1796 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1798 1, /* size (0 = byte, 1 = short, 2 = long) */
1800 FALSE, /* pc_relative */
1802 complain_overflow_dont, /* complain_on_overflow */
1803 ppc64_elf_unhandled_reloc, /* special_function */
1804 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1805 FALSE, /* partial_inplace */
1807 0xfffc, /* dst_mask */
1808 FALSE), /* pcrel_offset */
1810 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1811 HOWTO (R_PPC64_GOT_TPREL16_HI,
1812 16, /* rightshift */
1813 1, /* size (0 = byte, 1 = short, 2 = long) */
1815 FALSE, /* pc_relative */
1817 complain_overflow_dont, /* complain_on_overflow */
1818 ppc64_elf_unhandled_reloc, /* special_function */
1819 "R_PPC64_GOT_TPREL16_HI", /* name */
1820 FALSE, /* partial_inplace */
1822 0xffff, /* dst_mask */
1823 FALSE), /* pcrel_offset */
1825 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1826 HOWTO (R_PPC64_GOT_TPREL16_HA,
1827 16, /* rightshift */
1828 1, /* size (0 = byte, 1 = short, 2 = long) */
1830 FALSE, /* pc_relative */
1832 complain_overflow_dont, /* complain_on_overflow */
1833 ppc64_elf_unhandled_reloc, /* special_function */
1834 "R_PPC64_GOT_TPREL16_HA", /* name */
1835 FALSE, /* partial_inplace */
1837 0xffff, /* dst_mask */
1838 FALSE), /* pcrel_offset */
1840 /* GNU extension to record C++ vtable hierarchy. */
1841 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1843 0, /* size (0 = byte, 1 = short, 2 = long) */
1845 FALSE, /* pc_relative */
1847 complain_overflow_dont, /* complain_on_overflow */
1848 NULL, /* special_function */
1849 "R_PPC64_GNU_VTINHERIT", /* name */
1850 FALSE, /* partial_inplace */
1853 FALSE), /* pcrel_offset */
1855 /* GNU extension to record C++ vtable member usage. */
1856 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1858 0, /* size (0 = byte, 1 = short, 2 = long) */
1860 FALSE, /* pc_relative */
1862 complain_overflow_dont, /* complain_on_overflow */
1863 NULL, /* special_function */
1864 "R_PPC64_GNU_VTENTRY", /* name */
1865 FALSE, /* partial_inplace */
1868 FALSE), /* pcrel_offset */
1872 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1876 ppc_howto_init (void)
1878 unsigned int i, type;
1881 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1884 type = ppc64_elf_howto_raw[i].type;
1885 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1886 / sizeof (ppc64_elf_howto_table[0])));
1887 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1891 static reloc_howto_type *
1892 ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1893 bfd_reloc_code_real_type code)
1895 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
1897 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1898 /* Initialize howto table if needed. */
1906 case BFD_RELOC_NONE: r = R_PPC64_NONE;
1908 case BFD_RELOC_32: r = R_PPC64_ADDR32;
1910 case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
1912 case BFD_RELOC_16: r = R_PPC64_ADDR16;
1914 case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
1916 case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
1918 case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
1920 case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
1922 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
1924 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
1926 case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
1928 case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
1930 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
1932 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
1934 case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
1936 case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
1938 case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
1940 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
1942 case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
1944 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
1946 case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
1948 case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
1950 case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
1952 case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
1954 case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
1956 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
1958 case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
1960 case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
1962 case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
1964 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
1966 case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
1968 case BFD_RELOC_64: r = R_PPC64_ADDR64;
1970 case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
1972 case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
1974 case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
1976 case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
1978 case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
1980 case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
1982 case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
1984 case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
1986 case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
1988 case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
1990 case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
1992 case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
1994 case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
1996 case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
1998 case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
2000 case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
2002 case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
2004 case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
2006 case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
2008 case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
2010 case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
2012 case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
2014 case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
2016 case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
2018 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
2020 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
2022 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
2024 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
2026 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
2028 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
2030 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
2032 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
2034 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
2036 case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
2038 case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
2040 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
2042 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
2044 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
2046 case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
2048 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
2050 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
2052 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
2054 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
2056 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
2058 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
2060 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
2062 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
2064 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
2066 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
2068 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
2070 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
2072 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
2074 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
2076 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
2078 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
2080 case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
2082 case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
2084 case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
2086 case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
2088 case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
2090 case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
2092 case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
2094 case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
2096 case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
2098 case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
2100 case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
2102 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
2104 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
2106 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
2110 return ppc64_elf_howto_table[r];
2113 /* Set the howto pointer for a PowerPC ELF reloc. */
2116 ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
2117 Elf_Internal_Rela *dst)
2121 /* Initialize howto table if needed. */
2122 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2125 type = ELF64_R_TYPE (dst->r_info);
2126 if (type >= (sizeof (ppc64_elf_howto_table)
2127 / sizeof (ppc64_elf_howto_table[0])))
2129 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
2131 type = R_PPC64_NONE;
2133 cache_ptr->howto = ppc64_elf_howto_table[type];
2136 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2138 static bfd_reloc_status_type
2139 ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2140 void *data, asection *input_section,
2141 bfd *output_bfd, char **error_message)
2143 /* If this is a relocatable link (output_bfd test tells us), just
2144 call the generic function. Any adjustment will be done at final
2146 if (output_bfd != NULL)
2147 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2148 input_section, output_bfd, error_message);
2150 /* Adjust the addend for sign extension of the low 16 bits.
2151 We won't actually be using the low 16 bits, so trashing them
2153 reloc_entry->addend += 0x8000;
2154 return bfd_reloc_continue;
2157 static bfd_reloc_status_type
2158 ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2159 void *data, asection *input_section,
2160 bfd *output_bfd, char **error_message)
2162 if (output_bfd != NULL)
2163 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2164 input_section, output_bfd, error_message);
2166 if (strcmp (symbol->section->name, ".opd") == 0
2167 && (symbol->section->owner->flags & DYNAMIC) == 0)
2169 bfd_vma dest = opd_entry_value (symbol->section,
2170 symbol->value + reloc_entry->addend,
2172 if (dest != (bfd_vma) -1)
2173 reloc_entry->addend = dest - (symbol->value
2174 + symbol->section->output_section->vma
2175 + symbol->section->output_offset);
2177 return bfd_reloc_continue;
2180 static bfd_reloc_status_type
2181 ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2182 void *data, asection *input_section,
2183 bfd *output_bfd, char **error_message)
2186 enum elf_ppc64_reloc_type r_type;
2187 bfd_size_type octets;
2188 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2189 bfd_boolean is_power4 = FALSE;
2191 /* If this is a relocatable link (output_bfd test tells us), just
2192 call the generic function. Any adjustment will be done at final
2194 if (output_bfd != NULL)
2195 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2196 input_section, output_bfd, error_message);
2198 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2199 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2200 insn &= ~(0x01 << 21);
2201 r_type = reloc_entry->howto->type;
2202 if (r_type == R_PPC64_ADDR14_BRTAKEN
2203 || r_type == R_PPC64_REL14_BRTAKEN)
2204 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2208 /* Set 'a' bit. This is 0b00010 in BO field for branch
2209 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2210 for branch on CTR insns (BO == 1a00t or 1a01t). */
2211 if ((insn & (0x14 << 21)) == (0x04 << 21))
2213 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2223 if (!bfd_is_com_section (symbol->section))
2224 target = symbol->value;
2225 target += symbol->section->output_section->vma;
2226 target += symbol->section->output_offset;
2227 target += reloc_entry->addend;
2229 from = (reloc_entry->address
2230 + input_section->output_offset
2231 + input_section->output_section->vma);
2233 /* Invert 'y' bit if not the default. */
2234 if ((bfd_signed_vma) (target - from) < 0)
2237 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2239 return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data,
2240 input_section, output_bfd, error_message);
2243 static bfd_reloc_status_type
2244 ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2245 void *data, asection *input_section,
2246 bfd *output_bfd, char **error_message)
2248 /* If this is a relocatable link (output_bfd test tells us), just
2249 call the generic function. Any adjustment will be done at final
2251 if (output_bfd != NULL)
2252 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2253 input_section, output_bfd, error_message);
2255 /* Subtract the symbol section base address. */
2256 reloc_entry->addend -= symbol->section->output_section->vma;
2257 return bfd_reloc_continue;
2260 static bfd_reloc_status_type
2261 ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2262 void *data, asection *input_section,
2263 bfd *output_bfd, char **error_message)
2265 /* If this is a relocatable link (output_bfd test tells us), just
2266 call the generic function. Any adjustment will be done at final
2268 if (output_bfd != NULL)
2269 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2270 input_section, output_bfd, error_message);
2272 /* Subtract the symbol section base address. */
2273 reloc_entry->addend -= symbol->section->output_section->vma;
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_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2282 void *data, asection *input_section,
2283 bfd *output_bfd, char **error_message)
2287 /* If this is a relocatable link (output_bfd test tells us), just
2288 call the generic function. Any adjustment will be done at final
2290 if (output_bfd != NULL)
2291 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2292 input_section, output_bfd, error_message);
2294 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2296 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2298 /* Subtract the TOC base address. */
2299 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2300 return bfd_reloc_continue;
2303 static bfd_reloc_status_type
2304 ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2305 void *data, asection *input_section,
2306 bfd *output_bfd, char **error_message)
2310 /* If this is a relocatable link (output_bfd test tells us), just
2311 call the generic function. Any adjustment will be done at final
2313 if (output_bfd != NULL)
2314 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2315 input_section, output_bfd, error_message);
2317 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2319 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2321 /* Subtract the TOC base address. */
2322 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2324 /* Adjust the addend for sign extension of the low 16 bits. */
2325 reloc_entry->addend += 0x8000;
2326 return bfd_reloc_continue;
2329 static bfd_reloc_status_type
2330 ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2331 void *data, asection *input_section,
2332 bfd *output_bfd, char **error_message)
2335 bfd_size_type octets;
2337 /* If this is a relocatable link (output_bfd test tells us), just
2338 call the generic function. Any adjustment will be done at final
2340 if (output_bfd != NULL)
2341 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2342 input_section, output_bfd, error_message);
2344 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2346 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2348 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2349 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2350 return bfd_reloc_ok;
2353 static bfd_reloc_status_type
2354 ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2355 void *data, asection *input_section,
2356 bfd *output_bfd, char **error_message)
2358 /* If this is a relocatable link (output_bfd test tells us), just
2359 call the generic function. Any adjustment will be done at final
2361 if (output_bfd != NULL)
2362 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2363 input_section, output_bfd, error_message);
2365 if (error_message != NULL)
2367 static char buf[60];
2368 sprintf (buf, "generic linker can't handle %s",
2369 reloc_entry->howto->name);
2370 *error_message = buf;
2372 return bfd_reloc_dangerous;
2375 struct ppc64_elf_obj_tdata
2377 struct elf_obj_tdata elf;
2379 /* Shortcuts to dynamic linker sections. */
2383 /* Used during garbage collection. We attach global symbols defined
2384 on removed .opd entries to this section so that the sym is removed. */
2385 asection *deleted_section;
2387 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2388 sections means we potentially need one of these for each input bfd. */
2390 bfd_signed_vma refcount;
2394 /* A copy of relocs before they are modified for --emit-relocs. */
2395 Elf_Internal_Rela *opd_relocs;
2398 #define ppc64_elf_tdata(bfd) \
2399 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2401 #define ppc64_tlsld_got(bfd) \
2402 (&ppc64_elf_tdata (bfd)->tlsld_got)
2404 /* Override the generic function because we store some extras. */
2407 ppc64_elf_mkobject (bfd *abfd)
2409 if (abfd->tdata.any == NULL)
2411 bfd_size_type amt = sizeof (struct ppc64_elf_obj_tdata);
2412 abfd->tdata.any = bfd_zalloc (abfd, amt);
2413 if (abfd->tdata.any == NULL)
2416 return bfd_elf_mkobject (abfd);
2419 /* Return 1 if target is one of ours. */
2422 is_ppc64_elf_target (const struct bfd_target *targ)
2424 extern const bfd_target bfd_elf64_powerpc_vec;
2425 extern const bfd_target bfd_elf64_powerpcle_vec;
2427 return targ == &bfd_elf64_powerpc_vec || targ == &bfd_elf64_powerpcle_vec;
2430 /* Fix bad default arch selected for a 64 bit input bfd when the
2431 default is 32 bit. */
2434 ppc64_elf_object_p (bfd *abfd)
2436 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
2438 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2440 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2442 /* Relies on arch after 32 bit default being 64 bit default. */
2443 abfd->arch_info = abfd->arch_info->next;
2444 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2450 /* Support for core dump NOTE sections. */
2453 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2455 size_t offset, size;
2457 if (note->descsz != 504)
2461 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
2464 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 32);
2470 /* Make a ".reg/999" section. */
2471 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2472 size, note->descpos + offset);
2476 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2478 if (note->descsz != 136)
2481 elf_tdata (abfd)->core_program
2482 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2483 elf_tdata (abfd)->core_command
2484 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2490 ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
2503 va_start (ap, note_type);
2504 memset (data, 0, 40);
2505 strncpy (data + 40, va_arg (ap, const char *), 16);
2506 strncpy (data + 56, va_arg (ap, const char *), 80);
2508 return elfcore_write_note (abfd, buf, bufsiz,
2509 "CORE", note_type, data, sizeof (data));
2520 va_start (ap, note_type);
2521 memset (data, 0, 112);
2522 pid = va_arg (ap, long);
2523 bfd_put_32 (abfd, pid, data + 32);
2524 cursig = va_arg (ap, int);
2525 bfd_put_16 (abfd, cursig, data + 12);
2526 greg = va_arg (ap, const void *);
2527 memcpy (data + 112, greg, 384);
2528 memset (data + 496, 0, 8);
2530 return elfcore_write_note (abfd, buf, bufsiz,
2531 "CORE", note_type, data, sizeof (data));
2536 /* Merge backend specific data from an object file to the output
2537 object file when linking. */
2540 ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
2542 /* Check if we have the same endianess. */
2543 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
2544 && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
2545 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
2549 if (bfd_big_endian (ibfd))
2550 msg = _("%B: compiled for a big endian system "
2551 "and target is little endian");
2553 msg = _("%B: compiled for a little endian system "
2554 "and target is big endian");
2556 (*_bfd_error_handler) (msg, ibfd);
2558 bfd_set_error (bfd_error_wrong_format);
2565 /* Add extra PPC sections. */
2567 static const struct bfd_elf_special_section ppc64_elf_special_sections[]=
2569 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 },
2570 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2571 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2572 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2573 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2574 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2575 { NULL, 0, 0, 0, 0 }
2578 enum _ppc64_sec_type {
2584 struct _ppc64_elf_section_data
2586 struct bfd_elf_section_data elf;
2588 /* An array with one entry for each opd function descriptor. */
2591 /* Points to the function code section for local opd entries. */
2592 asection **opd_func_sec;
2593 /* After editing .opd, adjust references to opd local syms. */
2596 /* An array for toc sections, indexed by offset/8.
2597 Specifies the relocation symbol index used at a given toc offset. */
2601 enum _ppc64_sec_type sec_type:2;
2603 /* Flag set when small branches are detected. Used to
2604 select suitable defaults for the stub group size. */
2605 unsigned int has_14bit_branch:1;
2608 #define ppc64_elf_section_data(sec) \
2609 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2612 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
2614 if (!sec->used_by_bfd)
2616 struct _ppc64_elf_section_data *sdata;
2617 bfd_size_type amt = sizeof (*sdata);
2619 sdata = bfd_zalloc (abfd, amt);
2622 sec->used_by_bfd = sdata;
2625 return _bfd_elf_new_section_hook (abfd, sec);
2629 get_opd_info (asection * sec)
2632 && ppc64_elf_section_data (sec) != NULL
2633 && ppc64_elf_section_data (sec)->sec_type == sec_opd)
2634 return ppc64_elf_section_data (sec)->u.opd_adjust;
2638 /* Parameters for the qsort hook. */
2639 static asection *synthetic_opd;
2640 static bfd_boolean synthetic_relocatable;
2642 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2645 compare_symbols (const void *ap, const void *bp)
2647 const asymbol *a = * (const asymbol **) ap;
2648 const asymbol *b = * (const asymbol **) bp;
2650 /* Section symbols first. */
2651 if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM))
2653 if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM))
2656 /* then .opd symbols. */
2657 if (a->section == synthetic_opd && b->section != synthetic_opd)
2659 if (a->section != synthetic_opd && b->section == synthetic_opd)
2662 /* then other code symbols. */
2663 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
2664 == (SEC_CODE | SEC_ALLOC)
2665 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
2666 != (SEC_CODE | SEC_ALLOC))
2669 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
2670 != (SEC_CODE | SEC_ALLOC)
2671 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
2672 == (SEC_CODE | SEC_ALLOC))
2675 if (synthetic_relocatable)
2677 if (a->section->id < b->section->id)
2680 if (a->section->id > b->section->id)
2684 if (a->value + a->section->vma < b->value + b->section->vma)
2687 if (a->value + a->section->vma > b->value + b->section->vma)
2690 /* For syms with the same value, prefer strong dynamic global function
2691 syms over other syms. */
2692 if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
2695 if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
2698 if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
2701 if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
2704 if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
2707 if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
2710 if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
2713 if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
2719 /* Search SYMS for a symbol of the given VALUE. */
2722 sym_exists_at (asymbol **syms, long lo, long hi, int id, bfd_vma value)
2730 mid = (lo + hi) >> 1;
2731 if (syms[mid]->value + syms[mid]->section->vma < value)
2733 else if (syms[mid]->value + syms[mid]->section->vma > value)
2743 mid = (lo + hi) >> 1;
2744 if (syms[mid]->section->id < id)
2746 else if (syms[mid]->section->id > id)
2748 else if (syms[mid]->value < value)
2750 else if (syms[mid]->value > value)
2759 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2763 ppc64_elf_get_synthetic_symtab (bfd *abfd,
2764 long static_count, asymbol **static_syms,
2765 long dyn_count, asymbol **dyn_syms,
2772 long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
2774 bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
2779 opd = bfd_get_section_by_name (abfd, ".opd");
2783 symcount = static_count;
2785 symcount += dyn_count;
2789 syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
2793 if (!relocatable && static_count != 0 && dyn_count != 0)
2795 /* Use both symbol tables. */
2796 memcpy (syms, static_syms, static_count * sizeof (*syms));
2797 memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms));
2799 else if (!relocatable && static_count == 0)
2800 memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
2802 memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
2804 synthetic_opd = opd;
2805 synthetic_relocatable = relocatable;
2806 qsort (syms, symcount, sizeof (*syms), compare_symbols);
2808 if (!relocatable && symcount > 1)
2811 /* Trim duplicate syms, since we may have merged the normal and
2812 dynamic symbols. Actually, we only care about syms that have
2813 different values, so trim any with the same value. */
2814 for (i = 1, j = 1; i < symcount; ++i)
2815 if (syms[i - 1]->value + syms[i - 1]->section->vma
2816 != syms[i]->value + syms[i]->section->vma)
2817 syms[j++] = syms[i];
2822 if (syms[i]->section == opd)
2826 for (; i < symcount; ++i)
2827 if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
2828 != (SEC_CODE | SEC_ALLOC))
2829 || (syms[i]->flags & BSF_SECTION_SYM) == 0)
2833 for (; i < symcount; ++i)
2834 if ((syms[i]->flags & BSF_SECTION_SYM) == 0)
2838 for (; i < symcount; ++i)
2839 if (syms[i]->section != opd)
2843 for (; i < symcount; ++i)
2844 if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
2845 != (SEC_CODE | SEC_ALLOC))
2850 if (opdsymend == secsymend)
2855 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
2860 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
2861 relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0;
2865 if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
2872 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
2876 while (r < opd->relocation + relcount
2877 && r->address < syms[i]->value + opd->vma)
2880 if (r == opd->relocation + relcount)
2883 if (r->address != syms[i]->value + opd->vma)
2886 if (r->howto->type != R_PPC64_ADDR64)
2889 sym = *r->sym_ptr_ptr;
2890 if (!sym_exists_at (syms, opdsymend, symcount,
2891 sym->section->id, sym->value + r->addend))
2894 size += sizeof (asymbol);
2895 size += strlen (syms[i]->name) + 2;
2899 s = *ret = bfd_malloc (size);
2906 names = (char *) (s + count);
2908 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
2912 while (r < opd->relocation + relcount
2913 && r->address < syms[i]->value + opd->vma)
2916 if (r == opd->relocation + relcount)
2919 if (r->address != syms[i]->value + opd->vma)
2922 if (r->howto->type != R_PPC64_ADDR64)
2925 sym = *r->sym_ptr_ptr;
2926 if (!sym_exists_at (syms, opdsymend, symcount,
2927 sym->section->id, sym->value + r->addend))
2932 s->section = sym->section;
2933 s->value = sym->value + r->addend;
2936 len = strlen (syms[i]->name);
2937 memcpy (names, syms[i]->name, len + 1);
2948 if (!bfd_malloc_and_get_section (abfd, opd, &contents))
2952 free_contents_and_exit:
2960 for (i = secsymend; i < opdsymend; ++i)
2964 ent = bfd_get_64 (abfd, contents + syms[i]->value);
2965 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
2968 size += sizeof (asymbol);
2969 size += strlen (syms[i]->name) + 2;
2973 s = *ret = bfd_malloc (size);
2975 goto free_contents_and_exit;
2977 names = (char *) (s + count);
2979 for (i = secsymend; i < opdsymend; ++i)
2983 ent = bfd_get_64 (abfd, contents + syms[i]->value);
2984 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
2988 asection *sec = abfd->sections;
2995 long mid = (lo + hi) >> 1;
2996 if (syms[mid]->section->vma < ent)
2998 else if (syms[mid]->section->vma > ent)
3002 sec = syms[mid]->section;
3007 if (lo >= hi && lo > codesecsym)
3008 sec = syms[lo - 1]->section;
3010 for (; sec != NULL; sec = sec->next)
3014 if ((sec->flags & SEC_ALLOC) == 0
3015 || (sec->flags & SEC_LOAD) == 0)
3017 if ((sec->flags & SEC_CODE) != 0)
3020 s->value = ent - s->section->vma;
3023 len = strlen (syms[i]->name);
3024 memcpy (names, syms[i]->name, len + 1);
3037 /* The following functions are specific to the ELF linker, while
3038 functions above are used generally. Those named ppc64_elf_* are
3039 called by the main ELF linker code. They appear in this file more
3040 or less in the order in which they are called. eg.
3041 ppc64_elf_check_relocs is called early in the link process,
3042 ppc64_elf_finish_dynamic_sections is one of the last functions
3045 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3046 functions have both a function code symbol and a function descriptor
3047 symbol. A call to foo in a relocatable object file looks like:
3054 The function definition in another object file might be:
3058 . .quad .TOC.@tocbase
3064 When the linker resolves the call during a static link, the branch
3065 unsurprisingly just goes to .foo and the .opd information is unused.
3066 If the function definition is in a shared library, things are a little
3067 different: The call goes via a plt call stub, the opd information gets
3068 copied to the plt, and the linker patches the nop.
3076 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3077 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3078 . std 2,40(1) # this is the general idea
3086 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3088 The "reloc ()" notation is supposed to indicate that the linker emits
3089 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3092 What are the difficulties here? Well, firstly, the relocations
3093 examined by the linker in check_relocs are against the function code
3094 sym .foo, while the dynamic relocation in the plt is emitted against
3095 the function descriptor symbol, foo. Somewhere along the line, we need
3096 to carefully copy dynamic link information from one symbol to the other.
3097 Secondly, the generic part of the elf linker will make .foo a dynamic
3098 symbol as is normal for most other backends. We need foo dynamic
3099 instead, at least for an application final link. However, when
3100 creating a shared library containing foo, we need to have both symbols
3101 dynamic so that references to .foo are satisfied during the early
3102 stages of linking. Otherwise the linker might decide to pull in a
3103 definition from some other object, eg. a static library.
3105 Update: As of August 2004, we support a new convention. Function
3106 calls may use the function descriptor symbol, ie. "bl foo". This
3107 behaves exactly as "bl .foo". */
3109 /* The linker needs to keep track of the number of relocs that it
3110 decides to copy as dynamic relocs in check_relocs for each symbol.
3111 This is so that it can later discard them if they are found to be
3112 unnecessary. We store the information in a field extending the
3113 regular ELF linker hash table. */
3115 struct ppc_dyn_relocs
3117 struct ppc_dyn_relocs *next;
3119 /* The input section of the reloc. */
3122 /* Total number of relocs copied for the input section. */
3123 bfd_size_type count;
3125 /* Number of pc-relative relocs copied for the input section. */
3126 bfd_size_type pc_count;
3129 /* Track GOT entries needed for a given symbol. We might need more
3130 than one got entry per symbol. */
3133 struct got_entry *next;
3135 /* The symbol addend that we'll be placing in the GOT. */
3138 /* Unlike other ELF targets, we use separate GOT entries for the same
3139 symbol referenced from different input files. This is to support
3140 automatic multiple TOC/GOT sections, where the TOC base can vary
3141 from one input file to another.
3143 Point to the BFD owning this GOT entry. */
3146 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
3147 TLS_TPREL or TLS_DTPREL for tls entries. */
3150 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
3153 bfd_signed_vma refcount;
3158 /* The same for PLT. */
3161 struct plt_entry *next;
3167 bfd_signed_vma refcount;
3172 /* Of those relocs that might be copied as dynamic relocs, this macro
3173 selects those that must be copied when linking a shared library,
3174 even when the symbol is local. */
3176 #define MUST_BE_DYN_RELOC(RTYPE) \
3177 ((RTYPE) != R_PPC64_REL32 \
3178 && (RTYPE) != R_PPC64_REL64 \
3179 && (RTYPE) != R_PPC64_REL30)
3181 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3182 copying dynamic variables from a shared lib into an app's dynbss
3183 section, and instead use a dynamic relocation to point into the
3184 shared lib. With code that gcc generates, it's vital that this be
3185 enabled; In the PowerPC64 ABI, the address of a function is actually
3186 the address of a function descriptor, which resides in the .opd
3187 section. gcc uses the descriptor directly rather than going via the
3188 GOT as some other ABI's do, which means that initialized function
3189 pointers must reference the descriptor. Thus, a function pointer
3190 initialized to the address of a function in a shared library will
3191 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3192 redefines the function descriptor symbol to point to the copy. This
3193 presents a problem as a plt entry for that function is also
3194 initialized from the function descriptor symbol and the copy reloc
3195 may not be initialized first. */
3196 #define ELIMINATE_COPY_RELOCS 1
3198 /* Section name for stubs is the associated section name plus this
3200 #define STUB_SUFFIX ".stub"
3203 ppc_stub_long_branch:
3204 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3205 destination, but a 24 bit branch in a stub section will reach.
3208 ppc_stub_plt_branch:
3209 Similar to the above, but a 24 bit branch in the stub section won't
3210 reach its destination.
3211 . addis %r12,%r2,xxx@toc@ha
3212 . ld %r11,xxx@toc@l(%r12)
3217 Used to call a function in a shared library. If it so happens that
3218 the plt entry referenced crosses a 64k boundary, then an extra
3219 "addis %r12,%r12,1" will be inserted before the load at xxx+8 or
3220 xxx+16 as appropriate.
3221 . addis %r12,%r2,xxx@toc@ha
3223 . ld %r11,xxx+0@toc@l(%r12)
3224 . ld %r2,xxx+8@toc@l(%r12)
3226 . ld %r11,xxx+16@toc@l(%r12)
3229 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3230 code to adjust the value and save r2 to support multiple toc sections.
3231 A ppc_stub_long_branch with an r2 offset looks like:
3233 . addis %r2,%r2,off@ha
3234 . addi %r2,%r2,off@l
3237 A ppc_stub_plt_branch with an r2 offset looks like:
3239 . addis %r12,%r2,xxx@toc@ha
3240 . ld %r11,xxx@toc@l(%r12)
3241 . addis %r2,%r2,off@ha
3242 . addi %r2,%r2,off@l
3247 enum ppc_stub_type {
3249 ppc_stub_long_branch,
3250 ppc_stub_long_branch_r2off,
3251 ppc_stub_plt_branch,
3252 ppc_stub_plt_branch_r2off,
3256 struct ppc_stub_hash_entry {
3258 /* Base hash table entry structure. */
3259 struct bfd_hash_entry root;
3261 enum ppc_stub_type stub_type;
3263 /* The stub section. */
3266 /* Offset within stub_sec of the beginning of this stub. */
3267 bfd_vma stub_offset;
3269 /* Given the symbol's value and its section we can determine its final
3270 value when building the stubs (so the stub knows where to jump. */
3271 bfd_vma target_value;
3272 asection *target_section;
3274 /* The symbol table entry, if any, that this was derived from. */
3275 struct ppc_link_hash_entry *h;
3277 /* And the reloc addend that this was derived from. */
3280 /* Where this stub is being called from, or, in the case of combined
3281 stub sections, the first input section in the group. */
3285 struct ppc_branch_hash_entry {
3287 /* Base hash table entry structure. */
3288 struct bfd_hash_entry root;
3290 /* Offset within branch lookup table. */
3291 unsigned int offset;
3293 /* Generation marker. */
3297 struct ppc_link_hash_entry
3299 struct elf_link_hash_entry elf;
3302 /* A pointer to the most recently used stub hash entry against this
3304 struct ppc_stub_hash_entry *stub_cache;
3306 /* A pointer to the next symbol starting with a '.' */
3307 struct ppc_link_hash_entry *next_dot_sym;
3310 /* Track dynamic relocs copied for this symbol. */
3311 struct ppc_dyn_relocs *dyn_relocs;
3313 /* Link between function code and descriptor symbols. */
3314 struct ppc_link_hash_entry *oh;
3316 /* Flag function code and descriptor symbols. */
3317 unsigned int is_func:1;
3318 unsigned int is_func_descriptor:1;
3319 unsigned int fake:1;
3321 /* Whether global opd/toc sym has been adjusted or not.
3322 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3323 should be set for all globals defined in any opd/toc section. */
3324 unsigned int adjust_done:1;
3326 /* Set if we twiddled this symbol to weak at some stage. */
3327 unsigned int was_undefined:1;
3329 /* Contexts in which symbol is used in the GOT (or TOC).
3330 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3331 corresponding relocs are encountered during check_relocs.
3332 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3333 indicate the corresponding GOT entry type is not needed.
3334 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3335 a TPREL one. We use a separate flag rather than setting TPREL
3336 just for convenience in distinguishing the two cases. */
3337 #define TLS_GD 1 /* GD reloc. */
3338 #define TLS_LD 2 /* LD reloc. */
3339 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3340 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3341 #define TLS_TLS 16 /* Any TLS reloc. */
3342 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3343 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3347 /* ppc64 ELF linker hash table. */
3349 struct ppc_link_hash_table
3351 struct elf_link_hash_table elf;
3353 /* The stub hash table. */
3354 struct bfd_hash_table stub_hash_table;
3356 /* Another hash table for plt_branch stubs. */
3357 struct bfd_hash_table branch_hash_table;
3359 /* Linker stub bfd. */
3362 /* Linker call-backs. */
3363 asection * (*add_stub_section) (const char *, asection *);
3364 void (*layout_sections_again) (void);
3366 /* Array to keep track of which stub sections have been created, and
3367 information on stub grouping. */
3369 /* This is the section to which stubs in the group will be attached. */
3371 /* The stub section. */
3373 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3377 /* Temp used when calculating TOC pointers. */
3380 /* Highest input section id. */
3383 /* Highest output section index. */
3386 /* Used when adding symbols. */
3387 struct ppc_link_hash_entry *dot_syms;
3389 /* List of input sections for each output section. */
3390 asection **input_list;
3392 /* Short-cuts to get to dynamic linker sections. */
3403 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3404 struct ppc_link_hash_entry *tls_get_addr;
3405 struct ppc_link_hash_entry *tls_get_addr_fd;
3408 unsigned long stub_count[ppc_stub_plt_call];
3410 /* Number of stubs against global syms. */
3411 unsigned long stub_globals;
3413 /* Set if we should emit symbols for stubs. */
3414 unsigned int emit_stub_syms:1;
3416 /* Support for multiple toc sections. */
3417 unsigned int no_multi_toc:1;
3418 unsigned int multi_toc_needed:1;
3421 unsigned int stub_error:1;
3423 /* Temp used by ppc64_elf_check_directives. */
3424 unsigned int twiddled_syms:1;
3426 /* Incremented every time we size stubs. */
3427 unsigned int stub_iteration;
3429 /* Small local sym to section mapping cache. */
3430 struct sym_sec_cache sym_sec;
3433 /* Rename some of the generic section flags to better document how they
3435 #define has_toc_reloc has_gp_reloc
3436 #define makes_toc_func_call need_finalize_relax
3437 #define call_check_in_progress reloc_done
3439 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3441 #define ppc_hash_table(p) \
3442 ((struct ppc_link_hash_table *) ((p)->hash))
3444 #define ppc_stub_hash_lookup(table, string, create, copy) \
3445 ((struct ppc_stub_hash_entry *) \
3446 bfd_hash_lookup ((table), (string), (create), (copy)))
3448 #define ppc_branch_hash_lookup(table, string, create, copy) \
3449 ((struct ppc_branch_hash_entry *) \
3450 bfd_hash_lookup ((table), (string), (create), (copy)))
3452 /* Create an entry in the stub hash table. */
3454 static struct bfd_hash_entry *
3455 stub_hash_newfunc (struct bfd_hash_entry *entry,
3456 struct bfd_hash_table *table,
3459 /* Allocate the structure if it has not already been allocated by a
3463 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
3468 /* Call the allocation method of the superclass. */
3469 entry = bfd_hash_newfunc (entry, table, string);
3472 struct ppc_stub_hash_entry *eh;
3474 /* Initialize the local fields. */
3475 eh = (struct ppc_stub_hash_entry *) entry;
3476 eh->stub_type = ppc_stub_none;
3477 eh->stub_sec = NULL;
3478 eh->stub_offset = 0;
3479 eh->target_value = 0;
3480 eh->target_section = NULL;
3488 /* Create an entry in the branch hash table. */
3490 static struct bfd_hash_entry *
3491 branch_hash_newfunc (struct bfd_hash_entry *entry,
3492 struct bfd_hash_table *table,
3495 /* Allocate the structure if it has not already been allocated by a
3499 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
3504 /* Call the allocation method of the superclass. */
3505 entry = bfd_hash_newfunc (entry, table, string);
3508 struct ppc_branch_hash_entry *eh;
3510 /* Initialize the local fields. */
3511 eh = (struct ppc_branch_hash_entry *) entry;
3519 /* Create an entry in a ppc64 ELF linker hash table. */
3521 static struct bfd_hash_entry *
3522 link_hash_newfunc (struct bfd_hash_entry *entry,
3523 struct bfd_hash_table *table,
3526 /* Allocate the structure if it has not already been allocated by a
3530 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
3535 /* Call the allocation method of the superclass. */
3536 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
3539 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
3541 memset (&eh->u.stub_cache, 0,
3542 (sizeof (struct ppc_link_hash_entry)
3543 - offsetof (struct ppc_link_hash_entry, u.stub_cache)));
3545 /* When making function calls, old ABI code references function entry
3546 points (dot symbols), while new ABI code references the function
3547 descriptor symbol. We need to make any combination of reference and
3548 definition work together, without breaking archive linking.
3550 For a defined function "foo" and an undefined call to "bar":
3551 An old object defines "foo" and ".foo", references ".bar" (possibly
3553 A new object defines "foo" and references "bar".
3555 A new object thus has no problem with its undefined symbols being
3556 satisfied by definitions in an old object. On the other hand, the
3557 old object won't have ".bar" satisfied by a new object.
3559 Keep a list of newly added dot-symbols. */
3561 if (string[0] == '.')
3563 struct ppc_link_hash_table *htab;
3565 htab = (struct ppc_link_hash_table *) table;
3566 eh->u.next_dot_sym = htab->dot_syms;
3567 htab->dot_syms = eh;
3574 /* Create a ppc64 ELF linker hash table. */
3576 static struct bfd_link_hash_table *
3577 ppc64_elf_link_hash_table_create (bfd *abfd)
3579 struct ppc_link_hash_table *htab;
3580 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
3582 htab = bfd_zmalloc (amt);
3586 if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
3587 sizeof (struct ppc_link_hash_entry)))
3593 /* Init the stub hash table too. */
3594 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
3595 sizeof (struct ppc_stub_hash_entry)))
3598 /* And the branch hash table. */
3599 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
3600 sizeof (struct ppc_branch_hash_entry)))
3603 /* Initializing two fields of the union is just cosmetic. We really
3604 only care about glist, but when compiled on a 32-bit host the
3605 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3606 debugger inspection of these fields look nicer. */
3607 htab->elf.init_got_refcount.refcount = 0;
3608 htab->elf.init_got_refcount.glist = NULL;
3609 htab->elf.init_plt_refcount.refcount = 0;
3610 htab->elf.init_plt_refcount.glist = NULL;
3611 htab->elf.init_got_offset.offset = 0;
3612 htab->elf.init_got_offset.glist = NULL;
3613 htab->elf.init_plt_offset.offset = 0;
3614 htab->elf.init_plt_offset.glist = NULL;
3616 return &htab->elf.root;
3619 /* Free the derived linker hash table. */
3622 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
3624 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
3626 bfd_hash_table_free (&ret->stub_hash_table);
3627 bfd_hash_table_free (&ret->branch_hash_table);
3628 _bfd_generic_link_hash_table_free (hash);
3631 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3634 ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info)
3636 struct ppc_link_hash_table *htab;
3638 elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64;
3640 /* Always hook our dynamic sections into the first bfd, which is the
3641 linker created stub bfd. This ensures that the GOT header is at
3642 the start of the output TOC section. */
3643 htab = ppc_hash_table (info);
3644 htab->stub_bfd = abfd;
3645 htab->elf.dynobj = abfd;
3648 /* Build a name for an entry in the stub hash table. */
3651 ppc_stub_name (const asection *input_section,
3652 const asection *sym_sec,
3653 const struct ppc_link_hash_entry *h,
3654 const Elf_Internal_Rela *rel)
3659 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3660 offsets from a sym as a branch target? In fact, we could
3661 probably assume the addend is always zero. */
3662 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
3666 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
3667 stub_name = bfd_malloc (len);
3668 if (stub_name == NULL)
3671 sprintf (stub_name, "%08x.%s+%x",
3672 input_section->id & 0xffffffff,
3673 h->elf.root.root.string,
3674 (int) rel->r_addend & 0xffffffff);
3678 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3679 stub_name = bfd_malloc (len);
3680 if (stub_name == NULL)
3683 sprintf (stub_name, "%08x.%x:%x+%x",
3684 input_section->id & 0xffffffff,
3685 sym_sec->id & 0xffffffff,
3686 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
3687 (int) rel->r_addend & 0xffffffff);
3689 if (stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
3690 stub_name[len - 2] = 0;
3694 /* Look up an entry in the stub hash. Stub entries are cached because
3695 creating the stub name takes a bit of time. */
3697 static struct ppc_stub_hash_entry *
3698 ppc_get_stub_entry (const asection *input_section,
3699 const asection *sym_sec,
3700 struct ppc_link_hash_entry *h,
3701 const Elf_Internal_Rela *rel,
3702 struct ppc_link_hash_table *htab)
3704 struct ppc_stub_hash_entry *stub_entry;
3705 const asection *id_sec;
3707 /* If this input section is part of a group of sections sharing one
3708 stub section, then use the id of the first section in the group.
3709 Stub names need to include a section id, as there may well be
3710 more than one stub used to reach say, printf, and we need to
3711 distinguish between them. */
3712 id_sec = htab->stub_group[input_section->id].link_sec;
3714 if (h != NULL && h->u.stub_cache != NULL
3715 && h->u.stub_cache->h == h
3716 && h->u.stub_cache->id_sec == id_sec)
3718 stub_entry = h->u.stub_cache;
3724 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
3725 if (stub_name == NULL)
3728 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
3729 stub_name, FALSE, FALSE);
3731 h->u.stub_cache = stub_entry;
3739 /* Add a new stub entry to the stub hash. Not all fields of the new
3740 stub entry are initialised. */
3742 static struct ppc_stub_hash_entry *
3743 ppc_add_stub (const char *stub_name,
3745 struct ppc_link_hash_table *htab)
3749 struct ppc_stub_hash_entry *stub_entry;
3751 link_sec = htab->stub_group[section->id].link_sec;
3752 stub_sec = htab->stub_group[section->id].stub_sec;
3753 if (stub_sec == NULL)
3755 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3756 if (stub_sec == NULL)
3762 namelen = strlen (link_sec->name);
3763 len = namelen + sizeof (STUB_SUFFIX);
3764 s_name = bfd_alloc (htab->stub_bfd, len);
3768 memcpy (s_name, link_sec->name, namelen);
3769 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3770 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3771 if (stub_sec == NULL)
3773 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3775 htab->stub_group[section->id].stub_sec = stub_sec;
3778 /* Enter this entry into the linker stub hash table. */
3779 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3781 if (stub_entry == NULL)
3783 (*_bfd_error_handler) (_("%B: cannot create stub entry %s"),
3784 section->owner, stub_name);
3788 stub_entry->stub_sec = stub_sec;
3789 stub_entry->stub_offset = 0;
3790 stub_entry->id_sec = link_sec;
3794 /* Create sections for linker generated code. */
3797 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
3799 struct ppc_link_hash_table *htab;
3802 htab = ppc_hash_table (info);
3804 /* Create .sfpr for code to save and restore fp regs. */
3805 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
3806 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3807 htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
3809 if (htab->sfpr == NULL
3810 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
3813 /* Create .glink for lazy dynamic linking support. */
3814 htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
3816 if (htab->glink == NULL
3817 || ! bfd_set_section_alignment (dynobj, htab->glink, 3))
3820 /* Create branch lookup table for plt_branch stubs. */
3821 flags = (SEC_ALLOC | SEC_LOAD
3822 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3823 htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
3825 if (htab->brlt == NULL
3826 || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
3832 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
3833 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3834 htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
3838 || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
3844 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3845 not already done. */
3848 create_got_section (bfd *abfd, struct bfd_link_info *info)
3850 asection *got, *relgot;
3852 struct ppc_link_hash_table *htab = ppc_hash_table (info);
3856 if (! _bfd_elf_create_got_section (htab->elf.dynobj, info))
3859 htab->got = bfd_get_section_by_name (htab->elf.dynobj, ".got");
3864 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3865 | SEC_LINKER_CREATED);
3867 got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
3869 || !bfd_set_section_alignment (abfd, got, 3))
3872 relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
3873 flags | SEC_READONLY);
3875 || ! bfd_set_section_alignment (abfd, relgot, 3))
3878 ppc64_elf_tdata (abfd)->got = got;
3879 ppc64_elf_tdata (abfd)->relgot = relgot;
3883 /* Create the dynamic sections, and set up shortcuts. */
3886 ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
3888 struct ppc_link_hash_table *htab;
3890 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
3893 htab = ppc_hash_table (info);
3895 htab->got = bfd_get_section_by_name (dynobj, ".got");
3896 htab->plt = bfd_get_section_by_name (dynobj, ".plt");
3897 htab->relplt = bfd_get_section_by_name (dynobj, ".rela.plt");
3898 htab->dynbss = bfd_get_section_by_name (dynobj, ".dynbss");
3900 htab->relbss = bfd_get_section_by_name (dynobj, ".rela.bss");
3902 if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss
3903 || (!info->shared && !htab->relbss))
3909 /* Merge PLT info on FROM with that on TO. */
3912 move_plt_plist (struct ppc_link_hash_entry *from,
3913 struct ppc_link_hash_entry *to)
3915 if (from->elf.plt.plist != NULL)
3917 if (to->elf.plt.plist != NULL)
3919 struct plt_entry **entp;
3920 struct plt_entry *ent;
3922 for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; )
3924 struct plt_entry *dent;
3926 for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next)
3927 if (dent->addend == ent->addend)
3929 dent->plt.refcount += ent->plt.refcount;
3936 *entp = to->elf.plt.plist;
3939 to->elf.plt.plist = from->elf.plt.plist;
3940 from->elf.plt.plist = NULL;
3944 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3947 ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
3948 struct elf_link_hash_entry *dir,
3949 struct elf_link_hash_entry *ind)
3951 struct ppc_link_hash_entry *edir, *eind;
3953 edir = (struct ppc_link_hash_entry *) dir;
3954 eind = (struct ppc_link_hash_entry *) ind;
3956 /* Copy over any dynamic relocs we may have on the indirect sym. */
3957 if (eind->dyn_relocs != NULL)
3959 if (edir->dyn_relocs != NULL)
3961 struct ppc_dyn_relocs **pp;
3962 struct ppc_dyn_relocs *p;
3964 /* Add reloc counts against the indirect sym to the direct sym
3965 list. Merge any entries against the same section. */
3966 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3968 struct ppc_dyn_relocs *q;
3970 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3971 if (q->sec == p->sec)
3973 q->pc_count += p->pc_count;
3974 q->count += p->count;
3981 *pp = edir->dyn_relocs;
3984 edir->dyn_relocs = eind->dyn_relocs;
3985 eind->dyn_relocs = NULL;
3988 edir->is_func |= eind->is_func;
3989 edir->is_func_descriptor |= eind->is_func_descriptor;
3990 edir->tls_mask |= eind->tls_mask;
3992 /* If called to transfer flags for a weakdef during processing
3993 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
3994 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3995 if (!(ELIMINATE_COPY_RELOCS
3996 && eind->elf.root.type != bfd_link_hash_indirect
3997 && edir->elf.dynamic_adjusted))
3998 edir->elf.non_got_ref |= eind->elf.non_got_ref;
4000 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
4001 edir->elf.ref_regular |= eind->elf.ref_regular;
4002 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
4003 edir->elf.needs_plt |= eind->elf.needs_plt;
4005 /* If we were called to copy over info for a weak sym, that's all. */
4006 if (eind->elf.root.type != bfd_link_hash_indirect)
4009 /* Copy over got entries that we may have already seen to the
4010 symbol which just became indirect. */
4011 if (eind->elf.got.glist != NULL)
4013 if (edir->elf.got.glist != NULL)
4015 struct got_entry **entp;
4016 struct got_entry *ent;
4018 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
4020 struct got_entry *dent;
4022 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
4023 if (dent->addend == ent->addend
4024 && dent->owner == ent->owner
4025 && dent->tls_type == ent->tls_type)
4027 dent->got.refcount += ent->got.refcount;
4034 *entp = edir->elf.got.glist;
4037 edir->elf.got.glist = eind->elf.got.glist;
4038 eind->elf.got.glist = NULL;
4041 /* And plt entries. */
4042 move_plt_plist (eind, edir);
4044 if (eind->elf.dynindx != -1)
4046 if (edir->elf.dynindx != -1)
4047 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4048 edir->elf.dynstr_index);
4049 edir->elf.dynindx = eind->elf.dynindx;
4050 edir->elf.dynstr_index = eind->elf.dynstr_index;
4051 eind->elf.dynindx = -1;
4052 eind->elf.dynstr_index = 0;
4056 /* Find the function descriptor hash entry from the given function code
4057 hash entry FH. Link the entries via their OH fields. */
4059 static struct ppc_link_hash_entry *
4060 get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
4062 struct ppc_link_hash_entry *fdh = fh->oh;
4066 const char *fd_name = fh->elf.root.root.string + 1;
4068 fdh = (struct ppc_link_hash_entry *)
4069 elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
4072 fdh->is_func_descriptor = 1;
4082 /* Make a fake function descriptor sym for the code sym FH. */
4084 static struct ppc_link_hash_entry *
4085 make_fdh (struct bfd_link_info *info,
4086 struct ppc_link_hash_entry *fh)
4090 struct bfd_link_hash_entry *bh;
4091 struct ppc_link_hash_entry *fdh;
4093 abfd = fh->elf.root.u.undef.abfd;
4094 newsym = bfd_make_empty_symbol (abfd);
4095 newsym->name = fh->elf.root.root.string + 1;
4096 newsym->section = bfd_und_section_ptr;
4098 newsym->flags = BSF_WEAK;
4101 if (!_bfd_generic_link_add_one_symbol (info, abfd, newsym->name,
4102 newsym->flags, newsym->section,
4103 newsym->value, NULL, FALSE, FALSE,
4107 fdh = (struct ppc_link_hash_entry *) bh;
4108 fdh->elf.non_elf = 0;
4110 fdh->is_func_descriptor = 1;
4117 /* Fix function descriptor symbols defined in .opd sections to be
4121 ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED,
4122 struct bfd_link_info *info ATTRIBUTE_UNUSED,
4123 Elf_Internal_Sym *isym,
4124 const char **name ATTRIBUTE_UNUSED,
4125 flagword *flags ATTRIBUTE_UNUSED,
4127 bfd_vma *value ATTRIBUTE_UNUSED)
4130 && strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0)
4131 isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
4136 /* This function makes an old ABI object reference to ".bar" cause the
4137 inclusion of a new ABI object archive that defines "bar".
4138 NAME is a symbol defined in an archive. Return a symbol in the hash
4139 table that might be satisfied by the archive symbols. */
4141 static struct elf_link_hash_entry *
4142 ppc64_elf_archive_symbol_lookup (bfd *abfd,
4143 struct bfd_link_info *info,
4146 struct elf_link_hash_entry *h;
4150 h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
4152 /* Don't return this sym if it is a fake function descriptor
4153 created by add_symbol_adjust. */
4154 && !(h->root.type == bfd_link_hash_undefweak
4155 && ((struct ppc_link_hash_entry *) h)->fake))
4161 len = strlen (name);
4162 dot_name = bfd_alloc (abfd, len + 2);
4163 if (dot_name == NULL)
4164 return (struct elf_link_hash_entry *) 0 - 1;
4166 memcpy (dot_name + 1, name, len + 1);
4167 h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
4168 bfd_release (abfd, dot_name);
4172 /* This function satisfies all old ABI object references to ".bar" if a
4173 new ABI object defines "bar". Well, at least, undefined dot symbols
4174 are made weak. This stops later archive searches from including an
4175 object if we already have a function descriptor definition. It also
4176 prevents the linker complaining about undefined symbols.
4177 We also check and correct mismatched symbol visibility here. The
4178 most restrictive visibility of the function descriptor and the
4179 function entry symbol is used. */
4182 add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
4184 struct ppc_link_hash_table *htab;
4185 struct ppc_link_hash_entry *fdh;
4187 if (eh->elf.root.type == bfd_link_hash_indirect)
4190 if (eh->elf.root.type == bfd_link_hash_warning)
4191 eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
4193 if (eh->elf.root.root.string[0] != '.')
4196 htab = ppc_hash_table (info);
4197 fdh = get_fdh (eh, htab);
4199 && !info->relocatable
4200 && (eh->elf.root.type == bfd_link_hash_undefined
4201 || eh->elf.root.type == bfd_link_hash_undefweak)
4202 && eh->elf.ref_regular)
4204 /* Make an undefweak function descriptor sym, which is enough to
4205 pull in an --as-needed shared lib, but won't cause link
4206 errors. Archives are handled elsewhere. */
4207 fdh = make_fdh (info, eh);
4211 fdh->elf.ref_regular = 1;
4213 else if (fdh != NULL)
4215 unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
4216 unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
4217 if (entry_vis < descr_vis)
4218 fdh->elf.other += entry_vis - descr_vis;
4219 else if (entry_vis > descr_vis)
4220 eh->elf.other += descr_vis - entry_vis;
4222 if ((fdh->elf.root.type == bfd_link_hash_defined
4223 || fdh->elf.root.type == bfd_link_hash_defweak)
4224 && eh->elf.root.type == bfd_link_hash_undefined)
4226 eh->elf.root.type = bfd_link_hash_undefweak;
4227 eh->was_undefined = 1;
4228 htab->twiddled_syms = 1;
4235 /* Process list of dot-symbols we made in link_hash_newfunc. */
4238 ppc64_elf_check_directives (bfd *ibfd, struct bfd_link_info *info)
4240 struct ppc_link_hash_table *htab;
4241 struct ppc_link_hash_entry **p, *eh;
4243 htab = ppc_hash_table (info);
4244 if (!is_ppc64_elf_target (htab->elf.root.creator))
4247 if (is_ppc64_elf_target (ibfd->xvec))
4249 p = &htab->dot_syms;
4250 while ((eh = *p) != NULL)
4253 if (!add_symbol_adjust (eh, info))
4255 p = &eh->u.next_dot_sym;
4259 /* Clear the list for non-ppc64 input files. */
4260 p = &htab->dot_syms;
4261 while ((eh = *p) != NULL)
4264 p = &eh->u.next_dot_sym;
4267 /* We need to fix the undefs list for any syms we have twiddled to
4269 if (htab->twiddled_syms)
4271 bfd_link_repair_undef_list (&htab->elf.root);
4272 htab->twiddled_syms = 0;
4277 /* Undo hash table changes when an --as-needed input file is determined
4278 not to be needed. */
4281 ppc64_elf_as_needed_cleanup (bfd *ibfd ATTRIBUTE_UNUSED,
4282 struct bfd_link_info *info)
4284 ppc_hash_table (info)->dot_syms = NULL;
4289 update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
4290 unsigned long r_symndx, bfd_vma r_addend, int tls_type)
4292 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
4293 char *local_got_tls_masks;
4295 if (local_got_ents == NULL)
4297 bfd_size_type size = symtab_hdr->sh_info;
4299 size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks);
4300 local_got_ents = bfd_zalloc (abfd, size);
4301 if (local_got_ents == NULL)
4303 elf_local_got_ents (abfd) = local_got_ents;
4306 if ((tls_type & TLS_EXPLICIT) == 0)
4308 struct got_entry *ent;
4310 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
4311 if (ent->addend == r_addend
4312 && ent->owner == abfd
4313 && ent->tls_type == tls_type)
4317 bfd_size_type amt = sizeof (*ent);
4318 ent = bfd_alloc (abfd, amt);
4321 ent->next = local_got_ents[r_symndx];
4322 ent->addend = r_addend;
4324 ent->tls_type = tls_type;
4325 ent->got.refcount = 0;
4326 local_got_ents[r_symndx] = ent;
4328 ent->got.refcount += 1;
4331 local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
4332 local_got_tls_masks[r_symndx] |= tls_type;
4337 update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend)
4339 struct plt_entry *ent;
4341 for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next)
4342 if (ent->addend == addend)
4346 bfd_size_type amt = sizeof (*ent);
4347 ent = bfd_alloc (abfd, amt);
4350 ent->next = eh->elf.plt.plist;
4351 ent->addend = addend;
4352 ent->plt.refcount = 0;
4353 eh->elf.plt.plist = ent;
4355 ent->plt.refcount += 1;
4356 eh->elf.needs_plt = 1;
4357 if (eh->elf.root.root.string[0] == '.'
4358 && eh->elf.root.root.string[1] != '\0')
4363 /* Look through the relocs for a section during the first phase, and
4364 calculate needed space in the global offset table, procedure
4365 linkage table, and dynamic reloc sections. */
4368 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
4369 asection *sec, const Elf_Internal_Rela *relocs)
4371 struct ppc_link_hash_table *htab;
4372 Elf_Internal_Shdr *symtab_hdr;
4373 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
4374 const Elf_Internal_Rela *rel;
4375 const Elf_Internal_Rela *rel_end;
4377 asection **opd_sym_map;
4379 if (info->relocatable)
4382 /* Don't do anything special with non-loaded, non-alloced sections.
4383 In particular, any relocs in such sections should not affect GOT
4384 and PLT reference counting (ie. we don't allow them to create GOT
4385 or PLT entries), there's no possibility or desire to optimize TLS
4386 relocs, and there's not much point in propagating relocs to shared
4387 libs that the dynamic linker won't relocate. */
4388 if ((sec->flags & SEC_ALLOC) == 0)
4391 htab = ppc_hash_table (info);
4392 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4394 sym_hashes = elf_sym_hashes (abfd);
4395 sym_hashes_end = (sym_hashes
4396 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym)
4397 - symtab_hdr->sh_info);
4401 if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0)
4403 /* Garbage collection needs some extra help with .opd sections.
4404 We don't want to necessarily keep everything referenced by
4405 relocs in .opd, as that would keep all functions. Instead,
4406 if we reference an .opd symbol (a function descriptor), we
4407 want to keep the function code symbol's section. This is
4408 easy for global symbols, but for local syms we need to keep
4409 information about the associated function section. Later, if
4410 edit_opd deletes entries, we'll use this array to adjust
4411 local syms in .opd. */
4413 asection *func_section;
4418 amt = sec->size * sizeof (union opd_info) / 8;
4419 opd_sym_map = bfd_zalloc (abfd, amt);
4420 if (opd_sym_map == NULL)
4422 ppc64_elf_section_data (sec)->u.opd_func_sec = opd_sym_map;
4423 BFD_ASSERT (ppc64_elf_section_data (sec)->sec_type == sec_normal);
4424 ppc64_elf_section_data (sec)->sec_type = sec_opd;
4427 if (htab->sfpr == NULL
4428 && !create_linkage_sections (htab->elf.dynobj, info))
4431 rel_end = relocs + sec->reloc_count;
4432 for (rel = relocs; rel < rel_end; rel++)
4434 unsigned long r_symndx;
4435 struct elf_link_hash_entry *h;
4436 enum elf_ppc64_reloc_type r_type;
4438 struct _ppc64_elf_section_data *ppc64_sec;
4440 r_symndx = ELF64_R_SYM (rel->r_info);
4441 if (r_symndx < symtab_hdr->sh_info)
4445 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4446 while (h->root.type == bfd_link_hash_indirect
4447 || h->root.type == bfd_link_hash_warning)
4448 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4451 r_type = ELF64_R_TYPE (rel->r_info);
4454 case R_PPC64_GOT_TLSLD16:
4455 case R_PPC64_GOT_TLSLD16_LO:
4456 case R_PPC64_GOT_TLSLD16_HI:
4457 case R_PPC64_GOT_TLSLD16_HA:
4458 ppc64_tlsld_got (abfd)->refcount += 1;
4459 tls_type = TLS_TLS | TLS_LD;
4462 case R_PPC64_GOT_TLSGD16:
4463 case R_PPC64_GOT_TLSGD16_LO:
4464 case R_PPC64_GOT_TLSGD16_HI:
4465 case R_PPC64_GOT_TLSGD16_HA:
4466 tls_type = TLS_TLS | TLS_GD;
4469 case R_PPC64_GOT_TPREL16_DS:
4470 case R_PPC64_GOT_TPREL16_LO_DS:
4471 case R_PPC64_GOT_TPREL16_HI:
4472 case R_PPC64_GOT_TPREL16_HA:
4474 info->flags |= DF_STATIC_TLS;
4475 tls_type = TLS_TLS | TLS_TPREL;
4478 case R_PPC64_GOT_DTPREL16_DS:
4479 case R_PPC64_GOT_DTPREL16_LO_DS:
4480 case R_PPC64_GOT_DTPREL16_HI:
4481 case R_PPC64_GOT_DTPREL16_HA:
4482 tls_type = TLS_TLS | TLS_DTPREL;
4484 sec->has_tls_reloc = 1;
4488 case R_PPC64_GOT16_DS:
4489 case R_PPC64_GOT16_HA:
4490 case R_PPC64_GOT16_HI:
4491 case R_PPC64_GOT16_LO:
4492 case R_PPC64_GOT16_LO_DS:
4493 /* This symbol requires a global offset table entry. */
4494 sec->has_toc_reloc = 1;
4495 if (ppc64_elf_tdata (abfd)->got == NULL
4496 && !create_got_section (abfd, info))
4501 struct ppc_link_hash_entry *eh;
4502 struct got_entry *ent;
4504 eh = (struct ppc_link_hash_entry *) h;
4505 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
4506 if (ent->addend == rel->r_addend
4507 && ent->owner == abfd
4508 && ent->tls_type == tls_type)
4512 bfd_size_type amt = sizeof (*ent);
4513 ent = bfd_alloc (abfd, amt);
4516 ent->next = eh->elf.got.glist;
4517 ent->addend = rel->r_addend;
4519 ent->tls_type = tls_type;
4520 ent->got.refcount = 0;
4521 eh->elf.got.glist = ent;
4523 ent->got.refcount += 1;
4524 eh->tls_mask |= tls_type;
4527 /* This is a global offset table entry for a local symbol. */
4528 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
4529 rel->r_addend, tls_type))
4533 case R_PPC64_PLT16_HA:
4534 case R_PPC64_PLT16_HI:
4535 case R_PPC64_PLT16_LO:
4538 /* This symbol requires a procedure linkage table entry. We
4539 actually build the entry in adjust_dynamic_symbol,
4540 because this might be a case of linking PIC code without
4541 linking in any dynamic objects, in which case we don't
4542 need to generate a procedure linkage table after all. */
4545 /* It does not make sense to have a procedure linkage
4546 table entry for a local symbol. */
4547 bfd_set_error (bfd_error_bad_value);
4551 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
4556 /* The following relocations don't need to propagate the
4557 relocation if linking a shared object since they are
4558 section relative. */
4559 case R_PPC64_SECTOFF:
4560 case R_PPC64_SECTOFF_LO:
4561 case R_PPC64_SECTOFF_HI:
4562 case R_PPC64_SECTOFF_HA:
4563 case R_PPC64_SECTOFF_DS:
4564 case R_PPC64_SECTOFF_LO_DS:
4565 case R_PPC64_DTPREL16:
4566 case R_PPC64_DTPREL16_LO:
4567 case R_PPC64_DTPREL16_HI:
4568 case R_PPC64_DTPREL16_HA:
4569 case R_PPC64_DTPREL16_DS:
4570 case R_PPC64_DTPREL16_LO_DS:
4571 case R_PPC64_DTPREL16_HIGHER:
4572 case R_PPC64_DTPREL16_HIGHERA:
4573 case R_PPC64_DTPREL16_HIGHEST:
4574 case R_PPC64_DTPREL16_HIGHESTA:
4579 case R_PPC64_TOC16_LO:
4580 case R_PPC64_TOC16_HI:
4581 case R_PPC64_TOC16_HA:
4582 case R_PPC64_TOC16_DS:
4583 case R_PPC64_TOC16_LO_DS:
4584 sec->has_toc_reloc = 1;
4587 /* This relocation describes the C++ object vtable hierarchy.
4588 Reconstruct it for later use during GC. */
4589 case R_PPC64_GNU_VTINHERIT:
4590 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4594 /* This relocation describes which C++ vtable entries are actually
4595 used. Record for later use during GC. */
4596 case R_PPC64_GNU_VTENTRY:
4597 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
4602 case R_PPC64_REL14_BRTAKEN:
4603 case R_PPC64_REL14_BRNTAKEN:
4605 asection *dest = NULL;
4607 /* Heuristic: If jumping outside our section, chances are
4608 we are going to need a stub. */
4611 /* If the sym is weak it may be overridden later, so
4612 don't assume we know where a weak sym lives. */
4613 if (h->root.type == bfd_link_hash_defined)
4614 dest = h->root.u.def.section;
4617 dest = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
4620 ppc64_elf_section_data (sec)->has_14bit_branch = 1;
4627 /* We may need a .plt entry if the function this reloc
4628 refers to is in a shared lib. */
4629 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
4632 if (h == &htab->tls_get_addr->elf
4633 || h == &htab->tls_get_addr_fd->elf)
4634 sec->has_tls_reloc = 1;
4635 else if (htab->tls_get_addr == NULL
4636 && CONST_STRNEQ (h->root.root.string, ".__tls_get_addr")
4637 && (h->root.root.string[15] == 0
4638 || h->root.root.string[15] == '@'))
4640 htab->tls_get_addr = (struct ppc_link_hash_entry *) h;
4641 sec->has_tls_reloc = 1;
4643 else if (htab->tls_get_addr_fd == NULL
4644 && CONST_STRNEQ (h->root.root.string, "__tls_get_addr")
4645 && (h->root.root.string[14] == 0
4646 || h->root.root.string[14] == '@'))
4648 htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) h;
4649 sec->has_tls_reloc = 1;
4654 case R_PPC64_TPREL64:
4655 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
4657 info->flags |= DF_STATIC_TLS;
4660 case R_PPC64_DTPMOD64:
4661 if (rel + 1 < rel_end
4662 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
4663 && rel[1].r_offset == rel->r_offset + 8)
4664 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
4666 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
4669 case R_PPC64_DTPREL64:
4670 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
4672 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
4673 && rel[-1].r_offset == rel->r_offset - 8)
4674 /* This is the second reloc of a dtpmod, dtprel pair.
4675 Don't mark with TLS_DTPREL. */
4679 sec->has_tls_reloc = 1;
4682 struct ppc_link_hash_entry *eh;
4683 eh = (struct ppc_link_hash_entry *) h;
4684 eh->tls_mask |= tls_type;
4687 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
4688 rel->r_addend, tls_type))
4691 ppc64_sec = ppc64_elf_section_data (sec);
4692 if (ppc64_sec->sec_type != sec_toc)
4694 /* One extra to simplify get_tls_mask. */
4695 bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1;
4696 ppc64_sec->u.t_symndx = bfd_zalloc (abfd, amt);
4697 if (ppc64_sec->u.t_symndx == NULL)
4699 BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
4700 ppc64_sec->sec_type = sec_toc;
4702 BFD_ASSERT (rel->r_offset % 8 == 0);
4703 ppc64_sec->u.t_symndx[rel->r_offset / 8] = r_symndx;
4705 /* Mark the second slot of a GD or LD entry.
4706 -1 to indicate GD and -2 to indicate LD. */
4707 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
4708 ppc64_sec->u.t_symndx[rel->r_offset / 8 + 1] = -1;
4709 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
4710 ppc64_sec->u.t_symndx[rel->r_offset / 8 + 1] = -2;
4713 case R_PPC64_TPREL16:
4714 case R_PPC64_TPREL16_LO:
4715 case R_PPC64_TPREL16_HI:
4716 case R_PPC64_TPREL16_HA:
4717 case R_PPC64_TPREL16_DS:
4718 case R_PPC64_TPREL16_LO_DS:
4719 case R_PPC64_TPREL16_HIGHER:
4720 case R_PPC64_TPREL16_HIGHERA:
4721 case R_PPC64_TPREL16_HIGHEST:
4722 case R_PPC64_TPREL16_HIGHESTA:
4725 info->flags |= DF_STATIC_TLS;
4730 case R_PPC64_ADDR64:
4731 if (opd_sym_map != NULL
4732 && rel + 1 < rel_end
4733 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
4737 if (h->root.root.string[0] == '.'
4738 && h->root.root.string[1] != 0
4739 && get_fdh ((struct ppc_link_hash_entry *) h, htab))
4742 ((struct ppc_link_hash_entry *) h)->is_func = 1;
4748 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
4753 opd_sym_map[rel->r_offset / 8] = s;
4761 case R_PPC64_ADDR14:
4762 case R_PPC64_ADDR14_BRNTAKEN:
4763 case R_PPC64_ADDR14_BRTAKEN:
4764 case R_PPC64_ADDR16:
4765 case R_PPC64_ADDR16_DS:
4766 case R_PPC64_ADDR16_HA:
4767 case R_PPC64_ADDR16_HI:
4768 case R_PPC64_ADDR16_HIGHER:
4769 case R_PPC64_ADDR16_HIGHERA:
4770 case R_PPC64_ADDR16_HIGHEST:
4771 case R_PPC64_ADDR16_HIGHESTA:
4772 case R_PPC64_ADDR16_LO:
4773 case R_PPC64_ADDR16_LO_DS:
4774 case R_PPC64_ADDR24:
4775 case R_PPC64_ADDR32:
4776 case R_PPC64_UADDR16:
4777 case R_PPC64_UADDR32:
4778 case R_PPC64_UADDR64:
4780 if (h != NULL && !info->shared)
4781 /* We may need a copy reloc. */
4784 /* Don't propagate .opd relocs. */
4785 if (NO_OPD_RELOCS && opd_sym_map != NULL)
4788 /* If we are creating a shared library, and this is a reloc
4789 against a global symbol, or a non PC relative reloc
4790 against a local symbol, then we need to copy the reloc
4791 into the shared library. However, if we are linking with
4792 -Bsymbolic, we do not need to copy a reloc against a
4793 global symbol which is defined in an object we are
4794 including in the link (i.e., DEF_REGULAR is set). At
4795 this point we have not seen all the input files, so it is
4796 possible that DEF_REGULAR is not set now but will be set
4797 later (it is never cleared). In case of a weak definition,
4798 DEF_REGULAR may be cleared later by a strong definition in
4799 a shared library. We account for that possibility below by
4800 storing information in the dyn_relocs field of the hash
4801 table entry. A similar situation occurs when creating
4802 shared libraries and symbol visibility changes render the
4805 If on the other hand, we are creating an executable, we
4806 may need to keep relocations for symbols satisfied by a
4807 dynamic library if we manage to avoid copy relocs for the
4811 && (MUST_BE_DYN_RELOC (r_type)
4813 && (! info->symbolic
4814 || h->root.type == bfd_link_hash_defweak
4815 || !h->def_regular))))
4816 || (ELIMINATE_COPY_RELOCS
4819 && (h->root.type == bfd_link_hash_defweak
4820 || !h->def_regular)))
4822 struct ppc_dyn_relocs *p;
4823 struct ppc_dyn_relocs **head;
4825 /* We must copy these reloc types into the output file.
4826 Create a reloc section in dynobj and make room for
4833 name = (bfd_elf_string_from_elf_section
4835 elf_elfheader (abfd)->e_shstrndx,
4836 elf_section_data (sec)->rel_hdr.sh_name));
4840 if (! CONST_STRNEQ (name, ".rela")
4841 || strcmp (bfd_get_section_name (abfd, sec),
4844 (*_bfd_error_handler)
4845 (_("%B: bad relocation section name `%s\'"),
4847 bfd_set_error (bfd_error_bad_value);
4850 dynobj = htab->elf.dynobj;
4851 sreloc = bfd_get_section_by_name (dynobj, name);
4856 flags = (SEC_HAS_CONTENTS | SEC_READONLY
4857 | SEC_IN_MEMORY | SEC_LINKER_CREATED
4858 | SEC_ALLOC | SEC_LOAD);
4859 sreloc = bfd_make_section_with_flags (dynobj,
4863 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
4866 elf_section_data (sec)->sreloc = sreloc;
4869 /* If this is a global symbol, we count the number of
4870 relocations we need for this symbol. */
4873 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
4877 /* Track dynamic relocs needed for local syms too.
4878 We really need local syms available to do this
4884 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
4889 vpp = &elf_section_data (s)->local_dynrel;
4890 head = (struct ppc_dyn_relocs **) vpp;
4894 if (p == NULL || p->sec != sec)
4896 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
4907 if (!MUST_BE_DYN_RELOC (r_type))
4920 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4921 of the code entry point, and its section. */
4924 opd_entry_value (asection *opd_sec,
4926 asection **code_sec,
4929 bfd *opd_bfd = opd_sec->owner;
4930 Elf_Internal_Rela *relocs;
4931 Elf_Internal_Rela *lo, *hi, *look;
4934 /* No relocs implies we are linking a --just-symbols object. */
4935 if (opd_sec->reloc_count == 0)
4939 if (!bfd_get_section_contents (opd_bfd, opd_sec, &val, offset, 8))
4940 return (bfd_vma) -1;
4942 if (code_sec != NULL)
4944 asection *sec, *likely = NULL;
4945 for (sec = opd_bfd->sections; sec != NULL; sec = sec->next)
4947 && (sec->flags & SEC_LOAD) != 0
4948 && (sec->flags & SEC_ALLOC) != 0)
4953 if (code_off != NULL)
4954 *code_off = val - likely->vma;
4960 relocs = ppc64_elf_tdata (opd_bfd)->opd_relocs;
4962 relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
4964 /* Go find the opd reloc at the sym address. */
4966 BFD_ASSERT (lo != NULL);
4967 hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
4971 look = lo + (hi - lo) / 2;
4972 if (look->r_offset < offset)
4974 else if (look->r_offset > offset)
4978 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (opd_bfd)->symtab_hdr;
4979 if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64
4980 && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
4982 unsigned long symndx = ELF64_R_SYM (look->r_info);
4985 if (symndx < symtab_hdr->sh_info)
4987 Elf_Internal_Sym *sym;
4989 sym = (Elf_Internal_Sym *) symtab_hdr->contents;
4992 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
4993 symtab_hdr->sh_info,
4994 0, NULL, NULL, NULL);
4997 symtab_hdr->contents = (bfd_byte *) sym;
5001 val = sym->st_value;
5003 if ((sym->st_shndx != SHN_UNDEF
5004 && sym->st_shndx < SHN_LORESERVE)
5005 || sym->st_shndx > SHN_HIRESERVE)
5006 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
5007 BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
5011 struct elf_link_hash_entry **sym_hashes;
5012 struct elf_link_hash_entry *rh;
5014 sym_hashes = elf_sym_hashes (opd_bfd);
5015 rh = sym_hashes[symndx - symtab_hdr->sh_info];
5016 while (rh->root.type == bfd_link_hash_indirect
5017 || rh->root.type == bfd_link_hash_warning)
5018 rh = ((struct elf_link_hash_entry *) rh->root.u.i.link);
5019 BFD_ASSERT (rh->root.type == bfd_link_hash_defined
5020 || rh->root.type == bfd_link_hash_defweak);
5021 val = rh->root.u.def.value;
5022 sec = rh->root.u.def.section;
5024 val += look->r_addend;
5025 if (code_off != NULL)
5027 if (code_sec != NULL)
5029 if (sec != NULL && sec->output_section != NULL)
5030 val += sec->output_section->vma + sec->output_offset;
5039 /* Mark sections containing dynamically referenced symbols. When
5040 building shared libraries, we must assume that any visible symbol is
5044 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
5046 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5047 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
5049 if (eh->elf.root.type == bfd_link_hash_warning)
5050 eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
5052 /* Dynamic linking info is on the func descriptor sym. */
5054 && eh->oh->is_func_descriptor
5055 && (eh->oh->elf.root.type == bfd_link_hash_defined
5056 || eh->oh->elf.root.type == bfd_link_hash_defweak))
5059 if ((eh->elf.root.type == bfd_link_hash_defined
5060 || eh->elf.root.type == bfd_link_hash_defweak)
5061 && (eh->elf.ref_dynamic
5062 || (!info->executable
5063 && eh->elf.def_regular
5064 && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
5065 && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN)))
5069 eh->elf.root.u.def.section->flags |= SEC_KEEP;
5071 /* Function descriptor syms cause the associated
5072 function code sym section to be marked. */
5073 if (eh->is_func_descriptor
5074 && (eh->oh->elf.root.type == bfd_link_hash_defined
5075 || eh->oh->elf.root.type == bfd_link_hash_defweak))
5076 eh->oh->elf.root.u.def.section->flags |= SEC_KEEP;
5077 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
5078 && opd_entry_value (eh->elf.root.u.def.section,
5079 eh->elf.root.u.def.value,
5080 &code_sec, NULL) != (bfd_vma) -1)
5081 code_sec->flags |= SEC_KEEP;
5087 /* Return the section that should be marked against GC for a given
5091 ppc64_elf_gc_mark_hook (asection *sec,
5092 struct bfd_link_info *info,
5093 Elf_Internal_Rela *rel,
5094 struct elf_link_hash_entry *h,
5095 Elf_Internal_Sym *sym)
5099 /* First mark all our entry sym sections. */
5100 if (info->gc_sym_list != NULL)
5102 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5103 struct bfd_sym_chain *sym = info->gc_sym_list;
5105 info->gc_sym_list = NULL;
5106 for (; sym != NULL; sym = sym->next)
5108 struct ppc_link_hash_entry *eh;
5110 eh = (struct ppc_link_hash_entry *)
5111 elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE);
5114 if (eh->elf.root.type != bfd_link_hash_defined
5115 && eh->elf.root.type != bfd_link_hash_defweak)
5118 if (eh->is_func_descriptor
5119 && (eh->oh->elf.root.type == bfd_link_hash_defined
5120 || eh->oh->elf.root.type == bfd_link_hash_defweak))
5121 rsec = eh->oh->elf.root.u.def.section;
5122 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
5123 && opd_entry_value (eh->elf.root.u.def.section,
5124 eh->elf.root.u.def.value,
5125 &rsec, NULL) != (bfd_vma) -1)
5131 _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook);
5133 rsec = eh->elf.root.u.def.section;
5135 _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook);
5139 /* Syms return NULL if we're marking .opd, so we avoid marking all
5140 function sections, as all functions are referenced in .opd. */
5142 if (get_opd_info (sec) != NULL)
5147 enum elf_ppc64_reloc_type r_type;
5148 struct ppc_link_hash_entry *eh;
5150 r_type = ELF64_R_TYPE (rel->r_info);
5153 case R_PPC64_GNU_VTINHERIT:
5154 case R_PPC64_GNU_VTENTRY:
5158 switch (h->root.type)
5160 case bfd_link_hash_defined:
5161 case bfd_link_hash_defweak:
5162 eh = (struct ppc_link_hash_entry *) h;
5164 && eh->oh->is_func_descriptor
5165 && (eh->oh->elf.root.type == bfd_link_hash_defined
5166 || eh->oh->elf.root.type == bfd_link_hash_defweak))
5169 /* Function descriptor syms cause the associated
5170 function code sym section to be marked. */
5171 if (eh->is_func_descriptor
5172 && (eh->oh->elf.root.type == bfd_link_hash_defined
5173 || eh->oh->elf.root.type == bfd_link_hash_defweak))
5175 /* They also mark their opd section. */
5176 if (!eh->elf.root.u.def.section->gc_mark)
5177 _bfd_elf_gc_mark (info, eh->elf.root.u.def.section,
5178 ppc64_elf_gc_mark_hook);
5180 rsec = eh->oh->elf.root.u.def.section;
5182 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
5183 && opd_entry_value (eh->elf.root.u.def.section,
5184 eh->elf.root.u.def.value,
5185 &rsec, NULL) != (bfd_vma) -1)
5187 if (!eh->elf.root.u.def.section->gc_mark)
5188 _bfd_elf_gc_mark (info, eh->elf.root.u.def.section,
5189 ppc64_elf_gc_mark_hook);
5192 rsec = h->root.u.def.section;
5195 case bfd_link_hash_common:
5196 rsec = h->root.u.c.p->section;
5206 asection **opd_sym_section;
5208 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
5209 opd_sym_section = get_opd_info (rsec);
5210 if (opd_sym_section != NULL)
5213 _bfd_elf_gc_mark (info, rsec, ppc64_elf_gc_mark_hook);
5215 rsec = opd_sym_section[(sym->st_value + rel->r_addend) / 8];
5222 /* Update the .got, .plt. and dynamic reloc reference counts for the
5223 section being removed. */
5226 ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
5227 asection *sec, const Elf_Internal_Rela *relocs)
5229 struct ppc_link_hash_table *htab;
5230 Elf_Internal_Shdr *symtab_hdr;
5231 struct elf_link_hash_entry **sym_hashes;
5232 struct got_entry **local_got_ents;
5233 const Elf_Internal_Rela *rel, *relend;
5235 if ((sec->flags & SEC_ALLOC) == 0)
5238 elf_section_data (sec)->local_dynrel = NULL;
5240 htab = ppc_hash_table (info);
5241 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5242 sym_hashes = elf_sym_hashes (abfd);
5243 local_got_ents = elf_local_got_ents (abfd);
5245 relend = relocs + sec->reloc_count;
5246 for (rel = relocs; rel < relend; rel++)
5248 unsigned long r_symndx;
5249 enum elf_ppc64_reloc_type r_type;
5250 struct elf_link_hash_entry *h = NULL;
5253 r_symndx = ELF64_R_SYM (rel->r_info);
5254 r_type = ELF64_R_TYPE (rel->r_info);
5255 if (r_symndx >= symtab_hdr->sh_info)
5257 struct ppc_link_hash_entry *eh;
5258 struct ppc_dyn_relocs **pp;
5259 struct ppc_dyn_relocs *p;
5261 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5262 while (h->root.type == bfd_link_hash_indirect
5263 || h->root.type == bfd_link_hash_warning)
5264 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5265 eh = (struct ppc_link_hash_entry *) h;
5267 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
5270 /* Everything must go for SEC. */
5278 case R_PPC64_GOT_TLSLD16:
5279 case R_PPC64_GOT_TLSLD16_LO:
5280 case R_PPC64_GOT_TLSLD16_HI:
5281 case R_PPC64_GOT_TLSLD16_HA:
5282 ppc64_tlsld_got (abfd)->refcount -= 1;
5283 tls_type = TLS_TLS | TLS_LD;
5286 case R_PPC64_GOT_TLSGD16:
5287 case R_PPC64_GOT_TLSGD16_LO:
5288 case R_PPC64_GOT_TLSGD16_HI:
5289 case R_PPC64_GOT_TLSGD16_HA:
5290 tls_type = TLS_TLS | TLS_GD;
5293 case R_PPC64_GOT_TPREL16_DS:
5294 case R_PPC64_GOT_TPREL16_LO_DS:
5295 case R_PPC64_GOT_TPREL16_HI:
5296 case R_PPC64_GOT_TPREL16_HA:
5297 tls_type = TLS_TLS | TLS_TPREL;
5300 case R_PPC64_GOT_DTPREL16_DS:
5301 case R_PPC64_GOT_DTPREL16_LO_DS:
5302 case R_PPC64_GOT_DTPREL16_HI:
5303 case R_PPC64_GOT_DTPREL16_HA:
5304 tls_type = TLS_TLS | TLS_DTPREL;
5308 case R_PPC64_GOT16_DS:
5309 case R_PPC64_GOT16_HA:
5310 case R_PPC64_GOT16_HI:
5311 case R_PPC64_GOT16_LO:
5312 case R_PPC64_GOT16_LO_DS:
5315 struct got_entry *ent;
5320 ent = local_got_ents[r_symndx];
5322 for (; ent != NULL; ent = ent->next)
5323 if (ent->addend == rel->r_addend
5324 && ent->owner == abfd
5325 && ent->tls_type == tls_type)
5329 if (ent->got.refcount > 0)
5330 ent->got.refcount -= 1;
5334 case R_PPC64_PLT16_HA:
5335 case R_PPC64_PLT16_HI:
5336 case R_PPC64_PLT16_LO:
5340 case R_PPC64_REL14_BRNTAKEN:
5341 case R_PPC64_REL14_BRTAKEN:
5345 struct plt_entry *ent;
5347 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
5348 if (ent->addend == rel->r_addend)
5352 if (ent->plt.refcount > 0)
5353 ent->plt.refcount -= 1;
5364 /* The maximum size of .sfpr. */
5365 #define SFPR_MAX (218*4)
5367 struct sfpr_def_parms
5369 const char name[12];
5370 unsigned char lo, hi;
5371 bfd_byte * (*write_ent) (bfd *, bfd_byte *, int);
5372 bfd_byte * (*write_tail) (bfd *, bfd_byte *, int);
5375 /* Auto-generate _save*, _rest* functions in .sfpr. */
5378 sfpr_define (struct bfd_link_info *info, const struct sfpr_def_parms *parm)
5380 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5382 size_t len = strlen (parm->name);
5383 bfd_boolean writing = FALSE;
5386 memcpy (sym, parm->name, len);
5389 for (i = parm->lo; i <= parm->hi; i++)
5391 struct elf_link_hash_entry *h;
5393 sym[len + 0] = i / 10 + '0';
5394 sym[len + 1] = i % 10 + '0';
5395 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
5399 h->root.type = bfd_link_hash_defined;
5400 h->root.u.def.section = htab->sfpr;
5401 h->root.u.def.value = htab->sfpr->size;
5404 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
5406 if (htab->sfpr->contents == NULL)
5408 htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
5409 if (htab->sfpr->contents == NULL)
5415 bfd_byte *p = htab->sfpr->contents + htab->sfpr->size;
5417 p = (*parm->write_ent) (htab->elf.dynobj, p, i);
5419 p = (*parm->write_tail) (htab->elf.dynobj, p, i);
5420 htab->sfpr->size = p - htab->sfpr->contents;
5428 savegpr0 (bfd *abfd, bfd_byte *p, int r)
5430 bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
5435 savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
5437 p = savegpr0 (abfd, p, r);
5438 bfd_put_32 (abfd, STD_R0_0R1 + 16, p);
5440 bfd_put_32 (abfd, BLR, p);
5445 restgpr0 (bfd *abfd, bfd_byte *p, int r)
5447 bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
5452 restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
5454 bfd_put_32 (abfd, LD_R0_0R1 + 16, p);
5456 p = restgpr0 (abfd, p, r);
5457 bfd_put_32 (abfd, MTLR_R0, p);
5461 p = restgpr0 (abfd, p, 30);
5462 p = restgpr0 (abfd, p, 31);
5464 bfd_put_32 (abfd, BLR, p);
5469 savegpr1 (bfd *abfd, bfd_byte *p, int r)
5471 bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
5476 savegpr1_tail (bfd *abfd, bfd_byte *p, int r)
5478 p = savegpr1 (abfd, p, r);
5479 bfd_put_32 (abfd, BLR, p);
5484 restgpr1 (bfd *abfd, bfd_byte *p, int r)
5486 bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
5491 restgpr1_tail (bfd *abfd, bfd_byte *p, int r)
5493 p = restgpr1 (abfd, p, r);
5494 bfd_put_32 (abfd, BLR, p);
5499 savefpr (bfd *abfd, bfd_byte *p, int r)
5501 bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
5506 savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
5508 p = savefpr (abfd, p, r);
5509 bfd_put_32 (abfd, STD_R0_0R1 + 16, p);
5511 bfd_put_32 (abfd, BLR, p);
5516 restfpr (bfd *abfd, bfd_byte *p, int r)
5518 bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
5523 restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
5525 bfd_put_32 (abfd, LD_R0_0R1 + 16, p);
5527 p = restfpr (abfd, p, r);
5528 bfd_put_32 (abfd, MTLR_R0, p);
5532 p = restfpr (abfd, p, 30);
5533 p = restfpr (abfd, p, 31);
5535 bfd_put_32 (abfd, BLR, p);
5540 savefpr1_tail (bfd *abfd, bfd_byte *p, int r)
5542 p = savefpr (abfd, p, r);
5543 bfd_put_32 (abfd, BLR, p);
5548 restfpr1_tail (bfd *abfd, bfd_byte *p, int r)
5550 p = restfpr (abfd, p, r);
5551 bfd_put_32 (abfd, BLR, p);
5556 savevr (bfd *abfd, bfd_byte *p, int r)
5558 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
5560 bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p);
5565 savevr_tail (bfd *abfd, bfd_byte *p, int r)
5567 p = savevr (abfd, p, r);
5568 bfd_put_32 (abfd, BLR, p);
5573 restvr (bfd *abfd, bfd_byte *p, int r)
5575 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
5577 bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p);
5582 restvr_tail (bfd *abfd, bfd_byte *p, int r)
5584 p = restvr (abfd, p, r);
5585 bfd_put_32 (abfd, BLR, p);
5589 /* Called via elf_link_hash_traverse to transfer dynamic linking
5590 information on function code symbol entries to their corresponding
5591 function descriptor symbol entries. */
5594 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
5596 struct bfd_link_info *info;
5597 struct ppc_link_hash_table *htab;
5598 struct plt_entry *ent;
5599 struct ppc_link_hash_entry *fh;
5600 struct ppc_link_hash_entry *fdh;
5601 bfd_boolean force_local;
5603 fh = (struct ppc_link_hash_entry *) h;
5604 if (fh->elf.root.type == bfd_link_hash_indirect)
5607 if (fh->elf.root.type == bfd_link_hash_warning)
5608 fh = (struct ppc_link_hash_entry *) fh->elf.root.u.i.link;
5611 htab = ppc_hash_table (info);
5613 /* Resolve undefined references to dot-symbols as the value
5614 in the function descriptor, if we have one in a regular object.
5615 This is to satisfy cases like ".quad .foo". Calls to functions
5616 in dynamic objects are handled elsewhere. */
5617 if (fh->elf.root.type == bfd_link_hash_undefweak
5618 && fh->was_undefined
5619 && (fh->oh->elf.root.type == bfd_link_hash_defined
5620 || fh->oh->elf.root.type == bfd_link_hash_defweak)
5621 && get_opd_info (fh->oh->elf.root.u.def.section) != NULL
5622 && opd_entry_value (fh->oh->elf.root.u.def.section,
5623 fh->oh->elf.root.u.def.value,
5624 &fh->elf.root.u.def.section,
5625 &fh->elf.root.u.def.value) != (bfd_vma) -1)
5627 fh->elf.root.type = fh->oh->elf.root.type;
5628 fh->elf.forced_local = 1;
5631 /* If this is a function code symbol, transfer dynamic linking
5632 information to the function descriptor symbol. */
5636 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
5637 if (ent->plt.refcount > 0)
5640 || fh->elf.root.root.string[0] != '.'
5641 || fh->elf.root.root.string[1] == '\0')
5644 /* Find the corresponding function descriptor symbol. Create it
5645 as undefined if necessary. */
5647 fdh = get_fdh (fh, htab);
5649 while (fdh->elf.root.type == bfd_link_hash_indirect
5650 || fdh->elf.root.type == bfd_link_hash_warning)
5651 fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link;
5655 && (fh->elf.root.type == bfd_link_hash_undefined
5656 || fh->elf.root.type == bfd_link_hash_undefweak))
5658 fdh = make_fdh (info, fh);
5663 /* Fake function descriptors are made undefweak. If the function
5664 code symbol is strong undefined, make the fake sym the same.
5665 If the function code symbol is defined, then force the fake
5666 descriptor local; We can't support overriding of symbols in a
5667 shared library on a fake descriptor. */
5671 && fdh->elf.root.type == bfd_link_hash_undefweak)
5673 if (fh->elf.root.type == bfd_link_hash_undefined)
5675 fdh->elf.root.type = bfd_link_hash_undefined;
5676 bfd_link_add_undef (&htab->elf.root, &fdh->elf.root);
5678 else if (fh->elf.root.type == bfd_link_hash_defined
5679 || fh->elf.root.type == bfd_link_hash_defweak)
5681 _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
5686 && !fdh->elf.forced_local
5688 || fdh->elf.def_dynamic
5689 || fdh->elf.ref_dynamic
5690 || (fdh->elf.root.type == bfd_link_hash_undefweak
5691 && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT)))
5693 if (fdh->elf.dynindx == -1)
5694 if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
5696 fdh->elf.ref_regular |= fh->elf.ref_regular;
5697 fdh->elf.ref_dynamic |= fh->elf.ref_dynamic;
5698 fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak;
5699 fdh->elf.non_got_ref |= fh->elf.non_got_ref;
5700 if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT)
5702 move_plt_plist (fh, fdh);
5703 fdh->elf.needs_plt = 1;
5705 fdh->is_func_descriptor = 1;
5710 /* Now that the info is on the function descriptor, clear the
5711 function code sym info. Any function code syms for which we
5712 don't have a definition in a regular file, we force local.
5713 This prevents a shared library from exporting syms that have
5714 been imported from another library. Function code syms that
5715 are really in the library we must leave global to prevent the
5716 linker dragging in a definition from a static library. */
5717 force_local = (!fh->elf.def_regular
5719 || !fdh->elf.def_regular
5720 || fdh->elf.forced_local);
5721 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
5726 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5727 this hook to a) provide some gcc support functions, and b) transfer
5728 dynamic linking information gathered so far on function code symbol
5729 entries, to their corresponding function descriptor symbol entries. */
5732 ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
5733 struct bfd_link_info *info)
5735 struct ppc_link_hash_table *htab;
5737 const struct sfpr_def_parms funcs[] =
5739 { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail },
5740 { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail },
5741 { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail },
5742 { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail },
5743 { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail },
5744 { "_savefpr_", 14, 31, savefpr, savefpr0_tail },
5745 { "_restfpr_", 14, 29, restfpr, restfpr0_tail },
5746 { "_restfpr_", 30, 31, restfpr, restfpr0_tail },
5747 { "._savef", 14, 31, savefpr, savefpr1_tail },
5748 { "._restf", 14, 31, restfpr, restfpr1_tail },
5749 { "_savevr_", 20, 31, savevr, savevr_tail },
5750 { "_restvr_", 20, 31, restvr, restvr_tail }
5753 htab = ppc_hash_table (info);
5754 if (htab->sfpr == NULL)
5755 /* We don't have any relocs. */
5758 /* Provide any missing _save* and _rest* functions. */
5759 htab->sfpr->size = 0;
5760 for (i = 0; i < sizeof (funcs) / sizeof (funcs[0]); i++)
5761 if (!sfpr_define (info, &funcs[i]))
5764 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
5766 if (htab->sfpr->size == 0)
5767 htab->sfpr->flags |= SEC_EXCLUDE;
5772 /* Adjust a symbol defined by a dynamic object and referenced by a
5773 regular object. The current definition is in some section of the
5774 dynamic object, but we're not including those sections. We have to
5775 change the definition to something the rest of the link can
5779 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
5780 struct elf_link_hash_entry *h)
5782 struct ppc_link_hash_table *htab;
5784 unsigned int power_of_two;
5786 htab = ppc_hash_table (info);
5788 /* Deal with function syms. */
5789 if (h->type == STT_FUNC
5792 /* Clear procedure linkage table information for any symbol that
5793 won't need a .plt entry. */
5794 struct plt_entry *ent;
5795 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
5796 if (ent->plt.refcount > 0)
5799 || SYMBOL_CALLS_LOCAL (info, h)
5800 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5801 && h->root.type == bfd_link_hash_undefweak))
5803 h->plt.plist = NULL;
5808 h->plt.plist = NULL;
5810 /* If this is a weak symbol, and there is a real definition, the
5811 processor independent code will have arranged for us to see the
5812 real definition first, and we can just use the same value. */
5813 if (h->u.weakdef != NULL)
5815 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5816 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5817 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5818 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5819 if (ELIMINATE_COPY_RELOCS)
5820 h->non_got_ref = h->u.weakdef->non_got_ref;
5824 /* If we are creating a shared library, we must presume that the
5825 only references to the symbol are via the global offset table.
5826 For such cases we need not do anything here; the relocations will
5827 be handled correctly by relocate_section. */
5831 /* If there are no references to this symbol that do not use the
5832 GOT, we don't need to generate a copy reloc. */
5833 if (!h->non_got_ref)
5836 if (ELIMINATE_COPY_RELOCS)
5838 struct ppc_link_hash_entry * eh;
5839 struct ppc_dyn_relocs *p;
5841 eh = (struct ppc_link_hash_entry *) h;
5842 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5844 s = p->sec->output_section;
5845 if (s != NULL && (s->flags & SEC_READONLY) != 0)
5849 /* If we didn't find any dynamic relocs in read-only sections, then
5850 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
5858 if (h->plt.plist != NULL)
5860 /* We should never get here, but unfortunately there are versions
5861 of gcc out there that improperly (for this ABI) put initialized
5862 function pointers, vtable refs and suchlike in read-only
5863 sections. Allow them to proceed, but warn that this might
5864 break at runtime. */
5865 (*_bfd_error_handler)
5866 (_("copy reloc against `%s' requires lazy plt linking; "
5867 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
5868 h->root.root.string);
5871 /* This is a reference to a symbol defined by a dynamic object which
5872 is not a function. */
5876 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
5877 h->root.root.string);
5881 /* We must allocate the symbol in our .dynbss section, which will
5882 become part of the .bss section of the executable. There will be
5883 an entry for this symbol in the .dynsym section. The dynamic
5884 object will contain position independent code, so all references
5885 from the dynamic object to this symbol will go through the global
5886 offset table. The dynamic linker will use the .dynsym entry to
5887 determine the address it must put in the global offset table, so
5888 both the dynamic object and the regular object will refer to the
5889 same memory location for the variable. */
5891 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
5892 to copy the initial value out of the dynamic object and into the
5893 runtime process image. We need to remember the offset into the
5894 .rela.bss section we are going to use. */
5895 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
5897 htab->relbss->size += sizeof (Elf64_External_Rela);
5901 /* We need to figure out the alignment required for this symbol. I
5902 have no idea how ELF linkers handle this. */
5903 power_of_two = bfd_log2 (h->size);
5904 if (power_of_two > 4)
5907 /* Apply the required alignment. */
5909 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
5910 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
5912 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
5916 /* Define the symbol as being at this point in the section. */
5917 h->root.u.def.section = s;
5918 h->root.u.def.value = s->size;
5920 /* Increment the section size to make room for the symbol. */
5926 /* If given a function descriptor symbol, hide both the function code
5927 sym and the descriptor. */
5929 ppc64_elf_hide_symbol (struct bfd_link_info *info,
5930 struct elf_link_hash_entry *h,
5931 bfd_boolean force_local)
5933 struct ppc_link_hash_entry *eh;
5934 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
5936 eh = (struct ppc_link_hash_entry *) h;
5937 if (eh->is_func_descriptor)
5939 struct ppc_link_hash_entry *fh = eh->oh;
5944 struct ppc_link_hash_table *htab;
5947 /* We aren't supposed to use alloca in BFD because on
5948 systems which do not have alloca the version in libiberty
5949 calls xmalloc, which might cause the program to crash
5950 when it runs out of memory. This function doesn't have a
5951 return status, so there's no way to gracefully return an
5952 error. So cheat. We know that string[-1] can be safely
5953 accessed; It's either a string in an ELF string table,
5954 or allocated in an objalloc structure. */
5956 p = eh->elf.root.root.string - 1;
5959 htab = ppc_hash_table (info);
5960 fh = (struct ppc_link_hash_entry *)
5961 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
5964 /* Unfortunately, if it so happens that the string we were
5965 looking for was allocated immediately before this string,
5966 then we overwrote the string terminator. That's the only
5967 reason the lookup should fail. */
5970 q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
5971 while (q >= eh->elf.root.root.string && *q == *p)
5973 if (q < eh->elf.root.root.string && *p == '.')
5974 fh = (struct ppc_link_hash_entry *)
5975 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
5984 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
5989 get_sym_h (struct elf_link_hash_entry **hp,
5990 Elf_Internal_Sym **symp,
5993 Elf_Internal_Sym **locsymsp,
5994 unsigned long r_symndx,
5997 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
5999 if (r_symndx >= symtab_hdr->sh_info)
6001 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
6002 struct elf_link_hash_entry *h;
6004 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6005 while (h->root.type == bfd_link_hash_indirect
6006 || h->root.type == bfd_link_hash_warning)
6007 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6015 if (symsecp != NULL)
6017 asection *symsec = NULL;
6018 if (h->root.type == bfd_link_hash_defined
6019 || h->root.type == bfd_link_hash_defweak)
6020 symsec = h->root.u.def.section;
6024 if (tls_maskp != NULL)
6026 struct ppc_link_hash_entry *eh;
6028 eh = (struct ppc_link_hash_entry *) h;
6029 *tls_maskp = &eh->tls_mask;
6034 Elf_Internal_Sym *sym;
6035 Elf_Internal_Sym *locsyms = *locsymsp;
6037 if (locsyms == NULL)
6039 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
6040 if (locsyms == NULL)
6041 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
6042 symtab_hdr->sh_info,
6043 0, NULL, NULL, NULL);
6044 if (locsyms == NULL)
6046 *locsymsp = locsyms;
6048 sym = locsyms + r_symndx;
6056 if (symsecp != NULL)
6058 asection *symsec = NULL;
6059 if ((sym->st_shndx != SHN_UNDEF
6060 && sym->st_shndx < SHN_LORESERVE)
6061 || sym->st_shndx > SHN_HIRESERVE)
6062 symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx);
6066 if (tls_maskp != NULL)
6068 struct got_entry **lgot_ents;
6072 lgot_ents = elf_local_got_ents (ibfd);
6073 if (lgot_ents != NULL)
6075 char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info);
6076 tls_mask = &lgot_masks[r_symndx];
6078 *tls_maskp = tls_mask;
6084 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6085 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6086 type suitable for optimization, and 1 otherwise. */
6089 get_tls_mask (char **tls_maskp, unsigned long *toc_symndx,
6090 Elf_Internal_Sym **locsymsp,
6091 const Elf_Internal_Rela *rel, bfd *ibfd)
6093 unsigned long r_symndx;
6095 struct elf_link_hash_entry *h;
6096 Elf_Internal_Sym *sym;
6100 r_symndx = ELF64_R_SYM (rel->r_info);
6101 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
6104 if ((*tls_maskp != NULL && **tls_maskp != 0)
6106 || ppc64_elf_section_data (sec)->sec_type != sec_toc)
6109 /* Look inside a TOC section too. */
6112 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
6113 off = h->root.u.def.value;
6116 off = sym->st_value;
6117 off += rel->r_addend;
6118 BFD_ASSERT (off % 8 == 0);
6119 r_symndx = ppc64_elf_section_data (sec)->u.t_symndx[off / 8];
6120 next_r = ppc64_elf_section_data (sec)->u.t_symndx[off / 8 + 1];
6121 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
6123 if (toc_symndx != NULL)
6124 *toc_symndx = r_symndx;
6126 || ((h->root.type == bfd_link_hash_defined
6127 || h->root.type == bfd_link_hash_defweak)
6128 && !h->def_dynamic))
6129 && (next_r == -1 || next_r == -2))
6134 /* Adjust all global syms defined in opd sections. In gcc generated
6135 code for the old ABI, these will already have been done. */
6138 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
6140 struct ppc_link_hash_entry *eh;
6144 if (h->root.type == bfd_link_hash_indirect)
6147 if (h->root.type == bfd_link_hash_warning)
6148 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6150 if (h->root.type != bfd_link_hash_defined
6151 && h->root.type != bfd_link_hash_defweak)
6154 eh = (struct ppc_link_hash_entry *) h;
6155 if (eh->adjust_done)
6158 sym_sec = eh->elf.root.u.def.section;
6159 opd_adjust = get_opd_info (sym_sec);
6160 if (opd_adjust != NULL)
6162 long adjust = opd_adjust[eh->elf.root.u.def.value / 8];
6165 /* This entry has been deleted. */
6166 asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section;
6169 for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next)
6170 if (elf_discarded_section (dsec))
6172 ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec;
6176 eh->elf.root.u.def.value = 0;
6177 eh->elf.root.u.def.section = dsec;
6180 eh->elf.root.u.def.value += adjust;
6181 eh->adjust_done = 1;
6186 /* Handles decrementing dynamic reloc counts for the reloc specified by
6187 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6188 have already been determined. */
6191 dec_dynrel_count (bfd_vma r_info,
6193 struct bfd_link_info *info,
6194 Elf_Internal_Sym **local_syms,
6195 struct elf_link_hash_entry *h,
6198 enum elf_ppc64_reloc_type r_type;
6199 struct ppc_dyn_relocs *p;
6200 struct ppc_dyn_relocs **pp;
6202 /* Can this reloc be dynamic? This switch, and later tests here
6203 should be kept in sync with the code in check_relocs. */
6204 r_type = ELF64_R_TYPE (r_info);
6210 case R_PPC64_TPREL16:
6211 case R_PPC64_TPREL16_LO:
6212 case R_PPC64_TPREL16_HI:
6213 case R_PPC64_TPREL16_HA:
6214 case R_PPC64_TPREL16_DS:
6215 case R_PPC64_TPREL16_LO_DS:
6216 case R_PPC64_TPREL16_HIGHER:
6217 case R_PPC64_TPREL16_HIGHERA:
6218 case R_PPC64_TPREL16_HIGHEST:
6219 case R_PPC64_TPREL16_HIGHESTA:
6223 case R_PPC64_TPREL64:
6224 case R_PPC64_DTPMOD64:
6225 case R_PPC64_DTPREL64:
6226 case R_PPC64_ADDR64:
6230 case R_PPC64_ADDR14:
6231 case R_PPC64_ADDR14_BRNTAKEN:
6232 case R_PPC64_ADDR14_BRTAKEN:
6233 case R_PPC64_ADDR16:
6234 case R_PPC64_ADDR16_DS:
6235 case R_PPC64_ADDR16_HA:
6236 case R_PPC64_ADDR16_HI:
6237 case R_PPC64_ADDR16_HIGHER:
6238 case R_PPC64_ADDR16_HIGHERA:
6239 case R_PPC64_ADDR16_HIGHEST:
6240 case R_PPC64_ADDR16_HIGHESTA:
6241 case R_PPC64_ADDR16_LO:
6242 case R_PPC64_ADDR16_LO_DS:
6243 case R_PPC64_ADDR24:
6244 case R_PPC64_ADDR32:
6245 case R_PPC64_UADDR16:
6246 case R_PPC64_UADDR32:
6247 case R_PPC64_UADDR64:
6252 if (local_syms != NULL)
6254 unsigned long r_symndx;
6255 Elf_Internal_Sym *sym;
6256 bfd *ibfd = sec->owner;
6258 r_symndx = ELF64_R_SYM (r_info);
6259 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
6264 && (MUST_BE_DYN_RELOC (r_type)
6267 || h->root.type == bfd_link_hash_defweak
6268 || !h->def_regular))))
6269 || (ELIMINATE_COPY_RELOCS
6272 && (h->root.type == bfd_link_hash_defweak
6273 || !h->def_regular)))
6279 pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
6282 if (sym_sec != NULL)
6284 void *vpp = &elf_section_data (sym_sec)->local_dynrel;
6285 pp = (struct ppc_dyn_relocs **) vpp;
6289 void *vpp = &elf_section_data (sec)->local_dynrel;
6290 pp = (struct ppc_dyn_relocs **) vpp;
6293 /* elf_gc_sweep may have already removed all dyn relocs associated
6294 with local syms for a given section. Don't report a dynreloc
6300 while ((p = *pp) != NULL)
6304 if (!MUST_BE_DYN_RELOC (r_type))
6314 (*_bfd_error_handler) (_("dynreloc miscount for %B, section %A"),
6316 bfd_set_error (bfd_error_bad_value);
6320 /* Remove unused Official Procedure Descriptor entries. Currently we
6321 only remove those associated with functions in discarded link-once
6322 sections, or weakly defined functions that have been overridden. It
6323 would be possible to remove many more entries for statically linked
6327 ppc64_elf_edit_opd (bfd *obfd, struct bfd_link_info *info,
6328 bfd_boolean no_opd_opt,
6329 bfd_boolean non_overlapping)
6332 bfd_boolean some_edited = FALSE;
6333 asection *need_pad = NULL;
6335 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6338 Elf_Internal_Rela *relstart, *rel, *relend;
6339 Elf_Internal_Shdr *symtab_hdr;
6340 Elf_Internal_Sym *local_syms;
6341 struct elf_link_hash_entry **sym_hashes;
6345 bfd_boolean need_edit, add_aux_fields;
6346 bfd_size_type cnt_16b = 0;
6348 sec = bfd_get_section_by_name (ibfd, ".opd");
6349 if (sec == NULL || sec->size == 0)
6352 amt = sec->size * sizeof (long) / 8;
6353 opd_adjust = get_opd_info (sec);
6354 if (opd_adjust == NULL)
6356 /* check_relocs hasn't been called. Must be a ld -r link
6357 or --just-symbols object. */
6358 opd_adjust = bfd_alloc (obfd, amt);
6359 if (opd_adjust == NULL)
6361 ppc64_elf_section_data (sec)->u.opd_adjust = opd_adjust;
6362 BFD_ASSERT (ppc64_elf_section_data (sec)->sec_type == sec_normal);
6363 ppc64_elf_section_data (sec)->sec_type = sec_opd;
6365 memset (opd_adjust, 0, amt);
6370 if (sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS)
6373 if (sec->output_section == bfd_abs_section_ptr)
6376 /* Look through the section relocs. */
6377 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
6381 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
6382 sym_hashes = elf_sym_hashes (ibfd);
6384 /* Read the relocations. */
6385 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
6387 if (relstart == NULL)
6390 /* First run through the relocs to check they are sane, and to
6391 determine whether we need to edit this opd section. */
6395 relend = relstart + sec->reloc_count;
6396 for (rel = relstart; rel < relend; )
6398 enum elf_ppc64_reloc_type r_type;
6399 unsigned long r_symndx;
6401 struct elf_link_hash_entry *h;
6402 Elf_Internal_Sym *sym;
6404 /* .opd contains a regular array of 16 or 24 byte entries. We're
6405 only interested in the reloc pointing to a function entry
6407 if (rel->r_offset != offset
6408 || rel + 1 >= relend
6409 || (rel + 1)->r_offset != offset + 8)
6411 /* If someone messes with .opd alignment then after a
6412 "ld -r" we might have padding in the middle of .opd.
6413 Also, there's nothing to prevent someone putting
6414 something silly in .opd with the assembler. No .opd
6415 optimization for them! */
6417 (*_bfd_error_handler)
6418 (_("%B: .opd is not a regular array of opd entries"), ibfd);
6423 if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
6424 || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
6426 (*_bfd_error_handler)
6427 (_("%B: unexpected reloc type %u in .opd section"),
6433 r_symndx = ELF64_R_SYM (rel->r_info);
6434 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
6438 if (sym_sec == NULL || sym_sec->owner == NULL)
6440 const char *sym_name;
6442 sym_name = h->root.root.string;
6444 sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym,
6447 (*_bfd_error_handler)
6448 (_("%B: undefined sym `%s' in .opd section"),
6454 /* opd entries are always for functions defined in the
6455 current input bfd. If the symbol isn't defined in the
6456 input bfd, then we won't be using the function in this
6457 bfd; It must be defined in a linkonce section in another
6458 bfd, or is weak. It's also possible that we are
6459 discarding the function due to a linker script /DISCARD/,
6460 which we test for via the output_section. */
6461 if (sym_sec->owner != ibfd
6462 || sym_sec->output_section == bfd_abs_section_ptr)
6467 || (rel + 1 == relend && rel->r_offset == offset + 16))
6469 if (sec->size == offset + 24)
6474 if (rel == relend && sec->size == offset + 16)
6482 if (rel->r_offset == offset + 24)
6484 else if (rel->r_offset != offset + 16)
6486 else if (rel + 1 < relend
6487 && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64
6488 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC)
6493 else if (rel + 2 < relend
6494 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_ADDR64
6495 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC)
6504 add_aux_fields = non_overlapping && cnt_16b > 0;
6506 if (need_edit || add_aux_fields)
6508 Elf_Internal_Rela *write_rel;
6509 bfd_byte *rptr, *wptr;
6510 bfd_byte *new_contents = NULL;
6514 /* This seems a waste of time as input .opd sections are all
6515 zeros as generated by gcc, but I suppose there's no reason
6516 this will always be so. We might start putting something in
6517 the third word of .opd entries. */
6518 if ((sec->flags & SEC_IN_MEMORY) == 0)
6521 if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
6526 if (local_syms != NULL
6527 && symtab_hdr->contents != (unsigned char *) local_syms)
6529 if (elf_section_data (sec)->relocs != relstart)
6533 sec->contents = loc;
6534 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
6537 elf_section_data (sec)->relocs = relstart;
6539 new_contents = sec->contents;
6542 new_contents = bfd_malloc (sec->size + cnt_16b * 8);
6543 if (new_contents == NULL)
6547 wptr = new_contents;
6548 rptr = sec->contents;
6550 write_rel = relstart;
6554 for (rel = relstart; rel < relend; rel++)
6556 unsigned long r_symndx;
6558 struct elf_link_hash_entry *h;
6559 Elf_Internal_Sym *sym;
6561 r_symndx = ELF64_R_SYM (rel->r_info);
6562 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
6566 if (rel->r_offset == offset)
6568 struct ppc_link_hash_entry *fdh = NULL;
6570 /* See if the .opd entry is full 24 byte or
6571 16 byte (with fd_aux entry overlapped with next
6574 if ((rel + 2 == relend && sec->size == offset + 16)
6575 || (rel + 3 < relend
6576 && rel[2].r_offset == offset + 16
6577 && rel[3].r_offset == offset + 24
6578 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_ADDR64
6579 && ELF64_R_TYPE (rel[3].r_info) == R_PPC64_TOC))
6583 && h->root.root.string[0] == '.')
6585 fdh = get_fdh ((struct ppc_link_hash_entry *) h,
6586 ppc_hash_table (info));
6588 && fdh->elf.root.type != bfd_link_hash_defined
6589 && fdh->elf.root.type != bfd_link_hash_defweak)
6593 skip = (sym_sec->owner != ibfd
6594 || sym_sec->output_section == bfd_abs_section_ptr);
6597 if (fdh != NULL && sym_sec->owner == ibfd)
6599 /* Arrange for the function descriptor sym
6601 fdh->elf.root.u.def.value = 0;
6602 fdh->elf.root.u.def.section = sym_sec;
6604 opd_adjust[rel->r_offset / 8] = -1;
6608 /* We'll be keeping this opd entry. */
6612 /* Redefine the function descriptor symbol to
6613 this location in the opd section. It is
6614 necessary to update the value here rather
6615 than using an array of adjustments as we do
6616 for local symbols, because various places
6617 in the generic ELF code use the value
6618 stored in u.def.value. */
6619 fdh->elf.root.u.def.value = wptr - new_contents;
6620 fdh->adjust_done = 1;
6623 /* Local syms are a bit tricky. We could
6624 tweak them as they can be cached, but
6625 we'd need to look through the local syms
6626 for the function descriptor sym which we
6627 don't have at the moment. So keep an
6628 array of adjustments. */
6629 opd_adjust[rel->r_offset / 8]
6630 = (wptr - new_contents) - (rptr - sec->contents);
6633 memcpy (wptr, rptr, opd_ent_size);
6634 wptr += opd_ent_size;
6635 if (add_aux_fields && opd_ent_size == 16)
6637 memset (wptr, '\0', 8);
6641 rptr += opd_ent_size;
6642 offset += opd_ent_size;
6648 && !info->relocatable
6649 && !dec_dynrel_count (rel->r_info, sec, info,
6655 /* We need to adjust any reloc offsets to point to the
6656 new opd entries. While we're at it, we may as well
6657 remove redundant relocs. */
6658 rel->r_offset += opd_adjust[(offset - opd_ent_size) / 8];
6659 if (write_rel != rel)
6660 memcpy (write_rel, rel, sizeof (*rel));
6665 sec->size = wptr - new_contents;
6666 sec->reloc_count = write_rel - relstart;
6669 free (sec->contents);
6670 sec->contents = new_contents;
6673 /* Fudge the header size too, as this is used later in
6674 elf_bfd_final_link if we are emitting relocs. */
6675 elf_section_data (sec)->rel_hdr.sh_size
6676 = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize;
6677 BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL);
6680 else if (elf_section_data (sec)->relocs != relstart)
6683 if (local_syms != NULL
6684 && symtab_hdr->contents != (unsigned char *) local_syms)
6686 if (!info->keep_memory)
6689 symtab_hdr->contents = (unsigned char *) local_syms;
6694 elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
6696 /* If we are doing a final link and the last .opd entry is just 16 byte
6697 long, add a 8 byte padding after it. */
6698 if (need_pad != NULL && !info->relocatable)
6702 if ((need_pad->flags & SEC_IN_MEMORY) == 0)
6704 BFD_ASSERT (need_pad->size > 0);
6706 p = bfd_malloc (need_pad->size + 8);
6710 if (! bfd_get_section_contents (need_pad->owner, need_pad,
6711 p, 0, need_pad->size))
6714 need_pad->contents = p;
6715 need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
6719 p = bfd_realloc (need_pad->contents, need_pad->size + 8);
6723 need_pad->contents = p;
6726 memset (need_pad->contents + need_pad->size, 0, 8);
6727 need_pad->size += 8;
6733 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
6736 ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
6738 struct ppc_link_hash_table *htab;
6740 htab = ppc_hash_table (info);
6741 if (htab->tls_get_addr != NULL)
6743 struct ppc_link_hash_entry *h = htab->tls_get_addr;
6745 while (h->elf.root.type == bfd_link_hash_indirect
6746 || h->elf.root.type == bfd_link_hash_warning)
6747 h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link;
6749 htab->tls_get_addr = h;
6751 if (htab->tls_get_addr_fd == NULL
6753 && h->oh->is_func_descriptor
6754 && (h->oh->elf.root.type == bfd_link_hash_defined
6755 || h->oh->elf.root.type == bfd_link_hash_defweak))
6756 htab->tls_get_addr_fd = h->oh;
6759 if (htab->tls_get_addr_fd != NULL)
6761 struct ppc_link_hash_entry *h = htab->tls_get_addr_fd;
6763 while (h->elf.root.type == bfd_link_hash_indirect
6764 || h->elf.root.type == bfd_link_hash_warning)
6765 h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link;
6767 htab->tls_get_addr_fd = h;
6770 return _bfd_elf_tls_setup (obfd, info);
6773 /* Run through all the TLS relocs looking for optimization
6774 opportunities. The linker has been hacked (see ppc64elf.em) to do
6775 a preliminary section layout so that we know the TLS segment
6776 offsets. We can't optimize earlier because some optimizations need
6777 to know the tp offset, and we need to optimize before allocating
6778 dynamic relocations. */
6781 ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
6785 struct ppc_link_hash_table *htab;
6787 if (info->relocatable || info->shared)
6790 htab = ppc_hash_table (info);
6791 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6793 Elf_Internal_Sym *locsyms = NULL;
6794 asection *toc = bfd_get_section_by_name (ibfd, ".toc");
6795 unsigned char *toc_ref = NULL;
6797 /* Look at all the sections for this file, with TOC last. */
6798 for (sec = (ibfd->sections == toc && toc && toc->next ? toc->next
6801 sec = (sec == toc ? NULL
6802 : sec->next == NULL ? toc
6803 : sec->next == toc && toc->next ? toc->next
6805 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
6807 Elf_Internal_Rela *relstart, *rel, *relend;
6808 int expecting_tls_get_addr;
6809 long toc_ref_index = 0;
6811 /* Read the relocations. */
6812 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
6814 if (relstart == NULL)
6817 expecting_tls_get_addr = 0;
6818 relend = relstart + sec->reloc_count;
6819 for (rel = relstart; rel < relend; rel++)
6821 enum elf_ppc64_reloc_type r_type;
6822 unsigned long r_symndx;
6823 struct elf_link_hash_entry *h;
6824 Elf_Internal_Sym *sym;
6827 char tls_set, tls_clear, tls_type = 0;
6829 bfd_boolean ok_tprel, is_local;
6831 r_symndx = ELF64_R_SYM (rel->r_info);
6832 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
6836 if (elf_section_data (sec)->relocs != relstart)
6838 if (toc_ref != NULL)
6841 && (elf_tdata (ibfd)->symtab_hdr.contents
6842 != (unsigned char *) locsyms))
6849 if (h->root.type != bfd_link_hash_defined
6850 && h->root.type != bfd_link_hash_defweak)
6852 value = h->root.u.def.value;
6855 /* Symbols referenced by TLS relocs must be of type
6856 STT_TLS. So no need for .opd local sym adjust. */
6857 value = sym->st_value;
6865 value += sym_sec->output_offset;
6866 value += sym_sec->output_section->vma;
6867 value -= htab->elf.tls_sec->vma;
6868 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
6869 < (bfd_vma) 1 << 32);
6872 r_type = ELF64_R_TYPE (rel->r_info);
6875 case R_PPC64_GOT_TLSLD16:
6876 case R_PPC64_GOT_TLSLD16_LO:
6877 case R_PPC64_GOT_TLSLD16_HI:
6878 case R_PPC64_GOT_TLSLD16_HA:
6879 /* These relocs should never be against a symbol
6880 defined in a shared lib. Leave them alone if
6881 that turns out to be the case. */
6882 ppc64_tlsld_got (ibfd)->refcount -= 1;
6889 tls_type = TLS_TLS | TLS_LD;
6890 expecting_tls_get_addr = 1;
6893 case R_PPC64_GOT_TLSGD16:
6894 case R_PPC64_GOT_TLSGD16_LO:
6895 case R_PPC64_GOT_TLSGD16_HI:
6896 case R_PPC64_GOT_TLSGD16_HA:
6902 tls_set = TLS_TLS | TLS_TPRELGD;
6904 tls_type = TLS_TLS | TLS_GD;
6905 expecting_tls_get_addr = 1;
6908 case R_PPC64_GOT_TPREL16_DS:
6909 case R_PPC64_GOT_TPREL16_LO_DS:
6910 case R_PPC64_GOT_TPREL16_HI:
6911 case R_PPC64_GOT_TPREL16_HA:
6912 expecting_tls_get_addr = 0;
6917 tls_clear = TLS_TPREL;
6918 tls_type = TLS_TLS | TLS_TPREL;
6925 case R_PPC64_REL14_BRTAKEN:
6926 case R_PPC64_REL14_BRNTAKEN:
6929 && (h == &htab->tls_get_addr->elf
6930 || h == &htab->tls_get_addr_fd->elf))
6932 if (!expecting_tls_get_addr
6934 && ((ELF64_R_TYPE (rel[-1].r_info)
6936 || (ELF64_R_TYPE (rel[-1].r_info)
6937 == R_PPC64_TOC16_LO)))
6939 /* Check for toc tls entries. */
6943 retval = get_tls_mask (&toc_tls, NULL, &locsyms,
6947 if (retval > 1 && toc_tls != NULL)
6949 expecting_tls_get_addr = 1;
6950 if (toc_ref != NULL)
6951 toc_ref[toc_ref_index] = 1;
6955 if (expecting_tls_get_addr)
6957 struct plt_entry *ent;
6958 for (ent = h->plt.plist; ent; ent = ent->next)
6959 if (ent->addend == 0)
6961 if (ent->plt.refcount > 0)
6962 ent->plt.refcount -= 1;
6967 expecting_tls_get_addr = 0;
6971 case R_PPC64_TOC16_LO:
6973 expecting_tls_get_addr = 0;
6974 if (sym_sec == toc && toc != NULL)
6976 /* Mark this toc entry as referenced by a TLS
6977 code sequence. We can do that now in the
6978 case of R_PPC64_TLS, and after checking for
6979 tls_get_addr for the TOC16 relocs. */
6980 if (toc_ref == NULL)
6982 toc_ref = bfd_zmalloc (toc->size / 8);
6983 if (toc_ref == NULL)
6987 value = h->root.u.def.value;
6989 value = sym->st_value;
6990 value += rel->r_addend;
6991 BFD_ASSERT (value < toc->size && value % 8 == 0);
6992 toc_ref_index = value / 8;
6993 if (r_type == R_PPC64_TLS)
6994 toc_ref[toc_ref_index] = 1;
6998 case R_PPC64_TPREL64:
6999 expecting_tls_get_addr = 0;
7002 || !toc_ref[rel->r_offset / 8])
7007 tls_set = TLS_EXPLICIT;
7008 tls_clear = TLS_TPREL;
7014 case R_PPC64_DTPMOD64:
7015 expecting_tls_get_addr = 0;
7018 || !toc_ref[rel->r_offset / 8])
7020 if (rel + 1 < relend
7022 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
7023 && rel[1].r_offset == rel->r_offset + 8)
7027 tls_set = TLS_EXPLICIT | TLS_GD;
7030 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
7039 tls_set = TLS_EXPLICIT;
7045 expecting_tls_get_addr = 0;
7049 if ((tls_set & TLS_EXPLICIT) == 0)
7051 struct got_entry *ent;
7053 /* Adjust got entry for this reloc. */
7057 ent = elf_local_got_ents (ibfd)[r_symndx];
7059 for (; ent != NULL; ent = ent->next)
7060 if (ent->addend == rel->r_addend
7061 && ent->owner == ibfd
7062 && ent->tls_type == tls_type)
7069 /* We managed to get rid of a got entry. */
7070 if (ent->got.refcount > 0)
7071 ent->got.refcount -= 1;
7076 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7077 we'll lose one or two dyn relocs. */
7078 if (!dec_dynrel_count (rel->r_info, sec, info,
7082 if (tls_set == (TLS_EXPLICIT | TLS_GD))
7084 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
7090 *tls_mask |= tls_set;
7091 *tls_mask &= ~tls_clear;
7094 if (elf_section_data (sec)->relocs != relstart)
7098 if (toc_ref != NULL)
7102 && (elf_tdata (ibfd)->symtab_hdr.contents
7103 != (unsigned char *) locsyms))
7105 if (!info->keep_memory)
7108 elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms;
7114 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7115 the values of any global symbols in a toc section that has been
7116 edited. Globals in toc sections should be a rarity, so this function
7117 sets a flag if any are found in toc sections other than the one just
7118 edited, so that futher hash table traversals can be avoided. */
7120 struct adjust_toc_info
7123 unsigned long *skip;
7124 bfd_boolean global_toc_syms;
7128 adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
7130 struct ppc_link_hash_entry *eh;
7131 struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf;
7133 if (h->root.type == bfd_link_hash_indirect)
7136 if (h->root.type == bfd_link_hash_warning)
7137 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7139 if (h->root.type != bfd_link_hash_defined
7140 && h->root.type != bfd_link_hash_defweak)
7143 eh = (struct ppc_link_hash_entry *) h;
7144 if (eh->adjust_done)
7147 if (eh->elf.root.u.def.section == toc_inf->toc)
7149 unsigned long skip = toc_inf->skip[eh->elf.root.u.def.value >> 3];
7150 if (skip != (unsigned long) -1)
7151 eh->elf.root.u.def.value -= skip;
7154 (*_bfd_error_handler)
7155 (_("%s defined in removed toc entry"), eh->elf.root.root.string);
7156 eh->elf.root.u.def.section = &bfd_abs_section;
7157 eh->elf.root.u.def.value = 0;
7159 eh->adjust_done = 1;
7161 else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
7162 toc_inf->global_toc_syms = TRUE;
7167 /* Examine all relocs referencing .toc sections in order to remove
7168 unused .toc entries. */
7171 ppc64_elf_edit_toc (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info)
7174 struct adjust_toc_info toc_inf;
7176 toc_inf.global_toc_syms = TRUE;
7177 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
7179 asection *toc, *sec;
7180 Elf_Internal_Shdr *symtab_hdr;
7181 Elf_Internal_Sym *local_syms;
7182 struct elf_link_hash_entry **sym_hashes;
7183 Elf_Internal_Rela *relstart, *rel;
7184 unsigned long *skip, *drop;
7185 unsigned char *used;
7186 unsigned char *keep, last, some_unused;
7188 toc = bfd_get_section_by_name (ibfd, ".toc");
7191 || toc->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
7192 || elf_discarded_section (toc))
7196 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
7197 sym_hashes = elf_sym_hashes (ibfd);
7199 /* Look at sections dropped from the final link. */
7202 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7204 if (sec->reloc_count == 0
7205 || !elf_discarded_section (sec)
7206 || get_opd_info (sec)
7207 || (sec->flags & SEC_ALLOC) == 0
7208 || (sec->flags & SEC_DEBUGGING) != 0)
7211 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
7212 if (relstart == NULL)
7215 /* Run through the relocs to see which toc entries might be
7217 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
7219 enum elf_ppc64_reloc_type r_type;
7220 unsigned long r_symndx;
7222 struct elf_link_hash_entry *h;
7223 Elf_Internal_Sym *sym;
7226 r_type = ELF64_R_TYPE (rel->r_info);
7233 case R_PPC64_TOC16_LO:
7234 case R_PPC64_TOC16_HI:
7235 case R_PPC64_TOC16_HA:
7236 case R_PPC64_TOC16_DS:
7237 case R_PPC64_TOC16_LO_DS:
7241 r_symndx = ELF64_R_SYM (rel->r_info);
7242 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7250 val = h->root.u.def.value;
7252 val = sym->st_value;
7253 val += rel->r_addend;
7255 if (val >= toc->size)
7258 /* Anything in the toc ought to be aligned to 8 bytes.
7259 If not, don't mark as unused. */
7265 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 7) / 8);
7273 if (elf_section_data (sec)->relocs != relstart)
7280 used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8);
7284 if (local_syms != NULL
7285 && symtab_hdr->contents != (unsigned char *) local_syms)
7289 && elf_section_data (sec)->relocs != relstart)
7296 /* Now check all kept sections that might reference the toc.
7297 Check the toc itself last. */
7298 for (sec = (ibfd->sections == toc && toc->next ? toc->next
7301 sec = (sec == toc ? NULL
7302 : sec->next == NULL ? toc
7303 : sec->next == toc && toc->next ? toc->next
7308 if (sec->reloc_count == 0
7309 || elf_discarded_section (sec)
7310 || get_opd_info (sec)
7311 || (sec->flags & SEC_ALLOC) == 0
7312 || (sec->flags & SEC_DEBUGGING) != 0)
7315 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, TRUE);
7316 if (relstart == NULL)
7319 /* Mark toc entries referenced as used. */
7322 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
7324 enum elf_ppc64_reloc_type r_type;
7325 unsigned long r_symndx;
7327 struct elf_link_hash_entry *h;
7328 Elf_Internal_Sym *sym;
7331 r_type = ELF64_R_TYPE (rel->r_info);
7335 case R_PPC64_TOC16_LO:
7336 case R_PPC64_TOC16_HI:
7337 case R_PPC64_TOC16_HA:
7338 case R_PPC64_TOC16_DS:
7339 case R_PPC64_TOC16_LO_DS:
7340 /* In case we're taking addresses of toc entries. */
7341 case R_PPC64_ADDR64:
7348 r_symndx = ELF64_R_SYM (rel->r_info);
7349 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7360 val = h->root.u.def.value;
7362 val = sym->st_value;
7363 val += rel->r_addend;
7365 if (val >= toc->size)
7368 /* For the toc section, we only mark as used if
7369 this entry itself isn't unused. */
7372 && (used[rel->r_offset >> 3]
7373 || !skip[rel->r_offset >> 3]))
7374 /* Do all the relocs again, to catch reference
7383 /* Merge the used and skip arrays. Assume that TOC
7384 doublewords not appearing as either used or unused belong
7385 to to an entry more than one doubleword in size. */
7386 for (drop = skip, keep = used, last = 0, some_unused = 0;
7387 drop < skip + (toc->size + 7) / 8;
7408 bfd_byte *contents, *src;
7411 /* Shuffle the toc contents, and at the same time convert the
7412 skip array from booleans into offsets. */
7413 if (!bfd_malloc_and_get_section (ibfd, toc, &contents))
7416 elf_section_data (toc)->this_hdr.contents = contents;
7418 for (src = contents, off = 0, drop = skip;
7419 src < contents + toc->size;
7424 *drop = (unsigned long) -1;
7430 memcpy (src - off, src, 8);
7433 toc->rawsize = toc->size;
7434 toc->size = src - contents - off;
7436 if (toc->reloc_count != 0)
7438 Elf_Internal_Rela *wrel;
7441 /* Read toc relocs. */
7442 relstart = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
7444 if (relstart == NULL)
7447 /* Remove unused toc relocs, and adjust those we keep. */
7449 for (rel = relstart; rel < relstart + toc->reloc_count; ++rel)
7450 if (skip[rel->r_offset >> 3] != (unsigned long) -1)
7452 wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3];
7453 wrel->r_info = rel->r_info;
7454 wrel->r_addend = rel->r_addend;
7457 else if (!dec_dynrel_count (rel->r_info, toc, info,
7458 &local_syms, NULL, NULL))
7461 toc->reloc_count = wrel - relstart;
7462 sz = elf_section_data (toc)->rel_hdr.sh_entsize;
7463 elf_section_data (toc)->rel_hdr.sh_size = toc->reloc_count * sz;
7464 BFD_ASSERT (elf_section_data (toc)->rel_hdr2 == NULL);
7467 /* Adjust addends for relocs against the toc section sym. */
7468 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7470 if (sec->reloc_count == 0
7471 || elf_discarded_section (sec))
7474 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
7476 if (relstart == NULL)
7479 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
7481 enum elf_ppc64_reloc_type r_type;
7482 unsigned long r_symndx;
7484 struct elf_link_hash_entry *h;
7485 Elf_Internal_Sym *sym;
7487 r_type = ELF64_R_TYPE (rel->r_info);
7494 case R_PPC64_TOC16_LO:
7495 case R_PPC64_TOC16_HI:
7496 case R_PPC64_TOC16_HA:
7497 case R_PPC64_TOC16_DS:
7498 case R_PPC64_TOC16_LO_DS:
7499 case R_PPC64_ADDR64:
7503 r_symndx = ELF64_R_SYM (rel->r_info);
7504 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7508 if (sym_sec != toc || h != NULL || sym->st_value != 0)
7511 rel->r_addend -= skip[rel->r_addend >> 3];
7515 /* We shouldn't have local or global symbols defined in the TOC,
7516 but handle them anyway. */
7517 if (local_syms != NULL)
7519 Elf_Internal_Sym *sym;
7521 for (sym = local_syms;
7522 sym < local_syms + symtab_hdr->sh_info;
7524 if (sym->st_shndx != SHN_UNDEF
7525 && (sym->st_shndx < SHN_LORESERVE
7526 || sym->st_shndx > SHN_HIRESERVE)
7527 && sym->st_value != 0
7528 && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc)
7530 if (skip[sym->st_value >> 3] != (unsigned long) -1)
7531 sym->st_value -= skip[sym->st_value >> 3];
7534 (*_bfd_error_handler)
7535 (_("%s defined in removed toc entry"),
7536 bfd_elf_sym_name (ibfd, symtab_hdr, sym,
7539 sym->st_shndx = SHN_ABS;
7541 symtab_hdr->contents = (unsigned char *) local_syms;
7545 /* Finally, adjust any global syms defined in the toc. */
7546 if (toc_inf.global_toc_syms)
7549 toc_inf.skip = skip;
7550 toc_inf.global_toc_syms = FALSE;
7551 elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
7556 if (local_syms != NULL
7557 && symtab_hdr->contents != (unsigned char *) local_syms)
7559 if (!info->keep_memory)
7562 symtab_hdr->contents = (unsigned char *) local_syms;
7570 /* Allocate space in .plt, .got and associated reloc sections for
7574 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7576 struct bfd_link_info *info;
7577 struct ppc_link_hash_table *htab;
7579 struct ppc_link_hash_entry *eh;
7580 struct ppc_dyn_relocs *p;
7581 struct got_entry *gent;
7583 if (h->root.type == bfd_link_hash_indirect)
7586 if (h->root.type == bfd_link_hash_warning)
7587 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7589 info = (struct bfd_link_info *) inf;
7590 htab = ppc_hash_table (info);
7592 if (htab->elf.dynamic_sections_created
7594 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
7596 struct plt_entry *pent;
7597 bfd_boolean doneone = FALSE;
7598 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
7599 if (pent->plt.refcount > 0)
7601 /* If this is the first .plt entry, make room for the special
7605 s->size += PLT_INITIAL_ENTRY_SIZE;
7607 pent->plt.offset = s->size;
7609 /* Make room for this entry. */
7610 s->size += PLT_ENTRY_SIZE;
7612 /* Make room for the .glink code. */
7615 s->size += GLINK_CALL_STUB_SIZE;
7616 /* We need bigger stubs past index 32767. */
7617 if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
7621 /* We also need to make an entry in the .rela.plt section. */
7623 s->size += sizeof (Elf64_External_Rela);
7627 pent->plt.offset = (bfd_vma) -1;
7630 h->plt.plist = NULL;
7636 h->plt.plist = NULL;
7640 eh = (struct ppc_link_hash_entry *) h;
7641 /* Run through the TLS GD got entries first if we're changing them
7643 if ((eh->tls_mask & TLS_TPRELGD) != 0)
7644 for (gent = h->got.glist; gent != NULL; gent = gent->next)
7645 if (gent->got.refcount > 0
7646 && (gent->tls_type & TLS_GD) != 0)
7648 /* This was a GD entry that has been converted to TPREL. If
7649 there happens to be a TPREL entry we can use that one. */
7650 struct got_entry *ent;
7651 for (ent = h->got.glist; ent != NULL; ent = ent->next)
7652 if (ent->got.refcount > 0
7653 && (ent->tls_type & TLS_TPREL) != 0
7654 && ent->addend == gent->addend
7655 && ent->owner == gent->owner)
7657 gent->got.refcount = 0;
7661 /* If not, then we'll be using our own TPREL entry. */
7662 if (gent->got.refcount != 0)
7663 gent->tls_type = TLS_TLS | TLS_TPREL;
7666 for (gent = h->got.glist; gent != NULL; gent = gent->next)
7667 if (gent->got.refcount > 0)
7671 /* Make sure this symbol is output as a dynamic symbol.
7672 Undefined weak syms won't yet be marked as dynamic,
7673 nor will all TLS symbols. */
7674 if (h->dynindx == -1
7675 && !h->forced_local)
7677 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7681 if ((gent->tls_type & TLS_LD) != 0
7684 gent->got.offset = ppc64_tlsld_got (gent->owner)->offset;
7688 s = ppc64_elf_tdata (gent->owner)->got;
7689 gent->got.offset = s->size;
7691 += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8;
7692 dyn = htab->elf.dynamic_sections_created;
7694 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
7695 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7696 || h->root.type != bfd_link_hash_undefweak))
7697 ppc64_elf_tdata (gent->owner)->relgot->size
7698 += (gent->tls_type & eh->tls_mask & TLS_GD
7699 ? 2 * sizeof (Elf64_External_Rela)
7700 : sizeof (Elf64_External_Rela));
7703 gent->got.offset = (bfd_vma) -1;
7705 if (eh->dyn_relocs == NULL)
7708 /* In the shared -Bsymbolic case, discard space allocated for
7709 dynamic pc-relative relocs against symbols which turn out to be
7710 defined in regular objects. For the normal shared case, discard
7711 space for relocs that have become local due to symbol visibility
7716 /* Relocs that use pc_count are those that appear on a call insn,
7717 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
7718 generated via assembly. We want calls to protected symbols to
7719 resolve directly to the function rather than going via the plt.
7720 If people want function pointer comparisons to work as expected
7721 then they should avoid writing weird assembly. */
7722 if (SYMBOL_CALLS_LOCAL (info, h))
7724 struct ppc_dyn_relocs **pp;
7726 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
7728 p->count -= p->pc_count;
7737 /* Also discard relocs on undefined weak syms with non-default
7739 if (eh->dyn_relocs != NULL
7740 && h->root.type == bfd_link_hash_undefweak)
7742 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7743 eh->dyn_relocs = NULL;
7745 /* Make sure this symbol is output as a dynamic symbol.
7746 Undefined weak syms won't yet be marked as dynamic. */
7747 else if (h->dynindx == -1
7748 && !h->forced_local)
7750 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7755 else if (ELIMINATE_COPY_RELOCS)
7757 /* For the non-shared case, discard space for relocs against
7758 symbols which turn out to need copy relocs or are not
7765 /* Make sure this symbol is output as a dynamic symbol.
7766 Undefined weak syms won't yet be marked as dynamic. */
7767 if (h->dynindx == -1
7768 && !h->forced_local)
7770 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7774 /* If that succeeded, we know we'll be keeping all the
7776 if (h->dynindx != -1)
7780 eh->dyn_relocs = NULL;
7785 /* Finally, allocate space. */
7786 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7788 asection *sreloc = elf_section_data (p->sec)->sreloc;
7789 sreloc->size += p->count * sizeof (Elf64_External_Rela);
7795 /* Find any dynamic relocs that apply to read-only sections. */
7798 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
7800 struct ppc_link_hash_entry *eh;
7801 struct ppc_dyn_relocs *p;
7803 if (h->root.type == bfd_link_hash_warning)
7804 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7806 eh = (struct ppc_link_hash_entry *) h;
7807 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7809 asection *s = p->sec->output_section;
7811 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7813 struct bfd_link_info *info = inf;
7815 info->flags |= DF_TEXTREL;
7817 /* Not an error, just cut short the traversal. */
7824 /* Set the sizes of the dynamic sections. */
7827 ppc64_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
7828 struct bfd_link_info *info)
7830 struct ppc_link_hash_table *htab;
7836 htab = ppc_hash_table (info);
7837 dynobj = htab->elf.dynobj;
7841 if (htab->elf.dynamic_sections_created)
7843 /* Set the contents of the .interp section to the interpreter. */
7844 if (info->executable)
7846 s = bfd_get_section_by_name (dynobj, ".interp");
7849 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7850 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7854 /* Set up .got offsets for local syms, and space for local dynamic
7856 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
7858 struct got_entry **lgot_ents;
7859 struct got_entry **end_lgot_ents;
7861 bfd_size_type locsymcount;
7862 Elf_Internal_Shdr *symtab_hdr;
7865 if (!is_ppc64_elf_target (ibfd->xvec))
7868 if (ppc64_tlsld_got (ibfd)->refcount > 0)
7870 s = ppc64_elf_tdata (ibfd)->got;
7871 ppc64_tlsld_got (ibfd)->offset = s->size;
7875 srel = ppc64_elf_tdata (ibfd)->relgot;
7876 srel->size += sizeof (Elf64_External_Rela);
7880 ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1;
7882 for (s = ibfd->sections; s != NULL; s = s->next)
7884 struct ppc_dyn_relocs *p;
7886 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
7888 if (!bfd_is_abs_section (p->sec)
7889 && bfd_is_abs_section (p->sec->output_section))
7891 /* Input section has been discarded, either because
7892 it is a copy of a linkonce section or due to
7893 linker script /DISCARD/, so we'll be discarding
7896 else if (p->count != 0)
7898 srel = elf_section_data (p->sec)->sreloc;
7899 srel->size += p->count * sizeof (Elf64_External_Rela);
7900 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
7901 info->flags |= DF_TEXTREL;
7906 lgot_ents = elf_local_got_ents (ibfd);
7910 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
7911 locsymcount = symtab_hdr->sh_info;
7912 end_lgot_ents = lgot_ents + locsymcount;
7913 lgot_masks = (char *) end_lgot_ents;
7914 s = ppc64_elf_tdata (ibfd)->got;
7915 srel = ppc64_elf_tdata (ibfd)->relgot;
7916 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
7918 struct got_entry *ent;
7920 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
7921 if (ent->got.refcount > 0)
7923 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
7925 if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1)
7927 ppc64_tlsld_got (ibfd)->offset = s->size;
7930 srel->size += sizeof (Elf64_External_Rela);
7932 ent->got.offset = ppc64_tlsld_got (ibfd)->offset;
7936 ent->got.offset = s->size;
7937 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
7941 srel->size += 2 * sizeof (Elf64_External_Rela);
7947 srel->size += sizeof (Elf64_External_Rela);
7952 ent->got.offset = (bfd_vma) -1;
7956 /* Allocate global sym .plt and .got entries, and space for global
7957 sym dynamic relocs. */
7958 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
7960 /* We now have determined the sizes of the various dynamic sections.
7961 Allocate memory for them. */
7963 for (s = dynobj->sections; s != NULL; s = s->next)
7965 if ((s->flags & SEC_LINKER_CREATED) == 0)
7968 if (s == htab->brlt || s == htab->relbrlt)
7969 /* These haven't been allocated yet; don't strip. */
7971 else if (s == htab->got
7974 || s == htab->dynbss)
7976 /* Strip this section if we don't need it; see the
7979 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
7983 if (s != htab->relplt)
7986 /* We use the reloc_count field as a counter if we need
7987 to copy relocs into the output file. */
7993 /* It's not one of our sections, so don't allocate space. */
7999 /* If we don't need this section, strip it from the
8000 output file. This is mostly to handle .rela.bss and
8001 .rela.plt. We must create both sections in
8002 create_dynamic_sections, because they must be created
8003 before the linker maps input sections to output
8004 sections. The linker does that before
8005 adjust_dynamic_symbol is called, and it is that
8006 function which decides whether anything needs to go
8007 into these sections. */
8008 s->flags |= SEC_EXCLUDE;
8012 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8015 /* Allocate memory for the section contents. We use bfd_zalloc
8016 here in case unused entries are not reclaimed before the
8017 section's contents are written out. This should not happen,
8018 but this way if it does we get a R_PPC64_NONE reloc in .rela
8019 sections instead of garbage.
8020 We also rely on the section contents being zero when writing
8022 s->contents = bfd_zalloc (dynobj, s->size);
8023 if (s->contents == NULL)
8027 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8029 if (!is_ppc64_elf_target (ibfd->xvec))
8032 s = ppc64_elf_tdata (ibfd)->got;
8033 if (s != NULL && s != htab->got)
8036 s->flags |= SEC_EXCLUDE;
8039 s->contents = bfd_zalloc (ibfd, s->size);
8040 if (s->contents == NULL)
8044 s = ppc64_elf_tdata (ibfd)->relgot;
8048 s->flags |= SEC_EXCLUDE;
8051 s->contents = bfd_zalloc (ibfd, s->size);
8052 if (s->contents == NULL)
8060 if (htab->elf.dynamic_sections_created)
8062 /* Add some entries to the .dynamic section. We fill in the
8063 values later, in ppc64_elf_finish_dynamic_sections, but we
8064 must add the entries now so that we get the correct size for
8065 the .dynamic section. The DT_DEBUG entry is filled in by the
8066 dynamic linker and used by the debugger. */
8067 #define add_dynamic_entry(TAG, VAL) \
8068 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8070 if (info->executable)
8072 if (!add_dynamic_entry (DT_DEBUG, 0))
8076 if (htab->plt != NULL && htab->plt->size != 0)
8078 if (!add_dynamic_entry (DT_PLTGOT, 0)
8079 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8080 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
8081 || !add_dynamic_entry (DT_JMPREL, 0)
8082 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
8088 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
8089 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
8095 if (!add_dynamic_entry (DT_RELA, 0)
8096 || !add_dynamic_entry (DT_RELASZ, 0)
8097 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
8100 /* If any dynamic relocs apply to a read-only section,
8101 then we need a DT_TEXTREL entry. */
8102 if ((info->flags & DF_TEXTREL) == 0)
8103 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
8105 if ((info->flags & DF_TEXTREL) != 0)
8107 if (!add_dynamic_entry (DT_TEXTREL, 0))
8112 #undef add_dynamic_entry
8117 /* Determine the type of stub needed, if any, for a call. */
8119 static inline enum ppc_stub_type
8120 ppc_type_of_stub (asection *input_sec,
8121 const Elf_Internal_Rela *rel,
8122 struct ppc_link_hash_entry **hash,
8123 bfd_vma destination)
8125 struct ppc_link_hash_entry *h = *hash;
8127 bfd_vma branch_offset;
8128 bfd_vma max_branch_offset;
8129 enum elf_ppc64_reloc_type r_type;
8133 struct ppc_link_hash_entry *fdh = h;
8135 && fdh->oh->is_func_descriptor)
8138 if (fdh->elf.dynindx != -1)
8140 struct plt_entry *ent;
8142 for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
8143 if (ent->addend == rel->r_addend
8144 && ent->plt.offset != (bfd_vma) -1)
8147 return ppc_stub_plt_call;
8151 /* Here, we know we don't have a plt entry. If we don't have a
8152 either a defined function descriptor or a defined entry symbol
8153 in a regular object file, then it is pointless trying to make
8154 any other type of stub. */
8155 if (!((fdh->elf.root.type == bfd_link_hash_defined
8156 || fdh->elf.root.type == bfd_link_hash_defweak)
8157 && fdh->elf.root.u.def.section->output_section != NULL)
8158 && !((h->elf.root.type == bfd_link_hash_defined
8159 || h->elf.root.type == bfd_link_hash_defweak)
8160 && h->elf.root.u.def.section->output_section != NULL))
8161 return ppc_stub_none;
8164 /* Determine where the call point is. */
8165 location = (input_sec->output_offset
8166 + input_sec->output_section->vma
8169 branch_offset = destination - location;
8170 r_type = ELF64_R_TYPE (rel->r_info);
8172 /* Determine if a long branch stub is needed. */
8173 max_branch_offset = 1 << 25;
8174 if (r_type != R_PPC64_REL24)
8175 max_branch_offset = 1 << 15;
8177 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
8178 /* We need a stub. Figure out whether a long_branch or plt_branch
8180 return ppc_stub_long_branch;
8182 return ppc_stub_none;
8185 /* Build a .plt call stub. */
8187 static inline bfd_byte *
8188 build_plt_stub (bfd *obfd, bfd_byte *p, int offset)
8190 #define PPC_LO(v) ((v) & 0xffff)
8191 #define PPC_HI(v) (((v) >> 16) & 0xffff)
8192 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
8194 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
8195 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
8196 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
8197 if (PPC_HA (offset + 8) != PPC_HA (offset))
8198 bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4;
8200 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
8201 if (PPC_HA (offset + 8) != PPC_HA (offset))
8202 bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4;
8204 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
8205 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
8206 bfd_put_32 (obfd, BCTR, p), p += 4;
8211 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
8213 struct ppc_stub_hash_entry *stub_entry;
8214 struct ppc_branch_hash_entry *br_entry;
8215 struct bfd_link_info *info;
8216 struct ppc_link_hash_table *htab;
8220 struct plt_entry *ent;
8224 /* Massage our args to the form they really have. */
8225 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
8228 htab = ppc_hash_table (info);
8230 /* Make a note of the offset within the stubs for this entry. */
8231 stub_entry->stub_offset = stub_entry->stub_sec->size;
8232 loc = stub_entry->stub_sec->contents + stub_entry->stub_offset;
8234 htab->stub_count[stub_entry->stub_type - 1] += 1;
8235 switch (stub_entry->stub_type)
8237 case ppc_stub_long_branch:
8238 case ppc_stub_long_branch_r2off:
8239 /* Branches are relative. This is where we are going to. */
8240 off = dest = (stub_entry->target_value
8241 + stub_entry->target_section->output_offset
8242 + stub_entry->target_section->output_section->vma);
8244 /* And this is where we are coming from. */
8245 off -= (stub_entry->stub_offset
8246 + stub_entry->stub_sec->output_offset
8247 + stub_entry->stub_sec->output_section->vma);
8249 if (stub_entry->stub_type != ppc_stub_long_branch_r2off)
8255 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off
8256 - htab->stub_group[stub_entry->id_sec->id].toc_off);
8257 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc);
8259 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
8261 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
8266 bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
8268 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
8270 (*_bfd_error_handler) (_("long branch stub `%s' offset overflow"),
8271 stub_entry->root.string);
8272 htab->stub_error = TRUE;
8276 if (info->emitrelocations)
8278 Elf_Internal_Rela *relocs, *r;
8279 struct bfd_elf_section_data *elfsec_data;
8281 elfsec_data = elf_section_data (stub_entry->stub_sec);
8282 relocs = elfsec_data->relocs;
8285 bfd_size_type relsize;
8286 relsize = stub_entry->stub_sec->reloc_count * sizeof (*relocs);
8287 relocs = bfd_alloc (htab->stub_bfd, relsize);
8290 elfsec_data->relocs = relocs;
8291 elfsec_data->rel_hdr.sh_size = relsize;
8292 elfsec_data->rel_hdr.sh_entsize = 24;
8293 stub_entry->stub_sec->reloc_count = 0;
8295 r = relocs + stub_entry->stub_sec->reloc_count;
8296 stub_entry->stub_sec->reloc_count += 1;
8297 r->r_offset = loc - stub_entry->stub_sec->contents;
8298 r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
8300 if (stub_entry->h != NULL)
8302 struct elf_link_hash_entry **hashes;
8303 unsigned long symndx;
8304 struct ppc_link_hash_entry *h;
8306 hashes = elf_sym_hashes (htab->stub_bfd);
8309 bfd_size_type hsize;
8311 hsize = (htab->stub_globals + 1) * sizeof (*hashes);
8312 hashes = bfd_zalloc (htab->stub_bfd, hsize);
8315 elf_sym_hashes (htab->stub_bfd) = hashes;
8316 htab->stub_globals = 1;
8318 symndx = htab->stub_globals++;
8320 hashes[symndx] = &h->elf;
8321 r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
8322 if (h->oh != NULL && h->oh->is_func)
8324 if (h->elf.root.u.def.section != stub_entry->target_section)
8325 /* H is an opd symbol. The addend must be zero. */
8329 off = (h->elf.root.u.def.value
8330 + h->elf.root.u.def.section->output_offset
8331 + h->elf.root.u.def.section->output_section->vma);
8338 case ppc_stub_plt_branch:
8339 case ppc_stub_plt_branch_r2off:
8340 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
8341 stub_entry->root.string + 9,
8343 if (br_entry == NULL)
8345 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
8346 stub_entry->root.string);
8347 htab->stub_error = TRUE;
8351 off = (stub_entry->target_value
8352 + stub_entry->target_section->output_offset
8353 + stub_entry->target_section->output_section->vma);
8355 bfd_put_64 (htab->brlt->owner, off,
8356 htab->brlt->contents + br_entry->offset);
8358 if (htab->relbrlt != NULL)
8360 /* Create a reloc for the branch lookup table entry. */
8361 Elf_Internal_Rela rela;
8364 rela.r_offset = (br_entry->offset
8365 + htab->brlt->output_offset
8366 + htab->brlt->output_section->vma);
8367 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
8368 rela.r_addend = off;
8370 rl = htab->relbrlt->contents;
8371 rl += htab->relbrlt->reloc_count++ * sizeof (Elf64_External_Rela);
8372 bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
8374 else if (info->emitrelocations)
8376 Elf_Internal_Rela *relocs, *r;
8377 struct bfd_elf_section_data *elfsec_data;
8379 elfsec_data = elf_section_data (htab->brlt);
8380 relocs = elfsec_data->relocs;
8383 bfd_size_type relsize;
8384 relsize = htab->brlt->reloc_count * sizeof (*relocs);
8385 relocs = bfd_alloc (htab->brlt->owner, relsize);
8388 elfsec_data->relocs = relocs;
8389 elfsec_data->rel_hdr.sh_size = relsize;
8390 elfsec_data->rel_hdr.sh_entsize = 24;
8391 htab->brlt->reloc_count = 0;
8393 r = relocs + htab->brlt->reloc_count;
8394 htab->brlt->reloc_count += 1;
8395 r->r_offset = (br_entry->offset
8396 + htab->brlt->output_offset
8397 + htab->brlt->output_section->vma);
8398 r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
8402 off = (br_entry->offset
8403 + htab->brlt->output_offset
8404 + htab->brlt->output_section->vma
8405 - elf_gp (htab->brlt->output_section->owner)
8406 - htab->stub_group[stub_entry->id_sec->id].toc_off);
8408 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
8410 (*_bfd_error_handler)
8411 (_("linkage table error against `%s'"),
8412 stub_entry->root.string);
8413 bfd_set_error (bfd_error_bad_value);
8414 htab->stub_error = TRUE;
8419 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
8421 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc);
8423 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc);
8430 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off
8431 - htab->stub_group[stub_entry->id_sec->id].toc_off);
8432 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc);
8434 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc);
8436 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc);
8438 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
8440 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
8444 bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc);
8446 bfd_put_32 (htab->stub_bfd, BCTR, loc);
8449 case ppc_stub_plt_call:
8450 /* Do the best we can for shared libraries built without
8451 exporting ".foo" for each "foo". This can happen when symbol
8452 versioning scripts strip all bar a subset of symbols. */
8453 if (stub_entry->h->oh != NULL
8454 && stub_entry->h->oh->elf.root.type != bfd_link_hash_defined
8455 && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak)
8457 /* Point the symbol at the stub. There may be multiple stubs,
8458 we don't really care; The main thing is to make this sym
8459 defined somewhere. Maybe defining the symbol in the stub
8460 section is a silly idea. If we didn't do this, htab->top_id
8462 stub_entry->h->oh->elf.root.type = bfd_link_hash_defined;
8463 stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec;
8464 stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset;
8467 /* Now build the stub. */
8469 for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
8470 if (ent->addend == stub_entry->addend)
8472 off = ent->plt.offset;
8475 if (off >= (bfd_vma) -2)
8478 off &= ~ (bfd_vma) 1;
8479 off += (htab->plt->output_offset
8480 + htab->plt->output_section->vma
8481 - elf_gp (htab->plt->output_section->owner)
8482 - htab->stub_group[stub_entry->id_sec->id].toc_off);
8484 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
8486 (*_bfd_error_handler)
8487 (_("linkage table error against `%s'"),
8488 stub_entry->h->elf.root.root.string);
8489 bfd_set_error (bfd_error_bad_value);
8490 htab->stub_error = TRUE;
8494 p = build_plt_stub (htab->stub_bfd, loc, off);
8503 stub_entry->stub_sec->size += size;
8505 if (htab->emit_stub_syms)
8507 struct elf_link_hash_entry *h;
8510 const char *const stub_str[] = { "long_branch",
8511 "long_branch_r2off",
8516 len1 = strlen (stub_str[stub_entry->stub_type - 1]);
8517 len2 = strlen (stub_entry->root.string);
8518 name = bfd_malloc (len1 + len2 + 2);
8521 memcpy (name, stub_entry->root.string, 9);
8522 memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
8523 memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
8524 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
8527 if (h->root.type == bfd_link_hash_new)
8529 h->root.type = bfd_link_hash_defined;
8530 h->root.u.def.section = stub_entry->stub_sec;
8531 h->root.u.def.value = stub_entry->stub_offset;
8534 h->ref_regular_nonweak = 1;
8535 h->forced_local = 1;
8543 /* As above, but don't actually build the stub. Just bump offset so
8544 we know stub section sizes, and select plt_branch stubs where
8545 long_branch stubs won't do. */
8548 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
8550 struct ppc_stub_hash_entry *stub_entry;
8551 struct bfd_link_info *info;
8552 struct ppc_link_hash_table *htab;
8556 /* Massage our args to the form they really have. */
8557 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
8560 htab = ppc_hash_table (info);
8562 if (stub_entry->stub_type == ppc_stub_plt_call)
8564 struct plt_entry *ent;
8566 for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
8567 if (ent->addend == stub_entry->addend)
8569 off = ent->plt.offset & ~(bfd_vma) 1;
8572 if (off >= (bfd_vma) -2)
8574 off += (htab->plt->output_offset
8575 + htab->plt->output_section->vma
8576 - elf_gp (htab->plt->output_section->owner)
8577 - htab->stub_group[stub_entry->id_sec->id].toc_off);
8579 size = PLT_CALL_STUB_SIZE;
8580 if (PPC_HA (off + 16) != PPC_HA (off))
8585 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
8587 off = (stub_entry->target_value
8588 + stub_entry->target_section->output_offset
8589 + stub_entry->target_section->output_section->vma);
8590 off -= (stub_entry->stub_sec->size
8591 + stub_entry->stub_sec->output_offset
8592 + stub_entry->stub_sec->output_section->vma);
8594 /* Reset the stub type from the plt variant in case we now
8595 can reach with a shorter stub. */
8596 if (stub_entry->stub_type >= ppc_stub_plt_branch)
8597 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
8600 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
8606 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
8607 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
8609 struct ppc_branch_hash_entry *br_entry;
8611 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
8612 stub_entry->root.string + 9,
8614 if (br_entry == NULL)
8616 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
8617 stub_entry->root.string);
8618 htab->stub_error = TRUE;
8622 if (br_entry->iter != htab->stub_iteration)
8624 br_entry->iter = htab->stub_iteration;
8625 br_entry->offset = htab->brlt->size;
8626 htab->brlt->size += 8;
8628 if (htab->relbrlt != NULL)
8629 htab->relbrlt->size += sizeof (Elf64_External_Rela);
8630 else if (info->emitrelocations)
8632 htab->brlt->reloc_count += 1;
8633 htab->brlt->flags |= SEC_RELOC;
8637 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
8639 if (stub_entry->stub_type != ppc_stub_plt_branch)
8642 else if (info->emitrelocations)
8644 stub_entry->stub_sec->reloc_count += 1;
8645 stub_entry->stub_sec->flags |= SEC_RELOC;
8649 stub_entry->stub_sec->size += size;
8653 /* Set up various things so that we can make a list of input sections
8654 for each output section included in the link. Returns -1 on error,
8655 0 when no stubs will be needed, and 1 on success. */
8658 ppc64_elf_setup_section_lists (bfd *output_bfd,
8659 struct bfd_link_info *info,
8663 int top_id, top_index, id;
8665 asection **input_list;
8667 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8669 htab->no_multi_toc = no_multi_toc;
8671 if (htab->brlt == NULL)
8674 /* Find the top input section id. */
8675 for (input_bfd = info->input_bfds, top_id = 3;
8677 input_bfd = input_bfd->link_next)
8679 for (section = input_bfd->sections;
8681 section = section->next)
8683 if (top_id < section->id)
8684 top_id = section->id;
8688 htab->top_id = top_id;
8689 amt = sizeof (struct map_stub) * (top_id + 1);
8690 htab->stub_group = bfd_zmalloc (amt);
8691 if (htab->stub_group == NULL)
8694 /* Set toc_off for com, und, abs and ind sections. */
8695 for (id = 0; id < 3; id++)
8696 htab->stub_group[id].toc_off = TOC_BASE_OFF;
8698 elf_gp (output_bfd) = htab->toc_curr = ppc64_elf_toc (output_bfd);
8700 /* We can't use output_bfd->section_count here to find the top output
8701 section index as some sections may have been removed, and
8702 strip_excluded_output_sections doesn't renumber the indices. */
8703 for (section = output_bfd->sections, top_index = 0;
8705 section = section->next)
8707 if (top_index < section->index)
8708 top_index = section->index;
8711 htab->top_index = top_index;
8712 amt = sizeof (asection *) * (top_index + 1);
8713 input_list = bfd_zmalloc (amt);
8714 htab->input_list = input_list;
8715 if (input_list == NULL)
8721 /* The linker repeatedly calls this function for each TOC input section
8722 and linker generated GOT section. Group input bfds such that the toc
8723 within a group is less than 64k in size. Will break with cute linker
8724 scripts that play games with dot in the output toc section. */
8727 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
8729 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8731 if (!htab->no_multi_toc)
8733 bfd_vma addr = isec->output_offset + isec->output_section->vma;
8734 bfd_vma off = addr - htab->toc_curr;
8736 if (off + isec->size > 0x10000)
8737 htab->toc_curr = addr;
8739 elf_gp (isec->owner) = (htab->toc_curr
8740 - elf_gp (isec->output_section->owner)
8745 /* Called after the last call to the above function. */
8748 ppc64_elf_reinit_toc (bfd *output_bfd, struct bfd_link_info *info)
8750 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8752 htab->multi_toc_needed = htab->toc_curr != elf_gp (output_bfd);
8754 /* toc_curr tracks the TOC offset used for code sections below in
8755 ppc64_elf_next_input_section. Start off at 0x8000. */
8756 htab->toc_curr = TOC_BASE_OFF;
8759 /* No toc references were found in ISEC. If the code in ISEC makes no
8760 calls, then there's no need to use toc adjusting stubs when branching
8761 into ISEC. Actually, indirect calls from ISEC are OK as they will
8762 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
8763 needed, and 2 if a cyclical call-graph was found but no other reason
8764 for a stub was detected. If called from the top level, a return of
8765 2 means the same as a return of 0. */
8768 toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
8770 Elf_Internal_Rela *relstart, *rel;
8771 Elf_Internal_Sym *local_syms;
8773 struct ppc_link_hash_table *htab;
8775 /* We know none of our code bearing sections will need toc stubs. */
8776 if ((isec->flags & SEC_LINKER_CREATED) != 0)
8779 if (isec->size == 0)
8782 if (isec->output_section == NULL)
8785 /* Hack for linux kernel. .fixup contains branches, but only back to
8786 the function that hit an exception. */
8787 if (strcmp (isec->name, ".fixup") == 0)
8790 if (isec->reloc_count == 0)
8793 relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL,
8795 if (relstart == NULL)
8798 /* Look for branches to outside of this section. */
8801 htab = ppc_hash_table (info);
8802 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel)
8804 enum elf_ppc64_reloc_type r_type;
8805 unsigned long r_symndx;
8806 struct elf_link_hash_entry *h;
8807 Elf_Internal_Sym *sym;
8813 r_type = ELF64_R_TYPE (rel->r_info);
8814 if (r_type != R_PPC64_REL24
8815 && r_type != R_PPC64_REL14
8816 && r_type != R_PPC64_REL14_BRTAKEN
8817 && r_type != R_PPC64_REL14_BRNTAKEN)
8820 r_symndx = ELF64_R_SYM (rel->r_info);
8821 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx,
8828 /* Calls to dynamic lib functions go through a plt call stub
8829 that uses r2. Branches to undefined symbols might be a call
8830 using old-style dot symbols that can be satisfied by a plt
8831 call into a new-style dynamic library. */
8832 if (sym_sec == NULL)
8834 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
8837 && eh->oh->elf.plt.plist != NULL)
8843 /* Ignore other undefined symbols. */
8847 /* Assume branches to other sections not included in the link need
8848 stubs too, to cover -R and absolute syms. */
8849 if (sym_sec->output_section == NULL)
8856 sym_value = sym->st_value;
8859 if (h->root.type != bfd_link_hash_defined
8860 && h->root.type != bfd_link_hash_defweak)
8862 sym_value = h->root.u.def.value;
8864 sym_value += rel->r_addend;
8866 /* If this branch reloc uses an opd sym, find the code section. */
8867 opd_adjust = get_opd_info (sym_sec);
8868 if (opd_adjust != NULL)
8874 adjust = opd_adjust[sym->st_value / 8];
8876 /* Assume deleted functions won't ever be called. */
8878 sym_value += adjust;
8881 dest = opd_entry_value (sym_sec, sym_value, &sym_sec, NULL);
8882 if (dest == (bfd_vma) -1)
8887 + sym_sec->output_offset
8888 + sym_sec->output_section->vma);
8890 /* Ignore branch to self. */
8891 if (sym_sec == isec)
8894 /* If the called function uses the toc, we need a stub. */
8895 if (sym_sec->has_toc_reloc
8896 || sym_sec->makes_toc_func_call)
8902 /* Assume any branch that needs a long branch stub might in fact
8903 need a plt_branch stub. A plt_branch stub uses r2. */
8904 else if (dest - (isec->output_offset
8905 + isec->output_section->vma
8906 + rel->r_offset) + (1 << 25) >= (2 << 25))
8912 /* If calling back to a section in the process of being tested, we
8913 can't say for sure that no toc adjusting stubs are needed, so
8914 don't return zero. */
8915 else if (sym_sec->call_check_in_progress)
8918 /* Branches to another section that itself doesn't have any TOC
8919 references are OK. Recursively call ourselves to check. */
8920 else if (sym_sec->id <= htab->top_id
8921 && htab->stub_group[sym_sec->id].toc_off == 0)
8925 /* Mark current section as indeterminate, so that other
8926 sections that call back to current won't be marked as
8928 isec->call_check_in_progress = 1;
8929 recur = toc_adjusting_stub_needed (info, sym_sec);
8930 isec->call_check_in_progress = 0;
8934 /* An error. Exit. */
8938 else if (recur <= 1)
8940 /* Known result. Mark as checked and set section flag. */
8941 htab->stub_group[sym_sec->id].toc_off = 1;
8944 sym_sec->makes_toc_func_call = 1;
8951 /* Unknown result. Continue checking. */
8957 if (local_syms != NULL
8958 && (elf_tdata (isec->owner)->symtab_hdr.contents
8959 != (unsigned char *) local_syms))
8961 if (elf_section_data (isec)->relocs != relstart)
8967 /* The linker repeatedly calls this function for each input section,
8968 in the order that input sections are linked into output sections.
8969 Build lists of input sections to determine groupings between which
8970 we may insert linker stubs. */
8973 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
8975 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8977 if ((isec->output_section->flags & SEC_CODE) != 0
8978 && isec->output_section->index <= htab->top_index)
8980 asection **list = htab->input_list + isec->output_section->index;
8981 /* Steal the link_sec pointer for our list. */
8982 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
8983 /* This happens to make the list in reverse order,
8984 which is what we want. */
8985 PREV_SEC (isec) = *list;
8989 if (htab->multi_toc_needed)
8991 /* If a code section has a function that uses the TOC then we need
8992 to use the right TOC (obviously). Also, make sure that .opd gets
8993 the correct TOC value for R_PPC64_TOC relocs that don't have or
8994 can't find their function symbol (shouldn't ever happen now). */
8995 if (isec->has_toc_reloc || (isec->flags & SEC_CODE) == 0)
8997 if (elf_gp (isec->owner) != 0)
8998 htab->toc_curr = elf_gp (isec->owner);
9000 else if (htab->stub_group[isec->id].toc_off == 0)
9002 int ret = toc_adjusting_stub_needed (info, isec);
9006 isec->makes_toc_func_call = ret & 1;
9010 /* Functions that don't use the TOC can belong in any TOC group.
9011 Use the last TOC base. This happens to make _init and _fini
9013 htab->stub_group[isec->id].toc_off = htab->toc_curr;
9017 /* See whether we can group stub sections together. Grouping stub
9018 sections may result in fewer stubs. More importantly, we need to
9019 put all .init* and .fini* stubs at the beginning of the .init or
9020 .fini output sections respectively, because glibc splits the
9021 _init and _fini functions into multiple parts. Putting a stub in
9022 the middle of a function is not a good idea. */
9025 group_sections (struct ppc_link_hash_table *htab,
9026 bfd_size_type stub_group_size,
9027 bfd_boolean stubs_always_before_branch)
9030 bfd_size_type stub14_group_size;
9031 bfd_boolean suppress_size_errors;
9033 suppress_size_errors = FALSE;
9034 stub14_group_size = stub_group_size;
9035 if (stub_group_size == 1)
9037 /* Default values. */
9038 if (stubs_always_before_branch)
9040 stub_group_size = 0x1e00000;
9041 stub14_group_size = 0x7800;
9045 stub_group_size = 0x1c00000;
9046 stub14_group_size = 0x7000;
9048 suppress_size_errors = TRUE;
9051 list = htab->input_list + htab->top_index;
9054 asection *tail = *list;
9055 while (tail != NULL)
9059 bfd_size_type total;
9060 bfd_boolean big_sec;
9065 big_sec = total > (ppc64_elf_section_data (tail)->has_14bit_branch
9066 ? stub14_group_size : stub_group_size);
9067 if (big_sec && !suppress_size_errors)
9068 (*_bfd_error_handler) (_("%B section %A exceeds stub group size"),
9070 curr_toc = htab->stub_group[tail->id].toc_off;
9072 while ((prev = PREV_SEC (curr)) != NULL
9073 && ((total += curr->output_offset - prev->output_offset)
9074 < (ppc64_elf_section_data (prev)->has_14bit_branch
9075 ? stub14_group_size : stub_group_size))
9076 && htab->stub_group[prev->id].toc_off == curr_toc)
9079 /* OK, the size from the start of CURR to the end is less
9080 than stub_group_size and thus can be handled by one stub
9081 section. (or the tail section is itself larger than
9082 stub_group_size, in which case we may be toast.) We
9083 should really be keeping track of the total size of stubs
9084 added here, as stubs contribute to the final output
9085 section size. That's a little tricky, and this way will
9086 only break if stubs added make the total size more than
9087 2^25, ie. for the default stub_group_size, if stubs total
9088 more than 2097152 bytes, or nearly 75000 plt call stubs. */
9091 prev = PREV_SEC (tail);
9092 /* Set up this stub group. */
9093 htab->stub_group[tail->id].link_sec = curr;
9095 while (tail != curr && (tail = prev) != NULL);
9097 /* But wait, there's more! Input sections up to stub_group_size
9098 bytes before the stub section can be handled by it too.
9099 Don't do this if we have a really large section after the
9100 stubs, as adding more stubs increases the chance that
9101 branches may not reach into the stub section. */
9102 if (!stubs_always_before_branch && !big_sec)
9106 && ((total += tail->output_offset - prev->output_offset)
9107 < (ppc64_elf_section_data (prev)->has_14bit_branch
9108 ? stub14_group_size : stub_group_size))
9109 && htab->stub_group[prev->id].toc_off == curr_toc)
9112 prev = PREV_SEC (tail);
9113 htab->stub_group[tail->id].link_sec = curr;
9119 while (list-- != htab->input_list);
9120 free (htab->input_list);
9124 /* Determine and set the size of the stub section for a final link.
9126 The basic idea here is to examine all the relocations looking for
9127 PC-relative calls to a target that is unreachable with a "bl"
9131 ppc64_elf_size_stubs (bfd *output_bfd,
9132 struct bfd_link_info *info,
9133 bfd_signed_vma group_size,
9134 asection *(*add_stub_section) (const char *, asection *),
9135 void (*layout_sections_again) (void))
9137 bfd_size_type stub_group_size;
9138 bfd_boolean stubs_always_before_branch;
9139 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9141 /* Stash our params away. */
9142 htab->add_stub_section = add_stub_section;
9143 htab->layout_sections_again = layout_sections_again;
9144 stubs_always_before_branch = group_size < 0;
9146 stub_group_size = -group_size;
9148 stub_group_size = group_size;
9150 group_sections (htab, stub_group_size, stubs_always_before_branch);
9155 unsigned int bfd_indx;
9158 htab->stub_iteration += 1;
9160 for (input_bfd = info->input_bfds, bfd_indx = 0;
9162 input_bfd = input_bfd->link_next, bfd_indx++)
9164 Elf_Internal_Shdr *symtab_hdr;
9166 Elf_Internal_Sym *local_syms = NULL;
9168 if (!is_ppc64_elf_target (input_bfd->xvec))
9171 /* We'll need the symbol table in a second. */
9172 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
9173 if (symtab_hdr->sh_info == 0)
9176 /* Walk over each section attached to the input bfd. */
9177 for (section = input_bfd->sections;
9179 section = section->next)
9181 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
9183 /* If there aren't any relocs, then there's nothing more
9185 if ((section->flags & SEC_RELOC) == 0
9186 || (section->flags & SEC_ALLOC) == 0
9187 || (section->flags & SEC_LOAD) == 0
9188 || (section->flags & SEC_CODE) == 0
9189 || section->reloc_count == 0)
9192 /* If this section is a link-once section that will be
9193 discarded, then don't create any stubs. */
9194 if (section->output_section == NULL
9195 || section->output_section->owner != output_bfd)
9198 /* Get the relocs. */
9200 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
9202 if (internal_relocs == NULL)
9203 goto error_ret_free_local;
9205 /* Now examine each relocation. */
9206 irela = internal_relocs;
9207 irelaend = irela + section->reloc_count;
9208 for (; irela < irelaend; irela++)
9210 enum elf_ppc64_reloc_type r_type;
9211 unsigned int r_indx;
9212 enum ppc_stub_type stub_type;
9213 struct ppc_stub_hash_entry *stub_entry;
9214 asection *sym_sec, *code_sec;
9216 bfd_vma destination;
9217 bfd_boolean ok_dest;
9218 struct ppc_link_hash_entry *hash;
9219 struct ppc_link_hash_entry *fdh;
9220 struct elf_link_hash_entry *h;
9221 Elf_Internal_Sym *sym;
9223 const asection *id_sec;
9226 r_type = ELF64_R_TYPE (irela->r_info);
9227 r_indx = ELF64_R_SYM (irela->r_info);
9229 if (r_type >= R_PPC64_max)
9231 bfd_set_error (bfd_error_bad_value);
9232 goto error_ret_free_internal;
9235 /* Only look for stubs on branch instructions. */
9236 if (r_type != R_PPC64_REL24
9237 && r_type != R_PPC64_REL14
9238 && r_type != R_PPC64_REL14_BRTAKEN
9239 && r_type != R_PPC64_REL14_BRNTAKEN)
9242 /* Now determine the call target, its name, value,
9244 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9246 goto error_ret_free_internal;
9247 hash = (struct ppc_link_hash_entry *) h;
9254 sym_value = sym->st_value;
9257 else if (hash->elf.root.type == bfd_link_hash_defined
9258 || hash->elf.root.type == bfd_link_hash_defweak)
9260 sym_value = hash->elf.root.u.def.value;
9261 if (sym_sec->output_section != NULL)
9264 else if (hash->elf.root.type == bfd_link_hash_undefweak
9265 || hash->elf.root.type == bfd_link_hash_undefined)
9267 /* Recognise an old ABI func code entry sym, and
9268 use the func descriptor sym instead if it is
9270 if (hash->elf.root.root.string[0] == '.'
9271 && (fdh = get_fdh (hash, htab)) != NULL)
9273 if (fdh->elf.root.type == bfd_link_hash_defined
9274 || fdh->elf.root.type == bfd_link_hash_defweak)
9276 sym_sec = fdh->elf.root.u.def.section;
9277 sym_value = fdh->elf.root.u.def.value;
9278 if (sym_sec->output_section != NULL)
9287 bfd_set_error (bfd_error_bad_value);
9288 goto error_ret_free_internal;
9294 sym_value += irela->r_addend;
9295 destination = (sym_value
9296 + sym_sec->output_offset
9297 + sym_sec->output_section->vma);
9301 opd_adjust = get_opd_info (sym_sec);
9302 if (opd_adjust != NULL)
9308 long adjust = opd_adjust[sym_value / 8];
9311 sym_value += adjust;
9313 dest = opd_entry_value (sym_sec, sym_value,
9314 &code_sec, &sym_value);
9315 if (dest != (bfd_vma) -1)
9320 /* Fixup old ABI sym to point at code
9322 hash->elf.root.type = bfd_link_hash_defweak;
9323 hash->elf.root.u.def.section = code_sec;
9324 hash->elf.root.u.def.value = sym_value;
9329 /* Determine what (if any) linker stub is needed. */
9330 stub_type = ppc_type_of_stub (section, irela, &hash,
9333 if (stub_type != ppc_stub_plt_call)
9335 /* Check whether we need a TOC adjusting stub.
9336 Since the linker pastes together pieces from
9337 different object files when creating the
9338 _init and _fini functions, it may be that a
9339 call to what looks like a local sym is in
9340 fact a call needing a TOC adjustment. */
9341 if (code_sec != NULL
9342 && code_sec->output_section != NULL
9343 && (htab->stub_group[code_sec->id].toc_off
9344 != htab->stub_group[section->id].toc_off)
9345 && (code_sec->has_toc_reloc
9346 || code_sec->makes_toc_func_call))
9347 stub_type = ppc_stub_long_branch_r2off;
9350 if (stub_type == ppc_stub_none)
9353 /* __tls_get_addr calls might be eliminated. */
9354 if (stub_type != ppc_stub_plt_call
9356 && (hash == htab->tls_get_addr
9357 || hash == htab->tls_get_addr_fd)
9358 && section->has_tls_reloc
9359 && irela != internal_relocs)
9364 if (!get_tls_mask (&tls_mask, NULL, &local_syms,
9365 irela - 1, input_bfd))
9366 goto error_ret_free_internal;
9371 /* Support for grouping stub sections. */
9372 id_sec = htab->stub_group[section->id].link_sec;
9374 /* Get the name of this stub. */
9375 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
9377 goto error_ret_free_internal;
9379 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
9380 stub_name, FALSE, FALSE);
9381 if (stub_entry != NULL)
9383 /* The proper stub has already been created. */
9388 stub_entry = ppc_add_stub (stub_name, section, htab);
9389 if (stub_entry == NULL)
9392 error_ret_free_internal:
9393 if (elf_section_data (section)->relocs == NULL)
9394 free (internal_relocs);
9395 error_ret_free_local:
9396 if (local_syms != NULL
9397 && (symtab_hdr->contents
9398 != (unsigned char *) local_syms))
9403 stub_entry->stub_type = stub_type;
9404 stub_entry->target_value = sym_value;
9405 stub_entry->target_section = code_sec;
9406 stub_entry->h = hash;
9407 stub_entry->addend = irela->r_addend;
9409 if (stub_entry->h != NULL)
9410 htab->stub_globals += 1;
9413 /* We're done with the internal relocs, free them. */
9414 if (elf_section_data (section)->relocs != internal_relocs)
9415 free (internal_relocs);
9418 if (local_syms != NULL
9419 && symtab_hdr->contents != (unsigned char *) local_syms)
9421 if (!info->keep_memory)
9424 symtab_hdr->contents = (unsigned char *) local_syms;
9428 /* We may have added some stubs. Find out the new size of the
9430 for (stub_sec = htab->stub_bfd->sections;
9432 stub_sec = stub_sec->next)
9433 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
9435 stub_sec->rawsize = stub_sec->size;
9437 stub_sec->reloc_count = 0;
9438 stub_sec->flags &= ~SEC_RELOC;
9441 htab->brlt->size = 0;
9442 htab->brlt->reloc_count = 0;
9443 htab->brlt->flags &= ~SEC_RELOC;
9444 if (htab->relbrlt != NULL)
9445 htab->relbrlt->size = 0;
9447 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
9449 for (stub_sec = htab->stub_bfd->sections;
9451 stub_sec = stub_sec->next)
9452 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
9453 && stub_sec->rawsize != stub_sec->size)
9456 /* Exit from this loop when no stubs have been added, and no stubs
9457 have changed size. */
9458 if (stub_sec == NULL)
9461 /* Ask the linker to do its stuff. */
9462 (*htab->layout_sections_again) ();
9465 /* It would be nice to strip htab->brlt from the output if the
9466 section is empty, but it's too late. If we strip sections here,
9467 the dynamic symbol table is corrupted since the section symbol
9468 for the stripped section isn't written. */
9473 /* Called after we have determined section placement. If sections
9474 move, we'll be called again. Provide a value for TOCstart. */
9477 ppc64_elf_toc (bfd *obfd)
9482 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
9483 order. The TOC starts where the first of these sections starts. */
9484 s = bfd_get_section_by_name (obfd, ".got");
9486 s = bfd_get_section_by_name (obfd, ".toc");
9488 s = bfd_get_section_by_name (obfd, ".tocbss");
9490 s = bfd_get_section_by_name (obfd, ".plt");
9493 /* This may happen for
9494 o references to TOC base (SYM@toc / TOC[tc0]) without a
9497 o --gc-sections and empty TOC sections
9499 FIXME: Warn user? */
9501 /* Look for a likely section. We probably won't even be
9503 for (s = obfd->sections; s != NULL; s = s->next)
9504 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
9505 == (SEC_ALLOC | SEC_SMALL_DATA))
9508 for (s = obfd->sections; s != NULL; s = s->next)
9509 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
9510 == (SEC_ALLOC | SEC_SMALL_DATA))
9513 for (s = obfd->sections; s != NULL; s = s->next)
9514 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
9517 for (s = obfd->sections; s != NULL; s = s->next)
9518 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
9524 TOCstart = s->output_section->vma + s->output_offset;
9529 /* Build all the stubs associated with the current output file.
9530 The stubs are kept in a hash table attached to the main linker
9531 hash table. This function is called via gldelf64ppc_finish. */
9534 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms,
9535 struct bfd_link_info *info,
9538 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9541 int stub_sec_count = 0;
9543 htab->emit_stub_syms = emit_stub_syms;
9545 /* Allocate memory to hold the linker stubs. */
9546 for (stub_sec = htab->stub_bfd->sections;
9548 stub_sec = stub_sec->next)
9549 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
9550 && stub_sec->size != 0)
9552 stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
9553 if (stub_sec->contents == NULL)
9555 /* We want to check that built size is the same as calculated
9556 size. rawsize is a convenient location to use. */
9557 stub_sec->rawsize = stub_sec->size;
9561 if (htab->glink != NULL && htab->glink->size != 0)
9566 /* Build the .glink plt call stub. */
9567 if (htab->emit_stub_syms)
9569 struct elf_link_hash_entry *h;
9570 h = elf_link_hash_lookup (&htab->elf, "__glink", TRUE, FALSE, FALSE);
9573 if (h->root.type == bfd_link_hash_new)
9575 h->root.type = bfd_link_hash_defined;
9576 h->root.u.def.section = htab->glink;
9577 h->root.u.def.value = 8;
9580 h->ref_regular_nonweak = 1;
9581 h->forced_local = 1;
9585 p = htab->glink->contents;
9586 plt0 = (htab->plt->output_section->vma
9587 + htab->plt->output_offset
9588 - (htab->glink->output_section->vma
9589 + htab->glink->output_offset
9591 bfd_put_64 (htab->glink->owner, plt0, p);
9593 bfd_put_32 (htab->glink->owner, MFLR_R12, p);
9595 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
9597 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
9599 bfd_put_32 (htab->glink->owner, LD_R2_M16R11, p);
9601 bfd_put_32 (htab->glink->owner, MTLR_R12, p);
9603 bfd_put_32 (htab->glink->owner, ADD_R12_R2_R11, p);
9605 bfd_put_32 (htab->glink->owner, LD_R11_0R12, p);
9607 bfd_put_32 (htab->glink->owner, LD_R2_0R12 | 8, p);
9609 bfd_put_32 (htab->glink->owner, MTCTR_R11, p);
9611 bfd_put_32 (htab->glink->owner, LD_R11_0R12 | 16, p);
9613 bfd_put_32 (htab->glink->owner, BCTR, p);
9615 while (p - htab->glink->contents < GLINK_CALL_STUB_SIZE)
9617 bfd_put_32 (htab->glink->owner, NOP, p);
9621 /* Build the .glink lazy link call stubs. */
9623 while (p < htab->glink->contents + htab->glink->size)
9627 bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
9632 bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
9634 bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
9637 bfd_put_32 (htab->glink->owner,
9638 B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p);
9642 htab->glink->rawsize = p - htab->glink->contents;
9645 if (htab->brlt->size != 0)
9647 htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
9649 if (htab->brlt->contents == NULL)
9652 if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
9654 htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
9655 htab->relbrlt->size);
9656 if (htab->relbrlt->contents == NULL)
9660 /* Build the stubs as directed by the stub hash table. */
9661 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
9663 if (htab->relbrlt != NULL)
9664 htab->relbrlt->reloc_count = 0;
9666 for (stub_sec = htab->stub_bfd->sections;
9668 stub_sec = stub_sec->next)
9669 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
9671 stub_sec_count += 1;
9672 if (stub_sec->rawsize != stub_sec->size)
9676 if (stub_sec != NULL
9677 || htab->glink->rawsize != htab->glink->size)
9679 htab->stub_error = TRUE;
9680 (*_bfd_error_handler) (_("stubs don't match calculated size"));
9683 if (htab->stub_error)
9688 *stats = bfd_malloc (500);
9692 sprintf (*stats, _("linker stubs in %u group%s\n"
9695 " long branch %lu\n"
9696 " long toc adj %lu\n"
9699 stub_sec_count == 1 ? "" : "s",
9700 htab->stub_count[ppc_stub_long_branch - 1],
9701 htab->stub_count[ppc_stub_long_branch_r2off - 1],
9702 htab->stub_count[ppc_stub_plt_branch - 1],
9703 htab->stub_count[ppc_stub_plt_branch_r2off - 1],
9704 htab->stub_count[ppc_stub_plt_call - 1]);
9709 /* This function undoes the changes made by add_symbol_adjust. */
9712 undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
9714 struct ppc_link_hash_entry *eh;
9716 if (h->root.type == bfd_link_hash_indirect)
9719 if (h->root.type == bfd_link_hash_warning)
9720 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9722 eh = (struct ppc_link_hash_entry *) h;
9723 if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined)
9726 eh->elf.root.type = bfd_link_hash_undefined;
9731 ppc64_elf_restore_symbols (struct bfd_link_info *info)
9733 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9734 elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info);
9737 /* What to do when ld finds relocations against symbols defined in
9738 discarded sections. */
9741 ppc64_elf_action_discarded (asection *sec)
9743 if (strcmp (".opd", sec->name) == 0)
9746 if (strcmp (".toc", sec->name) == 0)
9749 if (strcmp (".toc1", sec->name) == 0)
9752 return _bfd_elf_default_action_discarded (sec);
9755 /* The RELOCATE_SECTION function is called by the ELF backend linker
9756 to handle the relocations for a section.
9758 The relocs are always passed as Rela structures; if the section
9759 actually uses Rel structures, the r_addend field will always be
9762 This function is responsible for adjust the section contents as
9763 necessary, and (if using Rela relocs and generating a
9764 relocatable output file) adjusting the reloc addend as
9767 This function does not have to worry about setting the reloc
9768 address or the reloc symbol index.
9770 LOCAL_SYMS is a pointer to the swapped in local symbols.
9772 LOCAL_SECTIONS is an array giving the section in the input file
9773 corresponding to the st_shndx field of each local symbol.
9775 The global hash table entry for the global symbols can be found
9776 via elf_sym_hashes (input_bfd).
9778 When generating relocatable output, this function must handle
9779 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
9780 going to be the section symbol corresponding to the output
9781 section, which means that the addend must be adjusted
9785 ppc64_elf_relocate_section (bfd *output_bfd,
9786 struct bfd_link_info *info,
9788 asection *input_section,
9790 Elf_Internal_Rela *relocs,
9791 Elf_Internal_Sym *local_syms,
9792 asection **local_sections)
9794 struct ppc_link_hash_table *htab;
9795 Elf_Internal_Shdr *symtab_hdr;
9796 struct elf_link_hash_entry **sym_hashes;
9797 Elf_Internal_Rela *rel;
9798 Elf_Internal_Rela *relend;
9799 Elf_Internal_Rela outrel;
9801 struct got_entry **local_got_ents;
9803 bfd_boolean ret = TRUE;
9805 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
9806 bfd_boolean is_power4 = FALSE;
9807 bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
9809 /* Initialize howto table if needed. */
9810 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
9813 htab = ppc_hash_table (info);
9815 /* Don't relocate stub sections. */
9816 if (input_section->owner == htab->stub_bfd)
9819 local_got_ents = elf_local_got_ents (input_bfd);
9820 TOCstart = elf_gp (output_bfd);
9821 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
9822 sym_hashes = elf_sym_hashes (input_bfd);
9823 is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd;
9826 relend = relocs + input_section->reloc_count;
9827 for (; rel < relend; rel++)
9829 enum elf_ppc64_reloc_type r_type;
9830 bfd_vma addend, orig_addend;
9831 bfd_reloc_status_type r;
9832 Elf_Internal_Sym *sym;
9834 struct elf_link_hash_entry *h_elf;
9835 struct ppc_link_hash_entry *h;
9836 struct ppc_link_hash_entry *fdh;
9837 const char *sym_name;
9838 unsigned long r_symndx, toc_symndx;
9839 char tls_mask, tls_gd, tls_type;
9842 bfd_boolean unresolved_reloc;
9844 unsigned long insn, mask;
9845 struct ppc_stub_hash_entry *stub_entry;
9846 bfd_vma max_br_offset;
9849 r_type = ELF64_R_TYPE (rel->r_info);
9850 r_symndx = ELF64_R_SYM (rel->r_info);
9852 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
9853 symbol of the previous ADDR64 reloc. The symbol gives us the
9854 proper TOC base to use. */
9855 if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
9857 && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64
9859 r_symndx = ELF64_R_SYM (rel[-1].r_info);
9865 unresolved_reloc = FALSE;
9867 orig_addend = rel->r_addend;
9869 if (r_symndx < symtab_hdr->sh_info)
9871 /* It's a local symbol. */
9874 sym = local_syms + r_symndx;
9875 sec = local_sections[r_symndx];
9876 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
9877 sym_type = ELF64_ST_TYPE (sym->st_info);
9878 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
9879 opd_adjust = get_opd_info (sec);
9880 if (opd_adjust != NULL)
9882 long adjust = opd_adjust[(sym->st_value + rel->r_addend) / 8];
9887 /* If this is a relocation against the opd section sym
9888 and we have edited .opd, adjust the reloc addend so
9889 that ld -r and ld --emit-relocs output is correct.
9890 If it is a reloc against some other .opd symbol,
9891 then the symbol value will be adjusted later. */
9892 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
9893 rel->r_addend += adjust;
9895 relocation += adjust;
9898 if (info->relocatable)
9903 if (info->relocatable)
9905 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
9906 r_symndx, symtab_hdr, sym_hashes,
9907 h_elf, sec, relocation,
9908 unresolved_reloc, warned);
9909 sym_name = h_elf->root.root.string;
9910 sym_type = h_elf->type;
9912 h = (struct ppc_link_hash_entry *) h_elf;
9914 /* TLS optimizations. Replace instruction sequences and relocs
9915 based on information we collected in tls_optimize. We edit
9916 RELOCS so that --emit-relocs will output something sensible
9917 for the final instruction stream. */
9921 if (IS_PPC64_TLS_RELOC (r_type))
9924 tls_mask = h->tls_mask;
9925 else if (local_got_ents != NULL)
9928 lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
9929 tls_mask = lgot_masks[r_symndx];
9931 if (tls_mask == 0 && r_type == R_PPC64_TLS)
9933 /* Check for toc tls entries. */
9936 if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms,
9941 tls_mask = *toc_tls;
9945 /* Check that tls relocs are used with tls syms, and non-tls
9946 relocs are used with non-tls syms. */
9948 && r_type != R_PPC64_NONE
9950 || h->elf.root.type == bfd_link_hash_defined
9951 || h->elf.root.type == bfd_link_hash_defweak)
9952 && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS))
9954 if (r_type == R_PPC64_TLS && tls_mask != 0)
9955 /* R_PPC64_TLS is OK against a symbol in the TOC. */
9958 (*_bfd_error_handler)
9959 (sym_type == STT_TLS
9960 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
9961 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"),
9964 (long) rel->r_offset,
9965 ppc64_elf_howto_table[r_type]->name,
9969 /* Ensure reloc mapping code below stays sane. */
9970 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
9971 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
9972 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
9973 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
9974 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
9975 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
9976 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
9977 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
9978 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
9979 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
9988 case R_PPC64_TOC16_LO:
9989 case R_PPC64_TOC16_DS:
9990 case R_PPC64_TOC16_LO_DS:
9992 /* Check for toc tls entries. */
9996 retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms,
10003 tls_mask = *toc_tls;
10004 if (r_type == R_PPC64_TOC16_DS
10005 || r_type == R_PPC64_TOC16_LO_DS)
10008 && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
10013 /* If we found a GD reloc pair, then we might be
10014 doing a GD->IE transition. */
10017 tls_gd = TLS_TPRELGD;
10018 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
10019 goto tls_get_addr_check;
10021 else if (retval == 3)
10023 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
10024 goto tls_get_addr_check;
10031 case R_PPC64_GOT_TPREL16_DS:
10032 case R_PPC64_GOT_TPREL16_LO_DS:
10034 && (tls_mask & TLS_TPREL) == 0)
10037 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
10039 insn |= 0x3c0d0000; /* addis 0,13,0 */
10040 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
10041 r_type = R_PPC64_TPREL16_HA;
10042 if (toc_symndx != 0)
10044 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
10045 /* We changed the symbol. Start over in order to
10046 get h, sym, sec etc. right. */
10051 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10057 && (tls_mask & TLS_TPREL) == 0)
10060 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
10061 if ((insn & ((0x3f << 26) | (31 << 11)))
10062 == ((31 << 26) | (13 << 11)))
10063 rtra = insn & ((1 << 26) - (1 << 16));
10064 else if ((insn & ((0x3f << 26) | (31 << 16)))
10065 == ((31 << 26) | (13 << 16)))
10066 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
10069 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
10072 else if ((insn & (31 << 1)) == 23 << 1
10073 && ((insn & (31 << 6)) < 14 << 6
10074 || ((insn & (31 << 6)) >= 16 << 6
10075 && (insn & (31 << 6)) < 24 << 6)))
10076 /* load and store indexed -> dform. */
10077 insn = (32 | ((insn >> 6) & 31)) << 26;
10078 else if ((insn & (31 << 1)) == 21 << 1
10079 && (insn & (0x1a << 6)) == 0)
10080 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
10081 insn = (((58 | ((insn >> 6) & 4)) << 26)
10082 | ((insn >> 6) & 1));
10083 else if ((insn & (31 << 1)) == 21 << 1
10084 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
10086 insn = (58 << 26) | 2;
10090 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
10091 /* Was PPC64_TLS which sits on insn boundary, now
10092 PPC64_TPREL16_LO which is at low-order half-word. */
10093 rel->r_offset += d_offset;
10094 r_type = R_PPC64_TPREL16_LO;
10095 if (toc_symndx != 0)
10097 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
10098 /* We changed the symbol. Start over in order to
10099 get h, sym, sec etc. right. */
10104 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10108 case R_PPC64_GOT_TLSGD16_HI:
10109 case R_PPC64_GOT_TLSGD16_HA:
10110 tls_gd = TLS_TPRELGD;
10111 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
10115 case R_PPC64_GOT_TLSLD16_HI:
10116 case R_PPC64_GOT_TLSLD16_HA:
10117 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
10120 if ((tls_mask & tls_gd) != 0)
10121 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
10122 + R_PPC64_GOT_TPREL16_DS);
10125 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
10126 rel->r_offset -= d_offset;
10127 r_type = R_PPC64_NONE;
10129 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10133 case R_PPC64_GOT_TLSGD16:
10134 case R_PPC64_GOT_TLSGD16_LO:
10135 tls_gd = TLS_TPRELGD;
10136 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
10137 goto tls_get_addr_check;
10140 case R_PPC64_GOT_TLSLD16:
10141 case R_PPC64_GOT_TLSLD16_LO:
10142 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
10144 tls_get_addr_check:
10145 if (rel + 1 < relend)
10147 enum elf_ppc64_reloc_type r_type2;
10148 unsigned long r_symndx2;
10149 struct elf_link_hash_entry *h2;
10150 bfd_vma insn1, insn2, insn3;
10153 /* The next instruction should be a call to
10154 __tls_get_addr. Peek at the reloc to be sure. */
10155 r_type2 = ELF64_R_TYPE (rel[1].r_info);
10156 r_symndx2 = ELF64_R_SYM (rel[1].r_info);
10157 if (r_symndx2 < symtab_hdr->sh_info
10158 || (r_type2 != R_PPC64_REL14
10159 && r_type2 != R_PPC64_REL14_BRTAKEN
10160 && r_type2 != R_PPC64_REL14_BRNTAKEN
10161 && r_type2 != R_PPC64_REL24))
10164 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
10165 while (h2->root.type == bfd_link_hash_indirect
10166 || h2->root.type == bfd_link_hash_warning)
10167 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
10168 if (h2 == NULL || (h2 != &htab->tls_get_addr->elf
10169 && h2 != &htab->tls_get_addr_fd->elf))
10172 /* OK, it checks out. Replace the call. */
10173 offset = rel[1].r_offset;
10174 insn1 = bfd_get_32 (output_bfd,
10175 contents + rel->r_offset - d_offset);
10176 insn3 = bfd_get_32 (output_bfd,
10177 contents + offset + 4);
10178 if ((tls_mask & tls_gd) != 0)
10181 insn1 &= (1 << 26) - (1 << 2);
10182 insn1 |= 58 << 26; /* ld */
10183 insn2 = 0x7c636a14; /* add 3,3,13 */
10184 rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE);
10185 if ((tls_mask & TLS_EXPLICIT) == 0)
10186 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
10187 + R_PPC64_GOT_TPREL16_DS);
10189 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
10190 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10195 insn1 = 0x3c6d0000; /* addis 3,13,0 */
10196 insn2 = 0x38630000; /* addi 3,3,0 */
10199 /* Was an LD reloc. */
10201 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
10202 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
10204 else if (toc_symndx != 0)
10205 r_symndx = toc_symndx;
10206 r_type = R_PPC64_TPREL16_HA;
10207 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10208 rel[1].r_info = ELF64_R_INFO (r_symndx,
10209 R_PPC64_TPREL16_LO);
10210 rel[1].r_offset += d_offset;
10213 || insn3 == CROR_151515 || insn3 == CROR_313131)
10217 rel[1].r_offset += 4;
10219 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - d_offset);
10220 bfd_put_32 (output_bfd, insn2, contents + offset);
10221 bfd_put_32 (output_bfd, insn3, contents + offset + 4);
10222 if (tls_gd == 0 || toc_symndx != 0)
10224 /* We changed the symbol. Start over in order
10225 to get h, sym, sec etc. right. */
10233 case R_PPC64_DTPMOD64:
10234 if (rel + 1 < relend
10235 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
10236 && rel[1].r_offset == rel->r_offset + 8)
10238 if ((tls_mask & TLS_GD) == 0)
10240 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
10241 if ((tls_mask & TLS_TPRELGD) != 0)
10242 r_type = R_PPC64_TPREL64;
10245 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
10246 r_type = R_PPC64_NONE;
10248 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10253 if ((tls_mask & TLS_LD) == 0)
10255 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
10256 r_type = R_PPC64_NONE;
10257 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10262 case R_PPC64_TPREL64:
10263 if ((tls_mask & TLS_TPREL) == 0)
10265 r_type = R_PPC64_NONE;
10266 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
10271 /* Handle other relocations that tweak non-addend part of insn. */
10273 max_br_offset = 1 << 25;
10274 addend = rel->r_addend;
10280 /* Branch taken prediction relocations. */
10281 case R_PPC64_ADDR14_BRTAKEN:
10282 case R_PPC64_REL14_BRTAKEN:
10283 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
10286 /* Branch not taken prediction relocations. */
10287 case R_PPC64_ADDR14_BRNTAKEN:
10288 case R_PPC64_REL14_BRNTAKEN:
10289 insn |= bfd_get_32 (output_bfd,
10290 contents + rel->r_offset) & ~(0x01 << 21);
10293 case R_PPC64_REL14:
10294 max_br_offset = 1 << 15;
10297 case R_PPC64_REL24:
10298 /* Calls to functions with a different TOC, such as calls to
10299 shared objects, need to alter the TOC pointer. This is
10300 done using a linkage stub. A REL24 branching to these
10301 linkage stubs needs to be followed by a nop, as the nop
10302 will be replaced with an instruction to restore the TOC
10307 && (((fdh = h->oh) != NULL
10308 && fdh->elf.plt.plist != NULL)
10309 || (fdh = h)->elf.plt.plist != NULL))
10311 && sec->output_section != NULL
10312 && sec->id <= htab->top_id
10313 && (htab->stub_group[sec->id].toc_off
10314 != htab->stub_group[input_section->id].toc_off)))
10315 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
10316 rel, htab)) != NULL
10317 && (stub_entry->stub_type == ppc_stub_plt_call
10318 || stub_entry->stub_type == ppc_stub_plt_branch_r2off
10319 || stub_entry->stub_type == ppc_stub_long_branch_r2off))
10321 bfd_boolean can_plt_call = FALSE;
10323 if (rel->r_offset + 8 <= input_section->size)
10326 nop = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
10328 || nop == CROR_151515 || nop == CROR_313131)
10330 bfd_put_32 (input_bfd, LD_R2_40R1,
10331 contents + rel->r_offset + 4);
10332 can_plt_call = TRUE;
10338 if (stub_entry->stub_type == ppc_stub_plt_call)
10340 /* If this is a plain branch rather than a branch
10341 and link, don't require a nop. However, don't
10342 allow tail calls in a shared library as they
10343 will result in r2 being corrupted. */
10345 br = bfd_get_32 (input_bfd, contents + rel->r_offset);
10346 if (info->executable && (br & 1) == 0)
10347 can_plt_call = TRUE;
10352 && strcmp (h->elf.root.root.string,
10353 ".__libc_start_main") == 0)
10355 /* Allow crt1 branch to go via a toc adjusting stub. */
10356 can_plt_call = TRUE;
10360 if (strcmp (input_section->output_section->name,
10362 || strcmp (input_section->output_section->name,
10364 (*_bfd_error_handler)
10365 (_("%B(%A+0x%lx): automatic multiple TOCs "
10366 "not supported using your crt files; "
10367 "recompile with -mminimal-toc or upgrade gcc"),
10370 (long) rel->r_offset);
10372 (*_bfd_error_handler)
10373 (_("%B(%A+0x%lx): sibling call optimization to `%s' "
10374 "does not allow automatic multiple TOCs; "
10375 "recompile with -mminimal-toc or "
10376 "-fno-optimize-sibling-calls, "
10377 "or make `%s' extern"),
10380 (long) rel->r_offset,
10383 bfd_set_error (bfd_error_bad_value);
10389 && stub_entry->stub_type == ppc_stub_plt_call)
10390 unresolved_reloc = FALSE;
10393 if (stub_entry == NULL
10394 && get_opd_info (sec) != NULL)
10396 /* The branch destination is the value of the opd entry. */
10397 bfd_vma off = (relocation + addend
10398 - sec->output_section->vma
10399 - sec->output_offset);
10400 bfd_vma dest = opd_entry_value (sec, off, NULL, NULL);
10401 if (dest != (bfd_vma) -1)
10408 /* If the branch is out of reach we ought to have a long
10410 from = (rel->r_offset
10411 + input_section->output_offset
10412 + input_section->output_section->vma);
10414 if (stub_entry == NULL
10415 && (relocation + addend - from + max_br_offset
10416 >= 2 * max_br_offset)
10417 && r_type != R_PPC64_ADDR14_BRTAKEN
10418 && r_type != R_PPC64_ADDR14_BRNTAKEN)
10419 stub_entry = ppc_get_stub_entry (input_section, sec, h, rel,
10422 if (stub_entry != NULL)
10424 /* Munge up the value and addend so that we call the stub
10425 rather than the procedure directly. */
10426 relocation = (stub_entry->stub_offset
10427 + stub_entry->stub_sec->output_offset
10428 + stub_entry->stub_sec->output_section->vma);
10436 /* Set 'a' bit. This is 0b00010 in BO field for branch
10437 on CR(BI) insns (BO == 001at or 011at), and 0b01000
10438 for branch on CTR insns (BO == 1a00t or 1a01t). */
10439 if ((insn & (0x14 << 21)) == (0x04 << 21))
10440 insn |= 0x02 << 21;
10441 else if ((insn & (0x14 << 21)) == (0x10 << 21))
10442 insn |= 0x08 << 21;
10448 /* Invert 'y' bit if not the default. */
10449 if ((bfd_signed_vma) (relocation + addend - from) < 0)
10450 insn ^= 0x01 << 21;
10453 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
10456 /* NOP out calls to undefined weak functions.
10457 We can thus call a weak function without first
10458 checking whether the function is defined. */
10460 && h->elf.root.type == bfd_link_hash_undefweak
10461 && r_type == R_PPC64_REL24
10465 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
10471 /* Set `addend'. */
10476 (*_bfd_error_handler)
10477 (_("%B: unknown relocation type %d for symbol %s"),
10478 input_bfd, (int) r_type, sym_name);
10480 bfd_set_error (bfd_error_bad_value);
10486 case R_PPC64_GNU_VTINHERIT:
10487 case R_PPC64_GNU_VTENTRY:
10490 /* GOT16 relocations. Like an ADDR16 using the symbol's
10491 address in the GOT as relocation value instead of the
10492 symbol's value itself. Also, create a GOT entry for the
10493 symbol and put the symbol value there. */
10494 case R_PPC64_GOT_TLSGD16:
10495 case R_PPC64_GOT_TLSGD16_LO:
10496 case R_PPC64_GOT_TLSGD16_HI:
10497 case R_PPC64_GOT_TLSGD16_HA:
10498 tls_type = TLS_TLS | TLS_GD;
10501 case R_PPC64_GOT_TLSLD16:
10502 case R_PPC64_GOT_TLSLD16_LO:
10503 case R_PPC64_GOT_TLSLD16_HI:
10504 case R_PPC64_GOT_TLSLD16_HA:
10505 tls_type = TLS_TLS | TLS_LD;
10508 case R_PPC64_GOT_TPREL16_DS:
10509 case R_PPC64_GOT_TPREL16_LO_DS:
10510 case R_PPC64_GOT_TPREL16_HI:
10511 case R_PPC64_GOT_TPREL16_HA:
10512 tls_type = TLS_TLS | TLS_TPREL;
10515 case R_PPC64_GOT_DTPREL16_DS:
10516 case R_PPC64_GOT_DTPREL16_LO_DS:
10517 case R_PPC64_GOT_DTPREL16_HI:
10518 case R_PPC64_GOT_DTPREL16_HA:
10519 tls_type = TLS_TLS | TLS_DTPREL;
10522 case R_PPC64_GOT16:
10523 case R_PPC64_GOT16_LO:
10524 case R_PPC64_GOT16_HI:
10525 case R_PPC64_GOT16_HA:
10526 case R_PPC64_GOT16_DS:
10527 case R_PPC64_GOT16_LO_DS:
10530 /* Relocation is to the entry for this symbol in the global
10535 unsigned long indx = 0;
10537 if (tls_type == (TLS_TLS | TLS_LD)
10539 || !h->elf.def_dynamic))
10540 offp = &ppc64_tlsld_got (input_bfd)->offset;
10543 struct got_entry *ent;
10547 bfd_boolean dyn = htab->elf.dynamic_sections_created;
10548 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
10551 && SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
10552 /* This is actually a static link, or it is a
10553 -Bsymbolic link and the symbol is defined
10554 locally, or the symbol was forced to be local
10555 because of a version file. */
10559 indx = h->elf.dynindx;
10560 unresolved_reloc = FALSE;
10562 ent = h->elf.got.glist;
10566 if (local_got_ents == NULL)
10568 ent = local_got_ents[r_symndx];
10571 for (; ent != NULL; ent = ent->next)
10572 if (ent->addend == orig_addend
10573 && ent->owner == input_bfd
10574 && ent->tls_type == tls_type)
10578 offp = &ent->got.offset;
10581 got = ppc64_elf_tdata (input_bfd)->got;
10585 /* The offset must always be a multiple of 8. We use the
10586 least significant bit to record whether we have already
10587 processed this entry. */
10589 if ((off & 1) != 0)
10593 /* Generate relocs for the dynamic linker, except in
10594 the case of TLSLD where we'll use one entry per
10596 asection *relgot = ppc64_elf_tdata (input_bfd)->relgot;
10599 if ((info->shared || indx != 0)
10601 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
10602 || h->elf.root.type != bfd_link_hash_undefweak))
10604 outrel.r_offset = (got->output_section->vma
10605 + got->output_offset
10607 outrel.r_addend = addend;
10608 if (tls_type & (TLS_LD | TLS_GD))
10610 outrel.r_addend = 0;
10611 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
10612 if (tls_type == (TLS_TLS | TLS_GD))
10614 loc = relgot->contents;
10615 loc += (relgot->reloc_count++
10616 * sizeof (Elf64_External_Rela));
10617 bfd_elf64_swap_reloca_out (output_bfd,
10619 outrel.r_offset += 8;
10620 outrel.r_addend = addend;
10622 = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
10625 else if (tls_type == (TLS_TLS | TLS_DTPREL))
10626 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
10627 else if (tls_type == (TLS_TLS | TLS_TPREL))
10628 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
10629 else if (indx == 0)
10631 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE);
10633 /* Write the .got section contents for the sake
10635 loc = got->contents + off;
10636 bfd_put_64 (output_bfd, outrel.r_addend + relocation,
10640 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
10642 if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
10644 outrel.r_addend += relocation;
10645 if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
10646 outrel.r_addend -= htab->elf.tls_sec->vma;
10648 loc = relgot->contents;
10649 loc += (relgot->reloc_count++
10650 * sizeof (Elf64_External_Rela));
10651 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
10654 /* Init the .got section contents here if we're not
10655 emitting a reloc. */
10658 relocation += addend;
10659 if (tls_type == (TLS_TLS | TLS_LD))
10661 else if (tls_type != 0)
10663 relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
10664 if (tls_type == (TLS_TLS | TLS_TPREL))
10665 relocation += DTP_OFFSET - TP_OFFSET;
10667 if (tls_type == (TLS_TLS | TLS_GD))
10669 bfd_put_64 (output_bfd, relocation,
10670 got->contents + off + 8);
10675 bfd_put_64 (output_bfd, relocation,
10676 got->contents + off);
10680 if (off >= (bfd_vma) -2)
10683 relocation = got->output_offset + off;
10685 /* TOC base (r2) is TOC start plus 0x8000. */
10686 addend = -TOC_BASE_OFF;
10690 case R_PPC64_PLT16_HA:
10691 case R_PPC64_PLT16_HI:
10692 case R_PPC64_PLT16_LO:
10693 case R_PPC64_PLT32:
10694 case R_PPC64_PLT64:
10695 /* Relocation is to the entry for this symbol in the
10696 procedure linkage table. */
10698 /* Resolve a PLT reloc against a local symbol directly,
10699 without using the procedure linkage table. */
10703 /* It's possible that we didn't make a PLT entry for this
10704 symbol. This happens when statically linking PIC code,
10705 or when using -Bsymbolic. Go find a match if there is a
10707 if (htab->plt != NULL)
10709 struct plt_entry *ent;
10710 for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next)
10711 if (ent->addend == orig_addend
10712 && ent->plt.offset != (bfd_vma) -1)
10714 relocation = (htab->plt->output_section->vma
10715 + htab->plt->output_offset
10716 + ent->plt.offset);
10717 unresolved_reloc = FALSE;
10723 /* Relocation value is TOC base. */
10724 relocation = TOCstart;
10726 relocation += htab->stub_group[input_section->id].toc_off;
10727 else if (unresolved_reloc)
10729 else if (sec != NULL && sec->id <= htab->top_id)
10730 relocation += htab->stub_group[sec->id].toc_off;
10732 unresolved_reloc = TRUE;
10735 /* TOC16 relocs. We want the offset relative to the TOC base,
10736 which is the address of the start of the TOC plus 0x8000.
10737 The TOC consists of sections .got, .toc, .tocbss, and .plt,
10739 case R_PPC64_TOC16:
10740 case R_PPC64_TOC16_LO:
10741 case R_PPC64_TOC16_HI:
10742 case R_PPC64_TOC16_DS:
10743 case R_PPC64_TOC16_LO_DS:
10744 case R_PPC64_TOC16_HA:
10745 addend -= TOCstart + htab->stub_group[input_section->id].toc_off;
10748 /* Relocate against the beginning of the section. */
10749 case R_PPC64_SECTOFF:
10750 case R_PPC64_SECTOFF_LO:
10751 case R_PPC64_SECTOFF_HI:
10752 case R_PPC64_SECTOFF_DS:
10753 case R_PPC64_SECTOFF_LO_DS:
10754 case R_PPC64_SECTOFF_HA:
10756 addend -= sec->output_section->vma;
10759 case R_PPC64_REL14:
10760 case R_PPC64_REL14_BRNTAKEN:
10761 case R_PPC64_REL14_BRTAKEN:
10762 case R_PPC64_REL24:
10765 case R_PPC64_TPREL16:
10766 case R_PPC64_TPREL16_LO:
10767 case R_PPC64_TPREL16_HI:
10768 case R_PPC64_TPREL16_HA:
10769 case R_PPC64_TPREL16_DS:
10770 case R_PPC64_TPREL16_LO_DS:
10771 case R_PPC64_TPREL16_HIGHER:
10772 case R_PPC64_TPREL16_HIGHERA:
10773 case R_PPC64_TPREL16_HIGHEST:
10774 case R_PPC64_TPREL16_HIGHESTA:
10775 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
10777 /* The TPREL16 relocs shouldn't really be used in shared
10778 libs as they will result in DT_TEXTREL being set, but
10779 support them anyway. */
10783 case R_PPC64_DTPREL16:
10784 case R_PPC64_DTPREL16_LO:
10785 case R_PPC64_DTPREL16_HI:
10786 case R_PPC64_DTPREL16_HA:
10787 case R_PPC64_DTPREL16_DS:
10788 case R_PPC64_DTPREL16_LO_DS:
10789 case R_PPC64_DTPREL16_HIGHER:
10790 case R_PPC64_DTPREL16_HIGHERA:
10791 case R_PPC64_DTPREL16_HIGHEST:
10792 case R_PPC64_DTPREL16_HIGHESTA:
10793 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
10796 case R_PPC64_DTPMOD64:
10801 case R_PPC64_TPREL64:
10802 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
10805 case R_PPC64_DTPREL64:
10806 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
10809 /* Relocations that may need to be propagated if this is a
10811 case R_PPC64_REL30:
10812 case R_PPC64_REL32:
10813 case R_PPC64_REL64:
10814 case R_PPC64_ADDR14:
10815 case R_PPC64_ADDR14_BRNTAKEN:
10816 case R_PPC64_ADDR14_BRTAKEN:
10817 case R_PPC64_ADDR16:
10818 case R_PPC64_ADDR16_DS:
10819 case R_PPC64_ADDR16_HA:
10820 case R_PPC64_ADDR16_HI:
10821 case R_PPC64_ADDR16_HIGHER:
10822 case R_PPC64_ADDR16_HIGHERA:
10823 case R_PPC64_ADDR16_HIGHEST:
10824 case R_PPC64_ADDR16_HIGHESTA:
10825 case R_PPC64_ADDR16_LO:
10826 case R_PPC64_ADDR16_LO_DS:
10827 case R_PPC64_ADDR24:
10828 case R_PPC64_ADDR32:
10829 case R_PPC64_ADDR64:
10830 case R_PPC64_UADDR16:
10831 case R_PPC64_UADDR32:
10832 case R_PPC64_UADDR64:
10833 /* r_symndx will be zero only for relocs against symbols
10834 from removed linkonce sections, or sections discarded by
10835 a linker script. */
10839 _bfd_clear_contents (ppc64_elf_howto_table[r_type], input_bfd,
10840 contents + rel->r_offset);
10846 if ((input_section->flags & SEC_ALLOC) == 0)
10849 if (NO_OPD_RELOCS && is_opd)
10854 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
10855 || h->elf.root.type != bfd_link_hash_undefweak)
10856 && (MUST_BE_DYN_RELOC (r_type)
10857 || !SYMBOL_CALLS_LOCAL (info, &h->elf)))
10858 || (ELIMINATE_COPY_RELOCS
10861 && h->elf.dynindx != -1
10862 && !h->elf.non_got_ref
10863 && h->elf.def_dynamic
10864 && !h->elf.def_regular))
10866 Elf_Internal_Rela outrel;
10867 bfd_boolean skip, relocate;
10872 /* When generating a dynamic object, these relocations
10873 are copied into the output file to be resolved at run
10879 out_off = _bfd_elf_section_offset (output_bfd, info,
10880 input_section, rel->r_offset);
10881 if (out_off == (bfd_vma) -1)
10883 else if (out_off == (bfd_vma) -2)
10884 skip = TRUE, relocate = TRUE;
10885 out_off += (input_section->output_section->vma
10886 + input_section->output_offset);
10887 outrel.r_offset = out_off;
10888 outrel.r_addend = rel->r_addend;
10890 /* Optimize unaligned reloc use. */
10891 if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
10892 || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
10893 r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
10894 else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
10895 || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
10896 r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
10897 else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
10898 || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
10899 r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
10902 memset (&outrel, 0, sizeof outrel);
10903 else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
10905 && r_type != R_PPC64_TOC)
10906 outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type);
10909 /* This symbol is local, or marked to become local,
10910 or this is an opd section reloc which must point
10911 at a local function. */
10912 outrel.r_addend += relocation;
10913 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
10915 if (is_opd && h != NULL)
10917 /* Lie about opd entries. This case occurs
10918 when building shared libraries and we
10919 reference a function in another shared
10920 lib. The same thing happens for a weak
10921 definition in an application that's
10922 overridden by a strong definition in a
10923 shared lib. (I believe this is a generic
10924 bug in binutils handling of weak syms.)
10925 In these cases we won't use the opd
10926 entry in this lib. */
10927 unresolved_reloc = FALSE;
10929 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
10931 /* We need to relocate .opd contents for ld.so.
10932 Prelink also wants simple and consistent rules
10933 for relocs. This make all RELATIVE relocs have
10934 *r_offset equal to r_addend. */
10941 if (bfd_is_abs_section (sec))
10943 else if (sec == NULL || sec->owner == NULL)
10945 bfd_set_error (bfd_error_bad_value);
10952 osec = sec->output_section;
10953 indx = elf_section_data (osec)->dynindx;
10957 if ((osec->flags & SEC_READONLY) == 0
10958 && htab->elf.data_index_section != NULL)
10959 osec = htab->elf.data_index_section;
10961 osec = htab->elf.text_index_section;
10962 indx = elf_section_data (osec)->dynindx;
10964 BFD_ASSERT (indx != 0);
10966 /* We are turning this relocation into one
10967 against a section symbol, so subtract out
10968 the output section's address but not the
10969 offset of the input section in the output
10971 outrel.r_addend -= osec->vma;
10974 outrel.r_info = ELF64_R_INFO (indx, r_type);
10978 sreloc = elf_section_data (input_section)->sreloc;
10979 if (sreloc == NULL)
10982 if (sreloc->reloc_count * sizeof (Elf64_External_Rela)
10985 loc = sreloc->contents;
10986 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
10987 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
10989 /* If this reloc is against an external symbol, it will
10990 be computed at runtime, so there's no need to do
10991 anything now. However, for the sake of prelink ensure
10992 that the section contents are a known value. */
10995 unresolved_reloc = FALSE;
10996 /* The value chosen here is quite arbitrary as ld.so
10997 ignores section contents except for the special
10998 case of .opd where the contents might be accessed
10999 before relocation. Choose zero, as that won't
11000 cause reloc overflow. */
11003 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
11004 to improve backward compatibility with older
11006 if (r_type == R_PPC64_ADDR64)
11007 addend = outrel.r_addend;
11008 /* Adjust pc_relative relocs to have zero in *r_offset. */
11009 else if (ppc64_elf_howto_table[r_type]->pc_relative)
11010 addend = (input_section->output_section->vma
11011 + input_section->output_offset
11018 case R_PPC64_GLOB_DAT:
11019 case R_PPC64_JMP_SLOT:
11020 case R_PPC64_RELATIVE:
11021 /* We shouldn't ever see these dynamic relocs in relocatable
11023 /* Fall through. */
11025 case R_PPC64_PLTGOT16:
11026 case R_PPC64_PLTGOT16_DS:
11027 case R_PPC64_PLTGOT16_HA:
11028 case R_PPC64_PLTGOT16_HI:
11029 case R_PPC64_PLTGOT16_LO:
11030 case R_PPC64_PLTGOT16_LO_DS:
11031 case R_PPC64_PLTREL32:
11032 case R_PPC64_PLTREL64:
11033 /* These ones haven't been implemented yet. */
11035 (*_bfd_error_handler)
11036 (_("%B: relocation %s is not supported for symbol %s."),
11038 ppc64_elf_howto_table[r_type]->name, sym_name);
11040 bfd_set_error (bfd_error_invalid_operation);
11045 /* Do any further special processing. */
11051 case R_PPC64_ADDR16_HA:
11052 case R_PPC64_ADDR16_HIGHERA:
11053 case R_PPC64_ADDR16_HIGHESTA:
11054 case R_PPC64_TOC16_HA:
11055 case R_PPC64_SECTOFF_HA:
11056 case R_PPC64_TPREL16_HA:
11057 case R_PPC64_DTPREL16_HA:
11058 case R_PPC64_TPREL16_HIGHER:
11059 case R_PPC64_TPREL16_HIGHERA:
11060 case R_PPC64_TPREL16_HIGHEST:
11061 case R_PPC64_TPREL16_HIGHESTA:
11062 case R_PPC64_DTPREL16_HIGHER:
11063 case R_PPC64_DTPREL16_HIGHERA:
11064 case R_PPC64_DTPREL16_HIGHEST:
11065 case R_PPC64_DTPREL16_HIGHESTA:
11066 /* It's just possible that this symbol is a weak symbol
11067 that's not actually defined anywhere. In that case,
11068 'sec' would be NULL, and we should leave the symbol
11069 alone (it will be set to zero elsewhere in the link). */
11074 case R_PPC64_GOT16_HA:
11075 case R_PPC64_PLTGOT16_HA:
11076 case R_PPC64_PLT16_HA:
11077 case R_PPC64_GOT_TLSGD16_HA:
11078 case R_PPC64_GOT_TLSLD16_HA:
11079 case R_PPC64_GOT_TPREL16_HA:
11080 case R_PPC64_GOT_DTPREL16_HA:
11081 /* Add 0x10000 if sign bit in 0:15 is set.
11082 Bits 0:15 are not used. */
11086 case R_PPC64_ADDR16_DS:
11087 case R_PPC64_ADDR16_LO_DS:
11088 case R_PPC64_GOT16_DS:
11089 case R_PPC64_GOT16_LO_DS:
11090 case R_PPC64_PLT16_LO_DS:
11091 case R_PPC64_SECTOFF_DS:
11092 case R_PPC64_SECTOFF_LO_DS:
11093 case R_PPC64_TOC16_DS:
11094 case R_PPC64_TOC16_LO_DS:
11095 case R_PPC64_PLTGOT16_DS:
11096 case R_PPC64_PLTGOT16_LO_DS:
11097 case R_PPC64_GOT_TPREL16_DS:
11098 case R_PPC64_GOT_TPREL16_LO_DS:
11099 case R_PPC64_GOT_DTPREL16_DS:
11100 case R_PPC64_GOT_DTPREL16_LO_DS:
11101 case R_PPC64_TPREL16_DS:
11102 case R_PPC64_TPREL16_LO_DS:
11103 case R_PPC64_DTPREL16_DS:
11104 case R_PPC64_DTPREL16_LO_DS:
11105 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
11107 /* If this reloc is against an lq insn, then the value must be
11108 a multiple of 16. This is somewhat of a hack, but the
11109 "correct" way to do this by defining _DQ forms of all the
11110 _DS relocs bloats all reloc switches in this file. It
11111 doesn't seem to make much sense to use any of these relocs
11112 in data, so testing the insn should be safe. */
11113 if ((insn & (0x3f << 26)) == (56u << 26))
11115 if (((relocation + addend) & mask) != 0)
11117 (*_bfd_error_handler)
11118 (_("%B: error: relocation %s not a multiple of %d"),
11120 ppc64_elf_howto_table[r_type]->name,
11122 bfd_set_error (bfd_error_bad_value);
11129 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
11130 because such sections are not SEC_ALLOC and thus ld.so will
11131 not process them. */
11132 if (unresolved_reloc
11133 && !((input_section->flags & SEC_DEBUGGING) != 0
11134 && h->elf.def_dynamic))
11136 (*_bfd_error_handler)
11137 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
11140 (long) rel->r_offset,
11141 ppc64_elf_howto_table[(int) r_type]->name,
11142 h->elf.root.root.string);
11146 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
11154 if (r != bfd_reloc_ok)
11156 if (sym_name == NULL)
11157 sym_name = "(null)";
11158 if (r == bfd_reloc_overflow)
11163 && h->elf.root.type == bfd_link_hash_undefweak
11164 && ppc64_elf_howto_table[r_type]->pc_relative)
11166 /* Assume this is a call protected by other code that
11167 detects the symbol is undefined. If this is the case,
11168 we can safely ignore the overflow. If not, the
11169 program is hosed anyway, and a little warning isn't
11175 if (!((*info->callbacks->reloc_overflow)
11176 (info, (h ? &h->elf.root : NULL), sym_name,
11177 ppc64_elf_howto_table[r_type]->name,
11178 orig_addend, input_bfd, input_section, rel->r_offset)))
11183 (*_bfd_error_handler)
11184 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
11187 (long) rel->r_offset,
11188 ppc64_elf_howto_table[r_type]->name,
11196 /* If we're emitting relocations, then shortly after this function
11197 returns, reloc offsets and addends for this section will be
11198 adjusted. Worse, reloc symbol indices will be for the output
11199 file rather than the input. Save a copy of the relocs for
11200 opd_entry_value. */
11201 if (is_opd && (info->emitrelocations || info->relocatable))
11204 amt = input_section->reloc_count * sizeof (Elf_Internal_Rela);
11205 rel = bfd_alloc (input_bfd, amt);
11206 BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd_relocs == NULL);
11207 ppc64_elf_tdata (input_bfd)->opd_relocs = rel;
11210 memcpy (rel, relocs, amt);
11215 /* Adjust the value of any local symbols in opd sections. */
11218 ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
11219 const char *name ATTRIBUTE_UNUSED,
11220 Elf_Internal_Sym *elfsym,
11221 asection *input_sec,
11222 struct elf_link_hash_entry *h)
11224 long *opd_adjust, adjust;
11230 opd_adjust = get_opd_info (input_sec);
11231 if (opd_adjust == NULL)
11234 value = elfsym->st_value - input_sec->output_offset;
11235 if (!info->relocatable)
11236 value -= input_sec->output_section->vma;
11238 adjust = opd_adjust[value / 8];
11240 elfsym->st_value = 0;
11242 elfsym->st_value += adjust;
11246 /* Finish up dynamic symbol handling. We set the contents of various
11247 dynamic sections here. */
11250 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
11251 struct bfd_link_info *info,
11252 struct elf_link_hash_entry *h,
11253 Elf_Internal_Sym *sym)
11255 struct ppc_link_hash_table *htab;
11256 struct plt_entry *ent;
11257 Elf_Internal_Rela rela;
11260 htab = ppc_hash_table (info);
11262 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
11263 if (ent->plt.offset != (bfd_vma) -1)
11265 /* This symbol has an entry in the procedure linkage
11266 table. Set it up. */
11268 if (htab->plt == NULL
11269 || htab->relplt == NULL
11270 || htab->glink == NULL)
11273 /* Create a JMP_SLOT reloc to inform the dynamic linker to
11274 fill in the PLT entry. */
11275 rela.r_offset = (htab->plt->output_section->vma
11276 + htab->plt->output_offset
11277 + ent->plt.offset);
11278 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
11279 rela.r_addend = ent->addend;
11281 loc = htab->relplt->contents;
11282 loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
11283 * sizeof (Elf64_External_Rela));
11284 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
11289 Elf_Internal_Rela rela;
11292 /* This symbol needs a copy reloc. Set it up. */
11294 if (h->dynindx == -1
11295 || (h->root.type != bfd_link_hash_defined
11296 && h->root.type != bfd_link_hash_defweak)
11297 || htab->relbss == NULL)
11300 rela.r_offset = (h->root.u.def.value
11301 + h->root.u.def.section->output_section->vma
11302 + h->root.u.def.section->output_offset);
11303 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
11305 loc = htab->relbss->contents;
11306 loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela);
11307 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
11310 /* Mark some specially defined symbols as absolute. */
11311 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
11312 sym->st_shndx = SHN_ABS;
11317 /* Used to decide how to sort relocs in an optimal manner for the
11318 dynamic linker, before writing them out. */
11320 static enum elf_reloc_type_class
11321 ppc64_elf_reloc_type_class (const Elf_Internal_Rela *rela)
11323 enum elf_ppc64_reloc_type r_type;
11325 r_type = ELF64_R_TYPE (rela->r_info);
11328 case R_PPC64_RELATIVE:
11329 return reloc_class_relative;
11330 case R_PPC64_JMP_SLOT:
11331 return reloc_class_plt;
11333 return reloc_class_copy;
11335 return reloc_class_normal;
11339 /* Finish up the dynamic sections. */
11342 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
11343 struct bfd_link_info *info)
11345 struct ppc_link_hash_table *htab;
11349 htab = ppc_hash_table (info);
11350 dynobj = htab->elf.dynobj;
11351 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
11353 if (htab->elf.dynamic_sections_created)
11355 Elf64_External_Dyn *dyncon, *dynconend;
11357 if (sdyn == NULL || htab->got == NULL)
11360 dyncon = (Elf64_External_Dyn *) sdyn->contents;
11361 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
11362 for (; dyncon < dynconend; dyncon++)
11364 Elf_Internal_Dyn dyn;
11367 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
11374 case DT_PPC64_GLINK:
11376 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
11377 /* We stupidly defined DT_PPC64_GLINK to be the start
11378 of glink rather than the first entry point, which is
11379 what ld.so needs, and now have a bigger stub to
11380 support automatic multiple TOCs. */
11381 dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 32;
11385 s = bfd_get_section_by_name (output_bfd, ".opd");
11388 dyn.d_un.d_ptr = s->vma;
11391 case DT_PPC64_OPDSZ:
11392 s = bfd_get_section_by_name (output_bfd, ".opd");
11395 dyn.d_un.d_val = s->size;
11400 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
11405 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
11409 dyn.d_un.d_val = htab->relplt->size;
11413 /* Don't count procedure linkage table relocs in the
11414 overall reloc count. */
11418 dyn.d_un.d_val -= s->size;
11422 /* We may not be using the standard ELF linker script.
11423 If .rela.plt is the first .rela section, we adjust
11424 DT_RELA to not include it. */
11428 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
11430 dyn.d_un.d_ptr += s->size;
11434 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
11438 if (htab->got != NULL && htab->got->size != 0)
11440 /* Fill in the first entry in the global offset table.
11441 We use it to hold the link-time TOCbase. */
11442 bfd_put_64 (output_bfd,
11443 elf_gp (output_bfd) + TOC_BASE_OFF,
11444 htab->got->contents);
11446 /* Set .got entry size. */
11447 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8;
11450 if (htab->plt != NULL && htab->plt->size != 0)
11452 /* Set .plt entry size. */
11453 elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize
11457 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
11458 brlt ourselves if emitrelocations. */
11459 if (htab->brlt != NULL
11460 && htab->brlt->reloc_count != 0
11461 && !_bfd_elf_link_output_relocs (output_bfd,
11463 &elf_section_data (htab->brlt)->rel_hdr,
11464 elf_section_data (htab->brlt)->relocs,
11468 /* We need to handle writing out multiple GOT sections ourselves,
11469 since we didn't add them to DYNOBJ. We know dynobj is the first
11471 while ((dynobj = dynobj->link_next) != NULL)
11475 if (!is_ppc64_elf_target (dynobj->xvec))
11478 s = ppc64_elf_tdata (dynobj)->got;
11481 && s->output_section != bfd_abs_section_ptr
11482 && !bfd_set_section_contents (output_bfd, s->output_section,
11483 s->contents, s->output_offset,
11486 s = ppc64_elf_tdata (dynobj)->relgot;
11489 && s->output_section != bfd_abs_section_ptr
11490 && !bfd_set_section_contents (output_bfd, s->output_section,
11491 s->contents, s->output_offset,
11499 #include "elf64-target.h"