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
5393 && ((!NO_OPD_RELOCS
&& is_opd
)
5394 || (!ifunc
&& SYMBOL_REFERENCES_LOCAL (info
, h
))))
5399 /* Track dynamic relocs needed for local syms too.
5400 We really need local syms available to do this
5402 struct ppc_local_dyn_relocs
*p
;
5403 struct ppc_local_dyn_relocs
**head
;
5407 Elf_Internal_Sym
*isym
;
5409 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
5414 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5418 vpp
= &elf_section_data (s
)->local_dynrel
;
5419 head
= (struct ppc_local_dyn_relocs
**) vpp
;
5420 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5422 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5424 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5426 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5434 p
->ifunc
= is_ifunc
;
5437 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
5438 && rel
->r_offset
% 2 == 0
5439 && sec
->alignment_power
!= 0
5440 && ((!NO_OPD_RELOCS
&& is_opd
) || !is_ifunc
))
5454 /* Merge backend specific data from an object file to the output
5455 object file when linking. */
5458 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5460 bfd
*obfd
= info
->output_bfd
;
5461 unsigned long iflags
, oflags
;
5463 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5466 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5469 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
5472 iflags
= elf_elfheader (ibfd
)->e_flags
;
5473 oflags
= elf_elfheader (obfd
)->e_flags
;
5475 if (iflags
& ~EF_PPC64_ABI
)
5478 /* xgettext:c-format */
5479 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5480 bfd_set_error (bfd_error_bad_value
);
5483 else if (iflags
!= oflags
&& iflags
!= 0)
5486 /* xgettext:c-format */
5487 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
5488 ibfd
, iflags
, oflags
);
5489 bfd_set_error (bfd_error_bad_value
);
5493 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
5496 /* Merge Tag_compatibility attributes and any common GNU ones. */
5497 return _bfd_elf_merge_object_attributes (ibfd
, info
);
5501 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5503 /* Print normal ELF private data. */
5504 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5506 if (elf_elfheader (abfd
)->e_flags
!= 0)
5510 fprintf (file
, _("private flags = 0x%lx:"),
5511 elf_elfheader (abfd
)->e_flags
);
5513 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5514 fprintf (file
, _(" [abiv%ld]"),
5515 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5522 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5523 of the code entry point, and its section, which must be in the same
5524 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5527 opd_entry_value (asection
*opd_sec
,
5529 asection
**code_sec
,
5533 bfd
*opd_bfd
= opd_sec
->owner
;
5534 Elf_Internal_Rela
*relocs
;
5535 Elf_Internal_Rela
*lo
, *hi
, *look
;
5538 /* No relocs implies we are linking a --just-symbols object, or looking
5539 at a final linked executable with addr2line or somesuch. */
5540 if (opd_sec
->reloc_count
== 0)
5542 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
5544 if (contents
== NULL
)
5546 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5547 return (bfd_vma
) -1;
5548 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5551 /* PR 17512: file: 64b9dfbb. */
5552 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5553 return (bfd_vma
) -1;
5555 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5556 if (code_sec
!= NULL
)
5558 asection
*sec
, *likely
= NULL
;
5564 && val
< sec
->vma
+ sec
->size
)
5570 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5572 && (sec
->flags
& SEC_LOAD
) != 0
5573 && (sec
->flags
& SEC_ALLOC
) != 0)
5578 if (code_off
!= NULL
)
5579 *code_off
= val
- likely
->vma
;
5585 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5587 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5589 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, true);
5590 /* PR 17512: file: df8e1fd6. */
5592 return (bfd_vma
) -1;
5594 /* Go find the opd reloc at the sym address. */
5596 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5600 look
= lo
+ (hi
- lo
) / 2;
5601 if (look
->r_offset
< offset
)
5603 else if (look
->r_offset
> offset
)
5607 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5609 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5610 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5612 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5613 asection
*sec
= NULL
;
5615 if (symndx
>= symtab_hdr
->sh_info
5616 && elf_sym_hashes (opd_bfd
) != NULL
)
5618 struct elf_link_hash_entry
**sym_hashes
;
5619 struct elf_link_hash_entry
*rh
;
5621 sym_hashes
= elf_sym_hashes (opd_bfd
);
5622 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5625 rh
= elf_follow_link (rh
);
5626 if (rh
->root
.type
!= bfd_link_hash_defined
5627 && rh
->root
.type
!= bfd_link_hash_defweak
)
5629 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5631 val
= rh
->root
.u
.def
.value
;
5632 sec
= rh
->root
.u
.def
.section
;
5639 Elf_Internal_Sym
*sym
;
5641 if (symndx
< symtab_hdr
->sh_info
)
5643 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5646 size_t symcnt
= symtab_hdr
->sh_info
;
5647 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5652 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5658 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5664 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5667 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5668 val
= sym
->st_value
;
5671 val
+= look
->r_addend
;
5672 if (code_off
!= NULL
)
5674 if (code_sec
!= NULL
)
5676 if (in_code_sec
&& *code_sec
!= sec
)
5681 if (sec
->output_section
!= NULL
)
5682 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5691 /* If the ELF symbol SYM might be a function in SEC, return the
5692 function size and set *CODE_OFF to the function's entry point,
5693 otherwise return zero. */
5695 static bfd_size_type
5696 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5700 elf_symbol_type
* elf_sym
= (elf_symbol_type
*) sym
;
5702 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5703 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5706 size
= (sym
->flags
& BSF_SYNTHETIC
) ? 0 : elf_sym
->internal_elf_sym
.st_size
;
5708 /* In theory we should check that the symbol's type satisfies
5709 _bfd_elf_is_function_type(), but there are some function-like
5710 symbols which would fail this test. (eg _start). Instead
5711 we check for hidden, local, notype symbols with zero size.
5712 This type of symbol is generated by the annobin plugin for gcc
5713 and clang, and should not be considered to be a function symbol. */
5715 && ((sym
->flags
& (BSF_SYNTHETIC
| BSF_LOCAL
)) == BSF_LOCAL
)
5716 && ELF_ST_TYPE (elf_sym
->internal_elf_sym
.st_info
) == STT_NOTYPE
5717 && ELF_ST_VISIBILITY (elf_sym
->internal_elf_sym
.st_other
) == STV_HIDDEN
)
5720 if (strcmp (sym
->section
->name
, ".opd") == 0)
5722 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5723 bfd_vma symval
= sym
->value
;
5726 && opd
->adjust
!= NULL
5727 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5729 /* opd_entry_value will use cached relocs that have been
5730 adjusted, but with raw symbols. That means both local
5731 and global symbols need adjusting. */
5732 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5738 if (opd_entry_value (sym
->section
, symval
,
5739 &sec
, code_off
, true) == (bfd_vma
) -1)
5741 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5742 symbol. This size has nothing to do with the code size of the
5743 function, which is what we're supposed to return, but the
5744 code size isn't available without looking up the dot-sym.
5745 However, doing that would be a waste of time particularly
5746 since elf_find_function will look at the dot-sym anyway.
5747 Now, elf_find_function will keep the largest size of any
5748 function sym found at the code address of interest, so return
5749 1 here to avoid it incorrectly caching a larger function size
5750 for a small function. This does mean we return the wrong
5751 size for a new-ABI function of size 24, but all that does is
5752 disable caching for such functions. */
5758 if (sym
->section
!= sec
)
5760 *code_off
= sym
->value
;
5763 /* Do not return 0 for the function's size. */
5764 return size
? size
: 1;
5767 /* Return true if symbol is a strong function defined in an ELFv2
5768 object with st_other localentry bits of zero, ie. its local entry
5769 point coincides with its global entry point. */
5772 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5775 && h
->type
== STT_FUNC
5776 && h
->root
.type
== bfd_link_hash_defined
5777 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5778 && !ppc_elf_hash_entry (h
)->non_zero_localentry
5779 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5780 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5783 /* Return true if symbol is defined in a regular object file. */
5786 is_static_defined (struct elf_link_hash_entry
*h
)
5788 return ((h
->root
.type
== bfd_link_hash_defined
5789 || h
->root
.type
== bfd_link_hash_defweak
)
5790 && h
->root
.u
.def
.section
!= NULL
5791 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5794 /* If FDH is a function descriptor symbol, return the associated code
5795 entry symbol if it is defined. Return NULL otherwise. */
5797 static struct ppc_link_hash_entry
*
5798 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5800 if (fdh
->is_func_descriptor
)
5802 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5803 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5804 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5810 /* If FH is a function code entry symbol, return the associated
5811 function descriptor symbol if it is defined. Return NULL otherwise. */
5813 static struct ppc_link_hash_entry
*
5814 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5817 && fh
->oh
->is_func_descriptor
)
5819 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5820 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5821 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5827 /* Given H is a symbol that satisfies is_static_defined, return the
5828 value in the output file. */
5831 defined_sym_val (struct elf_link_hash_entry
*h
)
5833 return (h
->root
.u
.def
.section
->output_section
->vma
5834 + h
->root
.u
.def
.section
->output_offset
5835 + h
->root
.u
.def
.value
);
5838 /* Return true if H matches __tls_get_addr or one of its variants. */
5841 is_tls_get_addr (struct elf_link_hash_entry
*h
,
5842 struct ppc_link_hash_table
*htab
)
5844 return (h
== elf_hash_entry (htab
->tls_get_addr_fd
)
5845 || h
== elf_hash_entry (htab
->tga_desc_fd
)
5846 || h
== elf_hash_entry (htab
->tls_get_addr
)
5847 || h
== elf_hash_entry (htab
->tga_desc
));
5850 static bool func_desc_adjust (struct elf_link_hash_entry
*, void *);
5852 /* Garbage collect sections, after first dealing with dot-symbols. */
5855 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5857 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5859 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5861 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5862 htab
->need_func_desc_adj
= 0;
5864 return bfd_elf_gc_sections (abfd
, info
);
5867 /* Mark all our entry sym sections, both opd and code section. */
5870 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5872 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5873 struct bfd_sym_chain
*sym
;
5878 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5880 struct ppc_link_hash_entry
*eh
, *fh
;
5883 eh
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
->name
,
5884 false, false, true));
5887 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5888 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5891 fh
= defined_code_entry (eh
);
5894 sec
= fh
->elf
.root
.u
.def
.section
;
5895 sec
->flags
|= SEC_KEEP
;
5897 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5898 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5899 eh
->elf
.root
.u
.def
.value
,
5900 &sec
, NULL
, false) != (bfd_vma
) -1)
5901 sec
->flags
|= SEC_KEEP
;
5903 sec
= eh
->elf
.root
.u
.def
.section
;
5904 sec
->flags
|= SEC_KEEP
;
5908 /* Mark sections containing dynamically referenced symbols. When
5909 building shared libraries, we must assume that any visible symbol is
5913 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5915 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5916 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
5917 struct ppc_link_hash_entry
*fdh
;
5918 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5920 /* Dynamic linking info is on the func descriptor sym. */
5921 fdh
= defined_func_desc (eh
);
5925 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5926 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5927 && (!eh
->elf
.start_stop
5928 || eh
->elf
.root
.ldscript_def
5929 || !info
->start_stop_gc
)
5930 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5931 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5932 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5933 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5934 && (!bfd_link_executable (info
)
5935 || info
->gc_keep_exported
5936 || info
->export_dynamic
5939 && (*d
->match
) (&d
->head
, NULL
,
5940 eh
->elf
.root
.root
.string
)))
5941 && (eh
->elf
.versioned
>= versioned
5942 || !bfd_hide_sym_by_version (info
->version_info
,
5943 eh
->elf
.root
.root
.string
)))))
5946 struct ppc_link_hash_entry
*fh
;
5948 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5950 /* Function descriptor syms cause the associated
5951 function code sym section to be marked. */
5952 fh
= defined_code_entry (eh
);
5955 code_sec
= fh
->elf
.root
.u
.def
.section
;
5956 code_sec
->flags
|= SEC_KEEP
;
5958 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5959 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5960 eh
->elf
.root
.u
.def
.value
,
5961 &code_sec
, NULL
, false) != (bfd_vma
) -1)
5962 code_sec
->flags
|= SEC_KEEP
;
5968 /* Return the section that should be marked against GC for a given
5972 ppc64_elf_gc_mark_hook (asection
*sec
,
5973 struct bfd_link_info
*info
,
5974 Elf_Internal_Rela
*rel
,
5975 struct elf_link_hash_entry
*h
,
5976 Elf_Internal_Sym
*sym
)
5980 /* Syms return NULL if we're marking .opd, so we avoid marking all
5981 function sections, as all functions are referenced in .opd. */
5983 if (get_opd_info (sec
) != NULL
)
5988 enum elf_ppc64_reloc_type r_type
;
5989 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5991 r_type
= ELF64_R_TYPE (rel
->r_info
);
5994 case R_PPC64_GNU_VTINHERIT
:
5995 case R_PPC64_GNU_VTENTRY
:
5999 switch (h
->root
.type
)
6001 case bfd_link_hash_defined
:
6002 case bfd_link_hash_defweak
:
6003 eh
= ppc_elf_hash_entry (h
);
6004 fdh
= defined_func_desc (eh
);
6007 /* -mcall-aixdesc code references the dot-symbol on
6008 a call reloc. Mark the function descriptor too
6009 against garbage collection. */
6011 if (fdh
->elf
.is_weakalias
)
6012 weakdef (&fdh
->elf
)->mark
= 1;
6016 /* Function descriptor syms cause the associated
6017 function code sym section to be marked. */
6018 fh
= defined_code_entry (eh
);
6021 /* They also mark their opd section. */
6022 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6024 rsec
= fh
->elf
.root
.u
.def
.section
;
6026 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6027 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6028 eh
->elf
.root
.u
.def
.value
,
6029 &rsec
, NULL
, false) != (bfd_vma
) -1)
6030 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6032 rsec
= h
->root
.u
.def
.section
;
6035 case bfd_link_hash_common
:
6036 rsec
= h
->root
.u
.c
.p
->section
;
6040 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6046 struct _opd_sec_data
*opd
;
6048 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6049 opd
= get_opd_info (rsec
);
6050 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6054 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6061 /* The maximum size of .sfpr. */
6062 #define SFPR_MAX (218*4)
6064 struct sfpr_def_parms
6066 const char name
[12];
6067 unsigned char lo
, hi
;
6068 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
6069 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
6072 /* Auto-generate _save*, _rest* functions in .sfpr.
6073 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6077 sfpr_define (struct bfd_link_info
*info
,
6078 const struct sfpr_def_parms
*parm
,
6081 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6083 size_t len
= strlen (parm
->name
);
6084 bool writing
= false;
6090 memcpy (sym
, parm
->name
, len
);
6093 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6095 struct ppc_link_hash_entry
*h
;
6097 sym
[len
+ 0] = i
/ 10 + '0';
6098 sym
[len
+ 1] = i
% 10 + '0';
6099 h
= ppc_elf_hash_entry (elf_link_hash_lookup (&htab
->elf
, sym
,
6100 writing
, true, true));
6101 if (stub_sec
!= NULL
)
6104 && h
->elf
.root
.type
== bfd_link_hash_defined
6105 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6107 struct elf_link_hash_entry
*s
;
6109 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6110 s
= elf_link_hash_lookup (&htab
->elf
, buf
, true, true, false);
6113 if (s
->root
.type
== bfd_link_hash_new
)
6115 s
->root
.type
= bfd_link_hash_defined
;
6116 s
->root
.u
.def
.section
= stub_sec
;
6117 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6118 + h
->elf
.root
.u
.def
.value
);
6121 s
->ref_regular_nonweak
= 1;
6122 s
->forced_local
= 1;
6124 s
->root
.linker_def
= 1;
6132 if (!h
->elf
.def_regular
)
6134 h
->elf
.root
.type
= bfd_link_hash_defined
;
6135 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6136 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6137 h
->elf
.type
= STT_FUNC
;
6138 h
->elf
.def_regular
= 1;
6140 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, true);
6142 if (htab
->sfpr
->contents
== NULL
)
6144 htab
->sfpr
->contents
6145 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6146 if (htab
->sfpr
->contents
== NULL
)
6153 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6155 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6157 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6158 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6166 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6168 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6173 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6175 p
= savegpr0 (abfd
, p
, r
);
6176 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6178 bfd_put_32 (abfd
, BLR
, p
);
6183 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6185 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6190 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6192 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6194 p
= restgpr0 (abfd
, p
, r
);
6195 bfd_put_32 (abfd
, MTLR_R0
, p
);
6199 p
= restgpr0 (abfd
, p
, 30);
6200 p
= restgpr0 (abfd
, p
, 31);
6202 bfd_put_32 (abfd
, BLR
, p
);
6207 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6209 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6214 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6216 p
= savegpr1 (abfd
, p
, r
);
6217 bfd_put_32 (abfd
, BLR
, p
);
6222 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6224 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6229 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6231 p
= restgpr1 (abfd
, p
, r
);
6232 bfd_put_32 (abfd
, BLR
, p
);
6237 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6239 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6244 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6246 p
= savefpr (abfd
, p
, r
);
6247 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6249 bfd_put_32 (abfd
, BLR
, p
);
6254 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6256 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6261 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6263 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6265 p
= restfpr (abfd
, p
, r
);
6266 bfd_put_32 (abfd
, MTLR_R0
, p
);
6270 p
= restfpr (abfd
, p
, 30);
6271 p
= restfpr (abfd
, p
, 31);
6273 bfd_put_32 (abfd
, BLR
, p
);
6278 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6280 p
= savefpr (abfd
, p
, r
);
6281 bfd_put_32 (abfd
, BLR
, p
);
6286 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6288 p
= restfpr (abfd
, p
, r
);
6289 bfd_put_32 (abfd
, BLR
, p
);
6294 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6296 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6298 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6303 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6305 p
= savevr (abfd
, p
, r
);
6306 bfd_put_32 (abfd
, BLR
, p
);
6311 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6313 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6315 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6320 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6322 p
= restvr (abfd
, p
, r
);
6323 bfd_put_32 (abfd
, BLR
, p
);
6327 #define STDU_R1_0R1 0xf8210001
6328 #define ADDI_R1_R1 0x38210000
6330 /* Emit prologue of wrapper preserving regs around a call to
6331 __tls_get_addr_opt. */
6334 tls_get_addr_prologue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6338 bfd_put_32 (obfd
, MFLR_R0
, p
);
6340 bfd_put_32 (obfd
, STD_R0_0R1
+ 16, p
);
6345 for (i
= 4; i
< 12; i
++)
6348 STD_R0_0R1
| i
<< 21 | (-(13 - i
) * 8 & 0xffff), p
);
6351 bfd_put_32 (obfd
, STDU_R1_0R1
| (-128 & 0xffff), p
);
6356 for (i
= 4; i
< 12; i
++)
6359 STD_R0_0R1
| i
<< 21 | (-(12 - i
) * 8 & 0xffff), p
);
6362 bfd_put_32 (obfd
, STDU_R1_0R1
| (-96 & 0xffff), p
);
6368 /* Emit epilogue of wrapper preserving regs around a call to
6369 __tls_get_addr_opt. */
6372 tls_get_addr_epilogue (bfd
*obfd
, bfd_byte
*p
, struct ppc_link_hash_table
*htab
)
6378 for (i
= 4; i
< 12; i
++)
6380 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (128 - (13 - i
) * 8), p
);
6383 bfd_put_32 (obfd
, ADDI_R1_R1
| 128, p
);
6388 for (i
= 4; i
< 12; i
++)
6390 bfd_put_32 (obfd
, LD_R0_0R1
| i
<< 21 | (96 - (12 - i
) * 8), p
);
6393 bfd_put_32 (obfd
, ADDI_R1_R1
| 96, p
);
6396 bfd_put_32 (obfd
, LD_R0_0R1
| 16, p
);
6398 bfd_put_32 (obfd
, MTLR_R0
, p
);
6400 bfd_put_32 (obfd
, BLR
, p
);
6405 /* Called via elf_link_hash_traverse to transfer dynamic linking
6406 information on function code symbol entries to their corresponding
6407 function descriptor symbol entries. Must not be called twice for
6408 any given code symbol. */
6411 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6413 struct bfd_link_info
*info
;
6414 struct ppc_link_hash_table
*htab
;
6415 struct ppc_link_hash_entry
*fh
;
6416 struct ppc_link_hash_entry
*fdh
;
6419 fh
= ppc_elf_hash_entry (h
);
6420 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6426 if (fh
->elf
.root
.root
.string
[0] != '.'
6427 || fh
->elf
.root
.root
.string
[1] == '\0')
6431 htab
= ppc_hash_table (info
);
6435 /* Find the corresponding function descriptor symbol. */
6436 fdh
= lookup_fdh (fh
, htab
);
6438 /* Resolve undefined references to dot-symbols as the value
6439 in the function descriptor, if we have one in a regular object.
6440 This is to satisfy cases like ".quad .foo". Calls to functions
6441 in dynamic objects are handled elsewhere. */
6442 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6443 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6444 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6445 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6446 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6447 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6448 fdh
->elf
.root
.u
.def
.value
,
6449 &fh
->elf
.root
.u
.def
.section
,
6450 &fh
->elf
.root
.u
.def
.value
, false) != (bfd_vma
) -1)
6452 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6453 fh
->elf
.forced_local
= 1;
6454 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6455 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6458 if (!fh
->elf
.dynamic
)
6460 struct plt_entry
*ent
;
6462 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6463 if (ent
->plt
.refcount
> 0)
6467 if (fdh
!= NULL
&& fdh
->fake
)
6468 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6473 /* Create a descriptor as undefined if necessary. */
6475 && !bfd_link_executable (info
)
6476 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6477 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6479 fdh
= make_fdh (info
, fh
);
6484 /* We can't support overriding of symbols on a fake descriptor. */
6487 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6488 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6489 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, true);
6491 /* Transfer dynamic linking information to the function descriptor. */
6494 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6495 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6496 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6497 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6498 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6499 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6500 || fh
->elf
.type
== STT_FUNC
6501 || fh
->elf
.type
== STT_GNU_IFUNC
);
6502 move_plt_plist (fh
, fdh
);
6504 if (!fdh
->elf
.forced_local
6505 && fh
->elf
.dynindx
!= -1)
6506 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6510 /* Now that the info is on the function descriptor, clear the
6511 function code sym info. Any function code syms for which we
6512 don't have a definition in a regular file, we force local.
6513 This prevents a shared library from exporting syms that have
6514 been imported from another library. Function code syms that
6515 are really in the library we must leave global to prevent the
6516 linker dragging in a definition from a static library. */
6517 force_local
= (!fh
->elf
.def_regular
6519 || !fdh
->elf
.def_regular
6520 || fdh
->elf
.forced_local
);
6521 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6526 static const struct sfpr_def_parms save_res_funcs
[] =
6528 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6529 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6530 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6531 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6532 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6533 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6534 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6535 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6536 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6537 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6538 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6539 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6542 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6543 this hook to a) run the edit functions in this file, b) provide
6544 some gcc support functions, and c) transfer dynamic linking
6545 information gathered so far on function code symbol entries, to
6546 their corresponding function descriptor symbol entries. */
6549 ppc64_elf_edit (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6551 struct ppc_link_hash_table
*htab
;
6553 htab
= ppc_hash_table (info
);
6557 /* Call back into the linker, which then runs the edit functions. */
6558 htab
->params
->edit ();
6560 /* Provide any missing _save* and _rest* functions. */
6561 if (htab
->sfpr
!= NULL
)
6565 htab
->sfpr
->size
= 0;
6566 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
6567 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
6569 if (htab
->sfpr
->size
== 0)
6570 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6573 if (bfd_link_relocatable (info
))
6576 if (htab
->elf
.hgot
!= NULL
)
6578 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, true);
6579 /* Make .TOC. defined so as to prevent it being made dynamic.
6580 The wrong value here is fixed later in ppc64_elf_set_toc. */
6581 if (!htab
->elf
.hgot
->def_regular
6582 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
6584 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
6585 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
6586 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6587 htab
->elf
.hgot
->def_regular
= 1;
6588 htab
->elf
.hgot
->root
.linker_def
= 1;
6590 htab
->elf
.hgot
->type
= STT_OBJECT
;
6591 htab
->elf
.hgot
->other
6592 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
6598 /* Return true if we have dynamic relocs against H or any of its weak
6599 aliases, that apply to read-only sections. Cannot be used after
6600 size_dynamic_sections. */
6603 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6605 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
6608 if (_bfd_elf_readonly_dynrelocs (&eh
->elf
))
6610 eh
= ppc_elf_hash_entry (eh
->elf
.u
.alias
);
6612 while (eh
!= NULL
&& &eh
->elf
!= h
);
6617 /* Return whether EH has pc-relative dynamic relocs. */
6620 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
6622 struct ppc_dyn_relocs
*p
;
6624 for (p
= (struct ppc_dyn_relocs
*) eh
->elf
.dyn_relocs
; p
!= NULL
; p
= p
->next
)
6625 if (p
->pc_count
!= 0)
6630 /* Return true if a global entry stub will be created for H. Valid
6631 for ELFv2 before plt entries have been allocated. */
6634 global_entry_stub (struct elf_link_hash_entry
*h
)
6636 struct plt_entry
*pent
;
6638 if (!h
->pointer_equality_needed
6642 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
6643 if (pent
->plt
.refcount
> 0
6644 && pent
->addend
== 0)
6650 /* Adjust a symbol defined by a dynamic object and referenced by a
6651 regular object. The current definition is in some section of the
6652 dynamic object, but we're not including those sections. We have to
6653 change the definition to something the rest of the link can
6657 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6658 struct elf_link_hash_entry
*h
)
6660 struct ppc_link_hash_table
*htab
;
6663 htab
= ppc_hash_table (info
);
6667 /* Deal with function syms. */
6668 if (h
->type
== STT_FUNC
6669 || h
->type
== STT_GNU_IFUNC
6672 bool local
= (ppc_elf_hash_entry (h
)->save_res
6673 || SYMBOL_CALLS_LOCAL (info
, h
)
6674 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6675 /* Discard dyn_relocs when non-pic if we've decided that a
6676 function symbol is local and not an ifunc. We keep dynamic
6677 relocs for ifuncs when local rather than always emitting a
6678 plt call stub for them and defining the symbol on the call
6679 stub. We can't do that for ELFv1 anyway (a function symbol
6680 is defined on a descriptor, not code) and it can be faster at
6681 run-time due to not needing to bounce through a stub. The
6682 dyn_relocs for ifuncs will be applied even in a static
6684 if (!bfd_link_pic (info
)
6685 && h
->type
!= STT_GNU_IFUNC
6687 h
->dyn_relocs
= NULL
;
6689 /* Clear procedure linkage table information for any symbol that
6690 won't need a .plt entry. */
6691 struct plt_entry
*ent
;
6692 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6693 if (ent
->plt
.refcount
> 0)
6696 || (h
->type
!= STT_GNU_IFUNC
6698 && (htab
->can_convert_all_inline_plt
6699 || (ppc_elf_hash_entry (h
)->tls_mask
6700 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6702 h
->plt
.plist
= NULL
;
6704 h
->pointer_equality_needed
= 0;
6706 else if (abiversion (info
->output_bfd
) >= 2)
6708 /* Taking a function's address in a read/write section
6709 doesn't require us to define the function symbol in the
6710 executable on a global entry stub. A dynamic reloc can
6711 be used instead. The reason we prefer a few more dynamic
6712 relocs is that calling via a global entry stub costs a
6713 few more instructions, and pointer_equality_needed causes
6714 extra work in ld.so when resolving these symbols. */
6715 if (global_entry_stub (h
))
6717 if (!_bfd_elf_readonly_dynrelocs (h
))
6719 h
->pointer_equality_needed
= 0;
6720 /* If we haven't seen a branch reloc and the symbol
6721 isn't an ifunc then we don't need a plt entry. */
6723 h
->plt
.plist
= NULL
;
6725 else if (!bfd_link_pic (info
))
6726 /* We are going to be defining the function symbol on the
6727 plt stub, so no dyn_relocs needed when non-pic. */
6728 h
->dyn_relocs
= NULL
;
6731 /* ELFv2 function symbols can't have copy relocs. */
6734 else if (!h
->needs_plt
6735 && !_bfd_elf_readonly_dynrelocs (h
))
6737 /* If we haven't seen a branch reloc and the symbol isn't an
6738 ifunc then we don't need a plt entry. */
6739 h
->plt
.plist
= NULL
;
6740 h
->pointer_equality_needed
= 0;
6745 h
->plt
.plist
= NULL
;
6747 /* If this is a weak symbol, and there is a real definition, the
6748 processor independent code will have arranged for us to see the
6749 real definition first, and we can just use the same value. */
6750 if (h
->is_weakalias
)
6752 struct elf_link_hash_entry
*def
= weakdef (h
);
6753 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6754 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6755 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6756 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6757 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6758 h
->dyn_relocs
= NULL
;
6762 /* If we are creating a shared library, we must presume that the
6763 only references to the symbol are via the global offset table.
6764 For such cases we need not do anything here; the relocations will
6765 be handled correctly by relocate_section. */
6766 if (!bfd_link_executable (info
))
6769 /* If there are no references to this symbol that do not use the
6770 GOT, we don't need to generate a copy reloc. */
6771 if (!h
->non_got_ref
)
6774 /* Don't generate a copy reloc for symbols defined in the executable. */
6775 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6777 /* If -z nocopyreloc was given, don't generate them either. */
6778 || info
->nocopyreloc
6780 /* If we don't find any dynamic relocs in read-only sections, then
6781 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6782 || (ELIMINATE_COPY_RELOCS
6784 && !alias_readonly_dynrelocs (h
))
6786 /* Protected variables do not work with .dynbss. The copy in
6787 .dynbss won't be used by the shared library with the protected
6788 definition for the variable. Text relocations are preferable
6789 to an incorrect program. */
6790 || h
->protected_def
)
6793 if (h
->type
== STT_FUNC
6794 || h
->type
== STT_GNU_IFUNC
)
6796 /* .dynbss copies of function symbols only work if we have
6797 ELFv1 dot-symbols. ELFv1 compilers since 2004 default to not
6798 use dot-symbols and set the function symbol size to the text
6799 size of the function rather than the size of the descriptor.
6800 That's wrong for copying a descriptor. */
6801 if (ppc_elf_hash_entry (h
)->oh
== NULL
6802 || !(h
->size
== 24 || h
->size
== 16))
6805 /* We should never get here, but unfortunately there are old
6806 versions of gcc (circa gcc-3.2) that improperly for the
6807 ELFv1 ABI put initialized function pointers, vtable refs and
6808 suchlike in read-only sections. Allow them to proceed, but
6809 warn that this might break at runtime. */
6810 info
->callbacks
->einfo
6811 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6812 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6813 h
->root
.root
.string
);
6816 /* This is a reference to a symbol defined by a dynamic object which
6817 is not a function. */
6819 /* We must allocate the symbol in our .dynbss section, which will
6820 become part of the .bss section of the executable. There will be
6821 an entry for this symbol in the .dynsym section. The dynamic
6822 object will contain position independent code, so all references
6823 from the dynamic object to this symbol will go through the global
6824 offset table. The dynamic linker will use the .dynsym entry to
6825 determine the address it must put in the global offset table, so
6826 both the dynamic object and the regular object will refer to the
6827 same memory location for the variable. */
6828 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6830 s
= htab
->elf
.sdynrelro
;
6831 srel
= htab
->elf
.sreldynrelro
;
6835 s
= htab
->elf
.sdynbss
;
6836 srel
= htab
->elf
.srelbss
;
6838 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6840 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6841 linker to copy the initial value out of the dynamic object
6842 and into the runtime process image. */
6843 srel
->size
+= sizeof (Elf64_External_Rela
);
6847 /* We no longer want dyn_relocs. */
6848 h
->dyn_relocs
= NULL
;
6849 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6852 /* If given a function descriptor symbol, hide both the function code
6853 sym and the descriptor. */
6855 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6856 struct elf_link_hash_entry
*h
,
6859 struct ppc_link_hash_entry
*eh
;
6860 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6862 if (ppc_hash_table (info
) == NULL
)
6865 eh
= ppc_elf_hash_entry (h
);
6866 if (eh
->is_func_descriptor
)
6868 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6873 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6876 /* We aren't supposed to use alloca in BFD because on
6877 systems which do not have alloca the version in libiberty
6878 calls xmalloc, which might cause the program to crash
6879 when it runs out of memory. This function doesn't have a
6880 return status, so there's no way to gracefully return an
6881 error. So cheat. We know that string[-1] can be safely
6882 accessed; It's either a string in an ELF string table,
6883 or allocated in an objalloc structure. */
6885 p
= eh
->elf
.root
.root
.string
- 1;
6888 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6892 /* Unfortunately, if it so happens that the string we were
6893 looking for was allocated immediately before this string,
6894 then we overwrote the string terminator. That's the only
6895 reason the lookup should fail. */
6898 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6899 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6901 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6902 fh
= ppc_elf_hash_entry (elf_link_hash_lookup (htab
, p
, false,
6912 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6917 get_sym_h (struct elf_link_hash_entry
**hp
,
6918 Elf_Internal_Sym
**symp
,
6920 unsigned char **tls_maskp
,
6921 Elf_Internal_Sym
**locsymsp
,
6922 unsigned long r_symndx
,
6925 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6927 if (r_symndx
>= symtab_hdr
->sh_info
)
6929 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6930 struct elf_link_hash_entry
*h
;
6932 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6933 h
= elf_follow_link (h
);
6941 if (symsecp
!= NULL
)
6943 asection
*symsec
= NULL
;
6944 if (h
->root
.type
== bfd_link_hash_defined
6945 || h
->root
.type
== bfd_link_hash_defweak
)
6946 symsec
= h
->root
.u
.def
.section
;
6950 if (tls_maskp
!= NULL
)
6951 *tls_maskp
= &ppc_elf_hash_entry (h
)->tls_mask
;
6955 Elf_Internal_Sym
*sym
;
6956 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6958 if (locsyms
== NULL
)
6960 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6961 if (locsyms
== NULL
)
6962 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6963 symtab_hdr
->sh_info
,
6964 0, NULL
, NULL
, NULL
);
6965 if (locsyms
== NULL
)
6967 *locsymsp
= locsyms
;
6969 sym
= locsyms
+ r_symndx
;
6977 if (symsecp
!= NULL
)
6978 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6980 if (tls_maskp
!= NULL
)
6982 struct got_entry
**lgot_ents
;
6983 unsigned char *tls_mask
;
6986 lgot_ents
= elf_local_got_ents (ibfd
);
6987 if (lgot_ents
!= NULL
)
6989 struct plt_entry
**local_plt
= (struct plt_entry
**)
6990 (lgot_ents
+ symtab_hdr
->sh_info
);
6991 unsigned char *lgot_masks
= (unsigned char *)
6992 (local_plt
+ symtab_hdr
->sh_info
);
6993 tls_mask
= &lgot_masks
[r_symndx
];
6995 *tls_maskp
= tls_mask
;
7001 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7002 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7003 type suitable for optimization, and 1 otherwise. */
7006 get_tls_mask (unsigned char **tls_maskp
,
7007 unsigned long *toc_symndx
,
7008 bfd_vma
*toc_addend
,
7009 Elf_Internal_Sym
**locsymsp
,
7010 const Elf_Internal_Rela
*rel
,
7013 unsigned long r_symndx
;
7015 struct elf_link_hash_entry
*h
;
7016 Elf_Internal_Sym
*sym
;
7020 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7021 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7024 if ((*tls_maskp
!= NULL
7025 && (**tls_maskp
& TLS_TLS
) != 0
7026 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
7028 || ppc64_elf_section_data (sec
) == NULL
7029 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7032 /* Look inside a TOC section too. */
7035 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7036 off
= h
->root
.u
.def
.value
;
7039 off
= sym
->st_value
;
7040 off
+= rel
->r_addend
;
7041 BFD_ASSERT (off
% 8 == 0);
7042 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7043 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7044 if (toc_symndx
!= NULL
)
7045 *toc_symndx
= r_symndx
;
7046 if (toc_addend
!= NULL
)
7047 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7048 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7050 if ((h
== NULL
|| is_static_defined (h
))
7051 && (next_r
== -1 || next_r
== -2))
7056 /* Find (or create) an entry in the tocsave hash table. */
7058 static struct tocsave_entry
*
7059 tocsave_find (struct ppc_link_hash_table
*htab
,
7060 enum insert_option insert
,
7061 Elf_Internal_Sym
**local_syms
,
7062 const Elf_Internal_Rela
*irela
,
7065 unsigned long r_indx
;
7066 struct elf_link_hash_entry
*h
;
7067 Elf_Internal_Sym
*sym
;
7068 struct tocsave_entry ent
, *p
;
7070 struct tocsave_entry
**slot
;
7072 r_indx
= ELF64_R_SYM (irela
->r_info
);
7073 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7075 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7078 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7083 ent
.offset
= h
->root
.u
.def
.value
;
7085 ent
.offset
= sym
->st_value
;
7086 ent
.offset
+= irela
->r_addend
;
7088 hash
= tocsave_htab_hash (&ent
);
7089 slot
= ((struct tocsave_entry
**)
7090 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7096 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7105 /* Adjust all global syms defined in opd sections. In gcc generated
7106 code for the old ABI, these will already have been done. */
7109 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7111 struct ppc_link_hash_entry
*eh
;
7113 struct _opd_sec_data
*opd
;
7115 if (h
->root
.type
== bfd_link_hash_indirect
)
7118 if (h
->root
.type
!= bfd_link_hash_defined
7119 && h
->root
.type
!= bfd_link_hash_defweak
)
7122 eh
= ppc_elf_hash_entry (h
);
7123 if (eh
->adjust_done
)
7126 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7127 opd
= get_opd_info (sym_sec
);
7128 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7130 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7133 /* This entry has been deleted. */
7134 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7137 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7138 if (discarded_section (dsec
))
7140 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7144 eh
->elf
.root
.u
.def
.value
= 0;
7145 eh
->elf
.root
.u
.def
.section
= dsec
;
7148 eh
->elf
.root
.u
.def
.value
+= adjust
;
7149 eh
->adjust_done
= 1;
7154 /* Handles decrementing dynamic reloc counts for the reloc specified by
7155 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7156 have already been determined. */
7159 dec_dynrel_count (const Elf_Internal_Rela
*rel
,
7161 struct bfd_link_info
*info
,
7162 Elf_Internal_Sym
**local_syms
,
7163 struct elf_link_hash_entry
*h
,
7164 Elf_Internal_Sym
*sym
)
7166 enum elf_ppc64_reloc_type r_type
;
7167 asection
*sym_sec
= NULL
;
7169 /* Can this reloc be dynamic? This switch, and later tests here
7170 should be kept in sync with the code in check_relocs. */
7171 r_type
= ELF64_R_TYPE (rel
->r_info
);
7178 case R_PPC64_TOC16_DS
:
7179 case R_PPC64_TOC16_LO
:
7180 case R_PPC64_TOC16_HI
:
7181 case R_PPC64_TOC16_HA
:
7182 case R_PPC64_TOC16_LO_DS
:
7187 case R_PPC64_TPREL16
:
7188 case R_PPC64_TPREL16_LO
:
7189 case R_PPC64_TPREL16_HI
:
7190 case R_PPC64_TPREL16_HA
:
7191 case R_PPC64_TPREL16_DS
:
7192 case R_PPC64_TPREL16_LO_DS
:
7193 case R_PPC64_TPREL16_HIGH
:
7194 case R_PPC64_TPREL16_HIGHA
:
7195 case R_PPC64_TPREL16_HIGHER
:
7196 case R_PPC64_TPREL16_HIGHERA
:
7197 case R_PPC64_TPREL16_HIGHEST
:
7198 case R_PPC64_TPREL16_HIGHESTA
:
7199 case R_PPC64_TPREL64
:
7200 case R_PPC64_TPREL34
:
7201 case R_PPC64_DTPMOD64
:
7202 case R_PPC64_DTPREL64
:
7203 case R_PPC64_ADDR64
:
7207 case R_PPC64_ADDR14
:
7208 case R_PPC64_ADDR14_BRNTAKEN
:
7209 case R_PPC64_ADDR14_BRTAKEN
:
7210 case R_PPC64_ADDR16
:
7211 case R_PPC64_ADDR16_DS
:
7212 case R_PPC64_ADDR16_HA
:
7213 case R_PPC64_ADDR16_HI
:
7214 case R_PPC64_ADDR16_HIGH
:
7215 case R_PPC64_ADDR16_HIGHA
:
7216 case R_PPC64_ADDR16_HIGHER
:
7217 case R_PPC64_ADDR16_HIGHERA
:
7218 case R_PPC64_ADDR16_HIGHEST
:
7219 case R_PPC64_ADDR16_HIGHESTA
:
7220 case R_PPC64_ADDR16_LO
:
7221 case R_PPC64_ADDR16_LO_DS
:
7222 case R_PPC64_ADDR24
:
7223 case R_PPC64_ADDR32
:
7224 case R_PPC64_UADDR16
:
7225 case R_PPC64_UADDR32
:
7226 case R_PPC64_UADDR64
:
7229 case R_PPC64_D34_LO
:
7230 case R_PPC64_D34_HI30
:
7231 case R_PPC64_D34_HA30
:
7232 case R_PPC64_ADDR16_HIGHER34
:
7233 case R_PPC64_ADDR16_HIGHERA34
:
7234 case R_PPC64_ADDR16_HIGHEST34
:
7235 case R_PPC64_ADDR16_HIGHESTA34
:
7240 if (local_syms
!= NULL
)
7242 unsigned long r_symndx
;
7243 bfd
*ibfd
= sec
->owner
;
7245 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7246 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7251 && (h
->root
.type
== bfd_link_hash_defweak
7252 || !h
->def_regular
))
7254 && !bfd_link_executable (info
)
7255 && !SYMBOLIC_BIND (info
, h
))
7256 || (bfd_link_pic (info
)
7257 && must_be_dyn_reloc (info
, r_type
))
7258 || (!bfd_link_pic (info
)
7260 ? h
->type
== STT_GNU_IFUNC
7261 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
7268 struct ppc_dyn_relocs
*p
;
7269 struct ppc_dyn_relocs
**pp
;
7270 pp
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
7272 /* elf_gc_sweep may have already removed all dyn relocs associated
7273 with local syms for a given section. Also, symbol flags are
7274 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7275 report a dynreloc miscount. */
7276 if (*pp
== NULL
&& info
->gc_sections
)
7279 while ((p
= *pp
) != NULL
)
7283 if (!must_be_dyn_reloc (info
, r_type
))
7285 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
7286 && rel
->r_offset
% 2 == 0
7287 && sec
->alignment_power
!= 0
7289 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
7290 || (h
->type
!= STT_GNU_IFUNC
7291 && SYMBOL_REFERENCES_LOCAL (info
, h
))))
7303 struct ppc_local_dyn_relocs
*p
;
7304 struct ppc_local_dyn_relocs
**pp
;
7308 if (local_syms
== NULL
)
7309 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7310 if (sym_sec
== NULL
)
7313 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7314 pp
= (struct ppc_local_dyn_relocs
**) vpp
;
7316 if (*pp
== NULL
&& info
->gc_sections
)
7319 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7320 while ((p
= *pp
) != NULL
)
7322 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7324 if ((r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
7325 && rel
->r_offset
% 2 == 0
7326 && sec
->alignment_power
!= 0
7328 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
7340 /* xgettext:c-format */
7341 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7343 bfd_set_error (bfd_error_bad_value
);
7347 /* Remove unused Official Procedure Descriptor entries. Currently we
7348 only remove those associated with functions in discarded link-once
7349 sections, or weakly defined functions that have been overridden. It
7350 would be possible to remove many more entries for statically linked
7354 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7357 bool some_edited
= false;
7358 asection
*need_pad
= NULL
;
7359 struct ppc_link_hash_table
*htab
;
7361 htab
= ppc_hash_table (info
);
7365 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7368 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7369 Elf_Internal_Shdr
*symtab_hdr
;
7370 Elf_Internal_Sym
*local_syms
;
7371 struct _opd_sec_data
*opd
;
7372 bool need_edit
, add_aux_fields
, broken
;
7373 bfd_size_type cnt_16b
= 0;
7375 if (!is_ppc64_elf (ibfd
))
7378 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7379 if (sec
== NULL
|| sec
->size
== 0)
7382 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7385 if (sec
->output_section
== bfd_abs_section_ptr
)
7388 /* Look through the section relocs. */
7389 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7393 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7395 /* Read the relocations. */
7396 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7398 if (relstart
== NULL
)
7401 /* First run through the relocs to check they are sane, and to
7402 determine whether we need to edit this opd section. */
7406 relend
= relstart
+ sec
->reloc_count
;
7407 for (rel
= relstart
; rel
< relend
; )
7409 enum elf_ppc64_reloc_type r_type
;
7410 unsigned long r_symndx
;
7412 struct elf_link_hash_entry
*h
;
7413 Elf_Internal_Sym
*sym
;
7416 /* .opd contains an array of 16 or 24 byte entries. We're
7417 only interested in the reloc pointing to a function entry
7419 offset
= rel
->r_offset
;
7420 if (rel
+ 1 == relend
7421 || rel
[1].r_offset
!= offset
+ 8)
7423 /* If someone messes with .opd alignment then after a
7424 "ld -r" we might have padding in the middle of .opd.
7425 Also, there's nothing to prevent someone putting
7426 something silly in .opd with the assembler. No .opd
7427 optimization for them! */
7430 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7435 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7436 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7439 /* xgettext:c-format */
7440 (_("%pB: unexpected reloc type %u in .opd section"),
7446 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7447 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7451 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7453 const char *sym_name
;
7455 sym_name
= h
->root
.root
.string
;
7457 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7461 /* xgettext:c-format */
7462 (_("%pB: undefined sym `%s' in .opd section"),
7468 /* opd entries are always for functions defined in the
7469 current input bfd. If the symbol isn't defined in the
7470 input bfd, then we won't be using the function in this
7471 bfd; It must be defined in a linkonce section in another
7472 bfd, or is weak. It's also possible that we are
7473 discarding the function due to a linker script /DISCARD/,
7474 which we test for via the output_section. */
7475 if (sym_sec
->owner
!= ibfd
7476 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7480 if (rel
+ 1 == relend
7481 || (rel
+ 2 < relend
7482 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7487 if (sec
->size
== offset
+ 24)
7492 if (sec
->size
== offset
+ 16)
7499 else if (rel
+ 1 < relend
7500 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7501 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7503 if (rel
[0].r_offset
== offset
+ 16)
7505 else if (rel
[0].r_offset
!= offset
+ 24)
7512 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7514 if (!broken
&& (need_edit
|| add_aux_fields
))
7516 Elf_Internal_Rela
*write_rel
;
7517 Elf_Internal_Shdr
*rel_hdr
;
7518 bfd_byte
*rptr
, *wptr
;
7519 bfd_byte
*new_contents
;
7522 new_contents
= NULL
;
7523 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7524 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7525 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7526 if (opd
->adjust
== NULL
)
7529 /* This seems a waste of time as input .opd sections are all
7530 zeros as generated by gcc, but I suppose there's no reason
7531 this will always be so. We might start putting something in
7532 the third word of .opd entries. */
7533 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7536 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7540 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7542 if (elf_section_data (sec
)->relocs
!= relstart
)
7546 sec
->contents
= loc
;
7547 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7550 elf_section_data (sec
)->relocs
= relstart
;
7552 new_contents
= sec
->contents
;
7555 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7556 if (new_contents
== NULL
)
7560 wptr
= new_contents
;
7561 rptr
= sec
->contents
;
7562 write_rel
= relstart
;
7563 for (rel
= relstart
; rel
< relend
; )
7565 unsigned long r_symndx
;
7567 struct elf_link_hash_entry
*h
;
7568 struct ppc_link_hash_entry
*fdh
= NULL
;
7569 Elf_Internal_Sym
*sym
;
7571 Elf_Internal_Rela
*next_rel
;
7574 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7575 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7580 if (next_rel
+ 1 == relend
7581 || (next_rel
+ 2 < relend
7582 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7585 /* See if the .opd entry is full 24 byte or
7586 16 byte (with fd_aux entry overlapped with next
7589 if (next_rel
== relend
)
7591 if (sec
->size
== rel
->r_offset
+ 16)
7594 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7598 && h
->root
.root
.string
[0] == '.')
7600 fdh
= ppc_elf_hash_entry (h
)->oh
;
7603 fdh
= ppc_follow_link (fdh
);
7604 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
7605 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7610 skip
= (sym_sec
->owner
!= ibfd
7611 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7614 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7616 /* Arrange for the function descriptor sym
7618 fdh
->elf
.root
.u
.def
.value
= 0;
7619 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7621 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7623 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7628 if (!dec_dynrel_count (rel
, sec
, info
,
7632 if (++rel
== next_rel
)
7635 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7636 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7643 /* We'll be keeping this opd entry. */
7648 /* Redefine the function descriptor symbol to
7649 this location in the opd section. It is
7650 necessary to update the value here rather
7651 than using an array of adjustments as we do
7652 for local symbols, because various places
7653 in the generic ELF code use the value
7654 stored in u.def.value. */
7655 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7656 fdh
->adjust_done
= 1;
7659 /* Local syms are a bit tricky. We could
7660 tweak them as they can be cached, but
7661 we'd need to look through the local syms
7662 for the function descriptor sym which we
7663 don't have at the moment. So keep an
7664 array of adjustments. */
7665 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
7666 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
7669 memcpy (wptr
, rptr
, opd_ent_size
);
7670 wptr
+= opd_ent_size
;
7671 if (add_aux_fields
&& opd_ent_size
== 16)
7673 memset (wptr
, '\0', 8);
7677 /* We need to adjust any reloc offsets to point to the
7679 for ( ; rel
!= next_rel
; ++rel
)
7681 rel
->r_offset
+= adjust
;
7682 if (write_rel
!= rel
)
7683 memcpy (write_rel
, rel
, sizeof (*rel
));
7688 rptr
+= opd_ent_size
;
7691 sec
->size
= wptr
- new_contents
;
7692 sec
->reloc_count
= write_rel
- relstart
;
7695 free (sec
->contents
);
7696 sec
->contents
= new_contents
;
7699 /* Fudge the header size too, as this is used later in
7700 elf_bfd_final_link if we are emitting relocs. */
7701 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7702 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7705 else if (elf_section_data (sec
)->relocs
!= relstart
)
7708 if (local_syms
!= NULL
7709 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7711 if (!info
->keep_memory
)
7714 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7719 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7721 /* If we are doing a final link and the last .opd entry is just 16 byte
7722 long, add a 8 byte padding after it. */
7723 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7727 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7729 BFD_ASSERT (need_pad
->size
> 0);
7731 p
= bfd_malloc (need_pad
->size
+ 8);
7735 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7736 p
, 0, need_pad
->size
))
7739 need_pad
->contents
= p
;
7740 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7744 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7748 need_pad
->contents
= p
;
7751 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7752 need_pad
->size
+= 8;
7758 /* Analyze inline PLT call relocations to see whether calls to locally
7759 defined functions can be converted to direct calls. */
7762 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7764 struct ppc_link_hash_table
*htab
;
7767 bfd_vma low_vma
, high_vma
, limit
;
7769 htab
= ppc_hash_table (info
);
7773 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7774 reduced somewhat to cater for possible stubs that might be added
7775 between the call and its destination. */
7776 if (htab
->params
->group_size
< 0)
7778 limit
= -htab
->params
->group_size
;
7784 limit
= htab
->params
->group_size
;
7791 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7792 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7794 if (low_vma
> sec
->vma
)
7796 if (high_vma
< sec
->vma
+ sec
->size
)
7797 high_vma
= sec
->vma
+ sec
->size
;
7800 /* If a "bl" can reach anywhere in local code sections, then we can
7801 convert all inline PLT sequences to direct calls when the symbol
7803 if (high_vma
- low_vma
< limit
)
7805 htab
->can_convert_all_inline_plt
= 1;
7809 /* Otherwise, go looking through relocs for cases where a direct
7810 call won't reach. Mark the symbol on any such reloc to disable
7811 the optimization and keep the PLT entry as it seems likely that
7812 this will be better than creating trampolines. Note that this
7813 will disable the optimization for all inline PLT calls to a
7814 particular symbol, not just those that won't reach. The
7815 difficulty in doing a more precise optimization is that the
7816 linker needs to make a decision depending on whether a
7817 particular R_PPC64_PLTCALL insn can be turned into a direct
7818 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7819 the sequence, and there is nothing that ties those relocs
7820 together except their symbol. */
7822 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7824 Elf_Internal_Shdr
*symtab_hdr
;
7825 Elf_Internal_Sym
*local_syms
;
7827 if (!is_ppc64_elf (ibfd
))
7831 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7833 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7834 if (ppc64_elf_section_data (sec
)->has_pltcall
7835 && !bfd_is_abs_section (sec
->output_section
))
7837 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7839 /* Read the relocations. */
7840 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7842 if (relstart
== NULL
)
7845 relend
= relstart
+ sec
->reloc_count
;
7846 for (rel
= relstart
; rel
< relend
; rel
++)
7848 enum elf_ppc64_reloc_type r_type
;
7849 unsigned long r_symndx
;
7851 struct elf_link_hash_entry
*h
;
7852 Elf_Internal_Sym
*sym
;
7853 unsigned char *tls_maskp
;
7855 r_type
= ELF64_R_TYPE (rel
->r_info
);
7856 if (r_type
!= R_PPC64_PLTCALL
7857 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
7860 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7861 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7864 if (elf_section_data (sec
)->relocs
!= relstart
)
7866 if (symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7871 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7875 to
= h
->root
.u
.def
.value
;
7878 to
+= (rel
->r_addend
7879 + sym_sec
->output_offset
7880 + sym_sec
->output_section
->vma
);
7881 from
= (rel
->r_offset
7882 + sec
->output_offset
7883 + sec
->output_section
->vma
);
7884 if (to
- from
+ limit
< 2 * limit
7885 && !(r_type
== R_PPC64_PLTCALL_NOTOC
7886 && (((h
? h
->other
: sym
->st_other
)
7887 & STO_PPC64_LOCAL_MASK
)
7888 > 1 << STO_PPC64_LOCAL_BIT
)))
7889 *tls_maskp
&= ~PLT_KEEP
;
7892 if (elf_section_data (sec
)->relocs
!= relstart
)
7896 if (local_syms
!= NULL
7897 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7899 if (!info
->keep_memory
)
7902 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7909 /* Set htab->tls_get_addr and various other info specific to TLS.
7910 This needs to run before dynamic symbols are processed in
7911 bfd_elf_size_dynamic_sections. */
7914 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7916 struct ppc_link_hash_table
*htab
;
7917 struct elf_link_hash_entry
*tga
, *tga_fd
, *desc
, *desc_fd
;
7919 htab
= ppc_hash_table (info
);
7923 /* Move dynamic linking info to the function descriptor sym. */
7924 if (htab
->need_func_desc_adj
)
7926 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7927 htab
->need_func_desc_adj
= 0;
7930 if (abiversion (info
->output_bfd
) == 1)
7933 if (htab
->params
->no_multi_toc
)
7934 htab
->do_multi_toc
= 0;
7935 else if (!htab
->do_multi_toc
)
7936 htab
->params
->no_multi_toc
= 1;
7938 /* Default to --no-plt-localentry, as this option can cause problems
7939 with symbol interposition. For example, glibc libpthread.so and
7940 libc.so duplicate many pthread symbols, with a fallback
7941 implementation in libc.so. In some cases the fallback does more
7942 work than the pthread implementation. __pthread_condattr_destroy
7943 is one such symbol: the libpthread.so implementation is
7944 localentry:0 while the libc.so implementation is localentry:8.
7945 An app that "cleverly" uses dlopen to only load necessary
7946 libraries at runtime may omit loading libpthread.so when not
7947 running multi-threaded, which then results in the libc.so
7948 fallback symbols being used and ld.so complaining. Now there
7949 are workarounds in ld (see non_zero_localentry) to detect the
7950 pthread situation, but that may not be the only case where
7951 --plt-localentry can cause trouble. */
7952 if (htab
->params
->plt_localentry0
< 0)
7953 htab
->params
->plt_localentry0
= 0;
7954 if (htab
->params
->plt_localentry0
&& htab
->has_power10_relocs
)
7956 /* The issue is that __glink_PLTresolve saves r2, which is done
7957 because glibc ld.so _dl_runtime_resolve restores r2 to support
7958 a glibc plt call optimisation where global entry code is
7959 skipped on calls that resolve to the same binary. The
7960 __glink_PLTresolve save of r2 is incompatible with code
7961 making tail calls, because the tail call might go via the
7962 resolver and thus overwrite the proper saved r2. */
7963 _bfd_error_handler (_("warning: --plt-localentry is incompatible with "
7964 "power10 pc-relative code"));
7965 htab
->params
->plt_localentry0
= 0;
7967 if (htab
->params
->plt_localentry0
7968 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7969 false, false, false) == NULL
)
7971 (_("warning: --plt-localentry is especially dangerous without "
7972 "ld.so support to detect ABI violations"));
7974 tga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7975 false, false, true);
7976 htab
->tls_get_addr
= ppc_elf_hash_entry (tga
);
7977 tga_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7978 false, false, true);
7979 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (tga_fd
);
7981 desc
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_desc",
7982 false, false, true);
7983 htab
->tga_desc
= ppc_elf_hash_entry (desc
);
7984 desc_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_desc",
7985 false, false, true);
7986 htab
->tga_desc_fd
= ppc_elf_hash_entry (desc_fd
);
7988 if (htab
->params
->tls_get_addr_opt
)
7990 struct elf_link_hash_entry
*opt
, *opt_fd
;
7992 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7993 false, false, true);
7994 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7995 false, false, true);
7997 && (opt_fd
->root
.type
== bfd_link_hash_defined
7998 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8000 /* If glibc supports an optimized __tls_get_addr call stub,
8001 signalled by the presence of __tls_get_addr_opt, and we'll
8002 be calling __tls_get_addr via a plt call stub, then
8003 make __tls_get_addr point to __tls_get_addr_opt. */
8004 if (!(htab
->elf
.dynamic_sections_created
8006 && (tga_fd
->type
== STT_FUNC
8007 || tga_fd
->needs_plt
)
8008 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8009 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
))))
8011 if (!(htab
->elf
.dynamic_sections_created
8013 && (desc_fd
->type
== STT_FUNC
8014 || desc_fd
->needs_plt
)
8015 && !(SYMBOL_CALLS_LOCAL (info
, desc_fd
)
8016 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, desc_fd
))))
8019 if (tga_fd
!= NULL
|| desc_fd
!= NULL
)
8021 struct plt_entry
*ent
= NULL
;
8024 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8025 if (ent
->plt
.refcount
> 0)
8027 if (ent
== NULL
&& desc_fd
!= NULL
)
8028 for (ent
= desc_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8029 if (ent
->plt
.refcount
> 0)
8035 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8036 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8037 tga_fd
->root
.u
.i
.warning
= NULL
;
8038 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8040 if (desc_fd
!= NULL
)
8042 desc_fd
->root
.type
= bfd_link_hash_indirect
;
8043 desc_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8044 desc_fd
->root
.u
.i
.warning
= NULL
;
8045 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, desc_fd
);
8048 if (opt_fd
->dynindx
!= -1)
8050 /* Use __tls_get_addr_opt in dynamic relocations. */
8051 opt_fd
->dynindx
= -1;
8052 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8053 opt_fd
->dynstr_index
);
8054 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8059 htab
->tls_get_addr_fd
= ppc_elf_hash_entry (opt_fd
);
8060 tga
= elf_hash_entry (htab
->tls_get_addr
);
8061 if (opt
!= NULL
&& tga
!= NULL
)
8063 tga
->root
.type
= bfd_link_hash_indirect
;
8064 tga
->root
.u
.i
.link
= &opt
->root
;
8065 tga
->root
.u
.i
.warning
= NULL
;
8066 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8068 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8070 htab
->tls_get_addr
= ppc_elf_hash_entry (opt
);
8072 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8073 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8074 if (htab
->tls_get_addr
!= NULL
)
8076 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8077 htab
->tls_get_addr
->is_func
= 1;
8080 if (desc_fd
!= NULL
)
8082 htab
->tga_desc_fd
= ppc_elf_hash_entry (opt_fd
);
8083 if (opt
!= NULL
&& desc
!= NULL
)
8085 desc
->root
.type
= bfd_link_hash_indirect
;
8086 desc
->root
.u
.i
.link
= &opt
->root
;
8087 desc
->root
.u
.i
.warning
= NULL
;
8088 ppc64_elf_copy_indirect_symbol (info
, opt
, desc
);
8090 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8091 desc
->forced_local
);
8092 htab
->tga_desc
= ppc_elf_hash_entry (opt
);
8094 htab
->tga_desc_fd
->oh
= htab
->tga_desc
;
8095 htab
->tga_desc_fd
->is_func_descriptor
= 1;
8096 if (htab
->tga_desc
!= NULL
)
8098 htab
->tga_desc
->oh
= htab
->tga_desc_fd
;
8099 htab
->tga_desc
->is_func
= 1;
8105 else if (htab
->params
->tls_get_addr_opt
< 0)
8106 htab
->params
->tls_get_addr_opt
= 0;
8109 if (htab
->tga_desc_fd
!= NULL
8110 && htab
->params
->tls_get_addr_opt
8111 && htab
->params
->no_tls_get_addr_regsave
== -1)
8112 htab
->params
->no_tls_get_addr_regsave
= 0;
8117 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8118 any of HASH1, HASH2, HASH3, or HASH4. */
8121 branch_reloc_hash_match (bfd
*ibfd
,
8122 Elf_Internal_Rela
*rel
,
8123 struct ppc_link_hash_entry
*hash1
,
8124 struct ppc_link_hash_entry
*hash2
,
8125 struct ppc_link_hash_entry
*hash3
,
8126 struct ppc_link_hash_entry
*hash4
)
8128 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8129 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8130 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8132 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8134 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8135 struct elf_link_hash_entry
*h
;
8137 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8138 h
= elf_follow_link (h
);
8139 if (h
== elf_hash_entry (hash1
)
8140 || h
== elf_hash_entry (hash2
)
8141 || h
== elf_hash_entry (hash3
)
8142 || h
== elf_hash_entry (hash4
))
8148 /* Run through all the TLS relocs looking for optimization
8149 opportunities. The linker has been hacked (see ppc64elf.em) to do
8150 a preliminary section layout so that we know the TLS segment
8151 offsets. We can't optimize earlier because some optimizations need
8152 to know the tp offset, and we need to optimize before allocating
8153 dynamic relocations. */
8156 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8160 struct ppc_link_hash_table
*htab
;
8161 unsigned char *toc_ref
;
8164 if (!bfd_link_executable (info
))
8167 htab
= ppc_hash_table (info
);
8171 htab
->do_tls_opt
= 1;
8173 /* Make two passes over the relocs. On the first pass, mark toc
8174 entries involved with tls relocs, and check that tls relocs
8175 involved in setting up a tls_get_addr call are indeed followed by
8176 such a call. If they are not, we can't do any tls optimization.
8177 On the second pass twiddle tls_mask flags to notify
8178 relocate_section that optimization can be done, and adjust got
8179 and plt refcounts. */
8181 for (pass
= 0; pass
< 2; ++pass
)
8182 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8184 Elf_Internal_Sym
*locsyms
= NULL
;
8185 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8187 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8188 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8190 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8191 bool found_tls_get_addr_arg
= 0;
8193 /* Read the relocations. */
8194 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8196 if (relstart
== NULL
)
8202 relend
= relstart
+ sec
->reloc_count
;
8203 for (rel
= relstart
; rel
< relend
; rel
++)
8205 enum elf_ppc64_reloc_type r_type
;
8206 unsigned long r_symndx
;
8207 struct elf_link_hash_entry
*h
;
8208 Elf_Internal_Sym
*sym
;
8210 unsigned char *tls_mask
;
8211 unsigned int tls_set
, tls_clear
, tls_type
= 0;
8213 bool ok_tprel
, is_local
;
8214 long toc_ref_index
= 0;
8215 int expecting_tls_get_addr
= 0;
8218 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8219 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8223 if (elf_section_data (sec
)->relocs
!= relstart
)
8226 if (elf_symtab_hdr (ibfd
).contents
8227 != (unsigned char *) locsyms
)
8234 if (h
->root
.type
== bfd_link_hash_defined
8235 || h
->root
.type
== bfd_link_hash_defweak
)
8236 value
= h
->root
.u
.def
.value
;
8237 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8241 found_tls_get_addr_arg
= 0;
8246 /* Symbols referenced by TLS relocs must be of type
8247 STT_TLS. So no need for .opd local sym adjust. */
8248 value
= sym
->st_value
;
8251 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
8255 && h
->root
.type
== bfd_link_hash_undefweak
)
8257 else if (sym_sec
!= NULL
8258 && sym_sec
->output_section
!= NULL
)
8260 value
+= sym_sec
->output_offset
;
8261 value
+= sym_sec
->output_section
->vma
;
8262 value
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8263 /* Note that even though the prefix insns
8264 allow a 1<<33 offset we use the same test
8265 as for addis;addi. There may be a mix of
8266 pcrel and non-pcrel code and the decision
8267 to optimise is per symbol, not per TLS
8269 ok_tprel
= value
+ 0x80008000ULL
< 1ULL << 32;
8273 r_type
= ELF64_R_TYPE (rel
->r_info
);
8274 /* If this section has old-style __tls_get_addr calls
8275 without marker relocs, then check that each
8276 __tls_get_addr call reloc is preceded by a reloc
8277 that conceivably belongs to the __tls_get_addr arg
8278 setup insn. If we don't find matching arg setup
8279 relocs, don't do any tls optimization. */
8281 && sec
->nomark_tls_get_addr
8283 && is_tls_get_addr (h
, htab
)
8284 && !found_tls_get_addr_arg
8285 && is_branch_reloc (r_type
))
8287 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8288 "TLS optimization disabled\n"),
8289 ibfd
, sec
, rel
->r_offset
);
8294 found_tls_get_addr_arg
= 0;
8297 case R_PPC64_GOT_TLSLD16
:
8298 case R_PPC64_GOT_TLSLD16_LO
:
8299 case R_PPC64_GOT_TLSLD_PCREL34
:
8300 expecting_tls_get_addr
= 1;
8301 found_tls_get_addr_arg
= 1;
8304 case R_PPC64_GOT_TLSLD16_HI
:
8305 case R_PPC64_GOT_TLSLD16_HA
:
8306 /* These relocs should never be against a symbol
8307 defined in a shared lib. Leave them alone if
8308 that turns out to be the case. */
8315 tls_type
= TLS_TLS
| TLS_LD
;
8318 case R_PPC64_GOT_TLSGD16
:
8319 case R_PPC64_GOT_TLSGD16_LO
:
8320 case R_PPC64_GOT_TLSGD_PCREL34
:
8321 expecting_tls_get_addr
= 1;
8322 found_tls_get_addr_arg
= 1;
8325 case R_PPC64_GOT_TLSGD16_HI
:
8326 case R_PPC64_GOT_TLSGD16_HA
:
8332 tls_set
= TLS_TLS
| TLS_GDIE
;
8334 tls_type
= TLS_TLS
| TLS_GD
;
8337 case R_PPC64_GOT_TPREL_PCREL34
:
8338 case R_PPC64_GOT_TPREL16_DS
:
8339 case R_PPC64_GOT_TPREL16_LO_DS
:
8340 case R_PPC64_GOT_TPREL16_HI
:
8341 case R_PPC64_GOT_TPREL16_HA
:
8346 tls_clear
= TLS_TPREL
;
8347 tls_type
= TLS_TLS
| TLS_TPREL
;
8357 if (rel
+ 1 < relend
8358 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8361 && (ELF64_R_TYPE (rel
[1].r_info
)
8363 && (ELF64_R_TYPE (rel
[1].r_info
)
8364 != R_PPC64_PLTSEQ_NOTOC
))
8366 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8367 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8372 struct plt_entry
*ent
= NULL
;
8374 for (ent
= h
->plt
.plist
;
8377 if (ent
->addend
== rel
[1].r_addend
)
8381 && ent
->plt
.refcount
> 0)
8382 ent
->plt
.refcount
-= 1;
8387 found_tls_get_addr_arg
= 1;
8392 case R_PPC64_TOC16_LO
:
8393 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8396 /* Mark this toc entry as referenced by a TLS
8397 code sequence. We can do that now in the
8398 case of R_PPC64_TLS, and after checking for
8399 tls_get_addr for the TOC16 relocs. */
8400 if (toc_ref
== NULL
)
8402 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8403 if (toc_ref
== NULL
)
8407 value
= h
->root
.u
.def
.value
;
8409 value
= sym
->st_value
;
8410 value
+= rel
->r_addend
;
8413 BFD_ASSERT (value
< toc
->size
8414 && toc
->output_offset
% 8 == 0);
8415 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8416 if (r_type
== R_PPC64_TLS
8417 || r_type
== R_PPC64_TLSGD
8418 || r_type
== R_PPC64_TLSLD
)
8420 toc_ref
[toc_ref_index
] = 1;
8424 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8429 expecting_tls_get_addr
= 2;
8432 case R_PPC64_TPREL64
:
8436 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8441 tls_set
= TLS_EXPLICIT
;
8442 tls_clear
= TLS_TPREL
;
8447 case R_PPC64_DTPMOD64
:
8451 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8453 if (rel
+ 1 < relend
8455 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8456 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8460 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8463 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_GDIE
;
8472 tls_set
= TLS_EXPLICIT
;
8477 case R_PPC64_TPREL16_HA
:
8480 unsigned char buf
[4];
8482 bfd_vma off
= rel
->r_offset
& ~3;
8483 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8486 insn
= bfd_get_32 (ibfd
, buf
);
8487 /* addis rt,13,imm */
8488 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
8489 != ((15u << 26) | (13 << 16)))
8491 /* xgettext:c-format */
8492 info
->callbacks
->minfo
8493 (_("%H: warning: %s unexpected insn %#x.\n"),
8494 ibfd
, sec
, off
, "R_PPC64_TPREL16_HA", insn
);
8495 htab
->do_tls_opt
= 0;
8500 case R_PPC64_TPREL16_HI
:
8501 case R_PPC64_TPREL16_HIGH
:
8502 case R_PPC64_TPREL16_HIGHA
:
8503 case R_PPC64_TPREL16_HIGHER
:
8504 case R_PPC64_TPREL16_HIGHERA
:
8505 case R_PPC64_TPREL16_HIGHEST
:
8506 case R_PPC64_TPREL16_HIGHESTA
:
8507 /* These can all be used in sequences along with
8508 TPREL16_LO or TPREL16_LO_DS in ways we aren't
8509 able to verify easily. */
8510 htab
->do_tls_opt
= 0;
8519 if (!expecting_tls_get_addr
8520 || !sec
->nomark_tls_get_addr
)
8523 if (rel
+ 1 < relend
8524 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8525 htab
->tls_get_addr_fd
,
8530 if (expecting_tls_get_addr
== 2)
8532 /* Check for toc tls entries. */
8533 unsigned char *toc_tls
;
8536 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8541 if (toc_tls
!= NULL
)
8543 if ((*toc_tls
& TLS_TLS
) != 0
8544 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8545 found_tls_get_addr_arg
= 1;
8547 toc_ref
[toc_ref_index
] = 1;
8553 /* Uh oh, we didn't find the expected call. We
8554 could just mark this symbol to exclude it
8555 from tls optimization but it's safer to skip
8556 the entire optimization. */
8557 /* xgettext:c-format */
8558 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8559 "TLS optimization disabled\n"),
8560 ibfd
, sec
, rel
->r_offset
);
8565 /* If we don't have old-style __tls_get_addr calls
8566 without TLSGD/TLSLD marker relocs, and we haven't
8567 found a new-style __tls_get_addr call with a
8568 marker for this symbol, then we either have a
8569 broken object file or an -mlongcall style
8570 indirect call to __tls_get_addr without a marker.
8571 Disable optimization in this case. */
8572 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8573 && (tls_set
& TLS_EXPLICIT
) == 0
8574 && !sec
->nomark_tls_get_addr
8575 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8576 != (TLS_TLS
| TLS_MARK
)))
8579 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
8581 struct plt_entry
*ent
= NULL
;
8583 if (htab
->tls_get_addr_fd
!= NULL
)
8584 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8587 if (ent
->addend
== 0)
8590 if (ent
== NULL
&& htab
->tga_desc_fd
!= NULL
)
8591 for (ent
= htab
->tga_desc_fd
->elf
.plt
.plist
;
8594 if (ent
->addend
== 0)
8597 if (ent
== NULL
&& htab
->tls_get_addr
!= NULL
)
8598 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8601 if (ent
->addend
== 0)
8604 if (ent
== NULL
&& htab
->tga_desc
!= NULL
)
8605 for (ent
= htab
->tga_desc
->elf
.plt
.plist
;
8608 if (ent
->addend
== 0)
8612 && ent
->plt
.refcount
> 0)
8613 ent
->plt
.refcount
-= 1;
8619 if ((tls_set
& TLS_EXPLICIT
) == 0)
8621 struct got_entry
*ent
;
8623 /* Adjust got entry for this reloc. */
8627 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8629 for (; ent
!= NULL
; ent
= ent
->next
)
8630 if (ent
->addend
== rel
->r_addend
8631 && ent
->owner
== ibfd
8632 && ent
->tls_type
== tls_type
)
8639 /* We managed to get rid of a got entry. */
8640 if (ent
->got
.refcount
> 0)
8641 ent
->got
.refcount
-= 1;
8646 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8647 we'll lose one or two dyn relocs. */
8648 if (!dec_dynrel_count (rel
, sec
, info
,
8652 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8654 if (!dec_dynrel_count (rel
+ 1, sec
, info
,
8660 *tls_mask
|= tls_set
& 0xff;
8661 *tls_mask
&= ~tls_clear
;
8664 if (elf_section_data (sec
)->relocs
!= relstart
)
8669 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8671 if (!info
->keep_memory
)
8674 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8682 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8683 the values of any global symbols in a toc section that has been
8684 edited. Globals in toc sections should be a rarity, so this function
8685 sets a flag if any are found in toc sections other than the one just
8686 edited, so that further hash table traversals can be avoided. */
8688 struct adjust_toc_info
8691 unsigned long *skip
;
8692 bool global_toc_syms
;
8695 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8698 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8700 struct ppc_link_hash_entry
*eh
;
8701 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8704 if (h
->root
.type
!= bfd_link_hash_defined
8705 && h
->root
.type
!= bfd_link_hash_defweak
)
8708 eh
= ppc_elf_hash_entry (h
);
8709 if (eh
->adjust_done
)
8712 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8714 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8715 i
= toc_inf
->toc
->rawsize
>> 3;
8717 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8719 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8722 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8725 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8726 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8729 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8730 eh
->adjust_done
= 1;
8732 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8733 toc_inf
->global_toc_syms
= true;
8738 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8739 on a _LO variety toc/got reloc. */
8742 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8744 return ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */
8745 || (insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
8746 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
8747 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
8748 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
8749 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
8750 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
8751 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
8752 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
8753 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
8754 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
8755 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
8756 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
8757 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
8758 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
8759 || (insn
& (0x3fu
<< 26)) == 56u << 26 /* lq,lfq */
8760 || ((insn
& (0x3fu
<< 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8761 /* Exclude lfqu by testing reloc. If relocs are ever
8762 defined for the reduced D field in psq_lu then those
8763 will need testing too. */
8764 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8765 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* ld,lwa */
8767 || (insn
& (0x3fu
<< 26)) == 60u << 26 /* stfq */
8768 || ((insn
& (0x3fu
<< 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8769 /* Exclude stfqu. psq_stu as above for psq_lu. */
8770 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8771 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std,stq */
8772 && (insn
& 1) == 0));
8775 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
8776 pld ra,symbol@got@pcrel
8777 load/store rt,off(ra)
8780 load/store rt,off(ra)
8781 may be translated to
8782 pload/pstore rt,symbol+off@pcrel
8784 This function returns true if the optimization is possible, placing
8785 the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
8787 On entry to this function, the linker has already determined that
8788 the pld can be replaced with pla: *PINSN1 is that pla insn,
8789 while *PINSN2 is the second instruction. */
8792 xlate_pcrel_opt (uint64_t *pinsn1
, uint64_t *pinsn2
, bfd_signed_vma
*poff
)
8794 uint64_t insn1
= *pinsn1
;
8795 uint64_t insn2
= *pinsn2
;
8798 if ((insn2
& (63ULL << 58)) == 1ULL << 58)
8800 /* Check that regs match. */
8801 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8804 /* P8LS or PMLS form, non-pcrel. */
8805 if ((insn2
& (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
8808 *pinsn1
= (insn2
& ~(31 << 16) & ~0x3ffff0000ffffULL
) | (1ULL << 52);
8810 off
= ((insn2
>> 16) & 0x3ffff0000ULL
) | (insn2
& 0xffff);
8811 *poff
= (off
^ 0x200000000ULL
) - 0x200000000ULL
;
8817 /* Check that regs match. */
8818 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8821 switch ((insn2
>> 26) & 63)
8837 /* These are the PMLS cases, where we just need to tack a prefix
8839 insn1
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
8840 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8841 off
= insn2
& 0xffff;
8844 case 58: /* lwa, ld */
8845 if ((insn2
& 1) != 0)
8847 insn1
= ((1ULL << 58) | (1ULL << 52)
8848 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
8849 | (insn2
& (31ULL << 21)));
8850 off
= insn2
& 0xfffc;
8853 case 57: /* lxsd, lxssp */
8854 if ((insn2
& 3) < 2)
8856 insn1
= ((1ULL << 58) | (1ULL << 52)
8857 | ((40ULL | (insn2
& 3)) << 26)
8858 | (insn2
& (31ULL << 21)));
8859 off
= insn2
& 0xfffc;
8862 case 61: /* stxsd, stxssp, lxv, stxv */
8863 if ((insn2
& 3) == 0)
8865 else if ((insn2
& 3) >= 2)
8867 insn1
= ((1ULL << 58) | (1ULL << 52)
8868 | ((44ULL | (insn2
& 3)) << 26)
8869 | (insn2
& (31ULL << 21)));
8870 off
= insn2
& 0xfffc;
8874 insn1
= ((1ULL << 58) | (1ULL << 52)
8875 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
8876 | (insn2
& (31ULL << 21)));
8877 off
= insn2
& 0xfff0;
8882 insn1
= ((1ULL << 58) | (1ULL << 52)
8883 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8884 off
= insn2
& 0xffff;
8887 case 6: /* lxvp, stxvp */
8888 if ((insn2
& 0xe) != 0)
8890 insn1
= ((1ULL << 58) | (1ULL << 52)
8891 | ((insn2
& 1) == 0 ? 58ULL << 26 : 62ULL << 26)
8892 | (insn2
& (31ULL << 21)));
8893 off
= insn2
& 0xfff0;
8896 case 62: /* std, stq */
8897 if ((insn2
& 1) != 0)
8899 insn1
= ((1ULL << 58) | (1ULL << 52)
8900 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
8901 | (insn2
& (31ULL << 21)));
8902 off
= insn2
& 0xfffc;
8907 *pinsn2
= (uint64_t) NOP
<< 32;
8908 *poff
= (off
^ 0x8000) - 0x8000;
8912 /* Examine all relocs referencing .toc sections in order to remove
8913 unused .toc entries. */
8916 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8919 struct adjust_toc_info toc_inf
;
8920 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8922 htab
->do_toc_opt
= 1;
8923 toc_inf
.global_toc_syms
= true;
8924 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8926 asection
*toc
, *sec
;
8927 Elf_Internal_Shdr
*symtab_hdr
;
8928 Elf_Internal_Sym
*local_syms
;
8929 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8930 unsigned long *skip
, *drop
;
8931 unsigned char *used
;
8932 unsigned char *keep
, last
, some_unused
;
8934 if (!is_ppc64_elf (ibfd
))
8937 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8940 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8941 || discarded_section (toc
))
8946 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8948 /* Look at sections dropped from the final link. */
8951 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8953 if (sec
->reloc_count
== 0
8954 || !discarded_section (sec
)
8955 || get_opd_info (sec
)
8956 || (sec
->flags
& SEC_ALLOC
) == 0
8957 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8960 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, false);
8961 if (relstart
== NULL
)
8964 /* Run through the relocs to see which toc entries might be
8966 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8968 enum elf_ppc64_reloc_type r_type
;
8969 unsigned long r_symndx
;
8971 struct elf_link_hash_entry
*h
;
8972 Elf_Internal_Sym
*sym
;
8975 r_type
= ELF64_R_TYPE (rel
->r_info
);
8982 case R_PPC64_TOC16_LO
:
8983 case R_PPC64_TOC16_HI
:
8984 case R_PPC64_TOC16_HA
:
8985 case R_PPC64_TOC16_DS
:
8986 case R_PPC64_TOC16_LO_DS
:
8990 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8991 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8999 val
= h
->root
.u
.def
.value
;
9001 val
= sym
->st_value
;
9002 val
+= rel
->r_addend
;
9004 if (val
>= toc
->size
)
9007 /* Anything in the toc ought to be aligned to 8 bytes.
9008 If not, don't mark as unused. */
9014 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9019 skip
[val
>> 3] = ref_from_discarded
;
9022 if (elf_section_data (sec
)->relocs
!= relstart
)
9026 /* For largetoc loads of address constants, we can convert
9027 . addis rx,2,addr@got@ha
9028 . ld ry,addr@got@l(rx)
9030 . addis rx,2,addr@toc@ha
9031 . addi ry,rx,addr@toc@l
9032 when addr is within 2G of the toc pointer. This then means
9033 that the word storing "addr" in the toc is no longer needed. */
9035 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9036 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9037 && toc
->reloc_count
!= 0)
9039 /* Read toc relocs. */
9040 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9042 if (toc_relocs
== NULL
)
9045 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9047 enum elf_ppc64_reloc_type r_type
;
9048 unsigned long r_symndx
;
9050 struct elf_link_hash_entry
*h
;
9051 Elf_Internal_Sym
*sym
;
9054 r_type
= ELF64_R_TYPE (rel
->r_info
);
9055 if (r_type
!= R_PPC64_ADDR64
)
9058 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9059 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9064 || sym_sec
->output_section
== NULL
9065 || discarded_section (sym_sec
))
9068 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9073 if (h
->type
== STT_GNU_IFUNC
)
9075 val
= h
->root
.u
.def
.value
;
9079 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9081 val
= sym
->st_value
;
9083 val
+= rel
->r_addend
;
9084 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9086 /* We don't yet know the exact toc pointer value, but we
9087 know it will be somewhere in the toc section. Don't
9088 optimize if the difference from any possible toc
9089 pointer is outside [ff..f80008000, 7fff7fff]. */
9090 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9091 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9094 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9095 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9100 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9105 skip
[rel
->r_offset
>> 3]
9106 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9113 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9117 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9120 && elf_section_data (sec
)->relocs
!= relstart
)
9122 if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9128 /* Now check all kept sections that might reference the toc.
9129 Check the toc itself last. */
9130 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9133 sec
= (sec
== toc
? NULL
9134 : sec
->next
== NULL
? toc
9135 : sec
->next
== toc
&& toc
->next
? toc
->next
9140 if (sec
->reloc_count
== 0
9141 || discarded_section (sec
)
9142 || get_opd_info (sec
)
9143 || (sec
->flags
& SEC_ALLOC
) == 0
9144 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9147 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9149 if (relstart
== NULL
)
9155 /* Mark toc entries referenced as used. */
9159 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9161 enum elf_ppc64_reloc_type r_type
;
9162 unsigned long r_symndx
;
9164 struct elf_link_hash_entry
*h
;
9165 Elf_Internal_Sym
*sym
;
9168 r_type
= ELF64_R_TYPE (rel
->r_info
);
9172 case R_PPC64_TOC16_LO
:
9173 case R_PPC64_TOC16_HI
:
9174 case R_PPC64_TOC16_HA
:
9175 case R_PPC64_TOC16_DS
:
9176 case R_PPC64_TOC16_LO_DS
:
9177 /* In case we're taking addresses of toc entries. */
9178 case R_PPC64_ADDR64
:
9185 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9186 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9197 val
= h
->root
.u
.def
.value
;
9199 val
= sym
->st_value
;
9200 val
+= rel
->r_addend
;
9202 if (val
>= toc
->size
)
9205 if ((skip
[val
>> 3] & can_optimize
) != 0)
9212 case R_PPC64_TOC16_HA
:
9215 case R_PPC64_TOC16_LO_DS
:
9216 off
= rel
->r_offset
;
9217 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9218 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9224 if ((opc
& (0x3f << 2)) == (58u << 2))
9229 /* Wrong sort of reloc, or not a ld. We may
9230 as well clear ref_from_discarded too. */
9237 /* For the toc section, we only mark as used if this
9238 entry itself isn't unused. */
9239 else if ((used
[rel
->r_offset
>> 3]
9240 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9243 /* Do all the relocs again, to catch reference
9252 if (elf_section_data (sec
)->relocs
!= relstart
)
9256 /* Merge the used and skip arrays. Assume that TOC
9257 doublewords not appearing as either used or unused belong
9258 to an entry more than one doubleword in size. */
9259 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9260 drop
< skip
+ (toc
->size
+ 7) / 8;
9265 *drop
&= ~ref_from_discarded
;
9266 if ((*drop
& can_optimize
) != 0)
9270 else if ((*drop
& ref_from_discarded
) != 0)
9273 last
= ref_from_discarded
;
9283 bfd_byte
*contents
, *src
;
9285 Elf_Internal_Sym
*sym
;
9286 bool local_toc_syms
= false;
9288 /* Shuffle the toc contents, and at the same time convert the
9289 skip array from booleans into offsets. */
9290 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9293 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9295 for (src
= contents
, off
= 0, drop
= skip
;
9296 src
< contents
+ toc
->size
;
9299 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9304 memcpy (src
- off
, src
, 8);
9308 toc
->rawsize
= toc
->size
;
9309 toc
->size
= src
- contents
- off
;
9311 /* Adjust addends for relocs against the toc section sym,
9312 and optimize any accesses we can. */
9313 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9315 if (sec
->reloc_count
== 0
9316 || discarded_section (sec
))
9319 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9321 if (relstart
== NULL
)
9324 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9326 enum elf_ppc64_reloc_type r_type
;
9327 unsigned long r_symndx
;
9329 struct elf_link_hash_entry
*h
;
9332 r_type
= ELF64_R_TYPE (rel
->r_info
);
9339 case R_PPC64_TOC16_LO
:
9340 case R_PPC64_TOC16_HI
:
9341 case R_PPC64_TOC16_HA
:
9342 case R_PPC64_TOC16_DS
:
9343 case R_PPC64_TOC16_LO_DS
:
9344 case R_PPC64_ADDR64
:
9348 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9349 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9357 val
= h
->root
.u
.def
.value
;
9360 val
= sym
->st_value
;
9362 local_toc_syms
= true;
9365 val
+= rel
->r_addend
;
9367 if (val
> toc
->rawsize
)
9369 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9371 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9373 Elf_Internal_Rela
*tocrel
9374 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9375 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9379 case R_PPC64_TOC16_HA
:
9380 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9383 case R_PPC64_TOC16_LO_DS
:
9384 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9388 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9390 info
->callbacks
->einfo
9391 /* xgettext:c-format */
9392 (_("%H: %s references "
9393 "optimized away TOC entry\n"),
9394 ibfd
, sec
, rel
->r_offset
,
9395 ppc64_elf_howto_table
[r_type
]->name
);
9396 bfd_set_error (bfd_error_bad_value
);
9399 rel
->r_addend
= tocrel
->r_addend
;
9400 elf_section_data (sec
)->relocs
= relstart
;
9404 if (h
!= NULL
|| sym
->st_value
!= 0)
9407 rel
->r_addend
-= skip
[val
>> 3];
9408 elf_section_data (sec
)->relocs
= relstart
;
9411 if (elf_section_data (sec
)->relocs
!= relstart
)
9415 /* We shouldn't have local or global symbols defined in the TOC,
9416 but handle them anyway. */
9417 if (local_syms
!= NULL
)
9418 for (sym
= local_syms
;
9419 sym
< local_syms
+ symtab_hdr
->sh_info
;
9421 if (sym
->st_value
!= 0
9422 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9426 if (sym
->st_value
> toc
->rawsize
)
9427 i
= toc
->rawsize
>> 3;
9429 i
= sym
->st_value
>> 3;
9431 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9435 (_("%s defined on removed toc entry"),
9436 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9439 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9440 sym
->st_value
= (bfd_vma
) i
<< 3;
9443 sym
->st_value
-= skip
[i
];
9444 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9447 /* Adjust any global syms defined in this toc input section. */
9448 if (toc_inf
.global_toc_syms
)
9451 toc_inf
.skip
= skip
;
9452 toc_inf
.global_toc_syms
= false;
9453 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9457 if (toc
->reloc_count
!= 0)
9459 Elf_Internal_Shdr
*rel_hdr
;
9460 Elf_Internal_Rela
*wrel
;
9463 /* Remove unused toc relocs, and adjust those we keep. */
9464 if (toc_relocs
== NULL
)
9465 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9467 if (toc_relocs
== NULL
)
9471 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9472 if ((skip
[rel
->r_offset
>> 3]
9473 & (ref_from_discarded
| can_optimize
)) == 0)
9475 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9476 wrel
->r_info
= rel
->r_info
;
9477 wrel
->r_addend
= rel
->r_addend
;
9480 else if (!dec_dynrel_count (rel
, toc
, info
,
9481 &local_syms
, NULL
, NULL
))
9484 elf_section_data (toc
)->relocs
= toc_relocs
;
9485 toc
->reloc_count
= wrel
- toc_relocs
;
9486 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9487 sz
= rel_hdr
->sh_entsize
;
9488 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9491 else if (elf_section_data (toc
)->relocs
!= toc_relocs
)
9494 if (local_syms
!= NULL
9495 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9497 if (!info
->keep_memory
)
9500 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9505 /* Look for cases where we can change an indirect GOT access to
9506 a GOT relative or PC relative access, possibly reducing the
9507 number of GOT entries. */
9508 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9511 Elf_Internal_Shdr
*symtab_hdr
;
9512 Elf_Internal_Sym
*local_syms
;
9513 Elf_Internal_Rela
*relstart
, *rel
;
9516 if (!is_ppc64_elf (ibfd
))
9519 if (!ppc64_elf_tdata (ibfd
)->has_optrel
)
9522 sec
= ppc64_elf_tdata (ibfd
)->got
;
9525 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
9528 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9530 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9532 if (sec
->reloc_count
== 0
9533 || !ppc64_elf_section_data (sec
)->has_optrel
9534 || discarded_section (sec
))
9537 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9539 if (relstart
== NULL
)
9542 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9545 && elf_section_data (sec
)->relocs
!= relstart
)
9550 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9552 enum elf_ppc64_reloc_type r_type
;
9553 unsigned long r_symndx
;
9554 Elf_Internal_Sym
*sym
;
9556 struct elf_link_hash_entry
*h
;
9557 struct got_entry
*ent
;
9559 unsigned char buf
[8];
9561 enum {no_check
, check_lo
, check_ha
} insn_check
;
9563 r_type
= ELF64_R_TYPE (rel
->r_info
);
9567 insn_check
= no_check
;
9570 case R_PPC64_PLT16_HA
:
9571 case R_PPC64_GOT_TLSLD16_HA
:
9572 case R_PPC64_GOT_TLSGD16_HA
:
9573 case R_PPC64_GOT_TPREL16_HA
:
9574 case R_PPC64_GOT_DTPREL16_HA
:
9575 case R_PPC64_GOT16_HA
:
9576 case R_PPC64_TOC16_HA
:
9577 insn_check
= check_ha
;
9580 case R_PPC64_PLT16_LO
:
9581 case R_PPC64_PLT16_LO_DS
:
9582 case R_PPC64_GOT_TLSLD16_LO
:
9583 case R_PPC64_GOT_TLSGD16_LO
:
9584 case R_PPC64_GOT_TPREL16_LO_DS
:
9585 case R_PPC64_GOT_DTPREL16_LO_DS
:
9586 case R_PPC64_GOT16_LO
:
9587 case R_PPC64_GOT16_LO_DS
:
9588 case R_PPC64_TOC16_LO
:
9589 case R_PPC64_TOC16_LO_DS
:
9590 insn_check
= check_lo
;
9594 if (insn_check
!= no_check
)
9596 bfd_vma off
= rel
->r_offset
& ~3;
9598 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9601 insn
= bfd_get_32 (ibfd
, buf
);
9602 if (insn_check
== check_lo
9603 ? !ok_lo_toc_insn (insn
, r_type
)
9604 : ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9605 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9609 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9610 sprintf (str
, "%#08x", insn
);
9611 info
->callbacks
->einfo
9612 /* xgettext:c-format */
9613 (_("%H: got/toc optimization is not supported for"
9614 " %s instruction\n"),
9615 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9622 /* Note that we don't delete GOT entries for
9623 R_PPC64_GOT16_DS since we'd need a lot more
9624 analysis. For starters, the preliminary layout is
9625 before the GOT, PLT, dynamic sections and stubs are
9626 laid out. Then we'd need to allow for changes in
9627 distance between sections caused by alignment. */
9631 case R_PPC64_GOT16_HA
:
9632 case R_PPC64_GOT16_LO_DS
:
9633 case R_PPC64_GOT_PCREL34
:
9637 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9638 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9643 || sym_sec
->output_section
== NULL
9644 || discarded_section (sym_sec
))
9647 if ((h
? h
->type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
)
9650 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9654 val
= h
->root
.u
.def
.value
;
9656 val
= sym
->st_value
;
9657 val
+= rel
->r_addend
;
9658 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9660 /* Fudge factor to allow for the fact that the preliminary layout
9661 isn't exact. Reduce limits by this factor. */
9662 #define LIMIT_ADJUST(LIMIT) ((LIMIT) - (LIMIT) / 16)
9669 case R_PPC64_GOT16_HA
:
9670 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9671 >= LIMIT_ADJUST (0x100000000ULL
))
9674 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9675 rel
->r_offset
& ~3, 4))
9677 insn
= bfd_get_32 (ibfd
, buf
);
9678 if (((insn
& ((0x3fu
<< 26) | 0x1f << 16))
9679 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9683 case R_PPC64_GOT16_LO_DS
:
9684 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9685 >= LIMIT_ADJUST (0x100000000ULL
))
9687 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9688 rel
->r_offset
& ~3, 4))
9690 insn
= bfd_get_32 (ibfd
, buf
);
9691 if ((insn
& (0x3fu
<< 26 | 0x3)) != 58u << 26 /* ld */)
9695 case R_PPC64_GOT_PCREL34
:
9697 pc
+= sec
->output_section
->vma
+ sec
->output_offset
;
9698 if (val
- pc
+ LIMIT_ADJUST (1ULL << 33)
9699 >= LIMIT_ADJUST (1ULL << 34))
9701 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9702 rel
->r_offset
& ~3, 8))
9704 insn
= bfd_get_32 (ibfd
, buf
);
9705 if ((insn
& (-1u << 18)) != ((1u << 26) | (1u << 20)))
9707 insn
= bfd_get_32 (ibfd
, buf
+ 4);
9708 if ((insn
& (0x3fu
<< 26)) != 57u << 26)
9718 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
9719 ent
= local_got_ents
[r_symndx
];
9721 for (; ent
!= NULL
; ent
= ent
->next
)
9722 if (ent
->addend
== rel
->r_addend
9723 && ent
->owner
== ibfd
9724 && ent
->tls_type
== 0)
9726 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
9727 ent
->got
.refcount
-= 1;
9730 if (elf_section_data (sec
)->relocs
!= relstart
)
9734 if (local_syms
!= NULL
9735 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9737 if (!info
->keep_memory
)
9740 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9747 /* Return true iff input section I references the TOC using
9748 instructions limited to +/-32k offsets. */
9751 ppc64_elf_has_small_toc_reloc (asection
*i
)
9753 return (is_ppc64_elf (i
->owner
)
9754 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9757 /* Allocate space for one GOT entry. */
9760 allocate_got (struct elf_link_hash_entry
*h
,
9761 struct bfd_link_info
*info
,
9762 struct got_entry
*gent
)
9764 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9765 struct ppc_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
9766 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9768 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9769 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9770 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9772 gent
->got
.offset
= got
->size
;
9773 got
->size
+= entsize
;
9775 if (h
->type
== STT_GNU_IFUNC
)
9777 htab
->elf
.irelplt
->size
+= rentsize
;
9778 htab
->got_reli_size
+= rentsize
;
9780 else if (((bfd_link_pic (info
)
9781 && (gent
->tls_type
== 0
9782 ? !info
->enable_dt_relr
9783 : !(bfd_link_executable (info
)
9784 && SYMBOL_REFERENCES_LOCAL (info
, h
))))
9785 || (htab
->elf
.dynamic_sections_created
9787 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9788 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9790 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9791 relgot
->size
+= rentsize
;
9795 /* This function merges got entries in the same toc group. */
9798 merge_got_entries (struct got_entry
**pent
)
9800 struct got_entry
*ent
, *ent2
;
9802 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9803 if (!ent
->is_indirect
)
9804 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9805 if (!ent2
->is_indirect
9806 && ent2
->addend
== ent
->addend
9807 && ent2
->tls_type
== ent
->tls_type
9808 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9810 ent2
->is_indirect
= true;
9811 ent2
->got
.ent
= ent
;
9815 /* If H is undefined, make it dynamic if that makes sense. */
9818 ensure_undef_dynamic (struct bfd_link_info
*info
,
9819 struct elf_link_hash_entry
*h
)
9821 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9823 if (htab
->dynamic_sections_created
9824 && ((info
->dynamic_undefined_weak
!= 0
9825 && h
->root
.type
== bfd_link_hash_undefweak
)
9826 || h
->root
.type
== bfd_link_hash_undefined
)
9829 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9830 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9834 /* Choose whether to use htab->iplt or htab->pltlocal rather than the
9835 usual htab->elf.splt section for a PLT entry. */
9838 bool use_local_plt (struct bfd_link_info
*info
,
9839 struct elf_link_hash_entry
*h
)
9843 || !elf_hash_table (info
)->dynamic_sections_created
);
9846 /* Allocate space in .plt, .got and associated reloc sections for
9850 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9852 struct bfd_link_info
*info
;
9853 struct ppc_link_hash_table
*htab
;
9855 struct ppc_link_hash_entry
*eh
;
9856 struct got_entry
**pgent
, *gent
;
9858 if (h
->root
.type
== bfd_link_hash_indirect
)
9861 info
= (struct bfd_link_info
*) inf
;
9862 htab
= ppc_hash_table (info
);
9866 eh
= ppc_elf_hash_entry (h
);
9867 /* Run through the TLS GD got entries first if we're changing them
9869 if ((eh
->tls_mask
& (TLS_TLS
| TLS_GDIE
)) == (TLS_TLS
| TLS_GDIE
))
9870 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9871 if (gent
->got
.refcount
> 0
9872 && (gent
->tls_type
& TLS_GD
) != 0)
9874 /* This was a GD entry that has been converted to TPREL. If
9875 there happens to be a TPREL entry we can use that one. */
9876 struct got_entry
*ent
;
9877 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9878 if (ent
->got
.refcount
> 0
9879 && (ent
->tls_type
& TLS_TPREL
) != 0
9880 && ent
->addend
== gent
->addend
9881 && ent
->owner
== gent
->owner
)
9883 gent
->got
.refcount
= 0;
9887 /* If not, then we'll be using our own TPREL entry. */
9888 if (gent
->got
.refcount
!= 0)
9889 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9892 /* Remove any list entry that won't generate a word in the GOT before
9893 we call merge_got_entries. Otherwise we risk merging to empty
9895 pgent
= &h
->got
.glist
;
9896 while ((gent
= *pgent
) != NULL
)
9897 if (gent
->got
.refcount
> 0)
9899 if ((gent
->tls_type
& TLS_LD
) != 0
9900 && SYMBOL_REFERENCES_LOCAL (info
, h
))
9902 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9903 *pgent
= gent
->next
;
9906 pgent
= &gent
->next
;
9909 *pgent
= gent
->next
;
9911 if (!htab
->do_multi_toc
)
9912 merge_got_entries (&h
->got
.glist
);
9914 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9915 if (!gent
->is_indirect
)
9917 /* Ensure we catch all the cases where this symbol should
9919 if (!ensure_undef_dynamic (info
, h
))
9922 if (!is_ppc64_elf (gent
->owner
))
9925 allocate_got (h
, info
, gent
);
9928 /* If no dynamic sections we can't have dynamic relocs, except for
9929 IFUNCs which are handled even in static executables. */
9930 if (!htab
->elf
.dynamic_sections_created
9931 && h
->type
!= STT_GNU_IFUNC
)
9932 h
->dyn_relocs
= NULL
;
9934 /* Discard relocs on undefined symbols that must be local. */
9935 else if (h
->root
.type
== bfd_link_hash_undefined
9936 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9937 h
->dyn_relocs
= NULL
;
9939 /* Also discard relocs on undefined weak syms with non-default
9940 visibility, or when dynamic_undefined_weak says so. */
9941 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9942 h
->dyn_relocs
= NULL
;
9944 if (h
->dyn_relocs
!= NULL
)
9946 struct ppc_dyn_relocs
*p
, **pp
;
9948 /* In the shared -Bsymbolic case, discard space allocated for
9949 dynamic pc-relative relocs against symbols which turn out to
9950 be defined in regular objects. For the normal shared case,
9951 discard space for relocs that have become local due to symbol
9952 visibility changes. */
9953 if (bfd_link_pic (info
))
9955 /* Relocs that use pc_count are those that appear on a call
9956 insn, or certain REL relocs (see must_be_dyn_reloc) that
9957 can be generated via assembly. We want calls to
9958 protected symbols to resolve directly to the function
9959 rather than going via the plt. If people want function
9960 pointer comparisons to work as expected then they should
9961 avoid writing weird assembly. */
9962 if (SYMBOL_CALLS_LOCAL (info
, h
))
9964 for (pp
= (struct ppc_dyn_relocs
**) &h
->dyn_relocs
;
9968 p
->count
-= p
->pc_count
;
9977 if (h
->dyn_relocs
!= NULL
)
9979 /* Ensure we catch all the cases where this symbol
9980 should be made dynamic. */
9981 if (!ensure_undef_dynamic (info
, h
))
9986 /* For a fixed position executable, discard space for
9987 relocs against symbols which are not dynamic. */
9988 else if (h
->type
!= STT_GNU_IFUNC
)
9990 if ((h
->dynamic_adjusted
9992 && h
->root
.type
== bfd_link_hash_undefweak
9993 && (info
->dynamic_undefined_weak
> 0
9994 || !_bfd_elf_readonly_dynrelocs (h
))))
9996 && !ELF_COMMON_DEF_P (h
))
9998 /* Ensure we catch all the cases where this symbol
9999 should be made dynamic. */
10000 if (!ensure_undef_dynamic (info
, h
))
10003 /* But if that didn't work out, discard dynamic relocs. */
10004 if (h
->dynindx
== -1)
10005 h
->dyn_relocs
= NULL
;
10008 h
->dyn_relocs
= NULL
;
10011 /* Finally, allocate space. */
10012 for (p
= (struct ppc_dyn_relocs
*) h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
10014 unsigned int count
;
10015 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
10016 if (eh
->elf
.type
== STT_GNU_IFUNC
)
10017 sreloc
= htab
->elf
.irelplt
;
10019 if (info
->enable_dt_relr
)
10020 count
-= p
->rel_count
;
10021 sreloc
->size
+= count
* sizeof (Elf64_External_Rela
);
10025 /* We might need a PLT entry when the symbol
10028 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
10029 d) has plt16 relocs and we are linking statically. */
10030 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
10031 || h
->type
== STT_GNU_IFUNC
10032 || (h
->needs_plt
&& h
->dynamic_adjusted
)
10035 && !htab
->elf
.dynamic_sections_created
10036 && !htab
->can_convert_all_inline_plt
10037 && (ppc_elf_hash_entry (h
)->tls_mask
10038 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
10040 struct plt_entry
*pent
;
10041 bool doneone
= false;
10042 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10043 if (pent
->plt
.refcount
> 0)
10045 if (!ensure_undef_dynamic (info
, h
))
10048 if (use_local_plt (info
, h
))
10050 if (h
->type
== STT_GNU_IFUNC
)
10052 s
= htab
->elf
.iplt
;
10053 pent
->plt
.offset
= s
->size
;
10054 s
->size
+= PLT_ENTRY_SIZE (htab
);
10055 s
= htab
->elf
.irelplt
;
10059 s
= htab
->pltlocal
;
10060 pent
->plt
.offset
= s
->size
;
10061 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10063 if (bfd_link_pic (info
)
10064 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
10065 s
= htab
->relpltlocal
;
10070 /* If this is the first .plt entry, make room for the special
10072 s
= htab
->elf
.splt
;
10074 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
10076 pent
->plt
.offset
= s
->size
;
10078 /* Make room for this entry. */
10079 s
->size
+= PLT_ENTRY_SIZE (htab
);
10081 /* Make room for the .glink code. */
10084 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
10087 /* We need bigger stubs past index 32767. */
10088 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
10095 /* We also need to make an entry in the .rela.plt section. */
10096 s
= htab
->elf
.srelplt
;
10099 s
->size
+= sizeof (Elf64_External_Rela
);
10103 pent
->plt
.offset
= (bfd_vma
) -1;
10106 h
->plt
.plist
= NULL
;
10112 h
->plt
.plist
= NULL
;
10119 #define PPC_LO(v) ((v) & 0xffff)
10120 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10121 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10123 ((((v) & 0x3ffff0000ULL) << 16) | (v & 0xffff))
10124 #define HA34(v) ((v + (1ULL << 33)) >> 34)
10126 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
10127 to set up space for global entry stubs. These are put in glink,
10128 after the branch table. */
10131 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
10133 struct bfd_link_info
*info
;
10134 struct ppc_link_hash_table
*htab
;
10135 struct plt_entry
*pent
;
10138 if (h
->root
.type
== bfd_link_hash_indirect
)
10141 if (!h
->pointer_equality_needed
)
10144 if (h
->def_regular
)
10148 htab
= ppc_hash_table (info
);
10152 s
= htab
->global_entry
;
10153 plt
= htab
->elf
.splt
;
10154 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10155 if (pent
->plt
.offset
!= (bfd_vma
) -1
10156 && pent
->addend
== 0)
10158 /* For ELFv2, if this symbol is not defined in a regular file
10159 and we are not generating a shared library or pie, then we
10160 need to define the symbol in the executable on a call stub.
10161 This is to avoid text relocations. */
10162 bfd_vma off
, stub_align
, stub_off
, stub_size
;
10163 unsigned int align_power
;
10166 stub_off
= s
->size
;
10167 if (htab
->params
->plt_stub_align
>= 0)
10168 align_power
= htab
->params
->plt_stub_align
;
10170 align_power
= -htab
->params
->plt_stub_align
;
10171 /* Setting section alignment is delayed until we know it is
10172 non-empty. Otherwise the .text output section will be
10173 aligned at least to plt_stub_align even when no global
10174 entry stubs are needed. */
10175 if (s
->alignment_power
< align_power
)
10176 s
->alignment_power
= align_power
;
10177 stub_align
= (bfd_vma
) 1 << align_power
;
10178 if (htab
->params
->plt_stub_align
>= 0
10179 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
10180 - (stub_off
& -stub_align
))
10181 > ((stub_size
- 1) & -stub_align
)))
10182 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
10183 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
10184 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
10185 /* Note that for --plt-stub-align negative we have a possible
10186 dependency between stub offset and size. Break that
10187 dependency by assuming the max stub size when calculating
10188 the stub offset. */
10189 if (PPC_HA (off
) == 0)
10191 h
->root
.type
= bfd_link_hash_defined
;
10192 h
->root
.u
.def
.section
= s
;
10193 h
->root
.u
.def
.value
= stub_off
;
10194 s
->size
= stub_off
+ stub_size
;
10200 /* Set the sizes of the dynamic sections. */
10203 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10204 struct bfd_link_info
*info
)
10206 struct ppc_link_hash_table
*htab
;
10211 struct got_entry
*first_tlsld
;
10213 htab
= ppc_hash_table (info
);
10217 dynobj
= htab
->elf
.dynobj
;
10218 if (dynobj
== NULL
)
10221 if (htab
->elf
.dynamic_sections_created
)
10223 /* Set the contents of the .interp section to the interpreter. */
10224 if (bfd_link_executable (info
) && !info
->nointerp
)
10226 s
= bfd_get_linker_section (dynobj
, ".interp");
10229 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10230 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10234 /* Set up .got offsets for local syms, and space for local dynamic
10236 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10238 struct got_entry
**lgot_ents
;
10239 struct got_entry
**end_lgot_ents
;
10240 struct plt_entry
**local_plt
;
10241 struct plt_entry
**end_local_plt
;
10242 unsigned char *lgot_masks
;
10243 bfd_size_type locsymcount
;
10244 Elf_Internal_Shdr
*symtab_hdr
;
10246 if (!is_ppc64_elf (ibfd
))
10249 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10251 struct ppc_local_dyn_relocs
*p
;
10253 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10255 if (!bfd_is_abs_section (p
->sec
)
10256 && bfd_is_abs_section (p
->sec
->output_section
))
10258 /* Input section has been discarded, either because
10259 it is a copy of a linkonce section or due to
10260 linker script /DISCARD/, so we'll be discarding
10263 else if (p
->count
!= 0)
10265 unsigned int count
;
10269 if (info
->enable_dt_relr
)
10270 count
-= p
->rel_count
;
10271 srel
= elf_section_data (p
->sec
)->sreloc
;
10273 srel
= htab
->elf
.irelplt
;
10274 srel
->size
+= count
* sizeof (Elf64_External_Rela
);
10275 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10276 info
->flags
|= DF_TEXTREL
;
10281 lgot_ents
= elf_local_got_ents (ibfd
);
10285 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10286 locsymcount
= symtab_hdr
->sh_info
;
10287 end_lgot_ents
= lgot_ents
+ locsymcount
;
10288 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10289 end_local_plt
= local_plt
+ locsymcount
;
10290 lgot_masks
= (unsigned char *) end_local_plt
;
10291 s
= ppc64_elf_tdata (ibfd
)->got
;
10292 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10294 struct got_entry
**pent
, *ent
;
10297 while ((ent
= *pent
) != NULL
)
10298 if (ent
->got
.refcount
> 0)
10300 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10302 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10307 unsigned int ent_size
= 8;
10308 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10310 ent
->got
.offset
= s
->size
;
10311 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10316 s
->size
+= ent_size
;
10317 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10319 htab
->elf
.irelplt
->size
+= rel_size
;
10320 htab
->got_reli_size
+= rel_size
;
10322 else if (bfd_link_pic (info
)
10323 && !(ent
->tls_type
!= 0
10324 && bfd_link_executable (info
)))
10326 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10327 srel
->size
+= rel_size
;
10336 /* Allocate space for plt calls to local syms. */
10337 lgot_masks
= (unsigned char *) end_local_plt
;
10338 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10340 struct plt_entry
*ent
;
10342 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10343 if (ent
->plt
.refcount
> 0)
10345 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10347 s
= htab
->elf
.iplt
;
10348 ent
->plt
.offset
= s
->size
;
10349 s
->size
+= PLT_ENTRY_SIZE (htab
);
10350 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10352 else if (htab
->can_convert_all_inline_plt
10353 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10354 ent
->plt
.offset
= (bfd_vma
) -1;
10357 s
= htab
->pltlocal
;
10358 ent
->plt
.offset
= s
->size
;
10359 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10360 if (bfd_link_pic (info
))
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 && bfd_link_executable (info
)))
12823 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12824 srel
->size
+= rel_size
;
12830 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12832 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12834 struct got_entry
*ent
;
12836 if (!is_ppc64_elf (ibfd
))
12839 ent
= ppc64_tlsld_got (ibfd
);
12840 if (!ent
->is_indirect
12841 && ent
->got
.offset
!= (bfd_vma
) -1)
12843 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12844 ent
->got
.offset
= s
->size
;
12846 if (bfd_link_dll (info
))
12848 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12849 srel
->size
+= sizeof (Elf64_External_Rela
);
12854 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12855 if (!done_something
)
12856 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12860 if (!is_ppc64_elf (ibfd
))
12863 got
= ppc64_elf_tdata (ibfd
)->got
;
12866 done_something
= got
->rawsize
!= got
->size
;
12867 if (done_something
)
12872 if (done_something
)
12873 (*htab
->params
->layout_sections_again
) ();
12875 /* Set up for second pass over toc sections to recalculate elf_gp
12876 on input sections. */
12877 htab
->toc_bfd
= NULL
;
12878 htab
->toc_first_sec
= NULL
;
12879 htab
->second_toc_pass
= true;
12880 return done_something
;
12883 /* Called after second pass of multitoc partitioning. */
12886 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
12888 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12890 /* After the second pass, toc_curr tracks the TOC offset used
12891 for code sections below in ppc64_elf_next_input_section. */
12892 htab
->toc_curr
= TOC_BASE_OFF
;
12895 /* No toc references were found in ISEC. If the code in ISEC makes no
12896 calls, then there's no need to use toc adjusting stubs when branching
12897 into ISEC. Actually, indirect calls from ISEC are OK as they will
12898 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
12899 needed, and 2 if a cyclical call-graph was found but no other reason
12900 for a stub was detected. If called from the top level, a return of
12901 2 means the same as a return of 0. */
12904 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
12908 /* Mark this section as checked. */
12909 isec
->call_check_done
= 1;
12911 /* We know none of our code bearing sections will need toc stubs. */
12912 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
12915 if (isec
->size
== 0)
12918 if (isec
->output_section
== NULL
)
12922 if (isec
->reloc_count
!= 0)
12924 Elf_Internal_Rela
*relstart
, *rel
;
12925 Elf_Internal_Sym
*local_syms
;
12926 struct ppc_link_hash_table
*htab
;
12928 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
12929 info
->keep_memory
);
12930 if (relstart
== NULL
)
12933 /* Look for branches to outside of this section. */
12935 htab
= ppc_hash_table (info
);
12939 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
12941 enum elf_ppc64_reloc_type r_type
;
12942 unsigned long r_symndx
;
12943 struct elf_link_hash_entry
*h
;
12944 struct ppc_link_hash_entry
*eh
;
12945 Elf_Internal_Sym
*sym
;
12947 struct _opd_sec_data
*opd
;
12951 r_type
= ELF64_R_TYPE (rel
->r_info
);
12952 if (r_type
!= R_PPC64_REL24
12953 && r_type
!= R_PPC64_REL24_NOTOC
12954 && r_type
!= R_PPC64_REL24_P9NOTOC
12955 && r_type
!= R_PPC64_REL14
12956 && r_type
!= R_PPC64_REL14_BRTAKEN
12957 && r_type
!= R_PPC64_REL14_BRNTAKEN
12958 && r_type
!= R_PPC64_PLTCALL
12959 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
12962 r_symndx
= ELF64_R_SYM (rel
->r_info
);
12963 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
12970 /* Calls to dynamic lib functions go through a plt call stub
12972 eh
= ppc_elf_hash_entry (h
);
12974 && (eh
->elf
.plt
.plist
!= NULL
12976 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12982 if (sym_sec
== NULL
)
12983 /* Ignore other undefined symbols. */
12986 /* Assume branches to other sections not included in the
12987 link need stubs too, to cover -R and absolute syms. */
12988 if (sym_sec
->output_section
== NULL
)
12995 sym_value
= sym
->st_value
;
12998 if (h
->root
.type
!= bfd_link_hash_defined
12999 && h
->root
.type
!= bfd_link_hash_defweak
)
13001 sym_value
= h
->root
.u
.def
.value
;
13003 sym_value
+= rel
->r_addend
;
13005 /* If this branch reloc uses an opd sym, find the code section. */
13006 opd
= get_opd_info (sym_sec
);
13009 if (h
== NULL
&& opd
->adjust
!= NULL
)
13013 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13015 /* Assume deleted functions won't ever be called. */
13017 sym_value
+= adjust
;
13020 dest
= opd_entry_value (sym_sec
, sym_value
,
13021 &sym_sec
, NULL
, false);
13022 if (dest
== (bfd_vma
) -1)
13027 + sym_sec
->output_offset
13028 + sym_sec
->output_section
->vma
);
13030 /* Ignore branch to self. */
13031 if (sym_sec
== isec
)
13034 /* If the called function uses the toc, we need a stub. */
13035 if (sym_sec
->has_toc_reloc
13036 || sym_sec
->makes_toc_func_call
)
13042 /* Assume any branch that needs a long branch stub might in fact
13043 need a plt_branch stub. A plt_branch stub uses r2. */
13044 else if (dest
- (isec
->output_offset
13045 + isec
->output_section
->vma
13046 + rel
->r_offset
) + (1 << 25)
13047 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
13055 /* If calling back to a section in the process of being
13056 tested, we can't say for sure that no toc adjusting stubs
13057 are needed, so don't return zero. */
13058 else if (sym_sec
->call_check_in_progress
)
13061 /* Branches to another section that itself doesn't have any TOC
13062 references are OK. Recursively call ourselves to check. */
13063 else if (!sym_sec
->call_check_done
)
13067 /* Mark current section as indeterminate, so that other
13068 sections that call back to current won't be marked as
13070 isec
->call_check_in_progress
= 1;
13071 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
13072 isec
->call_check_in_progress
= 0;
13083 if (elf_symtab_hdr (isec
->owner
).contents
13084 != (unsigned char *) local_syms
)
13086 if (elf_section_data (isec
)->relocs
!= relstart
)
13091 && isec
->map_head
.s
!= NULL
13092 && (strcmp (isec
->output_section
->name
, ".init") == 0
13093 || strcmp (isec
->output_section
->name
, ".fini") == 0))
13095 if (isec
->map_head
.s
->has_toc_reloc
13096 || isec
->map_head
.s
->makes_toc_func_call
)
13098 else if (!isec
->map_head
.s
->call_check_done
)
13101 isec
->call_check_in_progress
= 1;
13102 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
13103 isec
->call_check_in_progress
= 0;
13110 isec
->makes_toc_func_call
= 1;
13115 /* The linker repeatedly calls this function for each input section,
13116 in the order that input sections are linked into output sections.
13117 Build lists of input sections to determine groupings between which
13118 we may insert linker stubs. */
13121 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
13123 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13128 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
13129 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
13131 /* This happens to make the list in reverse order,
13132 which is what we want. */
13133 htab
->sec_info
[isec
->id
].u
.list
13134 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
13135 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
13138 if (htab
->multi_toc_needed
)
13140 /* Analyse sections that aren't already flagged as needing a
13141 valid toc pointer. Exclude .fixup for the linux kernel.
13142 .fixup contains branches, but only back to the function that
13143 hit an exception. */
13144 if (!(isec
->has_toc_reloc
13145 || (isec
->flags
& SEC_CODE
) == 0
13146 || strcmp (isec
->name
, ".fixup") == 0
13147 || isec
->call_check_done
))
13149 if (toc_adjusting_stub_needed (info
, isec
) < 0)
13152 /* Make all sections use the TOC assigned for this object file.
13153 This will be wrong for pasted sections; We fix that in
13154 check_pasted_section(). */
13155 if (elf_gp (isec
->owner
) != 0)
13156 htab
->toc_curr
= elf_gp (isec
->owner
);
13159 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
13163 /* Check that all .init and .fini sections use the same toc, if they
13164 have toc relocs. */
13167 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
13169 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
13173 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13174 bfd_vma toc_off
= 0;
13177 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13178 if (i
->has_toc_reloc
)
13181 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13182 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
13187 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13188 if (i
->makes_toc_func_call
)
13190 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
13194 /* Make sure the whole pasted function uses the same toc offset. */
13196 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
13197 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
13203 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
13205 bool ret1
= check_pasted_section (info
, ".init");
13206 bool ret2
= check_pasted_section (info
, ".fini");
13208 return ret1
&& ret2
;
13211 /* See whether we can group stub sections together. Grouping stub
13212 sections may result in fewer stubs. More importantly, we need to
13213 put all .init* and .fini* stubs at the beginning of the .init or
13214 .fini output sections respectively, because glibc splits the
13215 _init and _fini functions into multiple parts. Putting a stub in
13216 the middle of a function is not a good idea. */
13219 group_sections (struct bfd_link_info
*info
,
13220 bfd_size_type stub_group_size
,
13221 bool stubs_always_before_branch
)
13223 struct ppc_link_hash_table
*htab
;
13225 bool suppress_size_errors
;
13227 htab
= ppc_hash_table (info
);
13231 suppress_size_errors
= false;
13232 if (stub_group_size
== 1)
13234 /* Default values. */
13235 if (stubs_always_before_branch
)
13236 stub_group_size
= 0x1e00000;
13238 stub_group_size
= 0x1c00000;
13239 suppress_size_errors
= true;
13242 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
13246 if (osec
->id
>= htab
->sec_info_arr_size
)
13249 tail
= htab
->sec_info
[osec
->id
].u
.list
;
13250 while (tail
!= NULL
)
13254 bfd_size_type total
;
13257 struct map_stub
*group
;
13258 bfd_size_type group_size
;
13261 total
= tail
->size
;
13262 group_size
= (ppc64_elf_section_data (tail
) != NULL
13263 && ppc64_elf_section_data (tail
)->has_14bit_branch
13264 ? stub_group_size
>> 10 : stub_group_size
);
13266 big_sec
= total
> group_size
;
13267 if (big_sec
&& !suppress_size_errors
)
13268 /* xgettext:c-format */
13269 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
13270 tail
->owner
, tail
);
13271 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
13273 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
13274 && ((total
+= curr
->output_offset
- prev
->output_offset
)
13275 < (ppc64_elf_section_data (prev
) != NULL
13276 && ppc64_elf_section_data (prev
)->has_14bit_branch
13277 ? (group_size
= stub_group_size
>> 10) : group_size
))
13278 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13281 /* OK, the size from the start of CURR to the end is less
13282 than group_size and thus can be handled by one stub
13283 section. (or the tail section is itself larger than
13284 group_size, in which case we may be toast.) We should
13285 really be keeping track of the total size of stubs added
13286 here, as stubs contribute to the final output section
13287 size. That's a little tricky, and this way will only
13288 break if stubs added make the total size more than 2^25,
13289 ie. for the default stub_group_size, if stubs total more
13290 than 2097152 bytes, or nearly 75000 plt call stubs. */
13291 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
13294 group
->link_sec
= curr
;
13295 group
->stub_sec
= NULL
;
13296 group
->needs_save_res
= 0;
13297 group
->lr_restore
= 0;
13298 group
->eh_size
= 0;
13299 group
->eh_base
= 0;
13300 group
->next
= htab
->group
;
13301 htab
->group
= group
;
13304 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13305 /* Set up this stub group. */
13306 htab
->sec_info
[tail
->id
].u
.group
= group
;
13308 while (tail
!= curr
&& (tail
= prev
) != NULL
);
13310 /* But wait, there's more! Input sections up to group_size
13311 bytes before the stub section can be handled by it too.
13312 Don't do this if we have a really large section after the
13313 stubs, as adding more stubs increases the chance that
13314 branches may not reach into the stub section. */
13315 if (!stubs_always_before_branch
&& !big_sec
)
13318 while (prev
!= NULL
13319 && ((total
+= tail
->output_offset
- prev
->output_offset
)
13320 < (ppc64_elf_section_data (prev
) != NULL
13321 && ppc64_elf_section_data (prev
)->has_14bit_branch
13322 ? (group_size
= stub_group_size
>> 10)
13324 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
13327 prev
= htab
->sec_info
[tail
->id
].u
.list
;
13328 htab
->sec_info
[tail
->id
].u
.group
= group
;
13337 static const unsigned char glink_eh_frame_cie
[] =
13339 0, 0, 0, 16, /* length. */
13340 0, 0, 0, 0, /* id. */
13341 1, /* CIE version. */
13342 'z', 'R', 0, /* Augmentation string. */
13343 4, /* Code alignment. */
13344 0x78, /* Data alignment. */
13346 1, /* Augmentation size. */
13347 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
13348 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
13351 /* Stripping output sections is normally done before dynamic section
13352 symbols have been allocated. This function is called later, and
13353 handles cases like htab->brlt which is mapped to its own output
13357 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
13359 if (isec
->size
== 0
13360 && isec
->output_section
->size
== 0
13361 && !(isec
->output_section
->flags
& SEC_KEEP
)
13362 && !bfd_section_removed_from_list (info
->output_bfd
,
13363 isec
->output_section
)
13364 && elf_section_data (isec
->output_section
)->dynindx
== 0)
13366 isec
->output_section
->flags
|= SEC_EXCLUDE
;
13367 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
13368 info
->output_bfd
->section_count
--;
13373 compare_relr_address (const void *arg1
, const void *arg2
)
13375 bfd_vma a
= *(bfd_vma
*) arg1
;
13376 bfd_vma b
= *(bfd_vma
*) arg2
;
13377 return a
< b
? -1 : a
> b
? 1 : 0;
13381 append_relr_off (struct ppc_link_hash_table
*htab
, bfd_vma off
)
13383 if (htab
->relr_count
>= htab
->relr_alloc
)
13385 if (htab
->relr_alloc
== 0)
13386 htab
->relr_alloc
= 4096;
13388 htab
->relr_alloc
*= 2;
13390 = bfd_realloc (htab
->relr_addr
,
13391 htab
->relr_alloc
* sizeof (htab
->relr_addr
[0]));
13392 if (htab
->relr_addr
== NULL
)
13395 htab
->relr_addr
[htab
->relr_count
++] = off
;
13400 got_and_plt_relr_for_local_syms (struct bfd_link_info
*info
)
13402 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13405 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13407 struct got_entry
**lgot_ents
, **lgot
, **end_lgot_ents
;
13408 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13409 Elf_Internal_Shdr
*symtab_hdr
;
13410 bfd_size_type locsymcount
;
13411 Elf_Internal_Sym
*local_syms
= NULL
;
13412 struct plt_entry
*pent
;
13413 struct got_entry
*gent
;
13415 if (!is_ppc64_elf (ibfd
))
13418 lgot_ents
= elf_local_got_ents (ibfd
);
13422 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13423 locsymcount
= symtab_hdr
->sh_info
;
13424 end_lgot_ents
= lgot_ents
+ locsymcount
;
13425 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13426 end_local_plt
= local_plt
+ locsymcount
;
13427 for (lgot
= lgot_ents
; lgot
< end_lgot_ents
; ++lgot
)
13428 for (gent
= *lgot
; gent
!= NULL
; gent
= gent
->next
)
13429 if (!gent
->is_indirect
13430 && gent
->tls_type
== 0
13431 && gent
->got
.offset
!= (bfd_vma
) -1)
13433 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
13434 bfd_vma r_offset
= (got
->output_section
->vma
13435 + got
->output_offset
13436 + gent
->got
.offset
);
13437 if (!append_relr_off (htab
, r_offset
))
13439 htab
->stub_error
= true;
13444 if (!htab
->opd_abi
)
13445 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
13446 for (pent
= *lplt
; pent
!= NULL
; pent
= pent
->next
)
13447 if (pent
->plt
.offset
!= (bfd_vma
) -1)
13449 Elf_Internal_Sym
*sym
;
13451 if (!get_sym_h (NULL
, &sym
, NULL
, NULL
, &local_syms
,
13452 lplt
- local_plt
, ibfd
))
13455 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13460 if (ELF_ST_TYPE (sym
->st_info
) != STT_GNU_IFUNC
)
13462 bfd_vma r_offset
= (pent
->plt
.offset
13463 + htab
->pltlocal
->output_offset
13464 + htab
->pltlocal
->output_section
->vma
);
13465 if (!append_relr_off (htab
, r_offset
))
13470 if (local_syms
!= NULL
13471 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13473 if (!info
->keep_memory
)
13476 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13483 got_and_plt_relr (struct elf_link_hash_entry
*h
, void *inf
)
13485 struct bfd_link_info
*info
;
13486 struct ppc_link_hash_table
*htab
;
13487 struct plt_entry
*pent
;
13488 struct got_entry
*gent
;
13490 if (h
->root
.type
== bfd_link_hash_indirect
)
13493 info
= (struct bfd_link_info
*) inf
;
13494 htab
= ppc_hash_table (info
);
13498 if (h
->type
!= STT_GNU_IFUNC
13500 && (h
->root
.type
== bfd_link_hash_defined
13501 || h
->root
.type
== bfd_link_hash_defweak
))
13503 if (!htab
->elf
.dynamic_sections_created
13504 || h
->dynindx
== -1
13505 || SYMBOL_REFERENCES_LOCAL (info
, h
))
13506 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
13507 if (!gent
->is_indirect
13508 && gent
->tls_type
== 0
13509 && gent
->got
.offset
!= (bfd_vma
) -1)
13511 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
13512 bfd_vma r_offset
= (got
->output_section
->vma
13513 + got
->output_offset
13514 + gent
->got
.offset
);
13515 if (!append_relr_off (htab
, r_offset
))
13517 htab
->stub_error
= true;
13523 && use_local_plt (info
, h
))
13524 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
13525 if (pent
->plt
.offset
!= (bfd_vma
) -1)
13527 bfd_vma r_offset
= (htab
->pltlocal
->output_section
->vma
13528 + htab
->pltlocal
->output_offset
13529 + pent
->plt
.offset
);
13530 if (!append_relr_off (htab
, r_offset
))
13532 htab
->stub_error
= true;
13540 /* Determine and set the size of the stub section for a final link.
13542 The basic idea here is to examine all the relocations looking for
13543 PC-relative calls to a target that is unreachable with a "bl"
13547 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
13549 bfd_size_type stub_group_size
;
13550 bool stubs_always_before_branch
;
13551 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13556 if (htab
->params
->power10_stubs
== -1 && !htab
->has_power10_relocs
)
13557 htab
->params
->power10_stubs
= 0;
13559 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
13560 htab
->params
->plt_thread_safe
= 1;
13561 if (!htab
->opd_abi
)
13562 htab
->params
->plt_thread_safe
= 0;
13563 else if (htab
->params
->plt_thread_safe
== -1)
13565 static const char *const thread_starter
[] =
13569 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
13571 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
13572 "mq_notify", "create_timer",
13577 "GOMP_parallel_start",
13578 "GOMP_parallel_loop_static",
13579 "GOMP_parallel_loop_static_start",
13580 "GOMP_parallel_loop_dynamic",
13581 "GOMP_parallel_loop_dynamic_start",
13582 "GOMP_parallel_loop_guided",
13583 "GOMP_parallel_loop_guided_start",
13584 "GOMP_parallel_loop_runtime",
13585 "GOMP_parallel_loop_runtime_start",
13586 "GOMP_parallel_sections",
13587 "GOMP_parallel_sections_start",
13593 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
13595 struct elf_link_hash_entry
*h
;
13596 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
13597 false, false, true);
13598 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
13599 if (htab
->params
->plt_thread_safe
)
13603 stubs_always_before_branch
= htab
->params
->group_size
< 0;
13604 if (htab
->params
->group_size
< 0)
13605 stub_group_size
= -htab
->params
->group_size
;
13607 stub_group_size
= htab
->params
->group_size
;
13609 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
13612 htab
->tga_group
= NULL
;
13613 if (!htab
->params
->no_tls_get_addr_regsave
13614 && htab
->tga_desc_fd
!= NULL
13615 && (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefined
13616 || htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_undefweak
)
13617 && htab
->tls_get_addr_fd
!= NULL
13618 && is_static_defined (&htab
->tls_get_addr_fd
->elf
))
13620 asection
*sym_sec
, *code_sec
, *stub_sec
;
13622 struct _opd_sec_data
*opd
;
13624 sym_sec
= htab
->tls_get_addr_fd
->elf
.root
.u
.def
.section
;
13625 sym_value
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
13626 code_sec
= sym_sec
;
13627 opd
= get_opd_info (sym_sec
);
13629 opd_entry_value (sym_sec
, sym_value
, &code_sec
, NULL
, false);
13630 htab
->tga_group
= htab
->sec_info
[code_sec
->id
].u
.group
;
13631 stub_sec
= (*htab
->params
->add_stub_section
) (".tga_desc.stub",
13632 htab
->tga_group
->link_sec
);
13633 if (stub_sec
== NULL
)
13635 htab
->tga_group
->stub_sec
= stub_sec
;
13637 htab
->tga_desc_fd
->elf
.root
.type
= bfd_link_hash_defined
;
13638 htab
->tga_desc_fd
->elf
.root
.u
.def
.section
= stub_sec
;
13639 htab
->tga_desc_fd
->elf
.root
.u
.def
.value
= 0;
13640 htab
->tga_desc_fd
->elf
.type
= STT_FUNC
;
13641 htab
->tga_desc_fd
->elf
.def_regular
= 1;
13642 htab
->tga_desc_fd
->elf
.non_elf
= 0;
13643 _bfd_elf_link_hash_hide_symbol (info
, &htab
->tga_desc_fd
->elf
, true);
13646 #define STUB_SHRINK_ITER 20
13647 /* Loop until no stubs added. After iteration 20 of this loop we may
13648 exit on a stub section shrinking. This is to break out of a
13649 pathological case where adding stubs on one iteration decreases
13650 section gaps (perhaps due to alignment), which then requires
13651 fewer or smaller stubs on the next iteration. */
13656 unsigned int bfd_indx
;
13657 struct map_stub
*group
;
13659 htab
->stub_iteration
+= 1;
13660 htab
->relr_count
= 0;
13662 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
13664 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
13666 Elf_Internal_Shdr
*symtab_hdr
;
13668 Elf_Internal_Sym
*local_syms
= NULL
;
13670 if (!is_ppc64_elf (input_bfd
))
13673 /* We'll need the symbol table in a second. */
13674 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13675 if (symtab_hdr
->sh_info
== 0)
13678 /* Walk over each section attached to the input bfd. */
13679 for (section
= input_bfd
->sections
;
13681 section
= section
->next
)
13683 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
13686 /* If there aren't any relocs, then there's nothing more
13688 if ((section
->flags
& SEC_RELOC
) == 0
13689 || (section
->flags
& SEC_ALLOC
) == 0
13690 || (section
->flags
& SEC_LOAD
) == 0
13691 || section
->reloc_count
== 0)
13694 if (!info
->enable_dt_relr
13695 && (section
->flags
& SEC_CODE
) == 0)
13698 /* If this section is a link-once section that will be
13699 discarded, then don't create any stubs. */
13700 if (section
->output_section
== NULL
13701 || section
->output_section
->owner
!= info
->output_bfd
)
13704 /* Get the relocs. */
13706 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
13707 info
->keep_memory
);
13708 if (internal_relocs
== NULL
)
13709 goto error_ret_free_local
;
13711 is_opd
= ppc64_elf_section_data (section
)->sec_type
== sec_opd
;
13713 /* Now examine each relocation. */
13714 irela
= internal_relocs
;
13715 irelaend
= irela
+ section
->reloc_count
;
13716 for (; irela
< irelaend
; irela
++)
13718 enum elf_ppc64_reloc_type r_type
;
13719 unsigned int r_indx
;
13720 struct ppc_stub_type stub_type
;
13721 struct ppc_stub_hash_entry
*stub_entry
;
13722 asection
*sym_sec
, *code_sec
;
13723 bfd_vma sym_value
, code_value
;
13724 bfd_vma destination
;
13725 unsigned long local_off
;
13727 struct ppc_link_hash_entry
*hash
;
13728 struct ppc_link_hash_entry
*fdh
;
13729 struct elf_link_hash_entry
*h
;
13730 Elf_Internal_Sym
*sym
;
13732 const asection
*id_sec
;
13733 struct _opd_sec_data
*opd
;
13734 struct plt_entry
*plt_ent
;
13736 r_type
= ELF64_R_TYPE (irela
->r_info
);
13737 r_indx
= ELF64_R_SYM (irela
->r_info
);
13739 if (r_type
>= R_PPC64_max
)
13741 bfd_set_error (bfd_error_bad_value
);
13742 goto error_ret_free_internal
;
13745 /* Only look for stubs on branch instructions. */
13751 case R_PPC64_REL24
:
13752 case R_PPC64_REL24_NOTOC
:
13753 case R_PPC64_REL24_P9NOTOC
:
13754 case R_PPC64_REL14
:
13755 case R_PPC64_REL14_BRTAKEN
:
13756 case R_PPC64_REL14_BRNTAKEN
:
13757 if ((section
->flags
& SEC_CODE
) != 0)
13761 case R_PPC64_ADDR64
:
13763 if (info
->enable_dt_relr
13764 && irela
->r_offset
% 2 == 0
13765 && section
->alignment_power
!= 0)
13770 /* Now determine the call target, its name, value,
13772 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
13773 r_indx
, input_bfd
))
13774 goto error_ret_free_internal
;
13776 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
13778 /* Only locally defined symbols can possibly use
13779 relative relocations. */
13781 if ((sym_sec
== NULL
13782 || sym_sec
->output_section
== NULL
)
13783 /* No symbol is OK too. */
13784 && !(sym
!= NULL
&& sym
->st_shndx
== 0)
13785 /* Hack for __ehdr_start, which is undefined
13787 && !(h
!= NULL
&& h
->root
.linker_def
))
13789 if (NO_OPD_RELOCS
&& is_opd
)
13792 && r_type
== R_PPC64_ADDR64
)
13795 ? h
->type
== STT_GNU_IFUNC
13796 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13799 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
13802 r_offset
= _bfd_elf_section_offset (info
->output_bfd
,
13806 if (r_offset
>= (bfd_vma
) -2)
13808 r_offset
+= (section
->output_section
->vma
13809 + section
->output_offset
);
13810 if (!append_relr_off (htab
, r_offset
))
13811 goto error_ret_free_internal
;
13815 hash
= ppc_elf_hash_entry (h
);
13821 sym_value
= sym
->st_value
;
13822 if (sym_sec
!= NULL
13823 && sym_sec
->output_section
!= NULL
)
13826 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
13827 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
13829 sym_value
= hash
->elf
.root
.u
.def
.value
;
13830 if (sym_sec
->output_section
!= NULL
)
13833 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
13834 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
13836 /* Recognise an old ABI func code entry sym, and
13837 use the func descriptor sym instead if it is
13839 if (hash
->elf
.root
.root
.string
[0] == '.'
13840 && hash
->oh
!= NULL
)
13842 fdh
= ppc_follow_link (hash
->oh
);
13843 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
13844 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
13846 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
13847 sym_value
= fdh
->elf
.root
.u
.def
.value
;
13848 if (sym_sec
->output_section
!= NULL
)
13857 bfd_set_error (bfd_error_bad_value
);
13858 goto error_ret_free_internal
;
13865 sym_value
+= irela
->r_addend
;
13866 destination
= (sym_value
13867 + sym_sec
->output_offset
13868 + sym_sec
->output_section
->vma
);
13869 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
13874 code_sec
= sym_sec
;
13875 code_value
= sym_value
;
13876 opd
= get_opd_info (sym_sec
);
13881 if (hash
== NULL
&& opd
->adjust
!= NULL
)
13883 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
13886 code_value
+= adjust
;
13887 sym_value
+= adjust
;
13889 dest
= opd_entry_value (sym_sec
, sym_value
,
13890 &code_sec
, &code_value
, false);
13891 if (dest
!= (bfd_vma
) -1)
13893 destination
= dest
;
13896 /* Fixup old ABI sym to point at code
13898 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
13899 hash
->elf
.root
.u
.def
.section
= code_sec
;
13900 hash
->elf
.root
.u
.def
.value
= code_value
;
13905 /* Determine what (if any) linker stub is needed. */
13907 stub_type
.main
= ppc_type_of_stub (section
, irela
, &hash
,
13908 &plt_ent
, destination
,
13910 stub_type
.sub
= ppc_stub_toc
;
13911 stub_type
.r2save
= 0;
13913 if (r_type
== R_PPC64_REL24_NOTOC
13914 || r_type
== R_PPC64_REL24_P9NOTOC
)
13916 enum ppc_stub_sub_type notoc
= ppc_stub_notoc
;
13917 if (htab
->params
->power10_stubs
== 0
13918 || (r_type
== R_PPC64_REL24_P9NOTOC
13919 && htab
->params
->power10_stubs
!= 1))
13920 notoc
= ppc_stub_p9notoc
;
13921 if (stub_type
.main
== ppc_stub_plt_call
)
13922 stub_type
.sub
= notoc
;
13923 else if (stub_type
.main
== ppc_stub_long_branch
13924 || (code_sec
!= NULL
13925 && code_sec
->output_section
!= NULL
13926 && (((hash
? hash
->elf
.other
: sym
->st_other
)
13927 & STO_PPC64_LOCAL_MASK
)
13928 > 1 << STO_PPC64_LOCAL_BIT
)))
13930 stub_type
.main
= ppc_stub_long_branch
;
13931 stub_type
.sub
= notoc
;
13932 stub_type
.r2save
= 0;
13935 else if (stub_type
.main
!= ppc_stub_plt_call
)
13937 /* Check whether we need a TOC adjusting stub.
13938 Since the linker pastes together pieces from
13939 different object files when creating the
13940 _init and _fini functions, it may be that a
13941 call to what looks like a local sym is in
13942 fact a call needing a TOC adjustment. */
13943 if ((code_sec
!= NULL
13944 && code_sec
->output_section
!= NULL
13945 && (code_sec
->has_toc_reloc
13946 || code_sec
->makes_toc_func_call
)
13947 && (htab
->sec_info
[code_sec
->id
].toc_off
13948 != htab
->sec_info
[section
->id
].toc_off
))
13949 || (((hash
? hash
->elf
.other
: sym
->st_other
)
13950 & STO_PPC64_LOCAL_MASK
)
13951 == 1 << STO_PPC64_LOCAL_BIT
))
13953 stub_type
.main
= ppc_stub_long_branch
;
13954 stub_type
.sub
= ppc_stub_toc
;
13955 stub_type
.r2save
= 1;
13959 if (stub_type
.main
== ppc_stub_none
)
13962 /* __tls_get_addr calls might be eliminated. */
13963 if (stub_type
.main
!= ppc_stub_plt_call
13965 && is_tls_get_addr (&hash
->elf
, htab
)
13966 && section
->has_tls_reloc
13967 && irela
!= internal_relocs
)
13969 /* Get tls info. */
13970 unsigned char *tls_mask
;
13972 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
13973 irela
- 1, input_bfd
))
13974 goto error_ret_free_internal
;
13975 if ((*tls_mask
& TLS_TLS
) != 0
13976 && (*tls_mask
& (TLS_GD
| TLS_LD
)) == 0)
13980 if (stub_type
.main
== ppc_stub_plt_call
13981 && stub_type
.sub
== ppc_stub_toc
)
13984 && htab
->params
->plt_localentry0
!= 0
13985 && is_elfv2_localentry0 (&hash
->elf
))
13986 htab
->has_plt_localentry0
= 1;
13987 else if (irela
+ 1 < irelaend
13988 && irela
[1].r_offset
== irela
->r_offset
+ 4
13989 && (ELF64_R_TYPE (irela
[1].r_info
)
13990 == R_PPC64_TOCSAVE
))
13992 if (!tocsave_find (htab
, INSERT
,
13993 &local_syms
, irela
+ 1, input_bfd
))
13994 goto error_ret_free_internal
;
13997 stub_type
.r2save
= 1;
14000 /* Support for grouping stub sections. */
14001 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
14003 /* Get the name of this stub. */
14004 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
14006 goto error_ret_free_internal
;
14008 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
14009 stub_name
, false, false);
14010 if (stub_entry
!= NULL
)
14013 if (!ppc_merge_stub (htab
, stub_entry
, stub_type
, r_type
))
14015 /* xgettext:c-format */
14017 (_("%pB: cannot create stub entry %s"),
14018 section
->owner
, stub_entry
->root
.string
);
14019 goto error_ret_free_internal
;
14024 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
14025 if (stub_entry
== NULL
)
14028 error_ret_free_internal
:
14029 if (elf_section_data (section
)->relocs
== NULL
)
14030 free (internal_relocs
);
14031 error_ret_free_local
:
14032 if (symtab_hdr
->contents
14033 != (unsigned char *) local_syms
)
14038 stub_entry
->type
= stub_type
;
14039 if (stub_type
.main
== ppc_stub_plt_call
)
14041 stub_entry
->target_value
= sym_value
;
14042 stub_entry
->target_section
= sym_sec
;
14046 stub_entry
->target_value
= code_value
;
14047 stub_entry
->target_section
= code_sec
;
14049 stub_entry
->h
= hash
;
14050 stub_entry
->plt_ent
= plt_ent
;
14051 stub_entry
->symtype
14052 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
14053 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
14056 && (hash
->elf
.root
.type
== bfd_link_hash_defined
14057 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
14058 htab
->stub_globals
+= 1;
14061 /* We're done with the internal relocs, free them. */
14062 if (elf_section_data (section
)->relocs
!= internal_relocs
)
14063 free (internal_relocs
);
14066 if (local_syms
!= NULL
14067 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14069 if (!info
->keep_memory
)
14072 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14076 /* We may have added some stubs. Find out the new size of the
14078 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14080 group
->lr_restore
= 0;
14081 group
->eh_size
= 0;
14082 if (group
->stub_sec
!= NULL
)
14084 asection
*stub_sec
= group
->stub_sec
;
14086 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
14087 || stub_sec
->rawsize
< stub_sec
->size
)
14088 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
14089 stub_sec
->rawsize
= stub_sec
->size
;
14090 stub_sec
->size
= 0;
14091 stub_sec
->reloc_count
= 0;
14092 stub_sec
->flags
&= ~SEC_RELOC
;
14095 if (htab
->tga_group
!= NULL
)
14097 /* See emit_tga_desc and emit_tga_desc_eh_frame. */
14098 htab
->tga_group
->eh_size
14099 = 1 + 2 + (htab
->opd_abi
!= 0) + 3 + 8 * 2 + 3 + 8 + 3;
14100 htab
->tga_group
->lr_restore
= 23 * 4;
14101 htab
->tga_group
->stub_sec
->size
= 24 * 4;
14104 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
14105 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
14106 htab
->brlt
->rawsize
= htab
->brlt
->size
;
14107 htab
->brlt
->size
= 0;
14108 htab
->brlt
->reloc_count
= 0;
14109 htab
->brlt
->flags
&= ~SEC_RELOC
;
14110 if (htab
->relbrlt
!= NULL
)
14111 htab
->relbrlt
->size
= 0;
14113 if (htab
->elf
.srelrdyn
!= NULL
)
14115 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
14116 || htab
->elf
.srelrdyn
->rawsize
< htab
->elf
.srelrdyn
->size
)
14117 htab
->elf
.srelrdyn
->rawsize
= htab
->elf
.srelrdyn
->size
;
14118 htab
->elf
.srelrdyn
->size
= 0;
14121 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
14123 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14124 if (group
->needs_save_res
)
14125 group
->stub_sec
->size
+= htab
->sfpr
->size
;
14127 if (info
->emitrelocations
14128 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14130 htab
->glink
->reloc_count
= 1;
14131 htab
->glink
->flags
|= SEC_RELOC
;
14134 if (htab
->glink_eh_frame
!= NULL
14135 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
14136 && htab
->glink_eh_frame
->output_section
->size
> 8)
14138 size_t size
= 0, align
= 4;
14140 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14141 if (group
->eh_size
!= 0)
14142 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
14143 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14144 size
+= (24 + align
- 1) & -align
;
14146 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14147 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
14148 size
= (size
+ align
- 1) & -align
;
14149 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
14150 htab
->glink_eh_frame
->size
= size
;
14153 if (htab
->params
->plt_stub_align
!= 0)
14154 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14155 if (group
->stub_sec
!= NULL
)
14157 int align
= abs (htab
->params
->plt_stub_align
);
14158 group
->stub_sec
->size
14159 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
14162 if (htab
->elf
.srelrdyn
!= NULL
)
14166 for (r_offset
= 0; r_offset
< htab
->brlt
->size
; r_offset
+= 8)
14167 if (!append_relr_off (htab
, (r_offset
14168 + htab
->brlt
->output_section
->vma
14169 + htab
->brlt
->output_offset
)))
14172 if (!got_and_plt_relr_for_local_syms (info
))
14174 elf_link_hash_traverse (&htab
->elf
, got_and_plt_relr
, info
);
14175 if (htab
->stub_error
)
14178 if (htab
->relr_count
> 1)
14179 qsort (htab
->relr_addr
, htab
->relr_count
, sizeof (*htab
->relr_addr
),
14180 compare_relr_address
);
14183 while (i
< htab
->relr_count
)
14185 bfd_vma base
= htab
->relr_addr
[i
];
14186 htab
->elf
.srelrdyn
->size
+= 8;
14188 /* Handle possible duplicate address. This can happen
14189 as sections increase in size when adding stubs. */
14190 while (i
< htab
->relr_count
14191 && htab
->relr_addr
[i
] == base
)
14196 size_t start_i
= i
;
14197 while (i
< htab
->relr_count
14198 && htab
->relr_addr
[i
] - base
< 63 * 8
14199 && (htab
->relr_addr
[i
] - base
) % 8 == 0)
14203 htab
->elf
.srelrdyn
->size
+= 8;
14209 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14210 if (group
->stub_sec
!= NULL
14211 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
14212 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
14213 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
14217 && (htab
->brlt
->rawsize
== htab
->brlt
->size
14218 || (htab
->stub_iteration
> STUB_SHRINK_ITER
14219 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
14220 && (htab
->elf
.srelrdyn
== NULL
14221 || htab
->elf
.srelrdyn
->rawsize
== htab
->elf
.srelrdyn
->size
14222 || (htab
->stub_iteration
> STUB_SHRINK_ITER
14223 && htab
->elf
.srelrdyn
->rawsize
> htab
->elf
.srelrdyn
->size
))
14224 && (htab
->glink_eh_frame
== NULL
14225 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
)
14226 && (htab
->tga_group
== NULL
14227 || htab
->stub_iteration
> 1))
14230 /* Ask the linker to do its stuff. */
14231 (*htab
->params
->layout_sections_again
) ();
14234 if (htab
->glink_eh_frame
!= NULL
14235 && htab
->glink_eh_frame
->size
!= 0)
14238 bfd_byte
*p
, *last_fde
;
14239 size_t last_fde_len
, size
, align
, pad
;
14240 struct map_stub
*group
;
14242 /* It is necessary to at least have a rough outline of the
14243 linker generated CIEs and FDEs written before
14244 bfd_elf_discard_info is run, in order for these FDEs to be
14245 indexed in .eh_frame_hdr. */
14246 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
14249 htab
->glink_eh_frame
->contents
= p
;
14253 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
14254 /* CIE length (rewrite in case little-endian). */
14255 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
14256 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14257 p
+= last_fde_len
+ 4;
14259 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14260 if (group
->eh_size
!= 0)
14262 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
14264 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
14266 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14269 val
= p
- htab
->glink_eh_frame
->contents
;
14270 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
14272 /* Offset to stub section, written later. */
14274 /* stub section size. */
14275 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
14277 /* Augmentation. */
14279 /* Make sure we don't have all nops. This is enough for
14280 elf-eh-frame.c to detect the last non-nop opcode. */
14281 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
14282 p
= last_fde
+ last_fde_len
+ 4;
14284 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14287 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
14289 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
14292 val
= p
- htab
->glink_eh_frame
->contents
;
14293 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
14295 /* Offset to .glink, written later. */
14298 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
14300 /* Augmentation. */
14303 *p
++ = DW_CFA_advance_loc
+ (htab
->has_plt_localentry0
? 3 : 2);
14304 *p
++ = DW_CFA_register
;
14306 *p
++ = htab
->opd_abi
? 12 : 0;
14307 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 4 : 2);
14308 *p
++ = DW_CFA_restore_extended
;
14310 p
+= ((24 + align
- 1) & -align
) - 24;
14312 /* Subsume any padding into the last FDE if user .eh_frame
14313 sections are aligned more than glink_eh_frame. Otherwise any
14314 zero padding will be seen as a terminator. */
14315 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
14316 size
= p
- htab
->glink_eh_frame
->contents
;
14317 pad
= ((size
+ align
- 1) & -align
) - size
;
14318 htab
->glink_eh_frame
->size
= size
+ pad
;
14319 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
14322 maybe_strip_output (info
, htab
->brlt
);
14323 if (htab
->relbrlt
!= NULL
)
14324 maybe_strip_output (info
, htab
->relbrlt
);
14325 if (htab
->glink_eh_frame
!= NULL
)
14326 maybe_strip_output (info
, htab
->glink_eh_frame
);
14327 if (htab
->elf
.srelrdyn
!= NULL
)
14328 maybe_strip_output (info
, htab
->elf
.srelrdyn
);
14333 /* Called after we have determined section placement. If sections
14334 move, we'll be called again. Provide a value for TOCstart. */
14337 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
14340 bfd_vma TOCstart
, adjust
;
14344 struct elf_link_hash_entry
*h
;
14345 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
14347 if (is_elf_hash_table (&htab
->root
)
14348 && htab
->hgot
!= NULL
)
14352 h
= (struct elf_link_hash_entry
*)
14353 bfd_link_hash_lookup (&htab
->root
, ".TOC.", false, false, true);
14354 if (is_elf_hash_table (&htab
->root
))
14358 && h
->root
.type
== bfd_link_hash_defined
14359 && !h
->root
.linker_def
14360 && (!is_elf_hash_table (&htab
->root
)
14361 || h
->def_regular
))
14363 TOCstart
= defined_sym_val (h
) - TOC_BASE_OFF
;
14364 _bfd_set_gp_value (obfd
, TOCstart
);
14369 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
14370 order. The TOC starts where the first of these sections starts. */
14371 s
= bfd_get_section_by_name (obfd
, ".got");
14372 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14373 s
= bfd_get_section_by_name (obfd
, ".toc");
14374 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14375 s
= bfd_get_section_by_name (obfd
, ".tocbss");
14376 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14377 s
= bfd_get_section_by_name (obfd
, ".plt");
14378 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
14380 /* This may happen for
14381 o references to TOC base (SYM@toc / TOC[tc0]) without a
14383 o bad linker script
14384 o --gc-sections and empty TOC sections
14386 FIXME: Warn user? */
14388 /* Look for a likely section. We probably won't even be
14390 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14391 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
14393 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14396 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14397 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
14398 == (SEC_ALLOC
| SEC_SMALL_DATA
))
14401 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14402 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
14406 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
14407 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
14413 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
14415 /* Force alignment. */
14416 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
14417 TOCstart
-= adjust
;
14418 _bfd_set_gp_value (obfd
, TOCstart
);
14420 if (info
!= NULL
&& s
!= NULL
)
14422 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14426 if (htab
->elf
.hgot
!= NULL
)
14428 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
14429 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
14434 struct bfd_link_hash_entry
*bh
= NULL
;
14435 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
14436 s
, TOC_BASE_OFF
- adjust
,
14437 NULL
, false, false, &bh
);
14443 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
14444 write out any global entry stubs, and PLT relocations. */
14447 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
14449 struct bfd_link_info
*info
;
14450 struct ppc_link_hash_table
*htab
;
14451 struct plt_entry
*ent
;
14454 if (h
->root
.type
== bfd_link_hash_indirect
)
14458 htab
= ppc_hash_table (info
);
14462 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14463 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14465 /* This symbol has an entry in the procedure linkage
14466 table. Set it up. */
14467 Elf_Internal_Rela rela
;
14468 asection
*plt
, *relplt
;
14471 if (use_local_plt (info
, h
))
14473 if (!(h
->def_regular
14474 && (h
->root
.type
== bfd_link_hash_defined
14475 || h
->root
.type
== bfd_link_hash_defweak
)))
14477 if (h
->type
== STT_GNU_IFUNC
)
14479 plt
= htab
->elf
.iplt
;
14480 relplt
= htab
->elf
.irelplt
;
14481 htab
->elf
.ifunc_resolvers
= true;
14483 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14485 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14489 plt
= htab
->pltlocal
;
14491 if (bfd_link_pic (info
)
14492 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
14494 relplt
= htab
->relpltlocal
;
14496 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14498 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14501 rela
.r_addend
= defined_sym_val (h
) + ent
->addend
;
14503 if (relplt
== NULL
)
14505 loc
= plt
->contents
+ ent
->plt
.offset
;
14506 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
14509 bfd_vma toc
= elf_gp (info
->output_bfd
);
14510 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
14511 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14516 rela
.r_offset
= (plt
->output_section
->vma
14517 + plt
->output_offset
14518 + ent
->plt
.offset
);
14519 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14520 * sizeof (Elf64_External_Rela
));
14521 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14526 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
14527 + htab
->elf
.splt
->output_offset
14528 + ent
->plt
.offset
);
14529 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
14530 rela
.r_addend
= ent
->addend
;
14531 loc
= (htab
->elf
.srelplt
->contents
14532 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
14533 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
14534 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
14535 htab
->elf
.ifunc_resolvers
= true;
14536 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14540 if (!h
->pointer_equality_needed
)
14543 if (h
->def_regular
)
14546 s
= htab
->global_entry
;
14547 if (s
== NULL
|| s
->size
== 0)
14550 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14551 if (ent
->plt
.offset
!= (bfd_vma
) -1
14552 && ent
->addend
== 0)
14558 p
= s
->contents
+ h
->root
.u
.def
.value
;
14559 plt
= htab
->elf
.splt
;
14560 if (use_local_plt (info
, h
))
14562 if (h
->type
== STT_GNU_IFUNC
)
14563 plt
= htab
->elf
.iplt
;
14565 plt
= htab
->pltlocal
;
14567 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
14568 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
14570 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
14572 info
->callbacks
->einfo
14573 (_("%P: linkage table error against `%pT'\n"),
14574 h
->root
.root
.string
);
14575 bfd_set_error (bfd_error_bad_value
);
14576 htab
->stub_error
= true;
14579 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
14580 if (htab
->params
->emit_stub_syms
)
14582 size_t len
= strlen (h
->root
.root
.string
);
14583 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
14588 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
14589 h
= elf_link_hash_lookup (&htab
->elf
, name
, true, false, false);
14592 if (h
->root
.type
== bfd_link_hash_new
)
14594 h
->root
.type
= bfd_link_hash_defined
;
14595 h
->root
.u
.def
.section
= s
;
14596 h
->root
.u
.def
.value
= p
- s
->contents
;
14597 h
->ref_regular
= 1;
14598 h
->def_regular
= 1;
14599 h
->ref_regular_nonweak
= 1;
14600 h
->forced_local
= 1;
14602 h
->root
.linker_def
= 1;
14606 if (PPC_HA (off
) != 0)
14608 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
14611 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
14613 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
14615 bfd_put_32 (s
->owner
, BCTR
, p
);
14621 /* Write PLT relocs for locals. */
14624 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
14626 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14629 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
14631 struct got_entry
**lgot_ents
, **end_lgot_ents
;
14632 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
14633 Elf_Internal_Shdr
*symtab_hdr
;
14634 bfd_size_type locsymcount
;
14635 Elf_Internal_Sym
*local_syms
= NULL
;
14636 struct plt_entry
*ent
;
14638 if (!is_ppc64_elf (ibfd
))
14641 lgot_ents
= elf_local_got_ents (ibfd
);
14645 symtab_hdr
= &elf_symtab_hdr (ibfd
);
14646 locsymcount
= symtab_hdr
->sh_info
;
14647 end_lgot_ents
= lgot_ents
+ locsymcount
;
14648 local_plt
= (struct plt_entry
**) end_lgot_ents
;
14649 end_local_plt
= local_plt
+ locsymcount
;
14650 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
14651 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
14652 if (ent
->plt
.offset
!= (bfd_vma
) -1)
14654 Elf_Internal_Sym
*sym
;
14656 asection
*plt
, *relplt
;
14660 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
14661 lplt
- local_plt
, ibfd
))
14663 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14668 val
= sym
->st_value
+ ent
->addend
;
14669 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
14670 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
14672 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14674 htab
->elf
.ifunc_resolvers
= true;
14675 plt
= htab
->elf
.iplt
;
14676 relplt
= htab
->elf
.irelplt
;
14680 plt
= htab
->pltlocal
;
14682 if (bfd_link_pic (info
)
14683 && !(info
->enable_dt_relr
&& !htab
->opd_abi
))
14684 relplt
= htab
->relpltlocal
;
14687 if (relplt
== NULL
)
14689 loc
= plt
->contents
+ ent
->plt
.offset
;
14690 bfd_put_64 (info
->output_bfd
, val
, loc
);
14693 bfd_vma toc
= elf_gp (ibfd
);
14694 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
14699 Elf_Internal_Rela rela
;
14700 rela
.r_offset
= (ent
->plt
.offset
14701 + plt
->output_offset
14702 + plt
->output_section
->vma
);
14703 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14706 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
14708 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14713 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
14715 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14717 rela
.r_addend
= val
;
14718 loc
= relplt
->contents
+ (relplt
->reloc_count
++
14719 * sizeof (Elf64_External_Rela
));
14720 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
14724 if (local_syms
!= NULL
14725 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
14727 if (!info
->keep_memory
)
14730 symtab_hdr
->contents
= (unsigned char *) local_syms
;
14736 /* Emit the static wrapper function preserving registers around a
14737 __tls_get_addr_opt call. */
14740 emit_tga_desc (struct ppc_link_hash_table
*htab
)
14742 asection
*stub_sec
= htab
->tga_group
->stub_sec
;
14743 unsigned int cfa_updt
= 11 * 4;
14745 bfd_vma to
, from
, delta
;
14747 BFD_ASSERT (htab
->tga_desc_fd
->elf
.root
.type
== bfd_link_hash_defined
14748 && htab
->tga_desc_fd
->elf
.root
.u
.def
.section
== stub_sec
14749 && htab
->tga_desc_fd
->elf
.root
.u
.def
.value
== 0);
14750 to
= defined_sym_val (&htab
->tls_get_addr_fd
->elf
);
14751 from
= defined_sym_val (&htab
->tga_desc_fd
->elf
) + cfa_updt
;
14753 if (delta
+ (1 << 25) >= 1 << 26)
14755 _bfd_error_handler (_("__tls_get_addr call offset overflow"));
14756 htab
->stub_error
= true;
14760 p
= stub_sec
->contents
;
14761 p
= tls_get_addr_prologue (htab
->elf
.dynobj
, p
, htab
);
14762 bfd_put_32 (stub_sec
->owner
, B_DOT
| 1 | (delta
& 0x3fffffc), p
);
14764 p
= tls_get_addr_epilogue (htab
->elf
.dynobj
, p
, htab
);
14765 return stub_sec
->size
== (bfd_size_type
) (p
- stub_sec
->contents
);
14768 /* Emit eh_frame describing the static wrapper function. */
14771 emit_tga_desc_eh_frame (struct ppc_link_hash_table
*htab
, bfd_byte
*p
)
14773 unsigned int cfa_updt
= 11 * 4;
14776 *p
++ = DW_CFA_advance_loc
+ cfa_updt
/ 4;
14777 *p
++ = DW_CFA_def_cfa_offset
;
14785 *p
++ = DW_CFA_offset_extended_sf
;
14787 *p
++ = (-16 / 8) & 0x7f;
14788 for (i
= 4; i
< 12; i
++)
14790 *p
++ = DW_CFA_offset
+ i
;
14791 *p
++ = (htab
->opd_abi
? 13 : 12) - i
;
14793 *p
++ = DW_CFA_advance_loc
+ 10;
14794 *p
++ = DW_CFA_def_cfa_offset
;
14796 for (i
= 4; i
< 12; i
++)
14797 *p
++ = DW_CFA_restore
+ i
;
14798 *p
++ = DW_CFA_advance_loc
+ 2;
14799 *p
++ = DW_CFA_restore_extended
;
14804 /* Build all the stubs associated with the current output file.
14805 The stubs are kept in a hash table attached to the main linker
14806 hash table. This function is called via gldelf64ppc_finish. */
14809 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
14812 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
14813 struct map_stub
*group
;
14814 asection
*stub_sec
;
14816 int stub_sec_count
= 0;
14821 /* Allocate memory to hold the linker stubs. */
14822 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14824 group
->eh_size
= 0;
14825 group
->lr_restore
= 0;
14826 if ((stub_sec
= group
->stub_sec
) != NULL
14827 && stub_sec
->size
!= 0)
14829 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
14831 if (stub_sec
->contents
== NULL
)
14833 stub_sec
->size
= 0;
14837 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14842 /* Build the .glink plt call stub. */
14843 if (htab
->params
->emit_stub_syms
)
14845 struct elf_link_hash_entry
*h
;
14846 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
14847 true, false, false);
14850 if (h
->root
.type
== bfd_link_hash_new
)
14852 h
->root
.type
= bfd_link_hash_defined
;
14853 h
->root
.u
.def
.section
= htab
->glink
;
14854 h
->root
.u
.def
.value
= 8;
14855 h
->ref_regular
= 1;
14856 h
->def_regular
= 1;
14857 h
->ref_regular_nonweak
= 1;
14858 h
->forced_local
= 1;
14860 h
->root
.linker_def
= 1;
14863 plt0
= (htab
->elf
.splt
->output_section
->vma
14864 + htab
->elf
.splt
->output_offset
14866 if (info
->emitrelocations
)
14868 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
14871 r
->r_offset
= (htab
->glink
->output_offset
14872 + htab
->glink
->output_section
->vma
);
14873 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
14874 r
->r_addend
= plt0
;
14876 p
= htab
->glink
->contents
;
14877 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
14878 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
14882 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
14884 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14886 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14888 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
14890 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
14892 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
14894 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14896 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
14898 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14900 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
14908 . .quad plt0-1f # plt0 entry relative to 1:
14910 # We get here with r12 initially @ a glink branch
14911 # Load the address of _dl_runtime_resolve from plt0 and
14912 # jump to it, with r0 set to the index of the PLT entry
14913 # to be resolved and r11 the link map.
14914 __glink_PLTresolve:
14915 . std %r2,24(%r1) # optional
14921 . ld %r0,(0b-1b)(%r11)
14922 . sub %r12,%r12,%r11
14923 . add %r11,%r0,%r11
14924 . addi %r0,%r12,1b-2f
14931 . b __glink_PLTresolve
14933 . b __glink_PLTresolve */
14935 if (htab
->has_plt_localentry0
)
14937 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
14940 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
14942 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
14944 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
14946 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
14948 if (htab
->has_plt_localentry0
)
14949 insn
= LD_R0_0R11
| (-20 & 0xfffc);
14951 insn
= LD_R0_0R11
| (-16 & 0xfffc);
14952 bfd_put_32 (htab
->glink
->owner
, insn
, p
);
14954 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
14956 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R0_R11
, p
);
14958 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-44 & 0xffff), p
);
14960 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
14962 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
14964 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
14966 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
14969 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
14971 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
14973 /* Build the .glink lazy link call stubs. */
14975 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
14981 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
14986 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
14988 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
14993 bfd_put_32 (htab
->glink
->owner
,
14994 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
15000 if (htab
->tga_group
!= NULL
)
15002 htab
->tga_group
->lr_restore
= 23 * 4;
15003 htab
->tga_group
->stub_sec
->size
= 24 * 4;
15004 if (!emit_tga_desc (htab
))
15006 if (htab
->glink_eh_frame
!= NULL
15007 && htab
->glink_eh_frame
->size
!= 0)
15011 p
= htab
->glink_eh_frame
->contents
;
15012 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15014 htab
->tga_group
->eh_size
= emit_tga_desc_eh_frame (htab
, p
) - p
;
15018 /* Build .glink global entry stubs, and PLT relocs for globals. */
15019 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
15021 if (!write_plt_relocs_for_local_syms (info
))
15024 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
15026 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
15028 if (htab
->brlt
->contents
== NULL
)
15031 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
15033 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
15034 htab
->relbrlt
->size
);
15035 if (htab
->relbrlt
->contents
== NULL
)
15039 /* Build the stubs as directed by the stub hash table. */
15040 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
15042 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15043 if (group
->needs_save_res
)
15044 group
->stub_sec
->size
+= htab
->sfpr
->size
;
15046 if (htab
->relbrlt
!= NULL
)
15047 htab
->relbrlt
->reloc_count
= 0;
15049 if (htab
->params
->plt_stub_align
!= 0)
15050 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15051 if ((stub_sec
= group
->stub_sec
) != NULL
)
15053 int align
= abs (htab
->params
->plt_stub_align
);
15054 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
15057 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15058 if (group
->needs_save_res
)
15060 stub_sec
= group
->stub_sec
;
15061 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
15062 htab
->sfpr
->contents
, htab
->sfpr
->size
);
15063 if (htab
->params
->emit_stub_syms
)
15067 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
15068 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
15073 if (htab
->glink_eh_frame
!= NULL
15074 && htab
->glink_eh_frame
->size
!= 0)
15079 p
= htab
->glink_eh_frame
->contents
;
15080 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
15082 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15083 if (group
->eh_size
!= 0)
15085 /* Offset to stub section. */
15086 val
= (group
->stub_sec
->output_section
->vma
15087 + group
->stub_sec
->output_offset
);
15088 val
-= (htab
->glink_eh_frame
->output_section
->vma
15089 + htab
->glink_eh_frame
->output_offset
15090 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15091 if (val
+ 0x80000000 > 0xffffffff)
15094 (_("%s offset too large for .eh_frame sdata4 encoding"),
15095 group
->stub_sec
->name
);
15098 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
15099 p
+= (group
->eh_size
+ 17 + 3) & -4;
15101 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
15103 /* Offset to .glink. */
15104 val
= (htab
->glink
->output_section
->vma
15105 + htab
->glink
->output_offset
15107 val
-= (htab
->glink_eh_frame
->output_section
->vma
15108 + htab
->glink_eh_frame
->output_offset
15109 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
15110 if (val
+ 0x80000000 > 0xffffffff)
15113 (_("%s offset too large for .eh_frame sdata4 encoding"),
15114 htab
->glink
->name
);
15117 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
15118 p
+= (24 + align
- 1) & -align
;
15122 if (htab
->elf
.srelrdyn
!= NULL
&& htab
->elf
.srelrdyn
->size
!= 0)
15124 htab
->elf
.srelrdyn
->contents
15125 = bfd_alloc (htab
->elf
.dynobj
, htab
->elf
.srelrdyn
->size
);
15126 if (htab
->elf
.srelrdyn
->contents
== NULL
)
15130 bfd_byte
*loc
= htab
->elf
.srelrdyn
->contents
;
15131 while (i
< htab
->relr_count
)
15133 bfd_vma base
= htab
->relr_addr
[i
];
15134 BFD_ASSERT (base
% 2 == 0);
15135 bfd_put_64 (htab
->elf
.dynobj
, base
, loc
);
15138 while (i
< htab
->relr_count
15139 && htab
->relr_addr
[i
] == base
)
15141 htab
->stub_error
= true;
15148 while (i
< htab
->relr_count
15149 && htab
->relr_addr
[i
] - base
< 63 * 8
15150 && (htab
->relr_addr
[i
] - base
) % 8 == 0)
15152 bits
|= (bfd_vma
) 1 << ((htab
->relr_addr
[i
] - base
) / 8);
15157 bfd_put_64 (htab
->elf
.dynobj
, (bits
<< 1) | 1, loc
);
15162 /* Pad any excess with 1's, a do-nothing encoding. */
15163 while ((size_t) (loc
- htab
->elf
.srelrdyn
->contents
)
15164 < htab
->elf
.srelrdyn
->size
)
15166 bfd_put_64 (htab
->elf
.dynobj
, 1, loc
);
15171 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
15172 if ((stub_sec
= group
->stub_sec
) != NULL
)
15174 stub_sec_count
+= 1;
15175 if (stub_sec
->rawsize
!= stub_sec
->size
15176 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
15177 || stub_sec
->rawsize
< stub_sec
->size
))
15182 htab
->stub_error
= true;
15184 if (htab
->stub_error
)
15186 _bfd_error_handler (_("stubs don't match calculated size"));
15193 if (asprintf (&groupmsg
,
15194 ngettext ("linker stubs in %u group\n",
15195 "linker stubs in %u groups\n",
15197 stub_sec_count
) < 0)
15201 if (asprintf (stats
, _("%s"
15203 " long branch %lu\n"
15205 " global entry %lu"),
15207 htab
->stub_count
[ppc_stub_long_branch
- 1],
15208 htab
->stub_count
[ppc_stub_plt_branch
- 1],
15209 htab
->stub_count
[ppc_stub_plt_call
- 1],
15210 htab
->stub_count
[ppc_stub_global_entry
- 1]) < 0)
15218 /* What to do when ld finds relocations against symbols defined in
15219 discarded sections. */
15221 static unsigned int
15222 ppc64_elf_action_discarded (asection
*sec
)
15224 if (strcmp (".opd", sec
->name
) == 0)
15227 if (strcmp (".toc", sec
->name
) == 0)
15230 if (strcmp (".toc1", sec
->name
) == 0)
15233 return _bfd_elf_default_action_discarded (sec
);
15236 /* These are the dynamic relocations supported by glibc. */
15239 ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type
)
15243 case R_PPC64_RELATIVE
:
15245 case R_PPC64_ADDR64
:
15246 case R_PPC64_GLOB_DAT
:
15247 case R_PPC64_IRELATIVE
:
15248 case R_PPC64_JMP_IREL
:
15249 case R_PPC64_JMP_SLOT
:
15250 case R_PPC64_DTPMOD64
:
15251 case R_PPC64_DTPREL64
:
15252 case R_PPC64_TPREL64
:
15253 case R_PPC64_TPREL16_LO_DS
:
15254 case R_PPC64_TPREL16_DS
:
15255 case R_PPC64_TPREL16
:
15256 case R_PPC64_TPREL16_LO
:
15257 case R_PPC64_TPREL16_HI
:
15258 case R_PPC64_TPREL16_HIGH
:
15259 case R_PPC64_TPREL16_HA
:
15260 case R_PPC64_TPREL16_HIGHA
:
15261 case R_PPC64_TPREL16_HIGHER
:
15262 case R_PPC64_TPREL16_HIGHEST
:
15263 case R_PPC64_TPREL16_HIGHERA
:
15264 case R_PPC64_TPREL16_HIGHESTA
:
15265 case R_PPC64_ADDR16_LO_DS
:
15266 case R_PPC64_ADDR16_LO
:
15267 case R_PPC64_ADDR16_HI
:
15268 case R_PPC64_ADDR16_HIGH
:
15269 case R_PPC64_ADDR16_HA
:
15270 case R_PPC64_ADDR16_HIGHA
:
15271 case R_PPC64_REL30
:
15273 case R_PPC64_UADDR64
:
15274 case R_PPC64_UADDR32
:
15275 case R_PPC64_ADDR32
:
15276 case R_PPC64_ADDR24
:
15277 case R_PPC64_ADDR16
:
15278 case R_PPC64_UADDR16
:
15279 case R_PPC64_ADDR16_DS
:
15280 case R_PPC64_ADDR16_HIGHER
:
15281 case R_PPC64_ADDR16_HIGHEST
:
15282 case R_PPC64_ADDR16_HIGHERA
:
15283 case R_PPC64_ADDR16_HIGHESTA
:
15284 case R_PPC64_ADDR14
:
15285 case R_PPC64_ADDR14_BRTAKEN
:
15286 case R_PPC64_ADDR14_BRNTAKEN
:
15287 case R_PPC64_REL32
:
15288 case R_PPC64_REL64
:
15296 /* The RELOCATE_SECTION function is called by the ELF backend linker
15297 to handle the relocations for a section.
15299 The relocs are always passed as Rela structures; if the section
15300 actually uses Rel structures, the r_addend field will always be
15303 This function is responsible for adjust the section contents as
15304 necessary, and (if using Rela relocs and generating a
15305 relocatable output file) adjusting the reloc addend as
15308 This function does not have to worry about setting the reloc
15309 address or the reloc symbol index.
15311 LOCAL_SYMS is a pointer to the swapped in local symbols.
15313 LOCAL_SECTIONS is an array giving the section in the input file
15314 corresponding to the st_shndx field of each local symbol.
15316 The global hash table entry for the global symbols can be found
15317 via elf_sym_hashes (input_bfd).
15319 When generating relocatable output, this function must handle
15320 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
15321 going to be the section symbol corresponding to the output
15322 section, which means that the addend must be adjusted
15326 ppc64_elf_relocate_section (bfd
*output_bfd
,
15327 struct bfd_link_info
*info
,
15329 asection
*input_section
,
15330 bfd_byte
*contents
,
15331 Elf_Internal_Rela
*relocs
,
15332 Elf_Internal_Sym
*local_syms
,
15333 asection
**local_sections
)
15335 struct ppc_link_hash_table
*htab
;
15336 Elf_Internal_Shdr
*symtab_hdr
;
15337 struct elf_link_hash_entry
**sym_hashes
;
15338 Elf_Internal_Rela
*rel
;
15339 Elf_Internal_Rela
*wrel
;
15340 Elf_Internal_Rela
*relend
;
15341 Elf_Internal_Rela outrel
;
15343 struct got_entry
**local_got_ents
;
15347 /* Assume 'at' branch hints. */
15348 bool is_isa_v2
= true;
15349 bool warned_dynamic
= false;
15350 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
15352 /* Initialize howto table if needed. */
15353 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
15356 htab
= ppc_hash_table (info
);
15360 /* Don't relocate stub sections. */
15361 if (input_section
->owner
== htab
->params
->stub_bfd
)
15364 if (!is_ppc64_elf (input_bfd
))
15366 bfd_set_error (bfd_error_wrong_format
);
15370 local_got_ents
= elf_local_got_ents (input_bfd
);
15371 TOCstart
= elf_gp (output_bfd
);
15372 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
15373 sym_hashes
= elf_sym_hashes (input_bfd
);
15374 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
15376 rel
= wrel
= relocs
;
15377 relend
= relocs
+ input_section
->reloc_count
;
15378 for (; rel
< relend
; wrel
++, rel
++)
15380 enum elf_ppc64_reloc_type r_type
;
15382 bfd_reloc_status_type r
;
15383 Elf_Internal_Sym
*sym
;
15385 struct elf_link_hash_entry
*h_elf
;
15386 struct ppc_link_hash_entry
*h
;
15387 struct ppc_link_hash_entry
*fdh
;
15388 const char *sym_name
;
15389 unsigned long r_symndx
, toc_symndx
;
15390 bfd_vma toc_addend
;
15391 unsigned char tls_mask
, tls_gd
, tls_type
;
15392 unsigned char sym_type
;
15393 bfd_vma relocation
;
15394 bool unresolved_reloc
, save_unresolved_reloc
;
15396 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
15399 struct ppc_stub_hash_entry
*stub_entry
;
15400 bfd_vma max_br_offset
;
15402 Elf_Internal_Rela orig_rel
;
15403 reloc_howto_type
*howto
;
15404 struct reloc_howto_struct alt_howto
;
15411 r_type
= ELF64_R_TYPE (rel
->r_info
);
15412 r_symndx
= ELF64_R_SYM (rel
->r_info
);
15414 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
15415 symbol of the previous ADDR64 reloc. The symbol gives us the
15416 proper TOC base to use. */
15417 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
15419 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
15421 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
15427 unresolved_reloc
= false;
15430 if (r_symndx
< symtab_hdr
->sh_info
)
15432 /* It's a local symbol. */
15433 struct _opd_sec_data
*opd
;
15435 sym
= local_syms
+ r_symndx
;
15436 sec
= local_sections
[r_symndx
];
15437 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
15438 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
15439 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
15440 opd
= get_opd_info (sec
);
15441 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
15443 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
15449 /* If this is a relocation against the opd section sym
15450 and we have edited .opd, adjust the reloc addend so
15451 that ld -r and ld --emit-relocs output is correct.
15452 If it is a reloc against some other .opd symbol,
15453 then the symbol value will be adjusted later. */
15454 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
15455 rel
->r_addend
+= adjust
;
15457 relocation
+= adjust
;
15465 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
15466 r_symndx
, symtab_hdr
, sym_hashes
,
15467 h_elf
, sec
, relocation
,
15468 unresolved_reloc
, warned
, ignored
);
15469 sym_name
= h_elf
->root
.root
.string
;
15470 sym_type
= h_elf
->type
;
15472 && sec
->owner
== output_bfd
15473 && strcmp (sec
->name
, ".opd") == 0)
15475 /* This is a symbol defined in a linker script. All
15476 such are defined in output sections, even those
15477 defined by simple assignment from a symbol defined in
15478 an input section. Transfer the symbol to an
15479 appropriate input .opd section, so that a branch to
15480 this symbol will be mapped to the location specified
15481 by the opd entry. */
15482 struct bfd_link_order
*lo
;
15483 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
15484 if (lo
->type
== bfd_indirect_link_order
)
15486 asection
*isec
= lo
->u
.indirect
.section
;
15487 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
15488 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
15491 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
15492 h_elf
->root
.u
.def
.section
= isec
;
15499 h
= ppc_elf_hash_entry (h_elf
);
15501 if (sec
!= NULL
&& discarded_section (sec
))
15503 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
15504 input_bfd
, input_section
,
15505 contents
, rel
->r_offset
);
15506 wrel
->r_offset
= rel
->r_offset
;
15508 wrel
->r_addend
= 0;
15510 /* For ld -r, remove relocations in debug sections against
15511 symbols defined in discarded sections. Not done for
15512 non-debug to preserve relocs in .eh_frame which the
15513 eh_frame editing code expects to be present. */
15514 if (bfd_link_relocatable (info
)
15515 && (input_section
->flags
& SEC_DEBUGGING
))
15521 if (bfd_link_relocatable (info
))
15524 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
15526 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15527 sec
= bfd_abs_section_ptr
;
15528 unresolved_reloc
= false;
15531 /* TLS optimizations. Replace instruction sequences and relocs
15532 based on information we collected in tls_optimize. We edit
15533 RELOCS so that --emit-relocs will output something sensible
15534 for the final instruction stream. */
15539 tls_mask
= h
->tls_mask
;
15540 else if (local_got_ents
!= NULL
)
15542 struct plt_entry
**local_plt
= (struct plt_entry
**)
15543 (local_got_ents
+ symtab_hdr
->sh_info
);
15544 unsigned char *lgot_masks
= (unsigned char *)
15545 (local_plt
+ symtab_hdr
->sh_info
);
15546 tls_mask
= lgot_masks
[r_symndx
];
15548 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
15549 && (r_type
== R_PPC64_TLS
15550 || r_type
== R_PPC64_TLSGD
15551 || r_type
== R_PPC64_TLSLD
))
15553 /* Check for toc tls entries. */
15554 unsigned char *toc_tls
;
15556 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15557 &local_syms
, rel
, input_bfd
))
15561 tls_mask
= *toc_tls
;
15564 /* Check that tls relocs are used with tls syms, and non-tls
15565 relocs are used with non-tls syms. */
15566 if (r_symndx
!= STN_UNDEF
15567 && r_type
!= R_PPC64_NONE
15569 || h
->elf
.root
.type
== bfd_link_hash_defined
15570 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
15571 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
15573 if ((tls_mask
& TLS_TLS
) != 0
15574 && (r_type
== R_PPC64_TLS
15575 || r_type
== R_PPC64_TLSGD
15576 || r_type
== R_PPC64_TLSLD
))
15577 /* R_PPC64_TLS is OK against a symbol in the TOC. */
15580 info
->callbacks
->einfo
15581 (!IS_PPC64_TLS_RELOC (r_type
)
15582 /* xgettext:c-format */
15583 ? _("%H: %s used with TLS symbol `%pT'\n")
15584 /* xgettext:c-format */
15585 : _("%H: %s used with non-TLS symbol `%pT'\n"),
15586 input_bfd
, input_section
, rel
->r_offset
,
15587 ppc64_elf_howto_table
[r_type
]->name
,
15591 /* Ensure reloc mapping code below stays sane. */
15592 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
15593 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
15594 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
15595 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
15596 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
15597 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
15598 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
15599 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
15600 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
15601 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
15609 case R_PPC64_LO_DS_OPT
:
15610 if (offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15612 insn
= bfd_get_32 (input_bfd
,
15613 contents
+ rel
->r_offset
- d_offset
);
15614 if ((insn
& (0x3fu
<< 26)) != 58u << 26)
15616 insn
+= (14u << 26) - (58u << 26);
15617 bfd_put_32 (input_bfd
, insn
,
15618 contents
+ rel
->r_offset
- d_offset
);
15619 r_type
= R_PPC64_TOC16_LO
;
15620 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15624 case R_PPC64_TOC16
:
15625 case R_PPC64_TOC16_LO
:
15626 case R_PPC64_TOC16_DS
:
15627 case R_PPC64_TOC16_LO_DS
:
15629 /* Check for toc tls entries. */
15630 unsigned char *toc_tls
;
15633 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
15634 &local_syms
, rel
, input_bfd
);
15640 tls_mask
= *toc_tls
;
15641 if (r_type
== R_PPC64_TOC16_DS
15642 || r_type
== R_PPC64_TOC16_LO_DS
)
15644 if ((tls_mask
& TLS_TLS
) != 0
15645 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
15650 /* If we found a GD reloc pair, then we might be
15651 doing a GD->IE transition. */
15655 if ((tls_mask
& TLS_TLS
) != 0
15656 && (tls_mask
& TLS_GD
) == 0)
15659 else if (retval
== 3)
15661 if ((tls_mask
& TLS_TLS
) != 0
15662 && (tls_mask
& TLS_LD
) == 0)
15670 case R_PPC64_GOT_TPREL16_HI
:
15671 case R_PPC64_GOT_TPREL16_HA
:
15672 if ((tls_mask
& TLS_TLS
) != 0
15673 && (tls_mask
& TLS_TPREL
) == 0
15674 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15676 rel
->r_offset
-= d_offset
;
15677 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15678 r_type
= R_PPC64_NONE
;
15679 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15683 case R_PPC64_GOT_TPREL16_DS
:
15684 case R_PPC64_GOT_TPREL16_LO_DS
:
15685 if ((tls_mask
& TLS_TLS
) != 0
15686 && (tls_mask
& TLS_TPREL
) == 0
15687 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
15690 insn
= bfd_get_32 (input_bfd
,
15691 contents
+ rel
->r_offset
- d_offset
);
15693 insn
|= 0x3c0d0000; /* addis 0,13,0 */
15694 bfd_put_32 (input_bfd
, insn
,
15695 contents
+ rel
->r_offset
- d_offset
);
15696 r_type
= R_PPC64_TPREL16_HA
;
15697 if (toc_symndx
!= 0)
15699 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15700 rel
->r_addend
= toc_addend
;
15701 /* We changed the symbol. Start over in order to
15702 get h, sym, sec etc. right. */
15706 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15710 case R_PPC64_GOT_TPREL_PCREL34
:
15711 if ((tls_mask
& TLS_TLS
) != 0
15712 && (tls_mask
& TLS_TPREL
) == 0
15713 && offset_in_range (input_section
, rel
->r_offset
, 8))
15715 /* pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel */
15716 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15718 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15719 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
15720 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
15721 bfd_put_32 (input_bfd
, pinsn
>> 32,
15722 contents
+ rel
->r_offset
);
15723 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15724 contents
+ rel
->r_offset
+ 4);
15725 r_type
= R_PPC64_TPREL34
;
15726 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15731 if ((tls_mask
& TLS_TLS
) != 0
15732 && (tls_mask
& TLS_TPREL
) == 0
15733 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15735 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15736 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
15739 if ((rel
->r_offset
& 3) == 0)
15741 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15742 /* Was PPC64_TLS which sits on insn boundary, now
15743 PPC64_TPREL16_LO which is at low-order half-word. */
15744 rel
->r_offset
+= d_offset
;
15745 r_type
= R_PPC64_TPREL16_LO
;
15746 if (toc_symndx
!= 0)
15748 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
15749 rel
->r_addend
= toc_addend
;
15750 /* We changed the symbol. Start over in order to
15751 get h, sym, sec etc. right. */
15755 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15757 else if ((rel
->r_offset
& 3) == 1)
15759 /* For pcrel IE to LE we already have the full
15760 offset and thus don't need an addi here. A nop
15762 if ((insn
& (0x3fu
<< 26)) == 14 << 26)
15764 /* Extract regs from addi rt,ra,si. */
15765 unsigned int rt
= (insn
>> 21) & 0x1f;
15766 unsigned int ra
= (insn
>> 16) & 0x1f;
15771 /* Build or ra,rs,rb with rb==rs, ie. mr ra,rs. */
15772 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
15773 insn
|= (31u << 26) | (444u << 1);
15776 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- 1);
15781 case R_PPC64_GOT_TLSGD16_HI
:
15782 case R_PPC64_GOT_TLSGD16_HA
:
15784 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15785 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15789 case R_PPC64_GOT_TLSLD16_HI
:
15790 case R_PPC64_GOT_TLSLD16_HA
:
15791 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15792 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15795 if ((tls_mask
& tls_gd
) != 0)
15796 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
15797 + R_PPC64_GOT_TPREL16_DS
);
15800 rel
->r_offset
-= d_offset
;
15801 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15802 r_type
= R_PPC64_NONE
;
15804 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15808 case R_PPC64_GOT_TLSGD16
:
15809 case R_PPC64_GOT_TLSGD16_LO
:
15811 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15812 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15816 case R_PPC64_GOT_TLSLD16
:
15817 case R_PPC64_GOT_TLSLD16_LO
:
15818 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15819 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
15821 unsigned int insn1
, insn2
;
15824 offset
= (bfd_vma
) -1;
15825 /* If not using the newer R_PPC64_TLSGD/LD to mark
15826 __tls_get_addr calls, we must trust that the call
15827 stays with its arg setup insns, ie. that the next
15828 reloc is the __tls_get_addr call associated with
15829 the current reloc. Edit both insns. */
15830 if (input_section
->nomark_tls_get_addr
15831 && rel
+ 1 < relend
15832 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
15833 htab
->tls_get_addr_fd
,
15835 htab
->tls_get_addr
,
15837 offset
= rel
[1].r_offset
;
15838 /* We read the low GOT_TLS (or TOC16) insn because we
15839 need to keep the destination reg. It may be
15840 something other than the usual r3, and moved to r3
15841 before the call by intervening code. */
15842 insn1
= bfd_get_32 (input_bfd
,
15843 contents
+ rel
->r_offset
- d_offset
);
15844 if ((tls_mask
& tls_gd
) != 0)
15847 insn1
&= (0x1f << 21) | (0x1f << 16);
15848 insn1
|= 58u << 26; /* ld */
15849 insn2
= 0x7c636a14; /* add 3,3,13 */
15850 if (offset
!= (bfd_vma
) -1)
15851 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15852 if (r_type
== R_PPC64_TOC16
15853 || r_type
== R_PPC64_TOC16_LO
)
15854 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
15856 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 1)) & 1)
15857 + R_PPC64_GOT_TPREL16_DS
);
15858 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15863 insn1
&= 0x1f << 21;
15864 insn1
|= 0x3c0d0000; /* addis r,13,0 */
15865 insn2
= 0x38630000; /* addi 3,3,0 */
15868 /* Was an LD reloc. */
15869 r_symndx
= STN_UNDEF
;
15870 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15872 else if (toc_symndx
!= 0)
15874 r_symndx
= toc_symndx
;
15875 rel
->r_addend
= toc_addend
;
15877 r_type
= R_PPC64_TPREL16_HA
;
15878 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15879 if (offset
!= (bfd_vma
) -1)
15881 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
15882 R_PPC64_TPREL16_LO
);
15883 rel
[1].r_offset
= offset
+ d_offset
;
15884 rel
[1].r_addend
= rel
->r_addend
;
15887 bfd_put_32 (input_bfd
, insn1
,
15888 contents
+ rel
->r_offset
- d_offset
);
15889 if (offset
!= (bfd_vma
) -1
15890 && offset_in_range (input_section
, offset
, 4))
15892 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
15893 if (offset_in_range (input_section
, offset
+ 4, 4))
15895 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15896 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
15897 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
15900 if ((tls_mask
& tls_gd
) == 0
15901 && (tls_gd
== 0 || toc_symndx
!= 0))
15903 /* We changed the symbol. Start over in order
15904 to get h, sym, sec etc. right. */
15910 case R_PPC64_GOT_TLSGD_PCREL34
:
15911 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15912 && offset_in_range (input_section
, rel
->r_offset
, 8))
15914 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15916 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15917 if ((tls_mask
& TLS_GDIE
) != 0)
15919 /* IE, pla -> pld */
15920 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
15921 r_type
= R_PPC64_GOT_TPREL_PCREL34
;
15925 /* LE, pla pcrel -> paddi r13 */
15926 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15927 r_type
= R_PPC64_TPREL34
;
15929 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15930 bfd_put_32 (input_bfd
, pinsn
>> 32,
15931 contents
+ rel
->r_offset
);
15932 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15933 contents
+ rel
->r_offset
+ 4);
15937 case R_PPC64_GOT_TLSLD_PCREL34
:
15938 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
15939 && offset_in_range (input_section
, rel
->r_offset
, 8))
15941 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15943 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15944 pinsn
+= (-1ULL << 52) + (13ULL << 16);
15945 bfd_put_32 (input_bfd
, pinsn
>> 32,
15946 contents
+ rel
->r_offset
);
15947 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
15948 contents
+ rel
->r_offset
+ 4);
15949 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15950 r_symndx
= STN_UNDEF
;
15951 r_type
= R_PPC64_TPREL34
;
15952 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15957 case R_PPC64_TLSGD
:
15958 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
15959 && rel
+ 1 < relend
15960 && offset_in_range (input_section
, rel
->r_offset
,
15961 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
15964 unsigned int insn2
;
15965 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
15967 offset
= rel
->r_offset
;
15968 if (is_plt_seq_reloc (r_type1
))
15970 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
15971 if (r_type1
== R_PPC64_PLT_PCREL34
15972 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
15973 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15974 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
15978 if (r_type1
== R_PPC64_PLTCALL
)
15979 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
15981 if ((tls_mask
& TLS_GDIE
) != 0)
15984 r_type
= R_PPC64_NONE
;
15985 insn2
= 0x7c636a14; /* add 3,3,13 */
15990 if (toc_symndx
!= 0)
15992 r_symndx
= toc_symndx
;
15993 rel
->r_addend
= toc_addend
;
15995 if (r_type1
== R_PPC64_REL24_NOTOC
15996 || r_type1
== R_PPC64_REL24_P9NOTOC
15997 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
15999 r_type
= R_PPC64_NONE
;
16004 rel
->r_offset
= offset
+ d_offset
;
16005 r_type
= R_PPC64_TPREL16_LO
;
16006 insn2
= 0x38630000; /* addi 3,3,0 */
16009 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16010 /* Zap the reloc on the _tls_get_addr call too. */
16011 BFD_ASSERT (offset
== rel
[1].r_offset
);
16012 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16013 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16014 if ((tls_mask
& TLS_GDIE
) == 0
16016 && r_type
!= R_PPC64_NONE
)
16021 case R_PPC64_TLSLD
:
16022 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
16023 && rel
+ 1 < relend
16024 && offset_in_range (input_section
, rel
->r_offset
,
16025 is_8byte_reloc (ELF64_R_TYPE (rel
[1].r_info
))
16028 unsigned int insn2
;
16029 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
16031 offset
= rel
->r_offset
;
16032 if (is_plt_seq_reloc (r_type1
))
16034 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
16035 if (r_type1
== R_PPC64_PLT_PCREL34
16036 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
16037 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16038 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16042 if (r_type1
== R_PPC64_PLTCALL
)
16043 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
16045 if (r_type1
== R_PPC64_REL24_NOTOC
16046 || r_type1
== R_PPC64_REL24_P9NOTOC
16047 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
16049 r_type
= R_PPC64_NONE
;
16054 rel
->r_offset
= offset
+ d_offset
;
16055 r_symndx
= STN_UNDEF
;
16056 r_type
= R_PPC64_TPREL16_LO
;
16057 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16058 insn2
= 0x38630000; /* addi 3,3,0 */
16060 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16061 /* Zap the reloc on the _tls_get_addr call too. */
16062 BFD_ASSERT (offset
== rel
[1].r_offset
);
16063 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
16064 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
16065 if (r_type
!= R_PPC64_NONE
)
16070 case R_PPC64_DTPMOD64
:
16071 if (rel
+ 1 < relend
16072 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
16073 && rel
[1].r_offset
== rel
->r_offset
+ 8)
16075 if ((tls_mask
& TLS_GD
) == 0
16076 && offset_in_range (input_section
, rel
->r_offset
, 8))
16078 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
16079 if ((tls_mask
& TLS_GDIE
) != 0)
16080 r_type
= R_PPC64_TPREL64
;
16083 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
16084 r_type
= R_PPC64_NONE
;
16086 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16091 if ((tls_mask
& TLS_LD
) == 0
16092 && offset_in_range (input_section
, rel
->r_offset
, 8))
16094 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
16095 r_type
= R_PPC64_NONE
;
16096 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16101 case R_PPC64_TPREL64
:
16102 if ((tls_mask
& TLS_TPREL
) == 0)
16104 r_type
= R_PPC64_NONE
;
16105 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16109 case R_PPC64_ENTRY
:
16110 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16111 if (!bfd_link_pic (info
)
16112 && !info
->traditional_format
16113 && relocation
+ 0x80008000 <= 0xffffffff
16114 && offset_in_range (input_section
, rel
->r_offset
, 8))
16116 unsigned int insn1
, insn2
;
16118 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16119 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16120 if ((insn1
& ~0xfffc) == LD_R2_0R12
16121 && insn2
== ADD_R2_R2_R12
)
16123 bfd_put_32 (input_bfd
,
16124 LIS_R2
+ PPC_HA (relocation
),
16125 contents
+ rel
->r_offset
);
16126 bfd_put_32 (input_bfd
,
16127 ADDI_R2_R2
+ PPC_LO (relocation
),
16128 contents
+ rel
->r_offset
+ 4);
16133 relocation
-= (rel
->r_offset
16134 + input_section
->output_offset
16135 + input_section
->output_section
->vma
);
16136 if (relocation
+ 0x80008000 <= 0xffffffff
16137 && offset_in_range (input_section
, rel
->r_offset
, 8))
16139 unsigned int insn1
, insn2
;
16141 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16142 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16143 if ((insn1
& ~0xfffc) == LD_R2_0R12
16144 && insn2
== ADD_R2_R2_R12
)
16146 bfd_put_32 (input_bfd
,
16147 ADDIS_R2_R12
+ PPC_HA (relocation
),
16148 contents
+ rel
->r_offset
);
16149 bfd_put_32 (input_bfd
,
16150 ADDI_R2_R2
+ PPC_LO (relocation
),
16151 contents
+ rel
->r_offset
+ 4);
16157 case R_PPC64_REL16_HA
:
16158 /* If we are generating a non-PIC executable, edit
16159 . 0: addis 2,12,.TOC.-0b@ha
16160 . addi 2,2,.TOC.-0b@l
16161 used by ELFv2 global entry points to set up r2, to
16164 if .TOC. is in range. */
16165 if (!bfd_link_pic (info
)
16166 && !info
->traditional_format
16168 && rel
->r_addend
== d_offset
16169 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
16170 && rel
+ 1 < relend
16171 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
16172 && rel
[1].r_offset
== rel
->r_offset
+ 4
16173 && rel
[1].r_addend
== rel
->r_addend
+ 4
16174 && relocation
+ 0x80008000 <= 0xffffffff
16175 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 8))
16177 unsigned int insn1
, insn2
;
16178 offset
= rel
->r_offset
- d_offset
;
16179 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
16180 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16181 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
16182 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
16184 r_type
= R_PPC64_ADDR16_HA
;
16185 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16186 rel
->r_addend
-= d_offset
;
16187 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
16188 rel
[1].r_addend
-= d_offset
+ 4;
16189 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
16195 /* Handle other relocations that tweak non-addend part of insn. */
16197 max_br_offset
= 1 << 25;
16198 addend
= rel
->r_addend
;
16199 reloc_dest
= DEST_NORMAL
;
16205 case R_PPC64_TOCSAVE
:
16206 if (relocation
+ addend
== (rel
->r_offset
16207 + input_section
->output_offset
16208 + input_section
->output_section
->vma
)
16209 && tocsave_find (htab
, NO_INSERT
,
16210 &local_syms
, rel
, input_bfd
)
16211 && offset_in_range (input_section
, rel
->r_offset
, 4))
16213 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16215 || insn
== CROR_151515
|| insn
== CROR_313131
)
16216 bfd_put_32 (input_bfd
,
16217 STD_R2_0R1
+ STK_TOC (htab
),
16218 contents
+ rel
->r_offset
);
16222 /* Branch taken prediction relocations. */
16223 case R_PPC64_ADDR14_BRTAKEN
:
16224 case R_PPC64_REL14_BRTAKEN
:
16225 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
16226 /* Fall through. */
16228 /* Branch not taken prediction relocations. */
16229 case R_PPC64_ADDR14_BRNTAKEN
:
16230 case R_PPC64_REL14_BRNTAKEN
:
16231 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
16233 insn
|= bfd_get_32 (input_bfd
,
16234 contents
+ rel
->r_offset
) & ~(0x01 << 21);
16235 /* Fall through. */
16237 case R_PPC64_REL14
:
16238 max_br_offset
= 1 << 15;
16239 /* Fall through. */
16241 case R_PPC64_REL24
:
16242 case R_PPC64_REL24_NOTOC
:
16243 case R_PPC64_REL24_P9NOTOC
:
16244 case R_PPC64_PLTCALL
:
16245 case R_PPC64_PLTCALL_NOTOC
:
16246 /* Calls to functions with a different TOC, such as calls to
16247 shared objects, need to alter the TOC pointer. This is
16248 done using a linkage stub. A REL24 branching to these
16249 linkage stubs needs to be followed by a nop, as the nop
16250 will be replaced with an instruction to restore the TOC
16255 && h
->oh
->is_func_descriptor
)
16256 fdh
= ppc_follow_link (h
->oh
);
16257 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
16259 if ((r_type
== R_PPC64_PLTCALL
16260 || r_type
== R_PPC64_PLTCALL_NOTOC
)
16261 && stub_entry
!= NULL
16262 && stub_entry
->type
.main
== ppc_stub_plt_call
)
16265 if (stub_entry
!= NULL
16266 && (stub_entry
->type
.main
== ppc_stub_plt_call
16267 || stub_entry
->type
.r2save
))
16269 bool can_plt_call
= false;
16271 if (r_type
== R_PPC64_REL24_NOTOC
16272 || r_type
== R_PPC64_REL24_P9NOTOC
)
16274 /* NOTOC calls don't need to restore r2. */
16275 can_plt_call
= true;
16277 else if (stub_entry
->type
.main
== ppc_stub_plt_call
16279 && htab
->params
->plt_localentry0
!= 0
16281 && is_elfv2_localentry0 (&h
->elf
))
16283 /* The function doesn't use or change r2. */
16284 can_plt_call
= true;
16287 /* All of these stubs may modify r2, so there must be a
16288 branch and link followed by a nop. The nop is
16289 replaced by an insn to restore r2. */
16290 else if (offset_in_range (input_section
, rel
->r_offset
, 8))
16294 br
= bfd_get_32 (input_bfd
,
16295 contents
+ rel
->r_offset
);
16300 nop
= bfd_get_32 (input_bfd
,
16301 contents
+ rel
->r_offset
+ 4);
16302 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
16303 can_plt_call
= true;
16304 else if (nop
== NOP
16305 || nop
== CROR_151515
16306 || nop
== CROR_313131
)
16309 && is_tls_get_addr (&h
->elf
, htab
)
16310 && htab
->params
->tls_get_addr_opt
)
16312 /* Special stub used, leave nop alone. */
16315 bfd_put_32 (input_bfd
,
16316 LD_R2_0R1
+ STK_TOC (htab
),
16317 contents
+ rel
->r_offset
+ 4);
16318 can_plt_call
= true;
16323 if (!can_plt_call
&& h
!= NULL
)
16325 const char *name
= h
->elf
.root
.root
.string
;
16330 if (startswith (name
, "__libc_start_main")
16331 && (name
[17] == 0 || name
[17] == '@'))
16333 /* Allow crt1 branch to go via a toc adjusting
16334 stub. Other calls that never return could do
16335 the same, if we could detect such. */
16336 can_plt_call
= true;
16342 /* g++ as of 20130507 emits self-calls without a
16343 following nop. This is arguably wrong since we
16344 have conflicting information. On the one hand a
16345 global symbol and on the other a local call
16346 sequence, but don't error for this special case.
16347 It isn't possible to cheaply verify we have
16348 exactly such a call. Allow all calls to the same
16350 asection
*code_sec
= sec
;
16352 if (get_opd_info (sec
) != NULL
)
16354 bfd_vma off
= (relocation
+ addend
16355 - sec
->output_section
->vma
16356 - sec
->output_offset
);
16358 opd_entry_value (sec
, off
, &code_sec
, NULL
, false);
16360 if (code_sec
== input_section
)
16361 can_plt_call
= true;
16366 if (stub_entry
->type
.main
== ppc_stub_plt_call
)
16367 info
->callbacks
->einfo
16368 /* xgettext:c-format */
16369 (_("%H: call to `%pT' lacks nop, can't restore toc; "
16370 "(plt call stub)\n"),
16371 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
16373 info
->callbacks
->einfo
16374 /* xgettext:c-format */
16375 (_("%H: call to `%pT' lacks nop, can't restore toc; "
16376 "(toc save/adjust stub)\n"),
16377 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
16379 bfd_set_error (bfd_error_bad_value
);
16384 && stub_entry
->type
.main
== ppc_stub_plt_call
)
16385 unresolved_reloc
= false;
16388 if ((stub_entry
== NULL
16389 || stub_entry
->type
.main
== ppc_stub_long_branch
16390 || stub_entry
->type
.main
== ppc_stub_plt_branch
)
16391 && get_opd_info (sec
) != NULL
)
16393 /* The branch destination is the value of the opd entry. */
16394 bfd_vma off
= (relocation
+ addend
16395 - sec
->output_section
->vma
16396 - sec
->output_offset
);
16397 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, false);
16398 if (dest
!= (bfd_vma
) -1)
16402 reloc_dest
= DEST_OPD
;
16406 /* If the branch is out of reach we ought to have a long
16408 from
= (rel
->r_offset
16409 + input_section
->output_offset
16410 + input_section
->output_section
->vma
);
16412 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
16416 if (stub_entry
!= NULL
16417 && (stub_entry
->type
.main
== ppc_stub_long_branch
16418 || stub_entry
->type
.main
== ppc_stub_plt_branch
))
16420 if (stub_entry
->type
.sub
== ppc_stub_toc
16421 && !stub_entry
->type
.r2save
16422 && (r_type
== R_PPC64_ADDR14_BRTAKEN
16423 || r_type
== R_PPC64_ADDR14_BRNTAKEN
16424 || (relocation
+ addend
- from
+ max_br_offset
16425 < 2 * max_br_offset
)))
16426 /* Don't use the stub if this branch is in range. */
16429 if (stub_entry
!= NULL
16430 && stub_entry
->type
.sub
>= ppc_stub_notoc
16431 && ((r_type
!= R_PPC64_REL24_NOTOC
16432 && r_type
!= R_PPC64_REL24_P9NOTOC
)
16433 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
16434 & STO_PPC64_LOCAL_MASK
) <= 1 << STO_PPC64_LOCAL_BIT
)
16435 && (relocation
+ addend
- from
+ max_br_offset
16436 < 2 * max_br_offset
))
16439 if (stub_entry
!= NULL
16440 && stub_entry
->type
.r2save
16441 && (r_type
== R_PPC64_REL24_NOTOC
16442 || r_type
== R_PPC64_REL24_P9NOTOC
)
16443 && (relocation
+ addend
- from
+ max_br_offset
16444 < 2 * max_br_offset
))
16448 if (stub_entry
!= NULL
)
16450 /* Munge up the value and addend so that we call the stub
16451 rather than the procedure directly. */
16452 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
16454 if (stub_entry
->type
.main
== ppc_stub_save_res
)
16455 relocation
+= (stub_sec
->output_offset
16456 + stub_sec
->output_section
->vma
16457 + stub_sec
->size
- htab
->sfpr
->size
16458 - htab
->sfpr
->output_offset
16459 - htab
->sfpr
->output_section
->vma
);
16461 relocation
= (stub_entry
->stub_offset
16462 + stub_sec
->output_offset
16463 + stub_sec
->output_section
->vma
);
16465 reloc_dest
= DEST_STUB
;
16467 if (((stub_entry
->type
.r2save
16468 && (r_type
== R_PPC64_REL24_NOTOC
16469 || r_type
== R_PPC64_REL24_P9NOTOC
))
16470 || ((stub_entry
->type
.main
== ppc_stub_plt_call
16471 && (ALWAYS_EMIT_R2SAVE
|| stub_entry
->type
.r2save
))
16472 && rel
+ 1 < relend
16473 && rel
[1].r_offset
== rel
->r_offset
+ 4
16474 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
))
16475 && !(stub_entry
->type
.main
== ppc_stub_plt_call
16476 && htab
->params
->tls_get_addr_opt
16478 && is_tls_get_addr (&h
->elf
, htab
)))
16480 /* Skip over the r2 store at the start of the stub. */
16484 if ((r_type
== R_PPC64_REL24_NOTOC
16485 || r_type
== R_PPC64_REL24_P9NOTOC
)
16486 && stub_entry
->type
.main
== ppc_stub_plt_call
16487 && stub_entry
->type
.sub
>= ppc_stub_notoc
)
16488 htab
->notoc_plt
= 1;
16495 /* Set 'a' bit. This is 0b00010 in BO field for branch
16496 on CR(BI) insns (BO == 001at or 011at), and 0b01000
16497 for branch on CTR insns (BO == 1a00t or 1a01t). */
16498 if ((insn
& (0x14 << 21)) == (0x04 << 21))
16499 insn
|= 0x02 << 21;
16500 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
16501 insn
|= 0x08 << 21;
16507 /* Invert 'y' bit if not the default. */
16508 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
16509 insn
^= 0x01 << 21;
16512 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
16515 /* NOP out calls to undefined weak functions.
16516 We can thus call a weak function without first
16517 checking whether the function is defined. */
16519 && h
->elf
.root
.type
== bfd_link_hash_undefweak
16520 && h
->elf
.dynindx
== -1
16521 && (r_type
== R_PPC64_REL24
16522 || r_type
== R_PPC64_REL24_NOTOC
16523 || r_type
== R_PPC64_REL24_P9NOTOC
)
16526 && offset_in_range (input_section
, rel
->r_offset
, 4))
16528 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
16533 case R_PPC64_GOT16_DS
:
16534 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16535 || !htab
->do_toc_opt
)
16537 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16538 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
16540 && sec
->output_section
!= NULL
16541 && !discarded_section (sec
)
16542 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16543 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16545 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16546 if ((insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16548 insn
+= (14u << 26) - (58u << 26);
16549 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16550 r_type
= R_PPC64_TOC16
;
16551 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16556 case R_PPC64_GOT16_LO_DS
:
16557 case R_PPC64_GOT16_HA
:
16558 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16559 || !htab
->do_toc_opt
)
16561 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
16562 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
16564 && sec
->output_section
!= NULL
16565 && !discarded_section (sec
)
16566 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16567 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
16569 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16570 if (r_type
== R_PPC64_GOT16_LO_DS
16571 && (insn
& (0x3fu
<< 26 | 0x3)) == 58u << 26 /* ld */)
16573 insn
+= (14u << 26) - (58u << 26);
16574 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
16575 r_type
= R_PPC64_TOC16_LO
;
16576 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16578 else if (r_type
== R_PPC64_GOT16_HA
16579 && (insn
& (0x3fu
<< 26)) == 15u << 26 /* addis */)
16581 r_type
= R_PPC64_TOC16_HA
;
16582 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16587 case R_PPC64_GOT_PCREL34
:
16588 if ((h
? h
->elf
.type
: ELF_ST_TYPE (sym
->st_info
)) == STT_GNU_IFUNC
16589 || !htab
->do_toc_opt
)
16591 from
= (rel
->r_offset
16592 + input_section
->output_section
->vma
16593 + input_section
->output_offset
);
16594 if (!(relocation
- from
+ (1ULL << 33) < 1ULL << 34
16596 && sec
->output_section
!= NULL
16597 && !discarded_section (sec
)
16598 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16599 && offset_in_range (input_section
, rel
->r_offset
, 8)))
16602 offset
= rel
->r_offset
;
16603 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16605 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16606 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16607 != ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
16610 /* Replace with paddi. */
16611 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
16612 r_type
= R_PPC64_PCREL34
;
16613 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
16614 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ offset
);
16615 bfd_put_32 (input_bfd
, pinsn
, contents
+ offset
+ 4);
16616 /* Fall through. */
16618 case R_PPC64_PCREL34
:
16619 if (!htab
->params
->no_pcrel_opt
16620 && rel
+ 1 < relend
16621 && rel
[1].r_offset
== rel
->r_offset
16622 && rel
[1].r_info
== ELF64_R_INFO (0, R_PPC64_PCREL_OPT
)
16623 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
16624 && offset_in_range (input_section
, rel
->r_offset
, 8))
16626 offset
= rel
->r_offset
;
16627 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
16629 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
16630 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
16631 == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
16632 | (14ULL << 26) /* paddi */))
16634 bfd_vma off2
= rel
[1].r_addend
;
16636 /* zero means next insn. */
16639 if (offset_in_range (input_section
, off2
, 4))
16642 bfd_signed_vma addend_off
;
16643 pinsn2
= bfd_get_32 (input_bfd
, contents
+ off2
);
16645 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16647 if (!offset_in_range (input_section
, off2
, 8))
16649 pinsn2
|= bfd_get_32 (input_bfd
,
16650 contents
+ off2
+ 4);
16652 if (xlate_pcrel_opt (&pinsn
, &pinsn2
, &addend_off
))
16654 addend
+= addend_off
;
16655 rel
->r_addend
= addend
;
16656 bfd_put_32 (input_bfd
, pinsn
>> 32,
16657 contents
+ offset
);
16658 bfd_put_32 (input_bfd
, pinsn
,
16659 contents
+ offset
+ 4);
16660 bfd_put_32 (input_bfd
, pinsn2
>> 32,
16662 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
16663 bfd_put_32 (input_bfd
, pinsn2
,
16664 contents
+ off2
+ 4);
16673 save_unresolved_reloc
= unresolved_reloc
;
16677 /* xgettext:c-format */
16678 _bfd_error_handler (_("%pB: %s unsupported"),
16679 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
16681 bfd_set_error (bfd_error_bad_value
);
16687 case R_PPC64_TLSGD
:
16688 case R_PPC64_TLSLD
:
16689 case R_PPC64_TOCSAVE
:
16690 case R_PPC64_GNU_VTINHERIT
:
16691 case R_PPC64_GNU_VTENTRY
:
16692 case R_PPC64_ENTRY
:
16693 case R_PPC64_PCREL_OPT
:
16696 /* GOT16 relocations. Like an ADDR16 using the symbol's
16697 address in the GOT as relocation value instead of the
16698 symbol's value itself. Also, create a GOT entry for the
16699 symbol and put the symbol value there. */
16700 case R_PPC64_GOT_TLSGD16
:
16701 case R_PPC64_GOT_TLSGD16_LO
:
16702 case R_PPC64_GOT_TLSGD16_HI
:
16703 case R_PPC64_GOT_TLSGD16_HA
:
16704 case R_PPC64_GOT_TLSGD_PCREL34
:
16705 tls_type
= TLS_TLS
| TLS_GD
;
16708 case R_PPC64_GOT_TLSLD16
:
16709 case R_PPC64_GOT_TLSLD16_LO
:
16710 case R_PPC64_GOT_TLSLD16_HI
:
16711 case R_PPC64_GOT_TLSLD16_HA
:
16712 case R_PPC64_GOT_TLSLD_PCREL34
:
16713 tls_type
= TLS_TLS
| TLS_LD
;
16716 case R_PPC64_GOT_TPREL16_DS
:
16717 case R_PPC64_GOT_TPREL16_LO_DS
:
16718 case R_PPC64_GOT_TPREL16_HI
:
16719 case R_PPC64_GOT_TPREL16_HA
:
16720 case R_PPC64_GOT_TPREL_PCREL34
:
16721 tls_type
= TLS_TLS
| TLS_TPREL
;
16724 case R_PPC64_GOT_DTPREL16_DS
:
16725 case R_PPC64_GOT_DTPREL16_LO_DS
:
16726 case R_PPC64_GOT_DTPREL16_HI
:
16727 case R_PPC64_GOT_DTPREL16_HA
:
16728 case R_PPC64_GOT_DTPREL_PCREL34
:
16729 tls_type
= TLS_TLS
| TLS_DTPREL
;
16732 case R_PPC64_GOT16
:
16733 case R_PPC64_GOT16_LO
:
16734 case R_PPC64_GOT16_HI
:
16735 case R_PPC64_GOT16_HA
:
16736 case R_PPC64_GOT16_DS
:
16737 case R_PPC64_GOT16_LO_DS
:
16738 case R_PPC64_GOT_PCREL34
:
16741 /* Relocation is to the entry for this symbol in the global
16746 unsigned long indx
= 0;
16747 struct got_entry
*ent
;
16749 if (tls_type
== (TLS_TLS
| TLS_LD
)
16750 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
16751 ent
= ppc64_tlsld_got (input_bfd
);
16756 if (!htab
->elf
.dynamic_sections_created
16757 || h
->elf
.dynindx
== -1
16758 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16759 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16760 /* This is actually a static link, or it is a
16761 -Bsymbolic link and the symbol is defined
16762 locally, or the symbol was forced to be local
16763 because of a version file. */
16767 indx
= h
->elf
.dynindx
;
16768 unresolved_reloc
= false;
16770 ent
= h
->elf
.got
.glist
;
16774 if (local_got_ents
== NULL
)
16776 ent
= local_got_ents
[r_symndx
];
16779 for (; ent
!= NULL
; ent
= ent
->next
)
16780 if (ent
->addend
== orig_rel
.r_addend
16781 && ent
->owner
== input_bfd
16782 && ent
->tls_type
== tls_type
)
16788 if (ent
->is_indirect
)
16789 ent
= ent
->got
.ent
;
16790 offp
= &ent
->got
.offset
;
16791 got
= ppc64_elf_tdata (ent
->owner
)->got
;
16795 /* The offset must always be a multiple of 8. We use the
16796 least significant bit to record whether we have already
16797 processed this entry. */
16799 if ((off
& 1) != 0)
16803 /* Generate relocs for the dynamic linker, except in
16804 the case of TLSLD where we'll use one entry per
16812 ? h
->elf
.type
== STT_GNU_IFUNC
16813 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
16816 relgot
= htab
->elf
.irelplt
;
16817 if (indx
== 0 || is_static_defined (&h
->elf
))
16818 htab
->elf
.ifunc_resolvers
= true;
16821 || (bfd_link_pic (info
)
16823 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
16825 && bfd_link_executable (info
)
16827 || SYMBOL_REFERENCES_LOCAL (info
,
16829 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
16830 if (relgot
!= NULL
)
16832 outrel
.r_offset
= (got
->output_section
->vma
16833 + got
->output_offset
16835 outrel
.r_addend
= orig_rel
.r_addend
;
16836 if (tls_type
& (TLS_LD
| TLS_GD
))
16838 outrel
.r_addend
= 0;
16839 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
16840 if (tls_type
== (TLS_TLS
| TLS_GD
))
16842 loc
= relgot
->contents
;
16843 loc
+= (relgot
->reloc_count
++
16844 * sizeof (Elf64_External_Rela
));
16845 bfd_elf64_swap_reloca_out (output_bfd
,
16847 outrel
.r_offset
+= 8;
16848 outrel
.r_addend
= orig_rel
.r_addend
;
16850 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16853 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
16854 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
16855 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
16856 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
16857 else if (indx
!= 0)
16858 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
16862 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16864 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16866 /* Write the .got section contents for the sake
16868 loc
= got
->contents
+ off
;
16869 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
16873 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
16875 outrel
.r_addend
+= relocation
;
16876 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
16878 if (htab
->elf
.tls_sec
== NULL
)
16879 outrel
.r_addend
= 0;
16881 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
16884 if (!(info
->enable_dt_relr
16885 && ELF64_R_TYPE (outrel
.r_info
) == R_PPC64_RELATIVE
))
16887 loc
= relgot
->contents
;
16888 loc
+= (relgot
->reloc_count
++
16889 * sizeof (Elf64_External_Rela
));
16890 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16894 /* Init the .got section contents here if we're not
16895 emitting a reloc. */
16898 relocation
+= orig_rel
.r_addend
;
16901 if (htab
->elf
.tls_sec
== NULL
)
16905 if (tls_type
& TLS_LD
)
16908 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16909 if (tls_type
& TLS_TPREL
)
16910 relocation
+= DTP_OFFSET
- TP_OFFSET
;
16913 if (tls_type
& (TLS_GD
| TLS_LD
))
16915 bfd_put_64 (output_bfd
, relocation
,
16916 got
->contents
+ off
+ 8);
16920 bfd_put_64 (output_bfd
, relocation
,
16921 got
->contents
+ off
);
16925 if (off
>= (bfd_vma
) -2)
16928 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
16930 if (!(r_type
== R_PPC64_GOT_PCREL34
16931 || r_type
== R_PPC64_GOT_TLSGD_PCREL34
16932 || r_type
== R_PPC64_GOT_TLSLD_PCREL34
16933 || r_type
== R_PPC64_GOT_TPREL_PCREL34
16934 || r_type
== R_PPC64_GOT_DTPREL_PCREL34
))
16935 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
16939 case R_PPC64_PLT16_HA
:
16940 case R_PPC64_PLT16_HI
:
16941 case R_PPC64_PLT16_LO
:
16942 case R_PPC64_PLT16_LO_DS
:
16943 case R_PPC64_PLT_PCREL34
:
16944 case R_PPC64_PLT_PCREL34_NOTOC
:
16945 case R_PPC64_PLT32
:
16946 case R_PPC64_PLT64
:
16947 case R_PPC64_PLTSEQ
:
16948 case R_PPC64_PLTSEQ_NOTOC
:
16949 case R_PPC64_PLTCALL
:
16950 case R_PPC64_PLTCALL_NOTOC
:
16951 /* Relocation is to the entry for this symbol in the
16952 procedure linkage table. */
16953 unresolved_reloc
= true;
16955 struct plt_entry
**plt_list
= NULL
;
16957 plt_list
= &h
->elf
.plt
.plist
;
16958 else if (local_got_ents
!= NULL
)
16960 struct plt_entry
**local_plt
= (struct plt_entry
**)
16961 (local_got_ents
+ symtab_hdr
->sh_info
);
16962 plt_list
= local_plt
+ r_symndx
;
16966 struct plt_entry
*ent
;
16968 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
16969 if (ent
->plt
.offset
!= (bfd_vma
) -1
16970 && ent
->addend
== orig_rel
.r_addend
)
16975 plt
= htab
->elf
.splt
;
16976 if (use_local_plt (info
, elf_hash_entry (h
)))
16979 ? h
->elf
.type
== STT_GNU_IFUNC
16980 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16981 plt
= htab
->elf
.iplt
;
16983 plt
= htab
->pltlocal
;
16985 relocation
= (plt
->output_section
->vma
16986 + plt
->output_offset
16987 + ent
->plt
.offset
);
16988 if (r_type
== R_PPC64_PLT16_HA
16989 || r_type
== R_PPC64_PLT16_HI
16990 || r_type
== R_PPC64_PLT16_LO
16991 || r_type
== R_PPC64_PLT16_LO_DS
)
16993 got
= (elf_gp (output_bfd
)
16994 + htab
->sec_info
[input_section
->id
].toc_off
);
16998 unresolved_reloc
= false;
17006 /* Relocation value is TOC base. */
17007 relocation
= TOCstart
;
17008 if (r_symndx
== STN_UNDEF
)
17009 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
17010 else if (unresolved_reloc
)
17012 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
17013 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
17015 unresolved_reloc
= true;
17018 /* TOC16 relocs. We want the offset relative to the TOC base,
17019 which is the address of the start of the TOC plus 0x8000.
17020 The TOC consists of sections .got, .toc, .tocbss, and .plt,
17022 case R_PPC64_TOC16
:
17023 case R_PPC64_TOC16_LO
:
17024 case R_PPC64_TOC16_HI
:
17025 case R_PPC64_TOC16_DS
:
17026 case R_PPC64_TOC16_LO_DS
:
17027 case R_PPC64_TOC16_HA
:
17028 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
17033 /* Relocate against the beginning of the section. */
17034 case R_PPC64_SECTOFF
:
17035 case R_PPC64_SECTOFF_LO
:
17036 case R_PPC64_SECTOFF_HI
:
17037 case R_PPC64_SECTOFF_DS
:
17038 case R_PPC64_SECTOFF_LO_DS
:
17039 case R_PPC64_SECTOFF_HA
:
17041 addend
-= sec
->output_section
->vma
;
17044 case R_PPC64_REL16
:
17045 case R_PPC64_REL16_LO
:
17046 case R_PPC64_REL16_HI
:
17047 case R_PPC64_REL16_HA
:
17048 case R_PPC64_REL16_HIGH
:
17049 case R_PPC64_REL16_HIGHA
:
17050 case R_PPC64_REL16_HIGHER
:
17051 case R_PPC64_REL16_HIGHERA
:
17052 case R_PPC64_REL16_HIGHEST
:
17053 case R_PPC64_REL16_HIGHESTA
:
17054 case R_PPC64_REL16_HIGHER34
:
17055 case R_PPC64_REL16_HIGHERA34
:
17056 case R_PPC64_REL16_HIGHEST34
:
17057 case R_PPC64_REL16_HIGHESTA34
:
17058 case R_PPC64_REL16DX_HA
:
17059 case R_PPC64_REL14
:
17060 case R_PPC64_REL14_BRNTAKEN
:
17061 case R_PPC64_REL14_BRTAKEN
:
17062 case R_PPC64_REL24
:
17063 case R_PPC64_REL24_NOTOC
:
17064 case R_PPC64_REL24_P9NOTOC
:
17065 case R_PPC64_PCREL34
:
17066 case R_PPC64_PCREL28
:
17069 case R_PPC64_TPREL16
:
17070 case R_PPC64_TPREL16_LO
:
17071 case R_PPC64_TPREL16_HI
:
17072 case R_PPC64_TPREL16_HA
:
17073 case R_PPC64_TPREL16_DS
:
17074 case R_PPC64_TPREL16_LO_DS
:
17075 case R_PPC64_TPREL16_HIGH
:
17076 case R_PPC64_TPREL16_HIGHA
:
17077 case R_PPC64_TPREL16_HIGHER
:
17078 case R_PPC64_TPREL16_HIGHERA
:
17079 case R_PPC64_TPREL16_HIGHEST
:
17080 case R_PPC64_TPREL16_HIGHESTA
:
17082 && h
->elf
.root
.type
== bfd_link_hash_undefweak
17083 && h
->elf
.dynindx
== -1
17084 && offset_in_range (input_section
, rel
->r_offset
- d_offset
, 4))
17086 /* Make this relocation against an undefined weak symbol
17087 resolve to zero. This is really just a tweak, since
17088 code using weak externs ought to check that they are
17089 defined before using them. */
17090 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
17092 insn
= bfd_get_32 (input_bfd
, p
);
17093 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
17095 bfd_put_32 (input_bfd
, insn
, p
);
17098 /* Fall through. */
17100 case R_PPC64_TPREL34
:
17101 if (htab
->elf
.tls_sec
!= NULL
)
17102 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
17103 /* The TPREL16 relocs shouldn't really be used in shared
17104 libs or with non-local symbols as that will result in
17105 DT_TEXTREL being set, but support them anyway. */
17108 case R_PPC64_DTPREL16
:
17109 case R_PPC64_DTPREL16_LO
:
17110 case R_PPC64_DTPREL16_HI
:
17111 case R_PPC64_DTPREL16_HA
:
17112 case R_PPC64_DTPREL16_DS
:
17113 case R_PPC64_DTPREL16_LO_DS
:
17114 case R_PPC64_DTPREL16_HIGH
:
17115 case R_PPC64_DTPREL16_HIGHA
:
17116 case R_PPC64_DTPREL16_HIGHER
:
17117 case R_PPC64_DTPREL16_HIGHERA
:
17118 case R_PPC64_DTPREL16_HIGHEST
:
17119 case R_PPC64_DTPREL16_HIGHESTA
:
17120 case R_PPC64_DTPREL34
:
17121 if (htab
->elf
.tls_sec
!= NULL
)
17122 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17125 case R_PPC64_ADDR64_LOCAL
:
17126 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
17131 case R_PPC64_DTPMOD64
:
17136 case R_PPC64_TPREL64
:
17137 if (htab
->elf
.tls_sec
!= NULL
)
17138 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
17141 case R_PPC64_DTPREL64
:
17142 if (htab
->elf
.tls_sec
!= NULL
)
17143 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
17144 /* Fall through. */
17146 /* Relocations that may need to be propagated if this is a
17148 case R_PPC64_REL30
:
17149 case R_PPC64_REL32
:
17150 case R_PPC64_REL64
:
17151 case R_PPC64_ADDR14
:
17152 case R_PPC64_ADDR14_BRNTAKEN
:
17153 case R_PPC64_ADDR14_BRTAKEN
:
17154 case R_PPC64_ADDR16
:
17155 case R_PPC64_ADDR16_DS
:
17156 case R_PPC64_ADDR16_HA
:
17157 case R_PPC64_ADDR16_HI
:
17158 case R_PPC64_ADDR16_HIGH
:
17159 case R_PPC64_ADDR16_HIGHA
:
17160 case R_PPC64_ADDR16_HIGHER
:
17161 case R_PPC64_ADDR16_HIGHERA
:
17162 case R_PPC64_ADDR16_HIGHEST
:
17163 case R_PPC64_ADDR16_HIGHESTA
:
17164 case R_PPC64_ADDR16_LO
:
17165 case R_PPC64_ADDR16_LO_DS
:
17166 case R_PPC64_ADDR16_HIGHER34
:
17167 case R_PPC64_ADDR16_HIGHERA34
:
17168 case R_PPC64_ADDR16_HIGHEST34
:
17169 case R_PPC64_ADDR16_HIGHESTA34
:
17170 case R_PPC64_ADDR24
:
17171 case R_PPC64_ADDR32
:
17172 case R_PPC64_ADDR64
:
17173 case R_PPC64_UADDR16
:
17174 case R_PPC64_UADDR32
:
17175 case R_PPC64_UADDR64
:
17177 case R_PPC64_D34_LO
:
17178 case R_PPC64_D34_HI30
:
17179 case R_PPC64_D34_HA30
:
17182 if ((input_section
->flags
& SEC_ALLOC
) == 0)
17185 if (NO_OPD_RELOCS
&& is_opd
)
17188 if (bfd_link_pic (info
)
17190 || h
->elf
.dyn_relocs
!= NULL
)
17191 && ((h
!= NULL
&& pc_dynrelocs (h
))
17192 || must_be_dyn_reloc (info
, r_type
)))
17194 ? h
->elf
.dyn_relocs
!= NULL
17195 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
17197 bool skip
, relocate
;
17202 /* When generating a dynamic object, these relocations
17203 are copied into the output file to be resolved at run
17209 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
17210 input_section
, rel
->r_offset
);
17211 if (out_off
== (bfd_vma
) -1)
17213 else if (out_off
== (bfd_vma
) -2)
17214 skip
= true, relocate
= true;
17215 out_off
+= (input_section
->output_section
->vma
17216 + input_section
->output_offset
);
17217 outrel
.r_offset
= out_off
;
17218 outrel
.r_addend
= rel
->r_addend
;
17220 /* Optimize unaligned reloc use. */
17221 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
17222 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
17223 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
17224 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
17225 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
17226 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
17227 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
17228 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
17229 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
17232 memset (&outrel
, 0, sizeof outrel
);
17234 && !SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
17236 && r_type
!= R_PPC64_TOC
)
17238 indx
= h
->elf
.dynindx
;
17239 BFD_ASSERT (indx
!= -1);
17240 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
17244 /* This symbol is local, or marked to become local,
17245 or this is an opd section reloc which must point
17246 at a local function. */
17247 outrel
.r_addend
+= relocation
;
17248 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
17250 if (is_opd
&& h
!= NULL
)
17252 /* Lie about opd entries. This case occurs
17253 when building shared libraries and we
17254 reference a function in another shared
17255 lib. The same thing happens for a weak
17256 definition in an application that's
17257 overridden by a strong definition in a
17258 shared lib. (I believe this is a generic
17259 bug in binutils handling of weak syms.)
17260 In these cases we won't use the opd
17261 entry in this lib. */
17262 unresolved_reloc
= false;
17265 && r_type
== R_PPC64_ADDR64
17267 ? h
->elf
.type
== STT_GNU_IFUNC
17268 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
17269 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
17272 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
17274 /* We need to relocate .opd contents for ld.so.
17275 Prelink also wants simple and consistent rules
17276 for relocs. This make all RELATIVE relocs have
17277 *r_offset equal to r_addend. */
17284 ? h
->elf
.type
== STT_GNU_IFUNC
17285 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17287 info
->callbacks
->einfo
17288 /* xgettext:c-format */
17289 (_("%H: %s for indirect "
17290 "function `%pT' unsupported\n"),
17291 input_bfd
, input_section
, rel
->r_offset
,
17292 ppc64_elf_howto_table
[r_type
]->name
,
17296 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
17298 else if (sec
== NULL
|| sec
->owner
== NULL
)
17300 bfd_set_error (bfd_error_bad_value
);
17305 asection
*osec
= sec
->output_section
;
17307 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
17309 /* TLS symbol values are relative to the
17310 TLS segment. Dynamic relocations for
17311 local TLS symbols therefore can't be
17312 reduced to a relocation against their
17313 section symbol because it holds the
17314 address of the section, not a value
17315 relative to the TLS segment. We could
17316 change the .tdata dynamic section symbol
17317 to be zero value but STN_UNDEF works
17318 and is used elsewhere, eg. for TPREL64
17319 GOT relocs against local TLS symbols. */
17320 osec
= htab
->elf
.tls_sec
;
17325 indx
= elf_section_data (osec
)->dynindx
;
17328 if ((osec
->flags
& SEC_READONLY
) == 0
17329 && htab
->elf
.data_index_section
!= NULL
)
17330 osec
= htab
->elf
.data_index_section
;
17332 osec
= htab
->elf
.text_index_section
;
17333 indx
= elf_section_data (osec
)->dynindx
;
17335 BFD_ASSERT (indx
!= 0);
17338 /* We are turning this relocation into one
17339 against a section symbol, so subtract out
17340 the output section's address but not the
17341 offset of the input section in the output
17343 outrel
.r_addend
-= osec
->vma
;
17346 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
17350 if (!(info
->enable_dt_relr
17351 && ELF64_R_TYPE (outrel
.r_info
) == R_PPC64_RELATIVE
17352 && rel
->r_offset
% 2 == 0
17353 && input_section
->alignment_power
!= 0
17354 && ELF64_R_TYPE (orig_rel
.r_info
) != R_PPC64_UADDR64
))
17356 sreloc
= elf_section_data (input_section
)->sreloc
;
17358 ? h
->elf
.type
== STT_GNU_IFUNC
17359 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
17361 sreloc
= htab
->elf
.irelplt
;
17362 if (indx
== 0 || is_static_defined (&h
->elf
))
17363 htab
->elf
.ifunc_resolvers
= true;
17365 if (sreloc
== NULL
)
17368 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
17371 loc
= sreloc
->contents
;
17372 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
17373 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
17376 if (!warned_dynamic
17377 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel
.r_info
)))
17379 info
->callbacks
->einfo
17380 /* xgettext:c-format */
17381 (_("%X%P: %pB: %s against %pT "
17382 "is not supported by glibc as a dynamic relocation\n"),
17384 ppc64_elf_howto_table
[ELF64_R_TYPE (outrel
.r_info
)]->name
,
17386 warned_dynamic
= true;
17389 /* If this reloc is against an external symbol, it will
17390 be computed at runtime, so there's no need to do
17391 anything now. However, for the sake of prelink ensure
17392 that the section contents are a known value. */
17395 unresolved_reloc
= false;
17396 /* The value chosen here is quite arbitrary as ld.so
17397 ignores section contents except for the special
17398 case of .opd where the contents might be accessed
17399 before relocation. Choose zero, as that won't
17400 cause reloc overflow. */
17403 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
17404 to improve backward compatibility with older
17406 if (r_type
== R_PPC64_ADDR64
)
17407 addend
= outrel
.r_addend
;
17408 /* Adjust pc_relative relocs to have zero in *r_offset. */
17409 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
17410 addend
= outrel
.r_offset
;
17416 case R_PPC64_GLOB_DAT
:
17417 case R_PPC64_JMP_SLOT
:
17418 case R_PPC64_JMP_IREL
:
17419 case R_PPC64_RELATIVE
:
17420 /* We shouldn't ever see these dynamic relocs in relocatable
17422 /* Fall through. */
17424 case R_PPC64_PLTGOT16
:
17425 case R_PPC64_PLTGOT16_DS
:
17426 case R_PPC64_PLTGOT16_HA
:
17427 case R_PPC64_PLTGOT16_HI
:
17428 case R_PPC64_PLTGOT16_LO
:
17429 case R_PPC64_PLTGOT16_LO_DS
:
17430 case R_PPC64_PLTREL32
:
17431 case R_PPC64_PLTREL64
:
17432 /* These ones haven't been implemented yet. */
17434 info
->callbacks
->einfo
17435 /* xgettext:c-format */
17436 (_("%P: %pB: %s is not supported for `%pT'\n"),
17438 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
17440 bfd_set_error (bfd_error_invalid_operation
);
17445 /* Multi-instruction sequences that access the TOC can be
17446 optimized, eg. addis ra,r2,0; addi rb,ra,x;
17447 to nop; addi rb,r2,x; */
17453 case R_PPC64_GOT_TLSLD16_HI
:
17454 case R_PPC64_GOT_TLSGD16_HI
:
17455 case R_PPC64_GOT_TPREL16_HI
:
17456 case R_PPC64_GOT_DTPREL16_HI
:
17457 case R_PPC64_GOT16_HI
:
17458 case R_PPC64_TOC16_HI
:
17459 /* These relocs would only be useful if building up an
17460 offset to later add to r2, perhaps in an indexed
17461 addressing mode instruction. Don't try to optimize.
17462 Unfortunately, the possibility of someone building up an
17463 offset like this or even with the HA relocs, means that
17464 we need to check the high insn when optimizing the low
17468 case R_PPC64_PLTCALL_NOTOC
:
17469 if (!unresolved_reloc
)
17470 htab
->notoc_plt
= 1;
17471 /* Fall through. */
17472 case R_PPC64_PLTCALL
:
17473 if (unresolved_reloc
17474 && offset_in_range (input_section
, rel
->r_offset
,
17475 r_type
== R_PPC64_PLTCALL
? 8 : 4))
17477 /* No plt entry. Make this into a direct call. */
17478 bfd_byte
*p
= contents
+ rel
->r_offset
;
17479 insn
= bfd_get_32 (input_bfd
, p
);
17481 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
17482 if (r_type
== R_PPC64_PLTCALL
)
17483 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
17484 unresolved_reloc
= save_unresolved_reloc
;
17485 r_type
= R_PPC64_REL24
;
17489 case R_PPC64_PLTSEQ_NOTOC
:
17490 case R_PPC64_PLTSEQ
:
17491 if (unresolved_reloc
)
17493 unresolved_reloc
= false;
17498 case R_PPC64_PLT_PCREL34_NOTOC
:
17499 if (!unresolved_reloc
)
17500 htab
->notoc_plt
= 1;
17501 /* Fall through. */
17502 case R_PPC64_PLT_PCREL34
:
17503 if (unresolved_reloc
17504 && offset_in_range (input_section
, rel
->r_offset
, 8))
17506 bfd_byte
*p
= contents
+ rel
->r_offset
;
17507 bfd_put_32 (input_bfd
, PNOP
>> 32, p
);
17508 bfd_put_32 (input_bfd
, PNOP
, p
+ 4);
17509 unresolved_reloc
= false;
17514 case R_PPC64_PLT16_HA
:
17515 if (unresolved_reloc
)
17517 unresolved_reloc
= false;
17520 /* Fall through. */
17521 case R_PPC64_GOT_TLSLD16_HA
:
17522 case R_PPC64_GOT_TLSGD16_HA
:
17523 case R_PPC64_GOT_TPREL16_HA
:
17524 case R_PPC64_GOT_DTPREL16_HA
:
17525 case R_PPC64_GOT16_HA
:
17526 case R_PPC64_TOC16_HA
:
17527 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17528 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
17532 if (offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17534 p
= contents
+ (rel
->r_offset
& ~3);
17535 bfd_put_32 (input_bfd
, NOP
, p
);
17541 case R_PPC64_PLT16_LO
:
17542 case R_PPC64_PLT16_LO_DS
:
17543 if (unresolved_reloc
)
17545 unresolved_reloc
= false;
17548 /* Fall through. */
17549 case R_PPC64_GOT_TLSLD16_LO
:
17550 case R_PPC64_GOT_TLSGD16_LO
:
17551 case R_PPC64_GOT_TPREL16_LO_DS
:
17552 case R_PPC64_GOT_DTPREL16_LO_DS
:
17553 case R_PPC64_GOT16_LO
:
17554 case R_PPC64_GOT16_LO_DS
:
17555 case R_PPC64_TOC16_LO
:
17556 case R_PPC64_TOC16_LO_DS
:
17557 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
17558 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
17559 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17561 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17562 insn
= bfd_get_32 (input_bfd
, p
);
17563 if ((insn
& (0x3fu
<< 26)) == 12u << 26 /* addic */)
17565 /* Transform addic to addi when we change reg. */
17566 insn
&= ~((0x3fu
<< 26) | (0x1f << 16));
17567 insn
|= (14u << 26) | (2 << 16);
17571 insn
&= ~(0x1f << 16);
17574 bfd_put_32 (input_bfd
, insn
, p
);
17578 case R_PPC64_TPREL16_HA
:
17579 if (htab
->do_tls_opt
17580 && relocation
+ addend
+ 0x8000 < 0x10000
17581 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17583 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17584 bfd_put_32 (input_bfd
, NOP
, p
);
17589 case R_PPC64_TPREL16_LO
:
17590 case R_PPC64_TPREL16_LO_DS
:
17591 if (htab
->do_tls_opt
17592 && relocation
+ addend
+ 0x8000 < 0x10000
17593 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17595 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
17596 insn
= bfd_get_32 (input_bfd
, p
);
17597 insn
&= ~(0x1f << 16);
17599 bfd_put_32 (input_bfd
, insn
, p
);
17604 /* Do any further special processing. */
17610 case R_PPC64_REL16_HA
:
17611 case R_PPC64_REL16_HIGHA
:
17612 case R_PPC64_REL16_HIGHERA
:
17613 case R_PPC64_REL16_HIGHESTA
:
17614 case R_PPC64_REL16DX_HA
:
17615 case R_PPC64_ADDR16_HA
:
17616 case R_PPC64_ADDR16_HIGHA
:
17617 case R_PPC64_ADDR16_HIGHERA
:
17618 case R_PPC64_ADDR16_HIGHESTA
:
17619 case R_PPC64_TOC16_HA
:
17620 case R_PPC64_SECTOFF_HA
:
17621 case R_PPC64_TPREL16_HA
:
17622 case R_PPC64_TPREL16_HIGHA
:
17623 case R_PPC64_TPREL16_HIGHERA
:
17624 case R_PPC64_TPREL16_HIGHESTA
:
17625 case R_PPC64_DTPREL16_HA
:
17626 case R_PPC64_DTPREL16_HIGHA
:
17627 case R_PPC64_DTPREL16_HIGHERA
:
17628 case R_PPC64_DTPREL16_HIGHESTA
:
17629 /* It's just possible that this symbol is a weak symbol
17630 that's not actually defined anywhere. In that case,
17631 'sec' would be NULL, and we should leave the symbol
17632 alone (it will be set to zero elsewhere in the link). */
17635 /* Fall through. */
17637 case R_PPC64_GOT16_HA
:
17638 case R_PPC64_PLTGOT16_HA
:
17639 case R_PPC64_PLT16_HA
:
17640 case R_PPC64_GOT_TLSGD16_HA
:
17641 case R_PPC64_GOT_TLSLD16_HA
:
17642 case R_PPC64_GOT_TPREL16_HA
:
17643 case R_PPC64_GOT_DTPREL16_HA
:
17644 /* Add 0x10000 if sign bit in 0:15 is set.
17645 Bits 0:15 are not used. */
17649 case R_PPC64_D34_HA30
:
17650 case R_PPC64_ADDR16_HIGHERA34
:
17651 case R_PPC64_ADDR16_HIGHESTA34
:
17652 case R_PPC64_REL16_HIGHERA34
:
17653 case R_PPC64_REL16_HIGHESTA34
:
17655 addend
+= 1ULL << 33;
17658 case R_PPC64_ADDR16_DS
:
17659 case R_PPC64_ADDR16_LO_DS
:
17660 case R_PPC64_GOT16_DS
:
17661 case R_PPC64_GOT16_LO_DS
:
17662 case R_PPC64_PLT16_LO_DS
:
17663 case R_PPC64_SECTOFF_DS
:
17664 case R_PPC64_SECTOFF_LO_DS
:
17665 case R_PPC64_TOC16_DS
:
17666 case R_PPC64_TOC16_LO_DS
:
17667 case R_PPC64_PLTGOT16_DS
:
17668 case R_PPC64_PLTGOT16_LO_DS
:
17669 case R_PPC64_GOT_TPREL16_DS
:
17670 case R_PPC64_GOT_TPREL16_LO_DS
:
17671 case R_PPC64_GOT_DTPREL16_DS
:
17672 case R_PPC64_GOT_DTPREL16_LO_DS
:
17673 case R_PPC64_TPREL16_DS
:
17674 case R_PPC64_TPREL16_LO_DS
:
17675 case R_PPC64_DTPREL16_DS
:
17676 case R_PPC64_DTPREL16_LO_DS
:
17677 if (!offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17679 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17681 /* If this reloc is against an lq, lxv, or stxv insn, then
17682 the value must be a multiple of 16. This is somewhat of
17683 a hack, but the "correct" way to do this by defining _DQ
17684 forms of all the _DS relocs bloats all reloc switches in
17685 this file. It doesn't make much sense to use these
17686 relocs in data, so testing the insn should be safe. */
17687 if ((insn
& (0x3fu
<< 26)) == (56u << 26)
17688 || ((insn
& (0x3fu
<< 26)) == (61u << 26) && (insn
& 3) == 1))
17690 relocation
+= addend
;
17691 addend
= insn
& (mask
^ 3);
17692 if ((relocation
& mask
) != 0)
17694 relocation
^= relocation
& mask
;
17695 info
->callbacks
->einfo
17696 /* xgettext:c-format */
17697 (_("%H: error: %s not a multiple of %u\n"),
17698 input_bfd
, input_section
, rel
->r_offset
,
17699 ppc64_elf_howto_table
[r_type
]->name
,
17701 bfd_set_error (bfd_error_bad_value
);
17708 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
17709 because such sections are not SEC_ALLOC and thus ld.so will
17710 not process them. */
17711 howto
= ppc64_elf_howto_table
[(int) r_type
];
17712 if (unresolved_reloc
17713 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
17714 && h
->elf
.def_dynamic
)
17715 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
17716 rel
->r_offset
) != (bfd_vma
) -1)
17718 info
->callbacks
->einfo
17719 /* xgettext:c-format */
17720 (_("%H: unresolvable %s against `%pT'\n"),
17721 input_bfd
, input_section
, rel
->r_offset
,
17723 h
->elf
.root
.root
.string
);
17727 /* 16-bit fields in insns mostly have signed values, but a
17728 few insns have 16-bit unsigned values. Really, we should
17729 have different reloc types. */
17730 if (howto
->complain_on_overflow
!= complain_overflow_dont
17731 && howto
->dst_mask
== 0xffff
17732 && (input_section
->flags
& SEC_CODE
) != 0
17733 && offset_in_range (input_section
, rel
->r_offset
& ~3, 4))
17735 enum complain_overflow complain
= complain_overflow_signed
;
17737 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
17738 if ((insn
& (0x3fu
<< 26)) == 10u << 26 /* cmpli */)
17739 complain
= complain_overflow_bitfield
;
17740 else if (howto
->rightshift
== 0
17741 ? ((insn
& (0x3fu
<< 26)) == 28u << 26 /* andi */
17742 || (insn
& (0x3fu
<< 26)) == 24u << 26 /* ori */
17743 || (insn
& (0x3fu
<< 26)) == 26u << 26 /* xori */)
17744 : ((insn
& (0x3fu
<< 26)) == 29u << 26 /* andis */
17745 || (insn
& (0x3fu
<< 26)) == 25u << 26 /* oris */
17746 || (insn
& (0x3fu
<< 26)) == 27u << 26 /* xoris */))
17747 complain
= complain_overflow_unsigned
;
17748 if (howto
->complain_on_overflow
!= complain
)
17750 alt_howto
= *howto
;
17751 alt_howto
.complain_on_overflow
= complain
;
17752 howto
= &alt_howto
;
17758 /* Split field relocs aren't handled by _bfd_final_link_relocate. */
17760 case R_PPC64_D34_LO
:
17761 case R_PPC64_D34_HI30
:
17762 case R_PPC64_D34_HA30
:
17763 case R_PPC64_PCREL34
:
17764 case R_PPC64_GOT_PCREL34
:
17765 case R_PPC64_TPREL34
:
17766 case R_PPC64_DTPREL34
:
17767 case R_PPC64_GOT_TLSGD_PCREL34
:
17768 case R_PPC64_GOT_TLSLD_PCREL34
:
17769 case R_PPC64_GOT_TPREL_PCREL34
:
17770 case R_PPC64_GOT_DTPREL_PCREL34
:
17771 case R_PPC64_PLT_PCREL34
:
17772 case R_PPC64_PLT_PCREL34_NOTOC
:
17774 case R_PPC64_PCREL28
:
17775 if (!offset_in_range (input_section
, rel
->r_offset
, 8))
17776 r
= bfd_reloc_outofrange
;
17779 relocation
+= addend
;
17780 if (howto
->pc_relative
)
17781 relocation
-= (rel
->r_offset
17782 + input_section
->output_offset
17783 + input_section
->output_section
->vma
);
17784 relocation
>>= howto
->rightshift
;
17786 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17788 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
17790 pinsn
&= ~howto
->dst_mask
;
17791 pinsn
|= (((relocation
<< 16) | (relocation
& 0xffff))
17792 & howto
->dst_mask
);
17793 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ rel
->r_offset
);
17794 bfd_put_32 (input_bfd
, pinsn
, contents
+ rel
->r_offset
+ 4);
17796 if (howto
->complain_on_overflow
== complain_overflow_signed
17797 && (relocation
+ (1ULL << (howto
->bitsize
- 1))
17798 >= 1ULL << howto
->bitsize
))
17799 r
= bfd_reloc_overflow
;
17803 case R_PPC64_REL16DX_HA
:
17804 if (!offset_in_range (input_section
, rel
->r_offset
, 4))
17805 r
= bfd_reloc_outofrange
;
17808 relocation
+= addend
;
17809 relocation
-= (rel
->r_offset
17810 + input_section
->output_offset
17811 + input_section
->output_section
->vma
);
17812 relocation
= (bfd_signed_vma
) relocation
>> 16;
17813 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
17815 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
17816 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
17818 if (relocation
+ 0x8000 > 0xffff)
17819 r
= bfd_reloc_overflow
;
17824 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
17825 contents
, rel
->r_offset
,
17826 relocation
, addend
);
17829 if (r
!= bfd_reloc_ok
)
17831 char *more_info
= NULL
;
17832 const char *reloc_name
= howto
->name
;
17834 if (reloc_dest
!= DEST_NORMAL
)
17836 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
17837 if (more_info
!= NULL
)
17839 strcpy (more_info
, reloc_name
);
17840 strcat (more_info
, (reloc_dest
== DEST_OPD
17841 ? " (OPD)" : " (stub)"));
17842 reloc_name
= more_info
;
17846 if (r
== bfd_reloc_overflow
)
17848 /* On code like "if (foo) foo();" don't report overflow
17849 on a branch to zero when foo is undefined. */
17851 && (reloc_dest
== DEST_STUB
17853 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
17854 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
17855 && is_branch_reloc (r_type
))))
17856 info
->callbacks
->reloc_overflow
17857 (info
, (struct bfd_link_hash_entry
*) h
, sym_name
,
17858 reloc_name
, orig_rel
.r_addend
, input_bfd
, input_section
,
17863 info
->callbacks
->einfo
17864 /* xgettext:c-format */
17865 (_("%H: %s against `%pT': error %d\n"),
17866 input_bfd
, input_section
, rel
->r_offset
,
17867 reloc_name
, sym_name
, (int) r
);
17879 Elf_Internal_Shdr
*rel_hdr
;
17880 size_t deleted
= rel
- wrel
;
17882 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
17883 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17884 if (rel_hdr
->sh_size
== 0)
17886 /* It is too late to remove an empty reloc section. Leave
17888 ??? What is wrong with an empty section??? */
17889 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
17892 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
17893 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
17894 input_section
->reloc_count
-= deleted
;
17897 /* If we're emitting relocations, then shortly after this function
17898 returns, reloc offsets and addends for this section will be
17899 adjusted. Worse, reloc symbol indices will be for the output
17900 file rather than the input. Save a copy of the relocs for
17901 opd_entry_value. */
17902 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
17905 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
17906 rel
= bfd_alloc (input_bfd
, amt
);
17907 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
17908 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
17911 memcpy (rel
, relocs
, amt
);
17916 /* Adjust the value of any local symbols in opd sections. */
17919 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
17920 const char *name ATTRIBUTE_UNUSED
,
17921 Elf_Internal_Sym
*elfsym
,
17922 asection
*input_sec
,
17923 struct elf_link_hash_entry
*h
)
17925 struct _opd_sec_data
*opd
;
17932 opd
= get_opd_info (input_sec
);
17933 if (opd
== NULL
|| opd
->adjust
== NULL
)
17936 value
= elfsym
->st_value
- input_sec
->output_offset
;
17937 if (!bfd_link_relocatable (info
))
17938 value
-= input_sec
->output_section
->vma
;
17940 adjust
= opd
->adjust
[OPD_NDX (value
)];
17944 elfsym
->st_value
+= adjust
;
17948 /* Finish up dynamic symbol handling. We set the contents of various
17949 dynamic sections here. */
17952 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
17953 struct bfd_link_info
*info
,
17954 struct elf_link_hash_entry
*h
,
17955 Elf_Internal_Sym
*sym
)
17957 struct ppc_link_hash_table
*htab
;
17958 struct plt_entry
*ent
;
17960 htab
= ppc_hash_table (info
);
17964 if (!htab
->opd_abi
&& !h
->def_regular
)
17965 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
17966 if (ent
->plt
.offset
!= (bfd_vma
) -1)
17968 /* Mark the symbol as undefined, rather than as
17969 defined in glink. Leave the value if there were
17970 any relocations where pointer equality matters
17971 (this is a clue for the dynamic linker, to make
17972 function pointer comparisons work between an
17973 application and shared library), otherwise set it
17975 sym
->st_shndx
= SHN_UNDEF
;
17976 if (!h
->pointer_equality_needed
)
17978 else if (!h
->ref_regular_nonweak
)
17980 /* This breaks function pointer comparisons, but
17981 that is better than breaking tests for a NULL
17982 function pointer. */
17989 && (h
->root
.type
== bfd_link_hash_defined
17990 || h
->root
.type
== bfd_link_hash_defweak
)
17991 && (h
->root
.u
.def
.section
== htab
->elf
.sdynbss
17992 || h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
))
17994 /* This symbol needs a copy reloc. Set it up. */
17995 Elf_Internal_Rela rela
;
17999 if (h
->dynindx
== -1)
18002 rela
.r_offset
= defined_sym_val (h
);
18003 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
18005 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
18006 srel
= htab
->elf
.sreldynrelro
;
18008 srel
= htab
->elf
.srelbss
;
18009 loc
= srel
->contents
;
18010 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
18011 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
18017 /* Used to decide how to sort relocs in an optimal manner for the
18018 dynamic linker, before writing them out. */
18020 static enum elf_reloc_type_class
18021 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
18022 const asection
*rel_sec
,
18023 const Elf_Internal_Rela
*rela
)
18025 enum elf_ppc64_reloc_type r_type
;
18026 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
18028 if (rel_sec
== htab
->elf
.irelplt
)
18029 return reloc_class_ifunc
;
18031 r_type
= ELF64_R_TYPE (rela
->r_info
);
18034 case R_PPC64_RELATIVE
:
18035 return reloc_class_relative
;
18036 case R_PPC64_JMP_SLOT
:
18037 return reloc_class_plt
;
18039 return reloc_class_copy
;
18041 return reloc_class_normal
;
18045 /* Finish up the dynamic sections. */
18048 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
18049 struct bfd_link_info
*info
)
18051 struct ppc_link_hash_table
*htab
;
18055 htab
= ppc_hash_table (info
);
18059 dynobj
= htab
->elf
.dynobj
;
18060 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
18062 if (htab
->elf
.dynamic_sections_created
)
18064 Elf64_External_Dyn
*dyncon
, *dynconend
;
18066 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
18069 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
18070 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
18071 for (; dyncon
< dynconend
; dyncon
++)
18073 Elf_Internal_Dyn dyn
;
18076 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
18083 case DT_PPC64_GLINK
:
18085 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18086 /* We stupidly defined DT_PPC64_GLINK to be the start
18087 of glink rather than the first entry point, which is
18088 what ld.so needs, and now have a bigger stub to
18089 support automatic multiple TOCs. */
18090 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
18094 s
= bfd_get_section_by_name (output_bfd
, ".opd");
18097 dyn
.d_un
.d_ptr
= s
->vma
;
18101 if ((htab
->do_multi_toc
&& htab
->multi_toc_needed
)
18102 || htab
->notoc_plt
)
18103 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
18104 if (htab
->has_plt_localentry0
)
18105 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
18108 case DT_PPC64_OPDSZ
:
18109 s
= bfd_get_section_by_name (output_bfd
, ".opd");
18112 dyn
.d_un
.d_val
= s
->size
;
18116 s
= htab
->elf
.splt
;
18117 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18121 s
= htab
->elf
.srelplt
;
18122 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
18126 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
18130 if (htab
->elf
.ifunc_resolvers
)
18131 info
->callbacks
->einfo
18132 (_("%P: warning: text relocations and GNU indirect "
18133 "functions may result in a segfault at runtime\n"));
18137 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
18141 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
18142 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
18144 /* Fill in the first entry in the global offset table.
18145 We use it to hold the link-time TOCbase. */
18146 bfd_put_64 (output_bfd
,
18147 elf_gp (output_bfd
) + TOC_BASE_OFF
,
18148 htab
->elf
.sgot
->contents
);
18150 /* Set .got entry size. */
18151 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
18155 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
18156 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
18158 /* Set .plt entry size. */
18159 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
18160 = PLT_ENTRY_SIZE (htab
);
18163 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
18164 brlt ourselves if emitrelocations. */
18165 if (htab
->brlt
!= NULL
18166 && htab
->brlt
->reloc_count
!= 0
18167 && !_bfd_elf_link_output_relocs (output_bfd
,
18169 elf_section_data (htab
->brlt
)->rela
.hdr
,
18170 elf_section_data (htab
->brlt
)->relocs
,
18174 if (htab
->glink
!= NULL
18175 && htab
->glink
->reloc_count
!= 0
18176 && !_bfd_elf_link_output_relocs (output_bfd
,
18178 elf_section_data (htab
->glink
)->rela
.hdr
,
18179 elf_section_data (htab
->glink
)->relocs
,
18184 if (htab
->glink_eh_frame
!= NULL
18185 && htab
->glink_eh_frame
->size
!= 0
18186 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
18187 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
18188 htab
->glink_eh_frame
,
18189 htab
->glink_eh_frame
->contents
))
18192 /* We need to handle writing out multiple GOT sections ourselves,
18193 since we didn't add them to DYNOBJ. We know dynobj is the first
18195 while ((dynobj
= dynobj
->link
.next
) != NULL
)
18199 if (!is_ppc64_elf (dynobj
))
18202 s
= ppc64_elf_tdata (dynobj
)->got
;
18205 && s
->output_section
!= bfd_abs_section_ptr
18206 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
18207 s
->contents
, s
->output_offset
,
18210 s
= ppc64_elf_tdata (dynobj
)->relgot
;
18213 && s
->output_section
!= bfd_abs_section_ptr
18214 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
18215 s
->contents
, s
->output_offset
,
18223 #include "elf64-target.h"
18225 /* FreeBSD support */
18227 #undef TARGET_LITTLE_SYM
18228 #define TARGET_LITTLE_SYM powerpc_elf64_fbsd_le_vec
18229 #undef TARGET_LITTLE_NAME
18230 #define TARGET_LITTLE_NAME "elf64-powerpcle-freebsd"
18232 #undef TARGET_BIG_SYM
18233 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
18234 #undef TARGET_BIG_NAME
18235 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
18238 #define ELF_OSABI ELFOSABI_FREEBSD
18241 #define elf64_bed elf64_powerpc_fbsd_bed
18243 #include "elf64-target.h"