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)
133 /* The initial size of the plt reserved for the dynamic linker. */
134 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
136 /* Offsets to some stack save slots. */
138 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
139 /* This one is dodgy. ELFv2 does not have a linker word, so use the
140 CR save slot. Used only by optimised __tls_get_addr call stub,
141 relying on __tls_get_addr_opt not saving CR.. */
142 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
144 /* TOC base pointers offset from start of TOC. */
145 #define TOC_BASE_OFF 0x8000
146 /* TOC base alignment. */
147 #define TOC_BASE_ALIGN 256
149 /* Offset of tp and dtp pointers from start of TLS block. */
150 #define TP_OFFSET 0x7000
151 #define DTP_OFFSET 0x8000
153 /* .plt call stub instructions. The normal stub is like this, but
154 sometimes the .plt entry crosses a 64k boundary and we need to
155 insert an addi to adjust r11. */
156 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
157 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
158 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
159 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
160 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
161 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
162 #define BCTR 0x4e800420 /* bctr */
164 #define CRSETEQ 0x4c421242 /* crset 4*%cr0+%eq */
165 #define BEQCTRM 0x4dc20420 /* beqctr- */
166 #define BEQCTRLM 0x4dc20421 /* beqctrl- */
168 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
169 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
170 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
172 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
173 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
174 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
175 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
176 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
177 #define BNECTR 0x4ca20420 /* bnectr+ */
178 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
180 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
181 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
182 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
184 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
185 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
186 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
188 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
189 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
190 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
191 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
192 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
194 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
195 #define GLINK_PLTRESOLVE_SIZE(htab) \
196 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4) \
197 + (!htab->params->speculate_indirect_jumps ? 2 * 4 : 0))
201 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
202 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
204 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
205 /* ld %2,(0b-1b)(%11) */
206 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
207 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
213 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
214 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
215 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
216 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
217 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
220 #define NOP 0x60000000
222 /* Some other nops. */
223 #define CROR_151515 0x4def7b82
224 #define CROR_313131 0x4ffffb82
226 /* .glink entries for the first 32k functions are two instructions. */
227 #define LI_R0_0 0x38000000 /* li %r0,0 */
228 #define B_DOT 0x48000000 /* b . */
230 /* After that, we need two instructions to load the index, followed by
232 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
233 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
235 /* Instructions used by the save and restore reg functions. */
236 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
237 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
238 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
239 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
240 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
241 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
242 #define LI_R12_0 0x39800000 /* li %r12,0 */
243 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
244 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
245 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
246 #define BLR 0x4e800020 /* blr */
248 /* Since .opd is an array of descriptors and each entry will end up
249 with identical R_PPC64_RELATIVE relocs, there is really no need to
250 propagate .opd relocs; The dynamic linker should be taught to
251 relocate .opd without reloc entries. */
252 #ifndef NO_OPD_RELOCS
253 #define NO_OPD_RELOCS 0
257 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
261 abiversion (bfd *abfd)
263 return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
267 set_abiversion (bfd *abfd, int ver)
269 elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
270 elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
273 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
275 /* Relocation HOWTO's. */
276 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_max];
278 static reloc_howto_type ppc64_elf_howto_raw[] = {
279 /* This reloc does nothing. */
280 HOWTO (R_PPC64_NONE, /* type */
282 3, /* size (0 = byte, 1 = short, 2 = long) */
284 FALSE, /* pc_relative */
286 complain_overflow_dont, /* complain_on_overflow */
287 bfd_elf_generic_reloc, /* special_function */
288 "R_PPC64_NONE", /* name */
289 FALSE, /* partial_inplace */
292 FALSE), /* pcrel_offset */
294 /* A standard 32 bit relocation. */
295 HOWTO (R_PPC64_ADDR32, /* type */
297 2, /* size (0 = byte, 1 = short, 2 = long) */
299 FALSE, /* pc_relative */
301 complain_overflow_bitfield, /* complain_on_overflow */
302 bfd_elf_generic_reloc, /* special_function */
303 "R_PPC64_ADDR32", /* name */
304 FALSE, /* partial_inplace */
306 0xffffffff, /* dst_mask */
307 FALSE), /* pcrel_offset */
309 /* An absolute 26 bit branch; the lower two bits must be zero.
310 FIXME: we don't check that, we just clear them. */
311 HOWTO (R_PPC64_ADDR24, /* type */
313 2, /* size (0 = byte, 1 = short, 2 = long) */
315 FALSE, /* pc_relative */
317 complain_overflow_bitfield, /* complain_on_overflow */
318 bfd_elf_generic_reloc, /* special_function */
319 "R_PPC64_ADDR24", /* name */
320 FALSE, /* partial_inplace */
322 0x03fffffc, /* dst_mask */
323 FALSE), /* pcrel_offset */
325 /* A standard 16 bit relocation. */
326 HOWTO (R_PPC64_ADDR16, /* type */
328 1, /* size (0 = byte, 1 = short, 2 = long) */
330 FALSE, /* pc_relative */
332 complain_overflow_bitfield, /* complain_on_overflow */
333 bfd_elf_generic_reloc, /* special_function */
334 "R_PPC64_ADDR16", /* name */
335 FALSE, /* partial_inplace */
337 0xffff, /* dst_mask */
338 FALSE), /* pcrel_offset */
340 /* A 16 bit relocation without overflow. */
341 HOWTO (R_PPC64_ADDR16_LO, /* type */
343 1, /* size (0 = byte, 1 = short, 2 = long) */
345 FALSE, /* pc_relative */
347 complain_overflow_dont,/* complain_on_overflow */
348 bfd_elf_generic_reloc, /* special_function */
349 "R_PPC64_ADDR16_LO", /* name */
350 FALSE, /* partial_inplace */
352 0xffff, /* dst_mask */
353 FALSE), /* pcrel_offset */
355 /* Bits 16-31 of an address. */
356 HOWTO (R_PPC64_ADDR16_HI, /* type */
358 1, /* size (0 = byte, 1 = short, 2 = long) */
360 FALSE, /* pc_relative */
362 complain_overflow_signed, /* complain_on_overflow */
363 bfd_elf_generic_reloc, /* special_function */
364 "R_PPC64_ADDR16_HI", /* name */
365 FALSE, /* partial_inplace */
367 0xffff, /* dst_mask */
368 FALSE), /* pcrel_offset */
370 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
371 bits, treated as a signed number, is negative. */
372 HOWTO (R_PPC64_ADDR16_HA, /* type */
374 1, /* size (0 = byte, 1 = short, 2 = long) */
376 FALSE, /* pc_relative */
378 complain_overflow_signed, /* complain_on_overflow */
379 ppc64_elf_ha_reloc, /* special_function */
380 "R_PPC64_ADDR16_HA", /* name */
381 FALSE, /* partial_inplace */
383 0xffff, /* dst_mask */
384 FALSE), /* pcrel_offset */
386 /* An absolute 16 bit branch; the lower two bits must be zero.
387 FIXME: we don't check that, we just clear them. */
388 HOWTO (R_PPC64_ADDR14, /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 FALSE, /* pc_relative */
394 complain_overflow_signed, /* complain_on_overflow */
395 ppc64_elf_branch_reloc, /* special_function */
396 "R_PPC64_ADDR14", /* name */
397 FALSE, /* partial_inplace */
399 0x0000fffc, /* dst_mask */
400 FALSE), /* pcrel_offset */
402 /* An absolute 16 bit branch, for which bit 10 should be set to
403 indicate that the branch is expected to be taken. The lower two
404 bits must be zero. */
405 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 FALSE, /* pc_relative */
411 complain_overflow_signed, /* complain_on_overflow */
412 ppc64_elf_brtaken_reloc, /* special_function */
413 "R_PPC64_ADDR14_BRTAKEN",/* name */
414 FALSE, /* partial_inplace */
416 0x0000fffc, /* dst_mask */
417 FALSE), /* pcrel_offset */
419 /* An absolute 16 bit branch, for which bit 10 should be set to
420 indicate that the branch is not expected to be taken. The lower
421 two bits must be zero. */
422 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 FALSE, /* pc_relative */
428 complain_overflow_signed, /* complain_on_overflow */
429 ppc64_elf_brtaken_reloc, /* special_function */
430 "R_PPC64_ADDR14_BRNTAKEN",/* name */
431 FALSE, /* partial_inplace */
433 0x0000fffc, /* dst_mask */
434 FALSE), /* pcrel_offset */
436 /* A relative 26 bit branch; the lower two bits must be zero. */
437 HOWTO (R_PPC64_REL24, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 TRUE, /* pc_relative */
443 complain_overflow_signed, /* complain_on_overflow */
444 ppc64_elf_branch_reloc, /* special_function */
445 "R_PPC64_REL24", /* name */
446 FALSE, /* partial_inplace */
448 0x03fffffc, /* dst_mask */
449 TRUE), /* pcrel_offset */
451 /* A relative 16 bit branch; the lower two bits must be zero. */
452 HOWTO (R_PPC64_REL14, /* type */
454 2, /* size (0 = byte, 1 = short, 2 = long) */
456 TRUE, /* pc_relative */
458 complain_overflow_signed, /* complain_on_overflow */
459 ppc64_elf_branch_reloc, /* special_function */
460 "R_PPC64_REL14", /* name */
461 FALSE, /* partial_inplace */
463 0x0000fffc, /* dst_mask */
464 TRUE), /* pcrel_offset */
466 /* A relative 16 bit branch. Bit 10 should be set to indicate that
467 the branch is expected to be taken. The lower two bits must be
469 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 TRUE, /* pc_relative */
475 complain_overflow_signed, /* complain_on_overflow */
476 ppc64_elf_brtaken_reloc, /* special_function */
477 "R_PPC64_REL14_BRTAKEN", /* name */
478 FALSE, /* partial_inplace */
480 0x0000fffc, /* dst_mask */
481 TRUE), /* pcrel_offset */
483 /* A relative 16 bit branch. Bit 10 should be set to indicate that
484 the branch is not expected to be taken. The lower two bits must
486 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 TRUE, /* pc_relative */
492 complain_overflow_signed, /* complain_on_overflow */
493 ppc64_elf_brtaken_reloc, /* special_function */
494 "R_PPC64_REL14_BRNTAKEN",/* name */
495 FALSE, /* partial_inplace */
497 0x0000fffc, /* dst_mask */
498 TRUE), /* pcrel_offset */
500 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
502 HOWTO (R_PPC64_GOT16, /* type */
504 1, /* size (0 = byte, 1 = short, 2 = long) */
506 FALSE, /* pc_relative */
508 complain_overflow_signed, /* complain_on_overflow */
509 ppc64_elf_unhandled_reloc, /* special_function */
510 "R_PPC64_GOT16", /* name */
511 FALSE, /* partial_inplace */
513 0xffff, /* dst_mask */
514 FALSE), /* pcrel_offset */
516 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
518 HOWTO (R_PPC64_GOT16_LO, /* type */
520 1, /* size (0 = byte, 1 = short, 2 = long) */
522 FALSE, /* pc_relative */
524 complain_overflow_dont, /* complain_on_overflow */
525 ppc64_elf_unhandled_reloc, /* special_function */
526 "R_PPC64_GOT16_LO", /* name */
527 FALSE, /* partial_inplace */
529 0xffff, /* dst_mask */
530 FALSE), /* pcrel_offset */
532 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
534 HOWTO (R_PPC64_GOT16_HI, /* type */
536 1, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE, /* pc_relative */
540 complain_overflow_signed,/* complain_on_overflow */
541 ppc64_elf_unhandled_reloc, /* special_function */
542 "R_PPC64_GOT16_HI", /* name */
543 FALSE, /* partial_inplace */
545 0xffff, /* dst_mask */
546 FALSE), /* pcrel_offset */
548 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
550 HOWTO (R_PPC64_GOT16_HA, /* type */
552 1, /* size (0 = byte, 1 = short, 2 = long) */
554 FALSE, /* pc_relative */
556 complain_overflow_signed,/* complain_on_overflow */
557 ppc64_elf_unhandled_reloc, /* special_function */
558 "R_PPC64_GOT16_HA", /* name */
559 FALSE, /* partial_inplace */
561 0xffff, /* dst_mask */
562 FALSE), /* pcrel_offset */
564 /* This is used only by the dynamic linker. The symbol should exist
565 both in the object being run and in some shared library. The
566 dynamic linker copies the data addressed by the symbol from the
567 shared library into the object, because the object being
568 run has to have the data at some particular address. */
569 HOWTO (R_PPC64_COPY, /* type */
571 0, /* this one is variable size */
573 FALSE, /* pc_relative */
575 complain_overflow_dont, /* complain_on_overflow */
576 ppc64_elf_unhandled_reloc, /* special_function */
577 "R_PPC64_COPY", /* name */
578 FALSE, /* partial_inplace */
581 FALSE), /* pcrel_offset */
583 /* Like R_PPC64_ADDR64, but used when setting global offset table
585 HOWTO (R_PPC64_GLOB_DAT, /* type */
587 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
589 FALSE, /* pc_relative */
591 complain_overflow_dont, /* complain_on_overflow */
592 ppc64_elf_unhandled_reloc, /* special_function */
593 "R_PPC64_GLOB_DAT", /* name */
594 FALSE, /* partial_inplace */
596 ONES (64), /* dst_mask */
597 FALSE), /* pcrel_offset */
599 /* Created by the link editor. Marks a procedure linkage table
600 entry for a symbol. */
601 HOWTO (R_PPC64_JMP_SLOT, /* type */
603 0, /* size (0 = byte, 1 = short, 2 = long) */
605 FALSE, /* pc_relative */
607 complain_overflow_dont, /* complain_on_overflow */
608 ppc64_elf_unhandled_reloc, /* special_function */
609 "R_PPC64_JMP_SLOT", /* name */
610 FALSE, /* partial_inplace */
613 FALSE), /* pcrel_offset */
615 /* Used only by the dynamic linker. When the object is run, this
616 doubleword64 is set to the load address of the object, plus the
618 HOWTO (R_PPC64_RELATIVE, /* type */
620 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
622 FALSE, /* pc_relative */
624 complain_overflow_dont, /* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
626 "R_PPC64_RELATIVE", /* name */
627 FALSE, /* partial_inplace */
629 ONES (64), /* dst_mask */
630 FALSE), /* pcrel_offset */
632 /* Like R_PPC64_ADDR32, but may be unaligned. */
633 HOWTO (R_PPC64_UADDR32, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 FALSE, /* pc_relative */
639 complain_overflow_bitfield, /* complain_on_overflow */
640 bfd_elf_generic_reloc, /* special_function */
641 "R_PPC64_UADDR32", /* name */
642 FALSE, /* partial_inplace */
644 0xffffffff, /* dst_mask */
645 FALSE), /* pcrel_offset */
647 /* Like R_PPC64_ADDR16, but may be unaligned. */
648 HOWTO (R_PPC64_UADDR16, /* type */
650 1, /* size (0 = byte, 1 = short, 2 = long) */
652 FALSE, /* pc_relative */
654 complain_overflow_bitfield, /* complain_on_overflow */
655 bfd_elf_generic_reloc, /* special_function */
656 "R_PPC64_UADDR16", /* name */
657 FALSE, /* partial_inplace */
659 0xffff, /* dst_mask */
660 FALSE), /* pcrel_offset */
662 /* 32-bit PC relative. */
663 HOWTO (R_PPC64_REL32, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 TRUE, /* pc_relative */
669 complain_overflow_signed, /* complain_on_overflow */
670 bfd_elf_generic_reloc, /* special_function */
671 "R_PPC64_REL32", /* name */
672 FALSE, /* partial_inplace */
674 0xffffffff, /* dst_mask */
675 TRUE), /* pcrel_offset */
677 /* 32-bit relocation to the symbol's procedure linkage table. */
678 HOWTO (R_PPC64_PLT32, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE, /* pc_relative */
684 complain_overflow_bitfield, /* complain_on_overflow */
685 ppc64_elf_unhandled_reloc, /* special_function */
686 "R_PPC64_PLT32", /* name */
687 FALSE, /* partial_inplace */
689 0xffffffff, /* dst_mask */
690 FALSE), /* pcrel_offset */
692 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
693 FIXME: R_PPC64_PLTREL32 not supported. */
694 HOWTO (R_PPC64_PLTREL32, /* type */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
698 TRUE, /* pc_relative */
700 complain_overflow_signed, /* complain_on_overflow */
701 ppc64_elf_unhandled_reloc, /* special_function */
702 "R_PPC64_PLTREL32", /* name */
703 FALSE, /* partial_inplace */
705 0xffffffff, /* dst_mask */
706 TRUE), /* pcrel_offset */
708 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
710 HOWTO (R_PPC64_PLT16_LO, /* type */
712 1, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE, /* pc_relative */
716 complain_overflow_dont, /* complain_on_overflow */
717 ppc64_elf_unhandled_reloc, /* special_function */
718 "R_PPC64_PLT16_LO", /* name */
719 FALSE, /* partial_inplace */
721 0xffff, /* dst_mask */
722 FALSE), /* pcrel_offset */
724 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
726 HOWTO (R_PPC64_PLT16_HI, /* type */
728 1, /* size (0 = byte, 1 = short, 2 = long) */
730 FALSE, /* pc_relative */
732 complain_overflow_signed, /* complain_on_overflow */
733 ppc64_elf_unhandled_reloc, /* special_function */
734 "R_PPC64_PLT16_HI", /* name */
735 FALSE, /* partial_inplace */
737 0xffff, /* dst_mask */
738 FALSE), /* pcrel_offset */
740 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
742 HOWTO (R_PPC64_PLT16_HA, /* type */
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE, /* pc_relative */
748 complain_overflow_signed, /* complain_on_overflow */
749 ppc64_elf_unhandled_reloc, /* special_function */
750 "R_PPC64_PLT16_HA", /* name */
751 FALSE, /* partial_inplace */
753 0xffff, /* dst_mask */
754 FALSE), /* pcrel_offset */
756 /* 16-bit section relative relocation. */
757 HOWTO (R_PPC64_SECTOFF, /* type */
759 1, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE, /* pc_relative */
763 complain_overflow_signed, /* complain_on_overflow */
764 ppc64_elf_sectoff_reloc, /* special_function */
765 "R_PPC64_SECTOFF", /* name */
766 FALSE, /* partial_inplace */
768 0xffff, /* dst_mask */
769 FALSE), /* pcrel_offset */
771 /* Like R_PPC64_SECTOFF, but no overflow warning. */
772 HOWTO (R_PPC64_SECTOFF_LO, /* type */
774 1, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE, /* pc_relative */
778 complain_overflow_dont, /* complain_on_overflow */
779 ppc64_elf_sectoff_reloc, /* special_function */
780 "R_PPC64_SECTOFF_LO", /* name */
781 FALSE, /* partial_inplace */
783 0xffff, /* dst_mask */
784 FALSE), /* pcrel_offset */
786 /* 16-bit upper half section relative relocation. */
787 HOWTO (R_PPC64_SECTOFF_HI, /* type */
789 1, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE, /* pc_relative */
793 complain_overflow_signed, /* complain_on_overflow */
794 ppc64_elf_sectoff_reloc, /* special_function */
795 "R_PPC64_SECTOFF_HI", /* name */
796 FALSE, /* partial_inplace */
798 0xffff, /* dst_mask */
799 FALSE), /* pcrel_offset */
801 /* 16-bit upper half adjusted section relative relocation. */
802 HOWTO (R_PPC64_SECTOFF_HA, /* type */
804 1, /* size (0 = byte, 1 = short, 2 = long) */
806 FALSE, /* pc_relative */
808 complain_overflow_signed, /* complain_on_overflow */
809 ppc64_elf_sectoff_ha_reloc, /* special_function */
810 "R_PPC64_SECTOFF_HA", /* name */
811 FALSE, /* partial_inplace */
813 0xffff, /* dst_mask */
814 FALSE), /* pcrel_offset */
816 /* Like R_PPC64_REL24 without touching the two least significant bits. */
817 HOWTO (R_PPC64_REL30, /* type */
819 2, /* size (0 = byte, 1 = short, 2 = long) */
821 TRUE, /* pc_relative */
823 complain_overflow_dont, /* complain_on_overflow */
824 bfd_elf_generic_reloc, /* special_function */
825 "R_PPC64_REL30", /* name */
826 FALSE, /* partial_inplace */
828 0xfffffffc, /* dst_mask */
829 TRUE), /* pcrel_offset */
831 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
833 /* A standard 64-bit relocation. */
834 HOWTO (R_PPC64_ADDR64, /* type */
836 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
838 FALSE, /* pc_relative */
840 complain_overflow_dont, /* complain_on_overflow */
841 bfd_elf_generic_reloc, /* special_function */
842 "R_PPC64_ADDR64", /* name */
843 FALSE, /* partial_inplace */
845 ONES (64), /* dst_mask */
846 FALSE), /* pcrel_offset */
848 /* The bits 32-47 of an address. */
849 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
851 1, /* size (0 = byte, 1 = short, 2 = long) */
853 FALSE, /* pc_relative */
855 complain_overflow_dont, /* complain_on_overflow */
856 bfd_elf_generic_reloc, /* special_function */
857 "R_PPC64_ADDR16_HIGHER", /* name */
858 FALSE, /* partial_inplace */
860 0xffff, /* dst_mask */
861 FALSE), /* pcrel_offset */
863 /* The bits 32-47 of an address, plus 1 if the contents of the low
864 16 bits, treated as a signed number, is negative. */
865 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
867 1, /* size (0 = byte, 1 = short, 2 = long) */
869 FALSE, /* pc_relative */
871 complain_overflow_dont, /* complain_on_overflow */
872 ppc64_elf_ha_reloc, /* special_function */
873 "R_PPC64_ADDR16_HIGHERA", /* name */
874 FALSE, /* partial_inplace */
876 0xffff, /* dst_mask */
877 FALSE), /* pcrel_offset */
879 /* The bits 48-63 of an address. */
880 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
882 1, /* size (0 = byte, 1 = short, 2 = long) */
884 FALSE, /* pc_relative */
886 complain_overflow_dont, /* complain_on_overflow */
887 bfd_elf_generic_reloc, /* special_function */
888 "R_PPC64_ADDR16_HIGHEST", /* name */
889 FALSE, /* partial_inplace */
891 0xffff, /* dst_mask */
892 FALSE), /* pcrel_offset */
894 /* The bits 48-63 of an address, plus 1 if the contents of the low
895 16 bits, treated as a signed number, is negative. */
896 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
898 1, /* size (0 = byte, 1 = short, 2 = long) */
900 FALSE, /* pc_relative */
902 complain_overflow_dont, /* complain_on_overflow */
903 ppc64_elf_ha_reloc, /* special_function */
904 "R_PPC64_ADDR16_HIGHESTA", /* name */
905 FALSE, /* partial_inplace */
907 0xffff, /* dst_mask */
908 FALSE), /* pcrel_offset */
910 /* Like ADDR64, but may be unaligned. */
911 HOWTO (R_PPC64_UADDR64, /* type */
913 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
915 FALSE, /* pc_relative */
917 complain_overflow_dont, /* complain_on_overflow */
918 bfd_elf_generic_reloc, /* special_function */
919 "R_PPC64_UADDR64", /* name */
920 FALSE, /* partial_inplace */
922 ONES (64), /* dst_mask */
923 FALSE), /* pcrel_offset */
925 /* 64-bit relative relocation. */
926 HOWTO (R_PPC64_REL64, /* type */
928 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
930 TRUE, /* pc_relative */
932 complain_overflow_dont, /* complain_on_overflow */
933 bfd_elf_generic_reloc, /* special_function */
934 "R_PPC64_REL64", /* name */
935 FALSE, /* partial_inplace */
937 ONES (64), /* dst_mask */
938 TRUE), /* pcrel_offset */
940 /* 64-bit relocation to the symbol's procedure linkage table. */
941 HOWTO (R_PPC64_PLT64, /* type */
943 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
945 FALSE, /* pc_relative */
947 complain_overflow_dont, /* complain_on_overflow */
948 ppc64_elf_unhandled_reloc, /* special_function */
949 "R_PPC64_PLT64", /* name */
950 FALSE, /* partial_inplace */
952 ONES (64), /* dst_mask */
953 FALSE), /* pcrel_offset */
955 /* 64-bit PC relative relocation to the symbol's procedure linkage
957 /* FIXME: R_PPC64_PLTREL64 not supported. */
958 HOWTO (R_PPC64_PLTREL64, /* type */
960 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
962 TRUE, /* pc_relative */
964 complain_overflow_dont, /* complain_on_overflow */
965 ppc64_elf_unhandled_reloc, /* special_function */
966 "R_PPC64_PLTREL64", /* name */
967 FALSE, /* partial_inplace */
969 ONES (64), /* dst_mask */
970 TRUE), /* pcrel_offset */
972 /* 16 bit TOC-relative relocation. */
974 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
975 HOWTO (R_PPC64_TOC16, /* type */
977 1, /* size (0 = byte, 1 = short, 2 = long) */
979 FALSE, /* pc_relative */
981 complain_overflow_signed, /* complain_on_overflow */
982 ppc64_elf_toc_reloc, /* special_function */
983 "R_PPC64_TOC16", /* name */
984 FALSE, /* partial_inplace */
986 0xffff, /* dst_mask */
987 FALSE), /* pcrel_offset */
989 /* 16 bit TOC-relative relocation without overflow. */
991 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
992 HOWTO (R_PPC64_TOC16_LO, /* type */
994 1, /* size (0 = byte, 1 = short, 2 = long) */
996 FALSE, /* pc_relative */
998 complain_overflow_dont, /* complain_on_overflow */
999 ppc64_elf_toc_reloc, /* special_function */
1000 "R_PPC64_TOC16_LO", /* name */
1001 FALSE, /* partial_inplace */
1003 0xffff, /* dst_mask */
1004 FALSE), /* pcrel_offset */
1006 /* 16 bit TOC-relative relocation, high 16 bits. */
1008 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
1009 HOWTO (R_PPC64_TOC16_HI, /* type */
1010 16, /* rightshift */
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1013 FALSE, /* pc_relative */
1015 complain_overflow_signed, /* complain_on_overflow */
1016 ppc64_elf_toc_reloc, /* special_function */
1017 "R_PPC64_TOC16_HI", /* name */
1018 FALSE, /* partial_inplace */
1020 0xffff, /* dst_mask */
1021 FALSE), /* pcrel_offset */
1023 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1024 contents of the low 16 bits, treated as a signed number, is
1027 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1028 HOWTO (R_PPC64_TOC16_HA, /* type */
1029 16, /* rightshift */
1030 1, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE, /* pc_relative */
1034 complain_overflow_signed, /* complain_on_overflow */
1035 ppc64_elf_toc_ha_reloc, /* special_function */
1036 "R_PPC64_TOC16_HA", /* name */
1037 FALSE, /* partial_inplace */
1039 0xffff, /* dst_mask */
1040 FALSE), /* pcrel_offset */
1042 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1044 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1045 HOWTO (R_PPC64_TOC, /* type */
1047 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1049 FALSE, /* pc_relative */
1051 complain_overflow_dont, /* complain_on_overflow */
1052 ppc64_elf_toc64_reloc, /* special_function */
1053 "R_PPC64_TOC", /* name */
1054 FALSE, /* partial_inplace */
1056 ONES (64), /* dst_mask */
1057 FALSE), /* pcrel_offset */
1059 /* Like R_PPC64_GOT16, but also informs the link editor that the
1060 value to relocate may (!) refer to a PLT entry which the link
1061 editor (a) may replace with the symbol value. If the link editor
1062 is unable to fully resolve the symbol, it may (b) create a PLT
1063 entry and store the address to the new PLT entry in the GOT.
1064 This permits lazy resolution of function symbols at run time.
1065 The link editor may also skip all of this and just (c) emit a
1066 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1067 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1068 HOWTO (R_PPC64_PLTGOT16, /* type */
1070 1, /* size (0 = byte, 1 = short, 2 = long) */
1072 FALSE, /* pc_relative */
1074 complain_overflow_signed, /* complain_on_overflow */
1075 ppc64_elf_unhandled_reloc, /* special_function */
1076 "R_PPC64_PLTGOT16", /* name */
1077 FALSE, /* partial_inplace */
1079 0xffff, /* dst_mask */
1080 FALSE), /* pcrel_offset */
1082 /* Like R_PPC64_PLTGOT16, but without overflow. */
1083 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1084 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
1086 1, /* size (0 = byte, 1 = short, 2 = long) */
1088 FALSE, /* pc_relative */
1090 complain_overflow_dont, /* complain_on_overflow */
1091 ppc64_elf_unhandled_reloc, /* special_function */
1092 "R_PPC64_PLTGOT16_LO", /* name */
1093 FALSE, /* partial_inplace */
1095 0xffff, /* dst_mask */
1096 FALSE), /* pcrel_offset */
1098 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1099 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1100 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
1101 16, /* rightshift */
1102 1, /* size (0 = byte, 1 = short, 2 = long) */
1104 FALSE, /* pc_relative */
1106 complain_overflow_signed, /* complain_on_overflow */
1107 ppc64_elf_unhandled_reloc, /* special_function */
1108 "R_PPC64_PLTGOT16_HI", /* name */
1109 FALSE, /* partial_inplace */
1111 0xffff, /* dst_mask */
1112 FALSE), /* pcrel_offset */
1114 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1115 1 if the contents of the low 16 bits, treated as a signed number,
1117 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1118 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1119 16, /* rightshift */
1120 1, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE, /* pc_relative */
1124 complain_overflow_signed, /* complain_on_overflow */
1125 ppc64_elf_unhandled_reloc, /* special_function */
1126 "R_PPC64_PLTGOT16_HA", /* name */
1127 FALSE, /* partial_inplace */
1129 0xffff, /* dst_mask */
1130 FALSE), /* pcrel_offset */
1132 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1133 HOWTO (R_PPC64_ADDR16_DS, /* type */
1135 1, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE, /* pc_relative */
1139 complain_overflow_signed, /* complain_on_overflow */
1140 bfd_elf_generic_reloc, /* special_function */
1141 "R_PPC64_ADDR16_DS", /* name */
1142 FALSE, /* partial_inplace */
1144 0xfffc, /* dst_mask */
1145 FALSE), /* pcrel_offset */
1147 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1148 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1150 1, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE, /* pc_relative */
1154 complain_overflow_dont,/* complain_on_overflow */
1155 bfd_elf_generic_reloc, /* special_function */
1156 "R_PPC64_ADDR16_LO_DS",/* name */
1157 FALSE, /* partial_inplace */
1159 0xfffc, /* dst_mask */
1160 FALSE), /* pcrel_offset */
1162 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1163 HOWTO (R_PPC64_GOT16_DS, /* type */
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE, /* pc_relative */
1169 complain_overflow_signed, /* complain_on_overflow */
1170 ppc64_elf_unhandled_reloc, /* special_function */
1171 "R_PPC64_GOT16_DS", /* name */
1172 FALSE, /* partial_inplace */
1174 0xfffc, /* dst_mask */
1175 FALSE), /* pcrel_offset */
1177 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1178 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1180 1, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE, /* pc_relative */
1184 complain_overflow_dont, /* complain_on_overflow */
1185 ppc64_elf_unhandled_reloc, /* special_function */
1186 "R_PPC64_GOT16_LO_DS", /* name */
1187 FALSE, /* partial_inplace */
1189 0xfffc, /* dst_mask */
1190 FALSE), /* pcrel_offset */
1192 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1193 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1195 1, /* size (0 = byte, 1 = short, 2 = long) */
1197 FALSE, /* pc_relative */
1199 complain_overflow_dont, /* complain_on_overflow */
1200 ppc64_elf_unhandled_reloc, /* special_function */
1201 "R_PPC64_PLT16_LO_DS", /* name */
1202 FALSE, /* partial_inplace */
1204 0xfffc, /* dst_mask */
1205 FALSE), /* pcrel_offset */
1207 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1208 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE, /* pc_relative */
1214 complain_overflow_signed, /* complain_on_overflow */
1215 ppc64_elf_sectoff_reloc, /* special_function */
1216 "R_PPC64_SECTOFF_DS", /* name */
1217 FALSE, /* partial_inplace */
1219 0xfffc, /* dst_mask */
1220 FALSE), /* pcrel_offset */
1222 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1223 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1225 1, /* size (0 = byte, 1 = short, 2 = long) */
1227 FALSE, /* pc_relative */
1229 complain_overflow_dont, /* complain_on_overflow */
1230 ppc64_elf_sectoff_reloc, /* special_function */
1231 "R_PPC64_SECTOFF_LO_DS",/* name */
1232 FALSE, /* partial_inplace */
1234 0xfffc, /* dst_mask */
1235 FALSE), /* pcrel_offset */
1237 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1238 HOWTO (R_PPC64_TOC16_DS, /* type */
1240 1, /* size (0 = byte, 1 = short, 2 = long) */
1242 FALSE, /* pc_relative */
1244 complain_overflow_signed, /* complain_on_overflow */
1245 ppc64_elf_toc_reloc, /* special_function */
1246 "R_PPC64_TOC16_DS", /* name */
1247 FALSE, /* partial_inplace */
1249 0xfffc, /* dst_mask */
1250 FALSE), /* pcrel_offset */
1252 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1253 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1255 1, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE, /* pc_relative */
1259 complain_overflow_dont, /* complain_on_overflow */
1260 ppc64_elf_toc_reloc, /* special_function */
1261 "R_PPC64_TOC16_LO_DS", /* name */
1262 FALSE, /* partial_inplace */
1264 0xfffc, /* dst_mask */
1265 FALSE), /* pcrel_offset */
1267 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1268 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1269 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1271 1, /* size (0 = byte, 1 = short, 2 = long) */
1273 FALSE, /* pc_relative */
1275 complain_overflow_signed, /* complain_on_overflow */
1276 ppc64_elf_unhandled_reloc, /* special_function */
1277 "R_PPC64_PLTGOT16_DS", /* name */
1278 FALSE, /* partial_inplace */
1280 0xfffc, /* dst_mask */
1281 FALSE), /* pcrel_offset */
1283 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1284 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1285 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1287 1, /* size (0 = byte, 1 = short, 2 = long) */
1289 FALSE, /* pc_relative */
1291 complain_overflow_dont, /* complain_on_overflow */
1292 ppc64_elf_unhandled_reloc, /* special_function */
1293 "R_PPC64_PLTGOT16_LO_DS",/* name */
1294 FALSE, /* partial_inplace */
1296 0xfffc, /* dst_mask */
1297 FALSE), /* pcrel_offset */
1299 /* Marker relocs for TLS. */
1302 2, /* size (0 = byte, 1 = short, 2 = long) */
1304 FALSE, /* pc_relative */
1306 complain_overflow_dont, /* complain_on_overflow */
1307 bfd_elf_generic_reloc, /* special_function */
1308 "R_PPC64_TLS", /* name */
1309 FALSE, /* partial_inplace */
1312 FALSE), /* pcrel_offset */
1314 HOWTO (R_PPC64_TLSGD,
1316 2, /* size (0 = byte, 1 = short, 2 = long) */
1318 FALSE, /* pc_relative */
1320 complain_overflow_dont, /* complain_on_overflow */
1321 bfd_elf_generic_reloc, /* special_function */
1322 "R_PPC64_TLSGD", /* name */
1323 FALSE, /* partial_inplace */
1326 FALSE), /* pcrel_offset */
1328 HOWTO (R_PPC64_TLSLD,
1330 2, /* size (0 = byte, 1 = short, 2 = long) */
1332 FALSE, /* pc_relative */
1334 complain_overflow_dont, /* complain_on_overflow */
1335 bfd_elf_generic_reloc, /* special_function */
1336 "R_PPC64_TLSLD", /* name */
1337 FALSE, /* partial_inplace */
1340 FALSE), /* pcrel_offset */
1342 HOWTO (R_PPC64_TOCSAVE,
1344 2, /* size (0 = byte, 1 = short, 2 = long) */
1346 FALSE, /* pc_relative */
1348 complain_overflow_dont, /* complain_on_overflow */
1349 bfd_elf_generic_reloc, /* special_function */
1350 "R_PPC64_TOCSAVE", /* name */
1351 FALSE, /* partial_inplace */
1354 FALSE), /* pcrel_offset */
1356 /* Computes the load module index of the load module that contains the
1357 definition of its TLS sym. */
1358 HOWTO (R_PPC64_DTPMOD64,
1360 4, /* size (0 = byte, 1 = short, 2 = long) */
1362 FALSE, /* pc_relative */
1364 complain_overflow_dont, /* complain_on_overflow */
1365 ppc64_elf_unhandled_reloc, /* special_function */
1366 "R_PPC64_DTPMOD64", /* name */
1367 FALSE, /* partial_inplace */
1369 ONES (64), /* dst_mask */
1370 FALSE), /* pcrel_offset */
1372 /* Computes a dtv-relative displacement, the difference between the value
1373 of sym+add and the base address of the thread-local storage block that
1374 contains the definition of sym, minus 0x8000. */
1375 HOWTO (R_PPC64_DTPREL64,
1377 4, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE, /* pc_relative */
1381 complain_overflow_dont, /* complain_on_overflow */
1382 ppc64_elf_unhandled_reloc, /* special_function */
1383 "R_PPC64_DTPREL64", /* name */
1384 FALSE, /* partial_inplace */
1386 ONES (64), /* dst_mask */
1387 FALSE), /* pcrel_offset */
1389 /* A 16 bit dtprel reloc. */
1390 HOWTO (R_PPC64_DTPREL16,
1392 1, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE, /* pc_relative */
1396 complain_overflow_signed, /* complain_on_overflow */
1397 ppc64_elf_unhandled_reloc, /* special_function */
1398 "R_PPC64_DTPREL16", /* name */
1399 FALSE, /* partial_inplace */
1401 0xffff, /* dst_mask */
1402 FALSE), /* pcrel_offset */
1404 /* Like DTPREL16, but no overflow. */
1405 HOWTO (R_PPC64_DTPREL16_LO,
1407 1, /* size (0 = byte, 1 = short, 2 = long) */
1409 FALSE, /* pc_relative */
1411 complain_overflow_dont, /* complain_on_overflow */
1412 ppc64_elf_unhandled_reloc, /* special_function */
1413 "R_PPC64_DTPREL16_LO", /* name */
1414 FALSE, /* partial_inplace */
1416 0xffff, /* dst_mask */
1417 FALSE), /* pcrel_offset */
1419 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1420 HOWTO (R_PPC64_DTPREL16_HI,
1421 16, /* rightshift */
1422 1, /* size (0 = byte, 1 = short, 2 = long) */
1424 FALSE, /* pc_relative */
1426 complain_overflow_signed, /* complain_on_overflow */
1427 ppc64_elf_unhandled_reloc, /* special_function */
1428 "R_PPC64_DTPREL16_HI", /* name */
1429 FALSE, /* partial_inplace */
1431 0xffff, /* dst_mask */
1432 FALSE), /* pcrel_offset */
1434 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1435 HOWTO (R_PPC64_DTPREL16_HA,
1436 16, /* rightshift */
1437 1, /* size (0 = byte, 1 = short, 2 = long) */
1439 FALSE, /* pc_relative */
1441 complain_overflow_signed, /* complain_on_overflow */
1442 ppc64_elf_unhandled_reloc, /* special_function */
1443 "R_PPC64_DTPREL16_HA", /* name */
1444 FALSE, /* partial_inplace */
1446 0xffff, /* dst_mask */
1447 FALSE), /* pcrel_offset */
1449 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1450 HOWTO (R_PPC64_DTPREL16_HIGHER,
1451 32, /* rightshift */
1452 1, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE, /* pc_relative */
1456 complain_overflow_dont, /* complain_on_overflow */
1457 ppc64_elf_unhandled_reloc, /* special_function */
1458 "R_PPC64_DTPREL16_HIGHER", /* name */
1459 FALSE, /* partial_inplace */
1461 0xffff, /* dst_mask */
1462 FALSE), /* pcrel_offset */
1464 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1465 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1466 32, /* rightshift */
1467 1, /* size (0 = byte, 1 = short, 2 = long) */
1469 FALSE, /* pc_relative */
1471 complain_overflow_dont, /* complain_on_overflow */
1472 ppc64_elf_unhandled_reloc, /* special_function */
1473 "R_PPC64_DTPREL16_HIGHERA", /* name */
1474 FALSE, /* partial_inplace */
1476 0xffff, /* dst_mask */
1477 FALSE), /* pcrel_offset */
1479 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1480 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1481 48, /* rightshift */
1482 1, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE, /* pc_relative */
1486 complain_overflow_dont, /* complain_on_overflow */
1487 ppc64_elf_unhandled_reloc, /* special_function */
1488 "R_PPC64_DTPREL16_HIGHEST", /* name */
1489 FALSE, /* partial_inplace */
1491 0xffff, /* dst_mask */
1492 FALSE), /* pcrel_offset */
1494 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1495 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1496 48, /* rightshift */
1497 1, /* size (0 = byte, 1 = short, 2 = long) */
1499 FALSE, /* pc_relative */
1501 complain_overflow_dont, /* complain_on_overflow */
1502 ppc64_elf_unhandled_reloc, /* special_function */
1503 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1504 FALSE, /* partial_inplace */
1506 0xffff, /* dst_mask */
1507 FALSE), /* pcrel_offset */
1509 /* Like DTPREL16, but for insns with a DS field. */
1510 HOWTO (R_PPC64_DTPREL16_DS,
1512 1, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE, /* pc_relative */
1516 complain_overflow_signed, /* complain_on_overflow */
1517 ppc64_elf_unhandled_reloc, /* special_function */
1518 "R_PPC64_DTPREL16_DS", /* name */
1519 FALSE, /* partial_inplace */
1521 0xfffc, /* dst_mask */
1522 FALSE), /* pcrel_offset */
1524 /* Like DTPREL16_DS, but no overflow. */
1525 HOWTO (R_PPC64_DTPREL16_LO_DS,
1527 1, /* size (0 = byte, 1 = short, 2 = long) */
1529 FALSE, /* pc_relative */
1531 complain_overflow_dont, /* complain_on_overflow */
1532 ppc64_elf_unhandled_reloc, /* special_function */
1533 "R_PPC64_DTPREL16_LO_DS", /* name */
1534 FALSE, /* partial_inplace */
1536 0xfffc, /* dst_mask */
1537 FALSE), /* pcrel_offset */
1539 /* Computes a tp-relative displacement, the difference between the value of
1540 sym+add and the value of the thread pointer (r13). */
1541 HOWTO (R_PPC64_TPREL64,
1543 4, /* size (0 = byte, 1 = short, 2 = long) */
1545 FALSE, /* pc_relative */
1547 complain_overflow_dont, /* complain_on_overflow */
1548 ppc64_elf_unhandled_reloc, /* special_function */
1549 "R_PPC64_TPREL64", /* name */
1550 FALSE, /* partial_inplace */
1552 ONES (64), /* dst_mask */
1553 FALSE), /* pcrel_offset */
1555 /* A 16 bit tprel reloc. */
1556 HOWTO (R_PPC64_TPREL16,
1558 1, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE, /* pc_relative */
1562 complain_overflow_signed, /* complain_on_overflow */
1563 ppc64_elf_unhandled_reloc, /* special_function */
1564 "R_PPC64_TPREL16", /* name */
1565 FALSE, /* partial_inplace */
1567 0xffff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
1570 /* Like TPREL16, but no overflow. */
1571 HOWTO (R_PPC64_TPREL16_LO,
1573 1, /* size (0 = byte, 1 = short, 2 = long) */
1575 FALSE, /* pc_relative */
1577 complain_overflow_dont, /* complain_on_overflow */
1578 ppc64_elf_unhandled_reloc, /* special_function */
1579 "R_PPC64_TPREL16_LO", /* name */
1580 FALSE, /* partial_inplace */
1582 0xffff, /* dst_mask */
1583 FALSE), /* pcrel_offset */
1585 /* Like TPREL16_LO, but next higher group of 16 bits. */
1586 HOWTO (R_PPC64_TPREL16_HI,
1587 16, /* rightshift */
1588 1, /* size (0 = byte, 1 = short, 2 = long) */
1590 FALSE, /* pc_relative */
1592 complain_overflow_signed, /* complain_on_overflow */
1593 ppc64_elf_unhandled_reloc, /* special_function */
1594 "R_PPC64_TPREL16_HI", /* name */
1595 FALSE, /* partial_inplace */
1597 0xffff, /* dst_mask */
1598 FALSE), /* pcrel_offset */
1600 /* Like TPREL16_HI, but adjust for low 16 bits. */
1601 HOWTO (R_PPC64_TPREL16_HA,
1602 16, /* rightshift */
1603 1, /* size (0 = byte, 1 = short, 2 = long) */
1605 FALSE, /* pc_relative */
1607 complain_overflow_signed, /* complain_on_overflow */
1608 ppc64_elf_unhandled_reloc, /* special_function */
1609 "R_PPC64_TPREL16_HA", /* name */
1610 FALSE, /* partial_inplace */
1612 0xffff, /* dst_mask */
1613 FALSE), /* pcrel_offset */
1615 /* Like TPREL16_HI, but next higher group of 16 bits. */
1616 HOWTO (R_PPC64_TPREL16_HIGHER,
1617 32, /* rightshift */
1618 1, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE, /* pc_relative */
1622 complain_overflow_dont, /* complain_on_overflow */
1623 ppc64_elf_unhandled_reloc, /* special_function */
1624 "R_PPC64_TPREL16_HIGHER", /* name */
1625 FALSE, /* partial_inplace */
1627 0xffff, /* dst_mask */
1628 FALSE), /* pcrel_offset */
1630 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1631 HOWTO (R_PPC64_TPREL16_HIGHERA,
1632 32, /* rightshift */
1633 1, /* size (0 = byte, 1 = short, 2 = long) */
1635 FALSE, /* pc_relative */
1637 complain_overflow_dont, /* complain_on_overflow */
1638 ppc64_elf_unhandled_reloc, /* special_function */
1639 "R_PPC64_TPREL16_HIGHERA", /* name */
1640 FALSE, /* partial_inplace */
1642 0xffff, /* dst_mask */
1643 FALSE), /* pcrel_offset */
1645 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1646 HOWTO (R_PPC64_TPREL16_HIGHEST,
1647 48, /* rightshift */
1648 1, /* size (0 = byte, 1 = short, 2 = long) */
1650 FALSE, /* pc_relative */
1652 complain_overflow_dont, /* complain_on_overflow */
1653 ppc64_elf_unhandled_reloc, /* special_function */
1654 "R_PPC64_TPREL16_HIGHEST", /* name */
1655 FALSE, /* partial_inplace */
1657 0xffff, /* dst_mask */
1658 FALSE), /* pcrel_offset */
1660 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1661 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1662 48, /* rightshift */
1663 1, /* size (0 = byte, 1 = short, 2 = long) */
1665 FALSE, /* pc_relative */
1667 complain_overflow_dont, /* complain_on_overflow */
1668 ppc64_elf_unhandled_reloc, /* special_function */
1669 "R_PPC64_TPREL16_HIGHESTA", /* name */
1670 FALSE, /* partial_inplace */
1672 0xffff, /* dst_mask */
1673 FALSE), /* pcrel_offset */
1675 /* Like TPREL16, but for insns with a DS field. */
1676 HOWTO (R_PPC64_TPREL16_DS,
1678 1, /* size (0 = byte, 1 = short, 2 = long) */
1680 FALSE, /* pc_relative */
1682 complain_overflow_signed, /* complain_on_overflow */
1683 ppc64_elf_unhandled_reloc, /* special_function */
1684 "R_PPC64_TPREL16_DS", /* name */
1685 FALSE, /* partial_inplace */
1687 0xfffc, /* dst_mask */
1688 FALSE), /* pcrel_offset */
1690 /* Like TPREL16_DS, but no overflow. */
1691 HOWTO (R_PPC64_TPREL16_LO_DS,
1693 1, /* size (0 = byte, 1 = short, 2 = long) */
1695 FALSE, /* pc_relative */
1697 complain_overflow_dont, /* complain_on_overflow */
1698 ppc64_elf_unhandled_reloc, /* special_function */
1699 "R_PPC64_TPREL16_LO_DS", /* name */
1700 FALSE, /* partial_inplace */
1702 0xfffc, /* dst_mask */
1703 FALSE), /* pcrel_offset */
1705 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1706 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1707 to the first entry relative to the TOC base (r2). */
1708 HOWTO (R_PPC64_GOT_TLSGD16,
1710 1, /* size (0 = byte, 1 = short, 2 = long) */
1712 FALSE, /* pc_relative */
1714 complain_overflow_signed, /* complain_on_overflow */
1715 ppc64_elf_unhandled_reloc, /* special_function */
1716 "R_PPC64_GOT_TLSGD16", /* name */
1717 FALSE, /* partial_inplace */
1719 0xffff, /* dst_mask */
1720 FALSE), /* pcrel_offset */
1722 /* Like GOT_TLSGD16, but no overflow. */
1723 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1725 1, /* size (0 = byte, 1 = short, 2 = long) */
1727 FALSE, /* pc_relative */
1729 complain_overflow_dont, /* complain_on_overflow */
1730 ppc64_elf_unhandled_reloc, /* special_function */
1731 "R_PPC64_GOT_TLSGD16_LO", /* name */
1732 FALSE, /* partial_inplace */
1734 0xffff, /* dst_mask */
1735 FALSE), /* pcrel_offset */
1737 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1738 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1739 16, /* rightshift */
1740 1, /* size (0 = byte, 1 = short, 2 = long) */
1742 FALSE, /* pc_relative */
1744 complain_overflow_signed, /* complain_on_overflow */
1745 ppc64_elf_unhandled_reloc, /* special_function */
1746 "R_PPC64_GOT_TLSGD16_HI", /* name */
1747 FALSE, /* partial_inplace */
1749 0xffff, /* dst_mask */
1750 FALSE), /* pcrel_offset */
1752 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1753 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1754 16, /* rightshift */
1755 1, /* size (0 = byte, 1 = short, 2 = long) */
1757 FALSE, /* pc_relative */
1759 complain_overflow_signed, /* complain_on_overflow */
1760 ppc64_elf_unhandled_reloc, /* special_function */
1761 "R_PPC64_GOT_TLSGD16_HA", /* name */
1762 FALSE, /* partial_inplace */
1764 0xffff, /* dst_mask */
1765 FALSE), /* pcrel_offset */
1767 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1768 with values (sym+add)@dtpmod and zero, and computes the offset to the
1769 first entry relative to the TOC base (r2). */
1770 HOWTO (R_PPC64_GOT_TLSLD16,
1772 1, /* size (0 = byte, 1 = short, 2 = long) */
1774 FALSE, /* pc_relative */
1776 complain_overflow_signed, /* complain_on_overflow */
1777 ppc64_elf_unhandled_reloc, /* special_function */
1778 "R_PPC64_GOT_TLSLD16", /* name */
1779 FALSE, /* partial_inplace */
1781 0xffff, /* dst_mask */
1782 FALSE), /* pcrel_offset */
1784 /* Like GOT_TLSLD16, but no overflow. */
1785 HOWTO (R_PPC64_GOT_TLSLD16_LO,
1787 1, /* size (0 = byte, 1 = short, 2 = long) */
1789 FALSE, /* pc_relative */
1791 complain_overflow_dont, /* complain_on_overflow */
1792 ppc64_elf_unhandled_reloc, /* special_function */
1793 "R_PPC64_GOT_TLSLD16_LO", /* name */
1794 FALSE, /* partial_inplace */
1796 0xffff, /* dst_mask */
1797 FALSE), /* pcrel_offset */
1799 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1800 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1801 16, /* rightshift */
1802 1, /* size (0 = byte, 1 = short, 2 = long) */
1804 FALSE, /* pc_relative */
1806 complain_overflow_signed, /* complain_on_overflow */
1807 ppc64_elf_unhandled_reloc, /* special_function */
1808 "R_PPC64_GOT_TLSLD16_HI", /* name */
1809 FALSE, /* partial_inplace */
1811 0xffff, /* dst_mask */
1812 FALSE), /* pcrel_offset */
1814 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1815 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1816 16, /* rightshift */
1817 1, /* size (0 = byte, 1 = short, 2 = long) */
1819 FALSE, /* pc_relative */
1821 complain_overflow_signed, /* complain_on_overflow */
1822 ppc64_elf_unhandled_reloc, /* special_function */
1823 "R_PPC64_GOT_TLSLD16_HA", /* name */
1824 FALSE, /* partial_inplace */
1826 0xffff, /* dst_mask */
1827 FALSE), /* pcrel_offset */
1829 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1830 the offset to the entry relative to the TOC base (r2). */
1831 HOWTO (R_PPC64_GOT_DTPREL16_DS,
1833 1, /* size (0 = byte, 1 = short, 2 = long) */
1835 FALSE, /* pc_relative */
1837 complain_overflow_signed, /* complain_on_overflow */
1838 ppc64_elf_unhandled_reloc, /* special_function */
1839 "R_PPC64_GOT_DTPREL16_DS", /* name */
1840 FALSE, /* partial_inplace */
1842 0xfffc, /* dst_mask */
1843 FALSE), /* pcrel_offset */
1845 /* Like GOT_DTPREL16_DS, but no overflow. */
1846 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
1848 1, /* size (0 = byte, 1 = short, 2 = long) */
1850 FALSE, /* pc_relative */
1852 complain_overflow_dont, /* complain_on_overflow */
1853 ppc64_elf_unhandled_reloc, /* special_function */
1854 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1855 FALSE, /* partial_inplace */
1857 0xfffc, /* dst_mask */
1858 FALSE), /* pcrel_offset */
1860 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1861 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1862 16, /* rightshift */
1863 1, /* size (0 = byte, 1 = short, 2 = long) */
1865 FALSE, /* pc_relative */
1867 complain_overflow_signed, /* complain_on_overflow */
1868 ppc64_elf_unhandled_reloc, /* special_function */
1869 "R_PPC64_GOT_DTPREL16_HI", /* name */
1870 FALSE, /* partial_inplace */
1872 0xffff, /* dst_mask */
1873 FALSE), /* pcrel_offset */
1875 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1876 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1877 16, /* rightshift */
1878 1, /* size (0 = byte, 1 = short, 2 = long) */
1880 FALSE, /* pc_relative */
1882 complain_overflow_signed, /* complain_on_overflow */
1883 ppc64_elf_unhandled_reloc, /* special_function */
1884 "R_PPC64_GOT_DTPREL16_HA", /* name */
1885 FALSE, /* partial_inplace */
1887 0xffff, /* dst_mask */
1888 FALSE), /* pcrel_offset */
1890 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1891 offset to the entry relative to the TOC base (r2). */
1892 HOWTO (R_PPC64_GOT_TPREL16_DS,
1894 1, /* size (0 = byte, 1 = short, 2 = long) */
1896 FALSE, /* pc_relative */
1898 complain_overflow_signed, /* complain_on_overflow */
1899 ppc64_elf_unhandled_reloc, /* special_function */
1900 "R_PPC64_GOT_TPREL16_DS", /* name */
1901 FALSE, /* partial_inplace */
1903 0xfffc, /* dst_mask */
1904 FALSE), /* pcrel_offset */
1906 /* Like GOT_TPREL16_DS, but no overflow. */
1907 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1909 1, /* size (0 = byte, 1 = short, 2 = long) */
1911 FALSE, /* pc_relative */
1913 complain_overflow_dont, /* complain_on_overflow */
1914 ppc64_elf_unhandled_reloc, /* special_function */
1915 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1916 FALSE, /* partial_inplace */
1918 0xfffc, /* dst_mask */
1919 FALSE), /* pcrel_offset */
1921 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1922 HOWTO (R_PPC64_GOT_TPREL16_HI,
1923 16, /* rightshift */
1924 1, /* size (0 = byte, 1 = short, 2 = long) */
1926 FALSE, /* pc_relative */
1928 complain_overflow_signed, /* complain_on_overflow */
1929 ppc64_elf_unhandled_reloc, /* special_function */
1930 "R_PPC64_GOT_TPREL16_HI", /* name */
1931 FALSE, /* partial_inplace */
1933 0xffff, /* dst_mask */
1934 FALSE), /* pcrel_offset */
1936 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1937 HOWTO (R_PPC64_GOT_TPREL16_HA,
1938 16, /* rightshift */
1939 1, /* size (0 = byte, 1 = short, 2 = long) */
1941 FALSE, /* pc_relative */
1943 complain_overflow_signed, /* complain_on_overflow */
1944 ppc64_elf_unhandled_reloc, /* special_function */
1945 "R_PPC64_GOT_TPREL16_HA", /* name */
1946 FALSE, /* partial_inplace */
1948 0xffff, /* dst_mask */
1949 FALSE), /* pcrel_offset */
1951 HOWTO (R_PPC64_JMP_IREL, /* type */
1953 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1955 FALSE, /* pc_relative */
1957 complain_overflow_dont, /* complain_on_overflow */
1958 ppc64_elf_unhandled_reloc, /* special_function */
1959 "R_PPC64_JMP_IREL", /* name */
1960 FALSE, /* partial_inplace */
1963 FALSE), /* pcrel_offset */
1965 HOWTO (R_PPC64_IRELATIVE, /* type */
1967 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1969 FALSE, /* pc_relative */
1971 complain_overflow_dont, /* complain_on_overflow */
1972 bfd_elf_generic_reloc, /* special_function */
1973 "R_PPC64_IRELATIVE", /* name */
1974 FALSE, /* partial_inplace */
1976 ONES (64), /* dst_mask */
1977 FALSE), /* pcrel_offset */
1979 /* A 16 bit relative relocation. */
1980 HOWTO (R_PPC64_REL16, /* type */
1982 1, /* size (0 = byte, 1 = short, 2 = long) */
1984 TRUE, /* pc_relative */
1986 complain_overflow_signed, /* complain_on_overflow */
1987 bfd_elf_generic_reloc, /* special_function */
1988 "R_PPC64_REL16", /* name */
1989 FALSE, /* partial_inplace */
1991 0xffff, /* dst_mask */
1992 TRUE), /* pcrel_offset */
1994 /* A 16 bit relative relocation without overflow. */
1995 HOWTO (R_PPC64_REL16_LO, /* type */
1997 1, /* size (0 = byte, 1 = short, 2 = long) */
1999 TRUE, /* pc_relative */
2001 complain_overflow_dont,/* complain_on_overflow */
2002 bfd_elf_generic_reloc, /* special_function */
2003 "R_PPC64_REL16_LO", /* name */
2004 FALSE, /* partial_inplace */
2006 0xffff, /* dst_mask */
2007 TRUE), /* pcrel_offset */
2009 /* The high order 16 bits of a relative address. */
2010 HOWTO (R_PPC64_REL16_HI, /* type */
2011 16, /* rightshift */
2012 1, /* size (0 = byte, 1 = short, 2 = long) */
2014 TRUE, /* pc_relative */
2016 complain_overflow_signed, /* complain_on_overflow */
2017 bfd_elf_generic_reloc, /* special_function */
2018 "R_PPC64_REL16_HI", /* name */
2019 FALSE, /* partial_inplace */
2021 0xffff, /* dst_mask */
2022 TRUE), /* pcrel_offset */
2024 /* The high order 16 bits of a relative address, plus 1 if the contents of
2025 the low 16 bits, treated as a signed number, is negative. */
2026 HOWTO (R_PPC64_REL16_HA, /* type */
2027 16, /* rightshift */
2028 1, /* size (0 = byte, 1 = short, 2 = long) */
2030 TRUE, /* pc_relative */
2032 complain_overflow_signed, /* complain_on_overflow */
2033 ppc64_elf_ha_reloc, /* special_function */
2034 "R_PPC64_REL16_HA", /* name */
2035 FALSE, /* partial_inplace */
2037 0xffff, /* dst_mask */
2038 TRUE), /* pcrel_offset */
2040 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
2041 HOWTO (R_PPC64_REL16DX_HA, /* type */
2042 16, /* rightshift */
2043 2, /* size (0 = byte, 1 = short, 2 = long) */
2045 TRUE, /* pc_relative */
2047 complain_overflow_signed, /* complain_on_overflow */
2048 ppc64_elf_ha_reloc, /* special_function */
2049 "R_PPC64_REL16DX_HA", /* name */
2050 FALSE, /* partial_inplace */
2052 0x1fffc1, /* dst_mask */
2053 TRUE), /* pcrel_offset */
2055 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
2056 HOWTO (R_PPC64_16DX_HA, /* type */
2057 16, /* rightshift */
2058 2, /* size (0 = byte, 1 = short, 2 = long) */
2060 FALSE, /* pc_relative */
2062 complain_overflow_signed, /* complain_on_overflow */
2063 ppc64_elf_ha_reloc, /* special_function */
2064 "R_PPC64_16DX_HA", /* name */
2065 FALSE, /* partial_inplace */
2067 0x1fffc1, /* dst_mask */
2068 FALSE), /* pcrel_offset */
2070 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2071 HOWTO (R_PPC64_ADDR16_HIGH, /* type */
2072 16, /* rightshift */
2073 1, /* size (0 = byte, 1 = short, 2 = long) */
2075 FALSE, /* pc_relative */
2077 complain_overflow_dont, /* complain_on_overflow */
2078 bfd_elf_generic_reloc, /* special_function */
2079 "R_PPC64_ADDR16_HIGH", /* name */
2080 FALSE, /* partial_inplace */
2082 0xffff, /* dst_mask */
2083 FALSE), /* pcrel_offset */
2085 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2086 HOWTO (R_PPC64_ADDR16_HIGHA, /* type */
2087 16, /* rightshift */
2088 1, /* size (0 = byte, 1 = short, 2 = long) */
2090 FALSE, /* pc_relative */
2092 complain_overflow_dont, /* complain_on_overflow */
2093 ppc64_elf_ha_reloc, /* special_function */
2094 "R_PPC64_ADDR16_HIGHA", /* name */
2095 FALSE, /* partial_inplace */
2097 0xffff, /* dst_mask */
2098 FALSE), /* pcrel_offset */
2100 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2101 HOWTO (R_PPC64_DTPREL16_HIGH,
2102 16, /* rightshift */
2103 1, /* size (0 = byte, 1 = short, 2 = long) */
2105 FALSE, /* pc_relative */
2107 complain_overflow_dont, /* complain_on_overflow */
2108 ppc64_elf_unhandled_reloc, /* special_function */
2109 "R_PPC64_DTPREL16_HIGH", /* name */
2110 FALSE, /* partial_inplace */
2112 0xffff, /* dst_mask */
2113 FALSE), /* pcrel_offset */
2115 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2116 HOWTO (R_PPC64_DTPREL16_HIGHA,
2117 16, /* rightshift */
2118 1, /* size (0 = byte, 1 = short, 2 = long) */
2120 FALSE, /* pc_relative */
2122 complain_overflow_dont, /* complain_on_overflow */
2123 ppc64_elf_unhandled_reloc, /* special_function */
2124 "R_PPC64_DTPREL16_HIGHA", /* name */
2125 FALSE, /* partial_inplace */
2127 0xffff, /* dst_mask */
2128 FALSE), /* pcrel_offset */
2130 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2131 HOWTO (R_PPC64_TPREL16_HIGH,
2132 16, /* rightshift */
2133 1, /* size (0 = byte, 1 = short, 2 = long) */
2135 FALSE, /* pc_relative */
2137 complain_overflow_dont, /* complain_on_overflow */
2138 ppc64_elf_unhandled_reloc, /* special_function */
2139 "R_PPC64_TPREL16_HIGH", /* name */
2140 FALSE, /* partial_inplace */
2142 0xffff, /* dst_mask */
2143 FALSE), /* pcrel_offset */
2145 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2146 HOWTO (R_PPC64_TPREL16_HIGHA,
2147 16, /* rightshift */
2148 1, /* size (0 = byte, 1 = short, 2 = long) */
2150 FALSE, /* pc_relative */
2152 complain_overflow_dont, /* complain_on_overflow */
2153 ppc64_elf_unhandled_reloc, /* special_function */
2154 "R_PPC64_TPREL16_HIGHA", /* name */
2155 FALSE, /* partial_inplace */
2157 0xffff, /* dst_mask */
2158 FALSE), /* pcrel_offset */
2160 /* Marker reloc on ELFv2 large-model function entry. */
2161 HOWTO (R_PPC64_ENTRY,
2163 2, /* size (0 = byte, 1 = short, 2 = long) */
2165 FALSE, /* pc_relative */
2167 complain_overflow_dont, /* complain_on_overflow */
2168 bfd_elf_generic_reloc, /* special_function */
2169 "R_PPC64_ENTRY", /* name */
2170 FALSE, /* partial_inplace */
2173 FALSE), /* pcrel_offset */
2175 /* Like ADDR64, but use local entry point of function. */
2176 HOWTO (R_PPC64_ADDR64_LOCAL, /* type */
2178 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2180 FALSE, /* pc_relative */
2182 complain_overflow_dont, /* complain_on_overflow */
2183 bfd_elf_generic_reloc, /* special_function */
2184 "R_PPC64_ADDR64_LOCAL", /* name */
2185 FALSE, /* partial_inplace */
2187 ONES (64), /* dst_mask */
2188 FALSE), /* pcrel_offset */
2190 /* GNU extension to record C++ vtable hierarchy. */
2191 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
2193 0, /* size (0 = byte, 1 = short, 2 = long) */
2195 FALSE, /* pc_relative */
2197 complain_overflow_dont, /* complain_on_overflow */
2198 NULL, /* special_function */
2199 "R_PPC64_GNU_VTINHERIT", /* name */
2200 FALSE, /* partial_inplace */
2203 FALSE), /* pcrel_offset */
2205 /* GNU extension to record C++ vtable member usage. */
2206 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
2208 0, /* size (0 = byte, 1 = short, 2 = long) */
2210 FALSE, /* pc_relative */
2212 complain_overflow_dont, /* complain_on_overflow */
2213 NULL, /* special_function */
2214 "R_PPC64_GNU_VTENTRY", /* name */
2215 FALSE, /* partial_inplace */
2218 FALSE), /* pcrel_offset */
2222 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2226 ppc_howto_init (void)
2228 unsigned int i, type;
2230 for (i = 0; i < ARRAY_SIZE (ppc64_elf_howto_raw); i++)
2232 type = ppc64_elf_howto_raw[i].type;
2233 BFD_ASSERT (type < ARRAY_SIZE (ppc64_elf_howto_table));
2234 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
2238 static reloc_howto_type *
2239 ppc64_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
2240 bfd_reloc_code_real_type code)
2242 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
2244 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2245 /* Initialize howto table if needed. */
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];
2506 /* Set the howto pointer for a PowerPC ELF reloc. */
2509 ppc64_elf_info_to_howto (bfd *abfd, arelent *cache_ptr,
2510 Elf_Internal_Rela *dst)
2514 /* Initialize howto table if needed. */
2515 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2518 type = ELF64_R_TYPE (dst->r_info);
2519 if (type >= ARRAY_SIZE (ppc64_elf_howto_table))
2521 /* xgettext:c-format */
2522 _bfd_error_handler (_("%B: invalid relocation type %d"),
2524 type = R_PPC64_NONE;
2526 cache_ptr->howto = ppc64_elf_howto_table[type];
2529 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2531 static bfd_reloc_status_type
2532 ppc64_elf_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2533 void *data, asection *input_section,
2534 bfd *output_bfd, char **error_message)
2536 enum elf_ppc64_reloc_type r_type;
2538 bfd_size_type octets;
2541 /* If this is a relocatable link (output_bfd test tells us), just
2542 call the generic function. Any adjustment will be done at final
2544 if (output_bfd != NULL)
2545 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2546 input_section, output_bfd, error_message);
2548 /* Adjust the addend for sign extension of the low 16 bits.
2549 We won't actually be using the low 16 bits, so trashing them
2551 reloc_entry->addend += 0x8000;
2552 r_type = reloc_entry->howto->type;
2553 if (r_type != R_PPC64_REL16DX_HA)
2554 return bfd_reloc_continue;
2557 if (!bfd_is_com_section (symbol->section))
2558 value = symbol->value;
2559 value += (reloc_entry->addend
2560 + symbol->section->output_offset
2561 + symbol->section->output_section->vma);
2562 value -= (reloc_entry->address
2563 + input_section->output_offset
2564 + input_section->output_section->vma);
2565 value = (bfd_signed_vma) value >> 16;
2567 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2568 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2570 insn |= (value & 0xffc1) | ((value & 0x3e) << 15);
2571 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2572 if (value + 0x8000 > 0xffff)
2573 return bfd_reloc_overflow;
2574 return bfd_reloc_ok;
2577 static bfd_reloc_status_type
2578 ppc64_elf_branch_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2579 void *data, asection *input_section,
2580 bfd *output_bfd, char **error_message)
2582 if (output_bfd != NULL)
2583 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2584 input_section, output_bfd, error_message);
2586 if (strcmp (symbol->section->name, ".opd") == 0
2587 && (symbol->section->owner->flags & DYNAMIC) == 0)
2589 bfd_vma dest = opd_entry_value (symbol->section,
2590 symbol->value + reloc_entry->addend,
2592 if (dest != (bfd_vma) -1)
2593 reloc_entry->addend = dest - (symbol->value
2594 + symbol->section->output_section->vma
2595 + symbol->section->output_offset);
2599 elf_symbol_type *elfsym = (elf_symbol_type *) symbol;
2601 if (symbol->section->owner != abfd
2602 && symbol->section->owner != NULL
2603 && abiversion (symbol->section->owner) >= 2)
2607 for (i = 0; i < symbol->section->owner->symcount; ++i)
2609 asymbol *symdef = symbol->section->owner->outsymbols[i];
2611 if (strcmp (symdef->name, symbol->name) == 0)
2613 elfsym = (elf_symbol_type *) symdef;
2619 += PPC64_LOCAL_ENTRY_OFFSET (elfsym->internal_elf_sym.st_other);
2621 return bfd_reloc_continue;
2624 static bfd_reloc_status_type
2625 ppc64_elf_brtaken_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2626 void *data, asection *input_section,
2627 bfd *output_bfd, char **error_message)
2630 enum elf_ppc64_reloc_type r_type;
2631 bfd_size_type octets;
2632 /* Assume 'at' branch hints. */
2633 bfd_boolean is_isa_v2 = TRUE;
2635 /* If this is a relocatable link (output_bfd test tells us), just
2636 call the generic function. Any adjustment will be done at final
2638 if (output_bfd != NULL)
2639 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2640 input_section, output_bfd, error_message);
2642 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2643 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2644 insn &= ~(0x01 << 21);
2645 r_type = reloc_entry->howto->type;
2646 if (r_type == R_PPC64_ADDR14_BRTAKEN
2647 || r_type == R_PPC64_REL14_BRTAKEN)
2648 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2652 /* Set 'a' bit. This is 0b00010 in BO field for branch
2653 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2654 for branch on CTR insns (BO == 1a00t or 1a01t). */
2655 if ((insn & (0x14 << 21)) == (0x04 << 21))
2657 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2667 if (!bfd_is_com_section (symbol->section))
2668 target = symbol->value;
2669 target += symbol->section->output_section->vma;
2670 target += symbol->section->output_offset;
2671 target += reloc_entry->addend;
2673 from = (reloc_entry->address
2674 + input_section->output_offset
2675 + input_section->output_section->vma);
2677 /* Invert 'y' bit if not the default. */
2678 if ((bfd_signed_vma) (target - from) < 0)
2681 bfd_put_32 (abfd, insn, (bfd_byte *) data + octets);
2683 return ppc64_elf_branch_reloc (abfd, reloc_entry, symbol, data,
2684 input_section, output_bfd, error_message);
2687 static bfd_reloc_status_type
2688 ppc64_elf_sectoff_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2689 void *data, asection *input_section,
2690 bfd *output_bfd, char **error_message)
2692 /* If this is a relocatable link (output_bfd test tells us), just
2693 call the generic function. Any adjustment will be done at final
2695 if (output_bfd != NULL)
2696 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2697 input_section, output_bfd, error_message);
2699 /* Subtract the symbol section base address. */
2700 reloc_entry->addend -= symbol->section->output_section->vma;
2701 return bfd_reloc_continue;
2704 static bfd_reloc_status_type
2705 ppc64_elf_sectoff_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2706 void *data, asection *input_section,
2707 bfd *output_bfd, char **error_message)
2709 /* If this is a relocatable link (output_bfd test tells us), just
2710 call the generic function. Any adjustment will be done at final
2712 if (output_bfd != NULL)
2713 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2714 input_section, output_bfd, error_message);
2716 /* Subtract the symbol section base address. */
2717 reloc_entry->addend -= symbol->section->output_section->vma;
2719 /* Adjust the addend for sign extension of the low 16 bits. */
2720 reloc_entry->addend += 0x8000;
2721 return bfd_reloc_continue;
2724 static bfd_reloc_status_type
2725 ppc64_elf_toc_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2726 void *data, asection *input_section,
2727 bfd *output_bfd, char **error_message)
2731 /* If this is a relocatable link (output_bfd test tells us), just
2732 call the generic function. Any adjustment will be done at final
2734 if (output_bfd != NULL)
2735 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2736 input_section, output_bfd, error_message);
2738 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2740 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2742 /* Subtract the TOC base address. */
2743 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2744 return bfd_reloc_continue;
2747 static bfd_reloc_status_type
2748 ppc64_elf_toc_ha_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2749 void *data, asection *input_section,
2750 bfd *output_bfd, char **error_message)
2754 /* If this is a relocatable link (output_bfd test tells us), just
2755 call the generic function. Any adjustment will be done at final
2757 if (output_bfd != NULL)
2758 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2759 input_section, output_bfd, error_message);
2761 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2763 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2765 /* Subtract the TOC base address. */
2766 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2768 /* Adjust the addend for sign extension of the low 16 bits. */
2769 reloc_entry->addend += 0x8000;
2770 return bfd_reloc_continue;
2773 static bfd_reloc_status_type
2774 ppc64_elf_toc64_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2775 void *data, asection *input_section,
2776 bfd *output_bfd, char **error_message)
2779 bfd_size_type octets;
2781 /* If this is a relocatable link (output_bfd test tells us), just
2782 call the generic function. Any adjustment will be done at final
2784 if (output_bfd != NULL)
2785 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2786 input_section, output_bfd, error_message);
2788 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2790 TOCstart = ppc64_elf_set_toc (NULL, input_section->output_section->owner);
2792 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2793 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2794 return bfd_reloc_ok;
2797 static bfd_reloc_status_type
2798 ppc64_elf_unhandled_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
2799 void *data, asection *input_section,
2800 bfd *output_bfd, char **error_message)
2802 /* If this is a relocatable link (output_bfd test tells us), just
2803 call the generic function. Any adjustment will be done at final
2805 if (output_bfd != NULL)
2806 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2807 input_section, output_bfd, error_message);
2809 if (error_message != NULL)
2811 static char buf[60];
2812 sprintf (buf, "generic linker can't handle %s",
2813 reloc_entry->howto->name);
2814 *error_message = buf;
2816 return bfd_reloc_dangerous;
2819 /* Track GOT entries needed for a given symbol. We might need more
2820 than one got entry per symbol. */
2823 struct got_entry *next;
2825 /* The symbol addend that we'll be placing in the GOT. */
2828 /* Unlike other ELF targets, we use separate GOT entries for the same
2829 symbol referenced from different input files. This is to support
2830 automatic multiple TOC/GOT sections, where the TOC base can vary
2831 from one input file to another. After partitioning into TOC groups
2832 we merge entries within the group.
2834 Point to the BFD owning this GOT entry. */
2837 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2838 TLS_TPREL or TLS_DTPREL for tls entries. */
2839 unsigned char tls_type;
2841 /* Non-zero if got.ent points to real entry. */
2842 unsigned char is_indirect;
2844 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2847 bfd_signed_vma refcount;
2849 struct got_entry *ent;
2853 /* The same for PLT. */
2856 struct plt_entry *next;
2862 bfd_signed_vma refcount;
2867 struct ppc64_elf_obj_tdata
2869 struct elf_obj_tdata elf;
2871 /* Shortcuts to dynamic linker sections. */
2875 /* Used during garbage collection. We attach global symbols defined
2876 on removed .opd entries to this section so that the sym is removed. */
2877 asection *deleted_section;
2879 /* TLS local dynamic got entry handling. Support for multiple GOT
2880 sections means we potentially need one of these for each input bfd. */
2881 struct got_entry tlsld_got;
2884 /* A copy of relocs before they are modified for --emit-relocs. */
2885 Elf_Internal_Rela *relocs;
2887 /* Section contents. */
2891 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2892 the reloc to be in the range -32768 to 32767. */
2893 unsigned int has_small_toc_reloc : 1;
2895 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2896 instruction not one we handle. */
2897 unsigned int unexpected_toc_insn : 1;
2900 #define ppc64_elf_tdata(bfd) \
2901 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2903 #define ppc64_tlsld_got(bfd) \
2904 (&ppc64_elf_tdata (bfd)->tlsld_got)
2906 #define is_ppc64_elf(bfd) \
2907 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2908 && elf_object_id (bfd) == PPC64_ELF_DATA)
2910 /* Override the generic function because we store some extras. */
2913 ppc64_elf_mkobject (bfd *abfd)
2915 return bfd_elf_allocate_object (abfd, sizeof (struct ppc64_elf_obj_tdata),
2919 /* Fix bad default arch selected for a 64 bit input bfd when the
2920 default is 32 bit. Also select arch based on apuinfo. */
2923 ppc64_elf_object_p (bfd *abfd)
2925 if (!abfd->arch_info->the_default)
2928 if (abfd->arch_info->bits_per_word == 32)
2930 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2932 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2934 /* Relies on arch after 32 bit default being 64 bit default. */
2935 abfd->arch_info = abfd->arch_info->next;
2936 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2939 return _bfd_elf_ppc_set_arch (abfd);
2942 /* Support for core dump NOTE sections. */
2945 ppc64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
2947 size_t offset, size;
2949 if (note->descsz != 504)
2953 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
2956 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
2962 /* Make a ".reg/999" section. */
2963 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
2964 size, note->descpos + offset);
2968 ppc64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
2970 if (note->descsz != 136)
2973 elf_tdata (abfd)->core->pid
2974 = bfd_get_32 (abfd, note->descdata + 24);
2975 elf_tdata (abfd)->core->program
2976 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
2977 elf_tdata (abfd)->core->command
2978 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
2984 ppc64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type,
2997 va_start (ap, note_type);
2998 memset (data, 0, sizeof (data));
2999 strncpy (data + 40, va_arg (ap, const char *), 16);
3000 strncpy (data + 56, va_arg (ap, const char *), 80);
3002 return elfcore_write_note (abfd, buf, bufsiz,
3003 "CORE", note_type, data, sizeof (data));
3014 va_start (ap, note_type);
3015 memset (data, 0, 112);
3016 pid = va_arg (ap, long);
3017 bfd_put_32 (abfd, pid, data + 32);
3018 cursig = va_arg (ap, int);
3019 bfd_put_16 (abfd, cursig, data + 12);
3020 greg = va_arg (ap, const void *);
3021 memcpy (data + 112, greg, 384);
3022 memset (data + 496, 0, 8);
3024 return elfcore_write_note (abfd, buf, bufsiz,
3025 "CORE", note_type, data, sizeof (data));
3030 /* Add extra PPC sections. */
3032 static const struct bfd_elf_special_section ppc64_elf_special_sections[]=
3034 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, 0 },
3035 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
3036 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3037 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3038 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
3039 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
3040 { NULL, 0, 0, 0, 0 }
3043 enum _ppc64_sec_type {
3049 struct _ppc64_elf_section_data
3051 struct bfd_elf_section_data elf;
3055 /* An array with one entry for each opd function descriptor,
3056 and some spares since opd entries may be either 16 or 24 bytes. */
3057 #define OPD_NDX(OFF) ((OFF) >> 4)
3058 struct _opd_sec_data
3060 /* Points to the function code section for local opd entries. */
3061 asection **func_sec;
3063 /* After editing .opd, adjust references to opd local syms. */
3067 /* An array for toc sections, indexed by offset/8. */
3068 struct _toc_sec_data
3070 /* Specifies the relocation symbol index used at a given toc offset. */
3073 /* And the relocation addend. */
3078 enum _ppc64_sec_type sec_type:2;
3080 /* Flag set when small branches are detected. Used to
3081 select suitable defaults for the stub group size. */
3082 unsigned int has_14bit_branch:1;
3085 #define ppc64_elf_section_data(sec) \
3086 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
3089 ppc64_elf_new_section_hook (bfd *abfd, asection *sec)
3091 if (!sec->used_by_bfd)
3093 struct _ppc64_elf_section_data *sdata;
3094 bfd_size_type amt = sizeof (*sdata);
3096 sdata = bfd_zalloc (abfd, amt);
3099 sec->used_by_bfd = sdata;
3102 return _bfd_elf_new_section_hook (abfd, sec);
3105 static struct _opd_sec_data *
3106 get_opd_info (asection * sec)
3109 && ppc64_elf_section_data (sec) != NULL
3110 && ppc64_elf_section_data (sec)->sec_type == sec_opd)
3111 return &ppc64_elf_section_data (sec)->u.opd;
3115 /* Parameters for the qsort hook. */
3116 static bfd_boolean synthetic_relocatable;
3117 static asection *synthetic_opd;
3119 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3122 compare_symbols (const void *ap, const void *bp)
3124 const asymbol *a = * (const asymbol **) ap;
3125 const asymbol *b = * (const asymbol **) bp;
3127 /* Section symbols first. */
3128 if ((a->flags & BSF_SECTION_SYM) && !(b->flags & BSF_SECTION_SYM))
3130 if (!(a->flags & BSF_SECTION_SYM) && (b->flags & BSF_SECTION_SYM))
3133 /* then .opd symbols. */
3134 if (synthetic_opd != NULL)
3136 if (strcmp (a->section->name, ".opd") == 0
3137 && strcmp (b->section->name, ".opd") != 0)
3139 if (strcmp (a->section->name, ".opd") != 0
3140 && strcmp (b->section->name, ".opd") == 0)
3144 /* then other code symbols. */
3145 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3146 == (SEC_CODE | SEC_ALLOC)
3147 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3148 != (SEC_CODE | SEC_ALLOC))
3151 if ((a->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3152 != (SEC_CODE | SEC_ALLOC)
3153 && (b->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3154 == (SEC_CODE | SEC_ALLOC))
3157 if (synthetic_relocatable)
3159 if (a->section->id < b->section->id)
3162 if (a->section->id > b->section->id)
3166 if (a->value + a->section->vma < b->value + b->section->vma)
3169 if (a->value + a->section->vma > b->value + b->section->vma)
3172 /* For syms with the same value, prefer strong dynamic global function
3173 syms over other syms. */
3174 if ((a->flags & BSF_GLOBAL) != 0 && (b->flags & BSF_GLOBAL) == 0)
3177 if ((a->flags & BSF_GLOBAL) == 0 && (b->flags & BSF_GLOBAL) != 0)
3180 if ((a->flags & BSF_FUNCTION) != 0 && (b->flags & BSF_FUNCTION) == 0)
3183 if ((a->flags & BSF_FUNCTION) == 0 && (b->flags & BSF_FUNCTION) != 0)
3186 if ((a->flags & BSF_WEAK) == 0 && (b->flags & BSF_WEAK) != 0)
3189 if ((a->flags & BSF_WEAK) != 0 && (b->flags & BSF_WEAK) == 0)
3192 if ((a->flags & BSF_DYNAMIC) != 0 && (b->flags & BSF_DYNAMIC) == 0)
3195 if ((a->flags & BSF_DYNAMIC) == 0 && (b->flags & BSF_DYNAMIC) != 0)
3201 /* Search SYMS for a symbol of the given VALUE. */
3204 sym_exists_at (asymbol **syms, long lo, long hi, unsigned int id, bfd_vma value)
3208 if (id == (unsigned) -1)
3212 mid = (lo + hi) >> 1;
3213 if (syms[mid]->value + syms[mid]->section->vma < value)
3215 else if (syms[mid]->value + syms[mid]->section->vma > value)
3225 mid = (lo + hi) >> 1;
3226 if (syms[mid]->section->id < id)
3228 else if (syms[mid]->section->id > id)
3230 else if (syms[mid]->value < value)
3232 else if (syms[mid]->value > value)
3242 section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
3244 bfd_vma vma = *(bfd_vma *) ptr;
3245 return ((section->flags & SEC_ALLOC) != 0
3246 && section->vma <= vma
3247 && vma < section->vma + section->size);
3250 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3251 entry syms. Also generate @plt symbols for the glink branch table.
3252 Returns count of synthetic symbols in RET or -1 on error. */
3255 ppc64_elf_get_synthetic_symtab (bfd *abfd,
3256 long static_count, asymbol **static_syms,
3257 long dyn_count, asymbol **dyn_syms,
3264 long symcount, codesecsym, codesecsymend, secsymend, opdsymend;
3265 asection *opd = NULL;
3266 bfd_boolean relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
3268 int abi = abiversion (abfd);
3274 opd = bfd_get_section_by_name (abfd, ".opd");
3275 if (opd == NULL && abi == 1)
3287 symcount = static_count;
3289 symcount += dyn_count;
3293 syms = bfd_malloc ((symcount + 1) * sizeof (*syms));
3297 if (!relocatable && static_count != 0 && dyn_count != 0)
3299 /* Use both symbol tables. */
3300 memcpy (syms, static_syms, static_count * sizeof (*syms));
3301 memcpy (syms + static_count, dyn_syms,
3302 (dyn_count + 1) * sizeof (*syms));
3304 else if (!relocatable && static_count == 0)
3305 memcpy (syms, dyn_syms, (symcount + 1) * sizeof (*syms));
3307 memcpy (syms, static_syms, (symcount + 1) * sizeof (*syms));
3309 synthetic_relocatable = relocatable;
3310 synthetic_opd = opd;
3311 qsort (syms, symcount, sizeof (*syms), compare_symbols);
3313 if (!relocatable && symcount > 1)
3316 /* Trim duplicate syms, since we may have merged the normal and
3317 dynamic symbols. Actually, we only care about syms that have
3318 different values, so trim any with the same value. */
3319 for (i = 1, j = 1; i < symcount; ++i)
3320 if (syms[i - 1]->value + syms[i - 1]->section->vma
3321 != syms[i]->value + syms[i]->section->vma)
3322 syms[j++] = syms[i];
3327 /* Note that here and in compare_symbols we can't compare opd and
3328 sym->section directly. With separate debug info files, the
3329 symbols will be extracted from the debug file while abfd passed
3330 to this function is the real binary. */
3331 if (opd != NULL && strcmp (syms[i]->section->name, ".opd") == 0)
3335 for (; i < symcount; ++i)
3336 if (((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC
3337 | SEC_THREAD_LOCAL))
3338 != (SEC_CODE | SEC_ALLOC))
3339 || (syms[i]->flags & BSF_SECTION_SYM) == 0)
3343 for (; i < symcount; ++i)
3344 if ((syms[i]->flags & BSF_SECTION_SYM) == 0)
3348 for (; i < symcount; ++i)
3349 if (strcmp (syms[i]->section->name, ".opd") != 0)
3353 for (; i < symcount; ++i)
3354 if ((syms[i]->section->flags & (SEC_CODE | SEC_ALLOC | SEC_THREAD_LOCAL))
3355 != (SEC_CODE | SEC_ALLOC))
3363 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3368 if (opdsymend == secsymend)
3371 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3372 relcount = (opd->flags & SEC_RELOC) ? opd->reloc_count : 0;
3376 if (!(*slurp_relocs) (abfd, opd, static_syms, FALSE))
3383 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3387 while (r < opd->relocation + relcount
3388 && r->address < syms[i]->value + opd->vma)
3391 if (r == opd->relocation + relcount)
3394 if (r->address != syms[i]->value + opd->vma)
3397 if (r->howto->type != R_PPC64_ADDR64)
3400 sym = *r->sym_ptr_ptr;
3401 if (!sym_exists_at (syms, opdsymend, symcount,
3402 sym->section->id, sym->value + r->addend))
3405 size += sizeof (asymbol);
3406 size += strlen (syms[i]->name) + 2;
3412 s = *ret = bfd_malloc (size);
3419 names = (char *) (s + count);
3421 for (i = secsymend, r = opd->relocation; i < opdsymend; ++i)
3425 while (r < opd->relocation + relcount
3426 && r->address < syms[i]->value + opd->vma)
3429 if (r == opd->relocation + relcount)
3432 if (r->address != syms[i]->value + opd->vma)
3435 if (r->howto->type != R_PPC64_ADDR64)
3438 sym = *r->sym_ptr_ptr;
3439 if (!sym_exists_at (syms, opdsymend, symcount,
3440 sym->section->id, sym->value + r->addend))
3445 s->flags |= BSF_SYNTHETIC;
3446 s->section = sym->section;
3447 s->value = sym->value + r->addend;
3450 len = strlen (syms[i]->name);
3451 memcpy (names, syms[i]->name, len + 1);
3453 /* Have udata.p point back to the original symbol this
3454 synthetic symbol was derived from. */
3455 s->udata.p = syms[i];
3462 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
3463 bfd_byte *contents = NULL;
3466 bfd_vma glink_vma = 0, resolv_vma = 0;
3467 asection *dynamic, *glink = NULL, *relplt = NULL;
3470 if (opd != NULL && !bfd_malloc_and_get_section (abfd, opd, &contents))
3472 free_contents_and_exit_err:
3474 free_contents_and_exit:
3481 for (i = secsymend; i < opdsymend; ++i)
3485 /* Ignore bogus symbols. */
3486 if (syms[i]->value > opd->size - 8)
3489 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3490 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3493 size += sizeof (asymbol);
3494 size += strlen (syms[i]->name) + 2;
3498 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3500 && (dynamic = bfd_get_section_by_name (abfd, ".dynamic")) != NULL)
3502 bfd_byte *dynbuf, *extdyn, *extdynend;
3504 void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
3506 if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
3507 goto free_contents_and_exit_err;
3509 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
3510 swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
3513 extdynend = extdyn + dynamic->size;
3514 for (; extdyn < extdynend; extdyn += extdynsize)
3516 Elf_Internal_Dyn dyn;
3517 (*swap_dyn_in) (abfd, extdyn, &dyn);
3519 if (dyn.d_tag == DT_NULL)
3522 if (dyn.d_tag == DT_PPC64_GLINK)
3524 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
3525 See comment in ppc64_elf_finish_dynamic_sections. */
3526 glink_vma = dyn.d_un.d_val + 8 * 4;
3527 /* The .glink section usually does not survive the final
3528 link; search for the section (usually .text) where the
3529 glink stubs now reside. */
3530 glink = bfd_sections_find_if (abfd, section_covers_vma,
3541 /* Determine __glink trampoline by reading the relative branch
3542 from the first glink stub. */
3544 unsigned int off = 0;
3546 while (bfd_get_section_contents (abfd, glink, buf,
3547 glink_vma + off - glink->vma, 4))
3549 unsigned int insn = bfd_get_32 (abfd, buf);
3551 if ((insn & ~0x3fffffc) == 0)
3553 resolv_vma = glink_vma + off + (insn ^ 0x2000000) - 0x2000000;
3562 size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
3564 relplt = bfd_get_section_by_name (abfd, ".rela.plt");
3567 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
3568 if (! (*slurp_relocs) (abfd, relplt, dyn_syms, TRUE))
3569 goto free_contents_and_exit_err;
3571 plt_count = relplt->size / sizeof (Elf64_External_Rela);
3572 size += plt_count * sizeof (asymbol);
3574 p = relplt->relocation;
3575 for (i = 0; i < plt_count; i++, p++)
3577 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
3579 size += sizeof ("+0x") - 1 + 16;
3585 goto free_contents_and_exit;
3586 s = *ret = bfd_malloc (size);
3588 goto free_contents_and_exit_err;
3590 names = (char *) (s + count + plt_count + (resolv_vma != 0));
3592 for (i = secsymend; i < opdsymend; ++i)
3596 if (syms[i]->value > opd->size - 8)
3599 ent = bfd_get_64 (abfd, contents + syms[i]->value);
3600 if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
3604 asection *sec = abfd->sections;
3611 long mid = (lo + hi) >> 1;
3612 if (syms[mid]->section->vma < ent)
3614 else if (syms[mid]->section->vma > ent)
3618 sec = syms[mid]->section;
3623 if (lo >= hi && lo > codesecsym)
3624 sec = syms[lo - 1]->section;
3626 for (; sec != NULL; sec = sec->next)
3630 /* SEC_LOAD may not be set if SEC is from a separate debug
3632 if ((sec->flags & SEC_ALLOC) == 0)
3634 if ((sec->flags & SEC_CODE) != 0)
3637 s->flags |= BSF_SYNTHETIC;
3638 s->value = ent - s->section->vma;
3641 len = strlen (syms[i]->name);
3642 memcpy (names, syms[i]->name, len + 1);
3644 /* Have udata.p point back to the original symbol this
3645 synthetic symbol was derived from. */
3646 s->udata.p = syms[i];
3652 if (glink != NULL && relplt != NULL)
3656 /* Add a symbol for the main glink trampoline. */
3657 memset (s, 0, sizeof *s);
3659 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
3661 s->value = resolv_vma - glink->vma;
3663 memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3664 names += sizeof ("__glink_PLTresolve");
3669 /* FIXME: It would be very much nicer to put sym@plt on the
3670 stub rather than on the glink branch table entry. The
3671 objdump disassembler would then use a sensible symbol
3672 name on plt calls. The difficulty in doing so is
3673 a) finding the stubs, and,
3674 b) matching stubs against plt entries, and,
3675 c) there can be multiple stubs for a given plt entry.
3677 Solving (a) could be done by code scanning, but older
3678 ppc64 binaries used different stubs to current code.
3679 (b) is the tricky one since you need to known the toc
3680 pointer for at least one function that uses a pic stub to
3681 be able to calculate the plt address referenced.
3682 (c) means gdb would need to set multiple breakpoints (or
3683 find the glink branch itself) when setting breakpoints
3684 for pending shared library loads. */
3685 p = relplt->relocation;
3686 for (i = 0; i < plt_count; i++, p++)
3690 *s = **p->sym_ptr_ptr;
3691 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3692 we are defining a symbol, ensure one of them is set. */
3693 if ((s->flags & BSF_LOCAL) == 0)
3694 s->flags |= BSF_GLOBAL;
3695 s->flags |= BSF_SYNTHETIC;
3697 s->value = glink_vma - glink->vma;
3700 len = strlen ((*p->sym_ptr_ptr)->name);
3701 memcpy (names, (*p->sym_ptr_ptr)->name, len);
3705 memcpy (names, "+0x", sizeof ("+0x") - 1);
3706 names += sizeof ("+0x") - 1;
3707 bfd_sprintf_vma (abfd, names, p->addend);
3708 names += strlen (names);
3710 memcpy (names, "@plt", sizeof ("@plt"));
3711 names += sizeof ("@plt");
3731 /* The following functions are specific to the ELF linker, while
3732 functions above are used generally. Those named ppc64_elf_* are
3733 called by the main ELF linker code. They appear in this file more
3734 or less in the order in which they are called. eg.
3735 ppc64_elf_check_relocs is called early in the link process,
3736 ppc64_elf_finish_dynamic_sections is one of the last functions
3739 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3740 functions have both a function code symbol and a function descriptor
3741 symbol. A call to foo in a relocatable object file looks like:
3748 The function definition in another object file might be:
3752 . .quad .TOC.@tocbase
3758 When the linker resolves the call during a static link, the branch
3759 unsurprisingly just goes to .foo and the .opd information is unused.
3760 If the function definition is in a shared library, things are a little
3761 different: The call goes via a plt call stub, the opd information gets
3762 copied to the plt, and the linker patches the nop.
3770 . std 2,40(1) # in practice, the call stub
3771 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3772 . addi 11,11,Lfoo@toc@l # this is the general idea
3780 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3782 The "reloc ()" notation is supposed to indicate that the linker emits
3783 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3786 What are the difficulties here? Well, firstly, the relocations
3787 examined by the linker in check_relocs are against the function code
3788 sym .foo, while the dynamic relocation in the plt is emitted against
3789 the function descriptor symbol, foo. Somewhere along the line, we need
3790 to carefully copy dynamic link information from one symbol to the other.
3791 Secondly, the generic part of the elf linker will make .foo a dynamic
3792 symbol as is normal for most other backends. We need foo dynamic
3793 instead, at least for an application final link. However, when
3794 creating a shared library containing foo, we need to have both symbols
3795 dynamic so that references to .foo are satisfied during the early
3796 stages of linking. Otherwise the linker might decide to pull in a
3797 definition from some other object, eg. a static library.
3799 Update: As of August 2004, we support a new convention. Function
3800 calls may use the function descriptor symbol, ie. "bl foo". This
3801 behaves exactly as "bl .foo". */
3803 /* Of those relocs that might be copied as dynamic relocs, this
3804 function selects those that must be copied when linking a shared
3805 library or PIE, even when the symbol is local. */
3808 must_be_dyn_reloc (struct bfd_link_info *info,
3809 enum elf_ppc64_reloc_type r_type)
3814 /* Only relative relocs can be resolved when the object load
3815 address isn't fixed. DTPREL64 is excluded because the
3816 dynamic linker needs to differentiate global dynamic from
3817 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
3825 case R_PPC64_TPREL16:
3826 case R_PPC64_TPREL16_LO:
3827 case R_PPC64_TPREL16_HI:
3828 case R_PPC64_TPREL16_HA:
3829 case R_PPC64_TPREL16_DS:
3830 case R_PPC64_TPREL16_LO_DS:
3831 case R_PPC64_TPREL16_HIGH:
3832 case R_PPC64_TPREL16_HIGHA:
3833 case R_PPC64_TPREL16_HIGHER:
3834 case R_PPC64_TPREL16_HIGHERA:
3835 case R_PPC64_TPREL16_HIGHEST:
3836 case R_PPC64_TPREL16_HIGHESTA:
3837 case R_PPC64_TPREL64:
3838 /* These relocations are relative but in a shared library the
3839 linker doesn't know the thread pointer base. */
3840 return bfd_link_dll (info);
3844 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3845 copying dynamic variables from a shared lib into an app's dynbss
3846 section, and instead use a dynamic relocation to point into the
3847 shared lib. With code that gcc generates, it's vital that this be
3848 enabled; In the PowerPC64 ABI, the address of a function is actually
3849 the address of a function descriptor, which resides in the .opd
3850 section. gcc uses the descriptor directly rather than going via the
3851 GOT as some other ABI's do, which means that initialized function
3852 pointers must reference the descriptor. Thus, a function pointer
3853 initialized to the address of a function in a shared library will
3854 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3855 redefines the function descriptor symbol to point to the copy. This
3856 presents a problem as a plt entry for that function is also
3857 initialized from the function descriptor symbol and the copy reloc
3858 may not be initialized first. */
3859 #define ELIMINATE_COPY_RELOCS 1
3861 /* Section name for stubs is the associated section name plus this
3863 #define STUB_SUFFIX ".stub"
3866 ppc_stub_long_branch:
3867 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3868 destination, but a 24 bit branch in a stub section will reach.
3871 ppc_stub_plt_branch:
3872 Similar to the above, but a 24 bit branch in the stub section won't
3873 reach its destination.
3874 . addis %r11,%r2,xxx@toc@ha
3875 . ld %r12,xxx@toc@l(%r11)
3880 Used to call a function in a shared library. If it so happens that
3881 the plt entry referenced crosses a 64k boundary, then an extra
3882 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3884 . addis %r11,%r2,xxx@toc@ha
3885 . ld %r12,xxx+0@toc@l(%r11)
3887 . ld %r2,xxx+8@toc@l(%r11)
3888 . ld %r11,xxx+16@toc@l(%r11)
3891 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3892 code to adjust the value and save r2 to support multiple toc sections.
3893 A ppc_stub_long_branch with an r2 offset looks like:
3895 . addis %r2,%r2,off@ha
3896 . addi %r2,%r2,off@l
3899 A ppc_stub_plt_branch with an r2 offset looks like:
3901 . addis %r11,%r2,xxx@toc@ha
3902 . ld %r12,xxx@toc@l(%r11)
3903 . addis %r2,%r2,off@ha
3904 . addi %r2,%r2,off@l
3908 In cases where the "addis" instruction would add zero, the "addis" is
3909 omitted and following instructions modified slightly in some cases.
3912 enum ppc_stub_type {
3914 ppc_stub_long_branch,
3915 ppc_stub_long_branch_r2off,
3916 ppc_stub_plt_branch,
3917 ppc_stub_plt_branch_r2off,
3919 ppc_stub_plt_call_r2save,
3920 ppc_stub_global_entry,
3924 /* Information on stub grouping. */
3927 /* The stub section. */
3929 /* This is the section to which stubs in the group will be attached. */
3932 struct map_stub *next;
3933 /* Whether to emit a copy of register save/restore functions in this
3936 /* The offset of the __tls_get_addr_opt plt stub bctrl in this group,
3937 or -1u if no such stub with bctrl exists. */
3938 unsigned int tls_get_addr_opt_bctrl;
3941 struct ppc_stub_hash_entry {
3943 /* Base hash table entry structure. */
3944 struct bfd_hash_entry root;
3946 enum ppc_stub_type stub_type;
3948 /* Group information. */
3949 struct map_stub *group;
3951 /* Offset within stub_sec of the beginning of this stub. */
3952 bfd_vma stub_offset;
3954 /* Given the symbol's value and its section we can determine its final
3955 value when building the stubs (so the stub knows where to jump. */
3956 bfd_vma target_value;
3957 asection *target_section;
3959 /* The symbol table entry, if any, that this was derived from. */
3960 struct ppc_link_hash_entry *h;
3961 struct plt_entry *plt_ent;
3963 /* Symbol st_other. */
3964 unsigned char other;
3967 struct ppc_branch_hash_entry {
3969 /* Base hash table entry structure. */
3970 struct bfd_hash_entry root;
3972 /* Offset within branch lookup table. */
3973 unsigned int offset;
3975 /* Generation marker. */
3979 /* Used to track dynamic relocations for local symbols. */
3980 struct ppc_dyn_relocs
3982 struct ppc_dyn_relocs *next;
3984 /* The input section of the reloc. */
3987 /* Total number of relocs copied for the input section. */
3988 unsigned int count : 31;
3990 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3991 unsigned int ifunc : 1;
3994 struct ppc_link_hash_entry
3996 struct elf_link_hash_entry elf;
3999 /* A pointer to the most recently used stub hash entry against this
4001 struct ppc_stub_hash_entry *stub_cache;
4003 /* A pointer to the next symbol starting with a '.' */
4004 struct ppc_link_hash_entry *next_dot_sym;
4007 /* Track dynamic relocs copied for this symbol. */
4008 struct elf_dyn_relocs *dyn_relocs;
4010 /* Link between function code and descriptor symbols. */
4011 struct ppc_link_hash_entry *oh;
4013 /* Flag function code and descriptor symbols. */
4014 unsigned int is_func:1;
4015 unsigned int is_func_descriptor:1;
4016 unsigned int fake:1;
4018 /* Whether global opd/toc sym has been adjusted or not.
4019 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
4020 should be set for all globals defined in any opd/toc section. */
4021 unsigned int adjust_done:1;
4023 /* Set if this is an out-of-line register save/restore function,
4024 with non-standard calling convention. */
4025 unsigned int save_res:1;
4027 /* Set if a duplicate symbol with non-zero localentry is detected,
4028 even when the duplicate symbol does not provide a definition. */
4029 unsigned int non_zero_localentry:1;
4031 /* Contexts in which symbol is used in the GOT (or TOC).
4032 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
4033 corresponding relocs are encountered during check_relocs.
4034 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
4035 indicate the corresponding GOT entry type is not needed.
4036 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
4037 a TPREL one. We use a separate flag rather than setting TPREL
4038 just for convenience in distinguishing the two cases. */
4039 #define TLS_GD 1 /* GD reloc. */
4040 #define TLS_LD 2 /* LD reloc. */
4041 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
4042 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
4043 #define TLS_TLS 16 /* Any TLS reloc. */
4044 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
4045 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
4046 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
4047 unsigned char tls_mask;
4050 /* ppc64 ELF linker hash table. */
4052 struct ppc_link_hash_table
4054 struct elf_link_hash_table elf;
4056 /* The stub hash table. */
4057 struct bfd_hash_table stub_hash_table;
4059 /* Another hash table for plt_branch stubs. */
4060 struct bfd_hash_table branch_hash_table;
4062 /* Hash table for function prologue tocsave. */
4063 htab_t tocsave_htab;
4065 /* Various options and other info passed from the linker. */
4066 struct ppc64_elf_params *params;
4068 /* The size of sec_info below. */
4069 unsigned int sec_info_arr_size;
4071 /* Per-section array of extra section info. Done this way rather
4072 than as part of ppc64_elf_section_data so we have the info for
4073 non-ppc64 sections. */
4076 /* Along with elf_gp, specifies the TOC pointer used by this section. */
4081 /* The section group that this section belongs to. */
4082 struct map_stub *group;
4083 /* A temp section list pointer. */
4088 /* Linked list of groups. */
4089 struct map_stub *group;
4091 /* Temp used when calculating TOC pointers. */
4094 asection *toc_first_sec;
4096 /* Used when adding symbols. */
4097 struct ppc_link_hash_entry *dot_syms;
4099 /* Shortcuts to get to dynamic linker sections. */
4101 asection *global_entry;
4105 asection *glink_eh_frame;
4107 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
4108 struct ppc_link_hash_entry *tls_get_addr;
4109 struct ppc_link_hash_entry *tls_get_addr_fd;
4111 /* The size of reliplt used by got entry relocs. */
4112 bfd_size_type got_reli_size;
4115 unsigned long stub_count[ppc_stub_global_entry];
4117 /* Number of stubs against global syms. */
4118 unsigned long stub_globals;
4120 /* Set if we're linking code with function descriptors. */
4121 unsigned int opd_abi:1;
4123 /* Support for multiple toc sections. */
4124 unsigned int do_multi_toc:1;
4125 unsigned int multi_toc_needed:1;
4126 unsigned int second_toc_pass:1;
4127 unsigned int do_toc_opt:1;
4129 /* Set if tls optimization is enabled. */
4130 unsigned int do_tls_opt:1;
4133 unsigned int stub_error:1;
4135 /* Whether func_desc_adjust needs to be run over symbols. */
4136 unsigned int need_func_desc_adj:1;
4138 /* Whether there exist local gnu indirect function resolvers,
4139 referenced by dynamic relocations. */
4140 unsigned int local_ifunc_resolver:1;
4141 unsigned int maybe_local_ifunc_resolver:1;
4143 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
4144 unsigned int has_plt_localentry0:1;
4146 /* Incremented every time we size stubs. */
4147 unsigned int stub_iteration;
4149 /* Small local sym cache. */
4150 struct sym_cache sym_cache;
4153 /* Rename some of the generic section flags to better document how they
4156 /* Nonzero if this section has TLS related relocations. */
4157 #define has_tls_reloc sec_flg0
4159 /* Nonzero if this section has a call to __tls_get_addr. */
4160 #define has_tls_get_addr_call sec_flg1
4162 /* Nonzero if this section has any toc or got relocs. */
4163 #define has_toc_reloc sec_flg2
4165 /* Nonzero if this section has a call to another section that uses
4167 #define makes_toc_func_call sec_flg3
4169 /* Recursion protection when determining above flag. */
4170 #define call_check_in_progress sec_flg4
4171 #define call_check_done sec_flg5
4173 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4175 #define ppc_hash_table(p) \
4176 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4177 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4179 #define ppc_stub_hash_lookup(table, string, create, copy) \
4180 ((struct ppc_stub_hash_entry *) \
4181 bfd_hash_lookup ((table), (string), (create), (copy)))
4183 #define ppc_branch_hash_lookup(table, string, create, copy) \
4184 ((struct ppc_branch_hash_entry *) \
4185 bfd_hash_lookup ((table), (string), (create), (copy)))
4187 /* Create an entry in the stub hash table. */
4189 static struct bfd_hash_entry *
4190 stub_hash_newfunc (struct bfd_hash_entry *entry,
4191 struct bfd_hash_table *table,
4194 /* Allocate the structure if it has not already been allocated by a
4198 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
4203 /* Call the allocation method of the superclass. */
4204 entry = bfd_hash_newfunc (entry, table, string);
4207 struct ppc_stub_hash_entry *eh;
4209 /* Initialize the local fields. */
4210 eh = (struct ppc_stub_hash_entry *) entry;
4211 eh->stub_type = ppc_stub_none;
4213 eh->stub_offset = 0;
4214 eh->target_value = 0;
4215 eh->target_section = NULL;
4224 /* Create an entry in the branch hash table. */
4226 static struct bfd_hash_entry *
4227 branch_hash_newfunc (struct bfd_hash_entry *entry,
4228 struct bfd_hash_table *table,
4231 /* Allocate the structure if it has not already been allocated by a
4235 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
4240 /* Call the allocation method of the superclass. */
4241 entry = bfd_hash_newfunc (entry, table, string);
4244 struct ppc_branch_hash_entry *eh;
4246 /* Initialize the local fields. */
4247 eh = (struct ppc_branch_hash_entry *) entry;
4255 /* Create an entry in a ppc64 ELF linker hash table. */
4257 static struct bfd_hash_entry *
4258 link_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_link_hash_entry));
4271 /* Call the allocation method of the superclass. */
4272 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
4275 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
4277 memset (&eh->u.stub_cache, 0,
4278 (sizeof (struct ppc_link_hash_entry)
4279 - offsetof (struct ppc_link_hash_entry, u.stub_cache)));
4281 /* When making function calls, old ABI code references function entry
4282 points (dot symbols), while new ABI code references the function
4283 descriptor symbol. We need to make any combination of reference and
4284 definition work together, without breaking archive linking.
4286 For a defined function "foo" and an undefined call to "bar":
4287 An old object defines "foo" and ".foo", references ".bar" (possibly
4289 A new object defines "foo" and references "bar".
4291 A new object thus has no problem with its undefined symbols being
4292 satisfied by definitions in an old object. On the other hand, the
4293 old object won't have ".bar" satisfied by a new object.
4295 Keep a list of newly added dot-symbols. */
4297 if (string[0] == '.')
4299 struct ppc_link_hash_table *htab;
4301 htab = (struct ppc_link_hash_table *) table;
4302 eh->u.next_dot_sym = htab->dot_syms;
4303 htab->dot_syms = eh;
4310 struct tocsave_entry {
4316 tocsave_htab_hash (const void *p)
4318 const struct tocsave_entry *e = (const struct tocsave_entry *) p;
4319 return ((bfd_vma) (intptr_t) e->sec ^ e->offset) >> 3;
4323 tocsave_htab_eq (const void *p1, const void *p2)
4325 const struct tocsave_entry *e1 = (const struct tocsave_entry *) p1;
4326 const struct tocsave_entry *e2 = (const struct tocsave_entry *) p2;
4327 return e1->sec == e2->sec && e1->offset == e2->offset;
4330 /* Destroy a ppc64 ELF linker hash table. */
4333 ppc64_elf_link_hash_table_free (bfd *obfd)
4335 struct ppc_link_hash_table *htab;
4337 htab = (struct ppc_link_hash_table *) obfd->link.hash;
4338 if (htab->tocsave_htab)
4339 htab_delete (htab->tocsave_htab);
4340 bfd_hash_table_free (&htab->branch_hash_table);
4341 bfd_hash_table_free (&htab->stub_hash_table);
4342 _bfd_elf_link_hash_table_free (obfd);
4345 /* Create a ppc64 ELF linker hash table. */
4347 static struct bfd_link_hash_table *
4348 ppc64_elf_link_hash_table_create (bfd *abfd)
4350 struct ppc_link_hash_table *htab;
4351 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
4353 htab = bfd_zmalloc (amt);
4357 if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc,
4358 sizeof (struct ppc_link_hash_entry),
4365 /* Init the stub hash table too. */
4366 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
4367 sizeof (struct ppc_stub_hash_entry)))
4369 _bfd_elf_link_hash_table_free (abfd);
4373 /* And the branch hash table. */
4374 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
4375 sizeof (struct ppc_branch_hash_entry)))
4377 bfd_hash_table_free (&htab->stub_hash_table);
4378 _bfd_elf_link_hash_table_free (abfd);
4382 htab->tocsave_htab = htab_try_create (1024,
4386 if (htab->tocsave_htab == NULL)
4388 ppc64_elf_link_hash_table_free (abfd);
4391 htab->elf.root.hash_table_free = ppc64_elf_link_hash_table_free;
4393 /* Initializing two fields of the union is just cosmetic. We really
4394 only care about glist, but when compiled on a 32-bit host the
4395 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4396 debugger inspection of these fields look nicer. */
4397 htab->elf.init_got_refcount.refcount = 0;
4398 htab->elf.init_got_refcount.glist = NULL;
4399 htab->elf.init_plt_refcount.refcount = 0;
4400 htab->elf.init_plt_refcount.glist = NULL;
4401 htab->elf.init_got_offset.offset = 0;
4402 htab->elf.init_got_offset.glist = NULL;
4403 htab->elf.init_plt_offset.offset = 0;
4404 htab->elf.init_plt_offset.glist = NULL;
4406 return &htab->elf.root;
4409 /* Create sections for linker generated code. */
4412 create_linkage_sections (bfd *dynobj, struct bfd_link_info *info)
4414 struct ppc_link_hash_table *htab;
4417 htab = ppc_hash_table (info);
4419 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
4420 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4421 if (htab->params->save_restore_funcs)
4423 /* Create .sfpr for code to save and restore fp regs. */
4424 htab->sfpr = bfd_make_section_anyway_with_flags (dynobj, ".sfpr",
4426 if (htab->sfpr == NULL
4427 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
4431 if (bfd_link_relocatable (info))
4434 /* Create .glink for lazy dynamic linking support. */
4435 htab->glink = bfd_make_section_anyway_with_flags (dynobj, ".glink",
4437 if (htab->glink == NULL
4438 || ! bfd_set_section_alignment (dynobj, htab->glink, 3))
4441 /* The part of .glink used by global entry stubs, separate so that
4442 it can be aligned appropriately without affecting htab->glink. */
4443 htab->global_entry = bfd_make_section_anyway_with_flags (dynobj, ".glink",
4445 if (htab->global_entry == NULL
4446 || ! bfd_set_section_alignment (dynobj, htab->global_entry, 2))
4449 if (!info->no_ld_generated_unwind_info)
4451 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
4452 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4453 htab->glink_eh_frame = bfd_make_section_anyway_with_flags (dynobj,
4456 if (htab->glink_eh_frame == NULL
4457 || !bfd_set_section_alignment (dynobj, htab->glink_eh_frame, 2))
4461 flags = SEC_ALLOC | SEC_LINKER_CREATED;
4462 htab->elf.iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
4463 if (htab->elf.iplt == NULL
4464 || ! bfd_set_section_alignment (dynobj, htab->elf.iplt, 3))
4467 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4468 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4470 = bfd_make_section_anyway_with_flags (dynobj, ".rela.iplt", flags);
4471 if (htab->elf.irelplt == NULL
4472 || ! bfd_set_section_alignment (dynobj, htab->elf.irelplt, 3))
4475 /* Create branch lookup table for plt_branch stubs. */
4476 flags = (SEC_ALLOC | SEC_LOAD
4477 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4478 htab->brlt = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
4480 if (htab->brlt == NULL
4481 || ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
4484 if (!bfd_link_pic (info))
4487 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
4488 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4489 htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
4492 if (htab->relbrlt == NULL
4493 || ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
4499 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4502 ppc64_elf_init_stub_bfd (struct bfd_link_info *info,
4503 struct ppc64_elf_params *params)
4505 struct ppc_link_hash_table *htab;
4507 elf_elfheader (params->stub_bfd)->e_ident[EI_CLASS] = ELFCLASS64;
4509 /* Always hook our dynamic sections into the first bfd, which is the
4510 linker created stub bfd. This ensures that the GOT header is at
4511 the start of the output TOC section. */
4512 htab = ppc_hash_table (info);
4513 htab->elf.dynobj = params->stub_bfd;
4514 htab->params = params;
4516 return create_linkage_sections (htab->elf.dynobj, info);
4519 /* Build a name for an entry in the stub hash table. */
4522 ppc_stub_name (const asection *input_section,
4523 const asection *sym_sec,
4524 const struct ppc_link_hash_entry *h,
4525 const Elf_Internal_Rela *rel)
4530 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4531 offsets from a sym as a branch target? In fact, we could
4532 probably assume the addend is always zero. */
4533 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
4537 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
4538 stub_name = bfd_malloc (len);
4539 if (stub_name == NULL)
4542 len = sprintf (stub_name, "%08x.%s+%x",
4543 input_section->id & 0xffffffff,
4544 h->elf.root.root.string,
4545 (int) rel->r_addend & 0xffffffff);
4549 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4550 stub_name = bfd_malloc (len);
4551 if (stub_name == NULL)
4554 len = sprintf (stub_name, "%08x.%x:%x+%x",
4555 input_section->id & 0xffffffff,
4556 sym_sec->id & 0xffffffff,
4557 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
4558 (int) rel->r_addend & 0xffffffff);
4560 if (len > 2 && stub_name[len - 2] == '+' && stub_name[len - 1] == '0')
4561 stub_name[len - 2] = 0;
4565 /* Look up an entry in the stub hash. Stub entries are cached because
4566 creating the stub name takes a bit of time. */
4568 static struct ppc_stub_hash_entry *
4569 ppc_get_stub_entry (const asection *input_section,
4570 const asection *sym_sec,
4571 struct ppc_link_hash_entry *h,
4572 const Elf_Internal_Rela *rel,
4573 struct ppc_link_hash_table *htab)
4575 struct ppc_stub_hash_entry *stub_entry;
4576 struct map_stub *group;
4578 /* If this input section is part of a group of sections sharing one
4579 stub section, then use the id of the first section in the group.
4580 Stub names need to include a section id, as there may well be
4581 more than one stub used to reach say, printf, and we need to
4582 distinguish between them. */
4583 group = htab->sec_info[input_section->id].u.group;
4587 if (h != NULL && h->u.stub_cache != NULL
4588 && h->u.stub_cache->h == h
4589 && h->u.stub_cache->group == group)
4591 stub_entry = h->u.stub_cache;
4597 stub_name = ppc_stub_name (group->link_sec, sym_sec, h, rel);
4598 if (stub_name == NULL)
4601 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4602 stub_name, FALSE, FALSE);
4604 h->u.stub_cache = stub_entry;
4612 /* Add a new stub entry to the stub hash. Not all fields of the new
4613 stub entry are initialised. */
4615 static struct ppc_stub_hash_entry *
4616 ppc_add_stub (const char *stub_name,
4618 struct bfd_link_info *info)
4620 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4621 struct map_stub *group;
4624 struct ppc_stub_hash_entry *stub_entry;
4626 group = htab->sec_info[section->id].u.group;
4627 link_sec = group->link_sec;
4628 stub_sec = group->stub_sec;
4629 if (stub_sec == NULL)
4635 namelen = strlen (link_sec->name);
4636 len = namelen + sizeof (STUB_SUFFIX);
4637 s_name = bfd_alloc (htab->params->stub_bfd, len);
4641 memcpy (s_name, link_sec->name, namelen);
4642 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
4643 stub_sec = (*htab->params->add_stub_section) (s_name, link_sec);
4644 if (stub_sec == NULL)
4646 group->stub_sec = stub_sec;
4649 /* Enter this entry into the linker stub hash table. */
4650 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
4652 if (stub_entry == NULL)
4654 /* xgettext:c-format */
4655 info->callbacks->einfo (_("%P: %B: cannot create stub entry %s\n"),
4656 section->owner, stub_name);
4660 stub_entry->group = group;
4661 stub_entry->stub_offset = 0;
4665 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4666 not already done. */
4669 create_got_section (bfd *abfd, struct bfd_link_info *info)
4671 asection *got, *relgot;
4673 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4675 if (!is_ppc64_elf (abfd))
4681 && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
4684 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4685 | SEC_LINKER_CREATED);
4687 got = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
4689 || !bfd_set_section_alignment (abfd, got, 3))
4692 relgot = bfd_make_section_anyway_with_flags (abfd, ".rela.got",
4693 flags | SEC_READONLY);
4695 || ! bfd_set_section_alignment (abfd, relgot, 3))
4698 ppc64_elf_tdata (abfd)->got = got;
4699 ppc64_elf_tdata (abfd)->relgot = relgot;
4703 /* Follow indirect and warning symbol links. */
4705 static inline struct bfd_link_hash_entry *
4706 follow_link (struct bfd_link_hash_entry *h)
4708 while (h->type == bfd_link_hash_indirect
4709 || h->type == bfd_link_hash_warning)
4714 static inline struct elf_link_hash_entry *
4715 elf_follow_link (struct elf_link_hash_entry *h)
4717 return (struct elf_link_hash_entry *) follow_link (&h->root);
4720 static inline struct ppc_link_hash_entry *
4721 ppc_follow_link (struct ppc_link_hash_entry *h)
4723 return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
4726 /* Merge PLT info on FROM with that on TO. */
4729 move_plt_plist (struct ppc_link_hash_entry *from,
4730 struct ppc_link_hash_entry *to)
4732 if (from->elf.plt.plist != NULL)
4734 if (to->elf.plt.plist != NULL)
4736 struct plt_entry **entp;
4737 struct plt_entry *ent;
4739 for (entp = &from->elf.plt.plist; (ent = *entp) != NULL; )
4741 struct plt_entry *dent;
4743 for (dent = to->elf.plt.plist; dent != NULL; dent = dent->next)
4744 if (dent->addend == ent->addend)
4746 dent->plt.refcount += ent->plt.refcount;
4753 *entp = to->elf.plt.plist;
4756 to->elf.plt.plist = from->elf.plt.plist;
4757 from->elf.plt.plist = NULL;
4761 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4764 ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
4765 struct elf_link_hash_entry *dir,
4766 struct elf_link_hash_entry *ind)
4768 struct ppc_link_hash_entry *edir, *eind;
4770 edir = (struct ppc_link_hash_entry *) dir;
4771 eind = (struct ppc_link_hash_entry *) ind;
4773 edir->is_func |= eind->is_func;
4774 edir->is_func_descriptor |= eind->is_func_descriptor;
4775 edir->tls_mask |= eind->tls_mask;
4776 if (eind->oh != NULL)
4777 edir->oh = ppc_follow_link (eind->oh);
4779 if (edir->elf.versioned != versioned_hidden)
4780 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
4781 edir->elf.ref_regular |= eind->elf.ref_regular;
4782 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
4783 edir->elf.non_got_ref |= eind->elf.non_got_ref;
4784 edir->elf.needs_plt |= eind->elf.needs_plt;
4785 edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
4787 /* If we were called to copy over info for a weak sym, don't copy
4788 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4789 in order to simplify readonly_dynrelocs and save a field in the
4790 symbol hash entry, but that means dyn_relocs can't be used in any
4791 tests about a specific symbol, or affect other symbol flags which
4793 if (eind->elf.root.type != bfd_link_hash_indirect)
4796 /* Copy over any dynamic relocs we may have on the indirect sym. */
4797 if (eind->dyn_relocs != NULL)
4799 if (edir->dyn_relocs != NULL)
4801 struct elf_dyn_relocs **pp;
4802 struct elf_dyn_relocs *p;
4804 /* Add reloc counts against the indirect sym to the direct sym
4805 list. Merge any entries against the same section. */
4806 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
4808 struct elf_dyn_relocs *q;
4810 for (q = edir->dyn_relocs; q != NULL; q = q->next)
4811 if (q->sec == p->sec)
4813 q->pc_count += p->pc_count;
4814 q->count += p->count;
4821 *pp = edir->dyn_relocs;
4824 edir->dyn_relocs = eind->dyn_relocs;
4825 eind->dyn_relocs = NULL;
4828 /* Copy over got entries that we may have already seen to the
4829 symbol which just became indirect. */
4830 if (eind->elf.got.glist != NULL)
4832 if (edir->elf.got.glist != NULL)
4834 struct got_entry **entp;
4835 struct got_entry *ent;
4837 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
4839 struct got_entry *dent;
4841 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
4842 if (dent->addend == ent->addend
4843 && dent->owner == ent->owner
4844 && dent->tls_type == ent->tls_type)
4846 dent->got.refcount += ent->got.refcount;
4853 *entp = edir->elf.got.glist;
4856 edir->elf.got.glist = eind->elf.got.glist;
4857 eind->elf.got.glist = NULL;
4860 /* And plt entries. */
4861 move_plt_plist (eind, edir);
4863 if (eind->elf.dynindx != -1)
4865 if (edir->elf.dynindx != -1)
4866 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4867 edir->elf.dynstr_index);
4868 edir->elf.dynindx = eind->elf.dynindx;
4869 edir->elf.dynstr_index = eind->elf.dynstr_index;
4870 eind->elf.dynindx = -1;
4871 eind->elf.dynstr_index = 0;
4875 /* Find the function descriptor hash entry from the given function code
4876 hash entry FH. Link the entries via their OH fields. */
4878 static struct ppc_link_hash_entry *
4879 lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
4881 struct ppc_link_hash_entry *fdh = fh->oh;
4885 const char *fd_name = fh->elf.root.root.string + 1;
4887 fdh = (struct ppc_link_hash_entry *)
4888 elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
4892 fdh->is_func_descriptor = 1;
4898 fdh = ppc_follow_link (fdh);
4899 fdh->is_func_descriptor = 1;
4904 /* Make a fake function descriptor sym for the undefined code sym FH. */
4906 static struct ppc_link_hash_entry *
4907 make_fdh (struct bfd_link_info *info,
4908 struct ppc_link_hash_entry *fh)
4910 bfd *abfd = fh->elf.root.u.undef.abfd;
4911 struct bfd_link_hash_entry *bh = NULL;
4912 struct ppc_link_hash_entry *fdh;
4913 flagword flags = (fh->elf.root.type == bfd_link_hash_undefweak
4917 if (!_bfd_generic_link_add_one_symbol (info, abfd,
4918 fh->elf.root.root.string + 1,
4919 flags, bfd_und_section_ptr, 0,
4920 NULL, FALSE, FALSE, &bh))
4923 fdh = (struct ppc_link_hash_entry *) bh;
4924 fdh->elf.non_elf = 0;
4926 fdh->is_func_descriptor = 1;
4933 /* Fix function descriptor symbols defined in .opd sections to be
4937 ppc64_elf_add_symbol_hook (bfd *ibfd,
4938 struct bfd_link_info *info,
4939 Elf_Internal_Sym *isym,
4941 flagword *flags ATTRIBUTE_UNUSED,
4945 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
4946 && (ibfd->flags & DYNAMIC) == 0
4947 && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
4948 elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
4951 && strcmp ((*sec)->name, ".opd") == 0)
4955 if (!(ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
4956 || ELF_ST_TYPE (isym->st_info) == STT_FUNC))
4957 isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
4959 /* If the symbol is a function defined in .opd, and the function
4960 code is in a discarded group, let it appear to be undefined. */
4961 if (!bfd_link_relocatable (info)
4962 && (*sec)->reloc_count != 0
4963 && opd_entry_value (*sec, *value, &code_sec, NULL,
4964 FALSE) != (bfd_vma) -1
4965 && discarded_section (code_sec))
4967 *sec = bfd_und_section_ptr;
4968 isym->st_shndx = SHN_UNDEF;
4971 else if (*sec != NULL
4972 && strcmp ((*sec)->name, ".toc") == 0
4973 && ELF_ST_TYPE (isym->st_info) == STT_OBJECT)
4975 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4977 htab->params->object_in_toc = 1;
4980 if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
4982 if (abiversion (ibfd) == 0)
4983 set_abiversion (ibfd, 2);
4984 else if (abiversion (ibfd) == 1)
4986 info->callbacks->einfo (_("%P: symbol '%s' has invalid st_other"
4987 " for ABI version 1\n"), name);
4988 bfd_set_error (bfd_error_bad_value);
4996 /* Merge non-visibility st_other attributes: local entry point. */
4999 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
5000 const Elf_Internal_Sym *isym,
5001 bfd_boolean definition,
5002 bfd_boolean dynamic)
5004 if (definition && (!dynamic || !h->def_regular))
5005 h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1))
5006 | ELF_ST_VISIBILITY (h->other));
5009 /* Hook called on merging a symbol. We use this to clear "fake" since
5010 we now have a real symbol. */
5013 ppc64_elf_merge_symbol (struct elf_link_hash_entry *h,
5014 const Elf_Internal_Sym *isym,
5015 asection **psec ATTRIBUTE_UNUSED,
5016 bfd_boolean newdef ATTRIBUTE_UNUSED,
5017 bfd_boolean olddef ATTRIBUTE_UNUSED,
5018 bfd *oldbfd ATTRIBUTE_UNUSED,
5019 const asection *oldsec ATTRIBUTE_UNUSED)
5021 ((struct ppc_link_hash_entry *) h)->fake = 0;
5022 if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
5023 ((struct ppc_link_hash_entry *) h)->non_zero_localentry = 1;
5027 /* This function makes an old ABI object reference to ".bar" cause the
5028 inclusion of a new ABI object archive that defines "bar".
5029 NAME is a symbol defined in an archive. Return a symbol in the hash
5030 table that might be satisfied by the archive symbols. */
5032 static struct elf_link_hash_entry *
5033 ppc64_elf_archive_symbol_lookup (bfd *abfd,
5034 struct bfd_link_info *info,
5037 struct elf_link_hash_entry *h;
5041 h = _bfd_elf_archive_symbol_lookup (abfd, info, name);
5043 /* Don't return this sym if it is a fake function descriptor
5044 created by add_symbol_adjust. */
5045 && !((struct ppc_link_hash_entry *) h)->fake)
5051 len = strlen (name);
5052 dot_name = bfd_alloc (abfd, len + 2);
5053 if (dot_name == NULL)
5054 return (struct elf_link_hash_entry *) 0 - 1;
5056 memcpy (dot_name + 1, name, len + 1);
5057 h = _bfd_elf_archive_symbol_lookup (abfd, info, dot_name);
5058 bfd_release (abfd, dot_name);
5062 /* This function satisfies all old ABI object references to ".bar" if a
5063 new ABI object defines "bar". Well, at least, undefined dot symbols
5064 are made weak. This stops later archive searches from including an
5065 object if we already have a function descriptor definition. It also
5066 prevents the linker complaining about undefined symbols.
5067 We also check and correct mismatched symbol visibility here. The
5068 most restrictive visibility of the function descriptor and the
5069 function entry symbol is used. */
5072 add_symbol_adjust (struct ppc_link_hash_entry *eh, struct bfd_link_info *info)
5074 struct ppc_link_hash_table *htab;
5075 struct ppc_link_hash_entry *fdh;
5077 if (eh->elf.root.type == bfd_link_hash_warning)
5078 eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
5080 if (eh->elf.root.type == bfd_link_hash_indirect)
5083 if (eh->elf.root.root.string[0] != '.')
5086 htab = ppc_hash_table (info);
5090 fdh = lookup_fdh (eh, htab);
5092 && !bfd_link_relocatable (info)
5093 && (eh->elf.root.type == bfd_link_hash_undefined
5094 || eh->elf.root.type == bfd_link_hash_undefweak)
5095 && eh->elf.ref_regular)
5097 /* Make an undefined function descriptor sym, in order to
5098 pull in an --as-needed shared lib. Archives are handled
5100 fdh = make_fdh (info, eh);
5107 unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
5108 unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
5110 /* Make both descriptor and entry symbol have the most
5111 constraining visibility of either symbol. */
5112 if (entry_vis < descr_vis)
5113 fdh->elf.other += entry_vis - descr_vis;
5114 else if (entry_vis > descr_vis)
5115 eh->elf.other += descr_vis - entry_vis;
5117 /* Propagate reference flags from entry symbol to function
5118 descriptor symbol. */
5119 fdh->elf.root.non_ir_ref_regular |= eh->elf.root.non_ir_ref_regular;
5120 fdh->elf.root.non_ir_ref_dynamic |= eh->elf.root.non_ir_ref_dynamic;
5121 fdh->elf.ref_regular |= eh->elf.ref_regular;
5122 fdh->elf.ref_regular_nonweak |= eh->elf.ref_regular_nonweak;
5124 if (!fdh->elf.forced_local
5125 && fdh->elf.dynindx == -1
5126 && fdh->elf.versioned != versioned_hidden
5127 && (bfd_link_dll (info)
5128 || fdh->elf.def_dynamic
5129 || fdh->elf.ref_dynamic)
5130 && (eh->elf.ref_regular
5131 || eh->elf.def_regular))
5133 if (! bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
5141 /* Set up opd section info and abiversion for IBFD, and process list
5142 of dot-symbols we made in link_hash_newfunc. */
5145 ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
5147 struct ppc_link_hash_table *htab;
5148 struct ppc_link_hash_entry **p, *eh;
5149 asection *opd = bfd_get_section_by_name (ibfd, ".opd");
5151 if (opd != NULL && opd->size != 0)
5153 BFD_ASSERT (ppc64_elf_section_data (opd)->sec_type == sec_normal);
5154 ppc64_elf_section_data (opd)->sec_type = sec_opd;
5156 if (abiversion (ibfd) == 0)
5157 set_abiversion (ibfd, 1);
5158 else if (abiversion (ibfd) >= 2)
5160 /* xgettext:c-format */
5161 info->callbacks->einfo (_("%P: %B .opd not allowed in ABI"
5163 ibfd, abiversion (ibfd));
5164 bfd_set_error (bfd_error_bad_value);
5169 if (is_ppc64_elf (info->output_bfd))
5171 /* For input files without an explicit abiversion in e_flags
5172 we should have flagged any with symbol st_other bits set
5173 as ELFv1 and above flagged those with .opd as ELFv2.
5174 Set the output abiversion if not yet set, and for any input
5175 still ambiguous, take its abiversion from the output.
5176 Differences in ABI are reported later. */
5177 if (abiversion (info->output_bfd) == 0)
5178 set_abiversion (info->output_bfd, abiversion (ibfd));
5179 else if (abiversion (ibfd) == 0)
5180 set_abiversion (ibfd, abiversion (info->output_bfd));
5183 htab = ppc_hash_table (info);
5187 if (opd != NULL && opd->size != 0
5188 && (ibfd->flags & DYNAMIC) == 0
5189 && (opd->flags & SEC_RELOC) != 0
5190 && opd->reloc_count != 0
5191 && !bfd_is_abs_section (opd->output_section)
5192 && info->gc_sections)
5194 /* Garbage collection needs some extra help with .opd sections.
5195 We don't want to necessarily keep everything referenced by
5196 relocs in .opd, as that would keep all functions. Instead,
5197 if we reference an .opd symbol (a function descriptor), we
5198 want to keep the function code symbol's section. This is
5199 easy for global symbols, but for local syms we need to keep
5200 information about the associated function section. */
5202 asection **opd_sym_map;
5203 Elf_Internal_Shdr *symtab_hdr;
5204 Elf_Internal_Rela *relocs, *rel_end, *rel;
5206 amt = OPD_NDX (opd->size) * sizeof (*opd_sym_map);
5207 opd_sym_map = bfd_zalloc (ibfd, amt);
5208 if (opd_sym_map == NULL)
5210 ppc64_elf_section_data (opd)->u.opd.func_sec = opd_sym_map;
5211 relocs = _bfd_elf_link_read_relocs (ibfd, opd, NULL, NULL,
5215 symtab_hdr = &elf_symtab_hdr (ibfd);
5216 rel_end = relocs + opd->reloc_count - 1;
5217 for (rel = relocs; rel < rel_end; rel++)
5219 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
5220 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
5222 if (r_type == R_PPC64_ADDR64
5223 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC
5224 && r_symndx < symtab_hdr->sh_info)
5226 Elf_Internal_Sym *isym;
5229 isym = bfd_sym_from_r_symndx (&htab->sym_cache, ibfd, r_symndx);
5232 if (elf_section_data (opd)->relocs != relocs)
5237 s = bfd_section_from_elf_index (ibfd, isym->st_shndx);
5238 if (s != NULL && s != opd)
5239 opd_sym_map[OPD_NDX (rel->r_offset)] = s;
5242 if (elf_section_data (opd)->relocs != relocs)
5246 p = &htab->dot_syms;
5247 while ((eh = *p) != NULL)
5250 if (&eh->elf == htab->elf.hgot)
5252 else if (htab->elf.hgot == NULL
5253 && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
5254 htab->elf.hgot = &eh->elf;
5255 else if (abiversion (ibfd) <= 1)
5257 htab->need_func_desc_adj = 1;
5258 if (!add_symbol_adjust (eh, info))
5261 p = &eh->u.next_dot_sym;
5266 /* Undo hash table changes when an --as-needed input file is determined
5267 not to be needed. */
5270 ppc64_elf_notice_as_needed (bfd *ibfd,
5271 struct bfd_link_info *info,
5272 enum notice_asneeded_action act)
5274 if (act == notice_not_needed)
5276 struct ppc_link_hash_table *htab = ppc_hash_table (info);
5281 htab->dot_syms = NULL;
5283 return _bfd_elf_notice_as_needed (ibfd, info, act);
5286 /* If --just-symbols against a final linked binary, then assume we need
5287 toc adjusting stubs when calling functions defined there. */
5290 ppc64_elf_link_just_syms (asection *sec, struct bfd_link_info *info)
5292 if ((sec->flags & SEC_CODE) != 0
5293 && (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
5294 && is_ppc64_elf (sec->owner))
5296 if (abiversion (sec->owner) >= 2
5297 || bfd_get_section_by_name (sec->owner, ".opd") != NULL)
5298 sec->has_toc_reloc = 1;
5300 _bfd_elf_link_just_syms (sec, info);
5303 static struct plt_entry **
5304 update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
5305 unsigned long r_symndx, bfd_vma r_addend, int tls_type)
5307 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
5308 struct plt_entry **local_plt;
5309 unsigned char *local_got_tls_masks;
5311 if (local_got_ents == NULL)
5313 bfd_size_type size = symtab_hdr->sh_info;
5315 size *= (sizeof (*local_got_ents)
5316 + sizeof (*local_plt)
5317 + sizeof (*local_got_tls_masks));
5318 local_got_ents = bfd_zalloc (abfd, size);
5319 if (local_got_ents == NULL)
5321 elf_local_got_ents (abfd) = local_got_ents;
5324 if ((tls_type & (PLT_IFUNC | TLS_EXPLICIT)) == 0)
5326 struct got_entry *ent;
5328 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
5329 if (ent->addend == r_addend
5330 && ent->owner == abfd
5331 && ent->tls_type == tls_type)
5335 bfd_size_type amt = sizeof (*ent);
5336 ent = bfd_alloc (abfd, amt);
5339 ent->next = local_got_ents[r_symndx];
5340 ent->addend = r_addend;
5342 ent->tls_type = tls_type;
5343 ent->is_indirect = FALSE;
5344 ent->got.refcount = 0;
5345 local_got_ents[r_symndx] = ent;
5347 ent->got.refcount += 1;
5350 local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info);
5351 local_got_tls_masks = (unsigned char *) (local_plt + symtab_hdr->sh_info);
5352 local_got_tls_masks[r_symndx] |= tls_type;
5354 return local_plt + r_symndx;
5358 update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
5360 struct plt_entry *ent;
5362 for (ent = *plist; ent != NULL; ent = ent->next)
5363 if (ent->addend == addend)
5367 bfd_size_type amt = sizeof (*ent);
5368 ent = bfd_alloc (abfd, amt);
5372 ent->addend = addend;
5373 ent->plt.refcount = 0;
5376 ent->plt.refcount += 1;
5381 is_branch_reloc (enum elf_ppc64_reloc_type r_type)
5383 return (r_type == R_PPC64_REL24
5384 || r_type == R_PPC64_REL14
5385 || r_type == R_PPC64_REL14_BRTAKEN
5386 || r_type == R_PPC64_REL14_BRNTAKEN
5387 || r_type == R_PPC64_ADDR24
5388 || r_type == R_PPC64_ADDR14
5389 || r_type == R_PPC64_ADDR14_BRTAKEN
5390 || r_type == R_PPC64_ADDR14_BRNTAKEN);
5393 /* Look through the relocs for a section during the first phase, and
5394 calculate needed space in the global offset table, procedure
5395 linkage table, and dynamic reloc sections. */
5398 ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
5399 asection *sec, const Elf_Internal_Rela *relocs)
5401 struct ppc_link_hash_table *htab;
5402 Elf_Internal_Shdr *symtab_hdr;
5403 struct elf_link_hash_entry **sym_hashes;
5404 const Elf_Internal_Rela *rel;
5405 const Elf_Internal_Rela *rel_end;
5407 struct elf_link_hash_entry *tga, *dottga;
5410 if (bfd_link_relocatable (info))
5413 /* Don't do anything special with non-loaded, non-alloced sections.
5414 In particular, any relocs in such sections should not affect GOT
5415 and PLT reference counting (ie. we don't allow them to create GOT
5416 or PLT entries), there's no possibility or desire to optimize TLS
5417 relocs, and there's not much point in propagating relocs to shared
5418 libs that the dynamic linker won't relocate. */
5419 if ((sec->flags & SEC_ALLOC) == 0)
5422 BFD_ASSERT (is_ppc64_elf (abfd));
5424 htab = ppc_hash_table (info);
5428 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
5429 FALSE, FALSE, TRUE);
5430 dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
5431 FALSE, FALSE, TRUE);
5432 symtab_hdr = &elf_symtab_hdr (abfd);
5433 sym_hashes = elf_sym_hashes (abfd);
5435 is_opd = ppc64_elf_section_data (sec)->sec_type == sec_opd;
5436 rel_end = relocs + sec->reloc_count;
5437 for (rel = relocs; rel < rel_end; rel++)
5439 unsigned long r_symndx;
5440 struct elf_link_hash_entry *h;
5441 enum elf_ppc64_reloc_type r_type;
5443 struct _ppc64_elf_section_data *ppc64_sec;
5444 struct plt_entry **ifunc, **plt_list;
5446 r_symndx = ELF64_R_SYM (rel->r_info);
5447 if (r_symndx < symtab_hdr->sh_info)
5451 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5452 h = elf_follow_link (h);
5454 if (h == htab->elf.hgot)
5455 sec->has_toc_reloc = 1;
5462 if (h->type == STT_GNU_IFUNC)
5465 ifunc = &h->plt.plist;
5470 Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5475 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
5477 ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
5478 rel->r_addend, PLT_IFUNC);
5484 r_type = ELF64_R_TYPE (rel->r_info);
5489 /* These special tls relocs tie a call to __tls_get_addr with
5490 its parameter symbol. */
5493 case R_PPC64_GOT_TLSLD16:
5494 case R_PPC64_GOT_TLSLD16_LO:
5495 case R_PPC64_GOT_TLSLD16_HI:
5496 case R_PPC64_GOT_TLSLD16_HA:
5497 tls_type = TLS_TLS | TLS_LD;
5500 case R_PPC64_GOT_TLSGD16:
5501 case R_PPC64_GOT_TLSGD16_LO:
5502 case R_PPC64_GOT_TLSGD16_HI:
5503 case R_PPC64_GOT_TLSGD16_HA:
5504 tls_type = TLS_TLS | TLS_GD;
5507 case R_PPC64_GOT_TPREL16_DS:
5508 case R_PPC64_GOT_TPREL16_LO_DS:
5509 case R_PPC64_GOT_TPREL16_HI:
5510 case R_PPC64_GOT_TPREL16_HA:
5511 if (bfd_link_dll (info))
5512 info->flags |= DF_STATIC_TLS;
5513 tls_type = TLS_TLS | TLS_TPREL;
5516 case R_PPC64_GOT_DTPREL16_DS:
5517 case R_PPC64_GOT_DTPREL16_LO_DS:
5518 case R_PPC64_GOT_DTPREL16_HI:
5519 case R_PPC64_GOT_DTPREL16_HA:
5520 tls_type = TLS_TLS | TLS_DTPREL;
5522 sec->has_tls_reloc = 1;
5526 case R_PPC64_GOT16_DS:
5527 case R_PPC64_GOT16_HA:
5528 case R_PPC64_GOT16_HI:
5529 case R_PPC64_GOT16_LO:
5530 case R_PPC64_GOT16_LO_DS:
5531 /* This symbol requires a global offset table entry. */
5532 sec->has_toc_reloc = 1;
5533 if (r_type == R_PPC64_GOT_TLSLD16
5534 || r_type == R_PPC64_GOT_TLSGD16
5535 || r_type == R_PPC64_GOT_TPREL16_DS
5536 || r_type == R_PPC64_GOT_DTPREL16_DS
5537 || r_type == R_PPC64_GOT16
5538 || r_type == R_PPC64_GOT16_DS)
5540 htab->do_multi_toc = 1;
5541 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5544 if (ppc64_elf_tdata (abfd)->got == NULL
5545 && !create_got_section (abfd, info))
5550 struct ppc_link_hash_entry *eh;
5551 struct got_entry *ent;
5553 eh = (struct ppc_link_hash_entry *) h;
5554 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
5555 if (ent->addend == rel->r_addend
5556 && ent->owner == abfd
5557 && ent->tls_type == tls_type)
5561 bfd_size_type amt = sizeof (*ent);
5562 ent = bfd_alloc (abfd, amt);
5565 ent->next = eh->elf.got.glist;
5566 ent->addend = rel->r_addend;
5568 ent->tls_type = tls_type;
5569 ent->is_indirect = FALSE;
5570 ent->got.refcount = 0;
5571 eh->elf.got.glist = ent;
5573 ent->got.refcount += 1;
5574 eh->tls_mask |= tls_type;
5577 /* This is a global offset table entry for a local symbol. */
5578 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5579 rel->r_addend, tls_type))
5582 /* We may also need a plt entry if the symbol turns out to be
5584 if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1)
5586 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5591 case R_PPC64_PLT16_HA:
5592 case R_PPC64_PLT16_HI:
5593 case R_PPC64_PLT16_LO:
5596 /* This symbol requires a procedure linkage table entry. */
5601 if (h->root.root.string[0] == '.'
5602 && h->root.root.string[1] != '\0')
5603 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5604 plt_list = &h->plt.plist;
5606 if (plt_list == NULL)
5608 /* It does not make sense to have a procedure linkage
5609 table entry for a non-ifunc local symbol. */
5610 info->callbacks->einfo
5611 /* xgettext:c-format */
5612 (_("%H: %s reloc against local symbol\n"),
5613 abfd, sec, rel->r_offset,
5614 ppc64_elf_howto_table[r_type]->name);
5615 bfd_set_error (bfd_error_bad_value);
5618 if (!update_plt_info (abfd, plt_list, rel->r_addend))
5622 /* The following relocations don't need to propagate the
5623 relocation if linking a shared object since they are
5624 section relative. */
5625 case R_PPC64_SECTOFF:
5626 case R_PPC64_SECTOFF_LO:
5627 case R_PPC64_SECTOFF_HI:
5628 case R_PPC64_SECTOFF_HA:
5629 case R_PPC64_SECTOFF_DS:
5630 case R_PPC64_SECTOFF_LO_DS:
5631 case R_PPC64_DTPREL16:
5632 case R_PPC64_DTPREL16_LO:
5633 case R_PPC64_DTPREL16_HI:
5634 case R_PPC64_DTPREL16_HA:
5635 case R_PPC64_DTPREL16_DS:
5636 case R_PPC64_DTPREL16_LO_DS:
5637 case R_PPC64_DTPREL16_HIGH:
5638 case R_PPC64_DTPREL16_HIGHA:
5639 case R_PPC64_DTPREL16_HIGHER:
5640 case R_PPC64_DTPREL16_HIGHERA:
5641 case R_PPC64_DTPREL16_HIGHEST:
5642 case R_PPC64_DTPREL16_HIGHESTA:
5647 case R_PPC64_REL16_LO:
5648 case R_PPC64_REL16_HI:
5649 case R_PPC64_REL16_HA:
5650 case R_PPC64_REL16DX_HA:
5653 /* Not supported as a dynamic relocation. */
5654 case R_PPC64_ADDR64_LOCAL:
5655 if (bfd_link_pic (info))
5657 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5659 /* xgettext:c-format */
5660 info->callbacks->einfo (_("%H: %s reloc unsupported "
5661 "in shared libraries and PIEs.\n"),
5662 abfd, sec, rel->r_offset,
5663 ppc64_elf_howto_table[r_type]->name);
5664 bfd_set_error (bfd_error_bad_value);
5670 case R_PPC64_TOC16_DS:
5671 htab->do_multi_toc = 1;
5672 ppc64_elf_tdata (abfd)->has_small_toc_reloc = 1;
5674 case R_PPC64_TOC16_LO:
5675 case R_PPC64_TOC16_HI:
5676 case R_PPC64_TOC16_HA:
5677 case R_PPC64_TOC16_LO_DS:
5678 sec->has_toc_reloc = 1;
5685 /* This relocation describes the C++ object vtable hierarchy.
5686 Reconstruct it for later use during GC. */
5687 case R_PPC64_GNU_VTINHERIT:
5688 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5692 /* This relocation describes which C++ vtable entries are actually
5693 used. Record for later use during GC. */
5694 case R_PPC64_GNU_VTENTRY:
5695 BFD_ASSERT (h != NULL);
5697 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
5702 case R_PPC64_REL14_BRTAKEN:
5703 case R_PPC64_REL14_BRNTAKEN:
5705 asection *dest = NULL;
5707 /* Heuristic: If jumping outside our section, chances are
5708 we are going to need a stub. */
5711 /* If the sym is weak it may be overridden later, so
5712 don't assume we know where a weak sym lives. */
5713 if (h->root.type == bfd_link_hash_defined)
5714 dest = h->root.u.def.section;
5718 Elf_Internal_Sym *isym;
5720 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5725 dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
5729 ppc64_elf_section_data (sec)->has_14bit_branch = 1;
5738 if (h->root.root.string[0] == '.'
5739 && h->root.root.string[1] != '\0')
5740 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5742 if (h == tga || h == dottga)
5744 sec->has_tls_reloc = 1;
5746 && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
5747 || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
5748 /* We have a new-style __tls_get_addr call with
5752 /* Mark this section as having an old-style call. */
5753 sec->has_tls_get_addr_call = 1;
5755 plt_list = &h->plt.plist;
5758 /* We may need a .plt entry if the function this reloc
5759 refers to is in a shared lib. */
5761 && !update_plt_info (abfd, plt_list, rel->r_addend))
5765 case R_PPC64_ADDR14:
5766 case R_PPC64_ADDR14_BRNTAKEN:
5767 case R_PPC64_ADDR14_BRTAKEN:
5768 case R_PPC64_ADDR24:
5771 case R_PPC64_TPREL64:
5772 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
5773 if (bfd_link_dll (info))
5774 info->flags |= DF_STATIC_TLS;
5777 case R_PPC64_DTPMOD64:
5778 if (rel + 1 < rel_end
5779 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
5780 && rel[1].r_offset == rel->r_offset + 8)
5781 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
5783 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
5786 case R_PPC64_DTPREL64:
5787 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
5789 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
5790 && rel[-1].r_offset == rel->r_offset - 8)
5791 /* This is the second reloc of a dtpmod, dtprel pair.
5792 Don't mark with TLS_DTPREL. */
5796 sec->has_tls_reloc = 1;
5799 struct ppc_link_hash_entry *eh;
5800 eh = (struct ppc_link_hash_entry *) h;
5801 eh->tls_mask |= tls_type;
5804 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
5805 rel->r_addend, tls_type))
5808 ppc64_sec = ppc64_elf_section_data (sec);
5809 if (ppc64_sec->sec_type != sec_toc)
5813 /* One extra to simplify get_tls_mask. */
5814 amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned);
5815 ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt);
5816 if (ppc64_sec->u.toc.symndx == NULL)
5818 amt = sec->size * sizeof (bfd_vma) / 8;
5819 ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt);
5820 if (ppc64_sec->u.toc.add == NULL)
5822 BFD_ASSERT (ppc64_sec->sec_type == sec_normal);
5823 ppc64_sec->sec_type = sec_toc;
5825 BFD_ASSERT (rel->r_offset % 8 == 0);
5826 ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx;
5827 ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend;
5829 /* Mark the second slot of a GD or LD entry.
5830 -1 to indicate GD and -2 to indicate LD. */
5831 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
5832 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1;
5833 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
5834 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2;
5837 case R_PPC64_TPREL16:
5838 case R_PPC64_TPREL16_LO:
5839 case R_PPC64_TPREL16_HI:
5840 case R_PPC64_TPREL16_HA:
5841 case R_PPC64_TPREL16_DS:
5842 case R_PPC64_TPREL16_LO_DS:
5843 case R_PPC64_TPREL16_HIGH:
5844 case R_PPC64_TPREL16_HIGHA:
5845 case R_PPC64_TPREL16_HIGHER:
5846 case R_PPC64_TPREL16_HIGHERA:
5847 case R_PPC64_TPREL16_HIGHEST:
5848 case R_PPC64_TPREL16_HIGHESTA:
5849 if (bfd_link_dll (info))
5850 info->flags |= DF_STATIC_TLS;
5853 case R_PPC64_ADDR64:
5855 && rel + 1 < rel_end
5856 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC)
5859 ((struct ppc_link_hash_entry *) h)->is_func = 1;
5863 case R_PPC64_ADDR16:
5864 case R_PPC64_ADDR16_DS:
5865 case R_PPC64_ADDR16_HA:
5866 case R_PPC64_ADDR16_HI:
5867 case R_PPC64_ADDR16_HIGH:
5868 case R_PPC64_ADDR16_HIGHA:
5869 case R_PPC64_ADDR16_HIGHER:
5870 case R_PPC64_ADDR16_HIGHERA:
5871 case R_PPC64_ADDR16_HIGHEST:
5872 case R_PPC64_ADDR16_HIGHESTA:
5873 case R_PPC64_ADDR16_LO:
5874 case R_PPC64_ADDR16_LO_DS:
5875 if (h != NULL && !bfd_link_pic (info) && abiversion (abfd) != 1
5876 && rel->r_addend == 0)
5878 /* We may need a .plt entry if this reloc refers to a
5879 function in a shared lib. */
5880 if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
5882 h->pointer_equality_needed = 1;
5889 case R_PPC64_ADDR32:
5890 case R_PPC64_UADDR16:
5891 case R_PPC64_UADDR32:
5892 case R_PPC64_UADDR64:
5894 if (h != NULL && !bfd_link_pic (info))
5895 /* We may need a copy reloc. */
5898 /* Don't propagate .opd relocs. */
5899 if (NO_OPD_RELOCS && is_opd)
5902 /* If we are creating a shared library, and this is a reloc
5903 against a global symbol, or a non PC relative reloc
5904 against a local symbol, then we need to copy the reloc
5905 into the shared library. However, if we are linking with
5906 -Bsymbolic, we do not need to copy a reloc against a
5907 global symbol which is defined in an object we are
5908 including in the link (i.e., DEF_REGULAR is set). At
5909 this point we have not seen all the input files, so it is
5910 possible that DEF_REGULAR is not set now but will be set
5911 later (it is never cleared). In case of a weak definition,
5912 DEF_REGULAR may be cleared later by a strong definition in
5913 a shared library. We account for that possibility below by
5914 storing information in the dyn_relocs field of the hash
5915 table entry. A similar situation occurs when creating
5916 shared libraries and symbol visibility changes render the
5919 If on the other hand, we are creating an executable, we
5920 may need to keep relocations for symbols satisfied by a
5921 dynamic library if we manage to avoid copy relocs for the
5924 if ((bfd_link_pic (info)
5925 && (must_be_dyn_reloc (info, r_type)
5927 && (!SYMBOLIC_BIND (info, h)
5928 || h->root.type == bfd_link_hash_defweak
5929 || !h->def_regular))))
5930 || (ELIMINATE_COPY_RELOCS
5931 && !bfd_link_pic (info)
5933 && (h->root.type == bfd_link_hash_defweak
5934 || !h->def_regular))
5935 || (!bfd_link_pic (info)
5938 /* We must copy these reloc types into the output file.
5939 Create a reloc section in dynobj and make room for
5943 sreloc = _bfd_elf_make_dynamic_reloc_section
5944 (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
5950 /* If this is a global symbol, we count the number of
5951 relocations we need for this symbol. */
5954 struct elf_dyn_relocs *p;
5955 struct elf_dyn_relocs **head;
5957 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
5959 if (p == NULL || p->sec != sec)
5961 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
5971 if (!must_be_dyn_reloc (info, r_type))
5976 /* Track dynamic relocs needed for local syms too.
5977 We really need local syms available to do this
5979 struct ppc_dyn_relocs *p;
5980 struct ppc_dyn_relocs **head;
5981 bfd_boolean is_ifunc;
5984 Elf_Internal_Sym *isym;
5986 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
5991 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
5995 vpp = &elf_section_data (s)->local_dynrel;
5996 head = (struct ppc_dyn_relocs **) vpp;
5997 is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
5999 if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
6001 if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
6003 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
6009 p->ifunc = is_ifunc;
6025 /* Merge backend specific data from an object file to the output
6026 object file when linking. */
6029 ppc64_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
6031 bfd *obfd = info->output_bfd;
6032 unsigned long iflags, oflags;
6034 if ((ibfd->flags & BFD_LINKER_CREATED) != 0)
6037 if (!is_ppc64_elf (ibfd) || !is_ppc64_elf (obfd))
6040 if (!_bfd_generic_verify_endian_match (ibfd, info))
6043 iflags = elf_elfheader (ibfd)->e_flags;
6044 oflags = elf_elfheader (obfd)->e_flags;
6046 if (iflags & ~EF_PPC64_ABI)
6049 /* xgettext:c-format */
6050 (_("%B uses unknown e_flags 0x%lx"), ibfd, iflags);
6051 bfd_set_error (bfd_error_bad_value);
6054 else if (iflags != oflags && iflags != 0)
6057 /* xgettext:c-format */
6058 (_("%B: ABI version %ld is not compatible with ABI version %ld output"),
6059 ibfd, iflags, oflags);
6060 bfd_set_error (bfd_error_bad_value);
6064 _bfd_elf_ppc_merge_fp_attributes (ibfd, info);
6066 /* Merge Tag_compatibility attributes and any common GNU ones. */
6067 _bfd_elf_merge_object_attributes (ibfd, info);
6073 ppc64_elf_print_private_bfd_data (bfd *abfd, void *ptr)
6075 /* Print normal ELF private data. */
6076 _bfd_elf_print_private_bfd_data (abfd, ptr);
6078 if (elf_elfheader (abfd)->e_flags != 0)
6082 fprintf (file, _("private flags = 0x%lx:"),
6083 elf_elfheader (abfd)->e_flags);
6085 if ((elf_elfheader (abfd)->e_flags & EF_PPC64_ABI) != 0)
6086 fprintf (file, _(" [abiv%ld]"),
6087 elf_elfheader (abfd)->e_flags & EF_PPC64_ABI);
6094 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
6095 of the code entry point, and its section, which must be in the same
6096 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
6099 opd_entry_value (asection *opd_sec,
6101 asection **code_sec,
6103 bfd_boolean in_code_sec)
6105 bfd *opd_bfd = opd_sec->owner;
6106 Elf_Internal_Rela *relocs;
6107 Elf_Internal_Rela *lo, *hi, *look;
6110 /* No relocs implies we are linking a --just-symbols object, or looking
6111 at a final linked executable with addr2line or somesuch. */
6112 if (opd_sec->reloc_count == 0)
6114 bfd_byte *contents = ppc64_elf_tdata (opd_bfd)->opd.contents;
6116 if (contents == NULL)
6118 if (!bfd_malloc_and_get_section (opd_bfd, opd_sec, &contents))
6119 return (bfd_vma) -1;
6120 ppc64_elf_tdata (opd_bfd)->opd.contents = contents;
6123 /* PR 17512: file: 64b9dfbb. */
6124 if (offset + 7 >= opd_sec->size || offset + 7 < offset)
6125 return (bfd_vma) -1;
6127 val = bfd_get_64 (opd_bfd, contents + offset);
6128 if (code_sec != NULL)
6130 asection *sec, *likely = NULL;
6136 && val < sec->vma + sec->size)
6142 for (sec = opd_bfd->sections; sec != NULL; sec = sec->next)
6144 && (sec->flags & SEC_LOAD) != 0
6145 && (sec->flags & SEC_ALLOC) != 0)
6150 if (code_off != NULL)
6151 *code_off = val - likely->vma;
6157 BFD_ASSERT (is_ppc64_elf (opd_bfd));
6159 relocs = ppc64_elf_tdata (opd_bfd)->opd.relocs;
6161 relocs = _bfd_elf_link_read_relocs (opd_bfd, opd_sec, NULL, NULL, TRUE);
6162 /* PR 17512: file: df8e1fd6. */
6164 return (bfd_vma) -1;
6166 /* Go find the opd reloc at the sym address. */
6168 hi = lo + opd_sec->reloc_count - 1; /* ignore last reloc */
6172 look = lo + (hi - lo) / 2;
6173 if (look->r_offset < offset)
6175 else if (look->r_offset > offset)
6179 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (opd_bfd);
6181 if (ELF64_R_TYPE (look->r_info) == R_PPC64_ADDR64
6182 && ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
6184 unsigned long symndx = ELF64_R_SYM (look->r_info);
6185 asection *sec = NULL;
6187 if (symndx >= symtab_hdr->sh_info
6188 && elf_sym_hashes (opd_bfd) != NULL)
6190 struct elf_link_hash_entry **sym_hashes;
6191 struct elf_link_hash_entry *rh;
6193 sym_hashes = elf_sym_hashes (opd_bfd);
6194 rh = sym_hashes[symndx - symtab_hdr->sh_info];
6197 rh = elf_follow_link (rh);
6198 if (rh->root.type != bfd_link_hash_defined
6199 && rh->root.type != bfd_link_hash_defweak)
6201 if (rh->root.u.def.section->owner == opd_bfd)
6203 val = rh->root.u.def.value;
6204 sec = rh->root.u.def.section;
6211 Elf_Internal_Sym *sym;
6213 if (symndx < symtab_hdr->sh_info)
6215 sym = (Elf_Internal_Sym *) symtab_hdr->contents;
6218 size_t symcnt = symtab_hdr->sh_info;
6219 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
6224 symtab_hdr->contents = (bfd_byte *) sym;
6230 sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
6236 sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
6239 BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
6240 val = sym->st_value;
6243 val += look->r_addend;
6244 if (code_off != NULL)
6246 if (code_sec != NULL)
6248 if (in_code_sec && *code_sec != sec)
6253 if (sec->output_section != NULL)
6254 val += sec->output_section->vma + sec->output_offset;
6263 /* If the ELF symbol SYM might be a function in SEC, return the
6264 function size and set *CODE_OFF to the function's entry point,
6265 otherwise return zero. */
6267 static bfd_size_type
6268 ppc64_elf_maybe_function_sym (const asymbol *sym, asection *sec,
6273 if ((sym->flags & (BSF_SECTION_SYM | BSF_FILE | BSF_OBJECT
6274 | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC)) != 0)
6278 if (!(sym->flags & BSF_SYNTHETIC))
6279 size = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
6281 if (strcmp (sym->section->name, ".opd") == 0)
6283 struct _opd_sec_data *opd = get_opd_info (sym->section);
6284 bfd_vma symval = sym->value;
6287 && opd->adjust != NULL
6288 && elf_section_data (sym->section)->relocs != NULL)
6290 /* opd_entry_value will use cached relocs that have been
6291 adjusted, but with raw symbols. That means both local
6292 and global symbols need adjusting. */
6293 long adjust = opd->adjust[OPD_NDX (symval)];
6299 if (opd_entry_value (sym->section, symval,
6300 &sec, code_off, TRUE) == (bfd_vma) -1)
6302 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6303 symbol. This size has nothing to do with the code size of the
6304 function, which is what we're supposed to return, but the
6305 code size isn't available without looking up the dot-sym.
6306 However, doing that would be a waste of time particularly
6307 since elf_find_function will look at the dot-sym anyway.
6308 Now, elf_find_function will keep the largest size of any
6309 function sym found at the code address of interest, so return
6310 1 here to avoid it incorrectly caching a larger function size
6311 for a small function. This does mean we return the wrong
6312 size for a new-ABI function of size 24, but all that does is
6313 disable caching for such functions. */
6319 if (sym->section != sec)
6321 *code_off = sym->value;
6328 /* Return true if symbol is a strong function defined in an ELFv2
6329 object with st_other localentry bits of zero, ie. its local entry
6330 point coincides with its global entry point. */
6333 is_elfv2_localentry0 (struct elf_link_hash_entry *h)
6336 && h->type == STT_FUNC
6337 && h->root.type == bfd_link_hash_defined
6338 && (STO_PPC64_LOCAL_MASK & h->other) == 0
6339 && !((struct ppc_link_hash_entry *) h)->non_zero_localentry
6340 && is_ppc64_elf (h->root.u.def.section->owner)
6341 && abiversion (h->root.u.def.section->owner) >= 2);
6344 /* Return true if symbol is defined in a regular object file. */
6347 is_static_defined (struct elf_link_hash_entry *h)
6349 return ((h->root.type == bfd_link_hash_defined
6350 || h->root.type == bfd_link_hash_defweak)
6351 && h->root.u.def.section != NULL
6352 && h->root.u.def.section->output_section != NULL);
6355 /* If FDH is a function descriptor symbol, return the associated code
6356 entry symbol if it is defined. Return NULL otherwise. */
6358 static struct ppc_link_hash_entry *
6359 defined_code_entry (struct ppc_link_hash_entry *fdh)
6361 if (fdh->is_func_descriptor)
6363 struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh);
6364 if (fh->elf.root.type == bfd_link_hash_defined
6365 || fh->elf.root.type == bfd_link_hash_defweak)
6371 /* If FH is a function code entry symbol, return the associated
6372 function descriptor symbol if it is defined. Return NULL otherwise. */
6374 static struct ppc_link_hash_entry *
6375 defined_func_desc (struct ppc_link_hash_entry *fh)
6378 && fh->oh->is_func_descriptor)
6380 struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh);
6381 if (fdh->elf.root.type == bfd_link_hash_defined
6382 || fdh->elf.root.type == bfd_link_hash_defweak)
6388 static bfd_boolean func_desc_adjust (struct elf_link_hash_entry *, void *);
6390 /* Garbage collect sections, after first dealing with dot-symbols. */
6393 ppc64_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
6395 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6397 if (htab != NULL && htab->need_func_desc_adj)
6399 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
6400 htab->need_func_desc_adj = 0;
6402 return bfd_elf_gc_sections (abfd, info);
6405 /* Mark all our entry sym sections, both opd and code section. */
6408 ppc64_elf_gc_keep (struct bfd_link_info *info)
6410 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6411 struct bfd_sym_chain *sym;
6416 for (sym = info->gc_sym_list; sym != NULL; sym = sym->next)
6418 struct ppc_link_hash_entry *eh, *fh;
6421 eh = (struct ppc_link_hash_entry *)
6422 elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
6425 if (eh->elf.root.type != bfd_link_hash_defined
6426 && eh->elf.root.type != bfd_link_hash_defweak)
6429 fh = defined_code_entry (eh);
6432 sec = fh->elf.root.u.def.section;
6433 sec->flags |= SEC_KEEP;
6435 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6436 && opd_entry_value (eh->elf.root.u.def.section,
6437 eh->elf.root.u.def.value,
6438 &sec, NULL, FALSE) != (bfd_vma) -1)
6439 sec->flags |= SEC_KEEP;
6441 sec = eh->elf.root.u.def.section;
6442 sec->flags |= SEC_KEEP;
6446 /* Mark sections containing dynamically referenced symbols. When
6447 building shared libraries, we must assume that any visible symbol is
6451 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry *h, void *inf)
6453 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6454 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
6455 struct ppc_link_hash_entry *fdh;
6456 struct bfd_elf_dynamic_list *d = info->dynamic_list;
6458 /* Dynamic linking info is on the func descriptor sym. */
6459 fdh = defined_func_desc (eh);
6463 if ((eh->elf.root.type == bfd_link_hash_defined
6464 || eh->elf.root.type == bfd_link_hash_defweak)
6465 && ((eh->elf.ref_dynamic && !eh->elf.forced_local)
6466 || ((eh->elf.def_regular || ELF_COMMON_DEF_P (&eh->elf))
6467 && ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
6468 && ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN
6469 && (!bfd_link_executable (info)
6470 || info->gc_keep_exported
6471 || info->export_dynamic
6474 && (*d->match) (&d->head, NULL, eh->elf.root.root.string)))
6475 && (eh->elf.versioned >= versioned
6476 || !bfd_hide_sym_by_version (info->version_info,
6477 eh->elf.root.root.string)))))
6480 struct ppc_link_hash_entry *fh;
6482 eh->elf.root.u.def.section->flags |= SEC_KEEP;
6484 /* Function descriptor syms cause the associated
6485 function code sym section to be marked. */
6486 fh = defined_code_entry (eh);
6489 code_sec = fh->elf.root.u.def.section;
6490 code_sec->flags |= SEC_KEEP;
6492 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6493 && opd_entry_value (eh->elf.root.u.def.section,
6494 eh->elf.root.u.def.value,
6495 &code_sec, NULL, FALSE) != (bfd_vma) -1)
6496 code_sec->flags |= SEC_KEEP;
6502 /* Return the section that should be marked against GC for a given
6506 ppc64_elf_gc_mark_hook (asection *sec,
6507 struct bfd_link_info *info,
6508 Elf_Internal_Rela *rel,
6509 struct elf_link_hash_entry *h,
6510 Elf_Internal_Sym *sym)
6514 /* Syms return NULL if we're marking .opd, so we avoid marking all
6515 function sections, as all functions are referenced in .opd. */
6517 if (get_opd_info (sec) != NULL)
6522 enum elf_ppc64_reloc_type r_type;
6523 struct ppc_link_hash_entry *eh, *fh, *fdh;
6525 r_type = ELF64_R_TYPE (rel->r_info);
6528 case R_PPC64_GNU_VTINHERIT:
6529 case R_PPC64_GNU_VTENTRY:
6533 switch (h->root.type)
6535 case bfd_link_hash_defined:
6536 case bfd_link_hash_defweak:
6537 eh = (struct ppc_link_hash_entry *) h;
6538 fdh = defined_func_desc (eh);
6541 /* -mcall-aixdesc code references the dot-symbol on
6542 a call reloc. Mark the function descriptor too
6543 against garbage collection. */
6545 if (fdh->elf.is_weakalias)
6546 weakdef (&fdh->elf)->mark = 1;
6550 /* Function descriptor syms cause the associated
6551 function code sym section to be marked. */
6552 fh = defined_code_entry (eh);
6555 /* They also mark their opd section. */
6556 eh->elf.root.u.def.section->gc_mark = 1;
6558 rsec = fh->elf.root.u.def.section;
6560 else if (get_opd_info (eh->elf.root.u.def.section) != NULL
6561 && opd_entry_value (eh->elf.root.u.def.section,
6562 eh->elf.root.u.def.value,
6563 &rsec, NULL, FALSE) != (bfd_vma) -1)
6564 eh->elf.root.u.def.section->gc_mark = 1;
6566 rsec = h->root.u.def.section;
6569 case bfd_link_hash_common:
6570 rsec = h->root.u.c.p->section;
6574 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
6580 struct _opd_sec_data *opd;
6582 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
6583 opd = get_opd_info (rsec);
6584 if (opd != NULL && opd->func_sec != NULL)
6588 rsec = opd->func_sec[OPD_NDX (sym->st_value + rel->r_addend)];
6595 /* The maximum size of .sfpr. */
6596 #define SFPR_MAX (218*4)
6598 struct sfpr_def_parms
6600 const char name[12];
6601 unsigned char lo, hi;
6602 bfd_byte * (*write_ent) (bfd *, bfd_byte *, int);
6603 bfd_byte * (*write_tail) (bfd *, bfd_byte *, int);
6606 /* Auto-generate _save*, _rest* functions in .sfpr.
6607 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6611 sfpr_define (struct bfd_link_info *info,
6612 const struct sfpr_def_parms *parm,
6615 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6617 size_t len = strlen (parm->name);
6618 bfd_boolean writing = FALSE;
6624 memcpy (sym, parm->name, len);
6627 for (i = parm->lo; i <= parm->hi; i++)
6629 struct ppc_link_hash_entry *h;
6631 sym[len + 0] = i / 10 + '0';
6632 sym[len + 1] = i % 10 + '0';
6633 h = (struct ppc_link_hash_entry *)
6634 elf_link_hash_lookup (&htab->elf, sym, writing, TRUE, TRUE);
6635 if (stub_sec != NULL)
6638 && h->elf.root.type == bfd_link_hash_defined
6639 && h->elf.root.u.def.section == htab->sfpr)
6641 struct elf_link_hash_entry *s;
6643 sprintf (buf, "%08x.%s", stub_sec->id & 0xffffffff, sym);
6644 s = elf_link_hash_lookup (&htab->elf, buf, TRUE, TRUE, FALSE);
6647 if (s->root.type == bfd_link_hash_new
6648 || (s->root.type = bfd_link_hash_defined
6649 && s->root.u.def.section == stub_sec))
6651 s->root.type = bfd_link_hash_defined;
6652 s->root.u.def.section = stub_sec;
6653 s->root.u.def.value = (stub_sec->size
6654 + h->elf.root.u.def.value);
6657 s->ref_regular_nonweak = 1;
6658 s->forced_local = 1;
6660 s->root.linker_def = 1;
6668 if (!h->elf.def_regular)
6670 h->elf.root.type = bfd_link_hash_defined;
6671 h->elf.root.u.def.section = htab->sfpr;
6672 h->elf.root.u.def.value = htab->sfpr->size;
6673 h->elf.type = STT_FUNC;
6674 h->elf.def_regular = 1;
6676 _bfd_elf_link_hash_hide_symbol (info, &h->elf, TRUE);
6678 if (htab->sfpr->contents == NULL)
6680 htab->sfpr->contents = bfd_alloc (htab->elf.dynobj, SFPR_MAX);
6681 if (htab->sfpr->contents == NULL)
6688 bfd_byte *p = htab->sfpr->contents + htab->sfpr->size;
6690 p = (*parm->write_ent) (htab->elf.dynobj, p, i);
6692 p = (*parm->write_tail) (htab->elf.dynobj, p, i);
6693 htab->sfpr->size = p - htab->sfpr->contents;
6701 savegpr0 (bfd *abfd, bfd_byte *p, int r)
6703 bfd_put_32 (abfd, STD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6708 savegpr0_tail (bfd *abfd, bfd_byte *p, int r)
6710 p = savegpr0 (abfd, p, r);
6711 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6713 bfd_put_32 (abfd, BLR, p);
6718 restgpr0 (bfd *abfd, bfd_byte *p, int r)
6720 bfd_put_32 (abfd, LD_R0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6725 restgpr0_tail (bfd *abfd, bfd_byte *p, int r)
6727 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6729 p = restgpr0 (abfd, p, r);
6730 bfd_put_32 (abfd, MTLR_R0, p);
6734 p = restgpr0 (abfd, p, 30);
6735 p = restgpr0 (abfd, p, 31);
6737 bfd_put_32 (abfd, BLR, p);
6742 savegpr1 (bfd *abfd, bfd_byte *p, int r)
6744 bfd_put_32 (abfd, STD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6749 savegpr1_tail (bfd *abfd, bfd_byte *p, int r)
6751 p = savegpr1 (abfd, p, r);
6752 bfd_put_32 (abfd, BLR, p);
6757 restgpr1 (bfd *abfd, bfd_byte *p, int r)
6759 bfd_put_32 (abfd, LD_R0_0R12 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6764 restgpr1_tail (bfd *abfd, bfd_byte *p, int r)
6766 p = restgpr1 (abfd, p, r);
6767 bfd_put_32 (abfd, BLR, p);
6772 savefpr (bfd *abfd, bfd_byte *p, int r)
6774 bfd_put_32 (abfd, STFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6779 savefpr0_tail (bfd *abfd, bfd_byte *p, int r)
6781 p = savefpr (abfd, p, r);
6782 bfd_put_32 (abfd, STD_R0_0R1 + STK_LR, p);
6784 bfd_put_32 (abfd, BLR, p);
6789 restfpr (bfd *abfd, bfd_byte *p, int r)
6791 bfd_put_32 (abfd, LFD_FR0_0R1 + (r << 21) + (1 << 16) - (32 - r) * 8, p);
6796 restfpr0_tail (bfd *abfd, bfd_byte *p, int r)
6798 bfd_put_32 (abfd, LD_R0_0R1 + STK_LR, p);
6800 p = restfpr (abfd, p, r);
6801 bfd_put_32 (abfd, MTLR_R0, p);
6805 p = restfpr (abfd, p, 30);
6806 p = restfpr (abfd, p, 31);
6808 bfd_put_32 (abfd, BLR, p);
6813 savefpr1_tail (bfd *abfd, bfd_byte *p, int r)
6815 p = savefpr (abfd, p, r);
6816 bfd_put_32 (abfd, BLR, p);
6821 restfpr1_tail (bfd *abfd, bfd_byte *p, int r)
6823 p = restfpr (abfd, p, r);
6824 bfd_put_32 (abfd, BLR, p);
6829 savevr (bfd *abfd, bfd_byte *p, int r)
6831 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6833 bfd_put_32 (abfd, STVX_VR0_R12_R0 + (r << 21), p);
6838 savevr_tail (bfd *abfd, bfd_byte *p, int r)
6840 p = savevr (abfd, p, r);
6841 bfd_put_32 (abfd, BLR, p);
6846 restvr (bfd *abfd, bfd_byte *p, int r)
6848 bfd_put_32 (abfd, LI_R12_0 + (1 << 16) - (32 - r) * 16, p);
6850 bfd_put_32 (abfd, LVX_VR0_R12_R0 + (r << 21), p);
6855 restvr_tail (bfd *abfd, bfd_byte *p, int r)
6857 p = restvr (abfd, p, r);
6858 bfd_put_32 (abfd, BLR, p);
6862 /* Called via elf_link_hash_traverse to transfer dynamic linking
6863 information on function code symbol entries to their corresponding
6864 function descriptor symbol entries. */
6867 func_desc_adjust (struct elf_link_hash_entry *h, void *inf)
6869 struct bfd_link_info *info;
6870 struct ppc_link_hash_table *htab;
6871 struct ppc_link_hash_entry *fh;
6872 struct ppc_link_hash_entry *fdh;
6873 bfd_boolean force_local;
6875 fh = (struct ppc_link_hash_entry *) h;
6876 if (fh->elf.root.type == bfd_link_hash_indirect)
6882 if (fh->elf.root.root.string[0] != '.'
6883 || fh->elf.root.root.string[1] == '\0')
6887 htab = ppc_hash_table (info);
6891 /* Find the corresponding function descriptor symbol. */
6892 fdh = lookup_fdh (fh, htab);
6894 /* Resolve undefined references to dot-symbols as the value
6895 in the function descriptor, if we have one in a regular object.
6896 This is to satisfy cases like ".quad .foo". Calls to functions
6897 in dynamic objects are handled elsewhere. */
6898 if ((fh->elf.root.type == bfd_link_hash_undefined
6899 || fh->elf.root.type == bfd_link_hash_undefweak)
6900 && (fdh->elf.root.type == bfd_link_hash_defined
6901 || fdh->elf.root.type == bfd_link_hash_defweak)
6902 && get_opd_info (fdh->elf.root.u.def.section) != NULL
6903 && opd_entry_value (fdh->elf.root.u.def.section,
6904 fdh->elf.root.u.def.value,
6905 &fh->elf.root.u.def.section,
6906 &fh->elf.root.u.def.value, FALSE) != (bfd_vma) -1)
6908 fh->elf.root.type = fdh->elf.root.type;
6909 fh->elf.forced_local = 1;
6910 fh->elf.def_regular = fdh->elf.def_regular;
6911 fh->elf.def_dynamic = fdh->elf.def_dynamic;
6914 if (!fh->elf.dynamic)
6916 struct plt_entry *ent;
6918 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next)
6919 if (ent->plt.refcount > 0)
6925 /* Create a descriptor as undefined if necessary. */
6927 && !bfd_link_executable (info)
6928 && (fh->elf.root.type == bfd_link_hash_undefined
6929 || fh->elf.root.type == bfd_link_hash_undefweak))
6931 fdh = make_fdh (info, fh);
6936 /* We can't support overriding of symbols on a fake descriptor. */
6939 && (fh->elf.root.type == bfd_link_hash_defined
6940 || fh->elf.root.type == bfd_link_hash_defweak))
6941 _bfd_elf_link_hash_hide_symbol (info, &fdh->elf, TRUE);
6943 /* Transfer dynamic linking information to the function descriptor. */
6946 fdh->elf.ref_regular |= fh->elf.ref_regular;
6947 fdh->elf.ref_dynamic |= fh->elf.ref_dynamic;
6948 fdh->elf.ref_regular_nonweak |= fh->elf.ref_regular_nonweak;
6949 fdh->elf.non_got_ref |= fh->elf.non_got_ref;
6950 fdh->elf.dynamic |= fh->elf.dynamic;
6951 fdh->elf.needs_plt |= (fh->elf.needs_plt
6952 || fh->elf.type == STT_FUNC
6953 || fh->elf.type == STT_GNU_IFUNC);
6954 move_plt_plist (fh, fdh);
6956 if (!fdh->elf.forced_local
6957 && fh->elf.dynindx != -1)
6958 if (!bfd_elf_link_record_dynamic_symbol (info, &fdh->elf))
6962 /* Now that the info is on the function descriptor, clear the
6963 function code sym info. Any function code syms for which we
6964 don't have a definition in a regular file, we force local.
6965 This prevents a shared library from exporting syms that have
6966 been imported from another library. Function code syms that
6967 are really in the library we must leave global to prevent the
6968 linker dragging in a definition from a static library. */
6969 force_local = (!fh->elf.def_regular
6971 || !fdh->elf.def_regular
6972 || fdh->elf.forced_local);
6973 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
6978 static const struct sfpr_def_parms save_res_funcs[] =
6980 { "_savegpr0_", 14, 31, savegpr0, savegpr0_tail },
6981 { "_restgpr0_", 14, 29, restgpr0, restgpr0_tail },
6982 { "_restgpr0_", 30, 31, restgpr0, restgpr0_tail },
6983 { "_savegpr1_", 14, 31, savegpr1, savegpr1_tail },
6984 { "_restgpr1_", 14, 31, restgpr1, restgpr1_tail },
6985 { "_savefpr_", 14, 31, savefpr, savefpr0_tail },
6986 { "_restfpr_", 14, 29, restfpr, restfpr0_tail },
6987 { "_restfpr_", 30, 31, restfpr, restfpr0_tail },
6988 { "._savef", 14, 31, savefpr, savefpr1_tail },
6989 { "._restf", 14, 31, restfpr, restfpr1_tail },
6990 { "_savevr_", 20, 31, savevr, savevr_tail },
6991 { "_restvr_", 20, 31, restvr, restvr_tail }
6994 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6995 this hook to a) provide some gcc support functions, and b) transfer
6996 dynamic linking information gathered so far on function code symbol
6997 entries, to their corresponding function descriptor symbol entries. */
7000 ppc64_elf_func_desc_adjust (bfd *obfd ATTRIBUTE_UNUSED,
7001 struct bfd_link_info *info)
7003 struct ppc_link_hash_table *htab;
7005 htab = ppc_hash_table (info);
7009 /* Provide any missing _save* and _rest* functions. */
7010 if (htab->sfpr != NULL)
7014 htab->sfpr->size = 0;
7015 for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
7016 if (!sfpr_define (info, &save_res_funcs[i], NULL))
7018 if (htab->sfpr->size == 0)
7019 htab->sfpr->flags |= SEC_EXCLUDE;
7022 if (bfd_link_relocatable (info))
7025 if (htab->elf.hgot != NULL)
7027 _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
7028 /* Make .TOC. defined so as to prevent it being made dynamic.
7029 The wrong value here is fixed later in ppc64_elf_set_toc. */
7030 if (!htab->elf.hgot->def_regular
7031 || htab->elf.hgot->root.type != bfd_link_hash_defined)
7033 htab->elf.hgot->root.type = bfd_link_hash_defined;
7034 htab->elf.hgot->root.u.def.value = 0;
7035 htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
7036 htab->elf.hgot->def_regular = 1;
7037 htab->elf.hgot->root.linker_def = 1;
7039 htab->elf.hgot->type = STT_OBJECT;
7040 htab->elf.hgot->other = ((htab->elf.hgot->other & ~ELF_ST_VISIBILITY (-1))
7044 if (htab->need_func_desc_adj)
7046 elf_link_hash_traverse (&htab->elf, func_desc_adjust, info);
7047 htab->need_func_desc_adj = 0;
7053 /* Find dynamic relocs for H that apply to read-only sections. */
7056 readonly_dynrelocs (struct elf_link_hash_entry *h)
7058 struct ppc_link_hash_entry *eh;
7059 struct elf_dyn_relocs *p;
7061 eh = (struct ppc_link_hash_entry *) h;
7062 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7064 asection *s = p->sec->output_section;
7066 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7072 /* Return true if we have dynamic relocs against H or any of its weak
7073 aliases, that apply to read-only sections. Cannot be used after
7074 size_dynamic_sections. */
7077 alias_readonly_dynrelocs (struct elf_link_hash_entry *h)
7079 struct ppc_link_hash_entry *eh;
7081 eh = (struct ppc_link_hash_entry *) h;
7084 if (readonly_dynrelocs (&eh->elf))
7086 eh = (struct ppc_link_hash_entry *) eh->elf.u.alias;
7087 } while (eh != NULL && &eh->elf != h);
7092 /* Return whether EH has pc-relative dynamic relocs. */
7095 pc_dynrelocs (struct ppc_link_hash_entry *eh)
7097 struct elf_dyn_relocs *p;
7099 for (p = eh->dyn_relocs; p != NULL; p = p->next)
7100 if (p->pc_count != 0)
7105 /* Return true if a global entry stub will be created for H. Valid
7106 for ELFv2 before plt entries have been allocated. */
7109 global_entry_stub (struct elf_link_hash_entry *h)
7111 struct plt_entry *pent;
7113 if (!h->pointer_equality_needed
7117 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
7118 if (pent->plt.refcount > 0
7119 && pent->addend == 0)
7125 /* Adjust a symbol defined by a dynamic object and referenced by a
7126 regular object. The current definition is in some section of the
7127 dynamic object, but we're not including those sections. We have to
7128 change the definition to something the rest of the link can
7132 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
7133 struct elf_link_hash_entry *h)
7135 struct ppc_link_hash_table *htab;
7138 htab = ppc_hash_table (info);
7142 /* Deal with function syms. */
7143 if (h->type == STT_FUNC
7144 || h->type == STT_GNU_IFUNC
7147 bfd_boolean local = (((struct ppc_link_hash_entry *) h)->save_res
7148 || SYMBOL_CALLS_LOCAL (info, h)
7149 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
7150 /* Discard dyn_relocs when non-pic if we've decided that a
7151 function symbol is local and not an ifunc. We keep dynamic
7152 relocs for ifuncs when local rather than always emitting a
7153 plt call stub for them and defining the symbol on the call
7154 stub. We can't do that for ELFv1 anyway (a function symbol
7155 is defined on a descriptor, not code) and it can be faster at
7156 run-time due to not needing to bounce through a stub. The
7157 dyn_relocs for ifuncs will be applied even in a static
7159 if (!bfd_link_pic (info)
7160 && h->type != STT_GNU_IFUNC
7162 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7164 /* Clear procedure linkage table information for any symbol that
7165 won't need a .plt entry. */
7166 struct plt_entry *ent;
7167 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
7168 if (ent->plt.refcount > 0)
7171 || (h->type != STT_GNU_IFUNC && local))
7173 h->plt.plist = NULL;
7175 h->pointer_equality_needed = 0;
7177 else if (abiversion (info->output_bfd) >= 2)
7179 /* Taking a function's address in a read/write section
7180 doesn't require us to define the function symbol in the
7181 executable on a global entry stub. A dynamic reloc can
7182 be used instead. The reason we prefer a few more dynamic
7183 relocs is that calling via a global entry stub costs a
7184 few more instructions, and pointer_equality_needed causes
7185 extra work in ld.so when resolving these symbols. */
7186 if (global_entry_stub (h))
7188 if (!readonly_dynrelocs (h))
7190 h->pointer_equality_needed = 0;
7191 /* If we haven't seen a branch reloc then we don't need
7194 h->plt.plist = NULL;
7196 else if (!bfd_link_pic (info))
7197 /* We are going to be defining the function symbol on the
7198 plt stub, so no dyn_relocs needed when non-pic. */
7199 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7202 /* ELFv2 function symbols can't have copy relocs. */
7205 else if (!h->needs_plt
7206 && !readonly_dynrelocs (h))
7208 /* If we haven't seen a branch reloc then we don't need a
7210 h->plt.plist = NULL;
7211 h->pointer_equality_needed = 0;
7216 h->plt.plist = NULL;
7218 /* If this is a weak symbol, and there is a real definition, the
7219 processor independent code will have arranged for us to see the
7220 real definition first, and we can just use the same value. */
7221 if (h->is_weakalias)
7223 struct elf_link_hash_entry *def = weakdef (h);
7224 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
7225 h->root.u.def.section = def->root.u.def.section;
7226 h->root.u.def.value = def->root.u.def.value;
7227 if (def->root.u.def.section == htab->elf.sdynbss
7228 || def->root.u.def.section == htab->elf.sdynrelro)
7229 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7233 /* If we are creating a shared library, we must presume that the
7234 only references to the symbol are via the global offset table.
7235 For such cases we need not do anything here; the relocations will
7236 be handled correctly by relocate_section. */
7237 if (bfd_link_pic (info))
7240 /* If there are no references to this symbol that do not use the
7241 GOT, we don't need to generate a copy reloc. */
7242 if (!h->non_got_ref)
7245 /* Don't generate a copy reloc for symbols defined in the executable. */
7246 if (!h->def_dynamic || !h->ref_regular || h->def_regular
7248 /* If -z nocopyreloc was given, don't generate them either. */
7249 || info->nocopyreloc
7251 /* If we don't find any dynamic relocs in read-only sections, then
7252 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7253 || (ELIMINATE_COPY_RELOCS && !alias_readonly_dynrelocs (h))
7255 /* Protected variables do not work with .dynbss. The copy in
7256 .dynbss won't be used by the shared library with the protected
7257 definition for the variable. Text relocations are preferable
7258 to an incorrect program. */
7259 || h->protected_def)
7262 if (h->plt.plist != NULL)
7264 /* We should never get here, but unfortunately there are versions
7265 of gcc out there that improperly (for this ABI) put initialized
7266 function pointers, vtable refs and suchlike in read-only
7267 sections. Allow them to proceed, but warn that this might
7268 break at runtime. */
7269 info->callbacks->einfo
7270 (_("%P: copy reloc against `%T' requires lazy plt linking; "
7271 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7272 h->root.root.string);
7275 /* This is a reference to a symbol defined by a dynamic object which
7276 is not a function. */
7278 /* We must allocate the symbol in our .dynbss section, which will
7279 become part of the .bss section of the executable. There will be
7280 an entry for this symbol in the .dynsym section. The dynamic
7281 object will contain position independent code, so all references
7282 from the dynamic object to this symbol will go through the global
7283 offset table. The dynamic linker will use the .dynsym entry to
7284 determine the address it must put in the global offset table, so
7285 both the dynamic object and the regular object will refer to the
7286 same memory location for the variable. */
7287 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
7289 s = htab->elf.sdynrelro;
7290 srel = htab->elf.sreldynrelro;
7294 s = htab->elf.sdynbss;
7295 srel = htab->elf.srelbss;
7297 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
7299 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
7300 linker to copy the initial value out of the dynamic object
7301 and into the runtime process image. */
7302 srel->size += sizeof (Elf64_External_Rela);
7306 /* We no longer want dyn_relocs. */
7307 ((struct ppc_link_hash_entry *) h)->dyn_relocs = NULL;
7308 return _bfd_elf_adjust_dynamic_copy (info, h, s);
7311 /* If given a function descriptor symbol, hide both the function code
7312 sym and the descriptor. */
7314 ppc64_elf_hide_symbol (struct bfd_link_info *info,
7315 struct elf_link_hash_entry *h,
7316 bfd_boolean force_local)
7318 struct ppc_link_hash_entry *eh;
7319 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
7321 eh = (struct ppc_link_hash_entry *) h;
7322 if (eh->is_func_descriptor)
7324 struct ppc_link_hash_entry *fh = eh->oh;
7329 struct elf_link_hash_table *htab = elf_hash_table (info);
7332 /* We aren't supposed to use alloca in BFD because on
7333 systems which do not have alloca the version in libiberty
7334 calls xmalloc, which might cause the program to crash
7335 when it runs out of memory. This function doesn't have a
7336 return status, so there's no way to gracefully return an
7337 error. So cheat. We know that string[-1] can be safely
7338 accessed; It's either a string in an ELF string table,
7339 or allocated in an objalloc structure. */
7341 p = eh->elf.root.root.string - 1;
7344 fh = (struct ppc_link_hash_entry *)
7345 elf_link_hash_lookup (htab, p, FALSE, FALSE, FALSE);
7348 /* Unfortunately, if it so happens that the string we were
7349 looking for was allocated immediately before this string,
7350 then we overwrote the string terminator. That's the only
7351 reason the lookup should fail. */
7354 q = eh->elf.root.root.string + strlen (eh->elf.root.root.string);
7355 while (q >= eh->elf.root.root.string && *q == *p)
7357 if (q < eh->elf.root.root.string && *p == '.')
7358 fh = (struct ppc_link_hash_entry *)
7359 elf_link_hash_lookup (htab, p, FALSE, FALSE, FALSE);
7368 _bfd_elf_link_hash_hide_symbol (info, &fh->elf, force_local);
7373 get_sym_h (struct elf_link_hash_entry **hp,
7374 Elf_Internal_Sym **symp,
7376 unsigned char **tls_maskp,
7377 Elf_Internal_Sym **locsymsp,
7378 unsigned long r_symndx,
7381 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
7383 if (r_symndx >= symtab_hdr->sh_info)
7385 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
7386 struct elf_link_hash_entry *h;
7388 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7389 h = elf_follow_link (h);
7397 if (symsecp != NULL)
7399 asection *symsec = NULL;
7400 if (h->root.type == bfd_link_hash_defined
7401 || h->root.type == bfd_link_hash_defweak)
7402 symsec = h->root.u.def.section;
7406 if (tls_maskp != NULL)
7408 struct ppc_link_hash_entry *eh;
7410 eh = (struct ppc_link_hash_entry *) h;
7411 *tls_maskp = &eh->tls_mask;
7416 Elf_Internal_Sym *sym;
7417 Elf_Internal_Sym *locsyms = *locsymsp;
7419 if (locsyms == NULL)
7421 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
7422 if (locsyms == NULL)
7423 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
7424 symtab_hdr->sh_info,
7425 0, NULL, NULL, NULL);
7426 if (locsyms == NULL)
7428 *locsymsp = locsyms;
7430 sym = locsyms + r_symndx;
7438 if (symsecp != NULL)
7439 *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx);
7441 if (tls_maskp != NULL)
7443 struct got_entry **lgot_ents;
7444 unsigned char *tls_mask;
7447 lgot_ents = elf_local_got_ents (ibfd);
7448 if (lgot_ents != NULL)
7450 struct plt_entry **local_plt = (struct plt_entry **)
7451 (lgot_ents + symtab_hdr->sh_info);
7452 unsigned char *lgot_masks = (unsigned char *)
7453 (local_plt + symtab_hdr->sh_info);
7454 tls_mask = &lgot_masks[r_symndx];
7456 *tls_maskp = tls_mask;
7462 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7463 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7464 type suitable for optimization, and 1 otherwise. */
7467 get_tls_mask (unsigned char **tls_maskp,
7468 unsigned long *toc_symndx,
7469 bfd_vma *toc_addend,
7470 Elf_Internal_Sym **locsymsp,
7471 const Elf_Internal_Rela *rel,
7474 unsigned long r_symndx;
7476 struct elf_link_hash_entry *h;
7477 Elf_Internal_Sym *sym;
7481 r_symndx = ELF64_R_SYM (rel->r_info);
7482 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7485 if ((*tls_maskp != NULL && **tls_maskp != 0)
7487 || ppc64_elf_section_data (sec) == NULL
7488 || ppc64_elf_section_data (sec)->sec_type != sec_toc)
7491 /* Look inside a TOC section too. */
7494 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
7495 off = h->root.u.def.value;
7498 off = sym->st_value;
7499 off += rel->r_addend;
7500 BFD_ASSERT (off % 8 == 0);
7501 r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8];
7502 next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1];
7503 if (toc_symndx != NULL)
7504 *toc_symndx = r_symndx;
7505 if (toc_addend != NULL)
7506 *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8];
7507 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
7509 if ((h == NULL || is_static_defined (h))
7510 && (next_r == -1 || next_r == -2))
7515 /* Find (or create) an entry in the tocsave hash table. */
7517 static struct tocsave_entry *
7518 tocsave_find (struct ppc_link_hash_table *htab,
7519 enum insert_option insert,
7520 Elf_Internal_Sym **local_syms,
7521 const Elf_Internal_Rela *irela,
7524 unsigned long r_indx;
7525 struct elf_link_hash_entry *h;
7526 Elf_Internal_Sym *sym;
7527 struct tocsave_entry ent, *p;
7529 struct tocsave_entry **slot;
7531 r_indx = ELF64_R_SYM (irela->r_info);
7532 if (!get_sym_h (&h, &sym, &ent.sec, NULL, local_syms, r_indx, ibfd))
7534 if (ent.sec == NULL || ent.sec->output_section == NULL)
7537 (_("%B: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd);
7542 ent.offset = h->root.u.def.value;
7544 ent.offset = sym->st_value;
7545 ent.offset += irela->r_addend;
7547 hash = tocsave_htab_hash (&ent);
7548 slot = ((struct tocsave_entry **)
7549 htab_find_slot_with_hash (htab->tocsave_htab, &ent, hash, insert));
7555 p = (struct tocsave_entry *) bfd_alloc (ibfd, sizeof (*p));
7564 /* Adjust all global syms defined in opd sections. In gcc generated
7565 code for the old ABI, these will already have been done. */
7568 adjust_opd_syms (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
7570 struct ppc_link_hash_entry *eh;
7572 struct _opd_sec_data *opd;
7574 if (h->root.type == bfd_link_hash_indirect)
7577 if (h->root.type != bfd_link_hash_defined
7578 && h->root.type != bfd_link_hash_defweak)
7581 eh = (struct ppc_link_hash_entry *) h;
7582 if (eh->adjust_done)
7585 sym_sec = eh->elf.root.u.def.section;
7586 opd = get_opd_info (sym_sec);
7587 if (opd != NULL && opd->adjust != NULL)
7589 long adjust = opd->adjust[OPD_NDX (eh->elf.root.u.def.value)];
7592 /* This entry has been deleted. */
7593 asection *dsec = ppc64_elf_tdata (sym_sec->owner)->deleted_section;
7596 for (dsec = sym_sec->owner->sections; dsec; dsec = dsec->next)
7597 if (discarded_section (dsec))
7599 ppc64_elf_tdata (sym_sec->owner)->deleted_section = dsec;
7603 eh->elf.root.u.def.value = 0;
7604 eh->elf.root.u.def.section = dsec;
7607 eh->elf.root.u.def.value += adjust;
7608 eh->adjust_done = 1;
7613 /* Handles decrementing dynamic reloc counts for the reloc specified by
7614 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7615 have already been determined. */
7618 dec_dynrel_count (bfd_vma r_info,
7620 struct bfd_link_info *info,
7621 Elf_Internal_Sym **local_syms,
7622 struct elf_link_hash_entry *h,
7623 Elf_Internal_Sym *sym)
7625 enum elf_ppc64_reloc_type r_type;
7626 asection *sym_sec = NULL;
7628 /* Can this reloc be dynamic? This switch, and later tests here
7629 should be kept in sync with the code in check_relocs. */
7630 r_type = ELF64_R_TYPE (r_info);
7636 case R_PPC64_TPREL16:
7637 case R_PPC64_TPREL16_LO:
7638 case R_PPC64_TPREL16_HI:
7639 case R_PPC64_TPREL16_HA:
7640 case R_PPC64_TPREL16_DS:
7641 case R_PPC64_TPREL16_LO_DS:
7642 case R_PPC64_TPREL16_HIGH:
7643 case R_PPC64_TPREL16_HIGHA:
7644 case R_PPC64_TPREL16_HIGHER:
7645 case R_PPC64_TPREL16_HIGHERA:
7646 case R_PPC64_TPREL16_HIGHEST:
7647 case R_PPC64_TPREL16_HIGHESTA:
7648 case R_PPC64_TPREL64:
7649 case R_PPC64_DTPMOD64:
7650 case R_PPC64_DTPREL64:
7651 case R_PPC64_ADDR64:
7655 case R_PPC64_ADDR14:
7656 case R_PPC64_ADDR14_BRNTAKEN:
7657 case R_PPC64_ADDR14_BRTAKEN:
7658 case R_PPC64_ADDR16:
7659 case R_PPC64_ADDR16_DS:
7660 case R_PPC64_ADDR16_HA:
7661 case R_PPC64_ADDR16_HI:
7662 case R_PPC64_ADDR16_HIGH:
7663 case R_PPC64_ADDR16_HIGHA:
7664 case R_PPC64_ADDR16_HIGHER:
7665 case R_PPC64_ADDR16_HIGHERA:
7666 case R_PPC64_ADDR16_HIGHEST:
7667 case R_PPC64_ADDR16_HIGHESTA:
7668 case R_PPC64_ADDR16_LO:
7669 case R_PPC64_ADDR16_LO_DS:
7670 case R_PPC64_ADDR24:
7671 case R_PPC64_ADDR32:
7672 case R_PPC64_UADDR16:
7673 case R_PPC64_UADDR32:
7674 case R_PPC64_UADDR64:
7679 if (local_syms != NULL)
7681 unsigned long r_symndx;
7682 bfd *ibfd = sec->owner;
7684 r_symndx = ELF64_R_SYM (r_info);
7685 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd))
7689 if ((bfd_link_pic (info)
7690 && (must_be_dyn_reloc (info, r_type)
7692 && (!SYMBOLIC_BIND (info, h)
7693 || h->root.type == bfd_link_hash_defweak
7694 || !h->def_regular))))
7695 || (ELIMINATE_COPY_RELOCS
7696 && !bfd_link_pic (info)
7698 && (h->root.type == bfd_link_hash_defweak
7699 || !h->def_regular)))
7706 struct elf_dyn_relocs *p;
7707 struct elf_dyn_relocs **pp;
7708 pp = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
7710 /* elf_gc_sweep may have already removed all dyn relocs associated
7711 with local syms for a given section. Also, symbol flags are
7712 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7713 report a dynreloc miscount. */
7714 if (*pp == NULL && info->gc_sections)
7717 while ((p = *pp) != NULL)
7721 if (!must_be_dyn_reloc (info, r_type))
7733 struct ppc_dyn_relocs *p;
7734 struct ppc_dyn_relocs **pp;
7736 bfd_boolean is_ifunc;
7738 if (local_syms == NULL)
7739 sym_sec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
7740 if (sym_sec == NULL)
7743 vpp = &elf_section_data (sym_sec)->local_dynrel;
7744 pp = (struct ppc_dyn_relocs **) vpp;
7746 if (*pp == NULL && info->gc_sections)
7749 is_ifunc = ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC;
7750 while ((p = *pp) != NULL)
7752 if (p->sec == sec && p->ifunc == is_ifunc)
7763 /* xgettext:c-format */
7764 info->callbacks->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
7766 bfd_set_error (bfd_error_bad_value);
7770 /* Remove unused Official Procedure Descriptor entries. Currently we
7771 only remove those associated with functions in discarded link-once
7772 sections, or weakly defined functions that have been overridden. It
7773 would be possible to remove many more entries for statically linked
7777 ppc64_elf_edit_opd (struct bfd_link_info *info)
7780 bfd_boolean some_edited = FALSE;
7781 asection *need_pad = NULL;
7782 struct ppc_link_hash_table *htab;
7784 htab = ppc_hash_table (info);
7788 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
7791 Elf_Internal_Rela *relstart, *rel, *relend;
7792 Elf_Internal_Shdr *symtab_hdr;
7793 Elf_Internal_Sym *local_syms;
7794 struct _opd_sec_data *opd;
7795 bfd_boolean need_edit, add_aux_fields, broken;
7796 bfd_size_type cnt_16b = 0;
7798 if (!is_ppc64_elf (ibfd))
7801 sec = bfd_get_section_by_name (ibfd, ".opd");
7802 if (sec == NULL || sec->size == 0)
7805 if (sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
7808 if (sec->output_section == bfd_abs_section_ptr)
7811 /* Look through the section relocs. */
7812 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
7816 symtab_hdr = &elf_symtab_hdr (ibfd);
7818 /* Read the relocations. */
7819 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
7821 if (relstart == NULL)
7824 /* First run through the relocs to check they are sane, and to
7825 determine whether we need to edit this opd section. */
7829 relend = relstart + sec->reloc_count;
7830 for (rel = relstart; rel < relend; )
7832 enum elf_ppc64_reloc_type r_type;
7833 unsigned long r_symndx;
7835 struct elf_link_hash_entry *h;
7836 Elf_Internal_Sym *sym;
7839 /* .opd contains an array of 16 or 24 byte entries. We're
7840 only interested in the reloc pointing to a function entry
7842 offset = rel->r_offset;
7843 if (rel + 1 == relend
7844 || rel[1].r_offset != offset + 8)
7846 /* If someone messes with .opd alignment then after a
7847 "ld -r" we might have padding in the middle of .opd.
7848 Also, there's nothing to prevent someone putting
7849 something silly in .opd with the assembler. No .opd
7850 optimization for them! */
7853 (_("%B: .opd is not a regular array of opd entries"), ibfd);
7858 if ((r_type = ELF64_R_TYPE (rel->r_info)) != R_PPC64_ADDR64
7859 || (r_type = ELF64_R_TYPE ((rel + 1)->r_info)) != R_PPC64_TOC)
7862 /* xgettext:c-format */
7863 (_("%B: unexpected reloc type %u in .opd section"),
7869 r_symndx = ELF64_R_SYM (rel->r_info);
7870 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
7874 if (sym_sec == NULL || sym_sec->owner == NULL)
7876 const char *sym_name;
7878 sym_name = h->root.root.string;
7880 sym_name = bfd_elf_sym_name (ibfd, symtab_hdr, sym,
7884 /* xgettext:c-format */
7885 (_("%B: undefined sym `%s' in .opd section"),
7891 /* opd entries are always for functions defined in the
7892 current input bfd. If the symbol isn't defined in the
7893 input bfd, then we won't be using the function in this
7894 bfd; It must be defined in a linkonce section in another
7895 bfd, or is weak. It's also possible that we are
7896 discarding the function due to a linker script /DISCARD/,
7897 which we test for via the output_section. */
7898 if (sym_sec->owner != ibfd
7899 || sym_sec->output_section == bfd_abs_section_ptr)
7903 if (rel + 1 == relend
7904 || (rel + 2 < relend
7905 && ELF64_R_TYPE (rel[2].r_info) == R_PPC64_TOC))
7910 if (sec->size == offset + 24)
7915 if (sec->size == offset + 16)
7922 else if (rel + 1 < relend
7923 && ELF64_R_TYPE (rel[0].r_info) == R_PPC64_ADDR64
7924 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOC)
7926 if (rel[0].r_offset == offset + 16)
7928 else if (rel[0].r_offset != offset + 24)
7935 add_aux_fields = htab->params->non_overlapping_opd && cnt_16b > 0;
7937 if (!broken && (need_edit || add_aux_fields))
7939 Elf_Internal_Rela *write_rel;
7940 Elf_Internal_Shdr *rel_hdr;
7941 bfd_byte *rptr, *wptr;
7942 bfd_byte *new_contents;
7945 new_contents = NULL;
7946 amt = OPD_NDX (sec->size) * sizeof (long);
7947 opd = &ppc64_elf_section_data (sec)->u.opd;
7948 opd->adjust = bfd_zalloc (sec->owner, amt);
7949 if (opd->adjust == NULL)
7952 /* This seems a waste of time as input .opd sections are all
7953 zeros as generated by gcc, but I suppose there's no reason
7954 this will always be so. We might start putting something in
7955 the third word of .opd entries. */
7956 if ((sec->flags & SEC_IN_MEMORY) == 0)
7959 if (!bfd_malloc_and_get_section (ibfd, sec, &loc))
7964 if (local_syms != NULL
7965 && symtab_hdr->contents != (unsigned char *) local_syms)
7967 if (elf_section_data (sec)->relocs != relstart)
7971 sec->contents = loc;
7972 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
7975 elf_section_data (sec)->relocs = relstart;
7977 new_contents = sec->contents;
7980 new_contents = bfd_malloc (sec->size + cnt_16b * 8);
7981 if (new_contents == NULL)
7985 wptr = new_contents;
7986 rptr = sec->contents;
7987 write_rel = relstart;
7988 for (rel = relstart; rel < relend; )
7990 unsigned long r_symndx;
7992 struct elf_link_hash_entry *h;
7993 struct ppc_link_hash_entry *fdh = NULL;
7994 Elf_Internal_Sym *sym;
7996 Elf_Internal_Rela *next_rel;
7999 r_symndx = ELF64_R_SYM (rel->r_info);
8000 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8005 if (next_rel + 1 == relend
8006 || (next_rel + 2 < relend
8007 && ELF64_R_TYPE (next_rel[2].r_info) == R_PPC64_TOC))
8010 /* See if the .opd entry is full 24 byte or
8011 16 byte (with fd_aux entry overlapped with next
8014 if (next_rel == relend)
8016 if (sec->size == rel->r_offset + 16)
8019 else if (next_rel->r_offset == rel->r_offset + 16)
8023 && h->root.root.string[0] == '.')
8025 fdh = ((struct ppc_link_hash_entry *) h)->oh;
8028 fdh = ppc_follow_link (fdh);
8029 if (fdh->elf.root.type != bfd_link_hash_defined
8030 && fdh->elf.root.type != bfd_link_hash_defweak)
8035 skip = (sym_sec->owner != ibfd
8036 || sym_sec->output_section == bfd_abs_section_ptr);
8039 if (fdh != NULL && sym_sec->owner == ibfd)
8041 /* Arrange for the function descriptor sym
8043 fdh->elf.root.u.def.value = 0;
8044 fdh->elf.root.u.def.section = sym_sec;
8046 opd->adjust[OPD_NDX (rel->r_offset)] = -1;
8048 if (NO_OPD_RELOCS || bfd_link_relocatable (info))
8053 if (!dec_dynrel_count (rel->r_info, sec, info,
8057 if (++rel == next_rel)
8060 r_symndx = ELF64_R_SYM (rel->r_info);
8061 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8068 /* We'll be keeping this opd entry. */
8073 /* Redefine the function descriptor symbol to
8074 this location in the opd section. It is
8075 necessary to update the value here rather
8076 than using an array of adjustments as we do
8077 for local symbols, because various places
8078 in the generic ELF code use the value
8079 stored in u.def.value. */
8080 fdh->elf.root.u.def.value = wptr - new_contents;
8081 fdh->adjust_done = 1;
8084 /* Local syms are a bit tricky. We could
8085 tweak them as they can be cached, but
8086 we'd need to look through the local syms
8087 for the function descriptor sym which we
8088 don't have at the moment. So keep an
8089 array of adjustments. */
8090 adjust = (wptr - new_contents) - (rptr - sec->contents);
8091 opd->adjust[OPD_NDX (rel->r_offset)] = adjust;
8094 memcpy (wptr, rptr, opd_ent_size);
8095 wptr += opd_ent_size;
8096 if (add_aux_fields && opd_ent_size == 16)
8098 memset (wptr, '\0', 8);
8102 /* We need to adjust any reloc offsets to point to the
8104 for ( ; rel != next_rel; ++rel)
8106 rel->r_offset += adjust;
8107 if (write_rel != rel)
8108 memcpy (write_rel, rel, sizeof (*rel));
8113 rptr += opd_ent_size;
8116 sec->size = wptr - new_contents;
8117 sec->reloc_count = write_rel - relstart;
8120 free (sec->contents);
8121 sec->contents = new_contents;
8124 /* Fudge the header size too, as this is used later in
8125 elf_bfd_final_link if we are emitting relocs. */
8126 rel_hdr = _bfd_elf_single_rel_hdr (sec);
8127 rel_hdr->sh_size = sec->reloc_count * rel_hdr->sh_entsize;
8130 else if (elf_section_data (sec)->relocs != relstart)
8133 if (local_syms != NULL
8134 && symtab_hdr->contents != (unsigned char *) local_syms)
8136 if (!info->keep_memory)
8139 symtab_hdr->contents = (unsigned char *) local_syms;
8144 elf_link_hash_traverse (elf_hash_table (info), adjust_opd_syms, NULL);
8146 /* If we are doing a final link and the last .opd entry is just 16 byte
8147 long, add a 8 byte padding after it. */
8148 if (need_pad != NULL && !bfd_link_relocatable (info))
8152 if ((need_pad->flags & SEC_IN_MEMORY) == 0)
8154 BFD_ASSERT (need_pad->size > 0);
8156 p = bfd_malloc (need_pad->size + 8);
8160 if (! bfd_get_section_contents (need_pad->owner, need_pad,
8161 p, 0, need_pad->size))
8164 need_pad->contents = p;
8165 need_pad->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
8169 p = bfd_realloc (need_pad->contents, need_pad->size + 8);
8173 need_pad->contents = p;
8176 memset (need_pad->contents + need_pad->size, 0, 8);
8177 need_pad->size += 8;
8183 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8186 ppc64_elf_tls_setup (struct bfd_link_info *info)
8188 struct ppc_link_hash_table *htab;
8190 htab = ppc_hash_table (info);
8194 if (abiversion (info->output_bfd) == 1)
8197 if (htab->params->no_multi_toc)
8198 htab->do_multi_toc = 0;
8199 else if (!htab->do_multi_toc)
8200 htab->params->no_multi_toc = 1;
8202 /* Default to --no-plt-localentry, as this option can cause problems
8203 with symbol interposition. For example, glibc libpthread.so and
8204 libc.so duplicate many pthread symbols, with a fallback
8205 implementation in libc.so. In some cases the fallback does more
8206 work than the pthread implementation. __pthread_condattr_destroy
8207 is one such symbol: the libpthread.so implementation is
8208 localentry:0 while the libc.so implementation is localentry:8.
8209 An app that "cleverly" uses dlopen to only load necessary
8210 libraries at runtime may omit loading libpthread.so when not
8211 running multi-threaded, which then results in the libc.so
8212 fallback symbols being used and ld.so complaining. Now there
8213 are workarounds in ld (see non_zero_localentry) to detect the
8214 pthread situation, but that may not be the only case where
8215 --plt-localentry can cause trouble. */
8216 if (htab->params->plt_localentry0 < 0)
8217 htab->params->plt_localentry0 = 0;
8218 if (htab->params->plt_localentry0
8219 && elf_link_hash_lookup (&htab->elf, "GLIBC_2.26",
8220 FALSE, FALSE, FALSE) == NULL)
8221 info->callbacks->einfo
8222 (_("%P: warning: --plt-localentry is especially dangerous without "
8223 "ld.so support to detect ABI violations.\n"));
8225 htab->tls_get_addr = ((struct ppc_link_hash_entry *)
8226 elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
8227 FALSE, FALSE, TRUE));
8228 /* Move dynamic linking info to the function descriptor sym. */
8229 if (htab->tls_get_addr != NULL)
8230 func_desc_adjust (&htab->tls_get_addr->elf, info);
8231 htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
8232 elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
8233 FALSE, FALSE, TRUE));
8234 if (htab->params->tls_get_addr_opt)
8236 struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
8238 opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
8239 FALSE, FALSE, TRUE);
8241 func_desc_adjust (opt, info);
8242 opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
8243 FALSE, FALSE, TRUE);
8245 && (opt_fd->root.type == bfd_link_hash_defined
8246 || opt_fd->root.type == bfd_link_hash_defweak))
8248 /* If glibc supports an optimized __tls_get_addr call stub,
8249 signalled by the presence of __tls_get_addr_opt, and we'll
8250 be calling __tls_get_addr via a plt call stub, then
8251 make __tls_get_addr point to __tls_get_addr_opt. */
8252 tga_fd = &htab->tls_get_addr_fd->elf;
8253 if (htab->elf.dynamic_sections_created
8255 && (tga_fd->type == STT_FUNC
8256 || tga_fd->needs_plt)
8257 && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
8258 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, tga_fd)))
8260 struct plt_entry *ent;
8262 for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
8263 if (ent->plt.refcount > 0)
8267 tga_fd->root.type = bfd_link_hash_indirect;
8268 tga_fd->root.u.i.link = &opt_fd->root;
8269 ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
8271 if (opt_fd->dynindx != -1)
8273 /* Use __tls_get_addr_opt in dynamic relocations. */
8274 opt_fd->dynindx = -1;
8275 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
8276 opt_fd->dynstr_index);
8277 if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
8280 htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd;
8281 tga = &htab->tls_get_addr->elf;
8282 if (opt != NULL && tga != NULL)
8284 tga->root.type = bfd_link_hash_indirect;
8285 tga->root.u.i.link = &opt->root;
8286 ppc64_elf_copy_indirect_symbol (info, opt, tga);
8288 _bfd_elf_link_hash_hide_symbol (info, opt,
8290 htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
8292 htab->tls_get_addr_fd->oh = htab->tls_get_addr;
8293 htab->tls_get_addr_fd->is_func_descriptor = 1;
8294 if (htab->tls_get_addr != NULL)
8296 htab->tls_get_addr->oh = htab->tls_get_addr_fd;
8297 htab->tls_get_addr->is_func = 1;
8302 else if (htab->params->tls_get_addr_opt < 0)
8303 htab->params->tls_get_addr_opt = 0;
8305 return _bfd_elf_tls_setup (info->output_bfd, info);
8308 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8312 branch_reloc_hash_match (const bfd *ibfd,
8313 const Elf_Internal_Rela *rel,
8314 const struct ppc_link_hash_entry *hash1,
8315 const struct ppc_link_hash_entry *hash2)
8317 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
8318 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
8319 unsigned int r_symndx = ELF64_R_SYM (rel->r_info);
8321 if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
8323 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
8324 struct elf_link_hash_entry *h;
8326 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
8327 h = elf_follow_link (h);
8328 if (h == &hash1->elf || h == &hash2->elf)
8334 /* Run through all the TLS relocs looking for optimization
8335 opportunities. The linker has been hacked (see ppc64elf.em) to do
8336 a preliminary section layout so that we know the TLS segment
8337 offsets. We can't optimize earlier because some optimizations need
8338 to know the tp offset, and we need to optimize before allocating
8339 dynamic relocations. */
8342 ppc64_elf_tls_optimize (struct bfd_link_info *info)
8346 struct ppc_link_hash_table *htab;
8347 unsigned char *toc_ref;
8350 if (!bfd_link_executable (info))
8353 htab = ppc_hash_table (info);
8357 /* Make two passes over the relocs. On the first pass, mark toc
8358 entries involved with tls relocs, and check that tls relocs
8359 involved in setting up a tls_get_addr call are indeed followed by
8360 such a call. If they are not, we can't do any tls optimization.
8361 On the second pass twiddle tls_mask flags to notify
8362 relocate_section that optimization can be done, and adjust got
8363 and plt refcounts. */
8365 for (pass = 0; pass < 2; ++pass)
8366 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8368 Elf_Internal_Sym *locsyms = NULL;
8369 asection *toc = bfd_get_section_by_name (ibfd, ".toc");
8371 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8372 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
8374 Elf_Internal_Rela *relstart, *rel, *relend;
8375 bfd_boolean found_tls_get_addr_arg = 0;
8377 /* Read the relocations. */
8378 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
8380 if (relstart == NULL)
8386 relend = relstart + sec->reloc_count;
8387 for (rel = relstart; rel < relend; rel++)
8389 enum elf_ppc64_reloc_type r_type;
8390 unsigned long r_symndx;
8391 struct elf_link_hash_entry *h;
8392 Elf_Internal_Sym *sym;
8394 unsigned char *tls_mask;
8395 unsigned char tls_set, tls_clear, tls_type = 0;
8397 bfd_boolean ok_tprel, is_local;
8398 long toc_ref_index = 0;
8399 int expecting_tls_get_addr = 0;
8400 bfd_boolean ret = FALSE;
8402 r_symndx = ELF64_R_SYM (rel->r_info);
8403 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
8407 if (elf_section_data (sec)->relocs != relstart)
8409 if (toc_ref != NULL)
8412 && (elf_symtab_hdr (ibfd).contents
8413 != (unsigned char *) locsyms))
8420 if (h->root.type == bfd_link_hash_defined
8421 || h->root.type == bfd_link_hash_defweak)
8422 value = h->root.u.def.value;
8423 else if (h->root.type == bfd_link_hash_undefweak)
8427 found_tls_get_addr_arg = 0;
8432 /* Symbols referenced by TLS relocs must be of type
8433 STT_TLS. So no need for .opd local sym adjust. */
8434 value = sym->st_value;
8443 && h->root.type == bfd_link_hash_undefweak)
8445 else if (sym_sec != NULL
8446 && sym_sec->output_section != NULL)
8448 value += sym_sec->output_offset;
8449 value += sym_sec->output_section->vma;
8450 value -= htab->elf.tls_sec->vma;
8451 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
8452 < (bfd_vma) 1 << 32);
8456 r_type = ELF64_R_TYPE (rel->r_info);
8457 /* If this section has old-style __tls_get_addr calls
8458 without marker relocs, then check that each
8459 __tls_get_addr call reloc is preceded by a reloc
8460 that conceivably belongs to the __tls_get_addr arg
8461 setup insn. If we don't find matching arg setup
8462 relocs, don't do any tls optimization. */
8464 && sec->has_tls_get_addr_call
8466 && (h == &htab->tls_get_addr->elf
8467 || h == &htab->tls_get_addr_fd->elf)
8468 && !found_tls_get_addr_arg
8469 && is_branch_reloc (r_type))
8471 info->callbacks->minfo (_("%H __tls_get_addr lost arg, "
8472 "TLS optimization disabled\n"),
8473 ibfd, sec, rel->r_offset);
8478 found_tls_get_addr_arg = 0;
8481 case R_PPC64_GOT_TLSLD16:
8482 case R_PPC64_GOT_TLSLD16_LO:
8483 expecting_tls_get_addr = 1;
8484 found_tls_get_addr_arg = 1;
8487 case R_PPC64_GOT_TLSLD16_HI:
8488 case R_PPC64_GOT_TLSLD16_HA:
8489 /* These relocs should never be against a symbol
8490 defined in a shared lib. Leave them alone if
8491 that turns out to be the case. */
8498 tls_type = TLS_TLS | TLS_LD;
8501 case R_PPC64_GOT_TLSGD16:
8502 case R_PPC64_GOT_TLSGD16_LO:
8503 expecting_tls_get_addr = 1;
8504 found_tls_get_addr_arg = 1;
8507 case R_PPC64_GOT_TLSGD16_HI:
8508 case R_PPC64_GOT_TLSGD16_HA:
8514 tls_set = TLS_TLS | TLS_TPRELGD;
8516 tls_type = TLS_TLS | TLS_GD;
8519 case R_PPC64_GOT_TPREL16_DS:
8520 case R_PPC64_GOT_TPREL16_LO_DS:
8521 case R_PPC64_GOT_TPREL16_HI:
8522 case R_PPC64_GOT_TPREL16_HA:
8527 tls_clear = TLS_TPREL;
8528 tls_type = TLS_TLS | TLS_TPREL;
8535 found_tls_get_addr_arg = 1;
8540 case R_PPC64_TOC16_LO:
8541 if (sym_sec == NULL || sym_sec != toc)
8544 /* Mark this toc entry as referenced by a TLS
8545 code sequence. We can do that now in the
8546 case of R_PPC64_TLS, and after checking for
8547 tls_get_addr for the TOC16 relocs. */
8548 if (toc_ref == NULL)
8549 toc_ref = bfd_zmalloc (toc->output_section->rawsize / 8);
8550 if (toc_ref == NULL)
8554 value = h->root.u.def.value;
8556 value = sym->st_value;
8557 value += rel->r_addend;
8560 BFD_ASSERT (value < toc->size
8561 && toc->output_offset % 8 == 0);
8562 toc_ref_index = (value + toc->output_offset) / 8;
8563 if (r_type == R_PPC64_TLS
8564 || r_type == R_PPC64_TLSGD
8565 || r_type == R_PPC64_TLSLD)
8567 toc_ref[toc_ref_index] = 1;
8571 if (pass != 0 && toc_ref[toc_ref_index] == 0)
8576 expecting_tls_get_addr = 2;
8579 case R_PPC64_TPREL64:
8583 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8588 tls_set = TLS_EXPLICIT;
8589 tls_clear = TLS_TPREL;
8594 case R_PPC64_DTPMOD64:
8598 || !toc_ref[(rel->r_offset + toc->output_offset) / 8])
8600 if (rel + 1 < relend
8602 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
8603 && rel[1].r_offset == rel->r_offset + 8)
8607 tls_set = TLS_EXPLICIT | TLS_GD;
8610 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
8619 tls_set = TLS_EXPLICIT;
8630 if (!expecting_tls_get_addr
8631 || !sec->has_tls_get_addr_call)
8634 if (rel + 1 < relend
8635 && branch_reloc_hash_match (ibfd, rel + 1,
8637 htab->tls_get_addr_fd))
8639 if (expecting_tls_get_addr == 2)
8641 /* Check for toc tls entries. */
8642 unsigned char *toc_tls;
8645 retval = get_tls_mask (&toc_tls, NULL, NULL,
8650 if (toc_tls != NULL)
8652 if ((*toc_tls & (TLS_GD | TLS_LD)) != 0)
8653 found_tls_get_addr_arg = 1;
8655 toc_ref[toc_ref_index] = 1;
8661 if (expecting_tls_get_addr != 1)
8664 /* Uh oh, we didn't find the expected call. We
8665 could just mark this symbol to exclude it
8666 from tls optimization but it's safer to skip
8667 the entire optimization. */
8668 /* xgettext:c-format */
8669 info->callbacks->minfo (_("%H arg lost __tls_get_addr, "
8670 "TLS optimization disabled\n"),
8671 ibfd, sec, rel->r_offset);
8676 if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
8678 struct plt_entry *ent;
8679 for (ent = htab->tls_get_addr->elf.plt.plist;
8682 if (ent->addend == 0)
8684 if (ent->plt.refcount > 0)
8686 ent->plt.refcount -= 1;
8687 expecting_tls_get_addr = 0;
8693 if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL)
8695 struct plt_entry *ent;
8696 for (ent = htab->tls_get_addr_fd->elf.plt.plist;
8699 if (ent->addend == 0)
8701 if (ent->plt.refcount > 0)
8702 ent->plt.refcount -= 1;
8710 if ((tls_set & TLS_EXPLICIT) == 0)
8712 struct got_entry *ent;
8714 /* Adjust got entry for this reloc. */
8718 ent = elf_local_got_ents (ibfd)[r_symndx];
8720 for (; ent != NULL; ent = ent->next)
8721 if (ent->addend == rel->r_addend
8722 && ent->owner == ibfd
8723 && ent->tls_type == tls_type)
8730 /* We managed to get rid of a got entry. */
8731 if (ent->got.refcount > 0)
8732 ent->got.refcount -= 1;
8737 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8738 we'll lose one or two dyn relocs. */
8739 if (!dec_dynrel_count (rel->r_info, sec, info,
8743 if (tls_set == (TLS_EXPLICIT | TLS_GD))
8745 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info,
8751 *tls_mask |= tls_set;
8752 *tls_mask &= ~tls_clear;
8755 if (elf_section_data (sec)->relocs != relstart)
8760 && (elf_symtab_hdr (ibfd).contents != (unsigned char *) locsyms))
8762 if (!info->keep_memory)
8765 elf_symtab_hdr (ibfd).contents = (unsigned char *) locsyms;
8769 if (toc_ref != NULL)
8771 htab->do_tls_opt = 1;
8775 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8776 the values of any global symbols in a toc section that has been
8777 edited. Globals in toc sections should be a rarity, so this function
8778 sets a flag if any are found in toc sections other than the one just
8779 edited, so that further hash table traversals can be avoided. */
8781 struct adjust_toc_info
8784 unsigned long *skip;
8785 bfd_boolean global_toc_syms;
8788 enum toc_skip_enum { ref_from_discarded = 1, can_optimize = 2 };
8791 adjust_toc_syms (struct elf_link_hash_entry *h, void *inf)
8793 struct ppc_link_hash_entry *eh;
8794 struct adjust_toc_info *toc_inf = (struct adjust_toc_info *) inf;
8797 if (h->root.type != bfd_link_hash_defined
8798 && h->root.type != bfd_link_hash_defweak)
8801 eh = (struct ppc_link_hash_entry *) h;
8802 if (eh->adjust_done)
8805 if (eh->elf.root.u.def.section == toc_inf->toc)
8807 if (eh->elf.root.u.def.value > toc_inf->toc->rawsize)
8808 i = toc_inf->toc->rawsize >> 3;
8810 i = eh->elf.root.u.def.value >> 3;
8812 if ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0)
8815 (_("%s defined on removed toc entry"), eh->elf.root.root.string);
8818 while ((toc_inf->skip[i] & (ref_from_discarded | can_optimize)) != 0);
8819 eh->elf.root.u.def.value = (bfd_vma) i << 3;
8822 eh->elf.root.u.def.value -= toc_inf->skip[i];
8823 eh->adjust_done = 1;
8825 else if (strcmp (eh->elf.root.u.def.section->name, ".toc") == 0)
8826 toc_inf->global_toc_syms = TRUE;
8831 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8832 on a _LO variety toc/got reloc. */
8835 ok_lo_toc_insn (unsigned int insn, enum elf_ppc64_reloc_type r_type)
8837 return ((insn & (0x3f << 26)) == 12u << 26 /* addic */
8838 || (insn & (0x3f << 26)) == 14u << 26 /* addi */
8839 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
8840 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
8841 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
8842 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
8843 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
8844 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
8845 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
8846 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
8847 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
8848 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
8849 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
8850 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
8851 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
8852 || (insn & (0x3f << 26)) == 56u << 26 /* lq,lfq */
8853 || ((insn & (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8854 /* Exclude lfqu by testing reloc. If relocs are ever
8855 defined for the reduced D field in psq_lu then those
8856 will need testing too. */
8857 && r_type != R_PPC64_TOC16_LO && r_type != R_PPC64_GOT16_LO)
8858 || ((insn & (0x3f << 26)) == 58u << 26 /* ld,lwa */
8860 || (insn & (0x3f << 26)) == 60u << 26 /* stfq */
8861 || ((insn & (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8862 /* Exclude stfqu. psq_stu as above for psq_lu. */
8863 && r_type != R_PPC64_TOC16_LO && r_type != R_PPC64_GOT16_LO)
8864 || ((insn & (0x3f << 26)) == 62u << 26 /* std,stq */
8865 && (insn & 1) == 0));
8868 /* Examine all relocs referencing .toc sections in order to remove
8869 unused .toc entries. */
8872 ppc64_elf_edit_toc (struct bfd_link_info *info)
8875 struct adjust_toc_info toc_inf;
8876 struct ppc_link_hash_table *htab = ppc_hash_table (info);
8878 htab->do_toc_opt = 1;
8879 toc_inf.global_toc_syms = TRUE;
8880 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
8882 asection *toc, *sec;
8883 Elf_Internal_Shdr *symtab_hdr;
8884 Elf_Internal_Sym *local_syms;
8885 Elf_Internal_Rela *relstart, *rel, *toc_relocs;
8886 unsigned long *skip, *drop;
8887 unsigned char *used;
8888 unsigned char *keep, last, some_unused;
8890 if (!is_ppc64_elf (ibfd))
8893 toc = bfd_get_section_by_name (ibfd, ".toc");
8896 || toc->sec_info_type == SEC_INFO_TYPE_JUST_SYMS
8897 || discarded_section (toc))
8902 symtab_hdr = &elf_symtab_hdr (ibfd);
8904 /* Look at sections dropped from the final link. */
8907 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8909 if (sec->reloc_count == 0
8910 || !discarded_section (sec)
8911 || get_opd_info (sec)
8912 || (sec->flags & SEC_ALLOC) == 0
8913 || (sec->flags & SEC_DEBUGGING) != 0)
8916 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, FALSE);
8917 if (relstart == NULL)
8920 /* Run through the relocs to see which toc entries might be
8922 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
8924 enum elf_ppc64_reloc_type r_type;
8925 unsigned long r_symndx;
8927 struct elf_link_hash_entry *h;
8928 Elf_Internal_Sym *sym;
8931 r_type = ELF64_R_TYPE (rel->r_info);
8938 case R_PPC64_TOC16_LO:
8939 case R_PPC64_TOC16_HI:
8940 case R_PPC64_TOC16_HA:
8941 case R_PPC64_TOC16_DS:
8942 case R_PPC64_TOC16_LO_DS:
8946 r_symndx = ELF64_R_SYM (rel->r_info);
8947 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
8955 val = h->root.u.def.value;
8957 val = sym->st_value;
8958 val += rel->r_addend;
8960 if (val >= toc->size)
8963 /* Anything in the toc ought to be aligned to 8 bytes.
8964 If not, don't mark as unused. */
8970 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
8975 skip[val >> 3] = ref_from_discarded;
8978 if (elf_section_data (sec)->relocs != relstart)
8982 /* For largetoc loads of address constants, we can convert
8983 . addis rx,2,addr@got@ha
8984 . ld ry,addr@got@l(rx)
8986 . addis rx,2,addr@toc@ha
8987 . addi ry,rx,addr@toc@l
8988 when addr is within 2G of the toc pointer. This then means
8989 that the word storing "addr" in the toc is no longer needed. */
8991 if (!ppc64_elf_tdata (ibfd)->has_small_toc_reloc
8992 && toc->output_section->rawsize < (bfd_vma) 1 << 31
8993 && toc->reloc_count != 0)
8995 /* Read toc relocs. */
8996 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
8998 if (toc_relocs == NULL)
9001 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
9003 enum elf_ppc64_reloc_type r_type;
9004 unsigned long r_symndx;
9006 struct elf_link_hash_entry *h;
9007 Elf_Internal_Sym *sym;
9010 r_type = ELF64_R_TYPE (rel->r_info);
9011 if (r_type != R_PPC64_ADDR64)
9014 r_symndx = ELF64_R_SYM (rel->r_info);
9015 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9020 || sym_sec->output_section == NULL
9021 || discarded_section (sym_sec))
9024 if (!SYMBOL_REFERENCES_LOCAL (info, h))
9029 if (h->type == STT_GNU_IFUNC)
9031 val = h->root.u.def.value;
9035 if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
9037 val = sym->st_value;
9039 val += rel->r_addend;
9040 val += sym_sec->output_section->vma + sym_sec->output_offset;
9042 /* We don't yet know the exact toc pointer value, but we
9043 know it will be somewhere in the toc section. Don't
9044 optimize if the difference from any possible toc
9045 pointer is outside [ff..f80008000, 7fff7fff]. */
9046 addr = toc->output_section->vma + TOC_BASE_OFF;
9047 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
9050 addr = toc->output_section->vma + toc->output_section->rawsize;
9051 if (val - addr + (bfd_vma) 0x80008000 >= (bfd_vma) 1 << 32)
9056 skip = bfd_zmalloc (sizeof (*skip) * (toc->size + 15) / 8);
9061 skip[rel->r_offset >> 3]
9062 |= can_optimize | ((rel - toc_relocs) << 2);
9069 used = bfd_zmalloc (sizeof (*used) * (toc->size + 7) / 8);
9073 if (local_syms != NULL
9074 && symtab_hdr->contents != (unsigned char *) local_syms)
9078 && elf_section_data (sec)->relocs != relstart)
9080 if (toc_relocs != NULL
9081 && elf_section_data (toc)->relocs != toc_relocs)
9088 /* Now check all kept sections that might reference the toc.
9089 Check the toc itself last. */
9090 for (sec = (ibfd->sections == toc && toc->next ? toc->next
9093 sec = (sec == toc ? NULL
9094 : sec->next == NULL ? toc
9095 : sec->next == toc && toc->next ? toc->next
9100 if (sec->reloc_count == 0
9101 || discarded_section (sec)
9102 || get_opd_info (sec)
9103 || (sec->flags & SEC_ALLOC) == 0
9104 || (sec->flags & SEC_DEBUGGING) != 0)
9107 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
9109 if (relstart == NULL)
9115 /* Mark toc entries referenced as used. */
9119 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
9121 enum elf_ppc64_reloc_type r_type;
9122 unsigned long r_symndx;
9124 struct elf_link_hash_entry *h;
9125 Elf_Internal_Sym *sym;
9127 enum {no_check, check_lo, check_ha} insn_check;
9129 r_type = ELF64_R_TYPE (rel->r_info);
9133 insn_check = no_check;
9136 case R_PPC64_GOT_TLSLD16_HA:
9137 case R_PPC64_GOT_TLSGD16_HA:
9138 case R_PPC64_GOT_TPREL16_HA:
9139 case R_PPC64_GOT_DTPREL16_HA:
9140 case R_PPC64_GOT16_HA:
9141 case R_PPC64_TOC16_HA:
9142 insn_check = check_ha;
9145 case R_PPC64_GOT_TLSLD16_LO:
9146 case R_PPC64_GOT_TLSGD16_LO:
9147 case R_PPC64_GOT_TPREL16_LO_DS:
9148 case R_PPC64_GOT_DTPREL16_LO_DS:
9149 case R_PPC64_GOT16_LO:
9150 case R_PPC64_GOT16_LO_DS:
9151 case R_PPC64_TOC16_LO:
9152 case R_PPC64_TOC16_LO_DS:
9153 insn_check = check_lo;
9157 if (insn_check != no_check)
9159 bfd_vma off = rel->r_offset & ~3;
9160 unsigned char buf[4];
9163 if (!bfd_get_section_contents (ibfd, sec, buf, off, 4))
9168 insn = bfd_get_32 (ibfd, buf);
9169 if (insn_check == check_lo
9170 ? !ok_lo_toc_insn (insn, r_type)
9171 : ((insn & ((0x3f << 26) | 0x1f << 16))
9172 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9176 ppc64_elf_tdata (ibfd)->unexpected_toc_insn = 1;
9177 sprintf (str, "%#08x", insn);
9178 info->callbacks->einfo
9179 /* xgettext:c-format */
9180 (_("%H: toc optimization is not supported for"
9181 " %s instruction.\n"),
9182 ibfd, sec, rel->r_offset & ~3, str);
9189 case R_PPC64_TOC16_LO:
9190 case R_PPC64_TOC16_HI:
9191 case R_PPC64_TOC16_HA:
9192 case R_PPC64_TOC16_DS:
9193 case R_PPC64_TOC16_LO_DS:
9194 /* In case we're taking addresses of toc entries. */
9195 case R_PPC64_ADDR64:
9202 r_symndx = ELF64_R_SYM (rel->r_info);
9203 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9214 val = h->root.u.def.value;
9216 val = sym->st_value;
9217 val += rel->r_addend;
9219 if (val >= toc->size)
9222 if ((skip[val >> 3] & can_optimize) != 0)
9229 case R_PPC64_TOC16_HA:
9232 case R_PPC64_TOC16_LO_DS:
9233 off = rel->r_offset;
9234 off += (bfd_big_endian (ibfd) ? -2 : 3);
9235 if (!bfd_get_section_contents (ibfd, sec, &opc,
9241 if ((opc & (0x3f << 2)) == (58u << 2))
9246 /* Wrong sort of reloc, or not a ld. We may
9247 as well clear ref_from_discarded too. */
9254 /* For the toc section, we only mark as used if this
9255 entry itself isn't unused. */
9256 else if ((used[rel->r_offset >> 3]
9257 || !(skip[rel->r_offset >> 3] & ref_from_discarded))
9260 /* Do all the relocs again, to catch reference
9269 if (elf_section_data (sec)->relocs != relstart)
9273 /* Merge the used and skip arrays. Assume that TOC
9274 doublewords not appearing as either used or unused belong
9275 to an entry more than one doubleword in size. */
9276 for (drop = skip, keep = used, last = 0, some_unused = 0;
9277 drop < skip + (toc->size + 7) / 8;
9282 *drop &= ~ref_from_discarded;
9283 if ((*drop & can_optimize) != 0)
9287 else if ((*drop & ref_from_discarded) != 0)
9290 last = ref_from_discarded;
9300 bfd_byte *contents, *src;
9302 Elf_Internal_Sym *sym;
9303 bfd_boolean local_toc_syms = FALSE;
9305 /* Shuffle the toc contents, and at the same time convert the
9306 skip array from booleans into offsets. */
9307 if (!bfd_malloc_and_get_section (ibfd, toc, &contents))
9310 elf_section_data (toc)->this_hdr.contents = contents;
9312 for (src = contents, off = 0, drop = skip;
9313 src < contents + toc->size;
9316 if ((*drop & (can_optimize | ref_from_discarded)) != 0)
9321 memcpy (src - off, src, 8);
9325 toc->rawsize = toc->size;
9326 toc->size = src - contents - off;
9328 /* Adjust addends for relocs against the toc section sym,
9329 and optimize any accesses we can. */
9330 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
9332 if (sec->reloc_count == 0
9333 || discarded_section (sec))
9336 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
9338 if (relstart == NULL)
9341 for (rel = relstart; rel < relstart + sec->reloc_count; ++rel)
9343 enum elf_ppc64_reloc_type r_type;
9344 unsigned long r_symndx;
9346 struct elf_link_hash_entry *h;
9349 r_type = ELF64_R_TYPE (rel->r_info);
9356 case R_PPC64_TOC16_LO:
9357 case R_PPC64_TOC16_HI:
9358 case R_PPC64_TOC16_HA:
9359 case R_PPC64_TOC16_DS:
9360 case R_PPC64_TOC16_LO_DS:
9361 case R_PPC64_ADDR64:
9365 r_symndx = ELF64_R_SYM (rel->r_info);
9366 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
9374 val = h->root.u.def.value;
9377 val = sym->st_value;
9379 local_toc_syms = TRUE;
9382 val += rel->r_addend;
9384 if (val > toc->rawsize)
9386 else if ((skip[val >> 3] & ref_from_discarded) != 0)
9388 else if ((skip[val >> 3] & can_optimize) != 0)
9390 Elf_Internal_Rela *tocrel
9391 = toc_relocs + (skip[val >> 3] >> 2);
9392 unsigned long tsym = ELF64_R_SYM (tocrel->r_info);
9396 case R_PPC64_TOC16_HA:
9397 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_TOC16_HA);
9400 case R_PPC64_TOC16_LO_DS:
9401 rel->r_info = ELF64_R_INFO (tsym, R_PPC64_LO_DS_OPT);
9405 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
9407 info->callbacks->einfo
9408 /* xgettext:c-format */
9409 (_("%H: %s references "
9410 "optimized away TOC entry\n"),
9411 ibfd, sec, rel->r_offset,
9412 ppc64_elf_howto_table[r_type]->name);
9413 bfd_set_error (bfd_error_bad_value);
9416 rel->r_addend = tocrel->r_addend;
9417 elf_section_data (sec)->relocs = relstart;
9421 if (h != NULL || sym->st_value != 0)
9424 rel->r_addend -= skip[val >> 3];
9425 elf_section_data (sec)->relocs = relstart;
9428 if (elf_section_data (sec)->relocs != relstart)
9432 /* We shouldn't have local or global symbols defined in the TOC,
9433 but handle them anyway. */
9434 if (local_syms != NULL)
9435 for (sym = local_syms;
9436 sym < local_syms + symtab_hdr->sh_info;
9438 if (sym->st_value != 0
9439 && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc)
9443 if (sym->st_value > toc->rawsize)
9444 i = toc->rawsize >> 3;
9446 i = sym->st_value >> 3;
9448 if ((skip[i] & (ref_from_discarded | can_optimize)) != 0)
9452 (_("%s defined on removed toc entry"),
9453 bfd_elf_sym_name (ibfd, symtab_hdr, sym, NULL));
9456 while ((skip[i] & (ref_from_discarded | can_optimize)));
9457 sym->st_value = (bfd_vma) i << 3;
9460 sym->st_value -= skip[i];
9461 symtab_hdr->contents = (unsigned char *) local_syms;
9464 /* Adjust any global syms defined in this toc input section. */
9465 if (toc_inf.global_toc_syms)
9468 toc_inf.skip = skip;
9469 toc_inf.global_toc_syms = FALSE;
9470 elf_link_hash_traverse (elf_hash_table (info), adjust_toc_syms,
9474 if (toc->reloc_count != 0)
9476 Elf_Internal_Shdr *rel_hdr;
9477 Elf_Internal_Rela *wrel;
9480 /* Remove unused toc relocs, and adjust those we keep. */
9481 if (toc_relocs == NULL)
9482 toc_relocs = _bfd_elf_link_read_relocs (ibfd, toc, NULL, NULL,
9484 if (toc_relocs == NULL)
9488 for (rel = toc_relocs; rel < toc_relocs + toc->reloc_count; ++rel)
9489 if ((skip[rel->r_offset >> 3]
9490 & (ref_from_discarded | can_optimize)) == 0)
9492 wrel->r_offset = rel->r_offset - skip[rel->r_offset >> 3];
9493 wrel->r_info = rel->r_info;
9494 wrel->r_addend = rel->r_addend;
9497 else if (!dec_dynrel_count (rel->r_info, toc, info,
9498 &local_syms, NULL, NULL))
9501 elf_section_data (toc)->relocs = toc_relocs;
9502 toc->reloc_count = wrel - toc_relocs;
9503 rel_hdr = _bfd_elf_single_rel_hdr (toc);
9504 sz = rel_hdr->sh_entsize;
9505 rel_hdr->sh_size = toc->reloc_count * sz;
9508 else if (toc_relocs != NULL
9509 && elf_section_data (toc)->relocs != toc_relocs)
9512 if (local_syms != NULL
9513 && symtab_hdr->contents != (unsigned char *) local_syms)
9515 if (!info->keep_memory)
9518 symtab_hdr->contents = (unsigned char *) local_syms;
9526 /* Return true iff input section I references the TOC using
9527 instructions limited to +/-32k offsets. */
9530 ppc64_elf_has_small_toc_reloc (asection *i)
9532 return (is_ppc64_elf (i->owner)
9533 && ppc64_elf_tdata (i->owner)->has_small_toc_reloc);
9536 /* Allocate space for one GOT entry. */
9539 allocate_got (struct elf_link_hash_entry *h,
9540 struct bfd_link_info *info,
9541 struct got_entry *gent)
9543 struct ppc_link_hash_table *htab = ppc_hash_table (info);
9544 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
9545 int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
9547 int rentsize = (gent->tls_type & eh->tls_mask & TLS_GD
9548 ? 2 : 1) * sizeof (Elf64_External_Rela);
9549 asection *got = ppc64_elf_tdata (gent->owner)->got;
9551 gent->got.offset = got->size;
9552 got->size += entsize;
9554 if (h->type == STT_GNU_IFUNC)
9556 htab->elf.irelplt->size += rentsize;
9557 htab->got_reli_size += rentsize;
9559 else if (((bfd_link_pic (info)
9560 && !((gent->tls_type & TLS_TPREL) != 0
9561 && bfd_link_executable (info)
9562 && SYMBOL_REFERENCES_LOCAL (info, h)))
9563 || (htab->elf.dynamic_sections_created
9565 && !SYMBOL_REFERENCES_LOCAL (info, h)))
9566 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
9568 asection *relgot = ppc64_elf_tdata (gent->owner)->relgot;
9569 relgot->size += rentsize;
9573 /* This function merges got entries in the same toc group. */
9576 merge_got_entries (struct got_entry **pent)
9578 struct got_entry *ent, *ent2;
9580 for (ent = *pent; ent != NULL; ent = ent->next)
9581 if (!ent->is_indirect)
9582 for (ent2 = ent->next; ent2 != NULL; ent2 = ent2->next)
9583 if (!ent2->is_indirect
9584 && ent2->addend == ent->addend
9585 && ent2->tls_type == ent->tls_type
9586 && elf_gp (ent2->owner) == elf_gp (ent->owner))
9588 ent2->is_indirect = TRUE;
9589 ent2->got.ent = ent;
9593 /* If H is undefined, make it dynamic if that makes sense. */
9596 ensure_undef_dynamic (struct bfd_link_info *info,
9597 struct elf_link_hash_entry *h)
9599 struct elf_link_hash_table *htab = elf_hash_table (info);
9601 if (htab->dynamic_sections_created
9602 && ((info->dynamic_undefined_weak != 0
9603 && h->root.type == bfd_link_hash_undefweak)
9604 || h->root.type == bfd_link_hash_undefined)
9607 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
9608 return bfd_elf_link_record_dynamic_symbol (info, h);
9612 /* Allocate space in .plt, .got and associated reloc sections for
9616 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
9618 struct bfd_link_info *info;
9619 struct ppc_link_hash_table *htab;
9621 struct ppc_link_hash_entry *eh;
9622 struct got_entry **pgent, *gent;
9624 if (h->root.type == bfd_link_hash_indirect)
9627 info = (struct bfd_link_info *) inf;
9628 htab = ppc_hash_table (info);
9632 eh = (struct ppc_link_hash_entry *) h;
9633 /* Run through the TLS GD got entries first if we're changing them
9635 if ((eh->tls_mask & TLS_TPRELGD) != 0)
9636 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9637 if (gent->got.refcount > 0
9638 && (gent->tls_type & TLS_GD) != 0)
9640 /* This was a GD entry that has been converted to TPREL. If
9641 there happens to be a TPREL entry we can use that one. */
9642 struct got_entry *ent;
9643 for (ent = h->got.glist; ent != NULL; ent = ent->next)
9644 if (ent->got.refcount > 0
9645 && (ent->tls_type & TLS_TPREL) != 0
9646 && ent->addend == gent->addend
9647 && ent->owner == gent->owner)
9649 gent->got.refcount = 0;
9653 /* If not, then we'll be using our own TPREL entry. */
9654 if (gent->got.refcount != 0)
9655 gent->tls_type = TLS_TLS | TLS_TPREL;
9658 /* Remove any list entry that won't generate a word in the GOT before
9659 we call merge_got_entries. Otherwise we risk merging to empty
9661 pgent = &h->got.glist;
9662 while ((gent = *pgent) != NULL)
9663 if (gent->got.refcount > 0)
9665 if ((gent->tls_type & TLS_LD) != 0
9668 ppc64_tlsld_got (gent->owner)->got.refcount += 1;
9669 *pgent = gent->next;
9672 pgent = &gent->next;
9675 *pgent = gent->next;
9677 if (!htab->do_multi_toc)
9678 merge_got_entries (&h->got.glist);
9680 for (gent = h->got.glist; gent != NULL; gent = gent->next)
9681 if (!gent->is_indirect)
9683 /* Make sure this symbol is output as a dynamic symbol. */
9684 if (!ensure_undef_dynamic (info, h))
9687 if (!is_ppc64_elf (gent->owner))
9690 allocate_got (h, info, gent);
9693 /* If no dynamic sections we can't have dynamic relocs, except for
9694 IFUNCs which are handled even in static executables. */
9695 if (!htab->elf.dynamic_sections_created
9696 && h->type != STT_GNU_IFUNC)
9697 eh->dyn_relocs = NULL;
9699 /* Discard relocs on undefined symbols that must be local. */
9700 else if (h->root.type == bfd_link_hash_undefined
9701 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9702 eh->dyn_relocs = NULL;
9704 /* Also discard relocs on undefined weak syms with non-default
9705 visibility, or when dynamic_undefined_weak says so. */
9706 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
9707 eh->dyn_relocs = NULL;
9709 if (eh->dyn_relocs != NULL)
9711 struct elf_dyn_relocs *p, **pp;
9713 /* In the shared -Bsymbolic case, discard space allocated for
9714 dynamic pc-relative relocs against symbols which turn out to
9715 be defined in regular objects. For the normal shared case,
9716 discard space for relocs that have become local due to symbol
9717 visibility changes. */
9719 if (bfd_link_pic (info))
9721 /* Relocs that use pc_count are those that appear on a call
9722 insn, or certain REL relocs (see must_be_dyn_reloc) that
9723 can be generated via assembly. We want calls to
9724 protected symbols to resolve directly to the function
9725 rather than going via the plt. If people want function
9726 pointer comparisons to work as expected then they should
9727 avoid writing weird assembly. */
9728 if (SYMBOL_CALLS_LOCAL (info, h))
9730 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
9732 p->count -= p->pc_count;
9741 if (eh->dyn_relocs != NULL)
9743 /* Make sure this symbol is output as a dynamic symbol. */
9744 if (!ensure_undef_dynamic (info, h))
9748 else if (ELIMINATE_COPY_RELOCS && h->type != STT_GNU_IFUNC)
9750 /* For the non-pic case, discard space for relocs against
9751 symbols which turn out to need copy relocs or are not
9753 if (h->dynamic_adjusted
9755 && !ELF_COMMON_DEF_P (h))
9757 /* Make sure this symbol is output as a dynamic symbol. */
9758 if (!ensure_undef_dynamic (info, h))
9761 if (h->dynindx == -1)
9762 eh->dyn_relocs = NULL;
9765 eh->dyn_relocs = NULL;
9768 /* Finally, allocate space. */
9769 for (p = eh->dyn_relocs; p != NULL; p = p->next)
9771 asection *sreloc = elf_section_data (p->sec)->sreloc;
9772 if (eh->elf.type == STT_GNU_IFUNC)
9773 sreloc = htab->elf.irelplt;
9774 sreloc->size += p->count * sizeof (Elf64_External_Rela);
9778 if ((htab->elf.dynamic_sections_created
9779 && h->dynindx != -1)
9780 || h->type == STT_GNU_IFUNC)
9782 struct plt_entry *pent;
9783 bfd_boolean doneone = FALSE;
9784 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
9785 if (pent->plt.refcount > 0)
9787 if (!htab->elf.dynamic_sections_created
9788 || h->dynindx == -1)
9791 pent->plt.offset = s->size;
9792 s->size += PLT_ENTRY_SIZE (htab);
9793 s = htab->elf.irelplt;
9797 /* If this is the first .plt entry, make room for the special
9801 s->size += PLT_INITIAL_ENTRY_SIZE (htab);
9803 pent->plt.offset = s->size;
9805 /* Make room for this entry. */
9806 s->size += PLT_ENTRY_SIZE (htab);
9808 /* Make room for the .glink code. */
9811 s->size += GLINK_PLTRESOLVE_SIZE (htab);
9814 /* We need bigger stubs past index 32767. */
9815 if (s->size >= GLINK_PLTRESOLVE_SIZE (htab) + 32768*2*4)
9822 /* We also need to make an entry in the .rela.plt section. */
9823 s = htab->elf.srelplt;
9825 s->size += sizeof (Elf64_External_Rela);
9829 pent->plt.offset = (bfd_vma) -1;
9832 h->plt.plist = NULL;
9838 h->plt.plist = NULL;
9845 #define PPC_LO(v) ((v) & 0xffff)
9846 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9847 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9849 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9850 to set up space for global entry stubs. These are put in glink,
9851 after the branch table. */
9854 size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
9856 struct bfd_link_info *info;
9857 struct ppc_link_hash_table *htab;
9858 struct plt_entry *pent;
9861 if (h->root.type == bfd_link_hash_indirect)
9864 if (!h->pointer_equality_needed)
9871 htab = ppc_hash_table (info);
9875 s = htab->global_entry;
9876 plt = htab->elf.splt;
9877 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
9878 if (pent->plt.offset != (bfd_vma) -1
9879 && pent->addend == 0)
9881 /* For ELFv2, if this symbol is not defined in a regular file
9882 and we are not generating a shared library or pie, then we
9883 need to define the symbol in the executable on a call stub.
9884 This is to avoid text relocations. */
9885 bfd_vma off, stub_align, stub_off, stub_size;
9886 unsigned int align_power;
9889 if (!htab->params->speculate_indirect_jumps)
9892 if (htab->params->plt_stub_align >= 0)
9893 align_power = htab->params->plt_stub_align;
9895 align_power = -htab->params->plt_stub_align;
9896 /* Setting section alignment is delayed until we know it is
9897 non-empty. Otherwise the .text output section will be
9898 aligned at least to plt_stub_align even when no global
9899 entry stubs are needed. */
9900 if (s->alignment_power < align_power)
9901 s->alignment_power = align_power;
9902 stub_align = (bfd_vma) 1 << align_power;
9903 if (htab->params->plt_stub_align >= 0
9904 || ((((stub_off + stub_size - 1) & -stub_align)
9905 - (stub_off & -stub_align))
9906 > ((stub_size - 1) & -stub_align)))
9907 stub_off = (stub_off + stub_align - 1) & -stub_align;
9908 off = pent->plt.offset + plt->output_offset + plt->output_section->vma;
9909 off -= stub_off + s->output_offset + s->output_section->vma;
9910 /* Note that for --plt-stub-align negative we have a possible
9911 dependency between stub offset and size. Break that
9912 dependency by assuming the max stub size when calculating
9914 if (PPC_HA (off) == 0)
9916 h->root.type = bfd_link_hash_defined;
9917 h->root.u.def.section = s;
9918 h->root.u.def.value = stub_off;
9919 s->size = stub_off + stub_size;
9925 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9926 read-only sections. */
9929 maybe_set_textrel (struct elf_link_hash_entry *h, void *inf)
9933 if (h->root.type == bfd_link_hash_indirect)
9936 sec = readonly_dynrelocs (h);
9939 struct bfd_link_info *info = (struct bfd_link_info *) inf;
9941 info->flags |= DF_TEXTREL;
9942 info->callbacks->minfo
9943 (_("%B: dynamic relocation against `%T' in read-only section `%A'\n"),
9944 sec->owner, h->root.root.string, sec);
9946 /* Not an error, just cut short the traversal. */
9952 /* Set the sizes of the dynamic sections. */
9955 ppc64_elf_size_dynamic_sections (bfd *output_bfd,
9956 struct bfd_link_info *info)
9958 struct ppc_link_hash_table *htab;
9963 struct got_entry *first_tlsld;
9965 htab = ppc_hash_table (info);
9969 dynobj = htab->elf.dynobj;
9973 if (htab->elf.dynamic_sections_created)
9975 /* Set the contents of the .interp section to the interpreter. */
9976 if (bfd_link_executable (info) && !info->nointerp)
9978 s = bfd_get_linker_section (dynobj, ".interp");
9981 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
9982 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
9986 /* Set up .got offsets for local syms, and space for local dynamic
9988 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
9990 struct got_entry **lgot_ents;
9991 struct got_entry **end_lgot_ents;
9992 struct plt_entry **local_plt;
9993 struct plt_entry **end_local_plt;
9994 unsigned char *lgot_masks;
9995 bfd_size_type locsymcount;
9996 Elf_Internal_Shdr *symtab_hdr;
9998 if (!is_ppc64_elf (ibfd))
10001 for (s = ibfd->sections; s != NULL; s = s->next)
10003 struct ppc_dyn_relocs *p;
10005 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10007 if (!bfd_is_abs_section (p->sec)
10008 && bfd_is_abs_section (p->sec->output_section))
10010 /* Input section has been discarded, either because
10011 it is a copy of a linkonce section or due to
10012 linker script /DISCARD/, so we'll be discarding
10015 else if (p->count != 0)
10017 asection *srel = elf_section_data (p->sec)->sreloc;
10019 srel = htab->elf.irelplt;
10020 srel->size += p->count * sizeof (Elf64_External_Rela);
10021 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
10022 info->flags |= DF_TEXTREL;
10027 lgot_ents = elf_local_got_ents (ibfd);
10031 symtab_hdr = &elf_symtab_hdr (ibfd);
10032 locsymcount = symtab_hdr->sh_info;
10033 end_lgot_ents = lgot_ents + locsymcount;
10034 local_plt = (struct plt_entry **) end_lgot_ents;
10035 end_local_plt = local_plt + locsymcount;
10036 lgot_masks = (unsigned char *) end_local_plt;
10037 s = ppc64_elf_tdata (ibfd)->got;
10038 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
10040 struct got_entry **pent, *ent;
10043 while ((ent = *pent) != NULL)
10044 if (ent->got.refcount > 0)
10046 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
10048 ppc64_tlsld_got (ibfd)->got.refcount += 1;
10053 unsigned int ent_size = 8;
10054 unsigned int rel_size = sizeof (Elf64_External_Rela);
10056 ent->got.offset = s->size;
10057 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
10062 s->size += ent_size;
10063 if ((*lgot_masks & PLT_IFUNC) != 0)
10065 htab->elf.irelplt->size += rel_size;
10066 htab->got_reli_size += rel_size;
10068 else if (bfd_link_pic (info)
10069 && !((ent->tls_type & TLS_TPREL) != 0
10070 && bfd_link_executable (info)))
10072 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
10073 srel->size += rel_size;
10082 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
10083 for (; local_plt < end_local_plt; ++local_plt)
10085 struct plt_entry *ent;
10087 for (ent = *local_plt; ent != NULL; ent = ent->next)
10088 if (ent->plt.refcount > 0)
10090 s = htab->elf.iplt;
10091 ent->plt.offset = s->size;
10092 s->size += PLT_ENTRY_SIZE (htab);
10094 htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
10097 ent->plt.offset = (bfd_vma) -1;
10101 /* Allocate global sym .plt and .got entries, and space for global
10102 sym dynamic relocs. */
10103 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
10105 if (!htab->opd_abi && !bfd_link_pic (info))
10106 elf_link_hash_traverse (&htab->elf, size_global_entry_stubs, info);
10108 first_tlsld = NULL;
10109 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
10111 struct got_entry *ent;
10113 if (!is_ppc64_elf (ibfd))
10116 ent = ppc64_tlsld_got (ibfd);
10117 if (ent->got.refcount > 0)
10119 if (!htab->do_multi_toc && first_tlsld != NULL)
10121 ent->is_indirect = TRUE;
10122 ent->got.ent = first_tlsld;
10126 if (first_tlsld == NULL)
10128 s = ppc64_elf_tdata (ibfd)->got;
10129 ent->got.offset = s->size;
10132 if (bfd_link_pic (info))
10134 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
10135 srel->size += sizeof (Elf64_External_Rela);
10140 ent->got.offset = (bfd_vma) -1;
10143 /* We now have determined the sizes of the various dynamic sections.
10144 Allocate memory for them. */
10146 for (s = dynobj->sections; s != NULL; s = s->next)
10148 if ((s->flags & SEC_LINKER_CREATED) == 0)
10151 if (s == htab->brlt || s == htab->relbrlt)
10152 /* These haven't been allocated yet; don't strip. */
10154 else if (s == htab->elf.sgot
10155 || s == htab->elf.splt
10156 || s == htab->elf.iplt
10157 || s == htab->glink
10158 || s == htab->global_entry
10159 || s == htab->elf.sdynbss
10160 || s == htab->elf.sdynrelro)
10162 /* Strip this section if we don't need it; see the
10165 else if (s == htab->glink_eh_frame)
10167 if (!bfd_is_abs_section (s->output_section))
10168 /* Not sized yet. */
10171 else if (CONST_STRNEQ (s->name, ".rela"))
10175 if (s != htab->elf.srelplt)
10178 /* We use the reloc_count field as a counter if we need
10179 to copy relocs into the output file. */
10180 s->reloc_count = 0;
10185 /* It's not one of our sections, so don't allocate space. */
10191 /* If we don't need this section, strip it from the
10192 output file. This is mostly to handle .rela.bss and
10193 .rela.plt. We must create both sections in
10194 create_dynamic_sections, because they must be created
10195 before the linker maps input sections to output
10196 sections. The linker does that before
10197 adjust_dynamic_symbol is called, and it is that
10198 function which decides whether anything needs to go
10199 into these sections. */
10200 s->flags |= SEC_EXCLUDE;
10204 if (bfd_is_abs_section (s->output_section))
10205 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10208 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10211 /* Allocate memory for the section contents. We use bfd_zalloc
10212 here in case unused entries are not reclaimed before the
10213 section's contents are written out. This should not happen,
10214 but this way if it does we get a R_PPC64_NONE reloc in .rela
10215 sections instead of garbage.
10216 We also rely on the section contents being zero when writing
10217 the GOT and .dynrelro. */
10218 s->contents = bfd_zalloc (dynobj, s->size);
10219 if (s->contents == NULL)
10223 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
10225 if (!is_ppc64_elf (ibfd))
10228 s = ppc64_elf_tdata (ibfd)->got;
10229 if (s != NULL && s != htab->elf.sgot)
10232 s->flags |= SEC_EXCLUDE;
10235 s->contents = bfd_zalloc (ibfd, s->size);
10236 if (s->contents == NULL)
10240 s = ppc64_elf_tdata (ibfd)->relgot;
10244 s->flags |= SEC_EXCLUDE;
10247 s->contents = bfd_zalloc (ibfd, s->size);
10248 if (s->contents == NULL)
10251 s->reloc_count = 0;
10256 if (htab->elf.dynamic_sections_created)
10258 bfd_boolean tls_opt;
10260 /* Add some entries to the .dynamic section. We fill in the
10261 values later, in ppc64_elf_finish_dynamic_sections, but we
10262 must add the entries now so that we get the correct size for
10263 the .dynamic section. The DT_DEBUG entry is filled in by the
10264 dynamic linker and used by the debugger. */
10265 #define add_dynamic_entry(TAG, VAL) \
10266 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10268 if (bfd_link_executable (info))
10270 if (!add_dynamic_entry (DT_DEBUG, 0))
10274 if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
10276 if (!add_dynamic_entry (DT_PLTGOT, 0)
10277 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10278 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
10279 || !add_dynamic_entry (DT_JMPREL, 0)
10280 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
10284 if (NO_OPD_RELOCS && abiversion (output_bfd) <= 1)
10286 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
10287 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
10291 tls_opt = (htab->params->tls_get_addr_opt
10292 && htab->tls_get_addr_fd != NULL
10293 && htab->tls_get_addr_fd->elf.plt.plist != NULL);
10294 if (tls_opt || !htab->opd_abi)
10296 if (!add_dynamic_entry (DT_PPC64_OPT, tls_opt ? PPC64_OPT_TLS : 0))
10302 if (!add_dynamic_entry (DT_RELA, 0)
10303 || !add_dynamic_entry (DT_RELASZ, 0)
10304 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
10307 /* If any dynamic relocs apply to a read-only section,
10308 then we need a DT_TEXTREL entry. */
10309 if ((info->flags & DF_TEXTREL) == 0)
10310 elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
10312 if ((info->flags & DF_TEXTREL) != 0)
10314 if (!add_dynamic_entry (DT_TEXTREL, 0))
10319 #undef add_dynamic_entry
10324 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10327 ppc64_elf_hash_symbol (struct elf_link_hash_entry *h)
10329 if (h->plt.plist != NULL
10331 && !h->pointer_equality_needed)
10334 return _bfd_elf_hash_symbol (h);
10337 /* Determine the type of stub needed, if any, for a call. */
10339 static inline enum ppc_stub_type
10340 ppc_type_of_stub (asection *input_sec,
10341 const Elf_Internal_Rela *rel,
10342 struct ppc_link_hash_entry **hash,
10343 struct plt_entry **plt_ent,
10344 bfd_vma destination,
10345 unsigned long local_off)
10347 struct ppc_link_hash_entry *h = *hash;
10349 bfd_vma branch_offset;
10350 bfd_vma max_branch_offset;
10351 enum elf_ppc64_reloc_type r_type;
10355 struct plt_entry *ent;
10356 struct ppc_link_hash_entry *fdh = h;
10358 && h->oh->is_func_descriptor)
10360 fdh = ppc_follow_link (h->oh);
10364 for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
10365 if (ent->addend == rel->r_addend
10366 && ent->plt.offset != (bfd_vma) -1)
10369 return ppc_stub_plt_call;
10372 /* Here, we know we don't have a plt entry. If we don't have a
10373 either a defined function descriptor or a defined entry symbol
10374 in a regular object file, then it is pointless trying to make
10375 any other type of stub. */
10376 if (!is_static_defined (&fdh->elf)
10377 && !is_static_defined (&h->elf))
10378 return ppc_stub_none;
10380 else if (elf_local_got_ents (input_sec->owner) != NULL)
10382 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner);
10383 struct plt_entry **local_plt = (struct plt_entry **)
10384 elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info;
10385 unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
10387 if (local_plt[r_symndx] != NULL)
10389 struct plt_entry *ent;
10391 for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next)
10392 if (ent->addend == rel->r_addend
10393 && ent->plt.offset != (bfd_vma) -1)
10396 return ppc_stub_plt_call;
10401 /* Determine where the call point is. */
10402 location = (input_sec->output_offset
10403 + input_sec->output_section->vma
10406 branch_offset = destination - location;
10407 r_type = ELF64_R_TYPE (rel->r_info);
10409 /* Determine if a long branch stub is needed. */
10410 max_branch_offset = 1 << 25;
10411 if (r_type != R_PPC64_REL24)
10412 max_branch_offset = 1 << 15;
10414 if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
10415 /* We need a stub. Figure out whether a long_branch or plt_branch
10416 is needed later. */
10417 return ppc_stub_long_branch;
10419 return ppc_stub_none;
10422 /* With power7 weakly ordered memory model, it is possible for ld.so
10423 to update a plt entry in one thread and have another thread see a
10424 stale zero toc entry. To avoid this we need some sort of acquire
10425 barrier in the call stub. One solution is to make the load of the
10426 toc word seem to appear to depend on the load of the function entry
10427 word. Another solution is to test for r2 being zero, and branch to
10428 the appropriate glink entry if so.
10430 . fake dep barrier compare
10431 . ld 12,xxx(2) ld 12,xxx(2)
10432 . mtctr 12 mtctr 12
10433 . xor 11,12,12 ld 2,xxx+8(2)
10434 . add 2,2,11 cmpldi 2,0
10435 . ld 2,xxx+8(2) bnectr+
10436 . bctr b <glink_entry>
10438 The solution involving the compare turns out to be faster, so
10439 that's what we use unless the branch won't reach. */
10441 #define ALWAYS_USE_FAKE_DEP 0
10442 #define ALWAYS_EMIT_R2SAVE 0
10444 static inline unsigned int
10445 plt_stub_size (struct ppc_link_hash_table *htab,
10446 struct ppc_stub_hash_entry *stub_entry,
10449 unsigned size = 12;
10451 if (ALWAYS_EMIT_R2SAVE
10452 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10454 if (PPC_HA (off) != 0)
10456 if (!htab->params->speculate_indirect_jumps)
10461 if (htab->params->plt_static_chain)
10463 if (htab->params->plt_thread_safe
10464 && htab->elf.dynamic_sections_created
10465 && stub_entry->h != NULL
10466 && stub_entry->h->elf.dynindx != -1)
10468 if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain) != PPC_HA (off))
10471 if (stub_entry->h != NULL
10472 && (stub_entry->h == htab->tls_get_addr_fd
10473 || stub_entry->h == htab->tls_get_addr)
10474 && htab->params->tls_get_addr_opt)
10477 if (ALWAYS_EMIT_R2SAVE
10478 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10481 if (!htab->params->speculate_indirect_jumps)
10488 /* Depending on the sign of plt_stub_align:
10489 If positive, return the padding to align to a 2**plt_stub_align
10491 If negative, if this stub would cross fewer 2**plt_stub_align
10492 boundaries if we align, then return the padding needed to do so. */
10494 static inline unsigned int
10495 plt_stub_pad (struct ppc_link_hash_table *htab,
10496 struct ppc_stub_hash_entry *stub_entry,
10500 unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
10501 bfd_vma stub_off = stub_entry->group->stub_sec->size;
10503 if (htab->params->plt_stub_align >= 0)
10505 stub_align = 1 << htab->params->plt_stub_align;
10506 if ((stub_off & (stub_align - 1)) != 0)
10507 return stub_align - (stub_off & (stub_align - 1));
10511 stub_align = 1 << -htab->params->plt_stub_align;
10512 if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
10513 > ((stub_size - 1) & -stub_align))
10514 return stub_align - (stub_off & (stub_align - 1));
10518 static inline bfd_byte *
10519 output_bctr (struct ppc_link_hash_table *htab, bfd *obfd, bfd_byte *p)
10521 if (!htab->params->speculate_indirect_jumps)
10523 bfd_put_32 (obfd, CRSETEQ, p);
10525 bfd_put_32 (obfd, BEQCTRM, p);
10527 bfd_put_32 (obfd, B_DOT, p);
10532 bfd_put_32 (obfd, BCTR, p);
10538 /* Build a .plt call stub. */
10540 static inline bfd_byte *
10541 build_plt_stub (struct ppc_link_hash_table *htab,
10542 struct ppc_stub_hash_entry *stub_entry,
10543 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10545 bfd *obfd = htab->params->stub_bfd;
10546 bfd_boolean plt_load_toc = htab->opd_abi;
10547 bfd_boolean plt_static_chain = htab->params->plt_static_chain;
10548 bfd_boolean plt_thread_safe = (htab->params->plt_thread_safe
10549 && htab->elf.dynamic_sections_created
10550 && stub_entry->h != NULL
10551 && stub_entry->h->elf.dynindx != -1);
10552 bfd_boolean use_fake_dep = plt_thread_safe;
10553 bfd_vma cmp_branch_off = 0;
10555 if (!ALWAYS_USE_FAKE_DEP
10558 && htab->params->speculate_indirect_jumps
10559 && !((stub_entry->h == htab->tls_get_addr_fd
10560 || stub_entry->h == htab->tls_get_addr)
10561 && htab->params->tls_get_addr_opt))
10563 bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
10564 bfd_vma pltindex = ((pltoff - PLT_INITIAL_ENTRY_SIZE (htab))
10565 / PLT_ENTRY_SIZE (htab));
10566 bfd_vma glinkoff = GLINK_PLTRESOLVE_SIZE (htab) + pltindex * 8;
10569 if (pltindex > 32768)
10570 glinkoff += (pltindex - 32768) * 4;
10572 + htab->glink->output_offset
10573 + htab->glink->output_section->vma);
10574 from = (p - stub_entry->group->stub_sec->contents
10575 + 4 * (ALWAYS_EMIT_R2SAVE
10576 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10577 + 4 * (PPC_HA (offset) != 0)
10578 + 4 * (PPC_HA (offset + 8 + 8 * plt_static_chain)
10579 != PPC_HA (offset))
10580 + 4 * (plt_static_chain != 0)
10582 + stub_entry->group->stub_sec->output_offset
10583 + stub_entry->group->stub_sec->output_section->vma);
10584 cmp_branch_off = to - from;
10585 use_fake_dep = cmp_branch_off + (1 << 25) >= (1 << 26);
10588 if (PPC_HA (offset) != 0)
10592 if (ALWAYS_EMIT_R2SAVE
10593 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10594 r[0].r_offset += 4;
10595 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
10596 r[1].r_offset = r[0].r_offset + 4;
10597 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10598 r[1].r_addend = r[0].r_addend;
10601 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10603 r[2].r_offset = r[1].r_offset + 4;
10604 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO);
10605 r[2].r_addend = r[0].r_addend;
10609 r[2].r_offset = r[1].r_offset + 8 + 8 * use_fake_dep;
10610 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10611 r[2].r_addend = r[0].r_addend + 8;
10612 if (plt_static_chain)
10614 r[3].r_offset = r[2].r_offset + 4;
10615 r[3].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
10616 r[3].r_addend = r[0].r_addend + 16;
10621 if (ALWAYS_EMIT_R2SAVE
10622 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10623 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10626 bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
10627 bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
10631 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
10632 bfd_put_32 (obfd, LD_R12_0R12 | PPC_LO (offset), p), p += 4;
10635 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10637 bfd_put_32 (obfd, ADDI_R11_R11 | PPC_LO (offset), p), p += 4;
10640 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10645 bfd_put_32 (obfd, XOR_R2_R12_R12, p), p += 4;
10646 bfd_put_32 (obfd, ADD_R11_R11_R2, p), p += 4;
10648 bfd_put_32 (obfd, LD_R2_0R11 | PPC_LO (offset + 8), p), p += 4;
10649 if (plt_static_chain)
10650 bfd_put_32 (obfd, LD_R11_0R11 | PPC_LO (offset + 16), p), p += 4;
10657 if (ALWAYS_EMIT_R2SAVE
10658 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10659 r[0].r_offset += 4;
10660 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10663 if (PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10665 r[1].r_offset = r[0].r_offset + 4;
10666 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16);
10667 r[1].r_addend = r[0].r_addend;
10671 r[1].r_offset = r[0].r_offset + 8 + 8 * use_fake_dep;
10672 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10673 r[1].r_addend = r[0].r_addend + 8 + 8 * plt_static_chain;
10674 if (plt_static_chain)
10676 r[2].r_offset = r[1].r_offset + 4;
10677 r[2].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
10678 r[2].r_addend = r[0].r_addend + 8;
10683 if (ALWAYS_EMIT_R2SAVE
10684 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
10685 bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
10686 bfd_put_32 (obfd, LD_R12_0R2 | PPC_LO (offset), p), p += 4;
10688 && PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
10690 bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4;
10693 bfd_put_32 (obfd, MTCTR_R12, p), p += 4;
10698 bfd_put_32 (obfd, XOR_R11_R12_R12, p), p += 4;
10699 bfd_put_32 (obfd, ADD_R2_R2_R11, p), p += 4;
10701 if (plt_static_chain)
10702 bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4;
10703 bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4;
10706 if (plt_load_toc && plt_thread_safe && !use_fake_dep)
10708 bfd_put_32 (obfd, CMPLDI_R2_0, p), p += 4;
10709 bfd_put_32 (obfd, BNECTR_P4, p), p += 4;
10710 bfd_put_32 (obfd, B_DOT | (cmp_branch_off & 0x3fffffc), p), p += 4;
10713 p = output_bctr (htab, obfd, p);
10717 /* Build a special .plt call stub for __tls_get_addr. */
10719 #define LD_R11_0R3 0xe9630000
10720 #define LD_R12_0R3 0xe9830000
10721 #define MR_R0_R3 0x7c601b78
10722 #define CMPDI_R11_0 0x2c2b0000
10723 #define ADD_R3_R12_R13 0x7c6c6a14
10724 #define BEQLR 0x4d820020
10725 #define MR_R3_R0 0x7c030378
10726 #define STD_R11_0R1 0xf9610000
10727 #define BCTRL 0x4e800421
10728 #define LD_R11_0R1 0xe9610000
10729 #define MTLR_R11 0x7d6803a6
10731 static inline bfd_byte *
10732 build_tls_get_addr_stub (struct ppc_link_hash_table *htab,
10733 struct ppc_stub_hash_entry *stub_entry,
10734 bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
10736 bfd *obfd = htab->params->stub_bfd;
10738 bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
10739 bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
10740 bfd_put_32 (obfd, MR_R0_R3, p), p += 4;
10741 bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4;
10742 bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4;
10743 bfd_put_32 (obfd, BEQLR, p), p += 4;
10744 bfd_put_32 (obfd, MR_R3_R0, p), p += 4;
10746 r[0].r_offset += 7 * 4;
10747 if (!ALWAYS_EMIT_R2SAVE
10748 && stub_entry->stub_type != ppc_stub_plt_call_r2save)
10749 return build_plt_stub (htab, stub_entry, p, offset, r);
10751 bfd_put_32 (obfd, MFLR_R11, p), p += 4;
10752 bfd_put_32 (obfd, STD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10755 r[0].r_offset += 2 * 4;
10756 p = build_plt_stub (htab, stub_entry, p, offset, r);
10757 if (!htab->params->speculate_indirect_jumps)
10760 bfd_put_32 (obfd, BEQCTRLM, p - 4);
10763 bfd_put_32 (obfd, BCTRL, p - 4);
10765 bfd_put_32 (obfd, LD_R2_0R1 + STK_TOC (htab), p), p += 4;
10766 bfd_put_32 (obfd, LD_R11_0R1 + STK_LINKER (htab), p), p += 4;
10767 bfd_put_32 (obfd, MTLR_R11, p), p += 4;
10768 bfd_put_32 (obfd, BLR, p), p += 4;
10773 static Elf_Internal_Rela *
10774 get_relocs (asection *sec, int count)
10776 Elf_Internal_Rela *relocs;
10777 struct bfd_elf_section_data *elfsec_data;
10779 elfsec_data = elf_section_data (sec);
10780 relocs = elfsec_data->relocs;
10781 if (relocs == NULL)
10783 bfd_size_type relsize;
10784 relsize = sec->reloc_count * sizeof (*relocs);
10785 relocs = bfd_alloc (sec->owner, relsize);
10786 if (relocs == NULL)
10788 elfsec_data->relocs = relocs;
10789 elfsec_data->rela.hdr = bfd_zalloc (sec->owner,
10790 sizeof (Elf_Internal_Shdr));
10791 if (elfsec_data->rela.hdr == NULL)
10793 elfsec_data->rela.hdr->sh_size = (sec->reloc_count
10794 * sizeof (Elf64_External_Rela));
10795 elfsec_data->rela.hdr->sh_entsize = sizeof (Elf64_External_Rela);
10796 sec->reloc_count = 0;
10798 relocs += sec->reloc_count;
10799 sec->reloc_count += count;
10804 get_r2off (struct bfd_link_info *info,
10805 struct ppc_stub_hash_entry *stub_entry)
10807 struct ppc_link_hash_table *htab = ppc_hash_table (info);
10808 bfd_vma r2off = htab->sec_info[stub_entry->target_section->id].toc_off;
10812 /* Support linking -R objects. Get the toc pointer from the
10815 if (!htab->opd_abi)
10817 asection *opd = stub_entry->h->elf.root.u.def.section;
10818 bfd_vma opd_off = stub_entry->h->elf.root.u.def.value;
10820 if (strcmp (opd->name, ".opd") != 0
10821 || opd->reloc_count != 0)
10823 info->callbacks->einfo (_("%P: cannot find opd entry toc for `%T'\n"),
10824 stub_entry->h->elf.root.root.string);
10825 bfd_set_error (bfd_error_bad_value);
10826 return (bfd_vma) -1;
10828 if (!bfd_get_section_contents (opd->owner, opd, buf, opd_off + 8, 8))
10829 return (bfd_vma) -1;
10830 r2off = bfd_get_64 (opd->owner, buf);
10831 r2off -= elf_gp (info->output_bfd);
10833 r2off -= htab->sec_info[stub_entry->group->link_sec->id].toc_off;
10838 ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
10840 struct ppc_stub_hash_entry *stub_entry;
10841 struct ppc_branch_hash_entry *br_entry;
10842 struct bfd_link_info *info;
10843 struct ppc_link_hash_table *htab;
10847 Elf_Internal_Rela *r;
10850 /* Massage our args to the form they really have. */
10851 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
10854 htab = ppc_hash_table (info);
10858 /* Make a note of the offset within the stubs for this entry. */
10859 stub_entry->stub_offset = stub_entry->group->stub_sec->size;
10860 loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset;
10862 htab->stub_count[stub_entry->stub_type - 1] += 1;
10863 switch (stub_entry->stub_type)
10865 case ppc_stub_long_branch:
10866 case ppc_stub_long_branch_r2off:
10867 /* Branches are relative. This is where we are going to. */
10868 dest = (stub_entry->target_value
10869 + stub_entry->target_section->output_offset
10870 + stub_entry->target_section->output_section->vma);
10871 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10874 /* And this is where we are coming from. */
10875 off -= (stub_entry->stub_offset
10876 + stub_entry->group->stub_sec->output_offset
10877 + stub_entry->group->stub_sec->output_section->vma);
10880 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
10882 bfd_vma r2off = get_r2off (info, stub_entry);
10884 if (r2off == (bfd_vma) -1)
10886 htab->stub_error = TRUE;
10889 bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
10891 if (PPC_HA (r2off) != 0)
10893 bfd_put_32 (htab->params->stub_bfd,
10894 ADDIS_R2_R2 | PPC_HA (r2off), p);
10897 if (PPC_LO (r2off) != 0)
10899 bfd_put_32 (htab->params->stub_bfd,
10900 ADDI_R2_R2 | PPC_LO (r2off), p);
10905 bfd_put_32 (htab->params->stub_bfd, B_DOT | (off & 0x3fffffc), p);
10908 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
10910 info->callbacks->einfo
10911 (_("%P: long branch stub `%s' offset overflow\n"),
10912 stub_entry->root.string);
10913 htab->stub_error = TRUE;
10917 if (info->emitrelocations)
10919 r = get_relocs (stub_entry->group->stub_sec, 1);
10922 r->r_offset = p - 4 - stub_entry->group->stub_sec->contents;
10923 r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
10924 r->r_addend = dest;
10925 if (stub_entry->h != NULL)
10927 struct elf_link_hash_entry **hashes;
10928 unsigned long symndx;
10929 struct ppc_link_hash_entry *h;
10931 hashes = elf_sym_hashes (htab->params->stub_bfd);
10932 if (hashes == NULL)
10934 bfd_size_type hsize;
10936 hsize = (htab->stub_globals + 1) * sizeof (*hashes);
10937 hashes = bfd_zalloc (htab->params->stub_bfd, hsize);
10938 if (hashes == NULL)
10940 elf_sym_hashes (htab->params->stub_bfd) = hashes;
10941 htab->stub_globals = 1;
10943 symndx = htab->stub_globals++;
10945 hashes[symndx] = &h->elf;
10946 r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
10947 if (h->oh != NULL && h->oh->is_func)
10948 h = ppc_follow_link (h->oh);
10949 if (h->elf.root.u.def.section != stub_entry->target_section)
10950 /* H is an opd symbol. The addend must be zero. */
10954 off = (h->elf.root.u.def.value
10955 + h->elf.root.u.def.section->output_offset
10956 + h->elf.root.u.def.section->output_section->vma);
10957 r->r_addend -= off;
10963 case ppc_stub_plt_branch:
10964 case ppc_stub_plt_branch_r2off:
10965 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
10966 stub_entry->root.string + 9,
10968 if (br_entry == NULL)
10970 info->callbacks->einfo (_("%P: can't find branch stub `%s'\n"),
10971 stub_entry->root.string);
10972 htab->stub_error = TRUE;
10976 dest = (stub_entry->target_value
10977 + stub_entry->target_section->output_offset
10978 + stub_entry->target_section->output_section->vma);
10979 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
10980 dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
10982 bfd_put_64 (htab->brlt->owner, dest,
10983 htab->brlt->contents + br_entry->offset);
10985 if (br_entry->iter == htab->stub_iteration)
10987 br_entry->iter = 0;
10989 if (htab->relbrlt != NULL)
10991 /* Create a reloc for the branch lookup table entry. */
10992 Elf_Internal_Rela rela;
10995 rela.r_offset = (br_entry->offset
10996 + htab->brlt->output_offset
10997 + htab->brlt->output_section->vma);
10998 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
10999 rela.r_addend = dest;
11001 rl = htab->relbrlt->contents;
11002 rl += (htab->relbrlt->reloc_count++
11003 * sizeof (Elf64_External_Rela));
11004 bfd_elf64_swap_reloca_out (htab->relbrlt->owner, &rela, rl);
11006 else if (info->emitrelocations)
11008 r = get_relocs (htab->brlt, 1);
11011 /* brlt, being SEC_LINKER_CREATED does not go through the
11012 normal reloc processing. Symbols and offsets are not
11013 translated from input file to output file form, so
11014 set up the offset per the output file. */
11015 r->r_offset = (br_entry->offset
11016 + htab->brlt->output_offset
11017 + htab->brlt->output_section->vma);
11018 r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
11019 r->r_addend = dest;
11023 dest = (br_entry->offset
11024 + htab->brlt->output_offset
11025 + htab->brlt->output_section->vma);
11028 - elf_gp (info->output_bfd)
11029 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11031 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
11033 info->callbacks->einfo
11034 (_("%P: linkage table error against `%T'\n"),
11035 stub_entry->root.string);
11036 bfd_set_error (bfd_error_bad_value);
11037 htab->stub_error = TRUE;
11041 if (info->emitrelocations)
11043 r = get_relocs (stub_entry->group->stub_sec, 1 + (PPC_HA (off) != 0));
11046 r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
11047 if (bfd_big_endian (info->output_bfd))
11048 r[0].r_offset += 2;
11049 if (stub_entry->stub_type == ppc_stub_plt_branch_r2off)
11050 r[0].r_offset += 4;
11051 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
11052 r[0].r_addend = dest;
11053 if (PPC_HA (off) != 0)
11055 r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
11056 r[1].r_offset = r[0].r_offset + 4;
11057 r[1].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS);
11058 r[1].r_addend = r[0].r_addend;
11063 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
11065 if (PPC_HA (off) != 0)
11067 bfd_put_32 (htab->params->stub_bfd,
11068 ADDIS_R12_R2 | PPC_HA (off), p);
11070 bfd_put_32 (htab->params->stub_bfd,
11071 LD_R12_0R12 | PPC_LO (off), p);
11074 bfd_put_32 (htab->params->stub_bfd,
11075 LD_R12_0R2 | PPC_LO (off), p);
11079 bfd_vma r2off = get_r2off (info, stub_entry);
11081 if (r2off == (bfd_vma) -1)
11083 htab->stub_error = TRUE;
11087 bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
11089 if (PPC_HA (off) != 0)
11091 bfd_put_32 (htab->params->stub_bfd,
11092 ADDIS_R12_R2 | PPC_HA (off), p);
11094 bfd_put_32 (htab->params->stub_bfd,
11095 LD_R12_0R12 | PPC_LO (off), p);
11098 bfd_put_32 (htab->params->stub_bfd, LD_R12_0R2 | PPC_LO (off), p);
11100 if (PPC_HA (r2off) != 0)
11103 bfd_put_32 (htab->params->stub_bfd,
11104 ADDIS_R2_R2 | PPC_HA (r2off), p);
11106 if (PPC_LO (r2off) != 0)
11109 bfd_put_32 (htab->params->stub_bfd,
11110 ADDI_R2_R2 | PPC_LO (r2off), p);
11114 bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, p);
11116 p = output_bctr (htab, htab->params->stub_bfd, p);
11119 case ppc_stub_plt_call:
11120 case ppc_stub_plt_call_r2save:
11121 if (stub_entry->h != NULL
11122 && stub_entry->h->is_func_descriptor
11123 && stub_entry->h->oh != NULL)
11125 struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
11127 /* If the old-ABI "dot-symbol" is undefined make it weak so
11128 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11129 if (fh->elf.root.type == bfd_link_hash_undefined
11130 && (stub_entry->h->elf.root.type == bfd_link_hash_defined
11131 || stub_entry->h->elf.root.type == bfd_link_hash_defweak))
11132 fh->elf.root.type = bfd_link_hash_undefweak;
11135 /* Now build the stub. */
11136 dest = stub_entry->plt_ent->plt.offset & ~1;
11137 if (dest >= (bfd_vma) -2)
11140 plt = htab->elf.splt;
11141 if (!htab->elf.dynamic_sections_created
11142 || stub_entry->h == NULL
11143 || stub_entry->h->elf.dynindx == -1)
11144 plt = htab->elf.iplt;
11146 dest += plt->output_offset + plt->output_section->vma;
11148 if (stub_entry->h == NULL
11149 && (stub_entry->plt_ent->plt.offset & 1) == 0)
11151 Elf_Internal_Rela rela;
11154 rela.r_offset = dest;
11156 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
11158 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
11159 rela.r_addend = (stub_entry->target_value
11160 + stub_entry->target_section->output_offset
11161 + stub_entry->target_section->output_section->vma);
11163 rl = (htab->elf.irelplt->contents
11164 + (htab->elf.irelplt->reloc_count++
11165 * sizeof (Elf64_External_Rela)));
11166 bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl);
11167 stub_entry->plt_ent->plt.offset |= 1;
11168 htab->local_ifunc_resolver = 1;
11172 - elf_gp (info->output_bfd)
11173 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11175 if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
11177 info->callbacks->einfo
11178 /* xgettext:c-format */
11179 (_("%P: linkage table error against `%T'\n"),
11180 stub_entry->h != NULL
11181 ? stub_entry->h->elf.root.root.string
11183 bfd_set_error (bfd_error_bad_value);
11184 htab->stub_error = TRUE;
11188 if (htab->params->plt_stub_align != 0)
11190 unsigned pad = plt_stub_pad (htab, stub_entry, off);
11192 stub_entry->group->stub_sec->size += pad;
11193 stub_entry->stub_offset = stub_entry->group->stub_sec->size;
11198 if (info->emitrelocations)
11200 r = get_relocs (stub_entry->group->stub_sec,
11201 ((PPC_HA (off) != 0)
11203 ? 2 + (htab->params->plt_static_chain
11204 && PPC_HA (off + 16) == PPC_HA (off))
11208 r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
11209 if (bfd_big_endian (info->output_bfd))
11210 r[0].r_offset += 2;
11211 r[0].r_addend = dest;
11213 if (stub_entry->h != NULL
11214 && (stub_entry->h == htab->tls_get_addr_fd
11215 || stub_entry->h == htab->tls_get_addr)
11216 && htab->params->tls_get_addr_opt)
11217 p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
11219 p = build_plt_stub (htab, stub_entry, loc, off, r);
11222 case ppc_stub_save_res:
11230 stub_entry->group->stub_sec->size += p - loc;
11232 if (htab->params->emit_stub_syms)
11234 struct elf_link_hash_entry *h;
11237 const char *const stub_str[] = { "long_branch",
11238 "long_branch_r2off",
11240 "plt_branch_r2off",
11244 len1 = strlen (stub_str[stub_entry->stub_type - 1]);
11245 len2 = strlen (stub_entry->root.string);
11246 name = bfd_malloc (len1 + len2 + 2);
11249 memcpy (name, stub_entry->root.string, 9);
11250 memcpy (name + 9, stub_str[stub_entry->stub_type - 1], len1);
11251 memcpy (name + len1 + 9, stub_entry->root.string + 8, len2 - 8 + 1);
11252 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
11255 if (h->root.type == bfd_link_hash_new)
11257 h->root.type = bfd_link_hash_defined;
11258 h->root.u.def.section = stub_entry->group->stub_sec;
11259 h->root.u.def.value = stub_entry->stub_offset;
11260 h->ref_regular = 1;
11261 h->def_regular = 1;
11262 h->ref_regular_nonweak = 1;
11263 h->forced_local = 1;
11265 h->root.linker_def = 1;
11272 /* As above, but don't actually build the stub. Just bump offset so
11273 we know stub section sizes, and select plt_branch stubs where
11274 long_branch stubs won't do. */
11277 ppc_size_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg)
11279 struct ppc_stub_hash_entry *stub_entry;
11280 struct bfd_link_info *info;
11281 struct ppc_link_hash_table *htab;
11285 /* Massage our args to the form they really have. */
11286 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
11289 htab = ppc_hash_table (info);
11293 if (stub_entry->h != NULL
11294 && stub_entry->h->save_res
11295 && stub_entry->h->elf.root.type == bfd_link_hash_defined
11296 && stub_entry->h->elf.root.u.def.section == htab->sfpr)
11298 /* Don't make stubs to out-of-line register save/restore
11299 functions. Instead, emit copies of the functions. */
11300 stub_entry->group->needs_save_res = 1;
11301 stub_entry->stub_type = ppc_stub_save_res;
11305 if (stub_entry->stub_type == ppc_stub_plt_call
11306 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
11309 off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
11310 if (off >= (bfd_vma) -2)
11312 plt = htab->elf.splt;
11313 if (!htab->elf.dynamic_sections_created
11314 || stub_entry->h == NULL
11315 || stub_entry->h->elf.dynindx == -1)
11316 plt = htab->elf.iplt;
11317 off += (plt->output_offset
11318 + plt->output_section->vma
11319 - elf_gp (info->output_bfd)
11320 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11322 size = plt_stub_size (htab, stub_entry, off);
11323 if (stub_entry->h != NULL
11324 && (stub_entry->h == htab->tls_get_addr_fd
11325 || stub_entry->h == htab->tls_get_addr)
11326 && htab->params->tls_get_addr_opt
11327 && (ALWAYS_EMIT_R2SAVE
11328 || stub_entry->stub_type == ppc_stub_plt_call_r2save))
11329 stub_entry->group->tls_get_addr_opt_bctrl
11330 = stub_entry->group->stub_sec->size + size - 5 * 4;
11332 if (htab->params->plt_stub_align)
11333 size += plt_stub_pad (htab, stub_entry, off);
11334 if (info->emitrelocations)
11336 stub_entry->group->stub_sec->reloc_count
11337 += ((PPC_HA (off) != 0)
11339 ? 2 + (htab->params->plt_static_chain
11340 && PPC_HA (off + 16) == PPC_HA (off))
11342 stub_entry->group->stub_sec->flags |= SEC_RELOC;
11347 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11350 bfd_vma local_off = 0;
11352 off = (stub_entry->target_value
11353 + stub_entry->target_section->output_offset
11354 + stub_entry->target_section->output_section->vma);
11355 off -= (stub_entry->group->stub_sec->size
11356 + stub_entry->group->stub_sec->output_offset
11357 + stub_entry->group->stub_sec->output_section->vma);
11359 /* Reset the stub type from the plt variant in case we now
11360 can reach with a shorter stub. */
11361 if (stub_entry->stub_type >= ppc_stub_plt_branch)
11362 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch;
11365 if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
11367 r2off = get_r2off (info, stub_entry);
11368 if (r2off == (bfd_vma) -1)
11370 htab->stub_error = TRUE;
11374 if (PPC_HA (r2off) != 0)
11376 if (PPC_LO (r2off) != 0)
11381 local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
11383 /* If the branch offset if too big, use a ppc_stub_plt_branch.
11384 Do the same for -R objects without function descriptors. */
11385 if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off
11386 || (stub_entry->stub_type == ppc_stub_long_branch_r2off
11388 && htab->sec_info[stub_entry->target_section->id].toc_off == 0))
11390 struct ppc_branch_hash_entry *br_entry;
11392 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
11393 stub_entry->root.string + 9,
11395 if (br_entry == NULL)
11397 info->callbacks->einfo (_("%P: can't build branch stub `%s'\n"),
11398 stub_entry->root.string);
11399 htab->stub_error = TRUE;
11403 if (br_entry->iter != htab->stub_iteration)
11405 br_entry->iter = htab->stub_iteration;
11406 br_entry->offset = htab->brlt->size;
11407 htab->brlt->size += 8;
11409 if (htab->relbrlt != NULL)
11410 htab->relbrlt->size += sizeof (Elf64_External_Rela);
11411 else if (info->emitrelocations)
11413 htab->brlt->reloc_count += 1;
11414 htab->brlt->flags |= SEC_RELOC;
11418 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
11419 off = (br_entry->offset
11420 + htab->brlt->output_offset
11421 + htab->brlt->output_section->vma
11422 - elf_gp (info->output_bfd)
11423 - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
11425 if (info->emitrelocations)
11427 stub_entry->group->stub_sec->reloc_count
11428 += 1 + (PPC_HA (off) != 0);
11429 stub_entry->group->stub_sec->flags |= SEC_RELOC;
11432 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
11435 if (PPC_HA (off) != 0)
11441 if (PPC_HA (off) != 0)
11444 if (PPC_HA (r2off) != 0)
11446 if (PPC_LO (r2off) != 0)
11449 if (!htab->params->speculate_indirect_jumps)
11452 else if (info->emitrelocations)
11454 stub_entry->group->stub_sec->reloc_count += 1;
11455 stub_entry->group->stub_sec->flags |= SEC_RELOC;
11459 stub_entry->group->stub_sec->size += size;
11463 /* Set up various things so that we can make a list of input sections
11464 for each output section included in the link. Returns -1 on error,
11465 0 when no stubs will be needed, and 1 on success. */
11468 ppc64_elf_setup_section_lists (struct bfd_link_info *info)
11472 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11477 htab->sec_info_arr_size = bfd_get_next_section_id ();
11478 amt = sizeof (*htab->sec_info) * (htab->sec_info_arr_size);
11479 htab->sec_info = bfd_zmalloc (amt);
11480 if (htab->sec_info == NULL)
11483 /* Set toc_off for com, und, abs and ind sections. */
11484 for (id = 0; id < 3; id++)
11485 htab->sec_info[id].toc_off = TOC_BASE_OFF;
11490 /* Set up for first pass at multitoc partitioning. */
11493 ppc64_elf_start_multitoc_partition (struct bfd_link_info *info)
11495 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11497 htab->toc_curr = ppc64_elf_set_toc (info, info->output_bfd);
11498 htab->toc_bfd = NULL;
11499 htab->toc_first_sec = NULL;
11502 /* The linker repeatedly calls this function for each TOC input section
11503 and linker generated GOT section. Group input bfds such that the toc
11504 within a group is less than 64k in size. */
11507 ppc64_elf_next_toc_section (struct bfd_link_info *info, asection *isec)
11509 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11510 bfd_vma addr, off, limit;
11515 if (!htab->second_toc_pass)
11517 /* Keep track of the first .toc or .got section for this input bfd. */
11518 bfd_boolean new_bfd = htab->toc_bfd != isec->owner;
11522 htab->toc_bfd = isec->owner;
11523 htab->toc_first_sec = isec;
11526 addr = isec->output_offset + isec->output_section->vma;
11527 off = addr - htab->toc_curr;
11528 limit = 0x80008000;
11529 if (ppc64_elf_tdata (isec->owner)->has_small_toc_reloc)
11531 if (off + isec->size > limit)
11533 addr = (htab->toc_first_sec->output_offset
11534 + htab->toc_first_sec->output_section->vma);
11535 htab->toc_curr = addr;
11536 htab->toc_curr &= -TOC_BASE_ALIGN;
11539 /* toc_curr is the base address of this toc group. Set elf_gp
11540 for the input section to be the offset relative to the
11541 output toc base plus 0x8000. Making the input elf_gp an
11542 offset allows us to move the toc as a whole without
11543 recalculating input elf_gp. */
11544 off = htab->toc_curr - elf_gp (info->output_bfd);
11545 off += TOC_BASE_OFF;
11547 /* Die if someone uses a linker script that doesn't keep input
11548 file .toc and .got together. */
11550 && elf_gp (isec->owner) != 0
11551 && elf_gp (isec->owner) != off)
11554 elf_gp (isec->owner) = off;
11558 /* During the second pass toc_first_sec points to the start of
11559 a toc group, and toc_curr is used to track the old elf_gp.
11560 We use toc_bfd to ensure we only look at each bfd once. */
11561 if (htab->toc_bfd == isec->owner)
11563 htab->toc_bfd = isec->owner;
11565 if (htab->toc_first_sec == NULL
11566 || htab->toc_curr != elf_gp (isec->owner))
11568 htab->toc_curr = elf_gp (isec->owner);
11569 htab->toc_first_sec = isec;
11571 addr = (htab->toc_first_sec->output_offset
11572 + htab->toc_first_sec->output_section->vma);
11573 off = addr - elf_gp (info->output_bfd) + TOC_BASE_OFF;
11574 elf_gp (isec->owner) = off;
11579 /* Called via elf_link_hash_traverse to merge GOT entries for global
11583 merge_global_got (struct elf_link_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
11585 if (h->root.type == bfd_link_hash_indirect)
11588 merge_got_entries (&h->got.glist);
11593 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11597 reallocate_got (struct elf_link_hash_entry *h, void *inf)
11599 struct got_entry *gent;
11601 if (h->root.type == bfd_link_hash_indirect)
11604 for (gent = h->got.glist; gent != NULL; gent = gent->next)
11605 if (!gent->is_indirect)
11606 allocate_got (h, (struct bfd_link_info *) inf, gent);
11610 /* Called on the first multitoc pass after the last call to
11611 ppc64_elf_next_toc_section. This function removes duplicate GOT
11615 ppc64_elf_layout_multitoc (struct bfd_link_info *info)
11617 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11618 struct bfd *ibfd, *ibfd2;
11619 bfd_boolean done_something;
11621 htab->multi_toc_needed = htab->toc_curr != elf_gp (info->output_bfd);
11623 if (!htab->do_multi_toc)
11626 /* Merge global sym got entries within a toc group. */
11627 elf_link_hash_traverse (&htab->elf, merge_global_got, info);
11629 /* And tlsld_got. */
11630 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11632 struct got_entry *ent, *ent2;
11634 if (!is_ppc64_elf (ibfd))
11637 ent = ppc64_tlsld_got (ibfd);
11638 if (!ent->is_indirect
11639 && ent->got.offset != (bfd_vma) -1)
11641 for (ibfd2 = ibfd->link.next; ibfd2 != NULL; ibfd2 = ibfd2->link.next)
11643 if (!is_ppc64_elf (ibfd2))
11646 ent2 = ppc64_tlsld_got (ibfd2);
11647 if (!ent2->is_indirect
11648 && ent2->got.offset != (bfd_vma) -1
11649 && elf_gp (ibfd2) == elf_gp (ibfd))
11651 ent2->is_indirect = TRUE;
11652 ent2->got.ent = ent;
11658 /* Zap sizes of got sections. */
11659 htab->elf.irelplt->rawsize = htab->elf.irelplt->size;
11660 htab->elf.irelplt->size -= htab->got_reli_size;
11661 htab->got_reli_size = 0;
11663 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11665 asection *got, *relgot;
11667 if (!is_ppc64_elf (ibfd))
11670 got = ppc64_elf_tdata (ibfd)->got;
11673 got->rawsize = got->size;
11675 relgot = ppc64_elf_tdata (ibfd)->relgot;
11676 relgot->rawsize = relgot->size;
11681 /* Now reallocate the got, local syms first. We don't need to
11682 allocate section contents again since we never increase size. */
11683 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11685 struct got_entry **lgot_ents;
11686 struct got_entry **end_lgot_ents;
11687 struct plt_entry **local_plt;
11688 struct plt_entry **end_local_plt;
11689 unsigned char *lgot_masks;
11690 bfd_size_type locsymcount;
11691 Elf_Internal_Shdr *symtab_hdr;
11694 if (!is_ppc64_elf (ibfd))
11697 lgot_ents = elf_local_got_ents (ibfd);
11701 symtab_hdr = &elf_symtab_hdr (ibfd);
11702 locsymcount = symtab_hdr->sh_info;
11703 end_lgot_ents = lgot_ents + locsymcount;
11704 local_plt = (struct plt_entry **) end_lgot_ents;
11705 end_local_plt = local_plt + locsymcount;
11706 lgot_masks = (unsigned char *) end_local_plt;
11707 s = ppc64_elf_tdata (ibfd)->got;
11708 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
11710 struct got_entry *ent;
11712 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
11714 unsigned int ent_size = 8;
11715 unsigned int rel_size = sizeof (Elf64_External_Rela);
11717 ent->got.offset = s->size;
11718 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
11723 s->size += ent_size;
11724 if ((*lgot_masks & PLT_IFUNC) != 0)
11726 htab->elf.irelplt->size += rel_size;
11727 htab->got_reli_size += rel_size;
11729 else if (bfd_link_pic (info))
11731 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11732 srel->size += rel_size;
11738 elf_link_hash_traverse (&htab->elf, reallocate_got, info);
11740 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11742 struct got_entry *ent;
11744 if (!is_ppc64_elf (ibfd))
11747 ent = ppc64_tlsld_got (ibfd);
11748 if (!ent->is_indirect
11749 && ent->got.offset != (bfd_vma) -1)
11751 asection *s = ppc64_elf_tdata (ibfd)->got;
11752 ent->got.offset = s->size;
11754 if (bfd_link_pic (info))
11756 asection *srel = ppc64_elf_tdata (ibfd)->relgot;
11757 srel->size += sizeof (Elf64_External_Rela);
11762 done_something = htab->elf.irelplt->rawsize != htab->elf.irelplt->size;
11763 if (!done_something)
11764 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
11768 if (!is_ppc64_elf (ibfd))
11771 got = ppc64_elf_tdata (ibfd)->got;
11774 done_something = got->rawsize != got->size;
11775 if (done_something)
11780 if (done_something)
11781 (*htab->params->layout_sections_again) ();
11783 /* Set up for second pass over toc sections to recalculate elf_gp
11784 on input sections. */
11785 htab->toc_bfd = NULL;
11786 htab->toc_first_sec = NULL;
11787 htab->second_toc_pass = TRUE;
11788 return done_something;
11791 /* Called after second pass of multitoc partitioning. */
11794 ppc64_elf_finish_multitoc_partition (struct bfd_link_info *info)
11796 struct ppc_link_hash_table *htab = ppc_hash_table (info);
11798 /* After the second pass, toc_curr tracks the TOC offset used
11799 for code sections below in ppc64_elf_next_input_section. */
11800 htab->toc_curr = TOC_BASE_OFF;
11803 /* No toc references were found in ISEC. If the code in ISEC makes no
11804 calls, then there's no need to use toc adjusting stubs when branching
11805 into ISEC. Actually, indirect calls from ISEC are OK as they will
11806 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11807 needed, and 2 if a cyclical call-graph was found but no other reason
11808 for a stub was detected. If called from the top level, a return of
11809 2 means the same as a return of 0. */
11812 toc_adjusting_stub_needed (struct bfd_link_info *info, asection *isec)
11816 /* Mark this section as checked. */
11817 isec->call_check_done = 1;
11819 /* We know none of our code bearing sections will need toc stubs. */
11820 if ((isec->flags & SEC_LINKER_CREATED) != 0)
11823 if (isec->size == 0)
11826 if (isec->output_section == NULL)
11830 if (isec->reloc_count != 0)
11832 Elf_Internal_Rela *relstart, *rel;
11833 Elf_Internal_Sym *local_syms;
11834 struct ppc_link_hash_table *htab;
11836 relstart = _bfd_elf_link_read_relocs (isec->owner, isec, NULL, NULL,
11837 info->keep_memory);
11838 if (relstart == NULL)
11841 /* Look for branches to outside of this section. */
11843 htab = ppc_hash_table (info);
11847 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel)
11849 enum elf_ppc64_reloc_type r_type;
11850 unsigned long r_symndx;
11851 struct elf_link_hash_entry *h;
11852 struct ppc_link_hash_entry *eh;
11853 Elf_Internal_Sym *sym;
11855 struct _opd_sec_data *opd;
11859 r_type = ELF64_R_TYPE (rel->r_info);
11860 if (r_type != R_PPC64_REL24
11861 && r_type != R_PPC64_REL14
11862 && r_type != R_PPC64_REL14_BRTAKEN
11863 && r_type != R_PPC64_REL14_BRNTAKEN)
11866 r_symndx = ELF64_R_SYM (rel->r_info);
11867 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx,
11874 /* Calls to dynamic lib functions go through a plt call stub
11876 eh = (struct ppc_link_hash_entry *) h;
11878 && (eh->elf.plt.plist != NULL
11880 && ppc_follow_link (eh->oh)->elf.plt.plist != NULL)))
11886 if (sym_sec == NULL)
11887 /* Ignore other undefined symbols. */
11890 /* Assume branches to other sections not included in the
11891 link need stubs too, to cover -R and absolute syms. */
11892 if (sym_sec->output_section == NULL)
11899 sym_value = sym->st_value;
11902 if (h->root.type != bfd_link_hash_defined
11903 && h->root.type != bfd_link_hash_defweak)
11905 sym_value = h->root.u.def.value;
11907 sym_value += rel->r_addend;
11909 /* If this branch reloc uses an opd sym, find the code section. */
11910 opd = get_opd_info (sym_sec);
11913 if (h == NULL && opd->adjust != NULL)
11917 adjust = opd->adjust[OPD_NDX (sym_value)];
11919 /* Assume deleted functions won't ever be called. */
11921 sym_value += adjust;
11924 dest = opd_entry_value (sym_sec, sym_value,
11925 &sym_sec, NULL, FALSE);
11926 if (dest == (bfd_vma) -1)
11931 + sym_sec->output_offset
11932 + sym_sec->output_section->vma);
11934 /* Ignore branch to self. */
11935 if (sym_sec == isec)
11938 /* If the called function uses the toc, we need a stub. */
11939 if (sym_sec->has_toc_reloc
11940 || sym_sec->makes_toc_func_call)
11946 /* Assume any branch that needs a long branch stub might in fact
11947 need a plt_branch stub. A plt_branch stub uses r2. */
11948 else if (dest - (isec->output_offset
11949 + isec->output_section->vma
11950 + rel->r_offset) + (1 << 25)
11951 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11959 /* If calling back to a section in the process of being
11960 tested, we can't say for sure that no toc adjusting stubs
11961 are needed, so don't return zero. */
11962 else if (sym_sec->call_check_in_progress)
11965 /* Branches to another section that itself doesn't have any TOC
11966 references are OK. Recursively call ourselves to check. */
11967 else if (!sym_sec->call_check_done)
11971 /* Mark current section as indeterminate, so that other
11972 sections that call back to current won't be marked as
11974 isec->call_check_in_progress = 1;
11975 recur = toc_adjusting_stub_needed (info, sym_sec);
11976 isec->call_check_in_progress = 0;
11987 if (local_syms != NULL
11988 && (elf_symtab_hdr (isec->owner).contents
11989 != (unsigned char *) local_syms))
11991 if (elf_section_data (isec)->relocs != relstart)
11996 && isec->map_head.s != NULL
11997 && (strcmp (isec->output_section->name, ".init") == 0
11998 || strcmp (isec->output_section->name, ".fini") == 0))
12000 if (isec->map_head.s->has_toc_reloc
12001 || isec->map_head.s->makes_toc_func_call)
12003 else if (!isec->map_head.s->call_check_done)
12006 isec->call_check_in_progress = 1;
12007 recur = toc_adjusting_stub_needed (info, isec->map_head.s);
12008 isec->call_check_in_progress = 0;
12015 isec->makes_toc_func_call = 1;
12020 /* The linker repeatedly calls this function for each input section,
12021 in the order that input sections are linked into output sections.
12022 Build lists of input sections to determine groupings between which
12023 we may insert linker stubs. */
12026 ppc64_elf_next_input_section (struct bfd_link_info *info, asection *isec)
12028 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12033 if ((isec->output_section->flags & SEC_CODE) != 0
12034 && isec->output_section->id < htab->sec_info_arr_size)
12036 /* This happens to make the list in reverse order,
12037 which is what we want. */
12038 htab->sec_info[isec->id].u.list
12039 = htab->sec_info[isec->output_section->id].u.list;
12040 htab->sec_info[isec->output_section->id].u.list = isec;
12043 if (htab->multi_toc_needed)
12045 /* Analyse sections that aren't already flagged as needing a
12046 valid toc pointer. Exclude .fixup for the linux kernel.
12047 .fixup contains branches, but only back to the function that
12048 hit an exception. */
12049 if (!(isec->has_toc_reloc
12050 || (isec->flags & SEC_CODE) == 0
12051 || strcmp (isec->name, ".fixup") == 0
12052 || isec->call_check_done))
12054 if (toc_adjusting_stub_needed (info, isec) < 0)
12057 /* Make all sections use the TOC assigned for this object file.
12058 This will be wrong for pasted sections; We fix that in
12059 check_pasted_section(). */
12060 if (elf_gp (isec->owner) != 0)
12061 htab->toc_curr = elf_gp (isec->owner);
12064 htab->sec_info[isec->id].toc_off = htab->toc_curr;
12068 /* Check that all .init and .fini sections use the same toc, if they
12069 have toc relocs. */
12072 check_pasted_section (struct bfd_link_info *info, const char *name)
12074 asection *o = bfd_get_section_by_name (info->output_bfd, name);
12078 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12079 bfd_vma toc_off = 0;
12082 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
12083 if (i->has_toc_reloc)
12086 toc_off = htab->sec_info[i->id].toc_off;
12087 else if (toc_off != htab->sec_info[i->id].toc_off)
12092 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
12093 if (i->makes_toc_func_call)
12095 toc_off = htab->sec_info[i->id].toc_off;
12099 /* Make sure the whole pasted function uses the same toc offset. */
12101 for (i = o->map_head.s; i != NULL; i = i->map_head.s)
12102 htab->sec_info[i->id].toc_off = toc_off;
12108 ppc64_elf_check_init_fini (struct bfd_link_info *info)
12110 return (check_pasted_section (info, ".init")
12111 & check_pasted_section (info, ".fini"));
12114 /* See whether we can group stub sections together. Grouping stub
12115 sections may result in fewer stubs. More importantly, we need to
12116 put all .init* and .fini* stubs at the beginning of the .init or
12117 .fini output sections respectively, because glibc splits the
12118 _init and _fini functions into multiple parts. Putting a stub in
12119 the middle of a function is not a good idea. */
12122 group_sections (struct bfd_link_info *info,
12123 bfd_size_type stub_group_size,
12124 bfd_boolean stubs_always_before_branch)
12126 struct ppc_link_hash_table *htab;
12128 bfd_boolean suppress_size_errors;
12130 htab = ppc_hash_table (info);
12134 suppress_size_errors = FALSE;
12135 if (stub_group_size == 1)
12137 /* Default values. */
12138 if (stubs_always_before_branch)
12139 stub_group_size = 0x1e00000;
12141 stub_group_size = 0x1c00000;
12142 suppress_size_errors = TRUE;
12145 for (osec = info->output_bfd->sections; osec != NULL; osec = osec->next)
12149 if (osec->id >= htab->sec_info_arr_size)
12152 tail = htab->sec_info[osec->id].u.list;
12153 while (tail != NULL)
12157 bfd_size_type total;
12158 bfd_boolean big_sec;
12160 struct map_stub *group;
12161 bfd_size_type group_size;
12164 total = tail->size;
12165 group_size = (ppc64_elf_section_data (tail) != NULL
12166 && ppc64_elf_section_data (tail)->has_14bit_branch
12167 ? stub_group_size >> 10 : stub_group_size);
12169 big_sec = total > group_size;
12170 if (big_sec && !suppress_size_errors)
12171 /* xgettext:c-format */
12172 _bfd_error_handler (_("%B section %A exceeds stub group size"),
12173 tail->owner, tail);
12174 curr_toc = htab->sec_info[tail->id].toc_off;
12176 while ((prev = htab->sec_info[curr->id].u.list) != NULL
12177 && ((total += curr->output_offset - prev->output_offset)
12178 < (ppc64_elf_section_data (prev) != NULL
12179 && ppc64_elf_section_data (prev)->has_14bit_branch
12180 ? (group_size = stub_group_size >> 10) : group_size))
12181 && htab->sec_info[prev->id].toc_off == curr_toc)
12184 /* OK, the size from the start of CURR to the end is less
12185 than group_size and thus can be handled by one stub
12186 section. (or the tail section is itself larger than
12187 group_size, in which case we may be toast.) We should
12188 really be keeping track of the total size of stubs added
12189 here, as stubs contribute to the final output section
12190 size. That's a little tricky, and this way will only
12191 break if stubs added make the total size more than 2^25,
12192 ie. for the default stub_group_size, if stubs total more
12193 than 2097152 bytes, or nearly 75000 plt call stubs. */
12194 group = bfd_alloc (curr->owner, sizeof (*group));
12197 group->link_sec = curr;
12198 group->stub_sec = NULL;
12199 group->needs_save_res = 0;
12200 group->tls_get_addr_opt_bctrl = -1u;
12201 group->next = htab->group;
12202 htab->group = group;
12205 prev = htab->sec_info[tail->id].u.list;
12206 /* Set up this stub group. */
12207 htab->sec_info[tail->id].u.group = group;
12209 while (tail != curr && (tail = prev) != NULL);
12211 /* But wait, there's more! Input sections up to group_size
12212 bytes before the stub section can be handled by it too.
12213 Don't do this if we have a really large section after the
12214 stubs, as adding more stubs increases the chance that
12215 branches may not reach into the stub section. */
12216 if (!stubs_always_before_branch && !big_sec)
12219 while (prev != NULL
12220 && ((total += tail->output_offset - prev->output_offset)
12221 < (ppc64_elf_section_data (prev) != NULL
12222 && ppc64_elf_section_data (prev)->has_14bit_branch
12223 ? (group_size = stub_group_size >> 10) : group_size))
12224 && htab->sec_info[prev->id].toc_off == curr_toc)
12227 prev = htab->sec_info[tail->id].u.list;
12228 htab->sec_info[tail->id].u.group = group;
12237 static const unsigned char glink_eh_frame_cie[] =
12239 0, 0, 0, 16, /* length. */
12240 0, 0, 0, 0, /* id. */
12241 1, /* CIE version. */
12242 'z', 'R', 0, /* Augmentation string. */
12243 4, /* Code alignment. */
12244 0x78, /* Data alignment. */
12246 1, /* Augmentation size. */
12247 DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
12248 DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
12252 stub_eh_frame_size (struct map_stub *group, size_t align)
12254 size_t this_size = 17;
12255 if (group->tls_get_addr_opt_bctrl != -1u)
12257 unsigned int to_bctrl = group->tls_get_addr_opt_bctrl / 4;
12260 else if (to_bctrl < 256)
12262 else if (to_bctrl < 65536)
12268 this_size = (this_size + align - 1) & -align;
12272 /* Stripping output sections is normally done before dynamic section
12273 symbols have been allocated. This function is called later, and
12274 handles cases like htab->brlt which is mapped to its own output
12278 maybe_strip_output (struct bfd_link_info *info, asection *isec)
12280 if (isec->size == 0
12281 && isec->output_section->size == 0
12282 && !(isec->output_section->flags & SEC_KEEP)
12283 && !bfd_section_removed_from_list (info->output_bfd,
12284 isec->output_section)
12285 && elf_section_data (isec->output_section)->dynindx == 0)
12287 isec->output_section->flags |= SEC_EXCLUDE;
12288 bfd_section_list_remove (info->output_bfd, isec->output_section);
12289 info->output_bfd->section_count--;
12293 /* Determine and set the size of the stub section for a final link.
12295 The basic idea here is to examine all the relocations looking for
12296 PC-relative calls to a target that is unreachable with a "bl"
12300 ppc64_elf_size_stubs (struct bfd_link_info *info)
12302 bfd_size_type stub_group_size;
12303 bfd_boolean stubs_always_before_branch;
12304 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12309 if (htab->params->plt_thread_safe == -1 && !bfd_link_executable (info))
12310 htab->params->plt_thread_safe = 1;
12311 if (!htab->opd_abi)
12312 htab->params->plt_thread_safe = 0;
12313 else if (htab->params->plt_thread_safe == -1)
12315 static const char *const thread_starter[] =
12319 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12321 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12322 "mq_notify", "create_timer",
12327 "GOMP_parallel_start",
12328 "GOMP_parallel_loop_static",
12329 "GOMP_parallel_loop_static_start",
12330 "GOMP_parallel_loop_dynamic",
12331 "GOMP_parallel_loop_dynamic_start",
12332 "GOMP_parallel_loop_guided",
12333 "GOMP_parallel_loop_guided_start",
12334 "GOMP_parallel_loop_runtime",
12335 "GOMP_parallel_loop_runtime_start",
12336 "GOMP_parallel_sections",
12337 "GOMP_parallel_sections_start",
12343 for (i = 0; i < ARRAY_SIZE (thread_starter); i++)
12345 struct elf_link_hash_entry *h;
12346 h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
12347 FALSE, FALSE, TRUE);
12348 htab->params->plt_thread_safe = h != NULL && h->ref_regular;
12349 if (htab->params->plt_thread_safe)
12353 stubs_always_before_branch = htab->params->group_size < 0;
12354 if (htab->params->group_size < 0)
12355 stub_group_size = -htab->params->group_size;
12357 stub_group_size = htab->params->group_size;
12359 if (!group_sections (info, stub_group_size, stubs_always_before_branch))
12362 #define STUB_SHRINK_ITER 20
12363 /* Loop until no stubs added. After iteration 20 of this loop we may
12364 exit on a stub section shrinking. This is to break out of a
12365 pathological case where adding stubs on one iteration decreases
12366 section gaps (perhaps due to alignment), which then requires
12367 fewer or smaller stubs on the next iteration. */
12372 unsigned int bfd_indx;
12373 struct map_stub *group;
12375 htab->stub_iteration += 1;
12377 for (input_bfd = info->input_bfds, bfd_indx = 0;
12379 input_bfd = input_bfd->link.next, bfd_indx++)
12381 Elf_Internal_Shdr *symtab_hdr;
12383 Elf_Internal_Sym *local_syms = NULL;
12385 if (!is_ppc64_elf (input_bfd))
12388 /* We'll need the symbol table in a second. */
12389 symtab_hdr = &elf_symtab_hdr (input_bfd);
12390 if (symtab_hdr->sh_info == 0)
12393 /* Walk over each section attached to the input bfd. */
12394 for (section = input_bfd->sections;
12396 section = section->next)
12398 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
12400 /* If there aren't any relocs, then there's nothing more
12402 if ((section->flags & SEC_RELOC) == 0
12403 || (section->flags & SEC_ALLOC) == 0
12404 || (section->flags & SEC_LOAD) == 0
12405 || (section->flags & SEC_CODE) == 0
12406 || section->reloc_count == 0)
12409 /* If this section is a link-once section that will be
12410 discarded, then don't create any stubs. */
12411 if (section->output_section == NULL
12412 || section->output_section->owner != info->output_bfd)
12415 /* Get the relocs. */
12417 = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
12418 info->keep_memory);
12419 if (internal_relocs == NULL)
12420 goto error_ret_free_local;
12422 /* Now examine each relocation. */
12423 irela = internal_relocs;
12424 irelaend = irela + section->reloc_count;
12425 for (; irela < irelaend; irela++)
12427 enum elf_ppc64_reloc_type r_type;
12428 unsigned int r_indx;
12429 enum ppc_stub_type stub_type;
12430 struct ppc_stub_hash_entry *stub_entry;
12431 asection *sym_sec, *code_sec;
12432 bfd_vma sym_value, code_value;
12433 bfd_vma destination;
12434 unsigned long local_off;
12435 bfd_boolean ok_dest;
12436 struct ppc_link_hash_entry *hash;
12437 struct ppc_link_hash_entry *fdh;
12438 struct elf_link_hash_entry *h;
12439 Elf_Internal_Sym *sym;
12441 const asection *id_sec;
12442 struct _opd_sec_data *opd;
12443 struct plt_entry *plt_ent;
12445 r_type = ELF64_R_TYPE (irela->r_info);
12446 r_indx = ELF64_R_SYM (irela->r_info);
12448 if (r_type >= R_PPC64_max)
12450 bfd_set_error (bfd_error_bad_value);
12451 goto error_ret_free_internal;
12454 /* Only look for stubs on branch instructions. */
12455 if (r_type != R_PPC64_REL24
12456 && r_type != R_PPC64_REL14
12457 && r_type != R_PPC64_REL14_BRTAKEN
12458 && r_type != R_PPC64_REL14_BRNTAKEN)
12461 /* Now determine the call target, its name, value,
12463 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
12464 r_indx, input_bfd))
12465 goto error_ret_free_internal;
12466 hash = (struct ppc_link_hash_entry *) h;
12473 sym_value = sym->st_value;
12474 if (sym_sec != NULL
12475 && sym_sec->output_section != NULL)
12478 else if (hash->elf.root.type == bfd_link_hash_defined
12479 || hash->elf.root.type == bfd_link_hash_defweak)
12481 sym_value = hash->elf.root.u.def.value;
12482 if (sym_sec->output_section != NULL)
12485 else if (hash->elf.root.type == bfd_link_hash_undefweak
12486 || hash->elf.root.type == bfd_link_hash_undefined)
12488 /* Recognise an old ABI func code entry sym, and
12489 use the func descriptor sym instead if it is
12491 if (hash->elf.root.root.string[0] == '.'
12492 && hash->oh != NULL)
12494 fdh = ppc_follow_link (hash->oh);
12495 if (fdh->elf.root.type == bfd_link_hash_defined
12496 || fdh->elf.root.type == bfd_link_hash_defweak)
12498 sym_sec = fdh->elf.root.u.def.section;
12499 sym_value = fdh->elf.root.u.def.value;
12500 if (sym_sec->output_section != NULL)
12509 bfd_set_error (bfd_error_bad_value);
12510 goto error_ret_free_internal;
12517 sym_value += irela->r_addend;
12518 destination = (sym_value
12519 + sym_sec->output_offset
12520 + sym_sec->output_section->vma);
12521 local_off = PPC64_LOCAL_ENTRY_OFFSET (hash
12526 code_sec = sym_sec;
12527 code_value = sym_value;
12528 opd = get_opd_info (sym_sec);
12533 if (hash == NULL && opd->adjust != NULL)
12535 long adjust = opd->adjust[OPD_NDX (sym_value)];
12538 code_value += adjust;
12539 sym_value += adjust;
12541 dest = opd_entry_value (sym_sec, sym_value,
12542 &code_sec, &code_value, FALSE);
12543 if (dest != (bfd_vma) -1)
12545 destination = dest;
12548 /* Fixup old ABI sym to point at code
12550 hash->elf.root.type = bfd_link_hash_defweak;
12551 hash->elf.root.u.def.section = code_sec;
12552 hash->elf.root.u.def.value = code_value;
12557 /* Determine what (if any) linker stub is needed. */
12559 stub_type = ppc_type_of_stub (section, irela, &hash,
12560 &plt_ent, destination,
12563 if (stub_type != ppc_stub_plt_call)
12565 /* Check whether we need a TOC adjusting stub.
12566 Since the linker pastes together pieces from
12567 different object files when creating the
12568 _init and _fini functions, it may be that a
12569 call to what looks like a local sym is in
12570 fact a call needing a TOC adjustment. */
12571 if (code_sec != NULL
12572 && code_sec->output_section != NULL
12573 && (htab->sec_info[code_sec->id].toc_off
12574 != htab->sec_info[section->id].toc_off)
12575 && (code_sec->has_toc_reloc
12576 || code_sec->makes_toc_func_call))
12577 stub_type = ppc_stub_long_branch_r2off;
12580 if (stub_type == ppc_stub_none)
12583 /* __tls_get_addr calls might be eliminated. */
12584 if (stub_type != ppc_stub_plt_call
12586 && (hash == htab->tls_get_addr
12587 || hash == htab->tls_get_addr_fd)
12588 && section->has_tls_reloc
12589 && irela != internal_relocs)
12591 /* Get tls info. */
12592 unsigned char *tls_mask;
12594 if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms,
12595 irela - 1, input_bfd))
12596 goto error_ret_free_internal;
12597 if (*tls_mask != 0)
12601 if (stub_type == ppc_stub_plt_call)
12604 && htab->params->plt_localentry0 != 0
12605 && is_elfv2_localentry0 (&hash->elf))
12606 htab->has_plt_localentry0 = 1;
12607 else if (irela + 1 < irelaend
12608 && irela[1].r_offset == irela->r_offset + 4
12609 && (ELF64_R_TYPE (irela[1].r_info)
12610 == R_PPC64_TOCSAVE))
12612 if (!tocsave_find (htab, INSERT,
12613 &local_syms, irela + 1, input_bfd))
12614 goto error_ret_free_internal;
12617 stub_type = ppc_stub_plt_call_r2save;
12620 /* Support for grouping stub sections. */
12621 id_sec = htab->sec_info[section->id].u.group->link_sec;
12623 /* Get the name of this stub. */
12624 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
12626 goto error_ret_free_internal;
12628 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
12629 stub_name, FALSE, FALSE);
12630 if (stub_entry != NULL)
12632 /* The proper stub has already been created. */
12634 if (stub_type == ppc_stub_plt_call_r2save)
12635 stub_entry->stub_type = stub_type;
12639 stub_entry = ppc_add_stub (stub_name, section, info);
12640 if (stub_entry == NULL)
12643 error_ret_free_internal:
12644 if (elf_section_data (section)->relocs == NULL)
12645 free (internal_relocs);
12646 error_ret_free_local:
12647 if (local_syms != NULL
12648 && (symtab_hdr->contents
12649 != (unsigned char *) local_syms))
12654 stub_entry->stub_type = stub_type;
12655 if (stub_type != ppc_stub_plt_call
12656 && stub_type != ppc_stub_plt_call_r2save)
12658 stub_entry->target_value = code_value;
12659 stub_entry->target_section = code_sec;
12663 stub_entry->target_value = sym_value;
12664 stub_entry->target_section = sym_sec;
12666 stub_entry->h = hash;
12667 stub_entry->plt_ent = plt_ent;
12668 stub_entry->other = hash ? hash->elf.other : sym->st_other;
12670 if (stub_entry->h != NULL)
12671 htab->stub_globals += 1;
12674 /* We're done with the internal relocs, free them. */
12675 if (elf_section_data (section)->relocs != internal_relocs)
12676 free (internal_relocs);
12679 if (local_syms != NULL
12680 && symtab_hdr->contents != (unsigned char *) local_syms)
12682 if (!info->keep_memory)
12685 symtab_hdr->contents = (unsigned char *) local_syms;
12689 /* We may have added some stubs. Find out the new size of the
12691 for (group = htab->group; group != NULL; group = group->next)
12692 if (group->stub_sec != NULL)
12694 asection *stub_sec = group->stub_sec;
12696 if (htab->stub_iteration <= STUB_SHRINK_ITER
12697 || stub_sec->rawsize < stub_sec->size)
12698 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12699 stub_sec->rawsize = stub_sec->size;
12700 stub_sec->size = 0;
12701 stub_sec->reloc_count = 0;
12702 stub_sec->flags &= ~SEC_RELOC;
12705 htab->brlt->size = 0;
12706 htab->brlt->reloc_count = 0;
12707 htab->brlt->flags &= ~SEC_RELOC;
12708 if (htab->relbrlt != NULL)
12709 htab->relbrlt->size = 0;
12711 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, info);
12713 for (group = htab->group; group != NULL; group = group->next)
12714 if (group->needs_save_res)
12715 group->stub_sec->size += htab->sfpr->size;
12717 if (info->emitrelocations
12718 && htab->glink != NULL && htab->glink->size != 0)
12720 htab->glink->reloc_count = 1;
12721 htab->glink->flags |= SEC_RELOC;
12724 if (htab->glink_eh_frame != NULL
12725 && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
12726 && htab->glink_eh_frame->output_section->size > 8)
12728 size_t size = 0, align = 4;
12730 for (group = htab->group; group != NULL; group = group->next)
12731 if (group->stub_sec != NULL)
12732 size += stub_eh_frame_size (group, align);
12733 if (htab->glink != NULL && htab->glink->size != 0)
12734 size += (24 + align - 1) & -align;
12736 size += (sizeof (glink_eh_frame_cie) + align - 1) & -align;
12737 align = 1ul << htab->glink_eh_frame->output_section->alignment_power;
12738 size = (size + align - 1) & -align;
12739 htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
12740 htab->glink_eh_frame->size = size;
12743 if (htab->params->plt_stub_align != 0)
12744 for (group = htab->group; group != NULL; group = group->next)
12745 if (group->stub_sec != NULL)
12746 group->stub_sec->size = ((group->stub_sec->size
12747 + (1 << htab->params->plt_stub_align) - 1)
12748 & -(1 << htab->params->plt_stub_align));
12750 for (group = htab->group; group != NULL; group = group->next)
12751 if (group->stub_sec != NULL
12752 && group->stub_sec->rawsize != group->stub_sec->size
12753 && (htab->stub_iteration <= STUB_SHRINK_ITER
12754 || group->stub_sec->rawsize < group->stub_sec->size))
12758 && (htab->glink_eh_frame == NULL
12759 || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size))
12762 /* Ask the linker to do its stuff. */
12763 (*htab->params->layout_sections_again) ();
12766 if (htab->glink_eh_frame != NULL
12767 && htab->glink_eh_frame->size != 0)
12770 bfd_byte *p, *last_fde;
12771 size_t last_fde_len, size, align, pad;
12772 struct map_stub *group;
12774 p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
12777 htab->glink_eh_frame->contents = p;
12781 memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
12782 /* CIE length (rewrite in case little-endian). */
12783 last_fde_len = ((sizeof (glink_eh_frame_cie) + align - 1) & -align) - 4;
12784 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12785 p += last_fde_len + 4;
12787 for (group = htab->group; group != NULL; group = group->next)
12788 if (group->stub_sec != NULL)
12791 last_fde_len = stub_eh_frame_size (group, align) - 4;
12793 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12796 val = p - htab->glink_eh_frame->contents;
12797 bfd_put_32 (htab->elf.dynobj, val, p);
12799 /* Offset to stub section, written later. */
12801 /* stub section size. */
12802 bfd_put_32 (htab->elf.dynobj, group->stub_sec->size, p);
12804 /* Augmentation. */
12806 if (group->tls_get_addr_opt_bctrl != -1u)
12808 unsigned int to_bctrl = group->tls_get_addr_opt_bctrl / 4;
12810 /* This FDE needs more than just the default.
12811 Describe __tls_get_addr_opt stub LR. */
12813 *p++ = DW_CFA_advance_loc + to_bctrl;
12814 else if (to_bctrl < 256)
12816 *p++ = DW_CFA_advance_loc1;
12819 else if (to_bctrl < 65536)
12821 *p++ = DW_CFA_advance_loc2;
12822 bfd_put_16 (htab->elf.dynobj, to_bctrl, p);
12827 *p++ = DW_CFA_advance_loc4;
12828 bfd_put_32 (htab->elf.dynobj, to_bctrl, p);
12831 *p++ = DW_CFA_offset_extended_sf;
12833 *p++ = -(STK_LINKER (htab) / 8) & 0x7f;
12834 *p++ = DW_CFA_advance_loc + 4;
12835 *p++ = DW_CFA_restore_extended;
12839 p = last_fde + last_fde_len + 4;
12841 if (htab->glink != NULL && htab->glink->size != 0)
12844 last_fde_len = ((24 + align - 1) & -align) - 4;
12846 bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
12849 val = p - htab->glink_eh_frame->contents;
12850 bfd_put_32 (htab->elf.dynobj, val, p);
12852 /* Offset to .glink, written later. */
12855 bfd_put_32 (htab->elf.dynobj, htab->glink->size - 8, p);
12857 /* Augmentation. */
12860 *p++ = DW_CFA_advance_loc + 1;
12861 *p++ = DW_CFA_register;
12863 *p++ = htab->opd_abi ? 12 : 0;
12864 *p++ = DW_CFA_advance_loc + (htab->opd_abi ? 5 : 7);
12865 *p++ = DW_CFA_restore_extended;
12867 p += ((24 + align - 1) & -align) - 24;
12869 /* Subsume any padding into the last FDE if user .eh_frame
12870 sections are aligned more than glink_eh_frame. Otherwise any
12871 zero padding will be seen as a terminator. */
12872 align = 1ul << htab->glink_eh_frame->output_section->alignment_power;
12873 size = p - htab->glink_eh_frame->contents;
12874 pad = ((size + align - 1) & -align) - size;
12875 htab->glink_eh_frame->size = size + pad;
12876 bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
12879 maybe_strip_output (info, htab->brlt);
12880 if (htab->glink_eh_frame != NULL)
12881 maybe_strip_output (info, htab->glink_eh_frame);
12886 /* Called after we have determined section placement. If sections
12887 move, we'll be called again. Provide a value for TOCstart. */
12890 ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
12893 bfd_vma TOCstart, adjust;
12897 struct elf_link_hash_entry *h;
12898 struct elf_link_hash_table *htab = elf_hash_table (info);
12900 if (is_elf_hash_table (htab)
12901 && htab->hgot != NULL)
12905 h = elf_link_hash_lookup (htab, ".TOC.", FALSE, FALSE, TRUE);
12906 if (is_elf_hash_table (htab))
12910 && h->root.type == bfd_link_hash_defined
12911 && !h->root.linker_def
12912 && (!is_elf_hash_table (htab)
12913 || h->def_regular))
12915 TOCstart = (h->root.u.def.value - TOC_BASE_OFF
12916 + h->root.u.def.section->output_offset
12917 + h->root.u.def.section->output_section->vma);
12918 _bfd_set_gp_value (obfd, TOCstart);
12923 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12924 order. The TOC starts where the first of these sections starts. */
12925 s = bfd_get_section_by_name (obfd, ".got");
12926 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12927 s = bfd_get_section_by_name (obfd, ".toc");
12928 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12929 s = bfd_get_section_by_name (obfd, ".tocbss");
12930 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12931 s = bfd_get_section_by_name (obfd, ".plt");
12932 if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
12934 /* This may happen for
12935 o references to TOC base (SYM@toc / TOC[tc0]) without a
12937 o bad linker script
12938 o --gc-sections and empty TOC sections
12940 FIXME: Warn user? */
12942 /* Look for a likely section. We probably won't even be
12944 for (s = obfd->sections; s != NULL; s = s->next)
12945 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY
12947 == (SEC_ALLOC | SEC_SMALL_DATA))
12950 for (s = obfd->sections; s != NULL; s = s->next)
12951 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE))
12952 == (SEC_ALLOC | SEC_SMALL_DATA))
12955 for (s = obfd->sections; s != NULL; s = s->next)
12956 if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE))
12960 for (s = obfd->sections; s != NULL; s = s->next)
12961 if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC)
12967 TOCstart = s->output_section->vma + s->output_offset;
12969 /* Force alignment. */
12970 adjust = TOCstart & (TOC_BASE_ALIGN - 1);
12971 TOCstart -= adjust;
12972 _bfd_set_gp_value (obfd, TOCstart);
12974 if (info != NULL && s != NULL)
12976 struct ppc_link_hash_table *htab = ppc_hash_table (info);
12980 if (htab->elf.hgot != NULL)
12982 htab->elf.hgot->root.u.def.value = TOC_BASE_OFF - adjust;
12983 htab->elf.hgot->root.u.def.section = s;
12988 struct bfd_link_hash_entry *bh = NULL;
12989 _bfd_generic_link_add_one_symbol (info, obfd, ".TOC.", BSF_GLOBAL,
12990 s, TOC_BASE_OFF - adjust,
12991 NULL, FALSE, FALSE, &bh);
12997 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
12998 write out any global entry stubs. */
13001 build_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
13003 struct bfd_link_info *info;
13004 struct ppc_link_hash_table *htab;
13005 struct plt_entry *pent;
13008 if (h->root.type == bfd_link_hash_indirect)
13011 if (!h->pointer_equality_needed)
13014 if (h->def_regular)
13018 htab = ppc_hash_table (info);
13022 s = htab->global_entry;
13023 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
13024 if (pent->plt.offset != (bfd_vma) -1
13025 && pent->addend == 0)
13031 p = s->contents + h->root.u.def.value;
13032 plt = htab->elf.splt;
13033 if (!htab->elf.dynamic_sections_created
13034 || h->dynindx == -1)
13035 plt = htab->elf.iplt;
13036 off = pent->plt.offset + plt->output_offset + plt->output_section->vma;
13037 off -= h->root.u.def.value + s->output_offset + s->output_section->vma;
13039 if (off + 0x80008000 > 0xffffffff || (off & 3) != 0)
13041 info->callbacks->einfo
13042 (_("%P: linkage table error against `%T'\n"),
13043 h->root.root.string);
13044 bfd_set_error (bfd_error_bad_value);
13045 htab->stub_error = TRUE;
13048 htab->stub_count[ppc_stub_global_entry - 1] += 1;
13049 if (htab->params->emit_stub_syms)
13051 size_t len = strlen (h->root.root.string);
13052 char *name = bfd_malloc (sizeof "12345678.global_entry." + len);
13057 sprintf (name, "%08x.global_entry.%s", s->id, h->root.root.string);
13058 h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
13061 if (h->root.type == bfd_link_hash_new)
13063 h->root.type = bfd_link_hash_defined;
13064 h->root.u.def.section = s;
13065 h->root.u.def.value = p - s->contents;
13066 h->ref_regular = 1;
13067 h->def_regular = 1;
13068 h->ref_regular_nonweak = 1;
13069 h->forced_local = 1;
13071 h->root.linker_def = 1;
13075 if (PPC_HA (off) != 0)
13077 bfd_put_32 (s->owner, ADDIS_R12_R12 | PPC_HA (off), p);
13080 bfd_put_32 (s->owner, LD_R12_0R12 | PPC_LO (off), p);
13082 bfd_put_32 (s->owner, MTCTR_R12, p);
13084 output_bctr (htab, s->owner, p);
13090 /* Build all the stubs associated with the current output file.
13091 The stubs are kept in a hash table attached to the main linker
13092 hash table. This function is called via gldelf64ppc_finish. */
13095 ppc64_elf_build_stubs (struct bfd_link_info *info,
13098 struct ppc_link_hash_table *htab = ppc_hash_table (info);
13099 struct map_stub *group;
13100 asection *stub_sec;
13102 int stub_sec_count = 0;
13107 /* Allocate memory to hold the linker stubs. */
13108 for (group = htab->group; group != NULL; group = group->next)
13109 if ((stub_sec = group->stub_sec) != NULL
13110 && stub_sec->size != 0)
13112 stub_sec->contents = bfd_zalloc (htab->params->stub_bfd, stub_sec->size);
13113 if (stub_sec->contents == NULL)
13115 stub_sec->size = 0;
13118 if (htab->glink != NULL && htab->glink->size != 0)
13123 /* Build the .glink plt call stub. */
13124 if (htab->params->emit_stub_syms)
13126 struct elf_link_hash_entry *h;
13127 h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
13128 TRUE, FALSE, FALSE);
13131 if (h->root.type == bfd_link_hash_new)
13133 h->root.type = bfd_link_hash_defined;
13134 h->root.u.def.section = htab->glink;
13135 h->root.u.def.value = 8;
13136 h->ref_regular = 1;
13137 h->def_regular = 1;
13138 h->ref_regular_nonweak = 1;
13139 h->forced_local = 1;
13141 h->root.linker_def = 1;
13144 plt0 = (htab->elf.splt->output_section->vma
13145 + htab->elf.splt->output_offset
13147 if (info->emitrelocations)
13149 Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
13152 r->r_offset = (htab->glink->output_offset
13153 + htab->glink->output_section->vma);
13154 r->r_info = ELF64_R_INFO (0, R_PPC64_REL64);
13155 r->r_addend = plt0;
13157 p = htab->glink->contents;
13158 plt0 -= htab->glink->output_section->vma + htab->glink->output_offset;
13159 bfd_put_64 (htab->glink->owner, plt0, p);
13163 bfd_put_32 (htab->glink->owner, MFLR_R12, p);
13165 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
13167 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
13169 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
13171 bfd_put_32 (htab->glink->owner, MTLR_R12, p);
13173 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
13175 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
13177 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | 8, p);
13179 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
13181 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 16, p);
13186 bfd_put_32 (htab->glink->owner, MFLR_R0, p);
13188 bfd_put_32 (htab->glink->owner, BCL_20_31, p);
13190 bfd_put_32 (htab->glink->owner, MFLR_R11, p);
13192 bfd_put_32 (htab->glink->owner, STD_R2_0R1 + 24, p);
13194 bfd_put_32 (htab->glink->owner, LD_R2_0R11 | (-16 & 0xfffc), p);
13196 bfd_put_32 (htab->glink->owner, MTLR_R0, p);
13198 bfd_put_32 (htab->glink->owner, SUB_R12_R12_R11, p);
13200 bfd_put_32 (htab->glink->owner, ADD_R11_R2_R11, p);
13202 bfd_put_32 (htab->glink->owner, ADDI_R0_R12 | (-48 & 0xffff), p);
13204 bfd_put_32 (htab->glink->owner, LD_R12_0R11, p);
13206 bfd_put_32 (htab->glink->owner, SRDI_R0_R0_2, p);
13208 bfd_put_32 (htab->glink->owner, MTCTR_R12, p);
13210 bfd_put_32 (htab->glink->owner, LD_R11_0R11 | 8, p);
13213 p = output_bctr (htab, htab->glink->owner, p);
13214 BFD_ASSERT (p == htab->glink->contents + GLINK_PLTRESOLVE_SIZE (htab));
13216 /* Build the .glink lazy link call stubs. */
13218 while (p < htab->glink->contents + htab->glink->size)
13224 bfd_put_32 (htab->glink->owner, LI_R0_0 | indx, p);
13229 bfd_put_32 (htab->glink->owner, LIS_R0_0 | PPC_HI (indx), p);
13231 bfd_put_32 (htab->glink->owner, ORI_R0_R0_0 | PPC_LO (indx),
13236 bfd_put_32 (htab->glink->owner,
13237 B_DOT | ((htab->glink->contents - p + 8) & 0x3fffffc), p);
13243 /* Build .glink global entry stubs. */
13244 if (htab->global_entry != NULL && htab->global_entry->size != 0)
13245 elf_link_hash_traverse (&htab->elf, build_global_entry_stubs, info);
13247 if (htab->brlt != NULL && htab->brlt->size != 0)
13249 htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
13251 if (htab->brlt->contents == NULL)
13254 if (htab->relbrlt != NULL && htab->relbrlt->size != 0)
13256 htab->relbrlt->contents = bfd_zalloc (htab->relbrlt->owner,
13257 htab->relbrlt->size);
13258 if (htab->relbrlt->contents == NULL)
13262 /* Build the stubs as directed by the stub hash table. */
13263 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
13265 for (group = htab->group; group != NULL; group = group->next)
13266 if (group->needs_save_res)
13268 stub_sec = group->stub_sec;
13269 memcpy (stub_sec->contents + stub_sec->size, htab->sfpr->contents,
13271 if (htab->params->emit_stub_syms)
13275 for (i = 0; i < ARRAY_SIZE (save_res_funcs); i++)
13276 if (!sfpr_define (info, &save_res_funcs[i], stub_sec))
13279 stub_sec->size += htab->sfpr->size;
13282 if (htab->relbrlt != NULL)
13283 htab->relbrlt->reloc_count = 0;
13285 if (htab->params->plt_stub_align != 0)
13286 for (group = htab->group; group != NULL; group = group->next)
13287 if ((stub_sec = group->stub_sec) != NULL)
13288 stub_sec->size = ((stub_sec->size
13289 + (1 << htab->params->plt_stub_align) - 1)
13290 & -(1 << htab->params->plt_stub_align));
13292 for (group = htab->group; group != NULL; group = group->next)
13293 if ((stub_sec = group->stub_sec) != NULL)
13295 stub_sec_count += 1;
13296 if (stub_sec->rawsize != stub_sec->size
13297 && (htab->stub_iteration <= STUB_SHRINK_ITER
13298 || stub_sec->rawsize < stub_sec->size))
13304 htab->stub_error = TRUE;
13305 info->callbacks->einfo (_("%P: stubs don't match calculated size\n"));
13308 if (htab->stub_error)
13314 *stats = bfd_malloc (500);
13315 if (*stats == NULL)
13318 len = sprintf (*stats,
13319 ngettext ("linker stubs in %u group\n",
13320 "linker stubs in %u groups\n",
13323 sprintf (*stats + len, _(" branch %lu\n"
13324 " toc adjust %lu\n"
13325 " long branch %lu\n"
13326 " long toc adj %lu\n"
13328 " plt call toc %lu\n"
13329 " global entry %lu"),
13330 htab->stub_count[ppc_stub_long_branch - 1],
13331 htab->stub_count[ppc_stub_long_branch_r2off - 1],
13332 htab->stub_count[ppc_stub_plt_branch - 1],
13333 htab->stub_count[ppc_stub_plt_branch_r2off - 1],
13334 htab->stub_count[ppc_stub_plt_call - 1],
13335 htab->stub_count[ppc_stub_plt_call_r2save - 1],
13336 htab->stub_count[ppc_stub_global_entry - 1]);
13341 /* What to do when ld finds relocations against symbols defined in
13342 discarded sections. */
13344 static unsigned int
13345 ppc64_elf_action_discarded (asection *sec)
13347 if (strcmp (".opd", sec->name) == 0)
13350 if (strcmp (".toc", sec->name) == 0)
13353 if (strcmp (".toc1", sec->name) == 0)
13356 return _bfd_elf_default_action_discarded (sec);
13359 /* The RELOCATE_SECTION function is called by the ELF backend linker
13360 to handle the relocations for a section.
13362 The relocs are always passed as Rela structures; if the section
13363 actually uses Rel structures, the r_addend field will always be
13366 This function is responsible for adjust the section contents as
13367 necessary, and (if using Rela relocs and generating a
13368 relocatable output file) adjusting the reloc addend as
13371 This function does not have to worry about setting the reloc
13372 address or the reloc symbol index.
13374 LOCAL_SYMS is a pointer to the swapped in local symbols.
13376 LOCAL_SECTIONS is an array giving the section in the input file
13377 corresponding to the st_shndx field of each local symbol.
13379 The global hash table entry for the global symbols can be found
13380 via elf_sym_hashes (input_bfd).
13382 When generating relocatable output, this function must handle
13383 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13384 going to be the section symbol corresponding to the output
13385 section, which means that the addend must be adjusted
13389 ppc64_elf_relocate_section (bfd *output_bfd,
13390 struct bfd_link_info *info,
13392 asection *input_section,
13393 bfd_byte *contents,
13394 Elf_Internal_Rela *relocs,
13395 Elf_Internal_Sym *local_syms,
13396 asection **local_sections)
13398 struct ppc_link_hash_table *htab;
13399 Elf_Internal_Shdr *symtab_hdr;
13400 struct elf_link_hash_entry **sym_hashes;
13401 Elf_Internal_Rela *rel;
13402 Elf_Internal_Rela *wrel;
13403 Elf_Internal_Rela *relend;
13404 Elf_Internal_Rela outrel;
13406 struct got_entry **local_got_ents;
13408 bfd_boolean ret = TRUE;
13409 bfd_boolean is_opd;
13410 /* Assume 'at' branch hints. */
13411 bfd_boolean is_isa_v2 = TRUE;
13412 bfd_vma d_offset = (bfd_big_endian (input_bfd) ? 2 : 0);
13414 /* Initialize howto table if needed. */
13415 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
13418 htab = ppc_hash_table (info);
13422 /* Don't relocate stub sections. */
13423 if (input_section->owner == htab->params->stub_bfd)
13426 BFD_ASSERT (is_ppc64_elf (input_bfd));
13428 local_got_ents = elf_local_got_ents (input_bfd);
13429 TOCstart = elf_gp (output_bfd);
13430 symtab_hdr = &elf_symtab_hdr (input_bfd);
13431 sym_hashes = elf_sym_hashes (input_bfd);
13432 is_opd = ppc64_elf_section_data (input_section)->sec_type == sec_opd;
13434 rel = wrel = relocs;
13435 relend = relocs + input_section->reloc_count;
13436 for (; rel < relend; wrel++, rel++)
13438 enum elf_ppc64_reloc_type r_type;
13440 bfd_reloc_status_type r;
13441 Elf_Internal_Sym *sym;
13443 struct elf_link_hash_entry *h_elf;
13444 struct ppc_link_hash_entry *h;
13445 struct ppc_link_hash_entry *fdh;
13446 const char *sym_name;
13447 unsigned long r_symndx, toc_symndx;
13448 bfd_vma toc_addend;
13449 unsigned char tls_mask, tls_gd, tls_type;
13450 unsigned char sym_type;
13451 bfd_vma relocation;
13452 bfd_boolean unresolved_reloc;
13453 bfd_boolean warned;
13454 enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
13457 struct ppc_stub_hash_entry *stub_entry;
13458 bfd_vma max_br_offset;
13460 Elf_Internal_Rela orig_rel;
13461 reloc_howto_type *howto;
13462 struct reloc_howto_struct alt_howto;
13467 r_type = ELF64_R_TYPE (rel->r_info);
13468 r_symndx = ELF64_R_SYM (rel->r_info);
13470 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13471 symbol of the previous ADDR64 reloc. The symbol gives us the
13472 proper TOC base to use. */
13473 if (rel->r_info == ELF64_R_INFO (0, R_PPC64_TOC)
13475 && ELF64_R_TYPE (wrel[-1].r_info) == R_PPC64_ADDR64
13477 r_symndx = ELF64_R_SYM (wrel[-1].r_info);
13483 unresolved_reloc = FALSE;
13486 if (r_symndx < symtab_hdr->sh_info)
13488 /* It's a local symbol. */
13489 struct _opd_sec_data *opd;
13491 sym = local_syms + r_symndx;
13492 sec = local_sections[r_symndx];
13493 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
13494 sym_type = ELF64_ST_TYPE (sym->st_info);
13495 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
13496 opd = get_opd_info (sec);
13497 if (opd != NULL && opd->adjust != NULL)
13499 long adjust = opd->adjust[OPD_NDX (sym->st_value
13505 /* If this is a relocation against the opd section sym
13506 and we have edited .opd, adjust the reloc addend so
13507 that ld -r and ld --emit-relocs output is correct.
13508 If it is a reloc against some other .opd symbol,
13509 then the symbol value will be adjusted later. */
13510 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
13511 rel->r_addend += adjust;
13513 relocation += adjust;
13519 bfd_boolean ignored;
13521 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
13522 r_symndx, symtab_hdr, sym_hashes,
13523 h_elf, sec, relocation,
13524 unresolved_reloc, warned, ignored);
13525 sym_name = h_elf->root.root.string;
13526 sym_type = h_elf->type;
13528 && sec->owner == output_bfd
13529 && strcmp (sec->name, ".opd") == 0)
13531 /* This is a symbol defined in a linker script. All
13532 such are defined in output sections, even those
13533 defined by simple assignment from a symbol defined in
13534 an input section. Transfer the symbol to an
13535 appropriate input .opd section, so that a branch to
13536 this symbol will be mapped to the location specified
13537 by the opd entry. */
13538 struct bfd_link_order *lo;
13539 for (lo = sec->map_head.link_order; lo != NULL; lo = lo->next)
13540 if (lo->type == bfd_indirect_link_order)
13542 asection *isec = lo->u.indirect.section;
13543 if (h_elf->root.u.def.value >= isec->output_offset
13544 && h_elf->root.u.def.value < (isec->output_offset
13547 h_elf->root.u.def.value -= isec->output_offset;
13548 h_elf->root.u.def.section = isec;
13555 h = (struct ppc_link_hash_entry *) h_elf;
13557 if (sec != NULL && discarded_section (sec))
13559 _bfd_clear_contents (ppc64_elf_howto_table[r_type],
13560 input_bfd, input_section,
13561 contents + rel->r_offset);
13562 wrel->r_offset = rel->r_offset;
13564 wrel->r_addend = 0;
13566 /* For ld -r, remove relocations in debug sections against
13567 symbols defined in discarded sections. Not done for
13568 non-debug to preserve relocs in .eh_frame which the
13569 eh_frame editing code expects to be present. */
13570 if (bfd_link_relocatable (info)
13571 && (input_section->flags & SEC_DEBUGGING))
13577 if (bfd_link_relocatable (info))
13580 if (h != NULL && &h->elf == htab->elf.hgot)
13582 relocation = TOCstart + htab->sec_info[input_section->id].toc_off;
13583 sec = bfd_abs_section_ptr;
13584 unresolved_reloc = FALSE;
13587 /* TLS optimizations. Replace instruction sequences and relocs
13588 based on information we collected in tls_optimize. We edit
13589 RELOCS so that --emit-relocs will output something sensible
13590 for the final instruction stream. */
13595 tls_mask = h->tls_mask;
13596 else if (local_got_ents != NULL)
13598 struct plt_entry **local_plt = (struct plt_entry **)
13599 (local_got_ents + symtab_hdr->sh_info);
13600 unsigned char *lgot_masks = (unsigned char *)
13601 (local_plt + symtab_hdr->sh_info);
13602 tls_mask = lgot_masks[r_symndx];
13605 && (r_type == R_PPC64_TLS
13606 || r_type == R_PPC64_TLSGD
13607 || r_type == R_PPC64_TLSLD))
13609 /* Check for toc tls entries. */
13610 unsigned char *toc_tls;
13612 if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
13613 &local_syms, rel, input_bfd))
13617 tls_mask = *toc_tls;
13620 /* Check that tls relocs are used with tls syms, and non-tls
13621 relocs are used with non-tls syms. */
13622 if (r_symndx != STN_UNDEF
13623 && r_type != R_PPC64_NONE
13625 || h->elf.root.type == bfd_link_hash_defined
13626 || h->elf.root.type == bfd_link_hash_defweak)
13627 && (IS_PPC64_TLS_RELOC (r_type)
13628 != (sym_type == STT_TLS
13629 || (sym_type == STT_SECTION
13630 && (sec->flags & SEC_THREAD_LOCAL) != 0))))
13633 && (r_type == R_PPC64_TLS
13634 || r_type == R_PPC64_TLSGD
13635 || r_type == R_PPC64_TLSLD))
13636 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13639 info->callbacks->einfo
13640 (!IS_PPC64_TLS_RELOC (r_type)
13641 /* xgettext:c-format */
13642 ? _("%H: %s used with TLS symbol `%T'\n")
13643 /* xgettext:c-format */
13644 : _("%H: %s used with non-TLS symbol `%T'\n"),
13645 input_bfd, input_section, rel->r_offset,
13646 ppc64_elf_howto_table[r_type]->name,
13650 /* Ensure reloc mapping code below stays sane. */
13651 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
13652 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
13653 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
13654 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
13655 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
13656 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
13657 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
13658 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
13659 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
13660 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
13668 case R_PPC64_LO_DS_OPT:
13669 insn = bfd_get_32 (input_bfd, contents + rel->r_offset - d_offset);
13670 if ((insn & (0x3f << 26)) != 58u << 26)
13672 insn += (14u << 26) - (58u << 26);
13673 bfd_put_32 (input_bfd, insn, contents + rel->r_offset - d_offset);
13674 r_type = R_PPC64_TOC16_LO;
13675 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13678 case R_PPC64_TOC16:
13679 case R_PPC64_TOC16_LO:
13680 case R_PPC64_TOC16_DS:
13681 case R_PPC64_TOC16_LO_DS:
13683 /* Check for toc tls entries. */
13684 unsigned char *toc_tls;
13687 retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend,
13688 &local_syms, rel, input_bfd);
13694 tls_mask = *toc_tls;
13695 if (r_type == R_PPC64_TOC16_DS
13696 || r_type == R_PPC64_TOC16_LO_DS)
13699 && (tls_mask & (TLS_DTPREL | TLS_TPREL)) == 0)
13704 /* If we found a GD reloc pair, then we might be
13705 doing a GD->IE transition. */
13708 tls_gd = TLS_TPRELGD;
13709 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13712 else if (retval == 3)
13714 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13722 case R_PPC64_GOT_TPREL16_HI:
13723 case R_PPC64_GOT_TPREL16_HA:
13725 && (tls_mask & TLS_TPREL) == 0)
13727 rel->r_offset -= d_offset;
13728 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
13729 r_type = R_PPC64_NONE;
13730 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13734 case R_PPC64_GOT_TPREL16_DS:
13735 case R_PPC64_GOT_TPREL16_LO_DS:
13737 && (tls_mask & TLS_TPREL) == 0)
13740 insn = bfd_get_32 (input_bfd,
13741 contents + rel->r_offset - d_offset);
13743 insn |= 0x3c0d0000; /* addis 0,13,0 */
13744 bfd_put_32 (input_bfd, insn,
13745 contents + rel->r_offset - d_offset);
13746 r_type = R_PPC64_TPREL16_HA;
13747 if (toc_symndx != 0)
13749 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
13750 rel->r_addend = toc_addend;
13751 /* We changed the symbol. Start over in order to
13752 get h, sym, sec etc. right. */
13756 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13762 && (tls_mask & TLS_TPREL) == 0)
13764 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
13765 insn = _bfd_elf_ppc_at_tls_transform (insn, 13);
13768 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
13769 /* Was PPC64_TLS which sits on insn boundary, now
13770 PPC64_TPREL16_LO which is at low-order half-word. */
13771 rel->r_offset += d_offset;
13772 r_type = R_PPC64_TPREL16_LO;
13773 if (toc_symndx != 0)
13775 rel->r_info = ELF64_R_INFO (toc_symndx, r_type);
13776 rel->r_addend = toc_addend;
13777 /* We changed the symbol. Start over in order to
13778 get h, sym, sec etc. right. */
13782 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13786 case R_PPC64_GOT_TLSGD16_HI:
13787 case R_PPC64_GOT_TLSGD16_HA:
13788 tls_gd = TLS_TPRELGD;
13789 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13793 case R_PPC64_GOT_TLSLD16_HI:
13794 case R_PPC64_GOT_TLSLD16_HA:
13795 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13798 if ((tls_mask & tls_gd) != 0)
13799 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
13800 + R_PPC64_GOT_TPREL16_DS);
13803 rel->r_offset -= d_offset;
13804 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
13805 r_type = R_PPC64_NONE;
13807 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13811 case R_PPC64_GOT_TLSGD16:
13812 case R_PPC64_GOT_TLSGD16_LO:
13813 tls_gd = TLS_TPRELGD;
13814 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13818 case R_PPC64_GOT_TLSLD16:
13819 case R_PPC64_GOT_TLSLD16_LO:
13820 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13822 unsigned int insn1, insn2;
13826 offset = (bfd_vma) -1;
13827 /* If not using the newer R_PPC64_TLSGD/LD to mark
13828 __tls_get_addr calls, we must trust that the call
13829 stays with its arg setup insns, ie. that the next
13830 reloc is the __tls_get_addr call associated with
13831 the current reloc. Edit both insns. */
13832 if (input_section->has_tls_get_addr_call
13833 && rel + 1 < relend
13834 && branch_reloc_hash_match (input_bfd, rel + 1,
13835 htab->tls_get_addr,
13836 htab->tls_get_addr_fd))
13837 offset = rel[1].r_offset;
13838 /* We read the low GOT_TLS (or TOC16) insn because we
13839 need to keep the destination reg. It may be
13840 something other than the usual r3, and moved to r3
13841 before the call by intervening code. */
13842 insn1 = bfd_get_32 (input_bfd,
13843 contents + rel->r_offset - d_offset);
13844 if ((tls_mask & tls_gd) != 0)
13847 insn1 &= (0x1f << 21) | (0x1f << 16);
13848 insn1 |= 58 << 26; /* ld */
13849 insn2 = 0x7c636a14; /* add 3,3,13 */
13850 if (offset != (bfd_vma) -1)
13851 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13852 if ((tls_mask & TLS_EXPLICIT) == 0)
13853 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
13854 + R_PPC64_GOT_TPREL16_DS);
13856 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
13857 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13862 insn1 &= 0x1f << 21;
13863 insn1 |= 0x3c0d0000; /* addis r,13,0 */
13864 insn2 = 0x38630000; /* addi 3,3,0 */
13867 /* Was an LD reloc. */
13869 sec = local_sections[toc_symndx];
13871 r_symndx < symtab_hdr->sh_info;
13873 if (local_sections[r_symndx] == sec)
13875 if (r_symndx >= symtab_hdr->sh_info)
13876 r_symndx = STN_UNDEF;
13877 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
13878 if (r_symndx != STN_UNDEF)
13879 rel->r_addend -= (local_syms[r_symndx].st_value
13880 + sec->output_offset
13881 + sec->output_section->vma);
13883 else if (toc_symndx != 0)
13885 r_symndx = toc_symndx;
13886 rel->r_addend = toc_addend;
13888 r_type = R_PPC64_TPREL16_HA;
13889 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13890 if (offset != (bfd_vma) -1)
13892 rel[1].r_info = ELF64_R_INFO (r_symndx,
13893 R_PPC64_TPREL16_LO);
13894 rel[1].r_offset = offset + d_offset;
13895 rel[1].r_addend = rel->r_addend;
13898 bfd_put_32 (input_bfd, insn1,
13899 contents + rel->r_offset - d_offset);
13900 if (offset != (bfd_vma) -1)
13901 bfd_put_32 (input_bfd, insn2, contents + offset);
13902 if ((tls_mask & tls_gd) == 0
13903 && (tls_gd == 0 || toc_symndx != 0))
13905 /* We changed the symbol. Start over in order
13906 to get h, sym, sec etc. right. */
13912 case R_PPC64_TLSGD:
13913 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
13915 unsigned int insn2;
13916 bfd_vma offset = rel->r_offset;
13918 if ((tls_mask & TLS_TPRELGD) != 0)
13921 r_type = R_PPC64_NONE;
13922 insn2 = 0x7c636a14; /* add 3,3,13 */
13927 if (toc_symndx != 0)
13929 r_symndx = toc_symndx;
13930 rel->r_addend = toc_addend;
13932 r_type = R_PPC64_TPREL16_LO;
13933 rel->r_offset = offset + d_offset;
13934 insn2 = 0x38630000; /* addi 3,3,0 */
13936 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13937 /* Zap the reloc on the _tls_get_addr call too. */
13938 BFD_ASSERT (offset == rel[1].r_offset);
13939 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13940 bfd_put_32 (input_bfd, insn2, contents + offset);
13941 if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0)
13946 case R_PPC64_TLSLD:
13947 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
13949 unsigned int insn2;
13950 bfd_vma offset = rel->r_offset;
13953 sec = local_sections[toc_symndx];
13955 r_symndx < symtab_hdr->sh_info;
13957 if (local_sections[r_symndx] == sec)
13959 if (r_symndx >= symtab_hdr->sh_info)
13960 r_symndx = STN_UNDEF;
13961 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
13962 if (r_symndx != STN_UNDEF)
13963 rel->r_addend -= (local_syms[r_symndx].st_value
13964 + sec->output_offset
13965 + sec->output_section->vma);
13967 r_type = R_PPC64_TPREL16_LO;
13968 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13969 rel->r_offset = offset + d_offset;
13970 /* Zap the reloc on the _tls_get_addr call too. */
13971 BFD_ASSERT (offset == rel[1].r_offset);
13972 rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
13973 insn2 = 0x38630000; /* addi 3,3,0 */
13974 bfd_put_32 (input_bfd, insn2, contents + offset);
13979 case R_PPC64_DTPMOD64:
13980 if (rel + 1 < relend
13981 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
13982 && rel[1].r_offset == rel->r_offset + 8)
13984 if ((tls_mask & TLS_GD) == 0)
13986 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
13987 if ((tls_mask & TLS_TPRELGD) != 0)
13988 r_type = R_PPC64_TPREL64;
13991 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
13992 r_type = R_PPC64_NONE;
13994 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
13999 if ((tls_mask & TLS_LD) == 0)
14001 bfd_put_64 (output_bfd, 1, contents + rel->r_offset);
14002 r_type = R_PPC64_NONE;
14003 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14008 case R_PPC64_TPREL64:
14009 if ((tls_mask & TLS_TPREL) == 0)
14011 r_type = R_PPC64_NONE;
14012 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14016 case R_PPC64_ENTRY:
14017 relocation = TOCstart + htab->sec_info[input_section->id].toc_off;
14018 if (!bfd_link_pic (info)
14019 && !info->traditional_format
14020 && relocation + 0x80008000 <= 0xffffffff)
14022 unsigned int insn1, insn2;
14024 insn1 = bfd_get_32 (input_bfd, contents + rel->r_offset);
14025 insn2 = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
14026 if ((insn1 & ~0xfffc) == LD_R2_0R12
14027 && insn2 == ADD_R2_R2_R12)
14029 bfd_put_32 (input_bfd,
14030 LIS_R2 + PPC_HA (relocation),
14031 contents + rel->r_offset);
14032 bfd_put_32 (input_bfd,
14033 ADDI_R2_R2 + PPC_LO (relocation),
14034 contents + rel->r_offset + 4);
14039 relocation -= (rel->r_offset
14040 + input_section->output_offset
14041 + input_section->output_section->vma);
14042 if (relocation + 0x80008000 <= 0xffffffff)
14044 unsigned int insn1, insn2;
14046 insn1 = bfd_get_32 (input_bfd, contents + rel->r_offset);
14047 insn2 = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
14048 if ((insn1 & ~0xfffc) == LD_R2_0R12
14049 && insn2 == ADD_R2_R2_R12)
14051 bfd_put_32 (input_bfd,
14052 ADDIS_R2_R12 + PPC_HA (relocation),
14053 contents + rel->r_offset);
14054 bfd_put_32 (input_bfd,
14055 ADDI_R2_R2 + PPC_LO (relocation),
14056 contents + rel->r_offset + 4);
14062 case R_PPC64_REL16_HA:
14063 /* If we are generating a non-PIC executable, edit
14064 . 0: addis 2,12,.TOC.-0b@ha
14065 . addi 2,2,.TOC.-0b@l
14066 used by ELFv2 global entry points to set up r2, to
14069 if .TOC. is in range. */
14070 if (!bfd_link_pic (info)
14071 && !info->traditional_format
14073 && rel->r_addend == d_offset
14074 && h != NULL && &h->elf == htab->elf.hgot
14075 && rel + 1 < relend
14076 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_REL16_LO)
14077 && rel[1].r_offset == rel->r_offset + 4
14078 && rel[1].r_addend == rel->r_addend + 4
14079 && relocation + 0x80008000 <= 0xffffffff)
14081 unsigned int insn1, insn2;
14082 bfd_vma offset = rel->r_offset - d_offset;
14083 insn1 = bfd_get_32 (input_bfd, contents + offset);
14084 insn2 = bfd_get_32 (input_bfd, contents + offset + 4);
14085 if ((insn1 & 0xffff0000) == ADDIS_R2_R12
14086 && (insn2 & 0xffff0000) == ADDI_R2_R2)
14088 r_type = R_PPC64_ADDR16_HA;
14089 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
14090 rel->r_addend -= d_offset;
14091 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_ADDR16_LO);
14092 rel[1].r_addend -= d_offset + 4;
14093 bfd_put_32 (input_bfd, LIS_R2, contents + offset);
14099 /* Handle other relocations that tweak non-addend part of insn. */
14101 max_br_offset = 1 << 25;
14102 addend = rel->r_addend;
14103 reloc_dest = DEST_NORMAL;
14109 case R_PPC64_TOCSAVE:
14110 if (relocation + addend == (rel->r_offset
14111 + input_section->output_offset
14112 + input_section->output_section->vma)
14113 && tocsave_find (htab, NO_INSERT,
14114 &local_syms, rel, input_bfd))
14116 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
14118 || insn == CROR_151515 || insn == CROR_313131)
14119 bfd_put_32 (input_bfd,
14120 STD_R2_0R1 + STK_TOC (htab),
14121 contents + rel->r_offset);
14125 /* Branch taken prediction relocations. */
14126 case R_PPC64_ADDR14_BRTAKEN:
14127 case R_PPC64_REL14_BRTAKEN:
14128 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14129 /* Fall through. */
14131 /* Branch not taken prediction relocations. */
14132 case R_PPC64_ADDR14_BRNTAKEN:
14133 case R_PPC64_REL14_BRNTAKEN:
14134 insn |= bfd_get_32 (input_bfd,
14135 contents + rel->r_offset) & ~(0x01 << 21);
14136 /* Fall through. */
14138 case R_PPC64_REL14:
14139 max_br_offset = 1 << 15;
14140 /* Fall through. */
14142 case R_PPC64_REL24:
14143 /* Calls to functions with a different TOC, such as calls to
14144 shared objects, need to alter the TOC pointer. This is
14145 done using a linkage stub. A REL24 branching to these
14146 linkage stubs needs to be followed by a nop, as the nop
14147 will be replaced with an instruction to restore the TOC
14152 && h->oh->is_func_descriptor)
14153 fdh = ppc_follow_link (h->oh);
14154 stub_entry = ppc_get_stub_entry (input_section, sec, fdh, &orig_rel,
14156 if (stub_entry != NULL
14157 && (stub_entry->stub_type == ppc_stub_plt_call
14158 || stub_entry->stub_type == ppc_stub_plt_call_r2save
14159 || stub_entry->stub_type == ppc_stub_plt_branch_r2off
14160 || stub_entry->stub_type == ppc_stub_long_branch_r2off))
14162 bfd_boolean can_plt_call = FALSE;
14164 if (stub_entry->stub_type == ppc_stub_plt_call
14166 && htab->params->plt_localentry0 != 0
14167 && is_elfv2_localentry0 (&h->elf))
14169 /* The function doesn't use or change r2. */
14170 can_plt_call = TRUE;
14173 /* All of these stubs may modify r2, so there must be a
14174 branch and link followed by a nop. The nop is
14175 replaced by an insn to restore r2. */
14176 else if (rel->r_offset + 8 <= input_section->size)
14180 br = bfd_get_32 (input_bfd,
14181 contents + rel->r_offset);
14186 nop = bfd_get_32 (input_bfd,
14187 contents + rel->r_offset + 4);
14189 || nop == CROR_151515 || nop == CROR_313131)
14192 && (h == htab->tls_get_addr_fd
14193 || h == htab->tls_get_addr)
14194 && htab->params->tls_get_addr_opt)
14196 /* Special stub used, leave nop alone. */
14199 bfd_put_32 (input_bfd,
14200 LD_R2_0R1 + STK_TOC (htab),
14201 contents + rel->r_offset + 4);
14202 can_plt_call = TRUE;
14207 if (!can_plt_call && h != NULL)
14209 const char *name = h->elf.root.root.string;
14214 if (strncmp (name, "__libc_start_main", 17) == 0
14215 && (name[17] == 0 || name[17] == '@'))
14217 /* Allow crt1 branch to go via a toc adjusting
14218 stub. Other calls that never return could do
14219 the same, if we could detect such. */
14220 can_plt_call = TRUE;
14226 /* g++ as of 20130507 emits self-calls without a
14227 following nop. This is arguably wrong since we
14228 have conflicting information. On the one hand a
14229 global symbol and on the other a local call
14230 sequence, but don't error for this special case.
14231 It isn't possible to cheaply verify we have
14232 exactly such a call. Allow all calls to the same
14234 asection *code_sec = sec;
14236 if (get_opd_info (sec) != NULL)
14238 bfd_vma off = (relocation + addend
14239 - sec->output_section->vma
14240 - sec->output_offset);
14242 opd_entry_value (sec, off, &code_sec, NULL, FALSE);
14244 if (code_sec == input_section)
14245 can_plt_call = TRUE;
14250 if (stub_entry->stub_type == ppc_stub_plt_call
14251 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
14252 info->callbacks->einfo
14253 /* xgettext:c-format */
14254 (_("%H: call to `%T' lacks nop, can't restore toc; "
14255 "recompile with -fPIC\n"),
14256 input_bfd, input_section, rel->r_offset, sym_name);
14258 info->callbacks->einfo
14259 /* xgettext:c-format */
14260 (_("%H: call to `%T' lacks nop, can't restore toc; "
14261 "(-mcmodel=small toc adjust stub)\n"),
14262 input_bfd, input_section, rel->r_offset, sym_name);
14264 bfd_set_error (bfd_error_bad_value);
14269 && (stub_entry->stub_type == ppc_stub_plt_call
14270 || stub_entry->stub_type == ppc_stub_plt_call_r2save))
14271 unresolved_reloc = FALSE;
14274 if ((stub_entry == NULL
14275 || stub_entry->stub_type == ppc_stub_long_branch
14276 || stub_entry->stub_type == ppc_stub_plt_branch)
14277 && get_opd_info (sec) != NULL)
14279 /* The branch destination is the value of the opd entry. */
14280 bfd_vma off = (relocation + addend
14281 - sec->output_section->vma
14282 - sec->output_offset);
14283 bfd_vma dest = opd_entry_value (sec, off, NULL, NULL, FALSE);
14284 if (dest != (bfd_vma) -1)
14288 reloc_dest = DEST_OPD;
14292 /* If the branch is out of reach we ought to have a long
14294 from = (rel->r_offset
14295 + input_section->output_offset
14296 + input_section->output_section->vma);
14298 relocation += PPC64_LOCAL_ENTRY_OFFSET (fdh
14302 if (stub_entry != NULL
14303 && (stub_entry->stub_type == ppc_stub_long_branch
14304 || stub_entry->stub_type == ppc_stub_plt_branch)
14305 && (r_type == R_PPC64_ADDR14_BRTAKEN
14306 || r_type == R_PPC64_ADDR14_BRNTAKEN
14307 || (relocation + addend - from + max_br_offset
14308 < 2 * max_br_offset)))
14309 /* Don't use the stub if this branch is in range. */
14312 if (stub_entry != NULL)
14314 /* Munge up the value and addend so that we call the stub
14315 rather than the procedure directly. */
14316 asection *stub_sec = stub_entry->group->stub_sec;
14318 if (stub_entry->stub_type == ppc_stub_save_res)
14319 relocation += (stub_sec->output_offset
14320 + stub_sec->output_section->vma
14321 + stub_sec->size - htab->sfpr->size
14322 - htab->sfpr->output_offset
14323 - htab->sfpr->output_section->vma);
14325 relocation = (stub_entry->stub_offset
14326 + stub_sec->output_offset
14327 + stub_sec->output_section->vma);
14329 reloc_dest = DEST_STUB;
14331 if ((stub_entry->stub_type == ppc_stub_plt_call
14332 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
14333 && (ALWAYS_EMIT_R2SAVE
14334 || stub_entry->stub_type == ppc_stub_plt_call_r2save)
14335 && rel + 1 < relend
14336 && rel[1].r_offset == rel->r_offset + 4
14337 && ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
14345 /* Set 'a' bit. This is 0b00010 in BO field for branch
14346 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14347 for branch on CTR insns (BO == 1a00t or 1a01t). */
14348 if ((insn & (0x14 << 21)) == (0x04 << 21))
14349 insn |= 0x02 << 21;
14350 else if ((insn & (0x14 << 21)) == (0x10 << 21))
14351 insn |= 0x08 << 21;
14357 /* Invert 'y' bit if not the default. */
14358 if ((bfd_signed_vma) (relocation + addend - from) < 0)
14359 insn ^= 0x01 << 21;
14362 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
14365 /* NOP out calls to undefined weak functions.
14366 We can thus call a weak function without first
14367 checking whether the function is defined. */
14369 && h->elf.root.type == bfd_link_hash_undefweak
14370 && h->elf.dynindx == -1
14371 && r_type == R_PPC64_REL24
14375 bfd_put_32 (input_bfd, NOP, contents + rel->r_offset);
14381 /* Set `addend'. */
14386 info->callbacks->einfo
14387 /* xgettext:c-format */
14388 (_("%P: %B: unknown relocation type %d for `%T'\n"),
14389 input_bfd, (int) r_type, sym_name);
14391 bfd_set_error (bfd_error_bad_value);
14397 case R_PPC64_TLSGD:
14398 case R_PPC64_TLSLD:
14399 case R_PPC64_TOCSAVE:
14400 case R_PPC64_GNU_VTINHERIT:
14401 case R_PPC64_GNU_VTENTRY:
14402 case R_PPC64_ENTRY:
14405 /* GOT16 relocations. Like an ADDR16 using the symbol's
14406 address in the GOT as relocation value instead of the
14407 symbol's value itself. Also, create a GOT entry for the
14408 symbol and put the symbol value there. */
14409 case R_PPC64_GOT_TLSGD16:
14410 case R_PPC64_GOT_TLSGD16_LO:
14411 case R_PPC64_GOT_TLSGD16_HI:
14412 case R_PPC64_GOT_TLSGD16_HA:
14413 tls_type = TLS_TLS | TLS_GD;
14416 case R_PPC64_GOT_TLSLD16:
14417 case R_PPC64_GOT_TLSLD16_LO:
14418 case R_PPC64_GOT_TLSLD16_HI:
14419 case R_PPC64_GOT_TLSLD16_HA:
14420 tls_type = TLS_TLS | TLS_LD;
14423 case R_PPC64_GOT_TPREL16_DS:
14424 case R_PPC64_GOT_TPREL16_LO_DS:
14425 case R_PPC64_GOT_TPREL16_HI:
14426 case R_PPC64_GOT_TPREL16_HA:
14427 tls_type = TLS_TLS | TLS_TPREL;
14430 case R_PPC64_GOT_DTPREL16_DS:
14431 case R_PPC64_GOT_DTPREL16_LO_DS:
14432 case R_PPC64_GOT_DTPREL16_HI:
14433 case R_PPC64_GOT_DTPREL16_HA:
14434 tls_type = TLS_TLS | TLS_DTPREL;
14437 case R_PPC64_GOT16:
14438 case R_PPC64_GOT16_LO:
14439 case R_PPC64_GOT16_HI:
14440 case R_PPC64_GOT16_HA:
14441 case R_PPC64_GOT16_DS:
14442 case R_PPC64_GOT16_LO_DS:
14445 /* Relocation is to the entry for this symbol in the global
14450 unsigned long indx = 0;
14451 struct got_entry *ent;
14453 if (tls_type == (TLS_TLS | TLS_LD)
14455 || !h->elf.def_dynamic))
14456 ent = ppc64_tlsld_got (input_bfd);
14461 if (!htab->elf.dynamic_sections_created
14462 || h->elf.dynindx == -1
14463 || SYMBOL_REFERENCES_LOCAL (info, &h->elf)
14464 || UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf))
14465 /* This is actually a static link, or it is a
14466 -Bsymbolic link and the symbol is defined
14467 locally, or the symbol was forced to be local
14468 because of a version file. */
14472 indx = h->elf.dynindx;
14473 unresolved_reloc = FALSE;
14475 ent = h->elf.got.glist;
14479 if (local_got_ents == NULL)
14481 ent = local_got_ents[r_symndx];
14484 for (; ent != NULL; ent = ent->next)
14485 if (ent->addend == orig_rel.r_addend
14486 && ent->owner == input_bfd
14487 && ent->tls_type == tls_type)
14493 if (ent->is_indirect)
14494 ent = ent->got.ent;
14495 offp = &ent->got.offset;
14496 got = ppc64_elf_tdata (ent->owner)->got;
14500 /* The offset must always be a multiple of 8. We use the
14501 least significant bit to record whether we have already
14502 processed this entry. */
14504 if ((off & 1) != 0)
14508 /* Generate relocs for the dynamic linker, except in
14509 the case of TLSLD where we'll use one entry per
14517 ? h->elf.type == STT_GNU_IFUNC
14518 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
14521 relgot = htab->elf.irelplt;
14523 htab->local_ifunc_resolver = 1;
14524 else if (is_static_defined (&h->elf))
14525 htab->maybe_local_ifunc_resolver = 1;
14528 || (bfd_link_pic (info)
14530 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf)
14531 || (tls_type == (TLS_TLS | TLS_LD)
14532 && !h->elf.def_dynamic))
14533 && !(tls_type == (TLS_TLS | TLS_TPREL)
14534 && bfd_link_executable (info)
14535 && SYMBOL_REFERENCES_LOCAL (info, &h->elf))))
14536 relgot = ppc64_elf_tdata (ent->owner)->relgot;
14537 if (relgot != NULL)
14539 outrel.r_offset = (got->output_section->vma
14540 + got->output_offset
14542 outrel.r_addend = addend;
14543 if (tls_type & (TLS_LD | TLS_GD))
14545 outrel.r_addend = 0;
14546 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
14547 if (tls_type == (TLS_TLS | TLS_GD))
14549 loc = relgot->contents;
14550 loc += (relgot->reloc_count++
14551 * sizeof (Elf64_External_Rela));
14552 bfd_elf64_swap_reloca_out (output_bfd,
14554 outrel.r_offset += 8;
14555 outrel.r_addend = addend;
14557 = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
14560 else if (tls_type == (TLS_TLS | TLS_DTPREL))
14561 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
14562 else if (tls_type == (TLS_TLS | TLS_TPREL))
14563 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
14564 else if (indx != 0)
14565 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
14569 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14571 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
14573 /* Write the .got section contents for the sake
14575 loc = got->contents + off;
14576 bfd_put_64 (output_bfd, outrel.r_addend + relocation,
14580 if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
14582 outrel.r_addend += relocation;
14583 if (tls_type & (TLS_GD | TLS_DTPREL | TLS_TPREL))
14585 if (htab->elf.tls_sec == NULL)
14586 outrel.r_addend = 0;
14588 outrel.r_addend -= htab->elf.tls_sec->vma;
14591 loc = relgot->contents;
14592 loc += (relgot->reloc_count++
14593 * sizeof (Elf64_External_Rela));
14594 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
14597 /* Init the .got section contents here if we're not
14598 emitting a reloc. */
14601 relocation += addend;
14604 if (htab->elf.tls_sec == NULL)
14608 if (tls_type & TLS_LD)
14611 relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
14612 if (tls_type & TLS_TPREL)
14613 relocation += DTP_OFFSET - TP_OFFSET;
14616 if (tls_type & (TLS_GD | TLS_LD))
14618 bfd_put_64 (output_bfd, relocation,
14619 got->contents + off + 8);
14623 bfd_put_64 (output_bfd, relocation,
14624 got->contents + off);
14628 if (off >= (bfd_vma) -2)
14631 relocation = got->output_section->vma + got->output_offset + off;
14632 addend = -(TOCstart + htab->sec_info[input_section->id].toc_off);
14636 case R_PPC64_PLT16_HA:
14637 case R_PPC64_PLT16_HI:
14638 case R_PPC64_PLT16_LO:
14639 case R_PPC64_PLT32:
14640 case R_PPC64_PLT64:
14641 /* Relocation is to the entry for this symbol in the
14642 procedure linkage table. */
14644 struct plt_entry **plt_list = NULL;
14646 plt_list = &h->elf.plt.plist;
14647 else if (local_got_ents != NULL)
14649 struct plt_entry **local_plt = (struct plt_entry **)
14650 (local_got_ents + symtab_hdr->sh_info);
14651 unsigned char *local_got_tls_masks = (unsigned char *)
14652 (local_plt + symtab_hdr->sh_info);
14653 if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
14654 plt_list = local_plt + r_symndx;
14658 struct plt_entry *ent;
14660 for (ent = *plt_list; ent != NULL; ent = ent->next)
14661 if (ent->plt.offset != (bfd_vma) -1
14662 && ent->addend == orig_rel.r_addend)
14666 plt = htab->elf.splt;
14667 if (!htab->elf.dynamic_sections_created
14669 || h->elf.dynindx == -1)
14670 plt = htab->elf.iplt;
14671 relocation = (plt->output_section->vma
14672 + plt->output_offset
14673 + ent->plt.offset);
14675 unresolved_reloc = FALSE;
14683 /* Relocation value is TOC base. */
14684 relocation = TOCstart;
14685 if (r_symndx == STN_UNDEF)
14686 relocation += htab->sec_info[input_section->id].toc_off;
14687 else if (unresolved_reloc)
14689 else if (sec != NULL && sec->id < htab->sec_info_arr_size)
14690 relocation += htab->sec_info[sec->id].toc_off;
14692 unresolved_reloc = TRUE;
14695 /* TOC16 relocs. We want the offset relative to the TOC base,
14696 which is the address of the start of the TOC plus 0x8000.
14697 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14699 case R_PPC64_TOC16:
14700 case R_PPC64_TOC16_LO:
14701 case R_PPC64_TOC16_HI:
14702 case R_PPC64_TOC16_DS:
14703 case R_PPC64_TOC16_LO_DS:
14704 case R_PPC64_TOC16_HA:
14705 addend -= TOCstart + htab->sec_info[input_section->id].toc_off;
14708 /* Relocate against the beginning of the section. */
14709 case R_PPC64_SECTOFF:
14710 case R_PPC64_SECTOFF_LO:
14711 case R_PPC64_SECTOFF_HI:
14712 case R_PPC64_SECTOFF_DS:
14713 case R_PPC64_SECTOFF_LO_DS:
14714 case R_PPC64_SECTOFF_HA:
14716 addend -= sec->output_section->vma;
14719 case R_PPC64_REL16:
14720 case R_PPC64_REL16_LO:
14721 case R_PPC64_REL16_HI:
14722 case R_PPC64_REL16_HA:
14723 case R_PPC64_REL16DX_HA:
14726 case R_PPC64_REL14:
14727 case R_PPC64_REL14_BRNTAKEN:
14728 case R_PPC64_REL14_BRTAKEN:
14729 case R_PPC64_REL24:
14732 case R_PPC64_TPREL16:
14733 case R_PPC64_TPREL16_LO:
14734 case R_PPC64_TPREL16_HI:
14735 case R_PPC64_TPREL16_HA:
14736 case R_PPC64_TPREL16_DS:
14737 case R_PPC64_TPREL16_LO_DS:
14738 case R_PPC64_TPREL16_HIGH:
14739 case R_PPC64_TPREL16_HIGHA:
14740 case R_PPC64_TPREL16_HIGHER:
14741 case R_PPC64_TPREL16_HIGHERA:
14742 case R_PPC64_TPREL16_HIGHEST:
14743 case R_PPC64_TPREL16_HIGHESTA:
14745 && h->elf.root.type == bfd_link_hash_undefweak
14746 && h->elf.dynindx == -1)
14748 /* Make this relocation against an undefined weak symbol
14749 resolve to zero. This is really just a tweak, since
14750 code using weak externs ought to check that they are
14751 defined before using them. */
14752 bfd_byte *p = contents + rel->r_offset - d_offset;
14754 insn = bfd_get_32 (input_bfd, p);
14755 insn = _bfd_elf_ppc_at_tprel_transform (insn, 13);
14757 bfd_put_32 (input_bfd, insn, p);
14760 if (htab->elf.tls_sec != NULL)
14761 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
14762 /* The TPREL16 relocs shouldn't really be used in shared
14763 libs or with non-local symbols as that will result in
14764 DT_TEXTREL being set, but support them anyway. */
14767 case R_PPC64_DTPREL16:
14768 case R_PPC64_DTPREL16_LO:
14769 case R_PPC64_DTPREL16_HI:
14770 case R_PPC64_DTPREL16_HA:
14771 case R_PPC64_DTPREL16_DS:
14772 case R_PPC64_DTPREL16_LO_DS:
14773 case R_PPC64_DTPREL16_HIGH:
14774 case R_PPC64_DTPREL16_HIGHA:
14775 case R_PPC64_DTPREL16_HIGHER:
14776 case R_PPC64_DTPREL16_HIGHERA:
14777 case R_PPC64_DTPREL16_HIGHEST:
14778 case R_PPC64_DTPREL16_HIGHESTA:
14779 if (htab->elf.tls_sec != NULL)
14780 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
14783 case R_PPC64_ADDR64_LOCAL:
14784 addend += PPC64_LOCAL_ENTRY_OFFSET (h != NULL
14789 case R_PPC64_DTPMOD64:
14794 case R_PPC64_TPREL64:
14795 if (htab->elf.tls_sec != NULL)
14796 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
14799 case R_PPC64_DTPREL64:
14800 if (htab->elf.tls_sec != NULL)
14801 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
14802 /* Fall through. */
14804 /* Relocations that may need to be propagated if this is a
14806 case R_PPC64_REL30:
14807 case R_PPC64_REL32:
14808 case R_PPC64_REL64:
14809 case R_PPC64_ADDR14:
14810 case R_PPC64_ADDR14_BRNTAKEN:
14811 case R_PPC64_ADDR14_BRTAKEN:
14812 case R_PPC64_ADDR16:
14813 case R_PPC64_ADDR16_DS:
14814 case R_PPC64_ADDR16_HA:
14815 case R_PPC64_ADDR16_HI:
14816 case R_PPC64_ADDR16_HIGH:
14817 case R_PPC64_ADDR16_HIGHA:
14818 case R_PPC64_ADDR16_HIGHER:
14819 case R_PPC64_ADDR16_HIGHERA:
14820 case R_PPC64_ADDR16_HIGHEST:
14821 case R_PPC64_ADDR16_HIGHESTA:
14822 case R_PPC64_ADDR16_LO:
14823 case R_PPC64_ADDR16_LO_DS:
14824 case R_PPC64_ADDR24:
14825 case R_PPC64_ADDR32:
14826 case R_PPC64_ADDR64:
14827 case R_PPC64_UADDR16:
14828 case R_PPC64_UADDR32:
14829 case R_PPC64_UADDR64:
14831 if ((input_section->flags & SEC_ALLOC) == 0)
14834 if (NO_OPD_RELOCS && is_opd)
14837 if (bfd_link_pic (info)
14839 || h->dyn_relocs != NULL)
14840 && ((h != NULL && pc_dynrelocs (h))
14841 || must_be_dyn_reloc (info, r_type)))
14843 ? h->dyn_relocs != NULL
14844 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
14846 bfd_boolean skip, relocate;
14851 /* When generating a dynamic object, these relocations
14852 are copied into the output file to be resolved at run
14858 out_off = _bfd_elf_section_offset (output_bfd, info,
14859 input_section, rel->r_offset);
14860 if (out_off == (bfd_vma) -1)
14862 else if (out_off == (bfd_vma) -2)
14863 skip = TRUE, relocate = TRUE;
14864 out_off += (input_section->output_section->vma
14865 + input_section->output_offset);
14866 outrel.r_offset = out_off;
14867 outrel.r_addend = rel->r_addend;
14869 /* Optimize unaligned reloc use. */
14870 if ((r_type == R_PPC64_ADDR64 && (out_off & 7) != 0)
14871 || (r_type == R_PPC64_UADDR64 && (out_off & 7) == 0))
14872 r_type ^= R_PPC64_ADDR64 ^ R_PPC64_UADDR64;
14873 else if ((r_type == R_PPC64_ADDR32 && (out_off & 3) != 0)
14874 || (r_type == R_PPC64_UADDR32 && (out_off & 3) == 0))
14875 r_type ^= R_PPC64_ADDR32 ^ R_PPC64_UADDR32;
14876 else if ((r_type == R_PPC64_ADDR16 && (out_off & 1) != 0)
14877 || (r_type == R_PPC64_UADDR16 && (out_off & 1) == 0))
14878 r_type ^= R_PPC64_ADDR16 ^ R_PPC64_UADDR16;
14881 memset (&outrel, 0, sizeof outrel);
14882 else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
14884 && r_type != R_PPC64_TOC)
14886 indx = h->elf.dynindx;
14887 BFD_ASSERT (indx != -1);
14888 outrel.r_info = ELF64_R_INFO (indx, r_type);
14892 /* This symbol is local, or marked to become local,
14893 or this is an opd section reloc which must point
14894 at a local function. */
14895 outrel.r_addend += relocation;
14896 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
14898 if (is_opd && h != NULL)
14900 /* Lie about opd entries. This case occurs
14901 when building shared libraries and we
14902 reference a function in another shared
14903 lib. The same thing happens for a weak
14904 definition in an application that's
14905 overridden by a strong definition in a
14906 shared lib. (I believe this is a generic
14907 bug in binutils handling of weak syms.)
14908 In these cases we won't use the opd
14909 entry in this lib. */
14910 unresolved_reloc = FALSE;
14913 && r_type == R_PPC64_ADDR64
14915 ? h->elf.type == STT_GNU_IFUNC
14916 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
14917 outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
14920 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
14922 /* We need to relocate .opd contents for ld.so.
14923 Prelink also wants simple and consistent rules
14924 for relocs. This make all RELATIVE relocs have
14925 *r_offset equal to r_addend. */
14932 ? h->elf.type == STT_GNU_IFUNC
14933 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14935 info->callbacks->einfo
14936 /* xgettext:c-format */
14937 (_("%H: %s for indirect "
14938 "function `%T' unsupported\n"),
14939 input_bfd, input_section, rel->r_offset,
14940 ppc64_elf_howto_table[r_type]->name,
14944 else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
14946 else if (sec == NULL || sec->owner == NULL)
14948 bfd_set_error (bfd_error_bad_value);
14955 osec = sec->output_section;
14956 indx = elf_section_data (osec)->dynindx;
14960 if ((osec->flags & SEC_READONLY) == 0
14961 && htab->elf.data_index_section != NULL)
14962 osec = htab->elf.data_index_section;
14964 osec = htab->elf.text_index_section;
14965 indx = elf_section_data (osec)->dynindx;
14967 BFD_ASSERT (indx != 0);
14969 /* We are turning this relocation into one
14970 against a section symbol, so subtract out
14971 the output section's address but not the
14972 offset of the input section in the output
14974 outrel.r_addend -= osec->vma;
14977 outrel.r_info = ELF64_R_INFO (indx, r_type);
14981 sreloc = elf_section_data (input_section)->sreloc;
14983 ? h->elf.type == STT_GNU_IFUNC
14984 : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
14986 sreloc = htab->elf.irelplt;
14988 htab->local_ifunc_resolver = 1;
14989 else if (is_static_defined (&h->elf))
14990 htab->maybe_local_ifunc_resolver = 1;
14992 if (sreloc == NULL)
14995 if (sreloc->reloc_count * sizeof (Elf64_External_Rela)
14998 loc = sreloc->contents;
14999 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
15000 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
15002 /* If this reloc is against an external symbol, it will
15003 be computed at runtime, so there's no need to do
15004 anything now. However, for the sake of prelink ensure
15005 that the section contents are a known value. */
15008 unresolved_reloc = FALSE;
15009 /* The value chosen here is quite arbitrary as ld.so
15010 ignores section contents except for the special
15011 case of .opd where the contents might be accessed
15012 before relocation. Choose zero, as that won't
15013 cause reloc overflow. */
15016 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
15017 to improve backward compatibility with older
15019 if (r_type == R_PPC64_ADDR64)
15020 addend = outrel.r_addend;
15021 /* Adjust pc_relative relocs to have zero in *r_offset. */
15022 else if (ppc64_elf_howto_table[r_type]->pc_relative)
15023 addend = outrel.r_offset;
15029 case R_PPC64_GLOB_DAT:
15030 case R_PPC64_JMP_SLOT:
15031 case R_PPC64_JMP_IREL:
15032 case R_PPC64_RELATIVE:
15033 /* We shouldn't ever see these dynamic relocs in relocatable
15035 /* Fall through. */
15037 case R_PPC64_PLTGOT16:
15038 case R_PPC64_PLTGOT16_DS:
15039 case R_PPC64_PLTGOT16_HA:
15040 case R_PPC64_PLTGOT16_HI:
15041 case R_PPC64_PLTGOT16_LO:
15042 case R_PPC64_PLTGOT16_LO_DS:
15043 case R_PPC64_PLTREL32:
15044 case R_PPC64_PLTREL64:
15045 /* These ones haven't been implemented yet. */
15047 info->callbacks->einfo
15048 /* xgettext:c-format */
15049 (_("%P: %B: %s is not supported for `%T'\n"),
15051 ppc64_elf_howto_table[r_type]->name, sym_name);
15053 bfd_set_error (bfd_error_invalid_operation);
15058 /* Multi-instruction sequences that access the TOC can be
15059 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15060 to nop; addi rb,r2,x; */
15061 howto = ppc64_elf_howto_table[(int) r_type];
15067 case R_PPC64_GOT_TLSLD16_HI:
15068 case R_PPC64_GOT_TLSGD16_HI:
15069 case R_PPC64_GOT_TPREL16_HI:
15070 case R_PPC64_GOT_DTPREL16_HI:
15071 case R_PPC64_GOT16_HI:
15072 case R_PPC64_TOC16_HI:
15073 /* These relocs would only be useful if building up an
15074 offset to later add to r2, perhaps in an indexed
15075 addressing mode instruction. Don't try to optimize.
15076 Unfortunately, the possibility of someone building up an
15077 offset like this or even with the HA relocs, means that
15078 we need to check the high insn when optimizing the low
15082 case R_PPC64_GOT_TLSLD16_HA:
15083 case R_PPC64_GOT_TLSGD16_HA:
15084 case R_PPC64_GOT_TPREL16_HA:
15085 case R_PPC64_GOT_DTPREL16_HA:
15086 case R_PPC64_GOT16_HA:
15087 case R_PPC64_TOC16_HA:
15088 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
15089 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
15091 bfd_byte *p = contents + (rel->r_offset & ~3);
15092 bfd_put_32 (input_bfd, NOP, p);
15096 case R_PPC64_GOT_TLSLD16_LO:
15097 case R_PPC64_GOT_TLSGD16_LO:
15098 case R_PPC64_GOT_TPREL16_LO_DS:
15099 case R_PPC64_GOT_DTPREL16_LO_DS:
15100 case R_PPC64_GOT16_LO:
15101 case R_PPC64_GOT16_LO_DS:
15102 case R_PPC64_TOC16_LO:
15103 case R_PPC64_TOC16_LO_DS:
15104 if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
15105 && !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
15107 bfd_byte *p = contents + (rel->r_offset & ~3);
15108 insn = bfd_get_32 (input_bfd, p);
15109 if ((insn & (0x3f << 26)) == 12u << 26 /* addic */)
15111 /* Transform addic to addi when we change reg. */
15112 insn &= ~((0x3f << 26) | (0x1f << 16));
15113 insn |= (14u << 26) | (2 << 16);
15117 insn &= ~(0x1f << 16);
15120 bfd_put_32 (input_bfd, insn, p);
15124 case R_PPC64_TPREL16_HA:
15125 if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
15127 bfd_byte *p = contents + (rel->r_offset & ~3);
15128 insn = bfd_get_32 (input_bfd, p);
15129 if ((insn & ((0x3f << 26) | 0x1f << 16))
15130 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15131 /* xgettext:c-format */
15132 info->callbacks->minfo
15133 (_("%H: warning: %s unexpected insn %#x.\n"),
15134 input_bfd, input_section, rel->r_offset, howto->name, insn);
15136 bfd_put_32 (input_bfd, NOP, p);
15140 case R_PPC64_TPREL16_LO:
15141 case R_PPC64_TPREL16_LO_DS:
15142 if (htab->do_tls_opt && relocation + addend + 0x8000 < 0x10000)
15144 bfd_byte *p = contents + (rel->r_offset & ~3);
15145 insn = bfd_get_32 (input_bfd, p);
15146 insn &= ~(0x1f << 16);
15148 bfd_put_32 (input_bfd, insn, p);
15153 /* Do any further special processing. */
15159 case R_PPC64_REL16_HA:
15160 case R_PPC64_REL16DX_HA:
15161 case R_PPC64_ADDR16_HA:
15162 case R_PPC64_ADDR16_HIGHA:
15163 case R_PPC64_ADDR16_HIGHERA:
15164 case R_PPC64_ADDR16_HIGHESTA:
15165 case R_PPC64_TOC16_HA:
15166 case R_PPC64_SECTOFF_HA:
15167 case R_PPC64_TPREL16_HA:
15168 case R_PPC64_TPREL16_HIGHA:
15169 case R_PPC64_TPREL16_HIGHERA:
15170 case R_PPC64_TPREL16_HIGHESTA:
15171 case R_PPC64_DTPREL16_HA:
15172 case R_PPC64_DTPREL16_HIGHA:
15173 case R_PPC64_DTPREL16_HIGHERA:
15174 case R_PPC64_DTPREL16_HIGHESTA:
15175 /* It's just possible that this symbol is a weak symbol
15176 that's not actually defined anywhere. In that case,
15177 'sec' would be NULL, and we should leave the symbol
15178 alone (it will be set to zero elsewhere in the link). */
15181 /* Fall through. */
15183 case R_PPC64_GOT16_HA:
15184 case R_PPC64_PLTGOT16_HA:
15185 case R_PPC64_PLT16_HA:
15186 case R_PPC64_GOT_TLSGD16_HA:
15187 case R_PPC64_GOT_TLSLD16_HA:
15188 case R_PPC64_GOT_TPREL16_HA:
15189 case R_PPC64_GOT_DTPREL16_HA:
15190 /* Add 0x10000 if sign bit in 0:15 is set.
15191 Bits 0:15 are not used. */
15195 case R_PPC64_ADDR16_DS:
15196 case R_PPC64_ADDR16_LO_DS:
15197 case R_PPC64_GOT16_DS:
15198 case R_PPC64_GOT16_LO_DS:
15199 case R_PPC64_PLT16_LO_DS:
15200 case R_PPC64_SECTOFF_DS:
15201 case R_PPC64_SECTOFF_LO_DS:
15202 case R_PPC64_TOC16_DS:
15203 case R_PPC64_TOC16_LO_DS:
15204 case R_PPC64_PLTGOT16_DS:
15205 case R_PPC64_PLTGOT16_LO_DS:
15206 case R_PPC64_GOT_TPREL16_DS:
15207 case R_PPC64_GOT_TPREL16_LO_DS:
15208 case R_PPC64_GOT_DTPREL16_DS:
15209 case R_PPC64_GOT_DTPREL16_LO_DS:
15210 case R_PPC64_TPREL16_DS:
15211 case R_PPC64_TPREL16_LO_DS:
15212 case R_PPC64_DTPREL16_DS:
15213 case R_PPC64_DTPREL16_LO_DS:
15214 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
15216 /* If this reloc is against an lq, lxv, or stxv insn, then
15217 the value must be a multiple of 16. This is somewhat of
15218 a hack, but the "correct" way to do this by defining _DQ
15219 forms of all the _DS relocs bloats all reloc switches in
15220 this file. It doesn't make much sense to use these
15221 relocs in data, so testing the insn should be safe. */
15222 if ((insn & (0x3f << 26)) == (56u << 26)
15223 || ((insn & (0x3f << 26)) == (61u << 26) && (insn & 3) == 1))
15225 relocation += addend;
15226 addend = insn & (mask ^ 3);
15227 if ((relocation & mask) != 0)
15229 relocation ^= relocation & mask;
15230 info->callbacks->einfo
15231 /* xgettext:c-format */
15232 (_("%H: error: %s not a multiple of %u\n"),
15233 input_bfd, input_section, rel->r_offset,
15236 bfd_set_error (bfd_error_bad_value);
15243 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15244 because such sections are not SEC_ALLOC and thus ld.so will
15245 not process them. */
15246 if (unresolved_reloc
15247 && !((input_section->flags & SEC_DEBUGGING) != 0
15248 && h->elf.def_dynamic)
15249 && _bfd_elf_section_offset (output_bfd, info, input_section,
15250 rel->r_offset) != (bfd_vma) -1)
15252 info->callbacks->einfo
15253 /* xgettext:c-format */
15254 (_("%H: unresolvable %s against `%T'\n"),
15255 input_bfd, input_section, rel->r_offset,
15257 h->elf.root.root.string);
15261 /* 16-bit fields in insns mostly have signed values, but a
15262 few insns have 16-bit unsigned values. Really, we should
15263 have different reloc types. */
15264 if (howto->complain_on_overflow != complain_overflow_dont
15265 && howto->dst_mask == 0xffff
15266 && (input_section->flags & SEC_CODE) != 0)
15268 enum complain_overflow complain = complain_overflow_signed;
15270 insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
15271 if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
15272 complain = complain_overflow_bitfield;
15273 else if (howto->rightshift == 0
15274 ? ((insn & (0x3f << 26)) == 28u << 26 /* andi */
15275 || (insn & (0x3f << 26)) == 24u << 26 /* ori */
15276 || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
15277 : ((insn & (0x3f << 26)) == 29u << 26 /* andis */
15278 || (insn & (0x3f << 26)) == 25u << 26 /* oris */
15279 || (insn & (0x3f << 26)) == 27u << 26 /* xoris */))
15280 complain = complain_overflow_unsigned;
15281 if (howto->complain_on_overflow != complain)
15283 alt_howto = *howto;
15284 alt_howto.complain_on_overflow = complain;
15285 howto = &alt_howto;
15289 if (r_type == R_PPC64_REL16DX_HA)
15291 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15292 if (rel->r_offset + 4 > input_section->size)
15293 r = bfd_reloc_outofrange;
15296 relocation += addend;
15297 relocation -= (rel->r_offset
15298 + input_section->output_offset
15299 + input_section->output_section->vma);
15300 relocation = (bfd_signed_vma) relocation >> 16;
15301 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
15303 insn |= (relocation & 0xffc1) | ((relocation & 0x3e) << 15);
15304 bfd_put_32 (input_bfd, insn, contents + rel->r_offset);
15306 if (relocation + 0x8000 > 0xffff)
15307 r = bfd_reloc_overflow;
15311 r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
15312 rel->r_offset, relocation, addend);
15314 if (r != bfd_reloc_ok)
15316 char *more_info = NULL;
15317 const char *reloc_name = howto->name;
15319 if (reloc_dest != DEST_NORMAL)
15321 more_info = bfd_malloc (strlen (reloc_name) + 8);
15322 if (more_info != NULL)
15324 strcpy (more_info, reloc_name);
15325 strcat (more_info, (reloc_dest == DEST_OPD
15326 ? " (OPD)" : " (stub)"));
15327 reloc_name = more_info;
15331 if (r == bfd_reloc_overflow)
15333 /* On code like "if (foo) foo();" don't report overflow
15334 on a branch to zero when foo is undefined. */
15336 && (reloc_dest == DEST_STUB
15338 && (h->elf.root.type == bfd_link_hash_undefweak
15339 || h->elf.root.type == bfd_link_hash_undefined)
15340 && is_branch_reloc (r_type))))
15341 info->callbacks->reloc_overflow (info, &h->elf.root,
15342 sym_name, reloc_name,
15344 input_bfd, input_section,
15349 info->callbacks->einfo
15350 /* xgettext:c-format */
15351 (_("%H: %s against `%T': error %d\n"),
15352 input_bfd, input_section, rel->r_offset,
15353 reloc_name, sym_name, (int) r);
15356 if (more_info != NULL)
15366 Elf_Internal_Shdr *rel_hdr;
15367 size_t deleted = rel - wrel;
15369 rel_hdr = _bfd_elf_single_rel_hdr (input_section->output_section);
15370 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
15371 if (rel_hdr->sh_size == 0)
15373 /* It is too late to remove an empty reloc section. Leave
15375 ??? What is wrong with an empty section??? */
15376 rel_hdr->sh_size = rel_hdr->sh_entsize;
15379 rel_hdr = _bfd_elf_single_rel_hdr (input_section);
15380 rel_hdr->sh_size -= rel_hdr->sh_entsize * deleted;
15381 input_section->reloc_count -= deleted;
15384 /* If we're emitting relocations, then shortly after this function
15385 returns, reloc offsets and addends for this section will be
15386 adjusted. Worse, reloc symbol indices will be for the output
15387 file rather than the input. Save a copy of the relocs for
15388 opd_entry_value. */
15389 if (is_opd && (info->emitrelocations || bfd_link_relocatable (info)))
15392 amt = input_section->reloc_count * sizeof (Elf_Internal_Rela);
15393 rel = bfd_alloc (input_bfd, amt);
15394 BFD_ASSERT (ppc64_elf_tdata (input_bfd)->opd.relocs == NULL);
15395 ppc64_elf_tdata (input_bfd)->opd.relocs = rel;
15398 memcpy (rel, relocs, amt);
15403 /* Adjust the value of any local symbols in opd sections. */
15406 ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
15407 const char *name ATTRIBUTE_UNUSED,
15408 Elf_Internal_Sym *elfsym,
15409 asection *input_sec,
15410 struct elf_link_hash_entry *h)
15412 struct _opd_sec_data *opd;
15419 opd = get_opd_info (input_sec);
15420 if (opd == NULL || opd->adjust == NULL)
15423 value = elfsym->st_value - input_sec->output_offset;
15424 if (!bfd_link_relocatable (info))
15425 value -= input_sec->output_section->vma;
15427 adjust = opd->adjust[OPD_NDX (value)];
15431 elfsym->st_value += adjust;
15435 /* Finish up dynamic symbol handling. We set the contents of various
15436 dynamic sections here. */
15439 ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
15440 struct bfd_link_info *info,
15441 struct elf_link_hash_entry *h,
15442 Elf_Internal_Sym *sym)
15444 struct ppc_link_hash_table *htab;
15445 struct plt_entry *ent;
15446 Elf_Internal_Rela rela;
15449 htab = ppc_hash_table (info);
15453 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
15454 if (ent->plt.offset != (bfd_vma) -1)
15456 /* This symbol has an entry in the procedure linkage
15457 table. Set it up. */
15458 if (!htab->elf.dynamic_sections_created
15459 || h->dynindx == -1)
15461 BFD_ASSERT (h->type == STT_GNU_IFUNC
15463 && (h->root.type == bfd_link_hash_defined
15464 || h->root.type == bfd_link_hash_defweak));
15465 rela.r_offset = (htab->elf.iplt->output_section->vma
15466 + htab->elf.iplt->output_offset
15467 + ent->plt.offset);
15469 rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
15471 rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
15472 rela.r_addend = (h->root.u.def.value
15473 + h->root.u.def.section->output_offset
15474 + h->root.u.def.section->output_section->vma
15476 loc = (htab->elf.irelplt->contents
15477 + (htab->elf.irelplt->reloc_count++
15478 * sizeof (Elf64_External_Rela)));
15479 htab->local_ifunc_resolver = 1;
15483 rela.r_offset = (htab->elf.splt->output_section->vma
15484 + htab->elf.splt->output_offset
15485 + ent->plt.offset);
15486 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
15487 rela.r_addend = ent->addend;
15488 loc = (htab->elf.srelplt->contents
15489 + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
15490 / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
15491 if (h->type == STT_GNU_IFUNC && is_static_defined (h))
15492 htab->maybe_local_ifunc_resolver = 1;
15494 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
15496 if (!htab->opd_abi)
15498 if (!h->def_regular)
15500 /* Mark the symbol as undefined, rather than as
15501 defined in glink. Leave the value if there were
15502 any relocations where pointer equality matters
15503 (this is a clue for the dynamic linker, to make
15504 function pointer comparisons work between an
15505 application and shared library), otherwise set it
15507 sym->st_shndx = SHN_UNDEF;
15508 if (!h->pointer_equality_needed)
15510 else if (!h->ref_regular_nonweak)
15512 /* This breaks function pointer comparisons, but
15513 that is better than breaking tests for a NULL
15514 function pointer. */
15523 /* This symbol needs a copy reloc. Set it up. */
15526 if (h->dynindx == -1
15527 || (h->root.type != bfd_link_hash_defined
15528 && h->root.type != bfd_link_hash_defweak)
15529 || htab->elf.srelbss == NULL
15530 || htab->elf.sreldynrelro == NULL)
15533 rela.r_offset = (h->root.u.def.value
15534 + h->root.u.def.section->output_section->vma
15535 + h->root.u.def.section->output_offset);
15536 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
15538 if (h->root.u.def.section == htab->elf.sdynrelro)
15539 srel = htab->elf.sreldynrelro;
15541 srel = htab->elf.srelbss;
15542 loc = srel->contents;
15543 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela);
15544 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
15550 /* Used to decide how to sort relocs in an optimal manner for the
15551 dynamic linker, before writing them out. */
15553 static enum elf_reloc_type_class
15554 ppc64_elf_reloc_type_class (const struct bfd_link_info *info,
15555 const asection *rel_sec,
15556 const Elf_Internal_Rela *rela)
15558 enum elf_ppc64_reloc_type r_type;
15559 struct ppc_link_hash_table *htab = ppc_hash_table (info);
15561 if (rel_sec == htab->elf.irelplt)
15562 return reloc_class_ifunc;
15564 r_type = ELF64_R_TYPE (rela->r_info);
15567 case R_PPC64_RELATIVE:
15568 return reloc_class_relative;
15569 case R_PPC64_JMP_SLOT:
15570 return reloc_class_plt;
15572 return reloc_class_copy;
15574 return reloc_class_normal;
15578 /* Finish up the dynamic sections. */
15581 ppc64_elf_finish_dynamic_sections (bfd *output_bfd,
15582 struct bfd_link_info *info)
15584 struct ppc_link_hash_table *htab;
15588 htab = ppc_hash_table (info);
15592 dynobj = htab->elf.dynobj;
15593 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
15595 if (htab->elf.dynamic_sections_created)
15597 Elf64_External_Dyn *dyncon, *dynconend;
15599 if (sdyn == NULL || htab->elf.sgot == NULL)
15602 dyncon = (Elf64_External_Dyn *) sdyn->contents;
15603 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
15604 for (; dyncon < dynconend; dyncon++)
15606 Elf_Internal_Dyn dyn;
15609 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
15616 case DT_PPC64_GLINK:
15618 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
15619 /* We stupidly defined DT_PPC64_GLINK to be the start
15620 of glink rather than the first entry point, which is
15621 what ld.so needs, and now have a bigger stub to
15622 support automatic multiple TOCs. */
15623 dyn.d_un.d_ptr += GLINK_PLTRESOLVE_SIZE (htab) - 8 * 4;
15627 s = bfd_get_section_by_name (output_bfd, ".opd");
15630 dyn.d_un.d_ptr = s->vma;
15634 if (htab->do_multi_toc && htab->multi_toc_needed)
15635 dyn.d_un.d_val |= PPC64_OPT_MULTI_TOC;
15636 if (htab->has_plt_localentry0)
15637 dyn.d_un.d_val |= PPC64_OPT_LOCALENTRY;
15640 case DT_PPC64_OPDSZ:
15641 s = bfd_get_section_by_name (output_bfd, ".opd");
15644 dyn.d_un.d_val = s->size;
15648 s = htab->elf.splt;
15649 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
15653 s = htab->elf.srelplt;
15654 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
15658 dyn.d_un.d_val = htab->elf.srelplt->size;
15662 if (htab->local_ifunc_resolver)
15663 info->callbacks->einfo
15664 (_("%X%P: text relocations and GNU indirect "
15665 "functions will result in a segfault at runtime\n"));
15666 else if (htab->maybe_local_ifunc_resolver)
15667 info->callbacks->einfo
15668 (_("%P: warning: text relocations and GNU indirect "
15669 "functions may result in a segfault at runtime\n"));
15673 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
15677 if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0
15678 && htab->elf.sgot->output_section != bfd_abs_section_ptr)
15680 /* Fill in the first entry in the global offset table.
15681 We use it to hold the link-time TOCbase. */
15682 bfd_put_64 (output_bfd,
15683 elf_gp (output_bfd) + TOC_BASE_OFF,
15684 htab->elf.sgot->contents);
15686 /* Set .got entry size. */
15687 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 8;
15690 if (htab->elf.splt != NULL && htab->elf.splt->size != 0
15691 && htab->elf.splt->output_section != bfd_abs_section_ptr)
15693 /* Set .plt entry size. */
15694 elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
15695 = PLT_ENTRY_SIZE (htab);
15698 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15699 brlt ourselves if emitrelocations. */
15700 if (htab->brlt != NULL
15701 && htab->brlt->reloc_count != 0
15702 && !_bfd_elf_link_output_relocs (output_bfd,
15704 elf_section_data (htab->brlt)->rela.hdr,
15705 elf_section_data (htab->brlt)->relocs,
15709 if (htab->glink != NULL
15710 && htab->glink->reloc_count != 0
15711 && !_bfd_elf_link_output_relocs (output_bfd,
15713 elf_section_data (htab->glink)->rela.hdr,
15714 elf_section_data (htab->glink)->relocs,
15718 if (htab->glink_eh_frame != NULL
15719 && htab->glink_eh_frame->size != 0)
15723 struct map_stub *group;
15726 p = htab->glink_eh_frame->contents;
15727 p += (sizeof (glink_eh_frame_cie) + align - 1) & -align;
15729 for (group = htab->group; group != NULL; group = group->next)
15730 if (group->stub_sec != NULL)
15732 /* Offset to stub section. */
15733 val = (group->stub_sec->output_section->vma
15734 + group->stub_sec->output_offset);
15735 val -= (htab->glink_eh_frame->output_section->vma
15736 + htab->glink_eh_frame->output_offset
15737 + (p + 8 - htab->glink_eh_frame->contents));
15738 if (val + 0x80000000 > 0xffffffff)
15740 info->callbacks->einfo
15741 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
15742 group->stub_sec->name);
15745 bfd_put_32 (dynobj, val, p + 8);
15746 p += stub_eh_frame_size (group, align);
15748 if (htab->glink != NULL && htab->glink->size != 0)
15750 /* Offset to .glink. */
15751 val = (htab->glink->output_section->vma
15752 + htab->glink->output_offset
15754 val -= (htab->glink_eh_frame->output_section->vma
15755 + htab->glink_eh_frame->output_offset
15756 + (p + 8 - htab->glink_eh_frame->contents));
15757 if (val + 0x80000000 > 0xffffffff)
15759 info->callbacks->einfo
15760 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
15761 htab->glink->name);
15764 bfd_put_32 (dynobj, val, p + 8);
15765 p += (24 + align - 1) & -align;
15768 if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
15769 && !_bfd_elf_write_section_eh_frame (output_bfd, info,
15770 htab->glink_eh_frame,
15771 htab->glink_eh_frame->contents))
15775 /* We need to handle writing out multiple GOT sections ourselves,
15776 since we didn't add them to DYNOBJ. We know dynobj is the first
15778 while ((dynobj = dynobj->link.next) != NULL)
15782 if (!is_ppc64_elf (dynobj))
15785 s = ppc64_elf_tdata (dynobj)->got;
15788 && s->output_section != bfd_abs_section_ptr
15789 && !bfd_set_section_contents (output_bfd, s->output_section,
15790 s->contents, s->output_offset,
15793 s = ppc64_elf_tdata (dynobj)->relgot;
15796 && s->output_section != bfd_abs_section_ptr
15797 && !bfd_set_section_contents (output_bfd, s->output_section,
15798 s->contents, s->output_offset,
15806 #include "elf64-target.h"
15808 /* FreeBSD support */
15810 #undef TARGET_LITTLE_SYM
15811 #undef TARGET_LITTLE_NAME
15813 #undef TARGET_BIG_SYM
15814 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
15815 #undef TARGET_BIG_NAME
15816 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
15819 #define ELF_OSABI ELFOSABI_FREEBSD
15822 #define elf64_bed elf64_powerpc_fbsd_bed
15824 #include "elf64-target.h"