1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2024 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 */
28 /* The assembler should generate a full set of section symbols even
29 when they appear unused. The linux kernel build tool recordmcount
31 #define TARGET_KEEP_UNUSED_SECTION_SYMBOLS true
39 #include "elf/ppc64.h"
40 #include "elf64-ppc.h"
43 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
44 #define OCTETS_PER_BYTE(ABFD, SEC) 1
46 static bfd_reloc_status_type ppc64_elf_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_branch_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_reloc_status_type ppc64_elf_toc_reloc
57 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
58 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
59 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
60 static bfd_reloc_status_type ppc64_elf_toc64_reloc
61 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
62 static bfd_reloc_status_type ppc64_elf_prefix_reloc
63 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
64 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
65 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
66 static bfd_vma opd_entry_value
67 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bool);
69 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
70 #define TARGET_LITTLE_NAME "elf64-powerpcle"
71 #define TARGET_BIG_SYM powerpc_elf64_vec
72 #define TARGET_BIG_NAME "elf64-powerpc"
73 #define ELF_ARCH bfd_arch_powerpc
74 #define ELF_TARGET_ID PPC64_ELF_DATA
75 #define ELF_MACHINE_CODE EM_PPC64
76 #define ELF_MAXPAGESIZE 0x10000
77 #define ELF_COMMONPAGESIZE 0x1000
78 #define elf_info_to_howto ppc64_elf_info_to_howto
80 #define elf_backend_want_got_sym 0
81 #define elf_backend_want_plt_sym 0
82 #define elf_backend_plt_alignment 3
83 #define elf_backend_plt_not_loaded 1
84 #define elf_backend_got_header_size 8
85 #define elf_backend_want_dynrelro 1
86 #define elf_backend_can_gc_sections 1
87 #define elf_backend_can_refcount 1
88 #define elf_backend_rela_normal 1
89 #define elf_backend_dtrel_excludes_plt 1
90 #define elf_backend_default_execstack 0
92 #define bfd_elf64_mkobject ppc64_elf_mkobject
93 #define bfd_elf64_bfd_free_cached_info ppc64_elf_free_cached_info
94 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
95 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
96 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
97 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
98 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
99 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
100 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
101 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
102 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
104 #define elf_backend_object_p ppc64_elf_object_p
105 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
106 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
107 #define elf_backend_write_core_note ppc64_elf_write_core_note
108 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
109 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
110 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
111 #define elf_backend_check_directives ppc64_elf_before_check_relocs
112 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
113 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
114 #define elf_backend_check_relocs ppc64_elf_check_relocs
115 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
116 #define elf_backend_gc_keep ppc64_elf_gc_keep
117 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
118 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
119 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
120 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
121 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
122 #define elf_backend_early_size_sections ppc64_elf_edit
123 #define elf_backend_late_size_sections ppc64_elf_late_size_sections
124 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
125 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
126 #define elf_backend_action_discarded ppc64_elf_action_discarded
127 #define elf_backend_relocate_section ppc64_elf_relocate_section
128 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
129 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
130 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
131 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
132 #define elf_backend_special_sections ppc64_elf_special_sections
133 #define elf_backend_section_flags ppc64_elf_section_flags
134 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
135 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
136 #define elf_backend_get_reloc_section bfd_get_section_by_name
138 /* The name of the dynamic interpreter. This is put in the .interp
140 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
142 /* The size in bytes of an entry in the procedure linkage table. */
143 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
144 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
146 /* The initial size of the plt reserved for the dynamic linker. */
147 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
149 /* Offsets to some stack save slots. */
151 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
152 /* This one is dodgy. ELFv2 does not have a linker word, so use the
153 CR save slot. Used only by optimised __tls_get_addr call stub,
154 relying on __tls_get_addr_opt not saving CR.. */
155 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
157 /* TOC base pointers offset from start of TOC. */
158 #define TOC_BASE_OFF 0x8000
159 /* TOC base alignment. */
160 #define TOC_BASE_ALIGN 256
162 /* Offset of tp and dtp pointers from start of TLS block. */
163 #define TP_OFFSET 0x7000
164 #define DTP_OFFSET 0x8000
166 /* .plt call stub instructions. The normal stub is like this, but
167 sometimes the .plt entry crosses a 64k boundary and we need to
168 insert an addi to adjust r11. */
169 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
170 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
171 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
172 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
173 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
174 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
175 #define BCTR 0x4e800420 /* bctr */
177 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
178 #define ADDI_R12_R11 0x398b0000 /* addi %r12,%r11,off@l */
179 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
180 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
181 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
183 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
184 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
185 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
186 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
187 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
188 #define BNECTR 0x4ca20420 /* bnectr+ */
189 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
191 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
192 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
193 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
195 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
196 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
197 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
199 #define LI_R11_0 0x39600000 /* li %r11,0 */
200 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
201 #define LIS_R11 0x3d600000 /* lis %r11,xxx@ha */
202 #define LIS_R12 0x3d800000 /* lis %r12,xxx@ha */
203 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
204 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
205 #define ADDIS_R12_R11 0x3d8b0000 /* addis %r12,%r11,xxx@ha */
206 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
207 #define ORIS_R12_R12_0 0x658c0000 /* oris %r12,%r12,xxx@hi */
208 #define ORI_R11_R11_0 0x616b0000 /* ori %r11,%r11,xxx@l */
209 #define ORI_R12_R12_0 0x618c0000 /* ori %r12,%r12,xxx@l */
210 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
211 #define SLDI_R11_R11_34 0x796b1746 /* sldi %r11,%r11,34 */
212 #define SLDI_R12_R12_32 0x799c07c6 /* sldi %r12,%r12,32 */
213 #define LDX_R12_R11_R12 0x7d8b602a /* ldx %r12,%r11,%r12 */
214 #define ADD_R12_R11_R12 0x7d8b6214 /* add %r12,%r11,%r12 */
215 #define PADDI_R12_PC 0x0610000039800000ULL
216 #define PLD_R12_PC 0x04100000e5800000ULL
217 #define PNOP 0x0700000000000000ULL
219 /* __glink_PLTresolve stub instructions. We enter with the index in
220 R0 for ELFv1, and the address of a glink branch in R12 for ELFv2. */
221 #define GLINK_PLTRESOLVE_SIZE(htab) \
222 (8u + (htab->opd_abi ? 11 * 4 : htab->has_plt_localentry0 ? 14 * 4 : 13 * 4))
226 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
227 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
229 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
230 /* ld %2,(0b-1b)(%11) */
231 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
232 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
239 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
240 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
241 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
242 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
243 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
244 #define LD_R0_0R11 0xe80b0000 /* ld %r0,0(%r11) */
245 #define ADD_R11_R0_R11 0x7d605a14 /* add %r11,%r0,%r11 */
248 #define NOP 0x60000000
250 /* Some other nops. */
251 #define CROR_151515 0x4def7b82
252 #define CROR_313131 0x4ffffb82
254 /* .glink entries for the first 32k functions are two instructions. */
255 #define LI_R0_0 0x38000000 /* li %r0,0 */
256 #define B_DOT 0x48000000 /* b . */
258 /* After that, we need two instructions to load the index, followed by
260 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
261 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
263 /* Instructions used by the save and restore reg functions. */
264 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
265 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
266 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
267 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
268 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
269 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
270 #define LI_R12_0 0x39800000 /* li %r12,0 */
271 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
272 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
273 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
274 #define BLR 0x4e800020 /* blr */
276 /* Since .opd is an array of descriptors and each entry will end up
277 with identical R_PPC64_RELATIVE relocs, there is really no need to
278 propagate .opd relocs; The dynamic linker should be taught to
279 relocate .opd without reloc entries. */
280 #ifndef NO_OPD_RELOCS
281 #define NO_OPD_RELOCS 0
285 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
289 abiversion (bfd
*abfd
)
291 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
295 set_abiversion (bfd
*abfd
, int ver
)
297 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
298 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
301 #define is_ppc64_elf(bfd) \
302 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
303 && elf_object_id (bfd) == PPC64_ELF_DATA)
305 /* Relocation HOWTO's. */
306 /* Like other ELF RELA targets that don't apply multiple
307 field-altering relocations to the same localation, src_mask is
308 always zero and pcrel_offset is the same as pc_relative.
309 PowerPC can always use a zero bitpos, even when the field is not at
310 the LSB. For example, a REL24 could use rightshift=2, bisize=24
311 and bitpos=2 which matches the ABI description, or as we do here,
312 rightshift=0, bitsize=26 and bitpos=0. */
313 #define HOW(type, size, bitsize, mask, rightshift, pc_relative, \
314 complain, special_func) \
315 HOWTO (type, rightshift, size, bitsize, pc_relative, 0, \
316 complain_overflow_ ## complain, special_func, \
317 #type, false, 0, mask, pc_relative)
319 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
321 static reloc_howto_type ppc64_elf_howto_raw
[] =
323 /* This reloc does nothing. */
324 HOW (R_PPC64_NONE
, 0, 0, 0, 0, false, dont
,
325 bfd_elf_generic_reloc
),
327 /* A standard 32 bit relocation. */
328 HOW (R_PPC64_ADDR32
, 4, 32, 0xffffffff, 0, false, bitfield
,
329 bfd_elf_generic_reloc
),
331 /* An absolute 26 bit branch; the lower two bits must be zero.
332 FIXME: we don't check that, we just clear them. */
333 HOW (R_PPC64_ADDR24
, 4, 26, 0x03fffffc, 0, false, bitfield
,
334 bfd_elf_generic_reloc
),
336 /* A standard 16 bit relocation. */
337 HOW (R_PPC64_ADDR16
, 2, 16, 0xffff, 0, false, bitfield
,
338 bfd_elf_generic_reloc
),
340 /* A 16 bit relocation without overflow. */
341 HOW (R_PPC64_ADDR16_LO
, 2, 16, 0xffff, 0, false, dont
,
342 bfd_elf_generic_reloc
),
344 /* Bits 16-31 of an address. */
345 HOW (R_PPC64_ADDR16_HI
, 2, 16, 0xffff, 16, false, signed,
346 bfd_elf_generic_reloc
),
348 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
349 bits, treated as a signed number, is negative. */
350 HOW (R_PPC64_ADDR16_HA
, 2, 16, 0xffff, 16, false, signed,
353 /* An absolute 16 bit branch; the lower two bits must be zero.
354 FIXME: we don't check that, we just clear them. */
355 HOW (R_PPC64_ADDR14
, 4, 16, 0x0000fffc, 0, false, signed,
356 ppc64_elf_branch_reloc
),
358 /* An absolute 16 bit branch, for which bit 10 should be set to
359 indicate that the branch is expected to be taken. The lower two
360 bits must be zero. */
361 HOW (R_PPC64_ADDR14_BRTAKEN
, 4, 16, 0x0000fffc, 0, false, signed,
362 ppc64_elf_brtaken_reloc
),
364 /* An absolute 16 bit branch, for which bit 10 should be set to
365 indicate that the branch is not expected to be taken. The lower
366 two bits must be zero. */
367 HOW (R_PPC64_ADDR14_BRNTAKEN
, 4, 16, 0x0000fffc, 0, false, signed,
368 ppc64_elf_brtaken_reloc
),
370 /* A relative 26 bit branch; the lower two bits must be zero. */
371 HOW (R_PPC64_REL24
, 4, 26, 0x03fffffc, 0, true, signed,
372 ppc64_elf_branch_reloc
),
374 /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer. */
375 HOW (R_PPC64_REL24_NOTOC
, 4, 26, 0x03fffffc, 0, true, signed,
376 ppc64_elf_branch_reloc
),
378 /* Another variant, when p10 insns can't be used on stubs. */
379 HOW (R_PPC64_REL24_P9NOTOC
, 4, 26, 0x03fffffc, 0, true, signed,
380 ppc64_elf_branch_reloc
),
382 /* A relative 16 bit branch; the lower two bits must be zero. */
383 HOW (R_PPC64_REL14
, 4, 16, 0x0000fffc, 0, true, signed,
384 ppc64_elf_branch_reloc
),
386 /* A relative 16 bit branch. Bit 10 should be set to indicate that
387 the branch is expected to be taken. The lower two bits must be
389 HOW (R_PPC64_REL14_BRTAKEN
, 4, 16, 0x0000fffc, 0, true, signed,
390 ppc64_elf_brtaken_reloc
),
392 /* A relative 16 bit branch. Bit 10 should be set to indicate that
393 the branch is not expected to be taken. The lower two bits must
395 HOW (R_PPC64_REL14_BRNTAKEN
, 4, 16, 0x0000fffc, 0, true, signed,
396 ppc64_elf_brtaken_reloc
),
398 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
400 HOW (R_PPC64_GOT16
, 2, 16, 0xffff, 0, false, signed,
401 ppc64_elf_unhandled_reloc
),
403 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
405 HOW (R_PPC64_GOT16_LO
, 2, 16, 0xffff, 0, false, dont
,
406 ppc64_elf_unhandled_reloc
),
408 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
410 HOW (R_PPC64_GOT16_HI
, 2, 16, 0xffff, 16, false, signed,
411 ppc64_elf_unhandled_reloc
),
413 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
415 HOW (R_PPC64_GOT16_HA
, 2, 16, 0xffff, 16, false, signed,
416 ppc64_elf_unhandled_reloc
),
418 /* This is used only by the dynamic linker. The symbol should exist
419 both in the object being run and in some shared library. The
420 dynamic linker copies the data addressed by the symbol from the
421 shared library into the object, because the object being
422 run has to have the data at some particular address. */
423 HOW (R_PPC64_COPY
, 0, 0, 0, 0, false, dont
,
424 ppc64_elf_unhandled_reloc
),
426 /* Like R_PPC64_ADDR64, but used when setting global offset table
428 HOW (R_PPC64_GLOB_DAT
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
429 ppc64_elf_unhandled_reloc
),
431 /* Created by the link editor. Marks a procedure linkage table
432 entry for a symbol. */
433 HOW (R_PPC64_JMP_SLOT
, 0, 0, 0, 0, false, dont
,
434 ppc64_elf_unhandled_reloc
),
436 /* Used only by the dynamic linker. When the object is run, this
437 doubleword64 is set to the load address of the object, plus the
439 HOW (R_PPC64_RELATIVE
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
440 bfd_elf_generic_reloc
),
442 /* Like R_PPC64_ADDR32, but may be unaligned. */
443 HOW (R_PPC64_UADDR32
, 4, 32, 0xffffffff, 0, false, bitfield
,
444 bfd_elf_generic_reloc
),
446 /* Like R_PPC64_ADDR16, but may be unaligned. */
447 HOW (R_PPC64_UADDR16
, 2, 16, 0xffff, 0, false, bitfield
,
448 bfd_elf_generic_reloc
),
450 /* 32-bit PC relative. */
451 HOW (R_PPC64_REL32
, 4, 32, 0xffffffff, 0, true, signed,
452 bfd_elf_generic_reloc
),
454 /* 32-bit relocation to the symbol's procedure linkage table. */
455 HOW (R_PPC64_PLT32
, 4, 32, 0xffffffff, 0, false, bitfield
,
456 ppc64_elf_unhandled_reloc
),
458 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
459 FIXME: R_PPC64_PLTREL32 not supported. */
460 HOW (R_PPC64_PLTREL32
, 4, 32, 0xffffffff, 0, true, signed,
461 ppc64_elf_unhandled_reloc
),
463 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
465 HOW (R_PPC64_PLT16_LO
, 2, 16, 0xffff, 0, false, dont
,
466 ppc64_elf_unhandled_reloc
),
468 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
470 HOW (R_PPC64_PLT16_HI
, 2, 16, 0xffff, 16, false, signed,
471 ppc64_elf_unhandled_reloc
),
473 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
475 HOW (R_PPC64_PLT16_HA
, 2, 16, 0xffff, 16, false, signed,
476 ppc64_elf_unhandled_reloc
),
478 /* 16-bit section relative relocation. */
479 HOW (R_PPC64_SECTOFF
, 2, 16, 0xffff, 0, false, signed,
480 ppc64_elf_sectoff_reloc
),
482 /* Like R_PPC64_SECTOFF, but no overflow warning. */
483 HOW (R_PPC64_SECTOFF_LO
, 2, 16, 0xffff, 0, false, dont
,
484 ppc64_elf_sectoff_reloc
),
486 /* 16-bit upper half section relative relocation. */
487 HOW (R_PPC64_SECTOFF_HI
, 2, 16, 0xffff, 16, false, signed,
488 ppc64_elf_sectoff_reloc
),
490 /* 16-bit upper half adjusted section relative relocation. */
491 HOW (R_PPC64_SECTOFF_HA
, 2, 16, 0xffff, 16, false, signed,
492 ppc64_elf_sectoff_ha_reloc
),
494 /* Like R_PPC64_REL24 without touching the two least significant bits. */
495 HOW (R_PPC64_REL30
, 4, 30, 0xfffffffc, 2, true, dont
,
496 bfd_elf_generic_reloc
),
498 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
500 /* A standard 64-bit relocation. */
501 HOW (R_PPC64_ADDR64
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
502 bfd_elf_generic_reloc
),
504 /* The bits 32-47 of an address. */
505 HOW (R_PPC64_ADDR16_HIGHER
, 2, 16, 0xffff, 32, false, dont
,
506 bfd_elf_generic_reloc
),
508 /* The bits 32-47 of an address, plus 1 if the contents of the low
509 16 bits, treated as a signed number, is negative. */
510 HOW (R_PPC64_ADDR16_HIGHERA
, 2, 16, 0xffff, 32, false, dont
,
513 /* The bits 48-63 of an address. */
514 HOW (R_PPC64_ADDR16_HIGHEST
, 2, 16, 0xffff, 48, false, dont
,
515 bfd_elf_generic_reloc
),
517 /* The bits 48-63 of an address, plus 1 if the contents of the low
518 16 bits, treated as a signed number, is negative. */
519 HOW (R_PPC64_ADDR16_HIGHESTA
, 2, 16, 0xffff, 48, false, dont
,
522 /* Like ADDR64, but may be unaligned. */
523 HOW (R_PPC64_UADDR64
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
524 bfd_elf_generic_reloc
),
526 /* 64-bit relative relocation. */
527 HOW (R_PPC64_REL64
, 8, 64, 0xffffffffffffffffULL
, 0, true, dont
,
528 bfd_elf_generic_reloc
),
530 /* 64-bit relocation to the symbol's procedure linkage table. */
531 HOW (R_PPC64_PLT64
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
532 ppc64_elf_unhandled_reloc
),
534 /* 64-bit PC relative relocation to the symbol's procedure linkage
536 /* FIXME: R_PPC64_PLTREL64 not supported. */
537 HOW (R_PPC64_PLTREL64
, 8, 64, 0xffffffffffffffffULL
, 0, true, dont
,
538 ppc64_elf_unhandled_reloc
),
540 /* 16 bit TOC-relative relocation. */
541 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
542 HOW (R_PPC64_TOC16
, 2, 16, 0xffff, 0, false, signed,
543 ppc64_elf_toc_reloc
),
545 /* 16 bit TOC-relative relocation without overflow. */
546 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
547 HOW (R_PPC64_TOC16_LO
, 2, 16, 0xffff, 0, false, dont
,
548 ppc64_elf_toc_reloc
),
550 /* 16 bit TOC-relative relocation, high 16 bits. */
551 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
552 HOW (R_PPC64_TOC16_HI
, 2, 16, 0xffff, 16, false, signed,
553 ppc64_elf_toc_reloc
),
555 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
556 contents of the low 16 bits, treated as a signed number, is
558 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
559 HOW (R_PPC64_TOC16_HA
, 2, 16, 0xffff, 16, false, signed,
560 ppc64_elf_toc_ha_reloc
),
562 /* 64-bit relocation; insert value of TOC base (.TOC.). */
563 /* R_PPC64_TOC 51 doubleword64 .TOC. */
564 HOW (R_PPC64_TOC
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
565 ppc64_elf_toc64_reloc
),
567 /* Like R_PPC64_GOT16, but also informs the link editor that the
568 value to relocate may (!) refer to a PLT entry which the link
569 editor (a) may replace with the symbol value. If the link editor
570 is unable to fully resolve the symbol, it may (b) create a PLT
571 entry and store the address to the new PLT entry in the GOT.
572 This permits lazy resolution of function symbols at run time.
573 The link editor may also skip all of this and just (c) emit a
574 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
575 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
576 HOW (R_PPC64_PLTGOT16
, 2, 16, 0xffff, 0, false,signed,
577 ppc64_elf_unhandled_reloc
),
579 /* Like R_PPC64_PLTGOT16, but without overflow. */
580 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
581 HOW (R_PPC64_PLTGOT16_LO
, 2, 16, 0xffff, 0, false, dont
,
582 ppc64_elf_unhandled_reloc
),
584 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
585 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
586 HOW (R_PPC64_PLTGOT16_HI
, 2, 16, 0xffff, 16, false, signed,
587 ppc64_elf_unhandled_reloc
),
589 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
590 1 if the contents of the low 16 bits, treated as a signed number,
592 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
593 HOW (R_PPC64_PLTGOT16_HA
, 2, 16, 0xffff, 16, false, signed,
594 ppc64_elf_unhandled_reloc
),
596 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
597 HOW (R_PPC64_ADDR16_DS
, 2, 16, 0xfffc, 0, false, signed,
598 bfd_elf_generic_reloc
),
600 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
601 HOW (R_PPC64_ADDR16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
602 bfd_elf_generic_reloc
),
604 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
605 HOW (R_PPC64_GOT16_DS
, 2, 16, 0xfffc, 0, false, signed,
606 ppc64_elf_unhandled_reloc
),
608 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
609 HOW (R_PPC64_GOT16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
610 ppc64_elf_unhandled_reloc
),
612 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
613 HOW (R_PPC64_PLT16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
614 ppc64_elf_unhandled_reloc
),
616 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
617 HOW (R_PPC64_SECTOFF_DS
, 2, 16, 0xfffc, 0, false, signed,
618 ppc64_elf_sectoff_reloc
),
620 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
621 HOW (R_PPC64_SECTOFF_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
622 ppc64_elf_sectoff_reloc
),
624 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
625 HOW (R_PPC64_TOC16_DS
, 2, 16, 0xfffc, 0, false, signed,
626 ppc64_elf_toc_reloc
),
628 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
629 HOW (R_PPC64_TOC16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
630 ppc64_elf_toc_reloc
),
632 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
633 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
634 HOW (R_PPC64_PLTGOT16_DS
, 2, 16, 0xfffc, 0, false, signed,
635 ppc64_elf_unhandled_reloc
),
637 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
638 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
639 HOW (R_PPC64_PLTGOT16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
640 ppc64_elf_unhandled_reloc
),
642 /* Marker relocs for TLS. */
643 HOW (R_PPC64_TLS
, 4, 32, 0, 0, false, dont
,
644 bfd_elf_generic_reloc
),
646 HOW (R_PPC64_TLSGD
, 4, 32, 0, 0, false, dont
,
647 bfd_elf_generic_reloc
),
649 HOW (R_PPC64_TLSLD
, 4, 32, 0, 0, false, dont
,
650 bfd_elf_generic_reloc
),
652 /* Marker reloc for optimizing r2 save in prologue rather than on
653 each plt call stub. */
654 HOW (R_PPC64_TOCSAVE
, 4, 32, 0, 0, false, dont
,
655 bfd_elf_generic_reloc
),
657 /* Marker relocs on inline plt call instructions. */
658 HOW (R_PPC64_PLTSEQ
, 4, 32, 0, 0, false, dont
,
659 bfd_elf_generic_reloc
),
661 HOW (R_PPC64_PLTCALL
, 4, 32, 0, 0, false, dont
,
662 bfd_elf_generic_reloc
),
664 /* Computes the load module index of the load module that contains the
665 definition of its TLS sym. */
666 HOW (R_PPC64_DTPMOD64
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
667 ppc64_elf_unhandled_reloc
),
669 /* Computes a dtv-relative displacement, the difference between the value
670 of sym+add and the base address of the thread-local storage block that
671 contains the definition of sym, minus 0x8000. */
672 HOW (R_PPC64_DTPREL64
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
673 ppc64_elf_unhandled_reloc
),
675 /* A 16 bit dtprel reloc. */
676 HOW (R_PPC64_DTPREL16
, 2, 16, 0xffff, 0, false, signed,
677 ppc64_elf_unhandled_reloc
),
679 /* Like DTPREL16, but no overflow. */
680 HOW (R_PPC64_DTPREL16_LO
, 2, 16, 0xffff, 0, false, dont
,
681 ppc64_elf_unhandled_reloc
),
683 /* Like DTPREL16_LO, but next higher group of 16 bits. */
684 HOW (R_PPC64_DTPREL16_HI
, 2, 16, 0xffff, 16, false, signed,
685 ppc64_elf_unhandled_reloc
),
687 /* Like DTPREL16_HI, but adjust for low 16 bits. */
688 HOW (R_PPC64_DTPREL16_HA
, 2, 16, 0xffff, 16, false, signed,
689 ppc64_elf_unhandled_reloc
),
691 /* Like DTPREL16_HI, but next higher group of 16 bits. */
692 HOW (R_PPC64_DTPREL16_HIGHER
, 2, 16, 0xffff, 32, false, dont
,
693 ppc64_elf_unhandled_reloc
),
695 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
696 HOW (R_PPC64_DTPREL16_HIGHERA
, 2, 16, 0xffff, 32, false, dont
,
697 ppc64_elf_unhandled_reloc
),
699 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
700 HOW (R_PPC64_DTPREL16_HIGHEST
, 2, 16, 0xffff, 48, false, dont
,
701 ppc64_elf_unhandled_reloc
),
703 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
704 HOW (R_PPC64_DTPREL16_HIGHESTA
, 2, 16, 0xffff, 48, false, dont
,
705 ppc64_elf_unhandled_reloc
),
707 /* Like DTPREL16, but for insns with a DS field. */
708 HOW (R_PPC64_DTPREL16_DS
, 2, 16, 0xfffc, 0, false, signed,
709 ppc64_elf_unhandled_reloc
),
711 /* Like DTPREL16_DS, but no overflow. */
712 HOW (R_PPC64_DTPREL16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
713 ppc64_elf_unhandled_reloc
),
715 /* Computes a tp-relative displacement, the difference between the value of
716 sym+add and the value of the thread pointer (r13). */
717 HOW (R_PPC64_TPREL64
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
718 ppc64_elf_unhandled_reloc
),
720 /* A 16 bit tprel reloc. */
721 HOW (R_PPC64_TPREL16
, 2, 16, 0xffff, 0, false, signed,
722 ppc64_elf_unhandled_reloc
),
724 /* Like TPREL16, but no overflow. */
725 HOW (R_PPC64_TPREL16_LO
, 2, 16, 0xffff, 0, false, dont
,
726 ppc64_elf_unhandled_reloc
),
728 /* Like TPREL16_LO, but next higher group of 16 bits. */
729 HOW (R_PPC64_TPREL16_HI
, 2, 16, 0xffff, 16, false, signed,
730 ppc64_elf_unhandled_reloc
),
732 /* Like TPREL16_HI, but adjust for low 16 bits. */
733 HOW (R_PPC64_TPREL16_HA
, 2, 16, 0xffff, 16, false, signed,
734 ppc64_elf_unhandled_reloc
),
736 /* Like TPREL16_HI, but next higher group of 16 bits. */
737 HOW (R_PPC64_TPREL16_HIGHER
, 2, 16, 0xffff, 32, false, dont
,
738 ppc64_elf_unhandled_reloc
),
740 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
741 HOW (R_PPC64_TPREL16_HIGHERA
, 2, 16, 0xffff, 32, false, dont
,
742 ppc64_elf_unhandled_reloc
),
744 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
745 HOW (R_PPC64_TPREL16_HIGHEST
, 2, 16, 0xffff, 48, false, dont
,
746 ppc64_elf_unhandled_reloc
),
748 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
749 HOW (R_PPC64_TPREL16_HIGHESTA
, 2, 16, 0xffff, 48, false, dont
,
750 ppc64_elf_unhandled_reloc
),
752 /* Like TPREL16, but for insns with a DS field. */
753 HOW (R_PPC64_TPREL16_DS
, 2, 16, 0xfffc, 0, false, signed,
754 ppc64_elf_unhandled_reloc
),
756 /* Like TPREL16_DS, but no overflow. */
757 HOW (R_PPC64_TPREL16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
758 ppc64_elf_unhandled_reloc
),
760 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
761 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
762 to the first entry relative to the TOC base (r2). */
763 HOW (R_PPC64_GOT_TLSGD16
, 2, 16, 0xffff, 0, false, signed,
764 ppc64_elf_unhandled_reloc
),
766 /* Like GOT_TLSGD16, but no overflow. */
767 HOW (R_PPC64_GOT_TLSGD16_LO
, 2, 16, 0xffff, 0, false, dont
,
768 ppc64_elf_unhandled_reloc
),
770 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
771 HOW (R_PPC64_GOT_TLSGD16_HI
, 2, 16, 0xffff, 16, false, signed,
772 ppc64_elf_unhandled_reloc
),
774 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
775 HOW (R_PPC64_GOT_TLSGD16_HA
, 2, 16, 0xffff, 16, false, signed,
776 ppc64_elf_unhandled_reloc
),
778 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
779 with values (sym+add)@dtpmod and zero, and computes the offset to the
780 first entry relative to the TOC base (r2). */
781 HOW (R_PPC64_GOT_TLSLD16
, 2, 16, 0xffff, 0, false, signed,
782 ppc64_elf_unhandled_reloc
),
784 /* Like GOT_TLSLD16, but no overflow. */
785 HOW (R_PPC64_GOT_TLSLD16_LO
, 2, 16, 0xffff, 0, false, dont
,
786 ppc64_elf_unhandled_reloc
),
788 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
789 HOW (R_PPC64_GOT_TLSLD16_HI
, 2, 16, 0xffff, 16, false, signed,
790 ppc64_elf_unhandled_reloc
),
792 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
793 HOW (R_PPC64_GOT_TLSLD16_HA
, 2, 16, 0xffff, 16, false, signed,
794 ppc64_elf_unhandled_reloc
),
796 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
797 the offset to the entry relative to the TOC base (r2). */
798 HOW (R_PPC64_GOT_DTPREL16_DS
, 2, 16, 0xfffc, 0, false, signed,
799 ppc64_elf_unhandled_reloc
),
801 /* Like GOT_DTPREL16_DS, but no overflow. */
802 HOW (R_PPC64_GOT_DTPREL16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
803 ppc64_elf_unhandled_reloc
),
805 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
806 HOW (R_PPC64_GOT_DTPREL16_HI
, 2, 16, 0xffff, 16, false, signed,
807 ppc64_elf_unhandled_reloc
),
809 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
810 HOW (R_PPC64_GOT_DTPREL16_HA
, 2, 16, 0xffff, 16, false, signed,
811 ppc64_elf_unhandled_reloc
),
813 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
814 offset to the entry relative to the TOC base (r2). */
815 HOW (R_PPC64_GOT_TPREL16_DS
, 2, 16, 0xfffc, 0, false, signed,
816 ppc64_elf_unhandled_reloc
),
818 /* Like GOT_TPREL16_DS, but no overflow. */
819 HOW (R_PPC64_GOT_TPREL16_LO_DS
, 2, 16, 0xfffc, 0, false, dont
,
820 ppc64_elf_unhandled_reloc
),
822 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
823 HOW (R_PPC64_GOT_TPREL16_HI
, 2, 16, 0xffff, 16, false, signed,
824 ppc64_elf_unhandled_reloc
),
826 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
827 HOW (R_PPC64_GOT_TPREL16_HA
, 2, 16, 0xffff, 16, false, signed,
828 ppc64_elf_unhandled_reloc
),
830 HOW (R_PPC64_JMP_IREL
, 0, 0, 0, 0, false, dont
,
831 ppc64_elf_unhandled_reloc
),
833 HOW (R_PPC64_IRELATIVE
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
834 bfd_elf_generic_reloc
),
836 /* A 16 bit relative relocation. */
837 HOW (R_PPC64_REL16
, 2, 16, 0xffff, 0, true, signed,
838 bfd_elf_generic_reloc
),
840 /* A 16 bit relative relocation without overflow. */
841 HOW (R_PPC64_REL16_LO
, 2, 16, 0xffff, 0, true, dont
,
842 bfd_elf_generic_reloc
),
844 /* The high order 16 bits of a relative address. */
845 HOW (R_PPC64_REL16_HI
, 2, 16, 0xffff, 16, true, signed,
846 bfd_elf_generic_reloc
),
848 /* The high order 16 bits of a relative address, plus 1 if the contents of
849 the low 16 bits, treated as a signed number, is negative. */
850 HOW (R_PPC64_REL16_HA
, 2, 16, 0xffff, 16, true, signed,
853 HOW (R_PPC64_REL16_HIGH
, 2, 16, 0xffff, 16, true, dont
,
854 bfd_elf_generic_reloc
),
856 HOW (R_PPC64_REL16_HIGHA
, 2, 16, 0xffff, 16, true, dont
,
859 HOW (R_PPC64_REL16_HIGHER
, 2, 16, 0xffff, 32, true, dont
,
860 bfd_elf_generic_reloc
),
862 HOW (R_PPC64_REL16_HIGHERA
, 2, 16, 0xffff, 32, true, dont
,
865 HOW (R_PPC64_REL16_HIGHEST
, 2, 16, 0xffff, 48, true, dont
,
866 bfd_elf_generic_reloc
),
868 HOW (R_PPC64_REL16_HIGHESTA
, 2, 16, 0xffff, 48, true, dont
,
871 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
872 HOW (R_PPC64_REL16DX_HA
, 4, 16, 0x1fffc1, 16, true, signed,
875 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
876 HOW (R_PPC64_16DX_HA
, 4, 16, 0x1fffc1, 16, false, signed,
879 /* Like R_PPC64_ADDR16_HI, but no overflow. */
880 HOW (R_PPC64_ADDR16_HIGH
, 2, 16, 0xffff, 16, false, dont
,
881 bfd_elf_generic_reloc
),
883 /* Like R_PPC64_ADDR16_HA, but no overflow. */
884 HOW (R_PPC64_ADDR16_HIGHA
, 2, 16, 0xffff, 16, false, dont
,
887 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
888 HOW (R_PPC64_DTPREL16_HIGH
, 2, 16, 0xffff, 16, false, dont
,
889 ppc64_elf_unhandled_reloc
),
891 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
892 HOW (R_PPC64_DTPREL16_HIGHA
, 2, 16, 0xffff, 16, false, dont
,
893 ppc64_elf_unhandled_reloc
),
895 /* Like R_PPC64_TPREL16_HI, but no overflow. */
896 HOW (R_PPC64_TPREL16_HIGH
, 2, 16, 0xffff, 16, false, dont
,
897 ppc64_elf_unhandled_reloc
),
899 /* Like R_PPC64_TPREL16_HA, but no overflow. */
900 HOW (R_PPC64_TPREL16_HIGHA
, 2, 16, 0xffff, 16, false, dont
,
901 ppc64_elf_unhandled_reloc
),
903 /* Marker reloc on ELFv2 large-model function entry. */
904 HOW (R_PPC64_ENTRY
, 4, 32, 0, 0, false, dont
,
905 bfd_elf_generic_reloc
),
907 /* Like ADDR64, but use local entry point of function. */
908 HOW (R_PPC64_ADDR64_LOCAL
, 8, 64, 0xffffffffffffffffULL
, 0, false, dont
,
909 bfd_elf_generic_reloc
),
911 HOW (R_PPC64_PLTSEQ_NOTOC
, 4, 32, 0, 0, false, dont
,
912 bfd_elf_generic_reloc
),
914 HOW (R_PPC64_PLTCALL_NOTOC
, 4, 32, 0, 0, false, dont
,
915 bfd_elf_generic_reloc
),
917 HOW (R_PPC64_PCREL_OPT
, 4, 32, 0, 0, false, dont
,
918 bfd_elf_generic_reloc
),
920 HOW (R_PPC64_D34
, 8, 34, 0x3ffff0000ffffULL
, 0, false, signed,
921 ppc64_elf_prefix_reloc
),
923 HOW (R_PPC64_D34_LO
, 8, 34, 0x3ffff0000ffffULL
, 0, false, dont
,
924 ppc64_elf_prefix_reloc
),
926 HOW (R_PPC64_D34_HI30
, 8, 34, 0x3ffff0000ffffULL
, 34, false, dont
,
927 ppc64_elf_prefix_reloc
),
929 HOW (R_PPC64_D34_HA30
, 8, 34, 0x3ffff0000ffffULL
, 34, false, dont
,
930 ppc64_elf_prefix_reloc
),
932 HOW (R_PPC64_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
933 ppc64_elf_prefix_reloc
),
935 HOW (R_PPC64_GOT_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
936 ppc64_elf_unhandled_reloc
),
938 HOW (R_PPC64_PLT_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
939 ppc64_elf_unhandled_reloc
),
941 HOW (R_PPC64_PLT_PCREL34_NOTOC
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
942 ppc64_elf_unhandled_reloc
),
944 HOW (R_PPC64_TPREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, false, signed,
945 ppc64_elf_unhandled_reloc
),
947 HOW (R_PPC64_DTPREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, false, signed,
948 ppc64_elf_unhandled_reloc
),
950 HOW (R_PPC64_GOT_TLSGD_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
951 ppc64_elf_unhandled_reloc
),
953 HOW (R_PPC64_GOT_TLSLD_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
954 ppc64_elf_unhandled_reloc
),
956 HOW (R_PPC64_GOT_TPREL_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
957 ppc64_elf_unhandled_reloc
),
959 HOW (R_PPC64_GOT_DTPREL_PCREL34
, 8, 34, 0x3ffff0000ffffULL
, 0, true, signed,
960 ppc64_elf_unhandled_reloc
),
962 HOW (R_PPC64_ADDR16_HIGHER34
, 2, 16, 0xffff, 34, false, dont
,
963 bfd_elf_generic_reloc
),
965 HOW (R_PPC64_ADDR16_HIGHERA34
, 2, 16, 0xffff, 34, false, dont
,
968 HOW (R_PPC64_ADDR16_HIGHEST34
, 2, 16, 0xffff, 50, false, dont
,
969 bfd_elf_generic_reloc
),
971 HOW (R_PPC64_ADDR16_HIGHESTA34
, 2, 16, 0xffff, 50, false, dont
,
974 HOW (R_PPC64_REL16_HIGHER34
, 2, 16, 0xffff, 34, true, dont
,
975 bfd_elf_generic_reloc
),
977 HOW (R_PPC64_REL16_HIGHERA34
, 2, 16, 0xffff, 34, true, dont
,
980 HOW (R_PPC64_REL16_HIGHEST34
, 2, 16, 0xffff, 50, true, dont
,
981 bfd_elf_generic_reloc
),
983 HOW (R_PPC64_REL16_HIGHESTA34
, 2, 16, 0xffff, 50, true, dont
,
986 HOW (R_PPC64_D28
, 8, 28, 0xfff0000ffffULL
, 0, false, signed,
987 ppc64_elf_prefix_reloc
),
989 HOW (R_PPC64_PCREL28
, 8, 28, 0xfff0000ffffULL
, 0, true, signed,
990 ppc64_elf_prefix_reloc
),
992 /* GNU extension to record C++ vtable hierarchy. */
993 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, false, dont
,
996 /* GNU extension to record C++ vtable member usage. */
997 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, false, dont
,
1002 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1006 ppc_howto_init (void)
1008 unsigned int i
, type
;
1010 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1012 type
= ppc64_elf_howto_raw
[i
].type
;
1013 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
1014 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1018 static reloc_howto_type
*
1019 ppc64_elf_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1021 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1023 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1024 /* Initialize howto table if needed. */
1030 /* xgettext:c-format */
1031 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
1033 bfd_set_error (bfd_error_bad_value
);
1036 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1038 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1040 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1042 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1044 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1046 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1048 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
1050 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1052 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
1054 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1056 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1058 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1060 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1062 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
1064 case BFD_RELOC_PPC64_REL24_P9NOTOC
: r
= R_PPC64_REL24_P9NOTOC
;
1066 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1068 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1070 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1072 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1074 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1076 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1078 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1080 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1082 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1084 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1086 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1088 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1090 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1092 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1094 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1096 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1098 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1100 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1102 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1104 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1106 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1108 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1110 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1112 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1114 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1116 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1118 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1120 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1122 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1124 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1126 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1128 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1130 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1132 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1134 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1136 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1138 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1140 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1142 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1144 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1146 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1148 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1150 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1152 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1154 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1156 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1158 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1160 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1162 case BFD_RELOC_PPC64_TLS_PCREL
:
1163 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1165 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1167 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1169 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1171 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1173 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1175 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1177 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1179 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1181 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1183 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1185 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1187 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1189 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1191 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1193 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1195 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1197 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1199 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1201 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1203 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1205 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1207 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1209 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1211 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1213 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1215 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1217 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1219 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1221 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1223 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1225 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1227 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1229 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1231 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1233 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1235 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1237 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1239 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1241 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1243 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1245 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1247 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1249 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1251 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1253 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1255 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1257 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1259 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1261 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1263 case BFD_RELOC_PPC64_REL16_HIGH
: r
= R_PPC64_REL16_HIGH
;
1265 case BFD_RELOC_PPC64_REL16_HIGHA
: r
= R_PPC64_REL16_HIGHA
;
1267 case BFD_RELOC_PPC64_REL16_HIGHER
: r
= R_PPC64_REL16_HIGHER
;
1269 case BFD_RELOC_PPC64_REL16_HIGHERA
: r
= R_PPC64_REL16_HIGHERA
;
1271 case BFD_RELOC_PPC64_REL16_HIGHEST
: r
= R_PPC64_REL16_HIGHEST
;
1273 case BFD_RELOC_PPC64_REL16_HIGHESTA
: r
= R_PPC64_REL16_HIGHESTA
;
1275 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1277 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1279 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1281 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1283 case BFD_RELOC_PPC64_D34
: r
= R_PPC64_D34
;
1285 case BFD_RELOC_PPC64_D34_LO
: r
= R_PPC64_D34_LO
;
1287 case BFD_RELOC_PPC64_D34_HI30
: r
= R_PPC64_D34_HI30
;
1289 case BFD_RELOC_PPC64_D34_HA30
: r
= R_PPC64_D34_HA30
;
1291 case BFD_RELOC_PPC64_PCREL34
: r
= R_PPC64_PCREL34
;
1293 case BFD_RELOC_PPC64_GOT_PCREL34
: r
= R_PPC64_GOT_PCREL34
;
1295 case BFD_RELOC_PPC64_PLT_PCREL34
: r
= R_PPC64_PLT_PCREL34
;
1297 case BFD_RELOC_PPC64_TPREL34
: r
= R_PPC64_TPREL34
;
1299 case BFD_RELOC_PPC64_DTPREL34
: r
= R_PPC64_DTPREL34
;
1301 case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34
: r
= R_PPC64_GOT_TLSGD_PCREL34
;
1303 case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34
: r
= R_PPC64_GOT_TLSLD_PCREL34
;
1305 case BFD_RELOC_PPC64_GOT_TPREL_PCREL34
: r
= R_PPC64_GOT_TPREL_PCREL34
;
1307 case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34
: r
= R_PPC64_GOT_DTPREL_PCREL34
;
1309 case BFD_RELOC_PPC64_ADDR16_HIGHER34
: r
= R_PPC64_ADDR16_HIGHER34
;
1311 case BFD_RELOC_PPC64_ADDR16_HIGHERA34
: r
= R_PPC64_ADDR16_HIGHERA34
;
1313 case BFD_RELOC_PPC64_ADDR16_HIGHEST34
: r
= R_PPC64_ADDR16_HIGHEST34
;
1315 case BFD_RELOC_PPC64_ADDR16_HIGHESTA34
: r
= R_PPC64_ADDR16_HIGHESTA34
;
1317 case BFD_RELOC_PPC64_REL16_HIGHER34
: r
= R_PPC64_REL16_HIGHER34
;
1319 case BFD_RELOC_PPC64_REL16_HIGHERA34
: r
= R_PPC64_REL16_HIGHERA34
;
1321 case BFD_RELOC_PPC64_REL16_HIGHEST34
: r
= R_PPC64_REL16_HIGHEST34
;
1323 case BFD_RELOC_PPC64_REL16_HIGHESTA34
: r
= R_PPC64_REL16_HIGHESTA34
;
1325 case BFD_RELOC_PPC64_D28
: r
= R_PPC64_D28
;
1327 case BFD_RELOC_PPC64_PCREL28
: r
= R_PPC64_PCREL28
;
1329 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1331 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1335 return ppc64_elf_howto_table
[r
];
1338 static reloc_howto_type
*
1339 ppc64_elf_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1342 static char *compat_map
[][2] = {
1343 { "R_PPC64_GOT_TLSGD34", "R_PPC64_GOT_TLSGD_PCREL34" },
1344 { "R_PPC64_GOT_TLSLD34", "R_PPC64_GOT_TLSLD_PCREL34" },
1345 { "R_PPC64_GOT_TPREL34", "R_PPC64_GOT_TPREL_PCREL34" },
1346 { "R_PPC64_GOT_DTPREL34", "R_PPC64_GOT_DTPREL_PCREL34" }
1349 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1350 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1351 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1352 return &ppc64_elf_howto_raw
[i
];
1354 /* Handle old names of relocations in case they were used by
1356 FIXME: Remove this soon. Mapping the reloc names is very likely
1357 completely unnecessary. */
1358 for (i
= 0; i
< ARRAY_SIZE (compat_map
); i
++)
1359 if (strcasecmp (compat_map
[i
][0], r_name
) == 0)
1361 _bfd_error_handler (_("warning: %s should be used rather than %s"),
1362 compat_map
[i
][1], compat_map
[i
][0]);
1363 return ppc64_elf_reloc_name_lookup (abfd
, compat_map
[i
][1]);
1369 /* Set the howto pointer for a PowerPC ELF reloc. */
1372 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1373 Elf_Internal_Rela
*dst
)
1377 /* Initialize howto table if needed. */
1378 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1381 type
= ELF64_R_TYPE (dst
->r_info
);
1382 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1384 /* xgettext:c-format */
1385 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1387 bfd_set_error (bfd_error_bad_value
);
1390 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1391 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1393 /* xgettext:c-format */
1394 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1396 bfd_set_error (bfd_error_bad_value
);
1403 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1405 static bfd_reloc_status_type
1406 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1407 void *data
, asection
*input_section
,
1408 bfd
*output_bfd
, char **error_message
)
1410 enum elf_ppc64_reloc_type r_type
;
1412 bfd_size_type octets
;
1415 /* If this is a relocatable link (output_bfd test tells us), just
1416 call the generic function. Any adjustment will be done at final
1418 if (output_bfd
!= NULL
)
1419 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1420 input_section
, output_bfd
, error_message
);
1422 /* Adjust the addend for sign extension of the low 16 (or 34) bits.
1423 We won't actually be using the low bits, so trashing them
1425 r_type
= reloc_entry
->howto
->type
;
1426 if (r_type
== R_PPC64_ADDR16_HIGHERA34
1427 || r_type
== R_PPC64_ADDR16_HIGHESTA34
1428 || r_type
== R_PPC64_REL16_HIGHERA34
1429 || r_type
== R_PPC64_REL16_HIGHESTA34
)
1430 reloc_entry
->addend
+= 1ULL << 33;
1432 reloc_entry
->addend
+= 1U << 15;
1433 if (r_type
!= R_PPC64_REL16DX_HA
)
1434 return bfd_reloc_continue
;
1437 if (!bfd_is_com_section (symbol
->section
))
1438 value
= symbol
->value
;
1439 value
+= (reloc_entry
->addend
1440 + symbol
->section
->output_offset
1441 + symbol
->section
->output_section
->vma
);
1442 value
-= (reloc_entry
->address
1443 + input_section
->output_offset
1444 + input_section
->output_section
->vma
);
1445 value
= (bfd_signed_vma
) value
>> 16;
1447 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1448 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1449 input_section
, octets
))
1450 return bfd_reloc_outofrange
;
1452 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1454 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1455 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1456 if (value
+ 0x8000 > 0xffff)
1457 return bfd_reloc_overflow
;
1458 return bfd_reloc_ok
;
1461 static bfd_reloc_status_type
1462 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1463 void *data
, asection
*input_section
,
1464 bfd
*output_bfd
, char **error_message
)
1466 if (output_bfd
!= NULL
)
1467 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1468 input_section
, output_bfd
, error_message
);
1470 if (symbol
->section
->owner
== NULL
1471 || !is_ppc64_elf (symbol
->section
->owner
))
1472 return bfd_reloc_continue
;
1474 if (strcmp (symbol
->section
->name
, ".opd") == 0
1475 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1477 bfd_vma dest
= opd_entry_value (symbol
->section
,
1478 symbol
->value
+ reloc_entry
->addend
,
1480 if (dest
!= (bfd_vma
) -1)
1481 reloc_entry
->addend
= dest
- (symbol
->value
1482 + symbol
->section
->output_section
->vma
1483 + symbol
->section
->output_offset
);
1487 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1489 if (symbol
->section
->owner
!= abfd
1490 && abiversion (symbol
->section
->owner
) >= 2)
1494 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1496 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1498 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1500 elfsym
= (elf_symbol_type
*) symdef
;
1506 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1508 return bfd_reloc_continue
;
1511 static bfd_reloc_status_type
1512 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1513 void *data
, asection
*input_section
,
1514 bfd
*output_bfd
, char **error_message
)
1517 enum elf_ppc64_reloc_type r_type
;
1518 bfd_size_type octets
;
1519 /* Assume 'at' branch hints. */
1520 bool is_isa_v2
= true;
1522 /* If this is a relocatable link (output_bfd test tells us), just
1523 call the generic function. Any adjustment will be done at final
1525 if (output_bfd
!= NULL
)
1526 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1527 input_section
, output_bfd
, error_message
);
1529 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1530 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1531 input_section
, octets
))
1532 return bfd_reloc_outofrange
;
1534 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1535 insn
&= ~(0x01 << 21);
1536 r_type
= reloc_entry
->howto
->type
;
1537 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1538 || r_type
== R_PPC64_REL14_BRTAKEN
)
1539 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1543 /* Set 'a' bit. This is 0b00010 in BO field for branch
1544 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1545 for branch on CTR insns (BO == 1a00t or 1a01t). */
1546 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1548 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1558 if (!bfd_is_com_section (symbol
->section
))
1559 target
= symbol
->value
;
1560 target
+= symbol
->section
->output_section
->vma
;
1561 target
+= symbol
->section
->output_offset
;
1562 target
+= reloc_entry
->addend
;
1564 from
= (reloc_entry
->address
1565 + input_section
->output_offset
1566 + input_section
->output_section
->vma
);
1568 /* Invert 'y' bit if not the default. */
1569 if ((bfd_signed_vma
) (target
- from
) < 0)
1572 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1574 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1575 input_section
, output_bfd
, error_message
);
1578 static bfd_reloc_status_type
1579 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1580 void *data
, asection
*input_section
,
1581 bfd
*output_bfd
, char **error_message
)
1583 /* If this is a relocatable link (output_bfd test tells us), just
1584 call the generic function. Any adjustment will be done at final
1586 if (output_bfd
!= NULL
)
1587 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1588 input_section
, output_bfd
, error_message
);
1590 /* Subtract the symbol section base address. */
1591 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1592 return bfd_reloc_continue
;
1595 static bfd_reloc_status_type
1596 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1597 void *data
, asection
*input_section
,
1598 bfd
*output_bfd
, char **error_message
)
1600 /* If this is a relocatable link (output_bfd test tells us), just
1601 call the generic function. Any adjustment will be done at final
1603 if (output_bfd
!= NULL
)
1604 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1605 input_section
, output_bfd
, error_message
);
1607 /* Subtract the symbol section base address. */
1608 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1610 /* Adjust the addend for sign extension of the low 16 bits. */
1611 reloc_entry
->addend
+= 0x8000;
1612 return bfd_reloc_continue
;
1615 static bfd_reloc_status_type
1616 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1617 void *data
, asection
*input_section
,
1618 bfd
*output_bfd
, char **error_message
)
1622 /* If this is a relocatable link (output_bfd test tells us), just
1623 call the generic function. Any adjustment will be done at final
1625 if (output_bfd
!= NULL
)
1626 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1627 input_section
, output_bfd
, error_message
);
1629 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1631 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1633 /* Subtract the TOC base address. */
1634 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1635 return bfd_reloc_continue
;
1638 static bfd_reloc_status_type
1639 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1640 void *data
, asection
*input_section
,
1641 bfd
*output_bfd
, char **error_message
)
1645 /* If this is a relocatable link (output_bfd test tells us), just
1646 call the generic function. Any adjustment will be done at final
1648 if (output_bfd
!= NULL
)
1649 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1650 input_section
, output_bfd
, error_message
);
1652 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1654 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1656 /* Subtract the TOC base address. */
1657 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1659 /* Adjust the addend for sign extension of the low 16 bits. */
1660 reloc_entry
->addend
+= 0x8000;
1661 return bfd_reloc_continue
;
1664 static bfd_reloc_status_type
1665 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1666 void *data
, asection
*input_section
,
1667 bfd
*output_bfd
, char **error_message
)
1670 bfd_size_type octets
;
1672 /* If this is a relocatable link (output_bfd test tells us), just
1673 call the generic function. Any adjustment will be done at final
1675 if (output_bfd
!= NULL
)
1676 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1677 input_section
, output_bfd
, error_message
);
1679 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1680 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1681 input_section
, octets
))
1682 return bfd_reloc_outofrange
;
1684 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1686 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1688 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1689 return bfd_reloc_ok
;
1692 static bfd_reloc_status_type
1693 ppc64_elf_prefix_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1694 void *data
, asection
*input_section
,
1695 bfd
*output_bfd
, char **error_message
)
1699 bfd_size_type octets
;
1701 if (output_bfd
!= NULL
)
1702 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1703 input_section
, output_bfd
, error_message
);
1705 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1706 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1707 input_section
, octets
))
1708 return bfd_reloc_outofrange
;
1710 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1712 insn
|= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
+ 4);
1714 targ
= (symbol
->section
->output_section
->vma
1715 + symbol
->section
->output_offset
1716 + reloc_entry
->addend
);
1717 if (!bfd_is_com_section (symbol
->section
))
1718 targ
+= symbol
->value
;
1719 if (reloc_entry
->howto
->type
== R_PPC64_D34_HA30
)
1721 if (reloc_entry
->howto
->pc_relative
)
1723 bfd_vma from
= (reloc_entry
->address
1724 + input_section
->output_offset
1725 + input_section
->output_section
->vma
);
1728 targ
>>= reloc_entry
->howto
->rightshift
;
1729 insn
&= ~reloc_entry
->howto
->dst_mask
;
1730 insn
|= ((targ
<< 16) | (targ
& 0xffff)) & reloc_entry
->howto
->dst_mask
;
1731 bfd_put_32 (abfd
, insn
>> 32, (bfd_byte
*) data
+ octets
);
1732 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
+ 4);
1733 if (reloc_entry
->howto
->complain_on_overflow
== complain_overflow_signed
1734 && (targ
+ (1ULL << (reloc_entry
->howto
->bitsize
- 1))
1735 >= 1ULL << reloc_entry
->howto
->bitsize
))
1736 return bfd_reloc_overflow
;
1737 return bfd_reloc_ok
;
1740 static bfd_reloc_status_type
1741 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1742 void *data
, asection
*input_section
,
1743 bfd
*output_bfd
, char **error_message
)
1745 /* If this is a relocatable link (output_bfd test tells us), just
1746 call the generic function. Any adjustment will be done at final
1748 if (output_bfd
!= NULL
)
1749 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1750 input_section
, output_bfd
, error_message
);
1752 if (error_message
!= NULL
)
1753 *error_message
= bfd_asprintf (_("generic linker can't handle %s"),
1754 reloc_entry
->howto
->name
);
1755 return bfd_reloc_dangerous
;
1758 /* Track GOT entries needed for a given symbol. We might need more
1759 than one got entry per symbol. */
1762 struct got_entry
*next
;
1764 /* The symbol addend that we'll be placing in the GOT. */
1767 /* Unlike other ELF targets, we use separate GOT entries for the same
1768 symbol referenced from different input files. This is to support
1769 automatic multiple TOC/GOT sections, where the TOC base can vary
1770 from one input file to another. After partitioning into TOC groups
1771 we merge entries within the group.
1773 Point to the BFD owning this GOT entry. */
1776 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1777 TLS_TPREL or TLS_DTPREL for tls entries. */
1778 unsigned char tls_type
;
1780 /* Non-zero if got.ent points to real entry. */
1781 unsigned char is_indirect
;
1783 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1786 bfd_signed_vma refcount
;
1788 struct got_entry
*ent
;
1792 /* The same for PLT. */
1795 struct plt_entry
*next
;
1801 bfd_signed_vma refcount
;
1806 struct ppc64_elf_obj_tdata
1808 struct elf_obj_tdata elf
;
1810 /* Shortcuts to dynamic linker sections. */
1814 /* Used during garbage collection. We attach global symbols defined
1815 on removed .opd entries to this section so that the sym is removed. */
1816 asection
*deleted_section
;
1818 /* TLS local dynamic got entry handling. Support for multiple GOT
1819 sections means we potentially need one of these for each input bfd. */
1820 struct got_entry tlsld_got
;
1822 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1823 the reloc to be in the range -32768 to 32767. */
1824 unsigned int has_small_toc_reloc
: 1;
1826 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1827 instruction not one we handle. */
1828 unsigned int unexpected_toc_insn
: 1;
1830 /* Set if PLT/GOT/TOC relocs that can be optimised are present in
1832 unsigned int has_optrel
: 1;
1835 #define ppc64_elf_tdata(bfd) \
1836 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1838 #define ppc64_tlsld_got(bfd) \
1839 (&ppc64_elf_tdata (bfd)->tlsld_got)
1841 /* Override the generic function because we store some extras. */
1844 ppc64_elf_mkobject (bfd
*abfd
)
1846 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1850 /* Fix bad default arch selected for a 64 bit input bfd when the
1851 default is 32 bit. Also select arch based on apuinfo. */
1854 ppc64_elf_object_p (bfd
*abfd
)
1856 if (!abfd
->arch_info
->the_default
)
1859 if (abfd
->arch_info
->bits_per_word
== 32)
1861 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1863 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1865 /* Relies on arch after 32 bit default being 64 bit default. */
1866 abfd
->arch_info
= abfd
->arch_info
->next
;
1867 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1870 return _bfd_elf_ppc_set_arch (abfd
);
1873 /* Support for core dump NOTE sections. */
1876 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1878 size_t offset
, size
;
1880 if (note
->descsz
!= 504)
1884 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1887 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1893 /* Make a ".reg/999" section. */
1894 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1895 size
, note
->descpos
+ offset
);
1899 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1901 if (note
->descsz
!= 136)
1904 elf_tdata (abfd
)->core
->pid
1905 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1906 elf_tdata (abfd
)->core
->program
1907 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1908 elf_tdata (abfd
)->core
->command
1909 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1915 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1925 char data
[136] ATTRIBUTE_NONSTRING
;
1928 va_start (ap
, note_type
);
1929 memset (data
, 0, sizeof (data
));
1930 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1931 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1933 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1934 -Wstringop-truncation:
1935 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1937 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1939 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1940 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1944 return elfcore_write_note (abfd
, buf
, bufsiz
,
1945 "CORE", note_type
, data
, sizeof (data
));
1956 va_start (ap
, note_type
);
1957 memset (data
, 0, 112);
1958 pid
= va_arg (ap
, long);
1959 bfd_put_32 (abfd
, pid
, data
+ 32);
1960 cursig
= va_arg (ap
, int);
1961 bfd_put_16 (abfd
, cursig
, data
+ 12);
1962 greg
= va_arg (ap
, const void *);
1963 memcpy (data
+ 112, greg
, 384);
1964 memset (data
+ 496, 0, 8);
1966 return elfcore_write_note (abfd
, buf
, bufsiz
,
1967 "CORE", note_type
, data
, sizeof (data
));
1972 /* Add extra PPC sections. */
1974 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1976 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1977 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1978 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1979 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1980 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1981 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1982 { NULL
, 0, 0, 0, 0 }
1985 enum _ppc64_sec_type
{
1992 struct _ppc64_elf_section_data
1994 struct bfd_elf_section_data elf
;
1998 /* An array with one entry for each opd function descriptor,
1999 and some spares since opd entries may be either 16 or 24 bytes. */
2000 #define OPD_NDX(OFF) ((OFF) >> 4)
2001 struct _opd_sec_data
2003 /* Points to the function code section for local opd entries. */
2004 asection
**func_sec
;
2006 /* After editing .opd, adjust references to opd local syms. */
2011 /* A copy of relocs before they are modified for --emit-relocs. */
2012 Elf_Internal_Rela
*relocs
;
2014 /* Section contents. */
2019 /* An array for toc sections, indexed by offset/8. */
2020 struct _toc_sec_data
2022 /* Specifies the relocation symbol index used at a given toc offset. */
2025 /* And the relocation addend. */
2029 /* Stub debugging. */
2030 struct ppc_stub_hash_entry
*last_ent
;
2033 enum _ppc64_sec_type sec_type
:2;
2035 /* Flag set when small branches are detected. Used to
2036 select suitable defaults for the stub group size. */
2037 unsigned int has_14bit_branch
:1;
2039 /* Flag set when PLTCALL relocs are detected. */
2040 unsigned int has_pltcall
:1;
2042 /* Flag set when section has PLT/GOT/TOC relocations that can be
2044 unsigned int has_optrel
:1;
2047 #define ppc64_elf_section_data(sec) \
2048 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2051 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2053 if (!sec
->used_by_bfd
)
2055 struct _ppc64_elf_section_data
*sdata
;
2056 size_t amt
= sizeof (*sdata
);
2058 sdata
= bfd_zalloc (abfd
, amt
);
2061 sec
->used_by_bfd
= sdata
;
2064 return _bfd_elf_new_section_hook (abfd
, sec
);
2068 ppc64_elf_section_flags (const Elf_Internal_Shdr
*hdr
)
2070 const char *name
= hdr
->bfd_section
->name
;
2072 if (startswith (name
, ".sbss")
2073 || startswith (name
, ".sdata"))
2074 hdr
->bfd_section
->flags
|= SEC_SMALL_DATA
;
2079 static struct _opd_sec_data
*
2080 get_opd_info (asection
* sec
)
2083 && ppc64_elf_section_data (sec
) != NULL
2084 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2085 return &ppc64_elf_section_data (sec
)->u
.opd
;
2089 /* Parameters for the qsort hook. */
2090 static bool synthetic_relocatable
;
2091 static const asection
*synthetic_opd
;
2093 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2096 compare_symbols (const void *ap
, const void *bp
)
2098 const asymbol
*a
= *(const asymbol
**) ap
;
2099 const asymbol
*b
= *(const asymbol
**) bp
;
2101 /* Section symbols first. */
2102 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2104 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2107 /* then .opd symbols. */
2108 if (synthetic_opd
!= NULL
)
2110 if (strcmp (a
->section
->name
, ".opd") == 0
2111 && strcmp (b
->section
->name
, ".opd") != 0)
2113 if (strcmp (a
->section
->name
, ".opd") != 0
2114 && strcmp (b
->section
->name
, ".opd") == 0)
2118 /* then other code symbols. */
2119 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2120 == (SEC_CODE
| SEC_ALLOC
))
2121 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2122 != (SEC_CODE
| SEC_ALLOC
)))
2125 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2126 != (SEC_CODE
| SEC_ALLOC
))
2127 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2128 == (SEC_CODE
| SEC_ALLOC
)))
2131 if (synthetic_relocatable
)
2133 if (a
->section
->id
< b
->section
->id
)
2136 if (a
->section
->id
> b
->section
->id
)
2140 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2143 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2146 /* For syms with the same value, prefer strong dynamic global function
2147 syms over other syms. */
2148 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2151 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2154 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2157 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2160 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2163 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2166 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2169 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2172 /* Finally, sort on where the symbol is in memory. The symbols will
2173 be in at most two malloc'd blocks, one for static syms, one for
2174 dynamic syms, and we distinguish the two blocks above by testing
2175 BSF_DYNAMIC. Since we are sorting the symbol pointers which were
2176 originally in the same order as the symbols (and we're not
2177 sorting the symbols themselves), this ensures a stable sort. */
2185 /* Search SYMS for a symbol of the given VALUE. */
2188 sym_exists_at (asymbol
**syms
, size_t lo
, size_t hi
, unsigned int id
,
2193 if (id
== (unsigned) -1)
2197 mid
= (lo
+ hi
) >> 1;
2198 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2200 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2210 mid
= (lo
+ hi
) >> 1;
2211 if (syms
[mid
]->section
->id
< id
)
2213 else if (syms
[mid
]->section
->id
> id
)
2215 else if (syms
[mid
]->value
< value
)
2217 else if (syms
[mid
]->value
> value
)
2227 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2229 bfd_vma vma
= *(bfd_vma
*) ptr
;
2230 return ((section
->flags
& SEC_ALLOC
) != 0
2231 && section
->vma
<= vma
2232 && vma
< section
->vma
+ section
->size
);
2235 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2236 entry syms. Also generate @plt symbols for the glink branch table.
2237 Returns count of synthetic symbols in RET or -1 on error. */
2240 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2241 long static_count
, asymbol
**static_syms
,
2242 long dyn_count
, asymbol
**dyn_syms
,
2248 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2249 asection
*opd
= NULL
;
2250 bool relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2252 int abi
= abiversion (abfd
);
2258 opd
= bfd_get_section_by_name (abfd
, ".opd");
2259 if (opd
== NULL
&& abi
== 1)
2271 symcount
= static_count
;
2273 symcount
+= dyn_count
;
2277 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2281 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2283 /* Use both symbol tables. */
2284 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2285 memcpy (syms
+ static_count
, dyn_syms
,
2286 (dyn_count
+ 1) * sizeof (*syms
));
2288 else if (!relocatable
&& static_count
== 0)
2289 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2291 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2293 /* Trim uninteresting symbols. Interesting symbols are section,
2294 function, and notype symbols. */
2295 for (i
= 0, j
= 0; i
< symcount
; ++i
)
2296 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
2297 | BSF_RELC
| BSF_SRELC
)) == 0)
2298 syms
[j
++] = syms
[i
];
2301 synthetic_relocatable
= relocatable
;
2302 synthetic_opd
= opd
;
2303 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2305 if (!relocatable
&& symcount
> 1)
2307 /* Trim duplicate syms, since we may have merged the normal
2308 and dynamic symbols. Actually, we only care about syms
2309 that have different values, so trim any with the same
2310 value. Don't consider ifunc and ifunc resolver symbols
2311 duplicates however, because GDB wants to know whether a
2312 text symbol is an ifunc resolver. */
2313 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2315 const asymbol
*s0
= syms
[i
- 1];
2316 const asymbol
*s1
= syms
[i
];
2318 if ((s0
->value
+ s0
->section
->vma
2319 != s1
->value
+ s1
->section
->vma
)
2320 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2321 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2322 syms
[j
++] = syms
[i
];
2328 /* Note that here and in compare_symbols we can't compare opd and
2329 sym->section directly. With separate debug info files, the
2330 symbols will be extracted from the debug file while abfd passed
2331 to this function is the real binary. */
2332 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) != 0
2333 && strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2337 for (; i
< symcount
; ++i
)
2338 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2339 | SEC_THREAD_LOCAL
))
2340 != (SEC_CODE
| SEC_ALLOC
))
2341 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2345 for (; i
< symcount
; ++i
)
2346 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2350 for (; i
< symcount
; ++i
)
2351 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2355 for (; i
< symcount
; ++i
)
2356 if (((syms
[i
]->section
->flags
2357 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2358 != (SEC_CODE
| SEC_ALLOC
))
2366 bool (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bool);
2371 if (opdsymend
== secsymend
)
2374 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2375 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2379 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, false))
2386 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2390 while (r
< opd
->relocation
+ relcount
2391 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2394 if (r
== opd
->relocation
+ relcount
)
2397 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2400 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2403 sym
= *r
->sym_ptr_ptr
;
2404 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2405 sym
->section
->id
, sym
->value
+ r
->addend
))
2408 size
+= sizeof (asymbol
);
2409 size
+= strlen (syms
[i
]->name
) + 2;
2415 s
= *ret
= bfd_malloc (size
);
2422 names
= (char *) (s
+ count
);
2424 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2428 while (r
< opd
->relocation
+ relcount
2429 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2432 if (r
== opd
->relocation
+ relcount
)
2435 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2438 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2441 sym
= *r
->sym_ptr_ptr
;
2442 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2443 sym
->section
->id
, sym
->value
+ r
->addend
))
2448 s
->flags
|= BSF_SYNTHETIC
;
2449 s
->section
= sym
->section
;
2450 s
->value
= sym
->value
+ r
->addend
;
2453 len
= strlen (syms
[i
]->name
);
2454 memcpy (names
, syms
[i
]->name
, len
+ 1);
2456 /* Have udata.p point back to the original symbol this
2457 synthetic symbol was derived from. */
2458 s
->udata
.p
= syms
[i
];
2465 bool (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bool);
2466 bfd_byte
*contents
= NULL
;
2468 size_t plt_count
= 0;
2469 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2470 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2474 && ((opd
->flags
& SEC_HAS_CONTENTS
) == 0
2475 || !bfd_malloc_and_get_section (abfd
, opd
, &contents
)))
2477 free_contents_and_exit_err
:
2479 free_contents_and_exit
:
2485 for (i
= secsymend
; i
< opdsymend
; ++i
)
2489 /* Ignore bogus symbols. */
2490 if (syms
[i
]->value
> opd
->size
- 8)
2493 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2494 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2497 size
+= sizeof (asymbol
);
2498 size
+= strlen (syms
[i
]->name
) + 2;
2502 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2504 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2506 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2508 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2510 if ((dynamic
->flags
& SEC_HAS_CONTENTS
) == 0
2511 || !bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2512 goto free_contents_and_exit_err
;
2514 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2515 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2517 for (extdyn
= dynbuf
, extdynend
= dynbuf
+ dynamic
->size
;
2518 (size_t) (extdynend
- extdyn
) >= extdynsize
;
2519 extdyn
+= extdynsize
)
2521 Elf_Internal_Dyn dyn
;
2522 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2524 if (dyn
.d_tag
== DT_NULL
)
2527 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2529 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2530 See comment in ppc64_elf_finish_dynamic_sections. */
2531 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2532 /* The .glink section usually does not survive the final
2533 link; search for the section (usually .text) where the
2534 glink stubs now reside. */
2535 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2546 /* Determine __glink trampoline by reading the relative branch
2547 from the first glink stub. */
2549 unsigned int off
= 0;
2551 while (bfd_get_section_contents (abfd
, glink
, buf
,
2552 glink_vma
+ off
- glink
->vma
, 4))
2554 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2556 if ((insn
& ~0x3fffffc) == 0)
2559 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2568 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2570 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2573 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2574 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, true))
2575 goto free_contents_and_exit_err
;
2577 plt_count
= NUM_SHDR_ENTRIES (&elf_section_data (relplt
)->this_hdr
);
2578 size
+= plt_count
* sizeof (asymbol
);
2580 p
= relplt
->relocation
;
2581 for (i
= 0; i
< plt_count
; i
++, p
++)
2583 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2585 size
+= sizeof ("+0x") - 1 + 16;
2591 goto free_contents_and_exit
;
2592 s
= *ret
= bfd_malloc (size
);
2594 goto free_contents_and_exit_err
;
2596 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2598 for (i
= secsymend
; i
< opdsymend
; ++i
)
2602 if (syms
[i
]->value
> opd
->size
- 8)
2605 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2606 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2610 asection
*sec
= abfd
->sections
;
2617 size_t mid
= (lo
+ hi
) >> 1;
2618 if (syms
[mid
]->section
->vma
< ent
)
2620 else if (syms
[mid
]->section
->vma
> ent
)
2624 sec
= syms
[mid
]->section
;
2629 if (lo
>= hi
&& lo
> codesecsym
)
2630 sec
= syms
[lo
- 1]->section
;
2632 for (; sec
!= NULL
; sec
= sec
->next
)
2636 /* SEC_LOAD may not be set if SEC is from a separate debug
2638 if ((sec
->flags
& SEC_ALLOC
) == 0)
2640 if ((sec
->flags
& SEC_CODE
) != 0)
2643 s
->flags
|= BSF_SYNTHETIC
;
2644 s
->value
= ent
- s
->section
->vma
;
2647 len
= strlen (syms
[i
]->name
);
2648 memcpy (names
, syms
[i
]->name
, len
+ 1);
2650 /* Have udata.p point back to the original symbol this
2651 synthetic symbol was derived from. */
2652 s
->udata
.p
= syms
[i
];
2658 if (glink
!= NULL
&& relplt
!= NULL
)
2662 /* Add a symbol for the main glink trampoline. */
2663 memset (s
, 0, sizeof *s
);
2665 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2667 s
->value
= resolv_vma
- glink
->vma
;
2669 memcpy (names
, "__glink_PLTresolve",
2670 sizeof ("__glink_PLTresolve"));
2671 names
+= sizeof ("__glink_PLTresolve");
2676 /* FIXME: It would be very much nicer to put sym@plt on the
2677 stub rather than on the glink branch table entry. The
2678 objdump disassembler would then use a sensible symbol
2679 name on plt calls. The difficulty in doing so is
2680 a) finding the stubs, and,
2681 b) matching stubs against plt entries, and,
2682 c) there can be multiple stubs for a given plt entry.
2684 Solving (a) could be done by code scanning, but older
2685 ppc64 binaries used different stubs to current code.
2686 (b) is the tricky one since you need to known the toc
2687 pointer for at least one function that uses a pic stub to
2688 be able to calculate the plt address referenced.
2689 (c) means gdb would need to set multiple breakpoints (or
2690 find the glink branch itself) when setting breakpoints
2691 for pending shared library loads. */
2692 p
= relplt
->relocation
;
2693 for (i
= 0; i
< plt_count
; i
++, p
++)
2697 *s
= **p
->sym_ptr_ptr
;
2698 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2699 we are defining a symbol, ensure one of them is set. */
2700 if ((s
->flags
& BSF_LOCAL
) == 0)
2701 s
->flags
|= BSF_GLOBAL
;
2702 s
->flags
|= BSF_SYNTHETIC
;
2704 s
->value
= glink_vma
- glink
->vma
;
2707 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2708 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2712 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2713 names
+= sizeof ("+0x") - 1;
2714 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2715 names
+= strlen (names
);
2717 memcpy (names
, "@plt", sizeof ("@plt"));
2718 names
+= sizeof ("@plt");
2738 /* The following functions are specific to the ELF linker, while
2739 functions above are used generally. Those named ppc64_elf_* are
2740 called by the main ELF linker code. They appear in this file more
2741 or less in the order in which they are called. eg.
2742 ppc64_elf_check_relocs is called early in the link process,
2743 ppc64_elf_finish_dynamic_sections is one of the last functions
2746 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2747 functions have both a function code symbol and a function descriptor
2748 symbol. A call to foo in a relocatable object file looks like:
2755 The function definition in another object file might be:
2759 . .quad .TOC.@tocbase
2765 When the linker resolves the call during a static link, the branch
2766 unsurprisingly just goes to .foo and the .opd information is unused.
2767 If the function definition is in a shared library, things are a little
2768 different: The call goes via a plt call stub, the opd information gets
2769 copied to the plt, and the linker patches the nop.
2777 . std 2,40(1) # in practice, the call stub
2778 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2779 . addi 11,11,Lfoo@toc@l # this is the general idea
2787 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2789 The "reloc ()" notation is supposed to indicate that the linker emits
2790 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2793 What are the difficulties here? Well, firstly, the relocations
2794 examined by the linker in check_relocs are against the function code
2795 sym .foo, while the dynamic relocation in the plt is emitted against
2796 the function descriptor symbol, foo. Somewhere along the line, we need
2797 to carefully copy dynamic link information from one symbol to the other.
2798 Secondly, the generic part of the elf linker will make .foo a dynamic
2799 symbol as is normal for most other backends. We need foo dynamic
2800 instead, at least for an application final link. However, when
2801 creating a shared library containing foo, we need to have both symbols
2802 dynamic so that references to .foo are satisfied during the early
2803 stages of linking. Otherwise the linker might decide to pull in a
2804 definition from some other object, eg. a static library.
2806 Update: As of August 2004, we support a new convention. Function
2807 calls may use the function descriptor symbol, ie. "bl foo". This
2808 behaves exactly as "bl .foo". */
2810 /* Of those relocs that might be copied as dynamic relocs, this
2811 function selects those that must be copied when linking a shared
2812 library or PIE, even when the symbol is local. */
2815 must_be_dyn_reloc (struct bfd_link_info
*info
,
2816 enum elf_ppc64_reloc_type r_type
)
2821 /* Only relative relocs can be resolved when the object load
2822 address isn't fixed. DTPREL64 is excluded because the
2823 dynamic linker needs to differentiate global dynamic from
2824 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2831 case R_PPC64_TOC16_DS
:
2832 case R_PPC64_TOC16_LO
:
2833 case R_PPC64_TOC16_HI
:
2834 case R_PPC64_TOC16_HA
:
2835 case R_PPC64_TOC16_LO_DS
:
2838 case R_PPC64_TPREL16
:
2839 case R_PPC64_TPREL16_LO
:
2840 case R_PPC64_TPREL16_HI
:
2841 case R_PPC64_TPREL16_HA
:
2842 case R_PPC64_TPREL16_DS
:
2843 case R_PPC64_TPREL16_LO_DS
:
2844 case R_PPC64_TPREL16_HIGH
:
2845 case R_PPC64_TPREL16_HIGHA
:
2846 case R_PPC64_TPREL16_HIGHER
:
2847 case R_PPC64_TPREL16_HIGHERA
:
2848 case R_PPC64_TPREL16_HIGHEST
:
2849 case R_PPC64_TPREL16_HIGHESTA
:
2850 case R_PPC64_TPREL64
:
2851 case R_PPC64_TPREL34
:
2852 /* These relocations are relative but in a shared library the
2853 linker doesn't know the thread pointer base. */
2854 return bfd_link_dll (info
);
2858 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2859 copying dynamic variables from a shared lib into an app's .dynbss
2860 section, and instead use a dynamic relocation to point into the
2861 shared lib. With code that gcc generates it is vital that this be
2862 enabled; In the PowerPC64 ELFv1 ABI the address of a function is
2863 actually the address of a function descriptor which resides in the
2864 .opd section. gcc uses the descriptor directly rather than going
2865 via the GOT as some other ABIs do, which means that initialized
2866 function pointers reference the descriptor. Thus, a function
2867 pointer initialized to the address of a function in a shared
2868 library will either require a .dynbss copy and a copy reloc, or a
2869 dynamic reloc. Using a .dynbss copy redefines the function
2870 descriptor symbol to point to the copy. This presents a problem as
2871 a PLT entry for that function is also initialized from the function
2872 descriptor symbol and the copy may not be initialized first. */
2873 #define ELIMINATE_COPY_RELOCS 1
2875 /* Section name for stubs is the associated section name plus this
2877 #define STUB_SUFFIX ".stub"
2880 ppc_stub_long_branch:
2881 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2882 destination, but a 24 bit branch in a stub section will reach.
2885 ppc_stub_plt_branch:
2886 Similar to the above, but a 24 bit branch in the stub section won't
2887 reach its destination.
2888 . addis %r12,%r2,xxx@toc@ha
2889 . ld %r12,xxx@toc@l(%r12)
2894 Used to call a function in a shared library. If it so happens that
2895 the plt entry referenced crosses a 64k boundary, then an extra
2896 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2897 An r2save variant starts with "std %r2,40(%r1)".
2898 . addis %r11,%r2,xxx@toc@ha
2899 . ld %r12,xxx+0@toc@l(%r11)
2901 . ld %r2,xxx+8@toc@l(%r11)
2902 . ld %r11,xxx+16@toc@l(%r11)
2905 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2906 code to adjust the value and save r2 to support multiple toc sections.
2907 A ppc_stub_long_branch with an r2 offset looks like:
2909 . addis %r2,%r2,off@ha
2910 . addi %r2,%r2,off@l
2913 A ppc_stub_plt_branch with an r2 offset looks like:
2915 . addis %r12,%r2,xxx@toc@ha
2916 . ld %r12,xxx@toc@l(%r12)
2917 . addis %r2,%r2,off@ha
2918 . addi %r2,%r2,off@l
2922 All of the above stubs are shown as their ELFv1 variants. ELFv2
2923 variants exist too, simpler for plt calls since a new toc pointer
2924 and static chain are not loaded by the stub. In addition, ELFv2
2925 has some more complex stubs to handle calls marked with NOTOC
2926 relocs from functions where r2 is not a valid toc pointer.
2927 ppc_stub_long_branch_p9notoc:
2933 . addis %r12,%r11,dest-1b@ha
2934 . addi %r12,%r12,dest-1b@l
2937 ppc_stub_plt_branch_p9notoc:
2943 . lis %r12,xxx-1b@highest
2944 . ori %r12,%r12,xxx-1b@higher
2946 . oris %r12,%r12,xxx-1b@high
2947 . ori %r12,%r12,xxx-1b@l
2948 . add %r12,%r11,%r12
2952 ppc_stub_plt_call_p9notoc:
2958 . lis %r12,xxx-1b@highest
2959 . ori %r12,%r12,xxx-1b@higher
2961 . oris %r12,%r12,xxx-1b@high
2962 . ori %r12,%r12,xxx-1b@l
2963 . ldx %r12,%r11,%r12
2967 There are also ELFv1 power10 variants of these stubs.
2968 ppc_stub_long_branch_notoc:
2969 . pla %r12,dest@pcrel
2971 ppc_stub_plt_branch_notoc:
2972 . lis %r11,(dest-1f)@highesta34
2973 . ori %r11,%r11,(dest-1f)@highera34
2975 . 1: pla %r12,dest@pcrel
2976 . add %r12,%r11,%r12
2979 ppc_stub_plt_call_notoc:
2980 . lis %r11,(xxx-1f)@highesta34
2981 . ori %r11,%r11,(xxx-1f)@highera34
2983 . 1: pla %r12,xxx@pcrel
2984 . ldx %r12,%r11,%r12
2988 In cases where the high instructions would add zero, they are
2989 omitted and following instructions modified in some cases.
2990 For example, a power10 ppc_stub_plt_call_notoc might simplify down
2992 . pld %r12,xxx@pcrel
2996 Stub variants may be merged. For example, if printf is called from
2997 code with the tocsave optimization (ie. r2 saved in function
2998 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2999 and from other code without the tocsave optimization requiring a
3000 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
3001 type will be created. Calls with the tocsave optimization will
3002 enter this stub after the instruction saving r2. A similar
3003 situation exists when calls are marked with R_PPC64_REL24_NOTOC
3004 relocations. These require a ppc_stub_plt_call_notoc linkage stub
3005 to call an external function like printf. If other calls to printf
3006 require a ppc_stub_plt_call linkage stub then a single
3007 ppc_stub_plt_call_notoc linkage stub may be used for both types of
3010 enum ppc_stub_main_type
3013 ppc_stub_long_branch
,
3014 ppc_stub_plt_branch
,
3016 ppc_stub_global_entry
,
3020 /* ppc_stub_long_branch, ppc_stub_plt_branch and ppc_stub_plt_call have
3021 these variations. */
3023 enum ppc_stub_sub_type
3030 struct ppc_stub_type
3032 ENUM_BITFIELD (ppc_stub_main_type
) main
: 3;
3033 ENUM_BITFIELD (ppc_stub_sub_type
) sub
: 2;
3034 unsigned int r2save
: 1;
3037 /* Information on stub grouping. */
3040 /* The stub section. */
3042 /* This is the section to which stubs in the group will be attached. */
3045 struct map_stub
*next
;
3046 /* Whether to emit a copy of register save/restore functions in this
3049 /* Current offset within stubs after the insn restoring lr in a
3050 _notoc or _both stub using bcl for pc-relative addressing, or
3051 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
3052 unsigned int lr_restore
;
3053 /* Accumulated size of EH info emitted to describe return address
3054 if stubs modify lr. Does not include 17 byte FDE header. */
3055 unsigned int eh_size
;
3056 /* Offset in glink_eh_frame to the start of EH info for this group. */
3057 unsigned int eh_base
;
3060 struct ppc_stub_hash_entry
3062 /* Base hash table entry structure. */
3063 struct bfd_hash_entry root
;
3065 struct ppc_stub_type type
;
3067 /* Group information. */
3068 struct map_stub
*group
;
3070 /* Offset within stub_sec of the beginning of this stub. */
3071 bfd_vma stub_offset
;
3073 /* Given the symbol's value and its section we can determine its final
3074 value when building the stubs (so the stub knows where to jump. */
3075 bfd_vma target_value
;
3076 asection
*target_section
;
3078 /* The symbol table entry, if any, that this was derived from. */
3079 struct ppc_link_hash_entry
*h
;
3080 struct plt_entry
*plt_ent
;
3083 unsigned char symtype
;
3085 /* Symbol st_other. */
3086 unsigned char other
;
3088 /* Debug: Track hash table traversal. */
3092 struct ppc_branch_hash_entry
3094 /* Base hash table entry structure. */
3095 struct bfd_hash_entry root
;
3097 /* Offset within branch lookup table. */
3098 unsigned int offset
;
3100 /* Generation marker. */
3104 /* Used to track dynamic relocations. */
3105 struct ppc_dyn_relocs
3107 struct ppc_dyn_relocs
*next
;
3109 /* The input section of the reloc. */
3112 /* Total number of relocs copied for the input section. */
3115 /* Number of pc-relative relocs copied for the input section. */
3116 unsigned int pc_count
;
3118 /* Number of relocs that might become R_PPC64_RELATIVE. */
3119 unsigned int rel_count
;
3122 struct ppc_local_dyn_relocs
3124 struct ppc_local_dyn_relocs
*next
;
3126 /* The input section of the reloc. */
3129 /* Total number of relocs copied for the input section. */
3132 /* Number of relocs that might become R_PPC64_RELATIVE. */
3133 unsigned int rel_count
: 31;
3135 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3136 unsigned int ifunc
: 1;
3139 struct ppc_link_hash_entry
3141 struct elf_link_hash_entry elf
;
3145 /* A pointer to the most recently used stub hash entry against this
3147 struct ppc_stub_hash_entry
*stub_cache
;
3149 /* A pointer to the next symbol starting with a '.' */
3150 struct ppc_link_hash_entry
*next_dot_sym
;
3153 /* Link between function code and descriptor symbols. */
3154 struct ppc_link_hash_entry
*oh
;
3156 /* Flag function code and descriptor symbols. */
3157 unsigned int is_func
:1;
3158 unsigned int is_func_descriptor
:1;
3159 unsigned int fake
:1;
3161 /* Whether global opd/toc sym has been adjusted or not.
3162 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3163 should be set for all globals defined in any opd/toc section. */
3164 unsigned int adjust_done
:1;
3166 /* Set if this is an out-of-line register save/restore function,
3167 with non-standard calling convention. */
3168 unsigned int save_res
:1;
3170 /* Set if a duplicate symbol with non-zero localentry is detected,
3171 even when the duplicate symbol does not provide a definition. */
3172 unsigned int non_zero_localentry
:1;
3174 /* Contexts in which symbol is used in the GOT (or TOC).
3175 Bits are or'd into the mask as the corresponding relocs are
3176 encountered during check_relocs, with TLS_TLS being set when any
3177 of the other TLS bits are set. tls_optimize clears bits when
3178 optimizing to indicate the corresponding GOT entry type is not
3179 needed. If set, TLS_TLS is never cleared. tls_optimize may also
3180 set TLS_GDIE when a GD reloc turns into an IE one.
3181 These flags are also kept for local symbols. */
3182 #define TLS_TLS 1 /* Any TLS reloc. */
3183 #define TLS_GD 2 /* GD reloc. */
3184 #define TLS_LD 4 /* LD reloc. */
3185 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
3186 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
3187 #define TLS_MARK 32 /* __tls_get_addr call marked. */
3188 #define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
3189 #define TLS_EXPLICIT 256 /* TOC section TLS reloc, not stored. */
3190 unsigned char tls_mask
;
3192 /* The above field is also used to mark function symbols. In which
3193 case TLS_TLS will be 0. */
3194 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
3195 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
3196 #define NON_GOT 256 /* local symbol plt, not stored. */
3199 static inline struct ppc_link_hash_entry
*
3200 ppc_elf_hash_entry (struct elf_link_hash_entry
*ent
)
3202 return (struct ppc_link_hash_entry
*) ent
;
3205 static inline struct elf_link_hash_entry
*
3206 elf_hash_entry (struct ppc_link_hash_entry
*ent
)
3208 return (struct elf_link_hash_entry
*) ent
;
3211 /* ppc64 ELF linker hash table. */
3213 struct ppc_link_hash_table
3215 struct elf_link_hash_table elf
;
3217 /* The stub hash table. */
3218 struct bfd_hash_table stub_hash_table
;
3220 /* Another hash table for plt_branch stubs. */
3221 struct bfd_hash_table branch_hash_table
;
3223 /* Hash table for function prologue tocsave. */
3224 htab_t tocsave_htab
;
3226 /* Various options and other info passed from the linker. */
3227 struct ppc64_elf_params
*params
;
3229 /* The size of sec_info below. */
3230 unsigned int sec_info_arr_size
;
3232 /* Per-section array of extra section info. Done this way rather
3233 than as part of ppc64_elf_section_data so we have the info for
3234 non-ppc64 sections. */
3237 /* Along with elf_gp, specifies the TOC pointer used by this section. */
3242 /* The section group that this section belongs to. */
3243 struct map_stub
*group
;
3244 /* A temp section list pointer. */
3249 /* Linked list of groups. */
3250 struct map_stub
*group
;
3252 /* Temp used when calculating TOC pointers. */
3255 asection
*toc_first_sec
;
3257 /* Used when adding symbols. */
3258 struct ppc_link_hash_entry
*dot_syms
;
3260 /* Shortcuts to get to dynamic linker sections. */
3262 asection
*global_entry
;
3265 asection
*relpltlocal
;
3268 asection
*glink_eh_frame
;
3270 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3271 struct ppc_link_hash_entry
*tls_get_addr
;
3272 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3273 struct ppc_link_hash_entry
*tga_desc
;
3274 struct ppc_link_hash_entry
*tga_desc_fd
;
3275 struct map_stub
*tga_group
;
3277 /* The size of reliplt used by got entry relocs. */
3278 bfd_size_type got_reli_size
;
3280 /* DT_RELR array of section/r_offset. */
3290 unsigned long stub_count
[ppc_stub_save_res
];
3292 /* Number of stubs against global syms. */
3293 unsigned long stub_globals
;
3295 /* Set if we're linking code with function descriptors. */
3296 unsigned int opd_abi
:1;
3298 /* Support for multiple toc sections. */
3299 unsigned int do_multi_toc
:1;
3300 unsigned int multi_toc_needed
:1;
3301 unsigned int second_toc_pass
:1;
3302 unsigned int do_toc_opt
:1;
3304 /* Set if tls optimization is enabled. */
3305 unsigned int do_tls_opt
:1;
3307 /* Set if inline plt calls should be converted to direct calls. */
3308 unsigned int can_convert_all_inline_plt
:1;
3310 /* Set if a stub_offset changed. */
3311 unsigned int stub_changed
:1;
3314 unsigned int stub_error
:1;
3316 /* Whether func_desc_adjust needs to be run over symbols. */
3317 unsigned int need_func_desc_adj
:1;
3319 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
3320 unsigned int has_plt_localentry0
:1;
3322 /* Whether calls are made via the PLT from NOTOC functions. */
3323 unsigned int notoc_plt
:1;
3325 /* Whether any code linked seems to be Power10. */
3326 unsigned int has_power10_relocs
:1;
3328 /* Incremented once for each stub sized. */
3329 unsigned int stub_id
;
3331 /* Incremented every time we size stubs. */
3332 unsigned int stub_iteration
;
3334 /* After 20 iterations of stub sizing we no longer allow stubs to
3335 shrink. This is to break out of a pathological case where adding
3336 stubs or increasing their size on one iteration decreases section
3337 gaps (perhaps due to alignment), which then results in smaller
3338 stubs on the next iteration. */
3339 #define STUB_SHRINK_ITER 20
3342 /* Rename some of the generic section flags to better document how they
3345 /* Nonzero if this section has TLS related relocations. */
3346 #define has_tls_reloc sec_flg0
3348 /* Nonzero if this section has a call to __tls_get_addr lacking marker
3350 #define nomark_tls_get_addr sec_flg1
3352 /* Nonzero if this section has any toc or got relocs. */
3353 #define has_toc_reloc sec_flg2
3355 /* Nonzero if this section has a call to another section that uses
3357 #define makes_toc_func_call sec_flg3
3359 /* Recursion protection when determining above flag. */
3360 #define call_check_in_progress sec_flg4
3361 #define call_check_done sec_flg5
3363 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3365 #define ppc_hash_table(p) \
3366 ((is_elf_hash_table ((p)->hash) \
3367 && elf_hash_table_id (elf_hash_table (p)) == PPC64_ELF_DATA) \
3368 ? (struct ppc_link_hash_table *) (p)->hash : NULL)
3370 #define ppc_stub_hash_lookup(table, string, create, copy) \
3371 ((struct ppc_stub_hash_entry *) \
3372 bfd_hash_lookup ((table), (string), (create), (copy)))
3374 #define ppc_branch_hash_lookup(table, string, create, copy) \
3375 ((struct ppc_branch_hash_entry *) \
3376 bfd_hash_lookup ((table), (string), (create), (copy)))
3378 /* Create an entry in the stub hash table. */
3380 static struct bfd_hash_entry
*
3381 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3382 struct bfd_hash_table
*table
,
3385 /* Allocate the structure if it has not already been allocated by a
3389 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3394 /* Call the allocation method of the superclass. */
3395 entry
= bfd_hash_newfunc (entry
, table
, string
);
3398 struct ppc_stub_hash_entry
*eh
;
3400 /* Initialize the local fields. */
3401 eh
= (struct ppc_stub_hash_entry
*) entry
;
3402 eh
->type
.main
= ppc_stub_none
;
3403 eh
->type
.sub
= ppc_stub_toc
;
3404 eh
->type
.r2save
= 0;
3406 eh
->stub_offset
= 0;
3407 eh
->target_value
= 0;
3408 eh
->target_section
= NULL
;
3419 /* Create an entry in the branch hash table. */
3421 static struct bfd_hash_entry
*
3422 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3423 struct bfd_hash_table
*table
,
3426 /* Allocate the structure if it has not already been allocated by a
3430 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3435 /* Call the allocation method of the superclass. */
3436 entry
= bfd_hash_newfunc (entry
, table
, string
);
3439 struct ppc_branch_hash_entry
*eh
;
3441 /* Initialize the local fields. */
3442 eh
= (struct ppc_branch_hash_entry
*) entry
;
3450 /* Create an entry in a ppc64 ELF linker hash table. */
3452 static struct bfd_hash_entry
*
3453 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3454 struct bfd_hash_table
*table
,
3457 /* Allocate the structure if it has not already been allocated by a
3461 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3466 /* Call the allocation method of the superclass. */
3467 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3470 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3472 memset (&eh
->u
.stub_cache
, 0,
3473 (sizeof (struct ppc_link_hash_entry
)
3474 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3476 /* When making function calls, old ABI code references function entry
3477 points (dot symbols), while new ABI code references the function
3478 descriptor symbol. We need to make any combination of reference and
3479 definition work together, without breaking archive linking.
3481 For a defined function "foo" and an undefined call to "bar":
3482 An old object defines "foo" and ".foo", references ".bar" (possibly
3484 A new object defines "foo" and references "bar".
3486 A new object thus has no problem with its undefined symbols being
3487 satisfied by definitions in an old object. On the other hand, the
3488 old object won't have ".bar" satisfied by a new object.
3490 Keep a list of newly added dot-symbols. */
3492 if (string
[0] == '.')
3494 struct ppc_link_hash_table
*htab
;
3496 htab
= (struct ppc_link_hash_table
*) table
;
3497 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3498 htab
->dot_syms
= eh
;
3505 struct tocsave_entry
3512 tocsave_htab_hash (const void *p
)
3514 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3515 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3519 tocsave_htab_eq (const void *p1
, const void *p2
)
3521 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3522 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3523 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3526 /* Destroy a ppc64 ELF linker hash table. */
3529 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3531 struct ppc_link_hash_table
*htab
;
3533 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3534 if (htab
->tocsave_htab
)
3535 htab_delete (htab
->tocsave_htab
);
3536 bfd_hash_table_free (&htab
->branch_hash_table
);
3537 bfd_hash_table_free (&htab
->stub_hash_table
);
3538 _bfd_elf_link_hash_table_free (obfd
);
3541 /* Create a ppc64 ELF linker hash table. */
3543 static struct bfd_link_hash_table
*
3544 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3546 struct ppc_link_hash_table
*htab
;
3547 size_t amt
= sizeof (struct ppc_link_hash_table
);
3549 htab
= bfd_zmalloc (amt
);
3553 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3554 sizeof (struct ppc_link_hash_entry
),
3561 /* Init the stub hash table too. */
3562 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3563 sizeof (struct ppc_stub_hash_entry
)))
3565 _bfd_elf_link_hash_table_free (abfd
);
3569 /* And the branch hash table. */
3570 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3571 sizeof (struct ppc_branch_hash_entry
)))
3573 bfd_hash_table_free (&htab
->stub_hash_table
);
3574 _bfd_elf_link_hash_table_free (abfd
);
3578 htab
->tocsave_htab
= htab_try_create (1024,
3582 if (htab
->tocsave_htab
== NULL
)
3584 ppc64_elf_link_hash_table_free (abfd
);
3587 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3589 /* Initializing two fields of the union is just cosmetic. We really
3590 only care about glist, but when compiled on a 32-bit host the
3591 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3592 debugger inspection of these fields look nicer. */
3593 htab
->elf
.init_got_refcount
.refcount
= 0;
3594 htab
->elf
.init_got_refcount
.glist
= NULL
;
3595 htab
->elf
.init_plt_refcount
.refcount
= 0;
3596 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3597 htab
->elf
.init_got_offset
.offset
= 0;
3598 htab
->elf
.init_got_offset
.glist
= NULL
;
3599 htab
->elf
.init_plt_offset
.offset
= 0;
3600 htab
->elf
.init_plt_offset
.glist
= NULL
;
3602 return &htab
->elf
.root
;
3605 /* Create sections for linker generated code. */
3608 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3610 struct ppc_link_hash_table
*htab
;
3613 htab
= ppc_hash_table (info
);
3615 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3616 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3617 if (htab
->params
->save_restore_funcs
)
3619 /* Create .sfpr for code to save and restore fp regs. */
3620 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3622 if (htab
->sfpr
== NULL
3623 || !bfd_set_section_alignment (htab
->sfpr
, 2))
3627 if (bfd_link_relocatable (info
))
3630 /* Create .glink for lazy dynamic linking support. */
3631 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3633 if (htab
->glink
== NULL
3634 || !bfd_set_section_alignment (htab
->glink
, 3))
3637 /* The part of .glink used by global entry stubs, separate so that
3638 it can be aligned appropriately without affecting htab->glink. */
3639 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3641 if (htab
->global_entry
== NULL
3642 || !bfd_set_section_alignment (htab
->global_entry
, 2))
3645 if (!info
->no_ld_generated_unwind_info
)
3647 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3648 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3649 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3652 if (htab
->glink_eh_frame
== NULL
3653 || !bfd_set_section_alignment (htab
->glink_eh_frame
, 2))
3657 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3658 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3659 if (htab
->elf
.iplt
== NULL
3660 || !bfd_set_section_alignment (htab
->elf
.iplt
, 3))
3663 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3664 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3666 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3667 if (htab
->elf
.irelplt
== NULL
3668 || !bfd_set_section_alignment (htab
->elf
.irelplt
, 3))
3671 /* Create branch lookup table for plt_branch stubs. */
3672 flags
= (SEC_ALLOC
| SEC_LOAD
3673 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3674 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3676 if (htab
->brlt
== NULL
3677 || !bfd_set_section_alignment (htab
->brlt
, 3))
3680 /* Local plt entries, put in .branch_lt but a separate section for
3682 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3684 if (htab
->pltlocal
== NULL
3685 || !bfd_set_section_alignment (htab
->pltlocal
, 3))
3688 if (!bfd_link_pic (info
))
3691 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3692 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3694 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3695 if (htab
->relbrlt
== NULL
3696 || !bfd_set_section_alignment (htab
->relbrlt
, 3))
3700 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3701 if (htab
->relpltlocal
== NULL
3702 || !bfd_set_section_alignment (htab
->relpltlocal
, 3))
3708 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3711 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3712 struct ppc64_elf_params
*params
)
3714 struct ppc_link_hash_table
*htab
;
3716 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3718 /* Always hook our dynamic sections into the first bfd, which is the
3719 linker created stub bfd. This ensures that the GOT header is at
3720 the start of the output TOC section. */
3721 htab
= ppc_hash_table (info
);
3722 htab
->elf
.dynobj
= params
->stub_bfd
;
3723 htab
->params
= params
;
3725 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3728 /* Build a name for an entry in the stub hash table. */
3731 ppc_stub_name (const asection
*input_section
,
3732 const asection
*sym_sec
,
3733 const struct ppc_link_hash_entry
*h
,
3734 const Elf_Internal_Rela
*rel
)
3739 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3740 offsets from a sym as a branch target? In fact, we could
3741 probably assume the addend is always zero. */
3742 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3746 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3747 stub_name
= bfd_malloc (len
);
3748 if (stub_name
== NULL
)
3751 len
= sprintf (stub_name
, "%08x.%s+%x",
3752 input_section
->id
& 0xffffffff,
3753 h
->elf
.root
.root
.string
,
3754 (int) rel
->r_addend
& 0xffffffff);
3758 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3759 stub_name
= bfd_malloc (len
);
3760 if (stub_name
== NULL
)
3763 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3764 input_section
->id
& 0xffffffff,
3765 sym_sec
->id
& 0xffffffff,
3766 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3767 (int) rel
->r_addend
& 0xffffffff);
3769 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3770 stub_name
[len
- 2] = 0;
3774 /* If mixing power10 with non-power10 code and --power10-stubs is not
3775 specified (or is auto) then there may be multiple stub types for any
3776 given symbol. Up to three classes of stubs are stored in separate
3777 stub_hash_table entries having the same key string. The entries
3778 will always be adjacent on entry->root.next chain, even if hash
3779 table resizing occurs. This function selects the correct entry to
3782 static struct ppc_stub_hash_entry
*
3783 select_alt_stub (struct ppc_stub_hash_entry
*entry
,
3784 enum elf_ppc64_reloc_type r_type
)
3786 enum ppc_stub_sub_type subt
;
3790 case R_PPC64_REL24_NOTOC
:
3791 subt
= ppc_stub_notoc
;
3793 case R_PPC64_REL24_P9NOTOC
:
3794 subt
= ppc_stub_p9notoc
;
3797 subt
= ppc_stub_toc
;
3801 while (entry
!= NULL
&& entry
->type
.sub
!= subt
)
3803 const char *stub_name
= entry
->root
.string
;
3805 entry
= (struct ppc_stub_hash_entry
*) entry
->root
.next
;
3807 && entry
->root
.string
!= stub_name
)
3814 /* Look up an entry in the stub hash. Stub entries are cached because
3815 creating the stub name takes a bit of time. */
3817 static struct ppc_stub_hash_entry
*
3818 ppc_get_stub_entry (const asection
*input_section
,
3819 const asection
*sym_sec
,
3820 struct ppc_link_hash_entry
*h
,
3821 const Elf_Internal_Rela
*rel
,
3822 struct ppc_link_hash_table
*htab
)
3824 struct ppc_stub_hash_entry
*stub_entry
;
3825 struct map_stub
*group
;
3827 /* If this input section is part of a group of sections sharing one
3828 stub section, then use the id of the first section in the group.
3829 Stub names need to include a section id, as there may well be
3830 more than one stub used to reach say, printf, and we need to
3831 distinguish between them. */
3832 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3836 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3837 && h
->u
.stub_cache
->h
== h
3838 && h
->u
.stub_cache
->group
== group
)
3840 stub_entry
= h
->u
.stub_cache
;
3846 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3847 if (stub_name
== NULL
)
3850 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3851 stub_name
, false, false);
3853 h
->u
.stub_cache
= stub_entry
;
3858 if (stub_entry
!= NULL
&& htab
->params
->power10_stubs
== -1)
3859 stub_entry
= select_alt_stub (stub_entry
, ELF64_R_TYPE (rel
->r_info
));
3864 /* Add a new stub entry to the stub hash. Not all fields of the new
3865 stub entry are initialised. */
3867 static struct ppc_stub_hash_entry
*
3868 ppc_add_stub (const char *stub_name
,
3870 struct bfd_link_info
*info
)
3872 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3873 struct map_stub
*group
;
3876 struct ppc_stub_hash_entry
*stub_entry
;
3878 group
= htab
->sec_info
[section
->id
].u
.group
;
3879 link_sec
= group
->link_sec
;
3880 stub_sec
= group
->stub_sec
;
3881 if (stub_sec
== NULL
)
3887 namelen
= strlen (link_sec
->name
);
3888 len
= namelen
+ sizeof (STUB_SUFFIX
);
3889 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3893 memcpy (s_name
, link_sec
->name
, namelen
);
3894 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3895 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3896 if (stub_sec
== NULL
)
3898 group
->stub_sec
= stub_sec
;
3901 /* Enter this entry into the linker stub hash table. */
3902 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3904 if (stub_entry
== NULL
)
3906 /* xgettext:c-format */
3907 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3908 section
->owner
, stub_name
);
3912 stub_entry
->group
= group
;
3913 stub_entry
->stub_offset
= 0;
3917 /* A stub has already been created, but it may not be the required
3918 type. We shouldn't be transitioning from plt_call to long_branch
3919 stubs or vice versa, but we might be upgrading from plt_call to
3920 plt_call with r2save for example. */
3923 ppc_merge_stub (struct ppc_link_hash_table
*htab
,
3924 struct ppc_stub_hash_entry
*stub_entry
,
3925 struct ppc_stub_type stub_type
,
3926 enum elf_ppc64_reloc_type r_type
)
3928 struct ppc_stub_type old_type
= stub_entry
->type
;
3930 if (old_type
.main
== ppc_stub_save_res
)
3933 if (htab
->params
->power10_stubs
== -1)
3935 /* For --power10-stubs=auto, don't merge _notoc and other
3936 varieties of stubs. */
3937 struct ppc_stub_hash_entry
*alt_stub
;
3939 alt_stub
= select_alt_stub (stub_entry
, r_type
);
3940 if (alt_stub
== NULL
)
3942 alt_stub
= ((struct ppc_stub_hash_entry
*)
3943 stub_hash_newfunc (NULL
,
3944 &htab
->stub_hash_table
,
3945 stub_entry
->root
.string
));
3946 if (alt_stub
== NULL
)
3949 *alt_stub
= *stub_entry
;
3950 stub_entry
->root
.next
= &alt_stub
->root
;
3952 /* Sort notoc stubs first, then toc stubs, then p9notoc.
3953 Not that it matters, this just puts smaller stubs first. */
3954 if (stub_type
.sub
== ppc_stub_notoc
)
3955 alt_stub
= stub_entry
;
3956 else if (stub_type
.sub
== ppc_stub_p9notoc
3957 && alt_stub
->root
.next
3958 && alt_stub
->root
.next
->string
== alt_stub
->root
.string
)
3960 struct ppc_stub_hash_entry
*next
3961 = (struct ppc_stub_hash_entry
*) alt_stub
->root
.next
;
3962 alt_stub
->type
= next
->type
;
3965 alt_stub
->type
= stub_type
;
3968 stub_entry
= alt_stub
;
3971 old_type
= stub_entry
->type
;
3972 if (old_type
.main
== ppc_stub_plt_branch
)
3973 old_type
.main
= ppc_stub_long_branch
;
3975 if (old_type
.main
!= stub_type
.main
3976 || (old_type
.sub
!= stub_type
.sub
3977 && old_type
.sub
!= ppc_stub_toc
3978 && stub_type
.sub
!= ppc_stub_toc
))
3981 stub_entry
->type
.sub
|= stub_type
.sub
;
3982 stub_entry
->type
.r2save
|= stub_type
.r2save
;
3986 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3987 not already done. */
3990 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3992 asection
*got
, *relgot
;
3994 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3996 if (!is_ppc64_elf (abfd
))
4002 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4005 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4006 | SEC_LINKER_CREATED
);
4008 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4010 || !bfd_set_section_alignment (got
, 3))
4013 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4014 flags
| SEC_READONLY
);
4016 || !bfd_set_section_alignment (relgot
, 3))
4019 ppc64_elf_tdata (abfd
)->got
= got
;
4020 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4024 /* Follow indirect and warning symbol links. */
4026 static inline struct bfd_link_hash_entry
*
4027 follow_link (struct bfd_link_hash_entry
*h
)
4029 while (h
->type
== bfd_link_hash_indirect
4030 || h
->type
== bfd_link_hash_warning
)
4035 static inline struct elf_link_hash_entry
*
4036 elf_follow_link (struct elf_link_hash_entry
*h
)
4038 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4041 static inline struct ppc_link_hash_entry
*
4042 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4044 return ppc_elf_hash_entry (elf_follow_link (&h
->elf
));
4047 /* Merge PLT info on FROM with that on TO. */
4050 move_plt_plist (struct ppc_link_hash_entry
*from
,
4051 struct ppc_link_hash_entry
*to
)
4053 if (from
->elf
.plt
.plist
!= NULL
)
4055 if (to
->elf
.plt
.plist
!= NULL
)
4057 struct plt_entry
**entp
;
4058 struct plt_entry
*ent
;
4060 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4062 struct plt_entry
*dent
;
4064 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4065 if (dent
->addend
== ent
->addend
)
4067 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4074 *entp
= to
->elf
.plt
.plist
;
4077 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4078 from
->elf
.plt
.plist
= NULL
;
4082 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4085 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4086 struct elf_link_hash_entry
*dir
,
4087 struct elf_link_hash_entry
*ind
)
4089 struct ppc_link_hash_entry
*edir
, *eind
;
4091 edir
= ppc_elf_hash_entry (dir
);
4092 eind
= ppc_elf_hash_entry (ind
);
4094 edir
->is_func
|= eind
->is_func
;
4095 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4096 edir
->tls_mask
|= eind
->tls_mask
;
4097 if (eind
->oh
!= NULL
)
4098 edir
->oh
= ppc_follow_link (eind
->oh
);
4100 if (edir
->elf
.versioned
!= versioned_hidden
)
4101 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4102 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4103 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4104 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4105 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4106 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4108 /* If we were called to copy over info for a weak sym, don't copy
4109 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4110 in order to simplify readonly_dynrelocs and save a field in the
4111 symbol hash entry, but that means dyn_relocs can't be used in any
4112 tests about a specific symbol, or affect other symbol flags which
4114 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4117 /* Copy over any dynamic relocs we may have on the indirect sym. */
4118 if (ind
->dyn_relocs
!= NULL
)
4120 if (dir
->dyn_relocs
!= NULL
)
4122 struct ppc_dyn_relocs
**pp
;
4123 struct ppc_dyn_relocs
*p
;
4125 /* Add reloc counts against the indirect sym to the direct sym
4126 list. Merge any entries against the same section. */
4127 for (pp
= (struct ppc_dyn_relocs
**) &ind
->dyn_relocs
;
4131 struct ppc_dyn_relocs
*q
;
4133 for (q
= (struct ppc_dyn_relocs
*) dir
->dyn_relocs
;
4136 if (q
->sec
== p
->sec
)
4138 q
->count
+= p
->count
;
4139 q
->pc_count
+= p
->pc_count
;
4140 q
->rel_count
+= p
->rel_count
;
4147 *pp
= (struct ppc_dyn_relocs
*) dir
->dyn_relocs
;
4150 dir
->dyn_relocs
= ind
->dyn_relocs
;
4151 ind
->dyn_relocs
= NULL
;
4154 /* Copy over got entries that we may have already seen to the
4155 symbol which just became indirect. */
4156 if (eind
->elf
.got
.glist
!= NULL
)
4158 if (edir
->elf
.got
.glist
!= NULL
)
4160 struct got_entry
**entp
;
4161 struct got_entry
*ent
;
4163 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4165 struct got_entry
*dent
;
4167 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4168 if (dent
->addend
== ent
->addend
4169 && dent
->owner
== ent
->owner
4170 && dent
->tls_type
== ent
->tls_type
)
4172 dent
->got
.refcount
+= ent
->got
.refcount
;
4179 *entp
= edir
->elf
.got
.glist
;
4182 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4183 eind
->elf
.got
.glist
= NULL
;
4186 /* And plt entries. */
4187 move_plt_plist (eind
, edir
);
4189 if (eind
->elf
.dynindx
!= -1)
4191 if (edir
->elf
.dynindx
!= -1)
4192 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4193 edir
->elf
.dynstr_index
);
4194 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4195 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4196 eind
->elf
.dynindx
= -1;
4197 eind
->elf
.dynstr_index
= 0;
4201 /* Find the function descriptor hash entry from the given function code
4202 hash entry FH. Link the entries via their OH fields. */
4204 static struct ppc_link_hash_entry
*
4205 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4207 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4211 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4213 fdh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, fd_name
,
4214 false, false, false));
4218 fdh
->is_func_descriptor
= 1;
4224 fdh
= ppc_follow_link (fdh
);
4225 fdh
->is_func_descriptor
= 1;
4230 /* Make a fake function descriptor sym for the undefined code sym FH. */
4232 static struct ppc_link_hash_entry
*
4233 make_fdh (struct bfd_link_info
*info
,
4234 struct ppc_link_hash_entry
*fh
)
4236 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4237 struct bfd_link_hash_entry
*bh
= NULL
;
4238 struct ppc_link_hash_entry
*fdh
;
4239 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4243 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4244 fh
->elf
.root
.root
.string
+ 1,
4245 flags
, bfd_und_section_ptr
, 0,
4246 NULL
, false, false, &bh
))
4249 fdh
= (struct ppc_link_hash_entry
*) bh
;
4250 fdh
->elf
.non_elf
= 0;
4252 fdh
->is_func_descriptor
= 1;
4259 /* Fix function descriptor symbols defined in .opd sections to be
4263 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4264 struct bfd_link_info
*info
,
4265 Elf_Internal_Sym
*isym
,
4267 flagword
*flags ATTRIBUTE_UNUSED
,
4272 && strcmp ((*sec
)->name
, ".opd") == 0)
4276 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4277 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4278 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4280 /* If the symbol is a function defined in .opd, and the function
4281 code is in a discarded group, let it appear to be undefined. */
4282 if (!bfd_link_relocatable (info
)
4283 && (*sec
)->reloc_count
!= 0
4284 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4285 false) != (bfd_vma
) -1
4286 && discarded_section (code_sec
))
4288 *sec
= bfd_und_section_ptr
;
4289 isym
->st_shndx
= SHN_UNDEF
;
4292 else if (*sec
!= NULL
4293 && strcmp ((*sec
)->name
, ".toc") == 0
4294 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4296 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4298 htab
->params
->object_in_toc
= 1;
4301 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4303 if (abiversion (ibfd
) == 0)
4304 set_abiversion (ibfd
, 2);
4305 else if (abiversion (ibfd
) == 1)
4307 _bfd_error_handler (_("symbol '%s' has invalid st_other"
4308 " for ABI version 1"), *name
);
4309 bfd_set_error (bfd_error_bad_value
);
4317 /* Merge non-visibility st_other attributes: local entry point. */
4320 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
4321 unsigned int st_other
,
4325 if (definition
&& (!dynamic
|| !h
->def_regular
))
4326 h
->other
= ((st_other
& ~ELF_ST_VISIBILITY (-1))
4327 | ELF_ST_VISIBILITY (h
->other
));
4330 /* Hook called on merging a symbol. We use this to clear "fake" since
4331 we now have a real symbol. */
4334 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
4335 const Elf_Internal_Sym
*isym
,
4336 asection
**psec ATTRIBUTE_UNUSED
,
4337 bool newdef ATTRIBUTE_UNUSED
,
4338 bool olddef ATTRIBUTE_UNUSED
,
4339 bfd
*oldbfd ATTRIBUTE_UNUSED
,
4340 const asection
*oldsec ATTRIBUTE_UNUSED
)
4342 ppc_elf_hash_entry (h
)->fake
= 0;
4343 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4344 ppc_elf_hash_entry (h
)->non_zero_localentry
= 1;
4348 /* This function makes an old ABI object reference to ".bar" cause the
4349 inclusion of a new ABI object archive that defines "bar".
4350 NAME is a symbol defined in an archive. Return a symbol in the hash
4351 table that might be satisfied by the archive symbols. */
4353 static struct bfd_link_hash_entry
*
4354 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4355 struct bfd_link_info
*info
,
4358 struct bfd_link_hash_entry
*h
;
4362 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4364 && ppc_hash_table (info
) != NULL
4365 /* Don't return this sym if it is a fake function descriptor
4366 created by add_symbol_adjust. */
4367 && !((struct ppc_link_hash_entry
*) h
)->fake
)
4373 len
= strlen (name
);
4374 dot_name
= bfd_alloc (abfd
, len
+ 2);
4375 if (dot_name
== NULL
)
4376 return (struct bfd_link_hash_entry
*) -1;
4378 memcpy (dot_name
+ 1, name
, len
+ 1);
4379 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4380 bfd_release (abfd
, dot_name
);
4384 if (strcmp (name
, "__tls_get_addr_opt") == 0)
4385 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, "__tls_get_addr_desc");
4389 /* This function satisfies all old ABI object references to ".bar" if a
4390 new ABI object defines "bar". Well, at least, undefined dot symbols
4391 are made weak. This stops later archive searches from including an
4392 object if we already have a function descriptor definition. It also
4393 prevents the linker complaining about undefined symbols.
4394 We also check and correct mismatched symbol visibility here. The
4395 most restrictive visibility of the function descriptor and the
4396 function entry symbol is used. */
4399 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4401 struct ppc_link_hash_table
*htab
;
4402 struct ppc_link_hash_entry
*fdh
;
4404 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4405 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4407 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4410 if (eh
->elf
.root
.root
.string
[0] != '.')
4413 htab
= ppc_hash_table (info
);
4417 fdh
= lookup_fdh (eh
, htab
);
4419 && !bfd_link_relocatable (info
)
4420 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4421 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4422 && eh
->elf
.ref_regular
)
4424 /* Make an undefined function descriptor sym, in order to
4425 pull in an --as-needed shared lib. Archives are handled
4427 fdh
= make_fdh (info
, eh
);
4434 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4435 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4437 /* Make both descriptor and entry symbol have the most
4438 constraining visibility of either symbol. */
4439 if (entry_vis
< descr_vis
)
4440 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4441 else if (entry_vis
> descr_vis
)
4442 eh
->elf
.other
+= descr_vis
- entry_vis
;
4444 /* Propagate reference flags from entry symbol to function
4445 descriptor symbol. */
4446 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
4447 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
4448 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
4449 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
4451 if (!fdh
->elf
.forced_local
4452 && fdh
->elf
.dynindx
== -1
4453 && fdh
->elf
.versioned
!= versioned_hidden
4454 && (bfd_link_dll (info
)
4455 || fdh
->elf
.def_dynamic
4456 || fdh
->elf
.ref_dynamic
)
4457 && (eh
->elf
.ref_regular
4458 || eh
->elf
.def_regular
))
4460 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
4468 /* Set up opd section info and abiversion for IBFD, and process list
4469 of dot-symbols we made in link_hash_newfunc. */
4472 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
4474 struct ppc_link_hash_table
*htab
;
4475 struct ppc_link_hash_entry
**p
, *eh
;
4476 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
4478 if (opd
!= NULL
&& opd
->size
!= 0)
4480 if (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
)
4481 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
4482 else if (ppc64_elf_section_data (opd
)->sec_type
!= sec_opd
)
4485 if (abiversion (ibfd
) == 0)
4486 set_abiversion (ibfd
, 1);
4487 else if (abiversion (ibfd
) >= 2)
4489 /* xgettext:c-format */
4490 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4491 ibfd
, abiversion (ibfd
));
4492 bfd_set_error (bfd_error_bad_value
);
4497 if (is_ppc64_elf (info
->output_bfd
))
4499 /* For input files without an explicit abiversion in e_flags
4500 we should have flagged any with symbol st_other bits set
4501 as ELFv2 and above flagged those with .opd as ELFv1.
4502 Set the output abiversion if not yet set, and for any input
4503 still ambiguous, take its abiversion from the output.
4504 Differences in ABI are reported later. */
4505 if (abiversion (info
->output_bfd
) == 0)
4506 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4507 else if (abiversion (ibfd
) == 0)
4508 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4511 htab
= ppc_hash_table (info
);
4515 if (opd
!= NULL
&& opd
->size
!= 0
4516 && (ibfd
->flags
& DYNAMIC
) == 0
4517 && (opd
->flags
& SEC_RELOC
) != 0
4518 && opd
->reloc_count
!= 0
4519 && !bfd_is_abs_section (opd
->output_section
)
4520 && info
->gc_sections
)
4522 /* Garbage collection needs some extra help with .opd sections.
4523 We don't want to necessarily keep everything referenced by
4524 relocs in .opd, as that would keep all functions. Instead,
4525 if we reference an .opd symbol (a function descriptor), we
4526 want to keep the function code symbol's section. This is
4527 easy for global symbols, but for local syms we need to keep
4528 information about the associated function section. */
4530 asection
**opd_sym_map
;
4531 Elf_Internal_Shdr
*symtab_hdr
;
4532 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4534 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4535 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4536 if (opd_sym_map
== NULL
)
4538 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4539 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4543 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4544 rel_end
= relocs
+ opd
->reloc_count
- 1;
4545 for (rel
= relocs
; rel
< rel_end
; rel
++)
4547 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4548 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4550 if (r_type
== R_PPC64_ADDR64
4551 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4552 && r_symndx
< symtab_hdr
->sh_info
)
4554 Elf_Internal_Sym
*isym
;
4557 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, ibfd
,
4561 if (elf_section_data (opd
)->relocs
!= relocs
)
4566 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4567 if (s
!= NULL
&& s
!= opd
)
4568 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4571 if (elf_section_data (opd
)->relocs
!= relocs
)
4575 p
= &htab
->dot_syms
;
4576 while ((eh
= *p
) != NULL
)
4579 if (&eh
->elf
== htab
->elf
.hgot
)
4581 else if (htab
->elf
.hgot
== NULL
4582 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4583 htab
->elf
.hgot
= &eh
->elf
;
4584 else if (abiversion (ibfd
) <= 1)
4586 htab
->need_func_desc_adj
= 1;
4587 if (!add_symbol_adjust (eh
, info
))
4590 p
= &eh
->u
.next_dot_sym
;
4595 /* Undo hash table changes when an --as-needed input file is determined
4596 not to be needed. */
4599 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4600 struct bfd_link_info
*info
,
4601 enum notice_asneeded_action act
)
4603 if (act
== notice_not_needed
)
4605 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4610 htab
->dot_syms
= NULL
;
4612 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4615 /* If --just-symbols against a final linked binary, then assume we need
4616 toc adjusting stubs when calling functions defined there. */
4619 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4621 if ((sec
->flags
& SEC_CODE
) != 0
4622 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4623 && is_ppc64_elf (sec
->owner
))
4625 if (abiversion (sec
->owner
) >= 2
4626 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4627 sec
->has_toc_reloc
= 1;
4629 _bfd_elf_link_just_syms (sec
, info
);
4632 static struct plt_entry
**
4633 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4634 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4636 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4637 struct plt_entry
**local_plt
;
4638 unsigned char *local_got_tls_masks
;
4640 if (local_got_ents
== NULL
)
4642 bfd_size_type size
= symtab_hdr
->sh_info
;
4644 size
*= (sizeof (*local_got_ents
)
4645 + sizeof (*local_plt
)
4646 + sizeof (*local_got_tls_masks
));
4647 local_got_ents
= bfd_zalloc (abfd
, size
);
4648 if (local_got_ents
== NULL
)
4650 elf_local_got_ents (abfd
) = local_got_ents
;
4653 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4655 struct got_entry
*ent
;
4657 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4658 if (ent
->addend
== r_addend
4659 && ent
->owner
== abfd
4660 && ent
->tls_type
== tls_type
)
4664 size_t amt
= sizeof (*ent
);
4665 ent
= bfd_alloc (abfd
, amt
);
4668 ent
->next
= local_got_ents
[r_symndx
];
4669 ent
->addend
= r_addend
;
4671 ent
->tls_type
= tls_type
;
4672 ent
->is_indirect
= false;
4673 ent
->got
.refcount
= 0;
4674 local_got_ents
[r_symndx
] = ent
;
4676 ent
->got
.refcount
+= 1;
4679 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4680 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4681 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4683 return local_plt
+ r_symndx
;
4687 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4689 struct plt_entry
*ent
;
4691 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4692 if (ent
->addend
== addend
)
4696 size_t amt
= sizeof (*ent
);
4697 ent
= bfd_alloc (abfd
, amt
);
4701 ent
->addend
= addend
;
4702 ent
->plt
.refcount
= 0;
4705 ent
->plt
.refcount
+= 1;
4710 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4712 return (r_type
== R_PPC64_REL24
4713 || r_type
== R_PPC64_REL24_NOTOC
4714 || r_type
== R_PPC64_REL24_P9NOTOC
4715 || r_type
== R_PPC64_REL14
4716 || r_type
== R_PPC64_REL14_BRTAKEN
4717 || r_type
== R_PPC64_REL14_BRNTAKEN
4718 || r_type
== R_PPC64_ADDR24
4719 || r_type
== R_PPC64_ADDR14
4720 || r_type
== R_PPC64_ADDR14_BRTAKEN
4721 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4722 || r_type
== R_PPC64_PLTCALL
4723 || r_type
== R_PPC64_PLTCALL_NOTOC
);
4726 /* Relocs on inline plt call sequence insns prior to the call. */
4729 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4731 return (r_type
== R_PPC64_PLT16_HA
4732 || r_type
== R_PPC64_PLT16_HI
4733 || r_type
== R_PPC64_PLT16_LO
4734 || r_type
== R_PPC64_PLT16_LO_DS
4735 || r_type
== R_PPC64_PLT_PCREL34
4736 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4737 || r_type
== R_PPC64_PLTSEQ
4738 || r_type
== R_PPC64_PLTSEQ_NOTOC
);
4741 /* Of relocs which might appear paired with TLSGD and TLSLD marker
4742 relocs, return true for those that operate on a dword. */
4745 is_8byte_reloc (enum elf_ppc64_reloc_type r_type
)
4747 return (r_type
== R_PPC64_PLT_PCREL34
4748 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4749 || r_type
== R_PPC64_PLTCALL
);
4752 /* The RELR encoding doesn't allow odd addresses, so RELR_ALIGN must
4753 be at least 1. R_PPC64_RELATIVE relocs require alignment of 2**3.
4754 We use 3 here to avoid complexity in relocate_section, where for a
4755 value of 1 we'd need to test for not just an output RELATIVE reloc
4756 near the call to maybe_relr but also UADDR64 and some conditions on
4757 the symbol. See PR30824. */
4758 #define RELR_ALIGN 3
4761 maybe_relr (enum elf_ppc64_reloc_type r_type
,
4762 const Elf_Internal_Rela
*rel
,
4763 const asection
*sec
)
4765 return ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
4766 && (rel
->r_offset
& ((1 << RELR_ALIGN
) - 1)) == 0
4767 && sec
->alignment_power
>= RELR_ALIGN
);
4770 /* Like bfd_reloc_offset_in_range but without a howto. Return true
4771 iff a field of SIZE bytes at OFFSET is within SEC limits. */
4774 offset_in_range (asection
*sec
, bfd_vma offset
, size_t size
)
4776 return offset
<= sec
->size
&& size
<= sec
->size
- offset
;
4779 /* Look through the relocs for a section during the first phase, and
4780 calculate needed space in the global offset table, procedure
4781 linkage table, and dynamic reloc sections. */
4784 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4785 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4787 struct ppc_link_hash_table
*htab
;
4788 Elf_Internal_Shdr
*symtab_hdr
;
4789 struct elf_link_hash_entry
**sym_hashes
;
4790 const Elf_Internal_Rela
*rel
;
4791 const Elf_Internal_Rela
*rel_end
;
4793 struct elf_link_hash_entry
*tga
, *dottga
;
4796 if (bfd_link_relocatable (info
))
4799 BFD_ASSERT (is_ppc64_elf (abfd
));
4801 htab
= ppc_hash_table (info
);
4805 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4806 false, false, true);
4807 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4808 false, false, true);
4809 symtab_hdr
= &elf_symtab_hdr (abfd
);
4810 sym_hashes
= elf_sym_hashes (abfd
);
4812 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4813 rel_end
= relocs
+ sec
->reloc_count
;
4814 for (rel
= relocs
; rel
< rel_end
; rel
++)
4816 unsigned long r_symndx
;
4817 struct elf_link_hash_entry
*h
;
4818 Elf_Internal_Sym
*isym
;
4819 enum elf_ppc64_reloc_type r_type
;
4821 struct _ppc64_elf_section_data
*ppc64_sec
;
4822 struct plt_entry
**ifunc
, **plt_list
;
4824 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4825 if (r_symndx
< symtab_hdr
->sh_info
)
4828 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, abfd
, r_symndx
);
4835 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4836 h
= elf_follow_link (h
);
4838 if (h
== htab
->elf
.hgot
)
4839 sec
->has_toc_reloc
= 1;
4842 r_type
= ELF64_R_TYPE (rel
->r_info
);
4846 case R_PPC64_D34_LO
:
4847 case R_PPC64_D34_HI30
:
4848 case R_PPC64_D34_HA30
:
4850 case R_PPC64_TPREL34
:
4851 case R_PPC64_DTPREL34
:
4852 case R_PPC64_PCREL34
:
4853 case R_PPC64_GOT_PCREL34
:
4854 case R_PPC64_GOT_TLSGD_PCREL34
:
4855 case R_PPC64_GOT_TLSLD_PCREL34
:
4856 case R_PPC64_GOT_TPREL_PCREL34
:
4857 case R_PPC64_GOT_DTPREL_PCREL34
:
4858 case R_PPC64_PLT_PCREL34
:
4859 case R_PPC64_PLT_PCREL34_NOTOC
:
4860 case R_PPC64_PCREL28
:
4861 htab
->has_power10_relocs
= 1;
4869 case R_PPC64_PLT16_HA
:
4870 case R_PPC64_GOT_TLSLD16_HA
:
4871 case R_PPC64_GOT_TLSGD16_HA
:
4872 case R_PPC64_GOT_TPREL16_HA
:
4873 case R_PPC64_GOT_DTPREL16_HA
:
4874 case R_PPC64_GOT16_HA
:
4875 case R_PPC64_TOC16_HA
:
4876 case R_PPC64_PLT16_LO
:
4877 case R_PPC64_PLT16_LO_DS
:
4878 case R_PPC64_GOT_TLSLD16_LO
:
4879 case R_PPC64_GOT_TLSGD16_LO
:
4880 case R_PPC64_GOT_TPREL16_LO_DS
:
4881 case R_PPC64_GOT_DTPREL16_LO_DS
:
4882 case R_PPC64_GOT16_LO
:
4883 case R_PPC64_GOT16_LO_DS
:
4884 case R_PPC64_TOC16_LO
:
4885 case R_PPC64_TOC16_LO_DS
:
4886 case R_PPC64_GOT_PCREL34
:
4887 ppc64_elf_tdata (abfd
)->has_optrel
= 1;
4888 ppc64_elf_section_data (sec
)->has_optrel
= 1;
4897 if (h
->type
== STT_GNU_IFUNC
)
4900 ifunc
= &h
->plt
.plist
;
4905 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4907 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4909 NON_GOT
| PLT_IFUNC
);
4920 /* These special tls relocs tie a call to __tls_get_addr with
4921 its parameter symbol. */
4923 ppc_elf_hash_entry (h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4925 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4927 NON_GOT
| TLS_TLS
| TLS_MARK
))
4929 sec
->has_tls_reloc
= 1;
4932 case R_PPC64_GOT_TLSLD16
:
4933 case R_PPC64_GOT_TLSLD16_LO
:
4934 case R_PPC64_GOT_TLSLD16_HI
:
4935 case R_PPC64_GOT_TLSLD16_HA
:
4936 case R_PPC64_GOT_TLSLD_PCREL34
:
4937 tls_type
= TLS_TLS
| TLS_LD
;
4940 case R_PPC64_GOT_TLSGD16
:
4941 case R_PPC64_GOT_TLSGD16_LO
:
4942 case R_PPC64_GOT_TLSGD16_HI
:
4943 case R_PPC64_GOT_TLSGD16_HA
:
4944 case R_PPC64_GOT_TLSGD_PCREL34
:
4945 tls_type
= TLS_TLS
| TLS_GD
;
4948 case R_PPC64_GOT_TPREL16_DS
:
4949 case R_PPC64_GOT_TPREL16_LO_DS
:
4950 case R_PPC64_GOT_TPREL16_HI
:
4951 case R_PPC64_GOT_TPREL16_HA
:
4952 case R_PPC64_GOT_TPREL_PCREL34
:
4953 if (bfd_link_dll (info
))
4954 info
->flags
|= DF_STATIC_TLS
;
4955 tls_type
= TLS_TLS
| TLS_TPREL
;
4958 case R_PPC64_GOT_DTPREL16_DS
:
4959 case R_PPC64_GOT_DTPREL16_LO_DS
:
4960 case R_PPC64_GOT_DTPREL16_HI
:
4961 case R_PPC64_GOT_DTPREL16_HA
:
4962 case R_PPC64_GOT_DTPREL_PCREL34
:
4963 tls_type
= TLS_TLS
| TLS_DTPREL
;
4965 sec
->has_tls_reloc
= 1;
4969 case R_PPC64_GOT16_LO
:
4970 case R_PPC64_GOT16_HI
:
4971 case R_PPC64_GOT16_HA
:
4972 case R_PPC64_GOT16_DS
:
4973 case R_PPC64_GOT16_LO_DS
:
4974 case R_PPC64_GOT_PCREL34
:
4976 /* This symbol requires a global offset table entry. */
4977 sec
->has_toc_reloc
= 1;
4978 if (r_type
== R_PPC64_GOT_TLSLD16
4979 || r_type
== R_PPC64_GOT_TLSGD16
4980 || r_type
== R_PPC64_GOT_TPREL16_DS
4981 || r_type
== R_PPC64_GOT_DTPREL16_DS
4982 || r_type
== R_PPC64_GOT16
4983 || r_type
== R_PPC64_GOT16_DS
)
4985 htab
->do_multi_toc
= 1;
4986 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4989 if (ppc64_elf_tdata (abfd
)->got
== NULL
4990 && !create_got_section (abfd
, info
))
4995 struct ppc_link_hash_entry
*eh
;
4996 struct got_entry
*ent
;
4998 eh
= ppc_elf_hash_entry (h
);
4999 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5000 if (ent
->addend
== rel
->r_addend
5001 && ent
->owner
== abfd
5002 && ent
->tls_type
== tls_type
)
5006 size_t amt
= sizeof (*ent
);
5007 ent
= bfd_alloc (abfd
, amt
);
5010 ent
->next
= eh
->elf
.got
.glist
;
5011 ent
->addend
= rel
->r_addend
;
5013 ent
->tls_type
= tls_type
;
5014 ent
->is_indirect
= false;
5015 ent
->got
.refcount
= 0;
5016 eh
->elf
.got
.glist
= ent
;
5018 ent
->got
.refcount
+= 1;
5019 eh
->tls_mask
|= tls_type
;
5022 /* This is a global offset table entry for a local symbol. */
5023 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5024 rel
->r_addend
, tls_type
))
5028 case R_PPC64_PLT16_HA
:
5029 case R_PPC64_PLT16_HI
:
5030 case R_PPC64_PLT16_LO
:
5031 case R_PPC64_PLT16_LO_DS
:
5032 case R_PPC64_PLT_PCREL34
:
5033 case R_PPC64_PLT_PCREL34_NOTOC
:
5036 /* This symbol requires a procedure linkage table entry. */
5041 if (h
->root
.root
.string
[0] == '.'
5042 && h
->root
.root
.string
[1] != '\0')
5043 ppc_elf_hash_entry (h
)->is_func
= 1;
5044 ppc_elf_hash_entry (h
)->tls_mask
|= PLT_KEEP
;
5045 plt_list
= &h
->plt
.plist
;
5047 if (plt_list
== NULL
)
5048 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5050 NON_GOT
| PLT_KEEP
);
5051 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5055 /* The following relocations don't need to propagate the
5056 relocation if linking a shared object since they are
5057 section relative. */
5058 case R_PPC64_SECTOFF
:
5059 case R_PPC64_SECTOFF_LO
:
5060 case R_PPC64_SECTOFF_HI
:
5061 case R_PPC64_SECTOFF_HA
:
5062 case R_PPC64_SECTOFF_DS
:
5063 case R_PPC64_SECTOFF_LO_DS
:
5064 case R_PPC64_DTPREL16
:
5065 case R_PPC64_DTPREL16_LO
:
5066 case R_PPC64_DTPREL16_HI
:
5067 case R_PPC64_DTPREL16_HA
:
5068 case R_PPC64_DTPREL16_DS
:
5069 case R_PPC64_DTPREL16_LO_DS
:
5070 case R_PPC64_DTPREL16_HIGH
:
5071 case R_PPC64_DTPREL16_HIGHA
:
5072 case R_PPC64_DTPREL16_HIGHER
:
5073 case R_PPC64_DTPREL16_HIGHERA
:
5074 case R_PPC64_DTPREL16_HIGHEST
:
5075 case R_PPC64_DTPREL16_HIGHESTA
:
5080 case R_PPC64_REL16_LO
:
5081 case R_PPC64_REL16_HI
:
5082 case R_PPC64_REL16_HA
:
5083 case R_PPC64_REL16_HIGH
:
5084 case R_PPC64_REL16_HIGHA
:
5085 case R_PPC64_REL16_HIGHER
:
5086 case R_PPC64_REL16_HIGHERA
:
5087 case R_PPC64_REL16_HIGHEST
:
5088 case R_PPC64_REL16_HIGHESTA
:
5089 case R_PPC64_REL16_HIGHER34
:
5090 case R_PPC64_REL16_HIGHERA34
:
5091 case R_PPC64_REL16_HIGHEST34
:
5092 case R_PPC64_REL16_HIGHESTA34
:
5093 case R_PPC64_REL16DX_HA
:
5096 /* Not supported as a dynamic relocation. */
5097 case R_PPC64_ADDR64_LOCAL
:
5098 if (bfd_link_pic (info
))
5100 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5102 /* xgettext:c-format */
5103 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
5104 "in shared libraries and PIEs\n"),
5105 abfd
, sec
, rel
->r_offset
,
5106 ppc64_elf_howto_table
[r_type
]->name
);
5107 bfd_set_error (bfd_error_bad_value
);
5113 case R_PPC64_TOC16_DS
:
5114 htab
->do_multi_toc
= 1;
5115 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5117 case R_PPC64_TOC16_LO
:
5118 case R_PPC64_TOC16_HI
:
5119 case R_PPC64_TOC16_HA
:
5120 case R_PPC64_TOC16_LO_DS
:
5121 sec
->has_toc_reloc
= 1;
5122 if (h
!= NULL
&& bfd_link_executable (info
))
5124 /* We may need a copy reloc. */
5126 /* Strongly prefer a copy reloc over a dynamic reloc.
5127 glibc ld.so as of 2019-08 will error out if one of
5128 these relocations is emitted. */
5138 /* This relocation describes the C++ object vtable hierarchy.
5139 Reconstruct it for later use during GC. */
5140 case R_PPC64_GNU_VTINHERIT
:
5141 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5145 /* This relocation describes which C++ vtable entries are actually
5146 used. Record for later use during GC. */
5147 case R_PPC64_GNU_VTENTRY
:
5148 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5153 case R_PPC64_REL14_BRTAKEN
:
5154 case R_PPC64_REL14_BRNTAKEN
:
5156 asection
*dest
= NULL
;
5158 /* Heuristic: If jumping outside our section, chances are
5159 we are going to need a stub. */
5162 /* If the sym is weak it may be overridden later, so
5163 don't assume we know where a weak sym lives. */
5164 if (h
->root
.type
== bfd_link_hash_defined
)
5165 dest
= h
->root
.u
.def
.section
;
5168 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5171 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5175 case R_PPC64_PLTCALL
:
5176 case R_PPC64_PLTCALL_NOTOC
:
5177 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
5181 case R_PPC64_REL24_NOTOC
:
5182 case R_PPC64_REL24_P9NOTOC
:
5188 if (h
->root
.root
.string
[0] == '.'
5189 && h
->root
.root
.string
[1] != '\0')
5190 ppc_elf_hash_entry (h
)->is_func
= 1;
5192 if (h
== tga
|| h
== dottga
)
5194 sec
->has_tls_reloc
= 1;
5196 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5197 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5198 /* We have a new-style __tls_get_addr call with
5202 /* Mark this section as having an old-style call. */
5203 sec
->nomark_tls_get_addr
= 1;
5205 plt_list
= &h
->plt
.plist
;
5208 /* We may need a .plt entry if the function this reloc
5209 refers to is in a shared lib. */
5211 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5215 case R_PPC64_ADDR14
:
5216 case R_PPC64_ADDR14_BRNTAKEN
:
5217 case R_PPC64_ADDR14_BRTAKEN
:
5218 case R_PPC64_ADDR24
:
5221 case R_PPC64_TPREL64
:
5222 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5223 if (bfd_link_dll (info
))
5224 info
->flags
|= DF_STATIC_TLS
;
5227 case R_PPC64_DTPMOD64
:
5228 if (rel
+ 1 < rel_end
5229 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5230 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5231 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5233 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5236 case R_PPC64_DTPREL64
:
5237 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5239 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5240 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5241 /* This is the second reloc of a dtpmod, dtprel pair.
5242 Don't mark with TLS_DTPREL. */
5246 sec
->has_tls_reloc
= 1;
5248 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
& 0xff;
5250 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5251 rel
->r_addend
, tls_type
))
5254 ppc64_sec
= ppc64_elf_section_data (sec
);
5255 if (ppc64_sec
->sec_type
== sec_normal
)
5259 /* One extra to simplify get_tls_mask. */
5260 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5261 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5262 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5264 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5265 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5266 if (ppc64_sec
->u
.toc
.add
== NULL
)
5268 ppc64_sec
->sec_type
= sec_toc
;
5270 if (ppc64_sec
->sec_type
!= sec_toc
5271 || rel
->r_offset
% 8 != 0)
5273 info
->callbacks
->einfo (_("%H: %s reloc unsupported here\n"),
5274 abfd
, sec
, rel
->r_offset
,
5275 ppc64_elf_howto_table
[r_type
]->name
);
5276 bfd_set_error (bfd_error_bad_value
);
5279 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5280 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5282 /* Mark the second slot of a GD or LD entry.
5283 -1 to indicate GD and -2 to indicate LD. */
5284 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5285 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5286 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5287 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5290 case R_PPC64_TPREL16_HI
:
5291 case R_PPC64_TPREL16_HA
:
5292 case R_PPC64_TPREL16_HIGH
:
5293 case R_PPC64_TPREL16_HIGHA
:
5294 case R_PPC64_TPREL16_HIGHER
:
5295 case R_PPC64_TPREL16_HIGHERA
:
5296 case R_PPC64_TPREL16_HIGHEST
:
5297 case R_PPC64_TPREL16_HIGHESTA
:
5298 sec
->has_tls_reloc
= 1;
5300 case R_PPC64_TPREL34
:
5301 case R_PPC64_TPREL16
:
5302 case R_PPC64_TPREL16_DS
:
5303 case R_PPC64_TPREL16_LO
:
5304 case R_PPC64_TPREL16_LO_DS
:
5305 if (bfd_link_dll (info
))
5306 info
->flags
|= DF_STATIC_TLS
;
5309 case R_PPC64_ADDR64
:
5311 && rel
+ 1 < rel_end
5312 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5315 ppc_elf_hash_entry (h
)->is_func
= 1;
5319 case R_PPC64_ADDR16
:
5320 case R_PPC64_ADDR16_DS
:
5321 case R_PPC64_ADDR16_HA
:
5322 case R_PPC64_ADDR16_HI
:
5323 case R_PPC64_ADDR16_HIGH
:
5324 case R_PPC64_ADDR16_HIGHA
:
5325 case R_PPC64_ADDR16_HIGHER
:
5326 case R_PPC64_ADDR16_HIGHERA
:
5327 case R_PPC64_ADDR16_HIGHEST
:
5328 case R_PPC64_ADDR16_HIGHESTA
:
5329 case R_PPC64_ADDR16_LO
:
5330 case R_PPC64_ADDR16_LO_DS
:
5332 case R_PPC64_D34_LO
:
5333 case R_PPC64_D34_HI30
:
5334 case R_PPC64_D34_HA30
:
5335 case R_PPC64_ADDR16_HIGHER34
:
5336 case R_PPC64_ADDR16_HIGHERA34
:
5337 case R_PPC64_ADDR16_HIGHEST34
:
5338 case R_PPC64_ADDR16_HIGHESTA34
:
5340 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5341 && rel
->r_addend
== 0)
5343 /* We may need a .plt entry if this reloc refers to a
5344 function in a shared lib. */
5345 if (!update_plt_info (abfd
, &h
->plt
.plist
, 0))
5347 h
->pointer_equality_needed
= 1;
5354 case R_PPC64_ADDR32
:
5355 case R_PPC64_UADDR16
:
5356 case R_PPC64_UADDR32
:
5357 case R_PPC64_UADDR64
:
5359 if (h
!= NULL
&& bfd_link_executable (info
))
5360 /* We may need a copy reloc. */
5363 /* Don't propagate .opd relocs. */
5364 if (NO_OPD_RELOCS
&& is_opd
)
5367 /* Set up information for symbols that might need dynamic
5368 relocations. At this point in linking we have read all
5369 the input files and resolved most symbols, but have not
5370 yet decided whether symbols are dynamic or finalized
5371 symbol flags. In some cases we might be setting dynamic
5372 reloc info for symbols that do not end up needing such.
5373 That's OK, adjust_dynamic_symbol and allocate_dynrelocs
5374 work together with this code. */
5377 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5378 || (bfd_link_pic (info
)
5380 ? !bfd_is_abs_symbol (&h
->root
)
5381 : isym
->st_shndx
!= SHN_ABS
)
5382 && must_be_dyn_reloc (info
, r_type
))
5383 || (!bfd_link_pic (info
)
5386 /* We must copy these reloc types into the output file.
5387 Create a reloc section in dynobj and make room for
5391 sreloc
= _bfd_elf_make_dynamic_reloc_section
5392 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ true);
5398 /* If this is a global symbol, we count the number of
5399 relocations we need for this symbol. */
5402 struct ppc_dyn_relocs
*p
;
5403 struct ppc_dyn_relocs
**head
;
5405 head
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
5407 if (p
== NULL
|| p
->sec
!= sec
)
5409 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5420 if (!must_be_dyn_reloc (info
, r_type
))
5422 if (maybe_relr (r_type
, rel
, sec
))
5427 /* Track dynamic relocs needed for local syms too. */
5428 struct ppc_local_dyn_relocs
*p
;
5429 struct ppc_local_dyn_relocs
**head
;
5434 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5438 vpp
= &elf_section_data (s
)->local_dynrel
;
5439 head
= (struct ppc_local_dyn_relocs
**) vpp
;
5440 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5442 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5444 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5446 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5454 p
->ifunc
= is_ifunc
;
5457 if (maybe_relr (r_type
, rel
, sec
))
5471 /* Merge backend specific data from an object file to the output
5472 object file when linking. */
5475 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5477 bfd
*obfd
= info
->output_bfd
;
5478 unsigned long iflags
, oflags
;
5480 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5483 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5486 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
5489 iflags
= elf_elfheader (ibfd
)->e_flags
;
5490 oflags
= elf_elfheader (obfd
)->e_flags
;
5492 if (iflags
& ~EF_PPC64_ABI
)
5495 /* xgettext:c-format */
5496 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5497 bfd_set_error (bfd_error_bad_value
);
5500 else if (iflags
!= oflags
&& iflags
!= 0)
5503 /* xgettext:c-format */
5504 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
5505 ibfd
, iflags
, oflags
);
5506 bfd_set_error (bfd_error_bad_value
);
5510 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
5513 /* Merge Tag_compatibility attributes and any common GNU ones. */
5514 return _bfd_elf_merge_object_attributes (ibfd
, info
);
5518 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5520 /* Print normal ELF private data. */
5521 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5523 if (elf_elfheader (abfd
)->e_flags
!= 0)
5527 fprintf (file
, _("private flags = 0x%lx:"),
5528 elf_elfheader (abfd
)->e_flags
);
5530 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5531 fprintf (file
, _(" [abiv%ld]"),
5532 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5539 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5540 of the code entry point, and its section, which must be in the same
5541 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5544 opd_entry_value (asection
*opd_sec
,
5546 asection
**code_sec
,
5550 bfd
*opd_bfd
= opd_sec
->owner
;
5551 Elf_Internal_Rela
*relocs
;
5552 Elf_Internal_Rela
*lo
, *hi
, *look
;
5555 if (!is_ppc64_elf (opd_bfd
))
5556 return (bfd_vma
) -1;
5558 if (ppc64_elf_section_data (opd_sec
)->sec_type
== sec_normal
)
5559 ppc64_elf_section_data (opd_sec
)->sec_type
= sec_opd
;
5560 else if (ppc64_elf_section_data (opd_sec
)->sec_type
!= sec_opd
)
5561 return (bfd_vma
) -1;
5563 /* No relocs implies we are linking a --just-symbols object, or looking
5564 at a final linked executable with addr2line or somesuch. */
5565 if (opd_sec
->reloc_count
== 0)
5567 bfd_byte
*contents
= ppc64_elf_section_data (opd_sec
)->u
.opd
.u
.contents
;
5569 if (contents
== NULL
)
5571 if ((opd_sec
->flags
& SEC_HAS_CONTENTS
) == 0
5572 || !bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5573 return (bfd_vma
) -1;
5574 ppc64_elf_section_data (opd_sec
)->u
.opd
.u
.contents
= contents
;
5577 /* PR 17512: file: 64b9dfbb. */
5578 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5579 return (bfd_vma
) -1;
5581 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5582 if (code_sec
!= NULL
)
5584 asection
*sec
, *likely
= NULL
;
5590 && val
< sec
->vma
+ sec
->size
)
5596 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5598 && (sec
->flags
& SEC_LOAD
) != 0
5599 && (sec
->flags
& SEC_ALLOC
) != 0)
5604 if (code_off
!= NULL
)
5605 *code_off
= val
- likely
->vma
;
5611 relocs
= ppc64_elf_section_data (opd_sec
)->u
.opd
.u
.relocs
;
5613 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, true);
5614 /* PR 17512: file: df8e1fd6. */
5616 return (bfd_vma
) -1;
5618 /* Go find the opd reloc at the sym address. */
5620 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5624 look
= lo
+ (hi
- lo
) / 2;
5625 if (look
->r_offset
< offset
)
5627 else if (look
->r_offset
> offset
)
5631 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5633 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5634 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5636 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5637 asection
*sec
= NULL
;
5639 if (symndx
>= symtab_hdr
->sh_info
5640 && elf_sym_hashes (opd_bfd
) != NULL
)
5642 struct elf_link_hash_entry
**sym_hashes
;
5643 struct elf_link_hash_entry
*rh
;
5645 sym_hashes
= elf_sym_hashes (opd_bfd
);
5646 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5649 rh
= elf_follow_link (rh
);
5650 if (rh
->root
.type
!= bfd_link_hash_defined
5651 && rh
->root
.type
!= bfd_link_hash_defweak
)
5653 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5655 val
= rh
->root
.u
.def
.value
;
5656 sec
= rh
->root
.u
.def
.section
;
5663 Elf_Internal_Sym
*sym
;
5665 if (symndx
< symtab_hdr
->sh_info
)
5667 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5670 size_t symcnt
= symtab_hdr
->sh_info
;
5671 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5676 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5682 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5688 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5691 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5692 val
= sym
->st_value
;
5695 val
+= look
->r_addend
;
5696 if (code_off
!= NULL
)
5698 if (code_sec
!= NULL
)
5700 if (in_code_sec
&& *code_sec
!= sec
)
5705 if (sec
->output_section
!= NULL
)
5706 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5715 /* If the ELF symbol SYM might be a function in SEC, return the
5716 function size and set *CODE_OFF to the function's entry point,
5717 otherwise return zero. */
5719 static bfd_size_type
5720 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5724 elf_symbol_type
* elf_sym
= (elf_symbol_type
*) sym
;
5726 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5727 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5730 size
= (sym
->flags
& BSF_SYNTHETIC
) ? 0 : elf_sym
->internal_elf_sym
.st_size
;
5732 /* In theory we should check that the symbol's type satisfies
5733 _bfd_elf_is_function_type(), but there are some function-like
5734 symbols which would fail this test. (eg _start). Instead
5735 we check for hidden, local, notype symbols with zero size.
5736 This type of symbol is generated by the annobin plugin for gcc
5737 and clang, and should not be considered to be a function symbol. */
5739 && ((sym
->flags
& (BSF_SYNTHETIC
| BSF_LOCAL
)) == BSF_LOCAL
)
5740 && ELF_ST_TYPE (elf_sym
->internal_elf_sym
.st_info
) == STT_NOTYPE
5741 && ELF_ST_VISIBILITY (elf_sym
->internal_elf_sym
.st_other
) == STV_HIDDEN
)
5744 if (strcmp (sym
->section
->name
, ".opd") == 0)
5746 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5747 bfd_vma symval
= sym
->value
;
5750 && opd
->adjust
!= NULL
5751 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5753 /* opd_entry_value will use cached relocs that have been
5754 adjusted, but with raw symbols. That means both local
5755 and global symbols need adjusting. */
5756 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5762 if (opd_entry_value (sym
->section
, symval
,
5763 &sec
, code_off
, true) == (bfd_vma
) -1)
5765 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5766 symbol. This size has nothing to do with the code size of the
5767 function, which is what we're supposed to return, but the
5768 code size isn't available without looking up the dot-sym.
5769 However, doing that would be a waste of time particularly
5770 since elf_find_function will look at the dot-sym anyway.
5771 Now, elf_find_function will keep the largest size of any
5772 function sym found at the code address of interest, so return
5773 1 here to avoid it incorrectly caching a larger function size
5774 for a small function. This does mean we return the wrong
5775 size for a new-ABI function of size 24, but all that does is
5776 disable caching for such functions. */
5782 if (sym
->section
!= sec
)
5784 *code_off
= sym
->value
;
5787 /* Do not return 0 for the function's size. */
5788 return size
? size
: 1;
5791 /* Return true if symbol is a strong function defined in an ELFv2
5792 object with st_other localentry bits of zero, ie. its local entry
5793 point coincides with its global entry point. */
5796 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5799 && h
->type
== STT_FUNC
5800 && h
->root
.type
== bfd_link_hash_defined
5801 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5802 && !ppc_elf_hash_entry (h
)->non_zero_localentry
5803 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5804 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5807 /* Return true if symbol is defined in a regular object file. */
5810 is_static_defined (struct elf_link_hash_entry
*h
)
5812 return ((h
->root
.type
== bfd_link_hash_defined
5813 || h
->root
.type
== bfd_link_hash_defweak
)
5814 && h
->root
.u
.def
.section
!= NULL
5815 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5818 /* If FDH is a function descriptor symbol, return the associated code
5819 entry symbol if it is defined. Return NULL otherwise. */
5821 static struct ppc_link_hash_entry
*
5822 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5824 if (fdh
->is_func_descriptor
)
5826 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5827 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5828 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5834 /* If FH is a function code entry symbol, return the associated
5835 function descriptor symbol if it is defined. Return NULL otherwise. */
5837 static struct ppc_link_hash_entry
*
5838 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5841 && fh
->oh
->is_func_descriptor
)
5843 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5844 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5845 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5851 /* Given H is a symbol that satisfies is_static_defined, return the
5852 value in the output file. */
5855 defined_sym_val (struct elf_link_hash_entry
*h
)
5857 return (h
->root
.u
.def
.section
->output_section
->vma
5858 + h
->root
.u
.def
.section
->output_offset
5859 + h
->root
.u
.def
.value
);
5862 /* Return true if H matches __tls_get_addr or one of its variants. */
5865 is_tls_get_addr (struct elf_link_hash_entry
*h
,
5866 struct ppc_link_hash_table
*htab
)
5868 return (h
== elf_hash_entry (htab
->tls_get_addr_fd
)
5869 || h
== elf_hash_entry (htab
->tga_desc_fd
)
5870 || h
== elf_hash_entry (htab
->tls_get_addr
)
5871 || h
== elf_hash_entry (htab
->tga_desc
));
5874 static bool func_desc_adjust (struct elf_link_hash_entry
*, void *);
5876 /* Garbage collect sections, after first dealing with dot-symbols. */
5879 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5881 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5883 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5885 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5886 htab
->need_func_desc_adj
= 0;
5888 return bfd_elf_gc_sections (abfd
, info
);
5891 /* Mark all our entry sym sections, both opd and code section. */
5894 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5896 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5897 struct bfd_sym_chain
*sym
;
5902 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5904 struct ppc_link_hash_entry
*eh
, *fh
;
5907 eh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
->name
,
5908 false, false, true));
5911 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5912 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5915 fh
= defined_code_entry (eh
);
5918 sec
= fh
->elf
.root
.u
.def
.section
;
5919 sec
->flags
|= SEC_KEEP
;
5921 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5922 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5923 eh
->elf
.root
.u
.def
.value
,
5924 &sec
, NULL
, false) != (bfd_vma
) -1)
5925 sec
->flags
|= SEC_KEEP
;
5927 sec
= eh
->elf
.root
.u
.def
.section
;
5928 sec
->flags
|= SEC_KEEP
;
5932 /* Mark sections containing dynamically referenced symbols. When
5933 building shared libraries, we must assume that any visible symbol is
5937 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5939 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5940 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
5941 struct ppc_link_hash_entry
*fdh
;
5942 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5944 /* Dynamic linking info is on the func descriptor sym. */
5945 fdh
= defined_func_desc (eh
);
5949 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5950 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5951 && (!eh
->elf
.start_stop
5952 || eh
->elf
.root
.ldscript_def
5953 || !info
->start_stop_gc
)
5954 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5955 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5956 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5957 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5958 && (!bfd_link_executable (info
)
5959 || info
->gc_keep_exported
5960 || info
->export_dynamic
5963 && (*d
->match
) (&d
->head
, NULL
,
5964 eh
->elf
.root
.root
.string
)))
5965 && (eh
->elf
.versioned
>= versioned
5966 || !bfd_hide_sym_by_version (info
->version_info
,
5967 eh
->elf
.root
.root
.string
)))))
5970 struct ppc_link_hash_entry
*fh
;
5972 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5974 /* Function descriptor syms cause the associated
5975 function code sym section to be marked. */
5976 fh
= defined_code_entry (eh
);
5979 code_sec
= fh
->elf
.root
.u
.def
.section
;
5980 code_sec
->flags
|= SEC_KEEP
;
5982 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5983 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5984 eh
->elf
.root
.u
.def
.value
,
5985 &code_sec
, NULL
, false) != (bfd_vma
) -1)
5986 code_sec
->flags
|= SEC_KEEP
;
5992 /* Return the section that should be marked against GC for a given
5996 ppc64_elf_gc_mark_hook (asection
*sec
,
5997 struct bfd_link_info
*info
,
5998 Elf_Internal_Rela
*rel
,
5999 struct elf_link_hash_entry
*h
,
6000 Elf_Internal_Sym
*sym
)
6004 /* Syms return NULL if we're marking .opd, so we avoid marking all
6005 function sections, as all functions are referenced in .opd. */
6007 if (get_opd_info (sec
) != NULL
)
6012 enum elf_ppc64_reloc_type r_type
;
6013 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
6015 r_type
= ELF64_R_TYPE (rel
->r_info
);
6018 case R_PPC64_GNU_VTINHERIT
:
6019 case R_PPC64_GNU_VTENTRY
:
6023 switch (h
->root
.type
)
6025 case bfd_link_hash_defined
:
6026 case bfd_link_hash_defweak
:
6027 eh
= ppc_elf_hash_entry (h
);
6028 fdh
= defined_func_desc (eh
);
6031 /* -mcall-aixdesc code references the dot-symbol on
6032 a call reloc. Mark the function descriptor too
6033 against garbage collection. */
6035 if (fdh
->elf
.is_weakalias
)
6036 weakdef (&fdh
->elf
)->mark
= 1;
6040 /* Function descriptor syms cause the associated
6041 function code sym section to be marked. */
6042 fh
= defined_code_entry (eh
);
6045 /* They also mark their opd section. */
6046 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6048 rsec
= fh
->elf
.root
.u
.def
.section
;
6050 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6051 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6052 eh
->elf
.root
.u
.def
.value
,
6053 &rsec
, NULL
, false) != (bfd_vma
) -1)
6054 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6056 rsec
= h
->root
.u
.def
.section
;
6059 case bfd_link_hash_common
:
6060 rsec
= h
->root
.u
.c
.p
->section
;
6064 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6070 struct _opd_sec_data
*opd
;
6072 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6073 opd
= get_opd_info (rsec
);
6074 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6078 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6085 /* The maximum size of .sfpr. */
6086 #define SFPR_MAX (218*4)
6088 struct sfpr_def_parms
6090 const char name
[12];
6091 unsigned char lo
, hi
;
6092 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
6093 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
6096 /* Auto-generate _save*, _rest* functions in .sfpr.
6097 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6101 sfpr_define (struct bfd_link_info
*info
,
6102 const struct sfpr_def_parms
*parm
,
6105 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6107 size_t len
= strlen (parm
->name
);
6108 bool writing
= false;
6114 memcpy (sym
, parm
->name
, len
);
6117 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6119 struct ppc_link_hash_entry
*h
;
6121 sym
[len
+ 0] = i
/ 10 + '0';
6122 sym
[len
+ 1] = i
% 10 + '0';
6123 h
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
,
6124 writing
, true, true));
6125 if (stub_sec
!= NULL
)
6128 && h
->elf
.root
.type
== bfd_link_hash_defined
6129 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6131 struct elf_link_hash_entry
*s
;
6133 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6134 s
= elf_link_hash_lookup (&htab
->elf
, buf
, true, true, false);
6137 if (s
->root
.type
== bfd_link_hash_new
)
6139 s
->root
.type
= bfd_link_hash_defined
;
6140 s
->root
.u
.def
.section
= stub_sec
;
6141 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6142 + h
->elf
.root
.u
.def
.value
);
6145 s
->ref_regular_nonweak
= 1;
6146 s
->forced_local
= 1;
6148 s
->root
.linker_def
= 1;
6156 if (!h
->elf
.def_regular
)
6158 h
->elf
.root
.type
= bfd_link_hash_defined
;
6159 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6160 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6161 h
->elf
.type
= STT_FUNC
;
6162 h
->elf
.def_regular
= 1;
6164 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, true);
6166 if (htab
->sfpr
->contents
== NULL
)
6168 htab
->sfpr
->contents
6169 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6170 if (htab
->sfpr
->contents
== NULL
)
6177 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6179 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6181 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6182 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6190 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6192 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6197 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6199 p
= savegpr0 (abfd
, p
, r
);
6200 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6202 bfd_put_32 (abfd
, BLR
, p
);
6207 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6209 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6214 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6216 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6218 p
= restgpr0 (abfd
, p
, r
);
6219 bfd_put_32 (abfd
, MTLR_R0
, p
);
6223 p
= restgpr0 (abfd
, p
, 30);
6224 p
= restgpr0 (abfd
, p
, 31);
6226 bfd_put_32 (abfd
, BLR
, p
);
6231 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6233 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6238 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6240 p
= savegpr1 (abfd
, p
, r
);
6241 bfd_put_32 (abfd
, BLR
, p
);
6246 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6248 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6253 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6255 p
= restgpr1 (abfd
, p
, r
);
6256 bfd_put_32 (abfd
, BLR
, p
);
6261 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6263 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6268 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6270 p
= savefpr (abfd
, p
, r
);
6271 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6273 bfd_put_32 (abfd
, BLR
, p
);
6278 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6280 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6285 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6287 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6289 p
= restfpr (abfd
, p
, r
);
6290 bfd_put_32 (abfd
, MTLR_R0
, p
);
6294 p
= restfpr (abfd
, p
, 30);
6295 p
= restfpr (abfd
, p
, 31);
6297 bfd_put_32 (abfd
, BLR
, p
);
6302 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6304 p
= savefpr (abfd
, p
, r
);
6305 bfd_put_32 (abfd
, BLR
, p
);
6310 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6312 p
= restfpr (abfd
, p
, r
);
6313 bfd_put_32 (abfd
, BLR
, p
);
6318 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6320 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6322 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6327 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6329 p
= savevr (abfd
, p
, r
);
6330 bfd_put_32 (abfd
, BLR
, p
);
6335 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6337 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6339 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6344 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6346 p
= restvr (abfd
, p
, r
);
6347 bfd_put_32 (abfd
, BLR
, p
);
6351 #define STDU_R1_0R1 0xf8210001
6352 #define ADDI_R1_R1 0x38210000
6354 /* Emit prologue of wrapper preserving regs around a call to
6355 __tls_get_addr_opt. */
6358 tls_get_addr_prologue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6362 bfd_put_32 (obfd
, MFLR_R0
, p
);
6364 bfd_put_32 (obfd
, STD_R0_0R1
+ 16, p
);
6369 for (i
= 4; i
< 12; i
++)
6372 STD_R0_0R1
| i
<< 21 | (-(13 - i
) * 8 & 0xffff), p
);
6375 bfd_put_32 (obfd
, STDU_R1_0R1
| (-128 & 0xffff), p
);
6380 for (i
= 4; i
< 12; i
++)
6383 STD_R0_0R1
| i
<< 21 | (-(12 - i
) * 8 & 0xffff), p
);
6386 bfd_put_32 (obfd
, STDU_R1_0R1
| (-96 & 0xffff), p
);
6392 /* Emit epilogue of wrapper preserving regs around a call to
6393 __tls_get_addr_opt. */
6396 tls_get_addr_epilogue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6402 for (i
= 4; i
< 12; i
++)
6404 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (128 - (13 - i
) * 8), p
);
6407 bfd_put_32 (obfd
, ADDI_R1_R1
| 128, p
);
6412 for (i
= 4; i
< 12; i
++)
6414 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (96 - (12 - i
) * 8), p
);
6417 bfd_put_32 (obfd
, ADDI_R1_R1
| 96, p
);
6420 bfd_put_32 (obfd
, LD_R0_0R1
| 16, p
);
6422 bfd_put_32 (obfd
, MTLR_R0
, p
);
6424 bfd_put_32 (obfd
, BLR
, p
);
6429 /* Called via elf_link_hash_traverse to transfer dynamic linking
6430 information on function code symbol entries to their corresponding
6431 function descriptor symbol entries. Must not be called twice for
6432 any given code symbol. */
6435 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6437 struct bfd_link_info
*info
;
6438 struct ppc_link_hash_table
*htab
;
6439 struct ppc_link_hash_entry
*fh
;
6440 struct ppc_link_hash_entry
*fdh
;
6443 fh
= ppc_elf_hash_entry (h
);
6444 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6450 if (fh
->elf
.root
.root
.string
[0] != '.'
6451 || fh
->elf
.root
.root
.string
[1] == '\0')
6455 htab
= ppc_hash_table (info
);
6459 /* Find the corresponding function descriptor symbol. */
6460 fdh
= lookup_fdh (fh
, htab
);
6462 /* Resolve undefined references to dot-symbols as the value
6463 in the function descriptor, if we have one in a regular object.
6464 This is to satisfy cases like ".quad .foo". Calls to functions
6465 in dynamic objects are handled elsewhere. */
6466 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6467 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6468 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6469 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6470 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6471 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6472 fdh
->elf
.root
.u
.def
.value
,
6473 &fh
->elf
.root
.u
.def
.section
,
6474 &fh
->elf
.root
.u
.def
.value
, false) != (bfd_vma
) -1)
6476 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6477 fh
->elf
.forced_local
= 1;
6478 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6479 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6482 if (!fh
->elf
.dynamic
)
6484 struct plt_entry
*ent
;
6486 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6487 if (ent
->plt
.refcount
> 0)
6491 if (fdh
!= NULL
&& fdh
->fake
)
6492 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6497 /* Create a descriptor as undefined if necessary. */
6499 && !bfd_link_executable (info
)
6500 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6501 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6503 fdh
= make_fdh (info
, fh
);
6508 /* We can't support overriding of symbols on a fake descriptor. */
6511 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6512 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6513 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6515 /* Transfer dynamic linking information to the function descriptor. */
6518 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6519 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6520 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6521 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6522 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6523 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6524 || fh
->elf
.type
== STT_FUNC
6525 || fh
->elf
.type
== STT_GNU_IFUNC
);
6526 move_plt_plist (fh
, fdh
);
6528 if (!fdh
->elf
.forced_local
6529 && fh
->elf
.dynindx
!= -1)
6530 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6534 /* Now that the info is on the function descriptor, clear the
6535 function code sym info. Any function code syms for which we
6536 don't have a definition in a regular file, we force local.
6537 This prevents a shared library from exporting syms that have
6538 been imported from another library. Function code syms that
6539 are really in the library we must leave global to prevent the
6540 linker dragging in a definition from a static library. */
6541 force_local
= (!fh
->elf
.def_regular
6543 || !fdh
->elf
.def_regular
6544 || fdh
->elf
.forced_local
);
6545 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6550 static const struct sfpr_def_parms save_res_funcs
[] =
6552 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6553 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6554 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6555 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6556 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6557 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6558 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6559 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6560 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6561 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6562 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6563 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6566 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6567 this hook to a) run the edit functions in this file, b) provide
6568 some gcc support functions, and c) transfer dynamic linking
6569 information gathered so far on function code symbol entries, to
6570 their corresponding function descriptor symbol entries. */
6573 ppc64_elf_edit (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6575 struct ppc_link_hash_table
*htab
;
6577 htab
= ppc_hash_table (info
);
6581 /* Call back into the linker, which then runs the edit functions. */
6582 htab
->params
->edit ();
6584 /* Provide any missing _save* and _rest* functions. */
6585 if (htab
->sfpr
!= NULL
)
6589 htab
->sfpr
->size
= 0;
6590 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
6591 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
6593 if (htab
->sfpr
->size
== 0)
6594 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6597 if (bfd_link_relocatable (info
))
6600 if (htab
->elf
.hgot
!= NULL
)
6602 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, true);
6603 /* Make .TOC. defined so as to prevent it being made dynamic.
6604 The wrong value here is fixed later in ppc64_elf_set_toc. */
6605 if (!htab
->elf
.hgot
->def_regular
6606 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
6608 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
6609 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
6610 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6611 htab
->elf
.hgot
->def_regular
= 1;
6612 htab
->elf
.hgot
->root
.linker_def
= 1;
6614 htab
->elf
.hgot
->type
= STT_OBJECT
;
6615 htab
->elf
.hgot
->other
6616 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
6622 /* Return true if we have dynamic relocs against H or any of its weak
6623 aliases, that apply to read-only sections. Cannot be used after
6624 size_dynamic_sections. */
6627 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6629 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
6632 if (_bfd_elf_readonly_dynrelocs (&eh
->elf
))
6634 eh
= ppc_elf_hash_entry (eh
->elf
.u
.alias
);
6636 while (eh
!= NULL
&& &eh
->elf
!= h
);
6641 /* Return whether EH has pc-relative dynamic relocs. */
6644 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
6646 struct ppc_dyn_relocs
*p
;
6648 for (p
= (struct ppc_dyn_relocs
*) eh
->elf
.dyn_relocs
; p
!= NULL
; p
= p
->next
)
6649 if (p
->pc_count
!= 0)
6654 /* Return true if a global entry stub will be created for H. Valid
6655 for ELFv2 before plt entries have been allocated. */
6658 global_entry_stub (struct elf_link_hash_entry
*h
)
6660 struct plt_entry
*pent
;
6662 if (!h
->pointer_equality_needed
6666 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
6667 if (pent
->plt
.refcount
> 0
6668 && pent
->addend
== 0)
6674 /* Adjust a symbol defined by a dynamic object and referenced by a
6675 regular object. The current definition is in some section of the
6676 dynamic object, but we're not including those sections. We have to
6677 change the definition to something the rest of the link can
6681 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6682 struct elf_link_hash_entry
*h
)
6684 struct ppc_link_hash_table
*htab
;
6687 htab
= ppc_hash_table (info
);
6691 /* Deal with function syms. */
6692 if (h
->type
== STT_FUNC
6693 || h
->type
== STT_GNU_IFUNC
6696 bool local
= (ppc_elf_hash_entry (h
)->save_res
6697 || SYMBOL_CALLS_LOCAL (info
, h
)
6698 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6699 /* Discard dyn_relocs when non-pic if we've decided that a
6700 function symbol is local and not an ifunc. We keep dynamic
6701 relocs for ifuncs when local rather than always emitting a
6702 plt call stub for them and defining the symbol on the call
6703 stub. We can't do that for ELFv1 anyway (a function symbol
6704 is defined on a descriptor, not code) and it can be faster at
6705 run-time due to not needing to bounce through a stub. The
6706 dyn_relocs for ifuncs will be applied even in a static
6708 if (!bfd_link_pic (info
)
6709 && h
->type
!= STT_GNU_IFUNC
6711 h
->dyn_relocs
= NULL
;
6713 /* Clear procedure linkage table information for any symbol that
6714 won't need a .plt entry. */
6715 struct plt_entry
*ent
;
6716 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6717 if (ent
->plt
.refcount
> 0)
6720 || (h
->type
!= STT_GNU_IFUNC
6722 && (htab
->can_convert_all_inline_plt
6723 || (ppc_elf_hash_entry (h
)->tls_mask
6724 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6726 h
->plt
.plist
= NULL
;
6728 h
->pointer_equality_needed
= 0;
6730 else if (abiversion (info
->output_bfd
) >= 2)
6732 /* Taking a function's address in a read/write section
6733 doesn't require us to define the function symbol in the
6734 executable on a global entry stub. A dynamic reloc can
6735 be used instead. The reason we prefer a few more dynamic
6736 relocs is that calling via a global entry stub costs a
6737 few more instructions, and pointer_equality_needed causes
6738 extra work in ld.so when resolving these symbols. */
6739 if (global_entry_stub (h
))
6741 if (!_bfd_elf_readonly_dynrelocs (h
))
6743 h
->pointer_equality_needed
= 0;
6744 /* If we haven't seen a branch reloc and the symbol
6745 isn't an ifunc then we don't need a plt entry. */
6747 h
->plt
.plist
= NULL
;
6749 else if (!bfd_link_pic (info
))
6750 /* We are going to be defining the function symbol on the
6751 plt stub, so no dyn_relocs needed when non-pic. */
6752 h
->dyn_relocs
= NULL
;
6755 /* ELFv2 function symbols can't have copy relocs. */
6758 else if (!h
->needs_plt
6759 && !_bfd_elf_readonly_dynrelocs (h
))
6761 /* If we haven't seen a branch reloc and the symbol isn't an
6762 ifunc then we don't need a plt entry. */
6763 h
->plt
.plist
= NULL
;
6764 h
->pointer_equality_needed
= 0;
6769 h
->plt
.plist
= NULL
;
6771 /* If this is a weak symbol, and there is a real definition, the
6772 processor independent code will have arranged for us to see the
6773 real definition first, and we can just use the same value. */
6774 if (h
->is_weakalias
)
6776 struct elf_link_hash_entry
*def
= weakdef (h
);
6777 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6778 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6779 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6780 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6781 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6782 h
->dyn_relocs
= NULL
;
6786 /* If we are creating a shared library, we must presume that the
6787 only references to the symbol are via the global offset table.
6788 For such cases we need not do anything here; the relocations will
6789 be handled correctly by relocate_section. */
6790 if (!bfd_link_executable (info
))
6793 /* If there are no references to this symbol that do not use the
6794 GOT, we don't need to generate a copy reloc. */
6795 if (!h
->non_got_ref
)
6798 /* Don't generate a copy reloc for symbols defined in the executable. */
6799 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6801 /* If -z nocopyreloc was given, don't generate them either. */
6802 || info
->nocopyreloc
6804 /* If we don't find any dynamic relocs in read-only sections, then
6805 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6806 || (ELIMINATE_COPY_RELOCS
6808 && !alias_readonly_dynrelocs (h
))
6810 /* Protected variables do not work with .dynbss. The copy in
6811 .dynbss won't be used by the shared library with the protected
6812 definition for the variable. Text relocations are preferable
6813 to an incorrect program. */
6814 || h
->protected_def
)
6817 if (h
->type
== STT_FUNC
6818 || h
->type
== STT_GNU_IFUNC
)
6820 /* .dynbss copies of function symbols only work if we have
6821 ELFv1 dot-symbols. ELFv1 compilers since 2004 default to not
6822 use dot-symbols and set the function symbol size to the text
6823 size of the function rather than the size of the descriptor.
6824 That's wrong for copying a descriptor. */
6825 if (ppc_elf_hash_entry (h
)->oh
== NULL
6826 || !(h
->size
== 24 || h
->size
== 16))
6829 /* We should never get here, but unfortunately there are old
6830 versions of gcc (circa gcc-3.2) that improperly for the
6831 ELFv1 ABI put initialized function pointers, vtable refs and
6832 suchlike in read-only sections. Allow them to proceed, but
6833 warn that this might break at runtime. */
6834 info
->callbacks
->einfo
6835 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6836 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6837 h
->root
.root
.string
);
6840 /* This is a reference to a symbol defined by a dynamic object which
6841 is not a function. */
6843 /* We must allocate the symbol in our .dynbss section, which will
6844 become part of the .bss section of the executable. There will be
6845 an entry for this symbol in the .dynsym section. The dynamic
6846 object will contain position independent code, so all references
6847 from the dynamic object to this symbol will go through the global
6848 offset table. The dynamic linker will use the .dynsym entry to
6849 determine the address it must put in the global offset table, so
6850 both the dynamic object and the regular object will refer to the
6851 same memory location for the variable. */
6852 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6854 s
= htab
->elf
.sdynrelro
;
6855 srel
= htab
->elf
.sreldynrelro
;
6859 s
= htab
->elf
.sdynbss
;
6860 srel
= htab
->elf
.srelbss
;
6862 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6864 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6865 linker to copy the initial value out of the dynamic object
6866 and into the runtime process image. */
6867 srel
->size
+= sizeof (Elf64_External_Rela
);
6871 /* We no longer want dyn_relocs. */
6872 h
->dyn_relocs
= NULL
;
6873 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6876 /* If given a function descriptor symbol, hide both the function code
6877 sym and the descriptor. */
6879 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6880 struct elf_link_hash_entry
*h
,
6883 struct ppc_link_hash_entry
*eh
;
6884 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6886 if (ppc_hash_table (info
) == NULL
)
6889 eh
= ppc_elf_hash_entry (h
);
6890 if (eh
->is_func_descriptor
)
6892 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6897 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6900 /* We aren't supposed to use alloca in BFD because on
6901 systems which do not have alloca the version in libiberty
6902 calls xmalloc, which might cause the program to crash
6903 when it runs out of memory. This function doesn't have a
6904 return status, so there's no way to gracefully return an
6905 error. So cheat. We know that string[-1] can be safely
6906 accessed; It's either a string in an ELF string table,
6907 or allocated in an objalloc structure. */
6909 p
= eh
->elf
.root
.root
.string
- 1;
6912 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6916 /* Unfortunately, if it so happens that the string we were
6917 looking for was allocated immediately before this string,
6918 then we overwrote the string terminator. That's the only
6919 reason the lookup should fail. */
6922 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6923 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6925 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6926 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6936 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6941 get_sym_h (struct elf_link_hash_entry
**hp
,
6942 Elf_Internal_Sym
**symp
,
6944 unsigned char **tls_maskp
,
6945 Elf_Internal_Sym
**locsymsp
,
6946 unsigned long r_symndx
,
6949 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6951 if (r_symndx
>= symtab_hdr
->sh_info
)
6953 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6954 struct elf_link_hash_entry
*h
;
6956 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6957 h
= elf_follow_link (h
);
6965 if (symsecp
!= NULL
)
6967 asection
*symsec
= NULL
;
6968 if (h
->root
.type
== bfd_link_hash_defined
6969 || h
->root
.type
== bfd_link_hash_defweak
)
6970 symsec
= h
->root
.u
.def
.section
;
6974 if (tls_maskp
!= NULL
)
6975 *tls_maskp
= &ppc_elf_hash_entry (h
)->tls_mask
;
6979 Elf_Internal_Sym
*sym
;
6980 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6982 if (locsyms
== NULL
)
6984 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6985 if (locsyms
== NULL
)
6986 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6987 symtab_hdr
->sh_info
,
6988 0, NULL
, NULL
, NULL
);
6989 if (locsyms
== NULL
)
6991 *locsymsp
= locsyms
;
6993 sym
= locsyms
+ r_symndx
;
7001 if (symsecp
!= NULL
)
7002 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
7004 if (tls_maskp
!= NULL
)
7006 struct got_entry
**lgot_ents
;
7007 unsigned char *tls_mask
;
7010 lgot_ents
= elf_local_got_ents (ibfd
);
7011 if (lgot_ents
!= NULL
)
7013 struct plt_entry
**local_plt
= (struct plt_entry
**)
7014 (lgot_ents
+ symtab_hdr
->sh_info
);
7015 unsigned char *lgot_masks
= (unsigned char *)
7016 (local_plt
+ symtab_hdr
->sh_info
);
7017 tls_mask
= &lgot_masks
[r_symndx
];
7019 *tls_maskp
= tls_mask
;
7025 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7026 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7027 type suitable for optimization, and 1 otherwise. */
7030 get_tls_mask (unsigned char **tls_maskp
,
7031 unsigned long *toc_symndx
,
7032 bfd_vma
*toc_addend
,
7033 Elf_Internal_Sym
**locsymsp
,
7034 const Elf_Internal_Rela
*rel
,
7037 unsigned long r_symndx
;
7039 struct elf_link_hash_entry
*h
;
7040 Elf_Internal_Sym
*sym
;
7044 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7045 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7048 if ((*tls_maskp
!= NULL
7049 && (**tls_maskp
& TLS_TLS
) != 0
7050 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
7052 || ppc64_elf_section_data (sec
) == NULL
7053 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7056 /* Look inside a TOC section too. */
7059 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7060 off
= h
->root
.u
.def
.value
;
7063 off
= sym
->st_value
;
7064 off
+= rel
->r_addend
;
7065 BFD_ASSERT (off
% 8 == 0);
7066 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7067 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7068 if (toc_symndx
!= NULL
)
7069 *toc_symndx
= r_symndx
;
7070 if (toc_addend
!= NULL
)
7071 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7072 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7074 if ((h
== NULL
|| is_static_defined (h
))
7075 && (next_r
== -1 || next_r
== -2))
7080 /* Find (or create) an entry in the tocsave hash table. */
7082 static struct tocsave_entry
*
7083 tocsave_find (struct ppc_link_hash_table
*htab
,
7084 enum insert_option insert
,
7085 Elf_Internal_Sym
**local_syms
,
7086 const Elf_Internal_Rela
*irela
,
7089 unsigned long r_indx
;
7090 struct elf_link_hash_entry
*h
;
7091 Elf_Internal_Sym
*sym
;
7092 struct tocsave_entry ent
, *p
;
7094 struct tocsave_entry
**slot
;
7096 r_indx
= ELF64_R_SYM (irela
->r_info
);
7097 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7099 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7102 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7107 ent
.offset
= h
->root
.u
.def
.value
;
7109 ent
.offset
= sym
->st_value
;
7110 ent
.offset
+= irela
->r_addend
;
7112 hash
= tocsave_htab_hash (&ent
);
7113 slot
= ((struct tocsave_entry
**)
7114 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7120 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7129 /* Adjust all global syms defined in opd sections. In gcc generated
7130 code for the old ABI, these will already have been done. */
7133 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7135 struct ppc_link_hash_entry
*eh
;
7137 struct _opd_sec_data
*opd
;
7139 if (h
->root
.type
== bfd_link_hash_indirect
)
7142 if (h
->root
.type
!= bfd_link_hash_defined
7143 && h
->root
.type
!= bfd_link_hash_defweak
)
7146 eh
= ppc_elf_hash_entry (h
);
7147 if (eh
->adjust_done
)
7150 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7151 opd
= get_opd_info (sym_sec
);
7152 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7154 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7157 /* This entry has been deleted. */
7158 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7161 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7162 if (discarded_section (dsec
))
7164 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7168 eh
->elf
.root
.u
.def
.value
= 0;
7169 eh
->elf
.root
.u
.def
.section
= dsec
;
7172 eh
->elf
.root
.u
.def
.value
+= adjust
;
7173 eh
->adjust_done
= 1;
7178 /* Handles decrementing dynamic reloc counts for the reloc specified by
7179 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7180 have already been determined. */
7183 dec_dynrel_count (const Elf_Internal_Rela
*rel
,
7185 struct bfd_link_info
*info
,
7186 Elf_Internal_Sym
**local_syms
,
7187 struct elf_link_hash_entry
*h
,
7188 Elf_Internal_Sym
*sym
)
7190 enum elf_ppc64_reloc_type r_type
;
7191 asection
*sym_sec
= NULL
;
7193 /* Can this reloc be dynamic? This switch, and later tests here
7194 should be kept in sync with the code in check_relocs. */
7195 r_type
= ELF64_R_TYPE (rel
->r_info
);
7202 case R_PPC64_TOC16_DS
:
7203 case R_PPC64_TOC16_LO
:
7204 case R_PPC64_TOC16_HI
:
7205 case R_PPC64_TOC16_HA
:
7206 case R_PPC64_TOC16_LO_DS
:
7211 case R_PPC64_TPREL16
:
7212 case R_PPC64_TPREL16_LO
:
7213 case R_PPC64_TPREL16_HI
:
7214 case R_PPC64_TPREL16_HA
:
7215 case R_PPC64_TPREL16_DS
:
7216 case R_PPC64_TPREL16_LO_DS
:
7217 case R_PPC64_TPREL16_HIGH
:
7218 case R_PPC64_TPREL16_HIGHA
:
7219 case R_PPC64_TPREL16_HIGHER
:
7220 case R_PPC64_TPREL16_HIGHERA
:
7221 case R_PPC64_TPREL16_HIGHEST
:
7222 case R_PPC64_TPREL16_HIGHESTA
:
7223 case R_PPC64_TPREL64
:
7224 case R_PPC64_TPREL34
:
7225 case R_PPC64_DTPMOD64
:
7226 case R_PPC64_DTPREL64
:
7227 case R_PPC64_ADDR64
:
7231 case R_PPC64_ADDR14
:
7232 case R_PPC64_ADDR14_BRNTAKEN
:
7233 case R_PPC64_ADDR14_BRTAKEN
:
7234 case R_PPC64_ADDR16
:
7235 case R_PPC64_ADDR16_DS
:
7236 case R_PPC64_ADDR16_HA
:
7237 case R_PPC64_ADDR16_HI
:
7238 case R_PPC64_ADDR16_HIGH
:
7239 case R_PPC64_ADDR16_HIGHA
:
7240 case R_PPC64_ADDR16_HIGHER
:
7241 case R_PPC64_ADDR16_HIGHERA
:
7242 case R_PPC64_ADDR16_HIGHEST
:
7243 case R_PPC64_ADDR16_HIGHESTA
:
7244 case R_PPC64_ADDR16_LO
:
7245 case R_PPC64_ADDR16_LO_DS
:
7246 case R_PPC64_ADDR24
:
7247 case R_PPC64_ADDR32
:
7248 case R_PPC64_UADDR16
:
7249 case R_PPC64_UADDR32
:
7250 case R_PPC64_UADDR64
:
7253 case R_PPC64_D34_LO
:
7254 case R_PPC64_D34_HI30
:
7255 case R_PPC64_D34_HA30
:
7256 case R_PPC64_ADDR16_HIGHER34
:
7257 case R_PPC64_ADDR16_HIGHERA34
:
7258 case R_PPC64_ADDR16_HIGHEST34
:
7259 case R_PPC64_ADDR16_HIGHESTA34
:
7264 if (local_syms
!= NULL
)
7266 unsigned long r_symndx
;
7267 bfd
*ibfd
= sec
->owner
;
7269 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7270 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7275 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
7276 || (bfd_link_pic (info
)
7278 ? !bfd_is_abs_symbol (&h
->root
)
7279 : sym_sec
!= bfd_abs_section_ptr
)
7280 && must_be_dyn_reloc (info
, r_type
))
7281 || (!bfd_link_pic (info
)
7283 ? h
->type
== STT_GNU_IFUNC
7284 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
7291 struct ppc_dyn_relocs
*p
;
7292 struct ppc_dyn_relocs
**pp
;
7293 pp
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
7295 /* elf_gc_sweep may have already removed all dyn relocs associated
7296 with local syms for a given section. Also, symbol flags are
7297 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7298 report a dynreloc miscount. */
7299 if (*pp
== NULL
&& info
->gc_sections
)
7302 while ((p
= *pp
) != NULL
)
7306 if (!must_be_dyn_reloc (info
, r_type
))
7308 if (maybe_relr (r_type
, rel
, sec
))
7320 struct ppc_local_dyn_relocs
*p
;
7321 struct ppc_local_dyn_relocs
**pp
;
7325 if (local_syms
== NULL
)
7326 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7327 if (sym_sec
== NULL
)
7330 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7331 pp
= (struct ppc_local_dyn_relocs
**) vpp
;
7333 if (*pp
== NULL
&& info
->gc_sections
)
7336 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7337 while ((p
= *pp
) != NULL
)
7339 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7341 if (maybe_relr (r_type
, rel
, sec
))
7352 /* xgettext:c-format */
7353 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7355 bfd_set_error (bfd_error_bad_value
);
7359 /* Remove unused Official Procedure Descriptor entries. Currently we
7360 only remove those associated with functions in discarded link-once
7361 sections, or weakly defined functions that have been overridden. It
7362 would be possible to remove many more entries for statically linked
7366 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7369 bool some_edited
= false;
7370 asection
*need_pad
= NULL
;
7371 struct ppc_link_hash_table
*htab
;
7373 htab
= ppc_hash_table (info
);
7377 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7380 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7381 Elf_Internal_Shdr
*symtab_hdr
;
7382 Elf_Internal_Sym
*local_syms
;
7383 struct _opd_sec_data
*opd
;
7384 bool need_edit
, add_aux_fields
, broken
;
7385 bfd_size_type cnt_16b
= 0;
7387 if (!is_ppc64_elf (ibfd
))
7390 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7393 || (sec
->flags
& SEC_HAS_CONTENTS
) == 0)
7396 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7399 if (sec
->output_section
== bfd_abs_section_ptr
)
7402 /* Look through the section relocs. */
7403 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7407 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7409 /* Read the relocations. */
7410 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7412 if (relstart
== NULL
)
7415 /* First run through the relocs to check they are sane, and to
7416 determine whether we need to edit this opd section. */
7420 relend
= relstart
+ sec
->reloc_count
;
7421 for (rel
= relstart
; rel
< relend
; )
7423 enum elf_ppc64_reloc_type r_type
;
7424 unsigned long r_symndx
;
7426 struct elf_link_hash_entry
*h
;
7427 Elf_Internal_Sym
*sym
;
7430 /* .opd contains an array of 16 or 24 byte entries. We're
7431 only interested in the reloc pointing to a function entry
7433 offset
= rel
->r_offset
;
7434 if (rel
+ 1 == relend
7435 || rel
[1].r_offset
!= offset
+ 8)
7437 /* If someone messes with .opd alignment then after a
7438 "ld -r" we might have padding in the middle of .opd.
7439 Also, there's nothing to prevent someone putting
7440 something silly in .opd with the assembler. No .opd
7441 optimization for them! */
7444 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7449 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7450 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7453 /* xgettext:c-format */
7454 (_("%pB: unexpected reloc type %u in .opd section"),
7460 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7461 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7465 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7467 const char *sym_name
;
7469 sym_name
= h
->root
.root
.string
;
7471 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7475 /* xgettext:c-format */
7476 (_("%pB: undefined sym `%s' in .opd section"),
7482 /* opd entries are always for functions defined in the
7483 current input bfd. If the symbol isn't defined in the
7484 input bfd, then we won't be using the function in this
7485 bfd; It must be defined in a linkonce section in another
7486 bfd, or is weak. It's also possible that we are
7487 discarding the function due to a linker script /DISCARD/,
7488 which we test for via the output_section. */
7489 if (sym_sec
->owner
!= ibfd
7490 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7494 if (rel
+ 1 == relend
7495 || (rel
+ 2 < relend
7496 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7501 if (sec
->size
== offset
+ 24)
7506 if (sec
->size
== offset
+ 16)
7513 else if (rel
+ 1 < relend
7514 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7515 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7517 if (rel
[0].r_offset
== offset
+ 16)
7519 else if (rel
[0].r_offset
!= offset
+ 24)
7526 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7528 if (!broken
&& (need_edit
|| add_aux_fields
))
7530 Elf_Internal_Rela
*write_rel
;
7531 Elf_Internal_Shdr
*rel_hdr
;
7532 bfd_byte
*rptr
, *wptr
;
7533 bfd_byte
*new_contents
;
7536 new_contents
= NULL
;
7537 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7538 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7539 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7540 if (opd
->adjust
== NULL
)
7543 /* This seems a waste of time as input .opd sections are all
7544 zeros as generated by gcc, but I suppose there's no reason
7545 this will always be so. We might start putting something in
7546 the third word of .opd entries. */
7547 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7550 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7554 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7556 if (elf_section_data (sec
)->relocs
!= relstart
)
7560 sec
->contents
= loc
;
7561 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7564 elf_section_data (sec
)->relocs
= relstart
;
7566 new_contents
= sec
->contents
;
7569 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7570 if (new_contents
== NULL
)
7574 wptr
= new_contents
;
7575 rptr
= sec
->contents
;
7576 write_rel
= relstart
;
7577 for (rel
= relstart
; rel
< relend
; )
7579 unsigned long r_symndx
;
7581 struct elf_link_hash_entry
*h
;
7582 struct ppc_link_hash_entry
*fdh
= NULL
;
7583 Elf_Internal_Sym
*sym
;
7585 Elf_Internal_Rela
*next_rel
;
7588 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7589 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7594 if (next_rel
+ 1 == relend
7595 || (next_rel
+ 2 < relend
7596 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7599 /* See if the .opd entry is full 24 byte or
7600 16 byte (with fd_aux entry overlapped with next
7603 if (next_rel
== relend
)
7605 if (sec
->size
== rel
->r_offset
+ 16)
7608 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7612 && h
->root
.root
.string
[0] == '.')
7614 fdh
= ppc_elf_hash_entry (h
)->oh
;
7617 fdh
= ppc_follow_link (fdh
);
7618 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
7619 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7624 skip
= (sym_sec
->owner
!= ibfd
7625 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7628 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7630 /* Arrange for the function descriptor sym
7632 fdh
->elf
.root
.u
.def
.value
= 0;
7633 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7635 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7637 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7642 if (!dec_dynrel_count (rel
, sec
, info
,
7646 if (++rel
== next_rel
)
7649 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7650 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7657 /* We'll be keeping this opd entry. */
7662 /* Redefine the function descriptor symbol to
7663 this location in the opd section. It is
7664 necessary to update the value here rather
7665 than using an array of adjustments as we do
7666 for local symbols, because various places
7667 in the generic ELF code use the value
7668 stored in u.def.value. */
7669 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7670 fdh
->adjust_done
= 1;
7673 /* Local syms are a bit tricky. We could
7674 tweak them as they can be cached, but
7675 we'd need to look through the local syms
7676 for the function descriptor sym which we
7677 don't have at the moment. So keep an
7678 array of adjustments. */
7679 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
7680 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
7683 memcpy (wptr
, rptr
, opd_ent_size
);
7684 wptr
+= opd_ent_size
;
7685 if (add_aux_fields
&& opd_ent_size
== 16)
7687 memset (wptr
, '\0', 8);
7691 /* We need to adjust any reloc offsets to point to the
7693 for ( ; rel
!= next_rel
; ++rel
)
7695 rel
->r_offset
+= adjust
;
7696 if (write_rel
!= rel
)
7697 memcpy (write_rel
, rel
, sizeof (*rel
));
7702 rptr
+= opd_ent_size
;
7705 sec
->size
= wptr
- new_contents
;
7706 sec
->reloc_count
= write_rel
- relstart
;
7709 free (sec
->contents
);
7710 sec
->contents
= new_contents
;
7713 /* Fudge the header size too, as this is used later in
7714 elf_bfd_final_link if we are emitting relocs. */
7715 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7716 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7719 else if (elf_section_data (sec
)->relocs
!= relstart
)
7722 if (local_syms
!= NULL
7723 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7725 if (!info
->keep_memory
)
7728 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7733 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7735 /* If we are doing a final link and the last .opd entry is just 16 byte
7736 long, add a 8 byte padding after it. */
7737 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7741 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7743 BFD_ASSERT (need_pad
->size
> 0);
7745 p
= bfd_malloc (need_pad
->size
+ 8);
7749 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7750 p
, 0, need_pad
->size
))
7753 need_pad
->contents
= p
;
7754 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7758 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7762 need_pad
->contents
= p
;
7765 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7766 need_pad
->size
+= 8;
7772 /* Analyze inline PLT call relocations to see whether calls to locally
7773 defined functions can be converted to direct calls. */
7776 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7778 struct ppc_link_hash_table
*htab
;
7781 bfd_vma low_vma
, high_vma
, limit
;
7783 htab
= ppc_hash_table (info
);
7787 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7788 reduced somewhat to cater for possible stubs that might be added
7789 between the call and its destination. */
7790 if (htab
->params
->group_size
< 0)
7792 limit
= -htab
->params
->group_size
;
7798 limit
= htab
->params
->group_size
;
7805 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7806 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7808 if (low_vma
> sec
->vma
)
7810 if (high_vma
< sec
->vma
+ sec
->size
)
7811 high_vma
= sec
->vma
+ sec
->size
;
7814 /* If a "bl" can reach anywhere in local code sections, then we can
7815 convert all inline PLT sequences to direct calls when the symbol
7817 if (high_vma
- low_vma
< limit
)
7819 htab
->can_convert_all_inline_plt
= 1;
7823 /* Otherwise, go looking through relocs for cases where a direct
7824 call won't reach. Mark the symbol on any such reloc to disable
7825 the optimization and keep the PLT entry as it seems likely that
7826 this will be better than creating trampolines. Note that this
7827 will disable the optimization for all inline PLT calls to a
7828 particular symbol, not just those that won't reach. The
7829 difficulty in doing a more precise optimization is that the
7830 linker needs to make a decision depending on whether a
7831 particular R_PPC64_PLTCALL insn can be turned into a direct
7832 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7833 the sequence, and there is nothing that ties those relocs
7834 together except their symbol. */
7836 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7838 Elf_Internal_Shdr
*symtab_hdr
;
7839 Elf_Internal_Sym
*local_syms
;
7841 if (!is_ppc64_elf (ibfd
))
7845 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7847 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7848 if (ppc64_elf_section_data (sec
)->has_pltcall
7849 && !bfd_is_abs_section (sec
->output_section
))
7851 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7853 /* Read the relocations. */
7854 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7856 if (relstart
== NULL
)
7859 relend
= relstart
+ sec
->reloc_count
;
7860 for (rel
= relstart
; rel
< relend
; rel
++)
7862 enum elf_ppc64_reloc_type r_type
;
7863 unsigned long r_symndx
;
7865 struct elf_link_hash_entry
*h
;
7866 Elf_Internal_Sym
*sym
;
7867 unsigned char *tls_maskp
;
7869 r_type
= ELF64_R_TYPE (rel
->r_info
);
7870 if (r_type
!= R_PPC64_PLTCALL
7871 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
7874 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7875 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7878 if (elf_section_data (sec
)->relocs
!= relstart
)
7880 if (symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7885 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7889 to
= h
->root
.u
.def
.value
;
7892 to
+= (rel
->r_addend
7893 + sym_sec
->output_offset
7894 + sym_sec
->output_section
->vma
);
7895 from
= (rel
->r_offset
7896 + sec
->output_offset
7897 + sec
->output_section
->vma
);
7898 if (to
- from
+ limit
< 2 * limit
7899 && !(r_type
== R_PPC64_PLTCALL_NOTOC
7900 && (((h
? h
->other
: sym
->st_other
)
7901 & STO_PPC64_LOCAL_MASK
)
7902 > 1 << STO_PPC64_LOCAL_BIT
)))
7903 *tls_maskp
&= ~PLT_KEEP
;
7906 if (elf_section_data (sec
)->relocs
!= relstart
)
7910 if (local_syms
!= NULL
7911 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7913 if (!info
->keep_memory
)
7916 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7923 /* Set htab->tls_get_addr and various other info specific to TLS.
7924 This needs to run before dynamic symbols are processed in
7925 bfd_elf_size_dynamic_sections. */
7928 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7930 struct ppc_link_hash_table
*htab
;
7931 struct elf_link_hash_entry
*tga
, *tga_fd
, *desc
, *desc_fd
;
7933 htab
= ppc_hash_table (info
);
7937 /* Move dynamic linking info to the function descriptor sym. */
7938 if (htab
->need_func_desc_adj
)
7940 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7941 htab
->need_func_desc_adj
= 0;
7944 if (abiversion (info
->output_bfd
) == 1)
7947 if (htab
->params
->no_multi_toc
)
7948 htab
->do_multi_toc
= 0;
7949 else if (!htab
->do_multi_toc
)
7950 htab
->params
->no_multi_toc
= 1;
7952 /* Default to --no-plt-localentry, as this option can cause problems
7953 with symbol interposition. For example, glibc libpthread.so and
7954 libc.so duplicate many pthread symbols, with a fallback
7955 implementation in libc.so. In some cases the fallback does more
7956 work than the pthread implementation. __pthread_condattr_destroy
7957 is one such symbol: the libpthread.so implementation is
7958 localentry:0 while the libc.so implementation is localentry:8.
7959 An app that "cleverly" uses dlopen to only load necessary
7960 libraries at runtime may omit loading libpthread.so when not
7961 running multi-threaded, which then results in the libc.so
7962 fallback symbols being used and ld.so complaining. Now there
7963 are workarounds in ld (see non_zero_localentry) to detect the
7964 pthread situation, but that may not be the only case where
7965 --plt-localentry can cause trouble. */
7966 if (htab
->params
->plt_localentry0
< 0)
7967 htab
->params
->plt_localentry0
= 0;
7968 if (htab
->params
->plt_localentry0
&& htab
->has_power10_relocs
)
7970 /* The issue is that __glink_PLTresolve saves r2, which is done
7971 because glibc ld.so _dl_runtime_resolve restores r2 to support
7972 a glibc plt call optimisation where global entry code is
7973 skipped on calls that resolve to the same binary. The
7974 __glink_PLTresolve save of r2 is incompatible with code
7975 making tail calls, because the tail call might go via the
7976 resolver and thus overwrite the proper saved r2. */
7977 _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
7978 "power10 pc-relative code"));
7979 htab
->params
->plt_localentry0
= 0;
7981 if (htab
->params
->plt_localentry0
7982 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7983 false, false, false) == NULL
)
7985 (_("warning: --plt-localentry is especially dangerous without "
7986 "ld.so support to detect ABI violations"));
7988 tga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7989 false, false, true);
7990 htab
->tls_get_addr
= ppc_elf_hash_entry (tga
);
7991 tga_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7992 false, false, true);
7993 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (tga_fd
);
7995 desc
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_desc",
7996 false, false, true);
7997 htab
->tga_desc
= ppc_elf_hash_entry (desc
);
7998 desc_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_desc",
7999 false, false, true);
8000 htab
->tga_desc_fd
= ppc_elf_hash_entry (desc_fd
);
8002 if (htab
->params
->tls_get_addr_opt
)
8004 struct elf_link_hash_entry
*opt
, *opt_fd
;
8006 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
8007 false, false, true);
8008 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
8009 false, false, true);
8011 && (opt_fd
->root
.type
== bfd_link_hash_defined
8012 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8014 /* If glibc supports an optimized __tls_get_addr call stub,
8015 signalled by the presence of __tls_get_addr_opt, and we'll
8016 be calling __tls_get_addr via a plt call stub, then
8017 make __tls_get_addr point to __tls_get_addr_opt. */
8018 if (!(htab
->elf
.dynamic_sections_created
8020 && (tga_fd
->type
== STT_FUNC
8021 || tga_fd
->needs_plt
)
8022 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8023 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
))))
8025 if (!(htab
->elf
.dynamic_sections_created
8027 && (desc_fd
->type
== STT_FUNC
8028 || desc_fd
->needs_plt
)
8029 && !(SYMBOL_CALLS_LOCAL (info
, desc_fd
)
8030 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, desc_fd
))))
8033 if (tga_fd
!= NULL
|| desc_fd
!= NULL
)
8035 struct plt_entry
*ent
= NULL
;
8038 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8039 if (ent
->plt
.refcount
> 0)
8041 if (ent
== NULL
&& desc_fd
!= NULL
)
8042 for (ent
= desc_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8043 if (ent
->plt
.refcount
> 0)
8049 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8050 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8051 tga_fd
->root
.u
.i
.warning
= NULL
;
8052 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8054 if (desc_fd
!= NULL
)
8056 desc_fd
->root
.type
= bfd_link_hash_indirect
;
8057 desc_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8058 desc_fd
->root
.u
.i
.warning
= NULL
;
8059 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, desc_fd
);
8062 if (opt_fd
->dynindx
!= -1)
8064 /* Use __tls_get_addr_opt in dynamic relocations. */
8065 opt_fd
->dynindx
= -1;
8066 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8067 opt_fd
->dynstr_index
);
8068 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8073 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (opt_fd
);
8074 tga
= elf_hash_entry (htab
->tls_get_addr
);
8075 if (opt
!= NULL
&& tga
!= NULL
)
8077 tga
->root
.type
= bfd_link_hash_indirect
;
8078 tga
->root
.u
.i
.link
= &opt
->root
;
8079 tga
->root
.u
.i
.warning
= NULL
;
8080 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8082 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8084 htab
->tls_get_addr
= ppc_elf_hash_entry (opt
);
8086 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8087 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8088 if (htab
->tls_get_addr
!= NULL
)
8090 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8091 htab
->tls_get_addr
->is_func
= 1;
8094 if (desc_fd
!= NULL
)
8096 htab
->tga_desc_fd
= ppc_elf_hash_entry (opt_fd
);
8097 if (opt
!= NULL
&& desc
!= NULL
)
8099 desc
->root
.type
= bfd_link_hash_indirect
;
8100 desc
->root
.u
.i
.link
= &opt
->root
;
8101 desc
->root
.u
.i
.warning
= NULL
;
8102 ppc64_elf_copy_indirect_symbol (info
, opt
, desc
);
8104 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8105 desc
->forced_local
);
8106 htab
->tga_desc
= ppc_elf_hash_entry (opt
);
8108 htab
->tga_desc_fd
->oh
= htab
->tga_desc
;
8109 htab
->tga_desc_fd
->is_func_descriptor
= 1;
8110 if (htab
->tga_desc
!= NULL
)
8112 htab
->tga_desc
->oh
= htab
->tga_desc_fd
;
8113 htab
->tga_desc
->is_func
= 1;
8119 else if (htab
->params
->tls_get_addr_opt
< 0)
8120 htab
->params
->tls_get_addr_opt
= 0;
8123 if (htab
->tga_desc_fd
!= NULL
8124 && htab
->params
->tls_get_addr_opt
8125 && htab
->params
->no_tls_get_addr_regsave
== -1)
8126 htab
->params
->no_tls_get_addr_regsave
= 0;
8131 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8132 any of HASH1, HASH2, HASH3, or HASH4. */
8135 branch_reloc_hash_match (bfd
*ibfd
,
8136 Elf_Internal_Rela
*rel
,
8137 struct ppc_link_hash_entry
*hash1
,
8138 struct ppc_link_hash_entry
*hash2
,
8139 struct ppc_link_hash_entry
*hash3
,
8140 struct ppc_link_hash_entry
*hash4
)
8142 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8143 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8144 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8146 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8148 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8149 struct elf_link_hash_entry
*h
;
8151 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8152 h
= elf_follow_link (h
);
8153 if (h
== elf_hash_entry (hash1
)
8154 || h
== elf_hash_entry (hash2
)
8155 || h
== elf_hash_entry (hash3
)
8156 || h
== elf_hash_entry (hash4
))
8162 /* Run through all the TLS relocs looking for optimization
8163 opportunities. The linker has been hacked (see ppc64elf.em) to do
8164 a preliminary section layout so that we know the TLS segment
8165 offsets. We can't optimize earlier because some optimizations need
8166 to know the tp offset, and we need to optimize before allocating
8167 dynamic relocations. */
8170 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8174 struct ppc_link_hash_table
*htab
;
8175 unsigned char *toc_ref
;
8178 if (!bfd_link_executable (info
))
8181 htab
= ppc_hash_table (info
);
8185 htab
->do_tls_opt
= 1;
8187 /* Make two passes over the relocs. On the first pass, mark toc
8188 entries involved with tls relocs, and check that tls relocs
8189 involved in setting up a tls_get_addr call are indeed followed by
8190 such a call. If they are not, we can't do any tls optimization.
8191 On the second pass twiddle tls_mask flags to notify
8192 relocate_section that optimization can be done, and adjust got
8193 and plt refcounts. */
8195 for (pass
= 0; pass
< 2; ++pass
)
8196 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8198 Elf_Internal_Sym
*locsyms
= NULL
;
8199 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8201 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8202 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8204 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8205 bool found_tls_get_addr_arg
= 0;
8207 /* Read the relocations. */
8208 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8210 if (relstart
== NULL
)
8216 relend
= relstart
+ sec
->reloc_count
;
8217 for (rel
= relstart
; rel
< relend
; rel
++)
8219 enum elf_ppc64_reloc_type r_type
;
8220 unsigned long r_symndx
;
8221 struct elf_link_hash_entry
*h
;
8222 Elf_Internal_Sym
*sym
;
8224 unsigned char *tls_mask
;
8225 unsigned int tls_set
, tls_clear
, tls_type
= 0;
8227 bool ok_tprel
, is_local
;
8228 long toc_ref_index
= 0;
8229 int expecting_tls_get_addr
= 0;
8232 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8233 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8237 if (elf_section_data (sec
)->relocs
!= relstart
)
8240 if (elf_symtab_hdr (ibfd
).contents
8241 != (unsigned char *) locsyms
)
8248 if (h
->root
.type
== bfd_link_hash_defined
8249 || h
->root
.type
== bfd_link_hash_defweak
)
8250 value
= h
->root
.u
.def
.value
;
8251 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8255 found_tls_get_addr_arg
= 0;
8260 /* Symbols referenced by TLS relocs must be of type
8261 STT_TLS. So no need for .opd local sym adjust. */
8262 value
= sym
->st_value
;
8265 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
8269 && h
->root
.type
== bfd_link_hash_undefweak
)
8271 else if (sym_sec
!= NULL
8272 && sym_sec
->output_section
!= NULL
)
8274 value
+= sym_sec
->output_offset
;
8275 value
+= sym_sec
->output_section
->vma
;
8276 value
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8277 /* Note that even though the prefix insns
8278 allow a 1<<33 offset we use the same test
8279 as for addis;addi. There may be a mix of
8280 pcrel and non-pcrel code and the decision
8281 to optimise is per symbol, not per TLS
8283 ok_tprel
= value
+ 0x80008000ULL
< 1ULL << 32;
8287 r_type
= ELF64_R_TYPE (rel
->r_info
);
8288 /* If this section has old-style __tls_get_addr calls
8289 without marker relocs, then check that each
8290 __tls_get_addr call reloc is preceded by a reloc
8291 that conceivably belongs to the __tls_get_addr arg
8292 setup insn. If we don't find matching arg setup
8293 relocs, don't do any tls optimization. */
8295 && sec
->nomark_tls_get_addr
8297 && is_tls_get_addr (h
, htab
)
8298 && !found_tls_get_addr_arg
8299 && is_branch_reloc (r_type
))
8301 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8302 "TLS optimization disabled\n"),
8303 ibfd
, sec
, rel
->r_offset
);
8308 found_tls_get_addr_arg
= 0;
8311 case R_PPC64_GOT_TLSLD16
:
8312 case R_PPC64_GOT_TLSLD16_LO
:
8313 case R_PPC64_GOT_TLSLD_PCREL34
:
8314 expecting_tls_get_addr
= 1;
8315 found_tls_get_addr_arg
= 1;
8318 case R_PPC64_GOT_TLSLD16_HI
:
8319 case R_PPC64_GOT_TLSLD16_HA
:
8320 /* These relocs should never be against a symbol
8321 defined in a shared lib. Leave them alone if
8322 that turns out to be the case. */
8329 tls_type
= TLS_TLS
| TLS_LD
;
8332 case R_PPC64_GOT_TLSGD16
:
8333 case R_PPC64_GOT_TLSGD16_LO
:
8334 case R_PPC64_GOT_TLSGD_PCREL34
:
8335 expecting_tls_get_addr
= 1;
8336 found_tls_get_addr_arg
= 1;
8339 case R_PPC64_GOT_TLSGD16_HI
:
8340 case R_PPC64_GOT_TLSGD16_HA
:
8346 tls_set
= TLS_TLS
| TLS_GDIE
;
8348 tls_type
= TLS_TLS
| TLS_GD
;
8351 case R_PPC64_GOT_TPREL_PCREL34
:
8352 case R_PPC64_GOT_TPREL16_DS
:
8353 case R_PPC64_GOT_TPREL16_LO_DS
:
8354 case R_PPC64_GOT_TPREL16_HI
:
8355 case R_PPC64_GOT_TPREL16_HA
:
8360 tls_clear
= TLS_TPREL
;
8361 tls_type
= TLS_TLS
| TLS_TPREL
;
8371 if (rel
+ 1 < relend
8372 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8375 && (ELF64_R_TYPE (rel
[1].r_info
)
8377 && (ELF64_R_TYPE (rel
[1].r_info
)
8378 != R_PPC64_PLTSEQ_NOTOC
))
8380 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8381 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8386 struct plt_entry
*ent
= NULL
;
8388 for (ent
= h
->plt
.plist
;
8391 if (ent
->addend
== rel
[1].r_addend
)
8395 && ent
->plt
.refcount
> 0)
8396 ent
->plt
.refcount
-= 1;
8401 found_tls_get_addr_arg
= 1;
8406 case R_PPC64_TOC16_LO
:
8407 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8410 /* Mark this toc entry as referenced by a TLS
8411 code sequence. We can do that now in the
8412 case of R_PPC64_TLS, and after checking for
8413 tls_get_addr for the TOC16 relocs. */
8414 if (toc_ref
== NULL
)
8416 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8417 if (toc_ref
== NULL
)
8421 value
= h
->root
.u
.def
.value
;
8423 value
= sym
->st_value
;
8424 value
+= rel
->r_addend
;
8427 BFD_ASSERT (value
< toc
->size
8428 && toc
->output_offset
% 8 == 0);
8429 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8430 if (r_type
== R_PPC64_TLS
8431 || r_type
== R_PPC64_TLSGD
8432 || r_type
== R_PPC64_TLSLD
)
8434 toc_ref
[toc_ref_index
] = 1;
8438 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8443 expecting_tls_get_addr
= 2;
8446 case R_PPC64_TPREL64
:
8450 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8455 tls_set
= TLS_EXPLICIT
;
8456 tls_clear
= TLS_TPREL
;
8461 case R_PPC64_DTPMOD64
:
8465 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8467 if (rel
+ 1 < relend
8469 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8470 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8474 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8477 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_GDIE
;
8486 tls_set
= TLS_EXPLICIT
;
8491 case R_PPC64_TPREL16_HA
:
8494 unsigned char buf
[4];
8496 bfd_vma off
= rel
->r_offset
& ~3;
8497 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8500 insn
= bfd_get_32 (ibfd
, buf
);
8501 /* addis rt,13,imm */
8502 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8503 != ((15u << 26) | (13 << 16)))
8505 /* xgettext:c-format */
8506 info
->callbacks
->minfo
8507 (_("%H: warning: %s unexpected insn %#x.\n"),
8508 ibfd
, sec
, off
, "R_PPC64_TPREL16_HA", insn
);
8509 htab
->do_tls_opt
= 0;
8514 case R_PPC64_TPREL16_HI
:
8515 case R_PPC64_TPREL16_HIGH
:
8516 case R_PPC64_TPREL16_HIGHA
:
8517 case R_PPC64_TPREL16_HIGHER
:
8518 case R_PPC64_TPREL16_HIGHERA
:
8519 case R_PPC64_TPREL16_HIGHEST
:
8520 case R_PPC64_TPREL16_HIGHESTA
:
8521 /* These can all be used in sequences along with
8522 TPREL16_LO or TPREL16_LO_DS in ways we aren't
8523 able to verify easily. */
8524 htab
->do_tls_opt
= 0;
8533 if (!expecting_tls_get_addr
8534 || !sec
->nomark_tls_get_addr
)
8537 if (rel
+ 1 < relend
8538 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8539 htab
->tls_get_addr_fd
,
8544 if (expecting_tls_get_addr
== 2)
8546 /* Check for toc tls entries. */
8547 unsigned char *toc_tls
;
8550 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8555 if (toc_tls
!= NULL
)
8557 if ((*toc_tls
& TLS_TLS
) != 0
8558 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8559 found_tls_get_addr_arg
= 1;
8561 toc_ref
[toc_ref_index
] = 1;
8567 /* Uh oh, we didn't find the expected call. We
8568 could just mark this symbol to exclude it
8569 from tls optimization but it's safer to skip
8570 the entire optimization. */
8571 /* xgettext:c-format */
8572 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8573 "TLS optimization disabled\n"),
8574 ibfd
, sec
, rel
->r_offset
);
8579 /* If we don't have old-style __tls_get_addr calls
8580 without TLSGD/TLSLD marker relocs, and we haven't
8581 found a new-style __tls_get_addr call with a
8582 marker for this symbol, then we either have a
8583 broken object file or an -mlongcall style
8584 indirect call to __tls_get_addr without a marker.
8585 Disable optimization in this case. */
8586 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8587 && (tls_set
& TLS_EXPLICIT
) == 0
8588 && !sec
->nomark_tls_get_addr
8589 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8590 != (TLS_TLS
| TLS_MARK
)))
8593 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
8595 struct plt_entry
*ent
= NULL
;
8597 if (htab
->tls_get_addr_fd
!= NULL
)
8598 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8601 if (ent
->addend
== 0)
8604 if (ent
== NULL
&& htab
->tga_desc_fd
!= NULL
)
8605 for (ent
= htab
->tga_desc_fd
->elf
.plt
.plist
;
8608 if (ent
->addend
== 0)
8611 if (ent
== NULL
&& htab
->tls_get_addr
!= NULL
)
8612 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8615 if (ent
->addend
== 0)
8618 if (ent
== NULL
&& htab
->tga_desc
!= NULL
)
8619 for (ent
= htab
->tga_desc
->elf
.plt
.plist
;
8622 if (ent
->addend
== 0)
8626 && ent
->plt
.refcount
> 0)
8627 ent
->plt
.refcount
-= 1;
8633 if ((tls_set
& TLS_EXPLICIT
) == 0)
8635 struct got_entry
*ent
;
8637 /* Adjust got entry for this reloc. */
8641 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8643 for (; ent
!= NULL
; ent
= ent
->next
)
8644 if (ent
->addend
== rel
->r_addend
8645 && ent
->owner
== ibfd
8646 && ent
->tls_type
== tls_type
)
8653 /* We managed to get rid of a got entry. */
8654 if (ent
->got
.refcount
> 0)
8655 ent
->got
.refcount
-= 1;
8660 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8661 we'll lose one or two dyn relocs. */
8662 if (!dec_dynrel_count (rel
, sec
, info
,
8666 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8668 if (!dec_dynrel_count (rel
+ 1, sec
, info
,
8674 *tls_mask
|= tls_set
& 0xff;
8675 *tls_mask
&= ~tls_clear
;
8678 if (elf_section_data (sec
)->relocs
!= relstart
)
8683 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8685 if (!info
->keep_memory
)
8688 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8696 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8697 the values of any global symbols in a toc section that has been
8698 edited. Globals in toc sections should be a rarity, so this function
8699 sets a flag if any are found in toc sections other than the one just
8700 edited, so that further hash table traversals can be avoided. */
8702 struct adjust_toc_info
8705 unsigned long *skip
;
8706 bool global_toc_syms
;
8709 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8712 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8714 struct ppc_link_hash_entry
*eh
;
8715 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8718 if (h
->root
.type
!= bfd_link_hash_defined
8719 && h
->root
.type
!= bfd_link_hash_defweak
)
8722 eh
= ppc_elf_hash_entry (h
);
8723 if (eh
->adjust_done
)
8726 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8728 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8729 i
= toc_inf
->toc
->rawsize
>> 3;
8731 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8733 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8736 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8739 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8740 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8743 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8744 eh
->adjust_done
= 1;
8746 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8747 toc_inf
->global_toc_syms
= true;
8752 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8753 on a _LO variety toc/got reloc. */
8756 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8758 return ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */
8759 || (insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
8760 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
8761 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
8762 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
8763 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
8764 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
8765 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
8766 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
8767 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
8768 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
8769 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
8770 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
8771 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
8772 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
8773 || (insn
& (0x3fu
<< 26)) == 56u << 26 /* lq,lfq */
8774 || ((insn
& (0x3fu
<< 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8775 /* Exclude lfqu by testing reloc. If relocs are ever
8776 defined for the reduced D field in psq_lu then those
8777 will need testing too. */
8778 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8779 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* ld,lwa */
8781 || (insn
& (0x3fu
<< 26)) == 60u << 26 /* stfq */
8782 || ((insn
& (0x3fu
<< 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8783 /* Exclude stfqu. psq_stu as above for psq_lu. */
8784 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8785 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std,stq */
8786 && (insn
& 1) == 0));
8789 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
8790 pld ra,symbol@got@pcrel
8791 load/store rt,off(ra)
8794 load/store rt,off(ra)
8795 may be translated to
8796 pload/pstore rt,symbol+off@pcrel
8798 This function returns true if the optimization is possible, placing
8799 the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
8801 On entry to this function, the linker has already determined that
8802 the pld can be replaced with pla: *PINSN1 is that pla insn,
8803 while *PINSN2 is the second instruction. */
8806 xlate_pcrel_opt (uint64_t *pinsn1
, uint64_t *pinsn2
, bfd_signed_vma
*poff
)
8808 uint64_t insn1
= *pinsn1
;
8809 uint64_t insn2
= *pinsn2
;
8812 if ((insn2
& (63ULL << 58)) == 1ULL << 58)
8814 /* Check that regs match. */
8815 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8818 /* P8LS or PMLS form, non-pcrel. */
8819 if ((insn2
& (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
8822 *pinsn1
= (insn2
& ~(31 << 16) & ~0x3ffff0000ffffULL
) | (1ULL << 52);
8824 off
= ((insn2
>> 16) & 0x3ffff0000ULL
) | (insn2
& 0xffff);
8825 *poff
= (off
^ 0x200000000ULL
) - 0x200000000ULL
;
8831 /* Check that regs match. */
8832 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8835 switch ((insn2
>> 26) & 63)
8851 /* These are the PMLS cases, where we just need to tack a prefix
8853 insn1
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
8854 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8855 off
= insn2
& 0xffff;
8858 case 58: /* lwa, ld */
8859 if ((insn2
& 1) != 0)
8861 insn1
= ((1ULL << 58) | (1ULL << 52)
8862 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
8863 | (insn2
& (31ULL << 21)));
8864 off
= insn2
& 0xfffc;
8867 case 57: /* lxsd, lxssp */
8868 if ((insn2
& 3) < 2)
8870 insn1
= ((1ULL << 58) | (1ULL << 52)
8871 | ((40ULL | (insn2
& 3)) << 26)
8872 | (insn2
& (31ULL << 21)));
8873 off
= insn2
& 0xfffc;
8876 case 61: /* stxsd, stxssp, lxv, stxv */
8877 if ((insn2
& 3) == 0)
8879 else if ((insn2
& 3) >= 2)
8881 insn1
= ((1ULL << 58) | (1ULL << 52)
8882 | ((44ULL | (insn2
& 3)) << 26)
8883 | (insn2
& (31ULL << 21)));
8884 off
= insn2
& 0xfffc;
8888 insn1
= ((1ULL << 58) | (1ULL << 52)
8889 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
8890 | (insn2
& (31ULL << 21)));
8891 off
= insn2
& 0xfff0;
8896 insn1
= ((1ULL << 58) | (1ULL << 52)
8897 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8898 off
= insn2
& 0xffff;
8901 case 6: /* lxvp, stxvp */
8902 if ((insn2
& 0xe) != 0)
8904 insn1
= ((1ULL << 58) | (1ULL << 52)
8905 | ((insn2
& 1) == 0 ? 58ULL << 26 : 62ULL << 26)
8906 | (insn2
& (31ULL << 21)));
8907 off
= insn2
& 0xfff0;
8910 case 62: /* std, stq */
8911 if ((insn2
& 1) != 0)
8913 insn1
= ((1ULL << 58) | (1ULL << 52)
8914 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
8915 | (insn2
& (31ULL << 21)));
8916 off
= insn2
& 0xfffc;
8921 *pinsn2
= (uint64_t) NOP
<< 32;
8922 *poff
= (off
^ 0x8000) - 0x8000;
8926 /* Examine all relocs referencing .toc sections in order to remove
8927 unused .toc entries. */
8930 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8933 struct adjust_toc_info toc_inf
;
8934 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8936 htab
->do_toc_opt
= 1;
8937 toc_inf
.global_toc_syms
= true;
8938 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8940 asection
*toc
, *sec
;
8941 Elf_Internal_Shdr
*symtab_hdr
;
8942 Elf_Internal_Sym
*local_syms
;
8943 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8944 unsigned long *skip
, *drop
;
8945 unsigned char *used
;
8946 unsigned char *keep
, last
, some_unused
;
8948 if (!is_ppc64_elf (ibfd
))
8951 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8954 || (toc
->flags
& SEC_HAS_CONTENTS
) == 0
8955 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8956 || discarded_section (toc
))
8961 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8963 /* Look at sections dropped from the final link. */
8966 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8968 if (sec
->reloc_count
== 0
8969 || !discarded_section (sec
)
8970 || get_opd_info (sec
)
8971 || (sec
->flags
& SEC_ALLOC
) == 0
8972 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8975 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, false);
8976 if (relstart
== NULL
)
8979 /* Run through the relocs to see which toc entries might be
8981 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8983 enum elf_ppc64_reloc_type r_type
;
8984 unsigned long r_symndx
;
8986 struct elf_link_hash_entry
*h
;
8987 Elf_Internal_Sym
*sym
;
8990 r_type
= ELF64_R_TYPE (rel
->r_info
);
8997 case R_PPC64_TOC16_LO
:
8998 case R_PPC64_TOC16_HI
:
8999 case R_PPC64_TOC16_HA
:
9000 case R_PPC64_TOC16_DS
:
9001 case R_PPC64_TOC16_LO_DS
:
9005 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9006 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9014 val
= h
->root
.u
.def
.value
;
9016 val
= sym
->st_value
;
9017 val
+= rel
->r_addend
;
9019 if (val
>= toc
->size
)
9022 /* Anything in the toc ought to be aligned to 8 bytes.
9023 If not, don't mark as unused. */
9029 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9034 skip
[val
>> 3] = ref_from_discarded
;
9037 if (elf_section_data (sec
)->relocs
!= relstart
)
9041 /* For largetoc loads of address constants, we can convert
9042 . addis rx,2,addr@got@ha
9043 . ld ry,addr@got@l(rx)
9045 . addis rx,2,addr@toc@ha
9046 . addi ry,rx,addr@toc@l
9047 when addr is within 2G of the toc pointer. This then means
9048 that the word storing "addr" in the toc is no longer needed. */
9050 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9051 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9052 && toc
->reloc_count
!= 0)
9054 /* Read toc relocs. */
9055 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9057 if (toc_relocs
== NULL
)
9060 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9062 enum elf_ppc64_reloc_type r_type
;
9063 unsigned long r_symndx
;
9065 struct elf_link_hash_entry
*h
;
9066 Elf_Internal_Sym
*sym
;
9069 r_type
= ELF64_R_TYPE (rel
->r_info
);
9070 if (r_type
!= R_PPC64_ADDR64
)
9073 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9074 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9079 || sym_sec
->output_section
== NULL
9080 || discarded_section (sym_sec
))
9083 if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
9084 || (bfd_link_pic (info
)
9085 && sym_sec
== bfd_abs_section_ptr
))
9090 if (h
->type
== STT_GNU_IFUNC
)
9092 val
= h
->root
.u
.def
.value
;
9096 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9098 val
= sym
->st_value
;
9100 val
+= rel
->r_addend
;
9101 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9103 /* We don't yet know the exact toc pointer value, but we
9104 know it will be somewhere in the toc section. Don't
9105 optimize if the difference from any possible toc
9106 pointer is outside [ff..f80008000, 7fff7fff]. */
9107 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9108 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9111 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9112 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9117 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9122 skip
[rel
->r_offset
>> 3]
9123 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9130 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9134 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9137 && elf_section_data (sec
)->relocs
!= relstart
)
9139 if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9145 /* Now check all kept sections that might reference the toc.
9146 Check the toc itself last. */
9147 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9150 sec
= (sec
== toc
? NULL
9151 : sec
->next
== NULL
? toc
9152 : sec
->next
== toc
&& toc
->next
? toc
->next
9157 if (sec
->reloc_count
== 0
9158 || discarded_section (sec
)
9159 || get_opd_info (sec
)
9160 || (sec
->flags
& SEC_ALLOC
) == 0
9161 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9164 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9166 if (relstart
== NULL
)
9172 /* Mark toc entries referenced as used. */
9176 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9178 enum elf_ppc64_reloc_type r_type
;
9179 unsigned long r_symndx
;
9181 struct elf_link_hash_entry
*h
;
9182 Elf_Internal_Sym
*sym
;
9185 r_type
= ELF64_R_TYPE (rel
->r_info
);
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 bool 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
, 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 (elf_section_data (toc
)->relocs
!= toc_relocs
)
9511 if (local_syms
!= NULL
9512 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9514 if (!info
->keep_memory
)
9517 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9522 /* Look for cases where we can change an indirect GOT access to
9523 a GOT relative or PC relative access, possibly reducing the
9524 number of GOT entries. */
9525 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9528 Elf_Internal_Shdr
*symtab_hdr
;
9529 Elf_Internal_Sym
*local_syms
;
9530 Elf_Internal_Rela
*relstart
, *rel
;
9533 if (!is_ppc64_elf (ibfd
))
9536 if (!ppc64_elf_tdata (ibfd
)->has_optrel
)
9539 sec
= ppc64_elf_tdata (ibfd
)->got
;
9542 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
9545 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9547 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9549 if (sec
->reloc_count
== 0
9550 || !ppc64_elf_section_data (sec
)->has_optrel
9551 || discarded_section (sec
))
9554 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9556 if (relstart
== NULL
)
9559 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9562 && elf_section_data (sec
)->relocs
!= relstart
)
9567 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9569 enum elf_ppc64_reloc_type r_type
;
9570 unsigned long r_symndx
;
9571 Elf_Internal_Sym
*sym
;
9573 struct elf_link_hash_entry
*h
;
9574 struct got_entry
*ent
;
9576 unsigned char buf
[8];
9578 enum {no_check
, check_lo
, check_ha
} insn_check
;
9580 r_type
= ELF64_R_TYPE (rel
->r_info
);
9584 insn_check
= no_check
;
9587 case R_PPC64_PLT16_HA
:
9588 case R_PPC64_GOT_TLSLD16_HA
:
9589 case R_PPC64_GOT_TLSGD16_HA
:
9590 case R_PPC64_GOT_TPREL16_HA
:
9591 case R_PPC64_GOT_DTPREL16_HA
:
9592 case R_PPC64_GOT16_HA
:
9593 case R_PPC64_TOC16_HA
:
9594 insn_check
= check_ha
;
9597 case R_PPC64_PLT16_LO
:
9598 case R_PPC64_PLT16_LO_DS
:
9599 case R_PPC64_GOT_TLSLD16_LO
:
9600 case R_PPC64_GOT_TLSGD16_LO
:
9601 case R_PPC64_GOT_TPREL16_LO_DS
:
9602 case R_PPC64_GOT_DTPREL16_LO_DS
:
9603 case R_PPC64_GOT16_LO
:
9604 case R_PPC64_GOT16_LO_DS
:
9605 case R_PPC64_TOC16_LO
:
9606 case R_PPC64_TOC16_LO_DS
:
9607 insn_check
= check_lo
;
9611 if (insn_check
!= no_check
)
9613 bfd_vma off
= rel
->r_offset
& ~3;
9615 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9618 insn
= bfd_get_32 (ibfd
, buf
);
9619 if (insn_check
== check_lo
9620 ? !ok_lo_toc_insn (insn
, r_type
)
9621 : ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9622 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9626 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9627 sprintf (str
, "%#08x", insn
);
9628 info
->callbacks
->einfo
9629 /* xgettext:c-format */
9630 (_("%H: got/toc optimization is not supported for"
9631 " %s instruction\n"),
9632 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9639 /* Note that we don't delete GOT entries for
9640 R_PPC64_GOT16_DS since we'd need a lot more
9641 analysis. For starters, the preliminary layout is
9642 before the GOT, PLT, dynamic sections and stubs are
9643 laid out. Then we'd need to allow for changes in
9644 distance between sections caused by alignment. */
9648 case R_PPC64_GOT16_HA
:
9649 case R_PPC64_GOT16_LO_DS
:
9650 case R_PPC64_GOT_PCREL34
:
9654 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9655 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9660 || sym_sec
->output_section
== NULL
9661 || discarded_section (sym_sec
))
9664 if ((h
? h
->type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
)
9667 if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
9668 || (bfd_link_pic (info
)
9669 && sym_sec
== bfd_abs_section_ptr
))
9673 val
= h
->root
.u
.def
.value
;
9675 val
= sym
->st_value
;
9676 val
+= rel
->r_addend
;
9677 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9679 /* Fudge factor to allow for the fact that the preliminary layout
9680 isn't exact. Reduce limits by this factor. */
9681 #define LIMIT_ADJUST(LIMIT) ((LIMIT) - (LIMIT) / 16)
9688 case R_PPC64_GOT16_HA
:
9689 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9690 >= LIMIT_ADJUST (0x100000000ULL
))
9693 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9694 rel
->r_offset
& ~3, 4))
9696 insn
= bfd_get_32 (ibfd
, buf
);
9697 if (((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9698 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9702 case R_PPC64_GOT16_LO_DS
:
9703 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9704 >= LIMIT_ADJUST (0x100000000ULL
))
9706 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9707 rel
->r_offset
& ~3, 4))
9709 insn
= bfd_get_32 (ibfd
, buf
);
9710 if ((insn
& (0x3fu
<< 26 | 0x3)) != 58u << 26 /* ld */)
9714 case R_PPC64_GOT_PCREL34
:
9716 pc
+= sec
->output_section
->vma
+ sec
->output_offset
;
9717 if (val
- pc
+ LIMIT_ADJUST (1ULL << 33)
9718 >= LIMIT_ADJUST (1ULL << 34))
9720 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9721 rel
->r_offset
& ~3, 8))
9723 insn
= bfd_get_32 (ibfd
, buf
);
9724 if ((insn
& (-1u << 18)) != ((1u << 26) | (1u << 20)))
9726 insn
= bfd_get_32 (ibfd
, buf
+ 4);
9727 if ((insn
& (0x3fu
<< 26)) != 57u << 26)
9737 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
9738 ent
= local_got_ents
[r_symndx
];
9740 for (; ent
!= NULL
; ent
= ent
->next
)
9741 if (ent
->addend
== rel
->r_addend
9742 && ent
->owner
== ibfd
9743 && ent
->tls_type
== 0)
9745 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
9746 ent
->got
.refcount
-= 1;
9749 if (elf_section_data (sec
)->relocs
!= relstart
)
9753 if (local_syms
!= NULL
9754 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9756 if (!info
->keep_memory
)
9759 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9766 /* Return true iff input section I references the TOC using
9767 instructions limited to +/-32k offsets. */
9770 ppc64_elf_has_small_toc_reloc (asection
*i
)
9772 return (is_ppc64_elf (i
->owner
)
9773 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9776 /* Allocate space for one GOT entry. */
9779 allocate_got (struct elf_link_hash_entry
*h
,
9780 struct bfd_link_info
*info
,
9781 struct got_entry
*gent
)
9783 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9784 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
9785 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9787 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9788 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9789 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9791 gent
->got
.offset
= got
->size
;
9792 got
->size
+= entsize
;
9794 if (h
->type
== STT_GNU_IFUNC
)
9796 htab
->elf
.irelplt
->size
+= rentsize
;
9797 htab
->got_reli_size
+= rentsize
;
9799 else if (((bfd_link_pic (info
)
9800 && (gent
->tls_type
== 0
9801 ? !info
->enable_dt_relr
9802 : !(bfd_link_executable (info
)
9803 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9804 && !bfd_is_abs_symbol (&h
->root
))
9805 || (htab
->elf
.dynamic_sections_created
9807 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9808 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9810 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9811 relgot
->size
+= rentsize
;
9815 /* This function merges got entries in the same toc group. */
9818 merge_got_entries (struct got_entry
**pent
)
9820 struct got_entry
*ent
, *ent2
;
9822 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9823 if (!ent
->is_indirect
)
9824 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9825 if (!ent2
->is_indirect
9826 && ent2
->addend
== ent
->addend
9827 && ent2
->tls_type
== ent
->tls_type
9828 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9830 ent2
->is_indirect
= true;
9831 ent2
->got
.ent
= ent
;
9835 /* If H is undefined, make it dynamic if that makes sense. */
9838 ensure_undef_dynamic (struct bfd_link_info
*info
,
9839 struct elf_link_hash_entry
*h
)
9841 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9843 if (htab
->dynamic_sections_created
9844 && ((info
->dynamic_undefined_weak
!= 0
9845 && h
->root
.type
== bfd_link_hash_undefweak
)
9846 || h
->root
.type
== bfd_link_hash_undefined
)
9849 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9850 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9854 /* Choose whether to use htab->iplt or htab->pltlocal rather than the
9855 usual htab->elf.splt section for a PLT entry. */
9858 bool use_local_plt (struct bfd_link_info
*info
,
9859 struct elf_link_hash_entry
*h
)
9863 || !elf_hash_table (info
)->dynamic_sections_created
);
9866 /* Allocate space in .plt, .got and associated reloc sections for
9870 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9872 struct bfd_link_info
*info
;
9873 struct ppc_link_hash_table
*htab
;
9875 struct ppc_link_hash_entry
*eh
;
9876 struct got_entry
**pgent
, *gent
;
9878 if (h
->root
.type
== bfd_link_hash_indirect
)
9881 info
= (struct bfd_link_info
*) inf
;
9882 htab
= ppc_hash_table (info
);
9886 eh
= ppc_elf_hash_entry (h
);
9887 /* Run through the TLS GD got entries first if we're changing them
9889 if ((eh
->tls_mask
& (TLS_TLS
| TLS_GDIE
)) == (TLS_TLS
| TLS_GDIE
))
9890 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9891 if (gent
->got
.refcount
> 0
9892 && (gent
->tls_type
& TLS_GD
) != 0)
9894 /* This was a GD entry that has been converted to TPREL. If
9895 there happens to be a TPREL entry we can use that one. */
9896 struct got_entry
*ent
;
9897 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9898 if (ent
->got
.refcount
> 0
9899 && (ent
->tls_type
& TLS_TPREL
) != 0
9900 && ent
->addend
== gent
->addend
9901 && ent
->owner
== gent
->owner
)
9903 gent
->got
.refcount
= 0;
9907 /* If not, then we'll be using our own TPREL entry. */
9908 if (gent
->got
.refcount
!= 0)
9909 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9912 /* Remove any list entry that won't generate a word in the GOT before
9913 we call merge_got_entries. Otherwise we risk merging to empty
9915 pgent
= &h
->got
.glist
;
9916 while ((gent
= *pgent
) != NULL
)
9917 if (gent
->got
.refcount
> 0)
9919 if ((gent
->tls_type
& TLS_LD
) != 0
9920 && SYMBOL_REFERENCES_LOCAL (info
, h
))
9922 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9923 *pgent
= gent
->next
;
9926 pgent
= &gent
->next
;
9929 *pgent
= gent
->next
;
9931 if (!htab
->do_multi_toc
)
9932 merge_got_entries (&h
->got
.glist
);
9934 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9935 if (!gent
->is_indirect
)
9937 /* Ensure we catch all the cases where this symbol should
9939 if (!ensure_undef_dynamic (info
, h
))
9942 if (!is_ppc64_elf (gent
->owner
))
9945 allocate_got (h
, info
, gent
);
9948 /* If no dynamic sections we can't have dynamic relocs, except for
9949 IFUNCs which are handled even in static executables. */
9950 if (!htab
->elf
.dynamic_sections_created
9951 && h
->type
!= STT_GNU_IFUNC
)
9952 h
->dyn_relocs
= NULL
;
9954 /* Discard relocs on undefined symbols that must be local. */
9955 else if (h
->root
.type
== bfd_link_hash_undefined
9956 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9957 h
->dyn_relocs
= NULL
;
9959 /* Also discard relocs on undefined weak syms with non-default
9960 visibility, or when dynamic_undefined_weak says so. */
9961 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9962 h
->dyn_relocs
= NULL
;
9964 if (h
->dyn_relocs
!= NULL
)
9966 struct ppc_dyn_relocs
*p
, **pp
;
9968 /* In the shared -Bsymbolic case, discard space allocated for
9969 dynamic pc-relative relocs against symbols which turn out to
9970 be defined in regular objects. For the normal shared case,
9971 discard space for relocs that have become local due to symbol
9972 visibility changes. */
9973 if (bfd_link_pic (info
))
9975 /* Relocs that use pc_count are those that appear on a call
9976 insn, or certain REL relocs (see must_be_dyn_reloc) that
9977 can be generated via assembly. We want calls to
9978 protected symbols to resolve directly to the function
9979 rather than going via the plt. If people want function
9980 pointer comparisons to work as expected then they should
9981 avoid writing weird assembly. */
9982 if (SYMBOL_CALLS_LOCAL (info
, h
))
9984 for (pp
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
9988 p
->count
-= p
->pc_count
;
9997 if (h
->dyn_relocs
!= NULL
)
9999 /* Ensure we catch all the cases where this symbol
10000 should be made dynamic. */
10001 if (!ensure_undef_dynamic (info
, h
))
10006 /* For a fixed position executable, discard space for
10007 relocs against symbols which are not dynamic. */
10008 else if (h
->type
!= STT_GNU_IFUNC
)
10010 if ((h
->dynamic_adjusted
10012 && h
->root
.type
== bfd_link_hash_undefweak
10013 && (info
->dynamic_undefined_weak
> 0
10014 || !_bfd_elf_readonly_dynrelocs (h
))))
10016 && !ELF_COMMON_DEF_P (h
))
10018 /* Ensure we catch all the cases where this symbol
10019 should be made dynamic. */
10020 if (!ensure_undef_dynamic (info
, h
))
10023 /* But if that didn't work out, discard dynamic relocs. */
10024 if (h
->dynindx
== -1)
10025 h
->dyn_relocs
= NULL
;
10028 h
->dyn_relocs
= NULL
;
10031 /* Finally, allocate space. */
10032 for (p
= (struct ppc_dyn_relocs
*) h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
10033 if (!discarded_section (p
->sec
))
10035 unsigned int count
;
10036 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
10037 if (eh
->elf
.type
== STT_GNU_IFUNC
)
10038 sreloc
= htab
->elf
.irelplt
;
10040 if (info
->enable_dt_relr
10041 && ((!NO_OPD_RELOCS
10042 && ppc64_elf_section_data (p
->sec
)->sec_type
== sec_opd
)
10043 || (eh
->elf
.type
!= STT_GNU_IFUNC
10044 && SYMBOL_REFERENCES_LOCAL (info
, h
))))
10045 count
-= p
->rel_count
;
10046 sreloc
->size
+= count
* sizeof (Elf64_External_Rela
);
10050 /* We might need a PLT entry when the symbol
10053 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
10054 d) has plt16 relocs and we are linking statically. */
10055 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
10056 || h
->type
== STT_GNU_IFUNC
10057 || (h
->needs_plt
&& h
->dynamic_adjusted
)
10060 && !htab
->elf
.dynamic_sections_created
10061 && !htab
->can_convert_all_inline_plt
10062 && (ppc_elf_hash_entry (h
)->tls_mask
10063 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
10065 struct plt_entry
*pent
;
10066 bool doneone
= false;
10067 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10068 if (pent
->plt
.refcount
> 0)
10070 if (!ensure_undef_dynamic (info
, h
))
10073 if (use_local_plt (info
, h
))
10075 if (h
->type
== STT_GNU_IFUNC
)
10077 s
= htab
->elf
.iplt
;
10078 pent
->plt
.offset
= s
->size
;
10079 s
->size
+= PLT_ENTRY_SIZE (htab
);
10080 s
= htab
->elf
.irelplt
;
10084 s
= htab
->pltlocal
;
10085 pent
->plt
.offset
= s
->size
;
10086 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10088 if (bfd_link_pic (info
)
10089 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
10090 s
= htab
->relpltlocal
;
10095 /* If this is the first .plt entry, make room for the special
10097 s
= htab
->elf
.splt
;
10099 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
10101 pent
->plt
.offset
= s
->size
;
10103 /* Make room for this entry. */
10104 s
->size
+= PLT_ENTRY_SIZE (htab
);
10106 /* Make room for the .glink code. */
10109 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
10112 /* We need bigger stubs past index 32767. */
10113 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
10120 /* We also need to make an entry in the .rela.plt section. */
10121 s
= htab
->elf
.srelplt
;
10124 s
->size
+= sizeof (Elf64_External_Rela
);
10128 pent
->plt
.offset
= (bfd_vma
) -1;
10131 h
->plt
.plist
= NULL
;
10137 h
->plt
.plist
= NULL
;
10144 #define PPC_LO(v) ((v) & 0xffff)
10145 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10146 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10148 ((((v) & 0x3ffff0000ULL) << 16) | (v & 0xffff))
10149 #define HA34(v) ((v + (1ULL << 33)) >> 34)
10151 /* Called via elf_link_hash_traverse from ppc64_elf_late_size_sections
10152 to set up space for global entry stubs. These are put in glink,
10153 after the branch table. */
10156 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
10158 struct bfd_link_info
*info
;
10159 struct ppc_link_hash_table
*htab
;
10160 struct plt_entry
*pent
;
10163 if (h
->root
.type
== bfd_link_hash_indirect
)
10166 if (!h
->pointer_equality_needed
)
10169 if (h
->def_regular
)
10173 htab
= ppc_hash_table (info
);
10177 s
= htab
->global_entry
;
10178 plt
= htab
->elf
.splt
;
10179 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10180 if (pent
->plt
.offset
!= (bfd_vma
) -1
10181 && pent
->addend
== 0)
10183 /* For ELFv2, if this symbol is not defined in a regular file
10184 and we are not generating a shared library or pie, then we
10185 need to define the symbol in the executable on a call stub.
10186 This is to avoid text relocations. */
10187 bfd_vma off
, stub_align
, stub_off
, stub_size
;
10188 unsigned int align_power
;
10191 stub_off
= s
->size
;
10192 if (htab
->params
->plt_stub_align
>= 0)
10193 align_power
= htab
->params
->plt_stub_align
;
10195 align_power
= -htab
->params
->plt_stub_align
;
10196 /* Setting section alignment is delayed until we know it is
10197 non-empty. Otherwise the .text output section will be
10198 aligned at least to plt_stub_align even when no global
10199 entry stubs are needed. */
10200 if (s
->alignment_power
< align_power
)
10201 s
->alignment_power
= align_power
;
10202 stub_align
= (bfd_vma
) 1 << align_power
;
10203 if (htab
->params
->plt_stub_align
>= 0
10204 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
10205 - (stub_off
& -stub_align
))
10206 > ((stub_size
- 1) & -stub_align
)))
10207 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
10208 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
10209 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
10210 /* Note that for --plt-stub-align negative we have a possible
10211 dependency between stub offset and size. Break that
10212 dependency by assuming the max stub size when calculating
10213 the stub offset. */
10214 if (PPC_HA (off
) == 0)
10216 h
->root
.type
= bfd_link_hash_defined
;
10217 h
->root
.u
.def
.section
= s
;
10218 h
->root
.u
.def
.value
= stub_off
;
10219 s
->size
= stub_off
+ stub_size
;
10225 /* Set the sizes of the dynamic sections. */
10228 ppc64_elf_late_size_sections (bfd
*output_bfd
,
10229 struct bfd_link_info
*info
)
10231 struct ppc_link_hash_table
*htab
;
10236 struct got_entry
*first_tlsld
;
10238 htab
= ppc_hash_table (info
);
10242 dynobj
= htab
->elf
.dynobj
;
10243 if (dynobj
== NULL
)
10246 if (htab
->elf
.dynamic_sections_created
)
10248 /* Set the contents of the .interp section to the interpreter. */
10249 if (bfd_link_executable (info
) && !info
->nointerp
)
10251 s
= bfd_get_linker_section (dynobj
, ".interp");
10254 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10255 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10259 /* Set up .got offsets for local syms, and space for local dynamic
10261 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10263 struct got_entry
**lgot_ents
;
10264 struct got_entry
**end_lgot_ents
;
10265 struct plt_entry
**local_plt
;
10266 struct plt_entry
**end_local_plt
;
10267 unsigned char *lgot_masks
;
10268 bfd_size_type locsymcount
;
10269 Elf_Internal_Shdr
*symtab_hdr
;
10270 Elf_Internal_Sym
*local_syms
;
10271 Elf_Internal_Sym
*isym
;
10273 if (!is_ppc64_elf (ibfd
))
10276 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10278 struct ppc_local_dyn_relocs
*p
;
10280 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10282 if (discarded_section (p
->sec
))
10284 /* Input section has been discarded, either because
10285 it is a copy of a linkonce section or due to
10286 linker script /DISCARD/, so we'll be discarding
10289 else if (p
->count
!= 0)
10291 unsigned int count
;
10295 if (info
->enable_dt_relr
10296 && ((!NO_OPD_RELOCS
10297 && (ppc64_elf_section_data (p
->sec
)->sec_type
10300 count
-= p
->rel_count
;
10301 srel
= elf_section_data (p
->sec
)->sreloc
;
10303 srel
= htab
->elf
.irelplt
;
10304 srel
->size
+= count
* sizeof (Elf64_External_Rela
);
10305 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10306 info
->flags
|= DF_TEXTREL
;
10311 lgot_ents
= elf_local_got_ents (ibfd
);
10315 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10316 locsymcount
= symtab_hdr
->sh_info
;
10317 end_lgot_ents
= lgot_ents
+ locsymcount
;
10318 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10319 end_local_plt
= local_plt
+ locsymcount
;
10320 lgot_masks
= (unsigned char *) end_local_plt
;
10321 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
10322 if (local_syms
== NULL
&& locsymcount
!= 0)
10324 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
, locsymcount
,
10325 0, NULL
, NULL
, NULL
);
10326 if (local_syms
== NULL
)
10329 s
= ppc64_elf_tdata (ibfd
)->got
;
10330 for (isym
= local_syms
;
10331 lgot_ents
< end_lgot_ents
;
10332 ++lgot_ents
, ++lgot_masks
, isym
++)
10334 struct got_entry
**pent
, *ent
;
10337 while ((ent
= *pent
) != NULL
)
10338 if (ent
->got
.refcount
> 0)
10340 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10342 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10347 unsigned int ent_size
= 8;
10348 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10350 ent
->got
.offset
= s
->size
;
10351 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10356 s
->size
+= ent_size
;
10357 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10359 htab
->elf
.irelplt
->size
+= rel_size
;
10360 htab
->got_reli_size
+= rel_size
;
10362 else if (bfd_link_pic (info
)
10363 && (ent
->tls_type
== 0
10364 ? !info
->enable_dt_relr
10365 : !bfd_link_executable (info
))
10366 && isym
->st_shndx
!= SHN_ABS
)
10368 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10369 srel
->size
+= rel_size
;
10377 if (local_syms
!= NULL
10378 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
10380 if (!info
->keep_memory
)
10383 symtab_hdr
->contents
= (unsigned char *) local_syms
;
10386 /* Allocate space for plt calls to local syms. */
10387 lgot_masks
= (unsigned char *) end_local_plt
;
10388 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10390 struct plt_entry
*ent
;
10392 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10393 if (ent
->plt
.refcount
> 0)
10395 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10397 s
= htab
->elf
.iplt
;
10398 ent
->plt
.offset
= s
->size
;
10399 s
->size
+= PLT_ENTRY_SIZE (htab
);
10400 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10402 else if (htab
->can_convert_all_inline_plt
10403 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10404 ent
->plt
.offset
= (bfd_vma
) -1;
10407 s
= htab
->pltlocal
;
10408 ent
->plt
.offset
= s
->size
;
10409 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10410 if (bfd_link_pic (info
)
10411 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
10412 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
10416 ent
->plt
.offset
= (bfd_vma
) -1;
10420 /* Allocate global sym .plt and .got entries, and space for global
10421 sym dynamic relocs. */
10422 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10424 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10425 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10427 first_tlsld
= NULL
;
10428 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10430 struct got_entry
*ent
;
10432 if (!is_ppc64_elf (ibfd
))
10435 ent
= ppc64_tlsld_got (ibfd
);
10436 if (ent
->got
.refcount
> 0)
10438 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10440 ent
->is_indirect
= true;
10441 ent
->got
.ent
= first_tlsld
;
10445 if (first_tlsld
== NULL
)
10447 s
= ppc64_elf_tdata (ibfd
)->got
;
10448 ent
->got
.offset
= s
->size
;
10451 if (bfd_link_dll (info
))
10453 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10454 srel
->size
+= sizeof (Elf64_External_Rela
);
10459 ent
->got
.offset
= (bfd_vma
) -1;
10462 /* We now have determined the sizes of the various dynamic sections.
10463 Allocate memory for them. */
10465 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10467 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10470 if (s
== htab
->brlt
|| s
== htab
->relbrlt
|| s
== htab
->elf
.srelrdyn
)
10471 /* These haven't been allocated yet; don't strip. */
10473 else if (s
== htab
->elf
.sgot
10474 || s
== htab
->elf
.splt
10475 || s
== htab
->elf
.iplt
10476 || s
== htab
->pltlocal
10477 || s
== htab
->glink
10478 || s
== htab
->global_entry
10479 || s
== htab
->elf
.sdynbss
10480 || s
== htab
->elf
.sdynrelro
)
10482 /* Strip this section if we don't need it; see the
10485 else if (s
== htab
->glink_eh_frame
)
10487 if (!bfd_is_abs_section (s
->output_section
))
10488 /* Not sized yet. */
10491 else if (startswith (s
->name
, ".rela"))
10495 if (s
!= htab
->elf
.srelplt
)
10498 /* We use the reloc_count field as a counter if we need
10499 to copy relocs into the output file. */
10500 s
->reloc_count
= 0;
10505 /* It's not one of our sections, so don't allocate space. */
10511 /* If we don't need this section, strip it from the
10512 output file. This is mostly to handle .rela.bss and
10513 .rela.plt. We must create both sections in
10514 create_dynamic_sections, because they must be created
10515 before the linker maps input sections to output
10516 sections. The linker does that before
10517 adjust_dynamic_symbol is called, and it is that
10518 function which decides whether anything needs to go
10519 into these sections. */
10520 s
->flags
|= SEC_EXCLUDE
;
10524 if (bfd_is_abs_section (s
->output_section
))
10525 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10528 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10531 /* Allocate memory for the section contents. We use bfd_zalloc
10532 here in case unused entries are not reclaimed before the
10533 section's contents are written out. This should not happen,
10534 but this way if it does we get a R_PPC64_NONE reloc in .rela
10535 sections instead of garbage.
10536 We also rely on the section contents being zero when writing
10537 the GOT and .dynrelro. */
10538 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10539 if (s
->contents
== NULL
)
10543 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10545 if (!is_ppc64_elf (ibfd
))
10548 s
= ppc64_elf_tdata (ibfd
)->got
;
10549 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10552 s
->flags
|= SEC_EXCLUDE
;
10555 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10556 if (s
->contents
== NULL
)
10560 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10564 s
->flags
|= SEC_EXCLUDE
;
10567 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10568 if (s
->contents
== NULL
)
10571 s
->reloc_count
= 0;
10576 if (htab
->elf
.dynamic_sections_created
)
10580 /* Add some entries to the .dynamic section. We fill in the
10581 values later, in ppc64_elf_finish_dynamic_sections, but we
10582 must add the entries now so that we get the correct size for
10583 the .dynamic section. The DT_DEBUG entry is filled in by the
10584 dynamic linker and used by the debugger. */
10585 #define add_dynamic_entry(TAG, VAL) \
10586 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10588 if (bfd_link_executable (info
))
10590 if (!add_dynamic_entry (DT_DEBUG
, 0))
10594 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10596 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10597 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10598 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10599 || !add_dynamic_entry (DT_JMPREL
, 0)
10600 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10604 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10606 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10607 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10611 tls_opt
= (htab
->params
->tls_get_addr_opt
10612 && ((htab
->tls_get_addr_fd
!= NULL
10613 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
)
10614 || (htab
->tga_desc_fd
!= NULL
10615 && htab
->tga_desc_fd
->elf
.plt
.plist
!= NULL
)));
10616 if (tls_opt
|| !htab
->opd_abi
)
10618 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10624 if (!add_dynamic_entry (DT_RELA
, 0)
10625 || !add_dynamic_entry (DT_RELASZ
, 0)
10626 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10629 /* If any dynamic relocs apply to a read-only section,
10630 then we need a DT_TEXTREL entry. */
10631 if ((info
->flags
& DF_TEXTREL
) == 0)
10632 elf_link_hash_traverse (&htab
->elf
,
10633 _bfd_elf_maybe_set_textrel
, info
);
10635 if ((info
->flags
& DF_TEXTREL
) != 0)
10637 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10642 #undef add_dynamic_entry
10647 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10650 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10652 if (h
->plt
.plist
!= NULL
10654 && !h
->pointer_equality_needed
)
10657 return _bfd_elf_hash_symbol (h
);
10660 /* Determine the type of stub needed, if any, for a call. */
10662 static inline enum ppc_stub_main_type
10663 ppc_type_of_stub (asection
*input_sec
,
10664 const Elf_Internal_Rela
*rel
,
10665 struct ppc_link_hash_entry
**hash
,
10666 struct plt_entry
**plt_ent
,
10667 bfd_vma destination
,
10668 unsigned long local_off
)
10670 struct ppc_link_hash_entry
*h
= *hash
;
10672 bfd_vma branch_offset
;
10673 bfd_vma max_branch_offset
;
10674 enum elf_ppc64_reloc_type r_type
;
10678 struct plt_entry
*ent
;
10679 struct ppc_link_hash_entry
*fdh
= h
;
10681 && h
->oh
->is_func_descriptor
)
10683 fdh
= ppc_follow_link (h
->oh
);
10687 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10688 if (ent
->addend
== rel
->r_addend
10689 && ent
->plt
.offset
!= (bfd_vma
) -1)
10692 return ppc_stub_plt_call
;
10695 /* Here, we know we don't have a plt entry. If we don't have a
10696 either a defined function descriptor or a defined entry symbol
10697 in a regular object file, then it is pointless trying to make
10698 any other type of stub. */
10699 if (!is_static_defined (&fdh
->elf
)
10700 && !is_static_defined (&h
->elf
))
10701 return ppc_stub_none
;
10703 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10705 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10706 struct plt_entry
**local_plt
= (struct plt_entry
**)
10707 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10708 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10710 if (local_plt
[r_symndx
] != NULL
)
10712 struct plt_entry
*ent
;
10714 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10715 if (ent
->addend
== rel
->r_addend
10716 && ent
->plt
.offset
!= (bfd_vma
) -1)
10719 return ppc_stub_plt_call
;
10724 /* Determine where the call point is. */
10725 location
= (input_sec
->output_offset
10726 + input_sec
->output_section
->vma
10729 branch_offset
= destination
- location
;
10730 r_type
= ELF64_R_TYPE (rel
->r_info
);
10732 /* Determine if a long branch stub is needed. */
10733 max_branch_offset
= 1 << 25;
10734 if (r_type
== R_PPC64_REL14
10735 || r_type
== R_PPC64_REL14_BRTAKEN
10736 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10737 max_branch_offset
= 1 << 15;
10739 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10740 /* We need a stub. Figure out whether a long_branch or plt_branch
10741 is needed later. */
10742 return ppc_stub_long_branch
;
10744 return ppc_stub_none
;
10747 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
10748 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
10753 . lis %r12,xxx-1b@highest
10754 . ori %r12,%r12,xxx-1b@higher
10755 . sldi %r12,%r12,32
10756 . oris %r12,%r12,xxx-1b@high
10757 . ori %r12,%r12,xxx-1b@l
10758 . add/ldx %r12,%r11,%r12 */
10761 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bool load
)
10763 bfd_put_32 (abfd
, MFLR_R12
, p
);
10765 bfd_put_32 (abfd
, BCL_20_31
, p
);
10767 bfd_put_32 (abfd
, MFLR_R11
, p
);
10769 bfd_put_32 (abfd
, MTLR_R12
, p
);
10771 if (off
+ 0x8000 < 0x10000)
10774 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
10776 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
10779 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10781 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
10784 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
10786 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
10791 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10793 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
10798 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
10800 if (((off
>> 32) & 0xffff) != 0)
10802 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
10806 if (((off
>> 32) & 0xffffffffULL
) != 0)
10808 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
10811 if (PPC_HI (off
) != 0)
10813 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
10816 if (PPC_LO (off
) != 0)
10818 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
10822 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10824 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10830 static unsigned int
10831 size_offset (bfd_vma off
)
10834 if (off
+ 0x8000 < 0x10000)
10836 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10840 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10845 if (((off
>> 32) & 0xffff) != 0)
10848 if (((off
>> 32) & 0xffffffffULL
) != 0)
10850 if (PPC_HI (off
) != 0)
10852 if (PPC_LO (off
) != 0)
10859 static unsigned int
10860 num_relocs_for_offset (bfd_vma off
)
10862 unsigned int num_rel
;
10863 if (off
+ 0x8000 < 0x10000)
10865 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10870 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
10871 && ((off
>> 32) & 0xffff) != 0)
10873 if (PPC_HI (off
) != 0)
10875 if (PPC_LO (off
) != 0)
10881 static Elf_Internal_Rela
*
10882 emit_relocs_for_offset (struct bfd_link_info
*info
, Elf_Internal_Rela
*r
,
10883 bfd_vma roff
, bfd_vma targ
, bfd_vma off
)
10885 bfd_vma relative_targ
= targ
- (roff
- 8);
10886 if (bfd_big_endian (info
->output_bfd
))
10888 r
->r_offset
= roff
;
10889 r
->r_addend
= relative_targ
+ roff
;
10890 if (off
+ 0x8000 < 0x10000)
10891 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16
);
10892 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10894 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HA
);
10897 r
->r_offset
= roff
;
10898 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10899 r
->r_addend
= relative_targ
+ roff
;
10903 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10904 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10907 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHEST
);
10908 if (((off
>> 32) & 0xffff) != 0)
10912 r
->r_offset
= roff
;
10913 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10914 r
->r_addend
= relative_targ
+ roff
;
10917 if (((off
>> 32) & 0xffffffffULL
) != 0)
10919 if (PPC_HI (off
) != 0)
10923 r
->r_offset
= roff
;
10924 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGH
);
10925 r
->r_addend
= relative_targ
+ roff
;
10927 if (PPC_LO (off
) != 0)
10931 r
->r_offset
= roff
;
10932 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10933 r
->r_addend
= relative_targ
+ roff
;
10940 build_power10_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, int odd
,
10944 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10949 bfd_put_32 (abfd
, NOP
, p
);
10955 insn
= PADDI_R12_PC
;
10957 bfd_put_32 (abfd
, insn
>> 32, p
);
10959 bfd_put_32 (abfd
, insn
, p
);
10961 /* The minimum value for paddi is -0x200000000. The minimum value
10962 for li is -0x8000, which when shifted by 34 and added gives a
10963 minimum value of -0x2000200000000. The maximum value is
10964 0x1ffffffff+0x7fff<<34 which is 0x2000200000000-1. */
10965 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10968 bfd_put_32 (abfd
, LI_R11_0
| (HA34 (off
) & 0xffff), p
);
10972 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10975 insn
= PADDI_R12_PC
| D34 (off
);
10976 bfd_put_32 (abfd
, insn
>> 32, p
);
10978 bfd_put_32 (abfd
, insn
, p
);
10982 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10986 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10988 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10993 bfd_put_32 (abfd
, LIS_R11
| ((HA34 (off
) >> 16) & 0x3fff), p
);
10995 bfd_put_32 (abfd
, ORI_R11_R11_0
| (HA34 (off
) & 0xffff), p
);
10999 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
11002 insn
= PADDI_R12_PC
| D34 (off
);
11003 bfd_put_32 (abfd
, insn
>> 32, p
);
11005 bfd_put_32 (abfd
, insn
, p
);
11009 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
11013 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
11015 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
11021 static unsigned int
11022 size_power10_offset (bfd_vma off
, int odd
)
11024 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
11026 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
11032 static unsigned int
11033 num_relocs_for_power10_offset (bfd_vma off
, int odd
)
11035 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
11037 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
11043 static Elf_Internal_Rela
*
11044 emit_relocs_for_power10_offset (struct bfd_link_info
*info
,
11045 Elf_Internal_Rela
*r
, bfd_vma roff
,
11046 bfd_vma targ
, bfd_vma off
, int odd
)
11048 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
11050 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
11052 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
11053 r
->r_offset
= roff
+ d_offset
;
11054 r
->r_addend
= targ
+ 8 - odd
- d_offset
;
11055 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
11061 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
11062 r
->r_offset
= roff
+ d_offset
;
11063 r
->r_addend
= targ
+ 8 + odd
- d_offset
;
11064 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHESTA34
);
11067 r
->r_offset
= roff
+ d_offset
;
11068 r
->r_addend
= targ
+ 4 + odd
- d_offset
;
11069 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
11073 r
->r_offset
= roff
;
11074 r
->r_addend
= targ
;
11075 r
->r_info
= ELF64_R_INFO (0, R_PPC64_PCREL34
);
11079 /* Emit .eh_frame opcode to advance pc by DELTA. */
11082 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
11086 *eh
++ = DW_CFA_advance_loc
+ delta
;
11087 else if (delta
< 256)
11089 *eh
++ = DW_CFA_advance_loc1
;
11092 else if (delta
< 65536)
11094 *eh
++ = DW_CFA_advance_loc2
;
11095 bfd_put_16 (abfd
, delta
, eh
);
11100 *eh
++ = DW_CFA_advance_loc4
;
11101 bfd_put_32 (abfd
, delta
, eh
);
11107 /* Size of required .eh_frame opcode to advance pc by DELTA. */
11109 static unsigned int
11110 eh_advance_size (unsigned int delta
)
11112 if (delta
< 64 * 4)
11113 /* DW_CFA_advance_loc+[1..63]. */
11115 if (delta
< 256 * 4)
11116 /* DW_CFA_advance_loc1, byte. */
11118 if (delta
< 65536 * 4)
11119 /* DW_CFA_advance_loc2, 2 bytes. */
11121 /* DW_CFA_advance_loc4, 4 bytes. */
11125 /* With power7 weakly ordered memory model, it is possible for ld.so
11126 to update a plt entry in one thread and have another thread see a
11127 stale zero toc entry. To avoid this we need some sort of acquire
11128 barrier in the call stub. One solution is to make the load of the
11129 toc word seem to appear to depend on the load of the function entry
11130 word. Another solution is to test for r2 being zero, and branch to
11131 the appropriate glink entry if so.
11133 . fake dep barrier compare
11134 . ld 12,xxx(2) ld 12,xxx(2)
11135 . mtctr 12 mtctr 12
11136 . xor 11,12,12 ld 2,xxx+8(2)
11137 . add 2,2,11 cmpldi 2,0
11138 . ld 2,xxx+8(2) bnectr+
11139 . bctr b <glink_entry>
11141 The solution involving the compare turns out to be faster, so
11142 that's what we use unless the branch won't reach. */
11144 #define ALWAYS_USE_FAKE_DEP 0
11145 #define ALWAYS_EMIT_R2SAVE 0
11147 static inline unsigned int
11148 plt_stub_size (struct ppc_link_hash_table
*htab
,
11149 struct ppc_stub_hash_entry
*stub_entry
,
11155 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11157 size
= 8 + size_power10_offset (off
, odd
);
11158 if (stub_entry
->type
.r2save
)
11161 else if (stub_entry
->type
.sub
== ppc_stub_p9notoc
)
11163 size
= 8 + size_offset (off
- 8);
11164 if (stub_entry
->type
.r2save
)
11170 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11172 if (PPC_HA (off
) != 0)
11177 if (htab
->params
->plt_static_chain
)
11179 if (htab
->params
->plt_thread_safe
11180 && htab
->elf
.dynamic_sections_created
11181 && stub_entry
->h
!= NULL
11182 && stub_entry
->h
->elf
.dynindx
!= -1)
11184 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
)
11189 if (stub_entry
->h
!= NULL
11190 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11191 && htab
->params
->tls_get_addr_opt
)
11193 if (!htab
->params
->no_tls_get_addr_regsave
)
11196 if (stub_entry
->type
.r2save
)
11202 if (stub_entry
->type
.r2save
)
11209 /* Depending on the sign of plt_stub_align:
11210 If positive, return the padding to align to a 2**plt_stub_align
11212 If negative, if this stub would cross fewer 2**plt_stub_align
11213 boundaries if we align, then return the padding needed to do so. */
11215 static inline unsigned int
11216 plt_stub_pad (int plt_stub_align
,
11218 unsigned int stub_size
)
11220 unsigned int stub_align
;
11222 if (plt_stub_align
>= 0)
11223 stub_align
= 1u << plt_stub_align
;
11226 stub_align
= 1u << -plt_stub_align
;
11227 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
11228 <= ((stub_size
- 1) & -stub_align
))
11231 return stub_align
- 1 - ((stub_off
- 1) & (stub_align
- 1));
11234 /* Build a toc using .plt call stub. */
11236 static inline bfd_byte
*
11237 build_plt_stub (struct ppc_link_hash_table
*htab
,
11238 struct ppc_stub_hash_entry
*stub_entry
,
11239 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
11241 bfd
*obfd
= htab
->params
->stub_bfd
;
11242 bool plt_load_toc
= htab
->opd_abi
;
11243 bool plt_static_chain
= htab
->params
->plt_static_chain
;
11244 bool plt_thread_safe
= (htab
->params
->plt_thread_safe
11245 && htab
->elf
.dynamic_sections_created
11246 && stub_entry
->h
!= NULL
11247 && stub_entry
->h
->elf
.dynindx
!= -1);
11248 bool use_fake_dep
= plt_thread_safe
;
11249 bfd_vma cmp_branch_off
= 0;
11251 if (!ALWAYS_USE_FAKE_DEP
11254 && !(stub_entry
->h
!= NULL
11255 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11256 && htab
->params
->tls_get_addr_opt
))
11258 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11259 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
11260 / PLT_ENTRY_SIZE (htab
));
11261 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
11264 if (pltindex
> 32768)
11265 glinkoff
+= (pltindex
- 32768) * 4;
11267 + htab
->glink
->output_offset
11268 + htab
->glink
->output_section
->vma
);
11269 from
= (p
- stub_entry
->group
->stub_sec
->contents
11270 + 4 * (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11271 + 4 * (PPC_HA (offset
) != 0)
11272 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
11273 != PPC_HA (offset
))
11274 + 4 * (plt_static_chain
!= 0)
11276 + stub_entry
->group
->stub_sec
->output_offset
11277 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11278 cmp_branch_off
= to
- from
;
11279 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
11282 if (PPC_HA (offset
) != 0)
11286 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11287 r
[0].r_offset
+= 4;
11288 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11289 r
[1].r_offset
= r
[0].r_offset
+ 4;
11290 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11291 r
[1].r_addend
= r
[0].r_addend
;
11294 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11296 r
[2].r_offset
= r
[1].r_offset
+ 4;
11297 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
11298 r
[2].r_addend
= r
[0].r_addend
;
11302 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
11303 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11304 r
[2].r_addend
= r
[0].r_addend
+ 8;
11305 if (plt_static_chain
)
11307 r
[3].r_offset
= r
[2].r_offset
+ 4;
11308 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11309 r
[3].r_addend
= r
[0].r_addend
+ 16;
11314 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11315 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11318 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
11319 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
11323 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
11324 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
11327 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11329 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
11332 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11337 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
11338 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
11340 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
11341 if (plt_static_chain
)
11342 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
11349 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11350 r
[0].r_offset
+= 4;
11351 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11354 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11356 r
[1].r_offset
= r
[0].r_offset
+ 4;
11357 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
11358 r
[1].r_addend
= r
[0].r_addend
;
11362 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
11363 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11364 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
11365 if (plt_static_chain
)
11367 r
[2].r_offset
= r
[1].r_offset
+ 4;
11368 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11369 r
[2].r_addend
= r
[0].r_addend
+ 8;
11374 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11375 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11376 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
11378 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11380 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
11383 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11388 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
11389 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
11391 if (plt_static_chain
)
11392 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
11393 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
11396 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
11398 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
11399 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
11400 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
11403 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
11407 /* Build a special .plt call stub for __tls_get_addr. */
11409 #define LD_R0_0R3 0xe8030000
11410 #define LD_R12_0R3 0xe9830000
11411 #define MR_R0_R3 0x7c601b78
11412 #define CMPDI_R0_0 0x2c200000
11413 #define ADD_R3_R12_R13 0x7c6c6a14
11414 #define BEQLR 0x4d820020
11415 #define MR_R3_R0 0x7c030378
11416 #define BCTRL 0x4e800421
11419 build_tls_get_addr_head (struct ppc_link_hash_table
*htab
,
11420 struct ppc_stub_hash_entry
*stub_entry
,
11423 bfd
*obfd
= htab
->params
->stub_bfd
;
11425 bfd_put_32 (obfd
, LD_R0_0R3
+ 0, p
), p
+= 4;
11426 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
11427 bfd_put_32 (obfd
, CMPDI_R0_0
, p
), p
+= 4;
11428 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
11429 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
11430 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
11431 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
11433 if (!htab
->params
->no_tls_get_addr_regsave
)
11434 p
= tls_get_addr_prologue (obfd
, p
, htab
);
11435 else if (stub_entry
->type
.r2save
)
11437 bfd_put_32 (obfd
, MFLR_R0
, p
);
11439 bfd_put_32 (obfd
, STD_R0_0R1
+ STK_LINKER (htab
), p
);
11446 build_tls_get_addr_tail (struct ppc_link_hash_table
*htab
,
11447 struct ppc_stub_hash_entry
*stub_entry
,
11451 bfd
*obfd
= htab
->params
->stub_bfd
;
11453 if (!htab
->params
->no_tls_get_addr_regsave
)
11455 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11457 if (stub_entry
->type
.r2save
)
11459 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11462 p
= tls_get_addr_epilogue (obfd
, p
, htab
);
11464 else if (stub_entry
->type
.r2save
)
11466 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11468 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11470 bfd_put_32 (obfd
, LD_R0_0R1
+ STK_LINKER (htab
), p
);
11472 bfd_put_32 (obfd
, MTLR_R0
, p
);
11474 bfd_put_32 (obfd
, BLR
, p
);
11478 if (htab
->glink_eh_frame
!= NULL
11479 && htab
->glink_eh_frame
->size
!= 0)
11481 bfd_byte
*base
, *eh
;
11483 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
11484 eh
= base
+ stub_entry
->group
->eh_size
;
11486 if (!htab
->params
->no_tls_get_addr_regsave
)
11488 unsigned int cfa_updt
, delta
, i
;
11490 /* After the bctrl, lr has been modified so we need to emit
11491 .eh_frame info saying the return address is on the stack. In
11492 fact we must put the EH info at or before the call rather
11493 than after it, because the EH info for a call needs to be
11494 specified by that point.
11495 See libgcc/unwind-dw2.c execute_cfa_program.
11496 Any stack pointer update must be described immediately after
11497 the instruction making the change, and since the stdu occurs
11498 after saving regs we put all the reg saves and the cfa
11500 cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
11501 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
11502 stub_entry
->group
->lr_restore
11503 = stub_entry
->stub_offset
+ (p
- loc
) - 4;
11504 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11505 *eh
++ = DW_CFA_def_cfa_offset
;
11513 *eh
++ = DW_CFA_offset_extended_sf
;
11515 *eh
++ = (-16 / 8) & 0x7f;
11516 for (i
= 4; i
< 12; i
++)
11518 *eh
++ = DW_CFA_offset
+ i
;
11519 *eh
++ = (htab
->opd_abi
? 13 : 12) - i
;
11521 *eh
++ = (DW_CFA_advance_loc
11522 + (stub_entry
->group
->lr_restore
- 8 - cfa_updt
) / 4);
11523 *eh
++ = DW_CFA_def_cfa_offset
;
11525 for (i
= 4; i
< 12; i
++)
11526 *eh
++ = DW_CFA_restore
+ i
;
11527 *eh
++ = DW_CFA_advance_loc
+ 2;
11528 *eh
++ = DW_CFA_restore_extended
;
11530 stub_entry
->group
->eh_size
= eh
- base
;
11532 else if (stub_entry
->type
.r2save
)
11534 unsigned int lr_used
, delta
;
11536 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
11537 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11538 stub_entry
->group
->lr_restore
= lr_used
+ 16;
11539 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11540 *eh
++ = DW_CFA_offset_extended_sf
;
11542 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
11543 *eh
++ = DW_CFA_advance_loc
+ 4;
11544 *eh
++ = DW_CFA_restore_extended
;
11546 stub_entry
->group
->eh_size
= eh
- base
;
11552 static Elf_Internal_Rela
*
11553 get_relocs (asection
*sec
, int count
)
11555 Elf_Internal_Rela
*relocs
;
11556 struct bfd_elf_section_data
*elfsec_data
;
11558 elfsec_data
= elf_section_data (sec
);
11559 relocs
= elfsec_data
->relocs
;
11560 if (relocs
== NULL
)
11562 bfd_size_type relsize
;
11563 relsize
= sec
->reloc_count
* sizeof (*relocs
);
11564 relocs
= bfd_alloc (sec
->owner
, relsize
);
11565 if (relocs
== NULL
)
11567 elfsec_data
->relocs
= relocs
;
11568 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
11569 sizeof (Elf_Internal_Shdr
));
11570 if (elfsec_data
->rela
.hdr
== NULL
)
11572 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
11573 * sizeof (Elf64_External_Rela
));
11574 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
11575 sec
->reloc_count
= 0;
11577 relocs
+= sec
->reloc_count
;
11578 sec
->reloc_count
+= count
;
11583 swap_reloc_out (bfd
*obfd
, Elf_Internal_Rela
*rel
, bfd_byte
*loc
, asection
*s
)
11585 if ((size_t) (loc
- s
->contents
) >= s
->size
)
11587 bfd_elf64_swap_reloca_out (obfd
, rel
, loc
);
11592 count_and_swap_reloc_out (bfd
*obfd
, Elf_Internal_Rela
*rel
, asection
*s
)
11594 bfd_byte
*loc
= s
->contents
;
11595 loc
+= s
->reloc_count
++ * sizeof (Elf64_External_Rela
);
11596 return swap_reloc_out (obfd
, rel
, loc
, s
);
11600 /* Convert the relocs R[0] thru R[-NUM_REL+1], which are all no-symbol
11601 forms, to the equivalent relocs against the global symbol given by
11605 use_global_in_relocs (struct ppc_link_hash_table
*htab
,
11606 struct ppc_stub_hash_entry
*stub_entry
,
11607 Elf_Internal_Rela
*r
, unsigned int num_rel
)
11609 struct elf_link_hash_entry
**hashes
;
11610 unsigned long symndx
;
11611 struct ppc_link_hash_entry
*h
;
11614 /* Relocs are always against symbols in their own object file. Fake
11615 up global sym hashes for the stub bfd (which has no symbols). */
11616 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
11617 if (hashes
== NULL
)
11619 bfd_size_type hsize
;
11621 /* When called the first time, stub_globals will contain the
11622 total number of symbols seen during stub sizing. After
11623 allocating, stub_globals is used as an index to fill the
11625 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
11626 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
11627 if (hashes
== NULL
)
11629 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
11630 htab
->stub_globals
= 1;
11632 symndx
= htab
->stub_globals
++;
11634 hashes
[symndx
] = &h
->elf
;
11635 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
11636 h
= ppc_follow_link (h
->oh
);
11637 BFD_ASSERT (h
->elf
.root
.type
== bfd_link_hash_defined
11638 || h
->elf
.root
.type
== bfd_link_hash_defweak
);
11639 symval
= defined_sym_val (&h
->elf
);
11640 while (num_rel
-- != 0)
11642 r
->r_info
= ELF64_R_INFO (symndx
, ELF64_R_TYPE (r
->r_info
));
11643 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11645 /* H is an opd symbol. The addend must be zero, and the
11646 branch reloc is the only one we can convert. */
11651 r
->r_addend
-= symval
;
11658 get_r2off (struct bfd_link_info
*info
,
11659 struct ppc_stub_hash_entry
*stub_entry
)
11661 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11662 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
11666 /* Support linking -R objects. Get the toc pointer from the
11669 if (!htab
->opd_abi
)
11671 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
11672 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
11674 if (strcmp (opd
->name
, ".opd") != 0
11675 || opd
->reloc_count
!= 0)
11677 info
->callbacks
->einfo
11678 (_("%P: cannot find opd entry toc for `%pT'\n"),
11679 stub_entry
->h
->elf
.root
.root
.string
);
11680 bfd_set_error (bfd_error_bad_value
);
11681 return (bfd_vma
) -1;
11683 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
11684 return (bfd_vma
) -1;
11685 r2off
= bfd_get_64 (opd
->owner
, buf
);
11686 r2off
-= elf_gp (info
->output_bfd
);
11688 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
11695 dump_stub (const char *header
,
11696 struct ppc_stub_hash_entry
*stub_entry
,
11699 const char *t1
, *t2
, *t3
;
11700 switch (stub_entry
->type
.main
)
11702 case ppc_stub_none
: t1
= "none"; break;
11703 case ppc_stub_long_branch
: t1
= "long_branch"; break;
11704 case ppc_stub_plt_branch
: t1
= "plt_branch"; break;
11705 case ppc_stub_plt_call
: t1
= "plt_call"; break;
11706 case ppc_stub_global_entry
: t1
= "global_entry"; break;
11707 case ppc_stub_save_res
: t1
= "save_res"; break;
11708 default: t1
= "???"; break;
11710 switch (stub_entry
->type
.sub
)
11712 case ppc_stub_toc
: t2
= "toc"; break;
11713 case ppc_stub_notoc
: t2
= "notoc"; break;
11714 case ppc_stub_p9notoc
: t2
= "p9notoc"; break;
11715 default: t2
= "???"; break;
11717 t3
= stub_entry
->type
.r2save
? "r2save" : "";
11718 fprintf (stderr
, "%s id = %u type = %s:%s:%s\n",
11719 header
, stub_entry
->id
, t1
, t2
, t3
);
11720 fprintf (stderr
, "name = %s\n", stub_entry
->root
.string
);
11721 fprintf (stderr
, "offset = 0x%" PRIx64
":", stub_entry
->stub_offset
);
11722 for (size_t i
= stub_entry
->stub_offset
; i
< end_offset
; i
+= 4)
11724 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
11725 uint32_t *p
= (uint32_t *) (stub_sec
->contents
+ i
);
11726 fprintf (stderr
, " %08x", (uint32_t) bfd_get_32 (stub_sec
->owner
, p
));
11728 fprintf (stderr
, "\n");
11732 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11734 struct ppc_stub_hash_entry
*stub_entry
;
11735 struct ppc_branch_hash_entry
*br_entry
;
11736 struct bfd_link_info
*info
;
11737 struct ppc_link_hash_table
*htab
;
11740 bfd_byte
*p
, *relp
;
11742 Elf_Internal_Rela
*r
;
11748 /* Massage our args to the form they really have. */
11749 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11752 htab
= ppc_hash_table (info
);
11756 struct _ppc64_elf_section_data
*esd
11757 = ppc64_elf_section_data (stub_entry
->group
->stub_sec
);
11759 if (stub_entry
->id
!= htab
->stub_id
11760 || (stub_entry
->type
.main
!= ppc_stub_save_res
11761 && stub_entry
->stub_offset
< stub_entry
->group
->stub_sec
->size
))
11764 if (stub_entry
->id
!= htab
->stub_id
)
11765 fprintf (stderr
, "Expected id %u, got %u\n",
11766 htab
->stub_id
, stub_entry
->id
);
11767 if (stub_entry
->stub_offset
< stub_entry
->group
->stub_sec
->size
)
11768 fprintf (stderr
, "Expected offset >= %" PRIx64
", got %"
11769 PRIx64
"\n", stub_entry
->group
->stub_sec
->size
,
11770 stub_entry
->stub_offset
);
11771 if (esd
->sec_type
== sec_stub
)
11772 dump_stub ("Previous:", esd
->u
.last_ent
, stub_entry
->stub_offset
);
11773 dump_stub ("Current:", stub_entry
, 0);
11775 if (esd
->sec_type
== sec_normal
)
11776 esd
->sec_type
= sec_stub
;
11777 if (esd
->sec_type
== sec_stub
)
11778 esd
->u
.last_ent
= stub_entry
;
11779 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
11781 htab
->stub_count
[stub_entry
->type
.main
- 1] += 1;
11782 if (stub_entry
->type
.main
== ppc_stub_long_branch
11783 && stub_entry
->type
.sub
== ppc_stub_toc
)
11785 /* Branches are relative. This is where we are going to. */
11786 targ
= (stub_entry
->target_value
11787 + stub_entry
->target_section
->output_offset
11788 + stub_entry
->target_section
->output_section
->vma
);
11789 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11791 /* And this is where we are coming from. */
11792 off
= (stub_entry
->stub_offset
11793 + stub_entry
->group
->stub_sec
->output_offset
11794 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11798 obfd
= htab
->params
->stub_bfd
;
11799 if (stub_entry
->type
.r2save
)
11801 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11803 if (r2off
== (bfd_vma
) -1)
11805 htab
->stub_error
= true;
11808 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11810 if (PPC_HA (r2off
) != 0)
11812 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11815 if (PPC_LO (r2off
) != 0)
11817 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11822 bfd_put_32 (obfd
, B_DOT
| (off
& 0x3fffffc), p
);
11825 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11828 (_("long branch stub `%s' offset overflow"),
11829 stub_entry
->root
.string
);
11830 htab
->stub_error
= true;
11834 if (info
->emitrelocations
)
11836 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11839 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11840 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11841 r
->r_addend
= targ
;
11842 if (stub_entry
->h
!= NULL
11843 && !use_global_in_relocs (htab
, stub_entry
, r
, 1))
11847 else if (stub_entry
->type
.main
== ppc_stub_plt_branch
11848 && stub_entry
->type
.sub
== ppc_stub_toc
)
11850 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11851 stub_entry
->root
.string
+ 9,
11853 if (br_entry
== NULL
)
11855 _bfd_error_handler (_("can't find branch stub `%s'"),
11856 stub_entry
->root
.string
);
11857 htab
->stub_error
= true;
11861 targ
= (stub_entry
->target_value
11862 + stub_entry
->target_section
->output_offset
11863 + stub_entry
->target_section
->output_section
->vma
);
11864 if (!stub_entry
->type
.r2save
)
11865 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11867 bfd_put_64 (htab
->brlt
->owner
, targ
,
11868 htab
->brlt
->contents
+ br_entry
->offset
);
11870 if (br_entry
->iter
== htab
->stub_iteration
)
11872 br_entry
->iter
= 0;
11874 if (htab
->relbrlt
!= NULL
&& !info
->enable_dt_relr
)
11876 /* Create a reloc for the branch lookup table entry. */
11877 Elf_Internal_Rela rela
;
11879 rela
.r_offset
= (br_entry
->offset
11880 + htab
->brlt
->output_offset
11881 + htab
->brlt
->output_section
->vma
);
11882 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11883 rela
.r_addend
= targ
;
11885 BFD_ASSERT (count_and_swap_reloc_out (htab
->relbrlt
->owner
, &rela
,
11888 else if (info
->emitrelocations
)
11890 r
= get_relocs (htab
->brlt
, 1);
11893 /* brlt, being SEC_LINKER_CREATED does not go through the
11894 normal reloc processing. Symbols and offsets are not
11895 translated from input file to output file form, so
11896 set up the offset per the output file. */
11897 r
->r_offset
= (br_entry
->offset
11898 + htab
->brlt
->output_offset
11899 + htab
->brlt
->output_section
->vma
);
11900 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11901 r
->r_addend
= targ
;
11905 targ
= (br_entry
->offset
11906 + htab
->brlt
->output_offset
11907 + htab
->brlt
->output_section
->vma
);
11909 off
= (elf_gp (info
->output_bfd
)
11910 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11913 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11915 info
->callbacks
->einfo
11916 (_("%P: linkage table error against `%pT'\n"),
11917 stub_entry
->root
.string
);
11918 bfd_set_error (bfd_error_bad_value
);
11919 htab
->stub_error
= true;
11923 if (info
->emitrelocations
)
11925 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11928 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11929 if (bfd_big_endian (info
->output_bfd
))
11930 r
[0].r_offset
+= 2;
11931 if (stub_entry
->type
.r2save
)
11932 r
[0].r_offset
+= 4;
11933 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11934 r
[0].r_addend
= targ
;
11935 if (PPC_HA (off
) != 0)
11937 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11938 r
[1].r_offset
= r
[0].r_offset
+ 4;
11939 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11940 r
[1].r_addend
= r
[0].r_addend
;
11945 obfd
= htab
->params
->stub_bfd
;
11946 if (!stub_entry
->type
.r2save
)
11948 if (PPC_HA (off
) != 0)
11950 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11952 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11955 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11959 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11961 if (r2off
== (bfd_vma
) -1)
11963 htab
->stub_error
= true;
11967 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11969 if (PPC_HA (off
) != 0)
11971 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11973 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11976 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11978 if (PPC_HA (r2off
) != 0)
11981 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11983 if (PPC_LO (r2off
) != 0)
11986 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11990 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11992 bfd_put_32 (obfd
, BCTR
, p
);
11995 else if (stub_entry
->type
.sub
>= ppc_stub_notoc
)
11997 bool is_plt
= stub_entry
->type
.main
== ppc_stub_plt_call
;
11999 off
= (stub_entry
->stub_offset
12000 + stub_entry
->group
->stub_sec
->output_offset
12001 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12002 obfd
= htab
->params
->stub_bfd
;
12004 && stub_entry
->h
!= NULL
12005 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12006 && htab
->params
->tls_get_addr_opt
);
12009 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
12012 if (stub_entry
->type
.r2save
)
12015 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
12020 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12021 if (targ
>= (bfd_vma
) -2)
12024 plt
= htab
->elf
.splt
;
12025 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12027 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12028 plt
= htab
->elf
.iplt
;
12030 plt
= htab
->pltlocal
;
12032 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12035 targ
= (stub_entry
->target_value
12036 + stub_entry
->target_section
->output_offset
12037 + stub_entry
->target_section
->output_section
->vma
);
12043 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12044 p
= build_power10_offset (obfd
, p
, off
, odd
, is_plt
);
12047 if (htab
->glink_eh_frame
!= NULL
12048 && htab
->glink_eh_frame
->size
!= 0)
12050 bfd_byte
*base
, *eh
;
12051 unsigned int lr_used
, delta
;
12053 base
= (htab
->glink_eh_frame
->contents
12054 + stub_entry
->group
->eh_base
+ 17);
12055 eh
= base
+ stub_entry
->group
->eh_size
;
12056 lr_used
= stub_entry
->stub_offset
+ (p
- loc
) + 8;
12057 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12058 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12059 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
12060 *eh
++ = DW_CFA_register
;
12063 *eh
++ = DW_CFA_advance_loc
+ 2;
12064 *eh
++ = DW_CFA_restore_extended
;
12066 stub_entry
->group
->eh_size
= eh
- base
;
12069 /* The notoc stubs calculate their target (either a PLT entry or
12070 the global entry point of a function) relative to the PC
12071 returned by the "bcl" two instructions past the start of the
12072 sequence emitted by build_offset. The offset is therefore 8
12073 less than calculated from the start of the sequence. */
12075 p
= build_offset (obfd
, p
, off
, is_plt
);
12078 if (stub_entry
->type
.main
== ppc_stub_long_branch
)
12082 from
= (stub_entry
->stub_offset
12083 + stub_entry
->group
->stub_sec
->output_offset
12084 + stub_entry
->group
->stub_sec
->output_section
->vma
12086 bfd_put_32 (obfd
, B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
12090 bfd_put_32 (obfd
, MTCTR_R12
, p
);
12092 bfd_put_32 (obfd
, BCTR
, p
);
12097 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
12099 if (info
->emitrelocations
)
12101 bfd_vma roff
= relp
- stub_entry
->group
->stub_sec
->contents
;
12102 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12103 num_rel
+= num_relocs_for_power10_offset (off
, odd
);
12106 num_rel
+= num_relocs_for_offset (off
);
12109 r
= get_relocs (stub_entry
->group
->stub_sec
, num_rel
);
12112 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12113 r
= emit_relocs_for_power10_offset (info
, r
, roff
, targ
, off
, odd
);
12115 r
= emit_relocs_for_offset (info
, r
, roff
, targ
, off
);
12116 if (stub_entry
->type
.main
== ppc_stub_long_branch
)
12119 roff
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
12120 r
->r_offset
= roff
;
12121 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
12122 r
->r_addend
= targ
;
12123 if (stub_entry
->h
!= NULL
12124 && !use_global_in_relocs (htab
, stub_entry
, r
, num_rel
))
12129 else if (stub_entry
->type
.main
== ppc_stub_plt_call
)
12131 if (stub_entry
->h
!= NULL
12132 && stub_entry
->h
->is_func_descriptor
12133 && stub_entry
->h
->oh
!= NULL
)
12135 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
12137 /* If the old-ABI "dot-symbol" is undefined make it weak so
12138 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
12139 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
12140 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
12141 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
12142 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
12145 /* Now build the stub. */
12146 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12147 if (targ
>= (bfd_vma
) -2)
12150 plt
= htab
->elf
.splt
;
12151 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12153 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12154 plt
= htab
->elf
.iplt
;
12156 plt
= htab
->pltlocal
;
12158 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12160 off
= (elf_gp (info
->output_bfd
)
12161 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12164 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
12166 info
->callbacks
->einfo
12167 /* xgettext:c-format */
12168 (_("%P: linkage table error against `%pT'\n"),
12169 stub_entry
->h
!= NULL
12170 ? stub_entry
->h
->elf
.root
.root
.string
12172 bfd_set_error (bfd_error_bad_value
);
12173 htab
->stub_error
= true;
12178 if (info
->emitrelocations
)
12180 r
= get_relocs (stub_entry
->group
->stub_sec
,
12181 ((PPC_HA (off
) != 0)
12183 ? 2 + (htab
->params
->plt_static_chain
12184 && PPC_HA (off
+ 16) == PPC_HA (off
))
12188 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
12189 if (bfd_big_endian (info
->output_bfd
))
12190 r
[0].r_offset
+= 2;
12191 r
[0].r_addend
= targ
;
12194 obfd
= htab
->params
->stub_bfd
;
12195 is_tga
= (stub_entry
->h
!= NULL
12196 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12197 && htab
->params
->tls_get_addr_opt
);
12200 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
12202 r
[0].r_offset
+= p
- loc
;
12204 p
= build_plt_stub (htab
, stub_entry
, p
, off
, r
);
12206 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
12208 else if (stub_entry
->type
.main
== ppc_stub_save_res
)
12216 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
12218 if (htab
->params
->emit_stub_syms
)
12220 struct elf_link_hash_entry
*h
;
12223 const char *const stub_str
[] = { "long_branch",
12227 len1
= strlen (stub_str
[stub_entry
->type
.main
- 1]);
12228 len2
= strlen (stub_entry
->root
.string
);
12229 name
= bfd_malloc (len1
+ len2
+ 2);
12232 memcpy (name
, stub_entry
->root
.string
, 9);
12233 memcpy (name
+ 9, stub_str
[stub_entry
->type
.main
- 1], len1
);
12234 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
12235 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
12238 if (h
->root
.type
== bfd_link_hash_new
)
12240 h
->root
.type
= bfd_link_hash_defined
;
12241 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
12242 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
12243 h
->ref_regular
= 1;
12244 h
->def_regular
= 1;
12245 h
->ref_regular_nonweak
= 1;
12246 h
->forced_local
= 1;
12248 h
->root
.linker_def
= 1;
12255 /* As above, but don't actually build the stub. Just bump offset so
12256 we know stub section sizes, and select plt_branch stubs where
12257 long_branch stubs won't do. */
12260 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
12262 struct ppc_stub_hash_entry
*stub_entry
;
12263 struct bfd_link_info
*info
;
12264 struct ppc_link_hash_table
*htab
;
12266 bfd_vma targ
, off
, r2off
;
12267 unsigned int size
, pad
, extra
, lr_used
, delta
, odd
;
12268 bfd_vma stub_offset
;
12270 /* Massage our args to the form they really have. */
12271 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
12274 htab
= ppc_hash_table (info
);
12278 /* Fail if the target section could not be assigned to an output
12279 section. The user should fix his linker script. */
12280 if (stub_entry
->target_section
!= NULL
12281 && stub_entry
->target_section
->output_section
== NULL
12282 && info
->non_contiguous_regions
)
12283 info
->callbacks
->einfo (_("%F%P: Could not assign `%pA' to an output section. "
12284 "Retry without --enable-non-contiguous-regions.\n"),
12285 stub_entry
->target_section
);
12287 /* Same for the group. */
12288 if (stub_entry
->group
->stub_sec
!= NULL
12289 && stub_entry
->group
->stub_sec
->output_section
== NULL
12290 && info
->non_contiguous_regions
)
12291 info
->callbacks
->einfo (_("%F%P: Could not assign `%pA' to an output section. "
12292 "Retry without --enable-non-contiguous-regions.\n"),
12293 stub_entry
->group
->stub_sec
);
12295 /* Make a note of the offset within the stubs for this entry. */
12296 stub_offset
= stub_entry
->group
->stub_sec
->size
;
12297 if (htab
->stub_iteration
> STUB_SHRINK_ITER
12298 && stub_entry
->stub_offset
> stub_offset
)
12299 stub_offset
= stub_entry
->stub_offset
;
12300 stub_entry
->id
= ++htab
->stub_id
;
12302 if (stub_entry
->h
!= NULL
12303 && stub_entry
->h
->save_res
12304 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
12305 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
12307 /* Don't make stubs to out-of-line register save/restore
12308 functions. Instead, emit copies of the functions. */
12309 stub_entry
->group
->needs_save_res
= 1;
12310 stub_entry
->type
.main
= ppc_stub_save_res
;
12311 stub_entry
->type
.sub
= ppc_stub_toc
;
12312 stub_entry
->type
.r2save
= 0;
12316 if (stub_entry
->type
.main
== ppc_stub_plt_branch
)
12318 /* Reset the stub type from the plt branch variant in case we now
12319 can reach with a shorter stub. */
12320 stub_entry
->type
.main
= ppc_stub_long_branch
;
12323 if (stub_entry
->type
.main
== ppc_stub_long_branch
12324 && stub_entry
->type
.sub
== ppc_stub_toc
)
12326 targ
= (stub_entry
->target_value
12327 + stub_entry
->target_section
->output_offset
12328 + stub_entry
->target_section
->output_section
->vma
);
12329 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
12331 + stub_entry
->group
->stub_sec
->output_offset
12332 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12336 if (stub_entry
->type
.r2save
)
12338 r2off
= get_r2off (info
, stub_entry
);
12339 if (r2off
== (bfd_vma
) -1)
12341 htab
->stub_error
= true;
12345 if (PPC_HA (r2off
) != 0)
12347 if (PPC_LO (r2off
) != 0)
12353 /* If the branch offset is too big, use a ppc_stub_plt_branch.
12354 Do the same for -R objects without function descriptors. */
12355 if ((stub_entry
->type
.r2save
12357 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
12358 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12360 struct ppc_branch_hash_entry
*br_entry
;
12362 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
12363 stub_entry
->root
.string
+ 9,
12365 if (br_entry
== NULL
)
12367 _bfd_error_handler (_("can't build branch stub `%s'"),
12368 stub_entry
->root
.string
);
12369 htab
->stub_error
= true;
12373 if (br_entry
->iter
!= htab
->stub_iteration
)
12375 br_entry
->iter
= htab
->stub_iteration
;
12376 br_entry
->offset
= htab
->brlt
->size
;
12377 htab
->brlt
->size
+= 8;
12379 if (htab
->relbrlt
!= NULL
&& !info
->enable_dt_relr
)
12380 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
12381 else if (info
->emitrelocations
)
12383 htab
->brlt
->reloc_count
+= 1;
12384 htab
->brlt
->flags
|= SEC_RELOC
;
12388 targ
= (br_entry
->offset
12389 + htab
->brlt
->output_offset
12390 + htab
->brlt
->output_section
->vma
);
12391 off
= (elf_gp (info
->output_bfd
)
12392 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12395 if (info
->emitrelocations
)
12397 stub_entry
->group
->stub_sec
->reloc_count
12398 += 1 + (PPC_HA (off
) != 0);
12399 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12402 stub_entry
->type
.main
= ppc_stub_plt_branch
;
12403 if (!stub_entry
->type
.r2save
)
12406 if (PPC_HA (off
) != 0)
12412 if (PPC_HA (off
) != 0)
12415 if (PPC_HA (r2off
) != 0)
12417 if (PPC_LO (r2off
) != 0)
12420 pad
= plt_stub_pad (htab
->params
->plt_stub_align
, stub_offset
, size
);
12421 stub_offset
+= pad
;
12423 else if (info
->emitrelocations
)
12425 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
12426 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12429 else if (stub_entry
->type
.main
== ppc_stub_long_branch
)
12432 + stub_entry
->group
->stub_sec
->output_offset
12433 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12435 if (stub_entry
->type
.r2save
)
12438 targ
= (stub_entry
->target_value
12439 + stub_entry
->target_section
->output_offset
12440 + stub_entry
->target_section
->output_section
->vma
);
12444 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12445 extra
= size_power10_offset (off
, odd
);
12447 extra
= size_offset (off
- 8);
12448 /* Include branch insn plus those in the offset sequence. */
12451 /* If the branch can't reach, use a plt_branch.
12452 The branch insn is at the end, or "extra" bytes along. So
12453 its offset will be "extra" bytes less that that already
12455 if (off
- extra
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12457 stub_entry
->type
.main
= ppc_stub_plt_branch
;
12459 pad
= plt_stub_pad (htab
->params
->plt_stub_align
, stub_offset
, size
);
12462 stub_offset
+= pad
;
12466 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12467 extra
= size_power10_offset (off
, odd
);
12469 extra
= size_offset (off
- 8);
12473 else if (info
->emitrelocations
)
12474 stub_entry
->group
->stub_sec
->reloc_count
+=1;
12476 if (info
->emitrelocations
)
12478 unsigned int num_rel
;
12479 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12480 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12482 num_rel
= num_relocs_for_offset (off
- 8);
12483 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12484 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12487 if (stub_entry
->type
.sub
!= ppc_stub_notoc
)
12489 /* After the bcl, lr has been modified so we need to emit
12490 .eh_frame info saying the return address is in r12. */
12491 lr_used
= stub_offset
+ 8;
12492 if (stub_entry
->type
.r2save
)
12494 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12495 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12496 DW_CFA_restore_extended 65. */
12497 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12498 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12499 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12502 else if (stub_entry
->type
.sub
>= ppc_stub_notoc
)
12504 BFD_ASSERT (stub_entry
->type
.main
== ppc_stub_plt_call
);
12506 if (stub_entry
->h
!= NULL
12507 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12508 && htab
->params
->tls_get_addr_opt
)
12511 if (!htab
->params
->no_tls_get_addr_regsave
)
12513 else if (stub_entry
->type
.r2save
)
12516 if (stub_entry
->type
.r2save
)
12518 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12519 if (targ
>= (bfd_vma
) -2)
12522 plt
= htab
->elf
.splt
;
12523 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12525 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12526 plt
= htab
->elf
.iplt
;
12528 plt
= htab
->pltlocal
;
12530 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12532 + stub_entry
->group
->stub_sec
->output_offset
12533 + stub_entry
->group
->stub_sec
->output_section
->vma
12538 size
= plt_stub_size (htab
, stub_entry
, off
, odd
);
12539 pad
= plt_stub_pad (htab
->params
->plt_stub_align
, stub_offset
, size
);
12542 stub_offset
+= pad
;
12545 size
= plt_stub_size (htab
, stub_entry
, off
, odd
);
12548 if (info
->emitrelocations
)
12550 unsigned int num_rel
;
12551 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12552 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12554 num_rel
= num_relocs_for_offset (off
- 8);
12555 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12556 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12559 if (stub_entry
->type
.sub
!= ppc_stub_notoc
)
12561 /* After the bcl, lr has been modified so we need to emit
12562 .eh_frame info saying the return address is in r12. */
12563 lr_used
+= stub_offset
+ 8;
12564 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12565 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12566 DW_CFA_restore_extended 65. */
12567 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12568 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12569 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12571 if (stub_entry
->h
!= NULL
12572 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12573 && htab
->params
->tls_get_addr_opt
)
12575 if (!htab
->params
->no_tls_get_addr_regsave
)
12577 unsigned int cfa_updt
= stub_offset
+ 18 * 4;
12578 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12579 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12580 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12581 stub_entry
->group
->lr_restore
= stub_offset
+ size
- 4;
12583 else if (stub_entry
->type
.r2save
)
12585 lr_used
= stub_offset
+ size
- 20;
12586 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12587 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12588 stub_entry
->group
->lr_restore
= stub_offset
+ size
- 4;
12592 else if (stub_entry
->type
.main
== ppc_stub_plt_call
)
12594 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
12595 if (targ
>= (bfd_vma
) -2)
12597 plt
= htab
->elf
.splt
;
12598 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12600 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12601 plt
= htab
->elf
.iplt
;
12603 plt
= htab
->pltlocal
;
12605 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12607 off
= (elf_gp (info
->output_bfd
)
12608 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12611 size
= plt_stub_size (htab
, stub_entry
, off
, 0);
12612 pad
= plt_stub_pad (htab
->params
->plt_stub_align
, stub_offset
, size
);
12613 stub_offset
+= pad
;
12615 if (info
->emitrelocations
)
12617 stub_entry
->group
->stub_sec
->reloc_count
12618 += ((PPC_HA (off
) != 0)
12620 ? 2 + (htab
->params
->plt_static_chain
12621 && PPC_HA (off
+ 16) == PPC_HA (off
))
12623 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12626 if (stub_entry
->h
!= NULL
12627 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12628 && htab
->params
->tls_get_addr_opt
12629 && stub_entry
->type
.r2save
)
12631 if (!htab
->params
->no_tls_get_addr_regsave
)
12633 /* Adjustments to r1 need to be described. */
12634 unsigned int cfa_updt
= stub_offset
+ 18 * 4;
12635 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12636 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12637 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12641 lr_used
= stub_offset
+ size
- 20;
12642 /* The eh_frame info will consist of a DW_CFA_advance_loc
12643 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
12644 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
12645 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12646 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12648 stub_entry
->group
->lr_restore
= stub_offset
+ size
- 4;
12657 if (stub_entry
->stub_offset
!= stub_offset
)
12658 htab
->stub_changed
= true;
12659 stub_entry
->stub_offset
= stub_offset
;
12660 stub_entry
->group
->stub_sec
->size
= stub_offset
+ size
;
12664 /* Set up various things so that we can make a list of input sections
12665 for each output section included in the link. Returns -1 on error,
12666 0 when no stubs will be needed, and 1 on success. */
12669 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
12673 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12678 htab
->sec_info_arr_size
= _bfd_section_id
;
12679 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
12680 htab
->sec_info
= bfd_zmalloc (amt
);
12681 if (htab
->sec_info
== NULL
)
12684 /* Set toc_off for com, und, abs and ind sections. */
12685 for (id
= 0; id
< 3; id
++)
12686 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
12691 /* Set up for first pass at multitoc partitioning. */
12694 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
12696 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12698 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
12699 htab
->toc_bfd
= NULL
;
12700 htab
->toc_first_sec
= NULL
;
12703 /* The linker repeatedly calls this function for each TOC input section
12704 and linker generated GOT section. Group input bfds such that the toc
12705 within a group is less than 64k in size. */
12708 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
12710 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12711 bfd_vma addr
, off
, limit
;
12716 if (!htab
->second_toc_pass
)
12718 /* Keep track of the first .toc or .got section for this input bfd. */
12719 bool new_bfd
= htab
->toc_bfd
!= isec
->owner
;
12723 htab
->toc_bfd
= isec
->owner
;
12724 htab
->toc_first_sec
= isec
;
12727 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
12728 off
= addr
- htab
->toc_curr
;
12729 limit
= 0x80008000;
12730 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
12732 if (off
+ isec
->size
> limit
)
12734 addr
= (htab
->toc_first_sec
->output_offset
12735 + htab
->toc_first_sec
->output_section
->vma
);
12736 htab
->toc_curr
= addr
;
12737 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
12740 /* toc_curr is the base address of this toc group. Set elf_gp
12741 for the input section to be the offset relative to the
12742 output toc base plus 0x8000. Making the input elf_gp an
12743 offset allows us to move the toc as a whole without
12744 recalculating input elf_gp. */
12745 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
12746 off
+= TOC_BASE_OFF
;
12748 /* Die if someone uses a linker script that doesn't keep input
12749 file .toc and .got together. */
12751 && elf_gp (isec
->owner
) != 0
12752 && elf_gp (isec
->owner
) != off
)
12755 elf_gp (isec
->owner
) = off
;
12759 /* During the second pass toc_first_sec points to the start of
12760 a toc group, and toc_curr is used to track the old elf_gp.
12761 We use toc_bfd to ensure we only look at each bfd once. */
12762 if (htab
->toc_bfd
== isec
->owner
)
12764 htab
->toc_bfd
= isec
->owner
;
12766 if (htab
->toc_first_sec
== NULL
12767 || htab
->toc_curr
!= elf_gp (isec
->owner
))
12769 htab
->toc_curr
= elf_gp (isec
->owner
);
12770 htab
->toc_first_sec
= isec
;
12772 addr
= (htab
->toc_first_sec
->output_offset
12773 + htab
->toc_first_sec
->output_section
->vma
);
12774 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
12775 elf_gp (isec
->owner
) = off
;
12780 /* Called via elf_link_hash_traverse to merge GOT entries for global
12784 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
12786 if (h
->root
.type
== bfd_link_hash_indirect
)
12789 merge_got_entries (&h
->got
.glist
);
12794 /* Called via elf_link_hash_traverse to allocate GOT entries for global
12798 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
12800 struct got_entry
*gent
;
12802 if (h
->root
.type
== bfd_link_hash_indirect
)
12805 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
12806 if (!gent
->is_indirect
)
12807 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
12811 /* Called on the first multitoc pass after the last call to
12812 ppc64_elf_next_toc_section. This function removes duplicate GOT
12816 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
12818 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12819 struct bfd
*ibfd
, *ibfd2
;
12820 bool done_something
;
12822 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
12824 if (!htab
->do_multi_toc
)
12827 /* Merge global sym got entries within a toc group. */
12828 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
12830 /* And tlsld_got. */
12831 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12833 struct got_entry
*ent
, *ent2
;
12835 if (!is_ppc64_elf (ibfd
))
12838 ent
= ppc64_tlsld_got (ibfd
);
12839 if (!ent
->is_indirect
12840 && ent
->got
.offset
!= (bfd_vma
) -1)
12842 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
12844 if (!is_ppc64_elf (ibfd2
))
12847 ent2
= ppc64_tlsld_got (ibfd2
);
12848 if (!ent2
->is_indirect
12849 && ent2
->got
.offset
!= (bfd_vma
) -1
12850 && elf_gp (ibfd2
) == elf_gp (ibfd
))
12852 ent2
->is_indirect
= true;
12853 ent2
->got
.ent
= ent
;
12859 /* Zap sizes of got sections. */
12860 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
12861 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
12862 htab
->got_reli_size
= 0;
12864 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12866 asection
*got
, *relgot
;
12868 if (!is_ppc64_elf (ibfd
))
12871 got
= ppc64_elf_tdata (ibfd
)->got
;
12874 got
->rawsize
= got
->size
;
12876 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
12877 relgot
->rawsize
= relgot
->size
;
12882 /* Now reallocate the got, local syms first. We don't need to
12883 allocate section contents again since we never increase size. */
12884 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12886 struct got_entry
**lgot_ents
;
12887 struct got_entry
**end_lgot_ents
;
12888 struct plt_entry
**local_plt
;
12889 struct plt_entry
**end_local_plt
;
12890 unsigned char *lgot_masks
;
12891 bfd_size_type locsymcount
;
12892 Elf_Internal_Shdr
*symtab_hdr
;
12894 Elf_Internal_Sym
*local_syms
;
12895 Elf_Internal_Sym
*isym
;
12897 if (!is_ppc64_elf (ibfd
))
12900 lgot_ents
= elf_local_got_ents (ibfd
);
12904 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12905 locsymcount
= symtab_hdr
->sh_info
;
12906 end_lgot_ents
= lgot_ents
+ locsymcount
;
12907 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12908 end_local_plt
= local_plt
+ locsymcount
;
12909 lgot_masks
= (unsigned char *) end_local_plt
;
12910 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
12911 if (local_syms
== NULL
&& locsymcount
!= 0)
12913 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
, locsymcount
,
12914 0, NULL
, NULL
, NULL
);
12915 if (local_syms
== NULL
)
12918 s
= ppc64_elf_tdata (ibfd
)->got
;
12919 for (isym
= local_syms
;
12920 lgot_ents
< end_lgot_ents
;
12921 ++lgot_ents
, ++lgot_masks
, isym
++)
12923 struct got_entry
*ent
;
12925 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
12927 unsigned int ent_size
= 8;
12928 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
12930 ent
->got
.offset
= s
->size
;
12931 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
12936 s
->size
+= ent_size
;
12937 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
12939 htab
->elf
.irelplt
->size
+= rel_size
;
12940 htab
->got_reli_size
+= rel_size
;
12942 else if (bfd_link_pic (info
)
12943 && (ent
->tls_type
== 0
12944 ? !info
->enable_dt_relr
12945 : !bfd_link_executable (info
))
12946 && isym
->st_shndx
!= SHN_ABS
)
12948 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12949 srel
->size
+= rel_size
;
12955 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12957 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12959 struct got_entry
*ent
;
12961 if (!is_ppc64_elf (ibfd
))
12964 ent
= ppc64_tlsld_got (ibfd
);
12965 if (!ent
->is_indirect
12966 && ent
->got
.offset
!= (bfd_vma
) -1)
12968 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12969 ent
->got
.offset
= s
->size
;
12971 if (bfd_link_dll (info
))
12973 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12974 srel
->size
+= sizeof (Elf64_External_Rela
);
12979 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12980 if (!done_something
)
12981 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12985 if (!is_ppc64_elf (ibfd
))
12988 got
= ppc64_elf_tdata (ibfd
)->got
;
12991 done_something
= got
->rawsize
!= got
->size
;
12992 if (done_something
)
12997 if (done_something
)
12998 (*htab
->params
->layout_sections_again
) ();
13000 /* Set up for second pass over toc sections to recalculate elf_gp
13001 on input sections. */
13002 htab
->toc_bfd
= NULL
;
13003 htab
->toc_first_sec
= NULL
;
13004 htab
->second_toc_pass
= true;
13005 return done_something
;
13008 /* Called after second pass of multitoc partitioning. */
13011 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
13013 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13015 /* After the second pass, toc_curr tracks the TOC offset used
13016 for code sections below in ppc64_elf_next_input_section. */
13017 htab
->toc_curr
= TOC_BASE_OFF
;
13020 /* No toc references were found in ISEC. If the code in ISEC makes no
13021 calls, then there's no need to use toc adjusting stubs when branching
13022 into ISEC. Actually, indirect calls from ISEC are OK as they will
13023 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
13024 needed, and 2 if a cyclical call-graph was found but no other reason
13025 for a stub was detected. If called from the top level, a return of
13026 2 means the same as a return of 0. */
13029 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
13033 /* Mark this section as checked. */
13034 isec
->call_check_done
= 1;
13036 /* We know none of our code bearing sections will need toc stubs. */
13037 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
13040 if (isec
->size
== 0)
13043 if (isec
->output_section
== NULL
)
13047 if (isec
->reloc_count
!= 0)
13049 Elf_Internal_Rela
*relstart
, *rel
;
13050 Elf_Internal_Sym
*local_syms
;
13051 struct ppc_link_hash_table
*htab
;
13053 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
13054 info
->keep_memory
);
13055 if (relstart
== NULL
)
13058 /* Look for branches to outside of this section. */
13060 htab
= ppc_hash_table (info
);
13064 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
13066 enum elf_ppc64_reloc_type r_type
;
13067 unsigned long r_symndx
;
13068 struct elf_link_hash_entry
*h
;
13069 struct ppc_link_hash_entry
*eh
;
13070 Elf_Internal_Sym
*sym
;
13072 struct _opd_sec_data
*opd
;
13076 r_type
= ELF64_R_TYPE (rel
->r_info
);
13077 if (r_type
!= R_PPC64_REL24
13078 && r_type
!= R_PPC64_REL24_NOTOC
13079 && r_type
!= R_PPC64_REL24_P9NOTOC
13080 && r_type
!= R_PPC64_REL14
13081 && r_type
!= R_PPC64_REL14_BRTAKEN
13082 && r_type
!= R_PPC64_REL14_BRNTAKEN
13083 && r_type
!= R_PPC64_PLTCALL
13084 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
13087 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13088 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
13095 /* Calls to dynamic lib functions go through a plt call stub
13097 eh
= ppc_elf_hash_entry (h
);
13099 && (eh
->elf
.plt
.plist
!= NULL
13101 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
13107 if (sym_sec
== NULL
)
13108 /* Ignore other undefined symbols. */
13111 /* Assume branches to other sections not included in the
13112 link need stubs too, to cover -R and absolute syms. */
13113 if (sym_sec
->output_section
== NULL
)
13120 sym_value
= sym
->st_value
;
13123 if (h
->root
.type
!= bfd_link_hash_defined
13124 && h
->root
.type
!= bfd_link_hash_defweak
)
13126 sym_value
= h
->root
.u
.def
.value
;
13128 sym_value
+= rel
->r_addend
;
13130 /* If this branch reloc uses an opd sym, find the code section. */
13131 opd
= get_opd_info (sym_sec
);
13134 if (h
== NULL
&& opd
->adjust
!= NULL
)
13138 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13140 /* Assume deleted functions won't ever be called. */
13142 sym_value
+= adjust
;
13145 dest
= opd_entry_value (sym_sec
, sym_value
,
13146 &sym_sec
, NULL
, false);
13147 if (dest
== (bfd_vma
) -1)
13152 + sym_sec
->output_offset
13153 + sym_sec
->output_section
->vma
);
13155 /* Ignore branch to self. */
13156 if (sym_sec
== isec
)
13159 /* If the called function uses the toc, we need a stub. */
13160 if (sym_sec
->has_toc_reloc
13161 || sym_sec
->makes_toc_func_call
)
13167 /* Assume any branch that needs a long branch stub might in fact
13168 need a plt_branch stub. A plt_branch stub uses r2. */
13169 else if (dest
- (isec
->output_offset
13170 + isec
->output_section
->vma
13171 + rel
->r_offset
) + (1 << 25)
13172 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
13180 /* If calling back to a section in the process of being
13181 tested, we can't say for sure that no toc adjusting stubs
13182 are needed, so don't return zero. */
13183 else if (sym_sec
->call_check_in_progress
)
13186 /* Branches to another section that itself doesn't have any TOC
13187 references are OK. Recursively call ourselves to check. */
13188 else if (!sym_sec
->call_check_done
)
13192 /* Mark current section as indeterminate, so that other
13193 sections that call back to current won't be marked as
13195 isec
->call_check_in_progress
= 1;
13196 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
13197 isec
->call_check_in_progress
= 0;
13208 if (elf_symtab_hdr (isec
->owner
).contents
13209 != (unsigned char *) local_syms
)
13211 if (elf_section_data (isec
)->relocs
!= relstart
)
13216 && isec
->map_head
.s
!= NULL
13217 && (strcmp (isec
->output_section
->name
, ".init") == 0
13218 || strcmp (isec
->output_section
->name
, ".fini") == 0))
13220 if (isec
->map_head
.s
->has_toc_reloc
13221 || isec
->map_head
.s
->makes_toc_func_call
)
13223 else if (!isec
->map_head
.s
->call_check_done
)
13226 isec
->call_check_in_progress
= 1;
13227 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
13228 isec
->call_check_in_progress
= 0;
13235 isec
->makes_toc_func_call
= 1;
13240 /* The linker repeatedly calls this function for each input section,
13241 in the order that input sections are linked into output sections.
13242 Build lists of input sections to determine groupings between which
13243 we may insert linker stubs. */
13246 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
13248 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13253 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
13254 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
13256 /* This happens to make the list in reverse order,
13257 which is what we want. */
13258 htab
->sec_info
[isec
->id
].u
.list
13259 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
13260 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
13263 if (htab
->multi_toc_needed
)
13265 /* Analyse sections that aren't already flagged as needing a
13266 valid toc pointer. Exclude .fixup for the linux kernel.
13267 .fixup contains branches, but only back to the function that
13268 hit an exception. */
13269 if (!(isec
->has_toc_reloc
13270 || (isec
->flags
& SEC_CODE
) == 0
13271 || strcmp (isec
->name
, ".fixup") == 0
13272 || isec
->call_check_done
))
13274 if (toc_adjusting_stub_needed (info
, isec
) < 0)
13277 /* Make all sections use the TOC assigned for this object file.
13278 This will be wrong for pasted sections; We fix that in
13279 check_pasted_section(). */
13280 if (elf_gp (isec
->owner
) != 0)
13281 htab
->toc_curr
= elf_gp (isec
->owner
);
13284 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
13288 /* Check that all .init and .fini sections use the same toc, if they
13289 have toc relocs. */
13292 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
13294 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
13298 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13299 bfd_vma toc_off
= 0;
13302 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13303 if (i
->has_toc_reloc
)
13306 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13307 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
13312 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13313 if (i
->makes_toc_func_call
)
13315 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13319 /* Make sure the whole pasted function uses the same toc offset. */
13321 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13322 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
13328 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
13330 bool ret1
= check_pasted_section (info
, ".init");
13331 bool ret2
= check_pasted_section (info
, ".fini");
13333 return ret1
&& ret2
;
13336 /* See whether we can group stub sections together. Grouping stub
13337 sections may result in fewer stubs. More importantly, we need to
13338 put all .init* and .fini* stubs at the beginning of the .init or
13339 .fini output sections respectively, because glibc splits the
13340 _init and _fini functions into multiple parts. Putting a stub in
13341 the middle of a function is not a good idea. */
13344 group_sections (struct bfd_link_info
*info
,
13345 bfd_size_type stub_group_size
,
13346 bool stubs_always_before_branch
)
13348 struct ppc_link_hash_table
*htab
;
13350 bool suppress_size_errors
;
13352 htab
= ppc_hash_table (info
);
13356 suppress_size_errors
= false;
13357 if (stub_group_size
== 1)
13359 /* Default values. */
13360 if (stubs_always_before_branch
)
13361 stub_group_size
= 0x1e00000;
13363 stub_group_size
= 0x1c00000;
13364 suppress_size_errors
= true;
13367 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
13371 if (osec
->id
>= htab
->sec_info_arr_size
)
13374 tail
= htab
->sec_info
[osec
->id
].u
.list
;
13375 while (tail
!= NULL
)
13379 bfd_size_type total
;
13382 struct map_stub
*group
;
13383 bfd_size_type group_size
;
13386 total
= tail
->size
;
13387 group_size
= (ppc64_elf_section_data (tail
) != NULL
13388 && ppc64_elf_section_data (tail
)->has_14bit_branch
13389 ? stub_group_size
>> 10 : stub_group_size
);
13391 big_sec
= total
> group_size
;
13392 if (big_sec
&& !suppress_size_errors
)
13393 /* xgettext:c-format */
13394 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
13395 tail
->owner
, tail
);
13396 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
13398 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
13399 && ((total
+= curr
->output_offset
- prev
->output_offset
)
13400 < (ppc64_elf_section_data (prev
) != NULL
13401 && ppc64_elf_section_data (prev
)->has_14bit_branch
13402 ? (group_size
= stub_group_size
>> 10) : group_size
))
13403 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13406 /* OK, the size from the start of CURR to the end is less
13407 than group_size and thus can be handled by one stub
13408 section. (or the tail section is itself larger than
13409 group_size, in which case we may be toast.) We should
13410 really be keeping track of the total size of stubs added
13411 here, as stubs contribute to the final output section
13412 size. That's a little tricky, and this way will only
13413 break if stubs added make the total size more than 2^25,
13414 ie. for the default stub_group_size, if stubs total more
13415 than 2097152 bytes, or nearly 75000 plt call stubs. */
13416 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
13419 group
->link_sec
= curr
;
13420 group
->stub_sec
= NULL
;
13421 group
->needs_save_res
= 0;
13422 group
->lr_restore
= 0;
13423 group
->eh_size
= 0;
13424 group
->eh_base
= 0;
13425 group
->next
= htab
->group
;
13426 htab
->group
= group
;
13429 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13430 /* Set up this stub group. */
13431 htab
->sec_info
[tail
->id
].u
.group
= group
;
13433 while (tail
!= curr
&& (tail
= prev
) != NULL
);
13435 /* But wait, there's more! Input sections up to group_size
13436 bytes before the stub section can be handled by it too.
13437 Don't do this if we have a really large section after the
13438 stubs, as adding more stubs increases the chance that
13439 branches may not reach into the stub section. */
13440 if (!stubs_always_before_branch
&& !big_sec
)
13443 while (prev
!= NULL
13444 && ((total
+= tail
->output_offset
- prev
->output_offset
)
13445 < (ppc64_elf_section_data (prev
) != NULL
13446 && ppc64_elf_section_data (prev
)->has_14bit_branch
13447 ? (group_size
= stub_group_size
>> 10)
13449 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13452 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13453 htab
->sec_info
[tail
->id
].u
.group
= group
;
13462 static const unsigned char glink_eh_frame_cie
[] =
13464 0, 0, 0, 16, /* length. */
13465 0, 0, 0, 0, /* id. */
13466 1, /* CIE version. */
13467 'z', 'R', 0, /* Augmentation string. */
13468 4, /* Code alignment. */
13469 0x78, /* Data alignment. */
13471 1, /* Augmentation size. */
13472 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
13473 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
13476 /* Stripping output sections is normally done before dynamic section
13477 symbols have been allocated. This function is called later, and
13478 handles cases like htab->brlt which is mapped to its own output
13482 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
13484 if (isec
->size
== 0
13485 && isec
->output_section
->size
== 0
13486 && !(isec
->output_section
->flags
& SEC_KEEP
)
13487 && !bfd_section_removed_from_list (info
->output_bfd
,
13488 isec
->output_section
)
13489 && elf_section_data (isec
->output_section
)->dynindx
== 0)
13491 isec
->output_section
->flags
|= SEC_EXCLUDE
;
13492 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
13493 info
->output_bfd
->section_count
--;
13497 /* Stash R_PPC64_RELATIVE reloc at input section SEC, r_offset OFF to
13498 the array of such relocs. */
13501 append_relr_off (struct ppc_link_hash_table
*htab
, asection
*sec
, bfd_vma off
)
13503 if (htab
->relr_count
>= htab
->relr_alloc
)
13505 if (htab
->relr_alloc
== 0)
13506 htab
->relr_alloc
= 4096;
13508 htab
->relr_alloc
*= 2;
13509 htab
->relr
= bfd_realloc (htab
->relr
,
13510 htab
->relr_alloc
* sizeof (*htab
->relr
));
13511 if (htab
->relr
== NULL
)
13514 htab
->relr
[htab
->relr_count
].sec
= sec
;
13515 htab
->relr
[htab
->relr_count
].off
= off
;
13516 htab
->relr_count
++;
13520 /* qsort comparator for bfd_vma args. */
13523 compare_relr_address (const void *arg1
, const void *arg2
)
13525 bfd_vma a
= *(bfd_vma
*) arg1
;
13526 bfd_vma b
= *(bfd_vma
*) arg2
;
13527 return a
< b
? -1 : a
> b
? 1 : 0;
13530 /* Produce a malloc'd sorted array of reloc addresses from the info
13531 stored by append_relr_off. */
13534 sort_relr (struct ppc_link_hash_table
*htab
)
13536 bfd_vma
*addr
= bfd_malloc (htab
->relr_count
* sizeof (*addr
));
13540 for (size_t i
= 0; i
< htab
->relr_count
; i
++)
13541 addr
[i
] = (htab
->relr
[i
].sec
->output_section
->vma
13542 + htab
->relr
[i
].sec
->output_offset
13543 + htab
->relr
[i
].off
);
13545 if (htab
->relr_count
> 1)
13546 qsort (addr
, htab
->relr_count
, sizeof (*addr
), compare_relr_address
);
13551 /* Look over GOT and PLT entries saved on elf_local_got_ents for all
13552 input files, stashing info about needed relative relocs. */
13555 got_and_plt_relr_for_local_syms (struct bfd_link_info
*info
)
13557 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13560 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13562 struct got_entry
**lgot_ents
, **lgot
, **end_lgot_ents
;
13563 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13564 Elf_Internal_Shdr
*symtab_hdr
;
13565 bfd_size_type locsymcount
;
13566 Elf_Internal_Sym
*local_syms
;
13567 Elf_Internal_Sym
*isym
;
13568 struct plt_entry
*pent
;
13569 struct got_entry
*gent
;
13571 if (!is_ppc64_elf (ibfd
))
13574 lgot_ents
= elf_local_got_ents (ibfd
);
13578 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13579 locsymcount
= symtab_hdr
->sh_info
;
13580 local_syms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
13581 if (local_syms
== NULL
&& locsymcount
!= 0)
13583 local_syms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
, locsymcount
,
13584 0, NULL
, NULL
, NULL
);
13585 if (local_syms
== NULL
)
13588 end_lgot_ents
= lgot_ents
+ locsymcount
;
13589 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13590 end_local_plt
= local_plt
+ locsymcount
;
13591 for (lgot
= lgot_ents
, isym
= local_syms
;
13592 lgot
< end_lgot_ents
;
13594 for (gent
= *lgot
; gent
!= NULL
; gent
= gent
->next
)
13595 if (!gent
->is_indirect
13596 && gent
->tls_type
== 0
13597 && gent
->got
.offset
!= (bfd_vma
) -1
13598 && isym
->st_shndx
!= SHN_ABS
)
13600 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
13601 if (!append_relr_off (htab
, got
, gent
->got
.offset
))
13603 htab
->stub_error
= true;
13608 if (!htab
->opd_abi
)
13609 for (lplt
= local_plt
, isym
= local_syms
;
13610 lplt
< end_local_plt
;
13612 for (pent
= *lplt
; pent
!= NULL
; pent
= pent
->next
)
13613 if (pent
->plt
.offset
!= (bfd_vma
) -1
13614 && ELF_ST_TYPE (isym
->st_info
) != STT_GNU_IFUNC
)
13616 if (!append_relr_off (htab
, htab
->pltlocal
, pent
->plt
.offset
))
13618 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13624 if (local_syms
!= NULL
13625 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13627 if (!info
->keep_memory
)
13630 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13636 /* Stash info about needed GOT and PLT entry relative relocs for
13637 global symbol H. */
13640 got_and_plt_relr (struct elf_link_hash_entry
*h
, void *inf
)
13642 struct bfd_link_info
*info
;
13643 struct ppc_link_hash_table
*htab
;
13644 struct plt_entry
*pent
;
13645 struct got_entry
*gent
;
13647 if (h
->root
.type
== bfd_link_hash_indirect
)
13650 info
= (struct bfd_link_info
*) inf
;
13651 htab
= ppc_hash_table (info
);
13655 if (h
->type
!= STT_GNU_IFUNC
13657 && (h
->root
.type
== bfd_link_hash_defined
13658 || h
->root
.type
== bfd_link_hash_defweak
))
13660 if ((!htab
->elf
.dynamic_sections_created
13661 || h
->dynindx
== -1
13662 || SYMBOL_REFERENCES_LOCAL (info
, h
))
13663 && !bfd_is_abs_symbol (&h
->root
))
13664 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
13665 if (!gent
->is_indirect
13666 && gent
->tls_type
== 0
13667 && gent
->got
.offset
!= (bfd_vma
) -1)
13669 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
13670 if (!append_relr_off (htab
, got
, gent
->got
.offset
))
13672 htab
->stub_error
= true;
13678 && use_local_plt (info
, h
))
13679 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
13680 if (pent
->plt
.offset
!= (bfd_vma
) -1)
13682 if (!append_relr_off (htab
, htab
->pltlocal
, pent
->plt
.offset
))
13684 htab
->stub_error
= true;
13692 /* Determine and set the size of the stub section for a final link.
13694 The basic idea here is to examine all the relocations looking for
13695 PC-relative calls to a target that is unreachable with a "bl"
13699 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
13701 bfd_size_type stub_group_size
;
13702 bool stubs_always_before_branch
;
13703 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13708 if (htab
->params
->power10_stubs
== -1 && !htab
->has_power10_relocs
)
13709 htab
->params
->power10_stubs
= 0;
13711 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
13712 htab
->params
->plt_thread_safe
= 1;
13713 if (!htab
->opd_abi
)
13714 htab
->params
->plt_thread_safe
= 0;
13715 else if (htab
->params
->plt_thread_safe
== -1)
13717 static const char *const thread_starter
[] =
13721 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
13723 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
13724 "mq_notify", "create_timer",
13729 "GOMP_parallel_start",
13730 "GOMP_parallel_loop_static",
13731 "GOMP_parallel_loop_static_start",
13732 "GOMP_parallel_loop_dynamic",
13733 "GOMP_parallel_loop_dynamic_start",
13734 "GOMP_parallel_loop_guided",
13735 "GOMP_parallel_loop_guided_start",
13736 "GOMP_parallel_loop_runtime",
13737 "GOMP_parallel_loop_runtime_start",
13738 "GOMP_parallel_sections",
13739 "GOMP_parallel_sections_start",
13745 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
13747 struct elf_link_hash_entry
*h
;
13748 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
13749 false, false, true);
13750 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
13751 if (htab
->params
->plt_thread_safe
)
13755 stubs_always_before_branch
= htab
->params
->group_size
< 0;
13756 if (htab
->params
->group_size
< 0)
13757 stub_group_size
= -htab
->params
->group_size
;
13759 stub_group_size
= htab
->params
->group_size
;
13761 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
13764 htab
->tga_group
= NULL
;
13765 if (!htab
->params
->no_tls_get_addr_regsave
13766 && htab
->tga_desc_fd
!= NULL
13767 && (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefined
13768 || htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefweak
)
13769 && htab
->tls_get_addr_fd
!= NULL
13770 && is_static_defined (&htab
->tls_get_addr_fd
->elf
))
13772 asection
*sym_sec
, *code_sec
, *stub_sec
;
13774 struct _opd_sec_data
*opd
;
13776 sym_sec
= htab
->tls_get_addr_fd
->elf
.root
.u
.def
.section
;
13777 sym_value
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
13778 code_sec
= sym_sec
;
13779 opd
= get_opd_info (sym_sec
);
13781 opd_entry_value (sym_sec
, sym_value
, &code_sec
, NULL
, false);
13782 htab
->tga_group
= htab
->sec_info
[code_sec
->id
].u
.group
;
13783 stub_sec
= (*htab
->params
->add_stub_section
) (".tga_desc.stub",
13784 htab
->tga_group
->link_sec
);
13785 if (stub_sec
== NULL
)
13787 htab
->tga_group
->stub_sec
= stub_sec
;
13789 htab
->tga_desc_fd
->elf
.root
.type
= bfd_link_hash_defined
;
13790 htab
->tga_desc_fd
->elf
.root
.u
.def
.section
= stub_sec
;
13791 htab
->tga_desc_fd
->elf
.root
.u
.def
.value
= 0;
13792 htab
->tga_desc_fd
->elf
.type
= STT_FUNC
;
13793 htab
->tga_desc_fd
->elf
.def_regular
= 1;
13794 htab
->tga_desc_fd
->elf
.non_elf
= 0;
13795 _bfd_elf_link_hash_hide_symbol (info
, &htab
->tga_desc_fd
->elf
, true);
13798 /* Loop until no stubs added. After iteration 20 of this loop we may
13799 exit on a stub section shrinking. */
13804 unsigned int bfd_indx
;
13805 struct map_stub
*group
;
13807 htab
->stub_iteration
+= 1;
13808 htab
->relr_count
= 0;
13810 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
13812 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
13814 Elf_Internal_Shdr
*symtab_hdr
;
13816 Elf_Internal_Sym
*local_syms
= NULL
;
13818 if (!is_ppc64_elf (input_bfd
))
13821 /* We'll need the symbol table in a second. */
13822 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13823 if (symtab_hdr
->sh_info
== 0)
13826 /* Walk over each section attached to the input bfd. */
13827 for (section
= input_bfd
->sections
;
13829 section
= section
->next
)
13831 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
13834 /* If there aren't any relocs, then there's nothing more
13836 if ((section
->flags
& SEC_RELOC
) == 0
13837 || (section
->flags
& SEC_ALLOC
) == 0
13838 || (section
->flags
& SEC_LOAD
) == 0
13839 || section
->reloc_count
== 0)
13842 if (!info
->enable_dt_relr
13843 && (section
->flags
& SEC_CODE
) == 0)
13846 /* If this section is a link-once section that will be
13847 discarded, then don't create any stubs. */
13848 if (section
->output_section
== NULL
13849 || section
->output_section
->owner
!= info
->output_bfd
)
13852 /* Get the relocs. */
13854 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
13855 info
->keep_memory
);
13856 if (internal_relocs
== NULL
)
13857 goto error_ret_free_local
;
13859 is_opd
= ppc64_elf_section_data (section
)->sec_type
== sec_opd
;
13861 /* Now examine each relocation. */
13862 irela
= internal_relocs
;
13863 irelaend
= irela
+ section
->reloc_count
;
13864 for (; irela
< irelaend
; irela
++)
13866 enum elf_ppc64_reloc_type r_type
;
13867 unsigned int r_indx
;
13868 struct ppc_stub_type stub_type
;
13869 struct ppc_stub_hash_entry
*stub_entry
;
13870 asection
*sym_sec
, *code_sec
;
13871 bfd_vma sym_value
, code_value
;
13872 bfd_vma destination
;
13873 unsigned long local_off
;
13875 struct ppc_link_hash_entry
*hash
;
13876 struct ppc_link_hash_entry
*fdh
;
13877 struct elf_link_hash_entry
*h
;
13878 Elf_Internal_Sym
*sym
;
13880 const asection
*id_sec
;
13881 struct _opd_sec_data
*opd
;
13882 struct plt_entry
*plt_ent
;
13884 r_type
= ELF64_R_TYPE (irela
->r_info
);
13885 r_indx
= ELF64_R_SYM (irela
->r_info
);
13887 if (r_type
>= R_PPC64_max
)
13889 bfd_set_error (bfd_error_bad_value
);
13890 goto error_ret_free_internal
;
13893 /* Only look for stubs on branch instructions. */
13897 if (info
->enable_dt_relr
13898 && maybe_relr (r_type
, irela
, section
))
13902 case R_PPC64_REL24
:
13903 case R_PPC64_REL24_NOTOC
:
13904 case R_PPC64_REL24_P9NOTOC
:
13905 case R_PPC64_REL14
:
13906 case R_PPC64_REL14_BRTAKEN
:
13907 case R_PPC64_REL14_BRNTAKEN
:
13908 if ((section
->flags
& SEC_CODE
) != 0)
13913 /* Now determine the call target, its name, value,
13915 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
13916 r_indx
, input_bfd
))
13917 goto error_ret_free_internal
;
13919 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
13921 /* Only locally defined symbols can possibly use
13922 relative relocations. */
13924 if ((sym_sec
== NULL
13925 || sym_sec
->output_section
== NULL
)
13926 /* No symbol is OK too. */
13927 && !(sym
!= NULL
&& sym
->st_shndx
== 0)
13928 /* Hack for __ehdr_start, which is undefined
13930 && !(h
!= NULL
&& h
->root
.linker_def
))
13932 if (NO_OPD_RELOCS
&& is_opd
)
13935 && r_type
== R_PPC64_ADDR64
)
13938 ? h
->type
== STT_GNU_IFUNC
13939 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13942 ? bfd_is_abs_symbol (&h
->root
)
13943 : sym
->st_shndx
== SHN_ABS
)
13946 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
13949 r_offset
= _bfd_elf_section_offset (info
->output_bfd
,
13953 if (r_offset
>= (bfd_vma
) -2)
13955 if (!append_relr_off (htab
, section
, r_offset
))
13956 goto error_ret_free_internal
;
13960 hash
= ppc_elf_hash_entry (h
);
13966 sym_value
= sym
->st_value
;
13967 if (sym_sec
!= NULL
13968 && sym_sec
->output_section
!= NULL
)
13971 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
13972 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
13974 sym_value
= hash
->elf
.root
.u
.def
.value
;
13975 if (sym_sec
->output_section
!= NULL
)
13978 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
13979 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
13981 /* Recognise an old ABI func code entry sym, and
13982 use the func descriptor sym instead if it is
13984 if (hash
->elf
.root
.root
.string
[0] == '.'
13985 && hash
->oh
!= NULL
)
13987 fdh
= ppc_follow_link (hash
->oh
);
13988 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
13989 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
13991 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
13992 sym_value
= fdh
->elf
.root
.u
.def
.value
;
13993 if (sym_sec
->output_section
!= NULL
)
14002 bfd_set_error (bfd_error_bad_value
);
14003 goto error_ret_free_internal
;
14010 sym_value
+= irela
->r_addend
;
14011 destination
= (sym_value
14012 + sym_sec
->output_offset
14013 + sym_sec
->output_section
->vma
);
14014 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
14019 code_sec
= sym_sec
;
14020 code_value
= sym_value
;
14021 opd
= get_opd_info (sym_sec
);
14026 if (hash
== NULL
&& opd
->adjust
!= NULL
)
14028 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
14031 code_value
+= adjust
;
14032 sym_value
+= adjust
;
14034 dest
= opd_entry_value (sym_sec
, sym_value
,
14035 &code_sec
, &code_value
, false);
14036 if (dest
!= (bfd_vma
) -1)
14038 destination
= dest
;
14041 /* Fixup old ABI sym to point at code
14043 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
14044 hash
->elf
.root
.u
.def
.section
= code_sec
;
14045 hash
->elf
.root
.u
.def
.value
= code_value
;
14050 /* Determine what (if any) linker stub is needed. */
14052 stub_type
.main
= ppc_type_of_stub (section
, irela
, &hash
,
14053 &plt_ent
, destination
,
14055 stub_type
.sub
= ppc_stub_toc
;
14056 stub_type
.r2save
= 0;
14058 if (r_type
== R_PPC64_REL24_NOTOC
14059 || r_type
== R_PPC64_REL24_P9NOTOC
)
14061 enum ppc_stub_sub_type notoc
= ppc_stub_notoc
;
14062 if (htab
->params
->power10_stubs
== 0
14063 || (r_type
== R_PPC64_REL24_P9NOTOC
14064 && htab
->params
->power10_stubs
!= 1))
14065 notoc
= ppc_stub_p9notoc
;
14066 if (stub_type
.main
== ppc_stub_plt_call
)
14067 stub_type
.sub
= notoc
;
14068 else if (stub_type
.main
== ppc_stub_long_branch
14069 || (code_sec
!= NULL
14070 && code_sec
->output_section
!= NULL
14071 && (((hash
? hash
->elf
.other
: sym
->st_other
)
14072 & STO_PPC64_LOCAL_MASK
)
14073 > 1 << STO_PPC64_LOCAL_BIT
)))
14075 stub_type
.main
= ppc_stub_long_branch
;
14076 stub_type
.sub
= notoc
;
14077 stub_type
.r2save
= 0;
14080 else if (stub_type
.main
!= ppc_stub_plt_call
)
14082 /* Check whether we need a TOC adjusting stub.
14083 Since the linker pastes together pieces from
14084 different object files when creating the
14085 _init and _fini functions, it may be that a
14086 call to what looks like a local sym is in
14087 fact a call needing a TOC adjustment. */
14088 if ((code_sec
!= NULL
14089 && code_sec
->output_section
!= NULL
14090 && (code_sec
->has_toc_reloc
14091 || code_sec
->makes_toc_func_call
)
14092 && (htab
->sec_info
[code_sec
->id
].toc_off
14093 != htab
->sec_info
[section
->id
].toc_off
))
14094 || (((hash
? hash
->elf
.other
: sym
->st_other
)
14095 & STO_PPC64_LOCAL_MASK
)
14096 == 1 << STO_PPC64_LOCAL_BIT
))
14098 stub_type
.main
= ppc_stub_long_branch
;
14099 stub_type
.sub
= ppc_stub_toc
;
14100 stub_type
.r2save
= 1;
14104 if (stub_type
.main
== ppc_stub_none
)
14107 /* __tls_get_addr calls might be eliminated. */
14108 if (stub_type
.main
!= ppc_stub_plt_call
14110 && is_tls_get_addr (&hash
->elf
, htab
)
14111 && section
->has_tls_reloc
14112 && irela
!= internal_relocs
)
14114 /* Get tls info. */
14115 unsigned char *tls_mask
;
14117 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
14118 irela
- 1, input_bfd
))
14119 goto error_ret_free_internal
;
14120 if ((*tls_mask
& TLS_TLS
) != 0
14121 && (*tls_mask
& (TLS_GD
| TLS_LD
)) == 0)
14125 if (stub_type
.main
== ppc_stub_plt_call
14126 && stub_type
.sub
== ppc_stub_toc
)
14129 && htab
->params
->plt_localentry0
!= 0
14130 && is_elfv2_localentry0 (&hash
->elf
))
14131 htab
->has_plt_localentry0
= 1;
14132 else if (irela
+ 1 < irelaend
14133 && irela
[1].r_offset
== irela
->r_offset
+ 4
14134 && (ELF64_R_TYPE (irela
[1].r_info
)
14135 == R_PPC64_TOCSAVE
))
14137 if (!tocsave_find (htab
, INSERT
,
14138 &local_syms
, irela
+ 1, input_bfd
))
14139 goto error_ret_free_internal
;
14142 stub_type
.r2save
= 1;
14145 /* Support for grouping stub sections. */
14146 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
14148 /* Get the name of this stub. */
14149 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
14151 goto error_ret_free_internal
;
14153 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
14154 stub_name
, false, false);
14155 if (stub_entry
!= NULL
)
14158 if (!ppc_merge_stub (htab
, stub_entry
, stub_type
, r_type
))
14160 /* xgettext:c-format */
14162 (_("%pB: cannot create stub entry %s"),
14163 section
->owner
, stub_entry
->root
.string
);
14164 goto error_ret_free_internal
;
14169 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
14170 if (stub_entry
== NULL
)
14173 error_ret_free_internal
:
14174 if (elf_section_data (section
)->relocs
== NULL
)
14175 free (internal_relocs
);
14176 error_ret_free_local
:
14177 if (symtab_hdr
->contents
14178 != (unsigned char *) local_syms
)
14183 stub_entry
->type
= stub_type
;
14184 if (stub_type
.main
== ppc_stub_plt_call
)
14186 stub_entry
->target_value
= sym_value
;
14187 stub_entry
->target_section
= sym_sec
;
14191 stub_entry
->target_value
= code_value
;
14192 stub_entry
->target_section
= code_sec
;
14194 stub_entry
->h
= hash
;
14195 stub_entry
->plt_ent
= plt_ent
;
14196 stub_entry
->symtype
14197 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
14198 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
14201 && (hash
->elf
.root
.type
== bfd_link_hash_defined
14202 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
14203 htab
->stub_globals
+= 1;
14206 /* We're done with the internal relocs, free them. */
14207 if (elf_section_data (section
)->relocs
!= internal_relocs
)
14208 free (internal_relocs
);
14211 if (local_syms
!= NULL
14212 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14214 if (!info
->keep_memory
)
14217 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14221 /* We may have added some stubs. Find out the new size of the
14223 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14225 group
->lr_restore
= 0;
14226 group
->eh_size
= 0;
14227 if (group
->stub_sec
!= NULL
)
14229 asection
*stub_sec
= group
->stub_sec
;
14231 stub_sec
->rawsize
= stub_sec
->size
;
14232 stub_sec
->size
= 0;
14233 stub_sec
->reloc_count
= 0;
14234 stub_sec
->flags
&= ~SEC_RELOC
;
14237 if (htab
->tga_group
!= NULL
)
14239 /* See emit_tga_desc and emit_tga_desc_eh_frame. */
14240 htab
->tga_group
->eh_size
14241 = 1 + 2 + (htab
->opd_abi
!= 0) + 3 + 8 * 2 + 3 + 8 + 3;
14242 htab
->tga_group
->lr_restore
= 23 * 4;
14243 htab
->tga_group
->stub_sec
->size
= 24 * 4;
14246 htab
->brlt
->rawsize
= htab
->brlt
->size
;
14247 htab
->brlt
->size
= 0;
14248 htab
->brlt
->reloc_count
= 0;
14249 htab
->brlt
->flags
&= ~SEC_RELOC
;
14250 if (htab
->relbrlt
!= NULL
)
14251 htab
->relbrlt
->size
= 0;
14253 if (htab
->elf
.srelrdyn
!= NULL
)
14255 htab
->elf
.srelrdyn
->rawsize
= htab
->elf
.srelrdyn
->size
;
14256 htab
->elf
.srelrdyn
->size
= 0;
14259 htab
->stub_changed
= false;
14261 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
14263 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14264 if (group
->needs_save_res
)
14265 group
->stub_sec
->size
+= htab
->sfpr
->size
;
14267 if (info
->emitrelocations
14268 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14270 htab
->glink
->reloc_count
= 1;
14271 htab
->glink
->flags
|= SEC_RELOC
;
14274 if (htab
->glink_eh_frame
!= NULL
14275 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
14276 && htab
->glink_eh_frame
->output_section
->size
> 8)
14278 size_t size
= 0, align
= 4;
14280 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14281 if (group
->eh_size
!= 0)
14282 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
14283 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14284 size
+= (24 + align
- 1) & -align
;
14286 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14287 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
14288 size
= (size
+ align
- 1) & -align
;
14289 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
14290 htab
->glink_eh_frame
->size
= size
;
14293 if (htab
->params
->plt_stub_align
!= 0)
14294 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14295 if (group
->stub_sec
!= NULL
)
14297 int align
= abs (htab
->params
->plt_stub_align
);
14298 group
->stub_sec
->size
14299 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
14302 if (htab
->elf
.srelrdyn
!= NULL
)
14306 for (r_offset
= 0; r_offset
< htab
->brlt
->size
; r_offset
+= 8)
14307 if (!append_relr_off (htab
, htab
->brlt
, r_offset
))
14310 if (!got_and_plt_relr_for_local_syms (info
))
14312 elf_link_hash_traverse (&htab
->elf
, got_and_plt_relr
, info
);
14313 if (htab
->stub_error
)
14316 bfd_vma
*relr_addr
= sort_relr (htab
);
14317 if (htab
->relr_count
!= 0 && relr_addr
== NULL
)
14321 while (i
< htab
->relr_count
)
14323 bfd_vma base
= relr_addr
[i
];
14324 htab
->elf
.srelrdyn
->size
+= 8;
14326 /* Handle possible duplicate address. This can happen
14327 as sections increase in size when adding stubs. */
14328 while (i
< htab
->relr_count
14329 && relr_addr
[i
] == base
)
14334 size_t start_i
= i
;
14335 while (i
< htab
->relr_count
14336 && relr_addr
[i
] - base
< 63 * 8
14337 && (relr_addr
[i
] - base
) % 8 == 0)
14341 htab
->elf
.srelrdyn
->size
+= 8;
14348 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14349 if (group
->stub_sec
!= NULL
14350 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
14351 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
14352 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
14356 && (!htab
->stub_changed
14357 || htab
->stub_iteration
> STUB_SHRINK_ITER
)
14358 && (htab
->brlt
->rawsize
== htab
->brlt
->size
14359 || (htab
->stub_iteration
> STUB_SHRINK_ITER
14360 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
14361 && (htab
->elf
.srelrdyn
== NULL
14362 || htab
->elf
.srelrdyn
->rawsize
== htab
->elf
.srelrdyn
->size
14363 || (htab
->stub_iteration
> STUB_SHRINK_ITER
14364 && htab
->elf
.srelrdyn
->rawsize
> htab
->elf
.srelrdyn
->size
))
14365 && (htab
->glink_eh_frame
== NULL
14366 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
)
14367 && (htab
->tga_group
== NULL
14368 || htab
->stub_iteration
> 1))
14371 if (htab
->stub_iteration
> STUB_SHRINK_ITER
)
14373 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14374 if (group
->stub_sec
!= NULL
14375 && group
->stub_sec
->size
< group
->stub_sec
->rawsize
)
14376 group
->stub_sec
->size
= group
->stub_sec
->rawsize
;
14378 if (htab
->brlt
->size
< htab
->brlt
->rawsize
)
14379 htab
->brlt
->size
= htab
->brlt
->rawsize
;
14381 if (htab
->elf
.srelrdyn
!= NULL
14382 && htab
->elf
.srelrdyn
->size
< htab
->elf
.srelrdyn
->rawsize
)
14383 htab
->elf
.srelrdyn
->size
= htab
->elf
.srelrdyn
->rawsize
;
14386 /* Ask the linker to do its stuff. */
14387 (*htab
->params
->layout_sections_again
) ();
14390 if (htab
->glink_eh_frame
!= NULL
14391 && htab
->glink_eh_frame
->size
!= 0)
14394 bfd_byte
*p
, *last_fde
;
14395 size_t last_fde_len
, size
, align
, pad
;
14396 struct map_stub
*group
;
14398 /* It is necessary to at least have a rough outline of the
14399 linker generated CIEs and FDEs written before
14400 bfd_elf_discard_info is run, in order for these FDEs to be
14401 indexed in .eh_frame_hdr. */
14402 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
14405 htab
->glink_eh_frame
->contents
= p
;
14409 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
14410 /* CIE length (rewrite in case little-endian). */
14411 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
14412 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14413 p
+= last_fde_len
+ 4;
14415 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14416 if (group
->eh_size
!= 0)
14418 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
14420 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
14422 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14425 val
= p
- htab
->glink_eh_frame
->contents
;
14426 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
14428 /* Offset to stub section, written later. */
14430 /* stub section size. */
14431 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
14433 /* Augmentation. */
14435 /* Make sure we don't have all nops. This is enough for
14436 elf-eh-frame.c to detect the last non-nop opcode. */
14437 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
14438 p
= last_fde
+ last_fde_len
+ 4;
14440 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14443 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
14445 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14448 val
= p
- htab
->glink_eh_frame
->contents
;
14449 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
14451 /* Offset to .glink, written later. */
14454 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
14456 /* Augmentation. */
14459 *p
++ = DW_CFA_advance_loc
+ (htab
->has_plt_localentry0
? 3 : 2);
14460 *p
++ = DW_CFA_register
;
14462 *p
++ = htab
->opd_abi
? 12 : 0;
14463 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 4 : 2);
14464 *p
++ = DW_CFA_restore_extended
;
14466 p
+= ((24 + align
- 1) & -align
) - 24;
14468 /* Subsume any padding into the last FDE if user .eh_frame
14469 sections are aligned more than glink_eh_frame. Otherwise any
14470 zero padding will be seen as a terminator. */
14471 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
14472 size
= p
- htab
->glink_eh_frame
->contents
;
14473 pad
= ((size
+ align
- 1) & -align
) - size
;
14474 htab
->glink_eh_frame
->size
= size
+ pad
;
14475 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
14478 maybe_strip_output (info
, htab
->brlt
);
14479 if (htab
->relbrlt
!= NULL
)
14480 maybe_strip_output (info
, htab
->relbrlt
);
14481 if (htab
->glink_eh_frame
!= NULL
)
14482 maybe_strip_output (info
, htab
->glink_eh_frame
);
14483 if (htab
->elf
.srelrdyn
!= NULL
)
14484 maybe_strip_output (info
, htab
->elf
.srelrdyn
);
14489 /* Called after we have determined section placement. If sections
14490 move, we'll be called again. Provide a value for TOCstart. */
14493 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
14496 bfd_vma TOCstart
, adjust
;
14500 struct elf_link_hash_entry
*h
;
14501 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
14503 if (is_elf_hash_table (&htab
->root
)
14504 && htab
->hgot
!= NULL
)
14508 h
= (struct elf_link_hash_entry
*)
14509 bfd_link_hash_lookup (&htab
->root
, ".TOC.", false, false, true);
14510 if (is_elf_hash_table (&htab
->root
))
14514 && h
->root
.type
== bfd_link_hash_defined
14515 && !h
->root
.linker_def
14516 && (!is_elf_hash_table (&htab
->root
)
14517 || h
->def_regular
))
14519 TOCstart
= defined_sym_val (h
) - TOC_BASE_OFF
;
14520 _bfd_set_gp_value (obfd
, TOCstart
);
14525 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
14526 order. The TOC starts where the first of these sections starts. */
14527 s
= bfd_get_section_by_name (obfd
, ".got");
14528 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14529 s
= bfd_get_section_by_name (obfd
, ".toc");
14530 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14531 s
= bfd_get_section_by_name (obfd
, ".tocbss");
14532 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14533 s
= bfd_get_section_by_name (obfd
, ".plt");
14534 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14536 /* This may happen for
14537 o references to TOC base (SYM@toc / TOC[tc0]) without a
14539 o bad linker script
14540 o --gc-sections and empty TOC sections
14542 FIXME: Warn user? */
14544 /* Look for a likely section. We probably won't even be
14546 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14547 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
14549 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14552 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14553 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
14554 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14557 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14558 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
14562 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14563 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
14569 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
14571 /* Force alignment. */
14572 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
14573 TOCstart
-= adjust
;
14574 _bfd_set_gp_value (obfd
, TOCstart
);
14576 if (info
!= NULL
&& s
!= NULL
)
14578 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14582 if (htab
->elf
.hgot
!= NULL
)
14584 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
14585 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
14590 struct bfd_link_hash_entry
*bh
= NULL
;
14591 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
14592 s
, TOC_BASE_OFF
- adjust
,
14593 NULL
, false, false, &bh
);
14599 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
14600 write out any global entry stubs, and PLT relocations. */
14603 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
14605 struct bfd_link_info
*info
;
14606 struct ppc_link_hash_table
*htab
;
14607 struct plt_entry
*ent
;
14610 if (h
->root
.type
== bfd_link_hash_indirect
)
14614 htab
= ppc_hash_table (info
);
14618 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14619 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14621 /* This symbol has an entry in the procedure linkage
14622 table. Set it up. */
14623 Elf_Internal_Rela rela
;
14624 asection
*plt
, *relplt
;
14627 if (use_local_plt (info
, h
))
14629 if (!(h
->def_regular
14630 && (h
->root
.type
== bfd_link_hash_defined
14631 || h
->root
.type
== bfd_link_hash_defweak
)))
14633 if (h
->type
== STT_GNU_IFUNC
)
14635 plt
= htab
->elf
.iplt
;
14636 relplt
= htab
->elf
.irelplt
;
14637 htab
->elf
.ifunc_resolvers
= true;
14639 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14641 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14645 plt
= htab
->pltlocal
;
14647 if (bfd_link_pic (info
)
14648 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
14650 relplt
= htab
->relpltlocal
;
14652 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14654 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14657 rela
.r_addend
= defined_sym_val (h
) + ent
->addend
;
14659 if (relplt
== NULL
)
14661 loc
= plt
->contents
+ ent
->plt
.offset
;
14662 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
14665 bfd_vma toc
= elf_gp (info
->output_bfd
);
14666 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
14667 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14672 rela
.r_offset
= (plt
->output_section
->vma
14673 + plt
->output_offset
14674 + ent
->plt
.offset
);
14675 BFD_ASSERT (count_and_swap_reloc_out (info
->output_bfd
, &rela
,
14681 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
14682 + htab
->elf
.splt
->output_offset
14683 + ent
->plt
.offset
);
14684 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
14685 rela
.r_addend
= ent
->addend
;
14686 loc
= (htab
->elf
.srelplt
->contents
14687 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
14688 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
14689 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
14690 htab
->elf
.ifunc_resolvers
= true;
14691 BFD_ASSERT (swap_reloc_out (info
->output_bfd
, &rela
,
14692 loc
, htab
->elf
.srelplt
));
14696 if (!h
->pointer_equality_needed
)
14699 if (h
->def_regular
)
14702 s
= htab
->global_entry
;
14703 if (s
== NULL
|| s
->size
== 0)
14706 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14707 if (ent
->plt
.offset
!= (bfd_vma
) -1
14708 && ent
->addend
== 0)
14714 p
= s
->contents
+ h
->root
.u
.def
.value
;
14715 plt
= htab
->elf
.splt
;
14716 if (use_local_plt (info
, h
))
14718 if (h
->type
== STT_GNU_IFUNC
)
14719 plt
= htab
->elf
.iplt
;
14721 plt
= htab
->pltlocal
;
14723 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
14724 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
14726 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
14728 info
->callbacks
->einfo
14729 (_("%P: linkage table error against `%pT'\n"),
14730 h
->root
.root
.string
);
14731 bfd_set_error (bfd_error_bad_value
);
14732 htab
->stub_error
= true;
14735 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
14736 if (htab
->params
->emit_stub_syms
)
14738 size_t len
= strlen (h
->root
.root
.string
);
14739 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
14744 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
14745 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
14748 if (h
->root
.type
== bfd_link_hash_new
)
14750 h
->root
.type
= bfd_link_hash_defined
;
14751 h
->root
.u
.def
.section
= s
;
14752 h
->root
.u
.def
.value
= p
- s
->contents
;
14753 h
->ref_regular
= 1;
14754 h
->def_regular
= 1;
14755 h
->ref_regular_nonweak
= 1;
14756 h
->forced_local
= 1;
14758 h
->root
.linker_def
= 1;
14762 if (PPC_HA (off
) != 0)
14764 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
14767 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
14769 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
14771 bfd_put_32 (s
->owner
, BCTR
, p
);
14777 /* Write PLT relocs for locals. */
14780 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
14782 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14785 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
14787 struct got_entry
**lgot_ents
, **end_lgot_ents
;
14788 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
14789 Elf_Internal_Shdr
*symtab_hdr
;
14790 bfd_size_type locsymcount
;
14791 Elf_Internal_Sym
*local_syms
= NULL
;
14792 struct plt_entry
*ent
;
14794 if (!is_ppc64_elf (ibfd
))
14797 lgot_ents
= elf_local_got_ents (ibfd
);
14801 symtab_hdr
= &elf_symtab_hdr (ibfd
);
14802 locsymcount
= symtab_hdr
->sh_info
;
14803 end_lgot_ents
= lgot_ents
+ locsymcount
;
14804 local_plt
= (struct plt_entry
**) end_lgot_ents
;
14805 end_local_plt
= local_plt
+ locsymcount
;
14806 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
14807 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
14808 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14810 Elf_Internal_Sym
*sym
;
14812 asection
*plt
, *relplt
;
14815 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
14816 lplt
- local_plt
, ibfd
))
14818 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14823 val
= sym
->st_value
+ ent
->addend
;
14824 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
14825 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
14827 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14829 htab
->elf
.ifunc_resolvers
= true;
14830 plt
= htab
->elf
.iplt
;
14831 relplt
= htab
->elf
.irelplt
;
14835 plt
= htab
->pltlocal
;
14837 if (bfd_link_pic (info
)
14838 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
14839 relplt
= htab
->relpltlocal
;
14842 if (relplt
== NULL
)
14844 bfd_byte
*loc
= plt
->contents
+ ent
->plt
.offset
;
14845 bfd_put_64 (info
->output_bfd
, val
, loc
);
14848 bfd_vma toc
= elf_gp (ibfd
);
14849 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14854 Elf_Internal_Rela rela
;
14855 rela
.r_offset
= (ent
->plt
.offset
14856 + plt
->output_offset
14857 + plt
->output_section
->vma
);
14858 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14861 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14863 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14868 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14870 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14872 rela
.r_addend
= val
;
14873 BFD_ASSERT (count_and_swap_reloc_out (info
->output_bfd
,
14878 if (local_syms
!= NULL
14879 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14881 if (!info
->keep_memory
)
14884 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14890 /* Emit the static wrapper function preserving registers around a
14891 __tls_get_addr_opt call. */
14894 emit_tga_desc (struct ppc_link_hash_table
*htab
)
14896 asection
*stub_sec
= htab
->tga_group
->stub_sec
;
14897 unsigned int cfa_updt
= 11 * 4;
14899 bfd_vma to
, from
, delta
;
14901 BFD_ASSERT (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_defined
14902 && htab
->tga_desc_fd
->elf
.root
.u
.def
.section
== stub_sec
14903 && htab
->tga_desc_fd
->elf
.root
.u
.def
.value
== 0);
14904 to
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
14905 from
= defined_sym_val (&htab
->tga_desc_fd
->elf
) + cfa_updt
;
14907 if (delta
+ (1 << 25) >= 1 << 26)
14909 _bfd_error_handler (_("__tls_get_addr call offset overflow"));
14910 htab
->stub_error
= true;
14914 p
= stub_sec
->contents
;
14915 p
= tls_get_addr_prologue (htab
->elf
.dynobj
, p
, htab
);
14916 bfd_put_32 (stub_sec
->owner
, B_DOT
| 1 | (delta
& 0x3fffffc), p
);
14918 p
= tls_get_addr_epilogue (htab
->elf
.dynobj
, p
, htab
);
14919 return stub_sec
->size
== (bfd_size_type
) (p
- stub_sec
->contents
);
14922 /* Emit eh_frame describing the static wrapper function. */
14925 emit_tga_desc_eh_frame (struct ppc_link_hash_table
*htab
, bfd_byte
*p
)
14927 unsigned int cfa_updt
= 11 * 4;
14930 *p
++ = DW_CFA_advance_loc
+ cfa_updt
/ 4;
14931 *p
++ = DW_CFA_def_cfa_offset
;
14939 *p
++ = DW_CFA_offset_extended_sf
;
14941 *p
++ = (-16 / 8) & 0x7f;
14942 for (i
= 4; i
< 12; i
++)
14944 *p
++ = DW_CFA_offset
+ i
;
14945 *p
++ = (htab
->opd_abi
? 13 : 12) - i
;
14947 *p
++ = DW_CFA_advance_loc
+ 10;
14948 *p
++ = DW_CFA_def_cfa_offset
;
14950 for (i
= 4; i
< 12; i
++)
14951 *p
++ = DW_CFA_restore
+ i
;
14952 *p
++ = DW_CFA_advance_loc
+ 2;
14953 *p
++ = DW_CFA_restore_extended
;
14958 /* Build all the stubs associated with the current output file.
14959 The stubs are kept in a hash table attached to the main linker
14960 hash table. This function is called via gldelf64ppc_finish. */
14963 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
14966 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14967 struct map_stub
*group
;
14968 asection
*stub_sec
;
14970 int stub_sec_count
= 0;
14975 /* Allocate memory to hold the linker stubs. */
14976 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14978 group
->eh_size
= 0;
14979 group
->lr_restore
= 0;
14980 if ((stub_sec
= group
->stub_sec
) != NULL
14981 && stub_sec
->size
!= 0)
14983 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
14985 if (stub_sec
->contents
== NULL
)
14987 stub_sec
->size
= 0;
14991 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14996 /* Build the .glink plt call stub. */
14997 if (htab
->params
->emit_stub_syms
)
14999 struct elf_link_hash_entry
*h
;
15000 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
15001 true, false, false);
15004 if (h
->root
.type
== bfd_link_hash_new
)
15006 h
->root
.type
= bfd_link_hash_defined
;
15007 h
->root
.u
.def
.section
= htab
->glink
;
15008 h
->root
.u
.def
.value
= 8;
15009 h
->ref_regular
= 1;
15010 h
->def_regular
= 1;
15011 h
->ref_regular_nonweak
= 1;
15012 h
->forced_local
= 1;
15014 h
->root
.linker_def
= 1;
15017 plt0
= (htab
->elf
.splt
->output_section
->vma
15018 + htab
->elf
.splt
->output_offset
15020 if (info
->emitrelocations
)
15022 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
15025 r
->r_offset
= (htab
->glink
->output_offset
15026 + htab
->glink
->output_section
->vma
);
15027 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
15028 r
->r_addend
= plt0
;
15030 p
= htab
->glink
->contents
;
15031 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
15032 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
15036 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
15038 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
15040 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
15042 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
15044 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
15046 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
15048 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
15050 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
15052 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
15054 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
15062 . .quad plt0-1f # plt0 entry relative to 1:
15064 # We get here with r12 initially @ a glink branch
15065 # Load the address of _dl_runtime_resolve from plt0 and
15066 # jump to it, with r0 set to the index of the PLT entry
15067 # to be resolved and r11 the link map.
15068 __glink_PLTresolve:
15069 . std %r2,24(%r1) # optional
15075 . ld %r0,(0b-1b)(%r11)
15076 . sub %r12,%r12,%r11
15077 . add %r11,%r0,%r11
15078 . addi %r0,%r12,1b-2f
15085 . b __glink_PLTresolve
15087 . b __glink_PLTresolve */
15089 if (htab
->has_plt_localentry0
)
15091 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
15094 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
15096 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
15098 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
15100 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
15102 if (htab
->has_plt_localentry0
)
15103 insn
= LD_R0_0R11
| (-20 & 0xfffc);
15105 insn
= LD_R0_0R11
| (-16 & 0xfffc);
15106 bfd_put_32 (htab
->glink
->owner
, insn
, p
);
15108 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
15110 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R0_R11
, p
);
15112 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-44 & 0xffff), p
);
15114 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
15116 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
15118 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
15120 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
15123 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
15125 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
15127 /* Build the .glink lazy link call stubs. */
15129 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
15135 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
15140 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
15142 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
15147 bfd_put_32 (htab
->glink
->owner
,
15148 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
15154 if (htab
->tga_group
!= NULL
)
15156 htab
->tga_group
->lr_restore
= 23 * 4;
15157 htab
->tga_group
->stub_sec
->size
= 24 * 4;
15158 if (!emit_tga_desc (htab
))
15160 if (htab
->glink_eh_frame
!= NULL
15161 && htab
->glink_eh_frame
->size
!= 0)
15165 p
= htab
->glink_eh_frame
->contents
;
15166 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15168 htab
->tga_group
->eh_size
= emit_tga_desc_eh_frame (htab
, p
) - p
;
15172 /* Build .glink global entry stubs, and PLT relocs for globals. */
15173 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
15175 if (!write_plt_relocs_for_local_syms (info
))
15178 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
15180 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
15182 if (htab
->brlt
->contents
== NULL
)
15185 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
15187 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
15188 htab
->relbrlt
->size
);
15189 if (htab
->relbrlt
->contents
== NULL
)
15193 /* Build the stubs as directed by the stub hash table. */
15195 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
15197 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15198 if (group
->needs_save_res
)
15199 group
->stub_sec
->size
+= htab
->sfpr
->size
;
15201 if (htab
->relbrlt
!= NULL
)
15202 htab
->relbrlt
->reloc_count
= 0;
15204 if (htab
->params
->plt_stub_align
!= 0)
15205 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15206 if ((stub_sec
= group
->stub_sec
) != NULL
)
15208 int align
= abs (htab
->params
->plt_stub_align
);
15209 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
15212 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15213 if (group
->needs_save_res
)
15215 stub_sec
= group
->stub_sec
;
15216 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
15217 htab
->sfpr
->contents
, htab
->sfpr
->size
);
15218 if (htab
->params
->emit_stub_syms
)
15222 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
15223 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
15228 if (htab
->glink_eh_frame
!= NULL
15229 && htab
->glink_eh_frame
->size
!= 0)
15234 p
= htab
->glink_eh_frame
->contents
;
15235 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15237 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15238 if (group
->eh_size
!= 0)
15240 /* Offset to stub section. */
15241 val
= (group
->stub_sec
->output_section
->vma
15242 + group
->stub_sec
->output_offset
);
15243 val
-= (htab
->glink_eh_frame
->output_section
->vma
15244 + htab
->glink_eh_frame
->output_offset
15245 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15246 if (val
+ 0x80000000 > 0xffffffff)
15249 (_("%s offset too large for .eh_frame sdata4 encoding"),
15250 group
->stub_sec
->name
);
15253 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
15254 p
+= (group
->eh_size
+ 17 + 3) & -4;
15256 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
15258 /* Offset to .glink. */
15259 val
= (htab
->glink
->output_section
->vma
15260 + htab
->glink
->output_offset
15262 val
-= (htab
->glink_eh_frame
->output_section
->vma
15263 + htab
->glink_eh_frame
->output_offset
15264 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15265 if (val
+ 0x80000000 > 0xffffffff)
15268 (_("%s offset too large for .eh_frame sdata4 encoding"),
15269 htab
->glink
->name
);
15272 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
15273 p
+= (24 + align
- 1) & -align
;
15277 if (htab
->elf
.srelrdyn
!= NULL
&& htab
->elf
.srelrdyn
->size
!= 0)
15279 htab
->elf
.srelrdyn
->contents
15280 = bfd_alloc (htab
->elf
.dynobj
, htab
->elf
.srelrdyn
->size
);
15281 if (htab
->elf
.srelrdyn
->contents
== NULL
)
15284 bfd_vma
*relr_addr
= sort_relr (htab
);
15285 if (htab
->relr_count
!= 0 && relr_addr
== NULL
)
15289 bfd_byte
*loc
= htab
->elf
.srelrdyn
->contents
;
15290 while (i
< htab
->relr_count
)
15292 bfd_vma base
= relr_addr
[i
];
15293 BFD_ASSERT ((base
& ((1 << RELR_ALIGN
) - 1)) == 0);
15294 bfd_put_64 (htab
->elf
.dynobj
, base
, loc
);
15297 while (i
< htab
->relr_count
15298 && relr_addr
[i
] == base
)
15300 htab
->stub_error
= true;
15307 while (i
< htab
->relr_count
15308 && relr_addr
[i
] - base
< 63 * 8
15309 && (relr_addr
[i
] - base
) % 8 == 0)
15311 bits
|= (bfd_vma
) 1 << ((relr_addr
[i
] - base
) / 8);
15316 bfd_put_64 (htab
->elf
.dynobj
, (bits
<< 1) | 1, loc
);
15322 /* Pad any excess with 1's, a do-nothing encoding. */
15323 while ((size_t) (loc
- htab
->elf
.srelrdyn
->contents
)
15324 < htab
->elf
.srelrdyn
->size
)
15326 bfd_put_64 (htab
->elf
.dynobj
, 1, loc
);
15331 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15332 if ((stub_sec
= group
->stub_sec
) != NULL
)
15334 stub_sec_count
+= 1;
15335 if (stub_sec
->rawsize
!= stub_sec
->size
15336 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
15337 || stub_sec
->rawsize
< stub_sec
->size
))
15342 htab
->stub_error
= true;
15344 if (htab
->stub_error
)
15346 _bfd_error_handler (_("stubs don't match calculated size"));
15353 if (asprintf (&groupmsg
,
15354 ngettext ("linker stubs in %u group",
15355 "linker stubs in %u groups",
15357 stub_sec_count
) < 0)
15361 if (asprintf (stats
, _("%s, iter %u\n"
15363 " long branch %lu\n"
15365 " global entry %lu"),
15366 groupmsg
, htab
->stub_iteration
,
15367 htab
->stub_count
[ppc_stub_long_branch
- 1],
15368 htab
->stub_count
[ppc_stub_plt_branch
- 1],
15369 htab
->stub_count
[ppc_stub_plt_call
- 1],
15370 htab
->stub_count
[ppc_stub_global_entry
- 1]) < 0)
15378 /* What to do when ld finds relocations against symbols defined in
15379 discarded sections. */
15381 static unsigned int
15382 ppc64_elf_action_discarded (asection
*sec
)
15384 if (strcmp (".opd", sec
->name
) == 0)
15387 if (strcmp (".toc", sec
->name
) == 0)
15390 if (strcmp (".toc1", sec
->name
) == 0)
15393 return _bfd_elf_default_action_discarded (sec
);
15396 /* These are the dynamic relocations supported by glibc. */
15399 ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type
)
15403 case R_PPC64_RELATIVE
:
15405 case R_PPC64_ADDR64
:
15406 case R_PPC64_GLOB_DAT
:
15407 case R_PPC64_IRELATIVE
:
15408 case R_PPC64_JMP_IREL
:
15409 case R_PPC64_JMP_SLOT
:
15410 case R_PPC64_DTPMOD64
:
15411 case R_PPC64_DTPREL64
:
15412 case R_PPC64_TPREL64
:
15413 case R_PPC64_TPREL16_LO_DS
:
15414 case R_PPC64_TPREL16_DS
:
15415 case R_PPC64_TPREL16
:
15416 case R_PPC64_TPREL16_LO
:
15417 case R_PPC64_TPREL16_HI
:
15418 case R_PPC64_TPREL16_HIGH
:
15419 case R_PPC64_TPREL16_HA
:
15420 case R_PPC64_TPREL16_HIGHA
:
15421 case R_PPC64_TPREL16_HIGHER
:
15422 case R_PPC64_TPREL16_HIGHEST
:
15423 case R_PPC64_TPREL16_HIGHERA
:
15424 case R_PPC64_TPREL16_HIGHESTA
:
15425 case R_PPC64_ADDR16_LO_DS
:
15426 case R_PPC64_ADDR16_LO
:
15427 case R_PPC64_ADDR16_HI
:
15428 case R_PPC64_ADDR16_HIGH
:
15429 case R_PPC64_ADDR16_HA
:
15430 case R_PPC64_ADDR16_HIGHA
:
15431 case R_PPC64_REL30
:
15433 case R_PPC64_UADDR64
:
15434 case R_PPC64_UADDR32
:
15435 case R_PPC64_ADDR32
:
15436 case R_PPC64_ADDR24
:
15437 case R_PPC64_ADDR16
:
15438 case R_PPC64_UADDR16
:
15439 case R_PPC64_ADDR16_DS
:
15440 case R_PPC64_ADDR16_HIGHER
:
15441 case R_PPC64_ADDR16_HIGHEST
:
15442 case R_PPC64_ADDR16_HIGHERA
:
15443 case R_PPC64_ADDR16_HIGHESTA
:
15444 case R_PPC64_ADDR14
:
15445 case R_PPC64_ADDR14_BRTAKEN
:
15446 case R_PPC64_ADDR14_BRNTAKEN
:
15447 case R_PPC64_REL32
:
15448 case R_PPC64_REL64
:
15456 /* The RELOCATE_SECTION function is called by the ELF backend linker
15457 to handle the relocations for a section.
15459 The relocs are always passed as Rela structures; if the section
15460 actually uses Rel structures, the r_addend field will always be
15463 This function is responsible for adjust the section contents as
15464 necessary, and (if using Rela relocs and generating a
15465 relocatable output file) adjusting the reloc addend as
15468 This function does not have to worry about setting the reloc
15469 address or the reloc symbol index.
15471 LOCAL_SYMS is a pointer to the swapped in local symbols.
15473 LOCAL_SECTIONS is an array giving the section in the input file
15474 corresponding to the st_shndx field of each local symbol.
15476 The global hash table entry for the global symbols can be found
15477 via elf_sym_hashes (input_bfd).
15479 When generating relocatable output, this function must handle
15480 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
15481 going to be the section symbol corresponding to the output
15482 section, which means that the addend must be adjusted
15486 ppc64_elf_relocate_section (bfd
*output_bfd
,
15487 struct bfd_link_info
*info
,
15489 asection
*input_section
,
15490 bfd_byte
*contents
,
15491 Elf_Internal_Rela
*relocs
,
15492 Elf_Internal_Sym
*local_syms
,
15493 asection
**local_sections
)
15495 struct ppc_link_hash_table
*htab
;
15496 Elf_Internal_Shdr
*symtab_hdr
;
15497 struct elf_link_hash_entry
**sym_hashes
;
15498 Elf_Internal_Rela
*rel
;
15499 Elf_Internal_Rela
*wrel
;
15500 Elf_Internal_Rela
*relend
;
15501 Elf_Internal_Rela outrel
;
15503 struct got_entry
**local_got_ents
;
15507 /* Assume 'at' branch hints. */
15508 bool is_isa_v2
= true;
15509 bool warned_dynamic
= false;
15510 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
15512 /* Initialize howto table if needed. */
15513 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
15516 htab
= ppc_hash_table (info
);
15520 /* Don't relocate stub sections. */
15521 if (input_section
->owner
== htab
->params
->stub_bfd
)
15524 if (!is_ppc64_elf (input_bfd
))
15526 bfd_set_error (bfd_error_wrong_format
);
15530 local_got_ents
= elf_local_got_ents (input_bfd
);
15531 TOCstart
= elf_gp (output_bfd
);
15532 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
15533 sym_hashes
= elf_sym_hashes (input_bfd
);
15534 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
15536 rel
= wrel
= relocs
;
15537 relend
= relocs
+ input_section
->reloc_count
;
15538 for (; rel
< relend
; wrel
++, rel
++)
15540 enum elf_ppc64_reloc_type r_type
;
15542 bfd_reloc_status_type r
;
15543 Elf_Internal_Sym
*sym
;
15545 struct elf_link_hash_entry
*h_elf
;
15546 struct ppc_link_hash_entry
*h
;
15547 struct ppc_link_hash_entry
*fdh
;
15548 const char *sym_name
;
15549 unsigned long r_symndx
, toc_symndx
;
15550 bfd_vma toc_addend
;
15551 unsigned char tls_mask
, tls_gd
, tls_type
;
15552 unsigned char sym_type
;
15553 bfd_vma relocation
;
15554 bool unresolved_reloc
, save_unresolved_reloc
;
15556 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
15559 struct ppc_stub_hash_entry
*stub_entry
;
15560 bfd_vma max_br_offset
;
15562 Elf_Internal_Rela orig_rel
;
15563 reloc_howto_type
*howto
;
15564 struct reloc_howto_struct alt_howto
;
15571 r_type
= ELF64_R_TYPE (rel
->r_info
);
15572 r_symndx
= ELF64_R_SYM (rel
->r_info
);
15574 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
15575 symbol of the previous ADDR64 reloc. The symbol gives us the
15576 proper TOC base to use. */
15577 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
15579 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
15581 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
15587 unresolved_reloc
= false;
15590 if (r_symndx
< symtab_hdr
->sh_info
)
15592 /* It's a local symbol. */
15593 struct _opd_sec_data
*opd
;
15595 sym
= local_syms
+ r_symndx
;
15596 sec
= local_sections
[r_symndx
];
15597 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
15598 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
15599 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
15600 opd
= get_opd_info (sec
);
15601 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
15603 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
15609 /* If this is a relocation against the opd section sym
15610 and we have edited .opd, adjust the reloc addend so
15611 that ld -r and ld --emit-relocs output is correct.
15612 If it is a reloc against some other .opd symbol,
15613 then the symbol value will be adjusted later. */
15614 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
15615 rel
->r_addend
+= adjust
;
15617 relocation
+= adjust
;
15625 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
15626 r_symndx
, symtab_hdr
, sym_hashes
,
15627 h_elf
, sec
, relocation
,
15628 unresolved_reloc
, warned
, ignored
);
15629 sym_name
= h_elf
->root
.root
.string
;
15630 sym_type
= h_elf
->type
;
15632 && sec
->owner
== output_bfd
15633 && strcmp (sec
->name
, ".opd") == 0)
15635 /* This is a symbol defined in a linker script. All
15636 such are defined in output sections, even those
15637 defined by simple assignment from a symbol defined in
15638 an input section. Transfer the symbol to an
15639 appropriate input .opd section, so that a branch to
15640 this symbol will be mapped to the location specified
15641 by the opd entry. */
15642 struct bfd_link_order
*lo
;
15643 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
15644 if (lo
->type
== bfd_indirect_link_order
)
15646 asection
*isec
= lo
->u
.indirect
.section
;
15647 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
15648 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
15651 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
15652 h_elf
->root
.u
.def
.section
= isec
;
15659 h
= ppc_elf_hash_entry (h_elf
);
15661 if (sec
!= NULL
&& discarded_section (sec
))
15663 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
15664 input_bfd
, input_section
,
15665 contents
, rel
->r_offset
);
15666 wrel
->r_offset
= rel
->r_offset
;
15668 wrel
->r_addend
= 0;
15670 /* For ld -r, remove relocations in debug sections against
15671 symbols defined in discarded sections. Not done for
15672 non-debug to preserve relocs in .eh_frame which the
15673 eh_frame editing code expects to be present. */
15674 if (bfd_link_relocatable (info
)
15675 && (input_section
->flags
& SEC_DEBUGGING
))
15681 if (bfd_link_relocatable (info
))
15684 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
15686 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15687 sec
= bfd_abs_section_ptr
;
15688 unresolved_reloc
= false;
15691 /* TLS optimizations. Replace instruction sequences and relocs
15692 based on information we collected in tls_optimize. We edit
15693 RELOCS so that --emit-relocs will output something sensible
15694 for the final instruction stream. */
15699 tls_mask
= h
->tls_mask
;
15700 else if (local_got_ents
!= NULL
)
15702 struct plt_entry
**local_plt
= (struct plt_entry
**)
15703 (local_got_ents
+ symtab_hdr
->sh_info
);
15704 unsigned char *lgot_masks
= (unsigned char *)
15705 (local_plt
+ symtab_hdr
->sh_info
);
15706 tls_mask
= lgot_masks
[r_symndx
];
15708 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
15709 && (r_type
== R_PPC64_TLS
15710 || r_type
== R_PPC64_TLSGD
15711 || r_type
== R_PPC64_TLSLD
))
15713 /* Check for toc tls entries. */
15714 unsigned char *toc_tls
;
15716 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15717 &local_syms
, rel
, input_bfd
))
15721 tls_mask
= *toc_tls
;
15724 /* Check that tls relocs are used with tls syms, and non-tls
15725 relocs are used with non-tls syms. */
15726 if (r_symndx
!= STN_UNDEF
15727 && r_type
!= R_PPC64_NONE
15729 || h
->elf
.root
.type
== bfd_link_hash_defined
15730 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
15731 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
15733 if ((tls_mask
& TLS_TLS
) != 0
15734 && (r_type
== R_PPC64_TLS
15735 || r_type
== R_PPC64_TLSGD
15736 || r_type
== R_PPC64_TLSLD
))
15737 /* R_PPC64_TLS is OK against a symbol in the TOC. */
15740 info
->callbacks
->einfo
15741 (!IS_PPC64_TLS_RELOC (r_type
)
15742 /* xgettext:c-format */
15743 ? _("%H: %s used with TLS symbol `%pT'\n")
15744 /* xgettext:c-format */
15745 : _("%H: %s used with non-TLS symbol `%pT'\n"),
15746 input_bfd
, input_section
, rel
->r_offset
,
15747 ppc64_elf_howto_table
[r_type
]->name
,
15751 /* Ensure reloc mapping code below stays sane. */
15752 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
15753 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
15754 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
15755 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
15756 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
15757 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
15758 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
15759 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
15760 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
15761 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
15769 case R_PPC64_LO_DS_OPT
:
15770 if (offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15772 insn
= bfd_get_32 (input_bfd
,
15773 contents
+ rel
->r_offset
- d_offset
);
15774 if ((insn
& (0x3fu
<< 26)) != 58u << 26)
15776 insn
+= (14u << 26) - (58u << 26);
15777 bfd_put_32 (input_bfd
, insn
,
15778 contents
+ rel
->r_offset
- d_offset
);
15779 r_type
= R_PPC64_TOC16_LO
;
15780 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15784 case R_PPC64_TOC16
:
15785 case R_PPC64_TOC16_LO
:
15786 case R_PPC64_TOC16_DS
:
15787 case R_PPC64_TOC16_LO_DS
:
15789 /* Check for toc tls entries. */
15790 unsigned char *toc_tls
;
15793 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15794 &local_syms
, rel
, input_bfd
);
15800 tls_mask
= *toc_tls
;
15801 if (r_type
== R_PPC64_TOC16_DS
15802 || r_type
== R_PPC64_TOC16_LO_DS
)
15804 if ((tls_mask
& TLS_TLS
) != 0
15805 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
15810 /* If we found a GD reloc pair, then we might be
15811 doing a GD->IE transition. */
15815 if ((tls_mask
& TLS_TLS
) != 0
15816 && (tls_mask
& TLS_GD
) == 0)
15819 else if (retval
== 3)
15821 if ((tls_mask
& TLS_TLS
) != 0
15822 && (tls_mask
& TLS_LD
) == 0)
15830 case R_PPC64_GOT_TPREL16_HI
:
15831 case R_PPC64_GOT_TPREL16_HA
:
15832 if ((tls_mask
& TLS_TLS
) != 0
15833 && (tls_mask
& TLS_TPREL
) == 0
15834 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15836 rel
->r_offset
-= d_offset
;
15837 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15838 r_type
= R_PPC64_NONE
;
15839 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15843 case R_PPC64_GOT_TPREL16_DS
:
15844 case R_PPC64_GOT_TPREL16_LO_DS
:
15845 if ((tls_mask
& TLS_TLS
) != 0
15846 && (tls_mask
& TLS_TPREL
) == 0
15847 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15850 insn
= bfd_get_32 (input_bfd
,
15851 contents
+ rel
->r_offset
- d_offset
);
15853 insn
|= 0x3c0d0000; /* addis 0,13,0 */
15854 bfd_put_32 (input_bfd
, insn
,
15855 contents
+ rel
->r_offset
- d_offset
);
15856 r_type
= R_PPC64_TPREL16_HA
;
15857 if (toc_symndx
!= 0)
15859 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15860 rel
->r_addend
= toc_addend
;
15861 /* We changed the symbol. Start over in order to
15862 get h, sym, sec etc. right. */
15866 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15870 case R_PPC64_GOT_TPREL_PCREL34
:
15871 if ((tls_mask
& TLS_TLS
) != 0
15872 && (tls_mask
& TLS_TPREL
) == 0
15873 && offset_in_range (input_section
, rel
->r_offset
, 8))
15875 /* pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel */
15876 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15878 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15879 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
15880 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
15881 bfd_put_32 (input_bfd
, pinsn
>> 32,
15882 contents
+ rel
->r_offset
);
15883 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15884 contents
+ rel
->r_offset
+ 4);
15885 r_type
= R_PPC64_TPREL34
;
15886 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15891 if ((tls_mask
& TLS_TLS
) != 0
15892 && (tls_mask
& TLS_TPREL
) == 0
15893 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15895 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15896 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
15899 if ((rel
->r_offset
& 3) == 0)
15901 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15902 /* Was PPC64_TLS which sits on insn boundary, now
15903 PPC64_TPREL16_LO which is at low-order half-word. */
15904 rel
->r_offset
+= d_offset
;
15905 r_type
= R_PPC64_TPREL16_LO
;
15906 if (toc_symndx
!= 0)
15908 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15909 rel
->r_addend
= toc_addend
;
15910 /* We changed the symbol. Start over in order to
15911 get h, sym, sec etc. right. */
15915 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15917 else if ((rel
->r_offset
& 3) == 1)
15919 /* For pcrel IE to LE we already have the full
15920 offset and thus don't need an addi here. A nop
15922 if ((insn
& (0x3fu
<< 26)) == 14 << 26)
15924 /* Extract regs from addi rt,ra,si. */
15925 unsigned int rt
= (insn
>> 21) & 0x1f;
15926 unsigned int ra
= (insn
>> 16) & 0x1f;
15931 /* Build or ra,rs,rb with rb==rs, ie. mr ra,rs. */
15932 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
15933 insn
|= (31u << 26) | (444u << 1);
15936 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- 1);
15941 case R_PPC64_GOT_TLSGD16_HI
:
15942 case R_PPC64_GOT_TLSGD16_HA
:
15944 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15945 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15949 case R_PPC64_GOT_TLSLD16_HI
:
15950 case R_PPC64_GOT_TLSLD16_HA
:
15951 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15952 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15955 if ((tls_mask
& tls_gd
) != 0)
15956 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
15957 + R_PPC64_GOT_TPREL16_DS
);
15960 rel
->r_offset
-= d_offset
;
15961 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15962 r_type
= R_PPC64_NONE
;
15964 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15968 case R_PPC64_GOT_TLSGD16
:
15969 case R_PPC64_GOT_TLSGD16_LO
:
15971 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15972 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15976 case R_PPC64_GOT_TLSLD16
:
15977 case R_PPC64_GOT_TLSLD16_LO
:
15978 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15979 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15981 unsigned int insn1
, insn2
;
15984 offset
= (bfd_vma
) -1;
15985 /* If not using the newer R_PPC64_TLSGD/LD to mark
15986 __tls_get_addr calls, we must trust that the call
15987 stays with its arg setup insns, ie. that the next
15988 reloc is the __tls_get_addr call associated with
15989 the current reloc. Edit both insns. */
15990 if (input_section
->nomark_tls_get_addr
15991 && rel
+ 1 < relend
15992 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
15993 htab
->tls_get_addr_fd
,
15995 htab
->tls_get_addr
,
15997 offset
= rel
[1].r_offset
;
15998 /* We read the low GOT_TLS (or TOC16) insn because we
15999 need to keep the destination reg. It may be
16000 something other than the usual r3, and moved to r3
16001 before the call by intervening code. */
16002 insn1
= bfd_get_32 (input_bfd
,
16003 contents
+ rel
->r_offset
- d_offset
);
16004 if ((tls_mask
& tls_gd
) != 0)
16007 insn1
&= (0x1f << 21) | (0x1f << 16);
16008 insn1
|= 58u << 26; /* ld */
16009 insn2
= 0x7c636a14; /* add 3,3,13 */
16010 if (offset
!= (bfd_vma
) -1)
16011 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16012 if (r_type
== R_PPC64_TOC16
16013 || r_type
== R_PPC64_TOC16_LO
)
16014 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
16016 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 1)) & 1)
16017 + R_PPC64_GOT_TPREL16_DS
);
16018 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16023 insn1
&= 0x1f << 21;
16024 insn1
|= 0x3c0d0000; /* addis r,13,0 */
16025 insn2
= 0x38630000; /* addi 3,3,0 */
16028 /* Was an LD reloc. */
16029 r_symndx
= STN_UNDEF
;
16030 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16032 else if (toc_symndx
!= 0)
16034 r_symndx
= toc_symndx
;
16035 rel
->r_addend
= toc_addend
;
16037 r_type
= R_PPC64_TPREL16_HA
;
16038 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16039 if (offset
!= (bfd_vma
) -1)
16041 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
16042 R_PPC64_TPREL16_LO
);
16043 rel
[1].r_offset
= offset
+ d_offset
;
16044 rel
[1].r_addend
= rel
->r_addend
;
16047 bfd_put_32 (input_bfd
, insn1
,
16048 contents
+ rel
->r_offset
- d_offset
);
16049 if (offset
!= (bfd_vma
) -1
16050 && offset_in_range (input_section
, offset
, 4))
16052 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16053 if (offset_in_range (input_section
, offset
+ 4, 4))
16055 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16056 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
16057 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
16060 if ((tls_mask
& tls_gd
) == 0
16061 && (tls_gd
== 0 || toc_symndx
!= 0))
16063 /* We changed the symbol. Start over in order
16064 to get h, sym, sec etc. right. */
16070 case R_PPC64_GOT_TLSGD_PCREL34
:
16071 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
16072 && offset_in_range (input_section
, rel
->r_offset
, 8))
16074 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16076 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16077 if ((tls_mask
& TLS_GDIE
) != 0)
16079 /* IE, pla -> pld */
16080 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
16081 r_type
= R_PPC64_GOT_TPREL_PCREL34
;
16085 /* LE, pla pcrel -> paddi r13 */
16086 pinsn
+= (-1ULL << 52) + (13ULL << 16);
16087 r_type
= R_PPC64_TPREL34
;
16089 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16090 bfd_put_32 (input_bfd
, pinsn
>> 32,
16091 contents
+ rel
->r_offset
);
16092 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
16093 contents
+ rel
->r_offset
+ 4);
16097 case R_PPC64_GOT_TLSLD_PCREL34
:
16098 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
16099 && offset_in_range (input_section
, rel
->r_offset
, 8))
16101 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16103 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16104 pinsn
+= (-1ULL << 52) + (13ULL << 16);
16105 bfd_put_32 (input_bfd
, pinsn
>> 32,
16106 contents
+ rel
->r_offset
);
16107 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
16108 contents
+ rel
->r_offset
+ 4);
16109 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16110 r_symndx
= STN_UNDEF
;
16111 r_type
= R_PPC64_TPREL34
;
16112 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16117 case R_PPC64_TLSGD
:
16118 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
16119 && rel
+ 1 < relend
16120 && offset_in_range (input_section
, rel
->r_offset
,
16121 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
16124 unsigned int insn2
;
16125 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
16127 offset
= rel
->r_offset
;
16128 if (is_plt_seq_reloc (r_type1
))
16130 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
16131 if (r_type1
== R_PPC64_PLT_PCREL34
16132 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
16133 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16134 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16138 if (r_type1
== R_PPC64_PLTCALL
)
16139 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16141 if ((tls_mask
& TLS_GDIE
) != 0)
16144 r_type
= R_PPC64_NONE
;
16145 insn2
= 0x7c636a14; /* add 3,3,13 */
16150 if (toc_symndx
!= 0)
16152 r_symndx
= toc_symndx
;
16153 rel
->r_addend
= toc_addend
;
16155 if (r_type1
== R_PPC64_REL24_NOTOC
16156 || r_type1
== R_PPC64_REL24_P9NOTOC
16157 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
16159 r_type
= R_PPC64_NONE
;
16164 rel
->r_offset
= offset
+ d_offset
;
16165 r_type
= R_PPC64_TPREL16_LO
;
16166 insn2
= 0x38630000; /* addi 3,3,0 */
16169 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16170 /* Zap the reloc on the _tls_get_addr call too. */
16171 BFD_ASSERT (offset
== rel
[1].r_offset
);
16172 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16173 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16174 if ((tls_mask
& TLS_GDIE
) == 0
16176 && r_type
!= R_PPC64_NONE
)
16181 case R_PPC64_TLSLD
:
16182 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
16183 && rel
+ 1 < relend
16184 && offset_in_range (input_section
, rel
->r_offset
,
16185 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
16188 unsigned int insn2
;
16189 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
16191 offset
= rel
->r_offset
;
16192 if (is_plt_seq_reloc (r_type1
))
16194 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
16195 if (r_type1
== R_PPC64_PLT_PCREL34
16196 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
16197 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16198 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16202 if (r_type1
== R_PPC64_PLTCALL
)
16203 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16205 if (r_type1
== R_PPC64_REL24_NOTOC
16206 || r_type1
== R_PPC64_REL24_P9NOTOC
16207 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
16209 r_type
= R_PPC64_NONE
;
16214 rel
->r_offset
= offset
+ d_offset
;
16215 r_symndx
= STN_UNDEF
;
16216 r_type
= R_PPC64_TPREL16_LO
;
16217 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16218 insn2
= 0x38630000; /* addi 3,3,0 */
16220 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16221 /* Zap the reloc on the _tls_get_addr call too. */
16222 BFD_ASSERT (offset
== rel
[1].r_offset
);
16223 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16224 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16225 if (r_type
!= R_PPC64_NONE
)
16230 case R_PPC64_DTPMOD64
:
16231 if (rel
+ 1 < relend
16232 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
16233 && rel
[1].r_offset
== rel
->r_offset
+ 8)
16235 if ((tls_mask
& TLS_GD
) == 0
16236 && offset_in_range (input_section
, rel
->r_offset
, 8))
16238 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
16239 if ((tls_mask
& TLS_GDIE
) != 0)
16240 r_type
= R_PPC64_TPREL64
;
16243 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
16244 r_type
= R_PPC64_NONE
;
16246 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16251 if ((tls_mask
& TLS_LD
) == 0
16252 && offset_in_range (input_section
, rel
->r_offset
, 8))
16254 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
16255 r_type
= R_PPC64_NONE
;
16256 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16261 case R_PPC64_TPREL64
:
16262 if ((tls_mask
& TLS_TPREL
) == 0)
16264 r_type
= R_PPC64_NONE
;
16265 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16269 case R_PPC64_ENTRY
:
16270 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16271 if (!bfd_link_pic (info
)
16272 && !info
->traditional_format
16273 && relocation
+ 0x80008000 <= 0xffffffff
16274 && offset_in_range (input_section
, rel
->r_offset
, 8))
16276 unsigned int insn1
, insn2
;
16278 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16279 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16280 if ((insn1
& ~0xfffc) == LD_R2_0R12
16281 && insn2
== ADD_R2_R2_R12
)
16283 bfd_put_32 (input_bfd
,
16284 LIS_R2
+ PPC_HA (relocation
),
16285 contents
+ rel
->r_offset
);
16286 bfd_put_32 (input_bfd
,
16287 ADDI_R2_R2
+ PPC_LO (relocation
),
16288 contents
+ rel
->r_offset
+ 4);
16293 relocation
-= (rel
->r_offset
16294 + input_section
->output_offset
16295 + input_section
->output_section
->vma
);
16296 if (relocation
+ 0x80008000 <= 0xffffffff
16297 && offset_in_range (input_section
, rel
->r_offset
, 8))
16299 unsigned int insn1
, insn2
;
16301 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16302 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16303 if ((insn1
& ~0xfffc) == LD_R2_0R12
16304 && insn2
== ADD_R2_R2_R12
)
16306 bfd_put_32 (input_bfd
,
16307 ADDIS_R2_R12
+ PPC_HA (relocation
),
16308 contents
+ rel
->r_offset
);
16309 bfd_put_32 (input_bfd
,
16310 ADDI_R2_R2
+ PPC_LO (relocation
),
16311 contents
+ rel
->r_offset
+ 4);
16317 case R_PPC64_REL16_HA
:
16318 /* If we are generating a non-PIC executable, edit
16319 . 0: addis 2,12,.TOC.-0b@ha
16320 . addi 2,2,.TOC.-0b@l
16321 used by ELFv2 global entry points to set up r2, to
16324 if .TOC. is in range. */
16325 if (!bfd_link_pic (info
)
16326 && !info
->traditional_format
16328 && rel
->r_addend
== d_offset
16329 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
16330 && rel
+ 1 < relend
16331 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
16332 && rel
[1].r_offset
== rel
->r_offset
+ 4
16333 && rel
[1].r_addend
== rel
->r_addend
+ 4
16334 && relocation
+ 0x80008000 <= 0xffffffff
16335 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 8))
16337 unsigned int insn1
, insn2
;
16338 offset
= rel
->r_offset
- d_offset
;
16339 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
16340 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16341 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
16342 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
16344 r_type
= R_PPC64_ADDR16_HA
;
16345 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16346 rel
->r_addend
-= d_offset
;
16347 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
16348 rel
[1].r_addend
-= d_offset
+ 4;
16349 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
16355 /* Handle other relocations that tweak non-addend part of insn. */
16357 max_br_offset
= 1 << 25;
16358 addend
= rel
->r_addend
;
16359 reloc_dest
= DEST_NORMAL
;
16365 case R_PPC64_TOCSAVE
:
16366 if (relocation
+ addend
== (rel
->r_offset
16367 + input_section
->output_offset
16368 + input_section
->output_section
->vma
)
16369 && tocsave_find (htab
, NO_INSERT
,
16370 &local_syms
, rel
, input_bfd
)
16371 && offset_in_range (input_section
, rel
->r_offset
, 4))
16373 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16375 || insn
== CROR_151515
|| insn
== CROR_313131
)
16376 bfd_put_32 (input_bfd
,
16377 STD_R2_0R1
+ STK_TOC (htab
),
16378 contents
+ rel
->r_offset
);
16382 /* Branch taken prediction relocations. */
16383 case R_PPC64_ADDR14_BRTAKEN
:
16384 case R_PPC64_REL14_BRTAKEN
:
16385 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
16386 /* Fall through. */
16388 /* Branch not taken prediction relocations. */
16389 case R_PPC64_ADDR14_BRNTAKEN
:
16390 case R_PPC64_REL14_BRNTAKEN
:
16391 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
16393 insn
|= bfd_get_32 (input_bfd
,
16394 contents
+ rel
->r_offset
) & ~(0x01 << 21);
16395 /* Fall through. */
16397 case R_PPC64_REL14
:
16398 max_br_offset
= 1 << 15;
16399 /* Fall through. */
16401 case R_PPC64_REL24
:
16402 case R_PPC64_REL24_NOTOC
:
16403 case R_PPC64_REL24_P9NOTOC
:
16404 case R_PPC64_PLTCALL
:
16405 case R_PPC64_PLTCALL_NOTOC
:
16406 /* Calls to functions with a different TOC, such as calls to
16407 shared objects, need to alter the TOC pointer. This is
16408 done using a linkage stub. A REL24 branching to these
16409 linkage stubs needs to be followed by a nop, as the nop
16410 will be replaced with an instruction to restore the TOC
16415 && h
->oh
->is_func_descriptor
)
16416 fdh
= ppc_follow_link (h
->oh
);
16417 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
16419 if ((r_type
== R_PPC64_PLTCALL
16420 || r_type
== R_PPC64_PLTCALL_NOTOC
)
16421 && stub_entry
!= NULL
16422 && stub_entry
->type
.main
== ppc_stub_plt_call
)
16425 if (stub_entry
!= NULL
16426 && (stub_entry
->type
.main
== ppc_stub_plt_call
16427 || stub_entry
->type
.r2save
))
16429 bool can_plt_call
= false;
16431 if (r_type
== R_PPC64_REL24_NOTOC
16432 || r_type
== R_PPC64_REL24_P9NOTOC
)
16434 /* NOTOC calls don't need to restore r2. */
16435 can_plt_call
= true;
16437 else if (stub_entry
->type
.main
== ppc_stub_plt_call
16439 && htab
->params
->plt_localentry0
!= 0
16441 && is_elfv2_localentry0 (&h
->elf
))
16443 /* The function doesn't use or change r2. */
16444 can_plt_call
= true;
16447 /* All of these stubs may modify r2, so there must be a
16448 branch and link followed by a nop. The nop is
16449 replaced by an insn to restore r2. */
16450 else if (offset_in_range (input_section
, rel
->r_offset
, 8))
16454 br
= bfd_get_32 (input_bfd
,
16455 contents
+ rel
->r_offset
);
16460 nop
= bfd_get_32 (input_bfd
,
16461 contents
+ rel
->r_offset
+ 4);
16462 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
16463 can_plt_call
= true;
16464 else if (nop
== NOP
16465 || nop
== CROR_151515
16466 || nop
== CROR_313131
)
16469 && is_tls_get_addr (&h
->elf
, htab
)
16470 && htab
->params
->tls_get_addr_opt
)
16472 /* Special stub used, leave nop alone. */
16475 bfd_put_32 (input_bfd
,
16476 LD_R2_0R1
+ STK_TOC (htab
),
16477 contents
+ rel
->r_offset
+ 4);
16478 can_plt_call
= true;
16483 if (!can_plt_call
&& h
!= NULL
)
16485 const char *name
= h
->elf
.root
.root
.string
;
16490 if (startswith (name
, "__libc_start_main")
16491 && (name
[17] == 0 || name
[17] == '@'))
16493 /* Allow crt1 branch to go via a toc adjusting
16494 stub. Other calls that never return could do
16495 the same, if we could detect such. */
16496 can_plt_call
= true;
16502 /* g++ as of 20130507 emits self-calls without a
16503 following nop. This is arguably wrong since we
16504 have conflicting information. On the one hand a
16505 global symbol and on the other a local call
16506 sequence, but don't error for this special case.
16507 It isn't possible to cheaply verify we have
16508 exactly such a call. Allow all calls to the same
16510 asection
*code_sec
= sec
;
16512 if (get_opd_info (sec
) != NULL
)
16514 bfd_vma off
= (relocation
+ addend
16515 - sec
->output_section
->vma
16516 - sec
->output_offset
);
16518 opd_entry_value (sec
, off
, &code_sec
, NULL
, false);
16520 if (code_sec
== input_section
)
16521 can_plt_call
= true;
16526 if (stub_entry
->type
.main
== ppc_stub_plt_call
)
16527 info
->callbacks
->einfo
16528 /* xgettext:c-format */
16529 (_("%H: call to `%pT' lacks nop, can't restore toc; "
16530 "(plt call stub)\n"),
16531 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
16533 info
->callbacks
->einfo
16534 /* xgettext:c-format */
16535 (_("%H: call to `%pT' lacks nop, can't restore toc; "
16536 "(toc save/adjust stub)\n"),
16537 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
16539 bfd_set_error (bfd_error_bad_value
);
16544 && stub_entry
->type
.main
== ppc_stub_plt_call
)
16545 unresolved_reloc
= false;
16548 if ((stub_entry
== NULL
16549 || stub_entry
->type
.main
== ppc_stub_long_branch
16550 || stub_entry
->type
.main
== ppc_stub_plt_branch
)
16551 && get_opd_info (sec
) != NULL
)
16553 /* The branch destination is the value of the opd entry. */
16554 bfd_vma off
= (relocation
+ addend
16555 - sec
->output_section
->vma
16556 - sec
->output_offset
);
16557 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, false);
16558 if (dest
!= (bfd_vma
) -1)
16562 reloc_dest
= DEST_OPD
;
16566 /* If the branch is out of reach we ought to have a long
16568 from
= (rel
->r_offset
16569 + input_section
->output_offset
16570 + input_section
->output_section
->vma
);
16572 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
16576 if (stub_entry
!= NULL
16577 && (stub_entry
->type
.main
== ppc_stub_long_branch
16578 || stub_entry
->type
.main
== ppc_stub_plt_branch
))
16580 if (stub_entry
->type
.sub
== ppc_stub_toc
16581 && !stub_entry
->type
.r2save
16582 && (r_type
== R_PPC64_ADDR14_BRTAKEN
16583 || r_type
== R_PPC64_ADDR14_BRNTAKEN
16584 || (relocation
+ addend
- from
+ max_br_offset
16585 < 2 * max_br_offset
)))
16586 /* Don't use the stub if this branch is in range. */
16589 if (stub_entry
!= NULL
16590 && stub_entry
->type
.sub
>= ppc_stub_notoc
16591 && ((r_type
!= R_PPC64_REL24_NOTOC
16592 && r_type
!= R_PPC64_REL24_P9NOTOC
)
16593 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
16594 & STO_PPC64_LOCAL_MASK
) <= 1 << STO_PPC64_LOCAL_BIT
)
16595 && (relocation
+ addend
- from
+ max_br_offset
16596 < 2 * max_br_offset
))
16599 if (stub_entry
!= NULL
16600 && stub_entry
->type
.r2save
16601 && (r_type
== R_PPC64_REL24_NOTOC
16602 || r_type
== R_PPC64_REL24_P9NOTOC
)
16603 && (relocation
+ addend
- from
+ max_br_offset
16604 < 2 * max_br_offset
))
16608 if (stub_entry
!= NULL
)
16610 /* Munge up the value and addend so that we call the stub
16611 rather than the procedure directly. */
16612 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
16614 if (stub_entry
->type
.main
== ppc_stub_save_res
)
16615 relocation
+= (stub_sec
->output_offset
16616 + stub_sec
->output_section
->vma
16617 + stub_sec
->size
- htab
->sfpr
->size
16618 - htab
->sfpr
->output_offset
16619 - htab
->sfpr
->output_section
->vma
);
16621 relocation
= (stub_entry
->stub_offset
16622 + stub_sec
->output_offset
16623 + stub_sec
->output_section
->vma
);
16625 reloc_dest
= DEST_STUB
;
16627 if (((stub_entry
->type
.r2save
16628 && (r_type
== R_PPC64_REL24_NOTOC
16629 || r_type
== R_PPC64_REL24_P9NOTOC
))
16630 || ((stub_entry
->type
.main
== ppc_stub_plt_call
16631 && (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
))
16632 && rel
+ 1 < relend
16633 && rel
[1].r_offset
== rel
->r_offset
+ 4
16634 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
))
16635 && !(stub_entry
->type
.main
== ppc_stub_plt_call
16636 && htab
->params
->tls_get_addr_opt
16638 && is_tls_get_addr (&h
->elf
, htab
)))
16640 /* Skip over the r2 store at the start of the stub. */
16644 if ((r_type
== R_PPC64_REL24_NOTOC
16645 || r_type
== R_PPC64_REL24_P9NOTOC
)
16646 && stub_entry
->type
.main
== ppc_stub_plt_call
16647 && stub_entry
->type
.sub
>= ppc_stub_notoc
)
16648 htab
->notoc_plt
= 1;
16655 /* Set 'a' bit. This is 0b00010 in BO field for branch
16656 on CR(BI) insns (BO == 001at or 011at), and 0b01000
16657 for branch on CTR insns (BO == 1a00t or 1a01t). */
16658 if ((insn
& (0x14 << 21)) == (0x04 << 21))
16659 insn
|= 0x02 << 21;
16660 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
16661 insn
|= 0x08 << 21;
16667 /* Invert 'y' bit if not the default. */
16668 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
16669 insn
^= 0x01 << 21;
16672 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
16675 /* NOP out calls to undefined weak functions.
16676 We can thus call a weak function without first
16677 checking whether the function is defined. */
16679 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16680 && h
->elf
.dynindx
== -1
16681 && (r_type
== R_PPC64_REL24
16682 || r_type
== R_PPC64_REL24_NOTOC
16683 || r_type
== R_PPC64_REL24_P9NOTOC
)
16686 && offset_in_range (input_section
, rel
->r_offset
, 4))
16688 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
16693 case R_PPC64_GOT16_DS
:
16694 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16695 || (bfd_link_pic (info
)
16696 && sec
== bfd_abs_section_ptr
)
16697 || !htab
->do_toc_opt
)
16699 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16700 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
16702 && sec
->output_section
!= NULL
16703 && !discarded_section (sec
)
16704 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16705 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16707 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16708 if ((insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16710 insn
+= (14u << 26) - (58u << 26);
16711 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16712 r_type
= R_PPC64_TOC16
;
16713 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16718 case R_PPC64_GOT16_LO_DS
:
16719 case R_PPC64_GOT16_HA
:
16720 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16721 || (bfd_link_pic (info
)
16722 && sec
== bfd_abs_section_ptr
)
16723 || !htab
->do_toc_opt
)
16725 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16726 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
16728 && sec
->output_section
!= NULL
16729 && !discarded_section (sec
)
16730 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16731 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16733 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16734 if (r_type
== R_PPC64_GOT16_LO_DS
16735 && (insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16737 insn
+= (14u << 26) - (58u << 26);
16738 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16739 r_type
= R_PPC64_TOC16_LO
;
16740 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16742 else if (r_type
== R_PPC64_GOT16_HA
16743 && (insn
& (0x3fu
<< 26)) == 15u << 26 /* addis */)
16745 r_type
= R_PPC64_TOC16_HA
;
16746 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16751 case R_PPC64_GOT_PCREL34
:
16752 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16753 || (bfd_link_pic (info
)
16754 && sec
== bfd_abs_section_ptr
)
16755 || !htab
->do_toc_opt
)
16757 from
= (rel
->r_offset
16758 + input_section
->output_section
->vma
16759 + input_section
->output_offset
);
16760 if (!(relocation
- from
+ (1ULL << 33) < 1ULL << 34
16762 && sec
->output_section
!= NULL
16763 && !discarded_section (sec
)
16764 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16765 && offset_in_range (input_section
, rel
->r_offset
, 8)))
16768 offset
= rel
->r_offset
;
16769 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16771 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16772 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16773 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
16776 /* Replace with paddi. */
16777 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
16778 r_type
= R_PPC64_PCREL34
;
16779 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16780 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ offset
);
16781 bfd_put_32 (input_bfd
, pinsn
, contents
+ offset
+ 4);
16782 /* Fall through. */
16784 case R_PPC64_PCREL34
:
16785 if (!htab
->params
->no_pcrel_opt
16786 && rel
+ 1 < relend
16787 && rel
[1].r_offset
== rel
->r_offset
16788 && rel
[1].r_info
== ELF64_R_INFO (0, R_PPC64_PCREL_OPT
)
16789 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16790 && offset_in_range (input_section
, rel
->r_offset
, 8))
16792 offset
= rel
->r_offset
;
16793 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16795 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16796 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16797 == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
16798 | (14ULL << 26) /* paddi */))
16800 bfd_vma off2
= rel
[1].r_addend
;
16802 /* zero means next insn. */
16805 if (offset_in_range (input_section
, off2
, 4))
16808 bfd_signed_vma addend_off
;
16809 pinsn2
= bfd_get_32 (input_bfd
, contents
+ off2
);
16811 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16813 if (!offset_in_range (input_section
, off2
, 8))
16815 pinsn2
|= bfd_get_32 (input_bfd
,
16816 contents
+ off2
+ 4);
16818 if (xlate_pcrel_opt (&pinsn
, &pinsn2
, &addend_off
))
16820 addend
+= addend_off
;
16821 rel
->r_addend
= addend
;
16822 bfd_put_32 (input_bfd
, pinsn
>> 32,
16823 contents
+ offset
);
16824 bfd_put_32 (input_bfd
, pinsn
,
16825 contents
+ offset
+ 4);
16826 bfd_put_32 (input_bfd
, pinsn2
>> 32,
16828 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16829 bfd_put_32 (input_bfd
, pinsn2
,
16830 contents
+ off2
+ 4);
16839 save_unresolved_reloc
= unresolved_reloc
;
16843 /* xgettext:c-format */
16844 _bfd_error_handler (_("%pB: %s unsupported"),
16845 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
16847 bfd_set_error (bfd_error_bad_value
);
16853 case R_PPC64_TLSGD
:
16854 case R_PPC64_TLSLD
:
16855 case R_PPC64_TOCSAVE
:
16856 case R_PPC64_GNU_VTINHERIT
:
16857 case R_PPC64_GNU_VTENTRY
:
16858 case R_PPC64_ENTRY
:
16859 case R_PPC64_PCREL_OPT
:
16862 /* GOT16 relocations. Like an ADDR16 using the symbol's
16863 address in the GOT as relocation value instead of the
16864 symbol's value itself. Also, create a GOT entry for the
16865 symbol and put the symbol value there. */
16866 case R_PPC64_GOT_TLSGD16
:
16867 case R_PPC64_GOT_TLSGD16_LO
:
16868 case R_PPC64_GOT_TLSGD16_HI
:
16869 case R_PPC64_GOT_TLSGD16_HA
:
16870 case R_PPC64_GOT_TLSGD_PCREL34
:
16871 tls_type
= TLS_TLS
| TLS_GD
;
16874 case R_PPC64_GOT_TLSLD16
:
16875 case R_PPC64_GOT_TLSLD16_LO
:
16876 case R_PPC64_GOT_TLSLD16_HI
:
16877 case R_PPC64_GOT_TLSLD16_HA
:
16878 case R_PPC64_GOT_TLSLD_PCREL34
:
16879 tls_type
= TLS_TLS
| TLS_LD
;
16882 case R_PPC64_GOT_TPREL16_DS
:
16883 case R_PPC64_GOT_TPREL16_LO_DS
:
16884 case R_PPC64_GOT_TPREL16_HI
:
16885 case R_PPC64_GOT_TPREL16_HA
:
16886 case R_PPC64_GOT_TPREL_PCREL34
:
16887 tls_type
= TLS_TLS
| TLS_TPREL
;
16890 case R_PPC64_GOT_DTPREL16_DS
:
16891 case R_PPC64_GOT_DTPREL16_LO_DS
:
16892 case R_PPC64_GOT_DTPREL16_HI
:
16893 case R_PPC64_GOT_DTPREL16_HA
:
16894 case R_PPC64_GOT_DTPREL_PCREL34
:
16895 tls_type
= TLS_TLS
| TLS_DTPREL
;
16898 case R_PPC64_GOT16
:
16899 case R_PPC64_GOT16_LO
:
16900 case R_PPC64_GOT16_HI
:
16901 case R_PPC64_GOT16_HA
:
16902 case R_PPC64_GOT16_DS
:
16903 case R_PPC64_GOT16_LO_DS
:
16904 case R_PPC64_GOT_PCREL34
:
16907 /* Relocation is to the entry for this symbol in the global
16912 unsigned long indx
= 0;
16913 struct got_entry
*ent
;
16915 if (tls_type
== (TLS_TLS
| TLS_LD
)
16916 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16917 ent
= ppc64_tlsld_got (input_bfd
);
16922 if (!htab
->elf
.dynamic_sections_created
16923 || h
->elf
.dynindx
== -1
16924 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16925 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16926 /* This is actually a static link, or it is a
16927 -Bsymbolic link and the symbol is defined
16928 locally, or the symbol was forced to be local
16929 because of a version file. */
16933 indx
= h
->elf
.dynindx
;
16934 unresolved_reloc
= false;
16936 ent
= h
->elf
.got
.glist
;
16940 if (local_got_ents
== NULL
)
16942 ent
= local_got_ents
[r_symndx
];
16945 for (; ent
!= NULL
; ent
= ent
->next
)
16946 if (ent
->addend
== orig_rel
.r_addend
16947 && ent
->owner
== input_bfd
16948 && ent
->tls_type
== tls_type
)
16954 if (ent
->is_indirect
)
16955 ent
= ent
->got
.ent
;
16956 offp
= &ent
->got
.offset
;
16957 got
= ppc64_elf_tdata (ent
->owner
)->got
;
16961 /* The offset must always be a multiple of 8. We use the
16962 least significant bit to record whether we have already
16963 processed this entry. */
16965 if ((off
& 1) != 0)
16969 /* Generate relocs for the dynamic linker, except in
16970 the case of TLSLD where we'll use one entry per
16978 ? h
->elf
.type
== STT_GNU_IFUNC
16979 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
16982 relgot
= htab
->elf
.irelplt
;
16983 if (indx
== 0 || is_static_defined (&h
->elf
))
16984 htab
->elf
.ifunc_resolvers
= true;
16987 || (bfd_link_pic (info
)
16989 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16991 && bfd_link_executable (info
)
16993 || SYMBOL_REFERENCES_LOCAL (info
,
16996 ? !bfd_is_abs_symbol (&h
->elf
.root
)
16997 : sym
->st_shndx
!= SHN_ABS
)))
16999 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
17000 if (relgot
!= NULL
)
17002 outrel
.r_offset
= (got
->output_section
->vma
17003 + got
->output_offset
17005 outrel
.r_addend
= orig_rel
.r_addend
;
17006 if (tls_type
& (TLS_LD
| TLS_GD
))
17008 outrel
.r_addend
= 0;
17009 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
17010 if (tls_type
== (TLS_TLS
| TLS_GD
))
17012 BFD_ASSERT (count_and_swap_reloc_out (output_bfd
,
17015 outrel
.r_offset
+= 8;
17016 outrel
.r_addend
= orig_rel
.r_addend
;
17018 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
17021 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
17022 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
17023 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
17024 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
17025 else if (indx
!= 0)
17026 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
17030 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
17032 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
17034 /* Write the .got section contents for the sake
17036 loc
= got
->contents
+ off
;
17037 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
17041 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
17043 outrel
.r_addend
+= relocation
;
17044 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
17046 if (htab
->elf
.tls_sec
== NULL
)
17047 outrel
.r_addend
= 0;
17049 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
17052 if (!(info
->enable_dt_relr
17053 && ELF64_R_TYPE (outrel
.r_info
) == R_PPC64_RELATIVE
))
17054 BFD_ASSERT (count_and_swap_reloc_out (output_bfd
,
17058 /* Init the .got section contents here if we're not
17059 emitting a reloc. */
17062 relocation
+= orig_rel
.r_addend
;
17065 if (htab
->elf
.tls_sec
== NULL
)
17069 if (tls_type
& TLS_LD
)
17072 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17073 if (tls_type
& TLS_TPREL
)
17074 relocation
+= DTP_OFFSET
- TP_OFFSET
;
17077 if (tls_type
& (TLS_GD
| TLS_LD
))
17079 bfd_put_64 (output_bfd
, relocation
,
17080 got
->contents
+ off
+ 8);
17084 bfd_put_64 (output_bfd
, relocation
,
17085 got
->contents
+ off
);
17089 if (off
>= (bfd_vma
) -2)
17092 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
17094 if (!(r_type
== R_PPC64_GOT_PCREL34
17095 || r_type
== R_PPC64_GOT_TLSGD_PCREL34
17096 || r_type
== R_PPC64_GOT_TLSLD_PCREL34
17097 || r_type
== R_PPC64_GOT_TPREL_PCREL34
17098 || r_type
== R_PPC64_GOT_DTPREL_PCREL34
))
17099 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
17103 case R_PPC64_PLT16_HA
:
17104 case R_PPC64_PLT16_HI
:
17105 case R_PPC64_PLT16_LO
:
17106 case R_PPC64_PLT16_LO_DS
:
17107 case R_PPC64_PLT_PCREL34
:
17108 case R_PPC64_PLT_PCREL34_NOTOC
:
17109 case R_PPC64_PLT32
:
17110 case R_PPC64_PLT64
:
17111 case R_PPC64_PLTSEQ
:
17112 case R_PPC64_PLTSEQ_NOTOC
:
17113 case R_PPC64_PLTCALL
:
17114 case R_PPC64_PLTCALL_NOTOC
:
17115 /* Relocation is to the entry for this symbol in the
17116 procedure linkage table. */
17117 unresolved_reloc
= true;
17119 struct plt_entry
**plt_list
= NULL
;
17121 plt_list
= &h
->elf
.plt
.plist
;
17122 else if (local_got_ents
!= NULL
)
17124 struct plt_entry
**local_plt
= (struct plt_entry
**)
17125 (local_got_ents
+ symtab_hdr
->sh_info
);
17126 plt_list
= local_plt
+ r_symndx
;
17130 struct plt_entry
*ent
;
17132 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
17133 if (ent
->plt
.offset
!= (bfd_vma
) -1
17134 && ent
->addend
== orig_rel
.r_addend
)
17139 plt
= htab
->elf
.splt
;
17140 if (use_local_plt (info
, elf_hash_entry (h
)))
17143 ? h
->elf
.type
== STT_GNU_IFUNC
17144 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17145 plt
= htab
->elf
.iplt
;
17147 plt
= htab
->pltlocal
;
17149 relocation
= (plt
->output_section
->vma
17150 + plt
->output_offset
17151 + ent
->plt
.offset
);
17152 if (r_type
== R_PPC64_PLT16_HA
17153 || r_type
== R_PPC64_PLT16_HI
17154 || r_type
== R_PPC64_PLT16_LO
17155 || r_type
== R_PPC64_PLT16_LO_DS
)
17157 got
= (elf_gp (output_bfd
)
17158 + htab
->sec_info
[input_section
->id
].toc_off
);
17162 unresolved_reloc
= false;
17170 /* Relocation value is TOC base. */
17171 relocation
= TOCstart
;
17172 if (r_symndx
== STN_UNDEF
)
17173 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
17174 else if (unresolved_reloc
)
17176 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
17177 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
17179 unresolved_reloc
= true;
17180 if (unresolved_reloc
17183 && !SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
17184 info
->callbacks
->einfo
17185 /* xgettext:c-format */
17186 (_("%H: %s against %pT is not supported\n"),
17187 input_bfd
, input_section
, rel
->r_offset
,
17188 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
17191 /* TOC16 relocs. We want the offset relative to the TOC base,
17192 which is the address of the start of the TOC plus 0x8000.
17193 The TOC consists of sections .got, .toc, .tocbss, and .plt,
17195 case R_PPC64_TOC16
:
17196 case R_PPC64_TOC16_LO
:
17197 case R_PPC64_TOC16_HI
:
17198 case R_PPC64_TOC16_DS
:
17199 case R_PPC64_TOC16_LO_DS
:
17200 case R_PPC64_TOC16_HA
:
17201 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
17206 /* Relocate against the beginning of the section. */
17207 case R_PPC64_SECTOFF
:
17208 case R_PPC64_SECTOFF_LO
:
17209 case R_PPC64_SECTOFF_HI
:
17210 case R_PPC64_SECTOFF_DS
:
17211 case R_PPC64_SECTOFF_LO_DS
:
17212 case R_PPC64_SECTOFF_HA
:
17214 addend
-= sec
->output_section
->vma
;
17217 case R_PPC64_REL16
:
17218 case R_PPC64_REL16_LO
:
17219 case R_PPC64_REL16_HI
:
17220 case R_PPC64_REL16_HA
:
17221 case R_PPC64_REL16_HIGH
:
17222 case R_PPC64_REL16_HIGHA
:
17223 case R_PPC64_REL16_HIGHER
:
17224 case R_PPC64_REL16_HIGHERA
:
17225 case R_PPC64_REL16_HIGHEST
:
17226 case R_PPC64_REL16_HIGHESTA
:
17227 case R_PPC64_REL16_HIGHER34
:
17228 case R_PPC64_REL16_HIGHERA34
:
17229 case R_PPC64_REL16_HIGHEST34
:
17230 case R_PPC64_REL16_HIGHESTA34
:
17231 case R_PPC64_REL16DX_HA
:
17232 case R_PPC64_REL14
:
17233 case R_PPC64_REL14_BRNTAKEN
:
17234 case R_PPC64_REL14_BRTAKEN
:
17235 case R_PPC64_REL24
:
17236 case R_PPC64_REL24_NOTOC
:
17237 case R_PPC64_REL24_P9NOTOC
:
17238 case R_PPC64_PCREL34
:
17239 case R_PPC64_PCREL28
:
17242 case R_PPC64_TPREL16
:
17243 case R_PPC64_TPREL16_LO
:
17244 case R_PPC64_TPREL16_HI
:
17245 case R_PPC64_TPREL16_HA
:
17246 case R_PPC64_TPREL16_DS
:
17247 case R_PPC64_TPREL16_LO_DS
:
17248 case R_PPC64_TPREL16_HIGH
:
17249 case R_PPC64_TPREL16_HIGHA
:
17250 case R_PPC64_TPREL16_HIGHER
:
17251 case R_PPC64_TPREL16_HIGHERA
:
17252 case R_PPC64_TPREL16_HIGHEST
:
17253 case R_PPC64_TPREL16_HIGHESTA
:
17255 && h
->elf
.root
.type
== bfd_link_hash_undefweak
17256 && h
->elf
.dynindx
== -1
17257 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
17259 /* Make this relocation against an undefined weak symbol
17260 resolve to zero. This is really just a tweak, since
17261 code using weak externs ought to check that they are
17262 defined before using them. */
17263 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
17265 insn
= bfd_get_32 (input_bfd
, p
);
17266 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
17268 bfd_put_32 (input_bfd
, insn
, p
);
17271 /* Fall through. */
17273 case R_PPC64_TPREL34
:
17274 if (htab
->elf
.tls_sec
!= NULL
)
17275 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
17276 /* The TPREL16 relocs shouldn't really be used in shared
17277 libs or with non-local symbols as that will result in
17278 DT_TEXTREL being set, but support them anyway. */
17281 case R_PPC64_DTPREL16
:
17282 case R_PPC64_DTPREL16_LO
:
17283 case R_PPC64_DTPREL16_HI
:
17284 case R_PPC64_DTPREL16_HA
:
17285 case R_PPC64_DTPREL16_DS
:
17286 case R_PPC64_DTPREL16_LO_DS
:
17287 case R_PPC64_DTPREL16_HIGH
:
17288 case R_PPC64_DTPREL16_HIGHA
:
17289 case R_PPC64_DTPREL16_HIGHER
:
17290 case R_PPC64_DTPREL16_HIGHERA
:
17291 case R_PPC64_DTPREL16_HIGHEST
:
17292 case R_PPC64_DTPREL16_HIGHESTA
:
17293 case R_PPC64_DTPREL34
:
17294 if (htab
->elf
.tls_sec
!= NULL
)
17295 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17298 case R_PPC64_ADDR64_LOCAL
:
17299 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
17304 case R_PPC64_DTPMOD64
:
17309 case R_PPC64_TPREL64
:
17310 if (htab
->elf
.tls_sec
!= NULL
)
17311 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
17314 case R_PPC64_DTPREL64
:
17315 if (htab
->elf
.tls_sec
!= NULL
)
17316 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17317 /* Fall through. */
17319 /* Relocations that may need to be propagated if this is a
17321 case R_PPC64_REL30
:
17322 case R_PPC64_REL32
:
17323 case R_PPC64_REL64
:
17324 case R_PPC64_ADDR14
:
17325 case R_PPC64_ADDR14_BRNTAKEN
:
17326 case R_PPC64_ADDR14_BRTAKEN
:
17327 case R_PPC64_ADDR16
:
17328 case R_PPC64_ADDR16_DS
:
17329 case R_PPC64_ADDR16_HA
:
17330 case R_PPC64_ADDR16_HI
:
17331 case R_PPC64_ADDR16_HIGH
:
17332 case R_PPC64_ADDR16_HIGHA
:
17333 case R_PPC64_ADDR16_HIGHER
:
17334 case R_PPC64_ADDR16_HIGHERA
:
17335 case R_PPC64_ADDR16_HIGHEST
:
17336 case R_PPC64_ADDR16_HIGHESTA
:
17337 case R_PPC64_ADDR16_LO
:
17338 case R_PPC64_ADDR16_LO_DS
:
17339 case R_PPC64_ADDR16_HIGHER34
:
17340 case R_PPC64_ADDR16_HIGHERA34
:
17341 case R_PPC64_ADDR16_HIGHEST34
:
17342 case R_PPC64_ADDR16_HIGHESTA34
:
17343 case R_PPC64_ADDR24
:
17344 case R_PPC64_ADDR32
:
17345 case R_PPC64_ADDR64
:
17346 case R_PPC64_UADDR16
:
17347 case R_PPC64_UADDR32
:
17348 case R_PPC64_UADDR64
:
17350 case R_PPC64_D34_LO
:
17351 case R_PPC64_D34_HI30
:
17352 case R_PPC64_D34_HA30
:
17355 if ((input_section
->flags
& SEC_ALLOC
) == 0)
17358 if (NO_OPD_RELOCS
&& is_opd
)
17361 if (bfd_link_pic (info
)
17363 || h
->elf
.dyn_relocs
!= NULL
)
17364 && ((h
!= NULL
&& pc_dynrelocs (h
))
17365 || must_be_dyn_reloc (info
, r_type
)))
17367 ? h
->elf
.dyn_relocs
!= NULL
17368 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
17370 bool skip
, relocate
;
17375 /* When generating a dynamic object, these relocations
17376 are copied into the output file to be resolved at run
17382 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
17383 input_section
, rel
->r_offset
);
17384 if (out_off
== (bfd_vma
) -1)
17386 else if (out_off
== (bfd_vma
) -2)
17387 skip
= true, relocate
= true;
17388 out_off
+= (input_section
->output_section
->vma
17389 + input_section
->output_offset
);
17390 outrel
.r_offset
= out_off
;
17391 outrel
.r_addend
= rel
->r_addend
;
17393 /* Optimize unaligned reloc use. */
17394 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
17395 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
17396 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
17397 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
17398 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
17399 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
17400 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
17401 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
17402 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
17405 memset (&outrel
, 0, sizeof outrel
);
17407 && !SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
17409 && r_type
!= R_PPC64_TOC
)
17411 indx
= h
->elf
.dynindx
;
17412 BFD_ASSERT (indx
!= -1);
17413 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
17417 /* This symbol is local, or marked to become local,
17418 or this is an opd section reloc which must point
17419 at a local function. */
17420 outrel
.r_addend
+= relocation
;
17421 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
17423 if (is_opd
&& h
!= NULL
)
17425 /* Lie about opd entries. This case occurs
17426 when building shared libraries and we
17427 reference a function in another shared
17428 lib. The same thing happens for a weak
17429 definition in an application that's
17430 overridden by a strong definition in a
17431 shared lib. (I believe this is a generic
17432 bug in binutils handling of weak syms.)
17433 In these cases we won't use the opd
17434 entry in this lib. */
17435 unresolved_reloc
= false;
17438 && r_type
== R_PPC64_ADDR64
17440 ? h
->elf
.type
== STT_GNU_IFUNC
17441 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
17442 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
17445 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
17447 /* We need to relocate .opd contents for ld.so.
17448 Prelink also wants simple and consistent rules
17449 for relocs. This make all RELATIVE relocs have
17450 *r_offset equal to r_addend. */
17457 ? h
->elf
.type
== STT_GNU_IFUNC
17458 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17460 info
->callbacks
->einfo
17461 /* xgettext:c-format */
17462 (_("%H: %s for indirect "
17463 "function `%pT' unsupported\n"),
17464 input_bfd
, input_section
, rel
->r_offset
,
17465 ppc64_elf_howto_table
[r_type
]->name
,
17469 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
17471 else if (sec
== NULL
|| sec
->owner
== NULL
)
17473 bfd_set_error (bfd_error_bad_value
);
17478 asection
*osec
= sec
->output_section
;
17480 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
17482 /* TLS symbol values are relative to the
17483 TLS segment. Dynamic relocations for
17484 local TLS symbols therefore can't be
17485 reduced to a relocation against their
17486 section symbol because it holds the
17487 address of the section, not a value
17488 relative to the TLS segment. We could
17489 change the .tdata dynamic section symbol
17490 to be zero value but STN_UNDEF works
17491 and is used elsewhere, eg. for TPREL64
17492 GOT relocs against local TLS symbols. */
17493 osec
= htab
->elf
.tls_sec
;
17498 indx
= elf_section_data (osec
)->dynindx
;
17501 if ((osec
->flags
& SEC_READONLY
) == 0
17502 && htab
->elf
.data_index_section
!= NULL
)
17503 osec
= htab
->elf
.data_index_section
;
17505 osec
= htab
->elf
.text_index_section
;
17506 indx
= elf_section_data (osec
)->dynindx
;
17508 BFD_ASSERT (indx
!= 0);
17511 /* We are turning this relocation into one
17512 against a section symbol, so subtract out
17513 the output section's address but not the
17514 offset of the input section in the output
17516 outrel
.r_addend
-= osec
->vma
;
17519 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
17523 if (!(info
->enable_dt_relr
17524 && ELF64_R_TYPE (outrel
.r_info
) == R_PPC64_RELATIVE
17525 && maybe_relr (ELF64_R_TYPE (orig_rel
.r_info
),
17526 rel
, input_section
)))
17528 sreloc
= elf_section_data (input_section
)->sreloc
;
17530 ? h
->elf
.type
== STT_GNU_IFUNC
17531 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17533 sreloc
= htab
->elf
.irelplt
;
17534 if (indx
== 0 || is_static_defined (&h
->elf
))
17535 htab
->elf
.ifunc_resolvers
= true;
17537 if (sreloc
== NULL
)
17540 BFD_ASSERT (count_and_swap_reloc_out (output_bfd
, &outrel
,
17544 if (!warned_dynamic
17545 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel
.r_info
)))
17547 info
->callbacks
->einfo
17548 /* xgettext:c-format */
17549 (_("%X%P: %pB: %s against %pT "
17550 "is not supported by glibc as a dynamic relocation\n"),
17552 ppc64_elf_howto_table
[ELF64_R_TYPE (outrel
.r_info
)]->name
,
17554 warned_dynamic
= true;
17557 /* If this reloc is against an external symbol, it will
17558 be computed at runtime, so there's no need to do
17559 anything now. However, for the sake of prelink ensure
17560 that the section contents are a known value. */
17563 unresolved_reloc
= false;
17564 /* The value chosen here is quite arbitrary as ld.so
17565 ignores section contents except for the special
17566 case of .opd where the contents might be accessed
17567 before relocation. Choose zero, as that won't
17568 cause reloc overflow. */
17571 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
17572 to improve backward compatibility with older
17574 if (r_type
== R_PPC64_ADDR64
)
17575 addend
= outrel
.r_addend
;
17576 /* Adjust pc_relative relocs to have zero in *r_offset. */
17577 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
17578 addend
= outrel
.r_offset
;
17584 case R_PPC64_GLOB_DAT
:
17585 case R_PPC64_JMP_SLOT
:
17586 case R_PPC64_JMP_IREL
:
17587 case R_PPC64_RELATIVE
:
17588 /* We shouldn't ever see these dynamic relocs in relocatable
17590 /* Fall through. */
17592 case R_PPC64_PLTGOT16
:
17593 case R_PPC64_PLTGOT16_DS
:
17594 case R_PPC64_PLTGOT16_HA
:
17595 case R_PPC64_PLTGOT16_HI
:
17596 case R_PPC64_PLTGOT16_LO
:
17597 case R_PPC64_PLTGOT16_LO_DS
:
17598 case R_PPC64_PLTREL32
:
17599 case R_PPC64_PLTREL64
:
17600 /* These ones haven't been implemented yet. */
17602 info
->callbacks
->einfo
17603 /* xgettext:c-format */
17604 (_("%P: %pB: %s is not supported for `%pT'\n"),
17606 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
17608 bfd_set_error (bfd_error_invalid_operation
);
17613 /* Multi-instruction sequences that access the TOC can be
17614 optimized, eg. addis ra,r2,0; addi rb,ra,x;
17615 to nop; addi rb,r2,x; */
17621 case R_PPC64_GOT_TLSLD16_HI
:
17622 case R_PPC64_GOT_TLSGD16_HI
:
17623 case R_PPC64_GOT_TPREL16_HI
:
17624 case R_PPC64_GOT_DTPREL16_HI
:
17625 case R_PPC64_GOT16_HI
:
17626 case R_PPC64_TOC16_HI
:
17627 /* These relocs would only be useful if building up an
17628 offset to later add to r2, perhaps in an indexed
17629 addressing mode instruction. Don't try to optimize.
17630 Unfortunately, the possibility of someone building up an
17631 offset like this or even with the HA relocs, means that
17632 we need to check the high insn when optimizing the low
17636 case R_PPC64_PLTCALL_NOTOC
:
17637 if (!unresolved_reloc
)
17638 htab
->notoc_plt
= 1;
17639 /* Fall through. */
17640 case R_PPC64_PLTCALL
:
17641 if (unresolved_reloc
17642 && offset_in_range (input_section
, rel
->r_offset
,
17643 r_type
== R_PPC64_PLTCALL
? 8 : 4))
17645 /* No plt entry. Make this into a direct call. */
17646 bfd_byte
*p
= contents
+ rel
->r_offset
;
17647 insn
= bfd_get_32 (input_bfd
, p
);
17649 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
17650 if (r_type
== R_PPC64_PLTCALL
)
17651 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
17652 unresolved_reloc
= save_unresolved_reloc
;
17653 r_type
= R_PPC64_REL24
;
17657 case R_PPC64_PLTSEQ_NOTOC
:
17658 case R_PPC64_PLTSEQ
:
17659 if (unresolved_reloc
)
17661 unresolved_reloc
= false;
17666 case R_PPC64_PLT_PCREL34_NOTOC
:
17667 if (!unresolved_reloc
)
17668 htab
->notoc_plt
= 1;
17669 /* Fall through. */
17670 case R_PPC64_PLT_PCREL34
:
17671 if (unresolved_reloc
17672 && offset_in_range (input_section
, rel
->r_offset
, 8))
17674 bfd_byte
*p
= contents
+ rel
->r_offset
;
17675 bfd_put_32 (input_bfd
, PNOP
>> 32, p
);
17676 bfd_put_32 (input_bfd
, PNOP
, p
+ 4);
17677 unresolved_reloc
= false;
17682 case R_PPC64_PLT16_HA
:
17683 if (unresolved_reloc
)
17685 unresolved_reloc
= false;
17688 /* Fall through. */
17689 case R_PPC64_GOT_TLSLD16_HA
:
17690 case R_PPC64_GOT_TLSGD16_HA
:
17691 case R_PPC64_GOT_TPREL16_HA
:
17692 case R_PPC64_GOT_DTPREL16_HA
:
17693 case R_PPC64_GOT16_HA
:
17694 case R_PPC64_TOC16_HA
:
17695 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17696 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
17697 && !(bfd_link_pic (info
)
17699 ? bfd_is_abs_symbol (&h
->elf
.root
)
17700 : sec
== bfd_abs_section_ptr
)))
17704 if (offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17706 p
= contents
+ (rel
->r_offset
& ~3);
17707 bfd_put_32 (input_bfd
, NOP
, p
);
17713 case R_PPC64_PLT16_LO
:
17714 case R_PPC64_PLT16_LO_DS
:
17715 if (unresolved_reloc
)
17717 unresolved_reloc
= false;
17720 /* Fall through. */
17721 case R_PPC64_GOT_TLSLD16_LO
:
17722 case R_PPC64_GOT_TLSGD16_LO
:
17723 case R_PPC64_GOT_TPREL16_LO_DS
:
17724 case R_PPC64_GOT_DTPREL16_LO_DS
:
17725 case R_PPC64_GOT16_LO
:
17726 case R_PPC64_GOT16_LO_DS
:
17727 case R_PPC64_TOC16_LO
:
17728 case R_PPC64_TOC16_LO_DS
:
17729 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17730 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
17731 && !(bfd_link_pic (info
)
17733 ? bfd_is_abs_symbol (&h
->elf
.root
)
17734 : sec
== bfd_abs_section_ptr
))
17735 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17737 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17738 insn
= bfd_get_32 (input_bfd
, p
);
17739 if ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */)
17741 /* Transform addic to addi when we change reg. */
17742 insn
&= ~((0x3fu
<< 26) | (0x1f << 16));
17743 insn
|= (14u << 26) | (2 << 16);
17747 insn
&= ~(0x1f << 16);
17750 bfd_put_32 (input_bfd
, insn
, p
);
17754 case R_PPC64_TPREL16_HA
:
17755 if (htab
->do_tls_opt
17756 && relocation
+ addend
+ 0x8000 < 0x10000
17757 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17759 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17760 bfd_put_32 (input_bfd
, NOP
, p
);
17765 case R_PPC64_TPREL16_LO
:
17766 case R_PPC64_TPREL16_LO_DS
:
17767 if (htab
->do_tls_opt
17768 && relocation
+ addend
+ 0x8000 < 0x10000
17769 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17771 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17772 insn
= bfd_get_32 (input_bfd
, p
);
17773 insn
&= ~(0x1f << 16);
17775 bfd_put_32 (input_bfd
, insn
, p
);
17780 /* Do any further special processing. */
17786 case R_PPC64_REL16_HA
:
17787 case R_PPC64_REL16_HIGHA
:
17788 case R_PPC64_REL16_HIGHERA
:
17789 case R_PPC64_REL16_HIGHESTA
:
17790 case R_PPC64_REL16DX_HA
:
17791 case R_PPC64_ADDR16_HA
:
17792 case R_PPC64_ADDR16_HIGHA
:
17793 case R_PPC64_ADDR16_HIGHERA
:
17794 case R_PPC64_ADDR16_HIGHESTA
:
17795 case R_PPC64_TOC16_HA
:
17796 case R_PPC64_SECTOFF_HA
:
17797 case R_PPC64_TPREL16_HA
:
17798 case R_PPC64_TPREL16_HIGHA
:
17799 case R_PPC64_TPREL16_HIGHERA
:
17800 case R_PPC64_TPREL16_HIGHESTA
:
17801 case R_PPC64_DTPREL16_HA
:
17802 case R_PPC64_DTPREL16_HIGHA
:
17803 case R_PPC64_DTPREL16_HIGHERA
:
17804 case R_PPC64_DTPREL16_HIGHESTA
:
17805 /* It's just possible that this symbol is a weak symbol
17806 that's not actually defined anywhere. In that case,
17807 'sec' would be NULL, and we should leave the symbol
17808 alone (it will be set to zero elsewhere in the link). */
17811 /* Fall through. */
17813 case R_PPC64_GOT16_HA
:
17814 case R_PPC64_PLTGOT16_HA
:
17815 case R_PPC64_PLT16_HA
:
17816 case R_PPC64_GOT_TLSGD16_HA
:
17817 case R_PPC64_GOT_TLSLD16_HA
:
17818 case R_PPC64_GOT_TPREL16_HA
:
17819 case R_PPC64_GOT_DTPREL16_HA
:
17820 /* Add 0x10000 if sign bit in 0:15 is set.
17821 Bits 0:15 are not used. */
17825 case R_PPC64_D34_HA30
:
17826 case R_PPC64_ADDR16_HIGHERA34
:
17827 case R_PPC64_ADDR16_HIGHESTA34
:
17828 case R_PPC64_REL16_HIGHERA34
:
17829 case R_PPC64_REL16_HIGHESTA34
:
17831 addend
+= 1ULL << 33;
17834 case R_PPC64_ADDR16_DS
:
17835 case R_PPC64_ADDR16_LO_DS
:
17836 case R_PPC64_GOT16_DS
:
17837 case R_PPC64_GOT16_LO_DS
:
17838 case R_PPC64_PLT16_LO_DS
:
17839 case R_PPC64_SECTOFF_DS
:
17840 case R_PPC64_SECTOFF_LO_DS
:
17841 case R_PPC64_TOC16_DS
:
17842 case R_PPC64_TOC16_LO_DS
:
17843 case R_PPC64_PLTGOT16_DS
:
17844 case R_PPC64_PLTGOT16_LO_DS
:
17845 case R_PPC64_GOT_TPREL16_DS
:
17846 case R_PPC64_GOT_TPREL16_LO_DS
:
17847 case R_PPC64_GOT_DTPREL16_DS
:
17848 case R_PPC64_GOT_DTPREL16_LO_DS
:
17849 case R_PPC64_TPREL16_DS
:
17850 case R_PPC64_TPREL16_LO_DS
:
17851 case R_PPC64_DTPREL16_DS
:
17852 case R_PPC64_DTPREL16_LO_DS
:
17853 if (!offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17855 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17857 /* If this reloc is against an lq, lxv, or stxv insn, then
17858 the value must be a multiple of 16. This is somewhat of
17859 a hack, but the "correct" way to do this by defining _DQ
17860 forms of all the _DS relocs bloats all reloc switches in
17861 this file. It doesn't make much sense to use these
17862 relocs in data, so testing the insn should be safe. */
17863 if ((insn
& (0x3fu
<< 26)) == (56u << 26)
17864 || ((insn
& (0x3fu
<< 26)) == (61u << 26) && (insn
& 3) == 1))
17866 relocation
+= addend
;
17867 addend
= insn
& (mask
^ 3);
17868 if ((relocation
& mask
) != 0)
17870 relocation
^= relocation
& mask
;
17871 info
->callbacks
->einfo
17872 /* xgettext:c-format */
17873 (_("%H: error: %s not a multiple of %u\n"),
17874 input_bfd
, input_section
, rel
->r_offset
,
17875 ppc64_elf_howto_table
[r_type
]->name
,
17877 bfd_set_error (bfd_error_bad_value
);
17884 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
17885 because such sections are not SEC_ALLOC and thus ld.so will
17886 not process them. */
17887 howto
= ppc64_elf_howto_table
[(int) r_type
];
17888 if (unresolved_reloc
17889 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
17890 && h
->elf
.def_dynamic
)
17891 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
17892 rel
->r_offset
) != (bfd_vma
) -1)
17894 info
->callbacks
->einfo
17895 /* xgettext:c-format */
17896 (_("%H: unresolvable %s against `%pT'\n"),
17897 input_bfd
, input_section
, rel
->r_offset
,
17899 h
->elf
.root
.root
.string
);
17903 /* 16-bit fields in insns mostly have signed values, but a
17904 few insns have 16-bit unsigned values. Really, we should
17905 have different reloc types. */
17906 if (howto
->complain_on_overflow
!= complain_overflow_dont
17907 && howto
->dst_mask
== 0xffff
17908 && (input_section
->flags
& SEC_CODE
) != 0
17909 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17911 enum complain_overflow complain
= complain_overflow_signed
;
17913 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17914 if ((insn
& (0x3fu
<< 26)) == 10u << 26 /* cmpli */)
17915 complain
= complain_overflow_bitfield
;
17916 else if (howto
->rightshift
== 0
17917 ? ((insn
& (0x3fu
<< 26)) == 28u << 26 /* andi */
17918 || (insn
& (0x3fu
<< 26)) == 24u << 26 /* ori */
17919 || (insn
& (0x3fu
<< 26)) == 26u << 26 /* xori */)
17920 : ((insn
& (0x3fu
<< 26)) == 29u << 26 /* andis */
17921 || (insn
& (0x3fu
<< 26)) == 25u << 26 /* oris */
17922 || (insn
& (0x3fu
<< 26)) == 27u << 26 /* xoris */))
17923 complain
= complain_overflow_unsigned
;
17924 if (howto
->complain_on_overflow
!= complain
)
17926 alt_howto
= *howto
;
17927 alt_howto
.complain_on_overflow
= complain
;
17928 howto
= &alt_howto
;
17934 /* Split field relocs aren't handled by _bfd_final_link_relocate. */
17936 case R_PPC64_D34_LO
:
17937 case R_PPC64_D34_HI30
:
17938 case R_PPC64_D34_HA30
:
17939 case R_PPC64_PCREL34
:
17940 case R_PPC64_GOT_PCREL34
:
17941 case R_PPC64_TPREL34
:
17942 case R_PPC64_DTPREL34
:
17943 case R_PPC64_GOT_TLSGD_PCREL34
:
17944 case R_PPC64_GOT_TLSLD_PCREL34
:
17945 case R_PPC64_GOT_TPREL_PCREL34
:
17946 case R_PPC64_GOT_DTPREL_PCREL34
:
17947 case R_PPC64_PLT_PCREL34
:
17948 case R_PPC64_PLT_PCREL34_NOTOC
:
17950 case R_PPC64_PCREL28
:
17951 if (!offset_in_range (input_section
, rel
->r_offset
, 8))
17952 r
= bfd_reloc_outofrange
;
17955 relocation
+= addend
;
17956 if (howto
->pc_relative
)
17957 relocation
-= (rel
->r_offset
17958 + input_section
->output_offset
17959 + input_section
->output_section
->vma
);
17960 relocation
>>= howto
->rightshift
;
17962 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17964 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
17966 pinsn
&= ~howto
->dst_mask
;
17967 pinsn
|= (((relocation
<< 16) | (relocation
& 0xffff))
17968 & howto
->dst_mask
);
17969 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ rel
->r_offset
);
17970 bfd_put_32 (input_bfd
, pinsn
, contents
+ rel
->r_offset
+ 4);
17972 if (howto
->complain_on_overflow
== complain_overflow_signed
17973 && (relocation
+ (1ULL << (howto
->bitsize
- 1))
17974 >= 1ULL << howto
->bitsize
))
17975 r
= bfd_reloc_overflow
;
17979 case R_PPC64_REL16DX_HA
:
17980 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
17981 r
= bfd_reloc_outofrange
;
17984 relocation
+= addend
;
17985 relocation
-= (rel
->r_offset
17986 + input_section
->output_offset
17987 + input_section
->output_section
->vma
);
17988 relocation
= (bfd_signed_vma
) relocation
>> 16;
17989 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17991 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
17992 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
17994 if (relocation
+ 0x8000 > 0xffff)
17995 r
= bfd_reloc_overflow
;
18000 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
18001 contents
, rel
->r_offset
,
18002 relocation
, addend
);
18005 if (r
!= bfd_reloc_ok
)
18007 char *more_info
= NULL
;
18008 const char *reloc_name
= howto
->name
;
18010 if (reloc_dest
!= DEST_NORMAL
)
18012 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
18013 if (more_info
!= NULL
)
18015 strcpy (more_info
, reloc_name
);
18016 strcat (more_info
, (reloc_dest
== DEST_OPD
18017 ? " (OPD)" : " (stub)"));
18018 reloc_name
= more_info
;
18022 if (r
== bfd_reloc_overflow
)
18024 /* On code like "if (foo) foo();" don't report overflow
18025 on a branch to zero when foo is undefined. */
18027 && (reloc_dest
== DEST_STUB
18029 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
18030 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
18031 && is_branch_reloc (r_type
))))
18032 info
->callbacks
->reloc_overflow
18033 (info
, (struct bfd_link_hash_entry
*) h
, sym_name
,
18034 reloc_name
, orig_rel
.r_addend
, input_bfd
, input_section
,
18039 info
->callbacks
->einfo
18040 /* xgettext:c-format */
18041 (_("%H: %s against `%pT': error %d\n"),
18042 input_bfd
, input_section
, rel
->r_offset
,
18043 reloc_name
, sym_name
, (int) r
);
18055 Elf_Internal_Shdr
*rel_hdr
;
18056 size_t deleted
= rel
- wrel
;
18058 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
18059 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
18060 if (rel_hdr
->sh_size
== 0)
18062 /* It is too late to remove an empty reloc section. Leave
18064 ??? What is wrong with an empty section??? */
18065 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
18068 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
18069 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
18070 input_section
->reloc_count
-= deleted
;
18073 /* If we're emitting relocations, then shortly after this function
18074 returns, reloc offsets and addends for this section will be
18075 adjusted. Worse, reloc symbol indices will be for the output
18076 file rather than the input. Save a copy of the relocs for
18077 opd_entry_value. */
18079 && (info
->emitrelocations
|| bfd_link_relocatable (info
))
18080 && input_section
->reloc_count
!= 0)
18083 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
18084 rel
= bfd_alloc (input_bfd
, amt
);
18085 ppc64_elf_section_data (input_section
)->u
.opd
.u
.relocs
= rel
;
18088 memcpy (rel
, relocs
, amt
);
18093 /* Adjust the value of any local symbols in opd sections. */
18096 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
18097 const char *name ATTRIBUTE_UNUSED
,
18098 Elf_Internal_Sym
*elfsym
,
18099 asection
*input_sec
,
18100 struct elf_link_hash_entry
*h
)
18102 struct _opd_sec_data
*opd
;
18109 opd
= get_opd_info (input_sec
);
18110 if (opd
== NULL
|| opd
->adjust
== NULL
)
18113 value
= elfsym
->st_value
- input_sec
->output_offset
;
18114 if (!bfd_link_relocatable (info
))
18115 value
-= input_sec
->output_section
->vma
;
18117 adjust
= opd
->adjust
[OPD_NDX (value
)];
18121 elfsym
->st_value
+= adjust
;
18125 /* Finish up dynamic symbol handling. We set the contents of various
18126 dynamic sections here. */
18129 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
18130 struct bfd_link_info
*info
,
18131 struct elf_link_hash_entry
*h
,
18132 Elf_Internal_Sym
*sym
)
18134 struct ppc_link_hash_table
*htab
;
18135 struct plt_entry
*ent
;
18137 htab
= ppc_hash_table (info
);
18139 if (!htab
->opd_abi
&& !h
->def_regular
)
18140 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
18141 if (ent
->plt
.offset
!= (bfd_vma
) -1)
18143 /* Mark the symbol as undefined, rather than as
18144 defined in glink. Leave the value if there were
18145 any relocations where pointer equality matters
18146 (this is a clue for the dynamic linker, to make
18147 function pointer comparisons work between an
18148 application and shared library), otherwise set it
18150 sym
->st_shndx
= SHN_UNDEF
;
18151 if (!h
->pointer_equality_needed
)
18153 else if (!h
->ref_regular_nonweak
)
18155 /* This breaks function pointer comparisons, but
18156 that is better than breaking tests for a NULL
18157 function pointer. */
18164 && (h
->root
.type
== bfd_link_hash_defined
18165 || h
->root
.type
== bfd_link_hash_defweak
)
18166 && (h
->root
.u
.def
.section
== htab
->elf
.sdynbss
18167 || h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
))
18169 /* This symbol needs a copy reloc. Set it up. */
18170 Elf_Internal_Rela rela
;
18173 if (h
->dynindx
== -1)
18176 rela
.r_offset
= defined_sym_val (h
);
18177 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
18179 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
18180 srel
= htab
->elf
.sreldynrelro
;
18182 srel
= htab
->elf
.srelbss
;
18183 BFD_ASSERT (count_and_swap_reloc_out (output_bfd
, &rela
, srel
));
18189 /* Used to decide how to sort relocs in an optimal manner for the
18190 dynamic linker, before writing them out. */
18192 static enum elf_reloc_type_class
18193 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
18194 const asection
*rel_sec
,
18195 const Elf_Internal_Rela
*rela
)
18197 enum elf_ppc64_reloc_type r_type
;
18198 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
18200 if (rel_sec
== htab
->elf
.irelplt
)
18201 return reloc_class_ifunc
;
18203 r_type
= ELF64_R_TYPE (rela
->r_info
);
18206 case R_PPC64_RELATIVE
:
18207 return reloc_class_relative
;
18208 case R_PPC64_JMP_SLOT
:
18209 return reloc_class_plt
;
18211 return reloc_class_copy
;
18213 return reloc_class_normal
;
18217 /* Finish up the dynamic sections. */
18220 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
18221 struct bfd_link_info
*info
)
18223 struct ppc_link_hash_table
*htab
;
18227 htab
= ppc_hash_table (info
);
18231 dynobj
= htab
->elf
.dynobj
;
18232 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
18234 if (htab
->elf
.dynamic_sections_created
)
18236 Elf64_External_Dyn
*dyncon
, *dynconend
;
18238 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
18241 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
18242 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
18243 for (; dyncon
< dynconend
; dyncon
++)
18245 Elf_Internal_Dyn dyn
;
18248 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
18255 case DT_PPC64_GLINK
:
18257 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18258 /* We stupidly defined DT_PPC64_GLINK to be the start
18259 of glink rather than the first entry point, which is
18260 what ld.so needs, and now have a bigger stub to
18261 support automatic multiple TOCs. */
18262 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
18266 s
= bfd_get_section_by_name (output_bfd
, ".opd");
18269 dyn
.d_un
.d_ptr
= s
->vma
;
18273 if ((htab
->do_multi_toc
&& htab
->multi_toc_needed
)
18274 || htab
->notoc_plt
)
18275 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
18276 if (htab
->has_plt_localentry0
)
18277 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
18280 case DT_PPC64_OPDSZ
:
18281 s
= bfd_get_section_by_name (output_bfd
, ".opd");
18284 dyn
.d_un
.d_val
= s
->size
;
18288 s
= htab
->elf
.splt
;
18289 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18293 s
= htab
->elf
.srelplt
;
18294 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18298 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
18302 if (htab
->elf
.ifunc_resolvers
)
18303 info
->callbacks
->einfo
18304 (_("%P: warning: text relocations and GNU indirect "
18305 "functions may result in a segfault at runtime\n"));
18309 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
18313 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
18314 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
18316 /* Fill in the first entry in the global offset table.
18317 We use it to hold the link-time TOCbase. */
18318 bfd_put_64 (output_bfd
,
18319 elf_gp (output_bfd
) + TOC_BASE_OFF
,
18320 htab
->elf
.sgot
->contents
);
18322 /* Set .got entry size. */
18323 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
18327 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
18328 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
18330 /* Set .plt entry size. */
18331 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
18332 = PLT_ENTRY_SIZE (htab
);
18335 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
18336 brlt ourselves if emitrelocations. */
18337 if (htab
->brlt
!= NULL
18338 && htab
->brlt
->reloc_count
!= 0
18339 && !_bfd_elf_link_output_relocs (output_bfd
,
18341 elf_section_data (htab
->brlt
)->rela
.hdr
,
18342 elf_section_data (htab
->brlt
)->relocs
,
18346 if (htab
->glink
!= NULL
18347 && htab
->glink
->reloc_count
!= 0
18348 && !_bfd_elf_link_output_relocs (output_bfd
,
18350 elf_section_data (htab
->glink
)->rela
.hdr
,
18351 elf_section_data (htab
->glink
)->relocs
,
18356 if (htab
->glink_eh_frame
!= NULL
18357 && htab
->glink_eh_frame
->size
!= 0
18358 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
18359 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
18360 htab
->glink_eh_frame
,
18361 htab
->glink_eh_frame
->contents
))
18364 /* We need to handle writing out multiple GOT sections ourselves,
18365 since we didn't add them to DYNOBJ. We know dynobj is the first
18367 while ((dynobj
= dynobj
->link
.next
) != NULL
)
18371 if (!is_ppc64_elf (dynobj
))
18374 s
= ppc64_elf_tdata (dynobj
)->got
;
18377 && s
->output_section
!= bfd_abs_section_ptr
18378 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
18379 s
->contents
, s
->output_offset
,
18382 s
= ppc64_elf_tdata (dynobj
)->relgot
;
18385 && s
->output_section
!= bfd_abs_section_ptr
18386 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
18387 s
->contents
, s
->output_offset
,
18396 ppc64_elf_free_cached_info (bfd
*abfd
)
18398 if (abfd
->sections
)
18399 for (asection
*opd
= bfd_get_section_by_name (abfd
, ".opd");
18401 opd
= bfd_get_next_section_by_name (NULL
, opd
))
18402 if (opd
->reloc_count
== 0)
18403 free (ppc64_elf_section_data (opd
)->u
.opd
.u
.contents
);
18405 return _bfd_elf_free_cached_info (abfd
);
18408 #include "elf64-target.h"
18410 /* FreeBSD support */
18412 #undef TARGET_LITTLE_SYM
18413 #define TARGET_LITTLE_SYM powerpc_elf64_fbsd_le_vec
18414 #undef TARGET_LITTLE_NAME
18415 #define TARGET_LITTLE_NAME "elf64-powerpcle-freebsd"
18417 #undef TARGET_BIG_SYM
18418 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
18419 #undef TARGET_BIG_NAME
18420 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
18423 #define ELF_OSABI ELFOSABI_FREEBSD
18426 #define elf64_bed elf64_powerpc_fbsd_bed
18428 #include "elf64-target.h"