1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2021 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 /* Don't generate unused section symbols. */
29 #define TARGET_KEEP_UNUSED_SECTION_SYMBOLS false
37 #include "elf/ppc64.h"
38 #include "elf64-ppc.h"
41 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
42 #define OCTETS_PER_BYTE(ABFD, SEC) 1
44 static bfd_reloc_status_type ppc64_elf_ha_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_branch_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_toc_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
57 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
58 static bfd_reloc_status_type ppc64_elf_toc64_reloc
59 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
60 static bfd_reloc_status_type ppc64_elf_prefix_reloc
61 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
62 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
63 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
64 static bfd_vma opd_entry_value
65 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bool);
67 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
68 #define TARGET_LITTLE_NAME "elf64-powerpcle"
69 #define TARGET_BIG_SYM powerpc_elf64_vec
70 #define TARGET_BIG_NAME "elf64-powerpc"
71 #define ELF_ARCH bfd_arch_powerpc
72 #define ELF_TARGET_ID PPC64_ELF_DATA
73 #define ELF_MACHINE_CODE EM_PPC64
74 #define ELF_MAXPAGESIZE 0x10000
75 #define ELF_COMMONPAGESIZE 0x1000
76 #define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
77 #define elf_info_to_howto ppc64_elf_info_to_howto
79 #define elf_backend_want_got_sym 0
80 #define elf_backend_want_plt_sym 0
81 #define elf_backend_plt_alignment 3
82 #define elf_backend_plt_not_loaded 1
83 #define elf_backend_got_header_size 8
84 #define elf_backend_want_dynrelro 1
85 #define elf_backend_can_gc_sections 1
86 #define elf_backend_can_refcount 1
87 #define elf_backend_rela_normal 1
88 #define elf_backend_dtrel_excludes_plt 1
89 #define elf_backend_default_execstack 0
91 #define bfd_elf64_mkobject ppc64_elf_mkobject
92 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
93 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
94 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
95 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
96 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
97 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
98 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
99 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
100 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
102 #define elf_backend_object_p ppc64_elf_object_p
103 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
104 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
105 #define elf_backend_write_core_note ppc64_elf_write_core_note
106 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
107 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
108 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
109 #define elf_backend_check_directives ppc64_elf_before_check_relocs
110 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
111 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
112 #define elf_backend_check_relocs ppc64_elf_check_relocs
113 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
114 #define elf_backend_gc_keep ppc64_elf_gc_keep
115 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
116 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
117 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
118 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
119 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
120 #define elf_backend_always_size_sections ppc64_elf_edit
121 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
122 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
123 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
124 #define elf_backend_action_discarded ppc64_elf_action_discarded
125 #define elf_backend_relocate_section ppc64_elf_relocate_section
126 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
127 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
128 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
129 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
130 #define elf_backend_special_sections ppc64_elf_special_sections
131 #define elf_backend_section_flags ppc64_elf_section_flags
132 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
133 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
134 #define elf_backend_get_reloc_section bfd_get_section_by_name
136 /* The name of the dynamic interpreter. This is put in the .interp
138 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
140 /* The size in bytes of an entry in the procedure linkage table. */
141 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
142 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
144 /* The initial size of the plt reserved for the dynamic linker. */
145 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
147 /* Offsets to some stack save slots. */
149 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
150 /* This one is dodgy. ELFv2 does not have a linker word, so use the
151 CR save slot. Used only by optimised __tls_get_addr call stub,
152 relying on __tls_get_addr_opt not saving CR.. */
153 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
155 /* TOC base pointers offset from start of TOC. */
156 #define TOC_BASE_OFF 0x8000
157 /* TOC base alignment. */
158 #define TOC_BASE_ALIGN 256
160 /* Offset of tp and dtp pointers from start of TLS block. */
161 #define TP_OFFSET 0x7000
162 #define DTP_OFFSET 0x8000
164 /* .plt call stub instructions. The normal stub is like this, but
165 sometimes the .plt entry crosses a 64k boundary and we need to
166 insert an addi to adjust r11. */
167 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
168 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
169 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
170 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
171 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
172 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
173 #define BCTR 0x4e800420 /* bctr */
175 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
176 #define ADDI_R12_R11 0x398b0000 /* addi %r12,%r11,off@l */
177 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
178 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
179 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
181 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
182 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
183 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
184 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
185 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
186 #define BNECTR 0x4ca20420 /* bnectr+ */
187 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
189 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
190 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
191 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
193 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
194 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
195 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
197 #define LI_R11_0 0x39600000 /* li %r11,0 */
198 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
199 #define LIS_R11 0x3d600000 /* lis %r11,xxx@ha */
200 #define LIS_R12 0x3d800000 /* lis %r12,xxx@ha */
201 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
202 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
203 #define ADDIS_R12_R11 0x3d8b0000 /* addis %r12,%r11,xxx@ha */
204 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
205 #define ORIS_R12_R12_0 0x658c0000 /* oris %r12,%r12,xxx@hi */
206 #define ORI_R11_R11_0 0x616b0000 /* ori %r11,%r11,xxx@l */
207 #define ORI_R12_R12_0 0x618c0000 /* ori %r12,%r12,xxx@l */
208 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
209 #define SLDI_R11_R11_34 0x796b1746 /* sldi %r11,%r11,34 */
210 #define SLDI_R12_R12_32 0x799c07c6 /* sldi %r12,%r12,32 */
211 #define LDX_R12_R11_R12 0x7d8b602a /* ldx %r12,%r11,%r12 */
212 #define ADD_R12_R11_R12 0x7d8b6214 /* add %r12,%r11,%r12 */
213 #define PADDI_R12_PC 0x0610000039800000ULL
214 #define PLD_R12_PC 0x04100000e5800000ULL
215 #define PNOP 0x0700000000000000ULL
217 /* __glink_PLTresolve stub instructions. We enter with the index in
218 R0 for ELFv1, and the address of a glink branch in R12 for ELFv2. */
219 #define GLINK_PLTRESOLVE_SIZE(htab) \
220 (8u + (htab->opd_abi ? 11 * 4 : htab->has_plt_localentry0 ? 14 * 4 : 13 * 4))
224 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
225 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
227 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
228 /* ld %2,(0b-1b)(%11) */
229 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
230 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
237 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
238 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
239 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
240 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
241 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
242 #define LD_R0_0R11 0xe80b0000 /* ld %r0,0(%r11) */
243 #define ADD_R11_R0_R11 0x7d605a14 /* add %r11,%r0,%r11 */
246 #define NOP 0x60000000
248 /* Some other nops. */
249 #define CROR_151515 0x4def7b82
250 #define CROR_313131 0x4ffffb82
252 /* .glink entries for the first 32k functions are two instructions. */
253 #define LI_R0_0 0x38000000 /* li %r0,0 */
254 #define B_DOT 0x48000000 /* b . */
256 /* After that, we need two instructions to load the index, followed by
258 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
259 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
261 /* Instructions used by the save and restore reg functions. */
262 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
263 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
264 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
265 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
266 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
267 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
268 #define LI_R12_0 0x39800000 /* li %r12,0 */
269 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
270 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
271 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
272 #define BLR 0x4e800020 /* blr */
274 /* Since .opd is an array of descriptors and each entry will end up
275 with identical R_PPC64_RELATIVE relocs, there is really no need to
276 propagate .opd relocs; The dynamic linker should be taught to
277 relocate .opd without reloc entries. */
278 #ifndef NO_OPD_RELOCS
279 #define NO_OPD_RELOCS 0
283 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
287 abiversion (bfd
*abfd
)
289 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
293 set_abiversion (bfd
*abfd
, int ver
)
295 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
296 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
299 /* Relocation HOWTO's. */
300 /* Like other ELF RELA targets that don't apply multiple
301 field-altering relocations to the same localation, src_mask is
302 always zero and pcrel_offset is the same as pc_relative.
303 PowerPC can always use a zero bitpos, even when the field is not at
304 the LSB. For example, a REL24 could use rightshift=2, bisize=24
305 and bitpos=2 which matches the ABI description, or as we do here,
306 rightshift=0, bitsize=26 and bitpos=0. */
307 #define HOW(type, size, bitsize, mask, rightshift, pc_relative, \
308 complain, special_func) \
309 HOWTO (type, rightshift, size, bitsize, pc_relative, 0, \
310 complain_overflow_ ## complain, special_func, \
311 #type, false, 0, mask, pc_relative)
313 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
315 static reloc_howto_type ppc64_elf_howto_raw
[] =
317 /* This reloc does nothing. */
318 HOW (R_PPC64_NONE
, 3, 0, 0, 0, false, dont
,
319 bfd_elf_generic_reloc
),
321 /* A standard 32 bit relocation. */
322 HOW (R_PPC64_ADDR32
, 2, 32, 0xffffffff, 0, false, bitfield
,
323 bfd_elf_generic_reloc
),
325 /* An absolute 26 bit branch; the lower two bits must be zero.
326 FIXME: we don't check that, we just clear them. */
327 HOW (R_PPC64_ADDR24
, 2, 26, 0x03fffffc, 0, false, bitfield
,
328 bfd_elf_generic_reloc
),
330 /* A standard 16 bit relocation. */
331 HOW (R_PPC64_ADDR16
, 1, 16, 0xffff, 0, false, bitfield
,
332 bfd_elf_generic_reloc
),
334 /* A 16 bit relocation without overflow. */
335 HOW (R_PPC64_ADDR16_LO
, 1, 16, 0xffff, 0, false, dont
,
336 bfd_elf_generic_reloc
),
338 /* Bits 16-31 of an address. */
339 HOW (R_PPC64_ADDR16_HI
, 1, 16, 0xffff, 16, false, signed,
340 bfd_elf_generic_reloc
),
342 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
343 bits, treated as a signed number, is negative. */
344 HOW (R_PPC64_ADDR16_HA
, 1, 16, 0xffff, 16, false, signed,
347 /* An absolute 16 bit branch; the lower two bits must be zero.
348 FIXME: we don't check that, we just clear them. */
349 HOW (R_PPC64_ADDR14
, 2, 16, 0x0000fffc, 0, false, signed,
350 ppc64_elf_branch_reloc
),
352 /* An absolute 16 bit branch, for which bit 10 should be set to
353 indicate that the branch is expected to be taken. The lower two
354 bits must be zero. */
355 HOW (R_PPC64_ADDR14_BRTAKEN
, 2, 16, 0x0000fffc, 0, false, signed,
356 ppc64_elf_brtaken_reloc
),
358 /* An absolute 16 bit branch, for which bit 10 should be set to
359 indicate that the branch is not expected to be taken. The lower
360 two bits must be zero. */
361 HOW (R_PPC64_ADDR14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, false, signed,
362 ppc64_elf_brtaken_reloc
),
364 /* A relative 26 bit branch; the lower two bits must be zero. */
365 HOW (R_PPC64_REL24
, 2, 26, 0x03fffffc, 0, true, signed,
366 ppc64_elf_branch_reloc
),
368 /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer. */
369 HOW (R_PPC64_REL24_NOTOC
, 2, 26, 0x03fffffc, 0, true, signed,
370 ppc64_elf_branch_reloc
),
372 /* A relative 16 bit branch; the lower two bits must be zero. */
373 HOW (R_PPC64_REL14
, 2, 16, 0x0000fffc, 0, true, signed,
374 ppc64_elf_branch_reloc
),
376 /* A relative 16 bit branch. Bit 10 should be set to indicate that
377 the branch is expected to be taken. The lower two bits must be
379 HOW (R_PPC64_REL14_BRTAKEN
, 2, 16, 0x0000fffc, 0, true, signed,
380 ppc64_elf_brtaken_reloc
),
382 /* A relative 16 bit branch. Bit 10 should be set to indicate that
383 the branch is not expected to be taken. The lower two bits must
385 HOW (R_PPC64_REL14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, true, signed,
386 ppc64_elf_brtaken_reloc
),
388 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
390 HOW (R_PPC64_GOT16
, 1, 16, 0xffff, 0, false, signed,
391 ppc64_elf_unhandled_reloc
),
393 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
395 HOW (R_PPC64_GOT16_LO
, 1, 16, 0xffff, 0, false, dont
,
396 ppc64_elf_unhandled_reloc
),
398 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
400 HOW (R_PPC64_GOT16_HI
, 1, 16, 0xffff, 16, false, signed,
401 ppc64_elf_unhandled_reloc
),
403 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
405 HOW (R_PPC64_GOT16_HA
, 1, 16, 0xffff, 16, false, signed,
406 ppc64_elf_unhandled_reloc
),
408 /* This is used only by the dynamic linker. The symbol should exist
409 both in the object being run and in some shared library. The
410 dynamic linker copies the data addressed by the symbol from the
411 shared library into the object, because the object being
412 run has to have the data at some particular address. */
413 HOW (R_PPC64_COPY
, 0, 0, 0, 0, false, dont
,
414 ppc64_elf_unhandled_reloc
),
416 /* Like R_PPC64_ADDR64, but used when setting global offset table
418 HOW (R_PPC64_GLOB_DAT
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
419 ppc64_elf_unhandled_reloc
),
421 /* Created by the link editor. Marks a procedure linkage table
422 entry for a symbol. */
423 HOW (R_PPC64_JMP_SLOT
, 0, 0, 0, 0, false, dont
,
424 ppc64_elf_unhandled_reloc
),
426 /* Used only by the dynamic linker. When the object is run, this
427 doubleword64 is set to the load address of the object, plus the
429 HOW (R_PPC64_RELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
430 bfd_elf_generic_reloc
),
432 /* Like R_PPC64_ADDR32, but may be unaligned. */
433 HOW (R_PPC64_UADDR32
, 2, 32, 0xffffffff, 0, false, bitfield
,
434 bfd_elf_generic_reloc
),
436 /* Like R_PPC64_ADDR16, but may be unaligned. */
437 HOW (R_PPC64_UADDR16
, 1, 16, 0xffff, 0, false, bitfield
,
438 bfd_elf_generic_reloc
),
440 /* 32-bit PC relative. */
441 HOW (R_PPC64_REL32
, 2, 32, 0xffffffff, 0, true, signed,
442 bfd_elf_generic_reloc
),
444 /* 32-bit relocation to the symbol's procedure linkage table. */
445 HOW (R_PPC64_PLT32
, 2, 32, 0xffffffff, 0, false, bitfield
,
446 ppc64_elf_unhandled_reloc
),
448 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
449 FIXME: R_PPC64_PLTREL32 not supported. */
450 HOW (R_PPC64_PLTREL32
, 2, 32, 0xffffffff, 0, true, signed,
451 ppc64_elf_unhandled_reloc
),
453 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
455 HOW (R_PPC64_PLT16_LO
, 1, 16, 0xffff, 0, false, dont
,
456 ppc64_elf_unhandled_reloc
),
458 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
460 HOW (R_PPC64_PLT16_HI
, 1, 16, 0xffff, 16, false, signed,
461 ppc64_elf_unhandled_reloc
),
463 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
465 HOW (R_PPC64_PLT16_HA
, 1, 16, 0xffff, 16, false, signed,
466 ppc64_elf_unhandled_reloc
),
468 /* 16-bit section relative relocation. */
469 HOW (R_PPC64_SECTOFF
, 1, 16, 0xffff, 0, false, signed,
470 ppc64_elf_sectoff_reloc
),
472 /* Like R_PPC64_SECTOFF, but no overflow warning. */
473 HOW (R_PPC64_SECTOFF_LO
, 1, 16, 0xffff, 0, false, dont
,
474 ppc64_elf_sectoff_reloc
),
476 /* 16-bit upper half section relative relocation. */
477 HOW (R_PPC64_SECTOFF_HI
, 1, 16, 0xffff, 16, false, signed,
478 ppc64_elf_sectoff_reloc
),
480 /* 16-bit upper half adjusted section relative relocation. */
481 HOW (R_PPC64_SECTOFF_HA
, 1, 16, 0xffff, 16, false, signed,
482 ppc64_elf_sectoff_ha_reloc
),
484 /* Like R_PPC64_REL24 without touching the two least significant bits. */
485 HOW (R_PPC64_REL30
, 2, 30, 0xfffffffc, 2, true, dont
,
486 bfd_elf_generic_reloc
),
488 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
490 /* A standard 64-bit relocation. */
491 HOW (R_PPC64_ADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
492 bfd_elf_generic_reloc
),
494 /* The bits 32-47 of an address. */
495 HOW (R_PPC64_ADDR16_HIGHER
, 1, 16, 0xffff, 32, false, dont
,
496 bfd_elf_generic_reloc
),
498 /* The bits 32-47 of an address, plus 1 if the contents of the low
499 16 bits, treated as a signed number, is negative. */
500 HOW (R_PPC64_ADDR16_HIGHERA
, 1, 16, 0xffff, 32, false, dont
,
503 /* The bits 48-63 of an address. */
504 HOW (R_PPC64_ADDR16_HIGHEST
, 1, 16, 0xffff, 48, false, dont
,
505 bfd_elf_generic_reloc
),
507 /* The bits 48-63 of an address, plus 1 if the contents of the low
508 16 bits, treated as a signed number, is negative. */
509 HOW (R_PPC64_ADDR16_HIGHESTA
, 1, 16, 0xffff, 48, false, dont
,
512 /* Like ADDR64, but may be unaligned. */
513 HOW (R_PPC64_UADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
514 bfd_elf_generic_reloc
),
516 /* 64-bit relative relocation. */
517 HOW (R_PPC64_REL64
, 4, 64, 0xffffffffffffffffULL
, 0, true, dont
,
518 bfd_elf_generic_reloc
),
520 /* 64-bit relocation to the symbol's procedure linkage table. */
521 HOW (R_PPC64_PLT64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
522 ppc64_elf_unhandled_reloc
),
524 /* 64-bit PC relative relocation to the symbol's procedure linkage
526 /* FIXME: R_PPC64_PLTREL64 not supported. */
527 HOW (R_PPC64_PLTREL64
, 4, 64, 0xffffffffffffffffULL
, 0, true, dont
,
528 ppc64_elf_unhandled_reloc
),
530 /* 16 bit TOC-relative relocation. */
531 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
532 HOW (R_PPC64_TOC16
, 1, 16, 0xffff, 0, false, signed,
533 ppc64_elf_toc_reloc
),
535 /* 16 bit TOC-relative relocation without overflow. */
536 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
537 HOW (R_PPC64_TOC16_LO
, 1, 16, 0xffff, 0, false, dont
,
538 ppc64_elf_toc_reloc
),
540 /* 16 bit TOC-relative relocation, high 16 bits. */
541 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
542 HOW (R_PPC64_TOC16_HI
, 1, 16, 0xffff, 16, false, signed,
543 ppc64_elf_toc_reloc
),
545 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
546 contents of the low 16 bits, treated as a signed number, is
548 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
549 HOW (R_PPC64_TOC16_HA
, 1, 16, 0xffff, 16, false, signed,
550 ppc64_elf_toc_ha_reloc
),
552 /* 64-bit relocation; insert value of TOC base (.TOC.). */
553 /* R_PPC64_TOC 51 doubleword64 .TOC. */
554 HOW (R_PPC64_TOC
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
555 ppc64_elf_toc64_reloc
),
557 /* Like R_PPC64_GOT16, but also informs the link editor that the
558 value to relocate may (!) refer to a PLT entry which the link
559 editor (a) may replace with the symbol value. If the link editor
560 is unable to fully resolve the symbol, it may (b) create a PLT
561 entry and store the address to the new PLT entry in the GOT.
562 This permits lazy resolution of function symbols at run time.
563 The link editor may also skip all of this and just (c) emit a
564 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
565 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
566 HOW (R_PPC64_PLTGOT16
, 1, 16, 0xffff, 0, false,signed,
567 ppc64_elf_unhandled_reloc
),
569 /* Like R_PPC64_PLTGOT16, but without overflow. */
570 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
571 HOW (R_PPC64_PLTGOT16_LO
, 1, 16, 0xffff, 0, false, dont
,
572 ppc64_elf_unhandled_reloc
),
574 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
575 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
576 HOW (R_PPC64_PLTGOT16_HI
, 1, 16, 0xffff, 16, false, signed,
577 ppc64_elf_unhandled_reloc
),
579 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
580 1 if the contents of the low 16 bits, treated as a signed number,
582 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
583 HOW (R_PPC64_PLTGOT16_HA
, 1, 16, 0xffff, 16, false, signed,
584 ppc64_elf_unhandled_reloc
),
586 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
587 HOW (R_PPC64_ADDR16_DS
, 1, 16, 0xfffc, 0, false, signed,
588 bfd_elf_generic_reloc
),
590 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
591 HOW (R_PPC64_ADDR16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
592 bfd_elf_generic_reloc
),
594 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
595 HOW (R_PPC64_GOT16_DS
, 1, 16, 0xfffc, 0, false, signed,
596 ppc64_elf_unhandled_reloc
),
598 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
599 HOW (R_PPC64_GOT16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
600 ppc64_elf_unhandled_reloc
),
602 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
603 HOW (R_PPC64_PLT16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
604 ppc64_elf_unhandled_reloc
),
606 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
607 HOW (R_PPC64_SECTOFF_DS
, 1, 16, 0xfffc, 0, false, signed,
608 ppc64_elf_sectoff_reloc
),
610 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
611 HOW (R_PPC64_SECTOFF_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
612 ppc64_elf_sectoff_reloc
),
614 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
615 HOW (R_PPC64_TOC16_DS
, 1, 16, 0xfffc, 0, false, signed,
616 ppc64_elf_toc_reloc
),
618 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
619 HOW (R_PPC64_TOC16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
620 ppc64_elf_toc_reloc
),
622 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
623 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
624 HOW (R_PPC64_PLTGOT16_DS
, 1, 16, 0xfffc, 0, false, signed,
625 ppc64_elf_unhandled_reloc
),
627 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
628 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
629 HOW (R_PPC64_PLTGOT16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
630 ppc64_elf_unhandled_reloc
),
632 /* Marker relocs for TLS. */
633 HOW (R_PPC64_TLS
, 2, 32, 0, 0, false, dont
,
634 bfd_elf_generic_reloc
),
636 HOW (R_PPC64_TLSGD
, 2, 32, 0, 0, false, dont
,
637 bfd_elf_generic_reloc
),
639 HOW (R_PPC64_TLSLD
, 2, 32, 0, 0, false, dont
,
640 bfd_elf_generic_reloc
),
642 /* Marker reloc for optimizing r2 save in prologue rather than on
643 each plt call stub. */
644 HOW (R_PPC64_TOCSAVE
, 2, 32, 0, 0, false, dont
,
645 bfd_elf_generic_reloc
),
647 /* Marker relocs on inline plt call instructions. */
648 HOW (R_PPC64_PLTSEQ
, 2, 32, 0, 0, false, dont
,
649 bfd_elf_generic_reloc
),
651 HOW (R_PPC64_PLTCALL
, 2, 32, 0, 0, false, dont
,
652 bfd_elf_generic_reloc
),
654 /* Computes the load module index of the load module that contains the
655 definition of its TLS sym. */
656 HOW (R_PPC64_DTPMOD64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
657 ppc64_elf_unhandled_reloc
),
659 /* Computes a dtv-relative displacement, the difference between the value
660 of sym+add and the base address of the thread-local storage block that
661 contains the definition of sym, minus 0x8000. */
662 HOW (R_PPC64_DTPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
663 ppc64_elf_unhandled_reloc
),
665 /* A 16 bit dtprel reloc. */
666 HOW (R_PPC64_DTPREL16
, 1, 16, 0xffff, 0, false, signed,
667 ppc64_elf_unhandled_reloc
),
669 /* Like DTPREL16, but no overflow. */
670 HOW (R_PPC64_DTPREL16_LO
, 1, 16, 0xffff, 0, false, dont
,
671 ppc64_elf_unhandled_reloc
),
673 /* Like DTPREL16_LO, but next higher group of 16 bits. */
674 HOW (R_PPC64_DTPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
675 ppc64_elf_unhandled_reloc
),
677 /* Like DTPREL16_HI, but adjust for low 16 bits. */
678 HOW (R_PPC64_DTPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
679 ppc64_elf_unhandled_reloc
),
681 /* Like DTPREL16_HI, but next higher group of 16 bits. */
682 HOW (R_PPC64_DTPREL16_HIGHER
, 1, 16, 0xffff, 32, false, dont
,
683 ppc64_elf_unhandled_reloc
),
685 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
686 HOW (R_PPC64_DTPREL16_HIGHERA
, 1, 16, 0xffff, 32, false, dont
,
687 ppc64_elf_unhandled_reloc
),
689 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
690 HOW (R_PPC64_DTPREL16_HIGHEST
, 1, 16, 0xffff, 48, false, dont
,
691 ppc64_elf_unhandled_reloc
),
693 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
694 HOW (R_PPC64_DTPREL16_HIGHESTA
, 1, 16, 0xffff, 48, false, dont
,
695 ppc64_elf_unhandled_reloc
),
697 /* Like DTPREL16, but for insns with a DS field. */
698 HOW (R_PPC64_DTPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
699 ppc64_elf_unhandled_reloc
),
701 /* Like DTPREL16_DS, but no overflow. */
702 HOW (R_PPC64_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
703 ppc64_elf_unhandled_reloc
),
705 /* Computes a tp-relative displacement, the difference between the value of
706 sym+add and the value of the thread pointer (r13). */
707 HOW (R_PPC64_TPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
708 ppc64_elf_unhandled_reloc
),
710 /* A 16 bit tprel reloc. */
711 HOW (R_PPC64_TPREL16
, 1, 16, 0xffff, 0, false, signed,
712 ppc64_elf_unhandled_reloc
),
714 /* Like TPREL16, but no overflow. */
715 HOW (R_PPC64_TPREL16_LO
, 1, 16, 0xffff, 0, false, dont
,
716 ppc64_elf_unhandled_reloc
),
718 /* Like TPREL16_LO, but next higher group of 16 bits. */
719 HOW (R_PPC64_TPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
720 ppc64_elf_unhandled_reloc
),
722 /* Like TPREL16_HI, but adjust for low 16 bits. */
723 HOW (R_PPC64_TPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
724 ppc64_elf_unhandled_reloc
),
726 /* Like TPREL16_HI, but next higher group of 16 bits. */
727 HOW (R_PPC64_TPREL16_HIGHER
, 1, 16, 0xffff, 32, false, dont
,
728 ppc64_elf_unhandled_reloc
),
730 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
731 HOW (R_PPC64_TPREL16_HIGHERA
, 1, 16, 0xffff, 32, false, dont
,
732 ppc64_elf_unhandled_reloc
),
734 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
735 HOW (R_PPC64_TPREL16_HIGHEST
, 1, 16, 0xffff, 48, false, dont
,
736 ppc64_elf_unhandled_reloc
),
738 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
739 HOW (R_PPC64_TPREL16_HIGHESTA
, 1, 16, 0xffff, 48, false, dont
,
740 ppc64_elf_unhandled_reloc
),
742 /* Like TPREL16, but for insns with a DS field. */
743 HOW (R_PPC64_TPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
744 ppc64_elf_unhandled_reloc
),
746 /* Like TPREL16_DS, but no overflow. */
747 HOW (R_PPC64_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
748 ppc64_elf_unhandled_reloc
),
750 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
751 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
752 to the first entry relative to the TOC base (r2). */
753 HOW (R_PPC64_GOT_TLSGD16
, 1, 16, 0xffff, 0, false, signed,
754 ppc64_elf_unhandled_reloc
),
756 /* Like GOT_TLSGD16, but no overflow. */
757 HOW (R_PPC64_GOT_TLSGD16_LO
, 1, 16, 0xffff, 0, false, dont
,
758 ppc64_elf_unhandled_reloc
),
760 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
761 HOW (R_PPC64_GOT_TLSGD16_HI
, 1, 16, 0xffff, 16, false, signed,
762 ppc64_elf_unhandled_reloc
),
764 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
765 HOW (R_PPC64_GOT_TLSGD16_HA
, 1, 16, 0xffff, 16, false, signed,
766 ppc64_elf_unhandled_reloc
),
768 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
769 with values (sym+add)@dtpmod and zero, and computes the offset to the
770 first entry relative to the TOC base (r2). */
771 HOW (R_PPC64_GOT_TLSLD16
, 1, 16, 0xffff, 0, false, signed,
772 ppc64_elf_unhandled_reloc
),
774 /* Like GOT_TLSLD16, but no overflow. */
775 HOW (R_PPC64_GOT_TLSLD16_LO
, 1, 16, 0xffff, 0, false, dont
,
776 ppc64_elf_unhandled_reloc
),
778 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
779 HOW (R_PPC64_GOT_TLSLD16_HI
, 1, 16, 0xffff, 16, false, signed,
780 ppc64_elf_unhandled_reloc
),
782 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
783 HOW (R_PPC64_GOT_TLSLD16_HA
, 1, 16, 0xffff, 16, false, signed,
784 ppc64_elf_unhandled_reloc
),
786 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
787 the offset to the entry relative to the TOC base (r2). */
788 HOW (R_PPC64_GOT_DTPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
789 ppc64_elf_unhandled_reloc
),
791 /* Like GOT_DTPREL16_DS, but no overflow. */
792 HOW (R_PPC64_GOT_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
793 ppc64_elf_unhandled_reloc
),
795 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
796 HOW (R_PPC64_GOT_DTPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
797 ppc64_elf_unhandled_reloc
),
799 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
800 HOW (R_PPC64_GOT_DTPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
801 ppc64_elf_unhandled_reloc
),
803 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
804 offset to the entry relative to the TOC base (r2). */
805 HOW (R_PPC64_GOT_TPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
806 ppc64_elf_unhandled_reloc
),
808 /* Like GOT_TPREL16_DS, but no overflow. */
809 HOW (R_PPC64_GOT_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
810 ppc64_elf_unhandled_reloc
),
812 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
813 HOW (R_PPC64_GOT_TPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
814 ppc64_elf_unhandled_reloc
),
816 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
817 HOW (R_PPC64_GOT_TPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
818 ppc64_elf_unhandled_reloc
),
820 HOW (R_PPC64_JMP_IREL
, 0, 0, 0, 0, false, dont
,
821 ppc64_elf_unhandled_reloc
),
823 HOW (R_PPC64_IRELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
824 bfd_elf_generic_reloc
),
826 /* A 16 bit relative relocation. */
827 HOW (R_PPC64_REL16
, 1, 16, 0xffff, 0, true, signed,
828 bfd_elf_generic_reloc
),
830 /* A 16 bit relative relocation without overflow. */
831 HOW (R_PPC64_REL16_LO
, 1, 16, 0xffff, 0, true, dont
,
832 bfd_elf_generic_reloc
),
834 /* The high order 16 bits of a relative address. */
835 HOW (R_PPC64_REL16_HI
, 1, 16, 0xffff, 16, true, signed,
836 bfd_elf_generic_reloc
),
838 /* The high order 16 bits of a relative address, plus 1 if the contents of
839 the low 16 bits, treated as a signed number, is negative. */
840 HOW (R_PPC64_REL16_HA
, 1, 16, 0xffff, 16, true, signed,
843 HOW (R_PPC64_REL16_HIGH
, 1, 16, 0xffff, 16, true, dont
,
844 bfd_elf_generic_reloc
),
846 HOW (R_PPC64_REL16_HIGHA
, 1, 16, 0xffff, 16, true, dont
,
849 HOW (R_PPC64_REL16_HIGHER
, 1, 16, 0xffff, 32, true, dont
,
850 bfd_elf_generic_reloc
),
852 HOW (R_PPC64_REL16_HIGHERA
, 1, 16, 0xffff, 32, true, dont
,
855 HOW (R_PPC64_REL16_HIGHEST
, 1, 16, 0xffff, 48, true, dont
,
856 bfd_elf_generic_reloc
),
858 HOW (R_PPC64_REL16_HIGHESTA
, 1, 16, 0xffff, 48, true, dont
,
861 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
862 HOW (R_PPC64_REL16DX_HA
, 2, 16, 0x1fffc1, 16, true, signed,
865 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
866 HOW (R_PPC64_16DX_HA
, 2, 16, 0x1fffc1, 16, false, signed,
869 /* Like R_PPC64_ADDR16_HI, but no overflow. */
870 HOW (R_PPC64_ADDR16_HIGH
, 1, 16, 0xffff, 16, false, dont
,
871 bfd_elf_generic_reloc
),
873 /* Like R_PPC64_ADDR16_HA, but no overflow. */
874 HOW (R_PPC64_ADDR16_HIGHA
, 1, 16, 0xffff, 16, false, dont
,
877 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
878 HOW (R_PPC64_DTPREL16_HIGH
, 1, 16, 0xffff, 16, false, dont
,
879 ppc64_elf_unhandled_reloc
),
881 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
882 HOW (R_PPC64_DTPREL16_HIGHA
, 1, 16, 0xffff, 16, false, dont
,
883 ppc64_elf_unhandled_reloc
),
885 /* Like R_PPC64_TPREL16_HI, but no overflow. */
886 HOW (R_PPC64_TPREL16_HIGH
, 1, 16, 0xffff, 16, false, dont
,
887 ppc64_elf_unhandled_reloc
),
889 /* Like R_PPC64_TPREL16_HA, but no overflow. */
890 HOW (R_PPC64_TPREL16_HIGHA
, 1, 16, 0xffff, 16, false, dont
,
891 ppc64_elf_unhandled_reloc
),
893 /* Marker reloc on ELFv2 large-model function entry. */
894 HOW (R_PPC64_ENTRY
, 2, 32, 0, 0, false, dont
,
895 bfd_elf_generic_reloc
),
897 /* Like ADDR64, but use local entry point of function. */
898 HOW (R_PPC64_ADDR64_LOCAL
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
899 bfd_elf_generic_reloc
),
901 HOW (R_PPC64_PLTSEQ_NOTOC
, 2, 32, 0, 0, false, dont
,
902 bfd_elf_generic_reloc
),
904 HOW (R_PPC64_PLTCALL_NOTOC
, 2, 32, 0, 0, false, dont
,
905 bfd_elf_generic_reloc
),
907 HOW (R_PPC64_PCREL_OPT
, 2, 32, 0, 0, false, dont
,
908 bfd_elf_generic_reloc
),
910 HOW (R_PPC64_D34
, 4, 34, 0x3ffff0000ffffULL
, 0, false, signed,
911 ppc64_elf_prefix_reloc
),
913 HOW (R_PPC64_D34_LO
, 4, 34, 0x3ffff0000ffffULL
, 0, false, dont
,
914 ppc64_elf_prefix_reloc
),
916 HOW (R_PPC64_D34_HI30
, 4, 34, 0x3ffff0000ffffULL
, 34, false, dont
,
917 ppc64_elf_prefix_reloc
),
919 HOW (R_PPC64_D34_HA30
, 4, 34, 0x3ffff0000ffffULL
, 34, false, dont
,
920 ppc64_elf_prefix_reloc
),
922 HOW (R_PPC64_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
923 ppc64_elf_prefix_reloc
),
925 HOW (R_PPC64_GOT_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
926 ppc64_elf_unhandled_reloc
),
928 HOW (R_PPC64_PLT_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
929 ppc64_elf_unhandled_reloc
),
931 HOW (R_PPC64_PLT_PCREL34_NOTOC
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
932 ppc64_elf_unhandled_reloc
),
934 HOW (R_PPC64_TPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, false, signed,
935 ppc64_elf_unhandled_reloc
),
937 HOW (R_PPC64_DTPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, false, signed,
938 ppc64_elf_unhandled_reloc
),
940 HOW (R_PPC64_GOT_TLSGD_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
941 ppc64_elf_unhandled_reloc
),
943 HOW (R_PPC64_GOT_TLSLD_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
944 ppc64_elf_unhandled_reloc
),
946 HOW (R_PPC64_GOT_TPREL_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
947 ppc64_elf_unhandled_reloc
),
949 HOW (R_PPC64_GOT_DTPREL_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
950 ppc64_elf_unhandled_reloc
),
952 HOW (R_PPC64_ADDR16_HIGHER34
, 1, 16, 0xffff, 34, false, dont
,
953 bfd_elf_generic_reloc
),
955 HOW (R_PPC64_ADDR16_HIGHERA34
, 1, 16, 0xffff, 34, false, dont
,
958 HOW (R_PPC64_ADDR16_HIGHEST34
, 1, 16, 0xffff, 50, false, dont
,
959 bfd_elf_generic_reloc
),
961 HOW (R_PPC64_ADDR16_HIGHESTA34
, 1, 16, 0xffff, 50, false, dont
,
964 HOW (R_PPC64_REL16_HIGHER34
, 1, 16, 0xffff, 34, true, dont
,
965 bfd_elf_generic_reloc
),
967 HOW (R_PPC64_REL16_HIGHERA34
, 1, 16, 0xffff, 34, true, dont
,
970 HOW (R_PPC64_REL16_HIGHEST34
, 1, 16, 0xffff, 50, true, dont
,
971 bfd_elf_generic_reloc
),
973 HOW (R_PPC64_REL16_HIGHESTA34
, 1, 16, 0xffff, 50, true, dont
,
976 HOW (R_PPC64_D28
, 4, 28, 0xfff0000ffffULL
, 0, false, signed,
977 ppc64_elf_prefix_reloc
),
979 HOW (R_PPC64_PCREL28
, 4, 28, 0xfff0000ffffULL
, 0, true, signed,
980 ppc64_elf_prefix_reloc
),
982 /* GNU extension to record C++ vtable hierarchy. */
983 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, false, dont
,
986 /* GNU extension to record C++ vtable member usage. */
987 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, false, dont
,
992 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
996 ppc_howto_init (void)
998 unsigned int i
, type
;
1000 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1002 type
= ppc64_elf_howto_raw
[i
].type
;
1003 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
1004 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1008 static reloc_howto_type
*
1009 ppc64_elf_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1011 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1013 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1014 /* Initialize howto table if needed. */
1020 /* xgettext:c-format */
1021 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
1023 bfd_set_error (bfd_error_bad_value
);
1026 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1028 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1030 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1032 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1034 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1036 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1038 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
1040 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1042 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
1044 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1046 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1048 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1050 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1052 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
1054 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1056 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1058 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1060 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1062 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1064 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1066 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1068 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1070 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1072 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1074 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1076 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1078 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1080 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1082 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1084 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1086 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1088 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1090 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1092 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1094 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1096 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1098 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1100 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1102 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1104 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1106 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1108 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1110 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1112 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1114 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1116 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1118 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1120 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1122 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1124 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1126 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1128 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1130 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1132 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1134 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1136 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1138 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1140 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1142 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1144 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1146 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1148 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1150 case BFD_RELOC_PPC64_TLS_PCREL
:
1151 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1153 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1155 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1157 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1159 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1161 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1163 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1165 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1167 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1169 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1171 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1173 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1175 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1177 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1179 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1181 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1183 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1185 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1187 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1189 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1191 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1193 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1195 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1197 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1199 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1201 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1203 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1205 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1207 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1209 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1211 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1213 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1215 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1217 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1219 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1221 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1223 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1225 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1227 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1229 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1231 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1233 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1235 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1237 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1239 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1241 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1243 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1245 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1247 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1249 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1251 case BFD_RELOC_PPC64_REL16_HIGH
: r
= R_PPC64_REL16_HIGH
;
1253 case BFD_RELOC_PPC64_REL16_HIGHA
: r
= R_PPC64_REL16_HIGHA
;
1255 case BFD_RELOC_PPC64_REL16_HIGHER
: r
= R_PPC64_REL16_HIGHER
;
1257 case BFD_RELOC_PPC64_REL16_HIGHERA
: r
= R_PPC64_REL16_HIGHERA
;
1259 case BFD_RELOC_PPC64_REL16_HIGHEST
: r
= R_PPC64_REL16_HIGHEST
;
1261 case BFD_RELOC_PPC64_REL16_HIGHESTA
: r
= R_PPC64_REL16_HIGHESTA
;
1263 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1265 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1267 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1269 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1271 case BFD_RELOC_PPC64_D34
: r
= R_PPC64_D34
;
1273 case BFD_RELOC_PPC64_D34_LO
: r
= R_PPC64_D34_LO
;
1275 case BFD_RELOC_PPC64_D34_HI30
: r
= R_PPC64_D34_HI30
;
1277 case BFD_RELOC_PPC64_D34_HA30
: r
= R_PPC64_D34_HA30
;
1279 case BFD_RELOC_PPC64_PCREL34
: r
= R_PPC64_PCREL34
;
1281 case BFD_RELOC_PPC64_GOT_PCREL34
: r
= R_PPC64_GOT_PCREL34
;
1283 case BFD_RELOC_PPC64_PLT_PCREL34
: r
= R_PPC64_PLT_PCREL34
;
1285 case BFD_RELOC_PPC64_TPREL34
: r
= R_PPC64_TPREL34
;
1287 case BFD_RELOC_PPC64_DTPREL34
: r
= R_PPC64_DTPREL34
;
1289 case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34
: r
= R_PPC64_GOT_TLSGD_PCREL34
;
1291 case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34
: r
= R_PPC64_GOT_TLSLD_PCREL34
;
1293 case BFD_RELOC_PPC64_GOT_TPREL_PCREL34
: r
= R_PPC64_GOT_TPREL_PCREL34
;
1295 case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34
: r
= R_PPC64_GOT_DTPREL_PCREL34
;
1297 case BFD_RELOC_PPC64_ADDR16_HIGHER34
: r
= R_PPC64_ADDR16_HIGHER34
;
1299 case BFD_RELOC_PPC64_ADDR16_HIGHERA34
: r
= R_PPC64_ADDR16_HIGHERA34
;
1301 case BFD_RELOC_PPC64_ADDR16_HIGHEST34
: r
= R_PPC64_ADDR16_HIGHEST34
;
1303 case BFD_RELOC_PPC64_ADDR16_HIGHESTA34
: r
= R_PPC64_ADDR16_HIGHESTA34
;
1305 case BFD_RELOC_PPC64_REL16_HIGHER34
: r
= R_PPC64_REL16_HIGHER34
;
1307 case BFD_RELOC_PPC64_REL16_HIGHERA34
: r
= R_PPC64_REL16_HIGHERA34
;
1309 case BFD_RELOC_PPC64_REL16_HIGHEST34
: r
= R_PPC64_REL16_HIGHEST34
;
1311 case BFD_RELOC_PPC64_REL16_HIGHESTA34
: r
= R_PPC64_REL16_HIGHESTA34
;
1313 case BFD_RELOC_PPC64_D28
: r
= R_PPC64_D28
;
1315 case BFD_RELOC_PPC64_PCREL28
: r
= R_PPC64_PCREL28
;
1317 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1319 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1323 return ppc64_elf_howto_table
[r
];
1326 static reloc_howto_type
*
1327 ppc64_elf_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1330 static char *compat_map
[][2] = {
1331 { "R_PPC64_GOT_TLSGD34", "R_PPC64_GOT_TLSGD_PCREL34" },
1332 { "R_PPC64_GOT_TLSLD34", "R_PPC64_GOT_TLSLD_PCREL34" },
1333 { "R_PPC64_GOT_TPREL34", "R_PPC64_GOT_TPREL_PCREL34" },
1334 { "R_PPC64_GOT_DTPREL34", "R_PPC64_GOT_DTPREL_PCREL34" }
1337 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1338 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1339 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1340 return &ppc64_elf_howto_raw
[i
];
1342 /* Handle old names of relocations in case they were used by
1344 FIXME: Remove this soon. Mapping the reloc names is very likely
1345 completely unnecessary. */
1346 for (i
= 0; i
< ARRAY_SIZE (compat_map
); i
++)
1347 if (strcasecmp (compat_map
[i
][0], r_name
) == 0)
1349 _bfd_error_handler (_("warning: %s should be used rather than %s"),
1350 compat_map
[i
][1], compat_map
[i
][0]);
1351 return ppc64_elf_reloc_name_lookup (abfd
, compat_map
[i
][1]);
1357 /* Set the howto pointer for a PowerPC ELF reloc. */
1360 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1361 Elf_Internal_Rela
*dst
)
1365 /* Initialize howto table if needed. */
1366 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1369 type
= ELF64_R_TYPE (dst
->r_info
);
1370 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1372 /* xgettext:c-format */
1373 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1375 bfd_set_error (bfd_error_bad_value
);
1378 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1379 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1381 /* xgettext:c-format */
1382 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1384 bfd_set_error (bfd_error_bad_value
);
1391 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1393 static bfd_reloc_status_type
1394 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1395 void *data
, asection
*input_section
,
1396 bfd
*output_bfd
, char **error_message
)
1398 enum elf_ppc64_reloc_type r_type
;
1400 bfd_size_type octets
;
1403 /* If this is a relocatable link (output_bfd test tells us), just
1404 call the generic function. Any adjustment will be done at final
1406 if (output_bfd
!= NULL
)
1407 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1408 input_section
, output_bfd
, error_message
);
1410 /* Adjust the addend for sign extension of the low 16 (or 34) bits.
1411 We won't actually be using the low bits, so trashing them
1413 r_type
= reloc_entry
->howto
->type
;
1414 if (r_type
== R_PPC64_ADDR16_HIGHERA34
1415 || r_type
== R_PPC64_ADDR16_HIGHESTA34
1416 || r_type
== R_PPC64_REL16_HIGHERA34
1417 || r_type
== R_PPC64_REL16_HIGHESTA34
)
1418 reloc_entry
->addend
+= 1ULL << 33;
1420 reloc_entry
->addend
+= 1U << 15;
1421 if (r_type
!= R_PPC64_REL16DX_HA
)
1422 return bfd_reloc_continue
;
1425 if (!bfd_is_com_section (symbol
->section
))
1426 value
= symbol
->value
;
1427 value
+= (reloc_entry
->addend
1428 + symbol
->section
->output_offset
1429 + symbol
->section
->output_section
->vma
);
1430 value
-= (reloc_entry
->address
1431 + input_section
->output_offset
1432 + input_section
->output_section
->vma
);
1433 value
= (bfd_signed_vma
) value
>> 16;
1435 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1436 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1438 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1439 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1440 if (value
+ 0x8000 > 0xffff)
1441 return bfd_reloc_overflow
;
1442 return bfd_reloc_ok
;
1445 static bfd_reloc_status_type
1446 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1447 void *data
, asection
*input_section
,
1448 bfd
*output_bfd
, char **error_message
)
1450 if (output_bfd
!= NULL
)
1451 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1452 input_section
, output_bfd
, error_message
);
1454 if (strcmp (symbol
->section
->name
, ".opd") == 0
1455 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1457 bfd_vma dest
= opd_entry_value (symbol
->section
,
1458 symbol
->value
+ reloc_entry
->addend
,
1460 if (dest
!= (bfd_vma
) -1)
1461 reloc_entry
->addend
= dest
- (symbol
->value
1462 + symbol
->section
->output_section
->vma
1463 + symbol
->section
->output_offset
);
1467 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1469 if (symbol
->section
->owner
!= abfd
1470 && symbol
->section
->owner
!= NULL
1471 && abiversion (symbol
->section
->owner
) >= 2)
1475 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1477 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1479 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1481 elfsym
= (elf_symbol_type
*) symdef
;
1487 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1489 return bfd_reloc_continue
;
1492 static bfd_reloc_status_type
1493 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1494 void *data
, asection
*input_section
,
1495 bfd
*output_bfd
, char **error_message
)
1498 enum elf_ppc64_reloc_type r_type
;
1499 bfd_size_type octets
;
1500 /* Assume 'at' branch hints. */
1501 bool is_isa_v2
= true;
1503 /* If this is a relocatable link (output_bfd test tells us), just
1504 call the generic function. Any adjustment will be done at final
1506 if (output_bfd
!= NULL
)
1507 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1508 input_section
, output_bfd
, error_message
);
1510 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1511 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1512 insn
&= ~(0x01 << 21);
1513 r_type
= reloc_entry
->howto
->type
;
1514 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1515 || r_type
== R_PPC64_REL14_BRTAKEN
)
1516 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1520 /* Set 'a' bit. This is 0b00010 in BO field for branch
1521 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1522 for branch on CTR insns (BO == 1a00t or 1a01t). */
1523 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1525 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1535 if (!bfd_is_com_section (symbol
->section
))
1536 target
= symbol
->value
;
1537 target
+= symbol
->section
->output_section
->vma
;
1538 target
+= symbol
->section
->output_offset
;
1539 target
+= reloc_entry
->addend
;
1541 from
= (reloc_entry
->address
1542 + input_section
->output_offset
1543 + input_section
->output_section
->vma
);
1545 /* Invert 'y' bit if not the default. */
1546 if ((bfd_signed_vma
) (target
- from
) < 0)
1549 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1551 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1552 input_section
, output_bfd
, error_message
);
1555 static bfd_reloc_status_type
1556 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1557 void *data
, asection
*input_section
,
1558 bfd
*output_bfd
, char **error_message
)
1560 /* If this is a relocatable link (output_bfd test tells us), just
1561 call the generic function. Any adjustment will be done at final
1563 if (output_bfd
!= NULL
)
1564 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1565 input_section
, output_bfd
, error_message
);
1567 /* Subtract the symbol section base address. */
1568 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1569 return bfd_reloc_continue
;
1572 static bfd_reloc_status_type
1573 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1574 void *data
, asection
*input_section
,
1575 bfd
*output_bfd
, char **error_message
)
1577 /* If this is a relocatable link (output_bfd test tells us), just
1578 call the generic function. Any adjustment will be done at final
1580 if (output_bfd
!= NULL
)
1581 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1582 input_section
, output_bfd
, error_message
);
1584 /* Subtract the symbol section base address. */
1585 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1587 /* Adjust the addend for sign extension of the low 16 bits. */
1588 reloc_entry
->addend
+= 0x8000;
1589 return bfd_reloc_continue
;
1592 static bfd_reloc_status_type
1593 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1594 void *data
, asection
*input_section
,
1595 bfd
*output_bfd
, char **error_message
)
1599 /* If this is a relocatable link (output_bfd test tells us), just
1600 call the generic function. Any adjustment will be done at final
1602 if (output_bfd
!= NULL
)
1603 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1604 input_section
, output_bfd
, error_message
);
1606 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1608 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1610 /* Subtract the TOC base address. */
1611 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1612 return bfd_reloc_continue
;
1615 static bfd_reloc_status_type
1616 ppc64_elf_toc_ha_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
;
1636 /* Adjust the addend for sign extension of the low 16 bits. */
1637 reloc_entry
->addend
+= 0x8000;
1638 return bfd_reloc_continue
;
1641 static bfd_reloc_status_type
1642 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1643 void *data
, asection
*input_section
,
1644 bfd
*output_bfd
, char **error_message
)
1647 bfd_size_type octets
;
1649 /* If this is a relocatable link (output_bfd test tells us), just
1650 call the generic function. Any adjustment will be done at final
1652 if (output_bfd
!= NULL
)
1653 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1654 input_section
, output_bfd
, error_message
);
1656 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1658 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1660 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1661 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1662 return bfd_reloc_ok
;
1665 static bfd_reloc_status_type
1666 ppc64_elf_prefix_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1667 void *data
, asection
*input_section
,
1668 bfd
*output_bfd
, char **error_message
)
1673 if (output_bfd
!= NULL
)
1674 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1675 input_section
, output_bfd
, error_message
);
1677 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1679 insn
|= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 4);
1681 targ
= (symbol
->section
->output_section
->vma
1682 + symbol
->section
->output_offset
1683 + reloc_entry
->addend
);
1684 if (!bfd_is_com_section (symbol
->section
))
1685 targ
+= symbol
->value
;
1686 if (reloc_entry
->howto
->type
== R_PPC64_D34_HA30
)
1688 if (reloc_entry
->howto
->pc_relative
)
1690 bfd_vma from
= (reloc_entry
->address
1691 + input_section
->output_offset
1692 + input_section
->output_section
->vma
);
1695 targ
>>= reloc_entry
->howto
->rightshift
;
1696 insn
&= ~reloc_entry
->howto
->dst_mask
;
1697 insn
|= ((targ
<< 16) | (targ
& 0xffff)) & reloc_entry
->howto
->dst_mask
;
1698 bfd_put_32 (abfd
, insn
>> 32, (bfd_byte
*) data
+ reloc_entry
->address
);
1699 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
+ 4);
1700 if (reloc_entry
->howto
->complain_on_overflow
== complain_overflow_signed
1701 && (targ
+ (1ULL << (reloc_entry
->howto
->bitsize
- 1))
1702 >= 1ULL << reloc_entry
->howto
->bitsize
))
1703 return bfd_reloc_overflow
;
1704 return bfd_reloc_ok
;
1707 static bfd_reloc_status_type
1708 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1709 void *data
, asection
*input_section
,
1710 bfd
*output_bfd
, char **error_message
)
1712 /* If this is a relocatable link (output_bfd test tells us), just
1713 call the generic function. Any adjustment will be done at final
1715 if (output_bfd
!= NULL
)
1716 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1717 input_section
, output_bfd
, error_message
);
1719 if (error_message
!= NULL
)
1721 static char *message
;
1723 if (asprintf (&message
, _("generic linker can't handle %s"),
1724 reloc_entry
->howto
->name
) < 0)
1726 *error_message
= message
;
1728 return bfd_reloc_dangerous
;
1731 /* Track GOT entries needed for a given symbol. We might need more
1732 than one got entry per symbol. */
1735 struct got_entry
*next
;
1737 /* The symbol addend that we'll be placing in the GOT. */
1740 /* Unlike other ELF targets, we use separate GOT entries for the same
1741 symbol referenced from different input files. This is to support
1742 automatic multiple TOC/GOT sections, where the TOC base can vary
1743 from one input file to another. After partitioning into TOC groups
1744 we merge entries within the group.
1746 Point to the BFD owning this GOT entry. */
1749 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1750 TLS_TPREL or TLS_DTPREL for tls entries. */
1751 unsigned char tls_type
;
1753 /* Non-zero if got.ent points to real entry. */
1754 unsigned char is_indirect
;
1756 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1759 bfd_signed_vma refcount
;
1761 struct got_entry
*ent
;
1765 /* The same for PLT. */
1768 struct plt_entry
*next
;
1774 bfd_signed_vma refcount
;
1779 struct ppc64_elf_obj_tdata
1781 struct elf_obj_tdata elf
;
1783 /* Shortcuts to dynamic linker sections. */
1787 /* Used during garbage collection. We attach global symbols defined
1788 on removed .opd entries to this section so that the sym is removed. */
1789 asection
*deleted_section
;
1791 /* TLS local dynamic got entry handling. Support for multiple GOT
1792 sections means we potentially need one of these for each input bfd. */
1793 struct got_entry tlsld_got
;
1797 /* A copy of relocs before they are modified for --emit-relocs. */
1798 Elf_Internal_Rela
*relocs
;
1800 /* Section contents. */
1804 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1805 the reloc to be in the range -32768 to 32767. */
1806 unsigned int has_small_toc_reloc
: 1;
1808 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1809 instruction not one we handle. */
1810 unsigned int unexpected_toc_insn
: 1;
1812 /* Set if PLT/GOT/TOC relocs that can be optimised are present in
1814 unsigned int has_optrel
: 1;
1817 #define ppc64_elf_tdata(bfd) \
1818 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1820 #define ppc64_tlsld_got(bfd) \
1821 (&ppc64_elf_tdata (bfd)->tlsld_got)
1823 #define is_ppc64_elf(bfd) \
1824 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1825 && elf_object_id (bfd) == PPC64_ELF_DATA)
1827 /* Override the generic function because we store some extras. */
1830 ppc64_elf_mkobject (bfd
*abfd
)
1832 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1836 /* Fix bad default arch selected for a 64 bit input bfd when the
1837 default is 32 bit. Also select arch based on apuinfo. */
1840 ppc64_elf_object_p (bfd
*abfd
)
1842 if (!abfd
->arch_info
->the_default
)
1845 if (abfd
->arch_info
->bits_per_word
== 32)
1847 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1849 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1851 /* Relies on arch after 32 bit default being 64 bit default. */
1852 abfd
->arch_info
= abfd
->arch_info
->next
;
1853 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1856 return _bfd_elf_ppc_set_arch (abfd
);
1859 /* Support for core dump NOTE sections. */
1862 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1864 size_t offset
, size
;
1866 if (note
->descsz
!= 504)
1870 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1873 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1879 /* Make a ".reg/999" section. */
1880 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1881 size
, note
->descpos
+ offset
);
1885 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1887 if (note
->descsz
!= 136)
1890 elf_tdata (abfd
)->core
->pid
1891 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1892 elf_tdata (abfd
)->core
->program
1893 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1894 elf_tdata (abfd
)->core
->command
1895 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1901 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1911 char data
[136] ATTRIBUTE_NONSTRING
;
1914 va_start (ap
, note_type
);
1915 memset (data
, 0, sizeof (data
));
1916 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1917 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1919 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1920 -Wstringop-truncation:
1921 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1923 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1925 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1926 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1930 return elfcore_write_note (abfd
, buf
, bufsiz
,
1931 "CORE", note_type
, data
, sizeof (data
));
1942 va_start (ap
, note_type
);
1943 memset (data
, 0, 112);
1944 pid
= va_arg (ap
, long);
1945 bfd_put_32 (abfd
, pid
, data
+ 32);
1946 cursig
= va_arg (ap
, int);
1947 bfd_put_16 (abfd
, cursig
, data
+ 12);
1948 greg
= va_arg (ap
, const void *);
1949 memcpy (data
+ 112, greg
, 384);
1950 memset (data
+ 496, 0, 8);
1952 return elfcore_write_note (abfd
, buf
, bufsiz
,
1953 "CORE", note_type
, data
, sizeof (data
));
1958 /* Add extra PPC sections. */
1960 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1962 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1963 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1964 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1965 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1966 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1967 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1968 { NULL
, 0, 0, 0, 0 }
1971 enum _ppc64_sec_type
{
1977 struct _ppc64_elf_section_data
1979 struct bfd_elf_section_data elf
;
1983 /* An array with one entry for each opd function descriptor,
1984 and some spares since opd entries may be either 16 or 24 bytes. */
1985 #define OPD_NDX(OFF) ((OFF) >> 4)
1986 struct _opd_sec_data
1988 /* Points to the function code section for local opd entries. */
1989 asection
**func_sec
;
1991 /* After editing .opd, adjust references to opd local syms. */
1995 /* An array for toc sections, indexed by offset/8. */
1996 struct _toc_sec_data
1998 /* Specifies the relocation symbol index used at a given toc offset. */
2001 /* And the relocation addend. */
2006 enum _ppc64_sec_type sec_type
:2;
2008 /* Flag set when small branches are detected. Used to
2009 select suitable defaults for the stub group size. */
2010 unsigned int has_14bit_branch
:1;
2012 /* Flag set when PLTCALL relocs are detected. */
2013 unsigned int has_pltcall
:1;
2015 /* Flag set when section has PLT/GOT/TOC relocations that can be
2017 unsigned int has_optrel
:1;
2020 #define ppc64_elf_section_data(sec) \
2021 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2024 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2026 if (!sec
->used_by_bfd
)
2028 struct _ppc64_elf_section_data
*sdata
;
2029 size_t amt
= sizeof (*sdata
);
2031 sdata
= bfd_zalloc (abfd
, amt
);
2034 sec
->used_by_bfd
= sdata
;
2037 return _bfd_elf_new_section_hook (abfd
, sec
);
2041 ppc64_elf_section_flags (const Elf_Internal_Shdr
*hdr
)
2043 const char *name
= hdr
->bfd_section
->name
;
2045 if (startswith (name
, ".sbss")
2046 || startswith (name
, ".sdata"))
2047 hdr
->bfd_section
->flags
|= SEC_SMALL_DATA
;
2052 static struct _opd_sec_data
*
2053 get_opd_info (asection
* sec
)
2056 && ppc64_elf_section_data (sec
) != NULL
2057 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2058 return &ppc64_elf_section_data (sec
)->u
.opd
;
2062 /* Parameters for the qsort hook. */
2063 static bool synthetic_relocatable
;
2064 static const asection
*synthetic_opd
;
2066 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2069 compare_symbols (const void *ap
, const void *bp
)
2071 const asymbol
*a
= *(const asymbol
**) ap
;
2072 const asymbol
*b
= *(const asymbol
**) bp
;
2074 /* Section symbols first. */
2075 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2077 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2080 /* then .opd symbols. */
2081 if (synthetic_opd
!= NULL
)
2083 if (strcmp (a
->section
->name
, ".opd") == 0
2084 && strcmp (b
->section
->name
, ".opd") != 0)
2086 if (strcmp (a
->section
->name
, ".opd") != 0
2087 && strcmp (b
->section
->name
, ".opd") == 0)
2091 /* then other code symbols. */
2092 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2093 == (SEC_CODE
| SEC_ALLOC
))
2094 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2095 != (SEC_CODE
| SEC_ALLOC
)))
2098 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2099 != (SEC_CODE
| SEC_ALLOC
))
2100 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2101 == (SEC_CODE
| SEC_ALLOC
)))
2104 if (synthetic_relocatable
)
2106 if (a
->section
->id
< b
->section
->id
)
2109 if (a
->section
->id
> b
->section
->id
)
2113 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2116 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2119 /* For syms with the same value, prefer strong dynamic global function
2120 syms over other syms. */
2121 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2124 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2127 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2130 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2133 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2136 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2139 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2142 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2145 /* Finally, sort on where the symbol is in memory. The symbols will
2146 be in at most two malloc'd blocks, one for static syms, one for
2147 dynamic syms, and we distinguish the two blocks above by testing
2148 BSF_DYNAMIC. Since we are sorting the symbol pointers which were
2149 originally in the same order as the symbols (and we're not
2150 sorting the symbols themselves), this ensures a stable sort. */
2158 /* Search SYMS for a symbol of the given VALUE. */
2161 sym_exists_at (asymbol
**syms
, size_t lo
, size_t hi
, unsigned int id
,
2166 if (id
== (unsigned) -1)
2170 mid
= (lo
+ hi
) >> 1;
2171 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2173 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2183 mid
= (lo
+ hi
) >> 1;
2184 if (syms
[mid
]->section
->id
< id
)
2186 else if (syms
[mid
]->section
->id
> id
)
2188 else if (syms
[mid
]->value
< value
)
2190 else if (syms
[mid
]->value
> value
)
2200 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2202 bfd_vma vma
= *(bfd_vma
*) ptr
;
2203 return ((section
->flags
& SEC_ALLOC
) != 0
2204 && section
->vma
<= vma
2205 && vma
< section
->vma
+ section
->size
);
2208 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2209 entry syms. Also generate @plt symbols for the glink branch table.
2210 Returns count of synthetic symbols in RET or -1 on error. */
2213 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2214 long static_count
, asymbol
**static_syms
,
2215 long dyn_count
, asymbol
**dyn_syms
,
2221 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2222 asection
*opd
= NULL
;
2223 bool relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2225 int abi
= abiversion (abfd
);
2231 opd
= bfd_get_section_by_name (abfd
, ".opd");
2232 if (opd
== NULL
&& abi
== 1)
2244 symcount
= static_count
;
2246 symcount
+= dyn_count
;
2250 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2254 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2256 /* Use both symbol tables. */
2257 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2258 memcpy (syms
+ static_count
, dyn_syms
,
2259 (dyn_count
+ 1) * sizeof (*syms
));
2261 else if (!relocatable
&& static_count
== 0)
2262 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2264 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2266 /* Trim uninteresting symbols. Interesting symbols are section,
2267 function, and notype symbols. */
2268 for (i
= 0, j
= 0; i
< symcount
; ++i
)
2269 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
2270 | BSF_RELC
| BSF_SRELC
)) == 0)
2271 syms
[j
++] = syms
[i
];
2274 synthetic_relocatable
= relocatable
;
2275 synthetic_opd
= opd
;
2276 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2278 if (!relocatable
&& symcount
> 1)
2280 /* Trim duplicate syms, since we may have merged the normal
2281 and dynamic symbols. Actually, we only care about syms
2282 that have different values, so trim any with the same
2283 value. Don't consider ifunc and ifunc resolver symbols
2284 duplicates however, because GDB wants to know whether a
2285 text symbol is an ifunc resolver. */
2286 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2288 const asymbol
*s0
= syms
[i
- 1];
2289 const asymbol
*s1
= syms
[i
];
2291 if ((s0
->value
+ s0
->section
->vma
2292 != s1
->value
+ s1
->section
->vma
)
2293 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2294 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2295 syms
[j
++] = syms
[i
];
2301 /* Note that here and in compare_symbols we can't compare opd and
2302 sym->section directly. With separate debug info files, the
2303 symbols will be extracted from the debug file while abfd passed
2304 to this function is the real binary. */
2305 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) != 0
2306 && strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2310 for (; i
< symcount
; ++i
)
2311 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2312 | SEC_THREAD_LOCAL
))
2313 != (SEC_CODE
| SEC_ALLOC
))
2314 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2318 for (; i
< symcount
; ++i
)
2319 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2323 for (; i
< symcount
; ++i
)
2324 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2328 for (; i
< symcount
; ++i
)
2329 if (((syms
[i
]->section
->flags
2330 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2331 != (SEC_CODE
| SEC_ALLOC
))
2339 bool (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bool);
2344 if (opdsymend
== secsymend
)
2347 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2348 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2352 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, false))
2359 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2363 while (r
< opd
->relocation
+ relcount
2364 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2367 if (r
== opd
->relocation
+ relcount
)
2370 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2373 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2376 sym
= *r
->sym_ptr_ptr
;
2377 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2378 sym
->section
->id
, sym
->value
+ r
->addend
))
2381 size
+= sizeof (asymbol
);
2382 size
+= strlen (syms
[i
]->name
) + 2;
2388 s
= *ret
= bfd_malloc (size
);
2395 names
= (char *) (s
+ count
);
2397 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2401 while (r
< opd
->relocation
+ relcount
2402 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2405 if (r
== opd
->relocation
+ relcount
)
2408 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2411 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2414 sym
= *r
->sym_ptr_ptr
;
2415 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2416 sym
->section
->id
, sym
->value
+ r
->addend
))
2421 s
->flags
|= BSF_SYNTHETIC
;
2422 s
->section
= sym
->section
;
2423 s
->value
= sym
->value
+ r
->addend
;
2426 len
= strlen (syms
[i
]->name
);
2427 memcpy (names
, syms
[i
]->name
, len
+ 1);
2429 /* Have udata.p point back to the original symbol this
2430 synthetic symbol was derived from. */
2431 s
->udata
.p
= syms
[i
];
2438 bool (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bool);
2439 bfd_byte
*contents
= NULL
;
2441 size_t plt_count
= 0;
2442 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2443 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2446 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2448 free_contents_and_exit_err
:
2450 free_contents_and_exit
:
2456 for (i
= secsymend
; i
< opdsymend
; ++i
)
2460 /* Ignore bogus symbols. */
2461 if (syms
[i
]->value
> opd
->size
- 8)
2464 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2465 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2468 size
+= sizeof (asymbol
);
2469 size
+= strlen (syms
[i
]->name
) + 2;
2473 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2475 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2477 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2479 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2481 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2482 goto free_contents_and_exit_err
;
2484 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2485 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2488 extdynend
= extdyn
+ dynamic
->size
;
2489 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2491 Elf_Internal_Dyn dyn
;
2492 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2494 if (dyn
.d_tag
== DT_NULL
)
2497 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2499 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2500 See comment in ppc64_elf_finish_dynamic_sections. */
2501 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2502 /* The .glink section usually does not survive the final
2503 link; search for the section (usually .text) where the
2504 glink stubs now reside. */
2505 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2516 /* Determine __glink trampoline by reading the relative branch
2517 from the first glink stub. */
2519 unsigned int off
= 0;
2521 while (bfd_get_section_contents (abfd
, glink
, buf
,
2522 glink_vma
+ off
- glink
->vma
, 4))
2524 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2526 if ((insn
& ~0x3fffffc) == 0)
2529 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2538 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2540 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2543 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2544 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, true))
2545 goto free_contents_and_exit_err
;
2547 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
2548 size
+= plt_count
* sizeof (asymbol
);
2550 p
= relplt
->relocation
;
2551 for (i
= 0; i
< plt_count
; i
++, p
++)
2553 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2555 size
+= sizeof ("+0x") - 1 + 16;
2561 goto free_contents_and_exit
;
2562 s
= *ret
= bfd_malloc (size
);
2564 goto free_contents_and_exit_err
;
2566 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2568 for (i
= secsymend
; i
< opdsymend
; ++i
)
2572 if (syms
[i
]->value
> opd
->size
- 8)
2575 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2576 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2580 asection
*sec
= abfd
->sections
;
2587 size_t mid
= (lo
+ hi
) >> 1;
2588 if (syms
[mid
]->section
->vma
< ent
)
2590 else if (syms
[mid
]->section
->vma
> ent
)
2594 sec
= syms
[mid
]->section
;
2599 if (lo
>= hi
&& lo
> codesecsym
)
2600 sec
= syms
[lo
- 1]->section
;
2602 for (; sec
!= NULL
; sec
= sec
->next
)
2606 /* SEC_LOAD may not be set if SEC is from a separate debug
2608 if ((sec
->flags
& SEC_ALLOC
) == 0)
2610 if ((sec
->flags
& SEC_CODE
) != 0)
2613 s
->flags
|= BSF_SYNTHETIC
;
2614 s
->value
= ent
- s
->section
->vma
;
2617 len
= strlen (syms
[i
]->name
);
2618 memcpy (names
, syms
[i
]->name
, len
+ 1);
2620 /* Have udata.p point back to the original symbol this
2621 synthetic symbol was derived from. */
2622 s
->udata
.p
= syms
[i
];
2628 if (glink
!= NULL
&& relplt
!= NULL
)
2632 /* Add a symbol for the main glink trampoline. */
2633 memset (s
, 0, sizeof *s
);
2635 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2637 s
->value
= resolv_vma
- glink
->vma
;
2639 memcpy (names
, "__glink_PLTresolve",
2640 sizeof ("__glink_PLTresolve"));
2641 names
+= sizeof ("__glink_PLTresolve");
2646 /* FIXME: It would be very much nicer to put sym@plt on the
2647 stub rather than on the glink branch table entry. The
2648 objdump disassembler would then use a sensible symbol
2649 name on plt calls. The difficulty in doing so is
2650 a) finding the stubs, and,
2651 b) matching stubs against plt entries, and,
2652 c) there can be multiple stubs for a given plt entry.
2654 Solving (a) could be done by code scanning, but older
2655 ppc64 binaries used different stubs to current code.
2656 (b) is the tricky one since you need to known the toc
2657 pointer for at least one function that uses a pic stub to
2658 be able to calculate the plt address referenced.
2659 (c) means gdb would need to set multiple breakpoints (or
2660 find the glink branch itself) when setting breakpoints
2661 for pending shared library loads. */
2662 p
= relplt
->relocation
;
2663 for (i
= 0; i
< plt_count
; i
++, p
++)
2667 *s
= **p
->sym_ptr_ptr
;
2668 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2669 we are defining a symbol, ensure one of them is set. */
2670 if ((s
->flags
& BSF_LOCAL
) == 0)
2671 s
->flags
|= BSF_GLOBAL
;
2672 s
->flags
|= BSF_SYNTHETIC
;
2674 s
->value
= glink_vma
- glink
->vma
;
2677 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2678 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2682 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2683 names
+= sizeof ("+0x") - 1;
2684 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2685 names
+= strlen (names
);
2687 memcpy (names
, "@plt", sizeof ("@plt"));
2688 names
+= sizeof ("@plt");
2708 /* The following functions are specific to the ELF linker, while
2709 functions above are used generally. Those named ppc64_elf_* are
2710 called by the main ELF linker code. They appear in this file more
2711 or less in the order in which they are called. eg.
2712 ppc64_elf_check_relocs is called early in the link process,
2713 ppc64_elf_finish_dynamic_sections is one of the last functions
2716 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2717 functions have both a function code symbol and a function descriptor
2718 symbol. A call to foo in a relocatable object file looks like:
2725 The function definition in another object file might be:
2729 . .quad .TOC.@tocbase
2735 When the linker resolves the call during a static link, the branch
2736 unsurprisingly just goes to .foo and the .opd information is unused.
2737 If the function definition is in a shared library, things are a little
2738 different: The call goes via a plt call stub, the opd information gets
2739 copied to the plt, and the linker patches the nop.
2747 . std 2,40(1) # in practice, the call stub
2748 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2749 . addi 11,11,Lfoo@toc@l # this is the general idea
2757 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2759 The "reloc ()" notation is supposed to indicate that the linker emits
2760 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2763 What are the difficulties here? Well, firstly, the relocations
2764 examined by the linker in check_relocs are against the function code
2765 sym .foo, while the dynamic relocation in the plt is emitted against
2766 the function descriptor symbol, foo. Somewhere along the line, we need
2767 to carefully copy dynamic link information from one symbol to the other.
2768 Secondly, the generic part of the elf linker will make .foo a dynamic
2769 symbol as is normal for most other backends. We need foo dynamic
2770 instead, at least for an application final link. However, when
2771 creating a shared library containing foo, we need to have both symbols
2772 dynamic so that references to .foo are satisfied during the early
2773 stages of linking. Otherwise the linker might decide to pull in a
2774 definition from some other object, eg. a static library.
2776 Update: As of August 2004, we support a new convention. Function
2777 calls may use the function descriptor symbol, ie. "bl foo". This
2778 behaves exactly as "bl .foo". */
2780 /* Of those relocs that might be copied as dynamic relocs, this
2781 function selects those that must be copied when linking a shared
2782 library or PIE, even when the symbol is local. */
2785 must_be_dyn_reloc (struct bfd_link_info
*info
,
2786 enum elf_ppc64_reloc_type r_type
)
2791 /* Only relative relocs can be resolved when the object load
2792 address isn't fixed. DTPREL64 is excluded because the
2793 dynamic linker needs to differentiate global dynamic from
2794 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2801 case R_PPC64_TOC16_DS
:
2802 case R_PPC64_TOC16_LO
:
2803 case R_PPC64_TOC16_HI
:
2804 case R_PPC64_TOC16_HA
:
2805 case R_PPC64_TOC16_LO_DS
:
2808 case R_PPC64_TPREL16
:
2809 case R_PPC64_TPREL16_LO
:
2810 case R_PPC64_TPREL16_HI
:
2811 case R_PPC64_TPREL16_HA
:
2812 case R_PPC64_TPREL16_DS
:
2813 case R_PPC64_TPREL16_LO_DS
:
2814 case R_PPC64_TPREL16_HIGH
:
2815 case R_PPC64_TPREL16_HIGHA
:
2816 case R_PPC64_TPREL16_HIGHER
:
2817 case R_PPC64_TPREL16_HIGHERA
:
2818 case R_PPC64_TPREL16_HIGHEST
:
2819 case R_PPC64_TPREL16_HIGHESTA
:
2820 case R_PPC64_TPREL64
:
2821 case R_PPC64_TPREL34
:
2822 /* These relocations are relative but in a shared library the
2823 linker doesn't know the thread pointer base. */
2824 return bfd_link_dll (info
);
2828 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2829 copying dynamic variables from a shared lib into an app's .dynbss
2830 section, and instead use a dynamic relocation to point into the
2831 shared lib. With code that gcc generates it is vital that this be
2832 enabled; In the PowerPC64 ELFv1 ABI the address of a function is
2833 actually the address of a function descriptor which resides in the
2834 .opd section. gcc uses the descriptor directly rather than going
2835 via the GOT as some other ABIs do, which means that initialized
2836 function pointers reference the descriptor. Thus, a function
2837 pointer initialized to the address of a function in a shared
2838 library will either require a .dynbss copy and a copy reloc, or a
2839 dynamic reloc. Using a .dynbss copy redefines the function
2840 descriptor symbol to point to the copy. This presents a problem as
2841 a PLT entry for that function is also initialized from the function
2842 descriptor symbol and the copy may not be initialized first. */
2843 #define ELIMINATE_COPY_RELOCS 1
2845 /* Section name for stubs is the associated section name plus this
2847 #define STUB_SUFFIX ".stub"
2850 ppc_stub_long_branch:
2851 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2852 destination, but a 24 bit branch in a stub section will reach.
2855 ppc_stub_plt_branch:
2856 Similar to the above, but a 24 bit branch in the stub section won't
2857 reach its destination.
2858 . addis %r12,%r2,xxx@toc@ha
2859 . ld %r12,xxx@toc@l(%r12)
2864 Used to call a function in a shared library. If it so happens that
2865 the plt entry referenced crosses a 64k boundary, then an extra
2866 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2867 ppc_stub_plt_call_r2save starts with "std %r2,40(%r1)".
2868 . addis %r11,%r2,xxx@toc@ha
2869 . ld %r12,xxx+0@toc@l(%r11)
2871 . ld %r2,xxx+8@toc@l(%r11)
2872 . ld %r11,xxx+16@toc@l(%r11)
2875 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2876 code to adjust the value and save r2 to support multiple toc sections.
2877 A ppc_stub_long_branch with an r2 offset looks like:
2879 . addis %r2,%r2,off@ha
2880 . addi %r2,%r2,off@l
2883 A ppc_stub_plt_branch with an r2 offset looks like:
2885 . addis %r12,%r2,xxx@toc@ha
2886 . ld %r12,xxx@toc@l(%r12)
2887 . addis %r2,%r2,off@ha
2888 . addi %r2,%r2,off@l
2892 All of the above stubs are shown as their ELFv1 variants. ELFv2
2893 variants exist too, simpler for plt calls since a new toc pointer
2894 and static chain are not loaded by the stub. In addition, ELFv2
2895 has some more complex stubs to handle calls marked with NOTOC
2896 relocs from functions where r2 is not a valid toc pointer. These
2897 come in two flavours, the ones shown below, and _both variants that
2898 start with "std %r2,24(%r1)" to save r2 in the unlikely event that
2899 one call is from a function where r2 is used as the toc pointer but
2900 needs a toc adjusting stub for small-model multi-toc, and another
2901 call is from a function where r2 is not valid.
2902 ppc_stub_long_branch_notoc:
2908 . addis %r12,%r11,dest-1b@ha
2909 . addi %r12,%r12,dest-1b@l
2912 ppc_stub_plt_branch_notoc:
2918 . lis %r12,xxx-1b@highest
2919 . ori %r12,%r12,xxx-1b@higher
2921 . oris %r12,%r12,xxx-1b@high
2922 . ori %r12,%r12,xxx-1b@l
2923 . add %r12,%r11,%r12
2927 ppc_stub_plt_call_notoc:
2933 . lis %r12,xxx-1b@highest
2934 . ori %r12,%r12,xxx-1b@higher
2936 . oris %r12,%r12,xxx-1b@high
2937 . ori %r12,%r12,xxx-1b@l
2938 . ldx %r12,%r11,%r12
2942 There are also ELFv1 power10 variants of these stubs.
2943 ppc_stub_long_branch_notoc:
2944 . pla %r12,dest@pcrel
2946 ppc_stub_plt_branch_notoc:
2947 . lis %r11,(dest-1f)@highesta34
2948 . ori %r11,%r11,(dest-1f)@highera34
2950 . 1: pla %r12,dest@pcrel
2951 . add %r12,%r11,%r12
2954 ppc_stub_plt_call_notoc:
2955 . lis %r11,(xxx-1f)@highesta34
2956 . ori %r11,%r11,(xxx-1f)@highera34
2958 . 1: pla %r12,xxx@pcrel
2959 . ldx %r12,%r11,%r12
2963 In cases where the high instructions would add zero, they are
2964 omitted and following instructions modified in some cases.
2965 For example, a power10 ppc_stub_plt_call_notoc might simplify down
2967 . pld %r12,xxx@pcrel
2971 For a given stub group (a set of sections all using the same toc
2972 pointer value) there will be just one stub type used for any
2973 particular function symbol. For example, if printf is called from
2974 code with the tocsave optimization (ie. r2 saved in function
2975 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2976 and from other code without the tocsave optimization requiring a
2977 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
2978 type will be created. Calls with the tocsave optimization will
2979 enter this stub after the instruction saving r2. A similar
2980 situation exists when calls are marked with R_PPC64_REL24_NOTOC
2981 relocations. These require a ppc_stub_plt_call_notoc linkage stub
2982 to call an external function like printf. If other calls to printf
2983 require a ppc_stub_plt_call linkage stub then a single
2984 ppc_stub_plt_call_notoc linkage stub will be used for both types of
2985 call. If other calls to printf require a ppc_stub_plt_call_r2save
2986 linkage stub then a single ppc_stub_plt_call_both linkage stub will
2987 be created and calls not requiring r2 to be saved will enter the
2988 stub after the r2 save instruction. There is an analogous
2989 hierarchy of long branch and plt branch stubs for local call
2995 ppc_stub_long_branch
,
2996 ppc_stub_long_branch_r2off
,
2997 ppc_stub_long_branch_notoc
,
2998 ppc_stub_long_branch_both
, /* r2off and notoc variants both needed. */
2999 ppc_stub_plt_branch
,
3000 ppc_stub_plt_branch_r2off
,
3001 ppc_stub_plt_branch_notoc
,
3002 ppc_stub_plt_branch_both
,
3004 ppc_stub_plt_call_r2save
,
3005 ppc_stub_plt_call_notoc
,
3006 ppc_stub_plt_call_both
,
3007 ppc_stub_global_entry
,
3011 /* Information on stub grouping. */
3014 /* The stub section. */
3016 /* This is the section to which stubs in the group will be attached. */
3019 struct map_stub
*next
;
3020 /* Whether to emit a copy of register save/restore functions in this
3023 /* Current offset within stubs after the insn restoring lr in a
3024 _notoc or _both stub using bcl for pc-relative addressing, or
3025 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
3026 unsigned int lr_restore
;
3027 /* Accumulated size of EH info emitted to describe return address
3028 if stubs modify lr. Does not include 17 byte FDE header. */
3029 unsigned int eh_size
;
3030 /* Offset in glink_eh_frame to the start of EH info for this group. */
3031 unsigned int eh_base
;
3034 struct ppc_stub_hash_entry
3036 /* Base hash table entry structure. */
3037 struct bfd_hash_entry root
;
3039 enum ppc_stub_type stub_type
;
3041 /* Group information. */
3042 struct map_stub
*group
;
3044 /* Offset within stub_sec of the beginning of this stub. */
3045 bfd_vma stub_offset
;
3047 /* Given the symbol's value and its section we can determine its final
3048 value when building the stubs (so the stub knows where to jump. */
3049 bfd_vma target_value
;
3050 asection
*target_section
;
3052 /* The symbol table entry, if any, that this was derived from. */
3053 struct ppc_link_hash_entry
*h
;
3054 struct plt_entry
*plt_ent
;
3057 unsigned char symtype
;
3059 /* Symbol st_other. */
3060 unsigned char other
;
3063 struct ppc_branch_hash_entry
3065 /* Base hash table entry structure. */
3066 struct bfd_hash_entry root
;
3068 /* Offset within branch lookup table. */
3069 unsigned int offset
;
3071 /* Generation marker. */
3075 /* Used to track dynamic relocations for local symbols. */
3076 struct ppc_dyn_relocs
3078 struct ppc_dyn_relocs
*next
;
3080 /* The input section of the reloc. */
3083 /* Total number of relocs copied for the input section. */
3084 unsigned int count
: 31;
3086 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3087 unsigned int ifunc
: 1;
3090 struct ppc_link_hash_entry
3092 struct elf_link_hash_entry elf
;
3096 /* A pointer to the most recently used stub hash entry against this
3098 struct ppc_stub_hash_entry
*stub_cache
;
3100 /* A pointer to the next symbol starting with a '.' */
3101 struct ppc_link_hash_entry
*next_dot_sym
;
3104 /* Link between function code and descriptor symbols. */
3105 struct ppc_link_hash_entry
*oh
;
3107 /* Flag function code and descriptor symbols. */
3108 unsigned int is_func
:1;
3109 unsigned int is_func_descriptor
:1;
3110 unsigned int fake
:1;
3112 /* Whether global opd/toc sym has been adjusted or not.
3113 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3114 should be set for all globals defined in any opd/toc section. */
3115 unsigned int adjust_done
:1;
3117 /* Set if this is an out-of-line register save/restore function,
3118 with non-standard calling convention. */
3119 unsigned int save_res
:1;
3121 /* Set if a duplicate symbol with non-zero localentry is detected,
3122 even when the duplicate symbol does not provide a definition. */
3123 unsigned int non_zero_localentry
:1;
3125 /* Contexts in which symbol is used in the GOT (or TOC).
3126 Bits are or'd into the mask as the corresponding relocs are
3127 encountered during check_relocs, with TLS_TLS being set when any
3128 of the other TLS bits are set. tls_optimize clears bits when
3129 optimizing to indicate the corresponding GOT entry type is not
3130 needed. If set, TLS_TLS is never cleared. tls_optimize may also
3131 set TLS_GDIE when a GD reloc turns into an IE one.
3132 These flags are also kept for local symbols. */
3133 #define TLS_TLS 1 /* Any TLS reloc. */
3134 #define TLS_GD 2 /* GD reloc. */
3135 #define TLS_LD 4 /* LD reloc. */
3136 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
3137 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
3138 #define TLS_MARK 32 /* __tls_get_addr call marked. */
3139 #define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
3140 #define TLS_EXPLICIT 256 /* TOC section TLS reloc, not stored. */
3141 unsigned char tls_mask
;
3143 /* The above field is also used to mark function symbols. In which
3144 case TLS_TLS will be 0. */
3145 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
3146 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
3147 #define NON_GOT 256 /* local symbol plt, not stored. */
3150 static inline struct ppc_link_hash_entry
*
3151 ppc_elf_hash_entry (struct elf_link_hash_entry
*ent
)
3153 return (struct ppc_link_hash_entry
*) ent
;
3156 static inline struct elf_link_hash_entry
*
3157 elf_hash_entry (struct ppc_link_hash_entry
*ent
)
3159 return (struct elf_link_hash_entry
*) ent
;
3162 /* ppc64 ELF linker hash table. */
3164 struct ppc_link_hash_table
3166 struct elf_link_hash_table elf
;
3168 /* The stub hash table. */
3169 struct bfd_hash_table stub_hash_table
;
3171 /* Another hash table for plt_branch stubs. */
3172 struct bfd_hash_table branch_hash_table
;
3174 /* Hash table for function prologue tocsave. */
3175 htab_t tocsave_htab
;
3177 /* Various options and other info passed from the linker. */
3178 struct ppc64_elf_params
*params
;
3180 /* The size of sec_info below. */
3181 unsigned int sec_info_arr_size
;
3183 /* Per-section array of extra section info. Done this way rather
3184 than as part of ppc64_elf_section_data so we have the info for
3185 non-ppc64 sections. */
3188 /* Along with elf_gp, specifies the TOC pointer used by this section. */
3193 /* The section group that this section belongs to. */
3194 struct map_stub
*group
;
3195 /* A temp section list pointer. */
3200 /* Linked list of groups. */
3201 struct map_stub
*group
;
3203 /* Temp used when calculating TOC pointers. */
3206 asection
*toc_first_sec
;
3208 /* Used when adding symbols. */
3209 struct ppc_link_hash_entry
*dot_syms
;
3211 /* Shortcuts to get to dynamic linker sections. */
3213 asection
*global_entry
;
3216 asection
*relpltlocal
;
3219 asection
*glink_eh_frame
;
3221 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3222 struct ppc_link_hash_entry
*tls_get_addr
;
3223 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3224 struct ppc_link_hash_entry
*tga_desc
;
3225 struct ppc_link_hash_entry
*tga_desc_fd
;
3226 struct map_stub
*tga_group
;
3228 /* The size of reliplt used by got entry relocs. */
3229 bfd_size_type got_reli_size
;
3232 unsigned long stub_count
[ppc_stub_global_entry
];
3234 /* Number of stubs against global syms. */
3235 unsigned long stub_globals
;
3237 /* Set if we're linking code with function descriptors. */
3238 unsigned int opd_abi
:1;
3240 /* Support for multiple toc sections. */
3241 unsigned int do_multi_toc
:1;
3242 unsigned int multi_toc_needed
:1;
3243 unsigned int second_toc_pass
:1;
3244 unsigned int do_toc_opt
:1;
3246 /* Set if tls optimization is enabled. */
3247 unsigned int do_tls_opt
:1;
3249 /* Set if inline plt calls should be converted to direct calls. */
3250 unsigned int can_convert_all_inline_plt
:1;
3253 unsigned int stub_error
:1;
3255 /* Whether func_desc_adjust needs to be run over symbols. */
3256 unsigned int need_func_desc_adj
:1;
3258 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
3259 unsigned int has_plt_localentry0
:1;
3261 /* Whether calls are made via the PLT from NOTOC functions. */
3262 unsigned int notoc_plt
:1;
3264 /* Whether any code linked seems to be Power10. */
3265 unsigned int has_power10_relocs
:1;
3267 /* Incremented every time we size stubs. */
3268 unsigned int stub_iteration
;
3271 /* Rename some of the generic section flags to better document how they
3274 /* Nonzero if this section has TLS related relocations. */
3275 #define has_tls_reloc sec_flg0
3277 /* Nonzero if this section has a call to __tls_get_addr lacking marker
3279 #define nomark_tls_get_addr sec_flg1
3281 /* Nonzero if this section has any toc or got relocs. */
3282 #define has_toc_reloc sec_flg2
3284 /* Nonzero if this section has a call to another section that uses
3286 #define makes_toc_func_call sec_flg3
3288 /* Recursion protection when determining above flag. */
3289 #define call_check_in_progress sec_flg4
3290 #define call_check_done sec_flg5
3292 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3294 #define ppc_hash_table(p) \
3295 ((is_elf_hash_table ((p)->hash) \
3296 && elf_hash_table_id (elf_hash_table (p)) == PPC64_ELF_DATA) \
3297 ? (struct ppc_link_hash_table *) (p)->hash : NULL)
3299 #define ppc_stub_hash_lookup(table, string, create, copy) \
3300 ((struct ppc_stub_hash_entry *) \
3301 bfd_hash_lookup ((table), (string), (create), (copy)))
3303 #define ppc_branch_hash_lookup(table, string, create, copy) \
3304 ((struct ppc_branch_hash_entry *) \
3305 bfd_hash_lookup ((table), (string), (create), (copy)))
3307 /* Create an entry in the stub hash table. */
3309 static struct bfd_hash_entry
*
3310 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3311 struct bfd_hash_table
*table
,
3314 /* Allocate the structure if it has not already been allocated by a
3318 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3323 /* Call the allocation method of the superclass. */
3324 entry
= bfd_hash_newfunc (entry
, table
, string
);
3327 struct ppc_stub_hash_entry
*eh
;
3329 /* Initialize the local fields. */
3330 eh
= (struct ppc_stub_hash_entry
*) entry
;
3331 eh
->stub_type
= ppc_stub_none
;
3333 eh
->stub_offset
= 0;
3334 eh
->target_value
= 0;
3335 eh
->target_section
= NULL
;
3344 /* Create an entry in the branch hash table. */
3346 static struct bfd_hash_entry
*
3347 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3348 struct bfd_hash_table
*table
,
3351 /* Allocate the structure if it has not already been allocated by a
3355 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3360 /* Call the allocation method of the superclass. */
3361 entry
= bfd_hash_newfunc (entry
, table
, string
);
3364 struct ppc_branch_hash_entry
*eh
;
3366 /* Initialize the local fields. */
3367 eh
= (struct ppc_branch_hash_entry
*) entry
;
3375 /* Create an entry in a ppc64 ELF linker hash table. */
3377 static struct bfd_hash_entry
*
3378 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3379 struct bfd_hash_table
*table
,
3382 /* Allocate the structure if it has not already been allocated by a
3386 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3391 /* Call the allocation method of the superclass. */
3392 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3395 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3397 memset (&eh
->u
.stub_cache
, 0,
3398 (sizeof (struct ppc_link_hash_entry
)
3399 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3401 /* When making function calls, old ABI code references function entry
3402 points (dot symbols), while new ABI code references the function
3403 descriptor symbol. We need to make any combination of reference and
3404 definition work together, without breaking archive linking.
3406 For a defined function "foo" and an undefined call to "bar":
3407 An old object defines "foo" and ".foo", references ".bar" (possibly
3409 A new object defines "foo" and references "bar".
3411 A new object thus has no problem with its undefined symbols being
3412 satisfied by definitions in an old object. On the other hand, the
3413 old object won't have ".bar" satisfied by a new object.
3415 Keep a list of newly added dot-symbols. */
3417 if (string
[0] == '.')
3419 struct ppc_link_hash_table
*htab
;
3421 htab
= (struct ppc_link_hash_table
*) table
;
3422 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3423 htab
->dot_syms
= eh
;
3430 struct tocsave_entry
3437 tocsave_htab_hash (const void *p
)
3439 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3440 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3444 tocsave_htab_eq (const void *p1
, const void *p2
)
3446 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3447 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3448 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3451 /* Destroy a ppc64 ELF linker hash table. */
3454 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3456 struct ppc_link_hash_table
*htab
;
3458 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3459 if (htab
->tocsave_htab
)
3460 htab_delete (htab
->tocsave_htab
);
3461 bfd_hash_table_free (&htab
->branch_hash_table
);
3462 bfd_hash_table_free (&htab
->stub_hash_table
);
3463 _bfd_elf_link_hash_table_free (obfd
);
3466 /* Create a ppc64 ELF linker hash table. */
3468 static struct bfd_link_hash_table
*
3469 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3471 struct ppc_link_hash_table
*htab
;
3472 size_t amt
= sizeof (struct ppc_link_hash_table
);
3474 htab
= bfd_zmalloc (amt
);
3478 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3479 sizeof (struct ppc_link_hash_entry
),
3486 /* Init the stub hash table too. */
3487 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3488 sizeof (struct ppc_stub_hash_entry
)))
3490 _bfd_elf_link_hash_table_free (abfd
);
3494 /* And the branch hash table. */
3495 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3496 sizeof (struct ppc_branch_hash_entry
)))
3498 bfd_hash_table_free (&htab
->stub_hash_table
);
3499 _bfd_elf_link_hash_table_free (abfd
);
3503 htab
->tocsave_htab
= htab_try_create (1024,
3507 if (htab
->tocsave_htab
== NULL
)
3509 ppc64_elf_link_hash_table_free (abfd
);
3512 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3514 /* Initializing two fields of the union is just cosmetic. We really
3515 only care about glist, but when compiled on a 32-bit host the
3516 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3517 debugger inspection of these fields look nicer. */
3518 htab
->elf
.init_got_refcount
.refcount
= 0;
3519 htab
->elf
.init_got_refcount
.glist
= NULL
;
3520 htab
->elf
.init_plt_refcount
.refcount
= 0;
3521 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3522 htab
->elf
.init_got_offset
.offset
= 0;
3523 htab
->elf
.init_got_offset
.glist
= NULL
;
3524 htab
->elf
.init_plt_offset
.offset
= 0;
3525 htab
->elf
.init_plt_offset
.glist
= NULL
;
3527 return &htab
->elf
.root
;
3530 /* Create sections for linker generated code. */
3533 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3535 struct ppc_link_hash_table
*htab
;
3538 htab
= ppc_hash_table (info
);
3540 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3541 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3542 if (htab
->params
->save_restore_funcs
)
3544 /* Create .sfpr for code to save and restore fp regs. */
3545 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3547 if (htab
->sfpr
== NULL
3548 || !bfd_set_section_alignment (htab
->sfpr
, 2))
3552 if (bfd_link_relocatable (info
))
3555 /* Create .glink for lazy dynamic linking support. */
3556 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3558 if (htab
->glink
== NULL
3559 || !bfd_set_section_alignment (htab
->glink
, 3))
3562 /* The part of .glink used by global entry stubs, separate so that
3563 it can be aligned appropriately without affecting htab->glink. */
3564 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3566 if (htab
->global_entry
== NULL
3567 || !bfd_set_section_alignment (htab
->global_entry
, 2))
3570 if (!info
->no_ld_generated_unwind_info
)
3572 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3573 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3574 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3577 if (htab
->glink_eh_frame
== NULL
3578 || !bfd_set_section_alignment (htab
->glink_eh_frame
, 2))
3582 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3583 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3584 if (htab
->elf
.iplt
== NULL
3585 || !bfd_set_section_alignment (htab
->elf
.iplt
, 3))
3588 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3589 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3591 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3592 if (htab
->elf
.irelplt
== NULL
3593 || !bfd_set_section_alignment (htab
->elf
.irelplt
, 3))
3596 /* Create branch lookup table for plt_branch stubs. */
3597 flags
= (SEC_ALLOC
| SEC_LOAD
3598 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3599 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3601 if (htab
->brlt
== NULL
3602 || !bfd_set_section_alignment (htab
->brlt
, 3))
3605 /* Local plt entries, put in .branch_lt but a separate section for
3607 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3609 if (htab
->pltlocal
== NULL
3610 || !bfd_set_section_alignment (htab
->pltlocal
, 3))
3613 if (!bfd_link_pic (info
))
3616 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3617 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3619 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3620 if (htab
->relbrlt
== NULL
3621 || !bfd_set_section_alignment (htab
->relbrlt
, 3))
3625 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3626 if (htab
->relpltlocal
== NULL
3627 || !bfd_set_section_alignment (htab
->relpltlocal
, 3))
3633 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3636 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3637 struct ppc64_elf_params
*params
)
3639 struct ppc_link_hash_table
*htab
;
3641 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3643 /* Always hook our dynamic sections into the first bfd, which is the
3644 linker created stub bfd. This ensures that the GOT header is at
3645 the start of the output TOC section. */
3646 htab
= ppc_hash_table (info
);
3647 htab
->elf
.dynobj
= params
->stub_bfd
;
3648 htab
->params
= params
;
3650 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3653 /* Build a name for an entry in the stub hash table. */
3656 ppc_stub_name (const asection
*input_section
,
3657 const asection
*sym_sec
,
3658 const struct ppc_link_hash_entry
*h
,
3659 const Elf_Internal_Rela
*rel
)
3664 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3665 offsets from a sym as a branch target? In fact, we could
3666 probably assume the addend is always zero. */
3667 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3671 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3672 stub_name
= bfd_malloc (len
);
3673 if (stub_name
== NULL
)
3676 len
= sprintf (stub_name
, "%08x.%s+%x",
3677 input_section
->id
& 0xffffffff,
3678 h
->elf
.root
.root
.string
,
3679 (int) rel
->r_addend
& 0xffffffff);
3683 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3684 stub_name
= bfd_malloc (len
);
3685 if (stub_name
== NULL
)
3688 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3689 input_section
->id
& 0xffffffff,
3690 sym_sec
->id
& 0xffffffff,
3691 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3692 (int) rel
->r_addend
& 0xffffffff);
3694 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3695 stub_name
[len
- 2] = 0;
3699 /* If mixing power10 with non-power10 code and --power10-stubs is not
3700 specified (or is auto) then calls using @notoc relocations that
3701 need a stub will utilize power10 instructions in the stub, and
3702 calls without @notoc relocations will not use power10 instructions.
3703 The two classes of stubs are stored in separate stub_hash_table
3704 entries having the same key string. The two entries will always be
3705 adjacent on entry->root.next chain, even if hash table resizing
3706 occurs. This function selects the correct entry to use. */
3708 static struct ppc_stub_hash_entry
*
3709 select_alt_stub (struct ppc_stub_hash_entry
*entry
, bool notoc
)
3713 have_notoc
= (entry
->stub_type
== ppc_stub_plt_call_notoc
3714 || entry
->stub_type
== ppc_stub_plt_branch_notoc
3715 || entry
->stub_type
== ppc_stub_long_branch_notoc
);
3717 if (have_notoc
!= notoc
)
3719 const char *stub_name
= entry
->root
.string
;
3721 entry
= (struct ppc_stub_hash_entry
*) entry
->root
.next
;
3723 && entry
->root
.string
!= stub_name
)
3730 /* Look up an entry in the stub hash. Stub entries are cached because
3731 creating the stub name takes a bit of time. */
3733 static struct ppc_stub_hash_entry
*
3734 ppc_get_stub_entry (const asection
*input_section
,
3735 const asection
*sym_sec
,
3736 struct ppc_link_hash_entry
*h
,
3737 const Elf_Internal_Rela
*rel
,
3738 struct ppc_link_hash_table
*htab
)
3740 struct ppc_stub_hash_entry
*stub_entry
;
3741 struct map_stub
*group
;
3743 /* If this input section is part of a group of sections sharing one
3744 stub section, then use the id of the first section in the group.
3745 Stub names need to include a section id, as there may well be
3746 more than one stub used to reach say, printf, and we need to
3747 distinguish between them. */
3748 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3752 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3753 && h
->u
.stub_cache
->h
== h
3754 && h
->u
.stub_cache
->group
== group
)
3756 stub_entry
= h
->u
.stub_cache
;
3762 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3763 if (stub_name
== NULL
)
3766 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3767 stub_name
, false, false);
3769 h
->u
.stub_cache
= stub_entry
;
3774 if (stub_entry
!= NULL
&& htab
->params
->power10_stubs
== -1)
3776 bool notoc
= ELF64_R_TYPE (rel
->r_info
) == R_PPC64_REL24_NOTOC
;
3778 stub_entry
= select_alt_stub (stub_entry
, notoc
);
3784 /* Add a new stub entry to the stub hash. Not all fields of the new
3785 stub entry are initialised. */
3787 static struct ppc_stub_hash_entry
*
3788 ppc_add_stub (const char *stub_name
,
3790 struct bfd_link_info
*info
)
3792 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3793 struct map_stub
*group
;
3796 struct ppc_stub_hash_entry
*stub_entry
;
3798 group
= htab
->sec_info
[section
->id
].u
.group
;
3799 link_sec
= group
->link_sec
;
3800 stub_sec
= group
->stub_sec
;
3801 if (stub_sec
== NULL
)
3807 namelen
= strlen (link_sec
->name
);
3808 len
= namelen
+ sizeof (STUB_SUFFIX
);
3809 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3813 memcpy (s_name
, link_sec
->name
, namelen
);
3814 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3815 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3816 if (stub_sec
== NULL
)
3818 group
->stub_sec
= stub_sec
;
3821 /* Enter this entry into the linker stub hash table. */
3822 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3824 if (stub_entry
== NULL
)
3826 /* xgettext:c-format */
3827 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3828 section
->owner
, stub_name
);
3832 stub_entry
->group
= group
;
3833 stub_entry
->stub_offset
= 0;
3837 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3838 not already done. */
3841 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3843 asection
*got
, *relgot
;
3845 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3847 if (!is_ppc64_elf (abfd
))
3853 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3856 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3857 | SEC_LINKER_CREATED
);
3859 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3861 || !bfd_set_section_alignment (got
, 3))
3864 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3865 flags
| SEC_READONLY
);
3867 || !bfd_set_section_alignment (relgot
, 3))
3870 ppc64_elf_tdata (abfd
)->got
= got
;
3871 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3875 /* Follow indirect and warning symbol links. */
3877 static inline struct bfd_link_hash_entry
*
3878 follow_link (struct bfd_link_hash_entry
*h
)
3880 while (h
->type
== bfd_link_hash_indirect
3881 || h
->type
== bfd_link_hash_warning
)
3886 static inline struct elf_link_hash_entry
*
3887 elf_follow_link (struct elf_link_hash_entry
*h
)
3889 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
3892 static inline struct ppc_link_hash_entry
*
3893 ppc_follow_link (struct ppc_link_hash_entry
*h
)
3895 return ppc_elf_hash_entry (elf_follow_link (&h
->elf
));
3898 /* Merge PLT info on FROM with that on TO. */
3901 move_plt_plist (struct ppc_link_hash_entry
*from
,
3902 struct ppc_link_hash_entry
*to
)
3904 if (from
->elf
.plt
.plist
!= NULL
)
3906 if (to
->elf
.plt
.plist
!= NULL
)
3908 struct plt_entry
**entp
;
3909 struct plt_entry
*ent
;
3911 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3913 struct plt_entry
*dent
;
3915 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3916 if (dent
->addend
== ent
->addend
)
3918 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3925 *entp
= to
->elf
.plt
.plist
;
3928 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3929 from
->elf
.plt
.plist
= NULL
;
3933 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3936 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3937 struct elf_link_hash_entry
*dir
,
3938 struct elf_link_hash_entry
*ind
)
3940 struct ppc_link_hash_entry
*edir
, *eind
;
3942 edir
= ppc_elf_hash_entry (dir
);
3943 eind
= ppc_elf_hash_entry (ind
);
3945 edir
->is_func
|= eind
->is_func
;
3946 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3947 edir
->tls_mask
|= eind
->tls_mask
;
3948 if (eind
->oh
!= NULL
)
3949 edir
->oh
= ppc_follow_link (eind
->oh
);
3951 if (edir
->elf
.versioned
!= versioned_hidden
)
3952 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3953 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3954 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3955 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3956 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3957 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3959 /* If we were called to copy over info for a weak sym, don't copy
3960 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
3961 in order to simplify readonly_dynrelocs and save a field in the
3962 symbol hash entry, but that means dyn_relocs can't be used in any
3963 tests about a specific symbol, or affect other symbol flags which
3965 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3968 /* Copy over any dynamic relocs we may have on the indirect sym. */
3969 if (ind
->dyn_relocs
!= NULL
)
3971 if (dir
->dyn_relocs
!= NULL
)
3973 struct elf_dyn_relocs
**pp
;
3974 struct elf_dyn_relocs
*p
;
3976 /* Add reloc counts against the indirect sym to the direct sym
3977 list. Merge any entries against the same section. */
3978 for (pp
= &ind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3980 struct elf_dyn_relocs
*q
;
3982 for (q
= dir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3983 if (q
->sec
== p
->sec
)
3985 q
->pc_count
+= p
->pc_count
;
3986 q
->count
+= p
->count
;
3993 *pp
= dir
->dyn_relocs
;
3996 dir
->dyn_relocs
= ind
->dyn_relocs
;
3997 ind
->dyn_relocs
= NULL
;
4000 /* Copy over got entries that we may have already seen to the
4001 symbol which just became indirect. */
4002 if (eind
->elf
.got
.glist
!= NULL
)
4004 if (edir
->elf
.got
.glist
!= NULL
)
4006 struct got_entry
**entp
;
4007 struct got_entry
*ent
;
4009 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4011 struct got_entry
*dent
;
4013 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4014 if (dent
->addend
== ent
->addend
4015 && dent
->owner
== ent
->owner
4016 && dent
->tls_type
== ent
->tls_type
)
4018 dent
->got
.refcount
+= ent
->got
.refcount
;
4025 *entp
= edir
->elf
.got
.glist
;
4028 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4029 eind
->elf
.got
.glist
= NULL
;
4032 /* And plt entries. */
4033 move_plt_plist (eind
, edir
);
4035 if (eind
->elf
.dynindx
!= -1)
4037 if (edir
->elf
.dynindx
!= -1)
4038 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4039 edir
->elf
.dynstr_index
);
4040 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4041 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4042 eind
->elf
.dynindx
= -1;
4043 eind
->elf
.dynstr_index
= 0;
4047 /* Find the function descriptor hash entry from the given function code
4048 hash entry FH. Link the entries via their OH fields. */
4050 static struct ppc_link_hash_entry
*
4051 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4053 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4057 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4059 fdh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, fd_name
,
4060 false, false, false));
4064 fdh
->is_func_descriptor
= 1;
4070 fdh
= ppc_follow_link (fdh
);
4071 fdh
->is_func_descriptor
= 1;
4076 /* Make a fake function descriptor sym for the undefined code sym FH. */
4078 static struct ppc_link_hash_entry
*
4079 make_fdh (struct bfd_link_info
*info
,
4080 struct ppc_link_hash_entry
*fh
)
4082 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4083 struct bfd_link_hash_entry
*bh
= NULL
;
4084 struct ppc_link_hash_entry
*fdh
;
4085 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4089 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4090 fh
->elf
.root
.root
.string
+ 1,
4091 flags
, bfd_und_section_ptr
, 0,
4092 NULL
, false, false, &bh
))
4095 fdh
= (struct ppc_link_hash_entry
*) bh
;
4096 fdh
->elf
.non_elf
= 0;
4098 fdh
->is_func_descriptor
= 1;
4105 /* Fix function descriptor symbols defined in .opd sections to be
4109 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4110 struct bfd_link_info
*info
,
4111 Elf_Internal_Sym
*isym
,
4113 flagword
*flags ATTRIBUTE_UNUSED
,
4118 && strcmp ((*sec
)->name
, ".opd") == 0)
4122 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4123 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4124 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4126 /* If the symbol is a function defined in .opd, and the function
4127 code is in a discarded group, let it appear to be undefined. */
4128 if (!bfd_link_relocatable (info
)
4129 && (*sec
)->reloc_count
!= 0
4130 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4131 false) != (bfd_vma
) -1
4132 && discarded_section (code_sec
))
4134 *sec
= bfd_und_section_ptr
;
4135 isym
->st_shndx
= SHN_UNDEF
;
4138 else if (*sec
!= NULL
4139 && strcmp ((*sec
)->name
, ".toc") == 0
4140 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4142 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4144 htab
->params
->object_in_toc
= 1;
4147 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4149 if (abiversion (ibfd
) == 0)
4150 set_abiversion (ibfd
, 2);
4151 else if (abiversion (ibfd
) == 1)
4153 _bfd_error_handler (_("symbol '%s' has invalid st_other"
4154 " for ABI version 1"), *name
);
4155 bfd_set_error (bfd_error_bad_value
);
4163 /* Merge non-visibility st_other attributes: local entry point. */
4166 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
4167 unsigned int st_other
,
4171 if (definition
&& (!dynamic
|| !h
->def_regular
))
4172 h
->other
= ((st_other
& ~ELF_ST_VISIBILITY (-1))
4173 | ELF_ST_VISIBILITY (h
->other
));
4176 /* Hook called on merging a symbol. We use this to clear "fake" since
4177 we now have a real symbol. */
4180 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
4181 const Elf_Internal_Sym
*isym
,
4182 asection
**psec ATTRIBUTE_UNUSED
,
4183 bool newdef ATTRIBUTE_UNUSED
,
4184 bool olddef ATTRIBUTE_UNUSED
,
4185 bfd
*oldbfd ATTRIBUTE_UNUSED
,
4186 const asection
*oldsec ATTRIBUTE_UNUSED
)
4188 ppc_elf_hash_entry (h
)->fake
= 0;
4189 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4190 ppc_elf_hash_entry (h
)->non_zero_localentry
= 1;
4194 /* This function makes an old ABI object reference to ".bar" cause the
4195 inclusion of a new ABI object archive that defines "bar".
4196 NAME is a symbol defined in an archive. Return a symbol in the hash
4197 table that might be satisfied by the archive symbols. */
4199 static struct bfd_link_hash_entry
*
4200 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4201 struct bfd_link_info
*info
,
4204 struct bfd_link_hash_entry
*h
;
4208 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4210 && ppc_hash_table (info
) != NULL
4211 /* Don't return this sym if it is a fake function descriptor
4212 created by add_symbol_adjust. */
4213 && !((struct ppc_link_hash_entry
*) h
)->fake
)
4219 len
= strlen (name
);
4220 dot_name
= bfd_alloc (abfd
, len
+ 2);
4221 if (dot_name
== NULL
)
4222 return (struct bfd_link_hash_entry
*) -1;
4224 memcpy (dot_name
+ 1, name
, len
+ 1);
4225 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4226 bfd_release (abfd
, dot_name
);
4230 if (strcmp (name
, "__tls_get_addr_opt") == 0)
4231 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, "__tls_get_addr_desc");
4235 /* This function satisfies all old ABI object references to ".bar" if a
4236 new ABI object defines "bar". Well, at least, undefined dot symbols
4237 are made weak. This stops later archive searches from including an
4238 object if we already have a function descriptor definition. It also
4239 prevents the linker complaining about undefined symbols.
4240 We also check and correct mismatched symbol visibility here. The
4241 most restrictive visibility of the function descriptor and the
4242 function entry symbol is used. */
4245 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4247 struct ppc_link_hash_table
*htab
;
4248 struct ppc_link_hash_entry
*fdh
;
4250 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4251 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4253 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4256 if (eh
->elf
.root
.root
.string
[0] != '.')
4259 htab
= ppc_hash_table (info
);
4263 fdh
= lookup_fdh (eh
, htab
);
4265 && !bfd_link_relocatable (info
)
4266 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4267 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4268 && eh
->elf
.ref_regular
)
4270 /* Make an undefined function descriptor sym, in order to
4271 pull in an --as-needed shared lib. Archives are handled
4273 fdh
= make_fdh (info
, eh
);
4280 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4281 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4283 /* Make both descriptor and entry symbol have the most
4284 constraining visibility of either symbol. */
4285 if (entry_vis
< descr_vis
)
4286 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4287 else if (entry_vis
> descr_vis
)
4288 eh
->elf
.other
+= descr_vis
- entry_vis
;
4290 /* Propagate reference flags from entry symbol to function
4291 descriptor symbol. */
4292 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
4293 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
4294 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
4295 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
4297 if (!fdh
->elf
.forced_local
4298 && fdh
->elf
.dynindx
== -1
4299 && fdh
->elf
.versioned
!= versioned_hidden
4300 && (bfd_link_dll (info
)
4301 || fdh
->elf
.def_dynamic
4302 || fdh
->elf
.ref_dynamic
)
4303 && (eh
->elf
.ref_regular
4304 || eh
->elf
.def_regular
))
4306 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
4314 /* Set up opd section info and abiversion for IBFD, and process list
4315 of dot-symbols we made in link_hash_newfunc. */
4318 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
4320 struct ppc_link_hash_table
*htab
;
4321 struct ppc_link_hash_entry
**p
, *eh
;
4322 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
4324 if (opd
!= NULL
&& opd
->size
!= 0)
4326 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
4327 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
4329 if (abiversion (ibfd
) == 0)
4330 set_abiversion (ibfd
, 1);
4331 else if (abiversion (ibfd
) >= 2)
4333 /* xgettext:c-format */
4334 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4335 ibfd
, abiversion (ibfd
));
4336 bfd_set_error (bfd_error_bad_value
);
4341 if (is_ppc64_elf (info
->output_bfd
))
4343 /* For input files without an explicit abiversion in e_flags
4344 we should have flagged any with symbol st_other bits set
4345 as ELFv1 and above flagged those with .opd as ELFv2.
4346 Set the output abiversion if not yet set, and for any input
4347 still ambiguous, take its abiversion from the output.
4348 Differences in ABI are reported later. */
4349 if (abiversion (info
->output_bfd
) == 0)
4350 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4351 else if (abiversion (ibfd
) == 0)
4352 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4355 htab
= ppc_hash_table (info
);
4359 if (opd
!= NULL
&& opd
->size
!= 0
4360 && (ibfd
->flags
& DYNAMIC
) == 0
4361 && (opd
->flags
& SEC_RELOC
) != 0
4362 && opd
->reloc_count
!= 0
4363 && !bfd_is_abs_section (opd
->output_section
)
4364 && info
->gc_sections
)
4366 /* Garbage collection needs some extra help with .opd sections.
4367 We don't want to necessarily keep everything referenced by
4368 relocs in .opd, as that would keep all functions. Instead,
4369 if we reference an .opd symbol (a function descriptor), we
4370 want to keep the function code symbol's section. This is
4371 easy for global symbols, but for local syms we need to keep
4372 information about the associated function section. */
4374 asection
**opd_sym_map
;
4375 Elf_Internal_Shdr
*symtab_hdr
;
4376 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4378 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4379 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4380 if (opd_sym_map
== NULL
)
4382 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4383 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4387 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4388 rel_end
= relocs
+ opd
->reloc_count
- 1;
4389 for (rel
= relocs
; rel
< rel_end
; rel
++)
4391 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4392 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4394 if (r_type
== R_PPC64_ADDR64
4395 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4396 && r_symndx
< symtab_hdr
->sh_info
)
4398 Elf_Internal_Sym
*isym
;
4401 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, ibfd
,
4405 if (elf_section_data (opd
)->relocs
!= relocs
)
4410 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4411 if (s
!= NULL
&& s
!= opd
)
4412 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4415 if (elf_section_data (opd
)->relocs
!= relocs
)
4419 p
= &htab
->dot_syms
;
4420 while ((eh
= *p
) != NULL
)
4423 if (&eh
->elf
== htab
->elf
.hgot
)
4425 else if (htab
->elf
.hgot
== NULL
4426 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4427 htab
->elf
.hgot
= &eh
->elf
;
4428 else if (abiversion (ibfd
) <= 1)
4430 htab
->need_func_desc_adj
= 1;
4431 if (!add_symbol_adjust (eh
, info
))
4434 p
= &eh
->u
.next_dot_sym
;
4439 /* Undo hash table changes when an --as-needed input file is determined
4440 not to be needed. */
4443 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4444 struct bfd_link_info
*info
,
4445 enum notice_asneeded_action act
)
4447 if (act
== notice_not_needed
)
4449 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4454 htab
->dot_syms
= NULL
;
4456 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4459 /* If --just-symbols against a final linked binary, then assume we need
4460 toc adjusting stubs when calling functions defined there. */
4463 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4465 if ((sec
->flags
& SEC_CODE
) != 0
4466 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4467 && is_ppc64_elf (sec
->owner
))
4469 if (abiversion (sec
->owner
) >= 2
4470 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4471 sec
->has_toc_reloc
= 1;
4473 _bfd_elf_link_just_syms (sec
, info
);
4476 static struct plt_entry
**
4477 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4478 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4480 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4481 struct plt_entry
**local_plt
;
4482 unsigned char *local_got_tls_masks
;
4484 if (local_got_ents
== NULL
)
4486 bfd_size_type size
= symtab_hdr
->sh_info
;
4488 size
*= (sizeof (*local_got_ents
)
4489 + sizeof (*local_plt
)
4490 + sizeof (*local_got_tls_masks
));
4491 local_got_ents
= bfd_zalloc (abfd
, size
);
4492 if (local_got_ents
== NULL
)
4494 elf_local_got_ents (abfd
) = local_got_ents
;
4497 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4499 struct got_entry
*ent
;
4501 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4502 if (ent
->addend
== r_addend
4503 && ent
->owner
== abfd
4504 && ent
->tls_type
== tls_type
)
4508 size_t amt
= sizeof (*ent
);
4509 ent
= bfd_alloc (abfd
, amt
);
4512 ent
->next
= local_got_ents
[r_symndx
];
4513 ent
->addend
= r_addend
;
4515 ent
->tls_type
= tls_type
;
4516 ent
->is_indirect
= false;
4517 ent
->got
.refcount
= 0;
4518 local_got_ents
[r_symndx
] = ent
;
4520 ent
->got
.refcount
+= 1;
4523 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4524 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4525 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4527 return local_plt
+ r_symndx
;
4531 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4533 struct plt_entry
*ent
;
4535 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4536 if (ent
->addend
== addend
)
4540 size_t amt
= sizeof (*ent
);
4541 ent
= bfd_alloc (abfd
, amt
);
4545 ent
->addend
= addend
;
4546 ent
->plt
.refcount
= 0;
4549 ent
->plt
.refcount
+= 1;
4554 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4556 return (r_type
== R_PPC64_REL24
4557 || r_type
== R_PPC64_REL24_NOTOC
4558 || r_type
== R_PPC64_REL14
4559 || r_type
== R_PPC64_REL14_BRTAKEN
4560 || r_type
== R_PPC64_REL14_BRNTAKEN
4561 || r_type
== R_PPC64_ADDR24
4562 || r_type
== R_PPC64_ADDR14
4563 || r_type
== R_PPC64_ADDR14_BRTAKEN
4564 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4565 || r_type
== R_PPC64_PLTCALL
4566 || r_type
== R_PPC64_PLTCALL_NOTOC
);
4569 /* Relocs on inline plt call sequence insns prior to the call. */
4572 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4574 return (r_type
== R_PPC64_PLT16_HA
4575 || r_type
== R_PPC64_PLT16_HI
4576 || r_type
== R_PPC64_PLT16_LO
4577 || r_type
== R_PPC64_PLT16_LO_DS
4578 || r_type
== R_PPC64_PLT_PCREL34
4579 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4580 || r_type
== R_PPC64_PLTSEQ
4581 || r_type
== R_PPC64_PLTSEQ_NOTOC
);
4584 /* Look through the relocs for a section during the first phase, and
4585 calculate needed space in the global offset table, procedure
4586 linkage table, and dynamic reloc sections. */
4589 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4590 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4592 struct ppc_link_hash_table
*htab
;
4593 Elf_Internal_Shdr
*symtab_hdr
;
4594 struct elf_link_hash_entry
**sym_hashes
;
4595 const Elf_Internal_Rela
*rel
;
4596 const Elf_Internal_Rela
*rel_end
;
4598 struct elf_link_hash_entry
*tga
, *dottga
;
4601 if (bfd_link_relocatable (info
))
4604 BFD_ASSERT (is_ppc64_elf (abfd
));
4606 htab
= ppc_hash_table (info
);
4610 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4611 false, false, true);
4612 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4613 false, false, true);
4614 symtab_hdr
= &elf_symtab_hdr (abfd
);
4615 sym_hashes
= elf_sym_hashes (abfd
);
4617 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4618 rel_end
= relocs
+ sec
->reloc_count
;
4619 for (rel
= relocs
; rel
< rel_end
; rel
++)
4621 unsigned long r_symndx
;
4622 struct elf_link_hash_entry
*h
;
4623 enum elf_ppc64_reloc_type r_type
;
4625 struct _ppc64_elf_section_data
*ppc64_sec
;
4626 struct plt_entry
**ifunc
, **plt_list
;
4628 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4629 if (r_symndx
< symtab_hdr
->sh_info
)
4633 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4634 h
= elf_follow_link (h
);
4636 if (h
== htab
->elf
.hgot
)
4637 sec
->has_toc_reloc
= 1;
4640 r_type
= ELF64_R_TYPE (rel
->r_info
);
4644 case R_PPC64_D34_LO
:
4645 case R_PPC64_D34_HI30
:
4646 case R_PPC64_D34_HA30
:
4648 case R_PPC64_TPREL34
:
4649 case R_PPC64_DTPREL34
:
4650 case R_PPC64_PCREL34
:
4651 case R_PPC64_GOT_PCREL34
:
4652 case R_PPC64_GOT_TLSGD_PCREL34
:
4653 case R_PPC64_GOT_TLSLD_PCREL34
:
4654 case R_PPC64_GOT_TPREL_PCREL34
:
4655 case R_PPC64_GOT_DTPREL_PCREL34
:
4656 case R_PPC64_PLT_PCREL34
:
4657 case R_PPC64_PLT_PCREL34_NOTOC
:
4658 case R_PPC64_PCREL28
:
4659 htab
->has_power10_relocs
= 1;
4667 case R_PPC64_PLT16_HA
:
4668 case R_PPC64_GOT_TLSLD16_HA
:
4669 case R_PPC64_GOT_TLSGD16_HA
:
4670 case R_PPC64_GOT_TPREL16_HA
:
4671 case R_PPC64_GOT_DTPREL16_HA
:
4672 case R_PPC64_GOT16_HA
:
4673 case R_PPC64_TOC16_HA
:
4674 case R_PPC64_PLT16_LO
:
4675 case R_PPC64_PLT16_LO_DS
:
4676 case R_PPC64_GOT_TLSLD16_LO
:
4677 case R_PPC64_GOT_TLSGD16_LO
:
4678 case R_PPC64_GOT_TPREL16_LO_DS
:
4679 case R_PPC64_GOT_DTPREL16_LO_DS
:
4680 case R_PPC64_GOT16_LO
:
4681 case R_PPC64_GOT16_LO_DS
:
4682 case R_PPC64_TOC16_LO
:
4683 case R_PPC64_TOC16_LO_DS
:
4684 case R_PPC64_GOT_PCREL34
:
4685 ppc64_elf_tdata (abfd
)->has_optrel
= 1;
4686 ppc64_elf_section_data (sec
)->has_optrel
= 1;
4695 if (h
->type
== STT_GNU_IFUNC
)
4698 ifunc
= &h
->plt
.plist
;
4703 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
4708 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4710 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4712 NON_GOT
| PLT_IFUNC
);
4723 /* These special tls relocs tie a call to __tls_get_addr with
4724 its parameter symbol. */
4726 ppc_elf_hash_entry (h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4728 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4730 NON_GOT
| TLS_TLS
| TLS_MARK
))
4732 sec
->has_tls_reloc
= 1;
4735 case R_PPC64_GOT_TLSLD16
:
4736 case R_PPC64_GOT_TLSLD16_LO
:
4737 case R_PPC64_GOT_TLSLD16_HI
:
4738 case R_PPC64_GOT_TLSLD16_HA
:
4739 case R_PPC64_GOT_TLSLD_PCREL34
:
4740 tls_type
= TLS_TLS
| TLS_LD
;
4743 case R_PPC64_GOT_TLSGD16
:
4744 case R_PPC64_GOT_TLSGD16_LO
:
4745 case R_PPC64_GOT_TLSGD16_HI
:
4746 case R_PPC64_GOT_TLSGD16_HA
:
4747 case R_PPC64_GOT_TLSGD_PCREL34
:
4748 tls_type
= TLS_TLS
| TLS_GD
;
4751 case R_PPC64_GOT_TPREL16_DS
:
4752 case R_PPC64_GOT_TPREL16_LO_DS
:
4753 case R_PPC64_GOT_TPREL16_HI
:
4754 case R_PPC64_GOT_TPREL16_HA
:
4755 case R_PPC64_GOT_TPREL_PCREL34
:
4756 if (bfd_link_dll (info
))
4757 info
->flags
|= DF_STATIC_TLS
;
4758 tls_type
= TLS_TLS
| TLS_TPREL
;
4761 case R_PPC64_GOT_DTPREL16_DS
:
4762 case R_PPC64_GOT_DTPREL16_LO_DS
:
4763 case R_PPC64_GOT_DTPREL16_HI
:
4764 case R_PPC64_GOT_DTPREL16_HA
:
4765 case R_PPC64_GOT_DTPREL_PCREL34
:
4766 tls_type
= TLS_TLS
| TLS_DTPREL
;
4768 sec
->has_tls_reloc
= 1;
4772 case R_PPC64_GOT16_LO
:
4773 case R_PPC64_GOT16_HI
:
4774 case R_PPC64_GOT16_HA
:
4775 case R_PPC64_GOT16_DS
:
4776 case R_PPC64_GOT16_LO_DS
:
4777 case R_PPC64_GOT_PCREL34
:
4779 /* This symbol requires a global offset table entry. */
4780 sec
->has_toc_reloc
= 1;
4781 if (r_type
== R_PPC64_GOT_TLSLD16
4782 || r_type
== R_PPC64_GOT_TLSGD16
4783 || r_type
== R_PPC64_GOT_TPREL16_DS
4784 || r_type
== R_PPC64_GOT_DTPREL16_DS
4785 || r_type
== R_PPC64_GOT16
4786 || r_type
== R_PPC64_GOT16_DS
)
4788 htab
->do_multi_toc
= 1;
4789 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4792 if (ppc64_elf_tdata (abfd
)->got
== NULL
4793 && !create_got_section (abfd
, info
))
4798 struct ppc_link_hash_entry
*eh
;
4799 struct got_entry
*ent
;
4801 eh
= ppc_elf_hash_entry (h
);
4802 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4803 if (ent
->addend
== rel
->r_addend
4804 && ent
->owner
== abfd
4805 && ent
->tls_type
== tls_type
)
4809 size_t amt
= sizeof (*ent
);
4810 ent
= bfd_alloc (abfd
, amt
);
4813 ent
->next
= eh
->elf
.got
.glist
;
4814 ent
->addend
= rel
->r_addend
;
4816 ent
->tls_type
= tls_type
;
4817 ent
->is_indirect
= false;
4818 ent
->got
.refcount
= 0;
4819 eh
->elf
.got
.glist
= ent
;
4821 ent
->got
.refcount
+= 1;
4822 eh
->tls_mask
|= tls_type
;
4825 /* This is a global offset table entry for a local symbol. */
4826 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4827 rel
->r_addend
, tls_type
))
4831 case R_PPC64_PLT16_HA
:
4832 case R_PPC64_PLT16_HI
:
4833 case R_PPC64_PLT16_LO
:
4834 case R_PPC64_PLT16_LO_DS
:
4835 case R_PPC64_PLT_PCREL34
:
4836 case R_PPC64_PLT_PCREL34_NOTOC
:
4839 /* This symbol requires a procedure linkage table entry. */
4844 if (h
->root
.root
.string
[0] == '.'
4845 && h
->root
.root
.string
[1] != '\0')
4846 ppc_elf_hash_entry (h
)->is_func
= 1;
4847 ppc_elf_hash_entry (h
)->tls_mask
|= PLT_KEEP
;
4848 plt_list
= &h
->plt
.plist
;
4850 if (plt_list
== NULL
)
4851 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4853 NON_GOT
| PLT_KEEP
);
4854 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4858 /* The following relocations don't need to propagate the
4859 relocation if linking a shared object since they are
4860 section relative. */
4861 case R_PPC64_SECTOFF
:
4862 case R_PPC64_SECTOFF_LO
:
4863 case R_PPC64_SECTOFF_HI
:
4864 case R_PPC64_SECTOFF_HA
:
4865 case R_PPC64_SECTOFF_DS
:
4866 case R_PPC64_SECTOFF_LO_DS
:
4867 case R_PPC64_DTPREL16
:
4868 case R_PPC64_DTPREL16_LO
:
4869 case R_PPC64_DTPREL16_HI
:
4870 case R_PPC64_DTPREL16_HA
:
4871 case R_PPC64_DTPREL16_DS
:
4872 case R_PPC64_DTPREL16_LO_DS
:
4873 case R_PPC64_DTPREL16_HIGH
:
4874 case R_PPC64_DTPREL16_HIGHA
:
4875 case R_PPC64_DTPREL16_HIGHER
:
4876 case R_PPC64_DTPREL16_HIGHERA
:
4877 case R_PPC64_DTPREL16_HIGHEST
:
4878 case R_PPC64_DTPREL16_HIGHESTA
:
4883 case R_PPC64_REL16_LO
:
4884 case R_PPC64_REL16_HI
:
4885 case R_PPC64_REL16_HA
:
4886 case R_PPC64_REL16_HIGH
:
4887 case R_PPC64_REL16_HIGHA
:
4888 case R_PPC64_REL16_HIGHER
:
4889 case R_PPC64_REL16_HIGHERA
:
4890 case R_PPC64_REL16_HIGHEST
:
4891 case R_PPC64_REL16_HIGHESTA
:
4892 case R_PPC64_REL16_HIGHER34
:
4893 case R_PPC64_REL16_HIGHERA34
:
4894 case R_PPC64_REL16_HIGHEST34
:
4895 case R_PPC64_REL16_HIGHESTA34
:
4896 case R_PPC64_REL16DX_HA
:
4899 /* Not supported as a dynamic relocation. */
4900 case R_PPC64_ADDR64_LOCAL
:
4901 if (bfd_link_pic (info
))
4903 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
4905 /* xgettext:c-format */
4906 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
4907 "in shared libraries and PIEs\n"),
4908 abfd
, sec
, rel
->r_offset
,
4909 ppc64_elf_howto_table
[r_type
]->name
);
4910 bfd_set_error (bfd_error_bad_value
);
4916 case R_PPC64_TOC16_DS
:
4917 htab
->do_multi_toc
= 1;
4918 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4920 case R_PPC64_TOC16_LO
:
4921 case R_PPC64_TOC16_HI
:
4922 case R_PPC64_TOC16_HA
:
4923 case R_PPC64_TOC16_LO_DS
:
4924 sec
->has_toc_reloc
= 1;
4925 if (h
!= NULL
&& bfd_link_executable (info
))
4927 /* We may need a copy reloc. */
4929 /* Strongly prefer a copy reloc over a dynamic reloc.
4930 glibc ld.so as of 2019-08 will error out if one of
4931 these relocations is emitted. */
4941 /* This relocation describes the C++ object vtable hierarchy.
4942 Reconstruct it for later use during GC. */
4943 case R_PPC64_GNU_VTINHERIT
:
4944 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4948 /* This relocation describes which C++ vtable entries are actually
4949 used. Record for later use during GC. */
4950 case R_PPC64_GNU_VTENTRY
:
4951 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4956 case R_PPC64_REL14_BRTAKEN
:
4957 case R_PPC64_REL14_BRNTAKEN
:
4959 asection
*dest
= NULL
;
4961 /* Heuristic: If jumping outside our section, chances are
4962 we are going to need a stub. */
4965 /* If the sym is weak it may be overridden later, so
4966 don't assume we know where a weak sym lives. */
4967 if (h
->root
.type
== bfd_link_hash_defined
)
4968 dest
= h
->root
.u
.def
.section
;
4972 Elf_Internal_Sym
*isym
;
4974 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
4979 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4983 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4987 case R_PPC64_PLTCALL
:
4988 case R_PPC64_PLTCALL_NOTOC
:
4989 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
4993 case R_PPC64_REL24_NOTOC
:
4999 if (h
->root
.root
.string
[0] == '.'
5000 && h
->root
.root
.string
[1] != '\0')
5001 ppc_elf_hash_entry (h
)->is_func
= 1;
5003 if (h
== tga
|| h
== dottga
)
5005 sec
->has_tls_reloc
= 1;
5007 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5008 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5009 /* We have a new-style __tls_get_addr call with
5013 /* Mark this section as having an old-style call. */
5014 sec
->nomark_tls_get_addr
= 1;
5016 plt_list
= &h
->plt
.plist
;
5019 /* We may need a .plt entry if the function this reloc
5020 refers to is in a shared lib. */
5022 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5026 case R_PPC64_ADDR14
:
5027 case R_PPC64_ADDR14_BRNTAKEN
:
5028 case R_PPC64_ADDR14_BRTAKEN
:
5029 case R_PPC64_ADDR24
:
5032 case R_PPC64_TPREL64
:
5033 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5034 if (bfd_link_dll (info
))
5035 info
->flags
|= DF_STATIC_TLS
;
5038 case R_PPC64_DTPMOD64
:
5039 if (rel
+ 1 < rel_end
5040 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5041 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5042 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5044 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5047 case R_PPC64_DTPREL64
:
5048 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5050 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5051 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5052 /* This is the second reloc of a dtpmod, dtprel pair.
5053 Don't mark with TLS_DTPREL. */
5057 sec
->has_tls_reloc
= 1;
5059 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
& 0xff;
5061 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5062 rel
->r_addend
, tls_type
))
5065 ppc64_sec
= ppc64_elf_section_data (sec
);
5066 if (ppc64_sec
->sec_type
!= sec_toc
)
5070 /* One extra to simplify get_tls_mask. */
5071 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5072 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5073 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5075 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5076 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5077 if (ppc64_sec
->u
.toc
.add
== NULL
)
5079 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5080 ppc64_sec
->sec_type
= sec_toc
;
5082 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5083 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5084 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5086 /* Mark the second slot of a GD or LD entry.
5087 -1 to indicate GD and -2 to indicate LD. */
5088 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5089 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5090 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5091 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5094 case R_PPC64_TPREL16_HI
:
5095 case R_PPC64_TPREL16_HA
:
5096 case R_PPC64_TPREL16_HIGH
:
5097 case R_PPC64_TPREL16_HIGHA
:
5098 case R_PPC64_TPREL16_HIGHER
:
5099 case R_PPC64_TPREL16_HIGHERA
:
5100 case R_PPC64_TPREL16_HIGHEST
:
5101 case R_PPC64_TPREL16_HIGHESTA
:
5102 sec
->has_tls_reloc
= 1;
5104 case R_PPC64_TPREL34
:
5105 case R_PPC64_TPREL16
:
5106 case R_PPC64_TPREL16_DS
:
5107 case R_PPC64_TPREL16_LO
:
5108 case R_PPC64_TPREL16_LO_DS
:
5109 if (bfd_link_dll (info
))
5110 info
->flags
|= DF_STATIC_TLS
;
5113 case R_PPC64_ADDR64
:
5115 && rel
+ 1 < rel_end
5116 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5119 ppc_elf_hash_entry (h
)->is_func
= 1;
5123 case R_PPC64_ADDR16
:
5124 case R_PPC64_ADDR16_DS
:
5125 case R_PPC64_ADDR16_HA
:
5126 case R_PPC64_ADDR16_HI
:
5127 case R_PPC64_ADDR16_HIGH
:
5128 case R_PPC64_ADDR16_HIGHA
:
5129 case R_PPC64_ADDR16_HIGHER
:
5130 case R_PPC64_ADDR16_HIGHERA
:
5131 case R_PPC64_ADDR16_HIGHEST
:
5132 case R_PPC64_ADDR16_HIGHESTA
:
5133 case R_PPC64_ADDR16_LO
:
5134 case R_PPC64_ADDR16_LO_DS
:
5136 case R_PPC64_D34_LO
:
5137 case R_PPC64_D34_HI30
:
5138 case R_PPC64_D34_HA30
:
5139 case R_PPC64_ADDR16_HIGHER34
:
5140 case R_PPC64_ADDR16_HIGHERA34
:
5141 case R_PPC64_ADDR16_HIGHEST34
:
5142 case R_PPC64_ADDR16_HIGHESTA34
:
5144 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5145 && rel
->r_addend
== 0)
5147 /* We may need a .plt entry if this reloc refers to a
5148 function in a shared lib. */
5149 if (!update_plt_info (abfd
, &h
->plt
.plist
, 0))
5151 h
->pointer_equality_needed
= 1;
5158 case R_PPC64_ADDR32
:
5159 case R_PPC64_UADDR16
:
5160 case R_PPC64_UADDR32
:
5161 case R_PPC64_UADDR64
:
5163 if (h
!= NULL
&& bfd_link_executable (info
))
5164 /* We may need a copy reloc. */
5167 /* Don't propagate .opd relocs. */
5168 if (NO_OPD_RELOCS
&& is_opd
)
5171 /* If we are creating a shared library, and this is a reloc
5172 against a global symbol, or a non PC relative reloc
5173 against a local symbol, then we need to copy the reloc
5174 into the shared library. However, if we are linking with
5175 -Bsymbolic, we do not need to copy a reloc against a
5176 global symbol which is defined in an object we are
5177 including in the link (i.e., DEF_REGULAR is set). At
5178 this point we have not seen all the input files, so it is
5179 possible that DEF_REGULAR is not set now but will be set
5180 later (it is never cleared). In case of a weak definition,
5181 DEF_REGULAR may be cleared later by a strong definition in
5182 a shared library. We account for that possibility below by
5183 storing information in the dyn_relocs field of the hash
5184 table entry. A similar situation occurs when creating
5185 shared libraries and symbol visibility changes render the
5188 If on the other hand, we are creating an executable, we
5189 may need to keep relocations for symbols satisfied by a
5190 dynamic library if we manage to avoid copy relocs for the
5194 && (h
->root
.type
== bfd_link_hash_defweak
5195 || !h
->def_regular
))
5197 && !bfd_link_executable (info
)
5198 && !SYMBOLIC_BIND (info
, h
))
5199 || (bfd_link_pic (info
)
5200 && must_be_dyn_reloc (info
, r_type
))
5201 || (!bfd_link_pic (info
)
5204 /* We must copy these reloc types into the output file.
5205 Create a reloc section in dynobj and make room for
5209 sreloc
= _bfd_elf_make_dynamic_reloc_section
5210 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ true);
5216 /* If this is a global symbol, we count the number of
5217 relocations we need for this symbol. */
5220 struct elf_dyn_relocs
*p
;
5221 struct elf_dyn_relocs
**head
;
5223 head
= &h
->dyn_relocs
;
5225 if (p
== NULL
|| p
->sec
!= sec
)
5227 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5237 if (!must_be_dyn_reloc (info
, r_type
))
5242 /* Track dynamic relocs needed for local syms too.
5243 We really need local syms available to do this
5245 struct ppc_dyn_relocs
*p
;
5246 struct ppc_dyn_relocs
**head
;
5250 Elf_Internal_Sym
*isym
;
5252 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
5257 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5261 vpp
= &elf_section_data (s
)->local_dynrel
;
5262 head
= (struct ppc_dyn_relocs
**) vpp
;
5263 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5265 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5267 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5269 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5275 p
->ifunc
= is_ifunc
;
5291 /* Merge backend specific data from an object file to the output
5292 object file when linking. */
5295 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5297 bfd
*obfd
= info
->output_bfd
;
5298 unsigned long iflags
, oflags
;
5300 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5303 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5306 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
5309 iflags
= elf_elfheader (ibfd
)->e_flags
;
5310 oflags
= elf_elfheader (obfd
)->e_flags
;
5312 if (iflags
& ~EF_PPC64_ABI
)
5315 /* xgettext:c-format */
5316 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5317 bfd_set_error (bfd_error_bad_value
);
5320 else if (iflags
!= oflags
&& iflags
!= 0)
5323 /* xgettext:c-format */
5324 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
5325 ibfd
, iflags
, oflags
);
5326 bfd_set_error (bfd_error_bad_value
);
5330 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
5333 /* Merge Tag_compatibility attributes and any common GNU ones. */
5334 return _bfd_elf_merge_object_attributes (ibfd
, info
);
5338 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5340 /* Print normal ELF private data. */
5341 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5343 if (elf_elfheader (abfd
)->e_flags
!= 0)
5347 fprintf (file
, _("private flags = 0x%lx:"),
5348 elf_elfheader (abfd
)->e_flags
);
5350 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5351 fprintf (file
, _(" [abiv%ld]"),
5352 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5359 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5360 of the code entry point, and its section, which must be in the same
5361 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5364 opd_entry_value (asection
*opd_sec
,
5366 asection
**code_sec
,
5370 bfd
*opd_bfd
= opd_sec
->owner
;
5371 Elf_Internal_Rela
*relocs
;
5372 Elf_Internal_Rela
*lo
, *hi
, *look
;
5375 /* No relocs implies we are linking a --just-symbols object, or looking
5376 at a final linked executable with addr2line or somesuch. */
5377 if (opd_sec
->reloc_count
== 0)
5379 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
5381 if (contents
== NULL
)
5383 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5384 return (bfd_vma
) -1;
5385 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5388 /* PR 17512: file: 64b9dfbb. */
5389 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5390 return (bfd_vma
) -1;
5392 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5393 if (code_sec
!= NULL
)
5395 asection
*sec
, *likely
= NULL
;
5401 && val
< sec
->vma
+ sec
->size
)
5407 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5409 && (sec
->flags
& SEC_LOAD
) != 0
5410 && (sec
->flags
& SEC_ALLOC
) != 0)
5415 if (code_off
!= NULL
)
5416 *code_off
= val
- likely
->vma
;
5422 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5424 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5426 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, true);
5427 /* PR 17512: file: df8e1fd6. */
5429 return (bfd_vma
) -1;
5431 /* Go find the opd reloc at the sym address. */
5433 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5437 look
= lo
+ (hi
- lo
) / 2;
5438 if (look
->r_offset
< offset
)
5440 else if (look
->r_offset
> offset
)
5444 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5446 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5447 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5449 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5450 asection
*sec
= NULL
;
5452 if (symndx
>= symtab_hdr
->sh_info
5453 && elf_sym_hashes (opd_bfd
) != NULL
)
5455 struct elf_link_hash_entry
**sym_hashes
;
5456 struct elf_link_hash_entry
*rh
;
5458 sym_hashes
= elf_sym_hashes (opd_bfd
);
5459 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5462 rh
= elf_follow_link (rh
);
5463 if (rh
->root
.type
!= bfd_link_hash_defined
5464 && rh
->root
.type
!= bfd_link_hash_defweak
)
5466 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5468 val
= rh
->root
.u
.def
.value
;
5469 sec
= rh
->root
.u
.def
.section
;
5476 Elf_Internal_Sym
*sym
;
5478 if (symndx
< symtab_hdr
->sh_info
)
5480 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5483 size_t symcnt
= symtab_hdr
->sh_info
;
5484 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5489 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5495 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5501 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5504 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5505 val
= sym
->st_value
;
5508 val
+= look
->r_addend
;
5509 if (code_off
!= NULL
)
5511 if (code_sec
!= NULL
)
5513 if (in_code_sec
&& *code_sec
!= sec
)
5518 if (sec
->output_section
!= NULL
)
5519 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5528 /* If the ELF symbol SYM might be a function in SEC, return the
5529 function size and set *CODE_OFF to the function's entry point,
5530 otherwise return zero. */
5532 static bfd_size_type
5533 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5538 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5539 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5543 if (!(sym
->flags
& BSF_SYNTHETIC
))
5544 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
5546 if (strcmp (sym
->section
->name
, ".opd") == 0)
5548 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5549 bfd_vma symval
= sym
->value
;
5552 && opd
->adjust
!= NULL
5553 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5555 /* opd_entry_value will use cached relocs that have been
5556 adjusted, but with raw symbols. That means both local
5557 and global symbols need adjusting. */
5558 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5564 if (opd_entry_value (sym
->section
, symval
,
5565 &sec
, code_off
, true) == (bfd_vma
) -1)
5567 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5568 symbol. This size has nothing to do with the code size of the
5569 function, which is what we're supposed to return, but the
5570 code size isn't available without looking up the dot-sym.
5571 However, doing that would be a waste of time particularly
5572 since elf_find_function will look at the dot-sym anyway.
5573 Now, elf_find_function will keep the largest size of any
5574 function sym found at the code address of interest, so return
5575 1 here to avoid it incorrectly caching a larger function size
5576 for a small function. This does mean we return the wrong
5577 size for a new-ABI function of size 24, but all that does is
5578 disable caching for such functions. */
5584 if (sym
->section
!= sec
)
5586 *code_off
= sym
->value
;
5593 /* Return true if symbol is a strong function defined in an ELFv2
5594 object with st_other localentry bits of zero, ie. its local entry
5595 point coincides with its global entry point. */
5598 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5601 && h
->type
== STT_FUNC
5602 && h
->root
.type
== bfd_link_hash_defined
5603 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5604 && !ppc_elf_hash_entry (h
)->non_zero_localentry
5605 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5606 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5609 /* Return true if symbol is defined in a regular object file. */
5612 is_static_defined (struct elf_link_hash_entry
*h
)
5614 return ((h
->root
.type
== bfd_link_hash_defined
5615 || h
->root
.type
== bfd_link_hash_defweak
)
5616 && h
->root
.u
.def
.section
!= NULL
5617 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5620 /* If FDH is a function descriptor symbol, return the associated code
5621 entry symbol if it is defined. Return NULL otherwise. */
5623 static struct ppc_link_hash_entry
*
5624 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5626 if (fdh
->is_func_descriptor
)
5628 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5629 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5630 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5636 /* If FH is a function code entry symbol, return the associated
5637 function descriptor symbol if it is defined. Return NULL otherwise. */
5639 static struct ppc_link_hash_entry
*
5640 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5643 && fh
->oh
->is_func_descriptor
)
5645 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5646 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5647 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5653 /* Given H is a symbol that satisfies is_static_defined, return the
5654 value in the output file. */
5657 defined_sym_val (struct elf_link_hash_entry
*h
)
5659 return (h
->root
.u
.def
.section
->output_section
->vma
5660 + h
->root
.u
.def
.section
->output_offset
5661 + h
->root
.u
.def
.value
);
5664 /* Return true if H matches __tls_get_addr or one of its variants. */
5667 is_tls_get_addr (struct elf_link_hash_entry
*h
,
5668 struct ppc_link_hash_table
*htab
)
5670 return (h
== elf_hash_entry (htab
->tls_get_addr_fd
)
5671 || h
== elf_hash_entry (htab
->tga_desc_fd
)
5672 || h
== elf_hash_entry (htab
->tls_get_addr
)
5673 || h
== elf_hash_entry (htab
->tga_desc
));
5676 static bool func_desc_adjust (struct elf_link_hash_entry
*, void *);
5678 /* Garbage collect sections, after first dealing with dot-symbols. */
5681 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5683 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5685 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5687 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5688 htab
->need_func_desc_adj
= 0;
5690 return bfd_elf_gc_sections (abfd
, info
);
5693 /* Mark all our entry sym sections, both opd and code section. */
5696 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5698 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5699 struct bfd_sym_chain
*sym
;
5704 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5706 struct ppc_link_hash_entry
*eh
, *fh
;
5709 eh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
->name
,
5710 false, false, true));
5713 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5714 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5717 fh
= defined_code_entry (eh
);
5720 sec
= fh
->elf
.root
.u
.def
.section
;
5721 sec
->flags
|= SEC_KEEP
;
5723 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5724 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5725 eh
->elf
.root
.u
.def
.value
,
5726 &sec
, NULL
, false) != (bfd_vma
) -1)
5727 sec
->flags
|= SEC_KEEP
;
5729 sec
= eh
->elf
.root
.u
.def
.section
;
5730 sec
->flags
|= SEC_KEEP
;
5734 /* Mark sections containing dynamically referenced symbols. When
5735 building shared libraries, we must assume that any visible symbol is
5739 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5741 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5742 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
5743 struct ppc_link_hash_entry
*fdh
;
5744 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5746 /* Dynamic linking info is on the func descriptor sym. */
5747 fdh
= defined_func_desc (eh
);
5751 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5752 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5753 && (!eh
->elf
.start_stop
5754 || eh
->elf
.root
.ldscript_def
5755 || !info
->start_stop_gc
)
5756 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5757 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5758 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5759 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5760 && (!bfd_link_executable (info
)
5761 || info
->gc_keep_exported
5762 || info
->export_dynamic
5765 && (*d
->match
) (&d
->head
, NULL
,
5766 eh
->elf
.root
.root
.string
)))
5767 && (eh
->elf
.versioned
>= versioned
5768 || !bfd_hide_sym_by_version (info
->version_info
,
5769 eh
->elf
.root
.root
.string
)))))
5772 struct ppc_link_hash_entry
*fh
;
5774 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5776 /* Function descriptor syms cause the associated
5777 function code sym section to be marked. */
5778 fh
= defined_code_entry (eh
);
5781 code_sec
= fh
->elf
.root
.u
.def
.section
;
5782 code_sec
->flags
|= SEC_KEEP
;
5784 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5785 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5786 eh
->elf
.root
.u
.def
.value
,
5787 &code_sec
, NULL
, false) != (bfd_vma
) -1)
5788 code_sec
->flags
|= SEC_KEEP
;
5794 /* Return the section that should be marked against GC for a given
5798 ppc64_elf_gc_mark_hook (asection
*sec
,
5799 struct bfd_link_info
*info
,
5800 Elf_Internal_Rela
*rel
,
5801 struct elf_link_hash_entry
*h
,
5802 Elf_Internal_Sym
*sym
)
5806 /* Syms return NULL if we're marking .opd, so we avoid marking all
5807 function sections, as all functions are referenced in .opd. */
5809 if (get_opd_info (sec
) != NULL
)
5814 enum elf_ppc64_reloc_type r_type
;
5815 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5817 r_type
= ELF64_R_TYPE (rel
->r_info
);
5820 case R_PPC64_GNU_VTINHERIT
:
5821 case R_PPC64_GNU_VTENTRY
:
5825 switch (h
->root
.type
)
5827 case bfd_link_hash_defined
:
5828 case bfd_link_hash_defweak
:
5829 eh
= ppc_elf_hash_entry (h
);
5830 fdh
= defined_func_desc (eh
);
5833 /* -mcall-aixdesc code references the dot-symbol on
5834 a call reloc. Mark the function descriptor too
5835 against garbage collection. */
5837 if (fdh
->elf
.is_weakalias
)
5838 weakdef (&fdh
->elf
)->mark
= 1;
5842 /* Function descriptor syms cause the associated
5843 function code sym section to be marked. */
5844 fh
= defined_code_entry (eh
);
5847 /* They also mark their opd section. */
5848 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5850 rsec
= fh
->elf
.root
.u
.def
.section
;
5852 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5853 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5854 eh
->elf
.root
.u
.def
.value
,
5855 &rsec
, NULL
, false) != (bfd_vma
) -1)
5856 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5858 rsec
= h
->root
.u
.def
.section
;
5861 case bfd_link_hash_common
:
5862 rsec
= h
->root
.u
.c
.p
->section
;
5866 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5872 struct _opd_sec_data
*opd
;
5874 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5875 opd
= get_opd_info (rsec
);
5876 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5880 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
5887 /* The maximum size of .sfpr. */
5888 #define SFPR_MAX (218*4)
5890 struct sfpr_def_parms
5892 const char name
[12];
5893 unsigned char lo
, hi
;
5894 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
5895 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
5898 /* Auto-generate _save*, _rest* functions in .sfpr.
5899 If STUB_SEC is non-null, define alias symbols in STUB_SEC
5903 sfpr_define (struct bfd_link_info
*info
,
5904 const struct sfpr_def_parms
*parm
,
5907 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5909 size_t len
= strlen (parm
->name
);
5910 bool writing
= false;
5916 memcpy (sym
, parm
->name
, len
);
5919 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5921 struct ppc_link_hash_entry
*h
;
5923 sym
[len
+ 0] = i
/ 10 + '0';
5924 sym
[len
+ 1] = i
% 10 + '0';
5925 h
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
,
5926 writing
, true, true));
5927 if (stub_sec
!= NULL
)
5930 && h
->elf
.root
.type
== bfd_link_hash_defined
5931 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
5933 struct elf_link_hash_entry
*s
;
5935 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
5936 s
= elf_link_hash_lookup (&htab
->elf
, buf
, true, true, false);
5939 if (s
->root
.type
== bfd_link_hash_new
)
5941 s
->root
.type
= bfd_link_hash_defined
;
5942 s
->root
.u
.def
.section
= stub_sec
;
5943 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
5944 + h
->elf
.root
.u
.def
.value
);
5947 s
->ref_regular_nonweak
= 1;
5948 s
->forced_local
= 1;
5950 s
->root
.linker_def
= 1;
5958 if (!h
->elf
.def_regular
)
5960 h
->elf
.root
.type
= bfd_link_hash_defined
;
5961 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
5962 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
5963 h
->elf
.type
= STT_FUNC
;
5964 h
->elf
.def_regular
= 1;
5966 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, true);
5968 if (htab
->sfpr
->contents
== NULL
)
5970 htab
->sfpr
->contents
5971 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5972 if (htab
->sfpr
->contents
== NULL
)
5979 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5981 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5983 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5984 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5992 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5994 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5999 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6001 p
= savegpr0 (abfd
, p
, r
);
6002 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6004 bfd_put_32 (abfd
, BLR
, p
);
6009 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6011 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6016 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6018 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6020 p
= restgpr0 (abfd
, p
, r
);
6021 bfd_put_32 (abfd
, MTLR_R0
, p
);
6025 p
= restgpr0 (abfd
, p
, 30);
6026 p
= restgpr0 (abfd
, p
, 31);
6028 bfd_put_32 (abfd
, BLR
, p
);
6033 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6035 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6040 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6042 p
= savegpr1 (abfd
, p
, r
);
6043 bfd_put_32 (abfd
, BLR
, p
);
6048 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6050 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6055 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6057 p
= restgpr1 (abfd
, p
, r
);
6058 bfd_put_32 (abfd
, BLR
, p
);
6063 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6065 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6070 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6072 p
= savefpr (abfd
, p
, r
);
6073 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6075 bfd_put_32 (abfd
, BLR
, p
);
6080 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6082 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6087 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6089 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6091 p
= restfpr (abfd
, p
, r
);
6092 bfd_put_32 (abfd
, MTLR_R0
, p
);
6096 p
= restfpr (abfd
, p
, 30);
6097 p
= restfpr (abfd
, p
, 31);
6099 bfd_put_32 (abfd
, BLR
, p
);
6104 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6106 p
= savefpr (abfd
, p
, r
);
6107 bfd_put_32 (abfd
, BLR
, p
);
6112 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6114 p
= restfpr (abfd
, p
, r
);
6115 bfd_put_32 (abfd
, BLR
, p
);
6120 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6122 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6124 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6129 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6131 p
= savevr (abfd
, p
, r
);
6132 bfd_put_32 (abfd
, BLR
, p
);
6137 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6139 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6141 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6146 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6148 p
= restvr (abfd
, p
, r
);
6149 bfd_put_32 (abfd
, BLR
, p
);
6153 #define STDU_R1_0R1 0xf8210001
6154 #define ADDI_R1_R1 0x38210000
6156 /* Emit prologue of wrapper preserving regs around a call to
6157 __tls_get_addr_opt. */
6160 tls_get_addr_prologue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6164 bfd_put_32 (obfd
, MFLR_R0
, p
);
6166 bfd_put_32 (obfd
, STD_R0_0R1
+ 16, p
);
6171 for (i
= 4; i
< 12; i
++)
6174 STD_R0_0R1
| i
<< 21 | (-(13 - i
) * 8 & 0xffff), p
);
6177 bfd_put_32 (obfd
, STDU_R1_0R1
| (-128 & 0xffff), p
);
6182 for (i
= 4; i
< 12; i
++)
6185 STD_R0_0R1
| i
<< 21 | (-(12 - i
) * 8 & 0xffff), p
);
6188 bfd_put_32 (obfd
, STDU_R1_0R1
| (-96 & 0xffff), p
);
6194 /* Emit epilogue of wrapper preserving regs around a call to
6195 __tls_get_addr_opt. */
6198 tls_get_addr_epilogue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6204 for (i
= 4; i
< 12; i
++)
6206 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (128 - (13 - i
) * 8), p
);
6209 bfd_put_32 (obfd
, ADDI_R1_R1
| 128, p
);
6214 for (i
= 4; i
< 12; i
++)
6216 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (96 - (12 - i
) * 8), p
);
6219 bfd_put_32 (obfd
, ADDI_R1_R1
| 96, p
);
6222 bfd_put_32 (obfd
, LD_R0_0R1
| 16, p
);
6224 bfd_put_32 (obfd
, MTLR_R0
, p
);
6226 bfd_put_32 (obfd
, BLR
, p
);
6231 /* Called via elf_link_hash_traverse to transfer dynamic linking
6232 information on function code symbol entries to their corresponding
6233 function descriptor symbol entries. */
6236 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6238 struct bfd_link_info
*info
;
6239 struct ppc_link_hash_table
*htab
;
6240 struct ppc_link_hash_entry
*fh
;
6241 struct ppc_link_hash_entry
*fdh
;
6244 fh
= ppc_elf_hash_entry (h
);
6245 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6251 if (fh
->elf
.root
.root
.string
[0] != '.'
6252 || fh
->elf
.root
.root
.string
[1] == '\0')
6256 htab
= ppc_hash_table (info
);
6260 /* Find the corresponding function descriptor symbol. */
6261 fdh
= lookup_fdh (fh
, htab
);
6263 /* Resolve undefined references to dot-symbols as the value
6264 in the function descriptor, if we have one in a regular object.
6265 This is to satisfy cases like ".quad .foo". Calls to functions
6266 in dynamic objects are handled elsewhere. */
6267 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6268 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6269 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6270 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6271 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6272 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6273 fdh
->elf
.root
.u
.def
.value
,
6274 &fh
->elf
.root
.u
.def
.section
,
6275 &fh
->elf
.root
.u
.def
.value
, false) != (bfd_vma
) -1)
6277 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6278 fh
->elf
.forced_local
= 1;
6279 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6280 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6283 if (!fh
->elf
.dynamic
)
6285 struct plt_entry
*ent
;
6287 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6288 if (ent
->plt
.refcount
> 0)
6294 /* Create a descriptor as undefined if necessary. */
6296 && !bfd_link_executable (info
)
6297 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6298 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6300 fdh
= make_fdh (info
, fh
);
6305 /* We can't support overriding of symbols on a fake descriptor. */
6308 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6309 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6310 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6312 /* Transfer dynamic linking information to the function descriptor. */
6315 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6316 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6317 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6318 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6319 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6320 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6321 || fh
->elf
.type
== STT_FUNC
6322 || fh
->elf
.type
== STT_GNU_IFUNC
);
6323 move_plt_plist (fh
, fdh
);
6325 if (!fdh
->elf
.forced_local
6326 && fh
->elf
.dynindx
!= -1)
6327 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6331 /* Now that the info is on the function descriptor, clear the
6332 function code sym info. Any function code syms for which we
6333 don't have a definition in a regular file, we force local.
6334 This prevents a shared library from exporting syms that have
6335 been imported from another library. Function code syms that
6336 are really in the library we must leave global to prevent the
6337 linker dragging in a definition from a static library. */
6338 force_local
= (!fh
->elf
.def_regular
6340 || !fdh
->elf
.def_regular
6341 || fdh
->elf
.forced_local
);
6342 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6347 static const struct sfpr_def_parms save_res_funcs
[] =
6349 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6350 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6351 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6352 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6353 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6354 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6355 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6356 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6357 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6358 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6359 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6360 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6363 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6364 this hook to a) run the edit functions in this file, b) provide
6365 some gcc support functions, and c) transfer dynamic linking
6366 information gathered so far on function code symbol entries, to
6367 their corresponding function descriptor symbol entries. */
6370 ppc64_elf_edit (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6372 struct ppc_link_hash_table
*htab
;
6374 htab
= ppc_hash_table (info
);
6378 /* Call back into the linker, which then runs the edit functions. */
6379 htab
->params
->edit ();
6381 /* Provide any missing _save* and _rest* functions. */
6382 if (htab
->sfpr
!= NULL
)
6386 htab
->sfpr
->size
= 0;
6387 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
6388 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
6390 if (htab
->sfpr
->size
== 0)
6391 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6394 if (bfd_link_relocatable (info
))
6397 if (htab
->elf
.hgot
!= NULL
)
6399 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, true);
6400 /* Make .TOC. defined so as to prevent it being made dynamic.
6401 The wrong value here is fixed later in ppc64_elf_set_toc. */
6402 if (!htab
->elf
.hgot
->def_regular
6403 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
6405 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
6406 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
6407 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6408 htab
->elf
.hgot
->def_regular
= 1;
6409 htab
->elf
.hgot
->root
.linker_def
= 1;
6411 htab
->elf
.hgot
->type
= STT_OBJECT
;
6412 htab
->elf
.hgot
->other
6413 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
6416 if (htab
->need_func_desc_adj
)
6418 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6419 htab
->need_func_desc_adj
= 0;
6425 /* Return true if we have dynamic relocs against H or any of its weak
6426 aliases, that apply to read-only sections. Cannot be used after
6427 size_dynamic_sections. */
6430 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6432 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
6435 if (_bfd_elf_readonly_dynrelocs (&eh
->elf
))
6437 eh
= ppc_elf_hash_entry (eh
->elf
.u
.alias
);
6439 while (eh
!= NULL
&& &eh
->elf
!= h
);
6444 /* Return whether EH has pc-relative dynamic relocs. */
6447 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
6449 struct elf_dyn_relocs
*p
;
6451 for (p
= eh
->elf
.dyn_relocs
; p
!= NULL
; p
= p
->next
)
6452 if (p
->pc_count
!= 0)
6457 /* Return true if a global entry stub will be created for H. Valid
6458 for ELFv2 before plt entries have been allocated. */
6461 global_entry_stub (struct elf_link_hash_entry
*h
)
6463 struct plt_entry
*pent
;
6465 if (!h
->pointer_equality_needed
6469 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
6470 if (pent
->plt
.refcount
> 0
6471 && pent
->addend
== 0)
6477 /* Adjust a symbol defined by a dynamic object and referenced by a
6478 regular object. The current definition is in some section of the
6479 dynamic object, but we're not including those sections. We have to
6480 change the definition to something the rest of the link can
6484 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6485 struct elf_link_hash_entry
*h
)
6487 struct ppc_link_hash_table
*htab
;
6490 htab
= ppc_hash_table (info
);
6494 /* Deal with function syms. */
6495 if (h
->type
== STT_FUNC
6496 || h
->type
== STT_GNU_IFUNC
6499 bool local
= (ppc_elf_hash_entry (h
)->save_res
6500 || SYMBOL_CALLS_LOCAL (info
, h
)
6501 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6502 /* Discard dyn_relocs when non-pic if we've decided that a
6503 function symbol is local and not an ifunc. We keep dynamic
6504 relocs for ifuncs when local rather than always emitting a
6505 plt call stub for them and defining the symbol on the call
6506 stub. We can't do that for ELFv1 anyway (a function symbol
6507 is defined on a descriptor, not code) and it can be faster at
6508 run-time due to not needing to bounce through a stub. The
6509 dyn_relocs for ifuncs will be applied even in a static
6511 if (!bfd_link_pic (info
)
6512 && h
->type
!= STT_GNU_IFUNC
6514 h
->dyn_relocs
= NULL
;
6516 /* Clear procedure linkage table information for any symbol that
6517 won't need a .plt entry. */
6518 struct plt_entry
*ent
;
6519 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6520 if (ent
->plt
.refcount
> 0)
6523 || (h
->type
!= STT_GNU_IFUNC
6525 && (htab
->can_convert_all_inline_plt
6526 || (ppc_elf_hash_entry (h
)->tls_mask
6527 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6529 h
->plt
.plist
= NULL
;
6531 h
->pointer_equality_needed
= 0;
6533 else if (abiversion (info
->output_bfd
) >= 2)
6535 /* Taking a function's address in a read/write section
6536 doesn't require us to define the function symbol in the
6537 executable on a global entry stub. A dynamic reloc can
6538 be used instead. The reason we prefer a few more dynamic
6539 relocs is that calling via a global entry stub costs a
6540 few more instructions, and pointer_equality_needed causes
6541 extra work in ld.so when resolving these symbols. */
6542 if (global_entry_stub (h
))
6544 if (!_bfd_elf_readonly_dynrelocs (h
))
6546 h
->pointer_equality_needed
= 0;
6547 /* If we haven't seen a branch reloc and the symbol
6548 isn't an ifunc then we don't need a plt entry. */
6550 h
->plt
.plist
= NULL
;
6552 else if (!bfd_link_pic (info
))
6553 /* We are going to be defining the function symbol on the
6554 plt stub, so no dyn_relocs needed when non-pic. */
6555 h
->dyn_relocs
= NULL
;
6558 /* ELFv2 function symbols can't have copy relocs. */
6561 else if (!h
->needs_plt
6562 && !_bfd_elf_readonly_dynrelocs (h
))
6564 /* If we haven't seen a branch reloc and the symbol isn't an
6565 ifunc then we don't need a plt entry. */
6566 h
->plt
.plist
= NULL
;
6567 h
->pointer_equality_needed
= 0;
6572 h
->plt
.plist
= NULL
;
6574 /* If this is a weak symbol, and there is a real definition, the
6575 processor independent code will have arranged for us to see the
6576 real definition first, and we can just use the same value. */
6577 if (h
->is_weakalias
)
6579 struct elf_link_hash_entry
*def
= weakdef (h
);
6580 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6581 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6582 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6583 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6584 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6585 h
->dyn_relocs
= NULL
;
6589 /* If we are creating a shared library, we must presume that the
6590 only references to the symbol are via the global offset table.
6591 For such cases we need not do anything here; the relocations will
6592 be handled correctly by relocate_section. */
6593 if (!bfd_link_executable (info
))
6596 /* If there are no references to this symbol that do not use the
6597 GOT, we don't need to generate a copy reloc. */
6598 if (!h
->non_got_ref
)
6601 /* Don't generate a copy reloc for symbols defined in the executable. */
6602 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6604 /* If -z nocopyreloc was given, don't generate them either. */
6605 || info
->nocopyreloc
6607 /* If we don't find any dynamic relocs in read-only sections, then
6608 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6609 || (ELIMINATE_COPY_RELOCS
6611 && !alias_readonly_dynrelocs (h
))
6613 /* Protected variables do not work with .dynbss. The copy in
6614 .dynbss won't be used by the shared library with the protected
6615 definition for the variable. Text relocations are preferable
6616 to an incorrect program. */
6617 || h
->protected_def
)
6620 if (h
->type
== STT_FUNC
6621 || h
->type
== STT_GNU_IFUNC
)
6623 /* .dynbss copies of function symbols only work if we have
6624 ELFv1 dot-symbols. ELFv1 compilers since 2004 default to not
6625 use dot-symbols and set the function symbol size to the text
6626 size of the function rather than the size of the descriptor.
6627 That's wrong for copying a descriptor. */
6628 if (ppc_elf_hash_entry (h
)->oh
== NULL
6629 || !(h
->size
== 24 || h
->size
== 16))
6632 /* We should never get here, but unfortunately there are old
6633 versions of gcc (circa gcc-3.2) that improperly for the
6634 ELFv1 ABI put initialized function pointers, vtable refs and
6635 suchlike in read-only sections. Allow them to proceed, but
6636 warn that this might break at runtime. */
6637 info
->callbacks
->einfo
6638 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6639 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6640 h
->root
.root
.string
);
6643 /* This is a reference to a symbol defined by a dynamic object which
6644 is not a function. */
6646 /* We must allocate the symbol in our .dynbss section, which will
6647 become part of the .bss section of the executable. There will be
6648 an entry for this symbol in the .dynsym section. The dynamic
6649 object will contain position independent code, so all references
6650 from the dynamic object to this symbol will go through the global
6651 offset table. The dynamic linker will use the .dynsym entry to
6652 determine the address it must put in the global offset table, so
6653 both the dynamic object and the regular object will refer to the
6654 same memory location for the variable. */
6655 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6657 s
= htab
->elf
.sdynrelro
;
6658 srel
= htab
->elf
.sreldynrelro
;
6662 s
= htab
->elf
.sdynbss
;
6663 srel
= htab
->elf
.srelbss
;
6665 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6667 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6668 linker to copy the initial value out of the dynamic object
6669 and into the runtime process image. */
6670 srel
->size
+= sizeof (Elf64_External_Rela
);
6674 /* We no longer want dyn_relocs. */
6675 h
->dyn_relocs
= NULL
;
6676 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6679 /* If given a function descriptor symbol, hide both the function code
6680 sym and the descriptor. */
6682 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6683 struct elf_link_hash_entry
*h
,
6686 struct ppc_link_hash_entry
*eh
;
6687 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6689 if (ppc_hash_table (info
) == NULL
)
6692 eh
= ppc_elf_hash_entry (h
);
6693 if (eh
->is_func_descriptor
)
6695 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6700 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6703 /* We aren't supposed to use alloca in BFD because on
6704 systems which do not have alloca the version in libiberty
6705 calls xmalloc, which might cause the program to crash
6706 when it runs out of memory. This function doesn't have a
6707 return status, so there's no way to gracefully return an
6708 error. So cheat. We know that string[-1] can be safely
6709 accessed; It's either a string in an ELF string table,
6710 or allocated in an objalloc structure. */
6712 p
= eh
->elf
.root
.root
.string
- 1;
6715 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6719 /* Unfortunately, if it so happens that the string we were
6720 looking for was allocated immediately before this string,
6721 then we overwrote the string terminator. That's the only
6722 reason the lookup should fail. */
6725 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6726 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6728 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6729 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6739 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6744 get_sym_h (struct elf_link_hash_entry
**hp
,
6745 Elf_Internal_Sym
**symp
,
6747 unsigned char **tls_maskp
,
6748 Elf_Internal_Sym
**locsymsp
,
6749 unsigned long r_symndx
,
6752 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6754 if (r_symndx
>= symtab_hdr
->sh_info
)
6756 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6757 struct elf_link_hash_entry
*h
;
6759 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6760 h
= elf_follow_link (h
);
6768 if (symsecp
!= NULL
)
6770 asection
*symsec
= NULL
;
6771 if (h
->root
.type
== bfd_link_hash_defined
6772 || h
->root
.type
== bfd_link_hash_defweak
)
6773 symsec
= h
->root
.u
.def
.section
;
6777 if (tls_maskp
!= NULL
)
6778 *tls_maskp
= &ppc_elf_hash_entry (h
)->tls_mask
;
6782 Elf_Internal_Sym
*sym
;
6783 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6785 if (locsyms
== NULL
)
6787 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6788 if (locsyms
== NULL
)
6789 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6790 symtab_hdr
->sh_info
,
6791 0, NULL
, NULL
, NULL
);
6792 if (locsyms
== NULL
)
6794 *locsymsp
= locsyms
;
6796 sym
= locsyms
+ r_symndx
;
6804 if (symsecp
!= NULL
)
6805 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6807 if (tls_maskp
!= NULL
)
6809 struct got_entry
**lgot_ents
;
6810 unsigned char *tls_mask
;
6813 lgot_ents
= elf_local_got_ents (ibfd
);
6814 if (lgot_ents
!= NULL
)
6816 struct plt_entry
**local_plt
= (struct plt_entry
**)
6817 (lgot_ents
+ symtab_hdr
->sh_info
);
6818 unsigned char *lgot_masks
= (unsigned char *)
6819 (local_plt
+ symtab_hdr
->sh_info
);
6820 tls_mask
= &lgot_masks
[r_symndx
];
6822 *tls_maskp
= tls_mask
;
6828 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6829 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6830 type suitable for optimization, and 1 otherwise. */
6833 get_tls_mask (unsigned char **tls_maskp
,
6834 unsigned long *toc_symndx
,
6835 bfd_vma
*toc_addend
,
6836 Elf_Internal_Sym
**locsymsp
,
6837 const Elf_Internal_Rela
*rel
,
6840 unsigned long r_symndx
;
6842 struct elf_link_hash_entry
*h
;
6843 Elf_Internal_Sym
*sym
;
6847 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6848 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6851 if ((*tls_maskp
!= NULL
6852 && (**tls_maskp
& TLS_TLS
) != 0
6853 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
6855 || ppc64_elf_section_data (sec
) == NULL
6856 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6859 /* Look inside a TOC section too. */
6862 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6863 off
= h
->root
.u
.def
.value
;
6866 off
= sym
->st_value
;
6867 off
+= rel
->r_addend
;
6868 BFD_ASSERT (off
% 8 == 0);
6869 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6870 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6871 if (toc_symndx
!= NULL
)
6872 *toc_symndx
= r_symndx
;
6873 if (toc_addend
!= NULL
)
6874 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6875 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6877 if ((h
== NULL
|| is_static_defined (h
))
6878 && (next_r
== -1 || next_r
== -2))
6883 /* Find (or create) an entry in the tocsave hash table. */
6885 static struct tocsave_entry
*
6886 tocsave_find (struct ppc_link_hash_table
*htab
,
6887 enum insert_option insert
,
6888 Elf_Internal_Sym
**local_syms
,
6889 const Elf_Internal_Rela
*irela
,
6892 unsigned long r_indx
;
6893 struct elf_link_hash_entry
*h
;
6894 Elf_Internal_Sym
*sym
;
6895 struct tocsave_entry ent
, *p
;
6897 struct tocsave_entry
**slot
;
6899 r_indx
= ELF64_R_SYM (irela
->r_info
);
6900 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
6902 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
6905 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
6910 ent
.offset
= h
->root
.u
.def
.value
;
6912 ent
.offset
= sym
->st_value
;
6913 ent
.offset
+= irela
->r_addend
;
6915 hash
= tocsave_htab_hash (&ent
);
6916 slot
= ((struct tocsave_entry
**)
6917 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
6923 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
6932 /* Adjust all global syms defined in opd sections. In gcc generated
6933 code for the old ABI, these will already have been done. */
6936 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6938 struct ppc_link_hash_entry
*eh
;
6940 struct _opd_sec_data
*opd
;
6942 if (h
->root
.type
== bfd_link_hash_indirect
)
6945 if (h
->root
.type
!= bfd_link_hash_defined
6946 && h
->root
.type
!= bfd_link_hash_defweak
)
6949 eh
= ppc_elf_hash_entry (h
);
6950 if (eh
->adjust_done
)
6953 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6954 opd
= get_opd_info (sym_sec
);
6955 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6957 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
6960 /* This entry has been deleted. */
6961 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6964 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6965 if (discarded_section (dsec
))
6967 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6971 eh
->elf
.root
.u
.def
.value
= 0;
6972 eh
->elf
.root
.u
.def
.section
= dsec
;
6975 eh
->elf
.root
.u
.def
.value
+= adjust
;
6976 eh
->adjust_done
= 1;
6981 /* Handles decrementing dynamic reloc counts for the reloc specified by
6982 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
6983 have already been determined. */
6986 dec_dynrel_count (bfd_vma r_info
,
6988 struct bfd_link_info
*info
,
6989 Elf_Internal_Sym
**local_syms
,
6990 struct elf_link_hash_entry
*h
,
6991 Elf_Internal_Sym
*sym
)
6993 enum elf_ppc64_reloc_type r_type
;
6994 asection
*sym_sec
= NULL
;
6996 /* Can this reloc be dynamic? This switch, and later tests here
6997 should be kept in sync with the code in check_relocs. */
6998 r_type
= ELF64_R_TYPE (r_info
);
7005 case R_PPC64_TOC16_DS
:
7006 case R_PPC64_TOC16_LO
:
7007 case R_PPC64_TOC16_HI
:
7008 case R_PPC64_TOC16_HA
:
7009 case R_PPC64_TOC16_LO_DS
:
7014 case R_PPC64_TPREL16
:
7015 case R_PPC64_TPREL16_LO
:
7016 case R_PPC64_TPREL16_HI
:
7017 case R_PPC64_TPREL16_HA
:
7018 case R_PPC64_TPREL16_DS
:
7019 case R_PPC64_TPREL16_LO_DS
:
7020 case R_PPC64_TPREL16_HIGH
:
7021 case R_PPC64_TPREL16_HIGHA
:
7022 case R_PPC64_TPREL16_HIGHER
:
7023 case R_PPC64_TPREL16_HIGHERA
:
7024 case R_PPC64_TPREL16_HIGHEST
:
7025 case R_PPC64_TPREL16_HIGHESTA
:
7026 case R_PPC64_TPREL64
:
7027 case R_PPC64_TPREL34
:
7028 case R_PPC64_DTPMOD64
:
7029 case R_PPC64_DTPREL64
:
7030 case R_PPC64_ADDR64
:
7034 case R_PPC64_ADDR14
:
7035 case R_PPC64_ADDR14_BRNTAKEN
:
7036 case R_PPC64_ADDR14_BRTAKEN
:
7037 case R_PPC64_ADDR16
:
7038 case R_PPC64_ADDR16_DS
:
7039 case R_PPC64_ADDR16_HA
:
7040 case R_PPC64_ADDR16_HI
:
7041 case R_PPC64_ADDR16_HIGH
:
7042 case R_PPC64_ADDR16_HIGHA
:
7043 case R_PPC64_ADDR16_HIGHER
:
7044 case R_PPC64_ADDR16_HIGHERA
:
7045 case R_PPC64_ADDR16_HIGHEST
:
7046 case R_PPC64_ADDR16_HIGHESTA
:
7047 case R_PPC64_ADDR16_LO
:
7048 case R_PPC64_ADDR16_LO_DS
:
7049 case R_PPC64_ADDR24
:
7050 case R_PPC64_ADDR32
:
7051 case R_PPC64_UADDR16
:
7052 case R_PPC64_UADDR32
:
7053 case R_PPC64_UADDR64
:
7056 case R_PPC64_D34_LO
:
7057 case R_PPC64_D34_HI30
:
7058 case R_PPC64_D34_HA30
:
7059 case R_PPC64_ADDR16_HIGHER34
:
7060 case R_PPC64_ADDR16_HIGHERA34
:
7061 case R_PPC64_ADDR16_HIGHEST34
:
7062 case R_PPC64_ADDR16_HIGHESTA34
:
7067 if (local_syms
!= NULL
)
7069 unsigned long r_symndx
;
7070 bfd
*ibfd
= sec
->owner
;
7072 r_symndx
= ELF64_R_SYM (r_info
);
7073 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7078 && (h
->root
.type
== bfd_link_hash_defweak
7079 || !h
->def_regular
))
7081 && !bfd_link_executable (info
)
7082 && !SYMBOLIC_BIND (info
, h
))
7083 || (bfd_link_pic (info
)
7084 && must_be_dyn_reloc (info
, r_type
))
7085 || (!bfd_link_pic (info
)
7087 ? h
->type
== STT_GNU_IFUNC
7088 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
7095 struct elf_dyn_relocs
*p
;
7096 struct elf_dyn_relocs
**pp
;
7097 pp
= &h
->dyn_relocs
;
7099 /* elf_gc_sweep may have already removed all dyn relocs associated
7100 with local syms for a given section. Also, symbol flags are
7101 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7102 report a dynreloc miscount. */
7103 if (*pp
== NULL
&& info
->gc_sections
)
7106 while ((p
= *pp
) != NULL
)
7110 if (!must_be_dyn_reloc (info
, r_type
))
7122 struct ppc_dyn_relocs
*p
;
7123 struct ppc_dyn_relocs
**pp
;
7127 if (local_syms
== NULL
)
7128 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7129 if (sym_sec
== NULL
)
7132 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7133 pp
= (struct ppc_dyn_relocs
**) vpp
;
7135 if (*pp
== NULL
&& info
->gc_sections
)
7138 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7139 while ((p
= *pp
) != NULL
)
7141 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7152 /* xgettext:c-format */
7153 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7155 bfd_set_error (bfd_error_bad_value
);
7159 /* Remove unused Official Procedure Descriptor entries. Currently we
7160 only remove those associated with functions in discarded link-once
7161 sections, or weakly defined functions that have been overridden. It
7162 would be possible to remove many more entries for statically linked
7166 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7169 bool some_edited
= false;
7170 asection
*need_pad
= NULL
;
7171 struct ppc_link_hash_table
*htab
;
7173 htab
= ppc_hash_table (info
);
7177 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7180 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7181 Elf_Internal_Shdr
*symtab_hdr
;
7182 Elf_Internal_Sym
*local_syms
;
7183 struct _opd_sec_data
*opd
;
7184 bool need_edit
, add_aux_fields
, broken
;
7185 bfd_size_type cnt_16b
= 0;
7187 if (!is_ppc64_elf (ibfd
))
7190 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7191 if (sec
== NULL
|| sec
->size
== 0)
7194 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7197 if (sec
->output_section
== bfd_abs_section_ptr
)
7200 /* Look through the section relocs. */
7201 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7205 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7207 /* Read the relocations. */
7208 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7210 if (relstart
== NULL
)
7213 /* First run through the relocs to check they are sane, and to
7214 determine whether we need to edit this opd section. */
7218 relend
= relstart
+ sec
->reloc_count
;
7219 for (rel
= relstart
; rel
< relend
; )
7221 enum elf_ppc64_reloc_type r_type
;
7222 unsigned long r_symndx
;
7224 struct elf_link_hash_entry
*h
;
7225 Elf_Internal_Sym
*sym
;
7228 /* .opd contains an array of 16 or 24 byte entries. We're
7229 only interested in the reloc pointing to a function entry
7231 offset
= rel
->r_offset
;
7232 if (rel
+ 1 == relend
7233 || rel
[1].r_offset
!= offset
+ 8)
7235 /* If someone messes with .opd alignment then after a
7236 "ld -r" we might have padding in the middle of .opd.
7237 Also, there's nothing to prevent someone putting
7238 something silly in .opd with the assembler. No .opd
7239 optimization for them! */
7242 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7247 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7248 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7251 /* xgettext:c-format */
7252 (_("%pB: unexpected reloc type %u in .opd section"),
7258 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7259 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7263 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7265 const char *sym_name
;
7267 sym_name
= h
->root
.root
.string
;
7269 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7273 /* xgettext:c-format */
7274 (_("%pB: undefined sym `%s' in .opd section"),
7280 /* opd entries are always for functions defined in the
7281 current input bfd. If the symbol isn't defined in the
7282 input bfd, then we won't be using the function in this
7283 bfd; It must be defined in a linkonce section in another
7284 bfd, or is weak. It's also possible that we are
7285 discarding the function due to a linker script /DISCARD/,
7286 which we test for via the output_section. */
7287 if (sym_sec
->owner
!= ibfd
7288 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7292 if (rel
+ 1 == relend
7293 || (rel
+ 2 < relend
7294 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7299 if (sec
->size
== offset
+ 24)
7304 if (sec
->size
== offset
+ 16)
7311 else if (rel
+ 1 < relend
7312 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7313 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7315 if (rel
[0].r_offset
== offset
+ 16)
7317 else if (rel
[0].r_offset
!= offset
+ 24)
7324 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7326 if (!broken
&& (need_edit
|| add_aux_fields
))
7328 Elf_Internal_Rela
*write_rel
;
7329 Elf_Internal_Shdr
*rel_hdr
;
7330 bfd_byte
*rptr
, *wptr
;
7331 bfd_byte
*new_contents
;
7334 new_contents
= NULL
;
7335 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7336 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7337 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7338 if (opd
->adjust
== NULL
)
7341 /* This seems a waste of time as input .opd sections are all
7342 zeros as generated by gcc, but I suppose there's no reason
7343 this will always be so. We might start putting something in
7344 the third word of .opd entries. */
7345 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7348 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7352 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7354 if (elf_section_data (sec
)->relocs
!= relstart
)
7358 sec
->contents
= loc
;
7359 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7362 elf_section_data (sec
)->relocs
= relstart
;
7364 new_contents
= sec
->contents
;
7367 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7368 if (new_contents
== NULL
)
7372 wptr
= new_contents
;
7373 rptr
= sec
->contents
;
7374 write_rel
= relstart
;
7375 for (rel
= relstart
; rel
< relend
; )
7377 unsigned long r_symndx
;
7379 struct elf_link_hash_entry
*h
;
7380 struct ppc_link_hash_entry
*fdh
= NULL
;
7381 Elf_Internal_Sym
*sym
;
7383 Elf_Internal_Rela
*next_rel
;
7386 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7387 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7392 if (next_rel
+ 1 == relend
7393 || (next_rel
+ 2 < relend
7394 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7397 /* See if the .opd entry is full 24 byte or
7398 16 byte (with fd_aux entry overlapped with next
7401 if (next_rel
== relend
)
7403 if (sec
->size
== rel
->r_offset
+ 16)
7406 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7410 && h
->root
.root
.string
[0] == '.')
7412 fdh
= ppc_elf_hash_entry (h
)->oh
;
7415 fdh
= ppc_follow_link (fdh
);
7416 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
7417 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7422 skip
= (sym_sec
->owner
!= ibfd
7423 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7426 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7428 /* Arrange for the function descriptor sym
7430 fdh
->elf
.root
.u
.def
.value
= 0;
7431 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7433 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7435 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7440 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7444 if (++rel
== next_rel
)
7447 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7448 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7455 /* We'll be keeping this opd entry. */
7460 /* Redefine the function descriptor symbol to
7461 this location in the opd section. It is
7462 necessary to update the value here rather
7463 than using an array of adjustments as we do
7464 for local symbols, because various places
7465 in the generic ELF code use the value
7466 stored in u.def.value. */
7467 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7468 fdh
->adjust_done
= 1;
7471 /* Local syms are a bit tricky. We could
7472 tweak them as they can be cached, but
7473 we'd need to look through the local syms
7474 for the function descriptor sym which we
7475 don't have at the moment. So keep an
7476 array of adjustments. */
7477 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
7478 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
7481 memcpy (wptr
, rptr
, opd_ent_size
);
7482 wptr
+= opd_ent_size
;
7483 if (add_aux_fields
&& opd_ent_size
== 16)
7485 memset (wptr
, '\0', 8);
7489 /* We need to adjust any reloc offsets to point to the
7491 for ( ; rel
!= next_rel
; ++rel
)
7493 rel
->r_offset
+= adjust
;
7494 if (write_rel
!= rel
)
7495 memcpy (write_rel
, rel
, sizeof (*rel
));
7500 rptr
+= opd_ent_size
;
7503 sec
->size
= wptr
- new_contents
;
7504 sec
->reloc_count
= write_rel
- relstart
;
7507 free (sec
->contents
);
7508 sec
->contents
= new_contents
;
7511 /* Fudge the header size too, as this is used later in
7512 elf_bfd_final_link if we are emitting relocs. */
7513 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7514 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7517 else if (elf_section_data (sec
)->relocs
!= relstart
)
7520 if (local_syms
!= NULL
7521 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7523 if (!info
->keep_memory
)
7526 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7531 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7533 /* If we are doing a final link and the last .opd entry is just 16 byte
7534 long, add a 8 byte padding after it. */
7535 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7539 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7541 BFD_ASSERT (need_pad
->size
> 0);
7543 p
= bfd_malloc (need_pad
->size
+ 8);
7547 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7548 p
, 0, need_pad
->size
))
7551 need_pad
->contents
= p
;
7552 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7556 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7560 need_pad
->contents
= p
;
7563 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7564 need_pad
->size
+= 8;
7570 /* Analyze inline PLT call relocations to see whether calls to locally
7571 defined functions can be converted to direct calls. */
7574 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7576 struct ppc_link_hash_table
*htab
;
7579 bfd_vma low_vma
, high_vma
, limit
;
7581 htab
= ppc_hash_table (info
);
7585 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7586 reduced somewhat to cater for possible stubs that might be added
7587 between the call and its destination. */
7588 if (htab
->params
->group_size
< 0)
7590 limit
= -htab
->params
->group_size
;
7596 limit
= htab
->params
->group_size
;
7603 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7604 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7606 if (low_vma
> sec
->vma
)
7608 if (high_vma
< sec
->vma
+ sec
->size
)
7609 high_vma
= sec
->vma
+ sec
->size
;
7612 /* If a "bl" can reach anywhere in local code sections, then we can
7613 convert all inline PLT sequences to direct calls when the symbol
7615 if (high_vma
- low_vma
< limit
)
7617 htab
->can_convert_all_inline_plt
= 1;
7621 /* Otherwise, go looking through relocs for cases where a direct
7622 call won't reach. Mark the symbol on any such reloc to disable
7623 the optimization and keep the PLT entry as it seems likely that
7624 this will be better than creating trampolines. Note that this
7625 will disable the optimization for all inline PLT calls to a
7626 particular symbol, not just those that won't reach. The
7627 difficulty in doing a more precise optimization is that the
7628 linker needs to make a decision depending on whether a
7629 particular R_PPC64_PLTCALL insn can be turned into a direct
7630 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7631 the sequence, and there is nothing that ties those relocs
7632 together except their symbol. */
7634 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7636 Elf_Internal_Shdr
*symtab_hdr
;
7637 Elf_Internal_Sym
*local_syms
;
7639 if (!is_ppc64_elf (ibfd
))
7643 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7645 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7646 if (ppc64_elf_section_data (sec
)->has_pltcall
7647 && !bfd_is_abs_section (sec
->output_section
))
7649 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7651 /* Read the relocations. */
7652 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7654 if (relstart
== NULL
)
7657 relend
= relstart
+ sec
->reloc_count
;
7658 for (rel
= relstart
; rel
< relend
; rel
++)
7660 enum elf_ppc64_reloc_type r_type
;
7661 unsigned long r_symndx
;
7663 struct elf_link_hash_entry
*h
;
7664 Elf_Internal_Sym
*sym
;
7665 unsigned char *tls_maskp
;
7667 r_type
= ELF64_R_TYPE (rel
->r_info
);
7668 if (r_type
!= R_PPC64_PLTCALL
7669 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
7672 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7673 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7676 if (elf_section_data (sec
)->relocs
!= relstart
)
7678 if (symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7683 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7687 to
= h
->root
.u
.def
.value
;
7690 to
+= (rel
->r_addend
7691 + sym_sec
->output_offset
7692 + sym_sec
->output_section
->vma
);
7693 from
= (rel
->r_offset
7694 + sec
->output_offset
7695 + sec
->output_section
->vma
);
7696 if (to
- from
+ limit
< 2 * limit
7697 && !(r_type
== R_PPC64_PLTCALL_NOTOC
7698 && (((h
? h
->other
: sym
->st_other
)
7699 & STO_PPC64_LOCAL_MASK
)
7700 > 1 << STO_PPC64_LOCAL_BIT
)))
7701 *tls_maskp
&= ~PLT_KEEP
;
7704 if (elf_section_data (sec
)->relocs
!= relstart
)
7708 if (local_syms
!= NULL
7709 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7711 if (!info
->keep_memory
)
7714 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7721 /* Set htab->tls_get_addr and various other info specific to TLS.
7722 This needs to run before dynamic symbols are processed in
7723 bfd_elf_size_dynamic_sections. */
7726 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7728 struct ppc_link_hash_table
*htab
;
7729 struct elf_link_hash_entry
*tga
, *tga_fd
, *desc
, *desc_fd
;
7731 htab
= ppc_hash_table (info
);
7735 if (abiversion (info
->output_bfd
) == 1)
7738 if (htab
->params
->no_multi_toc
)
7739 htab
->do_multi_toc
= 0;
7740 else if (!htab
->do_multi_toc
)
7741 htab
->params
->no_multi_toc
= 1;
7743 /* Default to --no-plt-localentry, as this option can cause problems
7744 with symbol interposition. For example, glibc libpthread.so and
7745 libc.so duplicate many pthread symbols, with a fallback
7746 implementation in libc.so. In some cases the fallback does more
7747 work than the pthread implementation. __pthread_condattr_destroy
7748 is one such symbol: the libpthread.so implementation is
7749 localentry:0 while the libc.so implementation is localentry:8.
7750 An app that "cleverly" uses dlopen to only load necessary
7751 libraries at runtime may omit loading libpthread.so when not
7752 running multi-threaded, which then results in the libc.so
7753 fallback symbols being used and ld.so complaining. Now there
7754 are workarounds in ld (see non_zero_localentry) to detect the
7755 pthread situation, but that may not be the only case where
7756 --plt-localentry can cause trouble. */
7757 if (htab
->params
->plt_localentry0
< 0)
7758 htab
->params
->plt_localentry0
= 0;
7759 if (htab
->params
->plt_localentry0
&& htab
->has_power10_relocs
)
7761 /* The issue is that __glink_PLTresolve saves r2, which is done
7762 because glibc ld.so _dl_runtime_resolve restores r2 to support
7763 a glibc plt call optimisation where global entry code is
7764 skipped on calls that resolve to the same binary. The
7765 __glink_PLTresolve save of r2 is incompatible with code
7766 making tail calls, because the tail call might go via the
7767 resolver and thus overwrite the proper saved r2. */
7768 _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
7769 "power10 pc-relative code"));
7770 htab
->params
->plt_localentry0
= 0;
7772 if (htab
->params
->plt_localentry0
7773 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7774 false, false, false) == NULL
)
7776 (_("warning: --plt-localentry is especially dangerous without "
7777 "ld.so support to detect ABI violations"));
7779 tga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7780 false, false, true);
7781 htab
->tls_get_addr
= ppc_elf_hash_entry (tga
);
7783 /* Move dynamic linking info to the function descriptor sym. */
7785 func_desc_adjust (tga
, info
);
7786 tga_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7787 false, false, true);
7788 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (tga_fd
);
7790 desc
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_desc",
7791 false, false, true);
7792 htab
->tga_desc
= ppc_elf_hash_entry (desc
);
7794 func_desc_adjust (desc
, info
);
7795 desc_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_desc",
7796 false, false, true);
7797 htab
->tga_desc_fd
= ppc_elf_hash_entry (desc_fd
);
7799 if (htab
->params
->tls_get_addr_opt
)
7801 struct elf_link_hash_entry
*opt
, *opt_fd
;
7803 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7804 false, false, true);
7806 func_desc_adjust (opt
, info
);
7807 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7808 false, false, true);
7810 && (opt_fd
->root
.type
== bfd_link_hash_defined
7811 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7813 /* If glibc supports an optimized __tls_get_addr call stub,
7814 signalled by the presence of __tls_get_addr_opt, and we'll
7815 be calling __tls_get_addr via a plt call stub, then
7816 make __tls_get_addr point to __tls_get_addr_opt. */
7817 if (!(htab
->elf
.dynamic_sections_created
7819 && (tga_fd
->type
== STT_FUNC
7820 || tga_fd
->needs_plt
)
7821 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7822 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
))))
7824 if (!(htab
->elf
.dynamic_sections_created
7826 && (desc_fd
->type
== STT_FUNC
7827 || desc_fd
->needs_plt
)
7828 && !(SYMBOL_CALLS_LOCAL (info
, desc_fd
)
7829 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, desc_fd
))))
7832 if (tga_fd
!= NULL
|| desc_fd
!= NULL
)
7834 struct plt_entry
*ent
= NULL
;
7837 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7838 if (ent
->plt
.refcount
> 0)
7840 if (ent
== NULL
&& desc_fd
!= NULL
)
7841 for (ent
= desc_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7842 if (ent
->plt
.refcount
> 0)
7848 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7849 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7850 tga_fd
->root
.u
.i
.warning
= NULL
;
7851 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7853 if (desc_fd
!= NULL
)
7855 desc_fd
->root
.type
= bfd_link_hash_indirect
;
7856 desc_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7857 desc_fd
->root
.u
.i
.warning
= NULL
;
7858 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, desc_fd
);
7861 if (opt_fd
->dynindx
!= -1)
7863 /* Use __tls_get_addr_opt in dynamic relocations. */
7864 opt_fd
->dynindx
= -1;
7865 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7866 opt_fd
->dynstr_index
);
7867 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7872 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (opt_fd
);
7873 tga
= elf_hash_entry (htab
->tls_get_addr
);
7874 if (opt
!= NULL
&& tga
!= NULL
)
7876 tga
->root
.type
= bfd_link_hash_indirect
;
7877 tga
->root
.u
.i
.link
= &opt
->root
;
7878 tga
->root
.u
.i
.warning
= NULL
;
7879 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7881 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7883 htab
->tls_get_addr
= ppc_elf_hash_entry (opt
);
7885 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7886 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7887 if (htab
->tls_get_addr
!= NULL
)
7889 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7890 htab
->tls_get_addr
->is_func
= 1;
7893 if (desc_fd
!= NULL
)
7895 htab
->tga_desc_fd
= ppc_elf_hash_entry (opt_fd
);
7896 if (opt
!= NULL
&& desc
!= NULL
)
7898 desc
->root
.type
= bfd_link_hash_indirect
;
7899 desc
->root
.u
.i
.link
= &opt
->root
;
7900 desc
->root
.u
.i
.warning
= NULL
;
7901 ppc64_elf_copy_indirect_symbol (info
, opt
, desc
);
7903 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7904 desc
->forced_local
);
7905 htab
->tga_desc
= ppc_elf_hash_entry (opt
);
7907 htab
->tga_desc_fd
->oh
= htab
->tga_desc
;
7908 htab
->tga_desc_fd
->is_func_descriptor
= 1;
7909 if (htab
->tga_desc
!= NULL
)
7911 htab
->tga_desc
->oh
= htab
->tga_desc_fd
;
7912 htab
->tga_desc
->is_func
= 1;
7918 else if (htab
->params
->tls_get_addr_opt
< 0)
7919 htab
->params
->tls_get_addr_opt
= 0;
7922 if (htab
->tga_desc_fd
!= NULL
7923 && htab
->params
->tls_get_addr_opt
7924 && htab
->params
->no_tls_get_addr_regsave
== -1)
7925 htab
->params
->no_tls_get_addr_regsave
= 0;
7930 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7931 any of HASH1, HASH2, HASH3, or HASH4. */
7934 branch_reloc_hash_match (bfd
*ibfd
,
7935 Elf_Internal_Rela
*rel
,
7936 struct ppc_link_hash_entry
*hash1
,
7937 struct ppc_link_hash_entry
*hash2
,
7938 struct ppc_link_hash_entry
*hash3
,
7939 struct ppc_link_hash_entry
*hash4
)
7941 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7942 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7943 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7945 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7947 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7948 struct elf_link_hash_entry
*h
;
7950 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7951 h
= elf_follow_link (h
);
7952 if (h
== elf_hash_entry (hash1
)
7953 || h
== elf_hash_entry (hash2
)
7954 || h
== elf_hash_entry (hash3
)
7955 || h
== elf_hash_entry (hash4
))
7961 /* Run through all the TLS relocs looking for optimization
7962 opportunities. The linker has been hacked (see ppc64elf.em) to do
7963 a preliminary section layout so that we know the TLS segment
7964 offsets. We can't optimize earlier because some optimizations need
7965 to know the tp offset, and we need to optimize before allocating
7966 dynamic relocations. */
7969 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7973 struct ppc_link_hash_table
*htab
;
7974 unsigned char *toc_ref
;
7977 if (!bfd_link_executable (info
))
7980 htab
= ppc_hash_table (info
);
7984 htab
->do_tls_opt
= 1;
7986 /* Make two passes over the relocs. On the first pass, mark toc
7987 entries involved with tls relocs, and check that tls relocs
7988 involved in setting up a tls_get_addr call are indeed followed by
7989 such a call. If they are not, we can't do any tls optimization.
7990 On the second pass twiddle tls_mask flags to notify
7991 relocate_section that optimization can be done, and adjust got
7992 and plt refcounts. */
7994 for (pass
= 0; pass
< 2; ++pass
)
7995 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7997 Elf_Internal_Sym
*locsyms
= NULL
;
7998 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8000 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8001 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8003 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8004 bool found_tls_get_addr_arg
= 0;
8006 /* Read the relocations. */
8007 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8009 if (relstart
== NULL
)
8015 relend
= relstart
+ sec
->reloc_count
;
8016 for (rel
= relstart
; rel
< relend
; rel
++)
8018 enum elf_ppc64_reloc_type r_type
;
8019 unsigned long r_symndx
;
8020 struct elf_link_hash_entry
*h
;
8021 Elf_Internal_Sym
*sym
;
8023 unsigned char *tls_mask
;
8024 unsigned int tls_set
, tls_clear
, tls_type
= 0;
8026 bool ok_tprel
, is_local
;
8027 long toc_ref_index
= 0;
8028 int expecting_tls_get_addr
= 0;
8031 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8032 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8036 if (elf_section_data (sec
)->relocs
!= relstart
)
8039 if (elf_symtab_hdr (ibfd
).contents
8040 != (unsigned char *) locsyms
)
8047 if (h
->root
.type
== bfd_link_hash_defined
8048 || h
->root
.type
== bfd_link_hash_defweak
)
8049 value
= h
->root
.u
.def
.value
;
8050 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8054 found_tls_get_addr_arg
= 0;
8059 /* Symbols referenced by TLS relocs must be of type
8060 STT_TLS. So no need for .opd local sym adjust. */
8061 value
= sym
->st_value
;
8064 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
8068 && h
->root
.type
== bfd_link_hash_undefweak
)
8070 else if (sym_sec
!= NULL
8071 && sym_sec
->output_section
!= NULL
)
8073 value
+= sym_sec
->output_offset
;
8074 value
+= sym_sec
->output_section
->vma
;
8075 value
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8076 /* Note that even though the prefix insns
8077 allow a 1<<33 offset we use the same test
8078 as for addis;addi. There may be a mix of
8079 pcrel and non-pcrel code and the decision
8080 to optimise is per symbol, not per TLS
8082 ok_tprel
= value
+ 0x80008000ULL
< 1ULL << 32;
8086 r_type
= ELF64_R_TYPE (rel
->r_info
);
8087 /* If this section has old-style __tls_get_addr calls
8088 without marker relocs, then check that each
8089 __tls_get_addr call reloc is preceded by a reloc
8090 that conceivably belongs to the __tls_get_addr arg
8091 setup insn. If we don't find matching arg setup
8092 relocs, don't do any tls optimization. */
8094 && sec
->nomark_tls_get_addr
8096 && is_tls_get_addr (h
, htab
)
8097 && !found_tls_get_addr_arg
8098 && is_branch_reloc (r_type
))
8100 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8101 "TLS optimization disabled\n"),
8102 ibfd
, sec
, rel
->r_offset
);
8107 found_tls_get_addr_arg
= 0;
8110 case R_PPC64_GOT_TLSLD16
:
8111 case R_PPC64_GOT_TLSLD16_LO
:
8112 case R_PPC64_GOT_TLSLD_PCREL34
:
8113 expecting_tls_get_addr
= 1;
8114 found_tls_get_addr_arg
= 1;
8117 case R_PPC64_GOT_TLSLD16_HI
:
8118 case R_PPC64_GOT_TLSLD16_HA
:
8119 /* These relocs should never be against a symbol
8120 defined in a shared lib. Leave them alone if
8121 that turns out to be the case. */
8128 tls_type
= TLS_TLS
| TLS_LD
;
8131 case R_PPC64_GOT_TLSGD16
:
8132 case R_PPC64_GOT_TLSGD16_LO
:
8133 case R_PPC64_GOT_TLSGD_PCREL34
:
8134 expecting_tls_get_addr
= 1;
8135 found_tls_get_addr_arg
= 1;
8138 case R_PPC64_GOT_TLSGD16_HI
:
8139 case R_PPC64_GOT_TLSGD16_HA
:
8145 tls_set
= TLS_TLS
| TLS_GDIE
;
8147 tls_type
= TLS_TLS
| TLS_GD
;
8150 case R_PPC64_GOT_TPREL_PCREL34
:
8151 case R_PPC64_GOT_TPREL16_DS
:
8152 case R_PPC64_GOT_TPREL16_LO_DS
:
8153 case R_PPC64_GOT_TPREL16_HI
:
8154 case R_PPC64_GOT_TPREL16_HA
:
8159 tls_clear
= TLS_TPREL
;
8160 tls_type
= TLS_TLS
| TLS_TPREL
;
8170 if (rel
+ 1 < relend
8171 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8174 && (ELF64_R_TYPE (rel
[1].r_info
)
8176 && (ELF64_R_TYPE (rel
[1].r_info
)
8177 != R_PPC64_PLTSEQ_NOTOC
))
8179 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8180 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8185 struct plt_entry
*ent
= NULL
;
8187 for (ent
= h
->plt
.plist
;
8190 if (ent
->addend
== rel
[1].r_addend
)
8194 && ent
->plt
.refcount
> 0)
8195 ent
->plt
.refcount
-= 1;
8200 found_tls_get_addr_arg
= 1;
8205 case R_PPC64_TOC16_LO
:
8206 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8209 /* Mark this toc entry as referenced by a TLS
8210 code sequence. We can do that now in the
8211 case of R_PPC64_TLS, and after checking for
8212 tls_get_addr for the TOC16 relocs. */
8213 if (toc_ref
== NULL
)
8215 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8216 if (toc_ref
== NULL
)
8220 value
= h
->root
.u
.def
.value
;
8222 value
= sym
->st_value
;
8223 value
+= rel
->r_addend
;
8226 BFD_ASSERT (value
< toc
->size
8227 && toc
->output_offset
% 8 == 0);
8228 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8229 if (r_type
== R_PPC64_TLS
8230 || r_type
== R_PPC64_TLSGD
8231 || r_type
== R_PPC64_TLSLD
)
8233 toc_ref
[toc_ref_index
] = 1;
8237 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8242 expecting_tls_get_addr
= 2;
8245 case R_PPC64_TPREL64
:
8249 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8254 tls_set
= TLS_EXPLICIT
;
8255 tls_clear
= TLS_TPREL
;
8260 case R_PPC64_DTPMOD64
:
8264 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8266 if (rel
+ 1 < relend
8268 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8269 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8273 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8276 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_GDIE
;
8285 tls_set
= TLS_EXPLICIT
;
8290 case R_PPC64_TPREL16_HA
:
8293 unsigned char buf
[4];
8295 bfd_vma off
= rel
->r_offset
& ~3;
8296 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8299 insn
= bfd_get_32 (ibfd
, buf
);
8300 /* addis rt,13,imm */
8301 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8302 != ((15u << 26) | (13 << 16)))
8304 /* xgettext:c-format */
8305 info
->callbacks
->minfo
8306 (_("%H: warning: %s unexpected insn %#x.\n"),
8307 ibfd
, sec
, off
, "R_PPC64_TPREL16_HA", insn
);
8308 htab
->do_tls_opt
= 0;
8313 case R_PPC64_TPREL16_HI
:
8314 case R_PPC64_TPREL16_HIGH
:
8315 case R_PPC64_TPREL16_HIGHA
:
8316 case R_PPC64_TPREL16_HIGHER
:
8317 case R_PPC64_TPREL16_HIGHERA
:
8318 case R_PPC64_TPREL16_HIGHEST
:
8319 case R_PPC64_TPREL16_HIGHESTA
:
8320 /* These can all be used in sequences along with
8321 TPREL16_LO or TPREL16_LO_DS in ways we aren't
8322 able to verify easily. */
8323 htab
->do_tls_opt
= 0;
8332 if (!expecting_tls_get_addr
8333 || !sec
->nomark_tls_get_addr
)
8336 if (rel
+ 1 < relend
8337 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8338 htab
->tls_get_addr_fd
,
8343 if (expecting_tls_get_addr
== 2)
8345 /* Check for toc tls entries. */
8346 unsigned char *toc_tls
;
8349 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8354 if (toc_tls
!= NULL
)
8356 if ((*toc_tls
& TLS_TLS
) != 0
8357 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8358 found_tls_get_addr_arg
= 1;
8360 toc_ref
[toc_ref_index
] = 1;
8366 /* Uh oh, we didn't find the expected call. We
8367 could just mark this symbol to exclude it
8368 from tls optimization but it's safer to skip
8369 the entire optimization. */
8370 /* xgettext:c-format */
8371 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8372 "TLS optimization disabled\n"),
8373 ibfd
, sec
, rel
->r_offset
);
8378 /* If we don't have old-style __tls_get_addr calls
8379 without TLSGD/TLSLD marker relocs, and we haven't
8380 found a new-style __tls_get_addr call with a
8381 marker for this symbol, then we either have a
8382 broken object file or an -mlongcall style
8383 indirect call to __tls_get_addr without a marker.
8384 Disable optimization in this case. */
8385 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8386 && (tls_set
& TLS_EXPLICIT
) == 0
8387 && !sec
->nomark_tls_get_addr
8388 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8389 != (TLS_TLS
| TLS_MARK
)))
8392 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
8394 struct plt_entry
*ent
= NULL
;
8396 if (htab
->tls_get_addr_fd
!= NULL
)
8397 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8400 if (ent
->addend
== 0)
8403 if (ent
== NULL
&& htab
->tga_desc_fd
!= NULL
)
8404 for (ent
= htab
->tga_desc_fd
->elf
.plt
.plist
;
8407 if (ent
->addend
== 0)
8410 if (ent
== NULL
&& htab
->tls_get_addr
!= NULL
)
8411 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8414 if (ent
->addend
== 0)
8417 if (ent
== NULL
&& htab
->tga_desc
!= NULL
)
8418 for (ent
= htab
->tga_desc
->elf
.plt
.plist
;
8421 if (ent
->addend
== 0)
8425 && ent
->plt
.refcount
> 0)
8426 ent
->plt
.refcount
-= 1;
8432 if ((tls_set
& TLS_EXPLICIT
) == 0)
8434 struct got_entry
*ent
;
8436 /* Adjust got entry for this reloc. */
8440 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8442 for (; ent
!= NULL
; ent
= ent
->next
)
8443 if (ent
->addend
== rel
->r_addend
8444 && ent
->owner
== ibfd
8445 && ent
->tls_type
== tls_type
)
8452 /* We managed to get rid of a got entry. */
8453 if (ent
->got
.refcount
> 0)
8454 ent
->got
.refcount
-= 1;
8459 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8460 we'll lose one or two dyn relocs. */
8461 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8465 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8467 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8473 *tls_mask
|= tls_set
& 0xff;
8474 *tls_mask
&= ~tls_clear
;
8477 if (elf_section_data (sec
)->relocs
!= relstart
)
8482 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8484 if (!info
->keep_memory
)
8487 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8495 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8496 the values of any global symbols in a toc section that has been
8497 edited. Globals in toc sections should be a rarity, so this function
8498 sets a flag if any are found in toc sections other than the one just
8499 edited, so that further hash table traversals can be avoided. */
8501 struct adjust_toc_info
8504 unsigned long *skip
;
8505 bool global_toc_syms
;
8508 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8511 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8513 struct ppc_link_hash_entry
*eh
;
8514 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8517 if (h
->root
.type
!= bfd_link_hash_defined
8518 && h
->root
.type
!= bfd_link_hash_defweak
)
8521 eh
= ppc_elf_hash_entry (h
);
8522 if (eh
->adjust_done
)
8525 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8527 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8528 i
= toc_inf
->toc
->rawsize
>> 3;
8530 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8532 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8535 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8538 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8539 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8542 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8543 eh
->adjust_done
= 1;
8545 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8546 toc_inf
->global_toc_syms
= true;
8551 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8552 on a _LO variety toc/got reloc. */
8555 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8557 return ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */
8558 || (insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
8559 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
8560 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
8561 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
8562 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
8563 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
8564 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
8565 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
8566 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
8567 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
8568 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
8569 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
8570 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
8571 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
8572 || (insn
& (0x3fu
<< 26)) == 56u << 26 /* lq,lfq */
8573 || ((insn
& (0x3fu
<< 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8574 /* Exclude lfqu by testing reloc. If relocs are ever
8575 defined for the reduced D field in psq_lu then those
8576 will need testing too. */
8577 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8578 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* ld,lwa */
8580 || (insn
& (0x3fu
<< 26)) == 60u << 26 /* stfq */
8581 || ((insn
& (0x3fu
<< 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8582 /* Exclude stfqu. psq_stu as above for psq_lu. */
8583 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8584 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std,stq */
8585 && (insn
& 1) == 0));
8588 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
8589 pld ra,symbol@got@pcrel
8590 load/store rt,off(ra)
8593 load/store rt,off(ra)
8594 may be translated to
8595 pload/pstore rt,symbol+off@pcrel
8597 This function returns true if the optimization is possible, placing
8598 the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
8600 On entry to this function, the linker has already determined that
8601 the pld can be replaced with pla: *PINSN1 is that pla insn,
8602 while *PINSN2 is the second instruction. */
8605 xlate_pcrel_opt (uint64_t *pinsn1
, uint64_t *pinsn2
, bfd_signed_vma
*poff
)
8607 uint64_t insn1
= *pinsn1
;
8608 uint64_t insn2
= *pinsn2
;
8611 if ((insn2
& (63ULL << 58)) == 1ULL << 58)
8613 /* Check that regs match. */
8614 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8617 /* P8LS or PMLS form, non-pcrel. */
8618 if ((insn2
& (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
8621 *pinsn1
= (insn2
& ~(31 << 16) & ~0x3ffff0000ffffULL
) | (1ULL << 52);
8623 off
= ((insn2
>> 16) & 0x3ffff0000ULL
) | (insn2
& 0xffff);
8624 *poff
= (off
^ 0x200000000ULL
) - 0x200000000ULL
;
8630 /* Check that regs match. */
8631 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8634 switch ((insn2
>> 26) & 63)
8650 /* These are the PMLS cases, where we just need to tack a prefix
8652 insn1
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
8653 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8654 off
= insn2
& 0xffff;
8657 case 58: /* lwa, ld */
8658 if ((insn2
& 1) != 0)
8660 insn1
= ((1ULL << 58) | (1ULL << 52)
8661 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
8662 | (insn2
& (31ULL << 21)));
8663 off
= insn2
& 0xfffc;
8666 case 57: /* lxsd, lxssp */
8667 if ((insn2
& 3) < 2)
8669 insn1
= ((1ULL << 58) | (1ULL << 52)
8670 | ((40ULL | (insn2
& 3)) << 26)
8671 | (insn2
& (31ULL << 21)));
8672 off
= insn2
& 0xfffc;
8675 case 61: /* stxsd, stxssp, lxv, stxv */
8676 if ((insn2
& 3) == 0)
8678 else if ((insn2
& 3) >= 2)
8680 insn1
= ((1ULL << 58) | (1ULL << 52)
8681 | ((44ULL | (insn2
& 3)) << 26)
8682 | (insn2
& (31ULL << 21)));
8683 off
= insn2
& 0xfffc;
8687 insn1
= ((1ULL << 58) | (1ULL << 52)
8688 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
8689 | (insn2
& (31ULL << 21)));
8690 off
= insn2
& 0xfff0;
8695 insn1
= ((1ULL << 58) | (1ULL << 52)
8696 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8697 off
= insn2
& 0xffff;
8700 case 6: /* lxvp, stxvp */
8701 if ((insn2
& 0xe) != 0)
8703 insn1
= ((1ULL << 58) | (1ULL << 52)
8704 | ((insn2
& 1) == 0 ? 58ULL << 26 : 62ULL << 26)
8705 | (insn2
& (31ULL << 21)));
8706 off
= insn2
& 0xfff0;
8709 case 62: /* std, stq */
8710 if ((insn2
& 1) != 0)
8712 insn1
= ((1ULL << 58) | (1ULL << 52)
8713 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
8714 | (insn2
& (31ULL << 21)));
8715 off
= insn2
& 0xfffc;
8720 *pinsn2
= (uint64_t) NOP
<< 32;
8721 *poff
= (off
^ 0x8000) - 0x8000;
8725 /* Examine all relocs referencing .toc sections in order to remove
8726 unused .toc entries. */
8729 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8732 struct adjust_toc_info toc_inf
;
8733 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8735 htab
->do_toc_opt
= 1;
8736 toc_inf
.global_toc_syms
= true;
8737 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8739 asection
*toc
, *sec
;
8740 Elf_Internal_Shdr
*symtab_hdr
;
8741 Elf_Internal_Sym
*local_syms
;
8742 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8743 unsigned long *skip
, *drop
;
8744 unsigned char *used
;
8745 unsigned char *keep
, last
, some_unused
;
8747 if (!is_ppc64_elf (ibfd
))
8750 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8753 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8754 || discarded_section (toc
))
8759 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8761 /* Look at sections dropped from the final link. */
8764 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8766 if (sec
->reloc_count
== 0
8767 || !discarded_section (sec
)
8768 || get_opd_info (sec
)
8769 || (sec
->flags
& SEC_ALLOC
) == 0
8770 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8773 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, false);
8774 if (relstart
== NULL
)
8777 /* Run through the relocs to see which toc entries might be
8779 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8781 enum elf_ppc64_reloc_type r_type
;
8782 unsigned long r_symndx
;
8784 struct elf_link_hash_entry
*h
;
8785 Elf_Internal_Sym
*sym
;
8788 r_type
= ELF64_R_TYPE (rel
->r_info
);
8795 case R_PPC64_TOC16_LO
:
8796 case R_PPC64_TOC16_HI
:
8797 case R_PPC64_TOC16_HA
:
8798 case R_PPC64_TOC16_DS
:
8799 case R_PPC64_TOC16_LO_DS
:
8803 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8804 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8812 val
= h
->root
.u
.def
.value
;
8814 val
= sym
->st_value
;
8815 val
+= rel
->r_addend
;
8817 if (val
>= toc
->size
)
8820 /* Anything in the toc ought to be aligned to 8 bytes.
8821 If not, don't mark as unused. */
8827 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8832 skip
[val
>> 3] = ref_from_discarded
;
8835 if (elf_section_data (sec
)->relocs
!= relstart
)
8839 /* For largetoc loads of address constants, we can convert
8840 . addis rx,2,addr@got@ha
8841 . ld ry,addr@got@l(rx)
8843 . addis rx,2,addr@toc@ha
8844 . addi ry,rx,addr@toc@l
8845 when addr is within 2G of the toc pointer. This then means
8846 that the word storing "addr" in the toc is no longer needed. */
8848 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8849 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8850 && toc
->reloc_count
!= 0)
8852 /* Read toc relocs. */
8853 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8855 if (toc_relocs
== NULL
)
8858 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8860 enum elf_ppc64_reloc_type r_type
;
8861 unsigned long r_symndx
;
8863 struct elf_link_hash_entry
*h
;
8864 Elf_Internal_Sym
*sym
;
8867 r_type
= ELF64_R_TYPE (rel
->r_info
);
8868 if (r_type
!= R_PPC64_ADDR64
)
8871 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8872 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8877 || sym_sec
->output_section
== NULL
8878 || discarded_section (sym_sec
))
8881 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8886 if (h
->type
== STT_GNU_IFUNC
)
8888 val
= h
->root
.u
.def
.value
;
8892 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8894 val
= sym
->st_value
;
8896 val
+= rel
->r_addend
;
8897 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8899 /* We don't yet know the exact toc pointer value, but we
8900 know it will be somewhere in the toc section. Don't
8901 optimize if the difference from any possible toc
8902 pointer is outside [ff..f80008000, 7fff7fff]. */
8903 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8904 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8907 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8908 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8913 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8918 skip
[rel
->r_offset
>> 3]
8919 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8926 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8930 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8933 && elf_section_data (sec
)->relocs
!= relstart
)
8935 if (elf_section_data (toc
)->relocs
!= toc_relocs
)
8941 /* Now check all kept sections that might reference the toc.
8942 Check the toc itself last. */
8943 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8946 sec
= (sec
== toc
? NULL
8947 : sec
->next
== NULL
? toc
8948 : sec
->next
== toc
&& toc
->next
? toc
->next
8953 if (sec
->reloc_count
== 0
8954 || discarded_section (sec
)
8955 || get_opd_info (sec
)
8956 || (sec
->flags
& SEC_ALLOC
) == 0
8957 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8960 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8962 if (relstart
== NULL
)
8968 /* Mark toc entries referenced as used. */
8972 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8974 enum elf_ppc64_reloc_type r_type
;
8975 unsigned long r_symndx
;
8977 struct elf_link_hash_entry
*h
;
8978 Elf_Internal_Sym
*sym
;
8981 r_type
= ELF64_R_TYPE (rel
->r_info
);
8985 case R_PPC64_TOC16_LO
:
8986 case R_PPC64_TOC16_HI
:
8987 case R_PPC64_TOC16_HA
:
8988 case R_PPC64_TOC16_DS
:
8989 case R_PPC64_TOC16_LO_DS
:
8990 /* In case we're taking addresses of toc entries. */
8991 case R_PPC64_ADDR64
:
8998 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8999 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9010 val
= h
->root
.u
.def
.value
;
9012 val
= sym
->st_value
;
9013 val
+= rel
->r_addend
;
9015 if (val
>= toc
->size
)
9018 if ((skip
[val
>> 3] & can_optimize
) != 0)
9025 case R_PPC64_TOC16_HA
:
9028 case R_PPC64_TOC16_LO_DS
:
9029 off
= rel
->r_offset
;
9030 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9031 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9037 if ((opc
& (0x3f << 2)) == (58u << 2))
9042 /* Wrong sort of reloc, or not a ld. We may
9043 as well clear ref_from_discarded too. */
9050 /* For the toc section, we only mark as used if this
9051 entry itself isn't unused. */
9052 else if ((used
[rel
->r_offset
>> 3]
9053 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9056 /* Do all the relocs again, to catch reference
9065 if (elf_section_data (sec
)->relocs
!= relstart
)
9069 /* Merge the used and skip arrays. Assume that TOC
9070 doublewords not appearing as either used or unused belong
9071 to an entry more than one doubleword in size. */
9072 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9073 drop
< skip
+ (toc
->size
+ 7) / 8;
9078 *drop
&= ~ref_from_discarded
;
9079 if ((*drop
& can_optimize
) != 0)
9083 else if ((*drop
& ref_from_discarded
) != 0)
9086 last
= ref_from_discarded
;
9096 bfd_byte
*contents
, *src
;
9098 Elf_Internal_Sym
*sym
;
9099 bool local_toc_syms
= false;
9101 /* Shuffle the toc contents, and at the same time convert the
9102 skip array from booleans into offsets. */
9103 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9106 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9108 for (src
= contents
, off
= 0, drop
= skip
;
9109 src
< contents
+ toc
->size
;
9112 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9117 memcpy (src
- off
, src
, 8);
9121 toc
->rawsize
= toc
->size
;
9122 toc
->size
= src
- contents
- off
;
9124 /* Adjust addends for relocs against the toc section sym,
9125 and optimize any accesses we can. */
9126 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9128 if (sec
->reloc_count
== 0
9129 || discarded_section (sec
))
9132 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9134 if (relstart
== NULL
)
9137 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9139 enum elf_ppc64_reloc_type r_type
;
9140 unsigned long r_symndx
;
9142 struct elf_link_hash_entry
*h
;
9145 r_type
= ELF64_R_TYPE (rel
->r_info
);
9152 case R_PPC64_TOC16_LO
:
9153 case R_PPC64_TOC16_HI
:
9154 case R_PPC64_TOC16_HA
:
9155 case R_PPC64_TOC16_DS
:
9156 case R_PPC64_TOC16_LO_DS
:
9157 case R_PPC64_ADDR64
:
9161 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9162 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9170 val
= h
->root
.u
.def
.value
;
9173 val
= sym
->st_value
;
9175 local_toc_syms
= true;
9178 val
+= rel
->r_addend
;
9180 if (val
> toc
->rawsize
)
9182 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9184 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9186 Elf_Internal_Rela
*tocrel
9187 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9188 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9192 case R_PPC64_TOC16_HA
:
9193 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9196 case R_PPC64_TOC16_LO_DS
:
9197 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9201 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9203 info
->callbacks
->einfo
9204 /* xgettext:c-format */
9205 (_("%H: %s references "
9206 "optimized away TOC entry\n"),
9207 ibfd
, sec
, rel
->r_offset
,
9208 ppc64_elf_howto_table
[r_type
]->name
);
9209 bfd_set_error (bfd_error_bad_value
);
9212 rel
->r_addend
= tocrel
->r_addend
;
9213 elf_section_data (sec
)->relocs
= relstart
;
9217 if (h
!= NULL
|| sym
->st_value
!= 0)
9220 rel
->r_addend
-= skip
[val
>> 3];
9221 elf_section_data (sec
)->relocs
= relstart
;
9224 if (elf_section_data (sec
)->relocs
!= relstart
)
9228 /* We shouldn't have local or global symbols defined in the TOC,
9229 but handle them anyway. */
9230 if (local_syms
!= NULL
)
9231 for (sym
= local_syms
;
9232 sym
< local_syms
+ symtab_hdr
->sh_info
;
9234 if (sym
->st_value
!= 0
9235 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9239 if (sym
->st_value
> toc
->rawsize
)
9240 i
= toc
->rawsize
>> 3;
9242 i
= sym
->st_value
>> 3;
9244 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9248 (_("%s defined on removed toc entry"),
9249 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9252 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9253 sym
->st_value
= (bfd_vma
) i
<< 3;
9256 sym
->st_value
-= skip
[i
];
9257 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9260 /* Adjust any global syms defined in this toc input section. */
9261 if (toc_inf
.global_toc_syms
)
9264 toc_inf
.skip
= skip
;
9265 toc_inf
.global_toc_syms
= false;
9266 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9270 if (toc
->reloc_count
!= 0)
9272 Elf_Internal_Shdr
*rel_hdr
;
9273 Elf_Internal_Rela
*wrel
;
9276 /* Remove unused toc relocs, and adjust those we keep. */
9277 if (toc_relocs
== NULL
)
9278 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9280 if (toc_relocs
== NULL
)
9284 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9285 if ((skip
[rel
->r_offset
>> 3]
9286 & (ref_from_discarded
| can_optimize
)) == 0)
9288 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9289 wrel
->r_info
= rel
->r_info
;
9290 wrel
->r_addend
= rel
->r_addend
;
9293 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9294 &local_syms
, NULL
, NULL
))
9297 elf_section_data (toc
)->relocs
= toc_relocs
;
9298 toc
->reloc_count
= wrel
- toc_relocs
;
9299 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9300 sz
= rel_hdr
->sh_entsize
;
9301 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9304 else if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9307 if (local_syms
!= NULL
9308 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9310 if (!info
->keep_memory
)
9313 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9318 /* Look for cases where we can change an indirect GOT access to
9319 a GOT relative or PC relative access, possibly reducing the
9320 number of GOT entries. */
9321 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9324 Elf_Internal_Shdr
*symtab_hdr
;
9325 Elf_Internal_Sym
*local_syms
;
9326 Elf_Internal_Rela
*relstart
, *rel
;
9329 if (!is_ppc64_elf (ibfd
))
9332 if (!ppc64_elf_tdata (ibfd
)->has_optrel
)
9335 sec
= ppc64_elf_tdata (ibfd
)->got
;
9338 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
9341 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9343 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9345 if (sec
->reloc_count
== 0
9346 || !ppc64_elf_section_data (sec
)->has_optrel
9347 || discarded_section (sec
))
9350 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9352 if (relstart
== NULL
)
9355 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9358 && elf_section_data (sec
)->relocs
!= relstart
)
9363 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9365 enum elf_ppc64_reloc_type r_type
;
9366 unsigned long r_symndx
;
9367 Elf_Internal_Sym
*sym
;
9369 struct elf_link_hash_entry
*h
;
9370 struct got_entry
*ent
;
9372 unsigned char buf
[8];
9374 enum {no_check
, check_lo
, check_ha
} insn_check
;
9376 r_type
= ELF64_R_TYPE (rel
->r_info
);
9380 insn_check
= no_check
;
9383 case R_PPC64_PLT16_HA
:
9384 case R_PPC64_GOT_TLSLD16_HA
:
9385 case R_PPC64_GOT_TLSGD16_HA
:
9386 case R_PPC64_GOT_TPREL16_HA
:
9387 case R_PPC64_GOT_DTPREL16_HA
:
9388 case R_PPC64_GOT16_HA
:
9389 case R_PPC64_TOC16_HA
:
9390 insn_check
= check_ha
;
9393 case R_PPC64_PLT16_LO
:
9394 case R_PPC64_PLT16_LO_DS
:
9395 case R_PPC64_GOT_TLSLD16_LO
:
9396 case R_PPC64_GOT_TLSGD16_LO
:
9397 case R_PPC64_GOT_TPREL16_LO_DS
:
9398 case R_PPC64_GOT_DTPREL16_LO_DS
:
9399 case R_PPC64_GOT16_LO
:
9400 case R_PPC64_GOT16_LO_DS
:
9401 case R_PPC64_TOC16_LO
:
9402 case R_PPC64_TOC16_LO_DS
:
9403 insn_check
= check_lo
;
9407 if (insn_check
!= no_check
)
9409 bfd_vma off
= rel
->r_offset
& ~3;
9411 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9414 insn
= bfd_get_32 (ibfd
, buf
);
9415 if (insn_check
== check_lo
9416 ? !ok_lo_toc_insn (insn
, r_type
)
9417 : ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9418 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9422 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9423 sprintf (str
, "%#08x", insn
);
9424 info
->callbacks
->einfo
9425 /* xgettext:c-format */
9426 (_("%H: got/toc optimization is not supported for"
9427 " %s instruction\n"),
9428 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9435 /* Note that we don't delete GOT entries for
9436 R_PPC64_GOT16_DS since we'd need a lot more
9437 analysis. For starters, the preliminary layout is
9438 before the GOT, PLT, dynamic sections and stubs are
9439 laid out. Then we'd need to allow for changes in
9440 distance between sections caused by alignment. */
9444 case R_PPC64_GOT16_HA
:
9445 case R_PPC64_GOT16_LO_DS
:
9446 case R_PPC64_GOT_PCREL34
:
9450 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9451 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9456 || sym_sec
->output_section
== NULL
9457 || discarded_section (sym_sec
))
9460 if ((h
? h
->type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
)
9463 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9467 val
= h
->root
.u
.def
.value
;
9469 val
= sym
->st_value
;
9470 val
+= rel
->r_addend
;
9471 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9473 /* Fudge factor to allow for the fact that the preliminary layout
9474 isn't exact. Reduce limits by this factor. */
9475 #define LIMIT_ADJUST(LIMIT) ((LIMIT) - (LIMIT) / 16)
9482 case R_PPC64_GOT16_HA
:
9483 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9484 >= LIMIT_ADJUST (0x100000000ULL
))
9487 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9488 rel
->r_offset
& ~3, 4))
9490 insn
= bfd_get_32 (ibfd
, buf
);
9491 if (((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9492 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9496 case R_PPC64_GOT16_LO_DS
:
9497 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9498 >= LIMIT_ADJUST (0x100000000ULL
))
9500 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9501 rel
->r_offset
& ~3, 4))
9503 insn
= bfd_get_32 (ibfd
, buf
);
9504 if ((insn
& (0x3fu
<< 26 | 0x3)) != 58u << 26 /* ld */)
9508 case R_PPC64_GOT_PCREL34
:
9510 pc
+= sec
->output_section
->vma
+ sec
->output_offset
;
9511 if (val
- pc
+ LIMIT_ADJUST (1ULL << 33)
9512 >= LIMIT_ADJUST (1ULL << 34))
9514 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9515 rel
->r_offset
& ~3, 8))
9517 insn
= bfd_get_32 (ibfd
, buf
);
9518 if ((insn
& (-1u << 18)) != ((1u << 26) | (1u << 20)))
9520 insn
= bfd_get_32 (ibfd
, buf
+ 4);
9521 if ((insn
& (0x3fu
<< 26)) != 57u << 26)
9531 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
9532 ent
= local_got_ents
[r_symndx
];
9534 for (; ent
!= NULL
; ent
= ent
->next
)
9535 if (ent
->addend
== rel
->r_addend
9536 && ent
->owner
== ibfd
9537 && ent
->tls_type
== 0)
9539 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
9540 ent
->got
.refcount
-= 1;
9543 if (elf_section_data (sec
)->relocs
!= relstart
)
9547 if (local_syms
!= NULL
9548 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9550 if (!info
->keep_memory
)
9553 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9560 /* Return true iff input section I references the TOC using
9561 instructions limited to +/-32k offsets. */
9564 ppc64_elf_has_small_toc_reloc (asection
*i
)
9566 return (is_ppc64_elf (i
->owner
)
9567 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9570 /* Allocate space for one GOT entry. */
9573 allocate_got (struct elf_link_hash_entry
*h
,
9574 struct bfd_link_info
*info
,
9575 struct got_entry
*gent
)
9577 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9578 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
9579 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9581 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9582 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9583 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9585 gent
->got
.offset
= got
->size
;
9586 got
->size
+= entsize
;
9588 if (h
->type
== STT_GNU_IFUNC
)
9590 htab
->elf
.irelplt
->size
+= rentsize
;
9591 htab
->got_reli_size
+= rentsize
;
9593 else if (((bfd_link_pic (info
)
9594 && !(gent
->tls_type
!= 0
9595 && bfd_link_executable (info
)
9596 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9597 || (htab
->elf
.dynamic_sections_created
9599 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9600 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9602 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9603 relgot
->size
+= rentsize
;
9607 /* This function merges got entries in the same toc group. */
9610 merge_got_entries (struct got_entry
**pent
)
9612 struct got_entry
*ent
, *ent2
;
9614 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9615 if (!ent
->is_indirect
)
9616 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9617 if (!ent2
->is_indirect
9618 && ent2
->addend
== ent
->addend
9619 && ent2
->tls_type
== ent
->tls_type
9620 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9622 ent2
->is_indirect
= true;
9623 ent2
->got
.ent
= ent
;
9627 /* If H is undefined, make it dynamic if that makes sense. */
9630 ensure_undef_dynamic (struct bfd_link_info
*info
,
9631 struct elf_link_hash_entry
*h
)
9633 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9635 if (htab
->dynamic_sections_created
9636 && ((info
->dynamic_undefined_weak
!= 0
9637 && h
->root
.type
== bfd_link_hash_undefweak
)
9638 || h
->root
.type
== bfd_link_hash_undefined
)
9641 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9642 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9646 /* Choose whether to use htab->iplt or htab->pltlocal rather than the
9647 usual htab->elf.splt section for a PLT entry. */
9650 bool use_local_plt (struct bfd_link_info
*info
,
9651 struct elf_link_hash_entry
*h
)
9655 || !elf_hash_table (info
)->dynamic_sections_created
);
9658 /* Allocate space in .plt, .got and associated reloc sections for
9662 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9664 struct bfd_link_info
*info
;
9665 struct ppc_link_hash_table
*htab
;
9667 struct ppc_link_hash_entry
*eh
;
9668 struct got_entry
**pgent
, *gent
;
9670 if (h
->root
.type
== bfd_link_hash_indirect
)
9673 info
= (struct bfd_link_info
*) inf
;
9674 htab
= ppc_hash_table (info
);
9678 eh
= ppc_elf_hash_entry (h
);
9679 /* Run through the TLS GD got entries first if we're changing them
9681 if ((eh
->tls_mask
& (TLS_TLS
| TLS_GDIE
)) == (TLS_TLS
| TLS_GDIE
))
9682 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9683 if (gent
->got
.refcount
> 0
9684 && (gent
->tls_type
& TLS_GD
) != 0)
9686 /* This was a GD entry that has been converted to TPREL. If
9687 there happens to be a TPREL entry we can use that one. */
9688 struct got_entry
*ent
;
9689 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9690 if (ent
->got
.refcount
> 0
9691 && (ent
->tls_type
& TLS_TPREL
) != 0
9692 && ent
->addend
== gent
->addend
9693 && ent
->owner
== gent
->owner
)
9695 gent
->got
.refcount
= 0;
9699 /* If not, then we'll be using our own TPREL entry. */
9700 if (gent
->got
.refcount
!= 0)
9701 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9704 /* Remove any list entry that won't generate a word in the GOT before
9705 we call merge_got_entries. Otherwise we risk merging to empty
9707 pgent
= &h
->got
.glist
;
9708 while ((gent
= *pgent
) != NULL
)
9709 if (gent
->got
.refcount
> 0)
9711 if ((gent
->tls_type
& TLS_LD
) != 0
9712 && SYMBOL_REFERENCES_LOCAL (info
, h
))
9714 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9715 *pgent
= gent
->next
;
9718 pgent
= &gent
->next
;
9721 *pgent
= gent
->next
;
9723 if (!htab
->do_multi_toc
)
9724 merge_got_entries (&h
->got
.glist
);
9726 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9727 if (!gent
->is_indirect
)
9729 /* Ensure we catch all the cases where this symbol should
9731 if (!ensure_undef_dynamic (info
, h
))
9734 if (!is_ppc64_elf (gent
->owner
))
9737 allocate_got (h
, info
, gent
);
9740 /* If no dynamic sections we can't have dynamic relocs, except for
9741 IFUNCs which are handled even in static executables. */
9742 if (!htab
->elf
.dynamic_sections_created
9743 && h
->type
!= STT_GNU_IFUNC
)
9744 h
->dyn_relocs
= NULL
;
9746 /* Discard relocs on undefined symbols that must be local. */
9747 else if (h
->root
.type
== bfd_link_hash_undefined
9748 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9749 h
->dyn_relocs
= NULL
;
9751 /* Also discard relocs on undefined weak syms with non-default
9752 visibility, or when dynamic_undefined_weak says so. */
9753 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9754 h
->dyn_relocs
= NULL
;
9756 if (h
->dyn_relocs
!= NULL
)
9758 struct elf_dyn_relocs
*p
, **pp
;
9760 /* In the shared -Bsymbolic case, discard space allocated for
9761 dynamic pc-relative relocs against symbols which turn out to
9762 be defined in regular objects. For the normal shared case,
9763 discard space for relocs that have become local due to symbol
9764 visibility changes. */
9765 if (bfd_link_pic (info
))
9767 /* Relocs that use pc_count are those that appear on a call
9768 insn, or certain REL relocs (see must_be_dyn_reloc) that
9769 can be generated via assembly. We want calls to
9770 protected symbols to resolve directly to the function
9771 rather than going via the plt. If people want function
9772 pointer comparisons to work as expected then they should
9773 avoid writing weird assembly. */
9774 if (SYMBOL_CALLS_LOCAL (info
, h
))
9776 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
9778 p
->count
-= p
->pc_count
;
9787 if (h
->dyn_relocs
!= NULL
)
9789 /* Ensure we catch all the cases where this symbol
9790 should be made dynamic. */
9791 if (!ensure_undef_dynamic (info
, h
))
9796 /* For a fixed position executable, discard space for
9797 relocs against symbols which are not dynamic. */
9798 else if (h
->type
!= STT_GNU_IFUNC
)
9800 if (h
->dynamic_adjusted
9802 && !ELF_COMMON_DEF_P (h
))
9804 /* Ensure we catch all the cases where this symbol
9805 should be made dynamic. */
9806 if (!ensure_undef_dynamic (info
, h
))
9809 /* But if that didn't work out, discard dynamic relocs. */
9810 if (h
->dynindx
== -1)
9811 h
->dyn_relocs
= NULL
;
9814 h
->dyn_relocs
= NULL
;
9817 /* Finally, allocate space. */
9818 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9820 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9821 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9822 sreloc
= htab
->elf
.irelplt
;
9823 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9827 /* We might need a PLT entry when the symbol
9830 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
9831 d) has plt16 relocs and we are linking statically. */
9832 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
9833 || h
->type
== STT_GNU_IFUNC
9834 || (h
->needs_plt
&& h
->dynamic_adjusted
)
9837 && !htab
->elf
.dynamic_sections_created
9838 && !htab
->can_convert_all_inline_plt
9839 && (ppc_elf_hash_entry (h
)->tls_mask
9840 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
9842 struct plt_entry
*pent
;
9843 bool doneone
= false;
9844 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9845 if (pent
->plt
.refcount
> 0)
9847 if (use_local_plt (info
, h
))
9849 if (h
->type
== STT_GNU_IFUNC
)
9852 pent
->plt
.offset
= s
->size
;
9853 s
->size
+= PLT_ENTRY_SIZE (htab
);
9854 s
= htab
->elf
.irelplt
;
9859 pent
->plt
.offset
= s
->size
;
9860 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9861 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
9866 /* If this is the first .plt entry, make room for the special
9870 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9872 pent
->plt
.offset
= s
->size
;
9874 /* Make room for this entry. */
9875 s
->size
+= PLT_ENTRY_SIZE (htab
);
9877 /* Make room for the .glink code. */
9880 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
9883 /* We need bigger stubs past index 32767. */
9884 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
9891 /* We also need to make an entry in the .rela.plt section. */
9892 s
= htab
->elf
.srelplt
;
9895 s
->size
+= sizeof (Elf64_External_Rela
);
9899 pent
->plt
.offset
= (bfd_vma
) -1;
9902 h
->plt
.plist
= NULL
;
9908 h
->plt
.plist
= NULL
;
9915 #define PPC_LO(v) ((v) & 0xffff)
9916 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9917 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9919 ((((v) & 0x3ffff0000ULL) << 16) | (v & 0xffff))
9920 #define HA34(v) ((v + (1ULL << 33)) >> 34)
9922 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9923 to set up space for global entry stubs. These are put in glink,
9924 after the branch table. */
9927 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
9929 struct bfd_link_info
*info
;
9930 struct ppc_link_hash_table
*htab
;
9931 struct plt_entry
*pent
;
9934 if (h
->root
.type
== bfd_link_hash_indirect
)
9937 if (!h
->pointer_equality_needed
)
9944 htab
= ppc_hash_table (info
);
9948 s
= htab
->global_entry
;
9949 plt
= htab
->elf
.splt
;
9950 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9951 if (pent
->plt
.offset
!= (bfd_vma
) -1
9952 && pent
->addend
== 0)
9954 /* For ELFv2, if this symbol is not defined in a regular file
9955 and we are not generating a shared library or pie, then we
9956 need to define the symbol in the executable on a call stub.
9957 This is to avoid text relocations. */
9958 bfd_vma off
, stub_align
, stub_off
, stub_size
;
9959 unsigned int align_power
;
9963 if (htab
->params
->plt_stub_align
>= 0)
9964 align_power
= htab
->params
->plt_stub_align
;
9966 align_power
= -htab
->params
->plt_stub_align
;
9967 /* Setting section alignment is delayed until we know it is
9968 non-empty. Otherwise the .text output section will be
9969 aligned at least to plt_stub_align even when no global
9970 entry stubs are needed. */
9971 if (s
->alignment_power
< align_power
)
9972 s
->alignment_power
= align_power
;
9973 stub_align
= (bfd_vma
) 1 << align_power
;
9974 if (htab
->params
->plt_stub_align
>= 0
9975 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
9976 - (stub_off
& -stub_align
))
9977 > ((stub_size
- 1) & -stub_align
)))
9978 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
9979 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
9980 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
9981 /* Note that for --plt-stub-align negative we have a possible
9982 dependency between stub offset and size. Break that
9983 dependency by assuming the max stub size when calculating
9985 if (PPC_HA (off
) == 0)
9987 h
->root
.type
= bfd_link_hash_defined
;
9988 h
->root
.u
.def
.section
= s
;
9989 h
->root
.u
.def
.value
= stub_off
;
9990 s
->size
= stub_off
+ stub_size
;
9996 /* Set the sizes of the dynamic sections. */
9999 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10000 struct bfd_link_info
*info
)
10002 struct ppc_link_hash_table
*htab
;
10007 struct got_entry
*first_tlsld
;
10009 htab
= ppc_hash_table (info
);
10013 dynobj
= htab
->elf
.dynobj
;
10014 if (dynobj
== NULL
)
10017 if (htab
->elf
.dynamic_sections_created
)
10019 /* Set the contents of the .interp section to the interpreter. */
10020 if (bfd_link_executable (info
) && !info
->nointerp
)
10022 s
= bfd_get_linker_section (dynobj
, ".interp");
10025 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10026 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10030 /* Set up .got offsets for local syms, and space for local dynamic
10032 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10034 struct got_entry
**lgot_ents
;
10035 struct got_entry
**end_lgot_ents
;
10036 struct plt_entry
**local_plt
;
10037 struct plt_entry
**end_local_plt
;
10038 unsigned char *lgot_masks
;
10039 bfd_size_type locsymcount
;
10040 Elf_Internal_Shdr
*symtab_hdr
;
10042 if (!is_ppc64_elf (ibfd
))
10045 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10047 struct ppc_dyn_relocs
*p
;
10049 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10051 if (!bfd_is_abs_section (p
->sec
)
10052 && bfd_is_abs_section (p
->sec
->output_section
))
10054 /* Input section has been discarded, either because
10055 it is a copy of a linkonce section or due to
10056 linker script /DISCARD/, so we'll be discarding
10059 else if (p
->count
!= 0)
10061 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
10063 srel
= htab
->elf
.irelplt
;
10064 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10065 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10066 info
->flags
|= DF_TEXTREL
;
10071 lgot_ents
= elf_local_got_ents (ibfd
);
10075 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10076 locsymcount
= symtab_hdr
->sh_info
;
10077 end_lgot_ents
= lgot_ents
+ locsymcount
;
10078 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10079 end_local_plt
= local_plt
+ locsymcount
;
10080 lgot_masks
= (unsigned char *) end_local_plt
;
10081 s
= ppc64_elf_tdata (ibfd
)->got
;
10082 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10084 struct got_entry
**pent
, *ent
;
10087 while ((ent
= *pent
) != NULL
)
10088 if (ent
->got
.refcount
> 0)
10090 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10092 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10097 unsigned int ent_size
= 8;
10098 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10100 ent
->got
.offset
= s
->size
;
10101 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10106 s
->size
+= ent_size
;
10107 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10109 htab
->elf
.irelplt
->size
+= rel_size
;
10110 htab
->got_reli_size
+= rel_size
;
10112 else if (bfd_link_pic (info
)
10113 && !(ent
->tls_type
!= 0
10114 && bfd_link_executable (info
)))
10116 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10117 srel
->size
+= rel_size
;
10126 /* Allocate space for plt calls to local syms. */
10127 lgot_masks
= (unsigned char *) end_local_plt
;
10128 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10130 struct plt_entry
*ent
;
10132 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10133 if (ent
->plt
.refcount
> 0)
10135 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10137 s
= htab
->elf
.iplt
;
10138 ent
->plt
.offset
= s
->size
;
10139 s
->size
+= PLT_ENTRY_SIZE (htab
);
10140 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10142 else if (htab
->can_convert_all_inline_plt
10143 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10144 ent
->plt
.offset
= (bfd_vma
) -1;
10147 s
= htab
->pltlocal
;
10148 ent
->plt
.offset
= s
->size
;
10149 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10150 if (bfd_link_pic (info
))
10151 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
10155 ent
->plt
.offset
= (bfd_vma
) -1;
10159 /* Allocate global sym .plt and .got entries, and space for global
10160 sym dynamic relocs. */
10161 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10163 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10164 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10166 first_tlsld
= NULL
;
10167 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10169 struct got_entry
*ent
;
10171 if (!is_ppc64_elf (ibfd
))
10174 ent
= ppc64_tlsld_got (ibfd
);
10175 if (ent
->got
.refcount
> 0)
10177 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10179 ent
->is_indirect
= true;
10180 ent
->got
.ent
= first_tlsld
;
10184 if (first_tlsld
== NULL
)
10186 s
= ppc64_elf_tdata (ibfd
)->got
;
10187 ent
->got
.offset
= s
->size
;
10190 if (bfd_link_dll (info
))
10192 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10193 srel
->size
+= sizeof (Elf64_External_Rela
);
10198 ent
->got
.offset
= (bfd_vma
) -1;
10201 /* We now have determined the sizes of the various dynamic sections.
10202 Allocate memory for them. */
10204 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10206 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10209 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
10210 /* These haven't been allocated yet; don't strip. */
10212 else if (s
== htab
->elf
.sgot
10213 || s
== htab
->elf
.splt
10214 || s
== htab
->elf
.iplt
10215 || s
== htab
->pltlocal
10216 || s
== htab
->glink
10217 || s
== htab
->global_entry
10218 || s
== htab
->elf
.sdynbss
10219 || s
== htab
->elf
.sdynrelro
)
10221 /* Strip this section if we don't need it; see the
10224 else if (s
== htab
->glink_eh_frame
)
10226 if (!bfd_is_abs_section (s
->output_section
))
10227 /* Not sized yet. */
10230 else if (startswith (s
->name
, ".rela"))
10234 if (s
!= htab
->elf
.srelplt
)
10237 /* We use the reloc_count field as a counter if we need
10238 to copy relocs into the output file. */
10239 s
->reloc_count
= 0;
10244 /* It's not one of our sections, so don't allocate space. */
10250 /* If we don't need this section, strip it from the
10251 output file. This is mostly to handle .rela.bss and
10252 .rela.plt. We must create both sections in
10253 create_dynamic_sections, because they must be created
10254 before the linker maps input sections to output
10255 sections. The linker does that before
10256 adjust_dynamic_symbol is called, and it is that
10257 function which decides whether anything needs to go
10258 into these sections. */
10259 s
->flags
|= SEC_EXCLUDE
;
10263 if (bfd_is_abs_section (s
->output_section
))
10264 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10267 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10270 /* Allocate memory for the section contents. We use bfd_zalloc
10271 here in case unused entries are not reclaimed before the
10272 section's contents are written out. This should not happen,
10273 but this way if it does we get a R_PPC64_NONE reloc in .rela
10274 sections instead of garbage.
10275 We also rely on the section contents being zero when writing
10276 the GOT and .dynrelro. */
10277 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10278 if (s
->contents
== NULL
)
10282 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10284 if (!is_ppc64_elf (ibfd
))
10287 s
= ppc64_elf_tdata (ibfd
)->got
;
10288 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10291 s
->flags
|= SEC_EXCLUDE
;
10294 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10295 if (s
->contents
== NULL
)
10299 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10303 s
->flags
|= SEC_EXCLUDE
;
10306 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10307 if (s
->contents
== NULL
)
10310 s
->reloc_count
= 0;
10315 if (htab
->elf
.dynamic_sections_created
)
10319 /* Add some entries to the .dynamic section. We fill in the
10320 values later, in ppc64_elf_finish_dynamic_sections, but we
10321 must add the entries now so that we get the correct size for
10322 the .dynamic section. The DT_DEBUG entry is filled in by the
10323 dynamic linker and used by the debugger. */
10324 #define add_dynamic_entry(TAG, VAL) \
10325 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10327 if (bfd_link_executable (info
))
10329 if (!add_dynamic_entry (DT_DEBUG
, 0))
10333 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10335 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10336 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10337 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10338 || !add_dynamic_entry (DT_JMPREL
, 0)
10339 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10343 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10345 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10346 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10350 tls_opt
= (htab
->params
->tls_get_addr_opt
10351 && ((htab
->tls_get_addr_fd
!= NULL
10352 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
)
10353 || (htab
->tga_desc_fd
!= NULL
10354 && htab
->tga_desc_fd
->elf
.plt
.plist
!= NULL
)));
10355 if (tls_opt
|| !htab
->opd_abi
)
10357 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10363 if (!add_dynamic_entry (DT_RELA
, 0)
10364 || !add_dynamic_entry (DT_RELASZ
, 0)
10365 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10368 /* If any dynamic relocs apply to a read-only section,
10369 then we need a DT_TEXTREL entry. */
10370 if ((info
->flags
& DF_TEXTREL
) == 0)
10371 elf_link_hash_traverse (&htab
->elf
,
10372 _bfd_elf_maybe_set_textrel
, info
);
10374 if ((info
->flags
& DF_TEXTREL
) != 0)
10376 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10381 #undef add_dynamic_entry
10386 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10389 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10391 if (h
->plt
.plist
!= NULL
10393 && !h
->pointer_equality_needed
)
10396 return _bfd_elf_hash_symbol (h
);
10399 /* Determine the type of stub needed, if any, for a call. */
10401 static inline enum ppc_stub_type
10402 ppc_type_of_stub (asection
*input_sec
,
10403 const Elf_Internal_Rela
*rel
,
10404 struct ppc_link_hash_entry
**hash
,
10405 struct plt_entry
**plt_ent
,
10406 bfd_vma destination
,
10407 unsigned long local_off
)
10409 struct ppc_link_hash_entry
*h
= *hash
;
10411 bfd_vma branch_offset
;
10412 bfd_vma max_branch_offset
;
10413 enum elf_ppc64_reloc_type r_type
;
10417 struct plt_entry
*ent
;
10418 struct ppc_link_hash_entry
*fdh
= h
;
10420 && h
->oh
->is_func_descriptor
)
10422 fdh
= ppc_follow_link (h
->oh
);
10426 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10427 if (ent
->addend
== rel
->r_addend
10428 && ent
->plt
.offset
!= (bfd_vma
) -1)
10431 return ppc_stub_plt_call
;
10434 /* Here, we know we don't have a plt entry. If we don't have a
10435 either a defined function descriptor or a defined entry symbol
10436 in a regular object file, then it is pointless trying to make
10437 any other type of stub. */
10438 if (!is_static_defined (&fdh
->elf
)
10439 && !is_static_defined (&h
->elf
))
10440 return ppc_stub_none
;
10442 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10444 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10445 struct plt_entry
**local_plt
= (struct plt_entry
**)
10446 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10447 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10449 if (local_plt
[r_symndx
] != NULL
)
10451 struct plt_entry
*ent
;
10453 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10454 if (ent
->addend
== rel
->r_addend
10455 && ent
->plt
.offset
!= (bfd_vma
) -1)
10458 return ppc_stub_plt_call
;
10463 /* Determine where the call point is. */
10464 location
= (input_sec
->output_offset
10465 + input_sec
->output_section
->vma
10468 branch_offset
= destination
- location
;
10469 r_type
= ELF64_R_TYPE (rel
->r_info
);
10471 /* Determine if a long branch stub is needed. */
10472 max_branch_offset
= 1 << 25;
10473 if (r_type
== R_PPC64_REL14
10474 || r_type
== R_PPC64_REL14_BRTAKEN
10475 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10476 max_branch_offset
= 1 << 15;
10478 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10479 /* We need a stub. Figure out whether a long_branch or plt_branch
10480 is needed later. */
10481 return ppc_stub_long_branch
;
10483 return ppc_stub_none
;
10486 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
10487 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
10492 . lis %r12,xxx-1b@highest
10493 . ori %r12,%r12,xxx-1b@higher
10494 . sldi %r12,%r12,32
10495 . oris %r12,%r12,xxx-1b@high
10496 . ori %r12,%r12,xxx-1b@l
10497 . add/ldx %r12,%r11,%r12 */
10500 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bool load
)
10502 bfd_put_32 (abfd
, MFLR_R12
, p
);
10504 bfd_put_32 (abfd
, BCL_20_31
, p
);
10506 bfd_put_32 (abfd
, MFLR_R11
, p
);
10508 bfd_put_32 (abfd
, MTLR_R12
, p
);
10510 if (off
+ 0x8000 < 0x10000)
10513 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
10515 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
10518 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10520 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
10523 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
10525 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
10530 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10532 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
10537 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
10539 if (((off
>> 32) & 0xffff) != 0)
10541 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
10545 if (((off
>> 32) & 0xffffffffULL
) != 0)
10547 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
10550 if (PPC_HI (off
) != 0)
10552 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
10555 if (PPC_LO (off
) != 0)
10557 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
10561 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10563 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10569 static unsigned int
10570 size_offset (bfd_vma off
)
10573 if (off
+ 0x8000 < 0x10000)
10575 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10579 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10584 if (((off
>> 32) & 0xffff) != 0)
10587 if (((off
>> 32) & 0xffffffffULL
) != 0)
10589 if (PPC_HI (off
) != 0)
10591 if (PPC_LO (off
) != 0)
10598 static unsigned int
10599 num_relocs_for_offset (bfd_vma off
)
10601 unsigned int num_rel
;
10602 if (off
+ 0x8000 < 0x10000)
10604 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10609 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
10610 && ((off
>> 32) & 0xffff) != 0)
10612 if (PPC_HI (off
) != 0)
10614 if (PPC_LO (off
) != 0)
10620 static Elf_Internal_Rela
*
10621 emit_relocs_for_offset (struct bfd_link_info
*info
, Elf_Internal_Rela
*r
,
10622 bfd_vma roff
, bfd_vma targ
, bfd_vma off
)
10624 bfd_vma relative_targ
= targ
- (roff
- 8);
10625 if (bfd_big_endian (info
->output_bfd
))
10627 r
->r_offset
= roff
;
10628 r
->r_addend
= relative_targ
+ roff
;
10629 if (off
+ 0x8000 < 0x10000)
10630 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16
);
10631 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10633 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HA
);
10636 r
->r_offset
= roff
;
10637 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10638 r
->r_addend
= relative_targ
+ roff
;
10642 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10643 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10646 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHEST
);
10647 if (((off
>> 32) & 0xffff) != 0)
10651 r
->r_offset
= roff
;
10652 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10653 r
->r_addend
= relative_targ
+ roff
;
10656 if (((off
>> 32) & 0xffffffffULL
) != 0)
10658 if (PPC_HI (off
) != 0)
10662 r
->r_offset
= roff
;
10663 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGH
);
10664 r
->r_addend
= relative_targ
+ roff
;
10666 if (PPC_LO (off
) != 0)
10670 r
->r_offset
= roff
;
10671 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10672 r
->r_addend
= relative_targ
+ roff
;
10679 build_power10_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, int odd
,
10683 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10688 bfd_put_32 (abfd
, NOP
, p
);
10694 insn
= PADDI_R12_PC
;
10696 bfd_put_32 (abfd
, insn
>> 32, p
);
10698 bfd_put_32 (abfd
, insn
, p
);
10700 /* The minimum value for paddi is -0x200000000. The minimum value
10701 for li is -0x8000, which when shifted by 34 and added gives a
10702 minimum value of -0x2000200000000. The maximum value is
10703 0x1ffffffff+0x7fff<<34 which is 0x2000200000000-1. */
10704 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10707 bfd_put_32 (abfd
, LI_R11_0
| (HA34 (off
) & 0xffff), p
);
10711 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10714 insn
= PADDI_R12_PC
| D34 (off
);
10715 bfd_put_32 (abfd
, insn
>> 32, p
);
10717 bfd_put_32 (abfd
, insn
, p
);
10721 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10725 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10727 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10732 bfd_put_32 (abfd
, LIS_R11
| ((HA34 (off
) >> 16) & 0x3fff), p
);
10734 bfd_put_32 (abfd
, ORI_R11_R11_0
| (HA34 (off
) & 0xffff), p
);
10738 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10741 insn
= PADDI_R12_PC
| D34 (off
);
10742 bfd_put_32 (abfd
, insn
>> 32, p
);
10744 bfd_put_32 (abfd
, insn
, p
);
10748 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10752 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10754 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10760 static unsigned int
10761 size_power10_offset (bfd_vma off
, int odd
)
10763 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10765 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10771 static unsigned int
10772 num_relocs_for_power10_offset (bfd_vma off
, int odd
)
10774 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10776 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10782 static Elf_Internal_Rela
*
10783 emit_relocs_for_power10_offset (struct bfd_link_info
*info
,
10784 Elf_Internal_Rela
*r
, bfd_vma roff
,
10785 bfd_vma targ
, bfd_vma off
, int odd
)
10787 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10789 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10791 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
10792 r
->r_offset
= roff
+ d_offset
;
10793 r
->r_addend
= targ
+ 8 - odd
- d_offset
;
10794 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
10800 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
10801 r
->r_offset
= roff
+ d_offset
;
10802 r
->r_addend
= targ
+ 8 + odd
- d_offset
;
10803 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHESTA34
);
10806 r
->r_offset
= roff
+ d_offset
;
10807 r
->r_addend
= targ
+ 4 + odd
- d_offset
;
10808 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
10812 r
->r_offset
= roff
;
10813 r
->r_addend
= targ
;
10814 r
->r_info
= ELF64_R_INFO (0, R_PPC64_PCREL34
);
10818 /* Emit .eh_frame opcode to advance pc by DELTA. */
10821 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
10825 *eh
++ = DW_CFA_advance_loc
+ delta
;
10826 else if (delta
< 256)
10828 *eh
++ = DW_CFA_advance_loc1
;
10831 else if (delta
< 65536)
10833 *eh
++ = DW_CFA_advance_loc2
;
10834 bfd_put_16 (abfd
, delta
, eh
);
10839 *eh
++ = DW_CFA_advance_loc4
;
10840 bfd_put_32 (abfd
, delta
, eh
);
10846 /* Size of required .eh_frame opcode to advance pc by DELTA. */
10848 static unsigned int
10849 eh_advance_size (unsigned int delta
)
10851 if (delta
< 64 * 4)
10852 /* DW_CFA_advance_loc+[1..63]. */
10854 if (delta
< 256 * 4)
10855 /* DW_CFA_advance_loc1, byte. */
10857 if (delta
< 65536 * 4)
10858 /* DW_CFA_advance_loc2, 2 bytes. */
10860 /* DW_CFA_advance_loc4, 4 bytes. */
10864 /* With power7 weakly ordered memory model, it is possible for ld.so
10865 to update a plt entry in one thread and have another thread see a
10866 stale zero toc entry. To avoid this we need some sort of acquire
10867 barrier in the call stub. One solution is to make the load of the
10868 toc word seem to appear to depend on the load of the function entry
10869 word. Another solution is to test for r2 being zero, and branch to
10870 the appropriate glink entry if so.
10872 . fake dep barrier compare
10873 . ld 12,xxx(2) ld 12,xxx(2)
10874 . mtctr 12 mtctr 12
10875 . xor 11,12,12 ld 2,xxx+8(2)
10876 . add 2,2,11 cmpldi 2,0
10877 . ld 2,xxx+8(2) bnectr+
10878 . bctr b <glink_entry>
10880 The solution involving the compare turns out to be faster, so
10881 that's what we use unless the branch won't reach. */
10883 #define ALWAYS_USE_FAKE_DEP 0
10884 #define ALWAYS_EMIT_R2SAVE 0
10886 static inline unsigned int
10887 plt_stub_size (struct ppc_link_hash_table
*htab
,
10888 struct ppc_stub_hash_entry
*stub_entry
,
10894 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
10896 if (htab
->params
->power10_stubs
!= 0)
10897 size
= 8 + size_power10_offset (off
, odd
);
10899 size
= 8 + size_offset (off
- 8);
10900 if (stub_entry
->stub_type
> ppc_stub_plt_call_notoc
)
10906 if (ALWAYS_EMIT_R2SAVE
10907 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10909 if (PPC_HA (off
) != 0)
10914 if (htab
->params
->plt_static_chain
)
10916 if (htab
->params
->plt_thread_safe
10917 && htab
->elf
.dynamic_sections_created
10918 && stub_entry
->h
!= NULL
10919 && stub_entry
->h
->elf
.dynindx
!= -1)
10921 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
)
10926 if (stub_entry
->h
!= NULL
10927 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
10928 && htab
->params
->tls_get_addr_opt
)
10930 if (!htab
->params
->no_tls_get_addr_regsave
)
10933 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
10934 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10940 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
10941 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10948 /* Depending on the sign of plt_stub_align:
10949 If positive, return the padding to align to a 2**plt_stub_align
10951 If negative, if this stub would cross fewer 2**plt_stub_align
10952 boundaries if we align, then return the padding needed to do so. */
10954 static inline unsigned int
10955 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10956 struct ppc_stub_hash_entry
*stub_entry
,
10961 unsigned stub_size
;
10962 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10964 if (htab
->params
->plt_stub_align
>= 0)
10966 stub_align
= 1 << htab
->params
->plt_stub_align
;
10967 if ((stub_off
& (stub_align
- 1)) != 0)
10968 return stub_align
- (stub_off
& (stub_align
- 1));
10972 stub_align
= 1 << -htab
->params
->plt_stub_align
;
10973 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
, odd
);
10974 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10975 > ((stub_size
- 1) & -stub_align
))
10976 return stub_align
- (stub_off
& (stub_align
- 1));
10980 /* Build a .plt call stub. */
10982 static inline bfd_byte
*
10983 build_plt_stub (struct ppc_link_hash_table
*htab
,
10984 struct ppc_stub_hash_entry
*stub_entry
,
10985 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10987 bfd
*obfd
= htab
->params
->stub_bfd
;
10988 bool plt_load_toc
= htab
->opd_abi
;
10989 bool plt_static_chain
= htab
->params
->plt_static_chain
;
10990 bool plt_thread_safe
= (htab
->params
->plt_thread_safe
10991 && htab
->elf
.dynamic_sections_created
10992 && stub_entry
->h
!= NULL
10993 && stub_entry
->h
->elf
.dynindx
!= -1);
10994 bool use_fake_dep
= plt_thread_safe
;
10995 bfd_vma cmp_branch_off
= 0;
10997 if (!ALWAYS_USE_FAKE_DEP
11000 && !(stub_entry
->h
!= NULL
11001 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11002 && htab
->params
->tls_get_addr_opt
))
11004 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11005 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
11006 / PLT_ENTRY_SIZE (htab
));
11007 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
11010 if (pltindex
> 32768)
11011 glinkoff
+= (pltindex
- 32768) * 4;
11013 + htab
->glink
->output_offset
11014 + htab
->glink
->output_section
->vma
);
11015 from
= (p
- stub_entry
->group
->stub_sec
->contents
11016 + 4 * (ALWAYS_EMIT_R2SAVE
11017 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11018 + 4 * (PPC_HA (offset
) != 0)
11019 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
11020 != PPC_HA (offset
))
11021 + 4 * (plt_static_chain
!= 0)
11023 + stub_entry
->group
->stub_sec
->output_offset
11024 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11025 cmp_branch_off
= to
- from
;
11026 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
11029 if (PPC_HA (offset
) != 0)
11033 if (ALWAYS_EMIT_R2SAVE
11034 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11035 r
[0].r_offset
+= 4;
11036 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11037 r
[1].r_offset
= r
[0].r_offset
+ 4;
11038 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11039 r
[1].r_addend
= r
[0].r_addend
;
11042 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11044 r
[2].r_offset
= r
[1].r_offset
+ 4;
11045 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
11046 r
[2].r_addend
= r
[0].r_addend
;
11050 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
11051 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11052 r
[2].r_addend
= r
[0].r_addend
+ 8;
11053 if (plt_static_chain
)
11055 r
[3].r_offset
= r
[2].r_offset
+ 4;
11056 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11057 r
[3].r_addend
= r
[0].r_addend
+ 16;
11062 if (ALWAYS_EMIT_R2SAVE
11063 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11064 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11067 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
11068 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
11072 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
11073 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
11076 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11078 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
11081 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11086 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
11087 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
11089 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
11090 if (plt_static_chain
)
11091 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
11098 if (ALWAYS_EMIT_R2SAVE
11099 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11100 r
[0].r_offset
+= 4;
11101 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11104 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11106 r
[1].r_offset
= r
[0].r_offset
+ 4;
11107 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
11108 r
[1].r_addend
= r
[0].r_addend
;
11112 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
11113 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11114 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
11115 if (plt_static_chain
)
11117 r
[2].r_offset
= r
[1].r_offset
+ 4;
11118 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11119 r
[2].r_addend
= r
[0].r_addend
+ 8;
11124 if (ALWAYS_EMIT_R2SAVE
11125 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11126 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11127 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
11129 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11131 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
11134 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11139 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
11140 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
11142 if (plt_static_chain
)
11143 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
11144 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
11147 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
11149 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
11150 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
11151 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
11154 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
11158 /* Build a special .plt call stub for __tls_get_addr. */
11160 #define LD_R0_0R3 0xe8030000
11161 #define LD_R12_0R3 0xe9830000
11162 #define MR_R0_R3 0x7c601b78
11163 #define CMPDI_R0_0 0x2c200000
11164 #define ADD_R3_R12_R13 0x7c6c6a14
11165 #define BEQLR 0x4d820020
11166 #define MR_R3_R0 0x7c030378
11167 #define BCTRL 0x4e800421
11170 build_tls_get_addr_head (struct ppc_link_hash_table
*htab
,
11171 struct ppc_stub_hash_entry
*stub_entry
,
11174 bfd
*obfd
= htab
->params
->stub_bfd
;
11176 bfd_put_32 (obfd
, LD_R0_0R3
+ 0, p
), p
+= 4;
11177 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
11178 bfd_put_32 (obfd
, CMPDI_R0_0
, p
), p
+= 4;
11179 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
11180 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
11181 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
11182 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
11184 if (!htab
->params
->no_tls_get_addr_regsave
)
11185 p
= tls_get_addr_prologue (obfd
, p
, htab
);
11186 else if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
11187 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11189 bfd_put_32 (obfd
, MFLR_R0
, p
);
11191 bfd_put_32 (obfd
, STD_R0_0R1
+ STK_LINKER (htab
), p
);
11198 build_tls_get_addr_tail (struct ppc_link_hash_table
*htab
,
11199 struct ppc_stub_hash_entry
*stub_entry
,
11203 bfd
*obfd
= htab
->params
->stub_bfd
;
11205 if (!htab
->params
->no_tls_get_addr_regsave
)
11207 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11209 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
11210 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11212 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11215 p
= tls_get_addr_epilogue (obfd
, p
, htab
);
11217 else if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
11218 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11220 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11222 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11224 bfd_put_32 (obfd
, LD_R0_0R1
+ STK_LINKER (htab
), p
);
11226 bfd_put_32 (obfd
, MTLR_R0
, p
);
11228 bfd_put_32 (obfd
, BLR
, p
);
11232 if (htab
->glink_eh_frame
!= NULL
11233 && htab
->glink_eh_frame
->size
!= 0)
11235 bfd_byte
*base
, *eh
;
11237 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
11238 eh
= base
+ stub_entry
->group
->eh_size
;
11240 if (!htab
->params
->no_tls_get_addr_regsave
)
11242 unsigned int cfa_updt
, delta
, i
;
11244 /* After the bctrl, lr has been modified so we need to emit
11245 .eh_frame info saying the return address is on the stack. In
11246 fact we must put the EH info at or before the call rather
11247 than after it, because the EH info for a call needs to be
11248 specified by that point.
11249 See libgcc/unwind-dw2.c execute_cfa_program.
11250 Any stack pointer update must be described immediately after
11251 the instruction making the change, and since the stdu occurs
11252 after saving regs we put all the reg saves and the cfa
11254 cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
11255 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
11256 stub_entry
->group
->lr_restore
11257 = stub_entry
->stub_offset
+ (p
- loc
) - 4;
11258 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11259 *eh
++ = DW_CFA_def_cfa_offset
;
11267 *eh
++ = DW_CFA_offset_extended_sf
;
11269 *eh
++ = (-16 / 8) & 0x7f;
11270 for (i
= 4; i
< 12; i
++)
11272 *eh
++ = DW_CFA_offset
+ i
;
11273 *eh
++ = (htab
->opd_abi
? 13 : 12) - i
;
11275 *eh
++ = (DW_CFA_advance_loc
11276 + (stub_entry
->group
->lr_restore
- 8 - cfa_updt
) / 4);
11277 *eh
++ = DW_CFA_def_cfa_offset
;
11279 for (i
= 4; i
< 12; i
++)
11280 *eh
++ = DW_CFA_restore
+ i
;
11281 *eh
++ = DW_CFA_advance_loc
+ 2;
11282 *eh
++ = DW_CFA_restore_extended
;
11284 stub_entry
->group
->eh_size
= eh
- base
;
11286 else if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
11287 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11289 unsigned int lr_used
, delta
;
11291 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
11292 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11293 stub_entry
->group
->lr_restore
= lr_used
+ 16;
11294 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11295 *eh
++ = DW_CFA_offset_extended_sf
;
11297 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
11298 *eh
++ = DW_CFA_advance_loc
+ 4;
11299 *eh
++ = DW_CFA_restore_extended
;
11301 stub_entry
->group
->eh_size
= eh
- base
;
11307 static Elf_Internal_Rela
*
11308 get_relocs (asection
*sec
, int count
)
11310 Elf_Internal_Rela
*relocs
;
11311 struct bfd_elf_section_data
*elfsec_data
;
11313 elfsec_data
= elf_section_data (sec
);
11314 relocs
= elfsec_data
->relocs
;
11315 if (relocs
== NULL
)
11317 bfd_size_type relsize
;
11318 relsize
= sec
->reloc_count
* sizeof (*relocs
);
11319 relocs
= bfd_alloc (sec
->owner
, relsize
);
11320 if (relocs
== NULL
)
11322 elfsec_data
->relocs
= relocs
;
11323 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
11324 sizeof (Elf_Internal_Shdr
));
11325 if (elfsec_data
->rela
.hdr
== NULL
)
11327 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
11328 * sizeof (Elf64_External_Rela
));
11329 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
11330 sec
->reloc_count
= 0;
11332 relocs
+= sec
->reloc_count
;
11333 sec
->reloc_count
+= count
;
11337 /* Convert the relocs R[0] thru R[-NUM_REL+1], which are all no-symbol
11338 forms, to the equivalent relocs against the global symbol given by
11342 use_global_in_relocs (struct ppc_link_hash_table
*htab
,
11343 struct ppc_stub_hash_entry
*stub_entry
,
11344 Elf_Internal_Rela
*r
, unsigned int num_rel
)
11346 struct elf_link_hash_entry
**hashes
;
11347 unsigned long symndx
;
11348 struct ppc_link_hash_entry
*h
;
11351 /* Relocs are always against symbols in their own object file. Fake
11352 up global sym hashes for the stub bfd (which has no symbols). */
11353 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
11354 if (hashes
== NULL
)
11356 bfd_size_type hsize
;
11358 /* When called the first time, stub_globals will contain the
11359 total number of symbols seen during stub sizing. After
11360 allocating, stub_globals is used as an index to fill the
11362 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
11363 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
11364 if (hashes
== NULL
)
11366 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
11367 htab
->stub_globals
= 1;
11369 symndx
= htab
->stub_globals
++;
11371 hashes
[symndx
] = &h
->elf
;
11372 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
11373 h
= ppc_follow_link (h
->oh
);
11374 BFD_ASSERT (h
->elf
.root
.type
== bfd_link_hash_defined
11375 || h
->elf
.root
.type
== bfd_link_hash_defweak
);
11376 symval
= defined_sym_val (&h
->elf
);
11377 while (num_rel
-- != 0)
11379 r
->r_info
= ELF64_R_INFO (symndx
, ELF64_R_TYPE (r
->r_info
));
11380 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11382 /* H is an opd symbol. The addend must be zero, and the
11383 branch reloc is the only one we can convert. */
11388 r
->r_addend
-= symval
;
11395 get_r2off (struct bfd_link_info
*info
,
11396 struct ppc_stub_hash_entry
*stub_entry
)
11398 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11399 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
11403 /* Support linking -R objects. Get the toc pointer from the
11406 if (!htab
->opd_abi
)
11408 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
11409 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
11411 if (strcmp (opd
->name
, ".opd") != 0
11412 || opd
->reloc_count
!= 0)
11414 info
->callbacks
->einfo
11415 (_("%P: cannot find opd entry toc for `%pT'\n"),
11416 stub_entry
->h
->elf
.root
.root
.string
);
11417 bfd_set_error (bfd_error_bad_value
);
11418 return (bfd_vma
) -1;
11420 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
11421 return (bfd_vma
) -1;
11422 r2off
= bfd_get_64 (opd
->owner
, buf
);
11423 r2off
-= elf_gp (info
->output_bfd
);
11425 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
11430 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11432 struct ppc_stub_hash_entry
*stub_entry
;
11433 struct ppc_branch_hash_entry
*br_entry
;
11434 struct bfd_link_info
*info
;
11435 struct ppc_link_hash_table
*htab
;
11438 bfd_byte
*p
, *relp
;
11440 Elf_Internal_Rela
*r
;
11446 /* Massage our args to the form they really have. */
11447 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11450 /* Fail if the target section could not be assigned to an output
11451 section. The user should fix his linker script. */
11452 if (stub_entry
->target_section
!= NULL
11453 && stub_entry
->target_section
->output_section
== NULL
11454 && info
->non_contiguous_regions
)
11455 info
->callbacks
->einfo (_("%F%P: Could not assign '%pA' to an output section. "
11456 "Retry without --enable-non-contiguous-regions.\n"),
11457 stub_entry
->target_section
);
11459 /* Same for the group. */
11460 if (stub_entry
->group
->stub_sec
!= NULL
11461 && stub_entry
->group
->stub_sec
->output_section
== NULL
11462 && info
->non_contiguous_regions
)
11463 info
->callbacks
->einfo (_("%F%P: Could not assign group %pA target %pA to an "
11464 "output section. Retry without "
11465 "--enable-non-contiguous-regions.\n"),
11466 stub_entry
->group
->stub_sec
,
11467 stub_entry
->target_section
);
11469 htab
= ppc_hash_table (info
);
11473 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
11474 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
11476 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
11477 switch (stub_entry
->stub_type
)
11479 case ppc_stub_long_branch
:
11480 case ppc_stub_long_branch_r2off
:
11481 /* Branches are relative. This is where we are going to. */
11482 targ
= (stub_entry
->target_value
11483 + stub_entry
->target_section
->output_offset
11484 + stub_entry
->target_section
->output_section
->vma
);
11485 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11487 /* And this is where we are coming from. */
11488 off
= (stub_entry
->stub_offset
11489 + stub_entry
->group
->stub_sec
->output_offset
11490 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11494 obfd
= htab
->params
->stub_bfd
;
11495 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11497 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11499 if (r2off
== (bfd_vma
) -1)
11501 htab
->stub_error
= true;
11504 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11506 if (PPC_HA (r2off
) != 0)
11508 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11511 if (PPC_LO (r2off
) != 0)
11513 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11518 bfd_put_32 (obfd
, B_DOT
| (off
& 0x3fffffc), p
);
11521 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11524 (_("long branch stub `%s' offset overflow"),
11525 stub_entry
->root
.string
);
11526 htab
->stub_error
= true;
11530 if (info
->emitrelocations
)
11532 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11535 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11536 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11537 r
->r_addend
= targ
;
11538 if (stub_entry
->h
!= NULL
11539 && !use_global_in_relocs (htab
, stub_entry
, r
, 1))
11544 case ppc_stub_plt_branch
:
11545 case ppc_stub_plt_branch_r2off
:
11546 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11547 stub_entry
->root
.string
+ 9,
11549 if (br_entry
== NULL
)
11551 _bfd_error_handler (_("can't find branch stub `%s'"),
11552 stub_entry
->root
.string
);
11553 htab
->stub_error
= true;
11557 targ
= (stub_entry
->target_value
11558 + stub_entry
->target_section
->output_offset
11559 + stub_entry
->target_section
->output_section
->vma
);
11560 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11561 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11563 bfd_put_64 (htab
->brlt
->owner
, targ
,
11564 htab
->brlt
->contents
+ br_entry
->offset
);
11566 if (br_entry
->iter
== htab
->stub_iteration
)
11568 br_entry
->iter
= 0;
11570 if (htab
->relbrlt
!= NULL
)
11572 /* Create a reloc for the branch lookup table entry. */
11573 Elf_Internal_Rela rela
;
11576 rela
.r_offset
= (br_entry
->offset
11577 + htab
->brlt
->output_offset
11578 + htab
->brlt
->output_section
->vma
);
11579 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11580 rela
.r_addend
= targ
;
11582 rl
= htab
->relbrlt
->contents
;
11583 rl
+= (htab
->relbrlt
->reloc_count
++
11584 * sizeof (Elf64_External_Rela
));
11585 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11587 else if (info
->emitrelocations
)
11589 r
= get_relocs (htab
->brlt
, 1);
11592 /* brlt, being SEC_LINKER_CREATED does not go through the
11593 normal reloc processing. Symbols and offsets are not
11594 translated from input file to output file form, so
11595 set up the offset per the output file. */
11596 r
->r_offset
= (br_entry
->offset
11597 + htab
->brlt
->output_offset
11598 + htab
->brlt
->output_section
->vma
);
11599 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11600 r
->r_addend
= targ
;
11604 targ
= (br_entry
->offset
11605 + htab
->brlt
->output_offset
11606 + htab
->brlt
->output_section
->vma
);
11608 off
= (elf_gp (info
->output_bfd
)
11609 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11612 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11614 info
->callbacks
->einfo
11615 (_("%P: linkage table error against `%pT'\n"),
11616 stub_entry
->root
.string
);
11617 bfd_set_error (bfd_error_bad_value
);
11618 htab
->stub_error
= true;
11622 if (info
->emitrelocations
)
11624 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11627 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11628 if (bfd_big_endian (info
->output_bfd
))
11629 r
[0].r_offset
+= 2;
11630 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
11631 r
[0].r_offset
+= 4;
11632 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11633 r
[0].r_addend
= targ
;
11634 if (PPC_HA (off
) != 0)
11636 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11637 r
[1].r_offset
= r
[0].r_offset
+ 4;
11638 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11639 r
[1].r_addend
= r
[0].r_addend
;
11644 obfd
= htab
->params
->stub_bfd
;
11645 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11647 if (PPC_HA (off
) != 0)
11649 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11651 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11654 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11658 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11660 if (r2off
== (bfd_vma
) -1)
11662 htab
->stub_error
= true;
11666 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11668 if (PPC_HA (off
) != 0)
11670 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11672 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11675 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11677 if (PPC_HA (r2off
) != 0)
11680 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11682 if (PPC_LO (r2off
) != 0)
11685 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11689 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11691 bfd_put_32 (obfd
, BCTR
, p
);
11695 case ppc_stub_long_branch_notoc
:
11696 case ppc_stub_long_branch_both
:
11697 case ppc_stub_plt_branch_notoc
:
11698 case ppc_stub_plt_branch_both
:
11699 case ppc_stub_plt_call_notoc
:
11700 case ppc_stub_plt_call_both
:
11702 off
= (stub_entry
->stub_offset
11703 + stub_entry
->group
->stub_sec
->output_offset
11704 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11705 obfd
= htab
->params
->stub_bfd
;
11706 is_tga
= ((stub_entry
->stub_type
== ppc_stub_plt_call_notoc
11707 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11708 && stub_entry
->h
!= NULL
11709 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11710 && htab
->params
->tls_get_addr_opt
);
11713 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
11716 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
11717 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
11718 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11721 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11724 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
11726 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11727 if (targ
>= (bfd_vma
) -2)
11730 plt
= htab
->elf
.splt
;
11731 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
11733 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11734 plt
= htab
->elf
.iplt
;
11736 plt
= htab
->pltlocal
;
11738 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11741 targ
= (stub_entry
->target_value
11742 + stub_entry
->target_section
->output_offset
11743 + stub_entry
->target_section
->output_section
->vma
);
11749 if (htab
->params
->power10_stubs
!= 0)
11751 bool load
= stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
;
11752 p
= build_power10_offset (obfd
, p
, off
, odd
, load
);
11756 if (htab
->glink_eh_frame
!= NULL
11757 && htab
->glink_eh_frame
->size
!= 0)
11759 bfd_byte
*base
, *eh
;
11760 unsigned int lr_used
, delta
;
11762 base
= (htab
->glink_eh_frame
->contents
11763 + stub_entry
->group
->eh_base
+ 17);
11764 eh
= base
+ stub_entry
->group
->eh_size
;
11765 lr_used
= stub_entry
->stub_offset
+ (p
- loc
) + 8;
11766 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11767 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11768 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11769 *eh
++ = DW_CFA_register
;
11772 *eh
++ = DW_CFA_advance_loc
+ 2;
11773 *eh
++ = DW_CFA_restore_extended
;
11775 stub_entry
->group
->eh_size
= eh
- base
;
11778 /* The notoc stubs calculate their target (either a PLT entry or
11779 the global entry point of a function) relative to the PC
11780 returned by the "bcl" two instructions past the start of the
11781 sequence emitted by build_offset. The offset is therefore 8
11782 less than calculated from the start of the sequence. */
11784 p
= build_offset (obfd
, p
, off
,
11785 stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
);
11788 if (stub_entry
->stub_type
<= ppc_stub_long_branch_both
)
11792 from
= (stub_entry
->stub_offset
11793 + stub_entry
->group
->stub_sec
->output_offset
11794 + stub_entry
->group
->stub_sec
->output_section
->vma
11796 bfd_put_32 (obfd
, B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
11800 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11802 bfd_put_32 (obfd
, BCTR
, p
);
11807 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
11809 if (info
->emitrelocations
)
11811 bfd_vma roff
= relp
- stub_entry
->group
->stub_sec
->contents
;
11812 if (htab
->params
->power10_stubs
!= 0)
11813 num_rel
+= num_relocs_for_power10_offset (off
, odd
);
11816 num_rel
+= num_relocs_for_offset (off
);
11819 r
= get_relocs (stub_entry
->group
->stub_sec
, num_rel
);
11822 if (htab
->params
->power10_stubs
!= 0)
11823 r
= emit_relocs_for_power10_offset (info
, r
, roff
, targ
, off
, odd
);
11825 r
= emit_relocs_for_offset (info
, r
, roff
, targ
, off
);
11826 if (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
11827 || stub_entry
->stub_type
== ppc_stub_long_branch_both
)
11830 roff
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11831 r
->r_offset
= roff
;
11832 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11833 r
->r_addend
= targ
;
11834 if (stub_entry
->h
!= NULL
11835 && !use_global_in_relocs (htab
, stub_entry
, r
, num_rel
))
11841 case ppc_stub_plt_call
:
11842 case ppc_stub_plt_call_r2save
:
11843 if (stub_entry
->h
!= NULL
11844 && stub_entry
->h
->is_func_descriptor
11845 && stub_entry
->h
->oh
!= NULL
)
11847 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11849 /* If the old-ABI "dot-symbol" is undefined make it weak so
11850 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11851 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11852 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11853 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11854 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11857 /* Now build the stub. */
11858 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11859 if (targ
>= (bfd_vma
) -2)
11862 plt
= htab
->elf
.splt
;
11863 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
11865 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11866 plt
= htab
->elf
.iplt
;
11868 plt
= htab
->pltlocal
;
11870 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11872 off
= (elf_gp (info
->output_bfd
)
11873 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11876 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11878 info
->callbacks
->einfo
11879 /* xgettext:c-format */
11880 (_("%P: linkage table error against `%pT'\n"),
11881 stub_entry
->h
!= NULL
11882 ? stub_entry
->h
->elf
.root
.root
.string
11884 bfd_set_error (bfd_error_bad_value
);
11885 htab
->stub_error
= true;
11890 if (info
->emitrelocations
)
11892 r
= get_relocs (stub_entry
->group
->stub_sec
,
11893 ((PPC_HA (off
) != 0)
11895 ? 2 + (htab
->params
->plt_static_chain
11896 && PPC_HA (off
+ 16) == PPC_HA (off
))
11900 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11901 if (bfd_big_endian (info
->output_bfd
))
11902 r
[0].r_offset
+= 2;
11903 r
[0].r_addend
= targ
;
11906 obfd
= htab
->params
->stub_bfd
;
11907 is_tga
= (stub_entry
->h
!= NULL
11908 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11909 && htab
->params
->tls_get_addr_opt
);
11912 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
11914 r
[0].r_offset
+= p
- loc
;
11916 p
= build_plt_stub (htab
, stub_entry
, p
, off
, r
);
11918 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
11921 case ppc_stub_save_res
:
11929 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
11931 if (htab
->params
->emit_stub_syms
)
11933 struct elf_link_hash_entry
*h
;
11936 const char *const stub_str
[] = { "long_branch",
11949 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11950 len2
= strlen (stub_entry
->root
.string
);
11951 name
= bfd_malloc (len1
+ len2
+ 2);
11954 memcpy (name
, stub_entry
->root
.string
, 9);
11955 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11956 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11957 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
11960 if (h
->root
.type
== bfd_link_hash_new
)
11962 h
->root
.type
= bfd_link_hash_defined
;
11963 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11964 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11965 h
->ref_regular
= 1;
11966 h
->def_regular
= 1;
11967 h
->ref_regular_nonweak
= 1;
11968 h
->forced_local
= 1;
11970 h
->root
.linker_def
= 1;
11977 /* As above, but don't actually build the stub. Just bump offset so
11978 we know stub section sizes, and select plt_branch stubs where
11979 long_branch stubs won't do. */
11982 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11984 struct ppc_stub_hash_entry
*stub_entry
;
11985 struct bfd_link_info
*info
;
11986 struct ppc_link_hash_table
*htab
;
11988 bfd_vma targ
, off
, r2off
;
11989 unsigned int size
, extra
, lr_used
, delta
, odd
;
11991 /* Massage our args to the form they really have. */
11992 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11995 htab
= ppc_hash_table (info
);
11999 /* Fail if the target section could not be assigned to an output
12000 section. The user should fix his linker script. */
12001 if (stub_entry
->target_section
!= NULL
12002 && stub_entry
->target_section
->output_section
== NULL
12003 && info
->non_contiguous_regions
)
12004 info
->callbacks
->einfo (_("%F%P: Could not assign %pA to an output section. "
12005 "Retry without --enable-non-contiguous-regions.\n"),
12006 stub_entry
->target_section
);
12008 /* Same for the group. */
12009 if (stub_entry
->group
->stub_sec
!= NULL
12010 && stub_entry
->group
->stub_sec
->output_section
== NULL
12011 && info
->non_contiguous_regions
)
12012 info
->callbacks
->einfo (_("%F%P: Could not assign group %pA target %pA to an "
12013 "output section. Retry without "
12014 "--enable-non-contiguous-regions.\n"),
12015 stub_entry
->group
->stub_sec
,
12016 stub_entry
->target_section
);
12018 /* Make a note of the offset within the stubs for this entry. */
12019 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12021 if (stub_entry
->h
!= NULL
12022 && stub_entry
->h
->save_res
12023 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
12024 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
12026 /* Don't make stubs to out-of-line register save/restore
12027 functions. Instead, emit copies of the functions. */
12028 stub_entry
->group
->needs_save_res
= 1;
12029 stub_entry
->stub_type
= ppc_stub_save_res
;
12033 switch (stub_entry
->stub_type
)
12035 case ppc_stub_plt_branch
:
12036 case ppc_stub_plt_branch_r2off
:
12037 /* Reset the stub type from the plt branch variant in case we now
12038 can reach with a shorter stub. */
12039 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
12040 /* Fall through. */
12041 case ppc_stub_long_branch
:
12042 case ppc_stub_long_branch_r2off
:
12043 targ
= (stub_entry
->target_value
12044 + stub_entry
->target_section
->output_offset
12045 + stub_entry
->target_section
->output_section
->vma
);
12046 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
12047 off
= (stub_entry
->stub_offset
12048 + stub_entry
->group
->stub_sec
->output_offset
12049 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12053 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
12055 r2off
= get_r2off (info
, stub_entry
);
12056 if (r2off
== (bfd_vma
) -1)
12058 htab
->stub_error
= true;
12062 if (PPC_HA (r2off
) != 0)
12064 if (PPC_LO (r2off
) != 0)
12070 /* If the branch offset is too big, use a ppc_stub_plt_branch.
12071 Do the same for -R objects without function descriptors. */
12072 if ((stub_entry
->stub_type
== ppc_stub_long_branch_r2off
12074 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
12075 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12077 struct ppc_branch_hash_entry
*br_entry
;
12079 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
12080 stub_entry
->root
.string
+ 9,
12082 if (br_entry
== NULL
)
12084 _bfd_error_handler (_("can't build branch stub `%s'"),
12085 stub_entry
->root
.string
);
12086 htab
->stub_error
= true;
12090 if (br_entry
->iter
!= htab
->stub_iteration
)
12092 br_entry
->iter
= htab
->stub_iteration
;
12093 br_entry
->offset
= htab
->brlt
->size
;
12094 htab
->brlt
->size
+= 8;
12096 if (htab
->relbrlt
!= NULL
)
12097 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
12098 else if (info
->emitrelocations
)
12100 htab
->brlt
->reloc_count
+= 1;
12101 htab
->brlt
->flags
|= SEC_RELOC
;
12105 targ
= (br_entry
->offset
12106 + htab
->brlt
->output_offset
12107 + htab
->brlt
->output_section
->vma
);
12108 off
= (elf_gp (info
->output_bfd
)
12109 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12112 if (info
->emitrelocations
)
12114 stub_entry
->group
->stub_sec
->reloc_count
12115 += 1 + (PPC_HA (off
) != 0);
12116 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12119 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
12120 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
12123 if (PPC_HA (off
) != 0)
12129 if (PPC_HA (off
) != 0)
12132 if (PPC_HA (r2off
) != 0)
12134 if (PPC_LO (r2off
) != 0)
12138 else if (info
->emitrelocations
)
12140 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
12141 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12145 case ppc_stub_plt_branch_notoc
:
12146 case ppc_stub_plt_branch_both
:
12147 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
12148 /* Fall through. */
12149 case ppc_stub_long_branch_notoc
:
12150 case ppc_stub_long_branch_both
:
12151 off
= (stub_entry
->stub_offset
12152 + stub_entry
->group
->stub_sec
->output_offset
12153 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12155 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
12158 targ
= (stub_entry
->target_value
12159 + stub_entry
->target_section
->output_offset
12160 + stub_entry
->target_section
->output_section
->vma
);
12164 if (info
->emitrelocations
)
12166 unsigned int num_rel
;
12167 if (htab
->params
->power10_stubs
!= 0)
12168 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12170 num_rel
= num_relocs_for_offset (off
- 8);
12171 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12172 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12175 if (htab
->params
->power10_stubs
!= 0)
12176 extra
= size_power10_offset (off
, odd
);
12178 extra
= size_offset (off
- 8);
12179 /* Include branch insn plus those in the offset sequence. */
12181 /* The branch insn is at the end, or "extra" bytes along. So
12182 its offset will be "extra" bytes less that that already
12186 if (htab
->params
->power10_stubs
== 0)
12188 /* After the bcl, lr has been modified so we need to emit
12189 .eh_frame info saying the return address is in r12. */
12190 lr_used
= stub_entry
->stub_offset
+ 8;
12191 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
12193 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12194 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12195 DW_CFA_restore_extended 65. */
12196 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12197 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12198 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12201 /* If the branch can't reach, use a plt_branch. */
12202 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12204 stub_entry
->stub_type
+= (ppc_stub_plt_branch_notoc
12205 - ppc_stub_long_branch_notoc
);
12208 else if (info
->emitrelocations
)
12209 stub_entry
->group
->stub_sec
->reloc_count
+=1;
12212 case ppc_stub_plt_call_notoc
:
12213 case ppc_stub_plt_call_both
:
12215 if (stub_entry
->h
!= NULL
12216 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12217 && htab
->params
->tls_get_addr_opt
)
12220 if (!htab
->params
->no_tls_get_addr_regsave
)
12222 else if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
12225 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
12227 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12228 if (targ
>= (bfd_vma
) -2)
12231 plt
= htab
->elf
.splt
;
12232 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12234 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12235 plt
= htab
->elf
.iplt
;
12237 plt
= htab
->pltlocal
;
12239 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12240 off
= (stub_entry
->stub_offset
12241 + stub_entry
->group
->stub_sec
->output_offset
12242 + stub_entry
->group
->stub_sec
->output_section
->vma
12247 if (htab
->params
->plt_stub_align
!= 0)
12249 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
, odd
);
12251 stub_entry
->group
->stub_sec
->size
+= pad
;
12252 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12257 if (info
->emitrelocations
)
12259 unsigned int num_rel
;
12260 if (htab
->params
->power10_stubs
!= 0)
12261 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12263 num_rel
= num_relocs_for_offset (off
- 8);
12264 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12265 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12268 size
= plt_stub_size (htab
, stub_entry
, off
, odd
);
12270 if (htab
->params
->power10_stubs
== 0)
12272 /* After the bcl, lr has been modified so we need to emit
12273 .eh_frame info saying the return address is in r12. */
12274 lr_used
+= stub_entry
->stub_offset
+ 8;
12275 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12276 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12277 DW_CFA_restore_extended 65. */
12278 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12279 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12280 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12282 if ((stub_entry
->stub_type
== ppc_stub_plt_call_notoc
12283 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
12284 && stub_entry
->h
!= NULL
12285 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12286 && htab
->params
->tls_get_addr_opt
)
12288 if (!htab
->params
->no_tls_get_addr_regsave
)
12290 unsigned int cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
12291 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12292 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12293 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12294 stub_entry
->group
->lr_restore
12295 = stub_entry
->stub_offset
+ size
- 4;
12297 else if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
12299 lr_used
= stub_entry
->stub_offset
+ size
- 20;
12300 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12301 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12302 stub_entry
->group
->lr_restore
12303 = stub_entry
->stub_offset
+ size
- 4;
12308 case ppc_stub_plt_call
:
12309 case ppc_stub_plt_call_r2save
:
12310 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
12311 if (targ
>= (bfd_vma
) -2)
12313 plt
= htab
->elf
.splt
;
12314 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12316 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12317 plt
= htab
->elf
.iplt
;
12319 plt
= htab
->pltlocal
;
12321 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12323 off
= (elf_gp (info
->output_bfd
)
12324 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12327 if (htab
->params
->plt_stub_align
!= 0)
12329 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
, 0);
12331 stub_entry
->group
->stub_sec
->size
+= pad
;
12332 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12335 if (info
->emitrelocations
)
12337 stub_entry
->group
->stub_sec
->reloc_count
12338 += ((PPC_HA (off
) != 0)
12340 ? 2 + (htab
->params
->plt_static_chain
12341 && PPC_HA (off
+ 16) == PPC_HA (off
))
12343 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12346 size
= plt_stub_size (htab
, stub_entry
, off
, 0);
12348 if (stub_entry
->h
!= NULL
12349 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12350 && htab
->params
->tls_get_addr_opt
12351 && stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
12353 if (!htab
->params
->no_tls_get_addr_regsave
)
12355 /* Adjustments to r1 need to be described. */
12356 unsigned int cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
12357 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12358 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12359 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12363 lr_used
= stub_entry
->stub_offset
+ size
- 20;
12364 /* The eh_frame info will consist of a DW_CFA_advance_loc
12365 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
12366 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
12367 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12368 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12370 stub_entry
->group
->lr_restore
= stub_entry
->stub_offset
+ size
- 4;
12379 stub_entry
->group
->stub_sec
->size
+= size
;
12383 /* Set up various things so that we can make a list of input sections
12384 for each output section included in the link. Returns -1 on error,
12385 0 when no stubs will be needed, and 1 on success. */
12388 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
12392 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12397 htab
->sec_info_arr_size
= _bfd_section_id
;
12398 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
12399 htab
->sec_info
= bfd_zmalloc (amt
);
12400 if (htab
->sec_info
== NULL
)
12403 /* Set toc_off for com, und, abs and ind sections. */
12404 for (id
= 0; id
< 3; id
++)
12405 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
12410 /* Set up for first pass at multitoc partitioning. */
12413 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
12415 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12417 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
12418 htab
->toc_bfd
= NULL
;
12419 htab
->toc_first_sec
= NULL
;
12422 /* The linker repeatedly calls this function for each TOC input section
12423 and linker generated GOT section. Group input bfds such that the toc
12424 within a group is less than 64k in size. */
12427 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
12429 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12430 bfd_vma addr
, off
, limit
;
12435 if (!htab
->second_toc_pass
)
12437 /* Keep track of the first .toc or .got section for this input bfd. */
12438 bool new_bfd
= htab
->toc_bfd
!= isec
->owner
;
12442 htab
->toc_bfd
= isec
->owner
;
12443 htab
->toc_first_sec
= isec
;
12446 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
12447 off
= addr
- htab
->toc_curr
;
12448 limit
= 0x80008000;
12449 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
12451 if (off
+ isec
->size
> limit
)
12453 addr
= (htab
->toc_first_sec
->output_offset
12454 + htab
->toc_first_sec
->output_section
->vma
);
12455 htab
->toc_curr
= addr
;
12456 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
12459 /* toc_curr is the base address of this toc group. Set elf_gp
12460 for the input section to be the offset relative to the
12461 output toc base plus 0x8000. Making the input elf_gp an
12462 offset allows us to move the toc as a whole without
12463 recalculating input elf_gp. */
12464 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
12465 off
+= TOC_BASE_OFF
;
12467 /* Die if someone uses a linker script that doesn't keep input
12468 file .toc and .got together. */
12470 && elf_gp (isec
->owner
) != 0
12471 && elf_gp (isec
->owner
) != off
)
12474 elf_gp (isec
->owner
) = off
;
12478 /* During the second pass toc_first_sec points to the start of
12479 a toc group, and toc_curr is used to track the old elf_gp.
12480 We use toc_bfd to ensure we only look at each bfd once. */
12481 if (htab
->toc_bfd
== isec
->owner
)
12483 htab
->toc_bfd
= isec
->owner
;
12485 if (htab
->toc_first_sec
== NULL
12486 || htab
->toc_curr
!= elf_gp (isec
->owner
))
12488 htab
->toc_curr
= elf_gp (isec
->owner
);
12489 htab
->toc_first_sec
= isec
;
12491 addr
= (htab
->toc_first_sec
->output_offset
12492 + htab
->toc_first_sec
->output_section
->vma
);
12493 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
12494 elf_gp (isec
->owner
) = off
;
12499 /* Called via elf_link_hash_traverse to merge GOT entries for global
12503 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
12505 if (h
->root
.type
== bfd_link_hash_indirect
)
12508 merge_got_entries (&h
->got
.glist
);
12513 /* Called via elf_link_hash_traverse to allocate GOT entries for global
12517 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
12519 struct got_entry
*gent
;
12521 if (h
->root
.type
== bfd_link_hash_indirect
)
12524 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
12525 if (!gent
->is_indirect
)
12526 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
12530 /* Called on the first multitoc pass after the last call to
12531 ppc64_elf_next_toc_section. This function removes duplicate GOT
12535 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
12537 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12538 struct bfd
*ibfd
, *ibfd2
;
12539 bool done_something
;
12541 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
12543 if (!htab
->do_multi_toc
)
12546 /* Merge global sym got entries within a toc group. */
12547 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
12549 /* And tlsld_got. */
12550 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12552 struct got_entry
*ent
, *ent2
;
12554 if (!is_ppc64_elf (ibfd
))
12557 ent
= ppc64_tlsld_got (ibfd
);
12558 if (!ent
->is_indirect
12559 && ent
->got
.offset
!= (bfd_vma
) -1)
12561 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
12563 if (!is_ppc64_elf (ibfd2
))
12566 ent2
= ppc64_tlsld_got (ibfd2
);
12567 if (!ent2
->is_indirect
12568 && ent2
->got
.offset
!= (bfd_vma
) -1
12569 && elf_gp (ibfd2
) == elf_gp (ibfd
))
12571 ent2
->is_indirect
= true;
12572 ent2
->got
.ent
= ent
;
12578 /* Zap sizes of got sections. */
12579 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
12580 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
12581 htab
->got_reli_size
= 0;
12583 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12585 asection
*got
, *relgot
;
12587 if (!is_ppc64_elf (ibfd
))
12590 got
= ppc64_elf_tdata (ibfd
)->got
;
12593 got
->rawsize
= got
->size
;
12595 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
12596 relgot
->rawsize
= relgot
->size
;
12601 /* Now reallocate the got, local syms first. We don't need to
12602 allocate section contents again since we never increase size. */
12603 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12605 struct got_entry
**lgot_ents
;
12606 struct got_entry
**end_lgot_ents
;
12607 struct plt_entry
**local_plt
;
12608 struct plt_entry
**end_local_plt
;
12609 unsigned char *lgot_masks
;
12610 bfd_size_type locsymcount
;
12611 Elf_Internal_Shdr
*symtab_hdr
;
12614 if (!is_ppc64_elf (ibfd
))
12617 lgot_ents
= elf_local_got_ents (ibfd
);
12621 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12622 locsymcount
= symtab_hdr
->sh_info
;
12623 end_lgot_ents
= lgot_ents
+ locsymcount
;
12624 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12625 end_local_plt
= local_plt
+ locsymcount
;
12626 lgot_masks
= (unsigned char *) end_local_plt
;
12627 s
= ppc64_elf_tdata (ibfd
)->got
;
12628 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
12630 struct got_entry
*ent
;
12632 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
12634 unsigned int ent_size
= 8;
12635 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
12637 ent
->got
.offset
= s
->size
;
12638 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
12643 s
->size
+= ent_size
;
12644 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
12646 htab
->elf
.irelplt
->size
+= rel_size
;
12647 htab
->got_reli_size
+= rel_size
;
12649 else if (bfd_link_pic (info
)
12650 && !(ent
->tls_type
!= 0
12651 && bfd_link_executable (info
)))
12653 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12654 srel
->size
+= rel_size
;
12660 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12662 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12664 struct got_entry
*ent
;
12666 if (!is_ppc64_elf (ibfd
))
12669 ent
= ppc64_tlsld_got (ibfd
);
12670 if (!ent
->is_indirect
12671 && ent
->got
.offset
!= (bfd_vma
) -1)
12673 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12674 ent
->got
.offset
= s
->size
;
12676 if (bfd_link_dll (info
))
12678 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12679 srel
->size
+= sizeof (Elf64_External_Rela
);
12684 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12685 if (!done_something
)
12686 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12690 if (!is_ppc64_elf (ibfd
))
12693 got
= ppc64_elf_tdata (ibfd
)->got
;
12696 done_something
= got
->rawsize
!= got
->size
;
12697 if (done_something
)
12702 if (done_something
)
12703 (*htab
->params
->layout_sections_again
) ();
12705 /* Set up for second pass over toc sections to recalculate elf_gp
12706 on input sections. */
12707 htab
->toc_bfd
= NULL
;
12708 htab
->toc_first_sec
= NULL
;
12709 htab
->second_toc_pass
= true;
12710 return done_something
;
12713 /* Called after second pass of multitoc partitioning. */
12716 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
12718 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12720 /* After the second pass, toc_curr tracks the TOC offset used
12721 for code sections below in ppc64_elf_next_input_section. */
12722 htab
->toc_curr
= TOC_BASE_OFF
;
12725 /* No toc references were found in ISEC. If the code in ISEC makes no
12726 calls, then there's no need to use toc adjusting stubs when branching
12727 into ISEC. Actually, indirect calls from ISEC are OK as they will
12728 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
12729 needed, and 2 if a cyclical call-graph was found but no other reason
12730 for a stub was detected. If called from the top level, a return of
12731 2 means the same as a return of 0. */
12734 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
12738 /* Mark this section as checked. */
12739 isec
->call_check_done
= 1;
12741 /* We know none of our code bearing sections will need toc stubs. */
12742 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
12745 if (isec
->size
== 0)
12748 if (isec
->output_section
== NULL
)
12752 if (isec
->reloc_count
!= 0)
12754 Elf_Internal_Rela
*relstart
, *rel
;
12755 Elf_Internal_Sym
*local_syms
;
12756 struct ppc_link_hash_table
*htab
;
12758 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
12759 info
->keep_memory
);
12760 if (relstart
== NULL
)
12763 /* Look for branches to outside of this section. */
12765 htab
= ppc_hash_table (info
);
12769 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
12771 enum elf_ppc64_reloc_type r_type
;
12772 unsigned long r_symndx
;
12773 struct elf_link_hash_entry
*h
;
12774 struct ppc_link_hash_entry
*eh
;
12775 Elf_Internal_Sym
*sym
;
12777 struct _opd_sec_data
*opd
;
12781 r_type
= ELF64_R_TYPE (rel
->r_info
);
12782 if (r_type
!= R_PPC64_REL24
12783 && r_type
!= R_PPC64_REL24_NOTOC
12784 && r_type
!= R_PPC64_REL14
12785 && r_type
!= R_PPC64_REL14_BRTAKEN
12786 && r_type
!= R_PPC64_REL14_BRNTAKEN
12787 && r_type
!= R_PPC64_PLTCALL
12788 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
12791 r_symndx
= ELF64_R_SYM (rel
->r_info
);
12792 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
12799 /* Calls to dynamic lib functions go through a plt call stub
12801 eh
= ppc_elf_hash_entry (h
);
12803 && (eh
->elf
.plt
.plist
!= NULL
12805 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12811 if (sym_sec
== NULL
)
12812 /* Ignore other undefined symbols. */
12815 /* Assume branches to other sections not included in the
12816 link need stubs too, to cover -R and absolute syms. */
12817 if (sym_sec
->output_section
== NULL
)
12824 sym_value
= sym
->st_value
;
12827 if (h
->root
.type
!= bfd_link_hash_defined
12828 && h
->root
.type
!= bfd_link_hash_defweak
)
12830 sym_value
= h
->root
.u
.def
.value
;
12832 sym_value
+= rel
->r_addend
;
12834 /* If this branch reloc uses an opd sym, find the code section. */
12835 opd
= get_opd_info (sym_sec
);
12838 if (h
== NULL
&& opd
->adjust
!= NULL
)
12842 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12844 /* Assume deleted functions won't ever be called. */
12846 sym_value
+= adjust
;
12849 dest
= opd_entry_value (sym_sec
, sym_value
,
12850 &sym_sec
, NULL
, false);
12851 if (dest
== (bfd_vma
) -1)
12856 + sym_sec
->output_offset
12857 + sym_sec
->output_section
->vma
);
12859 /* Ignore branch to self. */
12860 if (sym_sec
== isec
)
12863 /* If the called function uses the toc, we need a stub. */
12864 if (sym_sec
->has_toc_reloc
12865 || sym_sec
->makes_toc_func_call
)
12871 /* Assume any branch that needs a long branch stub might in fact
12872 need a plt_branch stub. A plt_branch stub uses r2. */
12873 else if (dest
- (isec
->output_offset
12874 + isec
->output_section
->vma
12875 + rel
->r_offset
) + (1 << 25)
12876 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
12884 /* If calling back to a section in the process of being
12885 tested, we can't say for sure that no toc adjusting stubs
12886 are needed, so don't return zero. */
12887 else if (sym_sec
->call_check_in_progress
)
12890 /* Branches to another section that itself doesn't have any TOC
12891 references are OK. Recursively call ourselves to check. */
12892 else if (!sym_sec
->call_check_done
)
12896 /* Mark current section as indeterminate, so that other
12897 sections that call back to current won't be marked as
12899 isec
->call_check_in_progress
= 1;
12900 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
12901 isec
->call_check_in_progress
= 0;
12912 if (elf_symtab_hdr (isec
->owner
).contents
12913 != (unsigned char *) local_syms
)
12915 if (elf_section_data (isec
)->relocs
!= relstart
)
12920 && isec
->map_head
.s
!= NULL
12921 && (strcmp (isec
->output_section
->name
, ".init") == 0
12922 || strcmp (isec
->output_section
->name
, ".fini") == 0))
12924 if (isec
->map_head
.s
->has_toc_reloc
12925 || isec
->map_head
.s
->makes_toc_func_call
)
12927 else if (!isec
->map_head
.s
->call_check_done
)
12930 isec
->call_check_in_progress
= 1;
12931 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
12932 isec
->call_check_in_progress
= 0;
12939 isec
->makes_toc_func_call
= 1;
12944 /* The linker repeatedly calls this function for each input section,
12945 in the order that input sections are linked into output sections.
12946 Build lists of input sections to determine groupings between which
12947 we may insert linker stubs. */
12950 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
12952 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12957 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
12958 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
12960 /* This happens to make the list in reverse order,
12961 which is what we want. */
12962 htab
->sec_info
[isec
->id
].u
.list
12963 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
12964 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
12967 if (htab
->multi_toc_needed
)
12969 /* Analyse sections that aren't already flagged as needing a
12970 valid toc pointer. Exclude .fixup for the linux kernel.
12971 .fixup contains branches, but only back to the function that
12972 hit an exception. */
12973 if (!(isec
->has_toc_reloc
12974 || (isec
->flags
& SEC_CODE
) == 0
12975 || strcmp (isec
->name
, ".fixup") == 0
12976 || isec
->call_check_done
))
12978 if (toc_adjusting_stub_needed (info
, isec
) < 0)
12981 /* Make all sections use the TOC assigned for this object file.
12982 This will be wrong for pasted sections; We fix that in
12983 check_pasted_section(). */
12984 if (elf_gp (isec
->owner
) != 0)
12985 htab
->toc_curr
= elf_gp (isec
->owner
);
12988 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
12992 /* Check that all .init and .fini sections use the same toc, if they
12993 have toc relocs. */
12996 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
12998 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
13002 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13003 bfd_vma toc_off
= 0;
13006 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13007 if (i
->has_toc_reloc
)
13010 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13011 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
13016 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13017 if (i
->makes_toc_func_call
)
13019 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13023 /* Make sure the whole pasted function uses the same toc offset. */
13025 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13026 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
13032 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
13034 return (check_pasted_section (info
, ".init")
13035 & check_pasted_section (info
, ".fini"));
13038 /* See whether we can group stub sections together. Grouping stub
13039 sections may result in fewer stubs. More importantly, we need to
13040 put all .init* and .fini* stubs at the beginning of the .init or
13041 .fini output sections respectively, because glibc splits the
13042 _init and _fini functions into multiple parts. Putting a stub in
13043 the middle of a function is not a good idea. */
13046 group_sections (struct bfd_link_info
*info
,
13047 bfd_size_type stub_group_size
,
13048 bool stubs_always_before_branch
)
13050 struct ppc_link_hash_table
*htab
;
13052 bool suppress_size_errors
;
13054 htab
= ppc_hash_table (info
);
13058 suppress_size_errors
= false;
13059 if (stub_group_size
== 1)
13061 /* Default values. */
13062 if (stubs_always_before_branch
)
13063 stub_group_size
= 0x1e00000;
13065 stub_group_size
= 0x1c00000;
13066 suppress_size_errors
= true;
13069 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
13073 if (osec
->id
>= htab
->sec_info_arr_size
)
13076 tail
= htab
->sec_info
[osec
->id
].u
.list
;
13077 while (tail
!= NULL
)
13081 bfd_size_type total
;
13084 struct map_stub
*group
;
13085 bfd_size_type group_size
;
13088 total
= tail
->size
;
13089 group_size
= (ppc64_elf_section_data (tail
) != NULL
13090 && ppc64_elf_section_data (tail
)->has_14bit_branch
13091 ? stub_group_size
>> 10 : stub_group_size
);
13093 big_sec
= total
> group_size
;
13094 if (big_sec
&& !suppress_size_errors
)
13095 /* xgettext:c-format */
13096 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
13097 tail
->owner
, tail
);
13098 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
13100 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
13101 && ((total
+= curr
->output_offset
- prev
->output_offset
)
13102 < (ppc64_elf_section_data (prev
) != NULL
13103 && ppc64_elf_section_data (prev
)->has_14bit_branch
13104 ? (group_size
= stub_group_size
>> 10) : group_size
))
13105 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13108 /* OK, the size from the start of CURR to the end is less
13109 than group_size and thus can be handled by one stub
13110 section. (or the tail section is itself larger than
13111 group_size, in which case we may be toast.) We should
13112 really be keeping track of the total size of stubs added
13113 here, as stubs contribute to the final output section
13114 size. That's a little tricky, and this way will only
13115 break if stubs added make the total size more than 2^25,
13116 ie. for the default stub_group_size, if stubs total more
13117 than 2097152 bytes, or nearly 75000 plt call stubs. */
13118 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
13121 group
->link_sec
= curr
;
13122 group
->stub_sec
= NULL
;
13123 group
->needs_save_res
= 0;
13124 group
->lr_restore
= 0;
13125 group
->eh_size
= 0;
13126 group
->eh_base
= 0;
13127 group
->next
= htab
->group
;
13128 htab
->group
= group
;
13131 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13132 /* Set up this stub group. */
13133 htab
->sec_info
[tail
->id
].u
.group
= group
;
13135 while (tail
!= curr
&& (tail
= prev
) != NULL
);
13137 /* But wait, there's more! Input sections up to group_size
13138 bytes before the stub section can be handled by it too.
13139 Don't do this if we have a really large section after the
13140 stubs, as adding more stubs increases the chance that
13141 branches may not reach into the stub section. */
13142 if (!stubs_always_before_branch
&& !big_sec
)
13145 while (prev
!= NULL
13146 && ((total
+= tail
->output_offset
- prev
->output_offset
)
13147 < (ppc64_elf_section_data (prev
) != NULL
13148 && ppc64_elf_section_data (prev
)->has_14bit_branch
13149 ? (group_size
= stub_group_size
>> 10)
13151 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13154 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13155 htab
->sec_info
[tail
->id
].u
.group
= group
;
13164 static const unsigned char glink_eh_frame_cie
[] =
13166 0, 0, 0, 16, /* length. */
13167 0, 0, 0, 0, /* id. */
13168 1, /* CIE version. */
13169 'z', 'R', 0, /* Augmentation string. */
13170 4, /* Code alignment. */
13171 0x78, /* Data alignment. */
13173 1, /* Augmentation size. */
13174 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
13175 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
13178 /* Stripping output sections is normally done before dynamic section
13179 symbols have been allocated. This function is called later, and
13180 handles cases like htab->brlt which is mapped to its own output
13184 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
13186 if (isec
->size
== 0
13187 && isec
->output_section
->size
== 0
13188 && !(isec
->output_section
->flags
& SEC_KEEP
)
13189 && !bfd_section_removed_from_list (info
->output_bfd
,
13190 isec
->output_section
)
13191 && elf_section_data (isec
->output_section
)->dynindx
== 0)
13193 isec
->output_section
->flags
|= SEC_EXCLUDE
;
13194 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
13195 info
->output_bfd
->section_count
--;
13199 /* Determine and set the size of the stub section for a final link.
13201 The basic idea here is to examine all the relocations looking for
13202 PC-relative calls to a target that is unreachable with a "bl"
13206 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
13208 bfd_size_type stub_group_size
;
13209 bool stubs_always_before_branch
;
13210 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13215 if (htab
->params
->power10_stubs
== -1 && !htab
->has_power10_relocs
)
13216 htab
->params
->power10_stubs
= 0;
13218 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
13219 htab
->params
->plt_thread_safe
= 1;
13220 if (!htab
->opd_abi
)
13221 htab
->params
->plt_thread_safe
= 0;
13222 else if (htab
->params
->plt_thread_safe
== -1)
13224 static const char *const thread_starter
[] =
13228 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
13230 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
13231 "mq_notify", "create_timer",
13236 "GOMP_parallel_start",
13237 "GOMP_parallel_loop_static",
13238 "GOMP_parallel_loop_static_start",
13239 "GOMP_parallel_loop_dynamic",
13240 "GOMP_parallel_loop_dynamic_start",
13241 "GOMP_parallel_loop_guided",
13242 "GOMP_parallel_loop_guided_start",
13243 "GOMP_parallel_loop_runtime",
13244 "GOMP_parallel_loop_runtime_start",
13245 "GOMP_parallel_sections",
13246 "GOMP_parallel_sections_start",
13252 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
13254 struct elf_link_hash_entry
*h
;
13255 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
13256 false, false, true);
13257 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
13258 if (htab
->params
->plt_thread_safe
)
13262 stubs_always_before_branch
= htab
->params
->group_size
< 0;
13263 if (htab
->params
->group_size
< 0)
13264 stub_group_size
= -htab
->params
->group_size
;
13266 stub_group_size
= htab
->params
->group_size
;
13268 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
13271 htab
->tga_group
= NULL
;
13272 if (!htab
->params
->no_tls_get_addr_regsave
13273 && htab
->tga_desc_fd
!= NULL
13274 && (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefined
13275 || htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefweak
)
13276 && htab
->tls_get_addr_fd
!= NULL
13277 && is_static_defined (&htab
->tls_get_addr_fd
->elf
))
13279 asection
*sym_sec
, *code_sec
, *stub_sec
;
13281 struct _opd_sec_data
*opd
;
13283 sym_sec
= htab
->tls_get_addr_fd
->elf
.root
.u
.def
.section
;
13284 sym_value
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
13285 code_sec
= sym_sec
;
13286 opd
= get_opd_info (sym_sec
);
13288 opd_entry_value (sym_sec
, sym_value
, &code_sec
, NULL
, false);
13289 htab
->tga_group
= htab
->sec_info
[code_sec
->id
].u
.group
;
13290 stub_sec
= (*htab
->params
->add_stub_section
) (".tga_desc.stub",
13291 htab
->tga_group
->link_sec
);
13292 if (stub_sec
== NULL
)
13294 htab
->tga_group
->stub_sec
= stub_sec
;
13296 htab
->tga_desc_fd
->elf
.root
.type
= bfd_link_hash_defined
;
13297 htab
->tga_desc_fd
->elf
.root
.u
.def
.section
= stub_sec
;
13298 htab
->tga_desc_fd
->elf
.root
.u
.def
.value
= 0;
13299 htab
->tga_desc_fd
->elf
.type
= STT_FUNC
;
13300 htab
->tga_desc_fd
->elf
.def_regular
= 1;
13301 htab
->tga_desc_fd
->elf
.non_elf
= 0;
13302 _bfd_elf_link_hash_hide_symbol (info
, &htab
->tga_desc_fd
->elf
, true);
13305 #define STUB_SHRINK_ITER 20
13306 /* Loop until no stubs added. After iteration 20 of this loop we may
13307 exit on a stub section shrinking. This is to break out of a
13308 pathological case where adding stubs on one iteration decreases
13309 section gaps (perhaps due to alignment), which then requires
13310 fewer or smaller stubs on the next iteration. */
13315 unsigned int bfd_indx
;
13316 struct map_stub
*group
;
13318 htab
->stub_iteration
+= 1;
13320 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
13322 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
13324 Elf_Internal_Shdr
*symtab_hdr
;
13326 Elf_Internal_Sym
*local_syms
= NULL
;
13328 if (!is_ppc64_elf (input_bfd
))
13331 /* We'll need the symbol table in a second. */
13332 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13333 if (symtab_hdr
->sh_info
== 0)
13336 /* Walk over each section attached to the input bfd. */
13337 for (section
= input_bfd
->sections
;
13339 section
= section
->next
)
13341 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
13343 /* If there aren't any relocs, then there's nothing more
13345 if ((section
->flags
& SEC_RELOC
) == 0
13346 || (section
->flags
& SEC_ALLOC
) == 0
13347 || (section
->flags
& SEC_LOAD
) == 0
13348 || (section
->flags
& SEC_CODE
) == 0
13349 || section
->reloc_count
== 0)
13352 /* If this section is a link-once section that will be
13353 discarded, then don't create any stubs. */
13354 if (section
->output_section
== NULL
13355 || section
->output_section
->owner
!= info
->output_bfd
)
13358 /* Get the relocs. */
13360 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
13361 info
->keep_memory
);
13362 if (internal_relocs
== NULL
)
13363 goto error_ret_free_local
;
13365 /* Now examine each relocation. */
13366 irela
= internal_relocs
;
13367 irelaend
= irela
+ section
->reloc_count
;
13368 for (; irela
< irelaend
; irela
++)
13370 enum elf_ppc64_reloc_type r_type
;
13371 unsigned int r_indx
;
13372 enum ppc_stub_type stub_type
;
13373 struct ppc_stub_hash_entry
*stub_entry
;
13374 asection
*sym_sec
, *code_sec
;
13375 bfd_vma sym_value
, code_value
;
13376 bfd_vma destination
;
13377 unsigned long local_off
;
13379 struct ppc_link_hash_entry
*hash
;
13380 struct ppc_link_hash_entry
*fdh
;
13381 struct elf_link_hash_entry
*h
;
13382 Elf_Internal_Sym
*sym
;
13384 const asection
*id_sec
;
13385 struct _opd_sec_data
*opd
;
13386 struct plt_entry
*plt_ent
;
13388 r_type
= ELF64_R_TYPE (irela
->r_info
);
13389 r_indx
= ELF64_R_SYM (irela
->r_info
);
13391 if (r_type
>= R_PPC64_max
)
13393 bfd_set_error (bfd_error_bad_value
);
13394 goto error_ret_free_internal
;
13397 /* Only look for stubs on branch instructions. */
13398 if (r_type
!= R_PPC64_REL24
13399 && r_type
!= R_PPC64_REL24_NOTOC
13400 && r_type
!= R_PPC64_REL14
13401 && r_type
!= R_PPC64_REL14_BRTAKEN
13402 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
13405 /* Now determine the call target, its name, value,
13407 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
13408 r_indx
, input_bfd
))
13409 goto error_ret_free_internal
;
13410 hash
= ppc_elf_hash_entry (h
);
13417 sym_value
= sym
->st_value
;
13418 if (sym_sec
!= NULL
13419 && sym_sec
->output_section
!= NULL
)
13422 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
13423 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
13425 sym_value
= hash
->elf
.root
.u
.def
.value
;
13426 if (sym_sec
->output_section
!= NULL
)
13429 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
13430 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
13432 /* Recognise an old ABI func code entry sym, and
13433 use the func descriptor sym instead if it is
13435 if (hash
->elf
.root
.root
.string
[0] == '.'
13436 && hash
->oh
!= NULL
)
13438 fdh
= ppc_follow_link (hash
->oh
);
13439 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
13440 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
13442 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
13443 sym_value
= fdh
->elf
.root
.u
.def
.value
;
13444 if (sym_sec
->output_section
!= NULL
)
13453 bfd_set_error (bfd_error_bad_value
);
13454 goto error_ret_free_internal
;
13461 sym_value
+= irela
->r_addend
;
13462 destination
= (sym_value
13463 + sym_sec
->output_offset
13464 + sym_sec
->output_section
->vma
);
13465 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
13470 code_sec
= sym_sec
;
13471 code_value
= sym_value
;
13472 opd
= get_opd_info (sym_sec
);
13477 if (hash
== NULL
&& opd
->adjust
!= NULL
)
13479 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13482 code_value
+= adjust
;
13483 sym_value
+= adjust
;
13485 dest
= opd_entry_value (sym_sec
, sym_value
,
13486 &code_sec
, &code_value
, false);
13487 if (dest
!= (bfd_vma
) -1)
13489 destination
= dest
;
13492 /* Fixup old ABI sym to point at code
13494 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
13495 hash
->elf
.root
.u
.def
.section
= code_sec
;
13496 hash
->elf
.root
.u
.def
.value
= code_value
;
13501 /* Determine what (if any) linker stub is needed. */
13503 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
13504 &plt_ent
, destination
,
13507 if (r_type
== R_PPC64_REL24_NOTOC
)
13509 if (stub_type
== ppc_stub_plt_call
)
13510 stub_type
= ppc_stub_plt_call_notoc
;
13511 else if (stub_type
== ppc_stub_long_branch
13512 || (code_sec
!= NULL
13513 && code_sec
->output_section
!= NULL
13514 && (((hash
? hash
->elf
.other
: sym
->st_other
)
13515 & STO_PPC64_LOCAL_MASK
)
13516 > 1 << STO_PPC64_LOCAL_BIT
)))
13517 stub_type
= ppc_stub_long_branch_notoc
;
13519 else if (stub_type
!= ppc_stub_plt_call
)
13521 /* Check whether we need a TOC adjusting stub.
13522 Since the linker pastes together pieces from
13523 different object files when creating the
13524 _init and _fini functions, it may be that a
13525 call to what looks like a local sym is in
13526 fact a call needing a TOC adjustment. */
13527 if ((code_sec
!= NULL
13528 && code_sec
->output_section
!= NULL
13529 && (code_sec
->has_toc_reloc
13530 || code_sec
->makes_toc_func_call
)
13531 && (htab
->sec_info
[code_sec
->id
].toc_off
13532 != htab
->sec_info
[section
->id
].toc_off
))
13533 || (((hash
? hash
->elf
.other
: sym
->st_other
)
13534 & STO_PPC64_LOCAL_MASK
)
13535 == 1 << STO_PPC64_LOCAL_BIT
))
13536 stub_type
= ppc_stub_long_branch_r2off
;
13539 if (stub_type
== ppc_stub_none
)
13542 /* __tls_get_addr calls might be eliminated. */
13543 if (stub_type
!= ppc_stub_plt_call
13544 && stub_type
!= ppc_stub_plt_call_notoc
13546 && is_tls_get_addr (&hash
->elf
, htab
)
13547 && section
->has_tls_reloc
13548 && irela
!= internal_relocs
)
13550 /* Get tls info. */
13551 unsigned char *tls_mask
;
13553 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
13554 irela
- 1, input_bfd
))
13555 goto error_ret_free_internal
;
13556 if ((*tls_mask
& TLS_TLS
) != 0
13557 && (*tls_mask
& (TLS_GD
| TLS_LD
)) == 0)
13561 if (stub_type
== ppc_stub_plt_call
)
13564 && htab
->params
->plt_localentry0
!= 0
13565 && is_elfv2_localentry0 (&hash
->elf
))
13566 htab
->has_plt_localentry0
= 1;
13567 else if (irela
+ 1 < irelaend
13568 && irela
[1].r_offset
== irela
->r_offset
+ 4
13569 && (ELF64_R_TYPE (irela
[1].r_info
)
13570 == R_PPC64_TOCSAVE
))
13572 if (!tocsave_find (htab
, INSERT
,
13573 &local_syms
, irela
+ 1, input_bfd
))
13574 goto error_ret_free_internal
;
13577 stub_type
= ppc_stub_plt_call_r2save
;
13580 /* Support for grouping stub sections. */
13581 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
13583 /* Get the name of this stub. */
13584 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
13586 goto error_ret_free_internal
;
13588 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
13589 stub_name
, false, false);
13590 if (stub_entry
!= NULL
)
13592 enum ppc_stub_type old_type
;
13594 /* A stub has already been created, but it may
13595 not be the required type. We shouldn't be
13596 transitioning from plt_call to long_branch
13597 stubs or vice versa, but we might be
13598 upgrading from plt_call to plt_call_r2save or
13599 from long_branch to long_branch_r2off. */
13601 if (htab
->params
->power10_stubs
== -1)
13603 /* For --power10-stubs=auto, don't merge _notoc
13604 and other varieties of stubs. (The _both
13605 variety won't be created.) */
13606 bool notoc
= r_type
== R_PPC64_REL24_NOTOC
;
13607 struct ppc_stub_hash_entry
*alt_stub
13608 = select_alt_stub (stub_entry
, notoc
);
13610 if (alt_stub
== NULL
)
13612 alt_stub
= (struct ppc_stub_hash_entry
*)
13613 stub_hash_newfunc (NULL
,
13614 &htab
->stub_hash_table
,
13615 stub_entry
->root
.string
);
13616 if (alt_stub
== NULL
)
13618 /* xgettext:c-format */
13620 (_("%pB: cannot create stub entry %s"),
13621 section
->owner
, stub_entry
->root
.string
);
13622 goto error_ret_free_internal
;
13624 *alt_stub
= *stub_entry
;
13625 stub_entry
->root
.next
= &alt_stub
->root
;
13627 /* Sort notoc stubs first, for no good
13629 alt_stub
= stub_entry
;
13630 alt_stub
->stub_type
= stub_type
;
13632 stub_entry
= alt_stub
;
13634 old_type
= stub_entry
->stub_type
;
13640 case ppc_stub_save_res
:
13643 case ppc_stub_plt_call
:
13644 case ppc_stub_plt_call_r2save
:
13645 case ppc_stub_plt_call_notoc
:
13646 case ppc_stub_plt_call_both
:
13647 if (stub_type
== ppc_stub_plt_call
)
13649 else if (stub_type
== ppc_stub_plt_call_r2save
)
13651 if (old_type
== ppc_stub_plt_call_notoc
)
13652 stub_type
= ppc_stub_plt_call_both
;
13654 else if (stub_type
== ppc_stub_plt_call_notoc
)
13656 if (old_type
== ppc_stub_plt_call_r2save
)
13657 stub_type
= ppc_stub_plt_call_both
;
13663 case ppc_stub_plt_branch
:
13664 case ppc_stub_plt_branch_r2off
:
13665 case ppc_stub_plt_branch_notoc
:
13666 case ppc_stub_plt_branch_both
:
13667 old_type
+= (ppc_stub_long_branch
13668 - ppc_stub_plt_branch
);
13669 /* Fall through. */
13670 case ppc_stub_long_branch
:
13671 case ppc_stub_long_branch_r2off
:
13672 case ppc_stub_long_branch_notoc
:
13673 case ppc_stub_long_branch_both
:
13674 if (stub_type
== ppc_stub_long_branch
)
13676 else if (stub_type
== ppc_stub_long_branch_r2off
)
13678 if (old_type
== ppc_stub_long_branch_notoc
)
13679 stub_type
= ppc_stub_long_branch_both
;
13681 else if (stub_type
== ppc_stub_long_branch_notoc
)
13683 if (old_type
== ppc_stub_long_branch_r2off
)
13684 stub_type
= ppc_stub_long_branch_both
;
13690 if (old_type
< stub_type
)
13691 stub_entry
->stub_type
= stub_type
;
13695 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
13696 if (stub_entry
== NULL
)
13699 error_ret_free_internal
:
13700 if (elf_section_data (section
)->relocs
== NULL
)
13701 free (internal_relocs
);
13702 error_ret_free_local
:
13703 if (symtab_hdr
->contents
13704 != (unsigned char *) local_syms
)
13709 stub_entry
->stub_type
= stub_type
;
13710 if (stub_type
>= ppc_stub_plt_call
13711 && stub_type
<= ppc_stub_plt_call_both
)
13713 stub_entry
->target_value
= sym_value
;
13714 stub_entry
->target_section
= sym_sec
;
13718 stub_entry
->target_value
= code_value
;
13719 stub_entry
->target_section
= code_sec
;
13721 stub_entry
->h
= hash
;
13722 stub_entry
->plt_ent
= plt_ent
;
13723 stub_entry
->symtype
13724 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
13725 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
13728 && (hash
->elf
.root
.type
== bfd_link_hash_defined
13729 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
13730 htab
->stub_globals
+= 1;
13733 /* We're done with the internal relocs, free them. */
13734 if (elf_section_data (section
)->relocs
!= internal_relocs
)
13735 free (internal_relocs
);
13738 if (local_syms
!= NULL
13739 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13741 if (!info
->keep_memory
)
13744 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13748 /* We may have added some stubs. Find out the new size of the
13750 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13752 group
->lr_restore
= 0;
13753 group
->eh_size
= 0;
13754 if (group
->stub_sec
!= NULL
)
13756 asection
*stub_sec
= group
->stub_sec
;
13758 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13759 || stub_sec
->rawsize
< stub_sec
->size
)
13760 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
13761 stub_sec
->rawsize
= stub_sec
->size
;
13762 stub_sec
->size
= 0;
13763 stub_sec
->reloc_count
= 0;
13764 stub_sec
->flags
&= ~SEC_RELOC
;
13767 if (htab
->tga_group
!= NULL
)
13769 /* See emit_tga_desc and emit_tga_desc_eh_frame. */
13770 htab
->tga_group
->eh_size
13771 = 1 + 2 + (htab
->opd_abi
!= 0) + 3 + 8 * 2 + 3 + 8 + 3;
13772 htab
->tga_group
->lr_restore
= 23 * 4;
13773 htab
->tga_group
->stub_sec
->size
= 24 * 4;
13776 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13777 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
13778 htab
->brlt
->rawsize
= htab
->brlt
->size
;
13779 htab
->brlt
->size
= 0;
13780 htab
->brlt
->reloc_count
= 0;
13781 htab
->brlt
->flags
&= ~SEC_RELOC
;
13782 if (htab
->relbrlt
!= NULL
)
13783 htab
->relbrlt
->size
= 0;
13785 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
13787 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13788 if (group
->needs_save_res
)
13789 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13791 if (info
->emitrelocations
13792 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13794 htab
->glink
->reloc_count
= 1;
13795 htab
->glink
->flags
|= SEC_RELOC
;
13798 if (htab
->glink_eh_frame
!= NULL
13799 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
13800 && htab
->glink_eh_frame
->output_section
->size
> 8)
13802 size_t size
= 0, align
= 4;
13804 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13805 if (group
->eh_size
!= 0)
13806 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
13807 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13808 size
+= (24 + align
- 1) & -align
;
13810 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
13811 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13812 size
= (size
+ align
- 1) & -align
;
13813 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
13814 htab
->glink_eh_frame
->size
= size
;
13817 if (htab
->params
->plt_stub_align
!= 0)
13818 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13819 if (group
->stub_sec
!= NULL
)
13821 int align
= abs (htab
->params
->plt_stub_align
);
13822 group
->stub_sec
->size
13823 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13826 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13827 if (group
->stub_sec
!= NULL
13828 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
13829 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13830 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
13834 && (htab
->brlt
->rawsize
== htab
->brlt
->size
13835 || (htab
->stub_iteration
> STUB_SHRINK_ITER
13836 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
13837 && (htab
->glink_eh_frame
== NULL
13838 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
)
13839 && (htab
->tga_group
== NULL
13840 || htab
->stub_iteration
> 1))
13843 /* Ask the linker to do its stuff. */
13844 (*htab
->params
->layout_sections_again
) ();
13847 if (htab
->glink_eh_frame
!= NULL
13848 && htab
->glink_eh_frame
->size
!= 0)
13851 bfd_byte
*p
, *last_fde
;
13852 size_t last_fde_len
, size
, align
, pad
;
13853 struct map_stub
*group
;
13855 /* It is necessary to at least have a rough outline of the
13856 linker generated CIEs and FDEs written before
13857 bfd_elf_discard_info is run, in order for these FDEs to be
13858 indexed in .eh_frame_hdr. */
13859 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
13862 htab
->glink_eh_frame
->contents
= p
;
13866 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
13867 /* CIE length (rewrite in case little-endian). */
13868 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
13869 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13870 p
+= last_fde_len
+ 4;
13872 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13873 if (group
->eh_size
!= 0)
13875 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
13877 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
13879 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13882 val
= p
- htab
->glink_eh_frame
->contents
;
13883 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13885 /* Offset to stub section, written later. */
13887 /* stub section size. */
13888 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
13890 /* Augmentation. */
13892 /* Make sure we don't have all nops. This is enough for
13893 elf-eh-frame.c to detect the last non-nop opcode. */
13894 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
13895 p
= last_fde
+ last_fde_len
+ 4;
13897 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13900 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
13902 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13905 val
= p
- htab
->glink_eh_frame
->contents
;
13906 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13908 /* Offset to .glink, written later. */
13911 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
13913 /* Augmentation. */
13916 *p
++ = DW_CFA_advance_loc
+ (htab
->has_plt_localentry0
? 3 : 2);
13917 *p
++ = DW_CFA_register
;
13919 *p
++ = htab
->opd_abi
? 12 : 0;
13920 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 4 : 2);
13921 *p
++ = DW_CFA_restore_extended
;
13923 p
+= ((24 + align
- 1) & -align
) - 24;
13925 /* Subsume any padding into the last FDE if user .eh_frame
13926 sections are aligned more than glink_eh_frame. Otherwise any
13927 zero padding will be seen as a terminator. */
13928 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13929 size
= p
- htab
->glink_eh_frame
->contents
;
13930 pad
= ((size
+ align
- 1) & -align
) - size
;
13931 htab
->glink_eh_frame
->size
= size
+ pad
;
13932 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
13935 maybe_strip_output (info
, htab
->brlt
);
13936 if (htab
->relbrlt
!= NULL
)
13937 maybe_strip_output (info
, htab
->relbrlt
);
13938 if (htab
->glink_eh_frame
!= NULL
)
13939 maybe_strip_output (info
, htab
->glink_eh_frame
);
13944 /* Called after we have determined section placement. If sections
13945 move, we'll be called again. Provide a value for TOCstart. */
13948 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
13951 bfd_vma TOCstart
, adjust
;
13955 struct elf_link_hash_entry
*h
;
13956 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
13958 if (is_elf_hash_table (&htab
->root
)
13959 && htab
->hgot
!= NULL
)
13963 h
= (struct elf_link_hash_entry
*)
13964 bfd_link_hash_lookup (&htab
->root
, ".TOC.", false, false, true);
13965 if (is_elf_hash_table (&htab
->root
))
13969 && h
->root
.type
== bfd_link_hash_defined
13970 && !h
->root
.linker_def
13971 && (!is_elf_hash_table (&htab
->root
)
13972 || h
->def_regular
))
13974 TOCstart
= defined_sym_val (h
) - TOC_BASE_OFF
;
13975 _bfd_set_gp_value (obfd
, TOCstart
);
13980 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
13981 order. The TOC starts where the first of these sections starts. */
13982 s
= bfd_get_section_by_name (obfd
, ".got");
13983 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13984 s
= bfd_get_section_by_name (obfd
, ".toc");
13985 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13986 s
= bfd_get_section_by_name (obfd
, ".tocbss");
13987 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13988 s
= bfd_get_section_by_name (obfd
, ".plt");
13989 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13991 /* This may happen for
13992 o references to TOC base (SYM@toc / TOC[tc0]) without a
13994 o bad linker script
13995 o --gc-sections and empty TOC sections
13997 FIXME: Warn user? */
13999 /* Look for a likely section. We probably won't even be
14001 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14002 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
14004 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14007 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14008 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
14009 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14012 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14013 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
14017 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14018 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
14024 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
14026 /* Force alignment. */
14027 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
14028 TOCstart
-= adjust
;
14029 _bfd_set_gp_value (obfd
, TOCstart
);
14031 if (info
!= NULL
&& s
!= NULL
)
14033 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14037 if (htab
->elf
.hgot
!= NULL
)
14039 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
14040 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
14045 struct bfd_link_hash_entry
*bh
= NULL
;
14046 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
14047 s
, TOC_BASE_OFF
- adjust
,
14048 NULL
, false, false, &bh
);
14054 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
14055 write out any global entry stubs, and PLT relocations. */
14058 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
14060 struct bfd_link_info
*info
;
14061 struct ppc_link_hash_table
*htab
;
14062 struct plt_entry
*ent
;
14065 if (h
->root
.type
== bfd_link_hash_indirect
)
14069 htab
= ppc_hash_table (info
);
14073 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14074 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14076 /* This symbol has an entry in the procedure linkage
14077 table. Set it up. */
14078 Elf_Internal_Rela rela
;
14079 asection
*plt
, *relplt
;
14082 if (use_local_plt (info
, h
))
14084 if (!(h
->def_regular
14085 && (h
->root
.type
== bfd_link_hash_defined
14086 || h
->root
.type
== bfd_link_hash_defweak
)))
14088 if (h
->type
== STT_GNU_IFUNC
)
14090 plt
= htab
->elf
.iplt
;
14091 relplt
= htab
->elf
.irelplt
;
14092 htab
->elf
.ifunc_resolvers
= true;
14094 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14096 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14100 plt
= htab
->pltlocal
;
14101 if (bfd_link_pic (info
))
14103 relplt
= htab
->relpltlocal
;
14105 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14107 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14112 rela
.r_addend
= defined_sym_val (h
) + ent
->addend
;
14114 if (relplt
== NULL
)
14116 loc
= plt
->contents
+ ent
->plt
.offset
;
14117 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
14120 bfd_vma toc
= elf_gp (info
->output_bfd
);
14121 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
14122 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14127 rela
.r_offset
= (plt
->output_section
->vma
14128 + plt
->output_offset
14129 + ent
->plt
.offset
);
14130 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14131 * sizeof (Elf64_External_Rela
));
14132 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14137 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
14138 + htab
->elf
.splt
->output_offset
14139 + ent
->plt
.offset
);
14140 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
14141 rela
.r_addend
= ent
->addend
;
14142 loc
= (htab
->elf
.srelplt
->contents
14143 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
14144 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
14145 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
14146 htab
->elf
.ifunc_resolvers
= true;
14147 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14151 if (!h
->pointer_equality_needed
)
14154 if (h
->def_regular
)
14157 s
= htab
->global_entry
;
14158 if (s
== NULL
|| s
->size
== 0)
14161 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14162 if (ent
->plt
.offset
!= (bfd_vma
) -1
14163 && ent
->addend
== 0)
14169 p
= s
->contents
+ h
->root
.u
.def
.value
;
14170 plt
= htab
->elf
.splt
;
14171 if (use_local_plt (info
, h
))
14173 if (h
->type
== STT_GNU_IFUNC
)
14174 plt
= htab
->elf
.iplt
;
14176 plt
= htab
->pltlocal
;
14178 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
14179 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
14181 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
14183 info
->callbacks
->einfo
14184 (_("%P: linkage table error against `%pT'\n"),
14185 h
->root
.root
.string
);
14186 bfd_set_error (bfd_error_bad_value
);
14187 htab
->stub_error
= true;
14190 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
14191 if (htab
->params
->emit_stub_syms
)
14193 size_t len
= strlen (h
->root
.root
.string
);
14194 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
14199 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
14200 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
14203 if (h
->root
.type
== bfd_link_hash_new
)
14205 h
->root
.type
= bfd_link_hash_defined
;
14206 h
->root
.u
.def
.section
= s
;
14207 h
->root
.u
.def
.value
= p
- s
->contents
;
14208 h
->ref_regular
= 1;
14209 h
->def_regular
= 1;
14210 h
->ref_regular_nonweak
= 1;
14211 h
->forced_local
= 1;
14213 h
->root
.linker_def
= 1;
14217 if (PPC_HA (off
) != 0)
14219 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
14222 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
14224 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
14226 bfd_put_32 (s
->owner
, BCTR
, p
);
14232 /* Write PLT relocs for locals. */
14235 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
14237 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14240 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
14242 struct got_entry
**lgot_ents
, **end_lgot_ents
;
14243 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
14244 Elf_Internal_Shdr
*symtab_hdr
;
14245 bfd_size_type locsymcount
;
14246 Elf_Internal_Sym
*local_syms
= NULL
;
14247 struct plt_entry
*ent
;
14249 if (!is_ppc64_elf (ibfd
))
14252 lgot_ents
= elf_local_got_ents (ibfd
);
14256 symtab_hdr
= &elf_symtab_hdr (ibfd
);
14257 locsymcount
= symtab_hdr
->sh_info
;
14258 end_lgot_ents
= lgot_ents
+ locsymcount
;
14259 local_plt
= (struct plt_entry
**) end_lgot_ents
;
14260 end_local_plt
= local_plt
+ locsymcount
;
14261 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
14262 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
14263 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14265 Elf_Internal_Sym
*sym
;
14267 asection
*plt
, *relplt
;
14271 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
14272 lplt
- local_plt
, ibfd
))
14274 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14279 val
= sym
->st_value
+ ent
->addend
;
14280 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
14281 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
14283 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14285 htab
->elf
.ifunc_resolvers
= true;
14286 plt
= htab
->elf
.iplt
;
14287 relplt
= htab
->elf
.irelplt
;
14291 plt
= htab
->pltlocal
;
14292 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
14295 if (relplt
== NULL
)
14297 loc
= plt
->contents
+ ent
->plt
.offset
;
14298 bfd_put_64 (info
->output_bfd
, val
, loc
);
14301 bfd_vma toc
= elf_gp (ibfd
);
14302 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14307 Elf_Internal_Rela rela
;
14308 rela
.r_offset
= (ent
->plt
.offset
14309 + plt
->output_offset
14310 + plt
->output_section
->vma
);
14311 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14314 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14316 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14321 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14323 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14325 rela
.r_addend
= val
;
14326 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14327 * sizeof (Elf64_External_Rela
));
14328 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14332 if (local_syms
!= NULL
14333 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14335 if (!info
->keep_memory
)
14338 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14344 /* Emit the static wrapper function preserving registers around a
14345 __tls_get_addr_opt call. */
14348 emit_tga_desc (struct ppc_link_hash_table
*htab
)
14350 asection
*stub_sec
= htab
->tga_group
->stub_sec
;
14351 unsigned int cfa_updt
= 11 * 4;
14353 bfd_vma to
, from
, delta
;
14355 BFD_ASSERT (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_defined
14356 && htab
->tga_desc_fd
->elf
.root
.u
.def
.section
== stub_sec
14357 && htab
->tga_desc_fd
->elf
.root
.u
.def
.value
== 0);
14358 to
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
14359 from
= defined_sym_val (&htab
->tga_desc_fd
->elf
) + cfa_updt
;
14361 if (delta
+ (1 << 25) >= 1 << 26)
14363 _bfd_error_handler (_("__tls_get_addr call offset overflow"));
14364 htab
->stub_error
= true;
14368 p
= stub_sec
->contents
;
14369 p
= tls_get_addr_prologue (htab
->elf
.dynobj
, p
, htab
);
14370 bfd_put_32 (stub_sec
->owner
, B_DOT
| 1 | (delta
& 0x3fffffc), p
);
14372 p
= tls_get_addr_epilogue (htab
->elf
.dynobj
, p
, htab
);
14373 return stub_sec
->size
== (bfd_size_type
) (p
- stub_sec
->contents
);
14376 /* Emit eh_frame describing the static wrapper function. */
14379 emit_tga_desc_eh_frame (struct ppc_link_hash_table
*htab
, bfd_byte
*p
)
14381 unsigned int cfa_updt
= 11 * 4;
14384 *p
++ = DW_CFA_advance_loc
+ cfa_updt
/ 4;
14385 *p
++ = DW_CFA_def_cfa_offset
;
14393 *p
++ = DW_CFA_offset_extended_sf
;
14395 *p
++ = (-16 / 8) & 0x7f;
14396 for (i
= 4; i
< 12; i
++)
14398 *p
++ = DW_CFA_offset
+ i
;
14399 *p
++ = (htab
->opd_abi
? 13 : 12) - i
;
14401 *p
++ = DW_CFA_advance_loc
+ 10;
14402 *p
++ = DW_CFA_def_cfa_offset
;
14404 for (i
= 4; i
< 12; i
++)
14405 *p
++ = DW_CFA_restore
+ i
;
14406 *p
++ = DW_CFA_advance_loc
+ 2;
14407 *p
++ = DW_CFA_restore_extended
;
14412 /* Build all the stubs associated with the current output file.
14413 The stubs are kept in a hash table attached to the main linker
14414 hash table. This function is called via gldelf64ppc_finish. */
14417 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
14420 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14421 struct map_stub
*group
;
14422 asection
*stub_sec
;
14424 int stub_sec_count
= 0;
14429 /* Allocate memory to hold the linker stubs. */
14430 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14432 group
->eh_size
= 0;
14433 group
->lr_restore
= 0;
14434 if ((stub_sec
= group
->stub_sec
) != NULL
14435 && stub_sec
->size
!= 0)
14437 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
14439 if (stub_sec
->contents
== NULL
)
14441 stub_sec
->size
= 0;
14445 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14450 /* Build the .glink plt call stub. */
14451 if (htab
->params
->emit_stub_syms
)
14453 struct elf_link_hash_entry
*h
;
14454 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
14455 true, false, false);
14458 if (h
->root
.type
== bfd_link_hash_new
)
14460 h
->root
.type
= bfd_link_hash_defined
;
14461 h
->root
.u
.def
.section
= htab
->glink
;
14462 h
->root
.u
.def
.value
= 8;
14463 h
->ref_regular
= 1;
14464 h
->def_regular
= 1;
14465 h
->ref_regular_nonweak
= 1;
14466 h
->forced_local
= 1;
14468 h
->root
.linker_def
= 1;
14471 plt0
= (htab
->elf
.splt
->output_section
->vma
14472 + htab
->elf
.splt
->output_offset
14474 if (info
->emitrelocations
)
14476 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
14479 r
->r_offset
= (htab
->glink
->output_offset
14480 + htab
->glink
->output_section
->vma
);
14481 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
14482 r
->r_addend
= plt0
;
14484 p
= htab
->glink
->contents
;
14485 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
14486 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
14490 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
14492 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14494 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14496 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
14498 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
14500 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
14502 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14504 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
14506 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14508 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
14516 . .quad plt0-1f # plt0 entry relative to 1:
14518 # We get here with r12 initially @ a glink branch
14519 # Load the address of _dl_runtime_resolve from plt0 and
14520 # jump to it, with r0 set to the index of the PLT entry
14521 # to be resolved and r11 the link map.
14522 __glink_PLTresolve:
14523 . std %r2,24(%r1) # optional
14529 . ld %r0,(0b-1b)(%r11)
14530 . sub %r12,%r12,%r11
14531 . add %r11,%r0,%r11
14532 . addi %r0,%r12,1b-2f
14539 . b __glink_PLTresolve
14541 . b __glink_PLTresolve */
14543 if (htab
->has_plt_localentry0
)
14545 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
14548 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
14550 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14552 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14554 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
14556 if (htab
->has_plt_localentry0
)
14557 insn
= LD_R0_0R11
| (-20 & 0xfffc);
14559 insn
= LD_R0_0R11
| (-16 & 0xfffc);
14560 bfd_put_32 (htab
->glink
->owner
, insn
, p
);
14562 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
14564 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R0_R11
, p
);
14566 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-44 & 0xffff), p
);
14568 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14570 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
14572 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14574 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
14577 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
14579 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
14581 /* Build the .glink lazy link call stubs. */
14583 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
14589 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
14594 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
14596 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
14601 bfd_put_32 (htab
->glink
->owner
,
14602 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
14608 if (htab
->tga_group
!= NULL
)
14610 htab
->tga_group
->lr_restore
= 23 * 4;
14611 htab
->tga_group
->stub_sec
->size
= 24 * 4;
14612 if (!emit_tga_desc (htab
))
14614 if (htab
->glink_eh_frame
!= NULL
14615 && htab
->glink_eh_frame
->size
!= 0)
14619 p
= htab
->glink_eh_frame
->contents
;
14620 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14622 htab
->tga_group
->eh_size
= emit_tga_desc_eh_frame (htab
, p
) - p
;
14626 /* Build .glink global entry stubs, and PLT relocs for globals. */
14627 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
14629 if (!write_plt_relocs_for_local_syms (info
))
14632 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
14634 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
14636 if (htab
->brlt
->contents
== NULL
)
14639 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
14641 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
14642 htab
->relbrlt
->size
);
14643 if (htab
->relbrlt
->contents
== NULL
)
14647 /* Build the stubs as directed by the stub hash table. */
14648 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
14650 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14651 if (group
->needs_save_res
)
14652 group
->stub_sec
->size
+= htab
->sfpr
->size
;
14654 if (htab
->relbrlt
!= NULL
)
14655 htab
->relbrlt
->reloc_count
= 0;
14657 if (htab
->params
->plt_stub_align
!= 0)
14658 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14659 if ((stub_sec
= group
->stub_sec
) != NULL
)
14661 int align
= abs (htab
->params
->plt_stub_align
);
14662 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
14665 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14666 if (group
->needs_save_res
)
14668 stub_sec
= group
->stub_sec
;
14669 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
14670 htab
->sfpr
->contents
, htab
->sfpr
->size
);
14671 if (htab
->params
->emit_stub_syms
)
14675 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
14676 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
14681 if (htab
->glink_eh_frame
!= NULL
14682 && htab
->glink_eh_frame
->size
!= 0)
14687 p
= htab
->glink_eh_frame
->contents
;
14688 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14690 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14691 if (group
->eh_size
!= 0)
14693 /* Offset to stub section. */
14694 val
= (group
->stub_sec
->output_section
->vma
14695 + group
->stub_sec
->output_offset
);
14696 val
-= (htab
->glink_eh_frame
->output_section
->vma
14697 + htab
->glink_eh_frame
->output_offset
14698 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
14699 if (val
+ 0x80000000 > 0xffffffff)
14702 (_("%s offset too large for .eh_frame sdata4 encoding"),
14703 group
->stub_sec
->name
);
14706 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
14707 p
+= (group
->eh_size
+ 17 + 3) & -4;
14709 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14711 /* Offset to .glink. */
14712 val
= (htab
->glink
->output_section
->vma
14713 + htab
->glink
->output_offset
14715 val
-= (htab
->glink_eh_frame
->output_section
->vma
14716 + htab
->glink_eh_frame
->output_offset
14717 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
14718 if (val
+ 0x80000000 > 0xffffffff)
14721 (_("%s offset too large for .eh_frame sdata4 encoding"),
14722 htab
->glink
->name
);
14725 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
14726 p
+= (24 + align
- 1) & -align
;
14730 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14731 if ((stub_sec
= group
->stub_sec
) != NULL
)
14733 stub_sec_count
+= 1;
14734 if (stub_sec
->rawsize
!= stub_sec
->size
14735 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
14736 || stub_sec
->rawsize
< stub_sec
->size
))
14742 htab
->stub_error
= true;
14743 _bfd_error_handler (_("stubs don't match calculated size"));
14746 if (htab
->stub_error
)
14752 if (asprintf (&groupmsg
,
14753 ngettext ("linker stubs in %u group\n",
14754 "linker stubs in %u groups\n",
14756 stub_sec_count
) < 0)
14760 if (asprintf (stats
, _("%s"
14762 " branch toc adj %lu\n"
14763 " branch notoc %lu\n"
14764 " branch both %lu\n"
14765 " long branch %lu\n"
14766 " long toc adj %lu\n"
14767 " long notoc %lu\n"
14770 " plt call save %lu\n"
14771 " plt call notoc %lu\n"
14772 " plt call both %lu\n"
14773 " global entry %lu"),
14775 htab
->stub_count
[ppc_stub_long_branch
- 1],
14776 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
14777 htab
->stub_count
[ppc_stub_long_branch_notoc
- 1],
14778 htab
->stub_count
[ppc_stub_long_branch_both
- 1],
14779 htab
->stub_count
[ppc_stub_plt_branch
- 1],
14780 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
14781 htab
->stub_count
[ppc_stub_plt_branch_notoc
- 1],
14782 htab
->stub_count
[ppc_stub_plt_branch_both
- 1],
14783 htab
->stub_count
[ppc_stub_plt_call
- 1],
14784 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
14785 htab
->stub_count
[ppc_stub_plt_call_notoc
- 1],
14786 htab
->stub_count
[ppc_stub_plt_call_both
- 1],
14787 htab
->stub_count
[ppc_stub_global_entry
- 1]) < 0)
14795 /* What to do when ld finds relocations against symbols defined in
14796 discarded sections. */
14798 static unsigned int
14799 ppc64_elf_action_discarded (asection
*sec
)
14801 if (strcmp (".opd", sec
->name
) == 0)
14804 if (strcmp (".toc", sec
->name
) == 0)
14807 if (strcmp (".toc1", sec
->name
) == 0)
14810 return _bfd_elf_default_action_discarded (sec
);
14813 /* These are the dynamic relocations supported by glibc. */
14816 ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type
)
14820 case R_PPC64_RELATIVE
:
14822 case R_PPC64_ADDR64
:
14823 case R_PPC64_GLOB_DAT
:
14824 case R_PPC64_IRELATIVE
:
14825 case R_PPC64_JMP_IREL
:
14826 case R_PPC64_JMP_SLOT
:
14827 case R_PPC64_DTPMOD64
:
14828 case R_PPC64_DTPREL64
:
14829 case R_PPC64_TPREL64
:
14830 case R_PPC64_TPREL16_LO_DS
:
14831 case R_PPC64_TPREL16_DS
:
14832 case R_PPC64_TPREL16
:
14833 case R_PPC64_TPREL16_LO
:
14834 case R_PPC64_TPREL16_HI
:
14835 case R_PPC64_TPREL16_HIGH
:
14836 case R_PPC64_TPREL16_HA
:
14837 case R_PPC64_TPREL16_HIGHA
:
14838 case R_PPC64_TPREL16_HIGHER
:
14839 case R_PPC64_TPREL16_HIGHEST
:
14840 case R_PPC64_TPREL16_HIGHERA
:
14841 case R_PPC64_TPREL16_HIGHESTA
:
14842 case R_PPC64_ADDR16_LO_DS
:
14843 case R_PPC64_ADDR16_LO
:
14844 case R_PPC64_ADDR16_HI
:
14845 case R_PPC64_ADDR16_HIGH
:
14846 case R_PPC64_ADDR16_HA
:
14847 case R_PPC64_ADDR16_HIGHA
:
14848 case R_PPC64_REL30
:
14850 case R_PPC64_UADDR64
:
14851 case R_PPC64_UADDR32
:
14852 case R_PPC64_ADDR32
:
14853 case R_PPC64_ADDR24
:
14854 case R_PPC64_ADDR16
:
14855 case R_PPC64_UADDR16
:
14856 case R_PPC64_ADDR16_DS
:
14857 case R_PPC64_ADDR16_HIGHER
:
14858 case R_PPC64_ADDR16_HIGHEST
:
14859 case R_PPC64_ADDR16_HIGHERA
:
14860 case R_PPC64_ADDR16_HIGHESTA
:
14861 case R_PPC64_ADDR14
:
14862 case R_PPC64_ADDR14_BRTAKEN
:
14863 case R_PPC64_ADDR14_BRNTAKEN
:
14864 case R_PPC64_REL32
:
14865 case R_PPC64_REL64
:
14873 /* The RELOCATE_SECTION function is called by the ELF backend linker
14874 to handle the relocations for a section.
14876 The relocs are always passed as Rela structures; if the section
14877 actually uses Rel structures, the r_addend field will always be
14880 This function is responsible for adjust the section contents as
14881 necessary, and (if using Rela relocs and generating a
14882 relocatable output file) adjusting the reloc addend as
14885 This function does not have to worry about setting the reloc
14886 address or the reloc symbol index.
14888 LOCAL_SYMS is a pointer to the swapped in local symbols.
14890 LOCAL_SECTIONS is an array giving the section in the input file
14891 corresponding to the st_shndx field of each local symbol.
14893 The global hash table entry for the global symbols can be found
14894 via elf_sym_hashes (input_bfd).
14896 When generating relocatable output, this function must handle
14897 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
14898 going to be the section symbol corresponding to the output
14899 section, which means that the addend must be adjusted
14903 ppc64_elf_relocate_section (bfd
*output_bfd
,
14904 struct bfd_link_info
*info
,
14906 asection
*input_section
,
14907 bfd_byte
*contents
,
14908 Elf_Internal_Rela
*relocs
,
14909 Elf_Internal_Sym
*local_syms
,
14910 asection
**local_sections
)
14912 struct ppc_link_hash_table
*htab
;
14913 Elf_Internal_Shdr
*symtab_hdr
;
14914 struct elf_link_hash_entry
**sym_hashes
;
14915 Elf_Internal_Rela
*rel
;
14916 Elf_Internal_Rela
*wrel
;
14917 Elf_Internal_Rela
*relend
;
14918 Elf_Internal_Rela outrel
;
14920 struct got_entry
**local_got_ents
;
14924 /* Assume 'at' branch hints. */
14925 bool is_isa_v2
= true;
14926 bool warned_dynamic
= false;
14927 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
14929 /* Initialize howto table if needed. */
14930 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
14933 htab
= ppc_hash_table (info
);
14937 /* Don't relocate stub sections. */
14938 if (input_section
->owner
== htab
->params
->stub_bfd
)
14941 if (!is_ppc64_elf (input_bfd
))
14943 bfd_set_error (bfd_error_wrong_format
);
14947 local_got_ents
= elf_local_got_ents (input_bfd
);
14948 TOCstart
= elf_gp (output_bfd
);
14949 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
14950 sym_hashes
= elf_sym_hashes (input_bfd
);
14951 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
14953 rel
= wrel
= relocs
;
14954 relend
= relocs
+ input_section
->reloc_count
;
14955 for (; rel
< relend
; wrel
++, rel
++)
14957 enum elf_ppc64_reloc_type r_type
;
14959 bfd_reloc_status_type r
;
14960 Elf_Internal_Sym
*sym
;
14962 struct elf_link_hash_entry
*h_elf
;
14963 struct ppc_link_hash_entry
*h
;
14964 struct ppc_link_hash_entry
*fdh
;
14965 const char *sym_name
;
14966 unsigned long r_symndx
, toc_symndx
;
14967 bfd_vma toc_addend
;
14968 unsigned char tls_mask
, tls_gd
, tls_type
;
14969 unsigned char sym_type
;
14970 bfd_vma relocation
;
14971 bool unresolved_reloc
, save_unresolved_reloc
;
14973 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
14976 struct ppc_stub_hash_entry
*stub_entry
;
14977 bfd_vma max_br_offset
;
14979 Elf_Internal_Rela orig_rel
;
14980 reloc_howto_type
*howto
;
14981 struct reloc_howto_struct alt_howto
;
14988 r_type
= ELF64_R_TYPE (rel
->r_info
);
14989 r_symndx
= ELF64_R_SYM (rel
->r_info
);
14991 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
14992 symbol of the previous ADDR64 reloc. The symbol gives us the
14993 proper TOC base to use. */
14994 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
14996 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
14998 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
15004 unresolved_reloc
= false;
15007 if (r_symndx
< symtab_hdr
->sh_info
)
15009 /* It's a local symbol. */
15010 struct _opd_sec_data
*opd
;
15012 sym
= local_syms
+ r_symndx
;
15013 sec
= local_sections
[r_symndx
];
15014 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
15015 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
15016 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
15017 opd
= get_opd_info (sec
);
15018 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
15020 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
15026 /* If this is a relocation against the opd section sym
15027 and we have edited .opd, adjust the reloc addend so
15028 that ld -r and ld --emit-relocs output is correct.
15029 If it is a reloc against some other .opd symbol,
15030 then the symbol value will be adjusted later. */
15031 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
15032 rel
->r_addend
+= adjust
;
15034 relocation
+= adjust
;
15042 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
15043 r_symndx
, symtab_hdr
, sym_hashes
,
15044 h_elf
, sec
, relocation
,
15045 unresolved_reloc
, warned
, ignored
);
15046 sym_name
= h_elf
->root
.root
.string
;
15047 sym_type
= h_elf
->type
;
15049 && sec
->owner
== output_bfd
15050 && strcmp (sec
->name
, ".opd") == 0)
15052 /* This is a symbol defined in a linker script. All
15053 such are defined in output sections, even those
15054 defined by simple assignment from a symbol defined in
15055 an input section. Transfer the symbol to an
15056 appropriate input .opd section, so that a branch to
15057 this symbol will be mapped to the location specified
15058 by the opd entry. */
15059 struct bfd_link_order
*lo
;
15060 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
15061 if (lo
->type
== bfd_indirect_link_order
)
15063 asection
*isec
= lo
->u
.indirect
.section
;
15064 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
15065 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
15068 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
15069 h_elf
->root
.u
.def
.section
= isec
;
15076 h
= ppc_elf_hash_entry (h_elf
);
15078 if (sec
!= NULL
&& discarded_section (sec
))
15080 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
15081 input_bfd
, input_section
,
15082 contents
, rel
->r_offset
);
15083 wrel
->r_offset
= rel
->r_offset
;
15085 wrel
->r_addend
= 0;
15087 /* For ld -r, remove relocations in debug sections against
15088 symbols defined in discarded sections. Not done for
15089 non-debug to preserve relocs in .eh_frame which the
15090 eh_frame editing code expects to be present. */
15091 if (bfd_link_relocatable (info
)
15092 && (input_section
->flags
& SEC_DEBUGGING
))
15098 if (bfd_link_relocatable (info
))
15101 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
15103 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15104 sec
= bfd_abs_section_ptr
;
15105 unresolved_reloc
= false;
15108 /* TLS optimizations. Replace instruction sequences and relocs
15109 based on information we collected in tls_optimize. We edit
15110 RELOCS so that --emit-relocs will output something sensible
15111 for the final instruction stream. */
15116 tls_mask
= h
->tls_mask
;
15117 else if (local_got_ents
!= NULL
)
15119 struct plt_entry
**local_plt
= (struct plt_entry
**)
15120 (local_got_ents
+ symtab_hdr
->sh_info
);
15121 unsigned char *lgot_masks
= (unsigned char *)
15122 (local_plt
+ symtab_hdr
->sh_info
);
15123 tls_mask
= lgot_masks
[r_symndx
];
15125 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
15126 && (r_type
== R_PPC64_TLS
15127 || r_type
== R_PPC64_TLSGD
15128 || r_type
== R_PPC64_TLSLD
))
15130 /* Check for toc tls entries. */
15131 unsigned char *toc_tls
;
15133 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15134 &local_syms
, rel
, input_bfd
))
15138 tls_mask
= *toc_tls
;
15141 /* Check that tls relocs are used with tls syms, and non-tls
15142 relocs are used with non-tls syms. */
15143 if (r_symndx
!= STN_UNDEF
15144 && r_type
!= R_PPC64_NONE
15146 || h
->elf
.root
.type
== bfd_link_hash_defined
15147 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
15148 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
15150 if ((tls_mask
& TLS_TLS
) != 0
15151 && (r_type
== R_PPC64_TLS
15152 || r_type
== R_PPC64_TLSGD
15153 || r_type
== R_PPC64_TLSLD
))
15154 /* R_PPC64_TLS is OK against a symbol in the TOC. */
15157 info
->callbacks
->einfo
15158 (!IS_PPC64_TLS_RELOC (r_type
)
15159 /* xgettext:c-format */
15160 ? _("%H: %s used with TLS symbol `%pT'\n")
15161 /* xgettext:c-format */
15162 : _("%H: %s used with non-TLS symbol `%pT'\n"),
15163 input_bfd
, input_section
, rel
->r_offset
,
15164 ppc64_elf_howto_table
[r_type
]->name
,
15168 /* Ensure reloc mapping code below stays sane. */
15169 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
15170 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
15171 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
15172 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
15173 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
15174 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
15175 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
15176 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
15177 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
15178 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
15186 case R_PPC64_LO_DS_OPT
:
15187 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
15188 if ((insn
& (0x3fu
<< 26)) != 58u << 26)
15190 insn
+= (14u << 26) - (58u << 26);
15191 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
15192 r_type
= R_PPC64_TOC16_LO
;
15193 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15196 case R_PPC64_TOC16
:
15197 case R_PPC64_TOC16_LO
:
15198 case R_PPC64_TOC16_DS
:
15199 case R_PPC64_TOC16_LO_DS
:
15201 /* Check for toc tls entries. */
15202 unsigned char *toc_tls
;
15205 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15206 &local_syms
, rel
, input_bfd
);
15212 tls_mask
= *toc_tls
;
15213 if (r_type
== R_PPC64_TOC16_DS
15214 || r_type
== R_PPC64_TOC16_LO_DS
)
15216 if ((tls_mask
& TLS_TLS
) != 0
15217 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
15222 /* If we found a GD reloc pair, then we might be
15223 doing a GD->IE transition. */
15227 if ((tls_mask
& TLS_TLS
) != 0
15228 && (tls_mask
& TLS_GD
) == 0)
15231 else if (retval
== 3)
15233 if ((tls_mask
& TLS_TLS
) != 0
15234 && (tls_mask
& TLS_LD
) == 0)
15242 case R_PPC64_GOT_TPREL16_HI
:
15243 case R_PPC64_GOT_TPREL16_HA
:
15244 if ((tls_mask
& TLS_TLS
) != 0
15245 && (tls_mask
& TLS_TPREL
) == 0)
15247 rel
->r_offset
-= d_offset
;
15248 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15249 r_type
= R_PPC64_NONE
;
15250 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15254 case R_PPC64_GOT_TPREL16_DS
:
15255 case R_PPC64_GOT_TPREL16_LO_DS
:
15256 if ((tls_mask
& TLS_TLS
) != 0
15257 && (tls_mask
& TLS_TPREL
) == 0)
15260 insn
= bfd_get_32 (input_bfd
,
15261 contents
+ rel
->r_offset
- d_offset
);
15263 insn
|= 0x3c0d0000; /* addis 0,13,0 */
15264 bfd_put_32 (input_bfd
, insn
,
15265 contents
+ rel
->r_offset
- d_offset
);
15266 r_type
= R_PPC64_TPREL16_HA
;
15267 if (toc_symndx
!= 0)
15269 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15270 rel
->r_addend
= toc_addend
;
15271 /* We changed the symbol. Start over in order to
15272 get h, sym, sec etc. right. */
15276 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15280 case R_PPC64_GOT_TPREL_PCREL34
:
15281 if ((tls_mask
& TLS_TLS
) != 0
15282 && (tls_mask
& TLS_TPREL
) == 0)
15284 /* pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel */
15285 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15287 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15288 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
15289 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
15290 bfd_put_32 (input_bfd
, pinsn
>> 32,
15291 contents
+ rel
->r_offset
);
15292 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15293 contents
+ rel
->r_offset
+ 4);
15294 r_type
= R_PPC64_TPREL34
;
15295 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15300 if ((tls_mask
& TLS_TLS
) != 0
15301 && (tls_mask
& TLS_TPREL
) == 0)
15303 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15304 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
15307 if ((rel
->r_offset
& 3) == 0)
15309 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15310 /* Was PPC64_TLS which sits on insn boundary, now
15311 PPC64_TPREL16_LO which is at low-order half-word. */
15312 rel
->r_offset
+= d_offset
;
15313 r_type
= R_PPC64_TPREL16_LO
;
15314 if (toc_symndx
!= 0)
15316 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15317 rel
->r_addend
= toc_addend
;
15318 /* We changed the symbol. Start over in order to
15319 get h, sym, sec etc. right. */
15323 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15325 else if ((rel
->r_offset
& 3) == 1)
15327 /* For pcrel IE to LE we already have the full
15328 offset and thus don't need an addi here. A nop
15330 if ((insn
& (0x3fu
<< 26)) == 14 << 26)
15332 /* Extract regs from addi rt,ra,si. */
15333 unsigned int rt
= (insn
>> 21) & 0x1f;
15334 unsigned int ra
= (insn
>> 16) & 0x1f;
15339 /* Build or ra,rs,rb with rb==rs, ie. mr ra,rs. */
15340 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
15341 insn
|= (31u << 26) | (444u << 1);
15344 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- 1);
15349 case R_PPC64_GOT_TLSGD16_HI
:
15350 case R_PPC64_GOT_TLSGD16_HA
:
15352 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
15356 case R_PPC64_GOT_TLSLD16_HI
:
15357 case R_PPC64_GOT_TLSLD16_HA
:
15358 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
15361 if ((tls_mask
& tls_gd
) != 0)
15362 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
15363 + R_PPC64_GOT_TPREL16_DS
);
15366 rel
->r_offset
-= d_offset
;
15367 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15368 r_type
= R_PPC64_NONE
;
15370 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15374 case R_PPC64_GOT_TLSGD16
:
15375 case R_PPC64_GOT_TLSGD16_LO
:
15377 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
15381 case R_PPC64_GOT_TLSLD16
:
15382 case R_PPC64_GOT_TLSLD16_LO
:
15383 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
15385 unsigned int insn1
, insn2
;
15388 offset
= (bfd_vma
) -1;
15389 /* If not using the newer R_PPC64_TLSGD/LD to mark
15390 __tls_get_addr calls, we must trust that the call
15391 stays with its arg setup insns, ie. that the next
15392 reloc is the __tls_get_addr call associated with
15393 the current reloc. Edit both insns. */
15394 if (input_section
->nomark_tls_get_addr
15395 && rel
+ 1 < relend
15396 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
15397 htab
->tls_get_addr_fd
,
15399 htab
->tls_get_addr
,
15401 offset
= rel
[1].r_offset
;
15402 /* We read the low GOT_TLS (or TOC16) insn because we
15403 need to keep the destination reg. It may be
15404 something other than the usual r3, and moved to r3
15405 before the call by intervening code. */
15406 insn1
= bfd_get_32 (input_bfd
,
15407 contents
+ rel
->r_offset
- d_offset
);
15408 if ((tls_mask
& tls_gd
) != 0)
15411 insn1
&= (0x1f << 21) | (0x1f << 16);
15412 insn1
|= 58u << 26; /* ld */
15413 insn2
= 0x7c636a14; /* add 3,3,13 */
15414 if (offset
!= (bfd_vma
) -1)
15415 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15416 if (r_type
== R_PPC64_TOC16
15417 || r_type
== R_PPC64_TOC16_LO
)
15418 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
15420 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 1)) & 1)
15421 + R_PPC64_GOT_TPREL16_DS
);
15422 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15427 insn1
&= 0x1f << 21;
15428 insn1
|= 0x3c0d0000; /* addis r,13,0 */
15429 insn2
= 0x38630000; /* addi 3,3,0 */
15432 /* Was an LD reloc. */
15433 r_symndx
= STN_UNDEF
;
15434 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15436 else if (toc_symndx
!= 0)
15438 r_symndx
= toc_symndx
;
15439 rel
->r_addend
= toc_addend
;
15441 r_type
= R_PPC64_TPREL16_HA
;
15442 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15443 if (offset
!= (bfd_vma
) -1)
15445 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
15446 R_PPC64_TPREL16_LO
);
15447 rel
[1].r_offset
= offset
+ d_offset
;
15448 rel
[1].r_addend
= rel
->r_addend
;
15451 bfd_put_32 (input_bfd
, insn1
,
15452 contents
+ rel
->r_offset
- d_offset
);
15453 if (offset
!= (bfd_vma
) -1)
15455 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15456 if (offset
+ 8 <= input_section
->size
)
15458 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15459 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
15460 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
15463 if ((tls_mask
& tls_gd
) == 0
15464 && (tls_gd
== 0 || toc_symndx
!= 0))
15466 /* We changed the symbol. Start over in order
15467 to get h, sym, sec etc. right. */
15473 case R_PPC64_GOT_TLSGD_PCREL34
:
15474 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
15476 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15478 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15479 if ((tls_mask
& TLS_GDIE
) != 0)
15481 /* IE, pla -> pld */
15482 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
15483 r_type
= R_PPC64_GOT_TPREL_PCREL34
;
15487 /* LE, pla pcrel -> paddi r13 */
15488 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15489 r_type
= R_PPC64_TPREL34
;
15491 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15492 bfd_put_32 (input_bfd
, pinsn
>> 32,
15493 contents
+ rel
->r_offset
);
15494 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15495 contents
+ rel
->r_offset
+ 4);
15499 case R_PPC64_GOT_TLSLD_PCREL34
:
15500 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
15502 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15504 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15505 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15506 bfd_put_32 (input_bfd
, pinsn
>> 32,
15507 contents
+ rel
->r_offset
);
15508 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15509 contents
+ rel
->r_offset
+ 4);
15510 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15511 r_symndx
= STN_UNDEF
;
15512 r_type
= R_PPC64_TPREL34
;
15513 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15518 case R_PPC64_TLSGD
:
15519 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15520 && rel
+ 1 < relend
)
15522 unsigned int insn2
;
15523 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
15525 offset
= rel
->r_offset
;
15526 if (is_plt_seq_reloc (r_type1
))
15528 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
15529 if (r_type1
== R_PPC64_PLT_PCREL34
15530 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
15531 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15532 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15536 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
15537 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15539 if ((tls_mask
& TLS_GDIE
) != 0)
15542 r_type
= R_PPC64_NONE
;
15543 insn2
= 0x7c636a14; /* add 3,3,13 */
15548 if (toc_symndx
!= 0)
15550 r_symndx
= toc_symndx
;
15551 rel
->r_addend
= toc_addend
;
15553 if (r_type1
== R_PPC64_REL24_NOTOC
15554 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
15556 r_type
= R_PPC64_NONE
;
15561 rel
->r_offset
= offset
+ d_offset
;
15562 r_type
= R_PPC64_TPREL16_LO
;
15563 insn2
= 0x38630000; /* addi 3,3,0 */
15566 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15567 /* Zap the reloc on the _tls_get_addr call too. */
15568 BFD_ASSERT (offset
== rel
[1].r_offset
);
15569 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15570 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15571 if ((tls_mask
& TLS_GDIE
) == 0
15573 && r_type
!= R_PPC64_NONE
)
15578 case R_PPC64_TLSLD
:
15579 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15580 && rel
+ 1 < relend
)
15582 unsigned int insn2
;
15583 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
15585 offset
= rel
->r_offset
;
15586 if (is_plt_seq_reloc (r_type1
))
15588 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
15589 if (r_type1
== R_PPC64_PLT_PCREL34
15590 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
15591 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15592 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15596 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
15597 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15599 if (r_type1
== R_PPC64_REL24_NOTOC
15600 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
15602 r_type
= R_PPC64_NONE
;
15607 rel
->r_offset
= offset
+ d_offset
;
15608 r_symndx
= STN_UNDEF
;
15609 r_type
= R_PPC64_TPREL16_LO
;
15610 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15611 insn2
= 0x38630000; /* addi 3,3,0 */
15613 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15614 /* Zap the reloc on the _tls_get_addr call too. */
15615 BFD_ASSERT (offset
== rel
[1].r_offset
);
15616 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15617 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15618 if (r_type
!= R_PPC64_NONE
)
15623 case R_PPC64_DTPMOD64
:
15624 if (rel
+ 1 < relend
15625 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
15626 && rel
[1].r_offset
== rel
->r_offset
+ 8)
15628 if ((tls_mask
& TLS_GD
) == 0)
15630 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
15631 if ((tls_mask
& TLS_GDIE
) != 0)
15632 r_type
= R_PPC64_TPREL64
;
15635 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
15636 r_type
= R_PPC64_NONE
;
15638 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15643 if ((tls_mask
& TLS_LD
) == 0)
15645 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
15646 r_type
= R_PPC64_NONE
;
15647 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15652 case R_PPC64_TPREL64
:
15653 if ((tls_mask
& TLS_TPREL
) == 0)
15655 r_type
= R_PPC64_NONE
;
15656 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15660 case R_PPC64_ENTRY
:
15661 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15662 if (!bfd_link_pic (info
)
15663 && !info
->traditional_format
15664 && relocation
+ 0x80008000 <= 0xffffffff)
15666 unsigned int insn1
, insn2
;
15668 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15669 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15670 if ((insn1
& ~0xfffc) == LD_R2_0R12
15671 && insn2
== ADD_R2_R2_R12
)
15673 bfd_put_32 (input_bfd
,
15674 LIS_R2
+ PPC_HA (relocation
),
15675 contents
+ rel
->r_offset
);
15676 bfd_put_32 (input_bfd
,
15677 ADDI_R2_R2
+ PPC_LO (relocation
),
15678 contents
+ rel
->r_offset
+ 4);
15683 relocation
-= (rel
->r_offset
15684 + input_section
->output_offset
15685 + input_section
->output_section
->vma
);
15686 if (relocation
+ 0x80008000 <= 0xffffffff)
15688 unsigned int insn1
, insn2
;
15690 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15691 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15692 if ((insn1
& ~0xfffc) == LD_R2_0R12
15693 && insn2
== ADD_R2_R2_R12
)
15695 bfd_put_32 (input_bfd
,
15696 ADDIS_R2_R12
+ PPC_HA (relocation
),
15697 contents
+ rel
->r_offset
);
15698 bfd_put_32 (input_bfd
,
15699 ADDI_R2_R2
+ PPC_LO (relocation
),
15700 contents
+ rel
->r_offset
+ 4);
15706 case R_PPC64_REL16_HA
:
15707 /* If we are generating a non-PIC executable, edit
15708 . 0: addis 2,12,.TOC.-0b@ha
15709 . addi 2,2,.TOC.-0b@l
15710 used by ELFv2 global entry points to set up r2, to
15713 if .TOC. is in range. */
15714 if (!bfd_link_pic (info
)
15715 && !info
->traditional_format
15717 && rel
->r_addend
== d_offset
15718 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
15719 && rel
+ 1 < relend
15720 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
15721 && rel
[1].r_offset
== rel
->r_offset
+ 4
15722 && rel
[1].r_addend
== rel
->r_addend
+ 4
15723 && relocation
+ 0x80008000 <= 0xffffffff)
15725 unsigned int insn1
, insn2
;
15726 offset
= rel
->r_offset
- d_offset
;
15727 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
15728 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15729 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
15730 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
15732 r_type
= R_PPC64_ADDR16_HA
;
15733 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15734 rel
->r_addend
-= d_offset
;
15735 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
15736 rel
[1].r_addend
-= d_offset
+ 4;
15737 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
15743 /* Handle other relocations that tweak non-addend part of insn. */
15745 max_br_offset
= 1 << 25;
15746 addend
= rel
->r_addend
;
15747 reloc_dest
= DEST_NORMAL
;
15753 case R_PPC64_TOCSAVE
:
15754 if (relocation
+ addend
== (rel
->r_offset
15755 + input_section
->output_offset
15756 + input_section
->output_section
->vma
)
15757 && tocsave_find (htab
, NO_INSERT
,
15758 &local_syms
, rel
, input_bfd
))
15760 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15762 || insn
== CROR_151515
|| insn
== CROR_313131
)
15763 bfd_put_32 (input_bfd
,
15764 STD_R2_0R1
+ STK_TOC (htab
),
15765 contents
+ rel
->r_offset
);
15769 /* Branch taken prediction relocations. */
15770 case R_PPC64_ADDR14_BRTAKEN
:
15771 case R_PPC64_REL14_BRTAKEN
:
15772 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
15773 /* Fall through. */
15775 /* Branch not taken prediction relocations. */
15776 case R_PPC64_ADDR14_BRNTAKEN
:
15777 case R_PPC64_REL14_BRNTAKEN
:
15778 insn
|= bfd_get_32 (input_bfd
,
15779 contents
+ rel
->r_offset
) & ~(0x01 << 21);
15780 /* Fall through. */
15782 case R_PPC64_REL14
:
15783 max_br_offset
= 1 << 15;
15784 /* Fall through. */
15786 case R_PPC64_REL24
:
15787 case R_PPC64_REL24_NOTOC
:
15788 case R_PPC64_PLTCALL
:
15789 case R_PPC64_PLTCALL_NOTOC
:
15790 /* Calls to functions with a different TOC, such as calls to
15791 shared objects, need to alter the TOC pointer. This is
15792 done using a linkage stub. A REL24 branching to these
15793 linkage stubs needs to be followed by a nop, as the nop
15794 will be replaced with an instruction to restore the TOC
15799 && h
->oh
->is_func_descriptor
)
15800 fdh
= ppc_follow_link (h
->oh
);
15801 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
15803 if ((r_type
== R_PPC64_PLTCALL
15804 || r_type
== R_PPC64_PLTCALL_NOTOC
)
15805 && stub_entry
!= NULL
15806 && stub_entry
->stub_type
>= ppc_stub_plt_call
15807 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15810 if (stub_entry
!= NULL
15811 && ((stub_entry
->stub_type
>= ppc_stub_plt_call
15812 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15813 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
15814 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
15815 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
15816 || stub_entry
->stub_type
== ppc_stub_long_branch_both
))
15818 bool can_plt_call
= false;
15820 if (stub_entry
->stub_type
== ppc_stub_plt_call
15822 && htab
->params
->plt_localentry0
!= 0
15824 && is_elfv2_localentry0 (&h
->elf
))
15826 /* The function doesn't use or change r2. */
15827 can_plt_call
= true;
15829 else if (r_type
== R_PPC64_REL24_NOTOC
)
15831 /* NOTOC calls don't need to restore r2. */
15832 can_plt_call
= true;
15835 /* All of these stubs may modify r2, so there must be a
15836 branch and link followed by a nop. The nop is
15837 replaced by an insn to restore r2. */
15838 else if (rel
->r_offset
+ 8 <= input_section
->size
)
15842 br
= bfd_get_32 (input_bfd
,
15843 contents
+ rel
->r_offset
);
15848 nop
= bfd_get_32 (input_bfd
,
15849 contents
+ rel
->r_offset
+ 4);
15850 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
15851 can_plt_call
= true;
15852 else if (nop
== NOP
15853 || nop
== CROR_151515
15854 || nop
== CROR_313131
)
15857 && is_tls_get_addr (&h
->elf
, htab
)
15858 && htab
->params
->tls_get_addr_opt
)
15860 /* Special stub used, leave nop alone. */
15863 bfd_put_32 (input_bfd
,
15864 LD_R2_0R1
+ STK_TOC (htab
),
15865 contents
+ rel
->r_offset
+ 4);
15866 can_plt_call
= true;
15871 if (!can_plt_call
&& h
!= NULL
)
15873 const char *name
= h
->elf
.root
.root
.string
;
15878 if (startswith (name
, "__libc_start_main")
15879 && (name
[17] == 0 || name
[17] == '@'))
15881 /* Allow crt1 branch to go via a toc adjusting
15882 stub. Other calls that never return could do
15883 the same, if we could detect such. */
15884 can_plt_call
= true;
15890 /* g++ as of 20130507 emits self-calls without a
15891 following nop. This is arguably wrong since we
15892 have conflicting information. On the one hand a
15893 global symbol and on the other a local call
15894 sequence, but don't error for this special case.
15895 It isn't possible to cheaply verify we have
15896 exactly such a call. Allow all calls to the same
15898 asection
*code_sec
= sec
;
15900 if (get_opd_info (sec
) != NULL
)
15902 bfd_vma off
= (relocation
+ addend
15903 - sec
->output_section
->vma
15904 - sec
->output_offset
);
15906 opd_entry_value (sec
, off
, &code_sec
, NULL
, false);
15908 if (code_sec
== input_section
)
15909 can_plt_call
= true;
15914 if (stub_entry
->stub_type
>= ppc_stub_plt_call
15915 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15916 info
->callbacks
->einfo
15917 /* xgettext:c-format */
15918 (_("%H: call to `%pT' lacks nop, can't restore toc; "
15919 "(plt call stub)\n"),
15920 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
15922 info
->callbacks
->einfo
15923 /* xgettext:c-format */
15924 (_("%H: call to `%pT' lacks nop, can't restore toc; "
15925 "(toc save/adjust stub)\n"),
15926 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
15928 bfd_set_error (bfd_error_bad_value
);
15933 && stub_entry
->stub_type
>= ppc_stub_plt_call
15934 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15935 unresolved_reloc
= false;
15938 if ((stub_entry
== NULL
15939 || stub_entry
->stub_type
== ppc_stub_long_branch
15940 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
15941 && get_opd_info (sec
) != NULL
)
15943 /* The branch destination is the value of the opd entry. */
15944 bfd_vma off
= (relocation
+ addend
15945 - sec
->output_section
->vma
15946 - sec
->output_offset
);
15947 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, false);
15948 if (dest
!= (bfd_vma
) -1)
15952 reloc_dest
= DEST_OPD
;
15956 /* If the branch is out of reach we ought to have a long
15958 from
= (rel
->r_offset
15959 + input_section
->output_offset
15960 + input_section
->output_section
->vma
);
15962 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
15966 if (stub_entry
!= NULL
15967 && (stub_entry
->stub_type
== ppc_stub_long_branch
15968 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
15969 && (r_type
== R_PPC64_ADDR14_BRTAKEN
15970 || r_type
== R_PPC64_ADDR14_BRNTAKEN
15971 || (relocation
+ addend
- from
+ max_br_offset
15972 < 2 * max_br_offset
)))
15973 /* Don't use the stub if this branch is in range. */
15976 if (stub_entry
!= NULL
15977 && (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
15978 || stub_entry
->stub_type
== ppc_stub_long_branch_both
15979 || stub_entry
->stub_type
== ppc_stub_plt_branch_notoc
15980 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
15981 && (r_type
!= R_PPC64_REL24_NOTOC
15982 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
15983 & STO_PPC64_LOCAL_MASK
) <= 1 << STO_PPC64_LOCAL_BIT
)
15984 && (relocation
+ addend
- from
+ max_br_offset
15985 < 2 * max_br_offset
))
15988 if (stub_entry
!= NULL
15989 && (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
15990 || stub_entry
->stub_type
== ppc_stub_long_branch_both
15991 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
15992 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
15993 && r_type
== R_PPC64_REL24_NOTOC
15994 && (relocation
+ addend
- from
+ max_br_offset
15995 < 2 * max_br_offset
))
15998 if (stub_entry
!= NULL
)
16000 /* Munge up the value and addend so that we call the stub
16001 rather than the procedure directly. */
16002 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
16004 if (stub_entry
->stub_type
== ppc_stub_save_res
)
16005 relocation
+= (stub_sec
->output_offset
16006 + stub_sec
->output_section
->vma
16007 + stub_sec
->size
- htab
->sfpr
->size
16008 - htab
->sfpr
->output_offset
16009 - htab
->sfpr
->output_section
->vma
);
16011 relocation
= (stub_entry
->stub_offset
16012 + stub_sec
->output_offset
16013 + stub_sec
->output_section
->vma
);
16015 reloc_dest
= DEST_STUB
;
16017 if ((((stub_entry
->stub_type
== ppc_stub_plt_call
16018 && ALWAYS_EMIT_R2SAVE
)
16019 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
16020 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
16021 && rel
+ 1 < relend
16022 && rel
[1].r_offset
== rel
->r_offset
+ 4
16023 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
16024 || ((stub_entry
->stub_type
== ppc_stub_long_branch_both
16025 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
16026 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
16027 && r_type
== R_PPC64_REL24_NOTOC
))
16029 /* Skip over the r2 store at the start of the stub. */
16030 if (!(stub_entry
->stub_type
>= ppc_stub_plt_call
16031 && htab
->params
->tls_get_addr_opt
16033 && is_tls_get_addr (&h
->elf
, htab
)))
16037 if (r_type
== R_PPC64_REL24_NOTOC
16038 && (stub_entry
->stub_type
== ppc_stub_plt_call_notoc
16039 || stub_entry
->stub_type
== ppc_stub_plt_call_both
))
16040 htab
->notoc_plt
= 1;
16047 /* Set 'a' bit. This is 0b00010 in BO field for branch
16048 on CR(BI) insns (BO == 001at or 011at), and 0b01000
16049 for branch on CTR insns (BO == 1a00t or 1a01t). */
16050 if ((insn
& (0x14 << 21)) == (0x04 << 21))
16051 insn
|= 0x02 << 21;
16052 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
16053 insn
|= 0x08 << 21;
16059 /* Invert 'y' bit if not the default. */
16060 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
16061 insn
^= 0x01 << 21;
16064 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
16067 /* NOP out calls to undefined weak functions.
16068 We can thus call a weak function without first
16069 checking whether the function is defined. */
16071 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16072 && h
->elf
.dynindx
== -1
16073 && (r_type
== R_PPC64_REL24
16074 || r_type
== R_PPC64_REL24_NOTOC
)
16078 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
16083 case R_PPC64_GOT16_DS
:
16084 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16085 || !htab
->do_toc_opt
)
16087 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16088 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
16090 && sec
->output_section
!= NULL
16091 && !discarded_section (sec
)
16092 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16094 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16095 if ((insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16097 insn
+= (14u << 26) - (58u << 26);
16098 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16099 r_type
= R_PPC64_TOC16
;
16100 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16105 case R_PPC64_GOT16_LO_DS
:
16106 case R_PPC64_GOT16_HA
:
16107 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16108 || !htab
->do_toc_opt
)
16110 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16111 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
16113 && sec
->output_section
!= NULL
16114 && !discarded_section (sec
)
16115 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16117 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16118 if (r_type
== R_PPC64_GOT16_LO_DS
16119 && (insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16121 insn
+= (14u << 26) - (58u << 26);
16122 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16123 r_type
= R_PPC64_TOC16_LO
;
16124 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16126 else if (r_type
== R_PPC64_GOT16_HA
16127 && (insn
& (0x3fu
<< 26)) == 15u << 26 /* addis */)
16129 r_type
= R_PPC64_TOC16_HA
;
16130 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16135 case R_PPC64_GOT_PCREL34
:
16136 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16137 || !htab
->do_toc_opt
)
16139 from
= (rel
->r_offset
16140 + input_section
->output_section
->vma
16141 + input_section
->output_offset
);
16142 if (!(relocation
- from
+ (1ULL << 33) < 1ULL << 34
16144 && sec
->output_section
!= NULL
16145 && !discarded_section (sec
)
16146 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
16149 offset
= rel
->r_offset
;
16150 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16152 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16153 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16154 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
16157 /* Replace with paddi. */
16158 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
16159 r_type
= R_PPC64_PCREL34
;
16160 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16161 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ offset
);
16162 bfd_put_32 (input_bfd
, pinsn
, contents
+ offset
+ 4);
16163 /* Fall through. */
16165 case R_PPC64_PCREL34
:
16166 if (!htab
->params
->no_pcrel_opt
16167 && rel
+ 1 < relend
16168 && rel
[1].r_offset
== rel
->r_offset
16169 && rel
[1].r_info
== ELF64_R_INFO (0, R_PPC64_PCREL_OPT
)
16170 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16172 offset
= rel
->r_offset
;
16173 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16175 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16176 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16177 == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
16178 | (14ULL << 26) /* paddi */))
16180 bfd_vma off2
= rel
[1].r_addend
;
16182 /* zero means next insn. */
16185 if (off2
+ 4 <= input_section
->size
)
16188 bfd_signed_vma addend_off
;
16189 pinsn2
= bfd_get_32 (input_bfd
, contents
+ off2
);
16191 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16193 if (off2
+ 8 > input_section
->size
)
16195 pinsn2
|= bfd_get_32 (input_bfd
,
16196 contents
+ off2
+ 4);
16198 if (xlate_pcrel_opt (&pinsn
, &pinsn2
, &addend_off
))
16200 addend
+= addend_off
;
16201 rel
->r_addend
= addend
;
16202 bfd_put_32 (input_bfd
, pinsn
>> 32,
16203 contents
+ offset
);
16204 bfd_put_32 (input_bfd
, pinsn
,
16205 contents
+ offset
+ 4);
16206 bfd_put_32 (input_bfd
, pinsn2
>> 32,
16208 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16209 bfd_put_32 (input_bfd
, pinsn2
,
16210 contents
+ off2
+ 4);
16219 save_unresolved_reloc
= unresolved_reloc
;
16223 /* xgettext:c-format */
16224 _bfd_error_handler (_("%pB: %s unsupported"),
16225 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
16227 bfd_set_error (bfd_error_bad_value
);
16233 case R_PPC64_TLSGD
:
16234 case R_PPC64_TLSLD
:
16235 case R_PPC64_TOCSAVE
:
16236 case R_PPC64_GNU_VTINHERIT
:
16237 case R_PPC64_GNU_VTENTRY
:
16238 case R_PPC64_ENTRY
:
16239 case R_PPC64_PCREL_OPT
:
16242 /* GOT16 relocations. Like an ADDR16 using the symbol's
16243 address in the GOT as relocation value instead of the
16244 symbol's value itself. Also, create a GOT entry for the
16245 symbol and put the symbol value there. */
16246 case R_PPC64_GOT_TLSGD16
:
16247 case R_PPC64_GOT_TLSGD16_LO
:
16248 case R_PPC64_GOT_TLSGD16_HI
:
16249 case R_PPC64_GOT_TLSGD16_HA
:
16250 case R_PPC64_GOT_TLSGD_PCREL34
:
16251 tls_type
= TLS_TLS
| TLS_GD
;
16254 case R_PPC64_GOT_TLSLD16
:
16255 case R_PPC64_GOT_TLSLD16_LO
:
16256 case R_PPC64_GOT_TLSLD16_HI
:
16257 case R_PPC64_GOT_TLSLD16_HA
:
16258 case R_PPC64_GOT_TLSLD_PCREL34
:
16259 tls_type
= TLS_TLS
| TLS_LD
;
16262 case R_PPC64_GOT_TPREL16_DS
:
16263 case R_PPC64_GOT_TPREL16_LO_DS
:
16264 case R_PPC64_GOT_TPREL16_HI
:
16265 case R_PPC64_GOT_TPREL16_HA
:
16266 case R_PPC64_GOT_TPREL_PCREL34
:
16267 tls_type
= TLS_TLS
| TLS_TPREL
;
16270 case R_PPC64_GOT_DTPREL16_DS
:
16271 case R_PPC64_GOT_DTPREL16_LO_DS
:
16272 case R_PPC64_GOT_DTPREL16_HI
:
16273 case R_PPC64_GOT_DTPREL16_HA
:
16274 case R_PPC64_GOT_DTPREL_PCREL34
:
16275 tls_type
= TLS_TLS
| TLS_DTPREL
;
16278 case R_PPC64_GOT16
:
16279 case R_PPC64_GOT16_LO
:
16280 case R_PPC64_GOT16_HI
:
16281 case R_PPC64_GOT16_HA
:
16282 case R_PPC64_GOT16_DS
:
16283 case R_PPC64_GOT16_LO_DS
:
16284 case R_PPC64_GOT_PCREL34
:
16287 /* Relocation is to the entry for this symbol in the global
16292 unsigned long indx
= 0;
16293 struct got_entry
*ent
;
16295 if (tls_type
== (TLS_TLS
| TLS_LD
)
16296 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16297 ent
= ppc64_tlsld_got (input_bfd
);
16302 if (!htab
->elf
.dynamic_sections_created
16303 || h
->elf
.dynindx
== -1
16304 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16305 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16306 /* This is actually a static link, or it is a
16307 -Bsymbolic link and the symbol is defined
16308 locally, or the symbol was forced to be local
16309 because of a version file. */
16313 indx
= h
->elf
.dynindx
;
16314 unresolved_reloc
= false;
16316 ent
= h
->elf
.got
.glist
;
16320 if (local_got_ents
== NULL
)
16322 ent
= local_got_ents
[r_symndx
];
16325 for (; ent
!= NULL
; ent
= ent
->next
)
16326 if (ent
->addend
== orig_rel
.r_addend
16327 && ent
->owner
== input_bfd
16328 && ent
->tls_type
== tls_type
)
16334 if (ent
->is_indirect
)
16335 ent
= ent
->got
.ent
;
16336 offp
= &ent
->got
.offset
;
16337 got
= ppc64_elf_tdata (ent
->owner
)->got
;
16341 /* The offset must always be a multiple of 8. We use the
16342 least significant bit to record whether we have already
16343 processed this entry. */
16345 if ((off
& 1) != 0)
16349 /* Generate relocs for the dynamic linker, except in
16350 the case of TLSLD where we'll use one entry per
16358 ? h
->elf
.type
== STT_GNU_IFUNC
16359 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
16362 relgot
= htab
->elf
.irelplt
;
16363 if (indx
== 0 || is_static_defined (&h
->elf
))
16364 htab
->elf
.ifunc_resolvers
= true;
16367 || (bfd_link_pic (info
)
16369 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16371 && bfd_link_executable (info
)
16373 || SYMBOL_REFERENCES_LOCAL (info
,
16375 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
16376 if (relgot
!= NULL
)
16378 outrel
.r_offset
= (got
->output_section
->vma
16379 + got
->output_offset
16381 outrel
.r_addend
= orig_rel
.r_addend
;
16382 if (tls_type
& (TLS_LD
| TLS_GD
))
16384 outrel
.r_addend
= 0;
16385 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
16386 if (tls_type
== (TLS_TLS
| TLS_GD
))
16388 loc
= relgot
->contents
;
16389 loc
+= (relgot
->reloc_count
++
16390 * sizeof (Elf64_External_Rela
));
16391 bfd_elf64_swap_reloca_out (output_bfd
,
16393 outrel
.r_offset
+= 8;
16394 outrel
.r_addend
= orig_rel
.r_addend
;
16396 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16399 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
16400 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16401 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
16402 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
16403 else if (indx
!= 0)
16404 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
16408 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16410 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16412 /* Write the .got section contents for the sake
16414 loc
= got
->contents
+ off
;
16415 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
16419 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
16421 outrel
.r_addend
+= relocation
;
16422 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
16424 if (htab
->elf
.tls_sec
== NULL
)
16425 outrel
.r_addend
= 0;
16427 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
16430 loc
= relgot
->contents
;
16431 loc
+= (relgot
->reloc_count
++
16432 * sizeof (Elf64_External_Rela
));
16433 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16436 /* Init the .got section contents here if we're not
16437 emitting a reloc. */
16440 relocation
+= orig_rel
.r_addend
;
16443 if (htab
->elf
.tls_sec
== NULL
)
16447 if (tls_type
& TLS_LD
)
16450 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16451 if (tls_type
& TLS_TPREL
)
16452 relocation
+= DTP_OFFSET
- TP_OFFSET
;
16455 if (tls_type
& (TLS_GD
| TLS_LD
))
16457 bfd_put_64 (output_bfd
, relocation
,
16458 got
->contents
+ off
+ 8);
16462 bfd_put_64 (output_bfd
, relocation
,
16463 got
->contents
+ off
);
16467 if (off
>= (bfd_vma
) -2)
16470 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
16472 if (!(r_type
== R_PPC64_GOT_PCREL34
16473 || r_type
== R_PPC64_GOT_TLSGD_PCREL34
16474 || r_type
== R_PPC64_GOT_TLSLD_PCREL34
16475 || r_type
== R_PPC64_GOT_TPREL_PCREL34
16476 || r_type
== R_PPC64_GOT_DTPREL_PCREL34
))
16477 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
16481 case R_PPC64_PLT16_HA
:
16482 case R_PPC64_PLT16_HI
:
16483 case R_PPC64_PLT16_LO
:
16484 case R_PPC64_PLT16_LO_DS
:
16485 case R_PPC64_PLT_PCREL34
:
16486 case R_PPC64_PLT_PCREL34_NOTOC
:
16487 case R_PPC64_PLT32
:
16488 case R_PPC64_PLT64
:
16489 case R_PPC64_PLTSEQ
:
16490 case R_PPC64_PLTSEQ_NOTOC
:
16491 case R_PPC64_PLTCALL
:
16492 case R_PPC64_PLTCALL_NOTOC
:
16493 /* Relocation is to the entry for this symbol in the
16494 procedure linkage table. */
16495 unresolved_reloc
= true;
16497 struct plt_entry
**plt_list
= NULL
;
16499 plt_list
= &h
->elf
.plt
.plist
;
16500 else if (local_got_ents
!= NULL
)
16502 struct plt_entry
**local_plt
= (struct plt_entry
**)
16503 (local_got_ents
+ symtab_hdr
->sh_info
);
16504 plt_list
= local_plt
+ r_symndx
;
16508 struct plt_entry
*ent
;
16510 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
16511 if (ent
->plt
.offset
!= (bfd_vma
) -1
16512 && ent
->addend
== orig_rel
.r_addend
)
16517 plt
= htab
->elf
.splt
;
16518 if (use_local_plt (info
, elf_hash_entry (h
)))
16521 ? h
->elf
.type
== STT_GNU_IFUNC
16522 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16523 plt
= htab
->elf
.iplt
;
16525 plt
= htab
->pltlocal
;
16527 relocation
= (plt
->output_section
->vma
16528 + plt
->output_offset
16529 + ent
->plt
.offset
);
16530 if (r_type
== R_PPC64_PLT16_HA
16531 || r_type
== R_PPC64_PLT16_HI
16532 || r_type
== R_PPC64_PLT16_LO
16533 || r_type
== R_PPC64_PLT16_LO_DS
)
16535 got
= (elf_gp (output_bfd
)
16536 + htab
->sec_info
[input_section
->id
].toc_off
);
16540 unresolved_reloc
= false;
16548 /* Relocation value is TOC base. */
16549 relocation
= TOCstart
;
16550 if (r_symndx
== STN_UNDEF
)
16551 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
16552 else if (unresolved_reloc
)
16554 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
16555 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
16557 unresolved_reloc
= true;
16560 /* TOC16 relocs. We want the offset relative to the TOC base,
16561 which is the address of the start of the TOC plus 0x8000.
16562 The TOC consists of sections .got, .toc, .tocbss, and .plt,
16564 case R_PPC64_TOC16
:
16565 case R_PPC64_TOC16_LO
:
16566 case R_PPC64_TOC16_HI
:
16567 case R_PPC64_TOC16_DS
:
16568 case R_PPC64_TOC16_LO_DS
:
16569 case R_PPC64_TOC16_HA
:
16570 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16575 /* Relocate against the beginning of the section. */
16576 case R_PPC64_SECTOFF
:
16577 case R_PPC64_SECTOFF_LO
:
16578 case R_PPC64_SECTOFF_HI
:
16579 case R_PPC64_SECTOFF_DS
:
16580 case R_PPC64_SECTOFF_LO_DS
:
16581 case R_PPC64_SECTOFF_HA
:
16583 addend
-= sec
->output_section
->vma
;
16586 case R_PPC64_REL16
:
16587 case R_PPC64_REL16_LO
:
16588 case R_PPC64_REL16_HI
:
16589 case R_PPC64_REL16_HA
:
16590 case R_PPC64_REL16_HIGH
:
16591 case R_PPC64_REL16_HIGHA
:
16592 case R_PPC64_REL16_HIGHER
:
16593 case R_PPC64_REL16_HIGHERA
:
16594 case R_PPC64_REL16_HIGHEST
:
16595 case R_PPC64_REL16_HIGHESTA
:
16596 case R_PPC64_REL16_HIGHER34
:
16597 case R_PPC64_REL16_HIGHERA34
:
16598 case R_PPC64_REL16_HIGHEST34
:
16599 case R_PPC64_REL16_HIGHESTA34
:
16600 case R_PPC64_REL16DX_HA
:
16601 case R_PPC64_REL14
:
16602 case R_PPC64_REL14_BRNTAKEN
:
16603 case R_PPC64_REL14_BRTAKEN
:
16604 case R_PPC64_REL24
:
16605 case R_PPC64_REL24_NOTOC
:
16606 case R_PPC64_PCREL34
:
16607 case R_PPC64_PCREL28
:
16610 case R_PPC64_TPREL16
:
16611 case R_PPC64_TPREL16_LO
:
16612 case R_PPC64_TPREL16_HI
:
16613 case R_PPC64_TPREL16_HA
:
16614 case R_PPC64_TPREL16_DS
:
16615 case R_PPC64_TPREL16_LO_DS
:
16616 case R_PPC64_TPREL16_HIGH
:
16617 case R_PPC64_TPREL16_HIGHA
:
16618 case R_PPC64_TPREL16_HIGHER
:
16619 case R_PPC64_TPREL16_HIGHERA
:
16620 case R_PPC64_TPREL16_HIGHEST
:
16621 case R_PPC64_TPREL16_HIGHESTA
:
16622 case R_PPC64_TPREL34
:
16624 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16625 && h
->elf
.dynindx
== -1)
16627 /* Make this relocation against an undefined weak symbol
16628 resolve to zero. This is really just a tweak, since
16629 code using weak externs ought to check that they are
16630 defined before using them. */
16631 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
16633 insn
= bfd_get_32 (input_bfd
, p
);
16634 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
16636 bfd_put_32 (input_bfd
, insn
, p
);
16639 if (htab
->elf
.tls_sec
!= NULL
)
16640 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
16641 /* The TPREL16 relocs shouldn't really be used in shared
16642 libs or with non-local symbols as that will result in
16643 DT_TEXTREL being set, but support them anyway. */
16646 case R_PPC64_DTPREL16
:
16647 case R_PPC64_DTPREL16_LO
:
16648 case R_PPC64_DTPREL16_HI
:
16649 case R_PPC64_DTPREL16_HA
:
16650 case R_PPC64_DTPREL16_DS
:
16651 case R_PPC64_DTPREL16_LO_DS
:
16652 case R_PPC64_DTPREL16_HIGH
:
16653 case R_PPC64_DTPREL16_HIGHA
:
16654 case R_PPC64_DTPREL16_HIGHER
:
16655 case R_PPC64_DTPREL16_HIGHERA
:
16656 case R_PPC64_DTPREL16_HIGHEST
:
16657 case R_PPC64_DTPREL16_HIGHESTA
:
16658 case R_PPC64_DTPREL34
:
16659 if (htab
->elf
.tls_sec
!= NULL
)
16660 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16663 case R_PPC64_ADDR64_LOCAL
:
16664 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
16669 case R_PPC64_DTPMOD64
:
16674 case R_PPC64_TPREL64
:
16675 if (htab
->elf
.tls_sec
!= NULL
)
16676 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
16679 case R_PPC64_DTPREL64
:
16680 if (htab
->elf
.tls_sec
!= NULL
)
16681 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16682 /* Fall through. */
16684 /* Relocations that may need to be propagated if this is a
16686 case R_PPC64_REL30
:
16687 case R_PPC64_REL32
:
16688 case R_PPC64_REL64
:
16689 case R_PPC64_ADDR14
:
16690 case R_PPC64_ADDR14_BRNTAKEN
:
16691 case R_PPC64_ADDR14_BRTAKEN
:
16692 case R_PPC64_ADDR16
:
16693 case R_PPC64_ADDR16_DS
:
16694 case R_PPC64_ADDR16_HA
:
16695 case R_PPC64_ADDR16_HI
:
16696 case R_PPC64_ADDR16_HIGH
:
16697 case R_PPC64_ADDR16_HIGHA
:
16698 case R_PPC64_ADDR16_HIGHER
:
16699 case R_PPC64_ADDR16_HIGHERA
:
16700 case R_PPC64_ADDR16_HIGHEST
:
16701 case R_PPC64_ADDR16_HIGHESTA
:
16702 case R_PPC64_ADDR16_LO
:
16703 case R_PPC64_ADDR16_LO_DS
:
16704 case R_PPC64_ADDR16_HIGHER34
:
16705 case R_PPC64_ADDR16_HIGHERA34
:
16706 case R_PPC64_ADDR16_HIGHEST34
:
16707 case R_PPC64_ADDR16_HIGHESTA34
:
16708 case R_PPC64_ADDR24
:
16709 case R_PPC64_ADDR32
:
16710 case R_PPC64_ADDR64
:
16711 case R_PPC64_UADDR16
:
16712 case R_PPC64_UADDR32
:
16713 case R_PPC64_UADDR64
:
16715 case R_PPC64_D34_LO
:
16716 case R_PPC64_D34_HI30
:
16717 case R_PPC64_D34_HA30
:
16720 if ((input_section
->flags
& SEC_ALLOC
) == 0)
16723 if (NO_OPD_RELOCS
&& is_opd
)
16726 if (bfd_link_pic (info
)
16728 || h
->elf
.dyn_relocs
!= NULL
)
16729 && ((h
!= NULL
&& pc_dynrelocs (h
))
16730 || must_be_dyn_reloc (info
, r_type
)))
16732 ? h
->elf
.dyn_relocs
!= NULL
16733 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
16735 bool skip
, relocate
;
16740 /* When generating a dynamic object, these relocations
16741 are copied into the output file to be resolved at run
16747 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
16748 input_section
, rel
->r_offset
);
16749 if (out_off
== (bfd_vma
) -1)
16751 else if (out_off
== (bfd_vma
) -2)
16752 skip
= true, relocate
= true;
16753 out_off
+= (input_section
->output_section
->vma
16754 + input_section
->output_offset
);
16755 outrel
.r_offset
= out_off
;
16756 outrel
.r_addend
= rel
->r_addend
;
16758 /* Optimize unaligned reloc use. */
16759 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
16760 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
16761 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
16762 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
16763 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
16764 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
16765 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
16766 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
16767 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
16770 memset (&outrel
, 0, sizeof outrel
);
16772 && !SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16774 && r_type
!= R_PPC64_TOC
)
16776 indx
= h
->elf
.dynindx
;
16777 BFD_ASSERT (indx
!= -1);
16778 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
16782 /* This symbol is local, or marked to become local,
16783 or this is an opd section reloc which must point
16784 at a local function. */
16785 outrel
.r_addend
+= relocation
;
16786 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
16788 if (is_opd
&& h
!= NULL
)
16790 /* Lie about opd entries. This case occurs
16791 when building shared libraries and we
16792 reference a function in another shared
16793 lib. The same thing happens for a weak
16794 definition in an application that's
16795 overridden by a strong definition in a
16796 shared lib. (I believe this is a generic
16797 bug in binutils handling of weak syms.)
16798 In these cases we won't use the opd
16799 entry in this lib. */
16800 unresolved_reloc
= false;
16803 && r_type
== R_PPC64_ADDR64
16805 ? h
->elf
.type
== STT_GNU_IFUNC
16806 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
16807 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16810 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16812 /* We need to relocate .opd contents for ld.so.
16813 Prelink also wants simple and consistent rules
16814 for relocs. This make all RELATIVE relocs have
16815 *r_offset equal to r_addend. */
16822 ? h
->elf
.type
== STT_GNU_IFUNC
16823 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16825 info
->callbacks
->einfo
16826 /* xgettext:c-format */
16827 (_("%H: %s for indirect "
16828 "function `%pT' unsupported\n"),
16829 input_bfd
, input_section
, rel
->r_offset
,
16830 ppc64_elf_howto_table
[r_type
]->name
,
16834 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
16836 else if (sec
== NULL
|| sec
->owner
== NULL
)
16838 bfd_set_error (bfd_error_bad_value
);
16843 asection
*osec
= sec
->output_section
;
16845 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
16847 /* TLS symbol values are relative to the
16848 TLS segment. Dynamic relocations for
16849 local TLS symbols therefore can't be
16850 reduced to a relocation against their
16851 section symbol because it holds the
16852 address of the section, not a value
16853 relative to the TLS segment. We could
16854 change the .tdata dynamic section symbol
16855 to be zero value but STN_UNDEF works
16856 and is used elsewhere, eg. for TPREL64
16857 GOT relocs against local TLS symbols. */
16858 osec
= htab
->elf
.tls_sec
;
16863 indx
= elf_section_data (osec
)->dynindx
;
16866 if ((osec
->flags
& SEC_READONLY
) == 0
16867 && htab
->elf
.data_index_section
!= NULL
)
16868 osec
= htab
->elf
.data_index_section
;
16870 osec
= htab
->elf
.text_index_section
;
16871 indx
= elf_section_data (osec
)->dynindx
;
16873 BFD_ASSERT (indx
!= 0);
16876 /* We are turning this relocation into one
16877 against a section symbol, so subtract out
16878 the output section's address but not the
16879 offset of the input section in the output
16881 outrel
.r_addend
-= osec
->vma
;
16884 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
16888 sreloc
= elf_section_data (input_section
)->sreloc
;
16890 ? h
->elf
.type
== STT_GNU_IFUNC
16891 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16893 sreloc
= htab
->elf
.irelplt
;
16894 if (indx
== 0 || is_static_defined (&h
->elf
))
16895 htab
->elf
.ifunc_resolvers
= true;
16897 if (sreloc
== NULL
)
16900 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
16903 loc
= sreloc
->contents
;
16904 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
16905 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16907 if (!warned_dynamic
16908 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel
.r_info
)))
16910 info
->callbacks
->einfo
16911 /* xgettext:c-format */
16912 (_("%X%P: %pB: %s against %pT "
16913 "is not supported by glibc as a dynamic relocation\n"),
16915 ppc64_elf_howto_table
[ELF64_R_TYPE (outrel
.r_info
)]->name
,
16917 warned_dynamic
= true;
16920 /* If this reloc is against an external symbol, it will
16921 be computed at runtime, so there's no need to do
16922 anything now. However, for the sake of prelink ensure
16923 that the section contents are a known value. */
16926 unresolved_reloc
= false;
16927 /* The value chosen here is quite arbitrary as ld.so
16928 ignores section contents except for the special
16929 case of .opd where the contents might be accessed
16930 before relocation. Choose zero, as that won't
16931 cause reloc overflow. */
16934 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
16935 to improve backward compatibility with older
16937 if (r_type
== R_PPC64_ADDR64
)
16938 addend
= outrel
.r_addend
;
16939 /* Adjust pc_relative relocs to have zero in *r_offset. */
16940 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
16941 addend
= outrel
.r_offset
;
16947 case R_PPC64_GLOB_DAT
:
16948 case R_PPC64_JMP_SLOT
:
16949 case R_PPC64_JMP_IREL
:
16950 case R_PPC64_RELATIVE
:
16951 /* We shouldn't ever see these dynamic relocs in relocatable
16953 /* Fall through. */
16955 case R_PPC64_PLTGOT16
:
16956 case R_PPC64_PLTGOT16_DS
:
16957 case R_PPC64_PLTGOT16_HA
:
16958 case R_PPC64_PLTGOT16_HI
:
16959 case R_PPC64_PLTGOT16_LO
:
16960 case R_PPC64_PLTGOT16_LO_DS
:
16961 case R_PPC64_PLTREL32
:
16962 case R_PPC64_PLTREL64
:
16963 /* These ones haven't been implemented yet. */
16965 info
->callbacks
->einfo
16966 /* xgettext:c-format */
16967 (_("%P: %pB: %s is not supported for `%pT'\n"),
16969 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
16971 bfd_set_error (bfd_error_invalid_operation
);
16976 /* Multi-instruction sequences that access the TOC can be
16977 optimized, eg. addis ra,r2,0; addi rb,ra,x;
16978 to nop; addi rb,r2,x; */
16984 case R_PPC64_GOT_TLSLD16_HI
:
16985 case R_PPC64_GOT_TLSGD16_HI
:
16986 case R_PPC64_GOT_TPREL16_HI
:
16987 case R_PPC64_GOT_DTPREL16_HI
:
16988 case R_PPC64_GOT16_HI
:
16989 case R_PPC64_TOC16_HI
:
16990 /* These relocs would only be useful if building up an
16991 offset to later add to r2, perhaps in an indexed
16992 addressing mode instruction. Don't try to optimize.
16993 Unfortunately, the possibility of someone building up an
16994 offset like this or even with the HA relocs, means that
16995 we need to check the high insn when optimizing the low
16999 case R_PPC64_PLTCALL_NOTOC
:
17000 if (!unresolved_reloc
)
17001 htab
->notoc_plt
= 1;
17002 /* Fall through. */
17003 case R_PPC64_PLTCALL
:
17004 if (unresolved_reloc
)
17006 /* No plt entry. Make this into a direct call. */
17007 bfd_byte
*p
= contents
+ rel
->r_offset
;
17008 insn
= bfd_get_32 (input_bfd
, p
);
17010 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
17011 if (r_type
== R_PPC64_PLTCALL
)
17012 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
17013 unresolved_reloc
= save_unresolved_reloc
;
17014 r_type
= R_PPC64_REL24
;
17018 case R_PPC64_PLTSEQ_NOTOC
:
17019 case R_PPC64_PLTSEQ
:
17020 if (unresolved_reloc
)
17022 unresolved_reloc
= false;
17027 case R_PPC64_PLT_PCREL34_NOTOC
:
17028 if (!unresolved_reloc
)
17029 htab
->notoc_plt
= 1;
17030 /* Fall through. */
17031 case R_PPC64_PLT_PCREL34
:
17032 if (unresolved_reloc
)
17034 bfd_byte
*p
= contents
+ rel
->r_offset
;
17035 bfd_put_32 (input_bfd
, PNOP
>> 32, p
);
17036 bfd_put_32 (input_bfd
, PNOP
, p
+ 4);
17037 unresolved_reloc
= false;
17042 case R_PPC64_PLT16_HA
:
17043 if (unresolved_reloc
)
17045 unresolved_reloc
= false;
17048 /* Fall through. */
17049 case R_PPC64_GOT_TLSLD16_HA
:
17050 case R_PPC64_GOT_TLSGD16_HA
:
17051 case R_PPC64_GOT_TPREL16_HA
:
17052 case R_PPC64_GOT_DTPREL16_HA
:
17053 case R_PPC64_GOT16_HA
:
17054 case R_PPC64_TOC16_HA
:
17055 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17056 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
17060 p
= contents
+ (rel
->r_offset
& ~3);
17061 bfd_put_32 (input_bfd
, NOP
, p
);
17066 case R_PPC64_PLT16_LO
:
17067 case R_PPC64_PLT16_LO_DS
:
17068 if (unresolved_reloc
)
17070 unresolved_reloc
= false;
17073 /* Fall through. */
17074 case R_PPC64_GOT_TLSLD16_LO
:
17075 case R_PPC64_GOT_TLSGD16_LO
:
17076 case R_PPC64_GOT_TPREL16_LO_DS
:
17077 case R_PPC64_GOT_DTPREL16_LO_DS
:
17078 case R_PPC64_GOT16_LO
:
17079 case R_PPC64_GOT16_LO_DS
:
17080 case R_PPC64_TOC16_LO
:
17081 case R_PPC64_TOC16_LO_DS
:
17082 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17083 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
17085 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17086 insn
= bfd_get_32 (input_bfd
, p
);
17087 if ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */)
17089 /* Transform addic to addi when we change reg. */
17090 insn
&= ~((0x3fu
<< 26) | (0x1f << 16));
17091 insn
|= (14u << 26) | (2 << 16);
17095 insn
&= ~(0x1f << 16);
17098 bfd_put_32 (input_bfd
, insn
, p
);
17102 case R_PPC64_TPREL16_HA
:
17103 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
17105 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17106 bfd_put_32 (input_bfd
, NOP
, p
);
17111 case R_PPC64_TPREL16_LO
:
17112 case R_PPC64_TPREL16_LO_DS
:
17113 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
17115 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17116 insn
= bfd_get_32 (input_bfd
, p
);
17117 insn
&= ~(0x1f << 16);
17119 bfd_put_32 (input_bfd
, insn
, p
);
17124 /* Do any further special processing. */
17130 case R_PPC64_REL16_HA
:
17131 case R_PPC64_REL16_HIGHA
:
17132 case R_PPC64_REL16_HIGHERA
:
17133 case R_PPC64_REL16_HIGHESTA
:
17134 case R_PPC64_REL16DX_HA
:
17135 case R_PPC64_ADDR16_HA
:
17136 case R_PPC64_ADDR16_HIGHA
:
17137 case R_PPC64_ADDR16_HIGHERA
:
17138 case R_PPC64_ADDR16_HIGHESTA
:
17139 case R_PPC64_TOC16_HA
:
17140 case R_PPC64_SECTOFF_HA
:
17141 case R_PPC64_TPREL16_HA
:
17142 case R_PPC64_TPREL16_HIGHA
:
17143 case R_PPC64_TPREL16_HIGHERA
:
17144 case R_PPC64_TPREL16_HIGHESTA
:
17145 case R_PPC64_DTPREL16_HA
:
17146 case R_PPC64_DTPREL16_HIGHA
:
17147 case R_PPC64_DTPREL16_HIGHERA
:
17148 case R_PPC64_DTPREL16_HIGHESTA
:
17149 /* It's just possible that this symbol is a weak symbol
17150 that's not actually defined anywhere. In that case,
17151 'sec' would be NULL, and we should leave the symbol
17152 alone (it will be set to zero elsewhere in the link). */
17155 /* Fall through. */
17157 case R_PPC64_GOT16_HA
:
17158 case R_PPC64_PLTGOT16_HA
:
17159 case R_PPC64_PLT16_HA
:
17160 case R_PPC64_GOT_TLSGD16_HA
:
17161 case R_PPC64_GOT_TLSLD16_HA
:
17162 case R_PPC64_GOT_TPREL16_HA
:
17163 case R_PPC64_GOT_DTPREL16_HA
:
17164 /* Add 0x10000 if sign bit in 0:15 is set.
17165 Bits 0:15 are not used. */
17169 case R_PPC64_D34_HA30
:
17170 case R_PPC64_ADDR16_HIGHERA34
:
17171 case R_PPC64_ADDR16_HIGHESTA34
:
17172 case R_PPC64_REL16_HIGHERA34
:
17173 case R_PPC64_REL16_HIGHESTA34
:
17175 addend
+= 1ULL << 33;
17178 case R_PPC64_ADDR16_DS
:
17179 case R_PPC64_ADDR16_LO_DS
:
17180 case R_PPC64_GOT16_DS
:
17181 case R_PPC64_GOT16_LO_DS
:
17182 case R_PPC64_PLT16_LO_DS
:
17183 case R_PPC64_SECTOFF_DS
:
17184 case R_PPC64_SECTOFF_LO_DS
:
17185 case R_PPC64_TOC16_DS
:
17186 case R_PPC64_TOC16_LO_DS
:
17187 case R_PPC64_PLTGOT16_DS
:
17188 case R_PPC64_PLTGOT16_LO_DS
:
17189 case R_PPC64_GOT_TPREL16_DS
:
17190 case R_PPC64_GOT_TPREL16_LO_DS
:
17191 case R_PPC64_GOT_DTPREL16_DS
:
17192 case R_PPC64_GOT_DTPREL16_LO_DS
:
17193 case R_PPC64_TPREL16_DS
:
17194 case R_PPC64_TPREL16_LO_DS
:
17195 case R_PPC64_DTPREL16_DS
:
17196 case R_PPC64_DTPREL16_LO_DS
:
17197 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17199 /* If this reloc is against an lq, lxv, or stxv insn, then
17200 the value must be a multiple of 16. This is somewhat of
17201 a hack, but the "correct" way to do this by defining _DQ
17202 forms of all the _DS relocs bloats all reloc switches in
17203 this file. It doesn't make much sense to use these
17204 relocs in data, so testing the insn should be safe. */
17205 if ((insn
& (0x3fu
<< 26)) == (56u << 26)
17206 || ((insn
& (0x3fu
<< 26)) == (61u << 26) && (insn
& 3) == 1))
17208 relocation
+= addend
;
17209 addend
= insn
& (mask
^ 3);
17210 if ((relocation
& mask
) != 0)
17212 relocation
^= relocation
& mask
;
17213 info
->callbacks
->einfo
17214 /* xgettext:c-format */
17215 (_("%H: error: %s not a multiple of %u\n"),
17216 input_bfd
, input_section
, rel
->r_offset
,
17217 ppc64_elf_howto_table
[r_type
]->name
,
17219 bfd_set_error (bfd_error_bad_value
);
17226 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
17227 because such sections are not SEC_ALLOC and thus ld.so will
17228 not process them. */
17229 howto
= ppc64_elf_howto_table
[(int) r_type
];
17230 if (unresolved_reloc
17231 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
17232 && h
->elf
.def_dynamic
)
17233 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
17234 rel
->r_offset
) != (bfd_vma
) -1)
17236 info
->callbacks
->einfo
17237 /* xgettext:c-format */
17238 (_("%H: unresolvable %s against `%pT'\n"),
17239 input_bfd
, input_section
, rel
->r_offset
,
17241 h
->elf
.root
.root
.string
);
17245 /* 16-bit fields in insns mostly have signed values, but a
17246 few insns have 16-bit unsigned values. Really, we should
17247 have different reloc types. */
17248 if (howto
->complain_on_overflow
!= complain_overflow_dont
17249 && howto
->dst_mask
== 0xffff
17250 && (input_section
->flags
& SEC_CODE
) != 0)
17252 enum complain_overflow complain
= complain_overflow_signed
;
17254 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17255 if ((insn
& (0x3fu
<< 26)) == 10u << 26 /* cmpli */)
17256 complain
= complain_overflow_bitfield
;
17257 else if (howto
->rightshift
== 0
17258 ? ((insn
& (0x3fu
<< 26)) == 28u << 26 /* andi */
17259 || (insn
& (0x3fu
<< 26)) == 24u << 26 /* ori */
17260 || (insn
& (0x3fu
<< 26)) == 26u << 26 /* xori */)
17261 : ((insn
& (0x3fu
<< 26)) == 29u << 26 /* andis */
17262 || (insn
& (0x3fu
<< 26)) == 25u << 26 /* oris */
17263 || (insn
& (0x3fu
<< 26)) == 27u << 26 /* xoris */))
17264 complain
= complain_overflow_unsigned
;
17265 if (howto
->complain_on_overflow
!= complain
)
17267 alt_howto
= *howto
;
17268 alt_howto
.complain_on_overflow
= complain
;
17269 howto
= &alt_howto
;
17275 /* Split field relocs aren't handled by _bfd_final_link_relocate. */
17277 case R_PPC64_D34_LO
:
17278 case R_PPC64_D34_HI30
:
17279 case R_PPC64_D34_HA30
:
17280 case R_PPC64_PCREL34
:
17281 case R_PPC64_GOT_PCREL34
:
17282 case R_PPC64_TPREL34
:
17283 case R_PPC64_DTPREL34
:
17284 case R_PPC64_GOT_TLSGD_PCREL34
:
17285 case R_PPC64_GOT_TLSLD_PCREL34
:
17286 case R_PPC64_GOT_TPREL_PCREL34
:
17287 case R_PPC64_GOT_DTPREL_PCREL34
:
17288 case R_PPC64_PLT_PCREL34
:
17289 case R_PPC64_PLT_PCREL34_NOTOC
:
17291 case R_PPC64_PCREL28
:
17292 if (rel
->r_offset
+ 8 > input_section
->size
)
17293 r
= bfd_reloc_outofrange
;
17296 relocation
+= addend
;
17297 if (howto
->pc_relative
)
17298 relocation
-= (rel
->r_offset
17299 + input_section
->output_offset
17300 + input_section
->output_section
->vma
);
17301 relocation
>>= howto
->rightshift
;
17303 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17305 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
17307 pinsn
&= ~howto
->dst_mask
;
17308 pinsn
|= (((relocation
<< 16) | (relocation
& 0xffff))
17309 & howto
->dst_mask
);
17310 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ rel
->r_offset
);
17311 bfd_put_32 (input_bfd
, pinsn
, contents
+ rel
->r_offset
+ 4);
17313 if (howto
->complain_on_overflow
== complain_overflow_signed
17314 && (relocation
+ (1ULL << (howto
->bitsize
- 1))
17315 >= 1ULL << howto
->bitsize
))
17316 r
= bfd_reloc_overflow
;
17320 case R_PPC64_REL16DX_HA
:
17321 if (rel
->r_offset
+ 4 > input_section
->size
)
17322 r
= bfd_reloc_outofrange
;
17325 relocation
+= addend
;
17326 relocation
-= (rel
->r_offset
17327 + input_section
->output_offset
17328 + input_section
->output_section
->vma
);
17329 relocation
= (bfd_signed_vma
) relocation
>> 16;
17330 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17332 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
17333 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
17335 if (relocation
+ 0x8000 > 0xffff)
17336 r
= bfd_reloc_overflow
;
17341 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
17342 contents
, rel
->r_offset
,
17343 relocation
, addend
);
17346 if (r
!= bfd_reloc_ok
)
17348 char *more_info
= NULL
;
17349 const char *reloc_name
= howto
->name
;
17351 if (reloc_dest
!= DEST_NORMAL
)
17353 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
17354 if (more_info
!= NULL
)
17356 strcpy (more_info
, reloc_name
);
17357 strcat (more_info
, (reloc_dest
== DEST_OPD
17358 ? " (OPD)" : " (stub)"));
17359 reloc_name
= more_info
;
17363 if (r
== bfd_reloc_overflow
)
17365 /* On code like "if (foo) foo();" don't report overflow
17366 on a branch to zero when foo is undefined. */
17368 && (reloc_dest
== DEST_STUB
17370 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
17371 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
17372 && is_branch_reloc (r_type
))))
17373 info
->callbacks
->reloc_overflow
17374 (info
, (struct bfd_link_hash_entry
*) h
, sym_name
,
17375 reloc_name
, orig_rel
.r_addend
, input_bfd
, input_section
,
17380 info
->callbacks
->einfo
17381 /* xgettext:c-format */
17382 (_("%H: %s against `%pT': error %d\n"),
17383 input_bfd
, input_section
, rel
->r_offset
,
17384 reloc_name
, sym_name
, (int) r
);
17396 Elf_Internal_Shdr
*rel_hdr
;
17397 size_t deleted
= rel
- wrel
;
17399 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
17400 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17401 if (rel_hdr
->sh_size
== 0)
17403 /* It is too late to remove an empty reloc section. Leave
17405 ??? What is wrong with an empty section??? */
17406 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
17409 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
17410 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17411 input_section
->reloc_count
-= deleted
;
17414 /* If we're emitting relocations, then shortly after this function
17415 returns, reloc offsets and addends for this section will be
17416 adjusted. Worse, reloc symbol indices will be for the output
17417 file rather than the input. Save a copy of the relocs for
17418 opd_entry_value. */
17419 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
17422 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
17423 rel
= bfd_alloc (input_bfd
, amt
);
17424 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
17425 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
17428 memcpy (rel
, relocs
, amt
);
17433 /* Adjust the value of any local symbols in opd sections. */
17436 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
17437 const char *name ATTRIBUTE_UNUSED
,
17438 Elf_Internal_Sym
*elfsym
,
17439 asection
*input_sec
,
17440 struct elf_link_hash_entry
*h
)
17442 struct _opd_sec_data
*opd
;
17449 opd
= get_opd_info (input_sec
);
17450 if (opd
== NULL
|| opd
->adjust
== NULL
)
17453 value
= elfsym
->st_value
- input_sec
->output_offset
;
17454 if (!bfd_link_relocatable (info
))
17455 value
-= input_sec
->output_section
->vma
;
17457 adjust
= opd
->adjust
[OPD_NDX (value
)];
17461 elfsym
->st_value
+= adjust
;
17465 /* Finish up dynamic symbol handling. We set the contents of various
17466 dynamic sections here. */
17469 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
17470 struct bfd_link_info
*info
,
17471 struct elf_link_hash_entry
*h
,
17472 Elf_Internal_Sym
*sym
)
17474 struct ppc_link_hash_table
*htab
;
17475 struct plt_entry
*ent
;
17477 htab
= ppc_hash_table (info
);
17481 if (!htab
->opd_abi
&& !h
->def_regular
)
17482 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
17483 if (ent
->plt
.offset
!= (bfd_vma
) -1)
17485 /* Mark the symbol as undefined, rather than as
17486 defined in glink. Leave the value if there were
17487 any relocations where pointer equality matters
17488 (this is a clue for the dynamic linker, to make
17489 function pointer comparisons work between an
17490 application and shared library), otherwise set it
17492 sym
->st_shndx
= SHN_UNDEF
;
17493 if (!h
->pointer_equality_needed
)
17495 else if (!h
->ref_regular_nonweak
)
17497 /* This breaks function pointer comparisons, but
17498 that is better than breaking tests for a NULL
17499 function pointer. */
17506 && (h
->root
.type
== bfd_link_hash_defined
17507 || h
->root
.type
== bfd_link_hash_defweak
)
17508 && (h
->root
.u
.def
.section
== htab
->elf
.sdynbss
17509 || h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
))
17511 /* This symbol needs a copy reloc. Set it up. */
17512 Elf_Internal_Rela rela
;
17516 if (h
->dynindx
== -1)
17519 rela
.r_offset
= defined_sym_val (h
);
17520 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
17522 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
17523 srel
= htab
->elf
.sreldynrelro
;
17525 srel
= htab
->elf
.srelbss
;
17526 loc
= srel
->contents
;
17527 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
17528 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
17534 /* Used to decide how to sort relocs in an optimal manner for the
17535 dynamic linker, before writing them out. */
17537 static enum elf_reloc_type_class
17538 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
17539 const asection
*rel_sec
,
17540 const Elf_Internal_Rela
*rela
)
17542 enum elf_ppc64_reloc_type r_type
;
17543 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
17545 if (rel_sec
== htab
->elf
.irelplt
)
17546 return reloc_class_ifunc
;
17548 r_type
= ELF64_R_TYPE (rela
->r_info
);
17551 case R_PPC64_RELATIVE
:
17552 return reloc_class_relative
;
17553 case R_PPC64_JMP_SLOT
:
17554 return reloc_class_plt
;
17556 return reloc_class_copy
;
17558 return reloc_class_normal
;
17562 /* Finish up the dynamic sections. */
17565 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
17566 struct bfd_link_info
*info
)
17568 struct ppc_link_hash_table
*htab
;
17572 htab
= ppc_hash_table (info
);
17576 dynobj
= htab
->elf
.dynobj
;
17577 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
17579 if (htab
->elf
.dynamic_sections_created
)
17581 Elf64_External_Dyn
*dyncon
, *dynconend
;
17583 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
17586 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
17587 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
17588 for (; dyncon
< dynconend
; dyncon
++)
17590 Elf_Internal_Dyn dyn
;
17593 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
17600 case DT_PPC64_GLINK
:
17602 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17603 /* We stupidly defined DT_PPC64_GLINK to be the start
17604 of glink rather than the first entry point, which is
17605 what ld.so needs, and now have a bigger stub to
17606 support automatic multiple TOCs. */
17607 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
17611 s
= bfd_get_section_by_name (output_bfd
, ".opd");
17614 dyn
.d_un
.d_ptr
= s
->vma
;
17618 if ((htab
->do_multi_toc
&& htab
->multi_toc_needed
)
17619 || htab
->notoc_plt
)
17620 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
17621 if (htab
->has_plt_localentry0
)
17622 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
17625 case DT_PPC64_OPDSZ
:
17626 s
= bfd_get_section_by_name (output_bfd
, ".opd");
17629 dyn
.d_un
.d_val
= s
->size
;
17633 s
= htab
->elf
.splt
;
17634 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17638 s
= htab
->elf
.srelplt
;
17639 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17643 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
17647 if (htab
->elf
.ifunc_resolvers
)
17648 info
->callbacks
->einfo
17649 (_("%P: warning: text relocations and GNU indirect "
17650 "functions may result in a segfault at runtime\n"));
17654 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17658 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
17659 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
17661 /* Fill in the first entry in the global offset table.
17662 We use it to hold the link-time TOCbase. */
17663 bfd_put_64 (output_bfd
,
17664 elf_gp (output_bfd
) + TOC_BASE_OFF
,
17665 htab
->elf
.sgot
->contents
);
17667 /* Set .got entry size. */
17668 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
17672 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
17673 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
17675 /* Set .plt entry size. */
17676 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
17677 = PLT_ENTRY_SIZE (htab
);
17680 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
17681 brlt ourselves if emitrelocations. */
17682 if (htab
->brlt
!= NULL
17683 && htab
->brlt
->reloc_count
!= 0
17684 && !_bfd_elf_link_output_relocs (output_bfd
,
17686 elf_section_data (htab
->brlt
)->rela
.hdr
,
17687 elf_section_data (htab
->brlt
)->relocs
,
17691 if (htab
->glink
!= NULL
17692 && htab
->glink
->reloc_count
!= 0
17693 && !_bfd_elf_link_output_relocs (output_bfd
,
17695 elf_section_data (htab
->glink
)->rela
.hdr
,
17696 elf_section_data (htab
->glink
)->relocs
,
17701 if (htab
->glink_eh_frame
!= NULL
17702 && htab
->glink_eh_frame
->size
!= 0
17703 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
17704 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
17705 htab
->glink_eh_frame
,
17706 htab
->glink_eh_frame
->contents
))
17709 /* We need to handle writing out multiple GOT sections ourselves,
17710 since we didn't add them to DYNOBJ. We know dynobj is the first
17712 while ((dynobj
= dynobj
->link
.next
) != NULL
)
17716 if (!is_ppc64_elf (dynobj
))
17719 s
= ppc64_elf_tdata (dynobj
)->got
;
17722 && s
->output_section
!= bfd_abs_section_ptr
17723 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
17724 s
->contents
, s
->output_offset
,
17727 s
= ppc64_elf_tdata (dynobj
)->relgot
;
17730 && s
->output_section
!= bfd_abs_section_ptr
17731 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
17732 s
->contents
, s
->output_offset
,
17740 #include "elf64-target.h"
17742 /* FreeBSD support */
17744 #undef TARGET_LITTLE_SYM
17745 #define TARGET_LITTLE_SYM powerpc_elf64_fbsd_le_vec
17746 #undef TARGET_LITTLE_NAME
17747 #define TARGET_LITTLE_NAME "elf64-powerpcle-freebsd"
17749 #undef TARGET_BIG_SYM
17750 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
17751 #undef TARGET_BIG_NAME
17752 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
17755 #define ELF_OSABI ELFOSABI_FREEBSD
17758 #define elf64_bed elf64_powerpc_fbsd_bed
17760 #include "elf64-target.h"