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. */
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. */
3108 /* Number of pc-relative relocs copied for the input section. */
3109 unsigned int pc_count
;
3111 /* Number of relocs that might become R_PPC64_RELATIVE. */
3112 unsigned int rel_count
;
3115 struct ppc_local_dyn_relocs
3117 struct ppc_local_dyn_relocs
*next
;
3119 /* The input section of the reloc. */
3122 /* Total number of relocs copied for the input section. */
3125 /* Number of relocs that might become R_PPC64_RELATIVE. */
3126 unsigned int rel_count
: 31;
3128 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3129 unsigned int ifunc
: 1;
3132 struct ppc_link_hash_entry
3134 struct elf_link_hash_entry elf
;
3138 /* A pointer to the most recently used stub hash entry against this
3140 struct ppc_stub_hash_entry
*stub_cache
;
3142 /* A pointer to the next symbol starting with a '.' */
3143 struct ppc_link_hash_entry
*next_dot_sym
;
3146 /* Link between function code and descriptor symbols. */
3147 struct ppc_link_hash_entry
*oh
;
3149 /* Flag function code and descriptor symbols. */
3150 unsigned int is_func
:1;
3151 unsigned int is_func_descriptor
:1;
3152 unsigned int fake
:1;
3154 /* Whether global opd/toc sym has been adjusted or not.
3155 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3156 should be set for all globals defined in any opd/toc section. */
3157 unsigned int adjust_done
:1;
3159 /* Set if this is an out-of-line register save/restore function,
3160 with non-standard calling convention. */
3161 unsigned int save_res
:1;
3163 /* Set if a duplicate symbol with non-zero localentry is detected,
3164 even when the duplicate symbol does not provide a definition. */
3165 unsigned int non_zero_localentry
:1;
3167 /* Contexts in which symbol is used in the GOT (or TOC).
3168 Bits are or'd into the mask as the corresponding relocs are
3169 encountered during check_relocs, with TLS_TLS being set when any
3170 of the other TLS bits are set. tls_optimize clears bits when
3171 optimizing to indicate the corresponding GOT entry type is not
3172 needed. If set, TLS_TLS is never cleared. tls_optimize may also
3173 set TLS_GDIE when a GD reloc turns into an IE one.
3174 These flags are also kept for local symbols. */
3175 #define TLS_TLS 1 /* Any TLS reloc. */
3176 #define TLS_GD 2 /* GD reloc. */
3177 #define TLS_LD 4 /* LD reloc. */
3178 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
3179 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
3180 #define TLS_MARK 32 /* __tls_get_addr call marked. */
3181 #define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
3182 #define TLS_EXPLICIT 256 /* TOC section TLS reloc, not stored. */
3183 unsigned char tls_mask
;
3185 /* The above field is also used to mark function symbols. In which
3186 case TLS_TLS will be 0. */
3187 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
3188 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
3189 #define NON_GOT 256 /* local symbol plt, not stored. */
3192 static inline struct ppc_link_hash_entry
*
3193 ppc_elf_hash_entry (struct elf_link_hash_entry
*ent
)
3195 return (struct ppc_link_hash_entry
*) ent
;
3198 static inline struct elf_link_hash_entry
*
3199 elf_hash_entry (struct ppc_link_hash_entry
*ent
)
3201 return (struct elf_link_hash_entry
*) ent
;
3204 /* ppc64 ELF linker hash table. */
3206 struct ppc_link_hash_table
3208 struct elf_link_hash_table elf
;
3210 /* The stub hash table. */
3211 struct bfd_hash_table stub_hash_table
;
3213 /* Another hash table for plt_branch stubs. */
3214 struct bfd_hash_table branch_hash_table
;
3216 /* Hash table for function prologue tocsave. */
3217 htab_t tocsave_htab
;
3219 /* Various options and other info passed from the linker. */
3220 struct ppc64_elf_params
*params
;
3222 /* The size of sec_info below. */
3223 unsigned int sec_info_arr_size
;
3225 /* Per-section array of extra section info. Done this way rather
3226 than as part of ppc64_elf_section_data so we have the info for
3227 non-ppc64 sections. */
3230 /* Along with elf_gp, specifies the TOC pointer used by this section. */
3235 /* The section group that this section belongs to. */
3236 struct map_stub
*group
;
3237 /* A temp section list pointer. */
3242 /* Linked list of groups. */
3243 struct map_stub
*group
;
3245 /* Temp used when calculating TOC pointers. */
3248 asection
*toc_first_sec
;
3250 /* Used when adding symbols. */
3251 struct ppc_link_hash_entry
*dot_syms
;
3253 /* Shortcuts to get to dynamic linker sections. */
3255 asection
*global_entry
;
3258 asection
*relpltlocal
;
3261 asection
*glink_eh_frame
;
3263 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3264 struct ppc_link_hash_entry
*tls_get_addr
;
3265 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3266 struct ppc_link_hash_entry
*tga_desc
;
3267 struct ppc_link_hash_entry
*tga_desc_fd
;
3268 struct map_stub
*tga_group
;
3270 /* The size of reliplt used by got entry relocs. */
3271 bfd_size_type got_reli_size
;
3273 /* DT_RELR array of r_offset. */
3279 unsigned long stub_count
[ppc_stub_save_res
];
3281 /* Number of stubs against global syms. */
3282 unsigned long stub_globals
;
3284 /* Set if we're linking code with function descriptors. */
3285 unsigned int opd_abi
:1;
3287 /* Support for multiple toc sections. */
3288 unsigned int do_multi_toc
:1;
3289 unsigned int multi_toc_needed
:1;
3290 unsigned int second_toc_pass
:1;
3291 unsigned int do_toc_opt
:1;
3293 /* Set if tls optimization is enabled. */
3294 unsigned int do_tls_opt
:1;
3296 /* Set if inline plt calls should be converted to direct calls. */
3297 unsigned int can_convert_all_inline_plt
:1;
3300 unsigned int stub_error
:1;
3302 /* Whether func_desc_adjust needs to be run over symbols. */
3303 unsigned int need_func_desc_adj
:1;
3305 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
3306 unsigned int has_plt_localentry0
:1;
3308 /* Whether calls are made via the PLT from NOTOC functions. */
3309 unsigned int notoc_plt
:1;
3311 /* Whether any code linked seems to be Power10. */
3312 unsigned int has_power10_relocs
:1;
3314 /* Incremented every time we size stubs. */
3315 unsigned int stub_iteration
;
3318 /* Rename some of the generic section flags to better document how they
3321 /* Nonzero if this section has TLS related relocations. */
3322 #define has_tls_reloc sec_flg0
3324 /* Nonzero if this section has a call to __tls_get_addr lacking marker
3326 #define nomark_tls_get_addr sec_flg1
3328 /* Nonzero if this section has any toc or got relocs. */
3329 #define has_toc_reloc sec_flg2
3331 /* Nonzero if this section has a call to another section that uses
3333 #define makes_toc_func_call sec_flg3
3335 /* Recursion protection when determining above flag. */
3336 #define call_check_in_progress sec_flg4
3337 #define call_check_done sec_flg5
3339 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3341 #define ppc_hash_table(p) \
3342 ((is_elf_hash_table ((p)->hash) \
3343 && elf_hash_table_id (elf_hash_table (p)) == PPC64_ELF_DATA) \
3344 ? (struct ppc_link_hash_table *) (p)->hash : NULL)
3346 #define ppc_stub_hash_lookup(table, string, create, copy) \
3347 ((struct ppc_stub_hash_entry *) \
3348 bfd_hash_lookup ((table), (string), (create), (copy)))
3350 #define ppc_branch_hash_lookup(table, string, create, copy) \
3351 ((struct ppc_branch_hash_entry *) \
3352 bfd_hash_lookup ((table), (string), (create), (copy)))
3354 /* Create an entry in the stub hash table. */
3356 static struct bfd_hash_entry
*
3357 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3358 struct bfd_hash_table
*table
,
3361 /* Allocate the structure if it has not already been allocated by a
3365 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3370 /* Call the allocation method of the superclass. */
3371 entry
= bfd_hash_newfunc (entry
, table
, string
);
3374 struct ppc_stub_hash_entry
*eh
;
3376 /* Initialize the local fields. */
3377 eh
= (struct ppc_stub_hash_entry
*) entry
;
3378 eh
->type
.main
= ppc_stub_none
;
3379 eh
->type
.sub
= ppc_stub_toc
;
3380 eh
->type
.r2save
= 0;
3382 eh
->stub_offset
= 0;
3383 eh
->target_value
= 0;
3384 eh
->target_section
= NULL
;
3393 /* Create an entry in the branch hash table. */
3395 static struct bfd_hash_entry
*
3396 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3397 struct bfd_hash_table
*table
,
3400 /* Allocate the structure if it has not already been allocated by a
3404 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3409 /* Call the allocation method of the superclass. */
3410 entry
= bfd_hash_newfunc (entry
, table
, string
);
3413 struct ppc_branch_hash_entry
*eh
;
3415 /* Initialize the local fields. */
3416 eh
= (struct ppc_branch_hash_entry
*) entry
;
3424 /* Create an entry in a ppc64 ELF linker hash table. */
3426 static struct bfd_hash_entry
*
3427 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3428 struct bfd_hash_table
*table
,
3431 /* Allocate the structure if it has not already been allocated by a
3435 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3440 /* Call the allocation method of the superclass. */
3441 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3444 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3446 memset (&eh
->u
.stub_cache
, 0,
3447 (sizeof (struct ppc_link_hash_entry
)
3448 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3450 /* When making function calls, old ABI code references function entry
3451 points (dot symbols), while new ABI code references the function
3452 descriptor symbol. We need to make any combination of reference and
3453 definition work together, without breaking archive linking.
3455 For a defined function "foo" and an undefined call to "bar":
3456 An old object defines "foo" and ".foo", references ".bar" (possibly
3458 A new object defines "foo" and references "bar".
3460 A new object thus has no problem with its undefined symbols being
3461 satisfied by definitions in an old object. On the other hand, the
3462 old object won't have ".bar" satisfied by a new object.
3464 Keep a list of newly added dot-symbols. */
3466 if (string
[0] == '.')
3468 struct ppc_link_hash_table
*htab
;
3470 htab
= (struct ppc_link_hash_table
*) table
;
3471 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3472 htab
->dot_syms
= eh
;
3479 struct tocsave_entry
3486 tocsave_htab_hash (const void *p
)
3488 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3489 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3493 tocsave_htab_eq (const void *p1
, const void *p2
)
3495 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3496 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3497 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3500 /* Destroy a ppc64 ELF linker hash table. */
3503 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3505 struct ppc_link_hash_table
*htab
;
3507 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3508 if (htab
->tocsave_htab
)
3509 htab_delete (htab
->tocsave_htab
);
3510 bfd_hash_table_free (&htab
->branch_hash_table
);
3511 bfd_hash_table_free (&htab
->stub_hash_table
);
3512 _bfd_elf_link_hash_table_free (obfd
);
3515 /* Create a ppc64 ELF linker hash table. */
3517 static struct bfd_link_hash_table
*
3518 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3520 struct ppc_link_hash_table
*htab
;
3521 size_t amt
= sizeof (struct ppc_link_hash_table
);
3523 htab
= bfd_zmalloc (amt
);
3527 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3528 sizeof (struct ppc_link_hash_entry
),
3535 /* Init the stub hash table too. */
3536 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3537 sizeof (struct ppc_stub_hash_entry
)))
3539 _bfd_elf_link_hash_table_free (abfd
);
3543 /* And the branch hash table. */
3544 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3545 sizeof (struct ppc_branch_hash_entry
)))
3547 bfd_hash_table_free (&htab
->stub_hash_table
);
3548 _bfd_elf_link_hash_table_free (abfd
);
3552 htab
->tocsave_htab
= htab_try_create (1024,
3556 if (htab
->tocsave_htab
== NULL
)
3558 ppc64_elf_link_hash_table_free (abfd
);
3561 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3563 /* Initializing two fields of the union is just cosmetic. We really
3564 only care about glist, but when compiled on a 32-bit host the
3565 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3566 debugger inspection of these fields look nicer. */
3567 htab
->elf
.init_got_refcount
.refcount
= 0;
3568 htab
->elf
.init_got_refcount
.glist
= NULL
;
3569 htab
->elf
.init_plt_refcount
.refcount
= 0;
3570 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3571 htab
->elf
.init_got_offset
.offset
= 0;
3572 htab
->elf
.init_got_offset
.glist
= NULL
;
3573 htab
->elf
.init_plt_offset
.offset
= 0;
3574 htab
->elf
.init_plt_offset
.glist
= NULL
;
3576 return &htab
->elf
.root
;
3579 /* Create sections for linker generated code. */
3582 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3584 struct ppc_link_hash_table
*htab
;
3587 htab
= ppc_hash_table (info
);
3589 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3590 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3591 if (htab
->params
->save_restore_funcs
)
3593 /* Create .sfpr for code to save and restore fp regs. */
3594 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3596 if (htab
->sfpr
== NULL
3597 || !bfd_set_section_alignment (htab
->sfpr
, 2))
3601 if (bfd_link_relocatable (info
))
3604 /* Create .glink for lazy dynamic linking support. */
3605 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3607 if (htab
->glink
== NULL
3608 || !bfd_set_section_alignment (htab
->glink
, 3))
3611 /* The part of .glink used by global entry stubs, separate so that
3612 it can be aligned appropriately without affecting htab->glink. */
3613 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3615 if (htab
->global_entry
== NULL
3616 || !bfd_set_section_alignment (htab
->global_entry
, 2))
3619 if (!info
->no_ld_generated_unwind_info
)
3621 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3622 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3623 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3626 if (htab
->glink_eh_frame
== NULL
3627 || !bfd_set_section_alignment (htab
->glink_eh_frame
, 2))
3631 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3632 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3633 if (htab
->elf
.iplt
== NULL
3634 || !bfd_set_section_alignment (htab
->elf
.iplt
, 3))
3637 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3638 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3640 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3641 if (htab
->elf
.irelplt
== NULL
3642 || !bfd_set_section_alignment (htab
->elf
.irelplt
, 3))
3645 /* Create branch lookup table for plt_branch stubs. */
3646 flags
= (SEC_ALLOC
| SEC_LOAD
3647 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3648 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3650 if (htab
->brlt
== NULL
3651 || !bfd_set_section_alignment (htab
->brlt
, 3))
3654 /* Local plt entries, put in .branch_lt but a separate section for
3656 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3658 if (htab
->pltlocal
== NULL
3659 || !bfd_set_section_alignment (htab
->pltlocal
, 3))
3662 if (!bfd_link_pic (info
))
3665 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3666 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3668 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3669 if (htab
->relbrlt
== NULL
3670 || !bfd_set_section_alignment (htab
->relbrlt
, 3))
3674 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3675 if (htab
->relpltlocal
== NULL
3676 || !bfd_set_section_alignment (htab
->relpltlocal
, 3))
3682 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3685 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3686 struct ppc64_elf_params
*params
)
3688 struct ppc_link_hash_table
*htab
;
3690 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3692 /* Always hook our dynamic sections into the first bfd, which is the
3693 linker created stub bfd. This ensures that the GOT header is at
3694 the start of the output TOC section. */
3695 htab
= ppc_hash_table (info
);
3696 htab
->elf
.dynobj
= params
->stub_bfd
;
3697 htab
->params
= params
;
3699 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3702 /* Build a name for an entry in the stub hash table. */
3705 ppc_stub_name (const asection
*input_section
,
3706 const asection
*sym_sec
,
3707 const struct ppc_link_hash_entry
*h
,
3708 const Elf_Internal_Rela
*rel
)
3713 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3714 offsets from a sym as a branch target? In fact, we could
3715 probably assume the addend is always zero. */
3716 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3720 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3721 stub_name
= bfd_malloc (len
);
3722 if (stub_name
== NULL
)
3725 len
= sprintf (stub_name
, "%08x.%s+%x",
3726 input_section
->id
& 0xffffffff,
3727 h
->elf
.root
.root
.string
,
3728 (int) rel
->r_addend
& 0xffffffff);
3732 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3733 stub_name
= bfd_malloc (len
);
3734 if (stub_name
== NULL
)
3737 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3738 input_section
->id
& 0xffffffff,
3739 sym_sec
->id
& 0xffffffff,
3740 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3741 (int) rel
->r_addend
& 0xffffffff);
3743 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3744 stub_name
[len
- 2] = 0;
3748 /* If mixing power10 with non-power10 code and --power10-stubs is not
3749 specified (or is auto) then there may be multiple stub types for any
3750 given symbol. Up to three classes of stubs are stored in separate
3751 stub_hash_table entries having the same key string. The entries
3752 will always be adjacent on entry->root.next chain, even if hash
3753 table resizing occurs. This function selects the correct entry to
3756 static struct ppc_stub_hash_entry
*
3757 select_alt_stub (struct ppc_stub_hash_entry
*entry
,
3758 enum elf_ppc64_reloc_type r_type
)
3760 enum ppc_stub_sub_type subt
;
3764 case R_PPC64_REL24_NOTOC
:
3765 subt
= ppc_stub_notoc
;
3767 case R_PPC64_REL24_P9NOTOC
:
3768 subt
= ppc_stub_p9notoc
;
3771 subt
= ppc_stub_toc
;
3775 while (entry
!= NULL
&& entry
->type
.sub
!= subt
)
3777 const char *stub_name
= entry
->root
.string
;
3779 entry
= (struct ppc_stub_hash_entry
*) entry
->root
.next
;
3781 && entry
->root
.string
!= stub_name
)
3788 /* Look up an entry in the stub hash. Stub entries are cached because
3789 creating the stub name takes a bit of time. */
3791 static struct ppc_stub_hash_entry
*
3792 ppc_get_stub_entry (const asection
*input_section
,
3793 const asection
*sym_sec
,
3794 struct ppc_link_hash_entry
*h
,
3795 const Elf_Internal_Rela
*rel
,
3796 struct ppc_link_hash_table
*htab
)
3798 struct ppc_stub_hash_entry
*stub_entry
;
3799 struct map_stub
*group
;
3801 /* If this input section is part of a group of sections sharing one
3802 stub section, then use the id of the first section in the group.
3803 Stub names need to include a section id, as there may well be
3804 more than one stub used to reach say, printf, and we need to
3805 distinguish between them. */
3806 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3810 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3811 && h
->u
.stub_cache
->h
== h
3812 && h
->u
.stub_cache
->group
== group
)
3814 stub_entry
= h
->u
.stub_cache
;
3820 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3821 if (stub_name
== NULL
)
3824 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3825 stub_name
, false, false);
3827 h
->u
.stub_cache
= stub_entry
;
3832 if (stub_entry
!= NULL
&& htab
->params
->power10_stubs
== -1)
3833 stub_entry
= select_alt_stub (stub_entry
, ELF64_R_TYPE (rel
->r_info
));
3838 /* Add a new stub entry to the stub hash. Not all fields of the new
3839 stub entry are initialised. */
3841 static struct ppc_stub_hash_entry
*
3842 ppc_add_stub (const char *stub_name
,
3844 struct bfd_link_info
*info
)
3846 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3847 struct map_stub
*group
;
3850 struct ppc_stub_hash_entry
*stub_entry
;
3852 group
= htab
->sec_info
[section
->id
].u
.group
;
3853 link_sec
= group
->link_sec
;
3854 stub_sec
= group
->stub_sec
;
3855 if (stub_sec
== NULL
)
3861 namelen
= strlen (link_sec
->name
);
3862 len
= namelen
+ sizeof (STUB_SUFFIX
);
3863 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3867 memcpy (s_name
, link_sec
->name
, namelen
);
3868 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3869 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3870 if (stub_sec
== NULL
)
3872 group
->stub_sec
= stub_sec
;
3875 /* Enter this entry into the linker stub hash table. */
3876 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3878 if (stub_entry
== NULL
)
3880 /* xgettext:c-format */
3881 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3882 section
->owner
, stub_name
);
3886 stub_entry
->group
= group
;
3887 stub_entry
->stub_offset
= 0;
3891 /* A stub has already been created, but it may not be the required
3892 type. We shouldn't be transitioning from plt_call to long_branch
3893 stubs or vice versa, but we might be upgrading from plt_call to
3894 plt_call with r2save for example. */
3897 ppc_merge_stub (struct ppc_link_hash_table
*htab
,
3898 struct ppc_stub_hash_entry
*stub_entry
,
3899 struct ppc_stub_type stub_type
,
3900 enum elf_ppc64_reloc_type r_type
)
3902 struct ppc_stub_type old_type
= stub_entry
->type
;
3904 if (old_type
.main
== ppc_stub_save_res
)
3907 if (htab
->params
->power10_stubs
== -1)
3909 /* For --power10-stubs=auto, don't merge _notoc and other
3910 varieties of stubs. */
3911 struct ppc_stub_hash_entry
*alt_stub
;
3913 alt_stub
= select_alt_stub (stub_entry
, r_type
);
3914 if (alt_stub
== NULL
)
3916 alt_stub
= ((struct ppc_stub_hash_entry
*)
3917 stub_hash_newfunc (NULL
,
3918 &htab
->stub_hash_table
,
3919 stub_entry
->root
.string
));
3920 if (alt_stub
== NULL
)
3923 *alt_stub
= *stub_entry
;
3924 stub_entry
->root
.next
= &alt_stub
->root
;
3926 /* Sort notoc stubs first, then toc stubs, then p9notoc.
3927 Not that it matters, this just puts smaller stubs first. */
3928 if (stub_type
.sub
== ppc_stub_notoc
)
3929 alt_stub
= stub_entry
;
3930 else if (stub_type
.sub
== ppc_stub_p9notoc
3931 && alt_stub
->root
.next
3932 && alt_stub
->root
.next
->string
== alt_stub
->root
.string
)
3934 struct ppc_stub_hash_entry
*next
3935 = (struct ppc_stub_hash_entry
*) alt_stub
->root
.next
;
3936 alt_stub
->type
= next
->type
;
3939 alt_stub
->type
= stub_type
;
3942 stub_entry
= alt_stub
;
3945 old_type
= stub_entry
->type
;
3946 if (old_type
.main
== ppc_stub_plt_branch
)
3947 old_type
.main
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
3949 if (old_type
.main
!= stub_type
.main
3950 || (old_type
.sub
!= stub_type
.sub
3951 && old_type
.sub
!= ppc_stub_toc
3952 && stub_type
.sub
!= ppc_stub_toc
))
3955 stub_entry
->type
.sub
|= stub_type
.sub
;
3956 stub_entry
->type
.r2save
|= stub_type
.r2save
;
3960 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3961 not already done. */
3964 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3966 asection
*got
, *relgot
;
3968 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3970 if (!is_ppc64_elf (abfd
))
3976 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3979 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3980 | SEC_LINKER_CREATED
);
3982 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3984 || !bfd_set_section_alignment (got
, 3))
3987 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3988 flags
| SEC_READONLY
);
3990 || !bfd_set_section_alignment (relgot
, 3))
3993 ppc64_elf_tdata (abfd
)->got
= got
;
3994 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3998 /* Follow indirect and warning symbol links. */
4000 static inline struct bfd_link_hash_entry
*
4001 follow_link (struct bfd_link_hash_entry
*h
)
4003 while (h
->type
== bfd_link_hash_indirect
4004 || h
->type
== bfd_link_hash_warning
)
4009 static inline struct elf_link_hash_entry
*
4010 elf_follow_link (struct elf_link_hash_entry
*h
)
4012 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4015 static inline struct ppc_link_hash_entry
*
4016 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4018 return ppc_elf_hash_entry (elf_follow_link (&h
->elf
));
4021 /* Merge PLT info on FROM with that on TO. */
4024 move_plt_plist (struct ppc_link_hash_entry
*from
,
4025 struct ppc_link_hash_entry
*to
)
4027 if (from
->elf
.plt
.plist
!= NULL
)
4029 if (to
->elf
.plt
.plist
!= NULL
)
4031 struct plt_entry
**entp
;
4032 struct plt_entry
*ent
;
4034 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4036 struct plt_entry
*dent
;
4038 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4039 if (dent
->addend
== ent
->addend
)
4041 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4048 *entp
= to
->elf
.plt
.plist
;
4051 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4052 from
->elf
.plt
.plist
= NULL
;
4056 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4059 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4060 struct elf_link_hash_entry
*dir
,
4061 struct elf_link_hash_entry
*ind
)
4063 struct ppc_link_hash_entry
*edir
, *eind
;
4065 edir
= ppc_elf_hash_entry (dir
);
4066 eind
= ppc_elf_hash_entry (ind
);
4068 edir
->is_func
|= eind
->is_func
;
4069 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4070 edir
->tls_mask
|= eind
->tls_mask
;
4071 if (eind
->oh
!= NULL
)
4072 edir
->oh
= ppc_follow_link (eind
->oh
);
4074 if (edir
->elf
.versioned
!= versioned_hidden
)
4075 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4076 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4077 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4078 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4079 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4080 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4082 /* If we were called to copy over info for a weak sym, don't copy
4083 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4084 in order to simplify readonly_dynrelocs and save a field in the
4085 symbol hash entry, but that means dyn_relocs can't be used in any
4086 tests about a specific symbol, or affect other symbol flags which
4088 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4091 /* Copy over any dynamic relocs we may have on the indirect sym. */
4092 if (ind
->dyn_relocs
!= NULL
)
4094 if (dir
->dyn_relocs
!= NULL
)
4096 struct ppc_dyn_relocs
**pp
;
4097 struct ppc_dyn_relocs
*p
;
4099 /* Add reloc counts against the indirect sym to the direct sym
4100 list. Merge any entries against the same section. */
4101 for (pp
= (struct ppc_dyn_relocs
**) &ind
->dyn_relocs
;
4105 struct ppc_dyn_relocs
*q
;
4107 for (q
= (struct ppc_dyn_relocs
*) dir
->dyn_relocs
;
4110 if (q
->sec
== p
->sec
)
4112 q
->count
+= p
->count
;
4113 q
->pc_count
+= p
->pc_count
;
4114 q
->rel_count
+= p
->rel_count
;
4121 *pp
= (struct ppc_dyn_relocs
*) dir
->dyn_relocs
;
4124 dir
->dyn_relocs
= ind
->dyn_relocs
;
4125 ind
->dyn_relocs
= NULL
;
4128 /* Copy over got entries that we may have already seen to the
4129 symbol which just became indirect. */
4130 if (eind
->elf
.got
.glist
!= NULL
)
4132 if (edir
->elf
.got
.glist
!= NULL
)
4134 struct got_entry
**entp
;
4135 struct got_entry
*ent
;
4137 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4139 struct got_entry
*dent
;
4141 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4142 if (dent
->addend
== ent
->addend
4143 && dent
->owner
== ent
->owner
4144 && dent
->tls_type
== ent
->tls_type
)
4146 dent
->got
.refcount
+= ent
->got
.refcount
;
4153 *entp
= edir
->elf
.got
.glist
;
4156 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4157 eind
->elf
.got
.glist
= NULL
;
4160 /* And plt entries. */
4161 move_plt_plist (eind
, edir
);
4163 if (eind
->elf
.dynindx
!= -1)
4165 if (edir
->elf
.dynindx
!= -1)
4166 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4167 edir
->elf
.dynstr_index
);
4168 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4169 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4170 eind
->elf
.dynindx
= -1;
4171 eind
->elf
.dynstr_index
= 0;
4175 /* Find the function descriptor hash entry from the given function code
4176 hash entry FH. Link the entries via their OH fields. */
4178 static struct ppc_link_hash_entry
*
4179 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4181 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4185 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4187 fdh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, fd_name
,
4188 false, false, false));
4192 fdh
->is_func_descriptor
= 1;
4198 fdh
= ppc_follow_link (fdh
);
4199 fdh
->is_func_descriptor
= 1;
4204 /* Make a fake function descriptor sym for the undefined code sym FH. */
4206 static struct ppc_link_hash_entry
*
4207 make_fdh (struct bfd_link_info
*info
,
4208 struct ppc_link_hash_entry
*fh
)
4210 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4211 struct bfd_link_hash_entry
*bh
= NULL
;
4212 struct ppc_link_hash_entry
*fdh
;
4213 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4217 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4218 fh
->elf
.root
.root
.string
+ 1,
4219 flags
, bfd_und_section_ptr
, 0,
4220 NULL
, false, false, &bh
))
4223 fdh
= (struct ppc_link_hash_entry
*) bh
;
4224 fdh
->elf
.non_elf
= 0;
4226 fdh
->is_func_descriptor
= 1;
4233 /* Fix function descriptor symbols defined in .opd sections to be
4237 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4238 struct bfd_link_info
*info
,
4239 Elf_Internal_Sym
*isym
,
4241 flagword
*flags ATTRIBUTE_UNUSED
,
4246 && strcmp ((*sec
)->name
, ".opd") == 0)
4250 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4251 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4252 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4254 /* If the symbol is a function defined in .opd, and the function
4255 code is in a discarded group, let it appear to be undefined. */
4256 if (!bfd_link_relocatable (info
)
4257 && (*sec
)->reloc_count
!= 0
4258 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4259 false) != (bfd_vma
) -1
4260 && discarded_section (code_sec
))
4262 *sec
= bfd_und_section_ptr
;
4263 isym
->st_shndx
= SHN_UNDEF
;
4266 else if (*sec
!= NULL
4267 && strcmp ((*sec
)->name
, ".toc") == 0
4268 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4270 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4272 htab
->params
->object_in_toc
= 1;
4275 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4277 if (abiversion (ibfd
) == 0)
4278 set_abiversion (ibfd
, 2);
4279 else if (abiversion (ibfd
) == 1)
4281 _bfd_error_handler (_("symbol '%s' has invalid st_other"
4282 " for ABI version 1"), *name
);
4283 bfd_set_error (bfd_error_bad_value
);
4291 /* Merge non-visibility st_other attributes: local entry point. */
4294 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
4295 unsigned int st_other
,
4299 if (definition
&& (!dynamic
|| !h
->def_regular
))
4300 h
->other
= ((st_other
& ~ELF_ST_VISIBILITY (-1))
4301 | ELF_ST_VISIBILITY (h
->other
));
4304 /* Hook called on merging a symbol. We use this to clear "fake" since
4305 we now have a real symbol. */
4308 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
4309 const Elf_Internal_Sym
*isym
,
4310 asection
**psec ATTRIBUTE_UNUSED
,
4311 bool newdef ATTRIBUTE_UNUSED
,
4312 bool olddef ATTRIBUTE_UNUSED
,
4313 bfd
*oldbfd ATTRIBUTE_UNUSED
,
4314 const asection
*oldsec ATTRIBUTE_UNUSED
)
4316 ppc_elf_hash_entry (h
)->fake
= 0;
4317 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4318 ppc_elf_hash_entry (h
)->non_zero_localentry
= 1;
4322 /* This function makes an old ABI object reference to ".bar" cause the
4323 inclusion of a new ABI object archive that defines "bar".
4324 NAME is a symbol defined in an archive. Return a symbol in the hash
4325 table that might be satisfied by the archive symbols. */
4327 static struct bfd_link_hash_entry
*
4328 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4329 struct bfd_link_info
*info
,
4332 struct bfd_link_hash_entry
*h
;
4336 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4338 && ppc_hash_table (info
) != NULL
4339 /* Don't return this sym if it is a fake function descriptor
4340 created by add_symbol_adjust. */
4341 && !((struct ppc_link_hash_entry
*) h
)->fake
)
4347 len
= strlen (name
);
4348 dot_name
= bfd_alloc (abfd
, len
+ 2);
4349 if (dot_name
== NULL
)
4350 return (struct bfd_link_hash_entry
*) -1;
4352 memcpy (dot_name
+ 1, name
, len
+ 1);
4353 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4354 bfd_release (abfd
, dot_name
);
4358 if (strcmp (name
, "__tls_get_addr_opt") == 0)
4359 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, "__tls_get_addr_desc");
4363 /* This function satisfies all old ABI object references to ".bar" if a
4364 new ABI object defines "bar". Well, at least, undefined dot symbols
4365 are made weak. This stops later archive searches from including an
4366 object if we already have a function descriptor definition. It also
4367 prevents the linker complaining about undefined symbols.
4368 We also check and correct mismatched symbol visibility here. The
4369 most restrictive visibility of the function descriptor and the
4370 function entry symbol is used. */
4373 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4375 struct ppc_link_hash_table
*htab
;
4376 struct ppc_link_hash_entry
*fdh
;
4378 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4379 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4381 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4384 if (eh
->elf
.root
.root
.string
[0] != '.')
4387 htab
= ppc_hash_table (info
);
4391 fdh
= lookup_fdh (eh
, htab
);
4393 && !bfd_link_relocatable (info
)
4394 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4395 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4396 && eh
->elf
.ref_regular
)
4398 /* Make an undefined function descriptor sym, in order to
4399 pull in an --as-needed shared lib. Archives are handled
4401 fdh
= make_fdh (info
, eh
);
4408 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4409 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4411 /* Make both descriptor and entry symbol have the most
4412 constraining visibility of either symbol. */
4413 if (entry_vis
< descr_vis
)
4414 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4415 else if (entry_vis
> descr_vis
)
4416 eh
->elf
.other
+= descr_vis
- entry_vis
;
4418 /* Propagate reference flags from entry symbol to function
4419 descriptor symbol. */
4420 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
4421 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
4422 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
4423 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
4425 if (!fdh
->elf
.forced_local
4426 && fdh
->elf
.dynindx
== -1
4427 && fdh
->elf
.versioned
!= versioned_hidden
4428 && (bfd_link_dll (info
)
4429 || fdh
->elf
.def_dynamic
4430 || fdh
->elf
.ref_dynamic
)
4431 && (eh
->elf
.ref_regular
4432 || eh
->elf
.def_regular
))
4434 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
4442 /* Set up opd section info and abiversion for IBFD, and process list
4443 of dot-symbols we made in link_hash_newfunc. */
4446 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
4448 struct ppc_link_hash_table
*htab
;
4449 struct ppc_link_hash_entry
**p
, *eh
;
4450 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
4452 if (opd
!= NULL
&& opd
->size
!= 0)
4454 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
4455 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
4457 if (abiversion (ibfd
) == 0)
4458 set_abiversion (ibfd
, 1);
4459 else if (abiversion (ibfd
) >= 2)
4461 /* xgettext:c-format */
4462 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4463 ibfd
, abiversion (ibfd
));
4464 bfd_set_error (bfd_error_bad_value
);
4469 if (is_ppc64_elf (info
->output_bfd
))
4471 /* For input files without an explicit abiversion in e_flags
4472 we should have flagged any with symbol st_other bits set
4473 as ELFv1 and above flagged those with .opd as ELFv2.
4474 Set the output abiversion if not yet set, and for any input
4475 still ambiguous, take its abiversion from the output.
4476 Differences in ABI are reported later. */
4477 if (abiversion (info
->output_bfd
) == 0)
4478 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4479 else if (abiversion (ibfd
) == 0)
4480 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4483 htab
= ppc_hash_table (info
);
4487 if (opd
!= NULL
&& opd
->size
!= 0
4488 && (ibfd
->flags
& DYNAMIC
) == 0
4489 && (opd
->flags
& SEC_RELOC
) != 0
4490 && opd
->reloc_count
!= 0
4491 && !bfd_is_abs_section (opd
->output_section
)
4492 && info
->gc_sections
)
4494 /* Garbage collection needs some extra help with .opd sections.
4495 We don't want to necessarily keep everything referenced by
4496 relocs in .opd, as that would keep all functions. Instead,
4497 if we reference an .opd symbol (a function descriptor), we
4498 want to keep the function code symbol's section. This is
4499 easy for global symbols, but for local syms we need to keep
4500 information about the associated function section. */
4502 asection
**opd_sym_map
;
4503 Elf_Internal_Shdr
*symtab_hdr
;
4504 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4506 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4507 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4508 if (opd_sym_map
== NULL
)
4510 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4511 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4515 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4516 rel_end
= relocs
+ opd
->reloc_count
- 1;
4517 for (rel
= relocs
; rel
< rel_end
; rel
++)
4519 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4520 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4522 if (r_type
== R_PPC64_ADDR64
4523 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4524 && r_symndx
< symtab_hdr
->sh_info
)
4526 Elf_Internal_Sym
*isym
;
4529 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
, ibfd
,
4533 if (elf_section_data (opd
)->relocs
!= relocs
)
4538 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4539 if (s
!= NULL
&& s
!= opd
)
4540 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4543 if (elf_section_data (opd
)->relocs
!= relocs
)
4547 p
= &htab
->dot_syms
;
4548 while ((eh
= *p
) != NULL
)
4551 if (&eh
->elf
== htab
->elf
.hgot
)
4553 else if (htab
->elf
.hgot
== NULL
4554 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4555 htab
->elf
.hgot
= &eh
->elf
;
4556 else if (abiversion (ibfd
) <= 1)
4558 htab
->need_func_desc_adj
= 1;
4559 if (!add_symbol_adjust (eh
, info
))
4562 p
= &eh
->u
.next_dot_sym
;
4567 /* Undo hash table changes when an --as-needed input file is determined
4568 not to be needed. */
4571 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4572 struct bfd_link_info
*info
,
4573 enum notice_asneeded_action act
)
4575 if (act
== notice_not_needed
)
4577 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4582 htab
->dot_syms
= NULL
;
4584 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4587 /* If --just-symbols against a final linked binary, then assume we need
4588 toc adjusting stubs when calling functions defined there. */
4591 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4593 if ((sec
->flags
& SEC_CODE
) != 0
4594 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4595 && is_ppc64_elf (sec
->owner
))
4597 if (abiversion (sec
->owner
) >= 2
4598 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4599 sec
->has_toc_reloc
= 1;
4601 _bfd_elf_link_just_syms (sec
, info
);
4604 static struct plt_entry
**
4605 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4606 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4608 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4609 struct plt_entry
**local_plt
;
4610 unsigned char *local_got_tls_masks
;
4612 if (local_got_ents
== NULL
)
4614 bfd_size_type size
= symtab_hdr
->sh_info
;
4616 size
*= (sizeof (*local_got_ents
)
4617 + sizeof (*local_plt
)
4618 + sizeof (*local_got_tls_masks
));
4619 local_got_ents
= bfd_zalloc (abfd
, size
);
4620 if (local_got_ents
== NULL
)
4622 elf_local_got_ents (abfd
) = local_got_ents
;
4625 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4627 struct got_entry
*ent
;
4629 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4630 if (ent
->addend
== r_addend
4631 && ent
->owner
== abfd
4632 && ent
->tls_type
== tls_type
)
4636 size_t amt
= sizeof (*ent
);
4637 ent
= bfd_alloc (abfd
, amt
);
4640 ent
->next
= local_got_ents
[r_symndx
];
4641 ent
->addend
= r_addend
;
4643 ent
->tls_type
= tls_type
;
4644 ent
->is_indirect
= false;
4645 ent
->got
.refcount
= 0;
4646 local_got_ents
[r_symndx
] = ent
;
4648 ent
->got
.refcount
+= 1;
4651 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4652 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4653 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4655 return local_plt
+ r_symndx
;
4659 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4661 struct plt_entry
*ent
;
4663 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4664 if (ent
->addend
== addend
)
4668 size_t amt
= sizeof (*ent
);
4669 ent
= bfd_alloc (abfd
, amt
);
4673 ent
->addend
= addend
;
4674 ent
->plt
.refcount
= 0;
4677 ent
->plt
.refcount
+= 1;
4682 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4684 return (r_type
== R_PPC64_REL24
4685 || r_type
== R_PPC64_REL24_NOTOC
4686 || r_type
== R_PPC64_REL24_P9NOTOC
4687 || r_type
== R_PPC64_REL14
4688 || r_type
== R_PPC64_REL14_BRTAKEN
4689 || r_type
== R_PPC64_REL14_BRNTAKEN
4690 || r_type
== R_PPC64_ADDR24
4691 || r_type
== R_PPC64_ADDR14
4692 || r_type
== R_PPC64_ADDR14_BRTAKEN
4693 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4694 || r_type
== R_PPC64_PLTCALL
4695 || r_type
== R_PPC64_PLTCALL_NOTOC
);
4698 /* Relocs on inline plt call sequence insns prior to the call. */
4701 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4703 return (r_type
== R_PPC64_PLT16_HA
4704 || r_type
== R_PPC64_PLT16_HI
4705 || r_type
== R_PPC64_PLT16_LO
4706 || r_type
== R_PPC64_PLT16_LO_DS
4707 || r_type
== R_PPC64_PLT_PCREL34
4708 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4709 || r_type
== R_PPC64_PLTSEQ
4710 || r_type
== R_PPC64_PLTSEQ_NOTOC
);
4713 /* Of relocs which might appear paired with TLSGD and TLSLD marker
4714 relocs, return true for those that operate on a dword. */
4717 is_8byte_reloc (enum elf_ppc64_reloc_type r_type
)
4719 return (r_type
== R_PPC64_PLT_PCREL34
4720 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4721 || r_type
== R_PPC64_PLTCALL
);
4724 /* Like bfd_reloc_offset_in_range but without a howto. Return true
4725 iff a field of SIZE bytes at OFFSET is within SEC limits. */
4728 offset_in_range (asection
*sec
, bfd_vma offset
, size_t size
)
4730 return offset
<= sec
->size
&& size
<= sec
->size
- offset
;
4733 /* Look through the relocs for a section during the first phase, and
4734 calculate needed space in the global offset table, procedure
4735 linkage table, and dynamic reloc sections. */
4738 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4739 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4741 struct ppc_link_hash_table
*htab
;
4742 Elf_Internal_Shdr
*symtab_hdr
;
4743 struct elf_link_hash_entry
**sym_hashes
;
4744 const Elf_Internal_Rela
*rel
;
4745 const Elf_Internal_Rela
*rel_end
;
4747 struct elf_link_hash_entry
*tga
, *dottga
;
4750 if (bfd_link_relocatable (info
))
4753 BFD_ASSERT (is_ppc64_elf (abfd
));
4755 htab
= ppc_hash_table (info
);
4759 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4760 false, false, true);
4761 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4762 false, false, true);
4763 symtab_hdr
= &elf_symtab_hdr (abfd
);
4764 sym_hashes
= elf_sym_hashes (abfd
);
4766 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4767 rel_end
= relocs
+ sec
->reloc_count
;
4768 for (rel
= relocs
; rel
< rel_end
; rel
++)
4770 unsigned long r_symndx
;
4771 struct elf_link_hash_entry
*h
;
4772 enum elf_ppc64_reloc_type r_type
;
4774 struct _ppc64_elf_section_data
*ppc64_sec
;
4775 struct plt_entry
**ifunc
, **plt_list
;
4777 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4778 if (r_symndx
< symtab_hdr
->sh_info
)
4782 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4783 h
= elf_follow_link (h
);
4785 if (h
== htab
->elf
.hgot
)
4786 sec
->has_toc_reloc
= 1;
4789 r_type
= ELF64_R_TYPE (rel
->r_info
);
4793 case R_PPC64_D34_LO
:
4794 case R_PPC64_D34_HI30
:
4795 case R_PPC64_D34_HA30
:
4797 case R_PPC64_TPREL34
:
4798 case R_PPC64_DTPREL34
:
4799 case R_PPC64_PCREL34
:
4800 case R_PPC64_GOT_PCREL34
:
4801 case R_PPC64_GOT_TLSGD_PCREL34
:
4802 case R_PPC64_GOT_TLSLD_PCREL34
:
4803 case R_PPC64_GOT_TPREL_PCREL34
:
4804 case R_PPC64_GOT_DTPREL_PCREL34
:
4805 case R_PPC64_PLT_PCREL34
:
4806 case R_PPC64_PLT_PCREL34_NOTOC
:
4807 case R_PPC64_PCREL28
:
4808 htab
->has_power10_relocs
= 1;
4816 case R_PPC64_PLT16_HA
:
4817 case R_PPC64_GOT_TLSLD16_HA
:
4818 case R_PPC64_GOT_TLSGD16_HA
:
4819 case R_PPC64_GOT_TPREL16_HA
:
4820 case R_PPC64_GOT_DTPREL16_HA
:
4821 case R_PPC64_GOT16_HA
:
4822 case R_PPC64_TOC16_HA
:
4823 case R_PPC64_PLT16_LO
:
4824 case R_PPC64_PLT16_LO_DS
:
4825 case R_PPC64_GOT_TLSLD16_LO
:
4826 case R_PPC64_GOT_TLSGD16_LO
:
4827 case R_PPC64_GOT_TPREL16_LO_DS
:
4828 case R_PPC64_GOT_DTPREL16_LO_DS
:
4829 case R_PPC64_GOT16_LO
:
4830 case R_PPC64_GOT16_LO_DS
:
4831 case R_PPC64_TOC16_LO
:
4832 case R_PPC64_TOC16_LO_DS
:
4833 case R_PPC64_GOT_PCREL34
:
4834 ppc64_elf_tdata (abfd
)->has_optrel
= 1;
4835 ppc64_elf_section_data (sec
)->has_optrel
= 1;
4844 if (h
->type
== STT_GNU_IFUNC
)
4847 ifunc
= &h
->plt
.plist
;
4852 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
4857 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4859 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4861 NON_GOT
| PLT_IFUNC
);
4872 /* These special tls relocs tie a call to __tls_get_addr with
4873 its parameter symbol. */
4875 ppc_elf_hash_entry (h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4877 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4879 NON_GOT
| TLS_TLS
| TLS_MARK
))
4881 sec
->has_tls_reloc
= 1;
4884 case R_PPC64_GOT_TLSLD16
:
4885 case R_PPC64_GOT_TLSLD16_LO
:
4886 case R_PPC64_GOT_TLSLD16_HI
:
4887 case R_PPC64_GOT_TLSLD16_HA
:
4888 case R_PPC64_GOT_TLSLD_PCREL34
:
4889 tls_type
= TLS_TLS
| TLS_LD
;
4892 case R_PPC64_GOT_TLSGD16
:
4893 case R_PPC64_GOT_TLSGD16_LO
:
4894 case R_PPC64_GOT_TLSGD16_HI
:
4895 case R_PPC64_GOT_TLSGD16_HA
:
4896 case R_PPC64_GOT_TLSGD_PCREL34
:
4897 tls_type
= TLS_TLS
| TLS_GD
;
4900 case R_PPC64_GOT_TPREL16_DS
:
4901 case R_PPC64_GOT_TPREL16_LO_DS
:
4902 case R_PPC64_GOT_TPREL16_HI
:
4903 case R_PPC64_GOT_TPREL16_HA
:
4904 case R_PPC64_GOT_TPREL_PCREL34
:
4905 if (bfd_link_dll (info
))
4906 info
->flags
|= DF_STATIC_TLS
;
4907 tls_type
= TLS_TLS
| TLS_TPREL
;
4910 case R_PPC64_GOT_DTPREL16_DS
:
4911 case R_PPC64_GOT_DTPREL16_LO_DS
:
4912 case R_PPC64_GOT_DTPREL16_HI
:
4913 case R_PPC64_GOT_DTPREL16_HA
:
4914 case R_PPC64_GOT_DTPREL_PCREL34
:
4915 tls_type
= TLS_TLS
| TLS_DTPREL
;
4917 sec
->has_tls_reloc
= 1;
4921 case R_PPC64_GOT16_LO
:
4922 case R_PPC64_GOT16_HI
:
4923 case R_PPC64_GOT16_HA
:
4924 case R_PPC64_GOT16_DS
:
4925 case R_PPC64_GOT16_LO_DS
:
4926 case R_PPC64_GOT_PCREL34
:
4928 /* This symbol requires a global offset table entry. */
4929 sec
->has_toc_reloc
= 1;
4930 if (r_type
== R_PPC64_GOT_TLSLD16
4931 || r_type
== R_PPC64_GOT_TLSGD16
4932 || r_type
== R_PPC64_GOT_TPREL16_DS
4933 || r_type
== R_PPC64_GOT_DTPREL16_DS
4934 || r_type
== R_PPC64_GOT16
4935 || r_type
== R_PPC64_GOT16_DS
)
4937 htab
->do_multi_toc
= 1;
4938 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4941 if (ppc64_elf_tdata (abfd
)->got
== NULL
4942 && !create_got_section (abfd
, info
))
4947 struct ppc_link_hash_entry
*eh
;
4948 struct got_entry
*ent
;
4950 eh
= ppc_elf_hash_entry (h
);
4951 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4952 if (ent
->addend
== rel
->r_addend
4953 && ent
->owner
== abfd
4954 && ent
->tls_type
== tls_type
)
4958 size_t amt
= sizeof (*ent
);
4959 ent
= bfd_alloc (abfd
, amt
);
4962 ent
->next
= eh
->elf
.got
.glist
;
4963 ent
->addend
= rel
->r_addend
;
4965 ent
->tls_type
= tls_type
;
4966 ent
->is_indirect
= false;
4967 ent
->got
.refcount
= 0;
4968 eh
->elf
.got
.glist
= ent
;
4970 ent
->got
.refcount
+= 1;
4971 eh
->tls_mask
|= tls_type
;
4974 /* This is a global offset table entry for a local symbol. */
4975 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4976 rel
->r_addend
, tls_type
))
4980 case R_PPC64_PLT16_HA
:
4981 case R_PPC64_PLT16_HI
:
4982 case R_PPC64_PLT16_LO
:
4983 case R_PPC64_PLT16_LO_DS
:
4984 case R_PPC64_PLT_PCREL34
:
4985 case R_PPC64_PLT_PCREL34_NOTOC
:
4988 /* This symbol requires a procedure linkage table entry. */
4993 if (h
->root
.root
.string
[0] == '.'
4994 && h
->root
.root
.string
[1] != '\0')
4995 ppc_elf_hash_entry (h
)->is_func
= 1;
4996 ppc_elf_hash_entry (h
)->tls_mask
|= PLT_KEEP
;
4997 plt_list
= &h
->plt
.plist
;
4999 if (plt_list
== NULL
)
5000 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5002 NON_GOT
| PLT_KEEP
);
5003 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5007 /* The following relocations don't need to propagate the
5008 relocation if linking a shared object since they are
5009 section relative. */
5010 case R_PPC64_SECTOFF
:
5011 case R_PPC64_SECTOFF_LO
:
5012 case R_PPC64_SECTOFF_HI
:
5013 case R_PPC64_SECTOFF_HA
:
5014 case R_PPC64_SECTOFF_DS
:
5015 case R_PPC64_SECTOFF_LO_DS
:
5016 case R_PPC64_DTPREL16
:
5017 case R_PPC64_DTPREL16_LO
:
5018 case R_PPC64_DTPREL16_HI
:
5019 case R_PPC64_DTPREL16_HA
:
5020 case R_PPC64_DTPREL16_DS
:
5021 case R_PPC64_DTPREL16_LO_DS
:
5022 case R_PPC64_DTPREL16_HIGH
:
5023 case R_PPC64_DTPREL16_HIGHA
:
5024 case R_PPC64_DTPREL16_HIGHER
:
5025 case R_PPC64_DTPREL16_HIGHERA
:
5026 case R_PPC64_DTPREL16_HIGHEST
:
5027 case R_PPC64_DTPREL16_HIGHESTA
:
5032 case R_PPC64_REL16_LO
:
5033 case R_PPC64_REL16_HI
:
5034 case R_PPC64_REL16_HA
:
5035 case R_PPC64_REL16_HIGH
:
5036 case R_PPC64_REL16_HIGHA
:
5037 case R_PPC64_REL16_HIGHER
:
5038 case R_PPC64_REL16_HIGHERA
:
5039 case R_PPC64_REL16_HIGHEST
:
5040 case R_PPC64_REL16_HIGHESTA
:
5041 case R_PPC64_REL16_HIGHER34
:
5042 case R_PPC64_REL16_HIGHERA34
:
5043 case R_PPC64_REL16_HIGHEST34
:
5044 case R_PPC64_REL16_HIGHESTA34
:
5045 case R_PPC64_REL16DX_HA
:
5048 /* Not supported as a dynamic relocation. */
5049 case R_PPC64_ADDR64_LOCAL
:
5050 if (bfd_link_pic (info
))
5052 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5054 /* xgettext:c-format */
5055 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
5056 "in shared libraries and PIEs\n"),
5057 abfd
, sec
, rel
->r_offset
,
5058 ppc64_elf_howto_table
[r_type
]->name
);
5059 bfd_set_error (bfd_error_bad_value
);
5065 case R_PPC64_TOC16_DS
:
5066 htab
->do_multi_toc
= 1;
5067 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5069 case R_PPC64_TOC16_LO
:
5070 case R_PPC64_TOC16_HI
:
5071 case R_PPC64_TOC16_HA
:
5072 case R_PPC64_TOC16_LO_DS
:
5073 sec
->has_toc_reloc
= 1;
5074 if (h
!= NULL
&& bfd_link_executable (info
))
5076 /* We may need a copy reloc. */
5078 /* Strongly prefer a copy reloc over a dynamic reloc.
5079 glibc ld.so as of 2019-08 will error out if one of
5080 these relocations is emitted. */
5090 /* This relocation describes the C++ object vtable hierarchy.
5091 Reconstruct it for later use during GC. */
5092 case R_PPC64_GNU_VTINHERIT
:
5093 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5097 /* This relocation describes which C++ vtable entries are actually
5098 used. Record for later use during GC. */
5099 case R_PPC64_GNU_VTENTRY
:
5100 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5105 case R_PPC64_REL14_BRTAKEN
:
5106 case R_PPC64_REL14_BRNTAKEN
:
5108 asection
*dest
= NULL
;
5110 /* Heuristic: If jumping outside our section, chances are
5111 we are going to need a stub. */
5114 /* If the sym is weak it may be overridden later, so
5115 don't assume we know where a weak sym lives. */
5116 if (h
->root
.type
== bfd_link_hash_defined
)
5117 dest
= h
->root
.u
.def
.section
;
5121 Elf_Internal_Sym
*isym
;
5123 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
5128 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5132 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5136 case R_PPC64_PLTCALL
:
5137 case R_PPC64_PLTCALL_NOTOC
:
5138 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
5142 case R_PPC64_REL24_NOTOC
:
5143 case R_PPC64_REL24_P9NOTOC
:
5149 if (h
->root
.root
.string
[0] == '.'
5150 && h
->root
.root
.string
[1] != '\0')
5151 ppc_elf_hash_entry (h
)->is_func
= 1;
5153 if (h
== tga
|| h
== dottga
)
5155 sec
->has_tls_reloc
= 1;
5157 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5158 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5159 /* We have a new-style __tls_get_addr call with
5163 /* Mark this section as having an old-style call. */
5164 sec
->nomark_tls_get_addr
= 1;
5166 plt_list
= &h
->plt
.plist
;
5169 /* We may need a .plt entry if the function this reloc
5170 refers to is in a shared lib. */
5172 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5176 case R_PPC64_ADDR14
:
5177 case R_PPC64_ADDR14_BRNTAKEN
:
5178 case R_PPC64_ADDR14_BRTAKEN
:
5179 case R_PPC64_ADDR24
:
5182 case R_PPC64_TPREL64
:
5183 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5184 if (bfd_link_dll (info
))
5185 info
->flags
|= DF_STATIC_TLS
;
5188 case R_PPC64_DTPMOD64
:
5189 if (rel
+ 1 < rel_end
5190 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5191 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5192 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5194 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5197 case R_PPC64_DTPREL64
:
5198 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5200 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5201 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5202 /* This is the second reloc of a dtpmod, dtprel pair.
5203 Don't mark with TLS_DTPREL. */
5207 sec
->has_tls_reloc
= 1;
5209 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
& 0xff;
5211 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5212 rel
->r_addend
, tls_type
))
5215 ppc64_sec
= ppc64_elf_section_data (sec
);
5216 if (ppc64_sec
->sec_type
!= sec_toc
)
5220 /* One extra to simplify get_tls_mask. */
5221 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5222 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5223 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5225 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5226 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5227 if (ppc64_sec
->u
.toc
.add
== NULL
)
5229 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5230 ppc64_sec
->sec_type
= sec_toc
;
5232 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5233 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5234 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5236 /* Mark the second slot of a GD or LD entry.
5237 -1 to indicate GD and -2 to indicate LD. */
5238 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5239 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5240 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5241 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5244 case R_PPC64_TPREL16_HI
:
5245 case R_PPC64_TPREL16_HA
:
5246 case R_PPC64_TPREL16_HIGH
:
5247 case R_PPC64_TPREL16_HIGHA
:
5248 case R_PPC64_TPREL16_HIGHER
:
5249 case R_PPC64_TPREL16_HIGHERA
:
5250 case R_PPC64_TPREL16_HIGHEST
:
5251 case R_PPC64_TPREL16_HIGHESTA
:
5252 sec
->has_tls_reloc
= 1;
5254 case R_PPC64_TPREL34
:
5255 case R_PPC64_TPREL16
:
5256 case R_PPC64_TPREL16_DS
:
5257 case R_PPC64_TPREL16_LO
:
5258 case R_PPC64_TPREL16_LO_DS
:
5259 if (bfd_link_dll (info
))
5260 info
->flags
|= DF_STATIC_TLS
;
5263 case R_PPC64_ADDR64
:
5265 && rel
+ 1 < rel_end
5266 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5269 ppc_elf_hash_entry (h
)->is_func
= 1;
5273 case R_PPC64_ADDR16
:
5274 case R_PPC64_ADDR16_DS
:
5275 case R_PPC64_ADDR16_HA
:
5276 case R_PPC64_ADDR16_HI
:
5277 case R_PPC64_ADDR16_HIGH
:
5278 case R_PPC64_ADDR16_HIGHA
:
5279 case R_PPC64_ADDR16_HIGHER
:
5280 case R_PPC64_ADDR16_HIGHERA
:
5281 case R_PPC64_ADDR16_HIGHEST
:
5282 case R_PPC64_ADDR16_HIGHESTA
:
5283 case R_PPC64_ADDR16_LO
:
5284 case R_PPC64_ADDR16_LO_DS
:
5286 case R_PPC64_D34_LO
:
5287 case R_PPC64_D34_HI30
:
5288 case R_PPC64_D34_HA30
:
5289 case R_PPC64_ADDR16_HIGHER34
:
5290 case R_PPC64_ADDR16_HIGHERA34
:
5291 case R_PPC64_ADDR16_HIGHEST34
:
5292 case R_PPC64_ADDR16_HIGHESTA34
:
5294 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5295 && rel
->r_addend
== 0)
5297 /* We may need a .plt entry if this reloc refers to a
5298 function in a shared lib. */
5299 if (!update_plt_info (abfd
, &h
->plt
.plist
, 0))
5301 h
->pointer_equality_needed
= 1;
5308 case R_PPC64_ADDR32
:
5309 case R_PPC64_UADDR16
:
5310 case R_PPC64_UADDR32
:
5311 case R_PPC64_UADDR64
:
5313 if (h
!= NULL
&& bfd_link_executable (info
))
5314 /* We may need a copy reloc. */
5317 /* Don't propagate .opd relocs. */
5318 if (NO_OPD_RELOCS
&& is_opd
)
5321 /* If we are creating a shared library, and this is a reloc
5322 against a global symbol, or a non PC relative reloc
5323 against a local symbol, then we need to copy the reloc
5324 into the shared library. However, if we are linking with
5325 -Bsymbolic, we do not need to copy a reloc against a
5326 global symbol which is defined in an object we are
5327 including in the link (i.e., DEF_REGULAR is set). At
5328 this point we have not seen all the input files, so it is
5329 possible that DEF_REGULAR is not set now but will be set
5330 later (it is never cleared). In case of a weak definition,
5331 DEF_REGULAR may be cleared later by a strong definition in
5332 a shared library. We account for that possibility below by
5333 storing information in the dyn_relocs field of the hash
5334 table entry. A similar situation occurs when creating
5335 shared libraries and symbol visibility changes render the
5338 If on the other hand, we are creating an executable, we
5339 may need to keep relocations for symbols satisfied by a
5340 dynamic library if we manage to avoid copy relocs for the
5344 && (h
->root
.type
== bfd_link_hash_defweak
5345 || !h
->def_regular
))
5347 && !bfd_link_executable (info
)
5348 && !SYMBOLIC_BIND (info
, h
))
5349 || (bfd_link_pic (info
)
5350 && must_be_dyn_reloc (info
, r_type
))
5351 || (!bfd_link_pic (info
)
5354 /* We must copy these reloc types into the output file.
5355 Create a reloc section in dynobj and make room for
5359 sreloc
= _bfd_elf_make_dynamic_reloc_section
5360 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ true);
5366 /* If this is a global symbol, we count the number of
5367 relocations we need for this symbol. */
5370 struct ppc_dyn_relocs
*p
;
5371 struct ppc_dyn_relocs
**head
;
5373 head
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
5375 if (p
== NULL
|| p
->sec
!= sec
)
5377 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5388 if (!must_be_dyn_reloc (info
, r_type
))
5390 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5391 && rel
->r_offset
% 2 == 0
5392 && sec
->alignment_power
!= 0)
5397 /* Track dynamic relocs needed for local syms too.
5398 We really need local syms available to do this
5400 struct ppc_local_dyn_relocs
*p
;
5401 struct ppc_local_dyn_relocs
**head
;
5405 Elf_Internal_Sym
*isym
;
5407 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
5412 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5416 vpp
= &elf_section_data (s
)->local_dynrel
;
5417 head
= (struct ppc_local_dyn_relocs
**) vpp
;
5418 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5420 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5422 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5424 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5432 p
->ifunc
= is_ifunc
;
5435 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5436 && rel
->r_offset
% 2 == 0
5437 && sec
->alignment_power
!= 0)
5451 /* Merge backend specific data from an object file to the output
5452 object file when linking. */
5455 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5457 bfd
*obfd
= info
->output_bfd
;
5458 unsigned long iflags
, oflags
;
5460 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5463 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5466 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
5469 iflags
= elf_elfheader (ibfd
)->e_flags
;
5470 oflags
= elf_elfheader (obfd
)->e_flags
;
5472 if (iflags
& ~EF_PPC64_ABI
)
5475 /* xgettext:c-format */
5476 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5477 bfd_set_error (bfd_error_bad_value
);
5480 else if (iflags
!= oflags
&& iflags
!= 0)
5483 /* xgettext:c-format */
5484 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
5485 ibfd
, iflags
, oflags
);
5486 bfd_set_error (bfd_error_bad_value
);
5490 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
5493 /* Merge Tag_compatibility attributes and any common GNU ones. */
5494 return _bfd_elf_merge_object_attributes (ibfd
, info
);
5498 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5500 /* Print normal ELF private data. */
5501 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5503 if (elf_elfheader (abfd
)->e_flags
!= 0)
5507 fprintf (file
, _("private flags = 0x%lx:"),
5508 elf_elfheader (abfd
)->e_flags
);
5510 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5511 fprintf (file
, _(" [abiv%ld]"),
5512 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5519 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5520 of the code entry point, and its section, which must be in the same
5521 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5524 opd_entry_value (asection
*opd_sec
,
5526 asection
**code_sec
,
5530 bfd
*opd_bfd
= opd_sec
->owner
;
5531 Elf_Internal_Rela
*relocs
;
5532 Elf_Internal_Rela
*lo
, *hi
, *look
;
5535 /* No relocs implies we are linking a --just-symbols object, or looking
5536 at a final linked executable with addr2line or somesuch. */
5537 if (opd_sec
->reloc_count
== 0)
5539 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
5541 if (contents
== NULL
)
5543 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5544 return (bfd_vma
) -1;
5545 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5548 /* PR 17512: file: 64b9dfbb. */
5549 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5550 return (bfd_vma
) -1;
5552 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5553 if (code_sec
!= NULL
)
5555 asection
*sec
, *likely
= NULL
;
5561 && val
< sec
->vma
+ sec
->size
)
5567 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5569 && (sec
->flags
& SEC_LOAD
) != 0
5570 && (sec
->flags
& SEC_ALLOC
) != 0)
5575 if (code_off
!= NULL
)
5576 *code_off
= val
- likely
->vma
;
5582 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5584 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5586 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, true);
5587 /* PR 17512: file: df8e1fd6. */
5589 return (bfd_vma
) -1;
5591 /* Go find the opd reloc at the sym address. */
5593 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5597 look
= lo
+ (hi
- lo
) / 2;
5598 if (look
->r_offset
< offset
)
5600 else if (look
->r_offset
> offset
)
5604 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5606 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5607 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5609 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5610 asection
*sec
= NULL
;
5612 if (symndx
>= symtab_hdr
->sh_info
5613 && elf_sym_hashes (opd_bfd
) != NULL
)
5615 struct elf_link_hash_entry
**sym_hashes
;
5616 struct elf_link_hash_entry
*rh
;
5618 sym_hashes
= elf_sym_hashes (opd_bfd
);
5619 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5622 rh
= elf_follow_link (rh
);
5623 if (rh
->root
.type
!= bfd_link_hash_defined
5624 && rh
->root
.type
!= bfd_link_hash_defweak
)
5626 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5628 val
= rh
->root
.u
.def
.value
;
5629 sec
= rh
->root
.u
.def
.section
;
5636 Elf_Internal_Sym
*sym
;
5638 if (symndx
< symtab_hdr
->sh_info
)
5640 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5643 size_t symcnt
= symtab_hdr
->sh_info
;
5644 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5649 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5655 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5661 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5664 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5665 val
= sym
->st_value
;
5668 val
+= look
->r_addend
;
5669 if (code_off
!= NULL
)
5671 if (code_sec
!= NULL
)
5673 if (in_code_sec
&& *code_sec
!= sec
)
5678 if (sec
->output_section
!= NULL
)
5679 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5688 /* If the ELF symbol SYM might be a function in SEC, return the
5689 function size and set *CODE_OFF to the function's entry point,
5690 otherwise return zero. */
5692 static bfd_size_type
5693 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5697 elf_symbol_type
* elf_sym
= (elf_symbol_type
*) sym
;
5699 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5700 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5703 size
= (sym
->flags
& BSF_SYNTHETIC
) ? 0 : elf_sym
->internal_elf_sym
.st_size
;
5705 /* In theory we should check that the symbol's type satisfies
5706 _bfd_elf_is_function_type(), but there are some function-like
5707 symbols which would fail this test. (eg _start). Instead
5708 we check for hidden, local, notype symbols with zero size.
5709 This type of symbol is generated by the annobin plugin for gcc
5710 and clang, and should not be considered to be a function symbol. */
5712 && ((sym
->flags
& (BSF_SYNTHETIC
| BSF_LOCAL
)) == BSF_LOCAL
)
5713 && ELF_ST_TYPE (elf_sym
->internal_elf_sym
.st_info
) == STT_NOTYPE
5714 && ELF_ST_VISIBILITY (elf_sym
->internal_elf_sym
.st_other
) == STV_HIDDEN
)
5717 if (strcmp (sym
->section
->name
, ".opd") == 0)
5719 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5720 bfd_vma symval
= sym
->value
;
5723 && opd
->adjust
!= NULL
5724 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5726 /* opd_entry_value will use cached relocs that have been
5727 adjusted, but with raw symbols. That means both local
5728 and global symbols need adjusting. */
5729 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5735 if (opd_entry_value (sym
->section
, symval
,
5736 &sec
, code_off
, true) == (bfd_vma
) -1)
5738 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5739 symbol. This size has nothing to do with the code size of the
5740 function, which is what we're supposed to return, but the
5741 code size isn't available without looking up the dot-sym.
5742 However, doing that would be a waste of time particularly
5743 since elf_find_function will look at the dot-sym anyway.
5744 Now, elf_find_function will keep the largest size of any
5745 function sym found at the code address of interest, so return
5746 1 here to avoid it incorrectly caching a larger function size
5747 for a small function. This does mean we return the wrong
5748 size for a new-ABI function of size 24, but all that does is
5749 disable caching for such functions. */
5755 if (sym
->section
!= sec
)
5757 *code_off
= sym
->value
;
5760 /* Do not return 0 for the function's size. */
5761 return size
? size
: 1;
5764 /* Return true if symbol is a strong function defined in an ELFv2
5765 object with st_other localentry bits of zero, ie. its local entry
5766 point coincides with its global entry point. */
5769 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5772 && h
->type
== STT_FUNC
5773 && h
->root
.type
== bfd_link_hash_defined
5774 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5775 && !ppc_elf_hash_entry (h
)->non_zero_localentry
5776 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5777 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5780 /* Return true if symbol is defined in a regular object file. */
5783 is_static_defined (struct elf_link_hash_entry
*h
)
5785 return ((h
->root
.type
== bfd_link_hash_defined
5786 || h
->root
.type
== bfd_link_hash_defweak
)
5787 && h
->root
.u
.def
.section
!= NULL
5788 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5791 /* If FDH is a function descriptor symbol, return the associated code
5792 entry symbol if it is defined. Return NULL otherwise. */
5794 static struct ppc_link_hash_entry
*
5795 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5797 if (fdh
->is_func_descriptor
)
5799 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5800 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5801 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5807 /* If FH is a function code entry symbol, return the associated
5808 function descriptor symbol if it is defined. Return NULL otherwise. */
5810 static struct ppc_link_hash_entry
*
5811 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5814 && fh
->oh
->is_func_descriptor
)
5816 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5817 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5818 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5824 /* Given H is a symbol that satisfies is_static_defined, return the
5825 value in the output file. */
5828 defined_sym_val (struct elf_link_hash_entry
*h
)
5830 return (h
->root
.u
.def
.section
->output_section
->vma
5831 + h
->root
.u
.def
.section
->output_offset
5832 + h
->root
.u
.def
.value
);
5835 /* Return true if H matches __tls_get_addr or one of its variants. */
5838 is_tls_get_addr (struct elf_link_hash_entry
*h
,
5839 struct ppc_link_hash_table
*htab
)
5841 return (h
== elf_hash_entry (htab
->tls_get_addr_fd
)
5842 || h
== elf_hash_entry (htab
->tga_desc_fd
)
5843 || h
== elf_hash_entry (htab
->tls_get_addr
)
5844 || h
== elf_hash_entry (htab
->tga_desc
));
5847 static bool func_desc_adjust (struct elf_link_hash_entry
*, void *);
5849 /* Garbage collect sections, after first dealing with dot-symbols. */
5852 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5854 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5856 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5858 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5859 htab
->need_func_desc_adj
= 0;
5861 return bfd_elf_gc_sections (abfd
, info
);
5864 /* Mark all our entry sym sections, both opd and code section. */
5867 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5869 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5870 struct bfd_sym_chain
*sym
;
5875 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5877 struct ppc_link_hash_entry
*eh
, *fh
;
5880 eh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
->name
,
5881 false, false, true));
5884 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5885 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5888 fh
= defined_code_entry (eh
);
5891 sec
= fh
->elf
.root
.u
.def
.section
;
5892 sec
->flags
|= SEC_KEEP
;
5894 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5895 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5896 eh
->elf
.root
.u
.def
.value
,
5897 &sec
, NULL
, false) != (bfd_vma
) -1)
5898 sec
->flags
|= SEC_KEEP
;
5900 sec
= eh
->elf
.root
.u
.def
.section
;
5901 sec
->flags
|= SEC_KEEP
;
5905 /* Mark sections containing dynamically referenced symbols. When
5906 building shared libraries, we must assume that any visible symbol is
5910 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5912 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5913 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
5914 struct ppc_link_hash_entry
*fdh
;
5915 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5917 /* Dynamic linking info is on the func descriptor sym. */
5918 fdh
= defined_func_desc (eh
);
5922 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5923 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5924 && (!eh
->elf
.start_stop
5925 || eh
->elf
.root
.ldscript_def
5926 || !info
->start_stop_gc
)
5927 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5928 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5929 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5930 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5931 && (!bfd_link_executable (info
)
5932 || info
->gc_keep_exported
5933 || info
->export_dynamic
5936 && (*d
->match
) (&d
->head
, NULL
,
5937 eh
->elf
.root
.root
.string
)))
5938 && (eh
->elf
.versioned
>= versioned
5939 || !bfd_hide_sym_by_version (info
->version_info
,
5940 eh
->elf
.root
.root
.string
)))))
5943 struct ppc_link_hash_entry
*fh
;
5945 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5947 /* Function descriptor syms cause the associated
5948 function code sym section to be marked. */
5949 fh
= defined_code_entry (eh
);
5952 code_sec
= fh
->elf
.root
.u
.def
.section
;
5953 code_sec
->flags
|= SEC_KEEP
;
5955 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5956 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5957 eh
->elf
.root
.u
.def
.value
,
5958 &code_sec
, NULL
, false) != (bfd_vma
) -1)
5959 code_sec
->flags
|= SEC_KEEP
;
5965 /* Return the section that should be marked against GC for a given
5969 ppc64_elf_gc_mark_hook (asection
*sec
,
5970 struct bfd_link_info
*info
,
5971 Elf_Internal_Rela
*rel
,
5972 struct elf_link_hash_entry
*h
,
5973 Elf_Internal_Sym
*sym
)
5977 /* Syms return NULL if we're marking .opd, so we avoid marking all
5978 function sections, as all functions are referenced in .opd. */
5980 if (get_opd_info (sec
) != NULL
)
5985 enum elf_ppc64_reloc_type r_type
;
5986 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5988 r_type
= ELF64_R_TYPE (rel
->r_info
);
5991 case R_PPC64_GNU_VTINHERIT
:
5992 case R_PPC64_GNU_VTENTRY
:
5996 switch (h
->root
.type
)
5998 case bfd_link_hash_defined
:
5999 case bfd_link_hash_defweak
:
6000 eh
= ppc_elf_hash_entry (h
);
6001 fdh
= defined_func_desc (eh
);
6004 /* -mcall-aixdesc code references the dot-symbol on
6005 a call reloc. Mark the function descriptor too
6006 against garbage collection. */
6008 if (fdh
->elf
.is_weakalias
)
6009 weakdef (&fdh
->elf
)->mark
= 1;
6013 /* Function descriptor syms cause the associated
6014 function code sym section to be marked. */
6015 fh
= defined_code_entry (eh
);
6018 /* They also mark their opd section. */
6019 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6021 rsec
= fh
->elf
.root
.u
.def
.section
;
6023 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6024 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6025 eh
->elf
.root
.u
.def
.value
,
6026 &rsec
, NULL
, false) != (bfd_vma
) -1)
6027 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6029 rsec
= h
->root
.u
.def
.section
;
6032 case bfd_link_hash_common
:
6033 rsec
= h
->root
.u
.c
.p
->section
;
6037 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6043 struct _opd_sec_data
*opd
;
6045 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6046 opd
= get_opd_info (rsec
);
6047 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6051 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6058 /* The maximum size of .sfpr. */
6059 #define SFPR_MAX (218*4)
6061 struct sfpr_def_parms
6063 const char name
[12];
6064 unsigned char lo
, hi
;
6065 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
6066 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
6069 /* Auto-generate _save*, _rest* functions in .sfpr.
6070 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6074 sfpr_define (struct bfd_link_info
*info
,
6075 const struct sfpr_def_parms
*parm
,
6078 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6080 size_t len
= strlen (parm
->name
);
6081 bool writing
= false;
6087 memcpy (sym
, parm
->name
, len
);
6090 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6092 struct ppc_link_hash_entry
*h
;
6094 sym
[len
+ 0] = i
/ 10 + '0';
6095 sym
[len
+ 1] = i
% 10 + '0';
6096 h
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
,
6097 writing
, true, true));
6098 if (stub_sec
!= NULL
)
6101 && h
->elf
.root
.type
== bfd_link_hash_defined
6102 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6104 struct elf_link_hash_entry
*s
;
6106 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6107 s
= elf_link_hash_lookup (&htab
->elf
, buf
, true, true, false);
6110 if (s
->root
.type
== bfd_link_hash_new
)
6112 s
->root
.type
= bfd_link_hash_defined
;
6113 s
->root
.u
.def
.section
= stub_sec
;
6114 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6115 + h
->elf
.root
.u
.def
.value
);
6118 s
->ref_regular_nonweak
= 1;
6119 s
->forced_local
= 1;
6121 s
->root
.linker_def
= 1;
6129 if (!h
->elf
.def_regular
)
6131 h
->elf
.root
.type
= bfd_link_hash_defined
;
6132 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6133 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6134 h
->elf
.type
= STT_FUNC
;
6135 h
->elf
.def_regular
= 1;
6137 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, true);
6139 if (htab
->sfpr
->contents
== NULL
)
6141 htab
->sfpr
->contents
6142 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6143 if (htab
->sfpr
->contents
== NULL
)
6150 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6152 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6154 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6155 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6163 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6165 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6170 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6172 p
= savegpr0 (abfd
, p
, r
);
6173 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6175 bfd_put_32 (abfd
, BLR
, p
);
6180 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6182 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6187 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6189 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6191 p
= restgpr0 (abfd
, p
, r
);
6192 bfd_put_32 (abfd
, MTLR_R0
, p
);
6196 p
= restgpr0 (abfd
, p
, 30);
6197 p
= restgpr0 (abfd
, p
, 31);
6199 bfd_put_32 (abfd
, BLR
, p
);
6204 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6206 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6211 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6213 p
= savegpr1 (abfd
, p
, r
);
6214 bfd_put_32 (abfd
, BLR
, p
);
6219 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6221 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6226 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6228 p
= restgpr1 (abfd
, p
, r
);
6229 bfd_put_32 (abfd
, BLR
, p
);
6234 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6236 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6241 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6243 p
= savefpr (abfd
, p
, r
);
6244 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6246 bfd_put_32 (abfd
, BLR
, p
);
6251 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6253 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6258 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6260 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6262 p
= restfpr (abfd
, p
, r
);
6263 bfd_put_32 (abfd
, MTLR_R0
, p
);
6267 p
= restfpr (abfd
, p
, 30);
6268 p
= restfpr (abfd
, p
, 31);
6270 bfd_put_32 (abfd
, BLR
, p
);
6275 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6277 p
= savefpr (abfd
, p
, r
);
6278 bfd_put_32 (abfd
, BLR
, p
);
6283 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6285 p
= restfpr (abfd
, p
, r
);
6286 bfd_put_32 (abfd
, BLR
, p
);
6291 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6293 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6295 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6300 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6302 p
= savevr (abfd
, p
, r
);
6303 bfd_put_32 (abfd
, BLR
, p
);
6308 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6310 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6312 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6317 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6319 p
= restvr (abfd
, p
, r
);
6320 bfd_put_32 (abfd
, BLR
, p
);
6324 #define STDU_R1_0R1 0xf8210001
6325 #define ADDI_R1_R1 0x38210000
6327 /* Emit prologue of wrapper preserving regs around a call to
6328 __tls_get_addr_opt. */
6331 tls_get_addr_prologue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6335 bfd_put_32 (obfd
, MFLR_R0
, p
);
6337 bfd_put_32 (obfd
, STD_R0_0R1
+ 16, p
);
6342 for (i
= 4; i
< 12; i
++)
6345 STD_R0_0R1
| i
<< 21 | (-(13 - i
) * 8 & 0xffff), p
);
6348 bfd_put_32 (obfd
, STDU_R1_0R1
| (-128 & 0xffff), p
);
6353 for (i
= 4; i
< 12; i
++)
6356 STD_R0_0R1
| i
<< 21 | (-(12 - i
) * 8 & 0xffff), p
);
6359 bfd_put_32 (obfd
, STDU_R1_0R1
| (-96 & 0xffff), p
);
6365 /* Emit epilogue of wrapper preserving regs around a call to
6366 __tls_get_addr_opt. */
6369 tls_get_addr_epilogue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6375 for (i
= 4; i
< 12; i
++)
6377 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (128 - (13 - i
) * 8), p
);
6380 bfd_put_32 (obfd
, ADDI_R1_R1
| 128, p
);
6385 for (i
= 4; i
< 12; i
++)
6387 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (96 - (12 - i
) * 8), p
);
6390 bfd_put_32 (obfd
, ADDI_R1_R1
| 96, p
);
6393 bfd_put_32 (obfd
, LD_R0_0R1
| 16, p
);
6395 bfd_put_32 (obfd
, MTLR_R0
, p
);
6397 bfd_put_32 (obfd
, BLR
, p
);
6402 /* Called via elf_link_hash_traverse to transfer dynamic linking
6403 information on function code symbol entries to their corresponding
6404 function descriptor symbol entries. Must not be called twice for
6405 any given code symbol. */
6408 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6410 struct bfd_link_info
*info
;
6411 struct ppc_link_hash_table
*htab
;
6412 struct ppc_link_hash_entry
*fh
;
6413 struct ppc_link_hash_entry
*fdh
;
6416 fh
= ppc_elf_hash_entry (h
);
6417 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6423 if (fh
->elf
.root
.root
.string
[0] != '.'
6424 || fh
->elf
.root
.root
.string
[1] == '\0')
6428 htab
= ppc_hash_table (info
);
6432 /* Find the corresponding function descriptor symbol. */
6433 fdh
= lookup_fdh (fh
, htab
);
6435 /* Resolve undefined references to dot-symbols as the value
6436 in the function descriptor, if we have one in a regular object.
6437 This is to satisfy cases like ".quad .foo". Calls to functions
6438 in dynamic objects are handled elsewhere. */
6439 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6440 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6441 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6442 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6443 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6444 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6445 fdh
->elf
.root
.u
.def
.value
,
6446 &fh
->elf
.root
.u
.def
.section
,
6447 &fh
->elf
.root
.u
.def
.value
, false) != (bfd_vma
) -1)
6449 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6450 fh
->elf
.forced_local
= 1;
6451 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6452 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6455 if (!fh
->elf
.dynamic
)
6457 struct plt_entry
*ent
;
6459 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6460 if (ent
->plt
.refcount
> 0)
6464 if (fdh
!= NULL
&& fdh
->fake
)
6465 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6470 /* Create a descriptor as undefined if necessary. */
6472 && !bfd_link_executable (info
)
6473 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6474 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6476 fdh
= make_fdh (info
, fh
);
6481 /* We can't support overriding of symbols on a fake descriptor. */
6484 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6485 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6486 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6488 /* Transfer dynamic linking information to the function descriptor. */
6491 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6492 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6493 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6494 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6495 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6496 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6497 || fh
->elf
.type
== STT_FUNC
6498 || fh
->elf
.type
== STT_GNU_IFUNC
);
6499 move_plt_plist (fh
, fdh
);
6501 if (!fdh
->elf
.forced_local
6502 && fh
->elf
.dynindx
!= -1)
6503 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6507 /* Now that the info is on the function descriptor, clear the
6508 function code sym info. Any function code syms for which we
6509 don't have a definition in a regular file, we force local.
6510 This prevents a shared library from exporting syms that have
6511 been imported from another library. Function code syms that
6512 are really in the library we must leave global to prevent the
6513 linker dragging in a definition from a static library. */
6514 force_local
= (!fh
->elf
.def_regular
6516 || !fdh
->elf
.def_regular
6517 || fdh
->elf
.forced_local
);
6518 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6523 static const struct sfpr_def_parms save_res_funcs
[] =
6525 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6526 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6527 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6528 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6529 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6530 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6531 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6532 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6533 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6534 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6535 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6536 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6539 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6540 this hook to a) run the edit functions in this file, b) provide
6541 some gcc support functions, and c) transfer dynamic linking
6542 information gathered so far on function code symbol entries, to
6543 their corresponding function descriptor symbol entries. */
6546 ppc64_elf_edit (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6548 struct ppc_link_hash_table
*htab
;
6550 htab
= ppc_hash_table (info
);
6554 /* Call back into the linker, which then runs the edit functions. */
6555 htab
->params
->edit ();
6557 /* Provide any missing _save* and _rest* functions. */
6558 if (htab
->sfpr
!= NULL
)
6562 htab
->sfpr
->size
= 0;
6563 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
6564 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
6566 if (htab
->sfpr
->size
== 0)
6567 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6570 if (bfd_link_relocatable (info
))
6573 if (htab
->elf
.hgot
!= NULL
)
6575 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, true);
6576 /* Make .TOC. defined so as to prevent it being made dynamic.
6577 The wrong value here is fixed later in ppc64_elf_set_toc. */
6578 if (!htab
->elf
.hgot
->def_regular
6579 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
6581 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
6582 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
6583 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6584 htab
->elf
.hgot
->def_regular
= 1;
6585 htab
->elf
.hgot
->root
.linker_def
= 1;
6587 htab
->elf
.hgot
->type
= STT_OBJECT
;
6588 htab
->elf
.hgot
->other
6589 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
6595 /* Return true if we have dynamic relocs against H or any of its weak
6596 aliases, that apply to read-only sections. Cannot be used after
6597 size_dynamic_sections. */
6600 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6602 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
6605 if (_bfd_elf_readonly_dynrelocs (&eh
->elf
))
6607 eh
= ppc_elf_hash_entry (eh
->elf
.u
.alias
);
6609 while (eh
!= NULL
&& &eh
->elf
!= h
);
6614 /* Return whether EH has pc-relative dynamic relocs. */
6617 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
6619 struct ppc_dyn_relocs
*p
;
6621 for (p
= (struct ppc_dyn_relocs
*) eh
->elf
.dyn_relocs
; p
!= NULL
; p
= p
->next
)
6622 if (p
->pc_count
!= 0)
6627 /* Return true if a global entry stub will be created for H. Valid
6628 for ELFv2 before plt entries have been allocated. */
6631 global_entry_stub (struct elf_link_hash_entry
*h
)
6633 struct plt_entry
*pent
;
6635 if (!h
->pointer_equality_needed
6639 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
6640 if (pent
->plt
.refcount
> 0
6641 && pent
->addend
== 0)
6647 /* Adjust a symbol defined by a dynamic object and referenced by a
6648 regular object. The current definition is in some section of the
6649 dynamic object, but we're not including those sections. We have to
6650 change the definition to something the rest of the link can
6654 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6655 struct elf_link_hash_entry
*h
)
6657 struct ppc_link_hash_table
*htab
;
6660 htab
= ppc_hash_table (info
);
6664 /* Deal with function syms. */
6665 if (h
->type
== STT_FUNC
6666 || h
->type
== STT_GNU_IFUNC
6669 bool local
= (ppc_elf_hash_entry (h
)->save_res
6670 || SYMBOL_CALLS_LOCAL (info
, h
)
6671 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6672 /* Discard dyn_relocs when non-pic if we've decided that a
6673 function symbol is local and not an ifunc. We keep dynamic
6674 relocs for ifuncs when local rather than always emitting a
6675 plt call stub for them and defining the symbol on the call
6676 stub. We can't do that for ELFv1 anyway (a function symbol
6677 is defined on a descriptor, not code) and it can be faster at
6678 run-time due to not needing to bounce through a stub. The
6679 dyn_relocs for ifuncs will be applied even in a static
6681 if (!bfd_link_pic (info
)
6682 && h
->type
!= STT_GNU_IFUNC
6684 h
->dyn_relocs
= NULL
;
6686 /* Clear procedure linkage table information for any symbol that
6687 won't need a .plt entry. */
6688 struct plt_entry
*ent
;
6689 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6690 if (ent
->plt
.refcount
> 0)
6693 || (h
->type
!= STT_GNU_IFUNC
6695 && (htab
->can_convert_all_inline_plt
6696 || (ppc_elf_hash_entry (h
)->tls_mask
6697 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6699 h
->plt
.plist
= NULL
;
6701 h
->pointer_equality_needed
= 0;
6703 else if (abiversion (info
->output_bfd
) >= 2)
6705 /* Taking a function's address in a read/write section
6706 doesn't require us to define the function symbol in the
6707 executable on a global entry stub. A dynamic reloc can
6708 be used instead. The reason we prefer a few more dynamic
6709 relocs is that calling via a global entry stub costs a
6710 few more instructions, and pointer_equality_needed causes
6711 extra work in ld.so when resolving these symbols. */
6712 if (global_entry_stub (h
))
6714 if (!_bfd_elf_readonly_dynrelocs (h
))
6716 h
->pointer_equality_needed
= 0;
6717 /* If we haven't seen a branch reloc and the symbol
6718 isn't an ifunc then we don't need a plt entry. */
6720 h
->plt
.plist
= NULL
;
6722 else if (!bfd_link_pic (info
))
6723 /* We are going to be defining the function symbol on the
6724 plt stub, so no dyn_relocs needed when non-pic. */
6725 h
->dyn_relocs
= NULL
;
6728 /* ELFv2 function symbols can't have copy relocs. */
6731 else if (!h
->needs_plt
6732 && !_bfd_elf_readonly_dynrelocs (h
))
6734 /* If we haven't seen a branch reloc and the symbol isn't an
6735 ifunc then we don't need a plt entry. */
6736 h
->plt
.plist
= NULL
;
6737 h
->pointer_equality_needed
= 0;
6742 h
->plt
.plist
= NULL
;
6744 /* If this is a weak symbol, and there is a real definition, the
6745 processor independent code will have arranged for us to see the
6746 real definition first, and we can just use the same value. */
6747 if (h
->is_weakalias
)
6749 struct elf_link_hash_entry
*def
= weakdef (h
);
6750 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6751 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6752 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6753 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6754 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6755 h
->dyn_relocs
= NULL
;
6759 /* If we are creating a shared library, we must presume that the
6760 only references to the symbol are via the global offset table.
6761 For such cases we need not do anything here; the relocations will
6762 be handled correctly by relocate_section. */
6763 if (!bfd_link_executable (info
))
6766 /* If there are no references to this symbol that do not use the
6767 GOT, we don't need to generate a copy reloc. */
6768 if (!h
->non_got_ref
)
6771 /* Don't generate a copy reloc for symbols defined in the executable. */
6772 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6774 /* If -z nocopyreloc was given, don't generate them either. */
6775 || info
->nocopyreloc
6777 /* If we don't find any dynamic relocs in read-only sections, then
6778 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6779 || (ELIMINATE_COPY_RELOCS
6781 && !alias_readonly_dynrelocs (h
))
6783 /* Protected variables do not work with .dynbss. The copy in
6784 .dynbss won't be used by the shared library with the protected
6785 definition for the variable. Text relocations are preferable
6786 to an incorrect program. */
6787 || h
->protected_def
)
6790 if (h
->type
== STT_FUNC
6791 || h
->type
== STT_GNU_IFUNC
)
6793 /* .dynbss copies of function symbols only work if we have
6794 ELFv1 dot-symbols. ELFv1 compilers since 2004 default to not
6795 use dot-symbols and set the function symbol size to the text
6796 size of the function rather than the size of the descriptor.
6797 That's wrong for copying a descriptor. */
6798 if (ppc_elf_hash_entry (h
)->oh
== NULL
6799 || !(h
->size
== 24 || h
->size
== 16))
6802 /* We should never get here, but unfortunately there are old
6803 versions of gcc (circa gcc-3.2) that improperly for the
6804 ELFv1 ABI put initialized function pointers, vtable refs and
6805 suchlike in read-only sections. Allow them to proceed, but
6806 warn that this might break at runtime. */
6807 info
->callbacks
->einfo
6808 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6809 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6810 h
->root
.root
.string
);
6813 /* This is a reference to a symbol defined by a dynamic object which
6814 is not a function. */
6816 /* We must allocate the symbol in our .dynbss section, which will
6817 become part of the .bss section of the executable. There will be
6818 an entry for this symbol in the .dynsym section. The dynamic
6819 object will contain position independent code, so all references
6820 from the dynamic object to this symbol will go through the global
6821 offset table. The dynamic linker will use the .dynsym entry to
6822 determine the address it must put in the global offset table, so
6823 both the dynamic object and the regular object will refer to the
6824 same memory location for the variable. */
6825 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6827 s
= htab
->elf
.sdynrelro
;
6828 srel
= htab
->elf
.sreldynrelro
;
6832 s
= htab
->elf
.sdynbss
;
6833 srel
= htab
->elf
.srelbss
;
6835 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6837 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6838 linker to copy the initial value out of the dynamic object
6839 and into the runtime process image. */
6840 srel
->size
+= sizeof (Elf64_External_Rela
);
6844 /* We no longer want dyn_relocs. */
6845 h
->dyn_relocs
= NULL
;
6846 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6849 /* If given a function descriptor symbol, hide both the function code
6850 sym and the descriptor. */
6852 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6853 struct elf_link_hash_entry
*h
,
6856 struct ppc_link_hash_entry
*eh
;
6857 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6859 if (ppc_hash_table (info
) == NULL
)
6862 eh
= ppc_elf_hash_entry (h
);
6863 if (eh
->is_func_descriptor
)
6865 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6870 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6873 /* We aren't supposed to use alloca in BFD because on
6874 systems which do not have alloca the version in libiberty
6875 calls xmalloc, which might cause the program to crash
6876 when it runs out of memory. This function doesn't have a
6877 return status, so there's no way to gracefully return an
6878 error. So cheat. We know that string[-1] can be safely
6879 accessed; It's either a string in an ELF string table,
6880 or allocated in an objalloc structure. */
6882 p
= eh
->elf
.root
.root
.string
- 1;
6885 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6889 /* Unfortunately, if it so happens that the string we were
6890 looking for was allocated immediately before this string,
6891 then we overwrote the string terminator. That's the only
6892 reason the lookup should fail. */
6895 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6896 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6898 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6899 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6909 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6914 get_sym_h (struct elf_link_hash_entry
**hp
,
6915 Elf_Internal_Sym
**symp
,
6917 unsigned char **tls_maskp
,
6918 Elf_Internal_Sym
**locsymsp
,
6919 unsigned long r_symndx
,
6922 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6924 if (r_symndx
>= symtab_hdr
->sh_info
)
6926 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6927 struct elf_link_hash_entry
*h
;
6929 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6930 h
= elf_follow_link (h
);
6938 if (symsecp
!= NULL
)
6940 asection
*symsec
= NULL
;
6941 if (h
->root
.type
== bfd_link_hash_defined
6942 || h
->root
.type
== bfd_link_hash_defweak
)
6943 symsec
= h
->root
.u
.def
.section
;
6947 if (tls_maskp
!= NULL
)
6948 *tls_maskp
= &ppc_elf_hash_entry (h
)->tls_mask
;
6952 Elf_Internal_Sym
*sym
;
6953 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6955 if (locsyms
== NULL
)
6957 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6958 if (locsyms
== NULL
)
6959 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6960 symtab_hdr
->sh_info
,
6961 0, NULL
, NULL
, NULL
);
6962 if (locsyms
== NULL
)
6964 *locsymsp
= locsyms
;
6966 sym
= locsyms
+ r_symndx
;
6974 if (symsecp
!= NULL
)
6975 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6977 if (tls_maskp
!= NULL
)
6979 struct got_entry
**lgot_ents
;
6980 unsigned char *tls_mask
;
6983 lgot_ents
= elf_local_got_ents (ibfd
);
6984 if (lgot_ents
!= NULL
)
6986 struct plt_entry
**local_plt
= (struct plt_entry
**)
6987 (lgot_ents
+ symtab_hdr
->sh_info
);
6988 unsigned char *lgot_masks
= (unsigned char *)
6989 (local_plt
+ symtab_hdr
->sh_info
);
6990 tls_mask
= &lgot_masks
[r_symndx
];
6992 *tls_maskp
= tls_mask
;
6998 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6999 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7000 type suitable for optimization, and 1 otherwise. */
7003 get_tls_mask (unsigned char **tls_maskp
,
7004 unsigned long *toc_symndx
,
7005 bfd_vma
*toc_addend
,
7006 Elf_Internal_Sym
**locsymsp
,
7007 const Elf_Internal_Rela
*rel
,
7010 unsigned long r_symndx
;
7012 struct elf_link_hash_entry
*h
;
7013 Elf_Internal_Sym
*sym
;
7017 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7018 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7021 if ((*tls_maskp
!= NULL
7022 && (**tls_maskp
& TLS_TLS
) != 0
7023 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
7025 || ppc64_elf_section_data (sec
) == NULL
7026 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7029 /* Look inside a TOC section too. */
7032 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7033 off
= h
->root
.u
.def
.value
;
7036 off
= sym
->st_value
;
7037 off
+= rel
->r_addend
;
7038 BFD_ASSERT (off
% 8 == 0);
7039 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7040 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7041 if (toc_symndx
!= NULL
)
7042 *toc_symndx
= r_symndx
;
7043 if (toc_addend
!= NULL
)
7044 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7045 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7047 if ((h
== NULL
|| is_static_defined (h
))
7048 && (next_r
== -1 || next_r
== -2))
7053 /* Find (or create) an entry in the tocsave hash table. */
7055 static struct tocsave_entry
*
7056 tocsave_find (struct ppc_link_hash_table
*htab
,
7057 enum insert_option insert
,
7058 Elf_Internal_Sym
**local_syms
,
7059 const Elf_Internal_Rela
*irela
,
7062 unsigned long r_indx
;
7063 struct elf_link_hash_entry
*h
;
7064 Elf_Internal_Sym
*sym
;
7065 struct tocsave_entry ent
, *p
;
7067 struct tocsave_entry
**slot
;
7069 r_indx
= ELF64_R_SYM (irela
->r_info
);
7070 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7072 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7075 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7080 ent
.offset
= h
->root
.u
.def
.value
;
7082 ent
.offset
= sym
->st_value
;
7083 ent
.offset
+= irela
->r_addend
;
7085 hash
= tocsave_htab_hash (&ent
);
7086 slot
= ((struct tocsave_entry
**)
7087 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7093 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7102 /* Adjust all global syms defined in opd sections. In gcc generated
7103 code for the old ABI, these will already have been done. */
7106 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7108 struct ppc_link_hash_entry
*eh
;
7110 struct _opd_sec_data
*opd
;
7112 if (h
->root
.type
== bfd_link_hash_indirect
)
7115 if (h
->root
.type
!= bfd_link_hash_defined
7116 && h
->root
.type
!= bfd_link_hash_defweak
)
7119 eh
= ppc_elf_hash_entry (h
);
7120 if (eh
->adjust_done
)
7123 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7124 opd
= get_opd_info (sym_sec
);
7125 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7127 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7130 /* This entry has been deleted. */
7131 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7134 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7135 if (discarded_section (dsec
))
7137 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7141 eh
->elf
.root
.u
.def
.value
= 0;
7142 eh
->elf
.root
.u
.def
.section
= dsec
;
7145 eh
->elf
.root
.u
.def
.value
+= adjust
;
7146 eh
->adjust_done
= 1;
7151 /* Handles decrementing dynamic reloc counts for the reloc specified by
7152 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7153 have already been determined. */
7156 dec_dynrel_count (const Elf_Internal_Rela
*rel
,
7158 struct bfd_link_info
*info
,
7159 Elf_Internal_Sym
**local_syms
,
7160 struct elf_link_hash_entry
*h
,
7161 Elf_Internal_Sym
*sym
)
7163 enum elf_ppc64_reloc_type r_type
;
7164 asection
*sym_sec
= NULL
;
7166 /* Can this reloc be dynamic? This switch, and later tests here
7167 should be kept in sync with the code in check_relocs. */
7168 r_type
= ELF64_R_TYPE (rel
->r_info
);
7175 case R_PPC64_TOC16_DS
:
7176 case R_PPC64_TOC16_LO
:
7177 case R_PPC64_TOC16_HI
:
7178 case R_PPC64_TOC16_HA
:
7179 case R_PPC64_TOC16_LO_DS
:
7184 case R_PPC64_TPREL16
:
7185 case R_PPC64_TPREL16_LO
:
7186 case R_PPC64_TPREL16_HI
:
7187 case R_PPC64_TPREL16_HA
:
7188 case R_PPC64_TPREL16_DS
:
7189 case R_PPC64_TPREL16_LO_DS
:
7190 case R_PPC64_TPREL16_HIGH
:
7191 case R_PPC64_TPREL16_HIGHA
:
7192 case R_PPC64_TPREL16_HIGHER
:
7193 case R_PPC64_TPREL16_HIGHERA
:
7194 case R_PPC64_TPREL16_HIGHEST
:
7195 case R_PPC64_TPREL16_HIGHESTA
:
7196 case R_PPC64_TPREL64
:
7197 case R_PPC64_TPREL34
:
7198 case R_PPC64_DTPMOD64
:
7199 case R_PPC64_DTPREL64
:
7200 case R_PPC64_ADDR64
:
7204 case R_PPC64_ADDR14
:
7205 case R_PPC64_ADDR14_BRNTAKEN
:
7206 case R_PPC64_ADDR14_BRTAKEN
:
7207 case R_PPC64_ADDR16
:
7208 case R_PPC64_ADDR16_DS
:
7209 case R_PPC64_ADDR16_HA
:
7210 case R_PPC64_ADDR16_HI
:
7211 case R_PPC64_ADDR16_HIGH
:
7212 case R_PPC64_ADDR16_HIGHA
:
7213 case R_PPC64_ADDR16_HIGHER
:
7214 case R_PPC64_ADDR16_HIGHERA
:
7215 case R_PPC64_ADDR16_HIGHEST
:
7216 case R_PPC64_ADDR16_HIGHESTA
:
7217 case R_PPC64_ADDR16_LO
:
7218 case R_PPC64_ADDR16_LO_DS
:
7219 case R_PPC64_ADDR24
:
7220 case R_PPC64_ADDR32
:
7221 case R_PPC64_UADDR16
:
7222 case R_PPC64_UADDR32
:
7223 case R_PPC64_UADDR64
:
7226 case R_PPC64_D34_LO
:
7227 case R_PPC64_D34_HI30
:
7228 case R_PPC64_D34_HA30
:
7229 case R_PPC64_ADDR16_HIGHER34
:
7230 case R_PPC64_ADDR16_HIGHERA34
:
7231 case R_PPC64_ADDR16_HIGHEST34
:
7232 case R_PPC64_ADDR16_HIGHESTA34
:
7237 if (local_syms
!= NULL
)
7239 unsigned long r_symndx
;
7240 bfd
*ibfd
= sec
->owner
;
7242 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7243 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7248 && (h
->root
.type
== bfd_link_hash_defweak
7249 || !h
->def_regular
))
7251 && !bfd_link_executable (info
)
7252 && !SYMBOLIC_BIND (info
, h
))
7253 || (bfd_link_pic (info
)
7254 && must_be_dyn_reloc (info
, r_type
))
7255 || (!bfd_link_pic (info
)
7257 ? h
->type
== STT_GNU_IFUNC
7258 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
7265 struct ppc_dyn_relocs
*p
;
7266 struct ppc_dyn_relocs
**pp
;
7267 pp
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
7269 /* elf_gc_sweep may have already removed all dyn relocs associated
7270 with local syms for a given section. Also, symbol flags are
7271 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7272 report a dynreloc miscount. */
7273 if (*pp
== NULL
&& info
->gc_sections
)
7276 while ((p
= *pp
) != NULL
)
7280 if (!must_be_dyn_reloc (info
, r_type
))
7282 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
7283 && rel
->r_offset
% 2 == 0
7284 && sec
->alignment_power
!= 0)
7296 struct ppc_local_dyn_relocs
*p
;
7297 struct ppc_local_dyn_relocs
**pp
;
7301 if (local_syms
== NULL
)
7302 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7303 if (sym_sec
== NULL
)
7306 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7307 pp
= (struct ppc_local_dyn_relocs
**) vpp
;
7309 if (*pp
== NULL
&& info
->gc_sections
)
7312 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7313 while ((p
= *pp
) != NULL
)
7315 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7317 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
7318 && rel
->r_offset
% 2 == 0
7319 && sec
->alignment_power
!= 0)
7330 /* xgettext:c-format */
7331 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7333 bfd_set_error (bfd_error_bad_value
);
7337 /* Remove unused Official Procedure Descriptor entries. Currently we
7338 only remove those associated with functions in discarded link-once
7339 sections, or weakly defined functions that have been overridden. It
7340 would be possible to remove many more entries for statically linked
7344 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7347 bool some_edited
= false;
7348 asection
*need_pad
= NULL
;
7349 struct ppc_link_hash_table
*htab
;
7351 htab
= ppc_hash_table (info
);
7355 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7358 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7359 Elf_Internal_Shdr
*symtab_hdr
;
7360 Elf_Internal_Sym
*local_syms
;
7361 struct _opd_sec_data
*opd
;
7362 bool need_edit
, add_aux_fields
, broken
;
7363 bfd_size_type cnt_16b
= 0;
7365 if (!is_ppc64_elf (ibfd
))
7368 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7369 if (sec
== NULL
|| sec
->size
== 0)
7372 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7375 if (sec
->output_section
== bfd_abs_section_ptr
)
7378 /* Look through the section relocs. */
7379 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7383 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7385 /* Read the relocations. */
7386 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7388 if (relstart
== NULL
)
7391 /* First run through the relocs to check they are sane, and to
7392 determine whether we need to edit this opd section. */
7396 relend
= relstart
+ sec
->reloc_count
;
7397 for (rel
= relstart
; rel
< relend
; )
7399 enum elf_ppc64_reloc_type r_type
;
7400 unsigned long r_symndx
;
7402 struct elf_link_hash_entry
*h
;
7403 Elf_Internal_Sym
*sym
;
7406 /* .opd contains an array of 16 or 24 byte entries. We're
7407 only interested in the reloc pointing to a function entry
7409 offset
= rel
->r_offset
;
7410 if (rel
+ 1 == relend
7411 || rel
[1].r_offset
!= offset
+ 8)
7413 /* If someone messes with .opd alignment then after a
7414 "ld -r" we might have padding in the middle of .opd.
7415 Also, there's nothing to prevent someone putting
7416 something silly in .opd with the assembler. No .opd
7417 optimization for them! */
7420 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7425 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7426 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7429 /* xgettext:c-format */
7430 (_("%pB: unexpected reloc type %u in .opd section"),
7436 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7437 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7441 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7443 const char *sym_name
;
7445 sym_name
= h
->root
.root
.string
;
7447 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7451 /* xgettext:c-format */
7452 (_("%pB: undefined sym `%s' in .opd section"),
7458 /* opd entries are always for functions defined in the
7459 current input bfd. If the symbol isn't defined in the
7460 input bfd, then we won't be using the function in this
7461 bfd; It must be defined in a linkonce section in another
7462 bfd, or is weak. It's also possible that we are
7463 discarding the function due to a linker script /DISCARD/,
7464 which we test for via the output_section. */
7465 if (sym_sec
->owner
!= ibfd
7466 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7470 if (rel
+ 1 == relend
7471 || (rel
+ 2 < relend
7472 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7477 if (sec
->size
== offset
+ 24)
7482 if (sec
->size
== offset
+ 16)
7489 else if (rel
+ 1 < relend
7490 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7491 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7493 if (rel
[0].r_offset
== offset
+ 16)
7495 else if (rel
[0].r_offset
!= offset
+ 24)
7502 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7504 if (!broken
&& (need_edit
|| add_aux_fields
))
7506 Elf_Internal_Rela
*write_rel
;
7507 Elf_Internal_Shdr
*rel_hdr
;
7508 bfd_byte
*rptr
, *wptr
;
7509 bfd_byte
*new_contents
;
7512 new_contents
= NULL
;
7513 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7514 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7515 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7516 if (opd
->adjust
== NULL
)
7519 /* This seems a waste of time as input .opd sections are all
7520 zeros as generated by gcc, but I suppose there's no reason
7521 this will always be so. We might start putting something in
7522 the third word of .opd entries. */
7523 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7526 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7530 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7532 if (elf_section_data (sec
)->relocs
!= relstart
)
7536 sec
->contents
= loc
;
7537 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7540 elf_section_data (sec
)->relocs
= relstart
;
7542 new_contents
= sec
->contents
;
7545 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7546 if (new_contents
== NULL
)
7550 wptr
= new_contents
;
7551 rptr
= sec
->contents
;
7552 write_rel
= relstart
;
7553 for (rel
= relstart
; rel
< relend
; )
7555 unsigned long r_symndx
;
7557 struct elf_link_hash_entry
*h
;
7558 struct ppc_link_hash_entry
*fdh
= NULL
;
7559 Elf_Internal_Sym
*sym
;
7561 Elf_Internal_Rela
*next_rel
;
7564 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7565 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7570 if (next_rel
+ 1 == relend
7571 || (next_rel
+ 2 < relend
7572 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7575 /* See if the .opd entry is full 24 byte or
7576 16 byte (with fd_aux entry overlapped with next
7579 if (next_rel
== relend
)
7581 if (sec
->size
== rel
->r_offset
+ 16)
7584 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7588 && h
->root
.root
.string
[0] == '.')
7590 fdh
= ppc_elf_hash_entry (h
)->oh
;
7593 fdh
= ppc_follow_link (fdh
);
7594 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
7595 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7600 skip
= (sym_sec
->owner
!= ibfd
7601 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7604 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7606 /* Arrange for the function descriptor sym
7608 fdh
->elf
.root
.u
.def
.value
= 0;
7609 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7611 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7613 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7618 if (!dec_dynrel_count (rel
, sec
, info
,
7622 if (++rel
== next_rel
)
7625 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7626 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7633 /* We'll be keeping this opd entry. */
7638 /* Redefine the function descriptor symbol to
7639 this location in the opd section. It is
7640 necessary to update the value here rather
7641 than using an array of adjustments as we do
7642 for local symbols, because various places
7643 in the generic ELF code use the value
7644 stored in u.def.value. */
7645 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7646 fdh
->adjust_done
= 1;
7649 /* Local syms are a bit tricky. We could
7650 tweak them as they can be cached, but
7651 we'd need to look through the local syms
7652 for the function descriptor sym which we
7653 don't have at the moment. So keep an
7654 array of adjustments. */
7655 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
7656 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
7659 memcpy (wptr
, rptr
, opd_ent_size
);
7660 wptr
+= opd_ent_size
;
7661 if (add_aux_fields
&& opd_ent_size
== 16)
7663 memset (wptr
, '\0', 8);
7667 /* We need to adjust any reloc offsets to point to the
7669 for ( ; rel
!= next_rel
; ++rel
)
7671 rel
->r_offset
+= adjust
;
7672 if (write_rel
!= rel
)
7673 memcpy (write_rel
, rel
, sizeof (*rel
));
7678 rptr
+= opd_ent_size
;
7681 sec
->size
= wptr
- new_contents
;
7682 sec
->reloc_count
= write_rel
- relstart
;
7685 free (sec
->contents
);
7686 sec
->contents
= new_contents
;
7689 /* Fudge the header size too, as this is used later in
7690 elf_bfd_final_link if we are emitting relocs. */
7691 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7692 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7695 else if (elf_section_data (sec
)->relocs
!= relstart
)
7698 if (local_syms
!= NULL
7699 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7701 if (!info
->keep_memory
)
7704 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7709 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7711 /* If we are doing a final link and the last .opd entry is just 16 byte
7712 long, add a 8 byte padding after it. */
7713 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7717 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7719 BFD_ASSERT (need_pad
->size
> 0);
7721 p
= bfd_malloc (need_pad
->size
+ 8);
7725 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7726 p
, 0, need_pad
->size
))
7729 need_pad
->contents
= p
;
7730 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7734 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7738 need_pad
->contents
= p
;
7741 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7742 need_pad
->size
+= 8;
7748 /* Analyze inline PLT call relocations to see whether calls to locally
7749 defined functions can be converted to direct calls. */
7752 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7754 struct ppc_link_hash_table
*htab
;
7757 bfd_vma low_vma
, high_vma
, limit
;
7759 htab
= ppc_hash_table (info
);
7763 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7764 reduced somewhat to cater for possible stubs that might be added
7765 between the call and its destination. */
7766 if (htab
->params
->group_size
< 0)
7768 limit
= -htab
->params
->group_size
;
7774 limit
= htab
->params
->group_size
;
7781 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7782 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7784 if (low_vma
> sec
->vma
)
7786 if (high_vma
< sec
->vma
+ sec
->size
)
7787 high_vma
= sec
->vma
+ sec
->size
;
7790 /* If a "bl" can reach anywhere in local code sections, then we can
7791 convert all inline PLT sequences to direct calls when the symbol
7793 if (high_vma
- low_vma
< limit
)
7795 htab
->can_convert_all_inline_plt
= 1;
7799 /* Otherwise, go looking through relocs for cases where a direct
7800 call won't reach. Mark the symbol on any such reloc to disable
7801 the optimization and keep the PLT entry as it seems likely that
7802 this will be better than creating trampolines. Note that this
7803 will disable the optimization for all inline PLT calls to a
7804 particular symbol, not just those that won't reach. The
7805 difficulty in doing a more precise optimization is that the
7806 linker needs to make a decision depending on whether a
7807 particular R_PPC64_PLTCALL insn can be turned into a direct
7808 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7809 the sequence, and there is nothing that ties those relocs
7810 together except their symbol. */
7812 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7814 Elf_Internal_Shdr
*symtab_hdr
;
7815 Elf_Internal_Sym
*local_syms
;
7817 if (!is_ppc64_elf (ibfd
))
7821 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7823 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7824 if (ppc64_elf_section_data (sec
)->has_pltcall
7825 && !bfd_is_abs_section (sec
->output_section
))
7827 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7829 /* Read the relocations. */
7830 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7832 if (relstart
== NULL
)
7835 relend
= relstart
+ sec
->reloc_count
;
7836 for (rel
= relstart
; rel
< relend
; rel
++)
7838 enum elf_ppc64_reloc_type r_type
;
7839 unsigned long r_symndx
;
7841 struct elf_link_hash_entry
*h
;
7842 Elf_Internal_Sym
*sym
;
7843 unsigned char *tls_maskp
;
7845 r_type
= ELF64_R_TYPE (rel
->r_info
);
7846 if (r_type
!= R_PPC64_PLTCALL
7847 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
7850 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7851 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7854 if (elf_section_data (sec
)->relocs
!= relstart
)
7856 if (symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7861 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7865 to
= h
->root
.u
.def
.value
;
7868 to
+= (rel
->r_addend
7869 + sym_sec
->output_offset
7870 + sym_sec
->output_section
->vma
);
7871 from
= (rel
->r_offset
7872 + sec
->output_offset
7873 + sec
->output_section
->vma
);
7874 if (to
- from
+ limit
< 2 * limit
7875 && !(r_type
== R_PPC64_PLTCALL_NOTOC
7876 && (((h
? h
->other
: sym
->st_other
)
7877 & STO_PPC64_LOCAL_MASK
)
7878 > 1 << STO_PPC64_LOCAL_BIT
)))
7879 *tls_maskp
&= ~PLT_KEEP
;
7882 if (elf_section_data (sec
)->relocs
!= relstart
)
7886 if (local_syms
!= NULL
7887 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7889 if (!info
->keep_memory
)
7892 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7899 /* Set htab->tls_get_addr and various other info specific to TLS.
7900 This needs to run before dynamic symbols are processed in
7901 bfd_elf_size_dynamic_sections. */
7904 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7906 struct ppc_link_hash_table
*htab
;
7907 struct elf_link_hash_entry
*tga
, *tga_fd
, *desc
, *desc_fd
;
7909 htab
= ppc_hash_table (info
);
7913 /* Move dynamic linking info to the function descriptor sym. */
7914 if (htab
->need_func_desc_adj
)
7916 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7917 htab
->need_func_desc_adj
= 0;
7920 if (abiversion (info
->output_bfd
) == 1)
7923 if (htab
->params
->no_multi_toc
)
7924 htab
->do_multi_toc
= 0;
7925 else if (!htab
->do_multi_toc
)
7926 htab
->params
->no_multi_toc
= 1;
7928 /* Default to --no-plt-localentry, as this option can cause problems
7929 with symbol interposition. For example, glibc libpthread.so and
7930 libc.so duplicate many pthread symbols, with a fallback
7931 implementation in libc.so. In some cases the fallback does more
7932 work than the pthread implementation. __pthread_condattr_destroy
7933 is one such symbol: the libpthread.so implementation is
7934 localentry:0 while the libc.so implementation is localentry:8.
7935 An app that "cleverly" uses dlopen to only load necessary
7936 libraries at runtime may omit loading libpthread.so when not
7937 running multi-threaded, which then results in the libc.so
7938 fallback symbols being used and ld.so complaining. Now there
7939 are workarounds in ld (see non_zero_localentry) to detect the
7940 pthread situation, but that may not be the only case where
7941 --plt-localentry can cause trouble. */
7942 if (htab
->params
->plt_localentry0
< 0)
7943 htab
->params
->plt_localentry0
= 0;
7944 if (htab
->params
->plt_localentry0
&& htab
->has_power10_relocs
)
7946 /* The issue is that __glink_PLTresolve saves r2, which is done
7947 because glibc ld.so _dl_runtime_resolve restores r2 to support
7948 a glibc plt call optimisation where global entry code is
7949 skipped on calls that resolve to the same binary. The
7950 __glink_PLTresolve save of r2 is incompatible with code
7951 making tail calls, because the tail call might go via the
7952 resolver and thus overwrite the proper saved r2. */
7953 _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
7954 "power10 pc-relative code"));
7955 htab
->params
->plt_localentry0
= 0;
7957 if (htab
->params
->plt_localentry0
7958 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7959 false, false, false) == NULL
)
7961 (_("warning: --plt-localentry is especially dangerous without "
7962 "ld.so support to detect ABI violations"));
7964 tga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7965 false, false, true);
7966 htab
->tls_get_addr
= ppc_elf_hash_entry (tga
);
7967 tga_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7968 false, false, true);
7969 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (tga_fd
);
7971 desc
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_desc",
7972 false, false, true);
7973 htab
->tga_desc
= ppc_elf_hash_entry (desc
);
7974 desc_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_desc",
7975 false, false, true);
7976 htab
->tga_desc_fd
= ppc_elf_hash_entry (desc_fd
);
7978 if (htab
->params
->tls_get_addr_opt
)
7980 struct elf_link_hash_entry
*opt
, *opt_fd
;
7982 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7983 false, false, true);
7984 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7985 false, false, true);
7987 && (opt_fd
->root
.type
== bfd_link_hash_defined
7988 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7990 /* If glibc supports an optimized __tls_get_addr call stub,
7991 signalled by the presence of __tls_get_addr_opt, and we'll
7992 be calling __tls_get_addr via a plt call stub, then
7993 make __tls_get_addr point to __tls_get_addr_opt. */
7994 if (!(htab
->elf
.dynamic_sections_created
7996 && (tga_fd
->type
== STT_FUNC
7997 || tga_fd
->needs_plt
)
7998 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7999 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
))))
8001 if (!(htab
->elf
.dynamic_sections_created
8003 && (desc_fd
->type
== STT_FUNC
8004 || desc_fd
->needs_plt
)
8005 && !(SYMBOL_CALLS_LOCAL (info
, desc_fd
)
8006 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, desc_fd
))))
8009 if (tga_fd
!= NULL
|| desc_fd
!= NULL
)
8011 struct plt_entry
*ent
= NULL
;
8014 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8015 if (ent
->plt
.refcount
> 0)
8017 if (ent
== NULL
&& desc_fd
!= NULL
)
8018 for (ent
= desc_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8019 if (ent
->plt
.refcount
> 0)
8025 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8026 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8027 tga_fd
->root
.u
.i
.warning
= NULL
;
8028 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8030 if (desc_fd
!= NULL
)
8032 desc_fd
->root
.type
= bfd_link_hash_indirect
;
8033 desc_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8034 desc_fd
->root
.u
.i
.warning
= NULL
;
8035 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, desc_fd
);
8038 if (opt_fd
->dynindx
!= -1)
8040 /* Use __tls_get_addr_opt in dynamic relocations. */
8041 opt_fd
->dynindx
= -1;
8042 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8043 opt_fd
->dynstr_index
);
8044 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8049 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (opt_fd
);
8050 tga
= elf_hash_entry (htab
->tls_get_addr
);
8051 if (opt
!= NULL
&& tga
!= NULL
)
8053 tga
->root
.type
= bfd_link_hash_indirect
;
8054 tga
->root
.u
.i
.link
= &opt
->root
;
8055 tga
->root
.u
.i
.warning
= NULL
;
8056 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8058 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8060 htab
->tls_get_addr
= ppc_elf_hash_entry (opt
);
8062 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8063 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8064 if (htab
->tls_get_addr
!= NULL
)
8066 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8067 htab
->tls_get_addr
->is_func
= 1;
8070 if (desc_fd
!= NULL
)
8072 htab
->tga_desc_fd
= ppc_elf_hash_entry (opt_fd
);
8073 if (opt
!= NULL
&& desc
!= NULL
)
8075 desc
->root
.type
= bfd_link_hash_indirect
;
8076 desc
->root
.u
.i
.link
= &opt
->root
;
8077 desc
->root
.u
.i
.warning
= NULL
;
8078 ppc64_elf_copy_indirect_symbol (info
, opt
, desc
);
8080 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8081 desc
->forced_local
);
8082 htab
->tga_desc
= ppc_elf_hash_entry (opt
);
8084 htab
->tga_desc_fd
->oh
= htab
->tga_desc
;
8085 htab
->tga_desc_fd
->is_func_descriptor
= 1;
8086 if (htab
->tga_desc
!= NULL
)
8088 htab
->tga_desc
->oh
= htab
->tga_desc_fd
;
8089 htab
->tga_desc
->is_func
= 1;
8095 else if (htab
->params
->tls_get_addr_opt
< 0)
8096 htab
->params
->tls_get_addr_opt
= 0;
8099 if (htab
->tga_desc_fd
!= NULL
8100 && htab
->params
->tls_get_addr_opt
8101 && htab
->params
->no_tls_get_addr_regsave
== -1)
8102 htab
->params
->no_tls_get_addr_regsave
= 0;
8107 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8108 any of HASH1, HASH2, HASH3, or HASH4. */
8111 branch_reloc_hash_match (bfd
*ibfd
,
8112 Elf_Internal_Rela
*rel
,
8113 struct ppc_link_hash_entry
*hash1
,
8114 struct ppc_link_hash_entry
*hash2
,
8115 struct ppc_link_hash_entry
*hash3
,
8116 struct ppc_link_hash_entry
*hash4
)
8118 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8119 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8120 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8122 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8124 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8125 struct elf_link_hash_entry
*h
;
8127 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8128 h
= elf_follow_link (h
);
8129 if (h
== elf_hash_entry (hash1
)
8130 || h
== elf_hash_entry (hash2
)
8131 || h
== elf_hash_entry (hash3
)
8132 || h
== elf_hash_entry (hash4
))
8138 /* Run through all the TLS relocs looking for optimization
8139 opportunities. The linker has been hacked (see ppc64elf.em) to do
8140 a preliminary section layout so that we know the TLS segment
8141 offsets. We can't optimize earlier because some optimizations need
8142 to know the tp offset, and we need to optimize before allocating
8143 dynamic relocations. */
8146 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8150 struct ppc_link_hash_table
*htab
;
8151 unsigned char *toc_ref
;
8154 if (!bfd_link_executable (info
))
8157 htab
= ppc_hash_table (info
);
8161 htab
->do_tls_opt
= 1;
8163 /* Make two passes over the relocs. On the first pass, mark toc
8164 entries involved with tls relocs, and check that tls relocs
8165 involved in setting up a tls_get_addr call are indeed followed by
8166 such a call. If they are not, we can't do any tls optimization.
8167 On the second pass twiddle tls_mask flags to notify
8168 relocate_section that optimization can be done, and adjust got
8169 and plt refcounts. */
8171 for (pass
= 0; pass
< 2; ++pass
)
8172 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8174 Elf_Internal_Sym
*locsyms
= NULL
;
8175 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8177 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8178 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8180 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8181 bool found_tls_get_addr_arg
= 0;
8183 /* Read the relocations. */
8184 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8186 if (relstart
== NULL
)
8192 relend
= relstart
+ sec
->reloc_count
;
8193 for (rel
= relstart
; rel
< relend
; rel
++)
8195 enum elf_ppc64_reloc_type r_type
;
8196 unsigned long r_symndx
;
8197 struct elf_link_hash_entry
*h
;
8198 Elf_Internal_Sym
*sym
;
8200 unsigned char *tls_mask
;
8201 unsigned int tls_set
, tls_clear
, tls_type
= 0;
8203 bool ok_tprel
, is_local
;
8204 long toc_ref_index
= 0;
8205 int expecting_tls_get_addr
= 0;
8208 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8209 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8213 if (elf_section_data (sec
)->relocs
!= relstart
)
8216 if (elf_symtab_hdr (ibfd
).contents
8217 != (unsigned char *) locsyms
)
8224 if (h
->root
.type
== bfd_link_hash_defined
8225 || h
->root
.type
== bfd_link_hash_defweak
)
8226 value
= h
->root
.u
.def
.value
;
8227 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8231 found_tls_get_addr_arg
= 0;
8236 /* Symbols referenced by TLS relocs must be of type
8237 STT_TLS. So no need for .opd local sym adjust. */
8238 value
= sym
->st_value
;
8241 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
8245 && h
->root
.type
== bfd_link_hash_undefweak
)
8247 else if (sym_sec
!= NULL
8248 && sym_sec
->output_section
!= NULL
)
8250 value
+= sym_sec
->output_offset
;
8251 value
+= sym_sec
->output_section
->vma
;
8252 value
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8253 /* Note that even though the prefix insns
8254 allow a 1<<33 offset we use the same test
8255 as for addis;addi. There may be a mix of
8256 pcrel and non-pcrel code and the decision
8257 to optimise is per symbol, not per TLS
8259 ok_tprel
= value
+ 0x80008000ULL
< 1ULL << 32;
8263 r_type
= ELF64_R_TYPE (rel
->r_info
);
8264 /* If this section has old-style __tls_get_addr calls
8265 without marker relocs, then check that each
8266 __tls_get_addr call reloc is preceded by a reloc
8267 that conceivably belongs to the __tls_get_addr arg
8268 setup insn. If we don't find matching arg setup
8269 relocs, don't do any tls optimization. */
8271 && sec
->nomark_tls_get_addr
8273 && is_tls_get_addr (h
, htab
)
8274 && !found_tls_get_addr_arg
8275 && is_branch_reloc (r_type
))
8277 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8278 "TLS optimization disabled\n"),
8279 ibfd
, sec
, rel
->r_offset
);
8284 found_tls_get_addr_arg
= 0;
8287 case R_PPC64_GOT_TLSLD16
:
8288 case R_PPC64_GOT_TLSLD16_LO
:
8289 case R_PPC64_GOT_TLSLD_PCREL34
:
8290 expecting_tls_get_addr
= 1;
8291 found_tls_get_addr_arg
= 1;
8294 case R_PPC64_GOT_TLSLD16_HI
:
8295 case R_PPC64_GOT_TLSLD16_HA
:
8296 /* These relocs should never be against a symbol
8297 defined in a shared lib. Leave them alone if
8298 that turns out to be the case. */
8305 tls_type
= TLS_TLS
| TLS_LD
;
8308 case R_PPC64_GOT_TLSGD16
:
8309 case R_PPC64_GOT_TLSGD16_LO
:
8310 case R_PPC64_GOT_TLSGD_PCREL34
:
8311 expecting_tls_get_addr
= 1;
8312 found_tls_get_addr_arg
= 1;
8315 case R_PPC64_GOT_TLSGD16_HI
:
8316 case R_PPC64_GOT_TLSGD16_HA
:
8322 tls_set
= TLS_TLS
| TLS_GDIE
;
8324 tls_type
= TLS_TLS
| TLS_GD
;
8327 case R_PPC64_GOT_TPREL_PCREL34
:
8328 case R_PPC64_GOT_TPREL16_DS
:
8329 case R_PPC64_GOT_TPREL16_LO_DS
:
8330 case R_PPC64_GOT_TPREL16_HI
:
8331 case R_PPC64_GOT_TPREL16_HA
:
8336 tls_clear
= TLS_TPREL
;
8337 tls_type
= TLS_TLS
| TLS_TPREL
;
8347 if (rel
+ 1 < relend
8348 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8351 && (ELF64_R_TYPE (rel
[1].r_info
)
8353 && (ELF64_R_TYPE (rel
[1].r_info
)
8354 != R_PPC64_PLTSEQ_NOTOC
))
8356 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8357 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8362 struct plt_entry
*ent
= NULL
;
8364 for (ent
= h
->plt
.plist
;
8367 if (ent
->addend
== rel
[1].r_addend
)
8371 && ent
->plt
.refcount
> 0)
8372 ent
->plt
.refcount
-= 1;
8377 found_tls_get_addr_arg
= 1;
8382 case R_PPC64_TOC16_LO
:
8383 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8386 /* Mark this toc entry as referenced by a TLS
8387 code sequence. We can do that now in the
8388 case of R_PPC64_TLS, and after checking for
8389 tls_get_addr for the TOC16 relocs. */
8390 if (toc_ref
== NULL
)
8392 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8393 if (toc_ref
== NULL
)
8397 value
= h
->root
.u
.def
.value
;
8399 value
= sym
->st_value
;
8400 value
+= rel
->r_addend
;
8403 BFD_ASSERT (value
< toc
->size
8404 && toc
->output_offset
% 8 == 0);
8405 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8406 if (r_type
== R_PPC64_TLS
8407 || r_type
== R_PPC64_TLSGD
8408 || r_type
== R_PPC64_TLSLD
)
8410 toc_ref
[toc_ref_index
] = 1;
8414 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8419 expecting_tls_get_addr
= 2;
8422 case R_PPC64_TPREL64
:
8426 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8431 tls_set
= TLS_EXPLICIT
;
8432 tls_clear
= TLS_TPREL
;
8437 case R_PPC64_DTPMOD64
:
8441 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8443 if (rel
+ 1 < relend
8445 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8446 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8450 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8453 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_GDIE
;
8462 tls_set
= TLS_EXPLICIT
;
8467 case R_PPC64_TPREL16_HA
:
8470 unsigned char buf
[4];
8472 bfd_vma off
= rel
->r_offset
& ~3;
8473 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8476 insn
= bfd_get_32 (ibfd
, buf
);
8477 /* addis rt,13,imm */
8478 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8479 != ((15u << 26) | (13 << 16)))
8481 /* xgettext:c-format */
8482 info
->callbacks
->minfo
8483 (_("%H: warning: %s unexpected insn %#x.\n"),
8484 ibfd
, sec
, off
, "R_PPC64_TPREL16_HA", insn
);
8485 htab
->do_tls_opt
= 0;
8490 case R_PPC64_TPREL16_HI
:
8491 case R_PPC64_TPREL16_HIGH
:
8492 case R_PPC64_TPREL16_HIGHA
:
8493 case R_PPC64_TPREL16_HIGHER
:
8494 case R_PPC64_TPREL16_HIGHERA
:
8495 case R_PPC64_TPREL16_HIGHEST
:
8496 case R_PPC64_TPREL16_HIGHESTA
:
8497 /* These can all be used in sequences along with
8498 TPREL16_LO or TPREL16_LO_DS in ways we aren't
8499 able to verify easily. */
8500 htab
->do_tls_opt
= 0;
8509 if (!expecting_tls_get_addr
8510 || !sec
->nomark_tls_get_addr
)
8513 if (rel
+ 1 < relend
8514 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8515 htab
->tls_get_addr_fd
,
8520 if (expecting_tls_get_addr
== 2)
8522 /* Check for toc tls entries. */
8523 unsigned char *toc_tls
;
8526 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8531 if (toc_tls
!= NULL
)
8533 if ((*toc_tls
& TLS_TLS
) != 0
8534 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8535 found_tls_get_addr_arg
= 1;
8537 toc_ref
[toc_ref_index
] = 1;
8543 /* Uh oh, we didn't find the expected call. We
8544 could just mark this symbol to exclude it
8545 from tls optimization but it's safer to skip
8546 the entire optimization. */
8547 /* xgettext:c-format */
8548 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8549 "TLS optimization disabled\n"),
8550 ibfd
, sec
, rel
->r_offset
);
8555 /* If we don't have old-style __tls_get_addr calls
8556 without TLSGD/TLSLD marker relocs, and we haven't
8557 found a new-style __tls_get_addr call with a
8558 marker for this symbol, then we either have a
8559 broken object file or an -mlongcall style
8560 indirect call to __tls_get_addr without a marker.
8561 Disable optimization in this case. */
8562 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8563 && (tls_set
& TLS_EXPLICIT
) == 0
8564 && !sec
->nomark_tls_get_addr
8565 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8566 != (TLS_TLS
| TLS_MARK
)))
8569 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
8571 struct plt_entry
*ent
= NULL
;
8573 if (htab
->tls_get_addr_fd
!= NULL
)
8574 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8577 if (ent
->addend
== 0)
8580 if (ent
== NULL
&& htab
->tga_desc_fd
!= NULL
)
8581 for (ent
= htab
->tga_desc_fd
->elf
.plt
.plist
;
8584 if (ent
->addend
== 0)
8587 if (ent
== NULL
&& htab
->tls_get_addr
!= NULL
)
8588 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8591 if (ent
->addend
== 0)
8594 if (ent
== NULL
&& htab
->tga_desc
!= NULL
)
8595 for (ent
= htab
->tga_desc
->elf
.plt
.plist
;
8598 if (ent
->addend
== 0)
8602 && ent
->plt
.refcount
> 0)
8603 ent
->plt
.refcount
-= 1;
8609 if ((tls_set
& TLS_EXPLICIT
) == 0)
8611 struct got_entry
*ent
;
8613 /* Adjust got entry for this reloc. */
8617 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8619 for (; ent
!= NULL
; ent
= ent
->next
)
8620 if (ent
->addend
== rel
->r_addend
8621 && ent
->owner
== ibfd
8622 && ent
->tls_type
== tls_type
)
8629 /* We managed to get rid of a got entry. */
8630 if (ent
->got
.refcount
> 0)
8631 ent
->got
.refcount
-= 1;
8636 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8637 we'll lose one or two dyn relocs. */
8638 if (!dec_dynrel_count (rel
, sec
, info
,
8642 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8644 if (!dec_dynrel_count (rel
+ 1, sec
, info
,
8650 *tls_mask
|= tls_set
& 0xff;
8651 *tls_mask
&= ~tls_clear
;
8654 if (elf_section_data (sec
)->relocs
!= relstart
)
8659 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8661 if (!info
->keep_memory
)
8664 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8672 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8673 the values of any global symbols in a toc section that has been
8674 edited. Globals in toc sections should be a rarity, so this function
8675 sets a flag if any are found in toc sections other than the one just
8676 edited, so that further hash table traversals can be avoided. */
8678 struct adjust_toc_info
8681 unsigned long *skip
;
8682 bool global_toc_syms
;
8685 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8688 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8690 struct ppc_link_hash_entry
*eh
;
8691 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8694 if (h
->root
.type
!= bfd_link_hash_defined
8695 && h
->root
.type
!= bfd_link_hash_defweak
)
8698 eh
= ppc_elf_hash_entry (h
);
8699 if (eh
->adjust_done
)
8702 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8704 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8705 i
= toc_inf
->toc
->rawsize
>> 3;
8707 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8709 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8712 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8715 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8716 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8719 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8720 eh
->adjust_done
= 1;
8722 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8723 toc_inf
->global_toc_syms
= true;
8728 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8729 on a _LO variety toc/got reloc. */
8732 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8734 return ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */
8735 || (insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
8736 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
8737 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
8738 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
8739 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
8740 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
8741 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
8742 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
8743 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
8744 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
8745 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
8746 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
8747 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
8748 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
8749 || (insn
& (0x3fu
<< 26)) == 56u << 26 /* lq,lfq */
8750 || ((insn
& (0x3fu
<< 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8751 /* Exclude lfqu by testing reloc. If relocs are ever
8752 defined for the reduced D field in psq_lu then those
8753 will need testing too. */
8754 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8755 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* ld,lwa */
8757 || (insn
& (0x3fu
<< 26)) == 60u << 26 /* stfq */
8758 || ((insn
& (0x3fu
<< 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8759 /* Exclude stfqu. psq_stu as above for psq_lu. */
8760 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8761 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std,stq */
8762 && (insn
& 1) == 0));
8765 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
8766 pld ra,symbol@got@pcrel
8767 load/store rt,off(ra)
8770 load/store rt,off(ra)
8771 may be translated to
8772 pload/pstore rt,symbol+off@pcrel
8774 This function returns true if the optimization is possible, placing
8775 the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
8777 On entry to this function, the linker has already determined that
8778 the pld can be replaced with pla: *PINSN1 is that pla insn,
8779 while *PINSN2 is the second instruction. */
8782 xlate_pcrel_opt (uint64_t *pinsn1
, uint64_t *pinsn2
, bfd_signed_vma
*poff
)
8784 uint64_t insn1
= *pinsn1
;
8785 uint64_t insn2
= *pinsn2
;
8788 if ((insn2
& (63ULL << 58)) == 1ULL << 58)
8790 /* Check that regs match. */
8791 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8794 /* P8LS or PMLS form, non-pcrel. */
8795 if ((insn2
& (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
8798 *pinsn1
= (insn2
& ~(31 << 16) & ~0x3ffff0000ffffULL
) | (1ULL << 52);
8800 off
= ((insn2
>> 16) & 0x3ffff0000ULL
) | (insn2
& 0xffff);
8801 *poff
= (off
^ 0x200000000ULL
) - 0x200000000ULL
;
8807 /* Check that regs match. */
8808 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8811 switch ((insn2
>> 26) & 63)
8827 /* These are the PMLS cases, where we just need to tack a prefix
8829 insn1
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
8830 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8831 off
= insn2
& 0xffff;
8834 case 58: /* lwa, ld */
8835 if ((insn2
& 1) != 0)
8837 insn1
= ((1ULL << 58) | (1ULL << 52)
8838 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
8839 | (insn2
& (31ULL << 21)));
8840 off
= insn2
& 0xfffc;
8843 case 57: /* lxsd, lxssp */
8844 if ((insn2
& 3) < 2)
8846 insn1
= ((1ULL << 58) | (1ULL << 52)
8847 | ((40ULL | (insn2
& 3)) << 26)
8848 | (insn2
& (31ULL << 21)));
8849 off
= insn2
& 0xfffc;
8852 case 61: /* stxsd, stxssp, lxv, stxv */
8853 if ((insn2
& 3) == 0)
8855 else if ((insn2
& 3) >= 2)
8857 insn1
= ((1ULL << 58) | (1ULL << 52)
8858 | ((44ULL | (insn2
& 3)) << 26)
8859 | (insn2
& (31ULL << 21)));
8860 off
= insn2
& 0xfffc;
8864 insn1
= ((1ULL << 58) | (1ULL << 52)
8865 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
8866 | (insn2
& (31ULL << 21)));
8867 off
= insn2
& 0xfff0;
8872 insn1
= ((1ULL << 58) | (1ULL << 52)
8873 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8874 off
= insn2
& 0xffff;
8877 case 6: /* lxvp, stxvp */
8878 if ((insn2
& 0xe) != 0)
8880 insn1
= ((1ULL << 58) | (1ULL << 52)
8881 | ((insn2
& 1) == 0 ? 58ULL << 26 : 62ULL << 26)
8882 | (insn2
& (31ULL << 21)));
8883 off
= insn2
& 0xfff0;
8886 case 62: /* std, stq */
8887 if ((insn2
& 1) != 0)
8889 insn1
= ((1ULL << 58) | (1ULL << 52)
8890 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
8891 | (insn2
& (31ULL << 21)));
8892 off
= insn2
& 0xfffc;
8897 *pinsn2
= (uint64_t) NOP
<< 32;
8898 *poff
= (off
^ 0x8000) - 0x8000;
8902 /* Examine all relocs referencing .toc sections in order to remove
8903 unused .toc entries. */
8906 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8909 struct adjust_toc_info toc_inf
;
8910 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8912 htab
->do_toc_opt
= 1;
8913 toc_inf
.global_toc_syms
= true;
8914 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8916 asection
*toc
, *sec
;
8917 Elf_Internal_Shdr
*symtab_hdr
;
8918 Elf_Internal_Sym
*local_syms
;
8919 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8920 unsigned long *skip
, *drop
;
8921 unsigned char *used
;
8922 unsigned char *keep
, last
, some_unused
;
8924 if (!is_ppc64_elf (ibfd
))
8927 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8930 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8931 || discarded_section (toc
))
8936 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8938 /* Look at sections dropped from the final link. */
8941 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8943 if (sec
->reloc_count
== 0
8944 || !discarded_section (sec
)
8945 || get_opd_info (sec
)
8946 || (sec
->flags
& SEC_ALLOC
) == 0
8947 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8950 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, false);
8951 if (relstart
== NULL
)
8954 /* Run through the relocs to see which toc entries might be
8956 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8958 enum elf_ppc64_reloc_type r_type
;
8959 unsigned long r_symndx
;
8961 struct elf_link_hash_entry
*h
;
8962 Elf_Internal_Sym
*sym
;
8965 r_type
= ELF64_R_TYPE (rel
->r_info
);
8972 case R_PPC64_TOC16_LO
:
8973 case R_PPC64_TOC16_HI
:
8974 case R_PPC64_TOC16_HA
:
8975 case R_PPC64_TOC16_DS
:
8976 case R_PPC64_TOC16_LO_DS
:
8980 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8981 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8989 val
= h
->root
.u
.def
.value
;
8991 val
= sym
->st_value
;
8992 val
+= rel
->r_addend
;
8994 if (val
>= toc
->size
)
8997 /* Anything in the toc ought to be aligned to 8 bytes.
8998 If not, don't mark as unused. */
9004 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9009 skip
[val
>> 3] = ref_from_discarded
;
9012 if (elf_section_data (sec
)->relocs
!= relstart
)
9016 /* For largetoc loads of address constants, we can convert
9017 . addis rx,2,addr@got@ha
9018 . ld ry,addr@got@l(rx)
9020 . addis rx,2,addr@toc@ha
9021 . addi ry,rx,addr@toc@l
9022 when addr is within 2G of the toc pointer. This then means
9023 that the word storing "addr" in the toc is no longer needed. */
9025 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9026 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9027 && toc
->reloc_count
!= 0)
9029 /* Read toc relocs. */
9030 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9032 if (toc_relocs
== NULL
)
9035 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9037 enum elf_ppc64_reloc_type r_type
;
9038 unsigned long r_symndx
;
9040 struct elf_link_hash_entry
*h
;
9041 Elf_Internal_Sym
*sym
;
9044 r_type
= ELF64_R_TYPE (rel
->r_info
);
9045 if (r_type
!= R_PPC64_ADDR64
)
9048 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9049 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9054 || sym_sec
->output_section
== NULL
9055 || discarded_section (sym_sec
))
9058 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9063 if (h
->type
== STT_GNU_IFUNC
)
9065 val
= h
->root
.u
.def
.value
;
9069 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9071 val
= sym
->st_value
;
9073 val
+= rel
->r_addend
;
9074 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9076 /* We don't yet know the exact toc pointer value, but we
9077 know it will be somewhere in the toc section. Don't
9078 optimize if the difference from any possible toc
9079 pointer is outside [ff..f80008000, 7fff7fff]. */
9080 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9081 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9084 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9085 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9090 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9095 skip
[rel
->r_offset
>> 3]
9096 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9103 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9107 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9110 && elf_section_data (sec
)->relocs
!= relstart
)
9112 if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9118 /* Now check all kept sections that might reference the toc.
9119 Check the toc itself last. */
9120 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9123 sec
= (sec
== toc
? NULL
9124 : sec
->next
== NULL
? toc
9125 : sec
->next
== toc
&& toc
->next
? toc
->next
9130 if (sec
->reloc_count
== 0
9131 || discarded_section (sec
)
9132 || get_opd_info (sec
)
9133 || (sec
->flags
& SEC_ALLOC
) == 0
9134 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9137 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9139 if (relstart
== NULL
)
9145 /* Mark toc entries referenced as used. */
9149 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9151 enum elf_ppc64_reloc_type r_type
;
9152 unsigned long r_symndx
;
9154 struct elf_link_hash_entry
*h
;
9155 Elf_Internal_Sym
*sym
;
9158 r_type
= ELF64_R_TYPE (rel
->r_info
);
9162 case R_PPC64_TOC16_LO
:
9163 case R_PPC64_TOC16_HI
:
9164 case R_PPC64_TOC16_HA
:
9165 case R_PPC64_TOC16_DS
:
9166 case R_PPC64_TOC16_LO_DS
:
9167 /* In case we're taking addresses of toc entries. */
9168 case R_PPC64_ADDR64
:
9175 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9176 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9187 val
= h
->root
.u
.def
.value
;
9189 val
= sym
->st_value
;
9190 val
+= rel
->r_addend
;
9192 if (val
>= toc
->size
)
9195 if ((skip
[val
>> 3] & can_optimize
) != 0)
9202 case R_PPC64_TOC16_HA
:
9205 case R_PPC64_TOC16_LO_DS
:
9206 off
= rel
->r_offset
;
9207 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9208 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9214 if ((opc
& (0x3f << 2)) == (58u << 2))
9219 /* Wrong sort of reloc, or not a ld. We may
9220 as well clear ref_from_discarded too. */
9227 /* For the toc section, we only mark as used if this
9228 entry itself isn't unused. */
9229 else if ((used
[rel
->r_offset
>> 3]
9230 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9233 /* Do all the relocs again, to catch reference
9242 if (elf_section_data (sec
)->relocs
!= relstart
)
9246 /* Merge the used and skip arrays. Assume that TOC
9247 doublewords not appearing as either used or unused belong
9248 to an entry more than one doubleword in size. */
9249 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9250 drop
< skip
+ (toc
->size
+ 7) / 8;
9255 *drop
&= ~ref_from_discarded
;
9256 if ((*drop
& can_optimize
) != 0)
9260 else if ((*drop
& ref_from_discarded
) != 0)
9263 last
= ref_from_discarded
;
9273 bfd_byte
*contents
, *src
;
9275 Elf_Internal_Sym
*sym
;
9276 bool local_toc_syms
= false;
9278 /* Shuffle the toc contents, and at the same time convert the
9279 skip array from booleans into offsets. */
9280 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9283 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9285 for (src
= contents
, off
= 0, drop
= skip
;
9286 src
< contents
+ toc
->size
;
9289 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9294 memcpy (src
- off
, src
, 8);
9298 toc
->rawsize
= toc
->size
;
9299 toc
->size
= src
- contents
- off
;
9301 /* Adjust addends for relocs against the toc section sym,
9302 and optimize any accesses we can. */
9303 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9305 if (sec
->reloc_count
== 0
9306 || discarded_section (sec
))
9309 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9311 if (relstart
== NULL
)
9314 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9316 enum elf_ppc64_reloc_type r_type
;
9317 unsigned long r_symndx
;
9319 struct elf_link_hash_entry
*h
;
9322 r_type
= ELF64_R_TYPE (rel
->r_info
);
9329 case R_PPC64_TOC16_LO
:
9330 case R_PPC64_TOC16_HI
:
9331 case R_PPC64_TOC16_HA
:
9332 case R_PPC64_TOC16_DS
:
9333 case R_PPC64_TOC16_LO_DS
:
9334 case R_PPC64_ADDR64
:
9338 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9339 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9347 val
= h
->root
.u
.def
.value
;
9350 val
= sym
->st_value
;
9352 local_toc_syms
= true;
9355 val
+= rel
->r_addend
;
9357 if (val
> toc
->rawsize
)
9359 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9361 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9363 Elf_Internal_Rela
*tocrel
9364 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9365 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9369 case R_PPC64_TOC16_HA
:
9370 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9373 case R_PPC64_TOC16_LO_DS
:
9374 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9378 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9380 info
->callbacks
->einfo
9381 /* xgettext:c-format */
9382 (_("%H: %s references "
9383 "optimized away TOC entry\n"),
9384 ibfd
, sec
, rel
->r_offset
,
9385 ppc64_elf_howto_table
[r_type
]->name
);
9386 bfd_set_error (bfd_error_bad_value
);
9389 rel
->r_addend
= tocrel
->r_addend
;
9390 elf_section_data (sec
)->relocs
= relstart
;
9394 if (h
!= NULL
|| sym
->st_value
!= 0)
9397 rel
->r_addend
-= skip
[val
>> 3];
9398 elf_section_data (sec
)->relocs
= relstart
;
9401 if (elf_section_data (sec
)->relocs
!= relstart
)
9405 /* We shouldn't have local or global symbols defined in the TOC,
9406 but handle them anyway. */
9407 if (local_syms
!= NULL
)
9408 for (sym
= local_syms
;
9409 sym
< local_syms
+ symtab_hdr
->sh_info
;
9411 if (sym
->st_value
!= 0
9412 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9416 if (sym
->st_value
> toc
->rawsize
)
9417 i
= toc
->rawsize
>> 3;
9419 i
= sym
->st_value
>> 3;
9421 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9425 (_("%s defined on removed toc entry"),
9426 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9429 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9430 sym
->st_value
= (bfd_vma
) i
<< 3;
9433 sym
->st_value
-= skip
[i
];
9434 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9437 /* Adjust any global syms defined in this toc input section. */
9438 if (toc_inf
.global_toc_syms
)
9441 toc_inf
.skip
= skip
;
9442 toc_inf
.global_toc_syms
= false;
9443 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9447 if (toc
->reloc_count
!= 0)
9449 Elf_Internal_Shdr
*rel_hdr
;
9450 Elf_Internal_Rela
*wrel
;
9453 /* Remove unused toc relocs, and adjust those we keep. */
9454 if (toc_relocs
== NULL
)
9455 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9457 if (toc_relocs
== NULL
)
9461 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9462 if ((skip
[rel
->r_offset
>> 3]
9463 & (ref_from_discarded
| can_optimize
)) == 0)
9465 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9466 wrel
->r_info
= rel
->r_info
;
9467 wrel
->r_addend
= rel
->r_addend
;
9470 else if (!dec_dynrel_count (rel
, toc
, info
,
9471 &local_syms
, NULL
, NULL
))
9474 elf_section_data (toc
)->relocs
= toc_relocs
;
9475 toc
->reloc_count
= wrel
- toc_relocs
;
9476 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9477 sz
= rel_hdr
->sh_entsize
;
9478 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9481 else if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9484 if (local_syms
!= NULL
9485 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9487 if (!info
->keep_memory
)
9490 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9495 /* Look for cases where we can change an indirect GOT access to
9496 a GOT relative or PC relative access, possibly reducing the
9497 number of GOT entries. */
9498 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9501 Elf_Internal_Shdr
*symtab_hdr
;
9502 Elf_Internal_Sym
*local_syms
;
9503 Elf_Internal_Rela
*relstart
, *rel
;
9506 if (!is_ppc64_elf (ibfd
))
9509 if (!ppc64_elf_tdata (ibfd
)->has_optrel
)
9512 sec
= ppc64_elf_tdata (ibfd
)->got
;
9515 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
9518 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9520 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9522 if (sec
->reloc_count
== 0
9523 || !ppc64_elf_section_data (sec
)->has_optrel
9524 || discarded_section (sec
))
9527 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9529 if (relstart
== NULL
)
9532 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9535 && elf_section_data (sec
)->relocs
!= relstart
)
9540 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9542 enum elf_ppc64_reloc_type r_type
;
9543 unsigned long r_symndx
;
9544 Elf_Internal_Sym
*sym
;
9546 struct elf_link_hash_entry
*h
;
9547 struct got_entry
*ent
;
9549 unsigned char buf
[8];
9551 enum {no_check
, check_lo
, check_ha
} insn_check
;
9553 r_type
= ELF64_R_TYPE (rel
->r_info
);
9557 insn_check
= no_check
;
9560 case R_PPC64_PLT16_HA
:
9561 case R_PPC64_GOT_TLSLD16_HA
:
9562 case R_PPC64_GOT_TLSGD16_HA
:
9563 case R_PPC64_GOT_TPREL16_HA
:
9564 case R_PPC64_GOT_DTPREL16_HA
:
9565 case R_PPC64_GOT16_HA
:
9566 case R_PPC64_TOC16_HA
:
9567 insn_check
= check_ha
;
9570 case R_PPC64_PLT16_LO
:
9571 case R_PPC64_PLT16_LO_DS
:
9572 case R_PPC64_GOT_TLSLD16_LO
:
9573 case R_PPC64_GOT_TLSGD16_LO
:
9574 case R_PPC64_GOT_TPREL16_LO_DS
:
9575 case R_PPC64_GOT_DTPREL16_LO_DS
:
9576 case R_PPC64_GOT16_LO
:
9577 case R_PPC64_GOT16_LO_DS
:
9578 case R_PPC64_TOC16_LO
:
9579 case R_PPC64_TOC16_LO_DS
:
9580 insn_check
= check_lo
;
9584 if (insn_check
!= no_check
)
9586 bfd_vma off
= rel
->r_offset
& ~3;
9588 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9591 insn
= bfd_get_32 (ibfd
, buf
);
9592 if (insn_check
== check_lo
9593 ? !ok_lo_toc_insn (insn
, r_type
)
9594 : ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9595 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9599 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9600 sprintf (str
, "%#08x", insn
);
9601 info
->callbacks
->einfo
9602 /* xgettext:c-format */
9603 (_("%H: got/toc optimization is not supported for"
9604 " %s instruction\n"),
9605 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9612 /* Note that we don't delete GOT entries for
9613 R_PPC64_GOT16_DS since we'd need a lot more
9614 analysis. For starters, the preliminary layout is
9615 before the GOT, PLT, dynamic sections and stubs are
9616 laid out. Then we'd need to allow for changes in
9617 distance between sections caused by alignment. */
9621 case R_PPC64_GOT16_HA
:
9622 case R_PPC64_GOT16_LO_DS
:
9623 case R_PPC64_GOT_PCREL34
:
9627 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9628 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9633 || sym_sec
->output_section
== NULL
9634 || discarded_section (sym_sec
))
9637 if ((h
? h
->type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
)
9640 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9644 val
= h
->root
.u
.def
.value
;
9646 val
= sym
->st_value
;
9647 val
+= rel
->r_addend
;
9648 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9650 /* Fudge factor to allow for the fact that the preliminary layout
9651 isn't exact. Reduce limits by this factor. */
9652 #define LIMIT_ADJUST(LIMIT) ((LIMIT) - (LIMIT) / 16)
9659 case R_PPC64_GOT16_HA
:
9660 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9661 >= LIMIT_ADJUST (0x100000000ULL
))
9664 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9665 rel
->r_offset
& ~3, 4))
9667 insn
= bfd_get_32 (ibfd
, buf
);
9668 if (((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9669 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9673 case R_PPC64_GOT16_LO_DS
:
9674 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9675 >= LIMIT_ADJUST (0x100000000ULL
))
9677 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9678 rel
->r_offset
& ~3, 4))
9680 insn
= bfd_get_32 (ibfd
, buf
);
9681 if ((insn
& (0x3fu
<< 26 | 0x3)) != 58u << 26 /* ld */)
9685 case R_PPC64_GOT_PCREL34
:
9687 pc
+= sec
->output_section
->vma
+ sec
->output_offset
;
9688 if (val
- pc
+ LIMIT_ADJUST (1ULL << 33)
9689 >= LIMIT_ADJUST (1ULL << 34))
9691 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9692 rel
->r_offset
& ~3, 8))
9694 insn
= bfd_get_32 (ibfd
, buf
);
9695 if ((insn
& (-1u << 18)) != ((1u << 26) | (1u << 20)))
9697 insn
= bfd_get_32 (ibfd
, buf
+ 4);
9698 if ((insn
& (0x3fu
<< 26)) != 57u << 26)
9708 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
9709 ent
= local_got_ents
[r_symndx
];
9711 for (; ent
!= NULL
; ent
= ent
->next
)
9712 if (ent
->addend
== rel
->r_addend
9713 && ent
->owner
== ibfd
9714 && ent
->tls_type
== 0)
9716 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
9717 ent
->got
.refcount
-= 1;
9720 if (elf_section_data (sec
)->relocs
!= relstart
)
9724 if (local_syms
!= NULL
9725 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9727 if (!info
->keep_memory
)
9730 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9737 /* Return true iff input section I references the TOC using
9738 instructions limited to +/-32k offsets. */
9741 ppc64_elf_has_small_toc_reloc (asection
*i
)
9743 return (is_ppc64_elf (i
->owner
)
9744 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9747 /* Allocate space for one GOT entry. */
9750 allocate_got (struct elf_link_hash_entry
*h
,
9751 struct bfd_link_info
*info
,
9752 struct got_entry
*gent
)
9754 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9755 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
9756 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9758 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9759 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9760 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9762 gent
->got
.offset
= got
->size
;
9763 got
->size
+= entsize
;
9765 if (h
->type
== STT_GNU_IFUNC
)
9767 htab
->elf
.irelplt
->size
+= rentsize
;
9768 htab
->got_reli_size
+= rentsize
;
9770 else if (((bfd_link_pic (info
)
9771 && (gent
->tls_type
== 0
9772 ? !info
->enable_dt_relr
9773 : !(bfd_link_executable (info
)
9774 && SYMBOL_REFERENCES_LOCAL (info
, h
))))
9775 || (htab
->elf
.dynamic_sections_created
9777 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9778 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9780 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9781 relgot
->size
+= rentsize
;
9785 /* This function merges got entries in the same toc group. */
9788 merge_got_entries (struct got_entry
**pent
)
9790 struct got_entry
*ent
, *ent2
;
9792 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9793 if (!ent
->is_indirect
)
9794 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9795 if (!ent2
->is_indirect
9796 && ent2
->addend
== ent
->addend
9797 && ent2
->tls_type
== ent
->tls_type
9798 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9800 ent2
->is_indirect
= true;
9801 ent2
->got
.ent
= ent
;
9805 /* If H is undefined, make it dynamic if that makes sense. */
9808 ensure_undef_dynamic (struct bfd_link_info
*info
,
9809 struct elf_link_hash_entry
*h
)
9811 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9813 if (htab
->dynamic_sections_created
9814 && ((info
->dynamic_undefined_weak
!= 0
9815 && h
->root
.type
== bfd_link_hash_undefweak
)
9816 || h
->root
.type
== bfd_link_hash_undefined
)
9819 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9820 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9824 /* Choose whether to use htab->iplt or htab->pltlocal rather than the
9825 usual htab->elf.splt section for a PLT entry. */
9828 bool use_local_plt (struct bfd_link_info
*info
,
9829 struct elf_link_hash_entry
*h
)
9833 || !elf_hash_table (info
)->dynamic_sections_created
);
9836 /* Allocate space in .plt, .got and associated reloc sections for
9840 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9842 struct bfd_link_info
*info
;
9843 struct ppc_link_hash_table
*htab
;
9845 struct ppc_link_hash_entry
*eh
;
9846 struct got_entry
**pgent
, *gent
;
9848 if (h
->root
.type
== bfd_link_hash_indirect
)
9851 info
= (struct bfd_link_info
*) inf
;
9852 htab
= ppc_hash_table (info
);
9856 eh
= ppc_elf_hash_entry (h
);
9857 /* Run through the TLS GD got entries first if we're changing them
9859 if ((eh
->tls_mask
& (TLS_TLS
| TLS_GDIE
)) == (TLS_TLS
| TLS_GDIE
))
9860 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9861 if (gent
->got
.refcount
> 0
9862 && (gent
->tls_type
& TLS_GD
) != 0)
9864 /* This was a GD entry that has been converted to TPREL. If
9865 there happens to be a TPREL entry we can use that one. */
9866 struct got_entry
*ent
;
9867 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9868 if (ent
->got
.refcount
> 0
9869 && (ent
->tls_type
& TLS_TPREL
) != 0
9870 && ent
->addend
== gent
->addend
9871 && ent
->owner
== gent
->owner
)
9873 gent
->got
.refcount
= 0;
9877 /* If not, then we'll be using our own TPREL entry. */
9878 if (gent
->got
.refcount
!= 0)
9879 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9882 /* Remove any list entry that won't generate a word in the GOT before
9883 we call merge_got_entries. Otherwise we risk merging to empty
9885 pgent
= &h
->got
.glist
;
9886 while ((gent
= *pgent
) != NULL
)
9887 if (gent
->got
.refcount
> 0)
9889 if ((gent
->tls_type
& TLS_LD
) != 0
9890 && SYMBOL_REFERENCES_LOCAL (info
, h
))
9892 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9893 *pgent
= gent
->next
;
9896 pgent
= &gent
->next
;
9899 *pgent
= gent
->next
;
9901 if (!htab
->do_multi_toc
)
9902 merge_got_entries (&h
->got
.glist
);
9904 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9905 if (!gent
->is_indirect
)
9907 /* Ensure we catch all the cases where this symbol should
9909 if (!ensure_undef_dynamic (info
, h
))
9912 if (!is_ppc64_elf (gent
->owner
))
9915 allocate_got (h
, info
, gent
);
9918 /* If no dynamic sections we can't have dynamic relocs, except for
9919 IFUNCs which are handled even in static executables. */
9920 if (!htab
->elf
.dynamic_sections_created
9921 && h
->type
!= STT_GNU_IFUNC
)
9922 h
->dyn_relocs
= NULL
;
9924 /* Discard relocs on undefined symbols that must be local. */
9925 else if (h
->root
.type
== bfd_link_hash_undefined
9926 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9927 h
->dyn_relocs
= NULL
;
9929 /* Also discard relocs on undefined weak syms with non-default
9930 visibility, or when dynamic_undefined_weak says so. */
9931 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9932 h
->dyn_relocs
= NULL
;
9934 if (h
->dyn_relocs
!= NULL
)
9936 struct ppc_dyn_relocs
*p
, **pp
;
9938 /* In the shared -Bsymbolic case, discard space allocated for
9939 dynamic pc-relative relocs against symbols which turn out to
9940 be defined in regular objects. For the normal shared case,
9941 discard space for relocs that have become local due to symbol
9942 visibility changes. */
9943 if (bfd_link_pic (info
))
9945 /* Relocs that use pc_count are those that appear on a call
9946 insn, or certain REL relocs (see must_be_dyn_reloc) that
9947 can be generated via assembly. We want calls to
9948 protected symbols to resolve directly to the function
9949 rather than going via the plt. If people want function
9950 pointer comparisons to work as expected then they should
9951 avoid writing weird assembly. */
9952 if (SYMBOL_CALLS_LOCAL (info
, h
))
9954 for (pp
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
9958 p
->count
-= p
->pc_count
;
9967 if (h
->dyn_relocs
!= NULL
)
9969 /* Ensure we catch all the cases where this symbol
9970 should be made dynamic. */
9971 if (!ensure_undef_dynamic (info
, h
))
9976 /* For a fixed position executable, discard space for
9977 relocs against symbols which are not dynamic. */
9978 else if (h
->type
!= STT_GNU_IFUNC
)
9980 if ((h
->dynamic_adjusted
9982 && h
->root
.type
== bfd_link_hash_undefweak
9983 && (info
->dynamic_undefined_weak
> 0
9984 || !_bfd_elf_readonly_dynrelocs (h
))))
9986 && !ELF_COMMON_DEF_P (h
))
9988 /* Ensure we catch all the cases where this symbol
9989 should be made dynamic. */
9990 if (!ensure_undef_dynamic (info
, h
))
9993 /* But if that didn't work out, discard dynamic relocs. */
9994 if (h
->dynindx
== -1)
9995 h
->dyn_relocs
= NULL
;
9998 h
->dyn_relocs
= NULL
;
10001 /* Finally, allocate space. */
10002 for (p
= (struct ppc_dyn_relocs
*) h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
10004 unsigned int count
;
10005 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
10006 if (eh
->elf
.type
== STT_GNU_IFUNC
)
10007 sreloc
= htab
->elf
.irelplt
;
10009 if (info
->enable_dt_relr
10010 && ((!NO_OPD_RELOCS
10011 && ppc64_elf_section_data (p
->sec
)->sec_type
== sec_opd
)
10012 || (eh
->elf
.type
!= STT_GNU_IFUNC
10013 && SYMBOL_REFERENCES_LOCAL (info
, h
))))
10014 count
-= p
->rel_count
;
10015 sreloc
->size
+= count
* sizeof (Elf64_External_Rela
);
10019 /* We might need a PLT entry when the symbol
10022 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
10023 d) has plt16 relocs and we are linking statically. */
10024 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
10025 || h
->type
== STT_GNU_IFUNC
10026 || (h
->needs_plt
&& h
->dynamic_adjusted
)
10029 && !htab
->elf
.dynamic_sections_created
10030 && !htab
->can_convert_all_inline_plt
10031 && (ppc_elf_hash_entry (h
)->tls_mask
10032 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
10034 struct plt_entry
*pent
;
10035 bool doneone
= false;
10036 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10037 if (pent
->plt
.refcount
> 0)
10039 if (!ensure_undef_dynamic (info
, h
))
10042 if (use_local_plt (info
, h
))
10044 if (h
->type
== STT_GNU_IFUNC
)
10046 s
= htab
->elf
.iplt
;
10047 pent
->plt
.offset
= s
->size
;
10048 s
->size
+= PLT_ENTRY_SIZE (htab
);
10049 s
= htab
->elf
.irelplt
;
10053 s
= htab
->pltlocal
;
10054 pent
->plt
.offset
= s
->size
;
10055 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10057 if (bfd_link_pic (info
)
10058 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
10059 s
= htab
->relpltlocal
;
10064 /* If this is the first .plt entry, make room for the special
10066 s
= htab
->elf
.splt
;
10068 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
10070 pent
->plt
.offset
= s
->size
;
10072 /* Make room for this entry. */
10073 s
->size
+= PLT_ENTRY_SIZE (htab
);
10075 /* Make room for the .glink code. */
10078 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
10081 /* We need bigger stubs past index 32767. */
10082 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
10089 /* We also need to make an entry in the .rela.plt section. */
10090 s
= htab
->elf
.srelplt
;
10093 s
->size
+= sizeof (Elf64_External_Rela
);
10097 pent
->plt
.offset
= (bfd_vma
) -1;
10100 h
->plt
.plist
= NULL
;
10106 h
->plt
.plist
= NULL
;
10113 #define PPC_LO(v) ((v) & 0xffff)
10114 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10115 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10117 ((((v) & 0x3ffff0000ULL) << 16) | (v & 0xffff))
10118 #define HA34(v) ((v + (1ULL << 33)) >> 34)
10120 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
10121 to set up space for global entry stubs. These are put in glink,
10122 after the branch table. */
10125 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
10127 struct bfd_link_info
*info
;
10128 struct ppc_link_hash_table
*htab
;
10129 struct plt_entry
*pent
;
10132 if (h
->root
.type
== bfd_link_hash_indirect
)
10135 if (!h
->pointer_equality_needed
)
10138 if (h
->def_regular
)
10142 htab
= ppc_hash_table (info
);
10146 s
= htab
->global_entry
;
10147 plt
= htab
->elf
.splt
;
10148 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10149 if (pent
->plt
.offset
!= (bfd_vma
) -1
10150 && pent
->addend
== 0)
10152 /* For ELFv2, if this symbol is not defined in a regular file
10153 and we are not generating a shared library or pie, then we
10154 need to define the symbol in the executable on a call stub.
10155 This is to avoid text relocations. */
10156 bfd_vma off
, stub_align
, stub_off
, stub_size
;
10157 unsigned int align_power
;
10160 stub_off
= s
->size
;
10161 if (htab
->params
->plt_stub_align
>= 0)
10162 align_power
= htab
->params
->plt_stub_align
;
10164 align_power
= -htab
->params
->plt_stub_align
;
10165 /* Setting section alignment is delayed until we know it is
10166 non-empty. Otherwise the .text output section will be
10167 aligned at least to plt_stub_align even when no global
10168 entry stubs are needed. */
10169 if (s
->alignment_power
< align_power
)
10170 s
->alignment_power
= align_power
;
10171 stub_align
= (bfd_vma
) 1 << align_power
;
10172 if (htab
->params
->plt_stub_align
>= 0
10173 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
10174 - (stub_off
& -stub_align
))
10175 > ((stub_size
- 1) & -stub_align
)))
10176 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
10177 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
10178 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
10179 /* Note that for --plt-stub-align negative we have a possible
10180 dependency between stub offset and size. Break that
10181 dependency by assuming the max stub size when calculating
10182 the stub offset. */
10183 if (PPC_HA (off
) == 0)
10185 h
->root
.type
= bfd_link_hash_defined
;
10186 h
->root
.u
.def
.section
= s
;
10187 h
->root
.u
.def
.value
= stub_off
;
10188 s
->size
= stub_off
+ stub_size
;
10194 /* Set the sizes of the dynamic sections. */
10197 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10198 struct bfd_link_info
*info
)
10200 struct ppc_link_hash_table
*htab
;
10205 struct got_entry
*first_tlsld
;
10207 htab
= ppc_hash_table (info
);
10211 dynobj
= htab
->elf
.dynobj
;
10212 if (dynobj
== NULL
)
10215 if (htab
->elf
.dynamic_sections_created
)
10217 /* Set the contents of the .interp section to the interpreter. */
10218 if (bfd_link_executable (info
) && !info
->nointerp
)
10220 s
= bfd_get_linker_section (dynobj
, ".interp");
10223 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10224 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10228 /* Set up .got offsets for local syms, and space for local dynamic
10230 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10232 struct got_entry
**lgot_ents
;
10233 struct got_entry
**end_lgot_ents
;
10234 struct plt_entry
**local_plt
;
10235 struct plt_entry
**end_local_plt
;
10236 unsigned char *lgot_masks
;
10237 bfd_size_type locsymcount
;
10238 Elf_Internal_Shdr
*symtab_hdr
;
10240 if (!is_ppc64_elf (ibfd
))
10243 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10245 struct ppc_local_dyn_relocs
*p
;
10247 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10249 if (!bfd_is_abs_section (p
->sec
)
10250 && bfd_is_abs_section (p
->sec
->output_section
))
10252 /* Input section has been discarded, either because
10253 it is a copy of a linkonce section or due to
10254 linker script /DISCARD/, so we'll be discarding
10257 else if (p
->count
!= 0)
10259 unsigned int count
;
10263 if (info
->enable_dt_relr
10264 && ((!NO_OPD_RELOCS
10265 && (ppc64_elf_section_data (p
->sec
)->sec_type
10268 count
-= p
->rel_count
;
10269 srel
= elf_section_data (p
->sec
)->sreloc
;
10271 srel
= htab
->elf
.irelplt
;
10272 srel
->size
+= count
* sizeof (Elf64_External_Rela
);
10273 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10274 info
->flags
|= DF_TEXTREL
;
10279 lgot_ents
= elf_local_got_ents (ibfd
);
10283 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10284 locsymcount
= symtab_hdr
->sh_info
;
10285 end_lgot_ents
= lgot_ents
+ locsymcount
;
10286 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10287 end_local_plt
= local_plt
+ locsymcount
;
10288 lgot_masks
= (unsigned char *) end_local_plt
;
10289 s
= ppc64_elf_tdata (ibfd
)->got
;
10290 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10292 struct got_entry
**pent
, *ent
;
10295 while ((ent
= *pent
) != NULL
)
10296 if (ent
->got
.refcount
> 0)
10298 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10300 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10305 unsigned int ent_size
= 8;
10306 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10308 ent
->got
.offset
= s
->size
;
10309 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10314 s
->size
+= ent_size
;
10315 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10317 htab
->elf
.irelplt
->size
+= rel_size
;
10318 htab
->got_reli_size
+= rel_size
;
10320 else if (bfd_link_pic (info
)
10321 && (ent
->tls_type
== 0
10322 ? !info
->enable_dt_relr
10323 : !bfd_link_executable (info
)))
10325 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10326 srel
->size
+= rel_size
;
10335 /* Allocate space for plt calls to local syms. */
10336 lgot_masks
= (unsigned char *) end_local_plt
;
10337 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10339 struct plt_entry
*ent
;
10341 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10342 if (ent
->plt
.refcount
> 0)
10344 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10346 s
= htab
->elf
.iplt
;
10347 ent
->plt
.offset
= s
->size
;
10348 s
->size
+= PLT_ENTRY_SIZE (htab
);
10349 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10351 else if (htab
->can_convert_all_inline_plt
10352 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10353 ent
->plt
.offset
= (bfd_vma
) -1;
10356 s
= htab
->pltlocal
;
10357 ent
->plt
.offset
= s
->size
;
10358 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10359 if (bfd_link_pic (info
)
10360 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
10361 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
10365 ent
->plt
.offset
= (bfd_vma
) -1;
10369 /* Allocate global sym .plt and .got entries, and space for global
10370 sym dynamic relocs. */
10371 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10373 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10374 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10376 first_tlsld
= NULL
;
10377 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10379 struct got_entry
*ent
;
10381 if (!is_ppc64_elf (ibfd
))
10384 ent
= ppc64_tlsld_got (ibfd
);
10385 if (ent
->got
.refcount
> 0)
10387 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10389 ent
->is_indirect
= true;
10390 ent
->got
.ent
= first_tlsld
;
10394 if (first_tlsld
== NULL
)
10396 s
= ppc64_elf_tdata (ibfd
)->got
;
10397 ent
->got
.offset
= s
->size
;
10400 if (bfd_link_dll (info
))
10402 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10403 srel
->size
+= sizeof (Elf64_External_Rela
);
10408 ent
->got
.offset
= (bfd_vma
) -1;
10411 /* We now have determined the sizes of the various dynamic sections.
10412 Allocate memory for them. */
10414 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10416 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10419 if (s
== htab
->brlt
|| s
== htab
->relbrlt
|| s
== htab
->elf
.srelrdyn
)
10420 /* These haven't been allocated yet; don't strip. */
10422 else if (s
== htab
->elf
.sgot
10423 || s
== htab
->elf
.splt
10424 || s
== htab
->elf
.iplt
10425 || s
== htab
->pltlocal
10426 || s
== htab
->glink
10427 || s
== htab
->global_entry
10428 || s
== htab
->elf
.sdynbss
10429 || s
== htab
->elf
.sdynrelro
)
10431 /* Strip this section if we don't need it; see the
10434 else if (s
== htab
->glink_eh_frame
)
10436 if (!bfd_is_abs_section (s
->output_section
))
10437 /* Not sized yet. */
10440 else if (startswith (s
->name
, ".rela"))
10444 if (s
!= htab
->elf
.srelplt
)
10447 /* We use the reloc_count field as a counter if we need
10448 to copy relocs into the output file. */
10449 s
->reloc_count
= 0;
10454 /* It's not one of our sections, so don't allocate space. */
10460 /* If we don't need this section, strip it from the
10461 output file. This is mostly to handle .rela.bss and
10462 .rela.plt. We must create both sections in
10463 create_dynamic_sections, because they must be created
10464 before the linker maps input sections to output
10465 sections. The linker does that before
10466 adjust_dynamic_symbol is called, and it is that
10467 function which decides whether anything needs to go
10468 into these sections. */
10469 s
->flags
|= SEC_EXCLUDE
;
10473 if (bfd_is_abs_section (s
->output_section
))
10474 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10477 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10480 /* Allocate memory for the section contents. We use bfd_zalloc
10481 here in case unused entries are not reclaimed before the
10482 section's contents are written out. This should not happen,
10483 but this way if it does we get a R_PPC64_NONE reloc in .rela
10484 sections instead of garbage.
10485 We also rely on the section contents being zero when writing
10486 the GOT and .dynrelro. */
10487 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10488 if (s
->contents
== NULL
)
10492 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10494 if (!is_ppc64_elf (ibfd
))
10497 s
= ppc64_elf_tdata (ibfd
)->got
;
10498 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10501 s
->flags
|= SEC_EXCLUDE
;
10504 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10505 if (s
->contents
== NULL
)
10509 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10513 s
->flags
|= SEC_EXCLUDE
;
10516 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10517 if (s
->contents
== NULL
)
10520 s
->reloc_count
= 0;
10525 if (htab
->elf
.dynamic_sections_created
)
10529 /* Add some entries to the .dynamic section. We fill in the
10530 values later, in ppc64_elf_finish_dynamic_sections, but we
10531 must add the entries now so that we get the correct size for
10532 the .dynamic section. The DT_DEBUG entry is filled in by the
10533 dynamic linker and used by the debugger. */
10534 #define add_dynamic_entry(TAG, VAL) \
10535 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10537 if (bfd_link_executable (info
))
10539 if (!add_dynamic_entry (DT_DEBUG
, 0))
10543 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10545 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10546 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10547 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10548 || !add_dynamic_entry (DT_JMPREL
, 0)
10549 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10553 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10555 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10556 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10560 tls_opt
= (htab
->params
->tls_get_addr_opt
10561 && ((htab
->tls_get_addr_fd
!= NULL
10562 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
)
10563 || (htab
->tga_desc_fd
!= NULL
10564 && htab
->tga_desc_fd
->elf
.plt
.plist
!= NULL
)));
10565 if (tls_opt
|| !htab
->opd_abi
)
10567 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10573 if (!add_dynamic_entry (DT_RELA
, 0)
10574 || !add_dynamic_entry (DT_RELASZ
, 0)
10575 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10578 /* If any dynamic relocs apply to a read-only section,
10579 then we need a DT_TEXTREL entry. */
10580 if ((info
->flags
& DF_TEXTREL
) == 0)
10581 elf_link_hash_traverse (&htab
->elf
,
10582 _bfd_elf_maybe_set_textrel
, info
);
10584 if ((info
->flags
& DF_TEXTREL
) != 0)
10586 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10591 #undef add_dynamic_entry
10596 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10599 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10601 if (h
->plt
.plist
!= NULL
10603 && !h
->pointer_equality_needed
)
10606 return _bfd_elf_hash_symbol (h
);
10609 /* Determine the type of stub needed, if any, for a call. */
10611 static inline enum ppc_stub_main_type
10612 ppc_type_of_stub (asection
*input_sec
,
10613 const Elf_Internal_Rela
*rel
,
10614 struct ppc_link_hash_entry
**hash
,
10615 struct plt_entry
**plt_ent
,
10616 bfd_vma destination
,
10617 unsigned long local_off
)
10619 struct ppc_link_hash_entry
*h
= *hash
;
10621 bfd_vma branch_offset
;
10622 bfd_vma max_branch_offset
;
10623 enum elf_ppc64_reloc_type r_type
;
10627 struct plt_entry
*ent
;
10628 struct ppc_link_hash_entry
*fdh
= h
;
10630 && h
->oh
->is_func_descriptor
)
10632 fdh
= ppc_follow_link (h
->oh
);
10636 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10637 if (ent
->addend
== rel
->r_addend
10638 && ent
->plt
.offset
!= (bfd_vma
) -1)
10641 return ppc_stub_plt_call
;
10644 /* Here, we know we don't have a plt entry. If we don't have a
10645 either a defined function descriptor or a defined entry symbol
10646 in a regular object file, then it is pointless trying to make
10647 any other type of stub. */
10648 if (!is_static_defined (&fdh
->elf
)
10649 && !is_static_defined (&h
->elf
))
10650 return ppc_stub_none
;
10652 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10654 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10655 struct plt_entry
**local_plt
= (struct plt_entry
**)
10656 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10657 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10659 if (local_plt
[r_symndx
] != NULL
)
10661 struct plt_entry
*ent
;
10663 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10664 if (ent
->addend
== rel
->r_addend
10665 && ent
->plt
.offset
!= (bfd_vma
) -1)
10668 return ppc_stub_plt_call
;
10673 /* Determine where the call point is. */
10674 location
= (input_sec
->output_offset
10675 + input_sec
->output_section
->vma
10678 branch_offset
= destination
- location
;
10679 r_type
= ELF64_R_TYPE (rel
->r_info
);
10681 /* Determine if a long branch stub is needed. */
10682 max_branch_offset
= 1 << 25;
10683 if (r_type
== R_PPC64_REL14
10684 || r_type
== R_PPC64_REL14_BRTAKEN
10685 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10686 max_branch_offset
= 1 << 15;
10688 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10689 /* We need a stub. Figure out whether a long_branch or plt_branch
10690 is needed later. */
10691 return ppc_stub_long_branch
;
10693 return ppc_stub_none
;
10696 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
10697 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
10702 . lis %r12,xxx-1b@highest
10703 . ori %r12,%r12,xxx-1b@higher
10704 . sldi %r12,%r12,32
10705 . oris %r12,%r12,xxx-1b@high
10706 . ori %r12,%r12,xxx-1b@l
10707 . add/ldx %r12,%r11,%r12 */
10710 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bool load
)
10712 bfd_put_32 (abfd
, MFLR_R12
, p
);
10714 bfd_put_32 (abfd
, BCL_20_31
, p
);
10716 bfd_put_32 (abfd
, MFLR_R11
, p
);
10718 bfd_put_32 (abfd
, MTLR_R12
, p
);
10720 if (off
+ 0x8000 < 0x10000)
10723 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
10725 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
10728 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10730 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
10733 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
10735 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
10740 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10742 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
10747 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
10749 if (((off
>> 32) & 0xffff) != 0)
10751 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
10755 if (((off
>> 32) & 0xffffffffULL
) != 0)
10757 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
10760 if (PPC_HI (off
) != 0)
10762 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
10765 if (PPC_LO (off
) != 0)
10767 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
10771 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10773 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10779 static unsigned int
10780 size_offset (bfd_vma off
)
10783 if (off
+ 0x8000 < 0x10000)
10785 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10789 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10794 if (((off
>> 32) & 0xffff) != 0)
10797 if (((off
>> 32) & 0xffffffffULL
) != 0)
10799 if (PPC_HI (off
) != 0)
10801 if (PPC_LO (off
) != 0)
10808 static unsigned int
10809 num_relocs_for_offset (bfd_vma off
)
10811 unsigned int num_rel
;
10812 if (off
+ 0x8000 < 0x10000)
10814 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10819 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
10820 && ((off
>> 32) & 0xffff) != 0)
10822 if (PPC_HI (off
) != 0)
10824 if (PPC_LO (off
) != 0)
10830 static Elf_Internal_Rela
*
10831 emit_relocs_for_offset (struct bfd_link_info
*info
, Elf_Internal_Rela
*r
,
10832 bfd_vma roff
, bfd_vma targ
, bfd_vma off
)
10834 bfd_vma relative_targ
= targ
- (roff
- 8);
10835 if (bfd_big_endian (info
->output_bfd
))
10837 r
->r_offset
= roff
;
10838 r
->r_addend
= relative_targ
+ roff
;
10839 if (off
+ 0x8000 < 0x10000)
10840 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16
);
10841 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10843 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HA
);
10846 r
->r_offset
= roff
;
10847 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10848 r
->r_addend
= relative_targ
+ roff
;
10852 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10853 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10856 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHEST
);
10857 if (((off
>> 32) & 0xffff) != 0)
10861 r
->r_offset
= roff
;
10862 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10863 r
->r_addend
= relative_targ
+ roff
;
10866 if (((off
>> 32) & 0xffffffffULL
) != 0)
10868 if (PPC_HI (off
) != 0)
10872 r
->r_offset
= roff
;
10873 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGH
);
10874 r
->r_addend
= relative_targ
+ roff
;
10876 if (PPC_LO (off
) != 0)
10880 r
->r_offset
= roff
;
10881 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10882 r
->r_addend
= relative_targ
+ roff
;
10889 build_power10_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, int odd
,
10893 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10898 bfd_put_32 (abfd
, NOP
, p
);
10904 insn
= PADDI_R12_PC
;
10906 bfd_put_32 (abfd
, insn
>> 32, p
);
10908 bfd_put_32 (abfd
, insn
, p
);
10910 /* The minimum value for paddi is -0x200000000. The minimum value
10911 for li is -0x8000, which when shifted by 34 and added gives a
10912 minimum value of -0x2000200000000. The maximum value is
10913 0x1ffffffff+0x7fff<<34 which is 0x2000200000000-1. */
10914 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10917 bfd_put_32 (abfd
, LI_R11_0
| (HA34 (off
) & 0xffff), p
);
10921 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10924 insn
= PADDI_R12_PC
| D34 (off
);
10925 bfd_put_32 (abfd
, insn
>> 32, p
);
10927 bfd_put_32 (abfd
, insn
, p
);
10931 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10935 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10937 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10942 bfd_put_32 (abfd
, LIS_R11
| ((HA34 (off
) >> 16) & 0x3fff), p
);
10944 bfd_put_32 (abfd
, ORI_R11_R11_0
| (HA34 (off
) & 0xffff), p
);
10948 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10951 insn
= PADDI_R12_PC
| D34 (off
);
10952 bfd_put_32 (abfd
, insn
>> 32, p
);
10954 bfd_put_32 (abfd
, insn
, p
);
10958 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10962 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10964 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10970 static unsigned int
10971 size_power10_offset (bfd_vma off
, int odd
)
10973 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10975 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10981 static unsigned int
10982 num_relocs_for_power10_offset (bfd_vma off
, int odd
)
10984 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10986 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10992 static Elf_Internal_Rela
*
10993 emit_relocs_for_power10_offset (struct bfd_link_info
*info
,
10994 Elf_Internal_Rela
*r
, bfd_vma roff
,
10995 bfd_vma targ
, bfd_vma off
, int odd
)
10997 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10999 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
11001 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
11002 r
->r_offset
= roff
+ d_offset
;
11003 r
->r_addend
= targ
+ 8 - odd
- d_offset
;
11004 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
11010 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
11011 r
->r_offset
= roff
+ d_offset
;
11012 r
->r_addend
= targ
+ 8 + odd
- d_offset
;
11013 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHESTA34
);
11016 r
->r_offset
= roff
+ d_offset
;
11017 r
->r_addend
= targ
+ 4 + odd
- d_offset
;
11018 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
11022 r
->r_offset
= roff
;
11023 r
->r_addend
= targ
;
11024 r
->r_info
= ELF64_R_INFO (0, R_PPC64_PCREL34
);
11028 /* Emit .eh_frame opcode to advance pc by DELTA. */
11031 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
11035 *eh
++ = DW_CFA_advance_loc
+ delta
;
11036 else if (delta
< 256)
11038 *eh
++ = DW_CFA_advance_loc1
;
11041 else if (delta
< 65536)
11043 *eh
++ = DW_CFA_advance_loc2
;
11044 bfd_put_16 (abfd
, delta
, eh
);
11049 *eh
++ = DW_CFA_advance_loc4
;
11050 bfd_put_32 (abfd
, delta
, eh
);
11056 /* Size of required .eh_frame opcode to advance pc by DELTA. */
11058 static unsigned int
11059 eh_advance_size (unsigned int delta
)
11061 if (delta
< 64 * 4)
11062 /* DW_CFA_advance_loc+[1..63]. */
11064 if (delta
< 256 * 4)
11065 /* DW_CFA_advance_loc1, byte. */
11067 if (delta
< 65536 * 4)
11068 /* DW_CFA_advance_loc2, 2 bytes. */
11070 /* DW_CFA_advance_loc4, 4 bytes. */
11074 /* With power7 weakly ordered memory model, it is possible for ld.so
11075 to update a plt entry in one thread and have another thread see a
11076 stale zero toc entry. To avoid this we need some sort of acquire
11077 barrier in the call stub. One solution is to make the load of the
11078 toc word seem to appear to depend on the load of the function entry
11079 word. Another solution is to test for r2 being zero, and branch to
11080 the appropriate glink entry if so.
11082 . fake dep barrier compare
11083 . ld 12,xxx(2) ld 12,xxx(2)
11084 . mtctr 12 mtctr 12
11085 . xor 11,12,12 ld 2,xxx+8(2)
11086 . add 2,2,11 cmpldi 2,0
11087 . ld 2,xxx+8(2) bnectr+
11088 . bctr b <glink_entry>
11090 The solution involving the compare turns out to be faster, so
11091 that's what we use unless the branch won't reach. */
11093 #define ALWAYS_USE_FAKE_DEP 0
11094 #define ALWAYS_EMIT_R2SAVE 0
11096 static inline unsigned int
11097 plt_stub_size (struct ppc_link_hash_table
*htab
,
11098 struct ppc_stub_hash_entry
*stub_entry
,
11104 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11106 size
= 8 + size_power10_offset (off
, odd
);
11107 if (stub_entry
->type
.r2save
)
11110 else if (stub_entry
->type
.sub
== ppc_stub_p9notoc
)
11112 size
= 8 + size_offset (off
- 8);
11113 if (stub_entry
->type
.r2save
)
11119 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11121 if (PPC_HA (off
) != 0)
11126 if (htab
->params
->plt_static_chain
)
11128 if (htab
->params
->plt_thread_safe
11129 && htab
->elf
.dynamic_sections_created
11130 && stub_entry
->h
!= NULL
11131 && stub_entry
->h
->elf
.dynindx
!= -1)
11133 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
)
11138 if (stub_entry
->h
!= NULL
11139 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11140 && htab
->params
->tls_get_addr_opt
)
11142 if (!htab
->params
->no_tls_get_addr_regsave
)
11145 if (stub_entry
->type
.r2save
)
11151 if (stub_entry
->type
.r2save
)
11158 /* Depending on the sign of plt_stub_align:
11159 If positive, return the padding to align to a 2**plt_stub_align
11161 If negative, if this stub would cross fewer 2**plt_stub_align
11162 boundaries if we align, then return the padding needed to do so. */
11164 static inline unsigned int
11165 plt_stub_pad (struct ppc_link_hash_table
*htab
,
11166 struct ppc_stub_hash_entry
*stub_entry
,
11171 unsigned stub_size
;
11172 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
11174 if (htab
->params
->plt_stub_align
>= 0)
11176 stub_align
= 1 << htab
->params
->plt_stub_align
;
11177 if ((stub_off
& (stub_align
- 1)) != 0)
11178 return stub_align
- (stub_off
& (stub_align
- 1));
11182 stub_align
= 1 << -htab
->params
->plt_stub_align
;
11183 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
, odd
);
11184 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
11185 > ((stub_size
- 1) & -stub_align
))
11186 return stub_align
- (stub_off
& (stub_align
- 1));
11190 /* Build a toc using .plt call stub. */
11192 static inline bfd_byte
*
11193 build_plt_stub (struct ppc_link_hash_table
*htab
,
11194 struct ppc_stub_hash_entry
*stub_entry
,
11195 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
11197 bfd
*obfd
= htab
->params
->stub_bfd
;
11198 bool plt_load_toc
= htab
->opd_abi
;
11199 bool plt_static_chain
= htab
->params
->plt_static_chain
;
11200 bool plt_thread_safe
= (htab
->params
->plt_thread_safe
11201 && htab
->elf
.dynamic_sections_created
11202 && stub_entry
->h
!= NULL
11203 && stub_entry
->h
->elf
.dynindx
!= -1);
11204 bool use_fake_dep
= plt_thread_safe
;
11205 bfd_vma cmp_branch_off
= 0;
11207 if (!ALWAYS_USE_FAKE_DEP
11210 && !(stub_entry
->h
!= NULL
11211 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11212 && htab
->params
->tls_get_addr_opt
))
11214 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11215 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
11216 / PLT_ENTRY_SIZE (htab
));
11217 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
11220 if (pltindex
> 32768)
11221 glinkoff
+= (pltindex
- 32768) * 4;
11223 + htab
->glink
->output_offset
11224 + htab
->glink
->output_section
->vma
);
11225 from
= (p
- stub_entry
->group
->stub_sec
->contents
11226 + 4 * (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11227 + 4 * (PPC_HA (offset
) != 0)
11228 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
11229 != PPC_HA (offset
))
11230 + 4 * (plt_static_chain
!= 0)
11232 + stub_entry
->group
->stub_sec
->output_offset
11233 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11234 cmp_branch_off
= to
- from
;
11235 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
11238 if (PPC_HA (offset
) != 0)
11242 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11243 r
[0].r_offset
+= 4;
11244 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11245 r
[1].r_offset
= r
[0].r_offset
+ 4;
11246 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11247 r
[1].r_addend
= r
[0].r_addend
;
11250 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11252 r
[2].r_offset
= r
[1].r_offset
+ 4;
11253 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
11254 r
[2].r_addend
= r
[0].r_addend
;
11258 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
11259 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11260 r
[2].r_addend
= r
[0].r_addend
+ 8;
11261 if (plt_static_chain
)
11263 r
[3].r_offset
= r
[2].r_offset
+ 4;
11264 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11265 r
[3].r_addend
= r
[0].r_addend
+ 16;
11270 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11271 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11274 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
11275 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
11279 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
11280 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
11283 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11285 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
11288 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11293 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
11294 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
11296 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
11297 if (plt_static_chain
)
11298 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
11305 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11306 r
[0].r_offset
+= 4;
11307 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11310 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11312 r
[1].r_offset
= r
[0].r_offset
+ 4;
11313 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
11314 r
[1].r_addend
= r
[0].r_addend
;
11318 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
11319 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11320 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
11321 if (plt_static_chain
)
11323 r
[2].r_offset
= r
[1].r_offset
+ 4;
11324 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11325 r
[2].r_addend
= r
[0].r_addend
+ 8;
11330 if (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
)
11331 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11332 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
11334 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11336 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
11339 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11344 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
11345 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
11347 if (plt_static_chain
)
11348 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
11349 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
11352 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
11354 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
11355 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
11356 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
11359 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
11363 /* Build a special .plt call stub for __tls_get_addr. */
11365 #define LD_R0_0R3 0xe8030000
11366 #define LD_R12_0R3 0xe9830000
11367 #define MR_R0_R3 0x7c601b78
11368 #define CMPDI_R0_0 0x2c200000
11369 #define ADD_R3_R12_R13 0x7c6c6a14
11370 #define BEQLR 0x4d820020
11371 #define MR_R3_R0 0x7c030378
11372 #define BCTRL 0x4e800421
11375 build_tls_get_addr_head (struct ppc_link_hash_table
*htab
,
11376 struct ppc_stub_hash_entry
*stub_entry
,
11379 bfd
*obfd
= htab
->params
->stub_bfd
;
11381 bfd_put_32 (obfd
, LD_R0_0R3
+ 0, p
), p
+= 4;
11382 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
11383 bfd_put_32 (obfd
, CMPDI_R0_0
, p
), p
+= 4;
11384 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
11385 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
11386 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
11387 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
11389 if (!htab
->params
->no_tls_get_addr_regsave
)
11390 p
= tls_get_addr_prologue (obfd
, p
, htab
);
11391 else if (stub_entry
->type
.r2save
)
11393 bfd_put_32 (obfd
, MFLR_R0
, p
);
11395 bfd_put_32 (obfd
, STD_R0_0R1
+ STK_LINKER (htab
), p
);
11402 build_tls_get_addr_tail (struct ppc_link_hash_table
*htab
,
11403 struct ppc_stub_hash_entry
*stub_entry
,
11407 bfd
*obfd
= htab
->params
->stub_bfd
;
11409 if (!htab
->params
->no_tls_get_addr_regsave
)
11411 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11413 if (stub_entry
->type
.r2save
)
11415 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11418 p
= tls_get_addr_epilogue (obfd
, p
, htab
);
11420 else if (stub_entry
->type
.r2save
)
11422 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11424 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
);
11426 bfd_put_32 (obfd
, LD_R0_0R1
+ STK_LINKER (htab
), p
);
11428 bfd_put_32 (obfd
, MTLR_R0
, p
);
11430 bfd_put_32 (obfd
, BLR
, p
);
11434 if (htab
->glink_eh_frame
!= NULL
11435 && htab
->glink_eh_frame
->size
!= 0)
11437 bfd_byte
*base
, *eh
;
11439 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
11440 eh
= base
+ stub_entry
->group
->eh_size
;
11442 if (!htab
->params
->no_tls_get_addr_regsave
)
11444 unsigned int cfa_updt
, delta
, i
;
11446 /* After the bctrl, lr has been modified so we need to emit
11447 .eh_frame info saying the return address is on the stack. In
11448 fact we must put the EH info at or before the call rather
11449 than after it, because the EH info for a call needs to be
11450 specified by that point.
11451 See libgcc/unwind-dw2.c execute_cfa_program.
11452 Any stack pointer update must be described immediately after
11453 the instruction making the change, and since the stdu occurs
11454 after saving regs we put all the reg saves and the cfa
11456 cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
11457 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
11458 stub_entry
->group
->lr_restore
11459 = stub_entry
->stub_offset
+ (p
- loc
) - 4;
11460 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11461 *eh
++ = DW_CFA_def_cfa_offset
;
11469 *eh
++ = DW_CFA_offset_extended_sf
;
11471 *eh
++ = (-16 / 8) & 0x7f;
11472 for (i
= 4; i
< 12; i
++)
11474 *eh
++ = DW_CFA_offset
+ i
;
11475 *eh
++ = (htab
->opd_abi
? 13 : 12) - i
;
11477 *eh
++ = (DW_CFA_advance_loc
11478 + (stub_entry
->group
->lr_restore
- 8 - cfa_updt
) / 4);
11479 *eh
++ = DW_CFA_def_cfa_offset
;
11481 for (i
= 4; i
< 12; i
++)
11482 *eh
++ = DW_CFA_restore
+ i
;
11483 *eh
++ = DW_CFA_advance_loc
+ 2;
11484 *eh
++ = DW_CFA_restore_extended
;
11486 stub_entry
->group
->eh_size
= eh
- base
;
11488 else if (stub_entry
->type
.r2save
)
11490 unsigned int lr_used
, delta
;
11492 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
11493 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11494 stub_entry
->group
->lr_restore
= lr_used
+ 16;
11495 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11496 *eh
++ = DW_CFA_offset_extended_sf
;
11498 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
11499 *eh
++ = DW_CFA_advance_loc
+ 4;
11500 *eh
++ = DW_CFA_restore_extended
;
11502 stub_entry
->group
->eh_size
= eh
- base
;
11508 static Elf_Internal_Rela
*
11509 get_relocs (asection
*sec
, int count
)
11511 Elf_Internal_Rela
*relocs
;
11512 struct bfd_elf_section_data
*elfsec_data
;
11514 elfsec_data
= elf_section_data (sec
);
11515 relocs
= elfsec_data
->relocs
;
11516 if (relocs
== NULL
)
11518 bfd_size_type relsize
;
11519 relsize
= sec
->reloc_count
* sizeof (*relocs
);
11520 relocs
= bfd_alloc (sec
->owner
, relsize
);
11521 if (relocs
== NULL
)
11523 elfsec_data
->relocs
= relocs
;
11524 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
11525 sizeof (Elf_Internal_Shdr
));
11526 if (elfsec_data
->rela
.hdr
== NULL
)
11528 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
11529 * sizeof (Elf64_External_Rela
));
11530 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
11531 sec
->reloc_count
= 0;
11533 relocs
+= sec
->reloc_count
;
11534 sec
->reloc_count
+= count
;
11538 /* Convert the relocs R[0] thru R[-NUM_REL+1], which are all no-symbol
11539 forms, to the equivalent relocs against the global symbol given by
11543 use_global_in_relocs (struct ppc_link_hash_table
*htab
,
11544 struct ppc_stub_hash_entry
*stub_entry
,
11545 Elf_Internal_Rela
*r
, unsigned int num_rel
)
11547 struct elf_link_hash_entry
**hashes
;
11548 unsigned long symndx
;
11549 struct ppc_link_hash_entry
*h
;
11552 /* Relocs are always against symbols in their own object file. Fake
11553 up global sym hashes for the stub bfd (which has no symbols). */
11554 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
11555 if (hashes
== NULL
)
11557 bfd_size_type hsize
;
11559 /* When called the first time, stub_globals will contain the
11560 total number of symbols seen during stub sizing. After
11561 allocating, stub_globals is used as an index to fill the
11563 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
11564 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
11565 if (hashes
== NULL
)
11567 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
11568 htab
->stub_globals
= 1;
11570 symndx
= htab
->stub_globals
++;
11572 hashes
[symndx
] = &h
->elf
;
11573 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
11574 h
= ppc_follow_link (h
->oh
);
11575 BFD_ASSERT (h
->elf
.root
.type
== bfd_link_hash_defined
11576 || h
->elf
.root
.type
== bfd_link_hash_defweak
);
11577 symval
= defined_sym_val (&h
->elf
);
11578 while (num_rel
-- != 0)
11580 r
->r_info
= ELF64_R_INFO (symndx
, ELF64_R_TYPE (r
->r_info
));
11581 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11583 /* H is an opd symbol. The addend must be zero, and the
11584 branch reloc is the only one we can convert. */
11589 r
->r_addend
-= symval
;
11596 get_r2off (struct bfd_link_info
*info
,
11597 struct ppc_stub_hash_entry
*stub_entry
)
11599 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11600 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
11604 /* Support linking -R objects. Get the toc pointer from the
11607 if (!htab
->opd_abi
)
11609 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
11610 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
11612 if (strcmp (opd
->name
, ".opd") != 0
11613 || opd
->reloc_count
!= 0)
11615 info
->callbacks
->einfo
11616 (_("%P: cannot find opd entry toc for `%pT'\n"),
11617 stub_entry
->h
->elf
.root
.root
.string
);
11618 bfd_set_error (bfd_error_bad_value
);
11619 return (bfd_vma
) -1;
11621 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
11622 return (bfd_vma
) -1;
11623 r2off
= bfd_get_64 (opd
->owner
, buf
);
11624 r2off
-= elf_gp (info
->output_bfd
);
11626 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
11631 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11633 struct ppc_stub_hash_entry
*stub_entry
;
11634 struct ppc_branch_hash_entry
*br_entry
;
11635 struct bfd_link_info
*info
;
11636 struct ppc_link_hash_table
*htab
;
11639 bfd_byte
*p
, *relp
;
11641 Elf_Internal_Rela
*r
;
11647 /* Massage our args to the form they really have. */
11648 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11651 /* Fail if the target section could not be assigned to an output
11652 section. The user should fix his linker script. */
11653 if (stub_entry
->target_section
!= NULL
11654 && stub_entry
->target_section
->output_section
== NULL
11655 && info
->non_contiguous_regions
)
11656 info
->callbacks
->einfo (_("%F%P: Could not assign '%pA' to an output section. "
11657 "Retry without --enable-non-contiguous-regions.\n"),
11658 stub_entry
->target_section
);
11660 /* Same for the group. */
11661 if (stub_entry
->group
->stub_sec
!= NULL
11662 && stub_entry
->group
->stub_sec
->output_section
== NULL
11663 && info
->non_contiguous_regions
)
11664 info
->callbacks
->einfo (_("%F%P: Could not assign group %pA target %pA to an "
11665 "output section. Retry without "
11666 "--enable-non-contiguous-regions.\n"),
11667 stub_entry
->group
->stub_sec
,
11668 stub_entry
->target_section
);
11670 htab
= ppc_hash_table (info
);
11674 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
11675 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
11677 htab
->stub_count
[stub_entry
->type
.main
- 1] += 1;
11678 if (stub_entry
->type
.main
== ppc_stub_long_branch
11679 && stub_entry
->type
.sub
== ppc_stub_toc
)
11681 /* Branches are relative. This is where we are going to. */
11682 targ
= (stub_entry
->target_value
11683 + stub_entry
->target_section
->output_offset
11684 + stub_entry
->target_section
->output_section
->vma
);
11685 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11687 /* And this is where we are coming from. */
11688 off
= (stub_entry
->stub_offset
11689 + stub_entry
->group
->stub_sec
->output_offset
11690 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11694 obfd
= htab
->params
->stub_bfd
;
11695 if (stub_entry
->type
.r2save
)
11697 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11699 if (r2off
== (bfd_vma
) -1)
11701 htab
->stub_error
= true;
11704 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11706 if (PPC_HA (r2off
) != 0)
11708 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11711 if (PPC_LO (r2off
) != 0)
11713 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11718 bfd_put_32 (obfd
, B_DOT
| (off
& 0x3fffffc), p
);
11721 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11724 (_("long branch stub `%s' offset overflow"),
11725 stub_entry
->root
.string
);
11726 htab
->stub_error
= true;
11730 if (info
->emitrelocations
)
11732 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11735 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11736 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11737 r
->r_addend
= targ
;
11738 if (stub_entry
->h
!= NULL
11739 && !use_global_in_relocs (htab
, stub_entry
, r
, 1))
11743 else if (stub_entry
->type
.main
== ppc_stub_plt_branch
11744 && stub_entry
->type
.sub
== ppc_stub_toc
)
11746 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11747 stub_entry
->root
.string
+ 9,
11749 if (br_entry
== NULL
)
11751 _bfd_error_handler (_("can't find branch stub `%s'"),
11752 stub_entry
->root
.string
);
11753 htab
->stub_error
= true;
11757 targ
= (stub_entry
->target_value
11758 + stub_entry
->target_section
->output_offset
11759 + stub_entry
->target_section
->output_section
->vma
);
11760 if (!stub_entry
->type
.r2save
)
11761 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11763 bfd_put_64 (htab
->brlt
->owner
, targ
,
11764 htab
->brlt
->contents
+ br_entry
->offset
);
11766 if (br_entry
->iter
== htab
->stub_iteration
)
11768 br_entry
->iter
= 0;
11770 if (htab
->relbrlt
!= NULL
&& !info
->enable_dt_relr
)
11772 /* Create a reloc for the branch lookup table entry. */
11773 Elf_Internal_Rela rela
;
11776 rela
.r_offset
= (br_entry
->offset
11777 + htab
->brlt
->output_offset
11778 + htab
->brlt
->output_section
->vma
);
11779 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11780 rela
.r_addend
= targ
;
11782 rl
= htab
->relbrlt
->contents
;
11783 rl
+= (htab
->relbrlt
->reloc_count
++
11784 * sizeof (Elf64_External_Rela
));
11785 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11787 else if (info
->emitrelocations
)
11789 r
= get_relocs (htab
->brlt
, 1);
11792 /* brlt, being SEC_LINKER_CREATED does not go through the
11793 normal reloc processing. Symbols and offsets are not
11794 translated from input file to output file form, so
11795 set up the offset per the output file. */
11796 r
->r_offset
= (br_entry
->offset
11797 + htab
->brlt
->output_offset
11798 + htab
->brlt
->output_section
->vma
);
11799 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11800 r
->r_addend
= targ
;
11804 targ
= (br_entry
->offset
11805 + htab
->brlt
->output_offset
11806 + htab
->brlt
->output_section
->vma
);
11808 off
= (elf_gp (info
->output_bfd
)
11809 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11812 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11814 info
->callbacks
->einfo
11815 (_("%P: linkage table error against `%pT'\n"),
11816 stub_entry
->root
.string
);
11817 bfd_set_error (bfd_error_bad_value
);
11818 htab
->stub_error
= true;
11822 if (info
->emitrelocations
)
11824 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11827 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11828 if (bfd_big_endian (info
->output_bfd
))
11829 r
[0].r_offset
+= 2;
11830 if (stub_entry
->type
.r2save
)
11831 r
[0].r_offset
+= 4;
11832 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11833 r
[0].r_addend
= targ
;
11834 if (PPC_HA (off
) != 0)
11836 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11837 r
[1].r_offset
= r
[0].r_offset
+ 4;
11838 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11839 r
[1].r_addend
= r
[0].r_addend
;
11844 obfd
= htab
->params
->stub_bfd
;
11845 if (!stub_entry
->type
.r2save
)
11847 if (PPC_HA (off
) != 0)
11849 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11851 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11854 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11858 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11860 if (r2off
== (bfd_vma
) -1)
11862 htab
->stub_error
= true;
11866 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11868 if (PPC_HA (off
) != 0)
11870 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (off
), p
);
11872 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (off
), p
);
11875 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11877 if (PPC_HA (r2off
) != 0)
11880 bfd_put_32 (obfd
, ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11882 if (PPC_LO (r2off
) != 0)
11885 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (r2off
), p
);
11889 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11891 bfd_put_32 (obfd
, BCTR
, p
);
11894 else if (stub_entry
->type
.sub
>= ppc_stub_notoc
)
11896 bool is_plt
= stub_entry
->type
.main
== ppc_stub_plt_call
;
11898 off
= (stub_entry
->stub_offset
11899 + stub_entry
->group
->stub_sec
->output_offset
11900 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11901 obfd
= htab
->params
->stub_bfd
;
11903 && stub_entry
->h
!= NULL
11904 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
11905 && htab
->params
->tls_get_addr_opt
);
11908 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
11911 if (stub_entry
->type
.r2save
)
11914 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11919 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11920 if (targ
>= (bfd_vma
) -2)
11923 plt
= htab
->elf
.splt
;
11924 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
11926 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11927 plt
= htab
->elf
.iplt
;
11929 plt
= htab
->pltlocal
;
11931 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11934 targ
= (stub_entry
->target_value
11935 + stub_entry
->target_section
->output_offset
11936 + stub_entry
->target_section
->output_section
->vma
);
11942 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
11943 p
= build_power10_offset (obfd
, p
, off
, odd
, is_plt
);
11946 if (htab
->glink_eh_frame
!= NULL
11947 && htab
->glink_eh_frame
->size
!= 0)
11949 bfd_byte
*base
, *eh
;
11950 unsigned int lr_used
, delta
;
11952 base
= (htab
->glink_eh_frame
->contents
11953 + stub_entry
->group
->eh_base
+ 17);
11954 eh
= base
+ stub_entry
->group
->eh_size
;
11955 lr_used
= stub_entry
->stub_offset
+ (p
- loc
) + 8;
11956 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11957 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11958 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11959 *eh
++ = DW_CFA_register
;
11962 *eh
++ = DW_CFA_advance_loc
+ 2;
11963 *eh
++ = DW_CFA_restore_extended
;
11965 stub_entry
->group
->eh_size
= eh
- base
;
11968 /* The notoc stubs calculate their target (either a PLT entry or
11969 the global entry point of a function) relative to the PC
11970 returned by the "bcl" two instructions past the start of the
11971 sequence emitted by build_offset. The offset is therefore 8
11972 less than calculated from the start of the sequence. */
11974 p
= build_offset (obfd
, p
, off
, is_plt
);
11977 if (stub_entry
->type
.main
== ppc_stub_long_branch
)
11981 from
= (stub_entry
->stub_offset
11982 + stub_entry
->group
->stub_sec
->output_offset
11983 + stub_entry
->group
->stub_sec
->output_section
->vma
11985 bfd_put_32 (obfd
, B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
11989 bfd_put_32 (obfd
, MTCTR_R12
, p
);
11991 bfd_put_32 (obfd
, BCTR
, p
);
11996 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
11998 if (info
->emitrelocations
)
12000 bfd_vma roff
= relp
- stub_entry
->group
->stub_sec
->contents
;
12001 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12002 num_rel
+= num_relocs_for_power10_offset (off
, odd
);
12005 num_rel
+= num_relocs_for_offset (off
);
12008 r
= get_relocs (stub_entry
->group
->stub_sec
, num_rel
);
12011 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12012 r
= emit_relocs_for_power10_offset (info
, r
, roff
, targ
, off
, odd
);
12014 r
= emit_relocs_for_offset (info
, r
, roff
, targ
, off
);
12015 if (stub_entry
->type
.main
== ppc_stub_long_branch
)
12018 roff
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
12019 r
->r_offset
= roff
;
12020 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
12021 r
->r_addend
= targ
;
12022 if (stub_entry
->h
!= NULL
12023 && !use_global_in_relocs (htab
, stub_entry
, r
, num_rel
))
12028 else if (stub_entry
->type
.main
== ppc_stub_plt_call
)
12030 if (stub_entry
->h
!= NULL
12031 && stub_entry
->h
->is_func_descriptor
12032 && stub_entry
->h
->oh
!= NULL
)
12034 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
12036 /* If the old-ABI "dot-symbol" is undefined make it weak so
12037 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
12038 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
12039 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
12040 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
12041 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
12044 /* Now build the stub. */
12045 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12046 if (targ
>= (bfd_vma
) -2)
12049 plt
= htab
->elf
.splt
;
12050 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12052 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12053 plt
= htab
->elf
.iplt
;
12055 plt
= htab
->pltlocal
;
12057 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12059 off
= (elf_gp (info
->output_bfd
)
12060 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12063 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
12065 info
->callbacks
->einfo
12066 /* xgettext:c-format */
12067 (_("%P: linkage table error against `%pT'\n"),
12068 stub_entry
->h
!= NULL
12069 ? stub_entry
->h
->elf
.root
.root
.string
12071 bfd_set_error (bfd_error_bad_value
);
12072 htab
->stub_error
= true;
12077 if (info
->emitrelocations
)
12079 r
= get_relocs (stub_entry
->group
->stub_sec
,
12080 ((PPC_HA (off
) != 0)
12082 ? 2 + (htab
->params
->plt_static_chain
12083 && PPC_HA (off
+ 16) == PPC_HA (off
))
12087 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
12088 if (bfd_big_endian (info
->output_bfd
))
12089 r
[0].r_offset
+= 2;
12090 r
[0].r_addend
= targ
;
12093 obfd
= htab
->params
->stub_bfd
;
12094 is_tga
= (stub_entry
->h
!= NULL
12095 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12096 && htab
->params
->tls_get_addr_opt
);
12099 p
= build_tls_get_addr_head (htab
, stub_entry
, p
);
12101 r
[0].r_offset
+= p
- loc
;
12103 p
= build_plt_stub (htab
, stub_entry
, p
, off
, r
);
12105 p
= build_tls_get_addr_tail (htab
, stub_entry
, p
, loc
);
12107 else if (stub_entry
->type
.main
== ppc_stub_save_res
)
12115 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
12117 if (htab
->params
->emit_stub_syms
)
12119 struct elf_link_hash_entry
*h
;
12122 const char *const stub_str
[] = { "long_branch",
12126 len1
= strlen (stub_str
[stub_entry
->type
.main
- 1]);
12127 len2
= strlen (stub_entry
->root
.string
);
12128 name
= bfd_malloc (len1
+ len2
+ 2);
12131 memcpy (name
, stub_entry
->root
.string
, 9);
12132 memcpy (name
+ 9, stub_str
[stub_entry
->type
.main
- 1], len1
);
12133 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
12134 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
12137 if (h
->root
.type
== bfd_link_hash_new
)
12139 h
->root
.type
= bfd_link_hash_defined
;
12140 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
12141 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
12142 h
->ref_regular
= 1;
12143 h
->def_regular
= 1;
12144 h
->ref_regular_nonweak
= 1;
12145 h
->forced_local
= 1;
12147 h
->root
.linker_def
= 1;
12154 /* As above, but don't actually build the stub. Just bump offset so
12155 we know stub section sizes, and select plt_branch stubs where
12156 long_branch stubs won't do. */
12159 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
12161 struct ppc_stub_hash_entry
*stub_entry
;
12162 struct bfd_link_info
*info
;
12163 struct ppc_link_hash_table
*htab
;
12165 bfd_vma targ
, off
, r2off
;
12166 unsigned int size
, extra
, lr_used
, delta
, odd
;
12168 /* Massage our args to the form they really have. */
12169 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
12172 htab
= ppc_hash_table (info
);
12176 /* Fail if the target section could not be assigned to an output
12177 section. The user should fix his linker script. */
12178 if (stub_entry
->target_section
!= NULL
12179 && stub_entry
->target_section
->output_section
== NULL
12180 && info
->non_contiguous_regions
)
12181 info
->callbacks
->einfo (_("%F%P: Could not assign %pA to an output section. "
12182 "Retry without --enable-non-contiguous-regions.\n"),
12183 stub_entry
->target_section
);
12185 /* Same for the group. */
12186 if (stub_entry
->group
->stub_sec
!= NULL
12187 && stub_entry
->group
->stub_sec
->output_section
== NULL
12188 && info
->non_contiguous_regions
)
12189 info
->callbacks
->einfo (_("%F%P: Could not assign group %pA target %pA to an "
12190 "output section. Retry without "
12191 "--enable-non-contiguous-regions.\n"),
12192 stub_entry
->group
->stub_sec
,
12193 stub_entry
->target_section
);
12195 /* Make a note of the offset within the stubs for this entry. */
12196 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12198 if (stub_entry
->h
!= NULL
12199 && stub_entry
->h
->save_res
12200 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
12201 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
12203 /* Don't make stubs to out-of-line register save/restore
12204 functions. Instead, emit copies of the functions. */
12205 stub_entry
->group
->needs_save_res
= 1;
12206 stub_entry
->type
.main
= ppc_stub_save_res
;
12207 stub_entry
->type
.sub
= ppc_stub_toc
;
12208 stub_entry
->type
.r2save
= 0;
12212 if (stub_entry
->type
.main
== ppc_stub_plt_branch
)
12214 /* Reset the stub type from the plt branch variant in case we now
12215 can reach with a shorter stub. */
12216 stub_entry
->type
.main
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
12219 if (stub_entry
->type
.main
== ppc_stub_long_branch
12220 && stub_entry
->type
.sub
== ppc_stub_toc
)
12222 targ
= (stub_entry
->target_value
12223 + stub_entry
->target_section
->output_offset
12224 + stub_entry
->target_section
->output_section
->vma
);
12225 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
12226 off
= (stub_entry
->stub_offset
12227 + stub_entry
->group
->stub_sec
->output_offset
12228 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12232 if (stub_entry
->type
.r2save
)
12234 r2off
= get_r2off (info
, stub_entry
);
12235 if (r2off
== (bfd_vma
) -1)
12237 htab
->stub_error
= true;
12241 if (PPC_HA (r2off
) != 0)
12243 if (PPC_LO (r2off
) != 0)
12249 /* If the branch offset is too big, use a ppc_stub_plt_branch.
12250 Do the same for -R objects without function descriptors. */
12251 if ((stub_entry
->type
.r2save
12253 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
12254 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12256 struct ppc_branch_hash_entry
*br_entry
;
12258 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
12259 stub_entry
->root
.string
+ 9,
12261 if (br_entry
== NULL
)
12263 _bfd_error_handler (_("can't build branch stub `%s'"),
12264 stub_entry
->root
.string
);
12265 htab
->stub_error
= true;
12269 if (br_entry
->iter
!= htab
->stub_iteration
)
12271 br_entry
->iter
= htab
->stub_iteration
;
12272 br_entry
->offset
= htab
->brlt
->size
;
12273 htab
->brlt
->size
+= 8;
12275 if (htab
->relbrlt
!= NULL
&& !info
->enable_dt_relr
)
12276 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
12277 else if (info
->emitrelocations
)
12279 htab
->brlt
->reloc_count
+= 1;
12280 htab
->brlt
->flags
|= SEC_RELOC
;
12284 targ
= (br_entry
->offset
12285 + htab
->brlt
->output_offset
12286 + htab
->brlt
->output_section
->vma
);
12287 off
= (elf_gp (info
->output_bfd
)
12288 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12291 if (info
->emitrelocations
)
12293 stub_entry
->group
->stub_sec
->reloc_count
12294 += 1 + (PPC_HA (off
) != 0);
12295 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12298 stub_entry
->type
.main
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
12299 if (!stub_entry
->type
.r2save
)
12302 if (PPC_HA (off
) != 0)
12308 if (PPC_HA (off
) != 0)
12311 if (PPC_HA (r2off
) != 0)
12313 if (PPC_LO (r2off
) != 0)
12317 else if (info
->emitrelocations
)
12319 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
12320 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12323 else if (stub_entry
->type
.main
== ppc_stub_long_branch
)
12325 off
= (stub_entry
->stub_offset
12326 + stub_entry
->group
->stub_sec
->output_offset
12327 + stub_entry
->group
->stub_sec
->output_section
->vma
);
12329 if (stub_entry
->type
.r2save
)
12332 targ
= (stub_entry
->target_value
12333 + stub_entry
->target_section
->output_offset
12334 + stub_entry
->target_section
->output_section
->vma
);
12338 if (info
->emitrelocations
)
12340 unsigned int num_rel
;
12341 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12342 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12344 num_rel
= num_relocs_for_offset (off
- 8);
12345 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12346 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12349 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12350 extra
= size_power10_offset (off
, odd
);
12352 extra
= size_offset (off
- 8);
12353 /* Include branch insn plus those in the offset sequence. */
12355 /* The branch insn is at the end, or "extra" bytes along. So
12356 its offset will be "extra" bytes less that that already
12360 if (stub_entry
->type
.sub
!= ppc_stub_notoc
)
12362 /* After the bcl, lr has been modified so we need to emit
12363 .eh_frame info saying the return address is in r12. */
12364 lr_used
= stub_entry
->stub_offset
+ 8;
12365 if (stub_entry
->type
.r2save
)
12367 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12368 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12369 DW_CFA_restore_extended 65. */
12370 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12371 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12372 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12375 /* If the branch can't reach, use a plt_branch. */
12376 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
12378 stub_entry
->type
.main
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
12381 else if (info
->emitrelocations
)
12382 stub_entry
->group
->stub_sec
->reloc_count
+=1;
12384 else if (stub_entry
->type
.sub
>= ppc_stub_notoc
)
12386 BFD_ASSERT (stub_entry
->type
.main
== ppc_stub_plt_call
);
12388 if (stub_entry
->h
!= NULL
12389 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12390 && htab
->params
->tls_get_addr_opt
)
12393 if (!htab
->params
->no_tls_get_addr_regsave
)
12395 else if (stub_entry
->type
.r2save
)
12398 if (stub_entry
->type
.r2save
)
12400 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
12401 if (targ
>= (bfd_vma
) -2)
12404 plt
= htab
->elf
.splt
;
12405 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12407 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12408 plt
= htab
->elf
.iplt
;
12410 plt
= htab
->pltlocal
;
12412 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12413 off
= (stub_entry
->stub_offset
12414 + stub_entry
->group
->stub_sec
->output_offset
12415 + stub_entry
->group
->stub_sec
->output_section
->vma
12420 if (htab
->params
->plt_stub_align
!= 0)
12422 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
, odd
);
12424 stub_entry
->group
->stub_sec
->size
+= pad
;
12425 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12430 if (info
->emitrelocations
)
12432 unsigned int num_rel
;
12433 if (stub_entry
->type
.sub
== ppc_stub_notoc
)
12434 num_rel
= num_relocs_for_power10_offset (off
, odd
);
12436 num_rel
= num_relocs_for_offset (off
- 8);
12437 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
12438 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12441 size
= plt_stub_size (htab
, stub_entry
, off
, odd
);
12443 if (stub_entry
->type
.sub
!= ppc_stub_notoc
)
12445 /* After the bcl, lr has been modified so we need to emit
12446 .eh_frame info saying the return address is in r12. */
12447 lr_used
+= stub_entry
->stub_offset
+ 8;
12448 /* The eh_frame info will consist of a DW_CFA_advance_loc or
12449 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
12450 DW_CFA_restore_extended 65. */
12451 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12452 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12453 stub_entry
->group
->lr_restore
= lr_used
+ 8;
12455 if (stub_entry
->h
!= NULL
12456 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12457 && htab
->params
->tls_get_addr_opt
)
12459 if (!htab
->params
->no_tls_get_addr_regsave
)
12461 unsigned int cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
12462 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12463 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12464 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12465 stub_entry
->group
->lr_restore
12466 = stub_entry
->stub_offset
+ size
- 4;
12468 else if (stub_entry
->type
.r2save
)
12470 lr_used
= stub_entry
->stub_offset
+ size
- 20;
12471 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12472 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12473 stub_entry
->group
->lr_restore
12474 = stub_entry
->stub_offset
+ size
- 4;
12478 else if (stub_entry
->type
.main
== ppc_stub_plt_call
)
12480 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
12481 if (targ
>= (bfd_vma
) -2)
12483 plt
= htab
->elf
.splt
;
12484 if (use_local_plt (info
, elf_hash_entry (stub_entry
->h
)))
12486 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
12487 plt
= htab
->elf
.iplt
;
12489 plt
= htab
->pltlocal
;
12491 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
12493 off
= (elf_gp (info
->output_bfd
)
12494 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
12497 if (htab
->params
->plt_stub_align
!= 0)
12499 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
, 0);
12501 stub_entry
->group
->stub_sec
->size
+= pad
;
12502 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
12505 if (info
->emitrelocations
)
12507 stub_entry
->group
->stub_sec
->reloc_count
12508 += ((PPC_HA (off
) != 0)
12510 ? 2 + (htab
->params
->plt_static_chain
12511 && PPC_HA (off
+ 16) == PPC_HA (off
))
12513 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
12516 size
= plt_stub_size (htab
, stub_entry
, off
, 0);
12518 if (stub_entry
->h
!= NULL
12519 && is_tls_get_addr (&stub_entry
->h
->elf
, htab
)
12520 && htab
->params
->tls_get_addr_opt
12521 && stub_entry
->type
.r2save
)
12523 if (!htab
->params
->no_tls_get_addr_regsave
)
12525 /* Adjustments to r1 need to be described. */
12526 unsigned int cfa_updt
= stub_entry
->stub_offset
+ 18 * 4;
12527 delta
= cfa_updt
- stub_entry
->group
->lr_restore
;
12528 stub_entry
->group
->eh_size
+= eh_advance_size (delta
);
12529 stub_entry
->group
->eh_size
+= htab
->opd_abi
? 36 : 35;
12533 lr_used
= stub_entry
->stub_offset
+ size
- 20;
12534 /* The eh_frame info will consist of a DW_CFA_advance_loc
12535 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
12536 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
12537 delta
= lr_used
- stub_entry
->group
->lr_restore
;
12538 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
12540 stub_entry
->group
->lr_restore
= stub_entry
->stub_offset
+ size
- 4;
12549 stub_entry
->group
->stub_sec
->size
+= size
;
12553 /* Set up various things so that we can make a list of input sections
12554 for each output section included in the link. Returns -1 on error,
12555 0 when no stubs will be needed, and 1 on success. */
12558 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
12562 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12567 htab
->sec_info_arr_size
= _bfd_section_id
;
12568 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
12569 htab
->sec_info
= bfd_zmalloc (amt
);
12570 if (htab
->sec_info
== NULL
)
12573 /* Set toc_off for com, und, abs and ind sections. */
12574 for (id
= 0; id
< 3; id
++)
12575 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
12580 /* Set up for first pass at multitoc partitioning. */
12583 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
12585 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12587 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
12588 htab
->toc_bfd
= NULL
;
12589 htab
->toc_first_sec
= NULL
;
12592 /* The linker repeatedly calls this function for each TOC input section
12593 and linker generated GOT section. Group input bfds such that the toc
12594 within a group is less than 64k in size. */
12597 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
12599 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12600 bfd_vma addr
, off
, limit
;
12605 if (!htab
->second_toc_pass
)
12607 /* Keep track of the first .toc or .got section for this input bfd. */
12608 bool new_bfd
= htab
->toc_bfd
!= isec
->owner
;
12612 htab
->toc_bfd
= isec
->owner
;
12613 htab
->toc_first_sec
= isec
;
12616 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
12617 off
= addr
- htab
->toc_curr
;
12618 limit
= 0x80008000;
12619 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
12621 if (off
+ isec
->size
> limit
)
12623 addr
= (htab
->toc_first_sec
->output_offset
12624 + htab
->toc_first_sec
->output_section
->vma
);
12625 htab
->toc_curr
= addr
;
12626 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
12629 /* toc_curr is the base address of this toc group. Set elf_gp
12630 for the input section to be the offset relative to the
12631 output toc base plus 0x8000. Making the input elf_gp an
12632 offset allows us to move the toc as a whole without
12633 recalculating input elf_gp. */
12634 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
12635 off
+= TOC_BASE_OFF
;
12637 /* Die if someone uses a linker script that doesn't keep input
12638 file .toc and .got together. */
12640 && elf_gp (isec
->owner
) != 0
12641 && elf_gp (isec
->owner
) != off
)
12644 elf_gp (isec
->owner
) = off
;
12648 /* During the second pass toc_first_sec points to the start of
12649 a toc group, and toc_curr is used to track the old elf_gp.
12650 We use toc_bfd to ensure we only look at each bfd once. */
12651 if (htab
->toc_bfd
== isec
->owner
)
12653 htab
->toc_bfd
= isec
->owner
;
12655 if (htab
->toc_first_sec
== NULL
12656 || htab
->toc_curr
!= elf_gp (isec
->owner
))
12658 htab
->toc_curr
= elf_gp (isec
->owner
);
12659 htab
->toc_first_sec
= isec
;
12661 addr
= (htab
->toc_first_sec
->output_offset
12662 + htab
->toc_first_sec
->output_section
->vma
);
12663 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
12664 elf_gp (isec
->owner
) = off
;
12669 /* Called via elf_link_hash_traverse to merge GOT entries for global
12673 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
12675 if (h
->root
.type
== bfd_link_hash_indirect
)
12678 merge_got_entries (&h
->got
.glist
);
12683 /* Called via elf_link_hash_traverse to allocate GOT entries for global
12687 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
12689 struct got_entry
*gent
;
12691 if (h
->root
.type
== bfd_link_hash_indirect
)
12694 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
12695 if (!gent
->is_indirect
)
12696 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
12700 /* Called on the first multitoc pass after the last call to
12701 ppc64_elf_next_toc_section. This function removes duplicate GOT
12705 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
12707 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12708 struct bfd
*ibfd
, *ibfd2
;
12709 bool done_something
;
12711 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
12713 if (!htab
->do_multi_toc
)
12716 /* Merge global sym got entries within a toc group. */
12717 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
12719 /* And tlsld_got. */
12720 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12722 struct got_entry
*ent
, *ent2
;
12724 if (!is_ppc64_elf (ibfd
))
12727 ent
= ppc64_tlsld_got (ibfd
);
12728 if (!ent
->is_indirect
12729 && ent
->got
.offset
!= (bfd_vma
) -1)
12731 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
12733 if (!is_ppc64_elf (ibfd2
))
12736 ent2
= ppc64_tlsld_got (ibfd2
);
12737 if (!ent2
->is_indirect
12738 && ent2
->got
.offset
!= (bfd_vma
) -1
12739 && elf_gp (ibfd2
) == elf_gp (ibfd
))
12741 ent2
->is_indirect
= true;
12742 ent2
->got
.ent
= ent
;
12748 /* Zap sizes of got sections. */
12749 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
12750 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
12751 htab
->got_reli_size
= 0;
12753 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12755 asection
*got
, *relgot
;
12757 if (!is_ppc64_elf (ibfd
))
12760 got
= ppc64_elf_tdata (ibfd
)->got
;
12763 got
->rawsize
= got
->size
;
12765 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
12766 relgot
->rawsize
= relgot
->size
;
12771 /* Now reallocate the got, local syms first. We don't need to
12772 allocate section contents again since we never increase size. */
12773 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12775 struct got_entry
**lgot_ents
;
12776 struct got_entry
**end_lgot_ents
;
12777 struct plt_entry
**local_plt
;
12778 struct plt_entry
**end_local_plt
;
12779 unsigned char *lgot_masks
;
12780 bfd_size_type locsymcount
;
12781 Elf_Internal_Shdr
*symtab_hdr
;
12784 if (!is_ppc64_elf (ibfd
))
12787 lgot_ents
= elf_local_got_ents (ibfd
);
12791 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12792 locsymcount
= symtab_hdr
->sh_info
;
12793 end_lgot_ents
= lgot_ents
+ locsymcount
;
12794 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12795 end_local_plt
= local_plt
+ locsymcount
;
12796 lgot_masks
= (unsigned char *) end_local_plt
;
12797 s
= ppc64_elf_tdata (ibfd
)->got
;
12798 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
12800 struct got_entry
*ent
;
12802 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
12804 unsigned int ent_size
= 8;
12805 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
12807 ent
->got
.offset
= s
->size
;
12808 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
12813 s
->size
+= ent_size
;
12814 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
12816 htab
->elf
.irelplt
->size
+= rel_size
;
12817 htab
->got_reli_size
+= rel_size
;
12819 else if (bfd_link_pic (info
)
12820 && (ent
->tls_type
== 0
12821 ? !info
->enable_dt_relr
12822 : !bfd_link_executable (info
)))
12824 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12825 srel
->size
+= rel_size
;
12831 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12833 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12835 struct got_entry
*ent
;
12837 if (!is_ppc64_elf (ibfd
))
12840 ent
= ppc64_tlsld_got (ibfd
);
12841 if (!ent
->is_indirect
12842 && ent
->got
.offset
!= (bfd_vma
) -1)
12844 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12845 ent
->got
.offset
= s
->size
;
12847 if (bfd_link_dll (info
))
12849 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12850 srel
->size
+= sizeof (Elf64_External_Rela
);
12855 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12856 if (!done_something
)
12857 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12861 if (!is_ppc64_elf (ibfd
))
12864 got
= ppc64_elf_tdata (ibfd
)->got
;
12867 done_something
= got
->rawsize
!= got
->size
;
12868 if (done_something
)
12873 if (done_something
)
12874 (*htab
->params
->layout_sections_again
) ();
12876 /* Set up for second pass over toc sections to recalculate elf_gp
12877 on input sections. */
12878 htab
->toc_bfd
= NULL
;
12879 htab
->toc_first_sec
= NULL
;
12880 htab
->second_toc_pass
= true;
12881 return done_something
;
12884 /* Called after second pass of multitoc partitioning. */
12887 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
12889 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12891 /* After the second pass, toc_curr tracks the TOC offset used
12892 for code sections below in ppc64_elf_next_input_section. */
12893 htab
->toc_curr
= TOC_BASE_OFF
;
12896 /* No toc references were found in ISEC. If the code in ISEC makes no
12897 calls, then there's no need to use toc adjusting stubs when branching
12898 into ISEC. Actually, indirect calls from ISEC are OK as they will
12899 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
12900 needed, and 2 if a cyclical call-graph was found but no other reason
12901 for a stub was detected. If called from the top level, a return of
12902 2 means the same as a return of 0. */
12905 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
12909 /* Mark this section as checked. */
12910 isec
->call_check_done
= 1;
12912 /* We know none of our code bearing sections will need toc stubs. */
12913 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
12916 if (isec
->size
== 0)
12919 if (isec
->output_section
== NULL
)
12923 if (isec
->reloc_count
!= 0)
12925 Elf_Internal_Rela
*relstart
, *rel
;
12926 Elf_Internal_Sym
*local_syms
;
12927 struct ppc_link_hash_table
*htab
;
12929 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
12930 info
->keep_memory
);
12931 if (relstart
== NULL
)
12934 /* Look for branches to outside of this section. */
12936 htab
= ppc_hash_table (info
);
12940 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
12942 enum elf_ppc64_reloc_type r_type
;
12943 unsigned long r_symndx
;
12944 struct elf_link_hash_entry
*h
;
12945 struct ppc_link_hash_entry
*eh
;
12946 Elf_Internal_Sym
*sym
;
12948 struct _opd_sec_data
*opd
;
12952 r_type
= ELF64_R_TYPE (rel
->r_info
);
12953 if (r_type
!= R_PPC64_REL24
12954 && r_type
!= R_PPC64_REL24_NOTOC
12955 && r_type
!= R_PPC64_REL24_P9NOTOC
12956 && r_type
!= R_PPC64_REL14
12957 && r_type
!= R_PPC64_REL14_BRTAKEN
12958 && r_type
!= R_PPC64_REL14_BRNTAKEN
12959 && r_type
!= R_PPC64_PLTCALL
12960 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
12963 r_symndx
= ELF64_R_SYM (rel
->r_info
);
12964 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
12971 /* Calls to dynamic lib functions go through a plt call stub
12973 eh
= ppc_elf_hash_entry (h
);
12975 && (eh
->elf
.plt
.plist
!= NULL
12977 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12983 if (sym_sec
== NULL
)
12984 /* Ignore other undefined symbols. */
12987 /* Assume branches to other sections not included in the
12988 link need stubs too, to cover -R and absolute syms. */
12989 if (sym_sec
->output_section
== NULL
)
12996 sym_value
= sym
->st_value
;
12999 if (h
->root
.type
!= bfd_link_hash_defined
13000 && h
->root
.type
!= bfd_link_hash_defweak
)
13002 sym_value
= h
->root
.u
.def
.value
;
13004 sym_value
+= rel
->r_addend
;
13006 /* If this branch reloc uses an opd sym, find the code section. */
13007 opd
= get_opd_info (sym_sec
);
13010 if (h
== NULL
&& opd
->adjust
!= NULL
)
13014 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13016 /* Assume deleted functions won't ever be called. */
13018 sym_value
+= adjust
;
13021 dest
= opd_entry_value (sym_sec
, sym_value
,
13022 &sym_sec
, NULL
, false);
13023 if (dest
== (bfd_vma
) -1)
13028 + sym_sec
->output_offset
13029 + sym_sec
->output_section
->vma
);
13031 /* Ignore branch to self. */
13032 if (sym_sec
== isec
)
13035 /* If the called function uses the toc, we need a stub. */
13036 if (sym_sec
->has_toc_reloc
13037 || sym_sec
->makes_toc_func_call
)
13043 /* Assume any branch that needs a long branch stub might in fact
13044 need a plt_branch stub. A plt_branch stub uses r2. */
13045 else if (dest
- (isec
->output_offset
13046 + isec
->output_section
->vma
13047 + rel
->r_offset
) + (1 << 25)
13048 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
13056 /* If calling back to a section in the process of being
13057 tested, we can't say for sure that no toc adjusting stubs
13058 are needed, so don't return zero. */
13059 else if (sym_sec
->call_check_in_progress
)
13062 /* Branches to another section that itself doesn't have any TOC
13063 references are OK. Recursively call ourselves to check. */
13064 else if (!sym_sec
->call_check_done
)
13068 /* Mark current section as indeterminate, so that other
13069 sections that call back to current won't be marked as
13071 isec
->call_check_in_progress
= 1;
13072 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
13073 isec
->call_check_in_progress
= 0;
13084 if (elf_symtab_hdr (isec
->owner
).contents
13085 != (unsigned char *) local_syms
)
13087 if (elf_section_data (isec
)->relocs
!= relstart
)
13092 && isec
->map_head
.s
!= NULL
13093 && (strcmp (isec
->output_section
->name
, ".init") == 0
13094 || strcmp (isec
->output_section
->name
, ".fini") == 0))
13096 if (isec
->map_head
.s
->has_toc_reloc
13097 || isec
->map_head
.s
->makes_toc_func_call
)
13099 else if (!isec
->map_head
.s
->call_check_done
)
13102 isec
->call_check_in_progress
= 1;
13103 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
13104 isec
->call_check_in_progress
= 0;
13111 isec
->makes_toc_func_call
= 1;
13116 /* The linker repeatedly calls this function for each input section,
13117 in the order that input sections are linked into output sections.
13118 Build lists of input sections to determine groupings between which
13119 we may insert linker stubs. */
13122 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
13124 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13129 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
13130 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
13132 /* This happens to make the list in reverse order,
13133 which is what we want. */
13134 htab
->sec_info
[isec
->id
].u
.list
13135 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
13136 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
13139 if (htab
->multi_toc_needed
)
13141 /* Analyse sections that aren't already flagged as needing a
13142 valid toc pointer. Exclude .fixup for the linux kernel.
13143 .fixup contains branches, but only back to the function that
13144 hit an exception. */
13145 if (!(isec
->has_toc_reloc
13146 || (isec
->flags
& SEC_CODE
) == 0
13147 || strcmp (isec
->name
, ".fixup") == 0
13148 || isec
->call_check_done
))
13150 if (toc_adjusting_stub_needed (info
, isec
) < 0)
13153 /* Make all sections use the TOC assigned for this object file.
13154 This will be wrong for pasted sections; We fix that in
13155 check_pasted_section(). */
13156 if (elf_gp (isec
->owner
) != 0)
13157 htab
->toc_curr
= elf_gp (isec
->owner
);
13160 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
13164 /* Check that all .init and .fini sections use the same toc, if they
13165 have toc relocs. */
13168 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
13170 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
13174 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13175 bfd_vma toc_off
= 0;
13178 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13179 if (i
->has_toc_reloc
)
13182 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13183 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
13188 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13189 if (i
->makes_toc_func_call
)
13191 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13195 /* Make sure the whole pasted function uses the same toc offset. */
13197 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13198 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
13204 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
13206 bool ret1
= check_pasted_section (info
, ".init");
13207 bool ret2
= check_pasted_section (info
, ".fini");
13209 return ret1
&& ret2
;
13212 /* See whether we can group stub sections together. Grouping stub
13213 sections may result in fewer stubs. More importantly, we need to
13214 put all .init* and .fini* stubs at the beginning of the .init or
13215 .fini output sections respectively, because glibc splits the
13216 _init and _fini functions into multiple parts. Putting a stub in
13217 the middle of a function is not a good idea. */
13220 group_sections (struct bfd_link_info
*info
,
13221 bfd_size_type stub_group_size
,
13222 bool stubs_always_before_branch
)
13224 struct ppc_link_hash_table
*htab
;
13226 bool suppress_size_errors
;
13228 htab
= ppc_hash_table (info
);
13232 suppress_size_errors
= false;
13233 if (stub_group_size
== 1)
13235 /* Default values. */
13236 if (stubs_always_before_branch
)
13237 stub_group_size
= 0x1e00000;
13239 stub_group_size
= 0x1c00000;
13240 suppress_size_errors
= true;
13243 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
13247 if (osec
->id
>= htab
->sec_info_arr_size
)
13250 tail
= htab
->sec_info
[osec
->id
].u
.list
;
13251 while (tail
!= NULL
)
13255 bfd_size_type total
;
13258 struct map_stub
*group
;
13259 bfd_size_type group_size
;
13262 total
= tail
->size
;
13263 group_size
= (ppc64_elf_section_data (tail
) != NULL
13264 && ppc64_elf_section_data (tail
)->has_14bit_branch
13265 ? stub_group_size
>> 10 : stub_group_size
);
13267 big_sec
= total
> group_size
;
13268 if (big_sec
&& !suppress_size_errors
)
13269 /* xgettext:c-format */
13270 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
13271 tail
->owner
, tail
);
13272 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
13274 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
13275 && ((total
+= curr
->output_offset
- prev
->output_offset
)
13276 < (ppc64_elf_section_data (prev
) != NULL
13277 && ppc64_elf_section_data (prev
)->has_14bit_branch
13278 ? (group_size
= stub_group_size
>> 10) : group_size
))
13279 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13282 /* OK, the size from the start of CURR to the end is less
13283 than group_size and thus can be handled by one stub
13284 section. (or the tail section is itself larger than
13285 group_size, in which case we may be toast.) We should
13286 really be keeping track of the total size of stubs added
13287 here, as stubs contribute to the final output section
13288 size. That's a little tricky, and this way will only
13289 break if stubs added make the total size more than 2^25,
13290 ie. for the default stub_group_size, if stubs total more
13291 than 2097152 bytes, or nearly 75000 plt call stubs. */
13292 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
13295 group
->link_sec
= curr
;
13296 group
->stub_sec
= NULL
;
13297 group
->needs_save_res
= 0;
13298 group
->lr_restore
= 0;
13299 group
->eh_size
= 0;
13300 group
->eh_base
= 0;
13301 group
->next
= htab
->group
;
13302 htab
->group
= group
;
13305 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13306 /* Set up this stub group. */
13307 htab
->sec_info
[tail
->id
].u
.group
= group
;
13309 while (tail
!= curr
&& (tail
= prev
) != NULL
);
13311 /* But wait, there's more! Input sections up to group_size
13312 bytes before the stub section can be handled by it too.
13313 Don't do this if we have a really large section after the
13314 stubs, as adding more stubs increases the chance that
13315 branches may not reach into the stub section. */
13316 if (!stubs_always_before_branch
&& !big_sec
)
13319 while (prev
!= NULL
13320 && ((total
+= tail
->output_offset
- prev
->output_offset
)
13321 < (ppc64_elf_section_data (prev
) != NULL
13322 && ppc64_elf_section_data (prev
)->has_14bit_branch
13323 ? (group_size
= stub_group_size
>> 10)
13325 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13328 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13329 htab
->sec_info
[tail
->id
].u
.group
= group
;
13338 static const unsigned char glink_eh_frame_cie
[] =
13340 0, 0, 0, 16, /* length. */
13341 0, 0, 0, 0, /* id. */
13342 1, /* CIE version. */
13343 'z', 'R', 0, /* Augmentation string. */
13344 4, /* Code alignment. */
13345 0x78, /* Data alignment. */
13347 1, /* Augmentation size. */
13348 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
13349 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
13352 /* Stripping output sections is normally done before dynamic section
13353 symbols have been allocated. This function is called later, and
13354 handles cases like htab->brlt which is mapped to its own output
13358 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
13360 if (isec
->size
== 0
13361 && isec
->output_section
->size
== 0
13362 && !(isec
->output_section
->flags
& SEC_KEEP
)
13363 && !bfd_section_removed_from_list (info
->output_bfd
,
13364 isec
->output_section
)
13365 && elf_section_data (isec
->output_section
)->dynindx
== 0)
13367 isec
->output_section
->flags
|= SEC_EXCLUDE
;
13368 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
13369 info
->output_bfd
->section_count
--;
13374 compare_relr_address (const void *arg1
, const void *arg2
)
13376 bfd_vma a
= *(bfd_vma
*) arg1
;
13377 bfd_vma b
= *(bfd_vma
*) arg2
;
13378 return a
< b
? -1 : a
> b
? 1 : 0;
13382 append_relr_off (struct ppc_link_hash_table
*htab
, bfd_vma off
)
13384 if (htab
->relr_count
>= htab
->relr_alloc
)
13386 if (htab
->relr_alloc
== 0)
13387 htab
->relr_alloc
= 4096;
13389 htab
->relr_alloc
*= 2;
13391 = bfd_realloc (htab
->relr_addr
,
13392 htab
->relr_alloc
* sizeof (htab
->relr_addr
[0]));
13393 if (htab
->relr_addr
== NULL
)
13396 htab
->relr_addr
[htab
->relr_count
++] = off
;
13401 got_and_plt_relr_for_local_syms (struct bfd_link_info
*info
)
13403 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13406 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13408 struct got_entry
**lgot_ents
, **lgot
, **end_lgot_ents
;
13409 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13410 Elf_Internal_Shdr
*symtab_hdr
;
13411 bfd_size_type locsymcount
;
13412 Elf_Internal_Sym
*local_syms
= NULL
;
13413 struct plt_entry
*pent
;
13414 struct got_entry
*gent
;
13416 if (!is_ppc64_elf (ibfd
))
13419 lgot_ents
= elf_local_got_ents (ibfd
);
13423 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13424 locsymcount
= symtab_hdr
->sh_info
;
13425 end_lgot_ents
= lgot_ents
+ locsymcount
;
13426 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13427 end_local_plt
= local_plt
+ locsymcount
;
13428 for (lgot
= lgot_ents
; lgot
< end_lgot_ents
; ++lgot
)
13429 for (gent
= *lgot
; gent
!= NULL
; gent
= gent
->next
)
13430 if (!gent
->is_indirect
13431 && gent
->tls_type
== 0
13432 && gent
->got
.offset
!= (bfd_vma
) -1)
13434 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
13435 bfd_vma r_offset
= (got
->output_section
->vma
13436 + got
->output_offset
13437 + gent
->got
.offset
);
13438 if (!append_relr_off (htab
, r_offset
))
13440 htab
->stub_error
= true;
13445 if (!htab
->opd_abi
)
13446 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
13447 for (pent
= *lplt
; pent
!= NULL
; pent
= pent
->next
)
13448 if (pent
->plt
.offset
!= (bfd_vma
) -1)
13450 Elf_Internal_Sym
*sym
;
13452 if (!get_sym_h (NULL
, &sym
, NULL
, NULL
, &local_syms
,
13453 lplt
- local_plt
, ibfd
))
13456 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13461 if (ELF_ST_TYPE (sym
->st_info
) != STT_GNU_IFUNC
)
13463 bfd_vma r_offset
= (pent
->plt
.offset
13464 + htab
->pltlocal
->output_offset
13465 + htab
->pltlocal
->output_section
->vma
);
13466 if (!append_relr_off (htab
, r_offset
))
13471 if (local_syms
!= NULL
13472 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13474 if (!info
->keep_memory
)
13477 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13484 got_and_plt_relr (struct elf_link_hash_entry
*h
, void *inf
)
13486 struct bfd_link_info
*info
;
13487 struct ppc_link_hash_table
*htab
;
13488 struct plt_entry
*pent
;
13489 struct got_entry
*gent
;
13491 if (h
->root
.type
== bfd_link_hash_indirect
)
13494 info
= (struct bfd_link_info
*) inf
;
13495 htab
= ppc_hash_table (info
);
13499 if (h
->type
!= STT_GNU_IFUNC
13501 && (h
->root
.type
== bfd_link_hash_defined
13502 || h
->root
.type
== bfd_link_hash_defweak
))
13504 if (!htab
->elf
.dynamic_sections_created
13505 || h
->dynindx
== -1
13506 || SYMBOL_REFERENCES_LOCAL (info
, h
))
13507 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
13508 if (!gent
->is_indirect
13509 && gent
->tls_type
== 0
13510 && gent
->got
.offset
!= (bfd_vma
) -1)
13512 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
13513 bfd_vma r_offset
= (got
->output_section
->vma
13514 + got
->output_offset
13515 + gent
->got
.offset
);
13516 if (!append_relr_off (htab
, r_offset
))
13518 htab
->stub_error
= true;
13524 && use_local_plt (info
, h
))
13525 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
13526 if (pent
->plt
.offset
!= (bfd_vma
) -1)
13528 bfd_vma r_offset
= (htab
->pltlocal
->output_section
->vma
13529 + htab
->pltlocal
->output_offset
13530 + pent
->plt
.offset
);
13531 if (!append_relr_off (htab
, r_offset
))
13533 htab
->stub_error
= true;
13541 /* Determine and set the size of the stub section for a final link.
13543 The basic idea here is to examine all the relocations looking for
13544 PC-relative calls to a target that is unreachable with a "bl"
13548 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
13550 bfd_size_type stub_group_size
;
13551 bool stubs_always_before_branch
;
13552 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13557 if (htab
->params
->power10_stubs
== -1 && !htab
->has_power10_relocs
)
13558 htab
->params
->power10_stubs
= 0;
13560 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
13561 htab
->params
->plt_thread_safe
= 1;
13562 if (!htab
->opd_abi
)
13563 htab
->params
->plt_thread_safe
= 0;
13564 else if (htab
->params
->plt_thread_safe
== -1)
13566 static const char *const thread_starter
[] =
13570 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
13572 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
13573 "mq_notify", "create_timer",
13578 "GOMP_parallel_start",
13579 "GOMP_parallel_loop_static",
13580 "GOMP_parallel_loop_static_start",
13581 "GOMP_parallel_loop_dynamic",
13582 "GOMP_parallel_loop_dynamic_start",
13583 "GOMP_parallel_loop_guided",
13584 "GOMP_parallel_loop_guided_start",
13585 "GOMP_parallel_loop_runtime",
13586 "GOMP_parallel_loop_runtime_start",
13587 "GOMP_parallel_sections",
13588 "GOMP_parallel_sections_start",
13594 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
13596 struct elf_link_hash_entry
*h
;
13597 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
13598 false, false, true);
13599 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
13600 if (htab
->params
->plt_thread_safe
)
13604 stubs_always_before_branch
= htab
->params
->group_size
< 0;
13605 if (htab
->params
->group_size
< 0)
13606 stub_group_size
= -htab
->params
->group_size
;
13608 stub_group_size
= htab
->params
->group_size
;
13610 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
13613 htab
->tga_group
= NULL
;
13614 if (!htab
->params
->no_tls_get_addr_regsave
13615 && htab
->tga_desc_fd
!= NULL
13616 && (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefined
13617 || htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefweak
)
13618 && htab
->tls_get_addr_fd
!= NULL
13619 && is_static_defined (&htab
->tls_get_addr_fd
->elf
))
13621 asection
*sym_sec
, *code_sec
, *stub_sec
;
13623 struct _opd_sec_data
*opd
;
13625 sym_sec
= htab
->tls_get_addr_fd
->elf
.root
.u
.def
.section
;
13626 sym_value
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
13627 code_sec
= sym_sec
;
13628 opd
= get_opd_info (sym_sec
);
13630 opd_entry_value (sym_sec
, sym_value
, &code_sec
, NULL
, false);
13631 htab
->tga_group
= htab
->sec_info
[code_sec
->id
].u
.group
;
13632 stub_sec
= (*htab
->params
->add_stub_section
) (".tga_desc.stub",
13633 htab
->tga_group
->link_sec
);
13634 if (stub_sec
== NULL
)
13636 htab
->tga_group
->stub_sec
= stub_sec
;
13638 htab
->tga_desc_fd
->elf
.root
.type
= bfd_link_hash_defined
;
13639 htab
->tga_desc_fd
->elf
.root
.u
.def
.section
= stub_sec
;
13640 htab
->tga_desc_fd
->elf
.root
.u
.def
.value
= 0;
13641 htab
->tga_desc_fd
->elf
.type
= STT_FUNC
;
13642 htab
->tga_desc_fd
->elf
.def_regular
= 1;
13643 htab
->tga_desc_fd
->elf
.non_elf
= 0;
13644 _bfd_elf_link_hash_hide_symbol (info
, &htab
->tga_desc_fd
->elf
, true);
13647 #define STUB_SHRINK_ITER 20
13648 /* Loop until no stubs added. After iteration 20 of this loop we may
13649 exit on a stub section shrinking. This is to break out of a
13650 pathological case where adding stubs on one iteration decreases
13651 section gaps (perhaps due to alignment), which then requires
13652 fewer or smaller stubs on the next iteration. */
13657 unsigned int bfd_indx
;
13658 struct map_stub
*group
;
13660 htab
->stub_iteration
+= 1;
13661 htab
->relr_count
= 0;
13663 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
13665 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
13667 Elf_Internal_Shdr
*symtab_hdr
;
13669 Elf_Internal_Sym
*local_syms
= NULL
;
13671 if (!is_ppc64_elf (input_bfd
))
13674 /* We'll need the symbol table in a second. */
13675 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13676 if (symtab_hdr
->sh_info
== 0)
13679 /* Walk over each section attached to the input bfd. */
13680 for (section
= input_bfd
->sections
;
13682 section
= section
->next
)
13684 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
13687 /* If there aren't any relocs, then there's nothing more
13689 if ((section
->flags
& SEC_RELOC
) == 0
13690 || (section
->flags
& SEC_ALLOC
) == 0
13691 || (section
->flags
& SEC_LOAD
) == 0
13692 || section
->reloc_count
== 0)
13695 if (!info
->enable_dt_relr
13696 && (section
->flags
& SEC_CODE
) == 0)
13699 /* If this section is a link-once section that will be
13700 discarded, then don't create any stubs. */
13701 if (section
->output_section
== NULL
13702 || section
->output_section
->owner
!= info
->output_bfd
)
13705 /* Get the relocs. */
13707 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
13708 info
->keep_memory
);
13709 if (internal_relocs
== NULL
)
13710 goto error_ret_free_local
;
13712 is_opd
= ppc64_elf_section_data (section
)->sec_type
== sec_opd
;
13714 /* Now examine each relocation. */
13715 irela
= internal_relocs
;
13716 irelaend
= irela
+ section
->reloc_count
;
13717 for (; irela
< irelaend
; irela
++)
13719 enum elf_ppc64_reloc_type r_type
;
13720 unsigned int r_indx
;
13721 struct ppc_stub_type stub_type
;
13722 struct ppc_stub_hash_entry
*stub_entry
;
13723 asection
*sym_sec
, *code_sec
;
13724 bfd_vma sym_value
, code_value
;
13725 bfd_vma destination
;
13726 unsigned long local_off
;
13728 struct ppc_link_hash_entry
*hash
;
13729 struct ppc_link_hash_entry
*fdh
;
13730 struct elf_link_hash_entry
*h
;
13731 Elf_Internal_Sym
*sym
;
13733 const asection
*id_sec
;
13734 struct _opd_sec_data
*opd
;
13735 struct plt_entry
*plt_ent
;
13737 r_type
= ELF64_R_TYPE (irela
->r_info
);
13738 r_indx
= ELF64_R_SYM (irela
->r_info
);
13740 if (r_type
>= R_PPC64_max
)
13742 bfd_set_error (bfd_error_bad_value
);
13743 goto error_ret_free_internal
;
13746 /* Only look for stubs on branch instructions. */
13752 case R_PPC64_REL24
:
13753 case R_PPC64_REL24_NOTOC
:
13754 case R_PPC64_REL24_P9NOTOC
:
13755 case R_PPC64_REL14
:
13756 case R_PPC64_REL14_BRTAKEN
:
13757 case R_PPC64_REL14_BRNTAKEN
:
13758 if ((section
->flags
& SEC_CODE
) != 0)
13762 case R_PPC64_ADDR64
:
13764 if (info
->enable_dt_relr
13765 && irela
->r_offset
% 2 == 0
13766 && section
->alignment_power
!= 0)
13771 /* Now determine the call target, its name, value,
13773 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
13774 r_indx
, input_bfd
))
13775 goto error_ret_free_internal
;
13777 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
13779 /* Only locally defined symbols can possibly use
13780 relative relocations. */
13782 if ((sym_sec
== NULL
13783 || sym_sec
->output_section
== NULL
)
13784 /* No symbol is OK too. */
13785 && !(sym
!= NULL
&& sym
->st_shndx
== 0)
13786 /* Hack for __ehdr_start, which is undefined
13788 && !(h
!= NULL
&& h
->root
.linker_def
))
13790 if (NO_OPD_RELOCS
&& is_opd
)
13793 && r_type
== R_PPC64_ADDR64
)
13796 ? h
->type
== STT_GNU_IFUNC
13797 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13800 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
13803 r_offset
= _bfd_elf_section_offset (info
->output_bfd
,
13807 if (r_offset
>= (bfd_vma
) -2)
13809 r_offset
+= (section
->output_section
->vma
13810 + section
->output_offset
);
13811 if (!append_relr_off (htab
, r_offset
))
13812 goto error_ret_free_internal
;
13816 hash
= ppc_elf_hash_entry (h
);
13822 sym_value
= sym
->st_value
;
13823 if (sym_sec
!= NULL
13824 && sym_sec
->output_section
!= NULL
)
13827 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
13828 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
13830 sym_value
= hash
->elf
.root
.u
.def
.value
;
13831 if (sym_sec
->output_section
!= NULL
)
13834 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
13835 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
13837 /* Recognise an old ABI func code entry sym, and
13838 use the func descriptor sym instead if it is
13840 if (hash
->elf
.root
.root
.string
[0] == '.'
13841 && hash
->oh
!= NULL
)
13843 fdh
= ppc_follow_link (hash
->oh
);
13844 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
13845 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
13847 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
13848 sym_value
= fdh
->elf
.root
.u
.def
.value
;
13849 if (sym_sec
->output_section
!= NULL
)
13858 bfd_set_error (bfd_error_bad_value
);
13859 goto error_ret_free_internal
;
13866 sym_value
+= irela
->r_addend
;
13867 destination
= (sym_value
13868 + sym_sec
->output_offset
13869 + sym_sec
->output_section
->vma
);
13870 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
13875 code_sec
= sym_sec
;
13876 code_value
= sym_value
;
13877 opd
= get_opd_info (sym_sec
);
13882 if (hash
== NULL
&& opd
->adjust
!= NULL
)
13884 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13887 code_value
+= adjust
;
13888 sym_value
+= adjust
;
13890 dest
= opd_entry_value (sym_sec
, sym_value
,
13891 &code_sec
, &code_value
, false);
13892 if (dest
!= (bfd_vma
) -1)
13894 destination
= dest
;
13897 /* Fixup old ABI sym to point at code
13899 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
13900 hash
->elf
.root
.u
.def
.section
= code_sec
;
13901 hash
->elf
.root
.u
.def
.value
= code_value
;
13906 /* Determine what (if any) linker stub is needed. */
13908 stub_type
.main
= ppc_type_of_stub (section
, irela
, &hash
,
13909 &plt_ent
, destination
,
13911 stub_type
.sub
= ppc_stub_toc
;
13912 stub_type
.r2save
= 0;
13914 if (r_type
== R_PPC64_REL24_NOTOC
13915 || r_type
== R_PPC64_REL24_P9NOTOC
)
13917 enum ppc_stub_sub_type notoc
= ppc_stub_notoc
;
13918 if (htab
->params
->power10_stubs
== 0
13919 || (r_type
== R_PPC64_REL24_P9NOTOC
13920 && htab
->params
->power10_stubs
!= 1))
13921 notoc
= ppc_stub_p9notoc
;
13922 if (stub_type
.main
== ppc_stub_plt_call
)
13923 stub_type
.sub
= notoc
;
13924 else if (stub_type
.main
== ppc_stub_long_branch
13925 || (code_sec
!= NULL
13926 && code_sec
->output_section
!= NULL
13927 && (((hash
? hash
->elf
.other
: sym
->st_other
)
13928 & STO_PPC64_LOCAL_MASK
)
13929 > 1 << STO_PPC64_LOCAL_BIT
)))
13931 stub_type
.main
= ppc_stub_long_branch
;
13932 stub_type
.sub
= notoc
;
13933 stub_type
.r2save
= 0;
13936 else if (stub_type
.main
!= ppc_stub_plt_call
)
13938 /* Check whether we need a TOC adjusting stub.
13939 Since the linker pastes together pieces from
13940 different object files when creating the
13941 _init and _fini functions, it may be that a
13942 call to what looks like a local sym is in
13943 fact a call needing a TOC adjustment. */
13944 if ((code_sec
!= NULL
13945 && code_sec
->output_section
!= NULL
13946 && (code_sec
->has_toc_reloc
13947 || code_sec
->makes_toc_func_call
)
13948 && (htab
->sec_info
[code_sec
->id
].toc_off
13949 != htab
->sec_info
[section
->id
].toc_off
))
13950 || (((hash
? hash
->elf
.other
: sym
->st_other
)
13951 & STO_PPC64_LOCAL_MASK
)
13952 == 1 << STO_PPC64_LOCAL_BIT
))
13954 stub_type
.main
= ppc_stub_long_branch
;
13955 stub_type
.sub
= ppc_stub_toc
;
13956 stub_type
.r2save
= 1;
13960 if (stub_type
.main
== ppc_stub_none
)
13963 /* __tls_get_addr calls might be eliminated. */
13964 if (stub_type
.main
!= ppc_stub_plt_call
13966 && is_tls_get_addr (&hash
->elf
, htab
)
13967 && section
->has_tls_reloc
13968 && irela
!= internal_relocs
)
13970 /* Get tls info. */
13971 unsigned char *tls_mask
;
13973 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
13974 irela
- 1, input_bfd
))
13975 goto error_ret_free_internal
;
13976 if ((*tls_mask
& TLS_TLS
) != 0
13977 && (*tls_mask
& (TLS_GD
| TLS_LD
)) == 0)
13981 if (stub_type
.main
== ppc_stub_plt_call
13982 && stub_type
.sub
== ppc_stub_toc
)
13985 && htab
->params
->plt_localentry0
!= 0
13986 && is_elfv2_localentry0 (&hash
->elf
))
13987 htab
->has_plt_localentry0
= 1;
13988 else if (irela
+ 1 < irelaend
13989 && irela
[1].r_offset
== irela
->r_offset
+ 4
13990 && (ELF64_R_TYPE (irela
[1].r_info
)
13991 == R_PPC64_TOCSAVE
))
13993 if (!tocsave_find (htab
, INSERT
,
13994 &local_syms
, irela
+ 1, input_bfd
))
13995 goto error_ret_free_internal
;
13998 stub_type
.r2save
= 1;
14001 /* Support for grouping stub sections. */
14002 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
14004 /* Get the name of this stub. */
14005 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
14007 goto error_ret_free_internal
;
14009 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
14010 stub_name
, false, false);
14011 if (stub_entry
!= NULL
)
14014 if (!ppc_merge_stub (htab
, stub_entry
, stub_type
, r_type
))
14016 /* xgettext:c-format */
14018 (_("%pB: cannot create stub entry %s"),
14019 section
->owner
, stub_entry
->root
.string
);
14020 goto error_ret_free_internal
;
14025 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
14026 if (stub_entry
== NULL
)
14029 error_ret_free_internal
:
14030 if (elf_section_data (section
)->relocs
== NULL
)
14031 free (internal_relocs
);
14032 error_ret_free_local
:
14033 if (symtab_hdr
->contents
14034 != (unsigned char *) local_syms
)
14039 stub_entry
->type
= stub_type
;
14040 if (stub_type
.main
== ppc_stub_plt_call
)
14042 stub_entry
->target_value
= sym_value
;
14043 stub_entry
->target_section
= sym_sec
;
14047 stub_entry
->target_value
= code_value
;
14048 stub_entry
->target_section
= code_sec
;
14050 stub_entry
->h
= hash
;
14051 stub_entry
->plt_ent
= plt_ent
;
14052 stub_entry
->symtype
14053 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
14054 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
14057 && (hash
->elf
.root
.type
== bfd_link_hash_defined
14058 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
14059 htab
->stub_globals
+= 1;
14062 /* We're done with the internal relocs, free them. */
14063 if (elf_section_data (section
)->relocs
!= internal_relocs
)
14064 free (internal_relocs
);
14067 if (local_syms
!= NULL
14068 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14070 if (!info
->keep_memory
)
14073 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14077 /* We may have added some stubs. Find out the new size of the
14079 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14081 group
->lr_restore
= 0;
14082 group
->eh_size
= 0;
14083 if (group
->stub_sec
!= NULL
)
14085 asection
*stub_sec
= group
->stub_sec
;
14087 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
14088 || stub_sec
->rawsize
< stub_sec
->size
)
14089 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
14090 stub_sec
->rawsize
= stub_sec
->size
;
14091 stub_sec
->size
= 0;
14092 stub_sec
->reloc_count
= 0;
14093 stub_sec
->flags
&= ~SEC_RELOC
;
14096 if (htab
->tga_group
!= NULL
)
14098 /* See emit_tga_desc and emit_tga_desc_eh_frame. */
14099 htab
->tga_group
->eh_size
14100 = 1 + 2 + (htab
->opd_abi
!= 0) + 3 + 8 * 2 + 3 + 8 + 3;
14101 htab
->tga_group
->lr_restore
= 23 * 4;
14102 htab
->tga_group
->stub_sec
->size
= 24 * 4;
14105 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
14106 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
14107 htab
->brlt
->rawsize
= htab
->brlt
->size
;
14108 htab
->brlt
->size
= 0;
14109 htab
->brlt
->reloc_count
= 0;
14110 htab
->brlt
->flags
&= ~SEC_RELOC
;
14111 if (htab
->relbrlt
!= NULL
)
14112 htab
->relbrlt
->size
= 0;
14114 if (htab
->elf
.srelrdyn
!= NULL
)
14116 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
14117 || htab
->elf
.srelrdyn
->rawsize
< htab
->elf
.srelrdyn
->size
)
14118 htab
->elf
.srelrdyn
->rawsize
= htab
->elf
.srelrdyn
->size
;
14119 htab
->elf
.srelrdyn
->size
= 0;
14122 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
14124 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14125 if (group
->needs_save_res
)
14126 group
->stub_sec
->size
+= htab
->sfpr
->size
;
14128 if (info
->emitrelocations
14129 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14131 htab
->glink
->reloc_count
= 1;
14132 htab
->glink
->flags
|= SEC_RELOC
;
14135 if (htab
->glink_eh_frame
!= NULL
14136 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
14137 && htab
->glink_eh_frame
->output_section
->size
> 8)
14139 size_t size
= 0, align
= 4;
14141 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14142 if (group
->eh_size
!= 0)
14143 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
14144 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14145 size
+= (24 + align
- 1) & -align
;
14147 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14148 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
14149 size
= (size
+ align
- 1) & -align
;
14150 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
14151 htab
->glink_eh_frame
->size
= size
;
14154 if (htab
->params
->plt_stub_align
!= 0)
14155 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14156 if (group
->stub_sec
!= NULL
)
14158 int align
= abs (htab
->params
->plt_stub_align
);
14159 group
->stub_sec
->size
14160 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
14163 if (htab
->elf
.srelrdyn
!= NULL
)
14167 for (r_offset
= 0; r_offset
< htab
->brlt
->size
; r_offset
+= 8)
14168 if (!append_relr_off (htab
, (r_offset
14169 + htab
->brlt
->output_section
->vma
14170 + htab
->brlt
->output_offset
)))
14173 if (!got_and_plt_relr_for_local_syms (info
))
14175 elf_link_hash_traverse (&htab
->elf
, got_and_plt_relr
, info
);
14176 if (htab
->stub_error
)
14179 if (htab
->relr_count
> 1)
14180 qsort (htab
->relr_addr
, htab
->relr_count
, sizeof (*htab
->relr_addr
),
14181 compare_relr_address
);
14184 while (i
< htab
->relr_count
)
14186 bfd_vma base
= htab
->relr_addr
[i
];
14187 htab
->elf
.srelrdyn
->size
+= 8;
14189 /* Handle possible duplicate address. This can happen
14190 as sections increase in size when adding stubs. */
14191 while (i
< htab
->relr_count
14192 && htab
->relr_addr
[i
] == base
)
14197 size_t start_i
= i
;
14198 while (i
< htab
->relr_count
14199 && htab
->relr_addr
[i
] - base
< 63 * 8
14200 && (htab
->relr_addr
[i
] - base
) % 8 == 0)
14204 htab
->elf
.srelrdyn
->size
+= 8;
14210 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14211 if (group
->stub_sec
!= NULL
14212 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
14213 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
14214 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
14218 && (htab
->brlt
->rawsize
== htab
->brlt
->size
14219 || (htab
->stub_iteration
> STUB_SHRINK_ITER
14220 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
14221 && (htab
->elf
.srelrdyn
== NULL
14222 || htab
->elf
.srelrdyn
->rawsize
== htab
->elf
.srelrdyn
->size
14223 || (htab
->stub_iteration
> STUB_SHRINK_ITER
14224 && htab
->elf
.srelrdyn
->rawsize
> htab
->elf
.srelrdyn
->size
))
14225 && (htab
->glink_eh_frame
== NULL
14226 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
)
14227 && (htab
->tga_group
== NULL
14228 || htab
->stub_iteration
> 1))
14231 /* Ask the linker to do its stuff. */
14232 (*htab
->params
->layout_sections_again
) ();
14235 if (htab
->glink_eh_frame
!= NULL
14236 && htab
->glink_eh_frame
->size
!= 0)
14239 bfd_byte
*p
, *last_fde
;
14240 size_t last_fde_len
, size
, align
, pad
;
14241 struct map_stub
*group
;
14243 /* It is necessary to at least have a rough outline of the
14244 linker generated CIEs and FDEs written before
14245 bfd_elf_discard_info is run, in order for these FDEs to be
14246 indexed in .eh_frame_hdr. */
14247 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
14250 htab
->glink_eh_frame
->contents
= p
;
14254 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
14255 /* CIE length (rewrite in case little-endian). */
14256 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
14257 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14258 p
+= last_fde_len
+ 4;
14260 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14261 if (group
->eh_size
!= 0)
14263 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
14265 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
14267 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14270 val
= p
- htab
->glink_eh_frame
->contents
;
14271 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
14273 /* Offset to stub section, written later. */
14275 /* stub section size. */
14276 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
14278 /* Augmentation. */
14280 /* Make sure we don't have all nops. This is enough for
14281 elf-eh-frame.c to detect the last non-nop opcode. */
14282 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
14283 p
= last_fde
+ last_fde_len
+ 4;
14285 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14288 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
14290 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14293 val
= p
- htab
->glink_eh_frame
->contents
;
14294 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
14296 /* Offset to .glink, written later. */
14299 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
14301 /* Augmentation. */
14304 *p
++ = DW_CFA_advance_loc
+ (htab
->has_plt_localentry0
? 3 : 2);
14305 *p
++ = DW_CFA_register
;
14307 *p
++ = htab
->opd_abi
? 12 : 0;
14308 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 4 : 2);
14309 *p
++ = DW_CFA_restore_extended
;
14311 p
+= ((24 + align
- 1) & -align
) - 24;
14313 /* Subsume any padding into the last FDE if user .eh_frame
14314 sections are aligned more than glink_eh_frame. Otherwise any
14315 zero padding will be seen as a terminator. */
14316 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
14317 size
= p
- htab
->glink_eh_frame
->contents
;
14318 pad
= ((size
+ align
- 1) & -align
) - size
;
14319 htab
->glink_eh_frame
->size
= size
+ pad
;
14320 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
14323 maybe_strip_output (info
, htab
->brlt
);
14324 if (htab
->relbrlt
!= NULL
)
14325 maybe_strip_output (info
, htab
->relbrlt
);
14326 if (htab
->glink_eh_frame
!= NULL
)
14327 maybe_strip_output (info
, htab
->glink_eh_frame
);
14328 if (htab
->elf
.srelrdyn
!= NULL
)
14329 maybe_strip_output (info
, htab
->elf
.srelrdyn
);
14334 /* Called after we have determined section placement. If sections
14335 move, we'll be called again. Provide a value for TOCstart. */
14338 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
14341 bfd_vma TOCstart
, adjust
;
14345 struct elf_link_hash_entry
*h
;
14346 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
14348 if (is_elf_hash_table (&htab
->root
)
14349 && htab
->hgot
!= NULL
)
14353 h
= (struct elf_link_hash_entry
*)
14354 bfd_link_hash_lookup (&htab
->root
, ".TOC.", false, false, true);
14355 if (is_elf_hash_table (&htab
->root
))
14359 && h
->root
.type
== bfd_link_hash_defined
14360 && !h
->root
.linker_def
14361 && (!is_elf_hash_table (&htab
->root
)
14362 || h
->def_regular
))
14364 TOCstart
= defined_sym_val (h
) - TOC_BASE_OFF
;
14365 _bfd_set_gp_value (obfd
, TOCstart
);
14370 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
14371 order. The TOC starts where the first of these sections starts. */
14372 s
= bfd_get_section_by_name (obfd
, ".got");
14373 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14374 s
= bfd_get_section_by_name (obfd
, ".toc");
14375 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14376 s
= bfd_get_section_by_name (obfd
, ".tocbss");
14377 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14378 s
= bfd_get_section_by_name (obfd
, ".plt");
14379 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14381 /* This may happen for
14382 o references to TOC base (SYM@toc / TOC[tc0]) without a
14384 o bad linker script
14385 o --gc-sections and empty TOC sections
14387 FIXME: Warn user? */
14389 /* Look for a likely section. We probably won't even be
14391 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14392 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
14394 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14397 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14398 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
14399 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14402 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14403 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
14407 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14408 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
14414 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
14416 /* Force alignment. */
14417 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
14418 TOCstart
-= adjust
;
14419 _bfd_set_gp_value (obfd
, TOCstart
);
14421 if (info
!= NULL
&& s
!= NULL
)
14423 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14427 if (htab
->elf
.hgot
!= NULL
)
14429 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
14430 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
14435 struct bfd_link_hash_entry
*bh
= NULL
;
14436 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
14437 s
, TOC_BASE_OFF
- adjust
,
14438 NULL
, false, false, &bh
);
14444 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
14445 write out any global entry stubs, and PLT relocations. */
14448 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
14450 struct bfd_link_info
*info
;
14451 struct ppc_link_hash_table
*htab
;
14452 struct plt_entry
*ent
;
14455 if (h
->root
.type
== bfd_link_hash_indirect
)
14459 htab
= ppc_hash_table (info
);
14463 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14464 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14466 /* This symbol has an entry in the procedure linkage
14467 table. Set it up. */
14468 Elf_Internal_Rela rela
;
14469 asection
*plt
, *relplt
;
14472 if (use_local_plt (info
, h
))
14474 if (!(h
->def_regular
14475 && (h
->root
.type
== bfd_link_hash_defined
14476 || h
->root
.type
== bfd_link_hash_defweak
)))
14478 if (h
->type
== STT_GNU_IFUNC
)
14480 plt
= htab
->elf
.iplt
;
14481 relplt
= htab
->elf
.irelplt
;
14482 htab
->elf
.ifunc_resolvers
= true;
14484 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14486 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14490 plt
= htab
->pltlocal
;
14492 if (bfd_link_pic (info
)
14493 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
14495 relplt
= htab
->relpltlocal
;
14497 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14499 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14502 rela
.r_addend
= defined_sym_val (h
) + ent
->addend
;
14504 if (relplt
== NULL
)
14506 loc
= plt
->contents
+ ent
->plt
.offset
;
14507 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
14510 bfd_vma toc
= elf_gp (info
->output_bfd
);
14511 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
14512 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14517 rela
.r_offset
= (plt
->output_section
->vma
14518 + plt
->output_offset
14519 + ent
->plt
.offset
);
14520 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14521 * sizeof (Elf64_External_Rela
));
14522 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14527 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
14528 + htab
->elf
.splt
->output_offset
14529 + ent
->plt
.offset
);
14530 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
14531 rela
.r_addend
= ent
->addend
;
14532 loc
= (htab
->elf
.srelplt
->contents
14533 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
14534 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
14535 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
14536 htab
->elf
.ifunc_resolvers
= true;
14537 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14541 if (!h
->pointer_equality_needed
)
14544 if (h
->def_regular
)
14547 s
= htab
->global_entry
;
14548 if (s
== NULL
|| s
->size
== 0)
14551 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14552 if (ent
->plt
.offset
!= (bfd_vma
) -1
14553 && ent
->addend
== 0)
14559 p
= s
->contents
+ h
->root
.u
.def
.value
;
14560 plt
= htab
->elf
.splt
;
14561 if (use_local_plt (info
, h
))
14563 if (h
->type
== STT_GNU_IFUNC
)
14564 plt
= htab
->elf
.iplt
;
14566 plt
= htab
->pltlocal
;
14568 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
14569 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
14571 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
14573 info
->callbacks
->einfo
14574 (_("%P: linkage table error against `%pT'\n"),
14575 h
->root
.root
.string
);
14576 bfd_set_error (bfd_error_bad_value
);
14577 htab
->stub_error
= true;
14580 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
14581 if (htab
->params
->emit_stub_syms
)
14583 size_t len
= strlen (h
->root
.root
.string
);
14584 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
14589 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
14590 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
14593 if (h
->root
.type
== bfd_link_hash_new
)
14595 h
->root
.type
= bfd_link_hash_defined
;
14596 h
->root
.u
.def
.section
= s
;
14597 h
->root
.u
.def
.value
= p
- s
->contents
;
14598 h
->ref_regular
= 1;
14599 h
->def_regular
= 1;
14600 h
->ref_regular_nonweak
= 1;
14601 h
->forced_local
= 1;
14603 h
->root
.linker_def
= 1;
14607 if (PPC_HA (off
) != 0)
14609 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
14612 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
14614 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
14616 bfd_put_32 (s
->owner
, BCTR
, p
);
14622 /* Write PLT relocs for locals. */
14625 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
14627 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14630 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
14632 struct got_entry
**lgot_ents
, **end_lgot_ents
;
14633 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
14634 Elf_Internal_Shdr
*symtab_hdr
;
14635 bfd_size_type locsymcount
;
14636 Elf_Internal_Sym
*local_syms
= NULL
;
14637 struct plt_entry
*ent
;
14639 if (!is_ppc64_elf (ibfd
))
14642 lgot_ents
= elf_local_got_ents (ibfd
);
14646 symtab_hdr
= &elf_symtab_hdr (ibfd
);
14647 locsymcount
= symtab_hdr
->sh_info
;
14648 end_lgot_ents
= lgot_ents
+ locsymcount
;
14649 local_plt
= (struct plt_entry
**) end_lgot_ents
;
14650 end_local_plt
= local_plt
+ locsymcount
;
14651 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
14652 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
14653 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14655 Elf_Internal_Sym
*sym
;
14657 asection
*plt
, *relplt
;
14661 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
14662 lplt
- local_plt
, ibfd
))
14664 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14669 val
= sym
->st_value
+ ent
->addend
;
14670 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
14671 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
14673 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14675 htab
->elf
.ifunc_resolvers
= true;
14676 plt
= htab
->elf
.iplt
;
14677 relplt
= htab
->elf
.irelplt
;
14681 plt
= htab
->pltlocal
;
14683 if (bfd_link_pic (info
)
14684 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
14685 relplt
= htab
->relpltlocal
;
14688 if (relplt
== NULL
)
14690 loc
= plt
->contents
+ ent
->plt
.offset
;
14691 bfd_put_64 (info
->output_bfd
, val
, loc
);
14694 bfd_vma toc
= elf_gp (ibfd
);
14695 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14700 Elf_Internal_Rela rela
;
14701 rela
.r_offset
= (ent
->plt
.offset
14702 + plt
->output_offset
14703 + plt
->output_section
->vma
);
14704 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14707 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14709 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14714 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14716 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14718 rela
.r_addend
= val
;
14719 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14720 * sizeof (Elf64_External_Rela
));
14721 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14725 if (local_syms
!= NULL
14726 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14728 if (!info
->keep_memory
)
14731 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14737 /* Emit the static wrapper function preserving registers around a
14738 __tls_get_addr_opt call. */
14741 emit_tga_desc (struct ppc_link_hash_table
*htab
)
14743 asection
*stub_sec
= htab
->tga_group
->stub_sec
;
14744 unsigned int cfa_updt
= 11 * 4;
14746 bfd_vma to
, from
, delta
;
14748 BFD_ASSERT (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_defined
14749 && htab
->tga_desc_fd
->elf
.root
.u
.def
.section
== stub_sec
14750 && htab
->tga_desc_fd
->elf
.root
.u
.def
.value
== 0);
14751 to
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
14752 from
= defined_sym_val (&htab
->tga_desc_fd
->elf
) + cfa_updt
;
14754 if (delta
+ (1 << 25) >= 1 << 26)
14756 _bfd_error_handler (_("__tls_get_addr call offset overflow"));
14757 htab
->stub_error
= true;
14761 p
= stub_sec
->contents
;
14762 p
= tls_get_addr_prologue (htab
->elf
.dynobj
, p
, htab
);
14763 bfd_put_32 (stub_sec
->owner
, B_DOT
| 1 | (delta
& 0x3fffffc), p
);
14765 p
= tls_get_addr_epilogue (htab
->elf
.dynobj
, p
, htab
);
14766 return stub_sec
->size
== (bfd_size_type
) (p
- stub_sec
->contents
);
14769 /* Emit eh_frame describing the static wrapper function. */
14772 emit_tga_desc_eh_frame (struct ppc_link_hash_table
*htab
, bfd_byte
*p
)
14774 unsigned int cfa_updt
= 11 * 4;
14777 *p
++ = DW_CFA_advance_loc
+ cfa_updt
/ 4;
14778 *p
++ = DW_CFA_def_cfa_offset
;
14786 *p
++ = DW_CFA_offset_extended_sf
;
14788 *p
++ = (-16 / 8) & 0x7f;
14789 for (i
= 4; i
< 12; i
++)
14791 *p
++ = DW_CFA_offset
+ i
;
14792 *p
++ = (htab
->opd_abi
? 13 : 12) - i
;
14794 *p
++ = DW_CFA_advance_loc
+ 10;
14795 *p
++ = DW_CFA_def_cfa_offset
;
14797 for (i
= 4; i
< 12; i
++)
14798 *p
++ = DW_CFA_restore
+ i
;
14799 *p
++ = DW_CFA_advance_loc
+ 2;
14800 *p
++ = DW_CFA_restore_extended
;
14805 /* Build all the stubs associated with the current output file.
14806 The stubs are kept in a hash table attached to the main linker
14807 hash table. This function is called via gldelf64ppc_finish. */
14810 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
14813 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14814 struct map_stub
*group
;
14815 asection
*stub_sec
;
14817 int stub_sec_count
= 0;
14822 /* Allocate memory to hold the linker stubs. */
14823 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14825 group
->eh_size
= 0;
14826 group
->lr_restore
= 0;
14827 if ((stub_sec
= group
->stub_sec
) != NULL
14828 && stub_sec
->size
!= 0)
14830 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
14832 if (stub_sec
->contents
== NULL
)
14834 stub_sec
->size
= 0;
14838 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14843 /* Build the .glink plt call stub. */
14844 if (htab
->params
->emit_stub_syms
)
14846 struct elf_link_hash_entry
*h
;
14847 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
14848 true, false, false);
14851 if (h
->root
.type
== bfd_link_hash_new
)
14853 h
->root
.type
= bfd_link_hash_defined
;
14854 h
->root
.u
.def
.section
= htab
->glink
;
14855 h
->root
.u
.def
.value
= 8;
14856 h
->ref_regular
= 1;
14857 h
->def_regular
= 1;
14858 h
->ref_regular_nonweak
= 1;
14859 h
->forced_local
= 1;
14861 h
->root
.linker_def
= 1;
14864 plt0
= (htab
->elf
.splt
->output_section
->vma
14865 + htab
->elf
.splt
->output_offset
14867 if (info
->emitrelocations
)
14869 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
14872 r
->r_offset
= (htab
->glink
->output_offset
14873 + htab
->glink
->output_section
->vma
);
14874 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
14875 r
->r_addend
= plt0
;
14877 p
= htab
->glink
->contents
;
14878 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
14879 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
14883 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
14885 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14887 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14889 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
14891 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
14893 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
14895 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14897 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
14899 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14901 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
14909 . .quad plt0-1f # plt0 entry relative to 1:
14911 # We get here with r12 initially @ a glink branch
14912 # Load the address of _dl_runtime_resolve from plt0 and
14913 # jump to it, with r0 set to the index of the PLT entry
14914 # to be resolved and r11 the link map.
14915 __glink_PLTresolve:
14916 . std %r2,24(%r1) # optional
14922 . ld %r0,(0b-1b)(%r11)
14923 . sub %r12,%r12,%r11
14924 . add %r11,%r0,%r11
14925 . addi %r0,%r12,1b-2f
14932 . b __glink_PLTresolve
14934 . b __glink_PLTresolve */
14936 if (htab
->has_plt_localentry0
)
14938 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
14941 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
14943 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14945 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14947 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
14949 if (htab
->has_plt_localentry0
)
14950 insn
= LD_R0_0R11
| (-20 & 0xfffc);
14952 insn
= LD_R0_0R11
| (-16 & 0xfffc);
14953 bfd_put_32 (htab
->glink
->owner
, insn
, p
);
14955 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
14957 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R0_R11
, p
);
14959 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-44 & 0xffff), p
);
14961 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14963 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
14965 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14967 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
14970 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
14972 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
14974 /* Build the .glink lazy link call stubs. */
14976 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
14982 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
14987 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
14989 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
14994 bfd_put_32 (htab
->glink
->owner
,
14995 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
15001 if (htab
->tga_group
!= NULL
)
15003 htab
->tga_group
->lr_restore
= 23 * 4;
15004 htab
->tga_group
->stub_sec
->size
= 24 * 4;
15005 if (!emit_tga_desc (htab
))
15007 if (htab
->glink_eh_frame
!= NULL
15008 && htab
->glink_eh_frame
->size
!= 0)
15012 p
= htab
->glink_eh_frame
->contents
;
15013 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15015 htab
->tga_group
->eh_size
= emit_tga_desc_eh_frame (htab
, p
) - p
;
15019 /* Build .glink global entry stubs, and PLT relocs for globals. */
15020 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
15022 if (!write_plt_relocs_for_local_syms (info
))
15025 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
15027 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
15029 if (htab
->brlt
->contents
== NULL
)
15032 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
15034 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
15035 htab
->relbrlt
->size
);
15036 if (htab
->relbrlt
->contents
== NULL
)
15040 /* Build the stubs as directed by the stub hash table. */
15041 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
15043 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15044 if (group
->needs_save_res
)
15045 group
->stub_sec
->size
+= htab
->sfpr
->size
;
15047 if (htab
->relbrlt
!= NULL
)
15048 htab
->relbrlt
->reloc_count
= 0;
15050 if (htab
->params
->plt_stub_align
!= 0)
15051 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15052 if ((stub_sec
= group
->stub_sec
) != NULL
)
15054 int align
= abs (htab
->params
->plt_stub_align
);
15055 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
15058 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15059 if (group
->needs_save_res
)
15061 stub_sec
= group
->stub_sec
;
15062 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
15063 htab
->sfpr
->contents
, htab
->sfpr
->size
);
15064 if (htab
->params
->emit_stub_syms
)
15068 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
15069 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
15074 if (htab
->glink_eh_frame
!= NULL
15075 && htab
->glink_eh_frame
->size
!= 0)
15080 p
= htab
->glink_eh_frame
->contents
;
15081 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15083 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15084 if (group
->eh_size
!= 0)
15086 /* Offset to stub section. */
15087 val
= (group
->stub_sec
->output_section
->vma
15088 + group
->stub_sec
->output_offset
);
15089 val
-= (htab
->glink_eh_frame
->output_section
->vma
15090 + htab
->glink_eh_frame
->output_offset
15091 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15092 if (val
+ 0x80000000 > 0xffffffff)
15095 (_("%s offset too large for .eh_frame sdata4 encoding"),
15096 group
->stub_sec
->name
);
15099 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
15100 p
+= (group
->eh_size
+ 17 + 3) & -4;
15102 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
15104 /* Offset to .glink. */
15105 val
= (htab
->glink
->output_section
->vma
15106 + htab
->glink
->output_offset
15108 val
-= (htab
->glink_eh_frame
->output_section
->vma
15109 + htab
->glink_eh_frame
->output_offset
15110 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15111 if (val
+ 0x80000000 > 0xffffffff)
15114 (_("%s offset too large for .eh_frame sdata4 encoding"),
15115 htab
->glink
->name
);
15118 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
15119 p
+= (24 + align
- 1) & -align
;
15123 if (htab
->elf
.srelrdyn
!= NULL
&& htab
->elf
.srelrdyn
->size
!= 0)
15125 htab
->elf
.srelrdyn
->contents
15126 = bfd_alloc (htab
->elf
.dynobj
, htab
->elf
.srelrdyn
->size
);
15127 if (htab
->elf
.srelrdyn
->contents
== NULL
)
15131 bfd_byte
*loc
= htab
->elf
.srelrdyn
->contents
;
15132 while (i
< htab
->relr_count
)
15134 bfd_vma base
= htab
->relr_addr
[i
];
15135 BFD_ASSERT (base
% 2 == 0);
15136 bfd_put_64 (htab
->elf
.dynobj
, base
, loc
);
15139 while (i
< htab
->relr_count
15140 && htab
->relr_addr
[i
] == base
)
15142 htab
->stub_error
= true;
15149 while (i
< htab
->relr_count
15150 && htab
->relr_addr
[i
] - base
< 63 * 8
15151 && (htab
->relr_addr
[i
] - base
) % 8 == 0)
15153 bits
|= (bfd_vma
) 1 << ((htab
->relr_addr
[i
] - base
) / 8);
15158 bfd_put_64 (htab
->elf
.dynobj
, (bits
<< 1) | 1, loc
);
15163 /* Pad any excess with 1's, a do-nothing encoding. */
15164 while ((size_t) (loc
- htab
->elf
.srelrdyn
->contents
)
15165 < htab
->elf
.srelrdyn
->size
)
15167 bfd_put_64 (htab
->elf
.dynobj
, 1, loc
);
15172 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15173 if ((stub_sec
= group
->stub_sec
) != NULL
)
15175 stub_sec_count
+= 1;
15176 if (stub_sec
->rawsize
!= stub_sec
->size
15177 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
15178 || stub_sec
->rawsize
< stub_sec
->size
))
15183 htab
->stub_error
= true;
15185 if (htab
->stub_error
)
15187 _bfd_error_handler (_("stubs don't match calculated size"));
15194 if (asprintf (&groupmsg
,
15195 ngettext ("linker stubs in %u group\n",
15196 "linker stubs in %u groups\n",
15198 stub_sec_count
) < 0)
15202 if (asprintf (stats
, _("%s"
15204 " long branch %lu\n"
15206 " global entry %lu"),
15208 htab
->stub_count
[ppc_stub_long_branch
- 1],
15209 htab
->stub_count
[ppc_stub_plt_branch
- 1],
15210 htab
->stub_count
[ppc_stub_plt_call
- 1],
15211 htab
->stub_count
[ppc_stub_global_entry
- 1]) < 0)
15219 /* What to do when ld finds relocations against symbols defined in
15220 discarded sections. */
15222 static unsigned int
15223 ppc64_elf_action_discarded (asection
*sec
)
15225 if (strcmp (".opd", sec
->name
) == 0)
15228 if (strcmp (".toc", sec
->name
) == 0)
15231 if (strcmp (".toc1", sec
->name
) == 0)
15234 return _bfd_elf_default_action_discarded (sec
);
15237 /* These are the dynamic relocations supported by glibc. */
15240 ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type
)
15244 case R_PPC64_RELATIVE
:
15246 case R_PPC64_ADDR64
:
15247 case R_PPC64_GLOB_DAT
:
15248 case R_PPC64_IRELATIVE
:
15249 case R_PPC64_JMP_IREL
:
15250 case R_PPC64_JMP_SLOT
:
15251 case R_PPC64_DTPMOD64
:
15252 case R_PPC64_DTPREL64
:
15253 case R_PPC64_TPREL64
:
15254 case R_PPC64_TPREL16_LO_DS
:
15255 case R_PPC64_TPREL16_DS
:
15256 case R_PPC64_TPREL16
:
15257 case R_PPC64_TPREL16_LO
:
15258 case R_PPC64_TPREL16_HI
:
15259 case R_PPC64_TPREL16_HIGH
:
15260 case R_PPC64_TPREL16_HA
:
15261 case R_PPC64_TPREL16_HIGHA
:
15262 case R_PPC64_TPREL16_HIGHER
:
15263 case R_PPC64_TPREL16_HIGHEST
:
15264 case R_PPC64_TPREL16_HIGHERA
:
15265 case R_PPC64_TPREL16_HIGHESTA
:
15266 case R_PPC64_ADDR16_LO_DS
:
15267 case R_PPC64_ADDR16_LO
:
15268 case R_PPC64_ADDR16_HI
:
15269 case R_PPC64_ADDR16_HIGH
:
15270 case R_PPC64_ADDR16_HA
:
15271 case R_PPC64_ADDR16_HIGHA
:
15272 case R_PPC64_REL30
:
15274 case R_PPC64_UADDR64
:
15275 case R_PPC64_UADDR32
:
15276 case R_PPC64_ADDR32
:
15277 case R_PPC64_ADDR24
:
15278 case R_PPC64_ADDR16
:
15279 case R_PPC64_UADDR16
:
15280 case R_PPC64_ADDR16_DS
:
15281 case R_PPC64_ADDR16_HIGHER
:
15282 case R_PPC64_ADDR16_HIGHEST
:
15283 case R_PPC64_ADDR16_HIGHERA
:
15284 case R_PPC64_ADDR16_HIGHESTA
:
15285 case R_PPC64_ADDR14
:
15286 case R_PPC64_ADDR14_BRTAKEN
:
15287 case R_PPC64_ADDR14_BRNTAKEN
:
15288 case R_PPC64_REL32
:
15289 case R_PPC64_REL64
:
15297 /* The RELOCATE_SECTION function is called by the ELF backend linker
15298 to handle the relocations for a section.
15300 The relocs are always passed as Rela structures; if the section
15301 actually uses Rel structures, the r_addend field will always be
15304 This function is responsible for adjust the section contents as
15305 necessary, and (if using Rela relocs and generating a
15306 relocatable output file) adjusting the reloc addend as
15309 This function does not have to worry about setting the reloc
15310 address or the reloc symbol index.
15312 LOCAL_SYMS is a pointer to the swapped in local symbols.
15314 LOCAL_SECTIONS is an array giving the section in the input file
15315 corresponding to the st_shndx field of each local symbol.
15317 The global hash table entry for the global symbols can be found
15318 via elf_sym_hashes (input_bfd).
15320 When generating relocatable output, this function must handle
15321 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
15322 going to be the section symbol corresponding to the output
15323 section, which means that the addend must be adjusted
15327 ppc64_elf_relocate_section (bfd
*output_bfd
,
15328 struct bfd_link_info
*info
,
15330 asection
*input_section
,
15331 bfd_byte
*contents
,
15332 Elf_Internal_Rela
*relocs
,
15333 Elf_Internal_Sym
*local_syms
,
15334 asection
**local_sections
)
15336 struct ppc_link_hash_table
*htab
;
15337 Elf_Internal_Shdr
*symtab_hdr
;
15338 struct elf_link_hash_entry
**sym_hashes
;
15339 Elf_Internal_Rela
*rel
;
15340 Elf_Internal_Rela
*wrel
;
15341 Elf_Internal_Rela
*relend
;
15342 Elf_Internal_Rela outrel
;
15344 struct got_entry
**local_got_ents
;
15348 /* Assume 'at' branch hints. */
15349 bool is_isa_v2
= true;
15350 bool warned_dynamic
= false;
15351 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
15353 /* Initialize howto table if needed. */
15354 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
15357 htab
= ppc_hash_table (info
);
15361 /* Don't relocate stub sections. */
15362 if (input_section
->owner
== htab
->params
->stub_bfd
)
15365 if (!is_ppc64_elf (input_bfd
))
15367 bfd_set_error (bfd_error_wrong_format
);
15371 local_got_ents
= elf_local_got_ents (input_bfd
);
15372 TOCstart
= elf_gp (output_bfd
);
15373 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
15374 sym_hashes
= elf_sym_hashes (input_bfd
);
15375 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
15377 rel
= wrel
= relocs
;
15378 relend
= relocs
+ input_section
->reloc_count
;
15379 for (; rel
< relend
; wrel
++, rel
++)
15381 enum elf_ppc64_reloc_type r_type
;
15383 bfd_reloc_status_type r
;
15384 Elf_Internal_Sym
*sym
;
15386 struct elf_link_hash_entry
*h_elf
;
15387 struct ppc_link_hash_entry
*h
;
15388 struct ppc_link_hash_entry
*fdh
;
15389 const char *sym_name
;
15390 unsigned long r_symndx
, toc_symndx
;
15391 bfd_vma toc_addend
;
15392 unsigned char tls_mask
, tls_gd
, tls_type
;
15393 unsigned char sym_type
;
15394 bfd_vma relocation
;
15395 bool unresolved_reloc
, save_unresolved_reloc
;
15397 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
15400 struct ppc_stub_hash_entry
*stub_entry
;
15401 bfd_vma max_br_offset
;
15403 Elf_Internal_Rela orig_rel
;
15404 reloc_howto_type
*howto
;
15405 struct reloc_howto_struct alt_howto
;
15412 r_type
= ELF64_R_TYPE (rel
->r_info
);
15413 r_symndx
= ELF64_R_SYM (rel
->r_info
);
15415 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
15416 symbol of the previous ADDR64 reloc. The symbol gives us the
15417 proper TOC base to use. */
15418 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
15420 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
15422 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
15428 unresolved_reloc
= false;
15431 if (r_symndx
< symtab_hdr
->sh_info
)
15433 /* It's a local symbol. */
15434 struct _opd_sec_data
*opd
;
15436 sym
= local_syms
+ r_symndx
;
15437 sec
= local_sections
[r_symndx
];
15438 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
15439 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
15440 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
15441 opd
= get_opd_info (sec
);
15442 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
15444 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
15450 /* If this is a relocation against the opd section sym
15451 and we have edited .opd, adjust the reloc addend so
15452 that ld -r and ld --emit-relocs output is correct.
15453 If it is a reloc against some other .opd symbol,
15454 then the symbol value will be adjusted later. */
15455 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
15456 rel
->r_addend
+= adjust
;
15458 relocation
+= adjust
;
15466 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
15467 r_symndx
, symtab_hdr
, sym_hashes
,
15468 h_elf
, sec
, relocation
,
15469 unresolved_reloc
, warned
, ignored
);
15470 sym_name
= h_elf
->root
.root
.string
;
15471 sym_type
= h_elf
->type
;
15473 && sec
->owner
== output_bfd
15474 && strcmp (sec
->name
, ".opd") == 0)
15476 /* This is a symbol defined in a linker script. All
15477 such are defined in output sections, even those
15478 defined by simple assignment from a symbol defined in
15479 an input section. Transfer the symbol to an
15480 appropriate input .opd section, so that a branch to
15481 this symbol will be mapped to the location specified
15482 by the opd entry. */
15483 struct bfd_link_order
*lo
;
15484 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
15485 if (lo
->type
== bfd_indirect_link_order
)
15487 asection
*isec
= lo
->u
.indirect
.section
;
15488 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
15489 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
15492 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
15493 h_elf
->root
.u
.def
.section
= isec
;
15500 h
= ppc_elf_hash_entry (h_elf
);
15502 if (sec
!= NULL
&& discarded_section (sec
))
15504 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
15505 input_bfd
, input_section
,
15506 contents
, rel
->r_offset
);
15507 wrel
->r_offset
= rel
->r_offset
;
15509 wrel
->r_addend
= 0;
15511 /* For ld -r, remove relocations in debug sections against
15512 symbols defined in discarded sections. Not done for
15513 non-debug to preserve relocs in .eh_frame which the
15514 eh_frame editing code expects to be present. */
15515 if (bfd_link_relocatable (info
)
15516 && (input_section
->flags
& SEC_DEBUGGING
))
15522 if (bfd_link_relocatable (info
))
15525 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
15527 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15528 sec
= bfd_abs_section_ptr
;
15529 unresolved_reloc
= false;
15532 /* TLS optimizations. Replace instruction sequences and relocs
15533 based on information we collected in tls_optimize. We edit
15534 RELOCS so that --emit-relocs will output something sensible
15535 for the final instruction stream. */
15540 tls_mask
= h
->tls_mask
;
15541 else if (local_got_ents
!= NULL
)
15543 struct plt_entry
**local_plt
= (struct plt_entry
**)
15544 (local_got_ents
+ symtab_hdr
->sh_info
);
15545 unsigned char *lgot_masks
= (unsigned char *)
15546 (local_plt
+ symtab_hdr
->sh_info
);
15547 tls_mask
= lgot_masks
[r_symndx
];
15549 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
15550 && (r_type
== R_PPC64_TLS
15551 || r_type
== R_PPC64_TLSGD
15552 || r_type
== R_PPC64_TLSLD
))
15554 /* Check for toc tls entries. */
15555 unsigned char *toc_tls
;
15557 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15558 &local_syms
, rel
, input_bfd
))
15562 tls_mask
= *toc_tls
;
15565 /* Check that tls relocs are used with tls syms, and non-tls
15566 relocs are used with non-tls syms. */
15567 if (r_symndx
!= STN_UNDEF
15568 && r_type
!= R_PPC64_NONE
15570 || h
->elf
.root
.type
== bfd_link_hash_defined
15571 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
15572 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
15574 if ((tls_mask
& TLS_TLS
) != 0
15575 && (r_type
== R_PPC64_TLS
15576 || r_type
== R_PPC64_TLSGD
15577 || r_type
== R_PPC64_TLSLD
))
15578 /* R_PPC64_TLS is OK against a symbol in the TOC. */
15581 info
->callbacks
->einfo
15582 (!IS_PPC64_TLS_RELOC (r_type
)
15583 /* xgettext:c-format */
15584 ? _("%H: %s used with TLS symbol `%pT'\n")
15585 /* xgettext:c-format */
15586 : _("%H: %s used with non-TLS symbol `%pT'\n"),
15587 input_bfd
, input_section
, rel
->r_offset
,
15588 ppc64_elf_howto_table
[r_type
]->name
,
15592 /* Ensure reloc mapping code below stays sane. */
15593 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
15594 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
15595 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
15596 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
15597 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
15598 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
15599 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
15600 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
15601 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
15602 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
15610 case R_PPC64_LO_DS_OPT
:
15611 if (offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15613 insn
= bfd_get_32 (input_bfd
,
15614 contents
+ rel
->r_offset
- d_offset
);
15615 if ((insn
& (0x3fu
<< 26)) != 58u << 26)
15617 insn
+= (14u << 26) - (58u << 26);
15618 bfd_put_32 (input_bfd
, insn
,
15619 contents
+ rel
->r_offset
- d_offset
);
15620 r_type
= R_PPC64_TOC16_LO
;
15621 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15625 case R_PPC64_TOC16
:
15626 case R_PPC64_TOC16_LO
:
15627 case R_PPC64_TOC16_DS
:
15628 case R_PPC64_TOC16_LO_DS
:
15630 /* Check for toc tls entries. */
15631 unsigned char *toc_tls
;
15634 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15635 &local_syms
, rel
, input_bfd
);
15641 tls_mask
= *toc_tls
;
15642 if (r_type
== R_PPC64_TOC16_DS
15643 || r_type
== R_PPC64_TOC16_LO_DS
)
15645 if ((tls_mask
& TLS_TLS
) != 0
15646 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
15651 /* If we found a GD reloc pair, then we might be
15652 doing a GD->IE transition. */
15656 if ((tls_mask
& TLS_TLS
) != 0
15657 && (tls_mask
& TLS_GD
) == 0)
15660 else if (retval
== 3)
15662 if ((tls_mask
& TLS_TLS
) != 0
15663 && (tls_mask
& TLS_LD
) == 0)
15671 case R_PPC64_GOT_TPREL16_HI
:
15672 case R_PPC64_GOT_TPREL16_HA
:
15673 if ((tls_mask
& TLS_TLS
) != 0
15674 && (tls_mask
& TLS_TPREL
) == 0
15675 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15677 rel
->r_offset
-= d_offset
;
15678 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15679 r_type
= R_PPC64_NONE
;
15680 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15684 case R_PPC64_GOT_TPREL16_DS
:
15685 case R_PPC64_GOT_TPREL16_LO_DS
:
15686 if ((tls_mask
& TLS_TLS
) != 0
15687 && (tls_mask
& TLS_TPREL
) == 0
15688 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15691 insn
= bfd_get_32 (input_bfd
,
15692 contents
+ rel
->r_offset
- d_offset
);
15694 insn
|= 0x3c0d0000; /* addis 0,13,0 */
15695 bfd_put_32 (input_bfd
, insn
,
15696 contents
+ rel
->r_offset
- d_offset
);
15697 r_type
= R_PPC64_TPREL16_HA
;
15698 if (toc_symndx
!= 0)
15700 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15701 rel
->r_addend
= toc_addend
;
15702 /* We changed the symbol. Start over in order to
15703 get h, sym, sec etc. right. */
15707 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15711 case R_PPC64_GOT_TPREL_PCREL34
:
15712 if ((tls_mask
& TLS_TLS
) != 0
15713 && (tls_mask
& TLS_TPREL
) == 0
15714 && offset_in_range (input_section
, rel
->r_offset
, 8))
15716 /* pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel */
15717 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15719 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15720 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
15721 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
15722 bfd_put_32 (input_bfd
, pinsn
>> 32,
15723 contents
+ rel
->r_offset
);
15724 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15725 contents
+ rel
->r_offset
+ 4);
15726 r_type
= R_PPC64_TPREL34
;
15727 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15732 if ((tls_mask
& TLS_TLS
) != 0
15733 && (tls_mask
& TLS_TPREL
) == 0
15734 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15736 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15737 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
15740 if ((rel
->r_offset
& 3) == 0)
15742 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15743 /* Was PPC64_TLS which sits on insn boundary, now
15744 PPC64_TPREL16_LO which is at low-order half-word. */
15745 rel
->r_offset
+= d_offset
;
15746 r_type
= R_PPC64_TPREL16_LO
;
15747 if (toc_symndx
!= 0)
15749 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15750 rel
->r_addend
= toc_addend
;
15751 /* We changed the symbol. Start over in order to
15752 get h, sym, sec etc. right. */
15756 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15758 else if ((rel
->r_offset
& 3) == 1)
15760 /* For pcrel IE to LE we already have the full
15761 offset and thus don't need an addi here. A nop
15763 if ((insn
& (0x3fu
<< 26)) == 14 << 26)
15765 /* Extract regs from addi rt,ra,si. */
15766 unsigned int rt
= (insn
>> 21) & 0x1f;
15767 unsigned int ra
= (insn
>> 16) & 0x1f;
15772 /* Build or ra,rs,rb with rb==rs, ie. mr ra,rs. */
15773 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
15774 insn
|= (31u << 26) | (444u << 1);
15777 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- 1);
15782 case R_PPC64_GOT_TLSGD16_HI
:
15783 case R_PPC64_GOT_TLSGD16_HA
:
15785 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15786 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15790 case R_PPC64_GOT_TLSLD16_HI
:
15791 case R_PPC64_GOT_TLSLD16_HA
:
15792 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15793 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15796 if ((tls_mask
& tls_gd
) != 0)
15797 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
15798 + R_PPC64_GOT_TPREL16_DS
);
15801 rel
->r_offset
-= d_offset
;
15802 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15803 r_type
= R_PPC64_NONE
;
15805 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15809 case R_PPC64_GOT_TLSGD16
:
15810 case R_PPC64_GOT_TLSGD16_LO
:
15812 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15813 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15817 case R_PPC64_GOT_TLSLD16
:
15818 case R_PPC64_GOT_TLSLD16_LO
:
15819 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15820 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15822 unsigned int insn1
, insn2
;
15825 offset
= (bfd_vma
) -1;
15826 /* If not using the newer R_PPC64_TLSGD/LD to mark
15827 __tls_get_addr calls, we must trust that the call
15828 stays with its arg setup insns, ie. that the next
15829 reloc is the __tls_get_addr call associated with
15830 the current reloc. Edit both insns. */
15831 if (input_section
->nomark_tls_get_addr
15832 && rel
+ 1 < relend
15833 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
15834 htab
->tls_get_addr_fd
,
15836 htab
->tls_get_addr
,
15838 offset
= rel
[1].r_offset
;
15839 /* We read the low GOT_TLS (or TOC16) insn because we
15840 need to keep the destination reg. It may be
15841 something other than the usual r3, and moved to r3
15842 before the call by intervening code. */
15843 insn1
= bfd_get_32 (input_bfd
,
15844 contents
+ rel
->r_offset
- d_offset
);
15845 if ((tls_mask
& tls_gd
) != 0)
15848 insn1
&= (0x1f << 21) | (0x1f << 16);
15849 insn1
|= 58u << 26; /* ld */
15850 insn2
= 0x7c636a14; /* add 3,3,13 */
15851 if (offset
!= (bfd_vma
) -1)
15852 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15853 if (r_type
== R_PPC64_TOC16
15854 || r_type
== R_PPC64_TOC16_LO
)
15855 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
15857 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 1)) & 1)
15858 + R_PPC64_GOT_TPREL16_DS
);
15859 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15864 insn1
&= 0x1f << 21;
15865 insn1
|= 0x3c0d0000; /* addis r,13,0 */
15866 insn2
= 0x38630000; /* addi 3,3,0 */
15869 /* Was an LD reloc. */
15870 r_symndx
= STN_UNDEF
;
15871 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15873 else if (toc_symndx
!= 0)
15875 r_symndx
= toc_symndx
;
15876 rel
->r_addend
= toc_addend
;
15878 r_type
= R_PPC64_TPREL16_HA
;
15879 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15880 if (offset
!= (bfd_vma
) -1)
15882 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
15883 R_PPC64_TPREL16_LO
);
15884 rel
[1].r_offset
= offset
+ d_offset
;
15885 rel
[1].r_addend
= rel
->r_addend
;
15888 bfd_put_32 (input_bfd
, insn1
,
15889 contents
+ rel
->r_offset
- d_offset
);
15890 if (offset
!= (bfd_vma
) -1
15891 && offset_in_range (input_section
, offset
, 4))
15893 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15894 if (offset_in_range (input_section
, offset
+ 4, 4))
15896 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15897 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
15898 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
15901 if ((tls_mask
& tls_gd
) == 0
15902 && (tls_gd
== 0 || toc_symndx
!= 0))
15904 /* We changed the symbol. Start over in order
15905 to get h, sym, sec etc. right. */
15911 case R_PPC64_GOT_TLSGD_PCREL34
:
15912 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15913 && offset_in_range (input_section
, rel
->r_offset
, 8))
15915 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15917 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15918 if ((tls_mask
& TLS_GDIE
) != 0)
15920 /* IE, pla -> pld */
15921 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
15922 r_type
= R_PPC64_GOT_TPREL_PCREL34
;
15926 /* LE, pla pcrel -> paddi r13 */
15927 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15928 r_type
= R_PPC64_TPREL34
;
15930 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15931 bfd_put_32 (input_bfd
, pinsn
>> 32,
15932 contents
+ rel
->r_offset
);
15933 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15934 contents
+ rel
->r_offset
+ 4);
15938 case R_PPC64_GOT_TLSLD_PCREL34
:
15939 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15940 && offset_in_range (input_section
, rel
->r_offset
, 8))
15942 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15944 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15945 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15946 bfd_put_32 (input_bfd
, pinsn
>> 32,
15947 contents
+ rel
->r_offset
);
15948 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15949 contents
+ rel
->r_offset
+ 4);
15950 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15951 r_symndx
= STN_UNDEF
;
15952 r_type
= R_PPC64_TPREL34
;
15953 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15958 case R_PPC64_TLSGD
:
15959 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15960 && rel
+ 1 < relend
15961 && offset_in_range (input_section
, rel
->r_offset
,
15962 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
15965 unsigned int insn2
;
15966 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
15968 offset
= rel
->r_offset
;
15969 if (is_plt_seq_reloc (r_type1
))
15971 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
15972 if (r_type1
== R_PPC64_PLT_PCREL34
15973 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
15974 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15975 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15979 if (r_type1
== R_PPC64_PLTCALL
)
15980 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15982 if ((tls_mask
& TLS_GDIE
) != 0)
15985 r_type
= R_PPC64_NONE
;
15986 insn2
= 0x7c636a14; /* add 3,3,13 */
15991 if (toc_symndx
!= 0)
15993 r_symndx
= toc_symndx
;
15994 rel
->r_addend
= toc_addend
;
15996 if (r_type1
== R_PPC64_REL24_NOTOC
15997 || r_type1
== R_PPC64_REL24_P9NOTOC
15998 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
16000 r_type
= R_PPC64_NONE
;
16005 rel
->r_offset
= offset
+ d_offset
;
16006 r_type
= R_PPC64_TPREL16_LO
;
16007 insn2
= 0x38630000; /* addi 3,3,0 */
16010 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16011 /* Zap the reloc on the _tls_get_addr call too. */
16012 BFD_ASSERT (offset
== rel
[1].r_offset
);
16013 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16014 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16015 if ((tls_mask
& TLS_GDIE
) == 0
16017 && r_type
!= R_PPC64_NONE
)
16022 case R_PPC64_TLSLD
:
16023 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
16024 && rel
+ 1 < relend
16025 && offset_in_range (input_section
, rel
->r_offset
,
16026 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
16029 unsigned int insn2
;
16030 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
16032 offset
= rel
->r_offset
;
16033 if (is_plt_seq_reloc (r_type1
))
16035 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
16036 if (r_type1
== R_PPC64_PLT_PCREL34
16037 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
16038 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16039 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16043 if (r_type1
== R_PPC64_PLTCALL
)
16044 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16046 if (r_type1
== R_PPC64_REL24_NOTOC
16047 || r_type1
== R_PPC64_REL24_P9NOTOC
16048 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
16050 r_type
= R_PPC64_NONE
;
16055 rel
->r_offset
= offset
+ d_offset
;
16056 r_symndx
= STN_UNDEF
;
16057 r_type
= R_PPC64_TPREL16_LO
;
16058 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16059 insn2
= 0x38630000; /* addi 3,3,0 */
16061 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16062 /* Zap the reloc on the _tls_get_addr call too. */
16063 BFD_ASSERT (offset
== rel
[1].r_offset
);
16064 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16065 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16066 if (r_type
!= R_PPC64_NONE
)
16071 case R_PPC64_DTPMOD64
:
16072 if (rel
+ 1 < relend
16073 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
16074 && rel
[1].r_offset
== rel
->r_offset
+ 8)
16076 if ((tls_mask
& TLS_GD
) == 0
16077 && offset_in_range (input_section
, rel
->r_offset
, 8))
16079 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
16080 if ((tls_mask
& TLS_GDIE
) != 0)
16081 r_type
= R_PPC64_TPREL64
;
16084 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
16085 r_type
= R_PPC64_NONE
;
16087 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16092 if ((tls_mask
& TLS_LD
) == 0
16093 && offset_in_range (input_section
, rel
->r_offset
, 8))
16095 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
16096 r_type
= R_PPC64_NONE
;
16097 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16102 case R_PPC64_TPREL64
:
16103 if ((tls_mask
& TLS_TPREL
) == 0)
16105 r_type
= R_PPC64_NONE
;
16106 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16110 case R_PPC64_ENTRY
:
16111 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16112 if (!bfd_link_pic (info
)
16113 && !info
->traditional_format
16114 && relocation
+ 0x80008000 <= 0xffffffff
16115 && offset_in_range (input_section
, rel
->r_offset
, 8))
16117 unsigned int insn1
, insn2
;
16119 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16120 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16121 if ((insn1
& ~0xfffc) == LD_R2_0R12
16122 && insn2
== ADD_R2_R2_R12
)
16124 bfd_put_32 (input_bfd
,
16125 LIS_R2
+ PPC_HA (relocation
),
16126 contents
+ rel
->r_offset
);
16127 bfd_put_32 (input_bfd
,
16128 ADDI_R2_R2
+ PPC_LO (relocation
),
16129 contents
+ rel
->r_offset
+ 4);
16134 relocation
-= (rel
->r_offset
16135 + input_section
->output_offset
16136 + input_section
->output_section
->vma
);
16137 if (relocation
+ 0x80008000 <= 0xffffffff
16138 && offset_in_range (input_section
, rel
->r_offset
, 8))
16140 unsigned int insn1
, insn2
;
16142 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16143 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16144 if ((insn1
& ~0xfffc) == LD_R2_0R12
16145 && insn2
== ADD_R2_R2_R12
)
16147 bfd_put_32 (input_bfd
,
16148 ADDIS_R2_R12
+ PPC_HA (relocation
),
16149 contents
+ rel
->r_offset
);
16150 bfd_put_32 (input_bfd
,
16151 ADDI_R2_R2
+ PPC_LO (relocation
),
16152 contents
+ rel
->r_offset
+ 4);
16158 case R_PPC64_REL16_HA
:
16159 /* If we are generating a non-PIC executable, edit
16160 . 0: addis 2,12,.TOC.-0b@ha
16161 . addi 2,2,.TOC.-0b@l
16162 used by ELFv2 global entry points to set up r2, to
16165 if .TOC. is in range. */
16166 if (!bfd_link_pic (info
)
16167 && !info
->traditional_format
16169 && rel
->r_addend
== d_offset
16170 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
16171 && rel
+ 1 < relend
16172 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
16173 && rel
[1].r_offset
== rel
->r_offset
+ 4
16174 && rel
[1].r_addend
== rel
->r_addend
+ 4
16175 && relocation
+ 0x80008000 <= 0xffffffff
16176 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 8))
16178 unsigned int insn1
, insn2
;
16179 offset
= rel
->r_offset
- d_offset
;
16180 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
16181 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16182 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
16183 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
16185 r_type
= R_PPC64_ADDR16_HA
;
16186 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16187 rel
->r_addend
-= d_offset
;
16188 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
16189 rel
[1].r_addend
-= d_offset
+ 4;
16190 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
16196 /* Handle other relocations that tweak non-addend part of insn. */
16198 max_br_offset
= 1 << 25;
16199 addend
= rel
->r_addend
;
16200 reloc_dest
= DEST_NORMAL
;
16206 case R_PPC64_TOCSAVE
:
16207 if (relocation
+ addend
== (rel
->r_offset
16208 + input_section
->output_offset
16209 + input_section
->output_section
->vma
)
16210 && tocsave_find (htab
, NO_INSERT
,
16211 &local_syms
, rel
, input_bfd
)
16212 && offset_in_range (input_section
, rel
->r_offset
, 4))
16214 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16216 || insn
== CROR_151515
|| insn
== CROR_313131
)
16217 bfd_put_32 (input_bfd
,
16218 STD_R2_0R1
+ STK_TOC (htab
),
16219 contents
+ rel
->r_offset
);
16223 /* Branch taken prediction relocations. */
16224 case R_PPC64_ADDR14_BRTAKEN
:
16225 case R_PPC64_REL14_BRTAKEN
:
16226 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
16227 /* Fall through. */
16229 /* Branch not taken prediction relocations. */
16230 case R_PPC64_ADDR14_BRNTAKEN
:
16231 case R_PPC64_REL14_BRNTAKEN
:
16232 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
16234 insn
|= bfd_get_32 (input_bfd
,
16235 contents
+ rel
->r_offset
) & ~(0x01 << 21);
16236 /* Fall through. */
16238 case R_PPC64_REL14
:
16239 max_br_offset
= 1 << 15;
16240 /* Fall through. */
16242 case R_PPC64_REL24
:
16243 case R_PPC64_REL24_NOTOC
:
16244 case R_PPC64_REL24_P9NOTOC
:
16245 case R_PPC64_PLTCALL
:
16246 case R_PPC64_PLTCALL_NOTOC
:
16247 /* Calls to functions with a different TOC, such as calls to
16248 shared objects, need to alter the TOC pointer. This is
16249 done using a linkage stub. A REL24 branching to these
16250 linkage stubs needs to be followed by a nop, as the nop
16251 will be replaced with an instruction to restore the TOC
16256 && h
->oh
->is_func_descriptor
)
16257 fdh
= ppc_follow_link (h
->oh
);
16258 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
16260 if ((r_type
== R_PPC64_PLTCALL
16261 || r_type
== R_PPC64_PLTCALL_NOTOC
)
16262 && stub_entry
!= NULL
16263 && stub_entry
->type
.main
== ppc_stub_plt_call
)
16266 if (stub_entry
!= NULL
16267 && (stub_entry
->type
.main
== ppc_stub_plt_call
16268 || stub_entry
->type
.r2save
))
16270 bool can_plt_call
= false;
16272 if (r_type
== R_PPC64_REL24_NOTOC
16273 || r_type
== R_PPC64_REL24_P9NOTOC
)
16275 /* NOTOC calls don't need to restore r2. */
16276 can_plt_call
= true;
16278 else if (stub_entry
->type
.main
== ppc_stub_plt_call
16280 && htab
->params
->plt_localentry0
!= 0
16282 && is_elfv2_localentry0 (&h
->elf
))
16284 /* The function doesn't use or change r2. */
16285 can_plt_call
= true;
16288 /* All of these stubs may modify r2, so there must be a
16289 branch and link followed by a nop. The nop is
16290 replaced by an insn to restore r2. */
16291 else if (offset_in_range (input_section
, rel
->r_offset
, 8))
16295 br
= bfd_get_32 (input_bfd
,
16296 contents
+ rel
->r_offset
);
16301 nop
= bfd_get_32 (input_bfd
,
16302 contents
+ rel
->r_offset
+ 4);
16303 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
16304 can_plt_call
= true;
16305 else if (nop
== NOP
16306 || nop
== CROR_151515
16307 || nop
== CROR_313131
)
16310 && is_tls_get_addr (&h
->elf
, htab
)
16311 && htab
->params
->tls_get_addr_opt
)
16313 /* Special stub used, leave nop alone. */
16316 bfd_put_32 (input_bfd
,
16317 LD_R2_0R1
+ STK_TOC (htab
),
16318 contents
+ rel
->r_offset
+ 4);
16319 can_plt_call
= true;
16324 if (!can_plt_call
&& h
!= NULL
)
16326 const char *name
= h
->elf
.root
.root
.string
;
16331 if (startswith (name
, "__libc_start_main")
16332 && (name
[17] == 0 || name
[17] == '@'))
16334 /* Allow crt1 branch to go via a toc adjusting
16335 stub. Other calls that never return could do
16336 the same, if we could detect such. */
16337 can_plt_call
= true;
16343 /* g++ as of 20130507 emits self-calls without a
16344 following nop. This is arguably wrong since we
16345 have conflicting information. On the one hand a
16346 global symbol and on the other a local call
16347 sequence, but don't error for this special case.
16348 It isn't possible to cheaply verify we have
16349 exactly such a call. Allow all calls to the same
16351 asection
*code_sec
= sec
;
16353 if (get_opd_info (sec
) != NULL
)
16355 bfd_vma off
= (relocation
+ addend
16356 - sec
->output_section
->vma
16357 - sec
->output_offset
);
16359 opd_entry_value (sec
, off
, &code_sec
, NULL
, false);
16361 if (code_sec
== input_section
)
16362 can_plt_call
= true;
16367 if (stub_entry
->type
.main
== ppc_stub_plt_call
)
16368 info
->callbacks
->einfo
16369 /* xgettext:c-format */
16370 (_("%H: call to `%pT' lacks nop, can't restore toc; "
16371 "(plt call stub)\n"),
16372 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
16374 info
->callbacks
->einfo
16375 /* xgettext:c-format */
16376 (_("%H: call to `%pT' lacks nop, can't restore toc; "
16377 "(toc save/adjust stub)\n"),
16378 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
16380 bfd_set_error (bfd_error_bad_value
);
16385 && stub_entry
->type
.main
== ppc_stub_plt_call
)
16386 unresolved_reloc
= false;
16389 if ((stub_entry
== NULL
16390 || stub_entry
->type
.main
== ppc_stub_long_branch
16391 || stub_entry
->type
.main
== ppc_stub_plt_branch
)
16392 && get_opd_info (sec
) != NULL
)
16394 /* The branch destination is the value of the opd entry. */
16395 bfd_vma off
= (relocation
+ addend
16396 - sec
->output_section
->vma
16397 - sec
->output_offset
);
16398 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, false);
16399 if (dest
!= (bfd_vma
) -1)
16403 reloc_dest
= DEST_OPD
;
16407 /* If the branch is out of reach we ought to have a long
16409 from
= (rel
->r_offset
16410 + input_section
->output_offset
16411 + input_section
->output_section
->vma
);
16413 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
16417 if (stub_entry
!= NULL
16418 && (stub_entry
->type
.main
== ppc_stub_long_branch
16419 || stub_entry
->type
.main
== ppc_stub_plt_branch
))
16421 if (stub_entry
->type
.sub
== ppc_stub_toc
16422 && !stub_entry
->type
.r2save
16423 && (r_type
== R_PPC64_ADDR14_BRTAKEN
16424 || r_type
== R_PPC64_ADDR14_BRNTAKEN
16425 || (relocation
+ addend
- from
+ max_br_offset
16426 < 2 * max_br_offset
)))
16427 /* Don't use the stub if this branch is in range. */
16430 if (stub_entry
!= NULL
16431 && stub_entry
->type
.sub
>= ppc_stub_notoc
16432 && ((r_type
!= R_PPC64_REL24_NOTOC
16433 && r_type
!= R_PPC64_REL24_P9NOTOC
)
16434 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
16435 & STO_PPC64_LOCAL_MASK
) <= 1 << STO_PPC64_LOCAL_BIT
)
16436 && (relocation
+ addend
- from
+ max_br_offset
16437 < 2 * max_br_offset
))
16440 if (stub_entry
!= NULL
16441 && stub_entry
->type
.r2save
16442 && (r_type
== R_PPC64_REL24_NOTOC
16443 || r_type
== R_PPC64_REL24_P9NOTOC
)
16444 && (relocation
+ addend
- from
+ max_br_offset
16445 < 2 * max_br_offset
))
16449 if (stub_entry
!= NULL
)
16451 /* Munge up the value and addend so that we call the stub
16452 rather than the procedure directly. */
16453 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
16455 if (stub_entry
->type
.main
== ppc_stub_save_res
)
16456 relocation
+= (stub_sec
->output_offset
16457 + stub_sec
->output_section
->vma
16458 + stub_sec
->size
- htab
->sfpr
->size
16459 - htab
->sfpr
->output_offset
16460 - htab
->sfpr
->output_section
->vma
);
16462 relocation
= (stub_entry
->stub_offset
16463 + stub_sec
->output_offset
16464 + stub_sec
->output_section
->vma
);
16466 reloc_dest
= DEST_STUB
;
16468 if (((stub_entry
->type
.r2save
16469 && (r_type
== R_PPC64_REL24_NOTOC
16470 || r_type
== R_PPC64_REL24_P9NOTOC
))
16471 || ((stub_entry
->type
.main
== ppc_stub_plt_call
16472 && (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
))
16473 && rel
+ 1 < relend
16474 && rel
[1].r_offset
== rel
->r_offset
+ 4
16475 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
))
16476 && !(stub_entry
->type
.main
== ppc_stub_plt_call
16477 && htab
->params
->tls_get_addr_opt
16479 && is_tls_get_addr (&h
->elf
, htab
)))
16481 /* Skip over the r2 store at the start of the stub. */
16485 if ((r_type
== R_PPC64_REL24_NOTOC
16486 || r_type
== R_PPC64_REL24_P9NOTOC
)
16487 && stub_entry
->type
.main
== ppc_stub_plt_call
16488 && stub_entry
->type
.sub
>= ppc_stub_notoc
)
16489 htab
->notoc_plt
= 1;
16496 /* Set 'a' bit. This is 0b00010 in BO field for branch
16497 on CR(BI) insns (BO == 001at or 011at), and 0b01000
16498 for branch on CTR insns (BO == 1a00t or 1a01t). */
16499 if ((insn
& (0x14 << 21)) == (0x04 << 21))
16500 insn
|= 0x02 << 21;
16501 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
16502 insn
|= 0x08 << 21;
16508 /* Invert 'y' bit if not the default. */
16509 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
16510 insn
^= 0x01 << 21;
16513 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
16516 /* NOP out calls to undefined weak functions.
16517 We can thus call a weak function without first
16518 checking whether the function is defined. */
16520 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16521 && h
->elf
.dynindx
== -1
16522 && (r_type
== R_PPC64_REL24
16523 || r_type
== R_PPC64_REL24_NOTOC
16524 || r_type
== R_PPC64_REL24_P9NOTOC
)
16527 && offset_in_range (input_section
, rel
->r_offset
, 4))
16529 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
16534 case R_PPC64_GOT16_DS
:
16535 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16536 || !htab
->do_toc_opt
)
16538 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16539 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
16541 && sec
->output_section
!= NULL
16542 && !discarded_section (sec
)
16543 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16544 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16546 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16547 if ((insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16549 insn
+= (14u << 26) - (58u << 26);
16550 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16551 r_type
= R_PPC64_TOC16
;
16552 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16557 case R_PPC64_GOT16_LO_DS
:
16558 case R_PPC64_GOT16_HA
:
16559 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16560 || !htab
->do_toc_opt
)
16562 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16563 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
16565 && sec
->output_section
!= NULL
16566 && !discarded_section (sec
)
16567 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16568 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16570 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16571 if (r_type
== R_PPC64_GOT16_LO_DS
16572 && (insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16574 insn
+= (14u << 26) - (58u << 26);
16575 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16576 r_type
= R_PPC64_TOC16_LO
;
16577 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16579 else if (r_type
== R_PPC64_GOT16_HA
16580 && (insn
& (0x3fu
<< 26)) == 15u << 26 /* addis */)
16582 r_type
= R_PPC64_TOC16_HA
;
16583 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16588 case R_PPC64_GOT_PCREL34
:
16589 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16590 || !htab
->do_toc_opt
)
16592 from
= (rel
->r_offset
16593 + input_section
->output_section
->vma
16594 + input_section
->output_offset
);
16595 if (!(relocation
- from
+ (1ULL << 33) < 1ULL << 34
16597 && sec
->output_section
!= NULL
16598 && !discarded_section (sec
)
16599 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16600 && offset_in_range (input_section
, rel
->r_offset
, 8)))
16603 offset
= rel
->r_offset
;
16604 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16606 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16607 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16608 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
16611 /* Replace with paddi. */
16612 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
16613 r_type
= R_PPC64_PCREL34
;
16614 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16615 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ offset
);
16616 bfd_put_32 (input_bfd
, pinsn
, contents
+ offset
+ 4);
16617 /* Fall through. */
16619 case R_PPC64_PCREL34
:
16620 if (!htab
->params
->no_pcrel_opt
16621 && rel
+ 1 < relend
16622 && rel
[1].r_offset
== rel
->r_offset
16623 && rel
[1].r_info
== ELF64_R_INFO (0, R_PPC64_PCREL_OPT
)
16624 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16625 && offset_in_range (input_section
, rel
->r_offset
, 8))
16627 offset
= rel
->r_offset
;
16628 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16630 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16631 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16632 == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
16633 | (14ULL << 26) /* paddi */))
16635 bfd_vma off2
= rel
[1].r_addend
;
16637 /* zero means next insn. */
16640 if (offset_in_range (input_section
, off2
, 4))
16643 bfd_signed_vma addend_off
;
16644 pinsn2
= bfd_get_32 (input_bfd
, contents
+ off2
);
16646 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16648 if (!offset_in_range (input_section
, off2
, 8))
16650 pinsn2
|= bfd_get_32 (input_bfd
,
16651 contents
+ off2
+ 4);
16653 if (xlate_pcrel_opt (&pinsn
, &pinsn2
, &addend_off
))
16655 addend
+= addend_off
;
16656 rel
->r_addend
= addend
;
16657 bfd_put_32 (input_bfd
, pinsn
>> 32,
16658 contents
+ offset
);
16659 bfd_put_32 (input_bfd
, pinsn
,
16660 contents
+ offset
+ 4);
16661 bfd_put_32 (input_bfd
, pinsn2
>> 32,
16663 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16664 bfd_put_32 (input_bfd
, pinsn2
,
16665 contents
+ off2
+ 4);
16674 save_unresolved_reloc
= unresolved_reloc
;
16678 /* xgettext:c-format */
16679 _bfd_error_handler (_("%pB: %s unsupported"),
16680 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
16682 bfd_set_error (bfd_error_bad_value
);
16688 case R_PPC64_TLSGD
:
16689 case R_PPC64_TLSLD
:
16690 case R_PPC64_TOCSAVE
:
16691 case R_PPC64_GNU_VTINHERIT
:
16692 case R_PPC64_GNU_VTENTRY
:
16693 case R_PPC64_ENTRY
:
16694 case R_PPC64_PCREL_OPT
:
16697 /* GOT16 relocations. Like an ADDR16 using the symbol's
16698 address in the GOT as relocation value instead of the
16699 symbol's value itself. Also, create a GOT entry for the
16700 symbol and put the symbol value there. */
16701 case R_PPC64_GOT_TLSGD16
:
16702 case R_PPC64_GOT_TLSGD16_LO
:
16703 case R_PPC64_GOT_TLSGD16_HI
:
16704 case R_PPC64_GOT_TLSGD16_HA
:
16705 case R_PPC64_GOT_TLSGD_PCREL34
:
16706 tls_type
= TLS_TLS
| TLS_GD
;
16709 case R_PPC64_GOT_TLSLD16
:
16710 case R_PPC64_GOT_TLSLD16_LO
:
16711 case R_PPC64_GOT_TLSLD16_HI
:
16712 case R_PPC64_GOT_TLSLD16_HA
:
16713 case R_PPC64_GOT_TLSLD_PCREL34
:
16714 tls_type
= TLS_TLS
| TLS_LD
;
16717 case R_PPC64_GOT_TPREL16_DS
:
16718 case R_PPC64_GOT_TPREL16_LO_DS
:
16719 case R_PPC64_GOT_TPREL16_HI
:
16720 case R_PPC64_GOT_TPREL16_HA
:
16721 case R_PPC64_GOT_TPREL_PCREL34
:
16722 tls_type
= TLS_TLS
| TLS_TPREL
;
16725 case R_PPC64_GOT_DTPREL16_DS
:
16726 case R_PPC64_GOT_DTPREL16_LO_DS
:
16727 case R_PPC64_GOT_DTPREL16_HI
:
16728 case R_PPC64_GOT_DTPREL16_HA
:
16729 case R_PPC64_GOT_DTPREL_PCREL34
:
16730 tls_type
= TLS_TLS
| TLS_DTPREL
;
16733 case R_PPC64_GOT16
:
16734 case R_PPC64_GOT16_LO
:
16735 case R_PPC64_GOT16_HI
:
16736 case R_PPC64_GOT16_HA
:
16737 case R_PPC64_GOT16_DS
:
16738 case R_PPC64_GOT16_LO_DS
:
16739 case R_PPC64_GOT_PCREL34
:
16742 /* Relocation is to the entry for this symbol in the global
16747 unsigned long indx
= 0;
16748 struct got_entry
*ent
;
16750 if (tls_type
== (TLS_TLS
| TLS_LD
)
16751 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16752 ent
= ppc64_tlsld_got (input_bfd
);
16757 if (!htab
->elf
.dynamic_sections_created
16758 || h
->elf
.dynindx
== -1
16759 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16760 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16761 /* This is actually a static link, or it is a
16762 -Bsymbolic link and the symbol is defined
16763 locally, or the symbol was forced to be local
16764 because of a version file. */
16768 indx
= h
->elf
.dynindx
;
16769 unresolved_reloc
= false;
16771 ent
= h
->elf
.got
.glist
;
16775 if (local_got_ents
== NULL
)
16777 ent
= local_got_ents
[r_symndx
];
16780 for (; ent
!= NULL
; ent
= ent
->next
)
16781 if (ent
->addend
== orig_rel
.r_addend
16782 && ent
->owner
== input_bfd
16783 && ent
->tls_type
== tls_type
)
16789 if (ent
->is_indirect
)
16790 ent
= ent
->got
.ent
;
16791 offp
= &ent
->got
.offset
;
16792 got
= ppc64_elf_tdata (ent
->owner
)->got
;
16796 /* The offset must always be a multiple of 8. We use the
16797 least significant bit to record whether we have already
16798 processed this entry. */
16800 if ((off
& 1) != 0)
16804 /* Generate relocs for the dynamic linker, except in
16805 the case of TLSLD where we'll use one entry per
16813 ? h
->elf
.type
== STT_GNU_IFUNC
16814 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
16817 relgot
= htab
->elf
.irelplt
;
16818 if (indx
== 0 || is_static_defined (&h
->elf
))
16819 htab
->elf
.ifunc_resolvers
= true;
16822 || (bfd_link_pic (info
)
16824 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16826 && bfd_link_executable (info
)
16828 || SYMBOL_REFERENCES_LOCAL (info
,
16830 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
16831 if (relgot
!= NULL
)
16833 outrel
.r_offset
= (got
->output_section
->vma
16834 + got
->output_offset
16836 outrel
.r_addend
= orig_rel
.r_addend
;
16837 if (tls_type
& (TLS_LD
| TLS_GD
))
16839 outrel
.r_addend
= 0;
16840 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
16841 if (tls_type
== (TLS_TLS
| TLS_GD
))
16843 loc
= relgot
->contents
;
16844 loc
+= (relgot
->reloc_count
++
16845 * sizeof (Elf64_External_Rela
));
16846 bfd_elf64_swap_reloca_out (output_bfd
,
16848 outrel
.r_offset
+= 8;
16849 outrel
.r_addend
= orig_rel
.r_addend
;
16851 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16854 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
16855 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16856 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
16857 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
16858 else if (indx
!= 0)
16859 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
16863 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16865 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16867 /* Write the .got section contents for the sake
16869 loc
= got
->contents
+ off
;
16870 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
16874 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
16876 outrel
.r_addend
+= relocation
;
16877 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
16879 if (htab
->elf
.tls_sec
== NULL
)
16880 outrel
.r_addend
= 0;
16882 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
16885 if (!(info
->enable_dt_relr
16886 && ELF64_R_TYPE (outrel
.r_info
) == R_PPC64_RELATIVE
))
16888 loc
= relgot
->contents
;
16889 loc
+= (relgot
->reloc_count
++
16890 * sizeof (Elf64_External_Rela
));
16891 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16895 /* Init the .got section contents here if we're not
16896 emitting a reloc. */
16899 relocation
+= orig_rel
.r_addend
;
16902 if (htab
->elf
.tls_sec
== NULL
)
16906 if (tls_type
& TLS_LD
)
16909 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16910 if (tls_type
& TLS_TPREL
)
16911 relocation
+= DTP_OFFSET
- TP_OFFSET
;
16914 if (tls_type
& (TLS_GD
| TLS_LD
))
16916 bfd_put_64 (output_bfd
, relocation
,
16917 got
->contents
+ off
+ 8);
16921 bfd_put_64 (output_bfd
, relocation
,
16922 got
->contents
+ off
);
16926 if (off
>= (bfd_vma
) -2)
16929 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
16931 if (!(r_type
== R_PPC64_GOT_PCREL34
16932 || r_type
== R_PPC64_GOT_TLSGD_PCREL34
16933 || r_type
== R_PPC64_GOT_TLSLD_PCREL34
16934 || r_type
== R_PPC64_GOT_TPREL_PCREL34
16935 || r_type
== R_PPC64_GOT_DTPREL_PCREL34
))
16936 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
16940 case R_PPC64_PLT16_HA
:
16941 case R_PPC64_PLT16_HI
:
16942 case R_PPC64_PLT16_LO
:
16943 case R_PPC64_PLT16_LO_DS
:
16944 case R_PPC64_PLT_PCREL34
:
16945 case R_PPC64_PLT_PCREL34_NOTOC
:
16946 case R_PPC64_PLT32
:
16947 case R_PPC64_PLT64
:
16948 case R_PPC64_PLTSEQ
:
16949 case R_PPC64_PLTSEQ_NOTOC
:
16950 case R_PPC64_PLTCALL
:
16951 case R_PPC64_PLTCALL_NOTOC
:
16952 /* Relocation is to the entry for this symbol in the
16953 procedure linkage table. */
16954 unresolved_reloc
= true;
16956 struct plt_entry
**plt_list
= NULL
;
16958 plt_list
= &h
->elf
.plt
.plist
;
16959 else if (local_got_ents
!= NULL
)
16961 struct plt_entry
**local_plt
= (struct plt_entry
**)
16962 (local_got_ents
+ symtab_hdr
->sh_info
);
16963 plt_list
= local_plt
+ r_symndx
;
16967 struct plt_entry
*ent
;
16969 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
16970 if (ent
->plt
.offset
!= (bfd_vma
) -1
16971 && ent
->addend
== orig_rel
.r_addend
)
16976 plt
= htab
->elf
.splt
;
16977 if (use_local_plt (info
, elf_hash_entry (h
)))
16980 ? h
->elf
.type
== STT_GNU_IFUNC
16981 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16982 plt
= htab
->elf
.iplt
;
16984 plt
= htab
->pltlocal
;
16986 relocation
= (plt
->output_section
->vma
16987 + plt
->output_offset
16988 + ent
->plt
.offset
);
16989 if (r_type
== R_PPC64_PLT16_HA
16990 || r_type
== R_PPC64_PLT16_HI
16991 || r_type
== R_PPC64_PLT16_LO
16992 || r_type
== R_PPC64_PLT16_LO_DS
)
16994 got
= (elf_gp (output_bfd
)
16995 + htab
->sec_info
[input_section
->id
].toc_off
);
16999 unresolved_reloc
= false;
17007 /* Relocation value is TOC base. */
17008 relocation
= TOCstart
;
17009 if (r_symndx
== STN_UNDEF
)
17010 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
17011 else if (unresolved_reloc
)
17013 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
17014 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
17016 unresolved_reloc
= true;
17019 /* TOC16 relocs. We want the offset relative to the TOC base,
17020 which is the address of the start of the TOC plus 0x8000.
17021 The TOC consists of sections .got, .toc, .tocbss, and .plt,
17023 case R_PPC64_TOC16
:
17024 case R_PPC64_TOC16_LO
:
17025 case R_PPC64_TOC16_HI
:
17026 case R_PPC64_TOC16_DS
:
17027 case R_PPC64_TOC16_LO_DS
:
17028 case R_PPC64_TOC16_HA
:
17029 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
17034 /* Relocate against the beginning of the section. */
17035 case R_PPC64_SECTOFF
:
17036 case R_PPC64_SECTOFF_LO
:
17037 case R_PPC64_SECTOFF_HI
:
17038 case R_PPC64_SECTOFF_DS
:
17039 case R_PPC64_SECTOFF_LO_DS
:
17040 case R_PPC64_SECTOFF_HA
:
17042 addend
-= sec
->output_section
->vma
;
17045 case R_PPC64_REL16
:
17046 case R_PPC64_REL16_LO
:
17047 case R_PPC64_REL16_HI
:
17048 case R_PPC64_REL16_HA
:
17049 case R_PPC64_REL16_HIGH
:
17050 case R_PPC64_REL16_HIGHA
:
17051 case R_PPC64_REL16_HIGHER
:
17052 case R_PPC64_REL16_HIGHERA
:
17053 case R_PPC64_REL16_HIGHEST
:
17054 case R_PPC64_REL16_HIGHESTA
:
17055 case R_PPC64_REL16_HIGHER34
:
17056 case R_PPC64_REL16_HIGHERA34
:
17057 case R_PPC64_REL16_HIGHEST34
:
17058 case R_PPC64_REL16_HIGHESTA34
:
17059 case R_PPC64_REL16DX_HA
:
17060 case R_PPC64_REL14
:
17061 case R_PPC64_REL14_BRNTAKEN
:
17062 case R_PPC64_REL14_BRTAKEN
:
17063 case R_PPC64_REL24
:
17064 case R_PPC64_REL24_NOTOC
:
17065 case R_PPC64_REL24_P9NOTOC
:
17066 case R_PPC64_PCREL34
:
17067 case R_PPC64_PCREL28
:
17070 case R_PPC64_TPREL16
:
17071 case R_PPC64_TPREL16_LO
:
17072 case R_PPC64_TPREL16_HI
:
17073 case R_PPC64_TPREL16_HA
:
17074 case R_PPC64_TPREL16_DS
:
17075 case R_PPC64_TPREL16_LO_DS
:
17076 case R_PPC64_TPREL16_HIGH
:
17077 case R_PPC64_TPREL16_HIGHA
:
17078 case R_PPC64_TPREL16_HIGHER
:
17079 case R_PPC64_TPREL16_HIGHERA
:
17080 case R_PPC64_TPREL16_HIGHEST
:
17081 case R_PPC64_TPREL16_HIGHESTA
:
17083 && h
->elf
.root
.type
== bfd_link_hash_undefweak
17084 && h
->elf
.dynindx
== -1
17085 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
17087 /* Make this relocation against an undefined weak symbol
17088 resolve to zero. This is really just a tweak, since
17089 code using weak externs ought to check that they are
17090 defined before using them. */
17091 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
17093 insn
= bfd_get_32 (input_bfd
, p
);
17094 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
17096 bfd_put_32 (input_bfd
, insn
, p
);
17099 /* Fall through. */
17101 case R_PPC64_TPREL34
:
17102 if (htab
->elf
.tls_sec
!= NULL
)
17103 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
17104 /* The TPREL16 relocs shouldn't really be used in shared
17105 libs or with non-local symbols as that will result in
17106 DT_TEXTREL being set, but support them anyway. */
17109 case R_PPC64_DTPREL16
:
17110 case R_PPC64_DTPREL16_LO
:
17111 case R_PPC64_DTPREL16_HI
:
17112 case R_PPC64_DTPREL16_HA
:
17113 case R_PPC64_DTPREL16_DS
:
17114 case R_PPC64_DTPREL16_LO_DS
:
17115 case R_PPC64_DTPREL16_HIGH
:
17116 case R_PPC64_DTPREL16_HIGHA
:
17117 case R_PPC64_DTPREL16_HIGHER
:
17118 case R_PPC64_DTPREL16_HIGHERA
:
17119 case R_PPC64_DTPREL16_HIGHEST
:
17120 case R_PPC64_DTPREL16_HIGHESTA
:
17121 case R_PPC64_DTPREL34
:
17122 if (htab
->elf
.tls_sec
!= NULL
)
17123 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17126 case R_PPC64_ADDR64_LOCAL
:
17127 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
17132 case R_PPC64_DTPMOD64
:
17137 case R_PPC64_TPREL64
:
17138 if (htab
->elf
.tls_sec
!= NULL
)
17139 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
17142 case R_PPC64_DTPREL64
:
17143 if (htab
->elf
.tls_sec
!= NULL
)
17144 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17145 /* Fall through. */
17147 /* Relocations that may need to be propagated if this is a
17149 case R_PPC64_REL30
:
17150 case R_PPC64_REL32
:
17151 case R_PPC64_REL64
:
17152 case R_PPC64_ADDR14
:
17153 case R_PPC64_ADDR14_BRNTAKEN
:
17154 case R_PPC64_ADDR14_BRTAKEN
:
17155 case R_PPC64_ADDR16
:
17156 case R_PPC64_ADDR16_DS
:
17157 case R_PPC64_ADDR16_HA
:
17158 case R_PPC64_ADDR16_HI
:
17159 case R_PPC64_ADDR16_HIGH
:
17160 case R_PPC64_ADDR16_HIGHA
:
17161 case R_PPC64_ADDR16_HIGHER
:
17162 case R_PPC64_ADDR16_HIGHERA
:
17163 case R_PPC64_ADDR16_HIGHEST
:
17164 case R_PPC64_ADDR16_HIGHESTA
:
17165 case R_PPC64_ADDR16_LO
:
17166 case R_PPC64_ADDR16_LO_DS
:
17167 case R_PPC64_ADDR16_HIGHER34
:
17168 case R_PPC64_ADDR16_HIGHERA34
:
17169 case R_PPC64_ADDR16_HIGHEST34
:
17170 case R_PPC64_ADDR16_HIGHESTA34
:
17171 case R_PPC64_ADDR24
:
17172 case R_PPC64_ADDR32
:
17173 case R_PPC64_ADDR64
:
17174 case R_PPC64_UADDR16
:
17175 case R_PPC64_UADDR32
:
17176 case R_PPC64_UADDR64
:
17178 case R_PPC64_D34_LO
:
17179 case R_PPC64_D34_HI30
:
17180 case R_PPC64_D34_HA30
:
17183 if ((input_section
->flags
& SEC_ALLOC
) == 0)
17186 if (NO_OPD_RELOCS
&& is_opd
)
17189 if (bfd_link_pic (info
)
17191 || h
->elf
.dyn_relocs
!= NULL
)
17192 && ((h
!= NULL
&& pc_dynrelocs (h
))
17193 || must_be_dyn_reloc (info
, r_type
)))
17195 ? h
->elf
.dyn_relocs
!= NULL
17196 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
17198 bool skip
, relocate
;
17203 /* When generating a dynamic object, these relocations
17204 are copied into the output file to be resolved at run
17210 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
17211 input_section
, rel
->r_offset
);
17212 if (out_off
== (bfd_vma
) -1)
17214 else if (out_off
== (bfd_vma
) -2)
17215 skip
= true, relocate
= true;
17216 out_off
+= (input_section
->output_section
->vma
17217 + input_section
->output_offset
);
17218 outrel
.r_offset
= out_off
;
17219 outrel
.r_addend
= rel
->r_addend
;
17221 /* Optimize unaligned reloc use. */
17222 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
17223 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
17224 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
17225 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
17226 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
17227 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
17228 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
17229 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
17230 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
17233 memset (&outrel
, 0, sizeof outrel
);
17235 && !SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
17237 && r_type
!= R_PPC64_TOC
)
17239 indx
= h
->elf
.dynindx
;
17240 BFD_ASSERT (indx
!= -1);
17241 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
17245 /* This symbol is local, or marked to become local,
17246 or this is an opd section reloc which must point
17247 at a local function. */
17248 outrel
.r_addend
+= relocation
;
17249 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
17251 if (is_opd
&& h
!= NULL
)
17253 /* Lie about opd entries. This case occurs
17254 when building shared libraries and we
17255 reference a function in another shared
17256 lib. The same thing happens for a weak
17257 definition in an application that's
17258 overridden by a strong definition in a
17259 shared lib. (I believe this is a generic
17260 bug in binutils handling of weak syms.)
17261 In these cases we won't use the opd
17262 entry in this lib. */
17263 unresolved_reloc
= false;
17266 && r_type
== R_PPC64_ADDR64
17268 ? h
->elf
.type
== STT_GNU_IFUNC
17269 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
17270 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
17273 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
17275 /* We need to relocate .opd contents for ld.so.
17276 Prelink also wants simple and consistent rules
17277 for relocs. This make all RELATIVE relocs have
17278 *r_offset equal to r_addend. */
17285 ? h
->elf
.type
== STT_GNU_IFUNC
17286 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17288 info
->callbacks
->einfo
17289 /* xgettext:c-format */
17290 (_("%H: %s for indirect "
17291 "function `%pT' unsupported\n"),
17292 input_bfd
, input_section
, rel
->r_offset
,
17293 ppc64_elf_howto_table
[r_type
]->name
,
17297 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
17299 else if (sec
== NULL
|| sec
->owner
== NULL
)
17301 bfd_set_error (bfd_error_bad_value
);
17306 asection
*osec
= sec
->output_section
;
17308 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
17310 /* TLS symbol values are relative to the
17311 TLS segment. Dynamic relocations for
17312 local TLS symbols therefore can't be
17313 reduced to a relocation against their
17314 section symbol because it holds the
17315 address of the section, not a value
17316 relative to the TLS segment. We could
17317 change the .tdata dynamic section symbol
17318 to be zero value but STN_UNDEF works
17319 and is used elsewhere, eg. for TPREL64
17320 GOT relocs against local TLS symbols. */
17321 osec
= htab
->elf
.tls_sec
;
17326 indx
= elf_section_data (osec
)->dynindx
;
17329 if ((osec
->flags
& SEC_READONLY
) == 0
17330 && htab
->elf
.data_index_section
!= NULL
)
17331 osec
= htab
->elf
.data_index_section
;
17333 osec
= htab
->elf
.text_index_section
;
17334 indx
= elf_section_data (osec
)->dynindx
;
17336 BFD_ASSERT (indx
!= 0);
17339 /* We are turning this relocation into one
17340 against a section symbol, so subtract out
17341 the output section's address but not the
17342 offset of the input section in the output
17344 outrel
.r_addend
-= osec
->vma
;
17347 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
17351 if (!(info
->enable_dt_relr
17352 && ELF64_R_TYPE (outrel
.r_info
) == R_PPC64_RELATIVE
17353 && rel
->r_offset
% 2 == 0
17354 && input_section
->alignment_power
!= 0
17355 && ELF64_R_TYPE (orig_rel
.r_info
) != R_PPC64_UADDR64
))
17357 sreloc
= elf_section_data (input_section
)->sreloc
;
17359 ? h
->elf
.type
== STT_GNU_IFUNC
17360 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17362 sreloc
= htab
->elf
.irelplt
;
17363 if (indx
== 0 || is_static_defined (&h
->elf
))
17364 htab
->elf
.ifunc_resolvers
= true;
17366 if (sreloc
== NULL
)
17369 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
17372 loc
= sreloc
->contents
;
17373 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
17374 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
17377 if (!warned_dynamic
17378 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel
.r_info
)))
17380 info
->callbacks
->einfo
17381 /* xgettext:c-format */
17382 (_("%X%P: %pB: %s against %pT "
17383 "is not supported by glibc as a dynamic relocation\n"),
17385 ppc64_elf_howto_table
[ELF64_R_TYPE (outrel
.r_info
)]->name
,
17387 warned_dynamic
= true;
17390 /* If this reloc is against an external symbol, it will
17391 be computed at runtime, so there's no need to do
17392 anything now. However, for the sake of prelink ensure
17393 that the section contents are a known value. */
17396 unresolved_reloc
= false;
17397 /* The value chosen here is quite arbitrary as ld.so
17398 ignores section contents except for the special
17399 case of .opd where the contents might be accessed
17400 before relocation. Choose zero, as that won't
17401 cause reloc overflow. */
17404 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
17405 to improve backward compatibility with older
17407 if (r_type
== R_PPC64_ADDR64
)
17408 addend
= outrel
.r_addend
;
17409 /* Adjust pc_relative relocs to have zero in *r_offset. */
17410 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
17411 addend
= outrel
.r_offset
;
17417 case R_PPC64_GLOB_DAT
:
17418 case R_PPC64_JMP_SLOT
:
17419 case R_PPC64_JMP_IREL
:
17420 case R_PPC64_RELATIVE
:
17421 /* We shouldn't ever see these dynamic relocs in relocatable
17423 /* Fall through. */
17425 case R_PPC64_PLTGOT16
:
17426 case R_PPC64_PLTGOT16_DS
:
17427 case R_PPC64_PLTGOT16_HA
:
17428 case R_PPC64_PLTGOT16_HI
:
17429 case R_PPC64_PLTGOT16_LO
:
17430 case R_PPC64_PLTGOT16_LO_DS
:
17431 case R_PPC64_PLTREL32
:
17432 case R_PPC64_PLTREL64
:
17433 /* These ones haven't been implemented yet. */
17435 info
->callbacks
->einfo
17436 /* xgettext:c-format */
17437 (_("%P: %pB: %s is not supported for `%pT'\n"),
17439 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
17441 bfd_set_error (bfd_error_invalid_operation
);
17446 /* Multi-instruction sequences that access the TOC can be
17447 optimized, eg. addis ra,r2,0; addi rb,ra,x;
17448 to nop; addi rb,r2,x; */
17454 case R_PPC64_GOT_TLSLD16_HI
:
17455 case R_PPC64_GOT_TLSGD16_HI
:
17456 case R_PPC64_GOT_TPREL16_HI
:
17457 case R_PPC64_GOT_DTPREL16_HI
:
17458 case R_PPC64_GOT16_HI
:
17459 case R_PPC64_TOC16_HI
:
17460 /* These relocs would only be useful if building up an
17461 offset to later add to r2, perhaps in an indexed
17462 addressing mode instruction. Don't try to optimize.
17463 Unfortunately, the possibility of someone building up an
17464 offset like this or even with the HA relocs, means that
17465 we need to check the high insn when optimizing the low
17469 case R_PPC64_PLTCALL_NOTOC
:
17470 if (!unresolved_reloc
)
17471 htab
->notoc_plt
= 1;
17472 /* Fall through. */
17473 case R_PPC64_PLTCALL
:
17474 if (unresolved_reloc
17475 && offset_in_range (input_section
, rel
->r_offset
,
17476 r_type
== R_PPC64_PLTCALL
? 8 : 4))
17478 /* No plt entry. Make this into a direct call. */
17479 bfd_byte
*p
= contents
+ rel
->r_offset
;
17480 insn
= bfd_get_32 (input_bfd
, p
);
17482 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
17483 if (r_type
== R_PPC64_PLTCALL
)
17484 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
17485 unresolved_reloc
= save_unresolved_reloc
;
17486 r_type
= R_PPC64_REL24
;
17490 case R_PPC64_PLTSEQ_NOTOC
:
17491 case R_PPC64_PLTSEQ
:
17492 if (unresolved_reloc
)
17494 unresolved_reloc
= false;
17499 case R_PPC64_PLT_PCREL34_NOTOC
:
17500 if (!unresolved_reloc
)
17501 htab
->notoc_plt
= 1;
17502 /* Fall through. */
17503 case R_PPC64_PLT_PCREL34
:
17504 if (unresolved_reloc
17505 && offset_in_range (input_section
, rel
->r_offset
, 8))
17507 bfd_byte
*p
= contents
+ rel
->r_offset
;
17508 bfd_put_32 (input_bfd
, PNOP
>> 32, p
);
17509 bfd_put_32 (input_bfd
, PNOP
, p
+ 4);
17510 unresolved_reloc
= false;
17515 case R_PPC64_PLT16_HA
:
17516 if (unresolved_reloc
)
17518 unresolved_reloc
= false;
17521 /* Fall through. */
17522 case R_PPC64_GOT_TLSLD16_HA
:
17523 case R_PPC64_GOT_TLSGD16_HA
:
17524 case R_PPC64_GOT_TPREL16_HA
:
17525 case R_PPC64_GOT_DTPREL16_HA
:
17526 case R_PPC64_GOT16_HA
:
17527 case R_PPC64_TOC16_HA
:
17528 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17529 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
17533 if (offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17535 p
= contents
+ (rel
->r_offset
& ~3);
17536 bfd_put_32 (input_bfd
, NOP
, p
);
17542 case R_PPC64_PLT16_LO
:
17543 case R_PPC64_PLT16_LO_DS
:
17544 if (unresolved_reloc
)
17546 unresolved_reloc
= false;
17549 /* Fall through. */
17550 case R_PPC64_GOT_TLSLD16_LO
:
17551 case R_PPC64_GOT_TLSGD16_LO
:
17552 case R_PPC64_GOT_TPREL16_LO_DS
:
17553 case R_PPC64_GOT_DTPREL16_LO_DS
:
17554 case R_PPC64_GOT16_LO
:
17555 case R_PPC64_GOT16_LO_DS
:
17556 case R_PPC64_TOC16_LO
:
17557 case R_PPC64_TOC16_LO_DS
:
17558 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17559 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
17560 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17562 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17563 insn
= bfd_get_32 (input_bfd
, p
);
17564 if ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */)
17566 /* Transform addic to addi when we change reg. */
17567 insn
&= ~((0x3fu
<< 26) | (0x1f << 16));
17568 insn
|= (14u << 26) | (2 << 16);
17572 insn
&= ~(0x1f << 16);
17575 bfd_put_32 (input_bfd
, insn
, p
);
17579 case R_PPC64_TPREL16_HA
:
17580 if (htab
->do_tls_opt
17581 && relocation
+ addend
+ 0x8000 < 0x10000
17582 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17584 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17585 bfd_put_32 (input_bfd
, NOP
, p
);
17590 case R_PPC64_TPREL16_LO
:
17591 case R_PPC64_TPREL16_LO_DS
:
17592 if (htab
->do_tls_opt
17593 && relocation
+ addend
+ 0x8000 < 0x10000
17594 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17596 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17597 insn
= bfd_get_32 (input_bfd
, p
);
17598 insn
&= ~(0x1f << 16);
17600 bfd_put_32 (input_bfd
, insn
, p
);
17605 /* Do any further special processing. */
17611 case R_PPC64_REL16_HA
:
17612 case R_PPC64_REL16_HIGHA
:
17613 case R_PPC64_REL16_HIGHERA
:
17614 case R_PPC64_REL16_HIGHESTA
:
17615 case R_PPC64_REL16DX_HA
:
17616 case R_PPC64_ADDR16_HA
:
17617 case R_PPC64_ADDR16_HIGHA
:
17618 case R_PPC64_ADDR16_HIGHERA
:
17619 case R_PPC64_ADDR16_HIGHESTA
:
17620 case R_PPC64_TOC16_HA
:
17621 case R_PPC64_SECTOFF_HA
:
17622 case R_PPC64_TPREL16_HA
:
17623 case R_PPC64_TPREL16_HIGHA
:
17624 case R_PPC64_TPREL16_HIGHERA
:
17625 case R_PPC64_TPREL16_HIGHESTA
:
17626 case R_PPC64_DTPREL16_HA
:
17627 case R_PPC64_DTPREL16_HIGHA
:
17628 case R_PPC64_DTPREL16_HIGHERA
:
17629 case R_PPC64_DTPREL16_HIGHESTA
:
17630 /* It's just possible that this symbol is a weak symbol
17631 that's not actually defined anywhere. In that case,
17632 'sec' would be NULL, and we should leave the symbol
17633 alone (it will be set to zero elsewhere in the link). */
17636 /* Fall through. */
17638 case R_PPC64_GOT16_HA
:
17639 case R_PPC64_PLTGOT16_HA
:
17640 case R_PPC64_PLT16_HA
:
17641 case R_PPC64_GOT_TLSGD16_HA
:
17642 case R_PPC64_GOT_TLSLD16_HA
:
17643 case R_PPC64_GOT_TPREL16_HA
:
17644 case R_PPC64_GOT_DTPREL16_HA
:
17645 /* Add 0x10000 if sign bit in 0:15 is set.
17646 Bits 0:15 are not used. */
17650 case R_PPC64_D34_HA30
:
17651 case R_PPC64_ADDR16_HIGHERA34
:
17652 case R_PPC64_ADDR16_HIGHESTA34
:
17653 case R_PPC64_REL16_HIGHERA34
:
17654 case R_PPC64_REL16_HIGHESTA34
:
17656 addend
+= 1ULL << 33;
17659 case R_PPC64_ADDR16_DS
:
17660 case R_PPC64_ADDR16_LO_DS
:
17661 case R_PPC64_GOT16_DS
:
17662 case R_PPC64_GOT16_LO_DS
:
17663 case R_PPC64_PLT16_LO_DS
:
17664 case R_PPC64_SECTOFF_DS
:
17665 case R_PPC64_SECTOFF_LO_DS
:
17666 case R_PPC64_TOC16_DS
:
17667 case R_PPC64_TOC16_LO_DS
:
17668 case R_PPC64_PLTGOT16_DS
:
17669 case R_PPC64_PLTGOT16_LO_DS
:
17670 case R_PPC64_GOT_TPREL16_DS
:
17671 case R_PPC64_GOT_TPREL16_LO_DS
:
17672 case R_PPC64_GOT_DTPREL16_DS
:
17673 case R_PPC64_GOT_DTPREL16_LO_DS
:
17674 case R_PPC64_TPREL16_DS
:
17675 case R_PPC64_TPREL16_LO_DS
:
17676 case R_PPC64_DTPREL16_DS
:
17677 case R_PPC64_DTPREL16_LO_DS
:
17678 if (!offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17680 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17682 /* If this reloc is against an lq, lxv, or stxv insn, then
17683 the value must be a multiple of 16. This is somewhat of
17684 a hack, but the "correct" way to do this by defining _DQ
17685 forms of all the _DS relocs bloats all reloc switches in
17686 this file. It doesn't make much sense to use these
17687 relocs in data, so testing the insn should be safe. */
17688 if ((insn
& (0x3fu
<< 26)) == (56u << 26)
17689 || ((insn
& (0x3fu
<< 26)) == (61u << 26) && (insn
& 3) == 1))
17691 relocation
+= addend
;
17692 addend
= insn
& (mask
^ 3);
17693 if ((relocation
& mask
) != 0)
17695 relocation
^= relocation
& mask
;
17696 info
->callbacks
->einfo
17697 /* xgettext:c-format */
17698 (_("%H: error: %s not a multiple of %u\n"),
17699 input_bfd
, input_section
, rel
->r_offset
,
17700 ppc64_elf_howto_table
[r_type
]->name
,
17702 bfd_set_error (bfd_error_bad_value
);
17709 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
17710 because such sections are not SEC_ALLOC and thus ld.so will
17711 not process them. */
17712 howto
= ppc64_elf_howto_table
[(int) r_type
];
17713 if (unresolved_reloc
17714 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
17715 && h
->elf
.def_dynamic
)
17716 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
17717 rel
->r_offset
) != (bfd_vma
) -1)
17719 info
->callbacks
->einfo
17720 /* xgettext:c-format */
17721 (_("%H: unresolvable %s against `%pT'\n"),
17722 input_bfd
, input_section
, rel
->r_offset
,
17724 h
->elf
.root
.root
.string
);
17728 /* 16-bit fields in insns mostly have signed values, but a
17729 few insns have 16-bit unsigned values. Really, we should
17730 have different reloc types. */
17731 if (howto
->complain_on_overflow
!= complain_overflow_dont
17732 && howto
->dst_mask
== 0xffff
17733 && (input_section
->flags
& SEC_CODE
) != 0
17734 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17736 enum complain_overflow complain
= complain_overflow_signed
;
17738 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17739 if ((insn
& (0x3fu
<< 26)) == 10u << 26 /* cmpli */)
17740 complain
= complain_overflow_bitfield
;
17741 else if (howto
->rightshift
== 0
17742 ? ((insn
& (0x3fu
<< 26)) == 28u << 26 /* andi */
17743 || (insn
& (0x3fu
<< 26)) == 24u << 26 /* ori */
17744 || (insn
& (0x3fu
<< 26)) == 26u << 26 /* xori */)
17745 : ((insn
& (0x3fu
<< 26)) == 29u << 26 /* andis */
17746 || (insn
& (0x3fu
<< 26)) == 25u << 26 /* oris */
17747 || (insn
& (0x3fu
<< 26)) == 27u << 26 /* xoris */))
17748 complain
= complain_overflow_unsigned
;
17749 if (howto
->complain_on_overflow
!= complain
)
17751 alt_howto
= *howto
;
17752 alt_howto
.complain_on_overflow
= complain
;
17753 howto
= &alt_howto
;
17759 /* Split field relocs aren't handled by _bfd_final_link_relocate. */
17761 case R_PPC64_D34_LO
:
17762 case R_PPC64_D34_HI30
:
17763 case R_PPC64_D34_HA30
:
17764 case R_PPC64_PCREL34
:
17765 case R_PPC64_GOT_PCREL34
:
17766 case R_PPC64_TPREL34
:
17767 case R_PPC64_DTPREL34
:
17768 case R_PPC64_GOT_TLSGD_PCREL34
:
17769 case R_PPC64_GOT_TLSLD_PCREL34
:
17770 case R_PPC64_GOT_TPREL_PCREL34
:
17771 case R_PPC64_GOT_DTPREL_PCREL34
:
17772 case R_PPC64_PLT_PCREL34
:
17773 case R_PPC64_PLT_PCREL34_NOTOC
:
17775 case R_PPC64_PCREL28
:
17776 if (!offset_in_range (input_section
, rel
->r_offset
, 8))
17777 r
= bfd_reloc_outofrange
;
17780 relocation
+= addend
;
17781 if (howto
->pc_relative
)
17782 relocation
-= (rel
->r_offset
17783 + input_section
->output_offset
17784 + input_section
->output_section
->vma
);
17785 relocation
>>= howto
->rightshift
;
17787 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17789 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
17791 pinsn
&= ~howto
->dst_mask
;
17792 pinsn
|= (((relocation
<< 16) | (relocation
& 0xffff))
17793 & howto
->dst_mask
);
17794 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ rel
->r_offset
);
17795 bfd_put_32 (input_bfd
, pinsn
, contents
+ rel
->r_offset
+ 4);
17797 if (howto
->complain_on_overflow
== complain_overflow_signed
17798 && (relocation
+ (1ULL << (howto
->bitsize
- 1))
17799 >= 1ULL << howto
->bitsize
))
17800 r
= bfd_reloc_overflow
;
17804 case R_PPC64_REL16DX_HA
:
17805 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
17806 r
= bfd_reloc_outofrange
;
17809 relocation
+= addend
;
17810 relocation
-= (rel
->r_offset
17811 + input_section
->output_offset
17812 + input_section
->output_section
->vma
);
17813 relocation
= (bfd_signed_vma
) relocation
>> 16;
17814 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17816 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
17817 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
17819 if (relocation
+ 0x8000 > 0xffff)
17820 r
= bfd_reloc_overflow
;
17825 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
17826 contents
, rel
->r_offset
,
17827 relocation
, addend
);
17830 if (r
!= bfd_reloc_ok
)
17832 char *more_info
= NULL
;
17833 const char *reloc_name
= howto
->name
;
17835 if (reloc_dest
!= DEST_NORMAL
)
17837 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
17838 if (more_info
!= NULL
)
17840 strcpy (more_info
, reloc_name
);
17841 strcat (more_info
, (reloc_dest
== DEST_OPD
17842 ? " (OPD)" : " (stub)"));
17843 reloc_name
= more_info
;
17847 if (r
== bfd_reloc_overflow
)
17849 /* On code like "if (foo) foo();" don't report overflow
17850 on a branch to zero when foo is undefined. */
17852 && (reloc_dest
== DEST_STUB
17854 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
17855 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
17856 && is_branch_reloc (r_type
))))
17857 info
->callbacks
->reloc_overflow
17858 (info
, (struct bfd_link_hash_entry
*) h
, sym_name
,
17859 reloc_name
, orig_rel
.r_addend
, input_bfd
, input_section
,
17864 info
->callbacks
->einfo
17865 /* xgettext:c-format */
17866 (_("%H: %s against `%pT': error %d\n"),
17867 input_bfd
, input_section
, rel
->r_offset
,
17868 reloc_name
, sym_name
, (int) r
);
17880 Elf_Internal_Shdr
*rel_hdr
;
17881 size_t deleted
= rel
- wrel
;
17883 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
17884 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17885 if (rel_hdr
->sh_size
== 0)
17887 /* It is too late to remove an empty reloc section. Leave
17889 ??? What is wrong with an empty section??? */
17890 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
17893 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
17894 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17895 input_section
->reloc_count
-= deleted
;
17898 /* If we're emitting relocations, then shortly after this function
17899 returns, reloc offsets and addends for this section will be
17900 adjusted. Worse, reloc symbol indices will be for the output
17901 file rather than the input. Save a copy of the relocs for
17902 opd_entry_value. */
17903 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
17906 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
17907 rel
= bfd_alloc (input_bfd
, amt
);
17908 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
17909 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
17912 memcpy (rel
, relocs
, amt
);
17917 /* Adjust the value of any local symbols in opd sections. */
17920 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
17921 const char *name ATTRIBUTE_UNUSED
,
17922 Elf_Internal_Sym
*elfsym
,
17923 asection
*input_sec
,
17924 struct elf_link_hash_entry
*h
)
17926 struct _opd_sec_data
*opd
;
17933 opd
= get_opd_info (input_sec
);
17934 if (opd
== NULL
|| opd
->adjust
== NULL
)
17937 value
= elfsym
->st_value
- input_sec
->output_offset
;
17938 if (!bfd_link_relocatable (info
))
17939 value
-= input_sec
->output_section
->vma
;
17941 adjust
= opd
->adjust
[OPD_NDX (value
)];
17945 elfsym
->st_value
+= adjust
;
17949 /* Finish up dynamic symbol handling. We set the contents of various
17950 dynamic sections here. */
17953 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
17954 struct bfd_link_info
*info
,
17955 struct elf_link_hash_entry
*h
,
17956 Elf_Internal_Sym
*sym
)
17958 struct ppc_link_hash_table
*htab
;
17959 struct plt_entry
*ent
;
17961 htab
= ppc_hash_table (info
);
17965 if (!htab
->opd_abi
&& !h
->def_regular
)
17966 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
17967 if (ent
->plt
.offset
!= (bfd_vma
) -1)
17969 /* Mark the symbol as undefined, rather than as
17970 defined in glink. Leave the value if there were
17971 any relocations where pointer equality matters
17972 (this is a clue for the dynamic linker, to make
17973 function pointer comparisons work between an
17974 application and shared library), otherwise set it
17976 sym
->st_shndx
= SHN_UNDEF
;
17977 if (!h
->pointer_equality_needed
)
17979 else if (!h
->ref_regular_nonweak
)
17981 /* This breaks function pointer comparisons, but
17982 that is better than breaking tests for a NULL
17983 function pointer. */
17990 && (h
->root
.type
== bfd_link_hash_defined
17991 || h
->root
.type
== bfd_link_hash_defweak
)
17992 && (h
->root
.u
.def
.section
== htab
->elf
.sdynbss
17993 || h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
))
17995 /* This symbol needs a copy reloc. Set it up. */
17996 Elf_Internal_Rela rela
;
18000 if (h
->dynindx
== -1)
18003 rela
.r_offset
= defined_sym_val (h
);
18004 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
18006 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
18007 srel
= htab
->elf
.sreldynrelro
;
18009 srel
= htab
->elf
.srelbss
;
18010 loc
= srel
->contents
;
18011 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
18012 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
18018 /* Used to decide how to sort relocs in an optimal manner for the
18019 dynamic linker, before writing them out. */
18021 static enum elf_reloc_type_class
18022 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
18023 const asection
*rel_sec
,
18024 const Elf_Internal_Rela
*rela
)
18026 enum elf_ppc64_reloc_type r_type
;
18027 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
18029 if (rel_sec
== htab
->elf
.irelplt
)
18030 return reloc_class_ifunc
;
18032 r_type
= ELF64_R_TYPE (rela
->r_info
);
18035 case R_PPC64_RELATIVE
:
18036 return reloc_class_relative
;
18037 case R_PPC64_JMP_SLOT
:
18038 return reloc_class_plt
;
18040 return reloc_class_copy
;
18042 return reloc_class_normal
;
18046 /* Finish up the dynamic sections. */
18049 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
18050 struct bfd_link_info
*info
)
18052 struct ppc_link_hash_table
*htab
;
18056 htab
= ppc_hash_table (info
);
18060 dynobj
= htab
->elf
.dynobj
;
18061 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
18063 if (htab
->elf
.dynamic_sections_created
)
18065 Elf64_External_Dyn
*dyncon
, *dynconend
;
18067 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
18070 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
18071 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
18072 for (; dyncon
< dynconend
; dyncon
++)
18074 Elf_Internal_Dyn dyn
;
18077 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
18084 case DT_PPC64_GLINK
:
18086 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18087 /* We stupidly defined DT_PPC64_GLINK to be the start
18088 of glink rather than the first entry point, which is
18089 what ld.so needs, and now have a bigger stub to
18090 support automatic multiple TOCs. */
18091 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
18095 s
= bfd_get_section_by_name (output_bfd
, ".opd");
18098 dyn
.d_un
.d_ptr
= s
->vma
;
18102 if ((htab
->do_multi_toc
&& htab
->multi_toc_needed
)
18103 || htab
->notoc_plt
)
18104 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
18105 if (htab
->has_plt_localentry0
)
18106 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
18109 case DT_PPC64_OPDSZ
:
18110 s
= bfd_get_section_by_name (output_bfd
, ".opd");
18113 dyn
.d_un
.d_val
= s
->size
;
18117 s
= htab
->elf
.splt
;
18118 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18122 s
= htab
->elf
.srelplt
;
18123 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18127 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
18131 if (htab
->elf
.ifunc_resolvers
)
18132 info
->callbacks
->einfo
18133 (_("%P: warning: text relocations and GNU indirect "
18134 "functions may result in a segfault at runtime\n"));
18138 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
18142 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
18143 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
18145 /* Fill in the first entry in the global offset table.
18146 We use it to hold the link-time TOCbase. */
18147 bfd_put_64 (output_bfd
,
18148 elf_gp (output_bfd
) + TOC_BASE_OFF
,
18149 htab
->elf
.sgot
->contents
);
18151 /* Set .got entry size. */
18152 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
18156 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
18157 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
18159 /* Set .plt entry size. */
18160 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
18161 = PLT_ENTRY_SIZE (htab
);
18164 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
18165 brlt ourselves if emitrelocations. */
18166 if (htab
->brlt
!= NULL
18167 && htab
->brlt
->reloc_count
!= 0
18168 && !_bfd_elf_link_output_relocs (output_bfd
,
18170 elf_section_data (htab
->brlt
)->rela
.hdr
,
18171 elf_section_data (htab
->brlt
)->relocs
,
18175 if (htab
->glink
!= NULL
18176 && htab
->glink
->reloc_count
!= 0
18177 && !_bfd_elf_link_output_relocs (output_bfd
,
18179 elf_section_data (htab
->glink
)->rela
.hdr
,
18180 elf_section_data (htab
->glink
)->relocs
,
18185 if (htab
->glink_eh_frame
!= NULL
18186 && htab
->glink_eh_frame
->size
!= 0
18187 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
18188 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
18189 htab
->glink_eh_frame
,
18190 htab
->glink_eh_frame
->contents
))
18193 /* We need to handle writing out multiple GOT sections ourselves,
18194 since we didn't add them to DYNOBJ. We know dynobj is the first
18196 while ((dynobj
= dynobj
->link
.next
) != NULL
)
18200 if (!is_ppc64_elf (dynobj
))
18203 s
= ppc64_elf_tdata (dynobj
)->got
;
18206 && s
->output_section
!= bfd_abs_section_ptr
18207 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
18208 s
->contents
, s
->output_offset
,
18211 s
= ppc64_elf_tdata (dynobj
)->relgot
;
18214 && s
->output_section
!= bfd_abs_section_ptr
18215 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
18216 s
->contents
, s
->output_offset
,
18224 #include "elf64-target.h"
18226 /* FreeBSD support */
18228 #undef TARGET_LITTLE_SYM
18229 #define TARGET_LITTLE_SYM powerpc_elf64_fbsd_le_vec
18230 #undef TARGET_LITTLE_NAME
18231 #define TARGET_LITTLE_NAME "elf64-powerpcle-freebsd"
18233 #undef TARGET_BIG_SYM
18234 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
18235 #undef TARGET_BIG_NAME
18236 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
18239 #define ELF_OSABI ELFOSABI_FREEBSD
18242 #define elf64_bed elf64_powerpc_fbsd_bed
18244 #include "elf64-target.h"