1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010, 2011, 2012 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.
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 3 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. */
25 /* The 64-bit PowerPC ELF ABI may be found at
26 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
27 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
35 #include "elf/ppc64.h"
36 #include "elf64-ppc.h"
39 static bfd_reloc_status_type ppc64_elf_ha_reloc
40 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
41 static bfd_reloc_status_type ppc64_elf_branch_reloc
42 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
43 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
44 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
45 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
46 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
47 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
48 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
49 static bfd_reloc_status_type ppc64_elf_toc_reloc
50 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
51 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
52 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
53 static bfd_reloc_status_type ppc64_elf_toc64_reloc
54 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
55 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
56 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
57 static bfd_vma opd_entry_value
58 (asection *, bfd_vma, asection **, bfd_vma *, bfd_boolean);
60 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
61 #define TARGET_LITTLE_NAME "elf64-powerpcle"
62 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
63 #define TARGET_BIG_NAME "elf64-powerpc"
64 #define ELF_ARCH bfd_arch_powerpc
65 #define ELF_TARGET_ID PPC64_ELF_DATA
66 #define ELF_MACHINE_CODE EM_PPC64
67 #define ELF_MAXPAGESIZE 0x10000
68 #define ELF_COMMONPAGESIZE 0x1000
69 #define elf_info_to_howto ppc64_elf_info_to_howto
71 #define elf_backend_want_got_sym 0
72 #define elf_backend_want_plt_sym 0
73 #define elf_backend_plt_alignment 3
74 #define elf_backend_plt_not_loaded 1
75 #define elf_backend_got_header_size 8
76 #define elf_backend_can_gc_sections 1
77 #define elf_backend_can_refcount 1
78 #define elf_backend_rela_normal 1
79 #define elf_backend_default_execstack 0
81 #define bfd_elf64_mkobject ppc64_elf_mkobject
82 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
83 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
84 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
85 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
86 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
87 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
88 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
89 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
90 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
92 #define elf_backend_object_p ppc64_elf_object_p
93 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
94 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
95 #define elf_backend_write_core_note ppc64_elf_write_core_note
96 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
97 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
98 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
99 #define elf_backend_check_directives ppc64_elf_process_dot_syms
100 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
101 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
102 #define elf_backend_check_relocs ppc64_elf_check_relocs
103 #define elf_backend_gc_keep ppc64_elf_gc_keep
104 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
105 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
106 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
107 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
108 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
109 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
110 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
111 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
112 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
113 #define elf_backend_action_discarded ppc64_elf_action_discarded
114 #define elf_backend_relocate_section ppc64_elf_relocate_section
115 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
116 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
117 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
118 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
119 #define elf_backend_special_sections ppc64_elf_special_sections
120 #define elf_backend_post_process_headers _bfd_elf_set_osabi
121 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
123 /* The name of the dynamic interpreter. This is put in the .interp
125 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
127 /* The size in bytes of an entry in the procedure linkage table. */
128 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
130 /* The initial size of the plt reserved for the dynamic linker. */
131 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
133 /* Offsets to some stack save slots. */
135 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
136 /* This one is dodgy. ABIv2 does not have a linker word, so use the
137 CR save slot. Used only by optimised __tls_get_addr call stub,
138 relying on __tls_get_addr_opt not saving CR.. */
139 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
141 /* TOC base pointers offset from start of TOC. */
142 #define TOC_BASE_OFF 0x8000
144 /* Offset of tp and dtp pointers from start of TLS block. */
145 #define TP_OFFSET 0x7000
146 #define DTP_OFFSET 0x8000
148 /* .plt call stub instructions. The normal stub is like this, but
149 sometimes the .plt entry crosses a 64k boundary and we need to
150 insert an addi to adjust r11. */
151 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
152 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
153 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
154 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
155 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
156 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
157 #define BCTR 0x4e800420 /* bctr */
159 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
160 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
161 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
163 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
164 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
165 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
166 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
167 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
168 #define BNECTR 0x4ca20420 /* bnectr+ */
169 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
171 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
172 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
173 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
175 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
177 /* glink call stub instructions. We enter with the index in R0. */
178 #define GLINK_CALL_STUB_SIZE (16*4)
182 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
183 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
185 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
186 /* ld %2,(0b-1b)(%11) */
187 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
188 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
194 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
195 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
196 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
197 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
198 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
201 #define NOP 0x60000000
203 /* Some other nops. */
204 #define CROR_151515 0x4def7b82
205 #define CROR_313131 0x4ffffb82
207 /* .glink entries for the first 32k functions are two instructions. */
208 #define LI_R0_0 0x38000000 /* li %r0,0 */
209 #define B_DOT 0x48000000 /* b . */
211 /* After that, we need two instructions to load the index, followed by
213 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
214 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
216 /* Instructions used by the save and restore reg functions. */
217 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
218 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
219 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
220 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
221 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
222 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
223 #define LI_R12_0 0x39800000 /* li %r12,0 */
224 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
225 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
226 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
227 #define BLR 0x4e800020 /* blr */
229 /* Since .opd is an array of descriptors and each entry will end up
230 with identical R_PPC64_RELATIVE relocs, there is really no need to
231 propagate .opd relocs; The dynamic linker should be taught to
232 relocate .opd without reloc entries. */
233 #ifndef NO_OPD_RELOCS
234 #define NO_OPD_RELOCS 0
237 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
239 /* Relocation HOWTO's. */
240 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
242 static reloc_howto_type ppc64_elf_howto_raw[] = {
243 /* This reloc does nothing. */
244 HOWTO (R_PPC64_NONE, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 FALSE, /* pc_relative */
250 complain_overflow_dont, /* complain_on_overflow */
251 bfd_elf_generic_reloc, /* special_function */
252 "R_PPC64_NONE", /* name */
253 FALSE, /* partial_inplace */
256 FALSE), /* pcrel_offset */
258 /* A standard 32 bit relocation. */
259 HOWTO (R_PPC64_ADDR32, /* type */
261 2, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE, /* pc_relative */
265 complain_overflow_bitfield, /* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_PPC64_ADDR32", /* name */
268 FALSE, /* partial_inplace */
270 0xffffffff, /* dst_mask */
271 FALSE), /* pcrel_offset */
273 /* An absolute 26 bit branch; the lower two bits must be zero.
274 FIXME: we don't check that, we just clear them. */
275 HOWTO (R_PPC64_ADDR24, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 FALSE, /* pc_relative */
281 complain_overflow_bitfield, /* complain_on_overflow */
282 bfd_elf_generic_reloc, /* special_function */
283 "R_PPC64_ADDR24", /* name */
284 FALSE, /* partial_inplace */
286 0x03fffffc, /* dst_mask */
287 FALSE), /* pcrel_offset */
289 /* A standard 16 bit relocation. */
290 HOWTO (R_PPC64_ADDR16, /* type */
292 1, /* size (0 = byte, 1 = short, 2 = long) */
294 FALSE, /* pc_relative */
296 complain_overflow_bitfield, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_PPC64_ADDR16", /* name */
299 FALSE, /* partial_inplace */
301 0xffff, /* dst_mask */
302 FALSE), /* pcrel_offset */
304 /* A 16 bit relocation without overflow. */
305 HOWTO (R_PPC64_ADDR16_LO, /* type */
307 1, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE, /* pc_relative */
311 complain_overflow_dont,/* complain_on_overflow */
312 bfd_elf_generic_reloc, /* special_function */
313 "R_PPC64_ADDR16_LO", /* name */
314 FALSE, /* partial_inplace */
316 0xffff, /* dst_mask */
317 FALSE), /* pcrel_offset */
319 /* Bits 16-31 of an address. */
320 HOWTO (R_PPC64_ADDR16_HI, /* type */
322 1, /* size (0 = byte, 1 = short, 2 = long) */
324 FALSE, /* pc_relative */
326 complain_overflow_signed, /* complain_on_overflow */
327 bfd_elf_generic_reloc, /* special_function */
328 "R_PPC64_ADDR16_HI", /* name */
329 FALSE, /* partial_inplace */
331 0xffff, /* dst_mask */
332 FALSE), /* pcrel_offset */
334 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
335 bits, treated as a signed number, is negative. */
336 HOWTO (R_PPC64_ADDR16_HA, /* type */
338 1, /* size (0 = byte, 1 = short, 2 = long) */
340 FALSE, /* pc_relative */
342 complain_overflow_signed, /* complain_on_overflow */
343 ppc64_elf_ha_reloc, /* special_function */
344 "R_PPC64_ADDR16_HA", /* name */
345 FALSE, /* partial_inplace */
347 0xffff, /* dst_mask */
348 FALSE), /* pcrel_offset */
350 /* An absolute 16 bit branch; the lower two bits must be zero.
351 FIXME: we don't check that, we just clear them. */
352 HOWTO (R_PPC64_ADDR14, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 FALSE, /* pc_relative */
358 complain_overflow_bitfield, /* complain_on_overflow */
359 ppc64_elf_branch_reloc, /* special_function */
360 "R_PPC64_ADDR14", /* name */
361 FALSE, /* partial_inplace */
363 0x0000fffc, /* dst_mask */
364 FALSE), /* pcrel_offset */
366 /* An absolute 16 bit branch, for which bit 10 should be set to
367 indicate that the branch is expected to be taken. The lower two
368 bits must be zero. */
369 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE, /* pc_relative */
375 complain_overflow_bitfield, /* complain_on_overflow */
376 ppc64_elf_brtaken_reloc, /* special_function */
377 "R_PPC64_ADDR14_BRTAKEN",/* name */
378 FALSE, /* partial_inplace */
380 0x0000fffc, /* dst_mask */
381 FALSE), /* pcrel_offset */
383 /* An absolute 16 bit branch, for which bit 10 should be set to
384 indicate that the branch is not expected to be taken. The lower
385 two bits must be zero. */
386 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE, /* pc_relative */
392 complain_overflow_bitfield, /* complain_on_overflow */
393 ppc64_elf_brtaken_reloc, /* special_function */
394 "R_PPC64_ADDR14_BRNTAKEN",/* name */
395 FALSE, /* partial_inplace */
397 0x0000fffc, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 /* A relative 26 bit branch; the lower two bits must be zero. */
401 HOWTO (R_PPC64_REL24, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 TRUE, /* pc_relative */
407 complain_overflow_signed, /* complain_on_overflow */
408 ppc64_elf_branch_reloc, /* special_function */
409 "R_PPC64_REL24", /* name */
410 FALSE, /* partial_inplace */
412 0x03fffffc, /* dst_mask */
413 TRUE), /* pcrel_offset */
415 /* A relative 16 bit branch; the lower two bits must be zero. */
416 HOWTO (R_PPC64_REL14, /* type */
418 2, /* size (0 = byte, 1 = short, 2 = long) */
420 TRUE, /* pc_relative */
422 complain_overflow_signed, /* complain_on_overflow */
423 ppc64_elf_branch_reloc, /* special_function */
424 "R_PPC64_REL14", /* name */
425 FALSE, /* partial_inplace */
427 0x0000fffc, /* dst_mask */
428 TRUE), /* pcrel_offset */
430 /* A relative 16 bit branch. Bit 10 should be set to indicate that
431 the branch is expected to be taken. The lower two bits must be
433 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
437 TRUE, /* pc_relative */
439 complain_overflow_signed, /* complain_on_overflow */
440 ppc64_elf_brtaken_reloc, /* special_function */
441 "R_PPC64_REL14_BRTAKEN", /* name */
442 FALSE, /* partial_inplace */
444 0x0000fffc, /* dst_mask */
445 TRUE), /* pcrel_offset */
447 /* A relative 16 bit branch. Bit 10 should be set to indicate that
448 the branch is not expected to be taken. The lower two bits must
450 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 TRUE, /* pc_relative */
456 complain_overflow_signed, /* complain_on_overflow */
457 ppc64_elf_brtaken_reloc, /* special_function */
458 "R_PPC64_REL14_BRNTAKEN",/* name */
459 FALSE, /* partial_inplace */
461 0x0000fffc, /* dst_mask */
462 TRUE), /* pcrel_offset */
464 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
466 HOWTO (R_PPC64_GOT16, /* type */
468 1, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE, /* pc_relative */
472 complain_overflow_signed, /* complain_on_overflow */
473 ppc64_elf_unhandled_reloc, /* special_function */
474 "R_PPC64_GOT16", /* name */
475 FALSE, /* partial_inplace */
477 0xffff, /* dst_mask */
478 FALSE), /* pcrel_offset */
480 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
482 HOWTO (R_PPC64_GOT16_LO, /* type */
484 1, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE, /* pc_relative */
488 complain_overflow_dont, /* complain_on_overflow */
489 ppc64_elf_unhandled_reloc, /* special_function */
490 "R_PPC64_GOT16_LO", /* name */
491 FALSE, /* partial_inplace */
493 0xffff, /* dst_mask */
494 FALSE), /* pcrel_offset */
496 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
498 HOWTO (R_PPC64_GOT16_HI, /* type */
500 1, /* size (0 = byte, 1 = short, 2 = long) */
502 FALSE, /* pc_relative */
504 complain_overflow_signed,/* complain_on_overflow */
505 ppc64_elf_unhandled_reloc, /* special_function */
506 "R_PPC64_GOT16_HI", /* name */
507 FALSE, /* partial_inplace */
509 0xffff, /* dst_mask */
510 FALSE), /* pcrel_offset */
512 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
514 HOWTO (R_PPC64_GOT16_HA, /* type */
516 1, /* size (0 = byte, 1 = short, 2 = long) */
518 FALSE, /* pc_relative */
520 complain_overflow_signed,/* complain_on_overflow */
521 ppc64_elf_unhandled_reloc, /* special_function */
522 "R_PPC64_GOT16_HA", /* name */
523 FALSE, /* partial_inplace */
525 0xffff, /* dst_mask */
526 FALSE), /* pcrel_offset */
528 /* This is used only by the dynamic linker. The symbol should exist
529 both in the object being run and in some shared library. The
530 dynamic linker copies the data addressed by the symbol from the
531 shared library into the object, because the object being
532 run has to have the data at some particular address. */
533 HOWTO (R_PPC64_COPY, /* type */
535 0, /* this one is variable size */
537 FALSE, /* pc_relative */
539 complain_overflow_dont, /* complain_on_overflow */
540 ppc64_elf_unhandled_reloc, /* special_function */
541 "R_PPC64_COPY", /* name */
542 FALSE, /* partial_inplace */
545 FALSE), /* pcrel_offset */
547 /* Like R_PPC64_ADDR64, but used when setting global offset table
549 HOWTO (R_PPC64_GLOB_DAT, /* type */
551 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
553 FALSE, /* pc_relative */
555 complain_overflow_dont, /* complain_on_overflow */
556 ppc64_elf_unhandled_reloc, /* special_function */
557 "R_PPC64_GLOB_DAT", /* name */
558 FALSE, /* partial_inplace */
560 ONES (64), /* dst_mask */
561 FALSE), /* pcrel_offset */
563 /* Created by the link editor. Marks a procedure linkage table
564 entry for a symbol. */
565 HOWTO (R_PPC64_JMP_SLOT, /* type */
567 0, /* size (0 = byte, 1 = short, 2 = long) */
569 FALSE, /* pc_relative */
571 complain_overflow_dont, /* complain_on_overflow */
572 ppc64_elf_unhandled_reloc, /* special_function */
573 "R_PPC64_JMP_SLOT", /* name */
574 FALSE, /* partial_inplace */
577 FALSE), /* pcrel_offset */
579 /* Used only by the dynamic linker. When the object is run, this
580 doubleword64 is set to the load address of the object, plus the
582 HOWTO (R_PPC64_RELATIVE, /* type */
584 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
586 FALSE, /* pc_relative */
588 complain_overflow_dont, /* complain_on_overflow */
589 bfd_elf_generic_reloc, /* special_function */
590 "R_PPC64_RELATIVE", /* name */
591 FALSE, /* partial_inplace */
593 ONES (64), /* dst_mask */
594 FALSE), /* pcrel_offset */
596 /* Like R_PPC64_ADDR32, but may be unaligned. */
597 HOWTO (R_PPC64_UADDR32, /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 FALSE, /* pc_relative */
603 complain_overflow_bitfield, /* complain_on_overflow */
604 bfd_elf_generic_reloc, /* special_function */
605 "R_PPC64_UADDR32", /* name */
606 FALSE, /* partial_inplace */
608 0xffffffff, /* dst_mask */
609 FALSE), /* pcrel_offset */
611 /* Like R_PPC64_ADDR16, but may be unaligned. */
612 HOWTO (R_PPC64_UADDR16, /* type */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE, /* pc_relative */
618 complain_overflow_bitfield, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 "R_PPC64_UADDR16", /* name */
621 FALSE, /* partial_inplace */
623 0xffff, /* dst_mask */
624 FALSE), /* pcrel_offset */
626 /* 32-bit PC relative. */
627 HOWTO (R_PPC64_REL32, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 TRUE, /* pc_relative */
633 /* FIXME: Verify. Was complain_overflow_bitfield. */
634 complain_overflow_signed, /* complain_on_overflow */
635 bfd_elf_generic_reloc, /* special_function */
636 "R_PPC64_REL32", /* name */
637 FALSE, /* partial_inplace */
639 0xffffffff, /* dst_mask */
640 TRUE), /* pcrel_offset */
642 /* 32-bit relocation to the symbol's procedure linkage table. */
643 HOWTO (R_PPC64_PLT32, /* type */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
647 FALSE, /* pc_relative */
649 complain_overflow_bitfield, /* complain_on_overflow */
650 ppc64_elf_unhandled_reloc, /* special_function */
651 "R_PPC64_PLT32", /* name */
652 FALSE, /* partial_inplace */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
657 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
658 FIXME: R_PPC64_PLTREL32 not supported. */
659 HOWTO (R_PPC64_PLTREL32, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 TRUE, /* pc_relative */
665 complain_overflow_signed, /* complain_on_overflow */
666 bfd_elf_generic_reloc, /* special_function */
667 "R_PPC64_PLTREL32", /* name */
668 FALSE, /* partial_inplace */
670 0xffffffff, /* dst_mask */
671 TRUE), /* pcrel_offset */
673 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
675 HOWTO (R_PPC64_PLT16_LO, /* type */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE, /* pc_relative */
681 complain_overflow_dont, /* complain_on_overflow */
682 ppc64_elf_unhandled_reloc, /* special_function */
683 "R_PPC64_PLT16_LO", /* name */
684 FALSE, /* partial_inplace */
686 0xffff, /* dst_mask */
687 FALSE), /* pcrel_offset */
689 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
691 HOWTO (R_PPC64_PLT16_HI, /* type */
693 1, /* size (0 = byte, 1 = short, 2 = long) */
695 FALSE, /* pc_relative */
697 complain_overflow_signed, /* complain_on_overflow */
698 ppc64_elf_unhandled_reloc, /* special_function */
699 "R_PPC64_PLT16_HI", /* name */
700 FALSE, /* partial_inplace */
702 0xffff, /* dst_mask */
703 FALSE), /* pcrel_offset */
705 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
707 HOWTO (R_PPC64_PLT16_HA, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE, /* pc_relative */
713 complain_overflow_signed, /* complain_on_overflow */
714 ppc64_elf_unhandled_reloc, /* special_function */
715 "R_PPC64_PLT16_HA", /* name */
716 FALSE, /* partial_inplace */
718 0xffff, /* dst_mask */
719 FALSE), /* pcrel_offset */
721 /* 16-bit section relative relocation. */
722 HOWTO (R_PPC64_SECTOFF, /* type */
724 1, /* size (0 = byte, 1 = short, 2 = long) */
726 FALSE, /* pc_relative */
728 complain_overflow_bitfield, /* complain_on_overflow */
729 ppc64_elf_sectoff_reloc, /* special_function */
730 "R_PPC64_SECTOFF", /* name */
731 FALSE, /* partial_inplace */
733 0xffff, /* dst_mask */
734 FALSE), /* pcrel_offset */
736 /* Like R_PPC64_SECTOFF, but no overflow warning. */
737 HOWTO (R_PPC64_SECTOFF_LO, /* type */
739 1, /* size (0 = byte, 1 = short, 2 = long) */
741 FALSE, /* pc_relative */
743 complain_overflow_dont, /* complain_on_overflow */
744 ppc64_elf_sectoff_reloc, /* special_function */
745 "R_PPC64_SECTOFF_LO", /* name */
746 FALSE, /* partial_inplace */
748 0xffff, /* dst_mask */
749 FALSE), /* pcrel_offset */
751 /* 16-bit upper half section relative relocation. */
752 HOWTO (R_PPC64_SECTOFF_HI, /* type */
754 1, /* size (0 = byte, 1 = short, 2 = long) */
756 FALSE, /* pc_relative */
758 complain_overflow_signed, /* complain_on_overflow */
759 ppc64_elf_sectoff_reloc, /* special_function */
760 "R_PPC64_SECTOFF_HI", /* name */
761 FALSE, /* partial_inplace */
763 0xffff, /* dst_mask */
764 FALSE), /* pcrel_offset */
766 /* 16-bit upper half adjusted section relative relocation. */
767 HOWTO (R_PPC64_SECTOFF_HA, /* type */
769 1, /* size (0 = byte, 1 = short, 2 = long) */
771 FALSE, /* pc_relative */
773 complain_overflow_signed, /* complain_on_overflow */
774 ppc64_elf_sectoff_ha_reloc, /* special_function */
775 "R_PPC64_SECTOFF_HA", /* name */
776 FALSE, /* partial_inplace */
778 0xffff, /* dst_mask */
779 FALSE), /* pcrel_offset */
781 /* Like R_PPC64_REL24 without touching the two least significant bits. */
782 HOWTO (R_PPC64_REL30, /* type */
784 2, /* size (0 = byte, 1 = short, 2 = long) */
786 TRUE, /* pc_relative */
788 complain_overflow_dont, /* complain_on_overflow */
789 bfd_elf_generic_reloc, /* special_function */
790 "R_PPC64_REL30", /* name */
791 FALSE, /* partial_inplace */
793 0xfffffffc, /* dst_mask */
794 TRUE), /* pcrel_offset */
796 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
798 /* A standard 64-bit relocation. */
799 HOWTO (R_PPC64_ADDR64, /* type */
801 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
803 FALSE, /* pc_relative */
805 complain_overflow_dont, /* complain_on_overflow */
806 bfd_elf_generic_reloc, /* special_function */
807 "R_PPC64_ADDR64", /* name */
808 FALSE, /* partial_inplace */
810 ONES (64), /* dst_mask */
811 FALSE), /* pcrel_offset */
813 /* The bits 32-47 of an address. */
814 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE, /* pc_relative */
820 complain_overflow_dont, /* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_PPC64_ADDR16_HIGHER", /* name */
823 FALSE, /* partial_inplace */
825 0xffff, /* dst_mask */
826 FALSE), /* pcrel_offset */
828 /* The bits 32-47 of an address, plus 1 if the contents of the low
829 16 bits, treated as a signed number, is negative. */
830 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE, /* pc_relative */
836 complain_overflow_dont, /* complain_on_overflow */
837 ppc64_elf_ha_reloc, /* special_function */
838 "R_PPC64_ADDR16_HIGHERA", /* name */
839 FALSE, /* partial_inplace */
841 0xffff, /* dst_mask */
842 FALSE), /* pcrel_offset */
844 /* The bits 48-63 of an address. */
845 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
847 1, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE, /* pc_relative */
851 complain_overflow_dont, /* complain_on_overflow */
852 bfd_elf_generic_reloc, /* special_function */
853 "R_PPC64_ADDR16_HIGHEST", /* name */
854 FALSE, /* partial_inplace */
856 0xffff, /* dst_mask */
857 FALSE), /* pcrel_offset */
859 /* The bits 48-63 of an address, plus 1 if the contents of the low
860 16 bits, treated as a signed number, is negative. */
861 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
863 1, /* size (0 = byte, 1 = short, 2 = long) */
865 FALSE, /* pc_relative */
867 complain_overflow_dont, /* complain_on_overflow */
868 ppc64_elf_ha_reloc, /* special_function */
869 "R_PPC64_ADDR16_HIGHESTA", /* name */
870 FALSE, /* partial_inplace */
872 0xffff, /* dst_mask */
873 FALSE), /* pcrel_offset */
875 /* Like ADDR64, but may be unaligned. */
876 HOWTO (R_PPC64_UADDR64, /* type */
878 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
880 FALSE, /* pc_relative */
882 complain_overflow_dont, /* complain_on_overflow */
883 bfd_elf_generic_reloc, /* special_function */
884 "R_PPC64_UADDR64", /* name */
885 FALSE, /* partial_inplace */
887 ONES (64), /* dst_mask */
888 FALSE), /* pcrel_offset */
890 /* 64-bit relative relocation. */
891 HOWTO (R_PPC64_REL64, /* type */
893 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
895 TRUE, /* pc_relative */
897 complain_overflow_dont, /* complain_on_overflow */
898 bfd_elf_generic_reloc, /* special_function */
899 "R_PPC64_REL64", /* name */
900 FALSE, /* partial_inplace */
902 ONES (64), /* dst_mask */
903 TRUE), /* pcrel_offset */
905 /* 64-bit relocation to the symbol's procedure linkage table. */
906 HOWTO (R_PPC64_PLT64, /* type */
908 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
910 FALSE, /* pc_relative */
912 complain_overflow_dont, /* complain_on_overflow */
913 ppc64_elf_unhandled_reloc, /* special_function */
914 "R_PPC64_PLT64", /* name */
915 FALSE, /* partial_inplace */
917 ONES (64), /* dst_mask */
918 FALSE), /* pcrel_offset */
920 /* 64-bit PC relative relocation to the symbol's procedure linkage
922 /* FIXME: R_PPC64_PLTREL64 not supported. */
923 HOWTO (R_PPC64_PLTREL64, /* type */
925 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
927 TRUE, /* pc_relative */
929 complain_overflow_dont, /* complain_on_overflow */
930 ppc64_elf_unhandled_reloc, /* special_function */
931 "R_PPC64_PLTREL64", /* name */
932 FALSE, /* partial_inplace */
934 ONES (64), /* dst_mask */
935 TRUE), /* pcrel_offset */
937 /* 16 bit TOC-relative relocation. */
939 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
940 HOWTO (R_PPC64_TOC16, /* type */
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 FALSE, /* pc_relative */
946 complain_overflow_signed, /* complain_on_overflow */
947 ppc64_elf_toc_reloc, /* special_function */
948 "R_PPC64_TOC16", /* name */
949 FALSE, /* partial_inplace */
951 0xffff, /* dst_mask */
952 FALSE), /* pcrel_offset */
954 /* 16 bit TOC-relative relocation without overflow. */
956 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
957 HOWTO (R_PPC64_TOC16_LO, /* type */
959 1, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE, /* pc_relative */
963 complain_overflow_dont, /* complain_on_overflow */
964 ppc64_elf_toc_reloc, /* special_function */
965 "R_PPC64_TOC16_LO", /* name */
966 FALSE, /* partial_inplace */
968 0xffff, /* dst_mask */
969 FALSE), /* pcrel_offset */
971 /* 16 bit TOC-relative relocation, high 16 bits. */
973 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
974 HOWTO (R_PPC64_TOC16_HI, /* type */
976 1, /* size (0 = byte, 1 = short, 2 = long) */
978 FALSE, /* pc_relative */
980 complain_overflow_signed, /* complain_on_overflow */
981 ppc64_elf_toc_reloc, /* special_function */
982 "R_PPC64_TOC16_HI", /* name */
983 FALSE, /* partial_inplace */
985 0xffff, /* dst_mask */
986 FALSE), /* pcrel_offset */
988 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
989 contents of the low 16 bits, treated as a signed number, is
992 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
993 HOWTO (R_PPC64_TOC16_HA, /* type */
995 1, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE, /* pc_relative */
999 complain_overflow_signed, /* complain_on_overflow */
1000 ppc64_elf_toc_ha_reloc, /* special_function */
1001 "R_PPC64_TOC16_HA", /* name */
1002 FALSE, /* partial_inplace */
1004 0xffff, /* dst_mask */
1005 FALSE), /* pcrel_offset */
1007 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1009 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1010 HOWTO (R_PPC64_TOC, /* type */
1012 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1014 FALSE, /* pc_relative */
1016 complain_overflow_bitfield, /* complain_on_overflow */
1017 ppc64_elf_toc64_reloc, /* special_function */
1018 "R_PPC64_TOC", /* name */
1019 FALSE, /* partial_inplace */
1021 ONES (64), /* dst_mask */
1022 FALSE), /* pcrel_offset */
1024 /* Like R_PPC64_GOT16, but also informs the link editor that the
1025 value to relocate may (!) refer to a PLT entry which the link
1026 editor (a) may replace with the symbol value. If the link editor
1027 is unable to fully resolve the symbol, it may (b) create a PLT
1028 entry and store the address to the new PLT entry in the GOT.
1029 This permits lazy resolution of function symbols at run time.
1030 The link editor may also skip all of this and just (c) emit a
1031 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1032 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1033 HOWTO (R_PPC64_PLTGOT16, /* type */
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE, /* pc_relative */
1039 complain_overflow_signed, /* complain_on_overflow */
1040 ppc64_elf_unhandled_reloc, /* special_function */
1041 "R_PPC64_PLTGOT16", /* name */
1042 FALSE, /* partial_inplace */
1044 0xffff, /* dst_mask */
1045 FALSE), /* pcrel_offset */
1047 /* Like R_PPC64_PLTGOT16, but without overflow. */
1048 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1049 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
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_LO", /* name */
1058 FALSE, /* partial_inplace */
1060 0xffff, /* dst_mask */
1061 FALSE), /* pcrel_offset */
1063 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1064 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1065 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
1066 16, /* rightshift */
1067 1, /* size (0 = byte, 1 = short, 2 = long) */
1069 FALSE, /* pc_relative */
1071 complain_overflow_signed, /* complain_on_overflow */
1072 ppc64_elf_unhandled_reloc, /* special_function */
1073 "R_PPC64_PLTGOT16_HI", /* name */
1074 FALSE, /* partial_inplace */
1076 0xffff, /* dst_mask */
1077 FALSE), /* pcrel_offset */
1079 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1080 1 if the contents of the low 16 bits, treated as a signed number,
1082 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1083 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1084 16, /* rightshift */
1085 1, /* size (0 = byte, 1 = short, 2 = long) */
1087 FALSE, /* pc_relative */
1089 complain_overflow_signed, /* complain_on_overflow */
1090 ppc64_elf_unhandled_reloc, /* special_function */
1091 "R_PPC64_PLTGOT16_HA", /* name */
1092 FALSE, /* partial_inplace */
1094 0xffff, /* dst_mask */
1095 FALSE), /* pcrel_offset */
1097 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1098 HOWTO (R_PPC64_ADDR16_DS, /* type */
1100 1, /* size (0 = byte, 1 = short, 2 = long) */
1102 FALSE, /* pc_relative */
1104 complain_overflow_bitfield, /* complain_on_overflow */
1105 bfd_elf_generic_reloc, /* special_function */
1106 "R_PPC64_ADDR16_DS", /* name */
1107 FALSE, /* partial_inplace */
1109 0xfffc, /* dst_mask */
1110 FALSE), /* pcrel_offset */
1112 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1113 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1115 1, /* size (0 = byte, 1 = short, 2 = long) */
1117 FALSE, /* pc_relative */
1119 complain_overflow_dont,/* complain_on_overflow */
1120 bfd_elf_generic_reloc, /* special_function */
1121 "R_PPC64_ADDR16_LO_DS",/* name */
1122 FALSE, /* partial_inplace */
1124 0xfffc, /* dst_mask */
1125 FALSE), /* pcrel_offset */
1127 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1128 HOWTO (R_PPC64_GOT16_DS, /* type */
1130 1, /* size (0 = byte, 1 = short, 2 = long) */
1132 FALSE, /* pc_relative */
1134 complain_overflow_signed, /* complain_on_overflow */
1135 ppc64_elf_unhandled_reloc, /* special_function */
1136 "R_PPC64_GOT16_DS", /* name */
1137 FALSE, /* partial_inplace */
1139 0xfffc, /* dst_mask */
1140 FALSE), /* pcrel_offset */
1142 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1143 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1145 1, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE, /* pc_relative */
1149 complain_overflow_dont, /* complain_on_overflow */
1150 ppc64_elf_unhandled_reloc, /* special_function */
1151 "R_PPC64_GOT16_LO_DS", /* name */
1152 FALSE, /* partial_inplace */
1154 0xfffc, /* dst_mask */
1155 FALSE), /* pcrel_offset */
1157 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1158 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1160 1, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE, /* pc_relative */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 ppc64_elf_unhandled_reloc, /* special_function */
1166 "R_PPC64_PLT16_LO_DS", /* name */
1167 FALSE, /* partial_inplace */
1169 0xfffc, /* dst_mask */
1170 FALSE), /* pcrel_offset */
1172 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1173 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1175 1, /* size (0 = byte, 1 = short, 2 = long) */
1177 FALSE, /* pc_relative */
1179 complain_overflow_bitfield, /* complain_on_overflow */
1180 ppc64_elf_sectoff_reloc, /* special_function */
1181 "R_PPC64_SECTOFF_DS", /* name */
1182 FALSE, /* partial_inplace */
1184 0xfffc, /* dst_mask */
1185 FALSE), /* pcrel_offset */
1187 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1188 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1190 1, /* size (0 = byte, 1 = short, 2 = long) */
1192 FALSE, /* pc_relative */
1194 complain_overflow_dont, /* complain_on_overflow */
1195 ppc64_elf_sectoff_reloc, /* special_function */
1196 "R_PPC64_SECTOFF_LO_DS",/* name */
1197 FALSE, /* partial_inplace */
1199 0xfffc, /* dst_mask */
1200 FALSE), /* pcrel_offset */
1202 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1203 HOWTO (R_PPC64_TOC16_DS, /* type */
1205 1, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE, /* pc_relative */
1209 complain_overflow_signed, /* complain_on_overflow */
1210 ppc64_elf_toc_reloc, /* special_function */
1211 "R_PPC64_TOC16_DS", /* name */
1212 FALSE, /* partial_inplace */
1214 0xfffc, /* dst_mask */
1215 FALSE), /* pcrel_offset */
1217 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1218 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1220 1, /* size (0 = byte, 1 = short, 2 = long) */
1222 FALSE, /* pc_relative */
1224 complain_overflow_dont, /* complain_on_overflow */
1225 ppc64_elf_toc_reloc, /* special_function */
1226 "R_PPC64_TOC16_LO_DS", /* name */
1227 FALSE, /* partial_inplace */
1229 0xfffc, /* dst_mask */
1230 FALSE), /* pcrel_offset */
1232 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1233 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1234 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1236 1, /* size (0 = byte, 1 = short, 2 = long) */
1238 FALSE, /* pc_relative */
1240 complain_overflow_signed, /* complain_on_overflow */
1241 ppc64_elf_unhandled_reloc, /* special_function */
1242 "R_PPC64_PLTGOT16_DS", /* name */
1243 FALSE, /* partial_inplace */
1245 0xfffc, /* dst_mask */
1246 FALSE), /* pcrel_offset */
1248 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1249 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1250 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1252 1, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE, /* pc_relative */
1256 complain_overflow_dont, /* complain_on_overflow */
1257 ppc64_elf_unhandled_reloc, /* special_function */
1258 "R_PPC64_PLTGOT16_LO_DS",/* name */
1259 FALSE, /* partial_inplace */
1261 0xfffc, /* dst_mask */
1262 FALSE), /* pcrel_offset */
1264 /* Marker relocs for TLS. */
1267 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 FALSE, /* pc_relative */
1271 complain_overflow_dont, /* complain_on_overflow */
1272 bfd_elf_generic_reloc, /* special_function */
1273 "R_PPC64_TLS", /* name */
1274 FALSE, /* partial_inplace */
1277 FALSE), /* pcrel_offset */
1279 HOWTO (R_PPC64_TLSGD,
1281 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE, /* pc_relative */
1285 complain_overflow_dont, /* complain_on_overflow */
1286 bfd_elf_generic_reloc, /* special_function */
1287 "R_PPC64_TLSGD", /* name */
1288 FALSE, /* partial_inplace */
1291 FALSE), /* pcrel_offset */
1293 HOWTO (R_PPC64_TLSLD,
1295 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 FALSE, /* pc_relative */
1299 complain_overflow_dont, /* complain_on_overflow */
1300 bfd_elf_generic_reloc, /* special_function */
1301 "R_PPC64_TLSLD", /* name */
1302 FALSE, /* partial_inplace */
1305 FALSE), /* pcrel_offset */
1307 HOWTO (R_PPC64_TOCSAVE,
1309 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE, /* pc_relative */
1313 complain_overflow_dont, /* complain_on_overflow */
1314 bfd_elf_generic_reloc, /* special_function */
1315 "R_PPC64_TOCSAVE", /* name */
1316 FALSE, /* partial_inplace */
1319 FALSE), /* pcrel_offset */
1321 /* Computes the load module index of the load module that contains the
1322 definition of its TLS sym. */
1323 HOWTO (R_PPC64_DTPMOD64,
1325 4, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE, /* pc_relative */
1329 complain_overflow_dont, /* complain_on_overflow */
1330 ppc64_elf_unhandled_reloc, /* special_function */
1331 "R_PPC64_DTPMOD64", /* name */
1332 FALSE, /* partial_inplace */
1334 ONES (64), /* dst_mask */
1335 FALSE), /* pcrel_offset */
1337 /* Computes a dtv-relative displacement, the difference between the value
1338 of sym+add and the base address of the thread-local storage block that
1339 contains the definition of sym, minus 0x8000. */
1340 HOWTO (R_PPC64_DTPREL64,
1342 4, /* size (0 = byte, 1 = short, 2 = long) */
1344 FALSE, /* pc_relative */
1346 complain_overflow_dont, /* complain_on_overflow */
1347 ppc64_elf_unhandled_reloc, /* special_function */
1348 "R_PPC64_DTPREL64", /* name */
1349 FALSE, /* partial_inplace */
1351 ONES (64), /* dst_mask */
1352 FALSE), /* pcrel_offset */
1354 /* A 16 bit dtprel reloc. */
1355 HOWTO (R_PPC64_DTPREL16,
1357 1, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE, /* pc_relative */
1361 complain_overflow_signed, /* complain_on_overflow */
1362 ppc64_elf_unhandled_reloc, /* special_function */
1363 "R_PPC64_DTPREL16", /* name */
1364 FALSE, /* partial_inplace */
1366 0xffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1369 /* Like DTPREL16, but no overflow. */
1370 HOWTO (R_PPC64_DTPREL16_LO,
1372 1, /* size (0 = byte, 1 = short, 2 = long) */
1374 FALSE, /* pc_relative */
1376 complain_overflow_dont, /* complain_on_overflow */
1377 ppc64_elf_unhandled_reloc, /* special_function */
1378 "R_PPC64_DTPREL16_LO", /* name */
1379 FALSE, /* partial_inplace */
1381 0xffff, /* dst_mask */
1382 FALSE), /* pcrel_offset */
1384 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1385 HOWTO (R_PPC64_DTPREL16_HI,
1386 16, /* rightshift */
1387 1, /* size (0 = byte, 1 = short, 2 = long) */
1389 FALSE, /* pc_relative */
1391 complain_overflow_signed, /* complain_on_overflow */
1392 ppc64_elf_unhandled_reloc, /* special_function */
1393 "R_PPC64_DTPREL16_HI", /* name */
1394 FALSE, /* partial_inplace */
1396 0xffff, /* dst_mask */
1397 FALSE), /* pcrel_offset */
1399 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1400 HOWTO (R_PPC64_DTPREL16_HA,
1401 16, /* rightshift */
1402 1, /* size (0 = byte, 1 = short, 2 = long) */
1404 FALSE, /* pc_relative */
1406 complain_overflow_signed, /* complain_on_overflow */
1407 ppc64_elf_unhandled_reloc, /* special_function */
1408 "R_PPC64_DTPREL16_HA", /* name */
1409 FALSE, /* partial_inplace */
1411 0xffff, /* dst_mask */
1412 FALSE), /* pcrel_offset */
1414 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1415 HOWTO (R_PPC64_DTPREL16_HIGHER,
1416 32, /* rightshift */
1417 1, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE, /* pc_relative */
1421 complain_overflow_dont, /* complain_on_overflow */
1422 ppc64_elf_unhandled_reloc, /* special_function */
1423 "R_PPC64_DTPREL16_HIGHER", /* name */
1424 FALSE, /* partial_inplace */
1426 0xffff, /* dst_mask */
1427 FALSE), /* pcrel_offset */
1429 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1430 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1431 32, /* rightshift */
1432 1, /* 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_DTPREL16_HIGHERA", /* name */
1439 FALSE, /* partial_inplace */
1441 0xffff, /* dst_mask */
1442 FALSE), /* pcrel_offset */
1444 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1445 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1446 48, /* rightshift */
1447 1, /* size (0 = byte, 1 = short, 2 = long) */
1449 FALSE, /* pc_relative */
1451 complain_overflow_dont, /* complain_on_overflow */
1452 ppc64_elf_unhandled_reloc, /* special_function */
1453 "R_PPC64_DTPREL16_HIGHEST", /* name */
1454 FALSE, /* partial_inplace */
1456 0xffff, /* dst_mask */
1457 FALSE), /* pcrel_offset */
1459 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1460 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1461 48, /* rightshift */
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_DTPREL16_HIGHESTA", /* name */
1469 FALSE, /* partial_inplace */
1471 0xffff, /* dst_mask */
1472 FALSE), /* pcrel_offset */
1474 /* Like DTPREL16, but for insns with a DS field. */
1475 HOWTO (R_PPC64_DTPREL16_DS,
1477 1, /* size (0 = byte, 1 = short, 2 = long) */
1479 FALSE, /* pc_relative */
1481 complain_overflow_signed, /* complain_on_overflow */
1482 ppc64_elf_unhandled_reloc, /* special_function */
1483 "R_PPC64_DTPREL16_DS", /* name */
1484 FALSE, /* partial_inplace */
1486 0xfffc, /* dst_mask */
1487 FALSE), /* pcrel_offset */
1489 /* Like DTPREL16_DS, but no overflow. */
1490 HOWTO (R_PPC64_DTPREL16_LO_DS,
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_DTPREL16_LO_DS", /* name */
1499 FALSE, /* partial_inplace */
1501 0xfffc, /* dst_mask */
1502 FALSE), /* pcrel_offset */
1504 /* Computes a tp-relative displacement, the difference between the value of
1505 sym+add and the value of the thread pointer (r13). */
1506 HOWTO (R_PPC64_TPREL64,
1508 4, /* size (0 = byte, 1 = short, 2 = long) */
1510 FALSE, /* pc_relative */
1512 complain_overflow_dont, /* complain_on_overflow */
1513 ppc64_elf_unhandled_reloc, /* special_function */
1514 "R_PPC64_TPREL64", /* name */
1515 FALSE, /* partial_inplace */
1517 ONES (64), /* dst_mask */
1518 FALSE), /* pcrel_offset */
1520 /* A 16 bit tprel reloc. */
1521 HOWTO (R_PPC64_TPREL16,
1523 1, /* size (0 = byte, 1 = short, 2 = long) */
1525 FALSE, /* pc_relative */
1527 complain_overflow_signed, /* complain_on_overflow */
1528 ppc64_elf_unhandled_reloc, /* special_function */
1529 "R_PPC64_TPREL16", /* name */
1530 FALSE, /* partial_inplace */
1532 0xffff, /* dst_mask */
1533 FALSE), /* pcrel_offset */
1535 /* Like TPREL16, but no overflow. */
1536 HOWTO (R_PPC64_TPREL16_LO,
1538 1, /* size (0 = byte, 1 = short, 2 = long) */
1540 FALSE, /* pc_relative */
1542 complain_overflow_dont, /* complain_on_overflow */
1543 ppc64_elf_unhandled_reloc, /* special_function */
1544 "R_PPC64_TPREL16_LO", /* name */
1545 FALSE, /* partial_inplace */
1547 0xffff, /* dst_mask */
1548 FALSE), /* pcrel_offset */
1550 /* Like TPREL16_LO, but next higher group of 16 bits. */
1551 HOWTO (R_PPC64_TPREL16_HI,
1552 16, /* rightshift */
1553 1, /* size (0 = byte, 1 = short, 2 = long) */
1555 FALSE, /* pc_relative */
1557 complain_overflow_signed, /* complain_on_overflow */
1558 ppc64_elf_unhandled_reloc, /* special_function */
1559 "R_PPC64_TPREL16_HI", /* name */
1560 FALSE, /* partial_inplace */
1562 0xffff, /* dst_mask */
1563 FALSE), /* pcrel_offset */
1565 /* Like TPREL16_HI, but adjust for low 16 bits. */
1566 HOWTO (R_PPC64_TPREL16_HA,
1567 16, /* rightshift */
1568 1, /* size (0 = byte, 1 = short, 2 = long) */
1570 FALSE, /* pc_relative */
1572 complain_overflow_signed, /* complain_on_overflow */
1573 ppc64_elf_unhandled_reloc, /* special_function */
1574 "R_PPC64_TPREL16_HA", /* name */
1575 FALSE, /* partial_inplace */
1577 0xffff, /* dst_mask */
1578 FALSE), /* pcrel_offset */
1580 /* Like TPREL16_HI, but next higher group of 16 bits. */
1581 HOWTO (R_PPC64_TPREL16_HIGHER,
1582 32, /* rightshift */
1583 1, /* size (0 = byte, 1 = short, 2 = long) */
1585 FALSE, /* pc_relative */
1587 complain_overflow_dont, /* complain_on_overflow */
1588 ppc64_elf_unhandled_reloc, /* special_function */
1589 "R_PPC64_TPREL16_HIGHER", /* name */
1590 FALSE, /* partial_inplace */
1592 0xffff, /* dst_mask */
1593 FALSE), /* pcrel_offset */
1595 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1596 HOWTO (R_PPC64_TPREL16_HIGHERA,
1597 32, /* rightshift */
1598 1, /* size (0 = byte, 1 = short, 2 = long) */
1600 FALSE, /* pc_relative */
1602 complain_overflow_dont, /* complain_on_overflow */
1603 ppc64_elf_unhandled_reloc, /* special_function */
1604 "R_PPC64_TPREL16_HIGHERA", /* name */
1605 FALSE, /* partial_inplace */
1607 0xffff, /* dst_mask */
1608 FALSE), /* pcrel_offset */
1610 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1611 HOWTO (R_PPC64_TPREL16_HIGHEST,
1612 48, /* rightshift */
1613 1, /* size (0 = byte, 1 = short, 2 = long) */
1615 FALSE, /* pc_relative */
1617 complain_overflow_dont, /* complain_on_overflow */
1618 ppc64_elf_unhandled_reloc, /* special_function */
1619 "R_PPC64_TPREL16_HIGHEST", /* name */
1620 FALSE, /* partial_inplace */
1622 0xffff, /* dst_mask */
1623 FALSE), /* pcrel_offset */
1625 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1626 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1627 48, /* rightshift */
1628 1, /* size (0 = byte, 1 = short, 2 = long) */
1630 FALSE, /* pc_relative */
1632 complain_overflow_dont, /* complain_on_overflow */
1633 ppc64_elf_unhandled_reloc, /* special_function */
1634 "R_PPC64_TPREL16_HIGHESTA", /* name */
1635 FALSE, /* partial_inplace */
1637 0xffff, /* dst_mask */
1638 FALSE), /* pcrel_offset */
1640 /* Like TPREL16, but for insns with a DS field. */
1641 HOWTO (R_PPC64_TPREL16_DS,
1643 1, /* size (0 = byte, 1 = short, 2 = long) */
1645 FALSE, /* pc_relative */
1647 complain_overflow_signed, /* complain_on_overflow */
1648 ppc64_elf_unhandled_reloc, /* special_function */
1649 "R_PPC64_TPREL16_DS", /* name */
1650 FALSE, /* partial_inplace */
1652 0xfffc, /* dst_mask */
1653 FALSE), /* pcrel_offset */
1655 /* Like TPREL16_DS, but no overflow. */
1656 HOWTO (R_PPC64_TPREL16_LO_DS,
1658 1, /* size (0 = byte, 1 = short, 2 = long) */
1660 FALSE, /* pc_relative */
1662 complain_overflow_dont, /* complain_on_overflow */
1663 ppc64_elf_unhandled_reloc, /* special_function */
1664 "R_PPC64_TPREL16_LO_DS", /* name */
1665 FALSE, /* partial_inplace */
1667 0xfffc, /* dst_mask */
1668 FALSE), /* pcrel_offset */
1670 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1671 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1672 to the first entry relative to the TOC base (r2). */
1673 HOWTO (R_PPC64_GOT_TLSGD16,
1675 1, /* size (0 = byte, 1 = short, 2 = long) */
1677 FALSE, /* pc_relative */
1679 complain_overflow_signed, /* complain_on_overflow */
1680 ppc64_elf_unhandled_reloc, /* special_function */
1681 "R_PPC64_GOT_TLSGD16", /* name */
1682 FALSE, /* partial_inplace */
1684 0xffff, /* dst_mask */
1685 FALSE), /* pcrel_offset */
1687 /* Like GOT_TLSGD16, but no overflow. */
1688 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1690 1, /* size (0 = byte, 1 = short, 2 = long) */
1692 FALSE, /* pc_relative */
1694 complain_overflow_dont, /* complain_on_overflow */
1695 ppc64_elf_unhandled_reloc, /* special_function */
1696 "R_PPC64_GOT_TLSGD16_LO", /* name */
1697 FALSE, /* partial_inplace */
1699 0xffff, /* dst_mask */
1700 FALSE), /* pcrel_offset */
1702 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1703 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1704 16, /* rightshift */
1705 1, /* size (0 = byte, 1 = short, 2 = long) */
1707 FALSE, /* pc_relative */
1709 complain_overflow_signed, /* complain_on_overflow */
1710 ppc64_elf_unhandled_reloc, /* special_function */
1711 "R_PPC64_GOT_TLSGD16_HI", /* name */
1712 FALSE, /* partial_inplace */
1714 0xffff, /* dst_mask */
1715 FALSE), /* pcrel_offset */
1717 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1718 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1719 16, /* rightshift */
1720 1, /* size (0 = byte, 1 = short, 2 = long) */
1722 FALSE, /* pc_relative */
1724 complain_overflow_signed, /* complain_on_overflow */
1725 ppc64_elf_unhandled_reloc, /* special_function */
1726 "R_PPC64_GOT_TLSGD16_HA", /* name */
1727 FALSE, /* partial_inplace */
1729 0xffff, /* dst_mask */
1730 FALSE), /* pcrel_offset */
1732 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1733 with values (sym+add)@dtpmod and zero, and computes the offset to the
1734 first entry relative to the TOC base (r2). */
1735 HOWTO (R_PPC64_GOT_TLSLD16,
1737 1, /* size (0 = byte, 1 = short, 2 = long) */
1739 FALSE, /* pc_relative */
1741 complain_overflow_signed, /* complain_on_overflow */
1742 ppc64_elf_unhandled_reloc, /* special_function */
1743 "R_PPC64_GOT_TLSLD16", /* name */
1744 FALSE, /* partial_inplace */
1746 0xffff, /* dst_mask */
1747 FALSE), /* pcrel_offset */
1749 /* Like GOT_TLSLD16, but no overflow. */
1750 HOWTO (R_PPC64_GOT_TLSLD16_LO,
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_TLSLD16_LO", /* name */
1759 FALSE, /* partial_inplace */
1761 0xffff, /* dst_mask */
1762 FALSE), /* pcrel_offset */
1764 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1765 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1766 16, /* rightshift */
1767 1, /* size (0 = byte, 1 = short, 2 = long) */
1769 FALSE, /* pc_relative */
1771 complain_overflow_signed, /* complain_on_overflow */
1772 ppc64_elf_unhandled_reloc, /* special_function */
1773 "R_PPC64_GOT_TLSLD16_HI", /* name */
1774 FALSE, /* partial_inplace */
1776 0xffff, /* dst_mask */
1777 FALSE), /* pcrel_offset */
1779 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1780 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1781 16, /* rightshift */
1782 1, /* size (0 = byte, 1 = short, 2 = long) */
1784 FALSE, /* pc_relative */
1786 complain_overflow_signed, /* complain_on_overflow */
1787 ppc64_elf_unhandled_reloc, /* special_function */
1788 "R_PPC64_GOT_TLSLD16_HA", /* name */
1789 FALSE, /* partial_inplace */
1791 0xffff, /* dst_mask */
1792 FALSE), /* pcrel_offset */
1794 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1795 the offset to the entry relative to the TOC base (r2). */
1796 HOWTO (R_PPC64_GOT_DTPREL16_DS,
1798 1, /* size (0 = byte, 1 = short, 2 = long) */
1800 FALSE, /* pc_relative */
1802 complain_overflow_signed, /* complain_on_overflow */
1803 ppc64_elf_unhandled_reloc, /* special_function */
1804 "R_PPC64_GOT_DTPREL16_DS", /* name */
1805 FALSE, /* partial_inplace */
1807 0xfffc, /* dst_mask */
1808 FALSE), /* pcrel_offset */
1810 /* Like GOT_DTPREL16_DS, but no overflow. */
1811 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
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_DTPREL16_LO_DS", /* name */
1820 FALSE, /* partial_inplace */
1822 0xfffc, /* dst_mask */
1823 FALSE), /* pcrel_offset */
1825 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1826 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1827 16, /* rightshift */
1828 1, /* size (0 = byte, 1 = short, 2 = long) */
1830 FALSE, /* pc_relative */
1832 complain_overflow_signed, /* complain_on_overflow */
1833 ppc64_elf_unhandled_reloc, /* special_function */
1834 "R_PPC64_GOT_DTPREL16_HI", /* name */
1835 FALSE, /* partial_inplace */
1837 0xffff, /* dst_mask */
1838 FALSE), /* pcrel_offset */
1840 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1841 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1842 16, /* rightshift */
1843 1, /* size (0 = byte, 1 = short, 2 = long) */
1845 FALSE, /* pc_relative */
1847 complain_overflow_signed, /* complain_on_overflow */
1848 ppc64_elf_unhandled_reloc, /* special_function */
1849 "R_PPC64_GOT_DTPREL16_HA", /* name */
1850 FALSE, /* partial_inplace */
1852 0xffff, /* dst_mask */
1853 FALSE), /* pcrel_offset */
1855 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1856 offset to the entry relative to the TOC base (r2). */
1857 HOWTO (R_PPC64_GOT_TPREL16_DS,
1859 1, /* size (0 = byte, 1 = short, 2 = long) */
1861 FALSE, /* pc_relative */
1863 complain_overflow_signed, /* complain_on_overflow */
1864 ppc64_elf_unhandled_reloc, /* special_function */
1865 "R_PPC64_GOT_TPREL16_DS", /* name */
1866 FALSE, /* partial_inplace */
1868 0xfffc, /* dst_mask */
1869 FALSE), /* pcrel_offset */
1871 /* Like GOT_TPREL16_DS, but no overflow. */
1872 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1874 1, /* size (0 = byte, 1 = short, 2 = long) */
1876 FALSE, /* pc_relative */
1878 complain_overflow_dont, /* complain_on_overflow */
1879 ppc64_elf_unhandled_reloc, /* special_function */
1880 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1881 FALSE, /* partial_inplace */
1883 0xfffc, /* dst_mask */
1884 FALSE), /* pcrel_offset */
1886 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1887 HOWTO (R_PPC64_GOT_TPREL16_HI,
1888 16, /* rightshift */
1889 1, /* size (0 = byte, 1 = short, 2 = long) */
1891 FALSE, /* pc_relative */
1893 complain_overflow_signed, /* complain_on_overflow */
1894 ppc64_elf_unhandled_reloc, /* special_function */
1895 "R_PPC64_GOT_TPREL16_HI", /* name */
1896 FALSE, /* partial_inplace */
1898 0xffff, /* dst_mask */
1899 FALSE), /* pcrel_offset */
1901 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1902 HOWTO (R_PPC64_GOT_TPREL16_HA,
1903 16, /* rightshift */
1904 1, /* size (0 = byte, 1 = short, 2 = long) */
1906 FALSE, /* pc_relative */
1908 complain_overflow_signed, /* complain_on_overflow */
1909 ppc64_elf_unhandled_reloc, /* special_function */
1910 "R_PPC64_GOT_TPREL16_HA", /* name */
1911 FALSE, /* partial_inplace */
1913 0xffff, /* dst_mask */
1914 FALSE), /* pcrel_offset */
1916 HOWTO (R_PPC64_JMP_IREL, /* type */
1918 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1920 FALSE, /* pc_relative */
1922 complain_overflow_dont, /* complain_on_overflow */
1923 ppc64_elf_unhandled_reloc, /* special_function */
1924 "R_PPC64_JMP_IREL", /* name */
1925 FALSE, /* partial_inplace */
1928 FALSE), /* pcrel_offset */
1930 HOWTO (R_PPC64_IRELATIVE, /* type */
1932 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1934 FALSE, /* pc_relative */
1936 complain_overflow_dont, /* complain_on_overflow */
1937 bfd_elf_generic_reloc, /* special_function */
1938 "R_PPC64_IRELATIVE", /* name */
1939 FALSE, /* partial_inplace */
1941 ONES (64), /* dst_mask */
1942 FALSE), /* pcrel_offset */
1944 /* A 16 bit relative relocation. */
1945 HOWTO (R_PPC64_REL16, /* type */
1947 1, /* size (0 = byte, 1 = short, 2 = long) */
1949 TRUE, /* pc_relative */
1951 complain_overflow_bitfield, /* complain_on_overflow */
1952 bfd_elf_generic_reloc, /* special_function */
1953 "R_PPC64_REL16", /* name */
1954 FALSE, /* partial_inplace */
1956 0xffff, /* dst_mask */
1957 TRUE), /* pcrel_offset */
1959 /* A 16 bit relative relocation without overflow. */
1960 HOWTO (R_PPC64_REL16_LO, /* type */
1962 1, /* size (0 = byte, 1 = short, 2 = long) */
1964 TRUE, /* pc_relative */
1966 complain_overflow_dont,/* complain_on_overflow */
1967 bfd_elf_generic_reloc, /* special_function */
1968 "R_PPC64_REL16_LO", /* name */
1969 FALSE, /* partial_inplace */
1971 0xffff, /* dst_mask */
1972 TRUE), /* pcrel_offset */
1974 /* The high order 16 bits of a relative address. */
1975 HOWTO (R_PPC64_REL16_HI, /* type */
1976 16, /* rightshift */
1977 1, /* size (0 = byte, 1 = short, 2 = long) */
1979 TRUE, /* pc_relative */
1981 complain_overflow_signed, /* complain_on_overflow */
1982 bfd_elf_generic_reloc, /* special_function */
1983 "R_PPC64_REL16_HI", /* name */
1984 FALSE, /* partial_inplace */
1986 0xffff, /* dst_mask */
1987 TRUE), /* pcrel_offset */
1989 /* The high order 16 bits of a relative address, plus 1 if the contents of
1990 the low 16 bits, treated as a signed number, is negative. */
1991 HOWTO (R_PPC64_REL16_HA, /* type */
1992 16, /* rightshift */
1993 1, /* size (0 = byte, 1 = short, 2 = long) */
1995 TRUE, /* pc_relative */
1997 complain_overflow_signed, /* complain_on_overflow */
1998 ppc64_elf_ha_reloc, /* special_function */
1999 "R_PPC64_REL16_HA", /* name */
2000 FALSE, /* partial_inplace */
2002 0xffff, /* dst_mask */
2003 TRUE), /* pcrel_offset */
2005 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2006 HOWTO (R_PPC64_ADDR16_HIGH, /* type */
2007 16, /* rightshift */
2008 1, /* size (0 = byte, 1 = short, 2 = long) */
2010 FALSE, /* pc_relative */
2012 complain_overflow_dont, /* complain_on_overflow */
2013 bfd_elf_generic_reloc, /* special_function */
2014 "R_PPC64_ADDR16_HIGH", /* name */
2015 FALSE, /* partial_inplace */
2017 0xffff, /* dst_mask */
2018 FALSE), /* pcrel_offset */
2020 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2021 HOWTO (R_PPC64_ADDR16_HIGHA, /* type */
2022 16, /* rightshift */
2023 1, /* size (0 = byte, 1 = short, 2 = long) */
2025 FALSE, /* pc_relative */
2027 complain_overflow_dont, /* complain_on_overflow */
2028 ppc64_elf_ha_reloc, /* special_function */
2029 "R_PPC64_ADDR16_HIGHA", /* name */
2030 FALSE, /* partial_inplace */
2032 0xffff, /* dst_mask */
2033 FALSE), /* pcrel_offset */
2035 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2036 HOWTO (R_PPC64_DTPREL16_HIGH,
2037 16, /* rightshift */
2038 1, /* size (0 = byte, 1 = short, 2 = long) */
2040 FALSE, /* pc_relative */
2042 complain_overflow_dont, /* complain_on_overflow */
2043 ppc64_elf_unhandled_reloc, /* special_function */
2044 "R_PPC64_DTPREL16_HIGH", /* name */
2045 FALSE, /* partial_inplace */
2047 0xffff, /* dst_mask */
2048 FALSE), /* pcrel_offset */
2050 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2051 HOWTO (R_PPC64_DTPREL16_HIGHA,
2052 16, /* rightshift */
2053 1, /* size (0 = byte, 1 = short, 2 = long) */
2055 FALSE, /* pc_relative */
2057 complain_overflow_dont, /* complain_on_overflow */
2058 ppc64_elf_unhandled_reloc, /* special_function */
2059 "R_PPC64_DTPREL16_HIGHA", /* name */
2060 FALSE, /* partial_inplace */
2062 0xffff, /* dst_mask */
2063 FALSE), /* pcrel_offset */
2065 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2066 HOWTO (R_PPC64_TPREL16_HIGH,
2067 16, /* rightshift */
2068 1, /* size (0 = byte, 1 = short, 2 = long) */
2070 FALSE, /* pc_relative */
2072 complain_overflow_dont, /* complain_on_overflow */
2073 ppc64_elf_unhandled_reloc, /* special_function */
2074 "R_PPC64_TPREL16_HIGH", /* name */
2075 FALSE, /* partial_inplace */
2077 0xffff, /* dst_mask */
2078 FALSE), /* pcrel_offset */
2080 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2081 HOWTO (R_PPC64_TPREL16_HIGHA,
2082 16, /* rightshift */
2083 1, /* size (0 = byte, 1 = short, 2 = long) */
2085 FALSE, /* pc_relative */
2087 complain_overflow_dont, /* complain_on_overflow */
2088 ppc64_elf_unhandled_reloc, /* special_function */
2089 "R_PPC64_TPREL16_HIGHA", /* name */
2090 FALSE, /* partial_inplace */
2092 0xffff, /* dst_mask */
2093 FALSE), /* pcrel_offset */
2095 /* GNU extension to record C++ vtable hierarchy. */
2096 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
2098 0, /* size (0 = byte, 1 = short, 2 = long) */
2100 FALSE, /* pc_relative */
2102 complain_overflow_dont, /* complain_on_overflow */
2103 NULL, /* special_function */
2104 "R_PPC64_GNU_VTINHERIT", /* name */
2105 FALSE, /* partial_inplace */
2108 FALSE), /* pcrel_offset */
2110 /* GNU extension to record C++ vtable member usage. */
2111 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
2113 0, /* size (0 = byte, 1 = short, 2 = long) */
2115 FALSE, /* pc_relative */
2117 complain_overflow_dont, /* complain_on_overflow */
2118 NULL, /* special_function */
2119 "R_PPC64_GNU_VTENTRY", /* name */
2120 FALSE, /* partial_inplace */
2123 FALSE), /* pcrel_offset */
2127 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2131 ppc_howto_init (void)
2133 unsigned int i, type;
2136 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
2139 type = ppc64_elf_howto_raw[i].type;
2140 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
2141 / sizeof (ppc64_elf_howto_table[0])));
2142 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
2146 static reloc_howto_type *
2147 ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2148 bfd_reloc_code_real_type code)
2150 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
2152 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2153 /* Initialize howto table if needed. */
2161 case BFD_RELOC_NONE: r = R_PPC64_NONE;
2163 case BFD_RELOC_32: r = R_PPC64_ADDR32;
2165 case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
2167 case BFD_RELOC_16: r = R_PPC64_ADDR16;
2169 case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
2171 case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
2173 case BFD_RELOC_PPC64_ADDR16_HIGH: r = R_PPC64_ADDR16_HIGH;
2175 case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
2177 case BFD_RELOC_PPC64_ADDR16_HIGHA: r = R_PPC64_ADDR16_HIGHA;
2179 case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
2181 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
2183 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
2185 case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
2187 case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
2189 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
2191 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
2193 case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
2195 case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
2197 case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
2199 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
2201 case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
2203 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
2205 case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
2207 case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
2209 case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
2211 case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
2213 case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
2215 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
2217 case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
2219 case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
2221 case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
2223 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
2225 case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
2227 case BFD_RELOC_64: r = R_PPC64_ADDR64;
2229 case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
2231 case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
2233 case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
2235 case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
2237 case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
2239 case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
2241 case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
2243 case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
2245 case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
2247 case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
2249 case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
2251 case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
2253 case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
2255 case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
2257 case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
2259 case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
2261 case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
2263 case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
2265 case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
2267 case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
2269 case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
2271 case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
2273 case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
2275 case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
2277 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
2279 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
2281 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
2283 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
2285 case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD;
2287 case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD;
2289 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
2291 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
2293 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
2295 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
2297 case BFD_RELOC_PPC64_TPREL16_HIGH: r = R_PPC64_TPREL16_HIGH;
2299 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
2301 case BFD_RELOC_PPC64_TPREL16_HIGHA: r = R_PPC64_TPREL16_HIGHA;
2303 case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
2305 case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
2307 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
2309 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
2311 case BFD_RELOC_PPC64_DTPREL16_HIGH: r = R_PPC64_DTPREL16_HIGH;
2313 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
2315 case BFD_RELOC_PPC64_DTPREL16_HIGHA: r = R_PPC64_DTPREL16_HIGHA;
2317 case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
2319 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
2321 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
2323 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
2325 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
2327 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
2329 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
2331 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
2333 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
2335 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
2337 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
2339 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
2341 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
2343 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
2345 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
2347 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
2349 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
2351 case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
2353 case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
2355 case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
2357 case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
2359 case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
2361 case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
2363 case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
2365 case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
2367 case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
2369 case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
2371 case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
2373 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
2375 case BFD_RELOC_16_PCREL: r = R_PPC64_REL16;
2377 case BFD_RELOC_LO16_PCREL: r = R_PPC64_REL16_LO;
2379 case BFD_RELOC_HI16_PCREL: r = R_PPC64_REL16_HI;
2381 case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA;
2383 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
2385 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
2389 return ppc64_elf_howto_table[r];
2392 static reloc_howto_type *
2393 ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2399 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
2401 if (ppc64_elf_howto_raw[i].name != NULL
2402 && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0)
2403 return &ppc64_elf_howto_raw[i];
2408 /* Set the howto pointer for a PowerPC ELF reloc. */
2411 ppc64_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
2412 Elf_Internal_Rela *dst)
2416 /* Initialize howto table if needed. */
2417 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2420 type = ELF64_R_TYPE (dst->r_info);
2421 if (type >= (sizeof (ppc64_elf_howto_table)
2422 / sizeof (ppc64_elf_howto_table[0])))
2424 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
2426 type = R_PPC64_NONE;
2428 cache_ptr->howto = ppc64_elf_howto_table[type];
2431 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2433 static bfd_reloc_status_type
2434 ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2435 void *data, asection *input_section,
2436 bfd *output_bfd, char **error_message)
2438 /* If this is a relocatable link (output_bfd test tells us), just
2439 call the generic function. Any adjustment will be done at final
2441 if (output_bfd != NULL)
2442 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2443 input_section, output_bfd, error_message);
2445 /* Adjust the addend for sign extension of the low 16 bits.
2446 We won't actually be using the low 16 bits, so trashing them
2448 reloc_entry->addend += 0x8000;
2449 return bfd_reloc_continue;
2452 static bfd_reloc_status_type
2453 ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2454 void *data, asection *input_section,
2455 bfd *output_bfd, char **error_message)
2457 if (output_bfd != NULL)
2458 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2459 input_section, output_bfd, error_message);
2461 if (strcmp (symbol->section->name, ".opd") == 0
2462 && (symbol->section->owner->flags & DYNAMIC) == 0)
2464 bfd_vma dest = opd_entry_value (symbol->section,
2465 symbol->value + reloc_entry->addend,
2467 if (dest != (bfd_vma) -1)
2468 reloc_entry->addend = dest - (symbol->value
2469 + symbol->section->output_section->vma
2470 + symbol->section->output_offset);
2472 return bfd_reloc_continue;
2475 static bfd_reloc_status_type
2476 ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2477 void *data, asection *input_section,
2478 bfd *output_bfd, char **error_message)
2481 enum elf_ppc64_reloc_type r_type;
2482 bfd_size_type octets;
2483 /* Assume 'at' branch hints. */
2484 bfd_boolean is_isa_v2 = TRUE;
2486 /* If this is a relocatable link (output_bfd test tells us), just
2487 call the generic function. Any adjustment will be done at final
2489 if (output_bfd != NULL)
2490 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2491 input_section, output_bfd, error_message);
2493 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2494 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2495 insn &= ~(0x01 << 21);
2496 r_type = reloc_entry->howto->type;
2497 if (r_type == R_PPC64_ADDR14_BRTAKEN
2498 || r_type == R_PPC64_REL14_BRTAKEN)
2499 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2503 /* Set 'a' bit. This is 0b00010 in BO field for branch
2504 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2505 for branch on CTR insns (BO == 1a00t or 1a01t). */
2506 if ((insn & (0x14 << 21)) == (0x04 << 21))
2508 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2518 if (!bfd_is_com_section (symbol->section))
2519 target = symbol->value;
2520 target += symbol->section->output_section->vma;
2521 target += symbol->section->output_offset;
2522 target += reloc_entry->addend;
2524 from = (reloc_entry->address
2525 + input_section->output_offset
2526 + input_section->output_section->vma);
2528 /* Invert 'y' bit if not the default. */
2529 if ((bfd_signed_vma) (target - from) < 0)
2532 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2534 return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data,
2535 input_section, output_bfd, error_message);
2538 static bfd_reloc_status_type
2539 ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2540 void *data, asection *input_section,
2541 bfd *output_bfd, char **error_message)
2543 /* If this is a relocatable link (output_bfd test tells us), just
2544 call the generic function. Any adjustment will be done at final
2546 if (output_bfd != NULL)
2547 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2548 input_section, output_bfd, error_message);
2550 /* Subtract the symbol section base address. */
2551 reloc_entry->addend -= symbol->section->output_section->vma;
2552 return bfd_reloc_continue;
2555 static bfd_reloc_status_type
2556 ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2557 void *data, asection *input_section,
2558 bfd *output_bfd, char **error_message)
2560 /* If this is a relocatable link (output_bfd test tells us), just
2561 call the generic function. Any adjustment will be done at final
2563 if (output_bfd != NULL)
2564 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2565 input_section, output_bfd, error_message);
2567 /* Subtract the symbol section base address. */
2568 reloc_entry->addend -= symbol->section->output_section->vma;
2570 /* Adjust the addend for sign extension of the low 16 bits. */
2571 reloc_entry->addend += 0x8000;
2572 return bfd_reloc_continue;
2575 static bfd_reloc_status_type
2576 ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2577 void *data, asection *input_section,
2578 bfd *output_bfd, char **error_message)
2582 /* If this is a relocatable link (output_bfd test tells us), just
2583 call the generic function. Any adjustment will be done at final
2585 if (output_bfd != NULL)
2586 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2587 input_section, output_bfd, error_message);
2589 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2591 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2593 /* Subtract the TOC base address. */
2594 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2595 return bfd_reloc_continue;
2598 static bfd_reloc_status_type
2599 ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2600 void *data, asection *input_section,
2601 bfd *output_bfd, char **error_message)
2605 /* If this is a relocatable link (output_bfd test tells us), just
2606 call the generic function. Any adjustment will be done at final
2608 if (output_bfd != NULL)
2609 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2610 input_section, output_bfd, error_message);
2612 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2614 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2616 /* Subtract the TOC base address. */
2617 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2619 /* Adjust the addend for sign extension of the low 16 bits. */
2620 reloc_entry->addend += 0x8000;
2621 return bfd_reloc_continue;
2624 static bfd_reloc_status_type
2625 ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2626 void *data, asection *input_section,
2627 bfd *output_bfd, char **error_message)
2630 bfd_size_type octets;
2632 /* If this is a relocatable link (output_bfd test tells us), just
2633 call the generic function. Any adjustment will be done at final
2635 if (output_bfd != NULL)
2636 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2637 input_section, output_bfd, error_message);
2639 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2641 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2643 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2644 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2645 return bfd_reloc_ok;
2648 static bfd_reloc_status_type
2649 ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2650 void *data, asection *input_section,
2651 bfd *output_bfd, char **error_message)
2653 /* If this is a relocatable link (output_bfd test tells us), just
2654 call the generic function. Any adjustment will be done at final
2656 if (output_bfd != NULL)
2657 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2658 input_section, output_bfd, error_message);
2660 if (error_message != NULL)
2662 static char buf[60];
2663 sprintf (buf, "generic linker can't handle %s",
2664 reloc_entry->howto->name);
2665 *error_message = buf;
2667 return bfd_reloc_dangerous;
2670 /* Track GOT entries needed for a given symbol. We might need more
2671 than one got entry per symbol. */
2674 struct got_entry *next;
2676 /* The symbol addend that we'll be placing in the GOT. */
2679 /* Unlike other ELF targets, we use separate GOT entries for the same
2680 symbol referenced from different input files. This is to support
2681 automatic multiple TOC/GOT sections, where the TOC base can vary
2682 from one input file to another. After partitioning into TOC groups
2683 we merge entries within the group.
2685 Point to the BFD owning this GOT entry. */
2688 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2689 TLS_TPREL or TLS_DTPREL for tls entries. */
2690 unsigned char tls_type;
2692 /* Non-zero if got.ent points to real entry. */
2693 unsigned char is_indirect;
2695 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2698 bfd_signed_vma refcount;
2700 struct got_entry *ent;
2704 /* The same for PLT. */
2707 struct plt_entry *next;
2713 bfd_signed_vma refcount;
2718 struct ppc64_elf_obj_tdata
2720 struct elf_obj_tdata elf;
2722 /* Shortcuts to dynamic linker sections. */
2726 /* Used during garbage collection. We attach global symbols defined
2727 on removed .opd entries to this section so that the sym is removed. */
2728 asection *deleted_section;
2730 /* TLS local dynamic got entry handling. Support for multiple GOT
2731 sections means we potentially need one of these for each input bfd. */
2732 struct got_entry tlsld_got;
2735 /* A copy of relocs before they are modified for --emit-relocs. */
2736 Elf_Internal_Rela *relocs;
2738 /* Section contents. */
2742 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2743 the reloc to be in the range -32768 to 32767. */
2744 unsigned int has_small_toc_reloc : 1;
2746 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2747 instruction not one we handle. */
2748 unsigned int unexpected_toc_insn : 1;
2751 #define ppc64_elf_tdata(bfd) \
2752 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2754 #define ppc64_tlsld_got(bfd) \
2755 (&ppc64_elf_tdata (bfd)->tlsld_got)
2757 #define is_ppc64_elf(bfd) \
2758 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2759 && elf_object_id (bfd) == PPC64_ELF_DATA)
2761 /* Override the generic function because we store some extras. */
2764 ppc64_elf_mkobject (bfd *abfd)
2766 return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata),
2770 /* Fix bad default arch selected for a 64 bit input bfd when the
2771 default is 32 bit. */
2774 ppc64_elf_object_p (bfd *abfd)
2776 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
2778 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2780 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2782 /* Relies on arch after 32 bit default being 64 bit default. */
2783 abfd->arch_info = abfd->arch_info->next;
2784 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2790 /* Support for core dump NOTE sections. */
2793 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2795 size_t offset, size;
2797 if (note->descsz != 504)
2801 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2804 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
2810 /* Make a ".reg/999" section. */
2811 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2812 size, note->descpos + offset);
2816 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2818 if (note->descsz != 136)
2821 elf_tdata (abfd)->core->pid
2822 = bfd_get_32 (abfd, note->descdata + 24);
2823 elf_tdata (abfd)->core->program
2824 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2825 elf_tdata (abfd)->core->command
2826 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2832 ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
2845 va_start (ap, note_type);
2846 memset (data, 0, sizeof (data));
2847 strncpy (data + 40, va_arg (ap, const char *), 16);
2848 strncpy (data + 56, va_arg (ap, const char *), 80);
2850 return elfcore_write_note (abfd, buf, bufsiz,
2851 "CORE", note_type, data, sizeof (data));
2862 va_start (ap, note_type);
2863 memset (data, 0, 112);
2864 pid = va_arg (ap, long);
2865 bfd_put_32 (abfd, pid, data + 32);
2866 cursig = va_arg (ap, int);
2867 bfd_put_16 (abfd, cursig, data + 12);
2868 greg = va_arg (ap, const void *);
2869 memcpy (data + 112, greg, 384);
2870 memset (data + 496, 0, 8);
2872 return elfcore_write_note (abfd, buf, bufsiz,
2873 "CORE", note_type, data, sizeof (data));
2878 /* Add extra PPC sections. */
2880 static const struct bfd_elf_special_section ppc64_elf_special_sections[]=
2882 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 },
2883 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2884 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2885 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2886 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2887 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2888 { NULL, 0, 0, 0, 0 }
2891 enum _ppc64_sec_type {
2897 struct _ppc64_elf_section_data
2899 struct bfd_elf_section_data elf;
2903 /* An array with one entry for each opd function descriptor. */
2904 struct _opd_sec_data
2906 /* Points to the function code section for local opd entries. */
2907 asection **func_sec;
2909 /* After editing .opd, adjust references to opd local syms. */
2913 /* An array for toc sections, indexed by offset/8. */
2914 struct _toc_sec_data
2916 /* Specifies the relocation symbol index used at a given toc offset. */
2919 /* And the relocation addend. */
2924 enum _ppc64_sec_type sec_type:2;
2926 /* Flag set when small branches are detected. Used to
2927 select suitable defaults for the stub group size. */
2928 unsigned int has_14bit_branch:1;
2931 #define ppc64_elf_section_data(sec) \
2932 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2935 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
2937 if (!sec->used_by_bfd)
2939 struct _ppc64_elf_section_data *sdata;
2940 bfd_size_type amt = sizeof (*sdata);
2942 sdata = bfd_zalloc (abfd, amt);
2945 sec->used_by_bfd = sdata;
2948 return _bfd_elf_new_section_hook (abfd, sec);
2951 static struct _opd_sec_data *
2952 get_opd_info (asection * sec)
2955 && ppc64_elf_section_data (sec) != NULL
2956 && ppc64_elf_section_data (sec)->sec_type == sec_opd)
2957 return &ppc64_elf_section_data (sec)->u.opd;
2962 abiversion (bfd *abfd)
2964 return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
2968 set_abiversion (bfd *abfd, int ver)
2970 elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
2971 elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
2974 /* Parameters for the qsort hook. */
2975 static bfd_boolean synthetic_relocatable;
2977 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2980 compare_symbols (const void *ap, const void *bp)
2982 const asymbol *a = * (const asymbol **) ap;
2983 const asymbol *b = * (const asymbol **) bp;
2985 /* Section symbols first. */
2986 if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM))
2988 if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM))
2991 /* then .opd symbols. */
2992 if (strcmp (a->section->name, ".opd") == 0
2993 && strcmp (b->section->name, ".opd") != 0)
2995 if (strcmp (a->section->name, ".opd") != 0
2996 && strcmp (b->section->name, ".opd") == 0)
2999 /* then other code symbols. */
3000 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3001 == (SEC_CODE | SEC_ALLOC)
3002 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3003 != (SEC_CODE | SEC_ALLOC))
3006 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3007 != (SEC_CODE | SEC_ALLOC)
3008 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3009 == (SEC_CODE | SEC_ALLOC))
3012 if (synthetic_relocatable)
3014 if (a->section->id < b->section->id)
3017 if (a->section->id > b->section->id)
3021 if (a->value + a->section->vma < b->value + b->section->vma)
3024 if (a->value + a->section->vma > b->value + b->section->vma)
3027 /* For syms with the same value, prefer strong dynamic global function
3028 syms over other syms. */
3029 if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
3032 if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
3035 if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
3038 if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
3041 if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
3044 if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
3047 if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
3050 if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
3056 /* Search SYMS for a symbol of the given VALUE. */
3059 sym_exists_at (asymbol **syms, long lo, long hi, int id, bfd_vma value)
3067 mid = (lo + hi) >> 1;
3068 if (syms[mid]->value + syms[mid]->section->vma < value)
3070 else if (syms[mid]->value + syms[mid]->section->vma > value)
3080 mid = (lo + hi) >> 1;
3081 if (syms[mid]->section->id < id)
3083 else if (syms[mid]->section->id > id)
3085 else if (syms[mid]->value < value)
3087 else if (syms[mid]->value > value)
3097 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
3099 bfd_vma vma = *(bfd_vma *) ptr;
3100 return ((section->flags & SEC_ALLOC) != 0
3101 && section->vma <= vma
3102 && vma < section->vma + section->size);
3105 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3106 entry syms. Also generate @plt symbols for the glink branch table. */
3109 ppc64_elf_get_synthetic_symtab (bfd *abfd,
3110 long static_count, asymbol **static_syms,
3111 long dyn_count, asymbol **dyn_syms,
3118 long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
3119 asection *opd = NULL;
3120 bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
3122 int abi = abiversion (abfd);
3128 opd = bfd_get_section_by_name (abfd, ".opd");
3129 if (opd == NULL && abi == 1)
3133 symcount = static_count;
3135 symcount += dyn_count;
3139 syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
3143 if (!relocatable && static_count != 0 && dyn_count != 0)
3145 /* Use both symbol tables. */
3146 memcpy (syms, static_syms, static_count * sizeof (*syms));
3147 memcpy (syms + static_count, dyn_syms, (dyn_count + 1) * sizeof (*syms));
3149 else if (!relocatable && static_count == 0)
3150 memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
3152 memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
3154 synthetic_relocatable = relocatable;
3155 qsort (syms, symcount, sizeof (*syms), compare_symbols);
3157 if (!relocatable && symcount > 1)
3160 /* Trim duplicate syms, since we may have merged the normal and
3161 dynamic symbols. Actually, we only care about syms that have
3162 different values, so trim any with the same value. */
3163 for (i = 1, j = 1; i < symcount; ++i)
3164 if (syms[i - 1]->value + syms[i - 1]->section->vma
3165 != syms[i]->value + syms[i]->section->vma)
3166 syms[j++] = syms[i];
3171 if (strcmp (syms[i]->section->name, ".opd") == 0)
3175 for (; i < symcount; ++i)
3176 if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3177 != (SEC_CODE | SEC_ALLOC))
3178 || (syms[i]->flags & BSF_SECTION_SYM) == 0)
3182 for (; i < symcount; ++i)
3183 if ((syms[i]->flags & BSF_SECTION_SYM) == 0)
3187 for (; i < symcount; ++i)
3188 if (strcmp (syms[i]->section->name, ".opd") != 0)
3192 for (; i < symcount; ++i)
3193 if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3194 != (SEC_CODE | SEC_ALLOC))
3202 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3207 if (opdsymend == secsymend)
3210 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3211 relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0;
3215 if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
3222 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3226 while (r < opd->relocation + relcount
3227 && r->address < syms[i]->value + opd->vma)
3230 if (r == opd->relocation + relcount)
3233 if (r->address != syms[i]->value + opd->vma)
3236 if (r->howto->type != R_PPC64_ADDR64)
3239 sym = *r->sym_ptr_ptr;
3240 if (!sym_exists_at (syms, opdsymend, symcount,
3241 sym->section->id, sym->value + r->addend))
3244 size += sizeof (asymbol);
3245 size += strlen (syms[i]->name) + 2;
3249 s = *ret = bfd_malloc (size);
3256 names = (char *) (s + count);
3258 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3262 while (r < opd->relocation + relcount
3263 && r->address < syms[i]->value + opd->vma)
3266 if (r == opd->relocation + relcount)
3269 if (r->address != syms[i]->value + opd->vma)
3272 if (r->howto->type != R_PPC64_ADDR64)
3275 sym = *r->sym_ptr_ptr;
3276 if (!sym_exists_at (syms, opdsymend, symcount,
3277 sym->section->id, sym->value + r->addend))
3282 s->flags |= BSF_SYNTHETIC;
3283 s->section = sym->section;
3284 s->value = sym->value + r->addend;
3287 len = strlen (syms[i]->name);
3288 memcpy (names, syms[i]->name, len + 1);
3290 /* Have udata.p point back to the original symbol this
3291 synthetic symbol was derived from. */
3292 s->udata.p = syms[i];
3299 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3300 bfd_byte *contents = NULL;
3303 bfd_vma glink_vma = 0, resolv_vma = 0;
3304 asection *dynamic, *glink = NULL, *relplt = NULL;
3307 if (opd != NULL && !bfd_malloc_and_get_section (abfd, opd, &contents))
3309 free_contents_and_exit:
3317 for (i = secsymend; i < opdsymend; ++i)
3321 /* Ignore bogus symbols. */
3322 if (syms[i]->value > opd->size - 8)
3325 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3326 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3329 size += sizeof (asymbol);
3330 size += strlen (syms[i]->name) + 2;
3334 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3336 && (dynamic = bfd_get_section_by_name (abfd, ".dynamic")) != NULL)
3338 bfd_byte *dynbuf, *extdyn, *extdynend;
3340 void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
3342 if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
3343 goto free_contents_and_exit;
3345 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
3346 swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
3349 extdynend = extdyn + dynamic->size;
3350 for (; extdyn < extdynend; extdyn += extdynsize)
3352 Elf_Internal_Dyn dyn;
3353 (*swap_dyn_in) (abfd, extdyn, &dyn);
3355 if (dyn.d_tag == DT_NULL)
3358 if (dyn.d_tag == DT_PPC64_GLINK)
3360 /* The first glink stub starts at offset 32; see
3361 comment in ppc64_elf_finish_dynamic_sections. */
3362 glink_vma = dyn.d_un.d_val + GLINK_CALL_STUB_SIZE - 8 * 4;
3363 /* The .glink section usually does not survive the final
3364 link; search for the section (usually .text) where the
3365 glink stubs now reside. */
3366 glink = bfd_sections_find_if (abfd, section_covers_vma,
3377 /* Determine __glink trampoline by reading the relative branch
3378 from the first glink stub. */
3380 unsigned int off = 0;
3382 while (bfd_get_section_contents (abfd, glink, buf,
3383 glink_vma + off - glink->vma, 4))
3385 unsigned int insn = bfd_get_32 (abfd, buf);
3387 if ((insn & ~0x3fffffc) == 0)
3389 resolv_vma = glink_vma + off + (insn ^ 0x2000000) - 0x2000000;
3398 size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
3400 relplt = bfd_get_section_by_name (abfd, ".rela.plt");
3403 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3404 if (! (*slurp_relocs) (abfd, relplt, dyn_syms, TRUE))
3405 goto free_contents_and_exit;
3407 plt_count = relplt->size / sizeof (Elf64_External_Rela);
3408 size += plt_count * sizeof (asymbol);
3410 p = relplt->relocation;
3411 for (i = 0; i < plt_count; i++, p++)
3413 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
3415 size += sizeof ("+0x") - 1 + 16;
3420 s = *ret = bfd_malloc (size);
3422 goto free_contents_and_exit;
3424 names = (char *) (s + count + plt_count + (resolv_vma != 0));
3426 for (i = secsymend; i < opdsymend; ++i)
3430 if (syms[i]->value > opd->size - 8)
3433 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3434 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3438 asection *sec = abfd->sections;
3445 long mid = (lo + hi) >> 1;
3446 if (syms[mid]->section->vma < ent)
3448 else if (syms[mid]->section->vma > ent)
3452 sec = syms[mid]->section;
3457 if (lo >= hi && lo > codesecsym)
3458 sec = syms[lo - 1]->section;
3460 for (; sec != NULL; sec = sec->next)
3464 /* SEC_LOAD may not be set if SEC is from a separate debug
3466 if ((sec->flags & SEC_ALLOC) == 0)
3468 if ((sec->flags & SEC_CODE) != 0)
3471 s->flags |= BSF_SYNTHETIC;
3472 s->value = ent - s->section->vma;
3475 len = strlen (syms[i]->name);
3476 memcpy (names, syms[i]->name, len + 1);
3478 /* Have udata.p point back to the original symbol this
3479 synthetic symbol was derived from. */
3480 s->udata.p = syms[i];
3486 if (glink != NULL && relplt != NULL)
3490 /* Add a symbol for the main glink trampoline. */
3491 memset (s, 0, sizeof *s);
3493 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
3495 s->value = resolv_vma - glink->vma;
3497 memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3498 names += sizeof ("__glink_PLTresolve");
3503 /* FIXME: It would be very much nicer to put sym@plt on the
3504 stub rather than on the glink branch table entry. The
3505 objdump disassembler would then use a sensible symbol
3506 name on plt calls. The difficulty in doing so is
3507 a) finding the stubs, and,
3508 b) matching stubs against plt entries, and,
3509 c) there can be multiple stubs for a given plt entry.
3511 Solving (a) could be done by code scanning, but older
3512 ppc64 binaries used different stubs to current code.
3513 (b) is the tricky one since you need to known the toc
3514 pointer for at least one function that uses a pic stub to
3515 be able to calculate the plt address referenced.
3516 (c) means gdb would need to set multiple breakpoints (or
3517 find the glink branch itself) when setting breakpoints
3518 for pending shared library loads. */
3519 p = relplt->relocation;
3520 for (i = 0; i < plt_count; i++, p++)
3524 *s = **p->sym_ptr_ptr;
3525 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3526 we are defining a symbol, ensure one of them is set. */
3527 if ((s->flags & BSF_LOCAL) == 0)
3528 s->flags |= BSF_GLOBAL;
3529 s->flags |= BSF_SYNTHETIC;
3531 s->value = glink_vma - glink->vma;
3534 len = strlen ((*p->sym_ptr_ptr)->name);
3535 memcpy (names, (*p->sym_ptr_ptr)->name, len);
3539 memcpy (names, "+0x", sizeof ("+0x") - 1);
3540 names += sizeof ("+0x") - 1;
3541 bfd_sprintf_vma (abfd, names, p->addend);
3542 names += strlen (names);
3544 memcpy (names, "@plt", sizeof ("@plt"));
3545 names += sizeof ("@plt");
3565 /* The following functions are specific to the ELF linker, while
3566 functions above are used generally. Those named ppc64_elf_* are
3567 called by the main ELF linker code. They appear in this file more
3568 or less in the order in which they are called. eg.
3569 ppc64_elf_check_relocs is called early in the link process,
3570 ppc64_elf_finish_dynamic_sections is one of the last functions
3573 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3574 functions have both a function code symbol and a function descriptor
3575 symbol. A call to foo in a relocatable object file looks like:
3582 The function definition in another object file might be:
3586 . .quad .TOC.@tocbase
3592 When the linker resolves the call during a static link, the branch
3593 unsurprisingly just goes to .foo and the .opd information is unused.
3594 If the function definition is in a shared library, things are a little
3595 different: The call goes via a plt call stub, the opd information gets
3596 copied to the plt, and the linker patches the nop.
3604 . std 2,40(1) # in practice, the call stub
3605 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3606 . addi 11,11,Lfoo@toc@l # this is the general idea
3614 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3616 The "reloc ()" notation is supposed to indicate that the linker emits
3617 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3620 What are the difficulties here? Well, firstly, the relocations
3621 examined by the linker in check_relocs are against the function code
3622 sym .foo, while the dynamic relocation in the plt is emitted against
3623 the function descriptor symbol, foo. Somewhere along the line, we need
3624 to carefully copy dynamic link information from one symbol to the other.
3625 Secondly, the generic part of the elf linker will make .foo a dynamic
3626 symbol as is normal for most other backends. We need foo dynamic
3627 instead, at least for an application final link. However, when
3628 creating a shared library containing foo, we need to have both symbols
3629 dynamic so that references to .foo are satisfied during the early
3630 stages of linking. Otherwise the linker might decide to pull in a
3631 definition from some other object, eg. a static library.
3633 Update: As of August 2004, we support a new convention. Function
3634 calls may use the function descriptor symbol, ie. "bl foo". This
3635 behaves exactly as "bl .foo". */
3637 /* Of those relocs that might be copied as dynamic relocs, this function
3638 selects those that must be copied when linking a shared library,
3639 even when the symbol is local. */
3642 must_be_dyn_reloc (struct bfd_link_info *info,
3643 enum elf_ppc64_reloc_type r_type)
3655 case R_PPC64_TPREL16:
3656 case R_PPC64_TPREL16_LO:
3657 case R_PPC64_TPREL16_HI:
3658 case R_PPC64_TPREL16_HA:
3659 case R_PPC64_TPREL16_DS:
3660 case R_PPC64_TPREL16_LO_DS:
3661 case R_PPC64_TPREL16_HIGH:
3662 case R_PPC64_TPREL16_HIGHA:
3663 case R_PPC64_TPREL16_HIGHER:
3664 case R_PPC64_TPREL16_HIGHERA:
3665 case R_PPC64_TPREL16_HIGHEST:
3666 case R_PPC64_TPREL16_HIGHESTA:
3667 case R_PPC64_TPREL64:
3668 return !info->executable;
3672 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3673 copying dynamic variables from a shared lib into an app's dynbss
3674 section, and instead use a dynamic relocation to point into the
3675 shared lib. With code that gcc generates, it's vital that this be
3676 enabled; In the PowerPC64 ABI, the address of a function is actually
3677 the address of a function descriptor, which resides in the .opd
3678 section. gcc uses the descriptor directly rather than going via the
3679 GOT as some other ABI's do, which means that initialized function
3680 pointers must reference the descriptor. Thus, a function pointer
3681 initialized to the address of a function in a shared library will
3682 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3683 redefines the function descriptor symbol to point to the copy. This
3684 presents a problem as a plt entry for that function is also
3685 initialized from the function descriptor symbol and the copy reloc
3686 may not be initialized first. */
3687 #define ELIMINATE_COPY_RELOCS 1
3689 /* Section name for stubs is the associated section name plus this
3691 #define STUB_SUFFIX ".stub"
3694 ppc_stub_long_branch:
3695 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3696 destination, but a 24 bit branch in a stub section will reach.
3699 ppc_stub_plt_branch:
3700 Similar to the above, but a 24 bit branch in the stub section won't
3701 reach its destination.
3702 . addis %r11,%r2,xxx@toc@ha
3703 . ld %r12,xxx@toc@l(%r11)
3708 Used to call a function in a shared library. If it so happens that
3709 the plt entry referenced crosses a 64k boundary, then an extra
3710 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3712 . addis %r11,%r2,xxx@toc@ha
3713 . ld %r12,xxx+0@toc@l(%r11)
3715 . ld %r2,xxx+8@toc@l(%r11)
3716 . ld %r11,xxx+16@toc@l(%r11)
3719 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3720 code to adjust the value and save r2 to support multiple toc sections.
3721 A ppc_stub_long_branch with an r2 offset looks like:
3723 . addis %r2,%r2,off@ha
3724 . addi %r2,%r2,off@l
3727 A ppc_stub_plt_branch with an r2 offset looks like:
3729 . addis %r11,%r2,xxx@toc@ha
3730 . ld %r12,xxx@toc@l(%r11)
3731 . addis %r2,%r2,off@ha
3732 . addi %r2,%r2,off@l
3736 In cases where the "addis" instruction would add zero, the "addis" is
3737 omitted and following instructions modified slightly in some cases.
3740 enum ppc_stub_type {
3742 ppc_stub_long_branch,
3743 ppc_stub_long_branch_r2off,
3744 ppc_stub_plt_branch,
3745 ppc_stub_plt_branch_r2off,
3747 ppc_stub_plt_call_r2save
3750 struct ppc_stub_hash_entry {
3752 /* Base hash table entry structure. */
3753 struct bfd_hash_entry root;
3755 enum ppc_stub_type stub_type;
3757 /* The stub section. */
3760 /* Offset within stub_sec of the beginning of this stub. */
3761 bfd_vma stub_offset;
3763 /* Given the symbol's value and its section we can determine its final
3764 value when building the stubs (so the stub knows where to jump. */
3765 bfd_vma target_value;
3766 asection *target_section;
3768 /* The symbol table entry, if any, that this was derived from. */
3769 struct ppc_link_hash_entry *h;
3770 struct plt_entry *plt_ent;
3772 /* Where this stub is being called from, or, in the case of combined
3773 stub sections, the first input section in the group. */
3776 /* Symbol st_other. */
3777 unsigned char other;
3780 struct ppc_branch_hash_entry {
3782 /* Base hash table entry structure. */
3783 struct bfd_hash_entry root;
3785 /* Offset within branch lookup table. */
3786 unsigned int offset;
3788 /* Generation marker. */
3792 /* Used to track dynamic relocations for local symbols. */
3793 struct ppc_dyn_relocs
3795 struct ppc_dyn_relocs *next;
3797 /* The input section of the reloc. */
3800 /* Total number of relocs copied for the input section. */
3801 unsigned int count : 31;
3803 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3804 unsigned int ifunc : 1;
3807 struct ppc_link_hash_entry
3809 struct elf_link_hash_entry elf;
3812 /* A pointer to the most recently used stub hash entry against this
3814 struct ppc_stub_hash_entry *stub_cache;
3816 /* A pointer to the next symbol starting with a '.' */
3817 struct ppc_link_hash_entry *next_dot_sym;
3820 /* Track dynamic relocs copied for this symbol. */
3821 struct elf_dyn_relocs *dyn_relocs;
3823 /* Link between function code and descriptor symbols. */
3824 struct ppc_link_hash_entry *oh;
3826 /* Flag function code and descriptor symbols. */
3827 unsigned int is_func:1;
3828 unsigned int is_func_descriptor:1;
3829 unsigned int fake:1;
3831 /* Whether global opd/toc sym has been adjusted or not.
3832 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3833 should be set for all globals defined in any opd/toc section. */
3834 unsigned int adjust_done:1;
3836 /* Set if we twiddled this symbol to weak at some stage. */
3837 unsigned int was_undefined:1;
3839 /* Contexts in which symbol is used in the GOT (or TOC).
3840 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3841 corresponding relocs are encountered during check_relocs.
3842 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3843 indicate the corresponding GOT entry type is not needed.
3844 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3845 a TPREL one. We use a separate flag rather than setting TPREL
3846 just for convenience in distinguishing the two cases. */
3847 #define TLS_GD 1 /* GD reloc. */
3848 #define TLS_LD 2 /* LD reloc. */
3849 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3850 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3851 #define TLS_TLS 16 /* Any TLS reloc. */
3852 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3853 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3854 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3855 unsigned char tls_mask;
3858 /* ppc64 ELF linker hash table. */
3860 struct ppc_link_hash_table
3862 struct elf_link_hash_table elf;
3864 /* The stub hash table. */
3865 struct bfd_hash_table stub_hash_table;
3867 /* Another hash table for plt_branch stubs. */
3868 struct bfd_hash_table branch_hash_table;
3870 /* Hash table for function prologue tocsave. */
3871 htab_t tocsave_htab;
3873 /* Linker stub bfd. */
3876 /* Linker call-backs. */
3877 asection * (*add_stub_section) (const char *, asection *);
3878 void (*layout_sections_again) (void);
3880 /* Array to keep track of which stub sections have been created, and
3881 information on stub grouping. */
3883 /* This is the section to which stubs in the group will be attached. */
3885 /* The stub section. */
3887 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3891 /* Temp used when calculating TOC pointers. */
3894 asection *toc_first_sec;
3896 /* Highest input section id. */
3899 /* Highest output section index. */
3902 /* Used when adding symbols. */
3903 struct ppc_link_hash_entry *dot_syms;
3905 /* List of input sections for each output section. */
3906 asection **input_list;
3908 /* Short-cuts to get to dynamic linker sections. */
3920 asection *glink_eh_frame;
3922 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3923 struct ppc_link_hash_entry *tls_get_addr;
3924 struct ppc_link_hash_entry *tls_get_addr_fd;
3926 /* The size of reliplt used by got entry relocs. */
3927 bfd_size_type got_reli_size;
3930 unsigned long stub_count[ppc_stub_plt_call_r2save];
3932 /* Number of stubs against global syms. */
3933 unsigned long stub_globals;
3935 /* Alignment of PLT call stubs. */
3936 unsigned int plt_stub_align:4;
3938 /* Set if we're linking code with function descriptors. */
3939 unsigned int opd_abi:1;
3941 /* Set if PLT call stubs should load r11. */
3942 unsigned int plt_static_chain:1;
3944 /* Set if PLT call stubs need a read-read barrier. */
3945 unsigned int plt_thread_safe:1;
3947 /* Set if we should emit symbols for stubs. */
3948 unsigned int emit_stub_syms:1;
3950 /* Set if __tls_get_addr optimization should not be done. */
3951 unsigned int no_tls_get_addr_opt:1;
3953 /* Support for multiple toc sections. */
3954 unsigned int do_multi_toc:1;
3955 unsigned int multi_toc_needed:1;
3956 unsigned int second_toc_pass:1;
3957 unsigned int do_toc_opt:1;
3960 unsigned int stub_error:1;
3962 /* Temp used by ppc64_elf_process_dot_syms. */
3963 unsigned int twiddled_syms:1;
3965 /* Incremented every time we size stubs. */
3966 unsigned int stub_iteration;
3968 /* Small local sym cache. */
3969 struct sym_cache sym_cache;
3972 /* Rename some of the generic section flags to better document how they
3975 /* Nonzero if this section has TLS related relocations. */
3976 #define has_tls_reloc sec_flg0
3978 /* Nonzero if this section has a call to __tls_get_addr. */
3979 #define has_tls_get_addr_call sec_flg1
3981 /* Nonzero if this section has any toc or got relocs. */
3982 #define has_toc_reloc sec_flg2
3984 /* Nonzero if this section has a call to another section that uses
3986 #define makes_toc_func_call sec_flg3
3988 /* Recursion protection when determining above flag. */
3989 #define call_check_in_progress sec_flg4
3990 #define call_check_done sec_flg5
3992 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3994 #define ppc_hash_table(p) \
3995 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3996 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3998 #define ppc_stub_hash_lookup(table, string, create, copy) \
3999 ((struct ppc_stub_hash_entry *) \
4000 bfd_hash_lookup ((table), (string), (create), (copy)))
4002 #define ppc_branch_hash_lookup(table, string, create, copy) \
4003 ((struct ppc_branch_hash_entry *) \
4004 bfd_hash_lookup ((table), (string), (create), (copy)))
4006 /* Create an entry in the stub hash table. */
4008 static struct bfd_hash_entry *
4009 stub_hash_newfunc (struct bfd_hash_entry *entry,
4010 struct bfd_hash_table *table,
4013 /* Allocate the structure if it has not already been allocated by a
4017 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
4022 /* Call the allocation method of the superclass. */
4023 entry = bfd_hash_newfunc (entry, table, string);
4026 struct ppc_stub_hash_entry *eh;
4028 /* Initialize the local fields. */
4029 eh = (struct ppc_stub_hash_entry *) entry;
4030 eh->stub_type = ppc_stub_none;
4031 eh->stub_sec = NULL;
4032 eh->stub_offset = 0;
4033 eh->target_value = 0;
4034 eh->target_section = NULL;
4044 /* Create an entry in the branch hash table. */
4046 static struct bfd_hash_entry *
4047 branch_hash_newfunc (struct bfd_hash_entry *entry,
4048 struct bfd_hash_table *table,
4051 /* Allocate the structure if it has not already been allocated by a
4055 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
4060 /* Call the allocation method of the superclass. */
4061 entry = bfd_hash_newfunc (entry, table, string);
4064 struct ppc_branch_hash_entry *eh;
4066 /* Initialize the local fields. */
4067 eh = (struct ppc_branch_hash_entry *) entry;
4075 /* Create an entry in a ppc64 ELF linker hash table. */
4077 static struct bfd_hash_entry *
4078 link_hash_newfunc (struct bfd_hash_entry *entry,
4079 struct bfd_hash_table *table,
4082 /* Allocate the structure if it has not already been allocated by a
4086 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
4091 /* Call the allocation method of the superclass. */
4092 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
4095 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
4097 memset (&eh->u.stub_cache, 0,
4098 (sizeof (struct ppc_link_hash_entry)
4099 - offsetof (struct ppc_link_hash_entry, u.stub_cache)));
4101 /* When making function calls, old ABI code references function entry
4102 points (dot symbols), while new ABI code references the function
4103 descriptor symbol. We need to make any combination of reference and
4104 definition work together, without breaking archive linking.
4106 For a defined function "foo" and an undefined call to "bar":
4107 An old object defines "foo" and ".foo", references ".bar" (possibly
4109 A new object defines "foo" and references "bar".
4111 A new object thus has no problem with its undefined symbols being
4112 satisfied by definitions in an old object. On the other hand, the
4113 old object won't have ".bar" satisfied by a new object.
4115 Keep a list of newly added dot-symbols. */
4117 if (string[0] == '.')
4119 struct ppc_link_hash_table *htab;
4121 htab = (struct ppc_link_hash_table *) table;
4122 eh->u.next_dot_sym = htab->dot_syms;
4123 htab->dot_syms = eh;
4130 struct tocsave_entry {
4136 tocsave_htab_hash (const void *p)
4138 const struct tocsave_entry *e = (const struct tocsave_entry *) p;
4139 return ((bfd_vma)(intptr_t) e->sec ^ e->offset) >> 3;
4143 tocsave_htab_eq (const void *p1, const void *p2)
4145 const struct tocsave_entry *e1 = (const struct tocsave_entry *) p1;
4146 const struct tocsave_entry *e2 = (const struct tocsave_entry *) p2;
4147 return e1->sec == e2->sec && e1->offset == e2->offset;
4150 /* Create a ppc64 ELF linker hash table. */
4152 static struct bfd_link_hash_table *
4153 ppc64_elf_link_hash_table_create (bfd *abfd)
4155 struct ppc_link_hash_table *htab;
4156 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
4158 htab = bfd_zmalloc (amt);
4162 if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
4163 sizeof (struct ppc_link_hash_entry),
4170 /* Init the stub hash table too. */
4171 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
4172 sizeof (struct ppc_stub_hash_entry)))
4175 /* And the branch hash table. */
4176 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
4177 sizeof (struct ppc_branch_hash_entry)))
4180 htab->tocsave_htab = htab_try_create (1024,
4184 if (htab->tocsave_htab == NULL)
4187 /* Initializing two fields of the union is just cosmetic. We really
4188 only care about glist, but when compiled on a 32-bit host the
4189 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4190 debugger inspection of these fields look nicer. */
4191 htab->elf.init_got_refcount.refcount = 0;
4192 htab->elf.init_got_refcount.glist = NULL;
4193 htab->elf.init_plt_refcount.refcount = 0;
4194 htab->elf.init_plt_refcount.glist = NULL;
4195 htab->elf.init_got_offset.offset = 0;
4196 htab->elf.init_got_offset.glist = NULL;
4197 htab->elf.init_plt_offset.offset = 0;
4198 htab->elf.init_plt_offset.glist = NULL;
4200 return &htab->elf.root;
4203 /* Free the derived linker hash table. */
4206 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
4208 struct ppc_link_hash_table *htab = (struct ppc_link_hash_table *) hash;
4210 bfd_hash_table_free (&htab->stub_hash_table);
4211 bfd_hash_table_free (&htab->branch_hash_table);
4212 if (htab->tocsave_htab)
4213 htab_delete (htab->tocsave_htab);
4214 _bfd_elf_link_hash_table_free (hash);
4217 /* Create sections for linker generated code. */
4220 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
4222 struct ppc_link_hash_table *htab;
4225 htab = ppc_hash_table (info);
4227 /* Create .sfpr for code to save and restore fp regs. */
4228 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
4229 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4230 htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
4232 if (htab->sfpr == NULL
4233 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
4236 /* Create .glink for lazy dynamic linking support. */
4237 htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
4239 if (htab->glink == NULL
4240 || ! bfd_set_section_alignment (dynobj, htab->glink, 3))
4243 if (!info->no_ld_generated_unwind_info)
4245 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
4246 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4247 htab->glink_eh_frame = bfd_make_section_anyway_with_flags (dynobj,
4250 if (htab->glink_eh_frame == NULL
4251 || !bfd_set_section_alignment (dynobj, htab->glink_eh_frame, 2))
4255 flags = SEC_ALLOC | SEC_LINKER_CREATED;
4256 htab->iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
4257 if (htab->iplt == NULL
4258 || ! bfd_set_section_alignment (dynobj, htab->iplt, 3))
4261 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4262 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4263 htab->reliplt = bfd_make_section_anyway_with_flags (dynobj,
4266 if (htab->reliplt == NULL
4267 || ! bfd_set_section_alignment (dynobj, htab->reliplt, 3))
4270 /* Create branch lookup table for plt_branch stubs. */
4271 flags = (SEC_ALLOC | SEC_LOAD
4272 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4273 htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
4275 if (htab->brlt == NULL
4276 || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
4282 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4283 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4284 htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
4287 if (htab->relbrlt == NULL
4288 || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
4294 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4297 ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info)
4299 struct ppc_link_hash_table *htab;
4301 elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64;
4303 /* Always hook our dynamic sections into the first bfd, which is the
4304 linker created stub bfd. This ensures that the GOT header is at
4305 the start of the output TOC section. */
4306 htab = ppc_hash_table (info);
4309 htab->stub_bfd = abfd;
4310 htab->elf.dynobj = abfd;
4312 if (info->relocatable)
4315 return create_linkage_sections (htab->elf.dynobj, info);
4318 /* Build a name for an entry in the stub hash table. */
4321 ppc_stub_name (const asection *input_section,
4322 const asection *sym_sec,
4323 const struct ppc_link_hash_entry *h,
4324 const Elf_Internal_Rela *rel)
4329 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4330 offsets from a sym as a branch target? In fact, we could
4331 probably assume the addend is always zero. */
4332 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
4336 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
4337 stub_name = bfd_malloc (len);
4338 if (stub_name == NULL)
4341 len = sprintf (stub_name, "%08x.%s+%x",
4342 input_section->id & 0xffffffff,
4343 h->elf.root.root.string,
4344 (int) rel->r_addend & 0xffffffff);
4348 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4349 stub_name = bfd_malloc (len);
4350 if (stub_name == NULL)
4353 len = sprintf (stub_name, "%08x.%x:%x+%x",
4354 input_section->id & 0xffffffff,
4355 sym_sec->id & 0xffffffff,
4356 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
4357 (int) rel->r_addend & 0xffffffff);
4359 if (len > 2 && stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
4360 stub_name[len - 2] = 0;
4364 /* Look up an entry in the stub hash. Stub entries are cached because
4365 creating the stub name takes a bit of time. */
4367 static struct ppc_stub_hash_entry *
4368 ppc_get_stub_entry (const asection *input_section,
4369 const asection *sym_sec,
4370 struct ppc_link_hash_entry *h,
4371 const Elf_Internal_Rela *rel,
4372 struct ppc_link_hash_table *htab)
4374 struct ppc_stub_hash_entry *stub_entry;
4375 const asection *id_sec;
4377 /* If this input section is part of a group of sections sharing one
4378 stub section, then use the id of the first section in the group.
4379 Stub names need to include a section id, as there may well be
4380 more than one stub used to reach say, printf, and we need to
4381 distinguish between them. */
4382 id_sec = htab->stub_group[input_section->id].link_sec;
4384 if (h != NULL && h->u.stub_cache != NULL
4385 && h->u.stub_cache->h == h
4386 && h->u.stub_cache->id_sec == id_sec)
4388 stub_entry = h->u.stub_cache;
4394 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
4395 if (stub_name == NULL)
4398 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4399 stub_name, FALSE, FALSE);
4401 h->u.stub_cache = stub_entry;
4409 /* Add a new stub entry to the stub hash. Not all fields of the new
4410 stub entry are initialised. */
4412 static struct ppc_stub_hash_entry *
4413 ppc_add_stub (const char *stub_name,
4415 struct bfd_link_info *info)
4417 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4420 struct ppc_stub_hash_entry *stub_entry;
4422 link_sec = htab->stub_group[section->id].link_sec;
4423 stub_sec = htab->stub_group[section->id].stub_sec;
4424 if (stub_sec == NULL)
4426 stub_sec = htab->stub_group[link_sec->id].stub_sec;
4427 if (stub_sec == NULL)
4433 namelen = strlen (link_sec->name);
4434 len = namelen + sizeof (STUB_SUFFIX);
4435 s_name = bfd_alloc (htab->stub_bfd, len);
4439 memcpy (s_name, link_sec->name, namelen);
4440 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
4441 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
4442 if (stub_sec == NULL)
4444 htab->stub_group[link_sec->id].stub_sec = stub_sec;
4446 htab->stub_group[section->id].stub_sec = stub_sec;
4449 /* Enter this entry into the linker stub hash table. */
4450 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4452 if (stub_entry == NULL)
4454 info->callbacks->einfo (_("%P: %B: cannot create stub entry %s\n"),
4455 section->owner, stub_name);
4459 stub_entry->stub_sec = stub_sec;
4460 stub_entry->stub_offset = 0;
4461 stub_entry->id_sec = link_sec;
4465 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4466 not already done. */
4469 create_got_section (bfd *abfd, struct bfd_link_info *info)
4471 asection *got, *relgot;
4473 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4475 if (!is_ppc64_elf (abfd))
4482 if (! _bfd_elf_create_got_section (htab->elf.dynobj, info))
4485 htab->got = bfd_get_linker_section (htab->elf.dynobj, ".got");
4490 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4491 | SEC_LINKER_CREATED);
4493 got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
4495 || !bfd_set_section_alignment (abfd, got, 3))
4498 relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
4499 flags | SEC_READONLY);
4501 || ! bfd_set_section_alignment (abfd, relgot, 3))
4504 ppc64_elf_tdata (abfd)->got = got;
4505 ppc64_elf_tdata (abfd)->relgot = relgot;
4509 /* Create the dynamic sections, and set up shortcuts. */
4512 ppc64_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
4514 struct ppc_link_hash_table *htab;
4516 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
4519 htab = ppc_hash_table (info);
4524 htab->got = bfd_get_linker_section (dynobj, ".got");
4525 htab->plt = bfd_get_linker_section (dynobj, ".plt");
4526 htab->relplt = bfd_get_linker_section (dynobj, ".rela.plt");
4527 htab->dynbss = bfd_get_linker_section (dynobj, ".dynbss");
4529 htab->relbss = bfd_get_linker_section (dynobj, ".rela.bss");
4531 if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss
4532 || (!info->shared && !htab->relbss))
4538 /* Follow indirect and warning symbol links. */
4540 static inline struct bfd_link_hash_entry *
4541 follow_link (struct bfd_link_hash_entry *h)
4543 while (h->type == bfd_link_hash_indirect
4544 || h->type == bfd_link_hash_warning)
4549 static inline struct elf_link_hash_entry *
4550 elf_follow_link (struct elf_link_hash_entry *h)
4552 return (struct elf_link_hash_entry *) follow_link (&h->root);
4555 static inline struct ppc_link_hash_entry *
4556 ppc_follow_link (struct ppc_link_hash_entry *h)
4558 return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
4561 /* Merge PLT info on FROM with that on TO. */
4564 move_plt_plist (struct ppc_link_hash_entry *from,
4565 struct ppc_link_hash_entry *to)
4567 if (from->elf.plt.plist != NULL)
4569 if (to->elf.plt.plist != NULL)
4571 struct plt_entry **entp;
4572 struct plt_entry *ent;
4574 for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; )
4576 struct plt_entry *dent;
4578 for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next)
4579 if (dent->addend == ent->addend)
4581 dent->plt.refcount += ent->plt.refcount;
4588 *entp = to->elf.plt.plist;
4591 to->elf.plt.plist = from->elf.plt.plist;
4592 from->elf.plt.plist = NULL;
4596 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4599 ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
4600 struct elf_link_hash_entry *dir,
4601 struct elf_link_hash_entry *ind)
4603 struct ppc_link_hash_entry *edir, *eind;
4605 edir = (struct ppc_link_hash_entry *) dir;
4606 eind = (struct ppc_link_hash_entry *) ind;
4608 edir->is_func |= eind->is_func;
4609 edir->is_func_descriptor |= eind->is_func_descriptor;
4610 edir->tls_mask |= eind->tls_mask;
4611 if (eind->oh != NULL)
4612 edir->oh = ppc_follow_link (eind->oh);
4614 /* If called to transfer flags for a weakdef during processing
4615 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4616 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4617 if (!(ELIMINATE_COPY_RELOCS
4618 && eind->elf.root.type != bfd_link_hash_indirect
4619 && edir->elf.dynamic_adjusted))
4620 edir->elf.non_got_ref |= eind->elf.non_got_ref;
4622 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
4623 edir->elf.ref_regular |= eind->elf.ref_regular;
4624 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
4625 edir->elf.needs_plt |= eind->elf.needs_plt;
4627 /* Copy over any dynamic relocs we may have on the indirect sym. */
4628 if (eind->dyn_relocs != NULL)
4630 if (edir->dyn_relocs != NULL)
4632 struct elf_dyn_relocs **pp;
4633 struct elf_dyn_relocs *p;
4635 /* Add reloc counts against the indirect sym to the direct sym
4636 list. Merge any entries against the same section. */
4637 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
4639 struct elf_dyn_relocs *q;
4641 for (q = edir->dyn_relocs; q != NULL; q = q->next)
4642 if (q->sec == p->sec)
4644 q->pc_count += p->pc_count;
4645 q->count += p->count;
4652 *pp = edir->dyn_relocs;
4655 edir->dyn_relocs = eind->dyn_relocs;
4656 eind->dyn_relocs = NULL;
4659 /* If we were called to copy over info for a weak sym, that's all.
4660 You might think dyn_relocs need not be copied over; After all,
4661 both syms will be dynamic or both non-dynamic so we're just
4662 moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
4663 code in ppc64_elf_adjust_dynamic_symbol needs to check for
4664 dyn_relocs in read-only sections, and it does so on what is the
4666 if (eind->elf.root.type != bfd_link_hash_indirect)
4669 /* Copy over got entries that we may have already seen to the
4670 symbol which just became indirect. */
4671 if (eind->elf.got.glist != NULL)
4673 if (edir->elf.got.glist != NULL)
4675 struct got_entry **entp;
4676 struct got_entry *ent;
4678 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
4680 struct got_entry *dent;
4682 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
4683 if (dent->addend == ent->addend
4684 && dent->owner == ent->owner
4685 && dent->tls_type == ent->tls_type)
4687 dent->got.refcount += ent->got.refcount;
4694 *entp = edir->elf.got.glist;
4697 edir->elf.got.glist = eind->elf.got.glist;
4698 eind->elf.got.glist = NULL;
4701 /* And plt entries. */
4702 move_plt_plist (eind, edir);
4704 if (eind->elf.dynindx != -1)
4706 if (edir->elf.dynindx != -1)
4707 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4708 edir->elf.dynstr_index);
4709 edir->elf.dynindx = eind->elf.dynindx;
4710 edir->elf.dynstr_index = eind->elf.dynstr_index;
4711 eind->elf.dynindx = -1;
4712 eind->elf.dynstr_index = 0;
4716 /* Find the function descriptor hash entry from the given function code
4717 hash entry FH. Link the entries via their OH fields. */
4719 static struct ppc_link_hash_entry *
4720 lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
4722 struct ppc_link_hash_entry *fdh = fh->oh;
4726 const char *fd_name = fh->elf.root.root.string + 1;
4728 fdh = (struct ppc_link_hash_entry *)
4729 elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
4733 fdh->is_func_descriptor = 1;
4739 return ppc_follow_link (fdh);
4742 /* Make a fake function descriptor sym for the code sym FH. */
4744 static struct ppc_link_hash_entry *
4745 make_fdh (struct bfd_link_info *info,
4746 struct ppc_link_hash_entry *fh)
4750 struct bfd_link_hash_entry *bh;
4751 struct ppc_link_hash_entry *fdh;
4753 abfd = fh->elf.root.u.undef.abfd;
4754 newsym = bfd_make_empty_symbol (abfd);
4755 newsym->name = fh->elf.root.root.string + 1;
4756 newsym->section = bfd_und_section_ptr;
4758 newsym->flags = BSF_WEAK;
4761 if (!_bfd_generic_link_add_one_symbol (info, abfd, newsym->name,
4762 newsym->flags, newsym->section,
4763 newsym->value, NULL, FALSE, FALSE,
4767 fdh = (struct ppc_link_hash_entry *) bh;
4768 fdh->elf.non_elf = 0;
4770 fdh->is_func_descriptor = 1;
4777 /* Fix function descriptor symbols defined in .opd sections to be
4781 ppc64_elf_add_symbol_hook (bfd *ibfd,
4782 struct bfd_link_info *info,
4783 Elf_Internal_Sym *isym,
4785 flagword *flags ATTRIBUTE_UNUSED,
4787 bfd_vma *value ATTRIBUTE_UNUSED)
4789 if ((ibfd->flags & DYNAMIC) == 0
4790 && ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
4791 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4793 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
4795 if ((ibfd->flags & DYNAMIC) == 0)
4796 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
4798 else if (ELF_ST_TYPE (isym->st_info) == STT_FUNC)
4800 else if (*sec != NULL
4801 && strcmp ((*sec)->name, ".opd") == 0)
4802 isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
4804 if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
4806 if (abiversion (ibfd) == 0)
4807 set_abiversion (ibfd, 2);
4808 else if (abiversion (ibfd) == 1)
4810 info->callbacks->einfo (_("%P: symbol '%s' has invalid st_other"
4811 " for ABI version 1\n"), name);
4812 bfd_set_error (bfd_error_bad_value);
4820 /* Merge non-visibility st_other attributes: local entry point. */
4823 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
4824 const Elf_Internal_Sym *isym,
4825 bfd_boolean definition,
4826 bfd_boolean dynamic)
4828 if (definition && !dynamic)
4829 h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
4830 | ELF_ST_VISIBILITY (h->other));
4833 /* This function makes an old ABI object reference to ".bar" cause the
4834 inclusion of a new ABI object archive that defines "bar".
4835 NAME is a symbol defined in an archive. Return a symbol in the hash
4836 table that might be satisfied by the archive symbols. */
4838 static struct elf_link_hash_entry *
4839 ppc64_elf_archive_symbol_lookup (bfd *abfd,
4840 struct bfd_link_info *info,
4843 struct elf_link_hash_entry *h;
4847 h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
4849 /* Don't return this sym if it is a fake function descriptor
4850 created by add_symbol_adjust. */
4851 && !(h->root.type == bfd_link_hash_undefweak
4852 && ((struct ppc_link_hash_entry *) h)->fake))
4858 len = strlen (name);
4859 dot_name = bfd_alloc (abfd, len + 2);
4860 if (dot_name == NULL)
4861 return (struct elf_link_hash_entry *) 0 - 1;
4863 memcpy (dot_name + 1, name, len + 1);
4864 h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
4865 bfd_release (abfd, dot_name);
4869 /* This function satisfies all old ABI object references to ".bar" if a
4870 new ABI object defines "bar". Well, at least, undefined dot symbols
4871 are made weak. This stops later archive searches from including an
4872 object if we already have a function descriptor definition. It also
4873 prevents the linker complaining about undefined symbols.
4874 We also check and correct mismatched symbol visibility here. The
4875 most restrictive visibility of the function descriptor and the
4876 function entry symbol is used. */
4879 add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
4881 struct ppc_link_hash_table *htab;
4882 struct ppc_link_hash_entry *fdh;
4884 if (eh->elf.root.type == bfd_link_hash_indirect)
4887 if (eh->elf.root.type == bfd_link_hash_warning)
4888 eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
4890 if (eh->elf.root.root.string[0] != '.')
4893 htab = ppc_hash_table (info);
4897 fdh = lookup_fdh (eh, htab);
4900 if (!info->relocatable
4901 && (eh->elf.root.type == bfd_link_hash_undefined
4902 || eh->elf.root.type == bfd_link_hash_undefweak)
4903 && eh->elf.ref_regular)
4905 /* Make an undefweak function descriptor sym, which is enough to
4906 pull in an --as-needed shared lib, but won't cause link
4907 errors. Archives are handled elsewhere. */
4908 fdh = make_fdh (info, eh);
4911 fdh->elf.ref_regular = 1;
4916 unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
4917 unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
4918 if (entry_vis < descr_vis)
4919 fdh->elf.other += entry_vis - descr_vis;
4920 else if (entry_vis > descr_vis)
4921 eh->elf.other += descr_vis - entry_vis;
4923 if ((fdh->elf.root.type == bfd_link_hash_defined
4924 || fdh->elf.root.type == bfd_link_hash_defweak)
4925 && eh->elf.root.type == bfd_link_hash_undefined)
4927 eh->elf.root.type = bfd_link_hash_undefweak;
4928 eh->was_undefined = 1;
4929 htab->twiddled_syms = 1;
4936 /* Process list of dot-symbols we made in link_hash_newfunc. */
4939 ppc64_elf_process_dot_syms (bfd *ibfd, struct bfd_link_info *info)
4941 struct ppc_link_hash_table *htab;
4942 struct ppc_link_hash_entry **p, *eh;
4944 if (!is_ppc64_elf (info->output_bfd))
4946 htab = ppc_hash_table (info);
4950 if (is_ppc64_elf (ibfd))
4952 p = &htab->dot_syms;
4953 while ((eh = *p) != NULL)
4956 if (&eh->elf == htab->elf.hgot)
4958 else if (htab->elf.hgot == NULL
4959 && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
4960 htab->elf.hgot = &eh->elf;
4961 else if (!add_symbol_adjust (eh, info))
4963 p = &eh->u.next_dot_sym;
4967 /* Clear the list for non-ppc64 input files. */
4968 p = &htab->dot_syms;
4969 while ((eh = *p) != NULL)
4972 p = &eh->u.next_dot_sym;
4975 /* We need to fix the undefs list for any syms we have twiddled to
4977 if (htab->twiddled_syms)
4979 bfd_link_repair_undef_list (&htab->elf.root);
4980 htab->twiddled_syms = 0;
4985 /* Undo hash table changes when an --as-needed input file is determined
4986 not to be needed. */
4989 ppc64_elf_notice_as_needed (bfd *ibfd,
4990 struct bfd_link_info *info,
4991 enum notice_asneeded_action act)
4993 if (act == notice_not_needed)
4995 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5000 htab->dot_syms = NULL;
5002 return _bfd_elf_notice_as_needed (ibfd, info, act);
5005 /* If --just-symbols against a final linked binary, then assume we need
5006 toc adjusting stubs when calling functions defined there. */
5009 ppc64_elf_link_just_syms (asection *sec, struct bfd_link_info *info)
5011 if ((sec->flags & SEC_CODE) != 0
5012 && (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
5013 && is_ppc64_elf (sec->owner))
5015 asection *got = bfd_get_section_by_name (sec->owner, ".got");
5017 && got->size >= elf_backend_got_header_size
5018 && bfd_get_section_by_name (sec->owner, ".opd") != NULL)
5019 sec->has_toc_reloc = 1;
5021 _bfd_elf_link_just_syms (sec, info);
5024 static struct plt_entry **
5025 update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
5026 unsigned long r_symndx, bfd_vma r_addend, int tls_type)
5028 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
5029 struct plt_entry **local_plt;
5030 unsigned char *local_got_tls_masks;
5032 if (local_got_ents == NULL)
5034 bfd_size_type size = symtab_hdr->sh_info;
5036 size *= (sizeof (*local_got_ents)
5037 + sizeof (*local_plt)
5038 + sizeof (*local_got_tls_masks));
5039 local_got_ents = bfd_zalloc (abfd, size);
5040 if (local_got_ents == NULL)
5042 elf_local_got_ents (abfd) = local_got_ents;
5045 if ((tls_type & (PLT_IFUNC | TLS_EXPLICIT)) == 0)
5047 struct got_entry *ent;
5049 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
5050 if (ent->addend == r_addend
5051 && ent->owner == abfd
5052 && ent->tls_type == tls_type)
5056 bfd_size_type amt = sizeof (*ent);
5057 ent = bfd_alloc (abfd, amt);
5060 ent->next = local_got_ents[r_symndx];
5061 ent->addend = r_addend;
5063 ent->tls_type = tls_type;
5064 ent->is_indirect = FALSE;
5065 ent->got.refcount = 0;
5066 local_got_ents[r_symndx] = ent;
5068 ent->got.refcount += 1;
5071 local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info);
5072 local_got_tls_masks = (unsigned char *) (local_plt + symtab_hdr->sh_info);
5073 local_got_tls_masks[r_symndx] |= tls_type;
5075 return local_plt + r_symndx;
5079 update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
5081 struct plt_entry *ent;
5083 for (ent = *plist; ent != NULL; ent = ent->next)
5084 if (ent->addend == addend)
5088 bfd_size_type amt = sizeof (*ent);
5089 ent = bfd_alloc (abfd, amt);
5093 ent->addend = addend;
5094 ent->plt.refcount = 0;
5097 ent->plt.refcount += 1;
5102 is_branch_reloc (enum elf_ppc64_reloc_type r_type)
5104 return (r_type == R_PPC64_REL24
5105 || r_type == R_PPC64_REL14
5106 || r_type == R_PPC64_REL14_BRTAKEN
5107 || r_type == R_PPC64_REL14_BRNTAKEN
5108 || r_type == R_PPC64_ADDR24
5109 || r_type == R_PPC64_ADDR14
5110 || r_type == R_PPC64_ADDR14_BRTAKEN
5111 || r_type == R_PPC64_ADDR14_BRNTAKEN);
5114 /* Look through the relocs for a section during the first phase, and
5115 calculate needed space in the global offset table, procedure
5116 linkage table, and dynamic reloc sections. */
5119 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
5120 asection *sec, const Elf_Internal_Rela *relocs)
5122 struct ppc_link_hash_table *htab;
5123 Elf_Internal_Shdr *symtab_hdr;
5124 struct elf_link_hash_entry **sym_hashes;
5125 const Elf_Internal_Rela *rel;
5126 const Elf_Internal_Rela *rel_end;
5128 asection **opd_sym_map;
5129 struct elf_link_hash_entry *tga, *dottga;
5131 if (info->relocatable)
5134 /* Don't do anything special with non-loaded, non-alloced sections.
5135 In particular, any relocs in such sections should not affect GOT
5136 and PLT reference counting (ie. we don't allow them to create GOT
5137 or PLT entries), there's no possibility or desire to optimize TLS
5138 relocs, and there's not much point in propagating relocs to shared
5139 libs that the dynamic linker won't relocate. */
5140 if ((sec->flags & SEC_ALLOC) == 0)
5143 BFD_ASSERT (is_ppc64_elf (abfd));
5145 htab = ppc_hash_table (info);
5149 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
5150 FALSE, FALSE, TRUE);
5151 dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
5152 FALSE, FALSE, TRUE);
5153 symtab_hdr = &elf_symtab_hdr (abfd);
5154 sym_hashes = elf_sym_hashes (abfd);
5157 if (strcmp (sec->name, ".opd") == 0)
5159 /* Garbage collection needs some extra help with .opd sections.
5160 We don't want to necessarily keep everything referenced by
5161 relocs in .opd, as that would keep all functions. Instead,
5162 if we reference an .opd symbol (a function descriptor), we
5163 want to keep the function code symbol's section. This is
5164 easy for global symbols, but for local syms we need to keep
5165 information about the associated function section. */
5168 if (abiversion (abfd) == 0)
5169 set_abiversion (abfd, 1);
5170 else if (abiversion (abfd) == 2)
5172 info->callbacks->einfo (_("%P: .opd not allowed in ABI version %d\n"),
5174 bfd_set_error (bfd_error_bad_value);
5177 amt = sec->size * sizeof (*opd_sym_map) / 8;
5178 opd_sym_map = bfd_zalloc (abfd, amt);
5179 if (opd_sym_map == NULL)
5181 ppc64_elf_section_data (sec)->u.opd.func_sec = opd_sym_map;
5182 BFD_ASSERT (ppc64_elf_section_data (sec)->sec_type == sec_normal);
5183 ppc64_elf_section_data (sec)->sec_type = sec_opd;
5186 rel_end = relocs + sec->reloc_count;
5187 for (rel = relocs; rel < rel_end; rel++)
5189 unsigned long r_symndx;
5190 struct elf_link_hash_entry *h;
5191 enum elf_ppc64_reloc_type r_type;
5193 struct _ppc64_elf_section_data *ppc64_sec;
5194 struct plt_entry **ifunc;
5196 r_symndx = ELF64_R_SYM (rel->r_info);
5197 if (r_symndx < symtab_hdr->sh_info)
5201 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5202 h = elf_follow_link (h);
5204 /* PR15323, ref flags aren't set for references in the same
5206 h->root.non_ir_ref = 1;
5208 if (h == htab->elf.hgot)
5209 sec->has_toc_reloc = 1;
5216 if (h->type == STT_GNU_IFUNC)
5219 ifunc = &h->plt.plist;
5224 Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5229 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
5231 ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
5232 rel->r_addend, PLT_IFUNC);
5237 r_type = ELF64_R_TYPE (rel->r_info);
5238 if (is_branch_reloc (r_type))
5240 if (h != NULL && (h == tga || h == dottga))
5243 && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
5244 || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
5245 /* We have a new-style __tls_get_addr call with a marker
5249 /* Mark this section as having an old-style call. */
5250 sec->has_tls_get_addr_call = 1;
5253 /* STT_GNU_IFUNC symbols must have a PLT entry. */
5255 && !update_plt_info (abfd, ifunc, rel->r_addend))
5263 /* These special tls relocs tie a call to __tls_get_addr with
5264 its parameter symbol. */
5267 case R_PPC64_GOT_TLSLD16:
5268 case R_PPC64_GOT_TLSLD16_LO:
5269 case R_PPC64_GOT_TLSLD16_HI:
5270 case R_PPC64_GOT_TLSLD16_HA:
5271 tls_type = TLS_TLS | TLS_LD;
5274 case R_PPC64_GOT_TLSGD16:
5275 case R_PPC64_GOT_TLSGD16_LO:
5276 case R_PPC64_GOT_TLSGD16_HI:
5277 case R_PPC64_GOT_TLSGD16_HA:
5278 tls_type = TLS_TLS | TLS_GD;
5281 case R_PPC64_GOT_TPREL16_DS:
5282 case R_PPC64_GOT_TPREL16_LO_DS:
5283 case R_PPC64_GOT_TPREL16_HI:
5284 case R_PPC64_GOT_TPREL16_HA:
5285 if (!info->executable)
5286 info->flags |= DF_STATIC_TLS;
5287 tls_type = TLS_TLS | TLS_TPREL;
5290 case R_PPC64_GOT_DTPREL16_DS:
5291 case R_PPC64_GOT_DTPREL16_LO_DS:
5292 case R_PPC64_GOT_DTPREL16_HI:
5293 case R_PPC64_GOT_DTPREL16_HA:
5294 tls_type = TLS_TLS | TLS_DTPREL;
5296 sec->has_tls_reloc = 1;
5300 case R_PPC64_GOT16_DS:
5301 case R_PPC64_GOT16_HA:
5302 case R_PPC64_GOT16_HI:
5303 case R_PPC64_GOT16_LO:
5304 case R_PPC64_GOT16_LO_DS:
5305 /* This symbol requires a global offset table entry. */
5306 sec->has_toc_reloc = 1;
5307 if (r_type == R_PPC64_GOT_TLSLD16
5308 || r_type == R_PPC64_GOT_TLSGD16
5309 || r_type == R_PPC64_GOT_TPREL16_DS
5310 || r_type == R_PPC64_GOT_DTPREL16_DS
5311 || r_type == R_PPC64_GOT16
5312 || r_type == R_PPC64_GOT16_DS)
5314 htab->do_multi_toc = 1;
5315 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5318 if (ppc64_elf_tdata (abfd)->got == NULL
5319 && !create_got_section (abfd, info))
5324 struct ppc_link_hash_entry *eh;
5325 struct got_entry *ent;
5327 eh = (struct ppc_link_hash_entry *) h;
5328 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
5329 if (ent->addend == rel->r_addend
5330 && ent->owner == abfd
5331 && ent->tls_type == tls_type)
5335 bfd_size_type amt = sizeof (*ent);
5336 ent = bfd_alloc (abfd, amt);
5339 ent->next = eh->elf.got.glist;
5340 ent->addend = rel->r_addend;
5342 ent->tls_type = tls_type;
5343 ent->is_indirect = FALSE;
5344 ent->got.refcount = 0;
5345 eh->elf.got.glist = ent;
5347 ent->got.refcount += 1;
5348 eh->tls_mask |= tls_type;
5351 /* This is a global offset table entry for a local symbol. */
5352 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5353 rel->r_addend, tls_type))
5357 case R_PPC64_PLT16_HA:
5358 case R_PPC64_PLT16_HI:
5359 case R_PPC64_PLT16_LO:
5362 /* This symbol requires a procedure linkage table entry. We
5363 actually build the entry in adjust_dynamic_symbol,
5364 because this might be a case of linking PIC code without
5365 linking in any dynamic objects, in which case we don't
5366 need to generate a procedure linkage table after all. */
5369 /* It does not make sense to have a procedure linkage
5370 table entry for a local symbol. */
5371 bfd_set_error (bfd_error_bad_value);
5376 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5379 if (h->root.root.string[0] == '.'
5380 && h->root.root.string[1] != '\0')
5381 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5385 /* The following relocations don't need to propagate the
5386 relocation if linking a shared object since they are
5387 section relative. */
5388 case R_PPC64_SECTOFF:
5389 case R_PPC64_SECTOFF_LO:
5390 case R_PPC64_SECTOFF_HI:
5391 case R_PPC64_SECTOFF_HA:
5392 case R_PPC64_SECTOFF_DS:
5393 case R_PPC64_SECTOFF_LO_DS:
5394 case R_PPC64_DTPREL16:
5395 case R_PPC64_DTPREL16_LO:
5396 case R_PPC64_DTPREL16_HI:
5397 case R_PPC64_DTPREL16_HA:
5398 case R_PPC64_DTPREL16_DS:
5399 case R_PPC64_DTPREL16_LO_DS:
5400 case R_PPC64_DTPREL16_HIGH:
5401 case R_PPC64_DTPREL16_HIGHA:
5402 case R_PPC64_DTPREL16_HIGHER:
5403 case R_PPC64_DTPREL16_HIGHERA:
5404 case R_PPC64_DTPREL16_HIGHEST:
5405 case R_PPC64_DTPREL16_HIGHESTA:
5410 case R_PPC64_REL16_LO:
5411 case R_PPC64_REL16_HI:
5412 case R_PPC64_REL16_HA:
5416 case R_PPC64_TOC16_DS:
5417 htab->do_multi_toc = 1;
5418 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5419 case R_PPC64_TOC16_LO:
5420 case R_PPC64_TOC16_HI:
5421 case R_PPC64_TOC16_HA:
5422 case R_PPC64_TOC16_LO_DS:
5423 sec->has_toc_reloc = 1;
5426 /* This relocation describes the C++ object vtable hierarchy.
5427 Reconstruct it for later use during GC. */
5428 case R_PPC64_GNU_VTINHERIT:
5429 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5433 /* This relocation describes which C++ vtable entries are actually
5434 used. Record for later use during GC. */
5435 case R_PPC64_GNU_VTENTRY:
5436 BFD_ASSERT (h != NULL);
5438 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5443 case R_PPC64_REL14_BRTAKEN:
5444 case R_PPC64_REL14_BRNTAKEN:
5446 asection *dest = NULL;
5448 /* Heuristic: If jumping outside our section, chances are
5449 we are going to need a stub. */
5452 /* If the sym is weak it may be overridden later, so
5453 don't assume we know where a weak sym lives. */
5454 if (h->root.type == bfd_link_hash_defined)
5455 dest = h->root.u.def.section;
5459 Elf_Internal_Sym *isym;
5461 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5466 dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
5470 ppc64_elf_section_data (sec)->has_14bit_branch = 1;
5475 if (h != NULL && ifunc == NULL)
5477 /* We may need a .plt entry if the function this reloc
5478 refers to is in a shared lib. */
5479 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5482 if (h->root.root.string[0] == '.'
5483 && h->root.root.string[1] != '\0')
5484 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5485 if (h == tga || h == dottga)
5486 sec->has_tls_reloc = 1;
5490 case R_PPC64_TPREL64:
5491 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
5492 if (!info->executable)
5493 info->flags |= DF_STATIC_TLS;
5496 case R_PPC64_DTPMOD64:
5497 if (rel + 1 < rel_end
5498 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
5499 && rel[1].r_offset == rel->r_offset + 8)
5500 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
5502 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
5505 case R_PPC64_DTPREL64:
5506 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
5508 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
5509 && rel[-1].r_offset == rel->r_offset - 8)
5510 /* This is the second reloc of a dtpmod, dtprel pair.
5511 Don't mark with TLS_DTPREL. */
5515 sec->has_tls_reloc = 1;
5518 struct ppc_link_hash_entry *eh;
5519 eh = (struct ppc_link_hash_entry *) h;
5520 eh->tls_mask |= tls_type;
5523 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5524 rel->r_addend, tls_type))
5527 ppc64_sec = ppc64_elf_section_data (sec);
5528 if (ppc64_sec->sec_type != sec_toc)
5532 /* One extra to simplify get_tls_mask. */
5533 amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned);
5534 ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt);
5535 if (ppc64_sec->u.toc.symndx == NULL)
5537 amt = sec->size * sizeof (bfd_vma) / 8;
5538 ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt);
5539 if (ppc64_sec->u.toc.add == NULL)
5541 BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
5542 ppc64_sec->sec_type = sec_toc;
5544 BFD_ASSERT (rel->r_offset % 8 == 0);
5545 ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx;
5546 ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend;
5548 /* Mark the second slot of a GD or LD entry.
5549 -1 to indicate GD and -2 to indicate LD. */
5550 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
5551 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1;
5552 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
5553 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2;
5556 case R_PPC64_TPREL16:
5557 case R_PPC64_TPREL16_LO:
5558 case R_PPC64_TPREL16_HI:
5559 case R_PPC64_TPREL16_HA:
5560 case R_PPC64_TPREL16_DS:
5561 case R_PPC64_TPREL16_LO_DS:
5562 case R_PPC64_TPREL16_HIGH:
5563 case R_PPC64_TPREL16_HIGHA:
5564 case R_PPC64_TPREL16_HIGHER:
5565 case R_PPC64_TPREL16_HIGHERA:
5566 case R_PPC64_TPREL16_HIGHEST:
5567 case R_PPC64_TPREL16_HIGHESTA:
5570 if (!info->executable)
5571 info->flags |= DF_STATIC_TLS;
5576 case R_PPC64_ADDR64:
5577 if (opd_sym_map != NULL
5578 && rel + 1 < rel_end
5579 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
5583 if (h->root.root.string[0] == '.'
5584 && h->root.root.string[1] != 0
5585 && lookup_fdh ((struct ppc_link_hash_entry *) h, htab))
5588 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5593 Elf_Internal_Sym *isym;
5595 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5600 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
5601 if (s != NULL && s != sec)
5602 opd_sym_map[rel->r_offset / 8] = s;
5610 case R_PPC64_ADDR14:
5611 case R_PPC64_ADDR14_BRNTAKEN:
5612 case R_PPC64_ADDR14_BRTAKEN:
5613 case R_PPC64_ADDR16:
5614 case R_PPC64_ADDR16_DS:
5615 case R_PPC64_ADDR16_HA:
5616 case R_PPC64_ADDR16_HI:
5617 case R_PPC64_ADDR16_HIGH:
5618 case R_PPC64_ADDR16_HIGHA:
5619 case R_PPC64_ADDR16_HIGHER:
5620 case R_PPC64_ADDR16_HIGHERA:
5621 case R_PPC64_ADDR16_HIGHEST:
5622 case R_PPC64_ADDR16_HIGHESTA:
5623 case R_PPC64_ADDR16_LO:
5624 case R_PPC64_ADDR16_LO_DS:
5625 case R_PPC64_ADDR24:
5626 case R_PPC64_ADDR32:
5627 case R_PPC64_UADDR16:
5628 case R_PPC64_UADDR32:
5629 case R_PPC64_UADDR64:
5631 if (h != NULL && !info->shared)
5632 /* We may need a copy reloc. */
5635 /* Don't propagate .opd relocs. */
5636 if (NO_OPD_RELOCS && opd_sym_map != NULL)
5639 /* If we are creating a shared library, and this is a reloc
5640 against a global symbol, or a non PC relative reloc
5641 against a local symbol, then we need to copy the reloc
5642 into the shared library. However, if we are linking with
5643 -Bsymbolic, we do not need to copy a reloc against a
5644 global symbol which is defined in an object we are
5645 including in the link (i.e., DEF_REGULAR is set). At
5646 this point we have not seen all the input files, so it is
5647 possible that DEF_REGULAR is not set now but will be set
5648 later (it is never cleared). In case of a weak definition,
5649 DEF_REGULAR may be cleared later by a strong definition in
5650 a shared library. We account for that possibility below by
5651 storing information in the dyn_relocs field of the hash
5652 table entry. A similar situation occurs when creating
5653 shared libraries and symbol visibility changes render the
5656 If on the other hand, we are creating an executable, we
5657 may need to keep relocations for symbols satisfied by a
5658 dynamic library if we manage to avoid copy relocs for the
5662 && (must_be_dyn_reloc (info, r_type)
5664 && (!SYMBOLIC_BIND (info, h)
5665 || h->root.type == bfd_link_hash_defweak
5666 || !h->def_regular))))
5667 || (ELIMINATE_COPY_RELOCS
5670 && (h->root.type == bfd_link_hash_defweak
5671 || !h->def_regular))
5675 /* We must copy these reloc types into the output file.
5676 Create a reloc section in dynobj and make room for
5680 sreloc = _bfd_elf_make_dynamic_reloc_section
5681 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
5687 /* If this is a global symbol, we count the number of
5688 relocations we need for this symbol. */
5691 struct elf_dyn_relocs *p;
5692 struct elf_dyn_relocs **head;
5694 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
5696 if (p == NULL || p->sec != sec)
5698 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
5708 if (!must_be_dyn_reloc (info, r_type))
5713 /* Track dynamic relocs needed for local syms too.
5714 We really need local syms available to do this
5716 struct ppc_dyn_relocs *p;
5717 struct ppc_dyn_relocs **head;
5718 bfd_boolean is_ifunc;
5721 Elf_Internal_Sym *isym;
5723 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5728 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
5732 vpp = &elf_section_data (s)->local_dynrel;
5733 head = (struct ppc_dyn_relocs **) vpp;
5734 is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
5736 if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
5738 if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
5740 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
5746 p->ifunc = is_ifunc;
5762 /* Merge backend specific data from an object file to the output
5763 object file when linking. */
5766 ppc64_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
5768 unsigned long iflags, oflags;
5770 if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
5773 if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
5776 if (!_bfd_generic_verify_endian_match (ibfd, obfd))
5779 iflags = elf_elfheader (ibfd)->e_flags;
5780 oflags = elf_elfheader (obfd)->e_flags;
5782 if (!elf_flags_init (obfd) || oflags == 0)
5784 elf_flags_init (obfd) = TRUE;
5785 elf_elfheader (obfd)->e_flags = iflags;
5787 else if (iflags == oflags || iflags == 0)
5789 else if (iflags & ~EF_PPC64_ABI)
5791 (*_bfd_error_handler)
5792 (_("%B uses unknown e_flags 0x%lx"), ibfd, iflags);
5793 bfd_set_error (bfd_error_bad_value);
5798 (*_bfd_error_handler)
5799 (_("%B: ABI version %ld is not compatible with ABI version %ld output"),
5800 ibfd, iflags, oflags);
5801 bfd_set_error (bfd_error_bad_value);
5805 /* Merge Tag_compatibility attributes and any common GNU ones. */
5806 _bfd_elf_merge_object_attributes (ibfd, obfd);
5812 ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
5814 /* Print normal ELF private data. */
5815 _bfd_elf_print_private_bfd_data (abfd, ptr);
5817 if (elf_elfheader (abfd)->e_flags != 0)
5821 /* xgettext:c-format */
5822 fprintf (file, _("private flags = 0x%lx:"),
5823 elf_elfheader (abfd)->e_flags);
5825 if ((elf_elfheader (abfd)->e_flags & EF_PPC64_ABI) != 0)
5826 fprintf (file, _(" [abiv%ld]"),
5827 elf_elfheader (abfd)->e_flags & EF_PPC64_ABI);
5834 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5835 of the code entry point, and its section. */
5838 opd_entry_value (asection *opd_sec,
5840 asection **code_sec,
5842 bfd_boolean in_code_sec)
5844 bfd *opd_bfd = opd_sec->owner;
5845 Elf_Internal_Rela *relocs;
5846 Elf_Internal_Rela *lo, *hi, *look;
5849 /* No relocs implies we are linking a --just-symbols object, or looking
5850 at a final linked executable with addr2line or somesuch. */
5851 if (opd_sec->reloc_count == 0)
5853 bfd_byte *contents = ppc64_elf_tdata (opd_bfd)->opd.contents;
5855 if (contents == NULL)
5857 if (!bfd_malloc_and_get_section (opd_bfd, opd_sec, &contents))
5858 return (bfd_vma) -1;
5859 ppc64_elf_tdata (opd_bfd)->opd.contents = contents;
5862 val = bfd_get_64 (opd_bfd, contents + offset);
5863 if (code_sec != NULL)
5865 asection *sec, *likely = NULL;
5871 && val < sec->vma + sec->size)
5877 for (sec = opd_bfd->sections; sec != NULL; sec = sec->next)
5879 && (sec->flags & SEC_LOAD) != 0
5880 && (sec->flags & SEC_ALLOC) != 0)
5885 if (code_off != NULL)
5886 *code_off = val - likely->vma;
5892 BFD_ASSERT (is_ppc64_elf (opd_bfd));
5894 relocs = ppc64_elf_tdata (opd_bfd)->opd.relocs;
5896 relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
5898 /* Go find the opd reloc at the sym address. */
5900 BFD_ASSERT (lo != NULL);
5901 hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
5905 look = lo + (hi - lo) / 2;
5906 if (look->r_offset < offset)
5908 else if (look->r_offset > offset)
5912 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd);
5914 if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64
5915 && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
5917 unsigned long symndx = ELF64_R_SYM (look->r_info);
5920 if (symndx < symtab_hdr->sh_info
5921 || elf_sym_hashes (opd_bfd) == NULL)
5923 Elf_Internal_Sym *sym;
5925 sym = (Elf_Internal_Sym *) symtab_hdr->contents;
5928 size_t symcnt = symtab_hdr->sh_info;
5929 if (elf_sym_hashes (opd_bfd) == NULL)
5930 symcnt = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
5931 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, symcnt,
5932 0, NULL, NULL, NULL);
5935 symtab_hdr->contents = (bfd_byte *) sym;
5939 val = sym->st_value;
5940 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
5941 BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
5945 struct elf_link_hash_entry **sym_hashes;
5946 struct elf_link_hash_entry *rh;
5948 sym_hashes = elf_sym_hashes (opd_bfd);
5949 rh = sym_hashes[symndx - symtab_hdr->sh_info];
5952 rh = elf_follow_link (rh);
5953 BFD_ASSERT (rh->root.type == bfd_link_hash_defined
5954 || rh->root.type == bfd_link_hash_defweak);
5955 val = rh->root.u.def.value;
5956 sec = rh->root.u.def.section;
5960 /* Handle the odd case where we can be called
5961 during bfd_elf_link_add_symbols before the
5962 symbol hashes have been fully populated. */
5963 Elf_Internal_Sym *sym;
5965 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, 1,
5966 symndx, NULL, NULL, NULL);
5970 val = sym->st_value;
5971 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
5975 val += look->r_addend;
5976 if (code_off != NULL)
5978 if (code_sec != NULL)
5980 if (in_code_sec && *code_sec != sec)
5985 if (sec != NULL && sec->output_section != NULL)
5986 val += sec->output_section->vma + sec->output_offset;
5995 /* If the ELF symbol SYM might be a function in SEC, return the
5996 function size and set *CODE_OFF to the function's entry point,
5997 otherwise return zero. */
5999 static bfd_size_type
6000 ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
6005 if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT
6006 | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0)
6010 if (!(sym->flags & BSF_SYNTHETIC))
6011 size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
6013 if (strcmp (sym->section->name, ".opd") == 0)
6015 if (opd_entry_value (sym->section, sym->value,
6016 &sec, code_off, TRUE) == (bfd_vma) -1)
6018 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6019 symbol. This size has nothing to do with the code size of the
6020 function, which is what we're supposed to return, but the
6021 code size isn't available without looking up the dot-sym.
6022 However, doing that would be a waste of time particularly
6023 since elf_find_function will look at the dot-sym anyway.
6024 Now, elf_find_function will keep the largest size of any
6025 function sym found at the code address of interest, so return
6026 1 here to avoid it incorrectly caching a larger function size
6027 for a small function. This does mean we return the wrong
6028 size for a new-ABI function of size 24, but all that does is
6029 disable caching for such functions. */
6035 if (sym->section != sec)
6037 *code_off = sym->value;
6044 /* Return true if symbol is defined in a regular object file. */
6047 is_static_defined (struct elf_link_hash_entry *h)
6049 return ((h->root.type == bfd_link_hash_defined
6050 || h->root.type == bfd_link_hash_defweak)
6051 && h->root.u.def.section != NULL
6052 && h->root.u.def.section->output_section != NULL);
6055 /* If FDH is a function descriptor symbol, return the associated code
6056 entry symbol if it is defined. Return NULL otherwise. */
6058 static struct ppc_link_hash_entry *
6059 defined_code_entry (struct ppc_link_hash_entry *fdh)
6061 if (fdh->is_func_descriptor)
6063 struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh);
6064 if (fh->elf.root.type == bfd_link_hash_defined
6065 || fh->elf.root.type == bfd_link_hash_defweak)
6071 /* If FH is a function code entry symbol, return the associated
6072 function descriptor symbol if it is defined. Return NULL otherwise. */
6074 static struct ppc_link_hash_entry *
6075 defined_func_desc (struct ppc_link_hash_entry *fh)
6078 && fh->oh->is_func_descriptor)
6080 struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh);
6081 if (fdh->elf.root.type == bfd_link_hash_defined
6082 || fdh->elf.root.type == bfd_link_hash_defweak)
6088 /* Mark all our entry sym sections, both opd and code section. */
6091 ppc64_elf_gc_keep (struct bfd_link_info *info)
6093 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6094 struct bfd_sym_chain *sym;
6099 for (sym = info->gc_sym_list; sym != NULL; sym = sym->next)
6101 struct ppc_link_hash_entry *eh, *fh;
6104 eh = (struct ppc_link_hash_entry *)
6105 elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
6108 if (eh->elf.root.type != bfd_link_hash_defined
6109 && eh->elf.root.type != bfd_link_hash_defweak)
6112 fh = defined_code_entry (eh);
6115 sec = fh->elf.root.u.def.section;
6116 sec->flags |= SEC_KEEP;
6118 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6119 && opd_entry_value (eh->elf.root.u.def.section,
6120 eh->elf.root.u.def.value,
6121 &sec, NULL, FALSE) != (bfd_vma) -1)
6122 sec->flags |= SEC_KEEP;
6124 sec = eh->elf.root.u.def.section;
6125 sec->flags |= SEC_KEEP;
6129 /* Mark sections containing dynamically referenced symbols. When
6130 building shared libraries, we must assume that any visible symbol is
6134 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
6136 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6137 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
6138 struct ppc_link_hash_entry *fdh;
6140 /* Dynamic linking info is on the func descriptor sym. */
6141 fdh = defined_func_desc (eh);
6145 if ((eh->elf.root.type == bfd_link_hash_defined
6146 || eh->elf.root.type == bfd_link_hash_defweak)
6147 && (eh->elf.ref_dynamic
6148 || (!info->executable
6149 && eh->elf.def_regular
6150 && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
6151 && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN
6152 && (strchr (eh->elf.root.root.string, ELF_VER_CHR) != NULL
6153 || !bfd_hide_sym_by_version (info->version_info,
6154 eh->elf.root.root.string)))))
6157 struct ppc_link_hash_entry *fh;
6159 eh->elf.root.u.def.section->flags |= SEC_KEEP;
6161 /* Function descriptor syms cause the associated
6162 function code sym section to be marked. */
6163 fh = defined_code_entry (eh);
6166 code_sec = fh->elf.root.u.def.section;
6167 code_sec->flags |= SEC_KEEP;
6169 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6170 && opd_entry_value (eh->elf.root.u.def.section,
6171 eh->elf.root.u.def.value,
6172 &code_sec, NULL, FALSE) != (bfd_vma) -1)
6173 code_sec->flags |= SEC_KEEP;
6179 /* Return the section that should be marked against GC for a given
6183 ppc64_elf_gc_mark_hook (asection *sec,
6184 struct bfd_link_info *info,
6185 Elf_Internal_Rela *rel,
6186 struct elf_link_hash_entry *h,
6187 Elf_Internal_Sym *sym)
6191 /* Syms return NULL if we're marking .opd, so we avoid marking all
6192 function sections, as all functions are referenced in .opd. */
6194 if (get_opd_info (sec) != NULL)
6199 enum elf_ppc64_reloc_type r_type;
6200 struct ppc_link_hash_entry *eh, *fh, *fdh;
6202 r_type = ELF64_R_TYPE (rel->r_info);
6205 case R_PPC64_GNU_VTINHERIT:
6206 case R_PPC64_GNU_VTENTRY:
6210 switch (h->root.type)
6212 case bfd_link_hash_defined:
6213 case bfd_link_hash_defweak:
6214 eh = (struct ppc_link_hash_entry *) h;
6215 fdh = defined_func_desc (eh);
6219 /* Function descriptor syms cause the associated
6220 function code sym section to be marked. */
6221 fh = defined_code_entry (eh);
6224 /* They also mark their opd section. */
6225 eh->elf.root.u.def.section->gc_mark = 1;
6227 rsec = fh->elf.root.u.def.section;
6229 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6230 && opd_entry_value (eh->elf.root.u.def.section,
6231 eh->elf.root.u.def.value,
6232 &rsec, NULL, FALSE) != (bfd_vma) -1)
6233 eh->elf.root.u.def.section->gc_mark = 1;
6235 rsec = h->root.u.def.section;
6238 case bfd_link_hash_common:
6239 rsec = h->root.u.c.p->section;
6243 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
6249 struct _opd_sec_data *opd;
6251 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
6252 opd = get_opd_info (rsec);
6253 if (opd != NULL && opd->func_sec != NULL)
6257 rsec = opd->func_sec[(sym->st_value + rel->r_addend) / 8];
6264 /* Update the .got, .plt. and dynamic reloc reference counts for the
6265 section being removed. */
6268 ppc64_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
6269 asection *sec, const Elf_Internal_Rela *relocs)
6271 struct ppc_link_hash_table *htab;
6272 Elf_Internal_Shdr *symtab_hdr;
6273 struct elf_link_hash_entry **sym_hashes;
6274 struct got_entry **local_got_ents;
6275 const Elf_Internal_Rela *rel, *relend;
6277 if (info->relocatable)
6280 if ((sec->flags & SEC_ALLOC) == 0)
6283 elf_section_data (sec)->local_dynrel = NULL;
6285 htab = ppc_hash_table (info);
6289 symtab_hdr = &elf_symtab_hdr (abfd);
6290 sym_hashes = elf_sym_hashes (abfd);
6291 local_got_ents = elf_local_got_ents (abfd);
6293 relend = relocs + sec->reloc_count;
6294 for (rel = relocs; rel < relend; rel++)
6296 unsigned long r_symndx;
6297 enum elf_ppc64_reloc_type r_type;
6298 struct elf_link_hash_entry *h = NULL;
6299 unsigned char tls_type = 0;
6301 r_symndx = ELF64_R_SYM (rel->r_info);
6302 r_type = ELF64_R_TYPE (rel->r_info);
6303 if (r_symndx >= symtab_hdr->sh_info)
6305 struct ppc_link_hash_entry *eh;
6306 struct elf_dyn_relocs **pp;
6307 struct elf_dyn_relocs *p;
6309 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6310 h = elf_follow_link (h);
6311 eh = (struct ppc_link_hash_entry *) h;
6313 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
6316 /* Everything must go for SEC. */
6322 if (is_branch_reloc (r_type))
6324 struct plt_entry **ifunc = NULL;
6327 if (h->type == STT_GNU_IFUNC)
6328 ifunc = &h->plt.plist;
6330 else if (local_got_ents != NULL)
6332 struct plt_entry **local_plt = (struct plt_entry **)
6333 (local_got_ents + symtab_hdr->sh_info);
6334 unsigned char *local_got_tls_masks = (unsigned char *)
6335 (local_plt + symtab_hdr->sh_info);
6336 if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
6337 ifunc = local_plt + r_symndx;
6341 struct plt_entry *ent;
6343 for (ent = *ifunc; ent != NULL; ent = ent->next)
6344 if (ent->addend == rel->r_addend)
6348 if (ent->plt.refcount > 0)
6349 ent->plt.refcount -= 1;
6356 case R_PPC64_GOT_TLSLD16:
6357 case R_PPC64_GOT_TLSLD16_LO:
6358 case R_PPC64_GOT_TLSLD16_HI:
6359 case R_PPC64_GOT_TLSLD16_HA:
6360 tls_type = TLS_TLS | TLS_LD;
6363 case R_PPC64_GOT_TLSGD16:
6364 case R_PPC64_GOT_TLSGD16_LO:
6365 case R_PPC64_GOT_TLSGD16_HI:
6366 case R_PPC64_GOT_TLSGD16_HA:
6367 tls_type = TLS_TLS | TLS_GD;
6370 case R_PPC64_GOT_TPREL16_DS:
6371 case R_PPC64_GOT_TPREL16_LO_DS:
6372 case R_PPC64_GOT_TPREL16_HI:
6373 case R_PPC64_GOT_TPREL16_HA:
6374 tls_type = TLS_TLS | TLS_TPREL;
6377 case R_PPC64_GOT_DTPREL16_DS:
6378 case R_PPC64_GOT_DTPREL16_LO_DS:
6379 case R_PPC64_GOT_DTPREL16_HI:
6380 case R_PPC64_GOT_DTPREL16_HA:
6381 tls_type = TLS_TLS | TLS_DTPREL;
6385 case R_PPC64_GOT16_DS:
6386 case R_PPC64_GOT16_HA:
6387 case R_PPC64_GOT16_HI:
6388 case R_PPC64_GOT16_LO:
6389 case R_PPC64_GOT16_LO_DS:
6392 struct got_entry *ent;
6397 ent = local_got_ents[r_symndx];
6399 for (; ent != NULL; ent = ent->next)
6400 if (ent->addend == rel->r_addend
6401 && ent->owner == abfd
6402 && ent->tls_type == tls_type)
6406 if (ent->got.refcount > 0)
6407 ent->got.refcount -= 1;
6411 case R_PPC64_PLT16_HA:
6412 case R_PPC64_PLT16_HI:
6413 case R_PPC64_PLT16_LO:
6417 case R_PPC64_REL14_BRNTAKEN:
6418 case R_PPC64_REL14_BRTAKEN:
6422 struct plt_entry *ent;
6424 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
6425 if (ent->addend == rel->r_addend)
6427 if (ent != NULL && ent->plt.refcount > 0)
6428 ent->plt.refcount -= 1;
6439 /* The maximum size of .sfpr. */
6440 #define SFPR_MAX (218*4)
6442 struct sfpr_def_parms
6444 const char name[12];
6445 unsigned char lo, hi;
6446 bfd_byte * (*write_ent) (bfd *, bfd_byte *, int);
6447 bfd_byte * (*write_tail) (bfd *, bfd_byte *, int);
6450 /* Auto-generate _save*, _rest* functions in .sfpr. */
6453 sfpr_define (struct bfd_link_info *info, const struct sfpr_def_parms *parm)
6455 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6457 size_t len = strlen (parm->name);
6458 bfd_boolean writing = FALSE;
6464 memcpy (sym, parm->name, len);
6467 for (i = parm->lo; i <= parm->hi; i++)
6469 struct elf_link_hash_entry *h;
6471 sym[len + 0] = i / 10 + '0';
6472 sym[len + 1] = i % 10 + '0';
6473 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
6477 h->root.type = bfd_link_hash_defined;
6478 h->root.u.def.section = htab->sfpr;
6479 h->root.u.def.value = htab->sfpr->size;
6482 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
6484 if (htab->sfpr->contents == NULL)
6486 htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
6487 if (htab->sfpr->contents == NULL)
6493 bfd_byte *p = htab->sfpr->contents + htab->sfpr->size;
6495 p = (*parm->write_ent) (htab->elf.dynobj, p, i);
6497 p = (*parm->write_tail) (htab->elf.dynobj, p, i);
6498 htab->sfpr->size = p - htab->sfpr->contents;
6506 savegpr0 (bfd *abfd, bfd_byte *p, int r)
6508 bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6513 savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
6515 p = savegpr0 (abfd, p, r);
6516 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6518 bfd_put_32 (abfd, BLR, p);
6523 restgpr0 (bfd *abfd, bfd_byte *p, int r)
6525 bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6530 restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
6532 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6534 p = restgpr0 (abfd, p, r);
6535 bfd_put_32 (abfd, MTLR_R0, p);
6539 p = restgpr0 (abfd, p, 30);
6540 p = restgpr0 (abfd, p, 31);
6542 bfd_put_32 (abfd, BLR, p);
6547 savegpr1 (bfd *abfd, bfd_byte *p, int r)
6549 bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6554 savegpr1_tail (bfd *abfd, bfd_byte *p, int r)
6556 p = savegpr1 (abfd, p, r);
6557 bfd_put_32 (abfd, BLR, p);
6562 restgpr1 (bfd *abfd, bfd_byte *p, int r)
6564 bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6569 restgpr1_tail (bfd *abfd, bfd_byte *p, int r)
6571 p = restgpr1 (abfd, p, r);
6572 bfd_put_32 (abfd, BLR, p);
6577 savefpr (bfd *abfd, bfd_byte *p, int r)
6579 bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6584 savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
6586 p = savefpr (abfd, p, r);
6587 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6589 bfd_put_32 (abfd, BLR, p);
6594 restfpr (bfd *abfd, bfd_byte *p, int r)
6596 bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6601 restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
6603 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6605 p = restfpr (abfd, p, r);
6606 bfd_put_32 (abfd, MTLR_R0, p);
6610 p = restfpr (abfd, p, 30);
6611 p = restfpr (abfd, p, 31);
6613 bfd_put_32 (abfd, BLR, p);
6618 savefpr1_tail (bfd *abfd, bfd_byte *p, int r)
6620 p = savefpr (abfd, p, r);
6621 bfd_put_32 (abfd, BLR, p);
6626 restfpr1_tail (bfd *abfd, bfd_byte *p, int r)
6628 p = restfpr (abfd, p, r);
6629 bfd_put_32 (abfd, BLR, p);
6634 savevr (bfd *abfd, bfd_byte *p, int r)
6636 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6638 bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p);
6643 savevr_tail (bfd *abfd, bfd_byte *p, int r)
6645 p = savevr (abfd, p, r);
6646 bfd_put_32 (abfd, BLR, p);
6651 restvr (bfd *abfd, bfd_byte *p, int r)
6653 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6655 bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p);
6660 restvr_tail (bfd *abfd, bfd_byte *p, int r)
6662 p = restvr (abfd, p, r);
6663 bfd_put_32 (abfd, BLR, p);
6667 /* Called via elf_link_hash_traverse to transfer dynamic linking
6668 information on function code symbol entries to their corresponding
6669 function descriptor symbol entries. */
6672 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
6674 struct bfd_link_info *info;
6675 struct ppc_link_hash_table *htab;
6676 struct plt_entry *ent;
6677 struct ppc_link_hash_entry *fh;
6678 struct ppc_link_hash_entry *fdh;
6679 bfd_boolean force_local;
6681 fh = (struct ppc_link_hash_entry *) h;
6682 if (fh->elf.root.type == bfd_link_hash_indirect)
6686 htab = ppc_hash_table (info);
6690 /* Resolve undefined references to dot-symbols as the value
6691 in the function descriptor, if we have one in a regular object.
6692 This is to satisfy cases like ".quad .foo". Calls to functions
6693 in dynamic objects are handled elsewhere. */
6694 if (fh->elf.root.type == bfd_link_hash_undefweak
6695 && fh->was_undefined
6696 && (fdh = defined_func_desc (fh)) != NULL
6697 && get_opd_info (fdh->elf.root.u.def.section) != NULL
6698 && opd_entry_value (fdh->elf.root.u.def.section,
6699 fdh->elf.root.u.def.value,
6700 &fh->elf.root.u.def.section,
6701 &fh->elf.root.u.def.value, FALSE) != (bfd_vma) -1)
6703 fh->elf.root.type = fdh->elf.root.type;
6704 fh->elf.forced_local = 1;
6705 fh->elf.def_regular = fdh->elf.def_regular;
6706 fh->elf.def_dynamic = fdh->elf.def_dynamic;
6709 /* If this is a function code symbol, transfer dynamic linking
6710 information to the function descriptor symbol. */
6714 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
6715 if (ent->plt.refcount > 0)
6718 || fh->elf.root.root.string[0] != '.'
6719 || fh->elf.root.root.string[1] == '\0')
6722 /* Find the corresponding function descriptor symbol. Create it
6723 as undefined if necessary. */
6725 fdh = lookup_fdh (fh, htab);
6727 && !info->executable
6728 && (fh->elf.root.type == bfd_link_hash_undefined
6729 || fh->elf.root.type == bfd_link_hash_undefweak))
6731 fdh = make_fdh (info, fh);
6736 /* Fake function descriptors are made undefweak. If the function
6737 code symbol is strong undefined, make the fake sym the same.
6738 If the function code symbol is defined, then force the fake
6739 descriptor local; We can't support overriding of symbols in a
6740 shared library on a fake descriptor. */
6744 && fdh->elf.root.type == bfd_link_hash_undefweak)
6746 if (fh->elf.root.type == bfd_link_hash_undefined)
6748 fdh->elf.root.type = bfd_link_hash_undefined;
6749 bfd_link_add_undef (&htab->elf.root, &fdh->elf.root);
6751 else if (fh->elf.root.type == bfd_link_hash_defined
6752 || fh->elf.root.type == bfd_link_hash_defweak)
6754 _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
6759 && !fdh->elf.forced_local
6760 && (!info->executable
6761 || fdh->elf.def_dynamic
6762 || fdh->elf.ref_dynamic
6763 || (fdh->elf.root.type == bfd_link_hash_undefweak
6764 && ELF_ST_VISIBILITY (fdh->elf.other) == STV_DEFAULT)))
6766 if (fdh->elf.dynindx == -1)
6767 if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
6769 fdh->elf.ref_regular |= fh->elf.ref_regular;
6770 fdh->elf.ref_dynamic |= fh->elf.ref_dynamic;
6771 fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak;
6772 fdh->elf.non_got_ref |= fh->elf.non_got_ref;
6773 if (ELF_ST_VISIBILITY (fh->elf.other) == STV_DEFAULT)
6775 move_plt_plist (fh, fdh);
6776 fdh->elf.needs_plt = 1;
6778 fdh->is_func_descriptor = 1;
6783 /* Now that the info is on the function descriptor, clear the
6784 function code sym info. Any function code syms for which we
6785 don't have a definition in a regular file, we force local.
6786 This prevents a shared library from exporting syms that have
6787 been imported from another library. Function code syms that
6788 are really in the library we must leave global to prevent the
6789 linker dragging in a definition from a static library. */
6790 force_local = (!fh->elf.def_regular
6792 || !fdh->elf.def_regular
6793 || fdh->elf.forced_local);
6794 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
6799 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6800 this hook to a) provide some gcc support functions, and b) transfer
6801 dynamic linking information gathered so far on function code symbol
6802 entries, to their corresponding function descriptor symbol entries. */
6805 ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
6806 struct bfd_link_info *info)
6808 struct ppc_link_hash_table *htab;
6810 static const struct sfpr_def_parms funcs[] =
6812 { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail },
6813 { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail },
6814 { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail },
6815 { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail },
6816 { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail },
6817 { "_savefpr_", 14, 31, savefpr, savefpr0_tail },
6818 { "_restfpr_", 14, 29, restfpr, restfpr0_tail },
6819 { "_restfpr_", 30, 31, restfpr, restfpr0_tail },
6820 { "._savef", 14, 31, savefpr, savefpr1_tail },
6821 { "._restf", 14, 31, restfpr, restfpr1_tail },
6822 { "_savevr_", 20, 31, savevr, savevr_tail },
6823 { "_restvr_", 20, 31, restvr, restvr_tail }
6826 htab = ppc_hash_table (info);
6830 if (!info->relocatable
6831 && htab->elf.hgot != NULL)
6832 _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
6834 if (htab->sfpr == NULL)
6835 /* We don't have any relocs. */
6838 /* Provide any missing _save* and _rest* functions. */
6839 htab->sfpr->size = 0;
6840 if (!info->relocatable)
6841 for (i = 0; i < sizeof (funcs) / sizeof (funcs[0]); i++)
6842 if (!sfpr_define (info, &funcs[i]))
6845 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
6847 if (htab->sfpr->size == 0)
6848 htab->sfpr->flags |= SEC_EXCLUDE;
6853 /* Adjust a symbol defined by a dynamic object and referenced by a
6854 regular object. The current definition is in some section of the
6855 dynamic object, but we're not including those sections. We have to
6856 change the definition to something the rest of the link can
6860 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
6861 struct elf_link_hash_entry *h)
6863 struct ppc_link_hash_table *htab;
6866 htab = ppc_hash_table (info);
6870 /* Deal with function syms. */
6871 if (h->type == STT_FUNC
6872 || h->type == STT_GNU_IFUNC
6875 /* Clear procedure linkage table information for any symbol that
6876 won't need a .plt entry. */
6877 struct plt_entry *ent;
6878 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
6879 if (ent->plt.refcount > 0)
6882 || (h->type != STT_GNU_IFUNC
6883 && (SYMBOL_CALLS_LOCAL (info, h)
6884 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6885 && h->root.type == bfd_link_hash_undefweak))))
6887 h->plt.plist = NULL;
6892 h->plt.plist = NULL;
6894 /* If this is a weak symbol, and there is a real definition, the
6895 processor independent code will have arranged for us to see the
6896 real definition first, and we can just use the same value. */
6897 if (h->u.weakdef != NULL)
6899 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6900 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6901 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6902 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6903 if (ELIMINATE_COPY_RELOCS)
6904 h->non_got_ref = h->u.weakdef->non_got_ref;
6908 /* If we are creating a shared library, we must presume that the
6909 only references to the symbol are via the global offset table.
6910 For such cases we need not do anything here; the relocations will
6911 be handled correctly by relocate_section. */
6915 /* If there are no references to this symbol that do not use the
6916 GOT, we don't need to generate a copy reloc. */
6917 if (!h->non_got_ref)
6920 /* Don't generate a copy reloc for symbols defined in the executable. */
6921 if (!h->def_dynamic || !h->ref_regular || h->def_regular)
6924 if (ELIMINATE_COPY_RELOCS)
6926 struct ppc_link_hash_entry * eh;
6927 struct elf_dyn_relocs *p;
6929 eh = (struct ppc_link_hash_entry *) h;
6930 for (p = eh->dyn_relocs; p != NULL; p = p->next)
6932 s = p->sec->output_section;
6933 if (s != NULL && (s->flags & SEC_READONLY) != 0)
6937 /* If we didn't find any dynamic relocs in read-only sections, then
6938 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6946 if (h->plt.plist != NULL)
6948 /* We should never get here, but unfortunately there are versions
6949 of gcc out there that improperly (for this ABI) put initialized
6950 function pointers, vtable refs and suchlike in read-only
6951 sections. Allow them to proceed, but warn that this might
6952 break at runtime. */
6953 info->callbacks->einfo
6954 (_("%P: copy reloc against `%T' requires lazy plt linking; "
6955 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6956 h->root.root.string);
6959 /* This is a reference to a symbol defined by a dynamic object which
6960 is not a function. */
6962 /* We must allocate the symbol in our .dynbss section, which will
6963 become part of the .bss section of the executable. There will be
6964 an entry for this symbol in the .dynsym section. The dynamic
6965 object will contain position independent code, so all references
6966 from the dynamic object to this symbol will go through the global
6967 offset table. The dynamic linker will use the .dynsym entry to
6968 determine the address it must put in the global offset table, so
6969 both the dynamic object and the regular object will refer to the
6970 same memory location for the variable. */
6972 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
6973 to copy the initial value out of the dynamic object and into the
6974 runtime process image. We need to remember the offset into the
6975 .rela.bss section we are going to use. */
6976 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
6978 htab->relbss->size += sizeof (Elf64_External_Rela);
6984 return _bfd_elf_adjust_dynamic_copy (h, s);
6987 /* If given a function descriptor symbol, hide both the function code
6988 sym and the descriptor. */
6990 ppc64_elf_hide_symbol (struct bfd_link_info *info,
6991 struct elf_link_hash_entry *h,
6992 bfd_boolean force_local)
6994 struct ppc_link_hash_entry *eh;
6995 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
6997 eh = (struct ppc_link_hash_entry *) h;
6998 if (eh->is_func_descriptor)
7000 struct ppc_link_hash_entry *fh = eh->oh;
7005 struct ppc_link_hash_table *htab;
7008 /* We aren't supposed to use alloca in BFD because on
7009 systems which do not have alloca the version in libiberty
7010 calls xmalloc, which might cause the program to crash
7011 when it runs out of memory. This function doesn't have a
7012 return status, so there's no way to gracefully return an
7013 error. So cheat. We know that string[-1] can be safely
7014 accessed; It's either a string in an ELF string table,
7015 or allocated in an objalloc structure. */
7017 p = eh->elf.root.root.string - 1;
7020 htab = ppc_hash_table (info);
7024 fh = (struct ppc_link_hash_entry *)
7025 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
7028 /* Unfortunately, if it so happens that the string we were
7029 looking for was allocated immediately before this string,
7030 then we overwrote the string terminator. That's the only
7031 reason the lookup should fail. */
7034 q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
7035 while (q >= eh->elf.root.root.string && *q == *p)
7037 if (q < eh->elf.root.root.string && *p == '.')
7038 fh = (struct ppc_link_hash_entry *)
7039 elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
7048 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
7053 get_sym_h (struct elf_link_hash_entry **hp,
7054 Elf_Internal_Sym **symp,
7056 unsigned char **tls_maskp,
7057 Elf_Internal_Sym **locsymsp,
7058 unsigned long r_symndx,
7061 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
7063 if (r_symndx >= symtab_hdr->sh_info)
7065 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
7066 struct elf_link_hash_entry *h;
7068 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7069 h = elf_follow_link (h);
7077 if (symsecp != NULL)
7079 asection *symsec = NULL;
7080 if (h->root.type == bfd_link_hash_defined
7081 || h->root.type == bfd_link_hash_defweak)
7082 symsec = h->root.u.def.section;
7086 if (tls_maskp != NULL)
7088 struct ppc_link_hash_entry *eh;
7090 eh = (struct ppc_link_hash_entry *) h;
7091 *tls_maskp = &eh->tls_mask;
7096 Elf_Internal_Sym *sym;
7097 Elf_Internal_Sym *locsyms = *locsymsp;
7099 if (locsyms == NULL)
7101 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
7102 if (locsyms == NULL)
7103 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
7104 symtab_hdr->sh_info,
7105 0, NULL, NULL, NULL);
7106 if (locsyms == NULL)
7108 *locsymsp = locsyms;
7110 sym = locsyms + r_symndx;
7118 if (symsecp != NULL)
7119 *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx);
7121 if (tls_maskp != NULL)
7123 struct got_entry **lgot_ents;
7124 unsigned char *tls_mask;
7127 lgot_ents = elf_local_got_ents (ibfd);
7128 if (lgot_ents != NULL)
7130 struct plt_entry **local_plt = (struct plt_entry **)
7131 (lgot_ents + symtab_hdr->sh_info);
7132 unsigned char *lgot_masks = (unsigned char *)
7133 (local_plt + symtab_hdr->sh_info);
7134 tls_mask = &lgot_masks[r_symndx];
7136 *tls_maskp = tls_mask;
7142 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7143 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7144 type suitable for optimization, and 1 otherwise. */
7147 get_tls_mask (unsigned char **tls_maskp,
7148 unsigned long *toc_symndx,
7149 bfd_vma *toc_addend,
7150 Elf_Internal_Sym **locsymsp,
7151 const Elf_Internal_Rela *rel,
7154 unsigned long r_symndx;
7156 struct elf_link_hash_entry *h;
7157 Elf_Internal_Sym *sym;
7161 r_symndx = ELF64_R_SYM (rel->r_info);
7162 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7165 if ((*tls_maskp != NULL && **tls_maskp != 0)
7167 || ppc64_elf_section_data (sec) == NULL
7168 || ppc64_elf_section_data (sec)->sec_type != sec_toc)
7171 /* Look inside a TOC section too. */
7174 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
7175 off = h->root.u.def.value;
7178 off = sym->st_value;
7179 off += rel->r_addend;
7180 BFD_ASSERT (off % 8 == 0);
7181 r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8];
7182 next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1];
7183 if (toc_symndx != NULL)
7184 *toc_symndx = r_symndx;
7185 if (toc_addend != NULL)
7186 *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8];
7187 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7189 if ((h == NULL || is_static_defined (h))
7190 && (next_r == -1 || next_r == -2))
7195 /* Find (or create) an entry in the tocsave hash table. */
7197 static struct tocsave_entry *
7198 tocsave_find (struct ppc_link_hash_table *htab,
7199 enum insert_option insert,
7200 Elf_Internal_Sym **local_syms,
7201 const Elf_Internal_Rela *irela,
7204 unsigned long r_indx;
7205 struct elf_link_hash_entry *h;
7206 Elf_Internal_Sym *sym;
7207 struct tocsave_entry ent, *p;
7209 struct tocsave_entry **slot;
7211 r_indx = ELF64_R_SYM (irela->r_info);
7212 if (!get_sym_h (&h, &sym, &ent.sec, NULL, local_syms, r_indx, ibfd))
7214 if (ent.sec == NULL || ent.sec->output_section == NULL)
7216 (*_bfd_error_handler)
7217 (_("%B: undefined symbol on R_PPC64_TOCSAVE relocation"));
7222 ent.offset = h->root.u.def.value;
7224 ent.offset = sym->st_value;
7225 ent.offset += irela->r_addend;
7227 hash = tocsave_htab_hash (&ent);
7228 slot = ((struct tocsave_entry **)
7229 htab_find_slot_with_hash (htab->tocsave_htab, &ent, hash, insert));
7235 p = (struct tocsave_entry *) bfd_alloc (ibfd, sizeof (*p));
7244 /* Adjust all global syms defined in opd sections. In gcc generated
7245 code for the old ABI, these will already have been done. */
7248 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
7250 struct ppc_link_hash_entry *eh;
7252 struct _opd_sec_data *opd;
7254 if (h->root.type == bfd_link_hash_indirect)
7257 if (h->root.type != bfd_link_hash_defined
7258 && h->root.type != bfd_link_hash_defweak)
7261 eh = (struct ppc_link_hash_entry *) h;
7262 if (eh->adjust_done)
7265 sym_sec = eh->elf.root.u.def.section;
7266 opd = get_opd_info (sym_sec);
7267 if (opd != NULL && opd->adjust != NULL)
7269 long adjust = opd->adjust[eh->elf.root.u.def.value / 8];
7272 /* This entry has been deleted. */
7273 asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section;
7276 for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next)
7277 if (discarded_section (dsec))
7279 ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec;
7283 eh->elf.root.u.def.value = 0;
7284 eh->elf.root.u.def.section = dsec;
7287 eh->elf.root.u.def.value += adjust;
7288 eh->adjust_done = 1;
7293 /* Handles decrementing dynamic reloc counts for the reloc specified by
7294 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7295 have already been determined. */
7298 dec_dynrel_count (bfd_vma r_info,
7300 struct bfd_link_info *info,
7301 Elf_Internal_Sym **local_syms,
7302 struct elf_link_hash_entry *h,
7303 Elf_Internal_Sym *sym)
7305 enum elf_ppc64_reloc_type r_type;
7306 asection *sym_sec = NULL;
7308 /* Can this reloc be dynamic? This switch, and later tests here
7309 should be kept in sync with the code in check_relocs. */
7310 r_type = ELF64_R_TYPE (r_info);
7316 case R_PPC64_TPREL16:
7317 case R_PPC64_TPREL16_LO:
7318 case R_PPC64_TPREL16_HI:
7319 case R_PPC64_TPREL16_HA:
7320 case R_PPC64_TPREL16_DS:
7321 case R_PPC64_TPREL16_LO_DS:
7322 case R_PPC64_TPREL16_HIGH:
7323 case R_PPC64_TPREL16_HIGHA:
7324 case R_PPC64_TPREL16_HIGHER:
7325 case R_PPC64_TPREL16_HIGHERA:
7326 case R_PPC64_TPREL16_HIGHEST:
7327 case R_PPC64_TPREL16_HIGHESTA:
7331 case R_PPC64_TPREL64:
7332 case R_PPC64_DTPMOD64:
7333 case R_PPC64_DTPREL64:
7334 case R_PPC64_ADDR64:
7338 case R_PPC64_ADDR14:
7339 case R_PPC64_ADDR14_BRNTAKEN:
7340 case R_PPC64_ADDR14_BRTAKEN:
7341 case R_PPC64_ADDR16:
7342 case R_PPC64_ADDR16_DS:
7343 case R_PPC64_ADDR16_HA:
7344 case R_PPC64_ADDR16_HI:
7345 case R_PPC64_ADDR16_HIGH:
7346 case R_PPC64_ADDR16_HIGHA:
7347 case R_PPC64_ADDR16_HIGHER:
7348 case R_PPC64_ADDR16_HIGHERA:
7349 case R_PPC64_ADDR16_HIGHEST:
7350 case R_PPC64_ADDR16_HIGHESTA:
7351 case R_PPC64_ADDR16_LO:
7352 case R_PPC64_ADDR16_LO_DS:
7353 case R_PPC64_ADDR24:
7354 case R_PPC64_ADDR32:
7355 case R_PPC64_UADDR16:
7356 case R_PPC64_UADDR32:
7357 case R_PPC64_UADDR64:
7362 if (local_syms != NULL)
7364 unsigned long r_symndx;
7365 bfd *ibfd = sec->owner;
7367 r_symndx = ELF64_R_SYM (r_info);
7368 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
7373 && (must_be_dyn_reloc (info, r_type)
7375 && (!SYMBOLIC_BIND (info, h)
7376 || h->root.type == bfd_link_hash_defweak
7377 || !h->def_regular))))
7378 || (ELIMINATE_COPY_RELOCS
7381 && (h->root.type == bfd_link_hash_defweak
7382 || !h->def_regular)))
7389 struct elf_dyn_relocs *p;
7390 struct elf_dyn_relocs **pp;
7391 pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
7393 /* elf_gc_sweep may have already removed all dyn relocs associated
7394 with local syms for a given section. Also, symbol flags are
7395 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7396 report a dynreloc miscount. */
7397 if (*pp == NULL && info->gc_sections)
7400 while ((p = *pp) != NULL)
7404 if (!must_be_dyn_reloc (info, r_type))
7416 struct ppc_dyn_relocs *p;
7417 struct ppc_dyn_relocs **pp;
7419 bfd_boolean is_ifunc;
7421 if (local_syms == NULL)
7422 sym_sec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
7423 if (sym_sec == NULL)
7426 vpp = &elf_section_data (sym_sec)->local_dynrel;
7427 pp = (struct ppc_dyn_relocs **) vpp;
7429 if (*pp == NULL && info->gc_sections)
7432 is_ifunc = ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC;
7433 while ((p = *pp) != NULL)
7435 if (p->sec == sec && p->ifunc == is_ifunc)
7446 info->callbacks->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
7448 bfd_set_error (bfd_error_bad_value);
7452 /* Remove unused Official Procedure Descriptor entries. Currently we
7453 only remove those associated with functions in discarded link-once
7454 sections, or weakly defined functions that have been overridden. It
7455 would be possible to remove many more entries for statically linked
7459 ppc64_elf_edit_opd (struct bfd_link_info *info, bfd_boolean non_overlapping)
7462 bfd_boolean some_edited = FALSE;
7463 asection *need_pad = NULL;
7465 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
7468 Elf_Internal_Rela *relstart, *rel, *relend;
7469 Elf_Internal_Shdr *symtab_hdr;
7470 Elf_Internal_Sym *local_syms;
7472 struct _opd_sec_data *opd;
7473 bfd_boolean need_edit, add_aux_fields;
7474 bfd_size_type cnt_16b = 0;
7476 if (!is_ppc64_elf (ibfd))
7479 sec = bfd_get_section_by_name (ibfd, ".opd");
7480 if (sec == NULL || sec->size == 0)
7483 if (sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
7486 if (sec->output_section == bfd_abs_section_ptr)
7489 /* Look through the section relocs. */
7490 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
7494 symtab_hdr = &elf_symtab_hdr (ibfd);
7496 /* Read the relocations. */
7497 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
7499 if (relstart == NULL)
7502 /* First run through the relocs to check they are sane, and to
7503 determine whether we need to edit this opd section. */
7507 relend = relstart + sec->reloc_count;
7508 for (rel = relstart; rel < relend; )
7510 enum elf_ppc64_reloc_type r_type;
7511 unsigned long r_symndx;
7513 struct elf_link_hash_entry *h;
7514 Elf_Internal_Sym *sym;
7516 /* .opd contains a regular array of 16 or 24 byte entries. We're
7517 only interested in the reloc pointing to a function entry
7519 if (rel->r_offset != offset
7520 || rel + 1 >= relend
7521 || (rel + 1)->r_offset != offset + 8)
7523 /* If someone messes with .opd alignment then after a
7524 "ld -r" we might have padding in the middle of .opd.
7525 Also, there's nothing to prevent someone putting
7526 something silly in .opd with the assembler. No .opd
7527 optimization for them! */
7529 (*_bfd_error_handler)
7530 (_("%B: .opd is not a regular array of opd entries"), ibfd);
7535 if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
7536 || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
7538 (*_bfd_error_handler)
7539 (_("%B: unexpected reloc type %u in .opd section"),
7545 r_symndx = ELF64_R_SYM (rel->r_info);
7546 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7550 if (sym_sec == NULL || sym_sec->owner == NULL)
7552 const char *sym_name;
7554 sym_name = h->root.root.string;
7556 sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym,
7559 (*_bfd_error_handler)
7560 (_("%B: undefined sym `%s' in .opd section"),
7566 /* opd entries are always for functions defined in the
7567 current input bfd. If the symbol isn't defined in the
7568 input bfd, then we won't be using the function in this
7569 bfd; It must be defined in a linkonce section in another
7570 bfd, or is weak. It's also possible that we are
7571 discarding the function due to a linker script /DISCARD/,
7572 which we test for via the output_section. */
7573 if (sym_sec->owner != ibfd
7574 || sym_sec->output_section == bfd_abs_section_ptr)
7579 || (rel + 1 == relend && rel->r_offset == offset + 16))
7581 if (sec->size == offset + 24)
7586 if (rel == relend && sec->size == offset + 16)
7594 if (rel->r_offset == offset + 24)
7596 else if (rel->r_offset != offset + 16)
7598 else if (rel + 1 < relend
7599 && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64
7600 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC)
7605 else if (rel + 2 < relend
7606 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_ADDR64
7607 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC)
7616 add_aux_fields = non_overlapping && cnt_16b > 0;
7618 if (need_edit || add_aux_fields)
7620 Elf_Internal_Rela *write_rel;
7621 Elf_Internal_Shdr *rel_hdr;
7622 bfd_byte *rptr, *wptr;
7623 bfd_byte *new_contents;
7628 new_contents = NULL;
7629 amt = sec->size * sizeof (long) / 8;
7630 opd = &ppc64_elf_section_data (sec)->u.opd;
7631 opd->adjust = bfd_zalloc (sec->owner, amt);
7632 if (opd->adjust == NULL)
7634 ppc64_elf_section_data (sec)->sec_type = sec_opd;
7636 /* This seems a waste of time as input .opd sections are all
7637 zeros as generated by gcc, but I suppose there's no reason
7638 this will always be so. We might start putting something in
7639 the third word of .opd entries. */
7640 if ((sec->flags & SEC_IN_MEMORY) == 0)
7643 if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
7648 if (local_syms != NULL
7649 && symtab_hdr->contents != (unsigned char *) local_syms)
7651 if (elf_section_data (sec)->relocs != relstart)
7655 sec->contents = loc;
7656 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
7659 elf_section_data (sec)->relocs = relstart;
7661 new_contents = sec->contents;
7664 new_contents = bfd_malloc (sec->size + cnt_16b * 8);
7665 if (new_contents == NULL)
7669 wptr = new_contents;
7670 rptr = sec->contents;
7672 write_rel = relstart;
7676 for (rel = relstart; rel < relend; rel++)
7678 unsigned long r_symndx;
7680 struct elf_link_hash_entry *h;
7681 Elf_Internal_Sym *sym;
7683 r_symndx = ELF64_R_SYM (rel->r_info);
7684 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7688 if (rel->r_offset == offset)
7690 struct ppc_link_hash_entry *fdh = NULL;
7692 /* See if the .opd entry is full 24 byte or
7693 16 byte (with fd_aux entry overlapped with next
7696 if ((rel + 2 == relend && sec->size == offset + 16)
7697 || (rel + 3 < relend
7698 && rel[2].r_offset == offset + 16
7699 && rel[3].r_offset == offset + 24
7700 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_ADDR64
7701 && ELF64_R_TYPE (rel[3].r_info) == R_PPC64_TOC))
7705 && h->root.root.string[0] == '.')
7707 struct ppc_link_hash_table *htab;
7709 htab = ppc_hash_table (info);
7711 fdh = lookup_fdh ((struct ppc_link_hash_entry *) h,
7714 && fdh->elf.root.type != bfd_link_hash_defined
7715 && fdh->elf.root.type != bfd_link_hash_defweak)
7719 skip = (sym_sec->owner != ibfd
7720 || sym_sec->output_section == bfd_abs_section_ptr);
7723 if (fdh != NULL && sym_sec->owner == ibfd)
7725 /* Arrange for the function descriptor sym
7727 fdh->elf.root.u.def.value = 0;
7728 fdh->elf.root.u.def.section = sym_sec;
7730 opd->adjust[rel->r_offset / 8] = -1;
7734 /* We'll be keeping this opd entry. */
7738 /* Redefine the function descriptor symbol to
7739 this location in the opd section. It is
7740 necessary to update the value here rather
7741 than using an array of adjustments as we do
7742 for local symbols, because various places
7743 in the generic ELF code use the value
7744 stored in u.def.value. */
7745 fdh->elf.root.u.def.value = wptr - new_contents;
7746 fdh->adjust_done = 1;
7749 /* Local syms are a bit tricky. We could
7750 tweak them as they can be cached, but
7751 we'd need to look through the local syms
7752 for the function descriptor sym which we
7753 don't have at the moment. So keep an
7754 array of adjustments. */
7755 opd->adjust[rel->r_offset / 8]
7756 = (wptr - new_contents) - (rptr - sec->contents);
7759 memcpy (wptr, rptr, opd_ent_size);
7760 wptr += opd_ent_size;
7761 if (add_aux_fields && opd_ent_size == 16)
7763 memset (wptr, '\0', 8);
7767 rptr += opd_ent_size;
7768 offset += opd_ent_size;
7774 && !info->relocatable
7775 && !dec_dynrel_count (rel->r_info, sec, info,
7781 /* We need to adjust any reloc offsets to point to the
7782 new opd entries. While we're at it, we may as well
7783 remove redundant relocs. */
7784 rel->r_offset += opd->adjust[(offset - opd_ent_size) / 8];
7785 if (write_rel != rel)
7786 memcpy (write_rel, rel, sizeof (*rel));
7791 sec->size = wptr - new_contents;
7792 sec->reloc_count = write_rel - relstart;
7795 free (sec->contents);
7796 sec->contents = new_contents;
7799 /* Fudge the header size too, as this is used later in
7800 elf_bfd_final_link if we are emitting relocs. */
7801 rel_hdr = _bfd_elf_single_rel_hdr (sec);
7802 rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize;
7805 else if (elf_section_data (sec)->relocs != relstart)
7808 if (local_syms != NULL
7809 && symtab_hdr->contents != (unsigned char *) local_syms)
7811 if (!info->keep_memory)
7814 symtab_hdr->contents = (unsigned char *) local_syms;
7819 elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
7821 /* If we are doing a final link and the last .opd entry is just 16 byte
7822 long, add a 8 byte padding after it. */
7823 if (need_pad != NULL && !info->relocatable)
7827 if ((need_pad->flags & SEC_IN_MEMORY) == 0)
7829 BFD_ASSERT (need_pad->size > 0);
7831 p = bfd_malloc (need_pad->size + 8);
7835 if (! bfd_get_section_contents (need_pad->owner, need_pad,
7836 p, 0, need_pad->size))
7839 need_pad->contents = p;
7840 need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
7844 p = bfd_realloc (need_pad->contents, need_pad->size + 8);
7848 need_pad->contents = p;
7851 memset (need_pad->contents + need_pad->size, 0, 8);
7852 need_pad->size += 8;
7858 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7861 ppc64_elf_tls_setup (struct bfd_link_info *info,
7862 int no_tls_get_addr_opt,
7865 struct ppc_link_hash_table *htab;
7867 htab = ppc_hash_table (info);
7871 if (abiversion (info->output_bfd) == 1)
7875 htab->do_multi_toc = 0;
7876 else if (!htab->do_multi_toc)
7879 htab->tls_get_addr = ((struct ppc_link_hash_entry *)
7880 elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
7881 FALSE, FALSE, TRUE));
7882 /* Move dynamic linking info to the function descriptor sym. */
7883 if (htab->tls_get_addr != NULL)
7884 func_desc_adjust (&htab->tls_get_addr->elf, info);
7885 htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
7886 elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
7887 FALSE, FALSE, TRUE));
7888 if (!no_tls_get_addr_opt)
7890 struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
7892 opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
7893 FALSE, FALSE, TRUE);
7895 func_desc_adjust (opt, info);
7896 opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
7897 FALSE, FALSE, TRUE);
7899 && (opt_fd->root.type == bfd_link_hash_defined
7900 || opt_fd->root.type == bfd_link_hash_defweak))
7902 /* If glibc supports an optimized __tls_get_addr call stub,
7903 signalled by the presence of __tls_get_addr_opt, and we'll
7904 be calling __tls_get_addr via a plt call stub, then
7905 make __tls_get_addr point to __tls_get_addr_opt. */
7906 tga_fd = &htab->tls_get_addr_fd->elf;
7907 if (htab->elf.dynamic_sections_created
7909 && (tga_fd->type == STT_FUNC
7910 || tga_fd->needs_plt)
7911 && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
7912 || (ELF_ST_VISIBILITY (tga_fd->other) != STV_DEFAULT
7913 && tga_fd->root.type == bfd_link_hash_undefweak)))
7915 struct plt_entry *ent;
7917 for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
7918 if (ent->plt.refcount > 0)
7922 tga_fd->root.type = bfd_link_hash_indirect;
7923 tga_fd->root.u.i.link = &opt_fd->root;
7924 ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
7925 if (opt_fd->dynindx != -1)
7927 /* Use __tls_get_addr_opt in dynamic relocations. */
7928 opt_fd->dynindx = -1;
7929 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
7930 opt_fd->dynstr_index);
7931 if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
7934 htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd;
7935 tga = &htab->tls_get_addr->elf;
7936 if (opt != NULL && tga != NULL)
7938 tga->root.type = bfd_link_hash_indirect;
7939 tga->root.u.i.link = &opt->root;
7940 ppc64_elf_copy_indirect_symbol (info, opt, tga);
7941 _bfd_elf_link_hash_hide_symbol (info, opt,
7943 htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
7945 htab->tls_get_addr_fd->oh = htab->tls_get_addr;
7946 htab->tls_get_addr_fd->is_func_descriptor = 1;
7947 if (htab->tls_get_addr != NULL)
7949 htab->tls_get_addr->oh = htab->tls_get_addr_fd;
7950 htab->tls_get_addr->is_func = 1;
7956 no_tls_get_addr_opt = TRUE;
7958 htab->no_tls_get_addr_opt = no_tls_get_addr_opt;
7959 return _bfd_elf_tls_setup (info->output_bfd, info);
7962 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7966 branch_reloc_hash_match (const bfd *ibfd,
7967 const Elf_Internal_Rela *rel,
7968 const struct ppc_link_hash_entry *hash1,
7969 const struct ppc_link_hash_entry *hash2)
7971 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
7972 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
7973 unsigned int r_symndx = ELF64_R_SYM (rel->r_info);
7975 if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
7977 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
7978 struct elf_link_hash_entry *h;
7980 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7981 h = elf_follow_link (h);
7982 if (h == &hash1->elf || h == &hash2->elf)
7988 /* Run through all the TLS relocs looking for optimization
7989 opportunities. The linker has been hacked (see ppc64elf.em) to do
7990 a preliminary section layout so that we know the TLS segment
7991 offsets. We can't optimize earlier because some optimizations need
7992 to know the tp offset, and we need to optimize before allocating
7993 dynamic relocations. */
7996 ppc64_elf_tls_optimize (struct bfd_link_info *info)
8000 struct ppc_link_hash_table *htab;
8001 unsigned char *toc_ref;
8004 if (info->relocatable || !info->executable)
8007 htab = ppc_hash_table (info);
8011 /* Make two passes over the relocs. On the first pass, mark toc
8012 entries involved with tls relocs, and check that tls relocs
8013 involved in setting up a tls_get_addr call are indeed followed by
8014 such a call. If they are not, we can't do any tls optimization.
8015 On the second pass twiddle tls_mask flags to notify
8016 relocate_section that optimization can be done, and adjust got
8017 and plt refcounts. */
8019 for (pass = 0; pass < 2; ++pass)
8020 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8022 Elf_Internal_Sym *locsyms = NULL;
8023 asection *toc = bfd_get_section_by_name (ibfd, ".toc");
8025 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8026 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
8028 Elf_Internal_Rela *relstart, *rel, *relend;
8029 bfd_boolean found_tls_get_addr_arg = 0;
8031 /* Read the relocations. */
8032 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8034 if (relstart == NULL)
8037 relend = relstart + sec->reloc_count;
8038 for (rel = relstart; rel < relend; rel++)
8040 enum elf_ppc64_reloc_type r_type;
8041 unsigned long r_symndx;
8042 struct elf_link_hash_entry *h;
8043 Elf_Internal_Sym *sym;
8045 unsigned char *tls_mask;
8046 unsigned char tls_set, tls_clear, tls_type = 0;
8048 bfd_boolean ok_tprel, is_local;
8049 long toc_ref_index = 0;
8050 int expecting_tls_get_addr = 0;
8051 bfd_boolean ret = FALSE;
8053 r_symndx = ELF64_R_SYM (rel->r_info);
8054 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
8058 if (elf_section_data (sec)->relocs != relstart)
8060 if (toc_ref != NULL)
8063 && (elf_symtab_hdr (ibfd).contents
8064 != (unsigned char *) locsyms))
8071 if (h->root.type == bfd_link_hash_defined
8072 || h->root.type == bfd_link_hash_defweak)
8073 value = h->root.u.def.value;
8074 else if (h->root.type == bfd_link_hash_undefweak)
8078 found_tls_get_addr_arg = 0;
8083 /* Symbols referenced by TLS relocs must be of type
8084 STT_TLS. So no need for .opd local sym adjust. */
8085 value = sym->st_value;
8094 && h->root.type == bfd_link_hash_undefweak)
8098 value += sym_sec->output_offset;
8099 value += sym_sec->output_section->vma;
8100 value -= htab->elf.tls_sec->vma;
8101 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
8102 < (bfd_vma) 1 << 32);
8106 r_type = ELF64_R_TYPE (rel->r_info);
8107 /* If this section has old-style __tls_get_addr calls
8108 without marker relocs, then check that each
8109 __tls_get_addr call reloc is preceded by a reloc
8110 that conceivably belongs to the __tls_get_addr arg
8111 setup insn. If we don't find matching arg setup
8112 relocs, don't do any tls optimization. */
8114 && sec->has_tls_get_addr_call
8116 && (h == &htab->tls_get_addr->elf
8117 || h == &htab->tls_get_addr_fd->elf)
8118 && !found_tls_get_addr_arg
8119 && is_branch_reloc (r_type))
8121 info->callbacks->minfo (_("%H __tls_get_addr lost arg, "
8122 "TLS optimization disabled\n"),
8123 ibfd, sec, rel->r_offset);
8128 found_tls_get_addr_arg = 0;
8131 case R_PPC64_GOT_TLSLD16:
8132 case R_PPC64_GOT_TLSLD16_LO:
8133 expecting_tls_get_addr = 1;
8134 found_tls_get_addr_arg = 1;
8137 case R_PPC64_GOT_TLSLD16_HI:
8138 case R_PPC64_GOT_TLSLD16_HA:
8139 /* These relocs should never be against a symbol
8140 defined in a shared lib. Leave them alone if
8141 that turns out to be the case. */
8148 tls_type = TLS_TLS | TLS_LD;
8151 case R_PPC64_GOT_TLSGD16:
8152 case R_PPC64_GOT_TLSGD16_LO:
8153 expecting_tls_get_addr = 1;
8154 found_tls_get_addr_arg = 1;
8157 case R_PPC64_GOT_TLSGD16_HI:
8158 case R_PPC64_GOT_TLSGD16_HA:
8164 tls_set = TLS_TLS | TLS_TPRELGD;
8166 tls_type = TLS_TLS | TLS_GD;
8169 case R_PPC64_GOT_TPREL16_DS:
8170 case R_PPC64_GOT_TPREL16_LO_DS:
8171 case R_PPC64_GOT_TPREL16_HI:
8172 case R_PPC64_GOT_TPREL16_HA:
8177 tls_clear = TLS_TPREL;
8178 tls_type = TLS_TLS | TLS_TPREL;
8185 found_tls_get_addr_arg = 1;
8190 case R_PPC64_TOC16_LO:
8191 if (sym_sec == NULL || sym_sec != toc)
8194 /* Mark this toc entry as referenced by a TLS
8195 code sequence. We can do that now in the
8196 case of R_PPC64_TLS, and after checking for
8197 tls_get_addr for the TOC16 relocs. */
8198 if (toc_ref == NULL)
8199 toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8);
8200 if (toc_ref == NULL)
8204 value = h->root.u.def.value;
8206 value = sym->st_value;
8207 value += rel->r_addend;
8208 BFD_ASSERT (value < toc->size && value % 8 == 0);
8209 toc_ref_index = (value + toc->output_offset) / 8;
8210 if (r_type == R_PPC64_TLS
8211 || r_type == R_PPC64_TLSGD
8212 || r_type == R_PPC64_TLSLD)
8214 toc_ref[toc_ref_index] = 1;
8218 if (pass != 0 && toc_ref[toc_ref_index] == 0)
8223 expecting_tls_get_addr = 2;
8226 case R_PPC64_TPREL64:
8230 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8235 tls_set = TLS_EXPLICIT;
8236 tls_clear = TLS_TPREL;
8241 case R_PPC64_DTPMOD64:
8245 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8247 if (rel + 1 < relend
8249 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
8250 && rel[1].r_offset == rel->r_offset + 8)
8254 tls_set = TLS_EXPLICIT | TLS_GD;
8257 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
8266 tls_set = TLS_EXPLICIT;
8277 if (!expecting_tls_get_addr
8278 || !sec->has_tls_get_addr_call)
8281 if (rel + 1 < relend
8282 && branch_reloc_hash_match (ibfd, rel + 1,
8284 htab->tls_get_addr_fd))
8286 if (expecting_tls_get_addr == 2)
8288 /* Check for toc tls entries. */
8289 unsigned char *toc_tls;
8292 retval = get_tls_mask (&toc_tls, NULL, NULL,
8297 if (toc_tls != NULL)
8299 if ((*toc_tls & (TLS_GD | TLS_LD)) != 0)
8300 found_tls_get_addr_arg = 1;
8302 toc_ref[toc_ref_index] = 1;
8308 if (expecting_tls_get_addr != 1)
8311 /* Uh oh, we didn't find the expected call. We
8312 could just mark this symbol to exclude it
8313 from tls optimization but it's safer to skip
8314 the entire optimization. */
8315 info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
8316 "TLS optimization disabled\n"),
8317 ibfd, sec, rel->r_offset);
8322 if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
8324 struct plt_entry *ent;
8325 for (ent = htab->tls_get_addr->elf.plt.plist;
8328 if (ent->addend == 0)
8330 if (ent->plt.refcount > 0)
8332 ent->plt.refcount -= 1;
8333 expecting_tls_get_addr = 0;
8339 if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL)
8341 struct plt_entry *ent;
8342 for (ent = htab->tls_get_addr_fd->elf.plt.plist;
8345 if (ent->addend == 0)
8347 if (ent->plt.refcount > 0)
8348 ent->plt.refcount -= 1;
8356 if ((tls_set & TLS_EXPLICIT) == 0)
8358 struct got_entry *ent;
8360 /* Adjust got entry for this reloc. */
8364 ent = elf_local_got_ents (ibfd)[r_symndx];
8366 for (; ent != NULL; ent = ent->next)
8367 if (ent->addend == rel->r_addend
8368 && ent->owner == ibfd
8369 && ent->tls_type == tls_type)
8376 /* We managed to get rid of a got entry. */
8377 if (ent->got.refcount > 0)
8378 ent->got.refcount -= 1;
8383 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8384 we'll lose one or two dyn relocs. */
8385 if (!dec_dynrel_count (rel->r_info, sec, info,
8389 if (tls_set == (TLS_EXPLICIT | TLS_GD))
8391 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
8397 *tls_mask |= tls_set;
8398 *tls_mask &= ~tls_clear;
8401 if (elf_section_data (sec)->relocs != relstart)
8406 && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
8408 if (!info->keep_memory)
8411 elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
8415 if (toc_ref != NULL)
8420 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8421 the values of any global symbols in a toc section that has been
8422 edited. Globals in toc sections should be a rarity, so this function
8423 sets a flag if any are found in toc sections other than the one just
8424 edited, so that futher hash table traversals can be avoided. */
8426 struct adjust_toc_info
8429 unsigned long *skip;
8430 bfd_boolean global_toc_syms;
8433 enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 };
8436 adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
8438 struct ppc_link_hash_entry *eh;
8439 struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf;
8442 if (h->root.type != bfd_link_hash_defined
8443 && h->root.type != bfd_link_hash_defweak)
8446 eh = (struct ppc_link_hash_entry *) h;
8447 if (eh->adjust_done)
8450 if (eh->elf.root.u.def.section == toc_inf->toc)
8452 if (eh->elf.root.u.def.value > toc_inf->toc->rawsize)
8453 i = toc_inf->toc->rawsize >> 3;
8455 i = eh->elf.root.u.def.value >> 3;
8457 if ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0)
8459 (*_bfd_error_handler)
8460 (_("%s defined on removed toc entry"), eh->elf.root.root.string);
8463 while ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0);
8464 eh->elf.root.u.def.value = (bfd_vma) i << 3;
8467 eh->elf.root.u.def.value -= toc_inf->skip[i];
8468 eh->adjust_done = 1;
8470 else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
8471 toc_inf->global_toc_syms = TRUE;
8476 /* Return TRUE iff INSN is one we expect on a _LO variety toc/got reloc. */
8479 ok_lo_toc_insn (unsigned int insn)
8481 return ((insn & (0x3f << 26)) == 14u << 26 /* addi */
8482 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
8483 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
8484 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
8485 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
8486 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
8487 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
8488 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
8489 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
8490 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
8491 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
8492 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
8493 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
8494 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
8495 || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
8497 || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
8498 && ((insn & 3) == 0 || (insn & 3) == 3))
8499 || (insn & (0x3f << 26)) == 12u << 26 /* addic */);
8502 /* Examine all relocs referencing .toc sections in order to remove
8503 unused .toc entries. */
8506 ppc64_elf_edit_toc (struct bfd_link_info *info)
8509 struct adjust_toc_info toc_inf;
8510 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8512 htab->do_toc_opt = 1;
8513 toc_inf.global_toc_syms = TRUE;
8514 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8516 asection *toc, *sec;
8517 Elf_Internal_Shdr *symtab_hdr;
8518 Elf_Internal_Sym *local_syms;
8519 Elf_Internal_Rela *relstart, *rel, *toc_relocs;
8520 unsigned long *skip, *drop;
8521 unsigned char *used;
8522 unsigned char *keep, last, some_unused;
8524 if (!is_ppc64_elf (ibfd))
8527 toc = bfd_get_section_by_name (ibfd, ".toc");
8530 || toc->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
8531 || discarded_section (toc))
8536 symtab_hdr = &elf_symtab_hdr (ibfd);
8538 /* Look at sections dropped from the final link. */
8541 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8543 if (sec->reloc_count == 0
8544 || !discarded_section (sec)
8545 || get_opd_info (sec)
8546 || (sec->flags & SEC_ALLOC) == 0
8547 || (sec->flags & SEC_DEBUGGING) != 0)
8550 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
8551 if (relstart == NULL)
8554 /* Run through the relocs to see which toc entries might be
8556 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8558 enum elf_ppc64_reloc_type r_type;
8559 unsigned long r_symndx;
8561 struct elf_link_hash_entry *h;
8562 Elf_Internal_Sym *sym;
8565 r_type = ELF64_R_TYPE (rel->r_info);
8572 case R_PPC64_TOC16_LO:
8573 case R_PPC64_TOC16_HI:
8574 case R_PPC64_TOC16_HA:
8575 case R_PPC64_TOC16_DS:
8576 case R_PPC64_TOC16_LO_DS:
8580 r_symndx = ELF64_R_SYM (rel->r_info);
8581 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8589 val = h->root.u.def.value;
8591 val = sym->st_value;
8592 val += rel->r_addend;
8594 if (val >= toc->size)
8597 /* Anything in the toc ought to be aligned to 8 bytes.
8598 If not, don't mark as unused. */
8604 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
8609 skip[val >> 3] = ref_from_discarded;
8612 if (elf_section_data (sec)->relocs != relstart)
8616 /* For largetoc loads of address constants, we can convert
8617 . addis rx,2,addr@got@ha
8618 . ld ry,addr@got@l(rx)
8620 . addis rx,2,addr@toc@ha
8621 . addi ry,rx,addr@toc@l
8622 when addr is within 2G of the toc pointer. This then means
8623 that the word storing "addr" in the toc is no longer needed. */
8625 if (!ppc64_elf_tdata (ibfd)->has_small_toc_reloc
8626 && toc->output_section->rawsize < (bfd_vma) 1 << 31
8627 && toc->reloc_count != 0)
8629 /* Read toc relocs. */
8630 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
8632 if (toc_relocs == NULL)
8635 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
8637 enum elf_ppc64_reloc_type r_type;
8638 unsigned long r_symndx;
8640 struct elf_link_hash_entry *h;
8641 Elf_Internal_Sym *sym;
8644 r_type = ELF64_R_TYPE (rel->r_info);
8645 if (r_type != R_PPC64_ADDR64)
8648 r_symndx = ELF64_R_SYM (rel->r_info);
8649 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8654 || discarded_section (sym_sec))
8657 if (!SYMBOL_CALLS_LOCAL (info, h))
8662 if (h->type == STT_GNU_IFUNC)
8664 val = h->root.u.def.value;
8668 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
8670 val = sym->st_value;
8672 val += rel->r_addend;
8673 val += sym_sec->output_section->vma + sym_sec->output_offset;
8675 /* We don't yet know the exact toc pointer value, but we
8676 know it will be somewhere in the toc section. Don't
8677 optimize if the difference from any possible toc
8678 pointer is outside [ff..f80008000, 7fff7fff]. */
8679 addr = toc->output_section->vma + TOC_BASE_OFF;
8680 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
8683 addr = toc->output_section->vma + toc->output_section->rawsize;
8684 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
8689 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
8694 skip[rel->r_offset >> 3]
8695 |= can_optimize | ((rel - toc_relocs) << 2);
8702 used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8);
8706 if (local_syms != NULL
8707 && symtab_hdr->contents != (unsigned char *) local_syms)
8711 && elf_section_data (sec)->relocs != relstart)
8713 if (toc_relocs != NULL
8714 && elf_section_data (toc)->relocs != toc_relocs)
8721 /* Now check all kept sections that might reference the toc.
8722 Check the toc itself last. */
8723 for (sec = (ibfd->sections == toc && toc->next ? toc->next
8726 sec = (sec == toc ? NULL
8727 : sec->next == NULL ? toc
8728 : sec->next == toc && toc->next ? toc->next
8733 if (sec->reloc_count == 0
8734 || discarded_section (sec)
8735 || get_opd_info (sec)
8736 || (sec->flags & SEC_ALLOC) == 0
8737 || (sec->flags & SEC_DEBUGGING) != 0)
8740 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8742 if (relstart == NULL)
8745 /* Mark toc entries referenced as used. */
8749 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8751 enum elf_ppc64_reloc_type r_type;
8752 unsigned long r_symndx;
8754 struct elf_link_hash_entry *h;
8755 Elf_Internal_Sym *sym;
8757 enum {no_check, check_lo, check_ha} insn_check;
8759 r_type = ELF64_R_TYPE (rel->r_info);
8763 insn_check = no_check;
8766 case R_PPC64_GOT_TLSLD16_HA:
8767 case R_PPC64_GOT_TLSGD16_HA:
8768 case R_PPC64_GOT_TPREL16_HA:
8769 case R_PPC64_GOT_DTPREL16_HA:
8770 case R_PPC64_GOT16_HA:
8771 case R_PPC64_TOC16_HA:
8772 insn_check = check_ha;
8775 case R_PPC64_GOT_TLSLD16_LO:
8776 case R_PPC64_GOT_TLSGD16_LO:
8777 case R_PPC64_GOT_TPREL16_LO_DS:
8778 case R_PPC64_GOT_DTPREL16_LO_DS:
8779 case R_PPC64_GOT16_LO:
8780 case R_PPC64_GOT16_LO_DS:
8781 case R_PPC64_TOC16_LO:
8782 case R_PPC64_TOC16_LO_DS:
8783 insn_check = check_lo;
8787 if (insn_check != no_check)
8789 bfd_vma off = rel->r_offset & ~3;
8790 unsigned char buf[4];
8793 if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
8798 insn = bfd_get_32 (ibfd, buf);
8799 if (insn_check == check_lo
8800 ? !ok_lo_toc_insn (insn)
8801 : ((insn & ((0x3f << 26) | 0x1f << 16))
8802 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8806 ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
8807 sprintf (str, "%#08x", insn);
8808 info->callbacks->einfo
8809 (_("%P: %H: toc optimization is not supported for"
8810 " %s instruction.\n"),
8811 ibfd, sec, rel->r_offset & ~3, str);
8818 case R_PPC64_TOC16_LO:
8819 case R_PPC64_TOC16_HI:
8820 case R_PPC64_TOC16_HA:
8821 case R_PPC64_TOC16_DS:
8822 case R_PPC64_TOC16_LO_DS:
8823 /* In case we're taking addresses of toc entries. */
8824 case R_PPC64_ADDR64:
8831 r_symndx = ELF64_R_SYM (rel->r_info);
8832 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8843 val = h->root.u.def.value;
8845 val = sym->st_value;
8846 val += rel->r_addend;
8848 if (val >= toc->size)
8851 if ((skip[val >> 3] & can_optimize) != 0)
8858 case R_PPC64_TOC16_HA:
8861 case R_PPC64_TOC16_LO_DS:
8862 off = rel->r_offset;
8863 off += (bfd_big_endian (ibfd) ? -2 : 3);
8864 if (!bfd_get_section_contents (ibfd, sec, &opc,
8870 if ((opc & (0x3f << 2)) == (58u << 2))
8875 /* Wrong sort of reloc, or not a ld. We may
8876 as well clear ref_from_discarded too. */
8883 /* For the toc section, we only mark as used if this
8884 entry itself isn't unused. */
8885 else if ((used[rel->r_offset >> 3]
8886 || !(skip[rel->r_offset >> 3] & ref_from_discarded))
8889 /* Do all the relocs again, to catch reference
8898 if (elf_section_data (sec)->relocs != relstart)
8902 /* Merge the used and skip arrays. Assume that TOC
8903 doublewords not appearing as either used or unused belong
8904 to to an entry more than one doubleword in size. */
8905 for (drop = skip, keep = used, last = 0, some_unused = 0;
8906 drop < skip + (toc->size + 7) / 8;
8911 *drop &= ~ref_from_discarded;
8912 if ((*drop & can_optimize) != 0)
8916 else if ((*drop & ref_from_discarded) != 0)
8919 last = ref_from_discarded;
8929 bfd_byte *contents, *src;
8931 Elf_Internal_Sym *sym;
8932 bfd_boolean local_toc_syms = FALSE;
8934 /* Shuffle the toc contents, and at the same time convert the
8935 skip array from booleans into offsets. */
8936 if (!bfd_malloc_and_get_section (ibfd, toc, &contents))
8939 elf_section_data (toc)->this_hdr.contents = contents;
8941 for (src = contents, off = 0, drop = skip;
8942 src < contents + toc->size;
8945 if ((*drop & (can_optimize | ref_from_discarded)) != 0)
8950 memcpy (src - off, src, 8);
8954 toc->rawsize = toc->size;
8955 toc->size = src - contents - off;
8957 /* Adjust addends for relocs against the toc section sym,
8958 and optimize any accesses we can. */
8959 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8961 if (sec->reloc_count == 0
8962 || discarded_section (sec))
8965 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8967 if (relstart == NULL)
8970 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8972 enum elf_ppc64_reloc_type r_type;
8973 unsigned long r_symndx;
8975 struct elf_link_hash_entry *h;
8978 r_type = ELF64_R_TYPE (rel->r_info);
8985 case R_PPC64_TOC16_LO:
8986 case R_PPC64_TOC16_HI:
8987 case R_PPC64_TOC16_HA:
8988 case R_PPC64_TOC16_DS:
8989 case R_PPC64_TOC16_LO_DS:
8990 case R_PPC64_ADDR64:
8994 r_symndx = ELF64_R_SYM (rel->r_info);
8995 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9003 val = h->root.u.def.value;
9006 val = sym->st_value;
9008 local_toc_syms = TRUE;
9011 val += rel->r_addend;
9013 if (val > toc->rawsize)
9015 else if ((skip[val >> 3] & ref_from_discarded) != 0)
9017 else if ((skip[val >> 3] & can_optimize) != 0)
9019 Elf_Internal_Rela *tocrel
9020 = toc_relocs + (skip[val >> 3] >> 2);
9021 unsigned long tsym = ELF64_R_SYM (tocrel->r_info);
9025 case R_PPC64_TOC16_HA:
9026 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_TOC16_HA);
9029 case R_PPC64_TOC16_LO_DS:
9030 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_LO_DS_OPT);
9034 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
9036 info->callbacks->einfo
9037 (_("%P: %H: %s references "
9038 "optimized away TOC entry\n"),
9039 ibfd, sec, rel->r_offset,
9040 ppc64_elf_howto_table[r_type]->name);
9041 bfd_set_error (bfd_error_bad_value);
9044 rel->r_addend = tocrel->r_addend;
9045 elf_section_data (sec)->relocs = relstart;
9049 if (h != NULL || sym->st_value != 0)
9052 rel->r_addend -= skip[val >> 3];
9053 elf_section_data (sec)->relocs = relstart;
9056 if (elf_section_data (sec)->relocs != relstart)
9060 /* We shouldn't have local or global symbols defined in the TOC,
9061 but handle them anyway. */
9062 if (local_syms != NULL)
9063 for (sym = local_syms;
9064 sym < local_syms + symtab_hdr->sh_info;
9066 if (sym->st_value != 0
9067 && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc)
9071 if (sym->st_value > toc->rawsize)
9072 i = toc->rawsize >> 3;
9074 i = sym->st_value >> 3;
9076 if ((skip[i] & (ref_from_discarded | can_optimize)) != 0)
9079 (*_bfd_error_handler)
9080 (_("%s defined on removed toc entry"),
9081 bfd_elf_sym_name (ibfd, symtab_hdr, sym, NULL));
9084 while ((skip[i] & (ref_from_discarded | can_optimize)));
9085 sym->st_value = (bfd_vma) i << 3;
9088 sym->st_value -= skip[i];
9089 symtab_hdr->contents = (unsigned char *) local_syms;
9092 /* Adjust any global syms defined in this toc input section. */
9093 if (toc_inf.global_toc_syms)
9096 toc_inf.skip = skip;
9097 toc_inf.global_toc_syms = FALSE;
9098 elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
9102 if (toc->reloc_count != 0)
9104 Elf_Internal_Shdr *rel_hdr;
9105 Elf_Internal_Rela *wrel;
9108 /* Remove unused toc relocs, and adjust those we keep. */
9109 if (toc_relocs == NULL)
9110 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
9112 if (toc_relocs == NULL)
9116 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
9117 if ((skip[rel->r_offset >> 3]
9118 & (ref_from_discarded | can_optimize)) == 0)
9120 wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3];
9121 wrel->r_info = rel->r_info;
9122 wrel->r_addend = rel->r_addend;
9125 else if (!dec_dynrel_count (rel->r_info, toc, info,
9126 &local_syms, NULL, NULL))
9129 elf_section_data (toc)->relocs = toc_relocs;
9130 toc->reloc_count = wrel - toc_relocs;
9131 rel_hdr = _bfd_elf_single_rel_hdr (toc);
9132 sz = rel_hdr->sh_entsize;
9133 rel_hdr->sh_size = toc->reloc_count * sz;
9136 else if (toc_relocs != NULL
9137 && elf_section_data (toc)->relocs != toc_relocs)
9140 if (local_syms != NULL
9141 && symtab_hdr->contents != (unsigned char *) local_syms)
9143 if (!info->keep_memory)
9146 symtab_hdr->contents = (unsigned char *) local_syms;
9154 /* Return true iff input section I references the TOC using
9155 instructions limited to +/-32k offsets. */
9158 ppc64_elf_has_small_toc_reloc (asection *i)
9160 return (is_ppc64_elf (i->owner)
9161 && ppc64_elf_tdata (i->owner)->has_small_toc_reloc);
9164 /* Allocate space for one GOT entry. */
9167 allocate_got (struct elf_link_hash_entry *h,
9168 struct bfd_link_info *info,
9169 struct got_entry *gent)
9171 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9173 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
9174 int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
9176 int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD
9177 ? 2 : 1) * sizeof (Elf64_External_Rela);
9178 asection *got = ppc64_elf_tdata (gent->owner)->got;
9180 gent->got.offset = got->size;
9181 got->size += entsize;
9183 dyn = htab->elf.dynamic_sections_created;
9184 if (h->type == STT_GNU_IFUNC)
9186 htab->reliplt->size += rentsize;
9187 htab->got_reli_size += rentsize;
9189 else if ((info->shared
9190 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
9191 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9192 || h->root.type != bfd_link_hash_undefweak))
9194 asection *relgot = ppc64_elf_tdata (gent->owner)->relgot;
9195 relgot->size += rentsize;
9199 /* This function merges got entries in the same toc group. */
9202 merge_got_entries (struct got_entry **pent)
9204 struct got_entry *ent, *ent2;
9206 for (ent = *pent; ent != NULL; ent = ent->next)
9207 if (!ent->is_indirect)
9208 for (ent2 = ent->next; ent2 != NULL; ent2 = ent2->next)
9209 if (!ent2->is_indirect
9210 && ent2->addend == ent->addend
9211 && ent2->tls_type == ent->tls_type
9212 && elf_gp (ent2->owner) == elf_gp (ent->owner))
9214 ent2->is_indirect = TRUE;
9215 ent2->got.ent = ent;
9219 /* Allocate space in .plt, .got and associated reloc sections for
9223 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
9225 struct bfd_link_info *info;
9226 struct ppc_link_hash_table *htab;
9228 struct ppc_link_hash_entry *eh;
9229 struct elf_dyn_relocs *p;
9230 struct got_entry **pgent, *gent;
9232 if (h->root.type == bfd_link_hash_indirect)
9235 info = (struct bfd_link_info *) inf;
9236 htab = ppc_hash_table (info);
9240 if ((htab->elf.dynamic_sections_created
9242 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
9243 || h->type == STT_GNU_IFUNC)
9245 struct plt_entry *pent;
9246 bfd_boolean doneone = FALSE;
9247 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
9248 if (pent->plt.refcount > 0)
9250 if (!htab->elf.dynamic_sections_created
9251 || h->dynindx == -1)
9254 pent->plt.offset = s->size;
9255 s->size += PLT_ENTRY_SIZE (htab);
9260 /* If this is the first .plt entry, make room for the special
9264 s->size += PLT_INITIAL_ENTRY_SIZE (htab);
9266 pent->plt.offset = s->size;
9268 /* Make room for this entry. */
9269 s->size += PLT_ENTRY_SIZE (htab);
9271 /* Make room for the .glink code. */
9274 s->size += GLINK_CALL_STUB_SIZE;
9277 /* We need bigger stubs past index 32767. */
9278 if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
9285 /* We also need to make an entry in the .rela.plt section. */
9288 s->size += sizeof (Elf64_External_Rela);
9292 pent->plt.offset = (bfd_vma) -1;
9295 h->plt.plist = NULL;
9301 h->plt.plist = NULL;
9305 eh = (struct ppc_link_hash_entry *) h;
9306 /* Run through the TLS GD got entries first if we're changing them
9308 if ((eh->tls_mask & TLS_TPRELGD) != 0)
9309 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9310 if (gent->got.refcount > 0
9311 && (gent->tls_type & TLS_GD) != 0)
9313 /* This was a GD entry that has been converted to TPREL. If
9314 there happens to be a TPREL entry we can use that one. */
9315 struct got_entry *ent;
9316 for (ent = h->got.glist; ent != NULL; ent = ent->next)
9317 if (ent->got.refcount > 0
9318 && (ent->tls_type & TLS_TPREL) != 0
9319 && ent->addend == gent->addend
9320 && ent->owner == gent->owner)
9322 gent->got.refcount = 0;
9326 /* If not, then we'll be using our own TPREL entry. */
9327 if (gent->got.refcount != 0)
9328 gent->tls_type = TLS_TLS | TLS_TPREL;
9331 /* Remove any list entry that won't generate a word in the GOT before
9332 we call merge_got_entries. Otherwise we risk merging to empty
9334 pgent = &h->got.glist;
9335 while ((gent = *pgent) != NULL)
9336 if (gent->got.refcount > 0)
9338 if ((gent->tls_type & TLS_LD) != 0
9341 ppc64_tlsld_got (gent->owner)->got.refcount += 1;
9342 *pgent = gent->next;
9345 pgent = &gent->next;
9348 *pgent = gent->next;
9350 if (!htab->do_multi_toc)
9351 merge_got_entries (&h->got.glist);
9353 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9354 if (!gent->is_indirect)
9356 /* Make sure this symbol is output as a dynamic symbol.
9357 Undefined weak syms won't yet be marked as dynamic,
9358 nor will all TLS symbols. */
9359 if (h->dynindx == -1
9361 && h->type != STT_GNU_IFUNC
9362 && htab->elf.dynamic_sections_created)
9364 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9368 if (!is_ppc64_elf (gent->owner))
9371 allocate_got (h, info, gent);
9374 if (eh->dyn_relocs == NULL
9375 || (!htab->elf.dynamic_sections_created
9376 && h->type != STT_GNU_IFUNC))
9379 /* In the shared -Bsymbolic case, discard space allocated for
9380 dynamic pc-relative relocs against symbols which turn out to be
9381 defined in regular objects. For the normal shared case, discard
9382 space for relocs that have become local due to symbol visibility
9387 /* Relocs that use pc_count are those that appear on a call insn,
9388 or certain REL relocs (see must_be_dyn_reloc) that can be
9389 generated via assembly. We want calls to protected symbols to
9390 resolve directly to the function rather than going via the plt.
9391 If people want function pointer comparisons to work as expected
9392 then they should avoid writing weird assembly. */
9393 if (SYMBOL_CALLS_LOCAL (info, h))
9395 struct elf_dyn_relocs **pp;
9397 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
9399 p->count -= p->pc_count;
9408 /* Also discard relocs on undefined weak syms with non-default
9410 if (eh->dyn_relocs != NULL
9411 && h->root.type == bfd_link_hash_undefweak)
9413 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9414 eh->dyn_relocs = NULL;
9416 /* Make sure this symbol is output as a dynamic symbol.
9417 Undefined weak syms won't yet be marked as dynamic. */
9418 else if (h->dynindx == -1
9419 && !h->forced_local)
9421 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9426 else if (h->type == STT_GNU_IFUNC)
9428 if (!h->non_got_ref)
9429 eh->dyn_relocs = NULL;
9431 else if (ELIMINATE_COPY_RELOCS)
9433 /* For the non-shared case, discard space for relocs against
9434 symbols which turn out to need copy relocs or are not
9440 /* Make sure this symbol is output as a dynamic symbol.
9441 Undefined weak syms won't yet be marked as dynamic. */
9442 if (h->dynindx == -1
9443 && !h->forced_local)
9445 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9449 /* If that succeeded, we know we'll be keeping all the
9451 if (h->dynindx != -1)
9455 eh->dyn_relocs = NULL;
9460 /* Finally, allocate space. */
9461 for (p = eh->dyn_relocs; p != NULL; p = p->next)
9463 asection *sreloc = elf_section_data (p->sec)->sreloc;
9464 if (eh->elf.type == STT_GNU_IFUNC)
9465 sreloc = htab->reliplt;
9466 sreloc->size += p->count * sizeof (Elf64_External_Rela);
9472 /* Find any dynamic relocs that apply to read-only sections. */
9475 readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
9477 struct ppc_link_hash_entry *eh;
9478 struct elf_dyn_relocs *p;
9480 eh = (struct ppc_link_hash_entry *) h;
9481 for (p = eh->dyn_relocs; p != NULL; p = p->next)
9483 asection *s = p->sec->output_section;
9485 if (s != NULL && (s->flags & SEC_READONLY) != 0)
9487 struct bfd_link_info *info = inf;
9489 info->flags |= DF_TEXTREL;
9491 /* Not an error, just cut short the traversal. */
9498 /* Set the sizes of the dynamic sections. */
9501 ppc64_elf_size_dynamic_sections (bfd *output_bfd,
9502 struct bfd_link_info *info)
9504 struct ppc_link_hash_table *htab;
9509 struct got_entry *first_tlsld;
9511 htab = ppc_hash_table (info);
9515 dynobj = htab->elf.dynobj;
9519 if (htab->elf.dynamic_sections_created)
9521 /* Set the contents of the .interp section to the interpreter. */
9522 if (info->executable)
9524 s = bfd_get_linker_section (dynobj, ".interp");
9527 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
9528 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
9532 /* Set up .got offsets for local syms, and space for local dynamic
9534 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
9536 struct got_entry **lgot_ents;
9537 struct got_entry **end_lgot_ents;
9538 struct plt_entry **local_plt;
9539 struct plt_entry **end_local_plt;
9540 unsigned char *lgot_masks;
9541 bfd_size_type locsymcount;
9542 Elf_Internal_Shdr *symtab_hdr;
9544 if (!is_ppc64_elf (ibfd))
9547 for (s = ibfd->sections; s != NULL; s = s->next)
9549 struct ppc_dyn_relocs *p;
9551 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
9553 if (!bfd_is_abs_section (p->sec)
9554 && bfd_is_abs_section (p->sec->output_section))
9556 /* Input section has been discarded, either because
9557 it is a copy of a linkonce section or due to
9558 linker script /DISCARD/, so we'll be discarding
9561 else if (p->count != 0)
9563 asection *srel = elf_section_data (p->sec)->sreloc;
9565 srel = htab->reliplt;
9566 srel->size += p->count * sizeof (Elf64_External_Rela);
9567 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
9568 info->flags |= DF_TEXTREL;
9573 lgot_ents = elf_local_got_ents (ibfd);
9577 symtab_hdr = &elf_symtab_hdr (ibfd);
9578 locsymcount = symtab_hdr->sh_info;
9579 end_lgot_ents = lgot_ents + locsymcount;
9580 local_plt = (struct plt_entry **) end_lgot_ents;
9581 end_local_plt = local_plt + locsymcount;
9582 lgot_masks = (unsigned char *) end_local_plt;
9583 s = ppc64_elf_tdata (ibfd)->got;
9584 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
9586 struct got_entry **pent, *ent;
9589 while ((ent = *pent) != NULL)
9590 if (ent->got.refcount > 0)
9592 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
9594 ppc64_tlsld_got (ibfd)->got.refcount += 1;
9599 unsigned int ent_size = 8;
9600 unsigned int rel_size = sizeof (Elf64_External_Rela);
9602 ent->got.offset = s->size;
9603 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
9608 s->size += ent_size;
9609 if ((*lgot_masks & PLT_IFUNC) != 0)
9611 htab->reliplt->size += rel_size;
9612 htab->got_reli_size += rel_size;
9614 else if (info->shared)
9616 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
9617 srel->size += rel_size;
9626 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
9627 for (; local_plt < end_local_plt; ++local_plt)
9629 struct plt_entry *ent;
9631 for (ent = *local_plt; ent != NULL; ent = ent->next)
9632 if (ent->plt.refcount > 0)
9635 ent->plt.offset = s->size;
9636 s->size += PLT_ENTRY_SIZE (htab);
9638 htab->reliplt->size += sizeof (Elf64_External_Rela);
9641 ent->plt.offset = (bfd_vma) -1;
9645 /* Allocate global sym .plt and .got entries, and space for global
9646 sym dynamic relocs. */
9647 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
9650 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
9652 struct got_entry *ent;
9654 if (!is_ppc64_elf (ibfd))
9657 ent = ppc64_tlsld_got (ibfd);
9658 if (ent->got.refcount > 0)
9660 if (!htab->do_multi_toc && first_tlsld != NULL)
9662 ent->is_indirect = TRUE;
9663 ent->got.ent = first_tlsld;
9667 if (first_tlsld == NULL)
9669 s = ppc64_elf_tdata (ibfd)->got;
9670 ent->got.offset = s->size;
9675 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
9676 srel->size += sizeof (Elf64_External_Rela);
9681 ent->got.offset = (bfd_vma) -1;
9684 /* We now have determined the sizes of the various dynamic sections.
9685 Allocate memory for them. */
9687 for (s = dynobj->sections; s != NULL; s = s->next)
9689 if ((s->flags & SEC_LINKER_CREATED) == 0)
9692 if (s == htab->brlt || s == htab->relbrlt)
9693 /* These haven't been allocated yet; don't strip. */
9695 else if (s == htab->got
9699 || s == htab->dynbss)
9701 /* Strip this section if we don't need it; see the
9704 else if (s == htab->glink_eh_frame)
9706 if (!bfd_is_abs_section (s->output_section))
9707 /* Not sized yet. */
9710 else if (CONST_STRNEQ (s->name, ".rela"))
9714 if (s != htab->relplt)
9717 /* We use the reloc_count field as a counter if we need
9718 to copy relocs into the output file. */
9724 /* It's not one of our sections, so don't allocate space. */
9730 /* If we don't need this section, strip it from the
9731 output file. This is mostly to handle .rela.bss and
9732 .rela.plt. We must create both sections in
9733 create_dynamic_sections, because they must be created
9734 before the linker maps input sections to output
9735 sections. The linker does that before
9736 adjust_dynamic_symbol is called, and it is that
9737 function which decides whether anything needs to go
9738 into these sections. */
9739 s->flags |= SEC_EXCLUDE;
9743 if ((s->flags & SEC_HAS_CONTENTS) == 0)
9746 /* Allocate memory for the section contents. We use bfd_zalloc
9747 here in case unused entries are not reclaimed before the
9748 section's contents are written out. This should not happen,
9749 but this way if it does we get a R_PPC64_NONE reloc in .rela
9750 sections instead of garbage.
9751 We also rely on the section contents being zero when writing
9753 s->contents = bfd_zalloc (dynobj, s->size);
9754 if (s->contents == NULL)
9758 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
9760 if (!is_ppc64_elf (ibfd))
9763 s = ppc64_elf_tdata (ibfd)->got;
9764 if (s != NULL && s != htab->got)
9767 s->flags |= SEC_EXCLUDE;
9770 s->contents = bfd_zalloc (ibfd, s->size);
9771 if (s->contents == NULL)
9775 s = ppc64_elf_tdata (ibfd)->relgot;
9779 s->flags |= SEC_EXCLUDE;
9782 s->contents = bfd_zalloc (ibfd, s->size);
9783 if (s->contents == NULL)
9791 if (htab->elf.dynamic_sections_created)
9793 bfd_boolean tls_opt;
9795 /* Add some entries to the .dynamic section. We fill in the
9796 values later, in ppc64_elf_finish_dynamic_sections, but we
9797 must add the entries now so that we get the correct size for
9798 the .dynamic section. The DT_DEBUG entry is filled in by the
9799 dynamic linker and used by the debugger. */
9800 #define add_dynamic_entry(TAG, VAL) \
9801 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9803 if (info->executable)
9805 if (!add_dynamic_entry (DT_DEBUG, 0))
9809 if (htab->plt != NULL && htab->plt->size != 0)
9811 if (!add_dynamic_entry (DT_PLTGOT, 0)
9812 || !add_dynamic_entry (DT_PLTRELSZ, 0)
9813 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
9814 || !add_dynamic_entry (DT_JMPREL, 0)
9815 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
9819 if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
9821 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
9822 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
9826 tls_opt = (!htab->no_tls_get_addr_opt
9827 && htab->tls_get_addr_fd != NULL
9828 && htab->tls_get_addr_fd->elf.plt.plist != NULL);
9829 if (tls_opt || !htab->opd_abi)
9831 if (!add_dynamic_entry (DT_PPC64_OPT, tls_opt ? PPC64_OPT_TLS : 0))
9837 if (!add_dynamic_entry (DT_RELA, 0)
9838 || !add_dynamic_entry (DT_RELASZ, 0)
9839 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
9842 /* If any dynamic relocs apply to a read-only section,
9843 then we need a DT_TEXTREL entry. */
9844 if ((info->flags & DF_TEXTREL) == 0)
9845 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
9847 if ((info->flags & DF_TEXTREL) != 0)
9849 if (!add_dynamic_entry (DT_TEXTREL, 0))
9854 #undef add_dynamic_entry
9859 /* Determine the type of stub needed, if any, for a call. */
9861 static inline enum ppc_stub_type
9862 ppc_type_of_stub (asection *input_sec,
9863 const Elf_Internal_Rela *rel,
9864 struct ppc_link_hash_entry **hash,
9865 struct plt_entry **plt_ent,
9866 bfd_vma destination,
9867 unsigned long local_off)
9869 struct ppc_link_hash_entry *h = *hash;
9871 bfd_vma branch_offset;
9872 bfd_vma max_branch_offset;
9873 enum elf_ppc64_reloc_type r_type;
9877 struct plt_entry *ent;
9878 struct ppc_link_hash_entry *fdh = h;
9880 && h->oh->is_func_descriptor)
9882 fdh = ppc_follow_link (h->oh);
9886 for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
9887 if (ent->addend == rel->r_addend
9888 && ent->plt.offset != (bfd_vma) -1)
9891 return ppc_stub_plt_call;
9894 /* Here, we know we don't have a plt entry. If we don't have a
9895 either a defined function descriptor or a defined entry symbol
9896 in a regular object file, then it is pointless trying to make
9897 any other type of stub. */
9898 if (!is_static_defined (&fdh->elf)
9899 && !is_static_defined (&h->elf))
9900 return ppc_stub_none;
9902 else if (elf_local_got_ents (input_sec->owner) != NULL)
9904 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner);
9905 struct plt_entry **local_plt = (struct plt_entry **)
9906 elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info;
9907 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
9909 if (local_plt[r_symndx] != NULL)
9911 struct plt_entry *ent;
9913 for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next)
9914 if (ent->addend == rel->r_addend
9915 && ent->plt.offset != (bfd_vma) -1)
9918 return ppc_stub_plt_call;
9923 /* Determine where the call point is. */
9924 location = (input_sec->output_offset
9925 + input_sec->output_section->vma
9928 branch_offset = destination - location;
9929 r_type = ELF64_R_TYPE (rel->r_info);
9931 /* Determine if a long branch stub is needed. */
9932 max_branch_offset = 1 << 25;
9933 if (r_type != R_PPC64_REL24)
9934 max_branch_offset = 1 << 15;
9936 if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
9937 /* We need a stub. Figure out whether a long_branch or plt_branch
9939 return ppc_stub_long_branch;
9941 return ppc_stub_none;
9944 /* With power7 weakly ordered memory model, it is possible for ld.so
9945 to update a plt entry in one thread and have another thread see a
9946 stale zero toc entry. To avoid this we need some sort of acquire
9947 barrier in the call stub. One solution is to make the load of the
9948 toc word seem to appear to depend on the load of the function entry
9949 word. Another solution is to test for r2 being zero, and branch to
9950 the appropriate glink entry if so.
9952 . fake dep barrier compare
9953 . ld 12,xxx(2) ld 12,xxx(2)
9955 . xor 11,12,12 ld 2,xxx+8(2)
9956 . add 2,2,11 cmpldi 2,0
9957 . ld 2,xxx+8(2) bnectr+
9958 . bctr b <glink_entry>
9960 The solution involving the compare turns out to be faster, so
9961 that's what we use unless the branch won't reach. */
9963 #define ALWAYS_USE_FAKE_DEP 0
9964 #define ALWAYS_EMIT_R2SAVE 0
9966 #define PPC_LO(v) ((v) & 0xffff)
9967 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9968 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9970 static inline unsigned int
9971 plt_stub_size (struct ppc_link_hash_table *htab,
9972 struct ppc_stub_hash_entry *stub_entry,
9977 if (ALWAYS_EMIT_R2SAVE
9978 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
9980 if (PPC_HA (off) != 0)
9985 if (htab->plt_static_chain)
9987 if (htab->plt_thread_safe)
9989 if (PPC_HA (off + 8 + 8 * htab->plt_static_chain) != PPC_HA (off))
9992 if (stub_entry->h != NULL
9993 && (stub_entry->h == htab->tls_get_addr_fd
9994 || stub_entry->h == htab->tls_get_addr)
9995 && !htab->no_tls_get_addr_opt)
10000 /* If this stub would cross fewer 2**plt_stub_align boundaries if we align,
10001 then return the padding needed to do so. */
10002 static inline unsigned int
10003 plt_stub_pad (struct ppc_link_hash_table *htab,
10004 struct ppc_stub_hash_entry *stub_entry,
10007 int stub_align = 1 << htab->plt_stub_align;
10008 unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
10009 bfd_vma stub_off = stub_entry->stub_sec->size;
10011 if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
10012 > (stub_size & -stub_align))
10013 return stub_align - (stub_off & (stub_align - 1));
10017 /* Build a .plt call stub. */
10019 static inline bfd_byte *
10020 build_plt_stub (struct ppc_link_hash_table *htab,
10021 struct ppc_stub_hash_entry *stub_entry,
10022 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10024 bfd *obfd = htab->stub_bfd;
10025 bfd_boolean plt_load_toc = htab->opd_abi;
10026 bfd_boolean plt_static_chain = htab->plt_static_chain;
10027 bfd_boolean plt_thread_safe = htab->plt_thread_safe;
10028 bfd_boolean use_fake_dep = plt_thread_safe;
10029 bfd_vma cmp_branch_off = 0;
10031 if (!ALWAYS_USE_FAKE_DEP
10034 && !(stub_entry->h != NULL
10035 && (stub_entry->h == htab->tls_get_addr_fd
10036 || stub_entry->h == htab->tls_get_addr)
10037 && !htab->no_tls_get_addr_opt))
10039 bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
10040 bfd_vma pltindex = ((pltoff - PLT_INITIAL_ENTRY_SIZE (htab))
10041 / PLT_ENTRY_SIZE (htab));
10042 bfd_vma glinkoff = GLINK_CALL_STUB_SIZE + pltindex * 8;
10045 if (pltindex > 32768)
10046 glinkoff += (pltindex - 32768) * 4;
10048 + htab->glink->output_offset
10049 + htab->glink->output_section->vma);
10050 from = (p - stub_entry->stub_sec->contents
10051 + 4 * (ALWAYS_EMIT_R2SAVE
10052 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10053 + 4 * (PPC_HA (offset) != 0)
10054 + 4 * (PPC_HA (offset + 8 + 8 * plt_static_chain)
10055 != PPC_HA (offset))
10056 + 4 * (plt_static_chain != 0)
10058 + stub_entry->stub_sec->output_offset
10059 + stub_entry->stub_sec->output_section->vma);
10060 cmp_branch_off = to - from;
10061 use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
10064 if (PPC_HA (offset) != 0)
10068 if (ALWAYS_EMIT_R2SAVE
10069 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10070 r[0].r_offset += 4;
10071 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
10072 r[1].r_offset = r[0].r_offset + 4;
10073 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10074 r[1].r_addend = r[0].r_addend;
10077 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10079 r[2].r_offset = r[1].r_offset + 4;
10080 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO);
10081 r[2].r_addend = r[0].r_addend;
10085 r[2].r_offset = r[1].r_offset + 8 + 8 * use_fake_dep;
10086 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10087 r[2].r_addend = r[0].r_addend + 8;
10088 if (plt_static_chain)
10090 r[3].r_offset = r[2].r_offset + 4;
10091 r[3].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10092 r[3].r_addend = r[0].r_addend + 16;
10097 if (ALWAYS_EMIT_R2SAVE
10098 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10099 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10100 bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
10101 bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
10103 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10105 bfd_put_32 (obfd, ADDI_R11_R11 | PPC_LO (offset), p), p += 4;
10108 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10113 bfd_put_32 (obfd, XOR_R2_R12_R12, p), p += 4;
10114 bfd_put_32 (obfd, ADD_R11_R11_R2, p), p += 4;
10116 bfd_put_32 (obfd, LD_R2_0R11 | PPC_LO (offset + 8), p), p += 4;
10117 if (plt_static_chain)
10118 bfd_put_32 (obfd, LD_R11_0R11 | PPC_LO (offset + 16), p), p += 4;
10125 if (ALWAYS_EMIT_R2SAVE
10126 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10127 r[0].r_offset += 4;
10128 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10131 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10133 r[1].r_offset = r[0].r_offset + 4;
10134 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16);
10135 r[1].r_addend = r[0].r_addend;
10139 r[1].r_offset = r[0].r_offset + 8 + 8 * use_fake_dep;
10140 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10141 r[1].r_addend = r[0].r_addend + 8 + 8 * plt_static_chain;
10142 if (plt_static_chain)
10144 r[2].r_offset = r[1].r_offset + 4;
10145 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10146 r[2].r_addend = r[0].r_addend + 8;
10151 if (ALWAYS_EMIT_R2SAVE
10152 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10153 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10154 bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p), p += 4;
10156 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10158 bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4;
10161 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10166 bfd_put_32 (obfd, XOR_R11_R12_R12, p), p += 4;
10167 bfd_put_32 (obfd, ADD_R2_R2_R11, p), p += 4;
10169 if (plt_static_chain)
10170 bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4;
10171 bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4;
10174 if (plt_load_toc && plt_thread_safe && !use_fake_dep)
10176 bfd_put_32 (obfd, CMPLDI_R2_0, p), p += 4;
10177 bfd_put_32 (obfd, BNECTR_P4, p), p += 4;
10178 bfd_put_32 (obfd, B_DOT | (cmp_branch_off & 0x3fffffc), p), p += 4;
10181 bfd_put_32 (obfd, BCTR, p), p += 4;
10185 /* Build a special .plt call stub for __tls_get_addr. */
10187 #define LD_R11_0R3 0xe9630000
10188 #define LD_R12_0R3 0xe9830000
10189 #define MR_R0_R3 0x7c601b78
10190 #define CMPDI_R11_0 0x2c2b0000
10191 #define ADD_R3_R12_R13 0x7c6c6a14
10192 #define BEQLR 0x4d820020
10193 #define MR_R3_R0 0x7c030378
10194 #define STD_R11_0R1 0xf9610000
10195 #define BCTRL 0x4e800421
10196 #define LD_R11_0R1 0xe9610000
10197 #define MTLR_R11 0x7d6803a6
10199 static inline bfd_byte *
10200 build_tls_get_addr_stub (struct ppc_link_hash_table *htab,
10201 struct ppc_stub_hash_entry *stub_entry,
10202 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10204 bfd *obfd = htab->stub_bfd;
10206 bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
10207 bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
10208 bfd_put_32 (obfd, MR_R0_R3, p), p += 4;
10209 bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4;
10210 bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4;
10211 bfd_put_32 (obfd, BEQLR, p), p += 4;
10212 bfd_put_32 (obfd, MR_R3_R0, p), p += 4;
10213 bfd_put_32 (obfd, MFLR_R11, p), p += 4;
10214 bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10217 r[0].r_offset += 9 * 4;
10218 p = build_plt_stub (htab, stub_entry, p, offset, r);
10219 bfd_put_32 (obfd, BCTRL, p - 4);
10221 bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10222 bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p), p += 4;
10223 bfd_put_32 (obfd, MTLR_R11, p), p += 4;
10224 bfd_put_32 (obfd, BLR, p), p += 4;
10229 static Elf_Internal_Rela *
10230 get_relocs (asection *sec, int count)
10232 Elf_Internal_Rela *relocs;
10233 struct bfd_elf_section_data *elfsec_data;
10235 elfsec_data = elf_section_data (sec);
10236 relocs = elfsec_data->relocs;
10237 if (relocs == NULL)
10239 bfd_size_type relsize;
10240 relsize = sec->reloc_count * sizeof (*relocs);
10241 relocs = bfd_alloc (sec->owner, relsize);
10242 if (relocs == NULL)
10244 elfsec_data->relocs = relocs;
10245 elfsec_data->rela.hdr = bfd_zalloc (sec->owner,
10246 sizeof (Elf_Internal_Shdr));
10247 if (elfsec_data->rela.hdr == NULL)
10249 elfsec_data->rela.hdr->sh_size = (sec->reloc_count
10250 * sizeof (Elf64_External_Rela));
10251 elfsec_data->rela.hdr->sh_entsize = sizeof (Elf64_External_Rela);
10252 sec->reloc_count = 0;
10254 relocs += sec->reloc_count;
10255 sec->reloc_count += count;
10260 get_r2off (struct bfd_link_info *info,
10261 struct ppc_stub_hash_entry *stub_entry)
10263 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10264 bfd_vma r2off = htab->stub_group[stub_entry->target_section->id].toc_off;
10268 /* Support linking -R objects. Get the toc pointer from the
10271 if (!htab->opd_abi)
10273 asection *opd = stub_entry->h->elf.root.u.def.section;
10274 bfd_vma opd_off = stub_entry->h->elf.root.u.def.value;
10276 if (strcmp (opd->name, ".opd") != 0
10277 || opd->reloc_count != 0)
10279 info->callbacks->einfo (_("%P: cannot find opd entry toc for `%T'\n"),
10280 stub_entry->h->elf.root.root.string);
10281 bfd_set_error (bfd_error_bad_value);
10284 if (!bfd_get_section_contents (opd->owner, opd, buf, opd_off + 8, 8))
10286 r2off = bfd_get_64 (opd->owner, buf);
10287 r2off -= elf_gp (info->output_bfd);
10289 r2off -= htab->stub_group[stub_entry->id_sec->id].toc_off;
10294 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
10296 struct ppc_stub_hash_entry *stub_entry;
10297 struct ppc_branch_hash_entry *br_entry;
10298 struct bfd_link_info *info;
10299 struct ppc_link_hash_table *htab;
10304 Elf_Internal_Rela *r;
10307 /* Massage our args to the form they really have. */
10308 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
10311 htab = ppc_hash_table (info);
10315 /* Make a note of the offset within the stubs for this entry. */
10316 stub_entry->stub_offset = stub_entry->stub_sec->size;
10317 loc = stub_entry->stub_sec->contents + stub_entry->stub_offset;
10319 htab->stub_count[stub_entry->stub_type - 1] += 1;
10320 switch (stub_entry->stub_type)
10322 case ppc_stub_long_branch:
10323 case ppc_stub_long_branch_r2off:
10324 /* Branches are relative. This is where we are going to. */
10325 dest = (stub_entry->target_value
10326 + stub_entry->target_section->output_offset
10327 + stub_entry->target_section->output_section->vma);
10328 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10331 /* And this is where we are coming from. */
10332 off -= (stub_entry->stub_offset
10333 + stub_entry->stub_sec->output_offset
10334 + stub_entry->stub_sec->output_section->vma);
10337 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
10339 bfd_vma r2off = get_r2off (info, stub_entry);
10343 htab->stub_error = TRUE;
10346 bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
10349 if (PPC_HA (r2off) != 0)
10352 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
10355 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
10359 bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
10361 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
10363 info->callbacks->einfo
10364 (_("%P: long branch stub `%s' offset overflow\n"),
10365 stub_entry->root.string);
10366 htab->stub_error = TRUE;
10370 if (info->emitrelocations)
10372 r = get_relocs (stub_entry->stub_sec, 1);
10375 r->r_offset = loc - stub_entry->stub_sec->contents;
10376 r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
10377 r->r_addend = dest;
10378 if (stub_entry->h != NULL)
10380 struct elf_link_hash_entry **hashes;
10381 unsigned long symndx;
10382 struct ppc_link_hash_entry *h;
10384 hashes = elf_sym_hashes (htab->stub_bfd);
10385 if (hashes == NULL)
10387 bfd_size_type hsize;
10389 hsize = (htab->stub_globals + 1) * sizeof (*hashes);
10390 hashes = bfd_zalloc (htab->stub_bfd, hsize);
10391 if (hashes == NULL)
10393 elf_sym_hashes (htab->stub_bfd) = hashes;
10394 htab->stub_globals = 1;
10396 symndx = htab->stub_globals++;
10398 hashes[symndx] = &h->elf;
10399 r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
10400 if (h->oh != NULL && h->oh->is_func)
10401 h = ppc_follow_link (h->oh);
10402 if (h->elf.root.u.def.section != stub_entry->target_section)
10403 /* H is an opd symbol. The addend must be zero. */
10407 off = (h->elf.root.u.def.value
10408 + h->elf.root.u.def.section->output_offset
10409 + h->elf.root.u.def.section->output_section->vma);
10410 r->r_addend -= off;
10416 case ppc_stub_plt_branch:
10417 case ppc_stub_plt_branch_r2off:
10418 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
10419 stub_entry->root.string + 9,
10421 if (br_entry == NULL)
10423 info->callbacks->einfo (_("%P: can't find branch stub `%s'\n"),
10424 stub_entry->root.string);
10425 htab->stub_error = TRUE;
10429 dest = (stub_entry->target_value
10430 + stub_entry->target_section->output_offset
10431 + stub_entry->target_section->output_section->vma);
10432 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
10433 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10435 bfd_put_64 (htab->brlt->owner, dest,
10436 htab->brlt->contents + br_entry->offset);
10438 if (br_entry->iter == htab->stub_iteration)
10440 br_entry->iter = 0;
10442 if (htab->relbrlt != NULL)
10444 /* Create a reloc for the branch lookup table entry. */
10445 Elf_Internal_Rela rela;
10448 rela.r_offset = (br_entry->offset
10449 + htab->brlt->output_offset
10450 + htab->brlt->output_section->vma);
10451 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
10452 rela.r_addend = dest;
10454 rl = htab->relbrlt->contents;
10455 rl += (htab->relbrlt->reloc_count++
10456 * sizeof (Elf64_External_Rela));
10457 bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
10459 else if (info->emitrelocations)
10461 r = get_relocs (htab->brlt, 1);
10464 /* brlt, being SEC_LINKER_CREATED does not go through the
10465 normal reloc processing. Symbols and offsets are not
10466 translated from input file to output file form, so
10467 set up the offset per the output file. */
10468 r->r_offset = (br_entry->offset
10469 + htab->brlt->output_offset
10470 + htab->brlt->output_section->vma);
10471 r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
10472 r->r_addend = dest;
10476 dest = (br_entry->offset
10477 + htab->brlt->output_offset
10478 + htab->brlt->output_section->vma);
10481 - elf_gp (htab->brlt->output_section->owner)
10482 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10484 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
10486 info->callbacks->einfo
10487 (_("%P: linkage table error against `%T'\n"),
10488 stub_entry->root.string);
10489 bfd_set_error (bfd_error_bad_value);
10490 htab->stub_error = TRUE;
10494 if (info->emitrelocations)
10496 r = get_relocs (stub_entry->stub_sec, 1 + (PPC_HA (off) != 0));
10499 r[0].r_offset = loc - stub_entry->stub_sec->contents;
10500 if (bfd_big_endian (info->output_bfd))
10501 r[0].r_offset += 2;
10502 if (stub_entry->stub_type == ppc_stub_plt_branch_r2off
10504 r[0].r_offset += 4;
10505 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10506 r[0].r_addend = dest;
10507 if (PPC_HA (off) != 0)
10509 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
10510 r[1].r_offset = r[0].r_offset + 4;
10511 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10512 r[1].r_addend = r[0].r_addend;
10516 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
10519 if (PPC_HA (off) != 0)
10522 bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
10524 bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
10529 bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
10534 bfd_vma r2off = get_r2off (info, stub_entry);
10538 htab->stub_error = TRUE;
10542 bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
10545 if (PPC_HA (off) != 0)
10548 bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
10550 bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
10555 bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
10559 if (PPC_HA (r2off) != 0)
10562 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
10565 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
10568 bfd_put_32 (htab->stub_bfd, MTCTR_R12, loc);
10570 bfd_put_32 (htab->stub_bfd, BCTR, loc);
10573 case ppc_stub_plt_call:
10574 case ppc_stub_plt_call_r2save:
10575 if (stub_entry->h != NULL
10576 && stub_entry->h->is_func_descriptor
10577 && stub_entry->h->oh != NULL)
10579 struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
10581 /* If the old-ABI "dot-symbol" is undefined make it weak so
10582 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
10583 FIXME: We used to define the symbol on one of the call
10584 stubs instead, which is why we test symbol section id
10585 against htab->top_id in various places. Likely all
10586 these checks could now disappear. */
10587 if (fh->elf.root.type == bfd_link_hash_undefined)
10588 fh->elf.root.type = bfd_link_hash_undefweak;
10589 /* Stop undo_symbol_twiddle changing it back to undefined. */
10590 fh->was_undefined = 0;
10593 /* Now build the stub. */
10594 dest = stub_entry->plt_ent->plt.offset & ~1;
10595 if (dest >= (bfd_vma) -2)
10599 if (!htab->elf.dynamic_sections_created
10600 || stub_entry->h == NULL
10601 || stub_entry->h->elf.dynindx == -1)
10604 dest += plt->output_offset + plt->output_section->vma;
10606 if (stub_entry->h == NULL
10607 && (stub_entry->plt_ent->plt.offset & 1) == 0)
10609 Elf_Internal_Rela rela;
10612 rela.r_offset = dest;
10614 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
10616 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
10617 rela.r_addend = (stub_entry->target_value
10618 + stub_entry->target_section->output_offset
10619 + stub_entry->target_section->output_section->vma);
10621 rl = (htab->reliplt->contents
10622 + (htab->reliplt->reloc_count++
10623 * sizeof (Elf64_External_Rela)));
10624 bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl);
10625 stub_entry->plt_ent->plt.offset |= 1;
10629 - elf_gp (plt->output_section->owner)
10630 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10632 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
10634 info->callbacks->einfo
10635 (_("%P: linkage table error against `%T'\n"),
10636 stub_entry->h != NULL
10637 ? stub_entry->h->elf.root.root.string
10639 bfd_set_error (bfd_error_bad_value);
10640 htab->stub_error = TRUE;
10644 if (htab->plt_stub_align != 0)
10646 unsigned pad = plt_stub_pad (htab, stub_entry, off);
10648 stub_entry->stub_sec->size += pad;
10649 stub_entry->stub_offset = stub_entry->stub_sec->size;
10654 if (info->emitrelocations)
10656 r = get_relocs (stub_entry->stub_sec,
10658 + (PPC_HA (off) != 0)
10659 + (htab->plt_static_chain
10660 && PPC_HA (off + 16) == PPC_HA (off))));
10663 r[0].r_offset = loc - stub_entry->stub_sec->contents;
10664 if (bfd_big_endian (info->output_bfd))
10665 r[0].r_offset += 2;
10666 r[0].r_addend = dest;
10668 if (stub_entry->h != NULL
10669 && (stub_entry->h == htab->tls_get_addr_fd
10670 || stub_entry->h == htab->tls_get_addr)
10671 && !htab->no_tls_get_addr_opt)
10672 p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
10674 p = build_plt_stub (htab, stub_entry, loc, off, r);
10683 stub_entry->stub_sec->size += size;
10685 if (htab->emit_stub_syms)
10687 struct elf_link_hash_entry *h;
10690 const char *const stub_str[] = { "long_branch",
10691 "long_branch_r2off",
10693 "plt_branch_r2off",
10697 len1 = strlen (stub_str[stub_entry->stub_type - 1]);
10698 len2 = strlen (stub_entry->root.string);
10699 name = bfd_malloc (len1 + len2 + 2);
10702 memcpy (name, stub_entry->root.string, 9);
10703 memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
10704 memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
10705 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
10708 if (h->root.type == bfd_link_hash_new)
10710 h->root.type = bfd_link_hash_defined;
10711 h->root.u.def.section = stub_entry->stub_sec;
10712 h->root.u.def.value = stub_entry->stub_offset;
10713 h->ref_regular = 1;
10714 h->def_regular = 1;
10715 h->ref_regular_nonweak = 1;
10716 h->forced_local = 1;
10724 /* As above, but don't actually build the stub. Just bump offset so
10725 we know stub section sizes, and select plt_branch stubs where
10726 long_branch stubs won't do. */
10729 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
10731 struct ppc_stub_hash_entry *stub_entry;
10732 struct bfd_link_info *info;
10733 struct ppc_link_hash_table *htab;
10737 /* Massage our args to the form they really have. */
10738 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
10741 htab = ppc_hash_table (info);
10745 if (stub_entry->stub_type == ppc_stub_plt_call
10746 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10749 off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
10750 if (off >= (bfd_vma) -2)
10753 if (!htab->elf.dynamic_sections_created
10754 || stub_entry->h == NULL
10755 || stub_entry->h->elf.dynindx == -1)
10757 off += (plt->output_offset
10758 + plt->output_section->vma
10759 - elf_gp (plt->output_section->owner)
10760 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10762 size = plt_stub_size (htab, stub_entry, off);
10763 if (htab->plt_stub_align)
10764 size += plt_stub_pad (htab, stub_entry, off);
10765 if (info->emitrelocations)
10767 stub_entry->stub_sec->reloc_count
10768 += ((PPC_HA (off) != 0)
10770 ? 2 + (htab->plt_static_chain
10771 && PPC_HA (off + 16) == PPC_HA (off))
10773 stub_entry->stub_sec->flags |= SEC_RELOC;
10778 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
10781 bfd_vma local_off = 0;
10783 off = (stub_entry->target_value
10784 + stub_entry->target_section->output_offset
10785 + stub_entry->target_section->output_section->vma);
10786 off -= (stub_entry->stub_sec->size
10787 + stub_entry->stub_sec->output_offset
10788 + stub_entry->stub_sec->output_section->vma);
10790 /* Reset the stub type from the plt variant in case we now
10791 can reach with a shorter stub. */
10792 if (stub_entry->stub_type >= ppc_stub_plt_branch)
10793 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
10796 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
10798 r2off = get_r2off (info, stub_entry);
10799 if (r2off == 0 && htab->opd_abi)
10801 htab->stub_error = TRUE;
10805 if (PPC_HA (r2off) != 0)
10810 local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10812 /* If the branch offset if too big, use a ppc_stub_plt_branch.
10813 Do the same for -R objects without function descriptors. */
10814 if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off
10815 || (stub_entry->stub_type == ppc_stub_long_branch_r2off
10818 struct ppc_branch_hash_entry *br_entry;
10820 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
10821 stub_entry->root.string + 9,
10823 if (br_entry == NULL)
10825 info->callbacks->einfo (_("%P: can't build branch stub `%s'\n"),
10826 stub_entry->root.string);
10827 htab->stub_error = TRUE;
10831 if (br_entry->iter != htab->stub_iteration)
10833 br_entry->iter = htab->stub_iteration;
10834 br_entry->offset = htab->brlt->size;
10835 htab->brlt->size += 8;
10837 if (htab->relbrlt != NULL)
10838 htab->relbrlt->size += sizeof (Elf64_External_Rela);
10839 else if (info->emitrelocations)
10841 htab->brlt->reloc_count += 1;
10842 htab->brlt->flags |= SEC_RELOC;
10846 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
10847 off = (br_entry->offset
10848 + htab->brlt->output_offset
10849 + htab->brlt->output_section->vma
10850 - elf_gp (htab->brlt->output_section->owner)
10851 - htab->stub_group[stub_entry->id_sec->id].toc_off);
10853 if (info->emitrelocations)
10855 stub_entry->stub_sec->reloc_count += 1 + (PPC_HA (off) != 0);
10856 stub_entry->stub_sec->flags |= SEC_RELOC;
10859 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
10863 if (PPC_HA (off) != 0)
10869 if (PPC_HA (off) != 0)
10872 if (PPC_HA (r2off) != 0)
10876 else if (info->emitrelocations)
10878 stub_entry->stub_sec->reloc_count += 1;
10879 stub_entry->stub_sec->flags |= SEC_RELOC;
10883 stub_entry->stub_sec->size += size;
10887 /* Set up various things so that we can make a list of input sections
10888 for each output section included in the link. Returns -1 on error,
10889 0 when no stubs will be needed, and 1 on success. */
10892 ppc64_elf_setup_section_lists
10893 (struct bfd_link_info *info,
10894 asection *(*add_stub_section) (const char *, asection *),
10895 void (*layout_sections_again) (void))
10898 int top_id, top_index, id;
10900 asection **input_list;
10902 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10906 /* Stash our params away. */
10907 htab->add_stub_section = add_stub_section;
10908 htab->layout_sections_again = layout_sections_again;
10910 /* Find the top input section id. */
10911 for (input_bfd = info->input_bfds, top_id = 3;
10913 input_bfd = input_bfd->link_next)
10915 for (section = input_bfd->sections;
10917 section = section->next)
10919 if (top_id < section->id)
10920 top_id = section->id;
10924 htab->top_id = top_id;
10925 amt = sizeof (struct map_stub) * (top_id + 1);
10926 htab->stub_group = bfd_zmalloc (amt);
10927 if (htab->stub_group == NULL)
10930 /* Set toc_off for com, und, abs and ind sections. */
10931 for (id = 0; id < 3; id++)
10932 htab->stub_group[id].toc_off = TOC_BASE_OFF;
10934 /* We can't use output_bfd->section_count here to find the top output
10935 section index as some sections may have been removed, and
10936 strip_excluded_output_sections doesn't renumber the indices. */
10937 for (section = info->output_bfd->sections, top_index = 0;
10939 section = section->next)
10941 if (top_index < section->index)
10942 top_index = section->index;
10945 htab->top_index = top_index;
10946 amt = sizeof (asection *) * (top_index + 1);
10947 input_list = bfd_zmalloc (amt);
10948 htab->input_list = input_list;
10949 if (input_list == NULL)
10955 /* Set up for first pass at multitoc partitioning. */
10958 ppc64_elf_start_multitoc_partition (struct bfd_link_info *info)
10960 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10962 htab->toc_curr = ppc64_elf_set_toc (info, info->output_bfd);
10963 htab->toc_bfd = NULL;
10964 htab->toc_first_sec = NULL;
10967 /* The linker repeatedly calls this function for each TOC input section
10968 and linker generated GOT section. Group input bfds such that the toc
10969 within a group is less than 64k in size. */
10972 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
10974 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10975 bfd_vma addr, off, limit;
10980 if (!htab->second_toc_pass)
10982 /* Keep track of the first .toc or .got section for this input bfd. */
10983 bfd_boolean new_bfd = htab->toc_bfd != isec->owner;
10987 htab->toc_bfd = isec->owner;
10988 htab->toc_first_sec = isec;
10991 addr = isec->output_offset + isec->output_section->vma;
10992 off = addr - htab->toc_curr;
10993 limit = 0x80008000;
10994 if (ppc64_elf_tdata (isec->owner)->has_small_toc_reloc)
10996 if (off + isec->size > limit)
10998 addr = (htab->toc_first_sec->output_offset
10999 + htab->toc_first_sec->output_section->vma);
11000 htab->toc_curr = addr;
11003 /* toc_curr is the base address of this toc group. Set elf_gp
11004 for the input section to be the offset relative to the
11005 output toc base plus 0x8000. Making the input elf_gp an
11006 offset allows us to move the toc as a whole without
11007 recalculating input elf_gp. */
11008 off = htab->toc_curr - elf_gp (isec->output_section->owner);
11009 off += TOC_BASE_OFF;
11011 /* Die if someone uses a linker script that doesn't keep input
11012 file .toc and .got together. */
11014 && elf_gp (isec->owner) != 0
11015 && elf_gp (isec->owner) != off)
11018 elf_gp (isec->owner) = off;
11022 /* During the second pass toc_first_sec points to the start of
11023 a toc group, and toc_curr is used to track the old elf_gp.
11024 We use toc_bfd to ensure we only look at each bfd once. */
11025 if (htab->toc_bfd == isec->owner)
11027 htab->toc_bfd = isec->owner;
11029 if (htab->toc_first_sec == NULL
11030 || htab->toc_curr != elf_gp (isec->owner))
11032 htab->toc_curr = elf_gp (isec->owner);
11033 htab->toc_first_sec = isec;
11035 addr = (htab->toc_first_sec->output_offset
11036 + htab->toc_first_sec->output_section->vma);
11037 off = addr - elf_gp (isec->output_section->owner) + TOC_BASE_OFF;
11038 elf_gp (isec->owner) = off;
11043 /* Called via elf_link_hash_traverse to merge GOT entries for global
11047 merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
11049 if (h->root.type == bfd_link_hash_indirect)
11052 merge_got_entries (&h->got.glist);
11057 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11061 reallocate_got (struct elf_link_hash_entry *h, void *inf)
11063 struct got_entry *gent;
11065 if (h->root.type == bfd_link_hash_indirect)
11068 for (gent = h->got.glist; gent != NULL; gent = gent->next)
11069 if (!gent->is_indirect)
11070 allocate_got (h, (struct bfd_link_info *) inf, gent);
11074 /* Called on the first multitoc pass after the last call to
11075 ppc64_elf_next_toc_section. This function removes duplicate GOT
11079 ppc64_elf_layout_multitoc (struct bfd_link_info *info)
11081 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11082 struct bfd *ibfd, *ibfd2;
11083 bfd_boolean done_something;
11085 htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd);
11087 if (!htab->do_multi_toc)
11090 /* Merge global sym got entries within a toc group. */
11091 elf_link_hash_traverse (&htab->elf, merge_global_got, info);
11093 /* And tlsld_got. */
11094 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11096 struct got_entry *ent, *ent2;
11098 if (!is_ppc64_elf (ibfd))
11101 ent = ppc64_tlsld_got (ibfd);
11102 if (!ent->is_indirect
11103 && ent->got.offset != (bfd_vma) -1)
11105 for (ibfd2 = ibfd->link_next; ibfd2 != NULL; ibfd2 = ibfd2->link_next)
11107 if (!is_ppc64_elf (ibfd2))
11110 ent2 = ppc64_tlsld_got (ibfd2);
11111 if (!ent2->is_indirect
11112 && ent2->got.offset != (bfd_vma) -1
11113 && elf_gp (ibfd2) == elf_gp (ibfd))
11115 ent2->is_indirect = TRUE;
11116 ent2->got.ent = ent;
11122 /* Zap sizes of got sections. */
11123 htab->reliplt->rawsize = htab->reliplt->size;
11124 htab->reliplt->size -= htab->got_reli_size;
11125 htab->got_reli_size = 0;
11127 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11129 asection *got, *relgot;
11131 if (!is_ppc64_elf (ibfd))
11134 got = ppc64_elf_tdata (ibfd)->got;
11137 got->rawsize = got->size;
11139 relgot = ppc64_elf_tdata (ibfd)->relgot;
11140 relgot->rawsize = relgot->size;
11145 /* Now reallocate the got, local syms first. We don't need to
11146 allocate section contents again since we never increase size. */
11147 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11149 struct got_entry **lgot_ents;
11150 struct got_entry **end_lgot_ents;
11151 struct plt_entry **local_plt;
11152 struct plt_entry **end_local_plt;
11153 unsigned char *lgot_masks;
11154 bfd_size_type locsymcount;
11155 Elf_Internal_Shdr *symtab_hdr;
11158 if (!is_ppc64_elf (ibfd))
11161 lgot_ents = elf_local_got_ents (ibfd);
11165 symtab_hdr = &elf_symtab_hdr (ibfd);
11166 locsymcount = symtab_hdr->sh_info;
11167 end_lgot_ents = lgot_ents + locsymcount;
11168 local_plt = (struct plt_entry **) end_lgot_ents;
11169 end_local_plt = local_plt + locsymcount;
11170 lgot_masks = (unsigned char *) end_local_plt;
11171 s = ppc64_elf_tdata (ibfd)->got;
11172 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
11174 struct got_entry *ent;
11176 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
11178 unsigned int ent_size = 8;
11179 unsigned int rel_size = sizeof (Elf64_External_Rela);
11181 ent->got.offset = s->size;
11182 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
11187 s->size += ent_size;
11188 if ((*lgot_masks & PLT_IFUNC) != 0)
11190 htab->reliplt->size += rel_size;
11191 htab->got_reli_size += rel_size;
11193 else if (info->shared)
11195 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11196 srel->size += rel_size;
11202 elf_link_hash_traverse (&htab->elf, reallocate_got, info);
11204 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11206 struct got_entry *ent;
11208 if (!is_ppc64_elf (ibfd))
11211 ent = ppc64_tlsld_got (ibfd);
11212 if (!ent->is_indirect
11213 && ent->got.offset != (bfd_vma) -1)
11215 asection *s = ppc64_elf_tdata (ibfd)->got;
11216 ent->got.offset = s->size;
11220 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11221 srel->size += sizeof (Elf64_External_Rela);
11226 done_something = htab->reliplt->rawsize != htab->reliplt->size;
11227 if (!done_something)
11228 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
11232 if (!is_ppc64_elf (ibfd))
11235 got = ppc64_elf_tdata (ibfd)->got;
11238 done_something = got->rawsize != got->size;
11239 if (done_something)
11244 if (done_something)
11245 (*htab->layout_sections_again) ();
11247 /* Set up for second pass over toc sections to recalculate elf_gp
11248 on input sections. */
11249 htab->toc_bfd = NULL;
11250 htab->toc_first_sec = NULL;
11251 htab->second_toc_pass = TRUE;
11252 return done_something;
11255 /* Called after second pass of multitoc partitioning. */
11258 ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info)
11260 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11262 /* After the second pass, toc_curr tracks the TOC offset used
11263 for code sections below in ppc64_elf_next_input_section. */
11264 htab->toc_curr = TOC_BASE_OFF;
11267 /* No toc references were found in ISEC. If the code in ISEC makes no
11268 calls, then there's no need to use toc adjusting stubs when branching
11269 into ISEC. Actually, indirect calls from ISEC are OK as they will
11270 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11271 needed, and 2 if a cyclical call-graph was found but no other reason
11272 for a stub was detected. If called from the top level, a return of
11273 2 means the same as a return of 0. */
11276 toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
11280 /* Mark this section as checked. */
11281 isec->call_check_done = 1;
11283 /* We know none of our code bearing sections will need toc stubs. */
11284 if ((isec->flags & SEC_LINKER_CREATED) != 0)
11287 if (isec->size == 0)
11290 if (isec->output_section == NULL)
11294 if (isec->reloc_count != 0)
11296 Elf_Internal_Rela *relstart, *rel;
11297 Elf_Internal_Sym *local_syms;
11298 struct ppc_link_hash_table *htab;
11300 relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL,
11301 info->keep_memory);
11302 if (relstart == NULL)
11305 /* Look for branches to outside of this section. */
11307 htab = ppc_hash_table (info);
11311 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel)
11313 enum elf_ppc64_reloc_type r_type;
11314 unsigned long r_symndx;
11315 struct elf_link_hash_entry *h;
11316 struct ppc_link_hash_entry *eh;
11317 Elf_Internal_Sym *sym;
11319 struct _opd_sec_data *opd;
11323 r_type = ELF64_R_TYPE (rel->r_info);
11324 if (r_type != R_PPC64_REL24
11325 && r_type != R_PPC64_REL14
11326 && r_type != R_PPC64_REL14_BRTAKEN
11327 && r_type != R_PPC64_REL14_BRNTAKEN)
11330 r_symndx = ELF64_R_SYM (rel->r_info);
11331 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx,
11338 /* Calls to dynamic lib functions go through a plt call stub
11340 eh = (struct ppc_link_hash_entry *) h;
11342 && (eh->elf.plt.plist != NULL
11344 && ppc_follow_link (eh->oh)->elf.plt.plist != NULL)))
11350 if (sym_sec == NULL)
11351 /* Ignore other undefined symbols. */
11354 /* Assume branches to other sections not included in the
11355 link need stubs too, to cover -R and absolute syms. */
11356 if (sym_sec->output_section == NULL)
11363 sym_value = sym->st_value;
11366 if (h->root.type != bfd_link_hash_defined
11367 && h->root.type != bfd_link_hash_defweak)
11369 sym_value = h->root.u.def.value;
11371 sym_value += rel->r_addend;
11373 /* If this branch reloc uses an opd sym, find the code section. */
11374 opd = get_opd_info (sym_sec);
11377 if (h == NULL && opd->adjust != NULL)
11381 adjust = opd->adjust[sym->st_value / 8];
11383 /* Assume deleted functions won't ever be called. */
11385 sym_value += adjust;
11388 dest = opd_entry_value (sym_sec, sym_value,
11389 &sym_sec, NULL, FALSE);
11390 if (dest == (bfd_vma) -1)
11395 + sym_sec->output_offset
11396 + sym_sec->output_section->vma);
11398 /* Ignore branch to self. */
11399 if (sym_sec == isec)
11402 /* If the called function uses the toc, we need a stub. */
11403 if (sym_sec->has_toc_reloc
11404 || sym_sec->makes_toc_func_call)
11410 /* Assume any branch that needs a long branch stub might in fact
11411 need a plt_branch stub. A plt_branch stub uses r2. */
11412 else if (dest - (isec->output_offset
11413 + isec->output_section->vma
11414 + rel->r_offset) + (1 << 25)
11415 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11423 /* If calling back to a section in the process of being
11424 tested, we can't say for sure that no toc adjusting stubs
11425 are needed, so don't return zero. */
11426 else if (sym_sec->call_check_in_progress)
11429 /* Branches to another section that itself doesn't have any TOC
11430 references are OK. Recursively call ourselves to check. */
11431 else if (!sym_sec->call_check_done)
11435 /* Mark current section as indeterminate, so that other
11436 sections that call back to current won't be marked as
11438 isec->call_check_in_progress = 1;
11439 recur = toc_adjusting_stub_needed (info, sym_sec);
11440 isec->call_check_in_progress = 0;
11451 if (local_syms != NULL
11452 && (elf_symtab_hdr (isec->owner).contents
11453 != (unsigned char *) local_syms))
11455 if (elf_section_data (isec)->relocs != relstart)
11460 && isec->map_head.s != NULL
11461 && (strcmp (isec->output_section->name, ".init") == 0
11462 || strcmp (isec->output_section->name, ".fini") == 0))
11464 if (isec->map_head.s->has_toc_reloc
11465 || isec->map_head.s->makes_toc_func_call)
11467 else if (!isec->map_head.s->call_check_done)
11470 isec->call_check_in_progress = 1;
11471 recur = toc_adjusting_stub_needed (info, isec->map_head.s);
11472 isec->call_check_in_progress = 0;
11479 isec->makes_toc_func_call = 1;
11484 /* The linker repeatedly calls this function for each input section,
11485 in the order that input sections are linked into output sections.
11486 Build lists of input sections to determine groupings between which
11487 we may insert linker stubs. */
11490 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
11492 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11497 if ((isec->output_section->flags & SEC_CODE) != 0
11498 && isec->output_section->index <= htab->top_index)
11500 asection **list = htab->input_list + isec->output_section->index;
11501 /* Steal the link_sec pointer for our list. */
11502 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
11503 /* This happens to make the list in reverse order,
11504 which is what we want. */
11505 PREV_SEC (isec) = *list;
11509 if (htab->multi_toc_needed)
11511 /* If a code section has a function that uses the TOC then we need
11512 to use the right TOC (obviously). Also, make sure that .opd gets
11513 the correct TOC value for R_PPC64_TOC relocs that don't have or
11514 can't find their function symbol (shouldn't ever happen now).
11515 Also specially treat .fixup for the linux kernel. .fixup
11516 contains branches, but only back to the function that hit an
11518 if (isec->has_toc_reloc
11519 || (isec->flags & SEC_CODE) == 0
11520 || strcmp (isec->name, ".fixup") == 0)
11522 if (elf_gp (isec->owner) != 0)
11523 htab->toc_curr = elf_gp (isec->owner);
11527 if (!isec->call_check_done
11528 && toc_adjusting_stub_needed (info, isec) < 0)
11530 /* If we make a local call from this section, ie. a branch
11531 without a following nop, then we have no place to put a
11532 toc restoring insn. We must use the same toc group as
11534 Testing makes_toc_func_call actually tests for *any*
11535 calls to functions that need a good toc pointer. A more
11536 precise test would be better, as this one will set
11537 incorrect values for pasted .init/.fini fragments.
11538 (Fixed later in check_pasted_section.) */
11539 if (isec->makes_toc_func_call
11540 && elf_gp (isec->owner) != 0)
11541 htab->toc_curr = elf_gp (isec->owner);
11545 /* Functions that don't use the TOC can belong in any TOC group.
11546 Use the last TOC base. */
11547 htab->stub_group[isec->id].toc_off = htab->toc_curr;
11551 /* Check that all .init and .fini sections use the same toc, if they
11552 have toc relocs. */
11555 check_pasted_section (struct bfd_link_info *info, const char *name)
11557 asection *o = bfd_get_section_by_name (info->output_bfd, name);
11561 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11562 bfd_vma toc_off = 0;
11565 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
11566 if (i->has_toc_reloc)
11569 toc_off = htab->stub_group[i->id].toc_off;
11570 else if (toc_off != htab->stub_group[i->id].toc_off)
11575 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
11576 if (i->makes_toc_func_call)
11578 toc_off = htab->stub_group[i->id].toc_off;
11582 /* Make sure the whole pasted function uses the same toc offset. */
11584 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
11585 htab->stub_group[i->id].toc_off = toc_off;
11591 ppc64_elf_check_init_fini (struct bfd_link_info *info)
11593 return (check_pasted_section (info, ".init")
11594 & check_pasted_section (info, ".fini"));
11597 /* See whether we can group stub sections together. Grouping stub
11598 sections may result in fewer stubs. More importantly, we need to
11599 put all .init* and .fini* stubs at the beginning of the .init or
11600 .fini output sections respectively, because glibc splits the
11601 _init and _fini functions into multiple parts. Putting a stub in
11602 the middle of a function is not a good idea. */
11605 group_sections (struct ppc_link_hash_table *htab,
11606 bfd_size_type stub_group_size,
11607 bfd_boolean stubs_always_before_branch)
11610 bfd_size_type stub14_group_size;
11611 bfd_boolean suppress_size_errors;
11613 suppress_size_errors = FALSE;
11614 stub14_group_size = stub_group_size;
11615 if (stub_group_size == 1)
11617 /* Default values. */
11618 if (stubs_always_before_branch)
11620 stub_group_size = 0x1e00000;
11621 stub14_group_size = 0x7800;
11625 stub_group_size = 0x1c00000;
11626 stub14_group_size = 0x7000;
11628 suppress_size_errors = TRUE;
11631 list = htab->input_list + htab->top_index;
11634 asection *tail = *list;
11635 while (tail != NULL)
11639 bfd_size_type total;
11640 bfd_boolean big_sec;
11644 total = tail->size;
11645 big_sec = total > (ppc64_elf_section_data (tail) != NULL
11646 && ppc64_elf_section_data (tail)->has_14bit_branch
11647 ? stub14_group_size : stub_group_size);
11648 if (big_sec && !suppress_size_errors)
11649 (*_bfd_error_handler) (_("%B section %A exceeds stub group size"),
11650 tail->owner, tail);
11651 curr_toc = htab->stub_group[tail->id].toc_off;
11653 while ((prev = PREV_SEC (curr)) != NULL
11654 && ((total += curr->output_offset - prev->output_offset)
11655 < (ppc64_elf_section_data (prev) != NULL
11656 && ppc64_elf_section_data (prev)->has_14bit_branch
11657 ? stub14_group_size : stub_group_size))
11658 && htab->stub_group[prev->id].toc_off == curr_toc)
11661 /* OK, the size from the start of CURR to the end is less
11662 than stub_group_size and thus can be handled by one stub
11663 section. (or the tail section is itself larger than
11664 stub_group_size, in which case we may be toast.) We
11665 should really be keeping track of the total size of stubs
11666 added here, as stubs contribute to the final output
11667 section size. That's a little tricky, and this way will
11668 only break if stubs added make the total size more than
11669 2^25, ie. for the default stub_group_size, if stubs total
11670 more than 2097152 bytes, or nearly 75000 plt call stubs. */
11673 prev = PREV_SEC (tail);
11674 /* Set up this stub group. */
11675 htab->stub_group[tail->id].link_sec = curr;
11677 while (tail != curr && (tail = prev) != NULL);
11679 /* But wait, there's more! Input sections up to stub_group_size
11680 bytes before the stub section can be handled by it too.
11681 Don't do this if we have a really large section after the
11682 stubs, as adding more stubs increases the chance that
11683 branches may not reach into the stub section. */
11684 if (!stubs_always_before_branch && !big_sec)
11687 while (prev != NULL
11688 && ((total += tail->output_offset - prev->output_offset)
11689 < (ppc64_elf_section_data (prev) != NULL
11690 && ppc64_elf_section_data (prev)->has_14bit_branch
11691 ? stub14_group_size : stub_group_size))
11692 && htab->stub_group[prev->id].toc_off == curr_toc)
11695 prev = PREV_SEC (tail);
11696 htab->stub_group[tail->id].link_sec = curr;
11702 while (list-- != htab->input_list);
11703 free (htab->input_list);
11707 static const unsigned char glink_eh_frame_cie[] =
11709 0, 0, 0, 16, /* length. */
11710 0, 0, 0, 0, /* id. */
11711 1, /* CIE version. */
11712 'z', 'R', 0, /* Augmentation string. */
11713 4, /* Code alignment. */
11714 0x78, /* Data alignment. */
11716 1, /* Augmentation size. */
11717 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
11718 DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
11721 /* Stripping output sections is normally done before dynamic section
11722 symbols have been allocated. This function is called later, and
11723 handles cases like htab->brlt which is mapped to its own output
11727 maybe_strip_output (struct bfd_link_info *info, asection *isec)
11729 if (isec->size == 0
11730 && isec->output_section->size == 0
11731 && !(isec->output_section->flags & SEC_KEEP)
11732 && !bfd_section_removed_from_list (info->output_bfd,
11733 isec->output_section)
11734 && elf_section_data (isec->output_section)->dynindx == 0)
11736 isec->output_section->flags |= SEC_EXCLUDE;
11737 bfd_section_list_remove (info->output_bfd, isec->output_section);
11738 info->output_bfd->section_count--;
11742 /* Determine and set the size of the stub section for a final link.
11744 The basic idea here is to examine all the relocations looking for
11745 PC-relative calls to a target that is unreachable with a "bl"
11749 ppc64_elf_size_stubs (struct bfd_link_info *info, bfd_signed_vma group_size,
11750 bfd_boolean plt_static_chain, int plt_thread_safe,
11751 int plt_stub_align)
11753 bfd_size_type stub_group_size;
11754 bfd_boolean stubs_always_before_branch;
11755 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11760 htab->plt_static_chain = plt_static_chain;
11761 htab->plt_stub_align = plt_stub_align;
11762 if (plt_thread_safe == -1 && !info->executable)
11763 plt_thread_safe = 1;
11764 if (!htab->opd_abi)
11765 plt_thread_safe = 0;
11766 else if (plt_thread_safe == -1)
11768 static const char *const thread_starter[] =
11772 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
11774 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
11775 "mq_notify", "create_timer",
11779 "GOMP_parallel_start",
11780 "GOMP_parallel_loop_static_start",
11781 "GOMP_parallel_loop_dynamic_start",
11782 "GOMP_parallel_loop_guided_start",
11783 "GOMP_parallel_loop_runtime_start",
11784 "GOMP_parallel_sections_start",
11788 for (i = 0; i < sizeof (thread_starter)/ sizeof (thread_starter[0]); i++)
11790 struct elf_link_hash_entry *h;
11791 h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
11792 FALSE, FALSE, TRUE);
11793 plt_thread_safe = h != NULL && h->ref_regular;
11794 if (plt_thread_safe)
11798 htab->plt_thread_safe = plt_thread_safe;
11799 stubs_always_before_branch = group_size < 0;
11800 if (group_size < 0)
11801 stub_group_size = -group_size;
11803 stub_group_size = group_size;
11805 group_sections (htab, stub_group_size, stubs_always_before_branch);
11810 unsigned int bfd_indx;
11811 asection *stub_sec;
11813 htab->stub_iteration += 1;
11815 for (input_bfd = info->input_bfds, bfd_indx = 0;
11817 input_bfd = input_bfd->link_next, bfd_indx++)
11819 Elf_Internal_Shdr *symtab_hdr;
11821 Elf_Internal_Sym *local_syms = NULL;
11823 if (!is_ppc64_elf (input_bfd))
11826 /* We'll need the symbol table in a second. */
11827 symtab_hdr = &elf_symtab_hdr (input_bfd);
11828 if (symtab_hdr->sh_info == 0)
11831 /* Walk over each section attached to the input bfd. */
11832 for (section = input_bfd->sections;
11834 section = section->next)
11836 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
11838 /* If there aren't any relocs, then there's nothing more
11840 if ((section->flags & SEC_RELOC) == 0
11841 || (section->flags & SEC_ALLOC) == 0
11842 || (section->flags & SEC_LOAD) == 0
11843 || (section->flags & SEC_CODE) == 0
11844 || section->reloc_count == 0)
11847 /* If this section is a link-once section that will be
11848 discarded, then don't create any stubs. */
11849 if (section->output_section == NULL
11850 || section->output_section->owner != info->output_bfd)
11853 /* Get the relocs. */
11855 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
11856 info->keep_memory);
11857 if (internal_relocs == NULL)
11858 goto error_ret_free_local;
11860 /* Now examine each relocation. */
11861 irela = internal_relocs;
11862 irelaend = irela + section->reloc_count;
11863 for (; irela < irelaend; irela++)
11865 enum elf_ppc64_reloc_type r_type;
11866 unsigned int r_indx;
11867 enum ppc_stub_type stub_type;
11868 struct ppc_stub_hash_entry *stub_entry;
11869 asection *sym_sec, *code_sec;
11870 bfd_vma sym_value, code_value;
11871 bfd_vma destination;
11872 unsigned long local_off;
11873 bfd_boolean ok_dest;
11874 struct ppc_link_hash_entry *hash;
11875 struct ppc_link_hash_entry *fdh;
11876 struct elf_link_hash_entry *h;
11877 Elf_Internal_Sym *sym;
11879 const asection *id_sec;
11880 struct _opd_sec_data *opd;
11881 struct plt_entry *plt_ent;
11883 r_type = ELF64_R_TYPE (irela->r_info);
11884 r_indx = ELF64_R_SYM (irela->r_info);
11886 if (r_type >= R_PPC64_max)
11888 bfd_set_error (bfd_error_bad_value);
11889 goto error_ret_free_internal;
11892 /* Only look for stubs on branch instructions. */
11893 if (r_type != R_PPC64_REL24
11894 && r_type != R_PPC64_REL14
11895 && r_type != R_PPC64_REL14_BRTAKEN
11896 && r_type != R_PPC64_REL14_BRNTAKEN)
11899 /* Now determine the call target, its name, value,
11901 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
11902 r_indx, input_bfd))
11903 goto error_ret_free_internal;
11904 hash = (struct ppc_link_hash_entry *) h;
11911 sym_value = sym->st_value;
11914 else if (hash->elf.root.type == bfd_link_hash_defined
11915 || hash->elf.root.type == bfd_link_hash_defweak)
11917 sym_value = hash->elf.root.u.def.value;
11918 if (sym_sec->output_section != NULL)
11921 else if (hash->elf.root.type == bfd_link_hash_undefweak
11922 || hash->elf.root.type == bfd_link_hash_undefined)
11924 /* Recognise an old ABI func code entry sym, and
11925 use the func descriptor sym instead if it is
11927 if (hash->elf.root.root.string[0] == '.'
11928 && (fdh = lookup_fdh (hash, htab)) != NULL)
11930 if (fdh->elf.root.type == bfd_link_hash_defined
11931 || fdh->elf.root.type == bfd_link_hash_defweak)
11933 sym_sec = fdh->elf.root.u.def.section;
11934 sym_value = fdh->elf.root.u.def.value;
11935 if (sym_sec->output_section != NULL)
11944 bfd_set_error (bfd_error_bad_value);
11945 goto error_ret_free_internal;
11952 sym_value += irela->r_addend;
11953 destination = (sym_value
11954 + sym_sec->output_offset
11955 + sym_sec->output_section->vma);
11956 local_off = PPC64_LOCAL_ENTRY_OFFSET (hash
11961 code_sec = sym_sec;
11962 code_value = sym_value;
11963 opd = get_opd_info (sym_sec);
11968 if (hash == NULL && opd->adjust != NULL)
11970 long adjust = opd->adjust[sym_value / 8];
11973 code_value += adjust;
11974 sym_value += adjust;
11976 dest = opd_entry_value (sym_sec, sym_value,
11977 &code_sec, &code_value, FALSE);
11978 if (dest != (bfd_vma) -1)
11980 destination = dest;
11983 /* Fixup old ABI sym to point at code
11985 hash->elf.root.type = bfd_link_hash_defweak;
11986 hash->elf.root.u.def.section = code_sec;
11987 hash->elf.root.u.def.value = code_value;
11992 /* Determine what (if any) linker stub is needed. */
11994 stub_type = ppc_type_of_stub (section, irela, &hash,
11995 &plt_ent, destination,
11998 if (stub_type != ppc_stub_plt_call)
12000 /* Check whether we need a TOC adjusting stub.
12001 Since the linker pastes together pieces from
12002 different object files when creating the
12003 _init and _fini functions, it may be that a
12004 call to what looks like a local sym is in
12005 fact a call needing a TOC adjustment. */
12006 if (code_sec != NULL
12007 && code_sec->output_section != NULL
12008 && (htab->stub_group[code_sec->id].toc_off
12009 != htab->stub_group[section->id].toc_off)
12010 && (code_sec->has_toc_reloc
12011 || code_sec->makes_toc_func_call))
12012 stub_type = ppc_stub_long_branch_r2off;
12015 if (stub_type == ppc_stub_none)
12018 /* __tls_get_addr calls might be eliminated. */
12019 if (stub_type != ppc_stub_plt_call
12021 && (hash == htab->tls_get_addr
12022 || hash == htab->tls_get_addr_fd)
12023 && section->has_tls_reloc
12024 && irela != internal_relocs)
12026 /* Get tls info. */
12027 unsigned char *tls_mask;
12029 if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms,
12030 irela - 1, input_bfd))
12031 goto error_ret_free_internal;
12032 if (*tls_mask != 0)
12036 if (stub_type == ppc_stub_plt_call
12037 && irela + 1 < irelaend
12038 && irela[1].r_offset == irela->r_offset + 4
12039 && ELF64_R_TYPE (irela[1].r_info) == R_PPC64_TOCSAVE)
12041 if (!tocsave_find (htab, INSERT,
12042 &local_syms, irela + 1, input_bfd))
12043 goto error_ret_free_internal;
12045 else if (stub_type == ppc_stub_plt_call)
12046 stub_type = ppc_stub_plt_call_r2save;
12048 /* Support for grouping stub sections. */
12049 id_sec = htab->stub_group[section->id].link_sec;
12051 /* Get the name of this stub. */
12052 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
12054 goto error_ret_free_internal;
12056 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
12057 stub_name, FALSE, FALSE);
12058 if (stub_entry != NULL)
12060 /* The proper stub has already been created. */
12062 if (stub_type == ppc_stub_plt_call_r2save)
12063 stub_entry->stub_type = stub_type;
12067 stub_entry = ppc_add_stub (stub_name, section, info);
12068 if (stub_entry == NULL)
12071 error_ret_free_internal:
12072 if (elf_section_data (section)->relocs == NULL)
12073 free (internal_relocs);
12074 error_ret_free_local:
12075 if (local_syms != NULL
12076 && (symtab_hdr->contents
12077 != (unsigned char *) local_syms))
12082 stub_entry->stub_type = stub_type;
12083 if (stub_type != ppc_stub_plt_call
12084 && stub_type != ppc_stub_plt_call_r2save)
12086 stub_entry->target_value = code_value;
12087 stub_entry->target_section = code_sec;
12091 stub_entry->target_value = sym_value;
12092 stub_entry->target_section = sym_sec;
12094 stub_entry->h = hash;
12095 stub_entry->plt_ent = plt_ent;
12096 stub_entry->other = hash ? hash->elf.other : sym->st_other;
12098 if (stub_entry->h != NULL)
12099 htab->stub_globals += 1;
12102 /* We're done with the internal relocs, free them. */
12103 if (elf_section_data (section)->relocs != internal_relocs)
12104 free (internal_relocs);
12107 if (local_syms != NULL
12108 && symtab_hdr->contents != (unsigned char *) local_syms)
12110 if (!info->keep_memory)
12113 symtab_hdr->contents = (unsigned char *) local_syms;
12117 /* We may have added some stubs. Find out the new size of the
12119 for (stub_sec = htab->stub_bfd->sections;
12121 stub_sec = stub_sec->next)
12122 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12124 stub_sec->rawsize = stub_sec->size;
12125 stub_sec->size = 0;
12126 stub_sec->reloc_count = 0;
12127 stub_sec->flags &= ~SEC_RELOC;
12130 htab->brlt->size = 0;
12131 htab->brlt->reloc_count = 0;
12132 htab->brlt->flags &= ~SEC_RELOC;
12133 if (htab->relbrlt != NULL)
12134 htab->relbrlt->size = 0;
12136 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
12138 if (info->emitrelocations
12139 && htab->glink != NULL && htab->glink->size != 0)
12141 htab->glink->reloc_count = 1;
12142 htab->glink->flags |= SEC_RELOC;
12145 if (htab->glink_eh_frame != NULL
12146 && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
12147 && htab->glink_eh_frame->output_section->size != 0)
12149 size_t size = 0, align;
12151 for (stub_sec = htab->stub_bfd->sections;
12153 stub_sec = stub_sec->next)
12154 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12156 if (htab->glink != NULL && htab->glink->size != 0)
12159 size += sizeof (glink_eh_frame_cie);
12161 align <<= htab->glink_eh_frame->output_section->alignment_power;
12163 size = (size + align) & ~align;
12164 htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
12165 htab->glink_eh_frame->size = size;
12168 if (htab->plt_stub_align != 0)
12169 for (stub_sec = htab->stub_bfd->sections;
12171 stub_sec = stub_sec->next)
12172 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12173 stub_sec->size = ((stub_sec->size + (1 << htab->plt_stub_align) - 1)
12174 & (-1 << htab->plt_stub_align));
12176 for (stub_sec = htab->stub_bfd->sections;
12178 stub_sec = stub_sec->next)
12179 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
12180 && stub_sec->rawsize != stub_sec->size)
12183 /* Exit from this loop when no stubs have been added, and no stubs
12184 have changed size. */
12185 if (stub_sec == NULL
12186 && (htab->glink_eh_frame == NULL
12187 || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size))
12190 /* Ask the linker to do its stuff. */
12191 (*htab->layout_sections_again) ();
12194 maybe_strip_output (info, htab->brlt);
12195 if (htab->glink_eh_frame != NULL)
12196 maybe_strip_output (info, htab->glink_eh_frame);
12201 /* Called after we have determined section placement. If sections
12202 move, we'll be called again. Provide a value for TOCstart. */
12205 ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
12210 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12211 order. The TOC starts where the first of these sections starts. */
12212 s = bfd_get_section_by_name (obfd, ".got");
12213 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12214 s = bfd_get_section_by_name (obfd, ".toc");
12215 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12216 s = bfd_get_section_by_name (obfd, ".tocbss");
12217 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12218 s = bfd_get_section_by_name (obfd, ".plt");
12219 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12221 /* This may happen for
12222 o references to TOC base (SYM@toc / TOC[tc0]) without a
12224 o bad linker script
12225 o --gc-sections and empty TOC sections
12227 FIXME: Warn user? */
12229 /* Look for a likely section. We probably won't even be
12231 for (s = obfd->sections; s != NULL; s = s->next)
12232 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY
12234 == (SEC_ALLOC | SEC_SMALL_DATA))
12237 for (s = obfd->sections; s != NULL; s = s->next)
12238 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE))
12239 == (SEC_ALLOC | SEC_SMALL_DATA))
12242 for (s = obfd->sections; s != NULL; s = s->next)
12243 if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE))
12247 for (s = obfd->sections; s != NULL; s = s->next)
12248 if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC)
12254 TOCstart = s->output_section->vma + s->output_offset;
12256 _bfd_set_gp_value (obfd, TOCstart);
12258 if (info != NULL && s != NULL && is_ppc64_elf (obfd))
12260 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12263 && htab->elf.hgot != NULL)
12265 htab->elf.hgot->type = STT_OBJECT;
12266 htab->elf.hgot->root.type = bfd_link_hash_defined;
12267 htab->elf.hgot->root.u.def.value = TOC_BASE_OFF;
12268 htab->elf.hgot->root.u.def.section = s;
12274 /* Build all the stubs associated with the current output file.
12275 The stubs are kept in a hash table attached to the main linker
12276 hash table. This function is called via gldelf64ppc_finish. */
12279 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms,
12280 struct bfd_link_info *info,
12283 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12284 asection *stub_sec;
12286 int stub_sec_count = 0;
12291 htab->emit_stub_syms = emit_stub_syms;
12293 /* Allocate memory to hold the linker stubs. */
12294 for (stub_sec = htab->stub_bfd->sections;
12296 stub_sec = stub_sec->next)
12297 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
12298 && stub_sec->size != 0)
12300 stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
12301 if (stub_sec->contents == NULL)
12303 /* We want to check that built size is the same as calculated
12304 size. rawsize is a convenient location to use. */
12305 stub_sec->rawsize = stub_sec->size;
12306 stub_sec->size = 0;
12309 if (htab->glink != NULL && htab->glink->size != 0)
12314 /* Build the .glink plt call stub. */
12315 if (htab->emit_stub_syms)
12317 struct elf_link_hash_entry *h;
12318 h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
12319 TRUE, FALSE, FALSE);
12322 if (h->root.type == bfd_link_hash_new)
12324 h->root.type = bfd_link_hash_defined;
12325 h->root.u.def.section = htab->glink;
12326 h->root.u.def.value = 8;
12327 h->ref_regular = 1;
12328 h->def_regular = 1;
12329 h->ref_regular_nonweak = 1;
12330 h->forced_local = 1;
12334 plt0 = htab->plt->output_section->vma + htab->plt->output_offset - 16;
12335 if (info->emitrelocations)
12337 Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
12340 r->r_offset = (htab->glink->output_offset
12341 + htab->glink->output_section->vma);
12342 r->r_info = ELF64_R_INFO (0, R_PPC64_REL64);
12343 r->r_addend = plt0;
12345 p = htab->glink->contents;
12346 plt0 -= htab->glink->output_section->vma + htab->glink->output_offset;
12347 bfd_put_64 (htab->glink->owner, plt0, p);
12351 bfd_put_32 (htab->glink->owner, MFLR_R12, p);
12353 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
12355 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
12357 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
12359 bfd_put_32 (htab->glink->owner, MTLR_R12, p);
12361 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
12363 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
12365 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | 8, p);
12367 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
12369 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 16, p);
12374 bfd_put_32 (htab->glink->owner, MFLR_R0, p);
12376 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
12378 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
12380 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
12382 bfd_put_32 (htab->glink->owner, MTLR_R0, p);
12384 bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
12386 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
12388 bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-48 & 0xffff), p);
12390 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
12392 bfd_put_32 (htab->glink->owner, SRDI_R0_R0_2, p);
12394 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
12396 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 8, p);
12399 bfd_put_32 (htab->glink->owner, BCTR, p);
12401 while (p - htab->glink->contents < GLINK_CALL_STUB_SIZE)
12403 bfd_put_32 (htab->glink->owner, NOP, p);
12407 /* Build the .glink lazy link call stubs. */
12409 while (p < htab->glink->contents + htab->glink->size)
12415 bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
12420 bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
12422 bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx),
12427 bfd_put_32 (htab->glink->owner,
12428 B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p);
12432 htab->glink->rawsize = p - htab->glink->contents;
12435 if (htab->brlt->size != 0)
12437 htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
12439 if (htab->brlt->contents == NULL)
12442 if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
12444 htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
12445 htab->relbrlt->size);
12446 if (htab->relbrlt->contents == NULL)
12450 if (htab->glink_eh_frame != NULL
12451 && htab->glink_eh_frame->size != 0)
12454 bfd_byte *last_fde;
12455 size_t last_fde_len, size, align, pad;
12457 p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
12460 htab->glink_eh_frame->contents = p;
12463 htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
12465 memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
12466 /* CIE length (rewrite in case little-endian). */
12467 last_fde_len = sizeof (glink_eh_frame_cie) - 4;
12468 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12469 p += sizeof (glink_eh_frame_cie);
12471 for (stub_sec = htab->stub_bfd->sections;
12473 stub_sec = stub_sec->next)
12474 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12479 bfd_put_32 (htab->elf.dynobj, 16, p);
12482 val = p - htab->glink_eh_frame->contents;
12483 bfd_put_32 (htab->elf.dynobj, val, p);
12485 /* Offset to stub section. */
12486 val = (stub_sec->output_section->vma
12487 + stub_sec->output_offset);
12488 val -= (htab->glink_eh_frame->output_section->vma
12489 + htab->glink_eh_frame->output_offset);
12490 val -= p - htab->glink_eh_frame->contents;
12491 if (val + 0x80000000 > 0xffffffff)
12493 info->callbacks->einfo
12494 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
12498 bfd_put_32 (htab->elf.dynobj, val, p);
12500 /* stub section size. */
12501 bfd_put_32 (htab->elf.dynobj, stub_sec->rawsize, p);
12503 /* Augmentation. */
12508 if (htab->glink != NULL && htab->glink->size != 0)
12513 bfd_put_32 (htab->elf.dynobj, 20, p);
12516 val = p - htab->glink_eh_frame->contents;
12517 bfd_put_32 (htab->elf.dynobj, val, p);
12519 /* Offset to .glink. */
12520 val = (htab->glink->output_section->vma
12521 + htab->glink->output_offset
12523 val -= (htab->glink_eh_frame->output_section->vma
12524 + htab->glink_eh_frame->output_offset);
12525 val -= p - htab->glink_eh_frame->contents;
12526 if (val + 0x80000000 > 0xffffffff)
12528 info->callbacks->einfo
12529 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
12530 htab->glink->name);
12533 bfd_put_32 (htab->elf.dynobj, val, p);
12536 bfd_put_32 (htab->elf.dynobj, htab->glink->rawsize - 8, p);
12538 /* Augmentation. */
12541 *p++ = DW_CFA_advance_loc + 1;
12542 *p++ = DW_CFA_register;
12545 *p++ = DW_CFA_advance_loc + 4;
12546 *p++ = DW_CFA_restore_extended;
12549 /* Subsume any padding into the last FDE if user .eh_frame
12550 sections are aligned more than glink_eh_frame. Otherwise any
12551 zero padding will be seen as a terminator. */
12552 size = p - htab->glink_eh_frame->contents;
12554 align <<= htab->glink_eh_frame->output_section->alignment_power;
12556 pad = ((size + align) & ~align) - size;
12557 htab->glink_eh_frame->size = size + pad;
12558 bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
12561 /* Build the stubs as directed by the stub hash table. */
12562 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
12564 if (htab->relbrlt != NULL)
12565 htab->relbrlt->reloc_count = 0;
12567 if (htab->plt_stub_align != 0)
12568 for (stub_sec = htab->stub_bfd->sections;
12570 stub_sec = stub_sec->next)
12571 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12572 stub_sec->size = ((stub_sec->size + (1 << htab->plt_stub_align) - 1)
12573 & (-1 << htab->plt_stub_align));
12575 for (stub_sec = htab->stub_bfd->sections;
12577 stub_sec = stub_sec->next)
12578 if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
12580 stub_sec_count += 1;
12581 if (stub_sec->rawsize != stub_sec->size)
12585 if (stub_sec != NULL
12586 || htab->glink->rawsize != htab->glink->size
12587 || (htab->glink_eh_frame != NULL
12588 && htab->glink_eh_frame->rawsize != htab->glink_eh_frame->size))
12590 htab->stub_error = TRUE;
12591 info->callbacks->einfo (_("%P: stubs don't match calculated size\n"));
12594 if (htab->stub_error)
12599 *stats = bfd_malloc (500);
12600 if (*stats == NULL)
12603 sprintf (*stats, _("linker stubs in %u group%s\n"
12605 " toc adjust %lu\n"
12606 " long branch %lu\n"
12607 " long toc adj %lu\n"
12609 " plt call toc %lu"),
12611 stub_sec_count == 1 ? "" : "s",
12612 htab->stub_count[ppc_stub_long_branch - 1],
12613 htab->stub_count[ppc_stub_long_branch_r2off - 1],
12614 htab->stub_count[ppc_stub_plt_branch - 1],
12615 htab->stub_count[ppc_stub_plt_branch_r2off - 1],
12616 htab->stub_count[ppc_stub_plt_call - 1],
12617 htab->stub_count[ppc_stub_plt_call_r2save - 1]);
12622 /* This function undoes the changes made by add_symbol_adjust. */
12625 undo_symbol_twiddle (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
12627 struct ppc_link_hash_entry *eh;
12629 if (h->root.type == bfd_link_hash_indirect)
12632 eh = (struct ppc_link_hash_entry *) h;
12633 if (eh->elf.root.type != bfd_link_hash_undefweak || !eh->was_undefined)
12636 eh->elf.root.type = bfd_link_hash_undefined;
12641 ppc64_elf_restore_symbols (struct bfd_link_info *info)
12643 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12646 elf_link_hash_traverse (&htab->elf, undo_symbol_twiddle, info);
12649 /* What to do when ld finds relocations against symbols defined in
12650 discarded sections. */
12652 static unsigned int
12653 ppc64_elf_action_discarded (asection *sec)
12655 if (strcmp (".opd", sec->name) == 0)
12658 if (strcmp (".toc", sec->name) == 0)
12661 if (strcmp (".toc1", sec->name) == 0)
12664 return _bfd_elf_default_action_discarded (sec);
12667 /* The RELOCATE_SECTION function is called by the ELF backend linker
12668 to handle the relocations for a section.
12670 The relocs are always passed as Rela structures; if the section
12671 actually uses Rel structures, the r_addend field will always be
12674 This function is responsible for adjust the section contents as
12675 necessary, and (if using Rela relocs and generating a
12676 relocatable output file) adjusting the reloc addend as
12679 This function does not have to worry about setting the reloc
12680 address or the reloc symbol index.
12682 LOCAL_SYMS is a pointer to the swapped in local symbols.
12684 LOCAL_SECTIONS is an array giving the section in the input file
12685 corresponding to the st_shndx field of each local symbol.
12687 The global hash table entry for the global symbols can be found
12688 via elf_sym_hashes (input_bfd).
12690 When generating relocatable output, this function must handle
12691 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
12692 going to be the section symbol corresponding to the output
12693 section, which means that the addend must be adjusted
12697 ppc64_elf_relocate_section (bfd *output_bfd,
12698 struct bfd_link_info *info,
12700 asection *input_section,
12701 bfd_byte *contents,
12702 Elf_Internal_Rela *relocs,
12703 Elf_Internal_Sym *local_syms,
12704 asection **local_sections)
12706 struct ppc_link_hash_table *htab;
12707 Elf_Internal_Shdr *symtab_hdr;
12708 struct elf_link_hash_entry **sym_hashes;
12709 Elf_Internal_Rela *rel;
12710 Elf_Internal_Rela *relend;
12711 Elf_Internal_Rela outrel;
12713 struct got_entry **local_got_ents;
12715 bfd_boolean ret = TRUE;
12716 bfd_boolean is_opd;
12717 /* Assume 'at' branch hints. */
12718 bfd_boolean is_isa_v2 = TRUE;
12719 bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
12721 /* Initialize howto table if needed. */
12722 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
12725 htab = ppc_hash_table (info);
12729 /* Don't relocate stub sections. */
12730 if (input_section->owner == htab->stub_bfd)
12733 BFD_ASSERT (is_ppc64_elf (input_bfd));
12735 local_got_ents = elf_local_got_ents (input_bfd);
12736 TOCstart = elf_gp (output_bfd);
12737 symtab_hdr = &elf_symtab_hdr (input_bfd);
12738 sym_hashes = elf_sym_hashes (input_bfd);
12739 is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd;
12742 relend = relocs + input_section->reloc_count;
12743 for (; rel < relend; rel++)
12745 enum elf_ppc64_reloc_type r_type;
12747 bfd_reloc_status_type r;
12748 Elf_Internal_Sym *sym;
12750 struct elf_link_hash_entry *h_elf;
12751 struct ppc_link_hash_entry *h;
12752 struct ppc_link_hash_entry *fdh;
12753 const char *sym_name;
12754 unsigned long r_symndx, toc_symndx;
12755 bfd_vma toc_addend;
12756 unsigned char tls_mask, tls_gd, tls_type;
12757 unsigned char sym_type;
12758 bfd_vma relocation;
12759 bfd_boolean unresolved_reloc;
12760 bfd_boolean warned;
12761 enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
12764 struct ppc_stub_hash_entry *stub_entry;
12765 bfd_vma max_br_offset;
12767 const Elf_Internal_Rela orig_rel = *rel;
12769 r_type = ELF64_R_TYPE (rel->r_info);
12770 r_symndx = ELF64_R_SYM (rel->r_info);
12772 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
12773 symbol of the previous ADDR64 reloc. The symbol gives us the
12774 proper TOC base to use. */
12775 if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
12777 && ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_ADDR64
12779 r_symndx = ELF64_R_SYM (rel[-1].r_info);
12785 unresolved_reloc = FALSE;
12788 if (r_symndx < symtab_hdr->sh_info)
12790 /* It's a local symbol. */
12791 struct _opd_sec_data *opd;
12793 sym = local_syms + r_symndx;
12794 sec = local_sections[r_symndx];
12795 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
12796 sym_type = ELF64_ST_TYPE (sym->st_info);
12797 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
12798 opd = get_opd_info (sec);
12799 if (opd != NULL && opd->adjust != NULL)
12801 long adjust = opd->adjust[(sym->st_value + rel->r_addend) / 8];
12806 /* If this is a relocation against the opd section sym
12807 and we have edited .opd, adjust the reloc addend so
12808 that ld -r and ld --emit-relocs output is correct.
12809 If it is a reloc against some other .opd symbol,
12810 then the symbol value will be adjusted later. */
12811 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
12812 rel->r_addend += adjust;
12814 relocation += adjust;
12820 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
12821 r_symndx, symtab_hdr, sym_hashes,
12822 h_elf, sec, relocation,
12823 unresolved_reloc, warned);
12824 sym_name = h_elf->root.root.string;
12825 sym_type = h_elf->type;
12827 && sec->owner == output_bfd
12828 && strcmp (sec->name, ".opd") == 0)
12830 /* This is a symbol defined in a linker script. All
12831 such are defined in output sections, even those
12832 defined by simple assignment from a symbol defined in
12833 an input section. Transfer the symbol to an
12834 appropriate input .opd section, so that a branch to
12835 this symbol will be mapped to the location specified
12836 by the opd entry. */
12837 struct bfd_link_order *lo;
12838 for (lo = sec->map_head.link_order; lo != NULL; lo = lo->next)
12839 if (lo->type == bfd_indirect_link_order)
12841 asection *isec = lo->u.indirect.section;
12842 if (h_elf->root.u.def.value >= isec->output_offset
12843 && h_elf->root.u.def.value < (isec->output_offset
12846 h_elf->root.u.def.value -= isec->output_offset;
12847 h_elf->root.u.def.section = isec;
12854 h = (struct ppc_link_hash_entry *) h_elf;
12856 if (sec != NULL && discarded_section (sec))
12857 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
12859 ppc64_elf_howto_table[r_type], 0,
12862 if (info->relocatable)
12865 if (h != NULL && &h->elf == htab->elf.hgot)
12867 relocation = (TOCstart
12868 + htab->stub_group[input_section->id].toc_off);
12869 sec = bfd_abs_section_ptr;
12870 unresolved_reloc = FALSE;
12873 /* TLS optimizations. Replace instruction sequences and relocs
12874 based on information we collected in tls_optimize. We edit
12875 RELOCS so that --emit-relocs will output something sensible
12876 for the final instruction stream. */
12881 tls_mask = h->tls_mask;
12882 else if (local_got_ents != NULL)
12884 struct plt_entry **local_plt = (struct plt_entry **)
12885 (local_got_ents + symtab_hdr->sh_info);
12886 unsigned char *lgot_masks = (unsigned char *)
12887 (local_plt + symtab_hdr->sh_info);
12888 tls_mask = lgot_masks[r_symndx];
12891 && (r_type == R_PPC64_TLS
12892 || r_type == R_PPC64_TLSGD
12893 || r_type == R_PPC64_TLSLD))
12895 /* Check for toc tls entries. */
12896 unsigned char *toc_tls;
12898 if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
12899 &local_syms, rel, input_bfd))
12903 tls_mask = *toc_tls;
12906 /* Check that tls relocs are used with tls syms, and non-tls
12907 relocs are used with non-tls syms. */
12908 if (r_symndx != STN_UNDEF
12909 && r_type != R_PPC64_NONE
12911 || h->elf.root.type == bfd_link_hash_defined
12912 || h->elf.root.type == bfd_link_hash_defweak)
12913 && (IS_PPC64_TLS_RELOC (r_type)
12914 != (sym_type == STT_TLS
12915 || (sym_type == STT_SECTION
12916 && (sec->flags & SEC_THREAD_LOCAL) != 0))))
12919 && (r_type == R_PPC64_TLS
12920 || r_type == R_PPC64_TLSGD
12921 || r_type == R_PPC64_TLSLD))
12922 /* R_PPC64_TLS is OK against a symbol in the TOC. */
12925 info->callbacks->einfo
12926 (!IS_PPC64_TLS_RELOC (r_type)
12927 ? _("%P: %H: %s used with TLS symbol `%T'\n")
12928 : _("%P: %H: %s used with non-TLS symbol `%T'\n"),
12929 input_bfd, input_section, rel->r_offset,
12930 ppc64_elf_howto_table[r_type]->name,
12934 /* Ensure reloc mapping code below stays sane. */
12935 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
12936 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
12937 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
12938 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
12939 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
12940 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
12941 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
12942 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
12943 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
12944 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
12952 case R_PPC64_LO_DS_OPT:
12953 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
12954 if ((insn & (0x3f << 26)) != 58u << 26)
12956 insn += (14u << 26) - (58u << 26);
12957 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
12958 r_type = R_PPC64_TOC16_LO;
12959 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
12962 case R_PPC64_TOC16:
12963 case R_PPC64_TOC16_LO:
12964 case R_PPC64_TOC16_DS:
12965 case R_PPC64_TOC16_LO_DS:
12967 /* Check for toc tls entries. */
12968 unsigned char *toc_tls;
12971 retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
12972 &local_syms, rel, input_bfd);
12978 tls_mask = *toc_tls;
12979 if (r_type == R_PPC64_TOC16_DS
12980 || r_type == R_PPC64_TOC16_LO_DS)
12983 && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
12988 /* If we found a GD reloc pair, then we might be
12989 doing a GD->IE transition. */
12992 tls_gd = TLS_TPRELGD;
12993 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
12996 else if (retval == 3)
12998 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13006 case R_PPC64_GOT_TPREL16_HI:
13007 case R_PPC64_GOT_TPREL16_HA:
13009 && (tls_mask & TLS_TPREL) == 0)
13011 rel->r_offset -= d_offset;
13012 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
13013 r_type = R_PPC64_NONE;
13014 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13018 case R_PPC64_GOT_TPREL16_DS:
13019 case R_PPC64_GOT_TPREL16_LO_DS:
13021 && (tls_mask & TLS_TPREL) == 0)
13024 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
13026 insn |= 0x3c0d0000; /* addis 0,13,0 */
13027 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
13028 r_type = R_PPC64_TPREL16_HA;
13029 if (toc_symndx != 0)
13031 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
13032 rel->r_addend = toc_addend;
13033 /* We changed the symbol. Start over in order to
13034 get h, sym, sec etc. right. */
13039 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13045 && (tls_mask & TLS_TPREL) == 0)
13047 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
13048 insn = _bfd_elf_ppc_at_tls_transform (insn, 13);
13051 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
13052 /* Was PPC64_TLS which sits on insn boundary, now
13053 PPC64_TPREL16_LO which is at low-order half-word. */
13054 rel->r_offset += d_offset;
13055 r_type = R_PPC64_TPREL16_LO;
13056 if (toc_symndx != 0)
13058 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
13059 rel->r_addend = toc_addend;
13060 /* We changed the symbol. Start over in order to
13061 get h, sym, sec etc. right. */
13066 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13070 case R_PPC64_GOT_TLSGD16_HI:
13071 case R_PPC64_GOT_TLSGD16_HA:
13072 tls_gd = TLS_TPRELGD;
13073 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13077 case R_PPC64_GOT_TLSLD16_HI:
13078 case R_PPC64_GOT_TLSLD16_HA:
13079 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13082 if ((tls_mask & tls_gd) != 0)
13083 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
13084 + R_PPC64_GOT_TPREL16_DS);
13087 rel->r_offset -= d_offset;
13088 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
13089 r_type = R_PPC64_NONE;
13091 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13095 case R_PPC64_GOT_TLSGD16:
13096 case R_PPC64_GOT_TLSGD16_LO:
13097 tls_gd = TLS_TPRELGD;
13098 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13102 case R_PPC64_GOT_TLSLD16:
13103 case R_PPC64_GOT_TLSLD16_LO:
13104 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13106 unsigned int insn1, insn2, insn3;
13110 offset = (bfd_vma) -1;
13111 /* If not using the newer R_PPC64_TLSGD/LD to mark
13112 __tls_get_addr calls, we must trust that the call
13113 stays with its arg setup insns, ie. that the next
13114 reloc is the __tls_get_addr call associated with
13115 the current reloc. Edit both insns. */
13116 if (input_section->has_tls_get_addr_call
13117 && rel + 1 < relend
13118 && branch_reloc_hash_match (input_bfd, rel + 1,
13119 htab->tls_get_addr,
13120 htab->tls_get_addr_fd))
13121 offset = rel[1].r_offset;
13122 if ((tls_mask & tls_gd) != 0)
13125 insn1 = bfd_get_32 (output_bfd,
13126 contents + rel->r_offset - d_offset);
13127 insn1 &= (1 << 26) - (1 << 2);
13128 insn1 |= 58 << 26; /* ld */
13129 insn2 = 0x7c636a14; /* add 3,3,13 */
13130 if (offset != (bfd_vma) -1)
13131 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13132 if ((tls_mask & TLS_EXPLICIT) == 0)
13133 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
13134 + R_PPC64_GOT_TPREL16_DS);
13136 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
13137 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13142 insn1 = 0x3c6d0000; /* addis 3,13,0 */
13143 insn2 = 0x38630000; /* addi 3,3,0 */
13146 /* Was an LD reloc. */
13148 sec = local_sections[toc_symndx];
13150 r_symndx < symtab_hdr->sh_info;
13152 if (local_sections[r_symndx] == sec)
13154 if (r_symndx >= symtab_hdr->sh_info)
13155 r_symndx = STN_UNDEF;
13156 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
13157 if (r_symndx != STN_UNDEF)
13158 rel->r_addend -= (local_syms[r_symndx].st_value
13159 + sec->output_offset
13160 + sec->output_section->vma);
13162 else if (toc_symndx != 0)
13164 r_symndx = toc_symndx;
13165 rel->r_addend = toc_addend;
13167 r_type = R_PPC64_TPREL16_HA;
13168 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13169 if (offset != (bfd_vma) -1)
13171 rel[1].r_info = ELF64_R_INFO (r_symndx,
13172 R_PPC64_TPREL16_LO);
13173 rel[1].r_offset = offset + d_offset;
13174 rel[1].r_addend = rel->r_addend;
13177 bfd_put_32 (output_bfd, insn1,
13178 contents + rel->r_offset - d_offset);
13179 if (offset != (bfd_vma) -1)
13181 insn3 = bfd_get_32 (output_bfd,
13182 contents + offset + 4);
13184 || insn3 == CROR_151515 || insn3 == CROR_313131)
13186 rel[1].r_offset += 4;
13187 bfd_put_32 (output_bfd, insn2, contents + offset + 4);
13190 bfd_put_32 (output_bfd, insn2, contents + offset);
13192 if ((tls_mask & tls_gd) == 0
13193 && (tls_gd == 0 || toc_symndx != 0))
13195 /* We changed the symbol. Start over in order
13196 to get h, sym, sec etc. right. */
13203 case R_PPC64_TLSGD:
13204 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13206 unsigned int insn2, insn3;
13207 bfd_vma offset = rel->r_offset;
13209 if ((tls_mask & TLS_TPRELGD) != 0)
13212 r_type = R_PPC64_NONE;
13213 insn2 = 0x7c636a14; /* add 3,3,13 */
13218 if (toc_symndx != 0)
13220 r_symndx = toc_symndx;
13221 rel->r_addend = toc_addend;
13223 r_type = R_PPC64_TPREL16_LO;
13224 rel->r_offset = offset + d_offset;
13225 insn2 = 0x38630000; /* addi 3,3,0 */
13227 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13228 /* Zap the reloc on the _tls_get_addr call too. */
13229 BFD_ASSERT (offset == rel[1].r_offset);
13230 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13231 insn3 = bfd_get_32 (output_bfd,
13232 contents + offset + 4);
13234 || insn3 == CROR_151515 || insn3 == CROR_313131)
13236 rel->r_offset += 4;
13237 bfd_put_32 (output_bfd, insn2, contents + offset + 4);
13240 bfd_put_32 (output_bfd, insn2, contents + offset);
13241 if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0)
13249 case R_PPC64_TLSLD:
13250 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13252 unsigned int insn2, insn3;
13253 bfd_vma offset = rel->r_offset;
13256 sec = local_sections[toc_symndx];
13258 r_symndx < symtab_hdr->sh_info;
13260 if (local_sections[r_symndx] == sec)
13262 if (r_symndx >= symtab_hdr->sh_info)
13263 r_symndx = STN_UNDEF;
13264 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
13265 if (r_symndx != STN_UNDEF)
13266 rel->r_addend -= (local_syms[r_symndx].st_value
13267 + sec->output_offset
13268 + sec->output_section->vma);
13270 r_type = R_PPC64_TPREL16_LO;
13271 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13272 rel->r_offset = offset + d_offset;
13273 /* Zap the reloc on the _tls_get_addr call too. */
13274 BFD_ASSERT (offset == rel[1].r_offset);
13275 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13276 insn2 = 0x38630000; /* addi 3,3,0 */
13277 insn3 = bfd_get_32 (output_bfd,
13278 contents + offset + 4);
13280 || insn3 == CROR_151515 || insn3 == CROR_313131)
13282 rel->r_offset += 4;
13283 bfd_put_32 (output_bfd, insn2, contents + offset + 4);
13286 bfd_put_32 (output_bfd, insn2, contents + offset);
13292 case R_PPC64_DTPMOD64:
13293 if (rel + 1 < relend
13294 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
13295 && rel[1].r_offset == rel->r_offset + 8)
13297 if ((tls_mask & TLS_GD) == 0)
13299 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
13300 if ((tls_mask & TLS_TPRELGD) != 0)
13301 r_type = R_PPC64_TPREL64;
13304 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
13305 r_type = R_PPC64_NONE;
13307 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13312 if ((tls_mask & TLS_LD) == 0)
13314 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
13315 r_type = R_PPC64_NONE;
13316 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13321 case R_PPC64_TPREL64:
13322 if ((tls_mask & TLS_TPREL) == 0)
13324 r_type = R_PPC64_NONE;
13325 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13330 /* Handle other relocations that tweak non-addend part of insn. */
13332 max_br_offset = 1 << 25;
13333 addend = rel->r_addend;
13334 reloc_dest = DEST_NORMAL;
13340 case R_PPC64_TOCSAVE:
13341 if (relocation + addend == (rel->r_offset
13342 + input_section->output_offset
13343 + input_section->output_section->vma)
13344 && tocsave_find (htab, NO_INSERT,
13345 &local_syms, rel, input_bfd))
13347 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
13349 || insn == CROR_151515 || insn == CROR_313131)
13350 bfd_put_32 (input_bfd,
13351 STD_R2_0R1 + STK_TOC (htab),
13352 contents + rel->r_offset);
13356 /* Branch taken prediction relocations. */
13357 case R_PPC64_ADDR14_BRTAKEN:
13358 case R_PPC64_REL14_BRTAKEN:
13359 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
13362 /* Branch not taken prediction relocations. */
13363 case R_PPC64_ADDR14_BRNTAKEN:
13364 case R_PPC64_REL14_BRNTAKEN:
13365 insn |= bfd_get_32 (output_bfd,
13366 contents + rel->r_offset) & ~(0x01 << 21);
13369 case R_PPC64_REL14:
13370 max_br_offset = 1 << 15;
13373 case R_PPC64_REL24:
13374 /* Calls to functions with a different TOC, such as calls to
13375 shared objects, need to alter the TOC pointer. This is
13376 done using a linkage stub. A REL24 branching to these
13377 linkage stubs needs to be followed by a nop, as the nop
13378 will be replaced with an instruction to restore the TOC
13383 && h->oh->is_func_descriptor)
13384 fdh = ppc_follow_link (h->oh);
13385 stub_entry = ppc_get_stub_entry (input_section, sec, fdh, &orig_rel,
13387 if (stub_entry != NULL
13388 && (stub_entry->stub_type == ppc_stub_plt_call
13389 || stub_entry->stub_type == ppc_stub_plt_call_r2save
13390 || stub_entry->stub_type == ppc_stub_plt_branch_r2off
13391 || stub_entry->stub_type == ppc_stub_long_branch_r2off))
13393 bfd_boolean can_plt_call = FALSE;
13395 /* All of these stubs will modify r2, so there must be a
13396 branch and link followed by a nop. The nop is
13397 replaced by an insn to restore r2. */
13398 if (rel->r_offset + 8 <= input_section->size)
13402 br = bfd_get_32 (input_bfd,
13403 contents + rel->r_offset);
13408 nop = bfd_get_32 (input_bfd,
13409 contents + rel->r_offset + 4);
13411 || nop == CROR_151515 || nop == CROR_313131)
13414 && (h == htab->tls_get_addr_fd
13415 || h == htab->tls_get_addr)
13416 && !htab->no_tls_get_addr_opt)
13418 /* Special stub used, leave nop alone. */
13421 bfd_put_32 (input_bfd,
13422 LD_R2_0R1 + STK_TOC (htab),
13423 contents + rel->r_offset + 4);
13424 can_plt_call = TRUE;
13429 if (!can_plt_call && h != NULL)
13431 const char *name = h->elf.root.root.string;
13436 if (strncmp (name, "__libc_start_main", 17) == 0
13437 && (name[17] == 0 || name[17] == '@'))
13439 /* Allow crt1 branch to go via a toc adjusting
13440 stub. Other calls that never return could do
13441 the same, if we could detect such. */
13442 can_plt_call = TRUE;
13448 /* g++ as of 20130507 emits self-calls without a
13449 following nop. This is arguably wrong since we
13450 have conflicting information. On the one hand a
13451 global symbol and on the other a local call
13452 sequence, but don't error for this special case.
13453 It isn't possible to cheaply verify we have
13454 exactly such a call. Allow all calls to the same
13456 asection *code_sec = sec;
13458 if (get_opd_info (sec) != NULL)
13460 bfd_vma off = (relocation + addend
13461 - sec->output_section->vma
13462 - sec->output_offset);
13464 opd_entry_value (sec, off, &code_sec, NULL, FALSE);
13466 if (code_sec == input_section)
13467 can_plt_call = TRUE;
13472 info->callbacks->einfo
13473 (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
13474 "recompile with -fPIC"),
13475 input_bfd, input_section, rel->r_offset, sym_name);
13477 bfd_set_error (bfd_error_bad_value);
13482 && (stub_entry->stub_type == ppc_stub_plt_call
13483 || stub_entry->stub_type == ppc_stub_plt_call_r2save))
13484 unresolved_reloc = FALSE;
13487 if ((stub_entry == NULL
13488 || stub_entry->stub_type == ppc_stub_long_branch
13489 || stub_entry->stub_type == ppc_stub_plt_branch)
13490 && get_opd_info (sec) != NULL)
13492 /* The branch destination is the value of the opd entry. */
13493 bfd_vma off = (relocation + addend
13494 - sec->output_section->vma
13495 - sec->output_offset);
13496 bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, FALSE);
13497 if (dest != (bfd_vma) -1)
13501 reloc_dest = DEST_OPD;
13505 /* If the branch is out of reach we ought to have a long
13507 from = (rel->r_offset
13508 + input_section->output_offset
13509 + input_section->output_section->vma);
13511 relocation += PPC64_LOCAL_ENTRY_OFFSET (fdh
13515 if (stub_entry != NULL
13516 && (stub_entry->stub_type == ppc_stub_long_branch
13517 || stub_entry->stub_type == ppc_stub_plt_branch)
13518 && (r_type == R_PPC64_ADDR14_BRTAKEN
13519 || r_type == R_PPC64_ADDR14_BRNTAKEN
13520 || (relocation + addend - from + max_br_offset
13521 < 2 * max_br_offset)))
13522 /* Don't use the stub if this branch is in range. */
13525 if (stub_entry != NULL)
13527 /* Munge up the value and addend so that we call the stub
13528 rather than the procedure directly. */
13529 relocation = (stub_entry->stub_offset
13530 + stub_entry->stub_sec->output_offset
13531 + stub_entry->stub_sec->output_section->vma);
13533 reloc_dest = DEST_STUB;
13535 if ((stub_entry->stub_type == ppc_stub_plt_call
13536 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
13537 && (ALWAYS_EMIT_R2SAVE
13538 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
13539 && rel + 1 < relend
13540 && rel[1].r_offset == rel->r_offset + 4
13541 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
13549 /* Set 'a' bit. This is 0b00010 in BO field for branch
13550 on CR(BI) insns (BO == 001at or 011at), and 0b01000
13551 for branch on CTR insns (BO == 1a00t or 1a01t). */
13552 if ((insn & (0x14 << 21)) == (0x04 << 21))
13553 insn |= 0x02 << 21;
13554 else if ((insn & (0x14 << 21)) == (0x10 << 21))
13555 insn |= 0x08 << 21;
13561 /* Invert 'y' bit if not the default. */
13562 if ((bfd_signed_vma) (relocation + addend - from) < 0)
13563 insn ^= 0x01 << 21;
13566 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
13569 /* NOP out calls to undefined weak functions.
13570 We can thus call a weak function without first
13571 checking whether the function is defined. */
13573 && h->elf.root.type == bfd_link_hash_undefweak
13574 && h->elf.dynindx == -1
13575 && r_type == R_PPC64_REL24
13579 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
13585 /* Set `addend'. */
13590 info->callbacks->einfo
13591 (_("%P: %B: unknown relocation type %d for `%T'\n"),
13592 input_bfd, (int) r_type, sym_name);
13594 bfd_set_error (bfd_error_bad_value);
13600 case R_PPC64_TLSGD:
13601 case R_PPC64_TLSLD:
13602 case R_PPC64_TOCSAVE:
13603 case R_PPC64_GNU_VTINHERIT:
13604 case R_PPC64_GNU_VTENTRY:
13607 /* GOT16 relocations. Like an ADDR16 using the symbol's
13608 address in the GOT as relocation value instead of the
13609 symbol's value itself. Also, create a GOT entry for the
13610 symbol and put the symbol value there. */
13611 case R_PPC64_GOT_TLSGD16:
13612 case R_PPC64_GOT_TLSGD16_LO:
13613 case R_PPC64_GOT_TLSGD16_HI:
13614 case R_PPC64_GOT_TLSGD16_HA:
13615 tls_type = TLS_TLS | TLS_GD;
13618 case R_PPC64_GOT_TLSLD16:
13619 case R_PPC64_GOT_TLSLD16_LO:
13620 case R_PPC64_GOT_TLSLD16_HI:
13621 case R_PPC64_GOT_TLSLD16_HA:
13622 tls_type = TLS_TLS | TLS_LD;
13625 case R_PPC64_GOT_TPREL16_DS:
13626 case R_PPC64_GOT_TPREL16_LO_DS:
13627 case R_PPC64_GOT_TPREL16_HI:
13628 case R_PPC64_GOT_TPREL16_HA:
13629 tls_type = TLS_TLS | TLS_TPREL;
13632 case R_PPC64_GOT_DTPREL16_DS:
13633 case R_PPC64_GOT_DTPREL16_LO_DS:
13634 case R_PPC64_GOT_DTPREL16_HI:
13635 case R_PPC64_GOT_DTPREL16_HA:
13636 tls_type = TLS_TLS | TLS_DTPREL;
13639 case R_PPC64_GOT16:
13640 case R_PPC64_GOT16_LO:
13641 case R_PPC64_GOT16_HI:
13642 case R_PPC64_GOT16_HA:
13643 case R_PPC64_GOT16_DS:
13644 case R_PPC64_GOT16_LO_DS:
13647 /* Relocation is to the entry for this symbol in the global
13652 unsigned long indx = 0;
13653 struct got_entry *ent;
13655 if (tls_type == (TLS_TLS | TLS_LD)
13657 || !h->elf.def_dynamic))
13658 ent = ppc64_tlsld_got (input_bfd);
13664 bfd_boolean dyn = htab->elf.dynamic_sections_created;
13665 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
13668 && SYMBOL_CALLS_LOCAL (info, &h->elf)))
13669 /* This is actually a static link, or it is a
13670 -Bsymbolic link and the symbol is defined
13671 locally, or the symbol was forced to be local
13672 because of a version file. */
13676 BFD_ASSERT (h->elf.dynindx != -1);
13677 indx = h->elf.dynindx;
13678 unresolved_reloc = FALSE;
13680 ent = h->elf.got.glist;
13684 if (local_got_ents == NULL)
13686 ent = local_got_ents[r_symndx];
13689 for (; ent != NULL; ent = ent->next)
13690 if (ent->addend == orig_rel.r_addend
13691 && ent->owner == input_bfd
13692 && ent->tls_type == tls_type)
13698 if (ent->is_indirect)
13699 ent = ent->got.ent;
13700 offp = &ent->got.offset;
13701 got = ppc64_elf_tdata (ent->owner)->got;
13705 /* The offset must always be a multiple of 8. We use the
13706 least significant bit to record whether we have already
13707 processed this entry. */
13709 if ((off & 1) != 0)
13713 /* Generate relocs for the dynamic linker, except in
13714 the case of TLSLD where we'll use one entry per
13722 ? h->elf.type == STT_GNU_IFUNC
13723 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
13725 relgot = htab->reliplt;
13726 else if ((info->shared || indx != 0)
13728 || (tls_type == (TLS_TLS | TLS_LD)
13729 && !h->elf.def_dynamic)
13730 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
13731 || h->elf.root.type != bfd_link_hash_undefweak))
13732 relgot = ppc64_elf_tdata (ent->owner)->relgot;
13733 if (relgot != NULL)
13735 outrel.r_offset = (got->output_section->vma
13736 + got->output_offset
13738 outrel.r_addend = addend;
13739 if (tls_type & (TLS_LD | TLS_GD))
13741 outrel.r_addend = 0;
13742 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
13743 if (tls_type == (TLS_TLS | TLS_GD))
13745 loc = relgot->contents;
13746 loc += (relgot->reloc_count++
13747 * sizeof (Elf64_External_Rela));
13748 bfd_elf64_swap_reloca_out (output_bfd,
13750 outrel.r_offset += 8;
13751 outrel.r_addend = addend;
13753 = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
13756 else if (tls_type == (TLS_TLS | TLS_DTPREL))
13757 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
13758 else if (tls_type == (TLS_TLS | TLS_TPREL))
13759 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
13760 else if (indx != 0)
13761 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
13765 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
13767 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
13769 /* Write the .got section contents for the sake
13771 loc = got->contents + off;
13772 bfd_put_64 (output_bfd, outrel.r_addend + relocation,
13776 if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
13778 outrel.r_addend += relocation;
13779 if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
13780 outrel.r_addend -= htab->elf.tls_sec->vma;
13782 loc = relgot->contents;
13783 loc += (relgot->reloc_count++
13784 * sizeof (Elf64_External_Rela));
13785 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
13788 /* Init the .got section contents here if we're not
13789 emitting a reloc. */
13792 relocation += addend;
13793 if (tls_type == (TLS_TLS | TLS_LD))
13795 else if (tls_type != 0)
13797 relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
13798 if (tls_type == (TLS_TLS | TLS_TPREL))
13799 relocation += DTP_OFFSET - TP_OFFSET;
13801 if (tls_type == (TLS_TLS | TLS_GD))
13803 bfd_put_64 (output_bfd, relocation,
13804 got->contents + off + 8);
13809 bfd_put_64 (output_bfd, relocation,
13810 got->contents + off);
13814 if (off >= (bfd_vma) -2)
13817 relocation = got->output_section->vma + got->output_offset + off;
13818 addend = -(TOCstart + htab->stub_group[input_section->id].toc_off);
13822 case R_PPC64_PLT16_HA:
13823 case R_PPC64_PLT16_HI:
13824 case R_PPC64_PLT16_LO:
13825 case R_PPC64_PLT32:
13826 case R_PPC64_PLT64:
13827 /* Relocation is to the entry for this symbol in the
13828 procedure linkage table. */
13830 /* Resolve a PLT reloc against a local symbol directly,
13831 without using the procedure linkage table. */
13835 /* It's possible that we didn't make a PLT entry for this
13836 symbol. This happens when statically linking PIC code,
13837 or when using -Bsymbolic. Go find a match if there is a
13839 if (htab->plt != NULL)
13841 struct plt_entry *ent;
13842 for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next)
13843 if (ent->addend == orig_rel.r_addend
13844 && ent->plt.offset != (bfd_vma) -1)
13846 relocation = (htab->plt->output_section->vma
13847 + htab->plt->output_offset
13848 + ent->plt.offset);
13849 unresolved_reloc = FALSE;
13855 /* Relocation value is TOC base. */
13856 relocation = TOCstart;
13857 if (r_symndx == STN_UNDEF)
13858 relocation += htab->stub_group[input_section->id].toc_off;
13859 else if (unresolved_reloc)
13861 else if (sec != NULL && sec->id <= htab->top_id)
13862 relocation += htab->stub_group[sec->id].toc_off;
13864 unresolved_reloc = TRUE;
13867 /* TOC16 relocs. We want the offset relative to the TOC base,
13868 which is the address of the start of the TOC plus 0x8000.
13869 The TOC consists of sections .got, .toc, .tocbss, and .plt,
13871 case R_PPC64_TOC16:
13872 case R_PPC64_TOC16_LO:
13873 case R_PPC64_TOC16_HI:
13874 case R_PPC64_TOC16_DS:
13875 case R_PPC64_TOC16_LO_DS:
13876 case R_PPC64_TOC16_HA:
13877 addend -= TOCstart + htab->stub_group[input_section->id].toc_off;
13880 /* Relocate against the beginning of the section. */
13881 case R_PPC64_SECTOFF:
13882 case R_PPC64_SECTOFF_LO:
13883 case R_PPC64_SECTOFF_HI:
13884 case R_PPC64_SECTOFF_DS:
13885 case R_PPC64_SECTOFF_LO_DS:
13886 case R_PPC64_SECTOFF_HA:
13888 addend -= sec->output_section->vma;
13891 case R_PPC64_REL16:
13892 case R_PPC64_REL16_LO:
13893 case R_PPC64_REL16_HI:
13894 case R_PPC64_REL16_HA:
13897 case R_PPC64_REL14:
13898 case R_PPC64_REL14_BRNTAKEN:
13899 case R_PPC64_REL14_BRTAKEN:
13900 case R_PPC64_REL24:
13903 case R_PPC64_TPREL16:
13904 case R_PPC64_TPREL16_LO:
13905 case R_PPC64_TPREL16_HI:
13906 case R_PPC64_TPREL16_HA:
13907 case R_PPC64_TPREL16_DS:
13908 case R_PPC64_TPREL16_LO_DS:
13909 case R_PPC64_TPREL16_HIGH:
13910 case R_PPC64_TPREL16_HIGHA:
13911 case R_PPC64_TPREL16_HIGHER:
13912 case R_PPC64_TPREL16_HIGHERA:
13913 case R_PPC64_TPREL16_HIGHEST:
13914 case R_PPC64_TPREL16_HIGHESTA:
13916 && h->elf.root.type == bfd_link_hash_undefweak
13917 && h->elf.dynindx == -1)
13919 /* Make this relocation against an undefined weak symbol
13920 resolve to zero. This is really just a tweak, since
13921 code using weak externs ought to check that they are
13922 defined before using them. */
13923 bfd_byte *p = contents + rel->r_offset - d_offset;
13925 insn = bfd_get_32 (output_bfd, p);
13926 insn = _bfd_elf_ppc_at_tprel_transform (insn, 13);
13928 bfd_put_32 (output_bfd, insn, p);
13931 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
13933 /* The TPREL16 relocs shouldn't really be used in shared
13934 libs as they will result in DT_TEXTREL being set, but
13935 support them anyway. */
13939 case R_PPC64_DTPREL16:
13940 case R_PPC64_DTPREL16_LO:
13941 case R_PPC64_DTPREL16_HI:
13942 case R_PPC64_DTPREL16_HA:
13943 case R_PPC64_DTPREL16_DS:
13944 case R_PPC64_DTPREL16_LO_DS:
13945 case R_PPC64_DTPREL16_HIGH:
13946 case R_PPC64_DTPREL16_HIGHA:
13947 case R_PPC64_DTPREL16_HIGHER:
13948 case R_PPC64_DTPREL16_HIGHERA:
13949 case R_PPC64_DTPREL16_HIGHEST:
13950 case R_PPC64_DTPREL16_HIGHESTA:
13951 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
13954 case R_PPC64_DTPMOD64:
13959 case R_PPC64_TPREL64:
13960 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
13963 case R_PPC64_DTPREL64:
13964 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
13967 /* Relocations that may need to be propagated if this is a
13969 case R_PPC64_REL30:
13970 case R_PPC64_REL32:
13971 case R_PPC64_REL64:
13972 case R_PPC64_ADDR14:
13973 case R_PPC64_ADDR14_BRNTAKEN:
13974 case R_PPC64_ADDR14_BRTAKEN:
13975 case R_PPC64_ADDR16:
13976 case R_PPC64_ADDR16_DS:
13977 case R_PPC64_ADDR16_HA:
13978 case R_PPC64_ADDR16_HI:
13979 case R_PPC64_ADDR16_HIGH:
13980 case R_PPC64_ADDR16_HIGHA:
13981 case R_PPC64_ADDR16_HIGHER:
13982 case R_PPC64_ADDR16_HIGHERA:
13983 case R_PPC64_ADDR16_HIGHEST:
13984 case R_PPC64_ADDR16_HIGHESTA:
13985 case R_PPC64_ADDR16_LO:
13986 case R_PPC64_ADDR16_LO_DS:
13987 case R_PPC64_ADDR24:
13988 case R_PPC64_ADDR32:
13989 case R_PPC64_ADDR64:
13990 case R_PPC64_UADDR16:
13991 case R_PPC64_UADDR32:
13992 case R_PPC64_UADDR64:
13994 if ((input_section->flags & SEC_ALLOC) == 0)
13997 if (NO_OPD_RELOCS && is_opd)
14002 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
14003 || h->elf.root.type != bfd_link_hash_undefweak)
14004 && (must_be_dyn_reloc (info, r_type)
14005 || !SYMBOL_CALLS_LOCAL (info, &h->elf)))
14006 || (ELIMINATE_COPY_RELOCS
14009 && h->elf.dynindx != -1
14010 && !h->elf.non_got_ref
14011 && !h->elf.def_regular)
14014 ? h->elf.type == STT_GNU_IFUNC
14015 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)))
14017 bfd_boolean skip, relocate;
14021 /* When generating a dynamic object, these relocations
14022 are copied into the output file to be resolved at run
14028 out_off = _bfd_elf_section_offset (output_bfd, info,
14029 input_section, rel->r_offset);
14030 if (out_off == (bfd_vma) -1)
14032 else if (out_off == (bfd_vma) -2)
14033 skip = TRUE, relocate = TRUE;
14034 out_off += (input_section->output_section->vma
14035 + input_section->output_offset);
14036 outrel.r_offset = out_off;
14037 outrel.r_addend = rel->r_addend;
14039 /* Optimize unaligned reloc use. */
14040 if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
14041 || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
14042 r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
14043 else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
14044 || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
14045 r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
14046 else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
14047 || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
14048 r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
14051 memset (&outrel, 0, sizeof outrel);
14052 else if (!SYMBOL_CALLS_LOCAL (info, &h->elf)
14054 && r_type != R_PPC64_TOC)
14056 BFD_ASSERT (h->elf.dynindx != -1);
14057 outrel.r_info = ELF64_R_INFO (h->elf.dynindx, r_type);
14061 /* This symbol is local, or marked to become local,
14062 or this is an opd section reloc which must point
14063 at a local function. */
14064 outrel.r_addend += relocation;
14065 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
14067 if (is_opd && h != NULL)
14069 /* Lie about opd entries. This case occurs
14070 when building shared libraries and we
14071 reference a function in another shared
14072 lib. The same thing happens for a weak
14073 definition in an application that's
14074 overridden by a strong definition in a
14075 shared lib. (I believe this is a generic
14076 bug in binutils handling of weak syms.)
14077 In these cases we won't use the opd
14078 entry in this lib. */
14079 unresolved_reloc = FALSE;
14082 && r_type == R_PPC64_ADDR64
14084 ? h->elf.type == STT_GNU_IFUNC
14085 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
14086 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14089 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
14091 /* We need to relocate .opd contents for ld.so.
14092 Prelink also wants simple and consistent rules
14093 for relocs. This make all RELATIVE relocs have
14094 *r_offset equal to r_addend. */
14103 ? h->elf.type == STT_GNU_IFUNC
14104 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14106 info->callbacks->einfo
14107 (_("%P: %H: %s for indirect "
14108 "function `%T' unsupported\n"),
14109 input_bfd, input_section, rel->r_offset,
14110 ppc64_elf_howto_table[r_type]->name,
14114 else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
14116 else if (sec == NULL || sec->owner == NULL)
14118 bfd_set_error (bfd_error_bad_value);
14125 osec = sec->output_section;
14126 indx = elf_section_data (osec)->dynindx;
14130 if ((osec->flags & SEC_READONLY) == 0
14131 && htab->elf.data_index_section != NULL)
14132 osec = htab->elf.data_index_section;
14134 osec = htab->elf.text_index_section;
14135 indx = elf_section_data (osec)->dynindx;
14137 BFD_ASSERT (indx != 0);
14139 /* We are turning this relocation into one
14140 against a section symbol, so subtract out
14141 the output section's address but not the
14142 offset of the input section in the output
14144 outrel.r_addend -= osec->vma;
14147 outrel.r_info = ELF64_R_INFO (indx, r_type);
14151 sreloc = elf_section_data (input_section)->sreloc;
14153 ? h->elf.type == STT_GNU_IFUNC
14154 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14155 sreloc = htab->reliplt;
14156 if (sreloc == NULL)
14159 if (sreloc->reloc_count * sizeof (Elf64_External_Rela)
14162 loc = sreloc->contents;
14163 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
14164 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
14166 /* If this reloc is against an external symbol, it will
14167 be computed at runtime, so there's no need to do
14168 anything now. However, for the sake of prelink ensure
14169 that the section contents are a known value. */
14172 unresolved_reloc = FALSE;
14173 /* The value chosen here is quite arbitrary as ld.so
14174 ignores section contents except for the special
14175 case of .opd where the contents might be accessed
14176 before relocation. Choose zero, as that won't
14177 cause reloc overflow. */
14180 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
14181 to improve backward compatibility with older
14183 if (r_type == R_PPC64_ADDR64)
14184 addend = outrel.r_addend;
14185 /* Adjust pc_relative relocs to have zero in *r_offset. */
14186 else if (ppc64_elf_howto_table[r_type]->pc_relative)
14187 addend = (input_section->output_section->vma
14188 + input_section->output_offset
14195 case R_PPC64_GLOB_DAT:
14196 case R_PPC64_JMP_SLOT:
14197 case R_PPC64_JMP_IREL:
14198 case R_PPC64_RELATIVE:
14199 /* We shouldn't ever see these dynamic relocs in relocatable
14201 /* Fall through. */
14203 case R_PPC64_PLTGOT16:
14204 case R_PPC64_PLTGOT16_DS:
14205 case R_PPC64_PLTGOT16_HA:
14206 case R_PPC64_PLTGOT16_HI:
14207 case R_PPC64_PLTGOT16_LO:
14208 case R_PPC64_PLTGOT16_LO_DS:
14209 case R_PPC64_PLTREL32:
14210 case R_PPC64_PLTREL64:
14211 /* These ones haven't been implemented yet. */
14213 info->callbacks->einfo
14214 (_("%P: %B: %s is not supported for `%T'\n"),
14216 ppc64_elf_howto_table[r_type]->name, sym_name);
14218 bfd_set_error (bfd_error_invalid_operation);
14223 /* Multi-instruction sequences that access the TOC can be
14224 optimized, eg. addis ra,r2,0; addi rb,ra,x;
14225 to nop; addi rb,r2,x; */
14231 case R_PPC64_GOT_TLSLD16_HI:
14232 case R_PPC64_GOT_TLSGD16_HI:
14233 case R_PPC64_GOT_TPREL16_HI:
14234 case R_PPC64_GOT_DTPREL16_HI:
14235 case R_PPC64_GOT16_HI:
14236 case R_PPC64_TOC16_HI:
14237 /* These relocs would only be useful if building up an
14238 offset to later add to r2, perhaps in an indexed
14239 addressing mode instruction. Don't try to optimize.
14240 Unfortunately, the possibility of someone building up an
14241 offset like this or even with the HA relocs, means that
14242 we need to check the high insn when optimizing the low
14246 case R_PPC64_GOT_TLSLD16_HA:
14247 case R_PPC64_GOT_TLSGD16_HA:
14248 case R_PPC64_GOT_TPREL16_HA:
14249 case R_PPC64_GOT_DTPREL16_HA:
14250 case R_PPC64_GOT16_HA:
14251 case R_PPC64_TOC16_HA:
14252 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
14253 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
14255 bfd_byte *p = contents + (rel->r_offset & ~3);
14256 bfd_put_32 (input_bfd, NOP, p);
14260 case R_PPC64_GOT_TLSLD16_LO:
14261 case R_PPC64_GOT_TLSGD16_LO:
14262 case R_PPC64_GOT_TPREL16_LO_DS:
14263 case R_PPC64_GOT_DTPREL16_LO_DS:
14264 case R_PPC64_GOT16_LO:
14265 case R_PPC64_GOT16_LO_DS:
14266 case R_PPC64_TOC16_LO:
14267 case R_PPC64_TOC16_LO_DS:
14268 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
14269 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
14271 bfd_byte *p = contents + (rel->r_offset & ~3);
14272 insn = bfd_get_32 (input_bfd, p);
14273 if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
14275 /* Transform addic to addi when we change reg. */
14276 insn &= ~((0x3f << 26) | (0x1f << 16));
14277 insn |= (14u << 26) | (2 << 16);
14281 insn &= ~(0x1f << 16);
14284 bfd_put_32 (input_bfd, insn, p);
14289 /* Do any further special processing. */
14295 case R_PPC64_REL16_HA:
14296 case R_PPC64_ADDR16_HA:
14297 case R_PPC64_ADDR16_HIGHA:
14298 case R_PPC64_ADDR16_HIGHERA:
14299 case R_PPC64_ADDR16_HIGHESTA:
14300 case R_PPC64_TOC16_HA:
14301 case R_PPC64_SECTOFF_HA:
14302 case R_PPC64_TPREL16_HA:
14303 case R_PPC64_TPREL16_HIGHA:
14304 case R_PPC64_TPREL16_HIGHERA:
14305 case R_PPC64_TPREL16_HIGHESTA:
14306 case R_PPC64_DTPREL16_HA:
14307 case R_PPC64_DTPREL16_HIGHA:
14308 case R_PPC64_DTPREL16_HIGHERA:
14309 case R_PPC64_DTPREL16_HIGHESTA:
14310 /* It's just possible that this symbol is a weak symbol
14311 that's not actually defined anywhere. In that case,
14312 'sec' would be NULL, and we should leave the symbol
14313 alone (it will be set to zero elsewhere in the link). */
14318 case R_PPC64_GOT16_HA:
14319 case R_PPC64_PLTGOT16_HA:
14320 case R_PPC64_PLT16_HA:
14321 case R_PPC64_GOT_TLSGD16_HA:
14322 case R_PPC64_GOT_TLSLD16_HA:
14323 case R_PPC64_GOT_TPREL16_HA:
14324 case R_PPC64_GOT_DTPREL16_HA:
14325 /* Add 0x10000 if sign bit in 0:15 is set.
14326 Bits 0:15 are not used. */
14330 case R_PPC64_ADDR16_DS:
14331 case R_PPC64_ADDR16_LO_DS:
14332 case R_PPC64_GOT16_DS:
14333 case R_PPC64_GOT16_LO_DS:
14334 case R_PPC64_PLT16_LO_DS:
14335 case R_PPC64_SECTOFF_DS:
14336 case R_PPC64_SECTOFF_LO_DS:
14337 case R_PPC64_TOC16_DS:
14338 case R_PPC64_TOC16_LO_DS:
14339 case R_PPC64_PLTGOT16_DS:
14340 case R_PPC64_PLTGOT16_LO_DS:
14341 case R_PPC64_GOT_TPREL16_DS:
14342 case R_PPC64_GOT_TPREL16_LO_DS:
14343 case R_PPC64_GOT_DTPREL16_DS:
14344 case R_PPC64_GOT_DTPREL16_LO_DS:
14345 case R_PPC64_TPREL16_DS:
14346 case R_PPC64_TPREL16_LO_DS:
14347 case R_PPC64_DTPREL16_DS:
14348 case R_PPC64_DTPREL16_LO_DS:
14349 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
14351 /* If this reloc is against an lq insn, then the value must be
14352 a multiple of 16. This is somewhat of a hack, but the
14353 "correct" way to do this by defining _DQ forms of all the
14354 _DS relocs bloats all reloc switches in this file. It
14355 doesn't seem to make much sense to use any of these relocs
14356 in data, so testing the insn should be safe. */
14357 if ((insn & (0x3f << 26)) == (56u << 26))
14359 if (((relocation + addend) & mask) != 0)
14361 info->callbacks->einfo
14362 (_("%P: %H: error: %s not a multiple of %u\n"),
14363 input_bfd, input_section, rel->r_offset,
14364 ppc64_elf_howto_table[r_type]->name,
14366 bfd_set_error (bfd_error_bad_value);
14373 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
14374 because such sections are not SEC_ALLOC and thus ld.so will
14375 not process them. */
14376 if (unresolved_reloc
14377 && !((input_section->flags & SEC_DEBUGGING) != 0
14378 && h->elf.def_dynamic)
14379 && _bfd_elf_section_offset (output_bfd, info, input_section,
14380 rel->r_offset) != (bfd_vma) -1)
14382 info->callbacks->einfo
14383 (_("%P: %H: unresolvable %s against `%T'\n"),
14384 input_bfd, input_section, rel->r_offset,
14385 ppc64_elf_howto_table[(int) r_type]->name,
14386 h->elf.root.root.string);
14390 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
14398 if (r != bfd_reloc_ok)
14400 char *more_info = NULL;
14401 const char *reloc_name = ppc64_elf_howto_table[r_type]->name;
14403 if (reloc_dest != DEST_NORMAL)
14405 more_info = bfd_malloc (strlen (reloc_name) + 8);
14406 if (more_info != NULL)
14408 strcpy (more_info, reloc_name);
14409 strcat (more_info, (reloc_dest == DEST_OPD
14410 ? " (OPD)" : " (stub)"));
14411 reloc_name = more_info;
14415 if (r == bfd_reloc_overflow)
14420 && h->elf.root.type == bfd_link_hash_undefweak
14421 && ppc64_elf_howto_table[r_type]->pc_relative)
14423 /* Assume this is a call protected by other code that
14424 detects the symbol is undefined. If this is the case,
14425 we can safely ignore the overflow. If not, the
14426 program is hosed anyway, and a little warning isn't
14432 if (!((*info->callbacks->reloc_overflow)
14433 (info, &h->elf.root, sym_name,
14434 reloc_name, orig_rel.r_addend,
14435 input_bfd, input_section, rel->r_offset)))
14440 info->callbacks->einfo
14441 (_("%P: %H: %s against `%T': error %d\n"),
14442 input_bfd, input_section, rel->r_offset,
14443 reloc_name, sym_name, (int) r);
14446 if (more_info != NULL)
14451 /* If we're emitting relocations, then shortly after this function
14452 returns, reloc offsets and addends for this section will be
14453 adjusted. Worse, reloc symbol indices will be for the output
14454 file rather than the input. Save a copy of the relocs for
14455 opd_entry_value. */
14456 if (is_opd && (info->emitrelocations || info->relocatable))
14459 amt = input_section->reloc_count * sizeof (Elf_Internal_Rela);
14460 rel = bfd_alloc (input_bfd, amt);
14461 BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd.relocs == NULL);
14462 ppc64_elf_tdata (input_bfd)->opd.relocs = rel;
14465 memcpy (rel, relocs, amt);
14470 /* Adjust the value of any local symbols in opd sections. */
14473 ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
14474 const char *name ATTRIBUTE_UNUSED,
14475 Elf_Internal_Sym *elfsym,
14476 asection *input_sec,
14477 struct elf_link_hash_entry *h)
14479 struct _opd_sec_data *opd;
14486 opd = get_opd_info (input_sec);
14487 if (opd == NULL || opd->adjust == NULL)
14490 value = elfsym->st_value - input_sec->output_offset;
14491 if (!info->relocatable)
14492 value -= input_sec->output_section->vma;
14494 adjust = opd->adjust[value / 8];
14498 elfsym->st_value += adjust;
14502 /* Finish up dynamic symbol handling. We set the contents of various
14503 dynamic sections here. */
14506 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
14507 struct bfd_link_info *info,
14508 struct elf_link_hash_entry *h,
14509 Elf_Internal_Sym *sym ATTRIBUTE_UNUSED)
14511 struct ppc_link_hash_table *htab;
14512 struct plt_entry *ent;
14513 Elf_Internal_Rela rela;
14516 htab = ppc_hash_table (info);
14520 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
14521 if (ent->plt.offset != (bfd_vma) -1)
14523 /* This symbol has an entry in the procedure linkage
14524 table. Set it up. */
14525 if (!htab->elf.dynamic_sections_created
14526 || h->dynindx == -1)
14528 BFD_ASSERT (h->type == STT_GNU_IFUNC
14530 && (h->root.type == bfd_link_hash_defined
14531 || h->root.type == bfd_link_hash_defweak));
14532 rela.r_offset = (htab->iplt->output_section->vma
14533 + htab->iplt->output_offset
14534 + ent->plt.offset);
14536 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
14538 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14539 rela.r_addend = (h->root.u.def.value
14540 + h->root.u.def.section->output_offset
14541 + h->root.u.def.section->output_section->vma
14543 loc = (htab->reliplt->contents
14544 + (htab->reliplt->reloc_count++
14545 * sizeof (Elf64_External_Rela)));
14549 rela.r_offset = (htab->plt->output_section->vma
14550 + htab->plt->output_offset
14551 + ent->plt.offset);
14552 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
14553 rela.r_addend = ent->addend;
14554 loc = (htab->relplt->contents
14555 + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
14556 / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
14558 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
14563 /* This symbol needs a copy reloc. Set it up. */
14565 if (h->dynindx == -1
14566 || (h->root.type != bfd_link_hash_defined
14567 && h->root.type != bfd_link_hash_defweak)
14568 || htab->relbss == NULL)
14571 rela.r_offset = (h->root.u.def.value
14572 + h->root.u.def.section->output_section->vma
14573 + h->root.u.def.section->output_offset);
14574 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
14576 loc = htab->relbss->contents;
14577 loc += htab->relbss->reloc_count++ * sizeof (Elf64_External_Rela);
14578 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
14584 /* Used to decide how to sort relocs in an optimal manner for the
14585 dynamic linker, before writing them out. */
14587 static enum elf_reloc_type_class
14588 ppc64_elf_reloc_type_class (const struct bfd_link_info *info,
14589 const asection *rel_sec,
14590 const Elf_Internal_Rela *rela)
14592 enum elf_ppc64_reloc_type r_type;
14593 struct ppc_link_hash_table *htab = ppc_hash_table (info);
14595 if (rel_sec == htab->reliplt)
14596 return reloc_class_ifunc;
14598 r_type = ELF64_R_TYPE (rela->r_info);
14601 case R_PPC64_RELATIVE:
14602 return reloc_class_relative;
14603 case R_PPC64_JMP_SLOT:
14604 return reloc_class_plt;
14606 return reloc_class_copy;
14608 return reloc_class_normal;
14612 /* Finish up the dynamic sections. */
14615 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
14616 struct bfd_link_info *info)
14618 struct ppc_link_hash_table *htab;
14622 htab = ppc_hash_table (info);
14626 dynobj = htab->elf.dynobj;
14627 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
14629 if (htab->elf.dynamic_sections_created)
14631 Elf64_External_Dyn *dyncon, *dynconend;
14633 if (sdyn == NULL || htab->got == NULL)
14636 dyncon = (Elf64_External_Dyn *) sdyn->contents;
14637 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
14638 for (; dyncon < dynconend; dyncon++)
14640 Elf_Internal_Dyn dyn;
14643 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
14650 case DT_PPC64_GLINK:
14652 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
14653 /* We stupidly defined DT_PPC64_GLINK to be the start
14654 of glink rather than the first entry point, which is
14655 what ld.so needs, and now have a bigger stub to
14656 support automatic multiple TOCs. */
14657 dyn.d_un.d_ptr += GLINK_CALL_STUB_SIZE - 8 * 4;
14661 s = bfd_get_section_by_name (output_bfd, ".opd");
14664 dyn.d_un.d_ptr = s->vma;
14668 if (htab->do_multi_toc && htab->multi_toc_needed)
14669 dyn.d_un.d_val |= PPC64_OPT_MULTI_TOC;
14672 case DT_PPC64_OPDSZ:
14673 s = bfd_get_section_by_name (output_bfd, ".opd");
14676 dyn.d_un.d_val = s->size;
14681 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
14686 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
14690 dyn.d_un.d_val = htab->relplt->size;
14694 /* Don't count procedure linkage table relocs in the
14695 overall reloc count. */
14699 dyn.d_un.d_val -= s->size;
14703 /* We may not be using the standard ELF linker script.
14704 If .rela.plt is the first .rela section, we adjust
14705 DT_RELA to not include it. */
14709 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
14711 dyn.d_un.d_ptr += s->size;
14715 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
14719 if (htab->got != NULL && htab->got->size != 0)
14721 /* Fill in the first entry in the global offset table.
14722 We use it to hold the link-time TOCbase. */
14723 bfd_put_64 (output_bfd,
14724 elf_gp (output_bfd) + TOC_BASE_OFF,
14725 htab->got->contents);
14727 /* Set .got entry size. */
14728 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8;
14731 if (htab->plt != NULL && htab->plt->size != 0)
14733 /* Set .plt entry size. */
14734 elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize
14735 = PLT_ENTRY_SIZE (htab);
14738 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
14739 brlt ourselves if emitrelocations. */
14740 if (htab->brlt != NULL
14741 && htab->brlt->reloc_count != 0
14742 && !_bfd_elf_link_output_relocs (output_bfd,
14744 elf_section_data (htab->brlt)->rela.hdr,
14745 elf_section_data (htab->brlt)->relocs,
14749 if (htab->glink != NULL
14750 && htab->glink->reloc_count != 0
14751 && !_bfd_elf_link_output_relocs (output_bfd,
14753 elf_section_data (htab->glink)->rela.hdr,
14754 elf_section_data (htab->glink)->relocs,
14759 if (htab->glink_eh_frame != NULL
14760 && htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
14761 && !_bfd_elf_write_section_eh_frame (output_bfd, info,
14762 htab->glink_eh_frame,
14763 htab->glink_eh_frame->contents))
14766 /* We need to handle writing out multiple GOT sections ourselves,
14767 since we didn't add them to DYNOBJ. We know dynobj is the first
14769 while ((dynobj = dynobj->link_next) != NULL)
14773 if (!is_ppc64_elf (dynobj))
14776 s = ppc64_elf_tdata (dynobj)->got;
14779 && s->output_section != bfd_abs_section_ptr
14780 && !bfd_set_section_contents (output_bfd, s->output_section,
14781 s->contents, s->output_offset,
14784 s = ppc64_elf_tdata (dynobj)->relgot;
14787 && s->output_section != bfd_abs_section_ptr
14788 && !bfd_set_section_contents (output_bfd, s->output_section,
14789 s->contents, s->output_offset,
14797 #include "elf64-target.h"
14799 /* FreeBSD support */
14801 #undef TARGET_LITTLE_SYM
14802 #undef TARGET_LITTLE_NAME
14804 #undef TARGET_BIG_SYM
14805 #define TARGET_BIG_SYM bfd_elf64_powerpc_freebsd_vec
14806 #undef TARGET_BIG_NAME
14807 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
14810 #define ELF_OSABI ELFOSABI_FREEBSD
14813 #define elf64_bed elf64_powerpc_fbsd_bed
14815 #include "elf64-target.h"