1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2018 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 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
824 HOW (R_PPC64_REL16DX_HA
, 2, 16, 0x1fffc1, 16, TRUE
, signed,
827 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
828 HOW (R_PPC64_16DX_HA
, 2, 16, 0x1fffc1, 16, FALSE
, signed,
831 /* Like R_PPC64_ADDR16_HI, but no overflow. */
832 HOW (R_PPC64_ADDR16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
833 bfd_elf_generic_reloc
),
835 /* Like R_PPC64_ADDR16_HA, but no overflow. */
836 HOW (R_PPC64_ADDR16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
839 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
840 HOW (R_PPC64_DTPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
841 ppc64_elf_unhandled_reloc
),
843 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
844 HOW (R_PPC64_DTPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
845 ppc64_elf_unhandled_reloc
),
847 /* Like R_PPC64_TPREL16_HI, but no overflow. */
848 HOW (R_PPC64_TPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
849 ppc64_elf_unhandled_reloc
),
851 /* Like R_PPC64_TPREL16_HA, but no overflow. */
852 HOW (R_PPC64_TPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
853 ppc64_elf_unhandled_reloc
),
855 /* Marker reloc on ELFv2 large-model function entry. */
856 HOW (R_PPC64_ENTRY
, 2, 32, 0, 0, FALSE
, dont
,
857 bfd_elf_generic_reloc
),
859 /* Like ADDR64, but use local entry point of function. */
860 HOW (R_PPC64_ADDR64_LOCAL
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
861 bfd_elf_generic_reloc
),
863 /* GNU extension to record C++ vtable hierarchy. */
864 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, FALSE
, dont
,
867 /* GNU extension to record C++ vtable member usage. */
868 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, FALSE
, dont
,
873 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
877 ppc_howto_init (void)
879 unsigned int i
, type
;
881 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
883 type
= ppc64_elf_howto_raw
[i
].type
;
884 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
885 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
889 static reloc_howto_type
*
890 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
891 bfd_reloc_code_real_type code
)
893 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
895 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
896 /* Initialize howto table if needed. */
902 /* xgettext:c-format */
903 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
905 bfd_set_error (bfd_error_bad_value
);
908 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
910 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
912 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
914 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
916 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
918 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
920 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
922 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
924 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
926 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
928 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
930 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
932 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
934 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
936 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
938 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
940 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
942 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
944 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
946 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
948 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
950 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
952 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
954 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
956 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
958 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
960 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
962 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
964 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
966 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
968 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
970 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
972 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
974 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
976 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
978 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
980 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
982 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
984 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
986 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
988 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
990 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
992 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
994 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
996 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
998 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1000 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1002 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1004 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1006 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1008 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1010 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1012 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1014 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1016 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1018 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1020 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1022 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1024 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1026 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1028 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1030 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1032 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1034 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1036 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1038 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1040 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1042 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1044 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1046 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1048 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1050 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1052 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1054 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1056 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1058 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1060 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1062 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1064 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1066 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1068 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1070 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1072 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1074 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1076 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1078 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1080 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1082 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1084 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1086 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1088 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1090 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1092 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1094 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1096 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1098 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1100 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1102 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1104 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1106 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1108 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1110 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1112 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1114 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1116 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1118 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1120 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1122 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1124 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1126 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1128 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1130 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1132 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1134 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1136 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1138 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1140 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1142 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1146 return ppc64_elf_howto_table
[r
];
1149 static reloc_howto_type
*
1150 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1155 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1156 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1157 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1158 return &ppc64_elf_howto_raw
[i
];
1163 /* Set the howto pointer for a PowerPC ELF reloc. */
1166 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1167 Elf_Internal_Rela
*dst
)
1171 /* Initialize howto table if needed. */
1172 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1175 type
= ELF64_R_TYPE (dst
->r_info
);
1176 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1178 /* xgettext:c-format */
1179 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1181 bfd_set_error (bfd_error_bad_value
);
1184 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1185 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1187 /* xgettext:c-format */
1188 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1190 bfd_set_error (bfd_error_bad_value
);
1197 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1199 static bfd_reloc_status_type
1200 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1201 void *data
, asection
*input_section
,
1202 bfd
*output_bfd
, char **error_message
)
1204 enum elf_ppc64_reloc_type r_type
;
1206 bfd_size_type octets
;
1209 /* If this is a relocatable link (output_bfd test tells us), just
1210 call the generic function. Any adjustment will be done at final
1212 if (output_bfd
!= NULL
)
1213 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1214 input_section
, output_bfd
, error_message
);
1216 /* Adjust the addend for sign extension of the low 16 bits.
1217 We won't actually be using the low 16 bits, so trashing them
1219 reloc_entry
->addend
+= 0x8000;
1220 r_type
= reloc_entry
->howto
->type
;
1221 if (r_type
!= R_PPC64_REL16DX_HA
)
1222 return bfd_reloc_continue
;
1225 if (!bfd_is_com_section (symbol
->section
))
1226 value
= symbol
->value
;
1227 value
+= (reloc_entry
->addend
1228 + symbol
->section
->output_offset
1229 + symbol
->section
->output_section
->vma
);
1230 value
-= (reloc_entry
->address
1231 + input_section
->output_offset
1232 + input_section
->output_section
->vma
);
1233 value
= (bfd_signed_vma
) value
>> 16;
1235 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1236 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1238 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1239 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1240 if (value
+ 0x8000 > 0xffff)
1241 return bfd_reloc_overflow
;
1242 return bfd_reloc_ok
;
1245 static bfd_reloc_status_type
1246 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1247 void *data
, asection
*input_section
,
1248 bfd
*output_bfd
, char **error_message
)
1250 if (output_bfd
!= NULL
)
1251 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1252 input_section
, output_bfd
, error_message
);
1254 if (strcmp (symbol
->section
->name
, ".opd") == 0
1255 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1257 bfd_vma dest
= opd_entry_value (symbol
->section
,
1258 symbol
->value
+ reloc_entry
->addend
,
1260 if (dest
!= (bfd_vma
) -1)
1261 reloc_entry
->addend
= dest
- (symbol
->value
1262 + symbol
->section
->output_section
->vma
1263 + symbol
->section
->output_offset
);
1267 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1269 if (symbol
->section
->owner
!= abfd
1270 && symbol
->section
->owner
!= NULL
1271 && abiversion (symbol
->section
->owner
) >= 2)
1275 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1277 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1279 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1281 elfsym
= (elf_symbol_type
*) symdef
;
1287 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1289 return bfd_reloc_continue
;
1292 static bfd_reloc_status_type
1293 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1294 void *data
, asection
*input_section
,
1295 bfd
*output_bfd
, char **error_message
)
1298 enum elf_ppc64_reloc_type r_type
;
1299 bfd_size_type octets
;
1300 /* Assume 'at' branch hints. */
1301 bfd_boolean is_isa_v2
= TRUE
;
1303 /* If this is a relocatable link (output_bfd test tells us), just
1304 call the generic function. Any adjustment will be done at final
1306 if (output_bfd
!= NULL
)
1307 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1308 input_section
, output_bfd
, error_message
);
1310 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1311 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1312 insn
&= ~(0x01 << 21);
1313 r_type
= reloc_entry
->howto
->type
;
1314 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1315 || r_type
== R_PPC64_REL14_BRTAKEN
)
1316 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1320 /* Set 'a' bit. This is 0b00010 in BO field for branch
1321 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1322 for branch on CTR insns (BO == 1a00t or 1a01t). */
1323 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1325 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1335 if (!bfd_is_com_section (symbol
->section
))
1336 target
= symbol
->value
;
1337 target
+= symbol
->section
->output_section
->vma
;
1338 target
+= symbol
->section
->output_offset
;
1339 target
+= reloc_entry
->addend
;
1341 from
= (reloc_entry
->address
1342 + input_section
->output_offset
1343 + input_section
->output_section
->vma
);
1345 /* Invert 'y' bit if not the default. */
1346 if ((bfd_signed_vma
) (target
- from
) < 0)
1349 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1351 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1352 input_section
, output_bfd
, error_message
);
1355 static bfd_reloc_status_type
1356 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1357 void *data
, asection
*input_section
,
1358 bfd
*output_bfd
, char **error_message
)
1360 /* If this is a relocatable link (output_bfd test tells us), just
1361 call the generic function. Any adjustment will be done at final
1363 if (output_bfd
!= NULL
)
1364 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1365 input_section
, output_bfd
, error_message
);
1367 /* Subtract the symbol section base address. */
1368 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1369 return bfd_reloc_continue
;
1372 static bfd_reloc_status_type
1373 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1374 void *data
, asection
*input_section
,
1375 bfd
*output_bfd
, char **error_message
)
1377 /* If this is a relocatable link (output_bfd test tells us), just
1378 call the generic function. Any adjustment will be done at final
1380 if (output_bfd
!= NULL
)
1381 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1382 input_section
, output_bfd
, error_message
);
1384 /* Subtract the symbol section base address. */
1385 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1387 /* Adjust the addend for sign extension of the low 16 bits. */
1388 reloc_entry
->addend
+= 0x8000;
1389 return bfd_reloc_continue
;
1392 static bfd_reloc_status_type
1393 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1394 void *data
, asection
*input_section
,
1395 bfd
*output_bfd
, char **error_message
)
1399 /* If this is a relocatable link (output_bfd test tells us), just
1400 call the generic function. Any adjustment will be done at final
1402 if (output_bfd
!= NULL
)
1403 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1404 input_section
, output_bfd
, error_message
);
1406 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1408 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1410 /* Subtract the TOC base address. */
1411 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1412 return bfd_reloc_continue
;
1415 static bfd_reloc_status_type
1416 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1417 void *data
, asection
*input_section
,
1418 bfd
*output_bfd
, char **error_message
)
1422 /* If this is a relocatable link (output_bfd test tells us), just
1423 call the generic function. Any adjustment will be done at final
1425 if (output_bfd
!= NULL
)
1426 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1427 input_section
, output_bfd
, error_message
);
1429 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1431 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1433 /* Subtract the TOC base address. */
1434 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1436 /* Adjust the addend for sign extension of the low 16 bits. */
1437 reloc_entry
->addend
+= 0x8000;
1438 return bfd_reloc_continue
;
1441 static bfd_reloc_status_type
1442 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1443 void *data
, asection
*input_section
,
1444 bfd
*output_bfd
, char **error_message
)
1447 bfd_size_type octets
;
1449 /* If this is a relocatable link (output_bfd test tells us), just
1450 call the generic function. Any adjustment will be done at final
1452 if (output_bfd
!= NULL
)
1453 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1454 input_section
, output_bfd
, error_message
);
1456 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1458 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1460 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1461 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1462 return bfd_reloc_ok
;
1465 static bfd_reloc_status_type
1466 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1467 void *data
, asection
*input_section
,
1468 bfd
*output_bfd
, char **error_message
)
1470 /* If this is a relocatable link (output_bfd test tells us), just
1471 call the generic function. Any adjustment will be done at final
1473 if (output_bfd
!= NULL
)
1474 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1475 input_section
, output_bfd
, error_message
);
1477 if (error_message
!= NULL
)
1479 static char buf
[60];
1480 sprintf (buf
, "generic linker can't handle %s",
1481 reloc_entry
->howto
->name
);
1482 *error_message
= buf
;
1484 return bfd_reloc_dangerous
;
1487 /* Track GOT entries needed for a given symbol. We might need more
1488 than one got entry per symbol. */
1491 struct got_entry
*next
;
1493 /* The symbol addend that we'll be placing in the GOT. */
1496 /* Unlike other ELF targets, we use separate GOT entries for the same
1497 symbol referenced from different input files. This is to support
1498 automatic multiple TOC/GOT sections, where the TOC base can vary
1499 from one input file to another. After partitioning into TOC groups
1500 we merge entries within the group.
1502 Point to the BFD owning this GOT entry. */
1505 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1506 TLS_TPREL or TLS_DTPREL for tls entries. */
1507 unsigned char tls_type
;
1509 /* Non-zero if got.ent points to real entry. */
1510 unsigned char is_indirect
;
1512 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1515 bfd_signed_vma refcount
;
1517 struct got_entry
*ent
;
1521 /* The same for PLT. */
1524 struct plt_entry
*next
;
1530 bfd_signed_vma refcount
;
1535 struct ppc64_elf_obj_tdata
1537 struct elf_obj_tdata elf
;
1539 /* Shortcuts to dynamic linker sections. */
1543 /* Used during garbage collection. We attach global symbols defined
1544 on removed .opd entries to this section so that the sym is removed. */
1545 asection
*deleted_section
;
1547 /* TLS local dynamic got entry handling. Support for multiple GOT
1548 sections means we potentially need one of these for each input bfd. */
1549 struct got_entry tlsld_got
;
1553 /* A copy of relocs before they are modified for --emit-relocs. */
1554 Elf_Internal_Rela
*relocs
;
1556 /* Section contents. */
1560 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1561 the reloc to be in the range -32768 to 32767. */
1562 unsigned int has_small_toc_reloc
: 1;
1564 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1565 instruction not one we handle. */
1566 unsigned int unexpected_toc_insn
: 1;
1569 #define ppc64_elf_tdata(bfd) \
1570 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1572 #define ppc64_tlsld_got(bfd) \
1573 (&ppc64_elf_tdata (bfd)->tlsld_got)
1575 #define is_ppc64_elf(bfd) \
1576 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1577 && elf_object_id (bfd) == PPC64_ELF_DATA)
1579 /* Override the generic function because we store some extras. */
1582 ppc64_elf_mkobject (bfd
*abfd
)
1584 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1588 /* Fix bad default arch selected for a 64 bit input bfd when the
1589 default is 32 bit. Also select arch based on apuinfo. */
1592 ppc64_elf_object_p (bfd
*abfd
)
1594 if (!abfd
->arch_info
->the_default
)
1597 if (abfd
->arch_info
->bits_per_word
== 32)
1599 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1601 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1603 /* Relies on arch after 32 bit default being 64 bit default. */
1604 abfd
->arch_info
= abfd
->arch_info
->next
;
1605 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1608 return _bfd_elf_ppc_set_arch (abfd
);
1611 /* Support for core dump NOTE sections. */
1614 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1616 size_t offset
, size
;
1618 if (note
->descsz
!= 504)
1622 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1625 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1631 /* Make a ".reg/999" section. */
1632 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1633 size
, note
->descpos
+ offset
);
1637 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1639 if (note
->descsz
!= 136)
1642 elf_tdata (abfd
)->core
->pid
1643 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1644 elf_tdata (abfd
)->core
->program
1645 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1646 elf_tdata (abfd
)->core
->command
1647 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1653 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1663 char data
[136] ATTRIBUTE_NONSTRING
;
1666 va_start (ap
, note_type
);
1667 memset (data
, 0, sizeof (data
));
1668 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1669 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1671 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1672 -Wstringop-truncation:
1673 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1675 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1677 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1678 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1682 return elfcore_write_note (abfd
, buf
, bufsiz
,
1683 "CORE", note_type
, data
, sizeof (data
));
1694 va_start (ap
, note_type
);
1695 memset (data
, 0, 112);
1696 pid
= va_arg (ap
, long);
1697 bfd_put_32 (abfd
, pid
, data
+ 32);
1698 cursig
= va_arg (ap
, int);
1699 bfd_put_16 (abfd
, cursig
, data
+ 12);
1700 greg
= va_arg (ap
, const void *);
1701 memcpy (data
+ 112, greg
, 384);
1702 memset (data
+ 496, 0, 8);
1704 return elfcore_write_note (abfd
, buf
, bufsiz
,
1705 "CORE", note_type
, data
, sizeof (data
));
1710 /* Add extra PPC sections. */
1712 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1714 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1715 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1716 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1717 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1718 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1719 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1720 { NULL
, 0, 0, 0, 0 }
1723 enum _ppc64_sec_type
{
1729 struct _ppc64_elf_section_data
1731 struct bfd_elf_section_data elf
;
1735 /* An array with one entry for each opd function descriptor,
1736 and some spares since opd entries may be either 16 or 24 bytes. */
1737 #define OPD_NDX(OFF) ((OFF) >> 4)
1738 struct _opd_sec_data
1740 /* Points to the function code section for local opd entries. */
1741 asection
**func_sec
;
1743 /* After editing .opd, adjust references to opd local syms. */
1747 /* An array for toc sections, indexed by offset/8. */
1748 struct _toc_sec_data
1750 /* Specifies the relocation symbol index used at a given toc offset. */
1753 /* And the relocation addend. */
1758 enum _ppc64_sec_type sec_type
:2;
1760 /* Flag set when small branches are detected. Used to
1761 select suitable defaults for the stub group size. */
1762 unsigned int has_14bit_branch
:1;
1764 /* Flag set when PLTCALL relocs are detected. */
1765 unsigned int has_pltcall
:1;
1768 #define ppc64_elf_section_data(sec) \
1769 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
1772 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1774 if (!sec
->used_by_bfd
)
1776 struct _ppc64_elf_section_data
*sdata
;
1777 bfd_size_type amt
= sizeof (*sdata
);
1779 sdata
= bfd_zalloc (abfd
, amt
);
1782 sec
->used_by_bfd
= sdata
;
1785 return _bfd_elf_new_section_hook (abfd
, sec
);
1788 static struct _opd_sec_data
*
1789 get_opd_info (asection
* sec
)
1792 && ppc64_elf_section_data (sec
) != NULL
1793 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
1794 return &ppc64_elf_section_data (sec
)->u
.opd
;
1798 /* Parameters for the qsort hook. */
1799 static bfd_boolean synthetic_relocatable
;
1800 static asection
*synthetic_opd
;
1802 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
1805 compare_symbols (const void *ap
, const void *bp
)
1807 const asymbol
*a
= *(const asymbol
**) ap
;
1808 const asymbol
*b
= *(const asymbol
**) bp
;
1810 /* Section symbols first. */
1811 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
1813 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
1816 /* then .opd symbols. */
1817 if (synthetic_opd
!= NULL
)
1819 if (strcmp (a
->section
->name
, ".opd") == 0
1820 && strcmp (b
->section
->name
, ".opd") != 0)
1822 if (strcmp (a
->section
->name
, ".opd") != 0
1823 && strcmp (b
->section
->name
, ".opd") == 0)
1827 /* then other code symbols. */
1828 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1829 == (SEC_CODE
| SEC_ALLOC
))
1830 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1831 != (SEC_CODE
| SEC_ALLOC
)))
1834 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1835 != (SEC_CODE
| SEC_ALLOC
))
1836 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1837 == (SEC_CODE
| SEC_ALLOC
)))
1840 if (synthetic_relocatable
)
1842 if (a
->section
->id
< b
->section
->id
)
1845 if (a
->section
->id
> b
->section
->id
)
1849 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
1852 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
1855 /* For syms with the same value, prefer strong dynamic global function
1856 syms over other syms. */
1857 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
1860 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
1863 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
1866 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
1869 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
1872 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
1875 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
1878 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
1884 /* Search SYMS for a symbol of the given VALUE. */
1887 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
1891 if (id
== (unsigned) -1)
1895 mid
= (lo
+ hi
) >> 1;
1896 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
1898 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
1908 mid
= (lo
+ hi
) >> 1;
1909 if (syms
[mid
]->section
->id
< id
)
1911 else if (syms
[mid
]->section
->id
> id
)
1913 else if (syms
[mid
]->value
< value
)
1915 else if (syms
[mid
]->value
> value
)
1925 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
1927 bfd_vma vma
= *(bfd_vma
*) ptr
;
1928 return ((section
->flags
& SEC_ALLOC
) != 0
1929 && section
->vma
<= vma
1930 && vma
< section
->vma
+ section
->size
);
1933 /* Create synthetic symbols, effectively restoring "dot-symbol" function
1934 entry syms. Also generate @plt symbols for the glink branch table.
1935 Returns count of synthetic symbols in RET or -1 on error. */
1938 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
1939 long static_count
, asymbol
**static_syms
,
1940 long dyn_count
, asymbol
**dyn_syms
,
1946 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
1947 asection
*opd
= NULL
;
1948 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
1950 int abi
= abiversion (abfd
);
1956 opd
= bfd_get_section_by_name (abfd
, ".opd");
1957 if (opd
== NULL
&& abi
== 1)
1969 symcount
= static_count
;
1971 symcount
+= dyn_count
;
1975 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
1979 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
1981 /* Use both symbol tables. */
1982 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
1983 memcpy (syms
+ static_count
, dyn_syms
,
1984 (dyn_count
+ 1) * sizeof (*syms
));
1986 else if (!relocatable
&& static_count
== 0)
1987 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
1989 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
1991 /* Trim uninteresting symbols. Interesting symbols are section,
1992 function, and notype symbols. */
1993 for (i
= 0, j
= 0; i
< symcount
; ++i
)
1994 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
1995 | BSF_RELC
| BSF_SRELC
)) == 0)
1996 syms
[j
++] = syms
[i
];
1999 synthetic_relocatable
= relocatable
;
2000 synthetic_opd
= opd
;
2001 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2003 if (!relocatable
&& symcount
> 1)
2005 /* Trim duplicate syms, since we may have merged the normal
2006 and dynamic symbols. Actually, we only care about syms
2007 that have different values, so trim any with the same
2008 value. Don't consider ifunc and ifunc resolver symbols
2009 duplicates however, because GDB wants to know whether a
2010 text symbol is an ifunc resolver. */
2011 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2013 const asymbol
*s0
= syms
[i
- 1];
2014 const asymbol
*s1
= syms
[i
];
2016 if ((s0
->value
+ s0
->section
->vma
2017 != s1
->value
+ s1
->section
->vma
)
2018 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2019 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2020 syms
[j
++] = syms
[i
];
2026 /* Note that here and in compare_symbols we can't compare opd and
2027 sym->section directly. With separate debug info files, the
2028 symbols will be extracted from the debug file while abfd passed
2029 to this function is the real binary. */
2030 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2034 for (; i
< symcount
; ++i
)
2035 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2036 | SEC_THREAD_LOCAL
))
2037 != (SEC_CODE
| SEC_ALLOC
))
2038 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2042 for (; i
< symcount
; ++i
)
2043 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2047 for (; i
< symcount
; ++i
)
2048 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2052 for (; i
< symcount
; ++i
)
2053 if (((syms
[i
]->section
->flags
2054 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2055 != (SEC_CODE
| SEC_ALLOC
))
2063 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2068 if (opdsymend
== secsymend
)
2071 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2072 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2076 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2083 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2087 while (r
< opd
->relocation
+ relcount
2088 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2091 if (r
== opd
->relocation
+ relcount
)
2094 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2097 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2100 sym
= *r
->sym_ptr_ptr
;
2101 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2102 sym
->section
->id
, sym
->value
+ r
->addend
))
2105 size
+= sizeof (asymbol
);
2106 size
+= strlen (syms
[i
]->name
) + 2;
2112 s
= *ret
= bfd_malloc (size
);
2119 names
= (char *) (s
+ count
);
2121 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2125 while (r
< opd
->relocation
+ relcount
2126 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2129 if (r
== opd
->relocation
+ relcount
)
2132 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2135 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2138 sym
= *r
->sym_ptr_ptr
;
2139 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2140 sym
->section
->id
, sym
->value
+ r
->addend
))
2145 s
->flags
|= BSF_SYNTHETIC
;
2146 s
->section
= sym
->section
;
2147 s
->value
= sym
->value
+ r
->addend
;
2150 len
= strlen (syms
[i
]->name
);
2151 memcpy (names
, syms
[i
]->name
, len
+ 1);
2153 /* Have udata.p point back to the original symbol this
2154 synthetic symbol was derived from. */
2155 s
->udata
.p
= syms
[i
];
2162 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2163 bfd_byte
*contents
= NULL
;
2165 size_t plt_count
= 0;
2166 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2167 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2170 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2172 free_contents_and_exit_err
:
2174 free_contents_and_exit
:
2181 for (i
= secsymend
; i
< opdsymend
; ++i
)
2185 /* Ignore bogus symbols. */
2186 if (syms
[i
]->value
> opd
->size
- 8)
2189 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2190 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2193 size
+= sizeof (asymbol
);
2194 size
+= strlen (syms
[i
]->name
) + 2;
2198 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2200 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2202 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2204 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2206 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2207 goto free_contents_and_exit_err
;
2209 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2210 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2213 extdynend
= extdyn
+ dynamic
->size
;
2214 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2216 Elf_Internal_Dyn dyn
;
2217 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2219 if (dyn
.d_tag
== DT_NULL
)
2222 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2224 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2225 See comment in ppc64_elf_finish_dynamic_sections. */
2226 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2227 /* The .glink section usually does not survive the final
2228 link; search for the section (usually .text) where the
2229 glink stubs now reside. */
2230 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2241 /* Determine __glink trampoline by reading the relative branch
2242 from the first glink stub. */
2244 unsigned int off
= 0;
2246 while (bfd_get_section_contents (abfd
, glink
, buf
,
2247 glink_vma
+ off
- glink
->vma
, 4))
2249 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2251 if ((insn
& ~0x3fffffc) == 0)
2254 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2263 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2265 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2268 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2269 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
2270 goto free_contents_and_exit_err
;
2272 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
2273 size
+= plt_count
* sizeof (asymbol
);
2275 p
= relplt
->relocation
;
2276 for (i
= 0; i
< plt_count
; i
++, p
++)
2278 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2280 size
+= sizeof ("+0x") - 1 + 16;
2286 goto free_contents_and_exit
;
2287 s
= *ret
= bfd_malloc (size
);
2289 goto free_contents_and_exit_err
;
2291 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2293 for (i
= secsymend
; i
< opdsymend
; ++i
)
2297 if (syms
[i
]->value
> opd
->size
- 8)
2300 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2301 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2305 asection
*sec
= abfd
->sections
;
2312 size_t mid
= (lo
+ hi
) >> 1;
2313 if (syms
[mid
]->section
->vma
< ent
)
2315 else if (syms
[mid
]->section
->vma
> ent
)
2319 sec
= syms
[mid
]->section
;
2324 if (lo
>= hi
&& lo
> codesecsym
)
2325 sec
= syms
[lo
- 1]->section
;
2327 for (; sec
!= NULL
; sec
= sec
->next
)
2331 /* SEC_LOAD may not be set if SEC is from a separate debug
2333 if ((sec
->flags
& SEC_ALLOC
) == 0)
2335 if ((sec
->flags
& SEC_CODE
) != 0)
2338 s
->flags
|= BSF_SYNTHETIC
;
2339 s
->value
= ent
- s
->section
->vma
;
2342 len
= strlen (syms
[i
]->name
);
2343 memcpy (names
, syms
[i
]->name
, len
+ 1);
2345 /* Have udata.p point back to the original symbol this
2346 synthetic symbol was derived from. */
2347 s
->udata
.p
= syms
[i
];
2353 if (glink
!= NULL
&& relplt
!= NULL
)
2357 /* Add a symbol for the main glink trampoline. */
2358 memset (s
, 0, sizeof *s
);
2360 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2362 s
->value
= resolv_vma
- glink
->vma
;
2364 memcpy (names
, "__glink_PLTresolve",
2365 sizeof ("__glink_PLTresolve"));
2366 names
+= sizeof ("__glink_PLTresolve");
2371 /* FIXME: It would be very much nicer to put sym@plt on the
2372 stub rather than on the glink branch table entry. The
2373 objdump disassembler would then use a sensible symbol
2374 name on plt calls. The difficulty in doing so is
2375 a) finding the stubs, and,
2376 b) matching stubs against plt entries, and,
2377 c) there can be multiple stubs for a given plt entry.
2379 Solving (a) could be done by code scanning, but older
2380 ppc64 binaries used different stubs to current code.
2381 (b) is the tricky one since you need to known the toc
2382 pointer for at least one function that uses a pic stub to
2383 be able to calculate the plt address referenced.
2384 (c) means gdb would need to set multiple breakpoints (or
2385 find the glink branch itself) when setting breakpoints
2386 for pending shared library loads. */
2387 p
= relplt
->relocation
;
2388 for (i
= 0; i
< plt_count
; i
++, p
++)
2392 *s
= **p
->sym_ptr_ptr
;
2393 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2394 we are defining a symbol, ensure one of them is set. */
2395 if ((s
->flags
& BSF_LOCAL
) == 0)
2396 s
->flags
|= BSF_GLOBAL
;
2397 s
->flags
|= BSF_SYNTHETIC
;
2399 s
->value
= glink_vma
- glink
->vma
;
2402 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2403 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2407 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2408 names
+= sizeof ("+0x") - 1;
2409 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2410 names
+= strlen (names
);
2412 memcpy (names
, "@plt", sizeof ("@plt"));
2413 names
+= sizeof ("@plt");
2433 /* The following functions are specific to the ELF linker, while
2434 functions above are used generally. Those named ppc64_elf_* are
2435 called by the main ELF linker code. They appear in this file more
2436 or less in the order in which they are called. eg.
2437 ppc64_elf_check_relocs is called early in the link process,
2438 ppc64_elf_finish_dynamic_sections is one of the last functions
2441 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2442 functions have both a function code symbol and a function descriptor
2443 symbol. A call to foo in a relocatable object file looks like:
2450 The function definition in another object file might be:
2454 . .quad .TOC.@tocbase
2460 When the linker resolves the call during a static link, the branch
2461 unsurprisingly just goes to .foo and the .opd information is unused.
2462 If the function definition is in a shared library, things are a little
2463 different: The call goes via a plt call stub, the opd information gets
2464 copied to the plt, and the linker patches the nop.
2472 . std 2,40(1) # in practice, the call stub
2473 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2474 . addi 11,11,Lfoo@toc@l # this is the general idea
2482 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2484 The "reloc ()" notation is supposed to indicate that the linker emits
2485 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2488 What are the difficulties here? Well, firstly, the relocations
2489 examined by the linker in check_relocs are against the function code
2490 sym .foo, while the dynamic relocation in the plt is emitted against
2491 the function descriptor symbol, foo. Somewhere along the line, we need
2492 to carefully copy dynamic link information from one symbol to the other.
2493 Secondly, the generic part of the elf linker will make .foo a dynamic
2494 symbol as is normal for most other backends. We need foo dynamic
2495 instead, at least for an application final link. However, when
2496 creating a shared library containing foo, we need to have both symbols
2497 dynamic so that references to .foo are satisfied during the early
2498 stages of linking. Otherwise the linker might decide to pull in a
2499 definition from some other object, eg. a static library.
2501 Update: As of August 2004, we support a new convention. Function
2502 calls may use the function descriptor symbol, ie. "bl foo". This
2503 behaves exactly as "bl .foo". */
2505 /* Of those relocs that might be copied as dynamic relocs, this
2506 function selects those that must be copied when linking a shared
2507 library or PIE, even when the symbol is local. */
2510 must_be_dyn_reloc (struct bfd_link_info
*info
,
2511 enum elf_ppc64_reloc_type r_type
)
2516 /* Only relative relocs can be resolved when the object load
2517 address isn't fixed. DTPREL64 is excluded because the
2518 dynamic linker needs to differentiate global dynamic from
2519 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2527 case R_PPC64_TPREL16
:
2528 case R_PPC64_TPREL16_LO
:
2529 case R_PPC64_TPREL16_HI
:
2530 case R_PPC64_TPREL16_HA
:
2531 case R_PPC64_TPREL16_DS
:
2532 case R_PPC64_TPREL16_LO_DS
:
2533 case R_PPC64_TPREL16_HIGH
:
2534 case R_PPC64_TPREL16_HIGHA
:
2535 case R_PPC64_TPREL16_HIGHER
:
2536 case R_PPC64_TPREL16_HIGHERA
:
2537 case R_PPC64_TPREL16_HIGHEST
:
2538 case R_PPC64_TPREL16_HIGHESTA
:
2539 case R_PPC64_TPREL64
:
2540 /* These relocations are relative but in a shared library the
2541 linker doesn't know the thread pointer base. */
2542 return bfd_link_dll (info
);
2546 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2547 copying dynamic variables from a shared lib into an app's dynbss
2548 section, and instead use a dynamic relocation to point into the
2549 shared lib. With code that gcc generates, it's vital that this be
2550 enabled; In the PowerPC64 ABI, the address of a function is actually
2551 the address of a function descriptor, which resides in the .opd
2552 section. gcc uses the descriptor directly rather than going via the
2553 GOT as some other ABI's do, which means that initialized function
2554 pointers must reference the descriptor. Thus, a function pointer
2555 initialized to the address of a function in a shared library will
2556 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2557 redefines the function descriptor symbol to point to the copy. This
2558 presents a problem as a plt entry for that function is also
2559 initialized from the function descriptor symbol and the copy reloc
2560 may not be initialized first. */
2561 #define ELIMINATE_COPY_RELOCS 1
2563 /* Section name for stubs is the associated section name plus this
2565 #define STUB_SUFFIX ".stub"
2568 ppc_stub_long_branch:
2569 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2570 destination, but a 24 bit branch in a stub section will reach.
2573 ppc_stub_plt_branch:
2574 Similar to the above, but a 24 bit branch in the stub section won't
2575 reach its destination.
2576 . addis %r11,%r2,xxx@toc@ha
2577 . ld %r12,xxx@toc@l(%r11)
2582 Used to call a function in a shared library. If it so happens that
2583 the plt entry referenced crosses a 64k boundary, then an extra
2584 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2585 ppc_stub_plt_call_r2save starts with "std %r2,40(%r1)".
2586 . addis %r11,%r2,xxx@toc@ha
2587 . ld %r12,xxx+0@toc@l(%r11)
2589 . ld %r2,xxx+8@toc@l(%r11)
2590 . ld %r11,xxx+16@toc@l(%r11)
2593 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2594 code to adjust the value and save r2 to support multiple toc sections.
2595 A ppc_stub_long_branch with an r2 offset looks like:
2597 . addis %r2,%r2,off@ha
2598 . addi %r2,%r2,off@l
2601 A ppc_stub_plt_branch with an r2 offset looks like:
2603 . addis %r11,%r2,xxx@toc@ha
2604 . ld %r12,xxx@toc@l(%r11)
2605 . addis %r2,%r2,off@ha
2606 . addi %r2,%r2,off@l
2610 All of the above stubs are shown as their ELFv1 variants. ELFv2
2611 variants exist too, simpler for plt calls since a new toc pointer
2612 and static chain are not loaded by the stub. In addition, ELFv2
2613 has some more complex stubs to handle calls marked with NOTOC
2614 relocs from functions where r2 is not a valid toc pointer. These
2615 come in two flavours, the ones shown below, and _both variants that
2616 start with "std %r2,24(%r1)" to save r2 in the unlikely event that
2617 one call is from a function where r2 is used as the toc pointer but
2618 needs a toc adjusting stub for small-model multi-toc, and another
2619 call is from a function where r2 is not valid.
2620 ppc_stub_long_branch_notoc:
2626 . addis %r12,%r11,dest-1b@ha
2627 . addi %r12,%r12,dest-1b@l
2630 ppc_stub_plt_branch_notoc:
2636 . lis %r12,xxx-1b@highest
2637 . ori %r12,%r12,xxx-1b@higher
2639 . oris %r12,%r12,xxx-1b@high
2640 . ori %r12,%r12,xxx-1b@l
2641 . add %r12,%r11,%r12
2645 ppc_stub_plt_call_notoc:
2651 . lis %r12,xxx-1b@highest
2652 . ori %r12,%r12,xxx-1b@higher
2654 . oris %r12,%r12,xxx-1b@high
2655 . ori %r12,%r12,xxx-1b@l
2656 . ldx %r12,%r11,%r12
2660 In cases where the high instructions would add zero, they are
2661 omitted and following instructions modified in some cases.
2663 For a given stub group (a set of sections all using the same toc
2664 pointer value) there will be just one stub type used for any
2665 particular function symbol. For example, if printf is called from
2666 code with the tocsave optimization (ie. r2 saved in function
2667 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2668 and from other code without the tocsave optimization requiring a
2669 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
2670 type will be created. Calls with the tocsave optimization will
2671 enter this stub after the instruction saving r2. A similar
2672 situation exists when calls are marked with R_PPC64_REL24_NOTOC
2673 relocations. These require a ppc_stub_plt_call_notoc linkage stub
2674 to call an external function like printf. If other calls to printf
2675 require a ppc_stub_plt_call linkage stub then a single
2676 ppc_stub_plt_call_notoc linkage stub will be used for both types of
2677 call. If other calls to printf require a ppc_stub_plt_call_r2save
2678 linkage stub then a single ppc_stub_plt_call_both linkage stub will
2679 be created and calls not requiring r2 to be saved will enter the
2680 stub after the r2 save instruction. There is an analogous
2681 hierarchy of long branch and plt branch stubs for local call
2687 ppc_stub_long_branch
,
2688 ppc_stub_long_branch_r2off
,
2689 ppc_stub_long_branch_notoc
,
2690 ppc_stub_long_branch_both
, /* r2off and notoc variants both needed. */
2691 ppc_stub_plt_branch
,
2692 ppc_stub_plt_branch_r2off
,
2693 ppc_stub_plt_branch_notoc
,
2694 ppc_stub_plt_branch_both
,
2696 ppc_stub_plt_call_r2save
,
2697 ppc_stub_plt_call_notoc
,
2698 ppc_stub_plt_call_both
,
2699 ppc_stub_global_entry
,
2703 /* Information on stub grouping. */
2706 /* The stub section. */
2708 /* This is the section to which stubs in the group will be attached. */
2711 struct map_stub
*next
;
2712 /* Whether to emit a copy of register save/restore functions in this
2715 /* Current offset within stubs after the insn restoring lr in a
2716 _notoc or _both stub using bcl for pc-relative addressing, or
2717 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
2718 unsigned int lr_restore
;
2719 /* Accumulated size of EH info emitted to describe return address
2720 if stubs modify lr. Does not include 17 byte FDE header. */
2721 unsigned int eh_size
;
2722 /* Offset in glink_eh_frame to the start of EH info for this group. */
2723 unsigned int eh_base
;
2726 struct ppc_stub_hash_entry
2728 /* Base hash table entry structure. */
2729 struct bfd_hash_entry root
;
2731 enum ppc_stub_type stub_type
;
2733 /* Group information. */
2734 struct map_stub
*group
;
2736 /* Offset within stub_sec of the beginning of this stub. */
2737 bfd_vma stub_offset
;
2739 /* Given the symbol's value and its section we can determine its final
2740 value when building the stubs (so the stub knows where to jump. */
2741 bfd_vma target_value
;
2742 asection
*target_section
;
2744 /* The symbol table entry, if any, that this was derived from. */
2745 struct ppc_link_hash_entry
*h
;
2746 struct plt_entry
*plt_ent
;
2749 unsigned char symtype
;
2751 /* Symbol st_other. */
2752 unsigned char other
;
2755 struct ppc_branch_hash_entry
2757 /* Base hash table entry structure. */
2758 struct bfd_hash_entry root
;
2760 /* Offset within branch lookup table. */
2761 unsigned int offset
;
2763 /* Generation marker. */
2767 /* Used to track dynamic relocations for local symbols. */
2768 struct ppc_dyn_relocs
2770 struct ppc_dyn_relocs
*next
;
2772 /* The input section of the reloc. */
2775 /* Total number of relocs copied for the input section. */
2776 unsigned int count
: 31;
2778 /* Whether this entry is for STT_GNU_IFUNC symbols. */
2779 unsigned int ifunc
: 1;
2782 struct ppc_link_hash_entry
2784 struct elf_link_hash_entry elf
;
2788 /* A pointer to the most recently used stub hash entry against this
2790 struct ppc_stub_hash_entry
*stub_cache
;
2792 /* A pointer to the next symbol starting with a '.' */
2793 struct ppc_link_hash_entry
*next_dot_sym
;
2796 /* Track dynamic relocs copied for this symbol. */
2797 struct elf_dyn_relocs
*dyn_relocs
;
2799 /* Link between function code and descriptor symbols. */
2800 struct ppc_link_hash_entry
*oh
;
2802 /* Flag function code and descriptor symbols. */
2803 unsigned int is_func
:1;
2804 unsigned int is_func_descriptor
:1;
2805 unsigned int fake
:1;
2807 /* Whether global opd/toc sym has been adjusted or not.
2808 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
2809 should be set for all globals defined in any opd/toc section. */
2810 unsigned int adjust_done
:1;
2812 /* Set if this is an out-of-line register save/restore function,
2813 with non-standard calling convention. */
2814 unsigned int save_res
:1;
2816 /* Set if a duplicate symbol with non-zero localentry is detected,
2817 even when the duplicate symbol does not provide a definition. */
2818 unsigned int non_zero_localentry
:1;
2820 /* Contexts in which symbol is used in the GOT (or TOC).
2821 Bits are or'd into the mask as the corresponding relocs are
2822 encountered during check_relocs, with TLS_TLS being set when any
2823 of the other TLS bits are set. tls_optimize clears bits when
2824 optimizing to indicate the corresponding GOT entry type is not
2825 needed. If set, TLS_TLS is never cleared. tls_optimize may also
2826 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
2827 separate flag rather than setting TPREL just for convenience in
2828 distinguishing the two cases.
2829 These flags are also kept for local symbols. */
2830 #define TLS_TLS 1 /* Any TLS reloc. */
2831 #define TLS_GD 2 /* GD reloc. */
2832 #define TLS_LD 4 /* LD reloc. */
2833 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
2834 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
2835 #define TLS_MARK 32 /* __tls_get_addr call marked. */
2836 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2837 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
2838 unsigned char tls_mask
;
2840 /* The above field is also used to mark function symbols. In which
2841 case TLS_TLS will be 0. */
2842 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
2843 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
2844 #define NON_GOT 256 /* local symbol plt, not stored. */
2847 /* ppc64 ELF linker hash table. */
2849 struct ppc_link_hash_table
2851 struct elf_link_hash_table elf
;
2853 /* The stub hash table. */
2854 struct bfd_hash_table stub_hash_table
;
2856 /* Another hash table for plt_branch stubs. */
2857 struct bfd_hash_table branch_hash_table
;
2859 /* Hash table for function prologue tocsave. */
2860 htab_t tocsave_htab
;
2862 /* Various options and other info passed from the linker. */
2863 struct ppc64_elf_params
*params
;
2865 /* The size of sec_info below. */
2866 unsigned int sec_info_arr_size
;
2868 /* Per-section array of extra section info. Done this way rather
2869 than as part of ppc64_elf_section_data so we have the info for
2870 non-ppc64 sections. */
2873 /* Along with elf_gp, specifies the TOC pointer used by this section. */
2878 /* The section group that this section belongs to. */
2879 struct map_stub
*group
;
2880 /* A temp section list pointer. */
2885 /* Linked list of groups. */
2886 struct map_stub
*group
;
2888 /* Temp used when calculating TOC pointers. */
2891 asection
*toc_first_sec
;
2893 /* Used when adding symbols. */
2894 struct ppc_link_hash_entry
*dot_syms
;
2896 /* Shortcuts to get to dynamic linker sections. */
2898 asection
*global_entry
;
2901 asection
*relpltlocal
;
2904 asection
*glink_eh_frame
;
2906 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
2907 struct ppc_link_hash_entry
*tls_get_addr
;
2908 struct ppc_link_hash_entry
*tls_get_addr_fd
;
2910 /* The size of reliplt used by got entry relocs. */
2911 bfd_size_type got_reli_size
;
2914 unsigned long stub_count
[ppc_stub_global_entry
];
2916 /* Number of stubs against global syms. */
2917 unsigned long stub_globals
;
2919 /* Set if we're linking code with function descriptors. */
2920 unsigned int opd_abi
:1;
2922 /* Support for multiple toc sections. */
2923 unsigned int do_multi_toc
:1;
2924 unsigned int multi_toc_needed
:1;
2925 unsigned int second_toc_pass
:1;
2926 unsigned int do_toc_opt
:1;
2928 /* Set if tls optimization is enabled. */
2929 unsigned int do_tls_opt
:1;
2931 /* Set if inline plt calls should be converted to direct calls. */
2932 unsigned int can_convert_all_inline_plt
:1;
2935 unsigned int stub_error
:1;
2937 /* Whether func_desc_adjust needs to be run over symbols. */
2938 unsigned int need_func_desc_adj
:1;
2940 /* Whether there exist local gnu indirect function resolvers,
2941 referenced by dynamic relocations. */
2942 unsigned int local_ifunc_resolver
:1;
2943 unsigned int maybe_local_ifunc_resolver
:1;
2945 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
2946 unsigned int has_plt_localentry0
:1;
2948 /* Incremented every time we size stubs. */
2949 unsigned int stub_iteration
;
2951 /* Small local sym cache. */
2952 struct sym_cache sym_cache
;
2955 /* Rename some of the generic section flags to better document how they
2958 /* Nonzero if this section has TLS related relocations. */
2959 #define has_tls_reloc sec_flg0
2961 /* Nonzero if this section has an old-style call to __tls_get_addr. */
2962 #define has_tls_get_addr_call sec_flg1
2964 /* Nonzero if this section has any toc or got relocs. */
2965 #define has_toc_reloc sec_flg2
2967 /* Nonzero if this section has a call to another section that uses
2969 #define makes_toc_func_call sec_flg3
2971 /* Recursion protection when determining above flag. */
2972 #define call_check_in_progress sec_flg4
2973 #define call_check_done sec_flg5
2975 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2977 #define ppc_hash_table(p) \
2978 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2979 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
2981 #define ppc_stub_hash_lookup(table, string, create, copy) \
2982 ((struct ppc_stub_hash_entry *) \
2983 bfd_hash_lookup ((table), (string), (create), (copy)))
2985 #define ppc_branch_hash_lookup(table, string, create, copy) \
2986 ((struct ppc_branch_hash_entry *) \
2987 bfd_hash_lookup ((table), (string), (create), (copy)))
2989 /* Create an entry in the stub hash table. */
2991 static struct bfd_hash_entry
*
2992 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2993 struct bfd_hash_table
*table
,
2996 /* Allocate the structure if it has not already been allocated by a
3000 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3005 /* Call the allocation method of the superclass. */
3006 entry
= bfd_hash_newfunc (entry
, table
, string
);
3009 struct ppc_stub_hash_entry
*eh
;
3011 /* Initialize the local fields. */
3012 eh
= (struct ppc_stub_hash_entry
*) entry
;
3013 eh
->stub_type
= ppc_stub_none
;
3015 eh
->stub_offset
= 0;
3016 eh
->target_value
= 0;
3017 eh
->target_section
= NULL
;
3026 /* Create an entry in the branch hash table. */
3028 static struct bfd_hash_entry
*
3029 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3030 struct bfd_hash_table
*table
,
3033 /* Allocate the structure if it has not already been allocated by a
3037 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3042 /* Call the allocation method of the superclass. */
3043 entry
= bfd_hash_newfunc (entry
, table
, string
);
3046 struct ppc_branch_hash_entry
*eh
;
3048 /* Initialize the local fields. */
3049 eh
= (struct ppc_branch_hash_entry
*) entry
;
3057 /* Create an entry in a ppc64 ELF linker hash table. */
3059 static struct bfd_hash_entry
*
3060 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3061 struct bfd_hash_table
*table
,
3064 /* Allocate the structure if it has not already been allocated by a
3068 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3073 /* Call the allocation method of the superclass. */
3074 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3077 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3079 memset (&eh
->u
.stub_cache
, 0,
3080 (sizeof (struct ppc_link_hash_entry
)
3081 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3083 /* When making function calls, old ABI code references function entry
3084 points (dot symbols), while new ABI code references the function
3085 descriptor symbol. We need to make any combination of reference and
3086 definition work together, without breaking archive linking.
3088 For a defined function "foo" and an undefined call to "bar":
3089 An old object defines "foo" and ".foo", references ".bar" (possibly
3091 A new object defines "foo" and references "bar".
3093 A new object thus has no problem with its undefined symbols being
3094 satisfied by definitions in an old object. On the other hand, the
3095 old object won't have ".bar" satisfied by a new object.
3097 Keep a list of newly added dot-symbols. */
3099 if (string
[0] == '.')
3101 struct ppc_link_hash_table
*htab
;
3103 htab
= (struct ppc_link_hash_table
*) table
;
3104 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3105 htab
->dot_syms
= eh
;
3112 struct tocsave_entry
3119 tocsave_htab_hash (const void *p
)
3121 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3122 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3126 tocsave_htab_eq (const void *p1
, const void *p2
)
3128 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3129 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3130 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3133 /* Destroy a ppc64 ELF linker hash table. */
3136 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3138 struct ppc_link_hash_table
*htab
;
3140 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3141 if (htab
->tocsave_htab
)
3142 htab_delete (htab
->tocsave_htab
);
3143 bfd_hash_table_free (&htab
->branch_hash_table
);
3144 bfd_hash_table_free (&htab
->stub_hash_table
);
3145 _bfd_elf_link_hash_table_free (obfd
);
3148 /* Create a ppc64 ELF linker hash table. */
3150 static struct bfd_link_hash_table
*
3151 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3153 struct ppc_link_hash_table
*htab
;
3154 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3156 htab
= bfd_zmalloc (amt
);
3160 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3161 sizeof (struct ppc_link_hash_entry
),
3168 /* Init the stub hash table too. */
3169 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3170 sizeof (struct ppc_stub_hash_entry
)))
3172 _bfd_elf_link_hash_table_free (abfd
);
3176 /* And the branch hash table. */
3177 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3178 sizeof (struct ppc_branch_hash_entry
)))
3180 bfd_hash_table_free (&htab
->stub_hash_table
);
3181 _bfd_elf_link_hash_table_free (abfd
);
3185 htab
->tocsave_htab
= htab_try_create (1024,
3189 if (htab
->tocsave_htab
== NULL
)
3191 ppc64_elf_link_hash_table_free (abfd
);
3194 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3196 /* Initializing two fields of the union is just cosmetic. We really
3197 only care about glist, but when compiled on a 32-bit host the
3198 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3199 debugger inspection of these fields look nicer. */
3200 htab
->elf
.init_got_refcount
.refcount
= 0;
3201 htab
->elf
.init_got_refcount
.glist
= NULL
;
3202 htab
->elf
.init_plt_refcount
.refcount
= 0;
3203 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3204 htab
->elf
.init_got_offset
.offset
= 0;
3205 htab
->elf
.init_got_offset
.glist
= NULL
;
3206 htab
->elf
.init_plt_offset
.offset
= 0;
3207 htab
->elf
.init_plt_offset
.glist
= NULL
;
3209 return &htab
->elf
.root
;
3212 /* Create sections for linker generated code. */
3215 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3217 struct ppc_link_hash_table
*htab
;
3220 htab
= ppc_hash_table (info
);
3222 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3223 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3224 if (htab
->params
->save_restore_funcs
)
3226 /* Create .sfpr for code to save and restore fp regs. */
3227 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3229 if (htab
->sfpr
== NULL
3230 || !bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3234 if (bfd_link_relocatable (info
))
3237 /* Create .glink for lazy dynamic linking support. */
3238 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3240 if (htab
->glink
== NULL
3241 || !bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
3244 /* The part of .glink used by global entry stubs, separate so that
3245 it can be aligned appropriately without affecting htab->glink. */
3246 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3248 if (htab
->global_entry
== NULL
3249 || !bfd_set_section_alignment (dynobj
, htab
->global_entry
, 2))
3252 if (!info
->no_ld_generated_unwind_info
)
3254 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3255 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3256 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3259 if (htab
->glink_eh_frame
== NULL
3260 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
3264 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3265 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3266 if (htab
->elf
.iplt
== NULL
3267 || !bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
3270 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3271 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3273 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3274 if (htab
->elf
.irelplt
== NULL
3275 || !bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
3278 /* Create branch lookup table for plt_branch stubs. */
3279 flags
= (SEC_ALLOC
| SEC_LOAD
3280 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3281 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3283 if (htab
->brlt
== NULL
3284 || !bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3287 /* Local plt entries, put in .branch_lt but a separate section for
3289 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3291 if (htab
->pltlocal
== NULL
3292 || !bfd_set_section_alignment (dynobj
, htab
->pltlocal
, 3))
3295 if (!bfd_link_pic (info
))
3298 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3299 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3301 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3302 if (htab
->relbrlt
== NULL
3303 || !bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3307 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3308 if (htab
->relpltlocal
== NULL
3309 || !bfd_set_section_alignment (dynobj
, htab
->relpltlocal
, 3))
3315 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3318 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3319 struct ppc64_elf_params
*params
)
3321 struct ppc_link_hash_table
*htab
;
3323 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3325 /* Always hook our dynamic sections into the first bfd, which is the
3326 linker created stub bfd. This ensures that the GOT header is at
3327 the start of the output TOC section. */
3328 htab
= ppc_hash_table (info
);
3329 htab
->elf
.dynobj
= params
->stub_bfd
;
3330 htab
->params
= params
;
3332 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3335 /* Build a name for an entry in the stub hash table. */
3338 ppc_stub_name (const asection
*input_section
,
3339 const asection
*sym_sec
,
3340 const struct ppc_link_hash_entry
*h
,
3341 const Elf_Internal_Rela
*rel
)
3346 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3347 offsets from a sym as a branch target? In fact, we could
3348 probably assume the addend is always zero. */
3349 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3353 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3354 stub_name
= bfd_malloc (len
);
3355 if (stub_name
== NULL
)
3358 len
= sprintf (stub_name
, "%08x.%s+%x",
3359 input_section
->id
& 0xffffffff,
3360 h
->elf
.root
.root
.string
,
3361 (int) rel
->r_addend
& 0xffffffff);
3365 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3366 stub_name
= bfd_malloc (len
);
3367 if (stub_name
== NULL
)
3370 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3371 input_section
->id
& 0xffffffff,
3372 sym_sec
->id
& 0xffffffff,
3373 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3374 (int) rel
->r_addend
& 0xffffffff);
3376 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3377 stub_name
[len
- 2] = 0;
3381 /* Look up an entry in the stub hash. Stub entries are cached because
3382 creating the stub name takes a bit of time. */
3384 static struct ppc_stub_hash_entry
*
3385 ppc_get_stub_entry (const asection
*input_section
,
3386 const asection
*sym_sec
,
3387 struct ppc_link_hash_entry
*h
,
3388 const Elf_Internal_Rela
*rel
,
3389 struct ppc_link_hash_table
*htab
)
3391 struct ppc_stub_hash_entry
*stub_entry
;
3392 struct map_stub
*group
;
3394 /* If this input section is part of a group of sections sharing one
3395 stub section, then use the id of the first section in the group.
3396 Stub names need to include a section id, as there may well be
3397 more than one stub used to reach say, printf, and we need to
3398 distinguish between them. */
3399 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3403 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3404 && h
->u
.stub_cache
->h
== h
3405 && h
->u
.stub_cache
->group
== group
)
3407 stub_entry
= h
->u
.stub_cache
;
3413 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3414 if (stub_name
== NULL
)
3417 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3418 stub_name
, FALSE
, FALSE
);
3420 h
->u
.stub_cache
= stub_entry
;
3428 /* Add a new stub entry to the stub hash. Not all fields of the new
3429 stub entry are initialised. */
3431 static struct ppc_stub_hash_entry
*
3432 ppc_add_stub (const char *stub_name
,
3434 struct bfd_link_info
*info
)
3436 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3437 struct map_stub
*group
;
3440 struct ppc_stub_hash_entry
*stub_entry
;
3442 group
= htab
->sec_info
[section
->id
].u
.group
;
3443 link_sec
= group
->link_sec
;
3444 stub_sec
= group
->stub_sec
;
3445 if (stub_sec
== NULL
)
3451 namelen
= strlen (link_sec
->name
);
3452 len
= namelen
+ sizeof (STUB_SUFFIX
);
3453 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3457 memcpy (s_name
, link_sec
->name
, namelen
);
3458 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3459 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3460 if (stub_sec
== NULL
)
3462 group
->stub_sec
= stub_sec
;
3465 /* Enter this entry into the linker stub hash table. */
3466 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3468 if (stub_entry
== NULL
)
3470 /* xgettext:c-format */
3471 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3472 section
->owner
, stub_name
);
3476 stub_entry
->group
= group
;
3477 stub_entry
->stub_offset
= 0;
3481 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3482 not already done. */
3485 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3487 asection
*got
, *relgot
;
3489 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3491 if (!is_ppc64_elf (abfd
))
3497 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3500 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3501 | SEC_LINKER_CREATED
);
3503 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3505 || !bfd_set_section_alignment (abfd
, got
, 3))
3508 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3509 flags
| SEC_READONLY
);
3511 || !bfd_set_section_alignment (abfd
, relgot
, 3))
3514 ppc64_elf_tdata (abfd
)->got
= got
;
3515 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3519 /* Follow indirect and warning symbol links. */
3521 static inline struct bfd_link_hash_entry
*
3522 follow_link (struct bfd_link_hash_entry
*h
)
3524 while (h
->type
== bfd_link_hash_indirect
3525 || h
->type
== bfd_link_hash_warning
)
3530 static inline struct elf_link_hash_entry
*
3531 elf_follow_link (struct elf_link_hash_entry
*h
)
3533 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
3536 static inline struct ppc_link_hash_entry
*
3537 ppc_follow_link (struct ppc_link_hash_entry
*h
)
3539 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
3542 /* Merge PLT info on FROM with that on TO. */
3545 move_plt_plist (struct ppc_link_hash_entry
*from
,
3546 struct ppc_link_hash_entry
*to
)
3548 if (from
->elf
.plt
.plist
!= NULL
)
3550 if (to
->elf
.plt
.plist
!= NULL
)
3552 struct plt_entry
**entp
;
3553 struct plt_entry
*ent
;
3555 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3557 struct plt_entry
*dent
;
3559 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3560 if (dent
->addend
== ent
->addend
)
3562 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3569 *entp
= to
->elf
.plt
.plist
;
3572 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3573 from
->elf
.plt
.plist
= NULL
;
3577 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3580 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3581 struct elf_link_hash_entry
*dir
,
3582 struct elf_link_hash_entry
*ind
)
3584 struct ppc_link_hash_entry
*edir
, *eind
;
3586 edir
= (struct ppc_link_hash_entry
*) dir
;
3587 eind
= (struct ppc_link_hash_entry
*) ind
;
3589 edir
->is_func
|= eind
->is_func
;
3590 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3591 edir
->tls_mask
|= eind
->tls_mask
;
3592 if (eind
->oh
!= NULL
)
3593 edir
->oh
= ppc_follow_link (eind
->oh
);
3595 if (edir
->elf
.versioned
!= versioned_hidden
)
3596 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3597 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3598 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3599 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3600 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3601 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3603 /* If we were called to copy over info for a weak sym, don't copy
3604 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
3605 in order to simplify readonly_dynrelocs and save a field in the
3606 symbol hash entry, but that means dyn_relocs can't be used in any
3607 tests about a specific symbol, or affect other symbol flags which
3609 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3612 /* Copy over any dynamic relocs we may have on the indirect sym. */
3613 if (eind
->dyn_relocs
!= NULL
)
3615 if (edir
->dyn_relocs
!= NULL
)
3617 struct elf_dyn_relocs
**pp
;
3618 struct elf_dyn_relocs
*p
;
3620 /* Add reloc counts against the indirect sym to the direct sym
3621 list. Merge any entries against the same section. */
3622 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3624 struct elf_dyn_relocs
*q
;
3626 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3627 if (q
->sec
== p
->sec
)
3629 q
->pc_count
+= p
->pc_count
;
3630 q
->count
+= p
->count
;
3637 *pp
= edir
->dyn_relocs
;
3640 edir
->dyn_relocs
= eind
->dyn_relocs
;
3641 eind
->dyn_relocs
= NULL
;
3644 /* Copy over got entries that we may have already seen to the
3645 symbol which just became indirect. */
3646 if (eind
->elf
.got
.glist
!= NULL
)
3648 if (edir
->elf
.got
.glist
!= NULL
)
3650 struct got_entry
**entp
;
3651 struct got_entry
*ent
;
3653 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3655 struct got_entry
*dent
;
3657 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3658 if (dent
->addend
== ent
->addend
3659 && dent
->owner
== ent
->owner
3660 && dent
->tls_type
== ent
->tls_type
)
3662 dent
->got
.refcount
+= ent
->got
.refcount
;
3669 *entp
= edir
->elf
.got
.glist
;
3672 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3673 eind
->elf
.got
.glist
= NULL
;
3676 /* And plt entries. */
3677 move_plt_plist (eind
, edir
);
3679 if (eind
->elf
.dynindx
!= -1)
3681 if (edir
->elf
.dynindx
!= -1)
3682 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3683 edir
->elf
.dynstr_index
);
3684 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3685 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3686 eind
->elf
.dynindx
= -1;
3687 eind
->elf
.dynstr_index
= 0;
3691 /* Find the function descriptor hash entry from the given function code
3692 hash entry FH. Link the entries via their OH fields. */
3694 static struct ppc_link_hash_entry
*
3695 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
3697 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
3701 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
3703 fdh
= (struct ppc_link_hash_entry
*)
3704 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
3708 fdh
->is_func_descriptor
= 1;
3714 fdh
= ppc_follow_link (fdh
);
3715 fdh
->is_func_descriptor
= 1;
3720 /* Make a fake function descriptor sym for the undefined code sym FH. */
3722 static struct ppc_link_hash_entry
*
3723 make_fdh (struct bfd_link_info
*info
,
3724 struct ppc_link_hash_entry
*fh
)
3726 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
3727 struct bfd_link_hash_entry
*bh
= NULL
;
3728 struct ppc_link_hash_entry
*fdh
;
3729 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
3733 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
3734 fh
->elf
.root
.root
.string
+ 1,
3735 flags
, bfd_und_section_ptr
, 0,
3736 NULL
, FALSE
, FALSE
, &bh
))
3739 fdh
= (struct ppc_link_hash_entry
*) bh
;
3740 fdh
->elf
.non_elf
= 0;
3742 fdh
->is_func_descriptor
= 1;
3749 /* Fix function descriptor symbols defined in .opd sections to be
3753 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
3754 struct bfd_link_info
*info
,
3755 Elf_Internal_Sym
*isym
,
3757 flagword
*flags ATTRIBUTE_UNUSED
,
3762 && strcmp ((*sec
)->name
, ".opd") == 0)
3766 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
3767 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
3768 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
3770 /* If the symbol is a function defined in .opd, and the function
3771 code is in a discarded group, let it appear to be undefined. */
3772 if (!bfd_link_relocatable (info
)
3773 && (*sec
)->reloc_count
!= 0
3774 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
3775 FALSE
) != (bfd_vma
) -1
3776 && discarded_section (code_sec
))
3778 *sec
= bfd_und_section_ptr
;
3779 isym
->st_shndx
= SHN_UNDEF
;
3782 else if (*sec
!= NULL
3783 && strcmp ((*sec
)->name
, ".toc") == 0
3784 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
3786 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3788 htab
->params
->object_in_toc
= 1;
3791 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
3793 if (abiversion (ibfd
) == 0)
3794 set_abiversion (ibfd
, 2);
3795 else if (abiversion (ibfd
) == 1)
3797 _bfd_error_handler (_("symbol '%s' has invalid st_other"
3798 " for ABI version 1"), *name
);
3799 bfd_set_error (bfd_error_bad_value
);
3807 /* Merge non-visibility st_other attributes: local entry point. */
3810 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
3811 const Elf_Internal_Sym
*isym
,
3812 bfd_boolean definition
,
3813 bfd_boolean dynamic
)
3815 if (definition
&& (!dynamic
|| !h
->def_regular
))
3816 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
3817 | ELF_ST_VISIBILITY (h
->other
));
3820 /* Hook called on merging a symbol. We use this to clear "fake" since
3821 we now have a real symbol. */
3824 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
3825 const Elf_Internal_Sym
*isym
,
3826 asection
**psec ATTRIBUTE_UNUSED
,
3827 bfd_boolean newdef ATTRIBUTE_UNUSED
,
3828 bfd_boolean olddef ATTRIBUTE_UNUSED
,
3829 bfd
*oldbfd ATTRIBUTE_UNUSED
,
3830 const asection
*oldsec ATTRIBUTE_UNUSED
)
3832 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
3833 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
3834 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
3838 /* This function makes an old ABI object reference to ".bar" cause the
3839 inclusion of a new ABI object archive that defines "bar".
3840 NAME is a symbol defined in an archive. Return a symbol in the hash
3841 table that might be satisfied by the archive symbols. */
3843 static struct elf_link_hash_entry
*
3844 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
3845 struct bfd_link_info
*info
,
3848 struct elf_link_hash_entry
*h
;
3852 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
3854 /* Don't return this sym if it is a fake function descriptor
3855 created by add_symbol_adjust. */
3856 && !((struct ppc_link_hash_entry
*) h
)->fake
)
3862 len
= strlen (name
);
3863 dot_name
= bfd_alloc (abfd
, len
+ 2);
3864 if (dot_name
== NULL
)
3865 return (struct elf_link_hash_entry
*) -1;
3867 memcpy (dot_name
+ 1, name
, len
+ 1);
3868 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
3869 bfd_release (abfd
, dot_name
);
3873 /* This function satisfies all old ABI object references to ".bar" if a
3874 new ABI object defines "bar". Well, at least, undefined dot symbols
3875 are made weak. This stops later archive searches from including an
3876 object if we already have a function descriptor definition. It also
3877 prevents the linker complaining about undefined symbols.
3878 We also check and correct mismatched symbol visibility here. The
3879 most restrictive visibility of the function descriptor and the
3880 function entry symbol is used. */
3883 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
3885 struct ppc_link_hash_table
*htab
;
3886 struct ppc_link_hash_entry
*fdh
;
3888 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
3889 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
3891 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
3894 if (eh
->elf
.root
.root
.string
[0] != '.')
3897 htab
= ppc_hash_table (info
);
3901 fdh
= lookup_fdh (eh
, htab
);
3903 && !bfd_link_relocatable (info
)
3904 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
3905 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
3906 && eh
->elf
.ref_regular
)
3908 /* Make an undefined function descriptor sym, in order to
3909 pull in an --as-needed shared lib. Archives are handled
3911 fdh
= make_fdh (info
, eh
);
3918 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
3919 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
3921 /* Make both descriptor and entry symbol have the most
3922 constraining visibility of either symbol. */
3923 if (entry_vis
< descr_vis
)
3924 fdh
->elf
.other
+= entry_vis
- descr_vis
;
3925 else if (entry_vis
> descr_vis
)
3926 eh
->elf
.other
+= descr_vis
- entry_vis
;
3928 /* Propagate reference flags from entry symbol to function
3929 descriptor symbol. */
3930 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
3931 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
3932 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
3933 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
3935 if (!fdh
->elf
.forced_local
3936 && fdh
->elf
.dynindx
== -1
3937 && fdh
->elf
.versioned
!= versioned_hidden
3938 && (bfd_link_dll (info
)
3939 || fdh
->elf
.def_dynamic
3940 || fdh
->elf
.ref_dynamic
)
3941 && (eh
->elf
.ref_regular
3942 || eh
->elf
.def_regular
))
3944 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
3952 /* Set up opd section info and abiversion for IBFD, and process list
3953 of dot-symbols we made in link_hash_newfunc. */
3956 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
3958 struct ppc_link_hash_table
*htab
;
3959 struct ppc_link_hash_entry
**p
, *eh
;
3960 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
3962 if (opd
!= NULL
&& opd
->size
!= 0)
3964 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
3965 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
3967 if (abiversion (ibfd
) == 0)
3968 set_abiversion (ibfd
, 1);
3969 else if (abiversion (ibfd
) >= 2)
3971 /* xgettext:c-format */
3972 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
3973 ibfd
, abiversion (ibfd
));
3974 bfd_set_error (bfd_error_bad_value
);
3979 if (is_ppc64_elf (info
->output_bfd
))
3981 /* For input files without an explicit abiversion in e_flags
3982 we should have flagged any with symbol st_other bits set
3983 as ELFv1 and above flagged those with .opd as ELFv2.
3984 Set the output abiversion if not yet set, and for any input
3985 still ambiguous, take its abiversion from the output.
3986 Differences in ABI are reported later. */
3987 if (abiversion (info
->output_bfd
) == 0)
3988 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
3989 else if (abiversion (ibfd
) == 0)
3990 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
3993 htab
= ppc_hash_table (info
);
3997 if (opd
!= NULL
&& opd
->size
!= 0
3998 && (ibfd
->flags
& DYNAMIC
) == 0
3999 && (opd
->flags
& SEC_RELOC
) != 0
4000 && opd
->reloc_count
!= 0
4001 && !bfd_is_abs_section (opd
->output_section
)
4002 && info
->gc_sections
)
4004 /* Garbage collection needs some extra help with .opd sections.
4005 We don't want to necessarily keep everything referenced by
4006 relocs in .opd, as that would keep all functions. Instead,
4007 if we reference an .opd symbol (a function descriptor), we
4008 want to keep the function code symbol's section. This is
4009 easy for global symbols, but for local syms we need to keep
4010 information about the associated function section. */
4012 asection
**opd_sym_map
;
4013 Elf_Internal_Shdr
*symtab_hdr
;
4014 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4016 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4017 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4018 if (opd_sym_map
== NULL
)
4020 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4021 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4025 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4026 rel_end
= relocs
+ opd
->reloc_count
- 1;
4027 for (rel
= relocs
; rel
< rel_end
; rel
++)
4029 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4030 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4032 if (r_type
== R_PPC64_ADDR64
4033 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4034 && r_symndx
< symtab_hdr
->sh_info
)
4036 Elf_Internal_Sym
*isym
;
4039 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
4042 if (elf_section_data (opd
)->relocs
!= relocs
)
4047 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4048 if (s
!= NULL
&& s
!= opd
)
4049 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4052 if (elf_section_data (opd
)->relocs
!= relocs
)
4056 p
= &htab
->dot_syms
;
4057 while ((eh
= *p
) != NULL
)
4060 if (&eh
->elf
== htab
->elf
.hgot
)
4062 else if (htab
->elf
.hgot
== NULL
4063 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4064 htab
->elf
.hgot
= &eh
->elf
;
4065 else if (abiversion (ibfd
) <= 1)
4067 htab
->need_func_desc_adj
= 1;
4068 if (!add_symbol_adjust (eh
, info
))
4071 p
= &eh
->u
.next_dot_sym
;
4076 /* Undo hash table changes when an --as-needed input file is determined
4077 not to be needed. */
4080 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4081 struct bfd_link_info
*info
,
4082 enum notice_asneeded_action act
)
4084 if (act
== notice_not_needed
)
4086 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4091 htab
->dot_syms
= NULL
;
4093 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4096 /* If --just-symbols against a final linked binary, then assume we need
4097 toc adjusting stubs when calling functions defined there. */
4100 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4102 if ((sec
->flags
& SEC_CODE
) != 0
4103 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4104 && is_ppc64_elf (sec
->owner
))
4106 if (abiversion (sec
->owner
) >= 2
4107 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4108 sec
->has_toc_reloc
= 1;
4110 _bfd_elf_link_just_syms (sec
, info
);
4113 static struct plt_entry
**
4114 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4115 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4117 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4118 struct plt_entry
**local_plt
;
4119 unsigned char *local_got_tls_masks
;
4121 if (local_got_ents
== NULL
)
4123 bfd_size_type size
= symtab_hdr
->sh_info
;
4125 size
*= (sizeof (*local_got_ents
)
4126 + sizeof (*local_plt
)
4127 + sizeof (*local_got_tls_masks
));
4128 local_got_ents
= bfd_zalloc (abfd
, size
);
4129 if (local_got_ents
== NULL
)
4131 elf_local_got_ents (abfd
) = local_got_ents
;
4134 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4136 struct got_entry
*ent
;
4138 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4139 if (ent
->addend
== r_addend
4140 && ent
->owner
== abfd
4141 && ent
->tls_type
== tls_type
)
4145 bfd_size_type amt
= sizeof (*ent
);
4146 ent
= bfd_alloc (abfd
, amt
);
4149 ent
->next
= local_got_ents
[r_symndx
];
4150 ent
->addend
= r_addend
;
4152 ent
->tls_type
= tls_type
;
4153 ent
->is_indirect
= FALSE
;
4154 ent
->got
.refcount
= 0;
4155 local_got_ents
[r_symndx
] = ent
;
4157 ent
->got
.refcount
+= 1;
4160 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4161 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4162 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4164 return local_plt
+ r_symndx
;
4168 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4170 struct plt_entry
*ent
;
4172 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4173 if (ent
->addend
== addend
)
4177 bfd_size_type amt
= sizeof (*ent
);
4178 ent
= bfd_alloc (abfd
, amt
);
4182 ent
->addend
= addend
;
4183 ent
->plt
.refcount
= 0;
4186 ent
->plt
.refcount
+= 1;
4191 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4193 return (r_type
== R_PPC64_REL24
4194 || r_type
== R_PPC64_REL24_NOTOC
4195 || r_type
== R_PPC64_REL14
4196 || r_type
== R_PPC64_REL14_BRTAKEN
4197 || r_type
== R_PPC64_REL14_BRNTAKEN
4198 || r_type
== R_PPC64_ADDR24
4199 || r_type
== R_PPC64_ADDR14
4200 || r_type
== R_PPC64_ADDR14_BRTAKEN
4201 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4202 || r_type
== R_PPC64_PLTCALL
);
4205 /* Relocs on inline plt call sequence insns prior to the call. */
4208 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4210 return (r_type
== R_PPC64_PLT16_HA
4211 || r_type
== R_PPC64_PLT16_HI
4212 || r_type
== R_PPC64_PLT16_LO
4213 || r_type
== R_PPC64_PLT16_LO_DS
4214 || r_type
== R_PPC64_PLTSEQ
);
4217 /* Look through the relocs for a section during the first phase, and
4218 calculate needed space in the global offset table, procedure
4219 linkage table, and dynamic reloc sections. */
4222 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4223 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4225 struct ppc_link_hash_table
*htab
;
4226 Elf_Internal_Shdr
*symtab_hdr
;
4227 struct elf_link_hash_entry
**sym_hashes
;
4228 const Elf_Internal_Rela
*rel
;
4229 const Elf_Internal_Rela
*rel_end
;
4231 struct elf_link_hash_entry
*tga
, *dottga
;
4234 if (bfd_link_relocatable (info
))
4237 /* Don't do anything special with non-loaded, non-alloced sections.
4238 In particular, any relocs in such sections should not affect GOT
4239 and PLT reference counting (ie. we don't allow them to create GOT
4240 or PLT entries), there's no possibility or desire to optimize TLS
4241 relocs, and there's not much point in propagating relocs to shared
4242 libs that the dynamic linker won't relocate. */
4243 if ((sec
->flags
& SEC_ALLOC
) == 0)
4246 BFD_ASSERT (is_ppc64_elf (abfd
));
4248 htab
= ppc_hash_table (info
);
4252 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4253 FALSE
, FALSE
, TRUE
);
4254 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4255 FALSE
, FALSE
, TRUE
);
4256 symtab_hdr
= &elf_symtab_hdr (abfd
);
4257 sym_hashes
= elf_sym_hashes (abfd
);
4259 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4260 rel_end
= relocs
+ sec
->reloc_count
;
4261 for (rel
= relocs
; rel
< rel_end
; rel
++)
4263 unsigned long r_symndx
;
4264 struct elf_link_hash_entry
*h
;
4265 enum elf_ppc64_reloc_type r_type
;
4267 struct _ppc64_elf_section_data
*ppc64_sec
;
4268 struct plt_entry
**ifunc
, **plt_list
;
4270 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4271 if (r_symndx
< symtab_hdr
->sh_info
)
4275 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4276 h
= elf_follow_link (h
);
4278 if (h
== htab
->elf
.hgot
)
4279 sec
->has_toc_reloc
= 1;
4286 if (h
->type
== STT_GNU_IFUNC
)
4289 ifunc
= &h
->plt
.plist
;
4294 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4299 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4301 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4303 NON_GOT
| PLT_IFUNC
);
4309 r_type
= ELF64_R_TYPE (rel
->r_info
);
4314 /* These special tls relocs tie a call to __tls_get_addr with
4315 its parameter symbol. */
4317 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4319 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4321 NON_GOT
| TLS_TLS
| TLS_MARK
))
4323 sec
->has_tls_reloc
= 1;
4326 case R_PPC64_GOT_TLSLD16
:
4327 case R_PPC64_GOT_TLSLD16_LO
:
4328 case R_PPC64_GOT_TLSLD16_HI
:
4329 case R_PPC64_GOT_TLSLD16_HA
:
4330 tls_type
= TLS_TLS
| TLS_LD
;
4333 case R_PPC64_GOT_TLSGD16
:
4334 case R_PPC64_GOT_TLSGD16_LO
:
4335 case R_PPC64_GOT_TLSGD16_HI
:
4336 case R_PPC64_GOT_TLSGD16_HA
:
4337 tls_type
= TLS_TLS
| TLS_GD
;
4340 case R_PPC64_GOT_TPREL16_DS
:
4341 case R_PPC64_GOT_TPREL16_LO_DS
:
4342 case R_PPC64_GOT_TPREL16_HI
:
4343 case R_PPC64_GOT_TPREL16_HA
:
4344 if (bfd_link_dll (info
))
4345 info
->flags
|= DF_STATIC_TLS
;
4346 tls_type
= TLS_TLS
| TLS_TPREL
;
4349 case R_PPC64_GOT_DTPREL16_DS
:
4350 case R_PPC64_GOT_DTPREL16_LO_DS
:
4351 case R_PPC64_GOT_DTPREL16_HI
:
4352 case R_PPC64_GOT_DTPREL16_HA
:
4353 tls_type
= TLS_TLS
| TLS_DTPREL
;
4355 sec
->has_tls_reloc
= 1;
4359 case R_PPC64_GOT16_DS
:
4360 case R_PPC64_GOT16_HA
:
4361 case R_PPC64_GOT16_HI
:
4362 case R_PPC64_GOT16_LO
:
4363 case R_PPC64_GOT16_LO_DS
:
4364 /* This symbol requires a global offset table entry. */
4365 sec
->has_toc_reloc
= 1;
4366 if (r_type
== R_PPC64_GOT_TLSLD16
4367 || r_type
== R_PPC64_GOT_TLSGD16
4368 || r_type
== R_PPC64_GOT_TPREL16_DS
4369 || r_type
== R_PPC64_GOT_DTPREL16_DS
4370 || r_type
== R_PPC64_GOT16
4371 || r_type
== R_PPC64_GOT16_DS
)
4373 htab
->do_multi_toc
= 1;
4374 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4377 if (ppc64_elf_tdata (abfd
)->got
== NULL
4378 && !create_got_section (abfd
, info
))
4383 struct ppc_link_hash_entry
*eh
;
4384 struct got_entry
*ent
;
4386 eh
= (struct ppc_link_hash_entry
*) h
;
4387 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4388 if (ent
->addend
== rel
->r_addend
4389 && ent
->owner
== abfd
4390 && ent
->tls_type
== tls_type
)
4394 bfd_size_type amt
= sizeof (*ent
);
4395 ent
= bfd_alloc (abfd
, amt
);
4398 ent
->next
= eh
->elf
.got
.glist
;
4399 ent
->addend
= rel
->r_addend
;
4401 ent
->tls_type
= tls_type
;
4402 ent
->is_indirect
= FALSE
;
4403 ent
->got
.refcount
= 0;
4404 eh
->elf
.got
.glist
= ent
;
4406 ent
->got
.refcount
+= 1;
4407 eh
->tls_mask
|= tls_type
;
4410 /* This is a global offset table entry for a local symbol. */
4411 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4412 rel
->r_addend
, tls_type
))
4415 /* We may also need a plt entry if the symbol turns out to be
4417 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
4419 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4424 case R_PPC64_PLT16_HA
:
4425 case R_PPC64_PLT16_HI
:
4426 case R_PPC64_PLT16_LO
:
4427 case R_PPC64_PLT16_LO_DS
:
4430 /* This symbol requires a procedure linkage table entry. */
4435 if (h
->root
.root
.string
[0] == '.'
4436 && h
->root
.root
.string
[1] != '\0')
4437 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4438 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= PLT_KEEP
;
4439 plt_list
= &h
->plt
.plist
;
4441 if (plt_list
== NULL
)
4442 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4444 NON_GOT
| PLT_KEEP
);
4445 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4449 /* The following relocations don't need to propagate the
4450 relocation if linking a shared object since they are
4451 section relative. */
4452 case R_PPC64_SECTOFF
:
4453 case R_PPC64_SECTOFF_LO
:
4454 case R_PPC64_SECTOFF_HI
:
4455 case R_PPC64_SECTOFF_HA
:
4456 case R_PPC64_SECTOFF_DS
:
4457 case R_PPC64_SECTOFF_LO_DS
:
4458 case R_PPC64_DTPREL16
:
4459 case R_PPC64_DTPREL16_LO
:
4460 case R_PPC64_DTPREL16_HI
:
4461 case R_PPC64_DTPREL16_HA
:
4462 case R_PPC64_DTPREL16_DS
:
4463 case R_PPC64_DTPREL16_LO_DS
:
4464 case R_PPC64_DTPREL16_HIGH
:
4465 case R_PPC64_DTPREL16_HIGHA
:
4466 case R_PPC64_DTPREL16_HIGHER
:
4467 case R_PPC64_DTPREL16_HIGHERA
:
4468 case R_PPC64_DTPREL16_HIGHEST
:
4469 case R_PPC64_DTPREL16_HIGHESTA
:
4474 case R_PPC64_REL16_LO
:
4475 case R_PPC64_REL16_HI
:
4476 case R_PPC64_REL16_HA
:
4477 case R_PPC64_REL16DX_HA
:
4480 /* Not supported as a dynamic relocation. */
4481 case R_PPC64_ADDR64_LOCAL
:
4482 if (bfd_link_pic (info
))
4484 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
4486 /* xgettext:c-format */
4487 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
4488 "in shared libraries and PIEs\n"),
4489 abfd
, sec
, rel
->r_offset
,
4490 ppc64_elf_howto_table
[r_type
]->name
);
4491 bfd_set_error (bfd_error_bad_value
);
4497 case R_PPC64_TOC16_DS
:
4498 htab
->do_multi_toc
= 1;
4499 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4501 case R_PPC64_TOC16_LO
:
4502 case R_PPC64_TOC16_HI
:
4503 case R_PPC64_TOC16_HA
:
4504 case R_PPC64_TOC16_LO_DS
:
4505 sec
->has_toc_reloc
= 1;
4512 /* This relocation describes the C++ object vtable hierarchy.
4513 Reconstruct it for later use during GC. */
4514 case R_PPC64_GNU_VTINHERIT
:
4515 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4519 /* This relocation describes which C++ vtable entries are actually
4520 used. Record for later use during GC. */
4521 case R_PPC64_GNU_VTENTRY
:
4522 BFD_ASSERT (h
!= NULL
);
4524 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4529 case R_PPC64_REL14_BRTAKEN
:
4530 case R_PPC64_REL14_BRNTAKEN
:
4532 asection
*dest
= NULL
;
4534 /* Heuristic: If jumping outside our section, chances are
4535 we are going to need a stub. */
4538 /* If the sym is weak it may be overridden later, so
4539 don't assume we know where a weak sym lives. */
4540 if (h
->root
.type
== bfd_link_hash_defined
)
4541 dest
= h
->root
.u
.def
.section
;
4545 Elf_Internal_Sym
*isym
;
4547 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4552 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4556 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4560 case R_PPC64_PLTCALL
:
4561 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
4565 case R_PPC64_REL24_NOTOC
:
4571 if (h
->root
.root
.string
[0] == '.'
4572 && h
->root
.root
.string
[1] != '\0')
4573 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4575 if (h
== tga
|| h
== dottga
)
4577 sec
->has_tls_reloc
= 1;
4579 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4580 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4581 /* We have a new-style __tls_get_addr call with
4585 /* Mark this section as having an old-style call. */
4586 sec
->has_tls_get_addr_call
= 1;
4588 plt_list
= &h
->plt
.plist
;
4591 /* We may need a .plt entry if the function this reloc
4592 refers to is in a shared lib. */
4594 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4598 case R_PPC64_ADDR14
:
4599 case R_PPC64_ADDR14_BRNTAKEN
:
4600 case R_PPC64_ADDR14_BRTAKEN
:
4601 case R_PPC64_ADDR24
:
4604 case R_PPC64_TPREL64
:
4605 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4606 if (bfd_link_dll (info
))
4607 info
->flags
|= DF_STATIC_TLS
;
4610 case R_PPC64_DTPMOD64
:
4611 if (rel
+ 1 < rel_end
4612 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4613 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4614 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4616 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4619 case R_PPC64_DTPREL64
:
4620 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4622 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4623 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4624 /* This is the second reloc of a dtpmod, dtprel pair.
4625 Don't mark with TLS_DTPREL. */
4629 sec
->has_tls_reloc
= 1;
4632 struct ppc_link_hash_entry
*eh
;
4633 eh
= (struct ppc_link_hash_entry
*) h
;
4634 eh
->tls_mask
|= tls_type
;
4637 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4638 rel
->r_addend
, tls_type
))
4641 ppc64_sec
= ppc64_elf_section_data (sec
);
4642 if (ppc64_sec
->sec_type
!= sec_toc
)
4646 /* One extra to simplify get_tls_mask. */
4647 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
4648 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
4649 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
4651 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
4652 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
4653 if (ppc64_sec
->u
.toc
.add
== NULL
)
4655 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4656 ppc64_sec
->sec_type
= sec_toc
;
4658 BFD_ASSERT (rel
->r_offset
% 8 == 0);
4659 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
4660 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
4662 /* Mark the second slot of a GD or LD entry.
4663 -1 to indicate GD and -2 to indicate LD. */
4664 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
4665 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
4666 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
4667 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
4670 case R_PPC64_TPREL16
:
4671 case R_PPC64_TPREL16_LO
:
4672 case R_PPC64_TPREL16_HI
:
4673 case R_PPC64_TPREL16_HA
:
4674 case R_PPC64_TPREL16_DS
:
4675 case R_PPC64_TPREL16_LO_DS
:
4676 case R_PPC64_TPREL16_HIGH
:
4677 case R_PPC64_TPREL16_HIGHA
:
4678 case R_PPC64_TPREL16_HIGHER
:
4679 case R_PPC64_TPREL16_HIGHERA
:
4680 case R_PPC64_TPREL16_HIGHEST
:
4681 case R_PPC64_TPREL16_HIGHESTA
:
4682 if (bfd_link_dll (info
))
4683 info
->flags
|= DF_STATIC_TLS
;
4686 case R_PPC64_ADDR64
:
4688 && rel
+ 1 < rel_end
4689 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
4692 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4696 case R_PPC64_ADDR16
:
4697 case R_PPC64_ADDR16_DS
:
4698 case R_PPC64_ADDR16_HA
:
4699 case R_PPC64_ADDR16_HI
:
4700 case R_PPC64_ADDR16_HIGH
:
4701 case R_PPC64_ADDR16_HIGHA
:
4702 case R_PPC64_ADDR16_HIGHER
:
4703 case R_PPC64_ADDR16_HIGHERA
:
4704 case R_PPC64_ADDR16_HIGHEST
:
4705 case R_PPC64_ADDR16_HIGHESTA
:
4706 case R_PPC64_ADDR16_LO
:
4707 case R_PPC64_ADDR16_LO_DS
:
4708 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
4709 && rel
->r_addend
== 0)
4711 /* We may need a .plt entry if this reloc refers to a
4712 function in a shared lib. */
4713 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4715 h
->pointer_equality_needed
= 1;
4722 case R_PPC64_ADDR32
:
4723 case R_PPC64_UADDR16
:
4724 case R_PPC64_UADDR32
:
4725 case R_PPC64_UADDR64
:
4727 if (h
!= NULL
&& !bfd_link_pic (info
))
4728 /* We may need a copy reloc. */
4731 /* Don't propagate .opd relocs. */
4732 if (NO_OPD_RELOCS
&& is_opd
)
4735 /* If we are creating a shared library, and this is a reloc
4736 against a global symbol, or a non PC relative reloc
4737 against a local symbol, then we need to copy the reloc
4738 into the shared library. However, if we are linking with
4739 -Bsymbolic, we do not need to copy a reloc against a
4740 global symbol which is defined in an object we are
4741 including in the link (i.e., DEF_REGULAR is set). At
4742 this point we have not seen all the input files, so it is
4743 possible that DEF_REGULAR is not set now but will be set
4744 later (it is never cleared). In case of a weak definition,
4745 DEF_REGULAR may be cleared later by a strong definition in
4746 a shared library. We account for that possibility below by
4747 storing information in the dyn_relocs field of the hash
4748 table entry. A similar situation occurs when creating
4749 shared libraries and symbol visibility changes render the
4752 If on the other hand, we are creating an executable, we
4753 may need to keep relocations for symbols satisfied by a
4754 dynamic library if we manage to avoid copy relocs for the
4757 if ((bfd_link_pic (info
)
4758 && (must_be_dyn_reloc (info
, r_type
)
4760 && (!SYMBOLIC_BIND (info
, h
)
4761 || h
->root
.type
== bfd_link_hash_defweak
4762 || !h
->def_regular
))))
4763 || (ELIMINATE_COPY_RELOCS
4764 && !bfd_link_pic (info
)
4766 && (h
->root
.type
== bfd_link_hash_defweak
4767 || !h
->def_regular
))
4768 || (!bfd_link_pic (info
)
4771 /* We must copy these reloc types into the output file.
4772 Create a reloc section in dynobj and make room for
4776 sreloc
= _bfd_elf_make_dynamic_reloc_section
4777 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
4783 /* If this is a global symbol, we count the number of
4784 relocations we need for this symbol. */
4787 struct elf_dyn_relocs
*p
;
4788 struct elf_dyn_relocs
**head
;
4790 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4792 if (p
== NULL
|| p
->sec
!= sec
)
4794 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4804 if (!must_be_dyn_reloc (info
, r_type
))
4809 /* Track dynamic relocs needed for local syms too.
4810 We really need local syms available to do this
4812 struct ppc_dyn_relocs
*p
;
4813 struct ppc_dyn_relocs
**head
;
4814 bfd_boolean is_ifunc
;
4817 Elf_Internal_Sym
*isym
;
4819 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4824 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4828 vpp
= &elf_section_data (s
)->local_dynrel
;
4829 head
= (struct ppc_dyn_relocs
**) vpp
;
4830 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
4832 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
4834 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
4836 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4842 p
->ifunc
= is_ifunc
;
4858 /* Merge backend specific data from an object file to the output
4859 object file when linking. */
4862 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
4864 bfd
*obfd
= info
->output_bfd
;
4865 unsigned long iflags
, oflags
;
4867 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
4870 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
4873 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
4876 iflags
= elf_elfheader (ibfd
)->e_flags
;
4877 oflags
= elf_elfheader (obfd
)->e_flags
;
4879 if (iflags
& ~EF_PPC64_ABI
)
4882 /* xgettext:c-format */
4883 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
4884 bfd_set_error (bfd_error_bad_value
);
4887 else if (iflags
!= oflags
&& iflags
!= 0)
4890 /* xgettext:c-format */
4891 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
4892 ibfd
, iflags
, oflags
);
4893 bfd_set_error (bfd_error_bad_value
);
4897 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
4900 /* Merge Tag_compatibility attributes and any common GNU ones. */
4901 return _bfd_elf_merge_object_attributes (ibfd
, info
);
4905 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
4907 /* Print normal ELF private data. */
4908 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4910 if (elf_elfheader (abfd
)->e_flags
!= 0)
4914 fprintf (file
, _("private flags = 0x%lx:"),
4915 elf_elfheader (abfd
)->e_flags
);
4917 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
4918 fprintf (file
, _(" [abiv%ld]"),
4919 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
4926 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4927 of the code entry point, and its section, which must be in the same
4928 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
4931 opd_entry_value (asection
*opd_sec
,
4933 asection
**code_sec
,
4935 bfd_boolean in_code_sec
)
4937 bfd
*opd_bfd
= opd_sec
->owner
;
4938 Elf_Internal_Rela
*relocs
;
4939 Elf_Internal_Rela
*lo
, *hi
, *look
;
4942 /* No relocs implies we are linking a --just-symbols object, or looking
4943 at a final linked executable with addr2line or somesuch. */
4944 if (opd_sec
->reloc_count
== 0)
4946 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
4948 if (contents
== NULL
)
4950 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
4951 return (bfd_vma
) -1;
4952 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
4955 /* PR 17512: file: 64b9dfbb. */
4956 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
4957 return (bfd_vma
) -1;
4959 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
4960 if (code_sec
!= NULL
)
4962 asection
*sec
, *likely
= NULL
;
4968 && val
< sec
->vma
+ sec
->size
)
4974 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4976 && (sec
->flags
& SEC_LOAD
) != 0
4977 && (sec
->flags
& SEC_ALLOC
) != 0)
4982 if (code_off
!= NULL
)
4983 *code_off
= val
- likely
->vma
;
4989 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
4991 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
4993 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
4994 /* PR 17512: file: df8e1fd6. */
4996 return (bfd_vma
) -1;
4998 /* Go find the opd reloc at the sym address. */
5000 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5004 look
= lo
+ (hi
- lo
) / 2;
5005 if (look
->r_offset
< offset
)
5007 else if (look
->r_offset
> offset
)
5011 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5013 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5014 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5016 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5017 asection
*sec
= NULL
;
5019 if (symndx
>= symtab_hdr
->sh_info
5020 && elf_sym_hashes (opd_bfd
) != NULL
)
5022 struct elf_link_hash_entry
**sym_hashes
;
5023 struct elf_link_hash_entry
*rh
;
5025 sym_hashes
= elf_sym_hashes (opd_bfd
);
5026 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5029 rh
= elf_follow_link (rh
);
5030 if (rh
->root
.type
!= bfd_link_hash_defined
5031 && rh
->root
.type
!= bfd_link_hash_defweak
)
5033 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5035 val
= rh
->root
.u
.def
.value
;
5036 sec
= rh
->root
.u
.def
.section
;
5043 Elf_Internal_Sym
*sym
;
5045 if (symndx
< symtab_hdr
->sh_info
)
5047 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5050 size_t symcnt
= symtab_hdr
->sh_info
;
5051 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5056 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5062 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5068 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5071 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5072 val
= sym
->st_value
;
5075 val
+= look
->r_addend
;
5076 if (code_off
!= NULL
)
5078 if (code_sec
!= NULL
)
5080 if (in_code_sec
&& *code_sec
!= sec
)
5085 if (sec
->output_section
!= NULL
)
5086 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5095 /* If the ELF symbol SYM might be a function in SEC, return the
5096 function size and set *CODE_OFF to the function's entry point,
5097 otherwise return zero. */
5099 static bfd_size_type
5100 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5105 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5106 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5110 if (!(sym
->flags
& BSF_SYNTHETIC
))
5111 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
5113 if (strcmp (sym
->section
->name
, ".opd") == 0)
5115 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5116 bfd_vma symval
= sym
->value
;
5119 && opd
->adjust
!= NULL
5120 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5122 /* opd_entry_value will use cached relocs that have been
5123 adjusted, but with raw symbols. That means both local
5124 and global symbols need adjusting. */
5125 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5131 if (opd_entry_value (sym
->section
, symval
,
5132 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
5134 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5135 symbol. This size has nothing to do with the code size of the
5136 function, which is what we're supposed to return, but the
5137 code size isn't available without looking up the dot-sym.
5138 However, doing that would be a waste of time particularly
5139 since elf_find_function will look at the dot-sym anyway.
5140 Now, elf_find_function will keep the largest size of any
5141 function sym found at the code address of interest, so return
5142 1 here to avoid it incorrectly caching a larger function size
5143 for a small function. This does mean we return the wrong
5144 size for a new-ABI function of size 24, but all that does is
5145 disable caching for such functions. */
5151 if (sym
->section
!= sec
)
5153 *code_off
= sym
->value
;
5160 /* Return true if symbol is a strong function defined in an ELFv2
5161 object with st_other localentry bits of zero, ie. its local entry
5162 point coincides with its global entry point. */
5165 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5168 && h
->type
== STT_FUNC
5169 && h
->root
.type
== bfd_link_hash_defined
5170 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5171 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
5172 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5173 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5176 /* Return true if symbol is defined in a regular object file. */
5179 is_static_defined (struct elf_link_hash_entry
*h
)
5181 return ((h
->root
.type
== bfd_link_hash_defined
5182 || h
->root
.type
== bfd_link_hash_defweak
)
5183 && h
->root
.u
.def
.section
!= NULL
5184 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5187 /* If FDH is a function descriptor symbol, return the associated code
5188 entry symbol if it is defined. Return NULL otherwise. */
5190 static struct ppc_link_hash_entry
*
5191 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5193 if (fdh
->is_func_descriptor
)
5195 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5196 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5197 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5203 /* If FH is a function code entry symbol, return the associated
5204 function descriptor symbol if it is defined. Return NULL otherwise. */
5206 static struct ppc_link_hash_entry
*
5207 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5210 && fh
->oh
->is_func_descriptor
)
5212 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5213 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5214 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5220 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
5222 /* Garbage collect sections, after first dealing with dot-symbols. */
5225 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5227 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5229 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5231 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5232 htab
->need_func_desc_adj
= 0;
5234 return bfd_elf_gc_sections (abfd
, info
);
5237 /* Mark all our entry sym sections, both opd and code section. */
5240 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5242 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5243 struct bfd_sym_chain
*sym
;
5248 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5250 struct ppc_link_hash_entry
*eh
, *fh
;
5253 eh
= (struct ppc_link_hash_entry
*)
5254 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5257 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5258 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5261 fh
= defined_code_entry (eh
);
5264 sec
= fh
->elf
.root
.u
.def
.section
;
5265 sec
->flags
|= SEC_KEEP
;
5267 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5268 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5269 eh
->elf
.root
.u
.def
.value
,
5270 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5271 sec
->flags
|= SEC_KEEP
;
5273 sec
= eh
->elf
.root
.u
.def
.section
;
5274 sec
->flags
|= SEC_KEEP
;
5278 /* Mark sections containing dynamically referenced symbols. When
5279 building shared libraries, we must assume that any visible symbol is
5283 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5285 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5286 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5287 struct ppc_link_hash_entry
*fdh
;
5288 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5290 /* Dynamic linking info is on the func descriptor sym. */
5291 fdh
= defined_func_desc (eh
);
5295 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5296 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5297 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5298 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5299 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5300 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5301 && (!bfd_link_executable (info
)
5302 || info
->gc_keep_exported
5303 || info
->export_dynamic
5306 && (*d
->match
) (&d
->head
, NULL
,
5307 eh
->elf
.root
.root
.string
)))
5308 && (eh
->elf
.versioned
>= versioned
5309 || !bfd_hide_sym_by_version (info
->version_info
,
5310 eh
->elf
.root
.root
.string
)))))
5313 struct ppc_link_hash_entry
*fh
;
5315 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5317 /* Function descriptor syms cause the associated
5318 function code sym section to be marked. */
5319 fh
= defined_code_entry (eh
);
5322 code_sec
= fh
->elf
.root
.u
.def
.section
;
5323 code_sec
->flags
|= SEC_KEEP
;
5325 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5326 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5327 eh
->elf
.root
.u
.def
.value
,
5328 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5329 code_sec
->flags
|= SEC_KEEP
;
5335 /* Return the section that should be marked against GC for a given
5339 ppc64_elf_gc_mark_hook (asection
*sec
,
5340 struct bfd_link_info
*info
,
5341 Elf_Internal_Rela
*rel
,
5342 struct elf_link_hash_entry
*h
,
5343 Elf_Internal_Sym
*sym
)
5347 /* Syms return NULL if we're marking .opd, so we avoid marking all
5348 function sections, as all functions are referenced in .opd. */
5350 if (get_opd_info (sec
) != NULL
)
5355 enum elf_ppc64_reloc_type r_type
;
5356 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5358 r_type
= ELF64_R_TYPE (rel
->r_info
);
5361 case R_PPC64_GNU_VTINHERIT
:
5362 case R_PPC64_GNU_VTENTRY
:
5366 switch (h
->root
.type
)
5368 case bfd_link_hash_defined
:
5369 case bfd_link_hash_defweak
:
5370 eh
= (struct ppc_link_hash_entry
*) h
;
5371 fdh
= defined_func_desc (eh
);
5374 /* -mcall-aixdesc code references the dot-symbol on
5375 a call reloc. Mark the function descriptor too
5376 against garbage collection. */
5378 if (fdh
->elf
.is_weakalias
)
5379 weakdef (&fdh
->elf
)->mark
= 1;
5383 /* Function descriptor syms cause the associated
5384 function code sym section to be marked. */
5385 fh
= defined_code_entry (eh
);
5388 /* They also mark their opd section. */
5389 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5391 rsec
= fh
->elf
.root
.u
.def
.section
;
5393 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5394 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5395 eh
->elf
.root
.u
.def
.value
,
5396 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
5397 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5399 rsec
= h
->root
.u
.def
.section
;
5402 case bfd_link_hash_common
:
5403 rsec
= h
->root
.u
.c
.p
->section
;
5407 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5413 struct _opd_sec_data
*opd
;
5415 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5416 opd
= get_opd_info (rsec
);
5417 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5421 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
5428 /* The maximum size of .sfpr. */
5429 #define SFPR_MAX (218*4)
5431 struct sfpr_def_parms
5433 const char name
[12];
5434 unsigned char lo
, hi
;
5435 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
5436 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
5439 /* Auto-generate _save*, _rest* functions in .sfpr.
5440 If STUB_SEC is non-null, define alias symbols in STUB_SEC
5444 sfpr_define (struct bfd_link_info
*info
,
5445 const struct sfpr_def_parms
*parm
,
5448 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5450 size_t len
= strlen (parm
->name
);
5451 bfd_boolean writing
= FALSE
;
5457 memcpy (sym
, parm
->name
, len
);
5460 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5462 struct ppc_link_hash_entry
*h
;
5464 sym
[len
+ 0] = i
/ 10 + '0';
5465 sym
[len
+ 1] = i
% 10 + '0';
5466 h
= (struct ppc_link_hash_entry
*)
5467 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
5468 if (stub_sec
!= NULL
)
5471 && h
->elf
.root
.type
== bfd_link_hash_defined
5472 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
5474 struct elf_link_hash_entry
*s
;
5476 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
5477 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
5480 if (s
->root
.type
== bfd_link_hash_new
5481 || (s
->root
.type
= bfd_link_hash_defined
5482 && s
->root
.u
.def
.section
== stub_sec
))
5484 s
->root
.type
= bfd_link_hash_defined
;
5485 s
->root
.u
.def
.section
= stub_sec
;
5486 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
5487 + h
->elf
.root
.u
.def
.value
);
5490 s
->ref_regular_nonweak
= 1;
5491 s
->forced_local
= 1;
5493 s
->root
.linker_def
= 1;
5501 if (!h
->elf
.def_regular
)
5503 h
->elf
.root
.type
= bfd_link_hash_defined
;
5504 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
5505 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
5506 h
->elf
.type
= STT_FUNC
;
5507 h
->elf
.def_regular
= 1;
5509 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
5511 if (htab
->sfpr
->contents
== NULL
)
5513 htab
->sfpr
->contents
5514 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5515 if (htab
->sfpr
->contents
== NULL
)
5522 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5524 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5526 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5527 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5535 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5537 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5542 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5544 p
= savegpr0 (abfd
, p
, r
);
5545 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5547 bfd_put_32 (abfd
, BLR
, p
);
5552 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5554 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5559 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5561 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5563 p
= restgpr0 (abfd
, p
, r
);
5564 bfd_put_32 (abfd
, MTLR_R0
, p
);
5568 p
= restgpr0 (abfd
, p
, 30);
5569 p
= restgpr0 (abfd
, p
, 31);
5571 bfd_put_32 (abfd
, BLR
, p
);
5576 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5578 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5583 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5585 p
= savegpr1 (abfd
, p
, r
);
5586 bfd_put_32 (abfd
, BLR
, p
);
5591 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5593 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5598 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5600 p
= restgpr1 (abfd
, p
, r
);
5601 bfd_put_32 (abfd
, BLR
, p
);
5606 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5608 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5613 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5615 p
= savefpr (abfd
, p
, r
);
5616 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5618 bfd_put_32 (abfd
, BLR
, p
);
5623 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5625 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5630 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5632 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5634 p
= restfpr (abfd
, p
, r
);
5635 bfd_put_32 (abfd
, MTLR_R0
, p
);
5639 p
= restfpr (abfd
, p
, 30);
5640 p
= restfpr (abfd
, p
, 31);
5642 bfd_put_32 (abfd
, BLR
, p
);
5647 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5649 p
= savefpr (abfd
, p
, r
);
5650 bfd_put_32 (abfd
, BLR
, p
);
5655 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5657 p
= restfpr (abfd
, p
, r
);
5658 bfd_put_32 (abfd
, BLR
, p
);
5663 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
5665 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5667 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
5672 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5674 p
= savevr (abfd
, p
, r
);
5675 bfd_put_32 (abfd
, BLR
, p
);
5680 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
5682 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5684 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
5689 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5691 p
= restvr (abfd
, p
, r
);
5692 bfd_put_32 (abfd
, BLR
, p
);
5696 /* Called via elf_link_hash_traverse to transfer dynamic linking
5697 information on function code symbol entries to their corresponding
5698 function descriptor symbol entries. */
5701 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
5703 struct bfd_link_info
*info
;
5704 struct ppc_link_hash_table
*htab
;
5705 struct ppc_link_hash_entry
*fh
;
5706 struct ppc_link_hash_entry
*fdh
;
5707 bfd_boolean force_local
;
5709 fh
= (struct ppc_link_hash_entry
*) h
;
5710 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
5716 if (fh
->elf
.root
.root
.string
[0] != '.'
5717 || fh
->elf
.root
.root
.string
[1] == '\0')
5721 htab
= ppc_hash_table (info
);
5725 /* Find the corresponding function descriptor symbol. */
5726 fdh
= lookup_fdh (fh
, htab
);
5728 /* Resolve undefined references to dot-symbols as the value
5729 in the function descriptor, if we have one in a regular object.
5730 This is to satisfy cases like ".quad .foo". Calls to functions
5731 in dynamic objects are handled elsewhere. */
5732 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
5733 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5734 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
5735 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5736 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
5737 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
5738 fdh
->elf
.root
.u
.def
.value
,
5739 &fh
->elf
.root
.u
.def
.section
,
5740 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
5742 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
5743 fh
->elf
.forced_local
= 1;
5744 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
5745 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
5748 if (!fh
->elf
.dynamic
)
5750 struct plt_entry
*ent
;
5752 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5753 if (ent
->plt
.refcount
> 0)
5759 /* Create a descriptor as undefined if necessary. */
5761 && !bfd_link_executable (info
)
5762 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
5763 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
5765 fdh
= make_fdh (info
, fh
);
5770 /* We can't support overriding of symbols on a fake descriptor. */
5773 && (fh
->elf
.root
.type
== bfd_link_hash_defined
5774 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
5775 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
5777 /* Transfer dynamic linking information to the function descriptor. */
5780 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
5781 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
5782 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
5783 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
5784 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
5785 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
5786 || fh
->elf
.type
== STT_FUNC
5787 || fh
->elf
.type
== STT_GNU_IFUNC
);
5788 move_plt_plist (fh
, fdh
);
5790 if (!fdh
->elf
.forced_local
5791 && fh
->elf
.dynindx
!= -1)
5792 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5796 /* Now that the info is on the function descriptor, clear the
5797 function code sym info. Any function code syms for which we
5798 don't have a definition in a regular file, we force local.
5799 This prevents a shared library from exporting syms that have
5800 been imported from another library. Function code syms that
5801 are really in the library we must leave global to prevent the
5802 linker dragging in a definition from a static library. */
5803 force_local
= (!fh
->elf
.def_regular
5805 || !fdh
->elf
.def_regular
5806 || fdh
->elf
.forced_local
);
5807 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5812 static const struct sfpr_def_parms save_res_funcs
[] =
5814 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
5815 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
5816 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
5817 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
5818 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
5819 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
5820 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
5821 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
5822 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
5823 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
5824 { "_savevr_", 20, 31, savevr
, savevr_tail
},
5825 { "_restvr_", 20, 31, restvr
, restvr_tail
}
5828 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5829 this hook to a) provide some gcc support functions, and b) transfer
5830 dynamic linking information gathered so far on function code symbol
5831 entries, to their corresponding function descriptor symbol entries. */
5834 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
5835 struct bfd_link_info
*info
)
5837 struct ppc_link_hash_table
*htab
;
5839 htab
= ppc_hash_table (info
);
5843 /* Provide any missing _save* and _rest* functions. */
5844 if (htab
->sfpr
!= NULL
)
5848 htab
->sfpr
->size
= 0;
5849 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
5850 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
5852 if (htab
->sfpr
->size
== 0)
5853 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
5856 if (bfd_link_relocatable (info
))
5859 if (htab
->elf
.hgot
!= NULL
)
5861 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
5862 /* Make .TOC. defined so as to prevent it being made dynamic.
5863 The wrong value here is fixed later in ppc64_elf_set_toc. */
5864 if (!htab
->elf
.hgot
->def_regular
5865 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
5867 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
5868 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
5869 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
5870 htab
->elf
.hgot
->def_regular
= 1;
5871 htab
->elf
.hgot
->root
.linker_def
= 1;
5873 htab
->elf
.hgot
->type
= STT_OBJECT
;
5874 htab
->elf
.hgot
->other
5875 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
5878 if (htab
->need_func_desc_adj
)
5880 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5881 htab
->need_func_desc_adj
= 0;
5887 /* Find dynamic relocs for H that apply to read-only sections. */
5890 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
5892 struct ppc_link_hash_entry
*eh
;
5893 struct elf_dyn_relocs
*p
;
5895 eh
= (struct ppc_link_hash_entry
*) h
;
5896 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5898 asection
*s
= p
->sec
->output_section
;
5900 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5906 /* Return true if we have dynamic relocs against H or any of its weak
5907 aliases, that apply to read-only sections. Cannot be used after
5908 size_dynamic_sections. */
5911 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
5913 struct ppc_link_hash_entry
*eh
;
5915 eh
= (struct ppc_link_hash_entry
*) h
;
5918 if (readonly_dynrelocs (&eh
->elf
))
5920 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
5922 while (eh
!= NULL
&& &eh
->elf
!= h
);
5927 /* Return whether EH has pc-relative dynamic relocs. */
5930 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
5932 struct elf_dyn_relocs
*p
;
5934 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5935 if (p
->pc_count
!= 0)
5940 /* Return true if a global entry stub will be created for H. Valid
5941 for ELFv2 before plt entries have been allocated. */
5944 global_entry_stub (struct elf_link_hash_entry
*h
)
5946 struct plt_entry
*pent
;
5948 if (!h
->pointer_equality_needed
5952 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
5953 if (pent
->plt
.refcount
> 0
5954 && pent
->addend
== 0)
5960 /* Adjust a symbol defined by a dynamic object and referenced by a
5961 regular object. The current definition is in some section of the
5962 dynamic object, but we're not including those sections. We have to
5963 change the definition to something the rest of the link can
5967 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
5968 struct elf_link_hash_entry
*h
)
5970 struct ppc_link_hash_table
*htab
;
5973 htab
= ppc_hash_table (info
);
5977 /* Deal with function syms. */
5978 if (h
->type
== STT_FUNC
5979 || h
->type
== STT_GNU_IFUNC
5982 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
5983 || SYMBOL_CALLS_LOCAL (info
, h
)
5984 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
5985 /* Discard dyn_relocs when non-pic if we've decided that a
5986 function symbol is local and not an ifunc. We keep dynamic
5987 relocs for ifuncs when local rather than always emitting a
5988 plt call stub for them and defining the symbol on the call
5989 stub. We can't do that for ELFv1 anyway (a function symbol
5990 is defined on a descriptor, not code) and it can be faster at
5991 run-time due to not needing to bounce through a stub. The
5992 dyn_relocs for ifuncs will be applied even in a static
5994 if (!bfd_link_pic (info
)
5995 && h
->type
!= STT_GNU_IFUNC
5997 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
5999 /* Clear procedure linkage table information for any symbol that
6000 won't need a .plt entry. */
6001 struct plt_entry
*ent
;
6002 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6003 if (ent
->plt
.refcount
> 0)
6006 || (h
->type
!= STT_GNU_IFUNC
6008 && (htab
->can_convert_all_inline_plt
6009 || (((struct ppc_link_hash_entry
*) h
)->tls_mask
6010 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6012 h
->plt
.plist
= NULL
;
6014 h
->pointer_equality_needed
= 0;
6016 else if (abiversion (info
->output_bfd
) >= 2)
6018 /* Taking a function's address in a read/write section
6019 doesn't require us to define the function symbol in the
6020 executable on a global entry stub. A dynamic reloc can
6021 be used instead. The reason we prefer a few more dynamic
6022 relocs is that calling via a global entry stub costs a
6023 few more instructions, and pointer_equality_needed causes
6024 extra work in ld.so when resolving these symbols. */
6025 if (global_entry_stub (h
))
6027 if (!readonly_dynrelocs (h
))
6029 h
->pointer_equality_needed
= 0;
6030 /* If we haven't seen a branch reloc and the symbol
6031 isn't an ifunc then we don't need a plt entry. */
6033 h
->plt
.plist
= NULL
;
6035 else if (!bfd_link_pic (info
))
6036 /* We are going to be defining the function symbol on the
6037 plt stub, so no dyn_relocs needed when non-pic. */
6038 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6041 /* ELFv2 function symbols can't have copy relocs. */
6044 else if (!h
->needs_plt
6045 && !readonly_dynrelocs (h
))
6047 /* If we haven't seen a branch reloc and the symbol isn't an
6048 ifunc then we don't need a plt entry. */
6049 h
->plt
.plist
= NULL
;
6050 h
->pointer_equality_needed
= 0;
6055 h
->plt
.plist
= NULL
;
6057 /* If this is a weak symbol, and there is a real definition, the
6058 processor independent code will have arranged for us to see the
6059 real definition first, and we can just use the same value. */
6060 if (h
->is_weakalias
)
6062 struct elf_link_hash_entry
*def
= weakdef (h
);
6063 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6064 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6065 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6066 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6067 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6068 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6072 /* If we are creating a shared library, we must presume that the
6073 only references to the symbol are via the global offset table.
6074 For such cases we need not do anything here; the relocations will
6075 be handled correctly by relocate_section. */
6076 if (bfd_link_pic (info
))
6079 /* If there are no references to this symbol that do not use the
6080 GOT, we don't need to generate a copy reloc. */
6081 if (!h
->non_got_ref
)
6084 /* Don't generate a copy reloc for symbols defined in the executable. */
6085 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6087 /* If -z nocopyreloc was given, don't generate them either. */
6088 || info
->nocopyreloc
6090 /* If we don't find any dynamic relocs in read-only sections, then
6091 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6092 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
6094 /* Protected variables do not work with .dynbss. The copy in
6095 .dynbss won't be used by the shared library with the protected
6096 definition for the variable. Text relocations are preferable
6097 to an incorrect program. */
6098 || h
->protected_def
)
6101 if (h
->plt
.plist
!= NULL
)
6103 /* We should never get here, but unfortunately there are versions
6104 of gcc out there that improperly (for this ABI) put initialized
6105 function pointers, vtable refs and suchlike in read-only
6106 sections. Allow them to proceed, but warn that this might
6107 break at runtime. */
6108 info
->callbacks
->einfo
6109 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6110 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6111 h
->root
.root
.string
);
6114 /* This is a reference to a symbol defined by a dynamic object which
6115 is not a function. */
6117 /* We must allocate the symbol in our .dynbss section, which will
6118 become part of the .bss section of the executable. There will be
6119 an entry for this symbol in the .dynsym section. The dynamic
6120 object will contain position independent code, so all references
6121 from the dynamic object to this symbol will go through the global
6122 offset table. The dynamic linker will use the .dynsym entry to
6123 determine the address it must put in the global offset table, so
6124 both the dynamic object and the regular object will refer to the
6125 same memory location for the variable. */
6126 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6128 s
= htab
->elf
.sdynrelro
;
6129 srel
= htab
->elf
.sreldynrelro
;
6133 s
= htab
->elf
.sdynbss
;
6134 srel
= htab
->elf
.srelbss
;
6136 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6138 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6139 linker to copy the initial value out of the dynamic object
6140 and into the runtime process image. */
6141 srel
->size
+= sizeof (Elf64_External_Rela
);
6145 /* We no longer want dyn_relocs. */
6146 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6147 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6150 /* If given a function descriptor symbol, hide both the function code
6151 sym and the descriptor. */
6153 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6154 struct elf_link_hash_entry
*h
,
6155 bfd_boolean force_local
)
6157 struct ppc_link_hash_entry
*eh
;
6158 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6160 eh
= (struct ppc_link_hash_entry
*) h
;
6161 if (eh
->is_func_descriptor
)
6163 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6168 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6171 /* We aren't supposed to use alloca in BFD because on
6172 systems which do not have alloca the version in libiberty
6173 calls xmalloc, which might cause the program to crash
6174 when it runs out of memory. This function doesn't have a
6175 return status, so there's no way to gracefully return an
6176 error. So cheat. We know that string[-1] can be safely
6177 accessed; It's either a string in an ELF string table,
6178 or allocated in an objalloc structure. */
6180 p
= eh
->elf
.root
.root
.string
- 1;
6183 fh
= (struct ppc_link_hash_entry
*)
6184 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6187 /* Unfortunately, if it so happens that the string we were
6188 looking for was allocated immediately before this string,
6189 then we overwrote the string terminator. That's the only
6190 reason the lookup should fail. */
6193 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6194 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6196 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6197 fh
= (struct ppc_link_hash_entry
*)
6198 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6207 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6212 get_sym_h (struct elf_link_hash_entry
**hp
,
6213 Elf_Internal_Sym
**symp
,
6215 unsigned char **tls_maskp
,
6216 Elf_Internal_Sym
**locsymsp
,
6217 unsigned long r_symndx
,
6220 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6222 if (r_symndx
>= symtab_hdr
->sh_info
)
6224 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6225 struct elf_link_hash_entry
*h
;
6227 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6228 h
= elf_follow_link (h
);
6236 if (symsecp
!= NULL
)
6238 asection
*symsec
= NULL
;
6239 if (h
->root
.type
== bfd_link_hash_defined
6240 || h
->root
.type
== bfd_link_hash_defweak
)
6241 symsec
= h
->root
.u
.def
.section
;
6245 if (tls_maskp
!= NULL
)
6247 struct ppc_link_hash_entry
*eh
;
6249 eh
= (struct ppc_link_hash_entry
*) h
;
6250 *tls_maskp
= &eh
->tls_mask
;
6255 Elf_Internal_Sym
*sym
;
6256 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6258 if (locsyms
== NULL
)
6260 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6261 if (locsyms
== NULL
)
6262 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6263 symtab_hdr
->sh_info
,
6264 0, NULL
, NULL
, NULL
);
6265 if (locsyms
== NULL
)
6267 *locsymsp
= locsyms
;
6269 sym
= locsyms
+ r_symndx
;
6277 if (symsecp
!= NULL
)
6278 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6280 if (tls_maskp
!= NULL
)
6282 struct got_entry
**lgot_ents
;
6283 unsigned char *tls_mask
;
6286 lgot_ents
= elf_local_got_ents (ibfd
);
6287 if (lgot_ents
!= NULL
)
6289 struct plt_entry
**local_plt
= (struct plt_entry
**)
6290 (lgot_ents
+ symtab_hdr
->sh_info
);
6291 unsigned char *lgot_masks
= (unsigned char *)
6292 (local_plt
+ symtab_hdr
->sh_info
);
6293 tls_mask
= &lgot_masks
[r_symndx
];
6295 *tls_maskp
= tls_mask
;
6301 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6302 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6303 type suitable for optimization, and 1 otherwise. */
6306 get_tls_mask (unsigned char **tls_maskp
,
6307 unsigned long *toc_symndx
,
6308 bfd_vma
*toc_addend
,
6309 Elf_Internal_Sym
**locsymsp
,
6310 const Elf_Internal_Rela
*rel
,
6313 unsigned long r_symndx
;
6315 struct elf_link_hash_entry
*h
;
6316 Elf_Internal_Sym
*sym
;
6320 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6321 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6324 if ((*tls_maskp
!= NULL
6325 && (**tls_maskp
& TLS_TLS
) != 0
6326 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
6328 || ppc64_elf_section_data (sec
) == NULL
6329 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6332 /* Look inside a TOC section too. */
6335 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6336 off
= h
->root
.u
.def
.value
;
6339 off
= sym
->st_value
;
6340 off
+= rel
->r_addend
;
6341 BFD_ASSERT (off
% 8 == 0);
6342 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6343 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6344 if (toc_symndx
!= NULL
)
6345 *toc_symndx
= r_symndx
;
6346 if (toc_addend
!= NULL
)
6347 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6348 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6350 if ((h
== NULL
|| is_static_defined (h
))
6351 && (next_r
== -1 || next_r
== -2))
6356 /* Find (or create) an entry in the tocsave hash table. */
6358 static struct tocsave_entry
*
6359 tocsave_find (struct ppc_link_hash_table
*htab
,
6360 enum insert_option insert
,
6361 Elf_Internal_Sym
**local_syms
,
6362 const Elf_Internal_Rela
*irela
,
6365 unsigned long r_indx
;
6366 struct elf_link_hash_entry
*h
;
6367 Elf_Internal_Sym
*sym
;
6368 struct tocsave_entry ent
, *p
;
6370 struct tocsave_entry
**slot
;
6372 r_indx
= ELF64_R_SYM (irela
->r_info
);
6373 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
6375 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
6378 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
6383 ent
.offset
= h
->root
.u
.def
.value
;
6385 ent
.offset
= sym
->st_value
;
6386 ent
.offset
+= irela
->r_addend
;
6388 hash
= tocsave_htab_hash (&ent
);
6389 slot
= ((struct tocsave_entry
**)
6390 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
6396 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
6405 /* Adjust all global syms defined in opd sections. In gcc generated
6406 code for the old ABI, these will already have been done. */
6409 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6411 struct ppc_link_hash_entry
*eh
;
6413 struct _opd_sec_data
*opd
;
6415 if (h
->root
.type
== bfd_link_hash_indirect
)
6418 if (h
->root
.type
!= bfd_link_hash_defined
6419 && h
->root
.type
!= bfd_link_hash_defweak
)
6422 eh
= (struct ppc_link_hash_entry
*) h
;
6423 if (eh
->adjust_done
)
6426 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6427 opd
= get_opd_info (sym_sec
);
6428 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6430 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
6433 /* This entry has been deleted. */
6434 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6437 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6438 if (discarded_section (dsec
))
6440 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6444 eh
->elf
.root
.u
.def
.value
= 0;
6445 eh
->elf
.root
.u
.def
.section
= dsec
;
6448 eh
->elf
.root
.u
.def
.value
+= adjust
;
6449 eh
->adjust_done
= 1;
6454 /* Handles decrementing dynamic reloc counts for the reloc specified by
6455 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
6456 have already been determined. */
6459 dec_dynrel_count (bfd_vma r_info
,
6461 struct bfd_link_info
*info
,
6462 Elf_Internal_Sym
**local_syms
,
6463 struct elf_link_hash_entry
*h
,
6464 Elf_Internal_Sym
*sym
)
6466 enum elf_ppc64_reloc_type r_type
;
6467 asection
*sym_sec
= NULL
;
6469 /* Can this reloc be dynamic? This switch, and later tests here
6470 should be kept in sync with the code in check_relocs. */
6471 r_type
= ELF64_R_TYPE (r_info
);
6477 case R_PPC64_TPREL16
:
6478 case R_PPC64_TPREL16_LO
:
6479 case R_PPC64_TPREL16_HI
:
6480 case R_PPC64_TPREL16_HA
:
6481 case R_PPC64_TPREL16_DS
:
6482 case R_PPC64_TPREL16_LO_DS
:
6483 case R_PPC64_TPREL16_HIGH
:
6484 case R_PPC64_TPREL16_HIGHA
:
6485 case R_PPC64_TPREL16_HIGHER
:
6486 case R_PPC64_TPREL16_HIGHERA
:
6487 case R_PPC64_TPREL16_HIGHEST
:
6488 case R_PPC64_TPREL16_HIGHESTA
:
6489 case R_PPC64_TPREL64
:
6490 case R_PPC64_DTPMOD64
:
6491 case R_PPC64_DTPREL64
:
6492 case R_PPC64_ADDR64
:
6496 case R_PPC64_ADDR14
:
6497 case R_PPC64_ADDR14_BRNTAKEN
:
6498 case R_PPC64_ADDR14_BRTAKEN
:
6499 case R_PPC64_ADDR16
:
6500 case R_PPC64_ADDR16_DS
:
6501 case R_PPC64_ADDR16_HA
:
6502 case R_PPC64_ADDR16_HI
:
6503 case R_PPC64_ADDR16_HIGH
:
6504 case R_PPC64_ADDR16_HIGHA
:
6505 case R_PPC64_ADDR16_HIGHER
:
6506 case R_PPC64_ADDR16_HIGHERA
:
6507 case R_PPC64_ADDR16_HIGHEST
:
6508 case R_PPC64_ADDR16_HIGHESTA
:
6509 case R_PPC64_ADDR16_LO
:
6510 case R_PPC64_ADDR16_LO_DS
:
6511 case R_PPC64_ADDR24
:
6512 case R_PPC64_ADDR32
:
6513 case R_PPC64_UADDR16
:
6514 case R_PPC64_UADDR32
:
6515 case R_PPC64_UADDR64
:
6520 if (local_syms
!= NULL
)
6522 unsigned long r_symndx
;
6523 bfd
*ibfd
= sec
->owner
;
6525 r_symndx
= ELF64_R_SYM (r_info
);
6526 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6530 if ((bfd_link_pic (info
)
6531 && (must_be_dyn_reloc (info
, r_type
)
6533 && (!SYMBOLIC_BIND (info
, h
)
6534 || h
->root
.type
== bfd_link_hash_defweak
6535 || !h
->def_regular
))))
6536 || (ELIMINATE_COPY_RELOCS
6537 && !bfd_link_pic (info
)
6539 && (h
->root
.type
== bfd_link_hash_defweak
6540 || !h
->def_regular
)))
6547 struct elf_dyn_relocs
*p
;
6548 struct elf_dyn_relocs
**pp
;
6549 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6551 /* elf_gc_sweep may have already removed all dyn relocs associated
6552 with local syms for a given section. Also, symbol flags are
6553 changed by elf_gc_sweep_symbol, confusing the test above. Don't
6554 report a dynreloc miscount. */
6555 if (*pp
== NULL
&& info
->gc_sections
)
6558 while ((p
= *pp
) != NULL
)
6562 if (!must_be_dyn_reloc (info
, r_type
))
6574 struct ppc_dyn_relocs
*p
;
6575 struct ppc_dyn_relocs
**pp
;
6577 bfd_boolean is_ifunc
;
6579 if (local_syms
== NULL
)
6580 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6581 if (sym_sec
== NULL
)
6584 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6585 pp
= (struct ppc_dyn_relocs
**) vpp
;
6587 if (*pp
== NULL
&& info
->gc_sections
)
6590 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
6591 while ((p
= *pp
) != NULL
)
6593 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
6604 /* xgettext:c-format */
6605 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
6607 bfd_set_error (bfd_error_bad_value
);
6611 /* Remove unused Official Procedure Descriptor entries. Currently we
6612 only remove those associated with functions in discarded link-once
6613 sections, or weakly defined functions that have been overridden. It
6614 would be possible to remove many more entries for statically linked
6618 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
6621 bfd_boolean some_edited
= FALSE
;
6622 asection
*need_pad
= NULL
;
6623 struct ppc_link_hash_table
*htab
;
6625 htab
= ppc_hash_table (info
);
6629 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
6632 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6633 Elf_Internal_Shdr
*symtab_hdr
;
6634 Elf_Internal_Sym
*local_syms
;
6635 struct _opd_sec_data
*opd
;
6636 bfd_boolean need_edit
, add_aux_fields
, broken
;
6637 bfd_size_type cnt_16b
= 0;
6639 if (!is_ppc64_elf (ibfd
))
6642 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6643 if (sec
== NULL
|| sec
->size
== 0)
6646 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
6649 if (sec
->output_section
== bfd_abs_section_ptr
)
6652 /* Look through the section relocs. */
6653 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6657 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6659 /* Read the relocations. */
6660 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6662 if (relstart
== NULL
)
6665 /* First run through the relocs to check they are sane, and to
6666 determine whether we need to edit this opd section. */
6670 relend
= relstart
+ sec
->reloc_count
;
6671 for (rel
= relstart
; rel
< relend
; )
6673 enum elf_ppc64_reloc_type r_type
;
6674 unsigned long r_symndx
;
6676 struct elf_link_hash_entry
*h
;
6677 Elf_Internal_Sym
*sym
;
6680 /* .opd contains an array of 16 or 24 byte entries. We're
6681 only interested in the reloc pointing to a function entry
6683 offset
= rel
->r_offset
;
6684 if (rel
+ 1 == relend
6685 || rel
[1].r_offset
!= offset
+ 8)
6687 /* If someone messes with .opd alignment then after a
6688 "ld -r" we might have padding in the middle of .opd.
6689 Also, there's nothing to prevent someone putting
6690 something silly in .opd with the assembler. No .opd
6691 optimization for them! */
6694 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
6699 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6700 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6703 /* xgettext:c-format */
6704 (_("%pB: unexpected reloc type %u in .opd section"),
6710 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6711 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6715 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6717 const char *sym_name
;
6719 sym_name
= h
->root
.root
.string
;
6721 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6725 /* xgettext:c-format */
6726 (_("%pB: undefined sym `%s' in .opd section"),
6732 /* opd entries are always for functions defined in the
6733 current input bfd. If the symbol isn't defined in the
6734 input bfd, then we won't be using the function in this
6735 bfd; It must be defined in a linkonce section in another
6736 bfd, or is weak. It's also possible that we are
6737 discarding the function due to a linker script /DISCARD/,
6738 which we test for via the output_section. */
6739 if (sym_sec
->owner
!= ibfd
6740 || sym_sec
->output_section
== bfd_abs_section_ptr
)
6744 if (rel
+ 1 == relend
6745 || (rel
+ 2 < relend
6746 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
6751 if (sec
->size
== offset
+ 24)
6756 if (sec
->size
== offset
+ 16)
6763 else if (rel
+ 1 < relend
6764 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
6765 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
6767 if (rel
[0].r_offset
== offset
+ 16)
6769 else if (rel
[0].r_offset
!= offset
+ 24)
6776 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
6778 if (!broken
&& (need_edit
|| add_aux_fields
))
6780 Elf_Internal_Rela
*write_rel
;
6781 Elf_Internal_Shdr
*rel_hdr
;
6782 bfd_byte
*rptr
, *wptr
;
6783 bfd_byte
*new_contents
;
6786 new_contents
= NULL
;
6787 amt
= OPD_NDX (sec
->size
) * sizeof (long);
6788 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
6789 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
6790 if (opd
->adjust
== NULL
)
6793 /* This seems a waste of time as input .opd sections are all
6794 zeros as generated by gcc, but I suppose there's no reason
6795 this will always be so. We might start putting something in
6796 the third word of .opd entries. */
6797 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
6800 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
6805 if (local_syms
!= NULL
6806 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6808 if (elf_section_data (sec
)->relocs
!= relstart
)
6812 sec
->contents
= loc
;
6813 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6816 elf_section_data (sec
)->relocs
= relstart
;
6818 new_contents
= sec
->contents
;
6821 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
6822 if (new_contents
== NULL
)
6826 wptr
= new_contents
;
6827 rptr
= sec
->contents
;
6828 write_rel
= relstart
;
6829 for (rel
= relstart
; rel
< relend
; )
6831 unsigned long r_symndx
;
6833 struct elf_link_hash_entry
*h
;
6834 struct ppc_link_hash_entry
*fdh
= NULL
;
6835 Elf_Internal_Sym
*sym
;
6837 Elf_Internal_Rela
*next_rel
;
6840 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6841 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6846 if (next_rel
+ 1 == relend
6847 || (next_rel
+ 2 < relend
6848 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
6851 /* See if the .opd entry is full 24 byte or
6852 16 byte (with fd_aux entry overlapped with next
6855 if (next_rel
== relend
)
6857 if (sec
->size
== rel
->r_offset
+ 16)
6860 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
6864 && h
->root
.root
.string
[0] == '.')
6866 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
6869 fdh
= ppc_follow_link (fdh
);
6870 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
6871 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6876 skip
= (sym_sec
->owner
!= ibfd
6877 || sym_sec
->output_section
== bfd_abs_section_ptr
);
6880 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
6882 /* Arrange for the function descriptor sym
6884 fdh
->elf
.root
.u
.def
.value
= 0;
6885 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
6887 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
6889 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
6894 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
6898 if (++rel
== next_rel
)
6901 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6902 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6909 /* We'll be keeping this opd entry. */
6914 /* Redefine the function descriptor symbol to
6915 this location in the opd section. It is
6916 necessary to update the value here rather
6917 than using an array of adjustments as we do
6918 for local symbols, because various places
6919 in the generic ELF code use the value
6920 stored in u.def.value. */
6921 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
6922 fdh
->adjust_done
= 1;
6925 /* Local syms are a bit tricky. We could
6926 tweak them as they can be cached, but
6927 we'd need to look through the local syms
6928 for the function descriptor sym which we
6929 don't have at the moment. So keep an
6930 array of adjustments. */
6931 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
6932 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
6935 memcpy (wptr
, rptr
, opd_ent_size
);
6936 wptr
+= opd_ent_size
;
6937 if (add_aux_fields
&& opd_ent_size
== 16)
6939 memset (wptr
, '\0', 8);
6943 /* We need to adjust any reloc offsets to point to the
6945 for ( ; rel
!= next_rel
; ++rel
)
6947 rel
->r_offset
+= adjust
;
6948 if (write_rel
!= rel
)
6949 memcpy (write_rel
, rel
, sizeof (*rel
));
6954 rptr
+= opd_ent_size
;
6957 sec
->size
= wptr
- new_contents
;
6958 sec
->reloc_count
= write_rel
- relstart
;
6961 free (sec
->contents
);
6962 sec
->contents
= new_contents
;
6965 /* Fudge the header size too, as this is used later in
6966 elf_bfd_final_link if we are emitting relocs. */
6967 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
6968 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
6971 else if (elf_section_data (sec
)->relocs
!= relstart
)
6974 if (local_syms
!= NULL
6975 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6977 if (!info
->keep_memory
)
6980 symtab_hdr
->contents
= (unsigned char *) local_syms
;
6985 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
6987 /* If we are doing a final link and the last .opd entry is just 16 byte
6988 long, add a 8 byte padding after it. */
6989 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
6993 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
6995 BFD_ASSERT (need_pad
->size
> 0);
6997 p
= bfd_malloc (need_pad
->size
+ 8);
7001 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7002 p
, 0, need_pad
->size
))
7005 need_pad
->contents
= p
;
7006 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7010 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7014 need_pad
->contents
= p
;
7017 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7018 need_pad
->size
+= 8;
7024 /* Analyze inline PLT call relocations to see whether calls to locally
7025 defined functions can be converted to direct calls. */
7028 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7030 struct ppc_link_hash_table
*htab
;
7033 bfd_vma low_vma
, high_vma
, limit
;
7035 htab
= ppc_hash_table (info
);
7039 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7040 reduced somewhat to cater for possible stubs that might be added
7041 between the call and its destination. */
7042 if (htab
->params
->group_size
< 0)
7044 limit
= -htab
->params
->group_size
;
7050 limit
= htab
->params
->group_size
;
7057 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7058 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7060 if (low_vma
> sec
->vma
)
7062 if (high_vma
< sec
->vma
+ sec
->size
)
7063 high_vma
= sec
->vma
+ sec
->size
;
7066 /* If a "bl" can reach anywhere in local code sections, then we can
7067 convert all inline PLT sequences to direct calls when the symbol
7069 if (high_vma
- low_vma
< limit
)
7071 htab
->can_convert_all_inline_plt
= 1;
7075 /* Otherwise, go looking through relocs for cases where a direct
7076 call won't reach. Mark the symbol on any such reloc to disable
7077 the optimization and keep the PLT entry as it seems likely that
7078 this will be better than creating trampolines. Note that this
7079 will disable the optimization for all inline PLT calls to a
7080 particular symbol, not just those that won't reach. The
7081 difficulty in doing a more precise optimization is that the
7082 linker needs to make a decision depending on whether a
7083 particular R_PPC64_PLTCALL insn can be turned into a direct
7084 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7085 the sequence, and there is nothing that ties those relocs
7086 together except their symbol. */
7088 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7090 Elf_Internal_Shdr
*symtab_hdr
;
7091 Elf_Internal_Sym
*local_syms
;
7093 if (!is_ppc64_elf (ibfd
))
7097 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7099 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7100 if (ppc64_elf_section_data (sec
)->has_pltcall
7101 && !bfd_is_abs_section (sec
->output_section
))
7103 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7105 /* Read the relocations. */
7106 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7108 if (relstart
== NULL
)
7111 relend
= relstart
+ sec
->reloc_count
;
7112 for (rel
= relstart
; rel
< relend
; )
7114 enum elf_ppc64_reloc_type r_type
;
7115 unsigned long r_symndx
;
7117 struct elf_link_hash_entry
*h
;
7118 Elf_Internal_Sym
*sym
;
7119 unsigned char *tls_maskp
;
7121 r_type
= ELF64_R_TYPE (rel
->r_info
);
7122 if (r_type
!= R_PPC64_PLTCALL
)
7125 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7126 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7129 if (elf_section_data (sec
)->relocs
!= relstart
)
7131 if (local_syms
!= NULL
7132 && symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7137 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7141 to
= h
->root
.u
.def
.value
;
7144 to
+= (rel
->r_addend
7145 + sym_sec
->output_offset
7146 + sym_sec
->output_section
->vma
);
7147 from
= (rel
->r_offset
7148 + sec
->output_offset
7149 + sec
->output_section
->vma
);
7150 if (to
- from
+ limit
< 2 * limit
)
7151 *tls_maskp
&= ~PLT_KEEP
;
7154 if (elf_section_data (sec
)->relocs
!= relstart
)
7158 if (local_syms
!= NULL
7159 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7161 if (!info
->keep_memory
)
7164 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7171 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7174 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7176 struct ppc_link_hash_table
*htab
;
7178 htab
= ppc_hash_table (info
);
7182 if (abiversion (info
->output_bfd
) == 1)
7185 if (htab
->params
->no_multi_toc
)
7186 htab
->do_multi_toc
= 0;
7187 else if (!htab
->do_multi_toc
)
7188 htab
->params
->no_multi_toc
= 1;
7190 /* Default to --no-plt-localentry, as this option can cause problems
7191 with symbol interposition. For example, glibc libpthread.so and
7192 libc.so duplicate many pthread symbols, with a fallback
7193 implementation in libc.so. In some cases the fallback does more
7194 work than the pthread implementation. __pthread_condattr_destroy
7195 is one such symbol: the libpthread.so implementation is
7196 localentry:0 while the libc.so implementation is localentry:8.
7197 An app that "cleverly" uses dlopen to only load necessary
7198 libraries at runtime may omit loading libpthread.so when not
7199 running multi-threaded, which then results in the libc.so
7200 fallback symbols being used and ld.so complaining. Now there
7201 are workarounds in ld (see non_zero_localentry) to detect the
7202 pthread situation, but that may not be the only case where
7203 --plt-localentry can cause trouble. */
7204 if (htab
->params
->plt_localentry0
< 0)
7205 htab
->params
->plt_localentry0
= 0;
7206 if (htab
->params
->plt_localentry0
7207 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7208 FALSE
, FALSE
, FALSE
) == NULL
)
7210 (_("warning: --plt-localentry is especially dangerous without "
7211 "ld.so support to detect ABI violations"));
7213 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7214 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7215 FALSE
, FALSE
, TRUE
));
7216 /* Move dynamic linking info to the function descriptor sym. */
7217 if (htab
->tls_get_addr
!= NULL
)
7218 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7219 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7220 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7221 FALSE
, FALSE
, TRUE
));
7222 if (htab
->params
->tls_get_addr_opt
)
7224 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7226 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7227 FALSE
, FALSE
, TRUE
);
7229 func_desc_adjust (opt
, info
);
7230 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7231 FALSE
, FALSE
, TRUE
);
7233 && (opt_fd
->root
.type
== bfd_link_hash_defined
7234 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7236 /* If glibc supports an optimized __tls_get_addr call stub,
7237 signalled by the presence of __tls_get_addr_opt, and we'll
7238 be calling __tls_get_addr via a plt call stub, then
7239 make __tls_get_addr point to __tls_get_addr_opt. */
7240 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7241 if (htab
->elf
.dynamic_sections_created
7243 && (tga_fd
->type
== STT_FUNC
7244 || tga_fd
->needs_plt
)
7245 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7246 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
7248 struct plt_entry
*ent
;
7250 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7251 if (ent
->plt
.refcount
> 0)
7255 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7256 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7257 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7259 if (opt_fd
->dynindx
!= -1)
7261 /* Use __tls_get_addr_opt in dynamic relocations. */
7262 opt_fd
->dynindx
= -1;
7263 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7264 opt_fd
->dynstr_index
);
7265 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7268 htab
->tls_get_addr_fd
7269 = (struct ppc_link_hash_entry
*) opt_fd
;
7270 tga
= &htab
->tls_get_addr
->elf
;
7271 if (opt
!= NULL
&& tga
!= NULL
)
7273 tga
->root
.type
= bfd_link_hash_indirect
;
7274 tga
->root
.u
.i
.link
= &opt
->root
;
7275 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7277 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7279 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7281 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7282 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7283 if (htab
->tls_get_addr
!= NULL
)
7285 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7286 htab
->tls_get_addr
->is_func
= 1;
7291 else if (htab
->params
->tls_get_addr_opt
< 0)
7292 htab
->params
->tls_get_addr_opt
= 0;
7294 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7297 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7301 branch_reloc_hash_match (const bfd
*ibfd
,
7302 const Elf_Internal_Rela
*rel
,
7303 const struct ppc_link_hash_entry
*hash1
,
7304 const struct ppc_link_hash_entry
*hash2
)
7306 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7307 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7308 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7310 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7312 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7313 struct elf_link_hash_entry
*h
;
7315 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7316 h
= elf_follow_link (h
);
7317 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7323 /* Run through all the TLS relocs looking for optimization
7324 opportunities. The linker has been hacked (see ppc64elf.em) to do
7325 a preliminary section layout so that we know the TLS segment
7326 offsets. We can't optimize earlier because some optimizations need
7327 to know the tp offset, and we need to optimize before allocating
7328 dynamic relocations. */
7331 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7335 struct ppc_link_hash_table
*htab
;
7336 unsigned char *toc_ref
;
7339 if (!bfd_link_executable (info
))
7342 htab
= ppc_hash_table (info
);
7346 /* Make two passes over the relocs. On the first pass, mark toc
7347 entries involved with tls relocs, and check that tls relocs
7348 involved in setting up a tls_get_addr call are indeed followed by
7349 such a call. If they are not, we can't do any tls optimization.
7350 On the second pass twiddle tls_mask flags to notify
7351 relocate_section that optimization can be done, and adjust got
7352 and plt refcounts. */
7354 for (pass
= 0; pass
< 2; ++pass
)
7355 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7357 Elf_Internal_Sym
*locsyms
= NULL
;
7358 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7360 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7361 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7363 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7364 bfd_boolean found_tls_get_addr_arg
= 0;
7366 /* Read the relocations. */
7367 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7369 if (relstart
== NULL
)
7375 relend
= relstart
+ sec
->reloc_count
;
7376 for (rel
= relstart
; rel
< relend
; rel
++)
7378 enum elf_ppc64_reloc_type r_type
;
7379 unsigned long r_symndx
;
7380 struct elf_link_hash_entry
*h
;
7381 Elf_Internal_Sym
*sym
;
7383 unsigned char *tls_mask
;
7384 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7386 bfd_boolean ok_tprel
, is_local
;
7387 long toc_ref_index
= 0;
7388 int expecting_tls_get_addr
= 0;
7389 bfd_boolean ret
= FALSE
;
7391 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7392 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7396 if (elf_section_data (sec
)->relocs
!= relstart
)
7398 if (toc_ref
!= NULL
)
7401 && (elf_symtab_hdr (ibfd
).contents
7402 != (unsigned char *) locsyms
))
7409 if (h
->root
.type
== bfd_link_hash_defined
7410 || h
->root
.type
== bfd_link_hash_defweak
)
7411 value
= h
->root
.u
.def
.value
;
7412 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7416 found_tls_get_addr_arg
= 0;
7421 /* Symbols referenced by TLS relocs must be of type
7422 STT_TLS. So no need for .opd local sym adjust. */
7423 value
= sym
->st_value
;
7432 && h
->root
.type
== bfd_link_hash_undefweak
)
7434 else if (sym_sec
!= NULL
7435 && sym_sec
->output_section
!= NULL
)
7437 value
+= sym_sec
->output_offset
;
7438 value
+= sym_sec
->output_section
->vma
;
7439 value
-= htab
->elf
.tls_sec
->vma
;
7440 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7441 < (bfd_vma
) 1 << 32);
7445 r_type
= ELF64_R_TYPE (rel
->r_info
);
7446 /* If this section has old-style __tls_get_addr calls
7447 without marker relocs, then check that each
7448 __tls_get_addr call reloc is preceded by a reloc
7449 that conceivably belongs to the __tls_get_addr arg
7450 setup insn. If we don't find matching arg setup
7451 relocs, don't do any tls optimization. */
7453 && sec
->has_tls_get_addr_call
7455 && (h
== &htab
->tls_get_addr
->elf
7456 || h
== &htab
->tls_get_addr_fd
->elf
)
7457 && !found_tls_get_addr_arg
7458 && is_branch_reloc (r_type
))
7460 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7461 "TLS optimization disabled\n"),
7462 ibfd
, sec
, rel
->r_offset
);
7467 found_tls_get_addr_arg
= 0;
7470 case R_PPC64_GOT_TLSLD16
:
7471 case R_PPC64_GOT_TLSLD16_LO
:
7472 expecting_tls_get_addr
= 1;
7473 found_tls_get_addr_arg
= 1;
7476 case R_PPC64_GOT_TLSLD16_HI
:
7477 case R_PPC64_GOT_TLSLD16_HA
:
7478 /* These relocs should never be against a symbol
7479 defined in a shared lib. Leave them alone if
7480 that turns out to be the case. */
7487 tls_type
= TLS_TLS
| TLS_LD
;
7490 case R_PPC64_GOT_TLSGD16
:
7491 case R_PPC64_GOT_TLSGD16_LO
:
7492 expecting_tls_get_addr
= 1;
7493 found_tls_get_addr_arg
= 1;
7496 case R_PPC64_GOT_TLSGD16_HI
:
7497 case R_PPC64_GOT_TLSGD16_HA
:
7503 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7505 tls_type
= TLS_TLS
| TLS_GD
;
7508 case R_PPC64_GOT_TPREL16_DS
:
7509 case R_PPC64_GOT_TPREL16_LO_DS
:
7510 case R_PPC64_GOT_TPREL16_HI
:
7511 case R_PPC64_GOT_TPREL16_HA
:
7516 tls_clear
= TLS_TPREL
;
7517 tls_type
= TLS_TLS
| TLS_TPREL
;
7524 if (rel
+ 1 < relend
7525 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
7528 && (ELF64_R_TYPE (rel
[1].r_info
)
7531 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
7532 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
7537 struct plt_entry
*ent
= NULL
;
7539 for (ent
= h
->plt
.plist
;
7542 if (ent
->addend
== rel
[1].r_addend
)
7546 && ent
->plt
.refcount
> 0)
7547 ent
->plt
.refcount
-= 1;
7552 found_tls_get_addr_arg
= 1;
7557 case R_PPC64_TOC16_LO
:
7558 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7561 /* Mark this toc entry as referenced by a TLS
7562 code sequence. We can do that now in the
7563 case of R_PPC64_TLS, and after checking for
7564 tls_get_addr for the TOC16 relocs. */
7565 if (toc_ref
== NULL
)
7567 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7568 if (toc_ref
== NULL
)
7572 value
= h
->root
.u
.def
.value
;
7574 value
= sym
->st_value
;
7575 value
+= rel
->r_addend
;
7578 BFD_ASSERT (value
< toc
->size
7579 && toc
->output_offset
% 8 == 0);
7580 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7581 if (r_type
== R_PPC64_TLS
7582 || r_type
== R_PPC64_TLSGD
7583 || r_type
== R_PPC64_TLSLD
)
7585 toc_ref
[toc_ref_index
] = 1;
7589 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7594 expecting_tls_get_addr
= 2;
7597 case R_PPC64_TPREL64
:
7601 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7606 tls_set
= TLS_EXPLICIT
;
7607 tls_clear
= TLS_TPREL
;
7612 case R_PPC64_DTPMOD64
:
7616 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7618 if (rel
+ 1 < relend
7620 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7621 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7625 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7628 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7637 tls_set
= TLS_EXPLICIT
;
7648 if (!expecting_tls_get_addr
7649 || !sec
->has_tls_get_addr_call
)
7652 if (rel
+ 1 < relend
7653 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7655 htab
->tls_get_addr_fd
))
7657 if (expecting_tls_get_addr
== 2)
7659 /* Check for toc tls entries. */
7660 unsigned char *toc_tls
;
7663 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7668 if (toc_tls
!= NULL
)
7670 if ((*toc_tls
& TLS_TLS
) != 0
7671 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
7672 found_tls_get_addr_arg
= 1;
7674 toc_ref
[toc_ref_index
] = 1;
7680 /* Uh oh, we didn't find the expected call. We
7681 could just mark this symbol to exclude it
7682 from tls optimization but it's safer to skip
7683 the entire optimization. */
7684 /* xgettext:c-format */
7685 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7686 "TLS optimization disabled\n"),
7687 ibfd
, sec
, rel
->r_offset
);
7692 /* If we don't have old-style __tls_get_addr calls
7693 without TLSGD/TLSLD marker relocs, and we haven't
7694 found a new-style __tls_get_addr call with a
7695 marker for this symbol, then we either have a
7696 broken object file or an -mlongcall style
7697 indirect call to __tls_get_addr without a marker.
7698 Disable optimization in this case. */
7699 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
7700 && (tls_set
& TLS_EXPLICIT
) == 0
7701 && !sec
->has_tls_get_addr_call
7702 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
7703 != (TLS_TLS
| TLS_MARK
)))
7706 if (expecting_tls_get_addr
)
7708 struct plt_entry
*ent
= NULL
;
7710 if (htab
->tls_get_addr
!= NULL
)
7711 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7714 if (ent
->addend
== 0)
7717 if (ent
== NULL
&& htab
->tls_get_addr_fd
!= NULL
)
7718 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7721 if (ent
->addend
== 0)
7725 && ent
->plt
.refcount
> 0)
7726 ent
->plt
.refcount
-= 1;
7732 if ((tls_set
& TLS_EXPLICIT
) == 0)
7734 struct got_entry
*ent
;
7736 /* Adjust got entry for this reloc. */
7740 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7742 for (; ent
!= NULL
; ent
= ent
->next
)
7743 if (ent
->addend
== rel
->r_addend
7744 && ent
->owner
== ibfd
7745 && ent
->tls_type
== tls_type
)
7752 /* We managed to get rid of a got entry. */
7753 if (ent
->got
.refcount
> 0)
7754 ent
->got
.refcount
-= 1;
7759 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7760 we'll lose one or two dyn relocs. */
7761 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7765 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7767 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7773 *tls_mask
|= tls_set
;
7774 *tls_mask
&= ~tls_clear
;
7777 if (elf_section_data (sec
)->relocs
!= relstart
)
7782 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7784 if (!info
->keep_memory
)
7787 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7791 if (toc_ref
!= NULL
)
7793 htab
->do_tls_opt
= 1;
7797 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7798 the values of any global symbols in a toc section that has been
7799 edited. Globals in toc sections should be a rarity, so this function
7800 sets a flag if any are found in toc sections other than the one just
7801 edited, so that further hash table traversals can be avoided. */
7803 struct adjust_toc_info
7806 unsigned long *skip
;
7807 bfd_boolean global_toc_syms
;
7810 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7813 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7815 struct ppc_link_hash_entry
*eh
;
7816 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7819 if (h
->root
.type
!= bfd_link_hash_defined
7820 && h
->root
.type
!= bfd_link_hash_defweak
)
7823 eh
= (struct ppc_link_hash_entry
*) h
;
7824 if (eh
->adjust_done
)
7827 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7829 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7830 i
= toc_inf
->toc
->rawsize
>> 3;
7832 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7834 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7837 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7840 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7841 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7844 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7845 eh
->adjust_done
= 1;
7847 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7848 toc_inf
->global_toc_syms
= TRUE
;
7853 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
7854 on a _LO variety toc/got reloc. */
7857 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
7859 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7860 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7861 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7862 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7863 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7864 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7865 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7866 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7867 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7868 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7869 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7870 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7871 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7872 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7873 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7874 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7875 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7876 /* Exclude lfqu by testing reloc. If relocs are ever
7877 defined for the reduced D field in psq_lu then those
7878 will need testing too. */
7879 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
7880 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7882 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7883 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7884 /* Exclude stfqu. psq_stu as above for psq_lu. */
7885 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
7886 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7887 && (insn
& 1) == 0));
7890 /* Examine all relocs referencing .toc sections in order to remove
7891 unused .toc entries. */
7894 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7897 struct adjust_toc_info toc_inf
;
7898 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7900 htab
->do_toc_opt
= 1;
7901 toc_inf
.global_toc_syms
= TRUE
;
7902 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7904 asection
*toc
, *sec
;
7905 Elf_Internal_Shdr
*symtab_hdr
;
7906 Elf_Internal_Sym
*local_syms
;
7907 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7908 unsigned long *skip
, *drop
;
7909 unsigned char *used
;
7910 unsigned char *keep
, last
, some_unused
;
7912 if (!is_ppc64_elf (ibfd
))
7915 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7918 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
7919 || discarded_section (toc
))
7924 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7926 /* Look at sections dropped from the final link. */
7929 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7931 if (sec
->reloc_count
== 0
7932 || !discarded_section (sec
)
7933 || get_opd_info (sec
)
7934 || (sec
->flags
& SEC_ALLOC
) == 0
7935 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7938 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7939 if (relstart
== NULL
)
7942 /* Run through the relocs to see which toc entries might be
7944 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7946 enum elf_ppc64_reloc_type r_type
;
7947 unsigned long r_symndx
;
7949 struct elf_link_hash_entry
*h
;
7950 Elf_Internal_Sym
*sym
;
7953 r_type
= ELF64_R_TYPE (rel
->r_info
);
7960 case R_PPC64_TOC16_LO
:
7961 case R_PPC64_TOC16_HI
:
7962 case R_PPC64_TOC16_HA
:
7963 case R_PPC64_TOC16_DS
:
7964 case R_PPC64_TOC16_LO_DS
:
7968 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7969 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7977 val
= h
->root
.u
.def
.value
;
7979 val
= sym
->st_value
;
7980 val
+= rel
->r_addend
;
7982 if (val
>= toc
->size
)
7985 /* Anything in the toc ought to be aligned to 8 bytes.
7986 If not, don't mark as unused. */
7992 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
7997 skip
[val
>> 3] = ref_from_discarded
;
8000 if (elf_section_data (sec
)->relocs
!= relstart
)
8004 /* For largetoc loads of address constants, we can convert
8005 . addis rx,2,addr@got@ha
8006 . ld ry,addr@got@l(rx)
8008 . addis rx,2,addr@toc@ha
8009 . addi ry,rx,addr@toc@l
8010 when addr is within 2G of the toc pointer. This then means
8011 that the word storing "addr" in the toc is no longer needed. */
8013 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8014 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8015 && toc
->reloc_count
!= 0)
8017 /* Read toc relocs. */
8018 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8020 if (toc_relocs
== NULL
)
8023 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8025 enum elf_ppc64_reloc_type r_type
;
8026 unsigned long r_symndx
;
8028 struct elf_link_hash_entry
*h
;
8029 Elf_Internal_Sym
*sym
;
8032 r_type
= ELF64_R_TYPE (rel
->r_info
);
8033 if (r_type
!= R_PPC64_ADDR64
)
8036 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8037 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8042 || sym_sec
->output_section
== NULL
8043 || discarded_section (sym_sec
))
8046 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8051 if (h
->type
== STT_GNU_IFUNC
)
8053 val
= h
->root
.u
.def
.value
;
8057 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8059 val
= sym
->st_value
;
8061 val
+= rel
->r_addend
;
8062 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8064 /* We don't yet know the exact toc pointer value, but we
8065 know it will be somewhere in the toc section. Don't
8066 optimize if the difference from any possible toc
8067 pointer is outside [ff..f80008000, 7fff7fff]. */
8068 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8069 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8072 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8073 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8078 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8083 skip
[rel
->r_offset
>> 3]
8084 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8091 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8095 if (local_syms
!= NULL
8096 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8100 && elf_section_data (sec
)->relocs
!= relstart
)
8102 if (toc_relocs
!= NULL
8103 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8110 /* Now check all kept sections that might reference the toc.
8111 Check the toc itself last. */
8112 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8115 sec
= (sec
== toc
? NULL
8116 : sec
->next
== NULL
? toc
8117 : sec
->next
== toc
&& toc
->next
? toc
->next
8122 if (sec
->reloc_count
== 0
8123 || discarded_section (sec
)
8124 || get_opd_info (sec
)
8125 || (sec
->flags
& SEC_ALLOC
) == 0
8126 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8129 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8131 if (relstart
== NULL
)
8137 /* Mark toc entries referenced as used. */
8141 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8143 enum elf_ppc64_reloc_type r_type
;
8144 unsigned long r_symndx
;
8146 struct elf_link_hash_entry
*h
;
8147 Elf_Internal_Sym
*sym
;
8149 enum {no_check
, check_lo
, check_ha
} insn_check
;
8151 r_type
= ELF64_R_TYPE (rel
->r_info
);
8155 insn_check
= no_check
;
8158 case R_PPC64_GOT_TLSLD16_HA
:
8159 case R_PPC64_GOT_TLSGD16_HA
:
8160 case R_PPC64_GOT_TPREL16_HA
:
8161 case R_PPC64_GOT_DTPREL16_HA
:
8162 case R_PPC64_GOT16_HA
:
8163 case R_PPC64_TOC16_HA
:
8164 insn_check
= check_ha
;
8167 case R_PPC64_GOT_TLSLD16_LO
:
8168 case R_PPC64_GOT_TLSGD16_LO
:
8169 case R_PPC64_GOT_TPREL16_LO_DS
:
8170 case R_PPC64_GOT_DTPREL16_LO_DS
:
8171 case R_PPC64_GOT16_LO
:
8172 case R_PPC64_GOT16_LO_DS
:
8173 case R_PPC64_TOC16_LO
:
8174 case R_PPC64_TOC16_LO_DS
:
8175 insn_check
= check_lo
;
8179 if (insn_check
!= no_check
)
8181 bfd_vma off
= rel
->r_offset
& ~3;
8182 unsigned char buf
[4];
8185 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
8190 insn
= bfd_get_32 (ibfd
, buf
);
8191 if (insn_check
== check_lo
8192 ? !ok_lo_toc_insn (insn
, r_type
)
8193 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8194 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8198 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
8199 sprintf (str
, "%#08x", insn
);
8200 info
->callbacks
->einfo
8201 /* xgettext:c-format */
8202 (_("%H: toc optimization is not supported for"
8203 " %s instruction\n"),
8204 ibfd
, sec
, rel
->r_offset
& ~3, str
);
8211 case R_PPC64_TOC16_LO
:
8212 case R_PPC64_TOC16_HI
:
8213 case R_PPC64_TOC16_HA
:
8214 case R_PPC64_TOC16_DS
:
8215 case R_PPC64_TOC16_LO_DS
:
8216 /* In case we're taking addresses of toc entries. */
8217 case R_PPC64_ADDR64
:
8224 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8225 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8236 val
= h
->root
.u
.def
.value
;
8238 val
= sym
->st_value
;
8239 val
+= rel
->r_addend
;
8241 if (val
>= toc
->size
)
8244 if ((skip
[val
>> 3] & can_optimize
) != 0)
8251 case R_PPC64_TOC16_HA
:
8254 case R_PPC64_TOC16_LO_DS
:
8255 off
= rel
->r_offset
;
8256 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
8257 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
8263 if ((opc
& (0x3f << 2)) == (58u << 2))
8268 /* Wrong sort of reloc, or not a ld. We may
8269 as well clear ref_from_discarded too. */
8276 /* For the toc section, we only mark as used if this
8277 entry itself isn't unused. */
8278 else if ((used
[rel
->r_offset
>> 3]
8279 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
8282 /* Do all the relocs again, to catch reference
8291 if (elf_section_data (sec
)->relocs
!= relstart
)
8295 /* Merge the used and skip arrays. Assume that TOC
8296 doublewords not appearing as either used or unused belong
8297 to an entry more than one doubleword in size. */
8298 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8299 drop
< skip
+ (toc
->size
+ 7) / 8;
8304 *drop
&= ~ref_from_discarded
;
8305 if ((*drop
& can_optimize
) != 0)
8309 else if ((*drop
& ref_from_discarded
) != 0)
8312 last
= ref_from_discarded
;
8322 bfd_byte
*contents
, *src
;
8324 Elf_Internal_Sym
*sym
;
8325 bfd_boolean local_toc_syms
= FALSE
;
8327 /* Shuffle the toc contents, and at the same time convert the
8328 skip array from booleans into offsets. */
8329 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8332 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8334 for (src
= contents
, off
= 0, drop
= skip
;
8335 src
< contents
+ toc
->size
;
8338 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8343 memcpy (src
- off
, src
, 8);
8347 toc
->rawsize
= toc
->size
;
8348 toc
->size
= src
- contents
- off
;
8350 /* Adjust addends for relocs against the toc section sym,
8351 and optimize any accesses we can. */
8352 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8354 if (sec
->reloc_count
== 0
8355 || discarded_section (sec
))
8358 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8360 if (relstart
== NULL
)
8363 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8365 enum elf_ppc64_reloc_type r_type
;
8366 unsigned long r_symndx
;
8368 struct elf_link_hash_entry
*h
;
8371 r_type
= ELF64_R_TYPE (rel
->r_info
);
8378 case R_PPC64_TOC16_LO
:
8379 case R_PPC64_TOC16_HI
:
8380 case R_PPC64_TOC16_HA
:
8381 case R_PPC64_TOC16_DS
:
8382 case R_PPC64_TOC16_LO_DS
:
8383 case R_PPC64_ADDR64
:
8387 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8388 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8396 val
= h
->root
.u
.def
.value
;
8399 val
= sym
->st_value
;
8401 local_toc_syms
= TRUE
;
8404 val
+= rel
->r_addend
;
8406 if (val
> toc
->rawsize
)
8408 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8410 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8412 Elf_Internal_Rela
*tocrel
8413 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8414 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8418 case R_PPC64_TOC16_HA
:
8419 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8422 case R_PPC64_TOC16_LO_DS
:
8423 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8427 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
8429 info
->callbacks
->einfo
8430 /* xgettext:c-format */
8431 (_("%H: %s references "
8432 "optimized away TOC entry\n"),
8433 ibfd
, sec
, rel
->r_offset
,
8434 ppc64_elf_howto_table
[r_type
]->name
);
8435 bfd_set_error (bfd_error_bad_value
);
8438 rel
->r_addend
= tocrel
->r_addend
;
8439 elf_section_data (sec
)->relocs
= relstart
;
8443 if (h
!= NULL
|| sym
->st_value
!= 0)
8446 rel
->r_addend
-= skip
[val
>> 3];
8447 elf_section_data (sec
)->relocs
= relstart
;
8450 if (elf_section_data (sec
)->relocs
!= relstart
)
8454 /* We shouldn't have local or global symbols defined in the TOC,
8455 but handle them anyway. */
8456 if (local_syms
!= NULL
)
8457 for (sym
= local_syms
;
8458 sym
< local_syms
+ symtab_hdr
->sh_info
;
8460 if (sym
->st_value
!= 0
8461 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8465 if (sym
->st_value
> toc
->rawsize
)
8466 i
= toc
->rawsize
>> 3;
8468 i
= sym
->st_value
>> 3;
8470 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8474 (_("%s defined on removed toc entry"),
8475 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8478 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8479 sym
->st_value
= (bfd_vma
) i
<< 3;
8482 sym
->st_value
-= skip
[i
];
8483 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8486 /* Adjust any global syms defined in this toc input section. */
8487 if (toc_inf
.global_toc_syms
)
8490 toc_inf
.skip
= skip
;
8491 toc_inf
.global_toc_syms
= FALSE
;
8492 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8496 if (toc
->reloc_count
!= 0)
8498 Elf_Internal_Shdr
*rel_hdr
;
8499 Elf_Internal_Rela
*wrel
;
8502 /* Remove unused toc relocs, and adjust those we keep. */
8503 if (toc_relocs
== NULL
)
8504 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8506 if (toc_relocs
== NULL
)
8510 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8511 if ((skip
[rel
->r_offset
>> 3]
8512 & (ref_from_discarded
| can_optimize
)) == 0)
8514 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8515 wrel
->r_info
= rel
->r_info
;
8516 wrel
->r_addend
= rel
->r_addend
;
8519 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8520 &local_syms
, NULL
, NULL
))
8523 elf_section_data (toc
)->relocs
= toc_relocs
;
8524 toc
->reloc_count
= wrel
- toc_relocs
;
8525 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8526 sz
= rel_hdr
->sh_entsize
;
8527 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8530 else if (toc_relocs
!= NULL
8531 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8534 if (local_syms
!= NULL
8535 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8537 if (!info
->keep_memory
)
8540 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8548 /* Return true iff input section I references the TOC using
8549 instructions limited to +/-32k offsets. */
8552 ppc64_elf_has_small_toc_reloc (asection
*i
)
8554 return (is_ppc64_elf (i
->owner
)
8555 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8558 /* Allocate space for one GOT entry. */
8561 allocate_got (struct elf_link_hash_entry
*h
,
8562 struct bfd_link_info
*info
,
8563 struct got_entry
*gent
)
8565 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8566 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8567 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8569 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8570 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8571 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8573 gent
->got
.offset
= got
->size
;
8574 got
->size
+= entsize
;
8576 if (h
->type
== STT_GNU_IFUNC
)
8578 htab
->elf
.irelplt
->size
+= rentsize
;
8579 htab
->got_reli_size
+= rentsize
;
8581 else if (((bfd_link_pic (info
)
8582 && !((gent
->tls_type
& TLS_TPREL
) != 0
8583 && bfd_link_executable (info
)
8584 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
8585 || (htab
->elf
.dynamic_sections_created
8587 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
8588 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8590 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8591 relgot
->size
+= rentsize
;
8595 /* This function merges got entries in the same toc group. */
8598 merge_got_entries (struct got_entry
**pent
)
8600 struct got_entry
*ent
, *ent2
;
8602 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8603 if (!ent
->is_indirect
)
8604 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8605 if (!ent2
->is_indirect
8606 && ent2
->addend
== ent
->addend
8607 && ent2
->tls_type
== ent
->tls_type
8608 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8610 ent2
->is_indirect
= TRUE
;
8611 ent2
->got
.ent
= ent
;
8615 /* If H is undefined, make it dynamic if that makes sense. */
8618 ensure_undef_dynamic (struct bfd_link_info
*info
,
8619 struct elf_link_hash_entry
*h
)
8621 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
8623 if (htab
->dynamic_sections_created
8624 && ((info
->dynamic_undefined_weak
!= 0
8625 && h
->root
.type
== bfd_link_hash_undefweak
)
8626 || h
->root
.type
== bfd_link_hash_undefined
)
8629 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
8630 return bfd_elf_link_record_dynamic_symbol (info
, h
);
8634 /* Allocate space in .plt, .got and associated reloc sections for
8638 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8640 struct bfd_link_info
*info
;
8641 struct ppc_link_hash_table
*htab
;
8643 struct ppc_link_hash_entry
*eh
;
8644 struct got_entry
**pgent
, *gent
;
8646 if (h
->root
.type
== bfd_link_hash_indirect
)
8649 info
= (struct bfd_link_info
*) inf
;
8650 htab
= ppc_hash_table (info
);
8654 eh
= (struct ppc_link_hash_entry
*) h
;
8655 /* Run through the TLS GD got entries first if we're changing them
8657 if ((eh
->tls_mask
& (TLS_TLS
| TLS_TPRELGD
)) == (TLS_TLS
| TLS_TPRELGD
))
8658 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8659 if (gent
->got
.refcount
> 0
8660 && (gent
->tls_type
& TLS_GD
) != 0)
8662 /* This was a GD entry that has been converted to TPREL. If
8663 there happens to be a TPREL entry we can use that one. */
8664 struct got_entry
*ent
;
8665 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8666 if (ent
->got
.refcount
> 0
8667 && (ent
->tls_type
& TLS_TPREL
) != 0
8668 && ent
->addend
== gent
->addend
8669 && ent
->owner
== gent
->owner
)
8671 gent
->got
.refcount
= 0;
8675 /* If not, then we'll be using our own TPREL entry. */
8676 if (gent
->got
.refcount
!= 0)
8677 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8680 /* Remove any list entry that won't generate a word in the GOT before
8681 we call merge_got_entries. Otherwise we risk merging to empty
8683 pgent
= &h
->got
.glist
;
8684 while ((gent
= *pgent
) != NULL
)
8685 if (gent
->got
.refcount
> 0)
8687 if ((gent
->tls_type
& TLS_LD
) != 0
8690 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8691 *pgent
= gent
->next
;
8694 pgent
= &gent
->next
;
8697 *pgent
= gent
->next
;
8699 if (!htab
->do_multi_toc
)
8700 merge_got_entries (&h
->got
.glist
);
8702 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8703 if (!gent
->is_indirect
)
8705 /* Make sure this symbol is output as a dynamic symbol. */
8706 if (!ensure_undef_dynamic (info
, h
))
8709 if (!is_ppc64_elf (gent
->owner
))
8712 allocate_got (h
, info
, gent
);
8715 /* If no dynamic sections we can't have dynamic relocs, except for
8716 IFUNCs which are handled even in static executables. */
8717 if (!htab
->elf
.dynamic_sections_created
8718 && h
->type
!= STT_GNU_IFUNC
)
8719 eh
->dyn_relocs
= NULL
;
8721 /* Discard relocs on undefined symbols that must be local. */
8722 else if (h
->root
.type
== bfd_link_hash_undefined
8723 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8724 eh
->dyn_relocs
= NULL
;
8726 /* Also discard relocs on undefined weak syms with non-default
8727 visibility, or when dynamic_undefined_weak says so. */
8728 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8729 eh
->dyn_relocs
= NULL
;
8731 if (eh
->dyn_relocs
!= NULL
)
8733 struct elf_dyn_relocs
*p
, **pp
;
8735 /* In the shared -Bsymbolic case, discard space allocated for
8736 dynamic pc-relative relocs against symbols which turn out to
8737 be defined in regular objects. For the normal shared case,
8738 discard space for relocs that have become local due to symbol
8739 visibility changes. */
8741 if (bfd_link_pic (info
))
8743 /* Relocs that use pc_count are those that appear on a call
8744 insn, or certain REL relocs (see must_be_dyn_reloc) that
8745 can be generated via assembly. We want calls to
8746 protected symbols to resolve directly to the function
8747 rather than going via the plt. If people want function
8748 pointer comparisons to work as expected then they should
8749 avoid writing weird assembly. */
8750 if (SYMBOL_CALLS_LOCAL (info
, h
))
8752 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8754 p
->count
-= p
->pc_count
;
8763 if (eh
->dyn_relocs
!= NULL
)
8765 /* Make sure this symbol is output as a dynamic symbol. */
8766 if (!ensure_undef_dynamic (info
, h
))
8770 else if (ELIMINATE_COPY_RELOCS
&& h
->type
!= STT_GNU_IFUNC
)
8772 /* For the non-pic case, discard space for relocs against
8773 symbols which turn out to need copy relocs or are not
8775 if (h
->dynamic_adjusted
8777 && !ELF_COMMON_DEF_P (h
))
8779 /* Make sure this symbol is output as a dynamic symbol. */
8780 if (!ensure_undef_dynamic (info
, h
))
8783 if (h
->dynindx
== -1)
8784 eh
->dyn_relocs
= NULL
;
8787 eh
->dyn_relocs
= NULL
;
8790 /* Finally, allocate space. */
8791 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8793 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8794 if (eh
->elf
.type
== STT_GNU_IFUNC
)
8795 sreloc
= htab
->elf
.irelplt
;
8796 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8800 /* We might need a PLT entry when the symbol
8803 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
8804 d) has plt16 relocs and we are linking statically. */
8805 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
8806 || h
->type
== STT_GNU_IFUNC
8807 || (h
->needs_plt
&& h
->dynamic_adjusted
)
8810 && !htab
->elf
.dynamic_sections_created
8811 && !htab
->can_convert_all_inline_plt
8812 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
8813 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
8815 struct plt_entry
*pent
;
8816 bfd_boolean doneone
= FALSE
;
8817 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8818 if (pent
->plt
.refcount
> 0)
8820 if (!htab
->elf
.dynamic_sections_created
8821 || h
->dynindx
== -1)
8823 if (h
->type
== STT_GNU_IFUNC
)
8826 pent
->plt
.offset
= s
->size
;
8827 s
->size
+= PLT_ENTRY_SIZE (htab
);
8828 s
= htab
->elf
.irelplt
;
8833 pent
->plt
.offset
= s
->size
;
8834 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
8835 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
8840 /* If this is the first .plt entry, make room for the special
8844 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
8846 pent
->plt
.offset
= s
->size
;
8848 /* Make room for this entry. */
8849 s
->size
+= PLT_ENTRY_SIZE (htab
);
8851 /* Make room for the .glink code. */
8854 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
8857 /* We need bigger stubs past index 32767. */
8858 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
8865 /* We also need to make an entry in the .rela.plt section. */
8866 s
= htab
->elf
.srelplt
;
8869 s
->size
+= sizeof (Elf64_External_Rela
);
8873 pent
->plt
.offset
= (bfd_vma
) -1;
8876 h
->plt
.plist
= NULL
;
8882 h
->plt
.plist
= NULL
;
8889 #define PPC_LO(v) ((v) & 0xffff)
8890 #define PPC_HI(v) (((v) >> 16) & 0xffff)
8891 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
8893 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
8894 to set up space for global entry stubs. These are put in glink,
8895 after the branch table. */
8898 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
8900 struct bfd_link_info
*info
;
8901 struct ppc_link_hash_table
*htab
;
8902 struct plt_entry
*pent
;
8905 if (h
->root
.type
== bfd_link_hash_indirect
)
8908 if (!h
->pointer_equality_needed
)
8915 htab
= ppc_hash_table (info
);
8919 s
= htab
->global_entry
;
8920 plt
= htab
->elf
.splt
;
8921 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8922 if (pent
->plt
.offset
!= (bfd_vma
) -1
8923 && pent
->addend
== 0)
8925 /* For ELFv2, if this symbol is not defined in a regular file
8926 and we are not generating a shared library or pie, then we
8927 need to define the symbol in the executable on a call stub.
8928 This is to avoid text relocations. */
8929 bfd_vma off
, stub_align
, stub_off
, stub_size
;
8930 unsigned int align_power
;
8934 if (htab
->params
->plt_stub_align
>= 0)
8935 align_power
= htab
->params
->plt_stub_align
;
8937 align_power
= -htab
->params
->plt_stub_align
;
8938 /* Setting section alignment is delayed until we know it is
8939 non-empty. Otherwise the .text output section will be
8940 aligned at least to plt_stub_align even when no global
8941 entry stubs are needed. */
8942 if (s
->alignment_power
< align_power
)
8943 s
->alignment_power
= align_power
;
8944 stub_align
= (bfd_vma
) 1 << align_power
;
8945 if (htab
->params
->plt_stub_align
>= 0
8946 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
8947 - (stub_off
& -stub_align
))
8948 > ((stub_size
- 1) & -stub_align
)))
8949 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
8950 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
8951 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
8952 /* Note that for --plt-stub-align negative we have a possible
8953 dependency between stub offset and size. Break that
8954 dependency by assuming the max stub size when calculating
8956 if (PPC_HA (off
) == 0)
8958 h
->root
.type
= bfd_link_hash_defined
;
8959 h
->root
.u
.def
.section
= s
;
8960 h
->root
.u
.def
.value
= stub_off
;
8961 s
->size
= stub_off
+ stub_size
;
8967 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
8968 read-only sections. */
8971 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
8975 if (h
->root
.type
== bfd_link_hash_indirect
)
8978 sec
= readonly_dynrelocs (h
);
8981 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
8983 info
->flags
|= DF_TEXTREL
;
8984 info
->callbacks
->minfo (_("%pB: dynamic relocation against `%pT'"
8985 " in read-only section `%pA'\n"),
8986 sec
->owner
, h
->root
.root
.string
, sec
);
8988 /* Not an error, just cut short the traversal. */
8994 /* Set the sizes of the dynamic sections. */
8997 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
8998 struct bfd_link_info
*info
)
9000 struct ppc_link_hash_table
*htab
;
9005 struct got_entry
*first_tlsld
;
9007 htab
= ppc_hash_table (info
);
9011 dynobj
= htab
->elf
.dynobj
;
9015 if (htab
->elf
.dynamic_sections_created
)
9017 /* Set the contents of the .interp section to the interpreter. */
9018 if (bfd_link_executable (info
) && !info
->nointerp
)
9020 s
= bfd_get_linker_section (dynobj
, ".interp");
9023 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
9024 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
9028 /* Set up .got offsets for local syms, and space for local dynamic
9030 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9032 struct got_entry
**lgot_ents
;
9033 struct got_entry
**end_lgot_ents
;
9034 struct plt_entry
**local_plt
;
9035 struct plt_entry
**end_local_plt
;
9036 unsigned char *lgot_masks
;
9037 bfd_size_type locsymcount
;
9038 Elf_Internal_Shdr
*symtab_hdr
;
9040 if (!is_ppc64_elf (ibfd
))
9043 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
9045 struct ppc_dyn_relocs
*p
;
9047 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
9049 if (!bfd_is_abs_section (p
->sec
)
9050 && bfd_is_abs_section (p
->sec
->output_section
))
9052 /* Input section has been discarded, either because
9053 it is a copy of a linkonce section or due to
9054 linker script /DISCARD/, so we'll be discarding
9057 else if (p
->count
!= 0)
9059 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
9061 srel
= htab
->elf
.irelplt
;
9062 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9063 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
9064 info
->flags
|= DF_TEXTREL
;
9069 lgot_ents
= elf_local_got_ents (ibfd
);
9073 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9074 locsymcount
= symtab_hdr
->sh_info
;
9075 end_lgot_ents
= lgot_ents
+ locsymcount
;
9076 local_plt
= (struct plt_entry
**) end_lgot_ents
;
9077 end_local_plt
= local_plt
+ locsymcount
;
9078 lgot_masks
= (unsigned char *) end_local_plt
;
9079 s
= ppc64_elf_tdata (ibfd
)->got
;
9080 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
9082 struct got_entry
**pent
, *ent
;
9085 while ((ent
= *pent
) != NULL
)
9086 if (ent
->got
.refcount
> 0)
9088 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
9090 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
9095 unsigned int ent_size
= 8;
9096 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
9098 ent
->got
.offset
= s
->size
;
9099 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
9104 s
->size
+= ent_size
;
9105 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9107 htab
->elf
.irelplt
->size
+= rel_size
;
9108 htab
->got_reli_size
+= rel_size
;
9110 else if (bfd_link_pic (info
)
9111 && !((ent
->tls_type
& TLS_TPREL
) != 0
9112 && bfd_link_executable (info
)))
9114 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9115 srel
->size
+= rel_size
;
9124 /* Allocate space for plt calls to local syms. */
9125 lgot_masks
= (unsigned char *) end_local_plt
;
9126 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
9128 struct plt_entry
*ent
;
9130 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9131 if (ent
->plt
.refcount
> 0)
9133 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9136 ent
->plt
.offset
= s
->size
;
9137 s
->size
+= PLT_ENTRY_SIZE (htab
);
9138 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
9140 else if (htab
->can_convert_all_inline_plt
9141 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
9142 ent
->plt
.offset
= (bfd_vma
) -1;
9146 ent
->plt
.offset
= s
->size
;
9147 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9148 if (bfd_link_pic (info
))
9149 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
9153 ent
->plt
.offset
= (bfd_vma
) -1;
9157 /* Allocate global sym .plt and .got entries, and space for global
9158 sym dynamic relocs. */
9159 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9161 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
9162 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
9165 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9167 struct got_entry
*ent
;
9169 if (!is_ppc64_elf (ibfd
))
9172 ent
= ppc64_tlsld_got (ibfd
);
9173 if (ent
->got
.refcount
> 0)
9175 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9177 ent
->is_indirect
= TRUE
;
9178 ent
->got
.ent
= first_tlsld
;
9182 if (first_tlsld
== NULL
)
9184 s
= ppc64_elf_tdata (ibfd
)->got
;
9185 ent
->got
.offset
= s
->size
;
9188 if (bfd_link_pic (info
))
9190 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9191 srel
->size
+= sizeof (Elf64_External_Rela
);
9196 ent
->got
.offset
= (bfd_vma
) -1;
9199 /* We now have determined the sizes of the various dynamic sections.
9200 Allocate memory for them. */
9202 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9204 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9207 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9208 /* These haven't been allocated yet; don't strip. */
9210 else if (s
== htab
->elf
.sgot
9211 || s
== htab
->elf
.splt
9212 || s
== htab
->elf
.iplt
9213 || s
== htab
->pltlocal
9215 || s
== htab
->global_entry
9216 || s
== htab
->elf
.sdynbss
9217 || s
== htab
->elf
.sdynrelro
)
9219 /* Strip this section if we don't need it; see the
9222 else if (s
== htab
->glink_eh_frame
)
9224 if (!bfd_is_abs_section (s
->output_section
))
9225 /* Not sized yet. */
9228 else if (CONST_STRNEQ (s
->name
, ".rela"))
9232 if (s
!= htab
->elf
.srelplt
)
9235 /* We use the reloc_count field as a counter if we need
9236 to copy relocs into the output file. */
9242 /* It's not one of our sections, so don't allocate space. */
9248 /* If we don't need this section, strip it from the
9249 output file. This is mostly to handle .rela.bss and
9250 .rela.plt. We must create both sections in
9251 create_dynamic_sections, because they must be created
9252 before the linker maps input sections to output
9253 sections. The linker does that before
9254 adjust_dynamic_symbol is called, and it is that
9255 function which decides whether anything needs to go
9256 into these sections. */
9257 s
->flags
|= SEC_EXCLUDE
;
9261 if (bfd_is_abs_section (s
->output_section
))
9262 _bfd_error_handler (_("warning: discarding dynamic section %s"),
9265 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9268 /* Allocate memory for the section contents. We use bfd_zalloc
9269 here in case unused entries are not reclaimed before the
9270 section's contents are written out. This should not happen,
9271 but this way if it does we get a R_PPC64_NONE reloc in .rela
9272 sections instead of garbage.
9273 We also rely on the section contents being zero when writing
9274 the GOT and .dynrelro. */
9275 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9276 if (s
->contents
== NULL
)
9280 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9282 if (!is_ppc64_elf (ibfd
))
9285 s
= ppc64_elf_tdata (ibfd
)->got
;
9286 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
9289 s
->flags
|= SEC_EXCLUDE
;
9292 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9293 if (s
->contents
== NULL
)
9297 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9301 s
->flags
|= SEC_EXCLUDE
;
9304 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9305 if (s
->contents
== NULL
)
9313 if (htab
->elf
.dynamic_sections_created
)
9315 bfd_boolean tls_opt
;
9317 /* Add some entries to the .dynamic section. We fill in the
9318 values later, in ppc64_elf_finish_dynamic_sections, but we
9319 must add the entries now so that we get the correct size for
9320 the .dynamic section. The DT_DEBUG entry is filled in by the
9321 dynamic linker and used by the debugger. */
9322 #define add_dynamic_entry(TAG, VAL) \
9323 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9325 if (bfd_link_executable (info
))
9327 if (!add_dynamic_entry (DT_DEBUG
, 0))
9331 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
9333 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9334 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9335 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9336 || !add_dynamic_entry (DT_JMPREL
, 0)
9337 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9341 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
9343 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9344 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9348 tls_opt
= (htab
->params
->tls_get_addr_opt
9349 && htab
->tls_get_addr_fd
!= NULL
9350 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
9351 if (tls_opt
|| !htab
->opd_abi
)
9353 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
9359 if (!add_dynamic_entry (DT_RELA
, 0)
9360 || !add_dynamic_entry (DT_RELASZ
, 0)
9361 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9364 /* If any dynamic relocs apply to a read-only section,
9365 then we need a DT_TEXTREL entry. */
9366 if ((info
->flags
& DF_TEXTREL
) == 0)
9367 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
9369 if ((info
->flags
& DF_TEXTREL
) != 0)
9371 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9376 #undef add_dynamic_entry
9381 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
9384 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
9386 if (h
->plt
.plist
!= NULL
9388 && !h
->pointer_equality_needed
)
9391 return _bfd_elf_hash_symbol (h
);
9394 /* Determine the type of stub needed, if any, for a call. */
9396 static inline enum ppc_stub_type
9397 ppc_type_of_stub (asection
*input_sec
,
9398 const Elf_Internal_Rela
*rel
,
9399 struct ppc_link_hash_entry
**hash
,
9400 struct plt_entry
**plt_ent
,
9401 bfd_vma destination
,
9402 unsigned long local_off
)
9404 struct ppc_link_hash_entry
*h
= *hash
;
9406 bfd_vma branch_offset
;
9407 bfd_vma max_branch_offset
;
9408 enum elf_ppc64_reloc_type r_type
;
9412 struct plt_entry
*ent
;
9413 struct ppc_link_hash_entry
*fdh
= h
;
9415 && h
->oh
->is_func_descriptor
)
9417 fdh
= ppc_follow_link (h
->oh
);
9421 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9422 if (ent
->addend
== rel
->r_addend
9423 && ent
->plt
.offset
!= (bfd_vma
) -1)
9426 return ppc_stub_plt_call
;
9429 /* Here, we know we don't have a plt entry. If we don't have a
9430 either a defined function descriptor or a defined entry symbol
9431 in a regular object file, then it is pointless trying to make
9432 any other type of stub. */
9433 if (!is_static_defined (&fdh
->elf
)
9434 && !is_static_defined (&h
->elf
))
9435 return ppc_stub_none
;
9437 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9439 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9440 struct plt_entry
**local_plt
= (struct plt_entry
**)
9441 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9442 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9444 if (local_plt
[r_symndx
] != NULL
)
9446 struct plt_entry
*ent
;
9448 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9449 if (ent
->addend
== rel
->r_addend
9450 && ent
->plt
.offset
!= (bfd_vma
) -1)
9453 return ppc_stub_plt_call
;
9458 /* Determine where the call point is. */
9459 location
= (input_sec
->output_offset
9460 + input_sec
->output_section
->vma
9463 branch_offset
= destination
- location
;
9464 r_type
= ELF64_R_TYPE (rel
->r_info
);
9466 /* Determine if a long branch stub is needed. */
9467 max_branch_offset
= 1 << 25;
9468 if (r_type
== R_PPC64_REL14
9469 || r_type
== R_PPC64_REL14_BRTAKEN
9470 || r_type
== R_PPC64_REL14_BRNTAKEN
)
9471 max_branch_offset
= 1 << 15;
9473 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
9474 /* We need a stub. Figure out whether a long_branch or plt_branch
9476 return ppc_stub_long_branch
;
9478 return ppc_stub_none
;
9481 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
9482 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
9487 . lis %r12,xxx-1b@highest
9488 . ori %r12,%r12,xxx-1b@higher
9490 . oris %r12,%r12,xxx-1b@high
9491 . ori %r12,%r12,xxx-1b@l
9492 . add/ldx %r12,%r11,%r12 */
9495 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bfd_boolean load
)
9497 bfd_put_32 (abfd
, MFLR_R12
, p
);
9499 bfd_put_32 (abfd
, BCL_20_31
, p
);
9501 bfd_put_32 (abfd
, MFLR_R11
, p
);
9503 bfd_put_32 (abfd
, MTLR_R12
, p
);
9505 if (off
+ 0x8000 < 0x10000)
9508 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
9510 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
9513 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9515 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
9518 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
9520 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
9525 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9527 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
9532 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
9534 if (((off
>> 32) & 0xffff) != 0)
9536 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
9540 if (((off
>> 32) & 0xffffffffULL
) != 0)
9542 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
9545 if (PPC_HI (off
) != 0)
9547 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
9550 if (PPC_LO (off
) != 0)
9552 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
9556 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
9558 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
9565 size_offset (bfd_vma off
)
9568 if (off
+ 0x8000 < 0x10000)
9570 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9574 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9579 if (((off
>> 32) & 0xffff) != 0)
9582 if (((off
>> 32) & 0xffffffffULL
) != 0)
9584 if (PPC_HI (off
) != 0)
9586 if (PPC_LO (off
) != 0)
9593 /* Emit .eh_frame opcode to advance pc by DELTA. */
9596 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
9600 *eh
++ = DW_CFA_advance_loc
+ delta
;
9601 else if (delta
< 256)
9603 *eh
++ = DW_CFA_advance_loc1
;
9606 else if (delta
< 65536)
9608 *eh
++ = DW_CFA_advance_loc2
;
9609 bfd_put_16 (abfd
, delta
, eh
);
9614 *eh
++ = DW_CFA_advance_loc4
;
9615 bfd_put_32 (abfd
, delta
, eh
);
9621 /* Size of required .eh_frame opcode to advance pc by DELTA. */
9624 eh_advance_size (unsigned int delta
)
9627 /* DW_CFA_advance_loc+[1..63]. */
9629 if (delta
< 256 * 4)
9630 /* DW_CFA_advance_loc1, byte. */
9632 if (delta
< 65536 * 4)
9633 /* DW_CFA_advance_loc2, 2 bytes. */
9635 /* DW_CFA_advance_loc4, 4 bytes. */
9639 /* With power7 weakly ordered memory model, it is possible for ld.so
9640 to update a plt entry in one thread and have another thread see a
9641 stale zero toc entry. To avoid this we need some sort of acquire
9642 barrier in the call stub. One solution is to make the load of the
9643 toc word seem to appear to depend on the load of the function entry
9644 word. Another solution is to test for r2 being zero, and branch to
9645 the appropriate glink entry if so.
9647 . fake dep barrier compare
9648 . ld 12,xxx(2) ld 12,xxx(2)
9650 . xor 11,12,12 ld 2,xxx+8(2)
9651 . add 2,2,11 cmpldi 2,0
9652 . ld 2,xxx+8(2) bnectr+
9653 . bctr b <glink_entry>
9655 The solution involving the compare turns out to be faster, so
9656 that's what we use unless the branch won't reach. */
9658 #define ALWAYS_USE_FAKE_DEP 0
9659 #define ALWAYS_EMIT_R2SAVE 0
9661 static inline unsigned int
9662 plt_stub_size (struct ppc_link_hash_table
*htab
,
9663 struct ppc_stub_hash_entry
*stub_entry
,
9668 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
9670 size
= 8 + size_offset (off
- 8);
9671 if (stub_entry
->stub_type
> ppc_stub_plt_call_notoc
)
9677 if (ALWAYS_EMIT_R2SAVE
9678 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9680 if (PPC_HA (off
) != 0)
9685 if (htab
->params
->plt_static_chain
)
9687 if (htab
->params
->plt_thread_safe
9688 && htab
->elf
.dynamic_sections_created
9689 && stub_entry
->h
!= NULL
9690 && stub_entry
->h
->elf
.dynindx
!= -1)
9692 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
9695 if (stub_entry
->h
!= NULL
9696 && (stub_entry
->h
== htab
->tls_get_addr_fd
9697 || stub_entry
->h
== htab
->tls_get_addr
)
9698 && htab
->params
->tls_get_addr_opt
)
9701 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9707 /* Depending on the sign of plt_stub_align:
9708 If positive, return the padding to align to a 2**plt_stub_align
9710 If negative, if this stub would cross fewer 2**plt_stub_align
9711 boundaries if we align, then return the padding needed to do so. */
9713 static inline unsigned int
9714 plt_stub_pad (struct ppc_link_hash_table
*htab
,
9715 struct ppc_stub_hash_entry
*stub_entry
,
9720 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
9722 if (htab
->params
->plt_stub_align
>= 0)
9724 stub_align
= 1 << htab
->params
->plt_stub_align
;
9725 if ((stub_off
& (stub_align
- 1)) != 0)
9726 return stub_align
- (stub_off
& (stub_align
- 1));
9730 stub_align
= 1 << -htab
->params
->plt_stub_align
;
9731 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
9732 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
9733 > ((stub_size
- 1) & -stub_align
))
9734 return stub_align
- (stub_off
& (stub_align
- 1));
9738 /* Build a .plt call stub. */
9740 static inline bfd_byte
*
9741 build_plt_stub (struct ppc_link_hash_table
*htab
,
9742 struct ppc_stub_hash_entry
*stub_entry
,
9743 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
9745 bfd
*obfd
= htab
->params
->stub_bfd
;
9746 bfd_boolean plt_load_toc
= htab
->opd_abi
;
9747 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
9748 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
9749 && htab
->elf
.dynamic_sections_created
9750 && stub_entry
->h
!= NULL
9751 && stub_entry
->h
->elf
.dynindx
!= -1);
9752 bfd_boolean use_fake_dep
= plt_thread_safe
;
9753 bfd_vma cmp_branch_off
= 0;
9755 if (!ALWAYS_USE_FAKE_DEP
9758 && !((stub_entry
->h
== htab
->tls_get_addr_fd
9759 || stub_entry
->h
== htab
->tls_get_addr
)
9760 && htab
->params
->tls_get_addr_opt
))
9762 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
9763 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
9764 / PLT_ENTRY_SIZE (htab
));
9765 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
9768 if (pltindex
> 32768)
9769 glinkoff
+= (pltindex
- 32768) * 4;
9771 + htab
->glink
->output_offset
9772 + htab
->glink
->output_section
->vma
);
9773 from
= (p
- stub_entry
->group
->stub_sec
->contents
9774 + 4 * (ALWAYS_EMIT_R2SAVE
9775 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9776 + 4 * (PPC_HA (offset
) != 0)
9777 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
9779 + 4 * (plt_static_chain
!= 0)
9781 + stub_entry
->group
->stub_sec
->output_offset
9782 + stub_entry
->group
->stub_sec
->output_section
->vma
);
9783 cmp_branch_off
= to
- from
;
9784 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
9787 if (PPC_HA (offset
) != 0)
9791 if (ALWAYS_EMIT_R2SAVE
9792 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9794 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9795 r
[1].r_offset
= r
[0].r_offset
+ 4;
9796 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9797 r
[1].r_addend
= r
[0].r_addend
;
9800 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9802 r
[2].r_offset
= r
[1].r_offset
+ 4;
9803 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
9804 r
[2].r_addend
= r
[0].r_addend
;
9808 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
9809 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9810 r
[2].r_addend
= r
[0].r_addend
+ 8;
9811 if (plt_static_chain
)
9813 r
[3].r_offset
= r
[2].r_offset
+ 4;
9814 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9815 r
[3].r_addend
= r
[0].r_addend
+ 16;
9820 if (ALWAYS_EMIT_R2SAVE
9821 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9822 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
9825 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
9826 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
9830 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
9831 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
9834 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9836 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
9839 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
9844 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
9845 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
9847 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
9848 if (plt_static_chain
)
9849 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
9856 if (ALWAYS_EMIT_R2SAVE
9857 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9859 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9862 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9864 r
[1].r_offset
= r
[0].r_offset
+ 4;
9865 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
9866 r
[1].r_addend
= r
[0].r_addend
;
9870 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
9871 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9872 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
9873 if (plt_static_chain
)
9875 r
[2].r_offset
= r
[1].r_offset
+ 4;
9876 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9877 r
[2].r_addend
= r
[0].r_addend
+ 8;
9882 if (ALWAYS_EMIT_R2SAVE
9883 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9884 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
9885 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
9887 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9889 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
9892 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
9897 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
9898 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
9900 if (plt_static_chain
)
9901 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
9902 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
9905 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
9907 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
9908 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
9909 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
9912 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9916 /* Build a special .plt call stub for __tls_get_addr. */
9918 #define LD_R11_0R3 0xe9630000
9919 #define LD_R12_0R3 0xe9830000
9920 #define MR_R0_R3 0x7c601b78
9921 #define CMPDI_R11_0 0x2c2b0000
9922 #define ADD_R3_R12_R13 0x7c6c6a14
9923 #define BEQLR 0x4d820020
9924 #define MR_R3_R0 0x7c030378
9925 #define STD_R11_0R1 0xf9610000
9926 #define BCTRL 0x4e800421
9927 #define LD_R11_0R1 0xe9610000
9928 #define MTLR_R11 0x7d6803a6
9930 static inline bfd_byte
*
9931 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
9932 struct ppc_stub_hash_entry
*stub_entry
,
9933 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
9935 bfd
*obfd
= htab
->params
->stub_bfd
;
9938 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
9939 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
9940 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
9941 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
9942 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
9943 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
9944 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
9946 r
[0].r_offset
+= 7 * 4;
9947 if (stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
9948 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
9950 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
9951 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
9954 r
[0].r_offset
+= 2 * 4;
9955 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
9956 bfd_put_32 (obfd
, BCTRL
, p
- 4);
9958 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
9959 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
9960 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
9961 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
9963 if (htab
->glink_eh_frame
!= NULL
9964 && htab
->glink_eh_frame
->size
!= 0)
9966 bfd_byte
*base
, *eh
;
9967 unsigned int lr_used
, delta
;
9969 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
9970 eh
= base
+ stub_entry
->group
->eh_size
;
9971 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
9972 delta
= lr_used
- stub_entry
->group
->lr_restore
;
9973 stub_entry
->group
->lr_restore
= lr_used
+ 16;
9974 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
9975 *eh
++ = DW_CFA_offset_extended_sf
;
9977 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
9978 *eh
++ = DW_CFA_advance_loc
+ 4;
9979 *eh
++ = DW_CFA_restore_extended
;
9981 stub_entry
->group
->eh_size
= eh
- base
;
9986 static Elf_Internal_Rela
*
9987 get_relocs (asection
*sec
, int count
)
9989 Elf_Internal_Rela
*relocs
;
9990 struct bfd_elf_section_data
*elfsec_data
;
9992 elfsec_data
= elf_section_data (sec
);
9993 relocs
= elfsec_data
->relocs
;
9996 bfd_size_type relsize
;
9997 relsize
= sec
->reloc_count
* sizeof (*relocs
);
9998 relocs
= bfd_alloc (sec
->owner
, relsize
);
10001 elfsec_data
->relocs
= relocs
;
10002 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10003 sizeof (Elf_Internal_Shdr
));
10004 if (elfsec_data
->rela
.hdr
== NULL
)
10006 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10007 * sizeof (Elf64_External_Rela
));
10008 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10009 sec
->reloc_count
= 0;
10011 relocs
+= sec
->reloc_count
;
10012 sec
->reloc_count
+= count
;
10017 get_r2off (struct bfd_link_info
*info
,
10018 struct ppc_stub_hash_entry
*stub_entry
)
10020 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10021 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10025 /* Support linking -R objects. Get the toc pointer from the
10028 if (!htab
->opd_abi
)
10030 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10031 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10033 if (strcmp (opd
->name
, ".opd") != 0
10034 || opd
->reloc_count
!= 0)
10036 info
->callbacks
->einfo
10037 (_("%P: cannot find opd entry toc for `%pT'\n"),
10038 stub_entry
->h
->elf
.root
.root
.string
);
10039 bfd_set_error (bfd_error_bad_value
);
10040 return (bfd_vma
) -1;
10042 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10043 return (bfd_vma
) -1;
10044 r2off
= bfd_get_64 (opd
->owner
, buf
);
10045 r2off
-= elf_gp (info
->output_bfd
);
10047 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10052 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10054 struct ppc_stub_hash_entry
*stub_entry
;
10055 struct ppc_branch_hash_entry
*br_entry
;
10056 struct bfd_link_info
*info
;
10057 struct ppc_link_hash_table
*htab
;
10061 Elf_Internal_Rela
*r
;
10064 /* Massage our args to the form they really have. */
10065 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10068 htab
= ppc_hash_table (info
);
10072 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
10073 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10075 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10076 switch (stub_entry
->stub_type
)
10078 case ppc_stub_long_branch
:
10079 case ppc_stub_long_branch_r2off
:
10080 /* Branches are relative. This is where we are going to. */
10081 targ
= (stub_entry
->target_value
10082 + stub_entry
->target_section
->output_offset
10083 + stub_entry
->target_section
->output_section
->vma
);
10084 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10086 /* And this is where we are coming from. */
10087 off
= (stub_entry
->stub_offset
10088 + stub_entry
->group
->stub_sec
->output_offset
10089 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10093 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10095 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10097 if (r2off
== (bfd_vma
) -1)
10099 htab
->stub_error
= TRUE
;
10102 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10104 if (PPC_HA (r2off
) != 0)
10106 bfd_put_32 (htab
->params
->stub_bfd
,
10107 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10110 if (PPC_LO (r2off
) != 0)
10112 bfd_put_32 (htab
->params
->stub_bfd
,
10113 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10118 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
10121 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10124 (_("long branch stub `%s' offset overflow"),
10125 stub_entry
->root
.string
);
10126 htab
->stub_error
= TRUE
;
10130 if (info
->emitrelocations
)
10132 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
10135 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
10136 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10137 r
->r_addend
= targ
;
10138 if (stub_entry
->h
!= NULL
)
10140 struct elf_link_hash_entry
**hashes
;
10141 unsigned long symndx
;
10142 struct ppc_link_hash_entry
*h
;
10144 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10145 if (hashes
== NULL
)
10147 bfd_size_type hsize
;
10149 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10150 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10151 if (hashes
== NULL
)
10153 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10154 htab
->stub_globals
= 1;
10156 symndx
= htab
->stub_globals
++;
10158 hashes
[symndx
] = &h
->elf
;
10159 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
10160 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10161 h
= ppc_follow_link (h
->oh
);
10162 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
10163 /* H is an opd symbol. The addend must be zero. */
10167 off
= (h
->elf
.root
.u
.def
.value
10168 + h
->elf
.root
.u
.def
.section
->output_offset
10169 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10170 r
->r_addend
-= off
;
10176 case ppc_stub_plt_branch
:
10177 case ppc_stub_plt_branch_r2off
:
10178 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10179 stub_entry
->root
.string
+ 9,
10181 if (br_entry
== NULL
)
10183 _bfd_error_handler (_("can't find branch stub `%s'"),
10184 stub_entry
->root
.string
);
10185 htab
->stub_error
= TRUE
;
10189 targ
= (stub_entry
->target_value
10190 + stub_entry
->target_section
->output_offset
10191 + stub_entry
->target_section
->output_section
->vma
);
10192 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10193 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10195 bfd_put_64 (htab
->brlt
->owner
, targ
,
10196 htab
->brlt
->contents
+ br_entry
->offset
);
10198 if (br_entry
->iter
== htab
->stub_iteration
)
10200 br_entry
->iter
= 0;
10202 if (htab
->relbrlt
!= NULL
)
10204 /* Create a reloc for the branch lookup table entry. */
10205 Elf_Internal_Rela rela
;
10208 rela
.r_offset
= (br_entry
->offset
10209 + htab
->brlt
->output_offset
10210 + htab
->brlt
->output_section
->vma
);
10211 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10212 rela
.r_addend
= targ
;
10214 rl
= htab
->relbrlt
->contents
;
10215 rl
+= (htab
->relbrlt
->reloc_count
++
10216 * sizeof (Elf64_External_Rela
));
10217 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
10219 else if (info
->emitrelocations
)
10221 r
= get_relocs (htab
->brlt
, 1);
10224 /* brlt, being SEC_LINKER_CREATED does not go through the
10225 normal reloc processing. Symbols and offsets are not
10226 translated from input file to output file form, so
10227 set up the offset per the output file. */
10228 r
->r_offset
= (br_entry
->offset
10229 + htab
->brlt
->output_offset
10230 + htab
->brlt
->output_section
->vma
);
10231 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10232 r
->r_addend
= targ
;
10236 targ
= (br_entry
->offset
10237 + htab
->brlt
->output_offset
10238 + htab
->brlt
->output_section
->vma
);
10240 off
= (elf_gp (info
->output_bfd
)
10241 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10244 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10246 info
->callbacks
->einfo
10247 (_("%P: linkage table error against `%pT'\n"),
10248 stub_entry
->root
.string
);
10249 bfd_set_error (bfd_error_bad_value
);
10250 htab
->stub_error
= TRUE
;
10254 if (info
->emitrelocations
)
10256 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
10259 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10260 if (bfd_big_endian (info
->output_bfd
))
10261 r
[0].r_offset
+= 2;
10262 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
10263 r
[0].r_offset
+= 4;
10264 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10265 r
[0].r_addend
= targ
;
10266 if (PPC_HA (off
) != 0)
10268 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10269 r
[1].r_offset
= r
[0].r_offset
+ 4;
10270 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10271 r
[1].r_addend
= r
[0].r_addend
;
10276 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10278 if (PPC_HA (off
) != 0)
10280 bfd_put_32 (htab
->params
->stub_bfd
,
10281 ADDIS_R12_R2
| PPC_HA (off
), p
);
10283 bfd_put_32 (htab
->params
->stub_bfd
,
10284 LD_R12_0R12
| PPC_LO (off
), p
);
10287 bfd_put_32 (htab
->params
->stub_bfd
,
10288 LD_R12_0R2
| PPC_LO (off
), p
);
10292 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10294 if (r2off
== (bfd_vma
) -1)
10296 htab
->stub_error
= TRUE
;
10300 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10302 if (PPC_HA (off
) != 0)
10304 bfd_put_32 (htab
->params
->stub_bfd
,
10305 ADDIS_R12_R2
| PPC_HA (off
), p
);
10307 bfd_put_32 (htab
->params
->stub_bfd
,
10308 LD_R12_0R12
| PPC_LO (off
), p
);
10311 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
10313 if (PPC_HA (r2off
) != 0)
10316 bfd_put_32 (htab
->params
->stub_bfd
,
10317 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10319 if (PPC_LO (r2off
) != 0)
10322 bfd_put_32 (htab
->params
->stub_bfd
,
10323 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10327 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
10329 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
10333 case ppc_stub_long_branch_notoc
:
10334 case ppc_stub_long_branch_both
:
10335 case ppc_stub_plt_branch_notoc
:
10336 case ppc_stub_plt_branch_both
:
10337 case ppc_stub_plt_call_notoc
:
10338 case ppc_stub_plt_call_both
:
10340 off
= (stub_entry
->stub_offset
10341 + stub_entry
->group
->stub_sec
->output_offset
10342 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10343 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
10344 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
10345 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10348 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10351 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
10353 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10354 if (targ
>= (bfd_vma
) -2)
10357 plt
= htab
->elf
.splt
;
10358 if (!htab
->elf
.dynamic_sections_created
10359 || stub_entry
->h
== NULL
10360 || stub_entry
->h
->elf
.dynindx
== -1)
10362 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10363 plt
= htab
->elf
.iplt
;
10365 plt
= htab
->pltlocal
;
10367 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10370 targ
= (stub_entry
->target_value
10371 + stub_entry
->target_section
->output_offset
10372 + stub_entry
->target_section
->output_section
->vma
);
10375 /* The notoc stubs calculate their target (either a PLT entry or
10376 the global entry point of a function) relative to the PC
10377 returned by the "bcl" two instructions past the start of the
10378 sequence emitted by build_offset. The offset is therefore 8
10379 less than calculated from the start of the sequence. */
10381 p
= build_offset (htab
->params
->stub_bfd
, p
, off
,
10382 stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
);
10383 if (stub_entry
->stub_type
<= ppc_stub_long_branch_both
)
10386 from
= (stub_entry
->stub_offset
10387 + stub_entry
->group
->stub_sec
->output_offset
10388 + stub_entry
->group
->stub_sec
->output_section
->vma
10390 bfd_put_32 (htab
->params
->stub_bfd
,
10391 B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
10395 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
10397 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
10401 if (htab
->glink_eh_frame
!= NULL
10402 && htab
->glink_eh_frame
->size
!= 0)
10404 bfd_byte
*base
, *eh
;
10405 unsigned int lr_used
, delta
;
10407 base
= (htab
->glink_eh_frame
->contents
10408 + stub_entry
->group
->eh_base
+ 17);
10409 eh
= base
+ stub_entry
->group
->eh_size
;
10410 lr_used
= stub_entry
->stub_offset
+ 8;
10411 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
10412 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
10413 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10415 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10416 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10417 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
10418 *eh
++ = DW_CFA_register
;
10421 *eh
++ = DW_CFA_advance_loc
+ 2;
10422 *eh
++ = DW_CFA_restore_extended
;
10424 stub_entry
->group
->eh_size
= eh
- base
;
10428 case ppc_stub_plt_call
:
10429 case ppc_stub_plt_call_r2save
:
10430 if (stub_entry
->h
!= NULL
10431 && stub_entry
->h
->is_func_descriptor
10432 && stub_entry
->h
->oh
!= NULL
)
10434 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
10436 /* If the old-ABI "dot-symbol" is undefined make it weak so
10437 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
10438 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
10439 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
10440 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
10441 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
10444 /* Now build the stub. */
10445 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10446 if (targ
>= (bfd_vma
) -2)
10449 plt
= htab
->elf
.splt
;
10450 if (!htab
->elf
.dynamic_sections_created
10451 || stub_entry
->h
== NULL
10452 || stub_entry
->h
->elf
.dynindx
== -1)
10454 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10455 plt
= htab
->elf
.iplt
;
10457 plt
= htab
->pltlocal
;
10459 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10461 off
= (elf_gp (info
->output_bfd
)
10462 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10465 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10467 info
->callbacks
->einfo
10468 /* xgettext:c-format */
10469 (_("%P: linkage table error against `%pT'\n"),
10470 stub_entry
->h
!= NULL
10471 ? stub_entry
->h
->elf
.root
.root
.string
10473 bfd_set_error (bfd_error_bad_value
);
10474 htab
->stub_error
= TRUE
;
10479 if (info
->emitrelocations
)
10481 r
= get_relocs (stub_entry
->group
->stub_sec
,
10482 ((PPC_HA (off
) != 0)
10484 ? 2 + (htab
->params
->plt_static_chain
10485 && PPC_HA (off
+ 16) == PPC_HA (off
))
10489 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10490 if (bfd_big_endian (info
->output_bfd
))
10491 r
[0].r_offset
+= 2;
10492 r
[0].r_addend
= targ
;
10494 if (stub_entry
->h
!= NULL
10495 && (stub_entry
->h
== htab
->tls_get_addr_fd
10496 || stub_entry
->h
== htab
->tls_get_addr
)
10497 && htab
->params
->tls_get_addr_opt
)
10498 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
10500 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
10503 case ppc_stub_save_res
:
10511 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
10513 if (htab
->params
->emit_stub_syms
)
10515 struct elf_link_hash_entry
*h
;
10518 const char *const stub_str
[] = { "long_branch",
10531 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
10532 len2
= strlen (stub_entry
->root
.string
);
10533 name
= bfd_malloc (len1
+ len2
+ 2);
10536 memcpy (name
, stub_entry
->root
.string
, 9);
10537 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
10538 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
10539 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
10542 if (h
->root
.type
== bfd_link_hash_new
)
10544 h
->root
.type
= bfd_link_hash_defined
;
10545 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
10546 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
10547 h
->ref_regular
= 1;
10548 h
->def_regular
= 1;
10549 h
->ref_regular_nonweak
= 1;
10550 h
->forced_local
= 1;
10552 h
->root
.linker_def
= 1;
10559 /* As above, but don't actually build the stub. Just bump offset so
10560 we know stub section sizes, and select plt_branch stubs where
10561 long_branch stubs won't do. */
10564 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10566 struct ppc_stub_hash_entry
*stub_entry
;
10567 struct bfd_link_info
*info
;
10568 struct ppc_link_hash_table
*htab
;
10570 bfd_vma targ
, off
, r2off
;
10571 unsigned int size
, extra
, lr_used
, delta
;
10573 /* Massage our args to the form they really have. */
10574 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10577 htab
= ppc_hash_table (info
);
10581 /* Make a note of the offset within the stubs for this entry. */
10582 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10584 if (stub_entry
->h
!= NULL
10585 && stub_entry
->h
->save_res
10586 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
10587 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
10589 /* Don't make stubs to out-of-line register save/restore
10590 functions. Instead, emit copies of the functions. */
10591 stub_entry
->group
->needs_save_res
= 1;
10592 stub_entry
->stub_type
= ppc_stub_save_res
;
10596 switch (stub_entry
->stub_type
)
10598 case ppc_stub_plt_branch
:
10599 case ppc_stub_plt_branch_r2off
:
10600 /* Reset the stub type from the plt branch variant in case we now
10601 can reach with a shorter stub. */
10602 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
10603 /* Fall through. */
10604 case ppc_stub_long_branch
:
10605 case ppc_stub_long_branch_r2off
:
10606 targ
= (stub_entry
->target_value
10607 + stub_entry
->target_section
->output_offset
10608 + stub_entry
->target_section
->output_section
->vma
);
10609 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10610 off
= (stub_entry
->stub_offset
10611 + stub_entry
->group
->stub_sec
->output_offset
10612 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10616 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10618 r2off
= get_r2off (info
, stub_entry
);
10619 if (r2off
== (bfd_vma
) -1)
10621 htab
->stub_error
= TRUE
;
10625 if (PPC_HA (r2off
) != 0)
10627 if (PPC_LO (r2off
) != 0)
10633 /* If the branch offset is too big, use a ppc_stub_plt_branch.
10634 Do the same for -R objects without function descriptors. */
10635 if ((stub_entry
->stub_type
== ppc_stub_long_branch_r2off
10637 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
10638 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10640 struct ppc_branch_hash_entry
*br_entry
;
10642 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10643 stub_entry
->root
.string
+ 9,
10645 if (br_entry
== NULL
)
10647 _bfd_error_handler (_("can't build branch stub `%s'"),
10648 stub_entry
->root
.string
);
10649 htab
->stub_error
= TRUE
;
10653 if (br_entry
->iter
!= htab
->stub_iteration
)
10655 br_entry
->iter
= htab
->stub_iteration
;
10656 br_entry
->offset
= htab
->brlt
->size
;
10657 htab
->brlt
->size
+= 8;
10659 if (htab
->relbrlt
!= NULL
)
10660 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
10661 else if (info
->emitrelocations
)
10663 htab
->brlt
->reloc_count
+= 1;
10664 htab
->brlt
->flags
|= SEC_RELOC
;
10668 targ
= (br_entry
->offset
10669 + htab
->brlt
->output_offset
10670 + htab
->brlt
->output_section
->vma
);
10671 off
= (elf_gp (info
->output_bfd
)
10672 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10675 if (info
->emitrelocations
)
10677 stub_entry
->group
->stub_sec
->reloc_count
10678 += 1 + (PPC_HA (off
) != 0);
10679 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
10682 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
10683 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10686 if (PPC_HA (off
) != 0)
10692 if (PPC_HA (off
) != 0)
10695 if (PPC_HA (r2off
) != 0)
10697 if (PPC_LO (r2off
) != 0)
10701 else if (info
->emitrelocations
)
10703 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
10704 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
10708 case ppc_stub_plt_branch_notoc
:
10709 case ppc_stub_plt_branch_both
:
10710 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
10711 /* Fall through. */
10712 case ppc_stub_long_branch_notoc
:
10713 case ppc_stub_long_branch_both
:
10714 off
= (stub_entry
->stub_offset
10715 + stub_entry
->group
->stub_sec
->output_offset
10716 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10718 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
10721 targ
= (stub_entry
->target_value
10722 + stub_entry
->target_section
->output_offset
10723 + stub_entry
->target_section
->output_section
->vma
);
10726 extra
= size_offset (off
- 8);
10727 /* Include branch insn plus those in the offset sequence. */
10729 /* The branch insn is at the end, or "extra" bytes along. So
10730 its offset will be "extra" bytes less that that already
10734 /* After the bcl, lr has been modified so we need to emit
10735 .eh_frame info saying the return address is in r12. */
10736 lr_used
= stub_entry
->stub_offset
+ 8;
10737 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
10739 /* The eh_frame info will consist of a DW_CFA_advance_loc or
10740 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
10741 DW_CFA_restore_extended 65. */
10742 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10743 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
10744 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10746 /* If the branch can't reach, use a plt_branch. */
10747 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10749 stub_entry
->stub_type
+= (ppc_stub_plt_branch_notoc
10750 - ppc_stub_long_branch_notoc
);
10755 case ppc_stub_plt_call_notoc
:
10756 case ppc_stub_plt_call_both
:
10757 off
= (stub_entry
->stub_offset
10758 + stub_entry
->group
->stub_sec
->output_offset
10759 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10760 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10762 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10763 if (targ
>= (bfd_vma
) -2)
10766 plt
= htab
->elf
.splt
;
10767 if (!htab
->elf
.dynamic_sections_created
10768 || stub_entry
->h
== NULL
10769 || stub_entry
->h
->elf
.dynindx
== -1)
10771 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10772 plt
= htab
->elf
.iplt
;
10774 plt
= htab
->pltlocal
;
10776 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10779 if (htab
->params
->plt_stub_align
!= 0)
10781 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
10783 stub_entry
->group
->stub_sec
->size
+= pad
;
10784 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10788 size
= plt_stub_size (htab
, stub_entry
, off
);
10790 /* After the bcl, lr has been modified so we need to emit
10791 .eh_frame info saying the return address is in r12. */
10792 lr_used
= stub_entry
->stub_offset
+ 8;
10793 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10795 /* The eh_frame info will consist of a DW_CFA_advance_loc or
10796 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
10797 DW_CFA_restore_extended 65. */
10798 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10799 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
10800 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10803 case ppc_stub_plt_call
:
10804 case ppc_stub_plt_call_r2save
:
10805 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
10806 if (targ
>= (bfd_vma
) -2)
10808 plt
= htab
->elf
.splt
;
10809 if (!htab
->elf
.dynamic_sections_created
10810 || stub_entry
->h
== NULL
10811 || stub_entry
->h
->elf
.dynindx
== -1)
10813 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10814 plt
= htab
->elf
.iplt
;
10816 plt
= htab
->pltlocal
;
10818 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10820 off
= (elf_gp (info
->output_bfd
)
10821 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10824 if (htab
->params
->plt_stub_align
!= 0)
10826 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
10828 stub_entry
->group
->stub_sec
->size
+= pad
;
10829 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10832 if (info
->emitrelocations
)
10834 stub_entry
->group
->stub_sec
->reloc_count
10835 += ((PPC_HA (off
) != 0)
10837 ? 2 + (htab
->params
->plt_static_chain
10838 && PPC_HA (off
+ 16) == PPC_HA (off
))
10840 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
10843 size
= plt_stub_size (htab
, stub_entry
, off
);
10845 if (stub_entry
->h
!= NULL
10846 && (stub_entry
->h
== htab
->tls_get_addr_fd
10847 || stub_entry
->h
== htab
->tls_get_addr
)
10848 && htab
->params
->tls_get_addr_opt
10849 && stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10851 /* After the bctrl, lr has been modified so we need to
10852 emit .eh_frame info saying the return address is
10853 on the stack. In fact we put the EH info specifying
10854 that the return address is on the stack *at* the
10855 call rather than after it, because the EH info for a
10856 call needs to be specified by that point.
10857 See libgcc/unwind-dw2.c execute_cfa_program. */
10858 lr_used
= stub_entry
->stub_offset
+ size
- 20;
10859 /* The eh_frame info will consist of a DW_CFA_advance_loc
10860 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
10861 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
10862 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10863 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
10864 stub_entry
->group
->lr_restore
= size
- 4;
10873 stub_entry
->group
->stub_sec
->size
+= size
;
10877 /* Set up various things so that we can make a list of input sections
10878 for each output section included in the link. Returns -1 on error,
10879 0 when no stubs will be needed, and 1 on success. */
10882 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
10886 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10891 htab
->sec_info_arr_size
= _bfd_section_id
;
10892 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
10893 htab
->sec_info
= bfd_zmalloc (amt
);
10894 if (htab
->sec_info
== NULL
)
10897 /* Set toc_off for com, und, abs and ind sections. */
10898 for (id
= 0; id
< 3; id
++)
10899 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
10904 /* Set up for first pass at multitoc partitioning. */
10907 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
10909 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10911 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
10912 htab
->toc_bfd
= NULL
;
10913 htab
->toc_first_sec
= NULL
;
10916 /* The linker repeatedly calls this function for each TOC input section
10917 and linker generated GOT section. Group input bfds such that the toc
10918 within a group is less than 64k in size. */
10921 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
10923 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10924 bfd_vma addr
, off
, limit
;
10929 if (!htab
->second_toc_pass
)
10931 /* Keep track of the first .toc or .got section for this input bfd. */
10932 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
10936 htab
->toc_bfd
= isec
->owner
;
10937 htab
->toc_first_sec
= isec
;
10940 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
10941 off
= addr
- htab
->toc_curr
;
10942 limit
= 0x80008000;
10943 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
10945 if (off
+ isec
->size
> limit
)
10947 addr
= (htab
->toc_first_sec
->output_offset
10948 + htab
->toc_first_sec
->output_section
->vma
);
10949 htab
->toc_curr
= addr
;
10950 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
10953 /* toc_curr is the base address of this toc group. Set elf_gp
10954 for the input section to be the offset relative to the
10955 output toc base plus 0x8000. Making the input elf_gp an
10956 offset allows us to move the toc as a whole without
10957 recalculating input elf_gp. */
10958 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
10959 off
+= TOC_BASE_OFF
;
10961 /* Die if someone uses a linker script that doesn't keep input
10962 file .toc and .got together. */
10964 && elf_gp (isec
->owner
) != 0
10965 && elf_gp (isec
->owner
) != off
)
10968 elf_gp (isec
->owner
) = off
;
10972 /* During the second pass toc_first_sec points to the start of
10973 a toc group, and toc_curr is used to track the old elf_gp.
10974 We use toc_bfd to ensure we only look at each bfd once. */
10975 if (htab
->toc_bfd
== isec
->owner
)
10977 htab
->toc_bfd
= isec
->owner
;
10979 if (htab
->toc_first_sec
== NULL
10980 || htab
->toc_curr
!= elf_gp (isec
->owner
))
10982 htab
->toc_curr
= elf_gp (isec
->owner
);
10983 htab
->toc_first_sec
= isec
;
10985 addr
= (htab
->toc_first_sec
->output_offset
10986 + htab
->toc_first_sec
->output_section
->vma
);
10987 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
10988 elf_gp (isec
->owner
) = off
;
10993 /* Called via elf_link_hash_traverse to merge GOT entries for global
10997 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
10999 if (h
->root
.type
== bfd_link_hash_indirect
)
11002 merge_got_entries (&h
->got
.glist
);
11007 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11011 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11013 struct got_entry
*gent
;
11015 if (h
->root
.type
== bfd_link_hash_indirect
)
11018 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11019 if (!gent
->is_indirect
)
11020 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11024 /* Called on the first multitoc pass after the last call to
11025 ppc64_elf_next_toc_section. This function removes duplicate GOT
11029 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11031 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11032 struct bfd
*ibfd
, *ibfd2
;
11033 bfd_boolean done_something
;
11035 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11037 if (!htab
->do_multi_toc
)
11040 /* Merge global sym got entries within a toc group. */
11041 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11043 /* And tlsld_got. */
11044 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11046 struct got_entry
*ent
, *ent2
;
11048 if (!is_ppc64_elf (ibfd
))
11051 ent
= ppc64_tlsld_got (ibfd
);
11052 if (!ent
->is_indirect
11053 && ent
->got
.offset
!= (bfd_vma
) -1)
11055 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11057 if (!is_ppc64_elf (ibfd2
))
11060 ent2
= ppc64_tlsld_got (ibfd2
);
11061 if (!ent2
->is_indirect
11062 && ent2
->got
.offset
!= (bfd_vma
) -1
11063 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11065 ent2
->is_indirect
= TRUE
;
11066 ent2
->got
.ent
= ent
;
11072 /* Zap sizes of got sections. */
11073 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11074 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11075 htab
->got_reli_size
= 0;
11077 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11079 asection
*got
, *relgot
;
11081 if (!is_ppc64_elf (ibfd
))
11084 got
= ppc64_elf_tdata (ibfd
)->got
;
11087 got
->rawsize
= got
->size
;
11089 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11090 relgot
->rawsize
= relgot
->size
;
11095 /* Now reallocate the got, local syms first. We don't need to
11096 allocate section contents again since we never increase size. */
11097 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11099 struct got_entry
**lgot_ents
;
11100 struct got_entry
**end_lgot_ents
;
11101 struct plt_entry
**local_plt
;
11102 struct plt_entry
**end_local_plt
;
11103 unsigned char *lgot_masks
;
11104 bfd_size_type locsymcount
;
11105 Elf_Internal_Shdr
*symtab_hdr
;
11108 if (!is_ppc64_elf (ibfd
))
11111 lgot_ents
= elf_local_got_ents (ibfd
);
11115 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11116 locsymcount
= symtab_hdr
->sh_info
;
11117 end_lgot_ents
= lgot_ents
+ locsymcount
;
11118 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11119 end_local_plt
= local_plt
+ locsymcount
;
11120 lgot_masks
= (unsigned char *) end_local_plt
;
11121 s
= ppc64_elf_tdata (ibfd
)->got
;
11122 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11124 struct got_entry
*ent
;
11126 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11128 unsigned int ent_size
= 8;
11129 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11131 ent
->got
.offset
= s
->size
;
11132 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11137 s
->size
+= ent_size
;
11138 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
11140 htab
->elf
.irelplt
->size
+= rel_size
;
11141 htab
->got_reli_size
+= rel_size
;
11143 else if (bfd_link_pic (info
)
11144 && !((ent
->tls_type
& TLS_TPREL
) != 0
11145 && bfd_link_executable (info
)))
11147 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11148 srel
->size
+= rel_size
;
11154 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11156 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11158 struct got_entry
*ent
;
11160 if (!is_ppc64_elf (ibfd
))
11163 ent
= ppc64_tlsld_got (ibfd
);
11164 if (!ent
->is_indirect
11165 && ent
->got
.offset
!= (bfd_vma
) -1)
11167 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11168 ent
->got
.offset
= s
->size
;
11170 if (bfd_link_pic (info
))
11172 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11173 srel
->size
+= sizeof (Elf64_External_Rela
);
11178 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11179 if (!done_something
)
11180 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11184 if (!is_ppc64_elf (ibfd
))
11187 got
= ppc64_elf_tdata (ibfd
)->got
;
11190 done_something
= got
->rawsize
!= got
->size
;
11191 if (done_something
)
11196 if (done_something
)
11197 (*htab
->params
->layout_sections_again
) ();
11199 /* Set up for second pass over toc sections to recalculate elf_gp
11200 on input sections. */
11201 htab
->toc_bfd
= NULL
;
11202 htab
->toc_first_sec
= NULL
;
11203 htab
->second_toc_pass
= TRUE
;
11204 return done_something
;
11207 /* Called after second pass of multitoc partitioning. */
11210 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11212 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11214 /* After the second pass, toc_curr tracks the TOC offset used
11215 for code sections below in ppc64_elf_next_input_section. */
11216 htab
->toc_curr
= TOC_BASE_OFF
;
11219 /* No toc references were found in ISEC. If the code in ISEC makes no
11220 calls, then there's no need to use toc adjusting stubs when branching
11221 into ISEC. Actually, indirect calls from ISEC are OK as they will
11222 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11223 needed, and 2 if a cyclical call-graph was found but no other reason
11224 for a stub was detected. If called from the top level, a return of
11225 2 means the same as a return of 0. */
11228 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11232 /* Mark this section as checked. */
11233 isec
->call_check_done
= 1;
11235 /* We know none of our code bearing sections will need toc stubs. */
11236 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11239 if (isec
->size
== 0)
11242 if (isec
->output_section
== NULL
)
11246 if (isec
->reloc_count
!= 0)
11248 Elf_Internal_Rela
*relstart
, *rel
;
11249 Elf_Internal_Sym
*local_syms
;
11250 struct ppc_link_hash_table
*htab
;
11252 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11253 info
->keep_memory
);
11254 if (relstart
== NULL
)
11257 /* Look for branches to outside of this section. */
11259 htab
= ppc_hash_table (info
);
11263 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11265 enum elf_ppc64_reloc_type r_type
;
11266 unsigned long r_symndx
;
11267 struct elf_link_hash_entry
*h
;
11268 struct ppc_link_hash_entry
*eh
;
11269 Elf_Internal_Sym
*sym
;
11271 struct _opd_sec_data
*opd
;
11275 r_type
= ELF64_R_TYPE (rel
->r_info
);
11276 if (r_type
!= R_PPC64_REL24
11277 && r_type
!= R_PPC64_REL24_NOTOC
11278 && r_type
!= R_PPC64_REL14
11279 && r_type
!= R_PPC64_REL14_BRTAKEN
11280 && r_type
!= R_PPC64_REL14_BRNTAKEN
11281 && r_type
!= R_PPC64_PLTCALL
)
11284 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11285 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11292 /* Calls to dynamic lib functions go through a plt call stub
11294 eh
= (struct ppc_link_hash_entry
*) h
;
11296 && (eh
->elf
.plt
.plist
!= NULL
11298 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
11304 if (sym_sec
== NULL
)
11305 /* Ignore other undefined symbols. */
11308 /* Assume branches to other sections not included in the
11309 link need stubs too, to cover -R and absolute syms. */
11310 if (sym_sec
->output_section
== NULL
)
11317 sym_value
= sym
->st_value
;
11320 if (h
->root
.type
!= bfd_link_hash_defined
11321 && h
->root
.type
!= bfd_link_hash_defweak
)
11323 sym_value
= h
->root
.u
.def
.value
;
11325 sym_value
+= rel
->r_addend
;
11327 /* If this branch reloc uses an opd sym, find the code section. */
11328 opd
= get_opd_info (sym_sec
);
11331 if (h
== NULL
&& opd
->adjust
!= NULL
)
11335 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11337 /* Assume deleted functions won't ever be called. */
11339 sym_value
+= adjust
;
11342 dest
= opd_entry_value (sym_sec
, sym_value
,
11343 &sym_sec
, NULL
, FALSE
);
11344 if (dest
== (bfd_vma
) -1)
11349 + sym_sec
->output_offset
11350 + sym_sec
->output_section
->vma
);
11352 /* Ignore branch to self. */
11353 if (sym_sec
== isec
)
11356 /* If the called function uses the toc, we need a stub. */
11357 if (sym_sec
->has_toc_reloc
11358 || sym_sec
->makes_toc_func_call
)
11364 /* Assume any branch that needs a long branch stub might in fact
11365 need a plt_branch stub. A plt_branch stub uses r2. */
11366 else if (dest
- (isec
->output_offset
11367 + isec
->output_section
->vma
11368 + rel
->r_offset
) + (1 << 25)
11369 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11377 /* If calling back to a section in the process of being
11378 tested, we can't say for sure that no toc adjusting stubs
11379 are needed, so don't return zero. */
11380 else if (sym_sec
->call_check_in_progress
)
11383 /* Branches to another section that itself doesn't have any TOC
11384 references are OK. Recursively call ourselves to check. */
11385 else if (!sym_sec
->call_check_done
)
11389 /* Mark current section as indeterminate, so that other
11390 sections that call back to current won't be marked as
11392 isec
->call_check_in_progress
= 1;
11393 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
11394 isec
->call_check_in_progress
= 0;
11405 if (local_syms
!= NULL
11406 && (elf_symtab_hdr (isec
->owner
).contents
11407 != (unsigned char *) local_syms
))
11409 if (elf_section_data (isec
)->relocs
!= relstart
)
11414 && isec
->map_head
.s
!= NULL
11415 && (strcmp (isec
->output_section
->name
, ".init") == 0
11416 || strcmp (isec
->output_section
->name
, ".fini") == 0))
11418 if (isec
->map_head
.s
->has_toc_reloc
11419 || isec
->map_head
.s
->makes_toc_func_call
)
11421 else if (!isec
->map_head
.s
->call_check_done
)
11424 isec
->call_check_in_progress
= 1;
11425 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
11426 isec
->call_check_in_progress
= 0;
11433 isec
->makes_toc_func_call
= 1;
11438 /* The linker repeatedly calls this function for each input section,
11439 in the order that input sections are linked into output sections.
11440 Build lists of input sections to determine groupings between which
11441 we may insert linker stubs. */
11444 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
11446 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11451 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
11452 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
11454 /* This happens to make the list in reverse order,
11455 which is what we want. */
11456 htab
->sec_info
[isec
->id
].u
.list
11457 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
11458 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
11461 if (htab
->multi_toc_needed
)
11463 /* Analyse sections that aren't already flagged as needing a
11464 valid toc pointer. Exclude .fixup for the linux kernel.
11465 .fixup contains branches, but only back to the function that
11466 hit an exception. */
11467 if (!(isec
->has_toc_reloc
11468 || (isec
->flags
& SEC_CODE
) == 0
11469 || strcmp (isec
->name
, ".fixup") == 0
11470 || isec
->call_check_done
))
11472 if (toc_adjusting_stub_needed (info
, isec
) < 0)
11475 /* Make all sections use the TOC assigned for this object file.
11476 This will be wrong for pasted sections; We fix that in
11477 check_pasted_section(). */
11478 if (elf_gp (isec
->owner
) != 0)
11479 htab
->toc_curr
= elf_gp (isec
->owner
);
11482 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
11486 /* Check that all .init and .fini sections use the same toc, if they
11487 have toc relocs. */
11490 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
11492 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
11496 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11497 bfd_vma toc_off
= 0;
11500 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11501 if (i
->has_toc_reloc
)
11504 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11505 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
11510 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11511 if (i
->makes_toc_func_call
)
11513 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11517 /* Make sure the whole pasted function uses the same toc offset. */
11519 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11520 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
11526 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
11528 return (check_pasted_section (info
, ".init")
11529 & check_pasted_section (info
, ".fini"));
11532 /* See whether we can group stub sections together. Grouping stub
11533 sections may result in fewer stubs. More importantly, we need to
11534 put all .init* and .fini* stubs at the beginning of the .init or
11535 .fini output sections respectively, because glibc splits the
11536 _init and _fini functions into multiple parts. Putting a stub in
11537 the middle of a function is not a good idea. */
11540 group_sections (struct bfd_link_info
*info
,
11541 bfd_size_type stub_group_size
,
11542 bfd_boolean stubs_always_before_branch
)
11544 struct ppc_link_hash_table
*htab
;
11546 bfd_boolean suppress_size_errors
;
11548 htab
= ppc_hash_table (info
);
11552 suppress_size_errors
= FALSE
;
11553 if (stub_group_size
== 1)
11555 /* Default values. */
11556 if (stubs_always_before_branch
)
11557 stub_group_size
= 0x1e00000;
11559 stub_group_size
= 0x1c00000;
11560 suppress_size_errors
= TRUE
;
11563 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
11567 if (osec
->id
>= htab
->sec_info_arr_size
)
11570 tail
= htab
->sec_info
[osec
->id
].u
.list
;
11571 while (tail
!= NULL
)
11575 bfd_size_type total
;
11576 bfd_boolean big_sec
;
11578 struct map_stub
*group
;
11579 bfd_size_type group_size
;
11582 total
= tail
->size
;
11583 group_size
= (ppc64_elf_section_data (tail
) != NULL
11584 && ppc64_elf_section_data (tail
)->has_14bit_branch
11585 ? stub_group_size
>> 10 : stub_group_size
);
11587 big_sec
= total
> group_size
;
11588 if (big_sec
&& !suppress_size_errors
)
11589 /* xgettext:c-format */
11590 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
11591 tail
->owner
, tail
);
11592 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
11594 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
11595 && ((total
+= curr
->output_offset
- prev
->output_offset
)
11596 < (ppc64_elf_section_data (prev
) != NULL
11597 && ppc64_elf_section_data (prev
)->has_14bit_branch
11598 ? (group_size
= stub_group_size
>> 10) : group_size
))
11599 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
11602 /* OK, the size from the start of CURR to the end is less
11603 than group_size and thus can be handled by one stub
11604 section. (or the tail section is itself larger than
11605 group_size, in which case we may be toast.) We should
11606 really be keeping track of the total size of stubs added
11607 here, as stubs contribute to the final output section
11608 size. That's a little tricky, and this way will only
11609 break if stubs added make the total size more than 2^25,
11610 ie. for the default stub_group_size, if stubs total more
11611 than 2097152 bytes, or nearly 75000 plt call stubs. */
11612 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
11615 group
->link_sec
= curr
;
11616 group
->stub_sec
= NULL
;
11617 group
->needs_save_res
= 0;
11618 group
->lr_restore
= 0;
11619 group
->eh_size
= 0;
11620 group
->eh_base
= 0;
11621 group
->next
= htab
->group
;
11622 htab
->group
= group
;
11625 prev
= htab
->sec_info
[tail
->id
].u
.list
;
11626 /* Set up this stub group. */
11627 htab
->sec_info
[tail
->id
].u
.group
= group
;
11629 while (tail
!= curr
&& (tail
= prev
) != NULL
);
11631 /* But wait, there's more! Input sections up to group_size
11632 bytes before the stub section can be handled by it too.
11633 Don't do this if we have a really large section after the
11634 stubs, as adding more stubs increases the chance that
11635 branches may not reach into the stub section. */
11636 if (!stubs_always_before_branch
&& !big_sec
)
11639 while (prev
!= NULL
11640 && ((total
+= tail
->output_offset
- prev
->output_offset
)
11641 < (ppc64_elf_section_data (prev
) != NULL
11642 && ppc64_elf_section_data (prev
)->has_14bit_branch
11643 ? (group_size
= stub_group_size
>> 10)
11645 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
11648 prev
= htab
->sec_info
[tail
->id
].u
.list
;
11649 htab
->sec_info
[tail
->id
].u
.group
= group
;
11658 static const unsigned char glink_eh_frame_cie
[] =
11660 0, 0, 0, 16, /* length. */
11661 0, 0, 0, 0, /* id. */
11662 1, /* CIE version. */
11663 'z', 'R', 0, /* Augmentation string. */
11664 4, /* Code alignment. */
11665 0x78, /* Data alignment. */
11667 1, /* Augmentation size. */
11668 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
11669 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
11672 /* Stripping output sections is normally done before dynamic section
11673 symbols have been allocated. This function is called later, and
11674 handles cases like htab->brlt which is mapped to its own output
11678 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
11680 if (isec
->size
== 0
11681 && isec
->output_section
->size
== 0
11682 && !(isec
->output_section
->flags
& SEC_KEEP
)
11683 && !bfd_section_removed_from_list (info
->output_bfd
,
11684 isec
->output_section
)
11685 && elf_section_data (isec
->output_section
)->dynindx
== 0)
11687 isec
->output_section
->flags
|= SEC_EXCLUDE
;
11688 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
11689 info
->output_bfd
->section_count
--;
11693 /* Determine and set the size of the stub section for a final link.
11695 The basic idea here is to examine all the relocations looking for
11696 PC-relative calls to a target that is unreachable with a "bl"
11700 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
11702 bfd_size_type stub_group_size
;
11703 bfd_boolean stubs_always_before_branch
;
11704 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11709 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
11710 htab
->params
->plt_thread_safe
= 1;
11711 if (!htab
->opd_abi
)
11712 htab
->params
->plt_thread_safe
= 0;
11713 else if (htab
->params
->plt_thread_safe
== -1)
11715 static const char *const thread_starter
[] =
11719 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
11721 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
11722 "mq_notify", "create_timer",
11727 "GOMP_parallel_start",
11728 "GOMP_parallel_loop_static",
11729 "GOMP_parallel_loop_static_start",
11730 "GOMP_parallel_loop_dynamic",
11731 "GOMP_parallel_loop_dynamic_start",
11732 "GOMP_parallel_loop_guided",
11733 "GOMP_parallel_loop_guided_start",
11734 "GOMP_parallel_loop_runtime",
11735 "GOMP_parallel_loop_runtime_start",
11736 "GOMP_parallel_sections",
11737 "GOMP_parallel_sections_start",
11743 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
11745 struct elf_link_hash_entry
*h
;
11746 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
11747 FALSE
, FALSE
, TRUE
);
11748 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
11749 if (htab
->params
->plt_thread_safe
)
11753 stubs_always_before_branch
= htab
->params
->group_size
< 0;
11754 if (htab
->params
->group_size
< 0)
11755 stub_group_size
= -htab
->params
->group_size
;
11757 stub_group_size
= htab
->params
->group_size
;
11759 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
11762 #define STUB_SHRINK_ITER 20
11763 /* Loop until no stubs added. After iteration 20 of this loop we may
11764 exit on a stub section shrinking. This is to break out of a
11765 pathological case where adding stubs on one iteration decreases
11766 section gaps (perhaps due to alignment), which then requires
11767 fewer or smaller stubs on the next iteration. */
11772 unsigned int bfd_indx
;
11773 struct map_stub
*group
;
11775 htab
->stub_iteration
+= 1;
11777 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
11779 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
11781 Elf_Internal_Shdr
*symtab_hdr
;
11783 Elf_Internal_Sym
*local_syms
= NULL
;
11785 if (!is_ppc64_elf (input_bfd
))
11788 /* We'll need the symbol table in a second. */
11789 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
11790 if (symtab_hdr
->sh_info
== 0)
11793 /* Walk over each section attached to the input bfd. */
11794 for (section
= input_bfd
->sections
;
11796 section
= section
->next
)
11798 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
11800 /* If there aren't any relocs, then there's nothing more
11802 if ((section
->flags
& SEC_RELOC
) == 0
11803 || (section
->flags
& SEC_ALLOC
) == 0
11804 || (section
->flags
& SEC_LOAD
) == 0
11805 || (section
->flags
& SEC_CODE
) == 0
11806 || section
->reloc_count
== 0)
11809 /* If this section is a link-once section that will be
11810 discarded, then don't create any stubs. */
11811 if (section
->output_section
== NULL
11812 || section
->output_section
->owner
!= info
->output_bfd
)
11815 /* Get the relocs. */
11817 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
11818 info
->keep_memory
);
11819 if (internal_relocs
== NULL
)
11820 goto error_ret_free_local
;
11822 /* Now examine each relocation. */
11823 irela
= internal_relocs
;
11824 irelaend
= irela
+ section
->reloc_count
;
11825 for (; irela
< irelaend
; irela
++)
11827 enum elf_ppc64_reloc_type r_type
;
11828 unsigned int r_indx
;
11829 enum ppc_stub_type stub_type
;
11830 struct ppc_stub_hash_entry
*stub_entry
;
11831 asection
*sym_sec
, *code_sec
;
11832 bfd_vma sym_value
, code_value
;
11833 bfd_vma destination
;
11834 unsigned long local_off
;
11835 bfd_boolean ok_dest
;
11836 struct ppc_link_hash_entry
*hash
;
11837 struct ppc_link_hash_entry
*fdh
;
11838 struct elf_link_hash_entry
*h
;
11839 Elf_Internal_Sym
*sym
;
11841 const asection
*id_sec
;
11842 struct _opd_sec_data
*opd
;
11843 struct plt_entry
*plt_ent
;
11845 r_type
= ELF64_R_TYPE (irela
->r_info
);
11846 r_indx
= ELF64_R_SYM (irela
->r_info
);
11848 if (r_type
>= R_PPC64_max
)
11850 bfd_set_error (bfd_error_bad_value
);
11851 goto error_ret_free_internal
;
11854 /* Only look for stubs on branch instructions. */
11855 if (r_type
!= R_PPC64_REL24
11856 && r_type
!= R_PPC64_REL24_NOTOC
11857 && r_type
!= R_PPC64_REL14
11858 && r_type
!= R_PPC64_REL14_BRTAKEN
11859 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11862 /* Now determine the call target, its name, value,
11864 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
11865 r_indx
, input_bfd
))
11866 goto error_ret_free_internal
;
11867 hash
= (struct ppc_link_hash_entry
*) h
;
11874 sym_value
= sym
->st_value
;
11875 if (sym_sec
!= NULL
11876 && sym_sec
->output_section
!= NULL
)
11879 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
11880 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
11882 sym_value
= hash
->elf
.root
.u
.def
.value
;
11883 if (sym_sec
->output_section
!= NULL
)
11886 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
11887 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
11889 /* Recognise an old ABI func code entry sym, and
11890 use the func descriptor sym instead if it is
11892 if (hash
->elf
.root
.root
.string
[0] == '.'
11893 && hash
->oh
!= NULL
)
11895 fdh
= ppc_follow_link (hash
->oh
);
11896 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
11897 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
11899 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
11900 sym_value
= fdh
->elf
.root
.u
.def
.value
;
11901 if (sym_sec
->output_section
!= NULL
)
11910 bfd_set_error (bfd_error_bad_value
);
11911 goto error_ret_free_internal
;
11918 sym_value
+= irela
->r_addend
;
11919 destination
= (sym_value
11920 + sym_sec
->output_offset
11921 + sym_sec
->output_section
->vma
);
11922 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
11927 code_sec
= sym_sec
;
11928 code_value
= sym_value
;
11929 opd
= get_opd_info (sym_sec
);
11934 if (hash
== NULL
&& opd
->adjust
!= NULL
)
11936 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11939 code_value
+= adjust
;
11940 sym_value
+= adjust
;
11942 dest
= opd_entry_value (sym_sec
, sym_value
,
11943 &code_sec
, &code_value
, FALSE
);
11944 if (dest
!= (bfd_vma
) -1)
11946 destination
= dest
;
11949 /* Fixup old ABI sym to point at code
11951 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
11952 hash
->elf
.root
.u
.def
.section
= code_sec
;
11953 hash
->elf
.root
.u
.def
.value
= code_value
;
11958 /* Determine what (if any) linker stub is needed. */
11960 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
11961 &plt_ent
, destination
,
11964 if (r_type
== R_PPC64_REL24_NOTOC
)
11966 if (stub_type
== ppc_stub_plt_call
)
11967 stub_type
= ppc_stub_plt_call_notoc
;
11968 else if (stub_type
== ppc_stub_long_branch
11969 || (code_sec
!= NULL
11970 && code_sec
->output_section
!= NULL
11971 && (((hash
? hash
->elf
.other
: sym
->st_other
)
11972 & STO_PPC64_LOCAL_MASK
)
11973 != 1 << STO_PPC64_LOCAL_BIT
)))
11974 stub_type
= ppc_stub_long_branch_notoc
;
11976 else if (stub_type
!= ppc_stub_plt_call
)
11978 /* Check whether we need a TOC adjusting stub.
11979 Since the linker pastes together pieces from
11980 different object files when creating the
11981 _init and _fini functions, it may be that a
11982 call to what looks like a local sym is in
11983 fact a call needing a TOC adjustment. */
11984 if ((code_sec
!= NULL
11985 && code_sec
->output_section
!= NULL
11986 && (htab
->sec_info
[code_sec
->id
].toc_off
11987 != htab
->sec_info
[section
->id
].toc_off
)
11988 && (code_sec
->has_toc_reloc
11989 || code_sec
->makes_toc_func_call
))
11990 || (((hash
? hash
->elf
.other
: sym
->st_other
)
11991 & STO_PPC64_LOCAL_MASK
)
11992 == 1 << STO_PPC64_LOCAL_BIT
))
11993 stub_type
= ppc_stub_long_branch_r2off
;
11996 if (stub_type
== ppc_stub_none
)
11999 /* __tls_get_addr calls might be eliminated. */
12000 if (stub_type
!= ppc_stub_plt_call
12001 && stub_type
!= ppc_stub_plt_call_notoc
12003 && (hash
== htab
->tls_get_addr
12004 || hash
== htab
->tls_get_addr_fd
)
12005 && section
->has_tls_reloc
12006 && irela
!= internal_relocs
)
12008 /* Get tls info. */
12009 unsigned char *tls_mask
;
12011 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12012 irela
- 1, input_bfd
))
12013 goto error_ret_free_internal
;
12014 if ((*tls_mask
& TLS_TLS
) != 0)
12018 if (stub_type
== ppc_stub_plt_call
)
12021 && htab
->params
->plt_localentry0
!= 0
12022 && is_elfv2_localentry0 (&hash
->elf
))
12023 htab
->has_plt_localentry0
= 1;
12024 else if (irela
+ 1 < irelaend
12025 && irela
[1].r_offset
== irela
->r_offset
+ 4
12026 && (ELF64_R_TYPE (irela
[1].r_info
)
12027 == R_PPC64_TOCSAVE
))
12029 if (!tocsave_find (htab
, INSERT
,
12030 &local_syms
, irela
+ 1, input_bfd
))
12031 goto error_ret_free_internal
;
12034 stub_type
= ppc_stub_plt_call_r2save
;
12037 /* Support for grouping stub sections. */
12038 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12040 /* Get the name of this stub. */
12041 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12043 goto error_ret_free_internal
;
12045 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12046 stub_name
, FALSE
, FALSE
);
12047 if (stub_entry
!= NULL
)
12049 enum ppc_stub_type old_type
;
12050 /* A stub has already been created, but it may
12051 not be the required type. We shouldn't be
12052 transitioning from plt_call to long_branch
12053 stubs or vice versa, but we might be
12054 upgrading from plt_call to plt_call_r2save or
12055 from long_branch to long_branch_r2off. */
12057 old_type
= stub_entry
->stub_type
;
12063 case ppc_stub_save_res
:
12066 case ppc_stub_plt_call
:
12067 case ppc_stub_plt_call_r2save
:
12068 case ppc_stub_plt_call_notoc
:
12069 case ppc_stub_plt_call_both
:
12070 if (stub_type
== ppc_stub_plt_call
)
12072 else if (stub_type
== ppc_stub_plt_call_r2save
)
12074 if (old_type
== ppc_stub_plt_call_notoc
)
12075 stub_type
= ppc_stub_plt_call_both
;
12077 else if (stub_type
== ppc_stub_plt_call_notoc
)
12079 if (old_type
== ppc_stub_plt_call_r2save
)
12080 stub_type
= ppc_stub_plt_call_both
;
12086 case ppc_stub_plt_branch
:
12087 case ppc_stub_plt_branch_r2off
:
12088 case ppc_stub_plt_branch_notoc
:
12089 case ppc_stub_plt_branch_both
:
12090 old_type
+= (ppc_stub_long_branch
12091 - ppc_stub_plt_branch
);
12092 /* Fall through. */
12093 case ppc_stub_long_branch
:
12094 case ppc_stub_long_branch_r2off
:
12095 case ppc_stub_long_branch_notoc
:
12096 case ppc_stub_long_branch_both
:
12097 if (stub_type
== ppc_stub_long_branch
)
12099 else if (stub_type
== ppc_stub_long_branch_r2off
)
12101 if (old_type
== ppc_stub_long_branch_notoc
)
12102 stub_type
= ppc_stub_long_branch_both
;
12104 else if (stub_type
== ppc_stub_long_branch_notoc
)
12106 if (old_type
== ppc_stub_long_branch_r2off
)
12107 stub_type
= ppc_stub_long_branch_both
;
12113 if (old_type
< stub_type
)
12114 stub_entry
->stub_type
= stub_type
;
12118 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12119 if (stub_entry
== NULL
)
12122 error_ret_free_internal
:
12123 if (elf_section_data (section
)->relocs
== NULL
)
12124 free (internal_relocs
);
12125 error_ret_free_local
:
12126 if (local_syms
!= NULL
12127 && (symtab_hdr
->contents
12128 != (unsigned char *) local_syms
))
12133 stub_entry
->stub_type
= stub_type
;
12134 if (stub_type
>= ppc_stub_plt_call
12135 && stub_type
<= ppc_stub_plt_call_both
)
12137 stub_entry
->target_value
= sym_value
;
12138 stub_entry
->target_section
= sym_sec
;
12142 stub_entry
->target_value
= code_value
;
12143 stub_entry
->target_section
= code_sec
;
12145 stub_entry
->h
= hash
;
12146 stub_entry
->plt_ent
= plt_ent
;
12147 stub_entry
->symtype
12148 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
12149 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12151 if (stub_entry
->h
!= NULL
)
12152 htab
->stub_globals
+= 1;
12155 /* We're done with the internal relocs, free them. */
12156 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12157 free (internal_relocs
);
12160 if (local_syms
!= NULL
12161 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12163 if (!info
->keep_memory
)
12166 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12170 /* We may have added some stubs. Find out the new size of the
12172 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12174 group
->lr_restore
= 0;
12175 group
->eh_size
= 0;
12176 if (group
->stub_sec
!= NULL
)
12178 asection
*stub_sec
= group
->stub_sec
;
12180 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12181 || stub_sec
->rawsize
< stub_sec
->size
)
12182 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12183 stub_sec
->rawsize
= stub_sec
->size
;
12184 stub_sec
->size
= 0;
12185 stub_sec
->reloc_count
= 0;
12186 stub_sec
->flags
&= ~SEC_RELOC
;
12190 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12191 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
12192 htab
->brlt
->rawsize
= htab
->brlt
->size
;
12193 htab
->brlt
->size
= 0;
12194 htab
->brlt
->reloc_count
= 0;
12195 htab
->brlt
->flags
&= ~SEC_RELOC
;
12196 if (htab
->relbrlt
!= NULL
)
12197 htab
->relbrlt
->size
= 0;
12199 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12201 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12202 if (group
->needs_save_res
)
12203 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12205 if (info
->emitrelocations
12206 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12208 htab
->glink
->reloc_count
= 1;
12209 htab
->glink
->flags
|= SEC_RELOC
;
12212 if (htab
->glink_eh_frame
!= NULL
12213 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12214 && htab
->glink_eh_frame
->output_section
->size
> 8)
12216 size_t size
= 0, align
= 4;
12218 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12219 if (group
->eh_size
!= 0)
12220 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
12221 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12222 size
+= (24 + align
- 1) & -align
;
12224 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
12225 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12226 size
= (size
+ align
- 1) & -align
;
12227 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12228 htab
->glink_eh_frame
->size
= size
;
12231 if (htab
->params
->plt_stub_align
!= 0)
12232 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12233 if (group
->stub_sec
!= NULL
)
12235 int align
= abs (htab
->params
->plt_stub_align
);
12236 group
->stub_sec
->size
12237 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12240 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12241 if (group
->stub_sec
!= NULL
12242 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
12243 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
12244 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
12248 && (htab
->brlt
->rawsize
== htab
->brlt
->size
12249 || (htab
->stub_iteration
> STUB_SHRINK_ITER
12250 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
12251 && (htab
->glink_eh_frame
== NULL
12252 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12255 /* Ask the linker to do its stuff. */
12256 (*htab
->params
->layout_sections_again
) ();
12259 if (htab
->glink_eh_frame
!= NULL
12260 && htab
->glink_eh_frame
->size
!= 0)
12263 bfd_byte
*p
, *last_fde
;
12264 size_t last_fde_len
, size
, align
, pad
;
12265 struct map_stub
*group
;
12267 /* It is necessary to at least have a rough outline of the
12268 linker generated CIEs and FDEs written before
12269 bfd_elf_discard_info is run, in order for these FDEs to be
12270 indexed in .eh_frame_hdr. */
12271 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12274 htab
->glink_eh_frame
->contents
= p
;
12278 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12279 /* CIE length (rewrite in case little-endian). */
12280 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
12281 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12282 p
+= last_fde_len
+ 4;
12284 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12285 if (group
->eh_size
!= 0)
12287 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
12289 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
12291 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12294 val
= p
- htab
->glink_eh_frame
->contents
;
12295 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12297 /* Offset to stub section, written later. */
12299 /* stub section size. */
12300 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
12302 /* Augmentation. */
12304 /* Make sure we don't have all nops. This is enough for
12305 elf-eh-frame.c to detect the last non-nop opcode. */
12306 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
12307 p
= last_fde
+ last_fde_len
+ 4;
12309 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12312 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
12314 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12317 val
= p
- htab
->glink_eh_frame
->contents
;
12318 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12320 /* Offset to .glink, written later. */
12323 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12325 /* Augmentation. */
12328 *p
++ = DW_CFA_advance_loc
+ 1;
12329 *p
++ = DW_CFA_register
;
12331 *p
++ = htab
->opd_abi
? 12 : 0;
12332 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
12333 *p
++ = DW_CFA_restore_extended
;
12335 p
+= ((24 + align
- 1) & -align
) - 24;
12337 /* Subsume any padding into the last FDE if user .eh_frame
12338 sections are aligned more than glink_eh_frame. Otherwise any
12339 zero padding will be seen as a terminator. */
12340 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12341 size
= p
- htab
->glink_eh_frame
->contents
;
12342 pad
= ((size
+ align
- 1) & -align
) - size
;
12343 htab
->glink_eh_frame
->size
= size
+ pad
;
12344 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
12347 maybe_strip_output (info
, htab
->brlt
);
12348 if (htab
->glink_eh_frame
!= NULL
)
12349 maybe_strip_output (info
, htab
->glink_eh_frame
);
12354 /* Called after we have determined section placement. If sections
12355 move, we'll be called again. Provide a value for TOCstart. */
12358 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
12361 bfd_vma TOCstart
, adjust
;
12365 struct elf_link_hash_entry
*h
;
12366 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
12368 if (is_elf_hash_table (htab
)
12369 && htab
->hgot
!= NULL
)
12373 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
12374 if (is_elf_hash_table (htab
))
12378 && h
->root
.type
== bfd_link_hash_defined
12379 && !h
->root
.linker_def
12380 && (!is_elf_hash_table (htab
)
12381 || h
->def_regular
))
12383 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
12384 + h
->root
.u
.def
.section
->output_offset
12385 + h
->root
.u
.def
.section
->output_section
->vma
);
12386 _bfd_set_gp_value (obfd
, TOCstart
);
12391 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12392 order. The TOC starts where the first of these sections starts. */
12393 s
= bfd_get_section_by_name (obfd
, ".got");
12394 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12395 s
= bfd_get_section_by_name (obfd
, ".toc");
12396 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12397 s
= bfd_get_section_by_name (obfd
, ".tocbss");
12398 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12399 s
= bfd_get_section_by_name (obfd
, ".plt");
12400 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12402 /* This may happen for
12403 o references to TOC base (SYM@toc / TOC[tc0]) without a
12405 o bad linker script
12406 o --gc-sections and empty TOC sections
12408 FIXME: Warn user? */
12410 /* Look for a likely section. We probably won't even be
12412 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12413 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
12415 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12418 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12419 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
12420 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12423 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12424 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
12428 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12429 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
12435 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
12437 /* Force alignment. */
12438 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
12439 TOCstart
-= adjust
;
12440 _bfd_set_gp_value (obfd
, TOCstart
);
12442 if (info
!= NULL
&& s
!= NULL
)
12444 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12448 if (htab
->elf
.hgot
!= NULL
)
12450 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
12451 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
12456 struct bfd_link_hash_entry
*bh
= NULL
;
12457 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
12458 s
, TOC_BASE_OFF
- adjust
,
12459 NULL
, FALSE
, FALSE
, &bh
);
12465 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
12466 write out any global entry stubs, and PLT relocations. */
12469 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
12471 struct bfd_link_info
*info
;
12472 struct ppc_link_hash_table
*htab
;
12473 struct plt_entry
*ent
;
12476 if (h
->root
.type
== bfd_link_hash_indirect
)
12480 htab
= ppc_hash_table (info
);
12484 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12485 if (ent
->plt
.offset
!= (bfd_vma
) -1)
12487 /* This symbol has an entry in the procedure linkage
12488 table. Set it up. */
12489 Elf_Internal_Rela rela
;
12490 asection
*plt
, *relplt
;
12493 if (!htab
->elf
.dynamic_sections_created
12494 || h
->dynindx
== -1)
12496 if (!(h
->def_regular
12497 && (h
->root
.type
== bfd_link_hash_defined
12498 || h
->root
.type
== bfd_link_hash_defweak
)))
12500 if (h
->type
== STT_GNU_IFUNC
)
12502 plt
= htab
->elf
.iplt
;
12503 relplt
= htab
->elf
.irelplt
;
12504 htab
->local_ifunc_resolver
= 1;
12506 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
12508 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12512 plt
= htab
->pltlocal
;
12513 if (bfd_link_pic (info
))
12515 relplt
= htab
->relpltlocal
;
12517 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
12519 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12524 rela
.r_addend
= (h
->root
.u
.def
.value
12525 + h
->root
.u
.def
.section
->output_offset
12526 + h
->root
.u
.def
.section
->output_section
->vma
12529 if (relplt
== NULL
)
12531 loc
= plt
->contents
+ ent
->plt
.offset
;
12532 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
12535 bfd_vma toc
= elf_gp (info
->output_bfd
);
12536 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
12537 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
12542 rela
.r_offset
= (plt
->output_section
->vma
12543 + plt
->output_offset
12544 + ent
->plt
.offset
);
12545 loc
= relplt
->contents
+ (relplt
->reloc_count
++
12546 * sizeof (Elf64_External_Rela
));
12547 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12552 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
12553 + htab
->elf
.splt
->output_offset
12554 + ent
->plt
.offset
);
12555 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
12556 rela
.r_addend
= ent
->addend
;
12557 loc
= (htab
->elf
.srelplt
->contents
12558 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
12559 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
12560 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
12561 htab
->maybe_local_ifunc_resolver
= 1;
12562 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12566 if (!h
->pointer_equality_needed
)
12569 if (h
->def_regular
)
12572 s
= htab
->global_entry
;
12573 if (s
== NULL
|| s
->size
== 0)
12576 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12577 if (ent
->plt
.offset
!= (bfd_vma
) -1
12578 && ent
->addend
== 0)
12584 p
= s
->contents
+ h
->root
.u
.def
.value
;
12585 plt
= htab
->elf
.splt
;
12586 if (!htab
->elf
.dynamic_sections_created
12587 || h
->dynindx
== -1)
12589 if (h
->type
== STT_GNU_IFUNC
)
12590 plt
= htab
->elf
.iplt
;
12592 plt
= htab
->pltlocal
;
12594 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
12595 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
12597 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
12599 info
->callbacks
->einfo
12600 (_("%P: linkage table error against `%pT'\n"),
12601 h
->root
.root
.string
);
12602 bfd_set_error (bfd_error_bad_value
);
12603 htab
->stub_error
= TRUE
;
12606 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
12607 if (htab
->params
->emit_stub_syms
)
12609 size_t len
= strlen (h
->root
.root
.string
);
12610 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
12615 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
12616 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
12619 if (h
->root
.type
== bfd_link_hash_new
)
12621 h
->root
.type
= bfd_link_hash_defined
;
12622 h
->root
.u
.def
.section
= s
;
12623 h
->root
.u
.def
.value
= p
- s
->contents
;
12624 h
->ref_regular
= 1;
12625 h
->def_regular
= 1;
12626 h
->ref_regular_nonweak
= 1;
12627 h
->forced_local
= 1;
12629 h
->root
.linker_def
= 1;
12633 if (PPC_HA (off
) != 0)
12635 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
12638 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
12640 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
12642 bfd_put_32 (s
->owner
, BCTR
, p
);
12648 /* Write PLT relocs for locals. */
12651 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
12653 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12656 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12658 struct got_entry
**lgot_ents
, **end_lgot_ents
;
12659 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
12660 Elf_Internal_Shdr
*symtab_hdr
;
12661 bfd_size_type locsymcount
;
12662 Elf_Internal_Sym
*local_syms
= NULL
;
12663 struct plt_entry
*ent
;
12665 if (!is_ppc64_elf (ibfd
))
12668 lgot_ents
= elf_local_got_ents (ibfd
);
12672 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12673 locsymcount
= symtab_hdr
->sh_info
;
12674 end_lgot_ents
= lgot_ents
+ locsymcount
;
12675 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12676 end_local_plt
= local_plt
+ locsymcount
;
12677 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
12678 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
12679 if (ent
->plt
.offset
!= (bfd_vma
) -1)
12681 Elf_Internal_Sym
*sym
;
12683 asection
*plt
, *relplt
;
12687 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
12688 lplt
- local_plt
, ibfd
))
12690 if (local_syms
!= NULL
12691 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12696 val
= sym
->st_value
+ ent
->addend
;
12697 val
+= PPC64_LOCAL_ENTRY_OFFSET (sym
->st_other
);
12698 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
12699 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
12701 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
12703 htab
->local_ifunc_resolver
= 1;
12704 plt
= htab
->elf
.iplt
;
12705 relplt
= htab
->elf
.irelplt
;
12709 plt
= htab
->pltlocal
;
12710 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
12713 if (relplt
== NULL
)
12715 loc
= plt
->contents
+ ent
->plt
.offset
;
12716 bfd_put_64 (info
->output_bfd
, val
, loc
);
12719 bfd_vma toc
= elf_gp (ibfd
);
12720 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
12725 Elf_Internal_Rela rela
;
12726 rela
.r_offset
= (ent
->plt
.offset
12727 + plt
->output_offset
12728 + plt
->output_section
->vma
);
12729 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
12732 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
12734 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12739 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
12741 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12743 rela
.r_addend
= val
;
12744 loc
= relplt
->contents
+ (relplt
->reloc_count
++
12745 * sizeof (Elf64_External_Rela
));
12746 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12750 if (local_syms
!= NULL
12751 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12753 if (!info
->keep_memory
)
12756 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12762 /* Build all the stubs associated with the current output file.
12763 The stubs are kept in a hash table attached to the main linker
12764 hash table. This function is called via gldelf64ppc_finish. */
12767 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
12770 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12771 struct map_stub
*group
;
12772 asection
*stub_sec
;
12774 int stub_sec_count
= 0;
12779 /* Allocate memory to hold the linker stubs. */
12780 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12782 group
->eh_size
= 0;
12783 group
->lr_restore
= 0;
12784 if ((stub_sec
= group
->stub_sec
) != NULL
12785 && stub_sec
->size
!= 0)
12787 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
12789 if (stub_sec
->contents
== NULL
)
12791 stub_sec
->size
= 0;
12795 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12800 /* Build the .glink plt call stub. */
12801 if (htab
->params
->emit_stub_syms
)
12803 struct elf_link_hash_entry
*h
;
12804 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
12805 TRUE
, FALSE
, FALSE
);
12808 if (h
->root
.type
== bfd_link_hash_new
)
12810 h
->root
.type
= bfd_link_hash_defined
;
12811 h
->root
.u
.def
.section
= htab
->glink
;
12812 h
->root
.u
.def
.value
= 8;
12813 h
->ref_regular
= 1;
12814 h
->def_regular
= 1;
12815 h
->ref_regular_nonweak
= 1;
12816 h
->forced_local
= 1;
12818 h
->root
.linker_def
= 1;
12821 plt0
= (htab
->elf
.splt
->output_section
->vma
12822 + htab
->elf
.splt
->output_offset
12824 if (info
->emitrelocations
)
12826 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
12829 r
->r_offset
= (htab
->glink
->output_offset
12830 + htab
->glink
->output_section
->vma
);
12831 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
12832 r
->r_addend
= plt0
;
12834 p
= htab
->glink
->contents
;
12835 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
12836 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
12840 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
12842 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
12844 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
12846 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
12848 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
12850 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
12852 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
12854 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
12856 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
12858 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
12863 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
12865 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
12867 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
12869 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
12871 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
12873 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
12875 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
12877 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
12879 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
12881 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
12883 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
12885 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
12887 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
12890 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
12892 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
12894 /* Build the .glink lazy link call stubs. */
12896 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
12902 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
12907 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
12909 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
12914 bfd_put_32 (htab
->glink
->owner
,
12915 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
12921 /* Build .glink global entry stubs, and PLT relocs for globals. */
12922 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
12924 if (!write_plt_relocs_for_local_syms (info
))
12927 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
12929 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
12931 if (htab
->brlt
->contents
== NULL
)
12934 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
12936 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
12937 htab
->relbrlt
->size
);
12938 if (htab
->relbrlt
->contents
== NULL
)
12942 /* Build the stubs as directed by the stub hash table. */
12943 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
12945 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12946 if (group
->needs_save_res
)
12947 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12949 if (htab
->relbrlt
!= NULL
)
12950 htab
->relbrlt
->reloc_count
= 0;
12952 if (htab
->params
->plt_stub_align
!= 0)
12953 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12954 if ((stub_sec
= group
->stub_sec
) != NULL
)
12956 int align
= abs (htab
->params
->plt_stub_align
);
12957 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12960 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12961 if (group
->needs_save_res
)
12963 stub_sec
= group
->stub_sec
;
12964 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
12965 htab
->sfpr
->contents
, htab
->sfpr
->size
);
12966 if (htab
->params
->emit_stub_syms
)
12970 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
12971 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
12976 if (htab
->glink_eh_frame
!= NULL
12977 && htab
->glink_eh_frame
->size
!= 0)
12982 p
= htab
->glink_eh_frame
->contents
;
12983 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
12985 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12986 if (group
->eh_size
!= 0)
12988 /* Offset to stub section. */
12989 val
= (group
->stub_sec
->output_section
->vma
12990 + group
->stub_sec
->output_offset
);
12991 val
-= (htab
->glink_eh_frame
->output_section
->vma
12992 + htab
->glink_eh_frame
->output_offset
12993 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
12994 if (val
+ 0x80000000 > 0xffffffff)
12997 (_("%s offset too large for .eh_frame sdata4 encoding"),
12998 group
->stub_sec
->name
);
13001 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
13002 p
+= (group
->eh_size
+ 17 + 3) & -4;
13004 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13006 /* Offset to .glink. */
13007 val
= (htab
->glink
->output_section
->vma
13008 + htab
->glink
->output_offset
13010 val
-= (htab
->glink_eh_frame
->output_section
->vma
13011 + htab
->glink_eh_frame
->output_offset
13012 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
13013 if (val
+ 0x80000000 > 0xffffffff)
13016 (_("%s offset too large for .eh_frame sdata4 encoding"),
13017 htab
->glink
->name
);
13020 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
13021 p
+= (24 + align
- 1) & -align
;
13025 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13026 if ((stub_sec
= group
->stub_sec
) != NULL
)
13028 stub_sec_count
+= 1;
13029 if (stub_sec
->rawsize
!= stub_sec
->size
13030 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13031 || stub_sec
->rawsize
< stub_sec
->size
))
13037 htab
->stub_error
= TRUE
;
13038 _bfd_error_handler (_("stubs don't match calculated size"));
13041 if (htab
->stub_error
)
13047 *stats
= bfd_malloc (500);
13048 if (*stats
== NULL
)
13051 len
= sprintf (*stats
,
13052 ngettext ("linker stubs in %u group\n",
13053 "linker stubs in %u groups\n",
13056 sprintf (*stats
+ len
, _(" branch %lu\n"
13057 " branch toc adj %lu\n"
13058 " branch notoc %lu\n"
13059 " branch both %lu\n"
13060 " long branch %lu\n"
13061 " long toc adj %lu\n"
13062 " long notoc %lu\n"
13065 " plt call save %lu\n"
13066 " plt call notoc %lu\n"
13067 " plt call both %lu\n"
13068 " global entry %lu"),
13069 htab
->stub_count
[ppc_stub_long_branch
- 1],
13070 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13071 htab
->stub_count
[ppc_stub_long_branch_notoc
- 1],
13072 htab
->stub_count
[ppc_stub_long_branch_both
- 1],
13073 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13074 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13075 htab
->stub_count
[ppc_stub_plt_branch_notoc
- 1],
13076 htab
->stub_count
[ppc_stub_plt_branch_both
- 1],
13077 htab
->stub_count
[ppc_stub_plt_call
- 1],
13078 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13079 htab
->stub_count
[ppc_stub_plt_call_notoc
- 1],
13080 htab
->stub_count
[ppc_stub_plt_call_both
- 1],
13081 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13086 /* What to do when ld finds relocations against symbols defined in
13087 discarded sections. */
13089 static unsigned int
13090 ppc64_elf_action_discarded (asection
*sec
)
13092 if (strcmp (".opd", sec
->name
) == 0)
13095 if (strcmp (".toc", sec
->name
) == 0)
13098 if (strcmp (".toc1", sec
->name
) == 0)
13101 return _bfd_elf_default_action_discarded (sec
);
13104 /* The RELOCATE_SECTION function is called by the ELF backend linker
13105 to handle the relocations for a section.
13107 The relocs are always passed as Rela structures; if the section
13108 actually uses Rel structures, the r_addend field will always be
13111 This function is responsible for adjust the section contents as
13112 necessary, and (if using Rela relocs and generating a
13113 relocatable output file) adjusting the reloc addend as
13116 This function does not have to worry about setting the reloc
13117 address or the reloc symbol index.
13119 LOCAL_SYMS is a pointer to the swapped in local symbols.
13121 LOCAL_SECTIONS is an array giving the section in the input file
13122 corresponding to the st_shndx field of each local symbol.
13124 The global hash table entry for the global symbols can be found
13125 via elf_sym_hashes (input_bfd).
13127 When generating relocatable output, this function must handle
13128 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13129 going to be the section symbol corresponding to the output
13130 section, which means that the addend must be adjusted
13134 ppc64_elf_relocate_section (bfd
*output_bfd
,
13135 struct bfd_link_info
*info
,
13137 asection
*input_section
,
13138 bfd_byte
*contents
,
13139 Elf_Internal_Rela
*relocs
,
13140 Elf_Internal_Sym
*local_syms
,
13141 asection
**local_sections
)
13143 struct ppc_link_hash_table
*htab
;
13144 Elf_Internal_Shdr
*symtab_hdr
;
13145 struct elf_link_hash_entry
**sym_hashes
;
13146 Elf_Internal_Rela
*rel
;
13147 Elf_Internal_Rela
*wrel
;
13148 Elf_Internal_Rela
*relend
;
13149 Elf_Internal_Rela outrel
;
13151 struct got_entry
**local_got_ents
;
13153 bfd_boolean ret
= TRUE
;
13154 bfd_boolean is_opd
;
13155 /* Assume 'at' branch hints. */
13156 bfd_boolean is_isa_v2
= TRUE
;
13157 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13159 /* Initialize howto table if needed. */
13160 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13163 htab
= ppc_hash_table (info
);
13167 /* Don't relocate stub sections. */
13168 if (input_section
->owner
== htab
->params
->stub_bfd
)
13171 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13173 local_got_ents
= elf_local_got_ents (input_bfd
);
13174 TOCstart
= elf_gp (output_bfd
);
13175 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13176 sym_hashes
= elf_sym_hashes (input_bfd
);
13177 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13179 rel
= wrel
= relocs
;
13180 relend
= relocs
+ input_section
->reloc_count
;
13181 for (; rel
< relend
; wrel
++, rel
++)
13183 enum elf_ppc64_reloc_type r_type
;
13185 bfd_reloc_status_type r
;
13186 Elf_Internal_Sym
*sym
;
13188 struct elf_link_hash_entry
*h_elf
;
13189 struct ppc_link_hash_entry
*h
;
13190 struct ppc_link_hash_entry
*fdh
;
13191 const char *sym_name
;
13192 unsigned long r_symndx
, toc_symndx
;
13193 bfd_vma toc_addend
;
13194 unsigned char tls_mask
, tls_gd
, tls_type
;
13195 unsigned char sym_type
;
13196 bfd_vma relocation
;
13197 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
13198 bfd_boolean warned
;
13199 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13202 struct ppc_stub_hash_entry
*stub_entry
;
13203 bfd_vma max_br_offset
;
13205 Elf_Internal_Rela orig_rel
;
13206 reloc_howto_type
*howto
;
13207 struct reloc_howto_struct alt_howto
;
13212 r_type
= ELF64_R_TYPE (rel
->r_info
);
13213 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13215 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13216 symbol of the previous ADDR64 reloc. The symbol gives us the
13217 proper TOC base to use. */
13218 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13220 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13222 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13228 unresolved_reloc
= FALSE
;
13231 if (r_symndx
< symtab_hdr
->sh_info
)
13233 /* It's a local symbol. */
13234 struct _opd_sec_data
*opd
;
13236 sym
= local_syms
+ r_symndx
;
13237 sec
= local_sections
[r_symndx
];
13238 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13239 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13240 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13241 opd
= get_opd_info (sec
);
13242 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13244 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13250 /* If this is a relocation against the opd section sym
13251 and we have edited .opd, adjust the reloc addend so
13252 that ld -r and ld --emit-relocs output is correct.
13253 If it is a reloc against some other .opd symbol,
13254 then the symbol value will be adjusted later. */
13255 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13256 rel
->r_addend
+= adjust
;
13258 relocation
+= adjust
;
13264 bfd_boolean ignored
;
13266 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13267 r_symndx
, symtab_hdr
, sym_hashes
,
13268 h_elf
, sec
, relocation
,
13269 unresolved_reloc
, warned
, ignored
);
13270 sym_name
= h_elf
->root
.root
.string
;
13271 sym_type
= h_elf
->type
;
13273 && sec
->owner
== output_bfd
13274 && strcmp (sec
->name
, ".opd") == 0)
13276 /* This is a symbol defined in a linker script. All
13277 such are defined in output sections, even those
13278 defined by simple assignment from a symbol defined in
13279 an input section. Transfer the symbol to an
13280 appropriate input .opd section, so that a branch to
13281 this symbol will be mapped to the location specified
13282 by the opd entry. */
13283 struct bfd_link_order
*lo
;
13284 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13285 if (lo
->type
== bfd_indirect_link_order
)
13287 asection
*isec
= lo
->u
.indirect
.section
;
13288 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13289 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13292 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13293 h_elf
->root
.u
.def
.section
= isec
;
13300 h
= (struct ppc_link_hash_entry
*) h_elf
;
13302 if (sec
!= NULL
&& discarded_section (sec
))
13304 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
13305 input_bfd
, input_section
,
13306 contents
+ rel
->r_offset
);
13307 wrel
->r_offset
= rel
->r_offset
;
13309 wrel
->r_addend
= 0;
13311 /* For ld -r, remove relocations in debug sections against
13312 symbols defined in discarded sections. Not done for
13313 non-debug to preserve relocs in .eh_frame which the
13314 eh_frame editing code expects to be present. */
13315 if (bfd_link_relocatable (info
)
13316 && (input_section
->flags
& SEC_DEBUGGING
))
13322 if (bfd_link_relocatable (info
))
13325 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13327 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13328 sec
= bfd_abs_section_ptr
;
13329 unresolved_reloc
= FALSE
;
13332 /* TLS optimizations. Replace instruction sequences and relocs
13333 based on information we collected in tls_optimize. We edit
13334 RELOCS so that --emit-relocs will output something sensible
13335 for the final instruction stream. */
13340 tls_mask
= h
->tls_mask
;
13341 else if (local_got_ents
!= NULL
)
13343 struct plt_entry
**local_plt
= (struct plt_entry
**)
13344 (local_got_ents
+ symtab_hdr
->sh_info
);
13345 unsigned char *lgot_masks
= (unsigned char *)
13346 (local_plt
+ symtab_hdr
->sh_info
);
13347 tls_mask
= lgot_masks
[r_symndx
];
13349 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
13350 && (r_type
== R_PPC64_TLS
13351 || r_type
== R_PPC64_TLSGD
13352 || r_type
== R_PPC64_TLSLD
))
13354 /* Check for toc tls entries. */
13355 unsigned char *toc_tls
;
13357 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13358 &local_syms
, rel
, input_bfd
))
13362 tls_mask
= *toc_tls
;
13365 /* Check that tls relocs are used with tls syms, and non-tls
13366 relocs are used with non-tls syms. */
13367 if (r_symndx
!= STN_UNDEF
13368 && r_type
!= R_PPC64_NONE
13370 || h
->elf
.root
.type
== bfd_link_hash_defined
13371 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13372 && (IS_PPC64_TLS_RELOC (r_type
)
13373 != (sym_type
== STT_TLS
13374 || (sym_type
== STT_SECTION
13375 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13377 if ((tls_mask
& TLS_TLS
) != 0
13378 && (r_type
== R_PPC64_TLS
13379 || r_type
== R_PPC64_TLSGD
13380 || r_type
== R_PPC64_TLSLD
))
13381 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13384 info
->callbacks
->einfo
13385 (!IS_PPC64_TLS_RELOC (r_type
)
13386 /* xgettext:c-format */
13387 ? _("%H: %s used with TLS symbol `%pT'\n")
13388 /* xgettext:c-format */
13389 : _("%H: %s used with non-TLS symbol `%pT'\n"),
13390 input_bfd
, input_section
, rel
->r_offset
,
13391 ppc64_elf_howto_table
[r_type
]->name
,
13395 /* Ensure reloc mapping code below stays sane. */
13396 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13397 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13398 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13399 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13400 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13401 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13402 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13403 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13404 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13405 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
13413 case R_PPC64_LO_DS_OPT
:
13414 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
13415 if ((insn
& (0x3f << 26)) != 58u << 26)
13417 insn
+= (14u << 26) - (58u << 26);
13418 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13419 r_type
= R_PPC64_TOC16_LO
;
13420 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13423 case R_PPC64_TOC16
:
13424 case R_PPC64_TOC16_LO
:
13425 case R_PPC64_TOC16_DS
:
13426 case R_PPC64_TOC16_LO_DS
:
13428 /* Check for toc tls entries. */
13429 unsigned char *toc_tls
;
13432 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13433 &local_syms
, rel
, input_bfd
);
13439 tls_mask
= *toc_tls
;
13440 if (r_type
== R_PPC64_TOC16_DS
13441 || r_type
== R_PPC64_TOC16_LO_DS
)
13443 if ((tls_mask
& TLS_TLS
) != 0
13444 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
13449 /* If we found a GD reloc pair, then we might be
13450 doing a GD->IE transition. */
13453 tls_gd
= TLS_TPRELGD
;
13454 if ((tls_mask
& TLS_TLS
) != 0
13455 && (tls_mask
& TLS_GD
) == 0)
13458 else if (retval
== 3)
13460 if ((tls_mask
& TLS_TLS
) != 0
13461 && (tls_mask
& TLS_LD
) == 0)
13469 case R_PPC64_GOT_TPREL16_HI
:
13470 case R_PPC64_GOT_TPREL16_HA
:
13471 if ((tls_mask
& TLS_TLS
) != 0
13472 && (tls_mask
& TLS_TPREL
) == 0)
13474 rel
->r_offset
-= d_offset
;
13475 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13476 r_type
= R_PPC64_NONE
;
13477 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13481 case R_PPC64_GOT_TPREL16_DS
:
13482 case R_PPC64_GOT_TPREL16_LO_DS
:
13483 if ((tls_mask
& TLS_TLS
) != 0
13484 && (tls_mask
& TLS_TPREL
) == 0)
13487 insn
= bfd_get_32 (input_bfd
,
13488 contents
+ rel
->r_offset
- d_offset
);
13490 insn
|= 0x3c0d0000; /* addis 0,13,0 */
13491 bfd_put_32 (input_bfd
, insn
,
13492 contents
+ rel
->r_offset
- d_offset
);
13493 r_type
= R_PPC64_TPREL16_HA
;
13494 if (toc_symndx
!= 0)
13496 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13497 rel
->r_addend
= toc_addend
;
13498 /* We changed the symbol. Start over in order to
13499 get h, sym, sec etc. right. */
13503 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13508 if ((tls_mask
& TLS_TLS
) != 0
13509 && (tls_mask
& TLS_TPREL
) == 0)
13511 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13512 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
13515 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
13516 /* Was PPC64_TLS which sits on insn boundary, now
13517 PPC64_TPREL16_LO which is at low-order half-word. */
13518 rel
->r_offset
+= d_offset
;
13519 r_type
= R_PPC64_TPREL16_LO
;
13520 if (toc_symndx
!= 0)
13522 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13523 rel
->r_addend
= toc_addend
;
13524 /* We changed the symbol. Start over in order to
13525 get h, sym, sec etc. right. */
13529 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13533 case R_PPC64_GOT_TLSGD16_HI
:
13534 case R_PPC64_GOT_TLSGD16_HA
:
13535 tls_gd
= TLS_TPRELGD
;
13536 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13540 case R_PPC64_GOT_TLSLD16_HI
:
13541 case R_PPC64_GOT_TLSLD16_HA
:
13542 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13545 if ((tls_mask
& tls_gd
) != 0)
13546 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13547 + R_PPC64_GOT_TPREL16_DS
);
13550 rel
->r_offset
-= d_offset
;
13551 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13552 r_type
= R_PPC64_NONE
;
13554 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13558 case R_PPC64_GOT_TLSGD16
:
13559 case R_PPC64_GOT_TLSGD16_LO
:
13560 tls_gd
= TLS_TPRELGD
;
13561 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13565 case R_PPC64_GOT_TLSLD16
:
13566 case R_PPC64_GOT_TLSLD16_LO
:
13567 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13569 unsigned int insn1
, insn2
;
13573 offset
= (bfd_vma
) -1;
13574 /* If not using the newer R_PPC64_TLSGD/LD to mark
13575 __tls_get_addr calls, we must trust that the call
13576 stays with its arg setup insns, ie. that the next
13577 reloc is the __tls_get_addr call associated with
13578 the current reloc. Edit both insns. */
13579 if (input_section
->has_tls_get_addr_call
13580 && rel
+ 1 < relend
13581 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
13582 htab
->tls_get_addr
,
13583 htab
->tls_get_addr_fd
))
13584 offset
= rel
[1].r_offset
;
13585 /* We read the low GOT_TLS (or TOC16) insn because we
13586 need to keep the destination reg. It may be
13587 something other than the usual r3, and moved to r3
13588 before the call by intervening code. */
13589 insn1
= bfd_get_32 (input_bfd
,
13590 contents
+ rel
->r_offset
- d_offset
);
13591 if ((tls_mask
& tls_gd
) != 0)
13594 insn1
&= (0x1f << 21) | (0x1f << 16);
13595 insn1
|= 58 << 26; /* ld */
13596 insn2
= 0x7c636a14; /* add 3,3,13 */
13597 if (offset
!= (bfd_vma
) -1)
13598 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13599 if ((tls_mask
& TLS_EXPLICIT
) == 0)
13600 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13601 + R_PPC64_GOT_TPREL16_DS
);
13603 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
13604 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13609 insn1
&= 0x1f << 21;
13610 insn1
|= 0x3c0d0000; /* addis r,13,0 */
13611 insn2
= 0x38630000; /* addi 3,3,0 */
13614 /* Was an LD reloc. */
13616 sec
= local_sections
[toc_symndx
];
13618 r_symndx
< symtab_hdr
->sh_info
;
13620 if (local_sections
[r_symndx
] == sec
)
13622 if (r_symndx
>= symtab_hdr
->sh_info
)
13623 r_symndx
= STN_UNDEF
;
13624 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13625 if (r_symndx
!= STN_UNDEF
)
13626 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13627 + sec
->output_offset
13628 + sec
->output_section
->vma
);
13630 else if (toc_symndx
!= 0)
13632 r_symndx
= toc_symndx
;
13633 rel
->r_addend
= toc_addend
;
13635 r_type
= R_PPC64_TPREL16_HA
;
13636 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13637 if (offset
!= (bfd_vma
) -1)
13639 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
13640 R_PPC64_TPREL16_LO
);
13641 rel
[1].r_offset
= offset
+ d_offset
;
13642 rel
[1].r_addend
= rel
->r_addend
;
13645 bfd_put_32 (input_bfd
, insn1
,
13646 contents
+ rel
->r_offset
- d_offset
);
13647 if (offset
!= (bfd_vma
) -1)
13648 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13649 if ((tls_mask
& tls_gd
) == 0
13650 && (tls_gd
== 0 || toc_symndx
!= 0))
13652 /* We changed the symbol. Start over in order
13653 to get h, sym, sec etc. right. */
13659 case R_PPC64_TLSGD
:
13660 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
13661 && rel
+ 1 < relend
)
13663 unsigned int insn2
;
13664 bfd_vma offset
= rel
->r_offset
;
13666 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
13668 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
13669 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13673 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
13674 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
13676 if ((tls_mask
& TLS_TPRELGD
) != 0)
13679 r_type
= R_PPC64_NONE
;
13680 insn2
= 0x7c636a14; /* add 3,3,13 */
13685 if (toc_symndx
!= 0)
13687 r_symndx
= toc_symndx
;
13688 rel
->r_addend
= toc_addend
;
13690 r_type
= R_PPC64_TPREL16_LO
;
13691 rel
->r_offset
= offset
+ d_offset
;
13692 insn2
= 0x38630000; /* addi 3,3,0 */
13694 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13695 /* Zap the reloc on the _tls_get_addr call too. */
13696 BFD_ASSERT (offset
== rel
[1].r_offset
);
13697 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13698 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13699 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
13704 case R_PPC64_TLSLD
:
13705 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
13706 && rel
+ 1 < relend
)
13708 unsigned int insn2
;
13709 bfd_vma offset
= rel
->r_offset
;
13711 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
13713 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
13714 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13718 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
13719 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
13722 sec
= local_sections
[toc_symndx
];
13724 r_symndx
< symtab_hdr
->sh_info
;
13726 if (local_sections
[r_symndx
] == sec
)
13728 if (r_symndx
>= symtab_hdr
->sh_info
)
13729 r_symndx
= STN_UNDEF
;
13730 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13731 if (r_symndx
!= STN_UNDEF
)
13732 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13733 + sec
->output_offset
13734 + sec
->output_section
->vma
);
13736 r_type
= R_PPC64_TPREL16_LO
;
13737 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13738 rel
->r_offset
= offset
+ d_offset
;
13739 /* Zap the reloc on the _tls_get_addr call too. */
13740 BFD_ASSERT (offset
== rel
[1].r_offset
);
13741 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13742 insn2
= 0x38630000; /* addi 3,3,0 */
13743 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13748 case R_PPC64_DTPMOD64
:
13749 if (rel
+ 1 < relend
13750 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
13751 && rel
[1].r_offset
== rel
->r_offset
+ 8)
13753 if ((tls_mask
& TLS_GD
) == 0)
13755 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
13756 if ((tls_mask
& TLS_TPRELGD
) != 0)
13757 r_type
= R_PPC64_TPREL64
;
13760 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13761 r_type
= R_PPC64_NONE
;
13763 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13768 if ((tls_mask
& TLS_LD
) == 0)
13770 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13771 r_type
= R_PPC64_NONE
;
13772 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13777 case R_PPC64_TPREL64
:
13778 if ((tls_mask
& TLS_TPREL
) == 0)
13780 r_type
= R_PPC64_NONE
;
13781 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13785 case R_PPC64_ENTRY
:
13786 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13787 if (!bfd_link_pic (info
)
13788 && !info
->traditional_format
13789 && relocation
+ 0x80008000 <= 0xffffffff)
13791 unsigned int insn1
, insn2
;
13793 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13794 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
13795 if ((insn1
& ~0xfffc) == LD_R2_0R12
13796 && insn2
== ADD_R2_R2_R12
)
13798 bfd_put_32 (input_bfd
,
13799 LIS_R2
+ PPC_HA (relocation
),
13800 contents
+ rel
->r_offset
);
13801 bfd_put_32 (input_bfd
,
13802 ADDI_R2_R2
+ PPC_LO (relocation
),
13803 contents
+ rel
->r_offset
+ 4);
13808 relocation
-= (rel
->r_offset
13809 + input_section
->output_offset
13810 + input_section
->output_section
->vma
);
13811 if (relocation
+ 0x80008000 <= 0xffffffff)
13813 unsigned int insn1
, insn2
;
13815 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13816 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
13817 if ((insn1
& ~0xfffc) == LD_R2_0R12
13818 && insn2
== ADD_R2_R2_R12
)
13820 bfd_put_32 (input_bfd
,
13821 ADDIS_R2_R12
+ PPC_HA (relocation
),
13822 contents
+ rel
->r_offset
);
13823 bfd_put_32 (input_bfd
,
13824 ADDI_R2_R2
+ PPC_LO (relocation
),
13825 contents
+ rel
->r_offset
+ 4);
13831 case R_PPC64_REL16_HA
:
13832 /* If we are generating a non-PIC executable, edit
13833 . 0: addis 2,12,.TOC.-0b@ha
13834 . addi 2,2,.TOC.-0b@l
13835 used by ELFv2 global entry points to set up r2, to
13838 if .TOC. is in range. */
13839 if (!bfd_link_pic (info
)
13840 && !info
->traditional_format
13842 && rel
->r_addend
== d_offset
13843 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
13844 && rel
+ 1 < relend
13845 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
13846 && rel
[1].r_offset
== rel
->r_offset
+ 4
13847 && rel
[1].r_addend
== rel
->r_addend
+ 4
13848 && relocation
+ 0x80008000 <= 0xffffffff)
13850 unsigned int insn1
, insn2
;
13851 bfd_vma offset
= rel
->r_offset
- d_offset
;
13852 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
13853 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
13854 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
13855 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
13857 r_type
= R_PPC64_ADDR16_HA
;
13858 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13859 rel
->r_addend
-= d_offset
;
13860 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
13861 rel
[1].r_addend
-= d_offset
+ 4;
13862 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
13868 /* Handle other relocations that tweak non-addend part of insn. */
13870 max_br_offset
= 1 << 25;
13871 addend
= rel
->r_addend
;
13872 reloc_dest
= DEST_NORMAL
;
13878 case R_PPC64_TOCSAVE
:
13879 if (relocation
+ addend
== (rel
->r_offset
13880 + input_section
->output_offset
13881 + input_section
->output_section
->vma
)
13882 && tocsave_find (htab
, NO_INSERT
,
13883 &local_syms
, rel
, input_bfd
))
13885 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13887 || insn
== CROR_151515
|| insn
== CROR_313131
)
13888 bfd_put_32 (input_bfd
,
13889 STD_R2_0R1
+ STK_TOC (htab
),
13890 contents
+ rel
->r_offset
);
13894 /* Branch taken prediction relocations. */
13895 case R_PPC64_ADDR14_BRTAKEN
:
13896 case R_PPC64_REL14_BRTAKEN
:
13897 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
13898 /* Fall through. */
13900 /* Branch not taken prediction relocations. */
13901 case R_PPC64_ADDR14_BRNTAKEN
:
13902 case R_PPC64_REL14_BRNTAKEN
:
13903 insn
|= bfd_get_32 (input_bfd
,
13904 contents
+ rel
->r_offset
) & ~(0x01 << 21);
13905 /* Fall through. */
13907 case R_PPC64_REL14
:
13908 max_br_offset
= 1 << 15;
13909 /* Fall through. */
13911 case R_PPC64_REL24
:
13912 case R_PPC64_REL24_NOTOC
:
13913 case R_PPC64_PLTCALL
:
13914 /* Calls to functions with a different TOC, such as calls to
13915 shared objects, need to alter the TOC pointer. This is
13916 done using a linkage stub. A REL24 branching to these
13917 linkage stubs needs to be followed by a nop, as the nop
13918 will be replaced with an instruction to restore the TOC
13923 && h
->oh
->is_func_descriptor
)
13924 fdh
= ppc_follow_link (h
->oh
);
13925 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
13927 if (r_type
== R_PPC64_PLTCALL
13928 && stub_entry
!= NULL
13929 && stub_entry
->stub_type
>= ppc_stub_plt_call
13930 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
13933 if (stub_entry
!= NULL
13934 && ((stub_entry
->stub_type
>= ppc_stub_plt_call
13935 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
13936 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
13937 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
13938 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
13939 || stub_entry
->stub_type
== ppc_stub_long_branch_both
))
13941 bfd_boolean can_plt_call
= FALSE
;
13943 if (stub_entry
->stub_type
== ppc_stub_plt_call
13945 && htab
->params
->plt_localentry0
!= 0
13946 && is_elfv2_localentry0 (&h
->elf
))
13948 /* The function doesn't use or change r2. */
13949 can_plt_call
= TRUE
;
13951 else if (r_type
== R_PPC64_REL24_NOTOC
)
13953 /* NOTOC calls don't need to restore r2. */
13954 can_plt_call
= TRUE
;
13957 /* All of these stubs may modify r2, so there must be a
13958 branch and link followed by a nop. The nop is
13959 replaced by an insn to restore r2. */
13960 else if (rel
->r_offset
+ 8 <= input_section
->size
)
13964 br
= bfd_get_32 (input_bfd
,
13965 contents
+ rel
->r_offset
);
13970 nop
= bfd_get_32 (input_bfd
,
13971 contents
+ rel
->r_offset
+ 4);
13972 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
13973 can_plt_call
= TRUE
;
13974 else if (nop
== NOP
13975 || nop
== CROR_151515
13976 || nop
== CROR_313131
)
13979 && (h
== htab
->tls_get_addr_fd
13980 || h
== htab
->tls_get_addr
)
13981 && htab
->params
->tls_get_addr_opt
)
13983 /* Special stub used, leave nop alone. */
13986 bfd_put_32 (input_bfd
,
13987 LD_R2_0R1
+ STK_TOC (htab
),
13988 contents
+ rel
->r_offset
+ 4);
13989 can_plt_call
= TRUE
;
13994 if (!can_plt_call
&& h
!= NULL
)
13996 const char *name
= h
->elf
.root
.root
.string
;
14001 if (strncmp (name
, "__libc_start_main", 17) == 0
14002 && (name
[17] == 0 || name
[17] == '@'))
14004 /* Allow crt1 branch to go via a toc adjusting
14005 stub. Other calls that never return could do
14006 the same, if we could detect such. */
14007 can_plt_call
= TRUE
;
14013 /* g++ as of 20130507 emits self-calls without a
14014 following nop. This is arguably wrong since we
14015 have conflicting information. On the one hand a
14016 global symbol and on the other a local call
14017 sequence, but don't error for this special case.
14018 It isn't possible to cheaply verify we have
14019 exactly such a call. Allow all calls to the same
14021 asection
*code_sec
= sec
;
14023 if (get_opd_info (sec
) != NULL
)
14025 bfd_vma off
= (relocation
+ addend
14026 - sec
->output_section
->vma
14027 - sec
->output_offset
);
14029 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14031 if (code_sec
== input_section
)
14032 can_plt_call
= TRUE
;
14037 if (stub_entry
->stub_type
>= ppc_stub_plt_call
14038 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14039 info
->callbacks
->einfo
14040 /* xgettext:c-format */
14041 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14042 "(plt call stub)\n"),
14043 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14045 info
->callbacks
->einfo
14046 /* xgettext:c-format */
14047 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14048 "(toc save/adjust stub)\n"),
14049 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14051 bfd_set_error (bfd_error_bad_value
);
14056 && stub_entry
->stub_type
>= ppc_stub_plt_call
14057 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14058 unresolved_reloc
= FALSE
;
14061 if ((stub_entry
== NULL
14062 || stub_entry
->stub_type
== ppc_stub_long_branch
14063 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14064 && get_opd_info (sec
) != NULL
)
14066 /* The branch destination is the value of the opd entry. */
14067 bfd_vma off
= (relocation
+ addend
14068 - sec
->output_section
->vma
14069 - sec
->output_offset
);
14070 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14071 if (dest
!= (bfd_vma
) -1)
14075 reloc_dest
= DEST_OPD
;
14079 /* If the branch is out of reach we ought to have a long
14081 from
= (rel
->r_offset
14082 + input_section
->output_offset
14083 + input_section
->output_section
->vma
);
14085 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14089 if (stub_entry
!= NULL
14090 && (stub_entry
->stub_type
== ppc_stub_long_branch
14091 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14092 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14093 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14094 || (relocation
+ addend
- from
+ max_br_offset
14095 < 2 * max_br_offset
)))
14096 /* Don't use the stub if this branch is in range. */
14099 if (stub_entry
!= NULL
14100 && (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
14101 || stub_entry
->stub_type
== ppc_stub_long_branch_both
14102 || stub_entry
->stub_type
== ppc_stub_plt_branch_notoc
14103 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
14104 && (r_type
!= R_PPC64_REL24_NOTOC
14105 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
14106 & STO_PPC64_LOCAL_MASK
) == 1 << STO_PPC64_LOCAL_BIT
)
14107 && (relocation
+ addend
- from
+ max_br_offset
14108 < 2 * max_br_offset
))
14111 if (stub_entry
!= NULL
14112 && (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
14113 || stub_entry
->stub_type
== ppc_stub_long_branch_both
14114 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14115 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
14116 && r_type
== R_PPC64_REL24_NOTOC
14117 && (relocation
+ addend
- from
+ max_br_offset
14118 < 2 * max_br_offset
))
14121 if (stub_entry
!= NULL
)
14123 /* Munge up the value and addend so that we call the stub
14124 rather than the procedure directly. */
14125 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14127 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14128 relocation
+= (stub_sec
->output_offset
14129 + stub_sec
->output_section
->vma
14130 + stub_sec
->size
- htab
->sfpr
->size
14131 - htab
->sfpr
->output_offset
14132 - htab
->sfpr
->output_section
->vma
);
14134 relocation
= (stub_entry
->stub_offset
14135 + stub_sec
->output_offset
14136 + stub_sec
->output_section
->vma
);
14138 reloc_dest
= DEST_STUB
;
14140 if (((stub_entry
->stub_type
== ppc_stub_plt_call
14141 && ALWAYS_EMIT_R2SAVE
)
14142 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14143 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
14145 && (h
== htab
->tls_get_addr_fd
14146 || h
== htab
->tls_get_addr
)
14147 && htab
->params
->tls_get_addr_opt
)
14148 && rel
+ 1 < relend
14149 && rel
[1].r_offset
== rel
->r_offset
+ 4
14150 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14152 else if ((stub_entry
->stub_type
== ppc_stub_long_branch_both
14153 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
14154 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
14155 && r_type
== R_PPC64_REL24_NOTOC
)
14163 /* Set 'a' bit. This is 0b00010 in BO field for branch
14164 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14165 for branch on CTR insns (BO == 1a00t or 1a01t). */
14166 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14167 insn
|= 0x02 << 21;
14168 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14169 insn
|= 0x08 << 21;
14175 /* Invert 'y' bit if not the default. */
14176 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14177 insn
^= 0x01 << 21;
14180 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14183 /* NOP out calls to undefined weak functions.
14184 We can thus call a weak function without first
14185 checking whether the function is defined. */
14187 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14188 && h
->elf
.dynindx
== -1
14189 && (r_type
== R_PPC64_REL24
14190 || r_type
== R_PPC64_REL24_NOTOC
)
14194 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14200 /* Set `addend'. */
14202 save_unresolved_reloc
= unresolved_reloc
;
14206 /* xgettext:c-format */
14207 _bfd_error_handler (_("%pB: %s unsupported"),
14208 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
14210 bfd_set_error (bfd_error_bad_value
);
14216 case R_PPC64_TLSGD
:
14217 case R_PPC64_TLSLD
:
14218 case R_PPC64_TOCSAVE
:
14219 case R_PPC64_GNU_VTINHERIT
:
14220 case R_PPC64_GNU_VTENTRY
:
14221 case R_PPC64_ENTRY
:
14224 /* GOT16 relocations. Like an ADDR16 using the symbol's
14225 address in the GOT as relocation value instead of the
14226 symbol's value itself. Also, create a GOT entry for the
14227 symbol and put the symbol value there. */
14228 case R_PPC64_GOT_TLSGD16
:
14229 case R_PPC64_GOT_TLSGD16_LO
:
14230 case R_PPC64_GOT_TLSGD16_HI
:
14231 case R_PPC64_GOT_TLSGD16_HA
:
14232 tls_type
= TLS_TLS
| TLS_GD
;
14235 case R_PPC64_GOT_TLSLD16
:
14236 case R_PPC64_GOT_TLSLD16_LO
:
14237 case R_PPC64_GOT_TLSLD16_HI
:
14238 case R_PPC64_GOT_TLSLD16_HA
:
14239 tls_type
= TLS_TLS
| TLS_LD
;
14242 case R_PPC64_GOT_TPREL16_DS
:
14243 case R_PPC64_GOT_TPREL16_LO_DS
:
14244 case R_PPC64_GOT_TPREL16_HI
:
14245 case R_PPC64_GOT_TPREL16_HA
:
14246 tls_type
= TLS_TLS
| TLS_TPREL
;
14249 case R_PPC64_GOT_DTPREL16_DS
:
14250 case R_PPC64_GOT_DTPREL16_LO_DS
:
14251 case R_PPC64_GOT_DTPREL16_HI
:
14252 case R_PPC64_GOT_DTPREL16_HA
:
14253 tls_type
= TLS_TLS
| TLS_DTPREL
;
14256 case R_PPC64_GOT16
:
14257 case R_PPC64_GOT16_LO
:
14258 case R_PPC64_GOT16_HI
:
14259 case R_PPC64_GOT16_HA
:
14260 case R_PPC64_GOT16_DS
:
14261 case R_PPC64_GOT16_LO_DS
:
14264 /* Relocation is to the entry for this symbol in the global
14269 unsigned long indx
= 0;
14270 struct got_entry
*ent
;
14272 if (tls_type
== (TLS_TLS
| TLS_LD
)
14274 || !h
->elf
.def_dynamic
))
14275 ent
= ppc64_tlsld_got (input_bfd
);
14280 if (!htab
->elf
.dynamic_sections_created
14281 || h
->elf
.dynindx
== -1
14282 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14283 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
14284 /* This is actually a static link, or it is a
14285 -Bsymbolic link and the symbol is defined
14286 locally, or the symbol was forced to be local
14287 because of a version file. */
14291 indx
= h
->elf
.dynindx
;
14292 unresolved_reloc
= FALSE
;
14294 ent
= h
->elf
.got
.glist
;
14298 if (local_got_ents
== NULL
)
14300 ent
= local_got_ents
[r_symndx
];
14303 for (; ent
!= NULL
; ent
= ent
->next
)
14304 if (ent
->addend
== orig_rel
.r_addend
14305 && ent
->owner
== input_bfd
14306 && ent
->tls_type
== tls_type
)
14312 if (ent
->is_indirect
)
14313 ent
= ent
->got
.ent
;
14314 offp
= &ent
->got
.offset
;
14315 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14319 /* The offset must always be a multiple of 8. We use the
14320 least significant bit to record whether we have already
14321 processed this entry. */
14323 if ((off
& 1) != 0)
14327 /* Generate relocs for the dynamic linker, except in
14328 the case of TLSLD where we'll use one entry per
14336 ? h
->elf
.type
== STT_GNU_IFUNC
14337 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14340 relgot
= htab
->elf
.irelplt
;
14342 htab
->local_ifunc_resolver
= 1;
14343 else if (is_static_defined (&h
->elf
))
14344 htab
->maybe_local_ifunc_resolver
= 1;
14347 || (bfd_link_pic (info
)
14349 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
)
14350 || (tls_type
== (TLS_TLS
| TLS_LD
)
14351 && !h
->elf
.def_dynamic
))
14352 && !(tls_type
== (TLS_TLS
| TLS_TPREL
)
14353 && bfd_link_executable (info
)
14354 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
14355 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14356 if (relgot
!= NULL
)
14358 outrel
.r_offset
= (got
->output_section
->vma
14359 + got
->output_offset
14361 outrel
.r_addend
= addend
;
14362 if (tls_type
& (TLS_LD
| TLS_GD
))
14364 outrel
.r_addend
= 0;
14365 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14366 if (tls_type
== (TLS_TLS
| TLS_GD
))
14368 loc
= relgot
->contents
;
14369 loc
+= (relgot
->reloc_count
++
14370 * sizeof (Elf64_External_Rela
));
14371 bfd_elf64_swap_reloca_out (output_bfd
,
14373 outrel
.r_offset
+= 8;
14374 outrel
.r_addend
= addend
;
14376 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14379 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14380 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14381 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14382 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14383 else if (indx
!= 0)
14384 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14388 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14390 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14392 /* Write the .got section contents for the sake
14394 loc
= got
->contents
+ off
;
14395 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14399 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14401 outrel
.r_addend
+= relocation
;
14402 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14404 if (htab
->elf
.tls_sec
== NULL
)
14405 outrel
.r_addend
= 0;
14407 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14410 loc
= relgot
->contents
;
14411 loc
+= (relgot
->reloc_count
++
14412 * sizeof (Elf64_External_Rela
));
14413 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14416 /* Init the .got section contents here if we're not
14417 emitting a reloc. */
14420 relocation
+= addend
;
14423 if (htab
->elf
.tls_sec
== NULL
)
14427 if (tls_type
& TLS_LD
)
14430 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14431 if (tls_type
& TLS_TPREL
)
14432 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14435 if (tls_type
& (TLS_GD
| TLS_LD
))
14437 bfd_put_64 (output_bfd
, relocation
,
14438 got
->contents
+ off
+ 8);
14442 bfd_put_64 (output_bfd
, relocation
,
14443 got
->contents
+ off
);
14447 if (off
>= (bfd_vma
) -2)
14450 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
14451 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
14455 case R_PPC64_PLT16_HA
:
14456 case R_PPC64_PLT16_HI
:
14457 case R_PPC64_PLT16_LO
:
14458 case R_PPC64_PLT16_LO_DS
:
14459 case R_PPC64_PLT32
:
14460 case R_PPC64_PLT64
:
14461 case R_PPC64_PLTSEQ
:
14462 case R_PPC64_PLTCALL
:
14463 /* Relocation is to the entry for this symbol in the
14464 procedure linkage table. */
14465 unresolved_reloc
= TRUE
;
14467 struct plt_entry
**plt_list
= NULL
;
14469 plt_list
= &h
->elf
.plt
.plist
;
14470 else if (local_got_ents
!= NULL
)
14472 struct plt_entry
**local_plt
= (struct plt_entry
**)
14473 (local_got_ents
+ symtab_hdr
->sh_info
);
14474 plt_list
= local_plt
+ r_symndx
;
14478 struct plt_entry
*ent
;
14480 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
14481 if (ent
->plt
.offset
!= (bfd_vma
) -1
14482 && ent
->addend
== orig_rel
.r_addend
)
14487 plt
= htab
->elf
.splt
;
14488 if (!htab
->elf
.dynamic_sections_created
14490 || h
->elf
.dynindx
== -1)
14493 ? h
->elf
.type
== STT_GNU_IFUNC
14494 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14495 plt
= htab
->elf
.iplt
;
14497 plt
= htab
->pltlocal
;
14499 relocation
= (plt
->output_section
->vma
14500 + plt
->output_offset
14501 + ent
->plt
.offset
);
14502 if (r_type
== R_PPC64_PLT16_HA
14503 || r_type
== R_PPC64_PLT16_HI
14504 || r_type
== R_PPC64_PLT16_LO
14505 || r_type
== R_PPC64_PLT16_LO_DS
)
14507 got
= (elf_gp (output_bfd
)
14508 + htab
->sec_info
[input_section
->id
].toc_off
);
14512 unresolved_reloc
= FALSE
;
14520 /* Relocation value is TOC base. */
14521 relocation
= TOCstart
;
14522 if (r_symndx
== STN_UNDEF
)
14523 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
14524 else if (unresolved_reloc
)
14526 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
14527 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
14529 unresolved_reloc
= TRUE
;
14532 /* TOC16 relocs. We want the offset relative to the TOC base,
14533 which is the address of the start of the TOC plus 0x8000.
14534 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14536 case R_PPC64_TOC16
:
14537 case R_PPC64_TOC16_LO
:
14538 case R_PPC64_TOC16_HI
:
14539 case R_PPC64_TOC16_DS
:
14540 case R_PPC64_TOC16_LO_DS
:
14541 case R_PPC64_TOC16_HA
:
14542 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14545 /* Relocate against the beginning of the section. */
14546 case R_PPC64_SECTOFF
:
14547 case R_PPC64_SECTOFF_LO
:
14548 case R_PPC64_SECTOFF_HI
:
14549 case R_PPC64_SECTOFF_DS
:
14550 case R_PPC64_SECTOFF_LO_DS
:
14551 case R_PPC64_SECTOFF_HA
:
14553 addend
-= sec
->output_section
->vma
;
14556 case R_PPC64_REL16
:
14557 case R_PPC64_REL16_LO
:
14558 case R_PPC64_REL16_HI
:
14559 case R_PPC64_REL16_HA
:
14560 case R_PPC64_REL16DX_HA
:
14563 case R_PPC64_REL14
:
14564 case R_PPC64_REL14_BRNTAKEN
:
14565 case R_PPC64_REL14_BRTAKEN
:
14566 case R_PPC64_REL24
:
14567 case R_PPC64_REL24_NOTOC
:
14570 case R_PPC64_TPREL16
:
14571 case R_PPC64_TPREL16_LO
:
14572 case R_PPC64_TPREL16_HI
:
14573 case R_PPC64_TPREL16_HA
:
14574 case R_PPC64_TPREL16_DS
:
14575 case R_PPC64_TPREL16_LO_DS
:
14576 case R_PPC64_TPREL16_HIGH
:
14577 case R_PPC64_TPREL16_HIGHA
:
14578 case R_PPC64_TPREL16_HIGHER
:
14579 case R_PPC64_TPREL16_HIGHERA
:
14580 case R_PPC64_TPREL16_HIGHEST
:
14581 case R_PPC64_TPREL16_HIGHESTA
:
14583 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14584 && h
->elf
.dynindx
== -1)
14586 /* Make this relocation against an undefined weak symbol
14587 resolve to zero. This is really just a tweak, since
14588 code using weak externs ought to check that they are
14589 defined before using them. */
14590 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
14592 insn
= bfd_get_32 (input_bfd
, p
);
14593 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
14595 bfd_put_32 (input_bfd
, insn
, p
);
14598 if (htab
->elf
.tls_sec
!= NULL
)
14599 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14600 /* The TPREL16 relocs shouldn't really be used in shared
14601 libs or with non-local symbols as that will result in
14602 DT_TEXTREL being set, but support them anyway. */
14605 case R_PPC64_DTPREL16
:
14606 case R_PPC64_DTPREL16_LO
:
14607 case R_PPC64_DTPREL16_HI
:
14608 case R_PPC64_DTPREL16_HA
:
14609 case R_PPC64_DTPREL16_DS
:
14610 case R_PPC64_DTPREL16_LO_DS
:
14611 case R_PPC64_DTPREL16_HIGH
:
14612 case R_PPC64_DTPREL16_HIGHA
:
14613 case R_PPC64_DTPREL16_HIGHER
:
14614 case R_PPC64_DTPREL16_HIGHERA
:
14615 case R_PPC64_DTPREL16_HIGHEST
:
14616 case R_PPC64_DTPREL16_HIGHESTA
:
14617 if (htab
->elf
.tls_sec
!= NULL
)
14618 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14621 case R_PPC64_ADDR64_LOCAL
:
14622 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
14627 case R_PPC64_DTPMOD64
:
14632 case R_PPC64_TPREL64
:
14633 if (htab
->elf
.tls_sec
!= NULL
)
14634 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14637 case R_PPC64_DTPREL64
:
14638 if (htab
->elf
.tls_sec
!= NULL
)
14639 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14640 /* Fall through. */
14642 /* Relocations that may need to be propagated if this is a
14644 case R_PPC64_REL30
:
14645 case R_PPC64_REL32
:
14646 case R_PPC64_REL64
:
14647 case R_PPC64_ADDR14
:
14648 case R_PPC64_ADDR14_BRNTAKEN
:
14649 case R_PPC64_ADDR14_BRTAKEN
:
14650 case R_PPC64_ADDR16
:
14651 case R_PPC64_ADDR16_DS
:
14652 case R_PPC64_ADDR16_HA
:
14653 case R_PPC64_ADDR16_HI
:
14654 case R_PPC64_ADDR16_HIGH
:
14655 case R_PPC64_ADDR16_HIGHA
:
14656 case R_PPC64_ADDR16_HIGHER
:
14657 case R_PPC64_ADDR16_HIGHERA
:
14658 case R_PPC64_ADDR16_HIGHEST
:
14659 case R_PPC64_ADDR16_HIGHESTA
:
14660 case R_PPC64_ADDR16_LO
:
14661 case R_PPC64_ADDR16_LO_DS
:
14662 case R_PPC64_ADDR24
:
14663 case R_PPC64_ADDR32
:
14664 case R_PPC64_ADDR64
:
14665 case R_PPC64_UADDR16
:
14666 case R_PPC64_UADDR32
:
14667 case R_PPC64_UADDR64
:
14669 if ((input_section
->flags
& SEC_ALLOC
) == 0)
14672 if (NO_OPD_RELOCS
&& is_opd
)
14675 if (bfd_link_pic (info
)
14677 || h
->dyn_relocs
!= NULL
)
14678 && ((h
!= NULL
&& pc_dynrelocs (h
))
14679 || must_be_dyn_reloc (info
, r_type
)))
14681 ? h
->dyn_relocs
!= NULL
14682 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14684 bfd_boolean skip
, relocate
;
14689 /* When generating a dynamic object, these relocations
14690 are copied into the output file to be resolved at run
14696 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
14697 input_section
, rel
->r_offset
);
14698 if (out_off
== (bfd_vma
) -1)
14700 else if (out_off
== (bfd_vma
) -2)
14701 skip
= TRUE
, relocate
= TRUE
;
14702 out_off
+= (input_section
->output_section
->vma
14703 + input_section
->output_offset
);
14704 outrel
.r_offset
= out_off
;
14705 outrel
.r_addend
= rel
->r_addend
;
14707 /* Optimize unaligned reloc use. */
14708 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
14709 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
14710 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
14711 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
14712 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
14713 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
14714 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
14715 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
14716 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
14719 memset (&outrel
, 0, sizeof outrel
);
14720 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14722 && r_type
!= R_PPC64_TOC
)
14724 indx
= h
->elf
.dynindx
;
14725 BFD_ASSERT (indx
!= -1);
14726 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14730 /* This symbol is local, or marked to become local,
14731 or this is an opd section reloc which must point
14732 at a local function. */
14733 outrel
.r_addend
+= relocation
;
14734 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
14736 if (is_opd
&& h
!= NULL
)
14738 /* Lie about opd entries. This case occurs
14739 when building shared libraries and we
14740 reference a function in another shared
14741 lib. The same thing happens for a weak
14742 definition in an application that's
14743 overridden by a strong definition in a
14744 shared lib. (I believe this is a generic
14745 bug in binutils handling of weak syms.)
14746 In these cases we won't use the opd
14747 entry in this lib. */
14748 unresolved_reloc
= FALSE
;
14751 && r_type
== R_PPC64_ADDR64
14753 ? h
->elf
.type
== STT_GNU_IFUNC
14754 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14755 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14758 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14760 /* We need to relocate .opd contents for ld.so.
14761 Prelink also wants simple and consistent rules
14762 for relocs. This make all RELATIVE relocs have
14763 *r_offset equal to r_addend. */
14770 ? h
->elf
.type
== STT_GNU_IFUNC
14771 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14773 info
->callbacks
->einfo
14774 /* xgettext:c-format */
14775 (_("%H: %s for indirect "
14776 "function `%pT' unsupported\n"),
14777 input_bfd
, input_section
, rel
->r_offset
,
14778 ppc64_elf_howto_table
[r_type
]->name
,
14782 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
14784 else if (sec
== NULL
|| sec
->owner
== NULL
)
14786 bfd_set_error (bfd_error_bad_value
);
14793 osec
= sec
->output_section
;
14794 indx
= elf_section_data (osec
)->dynindx
;
14798 if ((osec
->flags
& SEC_READONLY
) == 0
14799 && htab
->elf
.data_index_section
!= NULL
)
14800 osec
= htab
->elf
.data_index_section
;
14802 osec
= htab
->elf
.text_index_section
;
14803 indx
= elf_section_data (osec
)->dynindx
;
14805 BFD_ASSERT (indx
!= 0);
14807 /* We are turning this relocation into one
14808 against a section symbol, so subtract out
14809 the output section's address but not the
14810 offset of the input section in the output
14812 outrel
.r_addend
-= osec
->vma
;
14815 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14819 sreloc
= elf_section_data (input_section
)->sreloc
;
14821 ? h
->elf
.type
== STT_GNU_IFUNC
14822 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14824 sreloc
= htab
->elf
.irelplt
;
14826 htab
->local_ifunc_resolver
= 1;
14827 else if (is_static_defined (&h
->elf
))
14828 htab
->maybe_local_ifunc_resolver
= 1;
14830 if (sreloc
== NULL
)
14833 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
14836 loc
= sreloc
->contents
;
14837 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
14838 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14840 /* If this reloc is against an external symbol, it will
14841 be computed at runtime, so there's no need to do
14842 anything now. However, for the sake of prelink ensure
14843 that the section contents are a known value. */
14846 unresolved_reloc
= FALSE
;
14847 /* The value chosen here is quite arbitrary as ld.so
14848 ignores section contents except for the special
14849 case of .opd where the contents might be accessed
14850 before relocation. Choose zero, as that won't
14851 cause reloc overflow. */
14854 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
14855 to improve backward compatibility with older
14857 if (r_type
== R_PPC64_ADDR64
)
14858 addend
= outrel
.r_addend
;
14859 /* Adjust pc_relative relocs to have zero in *r_offset. */
14860 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
14861 addend
= outrel
.r_offset
;
14867 case R_PPC64_GLOB_DAT
:
14868 case R_PPC64_JMP_SLOT
:
14869 case R_PPC64_JMP_IREL
:
14870 case R_PPC64_RELATIVE
:
14871 /* We shouldn't ever see these dynamic relocs in relocatable
14873 /* Fall through. */
14875 case R_PPC64_PLTGOT16
:
14876 case R_PPC64_PLTGOT16_DS
:
14877 case R_PPC64_PLTGOT16_HA
:
14878 case R_PPC64_PLTGOT16_HI
:
14879 case R_PPC64_PLTGOT16_LO
:
14880 case R_PPC64_PLTGOT16_LO_DS
:
14881 case R_PPC64_PLTREL32
:
14882 case R_PPC64_PLTREL64
:
14883 /* These ones haven't been implemented yet. */
14885 info
->callbacks
->einfo
14886 /* xgettext:c-format */
14887 (_("%P: %pB: %s is not supported for `%pT'\n"),
14889 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
14891 bfd_set_error (bfd_error_invalid_operation
);
14896 /* Multi-instruction sequences that access the TOC can be
14897 optimized, eg. addis ra,r2,0; addi rb,ra,x;
14898 to nop; addi rb,r2,x; */
14904 case R_PPC64_GOT_TLSLD16_HI
:
14905 case R_PPC64_GOT_TLSGD16_HI
:
14906 case R_PPC64_GOT_TPREL16_HI
:
14907 case R_PPC64_GOT_DTPREL16_HI
:
14908 case R_PPC64_GOT16_HI
:
14909 case R_PPC64_TOC16_HI
:
14910 /* These relocs would only be useful if building up an
14911 offset to later add to r2, perhaps in an indexed
14912 addressing mode instruction. Don't try to optimize.
14913 Unfortunately, the possibility of someone building up an
14914 offset like this or even with the HA relocs, means that
14915 we need to check the high insn when optimizing the low
14919 case R_PPC64_PLTCALL
:
14920 if (unresolved_reloc
)
14922 /* No plt entry. Make this into a direct call. */
14923 bfd_byte
*p
= contents
+ rel
->r_offset
;
14924 insn
= bfd_get_32 (input_bfd
, p
);
14926 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
14927 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
14928 unresolved_reloc
= save_unresolved_reloc
;
14929 r_type
= R_PPC64_REL24
;
14933 case R_PPC64_PLTSEQ
:
14934 if (unresolved_reloc
)
14936 unresolved_reloc
= FALSE
;
14941 case R_PPC64_PLT16_HA
:
14942 if (unresolved_reloc
)
14944 unresolved_reloc
= FALSE
;
14947 /* Fall through. */
14948 case R_PPC64_GOT_TLSLD16_HA
:
14949 case R_PPC64_GOT_TLSGD16_HA
:
14950 case R_PPC64_GOT_TPREL16_HA
:
14951 case R_PPC64_GOT_DTPREL16_HA
:
14952 case R_PPC64_GOT16_HA
:
14953 case R_PPC64_TOC16_HA
:
14954 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
14955 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
14959 p
= contents
+ (rel
->r_offset
& ~3);
14960 bfd_put_32 (input_bfd
, NOP
, p
);
14965 case R_PPC64_PLT16_LO
:
14966 case R_PPC64_PLT16_LO_DS
:
14967 if (unresolved_reloc
)
14969 unresolved_reloc
= FALSE
;
14972 /* Fall through. */
14973 case R_PPC64_GOT_TLSLD16_LO
:
14974 case R_PPC64_GOT_TLSGD16_LO
:
14975 case R_PPC64_GOT_TPREL16_LO_DS
:
14976 case R_PPC64_GOT_DTPREL16_LO_DS
:
14977 case R_PPC64_GOT16_LO
:
14978 case R_PPC64_GOT16_LO_DS
:
14979 case R_PPC64_TOC16_LO
:
14980 case R_PPC64_TOC16_LO_DS
:
14981 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
14982 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
14984 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
14985 insn
= bfd_get_32 (input_bfd
, p
);
14986 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
14988 /* Transform addic to addi when we change reg. */
14989 insn
&= ~((0x3f << 26) | (0x1f << 16));
14990 insn
|= (14u << 26) | (2 << 16);
14994 insn
&= ~(0x1f << 16);
14997 bfd_put_32 (input_bfd
, insn
, p
);
15001 case R_PPC64_TPREL16_HA
:
15002 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15004 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15005 insn
= bfd_get_32 (input_bfd
, p
);
15006 if ((insn
& ((0x3f << 26) | 0x1f << 16))
15007 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15008 /* xgettext:c-format */
15009 info
->callbacks
->minfo
15010 (_("%H: warning: %s unexpected insn %#x.\n"),
15011 input_bfd
, input_section
, rel
->r_offset
,
15012 ppc64_elf_howto_table
[r_type
]->name
, insn
);
15015 bfd_put_32 (input_bfd
, NOP
, p
);
15021 case R_PPC64_TPREL16_LO
:
15022 case R_PPC64_TPREL16_LO_DS
:
15023 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15025 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15026 insn
= bfd_get_32 (input_bfd
, p
);
15027 insn
&= ~(0x1f << 16);
15029 bfd_put_32 (input_bfd
, insn
, p
);
15034 /* Do any further special processing. */
15040 case R_PPC64_REL16_HA
:
15041 case R_PPC64_REL16DX_HA
:
15042 case R_PPC64_ADDR16_HA
:
15043 case R_PPC64_ADDR16_HIGHA
:
15044 case R_PPC64_ADDR16_HIGHERA
:
15045 case R_PPC64_ADDR16_HIGHESTA
:
15046 case R_PPC64_TOC16_HA
:
15047 case R_PPC64_SECTOFF_HA
:
15048 case R_PPC64_TPREL16_HA
:
15049 case R_PPC64_TPREL16_HIGHA
:
15050 case R_PPC64_TPREL16_HIGHERA
:
15051 case R_PPC64_TPREL16_HIGHESTA
:
15052 case R_PPC64_DTPREL16_HA
:
15053 case R_PPC64_DTPREL16_HIGHA
:
15054 case R_PPC64_DTPREL16_HIGHERA
:
15055 case R_PPC64_DTPREL16_HIGHESTA
:
15056 /* It's just possible that this symbol is a weak symbol
15057 that's not actually defined anywhere. In that case,
15058 'sec' would be NULL, and we should leave the symbol
15059 alone (it will be set to zero elsewhere in the link). */
15062 /* Fall through. */
15064 case R_PPC64_GOT16_HA
:
15065 case R_PPC64_PLTGOT16_HA
:
15066 case R_PPC64_PLT16_HA
:
15067 case R_PPC64_GOT_TLSGD16_HA
:
15068 case R_PPC64_GOT_TLSLD16_HA
:
15069 case R_PPC64_GOT_TPREL16_HA
:
15070 case R_PPC64_GOT_DTPREL16_HA
:
15071 /* Add 0x10000 if sign bit in 0:15 is set.
15072 Bits 0:15 are not used. */
15076 case R_PPC64_ADDR16_DS
:
15077 case R_PPC64_ADDR16_LO_DS
:
15078 case R_PPC64_GOT16_DS
:
15079 case R_PPC64_GOT16_LO_DS
:
15080 case R_PPC64_PLT16_LO_DS
:
15081 case R_PPC64_SECTOFF_DS
:
15082 case R_PPC64_SECTOFF_LO_DS
:
15083 case R_PPC64_TOC16_DS
:
15084 case R_PPC64_TOC16_LO_DS
:
15085 case R_PPC64_PLTGOT16_DS
:
15086 case R_PPC64_PLTGOT16_LO_DS
:
15087 case R_PPC64_GOT_TPREL16_DS
:
15088 case R_PPC64_GOT_TPREL16_LO_DS
:
15089 case R_PPC64_GOT_DTPREL16_DS
:
15090 case R_PPC64_GOT_DTPREL16_LO_DS
:
15091 case R_PPC64_TPREL16_DS
:
15092 case R_PPC64_TPREL16_LO_DS
:
15093 case R_PPC64_DTPREL16_DS
:
15094 case R_PPC64_DTPREL16_LO_DS
:
15095 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15097 /* If this reloc is against an lq, lxv, or stxv insn, then
15098 the value must be a multiple of 16. This is somewhat of
15099 a hack, but the "correct" way to do this by defining _DQ
15100 forms of all the _DS relocs bloats all reloc switches in
15101 this file. It doesn't make much sense to use these
15102 relocs in data, so testing the insn should be safe. */
15103 if ((insn
& (0x3f << 26)) == (56u << 26)
15104 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15106 relocation
+= addend
;
15107 addend
= insn
& (mask
^ 3);
15108 if ((relocation
& mask
) != 0)
15110 relocation
^= relocation
& mask
;
15111 info
->callbacks
->einfo
15112 /* xgettext:c-format */
15113 (_("%H: error: %s not a multiple of %u\n"),
15114 input_bfd
, input_section
, rel
->r_offset
,
15115 ppc64_elf_howto_table
[r_type
]->name
,
15117 bfd_set_error (bfd_error_bad_value
);
15124 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15125 because such sections are not SEC_ALLOC and thus ld.so will
15126 not process them. */
15127 howto
= ppc64_elf_howto_table
[(int) r_type
];
15128 if (unresolved_reloc
15129 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15130 && h
->elf
.def_dynamic
)
15131 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15132 rel
->r_offset
) != (bfd_vma
) -1)
15134 info
->callbacks
->einfo
15135 /* xgettext:c-format */
15136 (_("%H: unresolvable %s against `%pT'\n"),
15137 input_bfd
, input_section
, rel
->r_offset
,
15139 h
->elf
.root
.root
.string
);
15143 /* 16-bit fields in insns mostly have signed values, but a
15144 few insns have 16-bit unsigned values. Really, we should
15145 have different reloc types. */
15146 if (howto
->complain_on_overflow
!= complain_overflow_dont
15147 && howto
->dst_mask
== 0xffff
15148 && (input_section
->flags
& SEC_CODE
) != 0)
15150 enum complain_overflow complain
= complain_overflow_signed
;
15152 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15153 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15154 complain
= complain_overflow_bitfield
;
15155 else if (howto
->rightshift
== 0
15156 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15157 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15158 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15159 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15160 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15161 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15162 complain
= complain_overflow_unsigned
;
15163 if (howto
->complain_on_overflow
!= complain
)
15165 alt_howto
= *howto
;
15166 alt_howto
.complain_on_overflow
= complain
;
15167 howto
= &alt_howto
;
15171 if (r_type
== R_PPC64_REL16DX_HA
)
15173 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15174 if (rel
->r_offset
+ 4 > input_section
->size
)
15175 r
= bfd_reloc_outofrange
;
15178 relocation
+= addend
;
15179 relocation
-= (rel
->r_offset
15180 + input_section
->output_offset
15181 + input_section
->output_section
->vma
);
15182 relocation
= (bfd_signed_vma
) relocation
>> 16;
15183 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15185 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15186 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15188 if (relocation
+ 0x8000 > 0xffff)
15189 r
= bfd_reloc_overflow
;
15193 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15194 rel
->r_offset
, relocation
, addend
);
15196 if (r
!= bfd_reloc_ok
)
15198 char *more_info
= NULL
;
15199 const char *reloc_name
= howto
->name
;
15201 if (reloc_dest
!= DEST_NORMAL
)
15203 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15204 if (more_info
!= NULL
)
15206 strcpy (more_info
, reloc_name
);
15207 strcat (more_info
, (reloc_dest
== DEST_OPD
15208 ? " (OPD)" : " (stub)"));
15209 reloc_name
= more_info
;
15213 if (r
== bfd_reloc_overflow
)
15215 /* On code like "if (foo) foo();" don't report overflow
15216 on a branch to zero when foo is undefined. */
15218 && (reloc_dest
== DEST_STUB
15220 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15221 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15222 && is_branch_reloc (r_type
))))
15223 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15224 sym_name
, reloc_name
,
15226 input_bfd
, input_section
,
15231 info
->callbacks
->einfo
15232 /* xgettext:c-format */
15233 (_("%H: %s against `%pT': error %d\n"),
15234 input_bfd
, input_section
, rel
->r_offset
,
15235 reloc_name
, sym_name
, (int) r
);
15238 if (more_info
!= NULL
)
15248 Elf_Internal_Shdr
*rel_hdr
;
15249 size_t deleted
= rel
- wrel
;
15251 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15252 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15253 if (rel_hdr
->sh_size
== 0)
15255 /* It is too late to remove an empty reloc section. Leave
15257 ??? What is wrong with an empty section??? */
15258 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15261 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15262 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15263 input_section
->reloc_count
-= deleted
;
15266 /* If we're emitting relocations, then shortly after this function
15267 returns, reloc offsets and addends for this section will be
15268 adjusted. Worse, reloc symbol indices will be for the output
15269 file rather than the input. Save a copy of the relocs for
15270 opd_entry_value. */
15271 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15274 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15275 rel
= bfd_alloc (input_bfd
, amt
);
15276 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15277 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15280 memcpy (rel
, relocs
, amt
);
15285 /* Adjust the value of any local symbols in opd sections. */
15288 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15289 const char *name ATTRIBUTE_UNUSED
,
15290 Elf_Internal_Sym
*elfsym
,
15291 asection
*input_sec
,
15292 struct elf_link_hash_entry
*h
)
15294 struct _opd_sec_data
*opd
;
15301 opd
= get_opd_info (input_sec
);
15302 if (opd
== NULL
|| opd
->adjust
== NULL
)
15305 value
= elfsym
->st_value
- input_sec
->output_offset
;
15306 if (!bfd_link_relocatable (info
))
15307 value
-= input_sec
->output_section
->vma
;
15309 adjust
= opd
->adjust
[OPD_NDX (value
)];
15313 elfsym
->st_value
+= adjust
;
15317 /* Finish up dynamic symbol handling. We set the contents of various
15318 dynamic sections here. */
15321 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15322 struct bfd_link_info
*info
,
15323 struct elf_link_hash_entry
*h
,
15324 Elf_Internal_Sym
*sym
)
15326 struct ppc_link_hash_table
*htab
;
15327 struct plt_entry
*ent
;
15329 htab
= ppc_hash_table (info
);
15333 if (!htab
->opd_abi
&& !h
->def_regular
)
15334 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15335 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15337 /* Mark the symbol as undefined, rather than as
15338 defined in glink. Leave the value if there were
15339 any relocations where pointer equality matters
15340 (this is a clue for the dynamic linker, to make
15341 function pointer comparisons work between an
15342 application and shared library), otherwise set it
15344 sym
->st_shndx
= SHN_UNDEF
;
15345 if (!h
->pointer_equality_needed
)
15347 else if (!h
->ref_regular_nonweak
)
15349 /* This breaks function pointer comparisons, but
15350 that is better than breaking tests for a NULL
15351 function pointer. */
15359 /* This symbol needs a copy reloc. Set it up. */
15360 Elf_Internal_Rela rela
;
15364 if (h
->dynindx
== -1
15365 || (h
->root
.type
!= bfd_link_hash_defined
15366 && h
->root
.type
!= bfd_link_hash_defweak
)
15367 || htab
->elf
.srelbss
== NULL
15368 || htab
->elf
.sreldynrelro
== NULL
)
15371 rela
.r_offset
= (h
->root
.u
.def
.value
15372 + h
->root
.u
.def
.section
->output_section
->vma
15373 + h
->root
.u
.def
.section
->output_offset
);
15374 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15376 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
15377 srel
= htab
->elf
.sreldynrelro
;
15379 srel
= htab
->elf
.srelbss
;
15380 loc
= srel
->contents
;
15381 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15382 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15388 /* Used to decide how to sort relocs in an optimal manner for the
15389 dynamic linker, before writing them out. */
15391 static enum elf_reloc_type_class
15392 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15393 const asection
*rel_sec
,
15394 const Elf_Internal_Rela
*rela
)
15396 enum elf_ppc64_reloc_type r_type
;
15397 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15399 if (rel_sec
== htab
->elf
.irelplt
)
15400 return reloc_class_ifunc
;
15402 r_type
= ELF64_R_TYPE (rela
->r_info
);
15405 case R_PPC64_RELATIVE
:
15406 return reloc_class_relative
;
15407 case R_PPC64_JMP_SLOT
:
15408 return reloc_class_plt
;
15410 return reloc_class_copy
;
15412 return reloc_class_normal
;
15416 /* Finish up the dynamic sections. */
15419 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15420 struct bfd_link_info
*info
)
15422 struct ppc_link_hash_table
*htab
;
15426 htab
= ppc_hash_table (info
);
15430 dynobj
= htab
->elf
.dynobj
;
15431 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15433 if (htab
->elf
.dynamic_sections_created
)
15435 Elf64_External_Dyn
*dyncon
, *dynconend
;
15437 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15440 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15441 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15442 for (; dyncon
< dynconend
; dyncon
++)
15444 Elf_Internal_Dyn dyn
;
15447 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
15454 case DT_PPC64_GLINK
:
15456 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15457 /* We stupidly defined DT_PPC64_GLINK to be the start
15458 of glink rather than the first entry point, which is
15459 what ld.so needs, and now have a bigger stub to
15460 support automatic multiple TOCs. */
15461 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
15465 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15468 dyn
.d_un
.d_ptr
= s
->vma
;
15472 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
15473 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
15474 if (htab
->has_plt_localentry0
)
15475 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
15478 case DT_PPC64_OPDSZ
:
15479 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15482 dyn
.d_un
.d_val
= s
->size
;
15486 s
= htab
->elf
.splt
;
15487 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15491 s
= htab
->elf
.srelplt
;
15492 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15496 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
15500 if (htab
->local_ifunc_resolver
)
15501 info
->callbacks
->einfo
15502 (_("%X%P: text relocations and GNU indirect "
15503 "functions will result in a segfault at runtime\n"));
15504 else if (htab
->maybe_local_ifunc_resolver
)
15505 info
->callbacks
->einfo
15506 (_("%P: warning: text relocations and GNU indirect "
15507 "functions may result in a segfault at runtime\n"));
15511 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
15515 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
15516 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
15518 /* Fill in the first entry in the global offset table.
15519 We use it to hold the link-time TOCbase. */
15520 bfd_put_64 (output_bfd
,
15521 elf_gp (output_bfd
) + TOC_BASE_OFF
,
15522 htab
->elf
.sgot
->contents
);
15524 /* Set .got entry size. */
15525 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
15529 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
15530 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
15532 /* Set .plt entry size. */
15533 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
15534 = PLT_ENTRY_SIZE (htab
);
15537 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15538 brlt ourselves if emitrelocations. */
15539 if (htab
->brlt
!= NULL
15540 && htab
->brlt
->reloc_count
!= 0
15541 && !_bfd_elf_link_output_relocs (output_bfd
,
15543 elf_section_data (htab
->brlt
)->rela
.hdr
,
15544 elf_section_data (htab
->brlt
)->relocs
,
15548 if (htab
->glink
!= NULL
15549 && htab
->glink
->reloc_count
!= 0
15550 && !_bfd_elf_link_output_relocs (output_bfd
,
15552 elf_section_data (htab
->glink
)->rela
.hdr
,
15553 elf_section_data (htab
->glink
)->relocs
,
15558 if (htab
->glink_eh_frame
!= NULL
15559 && htab
->glink_eh_frame
->size
!= 0
15560 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
15561 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
15562 htab
->glink_eh_frame
,
15563 htab
->glink_eh_frame
->contents
))
15566 /* We need to handle writing out multiple GOT sections ourselves,
15567 since we didn't add them to DYNOBJ. We know dynobj is the first
15569 while ((dynobj
= dynobj
->link
.next
) != NULL
)
15573 if (!is_ppc64_elf (dynobj
))
15576 s
= ppc64_elf_tdata (dynobj
)->got
;
15579 && s
->output_section
!= bfd_abs_section_ptr
15580 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15581 s
->contents
, s
->output_offset
,
15584 s
= ppc64_elf_tdata (dynobj
)->relgot
;
15587 && s
->output_section
!= bfd_abs_section_ptr
15588 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15589 s
->contents
, s
->output_offset
,
15597 #include "elf64-target.h"
15599 /* FreeBSD support */
15601 #undef TARGET_LITTLE_SYM
15602 #undef TARGET_LITTLE_NAME
15604 #undef TARGET_BIG_SYM
15605 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
15606 #undef TARGET_BIG_NAME
15607 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
15610 #define ELF_OSABI ELFOSABI_FREEBSD
15613 #define elf64_bed elf64_powerpc_fbsd_bed
15615 #include "elf64-target.h"