1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2019 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 */
34 #include "elf/ppc64.h"
35 #include "elf64-ppc.h"
38 static bfd_reloc_status_type ppc64_elf_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_branch_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_toc64_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_prefix_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
58 static bfd_vma opd_entry_value
59 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bfd_boolean
);
61 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
62 #define TARGET_LITTLE_NAME "elf64-powerpcle"
63 #define TARGET_BIG_SYM powerpc_elf64_vec
64 #define TARGET_BIG_NAME "elf64-powerpc"
65 #define ELF_ARCH bfd_arch_powerpc
66 #define ELF_TARGET_ID PPC64_ELF_DATA
67 #define ELF_MACHINE_CODE EM_PPC64
68 #define ELF_MAXPAGESIZE 0x10000
69 #define ELF_COMMONPAGESIZE 0x1000
70 #define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
71 #define elf_info_to_howto ppc64_elf_info_to_howto
73 #define elf_backend_want_got_sym 0
74 #define elf_backend_want_plt_sym 0
75 #define elf_backend_plt_alignment 3
76 #define elf_backend_plt_not_loaded 1
77 #define elf_backend_got_header_size 8
78 #define elf_backend_want_dynrelro 1
79 #define elf_backend_can_gc_sections 1
80 #define elf_backend_can_refcount 1
81 #define elf_backend_rela_normal 1
82 #define elf_backend_dtrel_excludes_plt 1
83 #define elf_backend_default_execstack 0
85 #define bfd_elf64_mkobject ppc64_elf_mkobject
86 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
87 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
88 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
89 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
90 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
91 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
92 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
93 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
94 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
96 #define elf_backend_object_p ppc64_elf_object_p
97 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
98 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
99 #define elf_backend_write_core_note ppc64_elf_write_core_note
100 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
101 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
102 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
103 #define elf_backend_check_directives ppc64_elf_before_check_relocs
104 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
105 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
106 #define elf_backend_check_relocs ppc64_elf_check_relocs
107 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
108 #define elf_backend_gc_keep ppc64_elf_gc_keep
109 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
110 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
111 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
112 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
113 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
114 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
115 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
116 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
117 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
118 #define elf_backend_action_discarded ppc64_elf_action_discarded
119 #define elf_backend_relocate_section ppc64_elf_relocate_section
120 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
121 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
122 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
123 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
124 #define elf_backend_special_sections ppc64_elf_special_sections
125 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
126 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
127 #define elf_backend_get_reloc_section bfd_get_section_by_name
129 /* The name of the dynamic interpreter. This is put in the .interp
131 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
133 /* The size in bytes of an entry in the procedure linkage table. */
134 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
135 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
137 /* The initial size of the plt reserved for the dynamic linker. */
138 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
140 /* Offsets to some stack save slots. */
142 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
143 /* This one is dodgy. ELFv2 does not have a linker word, so use the
144 CR save slot. Used only by optimised __tls_get_addr call stub,
145 relying on __tls_get_addr_opt not saving CR.. */
146 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
148 /* TOC base pointers offset from start of TOC. */
149 #define TOC_BASE_OFF 0x8000
150 /* TOC base alignment. */
151 #define TOC_BASE_ALIGN 256
153 /* Offset of tp and dtp pointers from start of TLS block. */
154 #define TP_OFFSET 0x7000
155 #define DTP_OFFSET 0x8000
157 /* .plt call stub instructions. The normal stub is like this, but
158 sometimes the .plt entry crosses a 64k boundary and we need to
159 insert an addi to adjust r11. */
160 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
161 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
162 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
163 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
164 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
165 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
166 #define BCTR 0x4e800420 /* bctr */
168 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
169 #define ADDI_R12_R11 0x398b0000 /* addi %r12,%r11,off@l */
170 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
171 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
172 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
174 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
175 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
176 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
177 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
178 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
179 #define BNECTR 0x4ca20420 /* bnectr+ */
180 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
182 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
183 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
184 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
186 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
187 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
188 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
190 #define LI_R11_0 0x39600000 /* li %r11,0 */
191 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
192 #define LIS_R11 0x3d600000 /* lis %r11,xxx@ha */
193 #define LIS_R12 0x3d800000 /* lis %r12,xxx@ha */
194 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
195 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
196 #define ADDIS_R12_R11 0x3d8b0000 /* addis %r12,%r11,xxx@ha */
197 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
198 #define ORIS_R12_R12_0 0x658c0000 /* oris %r12,%r12,xxx@hi */
199 #define ORI_R11_R11_0 0x616b0000 /* ori %r11,%r11,xxx@l */
200 #define ORI_R12_R12_0 0x618c0000 /* ori %r12,%r12,xxx@l */
201 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
202 #define SLDI_R11_R11_34 0x796b1746 /* sldi %r11,%r11,34 */
203 #define SLDI_R12_R12_32 0x799c07c6 /* sldi %r12,%r12,32 */
204 #define LDX_R12_R11_R12 0x7d8b602a /* ldx %r12,%r11,%r12 */
205 #define ADD_R12_R11_R12 0x7d8b6214 /* add %r12,%r11,%r12 */
206 #define PADDI_R12_PC 0x0610000039800000ULL
207 #define PLD_R12_PC 0x04100000e5800000ULL
208 #define PNOP 0x0700000000000000ULL
210 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
211 #define GLINK_PLTRESOLVE_SIZE(htab) \
212 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
216 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
217 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
219 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
220 /* ld %2,(0b-1b)(%11) */
221 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
222 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
228 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
229 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
230 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
231 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
232 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
235 #define NOP 0x60000000
237 /* Some other nops. */
238 #define CROR_151515 0x4def7b82
239 #define CROR_313131 0x4ffffb82
241 /* .glink entries for the first 32k functions are two instructions. */
242 #define LI_R0_0 0x38000000 /* li %r0,0 */
243 #define B_DOT 0x48000000 /* b . */
245 /* After that, we need two instructions to load the index, followed by
247 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
248 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
250 /* Instructions used by the save and restore reg functions. */
251 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
252 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
253 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
254 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
255 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
256 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
257 #define LI_R12_0 0x39800000 /* li %r12,0 */
258 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
259 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
260 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
261 #define BLR 0x4e800020 /* blr */
263 /* Since .opd is an array of descriptors and each entry will end up
264 with identical R_PPC64_RELATIVE relocs, there is really no need to
265 propagate .opd relocs; The dynamic linker should be taught to
266 relocate .opd without reloc entries. */
267 #ifndef NO_OPD_RELOCS
268 #define NO_OPD_RELOCS 0
272 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
276 abiversion (bfd
*abfd
)
278 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
282 set_abiversion (bfd
*abfd
, int ver
)
284 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
285 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
288 /* Relocation HOWTO's. */
289 /* Like other ELF RELA targets that don't apply multiple
290 field-altering relocations to the same localation, src_mask is
291 always zero and pcrel_offset is the same as pc_relative.
292 PowerPC can always use a zero bitpos, even when the field is not at
293 the LSB. For example, a REL24 could use rightshift=2, bisize=24
294 and bitpos=2 which matches the ABI description, or as we do here,
295 rightshift=0, bitsize=26 and bitpos=0. */
296 #define HOW(type, size, bitsize, mask, rightshift, pc_relative, \
297 complain, special_func) \
298 HOWTO (type, rightshift, size, bitsize, pc_relative, 0, \
299 complain_overflow_ ## complain, special_func, \
300 #type, FALSE, 0, mask, pc_relative)
302 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
304 static reloc_howto_type ppc64_elf_howto_raw
[] =
306 /* This reloc does nothing. */
307 HOW (R_PPC64_NONE
, 3, 0, 0, 0, FALSE
, dont
,
308 bfd_elf_generic_reloc
),
310 /* A standard 32 bit relocation. */
311 HOW (R_PPC64_ADDR32
, 2, 32, 0xffffffff, 0, FALSE
, bitfield
,
312 bfd_elf_generic_reloc
),
314 /* An absolute 26 bit branch; the lower two bits must be zero.
315 FIXME: we don't check that, we just clear them. */
316 HOW (R_PPC64_ADDR24
, 2, 26, 0x03fffffc, 0, FALSE
, bitfield
,
317 bfd_elf_generic_reloc
),
319 /* A standard 16 bit relocation. */
320 HOW (R_PPC64_ADDR16
, 1, 16, 0xffff, 0, FALSE
, bitfield
,
321 bfd_elf_generic_reloc
),
323 /* A 16 bit relocation without overflow. */
324 HOW (R_PPC64_ADDR16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
325 bfd_elf_generic_reloc
),
327 /* Bits 16-31 of an address. */
328 HOW (R_PPC64_ADDR16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
329 bfd_elf_generic_reloc
),
331 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
332 bits, treated as a signed number, is negative. */
333 HOW (R_PPC64_ADDR16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
336 /* An absolute 16 bit branch; the lower two bits must be zero.
337 FIXME: we don't check that, we just clear them. */
338 HOW (R_PPC64_ADDR14
, 2, 16, 0x0000fffc, 0, FALSE
, signed,
339 ppc64_elf_branch_reloc
),
341 /* An absolute 16 bit branch, for which bit 10 should be set to
342 indicate that the branch is expected to be taken. The lower two
343 bits must be zero. */
344 HOW (R_PPC64_ADDR14_BRTAKEN
, 2, 16, 0x0000fffc, 0, FALSE
, signed,
345 ppc64_elf_brtaken_reloc
),
347 /* An absolute 16 bit branch, for which bit 10 should be set to
348 indicate that the branch is not expected to be taken. The lower
349 two bits must be zero. */
350 HOW (R_PPC64_ADDR14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, FALSE
, signed,
351 ppc64_elf_brtaken_reloc
),
353 /* A relative 26 bit branch; the lower two bits must be zero. */
354 HOW (R_PPC64_REL24
, 2, 26, 0x03fffffc, 0, TRUE
, signed,
355 ppc64_elf_branch_reloc
),
357 /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer. */
358 HOW (R_PPC64_REL24_NOTOC
, 2, 26, 0x03fffffc, 0, TRUE
, signed,
359 ppc64_elf_branch_reloc
),
361 /* A relative 16 bit branch; the lower two bits must be zero. */
362 HOW (R_PPC64_REL14
, 2, 16, 0x0000fffc, 0, TRUE
, signed,
363 ppc64_elf_branch_reloc
),
365 /* A relative 16 bit branch. Bit 10 should be set to indicate that
366 the branch is expected to be taken. The lower two bits must be
368 HOW (R_PPC64_REL14_BRTAKEN
, 2, 16, 0x0000fffc, 0, TRUE
, signed,
369 ppc64_elf_brtaken_reloc
),
371 /* A relative 16 bit branch. Bit 10 should be set to indicate that
372 the branch is not expected to be taken. The lower two bits must
374 HOW (R_PPC64_REL14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, TRUE
, signed,
375 ppc64_elf_brtaken_reloc
),
377 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
379 HOW (R_PPC64_GOT16
, 1, 16, 0xffff, 0, FALSE
, signed,
380 ppc64_elf_unhandled_reloc
),
382 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
384 HOW (R_PPC64_GOT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
385 ppc64_elf_unhandled_reloc
),
387 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
389 HOW (R_PPC64_GOT16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
390 ppc64_elf_unhandled_reloc
),
392 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
394 HOW (R_PPC64_GOT16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
395 ppc64_elf_unhandled_reloc
),
397 /* This is used only by the dynamic linker. The symbol should exist
398 both in the object being run and in some shared library. The
399 dynamic linker copies the data addressed by the symbol from the
400 shared library into the object, because the object being
401 run has to have the data at some particular address. */
402 HOW (R_PPC64_COPY
, 0, 0, 0, 0, FALSE
, dont
,
403 ppc64_elf_unhandled_reloc
),
405 /* Like R_PPC64_ADDR64, but used when setting global offset table
407 HOW (R_PPC64_GLOB_DAT
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
408 ppc64_elf_unhandled_reloc
),
410 /* Created by the link editor. Marks a procedure linkage table
411 entry for a symbol. */
412 HOW (R_PPC64_JMP_SLOT
, 0, 0, 0, 0, FALSE
, dont
,
413 ppc64_elf_unhandled_reloc
),
415 /* Used only by the dynamic linker. When the object is run, this
416 doubleword64 is set to the load address of the object, plus the
418 HOW (R_PPC64_RELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
419 bfd_elf_generic_reloc
),
421 /* Like R_PPC64_ADDR32, but may be unaligned. */
422 HOW (R_PPC64_UADDR32
, 2, 32, 0xffffffff, 0, FALSE
, bitfield
,
423 bfd_elf_generic_reloc
),
425 /* Like R_PPC64_ADDR16, but may be unaligned. */
426 HOW (R_PPC64_UADDR16
, 1, 16, 0xffff, 0, FALSE
, bitfield
,
427 bfd_elf_generic_reloc
),
429 /* 32-bit PC relative. */
430 HOW (R_PPC64_REL32
, 2, 32, 0xffffffff, 0, TRUE
, signed,
431 bfd_elf_generic_reloc
),
433 /* 32-bit relocation to the symbol's procedure linkage table. */
434 HOW (R_PPC64_PLT32
, 2, 32, 0xffffffff, 0, FALSE
, bitfield
,
435 ppc64_elf_unhandled_reloc
),
437 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
438 FIXME: R_PPC64_PLTREL32 not supported. */
439 HOW (R_PPC64_PLTREL32
, 2, 32, 0xffffffff, 0, TRUE
, signed,
440 ppc64_elf_unhandled_reloc
),
442 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
444 HOW (R_PPC64_PLT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
445 ppc64_elf_unhandled_reloc
),
447 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
449 HOW (R_PPC64_PLT16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
450 ppc64_elf_unhandled_reloc
),
452 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
454 HOW (R_PPC64_PLT16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
455 ppc64_elf_unhandled_reloc
),
457 /* 16-bit section relative relocation. */
458 HOW (R_PPC64_SECTOFF
, 1, 16, 0xffff, 0, FALSE
, signed,
459 ppc64_elf_sectoff_reloc
),
461 /* Like R_PPC64_SECTOFF, but no overflow warning. */
462 HOW (R_PPC64_SECTOFF_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
463 ppc64_elf_sectoff_reloc
),
465 /* 16-bit upper half section relative relocation. */
466 HOW (R_PPC64_SECTOFF_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
467 ppc64_elf_sectoff_reloc
),
469 /* 16-bit upper half adjusted section relative relocation. */
470 HOW (R_PPC64_SECTOFF_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
471 ppc64_elf_sectoff_ha_reloc
),
473 /* Like R_PPC64_REL24 without touching the two least significant bits. */
474 HOW (R_PPC64_REL30
, 2, 30, 0xfffffffc, 2, TRUE
, dont
,
475 bfd_elf_generic_reloc
),
477 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
479 /* A standard 64-bit relocation. */
480 HOW (R_PPC64_ADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
481 bfd_elf_generic_reloc
),
483 /* The bits 32-47 of an address. */
484 HOW (R_PPC64_ADDR16_HIGHER
, 1, 16, 0xffff, 32, FALSE
, dont
,
485 bfd_elf_generic_reloc
),
487 /* The bits 32-47 of an address, plus 1 if the contents of the low
488 16 bits, treated as a signed number, is negative. */
489 HOW (R_PPC64_ADDR16_HIGHERA
, 1, 16, 0xffff, 32, FALSE
, dont
,
492 /* The bits 48-63 of an address. */
493 HOW (R_PPC64_ADDR16_HIGHEST
, 1, 16, 0xffff, 48, FALSE
, dont
,
494 bfd_elf_generic_reloc
),
496 /* The bits 48-63 of an address, plus 1 if the contents of the low
497 16 bits, treated as a signed number, is negative. */
498 HOW (R_PPC64_ADDR16_HIGHESTA
, 1, 16, 0xffff, 48, FALSE
, dont
,
501 /* Like ADDR64, but may be unaligned. */
502 HOW (R_PPC64_UADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
503 bfd_elf_generic_reloc
),
505 /* 64-bit relative relocation. */
506 HOW (R_PPC64_REL64
, 4, 64, 0xffffffffffffffffULL
, 0, TRUE
, dont
,
507 bfd_elf_generic_reloc
),
509 /* 64-bit relocation to the symbol's procedure linkage table. */
510 HOW (R_PPC64_PLT64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
511 ppc64_elf_unhandled_reloc
),
513 /* 64-bit PC relative relocation to the symbol's procedure linkage
515 /* FIXME: R_PPC64_PLTREL64 not supported. */
516 HOW (R_PPC64_PLTREL64
, 4, 64, 0xffffffffffffffffULL
, 0, TRUE
, dont
,
517 ppc64_elf_unhandled_reloc
),
519 /* 16 bit TOC-relative relocation. */
520 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
521 HOW (R_PPC64_TOC16
, 1, 16, 0xffff, 0, FALSE
, signed,
522 ppc64_elf_toc_reloc
),
524 /* 16 bit TOC-relative relocation without overflow. */
525 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
526 HOW (R_PPC64_TOC16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
527 ppc64_elf_toc_reloc
),
529 /* 16 bit TOC-relative relocation, high 16 bits. */
530 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
531 HOW (R_PPC64_TOC16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
532 ppc64_elf_toc_reloc
),
534 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
535 contents of the low 16 bits, treated as a signed number, is
537 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
538 HOW (R_PPC64_TOC16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
539 ppc64_elf_toc_ha_reloc
),
541 /* 64-bit relocation; insert value of TOC base (.TOC.). */
542 /* R_PPC64_TOC 51 doubleword64 .TOC. */
543 HOW (R_PPC64_TOC
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
544 ppc64_elf_toc64_reloc
),
546 /* Like R_PPC64_GOT16, but also informs the link editor that the
547 value to relocate may (!) refer to a PLT entry which the link
548 editor (a) may replace with the symbol value. If the link editor
549 is unable to fully resolve the symbol, it may (b) create a PLT
550 entry and store the address to the new PLT entry in the GOT.
551 This permits lazy resolution of function symbols at run time.
552 The link editor may also skip all of this and just (c) emit a
553 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
554 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
555 HOW (R_PPC64_PLTGOT16
, 1, 16, 0xffff, 0, FALSE
,signed,
556 ppc64_elf_unhandled_reloc
),
558 /* Like R_PPC64_PLTGOT16, but without overflow. */
559 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
560 HOW (R_PPC64_PLTGOT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
561 ppc64_elf_unhandled_reloc
),
563 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
564 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
565 HOW (R_PPC64_PLTGOT16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
566 ppc64_elf_unhandled_reloc
),
568 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
569 1 if the contents of the low 16 bits, treated as a signed number,
571 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
572 HOW (R_PPC64_PLTGOT16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
573 ppc64_elf_unhandled_reloc
),
575 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
576 HOW (R_PPC64_ADDR16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
577 bfd_elf_generic_reloc
),
579 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
580 HOW (R_PPC64_ADDR16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
581 bfd_elf_generic_reloc
),
583 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
584 HOW (R_PPC64_GOT16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
585 ppc64_elf_unhandled_reloc
),
587 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
588 HOW (R_PPC64_GOT16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
589 ppc64_elf_unhandled_reloc
),
591 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
592 HOW (R_PPC64_PLT16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
593 ppc64_elf_unhandled_reloc
),
595 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
596 HOW (R_PPC64_SECTOFF_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
597 ppc64_elf_sectoff_reloc
),
599 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
600 HOW (R_PPC64_SECTOFF_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
601 ppc64_elf_sectoff_reloc
),
603 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
604 HOW (R_PPC64_TOC16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
605 ppc64_elf_toc_reloc
),
607 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
608 HOW (R_PPC64_TOC16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
609 ppc64_elf_toc_reloc
),
611 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
612 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
613 HOW (R_PPC64_PLTGOT16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
614 ppc64_elf_unhandled_reloc
),
616 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
617 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
618 HOW (R_PPC64_PLTGOT16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
619 ppc64_elf_unhandled_reloc
),
621 /* Marker relocs for TLS. */
622 HOW (R_PPC64_TLS
, 2, 32, 0, 0, FALSE
, dont
,
623 bfd_elf_generic_reloc
),
625 HOW (R_PPC64_TLSGD
, 2, 32, 0, 0, FALSE
, dont
,
626 bfd_elf_generic_reloc
),
628 HOW (R_PPC64_TLSLD
, 2, 32, 0, 0, FALSE
, dont
,
629 bfd_elf_generic_reloc
),
631 /* Marker reloc for optimizing r2 save in prologue rather than on
632 each plt call stub. */
633 HOW (R_PPC64_TOCSAVE
, 2, 32, 0, 0, FALSE
, dont
,
634 bfd_elf_generic_reloc
),
636 /* Marker relocs on inline plt call instructions. */
637 HOW (R_PPC64_PLTSEQ
, 2, 32, 0, 0, FALSE
, dont
,
638 bfd_elf_generic_reloc
),
640 HOW (R_PPC64_PLTCALL
, 2, 32, 0, 0, FALSE
, dont
,
641 bfd_elf_generic_reloc
),
643 /* Computes the load module index of the load module that contains the
644 definition of its TLS sym. */
645 HOW (R_PPC64_DTPMOD64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
646 ppc64_elf_unhandled_reloc
),
648 /* Computes a dtv-relative displacement, the difference between the value
649 of sym+add and the base address of the thread-local storage block that
650 contains the definition of sym, minus 0x8000. */
651 HOW (R_PPC64_DTPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
652 ppc64_elf_unhandled_reloc
),
654 /* A 16 bit dtprel reloc. */
655 HOW (R_PPC64_DTPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
656 ppc64_elf_unhandled_reloc
),
658 /* Like DTPREL16, but no overflow. */
659 HOW (R_PPC64_DTPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
660 ppc64_elf_unhandled_reloc
),
662 /* Like DTPREL16_LO, but next higher group of 16 bits. */
663 HOW (R_PPC64_DTPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
664 ppc64_elf_unhandled_reloc
),
666 /* Like DTPREL16_HI, but adjust for low 16 bits. */
667 HOW (R_PPC64_DTPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
668 ppc64_elf_unhandled_reloc
),
670 /* Like DTPREL16_HI, but next higher group of 16 bits. */
671 HOW (R_PPC64_DTPREL16_HIGHER
, 1, 16, 0xffff, 32, FALSE
, dont
,
672 ppc64_elf_unhandled_reloc
),
674 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
675 HOW (R_PPC64_DTPREL16_HIGHERA
, 1, 16, 0xffff, 32, FALSE
, dont
,
676 ppc64_elf_unhandled_reloc
),
678 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
679 HOW (R_PPC64_DTPREL16_HIGHEST
, 1, 16, 0xffff, 48, FALSE
, dont
,
680 ppc64_elf_unhandled_reloc
),
682 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
683 HOW (R_PPC64_DTPREL16_HIGHESTA
, 1, 16, 0xffff, 48, FALSE
, dont
,
684 ppc64_elf_unhandled_reloc
),
686 /* Like DTPREL16, but for insns with a DS field. */
687 HOW (R_PPC64_DTPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
688 ppc64_elf_unhandled_reloc
),
690 /* Like DTPREL16_DS, but no overflow. */
691 HOW (R_PPC64_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
692 ppc64_elf_unhandled_reloc
),
694 /* Computes a tp-relative displacement, the difference between the value of
695 sym+add and the value of the thread pointer (r13). */
696 HOW (R_PPC64_TPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
697 ppc64_elf_unhandled_reloc
),
699 /* A 16 bit tprel reloc. */
700 HOW (R_PPC64_TPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
701 ppc64_elf_unhandled_reloc
),
703 /* Like TPREL16, but no overflow. */
704 HOW (R_PPC64_TPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
705 ppc64_elf_unhandled_reloc
),
707 /* Like TPREL16_LO, but next higher group of 16 bits. */
708 HOW (R_PPC64_TPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
709 ppc64_elf_unhandled_reloc
),
711 /* Like TPREL16_HI, but adjust for low 16 bits. */
712 HOW (R_PPC64_TPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
713 ppc64_elf_unhandled_reloc
),
715 /* Like TPREL16_HI, but next higher group of 16 bits. */
716 HOW (R_PPC64_TPREL16_HIGHER
, 1, 16, 0xffff, 32, FALSE
, dont
,
717 ppc64_elf_unhandled_reloc
),
719 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
720 HOW (R_PPC64_TPREL16_HIGHERA
, 1, 16, 0xffff, 32, FALSE
, dont
,
721 ppc64_elf_unhandled_reloc
),
723 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
724 HOW (R_PPC64_TPREL16_HIGHEST
, 1, 16, 0xffff, 48, FALSE
, dont
,
725 ppc64_elf_unhandled_reloc
),
727 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
728 HOW (R_PPC64_TPREL16_HIGHESTA
, 1, 16, 0xffff, 48, FALSE
, dont
,
729 ppc64_elf_unhandled_reloc
),
731 /* Like TPREL16, but for insns with a DS field. */
732 HOW (R_PPC64_TPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
733 ppc64_elf_unhandled_reloc
),
735 /* Like TPREL16_DS, but no overflow. */
736 HOW (R_PPC64_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
737 ppc64_elf_unhandled_reloc
),
739 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
740 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
741 to the first entry relative to the TOC base (r2). */
742 HOW (R_PPC64_GOT_TLSGD16
, 1, 16, 0xffff, 0, FALSE
, signed,
743 ppc64_elf_unhandled_reloc
),
745 /* Like GOT_TLSGD16, but no overflow. */
746 HOW (R_PPC64_GOT_TLSGD16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
747 ppc64_elf_unhandled_reloc
),
749 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
750 HOW (R_PPC64_GOT_TLSGD16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
751 ppc64_elf_unhandled_reloc
),
753 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
754 HOW (R_PPC64_GOT_TLSGD16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
755 ppc64_elf_unhandled_reloc
),
757 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
758 with values (sym+add)@dtpmod and zero, and computes the offset to the
759 first entry relative to the TOC base (r2). */
760 HOW (R_PPC64_GOT_TLSLD16
, 1, 16, 0xffff, 0, FALSE
, signed,
761 ppc64_elf_unhandled_reloc
),
763 /* Like GOT_TLSLD16, but no overflow. */
764 HOW (R_PPC64_GOT_TLSLD16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
765 ppc64_elf_unhandled_reloc
),
767 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
768 HOW (R_PPC64_GOT_TLSLD16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
769 ppc64_elf_unhandled_reloc
),
771 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
772 HOW (R_PPC64_GOT_TLSLD16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
773 ppc64_elf_unhandled_reloc
),
775 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
776 the offset to the entry relative to the TOC base (r2). */
777 HOW (R_PPC64_GOT_DTPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
778 ppc64_elf_unhandled_reloc
),
780 /* Like GOT_DTPREL16_DS, but no overflow. */
781 HOW (R_PPC64_GOT_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
782 ppc64_elf_unhandled_reloc
),
784 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
785 HOW (R_PPC64_GOT_DTPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
786 ppc64_elf_unhandled_reloc
),
788 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
789 HOW (R_PPC64_GOT_DTPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
790 ppc64_elf_unhandled_reloc
),
792 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
793 offset to the entry relative to the TOC base (r2). */
794 HOW (R_PPC64_GOT_TPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
795 ppc64_elf_unhandled_reloc
),
797 /* Like GOT_TPREL16_DS, but no overflow. */
798 HOW (R_PPC64_GOT_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
799 ppc64_elf_unhandled_reloc
),
801 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
802 HOW (R_PPC64_GOT_TPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
803 ppc64_elf_unhandled_reloc
),
805 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
806 HOW (R_PPC64_GOT_TPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
807 ppc64_elf_unhandled_reloc
),
809 HOW (R_PPC64_JMP_IREL
, 0, 0, 0, 0, FALSE
, dont
,
810 ppc64_elf_unhandled_reloc
),
812 HOW (R_PPC64_IRELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
813 bfd_elf_generic_reloc
),
815 /* A 16 bit relative relocation. */
816 HOW (R_PPC64_REL16
, 1, 16, 0xffff, 0, TRUE
, signed,
817 bfd_elf_generic_reloc
),
819 /* A 16 bit relative relocation without overflow. */
820 HOW (R_PPC64_REL16_LO
, 1, 16, 0xffff, 0, TRUE
, dont
,
821 bfd_elf_generic_reloc
),
823 /* The high order 16 bits of a relative address. */
824 HOW (R_PPC64_REL16_HI
, 1, 16, 0xffff, 16, TRUE
, signed,
825 bfd_elf_generic_reloc
),
827 /* The high order 16 bits of a relative address, plus 1 if the contents of
828 the low 16 bits, treated as a signed number, is negative. */
829 HOW (R_PPC64_REL16_HA
, 1, 16, 0xffff, 16, TRUE
, signed,
832 HOW (R_PPC64_REL16_HIGH
, 1, 16, 0xffff, 16, TRUE
, dont
,
833 bfd_elf_generic_reloc
),
835 HOW (R_PPC64_REL16_HIGHA
, 1, 16, 0xffff, 16, TRUE
, dont
,
838 HOW (R_PPC64_REL16_HIGHER
, 1, 16, 0xffff, 32, TRUE
, dont
,
839 bfd_elf_generic_reloc
),
841 HOW (R_PPC64_REL16_HIGHERA
, 1, 16, 0xffff, 32, TRUE
, dont
,
844 HOW (R_PPC64_REL16_HIGHEST
, 1, 16, 0xffff, 48, TRUE
, dont
,
845 bfd_elf_generic_reloc
),
847 HOW (R_PPC64_REL16_HIGHESTA
, 1, 16, 0xffff, 48, TRUE
, dont
,
850 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
851 HOW (R_PPC64_REL16DX_HA
, 2, 16, 0x1fffc1, 16, TRUE
, signed,
854 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
855 HOW (R_PPC64_16DX_HA
, 2, 16, 0x1fffc1, 16, FALSE
, signed,
858 /* Like R_PPC64_ADDR16_HI, but no overflow. */
859 HOW (R_PPC64_ADDR16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
860 bfd_elf_generic_reloc
),
862 /* Like R_PPC64_ADDR16_HA, but no overflow. */
863 HOW (R_PPC64_ADDR16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
866 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
867 HOW (R_PPC64_DTPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
868 ppc64_elf_unhandled_reloc
),
870 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
871 HOW (R_PPC64_DTPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
872 ppc64_elf_unhandled_reloc
),
874 /* Like R_PPC64_TPREL16_HI, but no overflow. */
875 HOW (R_PPC64_TPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
876 ppc64_elf_unhandled_reloc
),
878 /* Like R_PPC64_TPREL16_HA, but no overflow. */
879 HOW (R_PPC64_TPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
880 ppc64_elf_unhandled_reloc
),
882 /* Marker reloc on ELFv2 large-model function entry. */
883 HOW (R_PPC64_ENTRY
, 2, 32, 0, 0, FALSE
, dont
,
884 bfd_elf_generic_reloc
),
886 /* Like ADDR64, but use local entry point of function. */
887 HOW (R_PPC64_ADDR64_LOCAL
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
888 bfd_elf_generic_reloc
),
890 HOW (R_PPC64_PLTSEQ_NOTOC
, 2, 32, 0, 0, FALSE
, dont
,
891 bfd_elf_generic_reloc
),
893 HOW (R_PPC64_PLTCALL_NOTOC
, 2, 32, 0, 0, FALSE
, dont
,
894 bfd_elf_generic_reloc
),
896 HOW (R_PPC64_PCREL_OPT
, 2, 32, 0, 0, FALSE
, dont
,
897 bfd_elf_generic_reloc
),
899 HOW (R_PPC64_D34
, 4, 34, 0x3ffff0000ffffULL
, 0, FALSE
, signed,
900 ppc64_elf_prefix_reloc
),
902 HOW (R_PPC64_D34_LO
, 4, 34, 0x3ffff0000ffffULL
, 0, FALSE
, dont
,
903 ppc64_elf_prefix_reloc
),
905 HOW (R_PPC64_D34_HI30
, 4, 34, 0x3ffff0000ffffULL
, 34, FALSE
, dont
,
906 ppc64_elf_prefix_reloc
),
908 HOW (R_PPC64_D34_HA30
, 4, 34, 0x3ffff0000ffffULL
, 34, FALSE
, dont
,
909 ppc64_elf_prefix_reloc
),
911 HOW (R_PPC64_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
912 ppc64_elf_prefix_reloc
),
914 HOW (R_PPC64_GOT_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
915 ppc64_elf_unhandled_reloc
),
917 HOW (R_PPC64_PLT_PCREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
918 ppc64_elf_unhandled_reloc
),
920 HOW (R_PPC64_PLT_PCREL34_NOTOC
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
921 ppc64_elf_unhandled_reloc
),
923 HOW (R_PPC64_TPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, FALSE
, signed,
924 ppc64_elf_unhandled_reloc
),
926 HOW (R_PPC64_DTPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, FALSE
, signed,
927 ppc64_elf_unhandled_reloc
),
929 HOW (R_PPC64_GOT_TLSGD34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
930 ppc64_elf_unhandled_reloc
),
932 HOW (R_PPC64_GOT_TLSLD34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
933 ppc64_elf_unhandled_reloc
),
935 HOW (R_PPC64_GOT_TPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
936 ppc64_elf_unhandled_reloc
),
938 HOW (R_PPC64_GOT_DTPREL34
, 4, 34, 0x3ffff0000ffffULL
, 0, TRUE
, signed,
939 ppc64_elf_unhandled_reloc
),
941 HOW (R_PPC64_ADDR16_HIGHER34
, 1, 16, 0xffff, 34, FALSE
, dont
,
942 bfd_elf_generic_reloc
),
944 HOW (R_PPC64_ADDR16_HIGHERA34
, 1, 16, 0xffff, 34, FALSE
, dont
,
947 HOW (R_PPC64_ADDR16_HIGHEST34
, 1, 16, 0xffff, 50, FALSE
, dont
,
948 bfd_elf_generic_reloc
),
950 HOW (R_PPC64_ADDR16_HIGHESTA34
, 1, 16, 0xffff, 50, FALSE
, dont
,
953 HOW (R_PPC64_REL16_HIGHER34
, 1, 16, 0xffff, 34, TRUE
, dont
,
954 bfd_elf_generic_reloc
),
956 HOW (R_PPC64_REL16_HIGHERA34
, 1, 16, 0xffff, 34, TRUE
, dont
,
959 HOW (R_PPC64_REL16_HIGHEST34
, 1, 16, 0xffff, 50, TRUE
, dont
,
960 bfd_elf_generic_reloc
),
962 HOW (R_PPC64_REL16_HIGHESTA34
, 1, 16, 0xffff, 50, TRUE
, dont
,
965 HOW (R_PPC64_D28
, 4, 28, 0xfff0000ffffULL
, 0, FALSE
, signed,
966 ppc64_elf_prefix_reloc
),
968 HOW (R_PPC64_PCREL28
, 4, 28, 0xfff0000ffffULL
, 0, TRUE
, signed,
969 ppc64_elf_prefix_reloc
),
971 /* GNU extension to record C++ vtable hierarchy. */
972 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, FALSE
, dont
,
975 /* GNU extension to record C++ vtable member usage. */
976 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, FALSE
, dont
,
981 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
985 ppc_howto_init (void)
987 unsigned int i
, type
;
989 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
991 type
= ppc64_elf_howto_raw
[i
].type
;
992 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
993 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
997 static reloc_howto_type
*
998 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
999 bfd_reloc_code_real_type code
)
1001 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1003 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1004 /* Initialize howto table if needed. */
1010 /* xgettext:c-format */
1011 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
1013 bfd_set_error (bfd_error_bad_value
);
1016 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1018 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1020 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1022 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1024 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1026 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1028 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
1030 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1032 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
1034 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1036 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1038 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1040 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1042 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
1044 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1046 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1048 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1050 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1052 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1054 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1056 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1058 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1060 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1062 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1064 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1066 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1068 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1070 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1072 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1074 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1076 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1078 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1080 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1082 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1084 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1086 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1088 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1090 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1092 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1094 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1096 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1098 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1100 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1102 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1104 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1106 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1108 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1110 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1112 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1114 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1116 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1118 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1120 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1122 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1124 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1126 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1128 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1130 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1132 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1134 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1136 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1138 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1140 case BFD_RELOC_PPC64_TLS_PCREL
:
1141 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1143 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1145 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1147 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1149 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1151 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1153 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1155 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1157 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1159 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1161 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1163 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1165 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1167 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1169 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1171 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1173 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1175 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1177 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1179 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1181 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1183 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1185 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1187 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1189 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1191 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1193 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1195 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1197 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1199 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1201 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1203 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1205 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1207 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1209 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1211 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1213 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1215 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1217 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1219 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1221 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1223 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1225 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1227 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1229 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1231 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1233 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1235 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1237 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1239 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1241 case BFD_RELOC_PPC64_REL16_HIGH
: r
= R_PPC64_REL16_HIGH
;
1243 case BFD_RELOC_PPC64_REL16_HIGHA
: r
= R_PPC64_REL16_HIGHA
;
1245 case BFD_RELOC_PPC64_REL16_HIGHER
: r
= R_PPC64_REL16_HIGHER
;
1247 case BFD_RELOC_PPC64_REL16_HIGHERA
: r
= R_PPC64_REL16_HIGHERA
;
1249 case BFD_RELOC_PPC64_REL16_HIGHEST
: r
= R_PPC64_REL16_HIGHEST
;
1251 case BFD_RELOC_PPC64_REL16_HIGHESTA
: r
= R_PPC64_REL16_HIGHESTA
;
1253 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1255 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1257 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1259 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1261 case BFD_RELOC_PPC64_D34
: r
= R_PPC64_D34
;
1263 case BFD_RELOC_PPC64_D34_LO
: r
= R_PPC64_D34_LO
;
1265 case BFD_RELOC_PPC64_D34_HI30
: r
= R_PPC64_D34_HI30
;
1267 case BFD_RELOC_PPC64_D34_HA30
: r
= R_PPC64_D34_HA30
;
1269 case BFD_RELOC_PPC64_PCREL34
: r
= R_PPC64_PCREL34
;
1271 case BFD_RELOC_PPC64_GOT_PCREL34
: r
= R_PPC64_GOT_PCREL34
;
1273 case BFD_RELOC_PPC64_PLT_PCREL34
: r
= R_PPC64_PLT_PCREL34
;
1275 case BFD_RELOC_PPC64_TPREL34
: r
= R_PPC64_TPREL34
;
1277 case BFD_RELOC_PPC64_DTPREL34
: r
= R_PPC64_DTPREL34
;
1279 case BFD_RELOC_PPC64_GOT_TLSGD34
: r
= R_PPC64_GOT_TLSGD34
;
1281 case BFD_RELOC_PPC64_GOT_TLSLD34
: r
= R_PPC64_GOT_TLSLD34
;
1283 case BFD_RELOC_PPC64_GOT_TPREL34
: r
= R_PPC64_GOT_TPREL34
;
1285 case BFD_RELOC_PPC64_GOT_DTPREL34
: r
= R_PPC64_GOT_DTPREL34
;
1287 case BFD_RELOC_PPC64_ADDR16_HIGHER34
: r
= R_PPC64_ADDR16_HIGHER34
;
1289 case BFD_RELOC_PPC64_ADDR16_HIGHERA34
: r
= R_PPC64_ADDR16_HIGHERA34
;
1291 case BFD_RELOC_PPC64_ADDR16_HIGHEST34
: r
= R_PPC64_ADDR16_HIGHEST34
;
1293 case BFD_RELOC_PPC64_ADDR16_HIGHESTA34
: r
= R_PPC64_ADDR16_HIGHESTA34
;
1295 case BFD_RELOC_PPC64_REL16_HIGHER34
: r
= R_PPC64_REL16_HIGHER34
;
1297 case BFD_RELOC_PPC64_REL16_HIGHERA34
: r
= R_PPC64_REL16_HIGHERA34
;
1299 case BFD_RELOC_PPC64_REL16_HIGHEST34
: r
= R_PPC64_REL16_HIGHEST34
;
1301 case BFD_RELOC_PPC64_REL16_HIGHESTA34
: r
= R_PPC64_REL16_HIGHESTA34
;
1303 case BFD_RELOC_PPC64_D28
: r
= R_PPC64_D28
;
1305 case BFD_RELOC_PPC64_PCREL28
: r
= R_PPC64_PCREL28
;
1307 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1309 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1313 return ppc64_elf_howto_table
[r
];
1316 static reloc_howto_type
*
1317 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1322 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1323 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1324 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1325 return &ppc64_elf_howto_raw
[i
];
1330 /* Set the howto pointer for a PowerPC ELF reloc. */
1333 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1334 Elf_Internal_Rela
*dst
)
1338 /* Initialize howto table if needed. */
1339 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1342 type
= ELF64_R_TYPE (dst
->r_info
);
1343 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1345 /* xgettext:c-format */
1346 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1348 bfd_set_error (bfd_error_bad_value
);
1351 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1352 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1354 /* xgettext:c-format */
1355 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1357 bfd_set_error (bfd_error_bad_value
);
1364 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1366 static bfd_reloc_status_type
1367 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1368 void *data
, asection
*input_section
,
1369 bfd
*output_bfd
, char **error_message
)
1371 enum elf_ppc64_reloc_type r_type
;
1373 bfd_size_type octets
;
1376 /* If this is a relocatable link (output_bfd test tells us), just
1377 call the generic function. Any adjustment will be done at final
1379 if (output_bfd
!= NULL
)
1380 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1381 input_section
, output_bfd
, error_message
);
1383 /* Adjust the addend for sign extension of the low 16 (or 34) bits.
1384 We won't actually be using the low bits, so trashing them
1386 r_type
= reloc_entry
->howto
->type
;
1387 if (r_type
== R_PPC64_ADDR16_HIGHERA34
1388 || r_type
== R_PPC64_ADDR16_HIGHESTA34
1389 || r_type
== R_PPC64_REL16_HIGHERA34
1390 || r_type
== R_PPC64_REL16_HIGHESTA34
)
1391 reloc_entry
->addend
+= 1ULL << 33;
1393 reloc_entry
->addend
+= 1U << 15;
1394 if (r_type
!= R_PPC64_REL16DX_HA
)
1395 return bfd_reloc_continue
;
1398 if (!bfd_is_com_section (symbol
->section
))
1399 value
= symbol
->value
;
1400 value
+= (reloc_entry
->addend
1401 + symbol
->section
->output_offset
1402 + symbol
->section
->output_section
->vma
);
1403 value
-= (reloc_entry
->address
1404 + input_section
->output_offset
1405 + input_section
->output_section
->vma
);
1406 value
= (bfd_signed_vma
) value
>> 16;
1408 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1409 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1411 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1412 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1413 if (value
+ 0x8000 > 0xffff)
1414 return bfd_reloc_overflow
;
1415 return bfd_reloc_ok
;
1418 static bfd_reloc_status_type
1419 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1420 void *data
, asection
*input_section
,
1421 bfd
*output_bfd
, char **error_message
)
1423 if (output_bfd
!= NULL
)
1424 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1425 input_section
, output_bfd
, error_message
);
1427 if (strcmp (symbol
->section
->name
, ".opd") == 0
1428 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1430 bfd_vma dest
= opd_entry_value (symbol
->section
,
1431 symbol
->value
+ reloc_entry
->addend
,
1433 if (dest
!= (bfd_vma
) -1)
1434 reloc_entry
->addend
= dest
- (symbol
->value
1435 + symbol
->section
->output_section
->vma
1436 + symbol
->section
->output_offset
);
1440 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1442 if (symbol
->section
->owner
!= abfd
1443 && symbol
->section
->owner
!= NULL
1444 && abiversion (symbol
->section
->owner
) >= 2)
1448 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1450 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1452 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1454 elfsym
= (elf_symbol_type
*) symdef
;
1460 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1462 return bfd_reloc_continue
;
1465 static bfd_reloc_status_type
1466 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1467 void *data
, asection
*input_section
,
1468 bfd
*output_bfd
, char **error_message
)
1471 enum elf_ppc64_reloc_type r_type
;
1472 bfd_size_type octets
;
1473 /* Assume 'at' branch hints. */
1474 bfd_boolean is_isa_v2
= TRUE
;
1476 /* If this is a relocatable link (output_bfd test tells us), just
1477 call the generic function. Any adjustment will be done at final
1479 if (output_bfd
!= NULL
)
1480 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1481 input_section
, output_bfd
, error_message
);
1483 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1484 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1485 insn
&= ~(0x01 << 21);
1486 r_type
= reloc_entry
->howto
->type
;
1487 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1488 || r_type
== R_PPC64_REL14_BRTAKEN
)
1489 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1493 /* Set 'a' bit. This is 0b00010 in BO field for branch
1494 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1495 for branch on CTR insns (BO == 1a00t or 1a01t). */
1496 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1498 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1508 if (!bfd_is_com_section (symbol
->section
))
1509 target
= symbol
->value
;
1510 target
+= symbol
->section
->output_section
->vma
;
1511 target
+= symbol
->section
->output_offset
;
1512 target
+= reloc_entry
->addend
;
1514 from
= (reloc_entry
->address
1515 + input_section
->output_offset
1516 + input_section
->output_section
->vma
);
1518 /* Invert 'y' bit if not the default. */
1519 if ((bfd_signed_vma
) (target
- from
) < 0)
1522 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1524 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1525 input_section
, output_bfd
, error_message
);
1528 static bfd_reloc_status_type
1529 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1530 void *data
, asection
*input_section
,
1531 bfd
*output_bfd
, char **error_message
)
1533 /* If this is a relocatable link (output_bfd test tells us), just
1534 call the generic function. Any adjustment will be done at final
1536 if (output_bfd
!= NULL
)
1537 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1538 input_section
, output_bfd
, error_message
);
1540 /* Subtract the symbol section base address. */
1541 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1542 return bfd_reloc_continue
;
1545 static bfd_reloc_status_type
1546 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1547 void *data
, asection
*input_section
,
1548 bfd
*output_bfd
, char **error_message
)
1550 /* If this is a relocatable link (output_bfd test tells us), just
1551 call the generic function. Any adjustment will be done at final
1553 if (output_bfd
!= NULL
)
1554 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1555 input_section
, output_bfd
, error_message
);
1557 /* Subtract the symbol section base address. */
1558 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1560 /* Adjust the addend for sign extension of the low 16 bits. */
1561 reloc_entry
->addend
+= 0x8000;
1562 return bfd_reloc_continue
;
1565 static bfd_reloc_status_type
1566 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1567 void *data
, asection
*input_section
,
1568 bfd
*output_bfd
, char **error_message
)
1572 /* If this is a relocatable link (output_bfd test tells us), just
1573 call the generic function. Any adjustment will be done at final
1575 if (output_bfd
!= NULL
)
1576 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1577 input_section
, output_bfd
, error_message
);
1579 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1581 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1583 /* Subtract the TOC base address. */
1584 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1585 return bfd_reloc_continue
;
1588 static bfd_reloc_status_type
1589 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1590 void *data
, asection
*input_section
,
1591 bfd
*output_bfd
, char **error_message
)
1595 /* If this is a relocatable link (output_bfd test tells us), just
1596 call the generic function. Any adjustment will be done at final
1598 if (output_bfd
!= NULL
)
1599 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1600 input_section
, output_bfd
, error_message
);
1602 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1604 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1606 /* Subtract the TOC base address. */
1607 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1609 /* Adjust the addend for sign extension of the low 16 bits. */
1610 reloc_entry
->addend
+= 0x8000;
1611 return bfd_reloc_continue
;
1614 static bfd_reloc_status_type
1615 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1616 void *data
, asection
*input_section
,
1617 bfd
*output_bfd
, char **error_message
)
1620 bfd_size_type octets
;
1622 /* If this is a relocatable link (output_bfd test tells us), just
1623 call the generic function. Any adjustment will be done at final
1625 if (output_bfd
!= NULL
)
1626 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1627 input_section
, output_bfd
, error_message
);
1629 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1631 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1633 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1634 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1635 return bfd_reloc_ok
;
1638 static bfd_reloc_status_type
1639 ppc64_elf_prefix_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1640 void *data
, asection
*input_section
,
1641 bfd
*output_bfd
, char **error_message
)
1646 if (output_bfd
!= NULL
)
1647 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1648 input_section
, output_bfd
, error_message
);
1650 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
1652 insn
|= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
+ 4);
1654 targ
= (symbol
->section
->output_section
->vma
1655 + symbol
->section
->output_offset
1656 + reloc_entry
->addend
);
1657 if (!bfd_is_com_section (symbol
->section
))
1658 targ
+= symbol
->value
;
1659 if (reloc_entry
->howto
->type
== R_PPC64_D34_HA30
)
1661 if (reloc_entry
->howto
->pc_relative
)
1663 bfd_vma from
= (reloc_entry
->address
1664 + input_section
->output_offset
1665 + input_section
->output_section
->vma
);
1668 targ
>>= reloc_entry
->howto
->rightshift
;
1669 insn
&= ~reloc_entry
->howto
->dst_mask
;
1670 insn
|= ((targ
<< 16) | (targ
& 0xffff)) & reloc_entry
->howto
->dst_mask
;
1671 bfd_put_32 (abfd
, insn
>> 32, (bfd_byte
*) data
+ reloc_entry
->address
);
1672 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
+ 4);
1673 if (reloc_entry
->howto
->complain_on_overflow
== complain_overflow_signed
1674 && (targ
+ (1ULL << (reloc_entry
->howto
->bitsize
- 1))
1675 >= 1ULL << reloc_entry
->howto
->bitsize
))
1676 return bfd_reloc_overflow
;
1677 return bfd_reloc_ok
;
1680 static bfd_reloc_status_type
1681 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1682 void *data
, asection
*input_section
,
1683 bfd
*output_bfd
, char **error_message
)
1685 /* If this is a relocatable link (output_bfd test tells us), just
1686 call the generic function. Any adjustment will be done at final
1688 if (output_bfd
!= NULL
)
1689 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1690 input_section
, output_bfd
, error_message
);
1692 if (error_message
!= NULL
)
1694 static char buf
[60];
1695 sprintf (buf
, "generic linker can't handle %s",
1696 reloc_entry
->howto
->name
);
1697 *error_message
= buf
;
1699 return bfd_reloc_dangerous
;
1702 /* Track GOT entries needed for a given symbol. We might need more
1703 than one got entry per symbol. */
1706 struct got_entry
*next
;
1708 /* The symbol addend that we'll be placing in the GOT. */
1711 /* Unlike other ELF targets, we use separate GOT entries for the same
1712 symbol referenced from different input files. This is to support
1713 automatic multiple TOC/GOT sections, where the TOC base can vary
1714 from one input file to another. After partitioning into TOC groups
1715 we merge entries within the group.
1717 Point to the BFD owning this GOT entry. */
1720 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1721 TLS_TPREL or TLS_DTPREL for tls entries. */
1722 unsigned char tls_type
;
1724 /* Non-zero if got.ent points to real entry. */
1725 unsigned char is_indirect
;
1727 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1730 bfd_signed_vma refcount
;
1732 struct got_entry
*ent
;
1736 /* The same for PLT. */
1739 struct plt_entry
*next
;
1745 bfd_signed_vma refcount
;
1750 struct ppc64_elf_obj_tdata
1752 struct elf_obj_tdata elf
;
1754 /* Shortcuts to dynamic linker sections. */
1758 /* Used during garbage collection. We attach global symbols defined
1759 on removed .opd entries to this section so that the sym is removed. */
1760 asection
*deleted_section
;
1762 /* TLS local dynamic got entry handling. Support for multiple GOT
1763 sections means we potentially need one of these for each input bfd. */
1764 struct got_entry tlsld_got
;
1768 /* A copy of relocs before they are modified for --emit-relocs. */
1769 Elf_Internal_Rela
*relocs
;
1771 /* Section contents. */
1775 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1776 the reloc to be in the range -32768 to 32767. */
1777 unsigned int has_small_toc_reloc
: 1;
1779 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1780 instruction not one we handle. */
1781 unsigned int unexpected_toc_insn
: 1;
1783 /* Set if PLT/GOT/TOC relocs that can be optimised are present in
1785 unsigned int has_optrel
: 1;
1788 #define ppc64_elf_tdata(bfd) \
1789 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1791 #define ppc64_tlsld_got(bfd) \
1792 (&ppc64_elf_tdata (bfd)->tlsld_got)
1794 #define is_ppc64_elf(bfd) \
1795 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1796 && elf_object_id (bfd) == PPC64_ELF_DATA)
1798 /* Override the generic function because we store some extras. */
1801 ppc64_elf_mkobject (bfd
*abfd
)
1803 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1807 /* Fix bad default arch selected for a 64 bit input bfd when the
1808 default is 32 bit. Also select arch based on apuinfo. */
1811 ppc64_elf_object_p (bfd
*abfd
)
1813 if (!abfd
->arch_info
->the_default
)
1816 if (abfd
->arch_info
->bits_per_word
== 32)
1818 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1820 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1822 /* Relies on arch after 32 bit default being 64 bit default. */
1823 abfd
->arch_info
= abfd
->arch_info
->next
;
1824 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1827 return _bfd_elf_ppc_set_arch (abfd
);
1830 /* Support for core dump NOTE sections. */
1833 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1835 size_t offset
, size
;
1837 if (note
->descsz
!= 504)
1841 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1844 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1850 /* Make a ".reg/999" section. */
1851 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1852 size
, note
->descpos
+ offset
);
1856 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1858 if (note
->descsz
!= 136)
1861 elf_tdata (abfd
)->core
->pid
1862 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1863 elf_tdata (abfd
)->core
->program
1864 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1865 elf_tdata (abfd
)->core
->command
1866 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1872 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1882 char data
[136] ATTRIBUTE_NONSTRING
;
1885 va_start (ap
, note_type
);
1886 memset (data
, 0, sizeof (data
));
1887 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1888 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1890 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1891 -Wstringop-truncation:
1892 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1894 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1896 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1897 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1901 return elfcore_write_note (abfd
, buf
, bufsiz
,
1902 "CORE", note_type
, data
, sizeof (data
));
1913 va_start (ap
, note_type
);
1914 memset (data
, 0, 112);
1915 pid
= va_arg (ap
, long);
1916 bfd_put_32 (abfd
, pid
, data
+ 32);
1917 cursig
= va_arg (ap
, int);
1918 bfd_put_16 (abfd
, cursig
, data
+ 12);
1919 greg
= va_arg (ap
, const void *);
1920 memcpy (data
+ 112, greg
, 384);
1921 memset (data
+ 496, 0, 8);
1923 return elfcore_write_note (abfd
, buf
, bufsiz
,
1924 "CORE", note_type
, data
, sizeof (data
));
1929 /* Add extra PPC sections. */
1931 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1933 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1934 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1935 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1936 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1937 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1938 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1939 { NULL
, 0, 0, 0, 0 }
1942 enum _ppc64_sec_type
{
1948 struct _ppc64_elf_section_data
1950 struct bfd_elf_section_data elf
;
1954 /* An array with one entry for each opd function descriptor,
1955 and some spares since opd entries may be either 16 or 24 bytes. */
1956 #define OPD_NDX(OFF) ((OFF) >> 4)
1957 struct _opd_sec_data
1959 /* Points to the function code section for local opd entries. */
1960 asection
**func_sec
;
1962 /* After editing .opd, adjust references to opd local syms. */
1966 /* An array for toc sections, indexed by offset/8. */
1967 struct _toc_sec_data
1969 /* Specifies the relocation symbol index used at a given toc offset. */
1972 /* And the relocation addend. */
1977 enum _ppc64_sec_type sec_type
:2;
1979 /* Flag set when small branches are detected. Used to
1980 select suitable defaults for the stub group size. */
1981 unsigned int has_14bit_branch
:1;
1983 /* Flag set when PLTCALL relocs are detected. */
1984 unsigned int has_pltcall
:1;
1986 /* Flag set when section has PLT/GOT/TOC relocations that can be
1988 unsigned int has_optrel
:1;
1991 #define ppc64_elf_section_data(sec) \
1992 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
1995 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1997 if (!sec
->used_by_bfd
)
1999 struct _ppc64_elf_section_data
*sdata
;
2000 bfd_size_type amt
= sizeof (*sdata
);
2002 sdata
= bfd_zalloc (abfd
, amt
);
2005 sec
->used_by_bfd
= sdata
;
2008 return _bfd_elf_new_section_hook (abfd
, sec
);
2011 static struct _opd_sec_data
*
2012 get_opd_info (asection
* sec
)
2015 && ppc64_elf_section_data (sec
) != NULL
2016 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2017 return &ppc64_elf_section_data (sec
)->u
.opd
;
2021 /* Parameters for the qsort hook. */
2022 static bfd_boolean synthetic_relocatable
;
2023 static asection
*synthetic_opd
;
2025 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2028 compare_symbols (const void *ap
, const void *bp
)
2030 const asymbol
*a
= *(const asymbol
**) ap
;
2031 const asymbol
*b
= *(const asymbol
**) bp
;
2033 /* Section symbols first. */
2034 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2036 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2039 /* then .opd symbols. */
2040 if (synthetic_opd
!= NULL
)
2042 if (strcmp (a
->section
->name
, ".opd") == 0
2043 && strcmp (b
->section
->name
, ".opd") != 0)
2045 if (strcmp (a
->section
->name
, ".opd") != 0
2046 && strcmp (b
->section
->name
, ".opd") == 0)
2050 /* then other code symbols. */
2051 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2052 == (SEC_CODE
| SEC_ALLOC
))
2053 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2054 != (SEC_CODE
| SEC_ALLOC
)))
2057 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2058 != (SEC_CODE
| SEC_ALLOC
))
2059 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2060 == (SEC_CODE
| SEC_ALLOC
)))
2063 if (synthetic_relocatable
)
2065 if (a
->section
->id
< b
->section
->id
)
2068 if (a
->section
->id
> b
->section
->id
)
2072 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2075 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2078 /* For syms with the same value, prefer strong dynamic global function
2079 syms over other syms. */
2080 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2083 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2086 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2089 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2092 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2095 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2098 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2101 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2107 /* Search SYMS for a symbol of the given VALUE. */
2110 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
2114 if (id
== (unsigned) -1)
2118 mid
= (lo
+ hi
) >> 1;
2119 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2121 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2131 mid
= (lo
+ hi
) >> 1;
2132 if (syms
[mid
]->section
->id
< id
)
2134 else if (syms
[mid
]->section
->id
> id
)
2136 else if (syms
[mid
]->value
< value
)
2138 else if (syms
[mid
]->value
> value
)
2148 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
2150 bfd_vma vma
= *(bfd_vma
*) ptr
;
2151 return ((section
->flags
& SEC_ALLOC
) != 0
2152 && section
->vma
<= vma
2153 && vma
< section
->vma
+ section
->size
);
2156 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2157 entry syms. Also generate @plt symbols for the glink branch table.
2158 Returns count of synthetic symbols in RET or -1 on error. */
2161 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2162 long static_count
, asymbol
**static_syms
,
2163 long dyn_count
, asymbol
**dyn_syms
,
2169 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2170 asection
*opd
= NULL
;
2171 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2173 int abi
= abiversion (abfd
);
2179 opd
= bfd_get_section_by_name (abfd
, ".opd");
2180 if (opd
== NULL
&& abi
== 1)
2192 symcount
= static_count
;
2194 symcount
+= dyn_count
;
2198 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2202 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2204 /* Use both symbol tables. */
2205 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2206 memcpy (syms
+ static_count
, dyn_syms
,
2207 (dyn_count
+ 1) * sizeof (*syms
));
2209 else if (!relocatable
&& static_count
== 0)
2210 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2212 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2214 /* Trim uninteresting symbols. Interesting symbols are section,
2215 function, and notype symbols. */
2216 for (i
= 0, j
= 0; i
< symcount
; ++i
)
2217 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
2218 | BSF_RELC
| BSF_SRELC
)) == 0)
2219 syms
[j
++] = syms
[i
];
2222 synthetic_relocatable
= relocatable
;
2223 synthetic_opd
= opd
;
2224 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2226 if (!relocatable
&& symcount
> 1)
2228 /* Trim duplicate syms, since we may have merged the normal
2229 and dynamic symbols. Actually, we only care about syms
2230 that have different values, so trim any with the same
2231 value. Don't consider ifunc and ifunc resolver symbols
2232 duplicates however, because GDB wants to know whether a
2233 text symbol is an ifunc resolver. */
2234 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2236 const asymbol
*s0
= syms
[i
- 1];
2237 const asymbol
*s1
= syms
[i
];
2239 if ((s0
->value
+ s0
->section
->vma
2240 != s1
->value
+ s1
->section
->vma
)
2241 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2242 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2243 syms
[j
++] = syms
[i
];
2249 /* Note that here and in compare_symbols we can't compare opd and
2250 sym->section directly. With separate debug info files, the
2251 symbols will be extracted from the debug file while abfd passed
2252 to this function is the real binary. */
2253 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2257 for (; i
< symcount
; ++i
)
2258 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2259 | SEC_THREAD_LOCAL
))
2260 != (SEC_CODE
| SEC_ALLOC
))
2261 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2265 for (; i
< symcount
; ++i
)
2266 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2270 for (; i
< symcount
; ++i
)
2271 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2275 for (; i
< symcount
; ++i
)
2276 if (((syms
[i
]->section
->flags
2277 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2278 != (SEC_CODE
| SEC_ALLOC
))
2286 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2291 if (opdsymend
== secsymend
)
2294 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2295 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2299 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2306 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2310 while (r
< opd
->relocation
+ relcount
2311 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2314 if (r
== opd
->relocation
+ relcount
)
2317 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2320 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2323 sym
= *r
->sym_ptr_ptr
;
2324 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2325 sym
->section
->id
, sym
->value
+ r
->addend
))
2328 size
+= sizeof (asymbol
);
2329 size
+= strlen (syms
[i
]->name
) + 2;
2335 s
= *ret
= bfd_malloc (size
);
2342 names
= (char *) (s
+ count
);
2344 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2348 while (r
< opd
->relocation
+ relcount
2349 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2352 if (r
== opd
->relocation
+ relcount
)
2355 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2358 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2361 sym
= *r
->sym_ptr_ptr
;
2362 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2363 sym
->section
->id
, sym
->value
+ r
->addend
))
2368 s
->flags
|= BSF_SYNTHETIC
;
2369 s
->section
= sym
->section
;
2370 s
->value
= sym
->value
+ r
->addend
;
2373 len
= strlen (syms
[i
]->name
);
2374 memcpy (names
, syms
[i
]->name
, len
+ 1);
2376 /* Have udata.p point back to the original symbol this
2377 synthetic symbol was derived from. */
2378 s
->udata
.p
= syms
[i
];
2385 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2386 bfd_byte
*contents
= NULL
;
2388 size_t plt_count
= 0;
2389 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2390 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2393 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2395 free_contents_and_exit_err
:
2397 free_contents_and_exit
:
2404 for (i
= secsymend
; i
< opdsymend
; ++i
)
2408 /* Ignore bogus symbols. */
2409 if (syms
[i
]->value
> opd
->size
- 8)
2412 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2413 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2416 size
+= sizeof (asymbol
);
2417 size
+= strlen (syms
[i
]->name
) + 2;
2421 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2423 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2425 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2427 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2429 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2430 goto free_contents_and_exit_err
;
2432 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2433 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2436 extdynend
= extdyn
+ dynamic
->size
;
2437 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2439 Elf_Internal_Dyn dyn
;
2440 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2442 if (dyn
.d_tag
== DT_NULL
)
2445 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2447 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2448 See comment in ppc64_elf_finish_dynamic_sections. */
2449 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2450 /* The .glink section usually does not survive the final
2451 link; search for the section (usually .text) where the
2452 glink stubs now reside. */
2453 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2464 /* Determine __glink trampoline by reading the relative branch
2465 from the first glink stub. */
2467 unsigned int off
= 0;
2469 while (bfd_get_section_contents (abfd
, glink
, buf
,
2470 glink_vma
+ off
- glink
->vma
, 4))
2472 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2474 if ((insn
& ~0x3fffffc) == 0)
2477 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2486 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2488 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2491 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2492 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
2493 goto free_contents_and_exit_err
;
2495 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
2496 size
+= plt_count
* sizeof (asymbol
);
2498 p
= relplt
->relocation
;
2499 for (i
= 0; i
< plt_count
; i
++, p
++)
2501 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2503 size
+= sizeof ("+0x") - 1 + 16;
2509 goto free_contents_and_exit
;
2510 s
= *ret
= bfd_malloc (size
);
2512 goto free_contents_and_exit_err
;
2514 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2516 for (i
= secsymend
; i
< opdsymend
; ++i
)
2520 if (syms
[i
]->value
> opd
->size
- 8)
2523 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2524 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2528 asection
*sec
= abfd
->sections
;
2535 size_t mid
= (lo
+ hi
) >> 1;
2536 if (syms
[mid
]->section
->vma
< ent
)
2538 else if (syms
[mid
]->section
->vma
> ent
)
2542 sec
= syms
[mid
]->section
;
2547 if (lo
>= hi
&& lo
> codesecsym
)
2548 sec
= syms
[lo
- 1]->section
;
2550 for (; sec
!= NULL
; sec
= sec
->next
)
2554 /* SEC_LOAD may not be set if SEC is from a separate debug
2556 if ((sec
->flags
& SEC_ALLOC
) == 0)
2558 if ((sec
->flags
& SEC_CODE
) != 0)
2561 s
->flags
|= BSF_SYNTHETIC
;
2562 s
->value
= ent
- s
->section
->vma
;
2565 len
= strlen (syms
[i
]->name
);
2566 memcpy (names
, syms
[i
]->name
, len
+ 1);
2568 /* Have udata.p point back to the original symbol this
2569 synthetic symbol was derived from. */
2570 s
->udata
.p
= syms
[i
];
2576 if (glink
!= NULL
&& relplt
!= NULL
)
2580 /* Add a symbol for the main glink trampoline. */
2581 memset (s
, 0, sizeof *s
);
2583 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2585 s
->value
= resolv_vma
- glink
->vma
;
2587 memcpy (names
, "__glink_PLTresolve",
2588 sizeof ("__glink_PLTresolve"));
2589 names
+= sizeof ("__glink_PLTresolve");
2594 /* FIXME: It would be very much nicer to put sym@plt on the
2595 stub rather than on the glink branch table entry. The
2596 objdump disassembler would then use a sensible symbol
2597 name on plt calls. The difficulty in doing so is
2598 a) finding the stubs, and,
2599 b) matching stubs against plt entries, and,
2600 c) there can be multiple stubs for a given plt entry.
2602 Solving (a) could be done by code scanning, but older
2603 ppc64 binaries used different stubs to current code.
2604 (b) is the tricky one since you need to known the toc
2605 pointer for at least one function that uses a pic stub to
2606 be able to calculate the plt address referenced.
2607 (c) means gdb would need to set multiple breakpoints (or
2608 find the glink branch itself) when setting breakpoints
2609 for pending shared library loads. */
2610 p
= relplt
->relocation
;
2611 for (i
= 0; i
< plt_count
; i
++, p
++)
2615 *s
= **p
->sym_ptr_ptr
;
2616 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2617 we are defining a symbol, ensure one of them is set. */
2618 if ((s
->flags
& BSF_LOCAL
) == 0)
2619 s
->flags
|= BSF_GLOBAL
;
2620 s
->flags
|= BSF_SYNTHETIC
;
2622 s
->value
= glink_vma
- glink
->vma
;
2625 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2626 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2630 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2631 names
+= sizeof ("+0x") - 1;
2632 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2633 names
+= strlen (names
);
2635 memcpy (names
, "@plt", sizeof ("@plt"));
2636 names
+= sizeof ("@plt");
2656 /* The following functions are specific to the ELF linker, while
2657 functions above are used generally. Those named ppc64_elf_* are
2658 called by the main ELF linker code. They appear in this file more
2659 or less in the order in which they are called. eg.
2660 ppc64_elf_check_relocs is called early in the link process,
2661 ppc64_elf_finish_dynamic_sections is one of the last functions
2664 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2665 functions have both a function code symbol and a function descriptor
2666 symbol. A call to foo in a relocatable object file looks like:
2673 The function definition in another object file might be:
2677 . .quad .TOC.@tocbase
2683 When the linker resolves the call during a static link, the branch
2684 unsurprisingly just goes to .foo and the .opd information is unused.
2685 If the function definition is in a shared library, things are a little
2686 different: The call goes via a plt call stub, the opd information gets
2687 copied to the plt, and the linker patches the nop.
2695 . std 2,40(1) # in practice, the call stub
2696 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2697 . addi 11,11,Lfoo@toc@l # this is the general idea
2705 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2707 The "reloc ()" notation is supposed to indicate that the linker emits
2708 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2711 What are the difficulties here? Well, firstly, the relocations
2712 examined by the linker in check_relocs are against the function code
2713 sym .foo, while the dynamic relocation in the plt is emitted against
2714 the function descriptor symbol, foo. Somewhere along the line, we need
2715 to carefully copy dynamic link information from one symbol to the other.
2716 Secondly, the generic part of the elf linker will make .foo a dynamic
2717 symbol as is normal for most other backends. We need foo dynamic
2718 instead, at least for an application final link. However, when
2719 creating a shared library containing foo, we need to have both symbols
2720 dynamic so that references to .foo are satisfied during the early
2721 stages of linking. Otherwise the linker might decide to pull in a
2722 definition from some other object, eg. a static library.
2724 Update: As of August 2004, we support a new convention. Function
2725 calls may use the function descriptor symbol, ie. "bl foo". This
2726 behaves exactly as "bl .foo". */
2728 /* Of those relocs that might be copied as dynamic relocs, this
2729 function selects those that must be copied when linking a shared
2730 library or PIE, even when the symbol is local. */
2733 must_be_dyn_reloc (struct bfd_link_info
*info
,
2734 enum elf_ppc64_reloc_type r_type
)
2739 /* Only relative relocs can be resolved when the object load
2740 address isn't fixed. DTPREL64 is excluded because the
2741 dynamic linker needs to differentiate global dynamic from
2742 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2749 case R_PPC64_TOC16_DS
:
2750 case R_PPC64_TOC16_LO
:
2751 case R_PPC64_TOC16_HI
:
2752 case R_PPC64_TOC16_HA
:
2753 case R_PPC64_TOC16_LO_DS
:
2756 case R_PPC64_TPREL16
:
2757 case R_PPC64_TPREL16_LO
:
2758 case R_PPC64_TPREL16_HI
:
2759 case R_PPC64_TPREL16_HA
:
2760 case R_PPC64_TPREL16_DS
:
2761 case R_PPC64_TPREL16_LO_DS
:
2762 case R_PPC64_TPREL16_HIGH
:
2763 case R_PPC64_TPREL16_HIGHA
:
2764 case R_PPC64_TPREL16_HIGHER
:
2765 case R_PPC64_TPREL16_HIGHERA
:
2766 case R_PPC64_TPREL16_HIGHEST
:
2767 case R_PPC64_TPREL16_HIGHESTA
:
2768 case R_PPC64_TPREL64
:
2769 case R_PPC64_TPREL34
:
2770 /* These relocations are relative but in a shared library the
2771 linker doesn't know the thread pointer base. */
2772 return bfd_link_dll (info
);
2776 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2777 copying dynamic variables from a shared lib into an app's dynbss
2778 section, and instead use a dynamic relocation to point into the
2779 shared lib. With code that gcc generates, it's vital that this be
2780 enabled; In the PowerPC64 ABI, the address of a function is actually
2781 the address of a function descriptor, which resides in the .opd
2782 section. gcc uses the descriptor directly rather than going via the
2783 GOT as some other ABI's do, which means that initialized function
2784 pointers must reference the descriptor. Thus, a function pointer
2785 initialized to the address of a function in a shared library will
2786 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2787 redefines the function descriptor symbol to point to the copy. This
2788 presents a problem as a plt entry for that function is also
2789 initialized from the function descriptor symbol and the copy reloc
2790 may not be initialized first. */
2791 #define ELIMINATE_COPY_RELOCS 1
2793 /* Section name for stubs is the associated section name plus this
2795 #define STUB_SUFFIX ".stub"
2798 ppc_stub_long_branch:
2799 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2800 destination, but a 24 bit branch in a stub section will reach.
2803 ppc_stub_plt_branch:
2804 Similar to the above, but a 24 bit branch in the stub section won't
2805 reach its destination.
2806 . addis %r11,%r2,xxx@toc@ha
2807 . ld %r12,xxx@toc@l(%r11)
2812 Used to call a function in a shared library. If it so happens that
2813 the plt entry referenced crosses a 64k boundary, then an extra
2814 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2815 ppc_stub_plt_call_r2save starts with "std %r2,40(%r1)".
2816 . addis %r11,%r2,xxx@toc@ha
2817 . ld %r12,xxx+0@toc@l(%r11)
2819 . ld %r2,xxx+8@toc@l(%r11)
2820 . ld %r11,xxx+16@toc@l(%r11)
2823 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2824 code to adjust the value and save r2 to support multiple toc sections.
2825 A ppc_stub_long_branch with an r2 offset looks like:
2827 . addis %r2,%r2,off@ha
2828 . addi %r2,%r2,off@l
2831 A ppc_stub_plt_branch with an r2 offset looks like:
2833 . addis %r11,%r2,xxx@toc@ha
2834 . ld %r12,xxx@toc@l(%r11)
2835 . addis %r2,%r2,off@ha
2836 . addi %r2,%r2,off@l
2840 All of the above stubs are shown as their ELFv1 variants. ELFv2
2841 variants exist too, simpler for plt calls since a new toc pointer
2842 and static chain are not loaded by the stub. In addition, ELFv2
2843 has some more complex stubs to handle calls marked with NOTOC
2844 relocs from functions where r2 is not a valid toc pointer. These
2845 come in two flavours, the ones shown below, and _both variants that
2846 start with "std %r2,24(%r1)" to save r2 in the unlikely event that
2847 one call is from a function where r2 is used as the toc pointer but
2848 needs a toc adjusting stub for small-model multi-toc, and another
2849 call is from a function where r2 is not valid.
2850 ppc_stub_long_branch_notoc:
2856 . addis %r12,%r11,dest-1b@ha
2857 . addi %r12,%r12,dest-1b@l
2860 ppc_stub_plt_branch_notoc:
2866 . lis %r12,xxx-1b@highest
2867 . ori %r12,%r12,xxx-1b@higher
2869 . oris %r12,%r12,xxx-1b@high
2870 . ori %r12,%r12,xxx-1b@l
2871 . add %r12,%r11,%r12
2875 ppc_stub_plt_call_notoc:
2881 . lis %r12,xxx-1b@highest
2882 . ori %r12,%r12,xxx-1b@higher
2884 . oris %r12,%r12,xxx-1b@high
2885 . ori %r12,%r12,xxx-1b@l
2886 . ldx %r12,%r11,%r12
2890 There are also ELFv1 powerxx variants of these stubs.
2891 ppc_stub_long_branch_notoc:
2892 . pla %r12,dest@pcrel
2894 ppc_stub_plt_branch_notoc:
2895 . lis %r11,(dest-1f)@highesta34
2896 . ori %r11,%r11,(dest-1f)@highera34
2898 . 1: pla %r12,dest@pcrel
2899 . add %r12,%r11,%r12
2902 ppc_stub_plt_call_notoc:
2903 . lis %r11,(xxx-1f)@highesta34
2904 . ori %r11,%r11,(xxx-1f)@highera34
2906 . 1: pla %r12,xxx@pcrel
2907 . ldx %r12,%r11,%r12
2911 In cases where the high instructions would add zero, they are
2912 omitted and following instructions modified in some cases.
2913 For example, a powerxx ppc_stub_plt_call_notoc might simplify down
2915 . pld %r12,xxx@pcrel
2919 For a given stub group (a set of sections all using the same toc
2920 pointer value) there will be just one stub type used for any
2921 particular function symbol. For example, if printf is called from
2922 code with the tocsave optimization (ie. r2 saved in function
2923 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2924 and from other code without the tocsave optimization requiring a
2925 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
2926 type will be created. Calls with the tocsave optimization will
2927 enter this stub after the instruction saving r2. A similar
2928 situation exists when calls are marked with R_PPC64_REL24_NOTOC
2929 relocations. These require a ppc_stub_plt_call_notoc linkage stub
2930 to call an external function like printf. If other calls to printf
2931 require a ppc_stub_plt_call linkage stub then a single
2932 ppc_stub_plt_call_notoc linkage stub will be used for both types of
2933 call. If other calls to printf require a ppc_stub_plt_call_r2save
2934 linkage stub then a single ppc_stub_plt_call_both linkage stub will
2935 be created and calls not requiring r2 to be saved will enter the
2936 stub after the r2 save instruction. There is an analogous
2937 hierarchy of long branch and plt branch stubs for local call
2943 ppc_stub_long_branch
,
2944 ppc_stub_long_branch_r2off
,
2945 ppc_stub_long_branch_notoc
,
2946 ppc_stub_long_branch_both
, /* r2off and notoc variants both needed. */
2947 ppc_stub_plt_branch
,
2948 ppc_stub_plt_branch_r2off
,
2949 ppc_stub_plt_branch_notoc
,
2950 ppc_stub_plt_branch_both
,
2952 ppc_stub_plt_call_r2save
,
2953 ppc_stub_plt_call_notoc
,
2954 ppc_stub_plt_call_both
,
2955 ppc_stub_global_entry
,
2959 /* Information on stub grouping. */
2962 /* The stub section. */
2964 /* This is the section to which stubs in the group will be attached. */
2967 struct map_stub
*next
;
2968 /* Whether to emit a copy of register save/restore functions in this
2971 /* Current offset within stubs after the insn restoring lr in a
2972 _notoc or _both stub using bcl for pc-relative addressing, or
2973 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
2974 unsigned int lr_restore
;
2975 /* Accumulated size of EH info emitted to describe return address
2976 if stubs modify lr. Does not include 17 byte FDE header. */
2977 unsigned int eh_size
;
2978 /* Offset in glink_eh_frame to the start of EH info for this group. */
2979 unsigned int eh_base
;
2982 struct ppc_stub_hash_entry
2984 /* Base hash table entry structure. */
2985 struct bfd_hash_entry root
;
2987 enum ppc_stub_type stub_type
;
2989 /* Group information. */
2990 struct map_stub
*group
;
2992 /* Offset within stub_sec of the beginning of this stub. */
2993 bfd_vma stub_offset
;
2995 /* Given the symbol's value and its section we can determine its final
2996 value when building the stubs (so the stub knows where to jump. */
2997 bfd_vma target_value
;
2998 asection
*target_section
;
3000 /* The symbol table entry, if any, that this was derived from. */
3001 struct ppc_link_hash_entry
*h
;
3002 struct plt_entry
*plt_ent
;
3005 unsigned char symtype
;
3007 /* Symbol st_other. */
3008 unsigned char other
;
3011 struct ppc_branch_hash_entry
3013 /* Base hash table entry structure. */
3014 struct bfd_hash_entry root
;
3016 /* Offset within branch lookup table. */
3017 unsigned int offset
;
3019 /* Generation marker. */
3023 /* Used to track dynamic relocations for local symbols. */
3024 struct ppc_dyn_relocs
3026 struct ppc_dyn_relocs
*next
;
3028 /* The input section of the reloc. */
3031 /* Total number of relocs copied for the input section. */
3032 unsigned int count
: 31;
3034 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3035 unsigned int ifunc
: 1;
3038 struct ppc_link_hash_entry
3040 struct elf_link_hash_entry elf
;
3044 /* A pointer to the most recently used stub hash entry against this
3046 struct ppc_stub_hash_entry
*stub_cache
;
3048 /* A pointer to the next symbol starting with a '.' */
3049 struct ppc_link_hash_entry
*next_dot_sym
;
3052 /* Track dynamic relocs copied for this symbol. */
3053 struct elf_dyn_relocs
*dyn_relocs
;
3055 /* Link between function code and descriptor symbols. */
3056 struct ppc_link_hash_entry
*oh
;
3058 /* Flag function code and descriptor symbols. */
3059 unsigned int is_func
:1;
3060 unsigned int is_func_descriptor
:1;
3061 unsigned int fake
:1;
3063 /* Whether global opd/toc sym has been adjusted or not.
3064 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3065 should be set for all globals defined in any opd/toc section. */
3066 unsigned int adjust_done
:1;
3068 /* Set if this is an out-of-line register save/restore function,
3069 with non-standard calling convention. */
3070 unsigned int save_res
:1;
3072 /* Set if a duplicate symbol with non-zero localentry is detected,
3073 even when the duplicate symbol does not provide a definition. */
3074 unsigned int non_zero_localentry
:1;
3076 /* Contexts in which symbol is used in the GOT (or TOC).
3077 Bits are or'd into the mask as the corresponding relocs are
3078 encountered during check_relocs, with TLS_TLS being set when any
3079 of the other TLS bits are set. tls_optimize clears bits when
3080 optimizing to indicate the corresponding GOT entry type is not
3081 needed. If set, TLS_TLS is never cleared. tls_optimize may also
3082 set TLS_GDIE when a GD reloc turns into an IE one.
3083 These flags are also kept for local symbols. */
3084 #define TLS_TLS 1 /* Any TLS reloc. */
3085 #define TLS_GD 2 /* GD reloc. */
3086 #define TLS_LD 4 /* LD reloc. */
3087 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
3088 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
3089 #define TLS_MARK 32 /* __tls_get_addr call marked. */
3090 #define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
3091 #define TLS_EXPLICIT 256 /* TOC section TLS reloc, not stored. */
3092 unsigned char tls_mask
;
3094 /* The above field is also used to mark function symbols. In which
3095 case TLS_TLS will be 0. */
3096 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
3097 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
3098 #define NON_GOT 256 /* local symbol plt, not stored. */
3101 /* ppc64 ELF linker hash table. */
3103 struct ppc_link_hash_table
3105 struct elf_link_hash_table elf
;
3107 /* The stub hash table. */
3108 struct bfd_hash_table stub_hash_table
;
3110 /* Another hash table for plt_branch stubs. */
3111 struct bfd_hash_table branch_hash_table
;
3113 /* Hash table for function prologue tocsave. */
3114 htab_t tocsave_htab
;
3116 /* Various options and other info passed from the linker. */
3117 struct ppc64_elf_params
*params
;
3119 /* The size of sec_info below. */
3120 unsigned int sec_info_arr_size
;
3122 /* Per-section array of extra section info. Done this way rather
3123 than as part of ppc64_elf_section_data so we have the info for
3124 non-ppc64 sections. */
3127 /* Along with elf_gp, specifies the TOC pointer used by this section. */
3132 /* The section group that this section belongs to. */
3133 struct map_stub
*group
;
3134 /* A temp section list pointer. */
3139 /* Linked list of groups. */
3140 struct map_stub
*group
;
3142 /* Temp used when calculating TOC pointers. */
3145 asection
*toc_first_sec
;
3147 /* Used when adding symbols. */
3148 struct ppc_link_hash_entry
*dot_syms
;
3150 /* Shortcuts to get to dynamic linker sections. */
3152 asection
*global_entry
;
3155 asection
*relpltlocal
;
3158 asection
*glink_eh_frame
;
3160 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3161 struct ppc_link_hash_entry
*tls_get_addr
;
3162 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3164 /* The size of reliplt used by got entry relocs. */
3165 bfd_size_type got_reli_size
;
3168 unsigned long stub_count
[ppc_stub_global_entry
];
3170 /* Number of stubs against global syms. */
3171 unsigned long stub_globals
;
3173 /* Set if we're linking code with function descriptors. */
3174 unsigned int opd_abi
:1;
3176 /* Support for multiple toc sections. */
3177 unsigned int do_multi_toc
:1;
3178 unsigned int multi_toc_needed
:1;
3179 unsigned int second_toc_pass
:1;
3180 unsigned int do_toc_opt
:1;
3182 /* Set if tls optimization is enabled. */
3183 unsigned int do_tls_opt
:1;
3185 /* Set if inline plt calls should be converted to direct calls. */
3186 unsigned int can_convert_all_inline_plt
:1;
3189 unsigned int stub_error
:1;
3191 /* Whether func_desc_adjust needs to be run over symbols. */
3192 unsigned int need_func_desc_adj
:1;
3194 /* Whether there exist local gnu indirect function resolvers,
3195 referenced by dynamic relocations. */
3196 unsigned int local_ifunc_resolver
:1;
3197 unsigned int maybe_local_ifunc_resolver
:1;
3199 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
3200 unsigned int has_plt_localentry0
:1;
3202 /* Whether calls are made via the PLT from NOTOC functions. */
3203 unsigned int notoc_plt
:1;
3205 /* Whether to use powerxx instructions in linkage stubs. */
3206 unsigned int powerxx_stubs
:1;
3208 /* Incremented every time we size stubs. */
3209 unsigned int stub_iteration
;
3211 /* Small local sym cache. */
3212 struct sym_cache sym_cache
;
3215 /* Rename some of the generic section flags to better document how they
3218 /* Nonzero if this section has TLS related relocations. */
3219 #define has_tls_reloc sec_flg0
3221 /* Nonzero if this section has a call to __tls_get_addr lacking marker
3223 #define nomark_tls_get_addr sec_flg1
3225 /* Nonzero if this section has any toc or got relocs. */
3226 #define has_toc_reloc sec_flg2
3228 /* Nonzero if this section has a call to another section that uses
3230 #define makes_toc_func_call sec_flg3
3232 /* Recursion protection when determining above flag. */
3233 #define call_check_in_progress sec_flg4
3234 #define call_check_done sec_flg5
3236 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3238 #define ppc_hash_table(p) \
3239 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3240 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3242 #define ppc_stub_hash_lookup(table, string, create, copy) \
3243 ((struct ppc_stub_hash_entry *) \
3244 bfd_hash_lookup ((table), (string), (create), (copy)))
3246 #define ppc_branch_hash_lookup(table, string, create, copy) \
3247 ((struct ppc_branch_hash_entry *) \
3248 bfd_hash_lookup ((table), (string), (create), (copy)))
3250 /* Create an entry in the stub hash table. */
3252 static struct bfd_hash_entry
*
3253 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3254 struct bfd_hash_table
*table
,
3257 /* Allocate the structure if it has not already been allocated by a
3261 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3266 /* Call the allocation method of the superclass. */
3267 entry
= bfd_hash_newfunc (entry
, table
, string
);
3270 struct ppc_stub_hash_entry
*eh
;
3272 /* Initialize the local fields. */
3273 eh
= (struct ppc_stub_hash_entry
*) entry
;
3274 eh
->stub_type
= ppc_stub_none
;
3276 eh
->stub_offset
= 0;
3277 eh
->target_value
= 0;
3278 eh
->target_section
= NULL
;
3287 /* Create an entry in the branch hash table. */
3289 static struct bfd_hash_entry
*
3290 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3291 struct bfd_hash_table
*table
,
3294 /* Allocate the structure if it has not already been allocated by a
3298 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3303 /* Call the allocation method of the superclass. */
3304 entry
= bfd_hash_newfunc (entry
, table
, string
);
3307 struct ppc_branch_hash_entry
*eh
;
3309 /* Initialize the local fields. */
3310 eh
= (struct ppc_branch_hash_entry
*) entry
;
3318 /* Create an entry in a ppc64 ELF linker hash table. */
3320 static struct bfd_hash_entry
*
3321 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3322 struct bfd_hash_table
*table
,
3325 /* Allocate the structure if it has not already been allocated by a
3329 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3334 /* Call the allocation method of the superclass. */
3335 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3338 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3340 memset (&eh
->u
.stub_cache
, 0,
3341 (sizeof (struct ppc_link_hash_entry
)
3342 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3344 /* When making function calls, old ABI code references function entry
3345 points (dot symbols), while new ABI code references the function
3346 descriptor symbol. We need to make any combination of reference and
3347 definition work together, without breaking archive linking.
3349 For a defined function "foo" and an undefined call to "bar":
3350 An old object defines "foo" and ".foo", references ".bar" (possibly
3352 A new object defines "foo" and references "bar".
3354 A new object thus has no problem with its undefined symbols being
3355 satisfied by definitions in an old object. On the other hand, the
3356 old object won't have ".bar" satisfied by a new object.
3358 Keep a list of newly added dot-symbols. */
3360 if (string
[0] == '.')
3362 struct ppc_link_hash_table
*htab
;
3364 htab
= (struct ppc_link_hash_table
*) table
;
3365 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3366 htab
->dot_syms
= eh
;
3373 struct tocsave_entry
3380 tocsave_htab_hash (const void *p
)
3382 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3383 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3387 tocsave_htab_eq (const void *p1
, const void *p2
)
3389 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3390 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3391 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3394 /* Destroy a ppc64 ELF linker hash table. */
3397 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3399 struct ppc_link_hash_table
*htab
;
3401 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3402 if (htab
->tocsave_htab
)
3403 htab_delete (htab
->tocsave_htab
);
3404 bfd_hash_table_free (&htab
->branch_hash_table
);
3405 bfd_hash_table_free (&htab
->stub_hash_table
);
3406 _bfd_elf_link_hash_table_free (obfd
);
3409 /* Create a ppc64 ELF linker hash table. */
3411 static struct bfd_link_hash_table
*
3412 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3414 struct ppc_link_hash_table
*htab
;
3415 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3417 htab
= bfd_zmalloc (amt
);
3421 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3422 sizeof (struct ppc_link_hash_entry
),
3429 /* Init the stub hash table too. */
3430 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3431 sizeof (struct ppc_stub_hash_entry
)))
3433 _bfd_elf_link_hash_table_free (abfd
);
3437 /* And the branch hash table. */
3438 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3439 sizeof (struct ppc_branch_hash_entry
)))
3441 bfd_hash_table_free (&htab
->stub_hash_table
);
3442 _bfd_elf_link_hash_table_free (abfd
);
3446 htab
->tocsave_htab
= htab_try_create (1024,
3450 if (htab
->tocsave_htab
== NULL
)
3452 ppc64_elf_link_hash_table_free (abfd
);
3455 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3457 /* Initializing two fields of the union is just cosmetic. We really
3458 only care about glist, but when compiled on a 32-bit host the
3459 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3460 debugger inspection of these fields look nicer. */
3461 htab
->elf
.init_got_refcount
.refcount
= 0;
3462 htab
->elf
.init_got_refcount
.glist
= NULL
;
3463 htab
->elf
.init_plt_refcount
.refcount
= 0;
3464 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3465 htab
->elf
.init_got_offset
.offset
= 0;
3466 htab
->elf
.init_got_offset
.glist
= NULL
;
3467 htab
->elf
.init_plt_offset
.offset
= 0;
3468 htab
->elf
.init_plt_offset
.glist
= NULL
;
3470 return &htab
->elf
.root
;
3473 /* Create sections for linker generated code. */
3476 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3478 struct ppc_link_hash_table
*htab
;
3481 htab
= ppc_hash_table (info
);
3483 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3484 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3485 if (htab
->params
->save_restore_funcs
)
3487 /* Create .sfpr for code to save and restore fp regs. */
3488 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3490 if (htab
->sfpr
== NULL
3491 || !bfd_set_section_alignment (htab
->sfpr
, 2))
3495 if (bfd_link_relocatable (info
))
3498 /* Create .glink for lazy dynamic linking support. */
3499 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3501 if (htab
->glink
== NULL
3502 || !bfd_set_section_alignment (htab
->glink
, 3))
3505 /* The part of .glink used by global entry stubs, separate so that
3506 it can be aligned appropriately without affecting htab->glink. */
3507 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3509 if (htab
->global_entry
== NULL
3510 || !bfd_set_section_alignment (htab
->global_entry
, 2))
3513 if (!info
->no_ld_generated_unwind_info
)
3515 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3516 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3517 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3520 if (htab
->glink_eh_frame
== NULL
3521 || !bfd_set_section_alignment (htab
->glink_eh_frame
, 2))
3525 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3526 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3527 if (htab
->elf
.iplt
== NULL
3528 || !bfd_set_section_alignment (htab
->elf
.iplt
, 3))
3531 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3532 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3534 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3535 if (htab
->elf
.irelplt
== NULL
3536 || !bfd_set_section_alignment (htab
->elf
.irelplt
, 3))
3539 /* Create branch lookup table for plt_branch stubs. */
3540 flags
= (SEC_ALLOC
| SEC_LOAD
3541 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3542 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3544 if (htab
->brlt
== NULL
3545 || !bfd_set_section_alignment (htab
->brlt
, 3))
3548 /* Local plt entries, put in .branch_lt but a separate section for
3550 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3552 if (htab
->pltlocal
== NULL
3553 || !bfd_set_section_alignment (htab
->pltlocal
, 3))
3556 if (!bfd_link_pic (info
))
3559 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3560 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3562 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3563 if (htab
->relbrlt
== NULL
3564 || !bfd_set_section_alignment (htab
->relbrlt
, 3))
3568 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3569 if (htab
->relpltlocal
== NULL
3570 || !bfd_set_section_alignment (htab
->relpltlocal
, 3))
3576 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3579 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3580 struct ppc64_elf_params
*params
)
3582 struct ppc_link_hash_table
*htab
;
3584 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3586 /* Always hook our dynamic sections into the first bfd, which is the
3587 linker created stub bfd. This ensures that the GOT header is at
3588 the start of the output TOC section. */
3589 htab
= ppc_hash_table (info
);
3590 htab
->elf
.dynobj
= params
->stub_bfd
;
3591 htab
->params
= params
;
3593 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3596 /* Build a name for an entry in the stub hash table. */
3599 ppc_stub_name (const asection
*input_section
,
3600 const asection
*sym_sec
,
3601 const struct ppc_link_hash_entry
*h
,
3602 const Elf_Internal_Rela
*rel
)
3607 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3608 offsets from a sym as a branch target? In fact, we could
3609 probably assume the addend is always zero. */
3610 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3614 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3615 stub_name
= bfd_malloc (len
);
3616 if (stub_name
== NULL
)
3619 len
= sprintf (stub_name
, "%08x.%s+%x",
3620 input_section
->id
& 0xffffffff,
3621 h
->elf
.root
.root
.string
,
3622 (int) rel
->r_addend
& 0xffffffff);
3626 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3627 stub_name
= bfd_malloc (len
);
3628 if (stub_name
== NULL
)
3631 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3632 input_section
->id
& 0xffffffff,
3633 sym_sec
->id
& 0xffffffff,
3634 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3635 (int) rel
->r_addend
& 0xffffffff);
3637 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3638 stub_name
[len
- 2] = 0;
3642 /* Look up an entry in the stub hash. Stub entries are cached because
3643 creating the stub name takes a bit of time. */
3645 static struct ppc_stub_hash_entry
*
3646 ppc_get_stub_entry (const asection
*input_section
,
3647 const asection
*sym_sec
,
3648 struct ppc_link_hash_entry
*h
,
3649 const Elf_Internal_Rela
*rel
,
3650 struct ppc_link_hash_table
*htab
)
3652 struct ppc_stub_hash_entry
*stub_entry
;
3653 struct map_stub
*group
;
3655 /* If this input section is part of a group of sections sharing one
3656 stub section, then use the id of the first section in the group.
3657 Stub names need to include a section id, as there may well be
3658 more than one stub used to reach say, printf, and we need to
3659 distinguish between them. */
3660 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3664 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3665 && h
->u
.stub_cache
->h
== h
3666 && h
->u
.stub_cache
->group
== group
)
3668 stub_entry
= h
->u
.stub_cache
;
3674 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3675 if (stub_name
== NULL
)
3678 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3679 stub_name
, FALSE
, FALSE
);
3681 h
->u
.stub_cache
= stub_entry
;
3689 /* Add a new stub entry to the stub hash. Not all fields of the new
3690 stub entry are initialised. */
3692 static struct ppc_stub_hash_entry
*
3693 ppc_add_stub (const char *stub_name
,
3695 struct bfd_link_info
*info
)
3697 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3698 struct map_stub
*group
;
3701 struct ppc_stub_hash_entry
*stub_entry
;
3703 group
= htab
->sec_info
[section
->id
].u
.group
;
3704 link_sec
= group
->link_sec
;
3705 stub_sec
= group
->stub_sec
;
3706 if (stub_sec
== NULL
)
3712 namelen
= strlen (link_sec
->name
);
3713 len
= namelen
+ sizeof (STUB_SUFFIX
);
3714 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3718 memcpy (s_name
, link_sec
->name
, namelen
);
3719 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3720 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3721 if (stub_sec
== NULL
)
3723 group
->stub_sec
= stub_sec
;
3726 /* Enter this entry into the linker stub hash table. */
3727 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3729 if (stub_entry
== NULL
)
3731 /* xgettext:c-format */
3732 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3733 section
->owner
, stub_name
);
3737 stub_entry
->group
= group
;
3738 stub_entry
->stub_offset
= 0;
3742 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3743 not already done. */
3746 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3748 asection
*got
, *relgot
;
3750 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3752 if (!is_ppc64_elf (abfd
))
3758 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3761 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3762 | SEC_LINKER_CREATED
);
3764 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3766 || !bfd_set_section_alignment (got
, 3))
3769 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3770 flags
| SEC_READONLY
);
3772 || !bfd_set_section_alignment (relgot
, 3))
3775 ppc64_elf_tdata (abfd
)->got
= got
;
3776 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3780 /* Follow indirect and warning symbol links. */
3782 static inline struct bfd_link_hash_entry
*
3783 follow_link (struct bfd_link_hash_entry
*h
)
3785 while (h
->type
== bfd_link_hash_indirect
3786 || h
->type
== bfd_link_hash_warning
)
3791 static inline struct elf_link_hash_entry
*
3792 elf_follow_link (struct elf_link_hash_entry
*h
)
3794 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
3797 static inline struct ppc_link_hash_entry
*
3798 ppc_follow_link (struct ppc_link_hash_entry
*h
)
3800 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
3803 /* Merge PLT info on FROM with that on TO. */
3806 move_plt_plist (struct ppc_link_hash_entry
*from
,
3807 struct ppc_link_hash_entry
*to
)
3809 if (from
->elf
.plt
.plist
!= NULL
)
3811 if (to
->elf
.plt
.plist
!= NULL
)
3813 struct plt_entry
**entp
;
3814 struct plt_entry
*ent
;
3816 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3818 struct plt_entry
*dent
;
3820 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3821 if (dent
->addend
== ent
->addend
)
3823 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3830 *entp
= to
->elf
.plt
.plist
;
3833 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3834 from
->elf
.plt
.plist
= NULL
;
3838 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3841 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3842 struct elf_link_hash_entry
*dir
,
3843 struct elf_link_hash_entry
*ind
)
3845 struct ppc_link_hash_entry
*edir
, *eind
;
3847 edir
= (struct ppc_link_hash_entry
*) dir
;
3848 eind
= (struct ppc_link_hash_entry
*) ind
;
3850 edir
->is_func
|= eind
->is_func
;
3851 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3852 edir
->tls_mask
|= eind
->tls_mask
;
3853 if (eind
->oh
!= NULL
)
3854 edir
->oh
= ppc_follow_link (eind
->oh
);
3856 if (edir
->elf
.versioned
!= versioned_hidden
)
3857 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3858 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3859 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3860 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3861 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3862 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3864 /* If we were called to copy over info for a weak sym, don't copy
3865 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
3866 in order to simplify readonly_dynrelocs and save a field in the
3867 symbol hash entry, but that means dyn_relocs can't be used in any
3868 tests about a specific symbol, or affect other symbol flags which
3870 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3873 /* Copy over any dynamic relocs we may have on the indirect sym. */
3874 if (eind
->dyn_relocs
!= NULL
)
3876 if (edir
->dyn_relocs
!= NULL
)
3878 struct elf_dyn_relocs
**pp
;
3879 struct elf_dyn_relocs
*p
;
3881 /* Add reloc counts against the indirect sym to the direct sym
3882 list. Merge any entries against the same section. */
3883 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3885 struct elf_dyn_relocs
*q
;
3887 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3888 if (q
->sec
== p
->sec
)
3890 q
->pc_count
+= p
->pc_count
;
3891 q
->count
+= p
->count
;
3898 *pp
= edir
->dyn_relocs
;
3901 edir
->dyn_relocs
= eind
->dyn_relocs
;
3902 eind
->dyn_relocs
= NULL
;
3905 /* Copy over got entries that we may have already seen to the
3906 symbol which just became indirect. */
3907 if (eind
->elf
.got
.glist
!= NULL
)
3909 if (edir
->elf
.got
.glist
!= NULL
)
3911 struct got_entry
**entp
;
3912 struct got_entry
*ent
;
3914 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3916 struct got_entry
*dent
;
3918 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3919 if (dent
->addend
== ent
->addend
3920 && dent
->owner
== ent
->owner
3921 && dent
->tls_type
== ent
->tls_type
)
3923 dent
->got
.refcount
+= ent
->got
.refcount
;
3930 *entp
= edir
->elf
.got
.glist
;
3933 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3934 eind
->elf
.got
.glist
= NULL
;
3937 /* And plt entries. */
3938 move_plt_plist (eind
, edir
);
3940 if (eind
->elf
.dynindx
!= -1)
3942 if (edir
->elf
.dynindx
!= -1)
3943 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3944 edir
->elf
.dynstr_index
);
3945 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3946 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3947 eind
->elf
.dynindx
= -1;
3948 eind
->elf
.dynstr_index
= 0;
3952 /* Find the function descriptor hash entry from the given function code
3953 hash entry FH. Link the entries via their OH fields. */
3955 static struct ppc_link_hash_entry
*
3956 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
3958 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
3962 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
3964 fdh
= (struct ppc_link_hash_entry
*)
3965 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
3969 fdh
->is_func_descriptor
= 1;
3975 fdh
= ppc_follow_link (fdh
);
3976 fdh
->is_func_descriptor
= 1;
3981 /* Make a fake function descriptor sym for the undefined code sym FH. */
3983 static struct ppc_link_hash_entry
*
3984 make_fdh (struct bfd_link_info
*info
,
3985 struct ppc_link_hash_entry
*fh
)
3987 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
3988 struct bfd_link_hash_entry
*bh
= NULL
;
3989 struct ppc_link_hash_entry
*fdh
;
3990 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
3994 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
3995 fh
->elf
.root
.root
.string
+ 1,
3996 flags
, bfd_und_section_ptr
, 0,
3997 NULL
, FALSE
, FALSE
, &bh
))
4000 fdh
= (struct ppc_link_hash_entry
*) bh
;
4001 fdh
->elf
.non_elf
= 0;
4003 fdh
->is_func_descriptor
= 1;
4010 /* Fix function descriptor symbols defined in .opd sections to be
4014 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4015 struct bfd_link_info
*info
,
4016 Elf_Internal_Sym
*isym
,
4018 flagword
*flags ATTRIBUTE_UNUSED
,
4023 && strcmp ((*sec
)->name
, ".opd") == 0)
4027 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4028 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4029 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4031 /* If the symbol is a function defined in .opd, and the function
4032 code is in a discarded group, let it appear to be undefined. */
4033 if (!bfd_link_relocatable (info
)
4034 && (*sec
)->reloc_count
!= 0
4035 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4036 FALSE
) != (bfd_vma
) -1
4037 && discarded_section (code_sec
))
4039 *sec
= bfd_und_section_ptr
;
4040 isym
->st_shndx
= SHN_UNDEF
;
4043 else if (*sec
!= NULL
4044 && strcmp ((*sec
)->name
, ".toc") == 0
4045 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4047 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4049 htab
->params
->object_in_toc
= 1;
4052 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4054 if (abiversion (ibfd
) == 0)
4055 set_abiversion (ibfd
, 2);
4056 else if (abiversion (ibfd
) == 1)
4058 _bfd_error_handler (_("symbol '%s' has invalid st_other"
4059 " for ABI version 1"), *name
);
4060 bfd_set_error (bfd_error_bad_value
);
4068 /* Merge non-visibility st_other attributes: local entry point. */
4071 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
4072 const Elf_Internal_Sym
*isym
,
4073 bfd_boolean definition
,
4074 bfd_boolean dynamic
)
4076 if (definition
&& (!dynamic
|| !h
->def_regular
))
4077 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
4078 | ELF_ST_VISIBILITY (h
->other
));
4081 /* Hook called on merging a symbol. We use this to clear "fake" since
4082 we now have a real symbol. */
4085 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
4086 const Elf_Internal_Sym
*isym
,
4087 asection
**psec ATTRIBUTE_UNUSED
,
4088 bfd_boolean newdef ATTRIBUTE_UNUSED
,
4089 bfd_boolean olddef ATTRIBUTE_UNUSED
,
4090 bfd
*oldbfd ATTRIBUTE_UNUSED
,
4091 const asection
*oldsec ATTRIBUTE_UNUSED
)
4093 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
4094 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4095 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
4099 /* This function makes an old ABI object reference to ".bar" cause the
4100 inclusion of a new ABI object archive that defines "bar".
4101 NAME is a symbol defined in an archive. Return a symbol in the hash
4102 table that might be satisfied by the archive symbols. */
4104 static struct elf_link_hash_entry
*
4105 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4106 struct bfd_link_info
*info
,
4109 struct elf_link_hash_entry
*h
;
4113 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4115 /* Don't return this sym if it is a fake function descriptor
4116 created by add_symbol_adjust. */
4117 && !((struct ppc_link_hash_entry
*) h
)->fake
)
4123 len
= strlen (name
);
4124 dot_name
= bfd_alloc (abfd
, len
+ 2);
4125 if (dot_name
== NULL
)
4126 return (struct elf_link_hash_entry
*) -1;
4128 memcpy (dot_name
+ 1, name
, len
+ 1);
4129 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4130 bfd_release (abfd
, dot_name
);
4134 /* This function satisfies all old ABI object references to ".bar" if a
4135 new ABI object defines "bar". Well, at least, undefined dot symbols
4136 are made weak. This stops later archive searches from including an
4137 object if we already have a function descriptor definition. It also
4138 prevents the linker complaining about undefined symbols.
4139 We also check and correct mismatched symbol visibility here. The
4140 most restrictive visibility of the function descriptor and the
4141 function entry symbol is used. */
4144 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4146 struct ppc_link_hash_table
*htab
;
4147 struct ppc_link_hash_entry
*fdh
;
4149 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4150 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4152 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4155 if (eh
->elf
.root
.root
.string
[0] != '.')
4158 htab
= ppc_hash_table (info
);
4162 fdh
= lookup_fdh (eh
, htab
);
4164 && !bfd_link_relocatable (info
)
4165 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4166 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4167 && eh
->elf
.ref_regular
)
4169 /* Make an undefined function descriptor sym, in order to
4170 pull in an --as-needed shared lib. Archives are handled
4172 fdh
= make_fdh (info
, eh
);
4179 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4180 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4182 /* Make both descriptor and entry symbol have the most
4183 constraining visibility of either symbol. */
4184 if (entry_vis
< descr_vis
)
4185 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4186 else if (entry_vis
> descr_vis
)
4187 eh
->elf
.other
+= descr_vis
- entry_vis
;
4189 /* Propagate reference flags from entry symbol to function
4190 descriptor symbol. */
4191 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
4192 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
4193 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
4194 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
4196 if (!fdh
->elf
.forced_local
4197 && fdh
->elf
.dynindx
== -1
4198 && fdh
->elf
.versioned
!= versioned_hidden
4199 && (bfd_link_dll (info
)
4200 || fdh
->elf
.def_dynamic
4201 || fdh
->elf
.ref_dynamic
)
4202 && (eh
->elf
.ref_regular
4203 || eh
->elf
.def_regular
))
4205 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
4213 /* Set up opd section info and abiversion for IBFD, and process list
4214 of dot-symbols we made in link_hash_newfunc. */
4217 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
4219 struct ppc_link_hash_table
*htab
;
4220 struct ppc_link_hash_entry
**p
, *eh
;
4221 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
4223 if (opd
!= NULL
&& opd
->size
!= 0)
4225 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
4226 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
4228 if (abiversion (ibfd
) == 0)
4229 set_abiversion (ibfd
, 1);
4230 else if (abiversion (ibfd
) >= 2)
4232 /* xgettext:c-format */
4233 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4234 ibfd
, abiversion (ibfd
));
4235 bfd_set_error (bfd_error_bad_value
);
4240 if (is_ppc64_elf (info
->output_bfd
))
4242 /* For input files without an explicit abiversion in e_flags
4243 we should have flagged any with symbol st_other bits set
4244 as ELFv1 and above flagged those with .opd as ELFv2.
4245 Set the output abiversion if not yet set, and for any input
4246 still ambiguous, take its abiversion from the output.
4247 Differences in ABI are reported later. */
4248 if (abiversion (info
->output_bfd
) == 0)
4249 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4250 else if (abiversion (ibfd
) == 0)
4251 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4254 htab
= ppc_hash_table (info
);
4258 if (opd
!= NULL
&& opd
->size
!= 0
4259 && (ibfd
->flags
& DYNAMIC
) == 0
4260 && (opd
->flags
& SEC_RELOC
) != 0
4261 && opd
->reloc_count
!= 0
4262 && !bfd_is_abs_section (opd
->output_section
)
4263 && info
->gc_sections
)
4265 /* Garbage collection needs some extra help with .opd sections.
4266 We don't want to necessarily keep everything referenced by
4267 relocs in .opd, as that would keep all functions. Instead,
4268 if we reference an .opd symbol (a function descriptor), we
4269 want to keep the function code symbol's section. This is
4270 easy for global symbols, but for local syms we need to keep
4271 information about the associated function section. */
4273 asection
**opd_sym_map
;
4274 Elf_Internal_Shdr
*symtab_hdr
;
4275 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4277 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4278 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4279 if (opd_sym_map
== NULL
)
4281 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4282 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4286 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4287 rel_end
= relocs
+ opd
->reloc_count
- 1;
4288 for (rel
= relocs
; rel
< rel_end
; rel
++)
4290 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4291 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4293 if (r_type
== R_PPC64_ADDR64
4294 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4295 && r_symndx
< symtab_hdr
->sh_info
)
4297 Elf_Internal_Sym
*isym
;
4300 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
4303 if (elf_section_data (opd
)->relocs
!= relocs
)
4308 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4309 if (s
!= NULL
&& s
!= opd
)
4310 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4313 if (elf_section_data (opd
)->relocs
!= relocs
)
4317 p
= &htab
->dot_syms
;
4318 while ((eh
= *p
) != NULL
)
4321 if (&eh
->elf
== htab
->elf
.hgot
)
4323 else if (htab
->elf
.hgot
== NULL
4324 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4325 htab
->elf
.hgot
= &eh
->elf
;
4326 else if (abiversion (ibfd
) <= 1)
4328 htab
->need_func_desc_adj
= 1;
4329 if (!add_symbol_adjust (eh
, info
))
4332 p
= &eh
->u
.next_dot_sym
;
4337 /* Undo hash table changes when an --as-needed input file is determined
4338 not to be needed. */
4341 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4342 struct bfd_link_info
*info
,
4343 enum notice_asneeded_action act
)
4345 if (act
== notice_not_needed
)
4347 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4352 htab
->dot_syms
= NULL
;
4354 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4357 /* If --just-symbols against a final linked binary, then assume we need
4358 toc adjusting stubs when calling functions defined there. */
4361 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4363 if ((sec
->flags
& SEC_CODE
) != 0
4364 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4365 && is_ppc64_elf (sec
->owner
))
4367 if (abiversion (sec
->owner
) >= 2
4368 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4369 sec
->has_toc_reloc
= 1;
4371 _bfd_elf_link_just_syms (sec
, info
);
4374 static struct plt_entry
**
4375 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4376 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4378 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4379 struct plt_entry
**local_plt
;
4380 unsigned char *local_got_tls_masks
;
4382 if (local_got_ents
== NULL
)
4384 bfd_size_type size
= symtab_hdr
->sh_info
;
4386 size
*= (sizeof (*local_got_ents
)
4387 + sizeof (*local_plt
)
4388 + sizeof (*local_got_tls_masks
));
4389 local_got_ents
= bfd_zalloc (abfd
, size
);
4390 if (local_got_ents
== NULL
)
4392 elf_local_got_ents (abfd
) = local_got_ents
;
4395 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4397 struct got_entry
*ent
;
4399 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4400 if (ent
->addend
== r_addend
4401 && ent
->owner
== abfd
4402 && ent
->tls_type
== tls_type
)
4406 bfd_size_type amt
= sizeof (*ent
);
4407 ent
= bfd_alloc (abfd
, amt
);
4410 ent
->next
= local_got_ents
[r_symndx
];
4411 ent
->addend
= r_addend
;
4413 ent
->tls_type
= tls_type
;
4414 ent
->is_indirect
= FALSE
;
4415 ent
->got
.refcount
= 0;
4416 local_got_ents
[r_symndx
] = ent
;
4418 ent
->got
.refcount
+= 1;
4421 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4422 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4423 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4425 return local_plt
+ r_symndx
;
4429 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4431 struct plt_entry
*ent
;
4433 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4434 if (ent
->addend
== addend
)
4438 bfd_size_type amt
= sizeof (*ent
);
4439 ent
= bfd_alloc (abfd
, amt
);
4443 ent
->addend
= addend
;
4444 ent
->plt
.refcount
= 0;
4447 ent
->plt
.refcount
+= 1;
4452 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4454 return (r_type
== R_PPC64_REL24
4455 || r_type
== R_PPC64_REL24_NOTOC
4456 || r_type
== R_PPC64_REL14
4457 || r_type
== R_PPC64_REL14_BRTAKEN
4458 || r_type
== R_PPC64_REL14_BRNTAKEN
4459 || r_type
== R_PPC64_ADDR24
4460 || r_type
== R_PPC64_ADDR14
4461 || r_type
== R_PPC64_ADDR14_BRTAKEN
4462 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4463 || r_type
== R_PPC64_PLTCALL
4464 || r_type
== R_PPC64_PLTCALL_NOTOC
);
4467 /* Relocs on inline plt call sequence insns prior to the call. */
4470 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4472 return (r_type
== R_PPC64_PLT16_HA
4473 || r_type
== R_PPC64_PLT16_HI
4474 || r_type
== R_PPC64_PLT16_LO
4475 || r_type
== R_PPC64_PLT16_LO_DS
4476 || r_type
== R_PPC64_PLT_PCREL34
4477 || r_type
== R_PPC64_PLT_PCREL34_NOTOC
4478 || r_type
== R_PPC64_PLTSEQ
4479 || r_type
== R_PPC64_PLTSEQ_NOTOC
);
4482 /* Look through the relocs for a section during the first phase, and
4483 calculate needed space in the global offset table, procedure
4484 linkage table, and dynamic reloc sections. */
4487 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4488 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4490 struct ppc_link_hash_table
*htab
;
4491 Elf_Internal_Shdr
*symtab_hdr
;
4492 struct elf_link_hash_entry
**sym_hashes
;
4493 const Elf_Internal_Rela
*rel
;
4494 const Elf_Internal_Rela
*rel_end
;
4496 struct elf_link_hash_entry
*tga
, *dottga
;
4499 if (bfd_link_relocatable (info
))
4502 /* Don't do anything special with non-loaded, non-alloced sections.
4503 In particular, any relocs in such sections should not affect GOT
4504 and PLT reference counting (ie. we don't allow them to create GOT
4505 or PLT entries), there's no possibility or desire to optimize TLS
4506 relocs, and there's not much point in propagating relocs to shared
4507 libs that the dynamic linker won't relocate. */
4508 if ((sec
->flags
& SEC_ALLOC
) == 0)
4511 BFD_ASSERT (is_ppc64_elf (abfd
));
4513 htab
= ppc_hash_table (info
);
4517 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4518 FALSE
, FALSE
, TRUE
);
4519 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4520 FALSE
, FALSE
, TRUE
);
4521 symtab_hdr
= &elf_symtab_hdr (abfd
);
4522 sym_hashes
= elf_sym_hashes (abfd
);
4524 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4525 rel_end
= relocs
+ sec
->reloc_count
;
4526 for (rel
= relocs
; rel
< rel_end
; rel
++)
4528 unsigned long r_symndx
;
4529 struct elf_link_hash_entry
*h
;
4530 enum elf_ppc64_reloc_type r_type
;
4532 struct _ppc64_elf_section_data
*ppc64_sec
;
4533 struct plt_entry
**ifunc
, **plt_list
;
4535 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4536 if (r_symndx
< symtab_hdr
->sh_info
)
4540 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4541 h
= elf_follow_link (h
);
4543 if (h
== htab
->elf
.hgot
)
4544 sec
->has_toc_reloc
= 1;
4547 r_type
= ELF64_R_TYPE (rel
->r_info
);
4551 case R_PPC64_D34_LO
:
4552 case R_PPC64_D34_HI30
:
4553 case R_PPC64_D34_HA30
:
4555 case R_PPC64_TPREL34
:
4556 case R_PPC64_DTPREL34
:
4557 case R_PPC64_PCREL34
:
4558 case R_PPC64_GOT_PCREL34
:
4559 case R_PPC64_GOT_TLSGD34
:
4560 case R_PPC64_GOT_TLSLD34
:
4561 case R_PPC64_GOT_TPREL34
:
4562 case R_PPC64_GOT_DTPREL34
:
4563 case R_PPC64_PLT_PCREL34
:
4564 case R_PPC64_PLT_PCREL34_NOTOC
:
4565 case R_PPC64_PCREL28
:
4566 htab
->powerxx_stubs
= 1;
4574 case R_PPC64_PLT16_HA
:
4575 case R_PPC64_GOT_TLSLD16_HA
:
4576 case R_PPC64_GOT_TLSGD16_HA
:
4577 case R_PPC64_GOT_TPREL16_HA
:
4578 case R_PPC64_GOT_DTPREL16_HA
:
4579 case R_PPC64_GOT16_HA
:
4580 case R_PPC64_TOC16_HA
:
4581 case R_PPC64_PLT16_LO
:
4582 case R_PPC64_PLT16_LO_DS
:
4583 case R_PPC64_GOT_TLSLD16_LO
:
4584 case R_PPC64_GOT_TLSGD16_LO
:
4585 case R_PPC64_GOT_TPREL16_LO_DS
:
4586 case R_PPC64_GOT_DTPREL16_LO_DS
:
4587 case R_PPC64_GOT16_LO
:
4588 case R_PPC64_GOT16_LO_DS
:
4589 case R_PPC64_TOC16_LO
:
4590 case R_PPC64_TOC16_LO_DS
:
4591 case R_PPC64_GOT_PCREL34
:
4592 ppc64_elf_tdata (abfd
)->has_optrel
= 1;
4593 ppc64_elf_section_data (sec
)->has_optrel
= 1;
4602 if (h
->type
== STT_GNU_IFUNC
)
4605 ifunc
= &h
->plt
.plist
;
4610 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4615 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4617 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4619 NON_GOT
| PLT_IFUNC
);
4630 /* These special tls relocs tie a call to __tls_get_addr with
4631 its parameter symbol. */
4633 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4635 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4637 NON_GOT
| TLS_TLS
| TLS_MARK
))
4639 sec
->has_tls_reloc
= 1;
4642 case R_PPC64_GOT_TLSLD16
:
4643 case R_PPC64_GOT_TLSLD16_LO
:
4644 case R_PPC64_GOT_TLSLD16_HI
:
4645 case R_PPC64_GOT_TLSLD16_HA
:
4646 case R_PPC64_GOT_TLSLD34
:
4647 tls_type
= TLS_TLS
| TLS_LD
;
4650 case R_PPC64_GOT_TLSGD16
:
4651 case R_PPC64_GOT_TLSGD16_LO
:
4652 case R_PPC64_GOT_TLSGD16_HI
:
4653 case R_PPC64_GOT_TLSGD16_HA
:
4654 case R_PPC64_GOT_TLSGD34
:
4655 tls_type
= TLS_TLS
| TLS_GD
;
4658 case R_PPC64_GOT_TPREL16_DS
:
4659 case R_PPC64_GOT_TPREL16_LO_DS
:
4660 case R_PPC64_GOT_TPREL16_HI
:
4661 case R_PPC64_GOT_TPREL16_HA
:
4662 case R_PPC64_GOT_TPREL34
:
4663 if (bfd_link_dll (info
))
4664 info
->flags
|= DF_STATIC_TLS
;
4665 tls_type
= TLS_TLS
| TLS_TPREL
;
4668 case R_PPC64_GOT_DTPREL16_DS
:
4669 case R_PPC64_GOT_DTPREL16_LO_DS
:
4670 case R_PPC64_GOT_DTPREL16_HI
:
4671 case R_PPC64_GOT_DTPREL16_HA
:
4672 case R_PPC64_GOT_DTPREL34
:
4673 tls_type
= TLS_TLS
| TLS_DTPREL
;
4675 sec
->has_tls_reloc
= 1;
4679 case R_PPC64_GOT16_LO
:
4680 case R_PPC64_GOT16_HI
:
4681 case R_PPC64_GOT16_HA
:
4682 case R_PPC64_GOT16_DS
:
4683 case R_PPC64_GOT16_LO_DS
:
4684 case R_PPC64_GOT_PCREL34
:
4686 /* This symbol requires a global offset table entry. */
4687 sec
->has_toc_reloc
= 1;
4688 if (r_type
== R_PPC64_GOT_TLSLD16
4689 || r_type
== R_PPC64_GOT_TLSGD16
4690 || r_type
== R_PPC64_GOT_TPREL16_DS
4691 || r_type
== R_PPC64_GOT_DTPREL16_DS
4692 || r_type
== R_PPC64_GOT16
4693 || r_type
== R_PPC64_GOT16_DS
)
4695 htab
->do_multi_toc
= 1;
4696 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4699 if (ppc64_elf_tdata (abfd
)->got
== NULL
4700 && !create_got_section (abfd
, info
))
4705 struct ppc_link_hash_entry
*eh
;
4706 struct got_entry
*ent
;
4708 eh
= (struct ppc_link_hash_entry
*) h
;
4709 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4710 if (ent
->addend
== rel
->r_addend
4711 && ent
->owner
== abfd
4712 && ent
->tls_type
== tls_type
)
4716 bfd_size_type amt
= sizeof (*ent
);
4717 ent
= bfd_alloc (abfd
, amt
);
4720 ent
->next
= eh
->elf
.got
.glist
;
4721 ent
->addend
= rel
->r_addend
;
4723 ent
->tls_type
= tls_type
;
4724 ent
->is_indirect
= FALSE
;
4725 ent
->got
.refcount
= 0;
4726 eh
->elf
.got
.glist
= ent
;
4728 ent
->got
.refcount
+= 1;
4729 eh
->tls_mask
|= tls_type
;
4732 /* This is a global offset table entry for a local symbol. */
4733 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4734 rel
->r_addend
, tls_type
))
4737 /* We may also need a plt entry if the symbol turns out to be
4739 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
4741 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4746 case R_PPC64_PLT16_HA
:
4747 case R_PPC64_PLT16_HI
:
4748 case R_PPC64_PLT16_LO
:
4749 case R_PPC64_PLT16_LO_DS
:
4750 case R_PPC64_PLT_PCREL34
:
4751 case R_PPC64_PLT_PCREL34_NOTOC
:
4754 /* This symbol requires a procedure linkage table entry. */
4759 if (h
->root
.root
.string
[0] == '.'
4760 && h
->root
.root
.string
[1] != '\0')
4761 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4762 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= PLT_KEEP
;
4763 plt_list
= &h
->plt
.plist
;
4765 if (plt_list
== NULL
)
4766 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4768 NON_GOT
| PLT_KEEP
);
4769 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4773 /* The following relocations don't need to propagate the
4774 relocation if linking a shared object since they are
4775 section relative. */
4776 case R_PPC64_SECTOFF
:
4777 case R_PPC64_SECTOFF_LO
:
4778 case R_PPC64_SECTOFF_HI
:
4779 case R_PPC64_SECTOFF_HA
:
4780 case R_PPC64_SECTOFF_DS
:
4781 case R_PPC64_SECTOFF_LO_DS
:
4782 case R_PPC64_DTPREL16
:
4783 case R_PPC64_DTPREL16_LO
:
4784 case R_PPC64_DTPREL16_HI
:
4785 case R_PPC64_DTPREL16_HA
:
4786 case R_PPC64_DTPREL16_DS
:
4787 case R_PPC64_DTPREL16_LO_DS
:
4788 case R_PPC64_DTPREL16_HIGH
:
4789 case R_PPC64_DTPREL16_HIGHA
:
4790 case R_PPC64_DTPREL16_HIGHER
:
4791 case R_PPC64_DTPREL16_HIGHERA
:
4792 case R_PPC64_DTPREL16_HIGHEST
:
4793 case R_PPC64_DTPREL16_HIGHESTA
:
4798 case R_PPC64_REL16_LO
:
4799 case R_PPC64_REL16_HI
:
4800 case R_PPC64_REL16_HA
:
4801 case R_PPC64_REL16_HIGH
:
4802 case R_PPC64_REL16_HIGHA
:
4803 case R_PPC64_REL16_HIGHER
:
4804 case R_PPC64_REL16_HIGHERA
:
4805 case R_PPC64_REL16_HIGHEST
:
4806 case R_PPC64_REL16_HIGHESTA
:
4807 case R_PPC64_REL16_HIGHER34
:
4808 case R_PPC64_REL16_HIGHERA34
:
4809 case R_PPC64_REL16_HIGHEST34
:
4810 case R_PPC64_REL16_HIGHESTA34
:
4811 case R_PPC64_REL16DX_HA
:
4814 /* Not supported as a dynamic relocation. */
4815 case R_PPC64_ADDR64_LOCAL
:
4816 if (bfd_link_pic (info
))
4818 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
4820 /* xgettext:c-format */
4821 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
4822 "in shared libraries and PIEs\n"),
4823 abfd
, sec
, rel
->r_offset
,
4824 ppc64_elf_howto_table
[r_type
]->name
);
4825 bfd_set_error (bfd_error_bad_value
);
4831 case R_PPC64_TOC16_DS
:
4832 htab
->do_multi_toc
= 1;
4833 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4835 case R_PPC64_TOC16_LO
:
4836 case R_PPC64_TOC16_HI
:
4837 case R_PPC64_TOC16_HA
:
4838 case R_PPC64_TOC16_LO_DS
:
4839 sec
->has_toc_reloc
= 1;
4840 if (h
!= NULL
&& bfd_link_executable (info
))
4842 /* We may need a copy reloc. */
4844 /* Strongly prefer a copy reloc over a dynamic reloc.
4845 glibc ld.so as of 2019-08 will error out if one of
4846 these relocations is emitted. */
4856 /* This relocation describes the C++ object vtable hierarchy.
4857 Reconstruct it for later use during GC. */
4858 case R_PPC64_GNU_VTINHERIT
:
4859 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4863 /* This relocation describes which C++ vtable entries are actually
4864 used. Record for later use during GC. */
4865 case R_PPC64_GNU_VTENTRY
:
4866 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4871 case R_PPC64_REL14_BRTAKEN
:
4872 case R_PPC64_REL14_BRNTAKEN
:
4874 asection
*dest
= NULL
;
4876 /* Heuristic: If jumping outside our section, chances are
4877 we are going to need a stub. */
4880 /* If the sym is weak it may be overridden later, so
4881 don't assume we know where a weak sym lives. */
4882 if (h
->root
.type
== bfd_link_hash_defined
)
4883 dest
= h
->root
.u
.def
.section
;
4887 Elf_Internal_Sym
*isym
;
4889 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4894 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4898 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4902 case R_PPC64_PLTCALL
:
4903 case R_PPC64_PLTCALL_NOTOC
:
4904 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
4908 case R_PPC64_REL24_NOTOC
:
4914 if (h
->root
.root
.string
[0] == '.'
4915 && h
->root
.root
.string
[1] != '\0')
4916 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4918 if (h
== tga
|| h
== dottga
)
4920 sec
->has_tls_reloc
= 1;
4922 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4923 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4924 /* We have a new-style __tls_get_addr call with
4928 /* Mark this section as having an old-style call. */
4929 sec
->nomark_tls_get_addr
= 1;
4931 plt_list
= &h
->plt
.plist
;
4934 /* We may need a .plt entry if the function this reloc
4935 refers to is in a shared lib. */
4937 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4941 case R_PPC64_ADDR14
:
4942 case R_PPC64_ADDR14_BRNTAKEN
:
4943 case R_PPC64_ADDR14_BRTAKEN
:
4944 case R_PPC64_ADDR24
:
4947 case R_PPC64_TPREL64
:
4948 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4949 if (bfd_link_dll (info
))
4950 info
->flags
|= DF_STATIC_TLS
;
4953 case R_PPC64_DTPMOD64
:
4954 if (rel
+ 1 < rel_end
4955 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4956 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4957 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4959 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4962 case R_PPC64_DTPREL64
:
4963 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4965 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4966 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4967 /* This is the second reloc of a dtpmod, dtprel pair.
4968 Don't mark with TLS_DTPREL. */
4972 sec
->has_tls_reloc
= 1;
4975 struct ppc_link_hash_entry
*eh
;
4976 eh
= (struct ppc_link_hash_entry
*) h
;
4977 eh
->tls_mask
|= tls_type
& 0xff;
4980 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4981 rel
->r_addend
, tls_type
))
4984 ppc64_sec
= ppc64_elf_section_data (sec
);
4985 if (ppc64_sec
->sec_type
!= sec_toc
)
4989 /* One extra to simplify get_tls_mask. */
4990 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
4991 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
4992 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
4994 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
4995 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
4996 if (ppc64_sec
->u
.toc
.add
== NULL
)
4998 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4999 ppc64_sec
->sec_type
= sec_toc
;
5001 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5002 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5003 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5005 /* Mark the second slot of a GD or LD entry.
5006 -1 to indicate GD and -2 to indicate LD. */
5007 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5008 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5009 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5010 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5013 case R_PPC64_TPREL16
:
5014 case R_PPC64_TPREL16_LO
:
5015 case R_PPC64_TPREL16_HI
:
5016 case R_PPC64_TPREL16_HA
:
5017 case R_PPC64_TPREL16_DS
:
5018 case R_PPC64_TPREL16_LO_DS
:
5019 case R_PPC64_TPREL16_HIGH
:
5020 case R_PPC64_TPREL16_HIGHA
:
5021 case R_PPC64_TPREL16_HIGHER
:
5022 case R_PPC64_TPREL16_HIGHERA
:
5023 case R_PPC64_TPREL16_HIGHEST
:
5024 case R_PPC64_TPREL16_HIGHESTA
:
5025 case R_PPC64_TPREL34
:
5026 if (bfd_link_dll (info
))
5027 info
->flags
|= DF_STATIC_TLS
;
5030 case R_PPC64_ADDR64
:
5032 && rel
+ 1 < rel_end
5033 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5036 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5040 case R_PPC64_ADDR16
:
5041 case R_PPC64_ADDR16_DS
:
5042 case R_PPC64_ADDR16_HA
:
5043 case R_PPC64_ADDR16_HI
:
5044 case R_PPC64_ADDR16_HIGH
:
5045 case R_PPC64_ADDR16_HIGHA
:
5046 case R_PPC64_ADDR16_HIGHER
:
5047 case R_PPC64_ADDR16_HIGHERA
:
5048 case R_PPC64_ADDR16_HIGHEST
:
5049 case R_PPC64_ADDR16_HIGHESTA
:
5050 case R_PPC64_ADDR16_LO
:
5051 case R_PPC64_ADDR16_LO_DS
:
5053 case R_PPC64_D34_LO
:
5054 case R_PPC64_D34_HI30
:
5055 case R_PPC64_D34_HA30
:
5056 case R_PPC64_ADDR16_HIGHER34
:
5057 case R_PPC64_ADDR16_HIGHERA34
:
5058 case R_PPC64_ADDR16_HIGHEST34
:
5059 case R_PPC64_ADDR16_HIGHESTA34
:
5061 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5062 && rel
->r_addend
== 0)
5064 /* We may need a .plt entry if this reloc refers to a
5065 function in a shared lib. */
5066 if (!update_plt_info (abfd
, &h
->plt
.plist
, 0))
5068 h
->pointer_equality_needed
= 1;
5075 case R_PPC64_ADDR32
:
5076 case R_PPC64_UADDR16
:
5077 case R_PPC64_UADDR32
:
5078 case R_PPC64_UADDR64
:
5080 if (h
!= NULL
&& bfd_link_executable (info
))
5081 /* We may need a copy reloc. */
5084 /* Don't propagate .opd relocs. */
5085 if (NO_OPD_RELOCS
&& is_opd
)
5088 /* If we are creating a shared library, and this is a reloc
5089 against a global symbol, or a non PC relative reloc
5090 against a local symbol, then we need to copy the reloc
5091 into the shared library. However, if we are linking with
5092 -Bsymbolic, we do not need to copy a reloc against a
5093 global symbol which is defined in an object we are
5094 including in the link (i.e., DEF_REGULAR is set). At
5095 this point we have not seen all the input files, so it is
5096 possible that DEF_REGULAR is not set now but will be set
5097 later (it is never cleared). In case of a weak definition,
5098 DEF_REGULAR may be cleared later by a strong definition in
5099 a shared library. We account for that possibility below by
5100 storing information in the dyn_relocs field of the hash
5101 table entry. A similar situation occurs when creating
5102 shared libraries and symbol visibility changes render the
5105 If on the other hand, we are creating an executable, we
5106 may need to keep relocations for symbols satisfied by a
5107 dynamic library if we manage to avoid copy relocs for the
5111 && (h
->root
.type
== bfd_link_hash_defweak
5112 || !h
->def_regular
))
5114 && !bfd_link_executable (info
)
5115 && !SYMBOLIC_BIND (info
, h
))
5116 || (bfd_link_pic (info
)
5117 && must_be_dyn_reloc (info
, r_type
))
5118 || (!bfd_link_pic (info
)
5121 /* We must copy these reloc types into the output file.
5122 Create a reloc section in dynobj and make room for
5126 sreloc
= _bfd_elf_make_dynamic_reloc_section
5127 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5133 /* If this is a global symbol, we count the number of
5134 relocations we need for this symbol. */
5137 struct elf_dyn_relocs
*p
;
5138 struct elf_dyn_relocs
**head
;
5140 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5142 if (p
== NULL
|| p
->sec
!= sec
)
5144 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5154 if (!must_be_dyn_reloc (info
, r_type
))
5159 /* Track dynamic relocs needed for local syms too.
5160 We really need local syms available to do this
5162 struct ppc_dyn_relocs
*p
;
5163 struct ppc_dyn_relocs
**head
;
5164 bfd_boolean is_ifunc
;
5167 Elf_Internal_Sym
*isym
;
5169 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5174 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5178 vpp
= &elf_section_data (s
)->local_dynrel
;
5179 head
= (struct ppc_dyn_relocs
**) vpp
;
5180 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5182 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5184 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5186 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5192 p
->ifunc
= is_ifunc
;
5208 /* Merge backend specific data from an object file to the output
5209 object file when linking. */
5212 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
5214 bfd
*obfd
= info
->output_bfd
;
5215 unsigned long iflags
, oflags
;
5217 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5220 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5223 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
5226 iflags
= elf_elfheader (ibfd
)->e_flags
;
5227 oflags
= elf_elfheader (obfd
)->e_flags
;
5229 if (iflags
& ~EF_PPC64_ABI
)
5232 /* xgettext:c-format */
5233 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5234 bfd_set_error (bfd_error_bad_value
);
5237 else if (iflags
!= oflags
&& iflags
!= 0)
5240 /* xgettext:c-format */
5241 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
5242 ibfd
, iflags
, oflags
);
5243 bfd_set_error (bfd_error_bad_value
);
5247 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
5250 /* Merge Tag_compatibility attributes and any common GNU ones. */
5251 return _bfd_elf_merge_object_attributes (ibfd
, info
);
5255 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5257 /* Print normal ELF private data. */
5258 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5260 if (elf_elfheader (abfd
)->e_flags
!= 0)
5264 fprintf (file
, _("private flags = 0x%lx:"),
5265 elf_elfheader (abfd
)->e_flags
);
5267 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5268 fprintf (file
, _(" [abiv%ld]"),
5269 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5276 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5277 of the code entry point, and its section, which must be in the same
5278 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5281 opd_entry_value (asection
*opd_sec
,
5283 asection
**code_sec
,
5285 bfd_boolean in_code_sec
)
5287 bfd
*opd_bfd
= opd_sec
->owner
;
5288 Elf_Internal_Rela
*relocs
;
5289 Elf_Internal_Rela
*lo
, *hi
, *look
;
5292 /* No relocs implies we are linking a --just-symbols object, or looking
5293 at a final linked executable with addr2line or somesuch. */
5294 if (opd_sec
->reloc_count
== 0)
5296 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
5298 if (contents
== NULL
)
5300 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5301 return (bfd_vma
) -1;
5302 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5305 /* PR 17512: file: 64b9dfbb. */
5306 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5307 return (bfd_vma
) -1;
5309 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5310 if (code_sec
!= NULL
)
5312 asection
*sec
, *likely
= NULL
;
5318 && val
< sec
->vma
+ sec
->size
)
5324 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5326 && (sec
->flags
& SEC_LOAD
) != 0
5327 && (sec
->flags
& SEC_ALLOC
) != 0)
5332 if (code_off
!= NULL
)
5333 *code_off
= val
- likely
->vma
;
5339 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5341 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5343 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5344 /* PR 17512: file: df8e1fd6. */
5346 return (bfd_vma
) -1;
5348 /* Go find the opd reloc at the sym address. */
5350 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5354 look
= lo
+ (hi
- lo
) / 2;
5355 if (look
->r_offset
< offset
)
5357 else if (look
->r_offset
> offset
)
5361 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5363 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5364 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5366 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5367 asection
*sec
= NULL
;
5369 if (symndx
>= symtab_hdr
->sh_info
5370 && elf_sym_hashes (opd_bfd
) != NULL
)
5372 struct elf_link_hash_entry
**sym_hashes
;
5373 struct elf_link_hash_entry
*rh
;
5375 sym_hashes
= elf_sym_hashes (opd_bfd
);
5376 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5379 rh
= elf_follow_link (rh
);
5380 if (rh
->root
.type
!= bfd_link_hash_defined
5381 && rh
->root
.type
!= bfd_link_hash_defweak
)
5383 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5385 val
= rh
->root
.u
.def
.value
;
5386 sec
= rh
->root
.u
.def
.section
;
5393 Elf_Internal_Sym
*sym
;
5395 if (symndx
< symtab_hdr
->sh_info
)
5397 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5400 size_t symcnt
= symtab_hdr
->sh_info
;
5401 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5406 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5412 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5418 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5421 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5422 val
= sym
->st_value
;
5425 val
+= look
->r_addend
;
5426 if (code_off
!= NULL
)
5428 if (code_sec
!= NULL
)
5430 if (in_code_sec
&& *code_sec
!= sec
)
5435 if (sec
->output_section
!= NULL
)
5436 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5445 /* If the ELF symbol SYM might be a function in SEC, return the
5446 function size and set *CODE_OFF to the function's entry point,
5447 otherwise return zero. */
5449 static bfd_size_type
5450 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5455 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5456 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5460 if (!(sym
->flags
& BSF_SYNTHETIC
))
5461 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
5463 if (strcmp (sym
->section
->name
, ".opd") == 0)
5465 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5466 bfd_vma symval
= sym
->value
;
5469 && opd
->adjust
!= NULL
5470 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5472 /* opd_entry_value will use cached relocs that have been
5473 adjusted, but with raw symbols. That means both local
5474 and global symbols need adjusting. */
5475 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5481 if (opd_entry_value (sym
->section
, symval
,
5482 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
5484 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5485 symbol. This size has nothing to do with the code size of the
5486 function, which is what we're supposed to return, but the
5487 code size isn't available without looking up the dot-sym.
5488 However, doing that would be a waste of time particularly
5489 since elf_find_function will look at the dot-sym anyway.
5490 Now, elf_find_function will keep the largest size of any
5491 function sym found at the code address of interest, so return
5492 1 here to avoid it incorrectly caching a larger function size
5493 for a small function. This does mean we return the wrong
5494 size for a new-ABI function of size 24, but all that does is
5495 disable caching for such functions. */
5501 if (sym
->section
!= sec
)
5503 *code_off
= sym
->value
;
5510 /* Return true if symbol is a strong function defined in an ELFv2
5511 object with st_other localentry bits of zero, ie. its local entry
5512 point coincides with its global entry point. */
5515 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5518 && h
->type
== STT_FUNC
5519 && h
->root
.type
== bfd_link_hash_defined
5520 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5521 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
5522 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5523 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5526 /* Return true if symbol is defined in a regular object file. */
5529 is_static_defined (struct elf_link_hash_entry
*h
)
5531 return ((h
->root
.type
== bfd_link_hash_defined
5532 || h
->root
.type
== bfd_link_hash_defweak
)
5533 && h
->root
.u
.def
.section
!= NULL
5534 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5537 /* If FDH is a function descriptor symbol, return the associated code
5538 entry symbol if it is defined. Return NULL otherwise. */
5540 static struct ppc_link_hash_entry
*
5541 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5543 if (fdh
->is_func_descriptor
)
5545 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5546 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5547 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5553 /* If FH is a function code entry symbol, return the associated
5554 function descriptor symbol if it is defined. Return NULL otherwise. */
5556 static struct ppc_link_hash_entry
*
5557 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5560 && fh
->oh
->is_func_descriptor
)
5562 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5563 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5564 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5570 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
5572 /* Garbage collect sections, after first dealing with dot-symbols. */
5575 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5577 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5579 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5581 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5582 htab
->need_func_desc_adj
= 0;
5584 return bfd_elf_gc_sections (abfd
, info
);
5587 /* Mark all our entry sym sections, both opd and code section. */
5590 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5592 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5593 struct bfd_sym_chain
*sym
;
5598 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5600 struct ppc_link_hash_entry
*eh
, *fh
;
5603 eh
= (struct ppc_link_hash_entry
*)
5604 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5607 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5608 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5611 fh
= defined_code_entry (eh
);
5614 sec
= fh
->elf
.root
.u
.def
.section
;
5615 sec
->flags
|= SEC_KEEP
;
5617 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5618 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5619 eh
->elf
.root
.u
.def
.value
,
5620 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5621 sec
->flags
|= SEC_KEEP
;
5623 sec
= eh
->elf
.root
.u
.def
.section
;
5624 sec
->flags
|= SEC_KEEP
;
5628 /* Mark sections containing dynamically referenced symbols. When
5629 building shared libraries, we must assume that any visible symbol is
5633 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5635 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5636 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5637 struct ppc_link_hash_entry
*fdh
;
5638 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5640 /* Dynamic linking info is on the func descriptor sym. */
5641 fdh
= defined_func_desc (eh
);
5645 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5646 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5647 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5648 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5649 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5650 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5651 && (!bfd_link_executable (info
)
5652 || info
->gc_keep_exported
5653 || info
->export_dynamic
5656 && (*d
->match
) (&d
->head
, NULL
,
5657 eh
->elf
.root
.root
.string
)))
5658 && (eh
->elf
.versioned
>= versioned
5659 || !bfd_hide_sym_by_version (info
->version_info
,
5660 eh
->elf
.root
.root
.string
)))))
5663 struct ppc_link_hash_entry
*fh
;
5665 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5667 /* Function descriptor syms cause the associated
5668 function code sym section to be marked. */
5669 fh
= defined_code_entry (eh
);
5672 code_sec
= fh
->elf
.root
.u
.def
.section
;
5673 code_sec
->flags
|= SEC_KEEP
;
5675 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5676 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5677 eh
->elf
.root
.u
.def
.value
,
5678 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5679 code_sec
->flags
|= SEC_KEEP
;
5685 /* Return the section that should be marked against GC for a given
5689 ppc64_elf_gc_mark_hook (asection
*sec
,
5690 struct bfd_link_info
*info
,
5691 Elf_Internal_Rela
*rel
,
5692 struct elf_link_hash_entry
*h
,
5693 Elf_Internal_Sym
*sym
)
5697 /* Syms return NULL if we're marking .opd, so we avoid marking all
5698 function sections, as all functions are referenced in .opd. */
5700 if (get_opd_info (sec
) != NULL
)
5705 enum elf_ppc64_reloc_type r_type
;
5706 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5708 r_type
= ELF64_R_TYPE (rel
->r_info
);
5711 case R_PPC64_GNU_VTINHERIT
:
5712 case R_PPC64_GNU_VTENTRY
:
5716 switch (h
->root
.type
)
5718 case bfd_link_hash_defined
:
5719 case bfd_link_hash_defweak
:
5720 eh
= (struct ppc_link_hash_entry
*) h
;
5721 fdh
= defined_func_desc (eh
);
5724 /* -mcall-aixdesc code references the dot-symbol on
5725 a call reloc. Mark the function descriptor too
5726 against garbage collection. */
5728 if (fdh
->elf
.is_weakalias
)
5729 weakdef (&fdh
->elf
)->mark
= 1;
5733 /* Function descriptor syms cause the associated
5734 function code sym section to be marked. */
5735 fh
= defined_code_entry (eh
);
5738 /* They also mark their opd section. */
5739 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5741 rsec
= fh
->elf
.root
.u
.def
.section
;
5743 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5744 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5745 eh
->elf
.root
.u
.def
.value
,
5746 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
5747 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5749 rsec
= h
->root
.u
.def
.section
;
5752 case bfd_link_hash_common
:
5753 rsec
= h
->root
.u
.c
.p
->section
;
5757 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5763 struct _opd_sec_data
*opd
;
5765 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5766 opd
= get_opd_info (rsec
);
5767 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5771 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
5778 /* The maximum size of .sfpr. */
5779 #define SFPR_MAX (218*4)
5781 struct sfpr_def_parms
5783 const char name
[12];
5784 unsigned char lo
, hi
;
5785 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
5786 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
5789 /* Auto-generate _save*, _rest* functions in .sfpr.
5790 If STUB_SEC is non-null, define alias symbols in STUB_SEC
5794 sfpr_define (struct bfd_link_info
*info
,
5795 const struct sfpr_def_parms
*parm
,
5798 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5800 size_t len
= strlen (parm
->name
);
5801 bfd_boolean writing
= FALSE
;
5807 memcpy (sym
, parm
->name
, len
);
5810 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5812 struct ppc_link_hash_entry
*h
;
5814 sym
[len
+ 0] = i
/ 10 + '0';
5815 sym
[len
+ 1] = i
% 10 + '0';
5816 h
= (struct ppc_link_hash_entry
*)
5817 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
5818 if (stub_sec
!= NULL
)
5821 && h
->elf
.root
.type
== bfd_link_hash_defined
5822 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
5824 struct elf_link_hash_entry
*s
;
5826 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
5827 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
5830 if (s
->root
.type
== bfd_link_hash_new
5831 || (s
->root
.type
= bfd_link_hash_defined
5832 && s
->root
.u
.def
.section
== stub_sec
))
5834 s
->root
.type
= bfd_link_hash_defined
;
5835 s
->root
.u
.def
.section
= stub_sec
;
5836 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
5837 + h
->elf
.root
.u
.def
.value
);
5840 s
->ref_regular_nonweak
= 1;
5841 s
->forced_local
= 1;
5843 s
->root
.linker_def
= 1;
5851 if (!h
->elf
.def_regular
)
5853 h
->elf
.root
.type
= bfd_link_hash_defined
;
5854 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
5855 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
5856 h
->elf
.type
= STT_FUNC
;
5857 h
->elf
.def_regular
= 1;
5859 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
5861 if (htab
->sfpr
->contents
== NULL
)
5863 htab
->sfpr
->contents
5864 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5865 if (htab
->sfpr
->contents
== NULL
)
5872 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5874 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5876 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5877 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5885 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5887 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5892 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5894 p
= savegpr0 (abfd
, p
, r
);
5895 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5897 bfd_put_32 (abfd
, BLR
, p
);
5902 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5904 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5909 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5911 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5913 p
= restgpr0 (abfd
, p
, r
);
5914 bfd_put_32 (abfd
, MTLR_R0
, p
);
5918 p
= restgpr0 (abfd
, p
, 30);
5919 p
= restgpr0 (abfd
, p
, 31);
5921 bfd_put_32 (abfd
, BLR
, p
);
5926 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5928 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5933 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5935 p
= savegpr1 (abfd
, p
, r
);
5936 bfd_put_32 (abfd
, BLR
, p
);
5941 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5943 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5948 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5950 p
= restgpr1 (abfd
, p
, r
);
5951 bfd_put_32 (abfd
, BLR
, p
);
5956 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5958 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5963 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5965 p
= savefpr (abfd
, p
, r
);
5966 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5968 bfd_put_32 (abfd
, BLR
, p
);
5973 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5975 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5980 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5982 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5984 p
= restfpr (abfd
, p
, r
);
5985 bfd_put_32 (abfd
, MTLR_R0
, p
);
5989 p
= restfpr (abfd
, p
, 30);
5990 p
= restfpr (abfd
, p
, 31);
5992 bfd_put_32 (abfd
, BLR
, p
);
5997 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5999 p
= savefpr (abfd
, p
, r
);
6000 bfd_put_32 (abfd
, BLR
, p
);
6005 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6007 p
= restfpr (abfd
, p
, r
);
6008 bfd_put_32 (abfd
, BLR
, p
);
6013 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6015 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6017 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6022 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6024 p
= savevr (abfd
, p
, r
);
6025 bfd_put_32 (abfd
, BLR
, p
);
6030 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6032 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6034 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6039 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6041 p
= restvr (abfd
, p
, r
);
6042 bfd_put_32 (abfd
, BLR
, p
);
6046 /* Called via elf_link_hash_traverse to transfer dynamic linking
6047 information on function code symbol entries to their corresponding
6048 function descriptor symbol entries. */
6051 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6053 struct bfd_link_info
*info
;
6054 struct ppc_link_hash_table
*htab
;
6055 struct ppc_link_hash_entry
*fh
;
6056 struct ppc_link_hash_entry
*fdh
;
6057 bfd_boolean force_local
;
6059 fh
= (struct ppc_link_hash_entry
*) h
;
6060 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6066 if (fh
->elf
.root
.root
.string
[0] != '.'
6067 || fh
->elf
.root
.root
.string
[1] == '\0')
6071 htab
= ppc_hash_table (info
);
6075 /* Find the corresponding function descriptor symbol. */
6076 fdh
= lookup_fdh (fh
, htab
);
6078 /* Resolve undefined references to dot-symbols as the value
6079 in the function descriptor, if we have one in a regular object.
6080 This is to satisfy cases like ".quad .foo". Calls to functions
6081 in dynamic objects are handled elsewhere. */
6082 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6083 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6084 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6085 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6086 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6087 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6088 fdh
->elf
.root
.u
.def
.value
,
6089 &fh
->elf
.root
.u
.def
.section
,
6090 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
6092 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6093 fh
->elf
.forced_local
= 1;
6094 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6095 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6098 if (!fh
->elf
.dynamic
)
6100 struct plt_entry
*ent
;
6102 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6103 if (ent
->plt
.refcount
> 0)
6109 /* Create a descriptor as undefined if necessary. */
6111 && !bfd_link_executable (info
)
6112 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6113 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6115 fdh
= make_fdh (info
, fh
);
6120 /* We can't support overriding of symbols on a fake descriptor. */
6123 && (fh
->elf
.root
.type
== bfd_link_hash_defined
6124 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
6125 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6127 /* Transfer dynamic linking information to the function descriptor. */
6130 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6131 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6132 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6133 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6134 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
6135 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
6136 || fh
->elf
.type
== STT_FUNC
6137 || fh
->elf
.type
== STT_GNU_IFUNC
);
6138 move_plt_plist (fh
, fdh
);
6140 if (!fdh
->elf
.forced_local
6141 && fh
->elf
.dynindx
!= -1)
6142 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6146 /* Now that the info is on the function descriptor, clear the
6147 function code sym info. Any function code syms for which we
6148 don't have a definition in a regular file, we force local.
6149 This prevents a shared library from exporting syms that have
6150 been imported from another library. Function code syms that
6151 are really in the library we must leave global to prevent the
6152 linker dragging in a definition from a static library. */
6153 force_local
= (!fh
->elf
.def_regular
6155 || !fdh
->elf
.def_regular
6156 || fdh
->elf
.forced_local
);
6157 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6162 static const struct sfpr_def_parms save_res_funcs
[] =
6164 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6165 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6166 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6167 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6168 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6169 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6170 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6171 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6172 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6173 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6174 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6175 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6178 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6179 this hook to a) provide some gcc support functions, and b) transfer
6180 dynamic linking information gathered so far on function code symbol
6181 entries, to their corresponding function descriptor symbol entries. */
6184 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
6185 struct bfd_link_info
*info
)
6187 struct ppc_link_hash_table
*htab
;
6189 htab
= ppc_hash_table (info
);
6193 /* Provide any missing _save* and _rest* functions. */
6194 if (htab
->sfpr
!= NULL
)
6198 htab
->sfpr
->size
= 0;
6199 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
6200 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
6202 if (htab
->sfpr
->size
== 0)
6203 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
6206 if (bfd_link_relocatable (info
))
6209 if (htab
->elf
.hgot
!= NULL
)
6211 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
6212 /* Make .TOC. defined so as to prevent it being made dynamic.
6213 The wrong value here is fixed later in ppc64_elf_set_toc. */
6214 if (!htab
->elf
.hgot
->def_regular
6215 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
6217 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
6218 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
6219 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6220 htab
->elf
.hgot
->def_regular
= 1;
6221 htab
->elf
.hgot
->root
.linker_def
= 1;
6223 htab
->elf
.hgot
->type
= STT_OBJECT
;
6224 htab
->elf
.hgot
->other
6225 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
6228 if (htab
->need_func_desc_adj
)
6230 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6231 htab
->need_func_desc_adj
= 0;
6237 /* Find dynamic relocs for H that apply to read-only sections. */
6240 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6242 struct ppc_link_hash_entry
*eh
;
6243 struct elf_dyn_relocs
*p
;
6245 eh
= (struct ppc_link_hash_entry
*) h
;
6246 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6248 asection
*s
= p
->sec
->output_section
;
6250 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
6256 /* Return true if we have dynamic relocs against H or any of its weak
6257 aliases, that apply to read-only sections. Cannot be used after
6258 size_dynamic_sections. */
6261 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
6263 struct ppc_link_hash_entry
*eh
;
6265 eh
= (struct ppc_link_hash_entry
*) h
;
6268 if (readonly_dynrelocs (&eh
->elf
))
6270 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
6272 while (eh
!= NULL
&& &eh
->elf
!= h
);
6277 /* Return whether EH has pc-relative dynamic relocs. */
6280 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
6282 struct elf_dyn_relocs
*p
;
6284 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
6285 if (p
->pc_count
!= 0)
6290 /* Return true if a global entry stub will be created for H. Valid
6291 for ELFv2 before plt entries have been allocated. */
6294 global_entry_stub (struct elf_link_hash_entry
*h
)
6296 struct plt_entry
*pent
;
6298 if (!h
->pointer_equality_needed
6302 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
6303 if (pent
->plt
.refcount
> 0
6304 && pent
->addend
== 0)
6310 /* Adjust a symbol defined by a dynamic object and referenced by a
6311 regular object. The current definition is in some section of the
6312 dynamic object, but we're not including those sections. We have to
6313 change the definition to something the rest of the link can
6317 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6318 struct elf_link_hash_entry
*h
)
6320 struct ppc_link_hash_table
*htab
;
6323 htab
= ppc_hash_table (info
);
6327 /* Deal with function syms. */
6328 if (h
->type
== STT_FUNC
6329 || h
->type
== STT_GNU_IFUNC
6332 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
6333 || SYMBOL_CALLS_LOCAL (info
, h
)
6334 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6335 /* Discard dyn_relocs when non-pic if we've decided that a
6336 function symbol is local and not an ifunc. We keep dynamic
6337 relocs for ifuncs when local rather than always emitting a
6338 plt call stub for them and defining the symbol on the call
6339 stub. We can't do that for ELFv1 anyway (a function symbol
6340 is defined on a descriptor, not code) and it can be faster at
6341 run-time due to not needing to bounce through a stub. The
6342 dyn_relocs for ifuncs will be applied even in a static
6344 if (!bfd_link_pic (info
)
6345 && h
->type
!= STT_GNU_IFUNC
6347 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6349 /* Clear procedure linkage table information for any symbol that
6350 won't need a .plt entry. */
6351 struct plt_entry
*ent
;
6352 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6353 if (ent
->plt
.refcount
> 0)
6356 || (h
->type
!= STT_GNU_IFUNC
6358 && (htab
->can_convert_all_inline_plt
6359 || (((struct ppc_link_hash_entry
*) h
)->tls_mask
6360 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6362 h
->plt
.plist
= NULL
;
6364 h
->pointer_equality_needed
= 0;
6366 else if (abiversion (info
->output_bfd
) >= 2)
6368 /* Taking a function's address in a read/write section
6369 doesn't require us to define the function symbol in the
6370 executable on a global entry stub. A dynamic reloc can
6371 be used instead. The reason we prefer a few more dynamic
6372 relocs is that calling via a global entry stub costs a
6373 few more instructions, and pointer_equality_needed causes
6374 extra work in ld.so when resolving these symbols. */
6375 if (global_entry_stub (h
))
6377 if (!readonly_dynrelocs (h
))
6379 h
->pointer_equality_needed
= 0;
6380 /* If we haven't seen a branch reloc and the symbol
6381 isn't an ifunc then we don't need a plt entry. */
6383 h
->plt
.plist
= NULL
;
6385 else if (!bfd_link_pic (info
))
6386 /* We are going to be defining the function symbol on the
6387 plt stub, so no dyn_relocs needed when non-pic. */
6388 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6391 /* ELFv2 function symbols can't have copy relocs. */
6394 else if (!h
->needs_plt
6395 && !readonly_dynrelocs (h
))
6397 /* If we haven't seen a branch reloc and the symbol isn't an
6398 ifunc then we don't need a plt entry. */
6399 h
->plt
.plist
= NULL
;
6400 h
->pointer_equality_needed
= 0;
6405 h
->plt
.plist
= NULL
;
6407 /* If this is a weak symbol, and there is a real definition, the
6408 processor independent code will have arranged for us to see the
6409 real definition first, and we can just use the same value. */
6410 if (h
->is_weakalias
)
6412 struct elf_link_hash_entry
*def
= weakdef (h
);
6413 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6414 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6415 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6416 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6417 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6418 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6422 /* If we are creating a shared library, we must presume that the
6423 only references to the symbol are via the global offset table.
6424 For such cases we need not do anything here; the relocations will
6425 be handled correctly by relocate_section. */
6426 if (!bfd_link_executable (info
))
6429 /* If there are no references to this symbol that do not use the
6430 GOT, we don't need to generate a copy reloc. */
6431 if (!h
->non_got_ref
)
6434 /* Don't generate a copy reloc for symbols defined in the executable. */
6435 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6437 /* If -z nocopyreloc was given, don't generate them either. */
6438 || info
->nocopyreloc
6440 /* If we don't find any dynamic relocs in read-only sections, then
6441 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6442 || (ELIMINATE_COPY_RELOCS
6444 && !alias_readonly_dynrelocs (h
))
6446 /* Protected variables do not work with .dynbss. The copy in
6447 .dynbss won't be used by the shared library with the protected
6448 definition for the variable. Text relocations are preferable
6449 to an incorrect program. */
6450 || h
->protected_def
)
6453 if (h
->plt
.plist
!= NULL
)
6455 /* We should never get here, but unfortunately there are versions
6456 of gcc out there that improperly (for this ABI) put initialized
6457 function pointers, vtable refs and suchlike in read-only
6458 sections. Allow them to proceed, but warn that this might
6459 break at runtime. */
6460 info
->callbacks
->einfo
6461 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6462 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6463 h
->root
.root
.string
);
6466 /* This is a reference to a symbol defined by a dynamic object which
6467 is not a function. */
6469 /* We must allocate the symbol in our .dynbss section, which will
6470 become part of the .bss section of the executable. There will be
6471 an entry for this symbol in the .dynsym section. The dynamic
6472 object will contain position independent code, so all references
6473 from the dynamic object to this symbol will go through the global
6474 offset table. The dynamic linker will use the .dynsym entry to
6475 determine the address it must put in the global offset table, so
6476 both the dynamic object and the regular object will refer to the
6477 same memory location for the variable. */
6478 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6480 s
= htab
->elf
.sdynrelro
;
6481 srel
= htab
->elf
.sreldynrelro
;
6485 s
= htab
->elf
.sdynbss
;
6486 srel
= htab
->elf
.srelbss
;
6488 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6490 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6491 linker to copy the initial value out of the dynamic object
6492 and into the runtime process image. */
6493 srel
->size
+= sizeof (Elf64_External_Rela
);
6497 /* We no longer want dyn_relocs. */
6498 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6499 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6502 /* If given a function descriptor symbol, hide both the function code
6503 sym and the descriptor. */
6505 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6506 struct elf_link_hash_entry
*h
,
6507 bfd_boolean force_local
)
6509 struct ppc_link_hash_entry
*eh
;
6510 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6512 if (ppc_hash_table (info
) == NULL
)
6515 eh
= (struct ppc_link_hash_entry
*) h
;
6516 if (eh
->is_func_descriptor
)
6518 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6523 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6526 /* We aren't supposed to use alloca in BFD because on
6527 systems which do not have alloca the version in libiberty
6528 calls xmalloc, which might cause the program to crash
6529 when it runs out of memory. This function doesn't have a
6530 return status, so there's no way to gracefully return an
6531 error. So cheat. We know that string[-1] can be safely
6532 accessed; It's either a string in an ELF string table,
6533 or allocated in an objalloc structure. */
6535 p
= eh
->elf
.root
.root
.string
- 1;
6538 fh
= (struct ppc_link_hash_entry
*)
6539 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6542 /* Unfortunately, if it so happens that the string we were
6543 looking for was allocated immediately before this string,
6544 then we overwrote the string terminator. That's the only
6545 reason the lookup should fail. */
6548 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6549 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6551 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6552 fh
= (struct ppc_link_hash_entry
*)
6553 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6562 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6567 get_sym_h (struct elf_link_hash_entry
**hp
,
6568 Elf_Internal_Sym
**symp
,
6570 unsigned char **tls_maskp
,
6571 Elf_Internal_Sym
**locsymsp
,
6572 unsigned long r_symndx
,
6575 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6577 if (r_symndx
>= symtab_hdr
->sh_info
)
6579 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6580 struct elf_link_hash_entry
*h
;
6582 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6583 h
= elf_follow_link (h
);
6591 if (symsecp
!= NULL
)
6593 asection
*symsec
= NULL
;
6594 if (h
->root
.type
== bfd_link_hash_defined
6595 || h
->root
.type
== bfd_link_hash_defweak
)
6596 symsec
= h
->root
.u
.def
.section
;
6600 if (tls_maskp
!= NULL
)
6602 struct ppc_link_hash_entry
*eh
;
6604 eh
= (struct ppc_link_hash_entry
*) h
;
6605 *tls_maskp
= &eh
->tls_mask
;
6610 Elf_Internal_Sym
*sym
;
6611 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6613 if (locsyms
== NULL
)
6615 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6616 if (locsyms
== NULL
)
6617 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6618 symtab_hdr
->sh_info
,
6619 0, NULL
, NULL
, NULL
);
6620 if (locsyms
== NULL
)
6622 *locsymsp
= locsyms
;
6624 sym
= locsyms
+ r_symndx
;
6632 if (symsecp
!= NULL
)
6633 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6635 if (tls_maskp
!= NULL
)
6637 struct got_entry
**lgot_ents
;
6638 unsigned char *tls_mask
;
6641 lgot_ents
= elf_local_got_ents (ibfd
);
6642 if (lgot_ents
!= NULL
)
6644 struct plt_entry
**local_plt
= (struct plt_entry
**)
6645 (lgot_ents
+ symtab_hdr
->sh_info
);
6646 unsigned char *lgot_masks
= (unsigned char *)
6647 (local_plt
+ symtab_hdr
->sh_info
);
6648 tls_mask
= &lgot_masks
[r_symndx
];
6650 *tls_maskp
= tls_mask
;
6656 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6657 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6658 type suitable for optimization, and 1 otherwise. */
6661 get_tls_mask (unsigned char **tls_maskp
,
6662 unsigned long *toc_symndx
,
6663 bfd_vma
*toc_addend
,
6664 Elf_Internal_Sym
**locsymsp
,
6665 const Elf_Internal_Rela
*rel
,
6668 unsigned long r_symndx
;
6670 struct elf_link_hash_entry
*h
;
6671 Elf_Internal_Sym
*sym
;
6675 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6676 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6679 if ((*tls_maskp
!= NULL
6680 && (**tls_maskp
& TLS_TLS
) != 0
6681 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
6683 || ppc64_elf_section_data (sec
) == NULL
6684 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6687 /* Look inside a TOC section too. */
6690 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6691 off
= h
->root
.u
.def
.value
;
6694 off
= sym
->st_value
;
6695 off
+= rel
->r_addend
;
6696 BFD_ASSERT (off
% 8 == 0);
6697 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6698 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6699 if (toc_symndx
!= NULL
)
6700 *toc_symndx
= r_symndx
;
6701 if (toc_addend
!= NULL
)
6702 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6703 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6705 if ((h
== NULL
|| is_static_defined (h
))
6706 && (next_r
== -1 || next_r
== -2))
6711 /* Find (or create) an entry in the tocsave hash table. */
6713 static struct tocsave_entry
*
6714 tocsave_find (struct ppc_link_hash_table
*htab
,
6715 enum insert_option insert
,
6716 Elf_Internal_Sym
**local_syms
,
6717 const Elf_Internal_Rela
*irela
,
6720 unsigned long r_indx
;
6721 struct elf_link_hash_entry
*h
;
6722 Elf_Internal_Sym
*sym
;
6723 struct tocsave_entry ent
, *p
;
6725 struct tocsave_entry
**slot
;
6727 r_indx
= ELF64_R_SYM (irela
->r_info
);
6728 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
6730 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
6733 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
6738 ent
.offset
= h
->root
.u
.def
.value
;
6740 ent
.offset
= sym
->st_value
;
6741 ent
.offset
+= irela
->r_addend
;
6743 hash
= tocsave_htab_hash (&ent
);
6744 slot
= ((struct tocsave_entry
**)
6745 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
6751 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
6760 /* Adjust all global syms defined in opd sections. In gcc generated
6761 code for the old ABI, these will already have been done. */
6764 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6766 struct ppc_link_hash_entry
*eh
;
6768 struct _opd_sec_data
*opd
;
6770 if (h
->root
.type
== bfd_link_hash_indirect
)
6773 if (h
->root
.type
!= bfd_link_hash_defined
6774 && h
->root
.type
!= bfd_link_hash_defweak
)
6777 eh
= (struct ppc_link_hash_entry
*) h
;
6778 if (eh
->adjust_done
)
6781 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6782 opd
= get_opd_info (sym_sec
);
6783 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6785 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
6788 /* This entry has been deleted. */
6789 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6792 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6793 if (discarded_section (dsec
))
6795 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6799 eh
->elf
.root
.u
.def
.value
= 0;
6800 eh
->elf
.root
.u
.def
.section
= dsec
;
6803 eh
->elf
.root
.u
.def
.value
+= adjust
;
6804 eh
->adjust_done
= 1;
6809 /* Handles decrementing dynamic reloc counts for the reloc specified by
6810 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
6811 have already been determined. */
6814 dec_dynrel_count (bfd_vma r_info
,
6816 struct bfd_link_info
*info
,
6817 Elf_Internal_Sym
**local_syms
,
6818 struct elf_link_hash_entry
*h
,
6819 Elf_Internal_Sym
*sym
)
6821 enum elf_ppc64_reloc_type r_type
;
6822 asection
*sym_sec
= NULL
;
6824 /* Can this reloc be dynamic? This switch, and later tests here
6825 should be kept in sync with the code in check_relocs. */
6826 r_type
= ELF64_R_TYPE (r_info
);
6833 case R_PPC64_TOC16_DS
:
6834 case R_PPC64_TOC16_LO
:
6835 case R_PPC64_TOC16_HI
:
6836 case R_PPC64_TOC16_HA
:
6837 case R_PPC64_TOC16_LO_DS
:
6842 case R_PPC64_TPREL16
:
6843 case R_PPC64_TPREL16_LO
:
6844 case R_PPC64_TPREL16_HI
:
6845 case R_PPC64_TPREL16_HA
:
6846 case R_PPC64_TPREL16_DS
:
6847 case R_PPC64_TPREL16_LO_DS
:
6848 case R_PPC64_TPREL16_HIGH
:
6849 case R_PPC64_TPREL16_HIGHA
:
6850 case R_PPC64_TPREL16_HIGHER
:
6851 case R_PPC64_TPREL16_HIGHERA
:
6852 case R_PPC64_TPREL16_HIGHEST
:
6853 case R_PPC64_TPREL16_HIGHESTA
:
6854 case R_PPC64_TPREL64
:
6855 case R_PPC64_TPREL34
:
6856 case R_PPC64_DTPMOD64
:
6857 case R_PPC64_DTPREL64
:
6858 case R_PPC64_ADDR64
:
6862 case R_PPC64_ADDR14
:
6863 case R_PPC64_ADDR14_BRNTAKEN
:
6864 case R_PPC64_ADDR14_BRTAKEN
:
6865 case R_PPC64_ADDR16
:
6866 case R_PPC64_ADDR16_DS
:
6867 case R_PPC64_ADDR16_HA
:
6868 case R_PPC64_ADDR16_HI
:
6869 case R_PPC64_ADDR16_HIGH
:
6870 case R_PPC64_ADDR16_HIGHA
:
6871 case R_PPC64_ADDR16_HIGHER
:
6872 case R_PPC64_ADDR16_HIGHERA
:
6873 case R_PPC64_ADDR16_HIGHEST
:
6874 case R_PPC64_ADDR16_HIGHESTA
:
6875 case R_PPC64_ADDR16_LO
:
6876 case R_PPC64_ADDR16_LO_DS
:
6877 case R_PPC64_ADDR24
:
6878 case R_PPC64_ADDR32
:
6879 case R_PPC64_UADDR16
:
6880 case R_PPC64_UADDR32
:
6881 case R_PPC64_UADDR64
:
6884 case R_PPC64_D34_LO
:
6885 case R_PPC64_D34_HI30
:
6886 case R_PPC64_D34_HA30
:
6887 case R_PPC64_ADDR16_HIGHER34
:
6888 case R_PPC64_ADDR16_HIGHERA34
:
6889 case R_PPC64_ADDR16_HIGHEST34
:
6890 case R_PPC64_ADDR16_HIGHESTA34
:
6895 if (local_syms
!= NULL
)
6897 unsigned long r_symndx
;
6898 bfd
*ibfd
= sec
->owner
;
6900 r_symndx
= ELF64_R_SYM (r_info
);
6901 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6906 && (h
->root
.type
== bfd_link_hash_defweak
6907 || !h
->def_regular
))
6909 && !bfd_link_executable (info
)
6910 && !SYMBOLIC_BIND (info
, h
))
6911 || (bfd_link_pic (info
)
6912 && must_be_dyn_reloc (info
, r_type
))
6913 || (!bfd_link_pic (info
)
6915 ? h
->type
== STT_GNU_IFUNC
6916 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
6923 struct elf_dyn_relocs
*p
;
6924 struct elf_dyn_relocs
**pp
;
6925 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6927 /* elf_gc_sweep may have already removed all dyn relocs associated
6928 with local syms for a given section. Also, symbol flags are
6929 changed by elf_gc_sweep_symbol, confusing the test above. Don't
6930 report a dynreloc miscount. */
6931 if (*pp
== NULL
&& info
->gc_sections
)
6934 while ((p
= *pp
) != NULL
)
6938 if (!must_be_dyn_reloc (info
, r_type
))
6950 struct ppc_dyn_relocs
*p
;
6951 struct ppc_dyn_relocs
**pp
;
6953 bfd_boolean is_ifunc
;
6955 if (local_syms
== NULL
)
6956 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6957 if (sym_sec
== NULL
)
6960 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6961 pp
= (struct ppc_dyn_relocs
**) vpp
;
6963 if (*pp
== NULL
&& info
->gc_sections
)
6966 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
6967 while ((p
= *pp
) != NULL
)
6969 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
6980 /* xgettext:c-format */
6981 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
6983 bfd_set_error (bfd_error_bad_value
);
6987 /* Remove unused Official Procedure Descriptor entries. Currently we
6988 only remove those associated with functions in discarded link-once
6989 sections, or weakly defined functions that have been overridden. It
6990 would be possible to remove many more entries for statically linked
6994 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
6997 bfd_boolean some_edited
= FALSE
;
6998 asection
*need_pad
= NULL
;
6999 struct ppc_link_hash_table
*htab
;
7001 htab
= ppc_hash_table (info
);
7005 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7008 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7009 Elf_Internal_Shdr
*symtab_hdr
;
7010 Elf_Internal_Sym
*local_syms
;
7011 struct _opd_sec_data
*opd
;
7012 bfd_boolean need_edit
, add_aux_fields
, broken
;
7013 bfd_size_type cnt_16b
= 0;
7015 if (!is_ppc64_elf (ibfd
))
7018 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7019 if (sec
== NULL
|| sec
->size
== 0)
7022 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7025 if (sec
->output_section
== bfd_abs_section_ptr
)
7028 /* Look through the section relocs. */
7029 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7033 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7035 /* Read the relocations. */
7036 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7038 if (relstart
== NULL
)
7041 /* First run through the relocs to check they are sane, and to
7042 determine whether we need to edit this opd section. */
7046 relend
= relstart
+ sec
->reloc_count
;
7047 for (rel
= relstart
; rel
< relend
; )
7049 enum elf_ppc64_reloc_type r_type
;
7050 unsigned long r_symndx
;
7052 struct elf_link_hash_entry
*h
;
7053 Elf_Internal_Sym
*sym
;
7056 /* .opd contains an array of 16 or 24 byte entries. We're
7057 only interested in the reloc pointing to a function entry
7059 offset
= rel
->r_offset
;
7060 if (rel
+ 1 == relend
7061 || rel
[1].r_offset
!= offset
+ 8)
7063 /* If someone messes with .opd alignment then after a
7064 "ld -r" we might have padding in the middle of .opd.
7065 Also, there's nothing to prevent someone putting
7066 something silly in .opd with the assembler. No .opd
7067 optimization for them! */
7070 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7075 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7076 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7079 /* xgettext:c-format */
7080 (_("%pB: unexpected reloc type %u in .opd section"),
7086 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7087 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7091 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7093 const char *sym_name
;
7095 sym_name
= h
->root
.root
.string
;
7097 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7101 /* xgettext:c-format */
7102 (_("%pB: undefined sym `%s' in .opd section"),
7108 /* opd entries are always for functions defined in the
7109 current input bfd. If the symbol isn't defined in the
7110 input bfd, then we won't be using the function in this
7111 bfd; It must be defined in a linkonce section in another
7112 bfd, or is weak. It's also possible that we are
7113 discarding the function due to a linker script /DISCARD/,
7114 which we test for via the output_section. */
7115 if (sym_sec
->owner
!= ibfd
7116 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7120 if (rel
+ 1 == relend
7121 || (rel
+ 2 < relend
7122 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7127 if (sec
->size
== offset
+ 24)
7132 if (sec
->size
== offset
+ 16)
7139 else if (rel
+ 1 < relend
7140 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7141 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7143 if (rel
[0].r_offset
== offset
+ 16)
7145 else if (rel
[0].r_offset
!= offset
+ 24)
7152 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7154 if (!broken
&& (need_edit
|| add_aux_fields
))
7156 Elf_Internal_Rela
*write_rel
;
7157 Elf_Internal_Shdr
*rel_hdr
;
7158 bfd_byte
*rptr
, *wptr
;
7159 bfd_byte
*new_contents
;
7162 new_contents
= NULL
;
7163 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7164 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7165 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7166 if (opd
->adjust
== NULL
)
7169 /* This seems a waste of time as input .opd sections are all
7170 zeros as generated by gcc, but I suppose there's no reason
7171 this will always be so. We might start putting something in
7172 the third word of .opd entries. */
7173 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7176 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7181 if (local_syms
!= NULL
7182 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7184 if (elf_section_data (sec
)->relocs
!= relstart
)
7188 sec
->contents
= loc
;
7189 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7192 elf_section_data (sec
)->relocs
= relstart
;
7194 new_contents
= sec
->contents
;
7197 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7198 if (new_contents
== NULL
)
7202 wptr
= new_contents
;
7203 rptr
= sec
->contents
;
7204 write_rel
= relstart
;
7205 for (rel
= relstart
; rel
< relend
; )
7207 unsigned long r_symndx
;
7209 struct elf_link_hash_entry
*h
;
7210 struct ppc_link_hash_entry
*fdh
= NULL
;
7211 Elf_Internal_Sym
*sym
;
7213 Elf_Internal_Rela
*next_rel
;
7216 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7217 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7222 if (next_rel
+ 1 == relend
7223 || (next_rel
+ 2 < relend
7224 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7227 /* See if the .opd entry is full 24 byte or
7228 16 byte (with fd_aux entry overlapped with next
7231 if (next_rel
== relend
)
7233 if (sec
->size
== rel
->r_offset
+ 16)
7236 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7240 && h
->root
.root
.string
[0] == '.')
7242 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
7245 fdh
= ppc_follow_link (fdh
);
7246 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
7247 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7252 skip
= (sym_sec
->owner
!= ibfd
7253 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7256 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7258 /* Arrange for the function descriptor sym
7260 fdh
->elf
.root
.u
.def
.value
= 0;
7261 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7263 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7265 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7270 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7274 if (++rel
== next_rel
)
7277 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7278 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7285 /* We'll be keeping this opd entry. */
7290 /* Redefine the function descriptor symbol to
7291 this location in the opd section. It is
7292 necessary to update the value here rather
7293 than using an array of adjustments as we do
7294 for local symbols, because various places
7295 in the generic ELF code use the value
7296 stored in u.def.value. */
7297 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
7298 fdh
->adjust_done
= 1;
7301 /* Local syms are a bit tricky. We could
7302 tweak them as they can be cached, but
7303 we'd need to look through the local syms
7304 for the function descriptor sym which we
7305 don't have at the moment. So keep an
7306 array of adjustments. */
7307 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
7308 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
7311 memcpy (wptr
, rptr
, opd_ent_size
);
7312 wptr
+= opd_ent_size
;
7313 if (add_aux_fields
&& opd_ent_size
== 16)
7315 memset (wptr
, '\0', 8);
7319 /* We need to adjust any reloc offsets to point to the
7321 for ( ; rel
!= next_rel
; ++rel
)
7323 rel
->r_offset
+= adjust
;
7324 if (write_rel
!= rel
)
7325 memcpy (write_rel
, rel
, sizeof (*rel
));
7330 rptr
+= opd_ent_size
;
7333 sec
->size
= wptr
- new_contents
;
7334 sec
->reloc_count
= write_rel
- relstart
;
7337 free (sec
->contents
);
7338 sec
->contents
= new_contents
;
7341 /* Fudge the header size too, as this is used later in
7342 elf_bfd_final_link if we are emitting relocs. */
7343 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7344 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7347 else if (elf_section_data (sec
)->relocs
!= relstart
)
7350 if (local_syms
!= NULL
7351 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7353 if (!info
->keep_memory
)
7356 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7361 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7363 /* If we are doing a final link and the last .opd entry is just 16 byte
7364 long, add a 8 byte padding after it. */
7365 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7369 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7371 BFD_ASSERT (need_pad
->size
> 0);
7373 p
= bfd_malloc (need_pad
->size
+ 8);
7377 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7378 p
, 0, need_pad
->size
))
7381 need_pad
->contents
= p
;
7382 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7386 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7390 need_pad
->contents
= p
;
7393 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7394 need_pad
->size
+= 8;
7400 /* Analyze inline PLT call relocations to see whether calls to locally
7401 defined functions can be converted to direct calls. */
7404 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7406 struct ppc_link_hash_table
*htab
;
7409 bfd_vma low_vma
, high_vma
, limit
;
7411 htab
= ppc_hash_table (info
);
7415 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7416 reduced somewhat to cater for possible stubs that might be added
7417 between the call and its destination. */
7418 if (htab
->params
->group_size
< 0)
7420 limit
= -htab
->params
->group_size
;
7426 limit
= htab
->params
->group_size
;
7433 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7434 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7436 if (low_vma
> sec
->vma
)
7438 if (high_vma
< sec
->vma
+ sec
->size
)
7439 high_vma
= sec
->vma
+ sec
->size
;
7442 /* If a "bl" can reach anywhere in local code sections, then we can
7443 convert all inline PLT sequences to direct calls when the symbol
7445 if (high_vma
- low_vma
< limit
)
7447 htab
->can_convert_all_inline_plt
= 1;
7451 /* Otherwise, go looking through relocs for cases where a direct
7452 call won't reach. Mark the symbol on any such reloc to disable
7453 the optimization and keep the PLT entry as it seems likely that
7454 this will be better than creating trampolines. Note that this
7455 will disable the optimization for all inline PLT calls to a
7456 particular symbol, not just those that won't reach. The
7457 difficulty in doing a more precise optimization is that the
7458 linker needs to make a decision depending on whether a
7459 particular R_PPC64_PLTCALL insn can be turned into a direct
7460 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7461 the sequence, and there is nothing that ties those relocs
7462 together except their symbol. */
7464 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7466 Elf_Internal_Shdr
*symtab_hdr
;
7467 Elf_Internal_Sym
*local_syms
;
7469 if (!is_ppc64_elf (ibfd
))
7473 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7475 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7476 if (ppc64_elf_section_data (sec
)->has_pltcall
7477 && !bfd_is_abs_section (sec
->output_section
))
7479 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7481 /* Read the relocations. */
7482 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7484 if (relstart
== NULL
)
7487 relend
= relstart
+ sec
->reloc_count
;
7488 for (rel
= relstart
; rel
< relend
; )
7490 enum elf_ppc64_reloc_type r_type
;
7491 unsigned long r_symndx
;
7493 struct elf_link_hash_entry
*h
;
7494 Elf_Internal_Sym
*sym
;
7495 unsigned char *tls_maskp
;
7497 r_type
= ELF64_R_TYPE (rel
->r_info
);
7498 if (r_type
!= R_PPC64_PLTCALL
7499 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
7502 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7503 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7506 if (elf_section_data (sec
)->relocs
!= relstart
)
7508 if (local_syms
!= NULL
7509 && symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7514 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7518 to
= h
->root
.u
.def
.value
;
7521 to
+= (rel
->r_addend
7522 + sym_sec
->output_offset
7523 + sym_sec
->output_section
->vma
);
7524 from
= (rel
->r_offset
7525 + sec
->output_offset
7526 + sec
->output_section
->vma
);
7527 if (to
- from
+ limit
< 2 * limit
7528 && !(r_type
== R_PPC64_PLTCALL_NOTOC
7529 && (((h
? h
->other
: sym
->st_other
)
7530 & STO_PPC64_LOCAL_MASK
)
7531 > 1 << STO_PPC64_LOCAL_BIT
)))
7532 *tls_maskp
&= ~PLT_KEEP
;
7535 if (elf_section_data (sec
)->relocs
!= relstart
)
7539 if (local_syms
!= NULL
7540 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7542 if (!info
->keep_memory
)
7545 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7552 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7555 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7557 struct ppc_link_hash_table
*htab
;
7559 htab
= ppc_hash_table (info
);
7563 if (abiversion (info
->output_bfd
) == 1)
7566 if (htab
->params
->no_multi_toc
)
7567 htab
->do_multi_toc
= 0;
7568 else if (!htab
->do_multi_toc
)
7569 htab
->params
->no_multi_toc
= 1;
7571 /* Default to --no-plt-localentry, as this option can cause problems
7572 with symbol interposition. For example, glibc libpthread.so and
7573 libc.so duplicate many pthread symbols, with a fallback
7574 implementation in libc.so. In some cases the fallback does more
7575 work than the pthread implementation. __pthread_condattr_destroy
7576 is one such symbol: the libpthread.so implementation is
7577 localentry:0 while the libc.so implementation is localentry:8.
7578 An app that "cleverly" uses dlopen to only load necessary
7579 libraries at runtime may omit loading libpthread.so when not
7580 running multi-threaded, which then results in the libc.so
7581 fallback symbols being used and ld.so complaining. Now there
7582 are workarounds in ld (see non_zero_localentry) to detect the
7583 pthread situation, but that may not be the only case where
7584 --plt-localentry can cause trouble. */
7585 if (htab
->params
->plt_localentry0
< 0)
7586 htab
->params
->plt_localentry0
= 0;
7587 if (htab
->params
->plt_localentry0
7588 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7589 FALSE
, FALSE
, FALSE
) == NULL
)
7591 (_("warning: --plt-localentry is especially dangerous without "
7592 "ld.so support to detect ABI violations"));
7594 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7595 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7596 FALSE
, FALSE
, TRUE
));
7597 /* Move dynamic linking info to the function descriptor sym. */
7598 if (htab
->tls_get_addr
!= NULL
)
7599 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7600 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7601 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7602 FALSE
, FALSE
, TRUE
));
7603 if (htab
->params
->tls_get_addr_opt
)
7605 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7607 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7608 FALSE
, FALSE
, TRUE
);
7610 func_desc_adjust (opt
, info
);
7611 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7612 FALSE
, FALSE
, TRUE
);
7614 && (opt_fd
->root
.type
== bfd_link_hash_defined
7615 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7617 /* If glibc supports an optimized __tls_get_addr call stub,
7618 signalled by the presence of __tls_get_addr_opt, and we'll
7619 be calling __tls_get_addr via a plt call stub, then
7620 make __tls_get_addr point to __tls_get_addr_opt. */
7621 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7622 if (htab
->elf
.dynamic_sections_created
7624 && (tga_fd
->type
== STT_FUNC
7625 || tga_fd
->needs_plt
)
7626 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7627 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
7629 struct plt_entry
*ent
;
7631 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7632 if (ent
->plt
.refcount
> 0)
7636 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7637 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7638 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7640 if (opt_fd
->dynindx
!= -1)
7642 /* Use __tls_get_addr_opt in dynamic relocations. */
7643 opt_fd
->dynindx
= -1;
7644 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7645 opt_fd
->dynstr_index
);
7646 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7649 htab
->tls_get_addr_fd
7650 = (struct ppc_link_hash_entry
*) opt_fd
;
7651 tga
= &htab
->tls_get_addr
->elf
;
7652 if (opt
!= NULL
&& tga
!= NULL
)
7654 tga
->root
.type
= bfd_link_hash_indirect
;
7655 tga
->root
.u
.i
.link
= &opt
->root
;
7656 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7658 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7660 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7662 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7663 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7664 if (htab
->tls_get_addr
!= NULL
)
7666 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7667 htab
->tls_get_addr
->is_func
= 1;
7672 else if (htab
->params
->tls_get_addr_opt
< 0)
7673 htab
->params
->tls_get_addr_opt
= 0;
7675 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7678 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7682 branch_reloc_hash_match (const bfd
*ibfd
,
7683 const Elf_Internal_Rela
*rel
,
7684 const struct ppc_link_hash_entry
*hash1
,
7685 const struct ppc_link_hash_entry
*hash2
)
7687 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7688 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7689 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7691 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7693 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7694 struct elf_link_hash_entry
*h
;
7696 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7697 h
= elf_follow_link (h
);
7698 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7704 /* Run through all the TLS relocs looking for optimization
7705 opportunities. The linker has been hacked (see ppc64elf.em) to do
7706 a preliminary section layout so that we know the TLS segment
7707 offsets. We can't optimize earlier because some optimizations need
7708 to know the tp offset, and we need to optimize before allocating
7709 dynamic relocations. */
7712 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7716 struct ppc_link_hash_table
*htab
;
7717 unsigned char *toc_ref
;
7720 if (!bfd_link_executable (info
))
7723 htab
= ppc_hash_table (info
);
7727 /* Make two passes over the relocs. On the first pass, mark toc
7728 entries involved with tls relocs, and check that tls relocs
7729 involved in setting up a tls_get_addr call are indeed followed by
7730 such a call. If they are not, we can't do any tls optimization.
7731 On the second pass twiddle tls_mask flags to notify
7732 relocate_section that optimization can be done, and adjust got
7733 and plt refcounts. */
7735 for (pass
= 0; pass
< 2; ++pass
)
7736 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7738 Elf_Internal_Sym
*locsyms
= NULL
;
7739 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7741 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7742 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7744 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7745 bfd_boolean found_tls_get_addr_arg
= 0;
7747 /* Read the relocations. */
7748 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7750 if (relstart
== NULL
)
7756 relend
= relstart
+ sec
->reloc_count
;
7757 for (rel
= relstart
; rel
< relend
; rel
++)
7759 enum elf_ppc64_reloc_type r_type
;
7760 unsigned long r_symndx
;
7761 struct elf_link_hash_entry
*h
;
7762 Elf_Internal_Sym
*sym
;
7764 unsigned char *tls_mask
;
7765 unsigned int tls_set
, tls_clear
, tls_type
= 0;
7767 bfd_boolean ok_tprel
, is_local
;
7768 long toc_ref_index
= 0;
7769 int expecting_tls_get_addr
= 0;
7770 bfd_boolean ret
= FALSE
;
7772 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7773 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7777 if (elf_section_data (sec
)->relocs
!= relstart
)
7779 if (toc_ref
!= NULL
)
7782 && (elf_symtab_hdr (ibfd
).contents
7783 != (unsigned char *) locsyms
))
7790 if (h
->root
.type
== bfd_link_hash_defined
7791 || h
->root
.type
== bfd_link_hash_defweak
)
7792 value
= h
->root
.u
.def
.value
;
7793 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7797 found_tls_get_addr_arg
= 0;
7802 /* Symbols referenced by TLS relocs must be of type
7803 STT_TLS. So no need for .opd local sym adjust. */
7804 value
= sym
->st_value
;
7807 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
7811 && h
->root
.type
== bfd_link_hash_undefweak
)
7813 else if (sym_sec
!= NULL
7814 && sym_sec
->output_section
!= NULL
)
7816 value
+= sym_sec
->output_offset
;
7817 value
+= sym_sec
->output_section
->vma
;
7818 value
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7819 /* Note that even though the prefix insns
7820 allow a 1<<33 offset we use the same test
7821 as for addis;addi. There may be a mix of
7822 pcrel and non-pcrel code and the decision
7823 to optimise is per symbol, not per TLS
7825 ok_tprel
= value
+ 0x80008000ULL
< 1ULL << 32;
7829 r_type
= ELF64_R_TYPE (rel
->r_info
);
7830 /* If this section has old-style __tls_get_addr calls
7831 without marker relocs, then check that each
7832 __tls_get_addr call reloc is preceded by a reloc
7833 that conceivably belongs to the __tls_get_addr arg
7834 setup insn. If we don't find matching arg setup
7835 relocs, don't do any tls optimization. */
7837 && sec
->nomark_tls_get_addr
7839 && (h
== &htab
->tls_get_addr
->elf
7840 || h
== &htab
->tls_get_addr_fd
->elf
)
7841 && !found_tls_get_addr_arg
7842 && is_branch_reloc (r_type
))
7844 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7845 "TLS optimization disabled\n"),
7846 ibfd
, sec
, rel
->r_offset
);
7851 found_tls_get_addr_arg
= 0;
7854 case R_PPC64_GOT_TLSLD16
:
7855 case R_PPC64_GOT_TLSLD16_LO
:
7856 case R_PPC64_GOT_TLSLD34
:
7857 expecting_tls_get_addr
= 1;
7858 found_tls_get_addr_arg
= 1;
7861 case R_PPC64_GOT_TLSLD16_HI
:
7862 case R_PPC64_GOT_TLSLD16_HA
:
7863 /* These relocs should never be against a symbol
7864 defined in a shared lib. Leave them alone if
7865 that turns out to be the case. */
7872 tls_type
= TLS_TLS
| TLS_LD
;
7875 case R_PPC64_GOT_TLSGD16
:
7876 case R_PPC64_GOT_TLSGD16_LO
:
7877 case R_PPC64_GOT_TLSGD34
:
7878 expecting_tls_get_addr
= 1;
7879 found_tls_get_addr_arg
= 1;
7882 case R_PPC64_GOT_TLSGD16_HI
:
7883 case R_PPC64_GOT_TLSGD16_HA
:
7889 tls_set
= TLS_TLS
| TLS_GDIE
;
7891 tls_type
= TLS_TLS
| TLS_GD
;
7894 case R_PPC64_GOT_TPREL34
:
7895 case R_PPC64_GOT_TPREL16_DS
:
7896 case R_PPC64_GOT_TPREL16_LO_DS
:
7897 case R_PPC64_GOT_TPREL16_HI
:
7898 case R_PPC64_GOT_TPREL16_HA
:
7903 tls_clear
= TLS_TPREL
;
7904 tls_type
= TLS_TLS
| TLS_TPREL
;
7914 if (rel
+ 1 < relend
7915 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
7918 && (ELF64_R_TYPE (rel
[1].r_info
)
7920 && (ELF64_R_TYPE (rel
[1].r_info
)
7921 != R_PPC64_PLTSEQ_NOTOC
))
7923 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
7924 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
7929 struct plt_entry
*ent
= NULL
;
7931 for (ent
= h
->plt
.plist
;
7934 if (ent
->addend
== rel
[1].r_addend
)
7938 && ent
->plt
.refcount
> 0)
7939 ent
->plt
.refcount
-= 1;
7944 found_tls_get_addr_arg
= 1;
7949 case R_PPC64_TOC16_LO
:
7950 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7953 /* Mark this toc entry as referenced by a TLS
7954 code sequence. We can do that now in the
7955 case of R_PPC64_TLS, and after checking for
7956 tls_get_addr for the TOC16 relocs. */
7957 if (toc_ref
== NULL
)
7959 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7960 if (toc_ref
== NULL
)
7964 value
= h
->root
.u
.def
.value
;
7966 value
= sym
->st_value
;
7967 value
+= rel
->r_addend
;
7970 BFD_ASSERT (value
< toc
->size
7971 && toc
->output_offset
% 8 == 0);
7972 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7973 if (r_type
== R_PPC64_TLS
7974 || r_type
== R_PPC64_TLSGD
7975 || r_type
== R_PPC64_TLSLD
)
7977 toc_ref
[toc_ref_index
] = 1;
7981 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7986 expecting_tls_get_addr
= 2;
7989 case R_PPC64_TPREL64
:
7993 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7998 tls_set
= TLS_EXPLICIT
;
7999 tls_clear
= TLS_TPREL
;
8004 case R_PPC64_DTPMOD64
:
8008 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8010 if (rel
+ 1 < relend
8012 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8013 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8017 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8020 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_GDIE
;
8029 tls_set
= TLS_EXPLICIT
;
8040 if (!expecting_tls_get_addr
8041 || !sec
->nomark_tls_get_addr
)
8044 if (rel
+ 1 < relend
8045 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8047 htab
->tls_get_addr_fd
))
8049 if (expecting_tls_get_addr
== 2)
8051 /* Check for toc tls entries. */
8052 unsigned char *toc_tls
;
8055 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8060 if (toc_tls
!= NULL
)
8062 if ((*toc_tls
& TLS_TLS
) != 0
8063 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8064 found_tls_get_addr_arg
= 1;
8066 toc_ref
[toc_ref_index
] = 1;
8072 /* Uh oh, we didn't find the expected call. We
8073 could just mark this symbol to exclude it
8074 from tls optimization but it's safer to skip
8075 the entire optimization. */
8076 /* xgettext:c-format */
8077 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8078 "TLS optimization disabled\n"),
8079 ibfd
, sec
, rel
->r_offset
);
8084 /* If we don't have old-style __tls_get_addr calls
8085 without TLSGD/TLSLD marker relocs, and we haven't
8086 found a new-style __tls_get_addr call with a
8087 marker for this symbol, then we either have a
8088 broken object file or an -mlongcall style
8089 indirect call to __tls_get_addr without a marker.
8090 Disable optimization in this case. */
8091 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8092 && (tls_set
& TLS_EXPLICIT
) == 0
8093 && !sec
->nomark_tls_get_addr
8094 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8095 != (TLS_TLS
| TLS_MARK
)))
8098 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
8100 struct plt_entry
*ent
= NULL
;
8102 if (htab
->tls_get_addr
!= NULL
)
8103 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8106 if (ent
->addend
== 0)
8109 if (ent
== NULL
&& htab
->tls_get_addr_fd
!= NULL
)
8110 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8113 if (ent
->addend
== 0)
8117 && ent
->plt
.refcount
> 0)
8118 ent
->plt
.refcount
-= 1;
8124 if ((tls_set
& TLS_EXPLICIT
) == 0)
8126 struct got_entry
*ent
;
8128 /* Adjust got entry for this reloc. */
8132 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8134 for (; ent
!= NULL
; ent
= ent
->next
)
8135 if (ent
->addend
== rel
->r_addend
8136 && ent
->owner
== ibfd
8137 && ent
->tls_type
== tls_type
)
8144 /* We managed to get rid of a got entry. */
8145 if (ent
->got
.refcount
> 0)
8146 ent
->got
.refcount
-= 1;
8151 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8152 we'll lose one or two dyn relocs. */
8153 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8157 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8159 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8165 *tls_mask
|= tls_set
& 0xff;
8166 *tls_mask
&= ~tls_clear
;
8169 if (elf_section_data (sec
)->relocs
!= relstart
)
8174 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8176 if (!info
->keep_memory
)
8179 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8183 if (toc_ref
!= NULL
)
8185 htab
->do_tls_opt
= 1;
8189 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8190 the values of any global symbols in a toc section that has been
8191 edited. Globals in toc sections should be a rarity, so this function
8192 sets a flag if any are found in toc sections other than the one just
8193 edited, so that further hash table traversals can be avoided. */
8195 struct adjust_toc_info
8198 unsigned long *skip
;
8199 bfd_boolean global_toc_syms
;
8202 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8205 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8207 struct ppc_link_hash_entry
*eh
;
8208 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8211 if (h
->root
.type
!= bfd_link_hash_defined
8212 && h
->root
.type
!= bfd_link_hash_defweak
)
8215 eh
= (struct ppc_link_hash_entry
*) h
;
8216 if (eh
->adjust_done
)
8219 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8221 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8222 i
= toc_inf
->toc
->rawsize
>> 3;
8224 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8226 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8229 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8232 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8233 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8236 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8237 eh
->adjust_done
= 1;
8239 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8240 toc_inf
->global_toc_syms
= TRUE
;
8245 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8246 on a _LO variety toc/got reloc. */
8249 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8251 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8252 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8253 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8254 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8255 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8256 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8257 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8258 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8259 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8260 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8261 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8262 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8263 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8264 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8265 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8266 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8267 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8268 /* Exclude lfqu by testing reloc. If relocs are ever
8269 defined for the reduced D field in psq_lu then those
8270 will need testing too. */
8271 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8272 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8274 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8275 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8276 /* Exclude stfqu. psq_stu as above for psq_lu. */
8277 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8278 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8279 && (insn
& 1) == 0));
8282 /* PCREL_OPT in one instance flags to the linker that a pair of insns:
8283 pld ra,symbol@got@pcrel
8284 load/store rt,off(ra)
8287 load/store rt,off(ra)
8288 may be translated to
8289 pload/pstore rt,symbol+off@pcrel
8291 This function returns true if the optimization is possible, placing
8292 the prefix insn in *PINSN1, a NOP in *PINSN2 and the offset in *POFF.
8294 On entry to this function, the linker has already determined that
8295 the pld can be replaced with pla: *PINSN1 is that pla insn,
8296 while *PINSN2 is the second instruction. */
8299 xlate_pcrel_opt (uint64_t *pinsn1
, uint64_t *pinsn2
, bfd_signed_vma
*poff
)
8301 uint64_t insn1
= *pinsn1
;
8302 uint64_t insn2
= *pinsn2
;
8305 if ((insn2
& (63ULL << 58)) == 1ULL << 58)
8307 /* Check that regs match. */
8308 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8311 /* P8LS or PMLS form, non-pcrel. */
8312 if ((insn2
& (-1ULL << 50) & ~(1ULL << 56)) != (1ULL << 58))
8315 *pinsn1
= (insn2
& ~(31 << 16) & ~0x3ffff0000ffffULL
) | (1ULL << 52);
8317 off
= ((insn2
>> 16) & 0x3ffff0000ULL
) | (insn2
& 0xffff);
8318 *poff
= (off
^ 0x200000000ULL
) - 0x200000000ULL
;
8324 /* Check that regs match. */
8325 if (((insn2
>> 16) & 31) != ((insn1
>> 21) & 31))
8328 switch ((insn2
>> 26) & 63)
8344 /* These are the PMLS cases, where we just need to tack a prefix
8346 insn1
= ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
8347 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8348 off
= insn2
& 0xffff;
8351 case 58: /* lwa, ld */
8352 if ((insn2
& 1) != 0)
8354 insn1
= ((1ULL << 58) | (1ULL << 52)
8355 | (insn2
& 2 ? 41ULL << 26 : 57ULL << 26)
8356 | (insn2
& (31ULL << 21)));
8357 off
= insn2
& 0xfffc;
8360 case 57: /* lxsd, lxssp */
8361 if ((insn2
& 3) < 2)
8363 insn1
= ((1ULL << 58) | (1ULL << 52)
8364 | ((40ULL | (insn2
& 3)) << 26)
8365 | (insn2
& (31ULL << 21)));
8366 off
= insn2
& 0xfffc;
8369 case 61: /* stxsd, stxssp, lxv, stxv */
8370 if ((insn2
& 3) == 0)
8372 else if ((insn2
& 3) >= 2)
8374 insn1
= ((1ULL << 58) | (1ULL << 52)
8375 | ((44ULL | (insn2
& 3)) << 26)
8376 | (insn2
& (31ULL << 21)));
8377 off
= insn2
& 0xfffc;
8381 insn1
= ((1ULL << 58) | (1ULL << 52)
8382 | ((50ULL | (insn2
& 4) | ((insn2
& 8) >> 3)) << 26)
8383 | (insn2
& (31ULL << 21)));
8384 off
= insn2
& 0xfff0;
8389 insn1
= ((1ULL << 58) | (1ULL << 52)
8390 | (insn2
& ((63ULL << 26) | (31ULL << 21))));
8391 off
= insn2
& 0xffff;
8394 case 62: /* std, stq */
8395 if ((insn2
& 1) != 0)
8397 insn1
= ((1ULL << 58) | (1ULL << 52)
8398 | ((insn2
& 2) == 0 ? 61ULL << 26 : 60ULL << 26)
8399 | (insn2
& (31ULL << 21)));
8400 off
= insn2
& 0xfffc;
8405 *pinsn2
= (uint64_t) NOP
<< 32;
8406 *poff
= (off
^ 0x8000) - 0x8000;
8410 /* Examine all relocs referencing .toc sections in order to remove
8411 unused .toc entries. */
8414 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8417 struct adjust_toc_info toc_inf
;
8418 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8420 htab
->do_toc_opt
= 1;
8421 toc_inf
.global_toc_syms
= TRUE
;
8422 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8424 asection
*toc
, *sec
;
8425 Elf_Internal_Shdr
*symtab_hdr
;
8426 Elf_Internal_Sym
*local_syms
;
8427 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8428 unsigned long *skip
, *drop
;
8429 unsigned char *used
;
8430 unsigned char *keep
, last
, some_unused
;
8432 if (!is_ppc64_elf (ibfd
))
8435 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8438 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8439 || discarded_section (toc
))
8444 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8446 /* Look at sections dropped from the final link. */
8449 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8451 if (sec
->reloc_count
== 0
8452 || !discarded_section (sec
)
8453 || get_opd_info (sec
)
8454 || (sec
->flags
& SEC_ALLOC
) == 0
8455 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8458 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
8459 if (relstart
== NULL
)
8462 /* Run through the relocs to see which toc entries might be
8464 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8466 enum elf_ppc64_reloc_type r_type
;
8467 unsigned long r_symndx
;
8469 struct elf_link_hash_entry
*h
;
8470 Elf_Internal_Sym
*sym
;
8473 r_type
= ELF64_R_TYPE (rel
->r_info
);
8480 case R_PPC64_TOC16_LO
:
8481 case R_PPC64_TOC16_HI
:
8482 case R_PPC64_TOC16_HA
:
8483 case R_PPC64_TOC16_DS
:
8484 case R_PPC64_TOC16_LO_DS
:
8488 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8489 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8497 val
= h
->root
.u
.def
.value
;
8499 val
= sym
->st_value
;
8500 val
+= rel
->r_addend
;
8502 if (val
>= toc
->size
)
8505 /* Anything in the toc ought to be aligned to 8 bytes.
8506 If not, don't mark as unused. */
8512 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8517 skip
[val
>> 3] = ref_from_discarded
;
8520 if (elf_section_data (sec
)->relocs
!= relstart
)
8524 /* For largetoc loads of address constants, we can convert
8525 . addis rx,2,addr@got@ha
8526 . ld ry,addr@got@l(rx)
8528 . addis rx,2,addr@toc@ha
8529 . addi ry,rx,addr@toc@l
8530 when addr is within 2G of the toc pointer. This then means
8531 that the word storing "addr" in the toc is no longer needed. */
8533 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8534 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8535 && toc
->reloc_count
!= 0)
8537 /* Read toc relocs. */
8538 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8540 if (toc_relocs
== NULL
)
8543 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8545 enum elf_ppc64_reloc_type r_type
;
8546 unsigned long r_symndx
;
8548 struct elf_link_hash_entry
*h
;
8549 Elf_Internal_Sym
*sym
;
8552 r_type
= ELF64_R_TYPE (rel
->r_info
);
8553 if (r_type
!= R_PPC64_ADDR64
)
8556 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8557 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8562 || sym_sec
->output_section
== NULL
8563 || discarded_section (sym_sec
))
8566 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8571 if (h
->type
== STT_GNU_IFUNC
)
8573 val
= h
->root
.u
.def
.value
;
8577 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8579 val
= sym
->st_value
;
8581 val
+= rel
->r_addend
;
8582 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8584 /* We don't yet know the exact toc pointer value, but we
8585 know it will be somewhere in the toc section. Don't
8586 optimize if the difference from any possible toc
8587 pointer is outside [ff..f80008000, 7fff7fff]. */
8588 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8589 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8592 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8593 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8598 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8603 skip
[rel
->r_offset
>> 3]
8604 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8611 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8615 if (local_syms
!= NULL
8616 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8620 && elf_section_data (sec
)->relocs
!= relstart
)
8622 if (toc_relocs
!= NULL
8623 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8630 /* Now check all kept sections that might reference the toc.
8631 Check the toc itself last. */
8632 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8635 sec
= (sec
== toc
? NULL
8636 : sec
->next
== NULL
? toc
8637 : sec
->next
== toc
&& toc
->next
? toc
->next
8642 if (sec
->reloc_count
== 0
8643 || discarded_section (sec
)
8644 || get_opd_info (sec
)
8645 || (sec
->flags
& SEC_ALLOC
) == 0
8646 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8649 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8651 if (relstart
== NULL
)
8657 /* Mark toc entries referenced as used. */
8661 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8663 enum elf_ppc64_reloc_type r_type
;
8664 unsigned long r_symndx
;
8666 struct elf_link_hash_entry
*h
;
8667 Elf_Internal_Sym
*sym
;
8670 r_type
= ELF64_R_TYPE (rel
->r_info
);
8674 case R_PPC64_TOC16_LO
:
8675 case R_PPC64_TOC16_HI
:
8676 case R_PPC64_TOC16_HA
:
8677 case R_PPC64_TOC16_DS
:
8678 case R_PPC64_TOC16_LO_DS
:
8679 /* In case we're taking addresses of toc entries. */
8680 case R_PPC64_ADDR64
:
8687 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8688 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8699 val
= h
->root
.u
.def
.value
;
8701 val
= sym
->st_value
;
8702 val
+= rel
->r_addend
;
8704 if (val
>= toc
->size
)
8707 if ((skip
[val
>> 3] & can_optimize
) != 0)
8714 case R_PPC64_TOC16_HA
:
8717 case R_PPC64_TOC16_LO_DS
:
8718 off
= rel
->r_offset
;
8719 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
8720 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
8726 if ((opc
& (0x3f << 2)) == (58u << 2))
8731 /* Wrong sort of reloc, or not a ld. We may
8732 as well clear ref_from_discarded too. */
8739 /* For the toc section, we only mark as used if this
8740 entry itself isn't unused. */
8741 else if ((used
[rel
->r_offset
>> 3]
8742 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
8745 /* Do all the relocs again, to catch reference
8754 if (elf_section_data (sec
)->relocs
!= relstart
)
8758 /* Merge the used and skip arrays. Assume that TOC
8759 doublewords not appearing as either used or unused belong
8760 to an entry more than one doubleword in size. */
8761 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8762 drop
< skip
+ (toc
->size
+ 7) / 8;
8767 *drop
&= ~ref_from_discarded
;
8768 if ((*drop
& can_optimize
) != 0)
8772 else if ((*drop
& ref_from_discarded
) != 0)
8775 last
= ref_from_discarded
;
8785 bfd_byte
*contents
, *src
;
8787 Elf_Internal_Sym
*sym
;
8788 bfd_boolean local_toc_syms
= FALSE
;
8790 /* Shuffle the toc contents, and at the same time convert the
8791 skip array from booleans into offsets. */
8792 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8795 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8797 for (src
= contents
, off
= 0, drop
= skip
;
8798 src
< contents
+ toc
->size
;
8801 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8806 memcpy (src
- off
, src
, 8);
8810 toc
->rawsize
= toc
->size
;
8811 toc
->size
= src
- contents
- off
;
8813 /* Adjust addends for relocs against the toc section sym,
8814 and optimize any accesses we can. */
8815 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8817 if (sec
->reloc_count
== 0
8818 || discarded_section (sec
))
8821 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8823 if (relstart
== NULL
)
8826 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8828 enum elf_ppc64_reloc_type r_type
;
8829 unsigned long r_symndx
;
8831 struct elf_link_hash_entry
*h
;
8834 r_type
= ELF64_R_TYPE (rel
->r_info
);
8841 case R_PPC64_TOC16_LO
:
8842 case R_PPC64_TOC16_HI
:
8843 case R_PPC64_TOC16_HA
:
8844 case R_PPC64_TOC16_DS
:
8845 case R_PPC64_TOC16_LO_DS
:
8846 case R_PPC64_ADDR64
:
8850 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8851 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8859 val
= h
->root
.u
.def
.value
;
8862 val
= sym
->st_value
;
8864 local_toc_syms
= TRUE
;
8867 val
+= rel
->r_addend
;
8869 if (val
> toc
->rawsize
)
8871 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8873 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8875 Elf_Internal_Rela
*tocrel
8876 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8877 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8881 case R_PPC64_TOC16_HA
:
8882 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8885 case R_PPC64_TOC16_LO_DS
:
8886 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8890 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
8892 info
->callbacks
->einfo
8893 /* xgettext:c-format */
8894 (_("%H: %s references "
8895 "optimized away TOC entry\n"),
8896 ibfd
, sec
, rel
->r_offset
,
8897 ppc64_elf_howto_table
[r_type
]->name
);
8898 bfd_set_error (bfd_error_bad_value
);
8901 rel
->r_addend
= tocrel
->r_addend
;
8902 elf_section_data (sec
)->relocs
= relstart
;
8906 if (h
!= NULL
|| sym
->st_value
!= 0)
8909 rel
->r_addend
-= skip
[val
>> 3];
8910 elf_section_data (sec
)->relocs
= relstart
;
8913 if (elf_section_data (sec
)->relocs
!= relstart
)
8917 /* We shouldn't have local or global symbols defined in the TOC,
8918 but handle them anyway. */
8919 if (local_syms
!= NULL
)
8920 for (sym
= local_syms
;
8921 sym
< local_syms
+ symtab_hdr
->sh_info
;
8923 if (sym
->st_value
!= 0
8924 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8928 if (sym
->st_value
> toc
->rawsize
)
8929 i
= toc
->rawsize
>> 3;
8931 i
= sym
->st_value
>> 3;
8933 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8937 (_("%s defined on removed toc entry"),
8938 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8941 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8942 sym
->st_value
= (bfd_vma
) i
<< 3;
8945 sym
->st_value
-= skip
[i
];
8946 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8949 /* Adjust any global syms defined in this toc input section. */
8950 if (toc_inf
.global_toc_syms
)
8953 toc_inf
.skip
= skip
;
8954 toc_inf
.global_toc_syms
= FALSE
;
8955 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8959 if (toc
->reloc_count
!= 0)
8961 Elf_Internal_Shdr
*rel_hdr
;
8962 Elf_Internal_Rela
*wrel
;
8965 /* Remove unused toc relocs, and adjust those we keep. */
8966 if (toc_relocs
== NULL
)
8967 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8969 if (toc_relocs
== NULL
)
8973 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8974 if ((skip
[rel
->r_offset
>> 3]
8975 & (ref_from_discarded
| can_optimize
)) == 0)
8977 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8978 wrel
->r_info
= rel
->r_info
;
8979 wrel
->r_addend
= rel
->r_addend
;
8982 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8983 &local_syms
, NULL
, NULL
))
8986 elf_section_data (toc
)->relocs
= toc_relocs
;
8987 toc
->reloc_count
= wrel
- toc_relocs
;
8988 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8989 sz
= rel_hdr
->sh_entsize
;
8990 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8993 else if (toc_relocs
!= NULL
8994 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8997 if (local_syms
!= NULL
8998 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9000 if (!info
->keep_memory
)
9003 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9008 /* Look for cases where we can change an indirect GOT access to
9009 a GOT relative or PC relative access, possibly reducing the
9010 number of GOT entries. */
9011 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9014 Elf_Internal_Shdr
*symtab_hdr
;
9015 Elf_Internal_Sym
*local_syms
;
9016 Elf_Internal_Rela
*relstart
, *rel
;
9019 if (!is_ppc64_elf (ibfd
))
9022 if (!ppc64_elf_tdata (ibfd
)->has_optrel
)
9025 sec
= ppc64_elf_tdata (ibfd
)->got
;
9028 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
9031 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9033 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9035 if (sec
->reloc_count
== 0
9036 || !ppc64_elf_section_data (sec
)->has_optrel
9037 || discarded_section (sec
))
9040 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9042 if (relstart
== NULL
)
9045 if (local_syms
!= NULL
9046 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9050 && elf_section_data (sec
)->relocs
!= relstart
)
9055 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9057 enum elf_ppc64_reloc_type r_type
;
9058 unsigned long r_symndx
;
9059 Elf_Internal_Sym
*sym
;
9061 struct elf_link_hash_entry
*h
;
9062 struct got_entry
*ent
;
9064 unsigned char buf
[8];
9066 enum {no_check
, check_lo
, check_ha
} insn_check
;
9068 r_type
= ELF64_R_TYPE (rel
->r_info
);
9072 insn_check
= no_check
;
9075 case R_PPC64_PLT16_HA
:
9076 case R_PPC64_GOT_TLSLD16_HA
:
9077 case R_PPC64_GOT_TLSGD16_HA
:
9078 case R_PPC64_GOT_TPREL16_HA
:
9079 case R_PPC64_GOT_DTPREL16_HA
:
9080 case R_PPC64_GOT16_HA
:
9081 case R_PPC64_TOC16_HA
:
9082 insn_check
= check_ha
;
9085 case R_PPC64_PLT16_LO
:
9086 case R_PPC64_PLT16_LO_DS
:
9087 case R_PPC64_GOT_TLSLD16_LO
:
9088 case R_PPC64_GOT_TLSGD16_LO
:
9089 case R_PPC64_GOT_TPREL16_LO_DS
:
9090 case R_PPC64_GOT_DTPREL16_LO_DS
:
9091 case R_PPC64_GOT16_LO
:
9092 case R_PPC64_GOT16_LO_DS
:
9093 case R_PPC64_TOC16_LO
:
9094 case R_PPC64_TOC16_LO_DS
:
9095 insn_check
= check_lo
;
9099 if (insn_check
!= no_check
)
9101 bfd_vma off
= rel
->r_offset
& ~3;
9103 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9106 insn
= bfd_get_32 (ibfd
, buf
);
9107 if (insn_check
== check_lo
9108 ? !ok_lo_toc_insn (insn
, r_type
)
9109 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9110 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9114 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9115 sprintf (str
, "%#08x", insn
);
9116 info
->callbacks
->einfo
9117 /* xgettext:c-format */
9118 (_("%H: got/toc optimization is not supported for"
9119 " %s instruction\n"),
9120 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9127 /* Note that we don't delete GOT entries for
9128 R_PPC64_GOT16_DS since we'd need a lot more
9129 analysis. For starters, the preliminary layout is
9130 before the GOT, PLT, dynamic sections and stubs are
9131 laid out. Then we'd need to allow for changes in
9132 distance between sections caused by alignment. */
9136 case R_PPC64_GOT16_HA
:
9137 case R_PPC64_GOT16_LO_DS
:
9138 case R_PPC64_GOT_PCREL34
:
9142 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9143 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9148 || sym_sec
->output_section
== NULL
9149 || discarded_section (sym_sec
))
9152 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9156 val
= h
->root
.u
.def
.value
;
9158 val
= sym
->st_value
;
9159 val
+= rel
->r_addend
;
9160 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9162 /* Fudge factor to allow for the fact that the preliminary layout
9163 isn't exact. Reduce limits by this factor. */
9164 #define LIMIT_ADJUST(LIMIT) ((LIMIT) - (LIMIT) / 16)
9171 case R_PPC64_GOT16_HA
:
9172 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9173 >= LIMIT_ADJUST (0x100000000ULL
))
9176 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9177 rel
->r_offset
& ~3, 4))
9179 insn
= bfd_get_32 (ibfd
, buf
);
9180 if (((insn
& ((0x3f << 26) | 0x1f << 16))
9181 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9185 case R_PPC64_GOT16_LO_DS
:
9186 if (val
- got
+ LIMIT_ADJUST (0x80008000ULL
)
9187 >= LIMIT_ADJUST (0x100000000ULL
))
9189 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9190 rel
->r_offset
& ~3, 4))
9192 insn
= bfd_get_32 (ibfd
, buf
);
9193 if ((insn
& (0x3f << 26 | 0x3)) != 58u << 26 /* ld */)
9197 case R_PPC64_GOT_PCREL34
:
9199 pc
+= sec
->output_section
->vma
+ sec
->output_offset
;
9200 if (val
- pc
+ LIMIT_ADJUST (1ULL << 33)
9201 >= LIMIT_ADJUST (1ULL << 34))
9203 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
9204 rel
->r_offset
& ~3, 8))
9206 insn
= bfd_get_32 (ibfd
, buf
);
9207 if ((insn
& (-1u << 18)) != ((1u << 26) | (1u << 20)))
9209 insn
= bfd_get_32 (ibfd
, buf
+ 4);
9210 if ((insn
& (0x3f << 26)) != 57u << 26)
9220 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
9221 ent
= local_got_ents
[r_symndx
];
9223 for (; ent
!= NULL
; ent
= ent
->next
)
9224 if (ent
->addend
== rel
->r_addend
9225 && ent
->owner
== ibfd
9226 && ent
->tls_type
== 0)
9228 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
9229 ent
->got
.refcount
-= 1;
9232 if (elf_section_data (sec
)->relocs
!= relstart
)
9236 if (local_syms
!= NULL
9237 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9239 if (!info
->keep_memory
)
9242 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9249 /* Return true iff input section I references the TOC using
9250 instructions limited to +/-32k offsets. */
9253 ppc64_elf_has_small_toc_reloc (asection
*i
)
9255 return (is_ppc64_elf (i
->owner
)
9256 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9259 /* Allocate space for one GOT entry. */
9262 allocate_got (struct elf_link_hash_entry
*h
,
9263 struct bfd_link_info
*info
,
9264 struct got_entry
*gent
)
9266 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9267 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
9268 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9270 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9271 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9272 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9274 gent
->got
.offset
= got
->size
;
9275 got
->size
+= entsize
;
9277 if (h
->type
== STT_GNU_IFUNC
)
9279 htab
->elf
.irelplt
->size
+= rentsize
;
9280 htab
->got_reli_size
+= rentsize
;
9282 else if (((bfd_link_pic (info
)
9283 && !(gent
->tls_type
!= 0
9284 && bfd_link_executable (info
)
9285 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9286 || (htab
->elf
.dynamic_sections_created
9288 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9289 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9291 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9292 relgot
->size
+= rentsize
;
9296 /* This function merges got entries in the same toc group. */
9299 merge_got_entries (struct got_entry
**pent
)
9301 struct got_entry
*ent
, *ent2
;
9303 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9304 if (!ent
->is_indirect
)
9305 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9306 if (!ent2
->is_indirect
9307 && ent2
->addend
== ent
->addend
9308 && ent2
->tls_type
== ent
->tls_type
9309 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9311 ent2
->is_indirect
= TRUE
;
9312 ent2
->got
.ent
= ent
;
9316 /* If H is undefined, make it dynamic if that makes sense. */
9319 ensure_undef_dynamic (struct bfd_link_info
*info
,
9320 struct elf_link_hash_entry
*h
)
9322 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9324 if (htab
->dynamic_sections_created
9325 && ((info
->dynamic_undefined_weak
!= 0
9326 && h
->root
.type
== bfd_link_hash_undefweak
)
9327 || h
->root
.type
== bfd_link_hash_undefined
)
9330 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9331 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9335 /* Allocate space in .plt, .got and associated reloc sections for
9339 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9341 struct bfd_link_info
*info
;
9342 struct ppc_link_hash_table
*htab
;
9344 struct ppc_link_hash_entry
*eh
;
9345 struct got_entry
**pgent
, *gent
;
9347 if (h
->root
.type
== bfd_link_hash_indirect
)
9350 info
= (struct bfd_link_info
*) inf
;
9351 htab
= ppc_hash_table (info
);
9355 eh
= (struct ppc_link_hash_entry
*) h
;
9356 /* Run through the TLS GD got entries first if we're changing them
9358 if ((eh
->tls_mask
& (TLS_TLS
| TLS_GDIE
)) == (TLS_TLS
| TLS_GDIE
))
9359 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9360 if (gent
->got
.refcount
> 0
9361 && (gent
->tls_type
& TLS_GD
) != 0)
9363 /* This was a GD entry that has been converted to TPREL. If
9364 there happens to be a TPREL entry we can use that one. */
9365 struct got_entry
*ent
;
9366 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9367 if (ent
->got
.refcount
> 0
9368 && (ent
->tls_type
& TLS_TPREL
) != 0
9369 && ent
->addend
== gent
->addend
9370 && ent
->owner
== gent
->owner
)
9372 gent
->got
.refcount
= 0;
9376 /* If not, then we'll be using our own TPREL entry. */
9377 if (gent
->got
.refcount
!= 0)
9378 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9381 /* Remove any list entry that won't generate a word in the GOT before
9382 we call merge_got_entries. Otherwise we risk merging to empty
9384 pgent
= &h
->got
.glist
;
9385 while ((gent
= *pgent
) != NULL
)
9386 if (gent
->got
.refcount
> 0)
9388 if ((gent
->tls_type
& TLS_LD
) != 0
9389 && SYMBOL_REFERENCES_LOCAL (info
, h
))
9391 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9392 *pgent
= gent
->next
;
9395 pgent
= &gent
->next
;
9398 *pgent
= gent
->next
;
9400 if (!htab
->do_multi_toc
)
9401 merge_got_entries (&h
->got
.glist
);
9403 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9404 if (!gent
->is_indirect
)
9406 /* Ensure we catch all the cases where this symbol should
9408 if (!ensure_undef_dynamic (info
, h
))
9411 if (!is_ppc64_elf (gent
->owner
))
9414 allocate_got (h
, info
, gent
);
9417 /* If no dynamic sections we can't have dynamic relocs, except for
9418 IFUNCs which are handled even in static executables. */
9419 if (!htab
->elf
.dynamic_sections_created
9420 && h
->type
!= STT_GNU_IFUNC
)
9421 eh
->dyn_relocs
= NULL
;
9423 /* Discard relocs on undefined symbols that must be local. */
9424 else if (h
->root
.type
== bfd_link_hash_undefined
9425 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9426 eh
->dyn_relocs
= NULL
;
9428 /* Also discard relocs on undefined weak syms with non-default
9429 visibility, or when dynamic_undefined_weak says so. */
9430 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9431 eh
->dyn_relocs
= NULL
;
9433 if (eh
->dyn_relocs
!= NULL
)
9435 struct elf_dyn_relocs
*p
, **pp
;
9437 /* In the shared -Bsymbolic case, discard space allocated for
9438 dynamic pc-relative relocs against symbols which turn out to
9439 be defined in regular objects. For the normal shared case,
9440 discard space for relocs that have become local due to symbol
9441 visibility changes. */
9442 if (bfd_link_pic (info
))
9444 /* Relocs that use pc_count are those that appear on a call
9445 insn, or certain REL relocs (see must_be_dyn_reloc) that
9446 can be generated via assembly. We want calls to
9447 protected symbols to resolve directly to the function
9448 rather than going via the plt. If people want function
9449 pointer comparisons to work as expected then they should
9450 avoid writing weird assembly. */
9451 if (SYMBOL_CALLS_LOCAL (info
, h
))
9453 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
9455 p
->count
-= p
->pc_count
;
9464 if (eh
->dyn_relocs
!= NULL
)
9466 /* Ensure we catch all the cases where this symbol
9467 should be made dynamic. */
9468 if (!ensure_undef_dynamic (info
, h
))
9473 /* For a fixed position executable, discard space for
9474 relocs against symbols which are not dynamic. */
9475 else if (h
->type
!= STT_GNU_IFUNC
)
9477 if (h
->dynamic_adjusted
9479 && !ELF_COMMON_DEF_P (h
))
9481 /* Ensure we catch all the cases where this symbol
9482 should be made dynamic. */
9483 if (!ensure_undef_dynamic (info
, h
))
9486 /* But if that didn't work out, discard dynamic relocs. */
9487 if (h
->dynindx
== -1)
9488 eh
->dyn_relocs
= NULL
;
9491 eh
->dyn_relocs
= NULL
;
9494 /* Finally, allocate space. */
9495 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9497 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9498 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9499 sreloc
= htab
->elf
.irelplt
;
9500 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9504 /* We might need a PLT entry when the symbol
9507 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
9508 d) has plt16 relocs and we are linking statically. */
9509 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
9510 || h
->type
== STT_GNU_IFUNC
9511 || (h
->needs_plt
&& h
->dynamic_adjusted
)
9514 && !htab
->elf
.dynamic_sections_created
9515 && !htab
->can_convert_all_inline_plt
9516 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
9517 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
9519 struct plt_entry
*pent
;
9520 bfd_boolean doneone
= FALSE
;
9521 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9522 if (pent
->plt
.refcount
> 0)
9524 if (!htab
->elf
.dynamic_sections_created
9525 || h
->dynindx
== -1)
9527 if (h
->type
== STT_GNU_IFUNC
)
9530 pent
->plt
.offset
= s
->size
;
9531 s
->size
+= PLT_ENTRY_SIZE (htab
);
9532 s
= htab
->elf
.irelplt
;
9537 pent
->plt
.offset
= s
->size
;
9538 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9539 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
9544 /* If this is the first .plt entry, make room for the special
9548 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9550 pent
->plt
.offset
= s
->size
;
9552 /* Make room for this entry. */
9553 s
->size
+= PLT_ENTRY_SIZE (htab
);
9555 /* Make room for the .glink code. */
9558 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
9561 /* We need bigger stubs past index 32767. */
9562 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
9569 /* We also need to make an entry in the .rela.plt section. */
9570 s
= htab
->elf
.srelplt
;
9573 s
->size
+= sizeof (Elf64_External_Rela
);
9577 pent
->plt
.offset
= (bfd_vma
) -1;
9580 h
->plt
.plist
= NULL
;
9586 h
->plt
.plist
= NULL
;
9593 #define PPC_LO(v) ((v) & 0xffff)
9594 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9595 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9597 ((((v) & 0x3ffff0000ULL) << 16) | (v & 0xffff))
9598 #define HA34(v) ((v + (1ULL << 33)) >> 34)
9600 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9601 to set up space for global entry stubs. These are put in glink,
9602 after the branch table. */
9605 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
9607 struct bfd_link_info
*info
;
9608 struct ppc_link_hash_table
*htab
;
9609 struct plt_entry
*pent
;
9612 if (h
->root
.type
== bfd_link_hash_indirect
)
9615 if (!h
->pointer_equality_needed
)
9622 htab
= ppc_hash_table (info
);
9626 s
= htab
->global_entry
;
9627 plt
= htab
->elf
.splt
;
9628 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9629 if (pent
->plt
.offset
!= (bfd_vma
) -1
9630 && pent
->addend
== 0)
9632 /* For ELFv2, if this symbol is not defined in a regular file
9633 and we are not generating a shared library or pie, then we
9634 need to define the symbol in the executable on a call stub.
9635 This is to avoid text relocations. */
9636 bfd_vma off
, stub_align
, stub_off
, stub_size
;
9637 unsigned int align_power
;
9641 if (htab
->params
->plt_stub_align
>= 0)
9642 align_power
= htab
->params
->plt_stub_align
;
9644 align_power
= -htab
->params
->plt_stub_align
;
9645 /* Setting section alignment is delayed until we know it is
9646 non-empty. Otherwise the .text output section will be
9647 aligned at least to plt_stub_align even when no global
9648 entry stubs are needed. */
9649 if (s
->alignment_power
< align_power
)
9650 s
->alignment_power
= align_power
;
9651 stub_align
= (bfd_vma
) 1 << align_power
;
9652 if (htab
->params
->plt_stub_align
>= 0
9653 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
9654 - (stub_off
& -stub_align
))
9655 > ((stub_size
- 1) & -stub_align
)))
9656 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
9657 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
9658 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
9659 /* Note that for --plt-stub-align negative we have a possible
9660 dependency between stub offset and size. Break that
9661 dependency by assuming the max stub size when calculating
9663 if (PPC_HA (off
) == 0)
9665 h
->root
.type
= bfd_link_hash_defined
;
9666 h
->root
.u
.def
.section
= s
;
9667 h
->root
.u
.def
.value
= stub_off
;
9668 s
->size
= stub_off
+ stub_size
;
9674 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9675 read-only sections. */
9678 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
9682 if (h
->root
.type
== bfd_link_hash_indirect
)
9685 sec
= readonly_dynrelocs (h
);
9688 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
9690 info
->flags
|= DF_TEXTREL
;
9691 info
->callbacks
->minfo (_("%pB: dynamic relocation against `%pT'"
9692 " in read-only section `%pA'\n"),
9693 sec
->owner
, h
->root
.root
.string
, sec
);
9695 /* Not an error, just cut short the traversal. */
9701 /* Set the sizes of the dynamic sections. */
9704 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
9705 struct bfd_link_info
*info
)
9707 struct ppc_link_hash_table
*htab
;
9712 struct got_entry
*first_tlsld
;
9714 htab
= ppc_hash_table (info
);
9718 dynobj
= htab
->elf
.dynobj
;
9722 if (htab
->elf
.dynamic_sections_created
)
9724 /* Set the contents of the .interp section to the interpreter. */
9725 if (bfd_link_executable (info
) && !info
->nointerp
)
9727 s
= bfd_get_linker_section (dynobj
, ".interp");
9730 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
9731 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
9735 /* Set up .got offsets for local syms, and space for local dynamic
9737 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9739 struct got_entry
**lgot_ents
;
9740 struct got_entry
**end_lgot_ents
;
9741 struct plt_entry
**local_plt
;
9742 struct plt_entry
**end_local_plt
;
9743 unsigned char *lgot_masks
;
9744 bfd_size_type locsymcount
;
9745 Elf_Internal_Shdr
*symtab_hdr
;
9747 if (!is_ppc64_elf (ibfd
))
9750 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
9752 struct ppc_dyn_relocs
*p
;
9754 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
9756 if (!bfd_is_abs_section (p
->sec
)
9757 && bfd_is_abs_section (p
->sec
->output_section
))
9759 /* Input section has been discarded, either because
9760 it is a copy of a linkonce section or due to
9761 linker script /DISCARD/, so we'll be discarding
9764 else if (p
->count
!= 0)
9766 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
9768 srel
= htab
->elf
.irelplt
;
9769 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9770 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
9771 info
->flags
|= DF_TEXTREL
;
9776 lgot_ents
= elf_local_got_ents (ibfd
);
9780 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9781 locsymcount
= symtab_hdr
->sh_info
;
9782 end_lgot_ents
= lgot_ents
+ locsymcount
;
9783 local_plt
= (struct plt_entry
**) end_lgot_ents
;
9784 end_local_plt
= local_plt
+ locsymcount
;
9785 lgot_masks
= (unsigned char *) end_local_plt
;
9786 s
= ppc64_elf_tdata (ibfd
)->got
;
9787 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
9789 struct got_entry
**pent
, *ent
;
9792 while ((ent
= *pent
) != NULL
)
9793 if (ent
->got
.refcount
> 0)
9795 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
9797 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
9802 unsigned int ent_size
= 8;
9803 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
9805 ent
->got
.offset
= s
->size
;
9806 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
9811 s
->size
+= ent_size
;
9812 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9814 htab
->elf
.irelplt
->size
+= rel_size
;
9815 htab
->got_reli_size
+= rel_size
;
9817 else if (bfd_link_pic (info
)
9818 && !(ent
->tls_type
!= 0
9819 && bfd_link_executable (info
)))
9821 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9822 srel
->size
+= rel_size
;
9831 /* Allocate space for plt calls to local syms. */
9832 lgot_masks
= (unsigned char *) end_local_plt
;
9833 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
9835 struct plt_entry
*ent
;
9837 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9838 if (ent
->plt
.refcount
> 0)
9840 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9843 ent
->plt
.offset
= s
->size
;
9844 s
->size
+= PLT_ENTRY_SIZE (htab
);
9845 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
9847 else if (htab
->can_convert_all_inline_plt
9848 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
9849 ent
->plt
.offset
= (bfd_vma
) -1;
9853 ent
->plt
.offset
= s
->size
;
9854 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9855 if (bfd_link_pic (info
))
9856 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
9860 ent
->plt
.offset
= (bfd_vma
) -1;
9864 /* Allocate global sym .plt and .got entries, and space for global
9865 sym dynamic relocs. */
9866 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9868 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
9869 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
9872 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9874 struct got_entry
*ent
;
9876 if (!is_ppc64_elf (ibfd
))
9879 ent
= ppc64_tlsld_got (ibfd
);
9880 if (ent
->got
.refcount
> 0)
9882 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9884 ent
->is_indirect
= TRUE
;
9885 ent
->got
.ent
= first_tlsld
;
9889 if (first_tlsld
== NULL
)
9891 s
= ppc64_elf_tdata (ibfd
)->got
;
9892 ent
->got
.offset
= s
->size
;
9895 if (bfd_link_dll (info
))
9897 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9898 srel
->size
+= sizeof (Elf64_External_Rela
);
9903 ent
->got
.offset
= (bfd_vma
) -1;
9906 /* We now have determined the sizes of the various dynamic sections.
9907 Allocate memory for them. */
9909 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9911 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9914 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9915 /* These haven't been allocated yet; don't strip. */
9917 else if (s
== htab
->elf
.sgot
9918 || s
== htab
->elf
.splt
9919 || s
== htab
->elf
.iplt
9920 || s
== htab
->pltlocal
9922 || s
== htab
->global_entry
9923 || s
== htab
->elf
.sdynbss
9924 || s
== htab
->elf
.sdynrelro
)
9926 /* Strip this section if we don't need it; see the
9929 else if (s
== htab
->glink_eh_frame
)
9931 if (!bfd_is_abs_section (s
->output_section
))
9932 /* Not sized yet. */
9935 else if (CONST_STRNEQ (s
->name
, ".rela"))
9939 if (s
!= htab
->elf
.srelplt
)
9942 /* We use the reloc_count field as a counter if we need
9943 to copy relocs into the output file. */
9949 /* It's not one of our sections, so don't allocate space. */
9955 /* If we don't need this section, strip it from the
9956 output file. This is mostly to handle .rela.bss and
9957 .rela.plt. We must create both sections in
9958 create_dynamic_sections, because they must be created
9959 before the linker maps input sections to output
9960 sections. The linker does that before
9961 adjust_dynamic_symbol is called, and it is that
9962 function which decides whether anything needs to go
9963 into these sections. */
9964 s
->flags
|= SEC_EXCLUDE
;
9968 if (bfd_is_abs_section (s
->output_section
))
9969 _bfd_error_handler (_("warning: discarding dynamic section %s"),
9972 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9975 /* Allocate memory for the section contents. We use bfd_zalloc
9976 here in case unused entries are not reclaimed before the
9977 section's contents are written out. This should not happen,
9978 but this way if it does we get a R_PPC64_NONE reloc in .rela
9979 sections instead of garbage.
9980 We also rely on the section contents being zero when writing
9981 the GOT and .dynrelro. */
9982 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9983 if (s
->contents
== NULL
)
9987 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9989 if (!is_ppc64_elf (ibfd
))
9992 s
= ppc64_elf_tdata (ibfd
)->got
;
9993 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
9996 s
->flags
|= SEC_EXCLUDE
;
9999 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10000 if (s
->contents
== NULL
)
10004 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10008 s
->flags
|= SEC_EXCLUDE
;
10011 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10012 if (s
->contents
== NULL
)
10015 s
->reloc_count
= 0;
10020 if (htab
->elf
.dynamic_sections_created
)
10022 bfd_boolean tls_opt
;
10024 /* Add some entries to the .dynamic section. We fill in the
10025 values later, in ppc64_elf_finish_dynamic_sections, but we
10026 must add the entries now so that we get the correct size for
10027 the .dynamic section. The DT_DEBUG entry is filled in by the
10028 dynamic linker and used by the debugger. */
10029 #define add_dynamic_entry(TAG, VAL) \
10030 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10032 if (bfd_link_executable (info
))
10034 if (!add_dynamic_entry (DT_DEBUG
, 0))
10038 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10040 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10041 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10042 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10043 || !add_dynamic_entry (DT_JMPREL
, 0)
10044 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10048 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10050 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10051 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10055 tls_opt
= (htab
->params
->tls_get_addr_opt
10056 && htab
->tls_get_addr_fd
!= NULL
10057 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
10058 if (tls_opt
|| !htab
->opd_abi
)
10060 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10066 if (!add_dynamic_entry (DT_RELA
, 0)
10067 || !add_dynamic_entry (DT_RELASZ
, 0)
10068 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10071 /* If any dynamic relocs apply to a read-only section,
10072 then we need a DT_TEXTREL entry. */
10073 if ((info
->flags
& DF_TEXTREL
) == 0)
10074 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
10076 if ((info
->flags
& DF_TEXTREL
) != 0)
10078 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10083 #undef add_dynamic_entry
10088 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10091 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10093 if (h
->plt
.plist
!= NULL
10095 && !h
->pointer_equality_needed
)
10098 return _bfd_elf_hash_symbol (h
);
10101 /* Determine the type of stub needed, if any, for a call. */
10103 static inline enum ppc_stub_type
10104 ppc_type_of_stub (asection
*input_sec
,
10105 const Elf_Internal_Rela
*rel
,
10106 struct ppc_link_hash_entry
**hash
,
10107 struct plt_entry
**plt_ent
,
10108 bfd_vma destination
,
10109 unsigned long local_off
)
10111 struct ppc_link_hash_entry
*h
= *hash
;
10113 bfd_vma branch_offset
;
10114 bfd_vma max_branch_offset
;
10115 enum elf_ppc64_reloc_type r_type
;
10119 struct plt_entry
*ent
;
10120 struct ppc_link_hash_entry
*fdh
= h
;
10122 && h
->oh
->is_func_descriptor
)
10124 fdh
= ppc_follow_link (h
->oh
);
10128 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10129 if (ent
->addend
== rel
->r_addend
10130 && ent
->plt
.offset
!= (bfd_vma
) -1)
10133 return ppc_stub_plt_call
;
10136 /* Here, we know we don't have a plt entry. If we don't have a
10137 either a defined function descriptor or a defined entry symbol
10138 in a regular object file, then it is pointless trying to make
10139 any other type of stub. */
10140 if (!is_static_defined (&fdh
->elf
)
10141 && !is_static_defined (&h
->elf
))
10142 return ppc_stub_none
;
10144 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10146 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10147 struct plt_entry
**local_plt
= (struct plt_entry
**)
10148 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10149 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10151 if (local_plt
[r_symndx
] != NULL
)
10153 struct plt_entry
*ent
;
10155 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10156 if (ent
->addend
== rel
->r_addend
10157 && ent
->plt
.offset
!= (bfd_vma
) -1)
10160 return ppc_stub_plt_call
;
10165 /* Determine where the call point is. */
10166 location
= (input_sec
->output_offset
10167 + input_sec
->output_section
->vma
10170 branch_offset
= destination
- location
;
10171 r_type
= ELF64_R_TYPE (rel
->r_info
);
10173 /* Determine if a long branch stub is needed. */
10174 max_branch_offset
= 1 << 25;
10175 if (r_type
== R_PPC64_REL14
10176 || r_type
== R_PPC64_REL14_BRTAKEN
10177 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10178 max_branch_offset
= 1 << 15;
10180 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10181 /* We need a stub. Figure out whether a long_branch or plt_branch
10182 is needed later. */
10183 return ppc_stub_long_branch
;
10185 return ppc_stub_none
;
10188 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
10189 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
10194 . lis %r12,xxx-1b@highest
10195 . ori %r12,%r12,xxx-1b@higher
10196 . sldi %r12,%r12,32
10197 . oris %r12,%r12,xxx-1b@high
10198 . ori %r12,%r12,xxx-1b@l
10199 . add/ldx %r12,%r11,%r12 */
10202 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bfd_boolean load
)
10204 bfd_put_32 (abfd
, MFLR_R12
, p
);
10206 bfd_put_32 (abfd
, BCL_20_31
, p
);
10208 bfd_put_32 (abfd
, MFLR_R11
, p
);
10210 bfd_put_32 (abfd
, MTLR_R12
, p
);
10212 if (off
+ 0x8000 < 0x10000)
10215 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
10217 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
10220 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10222 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
10225 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
10227 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
10232 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10234 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
10239 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
10241 if (((off
>> 32) & 0xffff) != 0)
10243 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
10247 if (((off
>> 32) & 0xffffffffULL
) != 0)
10249 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
10252 if (PPC_HI (off
) != 0)
10254 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
10257 if (PPC_LO (off
) != 0)
10259 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
10263 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10265 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10271 static unsigned int
10272 size_offset (bfd_vma off
)
10275 if (off
+ 0x8000 < 0x10000)
10277 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10281 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10286 if (((off
>> 32) & 0xffff) != 0)
10289 if (((off
>> 32) & 0xffffffffULL
) != 0)
10291 if (PPC_HI (off
) != 0)
10293 if (PPC_LO (off
) != 0)
10300 static unsigned int
10301 num_relocs_for_offset (bfd_vma off
)
10303 unsigned int num_rel
;
10304 if (off
+ 0x8000 < 0x10000)
10306 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10311 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
10312 && ((off
>> 32) & 0xffff) != 0)
10314 if (PPC_HI (off
) != 0)
10316 if (PPC_LO (off
) != 0)
10322 static Elf_Internal_Rela
*
10323 emit_relocs_for_offset (struct bfd_link_info
*info
, Elf_Internal_Rela
*r
,
10324 bfd_vma roff
, bfd_vma targ
, bfd_vma off
)
10326 bfd_vma relative_targ
= targ
- (roff
- 8);
10327 if (bfd_big_endian (info
->output_bfd
))
10329 r
->r_offset
= roff
;
10330 r
->r_addend
= relative_targ
+ roff
;
10331 if (off
+ 0x8000 < 0x10000)
10332 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16
);
10333 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
10335 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HA
);
10338 r
->r_offset
= roff
;
10339 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10340 r
->r_addend
= relative_targ
+ roff
;
10344 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
10345 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10348 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHEST
);
10349 if (((off
>> 32) & 0xffff) != 0)
10353 r
->r_offset
= roff
;
10354 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
10355 r
->r_addend
= relative_targ
+ roff
;
10358 if (((off
>> 32) & 0xffffffffULL
) != 0)
10360 if (PPC_HI (off
) != 0)
10364 r
->r_offset
= roff
;
10365 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGH
);
10366 r
->r_addend
= relative_targ
+ roff
;
10368 if (PPC_LO (off
) != 0)
10372 r
->r_offset
= roff
;
10373 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
10374 r
->r_addend
= relative_targ
+ roff
;
10381 build_powerxx_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, int odd
,
10385 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10390 bfd_put_32 (abfd
, NOP
, p
);
10396 insn
= PADDI_R12_PC
;
10398 bfd_put_32 (abfd
, insn
>> 32, p
);
10400 bfd_put_32 (abfd
, insn
, p
);
10402 /* The minimum value for paddi is -0x200000000. The minimum value
10403 for li is -0x8000, which when shifted by 34 and added gives a
10404 minimum value of -0x2000200000000. The maximum value is
10405 0x1ffffffff+0x7fff<<34 which is 0x2000200000000-1. */
10406 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10409 bfd_put_32 (abfd
, LI_R11_0
| (HA34 (off
) & 0xffff), p
);
10413 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10416 insn
= PADDI_R12_PC
| D34 (off
);
10417 bfd_put_32 (abfd
, insn
>> 32, p
);
10419 bfd_put_32 (abfd
, insn
, p
);
10423 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10427 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10429 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10434 bfd_put_32 (abfd
, LIS_R11
| ((HA34 (off
) >> 16) & 0x3fff), p
);
10436 bfd_put_32 (abfd
, ORI_R11_R11_0
| (HA34 (off
) & 0xffff), p
);
10440 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10443 insn
= PADDI_R12_PC
| D34 (off
);
10444 bfd_put_32 (abfd
, insn
>> 32, p
);
10446 bfd_put_32 (abfd
, insn
, p
);
10450 bfd_put_32 (abfd
, SLDI_R11_R11_34
, p
);
10454 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
10456 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
10462 static unsigned int
10463 size_powerxx_offset (bfd_vma off
, int odd
)
10465 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10467 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10473 static unsigned int
10474 num_relocs_for_powerxx_offset (bfd_vma off
, int odd
)
10476 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10478 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10484 static Elf_Internal_Rela
*
10485 emit_relocs_for_powerxx_offset (struct bfd_link_info
*info
,
10486 Elf_Internal_Rela
*r
, bfd_vma roff
,
10487 bfd_vma targ
, bfd_vma off
, int odd
)
10489 if (off
- odd
+ (1ULL << 33) < 1ULL << 34)
10491 else if (off
- (8 - odd
) + (0x20002ULL
<< 32) < 0x40004ULL
<< 32)
10493 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
10494 r
->r_offset
= roff
+ d_offset
;
10495 r
->r_addend
= targ
+ 8 - odd
- d_offset
;
10496 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
10502 int d_offset
= bfd_big_endian (info
->output_bfd
) ? 2 : 0;
10503 r
->r_offset
= roff
+ d_offset
;
10504 r
->r_addend
= targ
+ 8 + odd
- d_offset
;
10505 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHESTA34
);
10508 r
->r_offset
= roff
+ d_offset
;
10509 r
->r_addend
= targ
+ 4 + odd
- d_offset
;
10510 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHERA34
);
10514 r
->r_offset
= roff
;
10515 r
->r_addend
= targ
;
10516 r
->r_info
= ELF64_R_INFO (0, R_PPC64_PCREL34
);
10520 /* Emit .eh_frame opcode to advance pc by DELTA. */
10523 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
10527 *eh
++ = DW_CFA_advance_loc
+ delta
;
10528 else if (delta
< 256)
10530 *eh
++ = DW_CFA_advance_loc1
;
10533 else if (delta
< 65536)
10535 *eh
++ = DW_CFA_advance_loc2
;
10536 bfd_put_16 (abfd
, delta
, eh
);
10541 *eh
++ = DW_CFA_advance_loc4
;
10542 bfd_put_32 (abfd
, delta
, eh
);
10548 /* Size of required .eh_frame opcode to advance pc by DELTA. */
10550 static unsigned int
10551 eh_advance_size (unsigned int delta
)
10553 if (delta
< 64 * 4)
10554 /* DW_CFA_advance_loc+[1..63]. */
10556 if (delta
< 256 * 4)
10557 /* DW_CFA_advance_loc1, byte. */
10559 if (delta
< 65536 * 4)
10560 /* DW_CFA_advance_loc2, 2 bytes. */
10562 /* DW_CFA_advance_loc4, 4 bytes. */
10566 /* With power7 weakly ordered memory model, it is possible for ld.so
10567 to update a plt entry in one thread and have another thread see a
10568 stale zero toc entry. To avoid this we need some sort of acquire
10569 barrier in the call stub. One solution is to make the load of the
10570 toc word seem to appear to depend on the load of the function entry
10571 word. Another solution is to test for r2 being zero, and branch to
10572 the appropriate glink entry if so.
10574 . fake dep barrier compare
10575 . ld 12,xxx(2) ld 12,xxx(2)
10576 . mtctr 12 mtctr 12
10577 . xor 11,12,12 ld 2,xxx+8(2)
10578 . add 2,2,11 cmpldi 2,0
10579 . ld 2,xxx+8(2) bnectr+
10580 . bctr b <glink_entry>
10582 The solution involving the compare turns out to be faster, so
10583 that's what we use unless the branch won't reach. */
10585 #define ALWAYS_USE_FAKE_DEP 0
10586 #define ALWAYS_EMIT_R2SAVE 0
10588 static inline unsigned int
10589 plt_stub_size (struct ppc_link_hash_table
*htab
,
10590 struct ppc_stub_hash_entry
*stub_entry
,
10595 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
10597 if (htab
->powerxx_stubs
)
10599 bfd_vma start
= (stub_entry
->stub_offset
10600 + stub_entry
->group
->stub_sec
->output_offset
10601 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10602 if (stub_entry
->stub_type
> ppc_stub_plt_call_notoc
)
10604 size
= 8 + size_powerxx_offset (off
, start
& 4);
10607 size
= 8 + size_offset (off
- 8);
10608 if (stub_entry
->stub_type
> ppc_stub_plt_call_notoc
)
10614 if (ALWAYS_EMIT_R2SAVE
10615 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10617 if (PPC_HA (off
) != 0)
10622 if (htab
->params
->plt_static_chain
)
10624 if (htab
->params
->plt_thread_safe
10625 && htab
->elf
.dynamic_sections_created
10626 && stub_entry
->h
!= NULL
10627 && stub_entry
->h
->elf
.dynindx
!= -1)
10629 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
10632 if (stub_entry
->h
!= NULL
10633 && (stub_entry
->h
== htab
->tls_get_addr_fd
10634 || stub_entry
->h
== htab
->tls_get_addr
)
10635 && htab
->params
->tls_get_addr_opt
)
10638 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10644 /* Depending on the sign of plt_stub_align:
10645 If positive, return the padding to align to a 2**plt_stub_align
10647 If negative, if this stub would cross fewer 2**plt_stub_align
10648 boundaries if we align, then return the padding needed to do so. */
10650 static inline unsigned int
10651 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10652 struct ppc_stub_hash_entry
*stub_entry
,
10656 unsigned stub_size
;
10657 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10659 if (htab
->params
->plt_stub_align
>= 0)
10661 stub_align
= 1 << htab
->params
->plt_stub_align
;
10662 if ((stub_off
& (stub_align
- 1)) != 0)
10663 return stub_align
- (stub_off
& (stub_align
- 1));
10667 stub_align
= 1 << -htab
->params
->plt_stub_align
;
10668 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10669 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10670 > ((stub_size
- 1) & -stub_align
))
10671 return stub_align
- (stub_off
& (stub_align
- 1));
10675 /* Build a .plt call stub. */
10677 static inline bfd_byte
*
10678 build_plt_stub (struct ppc_link_hash_table
*htab
,
10679 struct ppc_stub_hash_entry
*stub_entry
,
10680 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10682 bfd
*obfd
= htab
->params
->stub_bfd
;
10683 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10684 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10685 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10686 && htab
->elf
.dynamic_sections_created
10687 && stub_entry
->h
!= NULL
10688 && stub_entry
->h
->elf
.dynindx
!= -1);
10689 bfd_boolean use_fake_dep
= plt_thread_safe
;
10690 bfd_vma cmp_branch_off
= 0;
10692 if (!ALWAYS_USE_FAKE_DEP
10695 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10696 || stub_entry
->h
== htab
->tls_get_addr
)
10697 && htab
->params
->tls_get_addr_opt
))
10699 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10700 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10701 / PLT_ENTRY_SIZE (htab
));
10702 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
10705 if (pltindex
> 32768)
10706 glinkoff
+= (pltindex
- 32768) * 4;
10708 + htab
->glink
->output_offset
10709 + htab
->glink
->output_section
->vma
);
10710 from
= (p
- stub_entry
->group
->stub_sec
->contents
10711 + 4 * (ALWAYS_EMIT_R2SAVE
10712 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10713 + 4 * (PPC_HA (offset
) != 0)
10714 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10715 != PPC_HA (offset
))
10716 + 4 * (plt_static_chain
!= 0)
10718 + stub_entry
->group
->stub_sec
->output_offset
10719 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10720 cmp_branch_off
= to
- from
;
10721 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10724 if (PPC_HA (offset
) != 0)
10728 if (ALWAYS_EMIT_R2SAVE
10729 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10730 r
[0].r_offset
+= 4;
10731 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10732 r
[1].r_offset
= r
[0].r_offset
+ 4;
10733 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10734 r
[1].r_addend
= r
[0].r_addend
;
10737 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10739 r
[2].r_offset
= r
[1].r_offset
+ 4;
10740 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10741 r
[2].r_addend
= r
[0].r_addend
;
10745 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10746 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10747 r
[2].r_addend
= r
[0].r_addend
+ 8;
10748 if (plt_static_chain
)
10750 r
[3].r_offset
= r
[2].r_offset
+ 4;
10751 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10752 r
[3].r_addend
= r
[0].r_addend
+ 16;
10757 if (ALWAYS_EMIT_R2SAVE
10758 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10759 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10762 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10763 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10767 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10768 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10771 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10773 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10776 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10781 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10782 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10784 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10785 if (plt_static_chain
)
10786 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10793 if (ALWAYS_EMIT_R2SAVE
10794 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10795 r
[0].r_offset
+= 4;
10796 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10799 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10801 r
[1].r_offset
= r
[0].r_offset
+ 4;
10802 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10803 r
[1].r_addend
= r
[0].r_addend
;
10807 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10808 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10809 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10810 if (plt_static_chain
)
10812 r
[2].r_offset
= r
[1].r_offset
+ 4;
10813 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10814 r
[2].r_addend
= r
[0].r_addend
+ 8;
10819 if (ALWAYS_EMIT_R2SAVE
10820 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10821 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10822 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10824 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10826 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
10829 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10834 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
10835 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
10837 if (plt_static_chain
)
10838 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
10839 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
10842 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
10844 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
10845 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
10846 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
10849 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
10853 /* Build a special .plt call stub for __tls_get_addr. */
10855 #define LD_R11_0R3 0xe9630000
10856 #define LD_R12_0R3 0xe9830000
10857 #define MR_R0_R3 0x7c601b78
10858 #define CMPDI_R11_0 0x2c2b0000
10859 #define ADD_R3_R12_R13 0x7c6c6a14
10860 #define BEQLR 0x4d820020
10861 #define MR_R3_R0 0x7c030378
10862 #define STD_R11_0R1 0xf9610000
10863 #define BCTRL 0x4e800421
10864 #define LD_R11_0R1 0xe9610000
10865 #define MTLR_R11 0x7d6803a6
10867 static inline bfd_byte
*
10868 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
10869 struct ppc_stub_hash_entry
*stub_entry
,
10870 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10872 bfd
*obfd
= htab
->params
->stub_bfd
;
10875 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
10876 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
10877 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
10878 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
10879 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
10880 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
10881 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
10883 r
[0].r_offset
+= 7 * 4;
10884 if (stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
10885 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10887 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
10888 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10891 r
[0].r_offset
+= 2 * 4;
10892 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10893 bfd_put_32 (obfd
, BCTRL
, p
- 4);
10895 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10896 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10897 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
10898 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
10900 if (htab
->glink_eh_frame
!= NULL
10901 && htab
->glink_eh_frame
->size
!= 0)
10903 bfd_byte
*base
, *eh
;
10904 unsigned int lr_used
, delta
;
10906 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
10907 eh
= base
+ stub_entry
->group
->eh_size
;
10908 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
10909 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10910 stub_entry
->group
->lr_restore
= lr_used
+ 16;
10911 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
10912 *eh
++ = DW_CFA_offset_extended_sf
;
10914 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
10915 *eh
++ = DW_CFA_advance_loc
+ 4;
10916 *eh
++ = DW_CFA_restore_extended
;
10918 stub_entry
->group
->eh_size
= eh
- base
;
10923 static Elf_Internal_Rela
*
10924 get_relocs (asection
*sec
, int count
)
10926 Elf_Internal_Rela
*relocs
;
10927 struct bfd_elf_section_data
*elfsec_data
;
10929 elfsec_data
= elf_section_data (sec
);
10930 relocs
= elfsec_data
->relocs
;
10931 if (relocs
== NULL
)
10933 bfd_size_type relsize
;
10934 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10935 relocs
= bfd_alloc (sec
->owner
, relsize
);
10936 if (relocs
== NULL
)
10938 elfsec_data
->relocs
= relocs
;
10939 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10940 sizeof (Elf_Internal_Shdr
));
10941 if (elfsec_data
->rela
.hdr
== NULL
)
10943 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10944 * sizeof (Elf64_External_Rela
));
10945 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10946 sec
->reloc_count
= 0;
10948 relocs
+= sec
->reloc_count
;
10949 sec
->reloc_count
+= count
;
10953 /* Convert the relocs R[0] thru R[-NUM_REL+1], which are all no-symbol
10954 forms, to the equivalent relocs against the global symbol given by
10958 use_global_in_relocs (struct ppc_link_hash_table
*htab
,
10959 struct ppc_stub_hash_entry
*stub_entry
,
10960 Elf_Internal_Rela
*r
, unsigned int num_rel
)
10962 struct elf_link_hash_entry
**hashes
;
10963 unsigned long symndx
;
10964 struct ppc_link_hash_entry
*h
;
10967 /* Relocs are always against symbols in their own object file. Fake
10968 up global sym hashes for the stub bfd (which has no symbols). */
10969 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10970 if (hashes
== NULL
)
10972 bfd_size_type hsize
;
10974 /* When called the first time, stub_globals will contain the
10975 total number of symbols seen during stub sizing. After
10976 allocating, stub_globals is used as an index to fill the
10978 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10979 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10980 if (hashes
== NULL
)
10982 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10983 htab
->stub_globals
= 1;
10985 symndx
= htab
->stub_globals
++;
10987 hashes
[symndx
] = &h
->elf
;
10988 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10989 h
= ppc_follow_link (h
->oh
);
10990 BFD_ASSERT (h
->elf
.root
.type
== bfd_link_hash_defined
10991 || h
->elf
.root
.type
== bfd_link_hash_defweak
);
10992 symval
= (h
->elf
.root
.u
.def
.value
10993 + h
->elf
.root
.u
.def
.section
->output_offset
10994 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10995 while (num_rel
-- != 0)
10997 r
->r_info
= ELF64_R_INFO (symndx
, ELF64_R_TYPE (r
->r_info
));
10998 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11000 /* H is an opd symbol. The addend must be zero, and the
11001 branch reloc is the only one we can convert. */
11006 r
->r_addend
-= symval
;
11013 get_r2off (struct bfd_link_info
*info
,
11014 struct ppc_stub_hash_entry
*stub_entry
)
11016 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11017 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
11021 /* Support linking -R objects. Get the toc pointer from the
11024 if (!htab
->opd_abi
)
11026 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
11027 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
11029 if (strcmp (opd
->name
, ".opd") != 0
11030 || opd
->reloc_count
!= 0)
11032 info
->callbacks
->einfo
11033 (_("%P: cannot find opd entry toc for `%pT'\n"),
11034 stub_entry
->h
->elf
.root
.root
.string
);
11035 bfd_set_error (bfd_error_bad_value
);
11036 return (bfd_vma
) -1;
11038 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
11039 return (bfd_vma
) -1;
11040 r2off
= bfd_get_64 (opd
->owner
, buf
);
11041 r2off
-= elf_gp (info
->output_bfd
);
11043 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
11048 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11050 struct ppc_stub_hash_entry
*stub_entry
;
11051 struct ppc_branch_hash_entry
*br_entry
;
11052 struct bfd_link_info
*info
;
11053 struct ppc_link_hash_table
*htab
;
11055 bfd_byte
*p
, *relp
;
11057 Elf_Internal_Rela
*r
;
11062 /* Massage our args to the form they really have. */
11063 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11066 htab
= ppc_hash_table (info
);
11070 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
11071 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
11073 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
11074 switch (stub_entry
->stub_type
)
11076 case ppc_stub_long_branch
:
11077 case ppc_stub_long_branch_r2off
:
11078 /* Branches are relative. This is where we are going to. */
11079 targ
= (stub_entry
->target_value
11080 + stub_entry
->target_section
->output_offset
11081 + stub_entry
->target_section
->output_section
->vma
);
11082 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11084 /* And this is where we are coming from. */
11085 off
= (stub_entry
->stub_offset
11086 + stub_entry
->group
->stub_sec
->output_offset
11087 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11091 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11093 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11095 if (r2off
== (bfd_vma
) -1)
11097 htab
->stub_error
= TRUE
;
11100 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11102 if (PPC_HA (r2off
) != 0)
11104 bfd_put_32 (htab
->params
->stub_bfd
,
11105 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11108 if (PPC_LO (r2off
) != 0)
11110 bfd_put_32 (htab
->params
->stub_bfd
,
11111 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11116 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
11119 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11122 (_("long branch stub `%s' offset overflow"),
11123 stub_entry
->root
.string
);
11124 htab
->stub_error
= TRUE
;
11128 if (info
->emitrelocations
)
11130 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11133 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11134 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11135 r
->r_addend
= targ
;
11136 if (stub_entry
->h
!= NULL
11137 && !use_global_in_relocs (htab
, stub_entry
, r
, 1))
11142 case ppc_stub_plt_branch
:
11143 case ppc_stub_plt_branch_r2off
:
11144 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11145 stub_entry
->root
.string
+ 9,
11147 if (br_entry
== NULL
)
11149 _bfd_error_handler (_("can't find branch stub `%s'"),
11150 stub_entry
->root
.string
);
11151 htab
->stub_error
= TRUE
;
11155 targ
= (stub_entry
->target_value
11156 + stub_entry
->target_section
->output_offset
11157 + stub_entry
->target_section
->output_section
->vma
);
11158 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11159 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11161 bfd_put_64 (htab
->brlt
->owner
, targ
,
11162 htab
->brlt
->contents
+ br_entry
->offset
);
11164 if (br_entry
->iter
== htab
->stub_iteration
)
11166 br_entry
->iter
= 0;
11168 if (htab
->relbrlt
!= NULL
)
11170 /* Create a reloc for the branch lookup table entry. */
11171 Elf_Internal_Rela rela
;
11174 rela
.r_offset
= (br_entry
->offset
11175 + htab
->brlt
->output_offset
11176 + htab
->brlt
->output_section
->vma
);
11177 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11178 rela
.r_addend
= targ
;
11180 rl
= htab
->relbrlt
->contents
;
11181 rl
+= (htab
->relbrlt
->reloc_count
++
11182 * sizeof (Elf64_External_Rela
));
11183 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11185 else if (info
->emitrelocations
)
11187 r
= get_relocs (htab
->brlt
, 1);
11190 /* brlt, being SEC_LINKER_CREATED does not go through the
11191 normal reloc processing. Symbols and offsets are not
11192 translated from input file to output file form, so
11193 set up the offset per the output file. */
11194 r
->r_offset
= (br_entry
->offset
11195 + htab
->brlt
->output_offset
11196 + htab
->brlt
->output_section
->vma
);
11197 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11198 r
->r_addend
= targ
;
11202 targ
= (br_entry
->offset
11203 + htab
->brlt
->output_offset
11204 + htab
->brlt
->output_section
->vma
);
11206 off
= (elf_gp (info
->output_bfd
)
11207 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11210 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11212 info
->callbacks
->einfo
11213 (_("%P: linkage table error against `%pT'\n"),
11214 stub_entry
->root
.string
);
11215 bfd_set_error (bfd_error_bad_value
);
11216 htab
->stub_error
= TRUE
;
11220 if (info
->emitrelocations
)
11222 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11225 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11226 if (bfd_big_endian (info
->output_bfd
))
11227 r
[0].r_offset
+= 2;
11228 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
11229 r
[0].r_offset
+= 4;
11230 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11231 r
[0].r_addend
= targ
;
11232 if (PPC_HA (off
) != 0)
11234 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11235 r
[1].r_offset
= r
[0].r_offset
+ 4;
11236 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11237 r
[1].r_addend
= r
[0].r_addend
;
11242 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11244 if (PPC_HA (off
) != 0)
11246 bfd_put_32 (htab
->params
->stub_bfd
,
11247 ADDIS_R12_R2
| PPC_HA (off
), p
);
11249 bfd_put_32 (htab
->params
->stub_bfd
,
11250 LD_R12_0R12
| PPC_LO (off
), p
);
11253 bfd_put_32 (htab
->params
->stub_bfd
,
11254 LD_R12_0R2
| PPC_LO (off
), p
);
11258 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11260 if (r2off
== (bfd_vma
) -1)
11262 htab
->stub_error
= TRUE
;
11266 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11268 if (PPC_HA (off
) != 0)
11270 bfd_put_32 (htab
->params
->stub_bfd
,
11271 ADDIS_R12_R2
| PPC_HA (off
), p
);
11273 bfd_put_32 (htab
->params
->stub_bfd
,
11274 LD_R12_0R12
| PPC_LO (off
), p
);
11277 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11279 if (PPC_HA (r2off
) != 0)
11282 bfd_put_32 (htab
->params
->stub_bfd
,
11283 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11285 if (PPC_LO (r2off
) != 0)
11288 bfd_put_32 (htab
->params
->stub_bfd
,
11289 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11293 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
11295 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
11299 case ppc_stub_long_branch_notoc
:
11300 case ppc_stub_long_branch_both
:
11301 case ppc_stub_plt_branch_notoc
:
11302 case ppc_stub_plt_branch_both
:
11303 case ppc_stub_plt_call_notoc
:
11304 case ppc_stub_plt_call_both
:
11306 off
= (stub_entry
->stub_offset
11307 + stub_entry
->group
->stub_sec
->output_offset
11308 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11309 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
11310 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
11311 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11314 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11317 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
11319 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11320 if (targ
>= (bfd_vma
) -2)
11323 plt
= htab
->elf
.splt
;
11324 if (!htab
->elf
.dynamic_sections_created
11325 || stub_entry
->h
== NULL
11326 || stub_entry
->h
->elf
.dynindx
== -1)
11328 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11329 plt
= htab
->elf
.iplt
;
11331 plt
= htab
->pltlocal
;
11333 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11336 targ
= (stub_entry
->target_value
11337 + stub_entry
->target_section
->output_offset
11338 + stub_entry
->target_section
->output_section
->vma
);
11344 if (htab
->powerxx_stubs
)
11346 bfd_boolean load
= stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
;
11347 p
= build_powerxx_offset (htab
->params
->stub_bfd
, p
, off
, odd
, load
);
11351 /* The notoc stubs calculate their target (either a PLT entry or
11352 the global entry point of a function) relative to the PC
11353 returned by the "bcl" two instructions past the start of the
11354 sequence emitted by build_offset. The offset is therefore 8
11355 less than calculated from the start of the sequence. */
11357 p
= build_offset (htab
->params
->stub_bfd
, p
, off
,
11358 stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
);
11361 if (stub_entry
->stub_type
<= ppc_stub_long_branch_both
)
11365 from
= (stub_entry
->stub_offset
11366 + stub_entry
->group
->stub_sec
->output_offset
11367 + stub_entry
->group
->stub_sec
->output_section
->vma
11369 bfd_put_32 (htab
->params
->stub_bfd
,
11370 B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
11374 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
11376 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
11380 if (info
->emitrelocations
)
11382 bfd_vma roff
= relp
- stub_entry
->group
->stub_sec
->contents
;
11383 if (htab
->powerxx_stubs
)
11384 num_rel
+= num_relocs_for_powerxx_offset (off
, odd
);
11387 num_rel
+= num_relocs_for_offset (off
);
11390 r
= get_relocs (stub_entry
->group
->stub_sec
, num_rel
);
11393 if (htab
->powerxx_stubs
)
11394 r
= emit_relocs_for_powerxx_offset (info
, r
, roff
, targ
, off
, odd
);
11396 r
= emit_relocs_for_offset (info
, r
, roff
, targ
, off
);
11397 if (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
11398 || stub_entry
->stub_type
== ppc_stub_long_branch_both
)
11401 roff
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11402 r
->r_offset
= roff
;
11403 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11404 r
->r_addend
= targ
;
11405 if (stub_entry
->h
!= NULL
11406 && !use_global_in_relocs (htab
, stub_entry
, r
, num_rel
))
11411 if (!htab
->powerxx_stubs
11412 && htab
->glink_eh_frame
!= NULL
11413 && htab
->glink_eh_frame
->size
!= 0)
11415 bfd_byte
*base
, *eh
;
11416 unsigned int lr_used
, delta
;
11418 base
= (htab
->glink_eh_frame
->contents
11419 + stub_entry
->group
->eh_base
+ 17);
11420 eh
= base
+ stub_entry
->group
->eh_size
;
11421 lr_used
= stub_entry
->stub_offset
+ 8;
11422 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
11423 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
11424 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11426 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11427 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11428 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
11429 *eh
++ = DW_CFA_register
;
11432 *eh
++ = DW_CFA_advance_loc
+ 2;
11433 *eh
++ = DW_CFA_restore_extended
;
11435 stub_entry
->group
->eh_size
= eh
- base
;
11439 case ppc_stub_plt_call
:
11440 case ppc_stub_plt_call_r2save
:
11441 if (stub_entry
->h
!= NULL
11442 && stub_entry
->h
->is_func_descriptor
11443 && stub_entry
->h
->oh
!= NULL
)
11445 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11447 /* If the old-ABI "dot-symbol" is undefined make it weak so
11448 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11449 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11450 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11451 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11452 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11455 /* Now build the stub. */
11456 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11457 if (targ
>= (bfd_vma
) -2)
11460 plt
= htab
->elf
.splt
;
11461 if (!htab
->elf
.dynamic_sections_created
11462 || stub_entry
->h
== NULL
11463 || stub_entry
->h
->elf
.dynindx
== -1)
11465 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11466 plt
= htab
->elf
.iplt
;
11468 plt
= htab
->pltlocal
;
11470 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11472 off
= (elf_gp (info
->output_bfd
)
11473 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11476 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11478 info
->callbacks
->einfo
11479 /* xgettext:c-format */
11480 (_("%P: linkage table error against `%pT'\n"),
11481 stub_entry
->h
!= NULL
11482 ? stub_entry
->h
->elf
.root
.root
.string
11484 bfd_set_error (bfd_error_bad_value
);
11485 htab
->stub_error
= TRUE
;
11490 if (info
->emitrelocations
)
11492 r
= get_relocs (stub_entry
->group
->stub_sec
,
11493 ((PPC_HA (off
) != 0)
11495 ? 2 + (htab
->params
->plt_static_chain
11496 && PPC_HA (off
+ 16) == PPC_HA (off
))
11500 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11501 if (bfd_big_endian (info
->output_bfd
))
11502 r
[0].r_offset
+= 2;
11503 r
[0].r_addend
= targ
;
11505 if (stub_entry
->h
!= NULL
11506 && (stub_entry
->h
== htab
->tls_get_addr_fd
11507 || stub_entry
->h
== htab
->tls_get_addr
)
11508 && htab
->params
->tls_get_addr_opt
)
11509 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
11511 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
11514 case ppc_stub_save_res
:
11522 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
11524 if (htab
->params
->emit_stub_syms
)
11526 struct elf_link_hash_entry
*h
;
11529 const char *const stub_str
[] = { "long_branch",
11542 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11543 len2
= strlen (stub_entry
->root
.string
);
11544 name
= bfd_malloc (len1
+ len2
+ 2);
11547 memcpy (name
, stub_entry
->root
.string
, 9);
11548 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11549 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11550 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
11553 if (h
->root
.type
== bfd_link_hash_new
)
11555 h
->root
.type
= bfd_link_hash_defined
;
11556 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11557 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11558 h
->ref_regular
= 1;
11559 h
->def_regular
= 1;
11560 h
->ref_regular_nonweak
= 1;
11561 h
->forced_local
= 1;
11563 h
->root
.linker_def
= 1;
11570 /* As above, but don't actually build the stub. Just bump offset so
11571 we know stub section sizes, and select plt_branch stubs where
11572 long_branch stubs won't do. */
11575 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11577 struct ppc_stub_hash_entry
*stub_entry
;
11578 struct bfd_link_info
*info
;
11579 struct ppc_link_hash_table
*htab
;
11581 bfd_vma targ
, off
, r2off
;
11582 unsigned int size
, extra
, lr_used
, delta
, odd
;
11584 /* Massage our args to the form they really have. */
11585 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11588 htab
= ppc_hash_table (info
);
11592 /* Make a note of the offset within the stubs for this entry. */
11593 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11595 if (stub_entry
->h
!= NULL
11596 && stub_entry
->h
->save_res
11597 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11598 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
11600 /* Don't make stubs to out-of-line register save/restore
11601 functions. Instead, emit copies of the functions. */
11602 stub_entry
->group
->needs_save_res
= 1;
11603 stub_entry
->stub_type
= ppc_stub_save_res
;
11607 switch (stub_entry
->stub_type
)
11609 case ppc_stub_plt_branch
:
11610 case ppc_stub_plt_branch_r2off
:
11611 /* Reset the stub type from the plt branch variant in case we now
11612 can reach with a shorter stub. */
11613 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11614 /* Fall through. */
11615 case ppc_stub_long_branch
:
11616 case ppc_stub_long_branch_r2off
:
11617 targ
= (stub_entry
->target_value
11618 + stub_entry
->target_section
->output_offset
11619 + stub_entry
->target_section
->output_section
->vma
);
11620 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11621 off
= (stub_entry
->stub_offset
11622 + stub_entry
->group
->stub_sec
->output_offset
11623 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11627 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11629 r2off
= get_r2off (info
, stub_entry
);
11630 if (r2off
== (bfd_vma
) -1)
11632 htab
->stub_error
= TRUE
;
11636 if (PPC_HA (r2off
) != 0)
11638 if (PPC_LO (r2off
) != 0)
11644 /* If the branch offset is too big, use a ppc_stub_plt_branch.
11645 Do the same for -R objects without function descriptors. */
11646 if ((stub_entry
->stub_type
== ppc_stub_long_branch_r2off
11648 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
11649 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11651 struct ppc_branch_hash_entry
*br_entry
;
11653 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11654 stub_entry
->root
.string
+ 9,
11656 if (br_entry
== NULL
)
11658 _bfd_error_handler (_("can't build branch stub `%s'"),
11659 stub_entry
->root
.string
);
11660 htab
->stub_error
= TRUE
;
11664 if (br_entry
->iter
!= htab
->stub_iteration
)
11666 br_entry
->iter
= htab
->stub_iteration
;
11667 br_entry
->offset
= htab
->brlt
->size
;
11668 htab
->brlt
->size
+= 8;
11670 if (htab
->relbrlt
!= NULL
)
11671 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
11672 else if (info
->emitrelocations
)
11674 htab
->brlt
->reloc_count
+= 1;
11675 htab
->brlt
->flags
|= SEC_RELOC
;
11679 targ
= (br_entry
->offset
11680 + htab
->brlt
->output_offset
11681 + htab
->brlt
->output_section
->vma
);
11682 off
= (elf_gp (info
->output_bfd
)
11683 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11686 if (info
->emitrelocations
)
11688 stub_entry
->group
->stub_sec
->reloc_count
11689 += 1 + (PPC_HA (off
) != 0);
11690 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11693 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11694 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11697 if (PPC_HA (off
) != 0)
11703 if (PPC_HA (off
) != 0)
11706 if (PPC_HA (r2off
) != 0)
11708 if (PPC_LO (r2off
) != 0)
11712 else if (info
->emitrelocations
)
11714 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11715 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11719 case ppc_stub_plt_branch_notoc
:
11720 case ppc_stub_plt_branch_both
:
11721 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11722 /* Fall through. */
11723 case ppc_stub_long_branch_notoc
:
11724 case ppc_stub_long_branch_both
:
11725 off
= (stub_entry
->stub_offset
11726 + stub_entry
->group
->stub_sec
->output_offset
11727 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11729 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
11732 targ
= (stub_entry
->target_value
11733 + stub_entry
->target_section
->output_offset
11734 + stub_entry
->target_section
->output_section
->vma
);
11738 if (info
->emitrelocations
)
11740 unsigned int num_rel
;
11741 if (htab
->powerxx_stubs
)
11742 num_rel
= num_relocs_for_powerxx_offset (off
, odd
);
11744 num_rel
= num_relocs_for_offset (off
- 8);
11745 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
11746 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11749 if (htab
->powerxx_stubs
)
11750 extra
= size_powerxx_offset (off
, odd
);
11752 extra
= size_offset (off
- 8);
11753 /* Include branch insn plus those in the offset sequence. */
11755 /* The branch insn is at the end, or "extra" bytes along. So
11756 its offset will be "extra" bytes less that that already
11760 if (!htab
->powerxx_stubs
)
11762 /* After the bcl, lr has been modified so we need to emit
11763 .eh_frame info saying the return address is in r12. */
11764 lr_used
= stub_entry
->stub_offset
+ 8;
11765 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
11767 /* The eh_frame info will consist of a DW_CFA_advance_loc or
11768 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
11769 DW_CFA_restore_extended 65. */
11770 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11771 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
11772 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11775 /* If the branch can't reach, use a plt_branch. */
11776 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11778 stub_entry
->stub_type
+= (ppc_stub_plt_branch_notoc
11779 - ppc_stub_long_branch_notoc
);
11782 else if (info
->emitrelocations
)
11783 stub_entry
->group
->stub_sec
->reloc_count
+=1;
11786 case ppc_stub_plt_call_notoc
:
11787 case ppc_stub_plt_call_both
:
11788 off
= (stub_entry
->stub_offset
11789 + stub_entry
->group
->stub_sec
->output_offset
11790 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11791 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11793 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11794 if (targ
>= (bfd_vma
) -2)
11797 plt
= htab
->elf
.splt
;
11798 if (!htab
->elf
.dynamic_sections_created
11799 || stub_entry
->h
== NULL
11800 || stub_entry
->h
->elf
.dynindx
== -1)
11802 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11803 plt
= htab
->elf
.iplt
;
11805 plt
= htab
->pltlocal
;
11807 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11811 if (htab
->params
->plt_stub_align
!= 0)
11813 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11815 stub_entry
->group
->stub_sec
->size
+= pad
;
11816 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11820 if (info
->emitrelocations
)
11822 unsigned int num_rel
;
11823 if (htab
->powerxx_stubs
)
11824 num_rel
= num_relocs_for_powerxx_offset (off
, odd
);
11826 num_rel
= num_relocs_for_offset (off
- 8);
11827 stub_entry
->group
->stub_sec
->reloc_count
+= num_rel
;
11828 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11831 size
= plt_stub_size (htab
, stub_entry
, off
);
11833 if (!htab
->powerxx_stubs
)
11835 /* After the bcl, lr has been modified so we need to emit
11836 .eh_frame info saying the return address is in r12. */
11837 lr_used
= stub_entry
->stub_offset
+ 8;
11838 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11840 /* The eh_frame info will consist of a DW_CFA_advance_loc or
11841 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
11842 DW_CFA_restore_extended 65. */
11843 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11844 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
11845 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11849 case ppc_stub_plt_call
:
11850 case ppc_stub_plt_call_r2save
:
11851 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11852 if (targ
>= (bfd_vma
) -2)
11854 plt
= htab
->elf
.splt
;
11855 if (!htab
->elf
.dynamic_sections_created
11856 || stub_entry
->h
== NULL
11857 || stub_entry
->h
->elf
.dynindx
== -1)
11859 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11860 plt
= htab
->elf
.iplt
;
11862 plt
= htab
->pltlocal
;
11864 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11866 off
= (elf_gp (info
->output_bfd
)
11867 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11870 if (htab
->params
->plt_stub_align
!= 0)
11872 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11874 stub_entry
->group
->stub_sec
->size
+= pad
;
11875 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11878 if (info
->emitrelocations
)
11880 stub_entry
->group
->stub_sec
->reloc_count
11881 += ((PPC_HA (off
) != 0)
11883 ? 2 + (htab
->params
->plt_static_chain
11884 && PPC_HA (off
+ 16) == PPC_HA (off
))
11886 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11889 size
= plt_stub_size (htab
, stub_entry
, off
);
11891 if (stub_entry
->h
!= NULL
11892 && (stub_entry
->h
== htab
->tls_get_addr_fd
11893 || stub_entry
->h
== htab
->tls_get_addr
)
11894 && htab
->params
->tls_get_addr_opt
11895 && stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11897 /* After the bctrl, lr has been modified so we need to
11898 emit .eh_frame info saying the return address is
11899 on the stack. In fact we put the EH info specifying
11900 that the return address is on the stack *at* the
11901 call rather than after it, because the EH info for a
11902 call needs to be specified by that point.
11903 See libgcc/unwind-dw2.c execute_cfa_program. */
11904 lr_used
= stub_entry
->stub_offset
+ size
- 20;
11905 /* The eh_frame info will consist of a DW_CFA_advance_loc
11906 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
11907 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
11908 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11909 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
11910 stub_entry
->group
->lr_restore
= size
- 4;
11919 stub_entry
->group
->stub_sec
->size
+= size
;
11923 /* Set up various things so that we can make a list of input sections
11924 for each output section included in the link. Returns -1 on error,
11925 0 when no stubs will be needed, and 1 on success. */
11928 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11932 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11937 htab
->sec_info_arr_size
= _bfd_section_id
;
11938 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11939 htab
->sec_info
= bfd_zmalloc (amt
);
11940 if (htab
->sec_info
== NULL
)
11943 /* Set toc_off for com, und, abs and ind sections. */
11944 for (id
= 0; id
< 3; id
++)
11945 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11950 /* Set up for first pass at multitoc partitioning. */
11953 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11955 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11957 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11958 htab
->toc_bfd
= NULL
;
11959 htab
->toc_first_sec
= NULL
;
11962 /* The linker repeatedly calls this function for each TOC input section
11963 and linker generated GOT section. Group input bfds such that the toc
11964 within a group is less than 64k in size. */
11967 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11969 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11970 bfd_vma addr
, off
, limit
;
11975 if (!htab
->second_toc_pass
)
11977 /* Keep track of the first .toc or .got section for this input bfd. */
11978 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11982 htab
->toc_bfd
= isec
->owner
;
11983 htab
->toc_first_sec
= isec
;
11986 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11987 off
= addr
- htab
->toc_curr
;
11988 limit
= 0x80008000;
11989 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11991 if (off
+ isec
->size
> limit
)
11993 addr
= (htab
->toc_first_sec
->output_offset
11994 + htab
->toc_first_sec
->output_section
->vma
);
11995 htab
->toc_curr
= addr
;
11996 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11999 /* toc_curr is the base address of this toc group. Set elf_gp
12000 for the input section to be the offset relative to the
12001 output toc base plus 0x8000. Making the input elf_gp an
12002 offset allows us to move the toc as a whole without
12003 recalculating input elf_gp. */
12004 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
12005 off
+= TOC_BASE_OFF
;
12007 /* Die if someone uses a linker script that doesn't keep input
12008 file .toc and .got together. */
12010 && elf_gp (isec
->owner
) != 0
12011 && elf_gp (isec
->owner
) != off
)
12014 elf_gp (isec
->owner
) = off
;
12018 /* During the second pass toc_first_sec points to the start of
12019 a toc group, and toc_curr is used to track the old elf_gp.
12020 We use toc_bfd to ensure we only look at each bfd once. */
12021 if (htab
->toc_bfd
== isec
->owner
)
12023 htab
->toc_bfd
= isec
->owner
;
12025 if (htab
->toc_first_sec
== NULL
12026 || htab
->toc_curr
!= elf_gp (isec
->owner
))
12028 htab
->toc_curr
= elf_gp (isec
->owner
);
12029 htab
->toc_first_sec
= isec
;
12031 addr
= (htab
->toc_first_sec
->output_offset
12032 + htab
->toc_first_sec
->output_section
->vma
);
12033 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
12034 elf_gp (isec
->owner
) = off
;
12039 /* Called via elf_link_hash_traverse to merge GOT entries for global
12043 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
12045 if (h
->root
.type
== bfd_link_hash_indirect
)
12048 merge_got_entries (&h
->got
.glist
);
12053 /* Called via elf_link_hash_traverse to allocate GOT entries for global
12057 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
12059 struct got_entry
*gent
;
12061 if (h
->root
.type
== bfd_link_hash_indirect
)
12064 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
12065 if (!gent
->is_indirect
)
12066 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
12070 /* Called on the first multitoc pass after the last call to
12071 ppc64_elf_next_toc_section. This function removes duplicate GOT
12075 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
12077 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12078 struct bfd
*ibfd
, *ibfd2
;
12079 bfd_boolean done_something
;
12081 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
12083 if (!htab
->do_multi_toc
)
12086 /* Merge global sym got entries within a toc group. */
12087 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
12089 /* And tlsld_got. */
12090 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12092 struct got_entry
*ent
, *ent2
;
12094 if (!is_ppc64_elf (ibfd
))
12097 ent
= ppc64_tlsld_got (ibfd
);
12098 if (!ent
->is_indirect
12099 && ent
->got
.offset
!= (bfd_vma
) -1)
12101 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
12103 if (!is_ppc64_elf (ibfd2
))
12106 ent2
= ppc64_tlsld_got (ibfd2
);
12107 if (!ent2
->is_indirect
12108 && ent2
->got
.offset
!= (bfd_vma
) -1
12109 && elf_gp (ibfd2
) == elf_gp (ibfd
))
12111 ent2
->is_indirect
= TRUE
;
12112 ent2
->got
.ent
= ent
;
12118 /* Zap sizes of got sections. */
12119 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
12120 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
12121 htab
->got_reli_size
= 0;
12123 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12125 asection
*got
, *relgot
;
12127 if (!is_ppc64_elf (ibfd
))
12130 got
= ppc64_elf_tdata (ibfd
)->got
;
12133 got
->rawsize
= got
->size
;
12135 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
12136 relgot
->rawsize
= relgot
->size
;
12141 /* Now reallocate the got, local syms first. We don't need to
12142 allocate section contents again since we never increase size. */
12143 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12145 struct got_entry
**lgot_ents
;
12146 struct got_entry
**end_lgot_ents
;
12147 struct plt_entry
**local_plt
;
12148 struct plt_entry
**end_local_plt
;
12149 unsigned char *lgot_masks
;
12150 bfd_size_type locsymcount
;
12151 Elf_Internal_Shdr
*symtab_hdr
;
12154 if (!is_ppc64_elf (ibfd
))
12157 lgot_ents
= elf_local_got_ents (ibfd
);
12161 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12162 locsymcount
= symtab_hdr
->sh_info
;
12163 end_lgot_ents
= lgot_ents
+ locsymcount
;
12164 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12165 end_local_plt
= local_plt
+ locsymcount
;
12166 lgot_masks
= (unsigned char *) end_local_plt
;
12167 s
= ppc64_elf_tdata (ibfd
)->got
;
12168 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
12170 struct got_entry
*ent
;
12172 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
12174 unsigned int ent_size
= 8;
12175 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
12177 ent
->got
.offset
= s
->size
;
12178 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
12183 s
->size
+= ent_size
;
12184 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
12186 htab
->elf
.irelplt
->size
+= rel_size
;
12187 htab
->got_reli_size
+= rel_size
;
12189 else if (bfd_link_pic (info
)
12190 && !(ent
->tls_type
!= 0
12191 && bfd_link_executable (info
)))
12193 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12194 srel
->size
+= rel_size
;
12200 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12202 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12204 struct got_entry
*ent
;
12206 if (!is_ppc64_elf (ibfd
))
12209 ent
= ppc64_tlsld_got (ibfd
);
12210 if (!ent
->is_indirect
12211 && ent
->got
.offset
!= (bfd_vma
) -1)
12213 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12214 ent
->got
.offset
= s
->size
;
12216 if (bfd_link_dll (info
))
12218 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12219 srel
->size
+= sizeof (Elf64_External_Rela
);
12224 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12225 if (!done_something
)
12226 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12230 if (!is_ppc64_elf (ibfd
))
12233 got
= ppc64_elf_tdata (ibfd
)->got
;
12236 done_something
= got
->rawsize
!= got
->size
;
12237 if (done_something
)
12242 if (done_something
)
12243 (*htab
->params
->layout_sections_again
) ();
12245 /* Set up for second pass over toc sections to recalculate elf_gp
12246 on input sections. */
12247 htab
->toc_bfd
= NULL
;
12248 htab
->toc_first_sec
= NULL
;
12249 htab
->second_toc_pass
= TRUE
;
12250 return done_something
;
12253 /* Called after second pass of multitoc partitioning. */
12256 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
12258 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12260 /* After the second pass, toc_curr tracks the TOC offset used
12261 for code sections below in ppc64_elf_next_input_section. */
12262 htab
->toc_curr
= TOC_BASE_OFF
;
12265 /* No toc references were found in ISEC. If the code in ISEC makes no
12266 calls, then there's no need to use toc adjusting stubs when branching
12267 into ISEC. Actually, indirect calls from ISEC are OK as they will
12268 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
12269 needed, and 2 if a cyclical call-graph was found but no other reason
12270 for a stub was detected. If called from the top level, a return of
12271 2 means the same as a return of 0. */
12274 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
12278 /* Mark this section as checked. */
12279 isec
->call_check_done
= 1;
12281 /* We know none of our code bearing sections will need toc stubs. */
12282 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
12285 if (isec
->size
== 0)
12288 if (isec
->output_section
== NULL
)
12292 if (isec
->reloc_count
!= 0)
12294 Elf_Internal_Rela
*relstart
, *rel
;
12295 Elf_Internal_Sym
*local_syms
;
12296 struct ppc_link_hash_table
*htab
;
12298 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
12299 info
->keep_memory
);
12300 if (relstart
== NULL
)
12303 /* Look for branches to outside of this section. */
12305 htab
= ppc_hash_table (info
);
12309 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
12311 enum elf_ppc64_reloc_type r_type
;
12312 unsigned long r_symndx
;
12313 struct elf_link_hash_entry
*h
;
12314 struct ppc_link_hash_entry
*eh
;
12315 Elf_Internal_Sym
*sym
;
12317 struct _opd_sec_data
*opd
;
12321 r_type
= ELF64_R_TYPE (rel
->r_info
);
12322 if (r_type
!= R_PPC64_REL24
12323 && r_type
!= R_PPC64_REL24_NOTOC
12324 && r_type
!= R_PPC64_REL14
12325 && r_type
!= R_PPC64_REL14_BRTAKEN
12326 && r_type
!= R_PPC64_REL14_BRNTAKEN
12327 && r_type
!= R_PPC64_PLTCALL
12328 && r_type
!= R_PPC64_PLTCALL_NOTOC
)
12331 r_symndx
= ELF64_R_SYM (rel
->r_info
);
12332 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
12339 /* Calls to dynamic lib functions go through a plt call stub
12341 eh
= (struct ppc_link_hash_entry
*) h
;
12343 && (eh
->elf
.plt
.plist
!= NULL
12345 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12351 if (sym_sec
== NULL
)
12352 /* Ignore other undefined symbols. */
12355 /* Assume branches to other sections not included in the
12356 link need stubs too, to cover -R and absolute syms. */
12357 if (sym_sec
->output_section
== NULL
)
12364 sym_value
= sym
->st_value
;
12367 if (h
->root
.type
!= bfd_link_hash_defined
12368 && h
->root
.type
!= bfd_link_hash_defweak
)
12370 sym_value
= h
->root
.u
.def
.value
;
12372 sym_value
+= rel
->r_addend
;
12374 /* If this branch reloc uses an opd sym, find the code section. */
12375 opd
= get_opd_info (sym_sec
);
12378 if (h
== NULL
&& opd
->adjust
!= NULL
)
12382 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12384 /* Assume deleted functions won't ever be called. */
12386 sym_value
+= adjust
;
12389 dest
= opd_entry_value (sym_sec
, sym_value
,
12390 &sym_sec
, NULL
, FALSE
);
12391 if (dest
== (bfd_vma
) -1)
12396 + sym_sec
->output_offset
12397 + sym_sec
->output_section
->vma
);
12399 /* Ignore branch to self. */
12400 if (sym_sec
== isec
)
12403 /* If the called function uses the toc, we need a stub. */
12404 if (sym_sec
->has_toc_reloc
12405 || sym_sec
->makes_toc_func_call
)
12411 /* Assume any branch that needs a long branch stub might in fact
12412 need a plt_branch stub. A plt_branch stub uses r2. */
12413 else if (dest
- (isec
->output_offset
12414 + isec
->output_section
->vma
12415 + rel
->r_offset
) + (1 << 25)
12416 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
12424 /* If calling back to a section in the process of being
12425 tested, we can't say for sure that no toc adjusting stubs
12426 are needed, so don't return zero. */
12427 else if (sym_sec
->call_check_in_progress
)
12430 /* Branches to another section that itself doesn't have any TOC
12431 references are OK. Recursively call ourselves to check. */
12432 else if (!sym_sec
->call_check_done
)
12436 /* Mark current section as indeterminate, so that other
12437 sections that call back to current won't be marked as
12439 isec
->call_check_in_progress
= 1;
12440 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
12441 isec
->call_check_in_progress
= 0;
12452 if (local_syms
!= NULL
12453 && (elf_symtab_hdr (isec
->owner
).contents
12454 != (unsigned char *) local_syms
))
12456 if (elf_section_data (isec
)->relocs
!= relstart
)
12461 && isec
->map_head
.s
!= NULL
12462 && (strcmp (isec
->output_section
->name
, ".init") == 0
12463 || strcmp (isec
->output_section
->name
, ".fini") == 0))
12465 if (isec
->map_head
.s
->has_toc_reloc
12466 || isec
->map_head
.s
->makes_toc_func_call
)
12468 else if (!isec
->map_head
.s
->call_check_done
)
12471 isec
->call_check_in_progress
= 1;
12472 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
12473 isec
->call_check_in_progress
= 0;
12480 isec
->makes_toc_func_call
= 1;
12485 /* The linker repeatedly calls this function for each input section,
12486 in the order that input sections are linked into output sections.
12487 Build lists of input sections to determine groupings between which
12488 we may insert linker stubs. */
12491 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
12493 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12498 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
12499 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
12501 /* This happens to make the list in reverse order,
12502 which is what we want. */
12503 htab
->sec_info
[isec
->id
].u
.list
12504 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
12505 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
12508 if (htab
->multi_toc_needed
)
12510 /* Analyse sections that aren't already flagged as needing a
12511 valid toc pointer. Exclude .fixup for the linux kernel.
12512 .fixup contains branches, but only back to the function that
12513 hit an exception. */
12514 if (!(isec
->has_toc_reloc
12515 || (isec
->flags
& SEC_CODE
) == 0
12516 || strcmp (isec
->name
, ".fixup") == 0
12517 || isec
->call_check_done
))
12519 if (toc_adjusting_stub_needed (info
, isec
) < 0)
12522 /* Make all sections use the TOC assigned for this object file.
12523 This will be wrong for pasted sections; We fix that in
12524 check_pasted_section(). */
12525 if (elf_gp (isec
->owner
) != 0)
12526 htab
->toc_curr
= elf_gp (isec
->owner
);
12529 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
12533 /* Check that all .init and .fini sections use the same toc, if they
12534 have toc relocs. */
12537 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
12539 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
12543 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12544 bfd_vma toc_off
= 0;
12547 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12548 if (i
->has_toc_reloc
)
12551 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12552 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
12557 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12558 if (i
->makes_toc_func_call
)
12560 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12564 /* Make sure the whole pasted function uses the same toc offset. */
12566 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12567 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
12573 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
12575 return (check_pasted_section (info
, ".init")
12576 & check_pasted_section (info
, ".fini"));
12579 /* See whether we can group stub sections together. Grouping stub
12580 sections may result in fewer stubs. More importantly, we need to
12581 put all .init* and .fini* stubs at the beginning of the .init or
12582 .fini output sections respectively, because glibc splits the
12583 _init and _fini functions into multiple parts. Putting a stub in
12584 the middle of a function is not a good idea. */
12587 group_sections (struct bfd_link_info
*info
,
12588 bfd_size_type stub_group_size
,
12589 bfd_boolean stubs_always_before_branch
)
12591 struct ppc_link_hash_table
*htab
;
12593 bfd_boolean suppress_size_errors
;
12595 htab
= ppc_hash_table (info
);
12599 suppress_size_errors
= FALSE
;
12600 if (stub_group_size
== 1)
12602 /* Default values. */
12603 if (stubs_always_before_branch
)
12604 stub_group_size
= 0x1e00000;
12606 stub_group_size
= 0x1c00000;
12607 suppress_size_errors
= TRUE
;
12610 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
12614 if (osec
->id
>= htab
->sec_info_arr_size
)
12617 tail
= htab
->sec_info
[osec
->id
].u
.list
;
12618 while (tail
!= NULL
)
12622 bfd_size_type total
;
12623 bfd_boolean big_sec
;
12625 struct map_stub
*group
;
12626 bfd_size_type group_size
;
12629 total
= tail
->size
;
12630 group_size
= (ppc64_elf_section_data (tail
) != NULL
12631 && ppc64_elf_section_data (tail
)->has_14bit_branch
12632 ? stub_group_size
>> 10 : stub_group_size
);
12634 big_sec
= total
> group_size
;
12635 if (big_sec
&& !suppress_size_errors
)
12636 /* xgettext:c-format */
12637 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
12638 tail
->owner
, tail
);
12639 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
12641 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
12642 && ((total
+= curr
->output_offset
- prev
->output_offset
)
12643 < (ppc64_elf_section_data (prev
) != NULL
12644 && ppc64_elf_section_data (prev
)->has_14bit_branch
12645 ? (group_size
= stub_group_size
>> 10) : group_size
))
12646 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12649 /* OK, the size from the start of CURR to the end is less
12650 than group_size and thus can be handled by one stub
12651 section. (or the tail section is itself larger than
12652 group_size, in which case we may be toast.) We should
12653 really be keeping track of the total size of stubs added
12654 here, as stubs contribute to the final output section
12655 size. That's a little tricky, and this way will only
12656 break if stubs added make the total size more than 2^25,
12657 ie. for the default stub_group_size, if stubs total more
12658 than 2097152 bytes, or nearly 75000 plt call stubs. */
12659 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
12662 group
->link_sec
= curr
;
12663 group
->stub_sec
= NULL
;
12664 group
->needs_save_res
= 0;
12665 group
->lr_restore
= 0;
12666 group
->eh_size
= 0;
12667 group
->eh_base
= 0;
12668 group
->next
= htab
->group
;
12669 htab
->group
= group
;
12672 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12673 /* Set up this stub group. */
12674 htab
->sec_info
[tail
->id
].u
.group
= group
;
12676 while (tail
!= curr
&& (tail
= prev
) != NULL
);
12678 /* But wait, there's more! Input sections up to group_size
12679 bytes before the stub section can be handled by it too.
12680 Don't do this if we have a really large section after the
12681 stubs, as adding more stubs increases the chance that
12682 branches may not reach into the stub section. */
12683 if (!stubs_always_before_branch
&& !big_sec
)
12686 while (prev
!= NULL
12687 && ((total
+= tail
->output_offset
- prev
->output_offset
)
12688 < (ppc64_elf_section_data (prev
) != NULL
12689 && ppc64_elf_section_data (prev
)->has_14bit_branch
12690 ? (group_size
= stub_group_size
>> 10)
12692 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12695 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12696 htab
->sec_info
[tail
->id
].u
.group
= group
;
12705 static const unsigned char glink_eh_frame_cie
[] =
12707 0, 0, 0, 16, /* length. */
12708 0, 0, 0, 0, /* id. */
12709 1, /* CIE version. */
12710 'z', 'R', 0, /* Augmentation string. */
12711 4, /* Code alignment. */
12712 0x78, /* Data alignment. */
12714 1, /* Augmentation size. */
12715 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12716 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
12719 /* Stripping output sections is normally done before dynamic section
12720 symbols have been allocated. This function is called later, and
12721 handles cases like htab->brlt which is mapped to its own output
12725 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12727 if (isec
->size
== 0
12728 && isec
->output_section
->size
== 0
12729 && !(isec
->output_section
->flags
& SEC_KEEP
)
12730 && !bfd_section_removed_from_list (info
->output_bfd
,
12731 isec
->output_section
)
12732 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12734 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12735 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12736 info
->output_bfd
->section_count
--;
12740 /* Determine and set the size of the stub section for a final link.
12742 The basic idea here is to examine all the relocations looking for
12743 PC-relative calls to a target that is unreachable with a "bl"
12747 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12749 bfd_size_type stub_group_size
;
12750 bfd_boolean stubs_always_before_branch
;
12751 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12756 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12757 htab
->params
->plt_thread_safe
= 1;
12758 if (!htab
->opd_abi
)
12759 htab
->params
->plt_thread_safe
= 0;
12760 else if (htab
->params
->plt_thread_safe
== -1)
12762 static const char *const thread_starter
[] =
12766 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12768 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12769 "mq_notify", "create_timer",
12774 "GOMP_parallel_start",
12775 "GOMP_parallel_loop_static",
12776 "GOMP_parallel_loop_static_start",
12777 "GOMP_parallel_loop_dynamic",
12778 "GOMP_parallel_loop_dynamic_start",
12779 "GOMP_parallel_loop_guided",
12780 "GOMP_parallel_loop_guided_start",
12781 "GOMP_parallel_loop_runtime",
12782 "GOMP_parallel_loop_runtime_start",
12783 "GOMP_parallel_sections",
12784 "GOMP_parallel_sections_start",
12790 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12792 struct elf_link_hash_entry
*h
;
12793 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12794 FALSE
, FALSE
, TRUE
);
12795 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12796 if (htab
->params
->plt_thread_safe
)
12800 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12801 if (htab
->params
->group_size
< 0)
12802 stub_group_size
= -htab
->params
->group_size
;
12804 stub_group_size
= htab
->params
->group_size
;
12806 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12809 #define STUB_SHRINK_ITER 20
12810 /* Loop until no stubs added. After iteration 20 of this loop we may
12811 exit on a stub section shrinking. This is to break out of a
12812 pathological case where adding stubs on one iteration decreases
12813 section gaps (perhaps due to alignment), which then requires
12814 fewer or smaller stubs on the next iteration. */
12819 unsigned int bfd_indx
;
12820 struct map_stub
*group
;
12822 htab
->stub_iteration
+= 1;
12824 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12826 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12828 Elf_Internal_Shdr
*symtab_hdr
;
12830 Elf_Internal_Sym
*local_syms
= NULL
;
12832 if (!is_ppc64_elf (input_bfd
))
12835 /* We'll need the symbol table in a second. */
12836 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12837 if (symtab_hdr
->sh_info
== 0)
12840 /* Walk over each section attached to the input bfd. */
12841 for (section
= input_bfd
->sections
;
12843 section
= section
->next
)
12845 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12847 /* If there aren't any relocs, then there's nothing more
12849 if ((section
->flags
& SEC_RELOC
) == 0
12850 || (section
->flags
& SEC_ALLOC
) == 0
12851 || (section
->flags
& SEC_LOAD
) == 0
12852 || (section
->flags
& SEC_CODE
) == 0
12853 || section
->reloc_count
== 0)
12856 /* If this section is a link-once section that will be
12857 discarded, then don't create any stubs. */
12858 if (section
->output_section
== NULL
12859 || section
->output_section
->owner
!= info
->output_bfd
)
12862 /* Get the relocs. */
12864 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12865 info
->keep_memory
);
12866 if (internal_relocs
== NULL
)
12867 goto error_ret_free_local
;
12869 /* Now examine each relocation. */
12870 irela
= internal_relocs
;
12871 irelaend
= irela
+ section
->reloc_count
;
12872 for (; irela
< irelaend
; irela
++)
12874 enum elf_ppc64_reloc_type r_type
;
12875 unsigned int r_indx
;
12876 enum ppc_stub_type stub_type
;
12877 struct ppc_stub_hash_entry
*stub_entry
;
12878 asection
*sym_sec
, *code_sec
;
12879 bfd_vma sym_value
, code_value
;
12880 bfd_vma destination
;
12881 unsigned long local_off
;
12882 bfd_boolean ok_dest
;
12883 struct ppc_link_hash_entry
*hash
;
12884 struct ppc_link_hash_entry
*fdh
;
12885 struct elf_link_hash_entry
*h
;
12886 Elf_Internal_Sym
*sym
;
12888 const asection
*id_sec
;
12889 struct _opd_sec_data
*opd
;
12890 struct plt_entry
*plt_ent
;
12892 r_type
= ELF64_R_TYPE (irela
->r_info
);
12893 r_indx
= ELF64_R_SYM (irela
->r_info
);
12895 if (r_type
>= R_PPC64_max
)
12897 bfd_set_error (bfd_error_bad_value
);
12898 goto error_ret_free_internal
;
12901 /* Only look for stubs on branch instructions. */
12902 if (r_type
!= R_PPC64_REL24
12903 && r_type
!= R_PPC64_REL24_NOTOC
12904 && r_type
!= R_PPC64_REL14
12905 && r_type
!= R_PPC64_REL14_BRTAKEN
12906 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12909 /* Now determine the call target, its name, value,
12911 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12912 r_indx
, input_bfd
))
12913 goto error_ret_free_internal
;
12914 hash
= (struct ppc_link_hash_entry
*) h
;
12921 sym_value
= sym
->st_value
;
12922 if (sym_sec
!= NULL
12923 && sym_sec
->output_section
!= NULL
)
12926 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12927 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12929 sym_value
= hash
->elf
.root
.u
.def
.value
;
12930 if (sym_sec
->output_section
!= NULL
)
12933 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12934 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12936 /* Recognise an old ABI func code entry sym, and
12937 use the func descriptor sym instead if it is
12939 if (hash
->elf
.root
.root
.string
[0] == '.'
12940 && hash
->oh
!= NULL
)
12942 fdh
= ppc_follow_link (hash
->oh
);
12943 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12944 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12946 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12947 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12948 if (sym_sec
->output_section
!= NULL
)
12957 bfd_set_error (bfd_error_bad_value
);
12958 goto error_ret_free_internal
;
12965 sym_value
+= irela
->r_addend
;
12966 destination
= (sym_value
12967 + sym_sec
->output_offset
12968 + sym_sec
->output_section
->vma
);
12969 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12974 code_sec
= sym_sec
;
12975 code_value
= sym_value
;
12976 opd
= get_opd_info (sym_sec
);
12981 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12983 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12986 code_value
+= adjust
;
12987 sym_value
+= adjust
;
12989 dest
= opd_entry_value (sym_sec
, sym_value
,
12990 &code_sec
, &code_value
, FALSE
);
12991 if (dest
!= (bfd_vma
) -1)
12993 destination
= dest
;
12996 /* Fixup old ABI sym to point at code
12998 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12999 hash
->elf
.root
.u
.def
.section
= code_sec
;
13000 hash
->elf
.root
.u
.def
.value
= code_value
;
13005 /* Determine what (if any) linker stub is needed. */
13007 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
13008 &plt_ent
, destination
,
13011 if (r_type
== R_PPC64_REL24_NOTOC
)
13013 if (stub_type
== ppc_stub_plt_call
)
13014 stub_type
= ppc_stub_plt_call_notoc
;
13015 else if (stub_type
== ppc_stub_long_branch
13016 || (code_sec
!= NULL
13017 && code_sec
->output_section
!= NULL
13018 && (((hash
? hash
->elf
.other
: sym
->st_other
)
13019 & STO_PPC64_LOCAL_MASK
)
13020 > 1 << STO_PPC64_LOCAL_BIT
)))
13021 stub_type
= ppc_stub_long_branch_notoc
;
13023 else if (stub_type
!= ppc_stub_plt_call
)
13025 /* Check whether we need a TOC adjusting stub.
13026 Since the linker pastes together pieces from
13027 different object files when creating the
13028 _init and _fini functions, it may be that a
13029 call to what looks like a local sym is in
13030 fact a call needing a TOC adjustment. */
13031 if ((code_sec
!= NULL
13032 && code_sec
->output_section
!= NULL
13033 && (htab
->sec_info
[code_sec
->id
].toc_off
13034 != htab
->sec_info
[section
->id
].toc_off
)
13035 && (code_sec
->has_toc_reloc
13036 || code_sec
->makes_toc_func_call
))
13037 || (((hash
? hash
->elf
.other
: sym
->st_other
)
13038 & STO_PPC64_LOCAL_MASK
)
13039 == 1 << STO_PPC64_LOCAL_BIT
))
13040 stub_type
= ppc_stub_long_branch_r2off
;
13043 if (stub_type
== ppc_stub_none
)
13046 /* __tls_get_addr calls might be eliminated. */
13047 if (stub_type
!= ppc_stub_plt_call
13048 && stub_type
!= ppc_stub_plt_call_notoc
13050 && (hash
== htab
->tls_get_addr
13051 || hash
== htab
->tls_get_addr_fd
)
13052 && section
->has_tls_reloc
13053 && irela
!= internal_relocs
)
13055 /* Get tls info. */
13056 unsigned char *tls_mask
;
13058 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
13059 irela
- 1, input_bfd
))
13060 goto error_ret_free_internal
;
13061 if ((*tls_mask
& TLS_TLS
) != 0)
13065 if (stub_type
== ppc_stub_plt_call
)
13068 && htab
->params
->plt_localentry0
!= 0
13069 && is_elfv2_localentry0 (&hash
->elf
))
13070 htab
->has_plt_localentry0
= 1;
13071 else if (irela
+ 1 < irelaend
13072 && irela
[1].r_offset
== irela
->r_offset
+ 4
13073 && (ELF64_R_TYPE (irela
[1].r_info
)
13074 == R_PPC64_TOCSAVE
))
13076 if (!tocsave_find (htab
, INSERT
,
13077 &local_syms
, irela
+ 1, input_bfd
))
13078 goto error_ret_free_internal
;
13081 stub_type
= ppc_stub_plt_call_r2save
;
13084 /* Support for grouping stub sections. */
13085 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
13087 /* Get the name of this stub. */
13088 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
13090 goto error_ret_free_internal
;
13092 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
13093 stub_name
, FALSE
, FALSE
);
13094 if (stub_entry
!= NULL
)
13096 enum ppc_stub_type old_type
;
13097 /* A stub has already been created, but it may
13098 not be the required type. We shouldn't be
13099 transitioning from plt_call to long_branch
13100 stubs or vice versa, but we might be
13101 upgrading from plt_call to plt_call_r2save or
13102 from long_branch to long_branch_r2off. */
13104 old_type
= stub_entry
->stub_type
;
13110 case ppc_stub_save_res
:
13113 case ppc_stub_plt_call
:
13114 case ppc_stub_plt_call_r2save
:
13115 case ppc_stub_plt_call_notoc
:
13116 case ppc_stub_plt_call_both
:
13117 if (stub_type
== ppc_stub_plt_call
)
13119 else if (stub_type
== ppc_stub_plt_call_r2save
)
13121 if (old_type
== ppc_stub_plt_call_notoc
)
13122 stub_type
= ppc_stub_plt_call_both
;
13124 else if (stub_type
== ppc_stub_plt_call_notoc
)
13126 if (old_type
== ppc_stub_plt_call_r2save
)
13127 stub_type
= ppc_stub_plt_call_both
;
13133 case ppc_stub_plt_branch
:
13134 case ppc_stub_plt_branch_r2off
:
13135 case ppc_stub_plt_branch_notoc
:
13136 case ppc_stub_plt_branch_both
:
13137 old_type
+= (ppc_stub_long_branch
13138 - ppc_stub_plt_branch
);
13139 /* Fall through. */
13140 case ppc_stub_long_branch
:
13141 case ppc_stub_long_branch_r2off
:
13142 case ppc_stub_long_branch_notoc
:
13143 case ppc_stub_long_branch_both
:
13144 if (stub_type
== ppc_stub_long_branch
)
13146 else if (stub_type
== ppc_stub_long_branch_r2off
)
13148 if (old_type
== ppc_stub_long_branch_notoc
)
13149 stub_type
= ppc_stub_long_branch_both
;
13151 else if (stub_type
== ppc_stub_long_branch_notoc
)
13153 if (old_type
== ppc_stub_long_branch_r2off
)
13154 stub_type
= ppc_stub_long_branch_both
;
13160 if (old_type
< stub_type
)
13161 stub_entry
->stub_type
= stub_type
;
13165 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
13166 if (stub_entry
== NULL
)
13169 error_ret_free_internal
:
13170 if (elf_section_data (section
)->relocs
== NULL
)
13171 free (internal_relocs
);
13172 error_ret_free_local
:
13173 if (local_syms
!= NULL
13174 && (symtab_hdr
->contents
13175 != (unsigned char *) local_syms
))
13180 stub_entry
->stub_type
= stub_type
;
13181 if (stub_type
>= ppc_stub_plt_call
13182 && stub_type
<= ppc_stub_plt_call_both
)
13184 stub_entry
->target_value
= sym_value
;
13185 stub_entry
->target_section
= sym_sec
;
13189 stub_entry
->target_value
= code_value
;
13190 stub_entry
->target_section
= code_sec
;
13192 stub_entry
->h
= hash
;
13193 stub_entry
->plt_ent
= plt_ent
;
13194 stub_entry
->symtype
13195 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
13196 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
13199 && (hash
->elf
.root
.type
== bfd_link_hash_defined
13200 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
13201 htab
->stub_globals
+= 1;
13204 /* We're done with the internal relocs, free them. */
13205 if (elf_section_data (section
)->relocs
!= internal_relocs
)
13206 free (internal_relocs
);
13209 if (local_syms
!= NULL
13210 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13212 if (!info
->keep_memory
)
13215 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13219 /* We may have added some stubs. Find out the new size of the
13221 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13223 group
->lr_restore
= 0;
13224 group
->eh_size
= 0;
13225 if (group
->stub_sec
!= NULL
)
13227 asection
*stub_sec
= group
->stub_sec
;
13229 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13230 || stub_sec
->rawsize
< stub_sec
->size
)
13231 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
13232 stub_sec
->rawsize
= stub_sec
->size
;
13233 stub_sec
->size
= 0;
13234 stub_sec
->reloc_count
= 0;
13235 stub_sec
->flags
&= ~SEC_RELOC
;
13239 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13240 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
13241 htab
->brlt
->rawsize
= htab
->brlt
->size
;
13242 htab
->brlt
->size
= 0;
13243 htab
->brlt
->reloc_count
= 0;
13244 htab
->brlt
->flags
&= ~SEC_RELOC
;
13245 if (htab
->relbrlt
!= NULL
)
13246 htab
->relbrlt
->size
= 0;
13248 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
13250 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13251 if (group
->needs_save_res
)
13252 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13254 if (info
->emitrelocations
13255 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13257 htab
->glink
->reloc_count
= 1;
13258 htab
->glink
->flags
|= SEC_RELOC
;
13261 if (htab
->glink_eh_frame
!= NULL
13262 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
13263 && htab
->glink_eh_frame
->output_section
->size
> 8)
13265 size_t size
= 0, align
= 4;
13267 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13268 if (group
->eh_size
!= 0)
13269 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
13270 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13271 size
+= (24 + align
- 1) & -align
;
13273 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
13274 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13275 size
= (size
+ align
- 1) & -align
;
13276 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
13277 htab
->glink_eh_frame
->size
= size
;
13280 if (htab
->params
->plt_stub_align
!= 0)
13281 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13282 if (group
->stub_sec
!= NULL
)
13284 int align
= abs (htab
->params
->plt_stub_align
);
13285 group
->stub_sec
->size
13286 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13289 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13290 if (group
->stub_sec
!= NULL
13291 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
13292 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13293 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
13297 && (htab
->brlt
->rawsize
== htab
->brlt
->size
13298 || (htab
->stub_iteration
> STUB_SHRINK_ITER
13299 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
13300 && (htab
->glink_eh_frame
== NULL
13301 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
13304 /* Ask the linker to do its stuff. */
13305 (*htab
->params
->layout_sections_again
) ();
13308 if (htab
->glink_eh_frame
!= NULL
13309 && htab
->glink_eh_frame
->size
!= 0)
13312 bfd_byte
*p
, *last_fde
;
13313 size_t last_fde_len
, size
, align
, pad
;
13314 struct map_stub
*group
;
13316 /* It is necessary to at least have a rough outline of the
13317 linker generated CIEs and FDEs written before
13318 bfd_elf_discard_info is run, in order for these FDEs to be
13319 indexed in .eh_frame_hdr. */
13320 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
13323 htab
->glink_eh_frame
->contents
= p
;
13327 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
13328 /* CIE length (rewrite in case little-endian). */
13329 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
13330 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13331 p
+= last_fde_len
+ 4;
13333 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13334 if (group
->eh_size
!= 0)
13336 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
13338 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
13340 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13343 val
= p
- htab
->glink_eh_frame
->contents
;
13344 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13346 /* Offset to stub section, written later. */
13348 /* stub section size. */
13349 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
13351 /* Augmentation. */
13353 /* Make sure we don't have all nops. This is enough for
13354 elf-eh-frame.c to detect the last non-nop opcode. */
13355 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
13356 p
= last_fde
+ last_fde_len
+ 4;
13358 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13361 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
13363 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13366 val
= p
- htab
->glink_eh_frame
->contents
;
13367 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13369 /* Offset to .glink, written later. */
13372 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
13374 /* Augmentation. */
13377 *p
++ = DW_CFA_advance_loc
+ 1;
13378 *p
++ = DW_CFA_register
;
13380 *p
++ = htab
->opd_abi
? 12 : 0;
13381 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
13382 *p
++ = DW_CFA_restore_extended
;
13384 p
+= ((24 + align
- 1) & -align
) - 24;
13386 /* Subsume any padding into the last FDE if user .eh_frame
13387 sections are aligned more than glink_eh_frame. Otherwise any
13388 zero padding will be seen as a terminator. */
13389 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13390 size
= p
- htab
->glink_eh_frame
->contents
;
13391 pad
= ((size
+ align
- 1) & -align
) - size
;
13392 htab
->glink_eh_frame
->size
= size
+ pad
;
13393 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
13396 maybe_strip_output (info
, htab
->brlt
);
13397 if (htab
->glink_eh_frame
!= NULL
)
13398 maybe_strip_output (info
, htab
->glink_eh_frame
);
13403 /* Called after we have determined section placement. If sections
13404 move, we'll be called again. Provide a value for TOCstart. */
13407 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
13410 bfd_vma TOCstart
, adjust
;
13414 struct elf_link_hash_entry
*h
;
13415 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
13417 if (is_elf_hash_table (htab
)
13418 && htab
->hgot
!= NULL
)
13422 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
13423 if (is_elf_hash_table (htab
))
13427 && h
->root
.type
== bfd_link_hash_defined
13428 && !h
->root
.linker_def
13429 && (!is_elf_hash_table (htab
)
13430 || h
->def_regular
))
13432 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
13433 + h
->root
.u
.def
.section
->output_offset
13434 + h
->root
.u
.def
.section
->output_section
->vma
);
13435 _bfd_set_gp_value (obfd
, TOCstart
);
13440 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
13441 order. The TOC starts where the first of these sections starts. */
13442 s
= bfd_get_section_by_name (obfd
, ".got");
13443 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13444 s
= bfd_get_section_by_name (obfd
, ".toc");
13445 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13446 s
= bfd_get_section_by_name (obfd
, ".tocbss");
13447 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13448 s
= bfd_get_section_by_name (obfd
, ".plt");
13449 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13451 /* This may happen for
13452 o references to TOC base (SYM@toc / TOC[tc0]) without a
13454 o bad linker script
13455 o --gc-sections and empty TOC sections
13457 FIXME: Warn user? */
13459 /* Look for a likely section. We probably won't even be
13461 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13462 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
13464 == (SEC_ALLOC
| SEC_SMALL_DATA
))
13467 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13468 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
13469 == (SEC_ALLOC
| SEC_SMALL_DATA
))
13472 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13473 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
13477 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13478 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
13484 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
13486 /* Force alignment. */
13487 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
13488 TOCstart
-= adjust
;
13489 _bfd_set_gp_value (obfd
, TOCstart
);
13491 if (info
!= NULL
&& s
!= NULL
)
13493 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13497 if (htab
->elf
.hgot
!= NULL
)
13499 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
13500 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
13505 struct bfd_link_hash_entry
*bh
= NULL
;
13506 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
13507 s
, TOC_BASE_OFF
- adjust
,
13508 NULL
, FALSE
, FALSE
, &bh
);
13514 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
13515 write out any global entry stubs, and PLT relocations. */
13518 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
13520 struct bfd_link_info
*info
;
13521 struct ppc_link_hash_table
*htab
;
13522 struct plt_entry
*ent
;
13525 if (h
->root
.type
== bfd_link_hash_indirect
)
13529 htab
= ppc_hash_table (info
);
13533 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13534 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13536 /* This symbol has an entry in the procedure linkage
13537 table. Set it up. */
13538 Elf_Internal_Rela rela
;
13539 asection
*plt
, *relplt
;
13542 if (!htab
->elf
.dynamic_sections_created
13543 || h
->dynindx
== -1)
13545 if (!(h
->def_regular
13546 && (h
->root
.type
== bfd_link_hash_defined
13547 || h
->root
.type
== bfd_link_hash_defweak
)))
13549 if (h
->type
== STT_GNU_IFUNC
)
13551 plt
= htab
->elf
.iplt
;
13552 relplt
= htab
->elf
.irelplt
;
13553 htab
->local_ifunc_resolver
= 1;
13555 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13557 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13561 plt
= htab
->pltlocal
;
13562 if (bfd_link_pic (info
))
13564 relplt
= htab
->relpltlocal
;
13566 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13568 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13573 rela
.r_addend
= (h
->root
.u
.def
.value
13574 + h
->root
.u
.def
.section
->output_offset
13575 + h
->root
.u
.def
.section
->output_section
->vma
13578 if (relplt
== NULL
)
13580 loc
= plt
->contents
+ ent
->plt
.offset
;
13581 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
13584 bfd_vma toc
= elf_gp (info
->output_bfd
);
13585 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
13586 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13591 rela
.r_offset
= (plt
->output_section
->vma
13592 + plt
->output_offset
13593 + ent
->plt
.offset
);
13594 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13595 * sizeof (Elf64_External_Rela
));
13596 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13601 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
13602 + htab
->elf
.splt
->output_offset
13603 + ent
->plt
.offset
);
13604 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13605 rela
.r_addend
= ent
->addend
;
13606 loc
= (htab
->elf
.srelplt
->contents
13607 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
13608 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
13609 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
13610 htab
->maybe_local_ifunc_resolver
= 1;
13611 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13615 if (!h
->pointer_equality_needed
)
13618 if (h
->def_regular
)
13621 s
= htab
->global_entry
;
13622 if (s
== NULL
|| s
->size
== 0)
13625 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13626 if (ent
->plt
.offset
!= (bfd_vma
) -1
13627 && ent
->addend
== 0)
13633 p
= s
->contents
+ h
->root
.u
.def
.value
;
13634 plt
= htab
->elf
.splt
;
13635 if (!htab
->elf
.dynamic_sections_created
13636 || h
->dynindx
== -1)
13638 if (h
->type
== STT_GNU_IFUNC
)
13639 plt
= htab
->elf
.iplt
;
13641 plt
= htab
->pltlocal
;
13643 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
13644 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
13646 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
13648 info
->callbacks
->einfo
13649 (_("%P: linkage table error against `%pT'\n"),
13650 h
->root
.root
.string
);
13651 bfd_set_error (bfd_error_bad_value
);
13652 htab
->stub_error
= TRUE
;
13655 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
13656 if (htab
->params
->emit_stub_syms
)
13658 size_t len
= strlen (h
->root
.root
.string
);
13659 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
13664 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
13665 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
13668 if (h
->root
.type
== bfd_link_hash_new
)
13670 h
->root
.type
= bfd_link_hash_defined
;
13671 h
->root
.u
.def
.section
= s
;
13672 h
->root
.u
.def
.value
= p
- s
->contents
;
13673 h
->ref_regular
= 1;
13674 h
->def_regular
= 1;
13675 h
->ref_regular_nonweak
= 1;
13676 h
->forced_local
= 1;
13678 h
->root
.linker_def
= 1;
13682 if (PPC_HA (off
) != 0)
13684 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
13687 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
13689 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
13691 bfd_put_32 (s
->owner
, BCTR
, p
);
13697 /* Write PLT relocs for locals. */
13700 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
13702 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13705 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13707 struct got_entry
**lgot_ents
, **end_lgot_ents
;
13708 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13709 Elf_Internal_Shdr
*symtab_hdr
;
13710 bfd_size_type locsymcount
;
13711 Elf_Internal_Sym
*local_syms
= NULL
;
13712 struct plt_entry
*ent
;
13714 if (!is_ppc64_elf (ibfd
))
13717 lgot_ents
= elf_local_got_ents (ibfd
);
13721 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13722 locsymcount
= symtab_hdr
->sh_info
;
13723 end_lgot_ents
= lgot_ents
+ locsymcount
;
13724 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13725 end_local_plt
= local_plt
+ locsymcount
;
13726 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
13727 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
13728 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13730 Elf_Internal_Sym
*sym
;
13732 asection
*plt
, *relplt
;
13736 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
13737 lplt
- local_plt
, ibfd
))
13739 if (local_syms
!= NULL
13740 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13745 val
= sym
->st_value
+ ent
->addend
;
13746 if (ELF_ST_TYPE (sym
->st_info
) != STT_GNU_IFUNC
)
13747 val
+= PPC64_LOCAL_ENTRY_OFFSET (sym
->st_other
);
13748 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
13749 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
13751 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13753 htab
->local_ifunc_resolver
= 1;
13754 plt
= htab
->elf
.iplt
;
13755 relplt
= htab
->elf
.irelplt
;
13759 plt
= htab
->pltlocal
;
13760 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
13763 if (relplt
== NULL
)
13765 loc
= plt
->contents
+ ent
->plt
.offset
;
13766 bfd_put_64 (info
->output_bfd
, val
, loc
);
13769 bfd_vma toc
= elf_gp (ibfd
);
13770 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13775 Elf_Internal_Rela rela
;
13776 rela
.r_offset
= (ent
->plt
.offset
13777 + plt
->output_offset
13778 + plt
->output_section
->vma
);
13779 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13782 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13784 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13789 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13791 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13793 rela
.r_addend
= val
;
13794 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13795 * sizeof (Elf64_External_Rela
));
13796 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13800 if (local_syms
!= NULL
13801 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13803 if (!info
->keep_memory
)
13806 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13812 /* Build all the stubs associated with the current output file.
13813 The stubs are kept in a hash table attached to the main linker
13814 hash table. This function is called via gldelf64ppc_finish. */
13817 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
13820 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13821 struct map_stub
*group
;
13822 asection
*stub_sec
;
13824 int stub_sec_count
= 0;
13829 /* Allocate memory to hold the linker stubs. */
13830 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13832 group
->eh_size
= 0;
13833 group
->lr_restore
= 0;
13834 if ((stub_sec
= group
->stub_sec
) != NULL
13835 && stub_sec
->size
!= 0)
13837 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
13839 if (stub_sec
->contents
== NULL
)
13841 stub_sec
->size
= 0;
13845 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13850 /* Build the .glink plt call stub. */
13851 if (htab
->params
->emit_stub_syms
)
13853 struct elf_link_hash_entry
*h
;
13854 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
13855 TRUE
, FALSE
, FALSE
);
13858 if (h
->root
.type
== bfd_link_hash_new
)
13860 h
->root
.type
= bfd_link_hash_defined
;
13861 h
->root
.u
.def
.section
= htab
->glink
;
13862 h
->root
.u
.def
.value
= 8;
13863 h
->ref_regular
= 1;
13864 h
->def_regular
= 1;
13865 h
->ref_regular_nonweak
= 1;
13866 h
->forced_local
= 1;
13868 h
->root
.linker_def
= 1;
13871 plt0
= (htab
->elf
.splt
->output_section
->vma
13872 + htab
->elf
.splt
->output_offset
13874 if (info
->emitrelocations
)
13876 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
13879 r
->r_offset
= (htab
->glink
->output_offset
13880 + htab
->glink
->output_section
->vma
);
13881 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
13882 r
->r_addend
= plt0
;
13884 p
= htab
->glink
->contents
;
13885 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
13886 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
13890 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
13892 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13894 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13896 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13898 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
13900 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13902 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13904 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
13906 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13908 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
13913 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
13915 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13917 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13919 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
13921 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13923 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
13925 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
13927 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13929 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
13931 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13933 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
13935 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13937 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
13940 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
13942 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
13944 /* Build the .glink lazy link call stubs. */
13946 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
13952 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
13957 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
13959 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
13964 bfd_put_32 (htab
->glink
->owner
,
13965 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
13971 /* Build .glink global entry stubs, and PLT relocs for globals. */
13972 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
13974 if (!write_plt_relocs_for_local_syms (info
))
13977 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
13979 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
13981 if (htab
->brlt
->contents
== NULL
)
13984 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
13986 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
13987 htab
->relbrlt
->size
);
13988 if (htab
->relbrlt
->contents
== NULL
)
13992 /* Build the stubs as directed by the stub hash table. */
13993 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
13995 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13996 if (group
->needs_save_res
)
13997 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13999 if (htab
->relbrlt
!= NULL
)
14000 htab
->relbrlt
->reloc_count
= 0;
14002 if (htab
->params
->plt_stub_align
!= 0)
14003 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14004 if ((stub_sec
= group
->stub_sec
) != NULL
)
14006 int align
= abs (htab
->params
->plt_stub_align
);
14007 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
14010 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14011 if (group
->needs_save_res
)
14013 stub_sec
= group
->stub_sec
;
14014 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
14015 htab
->sfpr
->contents
, htab
->sfpr
->size
);
14016 if (htab
->params
->emit_stub_syms
)
14020 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
14021 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
14026 if (htab
->glink_eh_frame
!= NULL
14027 && htab
->glink_eh_frame
->size
!= 0)
14032 p
= htab
->glink_eh_frame
->contents
;
14033 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
14035 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14036 if (group
->eh_size
!= 0)
14038 /* Offset to stub section. */
14039 val
= (group
->stub_sec
->output_section
->vma
14040 + group
->stub_sec
->output_offset
);
14041 val
-= (htab
->glink_eh_frame
->output_section
->vma
14042 + htab
->glink_eh_frame
->output_offset
14043 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
14044 if (val
+ 0x80000000 > 0xffffffff)
14047 (_("%s offset too large for .eh_frame sdata4 encoding"),
14048 group
->stub_sec
->name
);
14051 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
14052 p
+= (group
->eh_size
+ 17 + 3) & -4;
14054 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
14056 /* Offset to .glink. */
14057 val
= (htab
->glink
->output_section
->vma
14058 + htab
->glink
->output_offset
14060 val
-= (htab
->glink_eh_frame
->output_section
->vma
14061 + htab
->glink_eh_frame
->output_offset
14062 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
14063 if (val
+ 0x80000000 > 0xffffffff)
14066 (_("%s offset too large for .eh_frame sdata4 encoding"),
14067 htab
->glink
->name
);
14070 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
14071 p
+= (24 + align
- 1) & -align
;
14075 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
14076 if ((stub_sec
= group
->stub_sec
) != NULL
)
14078 stub_sec_count
+= 1;
14079 if (stub_sec
->rawsize
!= stub_sec
->size
14080 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
14081 || stub_sec
->rawsize
< stub_sec
->size
))
14087 htab
->stub_error
= TRUE
;
14088 _bfd_error_handler (_("stubs don't match calculated size"));
14091 if (htab
->stub_error
)
14097 *stats
= bfd_malloc (500);
14098 if (*stats
== NULL
)
14101 len
= sprintf (*stats
,
14102 ngettext ("linker stubs in %u group\n",
14103 "linker stubs in %u groups\n",
14106 sprintf (*stats
+ len
, _(" branch %lu\n"
14107 " branch toc adj %lu\n"
14108 " branch notoc %lu\n"
14109 " branch both %lu\n"
14110 " long branch %lu\n"
14111 " long toc adj %lu\n"
14112 " long notoc %lu\n"
14115 " plt call save %lu\n"
14116 " plt call notoc %lu\n"
14117 " plt call both %lu\n"
14118 " global entry %lu"),
14119 htab
->stub_count
[ppc_stub_long_branch
- 1],
14120 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
14121 htab
->stub_count
[ppc_stub_long_branch_notoc
- 1],
14122 htab
->stub_count
[ppc_stub_long_branch_both
- 1],
14123 htab
->stub_count
[ppc_stub_plt_branch
- 1],
14124 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
14125 htab
->stub_count
[ppc_stub_plt_branch_notoc
- 1],
14126 htab
->stub_count
[ppc_stub_plt_branch_both
- 1],
14127 htab
->stub_count
[ppc_stub_plt_call
- 1],
14128 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
14129 htab
->stub_count
[ppc_stub_plt_call_notoc
- 1],
14130 htab
->stub_count
[ppc_stub_plt_call_both
- 1],
14131 htab
->stub_count
[ppc_stub_global_entry
- 1]);
14136 /* What to do when ld finds relocations against symbols defined in
14137 discarded sections. */
14139 static unsigned int
14140 ppc64_elf_action_discarded (asection
*sec
)
14142 if (strcmp (".opd", sec
->name
) == 0)
14145 if (strcmp (".toc", sec
->name
) == 0)
14148 if (strcmp (".toc1", sec
->name
) == 0)
14151 return _bfd_elf_default_action_discarded (sec
);
14154 /* These are the dynamic relocations supported by glibc. */
14157 ppc64_glibc_dynamic_reloc (enum elf_ppc64_reloc_type r_type
)
14161 case R_PPC64_RELATIVE
:
14163 case R_PPC64_ADDR64
:
14164 case R_PPC64_GLOB_DAT
:
14165 case R_PPC64_IRELATIVE
:
14166 case R_PPC64_JMP_IREL
:
14167 case R_PPC64_JMP_SLOT
:
14168 case R_PPC64_DTPMOD64
:
14169 case R_PPC64_DTPREL64
:
14170 case R_PPC64_TPREL64
:
14171 case R_PPC64_TPREL16_LO_DS
:
14172 case R_PPC64_TPREL16_DS
:
14173 case R_PPC64_TPREL16
:
14174 case R_PPC64_TPREL16_LO
:
14175 case R_PPC64_TPREL16_HI
:
14176 case R_PPC64_TPREL16_HIGH
:
14177 case R_PPC64_TPREL16_HA
:
14178 case R_PPC64_TPREL16_HIGHA
:
14179 case R_PPC64_TPREL16_HIGHER
:
14180 case R_PPC64_TPREL16_HIGHEST
:
14181 case R_PPC64_TPREL16_HIGHERA
:
14182 case R_PPC64_TPREL16_HIGHESTA
:
14183 case R_PPC64_ADDR16_LO_DS
:
14184 case R_PPC64_ADDR16_LO
:
14185 case R_PPC64_ADDR16_HI
:
14186 case R_PPC64_ADDR16_HIGH
:
14187 case R_PPC64_ADDR16_HA
:
14188 case R_PPC64_ADDR16_HIGHA
:
14189 case R_PPC64_REL30
:
14191 case R_PPC64_UADDR64
:
14192 case R_PPC64_UADDR32
:
14193 case R_PPC64_ADDR32
:
14194 case R_PPC64_ADDR24
:
14195 case R_PPC64_ADDR16
:
14196 case R_PPC64_UADDR16
:
14197 case R_PPC64_ADDR16_DS
:
14198 case R_PPC64_ADDR16_HIGHER
:
14199 case R_PPC64_ADDR16_HIGHEST
:
14200 case R_PPC64_ADDR16_HIGHERA
:
14201 case R_PPC64_ADDR16_HIGHESTA
:
14202 case R_PPC64_ADDR14
:
14203 case R_PPC64_ADDR14_BRTAKEN
:
14204 case R_PPC64_ADDR14_BRNTAKEN
:
14205 case R_PPC64_REL32
:
14206 case R_PPC64_REL64
:
14214 /* The RELOCATE_SECTION function is called by the ELF backend linker
14215 to handle the relocations for a section.
14217 The relocs are always passed as Rela structures; if the section
14218 actually uses Rel structures, the r_addend field will always be
14221 This function is responsible for adjust the section contents as
14222 necessary, and (if using Rela relocs and generating a
14223 relocatable output file) adjusting the reloc addend as
14226 This function does not have to worry about setting the reloc
14227 address or the reloc symbol index.
14229 LOCAL_SYMS is a pointer to the swapped in local symbols.
14231 LOCAL_SECTIONS is an array giving the section in the input file
14232 corresponding to the st_shndx field of each local symbol.
14234 The global hash table entry for the global symbols can be found
14235 via elf_sym_hashes (input_bfd).
14237 When generating relocatable output, this function must handle
14238 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
14239 going to be the section symbol corresponding to the output
14240 section, which means that the addend must be adjusted
14244 ppc64_elf_relocate_section (bfd
*output_bfd
,
14245 struct bfd_link_info
*info
,
14247 asection
*input_section
,
14248 bfd_byte
*contents
,
14249 Elf_Internal_Rela
*relocs
,
14250 Elf_Internal_Sym
*local_syms
,
14251 asection
**local_sections
)
14253 struct ppc_link_hash_table
*htab
;
14254 Elf_Internal_Shdr
*symtab_hdr
;
14255 struct elf_link_hash_entry
**sym_hashes
;
14256 Elf_Internal_Rela
*rel
;
14257 Elf_Internal_Rela
*wrel
;
14258 Elf_Internal_Rela
*relend
;
14259 Elf_Internal_Rela outrel
;
14261 struct got_entry
**local_got_ents
;
14263 bfd_boolean ret
= TRUE
;
14264 bfd_boolean is_opd
;
14265 /* Assume 'at' branch hints. */
14266 bfd_boolean is_isa_v2
= TRUE
;
14267 bfd_boolean warned_dynamic
= FALSE
;
14268 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
14270 /* Initialize howto table if needed. */
14271 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
14274 htab
= ppc_hash_table (info
);
14278 /* Don't relocate stub sections. */
14279 if (input_section
->owner
== htab
->params
->stub_bfd
)
14282 if (!is_ppc64_elf (input_bfd
))
14284 bfd_set_error (bfd_error_wrong_format
);
14288 local_got_ents
= elf_local_got_ents (input_bfd
);
14289 TOCstart
= elf_gp (output_bfd
);
14290 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
14291 sym_hashes
= elf_sym_hashes (input_bfd
);
14292 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
14294 rel
= wrel
= relocs
;
14295 relend
= relocs
+ input_section
->reloc_count
;
14296 for (; rel
< relend
; wrel
++, rel
++)
14298 enum elf_ppc64_reloc_type r_type
;
14300 bfd_reloc_status_type r
;
14301 Elf_Internal_Sym
*sym
;
14303 struct elf_link_hash_entry
*h_elf
;
14304 struct ppc_link_hash_entry
*h
;
14305 struct ppc_link_hash_entry
*fdh
;
14306 const char *sym_name
;
14307 unsigned long r_symndx
, toc_symndx
;
14308 bfd_vma toc_addend
;
14309 unsigned char tls_mask
, tls_gd
, tls_type
;
14310 unsigned char sym_type
;
14311 bfd_vma relocation
;
14312 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
14313 bfd_boolean warned
;
14314 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
14317 struct ppc_stub_hash_entry
*stub_entry
;
14318 bfd_vma max_br_offset
;
14320 Elf_Internal_Rela orig_rel
;
14321 reloc_howto_type
*howto
;
14322 struct reloc_howto_struct alt_howto
;
14329 r_type
= ELF64_R_TYPE (rel
->r_info
);
14330 r_symndx
= ELF64_R_SYM (rel
->r_info
);
14332 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
14333 symbol of the previous ADDR64 reloc. The symbol gives us the
14334 proper TOC base to use. */
14335 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
14337 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
14339 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
14345 unresolved_reloc
= FALSE
;
14348 if (r_symndx
< symtab_hdr
->sh_info
)
14350 /* It's a local symbol. */
14351 struct _opd_sec_data
*opd
;
14353 sym
= local_syms
+ r_symndx
;
14354 sec
= local_sections
[r_symndx
];
14355 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
14356 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
14357 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
14358 opd
= get_opd_info (sec
);
14359 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
14361 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
14367 /* If this is a relocation against the opd section sym
14368 and we have edited .opd, adjust the reloc addend so
14369 that ld -r and ld --emit-relocs output is correct.
14370 If it is a reloc against some other .opd symbol,
14371 then the symbol value will be adjusted later. */
14372 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
14373 rel
->r_addend
+= adjust
;
14375 relocation
+= adjust
;
14381 bfd_boolean ignored
;
14383 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
14384 r_symndx
, symtab_hdr
, sym_hashes
,
14385 h_elf
, sec
, relocation
,
14386 unresolved_reloc
, warned
, ignored
);
14387 sym_name
= h_elf
->root
.root
.string
;
14388 sym_type
= h_elf
->type
;
14390 && sec
->owner
== output_bfd
14391 && strcmp (sec
->name
, ".opd") == 0)
14393 /* This is a symbol defined in a linker script. All
14394 such are defined in output sections, even those
14395 defined by simple assignment from a symbol defined in
14396 an input section. Transfer the symbol to an
14397 appropriate input .opd section, so that a branch to
14398 this symbol will be mapped to the location specified
14399 by the opd entry. */
14400 struct bfd_link_order
*lo
;
14401 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
14402 if (lo
->type
== bfd_indirect_link_order
)
14404 asection
*isec
= lo
->u
.indirect
.section
;
14405 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
14406 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
14409 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
14410 h_elf
->root
.u
.def
.section
= isec
;
14417 h
= (struct ppc_link_hash_entry
*) h_elf
;
14419 if (sec
!= NULL
&& discarded_section (sec
))
14421 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
14422 input_bfd
, input_section
,
14423 contents
, rel
->r_offset
);
14424 wrel
->r_offset
= rel
->r_offset
;
14426 wrel
->r_addend
= 0;
14428 /* For ld -r, remove relocations in debug sections against
14429 symbols defined in discarded sections. Not done for
14430 non-debug to preserve relocs in .eh_frame which the
14431 eh_frame editing code expects to be present. */
14432 if (bfd_link_relocatable (info
)
14433 && (input_section
->flags
& SEC_DEBUGGING
))
14439 if (bfd_link_relocatable (info
))
14442 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
14444 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14445 sec
= bfd_abs_section_ptr
;
14446 unresolved_reloc
= FALSE
;
14449 /* TLS optimizations. Replace instruction sequences and relocs
14450 based on information we collected in tls_optimize. We edit
14451 RELOCS so that --emit-relocs will output something sensible
14452 for the final instruction stream. */
14457 tls_mask
= h
->tls_mask
;
14458 else if (local_got_ents
!= NULL
)
14460 struct plt_entry
**local_plt
= (struct plt_entry
**)
14461 (local_got_ents
+ symtab_hdr
->sh_info
);
14462 unsigned char *lgot_masks
= (unsigned char *)
14463 (local_plt
+ symtab_hdr
->sh_info
);
14464 tls_mask
= lgot_masks
[r_symndx
];
14466 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
14467 && (r_type
== R_PPC64_TLS
14468 || r_type
== R_PPC64_TLSGD
14469 || r_type
== R_PPC64_TLSLD
))
14471 /* Check for toc tls entries. */
14472 unsigned char *toc_tls
;
14474 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
14475 &local_syms
, rel
, input_bfd
))
14479 tls_mask
= *toc_tls
;
14482 /* Check that tls relocs are used with tls syms, and non-tls
14483 relocs are used with non-tls syms. */
14484 if (r_symndx
!= STN_UNDEF
14485 && r_type
!= R_PPC64_NONE
14487 || h
->elf
.root
.type
== bfd_link_hash_defined
14488 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
14489 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
14491 if ((tls_mask
& TLS_TLS
) != 0
14492 && (r_type
== R_PPC64_TLS
14493 || r_type
== R_PPC64_TLSGD
14494 || r_type
== R_PPC64_TLSLD
))
14495 /* R_PPC64_TLS is OK against a symbol in the TOC. */
14498 info
->callbacks
->einfo
14499 (!IS_PPC64_TLS_RELOC (r_type
)
14500 /* xgettext:c-format */
14501 ? _("%H: %s used with TLS symbol `%pT'\n")
14502 /* xgettext:c-format */
14503 : _("%H: %s used with non-TLS symbol `%pT'\n"),
14504 input_bfd
, input_section
, rel
->r_offset
,
14505 ppc64_elf_howto_table
[r_type
]->name
,
14509 /* Ensure reloc mapping code below stays sane. */
14510 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
14511 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
14512 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
14513 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
14514 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
14515 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
14516 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
14517 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
14518 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
14519 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
14527 case R_PPC64_LO_DS_OPT
:
14528 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
14529 if ((insn
& (0x3f << 26)) != 58u << 26)
14531 insn
+= (14u << 26) - (58u << 26);
14532 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
14533 r_type
= R_PPC64_TOC16_LO
;
14534 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14537 case R_PPC64_TOC16
:
14538 case R_PPC64_TOC16_LO
:
14539 case R_PPC64_TOC16_DS
:
14540 case R_PPC64_TOC16_LO_DS
:
14542 /* Check for toc tls entries. */
14543 unsigned char *toc_tls
;
14546 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
14547 &local_syms
, rel
, input_bfd
);
14553 tls_mask
= *toc_tls
;
14554 if (r_type
== R_PPC64_TOC16_DS
14555 || r_type
== R_PPC64_TOC16_LO_DS
)
14557 if ((tls_mask
& TLS_TLS
) != 0
14558 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
14563 /* If we found a GD reloc pair, then we might be
14564 doing a GD->IE transition. */
14568 if ((tls_mask
& TLS_TLS
) != 0
14569 && (tls_mask
& TLS_GD
) == 0)
14572 else if (retval
== 3)
14574 if ((tls_mask
& TLS_TLS
) != 0
14575 && (tls_mask
& TLS_LD
) == 0)
14583 case R_PPC64_GOT_TPREL16_HI
:
14584 case R_PPC64_GOT_TPREL16_HA
:
14585 if ((tls_mask
& TLS_TLS
) != 0
14586 && (tls_mask
& TLS_TPREL
) == 0)
14588 rel
->r_offset
-= d_offset
;
14589 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14590 r_type
= R_PPC64_NONE
;
14591 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14595 case R_PPC64_GOT_TPREL16_DS
:
14596 case R_PPC64_GOT_TPREL16_LO_DS
:
14597 if ((tls_mask
& TLS_TLS
) != 0
14598 && (tls_mask
& TLS_TPREL
) == 0)
14601 insn
= bfd_get_32 (input_bfd
,
14602 contents
+ rel
->r_offset
- d_offset
);
14604 insn
|= 0x3c0d0000; /* addis 0,13,0 */
14605 bfd_put_32 (input_bfd
, insn
,
14606 contents
+ rel
->r_offset
- d_offset
);
14607 r_type
= R_PPC64_TPREL16_HA
;
14608 if (toc_symndx
!= 0)
14610 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
14611 rel
->r_addend
= toc_addend
;
14612 /* We changed the symbol. Start over in order to
14613 get h, sym, sec etc. right. */
14617 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14621 case R_PPC64_GOT_TPREL34
:
14622 if ((tls_mask
& TLS_TLS
) != 0
14623 && (tls_mask
& TLS_TPREL
) == 0)
14625 /* pld ra,sym@got@tprel@pcrel -> paddi ra,r13,sym@tprel */
14626 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14628 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14629 pinsn
+= ((2ULL << 56) + (-1ULL << 52)
14630 + (14ULL << 26) - (57ULL << 26) + (13ULL << 16));
14631 bfd_put_32 (input_bfd
, pinsn
>> 32,
14632 contents
+ rel
->r_offset
);
14633 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
14634 contents
+ rel
->r_offset
+ 4);
14635 r_type
= R_PPC64_TPREL34
;
14636 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14641 if ((tls_mask
& TLS_TLS
) != 0
14642 && (tls_mask
& TLS_TPREL
) == 0)
14644 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
14645 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
14648 if ((rel
->r_offset
& 3) == 0)
14650 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14651 /* Was PPC64_TLS which sits on insn boundary, now
14652 PPC64_TPREL16_LO which is at low-order half-word. */
14653 rel
->r_offset
+= d_offset
;
14654 r_type
= R_PPC64_TPREL16_LO
;
14655 if (toc_symndx
!= 0)
14657 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
14658 rel
->r_addend
= toc_addend
;
14659 /* We changed the symbol. Start over in order to
14660 get h, sym, sec etc. right. */
14664 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14666 else if ((rel
->r_offset
& 3) == 1)
14668 /* For pcrel IE to LE we already have the full
14669 offset and thus don't need an addi here. A nop
14671 if ((insn
& (0x3f << 26)) == 14 << 26)
14673 /* Extract regs from addi rt,ra,si. */
14674 unsigned int rt
= (insn
>> 21) & 0x1f;
14675 unsigned int ra
= (insn
>> 16) & 0x1f;
14680 /* Build or ra,rs,rb with rb==rs, ie. mr ra,rs. */
14681 insn
= (rt
<< 16) | (ra
<< 21) | (ra
<< 11);
14682 insn
|= (31u << 26) | (444u << 1);
14685 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- 1);
14690 case R_PPC64_GOT_TLSGD16_HI
:
14691 case R_PPC64_GOT_TLSGD16_HA
:
14693 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14697 case R_PPC64_GOT_TLSLD16_HI
:
14698 case R_PPC64_GOT_TLSLD16_HA
:
14699 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14702 if ((tls_mask
& tls_gd
) != 0)
14703 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
14704 + R_PPC64_GOT_TPREL16_DS
);
14707 rel
->r_offset
-= d_offset
;
14708 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14709 r_type
= R_PPC64_NONE
;
14711 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14715 case R_PPC64_GOT_TLSGD16
:
14716 case R_PPC64_GOT_TLSGD16_LO
:
14718 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14722 case R_PPC64_GOT_TLSLD16
:
14723 case R_PPC64_GOT_TLSLD16_LO
:
14724 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14726 unsigned int insn1
, insn2
;
14729 offset
= (bfd_vma
) -1;
14730 /* If not using the newer R_PPC64_TLSGD/LD to mark
14731 __tls_get_addr calls, we must trust that the call
14732 stays with its arg setup insns, ie. that the next
14733 reloc is the __tls_get_addr call associated with
14734 the current reloc. Edit both insns. */
14735 if (input_section
->nomark_tls_get_addr
14736 && rel
+ 1 < relend
14737 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
14738 htab
->tls_get_addr
,
14739 htab
->tls_get_addr_fd
))
14740 offset
= rel
[1].r_offset
;
14741 /* We read the low GOT_TLS (or TOC16) insn because we
14742 need to keep the destination reg. It may be
14743 something other than the usual r3, and moved to r3
14744 before the call by intervening code. */
14745 insn1
= bfd_get_32 (input_bfd
,
14746 contents
+ rel
->r_offset
- d_offset
);
14747 if ((tls_mask
& tls_gd
) != 0)
14750 insn1
&= (0x1f << 21) | (0x1f << 16);
14751 insn1
|= 58 << 26; /* ld */
14752 insn2
= 0x7c636a14; /* add 3,3,13 */
14753 if (offset
!= (bfd_vma
) -1)
14754 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14755 if (r_type
== R_PPC64_TOC16
14756 || r_type
== R_PPC64_TOC16_LO
)
14757 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
14759 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 1)) & 1)
14760 + R_PPC64_GOT_TPREL16_DS
);
14761 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14766 insn1
&= 0x1f << 21;
14767 insn1
|= 0x3c0d0000; /* addis r,13,0 */
14768 insn2
= 0x38630000; /* addi 3,3,0 */
14771 /* Was an LD reloc. */
14772 r_symndx
= STN_UNDEF
;
14773 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14775 else if (toc_symndx
!= 0)
14777 r_symndx
= toc_symndx
;
14778 rel
->r_addend
= toc_addend
;
14780 r_type
= R_PPC64_TPREL16_HA
;
14781 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14782 if (offset
!= (bfd_vma
) -1)
14784 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
14785 R_PPC64_TPREL16_LO
);
14786 rel
[1].r_offset
= offset
+ d_offset
;
14787 rel
[1].r_addend
= rel
->r_addend
;
14790 bfd_put_32 (input_bfd
, insn1
,
14791 contents
+ rel
->r_offset
- d_offset
);
14792 if (offset
!= (bfd_vma
) -1)
14794 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14795 if (offset
+ 8 <= input_section
->size
)
14797 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14798 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
14799 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
14802 if ((tls_mask
& tls_gd
) == 0
14803 && (tls_gd
== 0 || toc_symndx
!= 0))
14805 /* We changed the symbol. Start over in order
14806 to get h, sym, sec etc. right. */
14812 case R_PPC64_GOT_TLSGD34
:
14813 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14815 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14817 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14818 if ((tls_mask
& TLS_GDIE
) != 0)
14820 /* IE, pla -> pld */
14821 pinsn
+= (-2ULL << 56) + (57ULL << 26) - (14ULL << 26);
14822 r_type
= R_PPC64_GOT_TPREL34
;
14826 /* LE, pla pcrel -> paddi r13 */
14827 pinsn
+= (-1ULL << 52) + (13ULL << 16);
14828 r_type
= R_PPC64_TPREL34
;
14830 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14831 bfd_put_32 (input_bfd
, pinsn
>> 32,
14832 contents
+ rel
->r_offset
);
14833 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
14834 contents
+ rel
->r_offset
+ 4);
14838 case R_PPC64_GOT_TLSLD34
:
14839 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14841 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14843 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14844 pinsn
+= (-1ULL << 52) + (13ULL << 16);
14845 bfd_put_32 (input_bfd
, pinsn
>> 32,
14846 contents
+ rel
->r_offset
);
14847 bfd_put_32 (input_bfd
, pinsn
& 0xffffffff,
14848 contents
+ rel
->r_offset
+ 4);
14849 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14850 r_symndx
= STN_UNDEF
;
14851 r_type
= R_PPC64_TPREL34
;
14852 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14857 case R_PPC64_TLSGD
:
14858 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
14859 && rel
+ 1 < relend
)
14861 unsigned int insn2
;
14862 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
14864 offset
= rel
->r_offset
;
14865 if (is_plt_seq_reloc (r_type1
))
14867 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14868 if (r_type1
== R_PPC64_PLT_PCREL34
14869 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
14870 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14871 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14875 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14876 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14878 if ((tls_mask
& TLS_GDIE
) != 0)
14881 r_type
= R_PPC64_NONE
;
14882 insn2
= 0x7c636a14; /* add 3,3,13 */
14887 if (toc_symndx
!= 0)
14889 r_symndx
= toc_symndx
;
14890 rel
->r_addend
= toc_addend
;
14892 if (r_type1
== R_PPC64_REL24_NOTOC
14893 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
14895 r_type
= R_PPC64_NONE
;
14900 rel
->r_offset
= offset
+ d_offset
;
14901 r_type
= R_PPC64_TPREL16_LO
;
14902 insn2
= 0x38630000; /* addi 3,3,0 */
14905 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14906 /* Zap the reloc on the _tls_get_addr call too. */
14907 BFD_ASSERT (offset
== rel
[1].r_offset
);
14908 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14909 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14910 if ((tls_mask
& TLS_GDIE
) == 0
14912 && r_type
!= R_PPC64_NONE
)
14917 case R_PPC64_TLSLD
:
14918 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
14919 && rel
+ 1 < relend
)
14921 unsigned int insn2
;
14922 enum elf_ppc64_reloc_type r_type1
= ELF64_R_TYPE (rel
[1].r_info
);
14924 offset
= rel
->r_offset
;
14925 if (is_plt_seq_reloc (r_type1
))
14927 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14928 if (r_type1
== R_PPC64_PLT_PCREL34
14929 || r_type1
== R_PPC64_PLT_PCREL34_NOTOC
)
14930 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14931 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14935 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14936 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14938 if (r_type1
== R_PPC64_REL24_NOTOC
14939 || r_type1
== R_PPC64_PLTCALL_NOTOC
)
14941 r_type
= R_PPC64_NONE
;
14946 rel
->r_offset
= offset
+ d_offset
;
14947 r_symndx
= STN_UNDEF
;
14948 r_type
= R_PPC64_TPREL16_LO
;
14949 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14950 insn2
= 0x38630000; /* addi 3,3,0 */
14952 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14953 /* Zap the reloc on the _tls_get_addr call too. */
14954 BFD_ASSERT (offset
== rel
[1].r_offset
);
14955 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14956 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14957 if (r_type
!= R_PPC64_NONE
)
14962 case R_PPC64_DTPMOD64
:
14963 if (rel
+ 1 < relend
14964 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
14965 && rel
[1].r_offset
== rel
->r_offset
+ 8)
14967 if ((tls_mask
& TLS_GD
) == 0)
14969 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
14970 if ((tls_mask
& TLS_GDIE
) != 0)
14971 r_type
= R_PPC64_TPREL64
;
14974 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14975 r_type
= R_PPC64_NONE
;
14977 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14982 if ((tls_mask
& TLS_LD
) == 0)
14984 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14985 r_type
= R_PPC64_NONE
;
14986 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14991 case R_PPC64_TPREL64
:
14992 if ((tls_mask
& TLS_TPREL
) == 0)
14994 r_type
= R_PPC64_NONE
;
14995 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14999 case R_PPC64_ENTRY
:
15000 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15001 if (!bfd_link_pic (info
)
15002 && !info
->traditional_format
15003 && relocation
+ 0x80008000 <= 0xffffffff)
15005 unsigned int insn1
, insn2
;
15007 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15008 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15009 if ((insn1
& ~0xfffc) == LD_R2_0R12
15010 && insn2
== ADD_R2_R2_R12
)
15012 bfd_put_32 (input_bfd
,
15013 LIS_R2
+ PPC_HA (relocation
),
15014 contents
+ rel
->r_offset
);
15015 bfd_put_32 (input_bfd
,
15016 ADDI_R2_R2
+ PPC_LO (relocation
),
15017 contents
+ rel
->r_offset
+ 4);
15022 relocation
-= (rel
->r_offset
15023 + input_section
->output_offset
15024 + input_section
->output_section
->vma
);
15025 if (relocation
+ 0x80008000 <= 0xffffffff)
15027 unsigned int insn1
, insn2
;
15029 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15030 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
15031 if ((insn1
& ~0xfffc) == LD_R2_0R12
15032 && insn2
== ADD_R2_R2_R12
)
15034 bfd_put_32 (input_bfd
,
15035 ADDIS_R2_R12
+ PPC_HA (relocation
),
15036 contents
+ rel
->r_offset
);
15037 bfd_put_32 (input_bfd
,
15038 ADDI_R2_R2
+ PPC_LO (relocation
),
15039 contents
+ rel
->r_offset
+ 4);
15045 case R_PPC64_REL16_HA
:
15046 /* If we are generating a non-PIC executable, edit
15047 . 0: addis 2,12,.TOC.-0b@ha
15048 . addi 2,2,.TOC.-0b@l
15049 used by ELFv2 global entry points to set up r2, to
15052 if .TOC. is in range. */
15053 if (!bfd_link_pic (info
)
15054 && !info
->traditional_format
15056 && rel
->r_addend
== d_offset
15057 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
15058 && rel
+ 1 < relend
15059 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
15060 && rel
[1].r_offset
== rel
->r_offset
+ 4
15061 && rel
[1].r_addend
== rel
->r_addend
+ 4
15062 && relocation
+ 0x80008000 <= 0xffffffff)
15064 unsigned int insn1
, insn2
;
15065 offset
= rel
->r_offset
- d_offset
;
15066 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
15067 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15068 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
15069 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
15071 r_type
= R_PPC64_ADDR16_HA
;
15072 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15073 rel
->r_addend
-= d_offset
;
15074 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
15075 rel
[1].r_addend
-= d_offset
+ 4;
15076 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
15082 /* Handle other relocations that tweak non-addend part of insn. */
15084 max_br_offset
= 1 << 25;
15085 addend
= rel
->r_addend
;
15086 reloc_dest
= DEST_NORMAL
;
15092 case R_PPC64_TOCSAVE
:
15093 if (relocation
+ addend
== (rel
->r_offset
15094 + input_section
->output_offset
15095 + input_section
->output_section
->vma
)
15096 && tocsave_find (htab
, NO_INSERT
,
15097 &local_syms
, rel
, input_bfd
))
15099 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15101 || insn
== CROR_151515
|| insn
== CROR_313131
)
15102 bfd_put_32 (input_bfd
,
15103 STD_R2_0R1
+ STK_TOC (htab
),
15104 contents
+ rel
->r_offset
);
15108 /* Branch taken prediction relocations. */
15109 case R_PPC64_ADDR14_BRTAKEN
:
15110 case R_PPC64_REL14_BRTAKEN
:
15111 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
15112 /* Fall through. */
15114 /* Branch not taken prediction relocations. */
15115 case R_PPC64_ADDR14_BRNTAKEN
:
15116 case R_PPC64_REL14_BRNTAKEN
:
15117 insn
|= bfd_get_32 (input_bfd
,
15118 contents
+ rel
->r_offset
) & ~(0x01 << 21);
15119 /* Fall through. */
15121 case R_PPC64_REL14
:
15122 max_br_offset
= 1 << 15;
15123 /* Fall through. */
15125 case R_PPC64_REL24
:
15126 case R_PPC64_REL24_NOTOC
:
15127 case R_PPC64_PLTCALL
:
15128 case R_PPC64_PLTCALL_NOTOC
:
15129 /* Calls to functions with a different TOC, such as calls to
15130 shared objects, need to alter the TOC pointer. This is
15131 done using a linkage stub. A REL24 branching to these
15132 linkage stubs needs to be followed by a nop, as the nop
15133 will be replaced with an instruction to restore the TOC
15138 && h
->oh
->is_func_descriptor
)
15139 fdh
= ppc_follow_link (h
->oh
);
15140 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
15142 if ((r_type
== R_PPC64_PLTCALL
15143 || r_type
== R_PPC64_PLTCALL_NOTOC
)
15144 && stub_entry
!= NULL
15145 && stub_entry
->stub_type
>= ppc_stub_plt_call
15146 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15149 if (stub_entry
!= NULL
15150 && ((stub_entry
->stub_type
>= ppc_stub_plt_call
15151 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15152 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
15153 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
15154 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
15155 || stub_entry
->stub_type
== ppc_stub_long_branch_both
))
15157 bfd_boolean can_plt_call
= FALSE
;
15159 if (stub_entry
->stub_type
== ppc_stub_plt_call
15161 && htab
->params
->plt_localentry0
!= 0
15162 && is_elfv2_localentry0 (&h
->elf
))
15164 /* The function doesn't use or change r2. */
15165 can_plt_call
= TRUE
;
15167 else if (r_type
== R_PPC64_REL24_NOTOC
)
15169 /* NOTOC calls don't need to restore r2. */
15170 can_plt_call
= TRUE
;
15173 /* All of these stubs may modify r2, so there must be a
15174 branch and link followed by a nop. The nop is
15175 replaced by an insn to restore r2. */
15176 else if (rel
->r_offset
+ 8 <= input_section
->size
)
15180 br
= bfd_get_32 (input_bfd
,
15181 contents
+ rel
->r_offset
);
15186 nop
= bfd_get_32 (input_bfd
,
15187 contents
+ rel
->r_offset
+ 4);
15188 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
15189 can_plt_call
= TRUE
;
15190 else if (nop
== NOP
15191 || nop
== CROR_151515
15192 || nop
== CROR_313131
)
15195 && (h
== htab
->tls_get_addr_fd
15196 || h
== htab
->tls_get_addr
)
15197 && htab
->params
->tls_get_addr_opt
)
15199 /* Special stub used, leave nop alone. */
15202 bfd_put_32 (input_bfd
,
15203 LD_R2_0R1
+ STK_TOC (htab
),
15204 contents
+ rel
->r_offset
+ 4);
15205 can_plt_call
= TRUE
;
15210 if (!can_plt_call
&& h
!= NULL
)
15212 const char *name
= h
->elf
.root
.root
.string
;
15217 if (strncmp (name
, "__libc_start_main", 17) == 0
15218 && (name
[17] == 0 || name
[17] == '@'))
15220 /* Allow crt1 branch to go via a toc adjusting
15221 stub. Other calls that never return could do
15222 the same, if we could detect such. */
15223 can_plt_call
= TRUE
;
15229 /* g++ as of 20130507 emits self-calls without a
15230 following nop. This is arguably wrong since we
15231 have conflicting information. On the one hand a
15232 global symbol and on the other a local call
15233 sequence, but don't error for this special case.
15234 It isn't possible to cheaply verify we have
15235 exactly such a call. Allow all calls to the same
15237 asection
*code_sec
= sec
;
15239 if (get_opd_info (sec
) != NULL
)
15241 bfd_vma off
= (relocation
+ addend
15242 - sec
->output_section
->vma
15243 - sec
->output_offset
);
15245 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
15247 if (code_sec
== input_section
)
15248 can_plt_call
= TRUE
;
15253 if (stub_entry
->stub_type
>= ppc_stub_plt_call
15254 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15255 info
->callbacks
->einfo
15256 /* xgettext:c-format */
15257 (_("%H: call to `%pT' lacks nop, can't restore toc; "
15258 "(plt call stub)\n"),
15259 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
15261 info
->callbacks
->einfo
15262 /* xgettext:c-format */
15263 (_("%H: call to `%pT' lacks nop, can't restore toc; "
15264 "(toc save/adjust stub)\n"),
15265 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
15267 bfd_set_error (bfd_error_bad_value
);
15272 && stub_entry
->stub_type
>= ppc_stub_plt_call
15273 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
15274 unresolved_reloc
= FALSE
;
15277 if ((stub_entry
== NULL
15278 || stub_entry
->stub_type
== ppc_stub_long_branch
15279 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
15280 && get_opd_info (sec
) != NULL
)
15282 /* The branch destination is the value of the opd entry. */
15283 bfd_vma off
= (relocation
+ addend
15284 - sec
->output_section
->vma
15285 - sec
->output_offset
);
15286 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
15287 if (dest
!= (bfd_vma
) -1)
15291 reloc_dest
= DEST_OPD
;
15295 /* If the branch is out of reach we ought to have a long
15297 from
= (rel
->r_offset
15298 + input_section
->output_offset
15299 + input_section
->output_section
->vma
);
15301 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
15305 if (stub_entry
!= NULL
15306 && (stub_entry
->stub_type
== ppc_stub_long_branch
15307 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
15308 && (r_type
== R_PPC64_ADDR14_BRTAKEN
15309 || r_type
== R_PPC64_ADDR14_BRNTAKEN
15310 || (relocation
+ addend
- from
+ max_br_offset
15311 < 2 * max_br_offset
)))
15312 /* Don't use the stub if this branch is in range. */
15315 if (stub_entry
!= NULL
15316 && (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
15317 || stub_entry
->stub_type
== ppc_stub_long_branch_both
15318 || stub_entry
->stub_type
== ppc_stub_plt_branch_notoc
15319 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
15320 && (r_type
!= R_PPC64_REL24_NOTOC
15321 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
15322 & STO_PPC64_LOCAL_MASK
) <= 1 << STO_PPC64_LOCAL_BIT
)
15323 && (relocation
+ addend
- from
+ max_br_offset
15324 < 2 * max_br_offset
))
15327 if (stub_entry
!= NULL
15328 && (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
15329 || stub_entry
->stub_type
== ppc_stub_long_branch_both
15330 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
15331 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
15332 && r_type
== R_PPC64_REL24_NOTOC
15333 && (relocation
+ addend
- from
+ max_br_offset
15334 < 2 * max_br_offset
))
15337 if (stub_entry
!= NULL
)
15339 /* Munge up the value and addend so that we call the stub
15340 rather than the procedure directly. */
15341 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
15343 if (stub_entry
->stub_type
== ppc_stub_save_res
)
15344 relocation
+= (stub_sec
->output_offset
15345 + stub_sec
->output_section
->vma
15346 + stub_sec
->size
- htab
->sfpr
->size
15347 - htab
->sfpr
->output_offset
15348 - htab
->sfpr
->output_section
->vma
);
15350 relocation
= (stub_entry
->stub_offset
15351 + stub_sec
->output_offset
15352 + stub_sec
->output_section
->vma
);
15354 reloc_dest
= DEST_STUB
;
15356 if (((stub_entry
->stub_type
== ppc_stub_plt_call
15357 && ALWAYS_EMIT_R2SAVE
)
15358 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
15359 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
15361 && (h
== htab
->tls_get_addr_fd
15362 || h
== htab
->tls_get_addr
)
15363 && htab
->params
->tls_get_addr_opt
)
15364 && rel
+ 1 < relend
15365 && rel
[1].r_offset
== rel
->r_offset
+ 4
15366 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
15368 else if ((stub_entry
->stub_type
== ppc_stub_long_branch_both
15369 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
15370 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
15371 && r_type
== R_PPC64_REL24_NOTOC
)
15374 if (r_type
== R_PPC64_REL24_NOTOC
15375 && (stub_entry
->stub_type
== ppc_stub_plt_call_notoc
15376 || stub_entry
->stub_type
== ppc_stub_plt_call_both
))
15377 htab
->notoc_plt
= 1;
15384 /* Set 'a' bit. This is 0b00010 in BO field for branch
15385 on CR(BI) insns (BO == 001at or 011at), and 0b01000
15386 for branch on CTR insns (BO == 1a00t or 1a01t). */
15387 if ((insn
& (0x14 << 21)) == (0x04 << 21))
15388 insn
|= 0x02 << 21;
15389 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
15390 insn
|= 0x08 << 21;
15396 /* Invert 'y' bit if not the default. */
15397 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
15398 insn
^= 0x01 << 21;
15401 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15404 /* NOP out calls to undefined weak functions.
15405 We can thus call a weak function without first
15406 checking whether the function is defined. */
15408 && h
->elf
.root
.type
== bfd_link_hash_undefweak
15409 && h
->elf
.dynindx
== -1
15410 && (r_type
== R_PPC64_REL24
15411 || r_type
== R_PPC64_REL24_NOTOC
)
15415 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
15420 case R_PPC64_GOT16_DS
:
15421 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15422 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
15423 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
15425 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15426 if ((insn
& (0x3f << 26 | 0x3)) == 58u << 26 /* ld */)
15428 insn
+= (14u << 26) - (58u << 26);
15429 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
15430 r_type
= R_PPC64_TOC16
;
15431 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15436 case R_PPC64_GOT16_LO_DS
:
15437 case R_PPC64_GOT16_HA
:
15438 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15439 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
15440 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
15442 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15443 if ((insn
& (0x3f << 26 | 0x3)) == 58u << 26 /* ld */)
15445 insn
+= (14u << 26) - (58u << 26);
15446 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
15447 r_type
= R_PPC64_TOC16_LO
;
15448 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15450 else if ((insn
& (0x3f << 26)) == 15u << 26 /* addis */)
15452 r_type
= R_PPC64_TOC16_HA
;
15453 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15458 case R_PPC64_GOT_PCREL34
:
15459 from
= (rel
->r_offset
15460 + input_section
->output_section
->vma
15461 + input_section
->output_offset
);
15462 if (relocation
- from
+ (1ULL << 33) < 1ULL << 34
15463 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
15465 offset
= rel
->r_offset
;
15466 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
15468 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15469 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
15470 == ((1ULL << 58) | (1ULL << 52) | (57ULL << 26) /* pld */))
15472 /* Replace with paddi. */
15473 pinsn
+= (2ULL << 56) + (14ULL << 26) - (57ULL << 26);
15474 r_type
= R_PPC64_PCREL34
;
15475 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
15476 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ offset
);
15477 bfd_put_32 (input_bfd
, pinsn
, contents
+ offset
+ 4);
15483 case R_PPC64_PCREL34
:
15484 if (SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
15486 offset
= rel
->r_offset
;
15487 pinsn
= bfd_get_32 (input_bfd
, contents
+ offset
);
15489 pinsn
|= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
15490 if ((pinsn
& ((-1ULL << 50) | (63ULL << 26)))
15491 == ((1ULL << 58) | (2ULL << 56) | (1ULL << 52)
15492 | (14ULL << 26) /* paddi */))
15495 if (rel
+ 1 < relend
15496 && rel
[1].r_offset
== offset
15497 && rel
[1].r_info
== ELF64_R_INFO (0, R_PPC64_PCREL_OPT
))
15499 bfd_vma off2
= rel
[1].r_addend
;
15501 /* zero means next insn. */
15504 if (off2
+ 4 <= input_section
->size
)
15507 bfd_signed_vma addend_off
;
15508 pinsn2
= bfd_get_32 (input_bfd
, contents
+ off2
);
15510 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
15512 if (off2
+ 8 > input_section
->size
)
15514 pinsn2
|= bfd_get_32 (input_bfd
,
15515 contents
+ off2
+ 4);
15517 if (xlate_pcrel_opt (&pinsn
, &pinsn2
, &addend_off
))
15519 addend
+= addend_off
;
15520 rel
->r_addend
= addend
;
15521 bfd_put_32 (input_bfd
, pinsn
>> 32,
15522 contents
+ offset
);
15523 bfd_put_32 (input_bfd
, pinsn
,
15524 contents
+ offset
+ 4);
15525 bfd_put_32 (input_bfd
, pinsn2
>> 32,
15527 if ((pinsn2
& (63ULL << 58)) == 1ULL << 58)
15528 bfd_put_32 (input_bfd
, pinsn2
,
15529 contents
+ off2
+ 4);
15539 save_unresolved_reloc
= unresolved_reloc
;
15543 /* xgettext:c-format */
15544 _bfd_error_handler (_("%pB: %s unsupported"),
15545 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
15547 bfd_set_error (bfd_error_bad_value
);
15553 case R_PPC64_TLSGD
:
15554 case R_PPC64_TLSLD
:
15555 case R_PPC64_TOCSAVE
:
15556 case R_PPC64_GNU_VTINHERIT
:
15557 case R_PPC64_GNU_VTENTRY
:
15558 case R_PPC64_ENTRY
:
15559 case R_PPC64_PCREL_OPT
:
15562 /* GOT16 relocations. Like an ADDR16 using the symbol's
15563 address in the GOT as relocation value instead of the
15564 symbol's value itself. Also, create a GOT entry for the
15565 symbol and put the symbol value there. */
15566 case R_PPC64_GOT_TLSGD16
:
15567 case R_PPC64_GOT_TLSGD16_LO
:
15568 case R_PPC64_GOT_TLSGD16_HI
:
15569 case R_PPC64_GOT_TLSGD16_HA
:
15570 case R_PPC64_GOT_TLSGD34
:
15571 tls_type
= TLS_TLS
| TLS_GD
;
15574 case R_PPC64_GOT_TLSLD16
:
15575 case R_PPC64_GOT_TLSLD16_LO
:
15576 case R_PPC64_GOT_TLSLD16_HI
:
15577 case R_PPC64_GOT_TLSLD16_HA
:
15578 case R_PPC64_GOT_TLSLD34
:
15579 tls_type
= TLS_TLS
| TLS_LD
;
15582 case R_PPC64_GOT_TPREL16_DS
:
15583 case R_PPC64_GOT_TPREL16_LO_DS
:
15584 case R_PPC64_GOT_TPREL16_HI
:
15585 case R_PPC64_GOT_TPREL16_HA
:
15586 case R_PPC64_GOT_TPREL34
:
15587 tls_type
= TLS_TLS
| TLS_TPREL
;
15590 case R_PPC64_GOT_DTPREL16_DS
:
15591 case R_PPC64_GOT_DTPREL16_LO_DS
:
15592 case R_PPC64_GOT_DTPREL16_HI
:
15593 case R_PPC64_GOT_DTPREL16_HA
:
15594 case R_PPC64_GOT_DTPREL34
:
15595 tls_type
= TLS_TLS
| TLS_DTPREL
;
15598 case R_PPC64_GOT16
:
15599 case R_PPC64_GOT16_LO
:
15600 case R_PPC64_GOT16_HI
:
15601 case R_PPC64_GOT16_HA
:
15602 case R_PPC64_GOT16_DS
:
15603 case R_PPC64_GOT16_LO_DS
:
15604 case R_PPC64_GOT_PCREL34
:
15607 /* Relocation is to the entry for this symbol in the global
15612 unsigned long indx
= 0;
15613 struct got_entry
*ent
;
15615 if (tls_type
== (TLS_TLS
| TLS_LD
)
15616 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
15617 ent
= ppc64_tlsld_got (input_bfd
);
15622 if (!htab
->elf
.dynamic_sections_created
15623 || h
->elf
.dynindx
== -1
15624 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
15625 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
15626 /* This is actually a static link, or it is a
15627 -Bsymbolic link and the symbol is defined
15628 locally, or the symbol was forced to be local
15629 because of a version file. */
15633 indx
= h
->elf
.dynindx
;
15634 unresolved_reloc
= FALSE
;
15636 ent
= h
->elf
.got
.glist
;
15640 if (local_got_ents
== NULL
)
15642 ent
= local_got_ents
[r_symndx
];
15645 for (; ent
!= NULL
; ent
= ent
->next
)
15646 if (ent
->addend
== orig_rel
.r_addend
15647 && ent
->owner
== input_bfd
15648 && ent
->tls_type
== tls_type
)
15654 if (ent
->is_indirect
)
15655 ent
= ent
->got
.ent
;
15656 offp
= &ent
->got
.offset
;
15657 got
= ppc64_elf_tdata (ent
->owner
)->got
;
15661 /* The offset must always be a multiple of 8. We use the
15662 least significant bit to record whether we have already
15663 processed this entry. */
15665 if ((off
& 1) != 0)
15669 /* Generate relocs for the dynamic linker, except in
15670 the case of TLSLD where we'll use one entry per
15678 ? h
->elf
.type
== STT_GNU_IFUNC
15679 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
15682 relgot
= htab
->elf
.irelplt
;
15684 htab
->local_ifunc_resolver
= 1;
15685 else if (is_static_defined (&h
->elf
))
15686 htab
->maybe_local_ifunc_resolver
= 1;
15689 || (bfd_link_pic (info
)
15691 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
15693 && bfd_link_executable (info
)
15694 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
15695 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
15696 if (relgot
!= NULL
)
15698 outrel
.r_offset
= (got
->output_section
->vma
15699 + got
->output_offset
15701 outrel
.r_addend
= orig_rel
.r_addend
;
15702 if (tls_type
& (TLS_LD
| TLS_GD
))
15704 outrel
.r_addend
= 0;
15705 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
15706 if (tls_type
== (TLS_TLS
| TLS_GD
))
15708 loc
= relgot
->contents
;
15709 loc
+= (relgot
->reloc_count
++
15710 * sizeof (Elf64_External_Rela
));
15711 bfd_elf64_swap_reloca_out (output_bfd
,
15713 outrel
.r_offset
+= 8;
15714 outrel
.r_addend
= orig_rel
.r_addend
;
15716 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
15719 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
15720 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
15721 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
15722 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
15723 else if (indx
!= 0)
15724 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
15728 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15730 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
15732 /* Write the .got section contents for the sake
15734 loc
= got
->contents
+ off
;
15735 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
15739 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
15741 outrel
.r_addend
+= relocation
;
15742 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
15744 if (htab
->elf
.tls_sec
== NULL
)
15745 outrel
.r_addend
= 0;
15747 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
15750 loc
= relgot
->contents
;
15751 loc
+= (relgot
->reloc_count
++
15752 * sizeof (Elf64_External_Rela
));
15753 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
15756 /* Init the .got section contents here if we're not
15757 emitting a reloc. */
15760 relocation
+= orig_rel
.r_addend
;
15763 if (htab
->elf
.tls_sec
== NULL
)
15767 if (tls_type
& TLS_LD
)
15770 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15771 if (tls_type
& TLS_TPREL
)
15772 relocation
+= DTP_OFFSET
- TP_OFFSET
;
15775 if (tls_type
& (TLS_GD
| TLS_LD
))
15777 bfd_put_64 (output_bfd
, relocation
,
15778 got
->contents
+ off
+ 8);
15782 bfd_put_64 (output_bfd
, relocation
,
15783 got
->contents
+ off
);
15787 if (off
>= (bfd_vma
) -2)
15790 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
15792 if (!(r_type
== R_PPC64_GOT_PCREL34
15793 || r_type
== R_PPC64_GOT_TLSGD34
15794 || r_type
== R_PPC64_GOT_TLSLD34
15795 || r_type
== R_PPC64_GOT_TPREL34
15796 || r_type
== R_PPC64_GOT_DTPREL34
))
15797 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
15801 case R_PPC64_PLT16_HA
:
15802 case R_PPC64_PLT16_HI
:
15803 case R_PPC64_PLT16_LO
:
15804 case R_PPC64_PLT16_LO_DS
:
15805 case R_PPC64_PLT_PCREL34
:
15806 case R_PPC64_PLT_PCREL34_NOTOC
:
15807 case R_PPC64_PLT32
:
15808 case R_PPC64_PLT64
:
15809 case R_PPC64_PLTSEQ
:
15810 case R_PPC64_PLTSEQ_NOTOC
:
15811 case R_PPC64_PLTCALL
:
15812 case R_PPC64_PLTCALL_NOTOC
:
15813 /* Relocation is to the entry for this symbol in the
15814 procedure linkage table. */
15815 unresolved_reloc
= TRUE
;
15817 struct plt_entry
**plt_list
= NULL
;
15819 plt_list
= &h
->elf
.plt
.plist
;
15820 else if (local_got_ents
!= NULL
)
15822 struct plt_entry
**local_plt
= (struct plt_entry
**)
15823 (local_got_ents
+ symtab_hdr
->sh_info
);
15824 plt_list
= local_plt
+ r_symndx
;
15828 struct plt_entry
*ent
;
15830 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
15831 if (ent
->plt
.offset
!= (bfd_vma
) -1
15832 && ent
->addend
== orig_rel
.r_addend
)
15837 plt
= htab
->elf
.splt
;
15838 if (!htab
->elf
.dynamic_sections_created
15840 || h
->elf
.dynindx
== -1)
15843 ? h
->elf
.type
== STT_GNU_IFUNC
15844 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15845 plt
= htab
->elf
.iplt
;
15847 plt
= htab
->pltlocal
;
15849 relocation
= (plt
->output_section
->vma
15850 + plt
->output_offset
15851 + ent
->plt
.offset
);
15852 if (r_type
== R_PPC64_PLT16_HA
15853 || r_type
== R_PPC64_PLT16_HI
15854 || r_type
== R_PPC64_PLT16_LO
15855 || r_type
== R_PPC64_PLT16_LO_DS
)
15857 got
= (elf_gp (output_bfd
)
15858 + htab
->sec_info
[input_section
->id
].toc_off
);
15862 unresolved_reloc
= FALSE
;
15870 /* Relocation value is TOC base. */
15871 relocation
= TOCstart
;
15872 if (r_symndx
== STN_UNDEF
)
15873 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
15874 else if (unresolved_reloc
)
15876 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
15877 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
15879 unresolved_reloc
= TRUE
;
15882 /* TOC16 relocs. We want the offset relative to the TOC base,
15883 which is the address of the start of the TOC plus 0x8000.
15884 The TOC consists of sections .got, .toc, .tocbss, and .plt,
15886 case R_PPC64_TOC16
:
15887 case R_PPC64_TOC16_LO
:
15888 case R_PPC64_TOC16_HI
:
15889 case R_PPC64_TOC16_DS
:
15890 case R_PPC64_TOC16_LO_DS
:
15891 case R_PPC64_TOC16_HA
:
15892 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15897 /* Relocate against the beginning of the section. */
15898 case R_PPC64_SECTOFF
:
15899 case R_PPC64_SECTOFF_LO
:
15900 case R_PPC64_SECTOFF_HI
:
15901 case R_PPC64_SECTOFF_DS
:
15902 case R_PPC64_SECTOFF_LO_DS
:
15903 case R_PPC64_SECTOFF_HA
:
15905 addend
-= sec
->output_section
->vma
;
15908 case R_PPC64_REL16
:
15909 case R_PPC64_REL16_LO
:
15910 case R_PPC64_REL16_HI
:
15911 case R_PPC64_REL16_HA
:
15912 case R_PPC64_REL16_HIGH
:
15913 case R_PPC64_REL16_HIGHA
:
15914 case R_PPC64_REL16_HIGHER
:
15915 case R_PPC64_REL16_HIGHERA
:
15916 case R_PPC64_REL16_HIGHEST
:
15917 case R_PPC64_REL16_HIGHESTA
:
15918 case R_PPC64_REL16_HIGHER34
:
15919 case R_PPC64_REL16_HIGHERA34
:
15920 case R_PPC64_REL16_HIGHEST34
:
15921 case R_PPC64_REL16_HIGHESTA34
:
15922 case R_PPC64_REL16DX_HA
:
15923 case R_PPC64_REL14
:
15924 case R_PPC64_REL14_BRNTAKEN
:
15925 case R_PPC64_REL14_BRTAKEN
:
15926 case R_PPC64_REL24
:
15927 case R_PPC64_REL24_NOTOC
:
15928 case R_PPC64_PCREL34
:
15929 case R_PPC64_PCREL28
:
15932 case R_PPC64_TPREL16
:
15933 case R_PPC64_TPREL16_LO
:
15934 case R_PPC64_TPREL16_HI
:
15935 case R_PPC64_TPREL16_HA
:
15936 case R_PPC64_TPREL16_DS
:
15937 case R_PPC64_TPREL16_LO_DS
:
15938 case R_PPC64_TPREL16_HIGH
:
15939 case R_PPC64_TPREL16_HIGHA
:
15940 case R_PPC64_TPREL16_HIGHER
:
15941 case R_PPC64_TPREL16_HIGHERA
:
15942 case R_PPC64_TPREL16_HIGHEST
:
15943 case R_PPC64_TPREL16_HIGHESTA
:
15944 case R_PPC64_TPREL34
:
15946 && h
->elf
.root
.type
== bfd_link_hash_undefweak
15947 && h
->elf
.dynindx
== -1)
15949 /* Make this relocation against an undefined weak symbol
15950 resolve to zero. This is really just a tweak, since
15951 code using weak externs ought to check that they are
15952 defined before using them. */
15953 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
15955 insn
= bfd_get_32 (input_bfd
, p
);
15956 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
15958 bfd_put_32 (input_bfd
, insn
, p
);
15961 if (htab
->elf
.tls_sec
!= NULL
)
15962 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15963 /* The TPREL16 relocs shouldn't really be used in shared
15964 libs or with non-local symbols as that will result in
15965 DT_TEXTREL being set, but support them anyway. */
15968 case R_PPC64_DTPREL16
:
15969 case R_PPC64_DTPREL16_LO
:
15970 case R_PPC64_DTPREL16_HI
:
15971 case R_PPC64_DTPREL16_HA
:
15972 case R_PPC64_DTPREL16_DS
:
15973 case R_PPC64_DTPREL16_LO_DS
:
15974 case R_PPC64_DTPREL16_HIGH
:
15975 case R_PPC64_DTPREL16_HIGHA
:
15976 case R_PPC64_DTPREL16_HIGHER
:
15977 case R_PPC64_DTPREL16_HIGHERA
:
15978 case R_PPC64_DTPREL16_HIGHEST
:
15979 case R_PPC64_DTPREL16_HIGHESTA
:
15980 case R_PPC64_DTPREL34
:
15981 if (htab
->elf
.tls_sec
!= NULL
)
15982 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15985 case R_PPC64_ADDR64_LOCAL
:
15986 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
15991 case R_PPC64_DTPMOD64
:
15996 case R_PPC64_TPREL64
:
15997 if (htab
->elf
.tls_sec
!= NULL
)
15998 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
16001 case R_PPC64_DTPREL64
:
16002 if (htab
->elf
.tls_sec
!= NULL
)
16003 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
16004 /* Fall through. */
16006 /* Relocations that may need to be propagated if this is a
16008 case R_PPC64_REL30
:
16009 case R_PPC64_REL32
:
16010 case R_PPC64_REL64
:
16011 case R_PPC64_ADDR14
:
16012 case R_PPC64_ADDR14_BRNTAKEN
:
16013 case R_PPC64_ADDR14_BRTAKEN
:
16014 case R_PPC64_ADDR16
:
16015 case R_PPC64_ADDR16_DS
:
16016 case R_PPC64_ADDR16_HA
:
16017 case R_PPC64_ADDR16_HI
:
16018 case R_PPC64_ADDR16_HIGH
:
16019 case R_PPC64_ADDR16_HIGHA
:
16020 case R_PPC64_ADDR16_HIGHER
:
16021 case R_PPC64_ADDR16_HIGHERA
:
16022 case R_PPC64_ADDR16_HIGHEST
:
16023 case R_PPC64_ADDR16_HIGHESTA
:
16024 case R_PPC64_ADDR16_LO
:
16025 case R_PPC64_ADDR16_LO_DS
:
16026 case R_PPC64_ADDR16_HIGHER34
:
16027 case R_PPC64_ADDR16_HIGHERA34
:
16028 case R_PPC64_ADDR16_HIGHEST34
:
16029 case R_PPC64_ADDR16_HIGHESTA34
:
16030 case R_PPC64_ADDR24
:
16031 case R_PPC64_ADDR32
:
16032 case R_PPC64_ADDR64
:
16033 case R_PPC64_UADDR16
:
16034 case R_PPC64_UADDR32
:
16035 case R_PPC64_UADDR64
:
16037 case R_PPC64_D34_LO
:
16038 case R_PPC64_D34_HI30
:
16039 case R_PPC64_D34_HA30
:
16042 if ((input_section
->flags
& SEC_ALLOC
) == 0)
16045 if (NO_OPD_RELOCS
&& is_opd
)
16048 if (bfd_link_pic (info
)
16050 || h
->dyn_relocs
!= NULL
)
16051 && ((h
!= NULL
&& pc_dynrelocs (h
))
16052 || must_be_dyn_reloc (info
, r_type
)))
16054 ? h
->dyn_relocs
!= NULL
16055 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
16057 bfd_boolean skip
, relocate
;
16062 /* When generating a dynamic object, these relocations
16063 are copied into the output file to be resolved at run
16069 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
16070 input_section
, rel
->r_offset
);
16071 if (out_off
== (bfd_vma
) -1)
16073 else if (out_off
== (bfd_vma
) -2)
16074 skip
= TRUE
, relocate
= TRUE
;
16075 out_off
+= (input_section
->output_section
->vma
16076 + input_section
->output_offset
);
16077 outrel
.r_offset
= out_off
;
16078 outrel
.r_addend
= rel
->r_addend
;
16080 /* Optimize unaligned reloc use. */
16081 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
16082 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
16083 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
16084 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
16085 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
16086 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
16087 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
16088 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
16089 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
16092 memset (&outrel
, 0, sizeof outrel
);
16093 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
16095 && r_type
!= R_PPC64_TOC
)
16097 indx
= h
->elf
.dynindx
;
16098 BFD_ASSERT (indx
!= -1);
16099 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
16103 /* This symbol is local, or marked to become local,
16104 or this is an opd section reloc which must point
16105 at a local function. */
16106 outrel
.r_addend
+= relocation
;
16107 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
16109 if (is_opd
&& h
!= NULL
)
16111 /* Lie about opd entries. This case occurs
16112 when building shared libraries and we
16113 reference a function in another shared
16114 lib. The same thing happens for a weak
16115 definition in an application that's
16116 overridden by a strong definition in a
16117 shared lib. (I believe this is a generic
16118 bug in binutils handling of weak syms.)
16119 In these cases we won't use the opd
16120 entry in this lib. */
16121 unresolved_reloc
= FALSE
;
16124 && r_type
== R_PPC64_ADDR64
16126 ? h
->elf
.type
== STT_GNU_IFUNC
16127 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
16128 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
16131 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
16133 /* We need to relocate .opd contents for ld.so.
16134 Prelink also wants simple and consistent rules
16135 for relocs. This make all RELATIVE relocs have
16136 *r_offset equal to r_addend. */
16143 ? h
->elf
.type
== STT_GNU_IFUNC
16144 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16146 info
->callbacks
->einfo
16147 /* xgettext:c-format */
16148 (_("%H: %s for indirect "
16149 "function `%pT' unsupported\n"),
16150 input_bfd
, input_section
, rel
->r_offset
,
16151 ppc64_elf_howto_table
[r_type
]->name
,
16155 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
16157 else if (sec
== NULL
|| sec
->owner
== NULL
)
16159 bfd_set_error (bfd_error_bad_value
);
16164 asection
*osec
= sec
->output_section
;
16166 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
16168 /* TLS symbol values are relative to the
16169 TLS segment. Dynamic relocations for
16170 local TLS symbols therefore can't be
16171 reduced to a relocation against their
16172 section symbol because it holds the
16173 address of the section, not a value
16174 relative to the TLS segment. We could
16175 change the .tdata dynamic section symbol
16176 to be zero value but STN_UNDEF works
16177 and is used elsewhere, eg. for TPREL64
16178 GOT relocs against local TLS symbols. */
16179 osec
= htab
->elf
.tls_sec
;
16184 indx
= elf_section_data (osec
)->dynindx
;
16187 if ((osec
->flags
& SEC_READONLY
) == 0
16188 && htab
->elf
.data_index_section
!= NULL
)
16189 osec
= htab
->elf
.data_index_section
;
16191 osec
= htab
->elf
.text_index_section
;
16192 indx
= elf_section_data (osec
)->dynindx
;
16194 BFD_ASSERT (indx
!= 0);
16197 /* We are turning this relocation into one
16198 against a section symbol, so subtract out
16199 the output section's address but not the
16200 offset of the input section in the output
16202 outrel
.r_addend
-= osec
->vma
;
16205 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
16209 sreloc
= elf_section_data (input_section
)->sreloc
;
16211 ? h
->elf
.type
== STT_GNU_IFUNC
16212 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
16214 sreloc
= htab
->elf
.irelplt
;
16216 htab
->local_ifunc_resolver
= 1;
16217 else if (is_static_defined (&h
->elf
))
16218 htab
->maybe_local_ifunc_resolver
= 1;
16220 if (sreloc
== NULL
)
16223 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
16226 loc
= sreloc
->contents
;
16227 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
16228 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
16230 if (!warned_dynamic
16231 && !ppc64_glibc_dynamic_reloc (ELF64_R_TYPE (outrel
.r_info
)))
16233 info
->callbacks
->einfo
16234 /* xgettext:c-format */
16235 (_("%X%P: %pB: %s against %pT "
16236 "is not supported by glibc as a dynamic relocation\n"),
16238 ppc64_elf_howto_table
[ELF64_R_TYPE (outrel
.r_info
)]->name
,
16240 warned_dynamic
= TRUE
;
16243 /* If this reloc is against an external symbol, it will
16244 be computed at runtime, so there's no need to do
16245 anything now. However, for the sake of prelink ensure
16246 that the section contents are a known value. */
16249 unresolved_reloc
= FALSE
;
16250 /* The value chosen here is quite arbitrary as ld.so
16251 ignores section contents except for the special
16252 case of .opd where the contents might be accessed
16253 before relocation. Choose zero, as that won't
16254 cause reloc overflow. */
16257 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
16258 to improve backward compatibility with older
16260 if (r_type
== R_PPC64_ADDR64
)
16261 addend
= outrel
.r_addend
;
16262 /* Adjust pc_relative relocs to have zero in *r_offset. */
16263 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
16264 addend
= outrel
.r_offset
;
16270 case R_PPC64_GLOB_DAT
:
16271 case R_PPC64_JMP_SLOT
:
16272 case R_PPC64_JMP_IREL
:
16273 case R_PPC64_RELATIVE
:
16274 /* We shouldn't ever see these dynamic relocs in relocatable
16276 /* Fall through. */
16278 case R_PPC64_PLTGOT16
:
16279 case R_PPC64_PLTGOT16_DS
:
16280 case R_PPC64_PLTGOT16_HA
:
16281 case R_PPC64_PLTGOT16_HI
:
16282 case R_PPC64_PLTGOT16_LO
:
16283 case R_PPC64_PLTGOT16_LO_DS
:
16284 case R_PPC64_PLTREL32
:
16285 case R_PPC64_PLTREL64
:
16286 /* These ones haven't been implemented yet. */
16288 info
->callbacks
->einfo
16289 /* xgettext:c-format */
16290 (_("%P: %pB: %s is not supported for `%pT'\n"),
16292 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
16294 bfd_set_error (bfd_error_invalid_operation
);
16299 /* Multi-instruction sequences that access the TOC can be
16300 optimized, eg. addis ra,r2,0; addi rb,ra,x;
16301 to nop; addi rb,r2,x; */
16307 case R_PPC64_GOT_TLSLD16_HI
:
16308 case R_PPC64_GOT_TLSGD16_HI
:
16309 case R_PPC64_GOT_TPREL16_HI
:
16310 case R_PPC64_GOT_DTPREL16_HI
:
16311 case R_PPC64_GOT16_HI
:
16312 case R_PPC64_TOC16_HI
:
16313 /* These relocs would only be useful if building up an
16314 offset to later add to r2, perhaps in an indexed
16315 addressing mode instruction. Don't try to optimize.
16316 Unfortunately, the possibility of someone building up an
16317 offset like this or even with the HA relocs, means that
16318 we need to check the high insn when optimizing the low
16322 case R_PPC64_PLTCALL_NOTOC
:
16323 if (!unresolved_reloc
)
16324 htab
->notoc_plt
= 1;
16325 /* Fall through. */
16326 case R_PPC64_PLTCALL
:
16327 if (unresolved_reloc
)
16329 /* No plt entry. Make this into a direct call. */
16330 bfd_byte
*p
= contents
+ rel
->r_offset
;
16331 insn
= bfd_get_32 (input_bfd
, p
);
16333 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
16334 if (r_type
== R_PPC64_PLTCALL
)
16335 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
16336 unresolved_reloc
= save_unresolved_reloc
;
16337 r_type
= R_PPC64_REL24
;
16341 case R_PPC64_PLTSEQ_NOTOC
:
16342 case R_PPC64_PLTSEQ
:
16343 if (unresolved_reloc
)
16345 unresolved_reloc
= FALSE
;
16350 case R_PPC64_PLT_PCREL34_NOTOC
:
16351 if (!unresolved_reloc
)
16352 htab
->notoc_plt
= 1;
16353 /* Fall through. */
16354 case R_PPC64_PLT_PCREL34
:
16355 if (unresolved_reloc
)
16357 bfd_byte
*p
= contents
+ rel
->r_offset
;
16358 bfd_put_32 (input_bfd
, PNOP
>> 32, p
);
16359 bfd_put_32 (input_bfd
, PNOP
, p
+ 4);
16360 unresolved_reloc
= FALSE
;
16365 case R_PPC64_PLT16_HA
:
16366 if (unresolved_reloc
)
16368 unresolved_reloc
= FALSE
;
16371 /* Fall through. */
16372 case R_PPC64_GOT_TLSLD16_HA
:
16373 case R_PPC64_GOT_TLSGD16_HA
:
16374 case R_PPC64_GOT_TPREL16_HA
:
16375 case R_PPC64_GOT_DTPREL16_HA
:
16376 case R_PPC64_GOT16_HA
:
16377 case R_PPC64_TOC16_HA
:
16378 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
16379 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
16383 p
= contents
+ (rel
->r_offset
& ~3);
16384 bfd_put_32 (input_bfd
, NOP
, p
);
16389 case R_PPC64_PLT16_LO
:
16390 case R_PPC64_PLT16_LO_DS
:
16391 if (unresolved_reloc
)
16393 unresolved_reloc
= FALSE
;
16396 /* Fall through. */
16397 case R_PPC64_GOT_TLSLD16_LO
:
16398 case R_PPC64_GOT_TLSGD16_LO
:
16399 case R_PPC64_GOT_TPREL16_LO_DS
:
16400 case R_PPC64_GOT_DTPREL16_LO_DS
:
16401 case R_PPC64_GOT16_LO
:
16402 case R_PPC64_GOT16_LO_DS
:
16403 case R_PPC64_TOC16_LO
:
16404 case R_PPC64_TOC16_LO_DS
:
16405 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
16406 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
16408 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
16409 insn
= bfd_get_32 (input_bfd
, p
);
16410 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
16412 /* Transform addic to addi when we change reg. */
16413 insn
&= ~((0x3f << 26) | (0x1f << 16));
16414 insn
|= (14u << 26) | (2 << 16);
16418 insn
&= ~(0x1f << 16);
16421 bfd_put_32 (input_bfd
, insn
, p
);
16425 case R_PPC64_TPREL16_HA
:
16426 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
16428 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
16429 insn
= bfd_get_32 (input_bfd
, p
);
16430 if ((insn
& ((0x3f << 26) | 0x1f << 16))
16431 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
16432 /* xgettext:c-format */
16433 info
->callbacks
->minfo
16434 (_("%H: warning: %s unexpected insn %#x.\n"),
16435 input_bfd
, input_section
, rel
->r_offset
,
16436 ppc64_elf_howto_table
[r_type
]->name
, insn
);
16439 bfd_put_32 (input_bfd
, NOP
, p
);
16445 case R_PPC64_TPREL16_LO
:
16446 case R_PPC64_TPREL16_LO_DS
:
16447 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
16449 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
16450 insn
= bfd_get_32 (input_bfd
, p
);
16451 insn
&= ~(0x1f << 16);
16453 bfd_put_32 (input_bfd
, insn
, p
);
16458 /* Do any further special processing. */
16464 case R_PPC64_REL16_HA
:
16465 case R_PPC64_REL16_HIGHA
:
16466 case R_PPC64_REL16_HIGHERA
:
16467 case R_PPC64_REL16_HIGHESTA
:
16468 case R_PPC64_REL16DX_HA
:
16469 case R_PPC64_ADDR16_HA
:
16470 case R_PPC64_ADDR16_HIGHA
:
16471 case R_PPC64_ADDR16_HIGHERA
:
16472 case R_PPC64_ADDR16_HIGHESTA
:
16473 case R_PPC64_TOC16_HA
:
16474 case R_PPC64_SECTOFF_HA
:
16475 case R_PPC64_TPREL16_HA
:
16476 case R_PPC64_TPREL16_HIGHA
:
16477 case R_PPC64_TPREL16_HIGHERA
:
16478 case R_PPC64_TPREL16_HIGHESTA
:
16479 case R_PPC64_DTPREL16_HA
:
16480 case R_PPC64_DTPREL16_HIGHA
:
16481 case R_PPC64_DTPREL16_HIGHERA
:
16482 case R_PPC64_DTPREL16_HIGHESTA
:
16483 /* It's just possible that this symbol is a weak symbol
16484 that's not actually defined anywhere. In that case,
16485 'sec' would be NULL, and we should leave the symbol
16486 alone (it will be set to zero elsewhere in the link). */
16489 /* Fall through. */
16491 case R_PPC64_GOT16_HA
:
16492 case R_PPC64_PLTGOT16_HA
:
16493 case R_PPC64_PLT16_HA
:
16494 case R_PPC64_GOT_TLSGD16_HA
:
16495 case R_PPC64_GOT_TLSLD16_HA
:
16496 case R_PPC64_GOT_TPREL16_HA
:
16497 case R_PPC64_GOT_DTPREL16_HA
:
16498 /* Add 0x10000 if sign bit in 0:15 is set.
16499 Bits 0:15 are not used. */
16503 case R_PPC64_D34_HA30
:
16504 case R_PPC64_ADDR16_HIGHERA34
:
16505 case R_PPC64_ADDR16_HIGHESTA34
:
16506 case R_PPC64_REL16_HIGHERA34
:
16507 case R_PPC64_REL16_HIGHESTA34
:
16509 addend
+= 1ULL << 33;
16512 case R_PPC64_ADDR16_DS
:
16513 case R_PPC64_ADDR16_LO_DS
:
16514 case R_PPC64_GOT16_DS
:
16515 case R_PPC64_GOT16_LO_DS
:
16516 case R_PPC64_PLT16_LO_DS
:
16517 case R_PPC64_SECTOFF_DS
:
16518 case R_PPC64_SECTOFF_LO_DS
:
16519 case R_PPC64_TOC16_DS
:
16520 case R_PPC64_TOC16_LO_DS
:
16521 case R_PPC64_PLTGOT16_DS
:
16522 case R_PPC64_PLTGOT16_LO_DS
:
16523 case R_PPC64_GOT_TPREL16_DS
:
16524 case R_PPC64_GOT_TPREL16_LO_DS
:
16525 case R_PPC64_GOT_DTPREL16_DS
:
16526 case R_PPC64_GOT_DTPREL16_LO_DS
:
16527 case R_PPC64_TPREL16_DS
:
16528 case R_PPC64_TPREL16_LO_DS
:
16529 case R_PPC64_DTPREL16_DS
:
16530 case R_PPC64_DTPREL16_LO_DS
:
16531 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16533 /* If this reloc is against an lq, lxv, or stxv insn, then
16534 the value must be a multiple of 16. This is somewhat of
16535 a hack, but the "correct" way to do this by defining _DQ
16536 forms of all the _DS relocs bloats all reloc switches in
16537 this file. It doesn't make much sense to use these
16538 relocs in data, so testing the insn should be safe. */
16539 if ((insn
& (0x3f << 26)) == (56u << 26)
16540 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
16542 relocation
+= addend
;
16543 addend
= insn
& (mask
^ 3);
16544 if ((relocation
& mask
) != 0)
16546 relocation
^= relocation
& mask
;
16547 info
->callbacks
->einfo
16548 /* xgettext:c-format */
16549 (_("%H: error: %s not a multiple of %u\n"),
16550 input_bfd
, input_section
, rel
->r_offset
,
16551 ppc64_elf_howto_table
[r_type
]->name
,
16553 bfd_set_error (bfd_error_bad_value
);
16560 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
16561 because such sections are not SEC_ALLOC and thus ld.so will
16562 not process them. */
16563 howto
= ppc64_elf_howto_table
[(int) r_type
];
16564 if (unresolved_reloc
16565 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
16566 && h
->elf
.def_dynamic
)
16567 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
16568 rel
->r_offset
) != (bfd_vma
) -1)
16570 info
->callbacks
->einfo
16571 /* xgettext:c-format */
16572 (_("%H: unresolvable %s against `%pT'\n"),
16573 input_bfd
, input_section
, rel
->r_offset
,
16575 h
->elf
.root
.root
.string
);
16579 /* 16-bit fields in insns mostly have signed values, but a
16580 few insns have 16-bit unsigned values. Really, we should
16581 have different reloc types. */
16582 if (howto
->complain_on_overflow
!= complain_overflow_dont
16583 && howto
->dst_mask
== 0xffff
16584 && (input_section
->flags
& SEC_CODE
) != 0)
16586 enum complain_overflow complain
= complain_overflow_signed
;
16588 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
16589 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
16590 complain
= complain_overflow_bitfield
;
16591 else if (howto
->rightshift
== 0
16592 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
16593 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
16594 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
16595 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
16596 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
16597 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
16598 complain
= complain_overflow_unsigned
;
16599 if (howto
->complain_on_overflow
!= complain
)
16601 alt_howto
= *howto
;
16602 alt_howto
.complain_on_overflow
= complain
;
16603 howto
= &alt_howto
;
16609 /* Split field relocs aren't handled by _bfd_final_link_relocate. */
16611 case R_PPC64_D34_LO
:
16612 case R_PPC64_D34_HI30
:
16613 case R_PPC64_D34_HA30
:
16614 case R_PPC64_PCREL34
:
16615 case R_PPC64_GOT_PCREL34
:
16616 case R_PPC64_TPREL34
:
16617 case R_PPC64_DTPREL34
:
16618 case R_PPC64_GOT_TLSGD34
:
16619 case R_PPC64_GOT_TLSLD34
:
16620 case R_PPC64_GOT_TPREL34
:
16621 case R_PPC64_GOT_DTPREL34
:
16622 case R_PPC64_PLT_PCREL34
:
16623 case R_PPC64_PLT_PCREL34_NOTOC
:
16625 case R_PPC64_PCREL28
:
16626 if (rel
->r_offset
+ 8 > input_section
->size
)
16627 r
= bfd_reloc_outofrange
;
16630 relocation
+= addend
;
16631 if (howto
->pc_relative
)
16632 relocation
-= (rel
->r_offset
16633 + input_section
->output_offset
16634 + input_section
->output_section
->vma
);
16635 relocation
>>= howto
->rightshift
;
16637 pinsn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16639 pinsn
|= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
16641 pinsn
&= ~howto
->dst_mask
;
16642 pinsn
|= (((relocation
<< 16) | (relocation
& 0xffff))
16643 & howto
->dst_mask
);
16644 bfd_put_32 (input_bfd
, pinsn
>> 32, contents
+ rel
->r_offset
);
16645 bfd_put_32 (input_bfd
, pinsn
, contents
+ rel
->r_offset
+ 4);
16647 if (howto
->complain_on_overflow
== complain_overflow_signed
16648 && (relocation
+ (1ULL << (howto
->bitsize
- 1))
16649 >= 1ULL << howto
->bitsize
))
16650 r
= bfd_reloc_overflow
;
16654 case R_PPC64_REL16DX_HA
:
16655 if (rel
->r_offset
+ 4 > input_section
->size
)
16656 r
= bfd_reloc_outofrange
;
16659 relocation
+= addend
;
16660 relocation
-= (rel
->r_offset
16661 + input_section
->output_offset
16662 + input_section
->output_section
->vma
);
16663 relocation
= (bfd_signed_vma
) relocation
>> 16;
16664 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
16666 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
16667 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
16669 if (relocation
+ 0x8000 > 0xffff)
16670 r
= bfd_reloc_overflow
;
16675 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
16676 contents
, rel
->r_offset
,
16677 relocation
, addend
);
16680 if (r
!= bfd_reloc_ok
)
16682 char *more_info
= NULL
;
16683 const char *reloc_name
= howto
->name
;
16685 if (reloc_dest
!= DEST_NORMAL
)
16687 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
16688 if (more_info
!= NULL
)
16690 strcpy (more_info
, reloc_name
);
16691 strcat (more_info
, (reloc_dest
== DEST_OPD
16692 ? " (OPD)" : " (stub)"));
16693 reloc_name
= more_info
;
16697 if (r
== bfd_reloc_overflow
)
16699 /* On code like "if (foo) foo();" don't report overflow
16700 on a branch to zero when foo is undefined. */
16702 && (reloc_dest
== DEST_STUB
16704 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
16705 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
16706 && is_branch_reloc (r_type
))))
16707 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
16708 sym_name
, reloc_name
,
16710 input_bfd
, input_section
,
16715 info
->callbacks
->einfo
16716 /* xgettext:c-format */
16717 (_("%H: %s against `%pT': error %d\n"),
16718 input_bfd
, input_section
, rel
->r_offset
,
16719 reloc_name
, sym_name
, (int) r
);
16722 if (more_info
!= NULL
)
16732 Elf_Internal_Shdr
*rel_hdr
;
16733 size_t deleted
= rel
- wrel
;
16735 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
16736 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
16737 if (rel_hdr
->sh_size
== 0)
16739 /* It is too late to remove an empty reloc section. Leave
16741 ??? What is wrong with an empty section??? */
16742 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
16745 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
16746 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
16747 input_section
->reloc_count
-= deleted
;
16750 /* If we're emitting relocations, then shortly after this function
16751 returns, reloc offsets and addends for this section will be
16752 adjusted. Worse, reloc symbol indices will be for the output
16753 file rather than the input. Save a copy of the relocs for
16754 opd_entry_value. */
16755 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
16758 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
16759 rel
= bfd_alloc (input_bfd
, amt
);
16760 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
16761 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
16764 memcpy (rel
, relocs
, amt
);
16769 /* Adjust the value of any local symbols in opd sections. */
16772 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
16773 const char *name ATTRIBUTE_UNUSED
,
16774 Elf_Internal_Sym
*elfsym
,
16775 asection
*input_sec
,
16776 struct elf_link_hash_entry
*h
)
16778 struct _opd_sec_data
*opd
;
16785 opd
= get_opd_info (input_sec
);
16786 if (opd
== NULL
|| opd
->adjust
== NULL
)
16789 value
= elfsym
->st_value
- input_sec
->output_offset
;
16790 if (!bfd_link_relocatable (info
))
16791 value
-= input_sec
->output_section
->vma
;
16793 adjust
= opd
->adjust
[OPD_NDX (value
)];
16797 elfsym
->st_value
+= adjust
;
16801 /* Finish up dynamic symbol handling. We set the contents of various
16802 dynamic sections here. */
16805 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
16806 struct bfd_link_info
*info
,
16807 struct elf_link_hash_entry
*h
,
16808 Elf_Internal_Sym
*sym
)
16810 struct ppc_link_hash_table
*htab
;
16811 struct plt_entry
*ent
;
16813 htab
= ppc_hash_table (info
);
16817 if (!htab
->opd_abi
&& !h
->def_regular
)
16818 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
16819 if (ent
->plt
.offset
!= (bfd_vma
) -1)
16821 /* Mark the symbol as undefined, rather than as
16822 defined in glink. Leave the value if there were
16823 any relocations where pointer equality matters
16824 (this is a clue for the dynamic linker, to make
16825 function pointer comparisons work between an
16826 application and shared library), otherwise set it
16828 sym
->st_shndx
= SHN_UNDEF
;
16829 if (!h
->pointer_equality_needed
)
16831 else if (!h
->ref_regular_nonweak
)
16833 /* This breaks function pointer comparisons, but
16834 that is better than breaking tests for a NULL
16835 function pointer. */
16842 && (h
->root
.type
== bfd_link_hash_defined
16843 || h
->root
.type
== bfd_link_hash_defweak
)
16844 && (h
->root
.u
.def
.section
== htab
->elf
.sdynbss
16845 || h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
))
16847 /* This symbol needs a copy reloc. Set it up. */
16848 Elf_Internal_Rela rela
;
16852 if (h
->dynindx
== -1)
16855 rela
.r_offset
= (h
->root
.u
.def
.value
16856 + h
->root
.u
.def
.section
->output_section
->vma
16857 + h
->root
.u
.def
.section
->output_offset
);
16858 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
16860 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
16861 srel
= htab
->elf
.sreldynrelro
;
16863 srel
= htab
->elf
.srelbss
;
16864 loc
= srel
->contents
;
16865 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
16866 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
16872 /* Used to decide how to sort relocs in an optimal manner for the
16873 dynamic linker, before writing them out. */
16875 static enum elf_reloc_type_class
16876 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
16877 const asection
*rel_sec
,
16878 const Elf_Internal_Rela
*rela
)
16880 enum elf_ppc64_reloc_type r_type
;
16881 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
16883 if (rel_sec
== htab
->elf
.irelplt
)
16884 return reloc_class_ifunc
;
16886 r_type
= ELF64_R_TYPE (rela
->r_info
);
16889 case R_PPC64_RELATIVE
:
16890 return reloc_class_relative
;
16891 case R_PPC64_JMP_SLOT
:
16892 return reloc_class_plt
;
16894 return reloc_class_copy
;
16896 return reloc_class_normal
;
16900 /* Finish up the dynamic sections. */
16903 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
16904 struct bfd_link_info
*info
)
16906 struct ppc_link_hash_table
*htab
;
16910 htab
= ppc_hash_table (info
);
16914 dynobj
= htab
->elf
.dynobj
;
16915 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
16917 if (htab
->elf
.dynamic_sections_created
)
16919 Elf64_External_Dyn
*dyncon
, *dynconend
;
16921 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
16924 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
16925 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
16926 for (; dyncon
< dynconend
; dyncon
++)
16928 Elf_Internal_Dyn dyn
;
16931 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
16938 case DT_PPC64_GLINK
:
16940 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16941 /* We stupidly defined DT_PPC64_GLINK to be the start
16942 of glink rather than the first entry point, which is
16943 what ld.so needs, and now have a bigger stub to
16944 support automatic multiple TOCs. */
16945 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
16949 s
= bfd_get_section_by_name (output_bfd
, ".opd");
16952 dyn
.d_un
.d_ptr
= s
->vma
;
16956 if ((htab
->do_multi_toc
&& htab
->multi_toc_needed
)
16957 || htab
->notoc_plt
)
16958 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
16959 if (htab
->has_plt_localentry0
)
16960 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
16963 case DT_PPC64_OPDSZ
:
16964 s
= bfd_get_section_by_name (output_bfd
, ".opd");
16967 dyn
.d_un
.d_val
= s
->size
;
16971 s
= htab
->elf
.splt
;
16972 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16976 s
= htab
->elf
.srelplt
;
16977 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16981 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
16985 if (htab
->local_ifunc_resolver
)
16986 info
->callbacks
->einfo
16987 (_("%X%P: text relocations and GNU indirect "
16988 "functions will result in a segfault at runtime\n"));
16989 else if (htab
->maybe_local_ifunc_resolver
)
16990 info
->callbacks
->einfo
16991 (_("%P: warning: text relocations and GNU indirect "
16992 "functions may result in a segfault at runtime\n"));
16996 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
17000 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
17001 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
17003 /* Fill in the first entry in the global offset table.
17004 We use it to hold the link-time TOCbase. */
17005 bfd_put_64 (output_bfd
,
17006 elf_gp (output_bfd
) + TOC_BASE_OFF
,
17007 htab
->elf
.sgot
->contents
);
17009 /* Set .got entry size. */
17010 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
17014 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
17015 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
17017 /* Set .plt entry size. */
17018 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
17019 = PLT_ENTRY_SIZE (htab
);
17022 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
17023 brlt ourselves if emitrelocations. */
17024 if (htab
->brlt
!= NULL
17025 && htab
->brlt
->reloc_count
!= 0
17026 && !_bfd_elf_link_output_relocs (output_bfd
,
17028 elf_section_data (htab
->brlt
)->rela
.hdr
,
17029 elf_section_data (htab
->brlt
)->relocs
,
17033 if (htab
->glink
!= NULL
17034 && htab
->glink
->reloc_count
!= 0
17035 && !_bfd_elf_link_output_relocs (output_bfd
,
17037 elf_section_data (htab
->glink
)->rela
.hdr
,
17038 elf_section_data (htab
->glink
)->relocs
,
17043 if (htab
->glink_eh_frame
!= NULL
17044 && htab
->glink_eh_frame
->size
!= 0
17045 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
17046 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
17047 htab
->glink_eh_frame
,
17048 htab
->glink_eh_frame
->contents
))
17051 /* We need to handle writing out multiple GOT sections ourselves,
17052 since we didn't add them to DYNOBJ. We know dynobj is the first
17054 while ((dynobj
= dynobj
->link
.next
) != NULL
)
17058 if (!is_ppc64_elf (dynobj
))
17061 s
= ppc64_elf_tdata (dynobj
)->got
;
17064 && s
->output_section
!= bfd_abs_section_ptr
17065 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
17066 s
->contents
, s
->output_offset
,
17069 s
= ppc64_elf_tdata (dynobj
)->relgot
;
17072 && s
->output_section
!= bfd_abs_section_ptr
17073 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
17074 s
->contents
, s
->output_offset
,
17082 #include "elf64-target.h"
17084 /* FreeBSD support */
17086 #undef TARGET_LITTLE_SYM
17087 #undef TARGET_LITTLE_NAME
17089 #undef TARGET_BIG_SYM
17090 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
17091 #undef TARGET_BIG_NAME
17092 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
17095 #define ELF_OSABI ELFOSABI_FREEBSD
17098 #define elf64_bed elf64_powerpc_fbsd_bed
17100 #include "elf64-target.h"