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_unhandled_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_vma opd_entry_value
57 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bfd_boolean
);
59 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
60 #define TARGET_LITTLE_NAME "elf64-powerpcle"
61 #define TARGET_BIG_SYM powerpc_elf64_vec
62 #define TARGET_BIG_NAME "elf64-powerpc"
63 #define ELF_ARCH bfd_arch_powerpc
64 #define ELF_TARGET_ID PPC64_ELF_DATA
65 #define ELF_MACHINE_CODE EM_PPC64
66 #define ELF_MAXPAGESIZE 0x10000
67 #define ELF_COMMONPAGESIZE 0x1000
68 #define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
69 #define elf_info_to_howto ppc64_elf_info_to_howto
71 #define elf_backend_want_got_sym 0
72 #define elf_backend_want_plt_sym 0
73 #define elf_backend_plt_alignment 3
74 #define elf_backend_plt_not_loaded 1
75 #define elf_backend_got_header_size 8
76 #define elf_backend_want_dynrelro 1
77 #define elf_backend_can_gc_sections 1
78 #define elf_backend_can_refcount 1
79 #define elf_backend_rela_normal 1
80 #define elf_backend_dtrel_excludes_plt 1
81 #define elf_backend_default_execstack 0
83 #define bfd_elf64_mkobject ppc64_elf_mkobject
84 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
85 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
86 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
87 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
88 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
89 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
90 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
91 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
92 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
94 #define elf_backend_object_p ppc64_elf_object_p
95 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
96 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
97 #define elf_backend_write_core_note ppc64_elf_write_core_note
98 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
99 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
100 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
101 #define elf_backend_check_directives ppc64_elf_before_check_relocs
102 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
103 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
104 #define elf_backend_check_relocs ppc64_elf_check_relocs
105 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
106 #define elf_backend_gc_keep ppc64_elf_gc_keep
107 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
108 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
109 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
110 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
111 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
112 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
113 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
114 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
115 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
116 #define elf_backend_action_discarded ppc64_elf_action_discarded
117 #define elf_backend_relocate_section ppc64_elf_relocate_section
118 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
119 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
120 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
121 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
122 #define elf_backend_special_sections ppc64_elf_special_sections
123 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
124 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
125 #define elf_backend_get_reloc_section bfd_get_section_by_name
127 /* The name of the dynamic interpreter. This is put in the .interp
129 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
131 /* The size in bytes of an entry in the procedure linkage table. */
132 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
133 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
135 /* The initial size of the plt reserved for the dynamic linker. */
136 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
138 /* Offsets to some stack save slots. */
140 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
141 /* This one is dodgy. ELFv2 does not have a linker word, so use the
142 CR save slot. Used only by optimised __tls_get_addr call stub,
143 relying on __tls_get_addr_opt not saving CR.. */
144 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
146 /* TOC base pointers offset from start of TOC. */
147 #define TOC_BASE_OFF 0x8000
148 /* TOC base alignment. */
149 #define TOC_BASE_ALIGN 256
151 /* Offset of tp and dtp pointers from start of TLS block. */
152 #define TP_OFFSET 0x7000
153 #define DTP_OFFSET 0x8000
155 /* .plt call stub instructions. The normal stub is like this, but
156 sometimes the .plt entry crosses a 64k boundary and we need to
157 insert an addi to adjust r11. */
158 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
159 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
160 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
161 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
162 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
163 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
164 #define BCTR 0x4e800420 /* bctr */
166 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
167 #define ADDI_R12_R11 0x398b0000 /* addi %r12,%r11,off@l */
168 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
169 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
170 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
172 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
173 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
174 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
175 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
176 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
177 #define BNECTR 0x4ca20420 /* bnectr+ */
178 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
180 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
181 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
182 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
184 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
185 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
186 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
188 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
189 #define LIS_R12 0x3d800000 /* lis %r12,xxx@ha */
190 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
191 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
192 #define ADDIS_R12_R11 0x3d8b0000 /* addis %r12,%r11,xxx@ha */
193 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
194 #define ORIS_R12_R12_0 0x658c0000 /* oris %r12,%r12,xxx@hi */
195 #define ORI_R12_R12_0 0x618c0000 /* ori %r12,%r12,xxx@l */
196 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
197 #define SLDI_R12_R12_32 0x799c07c6 /* sldi %r12,%r12,32 */
198 #define LDX_R12_R11_R12 0x7d8b602a /* ldx %r12,%r11,%r12 */
199 #define ADD_R12_R11_R12 0x7d8b6214 /* add %r12,%r11,%r12 */
201 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
202 #define GLINK_PLTRESOLVE_SIZE(htab) \
203 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
207 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
208 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
210 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
211 /* ld %2,(0b-1b)(%11) */
212 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
213 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
219 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
220 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
221 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
222 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
223 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
226 #define NOP 0x60000000
228 /* Some other nops. */
229 #define CROR_151515 0x4def7b82
230 #define CROR_313131 0x4ffffb82
232 /* .glink entries for the first 32k functions are two instructions. */
233 #define LI_R0_0 0x38000000 /* li %r0,0 */
234 #define B_DOT 0x48000000 /* b . */
236 /* After that, we need two instructions to load the index, followed by
238 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
239 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
241 /* Instructions used by the save and restore reg functions. */
242 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
243 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
244 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
245 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
246 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
247 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
248 #define LI_R12_0 0x39800000 /* li %r12,0 */
249 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
250 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
251 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
252 #define BLR 0x4e800020 /* blr */
254 /* Since .opd is an array of descriptors and each entry will end up
255 with identical R_PPC64_RELATIVE relocs, there is really no need to
256 propagate .opd relocs; The dynamic linker should be taught to
257 relocate .opd without reloc entries. */
258 #ifndef NO_OPD_RELOCS
259 #define NO_OPD_RELOCS 0
263 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
267 abiversion (bfd
*abfd
)
269 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
273 set_abiversion (bfd
*abfd
, int ver
)
275 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
276 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
279 /* Relocation HOWTO's. */
280 /* Like other ELF RELA targets that don't apply multiple
281 field-altering relocations to the same localation, src_mask is
282 always zero and pcrel_offset is the same as pc_relative.
283 PowerPC can always use a zero bitpos, even when the field is not at
284 the LSB. For example, a REL24 could use rightshift=2, bisize=24
285 and bitpos=2 which matches the ABI description, or as we do here,
286 rightshift=0, bitsize=26 and bitpos=0. */
287 #define HOW(type, size, bitsize, mask, rightshift, pc_relative, \
288 complain, special_func) \
289 HOWTO (type, rightshift, size, bitsize, pc_relative, 0, \
290 complain_overflow_ ## complain, special_func, \
291 #type, FALSE, 0, mask, pc_relative)
293 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
295 static reloc_howto_type ppc64_elf_howto_raw
[] =
297 /* This reloc does nothing. */
298 HOW (R_PPC64_NONE
, 3, 0, 0, 0, FALSE
, dont
,
299 bfd_elf_generic_reloc
),
301 /* A standard 32 bit relocation. */
302 HOW (R_PPC64_ADDR32
, 2, 32, 0xffffffff, 0, FALSE
, bitfield
,
303 bfd_elf_generic_reloc
),
305 /* An absolute 26 bit branch; the lower two bits must be zero.
306 FIXME: we don't check that, we just clear them. */
307 HOW (R_PPC64_ADDR24
, 2, 26, 0x03fffffc, 0, FALSE
, bitfield
,
308 bfd_elf_generic_reloc
),
310 /* A standard 16 bit relocation. */
311 HOW (R_PPC64_ADDR16
, 1, 16, 0xffff, 0, FALSE
, bitfield
,
312 bfd_elf_generic_reloc
),
314 /* A 16 bit relocation without overflow. */
315 HOW (R_PPC64_ADDR16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
316 bfd_elf_generic_reloc
),
318 /* Bits 16-31 of an address. */
319 HOW (R_PPC64_ADDR16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
320 bfd_elf_generic_reloc
),
322 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
323 bits, treated as a signed number, is negative. */
324 HOW (R_PPC64_ADDR16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
327 /* An absolute 16 bit branch; the lower two bits must be zero.
328 FIXME: we don't check that, we just clear them. */
329 HOW (R_PPC64_ADDR14
, 2, 16, 0x0000fffc, 0, FALSE
, signed,
330 ppc64_elf_branch_reloc
),
332 /* An absolute 16 bit branch, for which bit 10 should be set to
333 indicate that the branch is expected to be taken. The lower two
334 bits must be zero. */
335 HOW (R_PPC64_ADDR14_BRTAKEN
, 2, 16, 0x0000fffc, 0, FALSE
, signed,
336 ppc64_elf_brtaken_reloc
),
338 /* An absolute 16 bit branch, for which bit 10 should be set to
339 indicate that the branch is not expected to be taken. The lower
340 two bits must be zero. */
341 HOW (R_PPC64_ADDR14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, FALSE
, signed,
342 ppc64_elf_brtaken_reloc
),
344 /* A relative 26 bit branch; the lower two bits must be zero. */
345 HOW (R_PPC64_REL24
, 2, 26, 0x03fffffc, 0, TRUE
, signed,
346 ppc64_elf_branch_reloc
),
348 /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer. */
349 HOW (R_PPC64_REL24_NOTOC
, 2, 26, 0x03fffffc, 0, TRUE
, signed,
350 ppc64_elf_branch_reloc
),
352 /* A relative 16 bit branch; the lower two bits must be zero. */
353 HOW (R_PPC64_REL14
, 2, 16, 0x0000fffc, 0, TRUE
, signed,
354 ppc64_elf_branch_reloc
),
356 /* A relative 16 bit branch. Bit 10 should be set to indicate that
357 the branch is expected to be taken. The lower two bits must be
359 HOW (R_PPC64_REL14_BRTAKEN
, 2, 16, 0x0000fffc, 0, TRUE
, signed,
360 ppc64_elf_brtaken_reloc
),
362 /* A relative 16 bit branch. Bit 10 should be set to indicate that
363 the branch is not expected to be taken. The lower two bits must
365 HOW (R_PPC64_REL14_BRNTAKEN
, 2, 16, 0x0000fffc, 0, TRUE
, signed,
366 ppc64_elf_brtaken_reloc
),
368 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
370 HOW (R_PPC64_GOT16
, 1, 16, 0xffff, 0, FALSE
, signed,
371 ppc64_elf_unhandled_reloc
),
373 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
375 HOW (R_PPC64_GOT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
376 ppc64_elf_unhandled_reloc
),
378 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
380 HOW (R_PPC64_GOT16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
381 ppc64_elf_unhandled_reloc
),
383 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
385 HOW (R_PPC64_GOT16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
386 ppc64_elf_unhandled_reloc
),
388 /* This is used only by the dynamic linker. The symbol should exist
389 both in the object being run and in some shared library. The
390 dynamic linker copies the data addressed by the symbol from the
391 shared library into the object, because the object being
392 run has to have the data at some particular address. */
393 HOW (R_PPC64_COPY
, 0, 0, 0, 0, FALSE
, dont
,
394 ppc64_elf_unhandled_reloc
),
396 /* Like R_PPC64_ADDR64, but used when setting global offset table
398 HOW (R_PPC64_GLOB_DAT
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
399 ppc64_elf_unhandled_reloc
),
401 /* Created by the link editor. Marks a procedure linkage table
402 entry for a symbol. */
403 HOW (R_PPC64_JMP_SLOT
, 0, 0, 0, 0, FALSE
, dont
,
404 ppc64_elf_unhandled_reloc
),
406 /* Used only by the dynamic linker. When the object is run, this
407 doubleword64 is set to the load address of the object, plus the
409 HOW (R_PPC64_RELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
410 bfd_elf_generic_reloc
),
412 /* Like R_PPC64_ADDR32, but may be unaligned. */
413 HOW (R_PPC64_UADDR32
, 2, 32, 0xffffffff, 0, FALSE
, bitfield
,
414 bfd_elf_generic_reloc
),
416 /* Like R_PPC64_ADDR16, but may be unaligned. */
417 HOW (R_PPC64_UADDR16
, 1, 16, 0xffff, 0, FALSE
, bitfield
,
418 bfd_elf_generic_reloc
),
420 /* 32-bit PC relative. */
421 HOW (R_PPC64_REL32
, 2, 32, 0xffffffff, 0, TRUE
, signed,
422 bfd_elf_generic_reloc
),
424 /* 32-bit relocation to the symbol's procedure linkage table. */
425 HOW (R_PPC64_PLT32
, 2, 32, 0xffffffff, 0, FALSE
, bitfield
,
426 ppc64_elf_unhandled_reloc
),
428 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
429 FIXME: R_PPC64_PLTREL32 not supported. */
430 HOW (R_PPC64_PLTREL32
, 2, 32, 0xffffffff, 0, TRUE
, signed,
431 ppc64_elf_unhandled_reloc
),
433 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
435 HOW (R_PPC64_PLT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
436 ppc64_elf_unhandled_reloc
),
438 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
440 HOW (R_PPC64_PLT16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
441 ppc64_elf_unhandled_reloc
),
443 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
445 HOW (R_PPC64_PLT16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
446 ppc64_elf_unhandled_reloc
),
448 /* 16-bit section relative relocation. */
449 HOW (R_PPC64_SECTOFF
, 1, 16, 0xffff, 0, FALSE
, signed,
450 ppc64_elf_sectoff_reloc
),
452 /* Like R_PPC64_SECTOFF, but no overflow warning. */
453 HOW (R_PPC64_SECTOFF_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
454 ppc64_elf_sectoff_reloc
),
456 /* 16-bit upper half section relative relocation. */
457 HOW (R_PPC64_SECTOFF_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
458 ppc64_elf_sectoff_reloc
),
460 /* 16-bit upper half adjusted section relative relocation. */
461 HOW (R_PPC64_SECTOFF_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
462 ppc64_elf_sectoff_ha_reloc
),
464 /* Like R_PPC64_REL24 without touching the two least significant bits. */
465 HOW (R_PPC64_REL30
, 2, 30, 0xfffffffc, 2, TRUE
, dont
,
466 bfd_elf_generic_reloc
),
468 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
470 /* A standard 64-bit relocation. */
471 HOW (R_PPC64_ADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
472 bfd_elf_generic_reloc
),
474 /* The bits 32-47 of an address. */
475 HOW (R_PPC64_ADDR16_HIGHER
, 1, 16, 0xffff, 32, FALSE
, dont
,
476 bfd_elf_generic_reloc
),
478 /* The bits 32-47 of an address, plus 1 if the contents of the low
479 16 bits, treated as a signed number, is negative. */
480 HOW (R_PPC64_ADDR16_HIGHERA
, 1, 16, 0xffff, 32, FALSE
, dont
,
483 /* The bits 48-63 of an address. */
484 HOW (R_PPC64_ADDR16_HIGHEST
, 1, 16, 0xffff, 48, FALSE
, dont
,
485 bfd_elf_generic_reloc
),
487 /* The bits 48-63 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_HIGHESTA
, 1, 16, 0xffff, 48, FALSE
, dont
,
492 /* Like ADDR64, but may be unaligned. */
493 HOW (R_PPC64_UADDR64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
494 bfd_elf_generic_reloc
),
496 /* 64-bit relative relocation. */
497 HOW (R_PPC64_REL64
, 4, 64, 0xffffffffffffffffULL
, 0, TRUE
, dont
,
498 bfd_elf_generic_reloc
),
500 /* 64-bit relocation to the symbol's procedure linkage table. */
501 HOW (R_PPC64_PLT64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
502 ppc64_elf_unhandled_reloc
),
504 /* 64-bit PC relative relocation to the symbol's procedure linkage
506 /* FIXME: R_PPC64_PLTREL64 not supported. */
507 HOW (R_PPC64_PLTREL64
, 4, 64, 0xffffffffffffffffULL
, 0, TRUE
, dont
,
508 ppc64_elf_unhandled_reloc
),
510 /* 16 bit TOC-relative relocation. */
511 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
512 HOW (R_PPC64_TOC16
, 1, 16, 0xffff, 0, FALSE
, signed,
513 ppc64_elf_toc_reloc
),
515 /* 16 bit TOC-relative relocation without overflow. */
516 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
517 HOW (R_PPC64_TOC16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
518 ppc64_elf_toc_reloc
),
520 /* 16 bit TOC-relative relocation, high 16 bits. */
521 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
522 HOW (R_PPC64_TOC16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
523 ppc64_elf_toc_reloc
),
525 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
526 contents of the low 16 bits, treated as a signed number, is
528 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
529 HOW (R_PPC64_TOC16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
530 ppc64_elf_toc_ha_reloc
),
532 /* 64-bit relocation; insert value of TOC base (.TOC.). */
533 /* R_PPC64_TOC 51 doubleword64 .TOC. */
534 HOW (R_PPC64_TOC
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
535 ppc64_elf_toc64_reloc
),
537 /* Like R_PPC64_GOT16, but also informs the link editor that the
538 value to relocate may (!) refer to a PLT entry which the link
539 editor (a) may replace with the symbol value. If the link editor
540 is unable to fully resolve the symbol, it may (b) create a PLT
541 entry and store the address to the new PLT entry in the GOT.
542 This permits lazy resolution of function symbols at run time.
543 The link editor may also skip all of this and just (c) emit a
544 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
545 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
546 HOW (R_PPC64_PLTGOT16
, 1, 16, 0xffff, 0, FALSE
,signed,
547 ppc64_elf_unhandled_reloc
),
549 /* Like R_PPC64_PLTGOT16, but without overflow. */
550 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
551 HOW (R_PPC64_PLTGOT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
552 ppc64_elf_unhandled_reloc
),
554 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
555 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
556 HOW (R_PPC64_PLTGOT16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
557 ppc64_elf_unhandled_reloc
),
559 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
560 1 if the contents of the low 16 bits, treated as a signed number,
562 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
563 HOW (R_PPC64_PLTGOT16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
564 ppc64_elf_unhandled_reloc
),
566 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
567 HOW (R_PPC64_ADDR16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
568 bfd_elf_generic_reloc
),
570 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
571 HOW (R_PPC64_ADDR16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
572 bfd_elf_generic_reloc
),
574 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
575 HOW (R_PPC64_GOT16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
576 ppc64_elf_unhandled_reloc
),
578 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
579 HOW (R_PPC64_GOT16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
580 ppc64_elf_unhandled_reloc
),
582 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
583 HOW (R_PPC64_PLT16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
584 ppc64_elf_unhandled_reloc
),
586 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
587 HOW (R_PPC64_SECTOFF_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
588 ppc64_elf_sectoff_reloc
),
590 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
591 HOW (R_PPC64_SECTOFF_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
592 ppc64_elf_sectoff_reloc
),
594 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
595 HOW (R_PPC64_TOC16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
596 ppc64_elf_toc_reloc
),
598 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
599 HOW (R_PPC64_TOC16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
600 ppc64_elf_toc_reloc
),
602 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
603 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
604 HOW (R_PPC64_PLTGOT16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
605 ppc64_elf_unhandled_reloc
),
607 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
608 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
609 HOW (R_PPC64_PLTGOT16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
610 ppc64_elf_unhandled_reloc
),
612 /* Marker relocs for TLS. */
613 HOW (R_PPC64_TLS
, 2, 32, 0, 0, FALSE
, dont
,
614 bfd_elf_generic_reloc
),
616 HOW (R_PPC64_TLSGD
, 2, 32, 0, 0, FALSE
, dont
,
617 bfd_elf_generic_reloc
),
619 HOW (R_PPC64_TLSLD
, 2, 32, 0, 0, FALSE
, dont
,
620 bfd_elf_generic_reloc
),
622 /* Marker reloc for optimizing r2 save in prologue rather than on
623 each plt call stub. */
624 HOW (R_PPC64_TOCSAVE
, 2, 32, 0, 0, FALSE
, dont
,
625 bfd_elf_generic_reloc
),
627 /* Marker relocs on inline plt call instructions. */
628 HOW (R_PPC64_PLTSEQ
, 2, 32, 0, 0, FALSE
, dont
,
629 bfd_elf_generic_reloc
),
631 HOW (R_PPC64_PLTCALL
, 2, 32, 0, 0, FALSE
, dont
,
632 bfd_elf_generic_reloc
),
634 /* Computes the load module index of the load module that contains the
635 definition of its TLS sym. */
636 HOW (R_PPC64_DTPMOD64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
637 ppc64_elf_unhandled_reloc
),
639 /* Computes a dtv-relative displacement, the difference between the value
640 of sym+add and the base address of the thread-local storage block that
641 contains the definition of sym, minus 0x8000. */
642 HOW (R_PPC64_DTPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
643 ppc64_elf_unhandled_reloc
),
645 /* A 16 bit dtprel reloc. */
646 HOW (R_PPC64_DTPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
647 ppc64_elf_unhandled_reloc
),
649 /* Like DTPREL16, but no overflow. */
650 HOW (R_PPC64_DTPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
651 ppc64_elf_unhandled_reloc
),
653 /* Like DTPREL16_LO, but next higher group of 16 bits. */
654 HOW (R_PPC64_DTPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
655 ppc64_elf_unhandled_reloc
),
657 /* Like DTPREL16_HI, but adjust for low 16 bits. */
658 HOW (R_PPC64_DTPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
659 ppc64_elf_unhandled_reloc
),
661 /* Like DTPREL16_HI, but next higher group of 16 bits. */
662 HOW (R_PPC64_DTPREL16_HIGHER
, 1, 16, 0xffff, 32, FALSE
, dont
,
663 ppc64_elf_unhandled_reloc
),
665 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
666 HOW (R_PPC64_DTPREL16_HIGHERA
, 1, 16, 0xffff, 32, FALSE
, dont
,
667 ppc64_elf_unhandled_reloc
),
669 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
670 HOW (R_PPC64_DTPREL16_HIGHEST
, 1, 16, 0xffff, 48, FALSE
, dont
,
671 ppc64_elf_unhandled_reloc
),
673 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
674 HOW (R_PPC64_DTPREL16_HIGHESTA
, 1, 16, 0xffff, 48, FALSE
, dont
,
675 ppc64_elf_unhandled_reloc
),
677 /* Like DTPREL16, but for insns with a DS field. */
678 HOW (R_PPC64_DTPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
679 ppc64_elf_unhandled_reloc
),
681 /* Like DTPREL16_DS, but no overflow. */
682 HOW (R_PPC64_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
683 ppc64_elf_unhandled_reloc
),
685 /* Computes a tp-relative displacement, the difference between the value of
686 sym+add and the value of the thread pointer (r13). */
687 HOW (R_PPC64_TPREL64
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
688 ppc64_elf_unhandled_reloc
),
690 /* A 16 bit tprel reloc. */
691 HOW (R_PPC64_TPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
692 ppc64_elf_unhandled_reloc
),
694 /* Like TPREL16, but no overflow. */
695 HOW (R_PPC64_TPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
696 ppc64_elf_unhandled_reloc
),
698 /* Like TPREL16_LO, but next higher group of 16 bits. */
699 HOW (R_PPC64_TPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
700 ppc64_elf_unhandled_reloc
),
702 /* Like TPREL16_HI, but adjust for low 16 bits. */
703 HOW (R_PPC64_TPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
704 ppc64_elf_unhandled_reloc
),
706 /* Like TPREL16_HI, but next higher group of 16 bits. */
707 HOW (R_PPC64_TPREL16_HIGHER
, 1, 16, 0xffff, 32, FALSE
, dont
,
708 ppc64_elf_unhandled_reloc
),
710 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
711 HOW (R_PPC64_TPREL16_HIGHERA
, 1, 16, 0xffff, 32, FALSE
, dont
,
712 ppc64_elf_unhandled_reloc
),
714 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
715 HOW (R_PPC64_TPREL16_HIGHEST
, 1, 16, 0xffff, 48, FALSE
, dont
,
716 ppc64_elf_unhandled_reloc
),
718 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
719 HOW (R_PPC64_TPREL16_HIGHESTA
, 1, 16, 0xffff, 48, FALSE
, dont
,
720 ppc64_elf_unhandled_reloc
),
722 /* Like TPREL16, but for insns with a DS field. */
723 HOW (R_PPC64_TPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
724 ppc64_elf_unhandled_reloc
),
726 /* Like TPREL16_DS, but no overflow. */
727 HOW (R_PPC64_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
728 ppc64_elf_unhandled_reloc
),
730 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
731 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
732 to the first entry relative to the TOC base (r2). */
733 HOW (R_PPC64_GOT_TLSGD16
, 1, 16, 0xffff, 0, FALSE
, signed,
734 ppc64_elf_unhandled_reloc
),
736 /* Like GOT_TLSGD16, but no overflow. */
737 HOW (R_PPC64_GOT_TLSGD16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
738 ppc64_elf_unhandled_reloc
),
740 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
741 HOW (R_PPC64_GOT_TLSGD16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
742 ppc64_elf_unhandled_reloc
),
744 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
745 HOW (R_PPC64_GOT_TLSGD16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
746 ppc64_elf_unhandled_reloc
),
748 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
749 with values (sym+add)@dtpmod and zero, and computes the offset to the
750 first entry relative to the TOC base (r2). */
751 HOW (R_PPC64_GOT_TLSLD16
, 1, 16, 0xffff, 0, FALSE
, signed,
752 ppc64_elf_unhandled_reloc
),
754 /* Like GOT_TLSLD16, but no overflow. */
755 HOW (R_PPC64_GOT_TLSLD16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
756 ppc64_elf_unhandled_reloc
),
758 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
759 HOW (R_PPC64_GOT_TLSLD16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
760 ppc64_elf_unhandled_reloc
),
762 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
763 HOW (R_PPC64_GOT_TLSLD16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
764 ppc64_elf_unhandled_reloc
),
766 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
767 the offset to the entry relative to the TOC base (r2). */
768 HOW (R_PPC64_GOT_DTPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
769 ppc64_elf_unhandled_reloc
),
771 /* Like GOT_DTPREL16_DS, but no overflow. */
772 HOW (R_PPC64_GOT_DTPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
773 ppc64_elf_unhandled_reloc
),
775 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
776 HOW (R_PPC64_GOT_DTPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
777 ppc64_elf_unhandled_reloc
),
779 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
780 HOW (R_PPC64_GOT_DTPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
781 ppc64_elf_unhandled_reloc
),
783 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
784 offset to the entry relative to the TOC base (r2). */
785 HOW (R_PPC64_GOT_TPREL16_DS
, 1, 16, 0xfffc, 0, FALSE
, signed,
786 ppc64_elf_unhandled_reloc
),
788 /* Like GOT_TPREL16_DS, but no overflow. */
789 HOW (R_PPC64_GOT_TPREL16_LO_DS
, 1, 16, 0xfffc, 0, FALSE
, dont
,
790 ppc64_elf_unhandled_reloc
),
792 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
793 HOW (R_PPC64_GOT_TPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, signed,
794 ppc64_elf_unhandled_reloc
),
796 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
797 HOW (R_PPC64_GOT_TPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, signed,
798 ppc64_elf_unhandled_reloc
),
800 HOW (R_PPC64_JMP_IREL
, 0, 0, 0, 0, FALSE
, dont
,
801 ppc64_elf_unhandled_reloc
),
803 HOW (R_PPC64_IRELATIVE
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
804 bfd_elf_generic_reloc
),
806 /* A 16 bit relative relocation. */
807 HOW (R_PPC64_REL16
, 1, 16, 0xffff, 0, TRUE
, signed,
808 bfd_elf_generic_reloc
),
810 /* A 16 bit relative relocation without overflow. */
811 HOW (R_PPC64_REL16_LO
, 1, 16, 0xffff, 0, TRUE
, dont
,
812 bfd_elf_generic_reloc
),
814 /* The high order 16 bits of a relative address. */
815 HOW (R_PPC64_REL16_HI
, 1, 16, 0xffff, 16, TRUE
, signed,
816 bfd_elf_generic_reloc
),
818 /* The high order 16 bits of a relative address, plus 1 if the contents of
819 the low 16 bits, treated as a signed number, is negative. */
820 HOW (R_PPC64_REL16_HA
, 1, 16, 0xffff, 16, TRUE
, signed,
823 HOW (R_PPC64_REL16_HIGH
, 1, 16, 0xffff, 16, TRUE
, dont
,
824 bfd_elf_generic_reloc
),
826 HOW (R_PPC64_REL16_HIGHA
, 1, 16, 0xffff, 16, TRUE
, dont
,
829 HOW (R_PPC64_REL16_HIGHER
, 1, 16, 0xffff, 32, TRUE
, dont
,
830 bfd_elf_generic_reloc
),
832 HOW (R_PPC64_REL16_HIGHERA
, 1, 16, 0xffff, 32, TRUE
, dont
,
835 HOW (R_PPC64_REL16_HIGHEST
, 1, 16, 0xffff, 48, TRUE
, dont
,
836 bfd_elf_generic_reloc
),
838 HOW (R_PPC64_REL16_HIGHESTA
, 1, 16, 0xffff, 48, TRUE
, dont
,
841 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
842 HOW (R_PPC64_REL16DX_HA
, 2, 16, 0x1fffc1, 16, TRUE
, signed,
845 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
846 HOW (R_PPC64_16DX_HA
, 2, 16, 0x1fffc1, 16, FALSE
, signed,
849 /* Like R_PPC64_ADDR16_HI, but no overflow. */
850 HOW (R_PPC64_ADDR16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
851 bfd_elf_generic_reloc
),
853 /* Like R_PPC64_ADDR16_HA, but no overflow. */
854 HOW (R_PPC64_ADDR16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
857 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
858 HOW (R_PPC64_DTPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
859 ppc64_elf_unhandled_reloc
),
861 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
862 HOW (R_PPC64_DTPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
863 ppc64_elf_unhandled_reloc
),
865 /* Like R_PPC64_TPREL16_HI, but no overflow. */
866 HOW (R_PPC64_TPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
867 ppc64_elf_unhandled_reloc
),
869 /* Like R_PPC64_TPREL16_HA, but no overflow. */
870 HOW (R_PPC64_TPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
871 ppc64_elf_unhandled_reloc
),
873 /* Marker reloc on ELFv2 large-model function entry. */
874 HOW (R_PPC64_ENTRY
, 2, 32, 0, 0, FALSE
, dont
,
875 bfd_elf_generic_reloc
),
877 /* Like ADDR64, but use local entry point of function. */
878 HOW (R_PPC64_ADDR64_LOCAL
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
879 bfd_elf_generic_reloc
),
881 /* GNU extension to record C++ vtable hierarchy. */
882 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, FALSE
, dont
,
885 /* GNU extension to record C++ vtable member usage. */
886 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, FALSE
, dont
,
891 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
895 ppc_howto_init (void)
897 unsigned int i
, type
;
899 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
901 type
= ppc64_elf_howto_raw
[i
].type
;
902 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
903 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
907 static reloc_howto_type
*
908 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
909 bfd_reloc_code_real_type code
)
911 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
913 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
914 /* Initialize howto table if needed. */
920 /* xgettext:c-format */
921 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
923 bfd_set_error (bfd_error_bad_value
);
926 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
928 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
930 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
932 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
934 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
936 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
938 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
940 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
942 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
944 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
946 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
948 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
950 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
952 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
954 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
956 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
958 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
960 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
962 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
964 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
966 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
968 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
970 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
972 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
974 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
976 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
978 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
980 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
982 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
984 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
986 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
988 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
990 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
992 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
994 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
996 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
998 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1000 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1002 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1004 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1006 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1008 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1010 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1012 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1014 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1016 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1018 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1020 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1022 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1024 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1026 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1028 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1030 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1032 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1034 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1036 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1038 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1040 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1042 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1044 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1046 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1048 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1050 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1052 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1054 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1056 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1058 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1060 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1062 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1064 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1066 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1068 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1070 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1072 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1074 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1076 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1078 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1080 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1082 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1084 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1086 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1088 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1090 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1092 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1094 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1096 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1098 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1100 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1102 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1104 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1106 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1108 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1110 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1112 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1114 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1116 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1118 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1120 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1122 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1124 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1126 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1128 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1130 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1132 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1134 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1136 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1138 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1140 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1142 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1144 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1146 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1148 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1150 case BFD_RELOC_PPC64_REL16_HIGH
: r
= R_PPC64_REL16_HIGH
;
1152 case BFD_RELOC_PPC64_REL16_HIGHA
: r
= R_PPC64_REL16_HIGHA
;
1154 case BFD_RELOC_PPC64_REL16_HIGHER
: r
= R_PPC64_REL16_HIGHER
;
1156 case BFD_RELOC_PPC64_REL16_HIGHERA
: r
= R_PPC64_REL16_HIGHERA
;
1158 case BFD_RELOC_PPC64_REL16_HIGHEST
: r
= R_PPC64_REL16_HIGHEST
;
1160 case BFD_RELOC_PPC64_REL16_HIGHESTA
: r
= R_PPC64_REL16_HIGHESTA
;
1162 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1164 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1166 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1168 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1170 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1172 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1176 return ppc64_elf_howto_table
[r
];
1179 static reloc_howto_type
*
1180 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1185 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1186 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1187 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1188 return &ppc64_elf_howto_raw
[i
];
1193 /* Set the howto pointer for a PowerPC ELF reloc. */
1196 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1197 Elf_Internal_Rela
*dst
)
1201 /* Initialize howto table if needed. */
1202 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1205 type
= ELF64_R_TYPE (dst
->r_info
);
1206 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1208 /* xgettext:c-format */
1209 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1211 bfd_set_error (bfd_error_bad_value
);
1214 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1215 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1217 /* xgettext:c-format */
1218 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1220 bfd_set_error (bfd_error_bad_value
);
1227 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1229 static bfd_reloc_status_type
1230 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1231 void *data
, asection
*input_section
,
1232 bfd
*output_bfd
, char **error_message
)
1234 enum elf_ppc64_reloc_type r_type
;
1236 bfd_size_type octets
;
1239 /* If this is a relocatable link (output_bfd test tells us), just
1240 call the generic function. Any adjustment will be done at final
1242 if (output_bfd
!= NULL
)
1243 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1244 input_section
, output_bfd
, error_message
);
1246 /* Adjust the addend for sign extension of the low 16 bits.
1247 We won't actually be using the low 16 bits, so trashing them
1249 reloc_entry
->addend
+= 0x8000;
1250 r_type
= reloc_entry
->howto
->type
;
1251 if (r_type
!= R_PPC64_REL16DX_HA
)
1252 return bfd_reloc_continue
;
1255 if (!bfd_is_com_section (symbol
->section
))
1256 value
= symbol
->value
;
1257 value
+= (reloc_entry
->addend
1258 + symbol
->section
->output_offset
1259 + symbol
->section
->output_section
->vma
);
1260 value
-= (reloc_entry
->address
1261 + input_section
->output_offset
1262 + input_section
->output_section
->vma
);
1263 value
= (bfd_signed_vma
) value
>> 16;
1265 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1266 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1268 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1269 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1270 if (value
+ 0x8000 > 0xffff)
1271 return bfd_reloc_overflow
;
1272 return bfd_reloc_ok
;
1275 static bfd_reloc_status_type
1276 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1277 void *data
, asection
*input_section
,
1278 bfd
*output_bfd
, char **error_message
)
1280 if (output_bfd
!= NULL
)
1281 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1282 input_section
, output_bfd
, error_message
);
1284 if (strcmp (symbol
->section
->name
, ".opd") == 0
1285 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1287 bfd_vma dest
= opd_entry_value (symbol
->section
,
1288 symbol
->value
+ reloc_entry
->addend
,
1290 if (dest
!= (bfd_vma
) -1)
1291 reloc_entry
->addend
= dest
- (symbol
->value
1292 + symbol
->section
->output_section
->vma
1293 + symbol
->section
->output_offset
);
1297 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1299 if (symbol
->section
->owner
!= abfd
1300 && symbol
->section
->owner
!= NULL
1301 && abiversion (symbol
->section
->owner
) >= 2)
1305 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1307 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1309 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1311 elfsym
= (elf_symbol_type
*) symdef
;
1317 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1319 return bfd_reloc_continue
;
1322 static bfd_reloc_status_type
1323 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1324 void *data
, asection
*input_section
,
1325 bfd
*output_bfd
, char **error_message
)
1328 enum elf_ppc64_reloc_type r_type
;
1329 bfd_size_type octets
;
1330 /* Assume 'at' branch hints. */
1331 bfd_boolean is_isa_v2
= TRUE
;
1333 /* If this is a relocatable link (output_bfd test tells us), just
1334 call the generic function. Any adjustment will be done at final
1336 if (output_bfd
!= NULL
)
1337 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1338 input_section
, output_bfd
, error_message
);
1340 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1341 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1342 insn
&= ~(0x01 << 21);
1343 r_type
= reloc_entry
->howto
->type
;
1344 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1345 || r_type
== R_PPC64_REL14_BRTAKEN
)
1346 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1350 /* Set 'a' bit. This is 0b00010 in BO field for branch
1351 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1352 for branch on CTR insns (BO == 1a00t or 1a01t). */
1353 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1355 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1365 if (!bfd_is_com_section (symbol
->section
))
1366 target
= symbol
->value
;
1367 target
+= symbol
->section
->output_section
->vma
;
1368 target
+= symbol
->section
->output_offset
;
1369 target
+= reloc_entry
->addend
;
1371 from
= (reloc_entry
->address
1372 + input_section
->output_offset
1373 + input_section
->output_section
->vma
);
1375 /* Invert 'y' bit if not the default. */
1376 if ((bfd_signed_vma
) (target
- from
) < 0)
1379 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1381 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1382 input_section
, output_bfd
, error_message
);
1385 static bfd_reloc_status_type
1386 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1387 void *data
, asection
*input_section
,
1388 bfd
*output_bfd
, char **error_message
)
1390 /* If this is a relocatable link (output_bfd test tells us), just
1391 call the generic function. Any adjustment will be done at final
1393 if (output_bfd
!= NULL
)
1394 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1395 input_section
, output_bfd
, error_message
);
1397 /* Subtract the symbol section base address. */
1398 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1399 return bfd_reloc_continue
;
1402 static bfd_reloc_status_type
1403 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1404 void *data
, asection
*input_section
,
1405 bfd
*output_bfd
, char **error_message
)
1407 /* If this is a relocatable link (output_bfd test tells us), just
1408 call the generic function. Any adjustment will be done at final
1410 if (output_bfd
!= NULL
)
1411 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1412 input_section
, output_bfd
, error_message
);
1414 /* Subtract the symbol section base address. */
1415 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1417 /* Adjust the addend for sign extension of the low 16 bits. */
1418 reloc_entry
->addend
+= 0x8000;
1419 return bfd_reloc_continue
;
1422 static bfd_reloc_status_type
1423 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1424 void *data
, asection
*input_section
,
1425 bfd
*output_bfd
, char **error_message
)
1429 /* If this is a relocatable link (output_bfd test tells us), just
1430 call the generic function. Any adjustment will be done at final
1432 if (output_bfd
!= NULL
)
1433 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1434 input_section
, output_bfd
, error_message
);
1436 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1438 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1440 /* Subtract the TOC base address. */
1441 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1442 return bfd_reloc_continue
;
1445 static bfd_reloc_status_type
1446 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1447 void *data
, asection
*input_section
,
1448 bfd
*output_bfd
, char **error_message
)
1452 /* If this is a relocatable link (output_bfd test tells us), just
1453 call the generic function. Any adjustment will be done at final
1455 if (output_bfd
!= NULL
)
1456 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1457 input_section
, output_bfd
, error_message
);
1459 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1461 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1463 /* Subtract the TOC base address. */
1464 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1466 /* Adjust the addend for sign extension of the low 16 bits. */
1467 reloc_entry
->addend
+= 0x8000;
1468 return bfd_reloc_continue
;
1471 static bfd_reloc_status_type
1472 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1473 void *data
, asection
*input_section
,
1474 bfd
*output_bfd
, char **error_message
)
1477 bfd_size_type octets
;
1479 /* If this is a relocatable link (output_bfd test tells us), just
1480 call the generic function. Any adjustment will be done at final
1482 if (output_bfd
!= NULL
)
1483 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1484 input_section
, output_bfd
, error_message
);
1486 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1488 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1490 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1491 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1492 return bfd_reloc_ok
;
1495 static bfd_reloc_status_type
1496 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1497 void *data
, asection
*input_section
,
1498 bfd
*output_bfd
, char **error_message
)
1500 /* If this is a relocatable link (output_bfd test tells us), just
1501 call the generic function. Any adjustment will be done at final
1503 if (output_bfd
!= NULL
)
1504 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1505 input_section
, output_bfd
, error_message
);
1507 if (error_message
!= NULL
)
1509 static char buf
[60];
1510 sprintf (buf
, "generic linker can't handle %s",
1511 reloc_entry
->howto
->name
);
1512 *error_message
= buf
;
1514 return bfd_reloc_dangerous
;
1517 /* Track GOT entries needed for a given symbol. We might need more
1518 than one got entry per symbol. */
1521 struct got_entry
*next
;
1523 /* The symbol addend that we'll be placing in the GOT. */
1526 /* Unlike other ELF targets, we use separate GOT entries for the same
1527 symbol referenced from different input files. This is to support
1528 automatic multiple TOC/GOT sections, where the TOC base can vary
1529 from one input file to another. After partitioning into TOC groups
1530 we merge entries within the group.
1532 Point to the BFD owning this GOT entry. */
1535 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1536 TLS_TPREL or TLS_DTPREL for tls entries. */
1537 unsigned char tls_type
;
1539 /* Non-zero if got.ent points to real entry. */
1540 unsigned char is_indirect
;
1542 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1545 bfd_signed_vma refcount
;
1547 struct got_entry
*ent
;
1551 /* The same for PLT. */
1554 struct plt_entry
*next
;
1560 bfd_signed_vma refcount
;
1565 struct ppc64_elf_obj_tdata
1567 struct elf_obj_tdata elf
;
1569 /* Shortcuts to dynamic linker sections. */
1573 /* Used during garbage collection. We attach global symbols defined
1574 on removed .opd entries to this section so that the sym is removed. */
1575 asection
*deleted_section
;
1577 /* TLS local dynamic got entry handling. Support for multiple GOT
1578 sections means we potentially need one of these for each input bfd. */
1579 struct got_entry tlsld_got
;
1583 /* A copy of relocs before they are modified for --emit-relocs. */
1584 Elf_Internal_Rela
*relocs
;
1586 /* Section contents. */
1590 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1591 the reloc to be in the range -32768 to 32767. */
1592 unsigned int has_small_toc_reloc
: 1;
1594 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1595 instruction not one we handle. */
1596 unsigned int unexpected_toc_insn
: 1;
1598 /* Set if got relocs that can be optimised are present in this file. */
1599 unsigned int has_gotrel
: 1;
1602 #define ppc64_elf_tdata(bfd) \
1603 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1605 #define ppc64_tlsld_got(bfd) \
1606 (&ppc64_elf_tdata (bfd)->tlsld_got)
1608 #define is_ppc64_elf(bfd) \
1609 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1610 && elf_object_id (bfd) == PPC64_ELF_DATA)
1612 /* Override the generic function because we store some extras. */
1615 ppc64_elf_mkobject (bfd
*abfd
)
1617 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1621 /* Fix bad default arch selected for a 64 bit input bfd when the
1622 default is 32 bit. Also select arch based on apuinfo. */
1625 ppc64_elf_object_p (bfd
*abfd
)
1627 if (!abfd
->arch_info
->the_default
)
1630 if (abfd
->arch_info
->bits_per_word
== 32)
1632 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1634 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1636 /* Relies on arch after 32 bit default being 64 bit default. */
1637 abfd
->arch_info
= abfd
->arch_info
->next
;
1638 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1641 return _bfd_elf_ppc_set_arch (abfd
);
1644 /* Support for core dump NOTE sections. */
1647 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1649 size_t offset
, size
;
1651 if (note
->descsz
!= 504)
1655 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1658 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1664 /* Make a ".reg/999" section. */
1665 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1666 size
, note
->descpos
+ offset
);
1670 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1672 if (note
->descsz
!= 136)
1675 elf_tdata (abfd
)->core
->pid
1676 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1677 elf_tdata (abfd
)->core
->program
1678 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1679 elf_tdata (abfd
)->core
->command
1680 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1686 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1696 char data
[136] ATTRIBUTE_NONSTRING
;
1699 va_start (ap
, note_type
);
1700 memset (data
, 0, sizeof (data
));
1701 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1702 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1704 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1705 -Wstringop-truncation:
1706 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1708 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1710 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1711 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1715 return elfcore_write_note (abfd
, buf
, bufsiz
,
1716 "CORE", note_type
, data
, sizeof (data
));
1727 va_start (ap
, note_type
);
1728 memset (data
, 0, 112);
1729 pid
= va_arg (ap
, long);
1730 bfd_put_32 (abfd
, pid
, data
+ 32);
1731 cursig
= va_arg (ap
, int);
1732 bfd_put_16 (abfd
, cursig
, data
+ 12);
1733 greg
= va_arg (ap
, const void *);
1734 memcpy (data
+ 112, greg
, 384);
1735 memset (data
+ 496, 0, 8);
1737 return elfcore_write_note (abfd
, buf
, bufsiz
,
1738 "CORE", note_type
, data
, sizeof (data
));
1743 /* Add extra PPC sections. */
1745 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1747 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1748 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1749 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1750 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1751 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1752 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1753 { NULL
, 0, 0, 0, 0 }
1756 enum _ppc64_sec_type
{
1762 struct _ppc64_elf_section_data
1764 struct bfd_elf_section_data elf
;
1768 /* An array with one entry for each opd function descriptor,
1769 and some spares since opd entries may be either 16 or 24 bytes. */
1770 #define OPD_NDX(OFF) ((OFF) >> 4)
1771 struct _opd_sec_data
1773 /* Points to the function code section for local opd entries. */
1774 asection
**func_sec
;
1776 /* After editing .opd, adjust references to opd local syms. */
1780 /* An array for toc sections, indexed by offset/8. */
1781 struct _toc_sec_data
1783 /* Specifies the relocation symbol index used at a given toc offset. */
1786 /* And the relocation addend. */
1791 enum _ppc64_sec_type sec_type
:2;
1793 /* Flag set when small branches are detected. Used to
1794 select suitable defaults for the stub group size. */
1795 unsigned int has_14bit_branch
:1;
1797 /* Flag set when PLTCALL relocs are detected. */
1798 unsigned int has_pltcall
:1;
1800 /* Flag set when section has GOT relocations that can be optimised. */
1801 unsigned int has_gotrel
:1;
1804 #define ppc64_elf_section_data(sec) \
1805 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
1808 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1810 if (!sec
->used_by_bfd
)
1812 struct _ppc64_elf_section_data
*sdata
;
1813 bfd_size_type amt
= sizeof (*sdata
);
1815 sdata
= bfd_zalloc (abfd
, amt
);
1818 sec
->used_by_bfd
= sdata
;
1821 return _bfd_elf_new_section_hook (abfd
, sec
);
1824 static struct _opd_sec_data
*
1825 get_opd_info (asection
* sec
)
1828 && ppc64_elf_section_data (sec
) != NULL
1829 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
1830 return &ppc64_elf_section_data (sec
)->u
.opd
;
1834 /* Parameters for the qsort hook. */
1835 static bfd_boolean synthetic_relocatable
;
1836 static asection
*synthetic_opd
;
1838 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
1841 compare_symbols (const void *ap
, const void *bp
)
1843 const asymbol
*a
= *(const asymbol
**) ap
;
1844 const asymbol
*b
= *(const asymbol
**) bp
;
1846 /* Section symbols first. */
1847 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
1849 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
1852 /* then .opd symbols. */
1853 if (synthetic_opd
!= NULL
)
1855 if (strcmp (a
->section
->name
, ".opd") == 0
1856 && strcmp (b
->section
->name
, ".opd") != 0)
1858 if (strcmp (a
->section
->name
, ".opd") != 0
1859 && strcmp (b
->section
->name
, ".opd") == 0)
1863 /* then other code symbols. */
1864 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1865 == (SEC_CODE
| SEC_ALLOC
))
1866 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1867 != (SEC_CODE
| SEC_ALLOC
)))
1870 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1871 != (SEC_CODE
| SEC_ALLOC
))
1872 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1873 == (SEC_CODE
| SEC_ALLOC
)))
1876 if (synthetic_relocatable
)
1878 if (a
->section
->id
< b
->section
->id
)
1881 if (a
->section
->id
> b
->section
->id
)
1885 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
1888 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
1891 /* For syms with the same value, prefer strong dynamic global function
1892 syms over other syms. */
1893 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
1896 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
1899 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
1902 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
1905 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
1908 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
1911 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
1914 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
1920 /* Search SYMS for a symbol of the given VALUE. */
1923 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
1927 if (id
== (unsigned) -1)
1931 mid
= (lo
+ hi
) >> 1;
1932 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
1934 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
1944 mid
= (lo
+ hi
) >> 1;
1945 if (syms
[mid
]->section
->id
< id
)
1947 else if (syms
[mid
]->section
->id
> id
)
1949 else if (syms
[mid
]->value
< value
)
1951 else if (syms
[mid
]->value
> value
)
1961 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
1963 bfd_vma vma
= *(bfd_vma
*) ptr
;
1964 return ((section
->flags
& SEC_ALLOC
) != 0
1965 && section
->vma
<= vma
1966 && vma
< section
->vma
+ section
->size
);
1969 /* Create synthetic symbols, effectively restoring "dot-symbol" function
1970 entry syms. Also generate @plt symbols for the glink branch table.
1971 Returns count of synthetic symbols in RET or -1 on error. */
1974 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
1975 long static_count
, asymbol
**static_syms
,
1976 long dyn_count
, asymbol
**dyn_syms
,
1982 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
1983 asection
*opd
= NULL
;
1984 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
1986 int abi
= abiversion (abfd
);
1992 opd
= bfd_get_section_by_name (abfd
, ".opd");
1993 if (opd
== NULL
&& abi
== 1)
2005 symcount
= static_count
;
2007 symcount
+= dyn_count
;
2011 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2015 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2017 /* Use both symbol tables. */
2018 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2019 memcpy (syms
+ static_count
, dyn_syms
,
2020 (dyn_count
+ 1) * sizeof (*syms
));
2022 else if (!relocatable
&& static_count
== 0)
2023 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2025 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2027 /* Trim uninteresting symbols. Interesting symbols are section,
2028 function, and notype symbols. */
2029 for (i
= 0, j
= 0; i
< symcount
; ++i
)
2030 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
2031 | BSF_RELC
| BSF_SRELC
)) == 0)
2032 syms
[j
++] = syms
[i
];
2035 synthetic_relocatable
= relocatable
;
2036 synthetic_opd
= opd
;
2037 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2039 if (!relocatable
&& symcount
> 1)
2041 /* Trim duplicate syms, since we may have merged the normal
2042 and dynamic symbols. Actually, we only care about syms
2043 that have different values, so trim any with the same
2044 value. Don't consider ifunc and ifunc resolver symbols
2045 duplicates however, because GDB wants to know whether a
2046 text symbol is an ifunc resolver. */
2047 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2049 const asymbol
*s0
= syms
[i
- 1];
2050 const asymbol
*s1
= syms
[i
];
2052 if ((s0
->value
+ s0
->section
->vma
2053 != s1
->value
+ s1
->section
->vma
)
2054 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2055 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2056 syms
[j
++] = syms
[i
];
2062 /* Note that here and in compare_symbols we can't compare opd and
2063 sym->section directly. With separate debug info files, the
2064 symbols will be extracted from the debug file while abfd passed
2065 to this function is the real binary. */
2066 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2070 for (; i
< symcount
; ++i
)
2071 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2072 | SEC_THREAD_LOCAL
))
2073 != (SEC_CODE
| SEC_ALLOC
))
2074 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2078 for (; i
< symcount
; ++i
)
2079 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2083 for (; i
< symcount
; ++i
)
2084 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2088 for (; i
< symcount
; ++i
)
2089 if (((syms
[i
]->section
->flags
2090 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2091 != (SEC_CODE
| SEC_ALLOC
))
2099 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2104 if (opdsymend
== secsymend
)
2107 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2108 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2112 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2119 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2123 while (r
< opd
->relocation
+ relcount
2124 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2127 if (r
== opd
->relocation
+ relcount
)
2130 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2133 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2136 sym
= *r
->sym_ptr_ptr
;
2137 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2138 sym
->section
->id
, sym
->value
+ r
->addend
))
2141 size
+= sizeof (asymbol
);
2142 size
+= strlen (syms
[i
]->name
) + 2;
2148 s
= *ret
= bfd_malloc (size
);
2155 names
= (char *) (s
+ count
);
2157 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2161 while (r
< opd
->relocation
+ relcount
2162 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2165 if (r
== opd
->relocation
+ relcount
)
2168 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2171 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2174 sym
= *r
->sym_ptr_ptr
;
2175 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2176 sym
->section
->id
, sym
->value
+ r
->addend
))
2181 s
->flags
|= BSF_SYNTHETIC
;
2182 s
->section
= sym
->section
;
2183 s
->value
= sym
->value
+ r
->addend
;
2186 len
= strlen (syms
[i
]->name
);
2187 memcpy (names
, syms
[i
]->name
, len
+ 1);
2189 /* Have udata.p point back to the original symbol this
2190 synthetic symbol was derived from. */
2191 s
->udata
.p
= syms
[i
];
2198 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2199 bfd_byte
*contents
= NULL
;
2201 size_t plt_count
= 0;
2202 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2203 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2206 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2208 free_contents_and_exit_err
:
2210 free_contents_and_exit
:
2217 for (i
= secsymend
; i
< opdsymend
; ++i
)
2221 /* Ignore bogus symbols. */
2222 if (syms
[i
]->value
> opd
->size
- 8)
2225 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2226 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2229 size
+= sizeof (asymbol
);
2230 size
+= strlen (syms
[i
]->name
) + 2;
2234 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2236 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2238 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2240 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2242 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2243 goto free_contents_and_exit_err
;
2245 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2246 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2249 extdynend
= extdyn
+ dynamic
->size
;
2250 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2252 Elf_Internal_Dyn dyn
;
2253 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2255 if (dyn
.d_tag
== DT_NULL
)
2258 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2260 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2261 See comment in ppc64_elf_finish_dynamic_sections. */
2262 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2263 /* The .glink section usually does not survive the final
2264 link; search for the section (usually .text) where the
2265 glink stubs now reside. */
2266 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2277 /* Determine __glink trampoline by reading the relative branch
2278 from the first glink stub. */
2280 unsigned int off
= 0;
2282 while (bfd_get_section_contents (abfd
, glink
, buf
,
2283 glink_vma
+ off
- glink
->vma
, 4))
2285 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2287 if ((insn
& ~0x3fffffc) == 0)
2290 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2299 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2301 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2304 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2305 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
2306 goto free_contents_and_exit_err
;
2308 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
2309 size
+= plt_count
* sizeof (asymbol
);
2311 p
= relplt
->relocation
;
2312 for (i
= 0; i
< plt_count
; i
++, p
++)
2314 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2316 size
+= sizeof ("+0x") - 1 + 16;
2322 goto free_contents_and_exit
;
2323 s
= *ret
= bfd_malloc (size
);
2325 goto free_contents_and_exit_err
;
2327 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2329 for (i
= secsymend
; i
< opdsymend
; ++i
)
2333 if (syms
[i
]->value
> opd
->size
- 8)
2336 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2337 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2341 asection
*sec
= abfd
->sections
;
2348 size_t mid
= (lo
+ hi
) >> 1;
2349 if (syms
[mid
]->section
->vma
< ent
)
2351 else if (syms
[mid
]->section
->vma
> ent
)
2355 sec
= syms
[mid
]->section
;
2360 if (lo
>= hi
&& lo
> codesecsym
)
2361 sec
= syms
[lo
- 1]->section
;
2363 for (; sec
!= NULL
; sec
= sec
->next
)
2367 /* SEC_LOAD may not be set if SEC is from a separate debug
2369 if ((sec
->flags
& SEC_ALLOC
) == 0)
2371 if ((sec
->flags
& SEC_CODE
) != 0)
2374 s
->flags
|= BSF_SYNTHETIC
;
2375 s
->value
= ent
- s
->section
->vma
;
2378 len
= strlen (syms
[i
]->name
);
2379 memcpy (names
, syms
[i
]->name
, len
+ 1);
2381 /* Have udata.p point back to the original symbol this
2382 synthetic symbol was derived from. */
2383 s
->udata
.p
= syms
[i
];
2389 if (glink
!= NULL
&& relplt
!= NULL
)
2393 /* Add a symbol for the main glink trampoline. */
2394 memset (s
, 0, sizeof *s
);
2396 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2398 s
->value
= resolv_vma
- glink
->vma
;
2400 memcpy (names
, "__glink_PLTresolve",
2401 sizeof ("__glink_PLTresolve"));
2402 names
+= sizeof ("__glink_PLTresolve");
2407 /* FIXME: It would be very much nicer to put sym@plt on the
2408 stub rather than on the glink branch table entry. The
2409 objdump disassembler would then use a sensible symbol
2410 name on plt calls. The difficulty in doing so is
2411 a) finding the stubs, and,
2412 b) matching stubs against plt entries, and,
2413 c) there can be multiple stubs for a given plt entry.
2415 Solving (a) could be done by code scanning, but older
2416 ppc64 binaries used different stubs to current code.
2417 (b) is the tricky one since you need to known the toc
2418 pointer for at least one function that uses a pic stub to
2419 be able to calculate the plt address referenced.
2420 (c) means gdb would need to set multiple breakpoints (or
2421 find the glink branch itself) when setting breakpoints
2422 for pending shared library loads. */
2423 p
= relplt
->relocation
;
2424 for (i
= 0; i
< plt_count
; i
++, p
++)
2428 *s
= **p
->sym_ptr_ptr
;
2429 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2430 we are defining a symbol, ensure one of them is set. */
2431 if ((s
->flags
& BSF_LOCAL
) == 0)
2432 s
->flags
|= BSF_GLOBAL
;
2433 s
->flags
|= BSF_SYNTHETIC
;
2435 s
->value
= glink_vma
- glink
->vma
;
2438 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2439 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2443 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2444 names
+= sizeof ("+0x") - 1;
2445 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2446 names
+= strlen (names
);
2448 memcpy (names
, "@plt", sizeof ("@plt"));
2449 names
+= sizeof ("@plt");
2469 /* The following functions are specific to the ELF linker, while
2470 functions above are used generally. Those named ppc64_elf_* are
2471 called by the main ELF linker code. They appear in this file more
2472 or less in the order in which they are called. eg.
2473 ppc64_elf_check_relocs is called early in the link process,
2474 ppc64_elf_finish_dynamic_sections is one of the last functions
2477 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2478 functions have both a function code symbol and a function descriptor
2479 symbol. A call to foo in a relocatable object file looks like:
2486 The function definition in another object file might be:
2490 . .quad .TOC.@tocbase
2496 When the linker resolves the call during a static link, the branch
2497 unsurprisingly just goes to .foo and the .opd information is unused.
2498 If the function definition is in a shared library, things are a little
2499 different: The call goes via a plt call stub, the opd information gets
2500 copied to the plt, and the linker patches the nop.
2508 . std 2,40(1) # in practice, the call stub
2509 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2510 . addi 11,11,Lfoo@toc@l # this is the general idea
2518 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2520 The "reloc ()" notation is supposed to indicate that the linker emits
2521 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2524 What are the difficulties here? Well, firstly, the relocations
2525 examined by the linker in check_relocs are against the function code
2526 sym .foo, while the dynamic relocation in the plt is emitted against
2527 the function descriptor symbol, foo. Somewhere along the line, we need
2528 to carefully copy dynamic link information from one symbol to the other.
2529 Secondly, the generic part of the elf linker will make .foo a dynamic
2530 symbol as is normal for most other backends. We need foo dynamic
2531 instead, at least for an application final link. However, when
2532 creating a shared library containing foo, we need to have both symbols
2533 dynamic so that references to .foo are satisfied during the early
2534 stages of linking. Otherwise the linker might decide to pull in a
2535 definition from some other object, eg. a static library.
2537 Update: As of August 2004, we support a new convention. Function
2538 calls may use the function descriptor symbol, ie. "bl foo". This
2539 behaves exactly as "bl .foo". */
2541 /* Of those relocs that might be copied as dynamic relocs, this
2542 function selects those that must be copied when linking a shared
2543 library or PIE, even when the symbol is local. */
2546 must_be_dyn_reloc (struct bfd_link_info
*info
,
2547 enum elf_ppc64_reloc_type r_type
)
2552 /* Only relative relocs can be resolved when the object load
2553 address isn't fixed. DTPREL64 is excluded because the
2554 dynamic linker needs to differentiate global dynamic from
2555 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2563 case R_PPC64_TPREL16
:
2564 case R_PPC64_TPREL16_LO
:
2565 case R_PPC64_TPREL16_HI
:
2566 case R_PPC64_TPREL16_HA
:
2567 case R_PPC64_TPREL16_DS
:
2568 case R_PPC64_TPREL16_LO_DS
:
2569 case R_PPC64_TPREL16_HIGH
:
2570 case R_PPC64_TPREL16_HIGHA
:
2571 case R_PPC64_TPREL16_HIGHER
:
2572 case R_PPC64_TPREL16_HIGHERA
:
2573 case R_PPC64_TPREL16_HIGHEST
:
2574 case R_PPC64_TPREL16_HIGHESTA
:
2575 case R_PPC64_TPREL64
:
2576 /* These relocations are relative but in a shared library the
2577 linker doesn't know the thread pointer base. */
2578 return bfd_link_dll (info
);
2582 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2583 copying dynamic variables from a shared lib into an app's dynbss
2584 section, and instead use a dynamic relocation to point into the
2585 shared lib. With code that gcc generates, it's vital that this be
2586 enabled; In the PowerPC64 ABI, the address of a function is actually
2587 the address of a function descriptor, which resides in the .opd
2588 section. gcc uses the descriptor directly rather than going via the
2589 GOT as some other ABI's do, which means that initialized function
2590 pointers must reference the descriptor. Thus, a function pointer
2591 initialized to the address of a function in a shared library will
2592 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2593 redefines the function descriptor symbol to point to the copy. This
2594 presents a problem as a plt entry for that function is also
2595 initialized from the function descriptor symbol and the copy reloc
2596 may not be initialized first. */
2597 #define ELIMINATE_COPY_RELOCS 1
2599 /* Section name for stubs is the associated section name plus this
2601 #define STUB_SUFFIX ".stub"
2604 ppc_stub_long_branch:
2605 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2606 destination, but a 24 bit branch in a stub section will reach.
2609 ppc_stub_plt_branch:
2610 Similar to the above, but a 24 bit branch in the stub section won't
2611 reach its destination.
2612 . addis %r11,%r2,xxx@toc@ha
2613 . ld %r12,xxx@toc@l(%r11)
2618 Used to call a function in a shared library. If it so happens that
2619 the plt entry referenced crosses a 64k boundary, then an extra
2620 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2621 ppc_stub_plt_call_r2save starts with "std %r2,40(%r1)".
2622 . addis %r11,%r2,xxx@toc@ha
2623 . ld %r12,xxx+0@toc@l(%r11)
2625 . ld %r2,xxx+8@toc@l(%r11)
2626 . ld %r11,xxx+16@toc@l(%r11)
2629 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2630 code to adjust the value and save r2 to support multiple toc sections.
2631 A ppc_stub_long_branch with an r2 offset looks like:
2633 . addis %r2,%r2,off@ha
2634 . addi %r2,%r2,off@l
2637 A ppc_stub_plt_branch with an r2 offset looks like:
2639 . addis %r11,%r2,xxx@toc@ha
2640 . ld %r12,xxx@toc@l(%r11)
2641 . addis %r2,%r2,off@ha
2642 . addi %r2,%r2,off@l
2646 All of the above stubs are shown as their ELFv1 variants. ELFv2
2647 variants exist too, simpler for plt calls since a new toc pointer
2648 and static chain are not loaded by the stub. In addition, ELFv2
2649 has some more complex stubs to handle calls marked with NOTOC
2650 relocs from functions where r2 is not a valid toc pointer. These
2651 come in two flavours, the ones shown below, and _both variants that
2652 start with "std %r2,24(%r1)" to save r2 in the unlikely event that
2653 one call is from a function where r2 is used as the toc pointer but
2654 needs a toc adjusting stub for small-model multi-toc, and another
2655 call is from a function where r2 is not valid.
2656 ppc_stub_long_branch_notoc:
2662 . addis %r12,%r11,dest-1b@ha
2663 . addi %r12,%r12,dest-1b@l
2666 ppc_stub_plt_branch_notoc:
2672 . lis %r12,xxx-1b@highest
2673 . ori %r12,%r12,xxx-1b@higher
2675 . oris %r12,%r12,xxx-1b@high
2676 . ori %r12,%r12,xxx-1b@l
2677 . add %r12,%r11,%r12
2681 ppc_stub_plt_call_notoc:
2687 . lis %r12,xxx-1b@highest
2688 . ori %r12,%r12,xxx-1b@higher
2690 . oris %r12,%r12,xxx-1b@high
2691 . ori %r12,%r12,xxx-1b@l
2692 . ldx %r12,%r11,%r12
2696 In cases where the high instructions would add zero, they are
2697 omitted and following instructions modified in some cases.
2699 For a given stub group (a set of sections all using the same toc
2700 pointer value) there will be just one stub type used for any
2701 particular function symbol. For example, if printf is called from
2702 code with the tocsave optimization (ie. r2 saved in function
2703 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2704 and from other code without the tocsave optimization requiring a
2705 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
2706 type will be created. Calls with the tocsave optimization will
2707 enter this stub after the instruction saving r2. A similar
2708 situation exists when calls are marked with R_PPC64_REL24_NOTOC
2709 relocations. These require a ppc_stub_plt_call_notoc linkage stub
2710 to call an external function like printf. If other calls to printf
2711 require a ppc_stub_plt_call linkage stub then a single
2712 ppc_stub_plt_call_notoc linkage stub will be used for both types of
2713 call. If other calls to printf require a ppc_stub_plt_call_r2save
2714 linkage stub then a single ppc_stub_plt_call_both linkage stub will
2715 be created and calls not requiring r2 to be saved will enter the
2716 stub after the r2 save instruction. There is an analogous
2717 hierarchy of long branch and plt branch stubs for local call
2723 ppc_stub_long_branch
,
2724 ppc_stub_long_branch_r2off
,
2725 ppc_stub_long_branch_notoc
,
2726 ppc_stub_long_branch_both
, /* r2off and notoc variants both needed. */
2727 ppc_stub_plt_branch
,
2728 ppc_stub_plt_branch_r2off
,
2729 ppc_stub_plt_branch_notoc
,
2730 ppc_stub_plt_branch_both
,
2732 ppc_stub_plt_call_r2save
,
2733 ppc_stub_plt_call_notoc
,
2734 ppc_stub_plt_call_both
,
2735 ppc_stub_global_entry
,
2739 /* Information on stub grouping. */
2742 /* The stub section. */
2744 /* This is the section to which stubs in the group will be attached. */
2747 struct map_stub
*next
;
2748 /* Whether to emit a copy of register save/restore functions in this
2751 /* Current offset within stubs after the insn restoring lr in a
2752 _notoc or _both stub using bcl for pc-relative addressing, or
2753 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
2754 unsigned int lr_restore
;
2755 /* Accumulated size of EH info emitted to describe return address
2756 if stubs modify lr. Does not include 17 byte FDE header. */
2757 unsigned int eh_size
;
2758 /* Offset in glink_eh_frame to the start of EH info for this group. */
2759 unsigned int eh_base
;
2762 struct ppc_stub_hash_entry
2764 /* Base hash table entry structure. */
2765 struct bfd_hash_entry root
;
2767 enum ppc_stub_type stub_type
;
2769 /* Group information. */
2770 struct map_stub
*group
;
2772 /* Offset within stub_sec of the beginning of this stub. */
2773 bfd_vma stub_offset
;
2775 /* Given the symbol's value and its section we can determine its final
2776 value when building the stubs (so the stub knows where to jump. */
2777 bfd_vma target_value
;
2778 asection
*target_section
;
2780 /* The symbol table entry, if any, that this was derived from. */
2781 struct ppc_link_hash_entry
*h
;
2782 struct plt_entry
*plt_ent
;
2785 unsigned char symtype
;
2787 /* Symbol st_other. */
2788 unsigned char other
;
2791 struct ppc_branch_hash_entry
2793 /* Base hash table entry structure. */
2794 struct bfd_hash_entry root
;
2796 /* Offset within branch lookup table. */
2797 unsigned int offset
;
2799 /* Generation marker. */
2803 /* Used to track dynamic relocations for local symbols. */
2804 struct ppc_dyn_relocs
2806 struct ppc_dyn_relocs
*next
;
2808 /* The input section of the reloc. */
2811 /* Total number of relocs copied for the input section. */
2812 unsigned int count
: 31;
2814 /* Whether this entry is for STT_GNU_IFUNC symbols. */
2815 unsigned int ifunc
: 1;
2818 struct ppc_link_hash_entry
2820 struct elf_link_hash_entry elf
;
2824 /* A pointer to the most recently used stub hash entry against this
2826 struct ppc_stub_hash_entry
*stub_cache
;
2828 /* A pointer to the next symbol starting with a '.' */
2829 struct ppc_link_hash_entry
*next_dot_sym
;
2832 /* Track dynamic relocs copied for this symbol. */
2833 struct elf_dyn_relocs
*dyn_relocs
;
2835 /* Link between function code and descriptor symbols. */
2836 struct ppc_link_hash_entry
*oh
;
2838 /* Flag function code and descriptor symbols. */
2839 unsigned int is_func
:1;
2840 unsigned int is_func_descriptor
:1;
2841 unsigned int fake
:1;
2843 /* Whether global opd/toc sym has been adjusted or not.
2844 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
2845 should be set for all globals defined in any opd/toc section. */
2846 unsigned int adjust_done
:1;
2848 /* Set if this is an out-of-line register save/restore function,
2849 with non-standard calling convention. */
2850 unsigned int save_res
:1;
2852 /* Set if a duplicate symbol with non-zero localentry is detected,
2853 even when the duplicate symbol does not provide a definition. */
2854 unsigned int non_zero_localentry
:1;
2856 /* Contexts in which symbol is used in the GOT (or TOC).
2857 Bits are or'd into the mask as the corresponding relocs are
2858 encountered during check_relocs, with TLS_TLS being set when any
2859 of the other TLS bits are set. tls_optimize clears bits when
2860 optimizing to indicate the corresponding GOT entry type is not
2861 needed. If set, TLS_TLS is never cleared. tls_optimize may also
2862 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
2863 separate flag rather than setting TPREL just for convenience in
2864 distinguishing the two cases.
2865 These flags are also kept for local symbols. */
2866 #define TLS_TLS 1 /* Any TLS reloc. */
2867 #define TLS_GD 2 /* GD reloc. */
2868 #define TLS_LD 4 /* LD reloc. */
2869 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
2870 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
2871 #define TLS_MARK 32 /* __tls_get_addr call marked. */
2872 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2873 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
2874 unsigned char tls_mask
;
2876 /* The above field is also used to mark function symbols. In which
2877 case TLS_TLS will be 0. */
2878 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
2879 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
2880 #define NON_GOT 256 /* local symbol plt, not stored. */
2883 /* ppc64 ELF linker hash table. */
2885 struct ppc_link_hash_table
2887 struct elf_link_hash_table elf
;
2889 /* The stub hash table. */
2890 struct bfd_hash_table stub_hash_table
;
2892 /* Another hash table for plt_branch stubs. */
2893 struct bfd_hash_table branch_hash_table
;
2895 /* Hash table for function prologue tocsave. */
2896 htab_t tocsave_htab
;
2898 /* Various options and other info passed from the linker. */
2899 struct ppc64_elf_params
*params
;
2901 /* The size of sec_info below. */
2902 unsigned int sec_info_arr_size
;
2904 /* Per-section array of extra section info. Done this way rather
2905 than as part of ppc64_elf_section_data so we have the info for
2906 non-ppc64 sections. */
2909 /* Along with elf_gp, specifies the TOC pointer used by this section. */
2914 /* The section group that this section belongs to. */
2915 struct map_stub
*group
;
2916 /* A temp section list pointer. */
2921 /* Linked list of groups. */
2922 struct map_stub
*group
;
2924 /* Temp used when calculating TOC pointers. */
2927 asection
*toc_first_sec
;
2929 /* Used when adding symbols. */
2930 struct ppc_link_hash_entry
*dot_syms
;
2932 /* Shortcuts to get to dynamic linker sections. */
2934 asection
*global_entry
;
2937 asection
*relpltlocal
;
2940 asection
*glink_eh_frame
;
2942 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
2943 struct ppc_link_hash_entry
*tls_get_addr
;
2944 struct ppc_link_hash_entry
*tls_get_addr_fd
;
2946 /* The size of reliplt used by got entry relocs. */
2947 bfd_size_type got_reli_size
;
2950 unsigned long stub_count
[ppc_stub_global_entry
];
2952 /* Number of stubs against global syms. */
2953 unsigned long stub_globals
;
2955 /* Set if we're linking code with function descriptors. */
2956 unsigned int opd_abi
:1;
2958 /* Support for multiple toc sections. */
2959 unsigned int do_multi_toc
:1;
2960 unsigned int multi_toc_needed
:1;
2961 unsigned int second_toc_pass
:1;
2962 unsigned int do_toc_opt
:1;
2964 /* Set if tls optimization is enabled. */
2965 unsigned int do_tls_opt
:1;
2967 /* Set if inline plt calls should be converted to direct calls. */
2968 unsigned int can_convert_all_inline_plt
:1;
2971 unsigned int stub_error
:1;
2973 /* Whether func_desc_adjust needs to be run over symbols. */
2974 unsigned int need_func_desc_adj
:1;
2976 /* Whether there exist local gnu indirect function resolvers,
2977 referenced by dynamic relocations. */
2978 unsigned int local_ifunc_resolver
:1;
2979 unsigned int maybe_local_ifunc_resolver
:1;
2981 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
2982 unsigned int has_plt_localentry0
:1;
2984 /* Incremented every time we size stubs. */
2985 unsigned int stub_iteration
;
2987 /* Small local sym cache. */
2988 struct sym_cache sym_cache
;
2991 /* Rename some of the generic section flags to better document how they
2994 /* Nonzero if this section has TLS related relocations. */
2995 #define has_tls_reloc sec_flg0
2997 /* Nonzero if this section has an old-style call to __tls_get_addr. */
2998 #define has_tls_get_addr_call sec_flg1
3000 /* Nonzero if this section has any toc or got relocs. */
3001 #define has_toc_reloc sec_flg2
3003 /* Nonzero if this section has a call to another section that uses
3005 #define makes_toc_func_call sec_flg3
3007 /* Recursion protection when determining above flag. */
3008 #define call_check_in_progress sec_flg4
3009 #define call_check_done sec_flg5
3011 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3013 #define ppc_hash_table(p) \
3014 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3015 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3017 #define ppc_stub_hash_lookup(table, string, create, copy) \
3018 ((struct ppc_stub_hash_entry *) \
3019 bfd_hash_lookup ((table), (string), (create), (copy)))
3021 #define ppc_branch_hash_lookup(table, string, create, copy) \
3022 ((struct ppc_branch_hash_entry *) \
3023 bfd_hash_lookup ((table), (string), (create), (copy)))
3025 /* Create an entry in the stub hash table. */
3027 static struct bfd_hash_entry
*
3028 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3029 struct bfd_hash_table
*table
,
3032 /* Allocate the structure if it has not already been allocated by a
3036 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3041 /* Call the allocation method of the superclass. */
3042 entry
= bfd_hash_newfunc (entry
, table
, string
);
3045 struct ppc_stub_hash_entry
*eh
;
3047 /* Initialize the local fields. */
3048 eh
= (struct ppc_stub_hash_entry
*) entry
;
3049 eh
->stub_type
= ppc_stub_none
;
3051 eh
->stub_offset
= 0;
3052 eh
->target_value
= 0;
3053 eh
->target_section
= NULL
;
3062 /* Create an entry in the branch hash table. */
3064 static struct bfd_hash_entry
*
3065 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3066 struct bfd_hash_table
*table
,
3069 /* Allocate the structure if it has not already been allocated by a
3073 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3078 /* Call the allocation method of the superclass. */
3079 entry
= bfd_hash_newfunc (entry
, table
, string
);
3082 struct ppc_branch_hash_entry
*eh
;
3084 /* Initialize the local fields. */
3085 eh
= (struct ppc_branch_hash_entry
*) entry
;
3093 /* Create an entry in a ppc64 ELF linker hash table. */
3095 static struct bfd_hash_entry
*
3096 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3097 struct bfd_hash_table
*table
,
3100 /* Allocate the structure if it has not already been allocated by a
3104 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3109 /* Call the allocation method of the superclass. */
3110 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3113 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3115 memset (&eh
->u
.stub_cache
, 0,
3116 (sizeof (struct ppc_link_hash_entry
)
3117 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3119 /* When making function calls, old ABI code references function entry
3120 points (dot symbols), while new ABI code references the function
3121 descriptor symbol. We need to make any combination of reference and
3122 definition work together, without breaking archive linking.
3124 For a defined function "foo" and an undefined call to "bar":
3125 An old object defines "foo" and ".foo", references ".bar" (possibly
3127 A new object defines "foo" and references "bar".
3129 A new object thus has no problem with its undefined symbols being
3130 satisfied by definitions in an old object. On the other hand, the
3131 old object won't have ".bar" satisfied by a new object.
3133 Keep a list of newly added dot-symbols. */
3135 if (string
[0] == '.')
3137 struct ppc_link_hash_table
*htab
;
3139 htab
= (struct ppc_link_hash_table
*) table
;
3140 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3141 htab
->dot_syms
= eh
;
3148 struct tocsave_entry
3155 tocsave_htab_hash (const void *p
)
3157 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3158 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3162 tocsave_htab_eq (const void *p1
, const void *p2
)
3164 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3165 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3166 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3169 /* Destroy a ppc64 ELF linker hash table. */
3172 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3174 struct ppc_link_hash_table
*htab
;
3176 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3177 if (htab
->tocsave_htab
)
3178 htab_delete (htab
->tocsave_htab
);
3179 bfd_hash_table_free (&htab
->branch_hash_table
);
3180 bfd_hash_table_free (&htab
->stub_hash_table
);
3181 _bfd_elf_link_hash_table_free (obfd
);
3184 /* Create a ppc64 ELF linker hash table. */
3186 static struct bfd_link_hash_table
*
3187 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3189 struct ppc_link_hash_table
*htab
;
3190 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3192 htab
= bfd_zmalloc (amt
);
3196 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3197 sizeof (struct ppc_link_hash_entry
),
3204 /* Init the stub hash table too. */
3205 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3206 sizeof (struct ppc_stub_hash_entry
)))
3208 _bfd_elf_link_hash_table_free (abfd
);
3212 /* And the branch hash table. */
3213 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3214 sizeof (struct ppc_branch_hash_entry
)))
3216 bfd_hash_table_free (&htab
->stub_hash_table
);
3217 _bfd_elf_link_hash_table_free (abfd
);
3221 htab
->tocsave_htab
= htab_try_create (1024,
3225 if (htab
->tocsave_htab
== NULL
)
3227 ppc64_elf_link_hash_table_free (abfd
);
3230 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3232 /* Initializing two fields of the union is just cosmetic. We really
3233 only care about glist, but when compiled on a 32-bit host the
3234 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3235 debugger inspection of these fields look nicer. */
3236 htab
->elf
.init_got_refcount
.refcount
= 0;
3237 htab
->elf
.init_got_refcount
.glist
= NULL
;
3238 htab
->elf
.init_plt_refcount
.refcount
= 0;
3239 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3240 htab
->elf
.init_got_offset
.offset
= 0;
3241 htab
->elf
.init_got_offset
.glist
= NULL
;
3242 htab
->elf
.init_plt_offset
.offset
= 0;
3243 htab
->elf
.init_plt_offset
.glist
= NULL
;
3245 return &htab
->elf
.root
;
3248 /* Create sections for linker generated code. */
3251 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3253 struct ppc_link_hash_table
*htab
;
3256 htab
= ppc_hash_table (info
);
3258 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3259 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3260 if (htab
->params
->save_restore_funcs
)
3262 /* Create .sfpr for code to save and restore fp regs. */
3263 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3265 if (htab
->sfpr
== NULL
3266 || !bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3270 if (bfd_link_relocatable (info
))
3273 /* Create .glink for lazy dynamic linking support. */
3274 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3276 if (htab
->glink
== NULL
3277 || !bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
3280 /* The part of .glink used by global entry stubs, separate so that
3281 it can be aligned appropriately without affecting htab->glink. */
3282 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3284 if (htab
->global_entry
== NULL
3285 || !bfd_set_section_alignment (dynobj
, htab
->global_entry
, 2))
3288 if (!info
->no_ld_generated_unwind_info
)
3290 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3291 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3292 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3295 if (htab
->glink_eh_frame
== NULL
3296 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
3300 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3301 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3302 if (htab
->elf
.iplt
== NULL
3303 || !bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
3306 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3307 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3309 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3310 if (htab
->elf
.irelplt
== NULL
3311 || !bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
3314 /* Create branch lookup table for plt_branch stubs. */
3315 flags
= (SEC_ALLOC
| SEC_LOAD
3316 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3317 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3319 if (htab
->brlt
== NULL
3320 || !bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3323 /* Local plt entries, put in .branch_lt but a separate section for
3325 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3327 if (htab
->pltlocal
== NULL
3328 || !bfd_set_section_alignment (dynobj
, htab
->pltlocal
, 3))
3331 if (!bfd_link_pic (info
))
3334 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3335 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3337 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3338 if (htab
->relbrlt
== NULL
3339 || !bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3343 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3344 if (htab
->relpltlocal
== NULL
3345 || !bfd_set_section_alignment (dynobj
, htab
->relpltlocal
, 3))
3351 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3354 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3355 struct ppc64_elf_params
*params
)
3357 struct ppc_link_hash_table
*htab
;
3359 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3361 /* Always hook our dynamic sections into the first bfd, which is the
3362 linker created stub bfd. This ensures that the GOT header is at
3363 the start of the output TOC section. */
3364 htab
= ppc_hash_table (info
);
3365 htab
->elf
.dynobj
= params
->stub_bfd
;
3366 htab
->params
= params
;
3368 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3371 /* Build a name for an entry in the stub hash table. */
3374 ppc_stub_name (const asection
*input_section
,
3375 const asection
*sym_sec
,
3376 const struct ppc_link_hash_entry
*h
,
3377 const Elf_Internal_Rela
*rel
)
3382 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3383 offsets from a sym as a branch target? In fact, we could
3384 probably assume the addend is always zero. */
3385 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3389 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3390 stub_name
= bfd_malloc (len
);
3391 if (stub_name
== NULL
)
3394 len
= sprintf (stub_name
, "%08x.%s+%x",
3395 input_section
->id
& 0xffffffff,
3396 h
->elf
.root
.root
.string
,
3397 (int) rel
->r_addend
& 0xffffffff);
3401 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3402 stub_name
= bfd_malloc (len
);
3403 if (stub_name
== NULL
)
3406 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3407 input_section
->id
& 0xffffffff,
3408 sym_sec
->id
& 0xffffffff,
3409 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3410 (int) rel
->r_addend
& 0xffffffff);
3412 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3413 stub_name
[len
- 2] = 0;
3417 /* Look up an entry in the stub hash. Stub entries are cached because
3418 creating the stub name takes a bit of time. */
3420 static struct ppc_stub_hash_entry
*
3421 ppc_get_stub_entry (const asection
*input_section
,
3422 const asection
*sym_sec
,
3423 struct ppc_link_hash_entry
*h
,
3424 const Elf_Internal_Rela
*rel
,
3425 struct ppc_link_hash_table
*htab
)
3427 struct ppc_stub_hash_entry
*stub_entry
;
3428 struct map_stub
*group
;
3430 /* If this input section is part of a group of sections sharing one
3431 stub section, then use the id of the first section in the group.
3432 Stub names need to include a section id, as there may well be
3433 more than one stub used to reach say, printf, and we need to
3434 distinguish between them. */
3435 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3439 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3440 && h
->u
.stub_cache
->h
== h
3441 && h
->u
.stub_cache
->group
== group
)
3443 stub_entry
= h
->u
.stub_cache
;
3449 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3450 if (stub_name
== NULL
)
3453 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3454 stub_name
, FALSE
, FALSE
);
3456 h
->u
.stub_cache
= stub_entry
;
3464 /* Add a new stub entry to the stub hash. Not all fields of the new
3465 stub entry are initialised. */
3467 static struct ppc_stub_hash_entry
*
3468 ppc_add_stub (const char *stub_name
,
3470 struct bfd_link_info
*info
)
3472 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3473 struct map_stub
*group
;
3476 struct ppc_stub_hash_entry
*stub_entry
;
3478 group
= htab
->sec_info
[section
->id
].u
.group
;
3479 link_sec
= group
->link_sec
;
3480 stub_sec
= group
->stub_sec
;
3481 if (stub_sec
== NULL
)
3487 namelen
= strlen (link_sec
->name
);
3488 len
= namelen
+ sizeof (STUB_SUFFIX
);
3489 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3493 memcpy (s_name
, link_sec
->name
, namelen
);
3494 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3495 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3496 if (stub_sec
== NULL
)
3498 group
->stub_sec
= stub_sec
;
3501 /* Enter this entry into the linker stub hash table. */
3502 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3504 if (stub_entry
== NULL
)
3506 /* xgettext:c-format */
3507 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3508 section
->owner
, stub_name
);
3512 stub_entry
->group
= group
;
3513 stub_entry
->stub_offset
= 0;
3517 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3518 not already done. */
3521 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3523 asection
*got
, *relgot
;
3525 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3527 if (!is_ppc64_elf (abfd
))
3533 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3536 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3537 | SEC_LINKER_CREATED
);
3539 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3541 || !bfd_set_section_alignment (abfd
, got
, 3))
3544 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3545 flags
| SEC_READONLY
);
3547 || !bfd_set_section_alignment (abfd
, relgot
, 3))
3550 ppc64_elf_tdata (abfd
)->got
= got
;
3551 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3555 /* Follow indirect and warning symbol links. */
3557 static inline struct bfd_link_hash_entry
*
3558 follow_link (struct bfd_link_hash_entry
*h
)
3560 while (h
->type
== bfd_link_hash_indirect
3561 || h
->type
== bfd_link_hash_warning
)
3566 static inline struct elf_link_hash_entry
*
3567 elf_follow_link (struct elf_link_hash_entry
*h
)
3569 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
3572 static inline struct ppc_link_hash_entry
*
3573 ppc_follow_link (struct ppc_link_hash_entry
*h
)
3575 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
3578 /* Merge PLT info on FROM with that on TO. */
3581 move_plt_plist (struct ppc_link_hash_entry
*from
,
3582 struct ppc_link_hash_entry
*to
)
3584 if (from
->elf
.plt
.plist
!= NULL
)
3586 if (to
->elf
.plt
.plist
!= NULL
)
3588 struct plt_entry
**entp
;
3589 struct plt_entry
*ent
;
3591 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3593 struct plt_entry
*dent
;
3595 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3596 if (dent
->addend
== ent
->addend
)
3598 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3605 *entp
= to
->elf
.plt
.plist
;
3608 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3609 from
->elf
.plt
.plist
= NULL
;
3613 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3616 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3617 struct elf_link_hash_entry
*dir
,
3618 struct elf_link_hash_entry
*ind
)
3620 struct ppc_link_hash_entry
*edir
, *eind
;
3622 edir
= (struct ppc_link_hash_entry
*) dir
;
3623 eind
= (struct ppc_link_hash_entry
*) ind
;
3625 edir
->is_func
|= eind
->is_func
;
3626 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3627 edir
->tls_mask
|= eind
->tls_mask
;
3628 if (eind
->oh
!= NULL
)
3629 edir
->oh
= ppc_follow_link (eind
->oh
);
3631 if (edir
->elf
.versioned
!= versioned_hidden
)
3632 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3633 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3634 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3635 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3636 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3637 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3639 /* If we were called to copy over info for a weak sym, don't copy
3640 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
3641 in order to simplify readonly_dynrelocs and save a field in the
3642 symbol hash entry, but that means dyn_relocs can't be used in any
3643 tests about a specific symbol, or affect other symbol flags which
3645 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3648 /* Copy over any dynamic relocs we may have on the indirect sym. */
3649 if (eind
->dyn_relocs
!= NULL
)
3651 if (edir
->dyn_relocs
!= NULL
)
3653 struct elf_dyn_relocs
**pp
;
3654 struct elf_dyn_relocs
*p
;
3656 /* Add reloc counts against the indirect sym to the direct sym
3657 list. Merge any entries against the same section. */
3658 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3660 struct elf_dyn_relocs
*q
;
3662 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3663 if (q
->sec
== p
->sec
)
3665 q
->pc_count
+= p
->pc_count
;
3666 q
->count
+= p
->count
;
3673 *pp
= edir
->dyn_relocs
;
3676 edir
->dyn_relocs
= eind
->dyn_relocs
;
3677 eind
->dyn_relocs
= NULL
;
3680 /* Copy over got entries that we may have already seen to the
3681 symbol which just became indirect. */
3682 if (eind
->elf
.got
.glist
!= NULL
)
3684 if (edir
->elf
.got
.glist
!= NULL
)
3686 struct got_entry
**entp
;
3687 struct got_entry
*ent
;
3689 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3691 struct got_entry
*dent
;
3693 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3694 if (dent
->addend
== ent
->addend
3695 && dent
->owner
== ent
->owner
3696 && dent
->tls_type
== ent
->tls_type
)
3698 dent
->got
.refcount
+= ent
->got
.refcount
;
3705 *entp
= edir
->elf
.got
.glist
;
3708 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3709 eind
->elf
.got
.glist
= NULL
;
3712 /* And plt entries. */
3713 move_plt_plist (eind
, edir
);
3715 if (eind
->elf
.dynindx
!= -1)
3717 if (edir
->elf
.dynindx
!= -1)
3718 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3719 edir
->elf
.dynstr_index
);
3720 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3721 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3722 eind
->elf
.dynindx
= -1;
3723 eind
->elf
.dynstr_index
= 0;
3727 /* Find the function descriptor hash entry from the given function code
3728 hash entry FH. Link the entries via their OH fields. */
3730 static struct ppc_link_hash_entry
*
3731 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
3733 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
3737 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
3739 fdh
= (struct ppc_link_hash_entry
*)
3740 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
3744 fdh
->is_func_descriptor
= 1;
3750 fdh
= ppc_follow_link (fdh
);
3751 fdh
->is_func_descriptor
= 1;
3756 /* Make a fake function descriptor sym for the undefined code sym FH. */
3758 static struct ppc_link_hash_entry
*
3759 make_fdh (struct bfd_link_info
*info
,
3760 struct ppc_link_hash_entry
*fh
)
3762 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
3763 struct bfd_link_hash_entry
*bh
= NULL
;
3764 struct ppc_link_hash_entry
*fdh
;
3765 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
3769 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
3770 fh
->elf
.root
.root
.string
+ 1,
3771 flags
, bfd_und_section_ptr
, 0,
3772 NULL
, FALSE
, FALSE
, &bh
))
3775 fdh
= (struct ppc_link_hash_entry
*) bh
;
3776 fdh
->elf
.non_elf
= 0;
3778 fdh
->is_func_descriptor
= 1;
3785 /* Fix function descriptor symbols defined in .opd sections to be
3789 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
3790 struct bfd_link_info
*info
,
3791 Elf_Internal_Sym
*isym
,
3793 flagword
*flags ATTRIBUTE_UNUSED
,
3798 && strcmp ((*sec
)->name
, ".opd") == 0)
3802 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
3803 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
3804 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
3806 /* If the symbol is a function defined in .opd, and the function
3807 code is in a discarded group, let it appear to be undefined. */
3808 if (!bfd_link_relocatable (info
)
3809 && (*sec
)->reloc_count
!= 0
3810 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
3811 FALSE
) != (bfd_vma
) -1
3812 && discarded_section (code_sec
))
3814 *sec
= bfd_und_section_ptr
;
3815 isym
->st_shndx
= SHN_UNDEF
;
3818 else if (*sec
!= NULL
3819 && strcmp ((*sec
)->name
, ".toc") == 0
3820 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
3822 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3824 htab
->params
->object_in_toc
= 1;
3827 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
3829 if (abiversion (ibfd
) == 0)
3830 set_abiversion (ibfd
, 2);
3831 else if (abiversion (ibfd
) == 1)
3833 _bfd_error_handler (_("symbol '%s' has invalid st_other"
3834 " for ABI version 1"), *name
);
3835 bfd_set_error (bfd_error_bad_value
);
3843 /* Merge non-visibility st_other attributes: local entry point. */
3846 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
3847 const Elf_Internal_Sym
*isym
,
3848 bfd_boolean definition
,
3849 bfd_boolean dynamic
)
3851 if (definition
&& (!dynamic
|| !h
->def_regular
))
3852 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
3853 | ELF_ST_VISIBILITY (h
->other
));
3856 /* Hook called on merging a symbol. We use this to clear "fake" since
3857 we now have a real symbol. */
3860 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
3861 const Elf_Internal_Sym
*isym
,
3862 asection
**psec ATTRIBUTE_UNUSED
,
3863 bfd_boolean newdef ATTRIBUTE_UNUSED
,
3864 bfd_boolean olddef ATTRIBUTE_UNUSED
,
3865 bfd
*oldbfd ATTRIBUTE_UNUSED
,
3866 const asection
*oldsec ATTRIBUTE_UNUSED
)
3868 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
3869 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
3870 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
3874 /* This function makes an old ABI object reference to ".bar" cause the
3875 inclusion of a new ABI object archive that defines "bar".
3876 NAME is a symbol defined in an archive. Return a symbol in the hash
3877 table that might be satisfied by the archive symbols. */
3879 static struct elf_link_hash_entry
*
3880 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
3881 struct bfd_link_info
*info
,
3884 struct elf_link_hash_entry
*h
;
3888 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
3890 /* Don't return this sym if it is a fake function descriptor
3891 created by add_symbol_adjust. */
3892 && !((struct ppc_link_hash_entry
*) h
)->fake
)
3898 len
= strlen (name
);
3899 dot_name
= bfd_alloc (abfd
, len
+ 2);
3900 if (dot_name
== NULL
)
3901 return (struct elf_link_hash_entry
*) -1;
3903 memcpy (dot_name
+ 1, name
, len
+ 1);
3904 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
3905 bfd_release (abfd
, dot_name
);
3909 /* This function satisfies all old ABI object references to ".bar" if a
3910 new ABI object defines "bar". Well, at least, undefined dot symbols
3911 are made weak. This stops later archive searches from including an
3912 object if we already have a function descriptor definition. It also
3913 prevents the linker complaining about undefined symbols.
3914 We also check and correct mismatched symbol visibility here. The
3915 most restrictive visibility of the function descriptor and the
3916 function entry symbol is used. */
3919 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
3921 struct ppc_link_hash_table
*htab
;
3922 struct ppc_link_hash_entry
*fdh
;
3924 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
3925 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
3927 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
3930 if (eh
->elf
.root
.root
.string
[0] != '.')
3933 htab
= ppc_hash_table (info
);
3937 fdh
= lookup_fdh (eh
, htab
);
3939 && !bfd_link_relocatable (info
)
3940 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
3941 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
3942 && eh
->elf
.ref_regular
)
3944 /* Make an undefined function descriptor sym, in order to
3945 pull in an --as-needed shared lib. Archives are handled
3947 fdh
= make_fdh (info
, eh
);
3954 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
3955 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
3957 /* Make both descriptor and entry symbol have the most
3958 constraining visibility of either symbol. */
3959 if (entry_vis
< descr_vis
)
3960 fdh
->elf
.other
+= entry_vis
- descr_vis
;
3961 else if (entry_vis
> descr_vis
)
3962 eh
->elf
.other
+= descr_vis
- entry_vis
;
3964 /* Propagate reference flags from entry symbol to function
3965 descriptor symbol. */
3966 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
3967 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
3968 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
3969 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
3971 if (!fdh
->elf
.forced_local
3972 && fdh
->elf
.dynindx
== -1
3973 && fdh
->elf
.versioned
!= versioned_hidden
3974 && (bfd_link_dll (info
)
3975 || fdh
->elf
.def_dynamic
3976 || fdh
->elf
.ref_dynamic
)
3977 && (eh
->elf
.ref_regular
3978 || eh
->elf
.def_regular
))
3980 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
3988 /* Set up opd section info and abiversion for IBFD, and process list
3989 of dot-symbols we made in link_hash_newfunc. */
3992 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
3994 struct ppc_link_hash_table
*htab
;
3995 struct ppc_link_hash_entry
**p
, *eh
;
3996 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
3998 if (opd
!= NULL
&& opd
->size
!= 0)
4000 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
4001 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
4003 if (abiversion (ibfd
) == 0)
4004 set_abiversion (ibfd
, 1);
4005 else if (abiversion (ibfd
) >= 2)
4007 /* xgettext:c-format */
4008 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4009 ibfd
, abiversion (ibfd
));
4010 bfd_set_error (bfd_error_bad_value
);
4015 if (is_ppc64_elf (info
->output_bfd
))
4017 /* For input files without an explicit abiversion in e_flags
4018 we should have flagged any with symbol st_other bits set
4019 as ELFv1 and above flagged those with .opd as ELFv2.
4020 Set the output abiversion if not yet set, and for any input
4021 still ambiguous, take its abiversion from the output.
4022 Differences in ABI are reported later. */
4023 if (abiversion (info
->output_bfd
) == 0)
4024 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4025 else if (abiversion (ibfd
) == 0)
4026 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4029 htab
= ppc_hash_table (info
);
4033 if (opd
!= NULL
&& opd
->size
!= 0
4034 && (ibfd
->flags
& DYNAMIC
) == 0
4035 && (opd
->flags
& SEC_RELOC
) != 0
4036 && opd
->reloc_count
!= 0
4037 && !bfd_is_abs_section (opd
->output_section
)
4038 && info
->gc_sections
)
4040 /* Garbage collection needs some extra help with .opd sections.
4041 We don't want to necessarily keep everything referenced by
4042 relocs in .opd, as that would keep all functions. Instead,
4043 if we reference an .opd symbol (a function descriptor), we
4044 want to keep the function code symbol's section. This is
4045 easy for global symbols, but for local syms we need to keep
4046 information about the associated function section. */
4048 asection
**opd_sym_map
;
4049 Elf_Internal_Shdr
*symtab_hdr
;
4050 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4052 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4053 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4054 if (opd_sym_map
== NULL
)
4056 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4057 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4061 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4062 rel_end
= relocs
+ opd
->reloc_count
- 1;
4063 for (rel
= relocs
; rel
< rel_end
; rel
++)
4065 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4066 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4068 if (r_type
== R_PPC64_ADDR64
4069 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4070 && r_symndx
< symtab_hdr
->sh_info
)
4072 Elf_Internal_Sym
*isym
;
4075 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
4078 if (elf_section_data (opd
)->relocs
!= relocs
)
4083 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4084 if (s
!= NULL
&& s
!= opd
)
4085 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4088 if (elf_section_data (opd
)->relocs
!= relocs
)
4092 p
= &htab
->dot_syms
;
4093 while ((eh
= *p
) != NULL
)
4096 if (&eh
->elf
== htab
->elf
.hgot
)
4098 else if (htab
->elf
.hgot
== NULL
4099 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4100 htab
->elf
.hgot
= &eh
->elf
;
4101 else if (abiversion (ibfd
) <= 1)
4103 htab
->need_func_desc_adj
= 1;
4104 if (!add_symbol_adjust (eh
, info
))
4107 p
= &eh
->u
.next_dot_sym
;
4112 /* Undo hash table changes when an --as-needed input file is determined
4113 not to be needed. */
4116 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4117 struct bfd_link_info
*info
,
4118 enum notice_asneeded_action act
)
4120 if (act
== notice_not_needed
)
4122 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4127 htab
->dot_syms
= NULL
;
4129 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4132 /* If --just-symbols against a final linked binary, then assume we need
4133 toc adjusting stubs when calling functions defined there. */
4136 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4138 if ((sec
->flags
& SEC_CODE
) != 0
4139 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4140 && is_ppc64_elf (sec
->owner
))
4142 if (abiversion (sec
->owner
) >= 2
4143 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4144 sec
->has_toc_reloc
= 1;
4146 _bfd_elf_link_just_syms (sec
, info
);
4149 static struct plt_entry
**
4150 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4151 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4153 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4154 struct plt_entry
**local_plt
;
4155 unsigned char *local_got_tls_masks
;
4157 if (local_got_ents
== NULL
)
4159 bfd_size_type size
= symtab_hdr
->sh_info
;
4161 size
*= (sizeof (*local_got_ents
)
4162 + sizeof (*local_plt
)
4163 + sizeof (*local_got_tls_masks
));
4164 local_got_ents
= bfd_zalloc (abfd
, size
);
4165 if (local_got_ents
== NULL
)
4167 elf_local_got_ents (abfd
) = local_got_ents
;
4170 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4172 struct got_entry
*ent
;
4174 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4175 if (ent
->addend
== r_addend
4176 && ent
->owner
== abfd
4177 && ent
->tls_type
== tls_type
)
4181 bfd_size_type amt
= sizeof (*ent
);
4182 ent
= bfd_alloc (abfd
, amt
);
4185 ent
->next
= local_got_ents
[r_symndx
];
4186 ent
->addend
= r_addend
;
4188 ent
->tls_type
= tls_type
;
4189 ent
->is_indirect
= FALSE
;
4190 ent
->got
.refcount
= 0;
4191 local_got_ents
[r_symndx
] = ent
;
4193 ent
->got
.refcount
+= 1;
4196 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4197 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4198 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4200 return local_plt
+ r_symndx
;
4204 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4206 struct plt_entry
*ent
;
4208 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4209 if (ent
->addend
== addend
)
4213 bfd_size_type amt
= sizeof (*ent
);
4214 ent
= bfd_alloc (abfd
, amt
);
4218 ent
->addend
= addend
;
4219 ent
->plt
.refcount
= 0;
4222 ent
->plt
.refcount
+= 1;
4227 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4229 return (r_type
== R_PPC64_REL24
4230 || r_type
== R_PPC64_REL24_NOTOC
4231 || r_type
== R_PPC64_REL14
4232 || r_type
== R_PPC64_REL14_BRTAKEN
4233 || r_type
== R_PPC64_REL14_BRNTAKEN
4234 || r_type
== R_PPC64_ADDR24
4235 || r_type
== R_PPC64_ADDR14
4236 || r_type
== R_PPC64_ADDR14_BRTAKEN
4237 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4238 || r_type
== R_PPC64_PLTCALL
);
4241 /* Relocs on inline plt call sequence insns prior to the call. */
4244 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4246 return (r_type
== R_PPC64_PLT16_HA
4247 || r_type
== R_PPC64_PLT16_HI
4248 || r_type
== R_PPC64_PLT16_LO
4249 || r_type
== R_PPC64_PLT16_LO_DS
4250 || r_type
== R_PPC64_PLTSEQ
);
4253 /* Look through the relocs for a section during the first phase, and
4254 calculate needed space in the global offset table, procedure
4255 linkage table, and dynamic reloc sections. */
4258 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4259 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4261 struct ppc_link_hash_table
*htab
;
4262 Elf_Internal_Shdr
*symtab_hdr
;
4263 struct elf_link_hash_entry
**sym_hashes
;
4264 const Elf_Internal_Rela
*rel
;
4265 const Elf_Internal_Rela
*rel_end
;
4267 struct elf_link_hash_entry
*tga
, *dottga
;
4270 if (bfd_link_relocatable (info
))
4273 /* Don't do anything special with non-loaded, non-alloced sections.
4274 In particular, any relocs in such sections should not affect GOT
4275 and PLT reference counting (ie. we don't allow them to create GOT
4276 or PLT entries), there's no possibility or desire to optimize TLS
4277 relocs, and there's not much point in propagating relocs to shared
4278 libs that the dynamic linker won't relocate. */
4279 if ((sec
->flags
& SEC_ALLOC
) == 0)
4282 BFD_ASSERT (is_ppc64_elf (abfd
));
4284 htab
= ppc_hash_table (info
);
4288 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4289 FALSE
, FALSE
, TRUE
);
4290 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4291 FALSE
, FALSE
, TRUE
);
4292 symtab_hdr
= &elf_symtab_hdr (abfd
);
4293 sym_hashes
= elf_sym_hashes (abfd
);
4295 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4296 rel_end
= relocs
+ sec
->reloc_count
;
4297 for (rel
= relocs
; rel
< rel_end
; rel
++)
4299 unsigned long r_symndx
;
4300 struct elf_link_hash_entry
*h
;
4301 enum elf_ppc64_reloc_type r_type
;
4303 struct _ppc64_elf_section_data
*ppc64_sec
;
4304 struct plt_entry
**ifunc
, **plt_list
;
4306 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4307 if (r_symndx
< symtab_hdr
->sh_info
)
4311 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4312 h
= elf_follow_link (h
);
4314 if (h
== htab
->elf
.hgot
)
4315 sec
->has_toc_reloc
= 1;
4322 if (h
->type
== STT_GNU_IFUNC
)
4325 ifunc
= &h
->plt
.plist
;
4330 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4335 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4337 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4339 NON_GOT
| PLT_IFUNC
);
4345 r_type
= ELF64_R_TYPE (rel
->r_info
);
4350 /* These special tls relocs tie a call to __tls_get_addr with
4351 its parameter symbol. */
4353 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4355 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4357 NON_GOT
| TLS_TLS
| TLS_MARK
))
4359 sec
->has_tls_reloc
= 1;
4362 case R_PPC64_GOT_TLSLD16
:
4363 case R_PPC64_GOT_TLSLD16_LO
:
4364 case R_PPC64_GOT_TLSLD16_HI
:
4365 case R_PPC64_GOT_TLSLD16_HA
:
4366 tls_type
= TLS_TLS
| TLS_LD
;
4369 case R_PPC64_GOT_TLSGD16
:
4370 case R_PPC64_GOT_TLSGD16_LO
:
4371 case R_PPC64_GOT_TLSGD16_HI
:
4372 case R_PPC64_GOT_TLSGD16_HA
:
4373 tls_type
= TLS_TLS
| TLS_GD
;
4376 case R_PPC64_GOT_TPREL16_DS
:
4377 case R_PPC64_GOT_TPREL16_LO_DS
:
4378 case R_PPC64_GOT_TPREL16_HI
:
4379 case R_PPC64_GOT_TPREL16_HA
:
4380 if (bfd_link_dll (info
))
4381 info
->flags
|= DF_STATIC_TLS
;
4382 tls_type
= TLS_TLS
| TLS_TPREL
;
4385 case R_PPC64_GOT_DTPREL16_DS
:
4386 case R_PPC64_GOT_DTPREL16_LO_DS
:
4387 case R_PPC64_GOT_DTPREL16_HI
:
4388 case R_PPC64_GOT_DTPREL16_HA
:
4389 tls_type
= TLS_TLS
| TLS_DTPREL
;
4391 sec
->has_tls_reloc
= 1;
4394 case R_PPC64_GOT16_DS
:
4395 case R_PPC64_GOT16_HA
:
4396 case R_PPC64_GOT16_LO_DS
:
4397 ppc64_elf_tdata (abfd
)->has_gotrel
= 1;
4398 ppc64_elf_section_data (sec
)->has_gotrel
= 1;
4402 case R_PPC64_GOT16_HI
:
4403 case R_PPC64_GOT16_LO
:
4405 /* This symbol requires a global offset table entry. */
4406 sec
->has_toc_reloc
= 1;
4407 if (r_type
== R_PPC64_GOT_TLSLD16
4408 || r_type
== R_PPC64_GOT_TLSGD16
4409 || r_type
== R_PPC64_GOT_TPREL16_DS
4410 || r_type
== R_PPC64_GOT_DTPREL16_DS
4411 || r_type
== R_PPC64_GOT16
4412 || r_type
== R_PPC64_GOT16_DS
)
4414 htab
->do_multi_toc
= 1;
4415 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4418 if (ppc64_elf_tdata (abfd
)->got
== NULL
4419 && !create_got_section (abfd
, info
))
4424 struct ppc_link_hash_entry
*eh
;
4425 struct got_entry
*ent
;
4427 eh
= (struct ppc_link_hash_entry
*) h
;
4428 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4429 if (ent
->addend
== rel
->r_addend
4430 && ent
->owner
== abfd
4431 && ent
->tls_type
== tls_type
)
4435 bfd_size_type amt
= sizeof (*ent
);
4436 ent
= bfd_alloc (abfd
, amt
);
4439 ent
->next
= eh
->elf
.got
.glist
;
4440 ent
->addend
= rel
->r_addend
;
4442 ent
->tls_type
= tls_type
;
4443 ent
->is_indirect
= FALSE
;
4444 ent
->got
.refcount
= 0;
4445 eh
->elf
.got
.glist
= ent
;
4447 ent
->got
.refcount
+= 1;
4448 eh
->tls_mask
|= tls_type
;
4451 /* This is a global offset table entry for a local symbol. */
4452 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4453 rel
->r_addend
, tls_type
))
4456 /* We may also need a plt entry if the symbol turns out to be
4458 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
4460 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4465 case R_PPC64_PLT16_HA
:
4466 case R_PPC64_PLT16_HI
:
4467 case R_PPC64_PLT16_LO
:
4468 case R_PPC64_PLT16_LO_DS
:
4471 /* This symbol requires a procedure linkage table entry. */
4476 if (h
->root
.root
.string
[0] == '.'
4477 && h
->root
.root
.string
[1] != '\0')
4478 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4479 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= PLT_KEEP
;
4480 plt_list
= &h
->plt
.plist
;
4482 if (plt_list
== NULL
)
4483 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4485 NON_GOT
| PLT_KEEP
);
4486 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4490 /* The following relocations don't need to propagate the
4491 relocation if linking a shared object since they are
4492 section relative. */
4493 case R_PPC64_SECTOFF
:
4494 case R_PPC64_SECTOFF_LO
:
4495 case R_PPC64_SECTOFF_HI
:
4496 case R_PPC64_SECTOFF_HA
:
4497 case R_PPC64_SECTOFF_DS
:
4498 case R_PPC64_SECTOFF_LO_DS
:
4499 case R_PPC64_DTPREL16
:
4500 case R_PPC64_DTPREL16_LO
:
4501 case R_PPC64_DTPREL16_HI
:
4502 case R_PPC64_DTPREL16_HA
:
4503 case R_PPC64_DTPREL16_DS
:
4504 case R_PPC64_DTPREL16_LO_DS
:
4505 case R_PPC64_DTPREL16_HIGH
:
4506 case R_PPC64_DTPREL16_HIGHA
:
4507 case R_PPC64_DTPREL16_HIGHER
:
4508 case R_PPC64_DTPREL16_HIGHERA
:
4509 case R_PPC64_DTPREL16_HIGHEST
:
4510 case R_PPC64_DTPREL16_HIGHESTA
:
4515 case R_PPC64_REL16_LO
:
4516 case R_PPC64_REL16_HI
:
4517 case R_PPC64_REL16_HA
:
4518 case R_PPC64_REL16_HIGH
:
4519 case R_PPC64_REL16_HIGHA
:
4520 case R_PPC64_REL16_HIGHER
:
4521 case R_PPC64_REL16_HIGHERA
:
4522 case R_PPC64_REL16_HIGHEST
:
4523 case R_PPC64_REL16_HIGHESTA
:
4524 case R_PPC64_REL16DX_HA
:
4527 /* Not supported as a dynamic relocation. */
4528 case R_PPC64_ADDR64_LOCAL
:
4529 if (bfd_link_pic (info
))
4531 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
4533 /* xgettext:c-format */
4534 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
4535 "in shared libraries and PIEs\n"),
4536 abfd
, sec
, rel
->r_offset
,
4537 ppc64_elf_howto_table
[r_type
]->name
);
4538 bfd_set_error (bfd_error_bad_value
);
4544 case R_PPC64_TOC16_DS
:
4545 htab
->do_multi_toc
= 1;
4546 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4548 case R_PPC64_TOC16_LO
:
4549 case R_PPC64_TOC16_HI
:
4550 case R_PPC64_TOC16_HA
:
4551 case R_PPC64_TOC16_LO_DS
:
4552 sec
->has_toc_reloc
= 1;
4559 /* This relocation describes the C++ object vtable hierarchy.
4560 Reconstruct it for later use during GC. */
4561 case R_PPC64_GNU_VTINHERIT
:
4562 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4566 /* This relocation describes which C++ vtable entries are actually
4567 used. Record for later use during GC. */
4568 case R_PPC64_GNU_VTENTRY
:
4569 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4574 case R_PPC64_REL14_BRTAKEN
:
4575 case R_PPC64_REL14_BRNTAKEN
:
4577 asection
*dest
= NULL
;
4579 /* Heuristic: If jumping outside our section, chances are
4580 we are going to need a stub. */
4583 /* If the sym is weak it may be overridden later, so
4584 don't assume we know where a weak sym lives. */
4585 if (h
->root
.type
== bfd_link_hash_defined
)
4586 dest
= h
->root
.u
.def
.section
;
4590 Elf_Internal_Sym
*isym
;
4592 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4597 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4601 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4605 case R_PPC64_PLTCALL
:
4606 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
4610 case R_PPC64_REL24_NOTOC
:
4616 if (h
->root
.root
.string
[0] == '.'
4617 && h
->root
.root
.string
[1] != '\0')
4618 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4620 if (h
== tga
|| h
== dottga
)
4622 sec
->has_tls_reloc
= 1;
4624 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4625 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4626 /* We have a new-style __tls_get_addr call with
4630 /* Mark this section as having an old-style call. */
4631 sec
->has_tls_get_addr_call
= 1;
4633 plt_list
= &h
->plt
.plist
;
4636 /* We may need a .plt entry if the function this reloc
4637 refers to is in a shared lib. */
4639 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4643 case R_PPC64_ADDR14
:
4644 case R_PPC64_ADDR14_BRNTAKEN
:
4645 case R_PPC64_ADDR14_BRTAKEN
:
4646 case R_PPC64_ADDR24
:
4649 case R_PPC64_TPREL64
:
4650 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4651 if (bfd_link_dll (info
))
4652 info
->flags
|= DF_STATIC_TLS
;
4655 case R_PPC64_DTPMOD64
:
4656 if (rel
+ 1 < rel_end
4657 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4658 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4659 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4661 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4664 case R_PPC64_DTPREL64
:
4665 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4667 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4668 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4669 /* This is the second reloc of a dtpmod, dtprel pair.
4670 Don't mark with TLS_DTPREL. */
4674 sec
->has_tls_reloc
= 1;
4677 struct ppc_link_hash_entry
*eh
;
4678 eh
= (struct ppc_link_hash_entry
*) h
;
4679 eh
->tls_mask
|= tls_type
;
4682 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4683 rel
->r_addend
, tls_type
))
4686 ppc64_sec
= ppc64_elf_section_data (sec
);
4687 if (ppc64_sec
->sec_type
!= sec_toc
)
4691 /* One extra to simplify get_tls_mask. */
4692 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
4693 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
4694 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
4696 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
4697 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
4698 if (ppc64_sec
->u
.toc
.add
== NULL
)
4700 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4701 ppc64_sec
->sec_type
= sec_toc
;
4703 BFD_ASSERT (rel
->r_offset
% 8 == 0);
4704 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
4705 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
4707 /* Mark the second slot of a GD or LD entry.
4708 -1 to indicate GD and -2 to indicate LD. */
4709 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
4710 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
4711 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
4712 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
4715 case R_PPC64_TPREL16
:
4716 case R_PPC64_TPREL16_LO
:
4717 case R_PPC64_TPREL16_HI
:
4718 case R_PPC64_TPREL16_HA
:
4719 case R_PPC64_TPREL16_DS
:
4720 case R_PPC64_TPREL16_LO_DS
:
4721 case R_PPC64_TPREL16_HIGH
:
4722 case R_PPC64_TPREL16_HIGHA
:
4723 case R_PPC64_TPREL16_HIGHER
:
4724 case R_PPC64_TPREL16_HIGHERA
:
4725 case R_PPC64_TPREL16_HIGHEST
:
4726 case R_PPC64_TPREL16_HIGHESTA
:
4727 if (bfd_link_dll (info
))
4728 info
->flags
|= DF_STATIC_TLS
;
4731 case R_PPC64_ADDR64
:
4733 && rel
+ 1 < rel_end
4734 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
4737 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4741 case R_PPC64_ADDR16
:
4742 case R_PPC64_ADDR16_DS
:
4743 case R_PPC64_ADDR16_HA
:
4744 case R_PPC64_ADDR16_HI
:
4745 case R_PPC64_ADDR16_HIGH
:
4746 case R_PPC64_ADDR16_HIGHA
:
4747 case R_PPC64_ADDR16_HIGHER
:
4748 case R_PPC64_ADDR16_HIGHERA
:
4749 case R_PPC64_ADDR16_HIGHEST
:
4750 case R_PPC64_ADDR16_HIGHESTA
:
4751 case R_PPC64_ADDR16_LO
:
4752 case R_PPC64_ADDR16_LO_DS
:
4753 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
4754 && rel
->r_addend
== 0)
4756 /* We may need a .plt entry if this reloc refers to a
4757 function in a shared lib. */
4758 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4760 h
->pointer_equality_needed
= 1;
4767 case R_PPC64_ADDR32
:
4768 case R_PPC64_UADDR16
:
4769 case R_PPC64_UADDR32
:
4770 case R_PPC64_UADDR64
:
4772 if (h
!= NULL
&& !bfd_link_pic (info
))
4773 /* We may need a copy reloc. */
4776 /* Don't propagate .opd relocs. */
4777 if (NO_OPD_RELOCS
&& is_opd
)
4780 /* If we are creating a shared library, and this is a reloc
4781 against a global symbol, or a non PC relative reloc
4782 against a local symbol, then we need to copy the reloc
4783 into the shared library. However, if we are linking with
4784 -Bsymbolic, we do not need to copy a reloc against a
4785 global symbol which is defined in an object we are
4786 including in the link (i.e., DEF_REGULAR is set). At
4787 this point we have not seen all the input files, so it is
4788 possible that DEF_REGULAR is not set now but will be set
4789 later (it is never cleared). In case of a weak definition,
4790 DEF_REGULAR may be cleared later by a strong definition in
4791 a shared library. We account for that possibility below by
4792 storing information in the dyn_relocs field of the hash
4793 table entry. A similar situation occurs when creating
4794 shared libraries and symbol visibility changes render the
4797 If on the other hand, we are creating an executable, we
4798 may need to keep relocations for symbols satisfied by a
4799 dynamic library if we manage to avoid copy relocs for the
4802 if ((bfd_link_pic (info
)
4803 && (must_be_dyn_reloc (info
, r_type
)
4805 && (!SYMBOLIC_BIND (info
, h
)
4806 || h
->root
.type
== bfd_link_hash_defweak
4807 || !h
->def_regular
))))
4808 || (ELIMINATE_COPY_RELOCS
4809 && !bfd_link_pic (info
)
4811 && (h
->root
.type
== bfd_link_hash_defweak
4812 || !h
->def_regular
))
4813 || (!bfd_link_pic (info
)
4816 /* We must copy these reloc types into the output file.
4817 Create a reloc section in dynobj and make room for
4821 sreloc
= _bfd_elf_make_dynamic_reloc_section
4822 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
4828 /* If this is a global symbol, we count the number of
4829 relocations we need for this symbol. */
4832 struct elf_dyn_relocs
*p
;
4833 struct elf_dyn_relocs
**head
;
4835 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4837 if (p
== NULL
|| p
->sec
!= sec
)
4839 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4849 if (!must_be_dyn_reloc (info
, r_type
))
4854 /* Track dynamic relocs needed for local syms too.
4855 We really need local syms available to do this
4857 struct ppc_dyn_relocs
*p
;
4858 struct ppc_dyn_relocs
**head
;
4859 bfd_boolean is_ifunc
;
4862 Elf_Internal_Sym
*isym
;
4864 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4869 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4873 vpp
= &elf_section_data (s
)->local_dynrel
;
4874 head
= (struct ppc_dyn_relocs
**) vpp
;
4875 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
4877 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
4879 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
4881 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4887 p
->ifunc
= is_ifunc
;
4903 /* Merge backend specific data from an object file to the output
4904 object file when linking. */
4907 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
4909 bfd
*obfd
= info
->output_bfd
;
4910 unsigned long iflags
, oflags
;
4912 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
4915 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
4918 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
4921 iflags
= elf_elfheader (ibfd
)->e_flags
;
4922 oflags
= elf_elfheader (obfd
)->e_flags
;
4924 if (iflags
& ~EF_PPC64_ABI
)
4927 /* xgettext:c-format */
4928 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
4929 bfd_set_error (bfd_error_bad_value
);
4932 else if (iflags
!= oflags
&& iflags
!= 0)
4935 /* xgettext:c-format */
4936 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
4937 ibfd
, iflags
, oflags
);
4938 bfd_set_error (bfd_error_bad_value
);
4942 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
4945 /* Merge Tag_compatibility attributes and any common GNU ones. */
4946 return _bfd_elf_merge_object_attributes (ibfd
, info
);
4950 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
4952 /* Print normal ELF private data. */
4953 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4955 if (elf_elfheader (abfd
)->e_flags
!= 0)
4959 fprintf (file
, _("private flags = 0x%lx:"),
4960 elf_elfheader (abfd
)->e_flags
);
4962 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
4963 fprintf (file
, _(" [abiv%ld]"),
4964 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
4971 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4972 of the code entry point, and its section, which must be in the same
4973 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
4976 opd_entry_value (asection
*opd_sec
,
4978 asection
**code_sec
,
4980 bfd_boolean in_code_sec
)
4982 bfd
*opd_bfd
= opd_sec
->owner
;
4983 Elf_Internal_Rela
*relocs
;
4984 Elf_Internal_Rela
*lo
, *hi
, *look
;
4987 /* No relocs implies we are linking a --just-symbols object, or looking
4988 at a final linked executable with addr2line or somesuch. */
4989 if (opd_sec
->reloc_count
== 0)
4991 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
4993 if (contents
== NULL
)
4995 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
4996 return (bfd_vma
) -1;
4997 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5000 /* PR 17512: file: 64b9dfbb. */
5001 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5002 return (bfd_vma
) -1;
5004 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5005 if (code_sec
!= NULL
)
5007 asection
*sec
, *likely
= NULL
;
5013 && val
< sec
->vma
+ sec
->size
)
5019 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5021 && (sec
->flags
& SEC_LOAD
) != 0
5022 && (sec
->flags
& SEC_ALLOC
) != 0)
5027 if (code_off
!= NULL
)
5028 *code_off
= val
- likely
->vma
;
5034 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5036 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5038 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5039 /* PR 17512: file: df8e1fd6. */
5041 return (bfd_vma
) -1;
5043 /* Go find the opd reloc at the sym address. */
5045 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5049 look
= lo
+ (hi
- lo
) / 2;
5050 if (look
->r_offset
< offset
)
5052 else if (look
->r_offset
> offset
)
5056 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5058 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5059 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5061 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5062 asection
*sec
= NULL
;
5064 if (symndx
>= symtab_hdr
->sh_info
5065 && elf_sym_hashes (opd_bfd
) != NULL
)
5067 struct elf_link_hash_entry
**sym_hashes
;
5068 struct elf_link_hash_entry
*rh
;
5070 sym_hashes
= elf_sym_hashes (opd_bfd
);
5071 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5074 rh
= elf_follow_link (rh
);
5075 if (rh
->root
.type
!= bfd_link_hash_defined
5076 && rh
->root
.type
!= bfd_link_hash_defweak
)
5078 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5080 val
= rh
->root
.u
.def
.value
;
5081 sec
= rh
->root
.u
.def
.section
;
5088 Elf_Internal_Sym
*sym
;
5090 if (symndx
< symtab_hdr
->sh_info
)
5092 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5095 size_t symcnt
= symtab_hdr
->sh_info
;
5096 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5101 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5107 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5113 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5116 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5117 val
= sym
->st_value
;
5120 val
+= look
->r_addend
;
5121 if (code_off
!= NULL
)
5123 if (code_sec
!= NULL
)
5125 if (in_code_sec
&& *code_sec
!= sec
)
5130 if (sec
->output_section
!= NULL
)
5131 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5140 /* If the ELF symbol SYM might be a function in SEC, return the
5141 function size and set *CODE_OFF to the function's entry point,
5142 otherwise return zero. */
5144 static bfd_size_type
5145 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5150 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5151 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5155 if (!(sym
->flags
& BSF_SYNTHETIC
))
5156 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
5158 if (strcmp (sym
->section
->name
, ".opd") == 0)
5160 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5161 bfd_vma symval
= sym
->value
;
5164 && opd
->adjust
!= NULL
5165 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5167 /* opd_entry_value will use cached relocs that have been
5168 adjusted, but with raw symbols. That means both local
5169 and global symbols need adjusting. */
5170 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5176 if (opd_entry_value (sym
->section
, symval
,
5177 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
5179 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5180 symbol. This size has nothing to do with the code size of the
5181 function, which is what we're supposed to return, but the
5182 code size isn't available without looking up the dot-sym.
5183 However, doing that would be a waste of time particularly
5184 since elf_find_function will look at the dot-sym anyway.
5185 Now, elf_find_function will keep the largest size of any
5186 function sym found at the code address of interest, so return
5187 1 here to avoid it incorrectly caching a larger function size
5188 for a small function. This does mean we return the wrong
5189 size for a new-ABI function of size 24, but all that does is
5190 disable caching for such functions. */
5196 if (sym
->section
!= sec
)
5198 *code_off
= sym
->value
;
5205 /* Return true if symbol is a strong function defined in an ELFv2
5206 object with st_other localentry bits of zero, ie. its local entry
5207 point coincides with its global entry point. */
5210 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5213 && h
->type
== STT_FUNC
5214 && h
->root
.type
== bfd_link_hash_defined
5215 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5216 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
5217 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5218 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5221 /* Return true if symbol is defined in a regular object file. */
5224 is_static_defined (struct elf_link_hash_entry
*h
)
5226 return ((h
->root
.type
== bfd_link_hash_defined
5227 || h
->root
.type
== bfd_link_hash_defweak
)
5228 && h
->root
.u
.def
.section
!= NULL
5229 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5232 /* If FDH is a function descriptor symbol, return the associated code
5233 entry symbol if it is defined. Return NULL otherwise. */
5235 static struct ppc_link_hash_entry
*
5236 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5238 if (fdh
->is_func_descriptor
)
5240 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5241 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5242 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5248 /* If FH is a function code entry symbol, return the associated
5249 function descriptor symbol if it is defined. Return NULL otherwise. */
5251 static struct ppc_link_hash_entry
*
5252 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5255 && fh
->oh
->is_func_descriptor
)
5257 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5258 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5259 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5265 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
5267 /* Garbage collect sections, after first dealing with dot-symbols. */
5270 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5272 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5274 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5276 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5277 htab
->need_func_desc_adj
= 0;
5279 return bfd_elf_gc_sections (abfd
, info
);
5282 /* Mark all our entry sym sections, both opd and code section. */
5285 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5287 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5288 struct bfd_sym_chain
*sym
;
5293 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5295 struct ppc_link_hash_entry
*eh
, *fh
;
5298 eh
= (struct ppc_link_hash_entry
*)
5299 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5302 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5303 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5306 fh
= defined_code_entry (eh
);
5309 sec
= fh
->elf
.root
.u
.def
.section
;
5310 sec
->flags
|= SEC_KEEP
;
5312 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5313 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5314 eh
->elf
.root
.u
.def
.value
,
5315 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5316 sec
->flags
|= SEC_KEEP
;
5318 sec
= eh
->elf
.root
.u
.def
.section
;
5319 sec
->flags
|= SEC_KEEP
;
5323 /* Mark sections containing dynamically referenced symbols. When
5324 building shared libraries, we must assume that any visible symbol is
5328 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5330 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5331 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5332 struct ppc_link_hash_entry
*fdh
;
5333 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5335 /* Dynamic linking info is on the func descriptor sym. */
5336 fdh
= defined_func_desc (eh
);
5340 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5341 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5342 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5343 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5344 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5345 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5346 && (!bfd_link_executable (info
)
5347 || info
->gc_keep_exported
5348 || info
->export_dynamic
5351 && (*d
->match
) (&d
->head
, NULL
,
5352 eh
->elf
.root
.root
.string
)))
5353 && (eh
->elf
.versioned
>= versioned
5354 || !bfd_hide_sym_by_version (info
->version_info
,
5355 eh
->elf
.root
.root
.string
)))))
5358 struct ppc_link_hash_entry
*fh
;
5360 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5362 /* Function descriptor syms cause the associated
5363 function code sym section to be marked. */
5364 fh
= defined_code_entry (eh
);
5367 code_sec
= fh
->elf
.root
.u
.def
.section
;
5368 code_sec
->flags
|= SEC_KEEP
;
5370 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5371 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5372 eh
->elf
.root
.u
.def
.value
,
5373 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5374 code_sec
->flags
|= SEC_KEEP
;
5380 /* Return the section that should be marked against GC for a given
5384 ppc64_elf_gc_mark_hook (asection
*sec
,
5385 struct bfd_link_info
*info
,
5386 Elf_Internal_Rela
*rel
,
5387 struct elf_link_hash_entry
*h
,
5388 Elf_Internal_Sym
*sym
)
5392 /* Syms return NULL if we're marking .opd, so we avoid marking all
5393 function sections, as all functions are referenced in .opd. */
5395 if (get_opd_info (sec
) != NULL
)
5400 enum elf_ppc64_reloc_type r_type
;
5401 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5403 r_type
= ELF64_R_TYPE (rel
->r_info
);
5406 case R_PPC64_GNU_VTINHERIT
:
5407 case R_PPC64_GNU_VTENTRY
:
5411 switch (h
->root
.type
)
5413 case bfd_link_hash_defined
:
5414 case bfd_link_hash_defweak
:
5415 eh
= (struct ppc_link_hash_entry
*) h
;
5416 fdh
= defined_func_desc (eh
);
5419 /* -mcall-aixdesc code references the dot-symbol on
5420 a call reloc. Mark the function descriptor too
5421 against garbage collection. */
5423 if (fdh
->elf
.is_weakalias
)
5424 weakdef (&fdh
->elf
)->mark
= 1;
5428 /* Function descriptor syms cause the associated
5429 function code sym section to be marked. */
5430 fh
= defined_code_entry (eh
);
5433 /* They also mark their opd section. */
5434 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5436 rsec
= fh
->elf
.root
.u
.def
.section
;
5438 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5439 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5440 eh
->elf
.root
.u
.def
.value
,
5441 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
5442 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5444 rsec
= h
->root
.u
.def
.section
;
5447 case bfd_link_hash_common
:
5448 rsec
= h
->root
.u
.c
.p
->section
;
5452 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5458 struct _opd_sec_data
*opd
;
5460 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5461 opd
= get_opd_info (rsec
);
5462 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5466 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
5473 /* The maximum size of .sfpr. */
5474 #define SFPR_MAX (218*4)
5476 struct sfpr_def_parms
5478 const char name
[12];
5479 unsigned char lo
, hi
;
5480 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
5481 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
5484 /* Auto-generate _save*, _rest* functions in .sfpr.
5485 If STUB_SEC is non-null, define alias symbols in STUB_SEC
5489 sfpr_define (struct bfd_link_info
*info
,
5490 const struct sfpr_def_parms
*parm
,
5493 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5495 size_t len
= strlen (parm
->name
);
5496 bfd_boolean writing
= FALSE
;
5502 memcpy (sym
, parm
->name
, len
);
5505 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5507 struct ppc_link_hash_entry
*h
;
5509 sym
[len
+ 0] = i
/ 10 + '0';
5510 sym
[len
+ 1] = i
% 10 + '0';
5511 h
= (struct ppc_link_hash_entry
*)
5512 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
5513 if (stub_sec
!= NULL
)
5516 && h
->elf
.root
.type
== bfd_link_hash_defined
5517 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
5519 struct elf_link_hash_entry
*s
;
5521 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
5522 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
5525 if (s
->root
.type
== bfd_link_hash_new
5526 || (s
->root
.type
= bfd_link_hash_defined
5527 && s
->root
.u
.def
.section
== stub_sec
))
5529 s
->root
.type
= bfd_link_hash_defined
;
5530 s
->root
.u
.def
.section
= stub_sec
;
5531 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
5532 + h
->elf
.root
.u
.def
.value
);
5535 s
->ref_regular_nonweak
= 1;
5536 s
->forced_local
= 1;
5538 s
->root
.linker_def
= 1;
5546 if (!h
->elf
.def_regular
)
5548 h
->elf
.root
.type
= bfd_link_hash_defined
;
5549 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
5550 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
5551 h
->elf
.type
= STT_FUNC
;
5552 h
->elf
.def_regular
= 1;
5554 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
5556 if (htab
->sfpr
->contents
== NULL
)
5558 htab
->sfpr
->contents
5559 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5560 if (htab
->sfpr
->contents
== NULL
)
5567 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5569 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5571 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5572 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5580 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5582 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5587 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5589 p
= savegpr0 (abfd
, p
, r
);
5590 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5592 bfd_put_32 (abfd
, BLR
, p
);
5597 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5599 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5604 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5606 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5608 p
= restgpr0 (abfd
, p
, r
);
5609 bfd_put_32 (abfd
, MTLR_R0
, p
);
5613 p
= restgpr0 (abfd
, p
, 30);
5614 p
= restgpr0 (abfd
, p
, 31);
5616 bfd_put_32 (abfd
, BLR
, p
);
5621 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5623 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5628 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5630 p
= savegpr1 (abfd
, p
, r
);
5631 bfd_put_32 (abfd
, BLR
, p
);
5636 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5638 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5643 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5645 p
= restgpr1 (abfd
, p
, r
);
5646 bfd_put_32 (abfd
, BLR
, p
);
5651 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5653 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5658 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5660 p
= savefpr (abfd
, p
, r
);
5661 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5663 bfd_put_32 (abfd
, BLR
, p
);
5668 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5670 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5675 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5677 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5679 p
= restfpr (abfd
, p
, r
);
5680 bfd_put_32 (abfd
, MTLR_R0
, p
);
5684 p
= restfpr (abfd
, p
, 30);
5685 p
= restfpr (abfd
, p
, 31);
5687 bfd_put_32 (abfd
, BLR
, p
);
5692 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5694 p
= savefpr (abfd
, p
, r
);
5695 bfd_put_32 (abfd
, BLR
, p
);
5700 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5702 p
= restfpr (abfd
, p
, r
);
5703 bfd_put_32 (abfd
, BLR
, p
);
5708 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
5710 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5712 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
5717 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5719 p
= savevr (abfd
, p
, r
);
5720 bfd_put_32 (abfd
, BLR
, p
);
5725 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
5727 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5729 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
5734 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5736 p
= restvr (abfd
, p
, r
);
5737 bfd_put_32 (abfd
, BLR
, p
);
5741 /* Called via elf_link_hash_traverse to transfer dynamic linking
5742 information on function code symbol entries to their corresponding
5743 function descriptor symbol entries. */
5746 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
5748 struct bfd_link_info
*info
;
5749 struct ppc_link_hash_table
*htab
;
5750 struct ppc_link_hash_entry
*fh
;
5751 struct ppc_link_hash_entry
*fdh
;
5752 bfd_boolean force_local
;
5754 fh
= (struct ppc_link_hash_entry
*) h
;
5755 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
5761 if (fh
->elf
.root
.root
.string
[0] != '.'
5762 || fh
->elf
.root
.root
.string
[1] == '\0')
5766 htab
= ppc_hash_table (info
);
5770 /* Find the corresponding function descriptor symbol. */
5771 fdh
= lookup_fdh (fh
, htab
);
5773 /* Resolve undefined references to dot-symbols as the value
5774 in the function descriptor, if we have one in a regular object.
5775 This is to satisfy cases like ".quad .foo". Calls to functions
5776 in dynamic objects are handled elsewhere. */
5777 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
5778 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5779 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
5780 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5781 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
5782 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
5783 fdh
->elf
.root
.u
.def
.value
,
5784 &fh
->elf
.root
.u
.def
.section
,
5785 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
5787 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
5788 fh
->elf
.forced_local
= 1;
5789 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
5790 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
5793 if (!fh
->elf
.dynamic
)
5795 struct plt_entry
*ent
;
5797 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5798 if (ent
->plt
.refcount
> 0)
5804 /* Create a descriptor as undefined if necessary. */
5806 && !bfd_link_executable (info
)
5807 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
5808 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
5810 fdh
= make_fdh (info
, fh
);
5815 /* We can't support overriding of symbols on a fake descriptor. */
5818 && (fh
->elf
.root
.type
== bfd_link_hash_defined
5819 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
5820 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
5822 /* Transfer dynamic linking information to the function descriptor. */
5825 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
5826 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
5827 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
5828 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
5829 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
5830 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
5831 || fh
->elf
.type
== STT_FUNC
5832 || fh
->elf
.type
== STT_GNU_IFUNC
);
5833 move_plt_plist (fh
, fdh
);
5835 if (!fdh
->elf
.forced_local
5836 && fh
->elf
.dynindx
!= -1)
5837 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5841 /* Now that the info is on the function descriptor, clear the
5842 function code sym info. Any function code syms for which we
5843 don't have a definition in a regular file, we force local.
5844 This prevents a shared library from exporting syms that have
5845 been imported from another library. Function code syms that
5846 are really in the library we must leave global to prevent the
5847 linker dragging in a definition from a static library. */
5848 force_local
= (!fh
->elf
.def_regular
5850 || !fdh
->elf
.def_regular
5851 || fdh
->elf
.forced_local
);
5852 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5857 static const struct sfpr_def_parms save_res_funcs
[] =
5859 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
5860 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
5861 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
5862 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
5863 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
5864 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
5865 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
5866 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
5867 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
5868 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
5869 { "_savevr_", 20, 31, savevr
, savevr_tail
},
5870 { "_restvr_", 20, 31, restvr
, restvr_tail
}
5873 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5874 this hook to a) provide some gcc support functions, and b) transfer
5875 dynamic linking information gathered so far on function code symbol
5876 entries, to their corresponding function descriptor symbol entries. */
5879 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
5880 struct bfd_link_info
*info
)
5882 struct ppc_link_hash_table
*htab
;
5884 htab
= ppc_hash_table (info
);
5888 /* Provide any missing _save* and _rest* functions. */
5889 if (htab
->sfpr
!= NULL
)
5893 htab
->sfpr
->size
= 0;
5894 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
5895 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
5897 if (htab
->sfpr
->size
== 0)
5898 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
5901 if (bfd_link_relocatable (info
))
5904 if (htab
->elf
.hgot
!= NULL
)
5906 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
5907 /* Make .TOC. defined so as to prevent it being made dynamic.
5908 The wrong value here is fixed later in ppc64_elf_set_toc. */
5909 if (!htab
->elf
.hgot
->def_regular
5910 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
5912 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
5913 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
5914 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
5915 htab
->elf
.hgot
->def_regular
= 1;
5916 htab
->elf
.hgot
->root
.linker_def
= 1;
5918 htab
->elf
.hgot
->type
= STT_OBJECT
;
5919 htab
->elf
.hgot
->other
5920 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
5923 if (htab
->need_func_desc_adj
)
5925 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5926 htab
->need_func_desc_adj
= 0;
5932 /* Find dynamic relocs for H that apply to read-only sections. */
5935 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
5937 struct ppc_link_hash_entry
*eh
;
5938 struct elf_dyn_relocs
*p
;
5940 eh
= (struct ppc_link_hash_entry
*) h
;
5941 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5943 asection
*s
= p
->sec
->output_section
;
5945 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5951 /* Return true if we have dynamic relocs against H or any of its weak
5952 aliases, that apply to read-only sections. Cannot be used after
5953 size_dynamic_sections. */
5956 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
5958 struct ppc_link_hash_entry
*eh
;
5960 eh
= (struct ppc_link_hash_entry
*) h
;
5963 if (readonly_dynrelocs (&eh
->elf
))
5965 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
5967 while (eh
!= NULL
&& &eh
->elf
!= h
);
5972 /* Return whether EH has pc-relative dynamic relocs. */
5975 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
5977 struct elf_dyn_relocs
*p
;
5979 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5980 if (p
->pc_count
!= 0)
5985 /* Return true if a global entry stub will be created for H. Valid
5986 for ELFv2 before plt entries have been allocated. */
5989 global_entry_stub (struct elf_link_hash_entry
*h
)
5991 struct plt_entry
*pent
;
5993 if (!h
->pointer_equality_needed
5997 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
5998 if (pent
->plt
.refcount
> 0
5999 && pent
->addend
== 0)
6005 /* Adjust a symbol defined by a dynamic object and referenced by a
6006 regular object. The current definition is in some section of the
6007 dynamic object, but we're not including those sections. We have to
6008 change the definition to something the rest of the link can
6012 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6013 struct elf_link_hash_entry
*h
)
6015 struct ppc_link_hash_table
*htab
;
6018 htab
= ppc_hash_table (info
);
6022 /* Deal with function syms. */
6023 if (h
->type
== STT_FUNC
6024 || h
->type
== STT_GNU_IFUNC
6027 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
6028 || SYMBOL_CALLS_LOCAL (info
, h
)
6029 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6030 /* Discard dyn_relocs when non-pic if we've decided that a
6031 function symbol is local and not an ifunc. We keep dynamic
6032 relocs for ifuncs when local rather than always emitting a
6033 plt call stub for them and defining the symbol on the call
6034 stub. We can't do that for ELFv1 anyway (a function symbol
6035 is defined on a descriptor, not code) and it can be faster at
6036 run-time due to not needing to bounce through a stub. The
6037 dyn_relocs for ifuncs will be applied even in a static
6039 if (!bfd_link_pic (info
)
6040 && h
->type
!= STT_GNU_IFUNC
6042 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6044 /* Clear procedure linkage table information for any symbol that
6045 won't need a .plt entry. */
6046 struct plt_entry
*ent
;
6047 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6048 if (ent
->plt
.refcount
> 0)
6051 || (h
->type
!= STT_GNU_IFUNC
6053 && (htab
->can_convert_all_inline_plt
6054 || (((struct ppc_link_hash_entry
*) h
)->tls_mask
6055 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6057 h
->plt
.plist
= NULL
;
6059 h
->pointer_equality_needed
= 0;
6061 else if (abiversion (info
->output_bfd
) >= 2)
6063 /* Taking a function's address in a read/write section
6064 doesn't require us to define the function symbol in the
6065 executable on a global entry stub. A dynamic reloc can
6066 be used instead. The reason we prefer a few more dynamic
6067 relocs is that calling via a global entry stub costs a
6068 few more instructions, and pointer_equality_needed causes
6069 extra work in ld.so when resolving these symbols. */
6070 if (global_entry_stub (h
))
6072 if (!readonly_dynrelocs (h
))
6074 h
->pointer_equality_needed
= 0;
6075 /* If we haven't seen a branch reloc and the symbol
6076 isn't an ifunc then we don't need a plt entry. */
6078 h
->plt
.plist
= NULL
;
6080 else if (!bfd_link_pic (info
))
6081 /* We are going to be defining the function symbol on the
6082 plt stub, so no dyn_relocs needed when non-pic. */
6083 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6086 /* ELFv2 function symbols can't have copy relocs. */
6089 else if (!h
->needs_plt
6090 && !readonly_dynrelocs (h
))
6092 /* If we haven't seen a branch reloc and the symbol isn't an
6093 ifunc then we don't need a plt entry. */
6094 h
->plt
.plist
= NULL
;
6095 h
->pointer_equality_needed
= 0;
6100 h
->plt
.plist
= NULL
;
6102 /* If this is a weak symbol, and there is a real definition, the
6103 processor independent code will have arranged for us to see the
6104 real definition first, and we can just use the same value. */
6105 if (h
->is_weakalias
)
6107 struct elf_link_hash_entry
*def
= weakdef (h
);
6108 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6109 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6110 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6111 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6112 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6113 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6117 /* If we are creating a shared library, we must presume that the
6118 only references to the symbol are via the global offset table.
6119 For such cases we need not do anything here; the relocations will
6120 be handled correctly by relocate_section. */
6121 if (bfd_link_pic (info
))
6124 /* If there are no references to this symbol that do not use the
6125 GOT, we don't need to generate a copy reloc. */
6126 if (!h
->non_got_ref
)
6129 /* Don't generate a copy reloc for symbols defined in the executable. */
6130 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6132 /* If -z nocopyreloc was given, don't generate them either. */
6133 || info
->nocopyreloc
6135 /* If we don't find any dynamic relocs in read-only sections, then
6136 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6137 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
6139 /* Protected variables do not work with .dynbss. The copy in
6140 .dynbss won't be used by the shared library with the protected
6141 definition for the variable. Text relocations are preferable
6142 to an incorrect program. */
6143 || h
->protected_def
)
6146 if (h
->plt
.plist
!= NULL
)
6148 /* We should never get here, but unfortunately there are versions
6149 of gcc out there that improperly (for this ABI) put initialized
6150 function pointers, vtable refs and suchlike in read-only
6151 sections. Allow them to proceed, but warn that this might
6152 break at runtime. */
6153 info
->callbacks
->einfo
6154 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6155 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6156 h
->root
.root
.string
);
6159 /* This is a reference to a symbol defined by a dynamic object which
6160 is not a function. */
6162 /* We must allocate the symbol in our .dynbss section, which will
6163 become part of the .bss section of the executable. There will be
6164 an entry for this symbol in the .dynsym section. The dynamic
6165 object will contain position independent code, so all references
6166 from the dynamic object to this symbol will go through the global
6167 offset table. The dynamic linker will use the .dynsym entry to
6168 determine the address it must put in the global offset table, so
6169 both the dynamic object and the regular object will refer to the
6170 same memory location for the variable. */
6171 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6173 s
= htab
->elf
.sdynrelro
;
6174 srel
= htab
->elf
.sreldynrelro
;
6178 s
= htab
->elf
.sdynbss
;
6179 srel
= htab
->elf
.srelbss
;
6181 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6183 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6184 linker to copy the initial value out of the dynamic object
6185 and into the runtime process image. */
6186 srel
->size
+= sizeof (Elf64_External_Rela
);
6190 /* We no longer want dyn_relocs. */
6191 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6192 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6195 /* If given a function descriptor symbol, hide both the function code
6196 sym and the descriptor. */
6198 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6199 struct elf_link_hash_entry
*h
,
6200 bfd_boolean force_local
)
6202 struct ppc_link_hash_entry
*eh
;
6203 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6205 if (ppc_hash_table (info
) == NULL
)
6208 eh
= (struct ppc_link_hash_entry
*) h
;
6209 if (eh
->is_func_descriptor
)
6211 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6216 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6219 /* We aren't supposed to use alloca in BFD because on
6220 systems which do not have alloca the version in libiberty
6221 calls xmalloc, which might cause the program to crash
6222 when it runs out of memory. This function doesn't have a
6223 return status, so there's no way to gracefully return an
6224 error. So cheat. We know that string[-1] can be safely
6225 accessed; It's either a string in an ELF string table,
6226 or allocated in an objalloc structure. */
6228 p
= eh
->elf
.root
.root
.string
- 1;
6231 fh
= (struct ppc_link_hash_entry
*)
6232 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6235 /* Unfortunately, if it so happens that the string we were
6236 looking for was allocated immediately before this string,
6237 then we overwrote the string terminator. That's the only
6238 reason the lookup should fail. */
6241 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6242 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6244 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6245 fh
= (struct ppc_link_hash_entry
*)
6246 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6255 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6260 get_sym_h (struct elf_link_hash_entry
**hp
,
6261 Elf_Internal_Sym
**symp
,
6263 unsigned char **tls_maskp
,
6264 Elf_Internal_Sym
**locsymsp
,
6265 unsigned long r_symndx
,
6268 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6270 if (r_symndx
>= symtab_hdr
->sh_info
)
6272 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6273 struct elf_link_hash_entry
*h
;
6275 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6276 h
= elf_follow_link (h
);
6284 if (symsecp
!= NULL
)
6286 asection
*symsec
= NULL
;
6287 if (h
->root
.type
== bfd_link_hash_defined
6288 || h
->root
.type
== bfd_link_hash_defweak
)
6289 symsec
= h
->root
.u
.def
.section
;
6293 if (tls_maskp
!= NULL
)
6295 struct ppc_link_hash_entry
*eh
;
6297 eh
= (struct ppc_link_hash_entry
*) h
;
6298 *tls_maskp
= &eh
->tls_mask
;
6303 Elf_Internal_Sym
*sym
;
6304 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6306 if (locsyms
== NULL
)
6308 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6309 if (locsyms
== NULL
)
6310 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6311 symtab_hdr
->sh_info
,
6312 0, NULL
, NULL
, NULL
);
6313 if (locsyms
== NULL
)
6315 *locsymsp
= locsyms
;
6317 sym
= locsyms
+ r_symndx
;
6325 if (symsecp
!= NULL
)
6326 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6328 if (tls_maskp
!= NULL
)
6330 struct got_entry
**lgot_ents
;
6331 unsigned char *tls_mask
;
6334 lgot_ents
= elf_local_got_ents (ibfd
);
6335 if (lgot_ents
!= NULL
)
6337 struct plt_entry
**local_plt
= (struct plt_entry
**)
6338 (lgot_ents
+ symtab_hdr
->sh_info
);
6339 unsigned char *lgot_masks
= (unsigned char *)
6340 (local_plt
+ symtab_hdr
->sh_info
);
6341 tls_mask
= &lgot_masks
[r_symndx
];
6343 *tls_maskp
= tls_mask
;
6349 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6350 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6351 type suitable for optimization, and 1 otherwise. */
6354 get_tls_mask (unsigned char **tls_maskp
,
6355 unsigned long *toc_symndx
,
6356 bfd_vma
*toc_addend
,
6357 Elf_Internal_Sym
**locsymsp
,
6358 const Elf_Internal_Rela
*rel
,
6361 unsigned long r_symndx
;
6363 struct elf_link_hash_entry
*h
;
6364 Elf_Internal_Sym
*sym
;
6368 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6369 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6372 if ((*tls_maskp
!= NULL
6373 && (**tls_maskp
& TLS_TLS
) != 0
6374 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
6376 || ppc64_elf_section_data (sec
) == NULL
6377 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6380 /* Look inside a TOC section too. */
6383 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6384 off
= h
->root
.u
.def
.value
;
6387 off
= sym
->st_value
;
6388 off
+= rel
->r_addend
;
6389 BFD_ASSERT (off
% 8 == 0);
6390 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6391 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6392 if (toc_symndx
!= NULL
)
6393 *toc_symndx
= r_symndx
;
6394 if (toc_addend
!= NULL
)
6395 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6396 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6398 if ((h
== NULL
|| is_static_defined (h
))
6399 && (next_r
== -1 || next_r
== -2))
6404 /* Find (or create) an entry in the tocsave hash table. */
6406 static struct tocsave_entry
*
6407 tocsave_find (struct ppc_link_hash_table
*htab
,
6408 enum insert_option insert
,
6409 Elf_Internal_Sym
**local_syms
,
6410 const Elf_Internal_Rela
*irela
,
6413 unsigned long r_indx
;
6414 struct elf_link_hash_entry
*h
;
6415 Elf_Internal_Sym
*sym
;
6416 struct tocsave_entry ent
, *p
;
6418 struct tocsave_entry
**slot
;
6420 r_indx
= ELF64_R_SYM (irela
->r_info
);
6421 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
6423 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
6426 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
6431 ent
.offset
= h
->root
.u
.def
.value
;
6433 ent
.offset
= sym
->st_value
;
6434 ent
.offset
+= irela
->r_addend
;
6436 hash
= tocsave_htab_hash (&ent
);
6437 slot
= ((struct tocsave_entry
**)
6438 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
6444 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
6453 /* Adjust all global syms defined in opd sections. In gcc generated
6454 code for the old ABI, these will already have been done. */
6457 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6459 struct ppc_link_hash_entry
*eh
;
6461 struct _opd_sec_data
*opd
;
6463 if (h
->root
.type
== bfd_link_hash_indirect
)
6466 if (h
->root
.type
!= bfd_link_hash_defined
6467 && h
->root
.type
!= bfd_link_hash_defweak
)
6470 eh
= (struct ppc_link_hash_entry
*) h
;
6471 if (eh
->adjust_done
)
6474 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6475 opd
= get_opd_info (sym_sec
);
6476 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6478 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
6481 /* This entry has been deleted. */
6482 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6485 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6486 if (discarded_section (dsec
))
6488 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6492 eh
->elf
.root
.u
.def
.value
= 0;
6493 eh
->elf
.root
.u
.def
.section
= dsec
;
6496 eh
->elf
.root
.u
.def
.value
+= adjust
;
6497 eh
->adjust_done
= 1;
6502 /* Handles decrementing dynamic reloc counts for the reloc specified by
6503 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
6504 have already been determined. */
6507 dec_dynrel_count (bfd_vma r_info
,
6509 struct bfd_link_info
*info
,
6510 Elf_Internal_Sym
**local_syms
,
6511 struct elf_link_hash_entry
*h
,
6512 Elf_Internal_Sym
*sym
)
6514 enum elf_ppc64_reloc_type r_type
;
6515 asection
*sym_sec
= NULL
;
6517 /* Can this reloc be dynamic? This switch, and later tests here
6518 should be kept in sync with the code in check_relocs. */
6519 r_type
= ELF64_R_TYPE (r_info
);
6525 case R_PPC64_TPREL16
:
6526 case R_PPC64_TPREL16_LO
:
6527 case R_PPC64_TPREL16_HI
:
6528 case R_PPC64_TPREL16_HA
:
6529 case R_PPC64_TPREL16_DS
:
6530 case R_PPC64_TPREL16_LO_DS
:
6531 case R_PPC64_TPREL16_HIGH
:
6532 case R_PPC64_TPREL16_HIGHA
:
6533 case R_PPC64_TPREL16_HIGHER
:
6534 case R_PPC64_TPREL16_HIGHERA
:
6535 case R_PPC64_TPREL16_HIGHEST
:
6536 case R_PPC64_TPREL16_HIGHESTA
:
6537 case R_PPC64_TPREL64
:
6538 case R_PPC64_DTPMOD64
:
6539 case R_PPC64_DTPREL64
:
6540 case R_PPC64_ADDR64
:
6544 case R_PPC64_ADDR14
:
6545 case R_PPC64_ADDR14_BRNTAKEN
:
6546 case R_PPC64_ADDR14_BRTAKEN
:
6547 case R_PPC64_ADDR16
:
6548 case R_PPC64_ADDR16_DS
:
6549 case R_PPC64_ADDR16_HA
:
6550 case R_PPC64_ADDR16_HI
:
6551 case R_PPC64_ADDR16_HIGH
:
6552 case R_PPC64_ADDR16_HIGHA
:
6553 case R_PPC64_ADDR16_HIGHER
:
6554 case R_PPC64_ADDR16_HIGHERA
:
6555 case R_PPC64_ADDR16_HIGHEST
:
6556 case R_PPC64_ADDR16_HIGHESTA
:
6557 case R_PPC64_ADDR16_LO
:
6558 case R_PPC64_ADDR16_LO_DS
:
6559 case R_PPC64_ADDR24
:
6560 case R_PPC64_ADDR32
:
6561 case R_PPC64_UADDR16
:
6562 case R_PPC64_UADDR32
:
6563 case R_PPC64_UADDR64
:
6568 if (local_syms
!= NULL
)
6570 unsigned long r_symndx
;
6571 bfd
*ibfd
= sec
->owner
;
6573 r_symndx
= ELF64_R_SYM (r_info
);
6574 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6578 if ((bfd_link_pic (info
)
6579 && (must_be_dyn_reloc (info
, r_type
)
6581 && (!SYMBOLIC_BIND (info
, h
)
6582 || h
->root
.type
== bfd_link_hash_defweak
6583 || !h
->def_regular
))))
6584 || (ELIMINATE_COPY_RELOCS
6585 && !bfd_link_pic (info
)
6587 && (h
->root
.type
== bfd_link_hash_defweak
6588 || !h
->def_regular
)))
6595 struct elf_dyn_relocs
*p
;
6596 struct elf_dyn_relocs
**pp
;
6597 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6599 /* elf_gc_sweep may have already removed all dyn relocs associated
6600 with local syms for a given section. Also, symbol flags are
6601 changed by elf_gc_sweep_symbol, confusing the test above. Don't
6602 report a dynreloc miscount. */
6603 if (*pp
== NULL
&& info
->gc_sections
)
6606 while ((p
= *pp
) != NULL
)
6610 if (!must_be_dyn_reloc (info
, r_type
))
6622 struct ppc_dyn_relocs
*p
;
6623 struct ppc_dyn_relocs
**pp
;
6625 bfd_boolean is_ifunc
;
6627 if (local_syms
== NULL
)
6628 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6629 if (sym_sec
== NULL
)
6632 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6633 pp
= (struct ppc_dyn_relocs
**) vpp
;
6635 if (*pp
== NULL
&& info
->gc_sections
)
6638 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
6639 while ((p
= *pp
) != NULL
)
6641 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
6652 /* xgettext:c-format */
6653 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
6655 bfd_set_error (bfd_error_bad_value
);
6659 /* Remove unused Official Procedure Descriptor entries. Currently we
6660 only remove those associated with functions in discarded link-once
6661 sections, or weakly defined functions that have been overridden. It
6662 would be possible to remove many more entries for statically linked
6666 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
6669 bfd_boolean some_edited
= FALSE
;
6670 asection
*need_pad
= NULL
;
6671 struct ppc_link_hash_table
*htab
;
6673 htab
= ppc_hash_table (info
);
6677 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
6680 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6681 Elf_Internal_Shdr
*symtab_hdr
;
6682 Elf_Internal_Sym
*local_syms
;
6683 struct _opd_sec_data
*opd
;
6684 bfd_boolean need_edit
, add_aux_fields
, broken
;
6685 bfd_size_type cnt_16b
= 0;
6687 if (!is_ppc64_elf (ibfd
))
6690 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6691 if (sec
== NULL
|| sec
->size
== 0)
6694 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
6697 if (sec
->output_section
== bfd_abs_section_ptr
)
6700 /* Look through the section relocs. */
6701 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6705 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6707 /* Read the relocations. */
6708 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6710 if (relstart
== NULL
)
6713 /* First run through the relocs to check they are sane, and to
6714 determine whether we need to edit this opd section. */
6718 relend
= relstart
+ sec
->reloc_count
;
6719 for (rel
= relstart
; rel
< relend
; )
6721 enum elf_ppc64_reloc_type r_type
;
6722 unsigned long r_symndx
;
6724 struct elf_link_hash_entry
*h
;
6725 Elf_Internal_Sym
*sym
;
6728 /* .opd contains an array of 16 or 24 byte entries. We're
6729 only interested in the reloc pointing to a function entry
6731 offset
= rel
->r_offset
;
6732 if (rel
+ 1 == relend
6733 || rel
[1].r_offset
!= offset
+ 8)
6735 /* If someone messes with .opd alignment then after a
6736 "ld -r" we might have padding in the middle of .opd.
6737 Also, there's nothing to prevent someone putting
6738 something silly in .opd with the assembler. No .opd
6739 optimization for them! */
6742 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
6747 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6748 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6751 /* xgettext:c-format */
6752 (_("%pB: unexpected reloc type %u in .opd section"),
6758 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6759 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6763 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6765 const char *sym_name
;
6767 sym_name
= h
->root
.root
.string
;
6769 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6773 /* xgettext:c-format */
6774 (_("%pB: undefined sym `%s' in .opd section"),
6780 /* opd entries are always for functions defined in the
6781 current input bfd. If the symbol isn't defined in the
6782 input bfd, then we won't be using the function in this
6783 bfd; It must be defined in a linkonce section in another
6784 bfd, or is weak. It's also possible that we are
6785 discarding the function due to a linker script /DISCARD/,
6786 which we test for via the output_section. */
6787 if (sym_sec
->owner
!= ibfd
6788 || sym_sec
->output_section
== bfd_abs_section_ptr
)
6792 if (rel
+ 1 == relend
6793 || (rel
+ 2 < relend
6794 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
6799 if (sec
->size
== offset
+ 24)
6804 if (sec
->size
== offset
+ 16)
6811 else if (rel
+ 1 < relend
6812 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
6813 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
6815 if (rel
[0].r_offset
== offset
+ 16)
6817 else if (rel
[0].r_offset
!= offset
+ 24)
6824 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
6826 if (!broken
&& (need_edit
|| add_aux_fields
))
6828 Elf_Internal_Rela
*write_rel
;
6829 Elf_Internal_Shdr
*rel_hdr
;
6830 bfd_byte
*rptr
, *wptr
;
6831 bfd_byte
*new_contents
;
6834 new_contents
= NULL
;
6835 amt
= OPD_NDX (sec
->size
) * sizeof (long);
6836 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
6837 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
6838 if (opd
->adjust
== NULL
)
6841 /* This seems a waste of time as input .opd sections are all
6842 zeros as generated by gcc, but I suppose there's no reason
6843 this will always be so. We might start putting something in
6844 the third word of .opd entries. */
6845 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
6848 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
6853 if (local_syms
!= NULL
6854 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6856 if (elf_section_data (sec
)->relocs
!= relstart
)
6860 sec
->contents
= loc
;
6861 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6864 elf_section_data (sec
)->relocs
= relstart
;
6866 new_contents
= sec
->contents
;
6869 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
6870 if (new_contents
== NULL
)
6874 wptr
= new_contents
;
6875 rptr
= sec
->contents
;
6876 write_rel
= relstart
;
6877 for (rel
= relstart
; rel
< relend
; )
6879 unsigned long r_symndx
;
6881 struct elf_link_hash_entry
*h
;
6882 struct ppc_link_hash_entry
*fdh
= NULL
;
6883 Elf_Internal_Sym
*sym
;
6885 Elf_Internal_Rela
*next_rel
;
6888 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6889 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6894 if (next_rel
+ 1 == relend
6895 || (next_rel
+ 2 < relend
6896 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
6899 /* See if the .opd entry is full 24 byte or
6900 16 byte (with fd_aux entry overlapped with next
6903 if (next_rel
== relend
)
6905 if (sec
->size
== rel
->r_offset
+ 16)
6908 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
6912 && h
->root
.root
.string
[0] == '.')
6914 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
6917 fdh
= ppc_follow_link (fdh
);
6918 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
6919 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6924 skip
= (sym_sec
->owner
!= ibfd
6925 || sym_sec
->output_section
== bfd_abs_section_ptr
);
6928 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
6930 /* Arrange for the function descriptor sym
6932 fdh
->elf
.root
.u
.def
.value
= 0;
6933 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
6935 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
6937 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
6942 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
6946 if (++rel
== next_rel
)
6949 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6950 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6957 /* We'll be keeping this opd entry. */
6962 /* Redefine the function descriptor symbol to
6963 this location in the opd section. It is
6964 necessary to update the value here rather
6965 than using an array of adjustments as we do
6966 for local symbols, because various places
6967 in the generic ELF code use the value
6968 stored in u.def.value. */
6969 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
6970 fdh
->adjust_done
= 1;
6973 /* Local syms are a bit tricky. We could
6974 tweak them as they can be cached, but
6975 we'd need to look through the local syms
6976 for the function descriptor sym which we
6977 don't have at the moment. So keep an
6978 array of adjustments. */
6979 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
6980 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
6983 memcpy (wptr
, rptr
, opd_ent_size
);
6984 wptr
+= opd_ent_size
;
6985 if (add_aux_fields
&& opd_ent_size
== 16)
6987 memset (wptr
, '\0', 8);
6991 /* We need to adjust any reloc offsets to point to the
6993 for ( ; rel
!= next_rel
; ++rel
)
6995 rel
->r_offset
+= adjust
;
6996 if (write_rel
!= rel
)
6997 memcpy (write_rel
, rel
, sizeof (*rel
));
7002 rptr
+= opd_ent_size
;
7005 sec
->size
= wptr
- new_contents
;
7006 sec
->reloc_count
= write_rel
- relstart
;
7009 free (sec
->contents
);
7010 sec
->contents
= new_contents
;
7013 /* Fudge the header size too, as this is used later in
7014 elf_bfd_final_link if we are emitting relocs. */
7015 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7016 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7019 else if (elf_section_data (sec
)->relocs
!= relstart
)
7022 if (local_syms
!= NULL
7023 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7025 if (!info
->keep_memory
)
7028 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7033 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7035 /* If we are doing a final link and the last .opd entry is just 16 byte
7036 long, add a 8 byte padding after it. */
7037 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7041 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7043 BFD_ASSERT (need_pad
->size
> 0);
7045 p
= bfd_malloc (need_pad
->size
+ 8);
7049 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7050 p
, 0, need_pad
->size
))
7053 need_pad
->contents
= p
;
7054 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7058 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7062 need_pad
->contents
= p
;
7065 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7066 need_pad
->size
+= 8;
7072 /* Analyze inline PLT call relocations to see whether calls to locally
7073 defined functions can be converted to direct calls. */
7076 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7078 struct ppc_link_hash_table
*htab
;
7081 bfd_vma low_vma
, high_vma
, limit
;
7083 htab
= ppc_hash_table (info
);
7087 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7088 reduced somewhat to cater for possible stubs that might be added
7089 between the call and its destination. */
7090 if (htab
->params
->group_size
< 0)
7092 limit
= -htab
->params
->group_size
;
7098 limit
= htab
->params
->group_size
;
7105 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7106 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7108 if (low_vma
> sec
->vma
)
7110 if (high_vma
< sec
->vma
+ sec
->size
)
7111 high_vma
= sec
->vma
+ sec
->size
;
7114 /* If a "bl" can reach anywhere in local code sections, then we can
7115 convert all inline PLT sequences to direct calls when the symbol
7117 if (high_vma
- low_vma
< limit
)
7119 htab
->can_convert_all_inline_plt
= 1;
7123 /* Otherwise, go looking through relocs for cases where a direct
7124 call won't reach. Mark the symbol on any such reloc to disable
7125 the optimization and keep the PLT entry as it seems likely that
7126 this will be better than creating trampolines. Note that this
7127 will disable the optimization for all inline PLT calls to a
7128 particular symbol, not just those that won't reach. The
7129 difficulty in doing a more precise optimization is that the
7130 linker needs to make a decision depending on whether a
7131 particular R_PPC64_PLTCALL insn can be turned into a direct
7132 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7133 the sequence, and there is nothing that ties those relocs
7134 together except their symbol. */
7136 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7138 Elf_Internal_Shdr
*symtab_hdr
;
7139 Elf_Internal_Sym
*local_syms
;
7141 if (!is_ppc64_elf (ibfd
))
7145 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7147 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7148 if (ppc64_elf_section_data (sec
)->has_pltcall
7149 && !bfd_is_abs_section (sec
->output_section
))
7151 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7153 /* Read the relocations. */
7154 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7156 if (relstart
== NULL
)
7159 relend
= relstart
+ sec
->reloc_count
;
7160 for (rel
= relstart
; rel
< relend
; )
7162 enum elf_ppc64_reloc_type r_type
;
7163 unsigned long r_symndx
;
7165 struct elf_link_hash_entry
*h
;
7166 Elf_Internal_Sym
*sym
;
7167 unsigned char *tls_maskp
;
7169 r_type
= ELF64_R_TYPE (rel
->r_info
);
7170 if (r_type
!= R_PPC64_PLTCALL
)
7173 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7174 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7177 if (elf_section_data (sec
)->relocs
!= relstart
)
7179 if (local_syms
!= NULL
7180 && symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7185 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7189 to
= h
->root
.u
.def
.value
;
7192 to
+= (rel
->r_addend
7193 + sym_sec
->output_offset
7194 + sym_sec
->output_section
->vma
);
7195 from
= (rel
->r_offset
7196 + sec
->output_offset
7197 + sec
->output_section
->vma
);
7198 if (to
- from
+ limit
< 2 * limit
)
7199 *tls_maskp
&= ~PLT_KEEP
;
7202 if (elf_section_data (sec
)->relocs
!= relstart
)
7206 if (local_syms
!= NULL
7207 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7209 if (!info
->keep_memory
)
7212 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7219 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7222 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7224 struct ppc_link_hash_table
*htab
;
7226 htab
= ppc_hash_table (info
);
7230 if (abiversion (info
->output_bfd
) == 1)
7233 if (htab
->params
->no_multi_toc
)
7234 htab
->do_multi_toc
= 0;
7235 else if (!htab
->do_multi_toc
)
7236 htab
->params
->no_multi_toc
= 1;
7238 /* Default to --no-plt-localentry, as this option can cause problems
7239 with symbol interposition. For example, glibc libpthread.so and
7240 libc.so duplicate many pthread symbols, with a fallback
7241 implementation in libc.so. In some cases the fallback does more
7242 work than the pthread implementation. __pthread_condattr_destroy
7243 is one such symbol: the libpthread.so implementation is
7244 localentry:0 while the libc.so implementation is localentry:8.
7245 An app that "cleverly" uses dlopen to only load necessary
7246 libraries at runtime may omit loading libpthread.so when not
7247 running multi-threaded, which then results in the libc.so
7248 fallback symbols being used and ld.so complaining. Now there
7249 are workarounds in ld (see non_zero_localentry) to detect the
7250 pthread situation, but that may not be the only case where
7251 --plt-localentry can cause trouble. */
7252 if (htab
->params
->plt_localentry0
< 0)
7253 htab
->params
->plt_localentry0
= 0;
7254 if (htab
->params
->plt_localentry0
7255 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7256 FALSE
, FALSE
, FALSE
) == NULL
)
7258 (_("warning: --plt-localentry is especially dangerous without "
7259 "ld.so support to detect ABI violations"));
7261 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7262 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7263 FALSE
, FALSE
, TRUE
));
7264 /* Move dynamic linking info to the function descriptor sym. */
7265 if (htab
->tls_get_addr
!= NULL
)
7266 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7267 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7268 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7269 FALSE
, FALSE
, TRUE
));
7270 if (htab
->params
->tls_get_addr_opt
)
7272 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7274 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7275 FALSE
, FALSE
, TRUE
);
7277 func_desc_adjust (opt
, info
);
7278 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7279 FALSE
, FALSE
, TRUE
);
7281 && (opt_fd
->root
.type
== bfd_link_hash_defined
7282 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7284 /* If glibc supports an optimized __tls_get_addr call stub,
7285 signalled by the presence of __tls_get_addr_opt, and we'll
7286 be calling __tls_get_addr via a plt call stub, then
7287 make __tls_get_addr point to __tls_get_addr_opt. */
7288 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7289 if (htab
->elf
.dynamic_sections_created
7291 && (tga_fd
->type
== STT_FUNC
7292 || tga_fd
->needs_plt
)
7293 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7294 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
7296 struct plt_entry
*ent
;
7298 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7299 if (ent
->plt
.refcount
> 0)
7303 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7304 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7305 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7307 if (opt_fd
->dynindx
!= -1)
7309 /* Use __tls_get_addr_opt in dynamic relocations. */
7310 opt_fd
->dynindx
= -1;
7311 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7312 opt_fd
->dynstr_index
);
7313 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7316 htab
->tls_get_addr_fd
7317 = (struct ppc_link_hash_entry
*) opt_fd
;
7318 tga
= &htab
->tls_get_addr
->elf
;
7319 if (opt
!= NULL
&& tga
!= NULL
)
7321 tga
->root
.type
= bfd_link_hash_indirect
;
7322 tga
->root
.u
.i
.link
= &opt
->root
;
7323 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7325 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7327 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7329 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7330 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7331 if (htab
->tls_get_addr
!= NULL
)
7333 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7334 htab
->tls_get_addr
->is_func
= 1;
7339 else if (htab
->params
->tls_get_addr_opt
< 0)
7340 htab
->params
->tls_get_addr_opt
= 0;
7342 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7345 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7349 branch_reloc_hash_match (const bfd
*ibfd
,
7350 const Elf_Internal_Rela
*rel
,
7351 const struct ppc_link_hash_entry
*hash1
,
7352 const struct ppc_link_hash_entry
*hash2
)
7354 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7355 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7356 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7358 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7360 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7361 struct elf_link_hash_entry
*h
;
7363 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7364 h
= elf_follow_link (h
);
7365 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7371 /* Run through all the TLS relocs looking for optimization
7372 opportunities. The linker has been hacked (see ppc64elf.em) to do
7373 a preliminary section layout so that we know the TLS segment
7374 offsets. We can't optimize earlier because some optimizations need
7375 to know the tp offset, and we need to optimize before allocating
7376 dynamic relocations. */
7379 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7383 struct ppc_link_hash_table
*htab
;
7384 unsigned char *toc_ref
;
7387 if (!bfd_link_executable (info
))
7390 htab
= ppc_hash_table (info
);
7394 /* Make two passes over the relocs. On the first pass, mark toc
7395 entries involved with tls relocs, and check that tls relocs
7396 involved in setting up a tls_get_addr call are indeed followed by
7397 such a call. If they are not, we can't do any tls optimization.
7398 On the second pass twiddle tls_mask flags to notify
7399 relocate_section that optimization can be done, and adjust got
7400 and plt refcounts. */
7402 for (pass
= 0; pass
< 2; ++pass
)
7403 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7405 Elf_Internal_Sym
*locsyms
= NULL
;
7406 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7408 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7409 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7411 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7412 bfd_boolean found_tls_get_addr_arg
= 0;
7414 /* Read the relocations. */
7415 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7417 if (relstart
== NULL
)
7423 relend
= relstart
+ sec
->reloc_count
;
7424 for (rel
= relstart
; rel
< relend
; rel
++)
7426 enum elf_ppc64_reloc_type r_type
;
7427 unsigned long r_symndx
;
7428 struct elf_link_hash_entry
*h
;
7429 Elf_Internal_Sym
*sym
;
7431 unsigned char *tls_mask
;
7432 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7434 bfd_boolean ok_tprel
, is_local
;
7435 long toc_ref_index
= 0;
7436 int expecting_tls_get_addr
= 0;
7437 bfd_boolean ret
= FALSE
;
7439 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7440 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7444 if (elf_section_data (sec
)->relocs
!= relstart
)
7446 if (toc_ref
!= NULL
)
7449 && (elf_symtab_hdr (ibfd
).contents
7450 != (unsigned char *) locsyms
))
7457 if (h
->root
.type
== bfd_link_hash_defined
7458 || h
->root
.type
== bfd_link_hash_defweak
)
7459 value
= h
->root
.u
.def
.value
;
7460 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7464 found_tls_get_addr_arg
= 0;
7469 /* Symbols referenced by TLS relocs must be of type
7470 STT_TLS. So no need for .opd local sym adjust. */
7471 value
= sym
->st_value
;
7480 && h
->root
.type
== bfd_link_hash_undefweak
)
7482 else if (sym_sec
!= NULL
7483 && sym_sec
->output_section
!= NULL
)
7485 value
+= sym_sec
->output_offset
;
7486 value
+= sym_sec
->output_section
->vma
;
7487 value
-= htab
->elf
.tls_sec
->vma
;
7488 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7489 < (bfd_vma
) 1 << 32);
7493 r_type
= ELF64_R_TYPE (rel
->r_info
);
7494 /* If this section has old-style __tls_get_addr calls
7495 without marker relocs, then check that each
7496 __tls_get_addr call reloc is preceded by a reloc
7497 that conceivably belongs to the __tls_get_addr arg
7498 setup insn. If we don't find matching arg setup
7499 relocs, don't do any tls optimization. */
7501 && sec
->has_tls_get_addr_call
7503 && (h
== &htab
->tls_get_addr
->elf
7504 || h
== &htab
->tls_get_addr_fd
->elf
)
7505 && !found_tls_get_addr_arg
7506 && is_branch_reloc (r_type
))
7508 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7509 "TLS optimization disabled\n"),
7510 ibfd
, sec
, rel
->r_offset
);
7515 found_tls_get_addr_arg
= 0;
7518 case R_PPC64_GOT_TLSLD16
:
7519 case R_PPC64_GOT_TLSLD16_LO
:
7520 expecting_tls_get_addr
= 1;
7521 found_tls_get_addr_arg
= 1;
7524 case R_PPC64_GOT_TLSLD16_HI
:
7525 case R_PPC64_GOT_TLSLD16_HA
:
7526 /* These relocs should never be against a symbol
7527 defined in a shared lib. Leave them alone if
7528 that turns out to be the case. */
7535 tls_type
= TLS_TLS
| TLS_LD
;
7538 case R_PPC64_GOT_TLSGD16
:
7539 case R_PPC64_GOT_TLSGD16_LO
:
7540 expecting_tls_get_addr
= 1;
7541 found_tls_get_addr_arg
= 1;
7544 case R_PPC64_GOT_TLSGD16_HI
:
7545 case R_PPC64_GOT_TLSGD16_HA
:
7551 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7553 tls_type
= TLS_TLS
| TLS_GD
;
7556 case R_PPC64_GOT_TPREL16_DS
:
7557 case R_PPC64_GOT_TPREL16_LO_DS
:
7558 case R_PPC64_GOT_TPREL16_HI
:
7559 case R_PPC64_GOT_TPREL16_HA
:
7564 tls_clear
= TLS_TPREL
;
7565 tls_type
= TLS_TLS
| TLS_TPREL
;
7572 if (rel
+ 1 < relend
7573 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
7576 && (ELF64_R_TYPE (rel
[1].r_info
)
7579 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
7580 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
7585 struct plt_entry
*ent
= NULL
;
7587 for (ent
= h
->plt
.plist
;
7590 if (ent
->addend
== rel
[1].r_addend
)
7594 && ent
->plt
.refcount
> 0)
7595 ent
->plt
.refcount
-= 1;
7600 found_tls_get_addr_arg
= 1;
7605 case R_PPC64_TOC16_LO
:
7606 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7609 /* Mark this toc entry as referenced by a TLS
7610 code sequence. We can do that now in the
7611 case of R_PPC64_TLS, and after checking for
7612 tls_get_addr for the TOC16 relocs. */
7613 if (toc_ref
== NULL
)
7615 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7616 if (toc_ref
== NULL
)
7620 value
= h
->root
.u
.def
.value
;
7622 value
= sym
->st_value
;
7623 value
+= rel
->r_addend
;
7626 BFD_ASSERT (value
< toc
->size
7627 && toc
->output_offset
% 8 == 0);
7628 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7629 if (r_type
== R_PPC64_TLS
7630 || r_type
== R_PPC64_TLSGD
7631 || r_type
== R_PPC64_TLSLD
)
7633 toc_ref
[toc_ref_index
] = 1;
7637 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7642 expecting_tls_get_addr
= 2;
7645 case R_PPC64_TPREL64
:
7649 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7654 tls_set
= TLS_EXPLICIT
;
7655 tls_clear
= TLS_TPREL
;
7660 case R_PPC64_DTPMOD64
:
7664 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7666 if (rel
+ 1 < relend
7668 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7669 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7673 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7676 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7685 tls_set
= TLS_EXPLICIT
;
7696 if (!expecting_tls_get_addr
7697 || !sec
->has_tls_get_addr_call
)
7700 if (rel
+ 1 < relend
7701 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7703 htab
->tls_get_addr_fd
))
7705 if (expecting_tls_get_addr
== 2)
7707 /* Check for toc tls entries. */
7708 unsigned char *toc_tls
;
7711 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7716 if (toc_tls
!= NULL
)
7718 if ((*toc_tls
& TLS_TLS
) != 0
7719 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
7720 found_tls_get_addr_arg
= 1;
7722 toc_ref
[toc_ref_index
] = 1;
7728 /* Uh oh, we didn't find the expected call. We
7729 could just mark this symbol to exclude it
7730 from tls optimization but it's safer to skip
7731 the entire optimization. */
7732 /* xgettext:c-format */
7733 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7734 "TLS optimization disabled\n"),
7735 ibfd
, sec
, rel
->r_offset
);
7740 /* If we don't have old-style __tls_get_addr calls
7741 without TLSGD/TLSLD marker relocs, and we haven't
7742 found a new-style __tls_get_addr call with a
7743 marker for this symbol, then we either have a
7744 broken object file or an -mlongcall style
7745 indirect call to __tls_get_addr without a marker.
7746 Disable optimization in this case. */
7747 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
7748 && (tls_set
& TLS_EXPLICIT
) == 0
7749 && !sec
->has_tls_get_addr_call
7750 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
7751 != (TLS_TLS
| TLS_MARK
)))
7754 if (expecting_tls_get_addr
)
7756 struct plt_entry
*ent
= NULL
;
7758 if (htab
->tls_get_addr
!= NULL
)
7759 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7762 if (ent
->addend
== 0)
7765 if (ent
== NULL
&& htab
->tls_get_addr_fd
!= NULL
)
7766 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7769 if (ent
->addend
== 0)
7773 && ent
->plt
.refcount
> 0)
7774 ent
->plt
.refcount
-= 1;
7780 if ((tls_set
& TLS_EXPLICIT
) == 0)
7782 struct got_entry
*ent
;
7784 /* Adjust got entry for this reloc. */
7788 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7790 for (; ent
!= NULL
; ent
= ent
->next
)
7791 if (ent
->addend
== rel
->r_addend
7792 && ent
->owner
== ibfd
7793 && ent
->tls_type
== tls_type
)
7800 /* We managed to get rid of a got entry. */
7801 if (ent
->got
.refcount
> 0)
7802 ent
->got
.refcount
-= 1;
7807 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7808 we'll lose one or two dyn relocs. */
7809 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7813 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7815 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7821 *tls_mask
|= tls_set
;
7822 *tls_mask
&= ~tls_clear
;
7825 if (elf_section_data (sec
)->relocs
!= relstart
)
7830 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7832 if (!info
->keep_memory
)
7835 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7839 if (toc_ref
!= NULL
)
7841 htab
->do_tls_opt
= 1;
7845 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7846 the values of any global symbols in a toc section that has been
7847 edited. Globals in toc sections should be a rarity, so this function
7848 sets a flag if any are found in toc sections other than the one just
7849 edited, so that further hash table traversals can be avoided. */
7851 struct adjust_toc_info
7854 unsigned long *skip
;
7855 bfd_boolean global_toc_syms
;
7858 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7861 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7863 struct ppc_link_hash_entry
*eh
;
7864 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7867 if (h
->root
.type
!= bfd_link_hash_defined
7868 && h
->root
.type
!= bfd_link_hash_defweak
)
7871 eh
= (struct ppc_link_hash_entry
*) h
;
7872 if (eh
->adjust_done
)
7875 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7877 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7878 i
= toc_inf
->toc
->rawsize
>> 3;
7880 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7882 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7885 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7888 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7889 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7892 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7893 eh
->adjust_done
= 1;
7895 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7896 toc_inf
->global_toc_syms
= TRUE
;
7901 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
7902 on a _LO variety toc/got reloc. */
7905 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
7907 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7908 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7909 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7910 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7911 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7912 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7913 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7914 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7915 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7916 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7917 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7918 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7919 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7920 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7921 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7922 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7923 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7924 /* Exclude lfqu by testing reloc. If relocs are ever
7925 defined for the reduced D field in psq_lu then those
7926 will need testing too. */
7927 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
7928 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7930 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7931 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7932 /* Exclude stfqu. psq_stu as above for psq_lu. */
7933 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
7934 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7935 && (insn
& 1) == 0));
7938 /* Examine all relocs referencing .toc sections in order to remove
7939 unused .toc entries. */
7942 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7945 struct adjust_toc_info toc_inf
;
7946 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7948 htab
->do_toc_opt
= 1;
7949 toc_inf
.global_toc_syms
= TRUE
;
7950 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7952 asection
*toc
, *sec
;
7953 Elf_Internal_Shdr
*symtab_hdr
;
7954 Elf_Internal_Sym
*local_syms
;
7955 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7956 unsigned long *skip
, *drop
;
7957 unsigned char *used
;
7958 unsigned char *keep
, last
, some_unused
;
7960 if (!is_ppc64_elf (ibfd
))
7963 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7966 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
7967 || discarded_section (toc
))
7972 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7974 /* Look at sections dropped from the final link. */
7977 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7979 if (sec
->reloc_count
== 0
7980 || !discarded_section (sec
)
7981 || get_opd_info (sec
)
7982 || (sec
->flags
& SEC_ALLOC
) == 0
7983 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7986 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7987 if (relstart
== NULL
)
7990 /* Run through the relocs to see which toc entries might be
7992 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7994 enum elf_ppc64_reloc_type r_type
;
7995 unsigned long r_symndx
;
7997 struct elf_link_hash_entry
*h
;
7998 Elf_Internal_Sym
*sym
;
8001 r_type
= ELF64_R_TYPE (rel
->r_info
);
8008 case R_PPC64_TOC16_LO
:
8009 case R_PPC64_TOC16_HI
:
8010 case R_PPC64_TOC16_HA
:
8011 case R_PPC64_TOC16_DS
:
8012 case R_PPC64_TOC16_LO_DS
:
8016 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8017 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8025 val
= h
->root
.u
.def
.value
;
8027 val
= sym
->st_value
;
8028 val
+= rel
->r_addend
;
8030 if (val
>= toc
->size
)
8033 /* Anything in the toc ought to be aligned to 8 bytes.
8034 If not, don't mark as unused. */
8040 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8045 skip
[val
>> 3] = ref_from_discarded
;
8048 if (elf_section_data (sec
)->relocs
!= relstart
)
8052 /* For largetoc loads of address constants, we can convert
8053 . addis rx,2,addr@got@ha
8054 . ld ry,addr@got@l(rx)
8056 . addis rx,2,addr@toc@ha
8057 . addi ry,rx,addr@toc@l
8058 when addr is within 2G of the toc pointer. This then means
8059 that the word storing "addr" in the toc is no longer needed. */
8061 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8062 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8063 && toc
->reloc_count
!= 0)
8065 /* Read toc relocs. */
8066 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8068 if (toc_relocs
== NULL
)
8071 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8073 enum elf_ppc64_reloc_type r_type
;
8074 unsigned long r_symndx
;
8076 struct elf_link_hash_entry
*h
;
8077 Elf_Internal_Sym
*sym
;
8080 r_type
= ELF64_R_TYPE (rel
->r_info
);
8081 if (r_type
!= R_PPC64_ADDR64
)
8084 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8085 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8090 || sym_sec
->output_section
== NULL
8091 || discarded_section (sym_sec
))
8094 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8099 if (h
->type
== STT_GNU_IFUNC
)
8101 val
= h
->root
.u
.def
.value
;
8105 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8107 val
= sym
->st_value
;
8109 val
+= rel
->r_addend
;
8110 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8112 /* We don't yet know the exact toc pointer value, but we
8113 know it will be somewhere in the toc section. Don't
8114 optimize if the difference from any possible toc
8115 pointer is outside [ff..f80008000, 7fff7fff]. */
8116 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8117 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8120 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8121 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8126 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8131 skip
[rel
->r_offset
>> 3]
8132 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8139 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8143 if (local_syms
!= NULL
8144 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8148 && elf_section_data (sec
)->relocs
!= relstart
)
8150 if (toc_relocs
!= NULL
8151 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8158 /* Now check all kept sections that might reference the toc.
8159 Check the toc itself last. */
8160 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8163 sec
= (sec
== toc
? NULL
8164 : sec
->next
== NULL
? toc
8165 : sec
->next
== toc
&& toc
->next
? toc
->next
8170 if (sec
->reloc_count
== 0
8171 || discarded_section (sec
)
8172 || get_opd_info (sec
)
8173 || (sec
->flags
& SEC_ALLOC
) == 0
8174 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8177 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8179 if (relstart
== NULL
)
8185 /* Mark toc entries referenced as used. */
8189 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8191 enum elf_ppc64_reloc_type r_type
;
8192 unsigned long r_symndx
;
8194 struct elf_link_hash_entry
*h
;
8195 Elf_Internal_Sym
*sym
;
8197 enum {no_check
, check_lo
, check_ha
} insn_check
;
8199 r_type
= ELF64_R_TYPE (rel
->r_info
);
8203 insn_check
= no_check
;
8206 case R_PPC64_GOT_TLSLD16_HA
:
8207 case R_PPC64_GOT_TLSGD16_HA
:
8208 case R_PPC64_GOT_TPREL16_HA
:
8209 case R_PPC64_GOT_DTPREL16_HA
:
8210 case R_PPC64_GOT16_HA
:
8211 case R_PPC64_TOC16_HA
:
8212 insn_check
= check_ha
;
8215 case R_PPC64_GOT_TLSLD16_LO
:
8216 case R_PPC64_GOT_TLSGD16_LO
:
8217 case R_PPC64_GOT_TPREL16_LO_DS
:
8218 case R_PPC64_GOT_DTPREL16_LO_DS
:
8219 case R_PPC64_GOT16_LO
:
8220 case R_PPC64_GOT16_LO_DS
:
8221 case R_PPC64_TOC16_LO
:
8222 case R_PPC64_TOC16_LO_DS
:
8223 insn_check
= check_lo
;
8227 if (insn_check
!= no_check
)
8229 bfd_vma off
= rel
->r_offset
& ~3;
8230 unsigned char buf
[4];
8233 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
8238 insn
= bfd_get_32 (ibfd
, buf
);
8239 if (insn_check
== check_lo
8240 ? !ok_lo_toc_insn (insn
, r_type
)
8241 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8242 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8246 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
8247 sprintf (str
, "%#08x", insn
);
8248 info
->callbacks
->einfo
8249 /* xgettext:c-format */
8250 (_("%H: toc optimization is not supported for"
8251 " %s instruction\n"),
8252 ibfd
, sec
, rel
->r_offset
& ~3, str
);
8259 case R_PPC64_TOC16_LO
:
8260 case R_PPC64_TOC16_HI
:
8261 case R_PPC64_TOC16_HA
:
8262 case R_PPC64_TOC16_DS
:
8263 case R_PPC64_TOC16_LO_DS
:
8264 /* In case we're taking addresses of toc entries. */
8265 case R_PPC64_ADDR64
:
8272 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8273 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8284 val
= h
->root
.u
.def
.value
;
8286 val
= sym
->st_value
;
8287 val
+= rel
->r_addend
;
8289 if (val
>= toc
->size
)
8292 if ((skip
[val
>> 3] & can_optimize
) != 0)
8299 case R_PPC64_TOC16_HA
:
8302 case R_PPC64_TOC16_LO_DS
:
8303 off
= rel
->r_offset
;
8304 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
8305 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
8311 if ((opc
& (0x3f << 2)) == (58u << 2))
8316 /* Wrong sort of reloc, or not a ld. We may
8317 as well clear ref_from_discarded too. */
8324 /* For the toc section, we only mark as used if this
8325 entry itself isn't unused. */
8326 else if ((used
[rel
->r_offset
>> 3]
8327 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
8330 /* Do all the relocs again, to catch reference
8339 if (elf_section_data (sec
)->relocs
!= relstart
)
8343 /* Merge the used and skip arrays. Assume that TOC
8344 doublewords not appearing as either used or unused belong
8345 to an entry more than one doubleword in size. */
8346 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8347 drop
< skip
+ (toc
->size
+ 7) / 8;
8352 *drop
&= ~ref_from_discarded
;
8353 if ((*drop
& can_optimize
) != 0)
8357 else if ((*drop
& ref_from_discarded
) != 0)
8360 last
= ref_from_discarded
;
8370 bfd_byte
*contents
, *src
;
8372 Elf_Internal_Sym
*sym
;
8373 bfd_boolean local_toc_syms
= FALSE
;
8375 /* Shuffle the toc contents, and at the same time convert the
8376 skip array from booleans into offsets. */
8377 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8380 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8382 for (src
= contents
, off
= 0, drop
= skip
;
8383 src
< contents
+ toc
->size
;
8386 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8391 memcpy (src
- off
, src
, 8);
8395 toc
->rawsize
= toc
->size
;
8396 toc
->size
= src
- contents
- off
;
8398 /* Adjust addends for relocs against the toc section sym,
8399 and optimize any accesses we can. */
8400 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8402 if (sec
->reloc_count
== 0
8403 || discarded_section (sec
))
8406 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8408 if (relstart
== NULL
)
8411 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8413 enum elf_ppc64_reloc_type r_type
;
8414 unsigned long r_symndx
;
8416 struct elf_link_hash_entry
*h
;
8419 r_type
= ELF64_R_TYPE (rel
->r_info
);
8426 case R_PPC64_TOC16_LO
:
8427 case R_PPC64_TOC16_HI
:
8428 case R_PPC64_TOC16_HA
:
8429 case R_PPC64_TOC16_DS
:
8430 case R_PPC64_TOC16_LO_DS
:
8431 case R_PPC64_ADDR64
:
8435 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8436 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8444 val
= h
->root
.u
.def
.value
;
8447 val
= sym
->st_value
;
8449 local_toc_syms
= TRUE
;
8452 val
+= rel
->r_addend
;
8454 if (val
> toc
->rawsize
)
8456 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8458 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8460 Elf_Internal_Rela
*tocrel
8461 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8462 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8466 case R_PPC64_TOC16_HA
:
8467 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8470 case R_PPC64_TOC16_LO_DS
:
8471 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8475 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
8477 info
->callbacks
->einfo
8478 /* xgettext:c-format */
8479 (_("%H: %s references "
8480 "optimized away TOC entry\n"),
8481 ibfd
, sec
, rel
->r_offset
,
8482 ppc64_elf_howto_table
[r_type
]->name
);
8483 bfd_set_error (bfd_error_bad_value
);
8486 rel
->r_addend
= tocrel
->r_addend
;
8487 elf_section_data (sec
)->relocs
= relstart
;
8491 if (h
!= NULL
|| sym
->st_value
!= 0)
8494 rel
->r_addend
-= skip
[val
>> 3];
8495 elf_section_data (sec
)->relocs
= relstart
;
8498 if (elf_section_data (sec
)->relocs
!= relstart
)
8502 /* We shouldn't have local or global symbols defined in the TOC,
8503 but handle them anyway. */
8504 if (local_syms
!= NULL
)
8505 for (sym
= local_syms
;
8506 sym
< local_syms
+ symtab_hdr
->sh_info
;
8508 if (sym
->st_value
!= 0
8509 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8513 if (sym
->st_value
> toc
->rawsize
)
8514 i
= toc
->rawsize
>> 3;
8516 i
= sym
->st_value
>> 3;
8518 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8522 (_("%s defined on removed toc entry"),
8523 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8526 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8527 sym
->st_value
= (bfd_vma
) i
<< 3;
8530 sym
->st_value
-= skip
[i
];
8531 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8534 /* Adjust any global syms defined in this toc input section. */
8535 if (toc_inf
.global_toc_syms
)
8538 toc_inf
.skip
= skip
;
8539 toc_inf
.global_toc_syms
= FALSE
;
8540 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8544 if (toc
->reloc_count
!= 0)
8546 Elf_Internal_Shdr
*rel_hdr
;
8547 Elf_Internal_Rela
*wrel
;
8550 /* Remove unused toc relocs, and adjust those we keep. */
8551 if (toc_relocs
== NULL
)
8552 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8554 if (toc_relocs
== NULL
)
8558 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8559 if ((skip
[rel
->r_offset
>> 3]
8560 & (ref_from_discarded
| can_optimize
)) == 0)
8562 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8563 wrel
->r_info
= rel
->r_info
;
8564 wrel
->r_addend
= rel
->r_addend
;
8567 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8568 &local_syms
, NULL
, NULL
))
8571 elf_section_data (toc
)->relocs
= toc_relocs
;
8572 toc
->reloc_count
= wrel
- toc_relocs
;
8573 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8574 sz
= rel_hdr
->sh_entsize
;
8575 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8578 else if (toc_relocs
!= NULL
8579 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8582 if (local_syms
!= NULL
8583 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8585 if (!info
->keep_memory
)
8588 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8593 /* Look for cases where we can change an indirect GOT access to
8594 a GOT relative access, possibly reducing the number of GOT
8596 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8599 Elf_Internal_Shdr
*symtab_hdr
;
8600 Elf_Internal_Sym
*local_syms
;
8601 Elf_Internal_Rela
*relstart
, *rel
;
8604 if (!is_ppc64_elf (ibfd
))
8607 if (!ppc64_elf_tdata (ibfd
)->has_gotrel
)
8610 sec
= ppc64_elf_tdata (ibfd
)->got
;
8611 got
= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
8614 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8616 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8618 if (sec
->reloc_count
== 0
8619 || !ppc64_elf_section_data (sec
)->has_gotrel
8620 || discarded_section (sec
))
8623 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8625 if (relstart
== NULL
)
8628 if (local_syms
!= NULL
8629 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8633 && elf_section_data (sec
)->relocs
!= relstart
)
8638 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8640 enum elf_ppc64_reloc_type r_type
;
8641 unsigned long r_symndx
;
8642 Elf_Internal_Sym
*sym
;
8644 struct elf_link_hash_entry
*h
;
8645 struct got_entry
*ent
;
8647 unsigned char buf
[4];
8650 r_type
= ELF64_R_TYPE (rel
->r_info
);
8656 case R_PPC64_GOT16_DS
:
8657 case R_PPC64_GOT16_HA
:
8658 case R_PPC64_GOT16_LO_DS
:
8662 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8663 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8667 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8671 val
= h
->root
.u
.def
.value
;
8673 val
= sym
->st_value
;
8674 val
+= rel
->r_addend
;
8675 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8682 case R_PPC64_GOT16_DS
:
8683 if (val
- got
+ 0x8000 >= 0x10000)
8685 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8686 rel
->r_offset
& ~3, 4))
8688 insn
= bfd_get_32 (ibfd
, buf
);
8689 if ((insn
& (0x3f << 26 | 0x3)) != 58u << 26 /* ld */)
8693 case R_PPC64_GOT16_HA
:
8694 if (val
- got
+ 0x80008000ULL
>= 0x100000000ULL
)
8697 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8698 rel
->r_offset
& ~3, 4))
8700 insn
= bfd_get_32 (ibfd
, buf
);
8701 if (((insn
& ((0x3f << 26) | 0x1f << 16))
8702 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8706 case R_PPC64_GOT16_LO_DS
:
8707 if (val
- got
+ 0x80008000ULL
>= 0x100000000ULL
)
8709 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
8710 rel
->r_offset
& ~3, 4))
8712 insn
= bfd_get_32 (ibfd
, buf
);
8713 if ((insn
& (0x3f << 26 | 0x3)) != 58u << 26 /* ld */)
8722 struct got_entry
**local_got_ents
= elf_local_got_ents (ibfd
);
8723 ent
= local_got_ents
[r_symndx
];
8725 for (; ent
!= NULL
; ent
= ent
->next
)
8726 if (ent
->addend
== rel
->r_addend
8727 && ent
->owner
== ibfd
8728 && ent
->tls_type
== 0)
8730 BFD_ASSERT (ent
&& ent
->got
.refcount
> 0);
8731 ent
->got
.refcount
-= 1;
8734 if (elf_section_data (sec
)->relocs
!= relstart
)
8738 if (local_syms
!= NULL
8739 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8741 if (!info
->keep_memory
)
8744 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8751 /* Return true iff input section I references the TOC using
8752 instructions limited to +/-32k offsets. */
8755 ppc64_elf_has_small_toc_reloc (asection
*i
)
8757 return (is_ppc64_elf (i
->owner
)
8758 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8761 /* Allocate space for one GOT entry. */
8764 allocate_got (struct elf_link_hash_entry
*h
,
8765 struct bfd_link_info
*info
,
8766 struct got_entry
*gent
)
8768 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8769 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8770 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8772 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8773 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8774 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8776 gent
->got
.offset
= got
->size
;
8777 got
->size
+= entsize
;
8779 if (h
->type
== STT_GNU_IFUNC
)
8781 htab
->elf
.irelplt
->size
+= rentsize
;
8782 htab
->got_reli_size
+= rentsize
;
8784 else if (((bfd_link_pic (info
)
8785 && !((gent
->tls_type
& TLS_TPREL
) != 0
8786 && bfd_link_executable (info
)
8787 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
8788 || (htab
->elf
.dynamic_sections_created
8790 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
8791 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8793 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8794 relgot
->size
+= rentsize
;
8798 /* This function merges got entries in the same toc group. */
8801 merge_got_entries (struct got_entry
**pent
)
8803 struct got_entry
*ent
, *ent2
;
8805 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8806 if (!ent
->is_indirect
)
8807 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8808 if (!ent2
->is_indirect
8809 && ent2
->addend
== ent
->addend
8810 && ent2
->tls_type
== ent
->tls_type
8811 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8813 ent2
->is_indirect
= TRUE
;
8814 ent2
->got
.ent
= ent
;
8818 /* If H is undefined, make it dynamic if that makes sense. */
8821 ensure_undef_dynamic (struct bfd_link_info
*info
,
8822 struct elf_link_hash_entry
*h
)
8824 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
8826 if (htab
->dynamic_sections_created
8827 && ((info
->dynamic_undefined_weak
!= 0
8828 && h
->root
.type
== bfd_link_hash_undefweak
)
8829 || h
->root
.type
== bfd_link_hash_undefined
)
8832 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
8833 return bfd_elf_link_record_dynamic_symbol (info
, h
);
8837 /* Allocate space in .plt, .got and associated reloc sections for
8841 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8843 struct bfd_link_info
*info
;
8844 struct ppc_link_hash_table
*htab
;
8846 struct ppc_link_hash_entry
*eh
;
8847 struct got_entry
**pgent
, *gent
;
8849 if (h
->root
.type
== bfd_link_hash_indirect
)
8852 info
= (struct bfd_link_info
*) inf
;
8853 htab
= ppc_hash_table (info
);
8857 eh
= (struct ppc_link_hash_entry
*) h
;
8858 /* Run through the TLS GD got entries first if we're changing them
8860 if ((eh
->tls_mask
& (TLS_TLS
| TLS_TPRELGD
)) == (TLS_TLS
| TLS_TPRELGD
))
8861 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8862 if (gent
->got
.refcount
> 0
8863 && (gent
->tls_type
& TLS_GD
) != 0)
8865 /* This was a GD entry that has been converted to TPREL. If
8866 there happens to be a TPREL entry we can use that one. */
8867 struct got_entry
*ent
;
8868 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8869 if (ent
->got
.refcount
> 0
8870 && (ent
->tls_type
& TLS_TPREL
) != 0
8871 && ent
->addend
== gent
->addend
8872 && ent
->owner
== gent
->owner
)
8874 gent
->got
.refcount
= 0;
8878 /* If not, then we'll be using our own TPREL entry. */
8879 if (gent
->got
.refcount
!= 0)
8880 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8883 /* Remove any list entry that won't generate a word in the GOT before
8884 we call merge_got_entries. Otherwise we risk merging to empty
8886 pgent
= &h
->got
.glist
;
8887 while ((gent
= *pgent
) != NULL
)
8888 if (gent
->got
.refcount
> 0)
8890 if ((gent
->tls_type
& TLS_LD
) != 0
8893 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8894 *pgent
= gent
->next
;
8897 pgent
= &gent
->next
;
8900 *pgent
= gent
->next
;
8902 if (!htab
->do_multi_toc
)
8903 merge_got_entries (&h
->got
.glist
);
8905 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8906 if (!gent
->is_indirect
)
8908 /* Make sure this symbol is output as a dynamic symbol. */
8909 if (!ensure_undef_dynamic (info
, h
))
8912 if (!is_ppc64_elf (gent
->owner
))
8915 allocate_got (h
, info
, gent
);
8918 /* If no dynamic sections we can't have dynamic relocs, except for
8919 IFUNCs which are handled even in static executables. */
8920 if (!htab
->elf
.dynamic_sections_created
8921 && h
->type
!= STT_GNU_IFUNC
)
8922 eh
->dyn_relocs
= NULL
;
8924 /* Discard relocs on undefined symbols that must be local. */
8925 else if (h
->root
.type
== bfd_link_hash_undefined
8926 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8927 eh
->dyn_relocs
= NULL
;
8929 /* Also discard relocs on undefined weak syms with non-default
8930 visibility, or when dynamic_undefined_weak says so. */
8931 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8932 eh
->dyn_relocs
= NULL
;
8934 if (eh
->dyn_relocs
!= NULL
)
8936 struct elf_dyn_relocs
*p
, **pp
;
8938 /* In the shared -Bsymbolic case, discard space allocated for
8939 dynamic pc-relative relocs against symbols which turn out to
8940 be defined in regular objects. For the normal shared case,
8941 discard space for relocs that have become local due to symbol
8942 visibility changes. */
8944 if (bfd_link_pic (info
))
8946 /* Relocs that use pc_count are those that appear on a call
8947 insn, or certain REL relocs (see must_be_dyn_reloc) that
8948 can be generated via assembly. We want calls to
8949 protected symbols to resolve directly to the function
8950 rather than going via the plt. If people want function
8951 pointer comparisons to work as expected then they should
8952 avoid writing weird assembly. */
8953 if (SYMBOL_CALLS_LOCAL (info
, h
))
8955 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8957 p
->count
-= p
->pc_count
;
8966 if (eh
->dyn_relocs
!= NULL
)
8968 /* Make sure this symbol is output as a dynamic symbol. */
8969 if (!ensure_undef_dynamic (info
, h
))
8973 else if (ELIMINATE_COPY_RELOCS
&& h
->type
!= STT_GNU_IFUNC
)
8975 /* For the non-pic case, discard space for relocs against
8976 symbols which turn out to need copy relocs or are not
8978 if (h
->dynamic_adjusted
8980 && !ELF_COMMON_DEF_P (h
))
8982 /* Make sure this symbol is output as a dynamic symbol. */
8983 if (!ensure_undef_dynamic (info
, h
))
8986 if (h
->dynindx
== -1)
8987 eh
->dyn_relocs
= NULL
;
8990 eh
->dyn_relocs
= NULL
;
8993 /* Finally, allocate space. */
8994 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8996 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8997 if (eh
->elf
.type
== STT_GNU_IFUNC
)
8998 sreloc
= htab
->elf
.irelplt
;
8999 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9003 /* We might need a PLT entry when the symbol
9006 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
9007 d) has plt16 relocs and we are linking statically. */
9008 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
9009 || h
->type
== STT_GNU_IFUNC
9010 || (h
->needs_plt
&& h
->dynamic_adjusted
)
9013 && !htab
->elf
.dynamic_sections_created
9014 && !htab
->can_convert_all_inline_plt
9015 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
9016 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
9018 struct plt_entry
*pent
;
9019 bfd_boolean doneone
= FALSE
;
9020 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9021 if (pent
->plt
.refcount
> 0)
9023 if (!htab
->elf
.dynamic_sections_created
9024 || h
->dynindx
== -1)
9026 if (h
->type
== STT_GNU_IFUNC
)
9029 pent
->plt
.offset
= s
->size
;
9030 s
->size
+= PLT_ENTRY_SIZE (htab
);
9031 s
= htab
->elf
.irelplt
;
9036 pent
->plt
.offset
= s
->size
;
9037 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9038 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
9043 /* If this is the first .plt entry, make room for the special
9047 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9049 pent
->plt
.offset
= s
->size
;
9051 /* Make room for this entry. */
9052 s
->size
+= PLT_ENTRY_SIZE (htab
);
9054 /* Make room for the .glink code. */
9057 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
9060 /* We need bigger stubs past index 32767. */
9061 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
9068 /* We also need to make an entry in the .rela.plt section. */
9069 s
= htab
->elf
.srelplt
;
9072 s
->size
+= sizeof (Elf64_External_Rela
);
9076 pent
->plt
.offset
= (bfd_vma
) -1;
9079 h
->plt
.plist
= NULL
;
9085 h
->plt
.plist
= NULL
;
9092 #define PPC_LO(v) ((v) & 0xffff)
9093 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9094 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9096 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9097 to set up space for global entry stubs. These are put in glink,
9098 after the branch table. */
9101 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
9103 struct bfd_link_info
*info
;
9104 struct ppc_link_hash_table
*htab
;
9105 struct plt_entry
*pent
;
9108 if (h
->root
.type
== bfd_link_hash_indirect
)
9111 if (!h
->pointer_equality_needed
)
9118 htab
= ppc_hash_table (info
);
9122 s
= htab
->global_entry
;
9123 plt
= htab
->elf
.splt
;
9124 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9125 if (pent
->plt
.offset
!= (bfd_vma
) -1
9126 && pent
->addend
== 0)
9128 /* For ELFv2, if this symbol is not defined in a regular file
9129 and we are not generating a shared library or pie, then we
9130 need to define the symbol in the executable on a call stub.
9131 This is to avoid text relocations. */
9132 bfd_vma off
, stub_align
, stub_off
, stub_size
;
9133 unsigned int align_power
;
9137 if (htab
->params
->plt_stub_align
>= 0)
9138 align_power
= htab
->params
->plt_stub_align
;
9140 align_power
= -htab
->params
->plt_stub_align
;
9141 /* Setting section alignment is delayed until we know it is
9142 non-empty. Otherwise the .text output section will be
9143 aligned at least to plt_stub_align even when no global
9144 entry stubs are needed. */
9145 if (s
->alignment_power
< align_power
)
9146 s
->alignment_power
= align_power
;
9147 stub_align
= (bfd_vma
) 1 << align_power
;
9148 if (htab
->params
->plt_stub_align
>= 0
9149 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
9150 - (stub_off
& -stub_align
))
9151 > ((stub_size
- 1) & -stub_align
)))
9152 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
9153 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
9154 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
9155 /* Note that for --plt-stub-align negative we have a possible
9156 dependency between stub offset and size. Break that
9157 dependency by assuming the max stub size when calculating
9159 if (PPC_HA (off
) == 0)
9161 h
->root
.type
= bfd_link_hash_defined
;
9162 h
->root
.u
.def
.section
= s
;
9163 h
->root
.u
.def
.value
= stub_off
;
9164 s
->size
= stub_off
+ stub_size
;
9170 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9171 read-only sections. */
9174 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
9178 if (h
->root
.type
== bfd_link_hash_indirect
)
9181 sec
= readonly_dynrelocs (h
);
9184 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
9186 info
->flags
|= DF_TEXTREL
;
9187 info
->callbacks
->minfo (_("%pB: dynamic relocation against `%pT'"
9188 " in read-only section `%pA'\n"),
9189 sec
->owner
, h
->root
.root
.string
, sec
);
9191 /* Not an error, just cut short the traversal. */
9197 /* Set the sizes of the dynamic sections. */
9200 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
9201 struct bfd_link_info
*info
)
9203 struct ppc_link_hash_table
*htab
;
9208 struct got_entry
*first_tlsld
;
9210 htab
= ppc_hash_table (info
);
9214 dynobj
= htab
->elf
.dynobj
;
9218 if (htab
->elf
.dynamic_sections_created
)
9220 /* Set the contents of the .interp section to the interpreter. */
9221 if (bfd_link_executable (info
) && !info
->nointerp
)
9223 s
= bfd_get_linker_section (dynobj
, ".interp");
9226 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
9227 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
9231 /* Set up .got offsets for local syms, and space for local dynamic
9233 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9235 struct got_entry
**lgot_ents
;
9236 struct got_entry
**end_lgot_ents
;
9237 struct plt_entry
**local_plt
;
9238 struct plt_entry
**end_local_plt
;
9239 unsigned char *lgot_masks
;
9240 bfd_size_type locsymcount
;
9241 Elf_Internal_Shdr
*symtab_hdr
;
9243 if (!is_ppc64_elf (ibfd
))
9246 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
9248 struct ppc_dyn_relocs
*p
;
9250 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
9252 if (!bfd_is_abs_section (p
->sec
)
9253 && bfd_is_abs_section (p
->sec
->output_section
))
9255 /* Input section has been discarded, either because
9256 it is a copy of a linkonce section or due to
9257 linker script /DISCARD/, so we'll be discarding
9260 else if (p
->count
!= 0)
9262 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
9264 srel
= htab
->elf
.irelplt
;
9265 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9266 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
9267 info
->flags
|= DF_TEXTREL
;
9272 lgot_ents
= elf_local_got_ents (ibfd
);
9276 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9277 locsymcount
= symtab_hdr
->sh_info
;
9278 end_lgot_ents
= lgot_ents
+ locsymcount
;
9279 local_plt
= (struct plt_entry
**) end_lgot_ents
;
9280 end_local_plt
= local_plt
+ locsymcount
;
9281 lgot_masks
= (unsigned char *) end_local_plt
;
9282 s
= ppc64_elf_tdata (ibfd
)->got
;
9283 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
9285 struct got_entry
**pent
, *ent
;
9288 while ((ent
= *pent
) != NULL
)
9289 if (ent
->got
.refcount
> 0)
9291 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
9293 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
9298 unsigned int ent_size
= 8;
9299 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
9301 ent
->got
.offset
= s
->size
;
9302 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
9307 s
->size
+= ent_size
;
9308 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9310 htab
->elf
.irelplt
->size
+= rel_size
;
9311 htab
->got_reli_size
+= rel_size
;
9313 else if (bfd_link_pic (info
)
9314 && !((ent
->tls_type
& TLS_TPREL
) != 0
9315 && bfd_link_executable (info
)))
9317 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9318 srel
->size
+= rel_size
;
9327 /* Allocate space for plt calls to local syms. */
9328 lgot_masks
= (unsigned char *) end_local_plt
;
9329 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
9331 struct plt_entry
*ent
;
9333 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9334 if (ent
->plt
.refcount
> 0)
9336 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9339 ent
->plt
.offset
= s
->size
;
9340 s
->size
+= PLT_ENTRY_SIZE (htab
);
9341 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
9343 else if (htab
->can_convert_all_inline_plt
9344 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
9345 ent
->plt
.offset
= (bfd_vma
) -1;
9349 ent
->plt
.offset
= s
->size
;
9350 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9351 if (bfd_link_pic (info
))
9352 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
9356 ent
->plt
.offset
= (bfd_vma
) -1;
9360 /* Allocate global sym .plt and .got entries, and space for global
9361 sym dynamic relocs. */
9362 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9364 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
9365 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
9368 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9370 struct got_entry
*ent
;
9372 if (!is_ppc64_elf (ibfd
))
9375 ent
= ppc64_tlsld_got (ibfd
);
9376 if (ent
->got
.refcount
> 0)
9378 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9380 ent
->is_indirect
= TRUE
;
9381 ent
->got
.ent
= first_tlsld
;
9385 if (first_tlsld
== NULL
)
9387 s
= ppc64_elf_tdata (ibfd
)->got
;
9388 ent
->got
.offset
= s
->size
;
9391 if (bfd_link_pic (info
))
9393 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9394 srel
->size
+= sizeof (Elf64_External_Rela
);
9399 ent
->got
.offset
= (bfd_vma
) -1;
9402 /* We now have determined the sizes of the various dynamic sections.
9403 Allocate memory for them. */
9405 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9407 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9410 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9411 /* These haven't been allocated yet; don't strip. */
9413 else if (s
== htab
->elf
.sgot
9414 || s
== htab
->elf
.splt
9415 || s
== htab
->elf
.iplt
9416 || s
== htab
->pltlocal
9418 || s
== htab
->global_entry
9419 || s
== htab
->elf
.sdynbss
9420 || s
== htab
->elf
.sdynrelro
)
9422 /* Strip this section if we don't need it; see the
9425 else if (s
== htab
->glink_eh_frame
)
9427 if (!bfd_is_abs_section (s
->output_section
))
9428 /* Not sized yet. */
9431 else if (CONST_STRNEQ (s
->name
, ".rela"))
9435 if (s
!= htab
->elf
.srelplt
)
9438 /* We use the reloc_count field as a counter if we need
9439 to copy relocs into the output file. */
9445 /* It's not one of our sections, so don't allocate space. */
9451 /* If we don't need this section, strip it from the
9452 output file. This is mostly to handle .rela.bss and
9453 .rela.plt. We must create both sections in
9454 create_dynamic_sections, because they must be created
9455 before the linker maps input sections to output
9456 sections. The linker does that before
9457 adjust_dynamic_symbol is called, and it is that
9458 function which decides whether anything needs to go
9459 into these sections. */
9460 s
->flags
|= SEC_EXCLUDE
;
9464 if (bfd_is_abs_section (s
->output_section
))
9465 _bfd_error_handler (_("warning: discarding dynamic section %s"),
9468 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9471 /* Allocate memory for the section contents. We use bfd_zalloc
9472 here in case unused entries are not reclaimed before the
9473 section's contents are written out. This should not happen,
9474 but this way if it does we get a R_PPC64_NONE reloc in .rela
9475 sections instead of garbage.
9476 We also rely on the section contents being zero when writing
9477 the GOT and .dynrelro. */
9478 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9479 if (s
->contents
== NULL
)
9483 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9485 if (!is_ppc64_elf (ibfd
))
9488 s
= ppc64_elf_tdata (ibfd
)->got
;
9489 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
9492 s
->flags
|= SEC_EXCLUDE
;
9495 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9496 if (s
->contents
== NULL
)
9500 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9504 s
->flags
|= SEC_EXCLUDE
;
9507 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9508 if (s
->contents
== NULL
)
9516 if (htab
->elf
.dynamic_sections_created
)
9518 bfd_boolean tls_opt
;
9520 /* Add some entries to the .dynamic section. We fill in the
9521 values later, in ppc64_elf_finish_dynamic_sections, but we
9522 must add the entries now so that we get the correct size for
9523 the .dynamic section. The DT_DEBUG entry is filled in by the
9524 dynamic linker and used by the debugger. */
9525 #define add_dynamic_entry(TAG, VAL) \
9526 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9528 if (bfd_link_executable (info
))
9530 if (!add_dynamic_entry (DT_DEBUG
, 0))
9534 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
9536 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9537 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9538 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9539 || !add_dynamic_entry (DT_JMPREL
, 0)
9540 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9544 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
9546 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9547 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9551 tls_opt
= (htab
->params
->tls_get_addr_opt
9552 && htab
->tls_get_addr_fd
!= NULL
9553 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
9554 if (tls_opt
|| !htab
->opd_abi
)
9556 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
9562 if (!add_dynamic_entry (DT_RELA
, 0)
9563 || !add_dynamic_entry (DT_RELASZ
, 0)
9564 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9567 /* If any dynamic relocs apply to a read-only section,
9568 then we need a DT_TEXTREL entry. */
9569 if ((info
->flags
& DF_TEXTREL
) == 0)
9570 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
9572 if ((info
->flags
& DF_TEXTREL
) != 0)
9574 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9579 #undef add_dynamic_entry
9584 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
9587 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
9589 if (h
->plt
.plist
!= NULL
9591 && !h
->pointer_equality_needed
)
9594 return _bfd_elf_hash_symbol (h
);
9597 /* Determine the type of stub needed, if any, for a call. */
9599 static inline enum ppc_stub_type
9600 ppc_type_of_stub (asection
*input_sec
,
9601 const Elf_Internal_Rela
*rel
,
9602 struct ppc_link_hash_entry
**hash
,
9603 struct plt_entry
**plt_ent
,
9604 bfd_vma destination
,
9605 unsigned long local_off
)
9607 struct ppc_link_hash_entry
*h
= *hash
;
9609 bfd_vma branch_offset
;
9610 bfd_vma max_branch_offset
;
9611 enum elf_ppc64_reloc_type r_type
;
9615 struct plt_entry
*ent
;
9616 struct ppc_link_hash_entry
*fdh
= h
;
9618 && h
->oh
->is_func_descriptor
)
9620 fdh
= ppc_follow_link (h
->oh
);
9624 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9625 if (ent
->addend
== rel
->r_addend
9626 && ent
->plt
.offset
!= (bfd_vma
) -1)
9629 return ppc_stub_plt_call
;
9632 /* Here, we know we don't have a plt entry. If we don't have a
9633 either a defined function descriptor or a defined entry symbol
9634 in a regular object file, then it is pointless trying to make
9635 any other type of stub. */
9636 if (!is_static_defined (&fdh
->elf
)
9637 && !is_static_defined (&h
->elf
))
9638 return ppc_stub_none
;
9640 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9642 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9643 struct plt_entry
**local_plt
= (struct plt_entry
**)
9644 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9645 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9647 if (local_plt
[r_symndx
] != NULL
)
9649 struct plt_entry
*ent
;
9651 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9652 if (ent
->addend
== rel
->r_addend
9653 && ent
->plt
.offset
!= (bfd_vma
) -1)
9656 return ppc_stub_plt_call
;
9661 /* Determine where the call point is. */
9662 location
= (input_sec
->output_offset
9663 + input_sec
->output_section
->vma
9666 branch_offset
= destination
- location
;
9667 r_type
= ELF64_R_TYPE (rel
->r_info
);
9669 /* Determine if a long branch stub is needed. */
9670 max_branch_offset
= 1 << 25;
9671 if (r_type
== R_PPC64_REL14
9672 || r_type
== R_PPC64_REL14_BRTAKEN
9673 || r_type
== R_PPC64_REL14_BRNTAKEN
)
9674 max_branch_offset
= 1 << 15;
9676 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
9677 /* We need a stub. Figure out whether a long_branch or plt_branch
9679 return ppc_stub_long_branch
;
9681 return ppc_stub_none
;
9684 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
9685 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
9690 . lis %r12,xxx-1b@highest
9691 . ori %r12,%r12,xxx-1b@higher
9693 . oris %r12,%r12,xxx-1b@high
9694 . ori %r12,%r12,xxx-1b@l
9695 . add/ldx %r12,%r11,%r12 */
9698 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bfd_boolean load
)
9700 bfd_put_32 (abfd
, MFLR_R12
, p
);
9702 bfd_put_32 (abfd
, BCL_20_31
, p
);
9704 bfd_put_32 (abfd
, MFLR_R11
, p
);
9706 bfd_put_32 (abfd
, MTLR_R12
, p
);
9708 if (off
+ 0x8000 < 0x10000)
9711 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
9713 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
9716 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9718 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
9721 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
9723 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
9728 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9730 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
9735 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
9737 if (((off
>> 32) & 0xffff) != 0)
9739 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
9743 if (((off
>> 32) & 0xffffffffULL
) != 0)
9745 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
9748 if (PPC_HI (off
) != 0)
9750 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
9753 if (PPC_LO (off
) != 0)
9755 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
9759 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
9761 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
9768 size_offset (bfd_vma off
)
9771 if (off
+ 0x8000 < 0x10000)
9773 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9777 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9782 if (((off
>> 32) & 0xffff) != 0)
9785 if (((off
>> 32) & 0xffffffffULL
) != 0)
9787 if (PPC_HI (off
) != 0)
9789 if (PPC_LO (off
) != 0)
9797 num_relocs_for_offset (bfd_vma off
)
9799 unsigned int num_rel
;
9800 if (off
+ 0x8000 < 0x10000)
9802 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9807 if (off
+ 0x800000000000ULL
>= 0x1000000000000ULL
9808 && ((off
>> 32) & 0xffff) != 0)
9810 if (PPC_HI (off
) != 0)
9812 if (PPC_LO (off
) != 0)
9818 static Elf_Internal_Rela
*
9819 emit_relocs_for_offset (struct bfd_link_info
*info
, Elf_Internal_Rela
*r
,
9820 bfd_vma roff
, bfd_vma targ
, bfd_vma off
)
9822 bfd_vma relative_targ
= targ
- (roff
- 8);
9823 if (bfd_big_endian (info
->output_bfd
))
9826 r
->r_addend
= relative_targ
+ roff
;
9827 if (off
+ 0x8000 < 0x10000)
9828 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16
);
9829 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9831 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HA
);
9835 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
9836 r
->r_addend
= relative_targ
+ roff
;
9840 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9841 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
9844 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHEST
);
9845 if (((off
>> 32) & 0xffff) != 0)
9850 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGHER
);
9851 r
->r_addend
= relative_targ
+ roff
;
9854 if (((off
>> 32) & 0xffffffffULL
) != 0)
9856 if (PPC_HI (off
) != 0)
9861 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_HIGH
);
9862 r
->r_addend
= relative_targ
+ roff
;
9864 if (PPC_LO (off
) != 0)
9869 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL16_LO
);
9870 r
->r_addend
= relative_targ
+ roff
;
9876 /* Emit .eh_frame opcode to advance pc by DELTA. */
9879 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
9883 *eh
++ = DW_CFA_advance_loc
+ delta
;
9884 else if (delta
< 256)
9886 *eh
++ = DW_CFA_advance_loc1
;
9889 else if (delta
< 65536)
9891 *eh
++ = DW_CFA_advance_loc2
;
9892 bfd_put_16 (abfd
, delta
, eh
);
9897 *eh
++ = DW_CFA_advance_loc4
;
9898 bfd_put_32 (abfd
, delta
, eh
);
9904 /* Size of required .eh_frame opcode to advance pc by DELTA. */
9907 eh_advance_size (unsigned int delta
)
9910 /* DW_CFA_advance_loc+[1..63]. */
9912 if (delta
< 256 * 4)
9913 /* DW_CFA_advance_loc1, byte. */
9915 if (delta
< 65536 * 4)
9916 /* DW_CFA_advance_loc2, 2 bytes. */
9918 /* DW_CFA_advance_loc4, 4 bytes. */
9922 /* With power7 weakly ordered memory model, it is possible for ld.so
9923 to update a plt entry in one thread and have another thread see a
9924 stale zero toc entry. To avoid this we need some sort of acquire
9925 barrier in the call stub. One solution is to make the load of the
9926 toc word seem to appear to depend on the load of the function entry
9927 word. Another solution is to test for r2 being zero, and branch to
9928 the appropriate glink entry if so.
9930 . fake dep barrier compare
9931 . ld 12,xxx(2) ld 12,xxx(2)
9933 . xor 11,12,12 ld 2,xxx+8(2)
9934 . add 2,2,11 cmpldi 2,0
9935 . ld 2,xxx+8(2) bnectr+
9936 . bctr b <glink_entry>
9938 The solution involving the compare turns out to be faster, so
9939 that's what we use unless the branch won't reach. */
9941 #define ALWAYS_USE_FAKE_DEP 0
9942 #define ALWAYS_EMIT_R2SAVE 0
9944 static inline unsigned int
9945 plt_stub_size (struct ppc_link_hash_table
*htab
,
9946 struct ppc_stub_hash_entry
*stub_entry
,
9951 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
9953 size
= 8 + size_offset (off
- 8);
9954 if (stub_entry
->stub_type
> ppc_stub_plt_call_notoc
)
9960 if (ALWAYS_EMIT_R2SAVE
9961 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9963 if (PPC_HA (off
) != 0)
9968 if (htab
->params
->plt_static_chain
)
9970 if (htab
->params
->plt_thread_safe
9971 && htab
->elf
.dynamic_sections_created
9972 && stub_entry
->h
!= NULL
9973 && stub_entry
->h
->elf
.dynindx
!= -1)
9975 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
9978 if (stub_entry
->h
!= NULL
9979 && (stub_entry
->h
== htab
->tls_get_addr_fd
9980 || stub_entry
->h
== htab
->tls_get_addr
)
9981 && htab
->params
->tls_get_addr_opt
)
9984 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9990 /* Depending on the sign of plt_stub_align:
9991 If positive, return the padding to align to a 2**plt_stub_align
9993 If negative, if this stub would cross fewer 2**plt_stub_align
9994 boundaries if we align, then return the padding needed to do so. */
9996 static inline unsigned int
9997 plt_stub_pad (struct ppc_link_hash_table
*htab
,
9998 struct ppc_stub_hash_entry
*stub_entry
,
10002 unsigned stub_size
;
10003 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10005 if (htab
->params
->plt_stub_align
>= 0)
10007 stub_align
= 1 << htab
->params
->plt_stub_align
;
10008 if ((stub_off
& (stub_align
- 1)) != 0)
10009 return stub_align
- (stub_off
& (stub_align
- 1));
10013 stub_align
= 1 << -htab
->params
->plt_stub_align
;
10014 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10015 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10016 > ((stub_size
- 1) & -stub_align
))
10017 return stub_align
- (stub_off
& (stub_align
- 1));
10021 /* Build a .plt call stub. */
10023 static inline bfd_byte
*
10024 build_plt_stub (struct ppc_link_hash_table
*htab
,
10025 struct ppc_stub_hash_entry
*stub_entry
,
10026 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10028 bfd
*obfd
= htab
->params
->stub_bfd
;
10029 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10030 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10031 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10032 && htab
->elf
.dynamic_sections_created
10033 && stub_entry
->h
!= NULL
10034 && stub_entry
->h
->elf
.dynindx
!= -1);
10035 bfd_boolean use_fake_dep
= plt_thread_safe
;
10036 bfd_vma cmp_branch_off
= 0;
10038 if (!ALWAYS_USE_FAKE_DEP
10041 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10042 || stub_entry
->h
== htab
->tls_get_addr
)
10043 && htab
->params
->tls_get_addr_opt
))
10045 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10046 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10047 / PLT_ENTRY_SIZE (htab
));
10048 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
10051 if (pltindex
> 32768)
10052 glinkoff
+= (pltindex
- 32768) * 4;
10054 + htab
->glink
->output_offset
10055 + htab
->glink
->output_section
->vma
);
10056 from
= (p
- stub_entry
->group
->stub_sec
->contents
10057 + 4 * (ALWAYS_EMIT_R2SAVE
10058 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10059 + 4 * (PPC_HA (offset
) != 0)
10060 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10061 != PPC_HA (offset
))
10062 + 4 * (plt_static_chain
!= 0)
10064 + stub_entry
->group
->stub_sec
->output_offset
10065 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10066 cmp_branch_off
= to
- from
;
10067 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10070 if (PPC_HA (offset
) != 0)
10074 if (ALWAYS_EMIT_R2SAVE
10075 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10076 r
[0].r_offset
+= 4;
10077 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10078 r
[1].r_offset
= r
[0].r_offset
+ 4;
10079 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10080 r
[1].r_addend
= r
[0].r_addend
;
10083 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10085 r
[2].r_offset
= r
[1].r_offset
+ 4;
10086 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10087 r
[2].r_addend
= r
[0].r_addend
;
10091 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10092 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10093 r
[2].r_addend
= r
[0].r_addend
+ 8;
10094 if (plt_static_chain
)
10096 r
[3].r_offset
= r
[2].r_offset
+ 4;
10097 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10098 r
[3].r_addend
= r
[0].r_addend
+ 16;
10103 if (ALWAYS_EMIT_R2SAVE
10104 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10105 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10108 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10109 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10113 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10114 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10117 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10119 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10122 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10127 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10128 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10130 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10131 if (plt_static_chain
)
10132 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10139 if (ALWAYS_EMIT_R2SAVE
10140 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10141 r
[0].r_offset
+= 4;
10142 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10145 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10147 r
[1].r_offset
= r
[0].r_offset
+ 4;
10148 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10149 r
[1].r_addend
= r
[0].r_addend
;
10153 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10154 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10155 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10156 if (plt_static_chain
)
10158 r
[2].r_offset
= r
[1].r_offset
+ 4;
10159 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10160 r
[2].r_addend
= r
[0].r_addend
+ 8;
10165 if (ALWAYS_EMIT_R2SAVE
10166 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10167 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10168 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10170 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10172 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
10175 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10180 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
10181 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
10183 if (plt_static_chain
)
10184 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
10185 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
10188 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
10190 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
10191 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
10192 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
10195 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
10199 /* Build a special .plt call stub for __tls_get_addr. */
10201 #define LD_R11_0R3 0xe9630000
10202 #define LD_R12_0R3 0xe9830000
10203 #define MR_R0_R3 0x7c601b78
10204 #define CMPDI_R11_0 0x2c2b0000
10205 #define ADD_R3_R12_R13 0x7c6c6a14
10206 #define BEQLR 0x4d820020
10207 #define MR_R3_R0 0x7c030378
10208 #define STD_R11_0R1 0xf9610000
10209 #define BCTRL 0x4e800421
10210 #define LD_R11_0R1 0xe9610000
10211 #define MTLR_R11 0x7d6803a6
10213 static inline bfd_byte
*
10214 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
10215 struct ppc_stub_hash_entry
*stub_entry
,
10216 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10218 bfd
*obfd
= htab
->params
->stub_bfd
;
10221 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
10222 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
10223 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
10224 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
10225 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
10226 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
10227 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
10229 r
[0].r_offset
+= 7 * 4;
10230 if (stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
10231 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10233 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
10234 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10237 r
[0].r_offset
+= 2 * 4;
10238 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10239 bfd_put_32 (obfd
, BCTRL
, p
- 4);
10241 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10242 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10243 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
10244 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
10246 if (htab
->glink_eh_frame
!= NULL
10247 && htab
->glink_eh_frame
->size
!= 0)
10249 bfd_byte
*base
, *eh
;
10250 unsigned int lr_used
, delta
;
10252 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
10253 eh
= base
+ stub_entry
->group
->eh_size
;
10254 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
10255 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10256 stub_entry
->group
->lr_restore
= lr_used
+ 16;
10257 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
10258 *eh
++ = DW_CFA_offset_extended_sf
;
10260 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
10261 *eh
++ = DW_CFA_advance_loc
+ 4;
10262 *eh
++ = DW_CFA_restore_extended
;
10264 stub_entry
->group
->eh_size
= eh
- base
;
10269 static Elf_Internal_Rela
*
10270 get_relocs (asection
*sec
, int count
)
10272 Elf_Internal_Rela
*relocs
;
10273 struct bfd_elf_section_data
*elfsec_data
;
10275 elfsec_data
= elf_section_data (sec
);
10276 relocs
= elfsec_data
->relocs
;
10277 if (relocs
== NULL
)
10279 bfd_size_type relsize
;
10280 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10281 relocs
= bfd_alloc (sec
->owner
, relsize
);
10282 if (relocs
== NULL
)
10284 elfsec_data
->relocs
= relocs
;
10285 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10286 sizeof (Elf_Internal_Shdr
));
10287 if (elfsec_data
->rela
.hdr
== NULL
)
10289 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10290 * sizeof (Elf64_External_Rela
));
10291 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10292 sec
->reloc_count
= 0;
10294 relocs
+= sec
->reloc_count
;
10295 sec
->reloc_count
+= count
;
10299 /* Convert the relocs R[0] thru R[-NUM_REL+1], which are all no-symbol
10300 forms, to the equivalent relocs against the global symbol given by
10304 use_global_in_relocs (struct ppc_link_hash_table
*htab
,
10305 struct ppc_stub_hash_entry
*stub_entry
,
10306 Elf_Internal_Rela
*r
, unsigned int num_rel
)
10308 struct elf_link_hash_entry
**hashes
;
10309 unsigned long symndx
;
10310 struct ppc_link_hash_entry
*h
;
10313 /* Relocs are always against symbols in their own object file. Fake
10314 up global sym hashes for the stub bfd (which has no symbols). */
10315 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10316 if (hashes
== NULL
)
10318 bfd_size_type hsize
;
10320 /* When called the first time, stub_globals will contain the
10321 total number of symbols seen during stub sizing. After
10322 allocating, stub_globals is used as an index to fill the
10324 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10325 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10326 if (hashes
== NULL
)
10328 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10329 htab
->stub_globals
= 1;
10331 symndx
= htab
->stub_globals
++;
10333 hashes
[symndx
] = &h
->elf
;
10334 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10335 h
= ppc_follow_link (h
->oh
);
10336 BFD_ASSERT (h
->elf
.root
.type
== bfd_link_hash_defined
10337 || h
->elf
.root
.type
== bfd_link_hash_defweak
);
10338 symval
= (h
->elf
.root
.u
.def
.value
10339 + h
->elf
.root
.u
.def
.section
->output_offset
10340 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10341 while (num_rel
-- != 0)
10343 r
->r_info
= ELF64_R_INFO (symndx
, ELF64_R_TYPE (r
->r_info
));
10344 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
10346 /* H is an opd symbol. The addend must be zero, and the
10347 branch reloc is the only one we can convert. */
10352 r
->r_addend
-= symval
;
10359 get_r2off (struct bfd_link_info
*info
,
10360 struct ppc_stub_hash_entry
*stub_entry
)
10362 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10363 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10367 /* Support linking -R objects. Get the toc pointer from the
10370 if (!htab
->opd_abi
)
10372 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10373 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10375 if (strcmp (opd
->name
, ".opd") != 0
10376 || opd
->reloc_count
!= 0)
10378 info
->callbacks
->einfo
10379 (_("%P: cannot find opd entry toc for `%pT'\n"),
10380 stub_entry
->h
->elf
.root
.root
.string
);
10381 bfd_set_error (bfd_error_bad_value
);
10382 return (bfd_vma
) -1;
10384 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10385 return (bfd_vma
) -1;
10386 r2off
= bfd_get_64 (opd
->owner
, buf
);
10387 r2off
-= elf_gp (info
->output_bfd
);
10389 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10394 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10396 struct ppc_stub_hash_entry
*stub_entry
;
10397 struct ppc_branch_hash_entry
*br_entry
;
10398 struct bfd_link_info
*info
;
10399 struct ppc_link_hash_table
*htab
;
10401 bfd_byte
*p
, *relp
;
10403 Elf_Internal_Rela
*r
;
10407 /* Massage our args to the form they really have. */
10408 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10411 htab
= ppc_hash_table (info
);
10415 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
10416 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10418 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10419 switch (stub_entry
->stub_type
)
10421 case ppc_stub_long_branch
:
10422 case ppc_stub_long_branch_r2off
:
10423 /* Branches are relative. This is where we are going to. */
10424 targ
= (stub_entry
->target_value
10425 + stub_entry
->target_section
->output_offset
10426 + stub_entry
->target_section
->output_section
->vma
);
10427 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10429 /* And this is where we are coming from. */
10430 off
= (stub_entry
->stub_offset
10431 + stub_entry
->group
->stub_sec
->output_offset
10432 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10436 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10438 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10440 if (r2off
== (bfd_vma
) -1)
10442 htab
->stub_error
= TRUE
;
10445 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10447 if (PPC_HA (r2off
) != 0)
10449 bfd_put_32 (htab
->params
->stub_bfd
,
10450 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10453 if (PPC_LO (r2off
) != 0)
10455 bfd_put_32 (htab
->params
->stub_bfd
,
10456 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10461 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
10464 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10467 (_("long branch stub `%s' offset overflow"),
10468 stub_entry
->root
.string
);
10469 htab
->stub_error
= TRUE
;
10473 if (info
->emitrelocations
)
10475 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
10478 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
10479 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10480 r
->r_addend
= targ
;
10481 if (stub_entry
->h
!= NULL
10482 && !use_global_in_relocs (htab
, stub_entry
, r
, 1))
10487 case ppc_stub_plt_branch
:
10488 case ppc_stub_plt_branch_r2off
:
10489 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10490 stub_entry
->root
.string
+ 9,
10492 if (br_entry
== NULL
)
10494 _bfd_error_handler (_("can't find branch stub `%s'"),
10495 stub_entry
->root
.string
);
10496 htab
->stub_error
= TRUE
;
10500 targ
= (stub_entry
->target_value
10501 + stub_entry
->target_section
->output_offset
10502 + stub_entry
->target_section
->output_section
->vma
);
10503 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10504 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10506 bfd_put_64 (htab
->brlt
->owner
, targ
,
10507 htab
->brlt
->contents
+ br_entry
->offset
);
10509 if (br_entry
->iter
== htab
->stub_iteration
)
10511 br_entry
->iter
= 0;
10513 if (htab
->relbrlt
!= NULL
)
10515 /* Create a reloc for the branch lookup table entry. */
10516 Elf_Internal_Rela rela
;
10519 rela
.r_offset
= (br_entry
->offset
10520 + htab
->brlt
->output_offset
10521 + htab
->brlt
->output_section
->vma
);
10522 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10523 rela
.r_addend
= targ
;
10525 rl
= htab
->relbrlt
->contents
;
10526 rl
+= (htab
->relbrlt
->reloc_count
++
10527 * sizeof (Elf64_External_Rela
));
10528 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
10530 else if (info
->emitrelocations
)
10532 r
= get_relocs (htab
->brlt
, 1);
10535 /* brlt, being SEC_LINKER_CREATED does not go through the
10536 normal reloc processing. Symbols and offsets are not
10537 translated from input file to output file form, so
10538 set up the offset per the output file. */
10539 r
->r_offset
= (br_entry
->offset
10540 + htab
->brlt
->output_offset
10541 + htab
->brlt
->output_section
->vma
);
10542 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10543 r
->r_addend
= targ
;
10547 targ
= (br_entry
->offset
10548 + htab
->brlt
->output_offset
10549 + htab
->brlt
->output_section
->vma
);
10551 off
= (elf_gp (info
->output_bfd
)
10552 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10555 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10557 info
->callbacks
->einfo
10558 (_("%P: linkage table error against `%pT'\n"),
10559 stub_entry
->root
.string
);
10560 bfd_set_error (bfd_error_bad_value
);
10561 htab
->stub_error
= TRUE
;
10565 if (info
->emitrelocations
)
10567 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
10570 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10571 if (bfd_big_endian (info
->output_bfd
))
10572 r
[0].r_offset
+= 2;
10573 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
10574 r
[0].r_offset
+= 4;
10575 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10576 r
[0].r_addend
= targ
;
10577 if (PPC_HA (off
) != 0)
10579 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10580 r
[1].r_offset
= r
[0].r_offset
+ 4;
10581 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10582 r
[1].r_addend
= r
[0].r_addend
;
10587 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10589 if (PPC_HA (off
) != 0)
10591 bfd_put_32 (htab
->params
->stub_bfd
,
10592 ADDIS_R12_R2
| PPC_HA (off
), p
);
10594 bfd_put_32 (htab
->params
->stub_bfd
,
10595 LD_R12_0R12
| PPC_LO (off
), p
);
10598 bfd_put_32 (htab
->params
->stub_bfd
,
10599 LD_R12_0R2
| PPC_LO (off
), p
);
10603 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10605 if (r2off
== (bfd_vma
) -1)
10607 htab
->stub_error
= TRUE
;
10611 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10613 if (PPC_HA (off
) != 0)
10615 bfd_put_32 (htab
->params
->stub_bfd
,
10616 ADDIS_R12_R2
| PPC_HA (off
), p
);
10618 bfd_put_32 (htab
->params
->stub_bfd
,
10619 LD_R12_0R12
| PPC_LO (off
), p
);
10622 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
10624 if (PPC_HA (r2off
) != 0)
10627 bfd_put_32 (htab
->params
->stub_bfd
,
10628 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10630 if (PPC_LO (r2off
) != 0)
10633 bfd_put_32 (htab
->params
->stub_bfd
,
10634 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10638 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
10640 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
10644 case ppc_stub_long_branch_notoc
:
10645 case ppc_stub_long_branch_both
:
10646 case ppc_stub_plt_branch_notoc
:
10647 case ppc_stub_plt_branch_both
:
10648 case ppc_stub_plt_call_notoc
:
10649 case ppc_stub_plt_call_both
:
10651 off
= (stub_entry
->stub_offset
10652 + stub_entry
->group
->stub_sec
->output_offset
10653 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10654 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
10655 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
10656 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10659 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10662 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
10664 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10665 if (targ
>= (bfd_vma
) -2)
10668 plt
= htab
->elf
.splt
;
10669 if (!htab
->elf
.dynamic_sections_created
10670 || stub_entry
->h
== NULL
10671 || stub_entry
->h
->elf
.dynindx
== -1)
10673 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10674 plt
= htab
->elf
.iplt
;
10676 plt
= htab
->pltlocal
;
10678 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10681 targ
= (stub_entry
->target_value
10682 + stub_entry
->target_section
->output_offset
10683 + stub_entry
->target_section
->output_section
->vma
);
10688 /* The notoc stubs calculate their target (either a PLT entry or
10689 the global entry point of a function) relative to the PC
10690 returned by the "bcl" two instructions past the start of the
10691 sequence emitted by build_offset. The offset is therefore 8
10692 less than calculated from the start of the sequence. */
10694 p
= build_offset (htab
->params
->stub_bfd
, p
, off
,
10695 stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
);
10696 if (stub_entry
->stub_type
<= ppc_stub_long_branch_both
)
10700 from
= (stub_entry
->stub_offset
10701 + stub_entry
->group
->stub_sec
->output_offset
10702 + stub_entry
->group
->stub_sec
->output_section
->vma
10704 bfd_put_32 (htab
->params
->stub_bfd
,
10705 B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
10709 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
10711 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
10715 if (info
->emitrelocations
)
10718 num_rel
+= num_relocs_for_offset (off
);
10719 r
= get_relocs (stub_entry
->group
->stub_sec
, num_rel
);
10722 roff
= relp
+ 16 - stub_entry
->group
->stub_sec
->contents
;
10723 r
= emit_relocs_for_offset (info
, r
, roff
, targ
, off
);
10724 if (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
10725 || stub_entry
->stub_type
== ppc_stub_long_branch_both
)
10728 roff
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
10729 r
->r_offset
= roff
;
10730 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10731 r
->r_addend
= targ
;
10732 if (stub_entry
->h
!= NULL
10733 && !use_global_in_relocs (htab
, stub_entry
, r
, num_rel
))
10738 if (htab
->glink_eh_frame
!= NULL
10739 && htab
->glink_eh_frame
->size
!= 0)
10741 bfd_byte
*base
, *eh
;
10742 unsigned int lr_used
, delta
;
10744 base
= (htab
->glink_eh_frame
->contents
10745 + stub_entry
->group
->eh_base
+ 17);
10746 eh
= base
+ stub_entry
->group
->eh_size
;
10747 lr_used
= stub_entry
->stub_offset
+ 8;
10748 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
10749 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
10750 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10752 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10753 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10754 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
10755 *eh
++ = DW_CFA_register
;
10758 *eh
++ = DW_CFA_advance_loc
+ 2;
10759 *eh
++ = DW_CFA_restore_extended
;
10761 stub_entry
->group
->eh_size
= eh
- base
;
10765 case ppc_stub_plt_call
:
10766 case ppc_stub_plt_call_r2save
:
10767 if (stub_entry
->h
!= NULL
10768 && stub_entry
->h
->is_func_descriptor
10769 && stub_entry
->h
->oh
!= NULL
)
10771 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
10773 /* If the old-ABI "dot-symbol" is undefined make it weak so
10774 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
10775 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
10776 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
10777 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
10778 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
10781 /* Now build the stub. */
10782 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10783 if (targ
>= (bfd_vma
) -2)
10786 plt
= htab
->elf
.splt
;
10787 if (!htab
->elf
.dynamic_sections_created
10788 || stub_entry
->h
== NULL
10789 || stub_entry
->h
->elf
.dynindx
== -1)
10791 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10792 plt
= htab
->elf
.iplt
;
10794 plt
= htab
->pltlocal
;
10796 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10798 off
= (elf_gp (info
->output_bfd
)
10799 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10802 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10804 info
->callbacks
->einfo
10805 /* xgettext:c-format */
10806 (_("%P: linkage table error against `%pT'\n"),
10807 stub_entry
->h
!= NULL
10808 ? stub_entry
->h
->elf
.root
.root
.string
10810 bfd_set_error (bfd_error_bad_value
);
10811 htab
->stub_error
= TRUE
;
10816 if (info
->emitrelocations
)
10818 r
= get_relocs (stub_entry
->group
->stub_sec
,
10819 ((PPC_HA (off
) != 0)
10821 ? 2 + (htab
->params
->plt_static_chain
10822 && PPC_HA (off
+ 16) == PPC_HA (off
))
10826 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10827 if (bfd_big_endian (info
->output_bfd
))
10828 r
[0].r_offset
+= 2;
10829 r
[0].r_addend
= targ
;
10831 if (stub_entry
->h
!= NULL
10832 && (stub_entry
->h
== htab
->tls_get_addr_fd
10833 || stub_entry
->h
== htab
->tls_get_addr
)
10834 && htab
->params
->tls_get_addr_opt
)
10835 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
10837 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
10840 case ppc_stub_save_res
:
10848 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
10850 if (htab
->params
->emit_stub_syms
)
10852 struct elf_link_hash_entry
*h
;
10855 const char *const stub_str
[] = { "long_branch",
10868 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
10869 len2
= strlen (stub_entry
->root
.string
);
10870 name
= bfd_malloc (len1
+ len2
+ 2);
10873 memcpy (name
, stub_entry
->root
.string
, 9);
10874 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
10875 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
10876 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
10879 if (h
->root
.type
== bfd_link_hash_new
)
10881 h
->root
.type
= bfd_link_hash_defined
;
10882 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
10883 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
10884 h
->ref_regular
= 1;
10885 h
->def_regular
= 1;
10886 h
->ref_regular_nonweak
= 1;
10887 h
->forced_local
= 1;
10889 h
->root
.linker_def
= 1;
10896 /* As above, but don't actually build the stub. Just bump offset so
10897 we know stub section sizes, and select plt_branch stubs where
10898 long_branch stubs won't do. */
10901 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10903 struct ppc_stub_hash_entry
*stub_entry
;
10904 struct bfd_link_info
*info
;
10905 struct ppc_link_hash_table
*htab
;
10907 bfd_vma targ
, off
, r2off
;
10908 unsigned int size
, extra
, lr_used
, delta
;
10910 /* Massage our args to the form they really have. */
10911 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10914 htab
= ppc_hash_table (info
);
10918 /* Make a note of the offset within the stubs for this entry. */
10919 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10921 if (stub_entry
->h
!= NULL
10922 && stub_entry
->h
->save_res
10923 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
10924 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
10926 /* Don't make stubs to out-of-line register save/restore
10927 functions. Instead, emit copies of the functions. */
10928 stub_entry
->group
->needs_save_res
= 1;
10929 stub_entry
->stub_type
= ppc_stub_save_res
;
10933 switch (stub_entry
->stub_type
)
10935 case ppc_stub_plt_branch
:
10936 case ppc_stub_plt_branch_r2off
:
10937 /* Reset the stub type from the plt branch variant in case we now
10938 can reach with a shorter stub. */
10939 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
10940 /* Fall through. */
10941 case ppc_stub_long_branch
:
10942 case ppc_stub_long_branch_r2off
:
10943 targ
= (stub_entry
->target_value
10944 + stub_entry
->target_section
->output_offset
10945 + stub_entry
->target_section
->output_section
->vma
);
10946 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10947 off
= (stub_entry
->stub_offset
10948 + stub_entry
->group
->stub_sec
->output_offset
10949 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10953 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10955 r2off
= get_r2off (info
, stub_entry
);
10956 if (r2off
== (bfd_vma
) -1)
10958 htab
->stub_error
= TRUE
;
10962 if (PPC_HA (r2off
) != 0)
10964 if (PPC_LO (r2off
) != 0)
10970 /* If the branch offset is too big, use a ppc_stub_plt_branch.
10971 Do the same for -R objects without function descriptors. */
10972 if ((stub_entry
->stub_type
== ppc_stub_long_branch_r2off
10974 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
10975 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10977 struct ppc_branch_hash_entry
*br_entry
;
10979 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10980 stub_entry
->root
.string
+ 9,
10982 if (br_entry
== NULL
)
10984 _bfd_error_handler (_("can't build branch stub `%s'"),
10985 stub_entry
->root
.string
);
10986 htab
->stub_error
= TRUE
;
10990 if (br_entry
->iter
!= htab
->stub_iteration
)
10992 br_entry
->iter
= htab
->stub_iteration
;
10993 br_entry
->offset
= htab
->brlt
->size
;
10994 htab
->brlt
->size
+= 8;
10996 if (htab
->relbrlt
!= NULL
)
10997 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
10998 else if (info
->emitrelocations
)
11000 htab
->brlt
->reloc_count
+= 1;
11001 htab
->brlt
->flags
|= SEC_RELOC
;
11005 targ
= (br_entry
->offset
11006 + htab
->brlt
->output_offset
11007 + htab
->brlt
->output_section
->vma
);
11008 off
= (elf_gp (info
->output_bfd
)
11009 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11012 if (info
->emitrelocations
)
11014 stub_entry
->group
->stub_sec
->reloc_count
11015 += 1 + (PPC_HA (off
) != 0);
11016 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11019 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11020 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11023 if (PPC_HA (off
) != 0)
11029 if (PPC_HA (off
) != 0)
11032 if (PPC_HA (r2off
) != 0)
11034 if (PPC_LO (r2off
) != 0)
11038 else if (info
->emitrelocations
)
11040 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11041 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11045 case ppc_stub_plt_branch_notoc
:
11046 case ppc_stub_plt_branch_both
:
11047 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11048 /* Fall through. */
11049 case ppc_stub_long_branch_notoc
:
11050 case ppc_stub_long_branch_both
:
11051 off
= (stub_entry
->stub_offset
11052 + stub_entry
->group
->stub_sec
->output_offset
11053 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11055 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
11058 targ
= (stub_entry
->target_value
11059 + stub_entry
->target_section
->output_offset
11060 + stub_entry
->target_section
->output_section
->vma
);
11063 if (info
->emitrelocations
)
11065 stub_entry
->group
->stub_sec
->reloc_count
11066 += num_relocs_for_offset (off
);
11067 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11070 extra
= size_offset (off
- 8);
11071 /* Include branch insn plus those in the offset sequence. */
11073 /* The branch insn is at the end, or "extra" bytes along. So
11074 its offset will be "extra" bytes less that that already
11078 /* After the bcl, lr has been modified so we need to emit
11079 .eh_frame info saying the return address is in r12. */
11080 lr_used
= stub_entry
->stub_offset
+ 8;
11081 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
11083 /* The eh_frame info will consist of a DW_CFA_advance_loc or
11084 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
11085 DW_CFA_restore_extended 65. */
11086 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11087 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
11088 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11090 /* If the branch can't reach, use a plt_branch. */
11091 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11093 stub_entry
->stub_type
+= (ppc_stub_plt_branch_notoc
11094 - ppc_stub_long_branch_notoc
);
11097 else if (info
->emitrelocations
)
11098 stub_entry
->group
->stub_sec
->reloc_count
+=1;
11101 case ppc_stub_plt_call_notoc
:
11102 case ppc_stub_plt_call_both
:
11103 off
= (stub_entry
->stub_offset
11104 + stub_entry
->group
->stub_sec
->output_offset
11105 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11106 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11108 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11109 if (targ
>= (bfd_vma
) -2)
11112 plt
= htab
->elf
.splt
;
11113 if (!htab
->elf
.dynamic_sections_created
11114 || stub_entry
->h
== NULL
11115 || stub_entry
->h
->elf
.dynindx
== -1)
11117 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11118 plt
= htab
->elf
.iplt
;
11120 plt
= htab
->pltlocal
;
11122 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11125 if (htab
->params
->plt_stub_align
!= 0)
11127 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11129 stub_entry
->group
->stub_sec
->size
+= pad
;
11130 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11134 if (info
->emitrelocations
)
11136 stub_entry
->group
->stub_sec
->reloc_count
11137 += num_relocs_for_offset (off
- 8);
11138 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11141 size
= plt_stub_size (htab
, stub_entry
, off
);
11143 /* After the bcl, lr has been modified so we need to emit
11144 .eh_frame info saying the return address is in r12. */
11145 lr_used
= stub_entry
->stub_offset
+ 8;
11146 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
11148 /* The eh_frame info will consist of a DW_CFA_advance_loc or
11149 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
11150 DW_CFA_restore_extended 65. */
11151 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11152 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
11153 stub_entry
->group
->lr_restore
= lr_used
+ 8;
11156 case ppc_stub_plt_call
:
11157 case ppc_stub_plt_call_r2save
:
11158 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11159 if (targ
>= (bfd_vma
) -2)
11161 plt
= htab
->elf
.splt
;
11162 if (!htab
->elf
.dynamic_sections_created
11163 || stub_entry
->h
== NULL
11164 || stub_entry
->h
->elf
.dynindx
== -1)
11166 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11167 plt
= htab
->elf
.iplt
;
11169 plt
= htab
->pltlocal
;
11171 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
11173 off
= (elf_gp (info
->output_bfd
)
11174 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11177 if (htab
->params
->plt_stub_align
!= 0)
11179 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11181 stub_entry
->group
->stub_sec
->size
+= pad
;
11182 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11185 if (info
->emitrelocations
)
11187 stub_entry
->group
->stub_sec
->reloc_count
11188 += ((PPC_HA (off
) != 0)
11190 ? 2 + (htab
->params
->plt_static_chain
11191 && PPC_HA (off
+ 16) == PPC_HA (off
))
11193 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11196 size
= plt_stub_size (htab
, stub_entry
, off
);
11198 if (stub_entry
->h
!= NULL
11199 && (stub_entry
->h
== htab
->tls_get_addr_fd
11200 || stub_entry
->h
== htab
->tls_get_addr
)
11201 && htab
->params
->tls_get_addr_opt
11202 && stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11204 /* After the bctrl, lr has been modified so we need to
11205 emit .eh_frame info saying the return address is
11206 on the stack. In fact we put the EH info specifying
11207 that the return address is on the stack *at* the
11208 call rather than after it, because the EH info for a
11209 call needs to be specified by that point.
11210 See libgcc/unwind-dw2.c execute_cfa_program. */
11211 lr_used
= stub_entry
->stub_offset
+ size
- 20;
11212 /* The eh_frame info will consist of a DW_CFA_advance_loc
11213 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
11214 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
11215 delta
= lr_used
- stub_entry
->group
->lr_restore
;
11216 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
11217 stub_entry
->group
->lr_restore
= size
- 4;
11226 stub_entry
->group
->stub_sec
->size
+= size
;
11230 /* Set up various things so that we can make a list of input sections
11231 for each output section included in the link. Returns -1 on error,
11232 0 when no stubs will be needed, and 1 on success. */
11235 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11239 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11244 htab
->sec_info_arr_size
= _bfd_section_id
;
11245 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11246 htab
->sec_info
= bfd_zmalloc (amt
);
11247 if (htab
->sec_info
== NULL
)
11250 /* Set toc_off for com, und, abs and ind sections. */
11251 for (id
= 0; id
< 3; id
++)
11252 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11257 /* Set up for first pass at multitoc partitioning. */
11260 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11262 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11264 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11265 htab
->toc_bfd
= NULL
;
11266 htab
->toc_first_sec
= NULL
;
11269 /* The linker repeatedly calls this function for each TOC input section
11270 and linker generated GOT section. Group input bfds such that the toc
11271 within a group is less than 64k in size. */
11274 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11276 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11277 bfd_vma addr
, off
, limit
;
11282 if (!htab
->second_toc_pass
)
11284 /* Keep track of the first .toc or .got section for this input bfd. */
11285 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11289 htab
->toc_bfd
= isec
->owner
;
11290 htab
->toc_first_sec
= isec
;
11293 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11294 off
= addr
- htab
->toc_curr
;
11295 limit
= 0x80008000;
11296 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11298 if (off
+ isec
->size
> limit
)
11300 addr
= (htab
->toc_first_sec
->output_offset
11301 + htab
->toc_first_sec
->output_section
->vma
);
11302 htab
->toc_curr
= addr
;
11303 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11306 /* toc_curr is the base address of this toc group. Set elf_gp
11307 for the input section to be the offset relative to the
11308 output toc base plus 0x8000. Making the input elf_gp an
11309 offset allows us to move the toc as a whole without
11310 recalculating input elf_gp. */
11311 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
11312 off
+= TOC_BASE_OFF
;
11314 /* Die if someone uses a linker script that doesn't keep input
11315 file .toc and .got together. */
11317 && elf_gp (isec
->owner
) != 0
11318 && elf_gp (isec
->owner
) != off
)
11321 elf_gp (isec
->owner
) = off
;
11325 /* During the second pass toc_first_sec points to the start of
11326 a toc group, and toc_curr is used to track the old elf_gp.
11327 We use toc_bfd to ensure we only look at each bfd once. */
11328 if (htab
->toc_bfd
== isec
->owner
)
11330 htab
->toc_bfd
= isec
->owner
;
11332 if (htab
->toc_first_sec
== NULL
11333 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11335 htab
->toc_curr
= elf_gp (isec
->owner
);
11336 htab
->toc_first_sec
= isec
;
11338 addr
= (htab
->toc_first_sec
->output_offset
11339 + htab
->toc_first_sec
->output_section
->vma
);
11340 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
11341 elf_gp (isec
->owner
) = off
;
11346 /* Called via elf_link_hash_traverse to merge GOT entries for global
11350 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11352 if (h
->root
.type
== bfd_link_hash_indirect
)
11355 merge_got_entries (&h
->got
.glist
);
11360 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11364 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11366 struct got_entry
*gent
;
11368 if (h
->root
.type
== bfd_link_hash_indirect
)
11371 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11372 if (!gent
->is_indirect
)
11373 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11377 /* Called on the first multitoc pass after the last call to
11378 ppc64_elf_next_toc_section. This function removes duplicate GOT
11382 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11384 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11385 struct bfd
*ibfd
, *ibfd2
;
11386 bfd_boolean done_something
;
11388 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11390 if (!htab
->do_multi_toc
)
11393 /* Merge global sym got entries within a toc group. */
11394 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11396 /* And tlsld_got. */
11397 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11399 struct got_entry
*ent
, *ent2
;
11401 if (!is_ppc64_elf (ibfd
))
11404 ent
= ppc64_tlsld_got (ibfd
);
11405 if (!ent
->is_indirect
11406 && ent
->got
.offset
!= (bfd_vma
) -1)
11408 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11410 if (!is_ppc64_elf (ibfd2
))
11413 ent2
= ppc64_tlsld_got (ibfd2
);
11414 if (!ent2
->is_indirect
11415 && ent2
->got
.offset
!= (bfd_vma
) -1
11416 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11418 ent2
->is_indirect
= TRUE
;
11419 ent2
->got
.ent
= ent
;
11425 /* Zap sizes of got sections. */
11426 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11427 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11428 htab
->got_reli_size
= 0;
11430 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11432 asection
*got
, *relgot
;
11434 if (!is_ppc64_elf (ibfd
))
11437 got
= ppc64_elf_tdata (ibfd
)->got
;
11440 got
->rawsize
= got
->size
;
11442 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11443 relgot
->rawsize
= relgot
->size
;
11448 /* Now reallocate the got, local syms first. We don't need to
11449 allocate section contents again since we never increase size. */
11450 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11452 struct got_entry
**lgot_ents
;
11453 struct got_entry
**end_lgot_ents
;
11454 struct plt_entry
**local_plt
;
11455 struct plt_entry
**end_local_plt
;
11456 unsigned char *lgot_masks
;
11457 bfd_size_type locsymcount
;
11458 Elf_Internal_Shdr
*symtab_hdr
;
11461 if (!is_ppc64_elf (ibfd
))
11464 lgot_ents
= elf_local_got_ents (ibfd
);
11468 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11469 locsymcount
= symtab_hdr
->sh_info
;
11470 end_lgot_ents
= lgot_ents
+ locsymcount
;
11471 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11472 end_local_plt
= local_plt
+ locsymcount
;
11473 lgot_masks
= (unsigned char *) end_local_plt
;
11474 s
= ppc64_elf_tdata (ibfd
)->got
;
11475 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11477 struct got_entry
*ent
;
11479 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11481 unsigned int ent_size
= 8;
11482 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11484 ent
->got
.offset
= s
->size
;
11485 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11490 s
->size
+= ent_size
;
11491 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
11493 htab
->elf
.irelplt
->size
+= rel_size
;
11494 htab
->got_reli_size
+= rel_size
;
11496 else if (bfd_link_pic (info
)
11497 && !((ent
->tls_type
& TLS_TPREL
) != 0
11498 && bfd_link_executable (info
)))
11500 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11501 srel
->size
+= rel_size
;
11507 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11509 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11511 struct got_entry
*ent
;
11513 if (!is_ppc64_elf (ibfd
))
11516 ent
= ppc64_tlsld_got (ibfd
);
11517 if (!ent
->is_indirect
11518 && ent
->got
.offset
!= (bfd_vma
) -1)
11520 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11521 ent
->got
.offset
= s
->size
;
11523 if (bfd_link_pic (info
))
11525 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11526 srel
->size
+= sizeof (Elf64_External_Rela
);
11531 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11532 if (!done_something
)
11533 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11537 if (!is_ppc64_elf (ibfd
))
11540 got
= ppc64_elf_tdata (ibfd
)->got
;
11543 done_something
= got
->rawsize
!= got
->size
;
11544 if (done_something
)
11549 if (done_something
)
11550 (*htab
->params
->layout_sections_again
) ();
11552 /* Set up for second pass over toc sections to recalculate elf_gp
11553 on input sections. */
11554 htab
->toc_bfd
= NULL
;
11555 htab
->toc_first_sec
= NULL
;
11556 htab
->second_toc_pass
= TRUE
;
11557 return done_something
;
11560 /* Called after second pass of multitoc partitioning. */
11563 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11565 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11567 /* After the second pass, toc_curr tracks the TOC offset used
11568 for code sections below in ppc64_elf_next_input_section. */
11569 htab
->toc_curr
= TOC_BASE_OFF
;
11572 /* No toc references were found in ISEC. If the code in ISEC makes no
11573 calls, then there's no need to use toc adjusting stubs when branching
11574 into ISEC. Actually, indirect calls from ISEC are OK as they will
11575 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11576 needed, and 2 if a cyclical call-graph was found but no other reason
11577 for a stub was detected. If called from the top level, a return of
11578 2 means the same as a return of 0. */
11581 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11585 /* Mark this section as checked. */
11586 isec
->call_check_done
= 1;
11588 /* We know none of our code bearing sections will need toc stubs. */
11589 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11592 if (isec
->size
== 0)
11595 if (isec
->output_section
== NULL
)
11599 if (isec
->reloc_count
!= 0)
11601 Elf_Internal_Rela
*relstart
, *rel
;
11602 Elf_Internal_Sym
*local_syms
;
11603 struct ppc_link_hash_table
*htab
;
11605 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11606 info
->keep_memory
);
11607 if (relstart
== NULL
)
11610 /* Look for branches to outside of this section. */
11612 htab
= ppc_hash_table (info
);
11616 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11618 enum elf_ppc64_reloc_type r_type
;
11619 unsigned long r_symndx
;
11620 struct elf_link_hash_entry
*h
;
11621 struct ppc_link_hash_entry
*eh
;
11622 Elf_Internal_Sym
*sym
;
11624 struct _opd_sec_data
*opd
;
11628 r_type
= ELF64_R_TYPE (rel
->r_info
);
11629 if (r_type
!= R_PPC64_REL24
11630 && r_type
!= R_PPC64_REL24_NOTOC
11631 && r_type
!= R_PPC64_REL14
11632 && r_type
!= R_PPC64_REL14_BRTAKEN
11633 && r_type
!= R_PPC64_REL14_BRNTAKEN
11634 && r_type
!= R_PPC64_PLTCALL
)
11637 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11638 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11645 /* Calls to dynamic lib functions go through a plt call stub
11647 eh
= (struct ppc_link_hash_entry
*) h
;
11649 && (eh
->elf
.plt
.plist
!= NULL
11651 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
11657 if (sym_sec
== NULL
)
11658 /* Ignore other undefined symbols. */
11661 /* Assume branches to other sections not included in the
11662 link need stubs too, to cover -R and absolute syms. */
11663 if (sym_sec
->output_section
== NULL
)
11670 sym_value
= sym
->st_value
;
11673 if (h
->root
.type
!= bfd_link_hash_defined
11674 && h
->root
.type
!= bfd_link_hash_defweak
)
11676 sym_value
= h
->root
.u
.def
.value
;
11678 sym_value
+= rel
->r_addend
;
11680 /* If this branch reloc uses an opd sym, find the code section. */
11681 opd
= get_opd_info (sym_sec
);
11684 if (h
== NULL
&& opd
->adjust
!= NULL
)
11688 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11690 /* Assume deleted functions won't ever be called. */
11692 sym_value
+= adjust
;
11695 dest
= opd_entry_value (sym_sec
, sym_value
,
11696 &sym_sec
, NULL
, FALSE
);
11697 if (dest
== (bfd_vma
) -1)
11702 + sym_sec
->output_offset
11703 + sym_sec
->output_section
->vma
);
11705 /* Ignore branch to self. */
11706 if (sym_sec
== isec
)
11709 /* If the called function uses the toc, we need a stub. */
11710 if (sym_sec
->has_toc_reloc
11711 || sym_sec
->makes_toc_func_call
)
11717 /* Assume any branch that needs a long branch stub might in fact
11718 need a plt_branch stub. A plt_branch stub uses r2. */
11719 else if (dest
- (isec
->output_offset
11720 + isec
->output_section
->vma
11721 + rel
->r_offset
) + (1 << 25)
11722 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11730 /* If calling back to a section in the process of being
11731 tested, we can't say for sure that no toc adjusting stubs
11732 are needed, so don't return zero. */
11733 else if (sym_sec
->call_check_in_progress
)
11736 /* Branches to another section that itself doesn't have any TOC
11737 references are OK. Recursively call ourselves to check. */
11738 else if (!sym_sec
->call_check_done
)
11742 /* Mark current section as indeterminate, so that other
11743 sections that call back to current won't be marked as
11745 isec
->call_check_in_progress
= 1;
11746 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
11747 isec
->call_check_in_progress
= 0;
11758 if (local_syms
!= NULL
11759 && (elf_symtab_hdr (isec
->owner
).contents
11760 != (unsigned char *) local_syms
))
11762 if (elf_section_data (isec
)->relocs
!= relstart
)
11767 && isec
->map_head
.s
!= NULL
11768 && (strcmp (isec
->output_section
->name
, ".init") == 0
11769 || strcmp (isec
->output_section
->name
, ".fini") == 0))
11771 if (isec
->map_head
.s
->has_toc_reloc
11772 || isec
->map_head
.s
->makes_toc_func_call
)
11774 else if (!isec
->map_head
.s
->call_check_done
)
11777 isec
->call_check_in_progress
= 1;
11778 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
11779 isec
->call_check_in_progress
= 0;
11786 isec
->makes_toc_func_call
= 1;
11791 /* The linker repeatedly calls this function for each input section,
11792 in the order that input sections are linked into output sections.
11793 Build lists of input sections to determine groupings between which
11794 we may insert linker stubs. */
11797 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
11799 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11804 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
11805 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
11807 /* This happens to make the list in reverse order,
11808 which is what we want. */
11809 htab
->sec_info
[isec
->id
].u
.list
11810 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
11811 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
11814 if (htab
->multi_toc_needed
)
11816 /* Analyse sections that aren't already flagged as needing a
11817 valid toc pointer. Exclude .fixup for the linux kernel.
11818 .fixup contains branches, but only back to the function that
11819 hit an exception. */
11820 if (!(isec
->has_toc_reloc
11821 || (isec
->flags
& SEC_CODE
) == 0
11822 || strcmp (isec
->name
, ".fixup") == 0
11823 || isec
->call_check_done
))
11825 if (toc_adjusting_stub_needed (info
, isec
) < 0)
11828 /* Make all sections use the TOC assigned for this object file.
11829 This will be wrong for pasted sections; We fix that in
11830 check_pasted_section(). */
11831 if (elf_gp (isec
->owner
) != 0)
11832 htab
->toc_curr
= elf_gp (isec
->owner
);
11835 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
11839 /* Check that all .init and .fini sections use the same toc, if they
11840 have toc relocs. */
11843 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
11845 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
11849 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11850 bfd_vma toc_off
= 0;
11853 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11854 if (i
->has_toc_reloc
)
11857 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11858 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
11863 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11864 if (i
->makes_toc_func_call
)
11866 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11870 /* Make sure the whole pasted function uses the same toc offset. */
11872 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11873 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
11879 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
11881 return (check_pasted_section (info
, ".init")
11882 & check_pasted_section (info
, ".fini"));
11885 /* See whether we can group stub sections together. Grouping stub
11886 sections may result in fewer stubs. More importantly, we need to
11887 put all .init* and .fini* stubs at the beginning of the .init or
11888 .fini output sections respectively, because glibc splits the
11889 _init and _fini functions into multiple parts. Putting a stub in
11890 the middle of a function is not a good idea. */
11893 group_sections (struct bfd_link_info
*info
,
11894 bfd_size_type stub_group_size
,
11895 bfd_boolean stubs_always_before_branch
)
11897 struct ppc_link_hash_table
*htab
;
11899 bfd_boolean suppress_size_errors
;
11901 htab
= ppc_hash_table (info
);
11905 suppress_size_errors
= FALSE
;
11906 if (stub_group_size
== 1)
11908 /* Default values. */
11909 if (stubs_always_before_branch
)
11910 stub_group_size
= 0x1e00000;
11912 stub_group_size
= 0x1c00000;
11913 suppress_size_errors
= TRUE
;
11916 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
11920 if (osec
->id
>= htab
->sec_info_arr_size
)
11923 tail
= htab
->sec_info
[osec
->id
].u
.list
;
11924 while (tail
!= NULL
)
11928 bfd_size_type total
;
11929 bfd_boolean big_sec
;
11931 struct map_stub
*group
;
11932 bfd_size_type group_size
;
11935 total
= tail
->size
;
11936 group_size
= (ppc64_elf_section_data (tail
) != NULL
11937 && ppc64_elf_section_data (tail
)->has_14bit_branch
11938 ? stub_group_size
>> 10 : stub_group_size
);
11940 big_sec
= total
> group_size
;
11941 if (big_sec
&& !suppress_size_errors
)
11942 /* xgettext:c-format */
11943 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
11944 tail
->owner
, tail
);
11945 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
11947 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
11948 && ((total
+= curr
->output_offset
- prev
->output_offset
)
11949 < (ppc64_elf_section_data (prev
) != NULL
11950 && ppc64_elf_section_data (prev
)->has_14bit_branch
11951 ? (group_size
= stub_group_size
>> 10) : group_size
))
11952 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
11955 /* OK, the size from the start of CURR to the end is less
11956 than group_size and thus can be handled by one stub
11957 section. (or the tail section is itself larger than
11958 group_size, in which case we may be toast.) We should
11959 really be keeping track of the total size of stubs added
11960 here, as stubs contribute to the final output section
11961 size. That's a little tricky, and this way will only
11962 break if stubs added make the total size more than 2^25,
11963 ie. for the default stub_group_size, if stubs total more
11964 than 2097152 bytes, or nearly 75000 plt call stubs. */
11965 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
11968 group
->link_sec
= curr
;
11969 group
->stub_sec
= NULL
;
11970 group
->needs_save_res
= 0;
11971 group
->lr_restore
= 0;
11972 group
->eh_size
= 0;
11973 group
->eh_base
= 0;
11974 group
->next
= htab
->group
;
11975 htab
->group
= group
;
11978 prev
= htab
->sec_info
[tail
->id
].u
.list
;
11979 /* Set up this stub group. */
11980 htab
->sec_info
[tail
->id
].u
.group
= group
;
11982 while (tail
!= curr
&& (tail
= prev
) != NULL
);
11984 /* But wait, there's more! Input sections up to group_size
11985 bytes before the stub section can be handled by it too.
11986 Don't do this if we have a really large section after the
11987 stubs, as adding more stubs increases the chance that
11988 branches may not reach into the stub section. */
11989 if (!stubs_always_before_branch
&& !big_sec
)
11992 while (prev
!= NULL
11993 && ((total
+= tail
->output_offset
- prev
->output_offset
)
11994 < (ppc64_elf_section_data (prev
) != NULL
11995 && ppc64_elf_section_data (prev
)->has_14bit_branch
11996 ? (group_size
= stub_group_size
>> 10)
11998 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12001 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12002 htab
->sec_info
[tail
->id
].u
.group
= group
;
12011 static const unsigned char glink_eh_frame_cie
[] =
12013 0, 0, 0, 16, /* length. */
12014 0, 0, 0, 0, /* id. */
12015 1, /* CIE version. */
12016 'z', 'R', 0, /* Augmentation string. */
12017 4, /* Code alignment. */
12018 0x78, /* Data alignment. */
12020 1, /* Augmentation size. */
12021 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12022 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
12025 /* Stripping output sections is normally done before dynamic section
12026 symbols have been allocated. This function is called later, and
12027 handles cases like htab->brlt which is mapped to its own output
12031 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12033 if (isec
->size
== 0
12034 && isec
->output_section
->size
== 0
12035 && !(isec
->output_section
->flags
& SEC_KEEP
)
12036 && !bfd_section_removed_from_list (info
->output_bfd
,
12037 isec
->output_section
)
12038 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12040 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12041 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12042 info
->output_bfd
->section_count
--;
12046 /* Determine and set the size of the stub section for a final link.
12048 The basic idea here is to examine all the relocations looking for
12049 PC-relative calls to a target that is unreachable with a "bl"
12053 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12055 bfd_size_type stub_group_size
;
12056 bfd_boolean stubs_always_before_branch
;
12057 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12062 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12063 htab
->params
->plt_thread_safe
= 1;
12064 if (!htab
->opd_abi
)
12065 htab
->params
->plt_thread_safe
= 0;
12066 else if (htab
->params
->plt_thread_safe
== -1)
12068 static const char *const thread_starter
[] =
12072 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12074 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12075 "mq_notify", "create_timer",
12080 "GOMP_parallel_start",
12081 "GOMP_parallel_loop_static",
12082 "GOMP_parallel_loop_static_start",
12083 "GOMP_parallel_loop_dynamic",
12084 "GOMP_parallel_loop_dynamic_start",
12085 "GOMP_parallel_loop_guided",
12086 "GOMP_parallel_loop_guided_start",
12087 "GOMP_parallel_loop_runtime",
12088 "GOMP_parallel_loop_runtime_start",
12089 "GOMP_parallel_sections",
12090 "GOMP_parallel_sections_start",
12096 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12098 struct elf_link_hash_entry
*h
;
12099 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12100 FALSE
, FALSE
, TRUE
);
12101 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12102 if (htab
->params
->plt_thread_safe
)
12106 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12107 if (htab
->params
->group_size
< 0)
12108 stub_group_size
= -htab
->params
->group_size
;
12110 stub_group_size
= htab
->params
->group_size
;
12112 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12115 #define STUB_SHRINK_ITER 20
12116 /* Loop until no stubs added. After iteration 20 of this loop we may
12117 exit on a stub section shrinking. This is to break out of a
12118 pathological case where adding stubs on one iteration decreases
12119 section gaps (perhaps due to alignment), which then requires
12120 fewer or smaller stubs on the next iteration. */
12125 unsigned int bfd_indx
;
12126 struct map_stub
*group
;
12128 htab
->stub_iteration
+= 1;
12130 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12132 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12134 Elf_Internal_Shdr
*symtab_hdr
;
12136 Elf_Internal_Sym
*local_syms
= NULL
;
12138 if (!is_ppc64_elf (input_bfd
))
12141 /* We'll need the symbol table in a second. */
12142 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12143 if (symtab_hdr
->sh_info
== 0)
12146 /* Walk over each section attached to the input bfd. */
12147 for (section
= input_bfd
->sections
;
12149 section
= section
->next
)
12151 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12153 /* If there aren't any relocs, then there's nothing more
12155 if ((section
->flags
& SEC_RELOC
) == 0
12156 || (section
->flags
& SEC_ALLOC
) == 0
12157 || (section
->flags
& SEC_LOAD
) == 0
12158 || (section
->flags
& SEC_CODE
) == 0
12159 || section
->reloc_count
== 0)
12162 /* If this section is a link-once section that will be
12163 discarded, then don't create any stubs. */
12164 if (section
->output_section
== NULL
12165 || section
->output_section
->owner
!= info
->output_bfd
)
12168 /* Get the relocs. */
12170 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12171 info
->keep_memory
);
12172 if (internal_relocs
== NULL
)
12173 goto error_ret_free_local
;
12175 /* Now examine each relocation. */
12176 irela
= internal_relocs
;
12177 irelaend
= irela
+ section
->reloc_count
;
12178 for (; irela
< irelaend
; irela
++)
12180 enum elf_ppc64_reloc_type r_type
;
12181 unsigned int r_indx
;
12182 enum ppc_stub_type stub_type
;
12183 struct ppc_stub_hash_entry
*stub_entry
;
12184 asection
*sym_sec
, *code_sec
;
12185 bfd_vma sym_value
, code_value
;
12186 bfd_vma destination
;
12187 unsigned long local_off
;
12188 bfd_boolean ok_dest
;
12189 struct ppc_link_hash_entry
*hash
;
12190 struct ppc_link_hash_entry
*fdh
;
12191 struct elf_link_hash_entry
*h
;
12192 Elf_Internal_Sym
*sym
;
12194 const asection
*id_sec
;
12195 struct _opd_sec_data
*opd
;
12196 struct plt_entry
*plt_ent
;
12198 r_type
= ELF64_R_TYPE (irela
->r_info
);
12199 r_indx
= ELF64_R_SYM (irela
->r_info
);
12201 if (r_type
>= R_PPC64_max
)
12203 bfd_set_error (bfd_error_bad_value
);
12204 goto error_ret_free_internal
;
12207 /* Only look for stubs on branch instructions. */
12208 if (r_type
!= R_PPC64_REL24
12209 && r_type
!= R_PPC64_REL24_NOTOC
12210 && r_type
!= R_PPC64_REL14
12211 && r_type
!= R_PPC64_REL14_BRTAKEN
12212 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12215 /* Now determine the call target, its name, value,
12217 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12218 r_indx
, input_bfd
))
12219 goto error_ret_free_internal
;
12220 hash
= (struct ppc_link_hash_entry
*) h
;
12227 sym_value
= sym
->st_value
;
12228 if (sym_sec
!= NULL
12229 && sym_sec
->output_section
!= NULL
)
12232 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12233 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12235 sym_value
= hash
->elf
.root
.u
.def
.value
;
12236 if (sym_sec
->output_section
!= NULL
)
12239 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12240 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12242 /* Recognise an old ABI func code entry sym, and
12243 use the func descriptor sym instead if it is
12245 if (hash
->elf
.root
.root
.string
[0] == '.'
12246 && hash
->oh
!= NULL
)
12248 fdh
= ppc_follow_link (hash
->oh
);
12249 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12250 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12252 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12253 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12254 if (sym_sec
->output_section
!= NULL
)
12263 bfd_set_error (bfd_error_bad_value
);
12264 goto error_ret_free_internal
;
12271 sym_value
+= irela
->r_addend
;
12272 destination
= (sym_value
12273 + sym_sec
->output_offset
12274 + sym_sec
->output_section
->vma
);
12275 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12280 code_sec
= sym_sec
;
12281 code_value
= sym_value
;
12282 opd
= get_opd_info (sym_sec
);
12287 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12289 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12292 code_value
+= adjust
;
12293 sym_value
+= adjust
;
12295 dest
= opd_entry_value (sym_sec
, sym_value
,
12296 &code_sec
, &code_value
, FALSE
);
12297 if (dest
!= (bfd_vma
) -1)
12299 destination
= dest
;
12302 /* Fixup old ABI sym to point at code
12304 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12305 hash
->elf
.root
.u
.def
.section
= code_sec
;
12306 hash
->elf
.root
.u
.def
.value
= code_value
;
12311 /* Determine what (if any) linker stub is needed. */
12313 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
12314 &plt_ent
, destination
,
12317 if (r_type
== R_PPC64_REL24_NOTOC
)
12319 if (stub_type
== ppc_stub_plt_call
)
12320 stub_type
= ppc_stub_plt_call_notoc
;
12321 else if (stub_type
== ppc_stub_long_branch
12322 || (code_sec
!= NULL
12323 && code_sec
->output_section
!= NULL
12324 && (((hash
? hash
->elf
.other
: sym
->st_other
)
12325 & STO_PPC64_LOCAL_MASK
)
12326 != 1 << STO_PPC64_LOCAL_BIT
)))
12327 stub_type
= ppc_stub_long_branch_notoc
;
12329 else if (stub_type
!= ppc_stub_plt_call
)
12331 /* Check whether we need a TOC adjusting stub.
12332 Since the linker pastes together pieces from
12333 different object files when creating the
12334 _init and _fini functions, it may be that a
12335 call to what looks like a local sym is in
12336 fact a call needing a TOC adjustment. */
12337 if ((code_sec
!= NULL
12338 && code_sec
->output_section
!= NULL
12339 && (htab
->sec_info
[code_sec
->id
].toc_off
12340 != htab
->sec_info
[section
->id
].toc_off
)
12341 && (code_sec
->has_toc_reloc
12342 || code_sec
->makes_toc_func_call
))
12343 || (((hash
? hash
->elf
.other
: sym
->st_other
)
12344 & STO_PPC64_LOCAL_MASK
)
12345 == 1 << STO_PPC64_LOCAL_BIT
))
12346 stub_type
= ppc_stub_long_branch_r2off
;
12349 if (stub_type
== ppc_stub_none
)
12352 /* __tls_get_addr calls might be eliminated. */
12353 if (stub_type
!= ppc_stub_plt_call
12354 && stub_type
!= ppc_stub_plt_call_notoc
12356 && (hash
== htab
->tls_get_addr
12357 || hash
== htab
->tls_get_addr_fd
)
12358 && section
->has_tls_reloc
12359 && irela
!= internal_relocs
)
12361 /* Get tls info. */
12362 unsigned char *tls_mask
;
12364 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12365 irela
- 1, input_bfd
))
12366 goto error_ret_free_internal
;
12367 if ((*tls_mask
& TLS_TLS
) != 0)
12371 if (stub_type
== ppc_stub_plt_call
)
12374 && htab
->params
->plt_localentry0
!= 0
12375 && is_elfv2_localentry0 (&hash
->elf
))
12376 htab
->has_plt_localentry0
= 1;
12377 else if (irela
+ 1 < irelaend
12378 && irela
[1].r_offset
== irela
->r_offset
+ 4
12379 && (ELF64_R_TYPE (irela
[1].r_info
)
12380 == R_PPC64_TOCSAVE
))
12382 if (!tocsave_find (htab
, INSERT
,
12383 &local_syms
, irela
+ 1, input_bfd
))
12384 goto error_ret_free_internal
;
12387 stub_type
= ppc_stub_plt_call_r2save
;
12390 /* Support for grouping stub sections. */
12391 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12393 /* Get the name of this stub. */
12394 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12396 goto error_ret_free_internal
;
12398 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12399 stub_name
, FALSE
, FALSE
);
12400 if (stub_entry
!= NULL
)
12402 enum ppc_stub_type old_type
;
12403 /* A stub has already been created, but it may
12404 not be the required type. We shouldn't be
12405 transitioning from plt_call to long_branch
12406 stubs or vice versa, but we might be
12407 upgrading from plt_call to plt_call_r2save or
12408 from long_branch to long_branch_r2off. */
12410 old_type
= stub_entry
->stub_type
;
12416 case ppc_stub_save_res
:
12419 case ppc_stub_plt_call
:
12420 case ppc_stub_plt_call_r2save
:
12421 case ppc_stub_plt_call_notoc
:
12422 case ppc_stub_plt_call_both
:
12423 if (stub_type
== ppc_stub_plt_call
)
12425 else if (stub_type
== ppc_stub_plt_call_r2save
)
12427 if (old_type
== ppc_stub_plt_call_notoc
)
12428 stub_type
= ppc_stub_plt_call_both
;
12430 else if (stub_type
== ppc_stub_plt_call_notoc
)
12432 if (old_type
== ppc_stub_plt_call_r2save
)
12433 stub_type
= ppc_stub_plt_call_both
;
12439 case ppc_stub_plt_branch
:
12440 case ppc_stub_plt_branch_r2off
:
12441 case ppc_stub_plt_branch_notoc
:
12442 case ppc_stub_plt_branch_both
:
12443 old_type
+= (ppc_stub_long_branch
12444 - ppc_stub_plt_branch
);
12445 /* Fall through. */
12446 case ppc_stub_long_branch
:
12447 case ppc_stub_long_branch_r2off
:
12448 case ppc_stub_long_branch_notoc
:
12449 case ppc_stub_long_branch_both
:
12450 if (stub_type
== ppc_stub_long_branch
)
12452 else if (stub_type
== ppc_stub_long_branch_r2off
)
12454 if (old_type
== ppc_stub_long_branch_notoc
)
12455 stub_type
= ppc_stub_long_branch_both
;
12457 else if (stub_type
== ppc_stub_long_branch_notoc
)
12459 if (old_type
== ppc_stub_long_branch_r2off
)
12460 stub_type
= ppc_stub_long_branch_both
;
12466 if (old_type
< stub_type
)
12467 stub_entry
->stub_type
= stub_type
;
12471 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12472 if (stub_entry
== NULL
)
12475 error_ret_free_internal
:
12476 if (elf_section_data (section
)->relocs
== NULL
)
12477 free (internal_relocs
);
12478 error_ret_free_local
:
12479 if (local_syms
!= NULL
12480 && (symtab_hdr
->contents
12481 != (unsigned char *) local_syms
))
12486 stub_entry
->stub_type
= stub_type
;
12487 if (stub_type
>= ppc_stub_plt_call
12488 && stub_type
<= ppc_stub_plt_call_both
)
12490 stub_entry
->target_value
= sym_value
;
12491 stub_entry
->target_section
= sym_sec
;
12495 stub_entry
->target_value
= code_value
;
12496 stub_entry
->target_section
= code_sec
;
12498 stub_entry
->h
= hash
;
12499 stub_entry
->plt_ent
= plt_ent
;
12500 stub_entry
->symtype
12501 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
12502 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12505 && (hash
->elf
.root
.type
== bfd_link_hash_defined
12506 || hash
->elf
.root
.type
== bfd_link_hash_defweak
))
12507 htab
->stub_globals
+= 1;
12510 /* We're done with the internal relocs, free them. */
12511 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12512 free (internal_relocs
);
12515 if (local_syms
!= NULL
12516 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12518 if (!info
->keep_memory
)
12521 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12525 /* We may have added some stubs. Find out the new size of the
12527 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12529 group
->lr_restore
= 0;
12530 group
->eh_size
= 0;
12531 if (group
->stub_sec
!= NULL
)
12533 asection
*stub_sec
= group
->stub_sec
;
12535 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12536 || stub_sec
->rawsize
< stub_sec
->size
)
12537 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12538 stub_sec
->rawsize
= stub_sec
->size
;
12539 stub_sec
->size
= 0;
12540 stub_sec
->reloc_count
= 0;
12541 stub_sec
->flags
&= ~SEC_RELOC
;
12545 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12546 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
12547 htab
->brlt
->rawsize
= htab
->brlt
->size
;
12548 htab
->brlt
->size
= 0;
12549 htab
->brlt
->reloc_count
= 0;
12550 htab
->brlt
->flags
&= ~SEC_RELOC
;
12551 if (htab
->relbrlt
!= NULL
)
12552 htab
->relbrlt
->size
= 0;
12554 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12556 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12557 if (group
->needs_save_res
)
12558 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12560 if (info
->emitrelocations
12561 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12563 htab
->glink
->reloc_count
= 1;
12564 htab
->glink
->flags
|= SEC_RELOC
;
12567 if (htab
->glink_eh_frame
!= NULL
12568 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12569 && htab
->glink_eh_frame
->output_section
->size
> 8)
12571 size_t size
= 0, align
= 4;
12573 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12574 if (group
->eh_size
!= 0)
12575 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
12576 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12577 size
+= (24 + align
- 1) & -align
;
12579 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
12580 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12581 size
= (size
+ align
- 1) & -align
;
12582 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12583 htab
->glink_eh_frame
->size
= size
;
12586 if (htab
->params
->plt_stub_align
!= 0)
12587 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12588 if (group
->stub_sec
!= NULL
)
12590 int align
= abs (htab
->params
->plt_stub_align
);
12591 group
->stub_sec
->size
12592 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12595 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12596 if (group
->stub_sec
!= NULL
12597 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
12598 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
12599 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
12603 && (htab
->brlt
->rawsize
== htab
->brlt
->size
12604 || (htab
->stub_iteration
> STUB_SHRINK_ITER
12605 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
12606 && (htab
->glink_eh_frame
== NULL
12607 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12610 /* Ask the linker to do its stuff. */
12611 (*htab
->params
->layout_sections_again
) ();
12614 if (htab
->glink_eh_frame
!= NULL
12615 && htab
->glink_eh_frame
->size
!= 0)
12618 bfd_byte
*p
, *last_fde
;
12619 size_t last_fde_len
, size
, align
, pad
;
12620 struct map_stub
*group
;
12622 /* It is necessary to at least have a rough outline of the
12623 linker generated CIEs and FDEs written before
12624 bfd_elf_discard_info is run, in order for these FDEs to be
12625 indexed in .eh_frame_hdr. */
12626 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12629 htab
->glink_eh_frame
->contents
= p
;
12633 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12634 /* CIE length (rewrite in case little-endian). */
12635 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
12636 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12637 p
+= last_fde_len
+ 4;
12639 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12640 if (group
->eh_size
!= 0)
12642 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
12644 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
12646 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12649 val
= p
- htab
->glink_eh_frame
->contents
;
12650 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12652 /* Offset to stub section, written later. */
12654 /* stub section size. */
12655 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
12657 /* Augmentation. */
12659 /* Make sure we don't have all nops. This is enough for
12660 elf-eh-frame.c to detect the last non-nop opcode. */
12661 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
12662 p
= last_fde
+ last_fde_len
+ 4;
12664 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12667 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
12669 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12672 val
= p
- htab
->glink_eh_frame
->contents
;
12673 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12675 /* Offset to .glink, written later. */
12678 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12680 /* Augmentation. */
12683 *p
++ = DW_CFA_advance_loc
+ 1;
12684 *p
++ = DW_CFA_register
;
12686 *p
++ = htab
->opd_abi
? 12 : 0;
12687 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
12688 *p
++ = DW_CFA_restore_extended
;
12690 p
+= ((24 + align
- 1) & -align
) - 24;
12692 /* Subsume any padding into the last FDE if user .eh_frame
12693 sections are aligned more than glink_eh_frame. Otherwise any
12694 zero padding will be seen as a terminator. */
12695 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12696 size
= p
- htab
->glink_eh_frame
->contents
;
12697 pad
= ((size
+ align
- 1) & -align
) - size
;
12698 htab
->glink_eh_frame
->size
= size
+ pad
;
12699 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
12702 maybe_strip_output (info
, htab
->brlt
);
12703 if (htab
->glink_eh_frame
!= NULL
)
12704 maybe_strip_output (info
, htab
->glink_eh_frame
);
12709 /* Called after we have determined section placement. If sections
12710 move, we'll be called again. Provide a value for TOCstart. */
12713 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
12716 bfd_vma TOCstart
, adjust
;
12720 struct elf_link_hash_entry
*h
;
12721 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
12723 if (is_elf_hash_table (htab
)
12724 && htab
->hgot
!= NULL
)
12728 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
12729 if (is_elf_hash_table (htab
))
12733 && h
->root
.type
== bfd_link_hash_defined
12734 && !h
->root
.linker_def
12735 && (!is_elf_hash_table (htab
)
12736 || h
->def_regular
))
12738 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
12739 + h
->root
.u
.def
.section
->output_offset
12740 + h
->root
.u
.def
.section
->output_section
->vma
);
12741 _bfd_set_gp_value (obfd
, TOCstart
);
12746 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12747 order. The TOC starts where the first of these sections starts. */
12748 s
= bfd_get_section_by_name (obfd
, ".got");
12749 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12750 s
= bfd_get_section_by_name (obfd
, ".toc");
12751 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12752 s
= bfd_get_section_by_name (obfd
, ".tocbss");
12753 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12754 s
= bfd_get_section_by_name (obfd
, ".plt");
12755 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12757 /* This may happen for
12758 o references to TOC base (SYM@toc / TOC[tc0]) without a
12760 o bad linker script
12761 o --gc-sections and empty TOC sections
12763 FIXME: Warn user? */
12765 /* Look for a likely section. We probably won't even be
12767 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12768 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
12770 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12773 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12774 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
12775 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12778 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12779 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
12783 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12784 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
12790 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
12792 /* Force alignment. */
12793 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
12794 TOCstart
-= adjust
;
12795 _bfd_set_gp_value (obfd
, TOCstart
);
12797 if (info
!= NULL
&& s
!= NULL
)
12799 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12803 if (htab
->elf
.hgot
!= NULL
)
12805 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
12806 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
12811 struct bfd_link_hash_entry
*bh
= NULL
;
12812 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
12813 s
, TOC_BASE_OFF
- adjust
,
12814 NULL
, FALSE
, FALSE
, &bh
);
12820 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
12821 write out any global entry stubs, and PLT relocations. */
12824 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
12826 struct bfd_link_info
*info
;
12827 struct ppc_link_hash_table
*htab
;
12828 struct plt_entry
*ent
;
12831 if (h
->root
.type
== bfd_link_hash_indirect
)
12835 htab
= ppc_hash_table (info
);
12839 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12840 if (ent
->plt
.offset
!= (bfd_vma
) -1)
12842 /* This symbol has an entry in the procedure linkage
12843 table. Set it up. */
12844 Elf_Internal_Rela rela
;
12845 asection
*plt
, *relplt
;
12848 if (!htab
->elf
.dynamic_sections_created
12849 || h
->dynindx
== -1)
12851 if (!(h
->def_regular
12852 && (h
->root
.type
== bfd_link_hash_defined
12853 || h
->root
.type
== bfd_link_hash_defweak
)))
12855 if (h
->type
== STT_GNU_IFUNC
)
12857 plt
= htab
->elf
.iplt
;
12858 relplt
= htab
->elf
.irelplt
;
12859 htab
->local_ifunc_resolver
= 1;
12861 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
12863 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12867 plt
= htab
->pltlocal
;
12868 if (bfd_link_pic (info
))
12870 relplt
= htab
->relpltlocal
;
12872 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
12874 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12879 rela
.r_addend
= (h
->root
.u
.def
.value
12880 + h
->root
.u
.def
.section
->output_offset
12881 + h
->root
.u
.def
.section
->output_section
->vma
12884 if (relplt
== NULL
)
12886 loc
= plt
->contents
+ ent
->plt
.offset
;
12887 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
12890 bfd_vma toc
= elf_gp (info
->output_bfd
);
12891 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
12892 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
12897 rela
.r_offset
= (plt
->output_section
->vma
12898 + plt
->output_offset
12899 + ent
->plt
.offset
);
12900 loc
= relplt
->contents
+ (relplt
->reloc_count
++
12901 * sizeof (Elf64_External_Rela
));
12902 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12907 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
12908 + htab
->elf
.splt
->output_offset
12909 + ent
->plt
.offset
);
12910 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
12911 rela
.r_addend
= ent
->addend
;
12912 loc
= (htab
->elf
.srelplt
->contents
12913 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
12914 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
12915 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
12916 htab
->maybe_local_ifunc_resolver
= 1;
12917 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12921 if (!h
->pointer_equality_needed
)
12924 if (h
->def_regular
)
12927 s
= htab
->global_entry
;
12928 if (s
== NULL
|| s
->size
== 0)
12931 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12932 if (ent
->plt
.offset
!= (bfd_vma
) -1
12933 && ent
->addend
== 0)
12939 p
= s
->contents
+ h
->root
.u
.def
.value
;
12940 plt
= htab
->elf
.splt
;
12941 if (!htab
->elf
.dynamic_sections_created
12942 || h
->dynindx
== -1)
12944 if (h
->type
== STT_GNU_IFUNC
)
12945 plt
= htab
->elf
.iplt
;
12947 plt
= htab
->pltlocal
;
12949 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
12950 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
12952 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
12954 info
->callbacks
->einfo
12955 (_("%P: linkage table error against `%pT'\n"),
12956 h
->root
.root
.string
);
12957 bfd_set_error (bfd_error_bad_value
);
12958 htab
->stub_error
= TRUE
;
12961 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
12962 if (htab
->params
->emit_stub_syms
)
12964 size_t len
= strlen (h
->root
.root
.string
);
12965 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
12970 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
12971 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
12974 if (h
->root
.type
== bfd_link_hash_new
)
12976 h
->root
.type
= bfd_link_hash_defined
;
12977 h
->root
.u
.def
.section
= s
;
12978 h
->root
.u
.def
.value
= p
- s
->contents
;
12979 h
->ref_regular
= 1;
12980 h
->def_regular
= 1;
12981 h
->ref_regular_nonweak
= 1;
12982 h
->forced_local
= 1;
12984 h
->root
.linker_def
= 1;
12988 if (PPC_HA (off
) != 0)
12990 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
12993 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
12995 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
12997 bfd_put_32 (s
->owner
, BCTR
, p
);
13003 /* Write PLT relocs for locals. */
13006 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
13008 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13011 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13013 struct got_entry
**lgot_ents
, **end_lgot_ents
;
13014 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13015 Elf_Internal_Shdr
*symtab_hdr
;
13016 bfd_size_type locsymcount
;
13017 Elf_Internal_Sym
*local_syms
= NULL
;
13018 struct plt_entry
*ent
;
13020 if (!is_ppc64_elf (ibfd
))
13023 lgot_ents
= elf_local_got_ents (ibfd
);
13027 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13028 locsymcount
= symtab_hdr
->sh_info
;
13029 end_lgot_ents
= lgot_ents
+ locsymcount
;
13030 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13031 end_local_plt
= local_plt
+ locsymcount
;
13032 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
13033 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
13034 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13036 Elf_Internal_Sym
*sym
;
13038 asection
*plt
, *relplt
;
13042 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
13043 lplt
- local_plt
, ibfd
))
13045 if (local_syms
!= NULL
13046 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13051 val
= sym
->st_value
+ ent
->addend
;
13052 if (ELF_ST_TYPE (sym
->st_info
) != STT_GNU_IFUNC
)
13053 val
+= PPC64_LOCAL_ENTRY_OFFSET (sym
->st_other
);
13054 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
13055 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
13057 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13059 htab
->local_ifunc_resolver
= 1;
13060 plt
= htab
->elf
.iplt
;
13061 relplt
= htab
->elf
.irelplt
;
13065 plt
= htab
->pltlocal
;
13066 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
13069 if (relplt
== NULL
)
13071 loc
= plt
->contents
+ ent
->plt
.offset
;
13072 bfd_put_64 (info
->output_bfd
, val
, loc
);
13075 bfd_vma toc
= elf_gp (ibfd
);
13076 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13081 Elf_Internal_Rela rela
;
13082 rela
.r_offset
= (ent
->plt
.offset
13083 + plt
->output_offset
13084 + plt
->output_section
->vma
);
13085 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13088 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13090 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13095 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13097 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13099 rela
.r_addend
= val
;
13100 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13101 * sizeof (Elf64_External_Rela
));
13102 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13106 if (local_syms
!= NULL
13107 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13109 if (!info
->keep_memory
)
13112 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13118 /* Build all the stubs associated with the current output file.
13119 The stubs are kept in a hash table attached to the main linker
13120 hash table. This function is called via gldelf64ppc_finish. */
13123 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
13126 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13127 struct map_stub
*group
;
13128 asection
*stub_sec
;
13130 int stub_sec_count
= 0;
13135 /* Allocate memory to hold the linker stubs. */
13136 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13138 group
->eh_size
= 0;
13139 group
->lr_restore
= 0;
13140 if ((stub_sec
= group
->stub_sec
) != NULL
13141 && stub_sec
->size
!= 0)
13143 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
13145 if (stub_sec
->contents
== NULL
)
13147 stub_sec
->size
= 0;
13151 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13156 /* Build the .glink plt call stub. */
13157 if (htab
->params
->emit_stub_syms
)
13159 struct elf_link_hash_entry
*h
;
13160 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
13161 TRUE
, FALSE
, FALSE
);
13164 if (h
->root
.type
== bfd_link_hash_new
)
13166 h
->root
.type
= bfd_link_hash_defined
;
13167 h
->root
.u
.def
.section
= htab
->glink
;
13168 h
->root
.u
.def
.value
= 8;
13169 h
->ref_regular
= 1;
13170 h
->def_regular
= 1;
13171 h
->ref_regular_nonweak
= 1;
13172 h
->forced_local
= 1;
13174 h
->root
.linker_def
= 1;
13177 plt0
= (htab
->elf
.splt
->output_section
->vma
13178 + htab
->elf
.splt
->output_offset
13180 if (info
->emitrelocations
)
13182 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
13185 r
->r_offset
= (htab
->glink
->output_offset
13186 + htab
->glink
->output_section
->vma
);
13187 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
13188 r
->r_addend
= plt0
;
13190 p
= htab
->glink
->contents
;
13191 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
13192 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
13196 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
13198 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13200 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13202 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13204 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
13206 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13208 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13210 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
13212 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13214 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
13219 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
13221 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13223 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13225 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
13227 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13229 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
13231 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
13233 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13235 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
13237 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13239 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
13241 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13243 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
13246 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
13248 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
13250 /* Build the .glink lazy link call stubs. */
13252 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
13258 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
13263 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
13265 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
13270 bfd_put_32 (htab
->glink
->owner
,
13271 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
13277 /* Build .glink global entry stubs, and PLT relocs for globals. */
13278 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
13280 if (!write_plt_relocs_for_local_syms (info
))
13283 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
13285 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
13287 if (htab
->brlt
->contents
== NULL
)
13290 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
13292 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
13293 htab
->relbrlt
->size
);
13294 if (htab
->relbrlt
->contents
== NULL
)
13298 /* Build the stubs as directed by the stub hash table. */
13299 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
13301 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13302 if (group
->needs_save_res
)
13303 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13305 if (htab
->relbrlt
!= NULL
)
13306 htab
->relbrlt
->reloc_count
= 0;
13308 if (htab
->params
->plt_stub_align
!= 0)
13309 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13310 if ((stub_sec
= group
->stub_sec
) != NULL
)
13312 int align
= abs (htab
->params
->plt_stub_align
);
13313 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13316 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13317 if (group
->needs_save_res
)
13319 stub_sec
= group
->stub_sec
;
13320 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
13321 htab
->sfpr
->contents
, htab
->sfpr
->size
);
13322 if (htab
->params
->emit_stub_syms
)
13326 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13327 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13332 if (htab
->glink_eh_frame
!= NULL
13333 && htab
->glink_eh_frame
->size
!= 0)
13338 p
= htab
->glink_eh_frame
->contents
;
13339 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
13341 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13342 if (group
->eh_size
!= 0)
13344 /* Offset to stub section. */
13345 val
= (group
->stub_sec
->output_section
->vma
13346 + group
->stub_sec
->output_offset
);
13347 val
-= (htab
->glink_eh_frame
->output_section
->vma
13348 + htab
->glink_eh_frame
->output_offset
13349 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
13350 if (val
+ 0x80000000 > 0xffffffff)
13353 (_("%s offset too large for .eh_frame sdata4 encoding"),
13354 group
->stub_sec
->name
);
13357 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
13358 p
+= (group
->eh_size
+ 17 + 3) & -4;
13360 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13362 /* Offset to .glink. */
13363 val
= (htab
->glink
->output_section
->vma
13364 + htab
->glink
->output_offset
13366 val
-= (htab
->glink_eh_frame
->output_section
->vma
13367 + htab
->glink_eh_frame
->output_offset
13368 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
13369 if (val
+ 0x80000000 > 0xffffffff)
13372 (_("%s offset too large for .eh_frame sdata4 encoding"),
13373 htab
->glink
->name
);
13376 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
13377 p
+= (24 + align
- 1) & -align
;
13381 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13382 if ((stub_sec
= group
->stub_sec
) != NULL
)
13384 stub_sec_count
+= 1;
13385 if (stub_sec
->rawsize
!= stub_sec
->size
13386 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13387 || stub_sec
->rawsize
< stub_sec
->size
))
13393 htab
->stub_error
= TRUE
;
13394 _bfd_error_handler (_("stubs don't match calculated size"));
13397 if (htab
->stub_error
)
13403 *stats
= bfd_malloc (500);
13404 if (*stats
== NULL
)
13407 len
= sprintf (*stats
,
13408 ngettext ("linker stubs in %u group\n",
13409 "linker stubs in %u groups\n",
13412 sprintf (*stats
+ len
, _(" branch %lu\n"
13413 " branch toc adj %lu\n"
13414 " branch notoc %lu\n"
13415 " branch both %lu\n"
13416 " long branch %lu\n"
13417 " long toc adj %lu\n"
13418 " long notoc %lu\n"
13421 " plt call save %lu\n"
13422 " plt call notoc %lu\n"
13423 " plt call both %lu\n"
13424 " global entry %lu"),
13425 htab
->stub_count
[ppc_stub_long_branch
- 1],
13426 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13427 htab
->stub_count
[ppc_stub_long_branch_notoc
- 1],
13428 htab
->stub_count
[ppc_stub_long_branch_both
- 1],
13429 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13430 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13431 htab
->stub_count
[ppc_stub_plt_branch_notoc
- 1],
13432 htab
->stub_count
[ppc_stub_plt_branch_both
- 1],
13433 htab
->stub_count
[ppc_stub_plt_call
- 1],
13434 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13435 htab
->stub_count
[ppc_stub_plt_call_notoc
- 1],
13436 htab
->stub_count
[ppc_stub_plt_call_both
- 1],
13437 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13442 /* What to do when ld finds relocations against symbols defined in
13443 discarded sections. */
13445 static unsigned int
13446 ppc64_elf_action_discarded (asection
*sec
)
13448 if (strcmp (".opd", sec
->name
) == 0)
13451 if (strcmp (".toc", sec
->name
) == 0)
13454 if (strcmp (".toc1", sec
->name
) == 0)
13457 return _bfd_elf_default_action_discarded (sec
);
13460 /* The RELOCATE_SECTION function is called by the ELF backend linker
13461 to handle the relocations for a section.
13463 The relocs are always passed as Rela structures; if the section
13464 actually uses Rel structures, the r_addend field will always be
13467 This function is responsible for adjust the section contents as
13468 necessary, and (if using Rela relocs and generating a
13469 relocatable output file) adjusting the reloc addend as
13472 This function does not have to worry about setting the reloc
13473 address or the reloc symbol index.
13475 LOCAL_SYMS is a pointer to the swapped in local symbols.
13477 LOCAL_SECTIONS is an array giving the section in the input file
13478 corresponding to the st_shndx field of each local symbol.
13480 The global hash table entry for the global symbols can be found
13481 via elf_sym_hashes (input_bfd).
13483 When generating relocatable output, this function must handle
13484 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13485 going to be the section symbol corresponding to the output
13486 section, which means that the addend must be adjusted
13490 ppc64_elf_relocate_section (bfd
*output_bfd
,
13491 struct bfd_link_info
*info
,
13493 asection
*input_section
,
13494 bfd_byte
*contents
,
13495 Elf_Internal_Rela
*relocs
,
13496 Elf_Internal_Sym
*local_syms
,
13497 asection
**local_sections
)
13499 struct ppc_link_hash_table
*htab
;
13500 Elf_Internal_Shdr
*symtab_hdr
;
13501 struct elf_link_hash_entry
**sym_hashes
;
13502 Elf_Internal_Rela
*rel
;
13503 Elf_Internal_Rela
*wrel
;
13504 Elf_Internal_Rela
*relend
;
13505 Elf_Internal_Rela outrel
;
13507 struct got_entry
**local_got_ents
;
13509 bfd_boolean ret
= TRUE
;
13510 bfd_boolean is_opd
;
13511 /* Assume 'at' branch hints. */
13512 bfd_boolean is_isa_v2
= TRUE
;
13513 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13515 /* Initialize howto table if needed. */
13516 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13519 htab
= ppc_hash_table (info
);
13523 /* Don't relocate stub sections. */
13524 if (input_section
->owner
== htab
->params
->stub_bfd
)
13527 if (!is_ppc64_elf (input_bfd
))
13529 bfd_set_error (bfd_error_wrong_format
);
13533 local_got_ents
= elf_local_got_ents (input_bfd
);
13534 TOCstart
= elf_gp (output_bfd
);
13535 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13536 sym_hashes
= elf_sym_hashes (input_bfd
);
13537 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13539 rel
= wrel
= relocs
;
13540 relend
= relocs
+ input_section
->reloc_count
;
13541 for (; rel
< relend
; wrel
++, rel
++)
13543 enum elf_ppc64_reloc_type r_type
;
13545 bfd_reloc_status_type r
;
13546 Elf_Internal_Sym
*sym
;
13548 struct elf_link_hash_entry
*h_elf
;
13549 struct ppc_link_hash_entry
*h
;
13550 struct ppc_link_hash_entry
*fdh
;
13551 const char *sym_name
;
13552 unsigned long r_symndx
, toc_symndx
;
13553 bfd_vma toc_addend
;
13554 unsigned char tls_mask
, tls_gd
, tls_type
;
13555 unsigned char sym_type
;
13556 bfd_vma relocation
;
13557 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
13558 bfd_boolean warned
;
13559 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13562 struct ppc_stub_hash_entry
*stub_entry
;
13563 bfd_vma max_br_offset
;
13565 Elf_Internal_Rela orig_rel
;
13566 reloc_howto_type
*howto
;
13567 struct reloc_howto_struct alt_howto
;
13572 r_type
= ELF64_R_TYPE (rel
->r_info
);
13573 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13575 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13576 symbol of the previous ADDR64 reloc. The symbol gives us the
13577 proper TOC base to use. */
13578 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13580 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13582 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13588 unresolved_reloc
= FALSE
;
13591 if (r_symndx
< symtab_hdr
->sh_info
)
13593 /* It's a local symbol. */
13594 struct _opd_sec_data
*opd
;
13596 sym
= local_syms
+ r_symndx
;
13597 sec
= local_sections
[r_symndx
];
13598 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13599 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13600 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13601 opd
= get_opd_info (sec
);
13602 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13604 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13610 /* If this is a relocation against the opd section sym
13611 and we have edited .opd, adjust the reloc addend so
13612 that ld -r and ld --emit-relocs output is correct.
13613 If it is a reloc against some other .opd symbol,
13614 then the symbol value will be adjusted later. */
13615 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13616 rel
->r_addend
+= adjust
;
13618 relocation
+= adjust
;
13624 bfd_boolean ignored
;
13626 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13627 r_symndx
, symtab_hdr
, sym_hashes
,
13628 h_elf
, sec
, relocation
,
13629 unresolved_reloc
, warned
, ignored
);
13630 sym_name
= h_elf
->root
.root
.string
;
13631 sym_type
= h_elf
->type
;
13633 && sec
->owner
== output_bfd
13634 && strcmp (sec
->name
, ".opd") == 0)
13636 /* This is a symbol defined in a linker script. All
13637 such are defined in output sections, even those
13638 defined by simple assignment from a symbol defined in
13639 an input section. Transfer the symbol to an
13640 appropriate input .opd section, so that a branch to
13641 this symbol will be mapped to the location specified
13642 by the opd entry. */
13643 struct bfd_link_order
*lo
;
13644 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13645 if (lo
->type
== bfd_indirect_link_order
)
13647 asection
*isec
= lo
->u
.indirect
.section
;
13648 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13649 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13652 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13653 h_elf
->root
.u
.def
.section
= isec
;
13660 h
= (struct ppc_link_hash_entry
*) h_elf
;
13662 if (sec
!= NULL
&& discarded_section (sec
))
13664 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
13665 input_bfd
, input_section
,
13666 contents
, rel
->r_offset
);
13667 wrel
->r_offset
= rel
->r_offset
;
13669 wrel
->r_addend
= 0;
13671 /* For ld -r, remove relocations in debug sections against
13672 symbols defined in discarded sections. Not done for
13673 non-debug to preserve relocs in .eh_frame which the
13674 eh_frame editing code expects to be present. */
13675 if (bfd_link_relocatable (info
)
13676 && (input_section
->flags
& SEC_DEBUGGING
))
13682 if (bfd_link_relocatable (info
))
13685 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13687 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13688 sec
= bfd_abs_section_ptr
;
13689 unresolved_reloc
= FALSE
;
13692 /* TLS optimizations. Replace instruction sequences and relocs
13693 based on information we collected in tls_optimize. We edit
13694 RELOCS so that --emit-relocs will output something sensible
13695 for the final instruction stream. */
13700 tls_mask
= h
->tls_mask
;
13701 else if (local_got_ents
!= NULL
)
13703 struct plt_entry
**local_plt
= (struct plt_entry
**)
13704 (local_got_ents
+ symtab_hdr
->sh_info
);
13705 unsigned char *lgot_masks
= (unsigned char *)
13706 (local_plt
+ symtab_hdr
->sh_info
);
13707 tls_mask
= lgot_masks
[r_symndx
];
13709 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
13710 && (r_type
== R_PPC64_TLS
13711 || r_type
== R_PPC64_TLSGD
13712 || r_type
== R_PPC64_TLSLD
))
13714 /* Check for toc tls entries. */
13715 unsigned char *toc_tls
;
13717 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13718 &local_syms
, rel
, input_bfd
))
13722 tls_mask
= *toc_tls
;
13725 /* Check that tls relocs are used with tls syms, and non-tls
13726 relocs are used with non-tls syms. */
13727 if (r_symndx
!= STN_UNDEF
13728 && r_type
!= R_PPC64_NONE
13730 || h
->elf
.root
.type
== bfd_link_hash_defined
13731 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13732 && (IS_PPC64_TLS_RELOC (r_type
)
13733 != (sym_type
== STT_TLS
13734 || (sym_type
== STT_SECTION
13735 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13737 if ((tls_mask
& TLS_TLS
) != 0
13738 && (r_type
== R_PPC64_TLS
13739 || r_type
== R_PPC64_TLSGD
13740 || r_type
== R_PPC64_TLSLD
))
13741 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13744 info
->callbacks
->einfo
13745 (!IS_PPC64_TLS_RELOC (r_type
)
13746 /* xgettext:c-format */
13747 ? _("%H: %s used with TLS symbol `%pT'\n")
13748 /* xgettext:c-format */
13749 : _("%H: %s used with non-TLS symbol `%pT'\n"),
13750 input_bfd
, input_section
, rel
->r_offset
,
13751 ppc64_elf_howto_table
[r_type
]->name
,
13755 /* Ensure reloc mapping code below stays sane. */
13756 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13757 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13758 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13759 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13760 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13761 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13762 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13763 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13764 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13765 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
13773 case R_PPC64_LO_DS_OPT
:
13774 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
13775 if ((insn
& (0x3f << 26)) != 58u << 26)
13777 insn
+= (14u << 26) - (58u << 26);
13778 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13779 r_type
= R_PPC64_TOC16_LO
;
13780 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13783 case R_PPC64_TOC16
:
13784 case R_PPC64_TOC16_LO
:
13785 case R_PPC64_TOC16_DS
:
13786 case R_PPC64_TOC16_LO_DS
:
13788 /* Check for toc tls entries. */
13789 unsigned char *toc_tls
;
13792 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13793 &local_syms
, rel
, input_bfd
);
13799 tls_mask
= *toc_tls
;
13800 if (r_type
== R_PPC64_TOC16_DS
13801 || r_type
== R_PPC64_TOC16_LO_DS
)
13803 if ((tls_mask
& TLS_TLS
) != 0
13804 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
13809 /* If we found a GD reloc pair, then we might be
13810 doing a GD->IE transition. */
13813 tls_gd
= TLS_TPRELGD
;
13814 if ((tls_mask
& TLS_TLS
) != 0
13815 && (tls_mask
& TLS_GD
) == 0)
13818 else if (retval
== 3)
13820 if ((tls_mask
& TLS_TLS
) != 0
13821 && (tls_mask
& TLS_LD
) == 0)
13829 case R_PPC64_GOT_TPREL16_HI
:
13830 case R_PPC64_GOT_TPREL16_HA
:
13831 if ((tls_mask
& TLS_TLS
) != 0
13832 && (tls_mask
& TLS_TPREL
) == 0)
13834 rel
->r_offset
-= d_offset
;
13835 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13836 r_type
= R_PPC64_NONE
;
13837 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13841 case R_PPC64_GOT_TPREL16_DS
:
13842 case R_PPC64_GOT_TPREL16_LO_DS
:
13843 if ((tls_mask
& TLS_TLS
) != 0
13844 && (tls_mask
& TLS_TPREL
) == 0)
13847 insn
= bfd_get_32 (input_bfd
,
13848 contents
+ rel
->r_offset
- d_offset
);
13850 insn
|= 0x3c0d0000; /* addis 0,13,0 */
13851 bfd_put_32 (input_bfd
, insn
,
13852 contents
+ rel
->r_offset
- d_offset
);
13853 r_type
= R_PPC64_TPREL16_HA
;
13854 if (toc_symndx
!= 0)
13856 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13857 rel
->r_addend
= toc_addend
;
13858 /* We changed the symbol. Start over in order to
13859 get h, sym, sec etc. right. */
13863 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13868 if ((tls_mask
& TLS_TLS
) != 0
13869 && (tls_mask
& TLS_TPREL
) == 0)
13871 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13872 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
13875 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
13876 /* Was PPC64_TLS which sits on insn boundary, now
13877 PPC64_TPREL16_LO which is at low-order half-word. */
13878 rel
->r_offset
+= d_offset
;
13879 r_type
= R_PPC64_TPREL16_LO
;
13880 if (toc_symndx
!= 0)
13882 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13883 rel
->r_addend
= toc_addend
;
13884 /* We changed the symbol. Start over in order to
13885 get h, sym, sec etc. right. */
13889 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13893 case R_PPC64_GOT_TLSGD16_HI
:
13894 case R_PPC64_GOT_TLSGD16_HA
:
13895 tls_gd
= TLS_TPRELGD
;
13896 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13900 case R_PPC64_GOT_TLSLD16_HI
:
13901 case R_PPC64_GOT_TLSLD16_HA
:
13902 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13905 if ((tls_mask
& tls_gd
) != 0)
13906 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13907 + R_PPC64_GOT_TPREL16_DS
);
13910 rel
->r_offset
-= d_offset
;
13911 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13912 r_type
= R_PPC64_NONE
;
13914 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13918 case R_PPC64_GOT_TLSGD16
:
13919 case R_PPC64_GOT_TLSGD16_LO
:
13920 tls_gd
= TLS_TPRELGD
;
13921 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13925 case R_PPC64_GOT_TLSLD16
:
13926 case R_PPC64_GOT_TLSLD16_LO
:
13927 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13929 unsigned int insn1
, insn2
;
13933 offset
= (bfd_vma
) -1;
13934 /* If not using the newer R_PPC64_TLSGD/LD to mark
13935 __tls_get_addr calls, we must trust that the call
13936 stays with its arg setup insns, ie. that the next
13937 reloc is the __tls_get_addr call associated with
13938 the current reloc. Edit both insns. */
13939 if (input_section
->has_tls_get_addr_call
13940 && rel
+ 1 < relend
13941 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
13942 htab
->tls_get_addr
,
13943 htab
->tls_get_addr_fd
))
13944 offset
= rel
[1].r_offset
;
13945 /* We read the low GOT_TLS (or TOC16) insn because we
13946 need to keep the destination reg. It may be
13947 something other than the usual r3, and moved to r3
13948 before the call by intervening code. */
13949 insn1
= bfd_get_32 (input_bfd
,
13950 contents
+ rel
->r_offset
- d_offset
);
13951 if ((tls_mask
& tls_gd
) != 0)
13954 insn1
&= (0x1f << 21) | (0x1f << 16);
13955 insn1
|= 58 << 26; /* ld */
13956 insn2
= 0x7c636a14; /* add 3,3,13 */
13957 if (offset
!= (bfd_vma
) -1)
13958 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13959 if ((tls_mask
& TLS_EXPLICIT
) == 0)
13960 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13961 + R_PPC64_GOT_TPREL16_DS
);
13963 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
13964 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13969 insn1
&= 0x1f << 21;
13970 insn1
|= 0x3c0d0000; /* addis r,13,0 */
13971 insn2
= 0x38630000; /* addi 3,3,0 */
13974 /* Was an LD reloc. */
13976 sec
= local_sections
[toc_symndx
];
13978 r_symndx
< symtab_hdr
->sh_info
;
13980 if (local_sections
[r_symndx
] == sec
)
13982 if (r_symndx
>= symtab_hdr
->sh_info
)
13983 r_symndx
= STN_UNDEF
;
13984 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13985 if (r_symndx
!= STN_UNDEF
)
13986 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13987 + sec
->output_offset
13988 + sec
->output_section
->vma
);
13990 else if (toc_symndx
!= 0)
13992 r_symndx
= toc_symndx
;
13993 rel
->r_addend
= toc_addend
;
13995 r_type
= R_PPC64_TPREL16_HA
;
13996 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13997 if (offset
!= (bfd_vma
) -1)
13999 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
14000 R_PPC64_TPREL16_LO
);
14001 rel
[1].r_offset
= offset
+ d_offset
;
14002 rel
[1].r_addend
= rel
->r_addend
;
14005 bfd_put_32 (input_bfd
, insn1
,
14006 contents
+ rel
->r_offset
- d_offset
);
14007 if (offset
!= (bfd_vma
) -1)
14009 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14010 if (offset
+ 8 <= input_section
->size
)
14012 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14013 if (insn2
== LD_R2_0R1
+ STK_TOC (htab
))
14014 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
+ 4);
14017 if ((tls_mask
& tls_gd
) == 0
14018 && (tls_gd
== 0 || toc_symndx
!= 0))
14020 /* We changed the symbol. Start over in order
14021 to get h, sym, sec etc. right. */
14027 case R_PPC64_TLSGD
:
14028 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
14029 && rel
+ 1 < relend
)
14031 unsigned int insn2
;
14032 bfd_vma offset
= rel
->r_offset
;
14034 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
14036 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14037 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14041 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14042 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14044 if ((tls_mask
& TLS_TPRELGD
) != 0)
14047 r_type
= R_PPC64_NONE
;
14048 insn2
= 0x7c636a14; /* add 3,3,13 */
14053 if (toc_symndx
!= 0)
14055 r_symndx
= toc_symndx
;
14056 rel
->r_addend
= toc_addend
;
14058 r_type
= R_PPC64_TPREL16_LO
;
14059 rel
->r_offset
= offset
+ d_offset
;
14060 insn2
= 0x38630000; /* addi 3,3,0 */
14062 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14063 /* Zap the reloc on the _tls_get_addr call too. */
14064 BFD_ASSERT (offset
== rel
[1].r_offset
);
14065 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14066 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14067 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
14072 case R_PPC64_TLSLD
:
14073 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
14074 && rel
+ 1 < relend
)
14076 unsigned int insn2
;
14077 bfd_vma offset
= rel
->r_offset
;
14079 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
14081 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14082 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14086 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14087 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14090 sec
= local_sections
[toc_symndx
];
14092 r_symndx
< symtab_hdr
->sh_info
;
14094 if (local_sections
[r_symndx
] == sec
)
14096 if (r_symndx
>= symtab_hdr
->sh_info
)
14097 r_symndx
= STN_UNDEF
;
14098 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14099 if (r_symndx
!= STN_UNDEF
)
14100 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
14101 + sec
->output_offset
14102 + sec
->output_section
->vma
);
14104 r_type
= R_PPC64_TPREL16_LO
;
14105 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14106 rel
->r_offset
= offset
+ d_offset
;
14107 /* Zap the reloc on the _tls_get_addr call too. */
14108 BFD_ASSERT (offset
== rel
[1].r_offset
);
14109 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14110 insn2
= 0x38630000; /* addi 3,3,0 */
14111 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14116 case R_PPC64_DTPMOD64
:
14117 if (rel
+ 1 < relend
14118 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
14119 && rel
[1].r_offset
== rel
->r_offset
+ 8)
14121 if ((tls_mask
& TLS_GD
) == 0)
14123 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
14124 if ((tls_mask
& TLS_TPRELGD
) != 0)
14125 r_type
= R_PPC64_TPREL64
;
14128 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14129 r_type
= R_PPC64_NONE
;
14131 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14136 if ((tls_mask
& TLS_LD
) == 0)
14138 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14139 r_type
= R_PPC64_NONE
;
14140 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14145 case R_PPC64_TPREL64
:
14146 if ((tls_mask
& TLS_TPREL
) == 0)
14148 r_type
= R_PPC64_NONE
;
14149 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14153 case R_PPC64_ENTRY
:
14154 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14155 if (!bfd_link_pic (info
)
14156 && !info
->traditional_format
14157 && relocation
+ 0x80008000 <= 0xffffffff)
14159 unsigned int insn1
, insn2
;
14161 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14162 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14163 if ((insn1
& ~0xfffc) == LD_R2_0R12
14164 && insn2
== ADD_R2_R2_R12
)
14166 bfd_put_32 (input_bfd
,
14167 LIS_R2
+ PPC_HA (relocation
),
14168 contents
+ rel
->r_offset
);
14169 bfd_put_32 (input_bfd
,
14170 ADDI_R2_R2
+ PPC_LO (relocation
),
14171 contents
+ rel
->r_offset
+ 4);
14176 relocation
-= (rel
->r_offset
14177 + input_section
->output_offset
14178 + input_section
->output_section
->vma
);
14179 if (relocation
+ 0x80008000 <= 0xffffffff)
14181 unsigned int insn1
, insn2
;
14183 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14184 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14185 if ((insn1
& ~0xfffc) == LD_R2_0R12
14186 && insn2
== ADD_R2_R2_R12
)
14188 bfd_put_32 (input_bfd
,
14189 ADDIS_R2_R12
+ PPC_HA (relocation
),
14190 contents
+ rel
->r_offset
);
14191 bfd_put_32 (input_bfd
,
14192 ADDI_R2_R2
+ PPC_LO (relocation
),
14193 contents
+ rel
->r_offset
+ 4);
14199 case R_PPC64_REL16_HA
:
14200 /* If we are generating a non-PIC executable, edit
14201 . 0: addis 2,12,.TOC.-0b@ha
14202 . addi 2,2,.TOC.-0b@l
14203 used by ELFv2 global entry points to set up r2, to
14206 if .TOC. is in range. */
14207 if (!bfd_link_pic (info
)
14208 && !info
->traditional_format
14210 && rel
->r_addend
== d_offset
14211 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
14212 && rel
+ 1 < relend
14213 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
14214 && rel
[1].r_offset
== rel
->r_offset
+ 4
14215 && rel
[1].r_addend
== rel
->r_addend
+ 4
14216 && relocation
+ 0x80008000 <= 0xffffffff)
14218 unsigned int insn1
, insn2
;
14219 bfd_vma offset
= rel
->r_offset
- d_offset
;
14220 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
14221 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14222 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
14223 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
14225 r_type
= R_PPC64_ADDR16_HA
;
14226 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14227 rel
->r_addend
-= d_offset
;
14228 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
14229 rel
[1].r_addend
-= d_offset
+ 4;
14230 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
14236 /* Handle other relocations that tweak non-addend part of insn. */
14238 max_br_offset
= 1 << 25;
14239 addend
= rel
->r_addend
;
14240 reloc_dest
= DEST_NORMAL
;
14246 case R_PPC64_TOCSAVE
:
14247 if (relocation
+ addend
== (rel
->r_offset
14248 + input_section
->output_offset
14249 + input_section
->output_section
->vma
)
14250 && tocsave_find (htab
, NO_INSERT
,
14251 &local_syms
, rel
, input_bfd
))
14253 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14255 || insn
== CROR_151515
|| insn
== CROR_313131
)
14256 bfd_put_32 (input_bfd
,
14257 STD_R2_0R1
+ STK_TOC (htab
),
14258 contents
+ rel
->r_offset
);
14262 /* Branch taken prediction relocations. */
14263 case R_PPC64_ADDR14_BRTAKEN
:
14264 case R_PPC64_REL14_BRTAKEN
:
14265 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14266 /* Fall through. */
14268 /* Branch not taken prediction relocations. */
14269 case R_PPC64_ADDR14_BRNTAKEN
:
14270 case R_PPC64_REL14_BRNTAKEN
:
14271 insn
|= bfd_get_32 (input_bfd
,
14272 contents
+ rel
->r_offset
) & ~(0x01 << 21);
14273 /* Fall through. */
14275 case R_PPC64_REL14
:
14276 max_br_offset
= 1 << 15;
14277 /* Fall through. */
14279 case R_PPC64_REL24
:
14280 case R_PPC64_REL24_NOTOC
:
14281 case R_PPC64_PLTCALL
:
14282 /* Calls to functions with a different TOC, such as calls to
14283 shared objects, need to alter the TOC pointer. This is
14284 done using a linkage stub. A REL24 branching to these
14285 linkage stubs needs to be followed by a nop, as the nop
14286 will be replaced with an instruction to restore the TOC
14291 && h
->oh
->is_func_descriptor
)
14292 fdh
= ppc_follow_link (h
->oh
);
14293 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
14295 if (r_type
== R_PPC64_PLTCALL
14296 && stub_entry
!= NULL
14297 && stub_entry
->stub_type
>= ppc_stub_plt_call
14298 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14301 if (stub_entry
!= NULL
14302 && ((stub_entry
->stub_type
>= ppc_stub_plt_call
14303 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14304 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14305 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
14306 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
14307 || stub_entry
->stub_type
== ppc_stub_long_branch_both
))
14309 bfd_boolean can_plt_call
= FALSE
;
14311 if (stub_entry
->stub_type
== ppc_stub_plt_call
14313 && htab
->params
->plt_localentry0
!= 0
14314 && is_elfv2_localentry0 (&h
->elf
))
14316 /* The function doesn't use or change r2. */
14317 can_plt_call
= TRUE
;
14319 else if (r_type
== R_PPC64_REL24_NOTOC
)
14321 /* NOTOC calls don't need to restore r2. */
14322 can_plt_call
= TRUE
;
14325 /* All of these stubs may modify r2, so there must be a
14326 branch and link followed by a nop. The nop is
14327 replaced by an insn to restore r2. */
14328 else if (rel
->r_offset
+ 8 <= input_section
->size
)
14332 br
= bfd_get_32 (input_bfd
,
14333 contents
+ rel
->r_offset
);
14338 nop
= bfd_get_32 (input_bfd
,
14339 contents
+ rel
->r_offset
+ 4);
14340 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
14341 can_plt_call
= TRUE
;
14342 else if (nop
== NOP
14343 || nop
== CROR_151515
14344 || nop
== CROR_313131
)
14347 && (h
== htab
->tls_get_addr_fd
14348 || h
== htab
->tls_get_addr
)
14349 && htab
->params
->tls_get_addr_opt
)
14351 /* Special stub used, leave nop alone. */
14354 bfd_put_32 (input_bfd
,
14355 LD_R2_0R1
+ STK_TOC (htab
),
14356 contents
+ rel
->r_offset
+ 4);
14357 can_plt_call
= TRUE
;
14362 if (!can_plt_call
&& h
!= NULL
)
14364 const char *name
= h
->elf
.root
.root
.string
;
14369 if (strncmp (name
, "__libc_start_main", 17) == 0
14370 && (name
[17] == 0 || name
[17] == '@'))
14372 /* Allow crt1 branch to go via a toc adjusting
14373 stub. Other calls that never return could do
14374 the same, if we could detect such. */
14375 can_plt_call
= TRUE
;
14381 /* g++ as of 20130507 emits self-calls without a
14382 following nop. This is arguably wrong since we
14383 have conflicting information. On the one hand a
14384 global symbol and on the other a local call
14385 sequence, but don't error for this special case.
14386 It isn't possible to cheaply verify we have
14387 exactly such a call. Allow all calls to the same
14389 asection
*code_sec
= sec
;
14391 if (get_opd_info (sec
) != NULL
)
14393 bfd_vma off
= (relocation
+ addend
14394 - sec
->output_section
->vma
14395 - sec
->output_offset
);
14397 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14399 if (code_sec
== input_section
)
14400 can_plt_call
= TRUE
;
14405 if (stub_entry
->stub_type
>= ppc_stub_plt_call
14406 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14407 info
->callbacks
->einfo
14408 /* xgettext:c-format */
14409 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14410 "(plt call stub)\n"),
14411 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14413 info
->callbacks
->einfo
14414 /* xgettext:c-format */
14415 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14416 "(toc save/adjust stub)\n"),
14417 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14419 bfd_set_error (bfd_error_bad_value
);
14424 && stub_entry
->stub_type
>= ppc_stub_plt_call
14425 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14426 unresolved_reloc
= FALSE
;
14429 if ((stub_entry
== NULL
14430 || stub_entry
->stub_type
== ppc_stub_long_branch
14431 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14432 && get_opd_info (sec
) != NULL
)
14434 /* The branch destination is the value of the opd entry. */
14435 bfd_vma off
= (relocation
+ addend
14436 - sec
->output_section
->vma
14437 - sec
->output_offset
);
14438 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14439 if (dest
!= (bfd_vma
) -1)
14443 reloc_dest
= DEST_OPD
;
14447 /* If the branch is out of reach we ought to have a long
14449 from
= (rel
->r_offset
14450 + input_section
->output_offset
14451 + input_section
->output_section
->vma
);
14453 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14457 if (stub_entry
!= NULL
14458 && (stub_entry
->stub_type
== ppc_stub_long_branch
14459 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14460 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14461 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14462 || (relocation
+ addend
- from
+ max_br_offset
14463 < 2 * max_br_offset
)))
14464 /* Don't use the stub if this branch is in range. */
14467 if (stub_entry
!= NULL
14468 && (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
14469 || stub_entry
->stub_type
== ppc_stub_long_branch_both
14470 || stub_entry
->stub_type
== ppc_stub_plt_branch_notoc
14471 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
14472 && (r_type
!= R_PPC64_REL24_NOTOC
14473 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
14474 & STO_PPC64_LOCAL_MASK
) == 1 << STO_PPC64_LOCAL_BIT
)
14475 && (relocation
+ addend
- from
+ max_br_offset
14476 < 2 * max_br_offset
))
14479 if (stub_entry
!= NULL
14480 && (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
14481 || stub_entry
->stub_type
== ppc_stub_long_branch_both
14482 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14483 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
14484 && r_type
== R_PPC64_REL24_NOTOC
14485 && (relocation
+ addend
- from
+ max_br_offset
14486 < 2 * max_br_offset
))
14489 if (stub_entry
!= NULL
)
14491 /* Munge up the value and addend so that we call the stub
14492 rather than the procedure directly. */
14493 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14495 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14496 relocation
+= (stub_sec
->output_offset
14497 + stub_sec
->output_section
->vma
14498 + stub_sec
->size
- htab
->sfpr
->size
14499 - htab
->sfpr
->output_offset
14500 - htab
->sfpr
->output_section
->vma
);
14502 relocation
= (stub_entry
->stub_offset
14503 + stub_sec
->output_offset
14504 + stub_sec
->output_section
->vma
);
14506 reloc_dest
= DEST_STUB
;
14508 if (((stub_entry
->stub_type
== ppc_stub_plt_call
14509 && ALWAYS_EMIT_R2SAVE
)
14510 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14511 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
14513 && (h
== htab
->tls_get_addr_fd
14514 || h
== htab
->tls_get_addr
)
14515 && htab
->params
->tls_get_addr_opt
)
14516 && rel
+ 1 < relend
14517 && rel
[1].r_offset
== rel
->r_offset
+ 4
14518 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14520 else if ((stub_entry
->stub_type
== ppc_stub_long_branch_both
14521 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
14522 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
14523 && r_type
== R_PPC64_REL24_NOTOC
)
14531 /* Set 'a' bit. This is 0b00010 in BO field for branch
14532 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14533 for branch on CTR insns (BO == 1a00t or 1a01t). */
14534 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14535 insn
|= 0x02 << 21;
14536 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14537 insn
|= 0x08 << 21;
14543 /* Invert 'y' bit if not the default. */
14544 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14545 insn
^= 0x01 << 21;
14548 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14551 /* NOP out calls to undefined weak functions.
14552 We can thus call a weak function without first
14553 checking whether the function is defined. */
14555 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14556 && h
->elf
.dynindx
== -1
14557 && (r_type
== R_PPC64_REL24
14558 || r_type
== R_PPC64_REL24_NOTOC
)
14562 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14567 case R_PPC64_GOT16_DS
:
14568 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14569 if (relocation
+ addend
- from
+ 0x8000 < 0x10000
14570 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
14572 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
14573 if ((insn
& (0x3f << 26 | 0x3)) == 58u << 26 /* ld */)
14575 insn
+= (14u << 26) - (58u << 26);
14576 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
14577 r_type
= R_PPC64_TOC16
;
14578 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14583 case R_PPC64_GOT16_LO_DS
:
14584 case R_PPC64_GOT16_HA
:
14585 from
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14586 if (relocation
+ addend
- from
+ 0x80008000ULL
< 0x100000000ULL
14587 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))
14589 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
14590 if ((insn
& (0x3f << 26 | 0x3)) == 58u << 26 /* ld */)
14592 insn
+= (14u << 26) - (58u << 26);
14593 bfd_put_32 (input_bfd
, insn
, contents
+ (rel
->r_offset
& ~3));
14594 r_type
= R_PPC64_TOC16_LO
;
14595 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14597 else if ((insn
& (0x3f << 26)) == 15u << 26 /* addis */)
14599 r_type
= R_PPC64_TOC16_HA
;
14600 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14606 /* Set `addend'. */
14608 save_unresolved_reloc
= unresolved_reloc
;
14612 /* xgettext:c-format */
14613 _bfd_error_handler (_("%pB: %s unsupported"),
14614 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
14616 bfd_set_error (bfd_error_bad_value
);
14622 case R_PPC64_TLSGD
:
14623 case R_PPC64_TLSLD
:
14624 case R_PPC64_TOCSAVE
:
14625 case R_PPC64_GNU_VTINHERIT
:
14626 case R_PPC64_GNU_VTENTRY
:
14627 case R_PPC64_ENTRY
:
14630 /* GOT16 relocations. Like an ADDR16 using the symbol's
14631 address in the GOT as relocation value instead of the
14632 symbol's value itself. Also, create a GOT entry for the
14633 symbol and put the symbol value there. */
14634 case R_PPC64_GOT_TLSGD16
:
14635 case R_PPC64_GOT_TLSGD16_LO
:
14636 case R_PPC64_GOT_TLSGD16_HI
:
14637 case R_PPC64_GOT_TLSGD16_HA
:
14638 tls_type
= TLS_TLS
| TLS_GD
;
14641 case R_PPC64_GOT_TLSLD16
:
14642 case R_PPC64_GOT_TLSLD16_LO
:
14643 case R_PPC64_GOT_TLSLD16_HI
:
14644 case R_PPC64_GOT_TLSLD16_HA
:
14645 tls_type
= TLS_TLS
| TLS_LD
;
14648 case R_PPC64_GOT_TPREL16_DS
:
14649 case R_PPC64_GOT_TPREL16_LO_DS
:
14650 case R_PPC64_GOT_TPREL16_HI
:
14651 case R_PPC64_GOT_TPREL16_HA
:
14652 tls_type
= TLS_TLS
| TLS_TPREL
;
14655 case R_PPC64_GOT_DTPREL16_DS
:
14656 case R_PPC64_GOT_DTPREL16_LO_DS
:
14657 case R_PPC64_GOT_DTPREL16_HI
:
14658 case R_PPC64_GOT_DTPREL16_HA
:
14659 tls_type
= TLS_TLS
| TLS_DTPREL
;
14662 case R_PPC64_GOT16
:
14663 case R_PPC64_GOT16_LO
:
14664 case R_PPC64_GOT16_HI
:
14665 case R_PPC64_GOT16_HA
:
14666 case R_PPC64_GOT16_DS
:
14667 case R_PPC64_GOT16_LO_DS
:
14670 /* Relocation is to the entry for this symbol in the global
14675 unsigned long indx
= 0;
14676 struct got_entry
*ent
;
14678 if (tls_type
== (TLS_TLS
| TLS_LD
)
14680 || !h
->elf
.def_dynamic
))
14681 ent
= ppc64_tlsld_got (input_bfd
);
14686 if (!htab
->elf
.dynamic_sections_created
14687 || h
->elf
.dynindx
== -1
14688 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14689 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
14690 /* This is actually a static link, or it is a
14691 -Bsymbolic link and the symbol is defined
14692 locally, or the symbol was forced to be local
14693 because of a version file. */
14697 indx
= h
->elf
.dynindx
;
14698 unresolved_reloc
= FALSE
;
14700 ent
= h
->elf
.got
.glist
;
14704 if (local_got_ents
== NULL
)
14706 ent
= local_got_ents
[r_symndx
];
14709 for (; ent
!= NULL
; ent
= ent
->next
)
14710 if (ent
->addend
== orig_rel
.r_addend
14711 && ent
->owner
== input_bfd
14712 && ent
->tls_type
== tls_type
)
14718 if (ent
->is_indirect
)
14719 ent
= ent
->got
.ent
;
14720 offp
= &ent
->got
.offset
;
14721 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14725 /* The offset must always be a multiple of 8. We use the
14726 least significant bit to record whether we have already
14727 processed this entry. */
14729 if ((off
& 1) != 0)
14733 /* Generate relocs for the dynamic linker, except in
14734 the case of TLSLD where we'll use one entry per
14742 ? h
->elf
.type
== STT_GNU_IFUNC
14743 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14746 relgot
= htab
->elf
.irelplt
;
14748 htab
->local_ifunc_resolver
= 1;
14749 else if (is_static_defined (&h
->elf
))
14750 htab
->maybe_local_ifunc_resolver
= 1;
14753 || (bfd_link_pic (info
)
14755 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
)
14756 || (tls_type
== (TLS_TLS
| TLS_LD
)
14757 && !h
->elf
.def_dynamic
))
14758 && !(tls_type
== (TLS_TLS
| TLS_TPREL
)
14759 && bfd_link_executable (info
)
14760 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
14761 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14762 if (relgot
!= NULL
)
14764 outrel
.r_offset
= (got
->output_section
->vma
14765 + got
->output_offset
14767 outrel
.r_addend
= addend
;
14768 if (tls_type
& (TLS_LD
| TLS_GD
))
14770 outrel
.r_addend
= 0;
14771 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14772 if (tls_type
== (TLS_TLS
| TLS_GD
))
14774 loc
= relgot
->contents
;
14775 loc
+= (relgot
->reloc_count
++
14776 * sizeof (Elf64_External_Rela
));
14777 bfd_elf64_swap_reloca_out (output_bfd
,
14779 outrel
.r_offset
+= 8;
14780 outrel
.r_addend
= addend
;
14782 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14785 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14786 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14787 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14788 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14789 else if (indx
!= 0)
14790 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14794 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14796 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14798 /* Write the .got section contents for the sake
14800 loc
= got
->contents
+ off
;
14801 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14805 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14807 outrel
.r_addend
+= relocation
;
14808 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14810 if (htab
->elf
.tls_sec
== NULL
)
14811 outrel
.r_addend
= 0;
14813 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14816 loc
= relgot
->contents
;
14817 loc
+= (relgot
->reloc_count
++
14818 * sizeof (Elf64_External_Rela
));
14819 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14822 /* Init the .got section contents here if we're not
14823 emitting a reloc. */
14826 relocation
+= addend
;
14829 if (htab
->elf
.tls_sec
== NULL
)
14833 if (tls_type
& TLS_LD
)
14836 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14837 if (tls_type
& TLS_TPREL
)
14838 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14841 if (tls_type
& (TLS_GD
| TLS_LD
))
14843 bfd_put_64 (output_bfd
, relocation
,
14844 got
->contents
+ off
+ 8);
14848 bfd_put_64 (output_bfd
, relocation
,
14849 got
->contents
+ off
);
14853 if (off
>= (bfd_vma
) -2)
14856 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
14857 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
14861 case R_PPC64_PLT16_HA
:
14862 case R_PPC64_PLT16_HI
:
14863 case R_PPC64_PLT16_LO
:
14864 case R_PPC64_PLT16_LO_DS
:
14865 case R_PPC64_PLT32
:
14866 case R_PPC64_PLT64
:
14867 case R_PPC64_PLTSEQ
:
14868 case R_PPC64_PLTCALL
:
14869 /* Relocation is to the entry for this symbol in the
14870 procedure linkage table. */
14871 unresolved_reloc
= TRUE
;
14873 struct plt_entry
**plt_list
= NULL
;
14875 plt_list
= &h
->elf
.plt
.plist
;
14876 else if (local_got_ents
!= NULL
)
14878 struct plt_entry
**local_plt
= (struct plt_entry
**)
14879 (local_got_ents
+ symtab_hdr
->sh_info
);
14880 plt_list
= local_plt
+ r_symndx
;
14884 struct plt_entry
*ent
;
14886 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
14887 if (ent
->plt
.offset
!= (bfd_vma
) -1
14888 && ent
->addend
== orig_rel
.r_addend
)
14893 plt
= htab
->elf
.splt
;
14894 if (!htab
->elf
.dynamic_sections_created
14896 || h
->elf
.dynindx
== -1)
14899 ? h
->elf
.type
== STT_GNU_IFUNC
14900 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14901 plt
= htab
->elf
.iplt
;
14903 plt
= htab
->pltlocal
;
14905 relocation
= (plt
->output_section
->vma
14906 + plt
->output_offset
14907 + ent
->plt
.offset
);
14908 if (r_type
== R_PPC64_PLT16_HA
14909 || r_type
== R_PPC64_PLT16_HI
14910 || r_type
== R_PPC64_PLT16_LO
14911 || r_type
== R_PPC64_PLT16_LO_DS
)
14913 got
= (elf_gp (output_bfd
)
14914 + htab
->sec_info
[input_section
->id
].toc_off
);
14918 unresolved_reloc
= FALSE
;
14926 /* Relocation value is TOC base. */
14927 relocation
= TOCstart
;
14928 if (r_symndx
== STN_UNDEF
)
14929 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
14930 else if (unresolved_reloc
)
14932 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
14933 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
14935 unresolved_reloc
= TRUE
;
14938 /* TOC16 relocs. We want the offset relative to the TOC base,
14939 which is the address of the start of the TOC plus 0x8000.
14940 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14942 case R_PPC64_TOC16
:
14943 case R_PPC64_TOC16_LO
:
14944 case R_PPC64_TOC16_HI
:
14945 case R_PPC64_TOC16_DS
:
14946 case R_PPC64_TOC16_LO_DS
:
14947 case R_PPC64_TOC16_HA
:
14948 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14951 /* Relocate against the beginning of the section. */
14952 case R_PPC64_SECTOFF
:
14953 case R_PPC64_SECTOFF_LO
:
14954 case R_PPC64_SECTOFF_HI
:
14955 case R_PPC64_SECTOFF_DS
:
14956 case R_PPC64_SECTOFF_LO_DS
:
14957 case R_PPC64_SECTOFF_HA
:
14959 addend
-= sec
->output_section
->vma
;
14962 case R_PPC64_REL16
:
14963 case R_PPC64_REL16_LO
:
14964 case R_PPC64_REL16_HI
:
14965 case R_PPC64_REL16_HA
:
14966 case R_PPC64_REL16_HIGH
:
14967 case R_PPC64_REL16_HIGHA
:
14968 case R_PPC64_REL16_HIGHER
:
14969 case R_PPC64_REL16_HIGHERA
:
14970 case R_PPC64_REL16_HIGHEST
:
14971 case R_PPC64_REL16_HIGHESTA
:
14972 case R_PPC64_REL16DX_HA
:
14975 case R_PPC64_REL14
:
14976 case R_PPC64_REL14_BRNTAKEN
:
14977 case R_PPC64_REL14_BRTAKEN
:
14978 case R_PPC64_REL24
:
14979 case R_PPC64_REL24_NOTOC
:
14982 case R_PPC64_TPREL16
:
14983 case R_PPC64_TPREL16_LO
:
14984 case R_PPC64_TPREL16_HI
:
14985 case R_PPC64_TPREL16_HA
:
14986 case R_PPC64_TPREL16_DS
:
14987 case R_PPC64_TPREL16_LO_DS
:
14988 case R_PPC64_TPREL16_HIGH
:
14989 case R_PPC64_TPREL16_HIGHA
:
14990 case R_PPC64_TPREL16_HIGHER
:
14991 case R_PPC64_TPREL16_HIGHERA
:
14992 case R_PPC64_TPREL16_HIGHEST
:
14993 case R_PPC64_TPREL16_HIGHESTA
:
14995 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14996 && h
->elf
.dynindx
== -1)
14998 /* Make this relocation against an undefined weak symbol
14999 resolve to zero. This is really just a tweak, since
15000 code using weak externs ought to check that they are
15001 defined before using them. */
15002 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
15004 insn
= bfd_get_32 (input_bfd
, p
);
15005 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
15007 bfd_put_32 (input_bfd
, insn
, p
);
15010 if (htab
->elf
.tls_sec
!= NULL
)
15011 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15012 /* The TPREL16 relocs shouldn't really be used in shared
15013 libs or with non-local symbols as that will result in
15014 DT_TEXTREL being set, but support them anyway. */
15017 case R_PPC64_DTPREL16
:
15018 case R_PPC64_DTPREL16_LO
:
15019 case R_PPC64_DTPREL16_HI
:
15020 case R_PPC64_DTPREL16_HA
:
15021 case R_PPC64_DTPREL16_DS
:
15022 case R_PPC64_DTPREL16_LO_DS
:
15023 case R_PPC64_DTPREL16_HIGH
:
15024 case R_PPC64_DTPREL16_HIGHA
:
15025 case R_PPC64_DTPREL16_HIGHER
:
15026 case R_PPC64_DTPREL16_HIGHERA
:
15027 case R_PPC64_DTPREL16_HIGHEST
:
15028 case R_PPC64_DTPREL16_HIGHESTA
:
15029 if (htab
->elf
.tls_sec
!= NULL
)
15030 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15033 case R_PPC64_ADDR64_LOCAL
:
15034 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
15039 case R_PPC64_DTPMOD64
:
15044 case R_PPC64_TPREL64
:
15045 if (htab
->elf
.tls_sec
!= NULL
)
15046 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15049 case R_PPC64_DTPREL64
:
15050 if (htab
->elf
.tls_sec
!= NULL
)
15051 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15052 /* Fall through. */
15054 /* Relocations that may need to be propagated if this is a
15056 case R_PPC64_REL30
:
15057 case R_PPC64_REL32
:
15058 case R_PPC64_REL64
:
15059 case R_PPC64_ADDR14
:
15060 case R_PPC64_ADDR14_BRNTAKEN
:
15061 case R_PPC64_ADDR14_BRTAKEN
:
15062 case R_PPC64_ADDR16
:
15063 case R_PPC64_ADDR16_DS
:
15064 case R_PPC64_ADDR16_HA
:
15065 case R_PPC64_ADDR16_HI
:
15066 case R_PPC64_ADDR16_HIGH
:
15067 case R_PPC64_ADDR16_HIGHA
:
15068 case R_PPC64_ADDR16_HIGHER
:
15069 case R_PPC64_ADDR16_HIGHERA
:
15070 case R_PPC64_ADDR16_HIGHEST
:
15071 case R_PPC64_ADDR16_HIGHESTA
:
15072 case R_PPC64_ADDR16_LO
:
15073 case R_PPC64_ADDR16_LO_DS
:
15074 case R_PPC64_ADDR24
:
15075 case R_PPC64_ADDR32
:
15076 case R_PPC64_ADDR64
:
15077 case R_PPC64_UADDR16
:
15078 case R_PPC64_UADDR32
:
15079 case R_PPC64_UADDR64
:
15081 if ((input_section
->flags
& SEC_ALLOC
) == 0)
15084 if (NO_OPD_RELOCS
&& is_opd
)
15087 if (bfd_link_pic (info
)
15089 || h
->dyn_relocs
!= NULL
)
15090 && ((h
!= NULL
&& pc_dynrelocs (h
))
15091 || must_be_dyn_reloc (info
, r_type
)))
15093 ? h
->dyn_relocs
!= NULL
15094 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
15096 bfd_boolean skip
, relocate
;
15101 /* When generating a dynamic object, these relocations
15102 are copied into the output file to be resolved at run
15108 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
15109 input_section
, rel
->r_offset
);
15110 if (out_off
== (bfd_vma
) -1)
15112 else if (out_off
== (bfd_vma
) -2)
15113 skip
= TRUE
, relocate
= TRUE
;
15114 out_off
+= (input_section
->output_section
->vma
15115 + input_section
->output_offset
);
15116 outrel
.r_offset
= out_off
;
15117 outrel
.r_addend
= rel
->r_addend
;
15119 /* Optimize unaligned reloc use. */
15120 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
15121 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
15122 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
15123 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
15124 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
15125 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
15126 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
15127 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
15128 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
15131 memset (&outrel
, 0, sizeof outrel
);
15132 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
15134 && r_type
!= R_PPC64_TOC
)
15136 indx
= h
->elf
.dynindx
;
15137 BFD_ASSERT (indx
!= -1);
15138 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15142 /* This symbol is local, or marked to become local,
15143 or this is an opd section reloc which must point
15144 at a local function. */
15145 outrel
.r_addend
+= relocation
;
15146 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
15148 if (is_opd
&& h
!= NULL
)
15150 /* Lie about opd entries. This case occurs
15151 when building shared libraries and we
15152 reference a function in another shared
15153 lib. The same thing happens for a weak
15154 definition in an application that's
15155 overridden by a strong definition in a
15156 shared lib. (I believe this is a generic
15157 bug in binutils handling of weak syms.)
15158 In these cases we won't use the opd
15159 entry in this lib. */
15160 unresolved_reloc
= FALSE
;
15163 && r_type
== R_PPC64_ADDR64
15165 ? h
->elf
.type
== STT_GNU_IFUNC
15166 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
15167 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15170 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
15172 /* We need to relocate .opd contents for ld.so.
15173 Prelink also wants simple and consistent rules
15174 for relocs. This make all RELATIVE relocs have
15175 *r_offset equal to r_addend. */
15182 ? h
->elf
.type
== STT_GNU_IFUNC
15183 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15185 info
->callbacks
->einfo
15186 /* xgettext:c-format */
15187 (_("%H: %s for indirect "
15188 "function `%pT' unsupported\n"),
15189 input_bfd
, input_section
, rel
->r_offset
,
15190 ppc64_elf_howto_table
[r_type
]->name
,
15194 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
15196 else if (sec
== NULL
|| sec
->owner
== NULL
)
15198 bfd_set_error (bfd_error_bad_value
);
15205 osec
= sec
->output_section
;
15206 indx
= elf_section_data (osec
)->dynindx
;
15210 if ((osec
->flags
& SEC_READONLY
) == 0
15211 && htab
->elf
.data_index_section
!= NULL
)
15212 osec
= htab
->elf
.data_index_section
;
15214 osec
= htab
->elf
.text_index_section
;
15215 indx
= elf_section_data (osec
)->dynindx
;
15217 BFD_ASSERT (indx
!= 0);
15219 /* We are turning this relocation into one
15220 against a section symbol, so subtract out
15221 the output section's address but not the
15222 offset of the input section in the output
15224 outrel
.r_addend
-= osec
->vma
;
15227 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15231 sreloc
= elf_section_data (input_section
)->sreloc
;
15233 ? h
->elf
.type
== STT_GNU_IFUNC
15234 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15236 sreloc
= htab
->elf
.irelplt
;
15238 htab
->local_ifunc_resolver
= 1;
15239 else if (is_static_defined (&h
->elf
))
15240 htab
->maybe_local_ifunc_resolver
= 1;
15242 if (sreloc
== NULL
)
15245 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
15248 loc
= sreloc
->contents
;
15249 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15250 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
15252 /* If this reloc is against an external symbol, it will
15253 be computed at runtime, so there's no need to do
15254 anything now. However, for the sake of prelink ensure
15255 that the section contents are a known value. */
15258 unresolved_reloc
= FALSE
;
15259 /* The value chosen here is quite arbitrary as ld.so
15260 ignores section contents except for the special
15261 case of .opd where the contents might be accessed
15262 before relocation. Choose zero, as that won't
15263 cause reloc overflow. */
15266 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
15267 to improve backward compatibility with older
15269 if (r_type
== R_PPC64_ADDR64
)
15270 addend
= outrel
.r_addend
;
15271 /* Adjust pc_relative relocs to have zero in *r_offset. */
15272 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
15273 addend
= outrel
.r_offset
;
15279 case R_PPC64_GLOB_DAT
:
15280 case R_PPC64_JMP_SLOT
:
15281 case R_PPC64_JMP_IREL
:
15282 case R_PPC64_RELATIVE
:
15283 /* We shouldn't ever see these dynamic relocs in relocatable
15285 /* Fall through. */
15287 case R_PPC64_PLTGOT16
:
15288 case R_PPC64_PLTGOT16_DS
:
15289 case R_PPC64_PLTGOT16_HA
:
15290 case R_PPC64_PLTGOT16_HI
:
15291 case R_PPC64_PLTGOT16_LO
:
15292 case R_PPC64_PLTGOT16_LO_DS
:
15293 case R_PPC64_PLTREL32
:
15294 case R_PPC64_PLTREL64
:
15295 /* These ones haven't been implemented yet. */
15297 info
->callbacks
->einfo
15298 /* xgettext:c-format */
15299 (_("%P: %pB: %s is not supported for `%pT'\n"),
15301 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
15303 bfd_set_error (bfd_error_invalid_operation
);
15308 /* Multi-instruction sequences that access the TOC can be
15309 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15310 to nop; addi rb,r2,x; */
15316 case R_PPC64_GOT_TLSLD16_HI
:
15317 case R_PPC64_GOT_TLSGD16_HI
:
15318 case R_PPC64_GOT_TPREL16_HI
:
15319 case R_PPC64_GOT_DTPREL16_HI
:
15320 case R_PPC64_GOT16_HI
:
15321 case R_PPC64_TOC16_HI
:
15322 /* These relocs would only be useful if building up an
15323 offset to later add to r2, perhaps in an indexed
15324 addressing mode instruction. Don't try to optimize.
15325 Unfortunately, the possibility of someone building up an
15326 offset like this or even with the HA relocs, means that
15327 we need to check the high insn when optimizing the low
15331 case R_PPC64_PLTCALL
:
15332 if (unresolved_reloc
)
15334 /* No plt entry. Make this into a direct call. */
15335 bfd_byte
*p
= contents
+ rel
->r_offset
;
15336 insn
= bfd_get_32 (input_bfd
, p
);
15338 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
15339 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
15340 unresolved_reloc
= save_unresolved_reloc
;
15341 r_type
= R_PPC64_REL24
;
15345 case R_PPC64_PLTSEQ
:
15346 if (unresolved_reloc
)
15348 unresolved_reloc
= FALSE
;
15353 case R_PPC64_PLT16_HA
:
15354 if (unresolved_reloc
)
15356 unresolved_reloc
= FALSE
;
15359 /* Fall through. */
15360 case R_PPC64_GOT_TLSLD16_HA
:
15361 case R_PPC64_GOT_TLSGD16_HA
:
15362 case R_PPC64_GOT_TPREL16_HA
:
15363 case R_PPC64_GOT_DTPREL16_HA
:
15364 case R_PPC64_GOT16_HA
:
15365 case R_PPC64_TOC16_HA
:
15366 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15367 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15371 p
= contents
+ (rel
->r_offset
& ~3);
15372 bfd_put_32 (input_bfd
, NOP
, p
);
15377 case R_PPC64_PLT16_LO
:
15378 case R_PPC64_PLT16_LO_DS
:
15379 if (unresolved_reloc
)
15381 unresolved_reloc
= FALSE
;
15384 /* Fall through. */
15385 case R_PPC64_GOT_TLSLD16_LO
:
15386 case R_PPC64_GOT_TLSGD16_LO
:
15387 case R_PPC64_GOT_TPREL16_LO_DS
:
15388 case R_PPC64_GOT_DTPREL16_LO_DS
:
15389 case R_PPC64_GOT16_LO
:
15390 case R_PPC64_GOT16_LO_DS
:
15391 case R_PPC64_TOC16_LO
:
15392 case R_PPC64_TOC16_LO_DS
:
15393 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15394 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15396 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15397 insn
= bfd_get_32 (input_bfd
, p
);
15398 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
15400 /* Transform addic to addi when we change reg. */
15401 insn
&= ~((0x3f << 26) | (0x1f << 16));
15402 insn
|= (14u << 26) | (2 << 16);
15406 insn
&= ~(0x1f << 16);
15409 bfd_put_32 (input_bfd
, insn
, p
);
15413 case R_PPC64_TPREL16_HA
:
15414 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15416 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15417 insn
= bfd_get_32 (input_bfd
, p
);
15418 if ((insn
& ((0x3f << 26) | 0x1f << 16))
15419 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15420 /* xgettext:c-format */
15421 info
->callbacks
->minfo
15422 (_("%H: warning: %s unexpected insn %#x.\n"),
15423 input_bfd
, input_section
, rel
->r_offset
,
15424 ppc64_elf_howto_table
[r_type
]->name
, insn
);
15427 bfd_put_32 (input_bfd
, NOP
, p
);
15433 case R_PPC64_TPREL16_LO
:
15434 case R_PPC64_TPREL16_LO_DS
:
15435 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15437 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15438 insn
= bfd_get_32 (input_bfd
, p
);
15439 insn
&= ~(0x1f << 16);
15441 bfd_put_32 (input_bfd
, insn
, p
);
15446 /* Do any further special processing. */
15452 case R_PPC64_REL16_HA
:
15453 case R_PPC64_REL16_HIGHA
:
15454 case R_PPC64_REL16_HIGHERA
:
15455 case R_PPC64_REL16_HIGHESTA
:
15456 case R_PPC64_REL16DX_HA
:
15457 case R_PPC64_ADDR16_HA
:
15458 case R_PPC64_ADDR16_HIGHA
:
15459 case R_PPC64_ADDR16_HIGHERA
:
15460 case R_PPC64_ADDR16_HIGHESTA
:
15461 case R_PPC64_TOC16_HA
:
15462 case R_PPC64_SECTOFF_HA
:
15463 case R_PPC64_TPREL16_HA
:
15464 case R_PPC64_TPREL16_HIGHA
:
15465 case R_PPC64_TPREL16_HIGHERA
:
15466 case R_PPC64_TPREL16_HIGHESTA
:
15467 case R_PPC64_DTPREL16_HA
:
15468 case R_PPC64_DTPREL16_HIGHA
:
15469 case R_PPC64_DTPREL16_HIGHERA
:
15470 case R_PPC64_DTPREL16_HIGHESTA
:
15471 /* It's just possible that this symbol is a weak symbol
15472 that's not actually defined anywhere. In that case,
15473 'sec' would be NULL, and we should leave the symbol
15474 alone (it will be set to zero elsewhere in the link). */
15477 /* Fall through. */
15479 case R_PPC64_GOT16_HA
:
15480 case R_PPC64_PLTGOT16_HA
:
15481 case R_PPC64_PLT16_HA
:
15482 case R_PPC64_GOT_TLSGD16_HA
:
15483 case R_PPC64_GOT_TLSLD16_HA
:
15484 case R_PPC64_GOT_TPREL16_HA
:
15485 case R_PPC64_GOT_DTPREL16_HA
:
15486 /* Add 0x10000 if sign bit in 0:15 is set.
15487 Bits 0:15 are not used. */
15491 case R_PPC64_ADDR16_DS
:
15492 case R_PPC64_ADDR16_LO_DS
:
15493 case R_PPC64_GOT16_DS
:
15494 case R_PPC64_GOT16_LO_DS
:
15495 case R_PPC64_PLT16_LO_DS
:
15496 case R_PPC64_SECTOFF_DS
:
15497 case R_PPC64_SECTOFF_LO_DS
:
15498 case R_PPC64_TOC16_DS
:
15499 case R_PPC64_TOC16_LO_DS
:
15500 case R_PPC64_PLTGOT16_DS
:
15501 case R_PPC64_PLTGOT16_LO_DS
:
15502 case R_PPC64_GOT_TPREL16_DS
:
15503 case R_PPC64_GOT_TPREL16_LO_DS
:
15504 case R_PPC64_GOT_DTPREL16_DS
:
15505 case R_PPC64_GOT_DTPREL16_LO_DS
:
15506 case R_PPC64_TPREL16_DS
:
15507 case R_PPC64_TPREL16_LO_DS
:
15508 case R_PPC64_DTPREL16_DS
:
15509 case R_PPC64_DTPREL16_LO_DS
:
15510 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15512 /* If this reloc is against an lq, lxv, or stxv insn, then
15513 the value must be a multiple of 16. This is somewhat of
15514 a hack, but the "correct" way to do this by defining _DQ
15515 forms of all the _DS relocs bloats all reloc switches in
15516 this file. It doesn't make much sense to use these
15517 relocs in data, so testing the insn should be safe. */
15518 if ((insn
& (0x3f << 26)) == (56u << 26)
15519 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15521 relocation
+= addend
;
15522 addend
= insn
& (mask
^ 3);
15523 if ((relocation
& mask
) != 0)
15525 relocation
^= relocation
& mask
;
15526 info
->callbacks
->einfo
15527 /* xgettext:c-format */
15528 (_("%H: error: %s not a multiple of %u\n"),
15529 input_bfd
, input_section
, rel
->r_offset
,
15530 ppc64_elf_howto_table
[r_type
]->name
,
15532 bfd_set_error (bfd_error_bad_value
);
15539 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15540 because such sections are not SEC_ALLOC and thus ld.so will
15541 not process them. */
15542 howto
= ppc64_elf_howto_table
[(int) r_type
];
15543 if (unresolved_reloc
15544 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15545 && h
->elf
.def_dynamic
)
15546 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15547 rel
->r_offset
) != (bfd_vma
) -1)
15549 info
->callbacks
->einfo
15550 /* xgettext:c-format */
15551 (_("%H: unresolvable %s against `%pT'\n"),
15552 input_bfd
, input_section
, rel
->r_offset
,
15554 h
->elf
.root
.root
.string
);
15558 /* 16-bit fields in insns mostly have signed values, but a
15559 few insns have 16-bit unsigned values. Really, we should
15560 have different reloc types. */
15561 if (howto
->complain_on_overflow
!= complain_overflow_dont
15562 && howto
->dst_mask
== 0xffff
15563 && (input_section
->flags
& SEC_CODE
) != 0)
15565 enum complain_overflow complain
= complain_overflow_signed
;
15567 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15568 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15569 complain
= complain_overflow_bitfield
;
15570 else if (howto
->rightshift
== 0
15571 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15572 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15573 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15574 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15575 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15576 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15577 complain
= complain_overflow_unsigned
;
15578 if (howto
->complain_on_overflow
!= complain
)
15580 alt_howto
= *howto
;
15581 alt_howto
.complain_on_overflow
= complain
;
15582 howto
= &alt_howto
;
15586 if (r_type
== R_PPC64_REL16DX_HA
)
15588 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15589 if (rel
->r_offset
+ 4 > input_section
->size
)
15590 r
= bfd_reloc_outofrange
;
15593 relocation
+= addend
;
15594 relocation
-= (rel
->r_offset
15595 + input_section
->output_offset
15596 + input_section
->output_section
->vma
);
15597 relocation
= (bfd_signed_vma
) relocation
>> 16;
15598 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15600 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15601 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15603 if (relocation
+ 0x8000 > 0xffff)
15604 r
= bfd_reloc_overflow
;
15608 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15609 rel
->r_offset
, relocation
, addend
);
15611 if (r
!= bfd_reloc_ok
)
15613 char *more_info
= NULL
;
15614 const char *reloc_name
= howto
->name
;
15616 if (reloc_dest
!= DEST_NORMAL
)
15618 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15619 if (more_info
!= NULL
)
15621 strcpy (more_info
, reloc_name
);
15622 strcat (more_info
, (reloc_dest
== DEST_OPD
15623 ? " (OPD)" : " (stub)"));
15624 reloc_name
= more_info
;
15628 if (r
== bfd_reloc_overflow
)
15630 /* On code like "if (foo) foo();" don't report overflow
15631 on a branch to zero when foo is undefined. */
15633 && (reloc_dest
== DEST_STUB
15635 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15636 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15637 && is_branch_reloc (r_type
))))
15638 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15639 sym_name
, reloc_name
,
15641 input_bfd
, input_section
,
15646 info
->callbacks
->einfo
15647 /* xgettext:c-format */
15648 (_("%H: %s against `%pT': error %d\n"),
15649 input_bfd
, input_section
, rel
->r_offset
,
15650 reloc_name
, sym_name
, (int) r
);
15653 if (more_info
!= NULL
)
15663 Elf_Internal_Shdr
*rel_hdr
;
15664 size_t deleted
= rel
- wrel
;
15666 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15667 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15668 if (rel_hdr
->sh_size
== 0)
15670 /* It is too late to remove an empty reloc section. Leave
15672 ??? What is wrong with an empty section??? */
15673 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15676 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15677 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15678 input_section
->reloc_count
-= deleted
;
15681 /* If we're emitting relocations, then shortly after this function
15682 returns, reloc offsets and addends for this section will be
15683 adjusted. Worse, reloc symbol indices will be for the output
15684 file rather than the input. Save a copy of the relocs for
15685 opd_entry_value. */
15686 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15689 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15690 rel
= bfd_alloc (input_bfd
, amt
);
15691 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15692 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15695 memcpy (rel
, relocs
, amt
);
15700 /* Adjust the value of any local symbols in opd sections. */
15703 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15704 const char *name ATTRIBUTE_UNUSED
,
15705 Elf_Internal_Sym
*elfsym
,
15706 asection
*input_sec
,
15707 struct elf_link_hash_entry
*h
)
15709 struct _opd_sec_data
*opd
;
15716 opd
= get_opd_info (input_sec
);
15717 if (opd
== NULL
|| opd
->adjust
== NULL
)
15720 value
= elfsym
->st_value
- input_sec
->output_offset
;
15721 if (!bfd_link_relocatable (info
))
15722 value
-= input_sec
->output_section
->vma
;
15724 adjust
= opd
->adjust
[OPD_NDX (value
)];
15728 elfsym
->st_value
+= adjust
;
15732 /* Finish up dynamic symbol handling. We set the contents of various
15733 dynamic sections here. */
15736 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15737 struct bfd_link_info
*info
,
15738 struct elf_link_hash_entry
*h
,
15739 Elf_Internal_Sym
*sym
)
15741 struct ppc_link_hash_table
*htab
;
15742 struct plt_entry
*ent
;
15744 htab
= ppc_hash_table (info
);
15748 if (!htab
->opd_abi
&& !h
->def_regular
)
15749 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15750 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15752 /* Mark the symbol as undefined, rather than as
15753 defined in glink. Leave the value if there were
15754 any relocations where pointer equality matters
15755 (this is a clue for the dynamic linker, to make
15756 function pointer comparisons work between an
15757 application and shared library), otherwise set it
15759 sym
->st_shndx
= SHN_UNDEF
;
15760 if (!h
->pointer_equality_needed
)
15762 else if (!h
->ref_regular_nonweak
)
15764 /* This breaks function pointer comparisons, but
15765 that is better than breaking tests for a NULL
15766 function pointer. */
15774 /* This symbol needs a copy reloc. Set it up. */
15775 Elf_Internal_Rela rela
;
15779 if (h
->dynindx
== -1
15780 || (h
->root
.type
!= bfd_link_hash_defined
15781 && h
->root
.type
!= bfd_link_hash_defweak
)
15782 || htab
->elf
.srelbss
== NULL
15783 || htab
->elf
.sreldynrelro
== NULL
)
15786 rela
.r_offset
= (h
->root
.u
.def
.value
15787 + h
->root
.u
.def
.section
->output_section
->vma
15788 + h
->root
.u
.def
.section
->output_offset
);
15789 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15791 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
15792 srel
= htab
->elf
.sreldynrelro
;
15794 srel
= htab
->elf
.srelbss
;
15795 loc
= srel
->contents
;
15796 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15797 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15803 /* Used to decide how to sort relocs in an optimal manner for the
15804 dynamic linker, before writing them out. */
15806 static enum elf_reloc_type_class
15807 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15808 const asection
*rel_sec
,
15809 const Elf_Internal_Rela
*rela
)
15811 enum elf_ppc64_reloc_type r_type
;
15812 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15814 if (rel_sec
== htab
->elf
.irelplt
)
15815 return reloc_class_ifunc
;
15817 r_type
= ELF64_R_TYPE (rela
->r_info
);
15820 case R_PPC64_RELATIVE
:
15821 return reloc_class_relative
;
15822 case R_PPC64_JMP_SLOT
:
15823 return reloc_class_plt
;
15825 return reloc_class_copy
;
15827 return reloc_class_normal
;
15831 /* Finish up the dynamic sections. */
15834 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15835 struct bfd_link_info
*info
)
15837 struct ppc_link_hash_table
*htab
;
15841 htab
= ppc_hash_table (info
);
15845 dynobj
= htab
->elf
.dynobj
;
15846 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15848 if (htab
->elf
.dynamic_sections_created
)
15850 Elf64_External_Dyn
*dyncon
, *dynconend
;
15852 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15855 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15856 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15857 for (; dyncon
< dynconend
; dyncon
++)
15859 Elf_Internal_Dyn dyn
;
15862 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
15869 case DT_PPC64_GLINK
:
15871 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15872 /* We stupidly defined DT_PPC64_GLINK to be the start
15873 of glink rather than the first entry point, which is
15874 what ld.so needs, and now have a bigger stub to
15875 support automatic multiple TOCs. */
15876 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
15880 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15883 dyn
.d_un
.d_ptr
= s
->vma
;
15887 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
15888 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
15889 if (htab
->has_plt_localentry0
)
15890 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
15893 case DT_PPC64_OPDSZ
:
15894 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15897 dyn
.d_un
.d_val
= s
->size
;
15901 s
= htab
->elf
.splt
;
15902 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15906 s
= htab
->elf
.srelplt
;
15907 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15911 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
15915 if (htab
->local_ifunc_resolver
)
15916 info
->callbacks
->einfo
15917 (_("%X%P: text relocations and GNU indirect "
15918 "functions will result in a segfault at runtime\n"));
15919 else if (htab
->maybe_local_ifunc_resolver
)
15920 info
->callbacks
->einfo
15921 (_("%P: warning: text relocations and GNU indirect "
15922 "functions may result in a segfault at runtime\n"));
15926 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
15930 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
15931 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
15933 /* Fill in the first entry in the global offset table.
15934 We use it to hold the link-time TOCbase. */
15935 bfd_put_64 (output_bfd
,
15936 elf_gp (output_bfd
) + TOC_BASE_OFF
,
15937 htab
->elf
.sgot
->contents
);
15939 /* Set .got entry size. */
15940 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
15944 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
15945 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
15947 /* Set .plt entry size. */
15948 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
15949 = PLT_ENTRY_SIZE (htab
);
15952 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15953 brlt ourselves if emitrelocations. */
15954 if (htab
->brlt
!= NULL
15955 && htab
->brlt
->reloc_count
!= 0
15956 && !_bfd_elf_link_output_relocs (output_bfd
,
15958 elf_section_data (htab
->brlt
)->rela
.hdr
,
15959 elf_section_data (htab
->brlt
)->relocs
,
15963 if (htab
->glink
!= NULL
15964 && htab
->glink
->reloc_count
!= 0
15965 && !_bfd_elf_link_output_relocs (output_bfd
,
15967 elf_section_data (htab
->glink
)->rela
.hdr
,
15968 elf_section_data (htab
->glink
)->relocs
,
15973 if (htab
->glink_eh_frame
!= NULL
15974 && htab
->glink_eh_frame
->size
!= 0
15975 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
15976 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
15977 htab
->glink_eh_frame
,
15978 htab
->glink_eh_frame
->contents
))
15981 /* We need to handle writing out multiple GOT sections ourselves,
15982 since we didn't add them to DYNOBJ. We know dynobj is the first
15984 while ((dynobj
= dynobj
->link
.next
) != NULL
)
15988 if (!is_ppc64_elf (dynobj
))
15991 s
= ppc64_elf_tdata (dynobj
)->got
;
15994 && s
->output_section
!= bfd_abs_section_ptr
15995 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15996 s
->contents
, s
->output_offset
,
15999 s
= ppc64_elf_tdata (dynobj
)->relgot
;
16002 && s
->output_section
!= bfd_abs_section_ptr
16003 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
16004 s
->contents
, s
->output_offset
,
16012 #include "elf64-target.h"
16014 /* FreeBSD support */
16016 #undef TARGET_LITTLE_SYM
16017 #undef TARGET_LITTLE_NAME
16019 #undef TARGET_BIG_SYM
16020 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
16021 #undef TARGET_BIG_NAME
16022 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
16025 #define ELF_OSABI ELFOSABI_FREEBSD
16028 #define elf64_bed elf64_powerpc_fbsd_bed
16030 #include "elf64-target.h"