1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5 Largely rewritten by Alan Modra.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
34 #include "elf/ppc64.h"
35 #include "elf64-ppc.h"
38 static bfd_reloc_status_type ppc64_elf_ha_reloc
39 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
40 static bfd_reloc_status_type ppc64_elf_branch_reloc
41 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
42 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
43 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
45 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
46 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
47 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_reloc
49 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
50 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
51 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
52 static bfd_reloc_status_type ppc64_elf_toc64_reloc
53 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
54 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
55 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
56 static bfd_vma opd_entry_value
57 (asection *, bfd_vma, asection **, bfd_vma *, bfd_boolean);
59 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
60 #define TARGET_LITTLE_NAME "elf64-powerpcle"
61 #define TARGET_BIG_SYM powerpc_elf64_vec
62 #define TARGET_BIG_NAME "elf64-powerpc"
63 #define ELF_ARCH bfd_arch_powerpc
64 #define ELF_TARGET_ID PPC64_ELF_DATA
65 #define ELF_MACHINE_CODE EM_PPC64
66 #define ELF_MAXPAGESIZE 0x10000
67 #define ELF_COMMONPAGESIZE 0x10000
68 #define elf_info_to_howto ppc64_elf_info_to_howto
70 #define elf_backend_want_got_sym 0
71 #define elf_backend_want_plt_sym 0
72 #define elf_backend_plt_alignment 3
73 #define elf_backend_plt_not_loaded 1
74 #define elf_backend_got_header_size 8
75 #define elf_backend_want_dynrelro 1
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_dtrel_excludes_plt 1
80 #define elf_backend_default_execstack 0
82 #define bfd_elf64_mkobject ppc64_elf_mkobject
83 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
84 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
85 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
86 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
87 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
88 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
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
91 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
93 #define elf_backend_object_p ppc64_elf_object_p
94 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
95 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
96 #define elf_backend_write_core_note ppc64_elf_write_core_note
97 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
98 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
99 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
100 #define elf_backend_check_directives ppc64_elf_before_check_relocs
101 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
102 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
103 #define elf_backend_check_relocs ppc64_elf_check_relocs
104 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
105 #define elf_backend_gc_keep ppc64_elf_gc_keep
106 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
107 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
108 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
109 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
110 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
111 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
112 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
113 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
114 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
115 #define elf_backend_action_discarded ppc64_elf_action_discarded
116 #define elf_backend_relocate_section ppc64_elf_relocate_section
117 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
118 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
119 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
120 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
121 #define elf_backend_special_sections ppc64_elf_special_sections
122 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
123 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
124 #define elf_backend_get_reloc_section bfd_get_section_by_name
126 /* The name of the dynamic interpreter. This is put in the .interp
128 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
130 /* The size in bytes of an entry in the procedure linkage table. */
131 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
132 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
134 /* The initial size of the plt reserved for the dynamic linker. */
135 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
137 /* Offsets to some stack save slots. */
139 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
140 /* This one is dodgy. ELFv2 does not have a linker word, so use the
141 CR save slot. Used only by optimised __tls_get_addr call stub,
142 relying on __tls_get_addr_opt not saving CR.. */
143 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
145 /* TOC base pointers offset from start of TOC. */
146 #define TOC_BASE_OFF 0x8000
147 /* TOC base alignment. */
148 #define TOC_BASE_ALIGN 256
150 /* Offset of tp and dtp pointers from start of TLS block. */
151 #define TP_OFFSET 0x7000
152 #define DTP_OFFSET 0x8000
154 /* .plt call stub instructions. The normal stub is like this, but
155 sometimes the .plt entry crosses a 64k boundary and we need to
156 insert an addi to adjust r11. */
157 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
158 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
159 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
160 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
161 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
162 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
163 #define BCTR 0x4e800420 /* bctr */
165 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
166 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
167 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
169 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
170 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
171 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
172 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
173 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
174 #define BNECTR 0x4ca20420 /* bnectr+ */
175 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
177 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
178 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
179 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
181 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
182 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
183 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
185 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
186 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
187 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
188 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
189 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
191 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
192 #define GLINK_PLTRESOLVE_SIZE(htab) \
193 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
197 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
198 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
200 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
201 /* ld %2,(0b-1b)(%11) */
202 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
203 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
209 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
210 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
211 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
212 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
213 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
216 #define NOP 0x60000000
218 /* Some other nops. */
219 #define CROR_151515 0x4def7b82
220 #define CROR_313131 0x4ffffb82
222 /* .glink entries for the first 32k functions are two instructions. */
223 #define LI_R0_0 0x38000000 /* li %r0,0 */
224 #define B_DOT 0x48000000 /* b . */
226 /* After that, we need two instructions to load the index, followed by
228 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
229 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
231 /* Instructions used by the save and restore reg functions. */
232 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
233 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
234 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
235 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
236 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
237 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
238 #define LI_R12_0 0x39800000 /* li %r12,0 */
239 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
240 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
241 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
242 #define BLR 0x4e800020 /* blr */
244 /* Since .opd is an array of descriptors and each entry will end up
245 with identical R_PPC64_RELATIVE relocs, there is really no need to
246 propagate .opd relocs; The dynamic linker should be taught to
247 relocate .opd without reloc entries. */
248 #ifndef NO_OPD_RELOCS
249 #define NO_OPD_RELOCS 0
253 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
257 abiversion (bfd *abfd)
259 return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
263 set_abiversion (bfd *abfd, int ver)
265 elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
266 elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
269 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
271 /* Relocation HOWTO's. */
272 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
274 static reloc_howto_type ppc64_elf_howto_raw[] =
276 /* This reloc does nothing. */
277 HOWTO (R_PPC64_NONE, /* type */
279 3, /* size (0 = byte, 1 = short, 2 = long) */
281 FALSE, /* pc_relative */
283 complain_overflow_dont, /* complain_on_overflow */
284 bfd_elf_generic_reloc, /* special_function */
285 "R_PPC64_NONE", /* name */
286 FALSE, /* partial_inplace */
289 FALSE), /* pcrel_offset */
291 /* A standard 32 bit relocation. */
292 HOWTO (R_PPC64_ADDR32, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 FALSE, /* pc_relative */
298 complain_overflow_bitfield, /* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_PPC64_ADDR32", /* name */
301 FALSE, /* partial_inplace */
303 0xffffffff, /* dst_mask */
304 FALSE), /* pcrel_offset */
306 /* An absolute 26 bit branch; the lower two bits must be zero.
307 FIXME: we don't check that, we just clear them. */
308 HOWTO (R_PPC64_ADDR24, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 FALSE, /* pc_relative */
314 complain_overflow_bitfield, /* complain_on_overflow */
315 bfd_elf_generic_reloc, /* special_function */
316 "R_PPC64_ADDR24", /* name */
317 FALSE, /* partial_inplace */
319 0x03fffffc, /* dst_mask */
320 FALSE), /* pcrel_offset */
322 /* A standard 16 bit relocation. */
323 HOWTO (R_PPC64_ADDR16, /* type */
325 1, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE, /* pc_relative */
329 complain_overflow_bitfield, /* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_PPC64_ADDR16", /* name */
332 FALSE, /* partial_inplace */
334 0xffff, /* dst_mask */
335 FALSE), /* pcrel_offset */
337 /* A 16 bit relocation without overflow. */
338 HOWTO (R_PPC64_ADDR16_LO, /* type */
340 1, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE, /* pc_relative */
344 complain_overflow_dont,/* complain_on_overflow */
345 bfd_elf_generic_reloc, /* special_function */
346 "R_PPC64_ADDR16_LO", /* name */
347 FALSE, /* partial_inplace */
349 0xffff, /* dst_mask */
350 FALSE), /* pcrel_offset */
352 /* Bits 16-31 of an address. */
353 HOWTO (R_PPC64_ADDR16_HI, /* type */
355 1, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE, /* pc_relative */
359 complain_overflow_signed, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_PPC64_ADDR16_HI", /* name */
362 FALSE, /* partial_inplace */
364 0xffff, /* dst_mask */
365 FALSE), /* pcrel_offset */
367 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
368 bits, treated as a signed number, is negative. */
369 HOWTO (R_PPC64_ADDR16_HA, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE, /* pc_relative */
375 complain_overflow_signed, /* complain_on_overflow */
376 ppc64_elf_ha_reloc, /* special_function */
377 "R_PPC64_ADDR16_HA", /* name */
378 FALSE, /* partial_inplace */
380 0xffff, /* dst_mask */
381 FALSE), /* pcrel_offset */
383 /* An absolute 16 bit branch; the lower two bits must be zero.
384 FIXME: we don't check that, we just clear them. */
385 HOWTO (R_PPC64_ADDR14, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE, /* pc_relative */
391 complain_overflow_signed, /* complain_on_overflow */
392 ppc64_elf_branch_reloc, /* special_function */
393 "R_PPC64_ADDR14", /* name */
394 FALSE, /* partial_inplace */
396 0x0000fffc, /* dst_mask */
397 FALSE), /* pcrel_offset */
399 /* An absolute 16 bit branch, for which bit 10 should be set to
400 indicate that the branch is expected to be taken. The lower two
401 bits must be zero. */
402 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE, /* pc_relative */
408 complain_overflow_signed, /* complain_on_overflow */
409 ppc64_elf_brtaken_reloc, /* special_function */
410 "R_PPC64_ADDR14_BRTAKEN",/* name */
411 FALSE, /* partial_inplace */
413 0x0000fffc, /* dst_mask */
414 FALSE), /* pcrel_offset */
416 /* An absolute 16 bit branch, for which bit 10 should be set to
417 indicate that the branch is not expected to be taken. The lower
418 two bits must be zero. */
419 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 FALSE, /* pc_relative */
425 complain_overflow_signed, /* complain_on_overflow */
426 ppc64_elf_brtaken_reloc, /* special_function */
427 "R_PPC64_ADDR14_BRNTAKEN",/* name */
428 FALSE, /* partial_inplace */
430 0x0000fffc, /* dst_mask */
431 FALSE), /* pcrel_offset */
433 /* A relative 26 bit branch; the lower two bits must be zero. */
434 HOWTO (R_PPC64_REL24, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 TRUE, /* pc_relative */
440 complain_overflow_signed, /* complain_on_overflow */
441 ppc64_elf_branch_reloc, /* special_function */
442 "R_PPC64_REL24", /* name */
443 FALSE, /* partial_inplace */
445 0x03fffffc, /* dst_mask */
446 TRUE), /* pcrel_offset */
448 /* A relative 16 bit branch; the lower two bits must be zero. */
449 HOWTO (R_PPC64_REL14, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 TRUE, /* pc_relative */
455 complain_overflow_signed, /* complain_on_overflow */
456 ppc64_elf_branch_reloc, /* special_function */
457 "R_PPC64_REL14", /* name */
458 FALSE, /* partial_inplace */
460 0x0000fffc, /* dst_mask */
461 TRUE), /* pcrel_offset */
463 /* A relative 16 bit branch. Bit 10 should be set to indicate that
464 the branch is expected to be taken. The lower two bits must be
466 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 TRUE, /* pc_relative */
472 complain_overflow_signed, /* complain_on_overflow */
473 ppc64_elf_brtaken_reloc, /* special_function */
474 "R_PPC64_REL14_BRTAKEN", /* name */
475 FALSE, /* partial_inplace */
477 0x0000fffc, /* dst_mask */
478 TRUE), /* pcrel_offset */
480 /* A relative 16 bit branch. Bit 10 should be set to indicate that
481 the branch is not expected to be taken. The lower two bits must
483 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 TRUE, /* pc_relative */
489 complain_overflow_signed, /* complain_on_overflow */
490 ppc64_elf_brtaken_reloc, /* special_function */
491 "R_PPC64_REL14_BRNTAKEN",/* name */
492 FALSE, /* partial_inplace */
494 0x0000fffc, /* dst_mask */
495 TRUE), /* pcrel_offset */
497 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
499 HOWTO (R_PPC64_GOT16, /* type */
501 1, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE, /* pc_relative */
505 complain_overflow_signed, /* complain_on_overflow */
506 ppc64_elf_unhandled_reloc, /* special_function */
507 "R_PPC64_GOT16", /* name */
508 FALSE, /* partial_inplace */
510 0xffff, /* dst_mask */
511 FALSE), /* pcrel_offset */
513 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
515 HOWTO (R_PPC64_GOT16_LO, /* type */
517 1, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE, /* pc_relative */
521 complain_overflow_dont, /* complain_on_overflow */
522 ppc64_elf_unhandled_reloc, /* special_function */
523 "R_PPC64_GOT16_LO", /* name */
524 FALSE, /* partial_inplace */
526 0xffff, /* dst_mask */
527 FALSE), /* pcrel_offset */
529 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
531 HOWTO (R_PPC64_GOT16_HI, /* type */
533 1, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE, /* pc_relative */
537 complain_overflow_signed,/* complain_on_overflow */
538 ppc64_elf_unhandled_reloc, /* special_function */
539 "R_PPC64_GOT16_HI", /* name */
540 FALSE, /* partial_inplace */
542 0xffff, /* dst_mask */
543 FALSE), /* pcrel_offset */
545 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
547 HOWTO (R_PPC64_GOT16_HA, /* type */
549 1, /* size (0 = byte, 1 = short, 2 = long) */
551 FALSE, /* pc_relative */
553 complain_overflow_signed,/* complain_on_overflow */
554 ppc64_elf_unhandled_reloc, /* special_function */
555 "R_PPC64_GOT16_HA", /* name */
556 FALSE, /* partial_inplace */
558 0xffff, /* dst_mask */
559 FALSE), /* pcrel_offset */
561 /* This is used only by the dynamic linker. The symbol should exist
562 both in the object being run and in some shared library. The
563 dynamic linker copies the data addressed by the symbol from the
564 shared library into the object, because the object being
565 run has to have the data at some particular address. */
566 HOWTO (R_PPC64_COPY, /* type */
568 0, /* this one is variable size */
570 FALSE, /* pc_relative */
572 complain_overflow_dont, /* complain_on_overflow */
573 ppc64_elf_unhandled_reloc, /* special_function */
574 "R_PPC64_COPY", /* name */
575 FALSE, /* partial_inplace */
578 FALSE), /* pcrel_offset */
580 /* Like R_PPC64_ADDR64, but used when setting global offset table
582 HOWTO (R_PPC64_GLOB_DAT, /* 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 ppc64_elf_unhandled_reloc, /* special_function */
590 "R_PPC64_GLOB_DAT", /* name */
591 FALSE, /* partial_inplace */
593 ONES (64), /* dst_mask */
594 FALSE), /* pcrel_offset */
596 /* Created by the link editor. Marks a procedure linkage table
597 entry for a symbol. */
598 HOWTO (R_PPC64_JMP_SLOT, /* type */
600 0, /* size (0 = byte, 1 = short, 2 = long) */
602 FALSE, /* pc_relative */
604 complain_overflow_dont, /* complain_on_overflow */
605 ppc64_elf_unhandled_reloc, /* special_function */
606 "R_PPC64_JMP_SLOT", /* name */
607 FALSE, /* partial_inplace */
610 FALSE), /* pcrel_offset */
612 /* Used only by the dynamic linker. When the object is run, this
613 doubleword64 is set to the load address of the object, plus the
615 HOWTO (R_PPC64_RELATIVE, /* type */
617 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
619 FALSE, /* pc_relative */
621 complain_overflow_dont, /* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_PPC64_RELATIVE", /* name */
624 FALSE, /* partial_inplace */
626 ONES (64), /* dst_mask */
627 FALSE), /* pcrel_offset */
629 /* Like R_PPC64_ADDR32, but may be unaligned. */
630 HOWTO (R_PPC64_UADDR32, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 FALSE, /* pc_relative */
636 complain_overflow_bitfield, /* complain_on_overflow */
637 bfd_elf_generic_reloc, /* special_function */
638 "R_PPC64_UADDR32", /* name */
639 FALSE, /* partial_inplace */
641 0xffffffff, /* dst_mask */
642 FALSE), /* pcrel_offset */
644 /* Like R_PPC64_ADDR16, but may be unaligned. */
645 HOWTO (R_PPC64_UADDR16, /* type */
647 1, /* size (0 = byte, 1 = short, 2 = long) */
649 FALSE, /* pc_relative */
651 complain_overflow_bitfield, /* complain_on_overflow */
652 bfd_elf_generic_reloc, /* special_function */
653 "R_PPC64_UADDR16", /* name */
654 FALSE, /* partial_inplace */
656 0xffff, /* dst_mask */
657 FALSE), /* pcrel_offset */
659 /* 32-bit PC relative. */
660 HOWTO (R_PPC64_REL32, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 TRUE, /* pc_relative */
666 complain_overflow_signed, /* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_PPC64_REL32", /* name */
669 FALSE, /* partial_inplace */
671 0xffffffff, /* dst_mask */
672 TRUE), /* pcrel_offset */
674 /* 32-bit relocation to the symbol's procedure linkage table. */
675 HOWTO (R_PPC64_PLT32, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE, /* pc_relative */
681 complain_overflow_bitfield, /* complain_on_overflow */
682 ppc64_elf_unhandled_reloc, /* special_function */
683 "R_PPC64_PLT32", /* name */
684 FALSE, /* partial_inplace */
686 0xffffffff, /* dst_mask */
687 FALSE), /* pcrel_offset */
689 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
690 FIXME: R_PPC64_PLTREL32 not supported. */
691 HOWTO (R_PPC64_PLTREL32, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE, /* pc_relative */
697 complain_overflow_signed, /* complain_on_overflow */
698 ppc64_elf_unhandled_reloc, /* special_function */
699 "R_PPC64_PLTREL32", /* name */
700 FALSE, /* partial_inplace */
702 0xffffffff, /* dst_mask */
703 TRUE), /* pcrel_offset */
705 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
707 HOWTO (R_PPC64_PLT16_LO, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE, /* pc_relative */
713 complain_overflow_dont, /* complain_on_overflow */
714 ppc64_elf_unhandled_reloc, /* special_function */
715 "R_PPC64_PLT16_LO", /* name */
716 FALSE, /* partial_inplace */
718 0xffff, /* dst_mask */
719 FALSE), /* pcrel_offset */
721 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
723 HOWTO (R_PPC64_PLT16_HI, /* type */
725 1, /* size (0 = byte, 1 = short, 2 = long) */
727 FALSE, /* pc_relative */
729 complain_overflow_signed, /* complain_on_overflow */
730 ppc64_elf_unhandled_reloc, /* special_function */
731 "R_PPC64_PLT16_HI", /* name */
732 FALSE, /* partial_inplace */
734 0xffff, /* dst_mask */
735 FALSE), /* pcrel_offset */
737 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
739 HOWTO (R_PPC64_PLT16_HA, /* type */
741 1, /* size (0 = byte, 1 = short, 2 = long) */
743 FALSE, /* pc_relative */
745 complain_overflow_signed, /* complain_on_overflow */
746 ppc64_elf_unhandled_reloc, /* special_function */
747 "R_PPC64_PLT16_HA", /* name */
748 FALSE, /* partial_inplace */
750 0xffff, /* dst_mask */
751 FALSE), /* pcrel_offset */
753 /* 16-bit section relative relocation. */
754 HOWTO (R_PPC64_SECTOFF, /* type */
756 1, /* size (0 = byte, 1 = short, 2 = long) */
758 FALSE, /* pc_relative */
760 complain_overflow_signed, /* complain_on_overflow */
761 ppc64_elf_sectoff_reloc, /* special_function */
762 "R_PPC64_SECTOFF", /* name */
763 FALSE, /* partial_inplace */
765 0xffff, /* dst_mask */
766 FALSE), /* pcrel_offset */
768 /* Like R_PPC64_SECTOFF, but no overflow warning. */
769 HOWTO (R_PPC64_SECTOFF_LO, /* type */
771 1, /* size (0 = byte, 1 = short, 2 = long) */
773 FALSE, /* pc_relative */
775 complain_overflow_dont, /* complain_on_overflow */
776 ppc64_elf_sectoff_reloc, /* special_function */
777 "R_PPC64_SECTOFF_LO", /* name */
778 FALSE, /* partial_inplace */
780 0xffff, /* dst_mask */
781 FALSE), /* pcrel_offset */
783 /* 16-bit upper half section relative relocation. */
784 HOWTO (R_PPC64_SECTOFF_HI, /* type */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
788 FALSE, /* pc_relative */
790 complain_overflow_signed, /* complain_on_overflow */
791 ppc64_elf_sectoff_reloc, /* special_function */
792 "R_PPC64_SECTOFF_HI", /* name */
793 FALSE, /* partial_inplace */
795 0xffff, /* dst_mask */
796 FALSE), /* pcrel_offset */
798 /* 16-bit upper half adjusted section relative relocation. */
799 HOWTO (R_PPC64_SECTOFF_HA, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE, /* pc_relative */
805 complain_overflow_signed, /* complain_on_overflow */
806 ppc64_elf_sectoff_ha_reloc, /* special_function */
807 "R_PPC64_SECTOFF_HA", /* name */
808 FALSE, /* partial_inplace */
810 0xffff, /* dst_mask */
811 FALSE), /* pcrel_offset */
813 /* Like R_PPC64_REL24 without touching the two least significant bits. */
814 HOWTO (R_PPC64_REL30, /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 TRUE, /* pc_relative */
820 complain_overflow_dont, /* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_PPC64_REL30", /* name */
823 FALSE, /* partial_inplace */
825 0xfffffffc, /* dst_mask */
826 TRUE), /* pcrel_offset */
828 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
830 /* A standard 64-bit relocation. */
831 HOWTO (R_PPC64_ADDR64, /* type */
833 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
835 FALSE, /* pc_relative */
837 complain_overflow_dont, /* complain_on_overflow */
838 bfd_elf_generic_reloc, /* special_function */
839 "R_PPC64_ADDR64", /* name */
840 FALSE, /* partial_inplace */
842 ONES (64), /* dst_mask */
843 FALSE), /* pcrel_offset */
845 /* The bits 32-47 of an address. */
846 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE, /* pc_relative */
852 complain_overflow_dont, /* complain_on_overflow */
853 bfd_elf_generic_reloc, /* special_function */
854 "R_PPC64_ADDR16_HIGHER", /* name */
855 FALSE, /* partial_inplace */
857 0xffff, /* dst_mask */
858 FALSE), /* pcrel_offset */
860 /* The bits 32-47 of an address, plus 1 if the contents of the low
861 16 bits, treated as a signed number, is negative. */
862 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
864 1, /* size (0 = byte, 1 = short, 2 = long) */
866 FALSE, /* pc_relative */
868 complain_overflow_dont, /* complain_on_overflow */
869 ppc64_elf_ha_reloc, /* special_function */
870 "R_PPC64_ADDR16_HIGHERA", /* name */
871 FALSE, /* partial_inplace */
873 0xffff, /* dst_mask */
874 FALSE), /* pcrel_offset */
876 /* The bits 48-63 of an address. */
877 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
879 1, /* size (0 = byte, 1 = short, 2 = long) */
881 FALSE, /* pc_relative */
883 complain_overflow_dont, /* complain_on_overflow */
884 bfd_elf_generic_reloc, /* special_function */
885 "R_PPC64_ADDR16_HIGHEST", /* name */
886 FALSE, /* partial_inplace */
888 0xffff, /* dst_mask */
889 FALSE), /* pcrel_offset */
891 /* The bits 48-63 of an address, plus 1 if the contents of the low
892 16 bits, treated as a signed number, is negative. */
893 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
895 1, /* size (0 = byte, 1 = short, 2 = long) */
897 FALSE, /* pc_relative */
899 complain_overflow_dont, /* complain_on_overflow */
900 ppc64_elf_ha_reloc, /* special_function */
901 "R_PPC64_ADDR16_HIGHESTA", /* name */
902 FALSE, /* partial_inplace */
904 0xffff, /* dst_mask */
905 FALSE), /* pcrel_offset */
907 /* Like ADDR64, but may be unaligned. */
908 HOWTO (R_PPC64_UADDR64, /* type */
910 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
912 FALSE, /* pc_relative */
914 complain_overflow_dont, /* complain_on_overflow */
915 bfd_elf_generic_reloc, /* special_function */
916 "R_PPC64_UADDR64", /* name */
917 FALSE, /* partial_inplace */
919 ONES (64), /* dst_mask */
920 FALSE), /* pcrel_offset */
922 /* 64-bit relative relocation. */
923 HOWTO (R_PPC64_REL64, /* 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 bfd_elf_generic_reloc, /* special_function */
931 "R_PPC64_REL64", /* name */
932 FALSE, /* partial_inplace */
934 ONES (64), /* dst_mask */
935 TRUE), /* pcrel_offset */
937 /* 64-bit relocation to the symbol's procedure linkage table. */
938 HOWTO (R_PPC64_PLT64, /* type */
940 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
942 FALSE, /* pc_relative */
944 complain_overflow_dont, /* complain_on_overflow */
945 ppc64_elf_unhandled_reloc, /* special_function */
946 "R_PPC64_PLT64", /* name */
947 FALSE, /* partial_inplace */
949 ONES (64), /* dst_mask */
950 FALSE), /* pcrel_offset */
952 /* 64-bit PC relative relocation to the symbol's procedure linkage
954 /* FIXME: R_PPC64_PLTREL64 not supported. */
955 HOWTO (R_PPC64_PLTREL64, /* type */
957 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
959 TRUE, /* pc_relative */
961 complain_overflow_dont, /* complain_on_overflow */
962 ppc64_elf_unhandled_reloc, /* special_function */
963 "R_PPC64_PLTREL64", /* name */
964 FALSE, /* partial_inplace */
966 ONES (64), /* dst_mask */
967 TRUE), /* pcrel_offset */
969 /* 16 bit TOC-relative relocation. */
971 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
972 HOWTO (R_PPC64_TOC16, /* type */
974 1, /* size (0 = byte, 1 = short, 2 = long) */
976 FALSE, /* pc_relative */
978 complain_overflow_signed, /* complain_on_overflow */
979 ppc64_elf_toc_reloc, /* special_function */
980 "R_PPC64_TOC16", /* name */
981 FALSE, /* partial_inplace */
983 0xffff, /* dst_mask */
984 FALSE), /* pcrel_offset */
986 /* 16 bit TOC-relative relocation without overflow. */
988 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
989 HOWTO (R_PPC64_TOC16_LO, /* type */
991 1, /* size (0 = byte, 1 = short, 2 = long) */
993 FALSE, /* pc_relative */
995 complain_overflow_dont, /* complain_on_overflow */
996 ppc64_elf_toc_reloc, /* special_function */
997 "R_PPC64_TOC16_LO", /* name */
998 FALSE, /* partial_inplace */
1000 0xffff, /* dst_mask */
1001 FALSE), /* pcrel_offset */
1003 /* 16 bit TOC-relative relocation, high 16 bits. */
1005 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
1006 HOWTO (R_PPC64_TOC16_HI, /* type */
1007 16, /* rightshift */
1008 1, /* size (0 = byte, 1 = short, 2 = long) */
1010 FALSE, /* pc_relative */
1012 complain_overflow_signed, /* complain_on_overflow */
1013 ppc64_elf_toc_reloc, /* special_function */
1014 "R_PPC64_TOC16_HI", /* name */
1015 FALSE, /* partial_inplace */
1017 0xffff, /* dst_mask */
1018 FALSE), /* pcrel_offset */
1020 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1021 contents of the low 16 bits, treated as a signed number, is
1024 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1025 HOWTO (R_PPC64_TOC16_HA, /* type */
1026 16, /* rightshift */
1027 1, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE, /* pc_relative */
1031 complain_overflow_signed, /* complain_on_overflow */
1032 ppc64_elf_toc_ha_reloc, /* special_function */
1033 "R_PPC64_TOC16_HA", /* name */
1034 FALSE, /* partial_inplace */
1036 0xffff, /* dst_mask */
1037 FALSE), /* pcrel_offset */
1039 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1041 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1042 HOWTO (R_PPC64_TOC, /* type */
1044 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1046 FALSE, /* pc_relative */
1048 complain_overflow_dont, /* complain_on_overflow */
1049 ppc64_elf_toc64_reloc, /* special_function */
1050 "R_PPC64_TOC", /* name */
1051 FALSE, /* partial_inplace */
1053 ONES (64), /* dst_mask */
1054 FALSE), /* pcrel_offset */
1056 /* Like R_PPC64_GOT16, but also informs the link editor that the
1057 value to relocate may (!) refer to a PLT entry which the link
1058 editor (a) may replace with the symbol value. If the link editor
1059 is unable to fully resolve the symbol, it may (b) create a PLT
1060 entry and store the address to the new PLT entry in the GOT.
1061 This permits lazy resolution of function symbols at run time.
1062 The link editor may also skip all of this and just (c) emit a
1063 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1064 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1065 HOWTO (R_PPC64_PLTGOT16, /* type */
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", /* name */
1074 FALSE, /* partial_inplace */
1076 0xffff, /* dst_mask */
1077 FALSE), /* pcrel_offset */
1079 /* Like R_PPC64_PLTGOT16, but without overflow. */
1080 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1081 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1085 FALSE, /* pc_relative */
1087 complain_overflow_dont, /* complain_on_overflow */
1088 ppc64_elf_unhandled_reloc, /* special_function */
1089 "R_PPC64_PLTGOT16_LO", /* name */
1090 FALSE, /* partial_inplace */
1092 0xffff, /* dst_mask */
1093 FALSE), /* pcrel_offset */
1095 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1096 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1097 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
1098 16, /* rightshift */
1099 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 FALSE, /* pc_relative */
1103 complain_overflow_signed, /* complain_on_overflow */
1104 ppc64_elf_unhandled_reloc, /* special_function */
1105 "R_PPC64_PLTGOT16_HI", /* name */
1106 FALSE, /* partial_inplace */
1108 0xffff, /* dst_mask */
1109 FALSE), /* pcrel_offset */
1111 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1112 1 if the contents of the low 16 bits, treated as a signed number,
1114 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1115 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1116 16, /* rightshift */
1117 1, /* size (0 = byte, 1 = short, 2 = long) */
1119 FALSE, /* pc_relative */
1121 complain_overflow_signed, /* complain_on_overflow */
1122 ppc64_elf_unhandled_reloc, /* special_function */
1123 "R_PPC64_PLTGOT16_HA", /* name */
1124 FALSE, /* partial_inplace */
1126 0xffff, /* dst_mask */
1127 FALSE), /* pcrel_offset */
1129 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1130 HOWTO (R_PPC64_ADDR16_DS, /* type */
1132 1, /* size (0 = byte, 1 = short, 2 = long) */
1134 FALSE, /* pc_relative */
1136 complain_overflow_signed, /* complain_on_overflow */
1137 bfd_elf_generic_reloc, /* special_function */
1138 "R_PPC64_ADDR16_DS", /* name */
1139 FALSE, /* partial_inplace */
1141 0xfffc, /* dst_mask */
1142 FALSE), /* pcrel_offset */
1144 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1145 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1147 1, /* size (0 = byte, 1 = short, 2 = long) */
1149 FALSE, /* pc_relative */
1151 complain_overflow_dont,/* complain_on_overflow */
1152 bfd_elf_generic_reloc, /* special_function */
1153 "R_PPC64_ADDR16_LO_DS",/* name */
1154 FALSE, /* partial_inplace */
1156 0xfffc, /* dst_mask */
1157 FALSE), /* pcrel_offset */
1159 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1160 HOWTO (R_PPC64_GOT16_DS, /* type */
1162 1, /* size (0 = byte, 1 = short, 2 = long) */
1164 FALSE, /* pc_relative */
1166 complain_overflow_signed, /* complain_on_overflow */
1167 ppc64_elf_unhandled_reloc, /* special_function */
1168 "R_PPC64_GOT16_DS", /* name */
1169 FALSE, /* partial_inplace */
1171 0xfffc, /* dst_mask */
1172 FALSE), /* pcrel_offset */
1174 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1175 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1177 1, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE, /* pc_relative */
1181 complain_overflow_dont, /* complain_on_overflow */
1182 ppc64_elf_unhandled_reloc, /* special_function */
1183 "R_PPC64_GOT16_LO_DS", /* name */
1184 FALSE, /* partial_inplace */
1186 0xfffc, /* dst_mask */
1187 FALSE), /* pcrel_offset */
1189 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1190 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1192 1, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE, /* pc_relative */
1196 complain_overflow_dont, /* complain_on_overflow */
1197 ppc64_elf_unhandled_reloc, /* special_function */
1198 "R_PPC64_PLT16_LO_DS", /* name */
1199 FALSE, /* partial_inplace */
1201 0xfffc, /* dst_mask */
1202 FALSE), /* pcrel_offset */
1204 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1205 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1207 1, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE, /* pc_relative */
1211 complain_overflow_signed, /* complain_on_overflow */
1212 ppc64_elf_sectoff_reloc, /* special_function */
1213 "R_PPC64_SECTOFF_DS", /* name */
1214 FALSE, /* partial_inplace */
1216 0xfffc, /* dst_mask */
1217 FALSE), /* pcrel_offset */
1219 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1220 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1222 1, /* size (0 = byte, 1 = short, 2 = long) */
1224 FALSE, /* pc_relative */
1226 complain_overflow_dont, /* complain_on_overflow */
1227 ppc64_elf_sectoff_reloc, /* special_function */
1228 "R_PPC64_SECTOFF_LO_DS",/* name */
1229 FALSE, /* partial_inplace */
1231 0xfffc, /* dst_mask */
1232 FALSE), /* pcrel_offset */
1234 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1235 HOWTO (R_PPC64_TOC16_DS, /* type */
1237 1, /* size (0 = byte, 1 = short, 2 = long) */
1239 FALSE, /* pc_relative */
1241 complain_overflow_signed, /* complain_on_overflow */
1242 ppc64_elf_toc_reloc, /* special_function */
1243 "R_PPC64_TOC16_DS", /* name */
1244 FALSE, /* partial_inplace */
1246 0xfffc, /* dst_mask */
1247 FALSE), /* pcrel_offset */
1249 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1250 HOWTO (R_PPC64_TOC16_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_toc_reloc, /* special_function */
1258 "R_PPC64_TOC16_LO_DS", /* name */
1259 FALSE, /* partial_inplace */
1261 0xfffc, /* dst_mask */
1262 FALSE), /* pcrel_offset */
1264 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1265 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1266 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1268 1, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE, /* pc_relative */
1272 complain_overflow_signed, /* complain_on_overflow */
1273 ppc64_elf_unhandled_reloc, /* special_function */
1274 "R_PPC64_PLTGOT16_DS", /* name */
1275 FALSE, /* partial_inplace */
1277 0xfffc, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1280 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1281 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1282 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1284 1, /* size (0 = byte, 1 = short, 2 = long) */
1286 FALSE, /* pc_relative */
1288 complain_overflow_dont, /* complain_on_overflow */
1289 ppc64_elf_unhandled_reloc, /* special_function */
1290 "R_PPC64_PLTGOT16_LO_DS",/* name */
1291 FALSE, /* partial_inplace */
1293 0xfffc, /* dst_mask */
1294 FALSE), /* pcrel_offset */
1296 /* Marker relocs for TLS. */
1299 2, /* size (0 = byte, 1 = short, 2 = long) */
1301 FALSE, /* pc_relative */
1303 complain_overflow_dont, /* complain_on_overflow */
1304 bfd_elf_generic_reloc, /* special_function */
1305 "R_PPC64_TLS", /* name */
1306 FALSE, /* partial_inplace */
1309 FALSE), /* pcrel_offset */
1311 HOWTO (R_PPC64_TLSGD,
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1315 FALSE, /* pc_relative */
1317 complain_overflow_dont, /* complain_on_overflow */
1318 bfd_elf_generic_reloc, /* special_function */
1319 "R_PPC64_TLSGD", /* name */
1320 FALSE, /* partial_inplace */
1323 FALSE), /* pcrel_offset */
1325 HOWTO (R_PPC64_TLSLD,
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 FALSE, /* pc_relative */
1331 complain_overflow_dont, /* complain_on_overflow */
1332 bfd_elf_generic_reloc, /* special_function */
1333 "R_PPC64_TLSLD", /* name */
1334 FALSE, /* partial_inplace */
1337 FALSE), /* pcrel_offset */
1339 HOWTO (R_PPC64_TOCSAVE,
1341 2, /* size (0 = byte, 1 = short, 2 = long) */
1343 FALSE, /* pc_relative */
1345 complain_overflow_dont, /* complain_on_overflow */
1346 bfd_elf_generic_reloc, /* special_function */
1347 "R_PPC64_TOCSAVE", /* name */
1348 FALSE, /* partial_inplace */
1351 FALSE), /* pcrel_offset */
1353 /* Computes the load module index of the load module that contains the
1354 definition of its TLS sym. */
1355 HOWTO (R_PPC64_DTPMOD64,
1357 4, /* size (0 = byte, 1 = short, 2 = long) */
1359 FALSE, /* pc_relative */
1361 complain_overflow_dont, /* complain_on_overflow */
1362 ppc64_elf_unhandled_reloc, /* special_function */
1363 "R_PPC64_DTPMOD64", /* name */
1364 FALSE, /* partial_inplace */
1366 ONES (64), /* dst_mask */
1367 FALSE), /* pcrel_offset */
1369 /* Computes a dtv-relative displacement, the difference between the value
1370 of sym+add and the base address of the thread-local storage block that
1371 contains the definition of sym, minus 0x8000. */
1372 HOWTO (R_PPC64_DTPREL64,
1374 4, /* size (0 = byte, 1 = short, 2 = long) */
1376 FALSE, /* pc_relative */
1378 complain_overflow_dont, /* complain_on_overflow */
1379 ppc64_elf_unhandled_reloc, /* special_function */
1380 "R_PPC64_DTPREL64", /* name */
1381 FALSE, /* partial_inplace */
1383 ONES (64), /* dst_mask */
1384 FALSE), /* pcrel_offset */
1386 /* A 16 bit dtprel reloc. */
1387 HOWTO (R_PPC64_DTPREL16,
1389 1, /* size (0 = byte, 1 = short, 2 = long) */
1391 FALSE, /* pc_relative */
1393 complain_overflow_signed, /* complain_on_overflow */
1394 ppc64_elf_unhandled_reloc, /* special_function */
1395 "R_PPC64_DTPREL16", /* name */
1396 FALSE, /* partial_inplace */
1398 0xffff, /* dst_mask */
1399 FALSE), /* pcrel_offset */
1401 /* Like DTPREL16, but no overflow. */
1402 HOWTO (R_PPC64_DTPREL16_LO,
1404 1, /* size (0 = byte, 1 = short, 2 = long) */
1406 FALSE, /* pc_relative */
1408 complain_overflow_dont, /* complain_on_overflow */
1409 ppc64_elf_unhandled_reloc, /* special_function */
1410 "R_PPC64_DTPREL16_LO", /* name */
1411 FALSE, /* partial_inplace */
1413 0xffff, /* dst_mask */
1414 FALSE), /* pcrel_offset */
1416 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1417 HOWTO (R_PPC64_DTPREL16_HI,
1418 16, /* rightshift */
1419 1, /* size (0 = byte, 1 = short, 2 = long) */
1421 FALSE, /* pc_relative */
1423 complain_overflow_signed, /* complain_on_overflow */
1424 ppc64_elf_unhandled_reloc, /* special_function */
1425 "R_PPC64_DTPREL16_HI", /* name */
1426 FALSE, /* partial_inplace */
1428 0xffff, /* dst_mask */
1429 FALSE), /* pcrel_offset */
1431 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1432 HOWTO (R_PPC64_DTPREL16_HA,
1433 16, /* rightshift */
1434 1, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE, /* pc_relative */
1438 complain_overflow_signed, /* complain_on_overflow */
1439 ppc64_elf_unhandled_reloc, /* special_function */
1440 "R_PPC64_DTPREL16_HA", /* name */
1441 FALSE, /* partial_inplace */
1443 0xffff, /* dst_mask */
1444 FALSE), /* pcrel_offset */
1446 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1447 HOWTO (R_PPC64_DTPREL16_HIGHER,
1448 32, /* rightshift */
1449 1, /* size (0 = byte, 1 = short, 2 = long) */
1451 FALSE, /* pc_relative */
1453 complain_overflow_dont, /* complain_on_overflow */
1454 ppc64_elf_unhandled_reloc, /* special_function */
1455 "R_PPC64_DTPREL16_HIGHER", /* name */
1456 FALSE, /* partial_inplace */
1458 0xffff, /* dst_mask */
1459 FALSE), /* pcrel_offset */
1461 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1462 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1463 32, /* rightshift */
1464 1, /* size (0 = byte, 1 = short, 2 = long) */
1466 FALSE, /* pc_relative */
1468 complain_overflow_dont, /* complain_on_overflow */
1469 ppc64_elf_unhandled_reloc, /* special_function */
1470 "R_PPC64_DTPREL16_HIGHERA", /* name */
1471 FALSE, /* partial_inplace */
1473 0xffff, /* dst_mask */
1474 FALSE), /* pcrel_offset */
1476 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1477 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1478 48, /* rightshift */
1479 1, /* size (0 = byte, 1 = short, 2 = long) */
1481 FALSE, /* pc_relative */
1483 complain_overflow_dont, /* complain_on_overflow */
1484 ppc64_elf_unhandled_reloc, /* special_function */
1485 "R_PPC64_DTPREL16_HIGHEST", /* name */
1486 FALSE, /* partial_inplace */
1488 0xffff, /* dst_mask */
1489 FALSE), /* pcrel_offset */
1491 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1492 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1493 48, /* rightshift */
1494 1, /* size (0 = byte, 1 = short, 2 = long) */
1496 FALSE, /* pc_relative */
1498 complain_overflow_dont, /* complain_on_overflow */
1499 ppc64_elf_unhandled_reloc, /* special_function */
1500 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1501 FALSE, /* partial_inplace */
1503 0xffff, /* dst_mask */
1504 FALSE), /* pcrel_offset */
1506 /* Like DTPREL16, but for insns with a DS field. */
1507 HOWTO (R_PPC64_DTPREL16_DS,
1509 1, /* size (0 = byte, 1 = short, 2 = long) */
1511 FALSE, /* pc_relative */
1513 complain_overflow_signed, /* complain_on_overflow */
1514 ppc64_elf_unhandled_reloc, /* special_function */
1515 "R_PPC64_DTPREL16_DS", /* name */
1516 FALSE, /* partial_inplace */
1518 0xfffc, /* dst_mask */
1519 FALSE), /* pcrel_offset */
1521 /* Like DTPREL16_DS, but no overflow. */
1522 HOWTO (R_PPC64_DTPREL16_LO_DS,
1524 1, /* size (0 = byte, 1 = short, 2 = long) */
1526 FALSE, /* pc_relative */
1528 complain_overflow_dont, /* complain_on_overflow */
1529 ppc64_elf_unhandled_reloc, /* special_function */
1530 "R_PPC64_DTPREL16_LO_DS", /* name */
1531 FALSE, /* partial_inplace */
1533 0xfffc, /* dst_mask */
1534 FALSE), /* pcrel_offset */
1536 /* Computes a tp-relative displacement, the difference between the value of
1537 sym+add and the value of the thread pointer (r13). */
1538 HOWTO (R_PPC64_TPREL64,
1540 4, /* size (0 = byte, 1 = short, 2 = long) */
1542 FALSE, /* pc_relative */
1544 complain_overflow_dont, /* complain_on_overflow */
1545 ppc64_elf_unhandled_reloc, /* special_function */
1546 "R_PPC64_TPREL64", /* name */
1547 FALSE, /* partial_inplace */
1549 ONES (64), /* dst_mask */
1550 FALSE), /* pcrel_offset */
1552 /* A 16 bit tprel reloc. */
1553 HOWTO (R_PPC64_TPREL16,
1555 1, /* size (0 = byte, 1 = short, 2 = long) */
1557 FALSE, /* pc_relative */
1559 complain_overflow_signed, /* complain_on_overflow */
1560 ppc64_elf_unhandled_reloc, /* special_function */
1561 "R_PPC64_TPREL16", /* name */
1562 FALSE, /* partial_inplace */
1564 0xffff, /* dst_mask */
1565 FALSE), /* pcrel_offset */
1567 /* Like TPREL16, but no overflow. */
1568 HOWTO (R_PPC64_TPREL16_LO,
1570 1, /* size (0 = byte, 1 = short, 2 = long) */
1572 FALSE, /* pc_relative */
1574 complain_overflow_dont, /* complain_on_overflow */
1575 ppc64_elf_unhandled_reloc, /* special_function */
1576 "R_PPC64_TPREL16_LO", /* name */
1577 FALSE, /* partial_inplace */
1579 0xffff, /* dst_mask */
1580 FALSE), /* pcrel_offset */
1582 /* Like TPREL16_LO, but next higher group of 16 bits. */
1583 HOWTO (R_PPC64_TPREL16_HI,
1584 16, /* rightshift */
1585 1, /* size (0 = byte, 1 = short, 2 = long) */
1587 FALSE, /* pc_relative */
1589 complain_overflow_signed, /* complain_on_overflow */
1590 ppc64_elf_unhandled_reloc, /* special_function */
1591 "R_PPC64_TPREL16_HI", /* name */
1592 FALSE, /* partial_inplace */
1594 0xffff, /* dst_mask */
1595 FALSE), /* pcrel_offset */
1597 /* Like TPREL16_HI, but adjust for low 16 bits. */
1598 HOWTO (R_PPC64_TPREL16_HA,
1599 16, /* rightshift */
1600 1, /* size (0 = byte, 1 = short, 2 = long) */
1602 FALSE, /* pc_relative */
1604 complain_overflow_signed, /* complain_on_overflow */
1605 ppc64_elf_unhandled_reloc, /* special_function */
1606 "R_PPC64_TPREL16_HA", /* name */
1607 FALSE, /* partial_inplace */
1609 0xffff, /* dst_mask */
1610 FALSE), /* pcrel_offset */
1612 /* Like TPREL16_HI, but next higher group of 16 bits. */
1613 HOWTO (R_PPC64_TPREL16_HIGHER,
1614 32, /* rightshift */
1615 1, /* size (0 = byte, 1 = short, 2 = long) */
1617 FALSE, /* pc_relative */
1619 complain_overflow_dont, /* complain_on_overflow */
1620 ppc64_elf_unhandled_reloc, /* special_function */
1621 "R_PPC64_TPREL16_HIGHER", /* name */
1622 FALSE, /* partial_inplace */
1624 0xffff, /* dst_mask */
1625 FALSE), /* pcrel_offset */
1627 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1628 HOWTO (R_PPC64_TPREL16_HIGHERA,
1629 32, /* rightshift */
1630 1, /* size (0 = byte, 1 = short, 2 = long) */
1632 FALSE, /* pc_relative */
1634 complain_overflow_dont, /* complain_on_overflow */
1635 ppc64_elf_unhandled_reloc, /* special_function */
1636 "R_PPC64_TPREL16_HIGHERA", /* name */
1637 FALSE, /* partial_inplace */
1639 0xffff, /* dst_mask */
1640 FALSE), /* pcrel_offset */
1642 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1643 HOWTO (R_PPC64_TPREL16_HIGHEST,
1644 48, /* rightshift */
1645 1, /* size (0 = byte, 1 = short, 2 = long) */
1647 FALSE, /* pc_relative */
1649 complain_overflow_dont, /* complain_on_overflow */
1650 ppc64_elf_unhandled_reloc, /* special_function */
1651 "R_PPC64_TPREL16_HIGHEST", /* name */
1652 FALSE, /* partial_inplace */
1654 0xffff, /* dst_mask */
1655 FALSE), /* pcrel_offset */
1657 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1658 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1659 48, /* rightshift */
1660 1, /* size (0 = byte, 1 = short, 2 = long) */
1662 FALSE, /* pc_relative */
1664 complain_overflow_dont, /* complain_on_overflow */
1665 ppc64_elf_unhandled_reloc, /* special_function */
1666 "R_PPC64_TPREL16_HIGHESTA", /* name */
1667 FALSE, /* partial_inplace */
1669 0xffff, /* dst_mask */
1670 FALSE), /* pcrel_offset */
1672 /* Like TPREL16, but for insns with a DS field. */
1673 HOWTO (R_PPC64_TPREL16_DS,
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_TPREL16_DS", /* name */
1682 FALSE, /* partial_inplace */
1684 0xfffc, /* dst_mask */
1685 FALSE), /* pcrel_offset */
1687 /* Like TPREL16_DS, but no overflow. */
1688 HOWTO (R_PPC64_TPREL16_LO_DS,
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_TPREL16_LO_DS", /* name */
1697 FALSE, /* partial_inplace */
1699 0xfffc, /* dst_mask */
1700 FALSE), /* pcrel_offset */
1702 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1703 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1704 to the first entry relative to the TOC base (r2). */
1705 HOWTO (R_PPC64_GOT_TLSGD16,
1707 1, /* size (0 = byte, 1 = short, 2 = long) */
1709 FALSE, /* pc_relative */
1711 complain_overflow_signed, /* complain_on_overflow */
1712 ppc64_elf_unhandled_reloc, /* special_function */
1713 "R_PPC64_GOT_TLSGD16", /* name */
1714 FALSE, /* partial_inplace */
1716 0xffff, /* dst_mask */
1717 FALSE), /* pcrel_offset */
1719 /* Like GOT_TLSGD16, but no overflow. */
1720 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1722 1, /* size (0 = byte, 1 = short, 2 = long) */
1724 FALSE, /* pc_relative */
1726 complain_overflow_dont, /* complain_on_overflow */
1727 ppc64_elf_unhandled_reloc, /* special_function */
1728 "R_PPC64_GOT_TLSGD16_LO", /* name */
1729 FALSE, /* partial_inplace */
1731 0xffff, /* dst_mask */
1732 FALSE), /* pcrel_offset */
1734 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1735 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1736 16, /* rightshift */
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_TLSGD16_HI", /* name */
1744 FALSE, /* partial_inplace */
1746 0xffff, /* dst_mask */
1747 FALSE), /* pcrel_offset */
1749 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1750 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1751 16, /* rightshift */
1752 1, /* size (0 = byte, 1 = short, 2 = long) */
1754 FALSE, /* pc_relative */
1756 complain_overflow_signed, /* complain_on_overflow */
1757 ppc64_elf_unhandled_reloc, /* special_function */
1758 "R_PPC64_GOT_TLSGD16_HA", /* name */
1759 FALSE, /* partial_inplace */
1761 0xffff, /* dst_mask */
1762 FALSE), /* pcrel_offset */
1764 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1765 with values (sym+add)@dtpmod and zero, and computes the offset to the
1766 first entry relative to the TOC base (r2). */
1767 HOWTO (R_PPC64_GOT_TLSLD16,
1769 1, /* size (0 = byte, 1 = short, 2 = long) */
1771 FALSE, /* pc_relative */
1773 complain_overflow_signed, /* complain_on_overflow */
1774 ppc64_elf_unhandled_reloc, /* special_function */
1775 "R_PPC64_GOT_TLSLD16", /* name */
1776 FALSE, /* partial_inplace */
1778 0xffff, /* dst_mask */
1779 FALSE), /* pcrel_offset */
1781 /* Like GOT_TLSLD16, but no overflow. */
1782 HOWTO (R_PPC64_GOT_TLSLD16_LO,
1784 1, /* size (0 = byte, 1 = short, 2 = long) */
1786 FALSE, /* pc_relative */
1788 complain_overflow_dont, /* complain_on_overflow */
1789 ppc64_elf_unhandled_reloc, /* special_function */
1790 "R_PPC64_GOT_TLSLD16_LO", /* name */
1791 FALSE, /* partial_inplace */
1793 0xffff, /* dst_mask */
1794 FALSE), /* pcrel_offset */
1796 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1797 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1798 16, /* rightshift */
1799 1, /* size (0 = byte, 1 = short, 2 = long) */
1801 FALSE, /* pc_relative */
1803 complain_overflow_signed, /* complain_on_overflow */
1804 ppc64_elf_unhandled_reloc, /* special_function */
1805 "R_PPC64_GOT_TLSLD16_HI", /* name */
1806 FALSE, /* partial_inplace */
1808 0xffff, /* dst_mask */
1809 FALSE), /* pcrel_offset */
1811 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1812 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1813 16, /* rightshift */
1814 1, /* size (0 = byte, 1 = short, 2 = long) */
1816 FALSE, /* pc_relative */
1818 complain_overflow_signed, /* complain_on_overflow */
1819 ppc64_elf_unhandled_reloc, /* special_function */
1820 "R_PPC64_GOT_TLSLD16_HA", /* name */
1821 FALSE, /* partial_inplace */
1823 0xffff, /* dst_mask */
1824 FALSE), /* pcrel_offset */
1826 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1827 the offset to the entry relative to the TOC base (r2). */
1828 HOWTO (R_PPC64_GOT_DTPREL16_DS,
1830 1, /* size (0 = byte, 1 = short, 2 = long) */
1832 FALSE, /* pc_relative */
1834 complain_overflow_signed, /* complain_on_overflow */
1835 ppc64_elf_unhandled_reloc, /* special_function */
1836 "R_PPC64_GOT_DTPREL16_DS", /* name */
1837 FALSE, /* partial_inplace */
1839 0xfffc, /* dst_mask */
1840 FALSE), /* pcrel_offset */
1842 /* Like GOT_DTPREL16_DS, but no overflow. */
1843 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
1845 1, /* size (0 = byte, 1 = short, 2 = long) */
1847 FALSE, /* pc_relative */
1849 complain_overflow_dont, /* complain_on_overflow */
1850 ppc64_elf_unhandled_reloc, /* special_function */
1851 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1852 FALSE, /* partial_inplace */
1854 0xfffc, /* dst_mask */
1855 FALSE), /* pcrel_offset */
1857 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1858 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1859 16, /* rightshift */
1860 1, /* size (0 = byte, 1 = short, 2 = long) */
1862 FALSE, /* pc_relative */
1864 complain_overflow_signed, /* complain_on_overflow */
1865 ppc64_elf_unhandled_reloc, /* special_function */
1866 "R_PPC64_GOT_DTPREL16_HI", /* name */
1867 FALSE, /* partial_inplace */
1869 0xffff, /* dst_mask */
1870 FALSE), /* pcrel_offset */
1872 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1873 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1874 16, /* rightshift */
1875 1, /* size (0 = byte, 1 = short, 2 = long) */
1877 FALSE, /* pc_relative */
1879 complain_overflow_signed, /* complain_on_overflow */
1880 ppc64_elf_unhandled_reloc, /* special_function */
1881 "R_PPC64_GOT_DTPREL16_HA", /* name */
1882 FALSE, /* partial_inplace */
1884 0xffff, /* dst_mask */
1885 FALSE), /* pcrel_offset */
1887 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1888 offset to the entry relative to the TOC base (r2). */
1889 HOWTO (R_PPC64_GOT_TPREL16_DS,
1891 1, /* size (0 = byte, 1 = short, 2 = long) */
1893 FALSE, /* pc_relative */
1895 complain_overflow_signed, /* complain_on_overflow */
1896 ppc64_elf_unhandled_reloc, /* special_function */
1897 "R_PPC64_GOT_TPREL16_DS", /* name */
1898 FALSE, /* partial_inplace */
1900 0xfffc, /* dst_mask */
1901 FALSE), /* pcrel_offset */
1903 /* Like GOT_TPREL16_DS, but no overflow. */
1904 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1906 1, /* size (0 = byte, 1 = short, 2 = long) */
1908 FALSE, /* pc_relative */
1910 complain_overflow_dont, /* complain_on_overflow */
1911 ppc64_elf_unhandled_reloc, /* special_function */
1912 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1913 FALSE, /* partial_inplace */
1915 0xfffc, /* dst_mask */
1916 FALSE), /* pcrel_offset */
1918 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1919 HOWTO (R_PPC64_GOT_TPREL16_HI,
1920 16, /* rightshift */
1921 1, /* size (0 = byte, 1 = short, 2 = long) */
1923 FALSE, /* pc_relative */
1925 complain_overflow_signed, /* complain_on_overflow */
1926 ppc64_elf_unhandled_reloc, /* special_function */
1927 "R_PPC64_GOT_TPREL16_HI", /* name */
1928 FALSE, /* partial_inplace */
1930 0xffff, /* dst_mask */
1931 FALSE), /* pcrel_offset */
1933 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1934 HOWTO (R_PPC64_GOT_TPREL16_HA,
1935 16, /* rightshift */
1936 1, /* size (0 = byte, 1 = short, 2 = long) */
1938 FALSE, /* pc_relative */
1940 complain_overflow_signed, /* complain_on_overflow */
1941 ppc64_elf_unhandled_reloc, /* special_function */
1942 "R_PPC64_GOT_TPREL16_HA", /* name */
1943 FALSE, /* partial_inplace */
1945 0xffff, /* dst_mask */
1946 FALSE), /* pcrel_offset */
1948 HOWTO (R_PPC64_JMP_IREL, /* type */
1950 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1952 FALSE, /* pc_relative */
1954 complain_overflow_dont, /* complain_on_overflow */
1955 ppc64_elf_unhandled_reloc, /* special_function */
1956 "R_PPC64_JMP_IREL", /* name */
1957 FALSE, /* partial_inplace */
1960 FALSE), /* pcrel_offset */
1962 HOWTO (R_PPC64_IRELATIVE, /* type */
1964 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1966 FALSE, /* pc_relative */
1968 complain_overflow_dont, /* complain_on_overflow */
1969 bfd_elf_generic_reloc, /* special_function */
1970 "R_PPC64_IRELATIVE", /* name */
1971 FALSE, /* partial_inplace */
1973 ONES (64), /* dst_mask */
1974 FALSE), /* pcrel_offset */
1976 /* A 16 bit relative relocation. */
1977 HOWTO (R_PPC64_REL16, /* type */
1979 1, /* size (0 = byte, 1 = short, 2 = long) */
1981 TRUE, /* pc_relative */
1983 complain_overflow_signed, /* complain_on_overflow */
1984 bfd_elf_generic_reloc, /* special_function */
1985 "R_PPC64_REL16", /* name */
1986 FALSE, /* partial_inplace */
1988 0xffff, /* dst_mask */
1989 TRUE), /* pcrel_offset */
1991 /* A 16 bit relative relocation without overflow. */
1992 HOWTO (R_PPC64_REL16_LO, /* type */
1994 1, /* size (0 = byte, 1 = short, 2 = long) */
1996 TRUE, /* pc_relative */
1998 complain_overflow_dont,/* complain_on_overflow */
1999 bfd_elf_generic_reloc, /* special_function */
2000 "R_PPC64_REL16_LO", /* name */
2001 FALSE, /* partial_inplace */
2003 0xffff, /* dst_mask */
2004 TRUE), /* pcrel_offset */
2006 /* The high order 16 bits of a relative address. */
2007 HOWTO (R_PPC64_REL16_HI, /* type */
2008 16, /* rightshift */
2009 1, /* size (0 = byte, 1 = short, 2 = long) */
2011 TRUE, /* pc_relative */
2013 complain_overflow_signed, /* complain_on_overflow */
2014 bfd_elf_generic_reloc, /* special_function */
2015 "R_PPC64_REL16_HI", /* name */
2016 FALSE, /* partial_inplace */
2018 0xffff, /* dst_mask */
2019 TRUE), /* pcrel_offset */
2021 /* The high order 16 bits of a relative address, plus 1 if the contents of
2022 the low 16 bits, treated as a signed number, is negative. */
2023 HOWTO (R_PPC64_REL16_HA, /* type */
2024 16, /* rightshift */
2025 1, /* size (0 = byte, 1 = short, 2 = long) */
2027 TRUE, /* pc_relative */
2029 complain_overflow_signed, /* complain_on_overflow */
2030 ppc64_elf_ha_reloc, /* special_function */
2031 "R_PPC64_REL16_HA", /* name */
2032 FALSE, /* partial_inplace */
2034 0xffff, /* dst_mask */
2035 TRUE), /* pcrel_offset */
2037 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
2038 HOWTO (R_PPC64_REL16DX_HA, /* type */
2039 16, /* rightshift */
2040 2, /* size (0 = byte, 1 = short, 2 = long) */
2042 TRUE, /* pc_relative */
2044 complain_overflow_signed, /* complain_on_overflow */
2045 ppc64_elf_ha_reloc, /* special_function */
2046 "R_PPC64_REL16DX_HA", /* name */
2047 FALSE, /* partial_inplace */
2049 0x1fffc1, /* dst_mask */
2050 TRUE), /* pcrel_offset */
2052 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
2053 HOWTO (R_PPC64_16DX_HA, /* type */
2054 16, /* rightshift */
2055 2, /* size (0 = byte, 1 = short, 2 = long) */
2057 FALSE, /* pc_relative */
2059 complain_overflow_signed, /* complain_on_overflow */
2060 ppc64_elf_ha_reloc, /* special_function */
2061 "R_PPC64_16DX_HA", /* name */
2062 FALSE, /* partial_inplace */
2064 0x1fffc1, /* dst_mask */
2065 FALSE), /* pcrel_offset */
2067 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2068 HOWTO (R_PPC64_ADDR16_HIGH, /* type */
2069 16, /* rightshift */
2070 1, /* size (0 = byte, 1 = short, 2 = long) */
2072 FALSE, /* pc_relative */
2074 complain_overflow_dont, /* complain_on_overflow */
2075 bfd_elf_generic_reloc, /* special_function */
2076 "R_PPC64_ADDR16_HIGH", /* name */
2077 FALSE, /* partial_inplace */
2079 0xffff, /* dst_mask */
2080 FALSE), /* pcrel_offset */
2082 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2083 HOWTO (R_PPC64_ADDR16_HIGHA, /* type */
2084 16, /* rightshift */
2085 1, /* size (0 = byte, 1 = short, 2 = long) */
2087 FALSE, /* pc_relative */
2089 complain_overflow_dont, /* complain_on_overflow */
2090 ppc64_elf_ha_reloc, /* special_function */
2091 "R_PPC64_ADDR16_HIGHA", /* name */
2092 FALSE, /* partial_inplace */
2094 0xffff, /* dst_mask */
2095 FALSE), /* pcrel_offset */
2097 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2098 HOWTO (R_PPC64_DTPREL16_HIGH,
2099 16, /* rightshift */
2100 1, /* size (0 = byte, 1 = short, 2 = long) */
2102 FALSE, /* pc_relative */
2104 complain_overflow_dont, /* complain_on_overflow */
2105 ppc64_elf_unhandled_reloc, /* special_function */
2106 "R_PPC64_DTPREL16_HIGH", /* name */
2107 FALSE, /* partial_inplace */
2109 0xffff, /* dst_mask */
2110 FALSE), /* pcrel_offset */
2112 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2113 HOWTO (R_PPC64_DTPREL16_HIGHA,
2114 16, /* rightshift */
2115 1, /* size (0 = byte, 1 = short, 2 = long) */
2117 FALSE, /* pc_relative */
2119 complain_overflow_dont, /* complain_on_overflow */
2120 ppc64_elf_unhandled_reloc, /* special_function */
2121 "R_PPC64_DTPREL16_HIGHA", /* name */
2122 FALSE, /* partial_inplace */
2124 0xffff, /* dst_mask */
2125 FALSE), /* pcrel_offset */
2127 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2128 HOWTO (R_PPC64_TPREL16_HIGH,
2129 16, /* rightshift */
2130 1, /* size (0 = byte, 1 = short, 2 = long) */
2132 FALSE, /* pc_relative */
2134 complain_overflow_dont, /* complain_on_overflow */
2135 ppc64_elf_unhandled_reloc, /* special_function */
2136 "R_PPC64_TPREL16_HIGH", /* name */
2137 FALSE, /* partial_inplace */
2139 0xffff, /* dst_mask */
2140 FALSE), /* pcrel_offset */
2142 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2143 HOWTO (R_PPC64_TPREL16_HIGHA,
2144 16, /* rightshift */
2145 1, /* size (0 = byte, 1 = short, 2 = long) */
2147 FALSE, /* pc_relative */
2149 complain_overflow_dont, /* complain_on_overflow */
2150 ppc64_elf_unhandled_reloc, /* special_function */
2151 "R_PPC64_TPREL16_HIGHA", /* name */
2152 FALSE, /* partial_inplace */
2154 0xffff, /* dst_mask */
2155 FALSE), /* pcrel_offset */
2157 /* Marker reloc on ELFv2 large-model function entry. */
2158 HOWTO (R_PPC64_ENTRY,
2160 2, /* size (0 = byte, 1 = short, 2 = long) */
2162 FALSE, /* pc_relative */
2164 complain_overflow_dont, /* complain_on_overflow */
2165 bfd_elf_generic_reloc, /* special_function */
2166 "R_PPC64_ENTRY", /* name */
2167 FALSE, /* partial_inplace */
2170 FALSE), /* pcrel_offset */
2172 /* Like ADDR64, but use local entry point of function. */
2173 HOWTO (R_PPC64_ADDR64_LOCAL, /* type */
2175 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2177 FALSE, /* pc_relative */
2179 complain_overflow_dont, /* complain_on_overflow */
2180 bfd_elf_generic_reloc, /* special_function */
2181 "R_PPC64_ADDR64_LOCAL", /* name */
2182 FALSE, /* partial_inplace */
2184 ONES (64), /* dst_mask */
2185 FALSE), /* pcrel_offset */
2187 /* GNU extension to record C++ vtable hierarchy. */
2188 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
2190 0, /* size (0 = byte, 1 = short, 2 = long) */
2192 FALSE, /* pc_relative */
2194 complain_overflow_dont, /* complain_on_overflow */
2195 NULL, /* special_function */
2196 "R_PPC64_GNU_VTINHERIT", /* name */
2197 FALSE, /* partial_inplace */
2200 FALSE), /* pcrel_offset */
2202 /* GNU extension to record C++ vtable member usage. */
2203 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
2205 0, /* size (0 = byte, 1 = short, 2 = long) */
2207 FALSE, /* pc_relative */
2209 complain_overflow_dont, /* complain_on_overflow */
2210 NULL, /* special_function */
2211 "R_PPC64_GNU_VTENTRY", /* name */
2212 FALSE, /* partial_inplace */
2215 FALSE), /* pcrel_offset */
2219 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2223 ppc_howto_init (void)
2225 unsigned int i, type;
2227 for (i = 0; i < ARRAY_SIZE (ppc64_elf_howto_raw); i++)
2229 type = ppc64_elf_howto_raw[i].type;
2230 BFD_ASSERT (type < ARRAY_SIZE (ppc64_elf_howto_table));
2231 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
2235 static reloc_howto_type *
2236 ppc64_elf_reloc_type_lookup (bfd *abfd,
2237 bfd_reloc_code_real_type code)
2239 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
2241 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2242 /* Initialize howto table if needed. */
2248 /* xgettext:c-format */
2249 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, (int) code);
2250 bfd_set_error (bfd_error_bad_value);
2253 case BFD_RELOC_NONE: r = R_PPC64_NONE;
2255 case BFD_RELOC_32: r = R_PPC64_ADDR32;
2257 case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
2259 case BFD_RELOC_16: r = R_PPC64_ADDR16;
2261 case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
2263 case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
2265 case BFD_RELOC_PPC64_ADDR16_HIGH: r = R_PPC64_ADDR16_HIGH;
2267 case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
2269 case BFD_RELOC_PPC64_ADDR16_HIGHA: r = R_PPC64_ADDR16_HIGHA;
2271 case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
2273 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
2275 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
2277 case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
2279 case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
2281 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
2283 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
2285 case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
2287 case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
2289 case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
2291 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
2293 case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
2295 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
2297 case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
2299 case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
2301 case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
2303 case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
2305 case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
2307 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
2309 case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
2311 case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
2313 case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
2315 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
2317 case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
2319 case BFD_RELOC_64: r = R_PPC64_ADDR64;
2321 case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
2323 case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
2325 case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
2327 case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
2329 case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
2331 case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
2333 case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
2335 case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
2337 case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
2339 case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
2341 case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
2343 case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
2345 case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
2347 case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
2349 case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
2351 case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
2353 case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
2355 case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
2357 case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
2359 case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
2361 case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
2363 case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
2365 case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
2367 case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
2369 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
2371 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
2373 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
2375 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
2377 case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD;
2379 case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD;
2381 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
2383 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
2385 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
2387 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
2389 case BFD_RELOC_PPC64_TPREL16_HIGH: r = R_PPC64_TPREL16_HIGH;
2391 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
2393 case BFD_RELOC_PPC64_TPREL16_HIGHA: r = R_PPC64_TPREL16_HIGHA;
2395 case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
2397 case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
2399 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
2401 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
2403 case BFD_RELOC_PPC64_DTPREL16_HIGH: r = R_PPC64_DTPREL16_HIGH;
2405 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
2407 case BFD_RELOC_PPC64_DTPREL16_HIGHA: r = R_PPC64_DTPREL16_HIGHA;
2409 case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
2411 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
2413 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
2415 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
2417 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
2419 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
2421 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
2423 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
2425 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
2427 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
2429 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
2431 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
2433 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
2435 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
2437 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
2439 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
2441 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
2443 case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
2445 case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
2447 case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
2449 case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
2451 case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
2453 case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
2455 case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
2457 case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
2459 case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
2461 case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
2463 case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
2465 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
2467 case BFD_RELOC_16_PCREL: r = R_PPC64_REL16;
2469 case BFD_RELOC_LO16_PCREL: r = R_PPC64_REL16_LO;
2471 case BFD_RELOC_HI16_PCREL: r = R_PPC64_REL16_HI;
2473 case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA;
2475 case BFD_RELOC_PPC_16DX_HA: r = R_PPC64_16DX_HA;
2477 case BFD_RELOC_PPC_REL16DX_HA: r = R_PPC64_REL16DX_HA;
2479 case BFD_RELOC_PPC64_ENTRY: r = R_PPC64_ENTRY;
2481 case BFD_RELOC_PPC64_ADDR64_LOCAL: r = R_PPC64_ADDR64_LOCAL;
2483 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
2485 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
2489 return ppc64_elf_howto_table[r];
2492 static reloc_howto_type *
2493 ppc64_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2498 for (i = 0; i < ARRAY_SIZE (ppc64_elf_howto_raw); i++)
2499 if (ppc64_elf_howto_raw[i].name != NULL
2500 && strcasecmp (ppc64_elf_howto_raw[i].name, r_name) == 0)
2501 return &ppc64_elf_howto_raw[i];
2507 /* Set the howto pointer for a PowerPC ELF reloc. */
2510 ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr,
2511 Elf_Internal_Rela *dst)
2515 /* Initialize howto table if needed. */
2516 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2519 type = ELF64_R_TYPE (dst->r_info);
2520 if (type >= ARRAY_SIZE (ppc64_elf_howto_table))
2522 /* xgettext:c-format */
2523 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2525 bfd_set_error (bfd_error_bad_value);
2528 cache_ptr->howto = ppc64_elf_howto_table[type];
2529 if (cache_ptr->howto == NULL || cache_ptr->howto->name == NULL)
2531 /* xgettext:c-format */
2532 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2534 bfd_set_error (bfd_error_bad_value);
2541 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2543 static bfd_reloc_status_type
2544 ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2545 void *data, asection *input_section,
2546 bfd *output_bfd, char **error_message)
2548 enum elf_ppc64_reloc_type r_type;
2550 bfd_size_type octets;
2553 /* If this is a relocatable link (output_bfd test tells us), just
2554 call the generic function. Any adjustment will be done at final
2556 if (output_bfd != NULL)
2557 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2558 input_section, output_bfd, error_message);
2560 /* Adjust the addend for sign extension of the low 16 bits.
2561 We won't actually be using the low 16 bits, so trashing them
2563 reloc_entry->addend += 0x8000;
2564 r_type = reloc_entry->howto->type;
2565 if (r_type != R_PPC64_REL16DX_HA)
2566 return bfd_reloc_continue;
2569 if (!bfd_is_com_section (symbol->section))
2570 value = symbol->value;
2571 value += (reloc_entry->addend
2572 + symbol->section->output_offset
2573 + symbol->section->output_section->vma);
2574 value -= (reloc_entry->address
2575 + input_section->output_offset
2576 + input_section->output_section->vma);
2577 value = (bfd_signed_vma) value >> 16;
2579 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2580 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2582 insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
2583 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2584 if (value + 0x8000 > 0xffff)
2585 return bfd_reloc_overflow;
2586 return bfd_reloc_ok;
2589 static bfd_reloc_status_type
2590 ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2591 void *data, asection *input_section,
2592 bfd *output_bfd, char **error_message)
2594 if (output_bfd != NULL)
2595 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2596 input_section, output_bfd, error_message);
2598 if (strcmp (symbol->section->name, ".opd") == 0
2599 && (symbol->section->owner->flags & DYNAMIC) == 0)
2601 bfd_vma dest = opd_entry_value (symbol->section,
2602 symbol->value + reloc_entry->addend,
2604 if (dest != (bfd_vma) -1)
2605 reloc_entry->addend = dest - (symbol->value
2606 + symbol->section->output_section->vma
2607 + symbol->section->output_offset);
2611 elf_symbol_type *elfsym = (elf_symbol_type *) symbol;
2613 if (symbol->section->owner != abfd
2614 && symbol->section->owner != NULL
2615 && abiversion (symbol->section->owner) >= 2)
2619 for (i = 0; i < symbol->section->owner->symcount; ++i)
2621 asymbol *symdef = symbol->section->owner->outsymbols[i];
2623 if (strcmp (symdef->name, symbol->name) == 0)
2625 elfsym = (elf_symbol_type *) symdef;
2631 += PPC64_LOCAL_ENTRY_OFFSET (elfsym->internal_elf_sym.st_other);
2633 return bfd_reloc_continue;
2636 static bfd_reloc_status_type
2637 ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2638 void *data, asection *input_section,
2639 bfd *output_bfd, char **error_message)
2642 enum elf_ppc64_reloc_type r_type;
2643 bfd_size_type octets;
2644 /* Assume 'at' branch hints. */
2645 bfd_boolean is_isa_v2 = TRUE;
2647 /* If this is a relocatable link (output_bfd test tells us), just
2648 call the generic function. Any adjustment will be done at final
2650 if (output_bfd != NULL)
2651 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2652 input_section, output_bfd, error_message);
2654 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2655 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2656 insn &= ~(0x01 << 21);
2657 r_type = reloc_entry->howto->type;
2658 if (r_type == R_PPC64_ADDR14_BRTAKEN
2659 || r_type == R_PPC64_REL14_BRTAKEN)
2660 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2664 /* Set 'a' bit. This is 0b00010 in BO field for branch
2665 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2666 for branch on CTR insns (BO == 1a00t or 1a01t). */
2667 if ((insn & (0x14 << 21)) == (0x04 << 21))
2669 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2679 if (!bfd_is_com_section (symbol->section))
2680 target = symbol->value;
2681 target += symbol->section->output_section->vma;
2682 target += symbol->section->output_offset;
2683 target += reloc_entry->addend;
2685 from = (reloc_entry->address
2686 + input_section->output_offset
2687 + input_section->output_section->vma);
2689 /* Invert 'y' bit if not the default. */
2690 if ((bfd_signed_vma) (target - from) < 0)
2693 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2695 return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data,
2696 input_section, output_bfd, error_message);
2699 static bfd_reloc_status_type
2700 ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2701 void *data, asection *input_section,
2702 bfd *output_bfd, char **error_message)
2704 /* If this is a relocatable link (output_bfd test tells us), just
2705 call the generic function. Any adjustment will be done at final
2707 if (output_bfd != NULL)
2708 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2709 input_section, output_bfd, error_message);
2711 /* Subtract the symbol section base address. */
2712 reloc_entry->addend -= symbol->section->output_section->vma;
2713 return bfd_reloc_continue;
2716 static bfd_reloc_status_type
2717 ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2718 void *data, asection *input_section,
2719 bfd *output_bfd, char **error_message)
2721 /* If this is a relocatable link (output_bfd test tells us), just
2722 call the generic function. Any adjustment will be done at final
2724 if (output_bfd != NULL)
2725 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2726 input_section, output_bfd, error_message);
2728 /* Subtract the symbol section base address. */
2729 reloc_entry->addend -= symbol->section->output_section->vma;
2731 /* Adjust the addend for sign extension of the low 16 bits. */
2732 reloc_entry->addend += 0x8000;
2733 return bfd_reloc_continue;
2736 static bfd_reloc_status_type
2737 ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2738 void *data, asection *input_section,
2739 bfd *output_bfd, char **error_message)
2743 /* If this is a relocatable link (output_bfd test tells us), just
2744 call the generic function. Any adjustment will be done at final
2746 if (output_bfd != NULL)
2747 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2748 input_section, output_bfd, error_message);
2750 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2752 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2754 /* Subtract the TOC base address. */
2755 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2756 return bfd_reloc_continue;
2759 static bfd_reloc_status_type
2760 ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2761 void *data, asection *input_section,
2762 bfd *output_bfd, char **error_message)
2766 /* If this is a relocatable link (output_bfd test tells us), just
2767 call the generic function. Any adjustment will be done at final
2769 if (output_bfd != NULL)
2770 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2771 input_section, output_bfd, error_message);
2773 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2775 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2777 /* Subtract the TOC base address. */
2778 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2780 /* Adjust the addend for sign extension of the low 16 bits. */
2781 reloc_entry->addend += 0x8000;
2782 return bfd_reloc_continue;
2785 static bfd_reloc_status_type
2786 ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2787 void *data, asection *input_section,
2788 bfd *output_bfd, char **error_message)
2791 bfd_size_type octets;
2793 /* If this is a relocatable link (output_bfd test tells us), just
2794 call the generic function. Any adjustment will be done at final
2796 if (output_bfd != NULL)
2797 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2798 input_section, output_bfd, error_message);
2800 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2802 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2804 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2805 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2806 return bfd_reloc_ok;
2809 static bfd_reloc_status_type
2810 ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2811 void *data, asection *input_section,
2812 bfd *output_bfd, char **error_message)
2814 /* If this is a relocatable link (output_bfd test tells us), just
2815 call the generic function. Any adjustment will be done at final
2817 if (output_bfd != NULL)
2818 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2819 input_section, output_bfd, error_message);
2821 if (error_message != NULL)
2823 static char buf[60];
2824 sprintf (buf, "generic linker can't handle %s",
2825 reloc_entry->howto->name);
2826 *error_message = buf;
2828 return bfd_reloc_dangerous;
2831 /* Track GOT entries needed for a given symbol. We might need more
2832 than one got entry per symbol. */
2835 struct got_entry *next;
2837 /* The symbol addend that we'll be placing in the GOT. */
2840 /* Unlike other ELF targets, we use separate GOT entries for the same
2841 symbol referenced from different input files. This is to support
2842 automatic multiple TOC/GOT sections, where the TOC base can vary
2843 from one input file to another. After partitioning into TOC groups
2844 we merge entries within the group.
2846 Point to the BFD owning this GOT entry. */
2849 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2850 TLS_TPREL or TLS_DTPREL for tls entries. */
2851 unsigned char tls_type;
2853 /* Non-zero if got.ent points to real entry. */
2854 unsigned char is_indirect;
2856 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2859 bfd_signed_vma refcount;
2861 struct got_entry *ent;
2865 /* The same for PLT. */
2868 struct plt_entry *next;
2874 bfd_signed_vma refcount;
2879 struct ppc64_elf_obj_tdata
2881 struct elf_obj_tdata elf;
2883 /* Shortcuts to dynamic linker sections. */
2887 /* Used during garbage collection. We attach global symbols defined
2888 on removed .opd entries to this section so that the sym is removed. */
2889 asection *deleted_section;
2891 /* TLS local dynamic got entry handling. Support for multiple GOT
2892 sections means we potentially need one of these for each input bfd. */
2893 struct got_entry tlsld_got;
2896 /* A copy of relocs before they are modified for --emit-relocs. */
2897 Elf_Internal_Rela *relocs;
2899 /* Section contents. */
2903 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2904 the reloc to be in the range -32768 to 32767. */
2905 unsigned int has_small_toc_reloc : 1;
2907 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2908 instruction not one we handle. */
2909 unsigned int unexpected_toc_insn : 1;
2912 #define ppc64_elf_tdata(bfd) \
2913 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2915 #define ppc64_tlsld_got(bfd) \
2916 (&ppc64_elf_tdata (bfd)->tlsld_got)
2918 #define is_ppc64_elf(bfd) \
2919 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2920 && elf_object_id (bfd) == PPC64_ELF_DATA)
2922 /* Override the generic function because we store some extras. */
2925 ppc64_elf_mkobject (bfd *abfd)
2927 return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata),
2931 /* Fix bad default arch selected for a 64 bit input bfd when the
2932 default is 32 bit. Also select arch based on apuinfo. */
2935 ppc64_elf_object_p (bfd *abfd)
2937 if (!abfd->arch_info->the_default)
2940 if (abfd->arch_info->bits_per_word == 32)
2942 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2944 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2946 /* Relies on arch after 32 bit default being 64 bit default. */
2947 abfd->arch_info = abfd->arch_info->next;
2948 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2951 return _bfd_elf_ppc_set_arch (abfd);
2954 /* Support for core dump NOTE sections. */
2957 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2959 size_t offset, size;
2961 if (note->descsz != 504)
2965 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2968 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
2974 /* Make a ".reg/999" section. */
2975 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2976 size, note->descpos + offset);
2980 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2982 if (note->descsz != 136)
2985 elf_tdata (abfd)->core->pid
2986 = bfd_get_32 (abfd, note->descdata + 24);
2987 elf_tdata (abfd)->core->program
2988 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2989 elf_tdata (abfd)->core->command
2990 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2996 ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
3009 va_start (ap, note_type);
3010 memset (data, 0, sizeof (data));
3011 strncpy (data + 40, va_arg (ap, const char *), 16);
3012 strncpy (data + 56, va_arg (ap, const char *), 80);
3014 return elfcore_write_note (abfd, buf, bufsiz,
3015 "CORE", note_type, data, sizeof (data));
3026 va_start (ap, note_type);
3027 memset (data, 0, 112);
3028 pid = va_arg (ap, long);
3029 bfd_put_32 (abfd, pid, data + 32);
3030 cursig = va_arg (ap, int);
3031 bfd_put_16 (abfd, cursig, data + 12);
3032 greg = va_arg (ap, const void *);
3033 memcpy (data + 112, greg, 384);
3034 memset (data + 496, 0, 8);
3036 return elfcore_write_note (abfd, buf, bufsiz,
3037 "CORE", note_type, data, sizeof (data));
3042 /* Add extra PPC sections. */
3044 static const struct bfd_elf_special_section ppc64_elf_special_sections[]=
3046 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 },
3047 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
3048 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3049 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3050 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3051 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
3052 { NULL, 0, 0, 0, 0 }
3055 enum _ppc64_sec_type {
3061 struct _ppc64_elf_section_data
3063 struct bfd_elf_section_data elf;
3067 /* An array with one entry for each opd function descriptor,
3068 and some spares since opd entries may be either 16 or 24 bytes. */
3069 #define OPD_NDX(OFF) ((OFF) >> 4)
3070 struct _opd_sec_data
3072 /* Points to the function code section for local opd entries. */
3073 asection **func_sec;
3075 /* After editing .opd, adjust references to opd local syms. */
3079 /* An array for toc sections, indexed by offset/8. */
3080 struct _toc_sec_data
3082 /* Specifies the relocation symbol index used at a given toc offset. */
3085 /* And the relocation addend. */
3090 enum _ppc64_sec_type sec_type:2;
3092 /* Flag set when small branches are detected. Used to
3093 select suitable defaults for the stub group size. */
3094 unsigned int has_14bit_branch:1;
3097 #define ppc64_elf_section_data(sec) \
3098 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
3101 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
3103 if (!sec->used_by_bfd)
3105 struct _ppc64_elf_section_data *sdata;
3106 bfd_size_type amt = sizeof (*sdata);
3108 sdata = bfd_zalloc (abfd, amt);
3111 sec->used_by_bfd = sdata;
3114 return _bfd_elf_new_section_hook (abfd, sec);
3117 static struct _opd_sec_data *
3118 get_opd_info (asection * sec)
3121 && ppc64_elf_section_data (sec) != NULL
3122 && ppc64_elf_section_data (sec)->sec_type == sec_opd)
3123 return &ppc64_elf_section_data (sec)->u.opd;
3127 /* Parameters for the qsort hook. */
3128 static bfd_boolean synthetic_relocatable;
3129 static asection *synthetic_opd;
3131 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3134 compare_symbols (const void *ap, const void *bp)
3136 const asymbol *a = * (const asymbol **) ap;
3137 const asymbol *b = * (const asymbol **) bp;
3139 /* Section symbols first. */
3140 if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM))
3142 if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM))
3145 /* then .opd symbols. */
3146 if (synthetic_opd != NULL)
3148 if (strcmp (a->section->name, ".opd") == 0
3149 && strcmp (b->section->name, ".opd") != 0)
3151 if (strcmp (a->section->name, ".opd") != 0
3152 && strcmp (b->section->name, ".opd") == 0)
3156 /* then other code symbols. */
3157 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3158 == (SEC_CODE | SEC_ALLOC)
3159 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3160 != (SEC_CODE | SEC_ALLOC))
3163 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3164 != (SEC_CODE | SEC_ALLOC)
3165 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3166 == (SEC_CODE | SEC_ALLOC))
3169 if (synthetic_relocatable)
3171 if (a->section->id < b->section->id)
3174 if (a->section->id > b->section->id)
3178 if (a->value + a->section->vma < b->value + b->section->vma)
3181 if (a->value + a->section->vma > b->value + b->section->vma)
3184 /* For syms with the same value, prefer strong dynamic global function
3185 syms over other syms. */
3186 if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
3189 if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
3192 if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
3195 if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
3198 if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
3201 if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
3204 if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
3207 if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
3213 /* Search SYMS for a symbol of the given VALUE. */
3216 sym_exists_at (asymbol **syms, long lo, long hi, unsigned int id, bfd_vma value)
3220 if (id == (unsigned) -1)
3224 mid = (lo + hi) >> 1;
3225 if (syms[mid]->value + syms[mid]->section->vma < value)
3227 else if (syms[mid]->value + syms[mid]->section->vma > value)
3237 mid = (lo + hi) >> 1;
3238 if (syms[mid]->section->id < id)
3240 else if (syms[mid]->section->id > id)
3242 else if (syms[mid]->value < value)
3244 else if (syms[mid]->value > value)
3254 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
3256 bfd_vma vma = *(bfd_vma *) ptr;
3257 return ((section->flags & SEC_ALLOC) != 0
3258 && section->vma <= vma
3259 && vma < section->vma + section->size);
3262 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3263 entry syms. Also generate @plt symbols for the glink branch table.
3264 Returns count of synthetic symbols in RET or -1 on error. */
3267 ppc64_elf_get_synthetic_symtab (bfd *abfd,
3268 long static_count, asymbol **static_syms,
3269 long dyn_count, asymbol **dyn_syms,
3275 size_t symcount, codesecsym, codesecsymend, secsymend, opdsymend;
3276 asection *opd = NULL;
3277 bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
3279 int abi = abiversion (abfd);
3285 opd = bfd_get_section_by_name (abfd, ".opd");
3286 if (opd == NULL && abi == 1)
3298 symcount = static_count;
3300 symcount += dyn_count;
3304 syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
3308 if (!relocatable && static_count != 0 && dyn_count != 0)
3310 /* Use both symbol tables. */
3311 memcpy (syms, static_syms, static_count * sizeof (*syms));
3312 memcpy (syms + static_count, dyn_syms,
3313 (dyn_count + 1) * sizeof (*syms));
3315 else if (!relocatable && static_count == 0)
3316 memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
3318 memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
3320 /* Trim uninteresting symbols. Interesting symbols are section,
3321 function, and notype symbols. */
3322 for (i = 0, j = 0; i < symcount; ++i)
3323 if ((syms[i]->flags & (BSF_FILE | BSF_OBJECT | BSF_THREAD_LOCAL
3324 | BSF_RELC | BSF_SRELC)) == 0)
3325 syms[j++] = syms[i];
3328 synthetic_relocatable = relocatable;
3329 synthetic_opd = opd;
3330 qsort (syms, symcount, sizeof (*syms), compare_symbols);
3332 if (!relocatable && symcount > 1)
3334 /* Trim duplicate syms, since we may have merged the normal and
3335 dynamic symbols. Actually, we only care about syms that have
3336 different values, so trim any with the same value. */
3337 for (i = 1, j = 1; i < symcount; ++i)
3338 if (syms[i - 1]->value + syms[i - 1]->section->vma
3339 != syms[i]->value + syms[i]->section->vma)
3340 syms[j++] = syms[i];
3345 /* Note that here and in compare_symbols we can't compare opd and
3346 sym->section directly. With separate debug info files, the
3347 symbols will be extracted from the debug file while abfd passed
3348 to this function is the real binary. */
3349 if (strcmp (syms[i]->section->name, ".opd") == 0)
3353 for (; i < symcount; ++i)
3354 if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC
3355 | SEC_THREAD_LOCAL))
3356 != (SEC_CODE | SEC_ALLOC))
3357 || (syms[i]->flags & BSF_SECTION_SYM) == 0)
3361 for (; i < symcount; ++i)
3362 if ((syms[i]->flags & BSF_SECTION_SYM) == 0)
3366 for (; i < symcount; ++i)
3367 if (strcmp (syms[i]->section->name, ".opd") != 0)
3371 for (; i < symcount; ++i)
3372 if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3373 != (SEC_CODE | SEC_ALLOC))
3381 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3386 if (opdsymend == secsymend)
3389 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3390 relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0;
3394 if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
3401 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3405 while (r < opd->relocation + relcount
3406 && r->address < syms[i]->value + opd->vma)
3409 if (r == opd->relocation + relcount)
3412 if (r->address != syms[i]->value + opd->vma)
3415 if (r->howto->type != R_PPC64_ADDR64)
3418 sym = *r->sym_ptr_ptr;
3419 if (!sym_exists_at (syms, opdsymend, symcount,
3420 sym->section->id, sym->value + r->addend))
3423 size += sizeof (asymbol);
3424 size += strlen (syms[i]->name) + 2;
3430 s = *ret = bfd_malloc (size);
3437 names = (char *) (s + count);
3439 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3443 while (r < opd->relocation + relcount
3444 && r->address < syms[i]->value + opd->vma)
3447 if (r == opd->relocation + relcount)
3450 if (r->address != syms[i]->value + opd->vma)
3453 if (r->howto->type != R_PPC64_ADDR64)
3456 sym = *r->sym_ptr_ptr;
3457 if (!sym_exists_at (syms, opdsymend, symcount,
3458 sym->section->id, sym->value + r->addend))
3463 s->flags |= BSF_SYNTHETIC;
3464 s->section = sym->section;
3465 s->value = sym->value + r->addend;
3468 len = strlen (syms[i]->name);
3469 memcpy (names, syms[i]->name, len + 1);
3471 /* Have udata.p point back to the original symbol this
3472 synthetic symbol was derived from. */
3473 s->udata.p = syms[i];
3480 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3481 bfd_byte *contents = NULL;
3483 size_t plt_count = 0;
3484 bfd_vma glink_vma = 0, resolv_vma = 0;
3485 asection *dynamic, *glink = NULL, *relplt = NULL;
3488 if (opd != NULL && !bfd_malloc_and_get_section (abfd, opd, &contents))
3490 free_contents_and_exit_err:
3492 free_contents_and_exit:
3499 for (i = secsymend; i < opdsymend; ++i)
3503 /* Ignore bogus symbols. */
3504 if (syms[i]->value > opd->size - 8)
3507 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3508 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3511 size += sizeof (asymbol);
3512 size += strlen (syms[i]->name) + 2;
3516 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3518 && (dynamic = bfd_get_section_by_name (abfd, ".dynamic")) != NULL)
3520 bfd_byte *dynbuf, *extdyn, *extdynend;
3522 void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
3524 if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
3525 goto free_contents_and_exit_err;
3527 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
3528 swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
3531 extdynend = extdyn + dynamic->size;
3532 for (; extdyn < extdynend; extdyn += extdynsize)
3534 Elf_Internal_Dyn dyn;
3535 (*swap_dyn_in) (abfd, extdyn, &dyn);
3537 if (dyn.d_tag == DT_NULL)
3540 if (dyn.d_tag == DT_PPC64_GLINK)
3542 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
3543 See comment in ppc64_elf_finish_dynamic_sections. */
3544 glink_vma = dyn.d_un.d_val + 8 * 4;
3545 /* The .glink section usually does not survive the final
3546 link; search for the section (usually .text) where the
3547 glink stubs now reside. */
3548 glink = bfd_sections_find_if (abfd, section_covers_vma,
3559 /* Determine __glink trampoline by reading the relative branch
3560 from the first glink stub. */
3562 unsigned int off = 0;
3564 while (bfd_get_section_contents (abfd, glink, buf,
3565 glink_vma + off - glink->vma, 4))
3567 unsigned int insn = bfd_get_32 (abfd, buf);
3569 if ((insn & ~0x3fffffc) == 0)
3571 resolv_vma = glink_vma + off + (insn ^ 0x2000000) - 0x2000000;
3580 size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
3582 relplt = bfd_get_section_by_name (abfd, ".rela.plt");
3585 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3586 if (! (*slurp_relocs) (abfd, relplt, dyn_syms, TRUE))
3587 goto free_contents_and_exit_err;
3589 plt_count = relplt->size / sizeof (Elf64_External_Rela);
3590 size += plt_count * sizeof (asymbol);
3592 p = relplt->relocation;
3593 for (i = 0; i < plt_count; i++, p++)
3595 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
3597 size += sizeof ("+0x") - 1 + 16;
3603 goto free_contents_and_exit;
3604 s = *ret = bfd_malloc (size);
3606 goto free_contents_and_exit_err;
3608 names = (char *) (s + count + plt_count + (resolv_vma != 0));
3610 for (i = secsymend; i < opdsymend; ++i)
3614 if (syms[i]->value > opd->size - 8)
3617 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3618 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3622 asection *sec = abfd->sections;
3629 size_t mid = (lo + hi) >> 1;
3630 if (syms[mid]->section->vma < ent)
3632 else if (syms[mid]->section->vma > ent)
3636 sec = syms[mid]->section;
3641 if (lo >= hi && lo > codesecsym)
3642 sec = syms[lo - 1]->section;
3644 for (; sec != NULL; sec = sec->next)
3648 /* SEC_LOAD may not be set if SEC is from a separate debug
3650 if ((sec->flags & SEC_ALLOC) == 0)
3652 if ((sec->flags & SEC_CODE) != 0)
3655 s->flags |= BSF_SYNTHETIC;
3656 s->value = ent - s->section->vma;
3659 len = strlen (syms[i]->name);
3660 memcpy (names, syms[i]->name, len + 1);
3662 /* Have udata.p point back to the original symbol this
3663 synthetic symbol was derived from. */
3664 s->udata.p = syms[i];
3670 if (glink != NULL && relplt != NULL)
3674 /* Add a symbol for the main glink trampoline. */
3675 memset (s, 0, sizeof *s);
3677 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
3679 s->value = resolv_vma - glink->vma;
3681 memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3682 names += sizeof ("__glink_PLTresolve");
3687 /* FIXME: It would be very much nicer to put sym@plt on the
3688 stub rather than on the glink branch table entry. The
3689 objdump disassembler would then use a sensible symbol
3690 name on plt calls. The difficulty in doing so is
3691 a) finding the stubs, and,
3692 b) matching stubs against plt entries, and,
3693 c) there can be multiple stubs for a given plt entry.
3695 Solving (a) could be done by code scanning, but older
3696 ppc64 binaries used different stubs to current code.
3697 (b) is the tricky one since you need to known the toc
3698 pointer for at least one function that uses a pic stub to
3699 be able to calculate the plt address referenced.
3700 (c) means gdb would need to set multiple breakpoints (or
3701 find the glink branch itself) when setting breakpoints
3702 for pending shared library loads. */
3703 p = relplt->relocation;
3704 for (i = 0; i < plt_count; i++, p++)
3708 *s = **p->sym_ptr_ptr;
3709 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3710 we are defining a symbol, ensure one of them is set. */
3711 if ((s->flags & BSF_LOCAL) == 0)
3712 s->flags |= BSF_GLOBAL;
3713 s->flags |= BSF_SYNTHETIC;
3715 s->value = glink_vma - glink->vma;
3718 len = strlen ((*p->sym_ptr_ptr)->name);
3719 memcpy (names, (*p->sym_ptr_ptr)->name, len);
3723 memcpy (names, "+0x", sizeof ("+0x") - 1);
3724 names += sizeof ("+0x") - 1;
3725 bfd_sprintf_vma (abfd, names, p->addend);
3726 names += strlen (names);
3728 memcpy (names, "@plt", sizeof ("@plt"));
3729 names += sizeof ("@plt");
3749 /* The following functions are specific to the ELF linker, while
3750 functions above are used generally. Those named ppc64_elf_* are
3751 called by the main ELF linker code. They appear in this file more
3752 or less in the order in which they are called. eg.
3753 ppc64_elf_check_relocs is called early in the link process,
3754 ppc64_elf_finish_dynamic_sections is one of the last functions
3757 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3758 functions have both a function code symbol and a function descriptor
3759 symbol. A call to foo in a relocatable object file looks like:
3766 The function definition in another object file might be:
3770 . .quad .TOC.@tocbase
3776 When the linker resolves the call during a static link, the branch
3777 unsurprisingly just goes to .foo and the .opd information is unused.
3778 If the function definition is in a shared library, things are a little
3779 different: The call goes via a plt call stub, the opd information gets
3780 copied to the plt, and the linker patches the nop.
3788 . std 2,40(1) # in practice, the call stub
3789 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3790 . addi 11,11,Lfoo@toc@l # this is the general idea
3798 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3800 The "reloc ()" notation is supposed to indicate that the linker emits
3801 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3804 What are the difficulties here? Well, firstly, the relocations
3805 examined by the linker in check_relocs are against the function code
3806 sym .foo, while the dynamic relocation in the plt is emitted against
3807 the function descriptor symbol, foo. Somewhere along the line, we need
3808 to carefully copy dynamic link information from one symbol to the other.
3809 Secondly, the generic part of the elf linker will make .foo a dynamic
3810 symbol as is normal for most other backends. We need foo dynamic
3811 instead, at least for an application final link. However, when
3812 creating a shared library containing foo, we need to have both symbols
3813 dynamic so that references to .foo are satisfied during the early
3814 stages of linking. Otherwise the linker might decide to pull in a
3815 definition from some other object, eg. a static library.
3817 Update: As of August 2004, we support a new convention. Function
3818 calls may use the function descriptor symbol, ie. "bl foo". This
3819 behaves exactly as "bl .foo". */
3821 /* Of those relocs that might be copied as dynamic relocs, this
3822 function selects those that must be copied when linking a shared
3823 library or PIE, even when the symbol is local. */
3826 must_be_dyn_reloc (struct bfd_link_info *info,
3827 enum elf_ppc64_reloc_type r_type)
3832 /* Only relative relocs can be resolved when the object load
3833 address isn't fixed. DTPREL64 is excluded because the
3834 dynamic linker needs to differentiate global dynamic from
3835 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
3843 case R_PPC64_TPREL16:
3844 case R_PPC64_TPREL16_LO:
3845 case R_PPC64_TPREL16_HI:
3846 case R_PPC64_TPREL16_HA:
3847 case R_PPC64_TPREL16_DS:
3848 case R_PPC64_TPREL16_LO_DS:
3849 case R_PPC64_TPREL16_HIGH:
3850 case R_PPC64_TPREL16_HIGHA:
3851 case R_PPC64_TPREL16_HIGHER:
3852 case R_PPC64_TPREL16_HIGHERA:
3853 case R_PPC64_TPREL16_HIGHEST:
3854 case R_PPC64_TPREL16_HIGHESTA:
3855 case R_PPC64_TPREL64:
3856 /* These relocations are relative but in a shared library the
3857 linker doesn't know the thread pointer base. */
3858 return bfd_link_dll (info);
3862 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3863 copying dynamic variables from a shared lib into an app's dynbss
3864 section, and instead use a dynamic relocation to point into the
3865 shared lib. With code that gcc generates, it's vital that this be
3866 enabled; In the PowerPC64 ABI, the address of a function is actually
3867 the address of a function descriptor, which resides in the .opd
3868 section. gcc uses the descriptor directly rather than going via the
3869 GOT as some other ABI's do, which means that initialized function
3870 pointers must reference the descriptor. Thus, a function pointer
3871 initialized to the address of a function in a shared library will
3872 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3873 redefines the function descriptor symbol to point to the copy. This
3874 presents a problem as a plt entry for that function is also
3875 initialized from the function descriptor symbol and the copy reloc
3876 may not be initialized first. */
3877 #define ELIMINATE_COPY_RELOCS 1
3879 /* Section name for stubs is the associated section name plus this
3881 #define STUB_SUFFIX ".stub"
3884 ppc_stub_long_branch:
3885 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3886 destination, but a 24 bit branch in a stub section will reach.
3889 ppc_stub_plt_branch:
3890 Similar to the above, but a 24 bit branch in the stub section won't
3891 reach its destination.
3892 . addis %r11,%r2,xxx@toc@ha
3893 . ld %r12,xxx@toc@l(%r11)
3898 Used to call a function in a shared library. If it so happens that
3899 the plt entry referenced crosses a 64k boundary, then an extra
3900 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3902 . addis %r11,%r2,xxx@toc@ha
3903 . ld %r12,xxx+0@toc@l(%r11)
3905 . ld %r2,xxx+8@toc@l(%r11)
3906 . ld %r11,xxx+16@toc@l(%r11)
3909 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3910 code to adjust the value and save r2 to support multiple toc sections.
3911 A ppc_stub_long_branch with an r2 offset looks like:
3913 . addis %r2,%r2,off@ha
3914 . addi %r2,%r2,off@l
3917 A ppc_stub_plt_branch with an r2 offset looks like:
3919 . addis %r11,%r2,xxx@toc@ha
3920 . ld %r12,xxx@toc@l(%r11)
3921 . addis %r2,%r2,off@ha
3922 . addi %r2,%r2,off@l
3926 In cases where the "addis" instruction would add zero, the "addis" is
3927 omitted and following instructions modified slightly in some cases.
3930 enum ppc_stub_type {
3932 ppc_stub_long_branch,
3933 ppc_stub_long_branch_r2off,
3934 ppc_stub_plt_branch,
3935 ppc_stub_plt_branch_r2off,
3937 ppc_stub_plt_call_r2save,
3938 ppc_stub_global_entry,
3942 /* Information on stub grouping. */
3945 /* The stub section. */
3947 /* This is the section to which stubs in the group will be attached. */
3950 struct map_stub *next;
3951 /* Whether to emit a copy of register save/restore functions in this
3954 /* The offset of the __tls_get_addr_opt plt stub bctrl in this group,
3955 or -1u if no such stub with bctrl exists. */
3956 unsigned int tls_get_addr_opt_bctrl;
3959 struct ppc_stub_hash_entry {
3961 /* Base hash table entry structure. */
3962 struct bfd_hash_entry root;
3964 enum ppc_stub_type stub_type;
3966 /* Group information. */
3967 struct map_stub *group;
3969 /* Offset within stub_sec of the beginning of this stub. */
3970 bfd_vma stub_offset;
3972 /* Given the symbol's value and its section we can determine its final
3973 value when building the stubs (so the stub knows where to jump. */
3974 bfd_vma target_value;
3975 asection *target_section;
3977 /* The symbol table entry, if any, that this was derived from. */
3978 struct ppc_link_hash_entry *h;
3979 struct plt_entry *plt_ent;
3982 unsigned char symtype;
3984 /* Symbol st_other. */
3985 unsigned char other;
3988 struct ppc_branch_hash_entry {
3990 /* Base hash table entry structure. */
3991 struct bfd_hash_entry root;
3993 /* Offset within branch lookup table. */
3994 unsigned int offset;
3996 /* Generation marker. */
4000 /* Used to track dynamic relocations for local symbols. */
4001 struct ppc_dyn_relocs
4003 struct ppc_dyn_relocs *next;
4005 /* The input section of the reloc. */
4008 /* Total number of relocs copied for the input section. */
4009 unsigned int count : 31;
4011 /* Whether this entry is for STT_GNU_IFUNC symbols. */
4012 unsigned int ifunc : 1;
4015 struct ppc_link_hash_entry
4017 struct elf_link_hash_entry elf;
4020 /* A pointer to the most recently used stub hash entry against this
4022 struct ppc_stub_hash_entry *stub_cache;
4024 /* A pointer to the next symbol starting with a '.' */
4025 struct ppc_link_hash_entry *next_dot_sym;
4028 /* Track dynamic relocs copied for this symbol. */
4029 struct elf_dyn_relocs *dyn_relocs;
4031 /* Link between function code and descriptor symbols. */
4032 struct ppc_link_hash_entry *oh;
4034 /* Flag function code and descriptor symbols. */
4035 unsigned int is_func:1;
4036 unsigned int is_func_descriptor:1;
4037 unsigned int fake:1;
4039 /* Whether global opd/toc sym has been adjusted or not.
4040 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
4041 should be set for all globals defined in any opd/toc section. */
4042 unsigned int adjust_done:1;
4044 /* Set if this is an out-of-line register save/restore function,
4045 with non-standard calling convention. */
4046 unsigned int save_res:1;
4048 /* Set if a duplicate symbol with non-zero localentry is detected,
4049 even when the duplicate symbol does not provide a definition. */
4050 unsigned int non_zero_localentry:1;
4052 /* Contexts in which symbol is used in the GOT (or TOC).
4053 Bits are or'd into the mask as the corresponding relocs are
4054 encountered during check_relocs, with TLS_TLS being set when any
4055 of the other TLS bits are set. tls_optimize clears bits when
4056 optimizing to indicate the corresponding GOT entry type is not
4057 needed. If set, TLS_TLS is never cleared. tls_optimize may also
4058 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
4059 separate flag rather than setting TPREL just for convenience in
4060 distinguishing the two cases.
4061 These flags are also kept for local symbols. */
4062 #define TLS_TLS 1 /* Any TLS reloc. */
4063 #define TLS_GD 2 /* GD reloc. */
4064 #define TLS_LD 4 /* LD reloc. */
4065 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
4066 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
4067 #define TLS_MARK 32 /* __tls_get_addr call marked. */
4068 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
4069 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
4070 unsigned char tls_mask;
4072 /* The above field is also used to mark function symbols. In which
4073 case TLS_TLS will be 0. */
4074 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
4075 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
4076 #define NON_GOT 256 /* local symbol plt, not stored. */
4079 /* ppc64 ELF linker hash table. */
4081 struct ppc_link_hash_table
4083 struct elf_link_hash_table elf;
4085 /* The stub hash table. */
4086 struct bfd_hash_table stub_hash_table;
4088 /* Another hash table for plt_branch stubs. */
4089 struct bfd_hash_table branch_hash_table;
4091 /* Hash table for function prologue tocsave. */
4092 htab_t tocsave_htab;
4094 /* Various options and other info passed from the linker. */
4095 struct ppc64_elf_params *params;
4097 /* The size of sec_info below. */
4098 unsigned int sec_info_arr_size;
4100 /* Per-section array of extra section info. Done this way rather
4101 than as part of ppc64_elf_section_data so we have the info for
4102 non-ppc64 sections. */
4105 /* Along with elf_gp, specifies the TOC pointer used by this section. */
4110 /* The section group that this section belongs to. */
4111 struct map_stub *group;
4112 /* A temp section list pointer. */
4117 /* Linked list of groups. */
4118 struct map_stub *group;
4120 /* Temp used when calculating TOC pointers. */
4123 asection *toc_first_sec;
4125 /* Used when adding symbols. */
4126 struct ppc_link_hash_entry *dot_syms;
4128 /* Shortcuts to get to dynamic linker sections. */
4130 asection *global_entry;
4133 asection *relpltlocal;
4136 asection *glink_eh_frame;
4138 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
4139 struct ppc_link_hash_entry *tls_get_addr;
4140 struct ppc_link_hash_entry *tls_get_addr_fd;
4142 /* The size of reliplt used by got entry relocs. */
4143 bfd_size_type got_reli_size;
4146 unsigned long stub_count[ppc_stub_global_entry];
4148 /* Number of stubs against global syms. */
4149 unsigned long stub_globals;
4151 /* Set if we're linking code with function descriptors. */
4152 unsigned int opd_abi:1;
4154 /* Support for multiple toc sections. */
4155 unsigned int do_multi_toc:1;
4156 unsigned int multi_toc_needed:1;
4157 unsigned int second_toc_pass:1;
4158 unsigned int do_toc_opt:1;
4160 /* Set if tls optimization is enabled. */
4161 unsigned int do_tls_opt:1;
4164 unsigned int stub_error:1;
4166 /* Whether func_desc_adjust needs to be run over symbols. */
4167 unsigned int need_func_desc_adj:1;
4169 /* Whether there exist local gnu indirect function resolvers,
4170 referenced by dynamic relocations. */
4171 unsigned int local_ifunc_resolver:1;
4172 unsigned int maybe_local_ifunc_resolver:1;
4174 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
4175 unsigned int has_plt_localentry0:1;
4177 /* Incremented every time we size stubs. */
4178 unsigned int stub_iteration;
4180 /* Small local sym cache. */
4181 struct sym_cache sym_cache;
4184 /* Rename some of the generic section flags to better document how they
4187 /* Nonzero if this section has TLS related relocations. */
4188 #define has_tls_reloc sec_flg0
4190 /* Nonzero if this section has a call to __tls_get_addr. */
4191 #define has_tls_get_addr_call sec_flg1
4193 /* Nonzero if this section has any toc or got relocs. */
4194 #define has_toc_reloc sec_flg2
4196 /* Nonzero if this section has a call to another section that uses
4198 #define makes_toc_func_call sec_flg3
4200 /* Recursion protection when determining above flag. */
4201 #define call_check_in_progress sec_flg4
4202 #define call_check_done sec_flg5
4204 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4206 #define ppc_hash_table(p) \
4207 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4208 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4210 #define ppc_stub_hash_lookup(table, string, create, copy) \
4211 ((struct ppc_stub_hash_entry *) \
4212 bfd_hash_lookup ((table), (string), (create), (copy)))
4214 #define ppc_branch_hash_lookup(table, string, create, copy) \
4215 ((struct ppc_branch_hash_entry *) \
4216 bfd_hash_lookup ((table), (string), (create), (copy)))
4218 /* Create an entry in the stub hash table. */
4220 static struct bfd_hash_entry *
4221 stub_hash_newfunc (struct bfd_hash_entry *entry,
4222 struct bfd_hash_table *table,
4225 /* Allocate the structure if it has not already been allocated by a
4229 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
4234 /* Call the allocation method of the superclass. */
4235 entry = bfd_hash_newfunc (entry, table, string);
4238 struct ppc_stub_hash_entry *eh;
4240 /* Initialize the local fields. */
4241 eh = (struct ppc_stub_hash_entry *) entry;
4242 eh->stub_type = ppc_stub_none;
4244 eh->stub_offset = 0;
4245 eh->target_value = 0;
4246 eh->target_section = NULL;
4255 /* Create an entry in the branch hash table. */
4257 static struct bfd_hash_entry *
4258 branch_hash_newfunc (struct bfd_hash_entry *entry,
4259 struct bfd_hash_table *table,
4262 /* Allocate the structure if it has not already been allocated by a
4266 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
4271 /* Call the allocation method of the superclass. */
4272 entry = bfd_hash_newfunc (entry, table, string);
4275 struct ppc_branch_hash_entry *eh;
4277 /* Initialize the local fields. */
4278 eh = (struct ppc_branch_hash_entry *) entry;
4286 /* Create an entry in a ppc64 ELF linker hash table. */
4288 static struct bfd_hash_entry *
4289 link_hash_newfunc (struct bfd_hash_entry *entry,
4290 struct bfd_hash_table *table,
4293 /* Allocate the structure if it has not already been allocated by a
4297 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
4302 /* Call the allocation method of the superclass. */
4303 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
4306 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
4308 memset (&eh->u.stub_cache, 0,
4309 (sizeof (struct ppc_link_hash_entry)
4310 - offsetof (struct ppc_link_hash_entry, u.stub_cache)));
4312 /* When making function calls, old ABI code references function entry
4313 points (dot symbols), while new ABI code references the function
4314 descriptor symbol. We need to make any combination of reference and
4315 definition work together, without breaking archive linking.
4317 For a defined function "foo" and an undefined call to "bar":
4318 An old object defines "foo" and ".foo", references ".bar" (possibly
4320 A new object defines "foo" and references "bar".
4322 A new object thus has no problem with its undefined symbols being
4323 satisfied by definitions in an old object. On the other hand, the
4324 old object won't have ".bar" satisfied by a new object.
4326 Keep a list of newly added dot-symbols. */
4328 if (string[0] == '.')
4330 struct ppc_link_hash_table *htab;
4332 htab = (struct ppc_link_hash_table *) table;
4333 eh->u.next_dot_sym = htab->dot_syms;
4334 htab->dot_syms = eh;
4341 struct tocsave_entry {
4347 tocsave_htab_hash (const void *p)
4349 const struct tocsave_entry *e = (const struct tocsave_entry *) p;
4350 return ((bfd_vma) (intptr_t) e->sec ^ e->offset) >> 3;
4354 tocsave_htab_eq (const void *p1, const void *p2)
4356 const struct tocsave_entry *e1 = (const struct tocsave_entry *) p1;
4357 const struct tocsave_entry *e2 = (const struct tocsave_entry *) p2;
4358 return e1->sec == e2->sec && e1->offset == e2->offset;
4361 /* Destroy a ppc64 ELF linker hash table. */
4364 ppc64_elf_link_hash_table_free (bfd *obfd)
4366 struct ppc_link_hash_table *htab;
4368 htab = (struct ppc_link_hash_table *) obfd->link.hash;
4369 if (htab->tocsave_htab)
4370 htab_delete (htab->tocsave_htab);
4371 bfd_hash_table_free (&htab->branch_hash_table);
4372 bfd_hash_table_free (&htab->stub_hash_table);
4373 _bfd_elf_link_hash_table_free (obfd);
4376 /* Create a ppc64 ELF linker hash table. */
4378 static struct bfd_link_hash_table *
4379 ppc64_elf_link_hash_table_create (bfd *abfd)
4381 struct ppc_link_hash_table *htab;
4382 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
4384 htab = bfd_zmalloc (amt);
4388 if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
4389 sizeof (struct ppc_link_hash_entry),
4396 /* Init the stub hash table too. */
4397 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
4398 sizeof (struct ppc_stub_hash_entry)))
4400 _bfd_elf_link_hash_table_free (abfd);
4404 /* And the branch hash table. */
4405 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
4406 sizeof (struct ppc_branch_hash_entry)))
4408 bfd_hash_table_free (&htab->stub_hash_table);
4409 _bfd_elf_link_hash_table_free (abfd);
4413 htab->tocsave_htab = htab_try_create (1024,
4417 if (htab->tocsave_htab == NULL)
4419 ppc64_elf_link_hash_table_free (abfd);
4422 htab->elf.root.hash_table_free = ppc64_elf_link_hash_table_free;
4424 /* Initializing two fields of the union is just cosmetic. We really
4425 only care about glist, but when compiled on a 32-bit host the
4426 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4427 debugger inspection of these fields look nicer. */
4428 htab->elf.init_got_refcount.refcount = 0;
4429 htab->elf.init_got_refcount.glist = NULL;
4430 htab->elf.init_plt_refcount.refcount = 0;
4431 htab->elf.init_plt_refcount.glist = NULL;
4432 htab->elf.init_got_offset.offset = 0;
4433 htab->elf.init_got_offset.glist = NULL;
4434 htab->elf.init_plt_offset.offset = 0;
4435 htab->elf.init_plt_offset.glist = NULL;
4437 return &htab->elf.root;
4440 /* Create sections for linker generated code. */
4443 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
4445 struct ppc_link_hash_table *htab;
4448 htab = ppc_hash_table (info);
4450 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
4451 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4452 if (htab->params->save_restore_funcs)
4454 /* Create .sfpr for code to save and restore fp regs. */
4455 htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
4457 if (htab->sfpr == NULL
4458 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
4462 if (bfd_link_relocatable (info))
4465 /* Create .glink for lazy dynamic linking support. */
4466 htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
4468 if (htab->glink == NULL
4469 || ! bfd_set_section_alignment (dynobj, htab->glink, 3))
4472 /* The part of .glink used by global entry stubs, separate so that
4473 it can be aligned appropriately without affecting htab->glink. */
4474 htab->global_entry = bfd_make_section_anyway_with_flags (dynobj, ".glink",
4476 if (htab->global_entry == NULL
4477 || ! bfd_set_section_alignment (dynobj, htab->global_entry, 2))
4480 if (!info->no_ld_generated_unwind_info)
4482 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
4483 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4484 htab->glink_eh_frame = bfd_make_section_anyway_with_flags (dynobj,
4487 if (htab->glink_eh_frame == NULL
4488 || !bfd_set_section_alignment (dynobj, htab->glink_eh_frame, 2))
4492 flags = SEC_ALLOC | SEC_LINKER_CREATED;
4493 htab->elf.iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
4494 if (htab->elf.iplt == NULL
4495 || ! bfd_set_section_alignment (dynobj, htab->elf.iplt, 3))
4498 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4499 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4501 = bfd_make_section_anyway_with_flags (dynobj, ".rela.iplt", flags);
4502 if (htab->elf.irelplt == NULL
4503 || ! bfd_set_section_alignment (dynobj, htab->elf.irelplt, 3))
4506 /* Create branch lookup table for plt_branch stubs. */
4507 flags = (SEC_ALLOC | SEC_LOAD
4508 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4509 htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
4511 if (htab->brlt == NULL
4512 || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
4515 /* Local plt entries, put in .branch_lt but a separate section for
4517 htab->pltlocal = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
4519 if (htab->pltlocal == NULL
4520 || ! bfd_set_section_alignment (dynobj, htab->pltlocal, 3))
4523 if (!bfd_link_pic (info))
4526 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4527 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4529 = bfd_make_section_anyway_with_flags (dynobj, ".rela.branch_lt", flags);
4530 if (htab->relbrlt == NULL
4531 || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
4535 = bfd_make_section_anyway_with_flags (dynobj, ".rela.branch_lt", flags);
4536 if (htab->relpltlocal == NULL
4537 || ! bfd_set_section_alignment (dynobj, htab->relpltlocal, 3))
4543 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4546 ppc64_elf_init_stub_bfd (struct bfd_link_info *info,
4547 struct ppc64_elf_params *params)
4549 struct ppc_link_hash_table *htab;
4551 elf_elfheader (params->stub_bfd)->e_ident[EI_CLASS] = ELFCLASS64;
4553 /* Always hook our dynamic sections into the first bfd, which is the
4554 linker created stub bfd. This ensures that the GOT header is at
4555 the start of the output TOC section. */
4556 htab = ppc_hash_table (info);
4557 htab->elf.dynobj = params->stub_bfd;
4558 htab->params = params;
4560 return create_linkage_sections (htab->elf.dynobj, info);
4563 /* Build a name for an entry in the stub hash table. */
4566 ppc_stub_name (const asection *input_section,
4567 const asection *sym_sec,
4568 const struct ppc_link_hash_entry *h,
4569 const Elf_Internal_Rela *rel)
4574 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4575 offsets from a sym as a branch target? In fact, we could
4576 probably assume the addend is always zero. */
4577 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
4581 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
4582 stub_name = bfd_malloc (len);
4583 if (stub_name == NULL)
4586 len = sprintf (stub_name, "%08x.%s+%x",
4587 input_section->id & 0xffffffff,
4588 h->elf.root.root.string,
4589 (int) rel->r_addend & 0xffffffff);
4593 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4594 stub_name = bfd_malloc (len);
4595 if (stub_name == NULL)
4598 len = sprintf (stub_name, "%08x.%x:%x+%x",
4599 input_section->id & 0xffffffff,
4600 sym_sec->id & 0xffffffff,
4601 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
4602 (int) rel->r_addend & 0xffffffff);
4604 if (len > 2 && stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
4605 stub_name[len - 2] = 0;
4609 /* Look up an entry in the stub hash. Stub entries are cached because
4610 creating the stub name takes a bit of time. */
4612 static struct ppc_stub_hash_entry *
4613 ppc_get_stub_entry (const asection *input_section,
4614 const asection *sym_sec,
4615 struct ppc_link_hash_entry *h,
4616 const Elf_Internal_Rela *rel,
4617 struct ppc_link_hash_table *htab)
4619 struct ppc_stub_hash_entry *stub_entry;
4620 struct map_stub *group;
4622 /* If this input section is part of a group of sections sharing one
4623 stub section, then use the id of the first section in the group.
4624 Stub names need to include a section id, as there may well be
4625 more than one stub used to reach say, printf, and we need to
4626 distinguish between them. */
4627 group = htab->sec_info[input_section->id].u.group;
4631 if (h != NULL && h->u.stub_cache != NULL
4632 && h->u.stub_cache->h == h
4633 && h->u.stub_cache->group == group)
4635 stub_entry = h->u.stub_cache;
4641 stub_name = ppc_stub_name (group->link_sec, sym_sec, h, rel);
4642 if (stub_name == NULL)
4645 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4646 stub_name, FALSE, FALSE);
4648 h->u.stub_cache = stub_entry;
4656 /* Add a new stub entry to the stub hash. Not all fields of the new
4657 stub entry are initialised. */
4659 static struct ppc_stub_hash_entry *
4660 ppc_add_stub (const char *stub_name,
4662 struct bfd_link_info *info)
4664 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4665 struct map_stub *group;
4668 struct ppc_stub_hash_entry *stub_entry;
4670 group = htab->sec_info[section->id].u.group;
4671 link_sec = group->link_sec;
4672 stub_sec = group->stub_sec;
4673 if (stub_sec == NULL)
4679 namelen = strlen (link_sec->name);
4680 len = namelen + sizeof (STUB_SUFFIX);
4681 s_name = bfd_alloc (htab->params->stub_bfd, len);
4685 memcpy (s_name, link_sec->name, namelen);
4686 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
4687 stub_sec = (*htab->params->add_stub_section) (s_name, link_sec);
4688 if (stub_sec == NULL)
4690 group->stub_sec = stub_sec;
4693 /* Enter this entry into the linker stub hash table. */
4694 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4696 if (stub_entry == NULL)
4698 /* xgettext:c-format */
4699 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
4700 section->owner, stub_name);
4704 stub_entry->group = group;
4705 stub_entry->stub_offset = 0;
4709 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4710 not already done. */
4713 create_got_section (bfd *abfd, struct bfd_link_info *info)
4715 asection *got, *relgot;
4717 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4719 if (!is_ppc64_elf (abfd))
4725 && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
4728 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4729 | SEC_LINKER_CREATED);
4731 got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
4733 || !bfd_set_section_alignment (abfd, got, 3))
4736 relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
4737 flags | SEC_READONLY);
4739 || ! bfd_set_section_alignment (abfd, relgot, 3))
4742 ppc64_elf_tdata (abfd)->got = got;
4743 ppc64_elf_tdata (abfd)->relgot = relgot;
4747 /* Follow indirect and warning symbol links. */
4749 static inline struct bfd_link_hash_entry *
4750 follow_link (struct bfd_link_hash_entry *h)
4752 while (h->type == bfd_link_hash_indirect
4753 || h->type == bfd_link_hash_warning)
4758 static inline struct elf_link_hash_entry *
4759 elf_follow_link (struct elf_link_hash_entry *h)
4761 return (struct elf_link_hash_entry *) follow_link (&h->root);
4764 static inline struct ppc_link_hash_entry *
4765 ppc_follow_link (struct ppc_link_hash_entry *h)
4767 return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
4770 /* Merge PLT info on FROM with that on TO. */
4773 move_plt_plist (struct ppc_link_hash_entry *from,
4774 struct ppc_link_hash_entry *to)
4776 if (from->elf.plt.plist != NULL)
4778 if (to->elf.plt.plist != NULL)
4780 struct plt_entry **entp;
4781 struct plt_entry *ent;
4783 for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; )
4785 struct plt_entry *dent;
4787 for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next)
4788 if (dent->addend == ent->addend)
4790 dent->plt.refcount += ent->plt.refcount;
4797 *entp = to->elf.plt.plist;
4800 to->elf.plt.plist = from->elf.plt.plist;
4801 from->elf.plt.plist = NULL;
4805 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4808 ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
4809 struct elf_link_hash_entry *dir,
4810 struct elf_link_hash_entry *ind)
4812 struct ppc_link_hash_entry *edir, *eind;
4814 edir = (struct ppc_link_hash_entry *) dir;
4815 eind = (struct ppc_link_hash_entry *) ind;
4817 edir->is_func |= eind->is_func;
4818 edir->is_func_descriptor |= eind->is_func_descriptor;
4819 edir->tls_mask |= eind->tls_mask;
4820 if (eind->oh != NULL)
4821 edir->oh = ppc_follow_link (eind->oh);
4823 if (edir->elf.versioned != versioned_hidden)
4824 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
4825 edir->elf.ref_regular |= eind->elf.ref_regular;
4826 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
4827 edir->elf.non_got_ref |= eind->elf.non_got_ref;
4828 edir->elf.needs_plt |= eind->elf.needs_plt;
4829 edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
4831 /* If we were called to copy over info for a weak sym, don't copy
4832 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4833 in order to simplify readonly_dynrelocs and save a field in the
4834 symbol hash entry, but that means dyn_relocs can't be used in any
4835 tests about a specific symbol, or affect other symbol flags which
4837 if (eind->elf.root.type != bfd_link_hash_indirect)
4840 /* Copy over any dynamic relocs we may have on the indirect sym. */
4841 if (eind->dyn_relocs != NULL)
4843 if (edir->dyn_relocs != NULL)
4845 struct elf_dyn_relocs **pp;
4846 struct elf_dyn_relocs *p;
4848 /* Add reloc counts against the indirect sym to the direct sym
4849 list. Merge any entries against the same section. */
4850 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
4852 struct elf_dyn_relocs *q;
4854 for (q = edir->dyn_relocs; q != NULL; q = q->next)
4855 if (q->sec == p->sec)
4857 q->pc_count += p->pc_count;
4858 q->count += p->count;
4865 *pp = edir->dyn_relocs;
4868 edir->dyn_relocs = eind->dyn_relocs;
4869 eind->dyn_relocs = NULL;
4872 /* Copy over got entries that we may have already seen to the
4873 symbol which just became indirect. */
4874 if (eind->elf.got.glist != NULL)
4876 if (edir->elf.got.glist != NULL)
4878 struct got_entry **entp;
4879 struct got_entry *ent;
4881 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
4883 struct got_entry *dent;
4885 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
4886 if (dent->addend == ent->addend
4887 && dent->owner == ent->owner
4888 && dent->tls_type == ent->tls_type)
4890 dent->got.refcount += ent->got.refcount;
4897 *entp = edir->elf.got.glist;
4900 edir->elf.got.glist = eind->elf.got.glist;
4901 eind->elf.got.glist = NULL;
4904 /* And plt entries. */
4905 move_plt_plist (eind, edir);
4907 if (eind->elf.dynindx != -1)
4909 if (edir->elf.dynindx != -1)
4910 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4911 edir->elf.dynstr_index);
4912 edir->elf.dynindx = eind->elf.dynindx;
4913 edir->elf.dynstr_index = eind->elf.dynstr_index;
4914 eind->elf.dynindx = -1;
4915 eind->elf.dynstr_index = 0;
4919 /* Find the function descriptor hash entry from the given function code
4920 hash entry FH. Link the entries via their OH fields. */
4922 static struct ppc_link_hash_entry *
4923 lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
4925 struct ppc_link_hash_entry *fdh = fh->oh;
4929 const char *fd_name = fh->elf.root.root.string + 1;
4931 fdh = (struct ppc_link_hash_entry *)
4932 elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
4936 fdh->is_func_descriptor = 1;
4942 fdh = ppc_follow_link (fdh);
4943 fdh->is_func_descriptor = 1;
4948 /* Make a fake function descriptor sym for the undefined code sym FH. */
4950 static struct ppc_link_hash_entry *
4951 make_fdh (struct bfd_link_info *info,
4952 struct ppc_link_hash_entry *fh)
4954 bfd *abfd = fh->elf.root.u.undef.abfd;
4955 struct bfd_link_hash_entry *bh = NULL;
4956 struct ppc_link_hash_entry *fdh;
4957 flagword flags = (fh->elf.root.type == bfd_link_hash_undefweak
4961 if (!_bfd_generic_link_add_one_symbol (info, abfd,
4962 fh->elf.root.root.string + 1,
4963 flags, bfd_und_section_ptr, 0,
4964 NULL, FALSE, FALSE, &bh))
4967 fdh = (struct ppc_link_hash_entry *) bh;
4968 fdh->elf.non_elf = 0;
4970 fdh->is_func_descriptor = 1;
4977 /* Fix function descriptor symbols defined in .opd sections to be
4981 ppc64_elf_add_symbol_hook (bfd *ibfd,
4982 struct bfd_link_info *info,
4983 Elf_Internal_Sym *isym,
4985 flagword *flags ATTRIBUTE_UNUSED,
4989 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
4990 && (ibfd->flags & DYNAMIC) == 0
4991 && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
4992 elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
4995 && strcmp ((*sec)->name, ".opd") == 0)
4999 if (!(ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
5000 || ELF_ST_TYPE (isym->st_info) == STT_FUNC))
5001 isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
5003 /* If the symbol is a function defined in .opd, and the function
5004 code is in a discarded group, let it appear to be undefined. */
5005 if (!bfd_link_relocatable (info)
5006 && (*sec)->reloc_count != 0
5007 && opd_entry_value (*sec, *value, &code_sec, NULL,
5008 FALSE) != (bfd_vma) -1
5009 && discarded_section (code_sec))
5011 *sec = bfd_und_section_ptr;
5012 isym->st_shndx = SHN_UNDEF;
5015 else if (*sec != NULL
5016 && strcmp ((*sec)->name, ".toc") == 0
5017 && ELF_ST_TYPE (isym->st_info) == STT_OBJECT)
5019 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5021 htab->params->object_in_toc = 1;
5024 if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
5026 if (abiversion (ibfd) == 0)
5027 set_abiversion (ibfd, 2);
5028 else if (abiversion (ibfd) == 1)
5030 _bfd_error_handler (_("symbol '%s' has invalid st_other"
5031 " for ABI version 1"), *name);
5032 bfd_set_error (bfd_error_bad_value);
5040 /* Merge non-visibility st_other attributes: local entry point. */
5043 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
5044 const Elf_Internal_Sym *isym,
5045 bfd_boolean definition,
5046 bfd_boolean dynamic)
5048 if (definition && (!dynamic || !h->def_regular))
5049 h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
5050 | ELF_ST_VISIBILITY (h->other));
5053 /* Hook called on merging a symbol. We use this to clear "fake" since
5054 we now have a real symbol. */
5057 ppc64_elf_merge_symbol (struct elf_link_hash_entry *h,
5058 const Elf_Internal_Sym *isym,
5059 asection **psec ATTRIBUTE_UNUSED,
5060 bfd_boolean newdef ATTRIBUTE_UNUSED,
5061 bfd_boolean olddef ATTRIBUTE_UNUSED,
5062 bfd *oldbfd ATTRIBUTE_UNUSED,
5063 const asection *oldsec ATTRIBUTE_UNUSED)
5065 ((struct ppc_link_hash_entry *) h)->fake = 0;
5066 if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
5067 ((struct ppc_link_hash_entry *) h)->non_zero_localentry = 1;
5071 /* This function makes an old ABI object reference to ".bar" cause the
5072 inclusion of a new ABI object archive that defines "bar".
5073 NAME is a symbol defined in an archive. Return a symbol in the hash
5074 table that might be satisfied by the archive symbols. */
5076 static struct elf_link_hash_entry *
5077 ppc64_elf_archive_symbol_lookup (bfd *abfd,
5078 struct bfd_link_info *info,
5081 struct elf_link_hash_entry *h;
5085 h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
5087 /* Don't return this sym if it is a fake function descriptor
5088 created by add_symbol_adjust. */
5089 && !((struct ppc_link_hash_entry *) h)->fake)
5095 len = strlen (name);
5096 dot_name = bfd_alloc (abfd, len + 2);
5097 if (dot_name == NULL)
5098 return (struct elf_link_hash_entry *) -1;
5100 memcpy (dot_name + 1, name, len + 1);
5101 h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
5102 bfd_release (abfd, dot_name);
5106 /* This function satisfies all old ABI object references to ".bar" if a
5107 new ABI object defines "bar". Well, at least, undefined dot symbols
5108 are made weak. This stops later archive searches from including an
5109 object if we already have a function descriptor definition. It also
5110 prevents the linker complaining about undefined symbols.
5111 We also check and correct mismatched symbol visibility here. The
5112 most restrictive visibility of the function descriptor and the
5113 function entry symbol is used. */
5116 add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
5118 struct ppc_link_hash_table *htab;
5119 struct ppc_link_hash_entry *fdh;
5121 if (eh->elf.root.type == bfd_link_hash_warning)
5122 eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
5124 if (eh->elf.root.type == bfd_link_hash_indirect)
5127 if (eh->elf.root.root.string[0] != '.')
5130 htab = ppc_hash_table (info);
5134 fdh = lookup_fdh (eh, htab);
5136 && !bfd_link_relocatable (info)
5137 && (eh->elf.root.type == bfd_link_hash_undefined
5138 || eh->elf.root.type == bfd_link_hash_undefweak)
5139 && eh->elf.ref_regular)
5141 /* Make an undefined function descriptor sym, in order to
5142 pull in an --as-needed shared lib. Archives are handled
5144 fdh = make_fdh (info, eh);
5151 unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
5152 unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
5154 /* Make both descriptor and entry symbol have the most
5155 constraining visibility of either symbol. */
5156 if (entry_vis < descr_vis)
5157 fdh->elf.other += entry_vis - descr_vis;
5158 else if (entry_vis > descr_vis)
5159 eh->elf.other += descr_vis - entry_vis;
5161 /* Propagate reference flags from entry symbol to function
5162 descriptor symbol. */
5163 fdh->elf.root.non_ir_ref_regular |= eh->elf.root.non_ir_ref_regular;
5164 fdh->elf.root.non_ir_ref_dynamic |= eh->elf.root.non_ir_ref_dynamic;
5165 fdh->elf.ref_regular |= eh->elf.ref_regular;
5166 fdh->elf.ref_regular_nonweak |= eh->elf.ref_regular_nonweak;
5168 if (!fdh->elf.forced_local
5169 && fdh->elf.dynindx == -1
5170 && fdh->elf.versioned != versioned_hidden
5171 && (bfd_link_dll (info)
5172 || fdh->elf.def_dynamic
5173 || fdh->elf.ref_dynamic)
5174 && (eh->elf.ref_regular
5175 || eh->elf.def_regular))
5177 if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
5185 /* Set up opd section info and abiversion for IBFD, and process list
5186 of dot-symbols we made in link_hash_newfunc. */
5189 ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
5191 struct ppc_link_hash_table *htab;
5192 struct ppc_link_hash_entry **p, *eh;
5193 asection *opd = bfd_get_section_by_name (ibfd, ".opd");
5195 if (opd != NULL && opd->size != 0)
5197 BFD_ASSERT (ppc64_elf_section_data (opd)->sec_type == sec_normal);
5198 ppc64_elf_section_data (opd)->sec_type = sec_opd;
5200 if (abiversion (ibfd) == 0)
5201 set_abiversion (ibfd, 1);
5202 else if (abiversion (ibfd) >= 2)
5204 /* xgettext:c-format */
5205 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
5206 ibfd, abiversion (ibfd));
5207 bfd_set_error (bfd_error_bad_value);
5212 if (is_ppc64_elf (info->output_bfd))
5214 /* For input files without an explicit abiversion in e_flags
5215 we should have flagged any with symbol st_other bits set
5216 as ELFv1 and above flagged those with .opd as ELFv2.
5217 Set the output abiversion if not yet set, and for any input
5218 still ambiguous, take its abiversion from the output.
5219 Differences in ABI are reported later. */
5220 if (abiversion (info->output_bfd) == 0)
5221 set_abiversion (info->output_bfd, abiversion (ibfd));
5222 else if (abiversion (ibfd) == 0)
5223 set_abiversion (ibfd, abiversion (info->output_bfd));
5226 htab = ppc_hash_table (info);
5230 if (opd != NULL && opd->size != 0
5231 && (ibfd->flags & DYNAMIC) == 0
5232 && (opd->flags & SEC_RELOC) != 0
5233 && opd->reloc_count != 0
5234 && !bfd_is_abs_section (opd->output_section)
5235 && info->gc_sections)
5237 /* Garbage collection needs some extra help with .opd sections.
5238 We don't want to necessarily keep everything referenced by
5239 relocs in .opd, as that would keep all functions. Instead,
5240 if we reference an .opd symbol (a function descriptor), we
5241 want to keep the function code symbol's section. This is
5242 easy for global symbols, but for local syms we need to keep
5243 information about the associated function section. */
5245 asection **opd_sym_map;
5246 Elf_Internal_Shdr *symtab_hdr;
5247 Elf_Internal_Rela *relocs, *rel_end, *rel;
5249 amt = OPD_NDX (opd->size) * sizeof (*opd_sym_map);
5250 opd_sym_map = bfd_zalloc (ibfd, amt);
5251 if (opd_sym_map == NULL)
5253 ppc64_elf_section_data (opd)->u.opd.func_sec = opd_sym_map;
5254 relocs = _bfd_elf_link_read_relocs (ibfd, opd, NULL, NULL,
5258 symtab_hdr = &elf_symtab_hdr (ibfd);
5259 rel_end = relocs + opd->reloc_count - 1;
5260 for (rel = relocs; rel < rel_end; rel++)
5262 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
5263 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
5265 if (r_type == R_PPC64_ADDR64
5266 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC
5267 && r_symndx < symtab_hdr->sh_info)
5269 Elf_Internal_Sym *isym;
5272 isym = bfd_sym_from_r_symndx (&htab->sym_cache, ibfd, r_symndx);
5275 if (elf_section_data (opd)->relocs != relocs)
5280 s = bfd_section_from_elf_index (ibfd, isym->st_shndx);
5281 if (s != NULL && s != opd)
5282 opd_sym_map[OPD_NDX (rel->r_offset)] = s;
5285 if (elf_section_data (opd)->relocs != relocs)
5289 p = &htab->dot_syms;
5290 while ((eh = *p) != NULL)
5293 if (&eh->elf == htab->elf.hgot)
5295 else if (htab->elf.hgot == NULL
5296 && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
5297 htab->elf.hgot = &eh->elf;
5298 else if (abiversion (ibfd) <= 1)
5300 htab->need_func_desc_adj = 1;
5301 if (!add_symbol_adjust (eh, info))
5304 p = &eh->u.next_dot_sym;
5309 /* Undo hash table changes when an --as-needed input file is determined
5310 not to be needed. */
5313 ppc64_elf_notice_as_needed (bfd *ibfd,
5314 struct bfd_link_info *info,
5315 enum notice_asneeded_action act)
5317 if (act == notice_not_needed)
5319 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5324 htab->dot_syms = NULL;
5326 return _bfd_elf_notice_as_needed (ibfd, info, act);
5329 /* If --just-symbols against a final linked binary, then assume we need
5330 toc adjusting stubs when calling functions defined there. */
5333 ppc64_elf_link_just_syms (asection *sec, struct bfd_link_info *info)
5335 if ((sec->flags & SEC_CODE) != 0
5336 && (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
5337 && is_ppc64_elf (sec->owner))
5339 if (abiversion (sec->owner) >= 2
5340 || bfd_get_section_by_name (sec->owner, ".opd") != NULL)
5341 sec->has_toc_reloc = 1;
5343 _bfd_elf_link_just_syms (sec, info);
5346 static struct plt_entry **
5347 update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
5348 unsigned long r_symndx, bfd_vma r_addend, int tls_type)
5350 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
5351 struct plt_entry **local_plt;
5352 unsigned char *local_got_tls_masks;
5354 if (local_got_ents == NULL)
5356 bfd_size_type size = symtab_hdr->sh_info;
5358 size *= (sizeof (*local_got_ents)
5359 + sizeof (*local_plt)
5360 + sizeof (*local_got_tls_masks));
5361 local_got_ents = bfd_zalloc (abfd, size);
5362 if (local_got_ents == NULL)
5364 elf_local_got_ents (abfd) = local_got_ents;
5367 if ((tls_type & (NON_GOT | TLS_EXPLICIT)) == 0)
5369 struct got_entry *ent;
5371 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
5372 if (ent->addend == r_addend
5373 && ent->owner == abfd
5374 && ent->tls_type == tls_type)
5378 bfd_size_type amt = sizeof (*ent);
5379 ent = bfd_alloc (abfd, amt);
5382 ent->next = local_got_ents[r_symndx];
5383 ent->addend = r_addend;
5385 ent->tls_type = tls_type;
5386 ent->is_indirect = FALSE;
5387 ent->got.refcount = 0;
5388 local_got_ents[r_symndx] = ent;
5390 ent->got.refcount += 1;
5393 local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info);
5394 local_got_tls_masks = (unsigned char *) (local_plt + symtab_hdr->sh_info);
5395 local_got_tls_masks[r_symndx] |= tls_type & 0xff;
5397 return local_plt + r_symndx;
5401 update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
5403 struct plt_entry *ent;
5405 for (ent = *plist; ent != NULL; ent = ent->next)
5406 if (ent->addend == addend)
5410 bfd_size_type amt = sizeof (*ent);
5411 ent = bfd_alloc (abfd, amt);
5415 ent->addend = addend;
5416 ent->plt.refcount = 0;
5419 ent->plt.refcount += 1;
5424 is_branch_reloc (enum elf_ppc64_reloc_type r_type)
5426 return (r_type == R_PPC64_REL24
5427 || r_type == R_PPC64_REL14
5428 || r_type == R_PPC64_REL14_BRTAKEN
5429 || r_type == R_PPC64_REL14_BRNTAKEN
5430 || r_type == R_PPC64_ADDR24
5431 || r_type == R_PPC64_ADDR14
5432 || r_type == R_PPC64_ADDR14_BRTAKEN
5433 || r_type == R_PPC64_ADDR14_BRNTAKEN);
5436 /* Look through the relocs for a section during the first phase, and
5437 calculate needed space in the global offset table, procedure
5438 linkage table, and dynamic reloc sections. */
5441 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
5442 asection *sec, const Elf_Internal_Rela *relocs)
5444 struct ppc_link_hash_table *htab;
5445 Elf_Internal_Shdr *symtab_hdr;
5446 struct elf_link_hash_entry **sym_hashes;
5447 const Elf_Internal_Rela *rel;
5448 const Elf_Internal_Rela *rel_end;
5450 struct elf_link_hash_entry *tga, *dottga;
5453 if (bfd_link_relocatable (info))
5456 /* Don't do anything special with non-loaded, non-alloced sections.
5457 In particular, any relocs in such sections should not affect GOT
5458 and PLT reference counting (ie. we don't allow them to create GOT
5459 or PLT entries), there's no possibility or desire to optimize TLS
5460 relocs, and there's not much point in propagating relocs to shared
5461 libs that the dynamic linker won't relocate. */
5462 if ((sec->flags & SEC_ALLOC) == 0)
5465 BFD_ASSERT (is_ppc64_elf (abfd));
5467 htab = ppc_hash_table (info);
5471 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
5472 FALSE, FALSE, TRUE);
5473 dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
5474 FALSE, FALSE, TRUE);
5475 symtab_hdr = &elf_symtab_hdr (abfd);
5476 sym_hashes = elf_sym_hashes (abfd);
5478 is_opd = ppc64_elf_section_data (sec)->sec_type == sec_opd;
5479 rel_end = relocs + sec->reloc_count;
5480 for (rel = relocs; rel < rel_end; rel++)
5482 unsigned long r_symndx;
5483 struct elf_link_hash_entry *h;
5484 enum elf_ppc64_reloc_type r_type;
5486 struct _ppc64_elf_section_data *ppc64_sec;
5487 struct plt_entry **ifunc, **plt_list;
5489 r_symndx = ELF64_R_SYM (rel->r_info);
5490 if (r_symndx < symtab_hdr->sh_info)
5494 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5495 h = elf_follow_link (h);
5497 if (h == htab->elf.hgot)
5498 sec->has_toc_reloc = 1;
5505 if (h->type == STT_GNU_IFUNC)
5508 ifunc = &h->plt.plist;
5513 Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5518 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
5520 ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
5522 NON_GOT | PLT_IFUNC);
5528 r_type = ELF64_R_TYPE (rel->r_info);
5533 /* These special tls relocs tie a call to __tls_get_addr with
5534 its parameter symbol. */
5536 ((struct ppc_link_hash_entry *) h)->tls_mask |= TLS_TLS | TLS_MARK;
5538 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5540 NON_GOT | TLS_TLS | TLS_MARK))
5542 sec->has_tls_reloc = 1;
5545 case R_PPC64_GOT_TLSLD16:
5546 case R_PPC64_GOT_TLSLD16_LO:
5547 case R_PPC64_GOT_TLSLD16_HI:
5548 case R_PPC64_GOT_TLSLD16_HA:
5549 tls_type = TLS_TLS | TLS_LD;
5552 case R_PPC64_GOT_TLSGD16:
5553 case R_PPC64_GOT_TLSGD16_LO:
5554 case R_PPC64_GOT_TLSGD16_HI:
5555 case R_PPC64_GOT_TLSGD16_HA:
5556 tls_type = TLS_TLS | TLS_GD;
5559 case R_PPC64_GOT_TPREL16_DS:
5560 case R_PPC64_GOT_TPREL16_LO_DS:
5561 case R_PPC64_GOT_TPREL16_HI:
5562 case R_PPC64_GOT_TPREL16_HA:
5563 if (bfd_link_dll (info))
5564 info->flags |= DF_STATIC_TLS;
5565 tls_type = TLS_TLS | TLS_TPREL;
5568 case R_PPC64_GOT_DTPREL16_DS:
5569 case R_PPC64_GOT_DTPREL16_LO_DS:
5570 case R_PPC64_GOT_DTPREL16_HI:
5571 case R_PPC64_GOT_DTPREL16_HA:
5572 tls_type = TLS_TLS | TLS_DTPREL;
5574 sec->has_tls_reloc = 1;
5578 case R_PPC64_GOT16_DS:
5579 case R_PPC64_GOT16_HA:
5580 case R_PPC64_GOT16_HI:
5581 case R_PPC64_GOT16_LO:
5582 case R_PPC64_GOT16_LO_DS:
5583 /* This symbol requires a global offset table entry. */
5584 sec->has_toc_reloc = 1;
5585 if (r_type == R_PPC64_GOT_TLSLD16
5586 || r_type == R_PPC64_GOT_TLSGD16
5587 || r_type == R_PPC64_GOT_TPREL16_DS
5588 || r_type == R_PPC64_GOT_DTPREL16_DS
5589 || r_type == R_PPC64_GOT16
5590 || r_type == R_PPC64_GOT16_DS)
5592 htab->do_multi_toc = 1;
5593 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5596 if (ppc64_elf_tdata (abfd)->got == NULL
5597 && !create_got_section (abfd, info))
5602 struct ppc_link_hash_entry *eh;
5603 struct got_entry *ent;
5605 eh = (struct ppc_link_hash_entry *) h;
5606 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
5607 if (ent->addend == rel->r_addend
5608 && ent->owner == abfd
5609 && ent->tls_type == tls_type)
5613 bfd_size_type amt = sizeof (*ent);
5614 ent = bfd_alloc (abfd, amt);
5617 ent->next = eh->elf.got.glist;
5618 ent->addend = rel->r_addend;
5620 ent->tls_type = tls_type;
5621 ent->is_indirect = FALSE;
5622 ent->got.refcount = 0;
5623 eh->elf.got.glist = ent;
5625 ent->got.refcount += 1;
5626 eh->tls_mask |= tls_type;
5629 /* This is a global offset table entry for a local symbol. */
5630 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5631 rel->r_addend, tls_type))
5634 /* We may also need a plt entry if the symbol turns out to be
5636 if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1)
5638 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5643 case R_PPC64_PLT16_HA:
5644 case R_PPC64_PLT16_HI:
5645 case R_PPC64_PLT16_LO:
5646 case R_PPC64_PLT16_LO_DS:
5649 /* This symbol requires a procedure linkage table entry. */
5654 if (h->root.root.string[0] == '.'
5655 && h->root.root.string[1] != '\0')
5656 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5657 ((struct ppc_link_hash_entry *) h)->tls_mask |= PLT_KEEP;
5658 plt_list = &h->plt.plist;
5660 if (plt_list == NULL)
5661 plt_list = update_local_sym_info (abfd, symtab_hdr, r_symndx,
5663 NON_GOT | PLT_KEEP);
5664 if (!update_plt_info (abfd, plt_list, rel->r_addend))
5668 /* The following relocations don't need to propagate the
5669 relocation if linking a shared object since they are
5670 section relative. */
5671 case R_PPC64_SECTOFF:
5672 case R_PPC64_SECTOFF_LO:
5673 case R_PPC64_SECTOFF_HI:
5674 case R_PPC64_SECTOFF_HA:
5675 case R_PPC64_SECTOFF_DS:
5676 case R_PPC64_SECTOFF_LO_DS:
5677 case R_PPC64_DTPREL16:
5678 case R_PPC64_DTPREL16_LO:
5679 case R_PPC64_DTPREL16_HI:
5680 case R_PPC64_DTPREL16_HA:
5681 case R_PPC64_DTPREL16_DS:
5682 case R_PPC64_DTPREL16_LO_DS:
5683 case R_PPC64_DTPREL16_HIGH:
5684 case R_PPC64_DTPREL16_HIGHA:
5685 case R_PPC64_DTPREL16_HIGHER:
5686 case R_PPC64_DTPREL16_HIGHERA:
5687 case R_PPC64_DTPREL16_HIGHEST:
5688 case R_PPC64_DTPREL16_HIGHESTA:
5693 case R_PPC64_REL16_LO:
5694 case R_PPC64_REL16_HI:
5695 case R_PPC64_REL16_HA:
5696 case R_PPC64_REL16DX_HA:
5699 /* Not supported as a dynamic relocation. */
5700 case R_PPC64_ADDR64_LOCAL:
5701 if (bfd_link_pic (info))
5703 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5705 /* xgettext:c-format */
5706 info->callbacks->einfo (_("%H: %s reloc unsupported "
5707 "in shared libraries and PIEs\n"),
5708 abfd, sec, rel->r_offset,
5709 ppc64_elf_howto_table[r_type]->name);
5710 bfd_set_error (bfd_error_bad_value);
5716 case R_PPC64_TOC16_DS:
5717 htab->do_multi_toc = 1;
5718 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5720 case R_PPC64_TOC16_LO:
5721 case R_PPC64_TOC16_HI:
5722 case R_PPC64_TOC16_HA:
5723 case R_PPC64_TOC16_LO_DS:
5724 sec->has_toc_reloc = 1;
5731 /* This relocation describes the C++ object vtable hierarchy.
5732 Reconstruct it for later use during GC. */
5733 case R_PPC64_GNU_VTINHERIT:
5734 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5738 /* This relocation describes which C++ vtable entries are actually
5739 used. Record for later use during GC. */
5740 case R_PPC64_GNU_VTENTRY:
5741 BFD_ASSERT (h != NULL);
5743 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5748 case R_PPC64_REL14_BRTAKEN:
5749 case R_PPC64_REL14_BRNTAKEN:
5751 asection *dest = NULL;
5753 /* Heuristic: If jumping outside our section, chances are
5754 we are going to need a stub. */
5757 /* If the sym is weak it may be overridden later, so
5758 don't assume we know where a weak sym lives. */
5759 if (h->root.type == bfd_link_hash_defined)
5760 dest = h->root.u.def.section;
5764 Elf_Internal_Sym *isym;
5766 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5771 dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
5775 ppc64_elf_section_data (sec)->has_14bit_branch = 1;
5784 if (h->root.root.string[0] == '.'
5785 && h->root.root.string[1] != '\0')
5786 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5788 if (h == tga || h == dottga)
5790 sec->has_tls_reloc = 1;
5792 && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
5793 || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
5794 /* We have a new-style __tls_get_addr call with
5798 /* Mark this section as having an old-style call. */
5799 sec->has_tls_get_addr_call = 1;
5801 plt_list = &h->plt.plist;
5804 /* We may need a .plt entry if the function this reloc
5805 refers to is in a shared lib. */
5807 && !update_plt_info (abfd, plt_list, rel->r_addend))
5811 case R_PPC64_ADDR14:
5812 case R_PPC64_ADDR14_BRNTAKEN:
5813 case R_PPC64_ADDR14_BRTAKEN:
5814 case R_PPC64_ADDR24:
5817 case R_PPC64_TPREL64:
5818 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
5819 if (bfd_link_dll (info))
5820 info->flags |= DF_STATIC_TLS;
5823 case R_PPC64_DTPMOD64:
5824 if (rel + 1 < rel_end
5825 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
5826 && rel[1].r_offset == rel->r_offset + 8)
5827 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
5829 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
5832 case R_PPC64_DTPREL64:
5833 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
5835 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
5836 && rel[-1].r_offset == rel->r_offset - 8)
5837 /* This is the second reloc of a dtpmod, dtprel pair.
5838 Don't mark with TLS_DTPREL. */
5842 sec->has_tls_reloc = 1;
5845 struct ppc_link_hash_entry *eh;
5846 eh = (struct ppc_link_hash_entry *) h;
5847 eh->tls_mask |= tls_type;
5850 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5851 rel->r_addend, tls_type))
5854 ppc64_sec = ppc64_elf_section_data (sec);
5855 if (ppc64_sec->sec_type != sec_toc)
5859 /* One extra to simplify get_tls_mask. */
5860 amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned);
5861 ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt);
5862 if (ppc64_sec->u.toc.symndx == NULL)
5864 amt = sec->size * sizeof (bfd_vma) / 8;
5865 ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt);
5866 if (ppc64_sec->u.toc.add == NULL)
5868 BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
5869 ppc64_sec->sec_type = sec_toc;
5871 BFD_ASSERT (rel->r_offset % 8 == 0);
5872 ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx;
5873 ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend;
5875 /* Mark the second slot of a GD or LD entry.
5876 -1 to indicate GD and -2 to indicate LD. */
5877 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
5878 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1;
5879 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
5880 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2;
5883 case R_PPC64_TPREL16:
5884 case R_PPC64_TPREL16_LO:
5885 case R_PPC64_TPREL16_HI:
5886 case R_PPC64_TPREL16_HA:
5887 case R_PPC64_TPREL16_DS:
5888 case R_PPC64_TPREL16_LO_DS:
5889 case R_PPC64_TPREL16_HIGH:
5890 case R_PPC64_TPREL16_HIGHA:
5891 case R_PPC64_TPREL16_HIGHER:
5892 case R_PPC64_TPREL16_HIGHERA:
5893 case R_PPC64_TPREL16_HIGHEST:
5894 case R_PPC64_TPREL16_HIGHESTA:
5895 if (bfd_link_dll (info))
5896 info->flags |= DF_STATIC_TLS;
5899 case R_PPC64_ADDR64:
5901 && rel + 1 < rel_end
5902 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
5905 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5909 case R_PPC64_ADDR16:
5910 case R_PPC64_ADDR16_DS:
5911 case R_PPC64_ADDR16_HA:
5912 case R_PPC64_ADDR16_HI:
5913 case R_PPC64_ADDR16_HIGH:
5914 case R_PPC64_ADDR16_HIGHA:
5915 case R_PPC64_ADDR16_HIGHER:
5916 case R_PPC64_ADDR16_HIGHERA:
5917 case R_PPC64_ADDR16_HIGHEST:
5918 case R_PPC64_ADDR16_HIGHESTA:
5919 case R_PPC64_ADDR16_LO:
5920 case R_PPC64_ADDR16_LO_DS:
5921 if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1
5922 && rel->r_addend == 0)
5924 /* We may need a .plt entry if this reloc refers to a
5925 function in a shared lib. */
5926 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5928 h->pointer_equality_needed = 1;
5935 case R_PPC64_ADDR32:
5936 case R_PPC64_UADDR16:
5937 case R_PPC64_UADDR32:
5938 case R_PPC64_UADDR64:
5940 if (h != NULL && !bfd_link_pic (info))
5941 /* We may need a copy reloc. */
5944 /* Don't propagate .opd relocs. */
5945 if (NO_OPD_RELOCS && is_opd)
5948 /* If we are creating a shared library, and this is a reloc
5949 against a global symbol, or a non PC relative reloc
5950 against a local symbol, then we need to copy the reloc
5951 into the shared library. However, if we are linking with
5952 -Bsymbolic, we do not need to copy a reloc against a
5953 global symbol which is defined in an object we are
5954 including in the link (i.e., DEF_REGULAR is set). At
5955 this point we have not seen all the input files, so it is
5956 possible that DEF_REGULAR is not set now but will be set
5957 later (it is never cleared). In case of a weak definition,
5958 DEF_REGULAR may be cleared later by a strong definition in
5959 a shared library. We account for that possibility below by
5960 storing information in the dyn_relocs field of the hash
5961 table entry. A similar situation occurs when creating
5962 shared libraries and symbol visibility changes render the
5965 If on the other hand, we are creating an executable, we
5966 may need to keep relocations for symbols satisfied by a
5967 dynamic library if we manage to avoid copy relocs for the
5970 if ((bfd_link_pic (info)
5971 && (must_be_dyn_reloc (info, r_type)
5973 && (!SYMBOLIC_BIND (info, h)
5974 || h->root.type == bfd_link_hash_defweak
5975 || !h->def_regular))))
5976 || (ELIMINATE_COPY_RELOCS
5977 && !bfd_link_pic (info)
5979 && (h->root.type == bfd_link_hash_defweak
5980 || !h->def_regular))
5981 || (!bfd_link_pic (info)
5984 /* We must copy these reloc types into the output file.
5985 Create a reloc section in dynobj and make room for
5989 sreloc = _bfd_elf_make_dynamic_reloc_section
5990 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
5996 /* If this is a global symbol, we count the number of
5997 relocations we need for this symbol. */
6000 struct elf_dyn_relocs *p;
6001 struct elf_dyn_relocs **head;
6003 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
6005 if (p == NULL || p->sec != sec)
6007 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
6017 if (!must_be_dyn_reloc (info, r_type))
6022 /* Track dynamic relocs needed for local syms too.
6023 We really need local syms available to do this
6025 struct ppc_dyn_relocs *p;
6026 struct ppc_dyn_relocs **head;
6027 bfd_boolean is_ifunc;
6030 Elf_Internal_Sym *isym;
6032 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
6037 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
6041 vpp = &elf_section_data (s)->local_dynrel;
6042 head = (struct ppc_dyn_relocs **) vpp;
6043 is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
6045 if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
6047 if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
6049 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
6055 p->ifunc = is_ifunc;
6071 /* Merge backend specific data from an object file to the output
6072 object file when linking. */
6075 ppc64_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
6077 bfd *obfd = info->output_bfd;
6078 unsigned long iflags, oflags;
6080 if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
6083 if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
6086 if (!_bfd_generic_verify_endian_match (ibfd, info))
6089 iflags = elf_elfheader (ibfd)->e_flags;
6090 oflags = elf_elfheader (obfd)->e_flags;
6092 if (iflags & ~EF_PPC64_ABI)
6095 /* xgettext:c-format */
6096 (_("%pB uses unknown e_flags 0x%lx"), ibfd, iflags);
6097 bfd_set_error (bfd_error_bad_value);
6100 else if (iflags != oflags && iflags != 0)
6103 /* xgettext:c-format */
6104 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
6105 ibfd, iflags, oflags);
6106 bfd_set_error (bfd_error_bad_value);
6110 _bfd_elf_ppc_merge_fp_attributes (ibfd, info);
6112 /* Merge Tag_compatibility attributes and any common GNU ones. */
6113 _bfd_elf_merge_object_attributes (ibfd, info);
6119 ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
6121 /* Print normal ELF private data. */
6122 _bfd_elf_print_private_bfd_data (abfd, ptr);
6124 if (elf_elfheader (abfd)->e_flags != 0)
6128 fprintf (file, _("private flags = 0x%lx:"),
6129 elf_elfheader (abfd)->e_flags);
6131 if ((elf_elfheader (abfd)->e_flags & EF_PPC64_ABI) != 0)
6132 fprintf (file, _(" [abiv%ld]"),
6133 elf_elfheader (abfd)->e_flags & EF_PPC64_ABI);
6140 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
6141 of the code entry point, and its section, which must be in the same
6142 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
6145 opd_entry_value (asection *opd_sec,
6147 asection **code_sec,
6149 bfd_boolean in_code_sec)
6151 bfd *opd_bfd = opd_sec->owner;
6152 Elf_Internal_Rela *relocs;
6153 Elf_Internal_Rela *lo, *hi, *look;
6156 /* No relocs implies we are linking a --just-symbols object, or looking
6157 at a final linked executable with addr2line or somesuch. */
6158 if (opd_sec->reloc_count == 0)
6160 bfd_byte *contents = ppc64_elf_tdata (opd_bfd)->opd.contents;
6162 if (contents == NULL)
6164 if (!bfd_malloc_and_get_section (opd_bfd, opd_sec, &contents))
6165 return (bfd_vma) -1;
6166 ppc64_elf_tdata (opd_bfd)->opd.contents = contents;
6169 /* PR 17512: file: 64b9dfbb. */
6170 if (offset + 7 >= opd_sec->size || offset + 7 < offset)
6171 return (bfd_vma) -1;
6173 val = bfd_get_64 (opd_bfd, contents + offset);
6174 if (code_sec != NULL)
6176 asection *sec, *likely = NULL;
6182 && val < sec->vma + sec->size)
6188 for (sec = opd_bfd->sections; sec != NULL; sec = sec->next)
6190 && (sec->flags & SEC_LOAD) != 0
6191 && (sec->flags & SEC_ALLOC) != 0)
6196 if (code_off != NULL)
6197 *code_off = val - likely->vma;
6203 BFD_ASSERT (is_ppc64_elf (opd_bfd));
6205 relocs = ppc64_elf_tdata (opd_bfd)->opd.relocs;
6207 relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
6208 /* PR 17512: file: df8e1fd6. */
6210 return (bfd_vma) -1;
6212 /* Go find the opd reloc at the sym address. */
6214 hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
6218 look = lo + (hi - lo) / 2;
6219 if (look->r_offset < offset)
6221 else if (look->r_offset > offset)
6225 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd);
6227 if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64
6228 && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
6230 unsigned long symndx = ELF64_R_SYM (look->r_info);
6231 asection *sec = NULL;
6233 if (symndx >= symtab_hdr->sh_info
6234 && elf_sym_hashes (opd_bfd) != NULL)
6236 struct elf_link_hash_entry **sym_hashes;
6237 struct elf_link_hash_entry *rh;
6239 sym_hashes = elf_sym_hashes (opd_bfd);
6240 rh = sym_hashes[symndx - symtab_hdr->sh_info];
6243 rh = elf_follow_link (rh);
6244 if (rh->root.type != bfd_link_hash_defined
6245 && rh->root.type != bfd_link_hash_defweak)
6247 if (rh->root.u.def.section->owner == opd_bfd)
6249 val = rh->root.u.def.value;
6250 sec = rh->root.u.def.section;
6257 Elf_Internal_Sym *sym;
6259 if (symndx < symtab_hdr->sh_info)
6261 sym = (Elf_Internal_Sym *) symtab_hdr->contents;
6264 size_t symcnt = symtab_hdr->sh_info;
6265 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
6270 symtab_hdr->contents = (bfd_byte *) sym;
6276 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
6282 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
6285 BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
6286 val = sym->st_value;
6289 val += look->r_addend;
6290 if (code_off != NULL)
6292 if (code_sec != NULL)
6294 if (in_code_sec && *code_sec != sec)
6299 if (sec->output_section != NULL)
6300 val += sec->output_section->vma + sec->output_offset;
6309 /* If the ELF symbol SYM might be a function in SEC, return the
6310 function size and set *CODE_OFF to the function's entry point,
6311 otherwise return zero. */
6313 static bfd_size_type
6314 ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
6319 if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT
6320 | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0)
6324 if (!(sym->flags & BSF_SYNTHETIC))
6325 size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
6327 if (strcmp (sym->section->name, ".opd") == 0)
6329 struct _opd_sec_data *opd = get_opd_info (sym->section);
6330 bfd_vma symval = sym->value;
6333 && opd->adjust != NULL
6334 && elf_section_data (sym->section)->relocs != NULL)
6336 /* opd_entry_value will use cached relocs that have been
6337 adjusted, but with raw symbols. That means both local
6338 and global symbols need adjusting. */
6339 long adjust = opd->adjust[OPD_NDX (symval)];
6345 if (opd_entry_value (sym->section, symval,
6346 &sec, code_off, TRUE) == (bfd_vma) -1)
6348 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6349 symbol. This size has nothing to do with the code size of the
6350 function, which is what we're supposed to return, but the
6351 code size isn't available without looking up the dot-sym.
6352 However, doing that would be a waste of time particularly
6353 since elf_find_function will look at the dot-sym anyway.
6354 Now, elf_find_function will keep the largest size of any
6355 function sym found at the code address of interest, so return
6356 1 here to avoid it incorrectly caching a larger function size
6357 for a small function. This does mean we return the wrong
6358 size for a new-ABI function of size 24, but all that does is
6359 disable caching for such functions. */
6365 if (sym->section != sec)
6367 *code_off = sym->value;
6374 /* Return true if symbol is a strong function defined in an ELFv2
6375 object with st_other localentry bits of zero, ie. its local entry
6376 point coincides with its global entry point. */
6379 is_elfv2_localentry0 (struct elf_link_hash_entry *h)
6382 && h->type == STT_FUNC
6383 && h->root.type == bfd_link_hash_defined
6384 && (STO_PPC64_LOCAL_MASK & h->other) == 0
6385 && !((struct ppc_link_hash_entry *) h)->non_zero_localentry
6386 && is_ppc64_elf (h->root.u.def.section->owner)
6387 && abiversion (h->root.u.def.section->owner) >= 2);
6390 /* Return true if symbol is defined in a regular object file. */
6393 is_static_defined (struct elf_link_hash_entry *h)
6395 return ((h->root.type == bfd_link_hash_defined
6396 || h->root.type == bfd_link_hash_defweak)
6397 && h->root.u.def.section != NULL
6398 && h->root.u.def.section->output_section != NULL);
6401 /* If FDH is a function descriptor symbol, return the associated code
6402 entry symbol if it is defined. Return NULL otherwise. */
6404 static struct ppc_link_hash_entry *
6405 defined_code_entry (struct ppc_link_hash_entry *fdh)
6407 if (fdh->is_func_descriptor)
6409 struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh);
6410 if (fh->elf.root.type == bfd_link_hash_defined
6411 || fh->elf.root.type == bfd_link_hash_defweak)
6417 /* If FH is a function code entry symbol, return the associated
6418 function descriptor symbol if it is defined. Return NULL otherwise. */
6420 static struct ppc_link_hash_entry *
6421 defined_func_desc (struct ppc_link_hash_entry *fh)
6424 && fh->oh->is_func_descriptor)
6426 struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh);
6427 if (fdh->elf.root.type == bfd_link_hash_defined
6428 || fdh->elf.root.type == bfd_link_hash_defweak)
6434 static bfd_boolean func_desc_adjust (struct elf_link_hash_entry *, void *);
6436 /* Garbage collect sections, after first dealing with dot-symbols. */
6439 ppc64_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
6441 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6443 if (htab != NULL && htab->need_func_desc_adj)
6445 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
6446 htab->need_func_desc_adj = 0;
6448 return bfd_elf_gc_sections (abfd, info);
6451 /* Mark all our entry sym sections, both opd and code section. */
6454 ppc64_elf_gc_keep (struct bfd_link_info *info)
6456 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6457 struct bfd_sym_chain *sym;
6462 for (sym = info->gc_sym_list; sym != NULL; sym = sym->next)
6464 struct ppc_link_hash_entry *eh, *fh;
6467 eh = (struct ppc_link_hash_entry *)
6468 elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
6471 if (eh->elf.root.type != bfd_link_hash_defined
6472 && eh->elf.root.type != bfd_link_hash_defweak)
6475 fh = defined_code_entry (eh);
6478 sec = fh->elf.root.u.def.section;
6479 sec->flags |= SEC_KEEP;
6481 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6482 && opd_entry_value (eh->elf.root.u.def.section,
6483 eh->elf.root.u.def.value,
6484 &sec, NULL, FALSE) != (bfd_vma) -1)
6485 sec->flags |= SEC_KEEP;
6487 sec = eh->elf.root.u.def.section;
6488 sec->flags |= SEC_KEEP;
6492 /* Mark sections containing dynamically referenced symbols. When
6493 building shared libraries, we must assume that any visible symbol is
6497 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
6499 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6500 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
6501 struct ppc_link_hash_entry *fdh;
6502 struct bfd_elf_dynamic_list *d = info->dynamic_list;
6504 /* Dynamic linking info is on the func descriptor sym. */
6505 fdh = defined_func_desc (eh);
6509 if ((eh->elf.root.type == bfd_link_hash_defined
6510 || eh->elf.root.type == bfd_link_hash_defweak)
6511 && ((eh->elf.ref_dynamic && !eh->elf.forced_local)
6512 || ((eh->elf.def_regular || ELF_COMMON_DEF_P (&eh->elf))
6513 && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
6514 && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN
6515 && (!bfd_link_executable (info)
6516 || info->gc_keep_exported
6517 || info->export_dynamic
6520 && (*d->match) (&d->head, NULL, eh->elf.root.root.string)))
6521 && (eh->elf.versioned >= versioned
6522 || !bfd_hide_sym_by_version (info->version_info,
6523 eh->elf.root.root.string)))))
6526 struct ppc_link_hash_entry *fh;
6528 eh->elf.root.u.def.section->flags |= SEC_KEEP;
6530 /* Function descriptor syms cause the associated
6531 function code sym section to be marked. */
6532 fh = defined_code_entry (eh);
6535 code_sec = fh->elf.root.u.def.section;
6536 code_sec->flags |= SEC_KEEP;
6538 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6539 && opd_entry_value (eh->elf.root.u.def.section,
6540 eh->elf.root.u.def.value,
6541 &code_sec, NULL, FALSE) != (bfd_vma) -1)
6542 code_sec->flags |= SEC_KEEP;
6548 /* Return the section that should be marked against GC for a given
6552 ppc64_elf_gc_mark_hook (asection *sec,
6553 struct bfd_link_info *info,
6554 Elf_Internal_Rela *rel,
6555 struct elf_link_hash_entry *h,
6556 Elf_Internal_Sym *sym)
6560 /* Syms return NULL if we're marking .opd, so we avoid marking all
6561 function sections, as all functions are referenced in .opd. */
6563 if (get_opd_info (sec) != NULL)
6568 enum elf_ppc64_reloc_type r_type;
6569 struct ppc_link_hash_entry *eh, *fh, *fdh;
6571 r_type = ELF64_R_TYPE (rel->r_info);
6574 case R_PPC64_GNU_VTINHERIT:
6575 case R_PPC64_GNU_VTENTRY:
6579 switch (h->root.type)
6581 case bfd_link_hash_defined:
6582 case bfd_link_hash_defweak:
6583 eh = (struct ppc_link_hash_entry *) h;
6584 fdh = defined_func_desc (eh);
6587 /* -mcall-aixdesc code references the dot-symbol on
6588 a call reloc. Mark the function descriptor too
6589 against garbage collection. */
6591 if (fdh->elf.is_weakalias)
6592 weakdef (&fdh->elf)->mark = 1;
6596 /* Function descriptor syms cause the associated
6597 function code sym section to be marked. */
6598 fh = defined_code_entry (eh);
6601 /* They also mark their opd section. */
6602 eh->elf.root.u.def.section->gc_mark = 1;
6604 rsec = fh->elf.root.u.def.section;
6606 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6607 && opd_entry_value (eh->elf.root.u.def.section,
6608 eh->elf.root.u.def.value,
6609 &rsec, NULL, FALSE) != (bfd_vma) -1)
6610 eh->elf.root.u.def.section->gc_mark = 1;
6612 rsec = h->root.u.def.section;
6615 case bfd_link_hash_common:
6616 rsec = h->root.u.c.p->section;
6620 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
6626 struct _opd_sec_data *opd;
6628 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
6629 opd = get_opd_info (rsec);
6630 if (opd != NULL && opd->func_sec != NULL)
6634 rsec = opd->func_sec[OPD_NDX (sym->st_value + rel->r_addend)];
6641 /* The maximum size of .sfpr. */
6642 #define SFPR_MAX (218*4)
6644 struct sfpr_def_parms
6646 const char name[12];
6647 unsigned char lo, hi;
6648 bfd_byte * (*write_ent) (bfd *, bfd_byte *, int);
6649 bfd_byte * (*write_tail) (bfd *, bfd_byte *, int);
6652 /* Auto-generate _save*, _rest* functions in .sfpr.
6653 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6657 sfpr_define (struct bfd_link_info *info,
6658 const struct sfpr_def_parms *parm,
6661 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6663 size_t len = strlen (parm->name);
6664 bfd_boolean writing = FALSE;
6670 memcpy (sym, parm->name, len);
6673 for (i = parm->lo; i <= parm->hi; i++)
6675 struct ppc_link_hash_entry *h;
6677 sym[len + 0] = i / 10 + '0';
6678 sym[len + 1] = i % 10 + '0';
6679 h = (struct ppc_link_hash_entry *)
6680 elf_link_hash_lookup (&htab->elf, sym, writing, TRUE, TRUE);
6681 if (stub_sec != NULL)
6684 && h->elf.root.type == bfd_link_hash_defined
6685 && h->elf.root.u.def.section == htab->sfpr)
6687 struct elf_link_hash_entry *s;
6689 sprintf (buf, "%08x.%s", stub_sec->id & 0xffffffff, sym);
6690 s = elf_link_hash_lookup (&htab->elf, buf, TRUE, TRUE, FALSE);
6693 if (s->root.type == bfd_link_hash_new
6694 || (s->root.type = bfd_link_hash_defined
6695 && s->root.u.def.section == stub_sec))
6697 s->root.type = bfd_link_hash_defined;
6698 s->root.u.def.section = stub_sec;
6699 s->root.u.def.value = (stub_sec->size - htab->sfpr->size
6700 + h->elf.root.u.def.value);
6703 s->ref_regular_nonweak = 1;
6704 s->forced_local = 1;
6706 s->root.linker_def = 1;
6714 if (!h->elf.def_regular)
6716 h->elf.root.type = bfd_link_hash_defined;
6717 h->elf.root.u.def.section = htab->sfpr;
6718 h->elf.root.u.def.value = htab->sfpr->size;
6719 h->elf.type = STT_FUNC;
6720 h->elf.def_regular = 1;
6722 _bfd_elf_link_hash_hide_symbol (info, &h->elf, TRUE);
6724 if (htab->sfpr->contents == NULL)
6726 htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
6727 if (htab->sfpr->contents == NULL)
6734 bfd_byte *p = htab->sfpr->contents + htab->sfpr->size;
6736 p = (*parm->write_ent) (htab->elf.dynobj, p, i);
6738 p = (*parm->write_tail) (htab->elf.dynobj, p, i);
6739 htab->sfpr->size = p - htab->sfpr->contents;
6747 savegpr0 (bfd *abfd, bfd_byte *p, int r)
6749 bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6754 savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
6756 p = savegpr0 (abfd, p, r);
6757 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6759 bfd_put_32 (abfd, BLR, p);
6764 restgpr0 (bfd *abfd, bfd_byte *p, int r)
6766 bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6771 restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
6773 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6775 p = restgpr0 (abfd, p, r);
6776 bfd_put_32 (abfd, MTLR_R0, p);
6780 p = restgpr0 (abfd, p, 30);
6781 p = restgpr0 (abfd, p, 31);
6783 bfd_put_32 (abfd, BLR, p);
6788 savegpr1 (bfd *abfd, bfd_byte *p, int r)
6790 bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6795 savegpr1_tail (bfd *abfd, bfd_byte *p, int r)
6797 p = savegpr1 (abfd, p, r);
6798 bfd_put_32 (abfd, BLR, p);
6803 restgpr1 (bfd *abfd, bfd_byte *p, int r)
6805 bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6810 restgpr1_tail (bfd *abfd, bfd_byte *p, int r)
6812 p = restgpr1 (abfd, p, r);
6813 bfd_put_32 (abfd, BLR, p);
6818 savefpr (bfd *abfd, bfd_byte *p, int r)
6820 bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6825 savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
6827 p = savefpr (abfd, p, r);
6828 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6830 bfd_put_32 (abfd, BLR, p);
6835 restfpr (bfd *abfd, bfd_byte *p, int r)
6837 bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6842 restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
6844 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6846 p = restfpr (abfd, p, r);
6847 bfd_put_32 (abfd, MTLR_R0, p);
6851 p = restfpr (abfd, p, 30);
6852 p = restfpr (abfd, p, 31);
6854 bfd_put_32 (abfd, BLR, p);
6859 savefpr1_tail (bfd *abfd, bfd_byte *p, int r)
6861 p = savefpr (abfd, p, r);
6862 bfd_put_32 (abfd, BLR, p);
6867 restfpr1_tail (bfd *abfd, bfd_byte *p, int r)
6869 p = restfpr (abfd, p, r);
6870 bfd_put_32 (abfd, BLR, p);
6875 savevr (bfd *abfd, bfd_byte *p, int r)
6877 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6879 bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p);
6884 savevr_tail (bfd *abfd, bfd_byte *p, int r)
6886 p = savevr (abfd, p, r);
6887 bfd_put_32 (abfd, BLR, p);
6892 restvr (bfd *abfd, bfd_byte *p, int r)
6894 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6896 bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p);
6901 restvr_tail (bfd *abfd, bfd_byte *p, int r)
6903 p = restvr (abfd, p, r);
6904 bfd_put_32 (abfd, BLR, p);
6908 /* Called via elf_link_hash_traverse to transfer dynamic linking
6909 information on function code symbol entries to their corresponding
6910 function descriptor symbol entries. */
6913 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
6915 struct bfd_link_info *info;
6916 struct ppc_link_hash_table *htab;
6917 struct ppc_link_hash_entry *fh;
6918 struct ppc_link_hash_entry *fdh;
6919 bfd_boolean force_local;
6921 fh = (struct ppc_link_hash_entry *) h;
6922 if (fh->elf.root.type == bfd_link_hash_indirect)
6928 if (fh->elf.root.root.string[0] != '.'
6929 || fh->elf.root.root.string[1] == '\0')
6933 htab = ppc_hash_table (info);
6937 /* Find the corresponding function descriptor symbol. */
6938 fdh = lookup_fdh (fh, htab);
6940 /* Resolve undefined references to dot-symbols as the value
6941 in the function descriptor, if we have one in a regular object.
6942 This is to satisfy cases like ".quad .foo". Calls to functions
6943 in dynamic objects are handled elsewhere. */
6944 if ((fh->elf.root.type == bfd_link_hash_undefined
6945 || fh->elf.root.type == bfd_link_hash_undefweak)
6946 && (fdh->elf.root.type == bfd_link_hash_defined
6947 || fdh->elf.root.type == bfd_link_hash_defweak)
6948 && get_opd_info (fdh->elf.root.u.def.section) != NULL
6949 && opd_entry_value (fdh->elf.root.u.def.section,
6950 fdh->elf.root.u.def.value,
6951 &fh->elf.root.u.def.section,
6952 &fh->elf.root.u.def.value, FALSE) != (bfd_vma) -1)
6954 fh->elf.root.type = fdh->elf.root.type;
6955 fh->elf.forced_local = 1;
6956 fh->elf.def_regular = fdh->elf.def_regular;
6957 fh->elf.def_dynamic = fdh->elf.def_dynamic;
6960 if (!fh->elf.dynamic)
6962 struct plt_entry *ent;
6964 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
6965 if (ent->plt.refcount > 0)
6971 /* Create a descriptor as undefined if necessary. */
6973 && !bfd_link_executable (info)
6974 && (fh->elf.root.type == bfd_link_hash_undefined
6975 || fh->elf.root.type == bfd_link_hash_undefweak))
6977 fdh = make_fdh (info, fh);
6982 /* We can't support overriding of symbols on a fake descriptor. */
6985 && (fh->elf.root.type == bfd_link_hash_defined
6986 || fh->elf.root.type == bfd_link_hash_defweak))
6987 _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
6989 /* Transfer dynamic linking information to the function descriptor. */
6992 fdh->elf.ref_regular |= fh->elf.ref_regular;
6993 fdh->elf.ref_dynamic |= fh->elf.ref_dynamic;
6994 fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak;
6995 fdh->elf.non_got_ref |= fh->elf.non_got_ref;
6996 fdh->elf.dynamic |= fh->elf.dynamic;
6997 fdh->elf.needs_plt |= (fh->elf.needs_plt
6998 || fh->elf.type == STT_FUNC
6999 || fh->elf.type == STT_GNU_IFUNC);
7000 move_plt_plist (fh, fdh);
7002 if (!fdh->elf.forced_local
7003 && fh->elf.dynindx != -1)
7004 if (!bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
7008 /* Now that the info is on the function descriptor, clear the
7009 function code sym info. Any function code syms for which we
7010 don't have a definition in a regular file, we force local.
7011 This prevents a shared library from exporting syms that have
7012 been imported from another library. Function code syms that
7013 are really in the library we must leave global to prevent the
7014 linker dragging in a definition from a static library. */
7015 force_local = (!fh->elf.def_regular
7017 || !fdh->elf.def_regular
7018 || fdh->elf.forced_local);
7019 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
7024 static const struct sfpr_def_parms save_res_funcs[] =
7026 { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail },
7027 { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail },
7028 { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail },
7029 { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail },
7030 { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail },
7031 { "_savefpr_", 14, 31, savefpr, savefpr0_tail },
7032 { "_restfpr_", 14, 29, restfpr, restfpr0_tail },
7033 { "_restfpr_", 30, 31, restfpr, restfpr0_tail },
7034 { "._savef", 14, 31, savefpr, savefpr1_tail },
7035 { "._restf", 14, 31, restfpr, restfpr1_tail },
7036 { "_savevr_", 20, 31, savevr, savevr_tail },
7037 { "_restvr_", 20, 31, restvr, restvr_tail }
7040 /* Called near the start of bfd_elf_size_dynamic_sections. We use
7041 this hook to a) provide some gcc support functions, and b) transfer
7042 dynamic linking information gathered so far on function code symbol
7043 entries, to their corresponding function descriptor symbol entries. */
7046 ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
7047 struct bfd_link_info *info)
7049 struct ppc_link_hash_table *htab;
7051 htab = ppc_hash_table (info);
7055 /* Provide any missing _save* and _rest* functions. */
7056 if (htab->sfpr != NULL)
7060 htab->sfpr->size = 0;
7061 for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
7062 if (!sfpr_define (info, &save_res_funcs[i], NULL))
7064 if (htab->sfpr->size == 0)
7065 htab->sfpr->flags |= SEC_EXCLUDE;
7068 if (bfd_link_relocatable (info))
7071 if (htab->elf.hgot != NULL)
7073 _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
7074 /* Make .TOC. defined so as to prevent it being made dynamic.
7075 The wrong value here is fixed later in ppc64_elf_set_toc. */
7076 if (!htab->elf.hgot->def_regular
7077 || htab->elf.hgot->root.type != bfd_link_hash_defined)
7079 htab->elf.hgot->root.type = bfd_link_hash_defined;
7080 htab->elf.hgot->root.u.def.value = 0;
7081 htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
7082 htab->elf.hgot->def_regular = 1;
7083 htab->elf.hgot->root.linker_def = 1;
7085 htab->elf.hgot->type = STT_OBJECT;
7086 htab->elf.hgot->other = ((htab->elf.hgot->other & ~ELF_ST_VISIBILITY (-1))
7090 if (htab->need_func_desc_adj)
7092 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
7093 htab->need_func_desc_adj = 0;
7099 /* Find dynamic relocs for H that apply to read-only sections. */
7102 readonly_dynrelocs (struct elf_link_hash_entry *h)
7104 struct ppc_link_hash_entry *eh;
7105 struct elf_dyn_relocs *p;
7107 eh = (struct ppc_link_hash_entry *) h;
7108 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7110 asection *s = p->sec->output_section;
7112 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7118 /* Return true if we have dynamic relocs against H or any of its weak
7119 aliases, that apply to read-only sections. Cannot be used after
7120 size_dynamic_sections. */
7123 alias_readonly_dynrelocs (struct elf_link_hash_entry *h)
7125 struct ppc_link_hash_entry *eh;
7127 eh = (struct ppc_link_hash_entry *) h;
7130 if (readonly_dynrelocs (&eh->elf))
7132 eh = (struct ppc_link_hash_entry *) eh->elf.u.alias;
7133 } while (eh != NULL && &eh->elf != h);
7138 /* Return whether EH has pc-relative dynamic relocs. */
7141 pc_dynrelocs (struct ppc_link_hash_entry *eh)
7143 struct elf_dyn_relocs *p;
7145 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7146 if (p->pc_count != 0)
7151 /* Return true if a global entry stub will be created for H. Valid
7152 for ELFv2 before plt entries have been allocated. */
7155 global_entry_stub (struct elf_link_hash_entry *h)
7157 struct plt_entry *pent;
7159 if (!h->pointer_equality_needed
7163 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
7164 if (pent->plt.refcount > 0
7165 && pent->addend == 0)
7171 /* Adjust a symbol defined by a dynamic object and referenced by a
7172 regular object. The current definition is in some section of the
7173 dynamic object, but we're not including those sections. We have to
7174 change the definition to something the rest of the link can
7178 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
7179 struct elf_link_hash_entry *h)
7181 struct ppc_link_hash_table *htab;
7184 htab = ppc_hash_table (info);
7188 /* Deal with function syms. */
7189 if (h->type == STT_FUNC
7190 || h->type == STT_GNU_IFUNC
7193 bfd_boolean local = (((struct ppc_link_hash_entry *) h)->save_res
7194 || SYMBOL_CALLS_LOCAL (info, h)
7195 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
7196 /* Discard dyn_relocs when non-pic if we've decided that a
7197 function symbol is local and not an ifunc. We keep dynamic
7198 relocs for ifuncs when local rather than always emitting a
7199 plt call stub for them and defining the symbol on the call
7200 stub. We can't do that for ELFv1 anyway (a function symbol
7201 is defined on a descriptor, not code) and it can be faster at
7202 run-time due to not needing to bounce through a stub. The
7203 dyn_relocs for ifuncs will be applied even in a static
7205 if (!bfd_link_pic (info)
7206 && h->type != STT_GNU_IFUNC
7208 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7210 /* Clear procedure linkage table information for any symbol that
7211 won't need a .plt entry. */
7212 struct plt_entry *ent;
7213 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
7214 if (ent->plt.refcount > 0)
7217 || (h->type != STT_GNU_IFUNC
7219 && (((struct ppc_link_hash_entry *) h)->tls_mask
7220 & (TLS_TLS | PLT_KEEP)) != PLT_KEEP))
7222 h->plt.plist = NULL;
7224 h->pointer_equality_needed = 0;
7226 else if (abiversion (info->output_bfd) >= 2)
7228 /* Taking a function's address in a read/write section
7229 doesn't require us to define the function symbol in the
7230 executable on a global entry stub. A dynamic reloc can
7231 be used instead. The reason we prefer a few more dynamic
7232 relocs is that calling via a global entry stub costs a
7233 few more instructions, and pointer_equality_needed causes
7234 extra work in ld.so when resolving these symbols. */
7235 if (global_entry_stub (h))
7237 if (!readonly_dynrelocs (h))
7239 h->pointer_equality_needed = 0;
7240 /* If we haven't seen a branch reloc then we don't need
7243 h->plt.plist = NULL;
7245 else if (!bfd_link_pic (info))
7246 /* We are going to be defining the function symbol on the
7247 plt stub, so no dyn_relocs needed when non-pic. */
7248 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7251 /* ELFv2 function symbols can't have copy relocs. */
7254 else if (!h->needs_plt
7255 && !readonly_dynrelocs (h))
7257 /* If we haven't seen a branch reloc then we don't need a
7259 h->plt.plist = NULL;
7260 h->pointer_equality_needed = 0;
7265 h->plt.plist = NULL;
7267 /* If this is a weak symbol, and there is a real definition, the
7268 processor independent code will have arranged for us to see the
7269 real definition first, and we can just use the same value. */
7270 if (h->is_weakalias)
7272 struct elf_link_hash_entry *def = weakdef (h);
7273 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
7274 h->root.u.def.section = def->root.u.def.section;
7275 h->root.u.def.value = def->root.u.def.value;
7276 if (def->root.u.def.section == htab->elf.sdynbss
7277 || def->root.u.def.section == htab->elf.sdynrelro)
7278 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7282 /* If we are creating a shared library, we must presume that the
7283 only references to the symbol are via the global offset table.
7284 For such cases we need not do anything here; the relocations will
7285 be handled correctly by relocate_section. */
7286 if (bfd_link_pic (info))
7289 /* If there are no references to this symbol that do not use the
7290 GOT, we don't need to generate a copy reloc. */
7291 if (!h->non_got_ref)
7294 /* Don't generate a copy reloc for symbols defined in the executable. */
7295 if (!h->def_dynamic || !h->ref_regular || h->def_regular
7297 /* If -z nocopyreloc was given, don't generate them either. */
7298 || info->nocopyreloc
7300 /* If we don't find any dynamic relocs in read-only sections, then
7301 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7302 || (ELIMINATE_COPY_RELOCS && !alias_readonly_dynrelocs (h))
7304 /* Protected variables do not work with .dynbss. The copy in
7305 .dynbss won't be used by the shared library with the protected
7306 definition for the variable. Text relocations are preferable
7307 to an incorrect program. */
7308 || h->protected_def)
7311 if (h->plt.plist != NULL)
7313 /* We should never get here, but unfortunately there are versions
7314 of gcc out there that improperly (for this ABI) put initialized
7315 function pointers, vtable refs and suchlike in read-only
7316 sections. Allow them to proceed, but warn that this might
7317 break at runtime. */
7318 info->callbacks->einfo
7319 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
7320 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7321 h->root.root.string);
7324 /* This is a reference to a symbol defined by a dynamic object which
7325 is not a function. */
7327 /* We must allocate the symbol in our .dynbss section, which will
7328 become part of the .bss section of the executable. There will be
7329 an entry for this symbol in the .dynsym section. The dynamic
7330 object will contain position independent code, so all references
7331 from the dynamic object to this symbol will go through the global
7332 offset table. The dynamic linker will use the .dynsym entry to
7333 determine the address it must put in the global offset table, so
7334 both the dynamic object and the regular object will refer to the
7335 same memory location for the variable. */
7336 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
7338 s = htab->elf.sdynrelro;
7339 srel = htab->elf.sreldynrelro;
7343 s = htab->elf.sdynbss;
7344 srel = htab->elf.srelbss;
7346 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
7348 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
7349 linker to copy the initial value out of the dynamic object
7350 and into the runtime process image. */
7351 srel->size += sizeof (Elf64_External_Rela);
7355 /* We no longer want dyn_relocs. */
7356 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7357 return _bfd_elf_adjust_dynamic_copy (info, h, s);
7360 /* If given a function descriptor symbol, hide both the function code
7361 sym and the descriptor. */
7363 ppc64_elf_hide_symbol (struct bfd_link_info *info,
7364 struct elf_link_hash_entry *h,
7365 bfd_boolean force_local)
7367 struct ppc_link_hash_entry *eh;
7368 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
7370 eh = (struct ppc_link_hash_entry *) h;
7371 if (eh->is_func_descriptor)
7373 struct ppc_link_hash_entry *fh = eh->oh;
7378 struct elf_link_hash_table *htab = elf_hash_table (info);
7381 /* We aren't supposed to use alloca in BFD because on
7382 systems which do not have alloca the version in libiberty
7383 calls xmalloc, which might cause the program to crash
7384 when it runs out of memory. This function doesn't have a
7385 return status, so there's no way to gracefully return an
7386 error. So cheat. We know that string[-1] can be safely
7387 accessed; It's either a string in an ELF string table,
7388 or allocated in an objalloc structure. */
7390 p = eh->elf.root.root.string - 1;
7393 fh = (struct ppc_link_hash_entry *)
7394 elf_link_hash_lookup (htab, p, FALSE, FALSE, FALSE);
7397 /* Unfortunately, if it so happens that the string we were
7398 looking for was allocated immediately before this string,
7399 then we overwrote the string terminator. That's the only
7400 reason the lookup should fail. */
7403 q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
7404 while (q >= eh->elf.root.root.string && *q == *p)
7406 if (q < eh->elf.root.root.string && *p == '.')
7407 fh = (struct ppc_link_hash_entry *)
7408 elf_link_hash_lookup (htab, p, FALSE, FALSE, FALSE);
7417 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
7422 get_sym_h (struct elf_link_hash_entry **hp,
7423 Elf_Internal_Sym **symp,
7425 unsigned char **tls_maskp,
7426 Elf_Internal_Sym **locsymsp,
7427 unsigned long r_symndx,
7430 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
7432 if (r_symndx >= symtab_hdr->sh_info)
7434 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
7435 struct elf_link_hash_entry *h;
7437 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7438 h = elf_follow_link (h);
7446 if (symsecp != NULL)
7448 asection *symsec = NULL;
7449 if (h->root.type == bfd_link_hash_defined
7450 || h->root.type == bfd_link_hash_defweak)
7451 symsec = h->root.u.def.section;
7455 if (tls_maskp != NULL)
7457 struct ppc_link_hash_entry *eh;
7459 eh = (struct ppc_link_hash_entry *) h;
7460 *tls_maskp = &eh->tls_mask;
7465 Elf_Internal_Sym *sym;
7466 Elf_Internal_Sym *locsyms = *locsymsp;
7468 if (locsyms == NULL)
7470 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
7471 if (locsyms == NULL)
7472 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
7473 symtab_hdr->sh_info,
7474 0, NULL, NULL, NULL);
7475 if (locsyms == NULL)
7477 *locsymsp = locsyms;
7479 sym = locsyms + r_symndx;
7487 if (symsecp != NULL)
7488 *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx);
7490 if (tls_maskp != NULL)
7492 struct got_entry **lgot_ents;
7493 unsigned char *tls_mask;
7496 lgot_ents = elf_local_got_ents (ibfd);
7497 if (lgot_ents != NULL)
7499 struct plt_entry **local_plt = (struct plt_entry **)
7500 (lgot_ents + symtab_hdr->sh_info);
7501 unsigned char *lgot_masks = (unsigned char *)
7502 (local_plt + symtab_hdr->sh_info);
7503 tls_mask = &lgot_masks[r_symndx];
7505 *tls_maskp = tls_mask;
7511 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7512 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7513 type suitable for optimization, and 1 otherwise. */
7516 get_tls_mask (unsigned char **tls_maskp,
7517 unsigned long *toc_symndx,
7518 bfd_vma *toc_addend,
7519 Elf_Internal_Sym **locsymsp,
7520 const Elf_Internal_Rela *rel,
7523 unsigned long r_symndx;
7525 struct elf_link_hash_entry *h;
7526 Elf_Internal_Sym *sym;
7530 r_symndx = ELF64_R_SYM (rel->r_info);
7531 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7534 if ((*tls_maskp != NULL
7535 && (**tls_maskp & TLS_TLS) != 0
7536 && **tls_maskp != (TLS_TLS | TLS_MARK))
7538 || ppc64_elf_section_data (sec) == NULL
7539 || ppc64_elf_section_data (sec)->sec_type != sec_toc)
7542 /* Look inside a TOC section too. */
7545 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
7546 off = h->root.u.def.value;
7549 off = sym->st_value;
7550 off += rel->r_addend;
7551 BFD_ASSERT (off % 8 == 0);
7552 r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8];
7553 next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1];
7554 if (toc_symndx != NULL)
7555 *toc_symndx = r_symndx;
7556 if (toc_addend != NULL)
7557 *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8];
7558 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7560 if ((h == NULL || is_static_defined (h))
7561 && (next_r == -1 || next_r == -2))
7566 /* Find (or create) an entry in the tocsave hash table. */
7568 static struct tocsave_entry *
7569 tocsave_find (struct ppc_link_hash_table *htab,
7570 enum insert_option insert,
7571 Elf_Internal_Sym **local_syms,
7572 const Elf_Internal_Rela *irela,
7575 unsigned long r_indx;
7576 struct elf_link_hash_entry *h;
7577 Elf_Internal_Sym *sym;
7578 struct tocsave_entry ent, *p;
7580 struct tocsave_entry **slot;
7582 r_indx = ELF64_R_SYM (irela->r_info);
7583 if (!get_sym_h (&h, &sym, &ent.sec, NULL, local_syms, r_indx, ibfd))
7585 if (ent.sec == NULL || ent.sec->output_section == NULL)
7588 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd);
7593 ent.offset = h->root.u.def.value;
7595 ent.offset = sym->st_value;
7596 ent.offset += irela->r_addend;
7598 hash = tocsave_htab_hash (&ent);
7599 slot = ((struct tocsave_entry **)
7600 htab_find_slot_with_hash (htab->tocsave_htab, &ent, hash, insert));
7606 p = (struct tocsave_entry *) bfd_alloc (ibfd, sizeof (*p));
7615 /* Adjust all global syms defined in opd sections. In gcc generated
7616 code for the old ABI, these will already have been done. */
7619 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
7621 struct ppc_link_hash_entry *eh;
7623 struct _opd_sec_data *opd;
7625 if (h->root.type == bfd_link_hash_indirect)
7628 if (h->root.type != bfd_link_hash_defined
7629 && h->root.type != bfd_link_hash_defweak)
7632 eh = (struct ppc_link_hash_entry *) h;
7633 if (eh->adjust_done)
7636 sym_sec = eh->elf.root.u.def.section;
7637 opd = get_opd_info (sym_sec);
7638 if (opd != NULL && opd->adjust != NULL)
7640 long adjust = opd->adjust[OPD_NDX (eh->elf.root.u.def.value)];
7643 /* This entry has been deleted. */
7644 asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section;
7647 for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next)
7648 if (discarded_section (dsec))
7650 ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec;
7654 eh->elf.root.u.def.value = 0;
7655 eh->elf.root.u.def.section = dsec;
7658 eh->elf.root.u.def.value += adjust;
7659 eh->adjust_done = 1;
7664 /* Handles decrementing dynamic reloc counts for the reloc specified by
7665 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7666 have already been determined. */
7669 dec_dynrel_count (bfd_vma r_info,
7671 struct bfd_link_info *info,
7672 Elf_Internal_Sym **local_syms,
7673 struct elf_link_hash_entry *h,
7674 Elf_Internal_Sym *sym)
7676 enum elf_ppc64_reloc_type r_type;
7677 asection *sym_sec = NULL;
7679 /* Can this reloc be dynamic? This switch, and later tests here
7680 should be kept in sync with the code in check_relocs. */
7681 r_type = ELF64_R_TYPE (r_info);
7687 case R_PPC64_TPREL16:
7688 case R_PPC64_TPREL16_LO:
7689 case R_PPC64_TPREL16_HI:
7690 case R_PPC64_TPREL16_HA:
7691 case R_PPC64_TPREL16_DS:
7692 case R_PPC64_TPREL16_LO_DS:
7693 case R_PPC64_TPREL16_HIGH:
7694 case R_PPC64_TPREL16_HIGHA:
7695 case R_PPC64_TPREL16_HIGHER:
7696 case R_PPC64_TPREL16_HIGHERA:
7697 case R_PPC64_TPREL16_HIGHEST:
7698 case R_PPC64_TPREL16_HIGHESTA:
7699 case R_PPC64_TPREL64:
7700 case R_PPC64_DTPMOD64:
7701 case R_PPC64_DTPREL64:
7702 case R_PPC64_ADDR64:
7706 case R_PPC64_ADDR14:
7707 case R_PPC64_ADDR14_BRNTAKEN:
7708 case R_PPC64_ADDR14_BRTAKEN:
7709 case R_PPC64_ADDR16:
7710 case R_PPC64_ADDR16_DS:
7711 case R_PPC64_ADDR16_HA:
7712 case R_PPC64_ADDR16_HI:
7713 case R_PPC64_ADDR16_HIGH:
7714 case R_PPC64_ADDR16_HIGHA:
7715 case R_PPC64_ADDR16_HIGHER:
7716 case R_PPC64_ADDR16_HIGHERA:
7717 case R_PPC64_ADDR16_HIGHEST:
7718 case R_PPC64_ADDR16_HIGHESTA:
7719 case R_PPC64_ADDR16_LO:
7720 case R_PPC64_ADDR16_LO_DS:
7721 case R_PPC64_ADDR24:
7722 case R_PPC64_ADDR32:
7723 case R_PPC64_UADDR16:
7724 case R_PPC64_UADDR32:
7725 case R_PPC64_UADDR64:
7730 if (local_syms != NULL)
7732 unsigned long r_symndx;
7733 bfd *ibfd = sec->owner;
7735 r_symndx = ELF64_R_SYM (r_info);
7736 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
7740 if ((bfd_link_pic (info)
7741 && (must_be_dyn_reloc (info, r_type)
7743 && (!SYMBOLIC_BIND (info, h)
7744 || h->root.type == bfd_link_hash_defweak
7745 || !h->def_regular))))
7746 || (ELIMINATE_COPY_RELOCS
7747 && !bfd_link_pic (info)
7749 && (h->root.type == bfd_link_hash_defweak
7750 || !h->def_regular)))
7757 struct elf_dyn_relocs *p;
7758 struct elf_dyn_relocs **pp;
7759 pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
7761 /* elf_gc_sweep may have already removed all dyn relocs associated
7762 with local syms for a given section. Also, symbol flags are
7763 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7764 report a dynreloc miscount. */
7765 if (*pp == NULL && info->gc_sections)
7768 while ((p = *pp) != NULL)
7772 if (!must_be_dyn_reloc (info, r_type))
7784 struct ppc_dyn_relocs *p;
7785 struct ppc_dyn_relocs **pp;
7787 bfd_boolean is_ifunc;
7789 if (local_syms == NULL)
7790 sym_sec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
7791 if (sym_sec == NULL)
7794 vpp = &elf_section_data (sym_sec)->local_dynrel;
7795 pp = (struct ppc_dyn_relocs **) vpp;
7797 if (*pp == NULL && info->gc_sections)
7800 is_ifunc = ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC;
7801 while ((p = *pp) != NULL)
7803 if (p->sec == sec && p->ifunc == is_ifunc)
7814 /* xgettext:c-format */
7815 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7817 bfd_set_error (bfd_error_bad_value);
7821 /* Remove unused Official Procedure Descriptor entries. Currently we
7822 only remove those associated with functions in discarded link-once
7823 sections, or weakly defined functions that have been overridden. It
7824 would be possible to remove many more entries for statically linked
7828 ppc64_elf_edit_opd (struct bfd_link_info *info)
7831 bfd_boolean some_edited = FALSE;
7832 asection *need_pad = NULL;
7833 struct ppc_link_hash_table *htab;
7835 htab = ppc_hash_table (info);
7839 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7842 Elf_Internal_Rela *relstart, *rel, *relend;
7843 Elf_Internal_Shdr *symtab_hdr;
7844 Elf_Internal_Sym *local_syms;
7845 struct _opd_sec_data *opd;
7846 bfd_boolean need_edit, add_aux_fields, broken;
7847 bfd_size_type cnt_16b = 0;
7849 if (!is_ppc64_elf (ibfd))
7852 sec = bfd_get_section_by_name (ibfd, ".opd");
7853 if (sec == NULL || sec->size == 0)
7856 if (sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
7859 if (sec->output_section == bfd_abs_section_ptr)
7862 /* Look through the section relocs. */
7863 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
7867 symtab_hdr = &elf_symtab_hdr (ibfd);
7869 /* Read the relocations. */
7870 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
7872 if (relstart == NULL)
7875 /* First run through the relocs to check they are sane, and to
7876 determine whether we need to edit this opd section. */
7880 relend = relstart + sec->reloc_count;
7881 for (rel = relstart; rel < relend; )
7883 enum elf_ppc64_reloc_type r_type;
7884 unsigned long r_symndx;
7886 struct elf_link_hash_entry *h;
7887 Elf_Internal_Sym *sym;
7890 /* .opd contains an array of 16 or 24 byte entries. We're
7891 only interested in the reloc pointing to a function entry
7893 offset = rel->r_offset;
7894 if (rel + 1 == relend
7895 || rel[1].r_offset != offset + 8)
7897 /* If someone messes with .opd alignment then after a
7898 "ld -r" we might have padding in the middle of .opd.
7899 Also, there's nothing to prevent someone putting
7900 something silly in .opd with the assembler. No .opd
7901 optimization for them! */
7904 (_("%pB: .opd is not a regular array of opd entries"), ibfd);
7909 if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
7910 || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
7913 /* xgettext:c-format */
7914 (_("%pB: unexpected reloc type %u in .opd section"),
7920 r_symndx = ELF64_R_SYM (rel->r_info);
7921 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7925 if (sym_sec == NULL || sym_sec->owner == NULL)
7927 const char *sym_name;
7929 sym_name = h->root.root.string;
7931 sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym,
7935 /* xgettext:c-format */
7936 (_("%pB: undefined sym `%s' in .opd section"),
7942 /* opd entries are always for functions defined in the
7943 current input bfd. If the symbol isn't defined in the
7944 input bfd, then we won't be using the function in this
7945 bfd; It must be defined in a linkonce section in another
7946 bfd, or is weak. It's also possible that we are
7947 discarding the function due to a linker script /DISCARD/,
7948 which we test for via the output_section. */
7949 if (sym_sec->owner != ibfd
7950 || sym_sec->output_section == bfd_abs_section_ptr)
7954 if (rel + 1 == relend
7955 || (rel + 2 < relend
7956 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC))
7961 if (sec->size == offset + 24)
7966 if (sec->size == offset + 16)
7973 else if (rel + 1 < relend
7974 && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64
7975 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC)
7977 if (rel[0].r_offset == offset + 16)
7979 else if (rel[0].r_offset != offset + 24)
7986 add_aux_fields = htab->params->non_overlapping_opd && cnt_16b > 0;
7988 if (!broken && (need_edit || add_aux_fields))
7990 Elf_Internal_Rela *write_rel;
7991 Elf_Internal_Shdr *rel_hdr;
7992 bfd_byte *rptr, *wptr;
7993 bfd_byte *new_contents;
7996 new_contents = NULL;
7997 amt = OPD_NDX (sec->size) * sizeof (long);
7998 opd = &ppc64_elf_section_data (sec)->u.opd;
7999 opd->adjust = bfd_zalloc (sec->owner, amt);
8000 if (opd->adjust == NULL)
8003 /* This seems a waste of time as input .opd sections are all
8004 zeros as generated by gcc, but I suppose there's no reason
8005 this will always be so. We might start putting something in
8006 the third word of .opd entries. */
8007 if ((sec->flags & SEC_IN_MEMORY) == 0)
8010 if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
8015 if (local_syms != NULL
8016 && symtab_hdr->contents != (unsigned char *) local_syms)
8018 if (elf_section_data (sec)->relocs != relstart)
8022 sec->contents = loc;
8023 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
8026 elf_section_data (sec)->relocs = relstart;
8028 new_contents = sec->contents;
8031 new_contents = bfd_malloc (sec->size + cnt_16b * 8);
8032 if (new_contents == NULL)
8036 wptr = new_contents;
8037 rptr = sec->contents;
8038 write_rel = relstart;
8039 for (rel = relstart; rel < relend; )
8041 unsigned long r_symndx;
8043 struct elf_link_hash_entry *h;
8044 struct ppc_link_hash_entry *fdh = NULL;
8045 Elf_Internal_Sym *sym;
8047 Elf_Internal_Rela *next_rel;
8050 r_symndx = ELF64_R_SYM (rel->r_info);
8051 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8056 if (next_rel + 1 == relend
8057 || (next_rel + 2 < relend
8058 && ELF64_R_TYPE (next_rel[2].r_info) == R_PPC64_TOC))
8061 /* See if the .opd entry is full 24 byte or
8062 16 byte (with fd_aux entry overlapped with next
8065 if (next_rel == relend)
8067 if (sec->size == rel->r_offset + 16)
8070 else if (next_rel->r_offset == rel->r_offset + 16)
8074 && h->root.root.string[0] == '.')
8076 fdh = ((struct ppc_link_hash_entry *) h)->oh;
8079 fdh = ppc_follow_link (fdh);
8080 if (fdh->elf.root.type != bfd_link_hash_defined
8081 && fdh->elf.root.type != bfd_link_hash_defweak)
8086 skip = (sym_sec->owner != ibfd
8087 || sym_sec->output_section == bfd_abs_section_ptr);
8090 if (fdh != NULL && sym_sec->owner == ibfd)
8092 /* Arrange for the function descriptor sym
8094 fdh->elf.root.u.def.value = 0;
8095 fdh->elf.root.u.def.section = sym_sec;
8097 opd->adjust[OPD_NDX (rel->r_offset)] = -1;
8099 if (NO_OPD_RELOCS || bfd_link_relocatable (info))
8104 if (!dec_dynrel_count (rel->r_info, sec, info,
8108 if (++rel == next_rel)
8111 r_symndx = ELF64_R_SYM (rel->r_info);
8112 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8119 /* We'll be keeping this opd entry. */
8124 /* Redefine the function descriptor symbol to
8125 this location in the opd section. It is
8126 necessary to update the value here rather
8127 than using an array of adjustments as we do
8128 for local symbols, because various places
8129 in the generic ELF code use the value
8130 stored in u.def.value. */
8131 fdh->elf.root.u.def.value = wptr - new_contents;
8132 fdh->adjust_done = 1;
8135 /* Local syms are a bit tricky. We could
8136 tweak them as they can be cached, but
8137 we'd need to look through the local syms
8138 for the function descriptor sym which we
8139 don't have at the moment. So keep an
8140 array of adjustments. */
8141 adjust = (wptr - new_contents) - (rptr - sec->contents);
8142 opd->adjust[OPD_NDX (rel->r_offset)] = adjust;
8145 memcpy (wptr, rptr, opd_ent_size);
8146 wptr += opd_ent_size;
8147 if (add_aux_fields && opd_ent_size == 16)
8149 memset (wptr, '\0', 8);
8153 /* We need to adjust any reloc offsets to point to the
8155 for ( ; rel != next_rel; ++rel)
8157 rel->r_offset += adjust;
8158 if (write_rel != rel)
8159 memcpy (write_rel, rel, sizeof (*rel));
8164 rptr += opd_ent_size;
8167 sec->size = wptr - new_contents;
8168 sec->reloc_count = write_rel - relstart;
8171 free (sec->contents);
8172 sec->contents = new_contents;
8175 /* Fudge the header size too, as this is used later in
8176 elf_bfd_final_link if we are emitting relocs. */
8177 rel_hdr = _bfd_elf_single_rel_hdr (sec);
8178 rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize;
8181 else if (elf_section_data (sec)->relocs != relstart)
8184 if (local_syms != NULL
8185 && symtab_hdr->contents != (unsigned char *) local_syms)
8187 if (!info->keep_memory)
8190 symtab_hdr->contents = (unsigned char *) local_syms;
8195 elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
8197 /* If we are doing a final link and the last .opd entry is just 16 byte
8198 long, add a 8 byte padding after it. */
8199 if (need_pad != NULL && !bfd_link_relocatable (info))
8203 if ((need_pad->flags & SEC_IN_MEMORY) == 0)
8205 BFD_ASSERT (need_pad->size > 0);
8207 p = bfd_malloc (need_pad->size + 8);
8211 if (! bfd_get_section_contents (need_pad->owner, need_pad,
8212 p, 0, need_pad->size))
8215 need_pad->contents = p;
8216 need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
8220 p = bfd_realloc (need_pad->contents, need_pad->size + 8);
8224 need_pad->contents = p;
8227 memset (need_pad->contents + need_pad->size, 0, 8);
8228 need_pad->size += 8;
8234 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8237 ppc64_elf_tls_setup (struct bfd_link_info *info)
8239 struct ppc_link_hash_table *htab;
8241 htab = ppc_hash_table (info);
8245 if (abiversion (info->output_bfd) == 1)
8248 if (htab->params->no_multi_toc)
8249 htab->do_multi_toc = 0;
8250 else if (!htab->do_multi_toc)
8251 htab->params->no_multi_toc = 1;
8253 /* Default to --no-plt-localentry, as this option can cause problems
8254 with symbol interposition. For example, glibc libpthread.so and
8255 libc.so duplicate many pthread symbols, with a fallback
8256 implementation in libc.so. In some cases the fallback does more
8257 work than the pthread implementation. __pthread_condattr_destroy
8258 is one such symbol: the libpthread.so implementation is
8259 localentry:0 while the libc.so implementation is localentry:8.
8260 An app that "cleverly" uses dlopen to only load necessary
8261 libraries at runtime may omit loading libpthread.so when not
8262 running multi-threaded, which then results in the libc.so
8263 fallback symbols being used and ld.so complaining. Now there
8264 are workarounds in ld (see non_zero_localentry) to detect the
8265 pthread situation, but that may not be the only case where
8266 --plt-localentry can cause trouble. */
8267 if (htab->params->plt_localentry0 < 0)
8268 htab->params->plt_localentry0 = 0;
8269 if (htab->params->plt_localentry0
8270 && elf_link_hash_lookup (&htab->elf, "GLIBC_2.26",
8271 FALSE, FALSE, FALSE) == NULL)
8273 (_("warning: --plt-localentry is especially dangerous without "
8274 "ld.so support to detect ABI violations"));
8276 htab->tls_get_addr = ((struct ppc_link_hash_entry *)
8277 elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
8278 FALSE, FALSE, TRUE));
8279 /* Move dynamic linking info to the function descriptor sym. */
8280 if (htab->tls_get_addr != NULL)
8281 func_desc_adjust (&htab->tls_get_addr->elf, info);
8282 htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
8283 elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
8284 FALSE, FALSE, TRUE));
8285 if (htab->params->tls_get_addr_opt)
8287 struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
8289 opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
8290 FALSE, FALSE, TRUE);
8292 func_desc_adjust (opt, info);
8293 opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
8294 FALSE, FALSE, TRUE);
8296 && (opt_fd->root.type == bfd_link_hash_defined
8297 || opt_fd->root.type == bfd_link_hash_defweak))
8299 /* If glibc supports an optimized __tls_get_addr call stub,
8300 signalled by the presence of __tls_get_addr_opt, and we'll
8301 be calling __tls_get_addr via a plt call stub, then
8302 make __tls_get_addr point to __tls_get_addr_opt. */
8303 tga_fd = &htab->tls_get_addr_fd->elf;
8304 if (htab->elf.dynamic_sections_created
8306 && (tga_fd->type == STT_FUNC
8307 || tga_fd->needs_plt)
8308 && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
8309 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, tga_fd)))
8311 struct plt_entry *ent;
8313 for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
8314 if (ent->plt.refcount > 0)
8318 tga_fd->root.type = bfd_link_hash_indirect;
8319 tga_fd->root.u.i.link = &opt_fd->root;
8320 ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
8322 if (opt_fd->dynindx != -1)
8324 /* Use __tls_get_addr_opt in dynamic relocations. */
8325 opt_fd->dynindx = -1;
8326 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
8327 opt_fd->dynstr_index);
8328 if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
8331 htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd;
8332 tga = &htab->tls_get_addr->elf;
8333 if (opt != NULL && tga != NULL)
8335 tga->root.type = bfd_link_hash_indirect;
8336 tga->root.u.i.link = &opt->root;
8337 ppc64_elf_copy_indirect_symbol (info, opt, tga);
8339 _bfd_elf_link_hash_hide_symbol (info, opt,
8341 htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
8343 htab->tls_get_addr_fd->oh = htab->tls_get_addr;
8344 htab->tls_get_addr_fd->is_func_descriptor = 1;
8345 if (htab->tls_get_addr != NULL)
8347 htab->tls_get_addr->oh = htab->tls_get_addr_fd;
8348 htab->tls_get_addr->is_func = 1;
8353 else if (htab->params->tls_get_addr_opt < 0)
8354 htab->params->tls_get_addr_opt = 0;
8356 return _bfd_elf_tls_setup (info->output_bfd, info);
8359 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8363 branch_reloc_hash_match (const bfd *ibfd,
8364 const Elf_Internal_Rela *rel,
8365 const struct ppc_link_hash_entry *hash1,
8366 const struct ppc_link_hash_entry *hash2)
8368 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
8369 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
8370 unsigned int r_symndx = ELF64_R_SYM (rel->r_info);
8372 if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
8374 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
8375 struct elf_link_hash_entry *h;
8377 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
8378 h = elf_follow_link (h);
8379 if (h == &hash1->elf || h == &hash2->elf)
8385 /* Run through all the TLS relocs looking for optimization
8386 opportunities. The linker has been hacked (see ppc64elf.em) to do
8387 a preliminary section layout so that we know the TLS segment
8388 offsets. We can't optimize earlier because some optimizations need
8389 to know the tp offset, and we need to optimize before allocating
8390 dynamic relocations. */
8393 ppc64_elf_tls_optimize (struct bfd_link_info *info)
8397 struct ppc_link_hash_table *htab;
8398 unsigned char *toc_ref;
8401 if (!bfd_link_executable (info))
8404 htab = ppc_hash_table (info);
8408 /* Make two passes over the relocs. On the first pass, mark toc
8409 entries involved with tls relocs, and check that tls relocs
8410 involved in setting up a tls_get_addr call are indeed followed by
8411 such a call. If they are not, we can't do any tls optimization.
8412 On the second pass twiddle tls_mask flags to notify
8413 relocate_section that optimization can be done, and adjust got
8414 and plt refcounts. */
8416 for (pass = 0; pass < 2; ++pass)
8417 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8419 Elf_Internal_Sym *locsyms = NULL;
8420 asection *toc = bfd_get_section_by_name (ibfd, ".toc");
8422 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8423 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
8425 Elf_Internal_Rela *relstart, *rel, *relend;
8426 bfd_boolean found_tls_get_addr_arg = 0;
8428 /* Read the relocations. */
8429 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8431 if (relstart == NULL)
8437 relend = relstart + sec->reloc_count;
8438 for (rel = relstart; rel < relend; rel++)
8440 enum elf_ppc64_reloc_type r_type;
8441 unsigned long r_symndx;
8442 struct elf_link_hash_entry *h;
8443 Elf_Internal_Sym *sym;
8445 unsigned char *tls_mask;
8446 unsigned char tls_set, tls_clear, tls_type = 0;
8448 bfd_boolean ok_tprel, is_local;
8449 long toc_ref_index = 0;
8450 int expecting_tls_get_addr = 0;
8451 bfd_boolean ret = FALSE;
8453 r_symndx = ELF64_R_SYM (rel->r_info);
8454 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
8458 if (elf_section_data (sec)->relocs != relstart)
8460 if (toc_ref != NULL)
8463 && (elf_symtab_hdr (ibfd).contents
8464 != (unsigned char *) locsyms))
8471 if (h->root.type == bfd_link_hash_defined
8472 || h->root.type == bfd_link_hash_defweak)
8473 value = h->root.u.def.value;
8474 else if (h->root.type == bfd_link_hash_undefweak)
8478 found_tls_get_addr_arg = 0;
8483 /* Symbols referenced by TLS relocs must be of type
8484 STT_TLS. So no need for .opd local sym adjust. */
8485 value = sym->st_value;
8494 && h->root.type == bfd_link_hash_undefweak)
8496 else if (sym_sec != NULL
8497 && sym_sec->output_section != NULL)
8499 value += sym_sec->output_offset;
8500 value += sym_sec->output_section->vma;
8501 value -= htab->elf.tls_sec->vma;
8502 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
8503 < (bfd_vma) 1 << 32);
8507 r_type = ELF64_R_TYPE (rel->r_info);
8508 /* If this section has old-style __tls_get_addr calls
8509 without marker relocs, then check that each
8510 __tls_get_addr call reloc is preceded by a reloc
8511 that conceivably belongs to the __tls_get_addr arg
8512 setup insn. If we don't find matching arg setup
8513 relocs, don't do any tls optimization. */
8515 && sec->has_tls_get_addr_call
8517 && (h == &htab->tls_get_addr->elf
8518 || h == &htab->tls_get_addr_fd->elf)
8519 && !found_tls_get_addr_arg
8520 && is_branch_reloc (r_type))
8522 info->callbacks->minfo (_("%H __tls_get_addr lost arg, "
8523 "TLS optimization disabled\n"),
8524 ibfd, sec, rel->r_offset);
8529 found_tls_get_addr_arg = 0;
8532 case R_PPC64_GOT_TLSLD16:
8533 case R_PPC64_GOT_TLSLD16_LO:
8534 expecting_tls_get_addr = 1;
8535 found_tls_get_addr_arg = 1;
8538 case R_PPC64_GOT_TLSLD16_HI:
8539 case R_PPC64_GOT_TLSLD16_HA:
8540 /* These relocs should never be against a symbol
8541 defined in a shared lib. Leave them alone if
8542 that turns out to be the case. */
8549 tls_type = TLS_TLS | TLS_LD;
8552 case R_PPC64_GOT_TLSGD16:
8553 case R_PPC64_GOT_TLSGD16_LO:
8554 expecting_tls_get_addr = 1;
8555 found_tls_get_addr_arg = 1;
8558 case R_PPC64_GOT_TLSGD16_HI:
8559 case R_PPC64_GOT_TLSGD16_HA:
8565 tls_set = TLS_TLS | TLS_TPRELGD;
8567 tls_type = TLS_TLS | TLS_GD;
8570 case R_PPC64_GOT_TPREL16_DS:
8571 case R_PPC64_GOT_TPREL16_LO_DS:
8572 case R_PPC64_GOT_TPREL16_HI:
8573 case R_PPC64_GOT_TPREL16_HA:
8578 tls_clear = TLS_TPREL;
8579 tls_type = TLS_TLS | TLS_TPREL;
8586 found_tls_get_addr_arg = 1;
8591 case R_PPC64_TOC16_LO:
8592 if (sym_sec == NULL || sym_sec != toc)
8595 /* Mark this toc entry as referenced by a TLS
8596 code sequence. We can do that now in the
8597 case of R_PPC64_TLS, and after checking for
8598 tls_get_addr for the TOC16 relocs. */
8599 if (toc_ref == NULL)
8600 toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8);
8601 if (toc_ref == NULL)
8605 value = h->root.u.def.value;
8607 value = sym->st_value;
8608 value += rel->r_addend;
8611 BFD_ASSERT (value < toc->size
8612 && toc->output_offset % 8 == 0);
8613 toc_ref_index = (value + toc->output_offset) / 8;
8614 if (r_type == R_PPC64_TLS
8615 || r_type == R_PPC64_TLSGD
8616 || r_type == R_PPC64_TLSLD)
8618 toc_ref[toc_ref_index] = 1;
8622 if (pass != 0 && toc_ref[toc_ref_index] == 0)
8627 expecting_tls_get_addr = 2;
8630 case R_PPC64_TPREL64:
8634 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8639 tls_set = TLS_EXPLICIT;
8640 tls_clear = TLS_TPREL;
8645 case R_PPC64_DTPMOD64:
8649 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8651 if (rel + 1 < relend
8653 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
8654 && rel[1].r_offset == rel->r_offset + 8)
8658 tls_set = TLS_EXPLICIT | TLS_GD;
8661 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
8670 tls_set = TLS_EXPLICIT;
8681 if (!expecting_tls_get_addr
8682 || !sec->has_tls_get_addr_call)
8685 if (rel + 1 < relend
8686 && branch_reloc_hash_match (ibfd, rel + 1,
8688 htab->tls_get_addr_fd))
8690 if (expecting_tls_get_addr == 2)
8692 /* Check for toc tls entries. */
8693 unsigned char *toc_tls;
8696 retval = get_tls_mask (&toc_tls, NULL, NULL,
8701 if (toc_tls != NULL)
8703 if ((*toc_tls & TLS_TLS) != 0
8704 && ((*toc_tls & (TLS_GD | TLS_LD)) != 0))
8705 found_tls_get_addr_arg = 1;
8707 toc_ref[toc_ref_index] = 1;
8713 /* Uh oh, we didn't find the expected call. We
8714 could just mark this symbol to exclude it
8715 from tls optimization but it's safer to skip
8716 the entire optimization. */
8717 /* xgettext:c-format */
8718 info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
8719 "TLS optimization disabled\n"),
8720 ibfd, sec, rel->r_offset);
8725 /* If we don't have old-style __tls_get_addr calls
8726 without TLSGD/TLSLD marker relocs, and we haven't
8727 found a new-style __tls_get_addr call with a
8728 marker for this symbol, then we either have a
8729 broken object file or an -mlongcall style
8730 indirect call to __tls_get_addr without a marker.
8731 Disable optimization in this case. */
8732 if ((tls_clear & (TLS_GD | TLS_LD)) != 0
8733 && (tls_set & TLS_EXPLICIT) == 0
8734 && !sec->has_tls_get_addr_call
8735 && ((*tls_mask & (TLS_TLS | TLS_MARK))
8736 != (TLS_TLS | TLS_MARK)))
8739 if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
8741 struct plt_entry *ent;
8742 for (ent = htab->tls_get_addr->elf.plt.plist;
8745 if (ent->addend == 0)
8747 if (ent->plt.refcount > 0)
8749 ent->plt.refcount -= 1;
8750 expecting_tls_get_addr = 0;
8756 if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL)
8758 struct plt_entry *ent;
8759 for (ent = htab->tls_get_addr_fd->elf.plt.plist;
8762 if (ent->addend == 0)
8764 if (ent->plt.refcount > 0)
8765 ent->plt.refcount -= 1;
8773 if ((tls_set & TLS_EXPLICIT) == 0)
8775 struct got_entry *ent;
8777 /* Adjust got entry for this reloc. */
8781 ent = elf_local_got_ents (ibfd)[r_symndx];
8783 for (; ent != NULL; ent = ent->next)
8784 if (ent->addend == rel->r_addend
8785 && ent->owner == ibfd
8786 && ent->tls_type == tls_type)
8793 /* We managed to get rid of a got entry. */
8794 if (ent->got.refcount > 0)
8795 ent->got.refcount -= 1;
8800 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8801 we'll lose one or two dyn relocs. */
8802 if (!dec_dynrel_count (rel->r_info, sec, info,
8806 if (tls_set == (TLS_EXPLICIT | TLS_GD))
8808 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
8814 *tls_mask |= tls_set;
8815 *tls_mask &= ~tls_clear;
8818 if (elf_section_data (sec)->relocs != relstart)
8823 && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
8825 if (!info->keep_memory)
8828 elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
8832 if (toc_ref != NULL)
8834 htab->do_tls_opt = 1;
8838 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8839 the values of any global symbols in a toc section that has been
8840 edited. Globals in toc sections should be a rarity, so this function
8841 sets a flag if any are found in toc sections other than the one just
8842 edited, so that further hash table traversals can be avoided. */
8844 struct adjust_toc_info
8847 unsigned long *skip;
8848 bfd_boolean global_toc_syms;
8851 enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 };
8854 adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
8856 struct ppc_link_hash_entry *eh;
8857 struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf;
8860 if (h->root.type != bfd_link_hash_defined
8861 && h->root.type != bfd_link_hash_defweak)
8864 eh = (struct ppc_link_hash_entry *) h;
8865 if (eh->adjust_done)
8868 if (eh->elf.root.u.def.section == toc_inf->toc)
8870 if (eh->elf.root.u.def.value > toc_inf->toc->rawsize)
8871 i = toc_inf->toc->rawsize >> 3;
8873 i = eh->elf.root.u.def.value >> 3;
8875 if ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0)
8878 (_("%s defined on removed toc entry"), eh->elf.root.root.string);
8881 while ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0);
8882 eh->elf.root.u.def.value = (bfd_vma) i << 3;
8885 eh->elf.root.u.def.value -= toc_inf->skip[i];
8886 eh->adjust_done = 1;
8888 else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
8889 toc_inf->global_toc_syms = TRUE;
8894 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8895 on a _LO variety toc/got reloc. */
8898 ok_lo_toc_insn (unsigned int insn, enum elf_ppc64_reloc_type r_type)
8900 return ((insn & (0x3f << 26)) == 12u << 26 /* addic */
8901 || (insn & (0x3f << 26)) == 14u << 26 /* addi */
8902 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
8903 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
8904 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
8905 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
8906 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
8907 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
8908 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
8909 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
8910 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
8911 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
8912 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
8913 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
8914 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
8915 || (insn & (0x3f << 26)) == 56u << 26 /* lq,lfq */
8916 || ((insn & (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8917 /* Exclude lfqu by testing reloc. If relocs are ever
8918 defined for the reduced D field in psq_lu then those
8919 will need testing too. */
8920 && r_type != R_PPC64_TOC16_LO && r_type != R_PPC64_GOT16_LO)
8921 || ((insn & (0x3f << 26)) == 58u << 26 /* ld,lwa */
8923 || (insn & (0x3f << 26)) == 60u << 26 /* stfq */
8924 || ((insn & (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8925 /* Exclude stfqu. psq_stu as above for psq_lu. */
8926 && r_type != R_PPC64_TOC16_LO && r_type != R_PPC64_GOT16_LO)
8927 || ((insn & (0x3f << 26)) == 62u << 26 /* std,stq */
8928 && (insn & 1) == 0));
8931 /* Examine all relocs referencing .toc sections in order to remove
8932 unused .toc entries. */
8935 ppc64_elf_edit_toc (struct bfd_link_info *info)
8938 struct adjust_toc_info toc_inf;
8939 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8941 htab->do_toc_opt = 1;
8942 toc_inf.global_toc_syms = TRUE;
8943 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8945 asection *toc, *sec;
8946 Elf_Internal_Shdr *symtab_hdr;
8947 Elf_Internal_Sym *local_syms;
8948 Elf_Internal_Rela *relstart, *rel, *toc_relocs;
8949 unsigned long *skip, *drop;
8950 unsigned char *used;
8951 unsigned char *keep, last, some_unused;
8953 if (!is_ppc64_elf (ibfd))
8956 toc = bfd_get_section_by_name (ibfd, ".toc");
8959 || toc->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
8960 || discarded_section (toc))
8965 symtab_hdr = &elf_symtab_hdr (ibfd);
8967 /* Look at sections dropped from the final link. */
8970 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8972 if (sec->reloc_count == 0
8973 || !discarded_section (sec)
8974 || get_opd_info (sec)
8975 || (sec->flags & SEC_ALLOC) == 0
8976 || (sec->flags & SEC_DEBUGGING) != 0)
8979 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
8980 if (relstart == NULL)
8983 /* Run through the relocs to see which toc entries might be
8985 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8987 enum elf_ppc64_reloc_type r_type;
8988 unsigned long r_symndx;
8990 struct elf_link_hash_entry *h;
8991 Elf_Internal_Sym *sym;
8994 r_type = ELF64_R_TYPE (rel->r_info);
9001 case R_PPC64_TOC16_LO:
9002 case R_PPC64_TOC16_HI:
9003 case R_PPC64_TOC16_HA:
9004 case R_PPC64_TOC16_DS:
9005 case R_PPC64_TOC16_LO_DS:
9009 r_symndx = ELF64_R_SYM (rel->r_info);
9010 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9018 val = h->root.u.def.value;
9020 val = sym->st_value;
9021 val += rel->r_addend;
9023 if (val >= toc->size)
9026 /* Anything in the toc ought to be aligned to 8 bytes.
9027 If not, don't mark as unused. */
9033 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
9038 skip[val >> 3] = ref_from_discarded;
9041 if (elf_section_data (sec)->relocs != relstart)
9045 /* For largetoc loads of address constants, we can convert
9046 . addis rx,2,addr@got@ha
9047 . ld ry,addr@got@l(rx)
9049 . addis rx,2,addr@toc@ha
9050 . addi ry,rx,addr@toc@l
9051 when addr is within 2G of the toc pointer. This then means
9052 that the word storing "addr" in the toc is no longer needed. */
9054 if (!ppc64_elf_tdata (ibfd)->has_small_toc_reloc
9055 && toc->output_section->rawsize < (bfd_vma) 1 << 31
9056 && toc->reloc_count != 0)
9058 /* Read toc relocs. */
9059 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
9061 if (toc_relocs == NULL)
9064 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
9066 enum elf_ppc64_reloc_type r_type;
9067 unsigned long r_symndx;
9069 struct elf_link_hash_entry *h;
9070 Elf_Internal_Sym *sym;
9073 r_type = ELF64_R_TYPE (rel->r_info);
9074 if (r_type != R_PPC64_ADDR64)
9077 r_symndx = ELF64_R_SYM (rel->r_info);
9078 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9083 || sym_sec->output_section == NULL
9084 || discarded_section (sym_sec))
9087 if (!SYMBOL_REFERENCES_LOCAL (info, h))
9092 if (h->type == STT_GNU_IFUNC)
9094 val = h->root.u.def.value;
9098 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
9100 val = sym->st_value;
9102 val += rel->r_addend;
9103 val += sym_sec->output_section->vma + sym_sec->output_offset;
9105 /* We don't yet know the exact toc pointer value, but we
9106 know it will be somewhere in the toc section. Don't
9107 optimize if the difference from any possible toc
9108 pointer is outside [ff..f80008000, 7fff7fff]. */
9109 addr = toc->output_section->vma + TOC_BASE_OFF;
9110 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
9113 addr = toc->output_section->vma + toc->output_section->rawsize;
9114 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
9119 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
9124 skip[rel->r_offset >> 3]
9125 |= can_optimize | ((rel - toc_relocs) << 2);
9132 used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8);
9136 if (local_syms != NULL
9137 && symtab_hdr->contents != (unsigned char *) local_syms)
9141 && elf_section_data (sec)->relocs != relstart)
9143 if (toc_relocs != NULL
9144 && elf_section_data (toc)->relocs != toc_relocs)
9151 /* Now check all kept sections that might reference the toc.
9152 Check the toc itself last. */
9153 for (sec = (ibfd->sections == toc && toc->next ? toc->next
9156 sec = (sec == toc ? NULL
9157 : sec->next == NULL ? toc
9158 : sec->next == toc && toc->next ? toc->next
9163 if (sec->reloc_count == 0
9164 || discarded_section (sec)
9165 || get_opd_info (sec)
9166 || (sec->flags & SEC_ALLOC) == 0
9167 || (sec->flags & SEC_DEBUGGING) != 0)
9170 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
9172 if (relstart == NULL)
9178 /* Mark toc entries referenced as used. */
9182 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
9184 enum elf_ppc64_reloc_type r_type;
9185 unsigned long r_symndx;
9187 struct elf_link_hash_entry *h;
9188 Elf_Internal_Sym *sym;
9190 enum {no_check, check_lo, check_ha} insn_check;
9192 r_type = ELF64_R_TYPE (rel->r_info);
9196 insn_check = no_check;
9199 case R_PPC64_GOT_TLSLD16_HA:
9200 case R_PPC64_GOT_TLSGD16_HA:
9201 case R_PPC64_GOT_TPREL16_HA:
9202 case R_PPC64_GOT_DTPREL16_HA:
9203 case R_PPC64_GOT16_HA:
9204 case R_PPC64_TOC16_HA:
9205 insn_check = check_ha;
9208 case R_PPC64_GOT_TLSLD16_LO:
9209 case R_PPC64_GOT_TLSGD16_LO:
9210 case R_PPC64_GOT_TPREL16_LO_DS:
9211 case R_PPC64_GOT_DTPREL16_LO_DS:
9212 case R_PPC64_GOT16_LO:
9213 case R_PPC64_GOT16_LO_DS:
9214 case R_PPC64_TOC16_LO:
9215 case R_PPC64_TOC16_LO_DS:
9216 insn_check = check_lo;
9220 if (insn_check != no_check)
9222 bfd_vma off = rel->r_offset & ~3;
9223 unsigned char buf[4];
9226 if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
9231 insn = bfd_get_32 (ibfd, buf);
9232 if (insn_check == check_lo
9233 ? !ok_lo_toc_insn (insn, r_type)
9234 : ((insn & ((0x3f << 26) | 0x1f << 16))
9235 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9239 ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
9240 sprintf (str, "%#08x", insn);
9241 info->callbacks->einfo
9242 /* xgettext:c-format */
9243 (_("%H: toc optimization is not supported for"
9244 " %s instruction\n"),
9245 ibfd, sec, rel->r_offset & ~3, str);
9252 case R_PPC64_TOC16_LO:
9253 case R_PPC64_TOC16_HI:
9254 case R_PPC64_TOC16_HA:
9255 case R_PPC64_TOC16_DS:
9256 case R_PPC64_TOC16_LO_DS:
9257 /* In case we're taking addresses of toc entries. */
9258 case R_PPC64_ADDR64:
9265 r_symndx = ELF64_R_SYM (rel->r_info);
9266 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9277 val = h->root.u.def.value;
9279 val = sym->st_value;
9280 val += rel->r_addend;
9282 if (val >= toc->size)
9285 if ((skip[val >> 3] & can_optimize) != 0)
9292 case R_PPC64_TOC16_HA:
9295 case R_PPC64_TOC16_LO_DS:
9296 off = rel->r_offset;
9297 off += (bfd_big_endian (ibfd) ? -2 : 3);
9298 if (!bfd_get_section_contents (ibfd, sec, &opc,
9304 if ((opc & (0x3f << 2)) == (58u << 2))
9309 /* Wrong sort of reloc, or not a ld. We may
9310 as well clear ref_from_discarded too. */
9317 /* For the toc section, we only mark as used if this
9318 entry itself isn't unused. */
9319 else if ((used[rel->r_offset >> 3]
9320 || !(skip[rel->r_offset >> 3] & ref_from_discarded))
9323 /* Do all the relocs again, to catch reference
9332 if (elf_section_data (sec)->relocs != relstart)
9336 /* Merge the used and skip arrays. Assume that TOC
9337 doublewords not appearing as either used or unused belong
9338 to an entry more than one doubleword in size. */
9339 for (drop = skip, keep = used, last = 0, some_unused = 0;
9340 drop < skip + (toc->size + 7) / 8;
9345 *drop &= ~ref_from_discarded;
9346 if ((*drop & can_optimize) != 0)
9350 else if ((*drop & ref_from_discarded) != 0)
9353 last = ref_from_discarded;
9363 bfd_byte *contents, *src;
9365 Elf_Internal_Sym *sym;
9366 bfd_boolean local_toc_syms = FALSE;
9368 /* Shuffle the toc contents, and at the same time convert the
9369 skip array from booleans into offsets. */
9370 if (!bfd_malloc_and_get_section (ibfd, toc, &contents))
9373 elf_section_data (toc)->this_hdr.contents = contents;
9375 for (src = contents, off = 0, drop = skip;
9376 src < contents + toc->size;
9379 if ((*drop & (can_optimize | ref_from_discarded)) != 0)
9384 memcpy (src - off, src, 8);
9388 toc->rawsize = toc->size;
9389 toc->size = src - contents - off;
9391 /* Adjust addends for relocs against the toc section sym,
9392 and optimize any accesses we can. */
9393 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
9395 if (sec->reloc_count == 0
9396 || discarded_section (sec))
9399 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
9401 if (relstart == NULL)
9404 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
9406 enum elf_ppc64_reloc_type r_type;
9407 unsigned long r_symndx;
9409 struct elf_link_hash_entry *h;
9412 r_type = ELF64_R_TYPE (rel->r_info);
9419 case R_PPC64_TOC16_LO:
9420 case R_PPC64_TOC16_HI:
9421 case R_PPC64_TOC16_HA:
9422 case R_PPC64_TOC16_DS:
9423 case R_PPC64_TOC16_LO_DS:
9424 case R_PPC64_ADDR64:
9428 r_symndx = ELF64_R_SYM (rel->r_info);
9429 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9437 val = h->root.u.def.value;
9440 val = sym->st_value;
9442 local_toc_syms = TRUE;
9445 val += rel->r_addend;
9447 if (val > toc->rawsize)
9449 else if ((skip[val >> 3] & ref_from_discarded) != 0)
9451 else if ((skip[val >> 3] & can_optimize) != 0)
9453 Elf_Internal_Rela *tocrel
9454 = toc_relocs + (skip[val >> 3] >> 2);
9455 unsigned long tsym = ELF64_R_SYM (tocrel->r_info);
9459 case R_PPC64_TOC16_HA:
9460 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_TOC16_HA);
9463 case R_PPC64_TOC16_LO_DS:
9464 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_LO_DS_OPT);
9468 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
9470 info->callbacks->einfo
9471 /* xgettext:c-format */
9472 (_("%H: %s references "
9473 "optimized away TOC entry\n"),
9474 ibfd, sec, rel->r_offset,
9475 ppc64_elf_howto_table[r_type]->name);
9476 bfd_set_error (bfd_error_bad_value);
9479 rel->r_addend = tocrel->r_addend;
9480 elf_section_data (sec)->relocs = relstart;
9484 if (h != NULL || sym->st_value != 0)
9487 rel->r_addend -= skip[val >> 3];
9488 elf_section_data (sec)->relocs = relstart;
9491 if (elf_section_data (sec)->relocs != relstart)
9495 /* We shouldn't have local or global symbols defined in the TOC,
9496 but handle them anyway. */
9497 if (local_syms != NULL)
9498 for (sym = local_syms;
9499 sym < local_syms + symtab_hdr->sh_info;
9501 if (sym->st_value != 0
9502 && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc)
9506 if (sym->st_value > toc->rawsize)
9507 i = toc->rawsize >> 3;
9509 i = sym->st_value >> 3;
9511 if ((skip[i] & (ref_from_discarded | can_optimize)) != 0)
9515 (_("%s defined on removed toc entry"),
9516 bfd_elf_sym_name (ibfd, symtab_hdr, sym, NULL));
9519 while ((skip[i] & (ref_from_discarded | can_optimize)));
9520 sym->st_value = (bfd_vma) i << 3;
9523 sym->st_value -= skip[i];
9524 symtab_hdr->contents = (unsigned char *) local_syms;
9527 /* Adjust any global syms defined in this toc input section. */
9528 if (toc_inf.global_toc_syms)
9531 toc_inf.skip = skip;
9532 toc_inf.global_toc_syms = FALSE;
9533 elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
9537 if (toc->reloc_count != 0)
9539 Elf_Internal_Shdr *rel_hdr;
9540 Elf_Internal_Rela *wrel;
9543 /* Remove unused toc relocs, and adjust those we keep. */
9544 if (toc_relocs == NULL)
9545 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
9547 if (toc_relocs == NULL)
9551 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
9552 if ((skip[rel->r_offset >> 3]
9553 & (ref_from_discarded | can_optimize)) == 0)
9555 wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3];
9556 wrel->r_info = rel->r_info;
9557 wrel->r_addend = rel->r_addend;
9560 else if (!dec_dynrel_count (rel->r_info, toc, info,
9561 &local_syms, NULL, NULL))
9564 elf_section_data (toc)->relocs = toc_relocs;
9565 toc->reloc_count = wrel - toc_relocs;
9566 rel_hdr = _bfd_elf_single_rel_hdr (toc);
9567 sz = rel_hdr->sh_entsize;
9568 rel_hdr->sh_size = toc->reloc_count * sz;
9571 else if (toc_relocs != NULL
9572 && elf_section_data (toc)->relocs != toc_relocs)
9575 if (local_syms != NULL
9576 && symtab_hdr->contents != (unsigned char *) local_syms)
9578 if (!info->keep_memory)
9581 symtab_hdr->contents = (unsigned char *) local_syms;
9589 /* Return true iff input section I references the TOC using
9590 instructions limited to +/-32k offsets. */
9593 ppc64_elf_has_small_toc_reloc (asection *i)
9595 return (is_ppc64_elf (i->owner)
9596 && ppc64_elf_tdata (i->owner)->has_small_toc_reloc);
9599 /* Allocate space for one GOT entry. */
9602 allocate_got (struct elf_link_hash_entry *h,
9603 struct bfd_link_info *info,
9604 struct got_entry *gent)
9606 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9607 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
9608 int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
9610 int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD
9611 ? 2 : 1) * sizeof (Elf64_External_Rela);
9612 asection *got = ppc64_elf_tdata (gent->owner)->got;
9614 gent->got.offset = got->size;
9615 got->size += entsize;
9617 if (h->type == STT_GNU_IFUNC)
9619 htab->elf.irelplt->size += rentsize;
9620 htab->got_reli_size += rentsize;
9622 else if (((bfd_link_pic (info)
9623 && !((gent->tls_type & TLS_TPREL) != 0
9624 && bfd_link_executable (info)
9625 && SYMBOL_REFERENCES_LOCAL (info, h)))
9626 || (htab->elf.dynamic_sections_created
9628 && !SYMBOL_REFERENCES_LOCAL (info, h)))
9629 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
9631 asection *relgot = ppc64_elf_tdata (gent->owner)->relgot;
9632 relgot->size += rentsize;
9636 /* This function merges got entries in the same toc group. */
9639 merge_got_entries (struct got_entry **pent)
9641 struct got_entry *ent, *ent2;
9643 for (ent = *pent; ent != NULL; ent = ent->next)
9644 if (!ent->is_indirect)
9645 for (ent2 = ent->next; ent2 != NULL; ent2 = ent2->next)
9646 if (!ent2->is_indirect
9647 && ent2->addend == ent->addend
9648 && ent2->tls_type == ent->tls_type
9649 && elf_gp (ent2->owner) == elf_gp (ent->owner))
9651 ent2->is_indirect = TRUE;
9652 ent2->got.ent = ent;
9656 /* If H is undefined, make it dynamic if that makes sense. */
9659 ensure_undef_dynamic (struct bfd_link_info *info,
9660 struct elf_link_hash_entry *h)
9662 struct elf_link_hash_table *htab = elf_hash_table (info);
9664 if (htab->dynamic_sections_created
9665 && ((info->dynamic_undefined_weak != 0
9666 && h->root.type == bfd_link_hash_undefweak)
9667 || h->root.type == bfd_link_hash_undefined)
9670 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
9671 return bfd_elf_link_record_dynamic_symbol (info, h);
9675 /* Allocate space in .plt, .got and associated reloc sections for
9679 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
9681 struct bfd_link_info *info;
9682 struct ppc_link_hash_table *htab;
9684 struct ppc_link_hash_entry *eh;
9685 struct got_entry **pgent, *gent;
9687 if (h->root.type == bfd_link_hash_indirect)
9690 info = (struct bfd_link_info *) inf;
9691 htab = ppc_hash_table (info);
9695 eh = (struct ppc_link_hash_entry *) h;
9696 /* Run through the TLS GD got entries first if we're changing them
9698 if ((eh->tls_mask & (TLS_TLS | TLS_TPRELGD)) == (TLS_TLS | TLS_TPRELGD))
9699 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9700 if (gent->got.refcount > 0
9701 && (gent->tls_type & TLS_GD) != 0)
9703 /* This was a GD entry that has been converted to TPREL. If
9704 there happens to be a TPREL entry we can use that one. */
9705 struct got_entry *ent;
9706 for (ent = h->got.glist; ent != NULL; ent = ent->next)
9707 if (ent->got.refcount > 0
9708 && (ent->tls_type & TLS_TPREL) != 0
9709 && ent->addend == gent->addend
9710 && ent->owner == gent->owner)
9712 gent->got.refcount = 0;
9716 /* If not, then we'll be using our own TPREL entry. */
9717 if (gent->got.refcount != 0)
9718 gent->tls_type = TLS_TLS | TLS_TPREL;
9721 /* Remove any list entry that won't generate a word in the GOT before
9722 we call merge_got_entries. Otherwise we risk merging to empty
9724 pgent = &h->got.glist;
9725 while ((gent = *pgent) != NULL)
9726 if (gent->got.refcount > 0)
9728 if ((gent->tls_type & TLS_LD) != 0
9731 ppc64_tlsld_got (gent->owner)->got.refcount += 1;
9732 *pgent = gent->next;
9735 pgent = &gent->next;
9738 *pgent = gent->next;
9740 if (!htab->do_multi_toc)
9741 merge_got_entries (&h->got.glist);
9743 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9744 if (!gent->is_indirect)
9746 /* Make sure this symbol is output as a dynamic symbol. */
9747 if (!ensure_undef_dynamic (info, h))
9750 if (!is_ppc64_elf (gent->owner))
9753 allocate_got (h, info, gent);
9756 /* If no dynamic sections we can't have dynamic relocs, except for
9757 IFUNCs which are handled even in static executables. */
9758 if (!htab->elf.dynamic_sections_created
9759 && h->type != STT_GNU_IFUNC)
9760 eh->dyn_relocs = NULL;
9762 /* Discard relocs on undefined symbols that must be local. */
9763 else if (h->root.type == bfd_link_hash_undefined
9764 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9765 eh->dyn_relocs = NULL;
9767 /* Also discard relocs on undefined weak syms with non-default
9768 visibility, or when dynamic_undefined_weak says so. */
9769 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
9770 eh->dyn_relocs = NULL;
9772 if (eh->dyn_relocs != NULL)
9774 struct elf_dyn_relocs *p, **pp;
9776 /* In the shared -Bsymbolic case, discard space allocated for
9777 dynamic pc-relative relocs against symbols which turn out to
9778 be defined in regular objects. For the normal shared case,
9779 discard space for relocs that have become local due to symbol
9780 visibility changes. */
9782 if (bfd_link_pic (info))
9784 /* Relocs that use pc_count are those that appear on a call
9785 insn, or certain REL relocs (see must_be_dyn_reloc) that
9786 can be generated via assembly. We want calls to
9787 protected symbols to resolve directly to the function
9788 rather than going via the plt. If people want function
9789 pointer comparisons to work as expected then they should
9790 avoid writing weird assembly. */
9791 if (SYMBOL_CALLS_LOCAL (info, h))
9793 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
9795 p->count -= p->pc_count;
9804 if (eh->dyn_relocs != NULL)
9806 /* Make sure this symbol is output as a dynamic symbol. */
9807 if (!ensure_undef_dynamic (info, h))
9811 else if (ELIMINATE_COPY_RELOCS && h->type != STT_GNU_IFUNC)
9813 /* For the non-pic case, discard space for relocs against
9814 symbols which turn out to need copy relocs or are not
9816 if (h->dynamic_adjusted
9818 && !ELF_COMMON_DEF_P (h))
9820 /* Make sure this symbol is output as a dynamic symbol. */
9821 if (!ensure_undef_dynamic (info, h))
9824 if (h->dynindx == -1)
9825 eh->dyn_relocs = NULL;
9828 eh->dyn_relocs = NULL;
9831 /* Finally, allocate space. */
9832 for (p = eh->dyn_relocs; p != NULL; p = p->next)
9834 asection *sreloc = elf_section_data (p->sec)->sreloc;
9835 if (eh->elf.type == STT_GNU_IFUNC)
9836 sreloc = htab->elf.irelplt;
9837 sreloc->size += p->count * sizeof (Elf64_External_Rela);
9841 /* We might need a PLT entry when the symbol
9844 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
9845 d) has plt16 relocs and we are linking statically. */
9846 if ((htab->elf.dynamic_sections_created && h->dynindx != -1)
9847 || h->type == STT_GNU_IFUNC
9848 || (h->needs_plt && h->dynamic_adjusted)
9851 && !htab->elf.dynamic_sections_created
9852 && (((struct ppc_link_hash_entry *) h)->tls_mask
9853 & (TLS_TLS | PLT_KEEP)) == PLT_KEEP))
9855 struct plt_entry *pent;
9856 bfd_boolean doneone = FALSE;
9857 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
9858 if (pent->plt.refcount > 0)
9860 if (!htab->elf.dynamic_sections_created
9861 || h->dynindx == -1)
9863 if (h->type == STT_GNU_IFUNC)
9866 pent->plt.offset = s->size;
9867 s->size += PLT_ENTRY_SIZE (htab);
9868 s = htab->elf.irelplt;
9873 pent->plt.offset = s->size;
9874 s->size += LOCAL_PLT_ENTRY_SIZE (htab);
9875 s = bfd_link_pic (info) ? htab->relpltlocal : NULL;
9880 /* If this is the first .plt entry, make room for the special
9884 s->size += PLT_INITIAL_ENTRY_SIZE (htab);
9886 pent->plt.offset = s->size;
9888 /* Make room for this entry. */
9889 s->size += PLT_ENTRY_SIZE (htab);
9891 /* Make room for the .glink code. */
9894 s->size += GLINK_PLTRESOLVE_SIZE (htab);
9897 /* We need bigger stubs past index 32767. */
9898 if (s->size >= GLINK_PLTRESOLVE_SIZE (htab) + 32768*2*4)
9905 /* We also need to make an entry in the .rela.plt section. */
9906 s = htab->elf.srelplt;
9909 s->size += sizeof (Elf64_External_Rela);
9913 pent->plt.offset = (bfd_vma) -1;
9916 h->plt.plist = NULL;
9922 h->plt.plist = NULL;
9929 #define PPC_LO(v) ((v) & 0xffff)
9930 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9931 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9933 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9934 to set up space for global entry stubs. These are put in glink,
9935 after the branch table. */
9938 size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
9940 struct bfd_link_info *info;
9941 struct ppc_link_hash_table *htab;
9942 struct plt_entry *pent;
9945 if (h->root.type == bfd_link_hash_indirect)
9948 if (!h->pointer_equality_needed)
9955 htab = ppc_hash_table (info);
9959 s = htab->global_entry;
9960 plt = htab->elf.splt;
9961 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
9962 if (pent->plt.offset != (bfd_vma) -1
9963 && pent->addend == 0)
9965 /* For ELFv2, if this symbol is not defined in a regular file
9966 and we are not generating a shared library or pie, then we
9967 need to define the symbol in the executable on a call stub.
9968 This is to avoid text relocations. */
9969 bfd_vma off, stub_align, stub_off, stub_size;
9970 unsigned int align_power;
9974 if (htab->params->plt_stub_align >= 0)
9975 align_power = htab->params->plt_stub_align;
9977 align_power = -htab->params->plt_stub_align;
9978 /* Setting section alignment is delayed until we know it is
9979 non-empty. Otherwise the .text output section will be
9980 aligned at least to plt_stub_align even when no global
9981 entry stubs are needed. */
9982 if (s->alignment_power < align_power)
9983 s->alignment_power = align_power;
9984 stub_align = (bfd_vma) 1 << align_power;
9985 if (htab->params->plt_stub_align >= 0
9986 || ((((stub_off + stub_size - 1) & -stub_align)
9987 - (stub_off & -stub_align))
9988 > ((stub_size - 1) & -stub_align)))
9989 stub_off = (stub_off + stub_align - 1) & -stub_align;
9990 off = pent->plt.offset + plt->output_offset + plt->output_section->vma;
9991 off -= stub_off + s->output_offset + s->output_section->vma;
9992 /* Note that for --plt-stub-align negative we have a possible
9993 dependency between stub offset and size. Break that
9994 dependency by assuming the max stub size when calculating
9996 if (PPC_HA (off) == 0)
9998 h->root.type = bfd_link_hash_defined;
9999 h->root.u.def.section = s;
10000 h->root.u.def.value = stub_off;
10001 s->size = stub_off + stub_size;
10007 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
10008 read-only sections. */
10011 maybe_set_textrel (struct elf_link_hash_entry *h, void *inf)
10015 if (h->root.type == bfd_link_hash_indirect)
10018 sec = readonly_dynrelocs (h);
10021 struct bfd_link_info *info = (struct bfd_link_info *) inf;
10023 info->flags |= DF_TEXTREL;
10024 info->callbacks->minfo
10025 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
10026 sec->owner, h->root.root.string, sec);
10028 /* Not an error, just cut short the traversal. */
10034 /* Set the sizes of the dynamic sections. */
10037 ppc64_elf_size_dynamic_sections (bfd *output_bfd,
10038 struct bfd_link_info *info)
10040 struct ppc_link_hash_table *htab;
10043 bfd_boolean relocs;
10045 struct got_entry *first_tlsld;
10047 htab = ppc_hash_table (info);
10051 dynobj = htab->elf.dynobj;
10052 if (dynobj == NULL)
10055 if (htab->elf.dynamic_sections_created)
10057 /* Set the contents of the .interp section to the interpreter. */
10058 if (bfd_link_executable (info) && !info->nointerp)
10060 s = bfd_get_linker_section (dynobj, ".interp");
10063 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
10064 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10068 /* Set up .got offsets for local syms, and space for local dynamic
10070 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
10072 struct got_entry **lgot_ents;
10073 struct got_entry **end_lgot_ents;
10074 struct plt_entry **local_plt;
10075 struct plt_entry **end_local_plt;
10076 unsigned char *lgot_masks;
10077 bfd_size_type locsymcount;
10078 Elf_Internal_Shdr *symtab_hdr;
10080 if (!is_ppc64_elf (ibfd))
10083 for (s = ibfd->sections; s != NULL; s = s->next)
10085 struct ppc_dyn_relocs *p;
10087 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10089 if (!bfd_is_abs_section (p->sec)
10090 && bfd_is_abs_section (p->sec->output_section))
10092 /* Input section has been discarded, either because
10093 it is a copy of a linkonce section or due to
10094 linker script /DISCARD/, so we'll be discarding
10097 else if (p->count != 0)
10099 asection *srel = elf_section_data (p->sec)->sreloc;
10101 srel = htab->elf.irelplt;
10102 srel->size += p->count * sizeof (Elf64_External_Rela);
10103 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
10104 info->flags |= DF_TEXTREL;
10109 lgot_ents = elf_local_got_ents (ibfd);
10113 symtab_hdr = &elf_symtab_hdr (ibfd);
10114 locsymcount = symtab_hdr->sh_info;
10115 end_lgot_ents = lgot_ents + locsymcount;
10116 local_plt = (struct plt_entry **) end_lgot_ents;
10117 end_local_plt = local_plt + locsymcount;
10118 lgot_masks = (unsigned char *) end_local_plt;
10119 s = ppc64_elf_tdata (ibfd)->got;
10120 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
10122 struct got_entry **pent, *ent;
10125 while ((ent = *pent) != NULL)
10126 if (ent->got.refcount > 0)
10128 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
10130 ppc64_tlsld_got (ibfd)->got.refcount += 1;
10135 unsigned int ent_size = 8;
10136 unsigned int rel_size = sizeof (Elf64_External_Rela);
10138 ent->got.offset = s->size;
10139 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
10144 s->size += ent_size;
10145 if ((*lgot_masks & (TLS_TLS | PLT_IFUNC)) == PLT_IFUNC)
10147 htab->elf.irelplt->size += rel_size;
10148 htab->got_reli_size += rel_size;
10150 else if (bfd_link_pic (info)
10151 && !((ent->tls_type & TLS_TPREL) != 0
10152 && bfd_link_executable (info)))
10154 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
10155 srel->size += rel_size;
10164 /* Allocate space for plt calls to local syms. */
10165 lgot_masks = (unsigned char *) end_local_plt;
10166 for (; local_plt < end_local_plt; ++local_plt, ++lgot_masks)
10168 struct plt_entry *ent;
10170 for (ent = *local_plt; ent != NULL; ent = ent->next)
10171 if (ent->plt.refcount > 0)
10173 if ((*lgot_masks & (TLS_TLS | PLT_IFUNC)) == PLT_IFUNC)
10175 s = htab->elf.iplt;
10176 ent->plt.offset = s->size;
10177 s->size += PLT_ENTRY_SIZE (htab);
10178 htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
10180 else if ((*lgot_masks & (TLS_TLS | PLT_KEEP)) != PLT_KEEP)
10181 ent->plt.offset = (bfd_vma) -1;
10184 s = htab->pltlocal;
10185 ent->plt.offset = s->size;
10186 s->size += LOCAL_PLT_ENTRY_SIZE (htab);
10187 if (bfd_link_pic (info))
10188 htab->relpltlocal->size += sizeof (Elf64_External_Rela);
10192 ent->plt.offset = (bfd_vma) -1;
10196 /* Allocate global sym .plt and .got entries, and space for global
10197 sym dynamic relocs. */
10198 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
10200 if (!htab->opd_abi && !bfd_link_pic (info))
10201 elf_link_hash_traverse (&htab->elf, size_global_entry_stubs, info);
10203 first_tlsld = NULL;
10204 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
10206 struct got_entry *ent;
10208 if (!is_ppc64_elf (ibfd))
10211 ent = ppc64_tlsld_got (ibfd);
10212 if (ent->got.refcount > 0)
10214 if (!htab->do_multi_toc && first_tlsld != NULL)
10216 ent->is_indirect = TRUE;
10217 ent->got.ent = first_tlsld;
10221 if (first_tlsld == NULL)
10223 s = ppc64_elf_tdata (ibfd)->got;
10224 ent->got.offset = s->size;
10227 if (bfd_link_pic (info))
10229 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
10230 srel->size += sizeof (Elf64_External_Rela);
10235 ent->got.offset = (bfd_vma) -1;
10238 /* We now have determined the sizes of the various dynamic sections.
10239 Allocate memory for them. */
10241 for (s = dynobj->sections; s != NULL; s = s->next)
10243 if ((s->flags & SEC_LINKER_CREATED) == 0)
10246 if (s == htab->brlt || s == htab->relbrlt)
10247 /* These haven't been allocated yet; don't strip. */
10249 else if (s == htab->elf.sgot
10250 || s == htab->elf.splt
10251 || s == htab->elf.iplt
10252 || s == htab->pltlocal
10253 || s == htab->glink
10254 || s == htab->global_entry
10255 || s == htab->elf.sdynbss
10256 || s == htab->elf.sdynrelro)
10258 /* Strip this section if we don't need it; see the
10261 else if (s == htab->glink_eh_frame)
10263 if (!bfd_is_abs_section (s->output_section))
10264 /* Not sized yet. */
10267 else if (CONST_STRNEQ (s->name, ".rela"))
10271 if (s != htab->elf.srelplt)
10274 /* We use the reloc_count field as a counter if we need
10275 to copy relocs into the output file. */
10276 s->reloc_count = 0;
10281 /* It's not one of our sections, so don't allocate space. */
10287 /* If we don't need this section, strip it from the
10288 output file. This is mostly to handle .rela.bss and
10289 .rela.plt. We must create both sections in
10290 create_dynamic_sections, because they must be created
10291 before the linker maps input sections to output
10292 sections. The linker does that before
10293 adjust_dynamic_symbol is called, and it is that
10294 function which decides whether anything needs to go
10295 into these sections. */
10296 s->flags |= SEC_EXCLUDE;
10300 if (bfd_is_abs_section (s->output_section))
10301 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10304 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10307 /* Allocate memory for the section contents. We use bfd_zalloc
10308 here in case unused entries are not reclaimed before the
10309 section's contents are written out. This should not happen,
10310 but this way if it does we get a R_PPC64_NONE reloc in .rela
10311 sections instead of garbage.
10312 We also rely on the section contents being zero when writing
10313 the GOT and .dynrelro. */
10314 s->contents = bfd_zalloc (dynobj, s->size);
10315 if (s->contents == NULL)
10319 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
10321 if (!is_ppc64_elf (ibfd))
10324 s = ppc64_elf_tdata (ibfd)->got;
10325 if (s != NULL && s != htab->elf.sgot)
10328 s->flags |= SEC_EXCLUDE;
10331 s->contents = bfd_zalloc (ibfd, s->size);
10332 if (s->contents == NULL)
10336 s = ppc64_elf_tdata (ibfd)->relgot;
10340 s->flags |= SEC_EXCLUDE;
10343 s->contents = bfd_zalloc (ibfd, s->size);
10344 if (s->contents == NULL)
10347 s->reloc_count = 0;
10352 if (htab->elf.dynamic_sections_created)
10354 bfd_boolean tls_opt;
10356 /* Add some entries to the .dynamic section. We fill in the
10357 values later, in ppc64_elf_finish_dynamic_sections, but we
10358 must add the entries now so that we get the correct size for
10359 the .dynamic section. The DT_DEBUG entry is filled in by the
10360 dynamic linker and used by the debugger. */
10361 #define add_dynamic_entry(TAG, VAL) \
10362 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10364 if (bfd_link_executable (info))
10366 if (!add_dynamic_entry (DT_DEBUG, 0))
10370 if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
10372 if (!add_dynamic_entry (DT_PLTGOT, 0)
10373 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10374 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
10375 || !add_dynamic_entry (DT_JMPREL, 0)
10376 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
10380 if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
10382 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
10383 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
10387 tls_opt = (htab->params->tls_get_addr_opt
10388 && htab->tls_get_addr_fd != NULL
10389 && htab->tls_get_addr_fd->elf.plt.plist != NULL);
10390 if (tls_opt || !htab->opd_abi)
10392 if (!add_dynamic_entry (DT_PPC64_OPT, tls_opt ? PPC64_OPT_TLS : 0))
10398 if (!add_dynamic_entry (DT_RELA, 0)
10399 || !add_dynamic_entry (DT_RELASZ, 0)
10400 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
10403 /* If any dynamic relocs apply to a read-only section,
10404 then we need a DT_TEXTREL entry. */
10405 if ((info->flags & DF_TEXTREL) == 0)
10406 elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
10408 if ((info->flags & DF_TEXTREL) != 0)
10410 if (!add_dynamic_entry (DT_TEXTREL, 0))
10415 #undef add_dynamic_entry
10420 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10423 ppc64_elf_hash_symbol (struct elf_link_hash_entry *h)
10425 if (h->plt.plist != NULL
10427 && !h->pointer_equality_needed)
10430 return _bfd_elf_hash_symbol (h);
10433 /* Determine the type of stub needed, if any, for a call. */
10435 static inline enum ppc_stub_type
10436 ppc_type_of_stub (asection *input_sec,
10437 const Elf_Internal_Rela *rel,
10438 struct ppc_link_hash_entry **hash,
10439 struct plt_entry **plt_ent,
10440 bfd_vma destination,
10441 unsigned long local_off)
10443 struct ppc_link_hash_entry *h = *hash;
10445 bfd_vma branch_offset;
10446 bfd_vma max_branch_offset;
10447 enum elf_ppc64_reloc_type r_type;
10451 struct plt_entry *ent;
10452 struct ppc_link_hash_entry *fdh = h;
10454 && h->oh->is_func_descriptor)
10456 fdh = ppc_follow_link (h->oh);
10460 for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
10461 if (ent->addend == rel->r_addend
10462 && ent->plt.offset != (bfd_vma) -1)
10465 return ppc_stub_plt_call;
10468 /* Here, we know we don't have a plt entry. If we don't have a
10469 either a defined function descriptor or a defined entry symbol
10470 in a regular object file, then it is pointless trying to make
10471 any other type of stub. */
10472 if (!is_static_defined (&fdh->elf)
10473 && !is_static_defined (&h->elf))
10474 return ppc_stub_none;
10476 else if (elf_local_got_ents (input_sec->owner) != NULL)
10478 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner);
10479 struct plt_entry **local_plt = (struct plt_entry **)
10480 elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info;
10481 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
10483 if (local_plt[r_symndx] != NULL)
10485 struct plt_entry *ent;
10487 for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next)
10488 if (ent->addend == rel->r_addend
10489 && ent->plt.offset != (bfd_vma) -1)
10492 return ppc_stub_plt_call;
10497 /* Determine where the call point is. */
10498 location = (input_sec->output_offset
10499 + input_sec->output_section->vma
10502 branch_offset = destination - location;
10503 r_type = ELF64_R_TYPE (rel->r_info);
10505 /* Determine if a long branch stub is needed. */
10506 max_branch_offset = 1 << 25;
10507 if (r_type != R_PPC64_REL24)
10508 max_branch_offset = 1 << 15;
10510 if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
10511 /* We need a stub. Figure out whether a long_branch or plt_branch
10512 is needed later. */
10513 return ppc_stub_long_branch;
10515 return ppc_stub_none;
10518 /* With power7 weakly ordered memory model, it is possible for ld.so
10519 to update a plt entry in one thread and have another thread see a
10520 stale zero toc entry. To avoid this we need some sort of acquire
10521 barrier in the call stub. One solution is to make the load of the
10522 toc word seem to appear to depend on the load of the function entry
10523 word. Another solution is to test for r2 being zero, and branch to
10524 the appropriate glink entry if so.
10526 . fake dep barrier compare
10527 . ld 12,xxx(2) ld 12,xxx(2)
10528 . mtctr 12 mtctr 12
10529 . xor 11,12,12 ld 2,xxx+8(2)
10530 . add 2,2,11 cmpldi 2,0
10531 . ld 2,xxx+8(2) bnectr+
10532 . bctr b <glink_entry>
10534 The solution involving the compare turns out to be faster, so
10535 that's what we use unless the branch won't reach. */
10537 #define ALWAYS_USE_FAKE_DEP 0
10538 #define ALWAYS_EMIT_R2SAVE 0
10540 static inline unsigned int
10541 plt_stub_size (struct ppc_link_hash_table *htab,
10542 struct ppc_stub_hash_entry *stub_entry,
10545 unsigned size = 12;
10547 if (ALWAYS_EMIT_R2SAVE
10548 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10550 if (PPC_HA (off) != 0)
10555 if (htab->params->plt_static_chain)
10557 if (htab->params->plt_thread_safe
10558 && htab->elf.dynamic_sections_created
10559 && stub_entry->h != NULL
10560 && stub_entry->h->elf.dynindx != -1)
10562 if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain) != PPC_HA (off))
10565 if (stub_entry->h != NULL
10566 && (stub_entry->h == htab->tls_get_addr_fd
10567 || stub_entry->h == htab->tls_get_addr)
10568 && htab->params->tls_get_addr_opt)
10571 if (ALWAYS_EMIT_R2SAVE
10572 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10578 /* Depending on the sign of plt_stub_align:
10579 If positive, return the padding to align to a 2**plt_stub_align
10581 If negative, if this stub would cross fewer 2**plt_stub_align
10582 boundaries if we align, then return the padding needed to do so. */
10584 static inline unsigned int
10585 plt_stub_pad (struct ppc_link_hash_table *htab,
10586 struct ppc_stub_hash_entry *stub_entry,
10590 unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
10591 bfd_vma stub_off = stub_entry->group->stub_sec->size;
10593 if (htab->params->plt_stub_align >= 0)
10595 stub_align = 1 << htab->params->plt_stub_align;
10596 if ((stub_off & (stub_align - 1)) != 0)
10597 return stub_align - (stub_off & (stub_align - 1));
10601 stub_align = 1 << -htab->params->plt_stub_align;
10602 if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
10603 > ((stub_size - 1) & -stub_align))
10604 return stub_align - (stub_off & (stub_align - 1));
10608 /* Build a .plt call stub. */
10610 static inline bfd_byte *
10611 build_plt_stub (struct ppc_link_hash_table *htab,
10612 struct ppc_stub_hash_entry *stub_entry,
10613 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10615 bfd *obfd = htab->params->stub_bfd;
10616 bfd_boolean plt_load_toc = htab->opd_abi;
10617 bfd_boolean plt_static_chain = htab->params->plt_static_chain;
10618 bfd_boolean plt_thread_safe = (htab->params->plt_thread_safe
10619 && htab->elf.dynamic_sections_created
10620 && stub_entry->h != NULL
10621 && stub_entry->h->elf.dynindx != -1);
10622 bfd_boolean use_fake_dep = plt_thread_safe;
10623 bfd_vma cmp_branch_off = 0;
10625 if (!ALWAYS_USE_FAKE_DEP
10628 && !((stub_entry->h == htab->tls_get_addr_fd
10629 || stub_entry->h == htab->tls_get_addr)
10630 && htab->params->tls_get_addr_opt))
10632 bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
10633 bfd_vma pltindex = ((pltoff - PLT_INITIAL_ENTRY_SIZE (htab))
10634 / PLT_ENTRY_SIZE (htab));
10635 bfd_vma glinkoff = GLINK_PLTRESOLVE_SIZE (htab) + pltindex * 8;
10638 if (pltindex > 32768)
10639 glinkoff += (pltindex - 32768) * 4;
10641 + htab->glink->output_offset
10642 + htab->glink->output_section->vma);
10643 from = (p - stub_entry->group->stub_sec->contents
10644 + 4 * (ALWAYS_EMIT_R2SAVE
10645 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10646 + 4 * (PPC_HA (offset) != 0)
10647 + 4 * (PPC_HA (offset + 8 + 8 * plt_static_chain)
10648 != PPC_HA (offset))
10649 + 4 * (plt_static_chain != 0)
10651 + stub_entry->group->stub_sec->output_offset
10652 + stub_entry->group->stub_sec->output_section->vma);
10653 cmp_branch_off = to - from;
10654 use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
10657 if (PPC_HA (offset) != 0)
10661 if (ALWAYS_EMIT_R2SAVE
10662 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10663 r[0].r_offset += 4;
10664 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
10665 r[1].r_offset = r[0].r_offset + 4;
10666 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10667 r[1].r_addend = r[0].r_addend;
10670 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10672 r[2].r_offset = r[1].r_offset + 4;
10673 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO);
10674 r[2].r_addend = r[0].r_addend;
10678 r[2].r_offset = r[1].r_offset + 8 + 8 * use_fake_dep;
10679 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10680 r[2].r_addend = r[0].r_addend + 8;
10681 if (plt_static_chain)
10683 r[3].r_offset = r[2].r_offset + 4;
10684 r[3].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10685 r[3].r_addend = r[0].r_addend + 16;
10690 if (ALWAYS_EMIT_R2SAVE
10691 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10692 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10695 bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
10696 bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
10700 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
10701 bfd_put_32 (obfd, LD_R12_0R12 | PPC_LO (offset), p), p += 4;
10704 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10706 bfd_put_32 (obfd, ADDI_R11_R11 | PPC_LO (offset), p), p += 4;
10709 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10714 bfd_put_32 (obfd, XOR_R2_R12_R12, p), p += 4;
10715 bfd_put_32 (obfd, ADD_R11_R11_R2, p), p += 4;
10717 bfd_put_32 (obfd, LD_R2_0R11 | PPC_LO (offset + 8), p), p += 4;
10718 if (plt_static_chain)
10719 bfd_put_32 (obfd, LD_R11_0R11 | PPC_LO (offset + 16), p), p += 4;
10726 if (ALWAYS_EMIT_R2SAVE
10727 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10728 r[0].r_offset += 4;
10729 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10732 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10734 r[1].r_offset = r[0].r_offset + 4;
10735 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16);
10736 r[1].r_addend = r[0].r_addend;
10740 r[1].r_offset = r[0].r_offset + 8 + 8 * use_fake_dep;
10741 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10742 r[1].r_addend = r[0].r_addend + 8 + 8 * plt_static_chain;
10743 if (plt_static_chain)
10745 r[2].r_offset = r[1].r_offset + 4;
10746 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10747 r[2].r_addend = r[0].r_addend + 8;
10752 if (ALWAYS_EMIT_R2SAVE
10753 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10754 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10755 bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p), p += 4;
10757 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10759 bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4;
10762 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10767 bfd_put_32 (obfd, XOR_R11_R12_R12, p), p += 4;
10768 bfd_put_32 (obfd, ADD_R2_R2_R11, p), p += 4;
10770 if (plt_static_chain)
10771 bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4;
10772 bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4;
10775 if (plt_load_toc && plt_thread_safe && !use_fake_dep)
10777 bfd_put_32 (obfd, CMPLDI_R2_0, p), p += 4;
10778 bfd_put_32 (obfd, BNECTR_P4, p), p += 4;
10779 bfd_put_32 (obfd, B_DOT | (cmp_branch_off & 0x3fffffc), p), p += 4;
10782 bfd_put_32 (obfd, BCTR, p), p += 4;
10786 /* Build a special .plt call stub for __tls_get_addr. */
10788 #define LD_R11_0R3 0xe9630000
10789 #define LD_R12_0R3 0xe9830000
10790 #define MR_R0_R3 0x7c601b78
10791 #define CMPDI_R11_0 0x2c2b0000
10792 #define ADD_R3_R12_R13 0x7c6c6a14
10793 #define BEQLR 0x4d820020
10794 #define MR_R3_R0 0x7c030378
10795 #define STD_R11_0R1 0xf9610000
10796 #define BCTRL 0x4e800421
10797 #define LD_R11_0R1 0xe9610000
10798 #define MTLR_R11 0x7d6803a6
10800 static inline bfd_byte *
10801 build_tls_get_addr_stub (struct ppc_link_hash_table *htab,
10802 struct ppc_stub_hash_entry *stub_entry,
10803 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10805 bfd *obfd = htab->params->stub_bfd;
10807 bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
10808 bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
10809 bfd_put_32 (obfd, MR_R0_R3, p), p += 4;
10810 bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4;
10811 bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4;
10812 bfd_put_32 (obfd, BEQLR, p), p += 4;
10813 bfd_put_32 (obfd, MR_R3_R0, p), p += 4;
10815 r[0].r_offset += 7 * 4;
10816 if (!ALWAYS_EMIT_R2SAVE
10817 && stub_entry->stub_type != ppc_stub_plt_call_r2save)
10818 return build_plt_stub (htab, stub_entry, p, offset, r);
10820 bfd_put_32 (obfd, MFLR_R11, p), p += 4;
10821 bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10824 r[0].r_offset += 2 * 4;
10825 p = build_plt_stub (htab, stub_entry, p, offset, r);
10826 bfd_put_32 (obfd, BCTRL, p - 4);
10828 bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p), p += 4;
10829 bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10830 bfd_put_32 (obfd, MTLR_R11, p), p += 4;
10831 bfd_put_32 (obfd, BLR, p), p += 4;
10836 static Elf_Internal_Rela *
10837 get_relocs (asection *sec, int count)
10839 Elf_Internal_Rela *relocs;
10840 struct bfd_elf_section_data *elfsec_data;
10842 elfsec_data = elf_section_data (sec);
10843 relocs = elfsec_data->relocs;
10844 if (relocs == NULL)
10846 bfd_size_type relsize;
10847 relsize = sec->reloc_count * sizeof (*relocs);
10848 relocs = bfd_alloc (sec->owner, relsize);
10849 if (relocs == NULL)
10851 elfsec_data->relocs = relocs;
10852 elfsec_data->rela.hdr = bfd_zalloc (sec->owner,
10853 sizeof (Elf_Internal_Shdr));
10854 if (elfsec_data->rela.hdr == NULL)
10856 elfsec_data->rela.hdr->sh_size = (sec->reloc_count
10857 * sizeof (Elf64_External_Rela));
10858 elfsec_data->rela.hdr->sh_entsize = sizeof (Elf64_External_Rela);
10859 sec->reloc_count = 0;
10861 relocs += sec->reloc_count;
10862 sec->reloc_count += count;
10867 get_r2off (struct bfd_link_info *info,
10868 struct ppc_stub_hash_entry *stub_entry)
10870 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10871 bfd_vma r2off = htab->sec_info[stub_entry->target_section->id].toc_off;
10875 /* Support linking -R objects. Get the toc pointer from the
10878 if (!htab->opd_abi)
10880 asection *opd = stub_entry->h->elf.root.u.def.section;
10881 bfd_vma opd_off = stub_entry->h->elf.root.u.def.value;
10883 if (strcmp (opd->name, ".opd") != 0
10884 || opd->reloc_count != 0)
10886 info->callbacks->einfo (_("%P: cannot find opd entry toc for `%pT'\n"),
10887 stub_entry->h->elf.root.root.string);
10888 bfd_set_error (bfd_error_bad_value);
10889 return (bfd_vma) -1;
10891 if (!bfd_get_section_contents (opd->owner, opd, buf, opd_off + 8, 8))
10892 return (bfd_vma) -1;
10893 r2off = bfd_get_64 (opd->owner, buf);
10894 r2off -= elf_gp (info->output_bfd);
10896 r2off -= htab->sec_info[stub_entry->group->link_sec->id].toc_off;
10901 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
10903 struct ppc_stub_hash_entry *stub_entry;
10904 struct ppc_branch_hash_entry *br_entry;
10905 struct bfd_link_info *info;
10906 struct ppc_link_hash_table *htab;
10910 Elf_Internal_Rela *r;
10913 /* Massage our args to the form they really have. */
10914 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
10917 htab = ppc_hash_table (info);
10921 /* Make a note of the offset within the stubs for this entry. */
10922 stub_entry->stub_offset = stub_entry->group->stub_sec->size;
10923 loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset;
10925 htab->stub_count[stub_entry->stub_type - 1] += 1;
10926 switch (stub_entry->stub_type)
10928 case ppc_stub_long_branch:
10929 case ppc_stub_long_branch_r2off:
10930 /* Branches are relative. This is where we are going to. */
10931 dest = (stub_entry->target_value
10932 + stub_entry->target_section->output_offset
10933 + stub_entry->target_section->output_section->vma);
10934 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10937 /* And this is where we are coming from. */
10938 off -= (stub_entry->stub_offset
10939 + stub_entry->group->stub_sec->output_offset
10940 + stub_entry->group->stub_sec->output_section->vma);
10943 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
10945 bfd_vma r2off = get_r2off (info, stub_entry);
10947 if (r2off == (bfd_vma) -1)
10949 htab->stub_error = TRUE;
10952 bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
10954 if (PPC_HA (r2off) != 0)
10956 bfd_put_32 (htab->params->stub_bfd,
10957 ADDIS_R2_R2 | PPC_HA (r2off), p);
10960 if (PPC_LO (r2off) != 0)
10962 bfd_put_32 (htab->params->stub_bfd,
10963 ADDI_R2_R2 | PPC_LO (r2off), p);
10968 bfd_put_32 (htab->params->stub_bfd, B_DOT | (off & 0x3fffffc), p);
10971 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
10974 (_("long branch stub `%s' offset overflow"),
10975 stub_entry->root.string);
10976 htab->stub_error = TRUE;
10980 if (info->emitrelocations)
10982 r = get_relocs (stub_entry->group->stub_sec, 1);
10985 r->r_offset = p - 4 - stub_entry->group->stub_sec->contents;
10986 r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
10987 r->r_addend = dest;
10988 if (stub_entry->h != NULL)
10990 struct elf_link_hash_entry **hashes;
10991 unsigned long symndx;
10992 struct ppc_link_hash_entry *h;
10994 hashes = elf_sym_hashes (htab->params->stub_bfd);
10995 if (hashes == NULL)
10997 bfd_size_type hsize;
10999 hsize = (htab->stub_globals + 1) * sizeof (*hashes);
11000 hashes = bfd_zalloc (htab->params->stub_bfd, hsize);
11001 if (hashes == NULL)
11003 elf_sym_hashes (htab->params->stub_bfd) = hashes;
11004 htab->stub_globals = 1;
11006 symndx = htab->stub_globals++;
11008 hashes[symndx] = &h->elf;
11009 r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
11010 if (h->oh != NULL && h->oh->is_func)
11011 h = ppc_follow_link (h->oh);
11012 if (h->elf.root.u.def.section != stub_entry->target_section)
11013 /* H is an opd symbol. The addend must be zero. */
11017 off = (h->elf.root.u.def.value
11018 + h->elf.root.u.def.section->output_offset
11019 + h->elf.root.u.def.section->output_section->vma);
11020 r->r_addend -= off;
11026 case ppc_stub_plt_branch:
11027 case ppc_stub_plt_branch_r2off:
11028 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
11029 stub_entry->root.string + 9,
11031 if (br_entry == NULL)
11033 _bfd_error_handler (_("can't find branch stub `%s'"),
11034 stub_entry->root.string);
11035 htab->stub_error = TRUE;
11039 dest = (stub_entry->target_value
11040 + stub_entry->target_section->output_offset
11041 + stub_entry->target_section->output_section->vma);
11042 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
11043 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
11045 bfd_put_64 (htab->brlt->owner, dest,
11046 htab->brlt->contents + br_entry->offset);
11048 if (br_entry->iter == htab->stub_iteration)
11050 br_entry->iter = 0;
11052 if (htab->relbrlt != NULL)
11054 /* Create a reloc for the branch lookup table entry. */
11055 Elf_Internal_Rela rela;
11058 rela.r_offset = (br_entry->offset
11059 + htab->brlt->output_offset
11060 + htab->brlt->output_section->vma);
11061 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
11062 rela.r_addend = dest;
11064 rl = htab->relbrlt->contents;
11065 rl += (htab->relbrlt->reloc_count++
11066 * sizeof (Elf64_External_Rela));
11067 bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
11069 else if (info->emitrelocations)
11071 r = get_relocs (htab->brlt, 1);
11074 /* brlt, being SEC_LINKER_CREATED does not go through the
11075 normal reloc processing. Symbols and offsets are not
11076 translated from input file to output file form, so
11077 set up the offset per the output file. */
11078 r->r_offset = (br_entry->offset
11079 + htab->brlt->output_offset
11080 + htab->brlt->output_section->vma);
11081 r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
11082 r->r_addend = dest;
11086 dest = (br_entry->offset
11087 + htab->brlt->output_offset
11088 + htab->brlt->output_section->vma);
11091 - elf_gp (info->output_bfd)
11092 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11094 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
11096 info->callbacks->einfo
11097 (_("%P: linkage table error against `%pT'\n"),
11098 stub_entry->root.string);
11099 bfd_set_error (bfd_error_bad_value);
11100 htab->stub_error = TRUE;
11104 if (info->emitrelocations)
11106 r = get_relocs (stub_entry->group->stub_sec, 1 + (PPC_HA (off) != 0));
11109 r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
11110 if (bfd_big_endian (info->output_bfd))
11111 r[0].r_offset += 2;
11112 if (stub_entry->stub_type == ppc_stub_plt_branch_r2off)
11113 r[0].r_offset += 4;
11114 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
11115 r[0].r_addend = dest;
11116 if (PPC_HA (off) != 0)
11118 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
11119 r[1].r_offset = r[0].r_offset + 4;
11120 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
11121 r[1].r_addend = r[0].r_addend;
11126 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
11128 if (PPC_HA (off) != 0)
11130 bfd_put_32 (htab->params->stub_bfd,
11131 ADDIS_R12_R2 | PPC_HA (off), p);
11133 bfd_put_32 (htab->params->stub_bfd,
11134 LD_R12_0R12 | PPC_LO (off), p);
11137 bfd_put_32 (htab->params->stub_bfd,
11138 LD_R12_0R2 | PPC_LO (off), p);
11142 bfd_vma r2off = get_r2off (info, stub_entry);
11144 if (r2off == (bfd_vma) -1)
11146 htab->stub_error = TRUE;
11150 bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
11152 if (PPC_HA (off) != 0)
11154 bfd_put_32 (htab->params->stub_bfd,
11155 ADDIS_R12_R2 | PPC_HA (off), p);
11157 bfd_put_32 (htab->params->stub_bfd,
11158 LD_R12_0R12 | PPC_LO (off), p);
11161 bfd_put_32 (htab->params->stub_bfd, LD_R12_0R2 | PPC_LO (off), p);
11163 if (PPC_HA (r2off) != 0)
11166 bfd_put_32 (htab->params->stub_bfd,
11167 ADDIS_R2_R2 | PPC_HA (r2off), p);
11169 if (PPC_LO (r2off) != 0)
11172 bfd_put_32 (htab->params->stub_bfd,
11173 ADDI_R2_R2 | PPC_LO (r2off), p);
11177 bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, p);
11179 bfd_put_32 (htab->params->stub_bfd, BCTR, p);
11183 case ppc_stub_plt_call:
11184 case ppc_stub_plt_call_r2save:
11185 if (stub_entry->h != NULL
11186 && stub_entry->h->is_func_descriptor
11187 && stub_entry->h->oh != NULL)
11189 struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
11191 /* If the old-ABI "dot-symbol" is undefined make it weak so
11192 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11193 if (fh->elf.root.type == bfd_link_hash_undefined
11194 && (stub_entry->h->elf.root.type == bfd_link_hash_defined
11195 || stub_entry->h->elf.root.type == bfd_link_hash_defweak))
11196 fh->elf.root.type = bfd_link_hash_undefweak;
11199 /* Now build the stub. */
11200 dest = stub_entry->plt_ent->plt.offset & ~1;
11201 if (dest >= (bfd_vma) -2)
11204 plt = htab->elf.splt;
11205 if (!htab->elf.dynamic_sections_created
11206 || stub_entry->h == NULL
11207 || stub_entry->h->elf.dynindx == -1)
11209 if (stub_entry->symtype == STT_GNU_IFUNC)
11210 plt = htab->elf.iplt;
11212 plt = htab->pltlocal;
11215 dest += plt->output_offset + plt->output_section->vma;
11218 - elf_gp (info->output_bfd)
11219 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11221 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
11223 info->callbacks->einfo
11224 /* xgettext:c-format */
11225 (_("%P: linkage table error against `%pT'\n"),
11226 stub_entry->h != NULL
11227 ? stub_entry->h->elf.root.root.string
11229 bfd_set_error (bfd_error_bad_value);
11230 htab->stub_error = TRUE;
11234 if (htab->params->plt_stub_align != 0)
11236 unsigned pad = plt_stub_pad (htab, stub_entry, off);
11238 stub_entry->group->stub_sec->size += pad;
11239 stub_entry->stub_offset = stub_entry->group->stub_sec->size;
11244 if (info->emitrelocations)
11246 r = get_relocs (stub_entry->group->stub_sec,
11247 ((PPC_HA (off) != 0)
11249 ? 2 + (htab->params->plt_static_chain
11250 && PPC_HA (off + 16) == PPC_HA (off))
11254 r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
11255 if (bfd_big_endian (info->output_bfd))
11256 r[0].r_offset += 2;
11257 r[0].r_addend = dest;
11259 if (stub_entry->h != NULL
11260 && (stub_entry->h == htab->tls_get_addr_fd
11261 || stub_entry->h == htab->tls_get_addr)
11262 && htab->params->tls_get_addr_opt)
11263 p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
11265 p = build_plt_stub (htab, stub_entry, loc, off, r);
11268 case ppc_stub_save_res:
11276 stub_entry->group->stub_sec->size += p - loc;
11278 if (htab->params->emit_stub_syms)
11280 struct elf_link_hash_entry *h;
11283 const char *const stub_str[] = { "long_branch",
11284 "long_branch_r2off",
11286 "plt_branch_r2off",
11290 len1 = strlen (stub_str[stub_entry->stub_type - 1]);
11291 len2 = strlen (stub_entry->root.string);
11292 name = bfd_malloc (len1 + len2 + 2);
11295 memcpy (name, stub_entry->root.string, 9);
11296 memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
11297 memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
11298 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
11301 if (h->root.type == bfd_link_hash_new)
11303 h->root.type = bfd_link_hash_defined;
11304 h->root.u.def.section = stub_entry->group->stub_sec;
11305 h->root.u.def.value = stub_entry->stub_offset;
11306 h->ref_regular = 1;
11307 h->def_regular = 1;
11308 h->ref_regular_nonweak = 1;
11309 h->forced_local = 1;
11311 h->root.linker_def = 1;
11318 /* As above, but don't actually build the stub. Just bump offset so
11319 we know stub section sizes, and select plt_branch stubs where
11320 long_branch stubs won't do. */
11323 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
11325 struct ppc_stub_hash_entry *stub_entry;
11326 struct bfd_link_info *info;
11327 struct ppc_link_hash_table *htab;
11331 /* Massage our args to the form they really have. */
11332 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
11335 htab = ppc_hash_table (info);
11339 if (stub_entry->h != NULL
11340 && stub_entry->h->save_res
11341 && stub_entry->h->elf.root.type == bfd_link_hash_defined
11342 && stub_entry->h->elf.root.u.def.section == htab->sfpr)
11344 /* Don't make stubs to out-of-line register save/restore
11345 functions. Instead, emit copies of the functions. */
11346 stub_entry->group->needs_save_res = 1;
11347 stub_entry->stub_type = ppc_stub_save_res;
11351 if (stub_entry->stub_type == ppc_stub_plt_call
11352 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
11355 off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
11356 if (off >= (bfd_vma) -2)
11358 plt = htab->elf.splt;
11359 if (!htab->elf.dynamic_sections_created
11360 || stub_entry->h == NULL
11361 || stub_entry->h->elf.dynindx == -1)
11363 if (stub_entry->symtype == STT_GNU_IFUNC)
11364 plt = htab->elf.iplt;
11366 plt = htab->pltlocal;
11368 off += (plt->output_offset
11369 + plt->output_section->vma
11370 - elf_gp (info->output_bfd)
11371 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11373 size = plt_stub_size (htab, stub_entry, off);
11374 if (stub_entry->h != NULL
11375 && (stub_entry->h == htab->tls_get_addr_fd
11376 || stub_entry->h == htab->tls_get_addr)
11377 && htab->params->tls_get_addr_opt
11378 && (ALWAYS_EMIT_R2SAVE
11379 || stub_entry->stub_type == ppc_stub_plt_call_r2save))
11380 stub_entry->group->tls_get_addr_opt_bctrl
11381 = stub_entry->group->stub_sec->size + size - 5 * 4;
11383 if (htab->params->plt_stub_align)
11384 size += plt_stub_pad (htab, stub_entry, off);
11385 if (info->emitrelocations)
11387 stub_entry->group->stub_sec->reloc_count
11388 += ((PPC_HA (off) != 0)
11390 ? 2 + (htab->params->plt_static_chain
11391 && PPC_HA (off + 16) == PPC_HA (off))
11393 stub_entry->group->stub_sec->flags |= SEC_RELOC;
11398 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11401 bfd_vma local_off = 0;
11403 off = (stub_entry->target_value
11404 + stub_entry->target_section->output_offset
11405 + stub_entry->target_section->output_section->vma);
11406 off -= (stub_entry->group->stub_sec->size
11407 + stub_entry->group->stub_sec->output_offset
11408 + stub_entry->group->stub_sec->output_section->vma);
11410 /* Reset the stub type from the plt variant in case we now
11411 can reach with a shorter stub. */
11412 if (stub_entry->stub_type >= ppc_stub_plt_branch)
11413 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
11416 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
11418 r2off = get_r2off (info, stub_entry);
11419 if (r2off == (bfd_vma) -1)
11421 htab->stub_error = TRUE;
11425 if (PPC_HA (r2off) != 0)
11427 if (PPC_LO (r2off) != 0)
11432 local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
11434 /* If the branch offset is too big, use a ppc_stub_plt_branch.
11435 Do the same for -R objects without function descriptors. */
11436 if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off
11437 || (stub_entry->stub_type == ppc_stub_long_branch_r2off
11439 && htab->sec_info[stub_entry->target_section->id].toc_off == 0))
11441 struct ppc_branch_hash_entry *br_entry;
11443 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
11444 stub_entry->root.string + 9,
11446 if (br_entry == NULL)
11448 _bfd_error_handler (_("can't build branch stub `%s'"),
11449 stub_entry->root.string);
11450 htab->stub_error = TRUE;
11454 if (br_entry->iter != htab->stub_iteration)
11456 br_entry->iter = htab->stub_iteration;
11457 br_entry->offset = htab->brlt->size;
11458 htab->brlt->size += 8;
11460 if (htab->relbrlt != NULL)
11461 htab->relbrlt->size += sizeof (Elf64_External_Rela);
11462 else if (info->emitrelocations)
11464 htab->brlt->reloc_count += 1;
11465 htab->brlt->flags |= SEC_RELOC;
11469 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
11470 off = (br_entry->offset
11471 + htab->brlt->output_offset
11472 + htab->brlt->output_section->vma
11473 - elf_gp (info->output_bfd)
11474 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11476 if (info->emitrelocations)
11478 stub_entry->group->stub_sec->reloc_count
11479 += 1 + (PPC_HA (off) != 0);
11480 stub_entry->group->stub_sec->flags |= SEC_RELOC;
11483 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
11486 if (PPC_HA (off) != 0)
11492 if (PPC_HA (off) != 0)
11495 if (PPC_HA (r2off) != 0)
11497 if (PPC_LO (r2off) != 0)
11501 else if (info->emitrelocations)
11503 stub_entry->group->stub_sec->reloc_count += 1;
11504 stub_entry->group->stub_sec->flags |= SEC_RELOC;
11508 stub_entry->group->stub_sec->size += size;
11512 /* Set up various things so that we can make a list of input sections
11513 for each output section included in the link. Returns -1 on error,
11514 0 when no stubs will be needed, and 1 on success. */
11517 ppc64_elf_setup_section_lists (struct bfd_link_info *info)
11521 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11526 htab->sec_info_arr_size = bfd_get_next_section_id ();
11527 amt = sizeof (*htab->sec_info) * (htab->sec_info_arr_size);
11528 htab->sec_info = bfd_zmalloc (amt);
11529 if (htab->sec_info == NULL)
11532 /* Set toc_off for com, und, abs and ind sections. */
11533 for (id = 0; id < 3; id++)
11534 htab->sec_info[id].toc_off = TOC_BASE_OFF;
11539 /* Set up for first pass at multitoc partitioning. */
11542 ppc64_elf_start_multitoc_partition (struct bfd_link_info *info)
11544 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11546 htab->toc_curr = ppc64_elf_set_toc (info, info->output_bfd);
11547 htab->toc_bfd = NULL;
11548 htab->toc_first_sec = NULL;
11551 /* The linker repeatedly calls this function for each TOC input section
11552 and linker generated GOT section. Group input bfds such that the toc
11553 within a group is less than 64k in size. */
11556 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
11558 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11559 bfd_vma addr, off, limit;
11564 if (!htab->second_toc_pass)
11566 /* Keep track of the first .toc or .got section for this input bfd. */
11567 bfd_boolean new_bfd = htab->toc_bfd != isec->owner;
11571 htab->toc_bfd = isec->owner;
11572 htab->toc_first_sec = isec;
11575 addr = isec->output_offset + isec->output_section->vma;
11576 off = addr - htab->toc_curr;
11577 limit = 0x80008000;
11578 if (ppc64_elf_tdata (isec->owner)->has_small_toc_reloc)
11580 if (off + isec->size > limit)
11582 addr = (htab->toc_first_sec->output_offset
11583 + htab->toc_first_sec->output_section->vma);
11584 htab->toc_curr = addr;
11585 htab->toc_curr &= -TOC_BASE_ALIGN;
11588 /* toc_curr is the base address of this toc group. Set elf_gp
11589 for the input section to be the offset relative to the
11590 output toc base plus 0x8000. Making the input elf_gp an
11591 offset allows us to move the toc as a whole without
11592 recalculating input elf_gp. */
11593 off = htab->toc_curr - elf_gp (info->output_bfd);
11594 off += TOC_BASE_OFF;
11596 /* Die if someone uses a linker script that doesn't keep input
11597 file .toc and .got together. */
11599 && elf_gp (isec->owner) != 0
11600 && elf_gp (isec->owner) != off)
11603 elf_gp (isec->owner) = off;
11607 /* During the second pass toc_first_sec points to the start of
11608 a toc group, and toc_curr is used to track the old elf_gp.
11609 We use toc_bfd to ensure we only look at each bfd once. */
11610 if (htab->toc_bfd == isec->owner)
11612 htab->toc_bfd = isec->owner;
11614 if (htab->toc_first_sec == NULL
11615 || htab->toc_curr != elf_gp (isec->owner))
11617 htab->toc_curr = elf_gp (isec->owner);
11618 htab->toc_first_sec = isec;
11620 addr = (htab->toc_first_sec->output_offset
11621 + htab->toc_first_sec->output_section->vma);
11622 off = addr - elf_gp (info->output_bfd) + TOC_BASE_OFF;
11623 elf_gp (isec->owner) = off;
11628 /* Called via elf_link_hash_traverse to merge GOT entries for global
11632 merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
11634 if (h->root.type == bfd_link_hash_indirect)
11637 merge_got_entries (&h->got.glist);
11642 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11646 reallocate_got (struct elf_link_hash_entry *h, void *inf)
11648 struct got_entry *gent;
11650 if (h->root.type == bfd_link_hash_indirect)
11653 for (gent = h->got.glist; gent != NULL; gent = gent->next)
11654 if (!gent->is_indirect)
11655 allocate_got (h, (struct bfd_link_info *) inf, gent);
11659 /* Called on the first multitoc pass after the last call to
11660 ppc64_elf_next_toc_section. This function removes duplicate GOT
11664 ppc64_elf_layout_multitoc (struct bfd_link_info *info)
11666 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11667 struct bfd *ibfd, *ibfd2;
11668 bfd_boolean done_something;
11670 htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd);
11672 if (!htab->do_multi_toc)
11675 /* Merge global sym got entries within a toc group. */
11676 elf_link_hash_traverse (&htab->elf, merge_global_got, info);
11678 /* And tlsld_got. */
11679 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11681 struct got_entry *ent, *ent2;
11683 if (!is_ppc64_elf (ibfd))
11686 ent = ppc64_tlsld_got (ibfd);
11687 if (!ent->is_indirect
11688 && ent->got.offset != (bfd_vma) -1)
11690 for (ibfd2 = ibfd->link.next; ibfd2 != NULL; ibfd2 = ibfd2->link.next)
11692 if (!is_ppc64_elf (ibfd2))
11695 ent2 = ppc64_tlsld_got (ibfd2);
11696 if (!ent2->is_indirect
11697 && ent2->got.offset != (bfd_vma) -1
11698 && elf_gp (ibfd2) == elf_gp (ibfd))
11700 ent2->is_indirect = TRUE;
11701 ent2->got.ent = ent;
11707 /* Zap sizes of got sections. */
11708 htab->elf.irelplt->rawsize = htab->elf.irelplt->size;
11709 htab->elf.irelplt->size -= htab->got_reli_size;
11710 htab->got_reli_size = 0;
11712 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11714 asection *got, *relgot;
11716 if (!is_ppc64_elf (ibfd))
11719 got = ppc64_elf_tdata (ibfd)->got;
11722 got->rawsize = got->size;
11724 relgot = ppc64_elf_tdata (ibfd)->relgot;
11725 relgot->rawsize = relgot->size;
11730 /* Now reallocate the got, local syms first. We don't need to
11731 allocate section contents again since we never increase size. */
11732 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11734 struct got_entry **lgot_ents;
11735 struct got_entry **end_lgot_ents;
11736 struct plt_entry **local_plt;
11737 struct plt_entry **end_local_plt;
11738 unsigned char *lgot_masks;
11739 bfd_size_type locsymcount;
11740 Elf_Internal_Shdr *symtab_hdr;
11743 if (!is_ppc64_elf (ibfd))
11746 lgot_ents = elf_local_got_ents (ibfd);
11750 symtab_hdr = &elf_symtab_hdr (ibfd);
11751 locsymcount = symtab_hdr->sh_info;
11752 end_lgot_ents = lgot_ents + locsymcount;
11753 local_plt = (struct plt_entry **) end_lgot_ents;
11754 end_local_plt = local_plt + locsymcount;
11755 lgot_masks = (unsigned char *) end_local_plt;
11756 s = ppc64_elf_tdata (ibfd)->got;
11757 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
11759 struct got_entry *ent;
11761 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
11763 unsigned int ent_size = 8;
11764 unsigned int rel_size = sizeof (Elf64_External_Rela);
11766 ent->got.offset = s->size;
11767 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
11772 s->size += ent_size;
11773 if ((*lgot_masks & (TLS_TLS | PLT_IFUNC)) == PLT_IFUNC)
11775 htab->elf.irelplt->size += rel_size;
11776 htab->got_reli_size += rel_size;
11778 else if (bfd_link_pic (info)
11779 && !((ent->tls_type & TLS_TPREL) != 0
11780 && bfd_link_executable (info)))
11782 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11783 srel->size += rel_size;
11789 elf_link_hash_traverse (&htab->elf, reallocate_got, info);
11791 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11793 struct got_entry *ent;
11795 if (!is_ppc64_elf (ibfd))
11798 ent = ppc64_tlsld_got (ibfd);
11799 if (!ent->is_indirect
11800 && ent->got.offset != (bfd_vma) -1)
11802 asection *s = ppc64_elf_tdata (ibfd)->got;
11803 ent->got.offset = s->size;
11805 if (bfd_link_pic (info))
11807 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11808 srel->size += sizeof (Elf64_External_Rela);
11813 done_something = htab->elf.irelplt->rawsize != htab->elf.irelplt->size;
11814 if (!done_something)
11815 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11819 if (!is_ppc64_elf (ibfd))
11822 got = ppc64_elf_tdata (ibfd)->got;
11825 done_something = got->rawsize != got->size;
11826 if (done_something)
11831 if (done_something)
11832 (*htab->params->layout_sections_again) ();
11834 /* Set up for second pass over toc sections to recalculate elf_gp
11835 on input sections. */
11836 htab->toc_bfd = NULL;
11837 htab->toc_first_sec = NULL;
11838 htab->second_toc_pass = TRUE;
11839 return done_something;
11842 /* Called after second pass of multitoc partitioning. */
11845 ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info)
11847 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11849 /* After the second pass, toc_curr tracks the TOC offset used
11850 for code sections below in ppc64_elf_next_input_section. */
11851 htab->toc_curr = TOC_BASE_OFF;
11854 /* No toc references were found in ISEC. If the code in ISEC makes no
11855 calls, then there's no need to use toc adjusting stubs when branching
11856 into ISEC. Actually, indirect calls from ISEC are OK as they will
11857 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11858 needed, and 2 if a cyclical call-graph was found but no other reason
11859 for a stub was detected. If called from the top level, a return of
11860 2 means the same as a return of 0. */
11863 toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
11867 /* Mark this section as checked. */
11868 isec->call_check_done = 1;
11870 /* We know none of our code bearing sections will need toc stubs. */
11871 if ((isec->flags & SEC_LINKER_CREATED) != 0)
11874 if (isec->size == 0)
11877 if (isec->output_section == NULL)
11881 if (isec->reloc_count != 0)
11883 Elf_Internal_Rela *relstart, *rel;
11884 Elf_Internal_Sym *local_syms;
11885 struct ppc_link_hash_table *htab;
11887 relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL,
11888 info->keep_memory);
11889 if (relstart == NULL)
11892 /* Look for branches to outside of this section. */
11894 htab = ppc_hash_table (info);
11898 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel)
11900 enum elf_ppc64_reloc_type r_type;
11901 unsigned long r_symndx;
11902 struct elf_link_hash_entry *h;
11903 struct ppc_link_hash_entry *eh;
11904 Elf_Internal_Sym *sym;
11906 struct _opd_sec_data *opd;
11910 r_type = ELF64_R_TYPE (rel->r_info);
11911 if (r_type != R_PPC64_REL24
11912 && r_type != R_PPC64_REL14
11913 && r_type != R_PPC64_REL14_BRTAKEN
11914 && r_type != R_PPC64_REL14_BRNTAKEN)
11917 r_symndx = ELF64_R_SYM (rel->r_info);
11918 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx,
11925 /* Calls to dynamic lib functions go through a plt call stub
11927 eh = (struct ppc_link_hash_entry *) h;
11929 && (eh->elf.plt.plist != NULL
11931 && ppc_follow_link (eh->oh)->elf.plt.plist != NULL)))
11937 if (sym_sec == NULL)
11938 /* Ignore other undefined symbols. */
11941 /* Assume branches to other sections not included in the
11942 link need stubs too, to cover -R and absolute syms. */
11943 if (sym_sec->output_section == NULL)
11950 sym_value = sym->st_value;
11953 if (h->root.type != bfd_link_hash_defined
11954 && h->root.type != bfd_link_hash_defweak)
11956 sym_value = h->root.u.def.value;
11958 sym_value += rel->r_addend;
11960 /* If this branch reloc uses an opd sym, find the code section. */
11961 opd = get_opd_info (sym_sec);
11964 if (h == NULL && opd->adjust != NULL)
11968 adjust = opd->adjust[OPD_NDX (sym_value)];
11970 /* Assume deleted functions won't ever be called. */
11972 sym_value += adjust;
11975 dest = opd_entry_value (sym_sec, sym_value,
11976 &sym_sec, NULL, FALSE);
11977 if (dest == (bfd_vma) -1)
11982 + sym_sec->output_offset
11983 + sym_sec->output_section->vma);
11985 /* Ignore branch to self. */
11986 if (sym_sec == isec)
11989 /* If the called function uses the toc, we need a stub. */
11990 if (sym_sec->has_toc_reloc
11991 || sym_sec->makes_toc_func_call)
11997 /* Assume any branch that needs a long branch stub might in fact
11998 need a plt_branch stub. A plt_branch stub uses r2. */
11999 else if (dest - (isec->output_offset
12000 + isec->output_section->vma
12001 + rel->r_offset) + (1 << 25)
12002 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
12010 /* If calling back to a section in the process of being
12011 tested, we can't say for sure that no toc adjusting stubs
12012 are needed, so don't return zero. */
12013 else if (sym_sec->call_check_in_progress)
12016 /* Branches to another section that itself doesn't have any TOC
12017 references are OK. Recursively call ourselves to check. */
12018 else if (!sym_sec->call_check_done)
12022 /* Mark current section as indeterminate, so that other
12023 sections that call back to current won't be marked as
12025 isec->call_check_in_progress = 1;
12026 recur = toc_adjusting_stub_needed (info, sym_sec);
12027 isec->call_check_in_progress = 0;
12038 if (local_syms != NULL
12039 && (elf_symtab_hdr (isec->owner).contents
12040 != (unsigned char *) local_syms))
12042 if (elf_section_data (isec)->relocs != relstart)
12047 && isec->map_head.s != NULL
12048 && (strcmp (isec->output_section->name, ".init") == 0
12049 || strcmp (isec->output_section->name, ".fini") == 0))
12051 if (isec->map_head.s->has_toc_reloc
12052 || isec->map_head.s->makes_toc_func_call)
12054 else if (!isec->map_head.s->call_check_done)
12057 isec->call_check_in_progress = 1;
12058 recur = toc_adjusting_stub_needed (info, isec->map_head.s);
12059 isec->call_check_in_progress = 0;
12066 isec->makes_toc_func_call = 1;
12071 /* The linker repeatedly calls this function for each input section,
12072 in the order that input sections are linked into output sections.
12073 Build lists of input sections to determine groupings between which
12074 we may insert linker stubs. */
12077 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
12079 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12084 if ((isec->output_section->flags & SEC_CODE) != 0
12085 && isec->output_section->id < htab->sec_info_arr_size)
12087 /* This happens to make the list in reverse order,
12088 which is what we want. */
12089 htab->sec_info[isec->id].u.list
12090 = htab->sec_info[isec->output_section->id].u.list;
12091 htab->sec_info[isec->output_section->id].u.list = isec;
12094 if (htab->multi_toc_needed)
12096 /* Analyse sections that aren't already flagged as needing a
12097 valid toc pointer. Exclude .fixup for the linux kernel.
12098 .fixup contains branches, but only back to the function that
12099 hit an exception. */
12100 if (!(isec->has_toc_reloc
12101 || (isec->flags & SEC_CODE) == 0
12102 || strcmp (isec->name, ".fixup") == 0
12103 || isec->call_check_done))
12105 if (toc_adjusting_stub_needed (info, isec) < 0)
12108 /* Make all sections use the TOC assigned for this object file.
12109 This will be wrong for pasted sections; We fix that in
12110 check_pasted_section(). */
12111 if (elf_gp (isec->owner) != 0)
12112 htab->toc_curr = elf_gp (isec->owner);
12115 htab->sec_info[isec->id].toc_off = htab->toc_curr;
12119 /* Check that all .init and .fini sections use the same toc, if they
12120 have toc relocs. */
12123 check_pasted_section (struct bfd_link_info *info, const char *name)
12125 asection *o = bfd_get_section_by_name (info->output_bfd, name);
12129 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12130 bfd_vma toc_off = 0;
12133 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
12134 if (i->has_toc_reloc)
12137 toc_off = htab->sec_info[i->id].toc_off;
12138 else if (toc_off != htab->sec_info[i->id].toc_off)
12143 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
12144 if (i->makes_toc_func_call)
12146 toc_off = htab->sec_info[i->id].toc_off;
12150 /* Make sure the whole pasted function uses the same toc offset. */
12152 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
12153 htab->sec_info[i->id].toc_off = toc_off;
12159 ppc64_elf_check_init_fini (struct bfd_link_info *info)
12161 return (check_pasted_section (info, ".init")
12162 & check_pasted_section (info, ".fini"));
12165 /* See whether we can group stub sections together. Grouping stub
12166 sections may result in fewer stubs. More importantly, we need to
12167 put all .init* and .fini* stubs at the beginning of the .init or
12168 .fini output sections respectively, because glibc splits the
12169 _init and _fini functions into multiple parts. Putting a stub in
12170 the middle of a function is not a good idea. */
12173 group_sections (struct bfd_link_info *info,
12174 bfd_size_type stub_group_size,
12175 bfd_boolean stubs_always_before_branch)
12177 struct ppc_link_hash_table *htab;
12179 bfd_boolean suppress_size_errors;
12181 htab = ppc_hash_table (info);
12185 suppress_size_errors = FALSE;
12186 if (stub_group_size == 1)
12188 /* Default values. */
12189 if (stubs_always_before_branch)
12190 stub_group_size = 0x1e00000;
12192 stub_group_size = 0x1c00000;
12193 suppress_size_errors = TRUE;
12196 for (osec = info->output_bfd->sections; osec != NULL; osec = osec->next)
12200 if (osec->id >= htab->sec_info_arr_size)
12203 tail = htab->sec_info[osec->id].u.list;
12204 while (tail != NULL)
12208 bfd_size_type total;
12209 bfd_boolean big_sec;
12211 struct map_stub *group;
12212 bfd_size_type group_size;
12215 total = tail->size;
12216 group_size = (ppc64_elf_section_data (tail) != NULL
12217 && ppc64_elf_section_data (tail)->has_14bit_branch
12218 ? stub_group_size >> 10 : stub_group_size);
12220 big_sec = total > group_size;
12221 if (big_sec && !suppress_size_errors)
12222 /* xgettext:c-format */
12223 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
12224 tail->owner, tail);
12225 curr_toc = htab->sec_info[tail->id].toc_off;
12227 while ((prev = htab->sec_info[curr->id].u.list) != NULL
12228 && ((total += curr->output_offset - prev->output_offset)
12229 < (ppc64_elf_section_data (prev) != NULL
12230 && ppc64_elf_section_data (prev)->has_14bit_branch
12231 ? (group_size = stub_group_size >> 10) : group_size))
12232 && htab->sec_info[prev->id].toc_off == curr_toc)
12235 /* OK, the size from the start of CURR to the end is less
12236 than group_size and thus can be handled by one stub
12237 section. (or the tail section is itself larger than
12238 group_size, in which case we may be toast.) We should
12239 really be keeping track of the total size of stubs added
12240 here, as stubs contribute to the final output section
12241 size. That's a little tricky, and this way will only
12242 break if stubs added make the total size more than 2^25,
12243 ie. for the default stub_group_size, if stubs total more
12244 than 2097152 bytes, or nearly 75000 plt call stubs. */
12245 group = bfd_alloc (curr->owner, sizeof (*group));
12248 group->link_sec = curr;
12249 group->stub_sec = NULL;
12250 group->needs_save_res = 0;
12251 group->tls_get_addr_opt_bctrl = -1u;
12252 group->next = htab->group;
12253 htab->group = group;
12256 prev = htab->sec_info[tail->id].u.list;
12257 /* Set up this stub group. */
12258 htab->sec_info[tail->id].u.group = group;
12260 while (tail != curr && (tail = prev) != NULL);
12262 /* But wait, there's more! Input sections up to group_size
12263 bytes before the stub section can be handled by it too.
12264 Don't do this if we have a really large section after the
12265 stubs, as adding more stubs increases the chance that
12266 branches may not reach into the stub section. */
12267 if (!stubs_always_before_branch && !big_sec)
12270 while (prev != NULL
12271 && ((total += tail->output_offset - prev->output_offset)
12272 < (ppc64_elf_section_data (prev) != NULL
12273 && ppc64_elf_section_data (prev)->has_14bit_branch
12274 ? (group_size = stub_group_size >> 10) : group_size))
12275 && htab->sec_info[prev->id].toc_off == curr_toc)
12278 prev = htab->sec_info[tail->id].u.list;
12279 htab->sec_info[tail->id].u.group = group;
12288 static const unsigned char glink_eh_frame_cie[] =
12290 0, 0, 0, 16, /* length. */
12291 0, 0, 0, 0, /* id. */
12292 1, /* CIE version. */
12293 'z', 'R', 0, /* Augmentation string. */
12294 4, /* Code alignment. */
12295 0x78, /* Data alignment. */
12297 1, /* Augmentation size. */
12298 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
12299 DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
12303 stub_eh_frame_size (struct map_stub *group, size_t align)
12305 size_t this_size = 17;
12306 if (group->tls_get_addr_opt_bctrl != -1u)
12308 unsigned int to_bctrl = group->tls_get_addr_opt_bctrl / 4;
12311 else if (to_bctrl < 256)
12313 else if (to_bctrl < 65536)
12319 this_size = (this_size + align - 1) & -align;
12323 /* Stripping output sections is normally done before dynamic section
12324 symbols have been allocated. This function is called later, and
12325 handles cases like htab->brlt which is mapped to its own output
12329 maybe_strip_output (struct bfd_link_info *info, asection *isec)
12331 if (isec->size == 0
12332 && isec->output_section->size == 0
12333 && !(isec->output_section->flags & SEC_KEEP)
12334 && !bfd_section_removed_from_list (info->output_bfd,
12335 isec->output_section)
12336 && elf_section_data (isec->output_section)->dynindx == 0)
12338 isec->output_section->flags |= SEC_EXCLUDE;
12339 bfd_section_list_remove (info->output_bfd, isec->output_section);
12340 info->output_bfd->section_count--;
12344 /* Determine and set the size of the stub section for a final link.
12346 The basic idea here is to examine all the relocations looking for
12347 PC-relative calls to a target that is unreachable with a "bl"
12351 ppc64_elf_size_stubs (struct bfd_link_info *info)
12353 bfd_size_type stub_group_size;
12354 bfd_boolean stubs_always_before_branch;
12355 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12360 if (htab->params->plt_thread_safe == -1 && !bfd_link_executable (info))
12361 htab->params->plt_thread_safe = 1;
12362 if (!htab->opd_abi)
12363 htab->params->plt_thread_safe = 0;
12364 else if (htab->params->plt_thread_safe == -1)
12366 static const char *const thread_starter[] =
12370 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12372 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12373 "mq_notify", "create_timer",
12378 "GOMP_parallel_start",
12379 "GOMP_parallel_loop_static",
12380 "GOMP_parallel_loop_static_start",
12381 "GOMP_parallel_loop_dynamic",
12382 "GOMP_parallel_loop_dynamic_start",
12383 "GOMP_parallel_loop_guided",
12384 "GOMP_parallel_loop_guided_start",
12385 "GOMP_parallel_loop_runtime",
12386 "GOMP_parallel_loop_runtime_start",
12387 "GOMP_parallel_sections",
12388 "GOMP_parallel_sections_start",
12394 for (i = 0; i < ARRAY_SIZE (thread_starter); i++)
12396 struct elf_link_hash_entry *h;
12397 h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
12398 FALSE, FALSE, TRUE);
12399 htab->params->plt_thread_safe = h != NULL && h->ref_regular;
12400 if (htab->params->plt_thread_safe)
12404 stubs_always_before_branch = htab->params->group_size < 0;
12405 if (htab->params->group_size < 0)
12406 stub_group_size = -htab->params->group_size;
12408 stub_group_size = htab->params->group_size;
12410 if (!group_sections (info, stub_group_size, stubs_always_before_branch))
12413 #define STUB_SHRINK_ITER 20
12414 /* Loop until no stubs added. After iteration 20 of this loop we may
12415 exit on a stub section shrinking. This is to break out of a
12416 pathological case where adding stubs on one iteration decreases
12417 section gaps (perhaps due to alignment), which then requires
12418 fewer or smaller stubs on the next iteration. */
12423 unsigned int bfd_indx;
12424 struct map_stub *group;
12426 htab->stub_iteration += 1;
12428 for (input_bfd = info->input_bfds, bfd_indx = 0;
12430 input_bfd = input_bfd->link.next, bfd_indx++)
12432 Elf_Internal_Shdr *symtab_hdr;
12434 Elf_Internal_Sym *local_syms = NULL;
12436 if (!is_ppc64_elf (input_bfd))
12439 /* We'll need the symbol table in a second. */
12440 symtab_hdr = &elf_symtab_hdr (input_bfd);
12441 if (symtab_hdr->sh_info == 0)
12444 /* Walk over each section attached to the input bfd. */
12445 for (section = input_bfd->sections;
12447 section = section->next)
12449 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
12451 /* If there aren't any relocs, then there's nothing more
12453 if ((section->flags & SEC_RELOC) == 0
12454 || (section->flags & SEC_ALLOC) == 0
12455 || (section->flags & SEC_LOAD) == 0
12456 || (section->flags & SEC_CODE) == 0
12457 || section->reloc_count == 0)
12460 /* If this section is a link-once section that will be
12461 discarded, then don't create any stubs. */
12462 if (section->output_section == NULL
12463 || section->output_section->owner != info->output_bfd)
12466 /* Get the relocs. */
12468 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
12469 info->keep_memory);
12470 if (internal_relocs == NULL)
12471 goto error_ret_free_local;
12473 /* Now examine each relocation. */
12474 irela = internal_relocs;
12475 irelaend = irela + section->reloc_count;
12476 for (; irela < irelaend; irela++)
12478 enum elf_ppc64_reloc_type r_type;
12479 unsigned int r_indx;
12480 enum ppc_stub_type stub_type;
12481 struct ppc_stub_hash_entry *stub_entry;
12482 asection *sym_sec, *code_sec;
12483 bfd_vma sym_value, code_value;
12484 bfd_vma destination;
12485 unsigned long local_off;
12486 bfd_boolean ok_dest;
12487 struct ppc_link_hash_entry *hash;
12488 struct ppc_link_hash_entry *fdh;
12489 struct elf_link_hash_entry *h;
12490 Elf_Internal_Sym *sym;
12492 const asection *id_sec;
12493 struct _opd_sec_data *opd;
12494 struct plt_entry *plt_ent;
12496 r_type = ELF64_R_TYPE (irela->r_info);
12497 r_indx = ELF64_R_SYM (irela->r_info);
12499 if (r_type >= R_PPC64_max)
12501 bfd_set_error (bfd_error_bad_value);
12502 goto error_ret_free_internal;
12505 /* Only look for stubs on branch instructions. */
12506 if (r_type != R_PPC64_REL24
12507 && r_type != R_PPC64_REL14
12508 && r_type != R_PPC64_REL14_BRTAKEN
12509 && r_type != R_PPC64_REL14_BRNTAKEN)
12512 /* Now determine the call target, its name, value,
12514 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
12515 r_indx, input_bfd))
12516 goto error_ret_free_internal;
12517 hash = (struct ppc_link_hash_entry *) h;
12524 sym_value = sym->st_value;
12525 if (sym_sec != NULL
12526 && sym_sec->output_section != NULL)
12529 else if (hash->elf.root.type == bfd_link_hash_defined
12530 || hash->elf.root.type == bfd_link_hash_defweak)
12532 sym_value = hash->elf.root.u.def.value;
12533 if (sym_sec->output_section != NULL)
12536 else if (hash->elf.root.type == bfd_link_hash_undefweak
12537 || hash->elf.root.type == bfd_link_hash_undefined)
12539 /* Recognise an old ABI func code entry sym, and
12540 use the func descriptor sym instead if it is
12542 if (hash->elf.root.root.string[0] == '.'
12543 && hash->oh != NULL)
12545 fdh = ppc_follow_link (hash->oh);
12546 if (fdh->elf.root.type == bfd_link_hash_defined
12547 || fdh->elf.root.type == bfd_link_hash_defweak)
12549 sym_sec = fdh->elf.root.u.def.section;
12550 sym_value = fdh->elf.root.u.def.value;
12551 if (sym_sec->output_section != NULL)
12560 bfd_set_error (bfd_error_bad_value);
12561 goto error_ret_free_internal;
12568 sym_value += irela->r_addend;
12569 destination = (sym_value
12570 + sym_sec->output_offset
12571 + sym_sec->output_section->vma);
12572 local_off = PPC64_LOCAL_ENTRY_OFFSET (hash
12577 code_sec = sym_sec;
12578 code_value = sym_value;
12579 opd = get_opd_info (sym_sec);
12584 if (hash == NULL && opd->adjust != NULL)
12586 long adjust = opd->adjust[OPD_NDX (sym_value)];
12589 code_value += adjust;
12590 sym_value += adjust;
12592 dest = opd_entry_value (sym_sec, sym_value,
12593 &code_sec, &code_value, FALSE);
12594 if (dest != (bfd_vma) -1)
12596 destination = dest;
12599 /* Fixup old ABI sym to point at code
12601 hash->elf.root.type = bfd_link_hash_defweak;
12602 hash->elf.root.u.def.section = code_sec;
12603 hash->elf.root.u.def.value = code_value;
12608 /* Determine what (if any) linker stub is needed. */
12610 stub_type = ppc_type_of_stub (section, irela, &hash,
12611 &plt_ent, destination,
12614 if (stub_type != ppc_stub_plt_call)
12616 /* Check whether we need a TOC adjusting stub.
12617 Since the linker pastes together pieces from
12618 different object files when creating the
12619 _init and _fini functions, it may be that a
12620 call to what looks like a local sym is in
12621 fact a call needing a TOC adjustment. */
12622 if (code_sec != NULL
12623 && code_sec->output_section != NULL
12624 && (htab->sec_info[code_sec->id].toc_off
12625 != htab->sec_info[section->id].toc_off)
12626 && (code_sec->has_toc_reloc
12627 || code_sec->makes_toc_func_call))
12628 stub_type = ppc_stub_long_branch_r2off;
12631 if (stub_type == ppc_stub_none)
12634 /* __tls_get_addr calls might be eliminated. */
12635 if (stub_type != ppc_stub_plt_call
12637 && (hash == htab->tls_get_addr
12638 || hash == htab->tls_get_addr_fd)
12639 && section->has_tls_reloc
12640 && irela != internal_relocs)
12642 /* Get tls info. */
12643 unsigned char *tls_mask;
12645 if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms,
12646 irela - 1, input_bfd))
12647 goto error_ret_free_internal;
12648 if ((*tls_mask & TLS_TLS) != 0)
12652 if (stub_type == ppc_stub_plt_call)
12655 && htab->params->plt_localentry0 != 0
12656 && is_elfv2_localentry0 (&hash->elf))
12657 htab->has_plt_localentry0 = 1;
12658 else if (irela + 1 < irelaend
12659 && irela[1].r_offset == irela->r_offset + 4
12660 && (ELF64_R_TYPE (irela[1].r_info)
12661 == R_PPC64_TOCSAVE))
12663 if (!tocsave_find (htab, INSERT,
12664 &local_syms, irela + 1, input_bfd))
12665 goto error_ret_free_internal;
12668 stub_type = ppc_stub_plt_call_r2save;
12671 /* Support for grouping stub sections. */
12672 id_sec = htab->sec_info[section->id].u.group->link_sec;
12674 /* Get the name of this stub. */
12675 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
12677 goto error_ret_free_internal;
12679 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
12680 stub_name, FALSE, FALSE);
12681 if (stub_entry != NULL)
12683 /* The proper stub has already been created. */
12685 if (stub_type == ppc_stub_plt_call_r2save)
12686 stub_entry->stub_type = stub_type;
12690 stub_entry = ppc_add_stub (stub_name, section, info);
12691 if (stub_entry == NULL)
12694 error_ret_free_internal:
12695 if (elf_section_data (section)->relocs == NULL)
12696 free (internal_relocs);
12697 error_ret_free_local:
12698 if (local_syms != NULL
12699 && (symtab_hdr->contents
12700 != (unsigned char *) local_syms))
12705 stub_entry->stub_type = stub_type;
12706 if (stub_type != ppc_stub_plt_call
12707 && stub_type != ppc_stub_plt_call_r2save)
12709 stub_entry->target_value = code_value;
12710 stub_entry->target_section = code_sec;
12714 stub_entry->target_value = sym_value;
12715 stub_entry->target_section = sym_sec;
12717 stub_entry->h = hash;
12718 stub_entry->plt_ent = plt_ent;
12719 stub_entry->symtype
12720 = hash ? hash->elf.type : ELF_ST_TYPE (sym->st_info);
12721 stub_entry->other = hash ? hash->elf.other : sym->st_other;
12723 if (stub_entry->h != NULL)
12724 htab->stub_globals += 1;
12727 /* We're done with the internal relocs, free them. */
12728 if (elf_section_data (section)->relocs != internal_relocs)
12729 free (internal_relocs);
12732 if (local_syms != NULL
12733 && symtab_hdr->contents != (unsigned char *) local_syms)
12735 if (!info->keep_memory)
12738 symtab_hdr->contents = (unsigned char *) local_syms;
12742 /* We may have added some stubs. Find out the new size of the
12744 for (group = htab->group; group != NULL; group = group->next)
12745 if (group->stub_sec != NULL)
12747 asection *stub_sec = group->stub_sec;
12749 if (htab->stub_iteration <= STUB_SHRINK_ITER
12750 || stub_sec->rawsize < stub_sec->size)
12751 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12752 stub_sec->rawsize = stub_sec->size;
12753 stub_sec->size = 0;
12754 stub_sec->reloc_count = 0;
12755 stub_sec->flags &= ~SEC_RELOC;
12758 if (htab->stub_iteration <= STUB_SHRINK_ITER
12759 || htab->brlt->rawsize < htab->brlt->size)
12760 htab->brlt->rawsize = htab->brlt->size;
12761 htab->brlt->size = 0;
12762 htab->brlt->reloc_count = 0;
12763 htab->brlt->flags &= ~SEC_RELOC;
12764 if (htab->relbrlt != NULL)
12765 htab->relbrlt->size = 0;
12767 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
12769 for (group = htab->group; group != NULL; group = group->next)
12770 if (group->needs_save_res)
12771 group->stub_sec->size += htab->sfpr->size;
12773 if (info->emitrelocations
12774 && htab->glink != NULL && htab->glink->size != 0)
12776 htab->glink->reloc_count = 1;
12777 htab->glink->flags |= SEC_RELOC;
12780 if (htab->glink_eh_frame != NULL
12781 && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
12782 && htab->glink_eh_frame->output_section->size > 8)
12784 size_t size = 0, align = 4;
12786 for (group = htab->group; group != NULL; group = group->next)
12787 if (group->stub_sec != NULL)
12788 size += stub_eh_frame_size (group, align);
12789 if (htab->glink != NULL && htab->glink->size != 0)
12790 size += (24 + align - 1) & -align;
12792 size += (sizeof (glink_eh_frame_cie) + align - 1) & -align;
12793 align = 1ul << htab->glink_eh_frame->output_section->alignment_power;
12794 size = (size + align - 1) & -align;
12795 htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
12796 htab->glink_eh_frame->size = size;
12799 if (htab->params->plt_stub_align != 0)
12800 for (group = htab->group; group != NULL; group = group->next)
12801 if (group->stub_sec != NULL)
12803 int align = abs (htab->params->plt_stub_align);
12804 group->stub_sec->size
12805 = (group->stub_sec->size + (1 << align) - 1) & -(1 << align);
12808 for (group = htab->group; group != NULL; group = group->next)
12809 if (group->stub_sec != NULL
12810 && group->stub_sec->rawsize != group->stub_sec->size
12811 && (htab->stub_iteration <= STUB_SHRINK_ITER
12812 || group->stub_sec->rawsize < group->stub_sec->size))
12816 && (htab->brlt->rawsize == htab->brlt->size
12817 || (htab->stub_iteration > STUB_SHRINK_ITER
12818 && htab->brlt->rawsize > htab->brlt->size))
12819 && (htab->glink_eh_frame == NULL
12820 || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size))
12823 /* Ask the linker to do its stuff. */
12824 (*htab->params->layout_sections_again) ();
12827 if (htab->glink_eh_frame != NULL
12828 && htab->glink_eh_frame->size != 0)
12831 bfd_byte *p, *last_fde;
12832 size_t last_fde_len, size, align, pad;
12833 struct map_stub *group;
12835 p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
12838 htab->glink_eh_frame->contents = p;
12842 memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
12843 /* CIE length (rewrite in case little-endian). */
12844 last_fde_len = ((sizeof (glink_eh_frame_cie) + align - 1) & -align) - 4;
12845 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12846 p += last_fde_len + 4;
12848 for (group = htab->group; group != NULL; group = group->next)
12849 if (group->stub_sec != NULL)
12852 last_fde_len = stub_eh_frame_size (group, align) - 4;
12854 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12857 val = p - htab->glink_eh_frame->contents;
12858 bfd_put_32 (htab->elf.dynobj, val, p);
12860 /* Offset to stub section, written later. */
12862 /* stub section size. */
12863 bfd_put_32 (htab->elf.dynobj, group->stub_sec->size, p);
12865 /* Augmentation. */
12867 if (group->tls_get_addr_opt_bctrl != -1u)
12869 unsigned int to_bctrl = group->tls_get_addr_opt_bctrl / 4;
12871 /* This FDE needs more than just the default.
12872 Describe __tls_get_addr_opt stub LR. */
12874 *p++ = DW_CFA_advance_loc + to_bctrl;
12875 else if (to_bctrl < 256)
12877 *p++ = DW_CFA_advance_loc1;
12880 else if (to_bctrl < 65536)
12882 *p++ = DW_CFA_advance_loc2;
12883 bfd_put_16 (htab->elf.dynobj, to_bctrl, p);
12888 *p++ = DW_CFA_advance_loc4;
12889 bfd_put_32 (htab->elf.dynobj, to_bctrl, p);
12892 *p++ = DW_CFA_offset_extended_sf;
12894 *p++ = -(STK_LINKER (htab) / 8) & 0x7f;
12895 *p++ = DW_CFA_advance_loc + 4;
12896 *p++ = DW_CFA_restore_extended;
12900 p = last_fde + last_fde_len + 4;
12902 if (htab->glink != NULL && htab->glink->size != 0)
12905 last_fde_len = ((24 + align - 1) & -align) - 4;
12907 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12910 val = p - htab->glink_eh_frame->contents;
12911 bfd_put_32 (htab->elf.dynobj, val, p);
12913 /* Offset to .glink, written later. */
12916 bfd_put_32 (htab->elf.dynobj, htab->glink->size - 8, p);
12918 /* Augmentation. */
12921 *p++ = DW_CFA_advance_loc + 1;
12922 *p++ = DW_CFA_register;
12924 *p++ = htab->opd_abi ? 12 : 0;
12925 *p++ = DW_CFA_advance_loc + (htab->opd_abi ? 5 : 7);
12926 *p++ = DW_CFA_restore_extended;
12928 p += ((24 + align - 1) & -align) - 24;
12930 /* Subsume any padding into the last FDE if user .eh_frame
12931 sections are aligned more than glink_eh_frame. Otherwise any
12932 zero padding will be seen as a terminator. */
12933 align = 1ul << htab->glink_eh_frame->output_section->alignment_power;
12934 size = p - htab->glink_eh_frame->contents;
12935 pad = ((size + align - 1) & -align) - size;
12936 htab->glink_eh_frame->size = size + pad;
12937 bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
12940 maybe_strip_output (info, htab->brlt);
12941 if (htab->glink_eh_frame != NULL)
12942 maybe_strip_output (info, htab->glink_eh_frame);
12947 /* Called after we have determined section placement. If sections
12948 move, we'll be called again. Provide a value for TOCstart. */
12951 ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
12954 bfd_vma TOCstart, adjust;
12958 struct elf_link_hash_entry *h;
12959 struct elf_link_hash_table *htab = elf_hash_table (info);
12961 if (is_elf_hash_table (htab)
12962 && htab->hgot != NULL)
12966 h = elf_link_hash_lookup (htab, ".TOC.", FALSE, FALSE, TRUE);
12967 if (is_elf_hash_table (htab))
12971 && h->root.type == bfd_link_hash_defined
12972 && !h->root.linker_def
12973 && (!is_elf_hash_table (htab)
12974 || h->def_regular))
12976 TOCstart = (h->root.u.def.value - TOC_BASE_OFF
12977 + h->root.u.def.section->output_offset
12978 + h->root.u.def.section->output_section->vma);
12979 _bfd_set_gp_value (obfd, TOCstart);
12984 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12985 order. The TOC starts where the first of these sections starts. */
12986 s = bfd_get_section_by_name (obfd, ".got");
12987 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12988 s = bfd_get_section_by_name (obfd, ".toc");
12989 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12990 s = bfd_get_section_by_name (obfd, ".tocbss");
12991 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12992 s = bfd_get_section_by_name (obfd, ".plt");
12993 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12995 /* This may happen for
12996 o references to TOC base (SYM@toc / TOC[tc0]) without a
12998 o bad linker script
12999 o --gc-sections and empty TOC sections
13001 FIXME: Warn user? */
13003 /* Look for a likely section. We probably won't even be
13005 for (s = obfd->sections; s != NULL; s = s->next)
13006 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY
13008 == (SEC_ALLOC | SEC_SMALL_DATA))
13011 for (s = obfd->sections; s != NULL; s = s->next)
13012 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE))
13013 == (SEC_ALLOC | SEC_SMALL_DATA))
13016 for (s = obfd->sections; s != NULL; s = s->next)
13017 if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE))
13021 for (s = obfd->sections; s != NULL; s = s->next)
13022 if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC)
13028 TOCstart = s->output_section->vma + s->output_offset;
13030 /* Force alignment. */
13031 adjust = TOCstart & (TOC_BASE_ALIGN - 1);
13032 TOCstart -= adjust;
13033 _bfd_set_gp_value (obfd, TOCstart);
13035 if (info != NULL && s != NULL)
13037 struct ppc_link_hash_table *htab = ppc_hash_table (info);
13041 if (htab->elf.hgot != NULL)
13043 htab->elf.hgot->root.u.def.value = TOC_BASE_OFF - adjust;
13044 htab->elf.hgot->root.u.def.section = s;
13049 struct bfd_link_hash_entry *bh = NULL;
13050 _bfd_generic_link_add_one_symbol (info, obfd, ".TOC.", BSF_GLOBAL,
13051 s, TOC_BASE_OFF - adjust,
13052 NULL, FALSE, FALSE, &bh);
13058 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
13059 write out any global entry stubs, and PLT relocations. */
13062 build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
13064 struct bfd_link_info *info;
13065 struct ppc_link_hash_table *htab;
13066 struct plt_entry *ent;
13069 if (h->root.type == bfd_link_hash_indirect)
13073 htab = ppc_hash_table (info);
13077 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
13078 if (ent->plt.offset != (bfd_vma) -1)
13080 /* This symbol has an entry in the procedure linkage
13081 table. Set it up. */
13082 Elf_Internal_Rela rela;
13083 asection *plt, *relplt;
13086 if (!htab->elf.dynamic_sections_created
13087 || h->dynindx == -1)
13089 if (!(h->def_regular
13090 && (h->root.type == bfd_link_hash_defined
13091 || h->root.type == bfd_link_hash_defweak)))
13093 if (h->type == STT_GNU_IFUNC)
13095 plt = htab->elf.iplt;
13096 relplt = htab->elf.irelplt;
13097 htab->local_ifunc_resolver = 1;
13099 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
13101 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
13105 plt = htab->pltlocal;
13106 if (bfd_link_pic (info))
13108 relplt = htab->relpltlocal;
13110 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_SLOT);
13112 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
13117 rela.r_addend = (h->root.u.def.value
13118 + h->root.u.def.section->output_offset
13119 + h->root.u.def.section->output_section->vma
13122 if (relplt == NULL)
13124 loc = plt->contents + ent->plt.offset;
13125 bfd_put_64 (info->output_bfd, rela.r_addend, loc);
13128 bfd_vma toc = elf_gp (info->output_bfd);
13129 toc += htab->sec_info[h->root.u.def.section->id].toc_off;
13130 bfd_put_64 (info->output_bfd, toc, loc + 8);
13135 rela.r_offset = (plt->output_section->vma
13136 + plt->output_offset
13137 + ent->plt.offset);
13138 loc = relplt->contents + (relplt->reloc_count++
13139 * sizeof (Elf64_External_Rela));
13140 bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
13145 rela.r_offset = (htab->elf.splt->output_section->vma
13146 + htab->elf.splt->output_offset
13147 + ent->plt.offset);
13148 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
13149 rela.r_addend = ent->addend;
13150 loc = (htab->elf.srelplt->contents
13151 + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
13152 / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
13153 if (h->type == STT_GNU_IFUNC && is_static_defined (h))
13154 htab->maybe_local_ifunc_resolver = 1;
13155 bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
13159 if (!h->pointer_equality_needed)
13162 if (h->def_regular)
13165 s = htab->global_entry;
13166 if (s == NULL || s->size == 0)
13169 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
13170 if (ent->plt.offset != (bfd_vma) -1
13171 && ent->addend == 0)
13177 p = s->contents + h->root.u.def.value;
13178 plt = htab->elf.splt;
13179 if (!htab->elf.dynamic_sections_created
13180 || h->dynindx == -1)
13182 if (h->type == STT_GNU_IFUNC)
13183 plt = htab->elf.iplt;
13185 plt = htab->pltlocal;
13187 off = ent->plt.offset + plt->output_offset + plt->output_section->vma;
13188 off -= h->root.u.def.value + s->output_offset + s->output_section->vma;
13190 if (off + 0x80008000 > 0xffffffff || (off & 3) != 0)
13192 info->callbacks->einfo
13193 (_("%P: linkage table error against `%pT'\n"),
13194 h->root.root.string);
13195 bfd_set_error (bfd_error_bad_value);
13196 htab->stub_error = TRUE;
13199 htab->stub_count[ppc_stub_global_entry - 1] += 1;
13200 if (htab->params->emit_stub_syms)
13202 size_t len = strlen (h->root.root.string);
13203 char *name = bfd_malloc (sizeof "12345678.global_entry." + len);
13208 sprintf (name, "%08x.global_entry.%s", s->id, h->root.root.string);
13209 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
13212 if (h->root.type == bfd_link_hash_new)
13214 h->root.type = bfd_link_hash_defined;
13215 h->root.u.def.section = s;
13216 h->root.u.def.value = p - s->contents;
13217 h->ref_regular = 1;
13218 h->def_regular = 1;
13219 h->ref_regular_nonweak = 1;
13220 h->forced_local = 1;
13222 h->root.linker_def = 1;
13226 if (PPC_HA (off) != 0)
13228 bfd_put_32 (s->owner, ADDIS_R12_R12 | PPC_HA (off), p);
13231 bfd_put_32 (s->owner, LD_R12_0R12 | PPC_LO (off), p);
13233 bfd_put_32 (s->owner, MTCTR_R12, p);
13235 bfd_put_32 (s->owner, BCTR, p);
13241 /* Write PLT relocs for locals. */
13244 write_plt_relocs_for_local_syms (struct bfd_link_info *info)
13246 struct ppc_link_hash_table *htab = ppc_hash_table (info);
13249 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
13251 struct got_entry **lgot_ents, **end_lgot_ents;
13252 struct plt_entry **local_plt, **lplt, **end_local_plt;
13253 Elf_Internal_Shdr *symtab_hdr;
13254 bfd_size_type locsymcount;
13255 Elf_Internal_Sym *local_syms = NULL;
13256 struct plt_entry *ent;
13258 if (!is_ppc64_elf (ibfd))
13261 lgot_ents = elf_local_got_ents (ibfd);
13265 symtab_hdr = &elf_symtab_hdr (ibfd);
13266 locsymcount = symtab_hdr->sh_info;
13267 end_lgot_ents = lgot_ents + locsymcount;
13268 local_plt = (struct plt_entry **) end_lgot_ents;
13269 end_local_plt = local_plt + locsymcount;
13270 for (lplt = local_plt; lplt < end_local_plt; ++lplt)
13271 for (ent = *lplt; ent != NULL; ent = ent->next)
13272 if (ent->plt.offset != (bfd_vma) -1)
13274 Elf_Internal_Sym *sym;
13276 asection *plt, *relplt;
13280 if (!get_sym_h (NULL, &sym, &sym_sec, NULL, &local_syms,
13281 lplt - local_plt, ibfd))
13283 if (local_syms != NULL
13284 && symtab_hdr->contents != (unsigned char *) local_syms)
13289 val = sym->st_value + ent->addend;
13290 val += PPC64_LOCAL_ENTRY_OFFSET (sym->st_other);
13291 if (sym_sec != NULL && sym_sec->output_section != NULL)
13292 val += sym_sec->output_offset + sym_sec->output_section->vma;
13294 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
13296 htab->local_ifunc_resolver = 1;
13297 plt = htab->elf.iplt;
13298 relplt = htab->elf.irelplt;
13302 plt = htab->pltlocal;
13303 relplt = bfd_link_pic (info) ? htab->relpltlocal : NULL;
13306 if (relplt == NULL)
13308 loc = plt->contents + ent->plt.offset;
13309 bfd_put_64 (info->output_bfd, val, loc);
13312 bfd_vma toc = elf_gp (ibfd);
13313 bfd_put_64 (info->output_bfd, toc, loc + 8);
13318 Elf_Internal_Rela rela;
13319 rela.r_offset = (ent->plt.offset
13320 + plt->output_offset
13321 + plt->output_section->vma);
13322 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
13325 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
13327 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
13332 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_SLOT);
13334 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
13336 rela.r_addend = val;
13337 loc = relplt->contents + (relplt->reloc_count++
13338 * sizeof (Elf64_External_Rela));
13339 bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
13343 if (local_syms != NULL
13344 && symtab_hdr->contents != (unsigned char *) local_syms)
13346 if (!info->keep_memory)
13349 symtab_hdr->contents = (unsigned char *) local_syms;
13355 /* Build all the stubs associated with the current output file.
13356 The stubs are kept in a hash table attached to the main linker
13357 hash table. This function is called via gldelf64ppc_finish. */
13360 ppc64_elf_build_stubs (struct bfd_link_info *info,
13363 struct ppc_link_hash_table *htab = ppc_hash_table (info);
13364 struct map_stub *group;
13365 asection *stub_sec;
13367 int stub_sec_count = 0;
13372 /* Allocate memory to hold the linker stubs. */
13373 for (group = htab->group; group != NULL; group = group->next)
13374 if ((stub_sec = group->stub_sec) != NULL
13375 && stub_sec->size != 0)
13377 stub_sec->contents = bfd_zalloc (htab->params->stub_bfd, stub_sec->size);
13378 if (stub_sec->contents == NULL)
13380 stub_sec->size = 0;
13383 if (htab->glink != NULL && htab->glink->size != 0)
13388 /* Build the .glink plt call stub. */
13389 if (htab->params->emit_stub_syms)
13391 struct elf_link_hash_entry *h;
13392 h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
13393 TRUE, FALSE, FALSE);
13396 if (h->root.type == bfd_link_hash_new)
13398 h->root.type = bfd_link_hash_defined;
13399 h->root.u.def.section = htab->glink;
13400 h->root.u.def.value = 8;
13401 h->ref_regular = 1;
13402 h->def_regular = 1;
13403 h->ref_regular_nonweak = 1;
13404 h->forced_local = 1;
13406 h->root.linker_def = 1;
13409 plt0 = (htab->elf.splt->output_section->vma
13410 + htab->elf.splt->output_offset
13412 if (info->emitrelocations)
13414 Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
13417 r->r_offset = (htab->glink->output_offset
13418 + htab->glink->output_section->vma);
13419 r->r_info = ELF64_R_INFO (0, R_PPC64_REL64);
13420 r->r_addend = plt0;
13422 p = htab->glink->contents;
13423 plt0 -= htab->glink->output_section->vma + htab->glink->output_offset;
13424 bfd_put_64 (htab->glink->owner, plt0, p);
13428 bfd_put_32 (htab->glink->owner, MFLR_R12, p);
13430 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
13432 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
13434 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
13436 bfd_put_32 (htab->glink->owner, MTLR_R12, p);
13438 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
13440 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
13442 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | 8, p);
13444 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
13446 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 16, p);
13451 bfd_put_32 (htab->glink->owner, MFLR_R0, p);
13453 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
13455 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
13457 bfd_put_32 (htab->glink->owner, STD_R2_0R1 + 24, p);
13459 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
13461 bfd_put_32 (htab->glink->owner, MTLR_R0, p);
13463 bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
13465 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
13467 bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-48 & 0xffff), p);
13469 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
13471 bfd_put_32 (htab->glink->owner, SRDI_R0_R0_2, p);
13473 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
13475 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 8, p);
13478 bfd_put_32 (htab->glink->owner, BCTR, p);
13480 BFD_ASSERT (p == htab->glink->contents + GLINK_PLTRESOLVE_SIZE (htab));
13482 /* Build the .glink lazy link call stubs. */
13484 while (p < htab->glink->contents + htab->glink->size)
13490 bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
13495 bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
13497 bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx),
13502 bfd_put_32 (htab->glink->owner,
13503 B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p);
13509 /* Build .glink global entry stubs, and PLT relocs for globals. */
13510 elf_link_hash_traverse (&htab->elf, build_global_entry_stubs_and_plt, info);
13512 if (!write_plt_relocs_for_local_syms (info))
13515 if (htab->brlt != NULL && htab->brlt->size != 0)
13517 htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
13519 if (htab->brlt->contents == NULL)
13522 if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
13524 htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
13525 htab->relbrlt->size);
13526 if (htab->relbrlt->contents == NULL)
13530 /* Build the stubs as directed by the stub hash table. */
13531 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
13533 for (group = htab->group; group != NULL; group = group->next)
13534 if (group->needs_save_res)
13535 group->stub_sec->size += htab->sfpr->size;
13537 if (htab->relbrlt != NULL)
13538 htab->relbrlt->reloc_count = 0;
13540 if (htab->params->plt_stub_align != 0)
13541 for (group = htab->group; group != NULL; group = group->next)
13542 if ((stub_sec = group->stub_sec) != NULL)
13544 int align = abs (htab->params->plt_stub_align);
13545 stub_sec->size = (stub_sec->size + (1 << align) - 1) & -(1 << align);
13548 for (group = htab->group; group != NULL; group = group->next)
13549 if (group->needs_save_res)
13551 stub_sec = group->stub_sec;
13552 memcpy (stub_sec->contents + stub_sec->size - htab->sfpr->size,
13553 htab->sfpr->contents, htab->sfpr->size);
13554 if (htab->params->emit_stub_syms)
13558 for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
13559 if (!sfpr_define (info, &save_res_funcs[i], stub_sec))
13564 for (group = htab->group; group != NULL; group = group->next)
13565 if ((stub_sec = group->stub_sec) != NULL)
13567 stub_sec_count += 1;
13568 if (stub_sec->rawsize != stub_sec->size
13569 && (htab->stub_iteration <= STUB_SHRINK_ITER
13570 || stub_sec->rawsize < stub_sec->size))
13576 htab->stub_error = TRUE;
13577 _bfd_error_handler (_("stubs don't match calculated size"));
13580 if (htab->stub_error)
13586 *stats = bfd_malloc (500);
13587 if (*stats == NULL)
13590 len = sprintf (*stats,
13591 ngettext ("linker stubs in %u group\n",
13592 "linker stubs in %u groups\n",
13595 sprintf (*stats + len, _(" branch %lu\n"
13596 " toc adjust %lu\n"
13597 " long branch %lu\n"
13598 " long toc adj %lu\n"
13600 " plt call toc %lu\n"
13601 " global entry %lu"),
13602 htab->stub_count[ppc_stub_long_branch - 1],
13603 htab->stub_count[ppc_stub_long_branch_r2off - 1],
13604 htab->stub_count[ppc_stub_plt_branch - 1],
13605 htab->stub_count[ppc_stub_plt_branch_r2off - 1],
13606 htab->stub_count[ppc_stub_plt_call - 1],
13607 htab->stub_count[ppc_stub_plt_call_r2save - 1],
13608 htab->stub_count[ppc_stub_global_entry - 1]);
13613 /* What to do when ld finds relocations against symbols defined in
13614 discarded sections. */
13616 static unsigned int
13617 ppc64_elf_action_discarded (asection *sec)
13619 if (strcmp (".opd", sec->name) == 0)
13622 if (strcmp (".toc", sec->name) == 0)
13625 if (strcmp (".toc1", sec->name) == 0)
13628 return _bfd_elf_default_action_discarded (sec);
13631 /* The RELOCATE_SECTION function is called by the ELF backend linker
13632 to handle the relocations for a section.
13634 The relocs are always passed as Rela structures; if the section
13635 actually uses Rel structures, the r_addend field will always be
13638 This function is responsible for adjust the section contents as
13639 necessary, and (if using Rela relocs and generating a
13640 relocatable output file) adjusting the reloc addend as
13643 This function does not have to worry about setting the reloc
13644 address or the reloc symbol index.
13646 LOCAL_SYMS is a pointer to the swapped in local symbols.
13648 LOCAL_SECTIONS is an array giving the section in the input file
13649 corresponding to the st_shndx field of each local symbol.
13651 The global hash table entry for the global symbols can be found
13652 via elf_sym_hashes (input_bfd).
13654 When generating relocatable output, this function must handle
13655 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13656 going to be the section symbol corresponding to the output
13657 section, which means that the addend must be adjusted
13661 ppc64_elf_relocate_section (bfd *output_bfd,
13662 struct bfd_link_info *info,
13664 asection *input_section,
13665 bfd_byte *contents,
13666 Elf_Internal_Rela *relocs,
13667 Elf_Internal_Sym *local_syms,
13668 asection **local_sections)
13670 struct ppc_link_hash_table *htab;
13671 Elf_Internal_Shdr *symtab_hdr;
13672 struct elf_link_hash_entry **sym_hashes;
13673 Elf_Internal_Rela *rel;
13674 Elf_Internal_Rela *wrel;
13675 Elf_Internal_Rela *relend;
13676 Elf_Internal_Rela outrel;
13678 struct got_entry **local_got_ents;
13680 bfd_boolean ret = TRUE;
13681 bfd_boolean is_opd;
13682 /* Assume 'at' branch hints. */
13683 bfd_boolean is_isa_v2 = TRUE;
13684 bfd_vma d_offset = (bfd_big_endian (input_bfd) ? 2 : 0);
13686 /* Initialize howto table if needed. */
13687 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
13690 htab = ppc_hash_table (info);
13694 /* Don't relocate stub sections. */
13695 if (input_section->owner == htab->params->stub_bfd)
13698 BFD_ASSERT (is_ppc64_elf (input_bfd));
13700 local_got_ents = elf_local_got_ents (input_bfd);
13701 TOCstart = elf_gp (output_bfd);
13702 symtab_hdr = &elf_symtab_hdr (input_bfd);
13703 sym_hashes = elf_sym_hashes (input_bfd);
13704 is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd;
13706 rel = wrel = relocs;
13707 relend = relocs + input_section->reloc_count;
13708 for (; rel < relend; wrel++, rel++)
13710 enum elf_ppc64_reloc_type r_type;
13712 bfd_reloc_status_type r;
13713 Elf_Internal_Sym *sym;
13715 struct elf_link_hash_entry *h_elf;
13716 struct ppc_link_hash_entry *h;
13717 struct ppc_link_hash_entry *fdh;
13718 const char *sym_name;
13719 unsigned long r_symndx, toc_symndx;
13720 bfd_vma toc_addend;
13721 unsigned char tls_mask, tls_gd, tls_type;
13722 unsigned char sym_type;
13723 bfd_vma relocation;
13724 bfd_boolean unresolved_reloc;
13725 bfd_boolean warned;
13726 enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
13729 struct ppc_stub_hash_entry *stub_entry;
13730 bfd_vma max_br_offset;
13732 Elf_Internal_Rela orig_rel;
13733 reloc_howto_type *howto;
13734 struct reloc_howto_struct alt_howto;
13739 r_type = ELF64_R_TYPE (rel->r_info);
13740 r_symndx = ELF64_R_SYM (rel->r_info);
13742 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13743 symbol of the previous ADDR64 reloc. The symbol gives us the
13744 proper TOC base to use. */
13745 if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
13747 && ELF64_R_TYPE (wrel[-1].r_info) == R_PPC64_ADDR64
13749 r_symndx = ELF64_R_SYM (wrel[-1].r_info);
13755 unresolved_reloc = FALSE;
13758 if (r_symndx < symtab_hdr->sh_info)
13760 /* It's a local symbol. */
13761 struct _opd_sec_data *opd;
13763 sym = local_syms + r_symndx;
13764 sec = local_sections[r_symndx];
13765 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
13766 sym_type = ELF64_ST_TYPE (sym->st_info);
13767 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
13768 opd = get_opd_info (sec);
13769 if (opd != NULL && opd->adjust != NULL)
13771 long adjust = opd->adjust[OPD_NDX (sym->st_value
13777 /* If this is a relocation against the opd section sym
13778 and we have edited .opd, adjust the reloc addend so
13779 that ld -r and ld --emit-relocs output is correct.
13780 If it is a reloc against some other .opd symbol,
13781 then the symbol value will be adjusted later. */
13782 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
13783 rel->r_addend += adjust;
13785 relocation += adjust;
13791 bfd_boolean ignored;
13793 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
13794 r_symndx, symtab_hdr, sym_hashes,
13795 h_elf, sec, relocation,
13796 unresolved_reloc, warned, ignored);
13797 sym_name = h_elf->root.root.string;
13798 sym_type = h_elf->type;
13800 && sec->owner == output_bfd
13801 && strcmp (sec->name, ".opd") == 0)
13803 /* This is a symbol defined in a linker script. All
13804 such are defined in output sections, even those
13805 defined by simple assignment from a symbol defined in
13806 an input section. Transfer the symbol to an
13807 appropriate input .opd section, so that a branch to
13808 this symbol will be mapped to the location specified
13809 by the opd entry. */
13810 struct bfd_link_order *lo;
13811 for (lo = sec->map_head.link_order; lo != NULL; lo = lo->next)
13812 if (lo->type == bfd_indirect_link_order)
13814 asection *isec = lo->u.indirect.section;
13815 if (h_elf->root.u.def.value >= isec->output_offset
13816 && h_elf->root.u.def.value < (isec->output_offset
13819 h_elf->root.u.def.value -= isec->output_offset;
13820 h_elf->root.u.def.section = isec;
13827 h = (struct ppc_link_hash_entry *) h_elf;
13829 if (sec != NULL && discarded_section (sec))
13831 _bfd_clear_contents (ppc64_elf_howto_table[r_type],
13832 input_bfd, input_section,
13833 contents + rel->r_offset);
13834 wrel->r_offset = rel->r_offset;
13836 wrel->r_addend = 0;
13838 /* For ld -r, remove relocations in debug sections against
13839 symbols defined in discarded sections. Not done for
13840 non-debug to preserve relocs in .eh_frame which the
13841 eh_frame editing code expects to be present. */
13842 if (bfd_link_relocatable (info)
13843 && (input_section->flags & SEC_DEBUGGING))
13849 if (bfd_link_relocatable (info))
13852 if (h != NULL && &h->elf == htab->elf.hgot)
13854 relocation = TOCstart + htab->sec_info[input_section->id].toc_off;
13855 sec = bfd_abs_section_ptr;
13856 unresolved_reloc = FALSE;
13859 /* TLS optimizations. Replace instruction sequences and relocs
13860 based on information we collected in tls_optimize. We edit
13861 RELOCS so that --emit-relocs will output something sensible
13862 for the final instruction stream. */
13867 tls_mask = h->tls_mask;
13868 else if (local_got_ents != NULL)
13870 struct plt_entry **local_plt = (struct plt_entry **)
13871 (local_got_ents + symtab_hdr->sh_info);
13872 unsigned char *lgot_masks = (unsigned char *)
13873 (local_plt + symtab_hdr->sh_info);
13874 tls_mask = lgot_masks[r_symndx];
13876 if (((tls_mask & TLS_TLS) == 0 || tls_mask == (TLS_TLS | TLS_MARK))
13877 && (r_type == R_PPC64_TLS
13878 || r_type == R_PPC64_TLSGD
13879 || r_type == R_PPC64_TLSLD))
13881 /* Check for toc tls entries. */
13882 unsigned char *toc_tls;
13884 if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
13885 &local_syms, rel, input_bfd))
13889 tls_mask = *toc_tls;
13892 /* Check that tls relocs are used with tls syms, and non-tls
13893 relocs are used with non-tls syms. */
13894 if (r_symndx != STN_UNDEF
13895 && r_type != R_PPC64_NONE
13897 || h->elf.root.type == bfd_link_hash_defined
13898 || h->elf.root.type == bfd_link_hash_defweak)
13899 && (IS_PPC64_TLS_RELOC (r_type)
13900 != (sym_type == STT_TLS
13901 || (sym_type == STT_SECTION
13902 && (sec->flags & SEC_THREAD_LOCAL) != 0))))
13904 if ((tls_mask & TLS_TLS) != 0
13905 && (r_type == R_PPC64_TLS
13906 || r_type == R_PPC64_TLSGD
13907 || r_type == R_PPC64_TLSLD))
13908 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13911 info->callbacks->einfo
13912 (!IS_PPC64_TLS_RELOC (r_type)
13913 /* xgettext:c-format */
13914 ? _("%H: %s used with TLS symbol `%pT'\n")
13915 /* xgettext:c-format */
13916 : _("%H: %s used with non-TLS symbol `%pT'\n"),
13917 input_bfd, input_section, rel->r_offset,
13918 ppc64_elf_howto_table[r_type]->name,
13922 /* Ensure reloc mapping code below stays sane. */
13923 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
13924 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
13925 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
13926 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
13927 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
13928 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
13929 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
13930 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
13931 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
13932 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
13940 case R_PPC64_LO_DS_OPT:
13941 insn = bfd_get_32 (input_bfd, contents + rel->r_offset - d_offset);
13942 if ((insn & (0x3f << 26)) != 58u << 26)
13944 insn += (14u << 26) - (58u << 26);
13945 bfd_put_32 (input_bfd, insn, contents + rel->r_offset - d_offset);
13946 r_type = R_PPC64_TOC16_LO;
13947 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13950 case R_PPC64_TOC16:
13951 case R_PPC64_TOC16_LO:
13952 case R_PPC64_TOC16_DS:
13953 case R_PPC64_TOC16_LO_DS:
13955 /* Check for toc tls entries. */
13956 unsigned char *toc_tls;
13959 retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
13960 &local_syms, rel, input_bfd);
13966 tls_mask = *toc_tls;
13967 if (r_type == R_PPC64_TOC16_DS
13968 || r_type == R_PPC64_TOC16_LO_DS)
13970 if ((tls_mask & TLS_TLS) != 0
13971 && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
13976 /* If we found a GD reloc pair, then we might be
13977 doing a GD->IE transition. */
13980 tls_gd = TLS_TPRELGD;
13981 if ((tls_mask & TLS_TLS) != 0
13982 && (tls_mask & TLS_GD) == 0)
13985 else if (retval == 3)
13987 if ((tls_mask & TLS_TLS) != 0
13988 && (tls_mask & TLS_LD) == 0)
13996 case R_PPC64_GOT_TPREL16_HI:
13997 case R_PPC64_GOT_TPREL16_HA:
13998 if ((tls_mask & TLS_TLS) != 0
13999 && (tls_mask & TLS_TPREL) == 0)
14001 rel->r_offset -= d_offset;
14002 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
14003 r_type = R_PPC64_NONE;
14004 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14008 case R_PPC64_GOT_TPREL16_DS:
14009 case R_PPC64_GOT_TPREL16_LO_DS:
14010 if ((tls_mask & TLS_TLS) != 0
14011 && (tls_mask & TLS_TPREL) == 0)
14014 insn = bfd_get_32 (input_bfd,
14015 contents + rel->r_offset - d_offset);
14017 insn |= 0x3c0d0000; /* addis 0,13,0 */
14018 bfd_put_32 (input_bfd, insn,
14019 contents + rel->r_offset - d_offset);
14020 r_type = R_PPC64_TPREL16_HA;
14021 if (toc_symndx != 0)
14023 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
14024 rel->r_addend = toc_addend;
14025 /* We changed the symbol. Start over in order to
14026 get h, sym, sec etc. right. */
14030 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14035 if ((tls_mask & TLS_TLS) != 0
14036 && (tls_mask & TLS_TPREL) == 0)
14038 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
14039 insn = _bfd_elf_ppc_at_tls_transform (insn, 13);
14042 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
14043 /* Was PPC64_TLS which sits on insn boundary, now
14044 PPC64_TPREL16_LO which is at low-order half-word. */
14045 rel->r_offset += d_offset;
14046 r_type = R_PPC64_TPREL16_LO;
14047 if (toc_symndx != 0)
14049 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
14050 rel->r_addend = toc_addend;
14051 /* We changed the symbol. Start over in order to
14052 get h, sym, sec etc. right. */
14056 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14060 case R_PPC64_GOT_TLSGD16_HI:
14061 case R_PPC64_GOT_TLSGD16_HA:
14062 tls_gd = TLS_TPRELGD;
14063 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
14067 case R_PPC64_GOT_TLSLD16_HI:
14068 case R_PPC64_GOT_TLSLD16_HA:
14069 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
14072 if ((tls_mask & tls_gd) != 0)
14073 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
14074 + R_PPC64_GOT_TPREL16_DS);
14077 rel->r_offset -= d_offset;
14078 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
14079 r_type = R_PPC64_NONE;
14081 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14085 case R_PPC64_GOT_TLSGD16:
14086 case R_PPC64_GOT_TLSGD16_LO:
14087 tls_gd = TLS_TPRELGD;
14088 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
14092 case R_PPC64_GOT_TLSLD16:
14093 case R_PPC64_GOT_TLSLD16_LO:
14094 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
14096 unsigned int insn1, insn2;
14100 offset = (bfd_vma) -1;
14101 /* If not using the newer R_PPC64_TLSGD/LD to mark
14102 __tls_get_addr calls, we must trust that the call
14103 stays with its arg setup insns, ie. that the next
14104 reloc is the __tls_get_addr call associated with
14105 the current reloc. Edit both insns. */
14106 if (input_section->has_tls_get_addr_call
14107 && rel + 1 < relend
14108 && branch_reloc_hash_match (input_bfd, rel + 1,
14109 htab->tls_get_addr,
14110 htab->tls_get_addr_fd))
14111 offset = rel[1].r_offset;
14112 /* We read the low GOT_TLS (or TOC16) insn because we
14113 need to keep the destination reg. It may be
14114 something other than the usual r3, and moved to r3
14115 before the call by intervening code. */
14116 insn1 = bfd_get_32 (input_bfd,
14117 contents + rel->r_offset - d_offset);
14118 if ((tls_mask & tls_gd) != 0)
14121 insn1 &= (0x1f << 21) | (0x1f << 16);
14122 insn1 |= 58 << 26; /* ld */
14123 insn2 = 0x7c636a14; /* add 3,3,13 */
14124 if (offset != (bfd_vma) -1)
14125 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
14126 if ((tls_mask & TLS_EXPLICIT) == 0)
14127 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
14128 + R_PPC64_GOT_TPREL16_DS);
14130 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
14131 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14136 insn1 &= 0x1f << 21;
14137 insn1 |= 0x3c0d0000; /* addis r,13,0 */
14138 insn2 = 0x38630000; /* addi 3,3,0 */
14141 /* Was an LD reloc. */
14143 sec = local_sections[toc_symndx];
14145 r_symndx < symtab_hdr->sh_info;
14147 if (local_sections[r_symndx] == sec)
14149 if (r_symndx >= symtab_hdr->sh_info)
14150 r_symndx = STN_UNDEF;
14151 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
14152 if (r_symndx != STN_UNDEF)
14153 rel->r_addend -= (local_syms[r_symndx].st_value
14154 + sec->output_offset
14155 + sec->output_section->vma);
14157 else if (toc_symndx != 0)
14159 r_symndx = toc_symndx;
14160 rel->r_addend = toc_addend;
14162 r_type = R_PPC64_TPREL16_HA;
14163 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14164 if (offset != (bfd_vma) -1)
14166 rel[1].r_info = ELF64_R_INFO (r_symndx,
14167 R_PPC64_TPREL16_LO);
14168 rel[1].r_offset = offset + d_offset;
14169 rel[1].r_addend = rel->r_addend;
14172 bfd_put_32 (input_bfd, insn1,
14173 contents + rel->r_offset - d_offset);
14174 if (offset != (bfd_vma) -1)
14175 bfd_put_32 (input_bfd, insn2, contents + offset);
14176 if ((tls_mask & tls_gd) == 0
14177 && (tls_gd == 0 || toc_symndx != 0))
14179 /* We changed the symbol. Start over in order
14180 to get h, sym, sec etc. right. */
14186 case R_PPC64_TLSGD:
14187 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0
14188 && rel + 1 < relend)
14190 unsigned int insn2;
14191 bfd_vma offset = rel->r_offset;
14193 if ((tls_mask & TLS_TPRELGD) != 0)
14196 r_type = R_PPC64_NONE;
14197 insn2 = 0x7c636a14; /* add 3,3,13 */
14202 if (toc_symndx != 0)
14204 r_symndx = toc_symndx;
14205 rel->r_addend = toc_addend;
14207 r_type = R_PPC64_TPREL16_LO;
14208 rel->r_offset = offset + d_offset;
14209 insn2 = 0x38630000; /* addi 3,3,0 */
14211 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14212 /* Zap the reloc on the _tls_get_addr call too. */
14213 BFD_ASSERT (offset == rel[1].r_offset);
14214 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
14215 bfd_put_32 (input_bfd, insn2, contents + offset);
14216 if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0)
14221 case R_PPC64_TLSLD:
14222 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0
14223 && rel + 1 < relend)
14225 unsigned int insn2;
14226 bfd_vma offset = rel->r_offset;
14229 sec = local_sections[toc_symndx];
14231 r_symndx < symtab_hdr->sh_info;
14233 if (local_sections[r_symndx] == sec)
14235 if (r_symndx >= symtab_hdr->sh_info)
14236 r_symndx = STN_UNDEF;
14237 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
14238 if (r_symndx != STN_UNDEF)
14239 rel->r_addend -= (local_syms[r_symndx].st_value
14240 + sec->output_offset
14241 + sec->output_section->vma);
14243 r_type = R_PPC64_TPREL16_LO;
14244 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14245 rel->r_offset = offset + d_offset;
14246 /* Zap the reloc on the _tls_get_addr call too. */
14247 BFD_ASSERT (offset == rel[1].r_offset);
14248 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
14249 insn2 = 0x38630000; /* addi 3,3,0 */
14250 bfd_put_32 (input_bfd, insn2, contents + offset);
14255 case R_PPC64_DTPMOD64:
14256 if (rel + 1 < relend
14257 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
14258 && rel[1].r_offset == rel->r_offset + 8)
14260 if ((tls_mask & TLS_GD) == 0)
14262 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
14263 if ((tls_mask & TLS_TPRELGD) != 0)
14264 r_type = R_PPC64_TPREL64;
14267 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
14268 r_type = R_PPC64_NONE;
14270 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14275 if ((tls_mask & TLS_LD) == 0)
14277 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
14278 r_type = R_PPC64_NONE;
14279 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14284 case R_PPC64_TPREL64:
14285 if ((tls_mask & TLS_TPREL) == 0)
14287 r_type = R_PPC64_NONE;
14288 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14292 case R_PPC64_ENTRY:
14293 relocation = TOCstart + htab->sec_info[input_section->id].toc_off;
14294 if (!bfd_link_pic (info)
14295 && !info->traditional_format
14296 && relocation + 0x80008000 <= 0xffffffff)
14298 unsigned int insn1, insn2;
14300 insn1 = bfd_get_32 (input_bfd, contents + rel->r_offset);
14301 insn2 = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
14302 if ((insn1 & ~0xfffc) == LD_R2_0R12
14303 && insn2 == ADD_R2_R2_R12)
14305 bfd_put_32 (input_bfd,
14306 LIS_R2 + PPC_HA (relocation),
14307 contents + rel->r_offset);
14308 bfd_put_32 (input_bfd,
14309 ADDI_R2_R2 + PPC_LO (relocation),
14310 contents + rel->r_offset + 4);
14315 relocation -= (rel->r_offset
14316 + input_section->output_offset
14317 + input_section->output_section->vma);
14318 if (relocation + 0x80008000 <= 0xffffffff)
14320 unsigned int insn1, insn2;
14322 insn1 = bfd_get_32 (input_bfd, contents + rel->r_offset);
14323 insn2 = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
14324 if ((insn1 & ~0xfffc) == LD_R2_0R12
14325 && insn2 == ADD_R2_R2_R12)
14327 bfd_put_32 (input_bfd,
14328 ADDIS_R2_R12 + PPC_HA (relocation),
14329 contents + rel->r_offset);
14330 bfd_put_32 (input_bfd,
14331 ADDI_R2_R2 + PPC_LO (relocation),
14332 contents + rel->r_offset + 4);
14338 case R_PPC64_REL16_HA:
14339 /* If we are generating a non-PIC executable, edit
14340 . 0: addis 2,12,.TOC.-0b@ha
14341 . addi 2,2,.TOC.-0b@l
14342 used by ELFv2 global entry points to set up r2, to
14345 if .TOC. is in range. */
14346 if (!bfd_link_pic (info)
14347 && !info->traditional_format
14349 && rel->r_addend == d_offset
14350 && h != NULL && &h->elf == htab->elf.hgot
14351 && rel + 1 < relend
14352 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_REL16_LO)
14353 && rel[1].r_offset == rel->r_offset + 4
14354 && rel[1].r_addend == rel->r_addend + 4
14355 && relocation + 0x80008000 <= 0xffffffff)
14357 unsigned int insn1, insn2;
14358 bfd_vma offset = rel->r_offset - d_offset;
14359 insn1 = bfd_get_32 (input_bfd, contents + offset);
14360 insn2 = bfd_get_32 (input_bfd, contents + offset + 4);
14361 if ((insn1 & 0xffff0000) == ADDIS_R2_R12
14362 && (insn2 & 0xffff0000) == ADDI_R2_R2)
14364 r_type = R_PPC64_ADDR16_HA;
14365 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14366 rel->r_addend -= d_offset;
14367 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_ADDR16_LO);
14368 rel[1].r_addend -= d_offset + 4;
14369 bfd_put_32 (input_bfd, LIS_R2, contents + offset);
14375 /* Handle other relocations that tweak non-addend part of insn. */
14377 max_br_offset = 1 << 25;
14378 addend = rel->r_addend;
14379 reloc_dest = DEST_NORMAL;
14385 case R_PPC64_TOCSAVE:
14386 if (relocation + addend == (rel->r_offset
14387 + input_section->output_offset
14388 + input_section->output_section->vma)
14389 && tocsave_find (htab, NO_INSERT,
14390 &local_syms, rel, input_bfd))
14392 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
14394 || insn == CROR_151515 || insn == CROR_313131)
14395 bfd_put_32 (input_bfd,
14396 STD_R2_0R1 + STK_TOC (htab),
14397 contents + rel->r_offset);
14401 /* Branch taken prediction relocations. */
14402 case R_PPC64_ADDR14_BRTAKEN:
14403 case R_PPC64_REL14_BRTAKEN:
14404 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14405 /* Fall through. */
14407 /* Branch not taken prediction relocations. */
14408 case R_PPC64_ADDR14_BRNTAKEN:
14409 case R_PPC64_REL14_BRNTAKEN:
14410 insn |= bfd_get_32 (input_bfd,
14411 contents + rel->r_offset) & ~(0x01 << 21);
14412 /* Fall through. */
14414 case R_PPC64_REL14:
14415 max_br_offset = 1 << 15;
14416 /* Fall through. */
14418 case R_PPC64_REL24:
14419 /* Calls to functions with a different TOC, such as calls to
14420 shared objects, need to alter the TOC pointer. This is
14421 done using a linkage stub. A REL24 branching to these
14422 linkage stubs needs to be followed by a nop, as the nop
14423 will be replaced with an instruction to restore the TOC
14428 && h->oh->is_func_descriptor)
14429 fdh = ppc_follow_link (h->oh);
14430 stub_entry = ppc_get_stub_entry (input_section, sec, fdh, &orig_rel,
14432 if (stub_entry != NULL
14433 && (stub_entry->stub_type == ppc_stub_plt_call
14434 || stub_entry->stub_type == ppc_stub_plt_call_r2save
14435 || stub_entry->stub_type == ppc_stub_plt_branch_r2off
14436 || stub_entry->stub_type == ppc_stub_long_branch_r2off))
14438 bfd_boolean can_plt_call = FALSE;
14440 if (stub_entry->stub_type == ppc_stub_plt_call
14442 && htab->params->plt_localentry0 != 0
14443 && is_elfv2_localentry0 (&h->elf))
14445 /* The function doesn't use or change r2. */
14446 can_plt_call = TRUE;
14449 /* All of these stubs may modify r2, so there must be a
14450 branch and link followed by a nop. The nop is
14451 replaced by an insn to restore r2. */
14452 else if (rel->r_offset + 8 <= input_section->size)
14456 br = bfd_get_32 (input_bfd,
14457 contents + rel->r_offset);
14462 nop = bfd_get_32 (input_bfd,
14463 contents + rel->r_offset + 4);
14465 || nop == CROR_151515 || nop == CROR_313131)
14468 && (h == htab->tls_get_addr_fd
14469 || h == htab->tls_get_addr)
14470 && htab->params->tls_get_addr_opt)
14472 /* Special stub used, leave nop alone. */
14475 bfd_put_32 (input_bfd,
14476 LD_R2_0R1 + STK_TOC (htab),
14477 contents + rel->r_offset + 4);
14478 can_plt_call = TRUE;
14483 if (!can_plt_call && h != NULL)
14485 const char *name = h->elf.root.root.string;
14490 if (strncmp (name, "__libc_start_main", 17) == 0
14491 && (name[17] == 0 || name[17] == '@'))
14493 /* Allow crt1 branch to go via a toc adjusting
14494 stub. Other calls that never return could do
14495 the same, if we could detect such. */
14496 can_plt_call = TRUE;
14502 /* g++ as of 20130507 emits self-calls without a
14503 following nop. This is arguably wrong since we
14504 have conflicting information. On the one hand a
14505 global symbol and on the other a local call
14506 sequence, but don't error for this special case.
14507 It isn't possible to cheaply verify we have
14508 exactly such a call. Allow all calls to the same
14510 asection *code_sec = sec;
14512 if (get_opd_info (sec) != NULL)
14514 bfd_vma off = (relocation + addend
14515 - sec->output_section->vma
14516 - sec->output_offset);
14518 opd_entry_value (sec, off, &code_sec, NULL, FALSE);
14520 if (code_sec == input_section)
14521 can_plt_call = TRUE;
14526 if (stub_entry->stub_type == ppc_stub_plt_call
14527 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
14528 info->callbacks->einfo
14529 /* xgettext:c-format */
14530 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14531 "recompile with -fPIC\n"),
14532 input_bfd, input_section, rel->r_offset, sym_name);
14534 info->callbacks->einfo
14535 /* xgettext:c-format */
14536 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14537 "(-mcmodel=small toc adjust stub)\n"),
14538 input_bfd, input_section, rel->r_offset, sym_name);
14540 bfd_set_error (bfd_error_bad_value);
14545 && (stub_entry->stub_type == ppc_stub_plt_call
14546 || stub_entry->stub_type == ppc_stub_plt_call_r2save))
14547 unresolved_reloc = FALSE;
14550 if ((stub_entry == NULL
14551 || stub_entry->stub_type == ppc_stub_long_branch
14552 || stub_entry->stub_type == ppc_stub_plt_branch)
14553 && get_opd_info (sec) != NULL)
14555 /* The branch destination is the value of the opd entry. */
14556 bfd_vma off = (relocation + addend
14557 - sec->output_section->vma
14558 - sec->output_offset);
14559 bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, FALSE);
14560 if (dest != (bfd_vma) -1)
14564 reloc_dest = DEST_OPD;
14568 /* If the branch is out of reach we ought to have a long
14570 from = (rel->r_offset
14571 + input_section->output_offset
14572 + input_section->output_section->vma);
14574 relocation += PPC64_LOCAL_ENTRY_OFFSET (fdh
14578 if (stub_entry != NULL
14579 && (stub_entry->stub_type == ppc_stub_long_branch
14580 || stub_entry->stub_type == ppc_stub_plt_branch)
14581 && (r_type == R_PPC64_ADDR14_BRTAKEN
14582 || r_type == R_PPC64_ADDR14_BRNTAKEN
14583 || (relocation + addend - from + max_br_offset
14584 < 2 * max_br_offset)))
14585 /* Don't use the stub if this branch is in range. */
14588 if (stub_entry != NULL)
14590 /* Munge up the value and addend so that we call the stub
14591 rather than the procedure directly. */
14592 asection *stub_sec = stub_entry->group->stub_sec;
14594 if (stub_entry->stub_type == ppc_stub_save_res)
14595 relocation += (stub_sec->output_offset
14596 + stub_sec->output_section->vma
14597 + stub_sec->size - htab->sfpr->size
14598 - htab->sfpr->output_offset
14599 - htab->sfpr->output_section->vma);
14601 relocation = (stub_entry->stub_offset
14602 + stub_sec->output_offset
14603 + stub_sec->output_section->vma);
14605 reloc_dest = DEST_STUB;
14607 if ((stub_entry->stub_type == ppc_stub_plt_call
14608 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
14609 && (ALWAYS_EMIT_R2SAVE
14610 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
14611 && rel + 1 < relend
14612 && rel[1].r_offset == rel->r_offset + 4
14613 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
14621 /* Set 'a' bit. This is 0b00010 in BO field for branch
14622 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14623 for branch on CTR insns (BO == 1a00t or 1a01t). */
14624 if ((insn & (0x14 << 21)) == (0x04 << 21))
14625 insn |= 0x02 << 21;
14626 else if ((insn & (0x14 << 21)) == (0x10 << 21))
14627 insn |= 0x08 << 21;
14633 /* Invert 'y' bit if not the default. */
14634 if ((bfd_signed_vma) (relocation + addend - from) < 0)
14635 insn ^= 0x01 << 21;
14638 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
14641 /* NOP out calls to undefined weak functions.
14642 We can thus call a weak function without first
14643 checking whether the function is defined. */
14645 && h->elf.root.type == bfd_link_hash_undefweak
14646 && h->elf.dynindx == -1
14647 && r_type == R_PPC64_REL24
14651 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
14657 /* Set `addend'. */
14662 /* xgettext:c-format */
14663 _bfd_error_handler (_("%pB: %s unsupported"),
14664 input_bfd, ppc64_elf_howto_table[r_type]->name);
14666 bfd_set_error (bfd_error_bad_value);
14672 case R_PPC64_TLSGD:
14673 case R_PPC64_TLSLD:
14674 case R_PPC64_TOCSAVE:
14675 case R_PPC64_GNU_VTINHERIT:
14676 case R_PPC64_GNU_VTENTRY:
14677 case R_PPC64_ENTRY:
14680 /* GOT16 relocations. Like an ADDR16 using the symbol's
14681 address in the GOT as relocation value instead of the
14682 symbol's value itself. Also, create a GOT entry for the
14683 symbol and put the symbol value there. */
14684 case R_PPC64_GOT_TLSGD16:
14685 case R_PPC64_GOT_TLSGD16_LO:
14686 case R_PPC64_GOT_TLSGD16_HI:
14687 case R_PPC64_GOT_TLSGD16_HA:
14688 tls_type = TLS_TLS | TLS_GD;
14691 case R_PPC64_GOT_TLSLD16:
14692 case R_PPC64_GOT_TLSLD16_LO:
14693 case R_PPC64_GOT_TLSLD16_HI:
14694 case R_PPC64_GOT_TLSLD16_HA:
14695 tls_type = TLS_TLS | TLS_LD;
14698 case R_PPC64_GOT_TPREL16_DS:
14699 case R_PPC64_GOT_TPREL16_LO_DS:
14700 case R_PPC64_GOT_TPREL16_HI:
14701 case R_PPC64_GOT_TPREL16_HA:
14702 tls_type = TLS_TLS | TLS_TPREL;
14705 case R_PPC64_GOT_DTPREL16_DS:
14706 case R_PPC64_GOT_DTPREL16_LO_DS:
14707 case R_PPC64_GOT_DTPREL16_HI:
14708 case R_PPC64_GOT_DTPREL16_HA:
14709 tls_type = TLS_TLS | TLS_DTPREL;
14712 case R_PPC64_GOT16:
14713 case R_PPC64_GOT16_LO:
14714 case R_PPC64_GOT16_HI:
14715 case R_PPC64_GOT16_HA:
14716 case R_PPC64_GOT16_DS:
14717 case R_PPC64_GOT16_LO_DS:
14720 /* Relocation is to the entry for this symbol in the global
14725 unsigned long indx = 0;
14726 struct got_entry *ent;
14728 if (tls_type == (TLS_TLS | TLS_LD)
14730 || !h->elf.def_dynamic))
14731 ent = ppc64_tlsld_got (input_bfd);
14736 if (!htab->elf.dynamic_sections_created
14737 || h->elf.dynindx == -1
14738 || SYMBOL_REFERENCES_LOCAL (info, &h->elf)
14739 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf))
14740 /* This is actually a static link, or it is a
14741 -Bsymbolic link and the symbol is defined
14742 locally, or the symbol was forced to be local
14743 because of a version file. */
14747 indx = h->elf.dynindx;
14748 unresolved_reloc = FALSE;
14750 ent = h->elf.got.glist;
14754 if (local_got_ents == NULL)
14756 ent = local_got_ents[r_symndx];
14759 for (; ent != NULL; ent = ent->next)
14760 if (ent->addend == orig_rel.r_addend
14761 && ent->owner == input_bfd
14762 && ent->tls_type == tls_type)
14768 if (ent->is_indirect)
14769 ent = ent->got.ent;
14770 offp = &ent->got.offset;
14771 got = ppc64_elf_tdata (ent->owner)->got;
14775 /* The offset must always be a multiple of 8. We use the
14776 least significant bit to record whether we have already
14777 processed this entry. */
14779 if ((off & 1) != 0)
14783 /* Generate relocs for the dynamic linker, except in
14784 the case of TLSLD where we'll use one entry per
14792 ? h->elf.type == STT_GNU_IFUNC
14793 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
14796 relgot = htab->elf.irelplt;
14798 htab->local_ifunc_resolver = 1;
14799 else if (is_static_defined (&h->elf))
14800 htab->maybe_local_ifunc_resolver = 1;
14803 || (bfd_link_pic (info)
14805 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf)
14806 || (tls_type == (TLS_TLS | TLS_LD)
14807 && !h->elf.def_dynamic))
14808 && !(tls_type == (TLS_TLS | TLS_TPREL)
14809 && bfd_link_executable (info)
14810 && SYMBOL_REFERENCES_LOCAL (info, &h->elf))))
14811 relgot = ppc64_elf_tdata (ent->owner)->relgot;
14812 if (relgot != NULL)
14814 outrel.r_offset = (got->output_section->vma
14815 + got->output_offset
14817 outrel.r_addend = addend;
14818 if (tls_type & (TLS_LD | TLS_GD))
14820 outrel.r_addend = 0;
14821 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
14822 if (tls_type == (TLS_TLS | TLS_GD))
14824 loc = relgot->contents;
14825 loc += (relgot->reloc_count++
14826 * sizeof (Elf64_External_Rela));
14827 bfd_elf64_swap_reloca_out (output_bfd,
14829 outrel.r_offset += 8;
14830 outrel.r_addend = addend;
14832 = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
14835 else if (tls_type == (TLS_TLS | TLS_DTPREL))
14836 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
14837 else if (tls_type == (TLS_TLS | TLS_TPREL))
14838 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
14839 else if (indx != 0)
14840 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
14844 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14846 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
14848 /* Write the .got section contents for the sake
14850 loc = got->contents + off;
14851 bfd_put_64 (output_bfd, outrel.r_addend + relocation,
14855 if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
14857 outrel.r_addend += relocation;
14858 if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
14860 if (htab->elf.tls_sec == NULL)
14861 outrel.r_addend = 0;
14863 outrel.r_addend -= htab->elf.tls_sec->vma;
14866 loc = relgot->contents;
14867 loc += (relgot->reloc_count++
14868 * sizeof (Elf64_External_Rela));
14869 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
14872 /* Init the .got section contents here if we're not
14873 emitting a reloc. */
14876 relocation += addend;
14879 if (htab->elf.tls_sec == NULL)
14883 if (tls_type & TLS_LD)
14886 relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
14887 if (tls_type & TLS_TPREL)
14888 relocation += DTP_OFFSET - TP_OFFSET;
14891 if (tls_type & (TLS_GD | TLS_LD))
14893 bfd_put_64 (output_bfd, relocation,
14894 got->contents + off + 8);
14898 bfd_put_64 (output_bfd, relocation,
14899 got->contents + off);
14903 if (off >= (bfd_vma) -2)
14906 relocation = got->output_section->vma + got->output_offset + off;
14907 addend = -(TOCstart + htab->sec_info[input_section->id].toc_off);
14911 case R_PPC64_PLT16_HA:
14912 case R_PPC64_PLT16_HI:
14913 case R_PPC64_PLT16_LO:
14914 case R_PPC64_PLT16_LO_DS:
14915 case R_PPC64_PLT32:
14916 case R_PPC64_PLT64:
14917 /* Relocation is to the entry for this symbol in the
14918 procedure linkage table. */
14920 struct plt_entry **plt_list = NULL;
14922 plt_list = &h->elf.plt.plist;
14923 else if (local_got_ents != NULL)
14925 struct plt_entry **local_plt = (struct plt_entry **)
14926 (local_got_ents + symtab_hdr->sh_info);
14927 plt_list = local_plt + r_symndx;
14931 struct plt_entry *ent;
14933 for (ent = *plt_list; ent != NULL; ent = ent->next)
14934 if (ent->plt.offset != (bfd_vma) -1
14935 && ent->addend == orig_rel.r_addend)
14940 plt = htab->elf.splt;
14941 if (!htab->elf.dynamic_sections_created
14943 || h->elf.dynindx == -1)
14946 ? h->elf.type == STT_GNU_IFUNC
14947 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14948 plt = htab->elf.iplt;
14950 plt = htab->pltlocal;
14952 relocation = (plt->output_section->vma
14953 + plt->output_offset
14954 + ent->plt.offset);
14955 if (r_type == R_PPC64_PLT16_HA
14956 || r_type ==R_PPC64_PLT16_HI
14957 || r_type ==R_PPC64_PLT16_LO
14958 || r_type ==R_PPC64_PLT16_LO_DS)
14960 got = (elf_gp (output_bfd)
14961 + htab->sec_info[input_section->id].toc_off);
14965 unresolved_reloc = FALSE;
14973 /* Relocation value is TOC base. */
14974 relocation = TOCstart;
14975 if (r_symndx == STN_UNDEF)
14976 relocation += htab->sec_info[input_section->id].toc_off;
14977 else if (unresolved_reloc)
14979 else if (sec != NULL && sec->id < htab->sec_info_arr_size)
14980 relocation += htab->sec_info[sec->id].toc_off;
14982 unresolved_reloc = TRUE;
14985 /* TOC16 relocs. We want the offset relative to the TOC base,
14986 which is the address of the start of the TOC plus 0x8000.
14987 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14989 case R_PPC64_TOC16:
14990 case R_PPC64_TOC16_LO:
14991 case R_PPC64_TOC16_HI:
14992 case R_PPC64_TOC16_DS:
14993 case R_PPC64_TOC16_LO_DS:
14994 case R_PPC64_TOC16_HA:
14995 addend -= TOCstart + htab->sec_info[input_section->id].toc_off;
14998 /* Relocate against the beginning of the section. */
14999 case R_PPC64_SECTOFF:
15000 case R_PPC64_SECTOFF_LO:
15001 case R_PPC64_SECTOFF_HI:
15002 case R_PPC64_SECTOFF_DS:
15003 case R_PPC64_SECTOFF_LO_DS:
15004 case R_PPC64_SECTOFF_HA:
15006 addend -= sec->output_section->vma;
15009 case R_PPC64_REL16:
15010 case R_PPC64_REL16_LO:
15011 case R_PPC64_REL16_HI:
15012 case R_PPC64_REL16_HA:
15013 case R_PPC64_REL16DX_HA:
15016 case R_PPC64_REL14:
15017 case R_PPC64_REL14_BRNTAKEN:
15018 case R_PPC64_REL14_BRTAKEN:
15019 case R_PPC64_REL24:
15022 case R_PPC64_TPREL16:
15023 case R_PPC64_TPREL16_LO:
15024 case R_PPC64_TPREL16_HI:
15025 case R_PPC64_TPREL16_HA:
15026 case R_PPC64_TPREL16_DS:
15027 case R_PPC64_TPREL16_LO_DS:
15028 case R_PPC64_TPREL16_HIGH:
15029 case R_PPC64_TPREL16_HIGHA:
15030 case R_PPC64_TPREL16_HIGHER:
15031 case R_PPC64_TPREL16_HIGHERA:
15032 case R_PPC64_TPREL16_HIGHEST:
15033 case R_PPC64_TPREL16_HIGHESTA:
15035 && h->elf.root.type == bfd_link_hash_undefweak
15036 && h->elf.dynindx == -1)
15038 /* Make this relocation against an undefined weak symbol
15039 resolve to zero. This is really just a tweak, since
15040 code using weak externs ought to check that they are
15041 defined before using them. */
15042 bfd_byte *p = contents + rel->r_offset - d_offset;
15044 insn = bfd_get_32 (input_bfd, p);
15045 insn = _bfd_elf_ppc_at_tprel_transform (insn, 13);
15047 bfd_put_32 (input_bfd, insn, p);
15050 if (htab->elf.tls_sec != NULL)
15051 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
15052 /* The TPREL16 relocs shouldn't really be used in shared
15053 libs or with non-local symbols as that will result in
15054 DT_TEXTREL being set, but support them anyway. */
15057 case R_PPC64_DTPREL16:
15058 case R_PPC64_DTPREL16_LO:
15059 case R_PPC64_DTPREL16_HI:
15060 case R_PPC64_DTPREL16_HA:
15061 case R_PPC64_DTPREL16_DS:
15062 case R_PPC64_DTPREL16_LO_DS:
15063 case R_PPC64_DTPREL16_HIGH:
15064 case R_PPC64_DTPREL16_HIGHA:
15065 case R_PPC64_DTPREL16_HIGHER:
15066 case R_PPC64_DTPREL16_HIGHERA:
15067 case R_PPC64_DTPREL16_HIGHEST:
15068 case R_PPC64_DTPREL16_HIGHESTA:
15069 if (htab->elf.tls_sec != NULL)
15070 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
15073 case R_PPC64_ADDR64_LOCAL:
15074 addend += PPC64_LOCAL_ENTRY_OFFSET (h != NULL
15079 case R_PPC64_DTPMOD64:
15084 case R_PPC64_TPREL64:
15085 if (htab->elf.tls_sec != NULL)
15086 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
15089 case R_PPC64_DTPREL64:
15090 if (htab->elf.tls_sec != NULL)
15091 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
15092 /* Fall through. */
15094 /* Relocations that may need to be propagated if this is a
15096 case R_PPC64_REL30:
15097 case R_PPC64_REL32:
15098 case R_PPC64_REL64:
15099 case R_PPC64_ADDR14:
15100 case R_PPC64_ADDR14_BRNTAKEN:
15101 case R_PPC64_ADDR14_BRTAKEN:
15102 case R_PPC64_ADDR16:
15103 case R_PPC64_ADDR16_DS:
15104 case R_PPC64_ADDR16_HA:
15105 case R_PPC64_ADDR16_HI:
15106 case R_PPC64_ADDR16_HIGH:
15107 case R_PPC64_ADDR16_HIGHA:
15108 case R_PPC64_ADDR16_HIGHER:
15109 case R_PPC64_ADDR16_HIGHERA:
15110 case R_PPC64_ADDR16_HIGHEST:
15111 case R_PPC64_ADDR16_HIGHESTA:
15112 case R_PPC64_ADDR16_LO:
15113 case R_PPC64_ADDR16_LO_DS:
15114 case R_PPC64_ADDR24:
15115 case R_PPC64_ADDR32:
15116 case R_PPC64_ADDR64:
15117 case R_PPC64_UADDR16:
15118 case R_PPC64_UADDR32:
15119 case R_PPC64_UADDR64:
15121 if ((input_section->flags & SEC_ALLOC) == 0)
15124 if (NO_OPD_RELOCS && is_opd)
15127 if (bfd_link_pic (info)
15129 || h->dyn_relocs != NULL)
15130 && ((h != NULL && pc_dynrelocs (h))
15131 || must_be_dyn_reloc (info, r_type)))
15133 ? h->dyn_relocs != NULL
15134 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
15136 bfd_boolean skip, relocate;
15141 /* When generating a dynamic object, these relocations
15142 are copied into the output file to be resolved at run
15148 out_off = _bfd_elf_section_offset (output_bfd, info,
15149 input_section, rel->r_offset);
15150 if (out_off == (bfd_vma) -1)
15152 else if (out_off == (bfd_vma) -2)
15153 skip = TRUE, relocate = TRUE;
15154 out_off += (input_section->output_section->vma
15155 + input_section->output_offset);
15156 outrel.r_offset = out_off;
15157 outrel.r_addend = rel->r_addend;
15159 /* Optimize unaligned reloc use. */
15160 if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
15161 || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
15162 r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
15163 else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
15164 || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
15165 r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
15166 else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
15167 || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
15168 r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
15171 memset (&outrel, 0, sizeof outrel);
15172 else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
15174 && r_type != R_PPC64_TOC)
15176 indx = h->elf.dynindx;
15177 BFD_ASSERT (indx != -1);
15178 outrel.r_info = ELF64_R_INFO (indx, r_type);
15182 /* This symbol is local, or marked to become local,
15183 or this is an opd section reloc which must point
15184 at a local function. */
15185 outrel.r_addend += relocation;
15186 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
15188 if (is_opd && h != NULL)
15190 /* Lie about opd entries. This case occurs
15191 when building shared libraries and we
15192 reference a function in another shared
15193 lib. The same thing happens for a weak
15194 definition in an application that's
15195 overridden by a strong definition in a
15196 shared lib. (I believe this is a generic
15197 bug in binutils handling of weak syms.)
15198 In these cases we won't use the opd
15199 entry in this lib. */
15200 unresolved_reloc = FALSE;
15203 && r_type == R_PPC64_ADDR64
15205 ? h->elf.type == STT_GNU_IFUNC
15206 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
15207 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
15210 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
15212 /* We need to relocate .opd contents for ld.so.
15213 Prelink also wants simple and consistent rules
15214 for relocs. This make all RELATIVE relocs have
15215 *r_offset equal to r_addend. */
15222 ? h->elf.type == STT_GNU_IFUNC
15223 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
15225 info->callbacks->einfo
15226 /* xgettext:c-format */
15227 (_("%H: %s for indirect "
15228 "function `%pT' unsupported\n"),
15229 input_bfd, input_section, rel->r_offset,
15230 ppc64_elf_howto_table[r_type]->name,
15234 else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
15236 else if (sec == NULL || sec->owner == NULL)
15238 bfd_set_error (bfd_error_bad_value);
15245 osec = sec->output_section;
15246 indx = elf_section_data (osec)->dynindx;
15250 if ((osec->flags & SEC_READONLY) == 0
15251 && htab->elf.data_index_section != NULL)
15252 osec = htab->elf.data_index_section;
15254 osec = htab->elf.text_index_section;
15255 indx = elf_section_data (osec)->dynindx;
15257 BFD_ASSERT (indx != 0);
15259 /* We are turning this relocation into one
15260 against a section symbol, so subtract out
15261 the output section's address but not the
15262 offset of the input section in the output
15264 outrel.r_addend -= osec->vma;
15267 outrel.r_info = ELF64_R_INFO (indx, r_type);
15271 sreloc = elf_section_data (input_section)->sreloc;
15273 ? h->elf.type == STT_GNU_IFUNC
15274 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
15276 sreloc = htab->elf.irelplt;
15278 htab->local_ifunc_resolver = 1;
15279 else if (is_static_defined (&h->elf))
15280 htab->maybe_local_ifunc_resolver = 1;
15282 if (sreloc == NULL)
15285 if (sreloc->reloc_count * sizeof (Elf64_External_Rela)
15288 loc = sreloc->contents;
15289 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
15290 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
15292 /* If this reloc is against an external symbol, it will
15293 be computed at runtime, so there's no need to do
15294 anything now. However, for the sake of prelink ensure
15295 that the section contents are a known value. */
15298 unresolved_reloc = FALSE;
15299 /* The value chosen here is quite arbitrary as ld.so
15300 ignores section contents except for the special
15301 case of .opd where the contents might be accessed
15302 before relocation. Choose zero, as that won't
15303 cause reloc overflow. */
15306 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
15307 to improve backward compatibility with older
15309 if (r_type == R_PPC64_ADDR64)
15310 addend = outrel.r_addend;
15311 /* Adjust pc_relative relocs to have zero in *r_offset. */
15312 else if (ppc64_elf_howto_table[r_type]->pc_relative)
15313 addend = outrel.r_offset;
15319 case R_PPC64_GLOB_DAT:
15320 case R_PPC64_JMP_SLOT:
15321 case R_PPC64_JMP_IREL:
15322 case R_PPC64_RELATIVE:
15323 /* We shouldn't ever see these dynamic relocs in relocatable
15325 /* Fall through. */
15327 case R_PPC64_PLTGOT16:
15328 case R_PPC64_PLTGOT16_DS:
15329 case R_PPC64_PLTGOT16_HA:
15330 case R_PPC64_PLTGOT16_HI:
15331 case R_PPC64_PLTGOT16_LO:
15332 case R_PPC64_PLTGOT16_LO_DS:
15333 case R_PPC64_PLTREL32:
15334 case R_PPC64_PLTREL64:
15335 /* These ones haven't been implemented yet. */
15337 info->callbacks->einfo
15338 /* xgettext:c-format */
15339 (_("%P: %pB: %s is not supported for `%pT'\n"),
15341 ppc64_elf_howto_table[r_type]->name, sym_name);
15343 bfd_set_error (bfd_error_invalid_operation);
15348 /* Multi-instruction sequences that access the TOC can be
15349 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15350 to nop; addi rb,r2,x; */
15356 case R_PPC64_GOT_TLSLD16_HI:
15357 case R_PPC64_GOT_TLSGD16_HI:
15358 case R_PPC64_GOT_TPREL16_HI:
15359 case R_PPC64_GOT_DTPREL16_HI:
15360 case R_PPC64_GOT16_HI:
15361 case R_PPC64_TOC16_HI:
15362 /* These relocs would only be useful if building up an
15363 offset to later add to r2, perhaps in an indexed
15364 addressing mode instruction. Don't try to optimize.
15365 Unfortunately, the possibility of someone building up an
15366 offset like this or even with the HA relocs, means that
15367 we need to check the high insn when optimizing the low
15371 case R_PPC64_GOT_TLSLD16_HA:
15372 case R_PPC64_GOT_TLSGD16_HA:
15373 case R_PPC64_GOT_TPREL16_HA:
15374 case R_PPC64_GOT_DTPREL16_HA:
15375 case R_PPC64_GOT16_HA:
15376 case R_PPC64_TOC16_HA:
15377 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
15378 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
15380 bfd_byte *p = contents + (rel->r_offset & ~3);
15381 bfd_put_32 (input_bfd, NOP, p);
15386 case R_PPC64_GOT_TLSLD16_LO:
15387 case R_PPC64_GOT_TLSGD16_LO:
15388 case R_PPC64_GOT_TPREL16_LO_DS:
15389 case R_PPC64_GOT_DTPREL16_LO_DS:
15390 case R_PPC64_GOT16_LO:
15391 case R_PPC64_GOT16_LO_DS:
15392 case R_PPC64_TOC16_LO:
15393 case R_PPC64_TOC16_LO_DS:
15394 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
15395 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
15397 bfd_byte *p = contents + (rel->r_offset & ~3);
15398 insn = bfd_get_32 (input_bfd, p);
15399 if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
15401 /* Transform addic to addi when we change reg. */
15402 insn &= ~((0x3f << 26) | (0x1f << 16));
15403 insn |= (14u << 26) | (2 << 16);
15407 insn &= ~(0x1f << 16);
15410 bfd_put_32 (input_bfd, insn, p);
15414 case R_PPC64_TPREL16_HA:
15415 if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
15417 bfd_byte *p = contents + (rel->r_offset & ~3);
15418 insn = bfd_get_32 (input_bfd, p);
15419 if ((insn & ((0x3f << 26) | 0x1f << 16))
15420 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15421 /* xgettext:c-format */
15422 info->callbacks->minfo
15423 (_("%H: warning: %s unexpected insn %#x.\n"),
15424 input_bfd, input_section, rel->r_offset,
15425 ppc64_elf_howto_table[r_type]->name, insn);
15428 bfd_put_32 (input_bfd, NOP, p);
15434 case R_PPC64_TPREL16_LO:
15435 case R_PPC64_TPREL16_LO_DS:
15436 if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
15438 bfd_byte *p = contents + (rel->r_offset & ~3);
15439 insn = bfd_get_32 (input_bfd, p);
15440 insn &= ~(0x1f << 16);
15442 bfd_put_32 (input_bfd, insn, p);
15447 /* Do any further special processing. */
15453 case R_PPC64_REL16_HA:
15454 case R_PPC64_REL16DX_HA:
15455 case R_PPC64_ADDR16_HA:
15456 case R_PPC64_ADDR16_HIGHA:
15457 case R_PPC64_ADDR16_HIGHERA:
15458 case R_PPC64_ADDR16_HIGHESTA:
15459 case R_PPC64_TOC16_HA:
15460 case R_PPC64_SECTOFF_HA:
15461 case R_PPC64_TPREL16_HA:
15462 case R_PPC64_TPREL16_HIGHA:
15463 case R_PPC64_TPREL16_HIGHERA:
15464 case R_PPC64_TPREL16_HIGHESTA:
15465 case R_PPC64_DTPREL16_HA:
15466 case R_PPC64_DTPREL16_HIGHA:
15467 case R_PPC64_DTPREL16_HIGHERA:
15468 case R_PPC64_DTPREL16_HIGHESTA:
15469 /* It's just possible that this symbol is a weak symbol
15470 that's not actually defined anywhere. In that case,
15471 'sec' would be NULL, and we should leave the symbol
15472 alone (it will be set to zero elsewhere in the link). */
15475 /* Fall through. */
15477 case R_PPC64_GOT16_HA:
15478 case R_PPC64_PLTGOT16_HA:
15479 case R_PPC64_PLT16_HA:
15480 case R_PPC64_GOT_TLSGD16_HA:
15481 case R_PPC64_GOT_TLSLD16_HA:
15482 case R_PPC64_GOT_TPREL16_HA:
15483 case R_PPC64_GOT_DTPREL16_HA:
15484 /* Add 0x10000 if sign bit in 0:15 is set.
15485 Bits 0:15 are not used. */
15489 case R_PPC64_ADDR16_DS:
15490 case R_PPC64_ADDR16_LO_DS:
15491 case R_PPC64_GOT16_DS:
15492 case R_PPC64_GOT16_LO_DS:
15493 case R_PPC64_PLT16_LO_DS:
15494 case R_PPC64_SECTOFF_DS:
15495 case R_PPC64_SECTOFF_LO_DS:
15496 case R_PPC64_TOC16_DS:
15497 case R_PPC64_TOC16_LO_DS:
15498 case R_PPC64_PLTGOT16_DS:
15499 case R_PPC64_PLTGOT16_LO_DS:
15500 case R_PPC64_GOT_TPREL16_DS:
15501 case R_PPC64_GOT_TPREL16_LO_DS:
15502 case R_PPC64_GOT_DTPREL16_DS:
15503 case R_PPC64_GOT_DTPREL16_LO_DS:
15504 case R_PPC64_TPREL16_DS:
15505 case R_PPC64_TPREL16_LO_DS:
15506 case R_PPC64_DTPREL16_DS:
15507 case R_PPC64_DTPREL16_LO_DS:
15508 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
15510 /* If this reloc is against an lq, lxv, or stxv insn, then
15511 the value must be a multiple of 16. This is somewhat of
15512 a hack, but the "correct" way to do this by defining _DQ
15513 forms of all the _DS relocs bloats all reloc switches in
15514 this file. It doesn't make much sense to use these
15515 relocs in data, so testing the insn should be safe. */
15516 if ((insn & (0x3f << 26)) == (56u << 26)
15517 || ((insn & (0x3f << 26)) == (61u << 26) && (insn & 3) == 1))
15519 relocation += addend;
15520 addend = insn & (mask ^ 3);
15521 if ((relocation & mask) != 0)
15523 relocation ^= relocation & mask;
15524 info->callbacks->einfo
15525 /* xgettext:c-format */
15526 (_("%H: error: %s not a multiple of %u\n"),
15527 input_bfd, input_section, rel->r_offset,
15528 ppc64_elf_howto_table[r_type]->name,
15530 bfd_set_error (bfd_error_bad_value);
15537 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15538 because such sections are not SEC_ALLOC and thus ld.so will
15539 not process them. */
15540 howto = ppc64_elf_howto_table[(int) r_type];
15541 if (unresolved_reloc
15542 && !((input_section->flags & SEC_DEBUGGING) != 0
15543 && h->elf.def_dynamic)
15544 && _bfd_elf_section_offset (output_bfd, info, input_section,
15545 rel->r_offset) != (bfd_vma) -1)
15547 info->callbacks->einfo
15548 /* xgettext:c-format */
15549 (_("%H: unresolvable %s against `%pT'\n"),
15550 input_bfd, input_section, rel->r_offset,
15552 h->elf.root.root.string);
15556 /* 16-bit fields in insns mostly have signed values, but a
15557 few insns have 16-bit unsigned values. Really, we should
15558 have different reloc types. */
15559 if (howto->complain_on_overflow != complain_overflow_dont
15560 && howto->dst_mask == 0xffff
15561 && (input_section->flags & SEC_CODE) != 0)
15563 enum complain_overflow complain = complain_overflow_signed;
15565 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
15566 if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
15567 complain = complain_overflow_bitfield;
15568 else if (howto->rightshift == 0
15569 ? ((insn & (0x3f << 26)) == 28u << 26 /* andi */
15570 || (insn & (0x3f << 26)) == 24u << 26 /* ori */
15571 || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
15572 : ((insn & (0x3f << 26)) == 29u << 26 /* andis */
15573 || (insn & (0x3f << 26)) == 25u << 26 /* oris */
15574 || (insn & (0x3f << 26)) == 27u << 26 /* xoris */))
15575 complain = complain_overflow_unsigned;
15576 if (howto->complain_on_overflow != complain)
15578 alt_howto = *howto;
15579 alt_howto.complain_on_overflow = complain;
15580 howto = &alt_howto;
15584 if (r_type == R_PPC64_REL16DX_HA)
15586 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15587 if (rel->r_offset + 4 > input_section->size)
15588 r = bfd_reloc_outofrange;
15591 relocation += addend;
15592 relocation -= (rel->r_offset
15593 + input_section->output_offset
15594 + input_section->output_section->vma);
15595 relocation = (bfd_signed_vma) relocation >> 16;
15596 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
15598 insn |= (relocation & 0xffc1) | ((relocation & 0x3e) << 15);
15599 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
15601 if (relocation + 0x8000 > 0xffff)
15602 r = bfd_reloc_overflow;
15606 r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
15607 rel->r_offset, relocation, addend);
15609 if (r != bfd_reloc_ok)
15611 char *more_info = NULL;
15612 const char *reloc_name = howto->name;
15614 if (reloc_dest != DEST_NORMAL)
15616 more_info = bfd_malloc (strlen (reloc_name) + 8);
15617 if (more_info != NULL)
15619 strcpy (more_info, reloc_name);
15620 strcat (more_info, (reloc_dest == DEST_OPD
15621 ? " (OPD)" : " (stub)"));
15622 reloc_name = more_info;
15626 if (r == bfd_reloc_overflow)
15628 /* On code like "if (foo) foo();" don't report overflow
15629 on a branch to zero when foo is undefined. */
15631 && (reloc_dest == DEST_STUB
15633 && (h->elf.root.type == bfd_link_hash_undefweak
15634 || h->elf.root.type == bfd_link_hash_undefined)
15635 && is_branch_reloc (r_type))))
15636 info->callbacks->reloc_overflow (info, &h->elf.root,
15637 sym_name, reloc_name,
15639 input_bfd, input_section,
15644 info->callbacks->einfo
15645 /* xgettext:c-format */
15646 (_("%H: %s against `%pT': error %d\n"),
15647 input_bfd, input_section, rel->r_offset,
15648 reloc_name, sym_name, (int) r);
15651 if (more_info != NULL)
15661 Elf_Internal_Shdr *rel_hdr;
15662 size_t deleted = rel - wrel;
15664 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
15665 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
15666 if (rel_hdr->sh_size == 0)
15668 /* It is too late to remove an empty reloc section. Leave
15670 ??? What is wrong with an empty section??? */
15671 rel_hdr->sh_size = rel_hdr->sh_entsize;
15674 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
15675 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
15676 input_section->reloc_count -= deleted;
15679 /* If we're emitting relocations, then shortly after this function
15680 returns, reloc offsets and addends for this section will be
15681 adjusted. Worse, reloc symbol indices will be for the output
15682 file rather than the input. Save a copy of the relocs for
15683 opd_entry_value. */
15684 if (is_opd && (info->emitrelocations || bfd_link_relocatable (info)))
15687 amt = input_section->reloc_count * sizeof (Elf_Internal_Rela);
15688 rel = bfd_alloc (input_bfd, amt);
15689 BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd.relocs == NULL);
15690 ppc64_elf_tdata (input_bfd)->opd.relocs = rel;
15693 memcpy (rel, relocs, amt);
15698 /* Adjust the value of any local symbols in opd sections. */
15701 ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
15702 const char *name ATTRIBUTE_UNUSED,
15703 Elf_Internal_Sym *elfsym,
15704 asection *input_sec,
15705 struct elf_link_hash_entry *h)
15707 struct _opd_sec_data *opd;
15714 opd = get_opd_info (input_sec);
15715 if (opd == NULL || opd->adjust == NULL)
15718 value = elfsym->st_value - input_sec->output_offset;
15719 if (!bfd_link_relocatable (info))
15720 value -= input_sec->output_section->vma;
15722 adjust = opd->adjust[OPD_NDX (value)];
15726 elfsym->st_value += adjust;
15730 /* Finish up dynamic symbol handling. We set the contents of various
15731 dynamic sections here. */
15734 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
15735 struct bfd_link_info *info,
15736 struct elf_link_hash_entry *h,
15737 Elf_Internal_Sym *sym)
15739 struct ppc_link_hash_table *htab;
15740 struct plt_entry *ent;
15742 htab = ppc_hash_table (info);
15746 if (!htab->opd_abi && !h->def_regular)
15747 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
15748 if (ent->plt.offset != (bfd_vma) -1)
15750 /* Mark the symbol as undefined, rather than as
15751 defined in glink. Leave the value if there were
15752 any relocations where pointer equality matters
15753 (this is a clue for the dynamic linker, to make
15754 function pointer comparisons work between an
15755 application and shared library), otherwise set it
15757 sym->st_shndx = SHN_UNDEF;
15758 if (!h->pointer_equality_needed)
15760 else if (!h->ref_regular_nonweak)
15762 /* This breaks function pointer comparisons, but
15763 that is better than breaking tests for a NULL
15764 function pointer. */
15772 /* This symbol needs a copy reloc. Set it up. */
15773 Elf_Internal_Rela rela;
15777 if (h->dynindx == -1
15778 || (h->root.type != bfd_link_hash_defined
15779 && h->root.type != bfd_link_hash_defweak)
15780 || htab->elf.srelbss == NULL
15781 || htab->elf.sreldynrelro == NULL)
15784 rela.r_offset = (h->root.u.def.value
15785 + h->root.u.def.section->output_section->vma
15786 + h->root.u.def.section->output_offset);
15787 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
15789 if (h->root.u.def.section == htab->elf.sdynrelro)
15790 srel = htab->elf.sreldynrelro;
15792 srel = htab->elf.srelbss;
15793 loc = srel->contents;
15794 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
15795 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
15801 /* Used to decide how to sort relocs in an optimal manner for the
15802 dynamic linker, before writing them out. */
15804 static enum elf_reloc_type_class
15805 ppc64_elf_reloc_type_class (const struct bfd_link_info *info,
15806 const asection *rel_sec,
15807 const Elf_Internal_Rela *rela)
15809 enum elf_ppc64_reloc_type r_type;
15810 struct ppc_link_hash_table *htab = ppc_hash_table (info);
15812 if (rel_sec == htab->elf.irelplt)
15813 return reloc_class_ifunc;
15815 r_type = ELF64_R_TYPE (rela->r_info);
15818 case R_PPC64_RELATIVE:
15819 return reloc_class_relative;
15820 case R_PPC64_JMP_SLOT:
15821 return reloc_class_plt;
15823 return reloc_class_copy;
15825 return reloc_class_normal;
15829 /* Finish up the dynamic sections. */
15832 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
15833 struct bfd_link_info *info)
15835 struct ppc_link_hash_table *htab;
15839 htab = ppc_hash_table (info);
15843 dynobj = htab->elf.dynobj;
15844 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
15846 if (htab->elf.dynamic_sections_created)
15848 Elf64_External_Dyn *dyncon, *dynconend;
15850 if (sdyn == NULL || htab->elf.sgot == NULL)
15853 dyncon = (Elf64_External_Dyn *) sdyn->contents;
15854 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
15855 for (; dyncon < dynconend; dyncon++)
15857 Elf_Internal_Dyn dyn;
15860 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
15867 case DT_PPC64_GLINK:
15869 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
15870 /* We stupidly defined DT_PPC64_GLINK to be the start
15871 of glink rather than the first entry point, which is
15872 what ld.so needs, and now have a bigger stub to
15873 support automatic multiple TOCs. */
15874 dyn.d_un.d_ptr += GLINK_PLTRESOLVE_SIZE (htab) - 8 * 4;
15878 s = bfd_get_section_by_name (output_bfd, ".opd");
15881 dyn.d_un.d_ptr = s->vma;
15885 if (htab->do_multi_toc && htab->multi_toc_needed)
15886 dyn.d_un.d_val |= PPC64_OPT_MULTI_TOC;
15887 if (htab->has_plt_localentry0)
15888 dyn.d_un.d_val |= PPC64_OPT_LOCALENTRY;
15891 case DT_PPC64_OPDSZ:
15892 s = bfd_get_section_by_name (output_bfd, ".opd");
15895 dyn.d_un.d_val = s->size;
15899 s = htab->elf.splt;
15900 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
15904 s = htab->elf.srelplt;
15905 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
15909 dyn.d_un.d_val = htab->elf.srelplt->size;
15913 if (htab->local_ifunc_resolver)
15914 info->callbacks->einfo
15915 (_("%X%P: text relocations and GNU indirect "
15916 "functions will result in a segfault at runtime\n"));
15917 else if (htab->maybe_local_ifunc_resolver)
15918 info->callbacks->einfo
15919 (_("%P: warning: text relocations and GNU indirect "
15920 "functions may result in a segfault at runtime\n"));
15924 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
15928 if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0
15929 && htab->elf.sgot->output_section != bfd_abs_section_ptr)
15931 /* Fill in the first entry in the global offset table.
15932 We use it to hold the link-time TOCbase. */
15933 bfd_put_64 (output_bfd,
15934 elf_gp (output_bfd) + TOC_BASE_OFF,
15935 htab->elf.sgot->contents);
15937 /* Set .got entry size. */
15938 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 8;
15941 if (htab->elf.splt != NULL && htab->elf.splt->size != 0
15942 && htab->elf.splt->output_section != bfd_abs_section_ptr)
15944 /* Set .plt entry size. */
15945 elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
15946 = PLT_ENTRY_SIZE (htab);
15949 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15950 brlt ourselves if emitrelocations. */
15951 if (htab->brlt != NULL
15952 && htab->brlt->reloc_count != 0
15953 && !_bfd_elf_link_output_relocs (output_bfd,
15955 elf_section_data (htab->brlt)->rela.hdr,
15956 elf_section_data (htab->brlt)->relocs,
15960 if (htab->glink != NULL
15961 && htab->glink->reloc_count != 0
15962 && !_bfd_elf_link_output_relocs (output_bfd,
15964 elf_section_data (htab->glink)->rela.hdr,
15965 elf_section_data (htab->glink)->relocs,
15969 if (htab->glink_eh_frame != NULL
15970 && htab->glink_eh_frame->size != 0)
15974 struct map_stub *group;
15977 p = htab->glink_eh_frame->contents;
15978 p += (sizeof (glink_eh_frame_cie) + align - 1) & -align;
15980 for (group = htab->group; group != NULL; group = group->next)
15981 if (group->stub_sec != NULL)
15983 /* Offset to stub section. */
15984 val = (group->stub_sec->output_section->vma
15985 + group->stub_sec->output_offset);
15986 val -= (htab->glink_eh_frame->output_section->vma
15987 + htab->glink_eh_frame->output_offset
15988 + (p + 8 - htab->glink_eh_frame->contents));
15989 if (val + 0x80000000 > 0xffffffff)
15992 (_("%s offset too large for .eh_frame sdata4 encoding"),
15993 group->stub_sec->name);
15996 bfd_put_32 (dynobj, val, p + 8);
15997 p += stub_eh_frame_size (group, align);
15999 if (htab->glink != NULL && htab->glink->size != 0)
16001 /* Offset to .glink. */
16002 val = (htab->glink->output_section->vma
16003 + htab->glink->output_offset
16005 val -= (htab->glink_eh_frame->output_section->vma
16006 + htab->glink_eh_frame->output_offset
16007 + (p + 8 - htab->glink_eh_frame->contents));
16008 if (val + 0x80000000 > 0xffffffff)
16011 (_("%s offset too large for .eh_frame sdata4 encoding"),
16012 htab->glink->name);
16015 bfd_put_32 (dynobj, val, p + 8);
16016 p += (24 + align - 1) & -align;
16019 if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
16020 && !_bfd_elf_write_section_eh_frame (output_bfd, info,
16021 htab->glink_eh_frame,
16022 htab->glink_eh_frame->contents))
16026 /* We need to handle writing out multiple GOT sections ourselves,
16027 since we didn't add them to DYNOBJ. We know dynobj is the first
16029 while ((dynobj = dynobj->link.next) != NULL)
16033 if (!is_ppc64_elf (dynobj))
16036 s = ppc64_elf_tdata (dynobj)->got;
16039 && s->output_section != bfd_abs_section_ptr
16040 && !bfd_set_section_contents (output_bfd, s->output_section,
16041 s->contents, s->output_offset,
16044 s = ppc64_elf_tdata (dynobj)->relgot;
16047 && s->output_section != bfd_abs_section_ptr
16048 && !bfd_set_section_contents (output_bfd, s->output_section,
16049 s->contents, s->output_offset,
16057 #include "elf64-target.h"
16059 /* FreeBSD support */
16061 #undef TARGET_LITTLE_SYM
16062 #undef TARGET_LITTLE_NAME
16064 #undef TARGET_BIG_SYM
16065 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
16066 #undef TARGET_BIG_NAME
16067 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
16070 #define ELF_OSABI ELFOSABI_FREEBSD
16073 #define elf64_bed elf64_powerpc_fbsd_bed
16075 #include "elf64-target.h"