1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2022 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5 Largely rewritten by Alan Modra.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
28 /* The assembler should generate a full set of section symbols even
29 when they appear unused. The linux kernel build tool recordmcount
31 #define TARGET_KEEP_UNUSED_SECTION_SYMBOLS true
39 #include "elf/ppc64.h"
40 #include "elf64-ppc.h"
43 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
44 #define OCTETS_PER_BYTE(ABFD, SEC) 1
46 static bfd_reloc_status_type ppc64_elf_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_branch_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_reloc_status_type ppc64_elf_toc_reloc
57 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
58 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
59 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
60 static bfd_reloc_status_type ppc64_elf_toc64_reloc
61 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
62 static bfd_reloc_status_type ppc64_elf_prefix_reloc
63 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
64 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
65 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
66 static bfd_vma opd_entry_value
67 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bool);
69 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
70 #define TARGET_LITTLE_NAME "elf64-powerpcle"
71 #define TARGET_BIG_SYM powerpc_elf64_vec
72 #define TARGET_BIG_NAME "elf64-powerpc"
73 #define ELF_ARCH bfd_arch_powerpc
74 #define ELF_TARGET_ID PPC64_ELF_DATA
75 #define ELF_MACHINE_CODE EM_PPC64
76 #define ELF_MAXPAGESIZE 0x10000
77 #define ELF_COMMONPAGESIZE 0x1000
78 #define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
79 #define elf_info_to_howto ppc64_elf_info_to_howto
81 #define elf_backend_want_got_sym 0
82 #define elf_backend_want_plt_sym 0
83 #define elf_backend_plt_alignment 3
84 #define elf_backend_plt_not_loaded 1
85 #define elf_backend_got_header_size 8
86 #define elf_backend_want_dynrelro 1
87 #define elf_backend_can_gc_sections 1
88 #define elf_backend_can_refcount 1
89 #define elf_backend_rela_normal 1
90 #define elf_backend_dtrel_excludes_plt 1
91 #define elf_backend_default_execstack 0
93 #define bfd_elf64_mkobject ppc64_elf_mkobject
94 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
95 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
96 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
97 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
98 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
99 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
100 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
101 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
102 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
104 #define elf_backend_object_p ppc64_elf_object_p
105 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
106 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
107 #define elf_backend_write_core_note ppc64_elf_write_core_note
108 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
109 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
110 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
111 #define elf_backend_check_directives ppc64_elf_before_check_relocs
112 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
113 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
114 #define elf_backend_check_relocs ppc64_elf_check_relocs
115 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
116 #define elf_backend_gc_keep ppc64_elf_gc_keep
117 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
118 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
119 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
120 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
121 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
122 #define elf_backend_always_size_sections ppc64_elf_edit
123 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
124 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
125 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
126 #define elf_backend_action_discarded ppc64_elf_action_discarded
127 #define elf_backend_relocate_section ppc64_elf_relocate_section
128 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
129 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
130 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
131 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
132 #define elf_backend_special_sections ppc64_elf_special_sections
133 #define elf_backend_section_flags ppc64_elf_section_flags
134 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
135 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
136 #define elf_backend_get_reloc_section bfd_get_section_by_name
138 /* The name of the dynamic interpreter. This is put in the .interp
140 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
142 /* The size in bytes of an entry in the procedure linkage table. */
143 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
144 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
146 /* The initial size of the plt reserved for the dynamic linker. */
147 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
149 /* Offsets to some stack save slots. */
151 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
152 /* This one is dodgy. ELFv2 does not have a linker word, so use the
153 CR save slot. Used only by optimised __tls_get_addr call stub,
154 relying on __tls_get_addr_opt not saving CR.. */
155 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
157 /* TOC base pointers offset from start of TOC. */
158 #define TOC_BASE_OFF 0x8000
159 /* TOC base alignment. */
160 #define TOC_BASE_ALIGN 256
162 /* Offset of tp and dtp pointers from start of TLS block. */
163 #define TP_OFFSET 0x7000
164 #define DTP_OFFSET 0x8000
166 /* .plt call stub instructions. The normal stub is like this, but
167 sometimes the .plt entry crosses a 64k boundary and we need to
168 insert an addi to adjust r11. */
169 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
170 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
171 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
172 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
173 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
174 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
175 #define BCTR 0x4e800420 /* bctr */
177 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
178 #define ADDI_R12_R11 0x398b0000 /* addi %r12,%r11,off@l */
179 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
180 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
181 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
183 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
184 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
185 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
186 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
187 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
188 #define BNECTR 0x4ca20420 /* bnectr+ */
189 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
191 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
192 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
193 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
195 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
196 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
197 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
199 #define LI_R11_0 0x39600000 /* li %r11,0 */
200 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
201 #define LIS_R11 0x3d600000 /* lis %r11,xxx@ha */
202 #define LIS_R12 0x3d800000 /* lis %r12,xxx@ha */
203 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
204 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
205 #define ADDIS_R12_R11 0x3d8b0000 /* addis %r12,%r11,xxx@ha */
206 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
207 #define ORIS_R12_R12_0 0x658c0000 /* oris %r12,%r12,xxx@hi */
208 #define ORI_R11_R11_0 0x616b0000 /* ori %r11,%r11,xxx@l */
209 #define ORI_R12_R12_0 0x618c0000 /* ori %r12,%r12,xxx@l */
210 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
211 #define SLDI_R11_R11_34 0x796b1746 /* sldi %r11,%r11,34 */
212 #define SLDI_R12_R12_32 0x799c07c6 /* sldi %r12,%r12,32 */
213 #define LDX_R12_R11_R12 0x7d8b602a /* ldx %r12,%r11,%r12 */
214 #define ADD_R12_R11_R12 0x7d8b6214 /* add %r12,%r11,%r12 */
215 #define PADDI_R12_PC 0x0610000039800000ULL
216 #define PLD_R12_PC 0x04100000e5800000ULL
217 #define PNOP 0x0700000000000000ULL
219 /* __glink_PLTresolve stub instructions. We enter with the index in
220 R0 for ELFv1, and the address of a glink branch in R12 for ELFv2. */
221 #define GLINK_PLTRESOLVE_SIZE(htab) \
222 (8u + (htab->opd_abi ? 11 * 4 : htab->has_plt_localentry0 ? 14 * 4 : 13 * 4))
226 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
227 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
229 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
230 /* ld %2,(0b-1b)(%11) */
231 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
232 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
239 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
240 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
241 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
242 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
243 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
244 #define LD_R0_0R11 0xe80b0000 /* ld %r0,0(%r11) */
245 #define ADD_R11_R0_R11 0x7d605a14 /* add %r11,%r0,%r11 */
248 #define NOP 0x60000000
250 /* Some other nops. */
251 #define CROR_151515 0x4def7b82
252 #define CROR_313131 0x4ffffb82
254 /* .glink entries for the first 32k functions are two instructions. */
255 #define LI_R0_0 0x38000000 /* li %r0,0 */
256 #define B_DOT 0x48000000 /* b . */
258 /* After that, we need two instructions to load the index, followed by
260 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
261 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
263 /* Instructions used by the save and restore reg functions. */
264 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
265 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
266 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
267 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
268 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
269 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
270 #define LI_R12_0 0x39800000 /* li %r12,0 */
271 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
272 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
273 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
274 #define BLR 0x4e800020 /* blr */
276 /* Since .opd is an array of descriptors and each entry will end up
277 with identical R_PPC64_RELATIVE relocs, there is really no need to
278 propagate .opd relocs; The dynamic linker should be taught to
279 relocate .opd without reloc entries. */
280 #ifndef NO_OPD_RELOCS
281 #define NO_OPD_RELOCS 0
285 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
289 abiversion (bfd
*abfd
)
291 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
295 set_abiversion (bfd
*abfd
, int ver
)
297 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
298 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
301 /* Relocation HOWTO's. */
302 /* Like other ELF RELA targets that don't apply multiple
303 field-altering relocations to the same localation, src_mask is
304 always zero and pcrel_offset is the same as pc_relative.
305 PowerPC can always use a zero bitpos, even when the field is not at
306 the LSB. For example, a REL24 could use rightshift=2, bisize=24
307 and bitpos=2 which matches the ABI description, or as we do here,
308 rightshift=0, bitsize=26 and bitpos=0. */
309 #define HOW(type, size, bitsize, mask, rightshift, pc_relative, \
310 complain, special_func) \
311 HOWTO (type, rightshift, size, bitsize, pc_relative, 0, \
312 complain_overflow_ ## complain, special_func, \
313 #type, false, 0, mask, pc_relative)
315 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
317 static reloc_howto_type ppc64_elf_howto_raw
[] =
319 /* This reloc does nothing. */
320 HOW (R_PPC64_NONE
, 3, 0, 0, 0, false, dont
,
321 bfd_elf_generic_reloc
),
323 /* A standard 32 bit relocation. */
324 HOW (R_PPC64_ADDR32
, 2, 32, 0xffffffff, 0, false, bitfield
,
325 bfd_elf_generic_reloc
),
327 /* An absolute 26 bit branch; the lower two bits must be zero.
328 FIXME: we don't check that, we just clear them. */
329 HOW (R_PPC64_ADDR24
, 2, 26, 0x03fffffc, 0, false, bitfield
,
330 bfd_elf_generic_reloc
),
332 /* A standard 16 bit relocation. */
333 HOW (R_PPC64_ADDR16
, 1, 16, 0xffff, 0, false, bitfield
,
334 bfd_elf_generic_reloc
),
336 /* A 16 bit relocation without overflow. */
337 HOW (R_PPC64_ADDR16_LO
, 1, 16, 0xffff, 0, false, dont
,
338 bfd_elf_generic_reloc
),
340 /* Bits 16-31 of an address. */
341 HOW (R_PPC64_ADDR16_HI
, 1, 16, 0xffff, 16, false, signed,
342 bfd_elf_generic_reloc
),
344 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
345 bits, treated as a signed number, is negative. */
346 HOW (R_PPC64_ADDR16_HA
, 1, 16, 0xffff, 16, false, signed,
349 /* An absolute 16 bit branch; the lower two bits must be zero.
350 FIXME: we don't check that, we just clear them. */
351 HOW (R_PPC64_ADDR14
, 2, 16, 0x0000fffc, 0, false, signed,
352 ppc64_elf_branch_reloc
),
354 /* An absolute 16 bit branch, for which bit 10 should be set to
355 indicate that the branch is expected to be taken. The lower two
356 bits must be zero. */
357 HOW (R_PPC64_ADDR14_BRTAKEN
, 2, 16, 0x0000fffc, 0, false, signed,
358 ppc64_elf_brtaken_reloc
),
360 /* An absolute 16 bit branch, for which bit 10 should be set to
361 indicate that the branch is not expected to be taken. The lower
362 two bits must be zero. */
363 HOW (R_PPC64_ADDR14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, false, signed,
364 ppc64_elf_brtaken_reloc
),
366 /* A relative 26 bit branch; the lower two bits must be zero. */
367 HOW (R_PPC64_REL24
, 2, 26, 0x03fffffc, 0, true, signed,
368 ppc64_elf_branch_reloc
),
370 /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer. */
371 HOW (R_PPC64_REL24_NOTOC
, 2, 26, 0x03fffffc, 0, true, signed,
372 ppc64_elf_branch_reloc
),
374 /* Another variant, when p10 insns can't be used on stubs. */
375 HOW (R_PPC64_REL24_P9NOTOC
, 2, 26, 0x03fffffc, 0, true, signed,
376 ppc64_elf_branch_reloc
),
378 /* A relative 16 bit branch; the lower two bits must be zero. */
379 HOW (R_PPC64_REL14
, 2, 16, 0x0000fffc, 0, true, signed,
380 ppc64_elf_branch_reloc
),
382 /* A relative 16 bit branch. Bit 10 should be set to indicate that
383 the branch is expected to be taken. The lower two bits must be
385 HOW (R_PPC64_REL14_BRTAKEN
, 2, 16, 0x0000fffc, 0, true, signed,
386 ppc64_elf_brtaken_reloc
),
388 /* A relative 16 bit branch. Bit 10 should be set to indicate that
389 the branch is not expected to be taken. The lower two bits must
391 HOW (R_PPC64_REL14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, true, signed,
392 ppc64_elf_brtaken_reloc
),
394 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
396 HOW (R_PPC64_GOT16
, 1, 16, 0xffff, 0, false, signed,
397 ppc64_elf_unhandled_reloc
),
399 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
401 HOW (R_PPC64_GOT16_LO
, 1, 16, 0xffff, 0, false, dont
,
402 ppc64_elf_unhandled_reloc
),
404 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
406 HOW (R_PPC64_GOT16_HI
, 1, 16, 0xffff, 16, false, signed,
407 ppc64_elf_unhandled_reloc
),
409 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
411 HOW (R_PPC64_GOT16_HA
, 1, 16, 0xffff, 16, false, signed,
412 ppc64_elf_unhandled_reloc
),
414 /* This is used only by the dynamic linker. The symbol should exist
415 both in the object being run and in some shared library. The
416 dynamic linker copies the data addressed by the symbol from the
417 shared library into the object, because the object being
418 run has to have the data at some particular address. */
419 HOW (R_PPC64_COPY
, 0, 0, 0, 0, false, dont
,
420 ppc64_elf_unhandled_reloc
),
422 /* Like R_PPC64_ADDR64, but used when setting global offset table
424 HOW (R_PPC64_GLOB_DAT
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
425 ppc64_elf_unhandled_reloc
),
427 /* Created by the link editor. Marks a procedure linkage table
428 entry for a symbol. */
429 HOW (R_PPC64_JMP_SLOT
, 0, 0, 0, 0, false, dont
,
430 ppc64_elf_unhandled_reloc
),
432 /* Used only by the dynamic linker. When the object is run, this
433 doubleword64 is set to the load address of the object, plus the
435 HOW (R_PPC64_RELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
436 bfd_elf_generic_reloc
),
438 /* Like R_PPC64_ADDR32, but may be unaligned. */
439 HOW (R_PPC64_UADDR32
, 2, 32, 0xffffffff, 0, false, bitfield
,
440 bfd_elf_generic_reloc
),
442 /* Like R_PPC64_ADDR16, but may be unaligned. */
443 HOW (R_PPC64_UADDR16
, 1, 16, 0xffff, 0, false, bitfield
,
444 bfd_elf_generic_reloc
),
446 /* 32-bit PC relative. */
447 HOW (R_PPC64_REL32
, 2, 32, 0xffffffff, 0, true, signed,
448 bfd_elf_generic_reloc
),
450 /* 32-bit relocation to the symbol's procedure linkage table. */
451 HOW (R_PPC64_PLT32
, 2, 32, 0xffffffff, 0, false, bitfield
,
452 ppc64_elf_unhandled_reloc
),
454 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
455 FIXME: R_PPC64_PLTREL32 not supported. */
456 HOW (R_PPC64_PLTREL32
, 2, 32, 0xffffffff, 0, true, signed,
457 ppc64_elf_unhandled_reloc
),
459 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
461 HOW (R_PPC64_PLT16_LO
, 1, 16, 0xffff, 0, false, dont
,
462 ppc64_elf_unhandled_reloc
),
464 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
466 HOW (R_PPC64_PLT16_HI
, 1, 16, 0xffff, 16, false, signed,
467 ppc64_elf_unhandled_reloc
),
469 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
471 HOW (R_PPC64_PLT16_HA
, 1, 16, 0xffff, 16, false, signed,
472 ppc64_elf_unhandled_reloc
),
474 /* 16-bit section relative relocation. */
475 HOW (R_PPC64_SECTOFF
, 1, 16, 0xffff, 0, false, signed,
476 ppc64_elf_sectoff_reloc
),
478 /* Like R_PPC64_SECTOFF, but no overflow warning. */
479 HOW (R_PPC64_SECTOFF_LO
, 1, 16, 0xffff, 0, false, dont
,
480 ppc64_elf_sectoff_reloc
),
482 /* 16-bit upper half section relative relocation. */
483 HOW (R_PPC64_SECTOFF_HI
, 1, 16, 0xffff, 16, false, signed,
484 ppc64_elf_sectoff_reloc
),
486 /* 16-bit upper half adjusted section relative relocation. */
487 HOW (R_PPC64_SECTOFF_HA
, 1, 16, 0xffff, 16, false, signed,
488 ppc64_elf_sectoff_ha_reloc
),
490 /* Like R_PPC64_REL24 without touching the two least significant bits. */
491 HOW (R_PPC64_REL30
, 2, 30, 0xfffffffc, 2, true, dont
,
492 bfd_elf_generic_reloc
),
494 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
496 /* A standard 64-bit relocation. */
497 HOW (R_PPC64_ADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
498 bfd_elf_generic_reloc
),
500 /* The bits 32-47 of an address. */
501 HOW (R_PPC64_ADDR16_HIGHER
, 1, 16, 0xffff, 32, false, dont
,
502 bfd_elf_generic_reloc
),
504 /* The bits 32-47 of an address, plus 1 if the contents of the low
505 16 bits, treated as a signed number, is negative. */
506 HOW (R_PPC64_ADDR16_HIGHERA
, 1, 16, 0xffff, 32, false, dont
,
509 /* The bits 48-63 of an address. */
510 HOW (R_PPC64_ADDR16_HIGHEST
, 1, 16, 0xffff, 48, false, dont
,
511 bfd_elf_generic_reloc
),
513 /* The bits 48-63 of an address, plus 1 if the contents of the low
514 16 bits, treated as a signed number, is negative. */
515 HOW (R_PPC64_ADDR16_HIGHESTA
, 1, 16, 0xffff, 48, false, dont
,
518 /* Like ADDR64, but may be unaligned. */
519 HOW (R_PPC64_UADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
520 bfd_elf_generic_reloc
),
522 /* 64-bit relative relocation. */
523 HOW (R_PPC64_REL64
, 4, 64, 0xffffffffffffffffULL
, 0, true, dont
,
524 bfd_elf_generic_reloc
),
526 /* 64-bit relocation to the symbol's procedure linkage table. */
527 HOW (R_PPC64_PLT64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
528 ppc64_elf_unhandled_reloc
),
530 /* 64-bit PC relative relocation to the symbol's procedure linkage
532 /* FIXME: R_PPC64_PLTREL64 not supported. */
533 HOW (R_PPC64_PLTREL64
, 4, 64, 0xffffffffffffffffULL
, 0, true, dont
,
534 ppc64_elf_unhandled_reloc
),
536 /* 16 bit TOC-relative relocation. */
537 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
538 HOW (R_PPC64_TOC16
, 1, 16, 0xffff, 0, false, signed,
539 ppc64_elf_toc_reloc
),
541 /* 16 bit TOC-relative relocation without overflow. */
542 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
543 HOW (R_PPC64_TOC16_LO
, 1, 16, 0xffff, 0, false, dont
,
544 ppc64_elf_toc_reloc
),
546 /* 16 bit TOC-relative relocation, high 16 bits. */
547 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
548 HOW (R_PPC64_TOC16_HI
, 1, 16, 0xffff, 16, false, signed,
549 ppc64_elf_toc_reloc
),
551 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
552 contents of the low 16 bits, treated as a signed number, is
554 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
555 HOW (R_PPC64_TOC16_HA
, 1, 16, 0xffff, 16, false, signed,
556 ppc64_elf_toc_ha_reloc
),
558 /* 64-bit relocation; insert value of TOC base (.TOC.). */
559 /* R_PPC64_TOC 51 doubleword64 .TOC. */
560 HOW (R_PPC64_TOC
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
561 ppc64_elf_toc64_reloc
),
563 /* Like R_PPC64_GOT16, but also informs the link editor that the
564 value to relocate may (!) refer to a PLT entry which the link
565 editor (a) may replace with the symbol value. If the link editor
566 is unable to fully resolve the symbol, it may (b) create a PLT
567 entry and store the address to the new PLT entry in the GOT.
568 This permits lazy resolution of function symbols at run time.
569 The link editor may also skip all of this and just (c) emit a
570 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
571 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
572 HOW (R_PPC64_PLTGOT16
, 1, 16, 0xffff, 0, false,signed,
573 ppc64_elf_unhandled_reloc
),
575 /* Like R_PPC64_PLTGOT16, but without overflow. */
576 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
577 HOW (R_PPC64_PLTGOT16_LO
, 1, 16, 0xffff, 0, false, dont
,
578 ppc64_elf_unhandled_reloc
),
580 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
581 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
582 HOW (R_PPC64_PLTGOT16_HI
, 1, 16, 0xffff, 16, false, signed,
583 ppc64_elf_unhandled_reloc
),
585 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
586 1 if the contents of the low 16 bits, treated as a signed number,
588 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
589 HOW (R_PPC64_PLTGOT16_HA
, 1, 16, 0xffff, 16, false, signed,
590 ppc64_elf_unhandled_reloc
),
592 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
593 HOW (R_PPC64_ADDR16_DS
, 1, 16, 0xfffc, 0, false, signed,
594 bfd_elf_generic_reloc
),
596 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
597 HOW (R_PPC64_ADDR16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
598 bfd_elf_generic_reloc
),
600 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
601 HOW (R_PPC64_GOT16_DS
, 1, 16, 0xfffc, 0, false, signed,
602 ppc64_elf_unhandled_reloc
),
604 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
605 HOW (R_PPC64_GOT16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
606 ppc64_elf_unhandled_reloc
),
608 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
609 HOW (R_PPC64_PLT16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
610 ppc64_elf_unhandled_reloc
),
612 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
613 HOW (R_PPC64_SECTOFF_DS
, 1, 16, 0xfffc, 0, false, signed,
614 ppc64_elf_sectoff_reloc
),
616 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
617 HOW (R_PPC64_SECTOFF_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
618 ppc64_elf_sectoff_reloc
),
620 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
621 HOW (R_PPC64_TOC16_DS
, 1, 16, 0xfffc, 0, false, signed,
622 ppc64_elf_toc_reloc
),
624 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
625 HOW (R_PPC64_TOC16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
626 ppc64_elf_toc_reloc
),
628 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
629 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
630 HOW (R_PPC64_PLTGOT16_DS
, 1, 16, 0xfffc, 0, false, signed,
631 ppc64_elf_unhandled_reloc
),
633 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
634 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
635 HOW (R_PPC64_PLTGOT16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
636 ppc64_elf_unhandled_reloc
),
638 /* Marker relocs for TLS. */
639 HOW (R_PPC64_TLS
, 2, 32, 0, 0, false, dont
,
640 bfd_elf_generic_reloc
),
642 HOW (R_PPC64_TLSGD
, 2, 32, 0, 0, false, dont
,
643 bfd_elf_generic_reloc
),
645 HOW (R_PPC64_TLSLD
, 2, 32, 0, 0, false, dont
,
646 bfd_elf_generic_reloc
),
648 /* Marker reloc for optimizing r2 save in prologue rather than on
649 each plt call stub. */
650 HOW (R_PPC64_TOCSAVE
, 2, 32, 0, 0, false, dont
,
651 bfd_elf_generic_reloc
),
653 /* Marker relocs on inline plt call instructions. */
654 HOW (R_PPC64_PLTSEQ
, 2, 32, 0, 0, false, dont
,
655 bfd_elf_generic_reloc
),
657 HOW (R_PPC64_PLTCALL
, 2, 32, 0, 0, false, dont
,
658 bfd_elf_generic_reloc
),
660 /* Computes the load module index of the load module that contains the
661 definition of its TLS sym. */
662 HOW (R_PPC64_DTPMOD64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
663 ppc64_elf_unhandled_reloc
),
665 /* Computes a dtv-relative displacement, the difference between the value
666 of sym+add and the base address of the thread-local storage block that
667 contains the definition of sym, minus 0x8000. */
668 HOW (R_PPC64_DTPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
669 ppc64_elf_unhandled_reloc
),
671 /* A 16 bit dtprel reloc. */
672 HOW (R_PPC64_DTPREL16
, 1, 16, 0xffff, 0, false, signed,
673 ppc64_elf_unhandled_reloc
),
675 /* Like DTPREL16, but no overflow. */
676 HOW (R_PPC64_DTPREL16_LO
, 1, 16, 0xffff, 0, false, dont
,
677 ppc64_elf_unhandled_reloc
),
679 /* Like DTPREL16_LO, but next higher group of 16 bits. */
680 HOW (R_PPC64_DTPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
681 ppc64_elf_unhandled_reloc
),
683 /* Like DTPREL16_HI, but adjust for low 16 bits. */
684 HOW (R_PPC64_DTPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
685 ppc64_elf_unhandled_reloc
),
687 /* Like DTPREL16_HI, but next higher group of 16 bits. */
688 HOW (R_PPC64_DTPREL16_HIGHER
, 1, 16, 0xffff, 32, false, dont
,
689 ppc64_elf_unhandled_reloc
),
691 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
692 HOW (R_PPC64_DTPREL16_HIGHERA
, 1, 16, 0xffff, 32, false, dont
,
693 ppc64_elf_unhandled_reloc
),
695 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
696 HOW (R_PPC64_DTPREL16_HIGHEST
, 1, 16, 0xffff, 48, false, dont
,
697 ppc64_elf_unhandled_reloc
),
699 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
700 HOW (R_PPC64_DTPREL16_HIGHESTA
, 1, 16, 0xffff, 48, false, dont
,
701 ppc64_elf_unhandled_reloc
),
703 /* Like DTPREL16, but for insns with a DS field. */
704 HOW (R_PPC64_DTPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
705 ppc64_elf_unhandled_reloc
),
707 /* Like DTPREL16_DS, but no overflow. */
708 HOW (R_PPC64_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
709 ppc64_elf_unhandled_reloc
),
711 /* Computes a tp-relative displacement, the difference between the value of
712 sym+add and the value of the thread pointer (r13). */
713 HOW (R_PPC64_TPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
714 ppc64_elf_unhandled_reloc
),
716 /* A 16 bit tprel reloc. */
717 HOW (R_PPC64_TPREL16
, 1, 16, 0xffff, 0, false, signed,
718 ppc64_elf_unhandled_reloc
),
720 /* Like TPREL16, but no overflow. */
721 HOW (R_PPC64_TPREL16_LO
, 1, 16, 0xffff, 0, false, dont
,
722 ppc64_elf_unhandled_reloc
),
724 /* Like TPREL16_LO, but next higher group of 16 bits. */
725 HOW (R_PPC64_TPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
726 ppc64_elf_unhandled_reloc
),
728 /* Like TPREL16_HI, but adjust for low 16 bits. */
729 HOW (R_PPC64_TPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
730 ppc64_elf_unhandled_reloc
),
732 /* Like TPREL16_HI, but next higher group of 16 bits. */
733 HOW (R_PPC64_TPREL16_HIGHER
, 1, 16, 0xffff, 32, false, dont
,
734 ppc64_elf_unhandled_reloc
),
736 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
737 HOW (R_PPC64_TPREL16_HIGHERA
, 1, 16, 0xffff, 32, false, dont
,
738 ppc64_elf_unhandled_reloc
),
740 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
741 HOW (R_PPC64_TPREL16_HIGHEST
, 1, 16, 0xffff, 48, false, dont
,
742 ppc64_elf_unhandled_reloc
),
744 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
745 HOW (R_PPC64_TPREL16_HIGHESTA
, 1, 16, 0xffff, 48, false, dont
,
746 ppc64_elf_unhandled_reloc
),
748 /* Like TPREL16, but for insns with a DS field. */
749 HOW (R_PPC64_TPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
750 ppc64_elf_unhandled_reloc
),
752 /* Like TPREL16_DS, but no overflow. */
753 HOW (R_PPC64_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
754 ppc64_elf_unhandled_reloc
),
756 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
757 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
758 to the first entry relative to the TOC base (r2). */
759 HOW (R_PPC64_GOT_TLSGD16
, 1, 16, 0xffff, 0, false, signed,
760 ppc64_elf_unhandled_reloc
),
762 /* Like GOT_TLSGD16, but no overflow. */
763 HOW (R_PPC64_GOT_TLSGD16_LO
, 1, 16, 0xffff, 0, false, dont
,
764 ppc64_elf_unhandled_reloc
),
766 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
767 HOW (R_PPC64_GOT_TLSGD16_HI
, 1, 16, 0xffff, 16, false, signed,
768 ppc64_elf_unhandled_reloc
),
770 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
771 HOW (R_PPC64_GOT_TLSGD16_HA
, 1, 16, 0xffff, 16, false, signed,
772 ppc64_elf_unhandled_reloc
),
774 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
775 with values (sym+add)@dtpmod and zero, and computes the offset to the
776 first entry relative to the TOC base (r2). */
777 HOW (R_PPC64_GOT_TLSLD16
, 1, 16, 0xffff, 0, false, signed,
778 ppc64_elf_unhandled_reloc
),
780 /* Like GOT_TLSLD16, but no overflow. */
781 HOW (R_PPC64_GOT_TLSLD16_LO
, 1, 16, 0xffff, 0, false, dont
,
782 ppc64_elf_unhandled_reloc
),
784 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
785 HOW (R_PPC64_GOT_TLSLD16_HI
, 1, 16, 0xffff, 16, false, signed,
786 ppc64_elf_unhandled_reloc
),
788 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
789 HOW (R_PPC64_GOT_TLSLD16_HA
, 1, 16, 0xffff, 16, false, signed,
790 ppc64_elf_unhandled_reloc
),
792 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
793 the offset to the entry relative to the TOC base (r2). */
794 HOW (R_PPC64_GOT_DTPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
795 ppc64_elf_unhandled_reloc
),
797 /* Like GOT_DTPREL16_DS, but no overflow. */
798 HOW (R_PPC64_GOT_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
799 ppc64_elf_unhandled_reloc
),
801 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
802 HOW (R_PPC64_GOT_DTPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
803 ppc64_elf_unhandled_reloc
),
805 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
806 HOW (R_PPC64_GOT_DTPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
807 ppc64_elf_unhandled_reloc
),
809 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
810 offset to the entry relative to the TOC base (r2). */
811 HOW (R_PPC64_GOT_TPREL16_DS
, 1, 16, 0xfffc, 0, false, signed,
812 ppc64_elf_unhandled_reloc
),
814 /* Like GOT_TPREL16_DS, but no overflow. */
815 HOW (R_PPC64_GOT_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, false, dont
,
816 ppc64_elf_unhandled_reloc
),
818 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
819 HOW (R_PPC64_GOT_TPREL16_HI
, 1, 16, 0xffff, 16, false, signed,
820 ppc64_elf_unhandled_reloc
),
822 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
823 HOW (R_PPC64_GOT_TPREL16_HA
, 1, 16, 0xffff, 16, false, signed,
824 ppc64_elf_unhandled_reloc
),
826 HOW (R_PPC64_JMP_IREL
, 0, 0, 0, 0, false, dont
,
827 ppc64_elf_unhandled_reloc
),
829 HOW (R_PPC64_IRELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
830 bfd_elf_generic_reloc
),
832 /* A 16 bit relative relocation. */
833 HOW (R_PPC64_REL16
, 1, 16, 0xffff, 0, true, signed,
834 bfd_elf_generic_reloc
),
836 /* A 16 bit relative relocation without overflow. */
837 HOW (R_PPC64_REL16_LO
, 1, 16, 0xffff, 0, true, dont
,
838 bfd_elf_generic_reloc
),
840 /* The high order 16 bits of a relative address. */
841 HOW (R_PPC64_REL16_HI
, 1, 16, 0xffff, 16, true, signed,
842 bfd_elf_generic_reloc
),
844 /* The high order 16 bits of a relative address, plus 1 if the contents of
845 the low 16 bits, treated as a signed number, is negative. */
846 HOW (R_PPC64_REL16_HA
, 1, 16, 0xffff, 16, true, signed,
849 HOW (R_PPC64_REL16_HIGH
, 1, 16, 0xffff, 16, true, dont
,
850 bfd_elf_generic_reloc
),
852 HOW (R_PPC64_REL16_HIGHA
, 1, 16, 0xffff, 16, true, dont
,
855 HOW (R_PPC64_REL16_HIGHER
, 1, 16, 0xffff, 32, true, dont
,
856 bfd_elf_generic_reloc
),
858 HOW (R_PPC64_REL16_HIGHERA
, 1, 16, 0xffff, 32, true, dont
,
861 HOW (R_PPC64_REL16_HIGHEST
, 1, 16, 0xffff, 48, true, dont
,
862 bfd_elf_generic_reloc
),
864 HOW (R_PPC64_REL16_HIGHESTA
, 1, 16, 0xffff, 48, true, dont
,
867 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
868 HOW (R_PPC64_REL16DX_HA
, 2, 16, 0x1fffc1, 16, true, signed,
871 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
872 HOW (R_PPC64_16DX_HA
, 2, 16, 0x1fffc1, 16, false, signed,
875 /* Like R_PPC64_ADDR16_HI, but no overflow. */
876 HOW (R_PPC64_ADDR16_HIGH
, 1, 16, 0xffff, 16, false, dont
,
877 bfd_elf_generic_reloc
),
879 /* Like R_PPC64_ADDR16_HA, but no overflow. */
880 HOW (R_PPC64_ADDR16_HIGHA
, 1, 16, 0xffff, 16, false, dont
,
883 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
884 HOW (R_PPC64_DTPREL16_HIGH
, 1, 16, 0xffff, 16, false, dont
,
885 ppc64_elf_unhandled_reloc
),
887 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
888 HOW (R_PPC64_DTPREL16_HIGHA
, 1, 16, 0xffff, 16, false, dont
,
889 ppc64_elf_unhandled_reloc
),
891 /* Like R_PPC64_TPREL16_HI, but no overflow. */
892 HOW (R_PPC64_TPREL16_HIGH
, 1, 16, 0xffff, 16, false, dont
,
893 ppc64_elf_unhandled_reloc
),
895 /* Like R_PPC64_TPREL16_HA, but no overflow. */
896 HOW (R_PPC64_TPREL16_HIGHA
, 1, 16, 0xffff, 16, false, dont
,
897 ppc64_elf_unhandled_reloc
),
899 /* Marker reloc on ELFv2 large-model function entry. */
900 HOW (R_PPC64_ENTRY
, 2, 32, 0, 0, false, dont
,
901 bfd_elf_generic_reloc
),
903 /* Like ADDR64, but use local entry point of function. */
904 HOW (R_PPC64_ADDR64_LOCAL
, 4, 64, 0xffffffffffffffffULL
, 0, false, dont
,
905 bfd_elf_generic_reloc
),
907 HOW (R_PPC64_PLTSEQ_NOTOC
, 2, 32, 0, 0, false, dont
,
908 bfd_elf_generic_reloc
),
910 HOW (R_PPC64_PLTCALL_NOTOC
, 2, 32, 0, 0, false, dont
,
911 bfd_elf_generic_reloc
),
913 HOW (R_PPC64_PCREL_OPT
, 2, 32, 0, 0, false, dont
,
914 bfd_elf_generic_reloc
),
916 HOW (R_PPC64_D34
, 4, 34, 0x3ffff0000ffffULL
, 0, false, signed,
917 ppc64_elf_prefix_reloc
),
919 HOW (R_PPC64_D34_LO
, 4, 34, 0x3ffff0000ffffULL
, 0, false, dont
,
920 ppc64_elf_prefix_reloc
),
922 HOW (R_PPC64_D34_HI30
, 4, 34, 0x3ffff0000ffffULL
, 34, false, dont
,
923 ppc64_elf_prefix_reloc
),
925 HOW (R_PPC64_D34_HA30
, 4, 34, 0x3ffff0000ffffULL
, 34, false, dont
,
926 ppc64_elf_prefix_reloc
),
928 HOW (R_PPC64_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
929 ppc64_elf_prefix_reloc
),
931 HOW (R_PPC64_GOT_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
932 ppc64_elf_unhandled_reloc
),
934 HOW (R_PPC64_PLT_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
935 ppc64_elf_unhandled_reloc
),
937 HOW (R_PPC64_PLT_PCREL34_NOTOC
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
938 ppc64_elf_unhandled_reloc
),
940 HOW (R_PPC64_TPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, false, signed,
941 ppc64_elf_unhandled_reloc
),
943 HOW (R_PPC64_DTPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, false, signed,
944 ppc64_elf_unhandled_reloc
),
946 HOW (R_PPC64_GOT_TLSGD_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
947 ppc64_elf_unhandled_reloc
),
949 HOW (R_PPC64_GOT_TLSLD_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
950 ppc64_elf_unhandled_reloc
),
952 HOW (R_PPC64_GOT_TPREL_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
953 ppc64_elf_unhandled_reloc
),
955 HOW (R_PPC64_GOT_DTPREL_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, true, signed,
956 ppc64_elf_unhandled_reloc
),
958 HOW (R_PPC64_ADDR16_HIGHER34
, 1, 16, 0xffff, 34, false, dont
,
959 bfd_elf_generic_reloc
),
961 HOW (R_PPC64_ADDR16_HIGHERA34
, 1, 16, 0xffff, 34, false, dont
,
964 HOW (R_PPC64_ADDR16_HIGHEST34
, 1, 16, 0xffff, 50, false, dont
,
965 bfd_elf_generic_reloc
),
967 HOW (R_PPC64_ADDR16_HIGHESTA34
, 1, 16, 0xffff, 50, false, dont
,
970 HOW (R_PPC64_REL16_HIGHER34
, 1, 16, 0xffff, 34, true, dont
,
971 bfd_elf_generic_reloc
),
973 HOW (R_PPC64_REL16_HIGHERA34
, 1, 16, 0xffff, 34, true, dont
,
976 HOW (R_PPC64_REL16_HIGHEST34
, 1, 16, 0xffff, 50, true, dont
,
977 bfd_elf_generic_reloc
),
979 HOW (R_PPC64_REL16_HIGHESTA34
, 1, 16, 0xffff, 50, true, dont
,
982 HOW (R_PPC64_D28
, 4, 28, 0xfff0000ffffULL
, 0, false, signed,
983 ppc64_elf_prefix_reloc
),
985 HOW (R_PPC64_PCREL28
, 4, 28, 0xfff0000ffffULL
, 0, true, signed,
986 ppc64_elf_prefix_reloc
),
988 /* GNU extension to record C++ vtable hierarchy. */
989 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, false, dont
,
992 /* GNU extension to record C++ vtable member usage. */
993 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, false, dont
,
998 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1002 ppc_howto_init (void)
1004 unsigned int i
, type
;
1006 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1008 type
= ppc64_elf_howto_raw
[i
].type
;
1009 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
1010 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1014 static reloc_howto_type
*
1015 ppc64_elf_reloc_type_lookup (bfd
*abfd
, bfd_reloc_code_real_type code
)
1017 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1019 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1020 /* Initialize howto table if needed. */
1026 /* xgettext:c-format */
1027 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
1029 bfd_set_error (bfd_error_bad_value
);
1032 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1034 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1036 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1038 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1040 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1042 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1044 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
1046 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1048 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
1050 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1052 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1054 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1056 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1058 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
1060 case BFD_RELOC_PPC64_REL24_P9NOTOC
: r
= R_PPC64_REL24_P9NOTOC
;
1062 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1064 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1066 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1068 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1070 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1072 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1074 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1076 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1078 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1080 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1082 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1084 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1086 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1088 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1090 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1092 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1094 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1096 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1098 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1100 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1102 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1104 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1106 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1108 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1110 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1112 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1114 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1116 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1118 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1120 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1122 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1124 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1126 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1128 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1130 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1132 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1134 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1136 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1138 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1140 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1142 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1144 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1146 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1148 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1150 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1152 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1154 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1156 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1158 case BFD_RELOC_PPC64_TLS_PCREL
:
1159 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1161 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1163 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1165 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1167 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1169 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1171 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1173 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1175 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1177 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1179 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1181 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1183 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1185 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1187 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1189 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1191 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1193 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1195 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1197 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1199 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1201 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1203 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1205 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1207 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1209 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1211 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1213 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1215 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1217 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1219 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1221 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1223 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1225 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1227 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1229 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1231 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1233 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1235 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1237 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1239 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1241 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1243 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1245 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1247 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1249 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1251 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1253 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1255 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1257 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1259 case BFD_RELOC_PPC64_REL16_HIGH
: r
= R_PPC64_REL16_HIGH
;
1261 case BFD_RELOC_PPC64_REL16_HIGHA
: r
= R_PPC64_REL16_HIGHA
;
1263 case BFD_RELOC_PPC64_REL16_HIGHER
: r
= R_PPC64_REL16_HIGHER
;
1265 case BFD_RELOC_PPC64_REL16_HIGHERA
: r
= R_PPC64_REL16_HIGHERA
;
1267 case BFD_RELOC_PPC64_REL16_HIGHEST
: r
= R_PPC64_REL16_HIGHEST
;
1269 case BFD_RELOC_PPC64_REL16_HIGHESTA
: r
= R_PPC64_REL16_HIGHESTA
;
1271 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1273 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1275 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1277 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1279 case BFD_RELOC_PPC64_D34
: r
= R_PPC64_D34
;
1281 case BFD_RELOC_PPC64_D34_LO
: r
= R_PPC64_D34_LO
;
1283 case BFD_RELOC_PPC64_D34_HI30
: r
= R_PPC64_D34_HI30
;
1285 case BFD_RELOC_PPC64_D34_HA30
: r
= R_PPC64_D34_HA30
;
1287 case BFD_RELOC_PPC64_PCREL34
: r
= R_PPC64_PCREL34
;
1289 case BFD_RELOC_PPC64_GOT_PCREL34
: r
= R_PPC64_GOT_PCREL34
;
1291 case BFD_RELOC_PPC64_PLT_PCREL34
: r
= R_PPC64_PLT_PCREL34
;
1293 case BFD_RELOC_PPC64_TPREL34
: r
= R_PPC64_TPREL34
;
1295 case BFD_RELOC_PPC64_DTPREL34
: r
= R_PPC64_DTPREL34
;
1297 case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34
: r
= R_PPC64_GOT_TLSGD_PCREL34
;
1299 case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34
: r
= R_PPC64_GOT_TLSLD_PCREL34
;
1301 case BFD_RELOC_PPC64_GOT_TPREL_PCREL34
: r
= R_PPC64_GOT_TPREL_PCREL34
;
1303 case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34
: r
= R_PPC64_GOT_DTPREL_PCREL34
;
1305 case BFD_RELOC_PPC64_ADDR16_HIGHER34
: r
= R_PPC64_ADDR16_HIGHER34
;
1307 case BFD_RELOC_PPC64_ADDR16_HIGHERA34
: r
= R_PPC64_ADDR16_HIGHERA34
;
1309 case BFD_RELOC_PPC64_ADDR16_HIGHEST34
: r
= R_PPC64_ADDR16_HIGHEST34
;
1311 case BFD_RELOC_PPC64_ADDR16_HIGHESTA34
: r
= R_PPC64_ADDR16_HIGHESTA34
;
1313 case BFD_RELOC_PPC64_REL16_HIGHER34
: r
= R_PPC64_REL16_HIGHER34
;
1315 case BFD_RELOC_PPC64_REL16_HIGHERA34
: r
= R_PPC64_REL16_HIGHERA34
;
1317 case BFD_RELOC_PPC64_REL16_HIGHEST34
: r
= R_PPC64_REL16_HIGHEST34
;
1319 case BFD_RELOC_PPC64_REL16_HIGHESTA34
: r
= R_PPC64_REL16_HIGHESTA34
;
1321 case BFD_RELOC_PPC64_D28
: r
= R_PPC64_D28
;
1323 case BFD_RELOC_PPC64_PCREL28
: r
= R_PPC64_PCREL28
;
1325 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1327 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1331 return ppc64_elf_howto_table
[r
];
1334 static reloc_howto_type
*
1335 ppc64_elf_reloc_name_lookup (bfd
*abfd
, const char *r_name
)
1338 static char *compat_map
[][2] = {
1339 { "R_PPC64_GOT_TLSGD34", "R_PPC64_GOT_TLSGD_PCREL34" },
1340 { "R_PPC64_GOT_TLSLD34", "R_PPC64_GOT_TLSLD_PCREL34" },
1341 { "R_PPC64_GOT_TPREL34", "R_PPC64_GOT_TPREL_PCREL34" },
1342 { "R_PPC64_GOT_DTPREL34", "R_PPC64_GOT_DTPREL_PCREL34" }
1345 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1346 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1347 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1348 return &ppc64_elf_howto_raw
[i
];
1350 /* Handle old names of relocations in case they were used by
1352 FIXME: Remove this soon. Mapping the reloc names is very likely
1353 completely unnecessary. */
1354 for (i
= 0; i
< ARRAY_SIZE (compat_map
); i
++)
1355 if (strcasecmp (compat_map
[i
][0], r_name
) == 0)
1357 _bfd_error_handler (_("warning: %s should be used rather than %s"),
1358 compat_map
[i
][1], compat_map
[i
][0]);
1359 return ppc64_elf_reloc_name_lookup (abfd
, compat_map
[i
][1]);
1365 /* Set the howto pointer for a PowerPC ELF reloc. */
1368 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1369 Elf_Internal_Rela
*dst
)
1373 /* Initialize howto table if needed. */
1374 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1377 type
= ELF64_R_TYPE (dst
->r_info
);
1378 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1380 /* xgettext:c-format */
1381 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1383 bfd_set_error (bfd_error_bad_value
);
1386 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1387 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1389 /* xgettext:c-format */
1390 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1392 bfd_set_error (bfd_error_bad_value
);
1399 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1401 static bfd_reloc_status_type
1402 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1403 void *data
, asection
*input_section
,
1404 bfd
*output_bfd
, char **error_message
)
1406 enum elf_ppc64_reloc_type r_type
;
1408 bfd_size_type octets
;
1411 /* If this is a relocatable link (output_bfd test tells us), just
1412 call the generic function. Any adjustment will be done at final
1414 if (output_bfd
!= NULL
)
1415 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1416 input_section
, output_bfd
, error_message
);
1418 /* Adjust the addend for sign extension of the low 16 (or 34) bits.
1419 We won't actually be using the low bits, so trashing them
1421 r_type
= reloc_entry
->howto
->type
;
1422 if (r_type
== R_PPC64_ADDR16_HIGHERA34
1423 || r_type
== R_PPC64_ADDR16_HIGHESTA34
1424 || r_type
== R_PPC64_REL16_HIGHERA34
1425 || r_type
== R_PPC64_REL16_HIGHESTA34
)
1426 reloc_entry
->addend
+= 1ULL << 33;
1428 reloc_entry
->addend
+= 1U << 15;
1429 if (r_type
!= R_PPC64_REL16DX_HA
)
1430 return bfd_reloc_continue
;
1433 if (!bfd_is_com_section (symbol
->section
))
1434 value
= symbol
->value
;
1435 value
+= (reloc_entry
->addend
1436 + symbol
->section
->output_offset
1437 + symbol
->section
->output_section
->vma
);
1438 value
-= (reloc_entry
->address
1439 + input_section
->output_offset
1440 + input_section
->output_section
->vma
);
1441 value
= (bfd_signed_vma
) value
>> 16;
1443 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1444 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1445 input_section
, octets
))
1446 return bfd_reloc_outofrange
;
1448 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1450 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1451 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1452 if (value
+ 0x8000 > 0xffff)
1453 return bfd_reloc_overflow
;
1454 return bfd_reloc_ok
;
1457 static bfd_reloc_status_type
1458 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1459 void *data
, asection
*input_section
,
1460 bfd
*output_bfd
, char **error_message
)
1462 if (output_bfd
!= NULL
)
1463 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1464 input_section
, output_bfd
, error_message
);
1466 if (strcmp (symbol
->section
->name
, ".opd") == 0
1467 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1469 bfd_vma dest
= opd_entry_value (symbol
->section
,
1470 symbol
->value
+ reloc_entry
->addend
,
1472 if (dest
!= (bfd_vma
) -1)
1473 reloc_entry
->addend
= dest
- (symbol
->value
1474 + symbol
->section
->output_section
->vma
1475 + symbol
->section
->output_offset
);
1479 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1481 if (symbol
->section
->owner
!= abfd
1482 && symbol
->section
->owner
!= NULL
1483 && abiversion (symbol
->section
->owner
) >= 2)
1487 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1489 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1491 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1493 elfsym
= (elf_symbol_type
*) symdef
;
1499 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1501 return bfd_reloc_continue
;
1504 static bfd_reloc_status_type
1505 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1506 void *data
, asection
*input_section
,
1507 bfd
*output_bfd
, char **error_message
)
1510 enum elf_ppc64_reloc_type r_type
;
1511 bfd_size_type octets
;
1512 /* Assume 'at' branch hints. */
1513 bool is_isa_v2
= true;
1515 /* If this is a relocatable link (output_bfd test tells us), just
1516 call the generic function. Any adjustment will be done at final
1518 if (output_bfd
!= NULL
)
1519 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1520 input_section
, output_bfd
, error_message
);
1522 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1523 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1524 input_section
, octets
))
1525 return bfd_reloc_outofrange
;
1527 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1528 insn
&= ~(0x01 << 21);
1529 r_type
= reloc_entry
->howto
->type
;
1530 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1531 || r_type
== R_PPC64_REL14_BRTAKEN
)
1532 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1536 /* Set 'a' bit. This is 0b00010 in BO field for branch
1537 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1538 for branch on CTR insns (BO == 1a00t or 1a01t). */
1539 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1541 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1551 if (!bfd_is_com_section (symbol
->section
))
1552 target
= symbol
->value
;
1553 target
+= symbol
->section
->output_section
->vma
;
1554 target
+= symbol
->section
->output_offset
;
1555 target
+= reloc_entry
->addend
;
1557 from
= (reloc_entry
->address
1558 + input_section
->output_offset
1559 + input_section
->output_section
->vma
);
1561 /* Invert 'y' bit if not the default. */
1562 if ((bfd_signed_vma
) (target
- from
) < 0)
1565 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1567 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1568 input_section
, output_bfd
, error_message
);
1571 static bfd_reloc_status_type
1572 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1573 void *data
, asection
*input_section
,
1574 bfd
*output_bfd
, char **error_message
)
1576 /* If this is a relocatable link (output_bfd test tells us), just
1577 call the generic function. Any adjustment will be done at final
1579 if (output_bfd
!= NULL
)
1580 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1581 input_section
, output_bfd
, error_message
);
1583 /* Subtract the symbol section base address. */
1584 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1585 return bfd_reloc_continue
;
1588 static bfd_reloc_status_type
1589 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1590 void *data
, asection
*input_section
,
1591 bfd
*output_bfd
, char **error_message
)
1593 /* If this is a relocatable link (output_bfd test tells us), just
1594 call the generic function. Any adjustment will be done at final
1596 if (output_bfd
!= NULL
)
1597 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1598 input_section
, output_bfd
, error_message
);
1600 /* Subtract the symbol section base address. */
1601 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1603 /* Adjust the addend for sign extension of the low 16 bits. */
1604 reloc_entry
->addend
+= 0x8000;
1605 return bfd_reloc_continue
;
1608 static bfd_reloc_status_type
1609 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1610 void *data
, asection
*input_section
,
1611 bfd
*output_bfd
, char **error_message
)
1615 /* If this is a relocatable link (output_bfd test tells us), just
1616 call the generic function. Any adjustment will be done at final
1618 if (output_bfd
!= NULL
)
1619 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1620 input_section
, output_bfd
, error_message
);
1622 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1624 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1626 /* Subtract the TOC base address. */
1627 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1628 return bfd_reloc_continue
;
1631 static bfd_reloc_status_type
1632 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1633 void *data
, asection
*input_section
,
1634 bfd
*output_bfd
, char **error_message
)
1638 /* If this is a relocatable link (output_bfd test tells us), just
1639 call the generic function. Any adjustment will be done at final
1641 if (output_bfd
!= NULL
)
1642 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1643 input_section
, output_bfd
, error_message
);
1645 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1647 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1649 /* Subtract the TOC base address. */
1650 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1652 /* Adjust the addend for sign extension of the low 16 bits. */
1653 reloc_entry
->addend
+= 0x8000;
1654 return bfd_reloc_continue
;
1657 static bfd_reloc_status_type
1658 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1659 void *data
, asection
*input_section
,
1660 bfd
*output_bfd
, char **error_message
)
1663 bfd_size_type octets
;
1665 /* If this is a relocatable link (output_bfd test tells us), just
1666 call the generic function. Any adjustment will be done at final
1668 if (output_bfd
!= NULL
)
1669 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1670 input_section
, output_bfd
, error_message
);
1672 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1673 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1674 input_section
, octets
))
1675 return bfd_reloc_outofrange
;
1677 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1679 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1681 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1682 return bfd_reloc_ok
;
1685 static bfd_reloc_status_type
1686 ppc64_elf_prefix_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1687 void *data
, asection
*input_section
,
1688 bfd
*output_bfd
, char **error_message
)
1692 bfd_size_type octets
;
1694 if (output_bfd
!= NULL
)
1695 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1696 input_section
, output_bfd
, error_message
);
1698 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
1699 if (!bfd_reloc_offset_in_range (reloc_entry
->howto
, abfd
,
1700 input_section
, octets
))
1701 return bfd_reloc_outofrange
;
1703 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1705 insn
|= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
+ 4);
1707 targ
= (symbol
->section
->output_section
->vma
1708 + symbol
->section
->output_offset
1709 + reloc_entry
->addend
);
1710 if (!bfd_is_com_section (symbol
->section
))
1711 targ
+= symbol
->value
;
1712 if (reloc_entry
->howto
->type
== R_PPC64_D34_HA30
)
1714 if (reloc_entry
->howto
->pc_relative
)
1716 bfd_vma from
= (reloc_entry
->address
1717 + input_section
->output_offset
1718 + input_section
->output_section
->vma
);
1721 targ
>>= reloc_entry
->howto
->rightshift
;
1722 insn
&= ~reloc_entry
->howto
->dst_mask
;
1723 insn
|= ((targ
<< 16) | (targ
& 0xffff)) & reloc_entry
->howto
->dst_mask
;
1724 bfd_put_32 (abfd
, insn
>> 32, (bfd_byte
*) data
+ octets
);
1725 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
+ 4);
1726 if (reloc_entry
->howto
->complain_on_overflow
== complain_overflow_signed
1727 && (targ
+ (1ULL << (reloc_entry
->howto
->bitsize
- 1))
1728 >= 1ULL << reloc_entry
->howto
->bitsize
))
1729 return bfd_reloc_overflow
;
1730 return bfd_reloc_ok
;
1733 static bfd_reloc_status_type
1734 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1735 void *data
, asection
*input_section
,
1736 bfd
*output_bfd
, char **error_message
)
1738 /* If this is a relocatable link (output_bfd test tells us), just
1739 call the generic function. Any adjustment will be done at final
1741 if (output_bfd
!= NULL
)
1742 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1743 input_section
, output_bfd
, error_message
);
1745 if (error_message
!= NULL
)
1747 static char *message
;
1749 if (asprintf (&message
, _("generic linker can't handle %s"),
1750 reloc_entry
->howto
->name
) < 0)
1752 *error_message
= message
;
1754 return bfd_reloc_dangerous
;
1757 /* Track GOT entries needed for a given symbol. We might need more
1758 than one got entry per symbol. */
1761 struct got_entry
*next
;
1763 /* The symbol addend that we'll be placing in the GOT. */
1766 /* Unlike other ELF targets, we use separate GOT entries for the same
1767 symbol referenced from different input files. This is to support
1768 automatic multiple TOC/GOT sections, where the TOC base can vary
1769 from one input file to another. After partitioning into TOC groups
1770 we merge entries within the group.
1772 Point to the BFD owning this GOT entry. */
1775 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1776 TLS_TPREL or TLS_DTPREL for tls entries. */
1777 unsigned char tls_type
;
1779 /* Non-zero if got.ent points to real entry. */
1780 unsigned char is_indirect
;
1782 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1785 bfd_signed_vma refcount
;
1787 struct got_entry
*ent
;
1791 /* The same for PLT. */
1794 struct plt_entry
*next
;
1800 bfd_signed_vma refcount
;
1805 struct ppc64_elf_obj_tdata
1807 struct elf_obj_tdata elf
;
1809 /* Shortcuts to dynamic linker sections. */
1813 /* Used during garbage collection. We attach global symbols defined
1814 on removed .opd entries to this section so that the sym is removed. */
1815 asection
*deleted_section
;
1817 /* TLS local dynamic got entry handling. Support for multiple GOT
1818 sections means we potentially need one of these for each input bfd. */
1819 struct got_entry tlsld_got
;
1823 /* A copy of relocs before they are modified for --emit-relocs. */
1824 Elf_Internal_Rela
*relocs
;
1826 /* Section contents. */
1830 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1831 the reloc to be in the range -32768 to 32767. */
1832 unsigned int has_small_toc_reloc
: 1;
1834 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1835 instruction not one we handle. */
1836 unsigned int unexpected_toc_insn
: 1;
1838 /* Set if PLT/GOT/TOC relocs that can be optimised are present in
1840 unsigned int has_optrel
: 1;
1843 #define ppc64_elf_tdata(bfd) \
1844 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1846 #define ppc64_tlsld_got(bfd) \
1847 (&ppc64_elf_tdata (bfd)->tlsld_got)
1849 #define is_ppc64_elf(bfd) \
1850 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1851 && elf_object_id (bfd) == PPC64_ELF_DATA)
1853 /* Override the generic function because we store some extras. */
1856 ppc64_elf_mkobject (bfd
*abfd
)
1858 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1862 /* Fix bad default arch selected for a 64 bit input bfd when the
1863 default is 32 bit. Also select arch based on apuinfo. */
1866 ppc64_elf_object_p (bfd
*abfd
)
1868 if (!abfd
->arch_info
->the_default
)
1871 if (abfd
->arch_info
->bits_per_word
== 32)
1873 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1875 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1877 /* Relies on arch after 32 bit default being 64 bit default. */
1878 abfd
->arch_info
= abfd
->arch_info
->next
;
1879 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1882 return _bfd_elf_ppc_set_arch (abfd
);
1885 /* Support for core dump NOTE sections. */
1888 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1890 size_t offset
, size
;
1892 if (note
->descsz
!= 504)
1896 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1899 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1905 /* Make a ".reg/999" section. */
1906 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1907 size
, note
->descpos
+ offset
);
1911 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1913 if (note
->descsz
!= 136)
1916 elf_tdata (abfd
)->core
->pid
1917 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1918 elf_tdata (abfd
)->core
->program
1919 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1920 elf_tdata (abfd
)->core
->command
1921 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1927 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1937 char data
[136] ATTRIBUTE_NONSTRING
;
1940 va_start (ap
, note_type
);
1941 memset (data
, 0, sizeof (data
));
1942 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1943 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1945 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1946 -Wstringop-truncation:
1947 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1949 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1951 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1952 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1956 return elfcore_write_note (abfd
, buf
, bufsiz
,
1957 "CORE", note_type
, data
, sizeof (data
));
1968 va_start (ap
, note_type
);
1969 memset (data
, 0, 112);
1970 pid
= va_arg (ap
, long);
1971 bfd_put_32 (abfd
, pid
, data
+ 32);
1972 cursig
= va_arg (ap
, int);
1973 bfd_put_16 (abfd
, cursig
, data
+ 12);
1974 greg
= va_arg (ap
, const void *);
1975 memcpy (data
+ 112, greg
, 384);
1976 memset (data
+ 496, 0, 8);
1978 return elfcore_write_note (abfd
, buf
, bufsiz
,
1979 "CORE", note_type
, data
, sizeof (data
));
1984 /* Add extra PPC sections. */
1986 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1988 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1989 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1990 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1991 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1992 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1993 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1994 { NULL
, 0, 0, 0, 0 }
1997 enum _ppc64_sec_type
{
2003 struct _ppc64_elf_section_data
2005 struct bfd_elf_section_data elf
;
2009 /* An array with one entry for each opd function descriptor,
2010 and some spares since opd entries may be either 16 or 24 bytes. */
2011 #define OPD_NDX(OFF) ((OFF) >> 4)
2012 struct _opd_sec_data
2014 /* Points to the function code section for local opd entries. */
2015 asection
**func_sec
;
2017 /* After editing .opd, adjust references to opd local syms. */
2021 /* An array for toc sections, indexed by offset/8. */
2022 struct _toc_sec_data
2024 /* Specifies the relocation symbol index used at a given toc offset. */
2027 /* And the relocation addend. */
2032 enum _ppc64_sec_type sec_type
:2;
2034 /* Flag set when small branches are detected. Used to
2035 select suitable defaults for the stub group size. */
2036 unsigned int has_14bit_branch
:1;
2038 /* Flag set when PLTCALL relocs are detected. */
2039 unsigned int has_pltcall
:1;
2041 /* Flag set when section has PLT/GOT/TOC relocations that can be
2043 unsigned int has_optrel
:1;
2046 #define ppc64_elf_section_data(sec) \
2047 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2050 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2052 if (!sec
->used_by_bfd
)
2054 struct _ppc64_elf_section_data
*sdata
;
2055 size_t amt
= sizeof (*sdata
);
2057 sdata
= bfd_zalloc (abfd
, amt
);
2060 sec
->used_by_bfd
= sdata
;
2063 return _bfd_elf_new_section_hook (abfd
, sec
);
2067 ppc64_elf_section_flags (const Elf_Internal_Shdr
*hdr
)
2069 const char *name
= hdr
->bfd_section
->name
;
2071 if (startswith (name
, ".sbss")
2072 || startswith (name
, ".sdata"))
2073 hdr
->bfd_section
->flags
|= SEC_SMALL_DATA
;
2078 static struct _opd_sec_data
*
2079 get_opd_info (asection
* sec
)
2082 && ppc64_elf_section_data (sec
) != NULL
2083 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2084 return &ppc64_elf_section_data (sec
)->u
.opd
;
2088 /* Parameters for the qsort hook. */
2089 static bool synthetic_relocatable
;
2090 static const asection
*synthetic_opd
;
2092 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2095 compare_symbols (const void *ap
, const void *bp
)
2097 const asymbol
*a
= *(const asymbol
**) ap
;
2098 const asymbol
*b
= *(const asymbol
**) bp
;
2100 /* Section symbols first. */
2101 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2103 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2106 /* then .opd symbols. */
2107 if (synthetic_opd
!= NULL
)
2109 if (strcmp (a
->section
->name
, ".opd") == 0
2110 && strcmp (b
->section
->name
, ".opd") != 0)
2112 if (strcmp (a
->section
->name
, ".opd") != 0
2113 && strcmp (b
->section
->name
, ".opd") == 0)
2117 /* then other code symbols. */
2118 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2119 == (SEC_CODE
| SEC_ALLOC
))
2120 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2121 != (SEC_CODE
| SEC_ALLOC
)))
2124 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2125 != (SEC_CODE
| SEC_ALLOC
))
2126 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2127 == (SEC_CODE
| SEC_ALLOC
)))
2130 if (synthetic_relocatable
)
2132 if (a
->section
->id
< b
->section
->id
)
2135 if (a
->section
->id
> b
->section
->id
)
2139 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2142 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2145 /* For syms with the same value, prefer strong dynamic global function
2146 syms over other syms. */
2147 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2150 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2153 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2156 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2159 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2162 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2165 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2168 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2171 /* Finally, sort on where the symbol is in memory. The symbols will
2172 be in at most two malloc'd blocks, one for static syms, one for
2173 dynamic syms, and we distinguish the two blocks above by testing
2174 BSF_DYNAMIC. Since we are sorting the symbol pointers which were
2175 originally in the same order as the symbols (and we're not
2176 sorting the symbols themselves), this ensures a stable sort. */
2184 /* Search SYMS for a symbol of the given VALUE. */
2187 sym_exists_at (asymbol
**syms
, size_t lo
, size_t hi
, unsigned int id
,
2192 if (id
== (unsigned) -1)
2196 mid
= (lo
+ hi
) >> 1;
2197 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2199 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2209 mid
= (lo
+ hi
) >> 1;
2210 if (syms
[mid
]->section
->id
< id
)
2212 else if (syms
[mid
]->section
->id
> id
)
2214 else if (syms
[mid
]->value
< value
)
2216 else if (syms
[mid
]->value
> value
)
2226 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2228 bfd_vma vma
= *(bfd_vma
*) ptr
;
2229 return ((section
->flags
& SEC_ALLOC
) != 0
2230 && section
->vma
<= vma
2231 && vma
< section
->vma
+ section
->size
);
2234 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2235 entry syms. Also generate @plt symbols for the glink branch table.
2236 Returns count of synthetic symbols in RET or -1 on error. */
2239 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2240 long static_count
, asymbol
**static_syms
,
2241 long dyn_count
, asymbol
**dyn_syms
,
2247 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2248 asection
*opd
= NULL
;
2249 bool relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2251 int abi
= abiversion (abfd
);
2257 opd
= bfd_get_section_by_name (abfd
, ".opd");
2258 if (opd
== NULL
&& abi
== 1)
2270 symcount
= static_count
;
2272 symcount
+= dyn_count
;
2276 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2280 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2282 /* Use both symbol tables. */
2283 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2284 memcpy (syms
+ static_count
, dyn_syms
,
2285 (dyn_count
+ 1) * sizeof (*syms
));
2287 else if (!relocatable
&& static_count
== 0)
2288 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2290 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2292 /* Trim uninteresting symbols. Interesting symbols are section,
2293 function, and notype symbols. */
2294 for (i
= 0, j
= 0; i
< symcount
; ++i
)
2295 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
2296 | BSF_RELC
| BSF_SRELC
)) == 0)
2297 syms
[j
++] = syms
[i
];
2300 synthetic_relocatable
= relocatable
;
2301 synthetic_opd
= opd
;
2302 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2304 if (!relocatable
&& symcount
> 1)
2306 /* Trim duplicate syms, since we may have merged the normal
2307 and dynamic symbols. Actually, we only care about syms
2308 that have different values, so trim any with the same
2309 value. Don't consider ifunc and ifunc resolver symbols
2310 duplicates however, because GDB wants to know whether a
2311 text symbol is an ifunc resolver. */
2312 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2314 const asymbol
*s0
= syms
[i
- 1];
2315 const asymbol
*s1
= syms
[i
];
2317 if ((s0
->value
+ s0
->section
->vma
2318 != s1
->value
+ s1
->section
->vma
)
2319 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2320 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2321 syms
[j
++] = syms
[i
];
2327 /* Note that here and in compare_symbols we can't compare opd and
2328 sym->section directly. With separate debug info files, the
2329 symbols will be extracted from the debug file while abfd passed
2330 to this function is the real binary. */
2331 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) != 0
2332 && strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2336 for (; i
< symcount
; ++i
)
2337 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2338 | SEC_THREAD_LOCAL
))
2339 != (SEC_CODE
| SEC_ALLOC
))
2340 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2344 for (; i
< symcount
; ++i
)
2345 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2349 for (; i
< symcount
; ++i
)
2350 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2354 for (; i
< symcount
; ++i
)
2355 if (((syms
[i
]->section
->flags
2356 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2357 != (SEC_CODE
| SEC_ALLOC
))
2365 bool (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bool);
2370 if (opdsymend
== secsymend
)
2373 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2374 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2378 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, false))
2385 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2389 while (r
< opd
->relocation
+ relcount
2390 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2393 if (r
== opd
->relocation
+ relcount
)
2396 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2399 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2402 sym
= *r
->sym_ptr_ptr
;
2403 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2404 sym
->section
->id
, sym
->value
+ r
->addend
))
2407 size
+= sizeof (asymbol
);
2408 size
+= strlen (syms
[i
]->name
) + 2;
2414 s
= *ret
= bfd_malloc (size
);
2421 names
= (char *) (s
+ count
);
2423 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2427 while (r
< opd
->relocation
+ relcount
2428 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2431 if (r
== opd
->relocation
+ relcount
)
2434 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2437 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2440 sym
= *r
->sym_ptr_ptr
;
2441 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2442 sym
->section
->id
, sym
->value
+ r
->addend
))
2447 s
->flags
|= BSF_SYNTHETIC
;
2448 s
->section
= sym
->section
;
2449 s
->value
= sym
->value
+ r
->addend
;
2452 len
= strlen (syms
[i
]->name
);
2453 memcpy (names
, syms
[i
]->name
, len
+ 1);
2455 /* Have udata.p point back to the original symbol this
2456 synthetic symbol was derived from. */
2457 s
->udata
.p
= syms
[i
];
2464 bool (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bool);
2465 bfd_byte
*contents
= NULL
;
2467 size_t plt_count
= 0;
2468 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2469 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2472 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2474 free_contents_and_exit_err
:
2476 free_contents_and_exit
:
2482 for (i
= secsymend
; i
< opdsymend
; ++i
)
2486 /* Ignore bogus symbols. */
2487 if (syms
[i
]->value
> opd
->size
- 8)
2490 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2491 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2494 size
+= sizeof (asymbol
);
2495 size
+= strlen (syms
[i
]->name
) + 2;
2499 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2501 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2503 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2505 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2507 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2508 goto free_contents_and_exit_err
;
2510 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2511 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2514 extdynend
= extdyn
+ dynamic
->size
;
2515 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2517 Elf_Internal_Dyn dyn
;
2518 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2520 if (dyn
.d_tag
== DT_NULL
)
2523 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2525 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2526 See comment in ppc64_elf_finish_dynamic_sections. */
2527 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2528 /* The .glink section usually does not survive the final
2529 link; search for the section (usually .text) where the
2530 glink stubs now reside. */
2531 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2542 /* Determine __glink trampoline by reading the relative branch
2543 from the first glink stub. */
2545 unsigned int off
= 0;
2547 while (bfd_get_section_contents (abfd
, glink
, buf
,
2548 glink_vma
+ off
- glink
->vma
, 4))
2550 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2552 if ((insn
& ~0x3fffffc) == 0)
2555 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2564 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2566 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2569 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2570 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, true))
2571 goto free_contents_and_exit_err
;
2573 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
2574 size
+= plt_count
* sizeof (asymbol
);
2576 p
= relplt
->relocation
;
2577 for (i
= 0; i
< plt_count
; i
++, p
++)
2579 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2581 size
+= sizeof ("+0x") - 1 + 16;
2587 goto free_contents_and_exit
;
2588 s
= *ret
= bfd_malloc (size
);
2590 goto free_contents_and_exit_err
;
2592 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2594 for (i
= secsymend
; i
< opdsymend
; ++i
)
2598 if (syms
[i
]->value
> opd
->size
- 8)
2601 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2602 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2606 asection
*sec
= abfd
->sections
;
2613 size_t mid
= (lo
+ hi
) >> 1;
2614 if (syms
[mid
]->section
->vma
< ent
)
2616 else if (syms
[mid
]->section
->vma
> ent
)
2620 sec
= syms
[mid
]->section
;
2625 if (lo
>= hi
&& lo
> codesecsym
)
2626 sec
= syms
[lo
- 1]->section
;
2628 for (; sec
!= NULL
; sec
= sec
->next
)
2632 /* SEC_LOAD may not be set if SEC is from a separate debug
2634 if ((sec
->flags
& SEC_ALLOC
) == 0)
2636 if ((sec
->flags
& SEC_CODE
) != 0)
2639 s
->flags
|= BSF_SYNTHETIC
;
2640 s
->value
= ent
- s
->section
->vma
;
2643 len
= strlen (syms
[i
]->name
);
2644 memcpy (names
, syms
[i
]->name
, len
+ 1);
2646 /* Have udata.p point back to the original symbol this
2647 synthetic symbol was derived from. */
2648 s
->udata
.p
= syms
[i
];
2654 if (glink
!= NULL
&& relplt
!= NULL
)
2658 /* Add a symbol for the main glink trampoline. */
2659 memset (s
, 0, sizeof *s
);
2661 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2663 s
->value
= resolv_vma
- glink
->vma
;
2665 memcpy (names
, "__glink_PLTresolve",
2666 sizeof ("__glink_PLTresolve"));
2667 names
+= sizeof ("__glink_PLTresolve");
2672 /* FIXME: It would be very much nicer to put sym@plt on the
2673 stub rather than on the glink branch table entry. The
2674 objdump disassembler would then use a sensible symbol
2675 name on plt calls. The difficulty in doing so is
2676 a) finding the stubs, and,
2677 b) matching stubs against plt entries, and,
2678 c) there can be multiple stubs for a given plt entry.
2680 Solving (a) could be done by code scanning, but older
2681 ppc64 binaries used different stubs to current code.
2682 (b) is the tricky one since you need to known the toc
2683 pointer for at least one function that uses a pic stub to
2684 be able to calculate the plt address referenced.
2685 (c) means gdb would need to set multiple breakpoints (or
2686 find the glink branch itself) when setting breakpoints
2687 for pending shared library loads. */
2688 p
= relplt
->relocation
;
2689 for (i
= 0; i
< plt_count
; i
++, p
++)
2693 *s
= **p
->sym_ptr_ptr
;
2694 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2695 we are defining a symbol, ensure one of them is set. */
2696 if ((s
->flags
& BSF_LOCAL
) == 0)
2697 s
->flags
|= BSF_GLOBAL
;
2698 s
->flags
|= BSF_SYNTHETIC
;
2700 s
->value
= glink_vma
- glink
->vma
;
2703 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2704 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2708 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2709 names
+= sizeof ("+0x") - 1;
2710 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2711 names
+= strlen (names
);
2713 memcpy (names
, "@plt", sizeof ("@plt"));
2714 names
+= sizeof ("@plt");
2734 /* The following functions are specific to the ELF linker, while
2735 functions above are used generally. Those named ppc64_elf_* are
2736 called by the main ELF linker code. They appear in this file more
2737 or less in the order in which they are called. eg.
2738 ppc64_elf_check_relocs is called early in the link process,
2739 ppc64_elf_finish_dynamic_sections is one of the last functions
2742 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2743 functions have both a function code symbol and a function descriptor
2744 symbol. A call to foo in a relocatable object file looks like:
2751 The function definition in another object file might be:
2755 . .quad .TOC.@tocbase
2761 When the linker resolves the call during a static link, the branch
2762 unsurprisingly just goes to .foo and the .opd information is unused.
2763 If the function definition is in a shared library, things are a little
2764 different: The call goes via a plt call stub, the opd information gets
2765 copied to the plt, and the linker patches the nop.
2773 . std 2,40(1) # in practice, the call stub
2774 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2775 . addi 11,11,Lfoo@toc@l # this is the general idea
2783 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2785 The "reloc ()" notation is supposed to indicate that the linker emits
2786 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2789 What are the difficulties here? Well, firstly, the relocations
2790 examined by the linker in check_relocs are against the function code
2791 sym .foo, while the dynamic relocation in the plt is emitted against
2792 the function descriptor symbol, foo. Somewhere along the line, we need
2793 to carefully copy dynamic link information from one symbol to the other.
2794 Secondly, the generic part of the elf linker will make .foo a dynamic
2795 symbol as is normal for most other backends. We need foo dynamic
2796 instead, at least for an application final link. However, when
2797 creating a shared library containing foo, we need to have both symbols
2798 dynamic so that references to .foo are satisfied during the early
2799 stages of linking. Otherwise the linker might decide to pull in a
2800 definition from some other object, eg. a static library.
2802 Update: As of August 2004, we support a new convention. Function
2803 calls may use the function descriptor symbol, ie. "bl foo". This
2804 behaves exactly as "bl .foo". */
2806 /* Of those relocs that might be copied as dynamic relocs, this
2807 function selects those that must be copied when linking a shared
2808 library or PIE, even when the symbol is local. */
2811 must_be_dyn_reloc (struct bfd_link_info
*info
,
2812 enum elf_ppc64_reloc_type r_type
)
2817 /* Only relative relocs can be resolved when the object load
2818 address isn't fixed. DTPREL64 is excluded because the
2819 dynamic linker needs to differentiate global dynamic from
2820 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2827 case R_PPC64_TOC16_DS
:
2828 case R_PPC64_TOC16_LO
:
2829 case R_PPC64_TOC16_HI
:
2830 case R_PPC64_TOC16_HA
:
2831 case R_PPC64_TOC16_LO_DS
:
2834 case R_PPC64_TPREL16
:
2835 case R_PPC64_TPREL16_LO
:
2836 case R_PPC64_TPREL16_HI
:
2837 case R_PPC64_TPREL16_HA
:
2838 case R_PPC64_TPREL16_DS
:
2839 case R_PPC64_TPREL16_LO_DS
:
2840 case R_PPC64_TPREL16_HIGH
:
2841 case R_PPC64_TPREL16_HIGHA
:
2842 case R_PPC64_TPREL16_HIGHER
:
2843 case R_PPC64_TPREL16_HIGHERA
:
2844 case R_PPC64_TPREL16_HIGHEST
:
2845 case R_PPC64_TPREL16_HIGHESTA
:
2846 case R_PPC64_TPREL64
:
2847 case R_PPC64_TPREL34
:
2848 /* These relocations are relative but in a shared library the
2849 linker doesn't know the thread pointer base. */
2850 return bfd_link_dll (info
);
2854 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2855 copying dynamic variables from a shared lib into an app's .dynbss
2856 section, and instead use a dynamic relocation to point into the
2857 shared lib. With code that gcc generates it is vital that this be
2858 enabled; In the PowerPC64 ELFv1 ABI the address of a function is
2859 actually the address of a function descriptor which resides in the
2860 .opd section. gcc uses the descriptor directly rather than going
2861 via the GOT as some other ABIs do, which means that initialized
2862 function pointers reference the descriptor. Thus, a function
2863 pointer initialized to the address of a function in a shared
2864 library will either require a .dynbss copy and a copy reloc, or a
2865 dynamic reloc. Using a .dynbss copy redefines the function
2866 descriptor symbol to point to the copy. This presents a problem as
2867 a PLT entry for that function is also initialized from the function
2868 descriptor symbol and the copy may not be initialized first. */
2869 #define ELIMINATE_COPY_RELOCS 1
2871 /* Section name for stubs is the associated section name plus this
2873 #define STUB_SUFFIX ".stub"
2876 ppc_stub_long_branch:
2877 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2878 destination, but a 24 bit branch in a stub section will reach.
2881 ppc_stub_plt_branch:
2882 Similar to the above, but a 24 bit branch in the stub section won't
2883 reach its destination.
2884 . addis %r12,%r2,xxx@toc@ha
2885 . ld %r12,xxx@toc@l(%r12)
2890 Used to call a function in a shared library. If it so happens that
2891 the plt entry referenced crosses a 64k boundary, then an extra
2892 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2893 An r2save variant starts with "std %r2,40(%r1)".
2894 . addis %r11,%r2,xxx@toc@ha
2895 . ld %r12,xxx+0@toc@l(%r11)
2897 . ld %r2,xxx+8@toc@l(%r11)
2898 . ld %r11,xxx+16@toc@l(%r11)
2901 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2902 code to adjust the value and save r2 to support multiple toc sections.
2903 A ppc_stub_long_branch with an r2 offset looks like:
2905 . addis %r2,%r2,off@ha
2906 . addi %r2,%r2,off@l
2909 A ppc_stub_plt_branch with an r2 offset looks like:
2911 . addis %r12,%r2,xxx@toc@ha
2912 . ld %r12,xxx@toc@l(%r12)
2913 . addis %r2,%r2,off@ha
2914 . addi %r2,%r2,off@l
2918 All of the above stubs are shown as their ELFv1 variants. ELFv2
2919 variants exist too, simpler for plt calls since a new toc pointer
2920 and static chain are not loaded by the stub. In addition, ELFv2
2921 has some more complex stubs to handle calls marked with NOTOC
2922 relocs from functions where r2 is not a valid toc pointer.
2923 ppc_stub_long_branch_p9notoc:
2929 . addis %r12,%r11,dest-1b@ha
2930 . addi %r12,%r12,dest-1b@l
2933 ppc_stub_plt_branch_p9notoc:
2939 . lis %r12,xxx-1b@highest
2940 . ori %r12,%r12,xxx-1b@higher
2942 . oris %r12,%r12,xxx-1b@high
2943 . ori %r12,%r12,xxx-1b@l
2944 . add %r12,%r11,%r12
2948 ppc_stub_plt_call_p9notoc:
2954 . lis %r12,xxx-1b@highest
2955 . ori %r12,%r12,xxx-1b@higher
2957 . oris %r12,%r12,xxx-1b@high
2958 . ori %r12,%r12,xxx-1b@l
2959 . ldx %r12,%r11,%r12
2963 There are also ELFv1 power10 variants of these stubs.
2964 ppc_stub_long_branch_notoc:
2965 . pla %r12,dest@pcrel
2967 ppc_stub_plt_branch_notoc:
2968 . lis %r11,(dest-1f)@highesta34
2969 . ori %r11,%r11,(dest-1f)@highera34
2971 . 1: pla %r12,dest@pcrel
2972 . add %r12,%r11,%r12
2975 ppc_stub_plt_call_notoc:
2976 . lis %r11,(xxx-1f)@highesta34
2977 . ori %r11,%r11,(xxx-1f)@highera34
2979 . 1: pla %r12,xxx@pcrel
2980 . ldx %r12,%r11,%r12
2984 In cases where the high instructions would add zero, they are
2985 omitted and following instructions modified in some cases.
2986 For example, a power10 ppc_stub_plt_call_notoc might simplify down
2988 . pld %r12,xxx@pcrel
2992 Stub variants may be merged. For example, if printf is called from
2993 code with the tocsave optimization (ie. r2 saved in function
2994 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2995 and from other code without the tocsave optimization requiring a
2996 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
2997 type will be created. Calls with the tocsave optimization will
2998 enter this stub after the instruction saving r2. A similar
2999 situation exists when calls are marked with R_PPC64_REL24_NOTOC
3000 relocations. These require a ppc_stub_plt_call_notoc linkage stub
3001 to call an external function like printf. If other calls to printf
3002 require a ppc_stub_plt_call linkage stub then a single
3003 ppc_stub_plt_call_notoc linkage stub may be used for both types of
3006 enum ppc_stub_main_type
3009 ppc_stub_long_branch
,
3010 ppc_stub_plt_branch
,
3012 ppc_stub_global_entry
,
3016 /* ppc_stub_long_branch, ppc_stub_plt_branch and ppc_stub_plt_call have
3017 these variations. */
3019 enum ppc_stub_sub_type
3026 struct ppc_stub_type
3028 ENUM_BITFIELD (ppc_stub_main_type
) main
: 3;
3029 ENUM_BITFIELD (ppc_stub_sub_type
) sub
: 2;
3030 unsigned int r2save
: 1;
3033 /* Information on stub grouping. */
3036 /* The stub section. */
3038 /* This is the section to which stubs in the group will be attached. */
3041 struct map_stub
*next
;
3042 /* Whether to emit a copy of register save/restore functions in this
3045 /* Current offset within stubs after the insn restoring lr in a
3046 _notoc or _both stub using bcl for pc-relative addressing, or
3047 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
3048 unsigned int lr_restore
;
3049 /* Accumulated size of EH info emitted to describe return address
3050 if stubs modify lr. Does not include 17 byte FDE header. */
3051 unsigned int eh_size
;
3052 /* Offset in glink_eh_frame to the start of EH info for this group. */
3053 unsigned int eh_base
;
3056 struct ppc_stub_hash_entry
3058 /* Base hash table entry structure. */
3059 struct bfd_hash_entry root
;
3061 struct ppc_stub_type type
;
3063 /* Group information. */
3064 struct map_stub
*group
;
3066 /* Offset within stub_sec of the beginning of this stub. */
3067 bfd_vma stub_offset
;
3069 /* Given the symbol's value and its section we can determine its final
3070 value when building the stubs (so the stub knows where to jump. */
3071 bfd_vma target_value
;
3072 asection
*target_section
;
3074 /* The symbol table entry, if any, that this was derived from. */
3075 struct ppc_link_hash_entry
*h
;
3076 struct plt_entry
*plt_ent
;
3079 unsigned char symtype
;
3081 /* Symbol st_other. */
3082 unsigned char other
;
3085 struct ppc_branch_hash_entry
3087 /* Base hash table entry structure. */
3088 struct bfd_hash_entry root
;
3090 /* Offset within branch lookup table. */
3091 unsigned int offset
;
3093 /* Generation marker. */
3097 /* Used to track dynamic relocations for local symbols. */
3098 struct ppc_dyn_relocs
3100 struct ppc_dyn_relocs
*next
;
3102 /* The input section of the reloc. */
3105 /* Total number of relocs copied for the input section. */
3106 unsigned int count
: 31;
3108 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3109 unsigned int ifunc
: 1;
3112 struct ppc_link_hash_entry
3114 struct elf_link_hash_entry elf
;
3118 /* A pointer to the most recently used stub hash entry against this
3120 struct ppc_stub_hash_entry
*stub_cache
;
3122 /* A pointer to the next symbol starting with a '.' */
3123 struct ppc_link_hash_entry
*next_dot_sym
;
3126 /* Link between function code and descriptor symbols. */
3127 struct ppc_link_hash_entry
*oh
;
3129 /* Flag function code and descriptor symbols. */
3130 unsigned int is_func
:1;
3131 unsigned int is_func_descriptor
:1;
3132 unsigned int fake
:1;
3134 /* Whether global opd/toc sym has been adjusted or not.
3135 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3136 should be set for all globals defined in any opd/toc section. */
3137 unsigned int adjust_done
:1;
3139 /* Set if this is an out-of-line register save/restore function,
3140 with non-standard calling convention. */
3141 unsigned int save_res
:1;
3143 /* Set if a duplicate symbol with non-zero localentry is detected,
3144 even when the duplicate symbol does not provide a definition. */
3145 unsigned int non_zero_localentry
:1;
3147 /* Contexts in which symbol is used in the GOT (or TOC).
3148 Bits are or'd into the mask as the corresponding relocs are
3149 encountered during check_relocs, with TLS_TLS being set when any
3150 of the other TLS bits are set. tls_optimize clears bits when
3151 optimizing to indicate the corresponding GOT entry type is not
3152 needed. If set, TLS_TLS is never cleared. tls_optimize may also
3153 set TLS_GDIE when a GD reloc turns into an IE one.
3154 These flags are also kept for local symbols. */
3155 #define TLS_TLS 1 /* Any TLS reloc. */
3156 #define TLS_GD 2 /* GD reloc. */
3157 #define TLS_LD 4 /* LD reloc. */
3158 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
3159 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
3160 #define TLS_MARK 32 /* __tls_get_addr call marked. */
3161 #define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
3162 #define TLS_EXPLICIT 256 /* TOC section TLS reloc, not stored. */
3163 unsigned char tls_mask
;
3165 /* The above field is also used to mark function symbols. In which
3166 case TLS_TLS will be 0. */
3167 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
3168 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
3169 #define NON_GOT 256 /* local symbol plt, not stored. */
3172 static inline struct ppc_link_hash_entry
*
3173 ppc_elf_hash_entry (struct elf_link_hash_entry
*ent
)
3175 return (struct ppc_link_hash_entry
*) ent
;
3178 static inline struct elf_link_hash_entry
*
3179 elf_hash_entry (struct ppc_link_hash_entry
*ent
)
3181 return (struct elf_link_hash_entry
*) ent
;
3184 /* ppc64 ELF linker hash table. */
3186 struct ppc_link_hash_table
3188 struct elf_link_hash_table elf
;
3190 /* The stub hash table. */
3191 struct bfd_hash_table stub_hash_table
;
3193 /* Another hash table for plt_branch stubs. */
3194 struct bfd_hash_table branch_hash_table
;
3196 /* Hash table for function prologue tocsave. */
3197 htab_t tocsave_htab
;
3199 /* Various options and other info passed from the linker. */
3200 struct ppc64_elf_params
*params
;
3202 /* The size of sec_info below. */
3203 unsigned int sec_info_arr_size
;
3205 /* Per-section array of extra section info. Done this way rather
3206 than as part of ppc64_elf_section_data so we have the info for
3207 non-ppc64 sections. */
3210 /* Along with elf_gp, specifies the TOC pointer used by this section. */
3215 /* The section group that this section belongs to. */
3216 struct map_stub
*group
;
3217 /* A temp section list pointer. */
3222 /* Linked list of groups. */
3223 struct map_stub
*group
;
3225 /* Temp used when calculating TOC pointers. */
3228 asection
*toc_first_sec
;
3230 /* Used when adding symbols. */
3231 struct ppc_link_hash_entry
*dot_syms
;
3233 /* Shortcuts to get to dynamic linker sections. */
3235 asection
*global_entry
;
3238 asection
*relpltlocal
;
3241 asection
*glink_eh_frame
;
3243 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3244 struct ppc_link_hash_entry
*tls_get_addr
;
3245 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3246 struct ppc_link_hash_entry
*tga_desc
;
3247 struct ppc_link_hash_entry
*tga_desc_fd
;
3248 struct map_stub
*tga_group
;
3250 /* The size of reliplt used by got entry relocs. */
3251 bfd_size_type got_reli_size
;
3254 unsigned long stub_count
[ppc_stub_save_res
];
3256 /* Number of stubs against global syms. */
3257 unsigned long stub_globals
;
3259 /* Set if we're linking code with function descriptors. */
3260 unsigned int opd_abi
:1;
3262 /* Support for multiple toc sections. */
3263 unsigned int do_multi_toc
:1;
3264 unsigned int multi_toc_needed
:1;
3265 unsigned int second_toc_pass
:1;
3266 unsigned int do_toc_opt
:1;
3268 /* Set if tls optimization is enabled. */
3269 unsigned int do_tls_opt
:1;
3271 /* Set if inline plt calls should be converted to direct calls. */
3272 unsigned int can_convert_all_inline_plt
:1;
3275 unsigned int stub_error
:1;
3277 /* Whether func_desc_adjust needs to be run over symbols. */
3278 unsigned int need_func_desc_adj
:1;
3280 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
3281 unsigned int has_plt_localentry0
:1;
3283 /* Whether calls are made via the PLT from NOTOC functions. */
3284 unsigned int notoc_plt
:1;
3286 /* Whether any code linked seems to be Power10. */
3287 unsigned int has_power10_relocs
:1;
3289 /* Incremented every time we size stubs. */
3290 unsigned int stub_iteration
;
3293 /* Rename some of the generic section flags to better document how they
3296 /* Nonzero if this section has TLS related relocations. */
3297 #define has_tls_reloc sec_flg0
3299 /* Nonzero if this section has a call to __tls_get_addr lacking marker
3301 #define nomark_tls_get_addr sec_flg1
3303 /* Nonzero if this section has any toc or got relocs. */
3304 #define has_toc_reloc sec_flg2
3306 /* Nonzero if this section has a call to another section that uses
3308 #define makes_toc_func_call sec_flg3
3310 /* Recursion protection when determining above flag. */
3311 #define call_check_in_progress sec_flg4
3312 #define call_check_done sec_flg5
3314 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3316 #define ppc_hash_table(p) \
3317 ((is_elf_hash_table ((p)->hash) \
3318 && elf_hash_table_id (elf_hash_table (p)) == PPC64_ELF_DATA) \
3319 ? (struct ppc_link_hash_table *) (p)->hash : NULL)
3321 #define ppc_stub_hash_lookup(table, string, create, copy) \
3322 ((struct ppc_stub_hash_entry *) \
3323 bfd_hash_lookup ((table), (string), (create), (copy)))
3325 #define ppc_branch_hash_lookup(table, string, create, copy) \
3326 ((struct ppc_branch_hash_entry *) \
3327 bfd_hash_lookup ((table), (string), (create), (copy)))
3329 /* Create an entry in the stub hash table. */
3331 static struct bfd_hash_entry
*
3332 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3333 struct bfd_hash_table
*table
,
3336 /* Allocate the structure if it has not already been allocated by a
3340 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3345 /* Call the allocation method of the superclass. */
3346 entry
= bfd_hash_newfunc (entry
, table
, string
);
3349 struct ppc_stub_hash_entry
*eh
;
3351 /* Initialize the local fields. */
3352 eh
= (struct ppc_stub_hash_entry
*) entry
;
3353 eh
->type
.main
= ppc_stub_none
;
3354 eh
->type
.sub
= ppc_stub_toc
;
3355 eh
->type
.r2save
= 0;
3357 eh
->stub_offset
= 0;
3358 eh
->target_value
= 0;
3359 eh
->target_section
= NULL
;
3368 /* Create an entry in the branch hash table. */
3370 static struct bfd_hash_entry
*
3371 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3372 struct bfd_hash_table
*table
,
3375 /* Allocate the structure if it has not already been allocated by a
3379 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3384 /* Call the allocation method of the superclass. */
3385 entry
= bfd_hash_newfunc (entry
, table
, string
);
3388 struct ppc_branch_hash_entry
*eh
;
3390 /* Initialize the local fields. */
3391 eh
= (struct ppc_branch_hash_entry
*) entry
;
3399 /* Create an entry in a ppc64 ELF linker hash table. */
3401 static struct bfd_hash_entry
*
3402 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3403 struct bfd_hash_table
*table
,
3406 /* Allocate the structure if it has not already been allocated by a
3410 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3415 /* Call the allocation method of the superclass. */
3416 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3419 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3421 memset (&eh
->u
.stub_cache
, 0,
3422 (sizeof (struct ppc_link_hash_entry
)
3423 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3425 /* When making function calls, old ABI code references function entry
3426 points (dot symbols), while new ABI code references the function
3427 descriptor symbol. We need to make any combination of reference and
3428 definition work together, without breaking archive linking.
3430 For a defined function "foo" and an undefined call to "bar":
3431 An old object defines "foo" and ".foo", references ".bar" (possibly
3433 A new object defines "foo" and references "bar".
3435 A new object thus has no problem with its undefined symbols being
3436 satisfied by definitions in an old object. On the other hand, the
3437 old object won't have ".bar" satisfied by a new object.
3439 Keep a list of newly added dot-symbols. */
3441 if (string
[0] == '.')
3443 struct ppc_link_hash_table
*htab
;
3445 htab
= (struct ppc_link_hash_table
*) table
;
3446 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3447 htab
->dot_syms
= eh
;
3454 struct tocsave_entry
3461 tocsave_htab_hash (const void *p
)
3463 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3464 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3468 tocsave_htab_eq (const void *p1
, const void *p2
)
3470 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3471 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3472 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3475 /* Destroy a ppc64 ELF linker hash table. */
3478 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3480 struct ppc_link_hash_table
*htab
;
3482 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3483 if (htab
->tocsave_htab
)
3484 htab_delete (htab
->tocsave_htab
);
3485 bfd_hash_table_free (&htab
->branch_hash_table
);
3486 bfd_hash_table_free (&htab
->stub_hash_table
);
3487 _bfd_elf_link_hash_table_free (obfd
);
3490 /* Create a ppc64 ELF linker hash table. */
3492 static struct bfd_link_hash_table
*
3493 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3495 struct ppc_link_hash_table
*htab
;
3496 size_t amt
= sizeof (struct ppc_link_hash_table
);
3498 htab
= bfd_zmalloc (amt
);
3502 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3503 sizeof (struct ppc_link_hash_entry
),
3510 /* Init the stub hash table too. */
3511 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3512 sizeof (struct ppc_stub_hash_entry
)))
3514 _bfd_elf_link_hash_table_free (abfd
);
3518 /* And the branch hash table. */
3519 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3520 sizeof (struct ppc_branch_hash_entry
)))
3522 bfd_hash_table_free (&htab
->stub_hash_table
);
3523 _bfd_elf_link_hash_table_free (abfd
);
3527 htab
->tocsave_htab
= htab_try_create (1024,
3531 if (htab
->tocsave_htab
== NULL
)
3533 ppc64_elf_link_hash_table_free (abfd
);
3536 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3538 /* Initializing two fields of the union is just cosmetic. We really
3539 only care about glist, but when compiled on a 32-bit host the
3540 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3541 debugger inspection of these fields look nicer. */
3542 htab
->elf
.init_got_refcount
.refcount
= 0;
3543 htab
->elf
.init_got_refcount
.glist
= NULL
;
3544 htab
->elf
.init_plt_refcount
.refcount
= 0;
3545 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3546 htab
->elf
.init_got_offset
.offset
= 0;
3547 htab
->elf
.init_got_offset
.glist
= NULL
;
3548 htab
->elf
.init_plt_offset
.offset
= 0;
3549 htab
->elf
.init_plt_offset
.glist
= NULL
;
3551 return &htab
->elf
.root
;
3554 /* Create sections for linker generated code. */
3557 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3559 struct ppc_link_hash_table
*htab
;
3562 htab
= ppc_hash_table (info
);
3564 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3565 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3566 if (htab
->params
->save_restore_funcs
)
3568 /* Create .sfpr for code to save and restore fp regs. */
3569 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3571 if (htab
->sfpr
== NULL
3572 || !bfd_set_section_alignment (htab
->sfpr
, 2))
3576 if (bfd_link_relocatable (info
))
3579 /* Create .glink for lazy dynamic linking support. */
3580 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3582 if (htab
->glink
== NULL
3583 || !bfd_set_section_alignment (htab
->glink
, 3))
3586 /* The part of .glink used by global entry stubs, separate so that
3587 it can be aligned appropriately without affecting htab->glink. */
3588 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3590 if (htab
->global_entry
== NULL
3591 || !bfd_set_section_alignment (htab
->global_entry
, 2))
3594 if (!info
->no_ld_generated_unwind_info
)
3596 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3597 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3598 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3601 if (htab
->glink_eh_frame
== NULL
3602 || !bfd_set_section_alignment (htab
->glink_eh_frame
, 2))
3606 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3607 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3608 if (htab
->elf
.iplt
== NULL
3609 || !bfd_set_section_alignment (htab
->elf
.iplt
, 3))
3612 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3613 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3615 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3616 if (htab
->elf
.irelplt
== NULL
3617 || !bfd_set_section_alignment (htab
->elf
.irelplt
, 3))
3620 /* Create branch lookup table for plt_branch stubs. */
3621 flags
= (SEC_ALLOC
| SEC_LOAD
3622 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3623 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3625 if (htab
->brlt
== NULL
3626 || !bfd_set_section_alignment (htab
->brlt
, 3))
3629 /* Local plt entries, put in .branch_lt but a separate section for
3631 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3633 if (htab
->pltlocal
== NULL
3634 || !bfd_set_section_alignment (htab
->pltlocal
, 3))
3637 if (!bfd_link_pic (info
))
3640 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3641 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3643 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3644 if (htab
->relbrlt
== NULL
3645 || !bfd_set_section_alignment (htab
->relbrlt
, 3))
3649 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3650 if (htab
->relpltlocal
== NULL
3651 || !bfd_set_section_alignment (htab
->relpltlocal
, 3))
3657 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3660 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3661 struct ppc64_elf_params
*params
)
3663 struct ppc_link_hash_table
*htab
;
3665 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3667 /* Always hook our dynamic sections into the first bfd, which is the
3668 linker created stub bfd. This ensures that the GOT header is at
3669 the start of the output TOC section. */
3670 htab
= ppc_hash_table (info
);
3671 htab
->elf
.dynobj
= params
->stub_bfd
;
3672 htab
->params
= params
;
3674 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3677 /* Build a name for an entry in the stub hash table. */
3680 ppc_stub_name (const asection
*input_section
,
3681 const asection
*sym_sec
,
3682 const struct ppc_link_hash_entry
*h
,
3683 const Elf_Internal_Rela
*rel
)
3688 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3689 offsets from a sym as a branch target? In fact, we could
3690 probably assume the addend is always zero. */
3691 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3695 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3696 stub_name
= bfd_malloc (len
);
3697 if (stub_name
== NULL
)
3700 len
= sprintf (stub_name
, "%08x.%s+%x",
3701 input_section
->id
& 0xffffffff,
3702 h
->elf
.root
.root
.string
,
3703 (int) rel
->r_addend
& 0xffffffff);
3707 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3708 stub_name
= bfd_malloc (len
);
3709 if (stub_name
== NULL
)
3712 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3713 input_section
->id
& 0xffffffff,
3714 sym_sec
->id
& 0xffffffff,
3715 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3716 (int) rel
->r_addend
& 0xffffffff);
3718 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3719 stub_name
[len
- 2] = 0;
3723 /* If mixing power10 with non-power10 code and --power10-stubs is not
3724 specified (or is auto) then there may be multiple stub types for any
3725 given symbol. Up to three classes of stubs are stored in separate
3726 stub_hash_table entries having the same key string. The entries
3727 will always be adjacent on entry->root.next chain, even if hash
3728 table resizing occurs. This function selects the correct entry to
3731 static struct ppc_stub_hash_entry
*
3732 select_alt_stub (struct ppc_stub_hash_entry
*entry
,
3733 enum elf_ppc64_reloc_type r_type
)
3735 enum ppc_stub_sub_type subt
;
3739 case R_PPC64_REL24_NOTOC
:
3740 subt
= ppc_stub_notoc
;
3742 case R_PPC64_REL24_P9NOTOC
:
3743 subt
= ppc_stub_p9notoc
;
3746 subt
= ppc_stub_toc
;
3750 while (entry
!= NULL
&& entry
->type
.sub
!= subt
)
3752 const char *stub_name
= entry
->root
.string
;
3754 entry
= (struct ppc_stub_hash_entry
*) entry
->root
.next
;
3756 && entry
->root
.string
!= stub_name
)
3763 /* Look up an entry in the stub hash. Stub entries are cached because
3764 creating the stub name takes a bit of time. */
3766 static struct ppc_stub_hash_entry
*
3767 ppc_get_stub_entry (const asection
*input_section
,
3768 const asection
*sym_sec
,
3769 struct ppc_link_hash_entry
*h
,
3770 const Elf_Internal_Rela
*rel
,
3771 struct ppc_link_hash_table
*htab
)
3773 struct ppc_stub_hash_entry
*stub_entry
;
3774 struct map_stub
*group
;
3776 /* If this input section is part of a group of sections sharing one
3777 stub section, then use the id of the first section in the group.
3778 Stub names need to include a section id, as there may well be
3779 more than one stub used to reach say, printf, and we need to
3780 distinguish between them. */
3781 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3785 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3786 && h
->u
.stub_cache
->h
== h
3787 && h
->u
.stub_cache
->group
== group
)
3789 stub_entry
= h
->u
.stub_cache
;
3795 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3796 if (stub_name
== NULL
)
3799 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3800 stub_name
, false, false);
3802 h
->u
.stub_cache
= stub_entry
;
3807 if (stub_entry
!= NULL
&& htab
->params
->power10_stubs
== -1)
3808 stub_entry
= select_alt_stub (stub_entry
, ELF64_R_TYPE (rel
->r_info
));
3813 /* Add a new stub entry to the stub hash. Not all fields of the new
3814 stub entry are initialised. */
3816 static struct ppc_stub_hash_entry
*
3817 ppc_add_stub (const char *stub_name
,
3819 struct bfd_link_info
*info
)
3821 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3822 struct map_stub
*group
;
3825 struct ppc_stub_hash_entry
*stub_entry
;
3827 group
= htab
->sec_info
[section
->id
].u
.group
;
3828 link_sec
= group
->link_sec
;
3829 stub_sec
= group
->stub_sec
;
3830 if (stub_sec
== NULL
)
3836 namelen
= strlen (link_sec
->name
);
3837 len
= namelen
+ sizeof (STUB_SUFFIX
);
3838 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3842 memcpy (s_name
, link_sec
->name
, namelen
);
3843 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3844 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3845 if (stub_sec
== NULL
)
3847 group
->stub_sec
= stub_sec
;
3850 /* Enter this entry into the linker stub hash table. */
3851 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3853 if (stub_entry
== NULL
)
3855 /* xgettext:c-format */
3856 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3857 section
->owner
, stub_name
);
3861 stub_entry
->group
= group
;
3862 stub_entry
->stub_offset
= 0;
3866 /* A stub has already been created, but it may not be the required
3867 type. We shouldn't be transitioning from plt_call to long_branch
3868 stubs or vice versa, but we might be upgrading from plt_call to
3869 plt_call with r2save for example. */
3872 ppc_merge_stub (struct ppc_link_hash_table
*htab
,
3873 struct ppc_stub_hash_entry
*stub_entry
,
3874 struct ppc_stub_type stub_type
,
3875 enum elf_ppc64_reloc_type r_type
)
3877 struct ppc_stub_type old_type
= stub_entry
->type
;
3879 if (old_type
.main
== ppc_stub_save_res
)
3882 if (htab
->params
->power10_stubs
== -1)
3884 /* For --power10-stubs=auto, don't merge _notoc and other
3885 varieties of stubs. */
3886 struct ppc_stub_hash_entry
*alt_stub
;
3888 alt_stub
= select_alt_stub (stub_entry
, r_type
);
3889 if (alt_stub
== NULL
)
3891 alt_stub
= ((struct ppc_stub_hash_entry
*)
3892 stub_hash_newfunc (NULL
,
3893 &htab
->stub_hash_table
,
3894 stub_entry
->root
.string
));
3895 if (alt_stub
== NULL
)
3898 *alt_stub
= *stub_entry
;
3899 stub_entry
->root
.next
= &alt_stub
->root
;
3901 /* Sort notoc stubs first, then toc stubs, then p9notoc.
3902 Not that it matters, this just puts smaller stubs first. */
3903 if (stub_type
.sub
== ppc_stub_notoc
)
3904 alt_stub
= stub_entry
;
3905 else if (stub_type
.sub
== ppc_stub_p9notoc
3906 && alt_stub
->root
.next
3907 && alt_stub
->root
.next
->string
== alt_stub
->root
.string
)
3909 struct ppc_stub_hash_entry
*next
3910 = (struct ppc_stub_hash_entry
*) alt_stub
->root
.next
;
3911 alt_stub
->type
= next
->type
;
3914 alt_stub
->type
= stub_type
;
3917 stub_entry
= alt_stub
;
3920 old_type
= stub_entry
->type
;
3921 if (old_type
.main
== ppc_stub_plt_branch
)
3922 old_type
.main
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
3924 if (old_type
.main
!= stub_type
.main
3925 || (old_type
.sub
!= stub_type
.sub
3926 && old_type
.sub
!= ppc_stub_toc
3927 && stub_type
.sub
!= ppc_stub_toc
))
3930 stub_entry
->type
.sub
|= stub_type
.sub
;
3931 stub_entry
->type
.r2save
|= stub_type
.r2save
;
3935 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3936 not already done. */
3939 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3941 asection
*got
, *relgot
;
3943 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3945 if (!is_ppc64_elf (abfd
))
3951 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3954 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3955 | SEC_LINKER_CREATED
);
3957 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3959 || !bfd_set_section_alignment (got
, 3))
3962 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3963 flags
| SEC_READONLY
);
3965 || !bfd_set_section_alignment (relgot
, 3))
3968 ppc64_elf_tdata (abfd
)->got
= got
;
3969 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3973 /* Follow indirect and warning symbol links. */
3975 static inline struct bfd_link_hash_entry
*
3976 follow_link (struct bfd_link_hash_entry
*h
)
3978 while (h
->type
== bfd_link_hash_indirect
3979 || h
->type
== bfd_link_hash_warning
)
3984 static inline struct elf_link_hash_entry
*
3985 elf_follow_link (struct elf_link_hash_entry
*h
)
3987 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
3990 static inline struct ppc_link_hash_entry
*
3991 ppc_follow_link (struct ppc_link_hash_entry
*h
)
3993 return ppc_elf_hash_entry (elf_follow_link (&h
->elf
));
3996 /* Merge PLT info on FROM with that on TO. */
3999 move_plt_plist (struct ppc_link_hash_entry
*from
,
4000 struct ppc_link_hash_entry
*to
)
4002 if (from
->elf
.plt
.plist
!= NULL
)
4004 if (to
->elf
.plt
.plist
!= NULL
)
4006 struct plt_entry
**entp
;
4007 struct plt_entry
*ent
;
4009 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4011 struct plt_entry
*dent
;
4013 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4014 if (dent
->addend
== ent
->addend
)
4016 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4023 *entp
= to
->elf
.plt
.plist
;
4026 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4027 from
->elf
.plt
.plist
= NULL
;
4031 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4034 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4035 struct elf_link_hash_entry
*dir
,
4036 struct elf_link_hash_entry
*ind
)
4038 struct ppc_link_hash_entry
*edir
, *eind
;
4040 edir
= ppc_elf_hash_entry (dir
);
4041 eind
= ppc_elf_hash_entry (ind
);
4043 edir
->is_func
|= eind
->is_func
;
4044 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4045 edir
->tls_mask
|= eind
->tls_mask
;
4046 if (eind
->oh
!= NULL
)
4047 edir
->oh
= ppc_follow_link (eind
->oh
);
4049 if (edir
->elf
.versioned
!= versioned_hidden
)
4050 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4051 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4052 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4053 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4054 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4055 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4057 /* If we were called to copy over info for a weak sym, don't copy
4058 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4059 in order to simplify readonly_dynrelocs and save a field in the
4060 symbol hash entry, but that means dyn_relocs can't be used in any
4061 tests about a specific symbol, or affect other symbol flags which
4063 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4066 /* Copy over any dynamic relocs we may have on the indirect sym. */
4067 if (ind
->dyn_relocs
!= NULL
)
4069 if (dir
->dyn_relocs
!= NULL
)
4071 struct elf_dyn_relocs
**pp
;
4072 struct elf_dyn_relocs
*p
;
4074 /* Add reloc counts against the indirect sym to the direct sym
4075 list. Merge any entries against the same section. */
4076 for (pp
= &ind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4078 struct elf_dyn_relocs
*q
;
4080 for (q
= dir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4081 if (q
->sec
== p
->sec
)
4083 q
->pc_count
+= p
->pc_count
;
4084 q
->count
+= p
->count
;
4091 *pp
= dir
->dyn_relocs
;
4094 dir
->dyn_relocs
= ind
->dyn_relocs
;
4095 ind
->dyn_relocs
= NULL
;
4098 /* Copy over got entries that we may have already seen to the
4099 symbol which just became indirect. */
4100 if (eind
->elf
.got
.glist
!= NULL
)
4102 if (edir
->elf
.got
.glist
!= NULL
)
4104 struct got_entry
**entp
;
4105 struct got_entry
*ent
;
4107 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4109 struct got_entry
*dent
;
4111 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4112 if (dent
->addend
== ent
->addend
4113 && dent
->owner
== ent
->owner
4114 && dent
->tls_type
== ent
->tls_type
)
4116 dent
->got
.refcount
+= ent
->got
.refcount
;
4123 *entp
= edir
->elf
.got
.glist
;
4126 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4127 eind
->elf
.got
.glist
= NULL
;
4130 /* And plt entries. */
4131 move_plt_plist (eind
, edir
);
4133 if (eind
->elf
.dynindx
!= -1)
4135 if (edir
->elf
.dynindx
!= -1)
4136 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4137 edir
->elf
.dynstr_index
);
4138 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4139 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4140 eind
->elf
.dynindx
= -1;
4141 eind
->elf
.dynstr_index
= 0;
4145 /* Find the function descriptor hash entry from the given function code
4146 hash entry FH. Link the entries via their OH fields. */
4148 static struct ppc_link_hash_entry
*
4149 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4151 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4155 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4157 fdh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, fd_name
,
4158 false, false, false));
4162 fdh
->is_func_descriptor
= 1;
4168 fdh
= ppc_follow_link (fdh
);
4169 fdh
->is_func_descriptor
= 1;
4174 /* Make a fake function descriptor sym for the undefined code sym FH. */
4176 static struct ppc_link_hash_entry
*
4177 make_fdh (struct bfd_link_info
*info
,
4178 struct ppc_link_hash_entry
*fh
)
4180 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4181 struct bfd_link_hash_entry
*bh
= NULL
;
4182 struct ppc_link_hash_entry
*fdh
;
4183 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4187 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4188 fh
->elf
.root
.root
.string
+ 1,
4189 flags
, bfd_und_section_ptr
, 0,
4190 NULL
, false, false, &bh
))
4193 fdh
= (struct ppc_link_hash_entry
*) bh
;
4194 fdh
->elf
.non_elf
= 0;
4196 fdh
->is_func_descriptor
= 1;
4203 /* Fix function descriptor symbols defined in .opd sections to be
4207 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4208 struct bfd_link_info
*info
,
4209 Elf_Internal_Sym
*isym
,
4211 flagword
*flags ATTRIBUTE_UNUSED
,
4216 && strcmp ((*sec
)->name
, ".opd") == 0)
4220 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4221 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4222 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4224 /* If the symbol is a function defined in .opd, and the function
4225 code is in a discarded group, let it appear to be undefined. */
4226 if (!bfd_link_relocatable (info
)
4227 && (*sec
)->reloc_count
!= 0
4228 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4229 false) != (bfd_vma
) -1
4230 && discarded_section (code_sec
))
4232 *sec
= bfd_und_section_ptr
;
4233 isym
->st_shndx
= SHN_UNDEF
;
4236 else if (*sec
!= NULL
4237 && strcmp ((*sec
)->name
, ".toc") == 0
4238 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4240 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4242 htab
->params
->object_in_toc
= 1;
4245 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4247 if (abiversion (ibfd
) == 0)
4248 set_abiversion (ibfd
, 2);
4249 else if (abiversion (ibfd
) == 1)
4251 _bfd_error_handler (_("symbol '%s' has invalid st_other"
4252 " for ABI version 1"), *name
);
4253 bfd_set_error (bfd_error_bad_value
);
4261 /* Merge non-visibility st_other attributes: local entry point. */
4264 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
4265 unsigned int st_other
,
4269 if (definition
&& (!dynamic
|| !h
->def_regular
))
4270 h
->other
= ((st_other
& ~ELF_ST_VISIBILITY (-1))
4271 | ELF_ST_VISIBILITY (h
->other
));
4274 /* Hook called on merging a symbol. We use this to clear "fake" since
4275 we now have a real symbol. */
4278 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
4279 const Elf_Internal_Sym
*isym
,
4280 asection
**psec ATTRIBUTE_UNUSED
,
4281 bool newdef ATTRIBUTE_UNUSED
,
4282 bool olddef ATTRIBUTE_UNUSED
,
4283 bfd
*oldbfd ATTRIBUTE_UNUSED
,
4284 const asection
*oldsec ATTRIBUTE_UNUSED
)
4286 ppc_elf_hash_entry (h
)->fake
= 0;
4287 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4288 ppc_elf_hash_entry (h
)->non_zero_localentry
= 1;
4292 /* This function makes an old ABI object reference to ".bar" cause the
4293 inclusion of a new ABI object archive that defines "bar".
4294 NAME is a symbol defined in an archive. Return a symbol in the hash
4295 table that might be satisfied by the archive symbols. */
4297 static struct bfd_link_hash_entry
*
4298 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4299 struct bfd_link_info
*info
,
4302 struct bfd_link_hash_entry
*h
;
4306 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4308 && ppc_hash_table (info
) != NULL
4309 /* Don't return this sym if it is a fake function descriptor
4310 created by add_symbol_adjust. */
4311 && !((struct ppc_link_hash_entry
*) h
)->fake
)
4317 len
= strlen (name
);
4318 dot_name
= bfd_alloc (abfd
, len
+ 2);
4319 if (dot_name
== NULL
)
4320 return (struct bfd_link_hash_entry
*) -1;
4322 memcpy (dot_name
+ 1, name
, len
+ 1);
4323 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4324 bfd_release (abfd
, dot_name
);
4328 if (strcmp (name
, "__tls_get_addr_opt") == 0)
4329 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, "__tls_get_addr_desc");
4333 /* This function satisfies all old ABI object references to ".bar" if a
4334 new ABI object defines "bar". Well, at least, undefined dot symbols
4335 are made weak. This stops later archive searches from including an
4336 object if we already have a function descriptor definition. It also
4337 prevents the linker complaining about undefined symbols.
4338 We also check and correct mismatched symbol visibility here. The
4339 most restrictive visibility of the function descriptor and the
4340 function entry symbol is used. */
4343 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4345 struct ppc_link_hash_table
*htab
;
4346 struct ppc_link_hash_entry
*fdh
;
4348 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4349 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4351 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4354 if (eh
->elf
.root
.root
.string
[0] != '.')
4357 htab
= ppc_hash_table (info
);
4361 fdh
= lookup_fdh (eh
, htab
);
4363 && !bfd_link_relocatable (info
)
4364 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4365 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4366 && eh
->elf
.ref_regular
)
4368 /* Make an undefined function descriptor sym, in order to
4369 pull in an --as-needed shared lib. Archives are handled
4371 fdh
= make_fdh (info
, eh
);
4378 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4379 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4381 /* Make both descriptor and entry symbol have the most
4382 constraining visibility of either symbol. */
4383 if (entry_vis
< descr_vis
)
4384 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4385 else if (entry_vis
> descr_vis
)
4386 eh
->elf
.other
+= descr_vis
- entry_vis
;
4388 /* Propagate reference flags from entry symbol to function
4389 descriptor symbol. */
4390 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
4391 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
4392 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
4393 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
4395 if (!fdh
->elf
.forced_local
4396 && fdh
->elf
.dynindx
== -1
4397 && fdh
->elf
.versioned
!= versioned_hidden
4398 && (bfd_link_dll (info
)
4399 || fdh
->elf
.def_dynamic
4400 || fdh
->elf
.ref_dynamic
)
4401 && (eh
->elf
.ref_regular
4402 || eh
->elf
.def_regular
))
4404 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
4412 /* Set up opd section info and abiversion for IBFD, and process list
4413 of dot-symbols we made in link_hash_newfunc. */
4416 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
4418 struct ppc_link_hash_table
*htab
;
4419 struct ppc_link_hash_entry
**p
, *eh
;
4420 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
4422 if (opd
!= NULL
&& opd
->size
!= 0)
4424 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
4425 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
4427 if (abiversion (ibfd
) == 0)
4428 set_abiversion (ibfd
, 1);
4429 else if (abiversion (ibfd
) >= 2)
4431 /* xgettext:c-format */
4432 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4433 ibfd
, abiversion (ibfd
));
4434 bfd_set_error (bfd_error_bad_value
);
4439 if (is_ppc64_elf (info
->output_bfd
))
4441 /* For input files without an explicit abiversion in e_flags
4442 we should have flagged any with symbol st_other bits set
4443 as ELFv1 and above flagged those with .opd as ELFv2.
4444 Set the output abiversion if not yet set, and for any input
4445 still ambiguous, take its abiversion from the output.
4446 Differences in ABI are reported later. */
4447 if (abiversion (info
->output_bfd
) == 0)
4448 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4449 else if (abiversion (ibfd
) == 0)
4450 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4453 htab
= ppc_hash_table (info
);
4457 if (opd
!= NULL
&& opd
->size
!= 0
4458 && (ibfd
->flags
& DYNAMIC
) == 0
4459 && (opd
->flags
& SEC_RELOC
) != 0
4460 && opd
->reloc_count
!= 0
4461 && !bfd_is_abs_section (opd
->output_section
)
4462 && info
->gc_sections
)
4464 /* Garbage collection needs some extra help with .opd sections.
4465 We don't want to necessarily keep everything referenced by
4466 relocs in .opd, as that would keep all functions. Instead,
4467 if we reference an .opd symbol (a function descriptor), we
4468 want to keep the function code symbol's section. This is
4469 easy for global symbols, but for local syms we need to keep
4470 information about the associated function section. */
4472 asection
**opd_sym_map
;
4473 Elf_Internal_Shdr
*symtab_hdr
;
4474 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4476 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4477 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4478 if (opd_sym_map
== NULL
)
4480 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4481 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4485 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4486 rel_end
= relocs
+ opd
->reloc_count
- 1;
4487 for (rel
= relocs
; rel
< rel_end
; rel
++)
4489 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4490 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4492 if (r_type
== R_PPC64_ADDR64
4493 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4494 && r_symndx
< symtab_hdr
->sh_info
)
4496 Elf_Internal_Sym
*isym
;
4499 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, ibfd
,
4503 if (elf_section_data (opd
)->relocs
!= relocs
)
4508 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4509 if (s
!= NULL
&& s
!= opd
)
4510 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4513 if (elf_section_data (opd
)->relocs
!= relocs
)
4517 p
= &htab
->dot_syms
;
4518 while ((eh
= *p
) != NULL
)
4521 if (&eh
->elf
== htab
->elf
.hgot
)
4523 else if (htab
->elf
.hgot
== NULL
4524 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4525 htab
->elf
.hgot
= &eh
->elf
;
4526 else if (abiversion (ibfd
) <= 1)
4528 htab
->need_func_desc_adj
= 1;
4529 if (!add_symbol_adjust (eh
, info
))
4532 p
= &eh
->u
.next_dot_sym
;
4537 /* Undo hash table changes when an --as-needed input file is determined
4538 not to be needed. */
4541 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4542 struct bfd_link_info
*info
,
4543 enum notice_asneeded_action act
)
4545 if (act
== notice_not_needed
)
4547 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4552 htab
->dot_syms
= NULL
;
4554 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4557 /* If --just-symbols against a final linked binary, then assume we need
4558 toc adjusting stubs when calling functions defined there. */
4561 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4563 if ((sec
->flags
& SEC_CODE
) != 0
4564 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4565 && is_ppc64_elf (sec
->owner
))
4567 if (abiversion (sec
->owner
) >= 2
4568 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4569 sec
->has_toc_reloc
= 1;
4571 _bfd_elf_link_just_syms (sec
, info
);
4574 static struct plt_entry
**
4575 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4576 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4578 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4579 struct plt_entry
**local_plt
;
4580 unsigned char *local_got_tls_masks
;
4582 if (local_got_ents
== NULL
)
4584 bfd_size_type size
= symtab_hdr
->sh_info
;
4586 size
*= (sizeof (*local_got_ents
)
4587 + sizeof (*local_plt
)
4588 + sizeof (*local_got_tls_masks
));
4589 local_got_ents
= bfd_zalloc (abfd
, size
);
4590 if (local_got_ents
== NULL
)
4592 elf_local_got_ents (abfd
) = local_got_ents
;
4595 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4597 struct got_entry
*ent
;
4599 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4600 if (ent
->addend
== r_addend
4601 && ent
->owner
== abfd
4602 && ent
->tls_type
== tls_type
)
4606 size_t amt
= sizeof (*ent
);
4607 ent
= bfd_alloc (abfd
, amt
);
4610 ent
->next
= local_got_ents
[r_symndx
];
4611 ent
->addend
= r_addend
;
4613 ent
->tls_type
= tls_type
;
4614 ent
->is_indirect
= false;
4615 ent
->got
.refcount
= 0;
4616 local_got_ents
[r_symndx
] = ent
;
4618 ent
->got
.refcount
+= 1;
4621 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4622 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4623 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4625 return local_plt
+ r_symndx
;
4629 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4631 struct plt_entry
*ent
;
4633 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4634 if (ent
->addend
== addend
)
4638 size_t amt
= sizeof (*ent
);
4639 ent
= bfd_alloc (abfd
, amt
);
4643 ent
->addend
= addend
;
4644 ent
->plt
.refcount
= 0;
4647 ent
->plt
.refcount
+= 1;
4652 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4654 return (r_type
== R_PPC64_REL24
4655 || r_type
== R_PPC64_REL24_NOTOC
4656 || r_type
== R_PPC64_REL24_P9NOTOC
4657 || r_type
== R_PPC64_REL14
4658 || r_type
== R_PPC64_REL14_BRTAKEN
4659 || r_type
== R_PPC64_REL14_BRNTAKEN
4660 || r_type
== R_PPC64_ADDR24
4661 || r_type
== R_PPC64_ADDR14
4662 || r_type
== R_PPC64_ADDR14_BRTAKEN
4663 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4664 || r_type
== R_PPC64_PLTCALL
4665 || r_type
== R_PPC64_PLTCALL_NOTOC
);
4668 /* Relocs on inline plt call sequence insns prior to the call. */
4671 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4673 return (r_type
== R_PPC64_PLT16_HA
4674 || r_type
== R_PPC64_PLT16_HI
4675 || r_type
== R_PPC64_PLT16_LO
4676 || r_type
== R_PPC64_PLT16_LO_DS
4677 || r_type
== R_PPC64_PLT_PCREL34
4678 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4679 || r_type
== R_PPC64_PLTSEQ
4680 || r_type
== R_PPC64_PLTSEQ_NOTOC
);
4683 /* Of relocs which might appear paired with TLSGD and TLSLD marker
4684 relocs, return true for those that operate on a dword. */
4687 is_8byte_reloc (enum elf_ppc64_reloc_type r_type
)
4689 return (r_type
== R_PPC64_PLT_PCREL34
4690 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4691 || r_type
== R_PPC64_PLTCALL
);
4694 /* Like bfd_reloc_offset_in_range but without a howto. Return true
4695 iff a field of SIZE bytes at OFFSET is within SEC limits. */
4698 offset_in_range (asection
*sec
, bfd_vma offset
, size_t size
)
4700 return offset
<= sec
->size
&& size
<= sec
->size
- offset
;
4703 /* Look through the relocs for a section during the first phase, and
4704 calculate needed space in the global offset table, procedure
4705 linkage table, and dynamic reloc sections. */
4708 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4709 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4711 struct ppc_link_hash_table
*htab
;
4712 Elf_Internal_Shdr
*symtab_hdr
;
4713 struct elf_link_hash_entry
**sym_hashes
;
4714 const Elf_Internal_Rela
*rel
;
4715 const Elf_Internal_Rela
*rel_end
;
4717 struct elf_link_hash_entry
*tga
, *dottga
;
4720 if (bfd_link_relocatable (info
))
4723 BFD_ASSERT (is_ppc64_elf (abfd
));
4725 htab
= ppc_hash_table (info
);
4729 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4730 false, false, true);
4731 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4732 false, false, true);
4733 symtab_hdr
= &elf_symtab_hdr (abfd
);
4734 sym_hashes
= elf_sym_hashes (abfd
);
4736 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4737 rel_end
= relocs
+ sec
->reloc_count
;
4738 for (rel
= relocs
; rel
< rel_end
; rel
++)
4740 unsigned long r_symndx
;
4741 struct elf_link_hash_entry
*h
;
4742 enum elf_ppc64_reloc_type r_type
;
4744 struct _ppc64_elf_section_data
*ppc64_sec
;
4745 struct plt_entry
**ifunc
, **plt_list
;
4747 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4748 if (r_symndx
< symtab_hdr
->sh_info
)
4752 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4753 h
= elf_follow_link (h
);
4755 if (h
== htab
->elf
.hgot
)
4756 sec
->has_toc_reloc
= 1;
4759 r_type
= ELF64_R_TYPE (rel
->r_info
);
4763 case R_PPC64_D34_LO
:
4764 case R_PPC64_D34_HI30
:
4765 case R_PPC64_D34_HA30
:
4767 case R_PPC64_TPREL34
:
4768 case R_PPC64_DTPREL34
:
4769 case R_PPC64_PCREL34
:
4770 case R_PPC64_GOT_PCREL34
:
4771 case R_PPC64_GOT_TLSGD_PCREL34
:
4772 case R_PPC64_GOT_TLSLD_PCREL34
:
4773 case R_PPC64_GOT_TPREL_PCREL34
:
4774 case R_PPC64_GOT_DTPREL_PCREL34
:
4775 case R_PPC64_PLT_PCREL34
:
4776 case R_PPC64_PLT_PCREL34_NOTOC
:
4777 case R_PPC64_PCREL28
:
4778 htab
->has_power10_relocs
= 1;
4786 case R_PPC64_PLT16_HA
:
4787 case R_PPC64_GOT_TLSLD16_HA
:
4788 case R_PPC64_GOT_TLSGD16_HA
:
4789 case R_PPC64_GOT_TPREL16_HA
:
4790 case R_PPC64_GOT_DTPREL16_HA
:
4791 case R_PPC64_GOT16_HA
:
4792 case R_PPC64_TOC16_HA
:
4793 case R_PPC64_PLT16_LO
:
4794 case R_PPC64_PLT16_LO_DS
:
4795 case R_PPC64_GOT_TLSLD16_LO
:
4796 case R_PPC64_GOT_TLSGD16_LO
:
4797 case R_PPC64_GOT_TPREL16_LO_DS
:
4798 case R_PPC64_GOT_DTPREL16_LO_DS
:
4799 case R_PPC64_GOT16_LO
:
4800 case R_PPC64_GOT16_LO_DS
:
4801 case R_PPC64_TOC16_LO
:
4802 case R_PPC64_TOC16_LO_DS
:
4803 case R_PPC64_GOT_PCREL34
:
4804 ppc64_elf_tdata (abfd
)->has_optrel
= 1;
4805 ppc64_elf_section_data (sec
)->has_optrel
= 1;
4814 if (h
->type
== STT_GNU_IFUNC
)
4817 ifunc
= &h
->plt
.plist
;
4822 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
4827 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4829 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4831 NON_GOT
| PLT_IFUNC
);
4842 /* These special tls relocs tie a call to __tls_get_addr with
4843 its parameter symbol. */
4845 ppc_elf_hash_entry (h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4847 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4849 NON_GOT
| TLS_TLS
| TLS_MARK
))
4851 sec
->has_tls_reloc
= 1;
4854 case R_PPC64_GOT_TLSLD16
:
4855 case R_PPC64_GOT_TLSLD16_LO
:
4856 case R_PPC64_GOT_TLSLD16_HI
:
4857 case R_PPC64_GOT_TLSLD16_HA
:
4858 case R_PPC64_GOT_TLSLD_PCREL34
:
4859 tls_type
= TLS_TLS
| TLS_LD
;
4862 case R_PPC64_GOT_TLSGD16
:
4863 case R_PPC64_GOT_TLSGD16_LO
:
4864 case R_PPC64_GOT_TLSGD16_HI
:
4865 case R_PPC64_GOT_TLSGD16_HA
:
4866 case R_PPC64_GOT_TLSGD_PCREL34
:
4867 tls_type
= TLS_TLS
| TLS_GD
;
4870 case R_PPC64_GOT_TPREL16_DS
:
4871 case R_PPC64_GOT_TPREL16_LO_DS
:
4872 case R_PPC64_GOT_TPREL16_HI
:
4873 case R_PPC64_GOT_TPREL16_HA
:
4874 case R_PPC64_GOT_TPREL_PCREL34
:
4875 if (bfd_link_dll (info
))
4876 info
->flags
|= DF_STATIC_TLS
;
4877 tls_type
= TLS_TLS
| TLS_TPREL
;
4880 case R_PPC64_GOT_DTPREL16_DS
:
4881 case R_PPC64_GOT_DTPREL16_LO_DS
:
4882 case R_PPC64_GOT_DTPREL16_HI
:
4883 case R_PPC64_GOT_DTPREL16_HA
:
4884 case R_PPC64_GOT_DTPREL_PCREL34
:
4885 tls_type
= TLS_TLS
| TLS_DTPREL
;
4887 sec
->has_tls_reloc
= 1;
4891 case R_PPC64_GOT16_LO
:
4892 case R_PPC64_GOT16_HI
:
4893 case R_PPC64_GOT16_HA
:
4894 case R_PPC64_GOT16_DS
:
4895 case R_PPC64_GOT16_LO_DS
:
4896 case R_PPC64_GOT_PCREL34
:
4898 /* This symbol requires a global offset table entry. */
4899 sec
->has_toc_reloc
= 1;
4900 if (r_type
== R_PPC64_GOT_TLSLD16
4901 || r_type
== R_PPC64_GOT_TLSGD16
4902 || r_type
== R_PPC64_GOT_TPREL16_DS
4903 || r_type
== R_PPC64_GOT_DTPREL16_DS
4904 || r_type
== R_PPC64_GOT16
4905 || r_type
== R_PPC64_GOT16_DS
)
4907 htab
->do_multi_toc
= 1;
4908 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4911 if (ppc64_elf_tdata (abfd
)->got
== NULL
4912 && !create_got_section (abfd
, info
))
4917 struct ppc_link_hash_entry
*eh
;
4918 struct got_entry
*ent
;
4920 eh
= ppc_elf_hash_entry (h
);
4921 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4922 if (ent
->addend
== rel
->r_addend
4923 && ent
->owner
== abfd
4924 && ent
->tls_type
== tls_type
)
4928 size_t amt
= sizeof (*ent
);
4929 ent
= bfd_alloc (abfd
, amt
);
4932 ent
->next
= eh
->elf
.got
.glist
;
4933 ent
->addend
= rel
->r_addend
;
4935 ent
->tls_type
= tls_type
;
4936 ent
->is_indirect
= false;
4937 ent
->got
.refcount
= 0;
4938 eh
->elf
.got
.glist
= ent
;
4940 ent
->got
.refcount
+= 1;
4941 eh
->tls_mask
|= tls_type
;
4944 /* This is a global offset table entry for a local symbol. */
4945 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4946 rel
->r_addend
, tls_type
))
4950 case R_PPC64_PLT16_HA
:
4951 case R_PPC64_PLT16_HI
:
4952 case R_PPC64_PLT16_LO
:
4953 case R_PPC64_PLT16_LO_DS
:
4954 case R_PPC64_PLT_PCREL34
:
4955 case R_PPC64_PLT_PCREL34_NOTOC
:
4958 /* This symbol requires a procedure linkage table entry. */
4963 if (h
->root
.root
.string
[0] == '.'
4964 && h
->root
.root
.string
[1] != '\0')
4965 ppc_elf_hash_entry (h
)->is_func
= 1;
4966 ppc_elf_hash_entry (h
)->tls_mask
|= PLT_KEEP
;
4967 plt_list
= &h
->plt
.plist
;
4969 if (plt_list
== NULL
)
4970 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4972 NON_GOT
| PLT_KEEP
);
4973 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4977 /* The following relocations don't need to propagate the
4978 relocation if linking a shared object since they are
4979 section relative. */
4980 case R_PPC64_SECTOFF
:
4981 case R_PPC64_SECTOFF_LO
:
4982 case R_PPC64_SECTOFF_HI
:
4983 case R_PPC64_SECTOFF_HA
:
4984 case R_PPC64_SECTOFF_DS
:
4985 case R_PPC64_SECTOFF_LO_DS
:
4986 case R_PPC64_DTPREL16
:
4987 case R_PPC64_DTPREL16_LO
:
4988 case R_PPC64_DTPREL16_HI
:
4989 case R_PPC64_DTPREL16_HA
:
4990 case R_PPC64_DTPREL16_DS
:
4991 case R_PPC64_DTPREL16_LO_DS
:
4992 case R_PPC64_DTPREL16_HIGH
:
4993 case R_PPC64_DTPREL16_HIGHA
:
4994 case R_PPC64_DTPREL16_HIGHER
:
4995 case R_PPC64_DTPREL16_HIGHERA
:
4996 case R_PPC64_DTPREL16_HIGHEST
:
4997 case R_PPC64_DTPREL16_HIGHESTA
:
5002 case R_PPC64_REL16_LO
:
5003 case R_PPC64_REL16_HI
:
5004 case R_PPC64_REL16_HA
:
5005 case R_PPC64_REL16_HIGH
:
5006 case R_PPC64_REL16_HIGHA
:
5007 case R_PPC64_REL16_HIGHER
:
5008 case R_PPC64_REL16_HIGHERA
:
5009 case R_PPC64_REL16_HIGHEST
:
5010 case R_PPC64_REL16_HIGHESTA
:
5011 case R_PPC64_REL16_HIGHER34
:
5012 case R_PPC64_REL16_HIGHERA34
:
5013 case R_PPC64_REL16_HIGHEST34
:
5014 case R_PPC64_REL16_HIGHESTA34
:
5015 case R_PPC64_REL16DX_HA
:
5018 /* Not supported as a dynamic relocation. */
5019 case R_PPC64_ADDR64_LOCAL
:
5020 if (bfd_link_pic (info
))
5022 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5024 /* xgettext:c-format */
5025 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
5026 "in shared libraries and PIEs\n"),
5027 abfd
, sec
, rel
->r_offset
,
5028 ppc64_elf_howto_table
[r_type
]->name
);
5029 bfd_set_error (bfd_error_bad_value
);
5035 case R_PPC64_TOC16_DS
:
5036 htab
->do_multi_toc
= 1;
5037 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5039 case R_PPC64_TOC16_LO
:
5040 case R_PPC64_TOC16_HI
:
5041 case R_PPC64_TOC16_HA
:
5042 case R_PPC64_TOC16_LO_DS
:
5043 sec
->has_toc_reloc
= 1;
5044 if (h
!= NULL
&& bfd_link_executable (info
))
5046 /* We may need a copy reloc. */
5048 /* Strongly prefer a copy reloc over a dynamic reloc.
5049 glibc ld.so as of 2019-08 will error out if one of
5050 these relocations is emitted. */
5060 /* This relocation describes the C++ object vtable hierarchy.
5061 Reconstruct it for later use during GC. */
5062 case R_PPC64_GNU_VTINHERIT
:
5063 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5067 /* This relocation describes which C++ vtable entries are actually
5068 used. Record for later use during GC. */
5069 case R_PPC64_GNU_VTENTRY
:
5070 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5075 case R_PPC64_REL14_BRTAKEN
:
5076 case R_PPC64_REL14_BRNTAKEN
:
5078 asection
*dest
= NULL
;
5080 /* Heuristic: If jumping outside our section, chances are
5081 we are going to need a stub. */
5084 /* If the sym is weak it may be overridden later, so
5085 don't assume we know where a weak sym lives. */
5086 if (h
->root
.type
== bfd_link_hash_defined
)
5087 dest
= h
->root
.u
.def
.section
;
5091 Elf_Internal_Sym
*isym
;
5093 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
5098 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5102 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5106 case R_PPC64_PLTCALL
:
5107 case R_PPC64_PLTCALL_NOTOC
:
5108 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
5112 case R_PPC64_REL24_NOTOC
:
5113 case R_PPC64_REL24_P9NOTOC
:
5119 if (h
->root
.root
.string
[0] == '.'
5120 && h
->root
.root
.string
[1] != '\0')
5121 ppc_elf_hash_entry (h
)->is_func
= 1;
5123 if (h
== tga
|| h
== dottga
)
5125 sec
->has_tls_reloc
= 1;
5127 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5128 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5129 /* We have a new-style __tls_get_addr call with
5133 /* Mark this section as having an old-style call. */
5134 sec
->nomark_tls_get_addr
= 1;
5136 plt_list
= &h
->plt
.plist
;
5139 /* We may need a .plt entry if the function this reloc
5140 refers to is in a shared lib. */
5142 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5146 case R_PPC64_ADDR14
:
5147 case R_PPC64_ADDR14_BRNTAKEN
:
5148 case R_PPC64_ADDR14_BRTAKEN
:
5149 case R_PPC64_ADDR24
:
5152 case R_PPC64_TPREL64
:
5153 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5154 if (bfd_link_dll (info
))
5155 info
->flags
|= DF_STATIC_TLS
;
5158 case R_PPC64_DTPMOD64
:
5159 if (rel
+ 1 < rel_end
5160 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5161 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5162 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5164 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5167 case R_PPC64_DTPREL64
:
5168 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5170 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5171 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5172 /* This is the second reloc of a dtpmod, dtprel pair.
5173 Don't mark with TLS_DTPREL. */
5177 sec
->has_tls_reloc
= 1;
5179 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
& 0xff;
5181 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5182 rel
->r_addend
, tls_type
))
5185 ppc64_sec
= ppc64_elf_section_data (sec
);
5186 if (ppc64_sec
->sec_type
!= sec_toc
)
5190 /* One extra to simplify get_tls_mask. */
5191 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5192 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5193 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5195 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5196 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5197 if (ppc64_sec
->u
.toc
.add
== NULL
)
5199 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5200 ppc64_sec
->sec_type
= sec_toc
;
5202 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5203 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5204 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5206 /* Mark the second slot of a GD or LD entry.
5207 -1 to indicate GD and -2 to indicate LD. */
5208 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5209 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5210 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5211 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5214 case R_PPC64_TPREL16_HI
:
5215 case R_PPC64_TPREL16_HA
:
5216 case R_PPC64_TPREL16_HIGH
:
5217 case R_PPC64_TPREL16_HIGHA
:
5218 case R_PPC64_TPREL16_HIGHER
:
5219 case R_PPC64_TPREL16_HIGHERA
:
5220 case R_PPC64_TPREL16_HIGHEST
:
5221 case R_PPC64_TPREL16_HIGHESTA
:
5222 sec
->has_tls_reloc
= 1;
5224 case R_PPC64_TPREL34
:
5225 case R_PPC64_TPREL16
:
5226 case R_PPC64_TPREL16_DS
:
5227 case R_PPC64_TPREL16_LO
:
5228 case R_PPC64_TPREL16_LO_DS
:
5229 if (bfd_link_dll (info
))
5230 info
->flags
|= DF_STATIC_TLS
;
5233 case R_PPC64_ADDR64
:
5235 && rel
+ 1 < rel_end
5236 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5239 ppc_elf_hash_entry (h
)->is_func
= 1;
5243 case R_PPC64_ADDR16
:
5244 case R_PPC64_ADDR16_DS
:
5245 case R_PPC64_ADDR16_HA
:
5246 case R_PPC64_ADDR16_HI
:
5247 case R_PPC64_ADDR16_HIGH
:
5248 case R_PPC64_ADDR16_HIGHA
:
5249 case R_PPC64_ADDR16_HIGHER
:
5250 case R_PPC64_ADDR16_HIGHERA
:
5251 case R_PPC64_ADDR16_HIGHEST
:
5252 case R_PPC64_ADDR16_HIGHESTA
:
5253 case R_PPC64_ADDR16_LO
:
5254 case R_PPC64_ADDR16_LO_DS
:
5256 case R_PPC64_D34_LO
:
5257 case R_PPC64_D34_HI30
:
5258 case R_PPC64_D34_HA30
:
5259 case R_PPC64_ADDR16_HIGHER34
:
5260 case R_PPC64_ADDR16_HIGHERA34
:
5261 case R_PPC64_ADDR16_HIGHEST34
:
5262 case R_PPC64_ADDR16_HIGHESTA34
:
5264 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5265 && rel
->r_addend
== 0)
5267 /* We may need a .plt entry if this reloc refers to a
5268 function in a shared lib. */
5269 if (!update_plt_info (abfd
, &h
->plt
.plist
, 0))
5271 h
->pointer_equality_needed
= 1;
5278 case R_PPC64_ADDR32
:
5279 case R_PPC64_UADDR16
:
5280 case R_PPC64_UADDR32
:
5281 case R_PPC64_UADDR64
:
5283 if (h
!= NULL
&& bfd_link_executable (info
))
5284 /* We may need a copy reloc. */
5287 /* Don't propagate .opd relocs. */
5288 if (NO_OPD_RELOCS
&& is_opd
)
5291 /* If we are creating a shared library, and this is a reloc
5292 against a global symbol, or a non PC relative reloc
5293 against a local symbol, then we need to copy the reloc
5294 into the shared library. However, if we are linking with
5295 -Bsymbolic, we do not need to copy a reloc against a
5296 global symbol which is defined in an object we are
5297 including in the link (i.e., DEF_REGULAR is set). At
5298 this point we have not seen all the input files, so it is
5299 possible that DEF_REGULAR is not set now but will be set
5300 later (it is never cleared). In case of a weak definition,
5301 DEF_REGULAR may be cleared later by a strong definition in
5302 a shared library. We account for that possibility below by
5303 storing information in the dyn_relocs field of the hash
5304 table entry. A similar situation occurs when creating
5305 shared libraries and symbol visibility changes render the
5308 If on the other hand, we are creating an executable, we
5309 may need to keep relocations for symbols satisfied by a
5310 dynamic library if we manage to avoid copy relocs for the
5314 && (h
->root
.type
== bfd_link_hash_defweak
5315 || !h
->def_regular
))
5317 && !bfd_link_executable (info
)
5318 && !SYMBOLIC_BIND (info
, h
))
5319 || (bfd_link_pic (info
)
5320 && must_be_dyn_reloc (info
, r_type
))
5321 || (!bfd_link_pic (info
)
5324 /* We must copy these reloc types into the output file.
5325 Create a reloc section in dynobj and make room for
5329 sreloc
= _bfd_elf_make_dynamic_reloc_section
5330 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ true);
5336 /* If this is a global symbol, we count the number of
5337 relocations we need for this symbol. */
5340 struct elf_dyn_relocs
*p
;
5341 struct elf_dyn_relocs
**head
;
5343 head
= &h
->dyn_relocs
;
5345 if (p
== NULL
|| p
->sec
!= sec
)
5347 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5357 if (!must_be_dyn_reloc (info
, r_type
))
5362 /* Track dynamic relocs needed for local syms too.
5363 We really need local syms available to do this
5365 struct ppc_dyn_relocs
*p
;
5366 struct ppc_dyn_relocs
**head
;
5370 Elf_Internal_Sym
*isym
;
5372 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
5377 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5381 vpp
= &elf_section_data (s
)->local_dynrel
;
5382 head
= (struct ppc_dyn_relocs
**) vpp
;
5383 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5385 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5387 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5389 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5395 p
->ifunc
= is_ifunc
;
5411 /* Merge backend specific data from an object file to the output
5412 object file when linking. */
5415 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5417 bfd
*obfd
= info
->output_bfd
;
5418 unsigned long iflags
, oflags
;
5420 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5423 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5426 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
5429 iflags
= elf_elfheader (ibfd
)->e_flags
;
5430 oflags
= elf_elfheader (obfd
)->e_flags
;
5432 if (iflags
& ~EF_PPC64_ABI
)
5435 /* xgettext:c-format */
5436 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5437 bfd_set_error (bfd_error_bad_value
);
5440 else if (iflags
!= oflags
&& iflags
!= 0)
5443 /* xgettext:c-format */
5444 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
5445 ibfd
, iflags
, oflags
);
5446 bfd_set_error (bfd_error_bad_value
);
5450 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
5453 /* Merge Tag_compatibility attributes and any common GNU ones. */
5454 return _bfd_elf_merge_object_attributes (ibfd
, info
);
5458 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5460 /* Print normal ELF private data. */
5461 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5463 if (elf_elfheader (abfd
)->e_flags
!= 0)
5467 fprintf (file
, _("private flags = 0x%lx:"),
5468 elf_elfheader (abfd
)->e_flags
);
5470 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5471 fprintf (file
, _(" [abiv%ld]"),
5472 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5479 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5480 of the code entry point, and its section, which must be in the same
5481 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5484 opd_entry_value (asection
*opd_sec
,
5486 asection
**code_sec
,
5490 bfd
*opd_bfd
= opd_sec
->owner
;
5491 Elf_Internal_Rela
*relocs
;
5492 Elf_Internal_Rela
*lo
, *hi
, *look
;
5495 /* No relocs implies we are linking a --just-symbols object, or looking
5496 at a final linked executable with addr2line or somesuch. */
5497 if (opd_sec
->reloc_count
== 0)
5499 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
5501 if (contents
== NULL
)
5503 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5504 return (bfd_vma
) -1;
5505 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5508 /* PR 17512: file: 64b9dfbb. */
5509 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5510 return (bfd_vma
) -1;
5512 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5513 if (code_sec
!= NULL
)
5515 asection
*sec
, *likely
= NULL
;
5521 && val
< sec
->vma
+ sec
->size
)
5527 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5529 && (sec
->flags
& SEC_LOAD
) != 0
5530 && (sec
->flags
& SEC_ALLOC
) != 0)
5535 if (code_off
!= NULL
)
5536 *code_off
= val
- likely
->vma
;
5542 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5544 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5546 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, true);
5547 /* PR 17512: file: df8e1fd6. */
5549 return (bfd_vma
) -1;
5551 /* Go find the opd reloc at the sym address. */
5553 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5557 look
= lo
+ (hi
- lo
) / 2;
5558 if (look
->r_offset
< offset
)
5560 else if (look
->r_offset
> offset
)
5564 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5566 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5567 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5569 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5570 asection
*sec
= NULL
;
5572 if (symndx
>= symtab_hdr
->sh_info
5573 && elf_sym_hashes (opd_bfd
) != NULL
)
5575 struct elf_link_hash_entry
**sym_hashes
;
5576 struct elf_link_hash_entry
*rh
;
5578 sym_hashes
= elf_sym_hashes (opd_bfd
);
5579 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5582 rh
= elf_follow_link (rh
);
5583 if (rh
->root
.type
!= bfd_link_hash_defined
5584 && rh
->root
.type
!= bfd_link_hash_defweak
)
5586 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5588 val
= rh
->root
.u
.def
.value
;
5589 sec
= rh
->root
.u
.def
.section
;
5596 Elf_Internal_Sym
*sym
;
5598 if (symndx
< symtab_hdr
->sh_info
)
5600 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5603 size_t symcnt
= symtab_hdr
->sh_info
;
5604 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5609 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5615 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5621 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5624 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5625 val
= sym
->st_value
;
5628 val
+= look
->r_addend
;
5629 if (code_off
!= NULL
)
5631 if (code_sec
!= NULL
)
5633 if (in_code_sec
&& *code_sec
!= sec
)
5638 if (sec
->output_section
!= NULL
)
5639 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5648 /* If the ELF symbol SYM might be a function in SEC, return the
5649 function size and set *CODE_OFF to the function's entry point,
5650 otherwise return zero. */
5652 static bfd_size_type
5653 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5657 elf_symbol_type
* elf_sym
= (elf_symbol_type
*) sym
;
5659 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5660 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5663 size
= (sym
->flags
& BSF_SYNTHETIC
) ? 0 : elf_sym
->internal_elf_sym
.st_size
;
5665 /* In theory we should check that the symbol's type satisfies
5666 _bfd_elf_is_function_type(), but there are some function-like
5667 symbols which would fail this test. (eg _start). Instead
5668 we check for hidden, local, notype symbols with zero size.
5669 This type of symbol is generated by the annobin plugin for gcc
5670 and clang, and should not be considered to be a function symbol. */
5672 && ((sym
->flags
& (BSF_SYNTHETIC
| BSF_LOCAL
)) == BSF_LOCAL
)
5673 && ELF_ST_TYPE (elf_sym
->internal_elf_sym
.st_info
) == STT_NOTYPE
5674 && ELF_ST_VISIBILITY (elf_sym
->internal_elf_sym
.st_other
) == STV_HIDDEN
)
5677 if (strcmp (sym
->section
->name
, ".opd") == 0)
5679 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5680 bfd_vma symval
= sym
->value
;
5683 && opd
->adjust
!= NULL
5684 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5686 /* opd_entry_value will use cached relocs that have been
5687 adjusted, but with raw symbols. That means both local
5688 and global symbols need adjusting. */
5689 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5695 if (opd_entry_value (sym
->section
, symval
,
5696 &sec
, code_off
, true) == (bfd_vma
) -1)
5698 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5699 symbol. This size has nothing to do with the code size of the
5700 function, which is what we're supposed to return, but the
5701 code size isn't available without looking up the dot-sym.
5702 However, doing that would be a waste of time particularly
5703 since elf_find_function will look at the dot-sym anyway.
5704 Now, elf_find_function will keep the largest size of any
5705 function sym found at the code address of interest, so return
5706 1 here to avoid it incorrectly caching a larger function size
5707 for a small function. This does mean we return the wrong
5708 size for a new-ABI function of size 24, but all that does is
5709 disable caching for such functions. */
5715 if (sym
->section
!= sec
)
5717 *code_off
= sym
->value
;
5720 /* Do not return 0 for the function's size. */
5721 return size
? size
: 1;
5724 /* Return true if symbol is a strong function defined in an ELFv2
5725 object with st_other localentry bits of zero, ie. its local entry
5726 point coincides with its global entry point. */
5729 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5732 && h
->type
== STT_FUNC
5733 && h
->root
.type
== bfd_link_hash_defined
5734 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5735 && !ppc_elf_hash_entry (h
)->non_zero_localentry
5736 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5737 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5740 /* Return true if symbol is defined in a regular object file. */
5743 is_static_defined (struct elf_link_hash_entry
*h
)
5745 return ((h
->root
.type
== bfd_link_hash_defined
5746 || h
->root
.type
== bfd_link_hash_defweak
)
5747 && h
->root
.u
.def
.section
!= NULL
5748 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5751 /* If FDH is a function descriptor symbol, return the associated code
5752 entry symbol if it is defined. Return NULL otherwise. */
5754 static struct ppc_link_hash_entry
*
5755 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5757 if (fdh
->is_func_descriptor
)
5759 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5760 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5761 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5767 /* If FH is a function code entry symbol, return the associated
5768 function descriptor symbol if it is defined. Return NULL otherwise. */
5770 static struct ppc_link_hash_entry
*
5771 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5774 && fh
->oh
->is_func_descriptor
)
5776 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5777 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5778 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5784 /* Given H is a symbol that satisfies is_static_defined, return the
5785 value in the output file. */
5788 defined_sym_val (struct elf_link_hash_entry
*h
)
5790 return (h
->root
.u
.def
.section
->output_section
->vma
5791 + h
->root
.u
.def
.section
->output_offset
5792 + h
->root
.u
.def
.value
);
5795 /* Return true if H matches __tls_get_addr or one of its variants. */
5798 is_tls_get_addr (struct elf_link_hash_entry
*h
,
5799 struct ppc_link_hash_table
*htab
)
5801 return (h
== elf_hash_entry (htab
->tls_get_addr_fd
)
5802 || h
== elf_hash_entry (htab
->tga_desc_fd
)
5803 || h
== elf_hash_entry (htab
->tls_get_addr
)
5804 || h
== elf_hash_entry (htab
->tga_desc
));
5807 static bool func_desc_adjust (struct elf_link_hash_entry
*, void *);
5809 /* Garbage collect sections, after first dealing with dot-symbols. */
5812 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5814 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5816 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5818 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5819 htab
->need_func_desc_adj
= 0;
5821 return bfd_elf_gc_sections (abfd
, info
);
5824 /* Mark all our entry sym sections, both opd and code section. */
5827 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5829 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5830 struct bfd_sym_chain
*sym
;
5835 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5837 struct ppc_link_hash_entry
*eh
, *fh
;
5840 eh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
->name
,
5841 false, false, true));
5844 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5845 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5848 fh
= defined_code_entry (eh
);
5851 sec
= fh
->elf
.root
.u
.def
.section
;
5852 sec
->flags
|= SEC_KEEP
;
5854 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5855 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5856 eh
->elf
.root
.u
.def
.value
,
5857 &sec
, NULL
, false) != (bfd_vma
) -1)
5858 sec
->flags
|= SEC_KEEP
;
5860 sec
= eh
->elf
.root
.u
.def
.section
;
5861 sec
->flags
|= SEC_KEEP
;
5865 /* Mark sections containing dynamically referenced symbols. When
5866 building shared libraries, we must assume that any visible symbol is
5870 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5872 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5873 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
5874 struct ppc_link_hash_entry
*fdh
;
5875 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5877 /* Dynamic linking info is on the func descriptor sym. */
5878 fdh
= defined_func_desc (eh
);
5882 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5883 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5884 && (!eh
->elf
.start_stop
5885 || eh
->elf
.root
.ldscript_def
5886 || !info
->start_stop_gc
)
5887 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5888 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5889 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5890 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5891 && (!bfd_link_executable (info
)
5892 || info
->gc_keep_exported
5893 || info
->export_dynamic
5896 && (*d
->match
) (&d
->head
, NULL
,
5897 eh
->elf
.root
.root
.string
)))
5898 && (eh
->elf
.versioned
>= versioned
5899 || !bfd_hide_sym_by_version (info
->version_info
,
5900 eh
->elf
.root
.root
.string
)))))
5903 struct ppc_link_hash_entry
*fh
;
5905 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5907 /* Function descriptor syms cause the associated
5908 function code sym section to be marked. */
5909 fh
= defined_code_entry (eh
);
5912 code_sec
= fh
->elf
.root
.u
.def
.section
;
5913 code_sec
->flags
|= SEC_KEEP
;
5915 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5916 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5917 eh
->elf
.root
.u
.def
.value
,
5918 &code_sec
, NULL
, false) != (bfd_vma
) -1)
5919 code_sec
->flags
|= SEC_KEEP
;
5925 /* Return the section that should be marked against GC for a given
5929 ppc64_elf_gc_mark_hook (asection
*sec
,
5930 struct bfd_link_info
*info
,
5931 Elf_Internal_Rela
*rel
,
5932 struct elf_link_hash_entry
*h
,
5933 Elf_Internal_Sym
*sym
)
5937 /* Syms return NULL if we're marking .opd, so we avoid marking all
5938 function sections, as all functions are referenced in .opd. */
5940 if (get_opd_info (sec
) != NULL
)
5945 enum elf_ppc64_reloc_type r_type
;
5946 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5948 r_type
= ELF64_R_TYPE (rel
->r_info
);
5951 case R_PPC64_GNU_VTINHERIT
:
5952 case R_PPC64_GNU_VTENTRY
:
5956 switch (h
->root
.type
)
5958 case bfd_link_hash_defined
:
5959 case bfd_link_hash_defweak
:
5960 eh
= ppc_elf_hash_entry (h
);
5961 fdh
= defined_func_desc (eh
);
5964 /* -mcall-aixdesc code references the dot-symbol on
5965 a call reloc. Mark the function descriptor too
5966 against garbage collection. */
5968 if (fdh
->elf
.is_weakalias
)
5969 weakdef (&fdh
->elf
)->mark
= 1;
5973 /* Function descriptor syms cause the associated
5974 function code sym section to be marked. */
5975 fh
= defined_code_entry (eh
);
5978 /* They also mark their opd section. */
5979 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5981 rsec
= fh
->elf
.root
.u
.def
.section
;
5983 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5984 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5985 eh
->elf
.root
.u
.def
.value
,
5986 &rsec
, NULL
, false) != (bfd_vma
) -1)
5987 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5989 rsec
= h
->root
.u
.def
.section
;
5992 case bfd_link_hash_common
:
5993 rsec
= h
->root
.u
.c
.p
->section
;
5997 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6003 struct _opd_sec_data
*opd
;
6005 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6006 opd
= get_opd_info (rsec
);
6007 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6011 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6018 /* The maximum size of .sfpr. */
6019 #define SFPR_MAX (218*4)
6021 struct sfpr_def_parms
6023 const char name
[12];
6024 unsigned char lo
, hi
;
6025 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
6026 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
6029 /* Auto-generate _save*, _rest* functions in .sfpr.
6030 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6034 sfpr_define (struct bfd_link_info
*info
,
6035 const struct sfpr_def_parms
*parm
,
6038 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6040 size_t len
= strlen (parm
->name
);
6041 bool writing
= false;
6047 memcpy (sym
, parm
->name
, len
);
6050 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6052 struct ppc_link_hash_entry
*h
;
6054 sym
[len
+ 0] = i
/ 10 + '0';
6055 sym
[len
+ 1] = i
% 10 + '0';
6056 h
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
,
6057 writing
, true, true));
6058 if (stub_sec
!= NULL
)
6061 && h
->elf
.root
.type
== bfd_link_hash_defined
6062 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6064 struct elf_link_hash_entry
*s
;
6066 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6067 s
= elf_link_hash_lookup (&htab
->elf
, buf
, true, true, false);
6070 if (s
->root
.type
== bfd_link_hash_new
)
6072 s
->root
.type
= bfd_link_hash_defined
;
6073 s
->root
.u
.def
.section
= stub_sec
;
6074 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6075 + h
->elf
.root
.u
.def
.value
);
6078 s
->ref_regular_nonweak
= 1;
6079 s
->forced_local
= 1;
6081 s
->root
.linker_def
= 1;
6089 if (!h
->elf
.def_regular
)
6091 h
->elf
.root
.type
= bfd_link_hash_defined
;
6092 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6093 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6094 h
->elf
.type
= STT_FUNC
;
6095 h
->elf
.def_regular
= 1;
6097 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, true);
6099 if (htab
->sfpr
->contents
== NULL
)
6101 htab
->sfpr
->contents
6102 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6103 if (htab
->sfpr
->contents
== NULL
)
6110 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6112 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6114 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6115 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6123 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6125 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6130 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6132 p
= savegpr0 (abfd
, p
, r
);
6133 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6135 bfd_put_32 (abfd
, BLR
, p
);
6140 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6142 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6147 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6149 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6151 p
= restgpr0 (abfd
, p
, r
);
6152 bfd_put_32 (abfd
, MTLR_R0
, p
);
6156 p
= restgpr0 (abfd
, p
, 30);
6157 p
= restgpr0 (abfd
, p
, 31);
6159 bfd_put_32 (abfd
, BLR
, p
);
6164 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6166 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6171 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6173 p
= savegpr1 (abfd
, p
, r
);
6174 bfd_put_32 (abfd
, BLR
, p
);
6179 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6181 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6186 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6188 p
= restgpr1 (abfd
, p
, r
);
6189 bfd_put_32 (abfd
, BLR
, p
);
6194 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6196 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6201 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6203 p
= savefpr (abfd
, p
, r
);
6204 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6206 bfd_put_32 (abfd
, BLR
, p
);
6211 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6213 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6218 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6220 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6222 p
= restfpr (abfd
, p
, r
);
6223 bfd_put_32 (abfd
, MTLR_R0
, p
);
6227 p
= restfpr (abfd
, p
, 30);
6228 p
= restfpr (abfd
, p
, 31);
6230 bfd_put_32 (abfd
, BLR
, p
);
6235 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6237 p
= savefpr (abfd
, p
, r
);
6238 bfd_put_32 (abfd
, BLR
, p
);
6243 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6245 p
= restfpr (abfd
, p
, r
);
6246 bfd_put_32 (abfd
, BLR
, p
);
6251 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6253 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6255 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6260 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6262 p
= savevr (abfd
, p
, r
);
6263 bfd_put_32 (abfd
, BLR
, p
);
6268 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6270 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6272 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6277 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6279 p
= restvr (abfd
, p
, r
);
6280 bfd_put_32 (abfd
, BLR
, p
);
6284 #define STDU_R1_0R1 0xf8210001
6285 #define ADDI_R1_R1 0x38210000
6287 /* Emit prologue of wrapper preserving regs around a call to
6288 __tls_get_addr_opt. */
6291 tls_get_addr_prologue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6295 bfd_put_32 (obfd
, MFLR_R0
, p
);
6297 bfd_put_32 (obfd
, STD_R0_0R1
+ 16, p
);
6302 for (i
= 4; i
< 12; i
++)
6305 STD_R0_0R1
| i
<< 21 | (-(13 - i
) * 8 & 0xffff), p
);
6308 bfd_put_32 (obfd
, STDU_R1_0R1
| (-128 & 0xffff), p
);
6313 for (i
= 4; i
< 12; i
++)
6316 STD_R0_0R1
| i
<< 21 | (-(12 - i
) * 8 & 0xffff), p
);
6319 bfd_put_32 (obfd
, STDU_R1_0R1
| (-96 & 0xffff), p
);
6325 /* Emit epilogue of wrapper preserving regs around a call to
6326 __tls_get_addr_opt. */
6329 tls_get_addr_epilogue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6335 for (i
= 4; i
< 12; i
++)
6337 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (128 - (13 - i
) * 8), p
);
6340 bfd_put_32 (obfd
, ADDI_R1_R1
| 128, p
);
6345 for (i
= 4; i
< 12; i
++)
6347 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (96 - (12 - i
) * 8), p
);
6350 bfd_put_32 (obfd
, ADDI_R1_R1
| 96, p
);
6353 bfd_put_32 (obfd
, LD_R0_0R1
| 16, p
);
6355 bfd_put_32 (obfd
, MTLR_R0
, p
);
6357 bfd_put_32 (obfd
, BLR
, p
);
6362 /* Called via elf_link_hash_traverse to transfer dynamic linking
6363 information on function code symbol entries to their corresponding
6364 function descriptor symbol entries. Must not be called twice for
6365 any given code symbol. */
6368 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6370 struct bfd_link_info
*info
;
6371 struct ppc_link_hash_table
*htab
;
6372 struct ppc_link_hash_entry
*fh
;
6373 struct ppc_link_hash_entry
*fdh
;
6376 fh
= ppc_elf_hash_entry (h
);
6377 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6383 if (fh
->elf
.root
.root
.string
[0] != '.'
6384 || fh
->elf
.root
.root
.string
[1] == '\0')
6388 htab
= ppc_hash_table (info
);
6392 /* Find the corresponding function descriptor symbol. */
6393 fdh
= lookup_fdh (fh
, htab
);
6395 /* Resolve undefined references to dot-symbols as the value
6396 in the function descriptor, if we have one in a regular object.
6397 This is to satisfy cases like ".quad .foo". Calls to functions
6398 in dynamic objects are handled elsewhere. */
6399 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6400 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6401 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6402 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6403 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6404 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6405 fdh
->elf
.root
.u
.def
.value
,
6406 &fh
->elf
.root
.u
.def
.section
,
6407 &fh
->elf
.root
.u
.def
.value
, false) != (bfd_vma
) -1)
6409 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6410 fh
->elf
.forced_local
= 1;
6411 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6412 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6415 if (!fh
->elf
.dynamic
)
6417 struct plt_entry
*ent
;
6419 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6420 if (ent
->plt
.refcount
> 0)
6424 if (fdh
!= NULL
&& fdh
->fake
)
6425 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6430 /* Create a descriptor as undefined if necessary. */
6432 && !bfd_link_executable (info
)
6433 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6434 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6436 fdh
= make_fdh (info
, fh
);
6441 /* We can't support overriding of symbols on a fake descriptor. */
6444 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6445 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6446 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6448 /* Transfer dynamic linking information to the function descriptor. */
6451 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6452 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6453 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6454 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6455 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6456 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6457 || fh
->elf
.type
== STT_FUNC
6458 || fh
->elf
.type
== STT_GNU_IFUNC
);
6459 move_plt_plist (fh
, fdh
);
6461 if (!fdh
->elf
.forced_local
6462 && fh
->elf
.dynindx
!= -1)
6463 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6467 /* Now that the info is on the function descriptor, clear the
6468 function code sym info. Any function code syms for which we
6469 don't have a definition in a regular file, we force local.
6470 This prevents a shared library from exporting syms that have
6471 been imported from another library. Function code syms that
6472 are really in the library we must leave global to prevent the
6473 linker dragging in a definition from a static library. */
6474 force_local
= (!fh
->elf
.def_regular
6476 || !fdh
->elf
.def_regular
6477 || fdh
->elf
.forced_local
);
6478 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6483 static const struct sfpr_def_parms save_res_funcs
[] =
6485 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6486 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6487 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6488 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6489 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6490 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6491 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6492 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6493 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6494 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6495 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6496 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6499 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6500 this hook to a) run the edit functions in this file, b) provide
6501 some gcc support functions, and c) transfer dynamic linking
6502 information gathered so far on function code symbol entries, to
6503 their corresponding function descriptor symbol entries. */
6506 ppc64_elf_edit (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6508 struct ppc_link_hash_table
*htab
;
6510 htab
= ppc_hash_table (info
);
6514 /* Call back into the linker, which then runs the edit functions. */
6515 htab
->params
->edit ();
6517 /* Provide any missing _save* and _rest* functions. */
6518 if (htab
->sfpr
!= NULL
)
6522 htab
->sfpr
->size
= 0;
6523 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
6524 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
6526 if (htab
->sfpr
->size
== 0)
6527 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6530 if (bfd_link_relocatable (info
))
6533 if (htab
->elf
.hgot
!= NULL
)
6535 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, true);
6536 /* Make .TOC. defined so as to prevent it being made dynamic.
6537 The wrong value here is fixed later in ppc64_elf_set_toc. */
6538 if (!htab
->elf
.hgot
->def_regular
6539 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
6541 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
6542 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
6543 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6544 htab
->elf
.hgot
->def_regular
= 1;
6545 htab
->elf
.hgot
->root
.linker_def
= 1;
6547 htab
->elf
.hgot
->type
= STT_OBJECT
;
6548 htab
->elf
.hgot
->other
6549 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
6555 /* Return true if we have dynamic relocs against H or any of its weak
6556 aliases, that apply to read-only sections. Cannot be used after
6557 size_dynamic_sections. */
6560 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6562 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
6565 if (_bfd_elf_readonly_dynrelocs (&eh
->elf
))
6567 eh
= ppc_elf_hash_entry (eh
->elf
.u
.alias
);
6569 while (eh
!= NULL
&& &eh
->elf
!= h
);
6574 /* Return whether EH has pc-relative dynamic relocs. */
6577 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
6579 struct elf_dyn_relocs
*p
;
6581 for (p
= eh
->elf
.dyn_relocs
; p
!= NULL
; p
= p
->next
)
6582 if (p
->pc_count
!= 0)
6587 /* Return true if a global entry stub will be created for H. Valid
6588 for ELFv2 before plt entries have been allocated. */
6591 global_entry_stub (struct elf_link_hash_entry
*h
)
6593 struct plt_entry
*pent
;
6595 if (!h
->pointer_equality_needed
6599 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
6600 if (pent
->plt
.refcount
> 0
6601 && pent
->addend
== 0)
6607 /* Adjust a symbol defined by a dynamic object and referenced by a
6608 regular object. The current definition is in some section of the
6609 dynamic object, but we're not including those sections. We have to
6610 change the definition to something the rest of the link can
6614 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6615 struct elf_link_hash_entry
*h
)
6617 struct ppc_link_hash_table
*htab
;
6620 htab
= ppc_hash_table (info
);
6624 /* Deal with function syms. */
6625 if (h
->type
== STT_FUNC
6626 || h
->type
== STT_GNU_IFUNC
6629 bool local
= (ppc_elf_hash_entry (h
)->save_res
6630 || SYMBOL_CALLS_LOCAL (info
, h
)
6631 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6632 /* Discard dyn_relocs when non-pic if we've decided that a
6633 function symbol is local and not an ifunc. We keep dynamic
6634 relocs for ifuncs when local rather than always emitting a
6635 plt call stub for them and defining the symbol on the call
6636 stub. We can't do that for ELFv1 anyway (a function symbol
6637 is defined on a descriptor, not code) and it can be faster at
6638 run-time due to not needing to bounce through a stub. The
6639 dyn_relocs for ifuncs will be applied even in a static
6641 if (!bfd_link_pic (info
)
6642 && h
->type
!= STT_GNU_IFUNC
6644 h
->dyn_relocs
= NULL
;
6646 /* Clear procedure linkage table information for any symbol that
6647 won't need a .plt entry. */
6648 struct plt_entry
*ent
;
6649 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6650 if (ent
->plt
.refcount
> 0)
6653 || (h
->type
!= STT_GNU_IFUNC
6655 && (htab
->can_convert_all_inline_plt
6656 || (ppc_elf_hash_entry (h
)->tls_mask
6657 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6659 h
->plt
.plist
= NULL
;
6661 h
->pointer_equality_needed
= 0;
6663 else if (abiversion (info
->output_bfd
) >= 2)
6665 /* Taking a function's address in a read/write section
6666 doesn't require us to define the function symbol in the
6667 executable on a global entry stub. A dynamic reloc can
6668 be used instead. The reason we prefer a few more dynamic
6669 relocs is that calling via a global entry stub costs a
6670 few more instructions, and pointer_equality_needed causes
6671 extra work in ld.so when resolving these symbols. */
6672 if (global_entry_stub (h
))
6674 if (!_bfd_elf_readonly_dynrelocs (h
))
6676 h
->pointer_equality_needed
= 0;
6677 /* If we haven't seen a branch reloc and the symbol
6678 isn't an ifunc then we don't need a plt entry. */
6680 h
->plt
.plist
= NULL
;
6682 else if (!bfd_link_pic (info
))
6683 /* We are going to be defining the function symbol on the
6684 plt stub, so no dyn_relocs needed when non-pic. */
6685 h
->dyn_relocs
= NULL
;
6688 /* ELFv2 function symbols can't have copy relocs. */
6691 else if (!h
->needs_plt
6692 && !_bfd_elf_readonly_dynrelocs (h
))
6694 /* If we haven't seen a branch reloc and the symbol isn't an
6695 ifunc then we don't need a plt entry. */
6696 h
->plt
.plist
= NULL
;
6697 h
->pointer_equality_needed
= 0;
6702 h
->plt
.plist
= NULL
;
6704 /* If this is a weak symbol, and there is a real definition, the
6705 processor independent code will have arranged for us to see the
6706 real definition first, and we can just use the same value. */
6707 if (h
->is_weakalias
)
6709 struct elf_link_hash_entry
*def
= weakdef (h
);
6710 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6711 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6712 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6713 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6714 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6715 h
->dyn_relocs
= NULL
;
6719 /* If we are creating a shared library, we must presume that the
6720 only references to the symbol are via the global offset table.
6721 For such cases we need not do anything here; the relocations will
6722 be handled correctly by relocate_section. */
6723 if (!bfd_link_executable (info
))
6726 /* If there are no references to this symbol that do not use the
6727 GOT, we don't need to generate a copy reloc. */
6728 if (!h
->non_got_ref
)
6731 /* Don't generate a copy reloc for symbols defined in the executable. */
6732 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6734 /* If -z nocopyreloc was given, don't generate them either. */
6735 || info
->nocopyreloc
6737 /* If we don't find any dynamic relocs in read-only sections, then
6738 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6739 || (ELIMINATE_COPY_RELOCS
6741 && !alias_readonly_dynrelocs (h
))
6743 /* Protected variables do not work with .dynbss. The copy in
6744 .dynbss won't be used by the shared library with the protected
6745 definition for the variable. Text relocations are preferable
6746 to an incorrect program. */
6747 || h
->protected_def
)
6750 if (h
->type
== STT_FUNC
6751 || h
->type
== STT_GNU_IFUNC
)
6753 /* .dynbss copies of function symbols only work if we have
6754 ELFv1 dot-symbols. ELFv1 compilers since 2004 default to not
6755 use dot-symbols and set the function symbol size to the text
6756 size of the function rather than the size of the descriptor.
6757 That's wrong for copying a descriptor. */
6758 if (ppc_elf_hash_entry (h
)->oh
== NULL
6759 || !(h
->size
== 24 || h
->size
== 16))
6762 /* We should never get here, but unfortunately there are old
6763 versions of gcc (circa gcc-3.2) that improperly for the
6764 ELFv1 ABI put initialized function pointers, vtable refs and
6765 suchlike in read-only sections. Allow them to proceed, but
6766 warn that this might break at runtime. */
6767 info
->callbacks
->einfo
6768 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6769 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6770 h
->root
.root
.string
);
6773 /* This is a reference to a symbol defined by a dynamic object which
6774 is not a function. */
6776 /* We must allocate the symbol in our .dynbss section, which will
6777 become part of the .bss section of the executable. There will be
6778 an entry for this symbol in the .dynsym section. The dynamic
6779 object will contain position independent code, so all references
6780 from the dynamic object to this symbol will go through the global
6781 offset table. The dynamic linker will use the .dynsym entry to
6782 determine the address it must put in the global offset table, so
6783 both the dynamic object and the regular object will refer to the
6784 same memory location for the variable. */
6785 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6787 s
= htab
->elf
.sdynrelro
;
6788 srel
= htab
->elf
.sreldynrelro
;
6792 s
= htab
->elf
.sdynbss
;
6793 srel
= htab
->elf
.srelbss
;
6795 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6797 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6798 linker to copy the initial value out of the dynamic object
6799 and into the runtime process image. */
6800 srel
->size
+= sizeof (Elf64_External_Rela
);
6804 /* We no longer want dyn_relocs. */
6805 h
->dyn_relocs
= NULL
;
6806 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6809 /* If given a function descriptor symbol, hide both the function code
6810 sym and the descriptor. */
6812 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6813 struct elf_link_hash_entry
*h
,
6816 struct ppc_link_hash_entry
*eh
;
6817 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6819 if (ppc_hash_table (info
) == NULL
)
6822 eh
= ppc_elf_hash_entry (h
);
6823 if (eh
->is_func_descriptor
)
6825 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6830 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6833 /* We aren't supposed to use alloca in BFD because on
6834 systems which do not have alloca the version in libiberty
6835 calls xmalloc, which might cause the program to crash
6836 when it runs out of memory. This function doesn't have a
6837 return status, so there's no way to gracefully return an
6838 error. So cheat. We know that string[-1] can be safely
6839 accessed; It's either a string in an ELF string table,
6840 or allocated in an objalloc structure. */
6842 p
= eh
->elf
.root
.root
.string
- 1;
6845 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6849 /* Unfortunately, if it so happens that the string we were
6850 looking for was allocated immediately before this string,
6851 then we overwrote the string terminator. That's the only
6852 reason the lookup should fail. */
6855 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6856 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6858 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6859 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6869 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6874 get_sym_h (struct elf_link_hash_entry
**hp
,
6875 Elf_Internal_Sym
**symp
,
6877 unsigned char **tls_maskp
,
6878 Elf_Internal_Sym
**locsymsp
,
6879 unsigned long r_symndx
,
6882 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6884 if (r_symndx
>= symtab_hdr
->sh_info
)
6886 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6887 struct elf_link_hash_entry
*h
;
6889 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6890 h
= elf_follow_link (h
);
6898 if (symsecp
!= NULL
)
6900 asection
*symsec
= NULL
;
6901 if (h
->root
.type
== bfd_link_hash_defined
6902 || h
->root
.type
== bfd_link_hash_defweak
)
6903 symsec
= h
->root
.u
.def
.section
;
6907 if (tls_maskp
!= NULL
)
6908 *tls_maskp
= &ppc_elf_hash_entry (h
)->tls_mask
;
6912 Elf_Internal_Sym
*sym
;
6913 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6915 if (locsyms
== NULL
)
6917 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6918 if (locsyms
== NULL
)
6919 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6920 symtab_hdr
->sh_info
,
6921 0, NULL
, NULL
, NULL
);
6922 if (locsyms
== NULL
)
6924 *locsymsp
= locsyms
;
6926 sym
= locsyms
+ r_symndx
;
6934 if (symsecp
!= NULL
)
6935 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6937 if (tls_maskp
!= NULL
)
6939 struct got_entry
**lgot_ents
;
6940 unsigned char *tls_mask
;
6943 lgot_ents
= elf_local_got_ents (ibfd
);
6944 if (lgot_ents
!= NULL
)
6946 struct plt_entry
**local_plt
= (struct plt_entry
**)
6947 (lgot_ents
+ symtab_hdr
->sh_info
);
6948 unsigned char *lgot_masks
= (unsigned char *)
6949 (local_plt
+ symtab_hdr
->sh_info
);
6950 tls_mask
= &lgot_masks
[r_symndx
];
6952 *tls_maskp
= tls_mask
;
6958 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6959 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6960 type suitable for optimization, and 1 otherwise. */
6963 get_tls_mask (unsigned char **tls_maskp
,
6964 unsigned long *toc_symndx
,
6965 bfd_vma
*toc_addend
,
6966 Elf_Internal_Sym
**locsymsp
,
6967 const Elf_Internal_Rela
*rel
,
6970 unsigned long r_symndx
;
6972 struct elf_link_hash_entry
*h
;
6973 Elf_Internal_Sym
*sym
;
6977 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6978 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6981 if ((*tls_maskp
!= NULL
6982 && (**tls_maskp
& TLS_TLS
) != 0
6983 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
6985 || ppc64_elf_section_data (sec
) == NULL
6986 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6989 /* Look inside a TOC section too. */
6992 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6993 off
= h
->root
.u
.def
.value
;
6996 off
= sym
->st_value
;
6997 off
+= rel
->r_addend
;
6998 BFD_ASSERT (off
% 8 == 0);
6999 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7000 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7001 if (toc_symndx
!= NULL
)
7002 *toc_symndx
= r_symndx
;
7003 if (toc_addend
!= NULL
)
7004 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7005 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7007 if ((h
== NULL
|| is_static_defined (h
))
7008 && (next_r
== -1 || next_r
== -2))
7013 /* Find (or create) an entry in the tocsave hash table. */
7015 static struct tocsave_entry
*
7016 tocsave_find (struct ppc_link_hash_table
*htab
,
7017 enum insert_option insert
,
7018 Elf_Internal_Sym
**local_syms
,
7019 const Elf_Internal_Rela
*irela
,
7022 unsigned long r_indx
;
7023 struct elf_link_hash_entry
*h
;
7024 Elf_Internal_Sym
*sym
;
7025 struct tocsave_entry ent
, *p
;
7027 struct tocsave_entry
**slot
;
7029 r_indx
= ELF64_R_SYM (irela
->r_info
);
7030 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7032 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7035 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7040 ent
.offset
= h
->root
.u
.def
.value
;
7042 ent
.offset
= sym
->st_value
;
7043 ent
.offset
+= irela
->r_addend
;
7045 hash
= tocsave_htab_hash (&ent
);
7046 slot
= ((struct tocsave_entry
**)
7047 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7053 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7062 /* Adjust all global syms defined in opd sections. In gcc generated
7063 code for the old ABI, these will already have been done. */
7066 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7068 struct ppc_link_hash_entry
*eh
;
7070 struct _opd_sec_data
*opd
;
7072 if (h
->root
.type
== bfd_link_hash_indirect
)
7075 if (h
->root
.type
!= bfd_link_hash_defined
7076 && h
->root
.type
!= bfd_link_hash_defweak
)
7079 eh
= ppc_elf_hash_entry (h
);
7080 if (eh
->adjust_done
)
7083 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7084 opd
= get_opd_info (sym_sec
);
7085 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7087 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7090 /* This entry has been deleted. */
7091 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7094 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7095 if (discarded_section (dsec
))
7097 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7101 eh
->elf
.root
.u
.def
.value
= 0;
7102 eh
->elf
.root
.u
.def
.section
= dsec
;
7105 eh
->elf
.root
.u
.def
.value
+= adjust
;
7106 eh
->adjust_done
= 1;
7111 /* Handles decrementing dynamic reloc counts for the reloc specified by
7112 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7113 have already been determined. */
7116 dec_dynrel_count (bfd_vma r_info
,
7118 struct bfd_link_info
*info
,
7119 Elf_Internal_Sym
**local_syms
,
7120 struct elf_link_hash_entry
*h
,
7121 Elf_Internal_Sym
*sym
)
7123 enum elf_ppc64_reloc_type r_type
;
7124 asection
*sym_sec
= NULL
;
7126 /* Can this reloc be dynamic? This switch, and later tests here
7127 should be kept in sync with the code in check_relocs. */
7128 r_type
= ELF64_R_TYPE (r_info
);
7135 case R_PPC64_TOC16_DS
:
7136 case R_PPC64_TOC16_LO
:
7137 case R_PPC64_TOC16_HI
:
7138 case R_PPC64_TOC16_HA
:
7139 case R_PPC64_TOC16_LO_DS
:
7144 case R_PPC64_TPREL16
:
7145 case R_PPC64_TPREL16_LO
:
7146 case R_PPC64_TPREL16_HI
:
7147 case R_PPC64_TPREL16_HA
:
7148 case R_PPC64_TPREL16_DS
:
7149 case R_PPC64_TPREL16_LO_DS
:
7150 case R_PPC64_TPREL16_HIGH
:
7151 case R_PPC64_TPREL16_HIGHA
:
7152 case R_PPC64_TPREL16_HIGHER
:
7153 case R_PPC64_TPREL16_HIGHERA
:
7154 case R_PPC64_TPREL16_HIGHEST
:
7155 case R_PPC64_TPREL16_HIGHESTA
:
7156 case R_PPC64_TPREL64
:
7157 case R_PPC64_TPREL34
:
7158 case R_PPC64_DTPMOD64
:
7159 case R_PPC64_DTPREL64
:
7160 case R_PPC64_ADDR64
:
7164 case R_PPC64_ADDR14
:
7165 case R_PPC64_ADDR14_BRNTAKEN
:
7166 case R_PPC64_ADDR14_BRTAKEN
:
7167 case R_PPC64_ADDR16
:
7168 case R_PPC64_ADDR16_DS
:
7169 case R_PPC64_ADDR16_HA
:
7170 case R_PPC64_ADDR16_HI
:
7171 case R_PPC64_ADDR16_HIGH
:
7172 case R_PPC64_ADDR16_HIGHA
:
7173 case R_PPC64_ADDR16_HIGHER
:
7174 case R_PPC64_ADDR16_HIGHERA
:
7175 case R_PPC64_ADDR16_HIGHEST
:
7176 case R_PPC64_ADDR16_HIGHESTA
:
7177 case R_PPC64_ADDR16_LO
:
7178 case R_PPC64_ADDR16_LO_DS
:
7179 case R_PPC64_ADDR24
:
7180 case R_PPC64_ADDR32
:
7181 case R_PPC64_UADDR16
:
7182 case R_PPC64_UADDR32
:
7183 case R_PPC64_UADDR64
:
7186 case R_PPC64_D34_LO
:
7187 case R_PPC64_D34_HI30
:
7188 case R_PPC64_D34_HA30
:
7189 case R_PPC64_ADDR16_HIGHER34
:
7190 case R_PPC64_ADDR16_HIGHERA34
:
7191 case R_PPC64_ADDR16_HIGHEST34
:
7192 case R_PPC64_ADDR16_HIGHESTA34
:
7197 if (local_syms
!= NULL
)
7199 unsigned long r_symndx
;
7200 bfd
*ibfd
= sec
->owner
;
7202 r_symndx
= ELF64_R_SYM (r_info
);
7203 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7208 && (h
->root
.type
== bfd_link_hash_defweak
7209 || !h
->def_regular
))
7211 && !bfd_link_executable (info
)
7212 && !SYMBOLIC_BIND (info
, h
))
7213 || (bfd_link_pic (info
)
7214 && must_be_dyn_reloc (info
, r_type
))
7215 || (!bfd_link_pic (info
)
7217 ? h
->type
== STT_GNU_IFUNC
7218 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
7225 struct elf_dyn_relocs
*p
;
7226 struct elf_dyn_relocs
**pp
;
7227 pp
= &h
->dyn_relocs
;
7229 /* elf_gc_sweep may have already removed all dyn relocs associated
7230 with local syms for a given section. Also, symbol flags are
7231 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7232 report a dynreloc miscount. */
7233 if (*pp
== NULL
&& info
->gc_sections
)
7236 while ((p
= *pp
) != NULL
)
7240 if (!must_be_dyn_reloc (info
, r_type
))
7252 struct ppc_dyn_relocs
*p
;
7253 struct ppc_dyn_relocs
**pp
;
7257 if (local_syms
== NULL
)
7258 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7259 if (sym_sec
== NULL
)
7262 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7263 pp
= (struct ppc_dyn_relocs
**) vpp
;
7265 if (*pp
== NULL
&& info
->gc_sections
)
7268 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7269 while ((p
= *pp
) != NULL
)
7271 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7282 /* xgettext:c-format */
7283 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7285 bfd_set_error (bfd_error_bad_value
);
7289 /* Remove unused Official Procedure Descriptor entries. Currently we
7290 only remove those associated with functions in discarded link-once
7291 sections, or weakly defined functions that have been overridden. It
7292 would be possible to remove many more entries for statically linked
7296 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7299 bool some_edited
= false;
7300 asection
*need_pad
= NULL
;
7301 struct ppc_link_hash_table
*htab
;
7303 htab
= ppc_hash_table (info
);
7307 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7310 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7311 Elf_Internal_Shdr
*symtab_hdr
;
7312 Elf_Internal_Sym
*local_syms
;
7313 struct _opd_sec_data
*opd
;
7314 bool need_edit
, add_aux_fields
, broken
;
7315 bfd_size_type cnt_16b
= 0;
7317 if (!is_ppc64_elf (ibfd
))
7320 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7321 if (sec
== NULL
|| sec
->size
== 0)
7324 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7327 if (sec
->output_section
== bfd_abs_section_ptr
)
7330 /* Look through the section relocs. */
7331 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7335 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7337 /* Read the relocations. */
7338 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7340 if (relstart
== NULL
)
7343 /* First run through the relocs to check they are sane, and to
7344 determine whether we need to edit this opd section. */
7348 relend
= relstart
+ sec
->reloc_count
;
7349 for (rel
= relstart
; rel
< relend
; )
7351 enum elf_ppc64_reloc_type r_type
;
7352 unsigned long r_symndx
;
7354 struct elf_link_hash_entry
*h
;
7355 Elf_Internal_Sym
*sym
;
7358 /* .opd contains an array of 16 or 24 byte entries. We're
7359 only interested in the reloc pointing to a function entry
7361 offset
= rel
->r_offset
;
7362 if (rel
+ 1 == relend
7363 || rel
[1].r_offset
!= offset
+ 8)
7365 /* If someone messes with .opd alignment then after a
7366 "ld -r" we might have padding in the middle of .opd.
7367 Also, there's nothing to prevent someone putting
7368 something silly in .opd with the assembler. No .opd
7369 optimization for them! */
7372 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7377 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7378 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7381 /* xgettext:c-format */
7382 (_("%pB: unexpected reloc type %u in .opd section"),
7388 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7389 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7393 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7395 const char *sym_name
;
7397 sym_name
= h
->root
.root
.string
;
7399 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7403 /* xgettext:c-format */
7404 (_("%pB: undefined sym `%s' in .opd section"),
7410 /* opd entries are always for functions defined in the
7411 current input bfd. If the symbol isn't defined in the
7412 input bfd, then we won't be using the function in this
7413 bfd; It must be defined in a linkonce section in another
7414 bfd, or is weak. It's also possible that we are
7415 discarding the function due to a linker script /DISCARD/,
7416 which we test for via the output_section. */
7417 if (sym_sec
->owner
!= ibfd
7418 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7422 if (rel
+ 1 == relend
7423 || (rel
+ 2 < relend
7424 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7429 if (sec
->size
== offset
+ 24)
7434 if (sec
->size
== offset
+ 16)
7441 else if (rel
+ 1 < relend
7442 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7443 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7445 if (rel
[0].r_offset
== offset
+ 16)
7447 else if (rel
[0].r_offset
!= offset
+ 24)
7454 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7456 if (!broken
&& (need_edit
|| add_aux_fields
))
7458 Elf_Internal_Rela
*write_rel
;
7459 Elf_Internal_Shdr
*rel_hdr
;
7460 bfd_byte
*rptr
, *wptr
;
7461 bfd_byte
*new_contents
;
7464 new_contents
= NULL
;
7465 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7466 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7467 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7468 if (opd
->adjust
== NULL
)
7471 /* This seems a waste of time as input .opd sections are all
7472 zeros as generated by gcc, but I suppose there's no reason
7473 this will always be so. We might start putting something in
7474 the third word of .opd entries. */
7475 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7478 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7482 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7484 if (elf_section_data (sec
)->relocs
!= relstart
)
7488 sec
->contents
= loc
;
7489 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7492 elf_section_data (sec
)->relocs
= relstart
;
7494 new_contents
= sec
->contents
;
7497 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7498 if (new_contents
== NULL
)
7502 wptr
= new_contents
;
7503 rptr
= sec
->contents
;
7504 write_rel
= relstart
;
7505 for (rel
= relstart
; rel
< relend
; )
7507 unsigned long r_symndx
;
7509 struct elf_link_hash_entry
*h
;
7510 struct ppc_link_hash_entry
*fdh
= NULL
;
7511 Elf_Internal_Sym
*sym
;
7513 Elf_Internal_Rela
*next_rel
;
7516 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7517 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7522 if (next_rel
+ 1 == relend
7523 || (next_rel
+ 2 < relend
7524 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7527 /* See if the .opd entry is full 24 byte or
7528 16 byte (with fd_aux entry overlapped with next
7531 if (next_rel
== relend
)
7533 if (sec
->size
== rel
->r_offset
+ 16)
7536 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7540 && h
->root
.root
.string
[0] == '.')
7542 fdh
= ppc_elf_hash_entry (h
)->oh
;
7545 fdh
= ppc_follow_link (fdh
);
7546 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
7547 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7552 skip
= (sym_sec
->owner
!= ibfd
7553 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7556 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7558 /* Arrange for the function descriptor sym
7560 fdh
->elf
.root
.u
.def
.value
= 0;
7561 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7563 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7565 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7570 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7574 if (++rel
== next_rel
)
7577 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7578 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7585 /* We'll be keeping this opd entry. */
7590 /* Redefine the function descriptor symbol to
7591 this location in the opd section. It is
7592 necessary to update the value here rather
7593 than using an array of adjustments as we do
7594 for local symbols, because various places
7595 in the generic ELF code use the value
7596 stored in u.def.value. */
7597 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7598 fdh
->adjust_done
= 1;
7601 /* Local syms are a bit tricky. We could
7602 tweak them as they can be cached, but
7603 we'd need to look through the local syms
7604 for the function descriptor sym which we
7605 don't have at the moment. So keep an
7606 array of adjustments. */
7607 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
7608 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
7611 memcpy (wptr
, rptr
, opd_ent_size
);
7612 wptr
+= opd_ent_size
;
7613 if (add_aux_fields
&& opd_ent_size
== 16)
7615 memset (wptr
, '\0', 8);
7619 /* We need to adjust any reloc offsets to point to the
7621 for ( ; rel
!= next_rel
; ++rel
)
7623 rel
->r_offset
+= adjust
;
7624 if (write_rel
!= rel
)
7625 memcpy (write_rel
, rel
, sizeof (*rel
));
7630 rptr
+= opd_ent_size
;
7633 sec
->size
= wptr
- new_contents
;
7634 sec
->reloc_count
= write_rel
- relstart
;
7637 free (sec
->contents
);
7638 sec
->contents
= new_contents
;
7641 /* Fudge the header size too, as this is used later in
7642 elf_bfd_final_link if we are emitting relocs. */
7643 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7644 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7647 else if (elf_section_data (sec
)->relocs
!= relstart
)
7650 if (local_syms
!= NULL
7651 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7653 if (!info
->keep_memory
)
7656 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7661 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7663 /* If we are doing a final link and the last .opd entry is just 16 byte
7664 long, add a 8 byte padding after it. */
7665 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7669 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7671 BFD_ASSERT (need_pad
->size
> 0);
7673 p
= bfd_malloc (need_pad
->size
+ 8);
7677 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7678 p
, 0, need_pad
->size
))
7681 need_pad
->contents
= p
;
7682 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7686 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7690 need_pad
->contents
= p
;
7693 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7694 need_pad
->size
+= 8;
7700 /* Analyze inline PLT call relocations to see whether calls to locally
7701 defined functions can be converted to direct calls. */
7704 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7706 struct ppc_link_hash_table
*htab
;
7709 bfd_vma low_vma
, high_vma
, limit
;
7711 htab
= ppc_hash_table (info
);
7715 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7716 reduced somewhat to cater for possible stubs that might be added
7717 between the call and its destination. */
7718 if (htab
->params
->group_size
< 0)
7720 limit
= -htab
->params
->group_size
;
7726 limit
= htab
->params
->group_size
;
7733 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7734 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7736 if (low_vma
> sec
->vma
)
7738 if (high_vma
< sec
->vma
+ sec
->size
)
7739 high_vma
= sec
->vma
+ sec
->size
;
7742 /* If a "bl" can reach anywhere in local code sections, then we can
7743 convert all inline PLT sequences to direct calls when the symbol
7745 if (high_vma
- low_vma
< limit
)
7747 htab
->can_convert_all_inline_plt
= 1;
7751 /* Otherwise, go looking through relocs for cases where a direct
7752 call won't reach. Mark the symbol on any such reloc to disable
7753 the optimization and keep the PLT entry as it seems likely that
7754 this will be better than creating trampolines. Note that this
7755 will disable the optimization for all inline PLT calls to a
7756 particular symbol, not just those that won't reach. The
7757 difficulty in doing a more precise optimization is that the
7758 linker needs to make a decision depending on whether a
7759 particular R_PPC64_PLTCALL insn can be turned into a direct
7760 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7761 the sequence, and there is nothing that ties those relocs
7762 together except their symbol. */
7764 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7766 Elf_Internal_Shdr
*symtab_hdr
;
7767 Elf_Internal_Sym
*local_syms
;
7769 if (!is_ppc64_elf (ibfd
))
7773 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7775 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7776 if (ppc64_elf_section_data (sec
)->has_pltcall
7777 && !bfd_is_abs_section (sec
->output_section
))
7779 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7781 /* Read the relocations. */
7782 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7784 if (relstart
== NULL
)
7787 relend
= relstart
+ sec
->reloc_count
;
7788 for (rel
= relstart
; rel
< relend
; rel
++)
7790 enum elf_ppc64_reloc_type r_type
;
7791 unsigned long r_symndx
;
7793 struct elf_link_hash_entry
*h
;
7794 Elf_Internal_Sym
*sym
;
7795 unsigned char *tls_maskp
;
7797 r_type
= ELF64_R_TYPE (rel
->r_info
);
7798 if (r_type
!= R_PPC64_PLTCALL
7799 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
7802 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7803 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7806 if (elf_section_data (sec
)->relocs
!= relstart
)
7808 if (symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7813 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7817 to
= h
->root
.u
.def
.value
;
7820 to
+= (rel
->r_addend
7821 + sym_sec
->output_offset
7822 + sym_sec
->output_section
->vma
);
7823 from
= (rel
->r_offset
7824 + sec
->output_offset
7825 + sec
->output_section
->vma
);
7826 if (to
- from
+ limit
< 2 * limit
7827 && !(r_type
== R_PPC64_PLTCALL_NOTOC
7828 && (((h
? h
->other
: sym
->st_other
)
7829 & STO_PPC64_LOCAL_MASK
)
7830 > 1 << STO_PPC64_LOCAL_BIT
)))
7831 *tls_maskp
&= ~PLT_KEEP
;
7834 if (elf_section_data (sec
)->relocs
!= relstart
)
7838 if (local_syms
!= NULL
7839 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7841 if (!info
->keep_memory
)
7844 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7851 /* Set htab->tls_get_addr and various other info specific to TLS.
7852 This needs to run before dynamic symbols are processed in
7853 bfd_elf_size_dynamic_sections. */
7856 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7858 struct ppc_link_hash_table
*htab
;
7859 struct elf_link_hash_entry
*tga
, *tga_fd
, *desc
, *desc_fd
;
7861 htab
= ppc_hash_table (info
);
7865 /* Move dynamic linking info to the function descriptor sym. */
7866 if (htab
->need_func_desc_adj
)
7868 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7869 htab
->need_func_desc_adj
= 0;
7872 if (abiversion (info
->output_bfd
) == 1)
7875 if (htab
->params
->no_multi_toc
)
7876 htab
->do_multi_toc
= 0;
7877 else if (!htab
->do_multi_toc
)
7878 htab
->params
->no_multi_toc
= 1;
7880 /* Default to --no-plt-localentry, as this option can cause problems
7881 with symbol interposition. For example, glibc libpthread.so and
7882 libc.so duplicate many pthread symbols, with a fallback
7883 implementation in libc.so. In some cases the fallback does more
7884 work than the pthread implementation. __pthread_condattr_destroy
7885 is one such symbol: the libpthread.so implementation is
7886 localentry:0 while the libc.so implementation is localentry:8.
7887 An app that "cleverly" uses dlopen to only load necessary
7888 libraries at runtime may omit loading libpthread.so when not
7889 running multi-threaded, which then results in the libc.so
7890 fallback symbols being used and ld.so complaining. Now there
7891 are workarounds in ld (see non_zero_localentry) to detect the
7892 pthread situation, but that may not be the only case where
7893 --plt-localentry can cause trouble. */
7894 if (htab
->params
->plt_localentry0
< 0)
7895 htab
->params
->plt_localentry0
= 0;
7896 if (htab
->params
->plt_localentry0
&& htab
->has_power10_relocs
)
7898 /* The issue is that __glink_PLTresolve saves r2, which is done
7899 because glibc ld.so _dl_runtime_resolve restores r2 to support
7900 a glibc plt call optimisation where global entry code is
7901 skipped on calls that resolve to the same binary. The
7902 __glink_PLTresolve save of r2 is incompatible with code
7903 making tail calls, because the tail call might go via the
7904 resolver and thus overwrite the proper saved r2. */
7905 _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
7906 "power10 pc-relative code"));
7907 htab
->params
->plt_localentry0
= 0;
7909 if (htab
->params
->plt_localentry0
7910 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7911 false, false, false) == NULL
)
7913 (_("warning: --plt-localentry is especially dangerous without "
7914 "ld.so support to detect ABI violations"));
7916 tga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7917 false, false, true);
7918 htab
->tls_get_addr
= ppc_elf_hash_entry (tga
);
7919 tga_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7920 false, false, true);
7921 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (tga_fd
);
7923 desc
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_desc",
7924 false, false, true);
7925 htab
->tga_desc
= ppc_elf_hash_entry (desc
);
7926 desc_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_desc",
7927 false, false, true);
7928 htab
->tga_desc_fd
= ppc_elf_hash_entry (desc_fd
);
7930 if (htab
->params
->tls_get_addr_opt
)
7932 struct elf_link_hash_entry
*opt
, *opt_fd
;
7934 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7935 false, false, true);
7936 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7937 false, false, true);
7939 && (opt_fd
->root
.type
== bfd_link_hash_defined
7940 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7942 /* If glibc supports an optimized __tls_get_addr call stub,
7943 signalled by the presence of __tls_get_addr_opt, and we'll
7944 be calling __tls_get_addr via a plt call stub, then
7945 make __tls_get_addr point to __tls_get_addr_opt. */
7946 if (!(htab
->elf
.dynamic_sections_created
7948 && (tga_fd
->type
== STT_FUNC
7949 || tga_fd
->needs_plt
)
7950 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7951 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
))))
7953 if (!(htab
->elf
.dynamic_sections_created
7955 && (desc_fd
->type
== STT_FUNC
7956 || desc_fd
->needs_plt
)
7957 && !(SYMBOL_CALLS_LOCAL (info
, desc_fd
)
7958 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, desc_fd
))))
7961 if (tga_fd
!= NULL
|| desc_fd
!= NULL
)
7963 struct plt_entry
*ent
= NULL
;
7966 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7967 if (ent
->plt
.refcount
> 0)
7969 if (ent
== NULL
&& desc_fd
!= NULL
)
7970 for (ent
= desc_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7971 if (ent
->plt
.refcount
> 0)
7977 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7978 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7979 tga_fd
->root
.u
.i
.warning
= NULL
;
7980 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7982 if (desc_fd
!= NULL
)
7984 desc_fd
->root
.type
= bfd_link_hash_indirect
;
7985 desc_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7986 desc_fd
->root
.u
.i
.warning
= NULL
;
7987 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, desc_fd
);
7990 if (opt_fd
->dynindx
!= -1)
7992 /* Use __tls_get_addr_opt in dynamic relocations. */
7993 opt_fd
->dynindx
= -1;
7994 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7995 opt_fd
->dynstr_index
);
7996 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8001 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (opt_fd
);
8002 tga
= elf_hash_entry (htab
->tls_get_addr
);
8003 if (opt
!= NULL
&& tga
!= NULL
)
8005 tga
->root
.type
= bfd_link_hash_indirect
;
8006 tga
->root
.u
.i
.link
= &opt
->root
;
8007 tga
->root
.u
.i
.warning
= NULL
;
8008 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8010 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8012 htab
->tls_get_addr
= ppc_elf_hash_entry (opt
);
8014 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8015 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8016 if (htab
->tls_get_addr
!= NULL
)
8018 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8019 htab
->tls_get_addr
->is_func
= 1;
8022 if (desc_fd
!= NULL
)
8024 htab
->tga_desc_fd
= ppc_elf_hash_entry (opt_fd
);
8025 if (opt
!= NULL
&& desc
!= NULL
)
8027 desc
->root
.type
= bfd_link_hash_indirect
;
8028 desc
->root
.u
.i
.link
= &opt
->root
;
8029 desc
->root
.u
.i
.warning
= NULL
;
8030 ppc64_elf_copy_indirect_symbol (info
, opt
, desc
);
8032 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8033 desc
->forced_local
);
8034 htab
->tga_desc
= ppc_elf_hash_entry (opt
);
8036 htab
->tga_desc_fd
->oh
= htab
->tga_desc
;
8037 htab
->tga_desc_fd
->is_func_descriptor
= 1;
8038 if (htab
->tga_desc
!= NULL
)
8040 htab
->tga_desc
->oh
= htab
->tga_desc_fd
;
8041 htab
->tga_desc
->is_func
= 1;
8047 else if (htab
->params
->tls_get_addr_opt
< 0)
8048 htab
->params
->tls_get_addr_opt
= 0;
8051 if (htab
->tga_desc_fd
!= NULL
8052 && htab
->params
->tls_get_addr_opt
8053 && htab
->params
->no_tls_get_addr_regsave
== -1)
8054 htab
->params
->no_tls_get_addr_regsave
= 0;
8059 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8060 any of HASH1, HASH2, HASH3, or HASH4. */
8063 branch_reloc_hash_match (bfd
*ibfd
,
8064 Elf_Internal_Rela
*rel
,
8065 struct ppc_link_hash_entry
*hash1
,
8066 struct ppc_link_hash_entry
*hash2
,
8067 struct ppc_link_hash_entry
*hash3
,
8068 struct ppc_link_hash_entry
*hash4
)
8070 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8071 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8072 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8074 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8076 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8077 struct elf_link_hash_entry
*h
;
8079 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8080 h
= elf_follow_link (h
);
8081 if (h
== elf_hash_entry (hash1
)
8082 || h
== elf_hash_entry (hash2
)
8083 || h
== elf_hash_entry (hash3
)
8084 || h
== elf_hash_entry (hash4
))
8090 /* Run through all the TLS relocs looking for optimization
8091 opportunities. The linker has been hacked (see ppc64elf.em) to do
8092 a preliminary section layout so that we know the TLS segment
8093 offsets. We can't optimize earlier because some optimizations need
8094 to know the tp offset, and we need to optimize before allocating
8095 dynamic relocations. */
8098 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8102 struct ppc_link_hash_table
*htab
;
8103 unsigned char *toc_ref
;
8106 if (!bfd_link_executable (info
))
8109 htab
= ppc_hash_table (info
);
8113 htab
->do_tls_opt
= 1;
8115 /* Make two passes over the relocs. On the first pass, mark toc
8116 entries involved with tls relocs, and check that tls relocs
8117 involved in setting up a tls_get_addr call are indeed followed by
8118 such a call. If they are not, we can't do any tls optimization.
8119 On the second pass twiddle tls_mask flags to notify
8120 relocate_section that optimization can be done, and adjust got
8121 and plt refcounts. */
8123 for (pass
= 0; pass
< 2; ++pass
)
8124 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8126 Elf_Internal_Sym
*locsyms
= NULL
;
8127 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8129 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8130 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8132 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8133 bool found_tls_get_addr_arg
= 0;
8135 /* Read the relocations. */
8136 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8138 if (relstart
== NULL
)
8144 relend
= relstart
+ sec
->reloc_count
;
8145 for (rel
= relstart
; rel
< relend
; rel
++)
8147 enum elf_ppc64_reloc_type r_type
;
8148 unsigned long r_symndx
;
8149 struct elf_link_hash_entry
*h
;
8150 Elf_Internal_Sym
*sym
;
8152 unsigned char *tls_mask
;
8153 unsigned int tls_set
, tls_clear
, tls_type
= 0;
8155 bool ok_tprel
, is_local
;
8156 long toc_ref_index
= 0;
8157 int expecting_tls_get_addr
= 0;
8160 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8161 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8165 if (elf_section_data (sec
)->relocs
!= relstart
)
8168 if (elf_symtab_hdr (ibfd
).contents
8169 != (unsigned char *) locsyms
)
8176 if (h
->root
.type
== bfd_link_hash_defined
8177 || h
->root
.type
== bfd_link_hash_defweak
)
8178 value
= h
->root
.u
.def
.value
;
8179 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8183 found_tls_get_addr_arg
= 0;
8188 /* Symbols referenced by TLS relocs must be of type
8189 STT_TLS. So no need for .opd local sym adjust. */
8190 value
= sym
->st_value
;
8193 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
8197 && h
->root
.type
== bfd_link_hash_undefweak
)
8199 else if (sym_sec
!= NULL
8200 && sym_sec
->output_section
!= NULL
)
8202 value
+= sym_sec
->output_offset
;
8203 value
+= sym_sec
->output_section
->vma
;
8204 value
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8205 /* Note that even though the prefix insns
8206 allow a 1<<33 offset we use the same test
8207 as for addis;addi. There may be a mix of
8208 pcrel and non-pcrel code and the decision
8209 to optimise is per symbol, not per TLS
8211 ok_tprel
= value
+ 0x80008000ULL
< 1ULL << 32;
8215 r_type
= ELF64_R_TYPE (rel
->r_info
);
8216 /* If this section has old-style __tls_get_addr calls
8217 without marker relocs, then check that each
8218 __tls_get_addr call reloc is preceded by a reloc
8219 that conceivably belongs to the __tls_get_addr arg
8220 setup insn. If we don't find matching arg setup
8221 relocs, don't do any tls optimization. */
8223 && sec
->nomark_tls_get_addr
8225 && is_tls_get_addr (h
, htab
)
8226 && !found_tls_get_addr_arg
8227 && is_branch_reloc (r_type
))
8229 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8230 "TLS optimization disabled\n"),
8231 ibfd
, sec
, rel
->r_offset
);
8236 found_tls_get_addr_arg
= 0;
8239 case R_PPC64_GOT_TLSLD16
:
8240 case R_PPC64_GOT_TLSLD16_LO
:
8241 case R_PPC64_GOT_TLSLD_PCREL34
:
8242 expecting_tls_get_addr
= 1;
8243 found_tls_get_addr_arg
= 1;
8246 case R_PPC64_GOT_TLSLD16_HI
:
8247 case R_PPC64_GOT_TLSLD16_HA
:
8248 /* These relocs should never be against a symbol
8249 defined in a shared lib. Leave them alone if
8250 that turns out to be the case. */
8257 tls_type
= TLS_TLS
| TLS_LD
;
8260 case R_PPC64_GOT_TLSGD16
:
8261 case R_PPC64_GOT_TLSGD16_LO
:
8262 case R_PPC64_GOT_TLSGD_PCREL34
:
8263 expecting_tls_get_addr
= 1;
8264 found_tls_get_addr_arg
= 1;
8267 case R_PPC64_GOT_TLSGD16_HI
:
8268 case R_PPC64_GOT_TLSGD16_HA
:
8274 tls_set
= TLS_TLS
| TLS_GDIE
;
8276 tls_type
= TLS_TLS
| TLS_GD
;
8279 case R_PPC64_GOT_TPREL_PCREL34
:
8280 case R_PPC64_GOT_TPREL16_DS
:
8281 case R_PPC64_GOT_TPREL16_LO_DS
:
8282 case R_PPC64_GOT_TPREL16_HI
:
8283 case R_PPC64_GOT_TPREL16_HA
:
8288 tls_clear
= TLS_TPREL
;
8289 tls_type
= TLS_TLS
| TLS_TPREL
;
8299 if (rel
+ 1 < relend
8300 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8303 && (ELF64_R_TYPE (rel
[1].r_info
)
8305 && (ELF64_R_TYPE (rel
[1].r_info
)
8306 != R_PPC64_PLTSEQ_NOTOC
))
8308 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8309 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8314 struct plt_entry
*ent
= NULL
;
8316 for (ent
= h
->plt
.plist
;
8319 if (ent
->addend
== rel
[1].r_addend
)
8323 && ent
->plt
.refcount
> 0)
8324 ent
->plt
.refcount
-= 1;
8329 found_tls_get_addr_arg
= 1;
8334 case R_PPC64_TOC16_LO
:
8335 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8338 /* Mark this toc entry as referenced by a TLS
8339 code sequence. We can do that now in the
8340 case of R_PPC64_TLS, and after checking for
8341 tls_get_addr for the TOC16 relocs. */
8342 if (toc_ref
== NULL
)
8344 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8345 if (toc_ref
== NULL
)
8349 value
= h
->root
.u
.def
.value
;
8351 value
= sym
->st_value
;
8352 value
+= rel
->r_addend
;
8355 BFD_ASSERT (value
< toc
->size
8356 && toc
->output_offset
% 8 == 0);
8357 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8358 if (r_type
== R_PPC64_TLS
8359 || r_type
== R_PPC64_TLSGD
8360 || r_type
== R_PPC64_TLSLD
)
8362 toc_ref
[toc_ref_index
] = 1;
8366 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8371 expecting_tls_get_addr
= 2;
8374 case R_PPC64_TPREL64
:
8378 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8383 tls_set
= TLS_EXPLICIT
;
8384 tls_clear
= TLS_TPREL
;
8389 case R_PPC64_DTPMOD64
:
8393 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8395 if (rel
+ 1 < relend
8397 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8398 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8402 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8405 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_GDIE
;
8414 tls_set
= TLS_EXPLICIT
;
8419 case R_PPC64_TPREL16_HA
:
8422 unsigned char buf
[4];
8424 bfd_vma off
= rel
->r_offset
& ~3;
8425 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8428 insn
= bfd_get_32 (ibfd
, buf
);
8429 /* addis rt,13,imm */
8430 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8431 != ((15u << 26) | (13 << 16)))
8433 /* xgettext:c-format */
8434 info
->callbacks
->minfo
8435 (_("%H: warning: %s unexpected insn %#x.\n"),
8436 ibfd
, sec
, off
, "R_PPC64_TPREL16_HA", insn
);
8437 htab
->do_tls_opt
= 0;
8442 case R_PPC64_TPREL16_HI
:
8443 case R_PPC64_TPREL16_HIGH
:
8444 case R_PPC64_TPREL16_HIGHA
:
8445 case R_PPC64_TPREL16_HIGHER
:
8446 case R_PPC64_TPREL16_HIGHERA
:
8447 case R_PPC64_TPREL16_HIGHEST
:
8448 case R_PPC64_TPREL16_HIGHESTA
:
8449 /* These can all be used in sequences along with
8450 TPREL16_LO or TPREL16_LO_DS in ways we aren't
8451 able to verify easily. */
8452 htab
->do_tls_opt
= 0;
8461 if (!expecting_tls_get_addr
8462 || !sec
->nomark_tls_get_addr
)
8465 if (rel
+ 1 < relend
8466 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8467 htab
->tls_get_addr_fd
,
8472 if (expecting_tls_get_addr
== 2)
8474 /* Check for toc tls entries. */
8475 unsigned char *toc_tls
;
8478 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8483 if (toc_tls
!= NULL
)
8485 if ((*toc_tls
& TLS_TLS
) != 0
8486 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8487 found_tls_get_addr_arg
= 1;
8489 toc_ref
[toc_ref_index
] = 1;
8495 /* Uh oh, we didn't find the expected call. We
8496 could just mark this symbol to exclude it
8497 from tls optimization but it's safer to skip
8498 the entire optimization. */
8499 /* xgettext:c-format */
8500 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8501 "TLS optimization disabled\n"),
8502 ibfd
, sec
, rel
->r_offset
);
8507 /* If we don't have old-style __tls_get_addr calls
8508 without TLSGD/TLSLD marker relocs, and we haven't
8509 found a new-style __tls_get_addr call with a
8510 marker for this symbol, then we either have a
8511 broken object file or an -mlongcall style
8512 indirect call to __tls_get_addr without a marker.
8513 Disable optimization in this case. */
8514 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8515 && (tls_set
& TLS_EXPLICIT
) == 0
8516 && !sec
->nomark_tls_get_addr
8517 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8518 != (TLS_TLS
| TLS_MARK
)))
8521 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
8523 struct plt_entry
*ent
= NULL
;
8525 if (htab
->tls_get_addr_fd
!= NULL
)
8526 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8529 if (ent
->addend
== 0)
8532 if (ent
== NULL
&& htab
->tga_desc_fd
!= NULL
)
8533 for (ent
= htab
->tga_desc_fd
->elf
.plt
.plist
;
8536 if (ent
->addend
== 0)
8539 if (ent
== NULL
&& htab
->tls_get_addr
!= NULL
)
8540 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8543 if (ent
->addend
== 0)
8546 if (ent
== NULL
&& htab
->tga_desc
!= NULL
)
8547 for (ent
= htab
->tga_desc
->elf
.plt
.plist
;
8550 if (ent
->addend
== 0)
8554 && ent
->plt
.refcount
> 0)
8555 ent
->plt
.refcount
-= 1;
8561 if ((tls_set
& TLS_EXPLICIT
) == 0)
8563 struct got_entry
*ent
;
8565 /* Adjust got entry for this reloc. */
8569 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8571 for (; ent
!= NULL
; ent
= ent
->next
)
8572 if (ent
->addend
== rel
->r_addend
8573 && ent
->owner
== ibfd
8574 && ent
->tls_type
== tls_type
)
8581 /* We managed to get rid of a got entry. */
8582 if (ent
->got
.refcount
> 0)
8583 ent
->got
.refcount
-= 1;
8588 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8589 we'll lose one or two dyn relocs. */
8590 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8594 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8596 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8602 *tls_mask
|= tls_set
& 0xff;
8603 *tls_mask
&= ~tls_clear
;
8606 if (elf_section_data (sec
)->relocs
!= relstart
)
8611 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8613 if (!info
->keep_memory
)
8616 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8624 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8625 the values of any global symbols in a toc section that has been
8626 edited. Globals in toc sections should be a rarity, so this function
8627 sets a flag if any are found in toc sections other than the one just
8628 edited, so that further hash table traversals can be avoided. */
8630 struct adjust_toc_info
8633 unsigned long *skip
;
8634 bool global_toc_syms
;
8637 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8640 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8642 struct ppc_link_hash_entry
*eh
;
8643 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8646 if (h
->root
.type
!= bfd_link_hash_defined
8647 && h
->root
.type
!= bfd_link_hash_defweak
)
8650 eh
= ppc_elf_hash_entry (h
);
8651 if (eh
->adjust_done
)
8654 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8656 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8657 i
= toc_inf
->toc
->rawsize
>> 3;
8659 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8661 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8664 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8667 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8668 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8671 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8672 eh
->adjust_done
= 1;
8674 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8675 toc_inf
->global_toc_syms
= true;
8680 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8681 on a _LO variety toc/got reloc. */
8684 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8686 return ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */
8687 || (insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
8688 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
8689 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
8690 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
8691 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
8692 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
8693 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
8694 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
8695 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
8696 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
8697 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
8698 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
8699 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
8700 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
8701 || (insn
& (0x3fu
<< 26)) == 56u << 26 /* lq,lfq */
8702 || ((insn
& (0x3fu
<< 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8703 /* Exclude lfqu by testing reloc. If relocs are ever
8704 defined for the reduced D field in psq_lu then those
8705 will need testing too. */
8706 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8707 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* ld,lwa */
8709 || (insn
& (0x3fu
<< 26)) == 60u << 26 /* stfq */
8710 || ((insn
& (0x3fu
<< 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8711 /* Exclude stfqu. psq_stu as above for psq_lu. */
8712 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8713 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std,stq */
8714 && (insn
& 1) == 0));
8717 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
8718 pld ra,symbol@got@pcrel
8719 load/store rt,off(ra)
8722 load/store rt,off(ra)
8723 may be translated to
8724 pload/pstore rt,symbol+off@pcrel
8726 This function returns true if the optimization is possible, placing
8727 the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
8729 On entry to this function, the linker has already determined that
8730 the pld can be replaced with pla: *PINSN1 is that pla insn,
8731 while *PINSN2 is the second instruction. */
8734 xlate_pcrel_opt (uint64_t *pinsn1
, uint64_t *pinsn2
, bfd_signed_vma
*poff
)
8736 uint64_t insn1
= *pinsn1
;
8737 uint64_t insn2
= *pinsn2
;
8740 if ((insn2
& (63ULL << 58)) == 1ULL << 58)
8742 /* Check that regs match. */
8743 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8746 /* P8LS or PMLS form, non-pcrel. */
8747 if ((insn2
& (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
8750 *pinsn1
= (insn2
& ~(31 << 16) & ~0x3ffff0000ffffULL
) | (1ULL << 52);
8752 off
= ((insn2
>> 16) & 0x3ffff0000ULL
) | (insn2
& 0xffff);
8753 *poff
= (off
^ 0x200000000ULL
) - 0x200000000ULL
;
8759 /* Check that regs match. */
8760 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8763 switch ((insn2
>> 26) & 63)
8779 /* These are the PMLS cases, where we just need to tack a prefix
8781 insn1
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
8782 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8783 off
= insn2
& 0xffff;
8786 case 58: /* lwa, ld */
8787 if ((insn2
& 1) != 0)
8789 insn1
= ((1ULL << 58) | (1ULL << 52)
8790 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
8791 | (insn2
& (31ULL << 21)));
8792 off
= insn2
& 0xfffc;
8795 case 57: /* lxsd, lxssp */
8796 if ((insn2
& 3) < 2)
8798 insn1
= ((1ULL << 58) | (1ULL << 52)
8799 | ((40ULL | (insn2
& 3)) << 26)
8800 | (insn2
& (31ULL << 21)));
8801 off
= insn2
& 0xfffc;
8804 case 61: /* stxsd, stxssp, lxv, stxv */
8805 if ((insn2
& 3) == 0)
8807 else if ((insn2
& 3) >= 2)
8809 insn1
= ((1ULL << 58) | (1ULL << 52)
8810 | ((44ULL | (insn2
& 3)) << 26)
8811 | (insn2
& (31ULL << 21)));
8812 off
= insn2
& 0xfffc;
8816 insn1
= ((1ULL << 58) | (1ULL << 52)
8817 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
8818 | (insn2
& (31ULL << 21)));
8819 off
= insn2
& 0xfff0;
8824 insn1
= ((1ULL << 58) | (1ULL << 52)
8825 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8826 off
= insn2
& 0xffff;
8829 case 6: /* lxvp, stxvp */
8830 if ((insn2
& 0xe) != 0)
8832 insn1
= ((1ULL << 58) | (1ULL << 52)
8833 | ((insn2
& 1) == 0 ? 58ULL << 26 : 62ULL << 26)
8834 | (insn2
& (31ULL << 21)));
8835 off
= insn2
& 0xfff0;
8838 case 62: /* std, stq */
8839 if ((insn2
& 1) != 0)
8841 insn1
= ((1ULL << 58) | (1ULL << 52)
8842 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
8843 | (insn2
& (31ULL << 21)));
8844 off
= insn2
& 0xfffc;
8849 *pinsn2
= (uint64_t) NOP
<< 32;
8850 *poff
= (off
^ 0x8000) - 0x8000;
8854 /* Examine all relocs referencing .toc sections in order to remove
8855 unused .toc entries. */
8858 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8861 struct adjust_toc_info toc_inf
;
8862 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8864 htab
->do_toc_opt
= 1;
8865 toc_inf
.global_toc_syms
= true;
8866 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8868 asection
*toc
, *sec
;
8869 Elf_Internal_Shdr
*symtab_hdr
;
8870 Elf_Internal_Sym
*local_syms
;
8871 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8872 unsigned long *skip
, *drop
;
8873 unsigned char *used
;
8874 unsigned char *keep
, last
, some_unused
;
8876 if (!is_ppc64_elf (ibfd
))
8879 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8882 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8883 || discarded_section (toc
))
8888 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8890 /* Look at sections dropped from the final link. */
8893 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8895 if (sec
->reloc_count
== 0
8896 || !discarded_section (sec
)
8897 || get_opd_info (sec
)
8898 || (sec
->flags
& SEC_ALLOC
) == 0
8899 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8902 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, false);
8903 if (relstart
== NULL
)
8906 /* Run through the relocs to see which toc entries might be
8908 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8910 enum elf_ppc64_reloc_type r_type
;
8911 unsigned long r_symndx
;
8913 struct elf_link_hash_entry
*h
;
8914 Elf_Internal_Sym
*sym
;
8917 r_type
= ELF64_R_TYPE (rel
->r_info
);
8924 case R_PPC64_TOC16_LO
:
8925 case R_PPC64_TOC16_HI
:
8926 case R_PPC64_TOC16_HA
:
8927 case R_PPC64_TOC16_DS
:
8928 case R_PPC64_TOC16_LO_DS
:
8932 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8933 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8941 val
= h
->root
.u
.def
.value
;
8943 val
= sym
->st_value
;
8944 val
+= rel
->r_addend
;
8946 if (val
>= toc
->size
)
8949 /* Anything in the toc ought to be aligned to 8 bytes.
8950 If not, don't mark as unused. */
8956 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8961 skip
[val
>> 3] = ref_from_discarded
;
8964 if (elf_section_data (sec
)->relocs
!= relstart
)
8968 /* For largetoc loads of address constants, we can convert
8969 . addis rx,2,addr@got@ha
8970 . ld ry,addr@got@l(rx)
8972 . addis rx,2,addr@toc@ha
8973 . addi ry,rx,addr@toc@l
8974 when addr is within 2G of the toc pointer. This then means
8975 that the word storing "addr" in the toc is no longer needed. */
8977 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8978 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8979 && toc
->reloc_count
!= 0)
8981 /* Read toc relocs. */
8982 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8984 if (toc_relocs
== NULL
)
8987 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8989 enum elf_ppc64_reloc_type r_type
;
8990 unsigned long r_symndx
;
8992 struct elf_link_hash_entry
*h
;
8993 Elf_Internal_Sym
*sym
;
8996 r_type
= ELF64_R_TYPE (rel
->r_info
);
8997 if (r_type
!= R_PPC64_ADDR64
)
9000 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9001 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9006 || sym_sec
->output_section
== NULL
9007 || discarded_section (sym_sec
))
9010 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9015 if (h
->type
== STT_GNU_IFUNC
)
9017 val
= h
->root
.u
.def
.value
;
9021 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9023 val
= sym
->st_value
;
9025 val
+= rel
->r_addend
;
9026 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9028 /* We don't yet know the exact toc pointer value, but we
9029 know it will be somewhere in the toc section. Don't
9030 optimize if the difference from any possible toc
9031 pointer is outside [ff..f80008000, 7fff7fff]. */
9032 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9033 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9036 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9037 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9042 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9047 skip
[rel
->r_offset
>> 3]
9048 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9055 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9059 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9062 && elf_section_data (sec
)->relocs
!= relstart
)
9064 if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9070 /* Now check all kept sections that might reference the toc.
9071 Check the toc itself last. */
9072 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9075 sec
= (sec
== toc
? NULL
9076 : sec
->next
== NULL
? toc
9077 : sec
->next
== toc
&& toc
->next
? toc
->next
9082 if (sec
->reloc_count
== 0
9083 || discarded_section (sec
)
9084 || get_opd_info (sec
)
9085 || (sec
->flags
& SEC_ALLOC
) == 0
9086 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9089 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9091 if (relstart
== NULL
)
9097 /* Mark toc entries referenced as used. */
9101 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9103 enum elf_ppc64_reloc_type r_type
;
9104 unsigned long r_symndx
;
9106 struct elf_link_hash_entry
*h
;
9107 Elf_Internal_Sym
*sym
;
9110 r_type
= ELF64_R_TYPE (rel
->r_info
);
9114 case R_PPC64_TOC16_LO
:
9115 case R_PPC64_TOC16_HI
:
9116 case R_PPC64_TOC16_HA
:
9117 case R_PPC64_TOC16_DS
:
9118 case R_PPC64_TOC16_LO_DS
:
9119 /* In case we're taking addresses of toc entries. */
9120 case R_PPC64_ADDR64
:
9127 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9128 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9139 val
= h
->root
.u
.def
.value
;
9141 val
= sym
->st_value
;
9142 val
+= rel
->r_addend
;
9144 if (val
>= toc
->size
)
9147 if ((skip
[val
>> 3] & can_optimize
) != 0)
9154 case R_PPC64_TOC16_HA
:
9157 case R_PPC64_TOC16_LO_DS
:
9158 off
= rel
->r_offset
;
9159 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9160 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9166 if ((opc
& (0x3f << 2)) == (58u << 2))
9171 /* Wrong sort of reloc, or not a ld. We may
9172 as well clear ref_from_discarded too. */
9179 /* For the toc section, we only mark as used if this
9180 entry itself isn't unused. */
9181 else if ((used
[rel
->r_offset
>> 3]
9182 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9185 /* Do all the relocs again, to catch reference
9194 if (elf_section_data (sec
)->relocs
!= relstart
)
9198 /* Merge the used and skip arrays. Assume that TOC
9199 doublewords not appearing as either used or unused belong
9200 to an entry more than one doubleword in size. */
9201 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9202 drop
< skip
+ (toc
->size
+ 7) / 8;
9207 *drop
&= ~ref_from_discarded
;
9208 if ((*drop
& can_optimize
) != 0)
9212 else if ((*drop
& ref_from_discarded
) != 0)
9215 last
= ref_from_discarded
;
9225 bfd_byte
*contents
, *src
;
9227 Elf_Internal_Sym
*sym
;
9228 bool local_toc_syms
= false;
9230 /* Shuffle the toc contents, and at the same time convert the
9231 skip array from booleans into offsets. */
9232 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9235 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9237 for (src
= contents
, off
= 0, drop
= skip
;
9238 src
< contents
+ toc
->size
;
9241 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9246 memcpy (src
- off
, src
, 8);
9250 toc
->rawsize
= toc
->size
;
9251 toc
->size
= src
- contents
- off
;
9253 /* Adjust addends for relocs against the toc section sym,
9254 and optimize any accesses we can. */
9255 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9257 if (sec
->reloc_count
== 0
9258 || discarded_section (sec
))
9261 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9263 if (relstart
== NULL
)
9266 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9268 enum elf_ppc64_reloc_type r_type
;
9269 unsigned long r_symndx
;
9271 struct elf_link_hash_entry
*h
;
9274 r_type
= ELF64_R_TYPE (rel
->r_info
);
9281 case R_PPC64_TOC16_LO
:
9282 case R_PPC64_TOC16_HI
:
9283 case R_PPC64_TOC16_HA
:
9284 case R_PPC64_TOC16_DS
:
9285 case R_PPC64_TOC16_LO_DS
:
9286 case R_PPC64_ADDR64
:
9290 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9291 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9299 val
= h
->root
.u
.def
.value
;
9302 val
= sym
->st_value
;
9304 local_toc_syms
= true;
9307 val
+= rel
->r_addend
;
9309 if (val
> toc
->rawsize
)
9311 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9313 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9315 Elf_Internal_Rela
*tocrel
9316 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9317 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9321 case R_PPC64_TOC16_HA
:
9322 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9325 case R_PPC64_TOC16_LO_DS
:
9326 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9330 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9332 info
->callbacks
->einfo
9333 /* xgettext:c-format */
9334 (_("%H: %s references "
9335 "optimized away TOC entry\n"),
9336 ibfd
, sec
, rel
->r_offset
,
9337 ppc64_elf_howto_table
[r_type
]->name
);
9338 bfd_set_error (bfd_error_bad_value
);
9341 rel
->r_addend
= tocrel
->r_addend
;
9342 elf_section_data (sec
)->relocs
= relstart
;
9346 if (h
!= NULL
|| sym
->st_value
!= 0)
9349 rel
->r_addend
-= skip
[val
>> 3];
9350 elf_section_data (sec
)->relocs
= relstart
;
9353 if (elf_section_data (sec
)->relocs
!= relstart
)
9357 /* We shouldn't have local or global symbols defined in the TOC,
9358 but handle them anyway. */
9359 if (local_syms
!= NULL
)
9360 for (sym
= local_syms
;
9361 sym
< local_syms
+ symtab_hdr
->sh_info
;
9363 if (sym
->st_value
!= 0
9364 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9368 if (sym
->st_value
> toc
->rawsize
)
9369 i
= toc
->rawsize
>> 3;
9371 i
= sym
->st_value
>> 3;
9373 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9377 (_("%s defined on removed toc entry"),
9378 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9381 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9382 sym
->st_value
= (bfd_vma
) i
<< 3;
9385 sym
->st_value
-= skip
[i
];
9386 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9389 /* Adjust any global syms defined in this toc input section. */
9390 if (toc_inf
.global_toc_syms
)
9393 toc_inf
.skip
= skip
;
9394 toc_inf
.global_toc_syms
= false;
9395 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9399 if (toc
->reloc_count
!= 0)
9401 Elf_Internal_Shdr
*rel_hdr
;
9402 Elf_Internal_Rela
*wrel
;
9405 /* Remove unused toc relocs, and adjust those we keep. */
9406 if (toc_relocs
== NULL
)
9407 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9409 if (toc_relocs
== NULL
)
9413 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9414 if ((skip
[rel
->r_offset
>> 3]
9415 & (ref_from_discarded
| can_optimize
)) == 0)
9417 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9418 wrel
->r_info
= rel
->r_info
;
9419 wrel
->r_addend
= rel
->r_addend
;
9422 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9423 &local_syms
, NULL
, NULL
))
9426 elf_section_data (toc
)->relocs
= toc_relocs
;
9427 toc
->reloc_count
= wrel
- toc_relocs
;
9428 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9429 sz
= rel_hdr
->sh_entsize
;
9430 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9433 else if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9436 if (local_syms
!= NULL
9437 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9439 if (!info
->keep_memory
)
9442 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9447 /* Look for cases where we can change an indirect GOT access to
9448 a GOT relative or PC relative access, possibly reducing the
9449 number of GOT entries. */
9450 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9453 Elf_Internal_Shdr
*symtab_hdr
;
9454 Elf_Internal_Sym
*local_syms
;
9455 Elf_Internal_Rela
*relstart
, *rel
;
9458 if (!is_ppc64_elf (ibfd
))
9461 if (!ppc64_elf_tdata (ibfd
)->has_optrel
)
9464 sec
= ppc64_elf_tdata (ibfd
)->got
;
9467 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
9470 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9472 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9474 if (sec
->reloc_count
== 0
9475 || !ppc64_elf_section_data (sec
)->has_optrel
9476 || discarded_section (sec
))
9479 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9481 if (relstart
== NULL
)
9484 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9487 && elf_section_data (sec
)->relocs
!= relstart
)
9492 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9494 enum elf_ppc64_reloc_type r_type
;
9495 unsigned long r_symndx
;
9496 Elf_Internal_Sym
*sym
;
9498 struct elf_link_hash_entry
*h
;
9499 struct got_entry
*ent
;
9501 unsigned char buf
[8];
9503 enum {no_check
, check_lo
, check_ha
} insn_check
;
9505 r_type
= ELF64_R_TYPE (rel
->r_info
);
9509 insn_check
= no_check
;
9512 case R_PPC64_PLT16_HA
:
9513 case R_PPC64_GOT_TLSLD16_HA
:
9514 case R_PPC64_GOT_TLSGD16_HA
:
9515 case R_PPC64_GOT_TPREL16_HA
:
9516 case R_PPC64_GOT_DTPREL16_HA
:
9517 case R_PPC64_GOT16_HA
:
9518 case R_PPC64_TOC16_HA
:
9519 insn_check
= check_ha
;
9522 case R_PPC64_PLT16_LO
:
9523 case R_PPC64_PLT16_LO_DS
:
9524 case R_PPC64_GOT_TLSLD16_LO
:
9525 case R_PPC64_GOT_TLSGD16_LO
:
9526 case R_PPC64_GOT_TPREL16_LO_DS
:
9527 case R_PPC64_GOT_DTPREL16_LO_DS
:
9528 case R_PPC64_GOT16_LO
:
9529 case R_PPC64_GOT16_LO_DS
:
9530 case R_PPC64_TOC16_LO
:
9531 case R_PPC64_TOC16_LO_DS
:
9532 insn_check
= check_lo
;
9536 if (insn_check
!= no_check
)
9538 bfd_vma off
= rel
->r_offset
& ~3;
9540 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9543 insn
= bfd_get_32 (ibfd
, buf
);
9544 if (insn_check
== check_lo
9545 ? !ok_lo_toc_insn (insn
, r_type
)
9546 : ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9547 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9551 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9552 sprintf (str
, "%#08x", insn
);
9553 info
->callbacks
->einfo
9554 /* xgettext:c-format */
9555 (_("%H: got/toc optimization is not supported for"
9556 " %s instruction\n"),
9557 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9564 /* Note that we don't delete GOT entries for
9565 R_PPC64_GOT16_DS since we'd need a lot more
9566 analysis. For starters, the preliminary layout is
9567 before the GOT, PLT, dynamic sections and stubs are
9568 laid out. Then we'd need to allow for changes in
9569 distance between sections caused by alignment. */
9573 case R_PPC64_GOT16_HA
:
9574 case R_PPC64_GOT16_LO_DS
:
9575 case R_PPC64_GOT_PCREL34
:
9579 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9580 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9585 || sym_sec
->output_section
== NULL
9586 || discarded_section (sym_sec
))
9589 if ((h
? h
->type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
)
9592 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9596 val
= h
->root
.u
.def
.value
;
9598 val
= sym
->st_value
;
9599 val
+= rel
->r_addend
;
9600 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9602 /* Fudge factor to allow for the fact that the preliminary layout
9603 isn't exact. Reduce limits by this factor. */
9604 #define LIMIT_ADJUST(LIMIT) ((LIMIT) - (LIMIT) / 16)
9611 case R_PPC64_GOT16_HA
:
9612 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9613 >= LIMIT_ADJUST (0x100000000ULL
))
9616 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9617 rel
->r_offset
& ~3, 4))
9619 insn
= bfd_get_32 (ibfd
, buf
);
9620 if (((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9621 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9625 case R_PPC64_GOT16_LO_DS
:
9626 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9627 >= LIMIT_ADJUST (0x100000000ULL
))
9629 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9630 rel
->r_offset
& ~3, 4))
9632 insn
= bfd_get_32 (ibfd
, buf
);
9633 if ((insn
& (0x3fu
<< 26 | 0x3)) != 58u << 26 /* ld */)
9637 case R_PPC64_GOT_PCREL34
:
9639 pc
+= sec
->output_section
->vma
+ sec
->output_offset
;
9640 if (val
- pc
+ LIMIT_ADJUST (1ULL << 33)
9641 >= LIMIT_ADJUST (1ULL << 34))
9643 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9644 rel
->r_offset
& ~3, 8))
9646 insn
= bfd_get_32 (ibfd
, buf
);
9647 if ((insn
& (-1u << 18)) != ((1u << 26) | (1u << 20)))
9649 insn
= bfd_get_32 (ibfd
, buf
+ 4);
9650 if ((insn
& (0x3fu
<< 26)) != 57u << 26)
9660 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
9661 ent
= local_got_ents
[r_symndx
];
9663 for (; ent
!= NULL
; ent
= ent
->next
)
9664 if (ent
->addend
== rel
->r_addend
9665 && ent
->owner
== ibfd
9666 && ent
->tls_type
== 0)
9668 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
9669 ent
->got
.refcount
-= 1;
9672 if (elf_section_data (sec
)->relocs
!= relstart
)
9676 if (local_syms
!= NULL
9677 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9679 if (!info
->keep_memory
)
9682 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9689 /* Return true iff input section I references the TOC using
9690 instructions limited to +/-32k offsets. */
9693 ppc64_elf_has_small_toc_reloc (asection
*i
)
9695 return (is_ppc64_elf (i
->owner
)
9696 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9699 /* Allocate space for one GOT entry. */
9702 allocate_got (struct elf_link_hash_entry
*h
,
9703 struct bfd_link_info
*info
,
9704 struct got_entry
*gent
)
9706 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9707 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
9708 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9710 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9711 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9712 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9714 gent
->got
.offset
= got
->size
;
9715 got
->size
+= entsize
;
9717 if (h
->type
== STT_GNU_IFUNC
)
9719 htab
->elf
.irelplt
->size
+= rentsize
;
9720 htab
->got_reli_size
+= rentsize
;
9722 else if (((bfd_link_pic (info
)
9723 && !(gent
->tls_type
!= 0
9724 && bfd_link_executable (info
)
9725 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9726 || (htab
->elf
.dynamic_sections_created
9728 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9729 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9731 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9732 relgot
->size
+= rentsize
;
9736 /* This function merges got entries in the same toc group. */
9739 merge_got_entries (struct got_entry
**pent
)
9741 struct got_entry
*ent
, *ent2
;
9743 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9744 if (!ent
->is_indirect
)
9745 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9746 if (!ent2
->is_indirect
9747 && ent2
->addend
== ent
->addend
9748 && ent2
->tls_type
== ent
->tls_type
9749 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9751 ent2
->is_indirect
= true;
9752 ent2
->got
.ent
= ent
;
9756 /* If H is undefined, make it dynamic if that makes sense. */
9759 ensure_undef_dynamic (struct bfd_link_info
*info
,
9760 struct elf_link_hash_entry
*h
)
9762 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9764 if (htab
->dynamic_sections_created
9765 && ((info
->dynamic_undefined_weak
!= 0
9766 && h
->root
.type
== bfd_link_hash_undefweak
)
9767 || h
->root
.type
== bfd_link_hash_undefined
)
9770 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9771 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9775 /* Choose whether to use htab->iplt or htab->pltlocal rather than the
9776 usual htab->elf.splt section for a PLT entry. */
9779 bool use_local_plt (struct bfd_link_info
*info
,
9780 struct elf_link_hash_entry
*h
)
9784 || !elf_hash_table (info
)->dynamic_sections_created
);
9787 /* Allocate space in .plt, .got and associated reloc sections for
9791 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9793 struct bfd_link_info
*info
;
9794 struct ppc_link_hash_table
*htab
;
9796 struct ppc_link_hash_entry
*eh
;
9797 struct got_entry
**pgent
, *gent
;
9799 if (h
->root
.type
== bfd_link_hash_indirect
)
9802 info
= (struct bfd_link_info
*) inf
;
9803 htab
= ppc_hash_table (info
);
9807 eh
= ppc_elf_hash_entry (h
);
9808 /* Run through the TLS GD got entries first if we're changing them
9810 if ((eh
->tls_mask
& (TLS_TLS
| TLS_GDIE
)) == (TLS_TLS
| TLS_GDIE
))
9811 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9812 if (gent
->got
.refcount
> 0
9813 && (gent
->tls_type
& TLS_GD
) != 0)
9815 /* This was a GD entry that has been converted to TPREL. If
9816 there happens to be a TPREL entry we can use that one. */
9817 struct got_entry
*ent
;
9818 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9819 if (ent
->got
.refcount
> 0
9820 && (ent
->tls_type
& TLS_TPREL
) != 0
9821 && ent
->addend
== gent
->addend
9822 && ent
->owner
== gent
->owner
)
9824 gent
->got
.refcount
= 0;
9828 /* If not, then we'll be using our own TPREL entry. */
9829 if (gent
->got
.refcount
!= 0)
9830 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9833 /* Remove any list entry that won't generate a word in the GOT before
9834 we call merge_got_entries. Otherwise we risk merging to empty
9836 pgent
= &h
->got
.glist
;
9837 while ((gent
= *pgent
) != NULL
)
9838 if (gent
->got
.refcount
> 0)
9840 if ((gent
->tls_type
& TLS_LD
) != 0
9841 && SYMBOL_REFERENCES_LOCAL (info
, h
))
9843 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9844 *pgent
= gent
->next
;
9847 pgent
= &gent
->next
;
9850 *pgent
= gent
->next
;
9852 if (!htab
->do_multi_toc
)
9853 merge_got_entries (&h
->got
.glist
);
9855 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9856 if (!gent
->is_indirect
)
9858 /* Ensure we catch all the cases where this symbol should
9860 if (!ensure_undef_dynamic (info
, h
))
9863 if (!is_ppc64_elf (gent
->owner
))
9866 allocate_got (h
, info
, gent
);
9869 /* If no dynamic sections we can't have dynamic relocs, except for
9870 IFUNCs which are handled even in static executables. */
9871 if (!htab
->elf
.dynamic_sections_created
9872 && h
->type
!= STT_GNU_IFUNC
)
9873 h
->dyn_relocs
= NULL
;
9875 /* Discard relocs on undefined symbols that must be local. */
9876 else if (h
->root
.type
== bfd_link_hash_undefined
9877 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9878 h
->dyn_relocs
= NULL
;
9880 /* Also discard relocs on undefined weak syms with non-default
9881 visibility, or when dynamic_undefined_weak says so. */
9882 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9883 h
->dyn_relocs
= NULL
;
9885 if (h
->dyn_relocs
!= NULL
)
9887 struct elf_dyn_relocs
*p
, **pp
;
9889 /* In the shared -Bsymbolic case, discard space allocated for
9890 dynamic pc-relative relocs against symbols which turn out to
9891 be defined in regular objects. For the normal shared case,
9892 discard space for relocs that have become local due to symbol
9893 visibility changes. */
9894 if (bfd_link_pic (info
))
9896 /* Relocs that use pc_count are those that appear on a call
9897 insn, or certain REL relocs (see must_be_dyn_reloc) that
9898 can be generated via assembly. We want calls to
9899 protected symbols to resolve directly to the function
9900 rather than going via the plt. If people want function
9901 pointer comparisons to work as expected then they should
9902 avoid writing weird assembly. */
9903 if (SYMBOL_CALLS_LOCAL (info
, h
))
9905 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
9907 p
->count
-= p
->pc_count
;
9916 if (h
->dyn_relocs
!= NULL
)
9918 /* Ensure we catch all the cases where this symbol
9919 should be made dynamic. */
9920 if (!ensure_undef_dynamic (info
, h
))
9925 /* For a fixed position executable, discard space for
9926 relocs against symbols which are not dynamic. */
9927 else if (h
->type
!= STT_GNU_IFUNC
)
9929 if ((h
->dynamic_adjusted
9931 && h
->root
.type
== bfd_link_hash_undefweak
9932 && (info
->dynamic_undefined_weak
> 0
9933 || !_bfd_elf_readonly_dynrelocs (h
))))
9935 && !ELF_COMMON_DEF_P (h
))
9937 /* Ensure we catch all the cases where this symbol
9938 should be made dynamic. */
9939 if (!ensure_undef_dynamic (info
, h
))
9942 /* But if that didn't work out, discard dynamic relocs. */
9943 if (h
->dynindx
== -1)
9944 h
->dyn_relocs
= NULL
;
9947 h
->dyn_relocs
= NULL
;
9950 /* Finally, allocate space. */
9951 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9953 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9954 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9955 sreloc
= htab
->elf
.irelplt
;
9956 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9960 /* We might need a PLT entry when the symbol
9963 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
9964 d) has plt16 relocs and we are linking statically. */
9965 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
9966 || h
->type
== STT_GNU_IFUNC
9967 || (h
->needs_plt
&& h
->dynamic_adjusted
)
9970 && !htab
->elf
.dynamic_sections_created
9971 && !htab
->can_convert_all_inline_plt
9972 && (ppc_elf_hash_entry (h
)->tls_mask
9973 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
9975 struct plt_entry
*pent
;
9976 bool doneone
= false;
9977 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9978 if (pent
->plt
.refcount
> 0)
9980 if (!ensure_undef_dynamic (info
, h
))
9983 if (use_local_plt (info
, h
))
9985 if (h
->type
== STT_GNU_IFUNC
)
9988 pent
->plt
.offset
= s
->size
;
9989 s
->size
+= PLT_ENTRY_SIZE (htab
);
9990 s
= htab
->elf
.irelplt
;
9995 pent
->plt
.offset
= s
->size
;
9996 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9997 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
10002 /* If this is the first .plt entry, make room for the special
10004 s
= htab
->elf
.splt
;
10006 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
10008 pent
->plt
.offset
= s
->size
;
10010 /* Make room for this entry. */
10011 s
->size
+= PLT_ENTRY_SIZE (htab
);
10013 /* Make room for the .glink code. */
10016 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
10019 /* We need bigger stubs past index 32767. */
10020 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
10027 /* We also need to make an entry in the .rela.plt section. */
10028 s
= htab
->elf
.srelplt
;
10031 s
->size
+= sizeof (Elf64_External_Rela
);
10035 pent
->plt
.offset
= (bfd_vma
) -1;
10038 h
->plt
.plist
= NULL
;
10044 h
->plt
.plist
= NULL
;
10051 #define PPC_LO(v) ((v) & 0xffff)
10052 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10053 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10055 ((((v) & 0x3ffff0000ULL) << 16) | (v & 0xffff))
10056 #define HA34(v) ((v + (1ULL << 33)) >> 34)
10058 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
10059 to set up space for global entry stubs. These are put in glink,
10060 after the branch table. */
10063 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
10065 struct bfd_link_info
*info
;
10066 struct ppc_link_hash_table
*htab
;
10067 struct plt_entry
*pent
;
10070 if (h
->root
.type
== bfd_link_hash_indirect
)
10073 if (!h
->pointer_equality_needed
)
10076 if (h
->def_regular
)
10080 htab
= ppc_hash_table (info
);
10084 s
= htab
->global_entry
;
10085 plt
= htab
->elf
.splt
;
10086 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10087 if (pent
->plt
.offset
!= (bfd_vma
) -1
10088 && pent
->addend
== 0)
10090 /* For ELFv2, if this symbol is not defined in a regular file
10091 and we are not generating a shared library or pie, then we
10092 need to define the symbol in the executable on a call stub.
10093 This is to avoid text relocations. */
10094 bfd_vma off
, stub_align
, stub_off
, stub_size
;
10095 unsigned int align_power
;
10098 stub_off
= s
->size
;
10099 if (htab
->params
->plt_stub_align
>= 0)
10100 align_power
= htab
->params
->plt_stub_align
;
10102 align_power
= -htab
->params
->plt_stub_align
;
10103 /* Setting section alignment is delayed until we know it is
10104 non-empty. Otherwise the .text output section will be
10105 aligned at least to plt_stub_align even when no global
10106 entry stubs are needed. */
10107 if (s
->alignment_power
< align_power
)
10108 s
->alignment_power
= align_power
;
10109 stub_align
= (bfd_vma
) 1 << align_power
;
10110 if (htab
->params
->plt_stub_align
>= 0
10111 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
10112 - (stub_off
& -stub_align
))
10113 > ((stub_size
- 1) & -stub_align
)))
10114 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
10115 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
10116 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
10117 /* Note that for --plt-stub-align negative we have a possible
10118 dependency between stub offset and size. Break that
10119 dependency by assuming the max stub size when calculating
10120 the stub offset. */
10121 if (PPC_HA (off
) == 0)
10123 h
->root
.type
= bfd_link_hash_defined
;
10124 h
->root
.u
.def
.section
= s
;
10125 h
->root
.u
.def
.value
= stub_off
;
10126 s
->size
= stub_off
+ stub_size
;
10132 /* Set the sizes of the dynamic sections. */
10135 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10136 struct bfd_link_info
*info
)
10138 struct ppc_link_hash_table
*htab
;
10143 struct got_entry
*first_tlsld
;
10145 htab
= ppc_hash_table (info
);
10149 dynobj
= htab
->elf
.dynobj
;
10150 if (dynobj
== NULL
)
10153 if (htab
->elf
.dynamic_sections_created
)
10155 /* Set the contents of the .interp section to the interpreter. */
10156 if (bfd_link_executable (info
) && !info
->nointerp
)
10158 s
= bfd_get_linker_section (dynobj
, ".interp");
10161 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10162 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10166 /* Set up .got offsets for local syms, and space for local dynamic
10168 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10170 struct got_entry
**lgot_ents
;
10171 struct got_entry
**end_lgot_ents
;
10172 struct plt_entry
**local_plt
;
10173 struct plt_entry
**end_local_plt
;
10174 unsigned char *lgot_masks
;
10175 bfd_size_type locsymcount
;
10176 Elf_Internal_Shdr
*symtab_hdr
;
10178 if (!is_ppc64_elf (ibfd
))
10181 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10183 struct ppc_dyn_relocs
*p
;
10185 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10187 if (!bfd_is_abs_section (p
->sec
)
10188 && bfd_is_abs_section (p
->sec
->output_section
))
10190 /* Input section has been discarded, either because
10191 it is a copy of a linkonce section or due to
10192 linker script /DISCARD/, so we'll be discarding
10195 else if (p
->count
!= 0)
10197 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
10199 srel
= htab
->elf
.irelplt
;
10200 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10201 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10202 info
->flags
|= DF_TEXTREL
;
10207 lgot_ents
= elf_local_got_ents (ibfd
);
10211 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10212 locsymcount
= symtab_hdr
->sh_info
;
10213 end_lgot_ents
= lgot_ents
+ locsymcount
;
10214 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10215 end_local_plt
= local_plt
+ locsymcount
;
10216 lgot_masks
= (unsigned char *) end_local_plt
;
10217 s
= ppc64_elf_tdata (ibfd
)->got
;
10218 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10220 struct got_entry
**pent
, *ent
;
10223 while ((ent
= *pent
) != NULL
)
10224 if (ent
->got
.refcount
> 0)
10226 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10228 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10233 unsigned int ent_size
= 8;
10234 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10236 ent
->got
.offset
= s
->size
;
10237 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10242 s
->size
+= ent_size
;
10243 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10245 htab
->elf
.irelplt
->size
+= rel_size
;
10246 htab
->got_reli_size
+= rel_size
;
10248 else if (bfd_link_pic (info
)
10249 && !(ent
->tls_type
!= 0
10250 && bfd_link_executable (info
)))
10252 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10253 srel
->size
+= rel_size
;
10262 /* Allocate space for plt calls to local syms. */
10263 lgot_masks
= (unsigned char *) end_local_plt
;
10264 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10266 struct plt_entry
*ent
;
10268 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10269 if (ent
->plt
.refcount
> 0)
10271 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10273 s
= htab
->elf
.iplt
;
10274 ent
->plt
.offset
= s
->size
;
10275 s
->size
+= PLT_ENTRY_SIZE (htab
);
10276 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10278 else if (htab
->can_convert_all_inline_plt
10279 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10280 ent
->plt
.offset
= (bfd_vma
) -1;
10283 s
= htab
->pltlocal
;
10284 ent
->plt
.offset
= s
->size
;
10285 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10286 if (bfd_link_pic (info
))
10287 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
10291 ent
->plt
.offset
= (bfd_vma
) -1;
10295 /* Allocate global sym .plt and .got entries, and space for global
10296 sym dynamic relocs. */
10297 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10299 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10300 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10302 first_tlsld
= NULL
;
10303 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10305 struct got_entry
*ent
;
10307 if (!is_ppc64_elf (ibfd
))
10310 ent
= ppc64_tlsld_got (ibfd
);
10311 if (ent
->got
.refcount
> 0)
10313 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10315 ent
->is_indirect
= true;
10316 ent
->got
.ent
= first_tlsld
;
10320 if (first_tlsld
== NULL
)
10322 s
= ppc64_elf_tdata (ibfd
)->got
;
10323 ent
->got
.offset
= s
->size
;
10326 if (bfd_link_dll (info
))
10328 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10329 srel
->size
+= sizeof (Elf64_External_Rela
);
10334 ent
->got
.offset
= (bfd_vma
) -1;
10337 /* We now have determined the sizes of the various dynamic sections.
10338 Allocate memory for them. */
10340 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10342 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10345 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
10346 /* These haven't been allocated yet; don't strip. */
10348 else if (s
== htab
->elf
.sgot
10349 || s
== htab
->elf
.splt
10350 || s
== htab
->elf
.iplt
10351 || s
== htab
->pltlocal
10352 || s
== htab
->glink
10353 || s
== htab
->global_entry
10354 || s
== htab
->elf
.sdynbss
10355 || s
== htab
->elf
.sdynrelro
)
10357 /* Strip this section if we don't need it; see the
10360 else if (s
== htab
->glink_eh_frame
)
10362 if (!bfd_is_abs_section (s
->output_section
))
10363 /* Not sized yet. */
10366 else if (startswith (s
->name
, ".rela"))
10370 if (s
!= htab
->elf
.srelplt
)
10373 /* We use the reloc_count field as a counter if we need
10374 to copy relocs into the output file. */
10375 s
->reloc_count
= 0;
10380 /* It's not one of our sections, so don't allocate space. */
10386 /* If we don't need this section, strip it from the
10387 output file. This is mostly to handle .rela.bss and
10388 .rela.plt. We must create both sections in
10389 create_dynamic_sections, because they must be created
10390 before the linker maps input sections to output
10391 sections. The linker does that before
10392 adjust_dynamic_symbol is called, and it is that
10393 function which decides whether anything needs to go
10394 into these sections. */
10395 s
->flags
|= SEC_EXCLUDE
;
10399 if (bfd_is_abs_section (s
->output_section
))
10400 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10403 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10406 /* Allocate memory for the section contents. We use bfd_zalloc
10407 here in case unused entries are not reclaimed before the
10408 section's contents are written out. This should not happen,
10409 but this way if it does we get a R_PPC64_NONE reloc in .rela
10410 sections instead of garbage.
10411 We also rely on the section contents being zero when writing
10412 the GOT and .dynrelro. */
10413 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10414 if (s
->contents
== NULL
)
10418 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10420 if (!is_ppc64_elf (ibfd
))
10423 s
= ppc64_elf_tdata (ibfd
)->got
;
10424 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10427 s
->flags
|= SEC_EXCLUDE
;
10430 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10431 if (s
->contents
== NULL
)
10435 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10439 s
->flags
|= SEC_EXCLUDE
;
10442 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10443 if (s
->contents
== NULL
)
10446 s
->reloc_count
= 0;
10451 if (htab
->elf
.dynamic_sections_created
)
10455 /* Add some entries to the .dynamic section. We fill in the
10456 values later, in ppc64_elf_finish_dynamic_sections, but we
10457 must add the entries now so that we get the correct size for
10458 the .dynamic section. The DT_DEBUG entry is filled in by the
10459 dynamic linker and used by the debugger. */
10460 #define add_dynamic_entry(TAG, VAL) \
10461 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10463 if (bfd_link_executable (info
))
10465 if (!add_dynamic_entry (DT_DEBUG
, 0))
10469 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10471 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10472 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10473 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10474 || !add_dynamic_entry (DT_JMPREL
, 0)
10475 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10479 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10481 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10482 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10486 tls_opt
= (htab
->params
->tls_get_addr_opt
10487 && ((htab
->tls_get_addr_fd
!= NULL
10488 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
)
10489 || (htab
->tga_desc_fd
!= NULL
10490 && htab
->tga_desc_fd
->elf
.plt
.plist
!= NULL
)));
10491 if (tls_opt
|| !htab
->opd_abi
)
10493 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10499 if (!add_dynamic_entry (DT_RELA
, 0)
10500 || !add_dynamic_entry (DT_RELASZ
, 0)
10501 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10504 /* If any dynamic relocs apply to a read-only section,
10505 then we need a DT_TEXTREL entry. */
10506 if ((info
->flags
& DF_TEXTREL
) == 0)
10507 elf_link_hash_traverse (&htab
->elf
,
10508 _bfd_elf_maybe_set_textrel
, info
);
10510 if ((info
->flags
& DF_TEXTREL
) != 0)
10512 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10517 #undef add_dynamic_entry
10522 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10525 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10527 if (h
->plt
.plist
!= NULL
10529 && !h
->pointer_equality_needed
)
10532 return _bfd_elf_hash_symbol (h
);
10535 /* Determine the type of stub needed, if any, for a call. */
10537 static inline enum ppc_stub_main_type
10538 ppc_type_of_stub (asection
*input_sec
,
10539 const Elf_Internal_Rela
*rel
,
10540 struct ppc_link_hash_entry
**hash
,
10541 struct plt_entry
**plt_ent
,
10542 bfd_vma destination
,
10543 unsigned long local_off
)
10545 struct ppc_link_hash_entry
*h
= *hash
;
10547 bfd_vma branch_offset
;
10548 bfd_vma max_branch_offset
;
10549 enum elf_ppc64_reloc_type r_type
;
10553 struct plt_entry
*ent
;
10554 struct ppc_link_hash_entry
*fdh
= h
;
10556 && h
->oh
->is_func_descriptor
)
10558 fdh
= ppc_follow_link (h
->oh
);
10562 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10563 if (ent
->addend
== rel
->r_addend
10564 && ent
->plt
.offset
!= (bfd_vma
) -1)
10567 return ppc_stub_plt_call
;
10570 /* Here, we know we don't have a plt entry. If we don't have a
10571 either a defined function descriptor or a defined entry symbol
10572 in a regular object file, then it is pointless trying to make
10573 any other type of stub. */
10574 if (!is_static_defined (&fdh
->elf
)
10575 && !is_static_defined (&h
->elf
))
10576 return ppc_stub_none
;
10578 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10580 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10581 struct plt_entry
**local_plt
= (struct plt_entry
**)
10582 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10583 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10585 if (local_plt
[r_symndx
] != NULL
)
10587 struct plt_entry
*ent
;
10589 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10590 if (ent
->addend
== rel
->r_addend
10591 && ent
->plt
.offset
!= (bfd_vma
) -1)
10594 return ppc_stub_plt_call
;
10599 /* Determine where the call point is. */
10600 location
= (input_sec
->output_offset
10601 + input_sec
->output_section
->vma
10604 branch_offset
= destination
- location
;
10605 r_type
= ELF64_R_TYPE (rel
->r_info
);
10607 /* Determine if a long branch stub is needed. */
10608 max_branch_offset
= 1 << 25;
10609 if (r_type
== R_PPC64_REL14
10610 || r_type
== R_PPC64_REL14_BRTAKEN
10611 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10612 max_branch_offset
= 1 << 15;
10614 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10615 /* We need a stub. Figure out whether a long_branch or plt_branch
10616 is needed later. */
10617 return ppc_stub_long_branch
;
10619 return ppc_stub_none
;
10622 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
10623 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
10628 . lis %r12,xxx-1b@highest
10629 . ori %r12,%r12,xxx-1b@higher
10630 . sldi %r12,%r12,32
10631 . oris %r12,%r12,xxx-1b@high
10632 . ori %r12,%r12,xxx-1b@l
10633 . add/ldx %r12,%r11,%r12 */
10636 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bool load
)
10638 bfd_put_32 (abfd
, MFLR_R12
, p
);
10640 bfd_put_32 (abfd
, BCL_20_31
, p
);
10642 bfd_put_32 (abfd
, MFLR_R11
, p
);
10644 bfd_put_32 (abfd
, MTLR_R12
, p
);
10646 if (off
+ 0x8000 < 0x10000)
10649 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
10651 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
10654 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10656 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
10659 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
10661 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
10666 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10668 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
10673 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
10675 if (((off
>> 32) & 0xffff) != 0)
10677 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
10681 if (((off
>> 32) & 0xffffffffULL
) != 0)
10683 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
10686 if (PPC_HI (off
) != 0)
10688 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
10691 if (PPC_LO (off
) != 0)
10693 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
10697 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10699 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10705 static unsigned int
10706 size_offset (bfd_vma off
)
10709 if (off
+ 0x8000 < 0x10000)
10711 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10715 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10720 if (((off
>> 32) & 0xffff) != 0)
10723 if (((off
>> 32) & 0xffffffffULL
) != 0)
10725 if (PPC_HI (off
) != 0)
10727 if (PPC_LO (off
) != 0)
10734 static unsigned int
10735 num_relocs_for_offset (bfd_vma off
)
10737 unsigned int num_rel
;
10738 if (off
+ 0x8000 < 0x10000)
10740 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10745 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
10746 && ((off
>> 32) & 0xffff) != 0)
10748 if (PPC_HI (off
) != 0)
10750 if (PPC_LO (off
) != 0)
10756 static Elf_Internal_Rela
*
10757 emit_relocs_for_offset (struct bfd_link_info
*info
, Elf_Internal_Rela
*r
,
10758 bfd_vma roff
, bfd_vma targ
, bfd_vma off
)
10760 bfd_vma relative_targ
= targ
- (roff
- 8);
10761 if (bfd_big_endian (info
->output_bfd
))
10763 r
->r_offset
= roff
;
10764 r
->r_addend
= relative_targ
+ roff
;
10765 if (off
+ 0x8000 < 0x10000)
10766 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16
);
10767 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10769 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HA
);
10772 r
->r_offset
= roff
;
10773 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10774 r
->r_addend
= relative_targ
+ roff
;
10778 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10779 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10782 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHEST
);
10783 if (((off
>> 32) & 0xffff) != 0)
10787 r
->r_offset
= roff
;
10788 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10789 r
->r_addend
= relative_targ
+ roff
;
10792 if (((off
>> 32) & 0xffffffffULL
) != 0)
10794 if (PPC_HI (off
) != 0)
10798 r
->r_offset
= roff
;
10799 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGH
);
10800 r
->r_addend
= relative_targ
+ roff
;
10802 if (PPC_LO (off
) != 0)
10806 r
->r_offset
= roff
;
10807 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10808 r
->r_addend
= relative_targ
+ roff
;
10815 build_power10_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, int odd
,
10819 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10824 bfd_put_32 (abfd
, NOP
, p
);
10830 insn
= PADDI_R12_PC
;
10832 bfd_put_32 (abfd
, insn
>> 32, p
);
10834 bfd_put_32 (abfd
, insn
, p
);
10836 /* The minimum value for paddi is -0x200000000. The minimum value
10837 for li is -0x8000, which when shifted by 34 and added gives a
10838 minimum value of -0x2000200000000. The maximum value is
10839 0x1ffffffff+0x7fff<<34 which is 0x2000200000000-1. */
10840 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10843 bfd_put_32 (abfd
, LI_R11_0
| (HA34 (off
) & 0xffff), p
);
10847 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10850 insn
= PADDI_R12_PC
| D34 (off
);
10851 bfd_put_32 (abfd
, insn
>> 32, p
);
10853 bfd_put_32 (abfd
, insn
, p
);
10857 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10861 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10863 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10868 bfd_put_32 (abfd
, LIS_R11
| ((HA34 (off
) >> 16) & 0x3fff), p
);
10870 bfd_put_32 (abfd
, ORI_R11_R11_0
| (HA34 (off
) & 0xffff), p
);
10874 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10877 insn
= PADDI_R12_PC
| D34 (off
);
10878 bfd_put_32 (abfd
, insn
>> 32, p
);
10880 bfd_put_32 (abfd
, insn
, p
);
10884 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10888 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10890 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10896 static unsigned int
10897 size_power10_offset (bfd_vma off
, int odd
)
10899 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10901 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10907 static unsigned int
10908 num_relocs_for_power10_offset (bfd_vma off
, int odd
)
10910 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10912 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10918 static Elf_Internal_Rela
*
10919 emit_relocs_for_power10_offset (struct bfd_link_info
*info
,
10920 Elf_Internal_Rela
*r
, bfd_vma roff
,
10921 bfd_vma targ
, bfd_vma off
, int odd
)
10923 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10925 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10927 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
10928 r
->r_offset
= roff
+ d_offset
;
10929 r
->r_addend
= targ
+ 8 - odd
- d_offset
;
10930 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
10936 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
10937 r
->r_offset
= roff
+ d_offset
;
10938 r
->r_addend
= targ
+ 8 + odd
- d_offset
;
10939 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHESTA34
);
10942 r
->r_offset
= roff
+ d_offset
;
10943 r
->r_addend
= targ
+ 4 + odd
- d_offset
;
10944 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
10948 r
->r_offset
= roff
;
10949 r
->r_addend
= targ
;
10950 r
->r_info
= ELF64_R_INFO (0, R_PPC64_PCREL34
);
10954 /* Emit .eh_frame opcode to advance pc by DELTA. */
10957 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
10961 *eh
++ = DW_CFA_advance_loc
+ delta
;
10962 else if (delta
< 256)
10964 *eh
++ = DW_CFA_advance_loc1
;
10967 else if (delta
< 65536)
10969 *eh
++ = DW_CFA_advance_loc2
;
10970 bfd_put_16 (abfd
, delta
, eh
);
10975 *eh
++ = DW_CFA_advance_loc4
;
10976 bfd_put_32 (abfd
, delta
, eh
);
10982 /* Size of required .eh_frame opcode to advance pc by DELTA. */
10984 static unsigned int
10985 eh_advance_size (unsigned int delta
)
10987 if (delta
< 64 * 4)
10988 /* DW_CFA_advance_loc+[1..63]. */
10990 if (delta
< 256 * 4)
10991 /* DW_CFA_advance_loc1, byte. */
10993 if (delta
< 65536 * 4)
10994 /* DW_CFA_advance_loc2, 2 bytes. */
10996 /* DW_CFA_advance_loc4, 4 bytes. */
11000 /* With power7 weakly ordered memory model, it is possible for ld.so
11001 to update a plt entry in one thread and have another thread see a
11002 stale zero toc entry. To avoid this we need some sort of acquire
11003 barrier in the call stub. One solution is to make the load of the
11004 toc word seem to appear to depend on the load of the function entry
11005 word. Another solution is to test for r2 being zero, and branch to
11006 the appropriate glink entry if so.
11008 . fake dep barrier compare
11009 . ld 12,xxx(2) ld 12,xxx(2)
11010 . mtctr 12 mtctr 12
11011 . xor 11,12,12 ld 2,xxx+8(2)
11012 . add 2,2,11 cmpldi 2,0
11013 . ld 2,xxx+8(2) bnectr+
11014 . bctr b <glink_entry>
11016 The solution involving the compare turns out to be faster, so
11017 that's what we use unless the branch won't reach. */
11019 #define ALWAYS_USE_FAKE_DEP 0
11020 #define ALWAYS_EMIT_R2SAVE 0
11022 static inline unsigned int
11023 plt_stub_size (struct ppc_link_hash_table
*htab
,
11024 struct ppc_stub_hash_entry
*stub_entry
,
11030 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11032 size
= 8 + size_power10_offset (off
, odd
);
11033 if (stub_entry
->type
.r2save
)
11036 else if (stub_entry
->type
.sub
== ppc_stub_p9notoc
)
11038 size
= 8 + size_offset (off
- 8);
11039 if (stub_entry
->type
.r2save
)
11045 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11047 if (PPC_HA (off
) != 0)
11052 if (htab
->params
->plt_static_chain
)
11054 if (htab
->params
->plt_thread_safe
11055 && htab
->elf
.dynamic_sections_created
11056 && stub_entry
->h
!= NULL
11057 && stub_entry
->h
->elf
.dynindx
!= -1)
11059 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
)
11064 if (stub_entry
->h
!= NULL
11065 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11066 && htab
->params
->tls_get_addr_opt
)
11068 if (!htab
->params
->no_tls_get_addr_regsave
)
11071 if (stub_entry
->type
.r2save
)
11077 if (stub_entry
->type
.r2save
)
11084 /* Depending on the sign of plt_stub_align:
11085 If positive, return the padding to align to a 2**plt_stub_align
11087 If negative, if this stub would cross fewer 2**plt_stub_align
11088 boundaries if we align, then return the padding needed to do so. */
11090 static inline unsigned int
11091 plt_stub_pad (struct ppc_link_hash_table
*htab
,
11092 struct ppc_stub_hash_entry
*stub_entry
,
11097 unsigned stub_size
;
11098 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
11100 if (htab
->params
->plt_stub_align
>= 0)
11102 stub_align
= 1 << htab
->params
->plt_stub_align
;
11103 if ((stub_off
& (stub_align
- 1)) != 0)
11104 return stub_align
- (stub_off
& (stub_align
- 1));
11108 stub_align
= 1 << -htab
->params
->plt_stub_align
;
11109 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
, odd
);
11110 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
11111 > ((stub_size
- 1) & -stub_align
))
11112 return stub_align
- (stub_off
& (stub_align
- 1));
11116 /* Build a toc using .plt call stub. */
11118 static inline bfd_byte
*
11119 build_plt_stub (struct ppc_link_hash_table
*htab
,
11120 struct ppc_stub_hash_entry
*stub_entry
,
11121 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
11123 bfd
*obfd
= htab
->params
->stub_bfd
;
11124 bool plt_load_toc
= htab
->opd_abi
;
11125 bool plt_static_chain
= htab
->params
->plt_static_chain
;
11126 bool plt_thread_safe
= (htab
->params
->plt_thread_safe
11127 && htab
->elf
.dynamic_sections_created
11128 && stub_entry
->h
!= NULL
11129 && stub_entry
->h
->elf
.dynindx
!= -1);
11130 bool use_fake_dep
= plt_thread_safe
;
11131 bfd_vma cmp_branch_off
= 0;
11133 if (!ALWAYS_USE_FAKE_DEP
11136 && !(stub_entry
->h
!= NULL
11137 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11138 && htab
->params
->tls_get_addr_opt
))
11140 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11141 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
11142 / PLT_ENTRY_SIZE (htab
));
11143 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
11146 if (pltindex
> 32768)
11147 glinkoff
+= (pltindex
- 32768) * 4;
11149 + htab
->glink
->output_offset
11150 + htab
->glink
->output_section
->vma
);
11151 from
= (p
- stub_entry
->group
->stub_sec
->contents
11152 + 4 * (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11153 + 4 * (PPC_HA (offset
) != 0)
11154 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
11155 != PPC_HA (offset
))
11156 + 4 * (plt_static_chain
!= 0)
11158 + stub_entry
->group
->stub_sec
->output_offset
11159 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11160 cmp_branch_off
= to
- from
;
11161 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
11164 if (PPC_HA (offset
) != 0)
11168 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11169 r
[0].r_offset
+= 4;
11170 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11171 r
[1].r_offset
= r
[0].r_offset
+ 4;
11172 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11173 r
[1].r_addend
= r
[0].r_addend
;
11176 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11178 r
[2].r_offset
= r
[1].r_offset
+ 4;
11179 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
11180 r
[2].r_addend
= r
[0].r_addend
;
11184 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
11185 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11186 r
[2].r_addend
= r
[0].r_addend
+ 8;
11187 if (plt_static_chain
)
11189 r
[3].r_offset
= r
[2].r_offset
+ 4;
11190 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11191 r
[3].r_addend
= r
[0].r_addend
+ 16;
11196 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11197 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11200 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
11201 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
11205 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
11206 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
11209 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11211 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
11214 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11219 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
11220 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
11222 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
11223 if (plt_static_chain
)
11224 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
11231 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11232 r
[0].r_offset
+= 4;
11233 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11236 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11238 r
[1].r_offset
= r
[0].r_offset
+ 4;
11239 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
11240 r
[1].r_addend
= r
[0].r_addend
;
11244 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
11245 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11246 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
11247 if (plt_static_chain
)
11249 r
[2].r_offset
= r
[1].r_offset
+ 4;
11250 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11251 r
[2].r_addend
= r
[0].r_addend
+ 8;
11256 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11257 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11258 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
11260 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11262 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
11265 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11270 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
11271 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
11273 if (plt_static_chain
)
11274 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
11275 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
11278 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
11280 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
11281 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
11282 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
11285 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
11289 /* Build a special .plt call stub for __tls_get_addr. */
11291 #define LD_R0_0R3 0xe8030000
11292 #define LD_R12_0R3 0xe9830000
11293 #define MR_R0_R3 0x7c601b78
11294 #define CMPDI_R0_0 0x2c200000
11295 #define ADD_R3_R12_R13 0x7c6c6a14
11296 #define BEQLR 0x4d820020
11297 #define MR_R3_R0 0x7c030378
11298 #define BCTRL 0x4e800421
11301 build_tls_get_addr_head (struct ppc_link_hash_table
*htab
,
11302 struct ppc_stub_hash_entry
*stub_entry
,
11305 bfd
*obfd
= htab
->params
->stub_bfd
;
11307 bfd_put_32 (obfd
, LD_R0_0R3
+ 0, p
), p
+= 4;
11308 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
11309 bfd_put_32 (obfd
, CMPDI_R0_0
, p
), p
+= 4;
11310 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
11311 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
11312 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
11313 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
11315 if (!htab
->params
->no_tls_get_addr_regsave
)
11316 p
= tls_get_addr_prologue (obfd
, p
, htab
);
11317 else if (stub_entry
->type
.r2save
)
11319 bfd_put_32 (obfd
, MFLR_R0
, p
);
11321 bfd_put_32 (obfd
, STD_R0_0R1
+ STK_LINKER (htab
), p
);
11328 build_tls_get_addr_tail (struct ppc_link_hash_table
*htab
,
11329 struct ppc_stub_hash_entry
*stub_entry
,
11333 bfd
*obfd
= htab
->params
->stub_bfd
;
11335 if (!htab
->params
->no_tls_get_addr_regsave
)
11337 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11339 if (stub_entry
->type
.r2save
)
11341 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11344 p
= tls_get_addr_epilogue (obfd
, p
, htab
);
11346 else if (stub_entry
->type
.r2save
)
11348 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11350 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11352 bfd_put_32 (obfd
, LD_R0_0R1
+ STK_LINKER (htab
), p
);
11354 bfd_put_32 (obfd
, MTLR_R0
, p
);
11356 bfd_put_32 (obfd
, BLR
, p
);
11360 if (htab
->glink_eh_frame
!= NULL
11361 && htab
->glink_eh_frame
->size
!= 0)
11363 bfd_byte
*base
, *eh
;
11365 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
11366 eh
= base
+ stub_entry
->group
->eh_size
;
11368 if (!htab
->params
->no_tls_get_addr_regsave
)
11370 unsigned int cfa_updt
, delta
, i
;
11372 /* After the bctrl, lr has been modified so we need to emit
11373 .eh_frame info saying the return address is on the stack. In
11374 fact we must put the EH info at or before the call rather
11375 than after it, because the EH info for a call needs to be
11376 specified by that point.
11377 See libgcc/unwind-dw2.c execute_cfa_program.
11378 Any stack pointer update must be described immediately after
11379 the instruction making the change, and since the stdu occurs
11380 after saving regs we put all the reg saves and the cfa
11382 cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
11383 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
11384 stub_entry
->group
->lr_restore
11385 = stub_entry
->stub_offset
+ (p
- loc
) - 4;
11386 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11387 *eh
++ = DW_CFA_def_cfa_offset
;
11395 *eh
++ = DW_CFA_offset_extended_sf
;
11397 *eh
++ = (-16 / 8) & 0x7f;
11398 for (i
= 4; i
< 12; i
++)
11400 *eh
++ = DW_CFA_offset
+ i
;
11401 *eh
++ = (htab
->opd_abi
? 13 : 12) - i
;
11403 *eh
++ = (DW_CFA_advance_loc
11404 + (stub_entry
->group
->lr_restore
- 8 - cfa_updt
) / 4);
11405 *eh
++ = DW_CFA_def_cfa_offset
;
11407 for (i
= 4; i
< 12; i
++)
11408 *eh
++ = DW_CFA_restore
+ i
;
11409 *eh
++ = DW_CFA_advance_loc
+ 2;
11410 *eh
++ = DW_CFA_restore_extended
;
11412 stub_entry
->group
->eh_size
= eh
- base
;
11414 else if (stub_entry
->type
.r2save
)
11416 unsigned int lr_used
, delta
;
11418 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
11419 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11420 stub_entry
->group
->lr_restore
= lr_used
+ 16;
11421 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11422 *eh
++ = DW_CFA_offset_extended_sf
;
11424 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
11425 *eh
++ = DW_CFA_advance_loc
+ 4;
11426 *eh
++ = DW_CFA_restore_extended
;
11428 stub_entry
->group
->eh_size
= eh
- base
;
11434 static Elf_Internal_Rela
*
11435 get_relocs (asection
*sec
, int count
)
11437 Elf_Internal_Rela
*relocs
;
11438 struct bfd_elf_section_data
*elfsec_data
;
11440 elfsec_data
= elf_section_data (sec
);
11441 relocs
= elfsec_data
->relocs
;
11442 if (relocs
== NULL
)
11444 bfd_size_type relsize
;
11445 relsize
= sec
->reloc_count
* sizeof (*relocs
);
11446 relocs
= bfd_alloc (sec
->owner
, relsize
);
11447 if (relocs
== NULL
)
11449 elfsec_data
->relocs
= relocs
;
11450 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
11451 sizeof (Elf_Internal_Shdr
));
11452 if (elfsec_data
->rela
.hdr
== NULL
)
11454 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
11455 * sizeof (Elf64_External_Rela
));
11456 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
11457 sec
->reloc_count
= 0;
11459 relocs
+= sec
->reloc_count
;
11460 sec
->reloc_count
+= count
;
11464 /* Convert the relocs R[0] thru R[-NUM_REL+1], which are all no-symbol
11465 forms, to the equivalent relocs against the global symbol given by
11469 use_global_in_relocs (struct ppc_link_hash_table
*htab
,
11470 struct ppc_stub_hash_entry
*stub_entry
,
11471 Elf_Internal_Rela
*r
, unsigned int num_rel
)
11473 struct elf_link_hash_entry
**hashes
;
11474 unsigned long symndx
;
11475 struct ppc_link_hash_entry
*h
;
11478 /* Relocs are always against symbols in their own object file. Fake
11479 up global sym hashes for the stub bfd (which has no symbols). */
11480 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
11481 if (hashes
== NULL
)
11483 bfd_size_type hsize
;
11485 /* When called the first time, stub_globals will contain the
11486 total number of symbols seen during stub sizing. After
11487 allocating, stub_globals is used as an index to fill the
11489 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
11490 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
11491 if (hashes
== NULL
)
11493 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
11494 htab
->stub_globals
= 1;
11496 symndx
= htab
->stub_globals
++;
11498 hashes
[symndx
] = &h
->elf
;
11499 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
11500 h
= ppc_follow_link (h
->oh
);
11501 BFD_ASSERT (h
->elf
.root
.type
== bfd_link_hash_defined
11502 || h
->elf
.root
.type
== bfd_link_hash_defweak
);
11503 symval
= defined_sym_val (&h
->elf
);
11504 while (num_rel
-- != 0)
11506 r
->r_info
= ELF64_R_INFO (symndx
, ELF64_R_TYPE (r
->r_info
));
11507 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11509 /* H is an opd symbol. The addend must be zero, and the
11510 branch reloc is the only one we can convert. */
11515 r
->r_addend
-= symval
;
11522 get_r2off (struct bfd_link_info
*info
,
11523 struct ppc_stub_hash_entry
*stub_entry
)
11525 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11526 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
11530 /* Support linking -R objects. Get the toc pointer from the
11533 if (!htab
->opd_abi
)
11535 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
11536 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
11538 if (strcmp (opd
->name
, ".opd") != 0
11539 || opd
->reloc_count
!= 0)
11541 info
->callbacks
->einfo
11542 (_("%P: cannot find opd entry toc for `%pT'\n"),
11543 stub_entry
->h
->elf
.root
.root
.string
);
11544 bfd_set_error (bfd_error_bad_value
);
11545 return (bfd_vma
) -1;
11547 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
11548 return (bfd_vma
) -1;
11549 r2off
= bfd_get_64 (opd
->owner
, buf
);
11550 r2off
-= elf_gp (info
->output_bfd
);
11552 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
11557 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11559 struct ppc_stub_hash_entry
*stub_entry
;
11560 struct ppc_branch_hash_entry
*br_entry
;
11561 struct bfd_link_info
*info
;
11562 struct ppc_link_hash_table
*htab
;
11565 bfd_byte
*p
, *relp
;
11567 Elf_Internal_Rela
*r
;
11573 /* Massage our args to the form they really have. */
11574 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11577 /* Fail if the target section could not be assigned to an output
11578 section. The user should fix his linker script. */
11579 if (stub_entry
->target_section
!= NULL
11580 && stub_entry
->target_section
->output_section
== NULL
11581 && info
->non_contiguous_regions
)
11582 info
->callbacks
->einfo (_("%F%P: Could not assign '%pA' to an output section. "
11583 "Retry without --enable-non-contiguous-regions.\n"),
11584 stub_entry
->target_section
);
11586 /* Same for the group. */
11587 if (stub_entry
->group
->stub_sec
!= NULL
11588 && stub_entry
->group
->stub_sec
->output_section
== NULL
11589 && info
->non_contiguous_regions
)
11590 info
->callbacks
->einfo (_("%F%P: Could not assign group %pA target %pA to an "
11591 "output section. Retry without "
11592 "--enable-non-contiguous-regions.\n"),
11593 stub_entry
->group
->stub_sec
,
11594 stub_entry
->target_section
);
11596 htab
= ppc_hash_table (info
);
11600 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
11601 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
11603 htab
->stub_count
[stub_entry
->type
.main
- 1] += 1;
11604 if (stub_entry
->type
.main
== ppc_stub_long_branch
11605 && stub_entry
->type
.sub
== ppc_stub_toc
)
11607 /* Branches are relative. This is where we are going to. */
11608 targ
= (stub_entry
->target_value
11609 + stub_entry
->target_section
->output_offset
11610 + stub_entry
->target_section
->output_section
->vma
);
11611 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11613 /* And this is where we are coming from. */
11614 off
= (stub_entry
->stub_offset
11615 + stub_entry
->group
->stub_sec
->output_offset
11616 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11620 obfd
= htab
->params
->stub_bfd
;
11621 if (stub_entry
->type
.r2save
)
11623 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11625 if (r2off
== (bfd_vma
) -1)
11627 htab
->stub_error
= true;
11630 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11632 if (PPC_HA (r2off
) != 0)
11634 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11637 if (PPC_LO (r2off
) != 0)
11639 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11644 bfd_put_32 (obfd
, B_DOT
| (off
& 0x3fffffc), p
);
11647 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11650 (_("long branch stub `%s' offset overflow"),
11651 stub_entry
->root
.string
);
11652 htab
->stub_error
= true;
11656 if (info
->emitrelocations
)
11658 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11661 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11662 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11663 r
->r_addend
= targ
;
11664 if (stub_entry
->h
!= NULL
11665 && !use_global_in_relocs (htab
, stub_entry
, r
, 1))
11669 else if (stub_entry
->type
.main
== ppc_stub_plt_branch
11670 && stub_entry
->type
.sub
== ppc_stub_toc
)
11672 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11673 stub_entry
->root
.string
+ 9,
11675 if (br_entry
== NULL
)
11677 _bfd_error_handler (_("can't find branch stub `%s'"),
11678 stub_entry
->root
.string
);
11679 htab
->stub_error
= true;
11683 targ
= (stub_entry
->target_value
11684 + stub_entry
->target_section
->output_offset
11685 + stub_entry
->target_section
->output_section
->vma
);
11686 if (!stub_entry
->type
.r2save
)
11687 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11689 bfd_put_64 (htab
->brlt
->owner
, targ
,
11690 htab
->brlt
->contents
+ br_entry
->offset
);
11692 if (br_entry
->iter
== htab
->stub_iteration
)
11694 br_entry
->iter
= 0;
11696 if (htab
->relbrlt
!= NULL
)
11698 /* Create a reloc for the branch lookup table entry. */
11699 Elf_Internal_Rela rela
;
11702 rela
.r_offset
= (br_entry
->offset
11703 + htab
->brlt
->output_offset
11704 + htab
->brlt
->output_section
->vma
);
11705 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11706 rela
.r_addend
= targ
;
11708 rl
= htab
->relbrlt
->contents
;
11709 rl
+= (htab
->relbrlt
->reloc_count
++
11710 * sizeof (Elf64_External_Rela
));
11711 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11713 else if (info
->emitrelocations
)
11715 r
= get_relocs (htab
->brlt
, 1);
11718 /* brlt, being SEC_LINKER_CREATED does not go through the
11719 normal reloc processing. Symbols and offsets are not
11720 translated from input file to output file form, so
11721 set up the offset per the output file. */
11722 r
->r_offset
= (br_entry
->offset
11723 + htab
->brlt
->output_offset
11724 + htab
->brlt
->output_section
->vma
);
11725 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11726 r
->r_addend
= targ
;
11730 targ
= (br_entry
->offset
11731 + htab
->brlt
->output_offset
11732 + htab
->brlt
->output_section
->vma
);
11734 off
= (elf_gp (info
->output_bfd
)
11735 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11738 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11740 info
->callbacks
->einfo
11741 (_("%P: linkage table error against `%pT'\n"),
11742 stub_entry
->root
.string
);
11743 bfd_set_error (bfd_error_bad_value
);
11744 htab
->stub_error
= true;
11748 if (info
->emitrelocations
)
11750 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11753 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11754 if (bfd_big_endian (info
->output_bfd
))
11755 r
[0].r_offset
+= 2;
11756 if (stub_entry
->type
.r2save
)
11757 r
[0].r_offset
+= 4;
11758 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11759 r
[0].r_addend
= targ
;
11760 if (PPC_HA (off
) != 0)
11762 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11763 r
[1].r_offset
= r
[0].r_offset
+ 4;
11764 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11765 r
[1].r_addend
= r
[0].r_addend
;
11770 obfd
= htab
->params
->stub_bfd
;
11771 if (!stub_entry
->type
.r2save
)
11773 if (PPC_HA (off
) != 0)
11775 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11777 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11780 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11784 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11786 if (r2off
== (bfd_vma
) -1)
11788 htab
->stub_error
= true;
11792 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11794 if (PPC_HA (off
) != 0)
11796 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11798 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11801 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11803 if (PPC_HA (r2off
) != 0)
11806 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11808 if (PPC_LO (r2off
) != 0)
11811 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11815 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11817 bfd_put_32 (obfd
, BCTR
, p
);
11820 else if (stub_entry
->type
.sub
>= ppc_stub_notoc
)
11822 bool is_plt
= stub_entry
->type
.main
== ppc_stub_plt_call
;
11824 off
= (stub_entry
->stub_offset
11825 + stub_entry
->group
->stub_sec
->output_offset
11826 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11827 obfd
= htab
->params
->stub_bfd
;
11829 && stub_entry
->h
!= NULL
11830 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11831 && htab
->params
->tls_get_addr_opt
);
11834 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
11837 if (stub_entry
->type
.r2save
)
11840 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11845 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11846 if (targ
>= (bfd_vma
) -2)
11849 plt
= htab
->elf
.splt
;
11850 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
11852 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11853 plt
= htab
->elf
.iplt
;
11855 plt
= htab
->pltlocal
;
11857 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11860 targ
= (stub_entry
->target_value
11861 + stub_entry
->target_section
->output_offset
11862 + stub_entry
->target_section
->output_section
->vma
);
11868 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11869 p
= build_power10_offset (obfd
, p
, off
, odd
, is_plt
);
11872 if (htab
->glink_eh_frame
!= NULL
11873 && htab
->glink_eh_frame
->size
!= 0)
11875 bfd_byte
*base
, *eh
;
11876 unsigned int lr_used
, delta
;
11878 base
= (htab
->glink_eh_frame
->contents
11879 + stub_entry
->group
->eh_base
+ 17);
11880 eh
= base
+ stub_entry
->group
->eh_size
;
11881 lr_used
= stub_entry
->stub_offset
+ (p
- loc
) + 8;
11882 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11883 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11884 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11885 *eh
++ = DW_CFA_register
;
11888 *eh
++ = DW_CFA_advance_loc
+ 2;
11889 *eh
++ = DW_CFA_restore_extended
;
11891 stub_entry
->group
->eh_size
= eh
- base
;
11894 /* The notoc stubs calculate their target (either a PLT entry or
11895 the global entry point of a function) relative to the PC
11896 returned by the "bcl" two instructions past the start of the
11897 sequence emitted by build_offset. The offset is therefore 8
11898 less than calculated from the start of the sequence. */
11900 p
= build_offset (obfd
, p
, off
, is_plt
);
11903 if (stub_entry
->type
.main
== ppc_stub_long_branch
)
11907 from
= (stub_entry
->stub_offset
11908 + stub_entry
->group
->stub_sec
->output_offset
11909 + stub_entry
->group
->stub_sec
->output_section
->vma
11911 bfd_put_32 (obfd
, B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
11915 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11917 bfd_put_32 (obfd
, BCTR
, p
);
11922 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
11924 if (info
->emitrelocations
)
11926 bfd_vma roff
= relp
- stub_entry
->group
->stub_sec
->contents
;
11927 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11928 num_rel
+= num_relocs_for_power10_offset (off
, odd
);
11931 num_rel
+= num_relocs_for_offset (off
);
11934 r
= get_relocs (stub_entry
->group
->stub_sec
, num_rel
);
11937 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11938 r
= emit_relocs_for_power10_offset (info
, r
, roff
, targ
, off
, odd
);
11940 r
= emit_relocs_for_offset (info
, r
, roff
, targ
, off
);
11941 if (stub_entry
->type
.main
== ppc_stub_long_branch
)
11944 roff
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11945 r
->r_offset
= roff
;
11946 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11947 r
->r_addend
= targ
;
11948 if (stub_entry
->h
!= NULL
11949 && !use_global_in_relocs (htab
, stub_entry
, r
, num_rel
))
11954 else if (stub_entry
->type
.main
== ppc_stub_plt_call
)
11956 if (stub_entry
->h
!= NULL
11957 && stub_entry
->h
->is_func_descriptor
11958 && stub_entry
->h
->oh
!= NULL
)
11960 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11962 /* If the old-ABI "dot-symbol" is undefined make it weak so
11963 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11964 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11965 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11966 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11967 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11970 /* Now build the stub. */
11971 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11972 if (targ
>= (bfd_vma
) -2)
11975 plt
= htab
->elf
.splt
;
11976 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
11978 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11979 plt
= htab
->elf
.iplt
;
11981 plt
= htab
->pltlocal
;
11983 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11985 off
= (elf_gp (info
->output_bfd
)
11986 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11989 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11991 info
->callbacks
->einfo
11992 /* xgettext:c-format */
11993 (_("%P: linkage table error against `%pT'\n"),
11994 stub_entry
->h
!= NULL
11995 ? stub_entry
->h
->elf
.root
.root
.string
11997 bfd_set_error (bfd_error_bad_value
);
11998 htab
->stub_error
= true;
12003 if (info
->emitrelocations
)
12005 r
= get_relocs (stub_entry
->group
->stub_sec
,
12006 ((PPC_HA (off
) != 0)
12008 ? 2 + (htab
->params
->plt_static_chain
12009 && PPC_HA (off
+ 16) == PPC_HA (off
))
12013 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
12014 if (bfd_big_endian (info
->output_bfd
))
12015 r
[0].r_offset
+= 2;
12016 r
[0].r_addend
= targ
;
12019 obfd
= htab
->params
->stub_bfd
;
12020 is_tga
= (stub_entry
->h
!= NULL
12021 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12022 && htab
->params
->tls_get_addr_opt
);
12025 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
12027 r
[0].r_offset
+= p
- loc
;
12029 p
= build_plt_stub (htab
, stub_entry
, p
, off
, r
);
12031 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
12033 else if (stub_entry
->type
.main
== ppc_stub_save_res
)
12041 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
12043 if (htab
->params
->emit_stub_syms
)
12045 struct elf_link_hash_entry
*h
;
12048 const char *const stub_str
[] = { "long_branch",
12052 len1
= strlen (stub_str
[stub_entry
->type
.main
- 1]);
12053 len2
= strlen (stub_entry
->root
.string
);
12054 name
= bfd_malloc (len1
+ len2
+ 2);
12057 memcpy (name
, stub_entry
->root
.string
, 9);
12058 memcpy (name
+ 9, stub_str
[stub_entry
->type
.main
- 1], len1
);
12059 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
12060 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
12063 if (h
->root
.type
== bfd_link_hash_new
)
12065 h
->root
.type
= bfd_link_hash_defined
;
12066 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
12067 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
12068 h
->ref_regular
= 1;
12069 h
->def_regular
= 1;
12070 h
->ref_regular_nonweak
= 1;
12071 h
->forced_local
= 1;
12073 h
->root
.linker_def
= 1;
12080 /* As above, but don't actually build the stub. Just bump offset so
12081 we know stub section sizes, and select plt_branch stubs where
12082 long_branch stubs won't do. */
12085 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
12087 struct ppc_stub_hash_entry
*stub_entry
;
12088 struct bfd_link_info
*info
;
12089 struct ppc_link_hash_table
*htab
;
12091 bfd_vma targ
, off
, r2off
;
12092 unsigned int size
, extra
, lr_used
, delta
, odd
;
12094 /* Massage our args to the form they really have. */
12095 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
12098 htab
= ppc_hash_table (info
);
12102 /* Fail if the target section could not be assigned to an output
12103 section. The user should fix his linker script. */
12104 if (stub_entry
->target_section
!= NULL
12105 && stub_entry
->target_section
->output_section
== NULL
12106 && info
->non_contiguous_regions
)
12107 info
->callbacks
->einfo (_("%F%P: Could not assign %pA to an output section. "
12108 "Retry without --enable-non-contiguous-regions.\n"),
12109 stub_entry
->target_section
);
12111 /* Same for the group. */
12112 if (stub_entry
->group
->stub_sec
!= NULL
12113 && stub_entry
->group
->stub_sec
->output_section
== NULL
12114 && info
->non_contiguous_regions
)
12115 info
->callbacks
->einfo (_("%F%P: Could not assign group %pA target %pA to an "
12116 "output section. Retry without "
12117 "--enable-non-contiguous-regions.\n"),
12118 stub_entry
->group
->stub_sec
,
12119 stub_entry
->target_section
);
12121 /* Make a note of the offset within the stubs for this entry. */
12122 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12124 if (stub_entry
->h
!= NULL
12125 && stub_entry
->h
->save_res
12126 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
12127 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
12129 /* Don't make stubs to out-of-line register save/restore
12130 functions. Instead, emit copies of the functions. */
12131 stub_entry
->group
->needs_save_res
= 1;
12132 stub_entry
->type
.main
= ppc_stub_save_res
;
12133 stub_entry
->type
.sub
= ppc_stub_toc
;
12134 stub_entry
->type
.r2save
= 0;
12138 if (stub_entry
->type
.main
== ppc_stub_plt_branch
)
12140 /* Reset the stub type from the plt branch variant in case we now
12141 can reach with a shorter stub. */
12142 stub_entry
->type
.main
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
12145 if (stub_entry
->type
.main
== ppc_stub_long_branch
12146 && stub_entry
->type
.sub
== ppc_stub_toc
)
12148 targ
= (stub_entry
->target_value
12149 + stub_entry
->target_section
->output_offset
12150 + stub_entry
->target_section
->output_section
->vma
);
12151 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
12152 off
= (stub_entry
->stub_offset
12153 + stub_entry
->group
->stub_sec
->output_offset
12154 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12158 if (stub_entry
->type
.r2save
)
12160 r2off
= get_r2off (info
, stub_entry
);
12161 if (r2off
== (bfd_vma
) -1)
12163 htab
->stub_error
= true;
12167 if (PPC_HA (r2off
) != 0)
12169 if (PPC_LO (r2off
) != 0)
12175 /* If the branch offset is too big, use a ppc_stub_plt_branch.
12176 Do the same for -R objects without function descriptors. */
12177 if ((stub_entry
->type
.r2save
12179 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
12180 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12182 struct ppc_branch_hash_entry
*br_entry
;
12184 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
12185 stub_entry
->root
.string
+ 9,
12187 if (br_entry
== NULL
)
12189 _bfd_error_handler (_("can't build branch stub `%s'"),
12190 stub_entry
->root
.string
);
12191 htab
->stub_error
= true;
12195 if (br_entry
->iter
!= htab
->stub_iteration
)
12197 br_entry
->iter
= htab
->stub_iteration
;
12198 br_entry
->offset
= htab
->brlt
->size
;
12199 htab
->brlt
->size
+= 8;
12201 if (htab
->relbrlt
!= NULL
)
12202 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
12203 else if (info
->emitrelocations
)
12205 htab
->brlt
->reloc_count
+= 1;
12206 htab
->brlt
->flags
|= SEC_RELOC
;
12210 targ
= (br_entry
->offset
12211 + htab
->brlt
->output_offset
12212 + htab
->brlt
->output_section
->vma
);
12213 off
= (elf_gp (info
->output_bfd
)
12214 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12217 if (info
->emitrelocations
)
12219 stub_entry
->group
->stub_sec
->reloc_count
12220 += 1 + (PPC_HA (off
) != 0);
12221 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12224 stub_entry
->type
.main
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
12225 if (!stub_entry
->type
.r2save
)
12228 if (PPC_HA (off
) != 0)
12234 if (PPC_HA (off
) != 0)
12237 if (PPC_HA (r2off
) != 0)
12239 if (PPC_LO (r2off
) != 0)
12243 else if (info
->emitrelocations
)
12245 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
12246 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12249 else if (stub_entry
->type
.main
== ppc_stub_long_branch
)
12251 off
= (stub_entry
->stub_offset
12252 + stub_entry
->group
->stub_sec
->output_offset
12253 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12255 if (stub_entry
->type
.r2save
)
12258 targ
= (stub_entry
->target_value
12259 + stub_entry
->target_section
->output_offset
12260 + stub_entry
->target_section
->output_section
->vma
);
12264 if (info
->emitrelocations
)
12266 unsigned int num_rel
;
12267 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12268 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12270 num_rel
= num_relocs_for_offset (off
- 8);
12271 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12272 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12275 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12276 extra
= size_power10_offset (off
, odd
);
12278 extra
= size_offset (off
- 8);
12279 /* Include branch insn plus those in the offset sequence. */
12281 /* The branch insn is at the end, or "extra" bytes along. So
12282 its offset will be "extra" bytes less that that already
12286 if (stub_entry
->type
.sub
!= ppc_stub_notoc
)
12288 /* After the bcl, lr has been modified so we need to emit
12289 .eh_frame info saying the return address is in r12. */
12290 lr_used
= stub_entry
->stub_offset
+ 8;
12291 if (stub_entry
->type
.r2save
)
12293 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12294 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12295 DW_CFA_restore_extended 65. */
12296 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12297 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12298 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12301 /* If the branch can't reach, use a plt_branch. */
12302 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12304 stub_entry
->type
.main
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
12307 else if (info
->emitrelocations
)
12308 stub_entry
->group
->stub_sec
->reloc_count
+=1;
12310 else if (stub_entry
->type
.sub
>= ppc_stub_notoc
)
12312 BFD_ASSERT (stub_entry
->type
.main
== ppc_stub_plt_call
);
12314 if (stub_entry
->h
!= NULL
12315 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12316 && htab
->params
->tls_get_addr_opt
)
12319 if (!htab
->params
->no_tls_get_addr_regsave
)
12321 else if (stub_entry
->type
.r2save
)
12324 if (stub_entry
->type
.r2save
)
12326 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12327 if (targ
>= (bfd_vma
) -2)
12330 plt
= htab
->elf
.splt
;
12331 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12333 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12334 plt
= htab
->elf
.iplt
;
12336 plt
= htab
->pltlocal
;
12338 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12339 off
= (stub_entry
->stub_offset
12340 + stub_entry
->group
->stub_sec
->output_offset
12341 + stub_entry
->group
->stub_sec
->output_section
->vma
12346 if (htab
->params
->plt_stub_align
!= 0)
12348 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
, odd
);
12350 stub_entry
->group
->stub_sec
->size
+= pad
;
12351 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12356 if (info
->emitrelocations
)
12358 unsigned int num_rel
;
12359 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12360 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12362 num_rel
= num_relocs_for_offset (off
- 8);
12363 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12364 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12367 size
= plt_stub_size (htab
, stub_entry
, off
, odd
);
12369 if (stub_entry
->type
.sub
!= ppc_stub_notoc
)
12371 /* After the bcl, lr has been modified so we need to emit
12372 .eh_frame info saying the return address is in r12. */
12373 lr_used
+= stub_entry
->stub_offset
+ 8;
12374 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12375 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12376 DW_CFA_restore_extended 65. */
12377 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12378 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12379 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12381 if (stub_entry
->h
!= NULL
12382 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12383 && htab
->params
->tls_get_addr_opt
)
12385 if (!htab
->params
->no_tls_get_addr_regsave
)
12387 unsigned int cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
12388 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12389 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12390 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12391 stub_entry
->group
->lr_restore
12392 = stub_entry
->stub_offset
+ size
- 4;
12394 else if (stub_entry
->type
.r2save
)
12396 lr_used
= stub_entry
->stub_offset
+ size
- 20;
12397 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12398 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12399 stub_entry
->group
->lr_restore
12400 = stub_entry
->stub_offset
+ size
- 4;
12404 else if (stub_entry
->type
.main
== ppc_stub_plt_call
)
12406 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
12407 if (targ
>= (bfd_vma
) -2)
12409 plt
= htab
->elf
.splt
;
12410 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12412 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12413 plt
= htab
->elf
.iplt
;
12415 plt
= htab
->pltlocal
;
12417 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12419 off
= (elf_gp (info
->output_bfd
)
12420 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12423 if (htab
->params
->plt_stub_align
!= 0)
12425 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
, 0);
12427 stub_entry
->group
->stub_sec
->size
+= pad
;
12428 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12431 if (info
->emitrelocations
)
12433 stub_entry
->group
->stub_sec
->reloc_count
12434 += ((PPC_HA (off
) != 0)
12436 ? 2 + (htab
->params
->plt_static_chain
12437 && PPC_HA (off
+ 16) == PPC_HA (off
))
12439 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12442 size
= plt_stub_size (htab
, stub_entry
, off
, 0);
12444 if (stub_entry
->h
!= NULL
12445 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12446 && htab
->params
->tls_get_addr_opt
12447 && stub_entry
->type
.r2save
)
12449 if (!htab
->params
->no_tls_get_addr_regsave
)
12451 /* Adjustments to r1 need to be described. */
12452 unsigned int cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
12453 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12454 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12455 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12459 lr_used
= stub_entry
->stub_offset
+ size
- 20;
12460 /* The eh_frame info will consist of a DW_CFA_advance_loc
12461 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
12462 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
12463 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12464 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12466 stub_entry
->group
->lr_restore
= stub_entry
->stub_offset
+ size
- 4;
12475 stub_entry
->group
->stub_sec
->size
+= size
;
12479 /* Set up various things so that we can make a list of input sections
12480 for each output section included in the link. Returns -1 on error,
12481 0 when no stubs will be needed, and 1 on success. */
12484 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
12488 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12493 htab
->sec_info_arr_size
= _bfd_section_id
;
12494 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
12495 htab
->sec_info
= bfd_zmalloc (amt
);
12496 if (htab
->sec_info
== NULL
)
12499 /* Set toc_off for com, und, abs and ind sections. */
12500 for (id
= 0; id
< 3; id
++)
12501 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
12506 /* Set up for first pass at multitoc partitioning. */
12509 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
12511 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12513 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
12514 htab
->toc_bfd
= NULL
;
12515 htab
->toc_first_sec
= NULL
;
12518 /* The linker repeatedly calls this function for each TOC input section
12519 and linker generated GOT section. Group input bfds such that the toc
12520 within a group is less than 64k in size. */
12523 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
12525 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12526 bfd_vma addr
, off
, limit
;
12531 if (!htab
->second_toc_pass
)
12533 /* Keep track of the first .toc or .got section for this input bfd. */
12534 bool new_bfd
= htab
->toc_bfd
!= isec
->owner
;
12538 htab
->toc_bfd
= isec
->owner
;
12539 htab
->toc_first_sec
= isec
;
12542 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
12543 off
= addr
- htab
->toc_curr
;
12544 limit
= 0x80008000;
12545 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
12547 if (off
+ isec
->size
> limit
)
12549 addr
= (htab
->toc_first_sec
->output_offset
12550 + htab
->toc_first_sec
->output_section
->vma
);
12551 htab
->toc_curr
= addr
;
12552 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
12555 /* toc_curr is the base address of this toc group. Set elf_gp
12556 for the input section to be the offset relative to the
12557 output toc base plus 0x8000. Making the input elf_gp an
12558 offset allows us to move the toc as a whole without
12559 recalculating input elf_gp. */
12560 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
12561 off
+= TOC_BASE_OFF
;
12563 /* Die if someone uses a linker script that doesn't keep input
12564 file .toc and .got together. */
12566 && elf_gp (isec
->owner
) != 0
12567 && elf_gp (isec
->owner
) != off
)
12570 elf_gp (isec
->owner
) = off
;
12574 /* During the second pass toc_first_sec points to the start of
12575 a toc group, and toc_curr is used to track the old elf_gp.
12576 We use toc_bfd to ensure we only look at each bfd once. */
12577 if (htab
->toc_bfd
== isec
->owner
)
12579 htab
->toc_bfd
= isec
->owner
;
12581 if (htab
->toc_first_sec
== NULL
12582 || htab
->toc_curr
!= elf_gp (isec
->owner
))
12584 htab
->toc_curr
= elf_gp (isec
->owner
);
12585 htab
->toc_first_sec
= isec
;
12587 addr
= (htab
->toc_first_sec
->output_offset
12588 + htab
->toc_first_sec
->output_section
->vma
);
12589 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
12590 elf_gp (isec
->owner
) = off
;
12595 /* Called via elf_link_hash_traverse to merge GOT entries for global
12599 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
12601 if (h
->root
.type
== bfd_link_hash_indirect
)
12604 merge_got_entries (&h
->got
.glist
);
12609 /* Called via elf_link_hash_traverse to allocate GOT entries for global
12613 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
12615 struct got_entry
*gent
;
12617 if (h
->root
.type
== bfd_link_hash_indirect
)
12620 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
12621 if (!gent
->is_indirect
)
12622 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
12626 /* Called on the first multitoc pass after the last call to
12627 ppc64_elf_next_toc_section. This function removes duplicate GOT
12631 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
12633 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12634 struct bfd
*ibfd
, *ibfd2
;
12635 bool done_something
;
12637 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
12639 if (!htab
->do_multi_toc
)
12642 /* Merge global sym got entries within a toc group. */
12643 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
12645 /* And tlsld_got. */
12646 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12648 struct got_entry
*ent
, *ent2
;
12650 if (!is_ppc64_elf (ibfd
))
12653 ent
= ppc64_tlsld_got (ibfd
);
12654 if (!ent
->is_indirect
12655 && ent
->got
.offset
!= (bfd_vma
) -1)
12657 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
12659 if (!is_ppc64_elf (ibfd2
))
12662 ent2
= ppc64_tlsld_got (ibfd2
);
12663 if (!ent2
->is_indirect
12664 && ent2
->got
.offset
!= (bfd_vma
) -1
12665 && elf_gp (ibfd2
) == elf_gp (ibfd
))
12667 ent2
->is_indirect
= true;
12668 ent2
->got
.ent
= ent
;
12674 /* Zap sizes of got sections. */
12675 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
12676 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
12677 htab
->got_reli_size
= 0;
12679 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12681 asection
*got
, *relgot
;
12683 if (!is_ppc64_elf (ibfd
))
12686 got
= ppc64_elf_tdata (ibfd
)->got
;
12689 got
->rawsize
= got
->size
;
12691 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
12692 relgot
->rawsize
= relgot
->size
;
12697 /* Now reallocate the got, local syms first. We don't need to
12698 allocate section contents again since we never increase size. */
12699 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12701 struct got_entry
**lgot_ents
;
12702 struct got_entry
**end_lgot_ents
;
12703 struct plt_entry
**local_plt
;
12704 struct plt_entry
**end_local_plt
;
12705 unsigned char *lgot_masks
;
12706 bfd_size_type locsymcount
;
12707 Elf_Internal_Shdr
*symtab_hdr
;
12710 if (!is_ppc64_elf (ibfd
))
12713 lgot_ents
= elf_local_got_ents (ibfd
);
12717 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12718 locsymcount
= symtab_hdr
->sh_info
;
12719 end_lgot_ents
= lgot_ents
+ locsymcount
;
12720 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12721 end_local_plt
= local_plt
+ locsymcount
;
12722 lgot_masks
= (unsigned char *) end_local_plt
;
12723 s
= ppc64_elf_tdata (ibfd
)->got
;
12724 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
12726 struct got_entry
*ent
;
12728 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
12730 unsigned int ent_size
= 8;
12731 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
12733 ent
->got
.offset
= s
->size
;
12734 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
12739 s
->size
+= ent_size
;
12740 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
12742 htab
->elf
.irelplt
->size
+= rel_size
;
12743 htab
->got_reli_size
+= rel_size
;
12745 else if (bfd_link_pic (info
)
12746 && !(ent
->tls_type
!= 0
12747 && bfd_link_executable (info
)))
12749 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12750 srel
->size
+= rel_size
;
12756 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12758 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12760 struct got_entry
*ent
;
12762 if (!is_ppc64_elf (ibfd
))
12765 ent
= ppc64_tlsld_got (ibfd
);
12766 if (!ent
->is_indirect
12767 && ent
->got
.offset
!= (bfd_vma
) -1)
12769 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12770 ent
->got
.offset
= s
->size
;
12772 if (bfd_link_dll (info
))
12774 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12775 srel
->size
+= sizeof (Elf64_External_Rela
);
12780 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12781 if (!done_something
)
12782 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12786 if (!is_ppc64_elf (ibfd
))
12789 got
= ppc64_elf_tdata (ibfd
)->got
;
12792 done_something
= got
->rawsize
!= got
->size
;
12793 if (done_something
)
12798 if (done_something
)
12799 (*htab
->params
->layout_sections_again
) ();
12801 /* Set up for second pass over toc sections to recalculate elf_gp
12802 on input sections. */
12803 htab
->toc_bfd
= NULL
;
12804 htab
->toc_first_sec
= NULL
;
12805 htab
->second_toc_pass
= true;
12806 return done_something
;
12809 /* Called after second pass of multitoc partitioning. */
12812 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
12814 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12816 /* After the second pass, toc_curr tracks the TOC offset used
12817 for code sections below in ppc64_elf_next_input_section. */
12818 htab
->toc_curr
= TOC_BASE_OFF
;
12821 /* No toc references were found in ISEC. If the code in ISEC makes no
12822 calls, then there's no need to use toc adjusting stubs when branching
12823 into ISEC. Actually, indirect calls from ISEC are OK as they will
12824 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
12825 needed, and 2 if a cyclical call-graph was found but no other reason
12826 for a stub was detected. If called from the top level, a return of
12827 2 means the same as a return of 0. */
12830 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
12834 /* Mark this section as checked. */
12835 isec
->call_check_done
= 1;
12837 /* We know none of our code bearing sections will need toc stubs. */
12838 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
12841 if (isec
->size
== 0)
12844 if (isec
->output_section
== NULL
)
12848 if (isec
->reloc_count
!= 0)
12850 Elf_Internal_Rela
*relstart
, *rel
;
12851 Elf_Internal_Sym
*local_syms
;
12852 struct ppc_link_hash_table
*htab
;
12854 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
12855 info
->keep_memory
);
12856 if (relstart
== NULL
)
12859 /* Look for branches to outside of this section. */
12861 htab
= ppc_hash_table (info
);
12865 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
12867 enum elf_ppc64_reloc_type r_type
;
12868 unsigned long r_symndx
;
12869 struct elf_link_hash_entry
*h
;
12870 struct ppc_link_hash_entry
*eh
;
12871 Elf_Internal_Sym
*sym
;
12873 struct _opd_sec_data
*opd
;
12877 r_type
= ELF64_R_TYPE (rel
->r_info
);
12878 if (r_type
!= R_PPC64_REL24
12879 && r_type
!= R_PPC64_REL24_NOTOC
12880 && r_type
!= R_PPC64_REL24_P9NOTOC
12881 && r_type
!= R_PPC64_REL14
12882 && r_type
!= R_PPC64_REL14_BRTAKEN
12883 && r_type
!= R_PPC64_REL14_BRNTAKEN
12884 && r_type
!= R_PPC64_PLTCALL
12885 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
12888 r_symndx
= ELF64_R_SYM (rel
->r_info
);
12889 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
12896 /* Calls to dynamic lib functions go through a plt call stub
12898 eh
= ppc_elf_hash_entry (h
);
12900 && (eh
->elf
.plt
.plist
!= NULL
12902 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12908 if (sym_sec
== NULL
)
12909 /* Ignore other undefined symbols. */
12912 /* Assume branches to other sections not included in the
12913 link need stubs too, to cover -R and absolute syms. */
12914 if (sym_sec
->output_section
== NULL
)
12921 sym_value
= sym
->st_value
;
12924 if (h
->root
.type
!= bfd_link_hash_defined
12925 && h
->root
.type
!= bfd_link_hash_defweak
)
12927 sym_value
= h
->root
.u
.def
.value
;
12929 sym_value
+= rel
->r_addend
;
12931 /* If this branch reloc uses an opd sym, find the code section. */
12932 opd
= get_opd_info (sym_sec
);
12935 if (h
== NULL
&& opd
->adjust
!= NULL
)
12939 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12941 /* Assume deleted functions won't ever be called. */
12943 sym_value
+= adjust
;
12946 dest
= opd_entry_value (sym_sec
, sym_value
,
12947 &sym_sec
, NULL
, false);
12948 if (dest
== (bfd_vma
) -1)
12953 + sym_sec
->output_offset
12954 + sym_sec
->output_section
->vma
);
12956 /* Ignore branch to self. */
12957 if (sym_sec
== isec
)
12960 /* If the called function uses the toc, we need a stub. */
12961 if (sym_sec
->has_toc_reloc
12962 || sym_sec
->makes_toc_func_call
)
12968 /* Assume any branch that needs a long branch stub might in fact
12969 need a plt_branch stub. A plt_branch stub uses r2. */
12970 else if (dest
- (isec
->output_offset
12971 + isec
->output_section
->vma
12972 + rel
->r_offset
) + (1 << 25)
12973 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
12981 /* If calling back to a section in the process of being
12982 tested, we can't say for sure that no toc adjusting stubs
12983 are needed, so don't return zero. */
12984 else if (sym_sec
->call_check_in_progress
)
12987 /* Branches to another section that itself doesn't have any TOC
12988 references are OK. Recursively call ourselves to check. */
12989 else if (!sym_sec
->call_check_done
)
12993 /* Mark current section as indeterminate, so that other
12994 sections that call back to current won't be marked as
12996 isec
->call_check_in_progress
= 1;
12997 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
12998 isec
->call_check_in_progress
= 0;
13009 if (elf_symtab_hdr (isec
->owner
).contents
13010 != (unsigned char *) local_syms
)
13012 if (elf_section_data (isec
)->relocs
!= relstart
)
13017 && isec
->map_head
.s
!= NULL
13018 && (strcmp (isec
->output_section
->name
, ".init") == 0
13019 || strcmp (isec
->output_section
->name
, ".fini") == 0))
13021 if (isec
->map_head
.s
->has_toc_reloc
13022 || isec
->map_head
.s
->makes_toc_func_call
)
13024 else if (!isec
->map_head
.s
->call_check_done
)
13027 isec
->call_check_in_progress
= 1;
13028 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
13029 isec
->call_check_in_progress
= 0;
13036 isec
->makes_toc_func_call
= 1;
13041 /* The linker repeatedly calls this function for each input section,
13042 in the order that input sections are linked into output sections.
13043 Build lists of input sections to determine groupings between which
13044 we may insert linker stubs. */
13047 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
13049 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13054 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
13055 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
13057 /* This happens to make the list in reverse order,
13058 which is what we want. */
13059 htab
->sec_info
[isec
->id
].u
.list
13060 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
13061 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
13064 if (htab
->multi_toc_needed
)
13066 /* Analyse sections that aren't already flagged as needing a
13067 valid toc pointer. Exclude .fixup for the linux kernel.
13068 .fixup contains branches, but only back to the function that
13069 hit an exception. */
13070 if (!(isec
->has_toc_reloc
13071 || (isec
->flags
& SEC_CODE
) == 0
13072 || strcmp (isec
->name
, ".fixup") == 0
13073 || isec
->call_check_done
))
13075 if (toc_adjusting_stub_needed (info
, isec
) < 0)
13078 /* Make all sections use the TOC assigned for this object file.
13079 This will be wrong for pasted sections; We fix that in
13080 check_pasted_section(). */
13081 if (elf_gp (isec
->owner
) != 0)
13082 htab
->toc_curr
= elf_gp (isec
->owner
);
13085 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
13089 /* Check that all .init and .fini sections use the same toc, if they
13090 have toc relocs. */
13093 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
13095 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
13099 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13100 bfd_vma toc_off
= 0;
13103 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13104 if (i
->has_toc_reloc
)
13107 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13108 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
13113 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13114 if (i
->makes_toc_func_call
)
13116 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13120 /* Make sure the whole pasted function uses the same toc offset. */
13122 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13123 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
13129 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
13131 return (check_pasted_section (info
, ".init")
13132 & check_pasted_section (info
, ".fini"));
13135 /* See whether we can group stub sections together. Grouping stub
13136 sections may result in fewer stubs. More importantly, we need to
13137 put all .init* and .fini* stubs at the beginning of the .init or
13138 .fini output sections respectively, because glibc splits the
13139 _init and _fini functions into multiple parts. Putting a stub in
13140 the middle of a function is not a good idea. */
13143 group_sections (struct bfd_link_info
*info
,
13144 bfd_size_type stub_group_size
,
13145 bool stubs_always_before_branch
)
13147 struct ppc_link_hash_table
*htab
;
13149 bool suppress_size_errors
;
13151 htab
= ppc_hash_table (info
);
13155 suppress_size_errors
= false;
13156 if (stub_group_size
== 1)
13158 /* Default values. */
13159 if (stubs_always_before_branch
)
13160 stub_group_size
= 0x1e00000;
13162 stub_group_size
= 0x1c00000;
13163 suppress_size_errors
= true;
13166 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
13170 if (osec
->id
>= htab
->sec_info_arr_size
)
13173 tail
= htab
->sec_info
[osec
->id
].u
.list
;
13174 while (tail
!= NULL
)
13178 bfd_size_type total
;
13181 struct map_stub
*group
;
13182 bfd_size_type group_size
;
13185 total
= tail
->size
;
13186 group_size
= (ppc64_elf_section_data (tail
) != NULL
13187 && ppc64_elf_section_data (tail
)->has_14bit_branch
13188 ? stub_group_size
>> 10 : stub_group_size
);
13190 big_sec
= total
> group_size
;
13191 if (big_sec
&& !suppress_size_errors
)
13192 /* xgettext:c-format */
13193 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
13194 tail
->owner
, tail
);
13195 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
13197 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
13198 && ((total
+= curr
->output_offset
- prev
->output_offset
)
13199 < (ppc64_elf_section_data (prev
) != NULL
13200 && ppc64_elf_section_data (prev
)->has_14bit_branch
13201 ? (group_size
= stub_group_size
>> 10) : group_size
))
13202 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13205 /* OK, the size from the start of CURR to the end is less
13206 than group_size and thus can be handled by one stub
13207 section. (or the tail section is itself larger than
13208 group_size, in which case we may be toast.) We should
13209 really be keeping track of the total size of stubs added
13210 here, as stubs contribute to the final output section
13211 size. That's a little tricky, and this way will only
13212 break if stubs added make the total size more than 2^25,
13213 ie. for the default stub_group_size, if stubs total more
13214 than 2097152 bytes, or nearly 75000 plt call stubs. */
13215 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
13218 group
->link_sec
= curr
;
13219 group
->stub_sec
= NULL
;
13220 group
->needs_save_res
= 0;
13221 group
->lr_restore
= 0;
13222 group
->eh_size
= 0;
13223 group
->eh_base
= 0;
13224 group
->next
= htab
->group
;
13225 htab
->group
= group
;
13228 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13229 /* Set up this stub group. */
13230 htab
->sec_info
[tail
->id
].u
.group
= group
;
13232 while (tail
!= curr
&& (tail
= prev
) != NULL
);
13234 /* But wait, there's more! Input sections up to group_size
13235 bytes before the stub section can be handled by it too.
13236 Don't do this if we have a really large section after the
13237 stubs, as adding more stubs increases the chance that
13238 branches may not reach into the stub section. */
13239 if (!stubs_always_before_branch
&& !big_sec
)
13242 while (prev
!= NULL
13243 && ((total
+= tail
->output_offset
- prev
->output_offset
)
13244 < (ppc64_elf_section_data (prev
) != NULL
13245 && ppc64_elf_section_data (prev
)->has_14bit_branch
13246 ? (group_size
= stub_group_size
>> 10)
13248 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13251 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13252 htab
->sec_info
[tail
->id
].u
.group
= group
;
13261 static const unsigned char glink_eh_frame_cie
[] =
13263 0, 0, 0, 16, /* length. */
13264 0, 0, 0, 0, /* id. */
13265 1, /* CIE version. */
13266 'z', 'R', 0, /* Augmentation string. */
13267 4, /* Code alignment. */
13268 0x78, /* Data alignment. */
13270 1, /* Augmentation size. */
13271 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
13272 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
13275 /* Stripping output sections is normally done before dynamic section
13276 symbols have been allocated. This function is called later, and
13277 handles cases like htab->brlt which is mapped to its own output
13281 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
13283 if (isec
->size
== 0
13284 && isec
->output_section
->size
== 0
13285 && !(isec
->output_section
->flags
& SEC_KEEP
)
13286 && !bfd_section_removed_from_list (info
->output_bfd
,
13287 isec
->output_section
)
13288 && elf_section_data (isec
->output_section
)->dynindx
== 0)
13290 isec
->output_section
->flags
|= SEC_EXCLUDE
;
13291 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
13292 info
->output_bfd
->section_count
--;
13296 /* Determine and set the size of the stub section for a final link.
13298 The basic idea here is to examine all the relocations looking for
13299 PC-relative calls to a target that is unreachable with a "bl"
13303 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
13305 bfd_size_type stub_group_size
;
13306 bool stubs_always_before_branch
;
13307 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13312 if (htab
->params
->power10_stubs
== -1 && !htab
->has_power10_relocs
)
13313 htab
->params
->power10_stubs
= 0;
13315 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
13316 htab
->params
->plt_thread_safe
= 1;
13317 if (!htab
->opd_abi
)
13318 htab
->params
->plt_thread_safe
= 0;
13319 else if (htab
->params
->plt_thread_safe
== -1)
13321 static const char *const thread_starter
[] =
13325 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
13327 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
13328 "mq_notify", "create_timer",
13333 "GOMP_parallel_start",
13334 "GOMP_parallel_loop_static",
13335 "GOMP_parallel_loop_static_start",
13336 "GOMP_parallel_loop_dynamic",
13337 "GOMP_parallel_loop_dynamic_start",
13338 "GOMP_parallel_loop_guided",
13339 "GOMP_parallel_loop_guided_start",
13340 "GOMP_parallel_loop_runtime",
13341 "GOMP_parallel_loop_runtime_start",
13342 "GOMP_parallel_sections",
13343 "GOMP_parallel_sections_start",
13349 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
13351 struct elf_link_hash_entry
*h
;
13352 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
13353 false, false, true);
13354 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
13355 if (htab
->params
->plt_thread_safe
)
13359 stubs_always_before_branch
= htab
->params
->group_size
< 0;
13360 if (htab
->params
->group_size
< 0)
13361 stub_group_size
= -htab
->params
->group_size
;
13363 stub_group_size
= htab
->params
->group_size
;
13365 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
13368 htab
->tga_group
= NULL
;
13369 if (!htab
->params
->no_tls_get_addr_regsave
13370 && htab
->tga_desc_fd
!= NULL
13371 && (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefined
13372 || htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefweak
)
13373 && htab
->tls_get_addr_fd
!= NULL
13374 && is_static_defined (&htab
->tls_get_addr_fd
->elf
))
13376 asection
*sym_sec
, *code_sec
, *stub_sec
;
13378 struct _opd_sec_data
*opd
;
13380 sym_sec
= htab
->tls_get_addr_fd
->elf
.root
.u
.def
.section
;
13381 sym_value
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
13382 code_sec
= sym_sec
;
13383 opd
= get_opd_info (sym_sec
);
13385 opd_entry_value (sym_sec
, sym_value
, &code_sec
, NULL
, false);
13386 htab
->tga_group
= htab
->sec_info
[code_sec
->id
].u
.group
;
13387 stub_sec
= (*htab
->params
->add_stub_section
) (".tga_desc.stub",
13388 htab
->tga_group
->link_sec
);
13389 if (stub_sec
== NULL
)
13391 htab
->tga_group
->stub_sec
= stub_sec
;
13393 htab
->tga_desc_fd
->elf
.root
.type
= bfd_link_hash_defined
;
13394 htab
->tga_desc_fd
->elf
.root
.u
.def
.section
= stub_sec
;
13395 htab
->tga_desc_fd
->elf
.root
.u
.def
.value
= 0;
13396 htab
->tga_desc_fd
->elf
.type
= STT_FUNC
;
13397 htab
->tga_desc_fd
->elf
.def_regular
= 1;
13398 htab
->tga_desc_fd
->elf
.non_elf
= 0;
13399 _bfd_elf_link_hash_hide_symbol (info
, &htab
->tga_desc_fd
->elf
, true);
13402 #define STUB_SHRINK_ITER 20
13403 /* Loop until no stubs added. After iteration 20 of this loop we may
13404 exit on a stub section shrinking. This is to break out of a
13405 pathological case where adding stubs on one iteration decreases
13406 section gaps (perhaps due to alignment), which then requires
13407 fewer or smaller stubs on the next iteration. */
13412 unsigned int bfd_indx
;
13413 struct map_stub
*group
;
13415 htab
->stub_iteration
+= 1;
13417 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
13419 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
13421 Elf_Internal_Shdr
*symtab_hdr
;
13423 Elf_Internal_Sym
*local_syms
= NULL
;
13425 if (!is_ppc64_elf (input_bfd
))
13428 /* We'll need the symbol table in a second. */
13429 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13430 if (symtab_hdr
->sh_info
== 0)
13433 /* Walk over each section attached to the input bfd. */
13434 for (section
= input_bfd
->sections
;
13436 section
= section
->next
)
13438 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
13440 /* If there aren't any relocs, then there's nothing more
13442 if ((section
->flags
& SEC_RELOC
) == 0
13443 || (section
->flags
& SEC_ALLOC
) == 0
13444 || (section
->flags
& SEC_LOAD
) == 0
13445 || (section
->flags
& SEC_CODE
) == 0
13446 || section
->reloc_count
== 0)
13449 /* If this section is a link-once section that will be
13450 discarded, then don't create any stubs. */
13451 if (section
->output_section
== NULL
13452 || section
->output_section
->owner
!= info
->output_bfd
)
13455 /* Get the relocs. */
13457 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
13458 info
->keep_memory
);
13459 if (internal_relocs
== NULL
)
13460 goto error_ret_free_local
;
13462 /* Now examine each relocation. */
13463 irela
= internal_relocs
;
13464 irelaend
= irela
+ section
->reloc_count
;
13465 for (; irela
< irelaend
; irela
++)
13467 enum elf_ppc64_reloc_type r_type
;
13468 unsigned int r_indx
;
13469 struct ppc_stub_type stub_type
;
13470 struct ppc_stub_hash_entry
*stub_entry
;
13471 asection
*sym_sec
, *code_sec
;
13472 bfd_vma sym_value
, code_value
;
13473 bfd_vma destination
;
13474 unsigned long local_off
;
13476 struct ppc_link_hash_entry
*hash
;
13477 struct ppc_link_hash_entry
*fdh
;
13478 struct elf_link_hash_entry
*h
;
13479 Elf_Internal_Sym
*sym
;
13481 const asection
*id_sec
;
13482 struct _opd_sec_data
*opd
;
13483 struct plt_entry
*plt_ent
;
13485 r_type
= ELF64_R_TYPE (irela
->r_info
);
13486 r_indx
= ELF64_R_SYM (irela
->r_info
);
13488 if (r_type
>= R_PPC64_max
)
13490 bfd_set_error (bfd_error_bad_value
);
13491 goto error_ret_free_internal
;
13494 /* Only look for stubs on branch instructions. */
13495 if (r_type
!= R_PPC64_REL24
13496 && r_type
!= R_PPC64_REL24_NOTOC
13497 && r_type
!= R_PPC64_REL24_P9NOTOC
13498 && r_type
!= R_PPC64_REL14
13499 && r_type
!= R_PPC64_REL14_BRTAKEN
13500 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
13503 /* Now determine the call target, its name, value,
13505 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
13506 r_indx
, input_bfd
))
13507 goto error_ret_free_internal
;
13508 hash
= ppc_elf_hash_entry (h
);
13515 sym_value
= sym
->st_value
;
13516 if (sym_sec
!= NULL
13517 && sym_sec
->output_section
!= NULL
)
13520 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
13521 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
13523 sym_value
= hash
->elf
.root
.u
.def
.value
;
13524 if (sym_sec
->output_section
!= NULL
)
13527 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
13528 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
13530 /* Recognise an old ABI func code entry sym, and
13531 use the func descriptor sym instead if it is
13533 if (hash
->elf
.root
.root
.string
[0] == '.'
13534 && hash
->oh
!= NULL
)
13536 fdh
= ppc_follow_link (hash
->oh
);
13537 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
13538 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
13540 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
13541 sym_value
= fdh
->elf
.root
.u
.def
.value
;
13542 if (sym_sec
->output_section
!= NULL
)
13551 bfd_set_error (bfd_error_bad_value
);
13552 goto error_ret_free_internal
;
13559 sym_value
+= irela
->r_addend
;
13560 destination
= (sym_value
13561 + sym_sec
->output_offset
13562 + sym_sec
->output_section
->vma
);
13563 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
13568 code_sec
= sym_sec
;
13569 code_value
= sym_value
;
13570 opd
= get_opd_info (sym_sec
);
13575 if (hash
== NULL
&& opd
->adjust
!= NULL
)
13577 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13580 code_value
+= adjust
;
13581 sym_value
+= adjust
;
13583 dest
= opd_entry_value (sym_sec
, sym_value
,
13584 &code_sec
, &code_value
, false);
13585 if (dest
!= (bfd_vma
) -1)
13587 destination
= dest
;
13590 /* Fixup old ABI sym to point at code
13592 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
13593 hash
->elf
.root
.u
.def
.section
= code_sec
;
13594 hash
->elf
.root
.u
.def
.value
= code_value
;
13599 /* Determine what (if any) linker stub is needed. */
13601 stub_type
.main
= ppc_type_of_stub (section
, irela
, &hash
,
13602 &plt_ent
, destination
,
13604 stub_type
.sub
= ppc_stub_toc
;
13605 stub_type
.r2save
= 0;
13607 if (r_type
== R_PPC64_REL24_NOTOC
13608 || r_type
== R_PPC64_REL24_P9NOTOC
)
13610 enum ppc_stub_sub_type notoc
= ppc_stub_notoc
;
13611 if (htab
->params
->power10_stubs
== 0
13612 || (r_type
== R_PPC64_REL24_P9NOTOC
13613 && htab
->params
->power10_stubs
!= 1))
13614 notoc
= ppc_stub_p9notoc
;
13615 if (stub_type
.main
== ppc_stub_plt_call
)
13616 stub_type
.sub
= notoc
;
13617 else if (stub_type
.main
== ppc_stub_long_branch
13618 || (code_sec
!= NULL
13619 && code_sec
->output_section
!= NULL
13620 && (((hash
? hash
->elf
.other
: sym
->st_other
)
13621 & STO_PPC64_LOCAL_MASK
)
13622 > 1 << STO_PPC64_LOCAL_BIT
)))
13624 stub_type
.main
= ppc_stub_long_branch
;
13625 stub_type
.sub
= notoc
;
13626 stub_type
.r2save
= 0;
13629 else if (stub_type
.main
!= ppc_stub_plt_call
)
13631 /* Check whether we need a TOC adjusting stub.
13632 Since the linker pastes together pieces from
13633 different object files when creating the
13634 _init and _fini functions, it may be that a
13635 call to what looks like a local sym is in
13636 fact a call needing a TOC adjustment. */
13637 if ((code_sec
!= NULL
13638 && code_sec
->output_section
!= NULL
13639 && (code_sec
->has_toc_reloc
13640 || code_sec
->makes_toc_func_call
)
13641 && (htab
->sec_info
[code_sec
->id
].toc_off
13642 != htab
->sec_info
[section
->id
].toc_off
))
13643 || (((hash
? hash
->elf
.other
: sym
->st_other
)
13644 & STO_PPC64_LOCAL_MASK
)
13645 == 1 << STO_PPC64_LOCAL_BIT
))
13647 stub_type
.main
= ppc_stub_long_branch
;
13648 stub_type
.sub
= ppc_stub_toc
;
13649 stub_type
.r2save
= 1;
13653 if (stub_type
.main
== ppc_stub_none
)
13656 /* __tls_get_addr calls might be eliminated. */
13657 if (stub_type
.main
!= ppc_stub_plt_call
13659 && is_tls_get_addr (&hash
->elf
, htab
)
13660 && section
->has_tls_reloc
13661 && irela
!= internal_relocs
)
13663 /* Get tls info. */
13664 unsigned char *tls_mask
;
13666 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
13667 irela
- 1, input_bfd
))
13668 goto error_ret_free_internal
;
13669 if ((*tls_mask
& TLS_TLS
) != 0
13670 && (*tls_mask
& (TLS_GD
| TLS_LD
)) == 0)
13674 if (stub_type
.main
== ppc_stub_plt_call
13675 && stub_type
.sub
== ppc_stub_toc
)
13678 && htab
->params
->plt_localentry0
!= 0
13679 && is_elfv2_localentry0 (&hash
->elf
))
13680 htab
->has_plt_localentry0
= 1;
13681 else if (irela
+ 1 < irelaend
13682 && irela
[1].r_offset
== irela
->r_offset
+ 4
13683 && (ELF64_R_TYPE (irela
[1].r_info
)
13684 == R_PPC64_TOCSAVE
))
13686 if (!tocsave_find (htab
, INSERT
,
13687 &local_syms
, irela
+ 1, input_bfd
))
13688 goto error_ret_free_internal
;
13691 stub_type
.r2save
= 1;
13694 /* Support for grouping stub sections. */
13695 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
13697 /* Get the name of this stub. */
13698 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
13700 goto error_ret_free_internal
;
13702 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
13703 stub_name
, false, false);
13704 if (stub_entry
!= NULL
)
13707 if (!ppc_merge_stub (htab
, stub_entry
, stub_type
, r_type
))
13709 /* xgettext:c-format */
13711 (_("%pB: cannot create stub entry %s"),
13712 section
->owner
, stub_entry
->root
.string
);
13713 goto error_ret_free_internal
;
13718 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
13719 if (stub_entry
== NULL
)
13722 error_ret_free_internal
:
13723 if (elf_section_data (section
)->relocs
== NULL
)
13724 free (internal_relocs
);
13725 error_ret_free_local
:
13726 if (symtab_hdr
->contents
13727 != (unsigned char *) local_syms
)
13732 stub_entry
->type
= stub_type
;
13733 if (stub_type
.main
== ppc_stub_plt_call
)
13735 stub_entry
->target_value
= sym_value
;
13736 stub_entry
->target_section
= sym_sec
;
13740 stub_entry
->target_value
= code_value
;
13741 stub_entry
->target_section
= code_sec
;
13743 stub_entry
->h
= hash
;
13744 stub_entry
->plt_ent
= plt_ent
;
13745 stub_entry
->symtype
13746 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
13747 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
13750 && (hash
->elf
.root
.type
== bfd_link_hash_defined
13751 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
13752 htab
->stub_globals
+= 1;
13755 /* We're done with the internal relocs, free them. */
13756 if (elf_section_data (section
)->relocs
!= internal_relocs
)
13757 free (internal_relocs
);
13760 if (local_syms
!= NULL
13761 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13763 if (!info
->keep_memory
)
13766 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13770 /* We may have added some stubs. Find out the new size of the
13772 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13774 group
->lr_restore
= 0;
13775 group
->eh_size
= 0;
13776 if (group
->stub_sec
!= NULL
)
13778 asection
*stub_sec
= group
->stub_sec
;
13780 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13781 || stub_sec
->rawsize
< stub_sec
->size
)
13782 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
13783 stub_sec
->rawsize
= stub_sec
->size
;
13784 stub_sec
->size
= 0;
13785 stub_sec
->reloc_count
= 0;
13786 stub_sec
->flags
&= ~SEC_RELOC
;
13789 if (htab
->tga_group
!= NULL
)
13791 /* See emit_tga_desc and emit_tga_desc_eh_frame. */
13792 htab
->tga_group
->eh_size
13793 = 1 + 2 + (htab
->opd_abi
!= 0) + 3 + 8 * 2 + 3 + 8 + 3;
13794 htab
->tga_group
->lr_restore
= 23 * 4;
13795 htab
->tga_group
->stub_sec
->size
= 24 * 4;
13798 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13799 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
13800 htab
->brlt
->rawsize
= htab
->brlt
->size
;
13801 htab
->brlt
->size
= 0;
13802 htab
->brlt
->reloc_count
= 0;
13803 htab
->brlt
->flags
&= ~SEC_RELOC
;
13804 if (htab
->relbrlt
!= NULL
)
13805 htab
->relbrlt
->size
= 0;
13807 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
13809 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13810 if (group
->needs_save_res
)
13811 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13813 if (info
->emitrelocations
13814 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13816 htab
->glink
->reloc_count
= 1;
13817 htab
->glink
->flags
|= SEC_RELOC
;
13820 if (htab
->glink_eh_frame
!= NULL
13821 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
13822 && htab
->glink_eh_frame
->output_section
->size
> 8)
13824 size_t size
= 0, align
= 4;
13826 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13827 if (group
->eh_size
!= 0)
13828 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
13829 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13830 size
+= (24 + align
- 1) & -align
;
13832 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
13833 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13834 size
= (size
+ align
- 1) & -align
;
13835 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
13836 htab
->glink_eh_frame
->size
= size
;
13839 if (htab
->params
->plt_stub_align
!= 0)
13840 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13841 if (group
->stub_sec
!= NULL
)
13843 int align
= abs (htab
->params
->plt_stub_align
);
13844 group
->stub_sec
->size
13845 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13848 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13849 if (group
->stub_sec
!= NULL
13850 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
13851 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13852 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
13856 && (htab
->brlt
->rawsize
== htab
->brlt
->size
13857 || (htab
->stub_iteration
> STUB_SHRINK_ITER
13858 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
13859 && (htab
->glink_eh_frame
== NULL
13860 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
)
13861 && (htab
->tga_group
== NULL
13862 || htab
->stub_iteration
> 1))
13865 /* Ask the linker to do its stuff. */
13866 (*htab
->params
->layout_sections_again
) ();
13869 if (htab
->glink_eh_frame
!= NULL
13870 && htab
->glink_eh_frame
->size
!= 0)
13873 bfd_byte
*p
, *last_fde
;
13874 size_t last_fde_len
, size
, align
, pad
;
13875 struct map_stub
*group
;
13877 /* It is necessary to at least have a rough outline of the
13878 linker generated CIEs and FDEs written before
13879 bfd_elf_discard_info is run, in order for these FDEs to be
13880 indexed in .eh_frame_hdr. */
13881 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
13884 htab
->glink_eh_frame
->contents
= p
;
13888 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
13889 /* CIE length (rewrite in case little-endian). */
13890 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
13891 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13892 p
+= last_fde_len
+ 4;
13894 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13895 if (group
->eh_size
!= 0)
13897 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
13899 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
13901 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13904 val
= p
- htab
->glink_eh_frame
->contents
;
13905 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13907 /* Offset to stub section, written later. */
13909 /* stub section size. */
13910 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
13912 /* Augmentation. */
13914 /* Make sure we don't have all nops. This is enough for
13915 elf-eh-frame.c to detect the last non-nop opcode. */
13916 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
13917 p
= last_fde
+ last_fde_len
+ 4;
13919 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13922 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
13924 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13927 val
= p
- htab
->glink_eh_frame
->contents
;
13928 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13930 /* Offset to .glink, written later. */
13933 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
13935 /* Augmentation. */
13938 *p
++ = DW_CFA_advance_loc
+ (htab
->has_plt_localentry0
? 3 : 2);
13939 *p
++ = DW_CFA_register
;
13941 *p
++ = htab
->opd_abi
? 12 : 0;
13942 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 4 : 2);
13943 *p
++ = DW_CFA_restore_extended
;
13945 p
+= ((24 + align
- 1) & -align
) - 24;
13947 /* Subsume any padding into the last FDE if user .eh_frame
13948 sections are aligned more than glink_eh_frame. Otherwise any
13949 zero padding will be seen as a terminator. */
13950 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13951 size
= p
- htab
->glink_eh_frame
->contents
;
13952 pad
= ((size
+ align
- 1) & -align
) - size
;
13953 htab
->glink_eh_frame
->size
= size
+ pad
;
13954 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
13957 maybe_strip_output (info
, htab
->brlt
);
13958 if (htab
->relbrlt
!= NULL
)
13959 maybe_strip_output (info
, htab
->relbrlt
);
13960 if (htab
->glink_eh_frame
!= NULL
)
13961 maybe_strip_output (info
, htab
->glink_eh_frame
);
13966 /* Called after we have determined section placement. If sections
13967 move, we'll be called again. Provide a value for TOCstart. */
13970 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
13973 bfd_vma TOCstart
, adjust
;
13977 struct elf_link_hash_entry
*h
;
13978 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
13980 if (is_elf_hash_table (&htab
->root
)
13981 && htab
->hgot
!= NULL
)
13985 h
= (struct elf_link_hash_entry
*)
13986 bfd_link_hash_lookup (&htab
->root
, ".TOC.", false, false, true);
13987 if (is_elf_hash_table (&htab
->root
))
13991 && h
->root
.type
== bfd_link_hash_defined
13992 && !h
->root
.linker_def
13993 && (!is_elf_hash_table (&htab
->root
)
13994 || h
->def_regular
))
13996 TOCstart
= defined_sym_val (h
) - TOC_BASE_OFF
;
13997 _bfd_set_gp_value (obfd
, TOCstart
);
14002 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
14003 order. The TOC starts where the first of these sections starts. */
14004 s
= bfd_get_section_by_name (obfd
, ".got");
14005 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14006 s
= bfd_get_section_by_name (obfd
, ".toc");
14007 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14008 s
= bfd_get_section_by_name (obfd
, ".tocbss");
14009 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14010 s
= bfd_get_section_by_name (obfd
, ".plt");
14011 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14013 /* This may happen for
14014 o references to TOC base (SYM@toc / TOC[tc0]) without a
14016 o bad linker script
14017 o --gc-sections and empty TOC sections
14019 FIXME: Warn user? */
14021 /* Look for a likely section. We probably won't even be
14023 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14024 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
14026 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14029 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14030 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
14031 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14034 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14035 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
14039 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14040 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
14046 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
14048 /* Force alignment. */
14049 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
14050 TOCstart
-= adjust
;
14051 _bfd_set_gp_value (obfd
, TOCstart
);
14053 if (info
!= NULL
&& s
!= NULL
)
14055 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14059 if (htab
->elf
.hgot
!= NULL
)
14061 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
14062 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
14067 struct bfd_link_hash_entry
*bh
= NULL
;
14068 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
14069 s
, TOC_BASE_OFF
- adjust
,
14070 NULL
, false, false, &bh
);
14076 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
14077 write out any global entry stubs, and PLT relocations. */
14080 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
14082 struct bfd_link_info
*info
;
14083 struct ppc_link_hash_table
*htab
;
14084 struct plt_entry
*ent
;
14087 if (h
->root
.type
== bfd_link_hash_indirect
)
14091 htab
= ppc_hash_table (info
);
14095 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14096 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14098 /* This symbol has an entry in the procedure linkage
14099 table. Set it up. */
14100 Elf_Internal_Rela rela
;
14101 asection
*plt
, *relplt
;
14104 if (use_local_plt (info
, h
))
14106 if (!(h
->def_regular
14107 && (h
->root
.type
== bfd_link_hash_defined
14108 || h
->root
.type
== bfd_link_hash_defweak
)))
14110 if (h
->type
== STT_GNU_IFUNC
)
14112 plt
= htab
->elf
.iplt
;
14113 relplt
= htab
->elf
.irelplt
;
14114 htab
->elf
.ifunc_resolvers
= true;
14116 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14118 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14122 plt
= htab
->pltlocal
;
14123 if (bfd_link_pic (info
))
14125 relplt
= htab
->relpltlocal
;
14127 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14129 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14134 rela
.r_addend
= defined_sym_val (h
) + ent
->addend
;
14136 if (relplt
== NULL
)
14138 loc
= plt
->contents
+ ent
->plt
.offset
;
14139 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
14142 bfd_vma toc
= elf_gp (info
->output_bfd
);
14143 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
14144 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14149 rela
.r_offset
= (plt
->output_section
->vma
14150 + plt
->output_offset
14151 + ent
->plt
.offset
);
14152 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14153 * sizeof (Elf64_External_Rela
));
14154 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14159 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
14160 + htab
->elf
.splt
->output_offset
14161 + ent
->plt
.offset
);
14162 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
14163 rela
.r_addend
= ent
->addend
;
14164 loc
= (htab
->elf
.srelplt
->contents
14165 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
14166 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
14167 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
14168 htab
->elf
.ifunc_resolvers
= true;
14169 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14173 if (!h
->pointer_equality_needed
)
14176 if (h
->def_regular
)
14179 s
= htab
->global_entry
;
14180 if (s
== NULL
|| s
->size
== 0)
14183 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14184 if (ent
->plt
.offset
!= (bfd_vma
) -1
14185 && ent
->addend
== 0)
14191 p
= s
->contents
+ h
->root
.u
.def
.value
;
14192 plt
= htab
->elf
.splt
;
14193 if (use_local_plt (info
, h
))
14195 if (h
->type
== STT_GNU_IFUNC
)
14196 plt
= htab
->elf
.iplt
;
14198 plt
= htab
->pltlocal
;
14200 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
14201 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
14203 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
14205 info
->callbacks
->einfo
14206 (_("%P: linkage table error against `%pT'\n"),
14207 h
->root
.root
.string
);
14208 bfd_set_error (bfd_error_bad_value
);
14209 htab
->stub_error
= true;
14212 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
14213 if (htab
->params
->emit_stub_syms
)
14215 size_t len
= strlen (h
->root
.root
.string
);
14216 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
14221 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
14222 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
14225 if (h
->root
.type
== bfd_link_hash_new
)
14227 h
->root
.type
= bfd_link_hash_defined
;
14228 h
->root
.u
.def
.section
= s
;
14229 h
->root
.u
.def
.value
= p
- s
->contents
;
14230 h
->ref_regular
= 1;
14231 h
->def_regular
= 1;
14232 h
->ref_regular_nonweak
= 1;
14233 h
->forced_local
= 1;
14235 h
->root
.linker_def
= 1;
14239 if (PPC_HA (off
) != 0)
14241 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
14244 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
14246 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
14248 bfd_put_32 (s
->owner
, BCTR
, p
);
14254 /* Write PLT relocs for locals. */
14257 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
14259 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14262 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
14264 struct got_entry
**lgot_ents
, **end_lgot_ents
;
14265 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
14266 Elf_Internal_Shdr
*symtab_hdr
;
14267 bfd_size_type locsymcount
;
14268 Elf_Internal_Sym
*local_syms
= NULL
;
14269 struct plt_entry
*ent
;
14271 if (!is_ppc64_elf (ibfd
))
14274 lgot_ents
= elf_local_got_ents (ibfd
);
14278 symtab_hdr
= &elf_symtab_hdr (ibfd
);
14279 locsymcount
= symtab_hdr
->sh_info
;
14280 end_lgot_ents
= lgot_ents
+ locsymcount
;
14281 local_plt
= (struct plt_entry
**) end_lgot_ents
;
14282 end_local_plt
= local_plt
+ locsymcount
;
14283 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
14284 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
14285 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14287 Elf_Internal_Sym
*sym
;
14289 asection
*plt
, *relplt
;
14293 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
14294 lplt
- local_plt
, ibfd
))
14296 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14301 val
= sym
->st_value
+ ent
->addend
;
14302 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
14303 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
14305 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14307 htab
->elf
.ifunc_resolvers
= true;
14308 plt
= htab
->elf
.iplt
;
14309 relplt
= htab
->elf
.irelplt
;
14313 plt
= htab
->pltlocal
;
14314 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
14317 if (relplt
== NULL
)
14319 loc
= plt
->contents
+ ent
->plt
.offset
;
14320 bfd_put_64 (info
->output_bfd
, val
, loc
);
14323 bfd_vma toc
= elf_gp (ibfd
);
14324 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14329 Elf_Internal_Rela rela
;
14330 rela
.r_offset
= (ent
->plt
.offset
14331 + plt
->output_offset
14332 + plt
->output_section
->vma
);
14333 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14336 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14338 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14343 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14345 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14347 rela
.r_addend
= val
;
14348 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14349 * sizeof (Elf64_External_Rela
));
14350 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14354 if (local_syms
!= NULL
14355 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14357 if (!info
->keep_memory
)
14360 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14366 /* Emit the static wrapper function preserving registers around a
14367 __tls_get_addr_opt call. */
14370 emit_tga_desc (struct ppc_link_hash_table
*htab
)
14372 asection
*stub_sec
= htab
->tga_group
->stub_sec
;
14373 unsigned int cfa_updt
= 11 * 4;
14375 bfd_vma to
, from
, delta
;
14377 BFD_ASSERT (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_defined
14378 && htab
->tga_desc_fd
->elf
.root
.u
.def
.section
== stub_sec
14379 && htab
->tga_desc_fd
->elf
.root
.u
.def
.value
== 0);
14380 to
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
14381 from
= defined_sym_val (&htab
->tga_desc_fd
->elf
) + cfa_updt
;
14383 if (delta
+ (1 << 25) >= 1 << 26)
14385 _bfd_error_handler (_("__tls_get_addr call offset overflow"));
14386 htab
->stub_error
= true;
14390 p
= stub_sec
->contents
;
14391 p
= tls_get_addr_prologue (htab
->elf
.dynobj
, p
, htab
);
14392 bfd_put_32 (stub_sec
->owner
, B_DOT
| 1 | (delta
& 0x3fffffc), p
);
14394 p
= tls_get_addr_epilogue (htab
->elf
.dynobj
, p
, htab
);
14395 return stub_sec
->size
== (bfd_size_type
) (p
- stub_sec
->contents
);
14398 /* Emit eh_frame describing the static wrapper function. */
14401 emit_tga_desc_eh_frame (struct ppc_link_hash_table
*htab
, bfd_byte
*p
)
14403 unsigned int cfa_updt
= 11 * 4;
14406 *p
++ = DW_CFA_advance_loc
+ cfa_updt
/ 4;
14407 *p
++ = DW_CFA_def_cfa_offset
;
14415 *p
++ = DW_CFA_offset_extended_sf
;
14417 *p
++ = (-16 / 8) & 0x7f;
14418 for (i
= 4; i
< 12; i
++)
14420 *p
++ = DW_CFA_offset
+ i
;
14421 *p
++ = (htab
->opd_abi
? 13 : 12) - i
;
14423 *p
++ = DW_CFA_advance_loc
+ 10;
14424 *p
++ = DW_CFA_def_cfa_offset
;
14426 for (i
= 4; i
< 12; i
++)
14427 *p
++ = DW_CFA_restore
+ i
;
14428 *p
++ = DW_CFA_advance_loc
+ 2;
14429 *p
++ = DW_CFA_restore_extended
;
14434 /* Build all the stubs associated with the current output file.
14435 The stubs are kept in a hash table attached to the main linker
14436 hash table. This function is called via gldelf64ppc_finish. */
14439 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
14442 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14443 struct map_stub
*group
;
14444 asection
*stub_sec
;
14446 int stub_sec_count
= 0;
14451 /* Allocate memory to hold the linker stubs. */
14452 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14454 group
->eh_size
= 0;
14455 group
->lr_restore
= 0;
14456 if ((stub_sec
= group
->stub_sec
) != NULL
14457 && stub_sec
->size
!= 0)
14459 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
14461 if (stub_sec
->contents
== NULL
)
14463 stub_sec
->size
= 0;
14467 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14472 /* Build the .glink plt call stub. */
14473 if (htab
->params
->emit_stub_syms
)
14475 struct elf_link_hash_entry
*h
;
14476 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
14477 true, false, false);
14480 if (h
->root
.type
== bfd_link_hash_new
)
14482 h
->root
.type
= bfd_link_hash_defined
;
14483 h
->root
.u
.def
.section
= htab
->glink
;
14484 h
->root
.u
.def
.value
= 8;
14485 h
->ref_regular
= 1;
14486 h
->def_regular
= 1;
14487 h
->ref_regular_nonweak
= 1;
14488 h
->forced_local
= 1;
14490 h
->root
.linker_def
= 1;
14493 plt0
= (htab
->elf
.splt
->output_section
->vma
14494 + htab
->elf
.splt
->output_offset
14496 if (info
->emitrelocations
)
14498 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
14501 r
->r_offset
= (htab
->glink
->output_offset
14502 + htab
->glink
->output_section
->vma
);
14503 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
14504 r
->r_addend
= plt0
;
14506 p
= htab
->glink
->contents
;
14507 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
14508 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
14512 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
14514 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14516 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14518 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
14520 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
14522 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
14524 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14526 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
14528 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14530 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
14538 . .quad plt0-1f # plt0 entry relative to 1:
14540 # We get here with r12 initially @ a glink branch
14541 # Load the address of _dl_runtime_resolve from plt0 and
14542 # jump to it, with r0 set to the index of the PLT entry
14543 # to be resolved and r11 the link map.
14544 __glink_PLTresolve:
14545 . std %r2,24(%r1) # optional
14551 . ld %r0,(0b-1b)(%r11)
14552 . sub %r12,%r12,%r11
14553 . add %r11,%r0,%r11
14554 . addi %r0,%r12,1b-2f
14561 . b __glink_PLTresolve
14563 . b __glink_PLTresolve */
14565 if (htab
->has_plt_localentry0
)
14567 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
14570 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
14572 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14574 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14576 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
14578 if (htab
->has_plt_localentry0
)
14579 insn
= LD_R0_0R11
| (-20 & 0xfffc);
14581 insn
= LD_R0_0R11
| (-16 & 0xfffc);
14582 bfd_put_32 (htab
->glink
->owner
, insn
, p
);
14584 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
14586 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R0_R11
, p
);
14588 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-44 & 0xffff), p
);
14590 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14592 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
14594 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14596 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
14599 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
14601 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
14603 /* Build the .glink lazy link call stubs. */
14605 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
14611 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
14616 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
14618 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
14623 bfd_put_32 (htab
->glink
->owner
,
14624 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
14630 if (htab
->tga_group
!= NULL
)
14632 htab
->tga_group
->lr_restore
= 23 * 4;
14633 htab
->tga_group
->stub_sec
->size
= 24 * 4;
14634 if (!emit_tga_desc (htab
))
14636 if (htab
->glink_eh_frame
!= NULL
14637 && htab
->glink_eh_frame
->size
!= 0)
14641 p
= htab
->glink_eh_frame
->contents
;
14642 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14644 htab
->tga_group
->eh_size
= emit_tga_desc_eh_frame (htab
, p
) - p
;
14648 /* Build .glink global entry stubs, and PLT relocs for globals. */
14649 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
14651 if (!write_plt_relocs_for_local_syms (info
))
14654 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
14656 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
14658 if (htab
->brlt
->contents
== NULL
)
14661 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
14663 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
14664 htab
->relbrlt
->size
);
14665 if (htab
->relbrlt
->contents
== NULL
)
14669 /* Build the stubs as directed by the stub hash table. */
14670 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
14672 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14673 if (group
->needs_save_res
)
14674 group
->stub_sec
->size
+= htab
->sfpr
->size
;
14676 if (htab
->relbrlt
!= NULL
)
14677 htab
->relbrlt
->reloc_count
= 0;
14679 if (htab
->params
->plt_stub_align
!= 0)
14680 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14681 if ((stub_sec
= group
->stub_sec
) != NULL
)
14683 int align
= abs (htab
->params
->plt_stub_align
);
14684 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
14687 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14688 if (group
->needs_save_res
)
14690 stub_sec
= group
->stub_sec
;
14691 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
14692 htab
->sfpr
->contents
, htab
->sfpr
->size
);
14693 if (htab
->params
->emit_stub_syms
)
14697 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
14698 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
14703 if (htab
->glink_eh_frame
!= NULL
14704 && htab
->glink_eh_frame
->size
!= 0)
14709 p
= htab
->glink_eh_frame
->contents
;
14710 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14712 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14713 if (group
->eh_size
!= 0)
14715 /* Offset to stub section. */
14716 val
= (group
->stub_sec
->output_section
->vma
14717 + group
->stub_sec
->output_offset
);
14718 val
-= (htab
->glink_eh_frame
->output_section
->vma
14719 + htab
->glink_eh_frame
->output_offset
14720 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
14721 if (val
+ 0x80000000 > 0xffffffff)
14724 (_("%s offset too large for .eh_frame sdata4 encoding"),
14725 group
->stub_sec
->name
);
14728 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
14729 p
+= (group
->eh_size
+ 17 + 3) & -4;
14731 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14733 /* Offset to .glink. */
14734 val
= (htab
->glink
->output_section
->vma
14735 + htab
->glink
->output_offset
14737 val
-= (htab
->glink_eh_frame
->output_section
->vma
14738 + htab
->glink_eh_frame
->output_offset
14739 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
14740 if (val
+ 0x80000000 > 0xffffffff)
14743 (_("%s offset too large for .eh_frame sdata4 encoding"),
14744 htab
->glink
->name
);
14747 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
14748 p
+= (24 + align
- 1) & -align
;
14752 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14753 if ((stub_sec
= group
->stub_sec
) != NULL
)
14755 stub_sec_count
+= 1;
14756 if (stub_sec
->rawsize
!= stub_sec
->size
14757 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
14758 || stub_sec
->rawsize
< stub_sec
->size
))
14764 htab
->stub_error
= true;
14765 _bfd_error_handler (_("stubs don't match calculated size"));
14768 if (htab
->stub_error
)
14774 if (asprintf (&groupmsg
,
14775 ngettext ("linker stubs in %u group\n",
14776 "linker stubs in %u groups\n",
14778 stub_sec_count
) < 0)
14782 if (asprintf (stats
, _("%s"
14784 " long branch %lu\n"
14786 " global entry %lu"),
14788 htab
->stub_count
[ppc_stub_long_branch
- 1],
14789 htab
->stub_count
[ppc_stub_plt_branch
- 1],
14790 htab
->stub_count
[ppc_stub_plt_call
- 1],
14791 htab
->stub_count
[ppc_stub_global_entry
- 1]) < 0)
14799 /* What to do when ld finds relocations against symbols defined in
14800 discarded sections. */
14802 static unsigned int
14803 ppc64_elf_action_discarded (asection
*sec
)
14805 if (strcmp (".opd", sec
->name
) == 0)
14808 if (strcmp (".toc", sec
->name
) == 0)
14811 if (strcmp (".toc1", sec
->name
) == 0)
14814 return _bfd_elf_default_action_discarded (sec
);
14817 /* These are the dynamic relocations supported by glibc. */
14820 ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type
)
14824 case R_PPC64_RELATIVE
:
14826 case R_PPC64_ADDR64
:
14827 case R_PPC64_GLOB_DAT
:
14828 case R_PPC64_IRELATIVE
:
14829 case R_PPC64_JMP_IREL
:
14830 case R_PPC64_JMP_SLOT
:
14831 case R_PPC64_DTPMOD64
:
14832 case R_PPC64_DTPREL64
:
14833 case R_PPC64_TPREL64
:
14834 case R_PPC64_TPREL16_LO_DS
:
14835 case R_PPC64_TPREL16_DS
:
14836 case R_PPC64_TPREL16
:
14837 case R_PPC64_TPREL16_LO
:
14838 case R_PPC64_TPREL16_HI
:
14839 case R_PPC64_TPREL16_HIGH
:
14840 case R_PPC64_TPREL16_HA
:
14841 case R_PPC64_TPREL16_HIGHA
:
14842 case R_PPC64_TPREL16_HIGHER
:
14843 case R_PPC64_TPREL16_HIGHEST
:
14844 case R_PPC64_TPREL16_HIGHERA
:
14845 case R_PPC64_TPREL16_HIGHESTA
:
14846 case R_PPC64_ADDR16_LO_DS
:
14847 case R_PPC64_ADDR16_LO
:
14848 case R_PPC64_ADDR16_HI
:
14849 case R_PPC64_ADDR16_HIGH
:
14850 case R_PPC64_ADDR16_HA
:
14851 case R_PPC64_ADDR16_HIGHA
:
14852 case R_PPC64_REL30
:
14854 case R_PPC64_UADDR64
:
14855 case R_PPC64_UADDR32
:
14856 case R_PPC64_ADDR32
:
14857 case R_PPC64_ADDR24
:
14858 case R_PPC64_ADDR16
:
14859 case R_PPC64_UADDR16
:
14860 case R_PPC64_ADDR16_DS
:
14861 case R_PPC64_ADDR16_HIGHER
:
14862 case R_PPC64_ADDR16_HIGHEST
:
14863 case R_PPC64_ADDR16_HIGHERA
:
14864 case R_PPC64_ADDR16_HIGHESTA
:
14865 case R_PPC64_ADDR14
:
14866 case R_PPC64_ADDR14_BRTAKEN
:
14867 case R_PPC64_ADDR14_BRNTAKEN
:
14868 case R_PPC64_REL32
:
14869 case R_PPC64_REL64
:
14877 /* The RELOCATE_SECTION function is called by the ELF backend linker
14878 to handle the relocations for a section.
14880 The relocs are always passed as Rela structures; if the section
14881 actually uses Rel structures, the r_addend field will always be
14884 This function is responsible for adjust the section contents as
14885 necessary, and (if using Rela relocs and generating a
14886 relocatable output file) adjusting the reloc addend as
14889 This function does not have to worry about setting the reloc
14890 address or the reloc symbol index.
14892 LOCAL_SYMS is a pointer to the swapped in local symbols.
14894 LOCAL_SECTIONS is an array giving the section in the input file
14895 corresponding to the st_shndx field of each local symbol.
14897 The global hash table entry for the global symbols can be found
14898 via elf_sym_hashes (input_bfd).
14900 When generating relocatable output, this function must handle
14901 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
14902 going to be the section symbol corresponding to the output
14903 section, which means that the addend must be adjusted
14907 ppc64_elf_relocate_section (bfd
*output_bfd
,
14908 struct bfd_link_info
*info
,
14910 asection
*input_section
,
14911 bfd_byte
*contents
,
14912 Elf_Internal_Rela
*relocs
,
14913 Elf_Internal_Sym
*local_syms
,
14914 asection
**local_sections
)
14916 struct ppc_link_hash_table
*htab
;
14917 Elf_Internal_Shdr
*symtab_hdr
;
14918 struct elf_link_hash_entry
**sym_hashes
;
14919 Elf_Internal_Rela
*rel
;
14920 Elf_Internal_Rela
*wrel
;
14921 Elf_Internal_Rela
*relend
;
14922 Elf_Internal_Rela outrel
;
14924 struct got_entry
**local_got_ents
;
14928 /* Assume 'at' branch hints. */
14929 bool is_isa_v2
= true;
14930 bool warned_dynamic
= false;
14931 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
14933 /* Initialize howto table if needed. */
14934 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
14937 htab
= ppc_hash_table (info
);
14941 /* Don't relocate stub sections. */
14942 if (input_section
->owner
== htab
->params
->stub_bfd
)
14945 if (!is_ppc64_elf (input_bfd
))
14947 bfd_set_error (bfd_error_wrong_format
);
14951 local_got_ents
= elf_local_got_ents (input_bfd
);
14952 TOCstart
= elf_gp (output_bfd
);
14953 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
14954 sym_hashes
= elf_sym_hashes (input_bfd
);
14955 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
14957 rel
= wrel
= relocs
;
14958 relend
= relocs
+ input_section
->reloc_count
;
14959 for (; rel
< relend
; wrel
++, rel
++)
14961 enum elf_ppc64_reloc_type r_type
;
14963 bfd_reloc_status_type r
;
14964 Elf_Internal_Sym
*sym
;
14966 struct elf_link_hash_entry
*h_elf
;
14967 struct ppc_link_hash_entry
*h
;
14968 struct ppc_link_hash_entry
*fdh
;
14969 const char *sym_name
;
14970 unsigned long r_symndx
, toc_symndx
;
14971 bfd_vma toc_addend
;
14972 unsigned char tls_mask
, tls_gd
, tls_type
;
14973 unsigned char sym_type
;
14974 bfd_vma relocation
;
14975 bool unresolved_reloc
, save_unresolved_reloc
;
14977 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
14980 struct ppc_stub_hash_entry
*stub_entry
;
14981 bfd_vma max_br_offset
;
14983 Elf_Internal_Rela orig_rel
;
14984 reloc_howto_type
*howto
;
14985 struct reloc_howto_struct alt_howto
;
14992 r_type
= ELF64_R_TYPE (rel
->r_info
);
14993 r_symndx
= ELF64_R_SYM (rel
->r_info
);
14995 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
14996 symbol of the previous ADDR64 reloc. The symbol gives us the
14997 proper TOC base to use. */
14998 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
15000 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
15002 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
15008 unresolved_reloc
= false;
15011 if (r_symndx
< symtab_hdr
->sh_info
)
15013 /* It's a local symbol. */
15014 struct _opd_sec_data
*opd
;
15016 sym
= local_syms
+ r_symndx
;
15017 sec
= local_sections
[r_symndx
];
15018 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
15019 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
15020 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
15021 opd
= get_opd_info (sec
);
15022 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
15024 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
15030 /* If this is a relocation against the opd section sym
15031 and we have edited .opd, adjust the reloc addend so
15032 that ld -r and ld --emit-relocs output is correct.
15033 If it is a reloc against some other .opd symbol,
15034 then the symbol value will be adjusted later. */
15035 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
15036 rel
->r_addend
+= adjust
;
15038 relocation
+= adjust
;
15046 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
15047 r_symndx
, symtab_hdr
, sym_hashes
,
15048 h_elf
, sec
, relocation
,
15049 unresolved_reloc
, warned
, ignored
);
15050 sym_name
= h_elf
->root
.root
.string
;
15051 sym_type
= h_elf
->type
;
15053 && sec
->owner
== output_bfd
15054 && strcmp (sec
->name
, ".opd") == 0)
15056 /* This is a symbol defined in a linker script. All
15057 such are defined in output sections, even those
15058 defined by simple assignment from a symbol defined in
15059 an input section. Transfer the symbol to an
15060 appropriate input .opd section, so that a branch to
15061 this symbol will be mapped to the location specified
15062 by the opd entry. */
15063 struct bfd_link_order
*lo
;
15064 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
15065 if (lo
->type
== bfd_indirect_link_order
)
15067 asection
*isec
= lo
->u
.indirect
.section
;
15068 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
15069 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
15072 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
15073 h_elf
->root
.u
.def
.section
= isec
;
15080 h
= ppc_elf_hash_entry (h_elf
);
15082 if (sec
!= NULL
&& discarded_section (sec
))
15084 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
15085 input_bfd
, input_section
,
15086 contents
, rel
->r_offset
);
15087 wrel
->r_offset
= rel
->r_offset
;
15089 wrel
->r_addend
= 0;
15091 /* For ld -r, remove relocations in debug sections against
15092 symbols defined in discarded sections. Not done for
15093 non-debug to preserve relocs in .eh_frame which the
15094 eh_frame editing code expects to be present. */
15095 if (bfd_link_relocatable (info
)
15096 && (input_section
->flags
& SEC_DEBUGGING
))
15102 if (bfd_link_relocatable (info
))
15105 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
15107 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15108 sec
= bfd_abs_section_ptr
;
15109 unresolved_reloc
= false;
15112 /* TLS optimizations. Replace instruction sequences and relocs
15113 based on information we collected in tls_optimize. We edit
15114 RELOCS so that --emit-relocs will output something sensible
15115 for the final instruction stream. */
15120 tls_mask
= h
->tls_mask
;
15121 else if (local_got_ents
!= NULL
)
15123 struct plt_entry
**local_plt
= (struct plt_entry
**)
15124 (local_got_ents
+ symtab_hdr
->sh_info
);
15125 unsigned char *lgot_masks
= (unsigned char *)
15126 (local_plt
+ symtab_hdr
->sh_info
);
15127 tls_mask
= lgot_masks
[r_symndx
];
15129 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
15130 && (r_type
== R_PPC64_TLS
15131 || r_type
== R_PPC64_TLSGD
15132 || r_type
== R_PPC64_TLSLD
))
15134 /* Check for toc tls entries. */
15135 unsigned char *toc_tls
;
15137 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15138 &local_syms
, rel
, input_bfd
))
15142 tls_mask
= *toc_tls
;
15145 /* Check that tls relocs are used with tls syms, and non-tls
15146 relocs are used with non-tls syms. */
15147 if (r_symndx
!= STN_UNDEF
15148 && r_type
!= R_PPC64_NONE
15150 || h
->elf
.root
.type
== bfd_link_hash_defined
15151 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
15152 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
15154 if ((tls_mask
& TLS_TLS
) != 0
15155 && (r_type
== R_PPC64_TLS
15156 || r_type
== R_PPC64_TLSGD
15157 || r_type
== R_PPC64_TLSLD
))
15158 /* R_PPC64_TLS is OK against a symbol in the TOC. */
15161 info
->callbacks
->einfo
15162 (!IS_PPC64_TLS_RELOC (r_type
)
15163 /* xgettext:c-format */
15164 ? _("%H: %s used with TLS symbol `%pT'\n")
15165 /* xgettext:c-format */
15166 : _("%H: %s used with non-TLS symbol `%pT'\n"),
15167 input_bfd
, input_section
, rel
->r_offset
,
15168 ppc64_elf_howto_table
[r_type
]->name
,
15172 /* Ensure reloc mapping code below stays sane. */
15173 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
15174 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
15175 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
15176 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
15177 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
15178 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
15179 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
15180 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
15181 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
15182 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
15190 case R_PPC64_LO_DS_OPT
:
15191 if (offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15193 insn
= bfd_get_32 (input_bfd
,
15194 contents
+ rel
->r_offset
- d_offset
);
15195 if ((insn
& (0x3fu
<< 26)) != 58u << 26)
15197 insn
+= (14u << 26) - (58u << 26);
15198 bfd_put_32 (input_bfd
, insn
,
15199 contents
+ rel
->r_offset
- d_offset
);
15200 r_type
= R_PPC64_TOC16_LO
;
15201 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15205 case R_PPC64_TOC16
:
15206 case R_PPC64_TOC16_LO
:
15207 case R_PPC64_TOC16_DS
:
15208 case R_PPC64_TOC16_LO_DS
:
15210 /* Check for toc tls entries. */
15211 unsigned char *toc_tls
;
15214 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15215 &local_syms
, rel
, input_bfd
);
15221 tls_mask
= *toc_tls
;
15222 if (r_type
== R_PPC64_TOC16_DS
15223 || r_type
== R_PPC64_TOC16_LO_DS
)
15225 if ((tls_mask
& TLS_TLS
) != 0
15226 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
15231 /* If we found a GD reloc pair, then we might be
15232 doing a GD->IE transition. */
15236 if ((tls_mask
& TLS_TLS
) != 0
15237 && (tls_mask
& TLS_GD
) == 0)
15240 else if (retval
== 3)
15242 if ((tls_mask
& TLS_TLS
) != 0
15243 && (tls_mask
& TLS_LD
) == 0)
15251 case R_PPC64_GOT_TPREL16_HI
:
15252 case R_PPC64_GOT_TPREL16_HA
:
15253 if ((tls_mask
& TLS_TLS
) != 0
15254 && (tls_mask
& TLS_TPREL
) == 0
15255 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15257 rel
->r_offset
-= d_offset
;
15258 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15259 r_type
= R_PPC64_NONE
;
15260 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15264 case R_PPC64_GOT_TPREL16_DS
:
15265 case R_PPC64_GOT_TPREL16_LO_DS
:
15266 if ((tls_mask
& TLS_TLS
) != 0
15267 && (tls_mask
& TLS_TPREL
) == 0
15268 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15271 insn
= bfd_get_32 (input_bfd
,
15272 contents
+ rel
->r_offset
- d_offset
);
15274 insn
|= 0x3c0d0000; /* addis 0,13,0 */
15275 bfd_put_32 (input_bfd
, insn
,
15276 contents
+ rel
->r_offset
- d_offset
);
15277 r_type
= R_PPC64_TPREL16_HA
;
15278 if (toc_symndx
!= 0)
15280 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15281 rel
->r_addend
= toc_addend
;
15282 /* We changed the symbol. Start over in order to
15283 get h, sym, sec etc. right. */
15287 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15291 case R_PPC64_GOT_TPREL_PCREL34
:
15292 if ((tls_mask
& TLS_TLS
) != 0
15293 && (tls_mask
& TLS_TPREL
) == 0
15294 && offset_in_range (input_section
, rel
->r_offset
, 8))
15296 /* pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel */
15297 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15299 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15300 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
15301 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
15302 bfd_put_32 (input_bfd
, pinsn
>> 32,
15303 contents
+ rel
->r_offset
);
15304 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15305 contents
+ rel
->r_offset
+ 4);
15306 r_type
= R_PPC64_TPREL34
;
15307 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15312 if ((tls_mask
& TLS_TLS
) != 0
15313 && (tls_mask
& TLS_TPREL
) == 0
15314 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15316 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15317 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
15320 if ((rel
->r_offset
& 3) == 0)
15322 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15323 /* Was PPC64_TLS which sits on insn boundary, now
15324 PPC64_TPREL16_LO which is at low-order half-word. */
15325 rel
->r_offset
+= d_offset
;
15326 r_type
= R_PPC64_TPREL16_LO
;
15327 if (toc_symndx
!= 0)
15329 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15330 rel
->r_addend
= toc_addend
;
15331 /* We changed the symbol. Start over in order to
15332 get h, sym, sec etc. right. */
15336 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15338 else if ((rel
->r_offset
& 3) == 1)
15340 /* For pcrel IE to LE we already have the full
15341 offset and thus don't need an addi here. A nop
15343 if ((insn
& (0x3fu
<< 26)) == 14 << 26)
15345 /* Extract regs from addi rt,ra,si. */
15346 unsigned int rt
= (insn
>> 21) & 0x1f;
15347 unsigned int ra
= (insn
>> 16) & 0x1f;
15352 /* Build or ra,rs,rb with rb==rs, ie. mr ra,rs. */
15353 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
15354 insn
|= (31u << 26) | (444u << 1);
15357 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- 1);
15362 case R_PPC64_GOT_TLSGD16_HI
:
15363 case R_PPC64_GOT_TLSGD16_HA
:
15365 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15366 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15370 case R_PPC64_GOT_TLSLD16_HI
:
15371 case R_PPC64_GOT_TLSLD16_HA
:
15372 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15373 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15376 if ((tls_mask
& tls_gd
) != 0)
15377 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
15378 + R_PPC64_GOT_TPREL16_DS
);
15381 rel
->r_offset
-= d_offset
;
15382 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15383 r_type
= R_PPC64_NONE
;
15385 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15389 case R_PPC64_GOT_TLSGD16
:
15390 case R_PPC64_GOT_TLSGD16_LO
:
15392 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15393 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15397 case R_PPC64_GOT_TLSLD16
:
15398 case R_PPC64_GOT_TLSLD16_LO
:
15399 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15400 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15402 unsigned int insn1
, insn2
;
15405 offset
= (bfd_vma
) -1;
15406 /* If not using the newer R_PPC64_TLSGD/LD to mark
15407 __tls_get_addr calls, we must trust that the call
15408 stays with its arg setup insns, ie. that the next
15409 reloc is the __tls_get_addr call associated with
15410 the current reloc. Edit both insns. */
15411 if (input_section
->nomark_tls_get_addr
15412 && rel
+ 1 < relend
15413 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
15414 htab
->tls_get_addr_fd
,
15416 htab
->tls_get_addr
,
15418 offset
= rel
[1].r_offset
;
15419 /* We read the low GOT_TLS (or TOC16) insn because we
15420 need to keep the destination reg. It may be
15421 something other than the usual r3, and moved to r3
15422 before the call by intervening code. */
15423 insn1
= bfd_get_32 (input_bfd
,
15424 contents
+ rel
->r_offset
- d_offset
);
15425 if ((tls_mask
& tls_gd
) != 0)
15428 insn1
&= (0x1f << 21) | (0x1f << 16);
15429 insn1
|= 58u << 26; /* ld */
15430 insn2
= 0x7c636a14; /* add 3,3,13 */
15431 if (offset
!= (bfd_vma
) -1)
15432 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15433 if (r_type
== R_PPC64_TOC16
15434 || r_type
== R_PPC64_TOC16_LO
)
15435 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
15437 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 1)) & 1)
15438 + R_PPC64_GOT_TPREL16_DS
);
15439 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15444 insn1
&= 0x1f << 21;
15445 insn1
|= 0x3c0d0000; /* addis r,13,0 */
15446 insn2
= 0x38630000; /* addi 3,3,0 */
15449 /* Was an LD reloc. */
15450 r_symndx
= STN_UNDEF
;
15451 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15453 else if (toc_symndx
!= 0)
15455 r_symndx
= toc_symndx
;
15456 rel
->r_addend
= toc_addend
;
15458 r_type
= R_PPC64_TPREL16_HA
;
15459 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15460 if (offset
!= (bfd_vma
) -1)
15462 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
15463 R_PPC64_TPREL16_LO
);
15464 rel
[1].r_offset
= offset
+ d_offset
;
15465 rel
[1].r_addend
= rel
->r_addend
;
15468 bfd_put_32 (input_bfd
, insn1
,
15469 contents
+ rel
->r_offset
- d_offset
);
15470 if (offset
!= (bfd_vma
) -1
15471 && offset_in_range (input_section
, offset
, 4))
15473 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15474 if (offset_in_range (input_section
, offset
+ 4, 4))
15476 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15477 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
15478 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
15481 if ((tls_mask
& tls_gd
) == 0
15482 && (tls_gd
== 0 || toc_symndx
!= 0))
15484 /* We changed the symbol. Start over in order
15485 to get h, sym, sec etc. right. */
15491 case R_PPC64_GOT_TLSGD_PCREL34
:
15492 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15493 && offset_in_range (input_section
, rel
->r_offset
, 8))
15495 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15497 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15498 if ((tls_mask
& TLS_GDIE
) != 0)
15500 /* IE, pla -> pld */
15501 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
15502 r_type
= R_PPC64_GOT_TPREL_PCREL34
;
15506 /* LE, pla pcrel -> paddi r13 */
15507 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15508 r_type
= R_PPC64_TPREL34
;
15510 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15511 bfd_put_32 (input_bfd
, pinsn
>> 32,
15512 contents
+ rel
->r_offset
);
15513 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15514 contents
+ rel
->r_offset
+ 4);
15518 case R_PPC64_GOT_TLSLD_PCREL34
:
15519 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15520 && offset_in_range (input_section
, rel
->r_offset
, 8))
15522 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15524 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15525 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15526 bfd_put_32 (input_bfd
, pinsn
>> 32,
15527 contents
+ rel
->r_offset
);
15528 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15529 contents
+ rel
->r_offset
+ 4);
15530 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15531 r_symndx
= STN_UNDEF
;
15532 r_type
= R_PPC64_TPREL34
;
15533 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15538 case R_PPC64_TLSGD
:
15539 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15540 && rel
+ 1 < relend
15541 && offset_in_range (input_section
, rel
->r_offset
,
15542 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
15545 unsigned int insn2
;
15546 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
15548 offset
= rel
->r_offset
;
15549 if (is_plt_seq_reloc (r_type1
))
15551 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
15552 if (r_type1
== R_PPC64_PLT_PCREL34
15553 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
15554 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15555 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15559 if (r_type1
== R_PPC64_PLTCALL
)
15560 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15562 if ((tls_mask
& TLS_GDIE
) != 0)
15565 r_type
= R_PPC64_NONE
;
15566 insn2
= 0x7c636a14; /* add 3,3,13 */
15571 if (toc_symndx
!= 0)
15573 r_symndx
= toc_symndx
;
15574 rel
->r_addend
= toc_addend
;
15576 if (r_type1
== R_PPC64_REL24_NOTOC
15577 || r_type1
== R_PPC64_REL24_P9NOTOC
15578 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
15580 r_type
= R_PPC64_NONE
;
15585 rel
->r_offset
= offset
+ d_offset
;
15586 r_type
= R_PPC64_TPREL16_LO
;
15587 insn2
= 0x38630000; /* addi 3,3,0 */
15590 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15591 /* Zap the reloc on the _tls_get_addr call too. */
15592 BFD_ASSERT (offset
== rel
[1].r_offset
);
15593 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15594 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15595 if ((tls_mask
& TLS_GDIE
) == 0
15597 && r_type
!= R_PPC64_NONE
)
15602 case R_PPC64_TLSLD
:
15603 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15604 && rel
+ 1 < relend
15605 && offset_in_range (input_section
, rel
->r_offset
,
15606 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
15609 unsigned int insn2
;
15610 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
15612 offset
= rel
->r_offset
;
15613 if (is_plt_seq_reloc (r_type1
))
15615 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
15616 if (r_type1
== R_PPC64_PLT_PCREL34
15617 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
15618 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15619 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15623 if (r_type1
== R_PPC64_PLTCALL
)
15624 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15626 if (r_type1
== R_PPC64_REL24_NOTOC
15627 || r_type1
== R_PPC64_REL24_P9NOTOC
15628 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
15630 r_type
= R_PPC64_NONE
;
15635 rel
->r_offset
= offset
+ d_offset
;
15636 r_symndx
= STN_UNDEF
;
15637 r_type
= R_PPC64_TPREL16_LO
;
15638 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15639 insn2
= 0x38630000; /* addi 3,3,0 */
15641 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15642 /* Zap the reloc on the _tls_get_addr call too. */
15643 BFD_ASSERT (offset
== rel
[1].r_offset
);
15644 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15645 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15646 if (r_type
!= R_PPC64_NONE
)
15651 case R_PPC64_DTPMOD64
:
15652 if (rel
+ 1 < relend
15653 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
15654 && rel
[1].r_offset
== rel
->r_offset
+ 8)
15656 if ((tls_mask
& TLS_GD
) == 0
15657 && offset_in_range (input_section
, rel
->r_offset
, 8))
15659 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
15660 if ((tls_mask
& TLS_GDIE
) != 0)
15661 r_type
= R_PPC64_TPREL64
;
15664 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
15665 r_type
= R_PPC64_NONE
;
15667 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15672 if ((tls_mask
& TLS_LD
) == 0
15673 && offset_in_range (input_section
, rel
->r_offset
, 8))
15675 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
15676 r_type
= R_PPC64_NONE
;
15677 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15682 case R_PPC64_TPREL64
:
15683 if ((tls_mask
& TLS_TPREL
) == 0)
15685 r_type
= R_PPC64_NONE
;
15686 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15690 case R_PPC64_ENTRY
:
15691 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15692 if (!bfd_link_pic (info
)
15693 && !info
->traditional_format
15694 && relocation
+ 0x80008000 <= 0xffffffff
15695 && offset_in_range (input_section
, rel
->r_offset
, 8))
15697 unsigned int insn1
, insn2
;
15699 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15700 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15701 if ((insn1
& ~0xfffc) == LD_R2_0R12
15702 && insn2
== ADD_R2_R2_R12
)
15704 bfd_put_32 (input_bfd
,
15705 LIS_R2
+ PPC_HA (relocation
),
15706 contents
+ rel
->r_offset
);
15707 bfd_put_32 (input_bfd
,
15708 ADDI_R2_R2
+ PPC_LO (relocation
),
15709 contents
+ rel
->r_offset
+ 4);
15714 relocation
-= (rel
->r_offset
15715 + input_section
->output_offset
15716 + input_section
->output_section
->vma
);
15717 if (relocation
+ 0x80008000 <= 0xffffffff
15718 && offset_in_range (input_section
, rel
->r_offset
, 8))
15720 unsigned int insn1
, insn2
;
15722 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15723 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15724 if ((insn1
& ~0xfffc) == LD_R2_0R12
15725 && insn2
== ADD_R2_R2_R12
)
15727 bfd_put_32 (input_bfd
,
15728 ADDIS_R2_R12
+ PPC_HA (relocation
),
15729 contents
+ rel
->r_offset
);
15730 bfd_put_32 (input_bfd
,
15731 ADDI_R2_R2
+ PPC_LO (relocation
),
15732 contents
+ rel
->r_offset
+ 4);
15738 case R_PPC64_REL16_HA
:
15739 /* If we are generating a non-PIC executable, edit
15740 . 0: addis 2,12,.TOC.-0b@ha
15741 . addi 2,2,.TOC.-0b@l
15742 used by ELFv2 global entry points to set up r2, to
15745 if .TOC. is in range. */
15746 if (!bfd_link_pic (info
)
15747 && !info
->traditional_format
15749 && rel
->r_addend
== d_offset
15750 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
15751 && rel
+ 1 < relend
15752 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
15753 && rel
[1].r_offset
== rel
->r_offset
+ 4
15754 && rel
[1].r_addend
== rel
->r_addend
+ 4
15755 && relocation
+ 0x80008000 <= 0xffffffff
15756 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 8))
15758 unsigned int insn1
, insn2
;
15759 offset
= rel
->r_offset
- d_offset
;
15760 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
15761 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15762 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
15763 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
15765 r_type
= R_PPC64_ADDR16_HA
;
15766 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15767 rel
->r_addend
-= d_offset
;
15768 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
15769 rel
[1].r_addend
-= d_offset
+ 4;
15770 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
15776 /* Handle other relocations that tweak non-addend part of insn. */
15778 max_br_offset
= 1 << 25;
15779 addend
= rel
->r_addend
;
15780 reloc_dest
= DEST_NORMAL
;
15786 case R_PPC64_TOCSAVE
:
15787 if (relocation
+ addend
== (rel
->r_offset
15788 + input_section
->output_offset
15789 + input_section
->output_section
->vma
)
15790 && tocsave_find (htab
, NO_INSERT
,
15791 &local_syms
, rel
, input_bfd
)
15792 && offset_in_range (input_section
, rel
->r_offset
, 4))
15794 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15796 || insn
== CROR_151515
|| insn
== CROR_313131
)
15797 bfd_put_32 (input_bfd
,
15798 STD_R2_0R1
+ STK_TOC (htab
),
15799 contents
+ rel
->r_offset
);
15803 /* Branch taken prediction relocations. */
15804 case R_PPC64_ADDR14_BRTAKEN
:
15805 case R_PPC64_REL14_BRTAKEN
:
15806 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
15807 /* Fall through. */
15809 /* Branch not taken prediction relocations. */
15810 case R_PPC64_ADDR14_BRNTAKEN
:
15811 case R_PPC64_REL14_BRNTAKEN
:
15812 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
15814 insn
|= bfd_get_32 (input_bfd
,
15815 contents
+ rel
->r_offset
) & ~(0x01 << 21);
15816 /* Fall through. */
15818 case R_PPC64_REL14
:
15819 max_br_offset
= 1 << 15;
15820 /* Fall through. */
15822 case R_PPC64_REL24
:
15823 case R_PPC64_REL24_NOTOC
:
15824 case R_PPC64_REL24_P9NOTOC
:
15825 case R_PPC64_PLTCALL
:
15826 case R_PPC64_PLTCALL_NOTOC
:
15827 /* Calls to functions with a different TOC, such as calls to
15828 shared objects, need to alter the TOC pointer. This is
15829 done using a linkage stub. A REL24 branching to these
15830 linkage stubs needs to be followed by a nop, as the nop
15831 will be replaced with an instruction to restore the TOC
15836 && h
->oh
->is_func_descriptor
)
15837 fdh
= ppc_follow_link (h
->oh
);
15838 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
15840 if ((r_type
== R_PPC64_PLTCALL
15841 || r_type
== R_PPC64_PLTCALL_NOTOC
)
15842 && stub_entry
!= NULL
15843 && stub_entry
->type
.main
== ppc_stub_plt_call
)
15846 if (stub_entry
!= NULL
15847 && (stub_entry
->type
.main
== ppc_stub_plt_call
15848 || stub_entry
->type
.r2save
))
15850 bool can_plt_call
= false;
15852 if (r_type
== R_PPC64_REL24_NOTOC
15853 || r_type
== R_PPC64_REL24_P9NOTOC
)
15855 /* NOTOC calls don't need to restore r2. */
15856 can_plt_call
= true;
15858 else if (stub_entry
->type
.main
== ppc_stub_plt_call
15860 && htab
->params
->plt_localentry0
!= 0
15862 && is_elfv2_localentry0 (&h
->elf
))
15864 /* The function doesn't use or change r2. */
15865 can_plt_call
= true;
15868 /* All of these stubs may modify r2, so there must be a
15869 branch and link followed by a nop. The nop is
15870 replaced by an insn to restore r2. */
15871 else if (offset_in_range (input_section
, rel
->r_offset
, 8))
15875 br
= bfd_get_32 (input_bfd
,
15876 contents
+ rel
->r_offset
);
15881 nop
= bfd_get_32 (input_bfd
,
15882 contents
+ rel
->r_offset
+ 4);
15883 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
15884 can_plt_call
= true;
15885 else if (nop
== NOP
15886 || nop
== CROR_151515
15887 || nop
== CROR_313131
)
15890 && is_tls_get_addr (&h
->elf
, htab
)
15891 && htab
->params
->tls_get_addr_opt
)
15893 /* Special stub used, leave nop alone. */
15896 bfd_put_32 (input_bfd
,
15897 LD_R2_0R1
+ STK_TOC (htab
),
15898 contents
+ rel
->r_offset
+ 4);
15899 can_plt_call
= true;
15904 if (!can_plt_call
&& h
!= NULL
)
15906 const char *name
= h
->elf
.root
.root
.string
;
15911 if (startswith (name
, "__libc_start_main")
15912 && (name
[17] == 0 || name
[17] == '@'))
15914 /* Allow crt1 branch to go via a toc adjusting
15915 stub. Other calls that never return could do
15916 the same, if we could detect such. */
15917 can_plt_call
= true;
15923 /* g++ as of 20130507 emits self-calls without a
15924 following nop. This is arguably wrong since we
15925 have conflicting information. On the one hand a
15926 global symbol and on the other a local call
15927 sequence, but don't error for this special case.
15928 It isn't possible to cheaply verify we have
15929 exactly such a call. Allow all calls to the same
15931 asection
*code_sec
= sec
;
15933 if (get_opd_info (sec
) != NULL
)
15935 bfd_vma off
= (relocation
+ addend
15936 - sec
->output_section
->vma
15937 - sec
->output_offset
);
15939 opd_entry_value (sec
, off
, &code_sec
, NULL
, false);
15941 if (code_sec
== input_section
)
15942 can_plt_call
= true;
15947 if (stub_entry
->type
.main
== ppc_stub_plt_call
)
15948 info
->callbacks
->einfo
15949 /* xgettext:c-format */
15950 (_("%H: call to `%pT' lacks nop, can't restore toc; "
15951 "(plt call stub)\n"),
15952 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
15954 info
->callbacks
->einfo
15955 /* xgettext:c-format */
15956 (_("%H: call to `%pT' lacks nop, can't restore toc; "
15957 "(toc save/adjust stub)\n"),
15958 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
15960 bfd_set_error (bfd_error_bad_value
);
15965 && stub_entry
->type
.main
== ppc_stub_plt_call
)
15966 unresolved_reloc
= false;
15969 if ((stub_entry
== NULL
15970 || stub_entry
->type
.main
== ppc_stub_long_branch
15971 || stub_entry
->type
.main
== ppc_stub_plt_branch
)
15972 && get_opd_info (sec
) != NULL
)
15974 /* The branch destination is the value of the opd entry. */
15975 bfd_vma off
= (relocation
+ addend
15976 - sec
->output_section
->vma
15977 - sec
->output_offset
);
15978 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, false);
15979 if (dest
!= (bfd_vma
) -1)
15983 reloc_dest
= DEST_OPD
;
15987 /* If the branch is out of reach we ought to have a long
15989 from
= (rel
->r_offset
15990 + input_section
->output_offset
15991 + input_section
->output_section
->vma
);
15993 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
15997 if (stub_entry
!= NULL
15998 && (stub_entry
->type
.main
== ppc_stub_long_branch
15999 || stub_entry
->type
.main
== ppc_stub_plt_branch
))
16001 if (stub_entry
->type
.sub
== ppc_stub_toc
16002 && !stub_entry
->type
.r2save
16003 && (r_type
== R_PPC64_ADDR14_BRTAKEN
16004 || r_type
== R_PPC64_ADDR14_BRNTAKEN
16005 || (relocation
+ addend
- from
+ max_br_offset
16006 < 2 * max_br_offset
)))
16007 /* Don't use the stub if this branch is in range. */
16010 if (stub_entry
!= NULL
16011 && stub_entry
->type
.sub
>= ppc_stub_notoc
16012 && ((r_type
!= R_PPC64_REL24_NOTOC
16013 && r_type
!= R_PPC64_REL24_P9NOTOC
)
16014 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
16015 & STO_PPC64_LOCAL_MASK
) <= 1 << STO_PPC64_LOCAL_BIT
)
16016 && (relocation
+ addend
- from
+ max_br_offset
16017 < 2 * max_br_offset
))
16020 if (stub_entry
!= NULL
16021 && stub_entry
->type
.r2save
16022 && (r_type
== R_PPC64_REL24_NOTOC
16023 || r_type
== R_PPC64_REL24_P9NOTOC
)
16024 && (relocation
+ addend
- from
+ max_br_offset
16025 < 2 * max_br_offset
))
16029 if (stub_entry
!= NULL
)
16031 /* Munge up the value and addend so that we call the stub
16032 rather than the procedure directly. */
16033 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
16035 if (stub_entry
->type
.main
== ppc_stub_save_res
)
16036 relocation
+= (stub_sec
->output_offset
16037 + stub_sec
->output_section
->vma
16038 + stub_sec
->size
- htab
->sfpr
->size
16039 - htab
->sfpr
->output_offset
16040 - htab
->sfpr
->output_section
->vma
);
16042 relocation
= (stub_entry
->stub_offset
16043 + stub_sec
->output_offset
16044 + stub_sec
->output_section
->vma
);
16046 reloc_dest
= DEST_STUB
;
16048 if (((stub_entry
->type
.r2save
16049 && (r_type
== R_PPC64_REL24_NOTOC
16050 || r_type
== R_PPC64_REL24_P9NOTOC
))
16051 || ((stub_entry
->type
.main
== ppc_stub_plt_call
16052 && (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
))
16053 && rel
+ 1 < relend
16054 && rel
[1].r_offset
== rel
->r_offset
+ 4
16055 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
))
16056 && !(stub_entry
->type
.main
== ppc_stub_plt_call
16057 && htab
->params
->tls_get_addr_opt
16059 && is_tls_get_addr (&h
->elf
, htab
)))
16061 /* Skip over the r2 store at the start of the stub. */
16065 if ((r_type
== R_PPC64_REL24_NOTOC
16066 || r_type
== R_PPC64_REL24_P9NOTOC
)
16067 && stub_entry
->type
.main
== ppc_stub_plt_call
16068 && stub_entry
->type
.sub
>= ppc_stub_notoc
)
16069 htab
->notoc_plt
= 1;
16076 /* Set 'a' bit. This is 0b00010 in BO field for branch
16077 on CR(BI) insns (BO == 001at or 011at), and 0b01000
16078 for branch on CTR insns (BO == 1a00t or 1a01t). */
16079 if ((insn
& (0x14 << 21)) == (0x04 << 21))
16080 insn
|= 0x02 << 21;
16081 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
16082 insn
|= 0x08 << 21;
16088 /* Invert 'y' bit if not the default. */
16089 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
16090 insn
^= 0x01 << 21;
16093 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
16096 /* NOP out calls to undefined weak functions.
16097 We can thus call a weak function without first
16098 checking whether the function is defined. */
16100 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16101 && h
->elf
.dynindx
== -1
16102 && (r_type
== R_PPC64_REL24
16103 || r_type
== R_PPC64_REL24_NOTOC
16104 || r_type
== R_PPC64_REL24_P9NOTOC
)
16107 && offset_in_range (input_section
, rel
->r_offset
, 4))
16109 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
16114 case R_PPC64_GOT16_DS
:
16115 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16116 || !htab
->do_toc_opt
)
16118 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16119 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
16121 && sec
->output_section
!= NULL
16122 && !discarded_section (sec
)
16123 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16124 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16126 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16127 if ((insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16129 insn
+= (14u << 26) - (58u << 26);
16130 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16131 r_type
= R_PPC64_TOC16
;
16132 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16137 case R_PPC64_GOT16_LO_DS
:
16138 case R_PPC64_GOT16_HA
:
16139 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16140 || !htab
->do_toc_opt
)
16142 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16143 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
16145 && sec
->output_section
!= NULL
16146 && !discarded_section (sec
)
16147 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16148 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16150 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16151 if (r_type
== R_PPC64_GOT16_LO_DS
16152 && (insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16154 insn
+= (14u << 26) - (58u << 26);
16155 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16156 r_type
= R_PPC64_TOC16_LO
;
16157 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16159 else if (r_type
== R_PPC64_GOT16_HA
16160 && (insn
& (0x3fu
<< 26)) == 15u << 26 /* addis */)
16162 r_type
= R_PPC64_TOC16_HA
;
16163 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16168 case R_PPC64_GOT_PCREL34
:
16169 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16170 || !htab
->do_toc_opt
)
16172 from
= (rel
->r_offset
16173 + input_section
->output_section
->vma
16174 + input_section
->output_offset
);
16175 if (!(relocation
- from
+ (1ULL << 33) < 1ULL << 34
16177 && sec
->output_section
!= NULL
16178 && !discarded_section (sec
)
16179 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16180 && offset_in_range (input_section
, rel
->r_offset
, 8)))
16183 offset
= rel
->r_offset
;
16184 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16186 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16187 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16188 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
16191 /* Replace with paddi. */
16192 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
16193 r_type
= R_PPC64_PCREL34
;
16194 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16195 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ offset
);
16196 bfd_put_32 (input_bfd
, pinsn
, contents
+ offset
+ 4);
16197 /* Fall through. */
16199 case R_PPC64_PCREL34
:
16200 if (!htab
->params
->no_pcrel_opt
16201 && rel
+ 1 < relend
16202 && rel
[1].r_offset
== rel
->r_offset
16203 && rel
[1].r_info
== ELF64_R_INFO (0, R_PPC64_PCREL_OPT
)
16204 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16205 && offset_in_range (input_section
, rel
->r_offset
, 8))
16207 offset
= rel
->r_offset
;
16208 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16210 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16211 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16212 == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
16213 | (14ULL << 26) /* paddi */))
16215 bfd_vma off2
= rel
[1].r_addend
;
16217 /* zero means next insn. */
16220 if (offset_in_range (input_section
, off2
, 4))
16223 bfd_signed_vma addend_off
;
16224 pinsn2
= bfd_get_32 (input_bfd
, contents
+ off2
);
16226 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16228 if (!offset_in_range (input_section
, off2
, 8))
16230 pinsn2
|= bfd_get_32 (input_bfd
,
16231 contents
+ off2
+ 4);
16233 if (xlate_pcrel_opt (&pinsn
, &pinsn2
, &addend_off
))
16235 addend
+= addend_off
;
16236 rel
->r_addend
= addend
;
16237 bfd_put_32 (input_bfd
, pinsn
>> 32,
16238 contents
+ offset
);
16239 bfd_put_32 (input_bfd
, pinsn
,
16240 contents
+ offset
+ 4);
16241 bfd_put_32 (input_bfd
, pinsn2
>> 32,
16243 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16244 bfd_put_32 (input_bfd
, pinsn2
,
16245 contents
+ off2
+ 4);
16254 save_unresolved_reloc
= unresolved_reloc
;
16258 /* xgettext:c-format */
16259 _bfd_error_handler (_("%pB: %s unsupported"),
16260 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
16262 bfd_set_error (bfd_error_bad_value
);
16268 case R_PPC64_TLSGD
:
16269 case R_PPC64_TLSLD
:
16270 case R_PPC64_TOCSAVE
:
16271 case R_PPC64_GNU_VTINHERIT
:
16272 case R_PPC64_GNU_VTENTRY
:
16273 case R_PPC64_ENTRY
:
16274 case R_PPC64_PCREL_OPT
:
16277 /* GOT16 relocations. Like an ADDR16 using the symbol's
16278 address in the GOT as relocation value instead of the
16279 symbol's value itself. Also, create a GOT entry for the
16280 symbol and put the symbol value there. */
16281 case R_PPC64_GOT_TLSGD16
:
16282 case R_PPC64_GOT_TLSGD16_LO
:
16283 case R_PPC64_GOT_TLSGD16_HI
:
16284 case R_PPC64_GOT_TLSGD16_HA
:
16285 case R_PPC64_GOT_TLSGD_PCREL34
:
16286 tls_type
= TLS_TLS
| TLS_GD
;
16289 case R_PPC64_GOT_TLSLD16
:
16290 case R_PPC64_GOT_TLSLD16_LO
:
16291 case R_PPC64_GOT_TLSLD16_HI
:
16292 case R_PPC64_GOT_TLSLD16_HA
:
16293 case R_PPC64_GOT_TLSLD_PCREL34
:
16294 tls_type
= TLS_TLS
| TLS_LD
;
16297 case R_PPC64_GOT_TPREL16_DS
:
16298 case R_PPC64_GOT_TPREL16_LO_DS
:
16299 case R_PPC64_GOT_TPREL16_HI
:
16300 case R_PPC64_GOT_TPREL16_HA
:
16301 case R_PPC64_GOT_TPREL_PCREL34
:
16302 tls_type
= TLS_TLS
| TLS_TPREL
;
16305 case R_PPC64_GOT_DTPREL16_DS
:
16306 case R_PPC64_GOT_DTPREL16_LO_DS
:
16307 case R_PPC64_GOT_DTPREL16_HI
:
16308 case R_PPC64_GOT_DTPREL16_HA
:
16309 case R_PPC64_GOT_DTPREL_PCREL34
:
16310 tls_type
= TLS_TLS
| TLS_DTPREL
;
16313 case R_PPC64_GOT16
:
16314 case R_PPC64_GOT16_LO
:
16315 case R_PPC64_GOT16_HI
:
16316 case R_PPC64_GOT16_HA
:
16317 case R_PPC64_GOT16_DS
:
16318 case R_PPC64_GOT16_LO_DS
:
16319 case R_PPC64_GOT_PCREL34
:
16322 /* Relocation is to the entry for this symbol in the global
16327 unsigned long indx
= 0;
16328 struct got_entry
*ent
;
16330 if (tls_type
== (TLS_TLS
| TLS_LD
)
16331 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16332 ent
= ppc64_tlsld_got (input_bfd
);
16337 if (!htab
->elf
.dynamic_sections_created
16338 || h
->elf
.dynindx
== -1
16339 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16340 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16341 /* This is actually a static link, or it is a
16342 -Bsymbolic link and the symbol is defined
16343 locally, or the symbol was forced to be local
16344 because of a version file. */
16348 indx
= h
->elf
.dynindx
;
16349 unresolved_reloc
= false;
16351 ent
= h
->elf
.got
.glist
;
16355 if (local_got_ents
== NULL
)
16357 ent
= local_got_ents
[r_symndx
];
16360 for (; ent
!= NULL
; ent
= ent
->next
)
16361 if (ent
->addend
== orig_rel
.r_addend
16362 && ent
->owner
== input_bfd
16363 && ent
->tls_type
== tls_type
)
16369 if (ent
->is_indirect
)
16370 ent
= ent
->got
.ent
;
16371 offp
= &ent
->got
.offset
;
16372 got
= ppc64_elf_tdata (ent
->owner
)->got
;
16376 /* The offset must always be a multiple of 8. We use the
16377 least significant bit to record whether we have already
16378 processed this entry. */
16380 if ((off
& 1) != 0)
16384 /* Generate relocs for the dynamic linker, except in
16385 the case of TLSLD where we'll use one entry per
16393 ? h
->elf
.type
== STT_GNU_IFUNC
16394 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
16397 relgot
= htab
->elf
.irelplt
;
16398 if (indx
== 0 || is_static_defined (&h
->elf
))
16399 htab
->elf
.ifunc_resolvers
= true;
16402 || (bfd_link_pic (info
)
16404 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16406 && bfd_link_executable (info
)
16408 || SYMBOL_REFERENCES_LOCAL (info
,
16410 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
16411 if (relgot
!= NULL
)
16413 outrel
.r_offset
= (got
->output_section
->vma
16414 + got
->output_offset
16416 outrel
.r_addend
= orig_rel
.r_addend
;
16417 if (tls_type
& (TLS_LD
| TLS_GD
))
16419 outrel
.r_addend
= 0;
16420 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
16421 if (tls_type
== (TLS_TLS
| TLS_GD
))
16423 loc
= relgot
->contents
;
16424 loc
+= (relgot
->reloc_count
++
16425 * sizeof (Elf64_External_Rela
));
16426 bfd_elf64_swap_reloca_out (output_bfd
,
16428 outrel
.r_offset
+= 8;
16429 outrel
.r_addend
= orig_rel
.r_addend
;
16431 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16434 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
16435 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16436 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
16437 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
16438 else if (indx
!= 0)
16439 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
16443 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16445 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16447 /* Write the .got section contents for the sake
16449 loc
= got
->contents
+ off
;
16450 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
16454 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
16456 outrel
.r_addend
+= relocation
;
16457 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
16459 if (htab
->elf
.tls_sec
== NULL
)
16460 outrel
.r_addend
= 0;
16462 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
16465 loc
= relgot
->contents
;
16466 loc
+= (relgot
->reloc_count
++
16467 * sizeof (Elf64_External_Rela
));
16468 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16471 /* Init the .got section contents here if we're not
16472 emitting a reloc. */
16475 relocation
+= orig_rel
.r_addend
;
16478 if (htab
->elf
.tls_sec
== NULL
)
16482 if (tls_type
& TLS_LD
)
16485 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16486 if (tls_type
& TLS_TPREL
)
16487 relocation
+= DTP_OFFSET
- TP_OFFSET
;
16490 if (tls_type
& (TLS_GD
| TLS_LD
))
16492 bfd_put_64 (output_bfd
, relocation
,
16493 got
->contents
+ off
+ 8);
16497 bfd_put_64 (output_bfd
, relocation
,
16498 got
->contents
+ off
);
16502 if (off
>= (bfd_vma
) -2)
16505 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
16507 if (!(r_type
== R_PPC64_GOT_PCREL34
16508 || r_type
== R_PPC64_GOT_TLSGD_PCREL34
16509 || r_type
== R_PPC64_GOT_TLSLD_PCREL34
16510 || r_type
== R_PPC64_GOT_TPREL_PCREL34
16511 || r_type
== R_PPC64_GOT_DTPREL_PCREL34
))
16512 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
16516 case R_PPC64_PLT16_HA
:
16517 case R_PPC64_PLT16_HI
:
16518 case R_PPC64_PLT16_LO
:
16519 case R_PPC64_PLT16_LO_DS
:
16520 case R_PPC64_PLT_PCREL34
:
16521 case R_PPC64_PLT_PCREL34_NOTOC
:
16522 case R_PPC64_PLT32
:
16523 case R_PPC64_PLT64
:
16524 case R_PPC64_PLTSEQ
:
16525 case R_PPC64_PLTSEQ_NOTOC
:
16526 case R_PPC64_PLTCALL
:
16527 case R_PPC64_PLTCALL_NOTOC
:
16528 /* Relocation is to the entry for this symbol in the
16529 procedure linkage table. */
16530 unresolved_reloc
= true;
16532 struct plt_entry
**plt_list
= NULL
;
16534 plt_list
= &h
->elf
.plt
.plist
;
16535 else if (local_got_ents
!= NULL
)
16537 struct plt_entry
**local_plt
= (struct plt_entry
**)
16538 (local_got_ents
+ symtab_hdr
->sh_info
);
16539 plt_list
= local_plt
+ r_symndx
;
16543 struct plt_entry
*ent
;
16545 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
16546 if (ent
->plt
.offset
!= (bfd_vma
) -1
16547 && ent
->addend
== orig_rel
.r_addend
)
16552 plt
= htab
->elf
.splt
;
16553 if (use_local_plt (info
, elf_hash_entry (h
)))
16556 ? h
->elf
.type
== STT_GNU_IFUNC
16557 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16558 plt
= htab
->elf
.iplt
;
16560 plt
= htab
->pltlocal
;
16562 relocation
= (plt
->output_section
->vma
16563 + plt
->output_offset
16564 + ent
->plt
.offset
);
16565 if (r_type
== R_PPC64_PLT16_HA
16566 || r_type
== R_PPC64_PLT16_HI
16567 || r_type
== R_PPC64_PLT16_LO
16568 || r_type
== R_PPC64_PLT16_LO_DS
)
16570 got
= (elf_gp (output_bfd
)
16571 + htab
->sec_info
[input_section
->id
].toc_off
);
16575 unresolved_reloc
= false;
16583 /* Relocation value is TOC base. */
16584 relocation
= TOCstart
;
16585 if (r_symndx
== STN_UNDEF
)
16586 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
16587 else if (unresolved_reloc
)
16589 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
16590 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
16592 unresolved_reloc
= true;
16595 /* TOC16 relocs. We want the offset relative to the TOC base,
16596 which is the address of the start of the TOC plus 0x8000.
16597 The TOC consists of sections .got, .toc, .tocbss, and .plt,
16599 case R_PPC64_TOC16
:
16600 case R_PPC64_TOC16_LO
:
16601 case R_PPC64_TOC16_HI
:
16602 case R_PPC64_TOC16_DS
:
16603 case R_PPC64_TOC16_LO_DS
:
16604 case R_PPC64_TOC16_HA
:
16605 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16610 /* Relocate against the beginning of the section. */
16611 case R_PPC64_SECTOFF
:
16612 case R_PPC64_SECTOFF_LO
:
16613 case R_PPC64_SECTOFF_HI
:
16614 case R_PPC64_SECTOFF_DS
:
16615 case R_PPC64_SECTOFF_LO_DS
:
16616 case R_PPC64_SECTOFF_HA
:
16618 addend
-= sec
->output_section
->vma
;
16621 case R_PPC64_REL16
:
16622 case R_PPC64_REL16_LO
:
16623 case R_PPC64_REL16_HI
:
16624 case R_PPC64_REL16_HA
:
16625 case R_PPC64_REL16_HIGH
:
16626 case R_PPC64_REL16_HIGHA
:
16627 case R_PPC64_REL16_HIGHER
:
16628 case R_PPC64_REL16_HIGHERA
:
16629 case R_PPC64_REL16_HIGHEST
:
16630 case R_PPC64_REL16_HIGHESTA
:
16631 case R_PPC64_REL16_HIGHER34
:
16632 case R_PPC64_REL16_HIGHERA34
:
16633 case R_PPC64_REL16_HIGHEST34
:
16634 case R_PPC64_REL16_HIGHESTA34
:
16635 case R_PPC64_REL16DX_HA
:
16636 case R_PPC64_REL14
:
16637 case R_PPC64_REL14_BRNTAKEN
:
16638 case R_PPC64_REL14_BRTAKEN
:
16639 case R_PPC64_REL24
:
16640 case R_PPC64_REL24_NOTOC
:
16641 case R_PPC64_REL24_P9NOTOC
:
16642 case R_PPC64_PCREL34
:
16643 case R_PPC64_PCREL28
:
16646 case R_PPC64_TPREL16
:
16647 case R_PPC64_TPREL16_LO
:
16648 case R_PPC64_TPREL16_HI
:
16649 case R_PPC64_TPREL16_HA
:
16650 case R_PPC64_TPREL16_DS
:
16651 case R_PPC64_TPREL16_LO_DS
:
16652 case R_PPC64_TPREL16_HIGH
:
16653 case R_PPC64_TPREL16_HIGHA
:
16654 case R_PPC64_TPREL16_HIGHER
:
16655 case R_PPC64_TPREL16_HIGHERA
:
16656 case R_PPC64_TPREL16_HIGHEST
:
16657 case R_PPC64_TPREL16_HIGHESTA
:
16659 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16660 && h
->elf
.dynindx
== -1
16661 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
16663 /* Make this relocation against an undefined weak symbol
16664 resolve to zero. This is really just a tweak, since
16665 code using weak externs ought to check that they are
16666 defined before using them. */
16667 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
16669 insn
= bfd_get_32 (input_bfd
, p
);
16670 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
16672 bfd_put_32 (input_bfd
, insn
, p
);
16675 /* Fall through. */
16677 case R_PPC64_TPREL34
:
16678 if (htab
->elf
.tls_sec
!= NULL
)
16679 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
16680 /* The TPREL16 relocs shouldn't really be used in shared
16681 libs or with non-local symbols as that will result in
16682 DT_TEXTREL being set, but support them anyway. */
16685 case R_PPC64_DTPREL16
:
16686 case R_PPC64_DTPREL16_LO
:
16687 case R_PPC64_DTPREL16_HI
:
16688 case R_PPC64_DTPREL16_HA
:
16689 case R_PPC64_DTPREL16_DS
:
16690 case R_PPC64_DTPREL16_LO_DS
:
16691 case R_PPC64_DTPREL16_HIGH
:
16692 case R_PPC64_DTPREL16_HIGHA
:
16693 case R_PPC64_DTPREL16_HIGHER
:
16694 case R_PPC64_DTPREL16_HIGHERA
:
16695 case R_PPC64_DTPREL16_HIGHEST
:
16696 case R_PPC64_DTPREL16_HIGHESTA
:
16697 case R_PPC64_DTPREL34
:
16698 if (htab
->elf
.tls_sec
!= NULL
)
16699 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16702 case R_PPC64_ADDR64_LOCAL
:
16703 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
16708 case R_PPC64_DTPMOD64
:
16713 case R_PPC64_TPREL64
:
16714 if (htab
->elf
.tls_sec
!= NULL
)
16715 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
16718 case R_PPC64_DTPREL64
:
16719 if (htab
->elf
.tls_sec
!= NULL
)
16720 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16721 /* Fall through. */
16723 /* Relocations that may need to be propagated if this is a
16725 case R_PPC64_REL30
:
16726 case R_PPC64_REL32
:
16727 case R_PPC64_REL64
:
16728 case R_PPC64_ADDR14
:
16729 case R_PPC64_ADDR14_BRNTAKEN
:
16730 case R_PPC64_ADDR14_BRTAKEN
:
16731 case R_PPC64_ADDR16
:
16732 case R_PPC64_ADDR16_DS
:
16733 case R_PPC64_ADDR16_HA
:
16734 case R_PPC64_ADDR16_HI
:
16735 case R_PPC64_ADDR16_HIGH
:
16736 case R_PPC64_ADDR16_HIGHA
:
16737 case R_PPC64_ADDR16_HIGHER
:
16738 case R_PPC64_ADDR16_HIGHERA
:
16739 case R_PPC64_ADDR16_HIGHEST
:
16740 case R_PPC64_ADDR16_HIGHESTA
:
16741 case R_PPC64_ADDR16_LO
:
16742 case R_PPC64_ADDR16_LO_DS
:
16743 case R_PPC64_ADDR16_HIGHER34
:
16744 case R_PPC64_ADDR16_HIGHERA34
:
16745 case R_PPC64_ADDR16_HIGHEST34
:
16746 case R_PPC64_ADDR16_HIGHESTA34
:
16747 case R_PPC64_ADDR24
:
16748 case R_PPC64_ADDR32
:
16749 case R_PPC64_ADDR64
:
16750 case R_PPC64_UADDR16
:
16751 case R_PPC64_UADDR32
:
16752 case R_PPC64_UADDR64
:
16754 case R_PPC64_D34_LO
:
16755 case R_PPC64_D34_HI30
:
16756 case R_PPC64_D34_HA30
:
16759 if ((input_section
->flags
& SEC_ALLOC
) == 0)
16762 if (NO_OPD_RELOCS
&& is_opd
)
16765 if (bfd_link_pic (info
)
16767 || h
->elf
.dyn_relocs
!= NULL
)
16768 && ((h
!= NULL
&& pc_dynrelocs (h
))
16769 || must_be_dyn_reloc (info
, r_type
)))
16771 ? h
->elf
.dyn_relocs
!= NULL
16772 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
16774 bool skip
, relocate
;
16779 /* When generating a dynamic object, these relocations
16780 are copied into the output file to be resolved at run
16786 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
16787 input_section
, rel
->r_offset
);
16788 if (out_off
== (bfd_vma
) -1)
16790 else if (out_off
== (bfd_vma
) -2)
16791 skip
= true, relocate
= true;
16792 out_off
+= (input_section
->output_section
->vma
16793 + input_section
->output_offset
);
16794 outrel
.r_offset
= out_off
;
16795 outrel
.r_addend
= rel
->r_addend
;
16797 /* Optimize unaligned reloc use. */
16798 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
16799 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
16800 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
16801 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
16802 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
16803 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
16804 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
16805 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
16806 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
16809 memset (&outrel
, 0, sizeof outrel
);
16811 && !SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16813 && r_type
!= R_PPC64_TOC
)
16815 indx
= h
->elf
.dynindx
;
16816 BFD_ASSERT (indx
!= -1);
16817 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
16821 /* This symbol is local, or marked to become local,
16822 or this is an opd section reloc which must point
16823 at a local function. */
16824 outrel
.r_addend
+= relocation
;
16825 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
16827 if (is_opd
&& h
!= NULL
)
16829 /* Lie about opd entries. This case occurs
16830 when building shared libraries and we
16831 reference a function in another shared
16832 lib. The same thing happens for a weak
16833 definition in an application that's
16834 overridden by a strong definition in a
16835 shared lib. (I believe this is a generic
16836 bug in binutils handling of weak syms.)
16837 In these cases we won't use the opd
16838 entry in this lib. */
16839 unresolved_reloc
= false;
16842 && r_type
== R_PPC64_ADDR64
16844 ? h
->elf
.type
== STT_GNU_IFUNC
16845 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
16846 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16849 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16851 /* We need to relocate .opd contents for ld.so.
16852 Prelink also wants simple and consistent rules
16853 for relocs. This make all RELATIVE relocs have
16854 *r_offset equal to r_addend. */
16861 ? h
->elf
.type
== STT_GNU_IFUNC
16862 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16864 info
->callbacks
->einfo
16865 /* xgettext:c-format */
16866 (_("%H: %s for indirect "
16867 "function `%pT' unsupported\n"),
16868 input_bfd
, input_section
, rel
->r_offset
,
16869 ppc64_elf_howto_table
[r_type
]->name
,
16873 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
16875 else if (sec
== NULL
|| sec
->owner
== NULL
)
16877 bfd_set_error (bfd_error_bad_value
);
16882 asection
*osec
= sec
->output_section
;
16884 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
16886 /* TLS symbol values are relative to the
16887 TLS segment. Dynamic relocations for
16888 local TLS symbols therefore can't be
16889 reduced to a relocation against their
16890 section symbol because it holds the
16891 address of the section, not a value
16892 relative to the TLS segment. We could
16893 change the .tdata dynamic section symbol
16894 to be zero value but STN_UNDEF works
16895 and is used elsewhere, eg. for TPREL64
16896 GOT relocs against local TLS symbols. */
16897 osec
= htab
->elf
.tls_sec
;
16902 indx
= elf_section_data (osec
)->dynindx
;
16905 if ((osec
->flags
& SEC_READONLY
) == 0
16906 && htab
->elf
.data_index_section
!= NULL
)
16907 osec
= htab
->elf
.data_index_section
;
16909 osec
= htab
->elf
.text_index_section
;
16910 indx
= elf_section_data (osec
)->dynindx
;
16912 BFD_ASSERT (indx
!= 0);
16915 /* We are turning this relocation into one
16916 against a section symbol, so subtract out
16917 the output section's address but not the
16918 offset of the input section in the output
16920 outrel
.r_addend
-= osec
->vma
;
16923 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
16927 sreloc
= elf_section_data (input_section
)->sreloc
;
16929 ? h
->elf
.type
== STT_GNU_IFUNC
16930 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16932 sreloc
= htab
->elf
.irelplt
;
16933 if (indx
== 0 || is_static_defined (&h
->elf
))
16934 htab
->elf
.ifunc_resolvers
= true;
16936 if (sreloc
== NULL
)
16939 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
16942 loc
= sreloc
->contents
;
16943 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
16944 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16946 if (!warned_dynamic
16947 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel
.r_info
)))
16949 info
->callbacks
->einfo
16950 /* xgettext:c-format */
16951 (_("%X%P: %pB: %s against %pT "
16952 "is not supported by glibc as a dynamic relocation\n"),
16954 ppc64_elf_howto_table
[ELF64_R_TYPE (outrel
.r_info
)]->name
,
16956 warned_dynamic
= true;
16959 /* If this reloc is against an external symbol, it will
16960 be computed at runtime, so there's no need to do
16961 anything now. However, for the sake of prelink ensure
16962 that the section contents are a known value. */
16965 unresolved_reloc
= false;
16966 /* The value chosen here is quite arbitrary as ld.so
16967 ignores section contents except for the special
16968 case of .opd where the contents might be accessed
16969 before relocation. Choose zero, as that won't
16970 cause reloc overflow. */
16973 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
16974 to improve backward compatibility with older
16976 if (r_type
== R_PPC64_ADDR64
)
16977 addend
= outrel
.r_addend
;
16978 /* Adjust pc_relative relocs to have zero in *r_offset. */
16979 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
16980 addend
= outrel
.r_offset
;
16986 case R_PPC64_GLOB_DAT
:
16987 case R_PPC64_JMP_SLOT
:
16988 case R_PPC64_JMP_IREL
:
16989 case R_PPC64_RELATIVE
:
16990 /* We shouldn't ever see these dynamic relocs in relocatable
16992 /* Fall through. */
16994 case R_PPC64_PLTGOT16
:
16995 case R_PPC64_PLTGOT16_DS
:
16996 case R_PPC64_PLTGOT16_HA
:
16997 case R_PPC64_PLTGOT16_HI
:
16998 case R_PPC64_PLTGOT16_LO
:
16999 case R_PPC64_PLTGOT16_LO_DS
:
17000 case R_PPC64_PLTREL32
:
17001 case R_PPC64_PLTREL64
:
17002 /* These ones haven't been implemented yet. */
17004 info
->callbacks
->einfo
17005 /* xgettext:c-format */
17006 (_("%P: %pB: %s is not supported for `%pT'\n"),
17008 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
17010 bfd_set_error (bfd_error_invalid_operation
);
17015 /* Multi-instruction sequences that access the TOC can be
17016 optimized, eg. addis ra,r2,0; addi rb,ra,x;
17017 to nop; addi rb,r2,x; */
17023 case R_PPC64_GOT_TLSLD16_HI
:
17024 case R_PPC64_GOT_TLSGD16_HI
:
17025 case R_PPC64_GOT_TPREL16_HI
:
17026 case R_PPC64_GOT_DTPREL16_HI
:
17027 case R_PPC64_GOT16_HI
:
17028 case R_PPC64_TOC16_HI
:
17029 /* These relocs would only be useful if building up an
17030 offset to later add to r2, perhaps in an indexed
17031 addressing mode instruction. Don't try to optimize.
17032 Unfortunately, the possibility of someone building up an
17033 offset like this or even with the HA relocs, means that
17034 we need to check the high insn when optimizing the low
17038 case R_PPC64_PLTCALL_NOTOC
:
17039 if (!unresolved_reloc
)
17040 htab
->notoc_plt
= 1;
17041 /* Fall through. */
17042 case R_PPC64_PLTCALL
:
17043 if (unresolved_reloc
17044 && offset_in_range (input_section
, rel
->r_offset
,
17045 r_type
== R_PPC64_PLTCALL
? 8 : 4))
17047 /* No plt entry. Make this into a direct call. */
17048 bfd_byte
*p
= contents
+ rel
->r_offset
;
17049 insn
= bfd_get_32 (input_bfd
, p
);
17051 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
17052 if (r_type
== R_PPC64_PLTCALL
)
17053 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
17054 unresolved_reloc
= save_unresolved_reloc
;
17055 r_type
= R_PPC64_REL24
;
17059 case R_PPC64_PLTSEQ_NOTOC
:
17060 case R_PPC64_PLTSEQ
:
17061 if (unresolved_reloc
)
17063 unresolved_reloc
= false;
17068 case R_PPC64_PLT_PCREL34_NOTOC
:
17069 if (!unresolved_reloc
)
17070 htab
->notoc_plt
= 1;
17071 /* Fall through. */
17072 case R_PPC64_PLT_PCREL34
:
17073 if (unresolved_reloc
17074 && offset_in_range (input_section
, rel
->r_offset
, 8))
17076 bfd_byte
*p
= contents
+ rel
->r_offset
;
17077 bfd_put_32 (input_bfd
, PNOP
>> 32, p
);
17078 bfd_put_32 (input_bfd
, PNOP
, p
+ 4);
17079 unresolved_reloc
= false;
17084 case R_PPC64_PLT16_HA
:
17085 if (unresolved_reloc
)
17087 unresolved_reloc
= false;
17090 /* Fall through. */
17091 case R_PPC64_GOT_TLSLD16_HA
:
17092 case R_PPC64_GOT_TLSGD16_HA
:
17093 case R_PPC64_GOT_TPREL16_HA
:
17094 case R_PPC64_GOT_DTPREL16_HA
:
17095 case R_PPC64_GOT16_HA
:
17096 case R_PPC64_TOC16_HA
:
17097 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17098 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
17102 if (offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17104 p
= contents
+ (rel
->r_offset
& ~3);
17105 bfd_put_32 (input_bfd
, NOP
, p
);
17111 case R_PPC64_PLT16_LO
:
17112 case R_PPC64_PLT16_LO_DS
:
17113 if (unresolved_reloc
)
17115 unresolved_reloc
= false;
17118 /* Fall through. */
17119 case R_PPC64_GOT_TLSLD16_LO
:
17120 case R_PPC64_GOT_TLSGD16_LO
:
17121 case R_PPC64_GOT_TPREL16_LO_DS
:
17122 case R_PPC64_GOT_DTPREL16_LO_DS
:
17123 case R_PPC64_GOT16_LO
:
17124 case R_PPC64_GOT16_LO_DS
:
17125 case R_PPC64_TOC16_LO
:
17126 case R_PPC64_TOC16_LO_DS
:
17127 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17128 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
17129 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17131 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17132 insn
= bfd_get_32 (input_bfd
, p
);
17133 if ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */)
17135 /* Transform addic to addi when we change reg. */
17136 insn
&= ~((0x3fu
<< 26) | (0x1f << 16));
17137 insn
|= (14u << 26) | (2 << 16);
17141 insn
&= ~(0x1f << 16);
17144 bfd_put_32 (input_bfd
, insn
, p
);
17148 case R_PPC64_TPREL16_HA
:
17149 if (htab
->do_tls_opt
17150 && relocation
+ addend
+ 0x8000 < 0x10000
17151 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17153 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17154 bfd_put_32 (input_bfd
, NOP
, p
);
17159 case R_PPC64_TPREL16_LO
:
17160 case R_PPC64_TPREL16_LO_DS
:
17161 if (htab
->do_tls_opt
17162 && relocation
+ addend
+ 0x8000 < 0x10000
17163 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17165 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17166 insn
= bfd_get_32 (input_bfd
, p
);
17167 insn
&= ~(0x1f << 16);
17169 bfd_put_32 (input_bfd
, insn
, p
);
17174 /* Do any further special processing. */
17180 case R_PPC64_REL16_HA
:
17181 case R_PPC64_REL16_HIGHA
:
17182 case R_PPC64_REL16_HIGHERA
:
17183 case R_PPC64_REL16_HIGHESTA
:
17184 case R_PPC64_REL16DX_HA
:
17185 case R_PPC64_ADDR16_HA
:
17186 case R_PPC64_ADDR16_HIGHA
:
17187 case R_PPC64_ADDR16_HIGHERA
:
17188 case R_PPC64_ADDR16_HIGHESTA
:
17189 case R_PPC64_TOC16_HA
:
17190 case R_PPC64_SECTOFF_HA
:
17191 case R_PPC64_TPREL16_HA
:
17192 case R_PPC64_TPREL16_HIGHA
:
17193 case R_PPC64_TPREL16_HIGHERA
:
17194 case R_PPC64_TPREL16_HIGHESTA
:
17195 case R_PPC64_DTPREL16_HA
:
17196 case R_PPC64_DTPREL16_HIGHA
:
17197 case R_PPC64_DTPREL16_HIGHERA
:
17198 case R_PPC64_DTPREL16_HIGHESTA
:
17199 /* It's just possible that this symbol is a weak symbol
17200 that's not actually defined anywhere. In that case,
17201 'sec' would be NULL, and we should leave the symbol
17202 alone (it will be set to zero elsewhere in the link). */
17205 /* Fall through. */
17207 case R_PPC64_GOT16_HA
:
17208 case R_PPC64_PLTGOT16_HA
:
17209 case R_PPC64_PLT16_HA
:
17210 case R_PPC64_GOT_TLSGD16_HA
:
17211 case R_PPC64_GOT_TLSLD16_HA
:
17212 case R_PPC64_GOT_TPREL16_HA
:
17213 case R_PPC64_GOT_DTPREL16_HA
:
17214 /* Add 0x10000 if sign bit in 0:15 is set.
17215 Bits 0:15 are not used. */
17219 case R_PPC64_D34_HA30
:
17220 case R_PPC64_ADDR16_HIGHERA34
:
17221 case R_PPC64_ADDR16_HIGHESTA34
:
17222 case R_PPC64_REL16_HIGHERA34
:
17223 case R_PPC64_REL16_HIGHESTA34
:
17225 addend
+= 1ULL << 33;
17228 case R_PPC64_ADDR16_DS
:
17229 case R_PPC64_ADDR16_LO_DS
:
17230 case R_PPC64_GOT16_DS
:
17231 case R_PPC64_GOT16_LO_DS
:
17232 case R_PPC64_PLT16_LO_DS
:
17233 case R_PPC64_SECTOFF_DS
:
17234 case R_PPC64_SECTOFF_LO_DS
:
17235 case R_PPC64_TOC16_DS
:
17236 case R_PPC64_TOC16_LO_DS
:
17237 case R_PPC64_PLTGOT16_DS
:
17238 case R_PPC64_PLTGOT16_LO_DS
:
17239 case R_PPC64_GOT_TPREL16_DS
:
17240 case R_PPC64_GOT_TPREL16_LO_DS
:
17241 case R_PPC64_GOT_DTPREL16_DS
:
17242 case R_PPC64_GOT_DTPREL16_LO_DS
:
17243 case R_PPC64_TPREL16_DS
:
17244 case R_PPC64_TPREL16_LO_DS
:
17245 case R_PPC64_DTPREL16_DS
:
17246 case R_PPC64_DTPREL16_LO_DS
:
17247 if (!offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17249 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17251 /* If this reloc is against an lq, lxv, or stxv insn, then
17252 the value must be a multiple of 16. This is somewhat of
17253 a hack, but the "correct" way to do this by defining _DQ
17254 forms of all the _DS relocs bloats all reloc switches in
17255 this file. It doesn't make much sense to use these
17256 relocs in data, so testing the insn should be safe. */
17257 if ((insn
& (0x3fu
<< 26)) == (56u << 26)
17258 || ((insn
& (0x3fu
<< 26)) == (61u << 26) && (insn
& 3) == 1))
17260 relocation
+= addend
;
17261 addend
= insn
& (mask
^ 3);
17262 if ((relocation
& mask
) != 0)
17264 relocation
^= relocation
& mask
;
17265 info
->callbacks
->einfo
17266 /* xgettext:c-format */
17267 (_("%H: error: %s not a multiple of %u\n"),
17268 input_bfd
, input_section
, rel
->r_offset
,
17269 ppc64_elf_howto_table
[r_type
]->name
,
17271 bfd_set_error (bfd_error_bad_value
);
17278 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
17279 because such sections are not SEC_ALLOC and thus ld.so will
17280 not process them. */
17281 howto
= ppc64_elf_howto_table
[(int) r_type
];
17282 if (unresolved_reloc
17283 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
17284 && h
->elf
.def_dynamic
)
17285 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
17286 rel
->r_offset
) != (bfd_vma
) -1)
17288 info
->callbacks
->einfo
17289 /* xgettext:c-format */
17290 (_("%H: unresolvable %s against `%pT'\n"),
17291 input_bfd
, input_section
, rel
->r_offset
,
17293 h
->elf
.root
.root
.string
);
17297 /* 16-bit fields in insns mostly have signed values, but a
17298 few insns have 16-bit unsigned values. Really, we should
17299 have different reloc types. */
17300 if (howto
->complain_on_overflow
!= complain_overflow_dont
17301 && howto
->dst_mask
== 0xffff
17302 && (input_section
->flags
& SEC_CODE
) != 0
17303 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17305 enum complain_overflow complain
= complain_overflow_signed
;
17307 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17308 if ((insn
& (0x3fu
<< 26)) == 10u << 26 /* cmpli */)
17309 complain
= complain_overflow_bitfield
;
17310 else if (howto
->rightshift
== 0
17311 ? ((insn
& (0x3fu
<< 26)) == 28u << 26 /* andi */
17312 || (insn
& (0x3fu
<< 26)) == 24u << 26 /* ori */
17313 || (insn
& (0x3fu
<< 26)) == 26u << 26 /* xori */)
17314 : ((insn
& (0x3fu
<< 26)) == 29u << 26 /* andis */
17315 || (insn
& (0x3fu
<< 26)) == 25u << 26 /* oris */
17316 || (insn
& (0x3fu
<< 26)) == 27u << 26 /* xoris */))
17317 complain
= complain_overflow_unsigned
;
17318 if (howto
->complain_on_overflow
!= complain
)
17320 alt_howto
= *howto
;
17321 alt_howto
.complain_on_overflow
= complain
;
17322 howto
= &alt_howto
;
17328 /* Split field relocs aren't handled by _bfd_final_link_relocate. */
17330 case R_PPC64_D34_LO
:
17331 case R_PPC64_D34_HI30
:
17332 case R_PPC64_D34_HA30
:
17333 case R_PPC64_PCREL34
:
17334 case R_PPC64_GOT_PCREL34
:
17335 case R_PPC64_TPREL34
:
17336 case R_PPC64_DTPREL34
:
17337 case R_PPC64_GOT_TLSGD_PCREL34
:
17338 case R_PPC64_GOT_TLSLD_PCREL34
:
17339 case R_PPC64_GOT_TPREL_PCREL34
:
17340 case R_PPC64_GOT_DTPREL_PCREL34
:
17341 case R_PPC64_PLT_PCREL34
:
17342 case R_PPC64_PLT_PCREL34_NOTOC
:
17344 case R_PPC64_PCREL28
:
17345 if (!offset_in_range (input_section
, rel
->r_offset
, 8))
17346 r
= bfd_reloc_outofrange
;
17349 relocation
+= addend
;
17350 if (howto
->pc_relative
)
17351 relocation
-= (rel
->r_offset
17352 + input_section
->output_offset
17353 + input_section
->output_section
->vma
);
17354 relocation
>>= howto
->rightshift
;
17356 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17358 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
17360 pinsn
&= ~howto
->dst_mask
;
17361 pinsn
|= (((relocation
<< 16) | (relocation
& 0xffff))
17362 & howto
->dst_mask
);
17363 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ rel
->r_offset
);
17364 bfd_put_32 (input_bfd
, pinsn
, contents
+ rel
->r_offset
+ 4);
17366 if (howto
->complain_on_overflow
== complain_overflow_signed
17367 && (relocation
+ (1ULL << (howto
->bitsize
- 1))
17368 >= 1ULL << howto
->bitsize
))
17369 r
= bfd_reloc_overflow
;
17373 case R_PPC64_REL16DX_HA
:
17374 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
17375 r
= bfd_reloc_outofrange
;
17378 relocation
+= addend
;
17379 relocation
-= (rel
->r_offset
17380 + input_section
->output_offset
17381 + input_section
->output_section
->vma
);
17382 relocation
= (bfd_signed_vma
) relocation
>> 16;
17383 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17385 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
17386 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
17388 if (relocation
+ 0x8000 > 0xffff)
17389 r
= bfd_reloc_overflow
;
17394 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
17395 contents
, rel
->r_offset
,
17396 relocation
, addend
);
17399 if (r
!= bfd_reloc_ok
)
17401 char *more_info
= NULL
;
17402 const char *reloc_name
= howto
->name
;
17404 if (reloc_dest
!= DEST_NORMAL
)
17406 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
17407 if (more_info
!= NULL
)
17409 strcpy (more_info
, reloc_name
);
17410 strcat (more_info
, (reloc_dest
== DEST_OPD
17411 ? " (OPD)" : " (stub)"));
17412 reloc_name
= more_info
;
17416 if (r
== bfd_reloc_overflow
)
17418 /* On code like "if (foo) foo();" don't report overflow
17419 on a branch to zero when foo is undefined. */
17421 && (reloc_dest
== DEST_STUB
17423 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
17424 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
17425 && is_branch_reloc (r_type
))))
17426 info
->callbacks
->reloc_overflow
17427 (info
, (struct bfd_link_hash_entry
*) h
, sym_name
,
17428 reloc_name
, orig_rel
.r_addend
, input_bfd
, input_section
,
17433 info
->callbacks
->einfo
17434 /* xgettext:c-format */
17435 (_("%H: %s against `%pT': error %d\n"),
17436 input_bfd
, input_section
, rel
->r_offset
,
17437 reloc_name
, sym_name
, (int) r
);
17449 Elf_Internal_Shdr
*rel_hdr
;
17450 size_t deleted
= rel
- wrel
;
17452 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
17453 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17454 if (rel_hdr
->sh_size
== 0)
17456 /* It is too late to remove an empty reloc section. Leave
17458 ??? What is wrong with an empty section??? */
17459 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
17462 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
17463 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17464 input_section
->reloc_count
-= deleted
;
17467 /* If we're emitting relocations, then shortly after this function
17468 returns, reloc offsets and addends for this section will be
17469 adjusted. Worse, reloc symbol indices will be for the output
17470 file rather than the input. Save a copy of the relocs for
17471 opd_entry_value. */
17472 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
17475 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
17476 rel
= bfd_alloc (input_bfd
, amt
);
17477 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
17478 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
17481 memcpy (rel
, relocs
, amt
);
17486 /* Adjust the value of any local symbols in opd sections. */
17489 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
17490 const char *name ATTRIBUTE_UNUSED
,
17491 Elf_Internal_Sym
*elfsym
,
17492 asection
*input_sec
,
17493 struct elf_link_hash_entry
*h
)
17495 struct _opd_sec_data
*opd
;
17502 opd
= get_opd_info (input_sec
);
17503 if (opd
== NULL
|| opd
->adjust
== NULL
)
17506 value
= elfsym
->st_value
- input_sec
->output_offset
;
17507 if (!bfd_link_relocatable (info
))
17508 value
-= input_sec
->output_section
->vma
;
17510 adjust
= opd
->adjust
[OPD_NDX (value
)];
17514 elfsym
->st_value
+= adjust
;
17518 /* Finish up dynamic symbol handling. We set the contents of various
17519 dynamic sections here. */
17522 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
17523 struct bfd_link_info
*info
,
17524 struct elf_link_hash_entry
*h
,
17525 Elf_Internal_Sym
*sym
)
17527 struct ppc_link_hash_table
*htab
;
17528 struct plt_entry
*ent
;
17530 htab
= ppc_hash_table (info
);
17534 if (!htab
->opd_abi
&& !h
->def_regular
)
17535 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
17536 if (ent
->plt
.offset
!= (bfd_vma
) -1)
17538 /* Mark the symbol as undefined, rather than as
17539 defined in glink. Leave the value if there were
17540 any relocations where pointer equality matters
17541 (this is a clue for the dynamic linker, to make
17542 function pointer comparisons work between an
17543 application and shared library), otherwise set it
17545 sym
->st_shndx
= SHN_UNDEF
;
17546 if (!h
->pointer_equality_needed
)
17548 else if (!h
->ref_regular_nonweak
)
17550 /* This breaks function pointer comparisons, but
17551 that is better than breaking tests for a NULL
17552 function pointer. */
17559 && (h
->root
.type
== bfd_link_hash_defined
17560 || h
->root
.type
== bfd_link_hash_defweak
)
17561 && (h
->root
.u
.def
.section
== htab
->elf
.sdynbss
17562 || h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
))
17564 /* This symbol needs a copy reloc. Set it up. */
17565 Elf_Internal_Rela rela
;
17569 if (h
->dynindx
== -1)
17572 rela
.r_offset
= defined_sym_val (h
);
17573 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
17575 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
17576 srel
= htab
->elf
.sreldynrelro
;
17578 srel
= htab
->elf
.srelbss
;
17579 loc
= srel
->contents
;
17580 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
17581 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
17587 /* Used to decide how to sort relocs in an optimal manner for the
17588 dynamic linker, before writing them out. */
17590 static enum elf_reloc_type_class
17591 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
17592 const asection
*rel_sec
,
17593 const Elf_Internal_Rela
*rela
)
17595 enum elf_ppc64_reloc_type r_type
;
17596 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
17598 if (rel_sec
== htab
->elf
.irelplt
)
17599 return reloc_class_ifunc
;
17601 r_type
= ELF64_R_TYPE (rela
->r_info
);
17604 case R_PPC64_RELATIVE
:
17605 return reloc_class_relative
;
17606 case R_PPC64_JMP_SLOT
:
17607 return reloc_class_plt
;
17609 return reloc_class_copy
;
17611 return reloc_class_normal
;
17615 /* Finish up the dynamic sections. */
17618 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
17619 struct bfd_link_info
*info
)
17621 struct ppc_link_hash_table
*htab
;
17625 htab
= ppc_hash_table (info
);
17629 dynobj
= htab
->elf
.dynobj
;
17630 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
17632 if (htab
->elf
.dynamic_sections_created
)
17634 Elf64_External_Dyn
*dyncon
, *dynconend
;
17636 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
17639 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
17640 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
17641 for (; dyncon
< dynconend
; dyncon
++)
17643 Elf_Internal_Dyn dyn
;
17646 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
17653 case DT_PPC64_GLINK
:
17655 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17656 /* We stupidly defined DT_PPC64_GLINK to be the start
17657 of glink rather than the first entry point, which is
17658 what ld.so needs, and now have a bigger stub to
17659 support automatic multiple TOCs. */
17660 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
17664 s
= bfd_get_section_by_name (output_bfd
, ".opd");
17667 dyn
.d_un
.d_ptr
= s
->vma
;
17671 if ((htab
->do_multi_toc
&& htab
->multi_toc_needed
)
17672 || htab
->notoc_plt
)
17673 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
17674 if (htab
->has_plt_localentry0
)
17675 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
17678 case DT_PPC64_OPDSZ
:
17679 s
= bfd_get_section_by_name (output_bfd
, ".opd");
17682 dyn
.d_un
.d_val
= s
->size
;
17686 s
= htab
->elf
.splt
;
17687 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17691 s
= htab
->elf
.srelplt
;
17692 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
17696 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
17700 if (htab
->elf
.ifunc_resolvers
)
17701 info
->callbacks
->einfo
17702 (_("%P: warning: text relocations and GNU indirect "
17703 "functions may result in a segfault at runtime\n"));
17707 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17711 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
17712 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
17714 /* Fill in the first entry in the global offset table.
17715 We use it to hold the link-time TOCbase. */
17716 bfd_put_64 (output_bfd
,
17717 elf_gp (output_bfd
) + TOC_BASE_OFF
,
17718 htab
->elf
.sgot
->contents
);
17720 /* Set .got entry size. */
17721 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
17725 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
17726 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
17728 /* Set .plt entry size. */
17729 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
17730 = PLT_ENTRY_SIZE (htab
);
17733 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
17734 brlt ourselves if emitrelocations. */
17735 if (htab
->brlt
!= NULL
17736 && htab
->brlt
->reloc_count
!= 0
17737 && !_bfd_elf_link_output_relocs (output_bfd
,
17739 elf_section_data (htab
->brlt
)->rela
.hdr
,
17740 elf_section_data (htab
->brlt
)->relocs
,
17744 if (htab
->glink
!= NULL
17745 && htab
->glink
->reloc_count
!= 0
17746 && !_bfd_elf_link_output_relocs (output_bfd
,
17748 elf_section_data (htab
->glink
)->rela
.hdr
,
17749 elf_section_data (htab
->glink
)->relocs
,
17754 if (htab
->glink_eh_frame
!= NULL
17755 && htab
->glink_eh_frame
->size
!= 0
17756 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
17757 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
17758 htab
->glink_eh_frame
,
17759 htab
->glink_eh_frame
->contents
))
17762 /* We need to handle writing out multiple GOT sections ourselves,
17763 since we didn't add them to DYNOBJ. We know dynobj is the first
17765 while ((dynobj
= dynobj
->link
.next
) != NULL
)
17769 if (!is_ppc64_elf (dynobj
))
17772 s
= ppc64_elf_tdata (dynobj
)->got
;
17775 && s
->output_section
!= bfd_abs_section_ptr
17776 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
17777 s
->contents
, s
->output_offset
,
17780 s
= ppc64_elf_tdata (dynobj
)->relgot
;
17783 && s
->output_section
!= bfd_abs_section_ptr
17784 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
17785 s
->contents
, s
->output_offset
,
17793 #include "elf64-target.h"
17795 /* FreeBSD support */
17797 #undef TARGET_LITTLE_SYM
17798 #define TARGET_LITTLE_SYM powerpc_elf64_fbsd_le_vec
17799 #undef TARGET_LITTLE_NAME
17800 #define TARGET_LITTLE_NAME "elf64-powerpcle-freebsd"
17802 #undef TARGET_BIG_SYM
17803 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
17804 #undef TARGET_BIG_NAME
17805 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
17808 #define ELF_OSABI ELFOSABI_FREEBSD
17811 #define elf64_bed elf64_powerpc_fbsd_bed
17813 #include "elf64-target.h"