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 HOW (R_PPC64_REL16_HIGH
, 1, 16, 0xffff, 16, TRUE
, dont
,
824 bfd_elf_generic_reloc
),
826 HOW (R_PPC64_REL16_HIGHA
, 1, 16, 0xffff, 16, TRUE
, dont
,
829 HOW (R_PPC64_REL16_HIGHER
, 1, 16, 0xffff, 32, TRUE
, dont
,
830 bfd_elf_generic_reloc
),
832 HOW (R_PPC64_REL16_HIGHERA
, 1, 16, 0xffff, 32, TRUE
, dont
,
835 HOW (R_PPC64_REL16_HIGHEST
, 1, 16, 0xffff, 48, TRUE
, dont
,
836 bfd_elf_generic_reloc
),
838 HOW (R_PPC64_REL16_HIGHESTA
, 1, 16, 0xffff, 48, TRUE
, dont
,
841 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
842 HOW (R_PPC64_REL16DX_HA
, 2, 16, 0x1fffc1, 16, TRUE
, signed,
845 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
846 HOW (R_PPC64_16DX_HA
, 2, 16, 0x1fffc1, 16, FALSE
, signed,
849 /* Like R_PPC64_ADDR16_HI, but no overflow. */
850 HOW (R_PPC64_ADDR16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
851 bfd_elf_generic_reloc
),
853 /* Like R_PPC64_ADDR16_HA, but no overflow. */
854 HOW (R_PPC64_ADDR16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
857 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
858 HOW (R_PPC64_DTPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
859 ppc64_elf_unhandled_reloc
),
861 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
862 HOW (R_PPC64_DTPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
863 ppc64_elf_unhandled_reloc
),
865 /* Like R_PPC64_TPREL16_HI, but no overflow. */
866 HOW (R_PPC64_TPREL16_HIGH
, 1, 16, 0xffff, 16, FALSE
, dont
,
867 ppc64_elf_unhandled_reloc
),
869 /* Like R_PPC64_TPREL16_HA, but no overflow. */
870 HOW (R_PPC64_TPREL16_HIGHA
, 1, 16, 0xffff, 16, FALSE
, dont
,
871 ppc64_elf_unhandled_reloc
),
873 /* Marker reloc on ELFv2 large-model function entry. */
874 HOW (R_PPC64_ENTRY
, 2, 32, 0, 0, FALSE
, dont
,
875 bfd_elf_generic_reloc
),
877 /* Like ADDR64, but use local entry point of function. */
878 HOW (R_PPC64_ADDR64_LOCAL
, 4, 64, 0xffffffffffffffffULL
, 0, FALSE
, dont
,
879 bfd_elf_generic_reloc
),
881 /* GNU extension to record C++ vtable hierarchy. */
882 HOW (R_PPC64_GNU_VTINHERIT
, 0, 0, 0, 0, FALSE
, dont
,
885 /* GNU extension to record C++ vtable member usage. */
886 HOW (R_PPC64_GNU_VTENTRY
, 0, 0, 0, 0, FALSE
, dont
,
891 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
895 ppc_howto_init (void)
897 unsigned int i
, type
;
899 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
901 type
= ppc64_elf_howto_raw
[i
].type
;
902 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
903 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
907 static reloc_howto_type
*
908 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
909 bfd_reloc_code_real_type code
)
911 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
913 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
914 /* Initialize howto table if needed. */
920 /* xgettext:c-format */
921 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
,
923 bfd_set_error (bfd_error_bad_value
);
926 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
928 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
930 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
932 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
934 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
936 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
938 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
940 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
942 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
944 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
946 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
948 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
950 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
952 case BFD_RELOC_PPC64_REL24_NOTOC
: r
= R_PPC64_REL24_NOTOC
;
954 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
956 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
958 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
960 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
962 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
964 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
966 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
968 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
970 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
972 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
974 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
976 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
978 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
980 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
982 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
984 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
986 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
988 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
990 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
992 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
994 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
996 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
998 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1000 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1002 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1004 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1006 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1008 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1010 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1012 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1014 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1016 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1018 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1020 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1022 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1024 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1026 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1028 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1030 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1032 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1034 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1036 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1038 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1040 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1042 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1044 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1046 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
1048 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
1050 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
1052 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
1054 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
1056 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
1058 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
1060 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
1062 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
1064 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
1066 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
1068 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
1070 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
1072 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
1074 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
1076 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
1078 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
1080 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
1082 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
1084 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
1086 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
1088 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
1090 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
1092 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
1094 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
1096 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
1098 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
1100 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
1102 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
1104 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
1106 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
1108 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
1110 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
1112 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
1114 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
1116 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
1118 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
1120 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
1122 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
1124 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
1126 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
1128 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
1130 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
1132 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
1134 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
1136 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
1138 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
1140 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
1142 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
1144 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
1146 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
1148 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
1150 case BFD_RELOC_PPC64_REL16_HIGH
: r
= R_PPC64_REL16_HIGH
;
1152 case BFD_RELOC_PPC64_REL16_HIGHA
: r
= R_PPC64_REL16_HIGHA
;
1154 case BFD_RELOC_PPC64_REL16_HIGHER
: r
= R_PPC64_REL16_HIGHER
;
1156 case BFD_RELOC_PPC64_REL16_HIGHERA
: r
= R_PPC64_REL16_HIGHERA
;
1158 case BFD_RELOC_PPC64_REL16_HIGHEST
: r
= R_PPC64_REL16_HIGHEST
;
1160 case BFD_RELOC_PPC64_REL16_HIGHESTA
: r
= R_PPC64_REL16_HIGHESTA
;
1162 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
1164 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
1166 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
1168 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
1170 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
1172 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
1176 return ppc64_elf_howto_table
[r
];
1179 static reloc_howto_type
*
1180 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1185 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
1186 if (ppc64_elf_howto_raw
[i
].name
!= NULL
1187 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
1188 return &ppc64_elf_howto_raw
[i
];
1193 /* Set the howto pointer for a PowerPC ELF reloc. */
1196 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
1197 Elf_Internal_Rela
*dst
)
1201 /* Initialize howto table if needed. */
1202 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1205 type
= ELF64_R_TYPE (dst
->r_info
);
1206 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
1208 /* xgettext:c-format */
1209 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1211 bfd_set_error (bfd_error_bad_value
);
1214 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1215 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
1217 /* xgettext:c-format */
1218 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
1220 bfd_set_error (bfd_error_bad_value
);
1227 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
1229 static bfd_reloc_status_type
1230 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1231 void *data
, asection
*input_section
,
1232 bfd
*output_bfd
, char **error_message
)
1234 enum elf_ppc64_reloc_type r_type
;
1236 bfd_size_type octets
;
1239 /* If this is a relocatable link (output_bfd test tells us), just
1240 call the generic function. Any adjustment will be done at final
1242 if (output_bfd
!= NULL
)
1243 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1244 input_section
, output_bfd
, error_message
);
1246 /* Adjust the addend for sign extension of the low 16 bits.
1247 We won't actually be using the low 16 bits, so trashing them
1249 reloc_entry
->addend
+= 0x8000;
1250 r_type
= reloc_entry
->howto
->type
;
1251 if (r_type
!= R_PPC64_REL16DX_HA
)
1252 return bfd_reloc_continue
;
1255 if (!bfd_is_com_section (symbol
->section
))
1256 value
= symbol
->value
;
1257 value
+= (reloc_entry
->addend
1258 + symbol
->section
->output_offset
1259 + symbol
->section
->output_section
->vma
);
1260 value
-= (reloc_entry
->address
1261 + input_section
->output_offset
1262 + input_section
->output_section
->vma
);
1263 value
= (bfd_signed_vma
) value
>> 16;
1265 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1266 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1268 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
1269 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1270 if (value
+ 0x8000 > 0xffff)
1271 return bfd_reloc_overflow
;
1272 return bfd_reloc_ok
;
1275 static bfd_reloc_status_type
1276 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1277 void *data
, asection
*input_section
,
1278 bfd
*output_bfd
, char **error_message
)
1280 if (output_bfd
!= NULL
)
1281 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1282 input_section
, output_bfd
, error_message
);
1284 if (strcmp (symbol
->section
->name
, ".opd") == 0
1285 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
1287 bfd_vma dest
= opd_entry_value (symbol
->section
,
1288 symbol
->value
+ reloc_entry
->addend
,
1290 if (dest
!= (bfd_vma
) -1)
1291 reloc_entry
->addend
= dest
- (symbol
->value
1292 + symbol
->section
->output_section
->vma
1293 + symbol
->section
->output_offset
);
1297 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
1299 if (symbol
->section
->owner
!= abfd
1300 && symbol
->section
->owner
!= NULL
1301 && abiversion (symbol
->section
->owner
) >= 2)
1305 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
1307 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
1309 if (strcmp (symdef
->name
, symbol
->name
) == 0)
1311 elfsym
= (elf_symbol_type
*) symdef
;
1317 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
1319 return bfd_reloc_continue
;
1322 static bfd_reloc_status_type
1323 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1324 void *data
, asection
*input_section
,
1325 bfd
*output_bfd
, char **error_message
)
1328 enum elf_ppc64_reloc_type r_type
;
1329 bfd_size_type octets
;
1330 /* Assume 'at' branch hints. */
1331 bfd_boolean is_isa_v2
= TRUE
;
1333 /* If this is a relocatable link (output_bfd test tells us), just
1334 call the generic function. Any adjustment will be done at final
1336 if (output_bfd
!= NULL
)
1337 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1338 input_section
, output_bfd
, error_message
);
1340 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1341 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
1342 insn
&= ~(0x01 << 21);
1343 r_type
= reloc_entry
->howto
->type
;
1344 if (r_type
== R_PPC64_ADDR14_BRTAKEN
1345 || r_type
== R_PPC64_REL14_BRTAKEN
)
1346 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1350 /* Set 'a' bit. This is 0b00010 in BO field for branch
1351 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1352 for branch on CTR insns (BO == 1a00t or 1a01t). */
1353 if ((insn
& (0x14 << 21)) == (0x04 << 21))
1355 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
1365 if (!bfd_is_com_section (symbol
->section
))
1366 target
= symbol
->value
;
1367 target
+= symbol
->section
->output_section
->vma
;
1368 target
+= symbol
->section
->output_offset
;
1369 target
+= reloc_entry
->addend
;
1371 from
= (reloc_entry
->address
1372 + input_section
->output_offset
1373 + input_section
->output_section
->vma
);
1375 /* Invert 'y' bit if not the default. */
1376 if ((bfd_signed_vma
) (target
- from
) < 0)
1379 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
1381 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
1382 input_section
, output_bfd
, error_message
);
1385 static bfd_reloc_status_type
1386 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1387 void *data
, asection
*input_section
,
1388 bfd
*output_bfd
, char **error_message
)
1390 /* If this is a relocatable link (output_bfd test tells us), just
1391 call the generic function. Any adjustment will be done at final
1393 if (output_bfd
!= NULL
)
1394 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1395 input_section
, output_bfd
, error_message
);
1397 /* Subtract the symbol section base address. */
1398 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1399 return bfd_reloc_continue
;
1402 static bfd_reloc_status_type
1403 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1404 void *data
, asection
*input_section
,
1405 bfd
*output_bfd
, char **error_message
)
1407 /* If this is a relocatable link (output_bfd test tells us), just
1408 call the generic function. Any adjustment will be done at final
1410 if (output_bfd
!= NULL
)
1411 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1412 input_section
, output_bfd
, error_message
);
1414 /* Subtract the symbol section base address. */
1415 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
1417 /* Adjust the addend for sign extension of the low 16 bits. */
1418 reloc_entry
->addend
+= 0x8000;
1419 return bfd_reloc_continue
;
1422 static bfd_reloc_status_type
1423 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1424 void *data
, asection
*input_section
,
1425 bfd
*output_bfd
, char **error_message
)
1429 /* If this is a relocatable link (output_bfd test tells us), just
1430 call the generic function. Any adjustment will be done at final
1432 if (output_bfd
!= NULL
)
1433 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1434 input_section
, output_bfd
, error_message
);
1436 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1438 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1440 /* Subtract the TOC base address. */
1441 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1442 return bfd_reloc_continue
;
1445 static bfd_reloc_status_type
1446 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1447 void *data
, asection
*input_section
,
1448 bfd
*output_bfd
, char **error_message
)
1452 /* If this is a relocatable link (output_bfd test tells us), just
1453 call the generic function. Any adjustment will be done at final
1455 if (output_bfd
!= NULL
)
1456 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1457 input_section
, output_bfd
, error_message
);
1459 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1461 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1463 /* Subtract the TOC base address. */
1464 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
1466 /* Adjust the addend for sign extension of the low 16 bits. */
1467 reloc_entry
->addend
+= 0x8000;
1468 return bfd_reloc_continue
;
1471 static bfd_reloc_status_type
1472 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1473 void *data
, asection
*input_section
,
1474 bfd
*output_bfd
, char **error_message
)
1477 bfd_size_type octets
;
1479 /* If this is a relocatable link (output_bfd test tells us), just
1480 call the generic function. Any adjustment will be done at final
1482 if (output_bfd
!= NULL
)
1483 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1484 input_section
, output_bfd
, error_message
);
1486 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
1488 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
1490 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
1491 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
1492 return bfd_reloc_ok
;
1495 static bfd_reloc_status_type
1496 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
1497 void *data
, asection
*input_section
,
1498 bfd
*output_bfd
, char **error_message
)
1500 /* If this is a relocatable link (output_bfd test tells us), just
1501 call the generic function. Any adjustment will be done at final
1503 if (output_bfd
!= NULL
)
1504 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1505 input_section
, output_bfd
, error_message
);
1507 if (error_message
!= NULL
)
1509 static char buf
[60];
1510 sprintf (buf
, "generic linker can't handle %s",
1511 reloc_entry
->howto
->name
);
1512 *error_message
= buf
;
1514 return bfd_reloc_dangerous
;
1517 /* Track GOT entries needed for a given symbol. We might need more
1518 than one got entry per symbol. */
1521 struct got_entry
*next
;
1523 /* The symbol addend that we'll be placing in the GOT. */
1526 /* Unlike other ELF targets, we use separate GOT entries for the same
1527 symbol referenced from different input files. This is to support
1528 automatic multiple TOC/GOT sections, where the TOC base can vary
1529 from one input file to another. After partitioning into TOC groups
1530 we merge entries within the group.
1532 Point to the BFD owning this GOT entry. */
1535 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
1536 TLS_TPREL or TLS_DTPREL for tls entries. */
1537 unsigned char tls_type
;
1539 /* Non-zero if got.ent points to real entry. */
1540 unsigned char is_indirect
;
1542 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
1545 bfd_signed_vma refcount
;
1547 struct got_entry
*ent
;
1551 /* The same for PLT. */
1554 struct plt_entry
*next
;
1560 bfd_signed_vma refcount
;
1565 struct ppc64_elf_obj_tdata
1567 struct elf_obj_tdata elf
;
1569 /* Shortcuts to dynamic linker sections. */
1573 /* Used during garbage collection. We attach global symbols defined
1574 on removed .opd entries to this section so that the sym is removed. */
1575 asection
*deleted_section
;
1577 /* TLS local dynamic got entry handling. Support for multiple GOT
1578 sections means we potentially need one of these for each input bfd. */
1579 struct got_entry tlsld_got
;
1583 /* A copy of relocs before they are modified for --emit-relocs. */
1584 Elf_Internal_Rela
*relocs
;
1586 /* Section contents. */
1590 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
1591 the reloc to be in the range -32768 to 32767. */
1592 unsigned int has_small_toc_reloc
: 1;
1594 /* Set if toc/got ha relocs detected not using r2, or lo reloc
1595 instruction not one we handle. */
1596 unsigned int unexpected_toc_insn
: 1;
1599 #define ppc64_elf_tdata(bfd) \
1600 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
1602 #define ppc64_tlsld_got(bfd) \
1603 (&ppc64_elf_tdata (bfd)->tlsld_got)
1605 #define is_ppc64_elf(bfd) \
1606 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1607 && elf_object_id (bfd) == PPC64_ELF_DATA)
1609 /* Override the generic function because we store some extras. */
1612 ppc64_elf_mkobject (bfd
*abfd
)
1614 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
1618 /* Fix bad default arch selected for a 64 bit input bfd when the
1619 default is 32 bit. Also select arch based on apuinfo. */
1622 ppc64_elf_object_p (bfd
*abfd
)
1624 if (!abfd
->arch_info
->the_default
)
1627 if (abfd
->arch_info
->bits_per_word
== 32)
1629 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1631 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
1633 /* Relies on arch after 32 bit default being 64 bit default. */
1634 abfd
->arch_info
= abfd
->arch_info
->next
;
1635 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
1638 return _bfd_elf_ppc_set_arch (abfd
);
1641 /* Support for core dump NOTE sections. */
1644 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1646 size_t offset
, size
;
1648 if (note
->descsz
!= 504)
1652 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1655 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
1661 /* Make a ".reg/999" section. */
1662 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1663 size
, note
->descpos
+ offset
);
1667 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1669 if (note
->descsz
!= 136)
1672 elf_tdata (abfd
)->core
->pid
1673 = bfd_get_32 (abfd
, note
->descdata
+ 24);
1674 elf_tdata (abfd
)->core
->program
1675 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
1676 elf_tdata (abfd
)->core
->command
1677 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
1683 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
1693 char data
[136] ATTRIBUTE_NONSTRING
;
1696 va_start (ap
, note_type
);
1697 memset (data
, 0, sizeof (data
));
1698 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
1699 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1701 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1702 -Wstringop-truncation:
1703 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1705 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1707 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
1708 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1712 return elfcore_write_note (abfd
, buf
, bufsiz
,
1713 "CORE", note_type
, data
, sizeof (data
));
1724 va_start (ap
, note_type
);
1725 memset (data
, 0, 112);
1726 pid
= va_arg (ap
, long);
1727 bfd_put_32 (abfd
, pid
, data
+ 32);
1728 cursig
= va_arg (ap
, int);
1729 bfd_put_16 (abfd
, cursig
, data
+ 12);
1730 greg
= va_arg (ap
, const void *);
1731 memcpy (data
+ 112, greg
, 384);
1732 memset (data
+ 496, 0, 8);
1734 return elfcore_write_note (abfd
, buf
, bufsiz
,
1735 "CORE", note_type
, data
, sizeof (data
));
1740 /* Add extra PPC sections. */
1742 static const struct bfd_elf_special_section ppc64_elf_special_sections
[] =
1744 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
1745 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1746 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1747 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1748 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1749 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1750 { NULL
, 0, 0, 0, 0 }
1753 enum _ppc64_sec_type
{
1759 struct _ppc64_elf_section_data
1761 struct bfd_elf_section_data elf
;
1765 /* An array with one entry for each opd function descriptor,
1766 and some spares since opd entries may be either 16 or 24 bytes. */
1767 #define OPD_NDX(OFF) ((OFF) >> 4)
1768 struct _opd_sec_data
1770 /* Points to the function code section for local opd entries. */
1771 asection
**func_sec
;
1773 /* After editing .opd, adjust references to opd local syms. */
1777 /* An array for toc sections, indexed by offset/8. */
1778 struct _toc_sec_data
1780 /* Specifies the relocation symbol index used at a given toc offset. */
1783 /* And the relocation addend. */
1788 enum _ppc64_sec_type sec_type
:2;
1790 /* Flag set when small branches are detected. Used to
1791 select suitable defaults for the stub group size. */
1792 unsigned int has_14bit_branch
:1;
1794 /* Flag set when PLTCALL relocs are detected. */
1795 unsigned int has_pltcall
:1;
1798 #define ppc64_elf_section_data(sec) \
1799 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
1802 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1804 if (!sec
->used_by_bfd
)
1806 struct _ppc64_elf_section_data
*sdata
;
1807 bfd_size_type amt
= sizeof (*sdata
);
1809 sdata
= bfd_zalloc (abfd
, amt
);
1812 sec
->used_by_bfd
= sdata
;
1815 return _bfd_elf_new_section_hook (abfd
, sec
);
1818 static struct _opd_sec_data
*
1819 get_opd_info (asection
* sec
)
1822 && ppc64_elf_section_data (sec
) != NULL
1823 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
1824 return &ppc64_elf_section_data (sec
)->u
.opd
;
1828 /* Parameters for the qsort hook. */
1829 static bfd_boolean synthetic_relocatable
;
1830 static asection
*synthetic_opd
;
1832 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
1835 compare_symbols (const void *ap
, const void *bp
)
1837 const asymbol
*a
= *(const asymbol
**) ap
;
1838 const asymbol
*b
= *(const asymbol
**) bp
;
1840 /* Section symbols first. */
1841 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
1843 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
1846 /* then .opd symbols. */
1847 if (synthetic_opd
!= NULL
)
1849 if (strcmp (a
->section
->name
, ".opd") == 0
1850 && strcmp (b
->section
->name
, ".opd") != 0)
1852 if (strcmp (a
->section
->name
, ".opd") != 0
1853 && strcmp (b
->section
->name
, ".opd") == 0)
1857 /* then other code symbols. */
1858 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1859 == (SEC_CODE
| SEC_ALLOC
))
1860 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1861 != (SEC_CODE
| SEC_ALLOC
)))
1864 if (((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1865 != (SEC_CODE
| SEC_ALLOC
))
1866 && ((b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
1867 == (SEC_CODE
| SEC_ALLOC
)))
1870 if (synthetic_relocatable
)
1872 if (a
->section
->id
< b
->section
->id
)
1875 if (a
->section
->id
> b
->section
->id
)
1879 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
1882 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
1885 /* For syms with the same value, prefer strong dynamic global function
1886 syms over other syms. */
1887 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
1890 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
1893 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
1896 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
1899 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
1902 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
1905 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
1908 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
1914 /* Search SYMS for a symbol of the given VALUE. */
1917 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
1921 if (id
== (unsigned) -1)
1925 mid
= (lo
+ hi
) >> 1;
1926 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
1928 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
1938 mid
= (lo
+ hi
) >> 1;
1939 if (syms
[mid
]->section
->id
< id
)
1941 else if (syms
[mid
]->section
->id
> id
)
1943 else if (syms
[mid
]->value
< value
)
1945 else if (syms
[mid
]->value
> value
)
1955 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
1957 bfd_vma vma
= *(bfd_vma
*) ptr
;
1958 return ((section
->flags
& SEC_ALLOC
) != 0
1959 && section
->vma
<= vma
1960 && vma
< section
->vma
+ section
->size
);
1963 /* Create synthetic symbols, effectively restoring "dot-symbol" function
1964 entry syms. Also generate @plt symbols for the glink branch table.
1965 Returns count of synthetic symbols in RET or -1 on error. */
1968 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
1969 long static_count
, asymbol
**static_syms
,
1970 long dyn_count
, asymbol
**dyn_syms
,
1976 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
1977 asection
*opd
= NULL
;
1978 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
1980 int abi
= abiversion (abfd
);
1986 opd
= bfd_get_section_by_name (abfd
, ".opd");
1987 if (opd
== NULL
&& abi
== 1)
1999 symcount
= static_count
;
2001 symcount
+= dyn_count
;
2005 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2009 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2011 /* Use both symbol tables. */
2012 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2013 memcpy (syms
+ static_count
, dyn_syms
,
2014 (dyn_count
+ 1) * sizeof (*syms
));
2016 else if (!relocatable
&& static_count
== 0)
2017 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2019 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2021 /* Trim uninteresting symbols. Interesting symbols are section,
2022 function, and notype symbols. */
2023 for (i
= 0, j
= 0; i
< symcount
; ++i
)
2024 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
2025 | BSF_RELC
| BSF_SRELC
)) == 0)
2026 syms
[j
++] = syms
[i
];
2029 synthetic_relocatable
= relocatable
;
2030 synthetic_opd
= opd
;
2031 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2033 if (!relocatable
&& symcount
> 1)
2035 /* Trim duplicate syms, since we may have merged the normal
2036 and dynamic symbols. Actually, we only care about syms
2037 that have different values, so trim any with the same
2038 value. Don't consider ifunc and ifunc resolver symbols
2039 duplicates however, because GDB wants to know whether a
2040 text symbol is an ifunc resolver. */
2041 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2043 const asymbol
*s0
= syms
[i
- 1];
2044 const asymbol
*s1
= syms
[i
];
2046 if ((s0
->value
+ s0
->section
->vma
2047 != s1
->value
+ s1
->section
->vma
)
2048 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
2049 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
2050 syms
[j
++] = syms
[i
];
2056 /* Note that here and in compare_symbols we can't compare opd and
2057 sym->section directly. With separate debug info files, the
2058 symbols will be extracted from the debug file while abfd passed
2059 to this function is the real binary. */
2060 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
2064 for (; i
< symcount
; ++i
)
2065 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
2066 | SEC_THREAD_LOCAL
))
2067 != (SEC_CODE
| SEC_ALLOC
))
2068 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2072 for (; i
< symcount
; ++i
)
2073 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2077 for (; i
< symcount
; ++i
)
2078 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
2082 for (; i
< symcount
; ++i
)
2083 if (((syms
[i
]->section
->flags
2084 & (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
)))
2085 != (SEC_CODE
| SEC_ALLOC
))
2093 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2098 if (opdsymend
== secsymend
)
2101 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2102 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2106 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2113 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2117 while (r
< opd
->relocation
+ relcount
2118 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2121 if (r
== opd
->relocation
+ relcount
)
2124 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2127 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2130 sym
= *r
->sym_ptr_ptr
;
2131 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2132 sym
->section
->id
, sym
->value
+ r
->addend
))
2135 size
+= sizeof (asymbol
);
2136 size
+= strlen (syms
[i
]->name
) + 2;
2142 s
= *ret
= bfd_malloc (size
);
2149 names
= (char *) (s
+ count
);
2151 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2155 while (r
< opd
->relocation
+ relcount
2156 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2159 if (r
== opd
->relocation
+ relcount
)
2162 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2165 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2168 sym
= *r
->sym_ptr_ptr
;
2169 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2170 sym
->section
->id
, sym
->value
+ r
->addend
))
2175 s
->flags
|= BSF_SYNTHETIC
;
2176 s
->section
= sym
->section
;
2177 s
->value
= sym
->value
+ r
->addend
;
2180 len
= strlen (syms
[i
]->name
);
2181 memcpy (names
, syms
[i
]->name
, len
+ 1);
2183 /* Have udata.p point back to the original symbol this
2184 synthetic symbol was derived from. */
2185 s
->udata
.p
= syms
[i
];
2192 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2193 bfd_byte
*contents
= NULL
;
2195 size_t plt_count
= 0;
2196 bfd_vma glink_vma
= 0, resolv_vma
= 0;
2197 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
2200 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2202 free_contents_and_exit_err
:
2204 free_contents_and_exit
:
2211 for (i
= secsymend
; i
< opdsymend
; ++i
)
2215 /* Ignore bogus symbols. */
2216 if (syms
[i
]->value
> opd
->size
- 8)
2219 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2220 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2223 size
+= sizeof (asymbol
);
2224 size
+= strlen (syms
[i
]->name
) + 2;
2228 /* Get start of .glink stubs from DT_PPC64_GLINK. */
2230 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
2232 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
2234 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
2236 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
2237 goto free_contents_and_exit_err
;
2239 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
2240 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
2243 extdynend
= extdyn
+ dynamic
->size
;
2244 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
2246 Elf_Internal_Dyn dyn
;
2247 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
2249 if (dyn
.d_tag
== DT_NULL
)
2252 if (dyn
.d_tag
== DT_PPC64_GLINK
)
2254 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
2255 See comment in ppc64_elf_finish_dynamic_sections. */
2256 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
2257 /* The .glink section usually does not survive the final
2258 link; search for the section (usually .text) where the
2259 glink stubs now reside. */
2260 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
2271 /* Determine __glink trampoline by reading the relative branch
2272 from the first glink stub. */
2274 unsigned int off
= 0;
2276 while (bfd_get_section_contents (abfd
, glink
, buf
,
2277 glink_vma
+ off
- glink
->vma
, 4))
2279 unsigned int insn
= bfd_get_32 (abfd
, buf
);
2281 if ((insn
& ~0x3fffffc) == 0)
2284 = glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
2293 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
2295 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2298 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2299 if (!(*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
2300 goto free_contents_and_exit_err
;
2302 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
2303 size
+= plt_count
* sizeof (asymbol
);
2305 p
= relplt
->relocation
;
2306 for (i
= 0; i
< plt_count
; i
++, p
++)
2308 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2310 size
+= sizeof ("+0x") - 1 + 16;
2316 goto free_contents_and_exit
;
2317 s
= *ret
= bfd_malloc (size
);
2319 goto free_contents_and_exit_err
;
2321 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
2323 for (i
= secsymend
; i
< opdsymend
; ++i
)
2327 if (syms
[i
]->value
> opd
->size
- 8)
2330 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2331 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2335 asection
*sec
= abfd
->sections
;
2342 size_t mid
= (lo
+ hi
) >> 1;
2343 if (syms
[mid
]->section
->vma
< ent
)
2345 else if (syms
[mid
]->section
->vma
> ent
)
2349 sec
= syms
[mid
]->section
;
2354 if (lo
>= hi
&& lo
> codesecsym
)
2355 sec
= syms
[lo
- 1]->section
;
2357 for (; sec
!= NULL
; sec
= sec
->next
)
2361 /* SEC_LOAD may not be set if SEC is from a separate debug
2363 if ((sec
->flags
& SEC_ALLOC
) == 0)
2365 if ((sec
->flags
& SEC_CODE
) != 0)
2368 s
->flags
|= BSF_SYNTHETIC
;
2369 s
->value
= ent
- s
->section
->vma
;
2372 len
= strlen (syms
[i
]->name
);
2373 memcpy (names
, syms
[i
]->name
, len
+ 1);
2375 /* Have udata.p point back to the original symbol this
2376 synthetic symbol was derived from. */
2377 s
->udata
.p
= syms
[i
];
2383 if (glink
!= NULL
&& relplt
!= NULL
)
2387 /* Add a symbol for the main glink trampoline. */
2388 memset (s
, 0, sizeof *s
);
2390 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2392 s
->value
= resolv_vma
- glink
->vma
;
2394 memcpy (names
, "__glink_PLTresolve",
2395 sizeof ("__glink_PLTresolve"));
2396 names
+= sizeof ("__glink_PLTresolve");
2401 /* FIXME: It would be very much nicer to put sym@plt on the
2402 stub rather than on the glink branch table entry. The
2403 objdump disassembler would then use a sensible symbol
2404 name on plt calls. The difficulty in doing so is
2405 a) finding the stubs, and,
2406 b) matching stubs against plt entries, and,
2407 c) there can be multiple stubs for a given plt entry.
2409 Solving (a) could be done by code scanning, but older
2410 ppc64 binaries used different stubs to current code.
2411 (b) is the tricky one since you need to known the toc
2412 pointer for at least one function that uses a pic stub to
2413 be able to calculate the plt address referenced.
2414 (c) means gdb would need to set multiple breakpoints (or
2415 find the glink branch itself) when setting breakpoints
2416 for pending shared library loads. */
2417 p
= relplt
->relocation
;
2418 for (i
= 0; i
< plt_count
; i
++, p
++)
2422 *s
= **p
->sym_ptr_ptr
;
2423 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2424 we are defining a symbol, ensure one of them is set. */
2425 if ((s
->flags
& BSF_LOCAL
) == 0)
2426 s
->flags
|= BSF_GLOBAL
;
2427 s
->flags
|= BSF_SYNTHETIC
;
2429 s
->value
= glink_vma
- glink
->vma
;
2432 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2433 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2437 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2438 names
+= sizeof ("+0x") - 1;
2439 bfd_sprintf_vma (abfd
, names
, p
->addend
);
2440 names
+= strlen (names
);
2442 memcpy (names
, "@plt", sizeof ("@plt"));
2443 names
+= sizeof ("@plt");
2463 /* The following functions are specific to the ELF linker, while
2464 functions above are used generally. Those named ppc64_elf_* are
2465 called by the main ELF linker code. They appear in this file more
2466 or less in the order in which they are called. eg.
2467 ppc64_elf_check_relocs is called early in the link process,
2468 ppc64_elf_finish_dynamic_sections is one of the last functions
2471 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2472 functions have both a function code symbol and a function descriptor
2473 symbol. A call to foo in a relocatable object file looks like:
2480 The function definition in another object file might be:
2484 . .quad .TOC.@tocbase
2490 When the linker resolves the call during a static link, the branch
2491 unsurprisingly just goes to .foo and the .opd information is unused.
2492 If the function definition is in a shared library, things are a little
2493 different: The call goes via a plt call stub, the opd information gets
2494 copied to the plt, and the linker patches the nop.
2502 . std 2,40(1) # in practice, the call stub
2503 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
2504 . addi 11,11,Lfoo@toc@l # this is the general idea
2512 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2514 The "reloc ()" notation is supposed to indicate that the linker emits
2515 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2518 What are the difficulties here? Well, firstly, the relocations
2519 examined by the linker in check_relocs are against the function code
2520 sym .foo, while the dynamic relocation in the plt is emitted against
2521 the function descriptor symbol, foo. Somewhere along the line, we need
2522 to carefully copy dynamic link information from one symbol to the other.
2523 Secondly, the generic part of the elf linker will make .foo a dynamic
2524 symbol as is normal for most other backends. We need foo dynamic
2525 instead, at least for an application final link. However, when
2526 creating a shared library containing foo, we need to have both symbols
2527 dynamic so that references to .foo are satisfied during the early
2528 stages of linking. Otherwise the linker might decide to pull in a
2529 definition from some other object, eg. a static library.
2531 Update: As of August 2004, we support a new convention. Function
2532 calls may use the function descriptor symbol, ie. "bl foo". This
2533 behaves exactly as "bl .foo". */
2535 /* Of those relocs that might be copied as dynamic relocs, this
2536 function selects those that must be copied when linking a shared
2537 library or PIE, even when the symbol is local. */
2540 must_be_dyn_reloc (struct bfd_link_info
*info
,
2541 enum elf_ppc64_reloc_type r_type
)
2546 /* Only relative relocs can be resolved when the object load
2547 address isn't fixed. DTPREL64 is excluded because the
2548 dynamic linker needs to differentiate global dynamic from
2549 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
2557 case R_PPC64_TPREL16
:
2558 case R_PPC64_TPREL16_LO
:
2559 case R_PPC64_TPREL16_HI
:
2560 case R_PPC64_TPREL16_HA
:
2561 case R_PPC64_TPREL16_DS
:
2562 case R_PPC64_TPREL16_LO_DS
:
2563 case R_PPC64_TPREL16_HIGH
:
2564 case R_PPC64_TPREL16_HIGHA
:
2565 case R_PPC64_TPREL16_HIGHER
:
2566 case R_PPC64_TPREL16_HIGHERA
:
2567 case R_PPC64_TPREL16_HIGHEST
:
2568 case R_PPC64_TPREL16_HIGHESTA
:
2569 case R_PPC64_TPREL64
:
2570 /* These relocations are relative but in a shared library the
2571 linker doesn't know the thread pointer base. */
2572 return bfd_link_dll (info
);
2576 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2577 copying dynamic variables from a shared lib into an app's dynbss
2578 section, and instead use a dynamic relocation to point into the
2579 shared lib. With code that gcc generates, it's vital that this be
2580 enabled; In the PowerPC64 ABI, the address of a function is actually
2581 the address of a function descriptor, which resides in the .opd
2582 section. gcc uses the descriptor directly rather than going via the
2583 GOT as some other ABI's do, which means that initialized function
2584 pointers must reference the descriptor. Thus, a function pointer
2585 initialized to the address of a function in a shared library will
2586 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2587 redefines the function descriptor symbol to point to the copy. This
2588 presents a problem as a plt entry for that function is also
2589 initialized from the function descriptor symbol and the copy reloc
2590 may not be initialized first. */
2591 #define ELIMINATE_COPY_RELOCS 1
2593 /* Section name for stubs is the associated section name plus this
2595 #define STUB_SUFFIX ".stub"
2598 ppc_stub_long_branch:
2599 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2600 destination, but a 24 bit branch in a stub section will reach.
2603 ppc_stub_plt_branch:
2604 Similar to the above, but a 24 bit branch in the stub section won't
2605 reach its destination.
2606 . addis %r11,%r2,xxx@toc@ha
2607 . ld %r12,xxx@toc@l(%r11)
2612 Used to call a function in a shared library. If it so happens that
2613 the plt entry referenced crosses a 64k boundary, then an extra
2614 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
2615 ppc_stub_plt_call_r2save starts with "std %r2,40(%r1)".
2616 . addis %r11,%r2,xxx@toc@ha
2617 . ld %r12,xxx+0@toc@l(%r11)
2619 . ld %r2,xxx+8@toc@l(%r11)
2620 . ld %r11,xxx+16@toc@l(%r11)
2623 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2624 code to adjust the value and save r2 to support multiple toc sections.
2625 A ppc_stub_long_branch with an r2 offset looks like:
2627 . addis %r2,%r2,off@ha
2628 . addi %r2,%r2,off@l
2631 A ppc_stub_plt_branch with an r2 offset looks like:
2633 . addis %r11,%r2,xxx@toc@ha
2634 . ld %r12,xxx@toc@l(%r11)
2635 . addis %r2,%r2,off@ha
2636 . addi %r2,%r2,off@l
2640 All of the above stubs are shown as their ELFv1 variants. ELFv2
2641 variants exist too, simpler for plt calls since a new toc pointer
2642 and static chain are not loaded by the stub. In addition, ELFv2
2643 has some more complex stubs to handle calls marked with NOTOC
2644 relocs from functions where r2 is not a valid toc pointer. These
2645 come in two flavours, the ones shown below, and _both variants that
2646 start with "std %r2,24(%r1)" to save r2 in the unlikely event that
2647 one call is from a function where r2 is used as the toc pointer but
2648 needs a toc adjusting stub for small-model multi-toc, and another
2649 call is from a function where r2 is not valid.
2650 ppc_stub_long_branch_notoc:
2656 . addis %r12,%r11,dest-1b@ha
2657 . addi %r12,%r12,dest-1b@l
2660 ppc_stub_plt_branch_notoc:
2666 . lis %r12,xxx-1b@highest
2667 . ori %r12,%r12,xxx-1b@higher
2669 . oris %r12,%r12,xxx-1b@high
2670 . ori %r12,%r12,xxx-1b@l
2671 . add %r12,%r11,%r12
2675 ppc_stub_plt_call_notoc:
2681 . lis %r12,xxx-1b@highest
2682 . ori %r12,%r12,xxx-1b@higher
2684 . oris %r12,%r12,xxx-1b@high
2685 . ori %r12,%r12,xxx-1b@l
2686 . ldx %r12,%r11,%r12
2690 In cases where the high instructions would add zero, they are
2691 omitted and following instructions modified in some cases.
2693 For a given stub group (a set of sections all using the same toc
2694 pointer value) there will be just one stub type used for any
2695 particular function symbol. For example, if printf is called from
2696 code with the tocsave optimization (ie. r2 saved in function
2697 prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
2698 and from other code without the tocsave optimization requiring a
2699 ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
2700 type will be created. Calls with the tocsave optimization will
2701 enter this stub after the instruction saving r2. A similar
2702 situation exists when calls are marked with R_PPC64_REL24_NOTOC
2703 relocations. These require a ppc_stub_plt_call_notoc linkage stub
2704 to call an external function like printf. If other calls to printf
2705 require a ppc_stub_plt_call linkage stub then a single
2706 ppc_stub_plt_call_notoc linkage stub will be used for both types of
2707 call. If other calls to printf require a ppc_stub_plt_call_r2save
2708 linkage stub then a single ppc_stub_plt_call_both linkage stub will
2709 be created and calls not requiring r2 to be saved will enter the
2710 stub after the r2 save instruction. There is an analogous
2711 hierarchy of long branch and plt branch stubs for local call
2717 ppc_stub_long_branch
,
2718 ppc_stub_long_branch_r2off
,
2719 ppc_stub_long_branch_notoc
,
2720 ppc_stub_long_branch_both
, /* r2off and notoc variants both needed. */
2721 ppc_stub_plt_branch
,
2722 ppc_stub_plt_branch_r2off
,
2723 ppc_stub_plt_branch_notoc
,
2724 ppc_stub_plt_branch_both
,
2726 ppc_stub_plt_call_r2save
,
2727 ppc_stub_plt_call_notoc
,
2728 ppc_stub_plt_call_both
,
2729 ppc_stub_global_entry
,
2733 /* Information on stub grouping. */
2736 /* The stub section. */
2738 /* This is the section to which stubs in the group will be attached. */
2741 struct map_stub
*next
;
2742 /* Whether to emit a copy of register save/restore functions in this
2745 /* Current offset within stubs after the insn restoring lr in a
2746 _notoc or _both stub using bcl for pc-relative addressing, or
2747 after the insn restoring lr in a __tls_get_addr_opt plt stub. */
2748 unsigned int lr_restore
;
2749 /* Accumulated size of EH info emitted to describe return address
2750 if stubs modify lr. Does not include 17 byte FDE header. */
2751 unsigned int eh_size
;
2752 /* Offset in glink_eh_frame to the start of EH info for this group. */
2753 unsigned int eh_base
;
2756 struct ppc_stub_hash_entry
2758 /* Base hash table entry structure. */
2759 struct bfd_hash_entry root
;
2761 enum ppc_stub_type stub_type
;
2763 /* Group information. */
2764 struct map_stub
*group
;
2766 /* Offset within stub_sec of the beginning of this stub. */
2767 bfd_vma stub_offset
;
2769 /* Given the symbol's value and its section we can determine its final
2770 value when building the stubs (so the stub knows where to jump. */
2771 bfd_vma target_value
;
2772 asection
*target_section
;
2774 /* The symbol table entry, if any, that this was derived from. */
2775 struct ppc_link_hash_entry
*h
;
2776 struct plt_entry
*plt_ent
;
2779 unsigned char symtype
;
2781 /* Symbol st_other. */
2782 unsigned char other
;
2785 struct ppc_branch_hash_entry
2787 /* Base hash table entry structure. */
2788 struct bfd_hash_entry root
;
2790 /* Offset within branch lookup table. */
2791 unsigned int offset
;
2793 /* Generation marker. */
2797 /* Used to track dynamic relocations for local symbols. */
2798 struct ppc_dyn_relocs
2800 struct ppc_dyn_relocs
*next
;
2802 /* The input section of the reloc. */
2805 /* Total number of relocs copied for the input section. */
2806 unsigned int count
: 31;
2808 /* Whether this entry is for STT_GNU_IFUNC symbols. */
2809 unsigned int ifunc
: 1;
2812 struct ppc_link_hash_entry
2814 struct elf_link_hash_entry elf
;
2818 /* A pointer to the most recently used stub hash entry against this
2820 struct ppc_stub_hash_entry
*stub_cache
;
2822 /* A pointer to the next symbol starting with a '.' */
2823 struct ppc_link_hash_entry
*next_dot_sym
;
2826 /* Track dynamic relocs copied for this symbol. */
2827 struct elf_dyn_relocs
*dyn_relocs
;
2829 /* Link between function code and descriptor symbols. */
2830 struct ppc_link_hash_entry
*oh
;
2832 /* Flag function code and descriptor symbols. */
2833 unsigned int is_func
:1;
2834 unsigned int is_func_descriptor
:1;
2835 unsigned int fake
:1;
2837 /* Whether global opd/toc sym has been adjusted or not.
2838 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
2839 should be set for all globals defined in any opd/toc section. */
2840 unsigned int adjust_done
:1;
2842 /* Set if this is an out-of-line register save/restore function,
2843 with non-standard calling convention. */
2844 unsigned int save_res
:1;
2846 /* Set if a duplicate symbol with non-zero localentry is detected,
2847 even when the duplicate symbol does not provide a definition. */
2848 unsigned int non_zero_localentry
:1;
2850 /* Contexts in which symbol is used in the GOT (or TOC).
2851 Bits are or'd into the mask as the corresponding relocs are
2852 encountered during check_relocs, with TLS_TLS being set when any
2853 of the other TLS bits are set. tls_optimize clears bits when
2854 optimizing to indicate the corresponding GOT entry type is not
2855 needed. If set, TLS_TLS is never cleared. tls_optimize may also
2856 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
2857 separate flag rather than setting TPREL just for convenience in
2858 distinguishing the two cases.
2859 These flags are also kept for local symbols. */
2860 #define TLS_TLS 1 /* Any TLS reloc. */
2861 #define TLS_GD 2 /* GD reloc. */
2862 #define TLS_LD 4 /* LD reloc. */
2863 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
2864 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
2865 #define TLS_MARK 32 /* __tls_get_addr call marked. */
2866 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2867 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
2868 unsigned char tls_mask
;
2870 /* The above field is also used to mark function symbols. In which
2871 case TLS_TLS will be 0. */
2872 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
2873 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
2874 #define NON_GOT 256 /* local symbol plt, not stored. */
2877 /* ppc64 ELF linker hash table. */
2879 struct ppc_link_hash_table
2881 struct elf_link_hash_table elf
;
2883 /* The stub hash table. */
2884 struct bfd_hash_table stub_hash_table
;
2886 /* Another hash table for plt_branch stubs. */
2887 struct bfd_hash_table branch_hash_table
;
2889 /* Hash table for function prologue tocsave. */
2890 htab_t tocsave_htab
;
2892 /* Various options and other info passed from the linker. */
2893 struct ppc64_elf_params
*params
;
2895 /* The size of sec_info below. */
2896 unsigned int sec_info_arr_size
;
2898 /* Per-section array of extra section info. Done this way rather
2899 than as part of ppc64_elf_section_data so we have the info for
2900 non-ppc64 sections. */
2903 /* Along with elf_gp, specifies the TOC pointer used by this section. */
2908 /* The section group that this section belongs to. */
2909 struct map_stub
*group
;
2910 /* A temp section list pointer. */
2915 /* Linked list of groups. */
2916 struct map_stub
*group
;
2918 /* Temp used when calculating TOC pointers. */
2921 asection
*toc_first_sec
;
2923 /* Used when adding symbols. */
2924 struct ppc_link_hash_entry
*dot_syms
;
2926 /* Shortcuts to get to dynamic linker sections. */
2928 asection
*global_entry
;
2931 asection
*relpltlocal
;
2934 asection
*glink_eh_frame
;
2936 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
2937 struct ppc_link_hash_entry
*tls_get_addr
;
2938 struct ppc_link_hash_entry
*tls_get_addr_fd
;
2940 /* The size of reliplt used by got entry relocs. */
2941 bfd_size_type got_reli_size
;
2944 unsigned long stub_count
[ppc_stub_global_entry
];
2946 /* Number of stubs against global syms. */
2947 unsigned long stub_globals
;
2949 /* Set if we're linking code with function descriptors. */
2950 unsigned int opd_abi
:1;
2952 /* Support for multiple toc sections. */
2953 unsigned int do_multi_toc
:1;
2954 unsigned int multi_toc_needed
:1;
2955 unsigned int second_toc_pass
:1;
2956 unsigned int do_toc_opt
:1;
2958 /* Set if tls optimization is enabled. */
2959 unsigned int do_tls_opt
:1;
2961 /* Set if inline plt calls should be converted to direct calls. */
2962 unsigned int can_convert_all_inline_plt
:1;
2965 unsigned int stub_error
:1;
2967 /* Whether func_desc_adjust needs to be run over symbols. */
2968 unsigned int need_func_desc_adj
:1;
2970 /* Whether there exist local gnu indirect function resolvers,
2971 referenced by dynamic relocations. */
2972 unsigned int local_ifunc_resolver
:1;
2973 unsigned int maybe_local_ifunc_resolver
:1;
2975 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
2976 unsigned int has_plt_localentry0
:1;
2978 /* Incremented every time we size stubs. */
2979 unsigned int stub_iteration
;
2981 /* Small local sym cache. */
2982 struct sym_cache sym_cache
;
2985 /* Rename some of the generic section flags to better document how they
2988 /* Nonzero if this section has TLS related relocations. */
2989 #define has_tls_reloc sec_flg0
2991 /* Nonzero if this section has an old-style call to __tls_get_addr. */
2992 #define has_tls_get_addr_call sec_flg1
2994 /* Nonzero if this section has any toc or got relocs. */
2995 #define has_toc_reloc sec_flg2
2997 /* Nonzero if this section has a call to another section that uses
2999 #define makes_toc_func_call sec_flg3
3001 /* Recursion protection when determining above flag. */
3002 #define call_check_in_progress sec_flg4
3003 #define call_check_done sec_flg5
3005 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3007 #define ppc_hash_table(p) \
3008 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
3009 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
3011 #define ppc_stub_hash_lookup(table, string, create, copy) \
3012 ((struct ppc_stub_hash_entry *) \
3013 bfd_hash_lookup ((table), (string), (create), (copy)))
3015 #define ppc_branch_hash_lookup(table, string, create, copy) \
3016 ((struct ppc_branch_hash_entry *) \
3017 bfd_hash_lookup ((table), (string), (create), (copy)))
3019 /* Create an entry in the stub hash table. */
3021 static struct bfd_hash_entry
*
3022 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3023 struct bfd_hash_table
*table
,
3026 /* Allocate the structure if it has not already been allocated by a
3030 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3035 /* Call the allocation method of the superclass. */
3036 entry
= bfd_hash_newfunc (entry
, table
, string
);
3039 struct ppc_stub_hash_entry
*eh
;
3041 /* Initialize the local fields. */
3042 eh
= (struct ppc_stub_hash_entry
*) entry
;
3043 eh
->stub_type
= ppc_stub_none
;
3045 eh
->stub_offset
= 0;
3046 eh
->target_value
= 0;
3047 eh
->target_section
= NULL
;
3056 /* Create an entry in the branch hash table. */
3058 static struct bfd_hash_entry
*
3059 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3060 struct bfd_hash_table
*table
,
3063 /* Allocate the structure if it has not already been allocated by a
3067 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3072 /* Call the allocation method of the superclass. */
3073 entry
= bfd_hash_newfunc (entry
, table
, string
);
3076 struct ppc_branch_hash_entry
*eh
;
3078 /* Initialize the local fields. */
3079 eh
= (struct ppc_branch_hash_entry
*) entry
;
3087 /* Create an entry in a ppc64 ELF linker hash table. */
3089 static struct bfd_hash_entry
*
3090 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3091 struct bfd_hash_table
*table
,
3094 /* Allocate the structure if it has not already been allocated by a
3098 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3103 /* Call the allocation method of the superclass. */
3104 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3107 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3109 memset (&eh
->u
.stub_cache
, 0,
3110 (sizeof (struct ppc_link_hash_entry
)
3111 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3113 /* When making function calls, old ABI code references function entry
3114 points (dot symbols), while new ABI code references the function
3115 descriptor symbol. We need to make any combination of reference and
3116 definition work together, without breaking archive linking.
3118 For a defined function "foo" and an undefined call to "bar":
3119 An old object defines "foo" and ".foo", references ".bar" (possibly
3121 A new object defines "foo" and references "bar".
3123 A new object thus has no problem with its undefined symbols being
3124 satisfied by definitions in an old object. On the other hand, the
3125 old object won't have ".bar" satisfied by a new object.
3127 Keep a list of newly added dot-symbols. */
3129 if (string
[0] == '.')
3131 struct ppc_link_hash_table
*htab
;
3133 htab
= (struct ppc_link_hash_table
*) table
;
3134 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3135 htab
->dot_syms
= eh
;
3142 struct tocsave_entry
3149 tocsave_htab_hash (const void *p
)
3151 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
3152 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
3156 tocsave_htab_eq (const void *p1
, const void *p2
)
3158 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
3159 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
3160 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
3163 /* Destroy a ppc64 ELF linker hash table. */
3166 ppc64_elf_link_hash_table_free (bfd
*obfd
)
3168 struct ppc_link_hash_table
*htab
;
3170 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
3171 if (htab
->tocsave_htab
)
3172 htab_delete (htab
->tocsave_htab
);
3173 bfd_hash_table_free (&htab
->branch_hash_table
);
3174 bfd_hash_table_free (&htab
->stub_hash_table
);
3175 _bfd_elf_link_hash_table_free (obfd
);
3178 /* Create a ppc64 ELF linker hash table. */
3180 static struct bfd_link_hash_table
*
3181 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3183 struct ppc_link_hash_table
*htab
;
3184 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3186 htab
= bfd_zmalloc (amt
);
3190 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3191 sizeof (struct ppc_link_hash_entry
),
3198 /* Init the stub hash table too. */
3199 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3200 sizeof (struct ppc_stub_hash_entry
)))
3202 _bfd_elf_link_hash_table_free (abfd
);
3206 /* And the branch hash table. */
3207 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3208 sizeof (struct ppc_branch_hash_entry
)))
3210 bfd_hash_table_free (&htab
->stub_hash_table
);
3211 _bfd_elf_link_hash_table_free (abfd
);
3215 htab
->tocsave_htab
= htab_try_create (1024,
3219 if (htab
->tocsave_htab
== NULL
)
3221 ppc64_elf_link_hash_table_free (abfd
);
3224 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
3226 /* Initializing two fields of the union is just cosmetic. We really
3227 only care about glist, but when compiled on a 32-bit host the
3228 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3229 debugger inspection of these fields look nicer. */
3230 htab
->elf
.init_got_refcount
.refcount
= 0;
3231 htab
->elf
.init_got_refcount
.glist
= NULL
;
3232 htab
->elf
.init_plt_refcount
.refcount
= 0;
3233 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3234 htab
->elf
.init_got_offset
.offset
= 0;
3235 htab
->elf
.init_got_offset
.glist
= NULL
;
3236 htab
->elf
.init_plt_offset
.offset
= 0;
3237 htab
->elf
.init_plt_offset
.glist
= NULL
;
3239 return &htab
->elf
.root
;
3242 /* Create sections for linker generated code. */
3245 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3247 struct ppc_link_hash_table
*htab
;
3250 htab
= ppc_hash_table (info
);
3252 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3253 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3254 if (htab
->params
->save_restore_funcs
)
3256 /* Create .sfpr for code to save and restore fp regs. */
3257 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3259 if (htab
->sfpr
== NULL
3260 || !bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3264 if (bfd_link_relocatable (info
))
3267 /* Create .glink for lazy dynamic linking support. */
3268 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3270 if (htab
->glink
== NULL
3271 || !bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
3274 /* The part of .glink used by global entry stubs, separate so that
3275 it can be aligned appropriately without affecting htab->glink. */
3276 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3278 if (htab
->global_entry
== NULL
3279 || !bfd_set_section_alignment (dynobj
, htab
->global_entry
, 2))
3282 if (!info
->no_ld_generated_unwind_info
)
3284 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
3285 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3286 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
3289 if (htab
->glink_eh_frame
== NULL
3290 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
3294 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
3295 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
3296 if (htab
->elf
.iplt
== NULL
3297 || !bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
3300 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3301 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3303 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
3304 if (htab
->elf
.irelplt
== NULL
3305 || !bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
3308 /* Create branch lookup table for plt_branch stubs. */
3309 flags
= (SEC_ALLOC
| SEC_LOAD
3310 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3311 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3313 if (htab
->brlt
== NULL
3314 || !bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3317 /* Local plt entries, put in .branch_lt but a separate section for
3319 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3321 if (htab
->pltlocal
== NULL
3322 || !bfd_set_section_alignment (dynobj
, htab
->pltlocal
, 3))
3325 if (!bfd_link_pic (info
))
3328 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3329 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3331 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3332 if (htab
->relbrlt
== NULL
3333 || !bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3337 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
3338 if (htab
->relpltlocal
== NULL
3339 || !bfd_set_section_alignment (dynobj
, htab
->relpltlocal
, 3))
3345 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3348 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
3349 struct ppc64_elf_params
*params
)
3351 struct ppc_link_hash_table
*htab
;
3353 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3355 /* Always hook our dynamic sections into the first bfd, which is the
3356 linker created stub bfd. This ensures that the GOT header is at
3357 the start of the output TOC section. */
3358 htab
= ppc_hash_table (info
);
3359 htab
->elf
.dynobj
= params
->stub_bfd
;
3360 htab
->params
= params
;
3362 return create_linkage_sections (htab
->elf
.dynobj
, info
);
3365 /* Build a name for an entry in the stub hash table. */
3368 ppc_stub_name (const asection
*input_section
,
3369 const asection
*sym_sec
,
3370 const struct ppc_link_hash_entry
*h
,
3371 const Elf_Internal_Rela
*rel
)
3376 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3377 offsets from a sym as a branch target? In fact, we could
3378 probably assume the addend is always zero. */
3379 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3383 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3384 stub_name
= bfd_malloc (len
);
3385 if (stub_name
== NULL
)
3388 len
= sprintf (stub_name
, "%08x.%s+%x",
3389 input_section
->id
& 0xffffffff,
3390 h
->elf
.root
.root
.string
,
3391 (int) rel
->r_addend
& 0xffffffff);
3395 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3396 stub_name
= bfd_malloc (len
);
3397 if (stub_name
== NULL
)
3400 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
3401 input_section
->id
& 0xffffffff,
3402 sym_sec
->id
& 0xffffffff,
3403 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3404 (int) rel
->r_addend
& 0xffffffff);
3406 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3407 stub_name
[len
- 2] = 0;
3411 /* Look up an entry in the stub hash. Stub entries are cached because
3412 creating the stub name takes a bit of time. */
3414 static struct ppc_stub_hash_entry
*
3415 ppc_get_stub_entry (const asection
*input_section
,
3416 const asection
*sym_sec
,
3417 struct ppc_link_hash_entry
*h
,
3418 const Elf_Internal_Rela
*rel
,
3419 struct ppc_link_hash_table
*htab
)
3421 struct ppc_stub_hash_entry
*stub_entry
;
3422 struct map_stub
*group
;
3424 /* If this input section is part of a group of sections sharing one
3425 stub section, then use the id of the first section in the group.
3426 Stub names need to include a section id, as there may well be
3427 more than one stub used to reach say, printf, and we need to
3428 distinguish between them. */
3429 group
= htab
->sec_info
[input_section
->id
].u
.group
;
3433 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3434 && h
->u
.stub_cache
->h
== h
3435 && h
->u
.stub_cache
->group
== group
)
3437 stub_entry
= h
->u
.stub_cache
;
3443 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
3444 if (stub_name
== NULL
)
3447 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3448 stub_name
, FALSE
, FALSE
);
3450 h
->u
.stub_cache
= stub_entry
;
3458 /* Add a new stub entry to the stub hash. Not all fields of the new
3459 stub entry are initialised. */
3461 static struct ppc_stub_hash_entry
*
3462 ppc_add_stub (const char *stub_name
,
3464 struct bfd_link_info
*info
)
3466 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3467 struct map_stub
*group
;
3470 struct ppc_stub_hash_entry
*stub_entry
;
3472 group
= htab
->sec_info
[section
->id
].u
.group
;
3473 link_sec
= group
->link_sec
;
3474 stub_sec
= group
->stub_sec
;
3475 if (stub_sec
== NULL
)
3481 namelen
= strlen (link_sec
->name
);
3482 len
= namelen
+ sizeof (STUB_SUFFIX
);
3483 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
3487 memcpy (s_name
, link_sec
->name
, namelen
);
3488 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3489 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
3490 if (stub_sec
== NULL
)
3492 group
->stub_sec
= stub_sec
;
3495 /* Enter this entry into the linker stub hash table. */
3496 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3498 if (stub_entry
== NULL
)
3500 /* xgettext:c-format */
3501 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
3502 section
->owner
, stub_name
);
3506 stub_entry
->group
= group
;
3507 stub_entry
->stub_offset
= 0;
3511 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3512 not already done. */
3515 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3517 asection
*got
, *relgot
;
3519 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3521 if (!is_ppc64_elf (abfd
))
3527 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3530 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3531 | SEC_LINKER_CREATED
);
3533 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3535 || !bfd_set_section_alignment (abfd
, got
, 3))
3538 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3539 flags
| SEC_READONLY
);
3541 || !bfd_set_section_alignment (abfd
, relgot
, 3))
3544 ppc64_elf_tdata (abfd
)->got
= got
;
3545 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3549 /* Follow indirect and warning symbol links. */
3551 static inline struct bfd_link_hash_entry
*
3552 follow_link (struct bfd_link_hash_entry
*h
)
3554 while (h
->type
== bfd_link_hash_indirect
3555 || h
->type
== bfd_link_hash_warning
)
3560 static inline struct elf_link_hash_entry
*
3561 elf_follow_link (struct elf_link_hash_entry
*h
)
3563 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
3566 static inline struct ppc_link_hash_entry
*
3567 ppc_follow_link (struct ppc_link_hash_entry
*h
)
3569 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
3572 /* Merge PLT info on FROM with that on TO. */
3575 move_plt_plist (struct ppc_link_hash_entry
*from
,
3576 struct ppc_link_hash_entry
*to
)
3578 if (from
->elf
.plt
.plist
!= NULL
)
3580 if (to
->elf
.plt
.plist
!= NULL
)
3582 struct plt_entry
**entp
;
3583 struct plt_entry
*ent
;
3585 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3587 struct plt_entry
*dent
;
3589 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3590 if (dent
->addend
== ent
->addend
)
3592 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3599 *entp
= to
->elf
.plt
.plist
;
3602 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3603 from
->elf
.plt
.plist
= NULL
;
3607 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3610 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3611 struct elf_link_hash_entry
*dir
,
3612 struct elf_link_hash_entry
*ind
)
3614 struct ppc_link_hash_entry
*edir
, *eind
;
3616 edir
= (struct ppc_link_hash_entry
*) dir
;
3617 eind
= (struct ppc_link_hash_entry
*) ind
;
3619 edir
->is_func
|= eind
->is_func
;
3620 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3621 edir
->tls_mask
|= eind
->tls_mask
;
3622 if (eind
->oh
!= NULL
)
3623 edir
->oh
= ppc_follow_link (eind
->oh
);
3625 if (edir
->elf
.versioned
!= versioned_hidden
)
3626 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
3627 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
3628 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
3629 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
3630 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
3631 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
3633 /* If we were called to copy over info for a weak sym, don't copy
3634 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
3635 in order to simplify readonly_dynrelocs and save a field in the
3636 symbol hash entry, but that means dyn_relocs can't be used in any
3637 tests about a specific symbol, or affect other symbol flags which
3639 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3642 /* Copy over any dynamic relocs we may have on the indirect sym. */
3643 if (eind
->dyn_relocs
!= NULL
)
3645 if (edir
->dyn_relocs
!= NULL
)
3647 struct elf_dyn_relocs
**pp
;
3648 struct elf_dyn_relocs
*p
;
3650 /* Add reloc counts against the indirect sym to the direct sym
3651 list. Merge any entries against the same section. */
3652 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3654 struct elf_dyn_relocs
*q
;
3656 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3657 if (q
->sec
== p
->sec
)
3659 q
->pc_count
+= p
->pc_count
;
3660 q
->count
+= p
->count
;
3667 *pp
= edir
->dyn_relocs
;
3670 edir
->dyn_relocs
= eind
->dyn_relocs
;
3671 eind
->dyn_relocs
= NULL
;
3674 /* Copy over got entries that we may have already seen to the
3675 symbol which just became indirect. */
3676 if (eind
->elf
.got
.glist
!= NULL
)
3678 if (edir
->elf
.got
.glist
!= NULL
)
3680 struct got_entry
**entp
;
3681 struct got_entry
*ent
;
3683 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3685 struct got_entry
*dent
;
3687 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3688 if (dent
->addend
== ent
->addend
3689 && dent
->owner
== ent
->owner
3690 && dent
->tls_type
== ent
->tls_type
)
3692 dent
->got
.refcount
+= ent
->got
.refcount
;
3699 *entp
= edir
->elf
.got
.glist
;
3702 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3703 eind
->elf
.got
.glist
= NULL
;
3706 /* And plt entries. */
3707 move_plt_plist (eind
, edir
);
3709 if (eind
->elf
.dynindx
!= -1)
3711 if (edir
->elf
.dynindx
!= -1)
3712 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3713 edir
->elf
.dynstr_index
);
3714 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3715 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3716 eind
->elf
.dynindx
= -1;
3717 eind
->elf
.dynstr_index
= 0;
3721 /* Find the function descriptor hash entry from the given function code
3722 hash entry FH. Link the entries via their OH fields. */
3724 static struct ppc_link_hash_entry
*
3725 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
3727 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
3731 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
3733 fdh
= (struct ppc_link_hash_entry
*)
3734 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
3738 fdh
->is_func_descriptor
= 1;
3744 fdh
= ppc_follow_link (fdh
);
3745 fdh
->is_func_descriptor
= 1;
3750 /* Make a fake function descriptor sym for the undefined code sym FH. */
3752 static struct ppc_link_hash_entry
*
3753 make_fdh (struct bfd_link_info
*info
,
3754 struct ppc_link_hash_entry
*fh
)
3756 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
3757 struct bfd_link_hash_entry
*bh
= NULL
;
3758 struct ppc_link_hash_entry
*fdh
;
3759 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
3763 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
3764 fh
->elf
.root
.root
.string
+ 1,
3765 flags
, bfd_und_section_ptr
, 0,
3766 NULL
, FALSE
, FALSE
, &bh
))
3769 fdh
= (struct ppc_link_hash_entry
*) bh
;
3770 fdh
->elf
.non_elf
= 0;
3772 fdh
->is_func_descriptor
= 1;
3779 /* Fix function descriptor symbols defined in .opd sections to be
3783 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
3784 struct bfd_link_info
*info
,
3785 Elf_Internal_Sym
*isym
,
3787 flagword
*flags ATTRIBUTE_UNUSED
,
3792 && strcmp ((*sec
)->name
, ".opd") == 0)
3796 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
3797 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
3798 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
3800 /* If the symbol is a function defined in .opd, and the function
3801 code is in a discarded group, let it appear to be undefined. */
3802 if (!bfd_link_relocatable (info
)
3803 && (*sec
)->reloc_count
!= 0
3804 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
3805 FALSE
) != (bfd_vma
) -1
3806 && discarded_section (code_sec
))
3808 *sec
= bfd_und_section_ptr
;
3809 isym
->st_shndx
= SHN_UNDEF
;
3812 else if (*sec
!= NULL
3813 && strcmp ((*sec
)->name
, ".toc") == 0
3814 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
3816 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3818 htab
->params
->object_in_toc
= 1;
3821 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
3823 if (abiversion (ibfd
) == 0)
3824 set_abiversion (ibfd
, 2);
3825 else if (abiversion (ibfd
) == 1)
3827 _bfd_error_handler (_("symbol '%s' has invalid st_other"
3828 " for ABI version 1"), *name
);
3829 bfd_set_error (bfd_error_bad_value
);
3837 /* Merge non-visibility st_other attributes: local entry point. */
3840 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
3841 const Elf_Internal_Sym
*isym
,
3842 bfd_boolean definition
,
3843 bfd_boolean dynamic
)
3845 if (definition
&& (!dynamic
|| !h
->def_regular
))
3846 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
3847 | ELF_ST_VISIBILITY (h
->other
));
3850 /* Hook called on merging a symbol. We use this to clear "fake" since
3851 we now have a real symbol. */
3854 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
3855 const Elf_Internal_Sym
*isym
,
3856 asection
**psec ATTRIBUTE_UNUSED
,
3857 bfd_boolean newdef ATTRIBUTE_UNUSED
,
3858 bfd_boolean olddef ATTRIBUTE_UNUSED
,
3859 bfd
*oldbfd ATTRIBUTE_UNUSED
,
3860 const asection
*oldsec ATTRIBUTE_UNUSED
)
3862 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
3863 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
3864 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
3868 /* This function makes an old ABI object reference to ".bar" cause the
3869 inclusion of a new ABI object archive that defines "bar".
3870 NAME is a symbol defined in an archive. Return a symbol in the hash
3871 table that might be satisfied by the archive symbols. */
3873 static struct elf_link_hash_entry
*
3874 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
3875 struct bfd_link_info
*info
,
3878 struct elf_link_hash_entry
*h
;
3882 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
3884 /* Don't return this sym if it is a fake function descriptor
3885 created by add_symbol_adjust. */
3886 && !((struct ppc_link_hash_entry
*) h
)->fake
)
3892 len
= strlen (name
);
3893 dot_name
= bfd_alloc (abfd
, len
+ 2);
3894 if (dot_name
== NULL
)
3895 return (struct elf_link_hash_entry
*) -1;
3897 memcpy (dot_name
+ 1, name
, len
+ 1);
3898 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
3899 bfd_release (abfd
, dot_name
);
3903 /* This function satisfies all old ABI object references to ".bar" if a
3904 new ABI object defines "bar". Well, at least, undefined dot symbols
3905 are made weak. This stops later archive searches from including an
3906 object if we already have a function descriptor definition. It also
3907 prevents the linker complaining about undefined symbols.
3908 We also check and correct mismatched symbol visibility here. The
3909 most restrictive visibility of the function descriptor and the
3910 function entry symbol is used. */
3913 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
3915 struct ppc_link_hash_table
*htab
;
3916 struct ppc_link_hash_entry
*fdh
;
3918 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
3919 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
3921 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
3924 if (eh
->elf
.root
.root
.string
[0] != '.')
3927 htab
= ppc_hash_table (info
);
3931 fdh
= lookup_fdh (eh
, htab
);
3933 && !bfd_link_relocatable (info
)
3934 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
3935 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
3936 && eh
->elf
.ref_regular
)
3938 /* Make an undefined function descriptor sym, in order to
3939 pull in an --as-needed shared lib. Archives are handled
3941 fdh
= make_fdh (info
, eh
);
3948 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
3949 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
3951 /* Make both descriptor and entry symbol have the most
3952 constraining visibility of either symbol. */
3953 if (entry_vis
< descr_vis
)
3954 fdh
->elf
.other
+= entry_vis
- descr_vis
;
3955 else if (entry_vis
> descr_vis
)
3956 eh
->elf
.other
+= descr_vis
- entry_vis
;
3958 /* Propagate reference flags from entry symbol to function
3959 descriptor symbol. */
3960 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
3961 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
3962 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
3963 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
3965 if (!fdh
->elf
.forced_local
3966 && fdh
->elf
.dynindx
== -1
3967 && fdh
->elf
.versioned
!= versioned_hidden
3968 && (bfd_link_dll (info
)
3969 || fdh
->elf
.def_dynamic
3970 || fdh
->elf
.ref_dynamic
)
3971 && (eh
->elf
.ref_regular
3972 || eh
->elf
.def_regular
))
3974 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
3982 /* Set up opd section info and abiversion for IBFD, and process list
3983 of dot-symbols we made in link_hash_newfunc. */
3986 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
3988 struct ppc_link_hash_table
*htab
;
3989 struct ppc_link_hash_entry
**p
, *eh
;
3990 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
3992 if (opd
!= NULL
&& opd
->size
!= 0)
3994 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
3995 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
3997 if (abiversion (ibfd
) == 0)
3998 set_abiversion (ibfd
, 1);
3999 else if (abiversion (ibfd
) >= 2)
4001 /* xgettext:c-format */
4002 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
4003 ibfd
, abiversion (ibfd
));
4004 bfd_set_error (bfd_error_bad_value
);
4009 if (is_ppc64_elf (info
->output_bfd
))
4011 /* For input files without an explicit abiversion in e_flags
4012 we should have flagged any with symbol st_other bits set
4013 as ELFv1 and above flagged those with .opd as ELFv2.
4014 Set the output abiversion if not yet set, and for any input
4015 still ambiguous, take its abiversion from the output.
4016 Differences in ABI are reported later. */
4017 if (abiversion (info
->output_bfd
) == 0)
4018 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
4019 else if (abiversion (ibfd
) == 0)
4020 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
4023 htab
= ppc_hash_table (info
);
4027 if (opd
!= NULL
&& opd
->size
!= 0
4028 && (ibfd
->flags
& DYNAMIC
) == 0
4029 && (opd
->flags
& SEC_RELOC
) != 0
4030 && opd
->reloc_count
!= 0
4031 && !bfd_is_abs_section (opd
->output_section
)
4032 && info
->gc_sections
)
4034 /* Garbage collection needs some extra help with .opd sections.
4035 We don't want to necessarily keep everything referenced by
4036 relocs in .opd, as that would keep all functions. Instead,
4037 if we reference an .opd symbol (a function descriptor), we
4038 want to keep the function code symbol's section. This is
4039 easy for global symbols, but for local syms we need to keep
4040 information about the associated function section. */
4042 asection
**opd_sym_map
;
4043 Elf_Internal_Shdr
*symtab_hdr
;
4044 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
4046 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
4047 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
4048 if (opd_sym_map
== NULL
)
4050 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
4051 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
4055 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4056 rel_end
= relocs
+ opd
->reloc_count
- 1;
4057 for (rel
= relocs
; rel
< rel_end
; rel
++)
4059 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
4060 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
4062 if (r_type
== R_PPC64_ADDR64
4063 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
4064 && r_symndx
< symtab_hdr
->sh_info
)
4066 Elf_Internal_Sym
*isym
;
4069 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
4072 if (elf_section_data (opd
)->relocs
!= relocs
)
4077 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
4078 if (s
!= NULL
&& s
!= opd
)
4079 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
4082 if (elf_section_data (opd
)->relocs
!= relocs
)
4086 p
= &htab
->dot_syms
;
4087 while ((eh
= *p
) != NULL
)
4090 if (&eh
->elf
== htab
->elf
.hgot
)
4092 else if (htab
->elf
.hgot
== NULL
4093 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
4094 htab
->elf
.hgot
= &eh
->elf
;
4095 else if (abiversion (ibfd
) <= 1)
4097 htab
->need_func_desc_adj
= 1;
4098 if (!add_symbol_adjust (eh
, info
))
4101 p
= &eh
->u
.next_dot_sym
;
4106 /* Undo hash table changes when an --as-needed input file is determined
4107 not to be needed. */
4110 ppc64_elf_notice_as_needed (bfd
*ibfd
,
4111 struct bfd_link_info
*info
,
4112 enum notice_asneeded_action act
)
4114 if (act
== notice_not_needed
)
4116 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4121 htab
->dot_syms
= NULL
;
4123 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
4126 /* If --just-symbols against a final linked binary, then assume we need
4127 toc adjusting stubs when calling functions defined there. */
4130 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
4132 if ((sec
->flags
& SEC_CODE
) != 0
4133 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
4134 && is_ppc64_elf (sec
->owner
))
4136 if (abiversion (sec
->owner
) >= 2
4137 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
4138 sec
->has_toc_reloc
= 1;
4140 _bfd_elf_link_just_syms (sec
, info
);
4143 static struct plt_entry
**
4144 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4145 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4147 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4148 struct plt_entry
**local_plt
;
4149 unsigned char *local_got_tls_masks
;
4151 if (local_got_ents
== NULL
)
4153 bfd_size_type size
= symtab_hdr
->sh_info
;
4155 size
*= (sizeof (*local_got_ents
)
4156 + sizeof (*local_plt
)
4157 + sizeof (*local_got_tls_masks
));
4158 local_got_ents
= bfd_zalloc (abfd
, size
);
4159 if (local_got_ents
== NULL
)
4161 elf_local_got_ents (abfd
) = local_got_ents
;
4164 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
4166 struct got_entry
*ent
;
4168 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4169 if (ent
->addend
== r_addend
4170 && ent
->owner
== abfd
4171 && ent
->tls_type
== tls_type
)
4175 bfd_size_type amt
= sizeof (*ent
);
4176 ent
= bfd_alloc (abfd
, amt
);
4179 ent
->next
= local_got_ents
[r_symndx
];
4180 ent
->addend
= r_addend
;
4182 ent
->tls_type
= tls_type
;
4183 ent
->is_indirect
= FALSE
;
4184 ent
->got
.refcount
= 0;
4185 local_got_ents
[r_symndx
] = ent
;
4187 ent
->got
.refcount
+= 1;
4190 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
4191 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
4192 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
4194 return local_plt
+ r_symndx
;
4198 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
4200 struct plt_entry
*ent
;
4202 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
4203 if (ent
->addend
== addend
)
4207 bfd_size_type amt
= sizeof (*ent
);
4208 ent
= bfd_alloc (abfd
, amt
);
4212 ent
->addend
= addend
;
4213 ent
->plt
.refcount
= 0;
4216 ent
->plt
.refcount
+= 1;
4221 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
4223 return (r_type
== R_PPC64_REL24
4224 || r_type
== R_PPC64_REL24_NOTOC
4225 || r_type
== R_PPC64_REL14
4226 || r_type
== R_PPC64_REL14_BRTAKEN
4227 || r_type
== R_PPC64_REL14_BRNTAKEN
4228 || r_type
== R_PPC64_ADDR24
4229 || r_type
== R_PPC64_ADDR14
4230 || r_type
== R_PPC64_ADDR14_BRTAKEN
4231 || r_type
== R_PPC64_ADDR14_BRNTAKEN
4232 || r_type
== R_PPC64_PLTCALL
);
4235 /* Relocs on inline plt call sequence insns prior to the call. */
4238 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
4240 return (r_type
== R_PPC64_PLT16_HA
4241 || r_type
== R_PPC64_PLT16_HI
4242 || r_type
== R_PPC64_PLT16_LO
4243 || r_type
== R_PPC64_PLT16_LO_DS
4244 || r_type
== R_PPC64_PLTSEQ
);
4247 /* Look through the relocs for a section during the first phase, and
4248 calculate needed space in the global offset table, procedure
4249 linkage table, and dynamic reloc sections. */
4252 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4253 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4255 struct ppc_link_hash_table
*htab
;
4256 Elf_Internal_Shdr
*symtab_hdr
;
4257 struct elf_link_hash_entry
**sym_hashes
;
4258 const Elf_Internal_Rela
*rel
;
4259 const Elf_Internal_Rela
*rel_end
;
4261 struct elf_link_hash_entry
*tga
, *dottga
;
4264 if (bfd_link_relocatable (info
))
4267 /* Don't do anything special with non-loaded, non-alloced sections.
4268 In particular, any relocs in such sections should not affect GOT
4269 and PLT reference counting (ie. we don't allow them to create GOT
4270 or PLT entries), there's no possibility or desire to optimize TLS
4271 relocs, and there's not much point in propagating relocs to shared
4272 libs that the dynamic linker won't relocate. */
4273 if ((sec
->flags
& SEC_ALLOC
) == 0)
4276 BFD_ASSERT (is_ppc64_elf (abfd
));
4278 htab
= ppc_hash_table (info
);
4282 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4283 FALSE
, FALSE
, TRUE
);
4284 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
4285 FALSE
, FALSE
, TRUE
);
4286 symtab_hdr
= &elf_symtab_hdr (abfd
);
4287 sym_hashes
= elf_sym_hashes (abfd
);
4289 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
4290 rel_end
= relocs
+ sec
->reloc_count
;
4291 for (rel
= relocs
; rel
< rel_end
; rel
++)
4293 unsigned long r_symndx
;
4294 struct elf_link_hash_entry
*h
;
4295 enum elf_ppc64_reloc_type r_type
;
4297 struct _ppc64_elf_section_data
*ppc64_sec
;
4298 struct plt_entry
**ifunc
, **plt_list
;
4300 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4301 if (r_symndx
< symtab_hdr
->sh_info
)
4305 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4306 h
= elf_follow_link (h
);
4308 if (h
== htab
->elf
.hgot
)
4309 sec
->has_toc_reloc
= 1;
4316 if (h
->type
== STT_GNU_IFUNC
)
4319 ifunc
= &h
->plt
.plist
;
4324 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4329 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
4331 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4333 NON_GOT
| PLT_IFUNC
);
4339 r_type
= ELF64_R_TYPE (rel
->r_info
);
4344 /* These special tls relocs tie a call to __tls_get_addr with
4345 its parameter symbol. */
4347 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
4349 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4351 NON_GOT
| TLS_TLS
| TLS_MARK
))
4353 sec
->has_tls_reloc
= 1;
4356 case R_PPC64_GOT_TLSLD16
:
4357 case R_PPC64_GOT_TLSLD16_LO
:
4358 case R_PPC64_GOT_TLSLD16_HI
:
4359 case R_PPC64_GOT_TLSLD16_HA
:
4360 tls_type
= TLS_TLS
| TLS_LD
;
4363 case R_PPC64_GOT_TLSGD16
:
4364 case R_PPC64_GOT_TLSGD16_LO
:
4365 case R_PPC64_GOT_TLSGD16_HI
:
4366 case R_PPC64_GOT_TLSGD16_HA
:
4367 tls_type
= TLS_TLS
| TLS_GD
;
4370 case R_PPC64_GOT_TPREL16_DS
:
4371 case R_PPC64_GOT_TPREL16_LO_DS
:
4372 case R_PPC64_GOT_TPREL16_HI
:
4373 case R_PPC64_GOT_TPREL16_HA
:
4374 if (bfd_link_dll (info
))
4375 info
->flags
|= DF_STATIC_TLS
;
4376 tls_type
= TLS_TLS
| TLS_TPREL
;
4379 case R_PPC64_GOT_DTPREL16_DS
:
4380 case R_PPC64_GOT_DTPREL16_LO_DS
:
4381 case R_PPC64_GOT_DTPREL16_HI
:
4382 case R_PPC64_GOT_DTPREL16_HA
:
4383 tls_type
= TLS_TLS
| TLS_DTPREL
;
4385 sec
->has_tls_reloc
= 1;
4389 case R_PPC64_GOT16_DS
:
4390 case R_PPC64_GOT16_HA
:
4391 case R_PPC64_GOT16_HI
:
4392 case R_PPC64_GOT16_LO
:
4393 case R_PPC64_GOT16_LO_DS
:
4394 /* This symbol requires a global offset table entry. */
4395 sec
->has_toc_reloc
= 1;
4396 if (r_type
== R_PPC64_GOT_TLSLD16
4397 || r_type
== R_PPC64_GOT_TLSGD16
4398 || r_type
== R_PPC64_GOT_TPREL16_DS
4399 || r_type
== R_PPC64_GOT_DTPREL16_DS
4400 || r_type
== R_PPC64_GOT16
4401 || r_type
== R_PPC64_GOT16_DS
)
4403 htab
->do_multi_toc
= 1;
4404 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4407 if (ppc64_elf_tdata (abfd
)->got
== NULL
4408 && !create_got_section (abfd
, info
))
4413 struct ppc_link_hash_entry
*eh
;
4414 struct got_entry
*ent
;
4416 eh
= (struct ppc_link_hash_entry
*) h
;
4417 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4418 if (ent
->addend
== rel
->r_addend
4419 && ent
->owner
== abfd
4420 && ent
->tls_type
== tls_type
)
4424 bfd_size_type amt
= sizeof (*ent
);
4425 ent
= bfd_alloc (abfd
, amt
);
4428 ent
->next
= eh
->elf
.got
.glist
;
4429 ent
->addend
= rel
->r_addend
;
4431 ent
->tls_type
= tls_type
;
4432 ent
->is_indirect
= FALSE
;
4433 ent
->got
.refcount
= 0;
4434 eh
->elf
.got
.glist
= ent
;
4436 ent
->got
.refcount
+= 1;
4437 eh
->tls_mask
|= tls_type
;
4440 /* This is a global offset table entry for a local symbol. */
4441 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4442 rel
->r_addend
, tls_type
))
4445 /* We may also need a plt entry if the symbol turns out to be
4447 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
4449 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4454 case R_PPC64_PLT16_HA
:
4455 case R_PPC64_PLT16_HI
:
4456 case R_PPC64_PLT16_LO
:
4457 case R_PPC64_PLT16_LO_DS
:
4460 /* This symbol requires a procedure linkage table entry. */
4465 if (h
->root
.root
.string
[0] == '.'
4466 && h
->root
.root
.string
[1] != '\0')
4467 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4468 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= PLT_KEEP
;
4469 plt_list
= &h
->plt
.plist
;
4471 if (plt_list
== NULL
)
4472 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4474 NON_GOT
| PLT_KEEP
);
4475 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4479 /* The following relocations don't need to propagate the
4480 relocation if linking a shared object since they are
4481 section relative. */
4482 case R_PPC64_SECTOFF
:
4483 case R_PPC64_SECTOFF_LO
:
4484 case R_PPC64_SECTOFF_HI
:
4485 case R_PPC64_SECTOFF_HA
:
4486 case R_PPC64_SECTOFF_DS
:
4487 case R_PPC64_SECTOFF_LO_DS
:
4488 case R_PPC64_DTPREL16
:
4489 case R_PPC64_DTPREL16_LO
:
4490 case R_PPC64_DTPREL16_HI
:
4491 case R_PPC64_DTPREL16_HA
:
4492 case R_PPC64_DTPREL16_DS
:
4493 case R_PPC64_DTPREL16_LO_DS
:
4494 case R_PPC64_DTPREL16_HIGH
:
4495 case R_PPC64_DTPREL16_HIGHA
:
4496 case R_PPC64_DTPREL16_HIGHER
:
4497 case R_PPC64_DTPREL16_HIGHERA
:
4498 case R_PPC64_DTPREL16_HIGHEST
:
4499 case R_PPC64_DTPREL16_HIGHESTA
:
4504 case R_PPC64_REL16_LO
:
4505 case R_PPC64_REL16_HI
:
4506 case R_PPC64_REL16_HA
:
4507 case R_PPC64_REL16_HIGH
:
4508 case R_PPC64_REL16_HIGHA
:
4509 case R_PPC64_REL16_HIGHER
:
4510 case R_PPC64_REL16_HIGHERA
:
4511 case R_PPC64_REL16_HIGHEST
:
4512 case R_PPC64_REL16_HIGHESTA
:
4513 case R_PPC64_REL16DX_HA
:
4516 /* Not supported as a dynamic relocation. */
4517 case R_PPC64_ADDR64_LOCAL
:
4518 if (bfd_link_pic (info
))
4520 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
4522 /* xgettext:c-format */
4523 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
4524 "in shared libraries and PIEs\n"),
4525 abfd
, sec
, rel
->r_offset
,
4526 ppc64_elf_howto_table
[r_type
]->name
);
4527 bfd_set_error (bfd_error_bad_value
);
4533 case R_PPC64_TOC16_DS
:
4534 htab
->do_multi_toc
= 1;
4535 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
4537 case R_PPC64_TOC16_LO
:
4538 case R_PPC64_TOC16_HI
:
4539 case R_PPC64_TOC16_HA
:
4540 case R_PPC64_TOC16_LO_DS
:
4541 sec
->has_toc_reloc
= 1;
4548 /* This relocation describes the C++ object vtable hierarchy.
4549 Reconstruct it for later use during GC. */
4550 case R_PPC64_GNU_VTINHERIT
:
4551 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4555 /* This relocation describes which C++ vtable entries are actually
4556 used. Record for later use during GC. */
4557 case R_PPC64_GNU_VTENTRY
:
4558 BFD_ASSERT (h
!= NULL
);
4560 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4565 case R_PPC64_REL14_BRTAKEN
:
4566 case R_PPC64_REL14_BRNTAKEN
:
4568 asection
*dest
= NULL
;
4570 /* Heuristic: If jumping outside our section, chances are
4571 we are going to need a stub. */
4574 /* If the sym is weak it may be overridden later, so
4575 don't assume we know where a weak sym lives. */
4576 if (h
->root
.type
== bfd_link_hash_defined
)
4577 dest
= h
->root
.u
.def
.section
;
4581 Elf_Internal_Sym
*isym
;
4583 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4588 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4592 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4596 case R_PPC64_PLTCALL
:
4597 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
4601 case R_PPC64_REL24_NOTOC
:
4607 if (h
->root
.root
.string
[0] == '.'
4608 && h
->root
.root
.string
[1] != '\0')
4609 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4611 if (h
== tga
|| h
== dottga
)
4613 sec
->has_tls_reloc
= 1;
4615 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
4616 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
4617 /* We have a new-style __tls_get_addr call with
4621 /* Mark this section as having an old-style call. */
4622 sec
->has_tls_get_addr_call
= 1;
4624 plt_list
= &h
->plt
.plist
;
4627 /* We may need a .plt entry if the function this reloc
4628 refers to is in a shared lib. */
4630 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
4634 case R_PPC64_ADDR14
:
4635 case R_PPC64_ADDR14_BRNTAKEN
:
4636 case R_PPC64_ADDR14_BRTAKEN
:
4637 case R_PPC64_ADDR24
:
4640 case R_PPC64_TPREL64
:
4641 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4642 if (bfd_link_dll (info
))
4643 info
->flags
|= DF_STATIC_TLS
;
4646 case R_PPC64_DTPMOD64
:
4647 if (rel
+ 1 < rel_end
4648 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4649 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4650 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4652 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4655 case R_PPC64_DTPREL64
:
4656 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4658 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4659 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4660 /* This is the second reloc of a dtpmod, dtprel pair.
4661 Don't mark with TLS_DTPREL. */
4665 sec
->has_tls_reloc
= 1;
4668 struct ppc_link_hash_entry
*eh
;
4669 eh
= (struct ppc_link_hash_entry
*) h
;
4670 eh
->tls_mask
|= tls_type
;
4673 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4674 rel
->r_addend
, tls_type
))
4677 ppc64_sec
= ppc64_elf_section_data (sec
);
4678 if (ppc64_sec
->sec_type
!= sec_toc
)
4682 /* One extra to simplify get_tls_mask. */
4683 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
4684 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
4685 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
4687 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
4688 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
4689 if (ppc64_sec
->u
.toc
.add
== NULL
)
4691 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4692 ppc64_sec
->sec_type
= sec_toc
;
4694 BFD_ASSERT (rel
->r_offset
% 8 == 0);
4695 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
4696 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
4698 /* Mark the second slot of a GD or LD entry.
4699 -1 to indicate GD and -2 to indicate LD. */
4700 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
4701 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
4702 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
4703 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
4706 case R_PPC64_TPREL16
:
4707 case R_PPC64_TPREL16_LO
:
4708 case R_PPC64_TPREL16_HI
:
4709 case R_PPC64_TPREL16_HA
:
4710 case R_PPC64_TPREL16_DS
:
4711 case R_PPC64_TPREL16_LO_DS
:
4712 case R_PPC64_TPREL16_HIGH
:
4713 case R_PPC64_TPREL16_HIGHA
:
4714 case R_PPC64_TPREL16_HIGHER
:
4715 case R_PPC64_TPREL16_HIGHERA
:
4716 case R_PPC64_TPREL16_HIGHEST
:
4717 case R_PPC64_TPREL16_HIGHESTA
:
4718 if (bfd_link_dll (info
))
4719 info
->flags
|= DF_STATIC_TLS
;
4722 case R_PPC64_ADDR64
:
4724 && rel
+ 1 < rel_end
4725 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
4728 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4732 case R_PPC64_ADDR16
:
4733 case R_PPC64_ADDR16_DS
:
4734 case R_PPC64_ADDR16_HA
:
4735 case R_PPC64_ADDR16_HI
:
4736 case R_PPC64_ADDR16_HIGH
:
4737 case R_PPC64_ADDR16_HIGHA
:
4738 case R_PPC64_ADDR16_HIGHER
:
4739 case R_PPC64_ADDR16_HIGHERA
:
4740 case R_PPC64_ADDR16_HIGHEST
:
4741 case R_PPC64_ADDR16_HIGHESTA
:
4742 case R_PPC64_ADDR16_LO
:
4743 case R_PPC64_ADDR16_LO_DS
:
4744 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
4745 && rel
->r_addend
== 0)
4747 /* We may need a .plt entry if this reloc refers to a
4748 function in a shared lib. */
4749 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
4751 h
->pointer_equality_needed
= 1;
4758 case R_PPC64_ADDR32
:
4759 case R_PPC64_UADDR16
:
4760 case R_PPC64_UADDR32
:
4761 case R_PPC64_UADDR64
:
4763 if (h
!= NULL
&& !bfd_link_pic (info
))
4764 /* We may need a copy reloc. */
4767 /* Don't propagate .opd relocs. */
4768 if (NO_OPD_RELOCS
&& is_opd
)
4771 /* If we are creating a shared library, and this is a reloc
4772 against a global symbol, or a non PC relative reloc
4773 against a local symbol, then we need to copy the reloc
4774 into the shared library. However, if we are linking with
4775 -Bsymbolic, we do not need to copy a reloc against a
4776 global symbol which is defined in an object we are
4777 including in the link (i.e., DEF_REGULAR is set). At
4778 this point we have not seen all the input files, so it is
4779 possible that DEF_REGULAR is not set now but will be set
4780 later (it is never cleared). In case of a weak definition,
4781 DEF_REGULAR may be cleared later by a strong definition in
4782 a shared library. We account for that possibility below by
4783 storing information in the dyn_relocs field of the hash
4784 table entry. A similar situation occurs when creating
4785 shared libraries and symbol visibility changes render the
4788 If on the other hand, we are creating an executable, we
4789 may need to keep relocations for symbols satisfied by a
4790 dynamic library if we manage to avoid copy relocs for the
4793 if ((bfd_link_pic (info
)
4794 && (must_be_dyn_reloc (info
, r_type
)
4796 && (!SYMBOLIC_BIND (info
, h
)
4797 || h
->root
.type
== bfd_link_hash_defweak
4798 || !h
->def_regular
))))
4799 || (ELIMINATE_COPY_RELOCS
4800 && !bfd_link_pic (info
)
4802 && (h
->root
.type
== bfd_link_hash_defweak
4803 || !h
->def_regular
))
4804 || (!bfd_link_pic (info
)
4807 /* We must copy these reloc types into the output file.
4808 Create a reloc section in dynobj and make room for
4812 sreloc
= _bfd_elf_make_dynamic_reloc_section
4813 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
4819 /* If this is a global symbol, we count the number of
4820 relocations we need for this symbol. */
4823 struct elf_dyn_relocs
*p
;
4824 struct elf_dyn_relocs
**head
;
4826 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4828 if (p
== NULL
|| p
->sec
!= sec
)
4830 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4840 if (!must_be_dyn_reloc (info
, r_type
))
4845 /* Track dynamic relocs needed for local syms too.
4846 We really need local syms available to do this
4848 struct ppc_dyn_relocs
*p
;
4849 struct ppc_dyn_relocs
**head
;
4850 bfd_boolean is_ifunc
;
4853 Elf_Internal_Sym
*isym
;
4855 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
4860 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
4864 vpp
= &elf_section_data (s
)->local_dynrel
;
4865 head
= (struct ppc_dyn_relocs
**) vpp
;
4866 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
4868 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
4870 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
4872 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4878 p
->ifunc
= is_ifunc
;
4894 /* Merge backend specific data from an object file to the output
4895 object file when linking. */
4898 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
4900 bfd
*obfd
= info
->output_bfd
;
4901 unsigned long iflags
, oflags
;
4903 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
4906 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
4909 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
4912 iflags
= elf_elfheader (ibfd
)->e_flags
;
4913 oflags
= elf_elfheader (obfd
)->e_flags
;
4915 if (iflags
& ~EF_PPC64_ABI
)
4918 /* xgettext:c-format */
4919 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
4920 bfd_set_error (bfd_error_bad_value
);
4923 else if (iflags
!= oflags
&& iflags
!= 0)
4926 /* xgettext:c-format */
4927 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
4928 ibfd
, iflags
, oflags
);
4929 bfd_set_error (bfd_error_bad_value
);
4933 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
4936 /* Merge Tag_compatibility attributes and any common GNU ones. */
4937 return _bfd_elf_merge_object_attributes (ibfd
, info
);
4941 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
4943 /* Print normal ELF private data. */
4944 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
4946 if (elf_elfheader (abfd
)->e_flags
!= 0)
4950 fprintf (file
, _("private flags = 0x%lx:"),
4951 elf_elfheader (abfd
)->e_flags
);
4953 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
4954 fprintf (file
, _(" [abiv%ld]"),
4955 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
4962 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4963 of the code entry point, and its section, which must be in the same
4964 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
4967 opd_entry_value (asection
*opd_sec
,
4969 asection
**code_sec
,
4971 bfd_boolean in_code_sec
)
4973 bfd
*opd_bfd
= opd_sec
->owner
;
4974 Elf_Internal_Rela
*relocs
;
4975 Elf_Internal_Rela
*lo
, *hi
, *look
;
4978 /* No relocs implies we are linking a --just-symbols object, or looking
4979 at a final linked executable with addr2line or somesuch. */
4980 if (opd_sec
->reloc_count
== 0)
4982 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
4984 if (contents
== NULL
)
4986 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
4987 return (bfd_vma
) -1;
4988 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
4991 /* PR 17512: file: 64b9dfbb. */
4992 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
4993 return (bfd_vma
) -1;
4995 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
4996 if (code_sec
!= NULL
)
4998 asection
*sec
, *likely
= NULL
;
5004 && val
< sec
->vma
+ sec
->size
)
5010 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5012 && (sec
->flags
& SEC_LOAD
) != 0
5013 && (sec
->flags
& SEC_ALLOC
) != 0)
5018 if (code_off
!= NULL
)
5019 *code_off
= val
- likely
->vma
;
5025 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
5027 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
5029 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
5030 /* PR 17512: file: df8e1fd6. */
5032 return (bfd_vma
) -1;
5034 /* Go find the opd reloc at the sym address. */
5036 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
5040 look
= lo
+ (hi
- lo
) / 2;
5041 if (look
->r_offset
< offset
)
5043 else if (look
->r_offset
> offset
)
5047 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
5049 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
5050 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5052 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5053 asection
*sec
= NULL
;
5055 if (symndx
>= symtab_hdr
->sh_info
5056 && elf_sym_hashes (opd_bfd
) != NULL
)
5058 struct elf_link_hash_entry
**sym_hashes
;
5059 struct elf_link_hash_entry
*rh
;
5061 sym_hashes
= elf_sym_hashes (opd_bfd
);
5062 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5065 rh
= elf_follow_link (rh
);
5066 if (rh
->root
.type
!= bfd_link_hash_defined
5067 && rh
->root
.type
!= bfd_link_hash_defweak
)
5069 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
5071 val
= rh
->root
.u
.def
.value
;
5072 sec
= rh
->root
.u
.def
.section
;
5079 Elf_Internal_Sym
*sym
;
5081 if (symndx
< symtab_hdr
->sh_info
)
5083 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5086 size_t symcnt
= symtab_hdr
->sh_info
;
5087 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5092 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5098 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5104 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5107 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5108 val
= sym
->st_value
;
5111 val
+= look
->r_addend
;
5112 if (code_off
!= NULL
)
5114 if (code_sec
!= NULL
)
5116 if (in_code_sec
&& *code_sec
!= sec
)
5121 if (sec
->output_section
!= NULL
)
5122 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5131 /* If the ELF symbol SYM might be a function in SEC, return the
5132 function size and set *CODE_OFF to the function's entry point,
5133 otherwise return zero. */
5135 static bfd_size_type
5136 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
5141 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
5142 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
5146 if (!(sym
->flags
& BSF_SYNTHETIC
))
5147 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
5149 if (strcmp (sym
->section
->name
, ".opd") == 0)
5151 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
5152 bfd_vma symval
= sym
->value
;
5155 && opd
->adjust
!= NULL
5156 && elf_section_data (sym
->section
)->relocs
!= NULL
)
5158 /* opd_entry_value will use cached relocs that have been
5159 adjusted, but with raw symbols. That means both local
5160 and global symbols need adjusting. */
5161 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
5167 if (opd_entry_value (sym
->section
, symval
,
5168 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
5170 /* An old ABI binary with dot-syms has a size of 24 on the .opd
5171 symbol. This size has nothing to do with the code size of the
5172 function, which is what we're supposed to return, but the
5173 code size isn't available without looking up the dot-sym.
5174 However, doing that would be a waste of time particularly
5175 since elf_find_function will look at the dot-sym anyway.
5176 Now, elf_find_function will keep the largest size of any
5177 function sym found at the code address of interest, so return
5178 1 here to avoid it incorrectly caching a larger function size
5179 for a small function. This does mean we return the wrong
5180 size for a new-ABI function of size 24, but all that does is
5181 disable caching for such functions. */
5187 if (sym
->section
!= sec
)
5189 *code_off
= sym
->value
;
5196 /* Return true if symbol is a strong function defined in an ELFv2
5197 object with st_other localentry bits of zero, ie. its local entry
5198 point coincides with its global entry point. */
5201 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
5204 && h
->type
== STT_FUNC
5205 && h
->root
.type
== bfd_link_hash_defined
5206 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
5207 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
5208 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
5209 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
5212 /* Return true if symbol is defined in a regular object file. */
5215 is_static_defined (struct elf_link_hash_entry
*h
)
5217 return ((h
->root
.type
== bfd_link_hash_defined
5218 || h
->root
.type
== bfd_link_hash_defweak
)
5219 && h
->root
.u
.def
.section
!= NULL
5220 && h
->root
.u
.def
.section
->output_section
!= NULL
);
5223 /* If FDH is a function descriptor symbol, return the associated code
5224 entry symbol if it is defined. Return NULL otherwise. */
5226 static struct ppc_link_hash_entry
*
5227 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
5229 if (fdh
->is_func_descriptor
)
5231 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
5232 if (fh
->elf
.root
.type
== bfd_link_hash_defined
5233 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5239 /* If FH is a function code entry symbol, return the associated
5240 function descriptor symbol if it is defined. Return NULL otherwise. */
5242 static struct ppc_link_hash_entry
*
5243 defined_func_desc (struct ppc_link_hash_entry
*fh
)
5246 && fh
->oh
->is_func_descriptor
)
5248 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
5249 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
5250 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5256 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
5258 /* Garbage collect sections, after first dealing with dot-symbols. */
5261 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
5263 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5265 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
5267 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5268 htab
->need_func_desc_adj
= 0;
5270 return bfd_elf_gc_sections (abfd
, info
);
5273 /* Mark all our entry sym sections, both opd and code section. */
5276 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
5278 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5279 struct bfd_sym_chain
*sym
;
5284 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
5286 struct ppc_link_hash_entry
*eh
, *fh
;
5289 eh
= (struct ppc_link_hash_entry
*)
5290 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
5293 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5294 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5297 fh
= defined_code_entry (eh
);
5300 sec
= fh
->elf
.root
.u
.def
.section
;
5301 sec
->flags
|= SEC_KEEP
;
5303 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5304 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5305 eh
->elf
.root
.u
.def
.value
,
5306 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5307 sec
->flags
|= SEC_KEEP
;
5309 sec
= eh
->elf
.root
.u
.def
.section
;
5310 sec
->flags
|= SEC_KEEP
;
5314 /* Mark sections containing dynamically referenced symbols. When
5315 building shared libraries, we must assume that any visible symbol is
5319 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5321 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5322 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5323 struct ppc_link_hash_entry
*fdh
;
5324 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
5326 /* Dynamic linking info is on the func descriptor sym. */
5327 fdh
= defined_func_desc (eh
);
5331 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5332 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5333 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
5334 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
5335 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5336 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
5337 && (!bfd_link_executable (info
)
5338 || info
->gc_keep_exported
5339 || info
->export_dynamic
5342 && (*d
->match
) (&d
->head
, NULL
,
5343 eh
->elf
.root
.root
.string
)))
5344 && (eh
->elf
.versioned
>= versioned
5345 || !bfd_hide_sym_by_version (info
->version_info
,
5346 eh
->elf
.root
.root
.string
)))))
5349 struct ppc_link_hash_entry
*fh
;
5351 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5353 /* Function descriptor syms cause the associated
5354 function code sym section to be marked. */
5355 fh
= defined_code_entry (eh
);
5358 code_sec
= fh
->elf
.root
.u
.def
.section
;
5359 code_sec
->flags
|= SEC_KEEP
;
5361 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5362 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5363 eh
->elf
.root
.u
.def
.value
,
5364 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
5365 code_sec
->flags
|= SEC_KEEP
;
5371 /* Return the section that should be marked against GC for a given
5375 ppc64_elf_gc_mark_hook (asection
*sec
,
5376 struct bfd_link_info
*info
,
5377 Elf_Internal_Rela
*rel
,
5378 struct elf_link_hash_entry
*h
,
5379 Elf_Internal_Sym
*sym
)
5383 /* Syms return NULL if we're marking .opd, so we avoid marking all
5384 function sections, as all functions are referenced in .opd. */
5386 if (get_opd_info (sec
) != NULL
)
5391 enum elf_ppc64_reloc_type r_type
;
5392 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
5394 r_type
= ELF64_R_TYPE (rel
->r_info
);
5397 case R_PPC64_GNU_VTINHERIT
:
5398 case R_PPC64_GNU_VTENTRY
:
5402 switch (h
->root
.type
)
5404 case bfd_link_hash_defined
:
5405 case bfd_link_hash_defweak
:
5406 eh
= (struct ppc_link_hash_entry
*) h
;
5407 fdh
= defined_func_desc (eh
);
5410 /* -mcall-aixdesc code references the dot-symbol on
5411 a call reloc. Mark the function descriptor too
5412 against garbage collection. */
5414 if (fdh
->elf
.is_weakalias
)
5415 weakdef (&fdh
->elf
)->mark
= 1;
5419 /* Function descriptor syms cause the associated
5420 function code sym section to be marked. */
5421 fh
= defined_code_entry (eh
);
5424 /* They also mark their opd section. */
5425 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5427 rsec
= fh
->elf
.root
.u
.def
.section
;
5429 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5430 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5431 eh
->elf
.root
.u
.def
.value
,
5432 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
5433 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
5435 rsec
= h
->root
.u
.def
.section
;
5438 case bfd_link_hash_common
:
5439 rsec
= h
->root
.u
.c
.p
->section
;
5443 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
5449 struct _opd_sec_data
*opd
;
5451 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5452 opd
= get_opd_info (rsec
);
5453 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
5457 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
5464 /* The maximum size of .sfpr. */
5465 #define SFPR_MAX (218*4)
5467 struct sfpr_def_parms
5469 const char name
[12];
5470 unsigned char lo
, hi
;
5471 bfd_byte
*(*write_ent
) (bfd
*, bfd_byte
*, int);
5472 bfd_byte
*(*write_tail
) (bfd
*, bfd_byte
*, int);
5475 /* Auto-generate _save*, _rest* functions in .sfpr.
5476 If STUB_SEC is non-null, define alias symbols in STUB_SEC
5480 sfpr_define (struct bfd_link_info
*info
,
5481 const struct sfpr_def_parms
*parm
,
5484 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5486 size_t len
= strlen (parm
->name
);
5487 bfd_boolean writing
= FALSE
;
5493 memcpy (sym
, parm
->name
, len
);
5496 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5498 struct ppc_link_hash_entry
*h
;
5500 sym
[len
+ 0] = i
/ 10 + '0';
5501 sym
[len
+ 1] = i
% 10 + '0';
5502 h
= (struct ppc_link_hash_entry
*)
5503 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
5504 if (stub_sec
!= NULL
)
5507 && h
->elf
.root
.type
== bfd_link_hash_defined
5508 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
5510 struct elf_link_hash_entry
*s
;
5512 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
5513 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
5516 if (s
->root
.type
== bfd_link_hash_new
5517 || (s
->root
.type
= bfd_link_hash_defined
5518 && s
->root
.u
.def
.section
== stub_sec
))
5520 s
->root
.type
= bfd_link_hash_defined
;
5521 s
->root
.u
.def
.section
= stub_sec
;
5522 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
5523 + h
->elf
.root
.u
.def
.value
);
5526 s
->ref_regular_nonweak
= 1;
5527 s
->forced_local
= 1;
5529 s
->root
.linker_def
= 1;
5537 if (!h
->elf
.def_regular
)
5539 h
->elf
.root
.type
= bfd_link_hash_defined
;
5540 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
5541 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
5542 h
->elf
.type
= STT_FUNC
;
5543 h
->elf
.def_regular
= 1;
5545 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
5547 if (htab
->sfpr
->contents
== NULL
)
5549 htab
->sfpr
->contents
5550 = bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5551 if (htab
->sfpr
->contents
== NULL
)
5558 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5560 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5562 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5563 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5571 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5573 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5578 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5580 p
= savegpr0 (abfd
, p
, r
);
5581 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5583 bfd_put_32 (abfd
, BLR
, p
);
5588 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5590 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5595 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5597 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5599 p
= restgpr0 (abfd
, p
, r
);
5600 bfd_put_32 (abfd
, MTLR_R0
, p
);
5604 p
= restgpr0 (abfd
, p
, 30);
5605 p
= restgpr0 (abfd
, p
, 31);
5607 bfd_put_32 (abfd
, BLR
, p
);
5612 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5614 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5619 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5621 p
= savegpr1 (abfd
, p
, r
);
5622 bfd_put_32 (abfd
, BLR
, p
);
5627 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5629 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5634 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5636 p
= restgpr1 (abfd
, p
, r
);
5637 bfd_put_32 (abfd
, BLR
, p
);
5642 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5644 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5649 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5651 p
= savefpr (abfd
, p
, r
);
5652 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
5654 bfd_put_32 (abfd
, BLR
, p
);
5659 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5661 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5666 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5668 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
5670 p
= restfpr (abfd
, p
, r
);
5671 bfd_put_32 (abfd
, MTLR_R0
, p
);
5675 p
= restfpr (abfd
, p
, 30);
5676 p
= restfpr (abfd
, p
, 31);
5678 bfd_put_32 (abfd
, BLR
, p
);
5683 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5685 p
= savefpr (abfd
, p
, r
);
5686 bfd_put_32 (abfd
, BLR
, p
);
5691 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5693 p
= restfpr (abfd
, p
, r
);
5694 bfd_put_32 (abfd
, BLR
, p
);
5699 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
5701 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5703 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
5708 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5710 p
= savevr (abfd
, p
, r
);
5711 bfd_put_32 (abfd
, BLR
, p
);
5716 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
5718 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5720 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
5725 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5727 p
= restvr (abfd
, p
, r
);
5728 bfd_put_32 (abfd
, BLR
, p
);
5732 /* Called via elf_link_hash_traverse to transfer dynamic linking
5733 information on function code symbol entries to their corresponding
5734 function descriptor symbol entries. */
5737 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
5739 struct bfd_link_info
*info
;
5740 struct ppc_link_hash_table
*htab
;
5741 struct ppc_link_hash_entry
*fh
;
5742 struct ppc_link_hash_entry
*fdh
;
5743 bfd_boolean force_local
;
5745 fh
= (struct ppc_link_hash_entry
*) h
;
5746 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
5752 if (fh
->elf
.root
.root
.string
[0] != '.'
5753 || fh
->elf
.root
.root
.string
[1] == '\0')
5757 htab
= ppc_hash_table (info
);
5761 /* Find the corresponding function descriptor symbol. */
5762 fdh
= lookup_fdh (fh
, htab
);
5764 /* Resolve undefined references to dot-symbols as the value
5765 in the function descriptor, if we have one in a regular object.
5766 This is to satisfy cases like ".quad .foo". Calls to functions
5767 in dynamic objects are handled elsewhere. */
5768 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
5769 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5770 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
5771 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
5772 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
5773 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
5774 fdh
->elf
.root
.u
.def
.value
,
5775 &fh
->elf
.root
.u
.def
.section
,
5776 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
5778 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
5779 fh
->elf
.forced_local
= 1;
5780 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
5781 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
5784 if (!fh
->elf
.dynamic
)
5786 struct plt_entry
*ent
;
5788 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5789 if (ent
->plt
.refcount
> 0)
5795 /* Create a descriptor as undefined if necessary. */
5797 && !bfd_link_executable (info
)
5798 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
5799 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
5801 fdh
= make_fdh (info
, fh
);
5806 /* We can't support overriding of symbols on a fake descriptor. */
5809 && (fh
->elf
.root
.type
== bfd_link_hash_defined
5810 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
5811 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
5813 /* Transfer dynamic linking information to the function descriptor. */
5816 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
5817 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
5818 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
5819 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
5820 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
5821 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
5822 || fh
->elf
.type
== STT_FUNC
5823 || fh
->elf
.type
== STT_GNU_IFUNC
);
5824 move_plt_plist (fh
, fdh
);
5826 if (!fdh
->elf
.forced_local
5827 && fh
->elf
.dynindx
!= -1)
5828 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5832 /* Now that the info is on the function descriptor, clear the
5833 function code sym info. Any function code syms for which we
5834 don't have a definition in a regular file, we force local.
5835 This prevents a shared library from exporting syms that have
5836 been imported from another library. Function code syms that
5837 are really in the library we must leave global to prevent the
5838 linker dragging in a definition from a static library. */
5839 force_local
= (!fh
->elf
.def_regular
5841 || !fdh
->elf
.def_regular
5842 || fdh
->elf
.forced_local
);
5843 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5848 static const struct sfpr_def_parms save_res_funcs
[] =
5850 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
5851 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
5852 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
5853 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
5854 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
5855 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
5856 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
5857 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
5858 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
5859 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
5860 { "_savevr_", 20, 31, savevr
, savevr_tail
},
5861 { "_restvr_", 20, 31, restvr
, restvr_tail
}
5864 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5865 this hook to a) provide some gcc support functions, and b) transfer
5866 dynamic linking information gathered so far on function code symbol
5867 entries, to their corresponding function descriptor symbol entries. */
5870 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
5871 struct bfd_link_info
*info
)
5873 struct ppc_link_hash_table
*htab
;
5875 htab
= ppc_hash_table (info
);
5879 /* Provide any missing _save* and _rest* functions. */
5880 if (htab
->sfpr
!= NULL
)
5884 htab
->sfpr
->size
= 0;
5885 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
5886 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
5888 if (htab
->sfpr
->size
== 0)
5889 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
5892 if (bfd_link_relocatable (info
))
5895 if (htab
->elf
.hgot
!= NULL
)
5897 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
5898 /* Make .TOC. defined so as to prevent it being made dynamic.
5899 The wrong value here is fixed later in ppc64_elf_set_toc. */
5900 if (!htab
->elf
.hgot
->def_regular
5901 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
5903 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
5904 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
5905 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
5906 htab
->elf
.hgot
->def_regular
= 1;
5907 htab
->elf
.hgot
->root
.linker_def
= 1;
5909 htab
->elf
.hgot
->type
= STT_OBJECT
;
5910 htab
->elf
.hgot
->other
5911 = (htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
5914 if (htab
->need_func_desc_adj
)
5916 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5917 htab
->need_func_desc_adj
= 0;
5923 /* Find dynamic relocs for H that apply to read-only sections. */
5926 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
5928 struct ppc_link_hash_entry
*eh
;
5929 struct elf_dyn_relocs
*p
;
5931 eh
= (struct ppc_link_hash_entry
*) h
;
5932 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5934 asection
*s
= p
->sec
->output_section
;
5936 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5942 /* Return true if we have dynamic relocs against H or any of its weak
5943 aliases, that apply to read-only sections. Cannot be used after
5944 size_dynamic_sections. */
5947 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
5949 struct ppc_link_hash_entry
*eh
;
5951 eh
= (struct ppc_link_hash_entry
*) h
;
5954 if (readonly_dynrelocs (&eh
->elf
))
5956 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
5958 while (eh
!= NULL
&& &eh
->elf
!= h
);
5963 /* Return whether EH has pc-relative dynamic relocs. */
5966 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
5968 struct elf_dyn_relocs
*p
;
5970 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5971 if (p
->pc_count
!= 0)
5976 /* Return true if a global entry stub will be created for H. Valid
5977 for ELFv2 before plt entries have been allocated. */
5980 global_entry_stub (struct elf_link_hash_entry
*h
)
5982 struct plt_entry
*pent
;
5984 if (!h
->pointer_equality_needed
5988 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
5989 if (pent
->plt
.refcount
> 0
5990 && pent
->addend
== 0)
5996 /* Adjust a symbol defined by a dynamic object and referenced by a
5997 regular object. The current definition is in some section of the
5998 dynamic object, but we're not including those sections. We have to
5999 change the definition to something the rest of the link can
6003 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
6004 struct elf_link_hash_entry
*h
)
6006 struct ppc_link_hash_table
*htab
;
6009 htab
= ppc_hash_table (info
);
6013 /* Deal with function syms. */
6014 if (h
->type
== STT_FUNC
6015 || h
->type
== STT_GNU_IFUNC
6018 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
6019 || SYMBOL_CALLS_LOCAL (info
, h
)
6020 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
6021 /* Discard dyn_relocs when non-pic if we've decided that a
6022 function symbol is local and not an ifunc. We keep dynamic
6023 relocs for ifuncs when local rather than always emitting a
6024 plt call stub for them and defining the symbol on the call
6025 stub. We can't do that for ELFv1 anyway (a function symbol
6026 is defined on a descriptor, not code) and it can be faster at
6027 run-time due to not needing to bounce through a stub. The
6028 dyn_relocs for ifuncs will be applied even in a static
6030 if (!bfd_link_pic (info
)
6031 && h
->type
!= STT_GNU_IFUNC
6033 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6035 /* Clear procedure linkage table information for any symbol that
6036 won't need a .plt entry. */
6037 struct plt_entry
*ent
;
6038 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6039 if (ent
->plt
.refcount
> 0)
6042 || (h
->type
!= STT_GNU_IFUNC
6044 && (htab
->can_convert_all_inline_plt
6045 || (((struct ppc_link_hash_entry
*) h
)->tls_mask
6046 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
6048 h
->plt
.plist
= NULL
;
6050 h
->pointer_equality_needed
= 0;
6052 else if (abiversion (info
->output_bfd
) >= 2)
6054 /* Taking a function's address in a read/write section
6055 doesn't require us to define the function symbol in the
6056 executable on a global entry stub. A dynamic reloc can
6057 be used instead. The reason we prefer a few more dynamic
6058 relocs is that calling via a global entry stub costs a
6059 few more instructions, and pointer_equality_needed causes
6060 extra work in ld.so when resolving these symbols. */
6061 if (global_entry_stub (h
))
6063 if (!readonly_dynrelocs (h
))
6065 h
->pointer_equality_needed
= 0;
6066 /* If we haven't seen a branch reloc and the symbol
6067 isn't an ifunc then we don't need a plt entry. */
6069 h
->plt
.plist
= NULL
;
6071 else if (!bfd_link_pic (info
))
6072 /* We are going to be defining the function symbol on the
6073 plt stub, so no dyn_relocs needed when non-pic. */
6074 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6077 /* ELFv2 function symbols can't have copy relocs. */
6080 else if (!h
->needs_plt
6081 && !readonly_dynrelocs (h
))
6083 /* If we haven't seen a branch reloc and the symbol isn't an
6084 ifunc then we don't need a plt entry. */
6085 h
->plt
.plist
= NULL
;
6086 h
->pointer_equality_needed
= 0;
6091 h
->plt
.plist
= NULL
;
6093 /* If this is a weak symbol, and there is a real definition, the
6094 processor independent code will have arranged for us to see the
6095 real definition first, and we can just use the same value. */
6096 if (h
->is_weakalias
)
6098 struct elf_link_hash_entry
*def
= weakdef (h
);
6099 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
6100 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
6101 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
6102 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
6103 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
6104 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6108 /* If we are creating a shared library, we must presume that the
6109 only references to the symbol are via the global offset table.
6110 For such cases we need not do anything here; the relocations will
6111 be handled correctly by relocate_section. */
6112 if (bfd_link_pic (info
))
6115 /* If there are no references to this symbol that do not use the
6116 GOT, we don't need to generate a copy reloc. */
6117 if (!h
->non_got_ref
)
6120 /* Don't generate a copy reloc for symbols defined in the executable. */
6121 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
6123 /* If -z nocopyreloc was given, don't generate them either. */
6124 || info
->nocopyreloc
6126 /* If we don't find any dynamic relocs in read-only sections, then
6127 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
6128 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
6130 /* Protected variables do not work with .dynbss. The copy in
6131 .dynbss won't be used by the shared library with the protected
6132 definition for the variable. Text relocations are preferable
6133 to an incorrect program. */
6134 || h
->protected_def
)
6137 if (h
->plt
.plist
!= NULL
)
6139 /* We should never get here, but unfortunately there are versions
6140 of gcc out there that improperly (for this ABI) put initialized
6141 function pointers, vtable refs and suchlike in read-only
6142 sections. Allow them to proceed, but warn that this might
6143 break at runtime. */
6144 info
->callbacks
->einfo
6145 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
6146 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
6147 h
->root
.root
.string
);
6150 /* This is a reference to a symbol defined by a dynamic object which
6151 is not a function. */
6153 /* We must allocate the symbol in our .dynbss section, which will
6154 become part of the .bss section of the executable. There will be
6155 an entry for this symbol in the .dynsym section. The dynamic
6156 object will contain position independent code, so all references
6157 from the dynamic object to this symbol will go through the global
6158 offset table. The dynamic linker will use the .dynsym entry to
6159 determine the address it must put in the global offset table, so
6160 both the dynamic object and the regular object will refer to the
6161 same memory location for the variable. */
6162 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
6164 s
= htab
->elf
.sdynrelro
;
6165 srel
= htab
->elf
.sreldynrelro
;
6169 s
= htab
->elf
.sdynbss
;
6170 srel
= htab
->elf
.srelbss
;
6172 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
6174 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
6175 linker to copy the initial value out of the dynamic object
6176 and into the runtime process image. */
6177 srel
->size
+= sizeof (Elf64_External_Rela
);
6181 /* We no longer want dyn_relocs. */
6182 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
6183 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
6186 /* If given a function descriptor symbol, hide both the function code
6187 sym and the descriptor. */
6189 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
6190 struct elf_link_hash_entry
*h
,
6191 bfd_boolean force_local
)
6193 struct ppc_link_hash_entry
*eh
;
6194 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
6196 eh
= (struct ppc_link_hash_entry
*) h
;
6197 if (eh
->is_func_descriptor
)
6199 struct ppc_link_hash_entry
*fh
= eh
->oh
;
6204 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
6207 /* We aren't supposed to use alloca in BFD because on
6208 systems which do not have alloca the version in libiberty
6209 calls xmalloc, which might cause the program to crash
6210 when it runs out of memory. This function doesn't have a
6211 return status, so there's no way to gracefully return an
6212 error. So cheat. We know that string[-1] can be safely
6213 accessed; It's either a string in an ELF string table,
6214 or allocated in an objalloc structure. */
6216 p
= eh
->elf
.root
.root
.string
- 1;
6219 fh
= (struct ppc_link_hash_entry
*)
6220 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6223 /* Unfortunately, if it so happens that the string we were
6224 looking for was allocated immediately before this string,
6225 then we overwrote the string terminator. That's the only
6226 reason the lookup should fail. */
6229 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
6230 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
6232 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
6233 fh
= (struct ppc_link_hash_entry
*)
6234 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
6243 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6248 get_sym_h (struct elf_link_hash_entry
**hp
,
6249 Elf_Internal_Sym
**symp
,
6251 unsigned char **tls_maskp
,
6252 Elf_Internal_Sym
**locsymsp
,
6253 unsigned long r_symndx
,
6256 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
6258 if (r_symndx
>= symtab_hdr
->sh_info
)
6260 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6261 struct elf_link_hash_entry
*h
;
6263 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6264 h
= elf_follow_link (h
);
6272 if (symsecp
!= NULL
)
6274 asection
*symsec
= NULL
;
6275 if (h
->root
.type
== bfd_link_hash_defined
6276 || h
->root
.type
== bfd_link_hash_defweak
)
6277 symsec
= h
->root
.u
.def
.section
;
6281 if (tls_maskp
!= NULL
)
6283 struct ppc_link_hash_entry
*eh
;
6285 eh
= (struct ppc_link_hash_entry
*) h
;
6286 *tls_maskp
= &eh
->tls_mask
;
6291 Elf_Internal_Sym
*sym
;
6292 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6294 if (locsyms
== NULL
)
6296 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6297 if (locsyms
== NULL
)
6298 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6299 symtab_hdr
->sh_info
,
6300 0, NULL
, NULL
, NULL
);
6301 if (locsyms
== NULL
)
6303 *locsymsp
= locsyms
;
6305 sym
= locsyms
+ r_symndx
;
6313 if (symsecp
!= NULL
)
6314 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6316 if (tls_maskp
!= NULL
)
6318 struct got_entry
**lgot_ents
;
6319 unsigned char *tls_mask
;
6322 lgot_ents
= elf_local_got_ents (ibfd
);
6323 if (lgot_ents
!= NULL
)
6325 struct plt_entry
**local_plt
= (struct plt_entry
**)
6326 (lgot_ents
+ symtab_hdr
->sh_info
);
6327 unsigned char *lgot_masks
= (unsigned char *)
6328 (local_plt
+ symtab_hdr
->sh_info
);
6329 tls_mask
= &lgot_masks
[r_symndx
];
6331 *tls_maskp
= tls_mask
;
6337 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6338 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6339 type suitable for optimization, and 1 otherwise. */
6342 get_tls_mask (unsigned char **tls_maskp
,
6343 unsigned long *toc_symndx
,
6344 bfd_vma
*toc_addend
,
6345 Elf_Internal_Sym
**locsymsp
,
6346 const Elf_Internal_Rela
*rel
,
6349 unsigned long r_symndx
;
6351 struct elf_link_hash_entry
*h
;
6352 Elf_Internal_Sym
*sym
;
6356 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6357 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6360 if ((*tls_maskp
!= NULL
6361 && (**tls_maskp
& TLS_TLS
) != 0
6362 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
6364 || ppc64_elf_section_data (sec
) == NULL
6365 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6368 /* Look inside a TOC section too. */
6371 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6372 off
= h
->root
.u
.def
.value
;
6375 off
= sym
->st_value
;
6376 off
+= rel
->r_addend
;
6377 BFD_ASSERT (off
% 8 == 0);
6378 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
6379 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
6380 if (toc_symndx
!= NULL
)
6381 *toc_symndx
= r_symndx
;
6382 if (toc_addend
!= NULL
)
6383 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
6384 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6386 if ((h
== NULL
|| is_static_defined (h
))
6387 && (next_r
== -1 || next_r
== -2))
6392 /* Find (or create) an entry in the tocsave hash table. */
6394 static struct tocsave_entry
*
6395 tocsave_find (struct ppc_link_hash_table
*htab
,
6396 enum insert_option insert
,
6397 Elf_Internal_Sym
**local_syms
,
6398 const Elf_Internal_Rela
*irela
,
6401 unsigned long r_indx
;
6402 struct elf_link_hash_entry
*h
;
6403 Elf_Internal_Sym
*sym
;
6404 struct tocsave_entry ent
, *p
;
6406 struct tocsave_entry
**slot
;
6408 r_indx
= ELF64_R_SYM (irela
->r_info
);
6409 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
6411 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
6414 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
6419 ent
.offset
= h
->root
.u
.def
.value
;
6421 ent
.offset
= sym
->st_value
;
6422 ent
.offset
+= irela
->r_addend
;
6424 hash
= tocsave_htab_hash (&ent
);
6425 slot
= ((struct tocsave_entry
**)
6426 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
6432 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
6441 /* Adjust all global syms defined in opd sections. In gcc generated
6442 code for the old ABI, these will already have been done. */
6445 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6447 struct ppc_link_hash_entry
*eh
;
6449 struct _opd_sec_data
*opd
;
6451 if (h
->root
.type
== bfd_link_hash_indirect
)
6454 if (h
->root
.type
!= bfd_link_hash_defined
6455 && h
->root
.type
!= bfd_link_hash_defweak
)
6458 eh
= (struct ppc_link_hash_entry
*) h
;
6459 if (eh
->adjust_done
)
6462 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6463 opd
= get_opd_info (sym_sec
);
6464 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
6466 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
6469 /* This entry has been deleted. */
6470 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6473 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6474 if (discarded_section (dsec
))
6476 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6480 eh
->elf
.root
.u
.def
.value
= 0;
6481 eh
->elf
.root
.u
.def
.section
= dsec
;
6484 eh
->elf
.root
.u
.def
.value
+= adjust
;
6485 eh
->adjust_done
= 1;
6490 /* Handles decrementing dynamic reloc counts for the reloc specified by
6491 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
6492 have already been determined. */
6495 dec_dynrel_count (bfd_vma r_info
,
6497 struct bfd_link_info
*info
,
6498 Elf_Internal_Sym
**local_syms
,
6499 struct elf_link_hash_entry
*h
,
6500 Elf_Internal_Sym
*sym
)
6502 enum elf_ppc64_reloc_type r_type
;
6503 asection
*sym_sec
= NULL
;
6505 /* Can this reloc be dynamic? This switch, and later tests here
6506 should be kept in sync with the code in check_relocs. */
6507 r_type
= ELF64_R_TYPE (r_info
);
6513 case R_PPC64_TPREL16
:
6514 case R_PPC64_TPREL16_LO
:
6515 case R_PPC64_TPREL16_HI
:
6516 case R_PPC64_TPREL16_HA
:
6517 case R_PPC64_TPREL16_DS
:
6518 case R_PPC64_TPREL16_LO_DS
:
6519 case R_PPC64_TPREL16_HIGH
:
6520 case R_PPC64_TPREL16_HIGHA
:
6521 case R_PPC64_TPREL16_HIGHER
:
6522 case R_PPC64_TPREL16_HIGHERA
:
6523 case R_PPC64_TPREL16_HIGHEST
:
6524 case R_PPC64_TPREL16_HIGHESTA
:
6525 case R_PPC64_TPREL64
:
6526 case R_PPC64_DTPMOD64
:
6527 case R_PPC64_DTPREL64
:
6528 case R_PPC64_ADDR64
:
6532 case R_PPC64_ADDR14
:
6533 case R_PPC64_ADDR14_BRNTAKEN
:
6534 case R_PPC64_ADDR14_BRTAKEN
:
6535 case R_PPC64_ADDR16
:
6536 case R_PPC64_ADDR16_DS
:
6537 case R_PPC64_ADDR16_HA
:
6538 case R_PPC64_ADDR16_HI
:
6539 case R_PPC64_ADDR16_HIGH
:
6540 case R_PPC64_ADDR16_HIGHA
:
6541 case R_PPC64_ADDR16_HIGHER
:
6542 case R_PPC64_ADDR16_HIGHERA
:
6543 case R_PPC64_ADDR16_HIGHEST
:
6544 case R_PPC64_ADDR16_HIGHESTA
:
6545 case R_PPC64_ADDR16_LO
:
6546 case R_PPC64_ADDR16_LO_DS
:
6547 case R_PPC64_ADDR24
:
6548 case R_PPC64_ADDR32
:
6549 case R_PPC64_UADDR16
:
6550 case R_PPC64_UADDR32
:
6551 case R_PPC64_UADDR64
:
6556 if (local_syms
!= NULL
)
6558 unsigned long r_symndx
;
6559 bfd
*ibfd
= sec
->owner
;
6561 r_symndx
= ELF64_R_SYM (r_info
);
6562 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6566 if ((bfd_link_pic (info
)
6567 && (must_be_dyn_reloc (info
, r_type
)
6569 && (!SYMBOLIC_BIND (info
, h
)
6570 || h
->root
.type
== bfd_link_hash_defweak
6571 || !h
->def_regular
))))
6572 || (ELIMINATE_COPY_RELOCS
6573 && !bfd_link_pic (info
)
6575 && (h
->root
.type
== bfd_link_hash_defweak
6576 || !h
->def_regular
)))
6583 struct elf_dyn_relocs
*p
;
6584 struct elf_dyn_relocs
**pp
;
6585 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6587 /* elf_gc_sweep may have already removed all dyn relocs associated
6588 with local syms for a given section. Also, symbol flags are
6589 changed by elf_gc_sweep_symbol, confusing the test above. Don't
6590 report a dynreloc miscount. */
6591 if (*pp
== NULL
&& info
->gc_sections
)
6594 while ((p
= *pp
) != NULL
)
6598 if (!must_be_dyn_reloc (info
, r_type
))
6610 struct ppc_dyn_relocs
*p
;
6611 struct ppc_dyn_relocs
**pp
;
6613 bfd_boolean is_ifunc
;
6615 if (local_syms
== NULL
)
6616 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6617 if (sym_sec
== NULL
)
6620 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6621 pp
= (struct ppc_dyn_relocs
**) vpp
;
6623 if (*pp
== NULL
&& info
->gc_sections
)
6626 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
6627 while ((p
= *pp
) != NULL
)
6629 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
6640 /* xgettext:c-format */
6641 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
6643 bfd_set_error (bfd_error_bad_value
);
6647 /* Remove unused Official Procedure Descriptor entries. Currently we
6648 only remove those associated with functions in discarded link-once
6649 sections, or weakly defined functions that have been overridden. It
6650 would be possible to remove many more entries for statically linked
6654 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
6657 bfd_boolean some_edited
= FALSE
;
6658 asection
*need_pad
= NULL
;
6659 struct ppc_link_hash_table
*htab
;
6661 htab
= ppc_hash_table (info
);
6665 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
6668 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6669 Elf_Internal_Shdr
*symtab_hdr
;
6670 Elf_Internal_Sym
*local_syms
;
6671 struct _opd_sec_data
*opd
;
6672 bfd_boolean need_edit
, add_aux_fields
, broken
;
6673 bfd_size_type cnt_16b
= 0;
6675 if (!is_ppc64_elf (ibfd
))
6678 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6679 if (sec
== NULL
|| sec
->size
== 0)
6682 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
6685 if (sec
->output_section
== bfd_abs_section_ptr
)
6688 /* Look through the section relocs. */
6689 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6693 symtab_hdr
= &elf_symtab_hdr (ibfd
);
6695 /* Read the relocations. */
6696 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6698 if (relstart
== NULL
)
6701 /* First run through the relocs to check they are sane, and to
6702 determine whether we need to edit this opd section. */
6706 relend
= relstart
+ sec
->reloc_count
;
6707 for (rel
= relstart
; rel
< relend
; )
6709 enum elf_ppc64_reloc_type r_type
;
6710 unsigned long r_symndx
;
6712 struct elf_link_hash_entry
*h
;
6713 Elf_Internal_Sym
*sym
;
6716 /* .opd contains an array of 16 or 24 byte entries. We're
6717 only interested in the reloc pointing to a function entry
6719 offset
= rel
->r_offset
;
6720 if (rel
+ 1 == relend
6721 || rel
[1].r_offset
!= offset
+ 8)
6723 /* If someone messes with .opd alignment then after a
6724 "ld -r" we might have padding in the middle of .opd.
6725 Also, there's nothing to prevent someone putting
6726 something silly in .opd with the assembler. No .opd
6727 optimization for them! */
6730 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
6735 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6736 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6739 /* xgettext:c-format */
6740 (_("%pB: unexpected reloc type %u in .opd section"),
6746 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6747 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6751 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6753 const char *sym_name
;
6755 sym_name
= h
->root
.root
.string
;
6757 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6761 /* xgettext:c-format */
6762 (_("%pB: undefined sym `%s' in .opd section"),
6768 /* opd entries are always for functions defined in the
6769 current input bfd. If the symbol isn't defined in the
6770 input bfd, then we won't be using the function in this
6771 bfd; It must be defined in a linkonce section in another
6772 bfd, or is weak. It's also possible that we are
6773 discarding the function due to a linker script /DISCARD/,
6774 which we test for via the output_section. */
6775 if (sym_sec
->owner
!= ibfd
6776 || sym_sec
->output_section
== bfd_abs_section_ptr
)
6780 if (rel
+ 1 == relend
6781 || (rel
+ 2 < relend
6782 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
6787 if (sec
->size
== offset
+ 24)
6792 if (sec
->size
== offset
+ 16)
6799 else if (rel
+ 1 < relend
6800 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
6801 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
6803 if (rel
[0].r_offset
== offset
+ 16)
6805 else if (rel
[0].r_offset
!= offset
+ 24)
6812 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
6814 if (!broken
&& (need_edit
|| add_aux_fields
))
6816 Elf_Internal_Rela
*write_rel
;
6817 Elf_Internal_Shdr
*rel_hdr
;
6818 bfd_byte
*rptr
, *wptr
;
6819 bfd_byte
*new_contents
;
6822 new_contents
= NULL
;
6823 amt
= OPD_NDX (sec
->size
) * sizeof (long);
6824 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
6825 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
6826 if (opd
->adjust
== NULL
)
6829 /* This seems a waste of time as input .opd sections are all
6830 zeros as generated by gcc, but I suppose there's no reason
6831 this will always be so. We might start putting something in
6832 the third word of .opd entries. */
6833 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
6836 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
6841 if (local_syms
!= NULL
6842 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6844 if (elf_section_data (sec
)->relocs
!= relstart
)
6848 sec
->contents
= loc
;
6849 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6852 elf_section_data (sec
)->relocs
= relstart
;
6854 new_contents
= sec
->contents
;
6857 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
6858 if (new_contents
== NULL
)
6862 wptr
= new_contents
;
6863 rptr
= sec
->contents
;
6864 write_rel
= relstart
;
6865 for (rel
= relstart
; rel
< relend
; )
6867 unsigned long r_symndx
;
6869 struct elf_link_hash_entry
*h
;
6870 struct ppc_link_hash_entry
*fdh
= NULL
;
6871 Elf_Internal_Sym
*sym
;
6873 Elf_Internal_Rela
*next_rel
;
6876 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6877 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6882 if (next_rel
+ 1 == relend
6883 || (next_rel
+ 2 < relend
6884 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
6887 /* See if the .opd entry is full 24 byte or
6888 16 byte (with fd_aux entry overlapped with next
6891 if (next_rel
== relend
)
6893 if (sec
->size
== rel
->r_offset
+ 16)
6896 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
6900 && h
->root
.root
.string
[0] == '.')
6902 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
6905 fdh
= ppc_follow_link (fdh
);
6906 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
6907 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6912 skip
= (sym_sec
->owner
!= ibfd
6913 || sym_sec
->output_section
== bfd_abs_section_ptr
);
6916 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
6918 /* Arrange for the function descriptor sym
6920 fdh
->elf
.root
.u
.def
.value
= 0;
6921 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
6923 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
6925 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
6930 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
6934 if (++rel
== next_rel
)
6937 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6938 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6945 /* We'll be keeping this opd entry. */
6950 /* Redefine the function descriptor symbol to
6951 this location in the opd section. It is
6952 necessary to update the value here rather
6953 than using an array of adjustments as we do
6954 for local symbols, because various places
6955 in the generic ELF code use the value
6956 stored in u.def.value. */
6957 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
6958 fdh
->adjust_done
= 1;
6961 /* Local syms are a bit tricky. We could
6962 tweak them as they can be cached, but
6963 we'd need to look through the local syms
6964 for the function descriptor sym which we
6965 don't have at the moment. So keep an
6966 array of adjustments. */
6967 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
6968 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
6971 memcpy (wptr
, rptr
, opd_ent_size
);
6972 wptr
+= opd_ent_size
;
6973 if (add_aux_fields
&& opd_ent_size
== 16)
6975 memset (wptr
, '\0', 8);
6979 /* We need to adjust any reloc offsets to point to the
6981 for ( ; rel
!= next_rel
; ++rel
)
6983 rel
->r_offset
+= adjust
;
6984 if (write_rel
!= rel
)
6985 memcpy (write_rel
, rel
, sizeof (*rel
));
6990 rptr
+= opd_ent_size
;
6993 sec
->size
= wptr
- new_contents
;
6994 sec
->reloc_count
= write_rel
- relstart
;
6997 free (sec
->contents
);
6998 sec
->contents
= new_contents
;
7001 /* Fudge the header size too, as this is used later in
7002 elf_bfd_final_link if we are emitting relocs. */
7003 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
7004 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
7007 else if (elf_section_data (sec
)->relocs
!= relstart
)
7010 if (local_syms
!= NULL
7011 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7013 if (!info
->keep_memory
)
7016 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7021 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
7023 /* If we are doing a final link and the last .opd entry is just 16 byte
7024 long, add a 8 byte padding after it. */
7025 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
7029 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
7031 BFD_ASSERT (need_pad
->size
> 0);
7033 p
= bfd_malloc (need_pad
->size
+ 8);
7037 if (!bfd_get_section_contents (need_pad
->owner
, need_pad
,
7038 p
, 0, need_pad
->size
))
7041 need_pad
->contents
= p
;
7042 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7046 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
7050 need_pad
->contents
= p
;
7053 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
7054 need_pad
->size
+= 8;
7060 /* Analyze inline PLT call relocations to see whether calls to locally
7061 defined functions can be converted to direct calls. */
7064 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
7066 struct ppc_link_hash_table
*htab
;
7069 bfd_vma low_vma
, high_vma
, limit
;
7071 htab
= ppc_hash_table (info
);
7075 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
7076 reduced somewhat to cater for possible stubs that might be added
7077 between the call and its destination. */
7078 if (htab
->params
->group_size
< 0)
7080 limit
= -htab
->params
->group_size
;
7086 limit
= htab
->params
->group_size
;
7093 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7094 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
7096 if (low_vma
> sec
->vma
)
7098 if (high_vma
< sec
->vma
+ sec
->size
)
7099 high_vma
= sec
->vma
+ sec
->size
;
7102 /* If a "bl" can reach anywhere in local code sections, then we can
7103 convert all inline PLT sequences to direct calls when the symbol
7105 if (high_vma
- low_vma
< limit
)
7107 htab
->can_convert_all_inline_plt
= 1;
7111 /* Otherwise, go looking through relocs for cases where a direct
7112 call won't reach. Mark the symbol on any such reloc to disable
7113 the optimization and keep the PLT entry as it seems likely that
7114 this will be better than creating trampolines. Note that this
7115 will disable the optimization for all inline PLT calls to a
7116 particular symbol, not just those that won't reach. The
7117 difficulty in doing a more precise optimization is that the
7118 linker needs to make a decision depending on whether a
7119 particular R_PPC64_PLTCALL insn can be turned into a direct
7120 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
7121 the sequence, and there is nothing that ties those relocs
7122 together except their symbol. */
7124 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7126 Elf_Internal_Shdr
*symtab_hdr
;
7127 Elf_Internal_Sym
*local_syms
;
7129 if (!is_ppc64_elf (ibfd
))
7133 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7135 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7136 if (ppc64_elf_section_data (sec
)->has_pltcall
7137 && !bfd_is_abs_section (sec
->output_section
))
7139 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7141 /* Read the relocations. */
7142 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7144 if (relstart
== NULL
)
7147 relend
= relstart
+ sec
->reloc_count
;
7148 for (rel
= relstart
; rel
< relend
; )
7150 enum elf_ppc64_reloc_type r_type
;
7151 unsigned long r_symndx
;
7153 struct elf_link_hash_entry
*h
;
7154 Elf_Internal_Sym
*sym
;
7155 unsigned char *tls_maskp
;
7157 r_type
= ELF64_R_TYPE (rel
->r_info
);
7158 if (r_type
!= R_PPC64_PLTCALL
)
7161 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7162 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
7165 if (elf_section_data (sec
)->relocs
!= relstart
)
7167 if (local_syms
!= NULL
7168 && symtab_hdr
->contents
!= (bfd_byte
*) local_syms
)
7173 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
7177 to
= h
->root
.u
.def
.value
;
7180 to
+= (rel
->r_addend
7181 + sym_sec
->output_offset
7182 + sym_sec
->output_section
->vma
);
7183 from
= (rel
->r_offset
7184 + sec
->output_offset
7185 + sec
->output_section
->vma
);
7186 if (to
- from
+ limit
< 2 * limit
)
7187 *tls_maskp
&= ~PLT_KEEP
;
7190 if (elf_section_data (sec
)->relocs
!= relstart
)
7194 if (local_syms
!= NULL
7195 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7197 if (!info
->keep_memory
)
7200 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7207 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
7210 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
7212 struct ppc_link_hash_table
*htab
;
7214 htab
= ppc_hash_table (info
);
7218 if (abiversion (info
->output_bfd
) == 1)
7221 if (htab
->params
->no_multi_toc
)
7222 htab
->do_multi_toc
= 0;
7223 else if (!htab
->do_multi_toc
)
7224 htab
->params
->no_multi_toc
= 1;
7226 /* Default to --no-plt-localentry, as this option can cause problems
7227 with symbol interposition. For example, glibc libpthread.so and
7228 libc.so duplicate many pthread symbols, with a fallback
7229 implementation in libc.so. In some cases the fallback does more
7230 work than the pthread implementation. __pthread_condattr_destroy
7231 is one such symbol: the libpthread.so implementation is
7232 localentry:0 while the libc.so implementation is localentry:8.
7233 An app that "cleverly" uses dlopen to only load necessary
7234 libraries at runtime may omit loading libpthread.so when not
7235 running multi-threaded, which then results in the libc.so
7236 fallback symbols being used and ld.so complaining. Now there
7237 are workarounds in ld (see non_zero_localentry) to detect the
7238 pthread situation, but that may not be the only case where
7239 --plt-localentry can cause trouble. */
7240 if (htab
->params
->plt_localentry0
< 0)
7241 htab
->params
->plt_localentry0
= 0;
7242 if (htab
->params
->plt_localentry0
7243 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
7244 FALSE
, FALSE
, FALSE
) == NULL
)
7246 (_("warning: --plt-localentry is especially dangerous without "
7247 "ld.so support to detect ABI violations"));
7249 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
7250 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
7251 FALSE
, FALSE
, TRUE
));
7252 /* Move dynamic linking info to the function descriptor sym. */
7253 if (htab
->tls_get_addr
!= NULL
)
7254 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
7255 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
7256 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
7257 FALSE
, FALSE
, TRUE
));
7258 if (htab
->params
->tls_get_addr_opt
)
7260 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
7262 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
7263 FALSE
, FALSE
, TRUE
);
7265 func_desc_adjust (opt
, info
);
7266 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
7267 FALSE
, FALSE
, TRUE
);
7269 && (opt_fd
->root
.type
== bfd_link_hash_defined
7270 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
7272 /* If glibc supports an optimized __tls_get_addr call stub,
7273 signalled by the presence of __tls_get_addr_opt, and we'll
7274 be calling __tls_get_addr via a plt call stub, then
7275 make __tls_get_addr point to __tls_get_addr_opt. */
7276 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
7277 if (htab
->elf
.dynamic_sections_created
7279 && (tga_fd
->type
== STT_FUNC
7280 || tga_fd
->needs_plt
)
7281 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
7282 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
7284 struct plt_entry
*ent
;
7286 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7287 if (ent
->plt
.refcount
> 0)
7291 tga_fd
->root
.type
= bfd_link_hash_indirect
;
7292 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
7293 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
7295 if (opt_fd
->dynindx
!= -1)
7297 /* Use __tls_get_addr_opt in dynamic relocations. */
7298 opt_fd
->dynindx
= -1;
7299 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
7300 opt_fd
->dynstr_index
);
7301 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
7304 htab
->tls_get_addr_fd
7305 = (struct ppc_link_hash_entry
*) opt_fd
;
7306 tga
= &htab
->tls_get_addr
->elf
;
7307 if (opt
!= NULL
&& tga
!= NULL
)
7309 tga
->root
.type
= bfd_link_hash_indirect
;
7310 tga
->root
.u
.i
.link
= &opt
->root
;
7311 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
7313 _bfd_elf_link_hash_hide_symbol (info
, opt
,
7315 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
7317 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
7318 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
7319 if (htab
->tls_get_addr
!= NULL
)
7321 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
7322 htab
->tls_get_addr
->is_func
= 1;
7327 else if (htab
->params
->tls_get_addr_opt
< 0)
7328 htab
->params
->tls_get_addr_opt
= 0;
7330 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
7333 /* Return TRUE iff REL is a branch reloc with a global symbol matching
7337 branch_reloc_hash_match (const bfd
*ibfd
,
7338 const Elf_Internal_Rela
*rel
,
7339 const struct ppc_link_hash_entry
*hash1
,
7340 const struct ppc_link_hash_entry
*hash2
)
7342 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7343 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
7344 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
7346 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
7348 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7349 struct elf_link_hash_entry
*h
;
7351 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7352 h
= elf_follow_link (h
);
7353 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
7359 /* Run through all the TLS relocs looking for optimization
7360 opportunities. The linker has been hacked (see ppc64elf.em) to do
7361 a preliminary section layout so that we know the TLS segment
7362 offsets. We can't optimize earlier because some optimizations need
7363 to know the tp offset, and we need to optimize before allocating
7364 dynamic relocations. */
7367 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
7371 struct ppc_link_hash_table
*htab
;
7372 unsigned char *toc_ref
;
7375 if (!bfd_link_executable (info
))
7378 htab
= ppc_hash_table (info
);
7382 /* Make two passes over the relocs. On the first pass, mark toc
7383 entries involved with tls relocs, and check that tls relocs
7384 involved in setting up a tls_get_addr call are indeed followed by
7385 such a call. If they are not, we can't do any tls optimization.
7386 On the second pass twiddle tls_mask flags to notify
7387 relocate_section that optimization can be done, and adjust got
7388 and plt refcounts. */
7390 for (pass
= 0; pass
< 2; ++pass
)
7391 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7393 Elf_Internal_Sym
*locsyms
= NULL
;
7394 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
7396 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7397 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
7399 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7400 bfd_boolean found_tls_get_addr_arg
= 0;
7402 /* Read the relocations. */
7403 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7405 if (relstart
== NULL
)
7411 relend
= relstart
+ sec
->reloc_count
;
7412 for (rel
= relstart
; rel
< relend
; rel
++)
7414 enum elf_ppc64_reloc_type r_type
;
7415 unsigned long r_symndx
;
7416 struct elf_link_hash_entry
*h
;
7417 Elf_Internal_Sym
*sym
;
7419 unsigned char *tls_mask
;
7420 unsigned char tls_set
, tls_clear
, tls_type
= 0;
7422 bfd_boolean ok_tprel
, is_local
;
7423 long toc_ref_index
= 0;
7424 int expecting_tls_get_addr
= 0;
7425 bfd_boolean ret
= FALSE
;
7427 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7428 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
7432 if (elf_section_data (sec
)->relocs
!= relstart
)
7434 if (toc_ref
!= NULL
)
7437 && (elf_symtab_hdr (ibfd
).contents
7438 != (unsigned char *) locsyms
))
7445 if (h
->root
.type
== bfd_link_hash_defined
7446 || h
->root
.type
== bfd_link_hash_defweak
)
7447 value
= h
->root
.u
.def
.value
;
7448 else if (h
->root
.type
== bfd_link_hash_undefweak
)
7452 found_tls_get_addr_arg
= 0;
7457 /* Symbols referenced by TLS relocs must be of type
7458 STT_TLS. So no need for .opd local sym adjust. */
7459 value
= sym
->st_value
;
7468 && h
->root
.type
== bfd_link_hash_undefweak
)
7470 else if (sym_sec
!= NULL
7471 && sym_sec
->output_section
!= NULL
)
7473 value
+= sym_sec
->output_offset
;
7474 value
+= sym_sec
->output_section
->vma
;
7475 value
-= htab
->elf
.tls_sec
->vma
;
7476 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
7477 < (bfd_vma
) 1 << 32);
7481 r_type
= ELF64_R_TYPE (rel
->r_info
);
7482 /* If this section has old-style __tls_get_addr calls
7483 without marker relocs, then check that each
7484 __tls_get_addr call reloc is preceded by a reloc
7485 that conceivably belongs to the __tls_get_addr arg
7486 setup insn. If we don't find matching arg setup
7487 relocs, don't do any tls optimization. */
7489 && sec
->has_tls_get_addr_call
7491 && (h
== &htab
->tls_get_addr
->elf
7492 || h
== &htab
->tls_get_addr_fd
->elf
)
7493 && !found_tls_get_addr_arg
7494 && is_branch_reloc (r_type
))
7496 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
7497 "TLS optimization disabled\n"),
7498 ibfd
, sec
, rel
->r_offset
);
7503 found_tls_get_addr_arg
= 0;
7506 case R_PPC64_GOT_TLSLD16
:
7507 case R_PPC64_GOT_TLSLD16_LO
:
7508 expecting_tls_get_addr
= 1;
7509 found_tls_get_addr_arg
= 1;
7512 case R_PPC64_GOT_TLSLD16_HI
:
7513 case R_PPC64_GOT_TLSLD16_HA
:
7514 /* These relocs should never be against a symbol
7515 defined in a shared lib. Leave them alone if
7516 that turns out to be the case. */
7523 tls_type
= TLS_TLS
| TLS_LD
;
7526 case R_PPC64_GOT_TLSGD16
:
7527 case R_PPC64_GOT_TLSGD16_LO
:
7528 expecting_tls_get_addr
= 1;
7529 found_tls_get_addr_arg
= 1;
7532 case R_PPC64_GOT_TLSGD16_HI
:
7533 case R_PPC64_GOT_TLSGD16_HA
:
7539 tls_set
= TLS_TLS
| TLS_TPRELGD
;
7541 tls_type
= TLS_TLS
| TLS_GD
;
7544 case R_PPC64_GOT_TPREL16_DS
:
7545 case R_PPC64_GOT_TPREL16_LO_DS
:
7546 case R_PPC64_GOT_TPREL16_HI
:
7547 case R_PPC64_GOT_TPREL16_HA
:
7552 tls_clear
= TLS_TPREL
;
7553 tls_type
= TLS_TLS
| TLS_TPREL
;
7560 if (rel
+ 1 < relend
7561 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
7564 && (ELF64_R_TYPE (rel
[1].r_info
)
7567 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
7568 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
7573 struct plt_entry
*ent
= NULL
;
7575 for (ent
= h
->plt
.plist
;
7578 if (ent
->addend
== rel
[1].r_addend
)
7582 && ent
->plt
.refcount
> 0)
7583 ent
->plt
.refcount
-= 1;
7588 found_tls_get_addr_arg
= 1;
7593 case R_PPC64_TOC16_LO
:
7594 if (sym_sec
== NULL
|| sym_sec
!= toc
)
7597 /* Mark this toc entry as referenced by a TLS
7598 code sequence. We can do that now in the
7599 case of R_PPC64_TLS, and after checking for
7600 tls_get_addr for the TOC16 relocs. */
7601 if (toc_ref
== NULL
)
7603 = bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
7604 if (toc_ref
== NULL
)
7608 value
= h
->root
.u
.def
.value
;
7610 value
= sym
->st_value
;
7611 value
+= rel
->r_addend
;
7614 BFD_ASSERT (value
< toc
->size
7615 && toc
->output_offset
% 8 == 0);
7616 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
7617 if (r_type
== R_PPC64_TLS
7618 || r_type
== R_PPC64_TLSGD
7619 || r_type
== R_PPC64_TLSLD
)
7621 toc_ref
[toc_ref_index
] = 1;
7625 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
7630 expecting_tls_get_addr
= 2;
7633 case R_PPC64_TPREL64
:
7637 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7642 tls_set
= TLS_EXPLICIT
;
7643 tls_clear
= TLS_TPREL
;
7648 case R_PPC64_DTPMOD64
:
7652 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
7654 if (rel
+ 1 < relend
7656 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7657 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7661 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7664 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7673 tls_set
= TLS_EXPLICIT
;
7684 if (!expecting_tls_get_addr
7685 || !sec
->has_tls_get_addr_call
)
7688 if (rel
+ 1 < relend
7689 && branch_reloc_hash_match (ibfd
, rel
+ 1,
7691 htab
->tls_get_addr_fd
))
7693 if (expecting_tls_get_addr
== 2)
7695 /* Check for toc tls entries. */
7696 unsigned char *toc_tls
;
7699 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
7704 if (toc_tls
!= NULL
)
7706 if ((*toc_tls
& TLS_TLS
) != 0
7707 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
7708 found_tls_get_addr_arg
= 1;
7710 toc_ref
[toc_ref_index
] = 1;
7716 /* Uh oh, we didn't find the expected call. We
7717 could just mark this symbol to exclude it
7718 from tls optimization but it's safer to skip
7719 the entire optimization. */
7720 /* xgettext:c-format */
7721 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
7722 "TLS optimization disabled\n"),
7723 ibfd
, sec
, rel
->r_offset
);
7728 /* If we don't have old-style __tls_get_addr calls
7729 without TLSGD/TLSLD marker relocs, and we haven't
7730 found a new-style __tls_get_addr call with a
7731 marker for this symbol, then we either have a
7732 broken object file or an -mlongcall style
7733 indirect call to __tls_get_addr without a marker.
7734 Disable optimization in this case. */
7735 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
7736 && (tls_set
& TLS_EXPLICIT
) == 0
7737 && !sec
->has_tls_get_addr_call
7738 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
7739 != (TLS_TLS
| TLS_MARK
)))
7742 if (expecting_tls_get_addr
)
7744 struct plt_entry
*ent
= NULL
;
7746 if (htab
->tls_get_addr
!= NULL
)
7747 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
7750 if (ent
->addend
== 0)
7753 if (ent
== NULL
&& htab
->tls_get_addr_fd
!= NULL
)
7754 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
7757 if (ent
->addend
== 0)
7761 && ent
->plt
.refcount
> 0)
7762 ent
->plt
.refcount
-= 1;
7768 if ((tls_set
& TLS_EXPLICIT
) == 0)
7770 struct got_entry
*ent
;
7772 /* Adjust got entry for this reloc. */
7776 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7778 for (; ent
!= NULL
; ent
= ent
->next
)
7779 if (ent
->addend
== rel
->r_addend
7780 && ent
->owner
== ibfd
7781 && ent
->tls_type
== tls_type
)
7788 /* We managed to get rid of a got entry. */
7789 if (ent
->got
.refcount
> 0)
7790 ent
->got
.refcount
-= 1;
7795 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7796 we'll lose one or two dyn relocs. */
7797 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7801 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7803 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7809 *tls_mask
|= tls_set
;
7810 *tls_mask
&= ~tls_clear
;
7813 if (elf_section_data (sec
)->relocs
!= relstart
)
7818 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
7820 if (!info
->keep_memory
)
7823 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
7827 if (toc_ref
!= NULL
)
7829 htab
->do_tls_opt
= 1;
7833 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7834 the values of any global symbols in a toc section that has been
7835 edited. Globals in toc sections should be a rarity, so this function
7836 sets a flag if any are found in toc sections other than the one just
7837 edited, so that further hash table traversals can be avoided. */
7839 struct adjust_toc_info
7842 unsigned long *skip
;
7843 bfd_boolean global_toc_syms
;
7846 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
7849 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7851 struct ppc_link_hash_entry
*eh
;
7852 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7855 if (h
->root
.type
!= bfd_link_hash_defined
7856 && h
->root
.type
!= bfd_link_hash_defweak
)
7859 eh
= (struct ppc_link_hash_entry
*) h
;
7860 if (eh
->adjust_done
)
7863 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7865 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
7866 i
= toc_inf
->toc
->rawsize
>> 3;
7868 i
= eh
->elf
.root
.u
.def
.value
>> 3;
7870 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
7873 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
7876 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
7877 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
7880 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
7881 eh
->adjust_done
= 1;
7883 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7884 toc_inf
->global_toc_syms
= TRUE
;
7889 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
7890 on a _LO variety toc/got reloc. */
7893 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
7895 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
7896 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
7897 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
7898 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
7899 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
7900 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
7901 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
7902 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
7903 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
7904 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
7905 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
7906 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
7907 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
7908 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
7909 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
7910 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
7911 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
7912 /* Exclude lfqu by testing reloc. If relocs are ever
7913 defined for the reduced D field in psq_lu then those
7914 will need testing too. */
7915 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
7916 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
7918 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
7919 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
7920 /* Exclude stfqu. psq_stu as above for psq_lu. */
7921 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
7922 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
7923 && (insn
& 1) == 0));
7926 /* Examine all relocs referencing .toc sections in order to remove
7927 unused .toc entries. */
7930 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
7933 struct adjust_toc_info toc_inf
;
7934 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7936 htab
->do_toc_opt
= 1;
7937 toc_inf
.global_toc_syms
= TRUE
;
7938 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7940 asection
*toc
, *sec
;
7941 Elf_Internal_Shdr
*symtab_hdr
;
7942 Elf_Internal_Sym
*local_syms
;
7943 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
7944 unsigned long *skip
, *drop
;
7945 unsigned char *used
;
7946 unsigned char *keep
, last
, some_unused
;
7948 if (!is_ppc64_elf (ibfd
))
7951 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7954 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
7955 || discarded_section (toc
))
7960 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7962 /* Look at sections dropped from the final link. */
7965 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7967 if (sec
->reloc_count
== 0
7968 || !discarded_section (sec
)
7969 || get_opd_info (sec
)
7970 || (sec
->flags
& SEC_ALLOC
) == 0
7971 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7974 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7975 if (relstart
== NULL
)
7978 /* Run through the relocs to see which toc entries might be
7980 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7982 enum elf_ppc64_reloc_type r_type
;
7983 unsigned long r_symndx
;
7985 struct elf_link_hash_entry
*h
;
7986 Elf_Internal_Sym
*sym
;
7989 r_type
= ELF64_R_TYPE (rel
->r_info
);
7996 case R_PPC64_TOC16_LO
:
7997 case R_PPC64_TOC16_HI
:
7998 case R_PPC64_TOC16_HA
:
7999 case R_PPC64_TOC16_DS
:
8000 case R_PPC64_TOC16_LO_DS
:
8004 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8005 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8013 val
= h
->root
.u
.def
.value
;
8015 val
= sym
->st_value
;
8016 val
+= rel
->r_addend
;
8018 if (val
>= toc
->size
)
8021 /* Anything in the toc ought to be aligned to 8 bytes.
8022 If not, don't mark as unused. */
8028 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8033 skip
[val
>> 3] = ref_from_discarded
;
8036 if (elf_section_data (sec
)->relocs
!= relstart
)
8040 /* For largetoc loads of address constants, we can convert
8041 . addis rx,2,addr@got@ha
8042 . ld ry,addr@got@l(rx)
8044 . addis rx,2,addr@toc@ha
8045 . addi ry,rx,addr@toc@l
8046 when addr is within 2G of the toc pointer. This then means
8047 that the word storing "addr" in the toc is no longer needed. */
8049 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8050 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8051 && toc
->reloc_count
!= 0)
8053 /* Read toc relocs. */
8054 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8056 if (toc_relocs
== NULL
)
8059 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8061 enum elf_ppc64_reloc_type r_type
;
8062 unsigned long r_symndx
;
8064 struct elf_link_hash_entry
*h
;
8065 Elf_Internal_Sym
*sym
;
8068 r_type
= ELF64_R_TYPE (rel
->r_info
);
8069 if (r_type
!= R_PPC64_ADDR64
)
8072 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8073 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8078 || sym_sec
->output_section
== NULL
8079 || discarded_section (sym_sec
))
8082 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8087 if (h
->type
== STT_GNU_IFUNC
)
8089 val
= h
->root
.u
.def
.value
;
8093 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8095 val
= sym
->st_value
;
8097 val
+= rel
->r_addend
;
8098 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8100 /* We don't yet know the exact toc pointer value, but we
8101 know it will be somewhere in the toc section. Don't
8102 optimize if the difference from any possible toc
8103 pointer is outside [ff..f80008000, 7fff7fff]. */
8104 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8105 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8108 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8109 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8114 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8119 skip
[rel
->r_offset
>> 3]
8120 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8127 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8131 if (local_syms
!= NULL
8132 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8136 && elf_section_data (sec
)->relocs
!= relstart
)
8138 if (toc_relocs
!= NULL
8139 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8146 /* Now check all kept sections that might reference the toc.
8147 Check the toc itself last. */
8148 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8151 sec
= (sec
== toc
? NULL
8152 : sec
->next
== NULL
? toc
8153 : sec
->next
== toc
&& toc
->next
? toc
->next
8158 if (sec
->reloc_count
== 0
8159 || discarded_section (sec
)
8160 || get_opd_info (sec
)
8161 || (sec
->flags
& SEC_ALLOC
) == 0
8162 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8165 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8167 if (relstart
== NULL
)
8173 /* Mark toc entries referenced as used. */
8177 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8179 enum elf_ppc64_reloc_type r_type
;
8180 unsigned long r_symndx
;
8182 struct elf_link_hash_entry
*h
;
8183 Elf_Internal_Sym
*sym
;
8185 enum {no_check
, check_lo
, check_ha
} insn_check
;
8187 r_type
= ELF64_R_TYPE (rel
->r_info
);
8191 insn_check
= no_check
;
8194 case R_PPC64_GOT_TLSLD16_HA
:
8195 case R_PPC64_GOT_TLSGD16_HA
:
8196 case R_PPC64_GOT_TPREL16_HA
:
8197 case R_PPC64_GOT_DTPREL16_HA
:
8198 case R_PPC64_GOT16_HA
:
8199 case R_PPC64_TOC16_HA
:
8200 insn_check
= check_ha
;
8203 case R_PPC64_GOT_TLSLD16_LO
:
8204 case R_PPC64_GOT_TLSGD16_LO
:
8205 case R_PPC64_GOT_TPREL16_LO_DS
:
8206 case R_PPC64_GOT_DTPREL16_LO_DS
:
8207 case R_PPC64_GOT16_LO
:
8208 case R_PPC64_GOT16_LO_DS
:
8209 case R_PPC64_TOC16_LO
:
8210 case R_PPC64_TOC16_LO_DS
:
8211 insn_check
= check_lo
;
8215 if (insn_check
!= no_check
)
8217 bfd_vma off
= rel
->r_offset
& ~3;
8218 unsigned char buf
[4];
8221 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
8226 insn
= bfd_get_32 (ibfd
, buf
);
8227 if (insn_check
== check_lo
8228 ? !ok_lo_toc_insn (insn
, r_type
)
8229 : ((insn
& ((0x3f << 26) | 0x1f << 16))
8230 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
8234 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
8235 sprintf (str
, "%#08x", insn
);
8236 info
->callbacks
->einfo
8237 /* xgettext:c-format */
8238 (_("%H: toc optimization is not supported for"
8239 " %s instruction\n"),
8240 ibfd
, sec
, rel
->r_offset
& ~3, str
);
8247 case R_PPC64_TOC16_LO
:
8248 case R_PPC64_TOC16_HI
:
8249 case R_PPC64_TOC16_HA
:
8250 case R_PPC64_TOC16_DS
:
8251 case R_PPC64_TOC16_LO_DS
:
8252 /* In case we're taking addresses of toc entries. */
8253 case R_PPC64_ADDR64
:
8260 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8261 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8272 val
= h
->root
.u
.def
.value
;
8274 val
= sym
->st_value
;
8275 val
+= rel
->r_addend
;
8277 if (val
>= toc
->size
)
8280 if ((skip
[val
>> 3] & can_optimize
) != 0)
8287 case R_PPC64_TOC16_HA
:
8290 case R_PPC64_TOC16_LO_DS
:
8291 off
= rel
->r_offset
;
8292 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
8293 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
8299 if ((opc
& (0x3f << 2)) == (58u << 2))
8304 /* Wrong sort of reloc, or not a ld. We may
8305 as well clear ref_from_discarded too. */
8312 /* For the toc section, we only mark as used if this
8313 entry itself isn't unused. */
8314 else if ((used
[rel
->r_offset
>> 3]
8315 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
8318 /* Do all the relocs again, to catch reference
8327 if (elf_section_data (sec
)->relocs
!= relstart
)
8331 /* Merge the used and skip arrays. Assume that TOC
8332 doublewords not appearing as either used or unused belong
8333 to an entry more than one doubleword in size. */
8334 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
8335 drop
< skip
+ (toc
->size
+ 7) / 8;
8340 *drop
&= ~ref_from_discarded
;
8341 if ((*drop
& can_optimize
) != 0)
8345 else if ((*drop
& ref_from_discarded
) != 0)
8348 last
= ref_from_discarded
;
8358 bfd_byte
*contents
, *src
;
8360 Elf_Internal_Sym
*sym
;
8361 bfd_boolean local_toc_syms
= FALSE
;
8363 /* Shuffle the toc contents, and at the same time convert the
8364 skip array from booleans into offsets. */
8365 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
8368 elf_section_data (toc
)->this_hdr
.contents
= contents
;
8370 for (src
= contents
, off
= 0, drop
= skip
;
8371 src
< contents
+ toc
->size
;
8374 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
8379 memcpy (src
- off
, src
, 8);
8383 toc
->rawsize
= toc
->size
;
8384 toc
->size
= src
- contents
- off
;
8386 /* Adjust addends for relocs against the toc section sym,
8387 and optimize any accesses we can. */
8388 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8390 if (sec
->reloc_count
== 0
8391 || discarded_section (sec
))
8394 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8396 if (relstart
== NULL
)
8399 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8401 enum elf_ppc64_reloc_type r_type
;
8402 unsigned long r_symndx
;
8404 struct elf_link_hash_entry
*h
;
8407 r_type
= ELF64_R_TYPE (rel
->r_info
);
8414 case R_PPC64_TOC16_LO
:
8415 case R_PPC64_TOC16_HI
:
8416 case R_PPC64_TOC16_HA
:
8417 case R_PPC64_TOC16_DS
:
8418 case R_PPC64_TOC16_LO_DS
:
8419 case R_PPC64_ADDR64
:
8423 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8424 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8432 val
= h
->root
.u
.def
.value
;
8435 val
= sym
->st_value
;
8437 local_toc_syms
= TRUE
;
8440 val
+= rel
->r_addend
;
8442 if (val
> toc
->rawsize
)
8444 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
8446 else if ((skip
[val
>> 3] & can_optimize
) != 0)
8448 Elf_Internal_Rela
*tocrel
8449 = toc_relocs
+ (skip
[val
>> 3] >> 2);
8450 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
8454 case R_PPC64_TOC16_HA
:
8455 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
8458 case R_PPC64_TOC16_LO_DS
:
8459 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
8463 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
8465 info
->callbacks
->einfo
8466 /* xgettext:c-format */
8467 (_("%H: %s references "
8468 "optimized away TOC entry\n"),
8469 ibfd
, sec
, rel
->r_offset
,
8470 ppc64_elf_howto_table
[r_type
]->name
);
8471 bfd_set_error (bfd_error_bad_value
);
8474 rel
->r_addend
= tocrel
->r_addend
;
8475 elf_section_data (sec
)->relocs
= relstart
;
8479 if (h
!= NULL
|| sym
->st_value
!= 0)
8482 rel
->r_addend
-= skip
[val
>> 3];
8483 elf_section_data (sec
)->relocs
= relstart
;
8486 if (elf_section_data (sec
)->relocs
!= relstart
)
8490 /* We shouldn't have local or global symbols defined in the TOC,
8491 but handle them anyway. */
8492 if (local_syms
!= NULL
)
8493 for (sym
= local_syms
;
8494 sym
< local_syms
+ symtab_hdr
->sh_info
;
8496 if (sym
->st_value
!= 0
8497 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
8501 if (sym
->st_value
> toc
->rawsize
)
8502 i
= toc
->rawsize
>> 3;
8504 i
= sym
->st_value
>> 3;
8506 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8510 (_("%s defined on removed toc entry"),
8511 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
8514 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
8515 sym
->st_value
= (bfd_vma
) i
<< 3;
8518 sym
->st_value
-= skip
[i
];
8519 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8522 /* Adjust any global syms defined in this toc input section. */
8523 if (toc_inf
.global_toc_syms
)
8526 toc_inf
.skip
= skip
;
8527 toc_inf
.global_toc_syms
= FALSE
;
8528 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
8532 if (toc
->reloc_count
!= 0)
8534 Elf_Internal_Shdr
*rel_hdr
;
8535 Elf_Internal_Rela
*wrel
;
8538 /* Remove unused toc relocs, and adjust those we keep. */
8539 if (toc_relocs
== NULL
)
8540 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8542 if (toc_relocs
== NULL
)
8546 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8547 if ((skip
[rel
->r_offset
>> 3]
8548 & (ref_from_discarded
| can_optimize
)) == 0)
8550 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
8551 wrel
->r_info
= rel
->r_info
;
8552 wrel
->r_addend
= rel
->r_addend
;
8555 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
8556 &local_syms
, NULL
, NULL
))
8559 elf_section_data (toc
)->relocs
= toc_relocs
;
8560 toc
->reloc_count
= wrel
- toc_relocs
;
8561 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
8562 sz
= rel_hdr
->sh_entsize
;
8563 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
8566 else if (toc_relocs
!= NULL
8567 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8570 if (local_syms
!= NULL
8571 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8573 if (!info
->keep_memory
)
8576 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8584 /* Return true iff input section I references the TOC using
8585 instructions limited to +/-32k offsets. */
8588 ppc64_elf_has_small_toc_reloc (asection
*i
)
8590 return (is_ppc64_elf (i
->owner
)
8591 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
8594 /* Allocate space for one GOT entry. */
8597 allocate_got (struct elf_link_hash_entry
*h
,
8598 struct bfd_link_info
*info
,
8599 struct got_entry
*gent
)
8601 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8602 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8603 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
8605 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
8606 ? 2 : 1) * sizeof (Elf64_External_Rela
);
8607 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
8609 gent
->got
.offset
= got
->size
;
8610 got
->size
+= entsize
;
8612 if (h
->type
== STT_GNU_IFUNC
)
8614 htab
->elf
.irelplt
->size
+= rentsize
;
8615 htab
->got_reli_size
+= rentsize
;
8617 else if (((bfd_link_pic (info
)
8618 && !((gent
->tls_type
& TLS_TPREL
) != 0
8619 && bfd_link_executable (info
)
8620 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
8621 || (htab
->elf
.dynamic_sections_created
8623 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
8624 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8626 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
8627 relgot
->size
+= rentsize
;
8631 /* This function merges got entries in the same toc group. */
8634 merge_got_entries (struct got_entry
**pent
)
8636 struct got_entry
*ent
, *ent2
;
8638 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
8639 if (!ent
->is_indirect
)
8640 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
8641 if (!ent2
->is_indirect
8642 && ent2
->addend
== ent
->addend
8643 && ent2
->tls_type
== ent
->tls_type
8644 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
8646 ent2
->is_indirect
= TRUE
;
8647 ent2
->got
.ent
= ent
;
8651 /* If H is undefined, make it dynamic if that makes sense. */
8654 ensure_undef_dynamic (struct bfd_link_info
*info
,
8655 struct elf_link_hash_entry
*h
)
8657 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
8659 if (htab
->dynamic_sections_created
8660 && ((info
->dynamic_undefined_weak
!= 0
8661 && h
->root
.type
== bfd_link_hash_undefweak
)
8662 || h
->root
.type
== bfd_link_hash_undefined
)
8665 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
8666 return bfd_elf_link_record_dynamic_symbol (info
, h
);
8670 /* Allocate space in .plt, .got and associated reloc sections for
8674 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8676 struct bfd_link_info
*info
;
8677 struct ppc_link_hash_table
*htab
;
8679 struct ppc_link_hash_entry
*eh
;
8680 struct got_entry
**pgent
, *gent
;
8682 if (h
->root
.type
== bfd_link_hash_indirect
)
8685 info
= (struct bfd_link_info
*) inf
;
8686 htab
= ppc_hash_table (info
);
8690 eh
= (struct ppc_link_hash_entry
*) h
;
8691 /* Run through the TLS GD got entries first if we're changing them
8693 if ((eh
->tls_mask
& (TLS_TLS
| TLS_TPRELGD
)) == (TLS_TLS
| TLS_TPRELGD
))
8694 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8695 if (gent
->got
.refcount
> 0
8696 && (gent
->tls_type
& TLS_GD
) != 0)
8698 /* This was a GD entry that has been converted to TPREL. If
8699 there happens to be a TPREL entry we can use that one. */
8700 struct got_entry
*ent
;
8701 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
8702 if (ent
->got
.refcount
> 0
8703 && (ent
->tls_type
& TLS_TPREL
) != 0
8704 && ent
->addend
== gent
->addend
8705 && ent
->owner
== gent
->owner
)
8707 gent
->got
.refcount
= 0;
8711 /* If not, then we'll be using our own TPREL entry. */
8712 if (gent
->got
.refcount
!= 0)
8713 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
8716 /* Remove any list entry that won't generate a word in the GOT before
8717 we call merge_got_entries. Otherwise we risk merging to empty
8719 pgent
= &h
->got
.glist
;
8720 while ((gent
= *pgent
) != NULL
)
8721 if (gent
->got
.refcount
> 0)
8723 if ((gent
->tls_type
& TLS_LD
) != 0
8726 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
8727 *pgent
= gent
->next
;
8730 pgent
= &gent
->next
;
8733 *pgent
= gent
->next
;
8735 if (!htab
->do_multi_toc
)
8736 merge_got_entries (&h
->got
.glist
);
8738 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
8739 if (!gent
->is_indirect
)
8741 /* Make sure this symbol is output as a dynamic symbol. */
8742 if (!ensure_undef_dynamic (info
, h
))
8745 if (!is_ppc64_elf (gent
->owner
))
8748 allocate_got (h
, info
, gent
);
8751 /* If no dynamic sections we can't have dynamic relocs, except for
8752 IFUNCs which are handled even in static executables. */
8753 if (!htab
->elf
.dynamic_sections_created
8754 && h
->type
!= STT_GNU_IFUNC
)
8755 eh
->dyn_relocs
= NULL
;
8757 /* Discard relocs on undefined symbols that must be local. */
8758 else if (h
->root
.type
== bfd_link_hash_undefined
8759 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8760 eh
->dyn_relocs
= NULL
;
8762 /* Also discard relocs on undefined weak syms with non-default
8763 visibility, or when dynamic_undefined_weak says so. */
8764 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
8765 eh
->dyn_relocs
= NULL
;
8767 if (eh
->dyn_relocs
!= NULL
)
8769 struct elf_dyn_relocs
*p
, **pp
;
8771 /* In the shared -Bsymbolic case, discard space allocated for
8772 dynamic pc-relative relocs against symbols which turn out to
8773 be defined in regular objects. For the normal shared case,
8774 discard space for relocs that have become local due to symbol
8775 visibility changes. */
8777 if (bfd_link_pic (info
))
8779 /* Relocs that use pc_count are those that appear on a call
8780 insn, or certain REL relocs (see must_be_dyn_reloc) that
8781 can be generated via assembly. We want calls to
8782 protected symbols to resolve directly to the function
8783 rather than going via the plt. If people want function
8784 pointer comparisons to work as expected then they should
8785 avoid writing weird assembly. */
8786 if (SYMBOL_CALLS_LOCAL (info
, h
))
8788 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
8790 p
->count
-= p
->pc_count
;
8799 if (eh
->dyn_relocs
!= NULL
)
8801 /* Make sure this symbol is output as a dynamic symbol. */
8802 if (!ensure_undef_dynamic (info
, h
))
8806 else if (ELIMINATE_COPY_RELOCS
&& h
->type
!= STT_GNU_IFUNC
)
8808 /* For the non-pic case, discard space for relocs against
8809 symbols which turn out to need copy relocs or are not
8811 if (h
->dynamic_adjusted
8813 && !ELF_COMMON_DEF_P (h
))
8815 /* Make sure this symbol is output as a dynamic symbol. */
8816 if (!ensure_undef_dynamic (info
, h
))
8819 if (h
->dynindx
== -1)
8820 eh
->dyn_relocs
= NULL
;
8823 eh
->dyn_relocs
= NULL
;
8826 /* Finally, allocate space. */
8827 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
8829 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
8830 if (eh
->elf
.type
== STT_GNU_IFUNC
)
8831 sreloc
= htab
->elf
.irelplt
;
8832 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
8836 /* We might need a PLT entry when the symbol
8839 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
8840 d) has plt16 relocs and we are linking statically. */
8841 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
8842 || h
->type
== STT_GNU_IFUNC
8843 || (h
->needs_plt
&& h
->dynamic_adjusted
)
8846 && !htab
->elf
.dynamic_sections_created
8847 && !htab
->can_convert_all_inline_plt
8848 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
8849 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
8851 struct plt_entry
*pent
;
8852 bfd_boolean doneone
= FALSE
;
8853 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8854 if (pent
->plt
.refcount
> 0)
8856 if (!htab
->elf
.dynamic_sections_created
8857 || h
->dynindx
== -1)
8859 if (h
->type
== STT_GNU_IFUNC
)
8862 pent
->plt
.offset
= s
->size
;
8863 s
->size
+= PLT_ENTRY_SIZE (htab
);
8864 s
= htab
->elf
.irelplt
;
8869 pent
->plt
.offset
= s
->size
;
8870 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
8871 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
8876 /* If this is the first .plt entry, make room for the special
8880 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
8882 pent
->plt
.offset
= s
->size
;
8884 /* Make room for this entry. */
8885 s
->size
+= PLT_ENTRY_SIZE (htab
);
8887 /* Make room for the .glink code. */
8890 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
8893 /* We need bigger stubs past index 32767. */
8894 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
8901 /* We also need to make an entry in the .rela.plt section. */
8902 s
= htab
->elf
.srelplt
;
8905 s
->size
+= sizeof (Elf64_External_Rela
);
8909 pent
->plt
.offset
= (bfd_vma
) -1;
8912 h
->plt
.plist
= NULL
;
8918 h
->plt
.plist
= NULL
;
8925 #define PPC_LO(v) ((v) & 0xffff)
8926 #define PPC_HI(v) (((v) >> 16) & 0xffff)
8927 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
8929 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
8930 to set up space for global entry stubs. These are put in glink,
8931 after the branch table. */
8934 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
8936 struct bfd_link_info
*info
;
8937 struct ppc_link_hash_table
*htab
;
8938 struct plt_entry
*pent
;
8941 if (h
->root
.type
== bfd_link_hash_indirect
)
8944 if (!h
->pointer_equality_needed
)
8951 htab
= ppc_hash_table (info
);
8955 s
= htab
->global_entry
;
8956 plt
= htab
->elf
.splt
;
8957 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
8958 if (pent
->plt
.offset
!= (bfd_vma
) -1
8959 && pent
->addend
== 0)
8961 /* For ELFv2, if this symbol is not defined in a regular file
8962 and we are not generating a shared library or pie, then we
8963 need to define the symbol in the executable on a call stub.
8964 This is to avoid text relocations. */
8965 bfd_vma off
, stub_align
, stub_off
, stub_size
;
8966 unsigned int align_power
;
8970 if (htab
->params
->plt_stub_align
>= 0)
8971 align_power
= htab
->params
->plt_stub_align
;
8973 align_power
= -htab
->params
->plt_stub_align
;
8974 /* Setting section alignment is delayed until we know it is
8975 non-empty. Otherwise the .text output section will be
8976 aligned at least to plt_stub_align even when no global
8977 entry stubs are needed. */
8978 if (s
->alignment_power
< align_power
)
8979 s
->alignment_power
= align_power
;
8980 stub_align
= (bfd_vma
) 1 << align_power
;
8981 if (htab
->params
->plt_stub_align
>= 0
8982 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
8983 - (stub_off
& -stub_align
))
8984 > ((stub_size
- 1) & -stub_align
)))
8985 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
8986 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
8987 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
8988 /* Note that for --plt-stub-align negative we have a possible
8989 dependency between stub offset and size. Break that
8990 dependency by assuming the max stub size when calculating
8992 if (PPC_HA (off
) == 0)
8994 h
->root
.type
= bfd_link_hash_defined
;
8995 h
->root
.u
.def
.section
= s
;
8996 h
->root
.u
.def
.value
= stub_off
;
8997 s
->size
= stub_off
+ stub_size
;
9003 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9004 read-only sections. */
9007 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
9011 if (h
->root
.type
== bfd_link_hash_indirect
)
9014 sec
= readonly_dynrelocs (h
);
9017 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
9019 info
->flags
|= DF_TEXTREL
;
9020 info
->callbacks
->minfo (_("%pB: dynamic relocation against `%pT'"
9021 " in read-only section `%pA'\n"),
9022 sec
->owner
, h
->root
.root
.string
, sec
);
9024 /* Not an error, just cut short the traversal. */
9030 /* Set the sizes of the dynamic sections. */
9033 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
9034 struct bfd_link_info
*info
)
9036 struct ppc_link_hash_table
*htab
;
9041 struct got_entry
*first_tlsld
;
9043 htab
= ppc_hash_table (info
);
9047 dynobj
= htab
->elf
.dynobj
;
9051 if (htab
->elf
.dynamic_sections_created
)
9053 /* Set the contents of the .interp section to the interpreter. */
9054 if (bfd_link_executable (info
) && !info
->nointerp
)
9056 s
= bfd_get_linker_section (dynobj
, ".interp");
9059 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
9060 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
9064 /* Set up .got offsets for local syms, and space for local dynamic
9066 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9068 struct got_entry
**lgot_ents
;
9069 struct got_entry
**end_lgot_ents
;
9070 struct plt_entry
**local_plt
;
9071 struct plt_entry
**end_local_plt
;
9072 unsigned char *lgot_masks
;
9073 bfd_size_type locsymcount
;
9074 Elf_Internal_Shdr
*symtab_hdr
;
9076 if (!is_ppc64_elf (ibfd
))
9079 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
9081 struct ppc_dyn_relocs
*p
;
9083 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
9085 if (!bfd_is_abs_section (p
->sec
)
9086 && bfd_is_abs_section (p
->sec
->output_section
))
9088 /* Input section has been discarded, either because
9089 it is a copy of a linkonce section or due to
9090 linker script /DISCARD/, so we'll be discarding
9093 else if (p
->count
!= 0)
9095 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
9097 srel
= htab
->elf
.irelplt
;
9098 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9099 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
9100 info
->flags
|= DF_TEXTREL
;
9105 lgot_ents
= elf_local_got_ents (ibfd
);
9109 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9110 locsymcount
= symtab_hdr
->sh_info
;
9111 end_lgot_ents
= lgot_ents
+ locsymcount
;
9112 local_plt
= (struct plt_entry
**) end_lgot_ents
;
9113 end_local_plt
= local_plt
+ locsymcount
;
9114 lgot_masks
= (unsigned char *) end_local_plt
;
9115 s
= ppc64_elf_tdata (ibfd
)->got
;
9116 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
9118 struct got_entry
**pent
, *ent
;
9121 while ((ent
= *pent
) != NULL
)
9122 if (ent
->got
.refcount
> 0)
9124 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
9126 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
9131 unsigned int ent_size
= 8;
9132 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
9134 ent
->got
.offset
= s
->size
;
9135 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
9140 s
->size
+= ent_size
;
9141 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9143 htab
->elf
.irelplt
->size
+= rel_size
;
9144 htab
->got_reli_size
+= rel_size
;
9146 else if (bfd_link_pic (info
)
9147 && !((ent
->tls_type
& TLS_TPREL
) != 0
9148 && bfd_link_executable (info
)))
9150 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9151 srel
->size
+= rel_size
;
9160 /* Allocate space for plt calls to local syms. */
9161 lgot_masks
= (unsigned char *) end_local_plt
;
9162 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
9164 struct plt_entry
*ent
;
9166 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9167 if (ent
->plt
.refcount
> 0)
9169 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
9172 ent
->plt
.offset
= s
->size
;
9173 s
->size
+= PLT_ENTRY_SIZE (htab
);
9174 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
9176 else if (htab
->can_convert_all_inline_plt
9177 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
9178 ent
->plt
.offset
= (bfd_vma
) -1;
9182 ent
->plt
.offset
= s
->size
;
9183 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9184 if (bfd_link_pic (info
))
9185 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
9189 ent
->plt
.offset
= (bfd_vma
) -1;
9193 /* Allocate global sym .plt and .got entries, and space for global
9194 sym dynamic relocs. */
9195 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9197 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
9198 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
9201 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9203 struct got_entry
*ent
;
9205 if (!is_ppc64_elf (ibfd
))
9208 ent
= ppc64_tlsld_got (ibfd
);
9209 if (ent
->got
.refcount
> 0)
9211 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9213 ent
->is_indirect
= TRUE
;
9214 ent
->got
.ent
= first_tlsld
;
9218 if (first_tlsld
== NULL
)
9220 s
= ppc64_elf_tdata (ibfd
)->got
;
9221 ent
->got
.offset
= s
->size
;
9224 if (bfd_link_pic (info
))
9226 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9227 srel
->size
+= sizeof (Elf64_External_Rela
);
9232 ent
->got
.offset
= (bfd_vma
) -1;
9235 /* We now have determined the sizes of the various dynamic sections.
9236 Allocate memory for them. */
9238 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9240 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9243 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9244 /* These haven't been allocated yet; don't strip. */
9246 else if (s
== htab
->elf
.sgot
9247 || s
== htab
->elf
.splt
9248 || s
== htab
->elf
.iplt
9249 || s
== htab
->pltlocal
9251 || s
== htab
->global_entry
9252 || s
== htab
->elf
.sdynbss
9253 || s
== htab
->elf
.sdynrelro
)
9255 /* Strip this section if we don't need it; see the
9258 else if (s
== htab
->glink_eh_frame
)
9260 if (!bfd_is_abs_section (s
->output_section
))
9261 /* Not sized yet. */
9264 else if (CONST_STRNEQ (s
->name
, ".rela"))
9268 if (s
!= htab
->elf
.srelplt
)
9271 /* We use the reloc_count field as a counter if we need
9272 to copy relocs into the output file. */
9278 /* It's not one of our sections, so don't allocate space. */
9284 /* If we don't need this section, strip it from the
9285 output file. This is mostly to handle .rela.bss and
9286 .rela.plt. We must create both sections in
9287 create_dynamic_sections, because they must be created
9288 before the linker maps input sections to output
9289 sections. The linker does that before
9290 adjust_dynamic_symbol is called, and it is that
9291 function which decides whether anything needs to go
9292 into these sections. */
9293 s
->flags
|= SEC_EXCLUDE
;
9297 if (bfd_is_abs_section (s
->output_section
))
9298 _bfd_error_handler (_("warning: discarding dynamic section %s"),
9301 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
9304 /* Allocate memory for the section contents. We use bfd_zalloc
9305 here in case unused entries are not reclaimed before the
9306 section's contents are written out. This should not happen,
9307 but this way if it does we get a R_PPC64_NONE reloc in .rela
9308 sections instead of garbage.
9309 We also rely on the section contents being zero when writing
9310 the GOT and .dynrelro. */
9311 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
9312 if (s
->contents
== NULL
)
9316 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9318 if (!is_ppc64_elf (ibfd
))
9321 s
= ppc64_elf_tdata (ibfd
)->got
;
9322 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
9325 s
->flags
|= SEC_EXCLUDE
;
9328 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9329 if (s
->contents
== NULL
)
9333 s
= ppc64_elf_tdata (ibfd
)->relgot
;
9337 s
->flags
|= SEC_EXCLUDE
;
9340 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
9341 if (s
->contents
== NULL
)
9349 if (htab
->elf
.dynamic_sections_created
)
9351 bfd_boolean tls_opt
;
9353 /* Add some entries to the .dynamic section. We fill in the
9354 values later, in ppc64_elf_finish_dynamic_sections, but we
9355 must add the entries now so that we get the correct size for
9356 the .dynamic section. The DT_DEBUG entry is filled in by the
9357 dynamic linker and used by the debugger. */
9358 #define add_dynamic_entry(TAG, VAL) \
9359 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9361 if (bfd_link_executable (info
))
9363 if (!add_dynamic_entry (DT_DEBUG
, 0))
9367 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
9369 if (!add_dynamic_entry (DT_PLTGOT
, 0)
9370 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
9371 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
9372 || !add_dynamic_entry (DT_JMPREL
, 0)
9373 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
9377 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
9379 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
9380 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
9384 tls_opt
= (htab
->params
->tls_get_addr_opt
9385 && htab
->tls_get_addr_fd
!= NULL
9386 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
9387 if (tls_opt
|| !htab
->opd_abi
)
9389 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
9395 if (!add_dynamic_entry (DT_RELA
, 0)
9396 || !add_dynamic_entry (DT_RELASZ
, 0)
9397 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
9400 /* If any dynamic relocs apply to a read-only section,
9401 then we need a DT_TEXTREL entry. */
9402 if ((info
->flags
& DF_TEXTREL
) == 0)
9403 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
9405 if ((info
->flags
& DF_TEXTREL
) != 0)
9407 if (!add_dynamic_entry (DT_TEXTREL
, 0))
9412 #undef add_dynamic_entry
9417 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
9420 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
9422 if (h
->plt
.plist
!= NULL
9424 && !h
->pointer_equality_needed
)
9427 return _bfd_elf_hash_symbol (h
);
9430 /* Determine the type of stub needed, if any, for a call. */
9432 static inline enum ppc_stub_type
9433 ppc_type_of_stub (asection
*input_sec
,
9434 const Elf_Internal_Rela
*rel
,
9435 struct ppc_link_hash_entry
**hash
,
9436 struct plt_entry
**plt_ent
,
9437 bfd_vma destination
,
9438 unsigned long local_off
)
9440 struct ppc_link_hash_entry
*h
= *hash
;
9442 bfd_vma branch_offset
;
9443 bfd_vma max_branch_offset
;
9444 enum elf_ppc64_reloc_type r_type
;
9448 struct plt_entry
*ent
;
9449 struct ppc_link_hash_entry
*fdh
= h
;
9451 && h
->oh
->is_func_descriptor
)
9453 fdh
= ppc_follow_link (h
->oh
);
9457 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9458 if (ent
->addend
== rel
->r_addend
9459 && ent
->plt
.offset
!= (bfd_vma
) -1)
9462 return ppc_stub_plt_call
;
9465 /* Here, we know we don't have a plt entry. If we don't have a
9466 either a defined function descriptor or a defined entry symbol
9467 in a regular object file, then it is pointless trying to make
9468 any other type of stub. */
9469 if (!is_static_defined (&fdh
->elf
)
9470 && !is_static_defined (&h
->elf
))
9471 return ppc_stub_none
;
9473 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
9475 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
9476 struct plt_entry
**local_plt
= (struct plt_entry
**)
9477 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
9478 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
9480 if (local_plt
[r_symndx
] != NULL
)
9482 struct plt_entry
*ent
;
9484 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
9485 if (ent
->addend
== rel
->r_addend
9486 && ent
->plt
.offset
!= (bfd_vma
) -1)
9489 return ppc_stub_plt_call
;
9494 /* Determine where the call point is. */
9495 location
= (input_sec
->output_offset
9496 + input_sec
->output_section
->vma
9499 branch_offset
= destination
- location
;
9500 r_type
= ELF64_R_TYPE (rel
->r_info
);
9502 /* Determine if a long branch stub is needed. */
9503 max_branch_offset
= 1 << 25;
9504 if (r_type
== R_PPC64_REL14
9505 || r_type
== R_PPC64_REL14_BRTAKEN
9506 || r_type
== R_PPC64_REL14_BRNTAKEN
)
9507 max_branch_offset
= 1 << 15;
9509 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
9510 /* We need a stub. Figure out whether a long_branch or plt_branch
9512 return ppc_stub_long_branch
;
9514 return ppc_stub_none
;
9517 /* Gets the address of a label (1:) in r11 and builds an offset in r12,
9518 then adds it to r11 (LOAD false) or loads r12 from r11+r12 (LOAD true).
9523 . lis %r12,xxx-1b@highest
9524 . ori %r12,%r12,xxx-1b@higher
9526 . oris %r12,%r12,xxx-1b@high
9527 . ori %r12,%r12,xxx-1b@l
9528 . add/ldx %r12,%r11,%r12 */
9531 build_offset (bfd
*abfd
, bfd_byte
*p
, bfd_vma off
, bfd_boolean load
)
9533 bfd_put_32 (abfd
, MFLR_R12
, p
);
9535 bfd_put_32 (abfd
, BCL_20_31
, p
);
9537 bfd_put_32 (abfd
, MFLR_R11
, p
);
9539 bfd_put_32 (abfd
, MTLR_R12
, p
);
9541 if (off
+ 0x8000 < 0x10000)
9544 bfd_put_32 (abfd
, LD_R12_0R11
+ PPC_LO (off
), p
);
9546 bfd_put_32 (abfd
, ADDI_R12_R11
+ PPC_LO (off
), p
);
9549 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9551 bfd_put_32 (abfd
, ADDIS_R12_R11
+ PPC_HA (off
), p
);
9554 bfd_put_32 (abfd
, LD_R12_0R12
+ PPC_LO (off
), p
);
9556 bfd_put_32 (abfd
, ADDI_R12_R12
+ PPC_LO (off
), p
);
9561 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9563 bfd_put_32 (abfd
, LI_R12_0
+ ((off
>> 32) & 0xffff), p
);
9568 bfd_put_32 (abfd
, LIS_R12
+ ((off
>> 48) & 0xffff), p
);
9570 if (((off
>> 32) & 0xffff) != 0)
9572 bfd_put_32 (abfd
, ORI_R12_R12_0
+ ((off
>> 32) & 0xffff), p
);
9576 if (((off
>> 32) & 0xffffffffULL
) != 0)
9578 bfd_put_32 (abfd
, SLDI_R12_R12_32
, p
);
9581 if (PPC_HI (off
) != 0)
9583 bfd_put_32 (abfd
, ORIS_R12_R12_0
+ PPC_HI (off
), p
);
9586 if (PPC_LO (off
) != 0)
9588 bfd_put_32 (abfd
, ORI_R12_R12_0
+ PPC_LO (off
), p
);
9592 bfd_put_32 (abfd
, LDX_R12_R11_R12
, p
);
9594 bfd_put_32 (abfd
, ADD_R12_R11_R12
, p
);
9601 size_offset (bfd_vma off
)
9604 if (off
+ 0x8000 < 0x10000)
9606 else if (off
+ 0x80008000ULL
< 0x100000000ULL
)
9610 if (off
+ 0x800000000000ULL
< 0x1000000000000ULL
)
9615 if (((off
>> 32) & 0xffff) != 0)
9618 if (((off
>> 32) & 0xffffffffULL
) != 0)
9620 if (PPC_HI (off
) != 0)
9622 if (PPC_LO (off
) != 0)
9629 /* Emit .eh_frame opcode to advance pc by DELTA. */
9632 eh_advance (bfd
*abfd
, bfd_byte
*eh
, unsigned int delta
)
9636 *eh
++ = DW_CFA_advance_loc
+ delta
;
9637 else if (delta
< 256)
9639 *eh
++ = DW_CFA_advance_loc1
;
9642 else if (delta
< 65536)
9644 *eh
++ = DW_CFA_advance_loc2
;
9645 bfd_put_16 (abfd
, delta
, eh
);
9650 *eh
++ = DW_CFA_advance_loc4
;
9651 bfd_put_32 (abfd
, delta
, eh
);
9657 /* Size of required .eh_frame opcode to advance pc by DELTA. */
9660 eh_advance_size (unsigned int delta
)
9663 /* DW_CFA_advance_loc+[1..63]. */
9665 if (delta
< 256 * 4)
9666 /* DW_CFA_advance_loc1, byte. */
9668 if (delta
< 65536 * 4)
9669 /* DW_CFA_advance_loc2, 2 bytes. */
9671 /* DW_CFA_advance_loc4, 4 bytes. */
9675 /* With power7 weakly ordered memory model, it is possible for ld.so
9676 to update a plt entry in one thread and have another thread see a
9677 stale zero toc entry. To avoid this we need some sort of acquire
9678 barrier in the call stub. One solution is to make the load of the
9679 toc word seem to appear to depend on the load of the function entry
9680 word. Another solution is to test for r2 being zero, and branch to
9681 the appropriate glink entry if so.
9683 . fake dep barrier compare
9684 . ld 12,xxx(2) ld 12,xxx(2)
9686 . xor 11,12,12 ld 2,xxx+8(2)
9687 . add 2,2,11 cmpldi 2,0
9688 . ld 2,xxx+8(2) bnectr+
9689 . bctr b <glink_entry>
9691 The solution involving the compare turns out to be faster, so
9692 that's what we use unless the branch won't reach. */
9694 #define ALWAYS_USE_FAKE_DEP 0
9695 #define ALWAYS_EMIT_R2SAVE 0
9697 static inline unsigned int
9698 plt_stub_size (struct ppc_link_hash_table
*htab
,
9699 struct ppc_stub_hash_entry
*stub_entry
,
9704 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
9706 size
= 8 + size_offset (off
- 8);
9707 if (stub_entry
->stub_type
> ppc_stub_plt_call_notoc
)
9713 if (ALWAYS_EMIT_R2SAVE
9714 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9716 if (PPC_HA (off
) != 0)
9721 if (htab
->params
->plt_static_chain
)
9723 if (htab
->params
->plt_thread_safe
9724 && htab
->elf
.dynamic_sections_created
9725 && stub_entry
->h
!= NULL
9726 && stub_entry
->h
->elf
.dynindx
!= -1)
9728 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
9731 if (stub_entry
->h
!= NULL
9732 && (stub_entry
->h
== htab
->tls_get_addr_fd
9733 || stub_entry
->h
== htab
->tls_get_addr
)
9734 && htab
->params
->tls_get_addr_opt
)
9737 if (stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9743 /* Depending on the sign of plt_stub_align:
9744 If positive, return the padding to align to a 2**plt_stub_align
9746 If negative, if this stub would cross fewer 2**plt_stub_align
9747 boundaries if we align, then return the padding needed to do so. */
9749 static inline unsigned int
9750 plt_stub_pad (struct ppc_link_hash_table
*htab
,
9751 struct ppc_stub_hash_entry
*stub_entry
,
9756 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
9758 if (htab
->params
->plt_stub_align
>= 0)
9760 stub_align
= 1 << htab
->params
->plt_stub_align
;
9761 if ((stub_off
& (stub_align
- 1)) != 0)
9762 return stub_align
- (stub_off
& (stub_align
- 1));
9766 stub_align
= 1 << -htab
->params
->plt_stub_align
;
9767 stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
9768 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
9769 > ((stub_size
- 1) & -stub_align
))
9770 return stub_align
- (stub_off
& (stub_align
- 1));
9774 /* Build a .plt call stub. */
9776 static inline bfd_byte
*
9777 build_plt_stub (struct ppc_link_hash_table
*htab
,
9778 struct ppc_stub_hash_entry
*stub_entry
,
9779 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
9781 bfd
*obfd
= htab
->params
->stub_bfd
;
9782 bfd_boolean plt_load_toc
= htab
->opd_abi
;
9783 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
9784 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
9785 && htab
->elf
.dynamic_sections_created
9786 && stub_entry
->h
!= NULL
9787 && stub_entry
->h
->elf
.dynindx
!= -1);
9788 bfd_boolean use_fake_dep
= plt_thread_safe
;
9789 bfd_vma cmp_branch_off
= 0;
9791 if (!ALWAYS_USE_FAKE_DEP
9794 && !((stub_entry
->h
== htab
->tls_get_addr_fd
9795 || stub_entry
->h
== htab
->tls_get_addr
)
9796 && htab
->params
->tls_get_addr_opt
))
9798 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
9799 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
9800 / PLT_ENTRY_SIZE (htab
));
9801 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
9804 if (pltindex
> 32768)
9805 glinkoff
+= (pltindex
- 32768) * 4;
9807 + htab
->glink
->output_offset
9808 + htab
->glink
->output_section
->vma
);
9809 from
= (p
- stub_entry
->group
->stub_sec
->contents
9810 + 4 * (ALWAYS_EMIT_R2SAVE
9811 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9812 + 4 * (PPC_HA (offset
) != 0)
9813 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
9815 + 4 * (plt_static_chain
!= 0)
9817 + stub_entry
->group
->stub_sec
->output_offset
9818 + stub_entry
->group
->stub_sec
->output_section
->vma
);
9819 cmp_branch_off
= to
- from
;
9820 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
9823 if (PPC_HA (offset
) != 0)
9827 if (ALWAYS_EMIT_R2SAVE
9828 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9830 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
9831 r
[1].r_offset
= r
[0].r_offset
+ 4;
9832 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9833 r
[1].r_addend
= r
[0].r_addend
;
9836 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9838 r
[2].r_offset
= r
[1].r_offset
+ 4;
9839 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
9840 r
[2].r_addend
= r
[0].r_addend
;
9844 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
9845 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9846 r
[2].r_addend
= r
[0].r_addend
+ 8;
9847 if (plt_static_chain
)
9849 r
[3].r_offset
= r
[2].r_offset
+ 4;
9850 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
9851 r
[3].r_addend
= r
[0].r_addend
+ 16;
9856 if (ALWAYS_EMIT_R2SAVE
9857 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9858 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
9861 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
9862 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
9866 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
9867 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
9870 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9872 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
9875 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
9880 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
9881 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
9883 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
9884 if (plt_static_chain
)
9885 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
9892 if (ALWAYS_EMIT_R2SAVE
9893 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9895 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9898 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9900 r
[1].r_offset
= r
[0].r_offset
+ 4;
9901 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
9902 r
[1].r_addend
= r
[0].r_addend
;
9906 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
9907 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9908 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
9909 if (plt_static_chain
)
9911 r
[2].r_offset
= r
[1].r_offset
+ 4;
9912 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
9913 r
[2].r_addend
= r
[0].r_addend
+ 8;
9918 if (ALWAYS_EMIT_R2SAVE
9919 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
9920 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
9921 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
9923 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
9925 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
9928 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
9933 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
9934 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
9936 if (plt_static_chain
)
9937 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
9938 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
9941 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
9943 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
9944 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
9945 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
9948 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
9952 /* Build a special .plt call stub for __tls_get_addr. */
9954 #define LD_R11_0R3 0xe9630000
9955 #define LD_R12_0R3 0xe9830000
9956 #define MR_R0_R3 0x7c601b78
9957 #define CMPDI_R11_0 0x2c2b0000
9958 #define ADD_R3_R12_R13 0x7c6c6a14
9959 #define BEQLR 0x4d820020
9960 #define MR_R3_R0 0x7c030378
9961 #define STD_R11_0R1 0xf9610000
9962 #define BCTRL 0x4e800421
9963 #define LD_R11_0R1 0xe9610000
9964 #define MTLR_R11 0x7d6803a6
9966 static inline bfd_byte
*
9967 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
9968 struct ppc_stub_hash_entry
*stub_entry
,
9969 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
9971 bfd
*obfd
= htab
->params
->stub_bfd
;
9974 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
9975 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
9976 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
9977 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
9978 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
9979 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
9980 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
9982 r
[0].r_offset
+= 7 * 4;
9983 if (stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
9984 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
9986 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
9987 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
9990 r
[0].r_offset
+= 2 * 4;
9991 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
9992 bfd_put_32 (obfd
, BCTRL
, p
- 4);
9994 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
9995 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
9996 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
9997 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
9999 if (htab
->glink_eh_frame
!= NULL
10000 && htab
->glink_eh_frame
->size
!= 0)
10002 bfd_byte
*base
, *eh
;
10003 unsigned int lr_used
, delta
;
10005 base
= htab
->glink_eh_frame
->contents
+ stub_entry
->group
->eh_base
+ 17;
10006 eh
= base
+ stub_entry
->group
->eh_size
;
10007 lr_used
= stub_entry
->stub_offset
+ (p
- 20 - loc
);
10008 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10009 stub_entry
->group
->lr_restore
= lr_used
+ 16;
10010 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
10011 *eh
++ = DW_CFA_offset_extended_sf
;
10013 *eh
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
10014 *eh
++ = DW_CFA_advance_loc
+ 4;
10015 *eh
++ = DW_CFA_restore_extended
;
10017 stub_entry
->group
->eh_size
= eh
- base
;
10022 static Elf_Internal_Rela
*
10023 get_relocs (asection
*sec
, int count
)
10025 Elf_Internal_Rela
*relocs
;
10026 struct bfd_elf_section_data
*elfsec_data
;
10028 elfsec_data
= elf_section_data (sec
);
10029 relocs
= elfsec_data
->relocs
;
10030 if (relocs
== NULL
)
10032 bfd_size_type relsize
;
10033 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10034 relocs
= bfd_alloc (sec
->owner
, relsize
);
10035 if (relocs
== NULL
)
10037 elfsec_data
->relocs
= relocs
;
10038 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10039 sizeof (Elf_Internal_Shdr
));
10040 if (elfsec_data
->rela
.hdr
== NULL
)
10042 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10043 * sizeof (Elf64_External_Rela
));
10044 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10045 sec
->reloc_count
= 0;
10047 relocs
+= sec
->reloc_count
;
10048 sec
->reloc_count
+= count
;
10053 get_r2off (struct bfd_link_info
*info
,
10054 struct ppc_stub_hash_entry
*stub_entry
)
10056 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10057 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10061 /* Support linking -R objects. Get the toc pointer from the
10064 if (!htab
->opd_abi
)
10066 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10067 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10069 if (strcmp (opd
->name
, ".opd") != 0
10070 || opd
->reloc_count
!= 0)
10072 info
->callbacks
->einfo
10073 (_("%P: cannot find opd entry toc for `%pT'\n"),
10074 stub_entry
->h
->elf
.root
.root
.string
);
10075 bfd_set_error (bfd_error_bad_value
);
10076 return (bfd_vma
) -1;
10078 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10079 return (bfd_vma
) -1;
10080 r2off
= bfd_get_64 (opd
->owner
, buf
);
10081 r2off
-= elf_gp (info
->output_bfd
);
10083 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10088 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10090 struct ppc_stub_hash_entry
*stub_entry
;
10091 struct ppc_branch_hash_entry
*br_entry
;
10092 struct bfd_link_info
*info
;
10093 struct ppc_link_hash_table
*htab
;
10097 Elf_Internal_Rela
*r
;
10100 /* Massage our args to the form they really have. */
10101 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10104 htab
= ppc_hash_table (info
);
10108 BFD_ASSERT (stub_entry
->stub_offset
>= stub_entry
->group
->stub_sec
->size
);
10109 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10111 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10112 switch (stub_entry
->stub_type
)
10114 case ppc_stub_long_branch
:
10115 case ppc_stub_long_branch_r2off
:
10116 /* Branches are relative. This is where we are going to. */
10117 targ
= (stub_entry
->target_value
10118 + stub_entry
->target_section
->output_offset
10119 + stub_entry
->target_section
->output_section
->vma
);
10120 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10122 /* And this is where we are coming from. */
10123 off
= (stub_entry
->stub_offset
10124 + stub_entry
->group
->stub_sec
->output_offset
10125 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10129 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10131 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10133 if (r2off
== (bfd_vma
) -1)
10135 htab
->stub_error
= TRUE
;
10138 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10140 if (PPC_HA (r2off
) != 0)
10142 bfd_put_32 (htab
->params
->stub_bfd
,
10143 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10146 if (PPC_LO (r2off
) != 0)
10148 bfd_put_32 (htab
->params
->stub_bfd
,
10149 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10154 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
10157 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10160 (_("long branch stub `%s' offset overflow"),
10161 stub_entry
->root
.string
);
10162 htab
->stub_error
= TRUE
;
10166 if (info
->emitrelocations
)
10168 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
10171 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
10172 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10173 r
->r_addend
= targ
;
10174 if (stub_entry
->h
!= NULL
)
10176 struct elf_link_hash_entry
**hashes
;
10177 unsigned long symndx
;
10178 struct ppc_link_hash_entry
*h
;
10180 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10181 if (hashes
== NULL
)
10183 bfd_size_type hsize
;
10185 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10186 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10187 if (hashes
== NULL
)
10189 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10190 htab
->stub_globals
= 1;
10192 symndx
= htab
->stub_globals
++;
10194 hashes
[symndx
] = &h
->elf
;
10195 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
10196 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10197 h
= ppc_follow_link (h
->oh
);
10198 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
10199 /* H is an opd symbol. The addend must be zero. */
10203 off
= (h
->elf
.root
.u
.def
.value
10204 + h
->elf
.root
.u
.def
.section
->output_offset
10205 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10206 r
->r_addend
-= off
;
10212 case ppc_stub_plt_branch
:
10213 case ppc_stub_plt_branch_r2off
:
10214 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10215 stub_entry
->root
.string
+ 9,
10217 if (br_entry
== NULL
)
10219 _bfd_error_handler (_("can't find branch stub `%s'"),
10220 stub_entry
->root
.string
);
10221 htab
->stub_error
= TRUE
;
10225 targ
= (stub_entry
->target_value
10226 + stub_entry
->target_section
->output_offset
10227 + stub_entry
->target_section
->output_section
->vma
);
10228 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10229 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10231 bfd_put_64 (htab
->brlt
->owner
, targ
,
10232 htab
->brlt
->contents
+ br_entry
->offset
);
10234 if (br_entry
->iter
== htab
->stub_iteration
)
10236 br_entry
->iter
= 0;
10238 if (htab
->relbrlt
!= NULL
)
10240 /* Create a reloc for the branch lookup table entry. */
10241 Elf_Internal_Rela rela
;
10244 rela
.r_offset
= (br_entry
->offset
10245 + htab
->brlt
->output_offset
10246 + htab
->brlt
->output_section
->vma
);
10247 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10248 rela
.r_addend
= targ
;
10250 rl
= htab
->relbrlt
->contents
;
10251 rl
+= (htab
->relbrlt
->reloc_count
++
10252 * sizeof (Elf64_External_Rela
));
10253 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
10255 else if (info
->emitrelocations
)
10257 r
= get_relocs (htab
->brlt
, 1);
10260 /* brlt, being SEC_LINKER_CREATED does not go through the
10261 normal reloc processing. Symbols and offsets are not
10262 translated from input file to output file form, so
10263 set up the offset per the output file. */
10264 r
->r_offset
= (br_entry
->offset
10265 + htab
->brlt
->output_offset
10266 + htab
->brlt
->output_section
->vma
);
10267 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10268 r
->r_addend
= targ
;
10272 targ
= (br_entry
->offset
10273 + htab
->brlt
->output_offset
10274 + htab
->brlt
->output_section
->vma
);
10276 off
= (elf_gp (info
->output_bfd
)
10277 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10280 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10282 info
->callbacks
->einfo
10283 (_("%P: linkage table error against `%pT'\n"),
10284 stub_entry
->root
.string
);
10285 bfd_set_error (bfd_error_bad_value
);
10286 htab
->stub_error
= TRUE
;
10290 if (info
->emitrelocations
)
10292 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
10295 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10296 if (bfd_big_endian (info
->output_bfd
))
10297 r
[0].r_offset
+= 2;
10298 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
10299 r
[0].r_offset
+= 4;
10300 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10301 r
[0].r_addend
= targ
;
10302 if (PPC_HA (off
) != 0)
10304 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10305 r
[1].r_offset
= r
[0].r_offset
+ 4;
10306 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10307 r
[1].r_addend
= r
[0].r_addend
;
10312 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10314 if (PPC_HA (off
) != 0)
10316 bfd_put_32 (htab
->params
->stub_bfd
,
10317 ADDIS_R12_R2
| PPC_HA (off
), p
);
10319 bfd_put_32 (htab
->params
->stub_bfd
,
10320 LD_R12_0R12
| PPC_LO (off
), p
);
10323 bfd_put_32 (htab
->params
->stub_bfd
,
10324 LD_R12_0R2
| PPC_LO (off
), p
);
10328 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10330 if (r2off
== (bfd_vma
) -1)
10332 htab
->stub_error
= TRUE
;
10336 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10338 if (PPC_HA (off
) != 0)
10340 bfd_put_32 (htab
->params
->stub_bfd
,
10341 ADDIS_R12_R2
| PPC_HA (off
), p
);
10343 bfd_put_32 (htab
->params
->stub_bfd
,
10344 LD_R12_0R12
| PPC_LO (off
), p
);
10347 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
10349 if (PPC_HA (r2off
) != 0)
10352 bfd_put_32 (htab
->params
->stub_bfd
,
10353 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
10355 if (PPC_LO (r2off
) != 0)
10358 bfd_put_32 (htab
->params
->stub_bfd
,
10359 ADDI_R2_R2
| PPC_LO (r2off
), p
);
10363 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
10365 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
10369 case ppc_stub_long_branch_notoc
:
10370 case ppc_stub_long_branch_both
:
10371 case ppc_stub_plt_branch_notoc
:
10372 case ppc_stub_plt_branch_both
:
10373 case ppc_stub_plt_call_notoc
:
10374 case ppc_stub_plt_call_both
:
10376 off
= (stub_entry
->stub_offset
10377 + stub_entry
->group
->stub_sec
->output_offset
10378 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10379 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
10380 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
10381 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10384 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
10387 if (stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
)
10389 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10390 if (targ
>= (bfd_vma
) -2)
10393 plt
= htab
->elf
.splt
;
10394 if (!htab
->elf
.dynamic_sections_created
10395 || stub_entry
->h
== NULL
10396 || stub_entry
->h
->elf
.dynindx
== -1)
10398 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10399 plt
= htab
->elf
.iplt
;
10401 plt
= htab
->pltlocal
;
10403 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10406 targ
= (stub_entry
->target_value
10407 + stub_entry
->target_section
->output_offset
10408 + stub_entry
->target_section
->output_section
->vma
);
10411 /* The notoc stubs calculate their target (either a PLT entry or
10412 the global entry point of a function) relative to the PC
10413 returned by the "bcl" two instructions past the start of the
10414 sequence emitted by build_offset. The offset is therefore 8
10415 less than calculated from the start of the sequence. */
10417 p
= build_offset (htab
->params
->stub_bfd
, p
, off
,
10418 stub_entry
->stub_type
>= ppc_stub_plt_call_notoc
);
10419 if (stub_entry
->stub_type
<= ppc_stub_long_branch_both
)
10422 from
= (stub_entry
->stub_offset
10423 + stub_entry
->group
->stub_sec
->output_offset
10424 + stub_entry
->group
->stub_sec
->output_section
->vma
10426 bfd_put_32 (htab
->params
->stub_bfd
,
10427 B_DOT
| ((targ
- from
) & 0x3fffffc), p
);
10431 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
10433 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
10437 if (htab
->glink_eh_frame
!= NULL
10438 && htab
->glink_eh_frame
->size
!= 0)
10440 bfd_byte
*base
, *eh
;
10441 unsigned int lr_used
, delta
;
10443 base
= (htab
->glink_eh_frame
->contents
10444 + stub_entry
->group
->eh_base
+ 17);
10445 eh
= base
+ stub_entry
->group
->eh_size
;
10446 lr_used
= stub_entry
->stub_offset
+ 8;
10447 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
10448 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
10449 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10451 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10452 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10453 eh
= eh_advance (htab
->elf
.dynobj
, eh
, delta
);
10454 *eh
++ = DW_CFA_register
;
10457 *eh
++ = DW_CFA_advance_loc
+ 2;
10458 *eh
++ = DW_CFA_restore_extended
;
10460 stub_entry
->group
->eh_size
= eh
- base
;
10464 case ppc_stub_plt_call
:
10465 case ppc_stub_plt_call_r2save
:
10466 if (stub_entry
->h
!= NULL
10467 && stub_entry
->h
->is_func_descriptor
10468 && stub_entry
->h
->oh
!= NULL
)
10470 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
10472 /* If the old-ABI "dot-symbol" is undefined make it weak so
10473 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
10474 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
10475 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
10476 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
10477 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
10480 /* Now build the stub. */
10481 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10482 if (targ
>= (bfd_vma
) -2)
10485 plt
= htab
->elf
.splt
;
10486 if (!htab
->elf
.dynamic_sections_created
10487 || stub_entry
->h
== NULL
10488 || stub_entry
->h
->elf
.dynindx
== -1)
10490 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10491 plt
= htab
->elf
.iplt
;
10493 plt
= htab
->pltlocal
;
10495 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10497 off
= (elf_gp (info
->output_bfd
)
10498 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10501 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10503 info
->callbacks
->einfo
10504 /* xgettext:c-format */
10505 (_("%P: linkage table error against `%pT'\n"),
10506 stub_entry
->h
!= NULL
10507 ? stub_entry
->h
->elf
.root
.root
.string
10509 bfd_set_error (bfd_error_bad_value
);
10510 htab
->stub_error
= TRUE
;
10515 if (info
->emitrelocations
)
10517 r
= get_relocs (stub_entry
->group
->stub_sec
,
10518 ((PPC_HA (off
) != 0)
10520 ? 2 + (htab
->params
->plt_static_chain
10521 && PPC_HA (off
+ 16) == PPC_HA (off
))
10525 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10526 if (bfd_big_endian (info
->output_bfd
))
10527 r
[0].r_offset
+= 2;
10528 r
[0].r_addend
= targ
;
10530 if (stub_entry
->h
!= NULL
10531 && (stub_entry
->h
== htab
->tls_get_addr_fd
10532 || stub_entry
->h
== htab
->tls_get_addr
)
10533 && htab
->params
->tls_get_addr_opt
)
10534 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
10536 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
10539 case ppc_stub_save_res
:
10547 stub_entry
->group
->stub_sec
->size
= stub_entry
->stub_offset
+ (p
- loc
);
10549 if (htab
->params
->emit_stub_syms
)
10551 struct elf_link_hash_entry
*h
;
10554 const char *const stub_str
[] = { "long_branch",
10567 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
10568 len2
= strlen (stub_entry
->root
.string
);
10569 name
= bfd_malloc (len1
+ len2
+ 2);
10572 memcpy (name
, stub_entry
->root
.string
, 9);
10573 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
10574 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
10575 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
10578 if (h
->root
.type
== bfd_link_hash_new
)
10580 h
->root
.type
= bfd_link_hash_defined
;
10581 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
10582 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
10583 h
->ref_regular
= 1;
10584 h
->def_regular
= 1;
10585 h
->ref_regular_nonweak
= 1;
10586 h
->forced_local
= 1;
10588 h
->root
.linker_def
= 1;
10595 /* As above, but don't actually build the stub. Just bump offset so
10596 we know stub section sizes, and select plt_branch stubs where
10597 long_branch stubs won't do. */
10600 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10602 struct ppc_stub_hash_entry
*stub_entry
;
10603 struct bfd_link_info
*info
;
10604 struct ppc_link_hash_table
*htab
;
10606 bfd_vma targ
, off
, r2off
;
10607 unsigned int size
, extra
, lr_used
, delta
;
10609 /* Massage our args to the form they really have. */
10610 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10613 htab
= ppc_hash_table (info
);
10617 /* Make a note of the offset within the stubs for this entry. */
10618 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10620 if (stub_entry
->h
!= NULL
10621 && stub_entry
->h
->save_res
10622 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
10623 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
10625 /* Don't make stubs to out-of-line register save/restore
10626 functions. Instead, emit copies of the functions. */
10627 stub_entry
->group
->needs_save_res
= 1;
10628 stub_entry
->stub_type
= ppc_stub_save_res
;
10632 switch (stub_entry
->stub_type
)
10634 case ppc_stub_plt_branch
:
10635 case ppc_stub_plt_branch_r2off
:
10636 /* Reset the stub type from the plt branch variant in case we now
10637 can reach with a shorter stub. */
10638 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
10639 /* Fall through. */
10640 case ppc_stub_long_branch
:
10641 case ppc_stub_long_branch_r2off
:
10642 targ
= (stub_entry
->target_value
10643 + stub_entry
->target_section
->output_offset
10644 + stub_entry
->target_section
->output_section
->vma
);
10645 targ
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10646 off
= (stub_entry
->stub_offset
10647 + stub_entry
->group
->stub_sec
->output_offset
10648 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10652 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10654 r2off
= get_r2off (info
, stub_entry
);
10655 if (r2off
== (bfd_vma
) -1)
10657 htab
->stub_error
= TRUE
;
10661 if (PPC_HA (r2off
) != 0)
10663 if (PPC_LO (r2off
) != 0)
10669 /* If the branch offset is too big, use a ppc_stub_plt_branch.
10670 Do the same for -R objects without function descriptors. */
10671 if ((stub_entry
->stub_type
== ppc_stub_long_branch_r2off
10673 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0)
10674 || off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10676 struct ppc_branch_hash_entry
*br_entry
;
10678 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10679 stub_entry
->root
.string
+ 9,
10681 if (br_entry
== NULL
)
10683 _bfd_error_handler (_("can't build branch stub `%s'"),
10684 stub_entry
->root
.string
);
10685 htab
->stub_error
= TRUE
;
10689 if (br_entry
->iter
!= htab
->stub_iteration
)
10691 br_entry
->iter
= htab
->stub_iteration
;
10692 br_entry
->offset
= htab
->brlt
->size
;
10693 htab
->brlt
->size
+= 8;
10695 if (htab
->relbrlt
!= NULL
)
10696 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
10697 else if (info
->emitrelocations
)
10699 htab
->brlt
->reloc_count
+= 1;
10700 htab
->brlt
->flags
|= SEC_RELOC
;
10704 targ
= (br_entry
->offset
10705 + htab
->brlt
->output_offset
10706 + htab
->brlt
->output_section
->vma
);
10707 off
= (elf_gp (info
->output_bfd
)
10708 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10711 if (info
->emitrelocations
)
10713 stub_entry
->group
->stub_sec
->reloc_count
10714 += 1 + (PPC_HA (off
) != 0);
10715 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
10718 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
10719 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10722 if (PPC_HA (off
) != 0)
10728 if (PPC_HA (off
) != 0)
10731 if (PPC_HA (r2off
) != 0)
10733 if (PPC_LO (r2off
) != 0)
10737 else if (info
->emitrelocations
)
10739 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
10740 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
10744 case ppc_stub_plt_branch_notoc
:
10745 case ppc_stub_plt_branch_both
:
10746 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
10747 /* Fall through. */
10748 case ppc_stub_long_branch_notoc
:
10749 case ppc_stub_long_branch_both
:
10750 off
= (stub_entry
->stub_offset
10751 + stub_entry
->group
->stub_sec
->output_offset
10752 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10754 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
10757 targ
= (stub_entry
->target_value
10758 + stub_entry
->target_section
->output_offset
10759 + stub_entry
->target_section
->output_section
->vma
);
10762 extra
= size_offset (off
- 8);
10763 /* Include branch insn plus those in the offset sequence. */
10765 /* The branch insn is at the end, or "extra" bytes along. So
10766 its offset will be "extra" bytes less that that already
10770 /* After the bcl, lr has been modified so we need to emit
10771 .eh_frame info saying the return address is in r12. */
10772 lr_used
= stub_entry
->stub_offset
+ 8;
10773 if (stub_entry
->stub_type
== ppc_stub_long_branch_both
)
10775 /* The eh_frame info will consist of a DW_CFA_advance_loc or
10776 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
10777 DW_CFA_restore_extended 65. */
10778 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10779 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
10780 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10782 /* If the branch can't reach, use a plt_branch. */
10783 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10785 stub_entry
->stub_type
+= (ppc_stub_plt_branch_notoc
10786 - ppc_stub_long_branch_notoc
);
10791 case ppc_stub_plt_call_notoc
:
10792 case ppc_stub_plt_call_both
:
10793 off
= (stub_entry
->stub_offset
10794 + stub_entry
->group
->stub_sec
->output_offset
10795 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10796 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10798 targ
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10799 if (targ
>= (bfd_vma
) -2)
10802 plt
= htab
->elf
.splt
;
10803 if (!htab
->elf
.dynamic_sections_created
10804 || stub_entry
->h
== NULL
10805 || stub_entry
->h
->elf
.dynindx
== -1)
10807 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10808 plt
= htab
->elf
.iplt
;
10810 plt
= htab
->pltlocal
;
10812 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10815 if (htab
->params
->plt_stub_align
!= 0)
10817 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
10819 stub_entry
->group
->stub_sec
->size
+= pad
;
10820 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10824 size
= plt_stub_size (htab
, stub_entry
, off
);
10826 /* After the bcl, lr has been modified so we need to emit
10827 .eh_frame info saying the return address is in r12. */
10828 lr_used
= stub_entry
->stub_offset
+ 8;
10829 if (stub_entry
->stub_type
== ppc_stub_plt_call_both
)
10831 /* The eh_frame info will consist of a DW_CFA_advance_loc or
10832 variant, DW_CFA_register, 65, 12, DW_CFA_advance_loc+2,
10833 DW_CFA_restore_extended 65. */
10834 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10835 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
10836 stub_entry
->group
->lr_restore
= lr_used
+ 8;
10839 case ppc_stub_plt_call
:
10840 case ppc_stub_plt_call_r2save
:
10841 targ
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
10842 if (targ
>= (bfd_vma
) -2)
10844 plt
= htab
->elf
.splt
;
10845 if (!htab
->elf
.dynamic_sections_created
10846 || stub_entry
->h
== NULL
10847 || stub_entry
->h
->elf
.dynindx
== -1)
10849 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
10850 plt
= htab
->elf
.iplt
;
10852 plt
= htab
->pltlocal
;
10854 targ
+= plt
->output_offset
+ plt
->output_section
->vma
;
10856 off
= (elf_gp (info
->output_bfd
)
10857 + htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10860 if (htab
->params
->plt_stub_align
!= 0)
10862 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
10864 stub_entry
->group
->stub_sec
->size
+= pad
;
10865 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10868 if (info
->emitrelocations
)
10870 stub_entry
->group
->stub_sec
->reloc_count
10871 += ((PPC_HA (off
) != 0)
10873 ? 2 + (htab
->params
->plt_static_chain
10874 && PPC_HA (off
+ 16) == PPC_HA (off
))
10876 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
10879 size
= plt_stub_size (htab
, stub_entry
, off
);
10881 if (stub_entry
->h
!= NULL
10882 && (stub_entry
->h
== htab
->tls_get_addr_fd
10883 || stub_entry
->h
== htab
->tls_get_addr
)
10884 && htab
->params
->tls_get_addr_opt
10885 && stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10887 /* After the bctrl, lr has been modified so we need to
10888 emit .eh_frame info saying the return address is
10889 on the stack. In fact we put the EH info specifying
10890 that the return address is on the stack *at* the
10891 call rather than after it, because the EH info for a
10892 call needs to be specified by that point.
10893 See libgcc/unwind-dw2.c execute_cfa_program. */
10894 lr_used
= stub_entry
->stub_offset
+ size
- 20;
10895 /* The eh_frame info will consist of a DW_CFA_advance_loc
10896 or variant, DW_CFA_offset_externed_sf, 65, -stackoff,
10897 DW_CFA_advance_loc+4, DW_CFA_restore_extended, 65. */
10898 delta
= lr_used
- stub_entry
->group
->lr_restore
;
10899 stub_entry
->group
->eh_size
+= eh_advance_size (delta
) + 6;
10900 stub_entry
->group
->lr_restore
= size
- 4;
10909 stub_entry
->group
->stub_sec
->size
+= size
;
10913 /* Set up various things so that we can make a list of input sections
10914 for each output section included in the link. Returns -1 on error,
10915 0 when no stubs will be needed, and 1 on success. */
10918 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
10922 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10927 htab
->sec_info_arr_size
= _bfd_section_id
;
10928 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
10929 htab
->sec_info
= bfd_zmalloc (amt
);
10930 if (htab
->sec_info
== NULL
)
10933 /* Set toc_off for com, und, abs and ind sections. */
10934 for (id
= 0; id
< 3; id
++)
10935 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
10940 /* Set up for first pass at multitoc partitioning. */
10943 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
10945 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10947 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
10948 htab
->toc_bfd
= NULL
;
10949 htab
->toc_first_sec
= NULL
;
10952 /* The linker repeatedly calls this function for each TOC input section
10953 and linker generated GOT section. Group input bfds such that the toc
10954 within a group is less than 64k in size. */
10957 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
10959 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10960 bfd_vma addr
, off
, limit
;
10965 if (!htab
->second_toc_pass
)
10967 /* Keep track of the first .toc or .got section for this input bfd. */
10968 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
10972 htab
->toc_bfd
= isec
->owner
;
10973 htab
->toc_first_sec
= isec
;
10976 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
10977 off
= addr
- htab
->toc_curr
;
10978 limit
= 0x80008000;
10979 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
10981 if (off
+ isec
->size
> limit
)
10983 addr
= (htab
->toc_first_sec
->output_offset
10984 + htab
->toc_first_sec
->output_section
->vma
);
10985 htab
->toc_curr
= addr
;
10986 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
10989 /* toc_curr is the base address of this toc group. Set elf_gp
10990 for the input section to be the offset relative to the
10991 output toc base plus 0x8000. Making the input elf_gp an
10992 offset allows us to move the toc as a whole without
10993 recalculating input elf_gp. */
10994 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
10995 off
+= TOC_BASE_OFF
;
10997 /* Die if someone uses a linker script that doesn't keep input
10998 file .toc and .got together. */
11000 && elf_gp (isec
->owner
) != 0
11001 && elf_gp (isec
->owner
) != off
)
11004 elf_gp (isec
->owner
) = off
;
11008 /* During the second pass toc_first_sec points to the start of
11009 a toc group, and toc_curr is used to track the old elf_gp.
11010 We use toc_bfd to ensure we only look at each bfd once. */
11011 if (htab
->toc_bfd
== isec
->owner
)
11013 htab
->toc_bfd
= isec
->owner
;
11015 if (htab
->toc_first_sec
== NULL
11016 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11018 htab
->toc_curr
= elf_gp (isec
->owner
);
11019 htab
->toc_first_sec
= isec
;
11021 addr
= (htab
->toc_first_sec
->output_offset
11022 + htab
->toc_first_sec
->output_section
->vma
);
11023 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
11024 elf_gp (isec
->owner
) = off
;
11029 /* Called via elf_link_hash_traverse to merge GOT entries for global
11033 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11035 if (h
->root
.type
== bfd_link_hash_indirect
)
11038 merge_got_entries (&h
->got
.glist
);
11043 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11047 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11049 struct got_entry
*gent
;
11051 if (h
->root
.type
== bfd_link_hash_indirect
)
11054 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11055 if (!gent
->is_indirect
)
11056 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11060 /* Called on the first multitoc pass after the last call to
11061 ppc64_elf_next_toc_section. This function removes duplicate GOT
11065 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11067 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11068 struct bfd
*ibfd
, *ibfd2
;
11069 bfd_boolean done_something
;
11071 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11073 if (!htab
->do_multi_toc
)
11076 /* Merge global sym got entries within a toc group. */
11077 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11079 /* And tlsld_got. */
11080 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11082 struct got_entry
*ent
, *ent2
;
11084 if (!is_ppc64_elf (ibfd
))
11087 ent
= ppc64_tlsld_got (ibfd
);
11088 if (!ent
->is_indirect
11089 && ent
->got
.offset
!= (bfd_vma
) -1)
11091 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11093 if (!is_ppc64_elf (ibfd2
))
11096 ent2
= ppc64_tlsld_got (ibfd2
);
11097 if (!ent2
->is_indirect
11098 && ent2
->got
.offset
!= (bfd_vma
) -1
11099 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11101 ent2
->is_indirect
= TRUE
;
11102 ent2
->got
.ent
= ent
;
11108 /* Zap sizes of got sections. */
11109 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11110 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11111 htab
->got_reli_size
= 0;
11113 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11115 asection
*got
, *relgot
;
11117 if (!is_ppc64_elf (ibfd
))
11120 got
= ppc64_elf_tdata (ibfd
)->got
;
11123 got
->rawsize
= got
->size
;
11125 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11126 relgot
->rawsize
= relgot
->size
;
11131 /* Now reallocate the got, local syms first. We don't need to
11132 allocate section contents again since we never increase size. */
11133 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11135 struct got_entry
**lgot_ents
;
11136 struct got_entry
**end_lgot_ents
;
11137 struct plt_entry
**local_plt
;
11138 struct plt_entry
**end_local_plt
;
11139 unsigned char *lgot_masks
;
11140 bfd_size_type locsymcount
;
11141 Elf_Internal_Shdr
*symtab_hdr
;
11144 if (!is_ppc64_elf (ibfd
))
11147 lgot_ents
= elf_local_got_ents (ibfd
);
11151 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11152 locsymcount
= symtab_hdr
->sh_info
;
11153 end_lgot_ents
= lgot_ents
+ locsymcount
;
11154 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11155 end_local_plt
= local_plt
+ locsymcount
;
11156 lgot_masks
= (unsigned char *) end_local_plt
;
11157 s
= ppc64_elf_tdata (ibfd
)->got
;
11158 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11160 struct got_entry
*ent
;
11162 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11164 unsigned int ent_size
= 8;
11165 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11167 ent
->got
.offset
= s
->size
;
11168 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11173 s
->size
+= ent_size
;
11174 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
11176 htab
->elf
.irelplt
->size
+= rel_size
;
11177 htab
->got_reli_size
+= rel_size
;
11179 else if (bfd_link_pic (info
)
11180 && !((ent
->tls_type
& TLS_TPREL
) != 0
11181 && bfd_link_executable (info
)))
11183 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11184 srel
->size
+= rel_size
;
11190 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11192 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11194 struct got_entry
*ent
;
11196 if (!is_ppc64_elf (ibfd
))
11199 ent
= ppc64_tlsld_got (ibfd
);
11200 if (!ent
->is_indirect
11201 && ent
->got
.offset
!= (bfd_vma
) -1)
11203 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11204 ent
->got
.offset
= s
->size
;
11206 if (bfd_link_pic (info
))
11208 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11209 srel
->size
+= sizeof (Elf64_External_Rela
);
11214 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11215 if (!done_something
)
11216 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11220 if (!is_ppc64_elf (ibfd
))
11223 got
= ppc64_elf_tdata (ibfd
)->got
;
11226 done_something
= got
->rawsize
!= got
->size
;
11227 if (done_something
)
11232 if (done_something
)
11233 (*htab
->params
->layout_sections_again
) ();
11235 /* Set up for second pass over toc sections to recalculate elf_gp
11236 on input sections. */
11237 htab
->toc_bfd
= NULL
;
11238 htab
->toc_first_sec
= NULL
;
11239 htab
->second_toc_pass
= TRUE
;
11240 return done_something
;
11243 /* Called after second pass of multitoc partitioning. */
11246 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11248 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11250 /* After the second pass, toc_curr tracks the TOC offset used
11251 for code sections below in ppc64_elf_next_input_section. */
11252 htab
->toc_curr
= TOC_BASE_OFF
;
11255 /* No toc references were found in ISEC. If the code in ISEC makes no
11256 calls, then there's no need to use toc adjusting stubs when branching
11257 into ISEC. Actually, indirect calls from ISEC are OK as they will
11258 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11259 needed, and 2 if a cyclical call-graph was found but no other reason
11260 for a stub was detected. If called from the top level, a return of
11261 2 means the same as a return of 0. */
11264 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11268 /* Mark this section as checked. */
11269 isec
->call_check_done
= 1;
11271 /* We know none of our code bearing sections will need toc stubs. */
11272 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11275 if (isec
->size
== 0)
11278 if (isec
->output_section
== NULL
)
11282 if (isec
->reloc_count
!= 0)
11284 Elf_Internal_Rela
*relstart
, *rel
;
11285 Elf_Internal_Sym
*local_syms
;
11286 struct ppc_link_hash_table
*htab
;
11288 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11289 info
->keep_memory
);
11290 if (relstart
== NULL
)
11293 /* Look for branches to outside of this section. */
11295 htab
= ppc_hash_table (info
);
11299 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11301 enum elf_ppc64_reloc_type r_type
;
11302 unsigned long r_symndx
;
11303 struct elf_link_hash_entry
*h
;
11304 struct ppc_link_hash_entry
*eh
;
11305 Elf_Internal_Sym
*sym
;
11307 struct _opd_sec_data
*opd
;
11311 r_type
= ELF64_R_TYPE (rel
->r_info
);
11312 if (r_type
!= R_PPC64_REL24
11313 && r_type
!= R_PPC64_REL24_NOTOC
11314 && r_type
!= R_PPC64_REL14
11315 && r_type
!= R_PPC64_REL14_BRTAKEN
11316 && r_type
!= R_PPC64_REL14_BRNTAKEN
11317 && r_type
!= R_PPC64_PLTCALL
)
11320 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11321 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11328 /* Calls to dynamic lib functions go through a plt call stub
11330 eh
= (struct ppc_link_hash_entry
*) h
;
11332 && (eh
->elf
.plt
.plist
!= NULL
11334 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
11340 if (sym_sec
== NULL
)
11341 /* Ignore other undefined symbols. */
11344 /* Assume branches to other sections not included in the
11345 link need stubs too, to cover -R and absolute syms. */
11346 if (sym_sec
->output_section
== NULL
)
11353 sym_value
= sym
->st_value
;
11356 if (h
->root
.type
!= bfd_link_hash_defined
11357 && h
->root
.type
!= bfd_link_hash_defweak
)
11359 sym_value
= h
->root
.u
.def
.value
;
11361 sym_value
+= rel
->r_addend
;
11363 /* If this branch reloc uses an opd sym, find the code section. */
11364 opd
= get_opd_info (sym_sec
);
11367 if (h
== NULL
&& opd
->adjust
!= NULL
)
11371 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11373 /* Assume deleted functions won't ever be called. */
11375 sym_value
+= adjust
;
11378 dest
= opd_entry_value (sym_sec
, sym_value
,
11379 &sym_sec
, NULL
, FALSE
);
11380 if (dest
== (bfd_vma
) -1)
11385 + sym_sec
->output_offset
11386 + sym_sec
->output_section
->vma
);
11388 /* Ignore branch to self. */
11389 if (sym_sec
== isec
)
11392 /* If the called function uses the toc, we need a stub. */
11393 if (sym_sec
->has_toc_reloc
11394 || sym_sec
->makes_toc_func_call
)
11400 /* Assume any branch that needs a long branch stub might in fact
11401 need a plt_branch stub. A plt_branch stub uses r2. */
11402 else if (dest
- (isec
->output_offset
11403 + isec
->output_section
->vma
11404 + rel
->r_offset
) + (1 << 25)
11405 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11413 /* If calling back to a section in the process of being
11414 tested, we can't say for sure that no toc adjusting stubs
11415 are needed, so don't return zero. */
11416 else if (sym_sec
->call_check_in_progress
)
11419 /* Branches to another section that itself doesn't have any TOC
11420 references are OK. Recursively call ourselves to check. */
11421 else if (!sym_sec
->call_check_done
)
11425 /* Mark current section as indeterminate, so that other
11426 sections that call back to current won't be marked as
11428 isec
->call_check_in_progress
= 1;
11429 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
11430 isec
->call_check_in_progress
= 0;
11441 if (local_syms
!= NULL
11442 && (elf_symtab_hdr (isec
->owner
).contents
11443 != (unsigned char *) local_syms
))
11445 if (elf_section_data (isec
)->relocs
!= relstart
)
11450 && isec
->map_head
.s
!= NULL
11451 && (strcmp (isec
->output_section
->name
, ".init") == 0
11452 || strcmp (isec
->output_section
->name
, ".fini") == 0))
11454 if (isec
->map_head
.s
->has_toc_reloc
11455 || isec
->map_head
.s
->makes_toc_func_call
)
11457 else if (!isec
->map_head
.s
->call_check_done
)
11460 isec
->call_check_in_progress
= 1;
11461 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
11462 isec
->call_check_in_progress
= 0;
11469 isec
->makes_toc_func_call
= 1;
11474 /* The linker repeatedly calls this function for each input section,
11475 in the order that input sections are linked into output sections.
11476 Build lists of input sections to determine groupings between which
11477 we may insert linker stubs. */
11480 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
11482 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11487 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
11488 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
11490 /* This happens to make the list in reverse order,
11491 which is what we want. */
11492 htab
->sec_info
[isec
->id
].u
.list
11493 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
11494 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
11497 if (htab
->multi_toc_needed
)
11499 /* Analyse sections that aren't already flagged as needing a
11500 valid toc pointer. Exclude .fixup for the linux kernel.
11501 .fixup contains branches, but only back to the function that
11502 hit an exception. */
11503 if (!(isec
->has_toc_reloc
11504 || (isec
->flags
& SEC_CODE
) == 0
11505 || strcmp (isec
->name
, ".fixup") == 0
11506 || isec
->call_check_done
))
11508 if (toc_adjusting_stub_needed (info
, isec
) < 0)
11511 /* Make all sections use the TOC assigned for this object file.
11512 This will be wrong for pasted sections; We fix that in
11513 check_pasted_section(). */
11514 if (elf_gp (isec
->owner
) != 0)
11515 htab
->toc_curr
= elf_gp (isec
->owner
);
11518 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
11522 /* Check that all .init and .fini sections use the same toc, if they
11523 have toc relocs. */
11526 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
11528 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
11532 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11533 bfd_vma toc_off
= 0;
11536 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11537 if (i
->has_toc_reloc
)
11540 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11541 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
11546 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11547 if (i
->makes_toc_func_call
)
11549 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11553 /* Make sure the whole pasted function uses the same toc offset. */
11555 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11556 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
11562 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
11564 return (check_pasted_section (info
, ".init")
11565 & check_pasted_section (info
, ".fini"));
11568 /* See whether we can group stub sections together. Grouping stub
11569 sections may result in fewer stubs. More importantly, we need to
11570 put all .init* and .fini* stubs at the beginning of the .init or
11571 .fini output sections respectively, because glibc splits the
11572 _init and _fini functions into multiple parts. Putting a stub in
11573 the middle of a function is not a good idea. */
11576 group_sections (struct bfd_link_info
*info
,
11577 bfd_size_type stub_group_size
,
11578 bfd_boolean stubs_always_before_branch
)
11580 struct ppc_link_hash_table
*htab
;
11582 bfd_boolean suppress_size_errors
;
11584 htab
= ppc_hash_table (info
);
11588 suppress_size_errors
= FALSE
;
11589 if (stub_group_size
== 1)
11591 /* Default values. */
11592 if (stubs_always_before_branch
)
11593 stub_group_size
= 0x1e00000;
11595 stub_group_size
= 0x1c00000;
11596 suppress_size_errors
= TRUE
;
11599 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
11603 if (osec
->id
>= htab
->sec_info_arr_size
)
11606 tail
= htab
->sec_info
[osec
->id
].u
.list
;
11607 while (tail
!= NULL
)
11611 bfd_size_type total
;
11612 bfd_boolean big_sec
;
11614 struct map_stub
*group
;
11615 bfd_size_type group_size
;
11618 total
= tail
->size
;
11619 group_size
= (ppc64_elf_section_data (tail
) != NULL
11620 && ppc64_elf_section_data (tail
)->has_14bit_branch
11621 ? stub_group_size
>> 10 : stub_group_size
);
11623 big_sec
= total
> group_size
;
11624 if (big_sec
&& !suppress_size_errors
)
11625 /* xgettext:c-format */
11626 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
11627 tail
->owner
, tail
);
11628 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
11630 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
11631 && ((total
+= curr
->output_offset
- prev
->output_offset
)
11632 < (ppc64_elf_section_data (prev
) != NULL
11633 && ppc64_elf_section_data (prev
)->has_14bit_branch
11634 ? (group_size
= stub_group_size
>> 10) : group_size
))
11635 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
11638 /* OK, the size from the start of CURR to the end is less
11639 than group_size and thus can be handled by one stub
11640 section. (or the tail section is itself larger than
11641 group_size, in which case we may be toast.) We should
11642 really be keeping track of the total size of stubs added
11643 here, as stubs contribute to the final output section
11644 size. That's a little tricky, and this way will only
11645 break if stubs added make the total size more than 2^25,
11646 ie. for the default stub_group_size, if stubs total more
11647 than 2097152 bytes, or nearly 75000 plt call stubs. */
11648 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
11651 group
->link_sec
= curr
;
11652 group
->stub_sec
= NULL
;
11653 group
->needs_save_res
= 0;
11654 group
->lr_restore
= 0;
11655 group
->eh_size
= 0;
11656 group
->eh_base
= 0;
11657 group
->next
= htab
->group
;
11658 htab
->group
= group
;
11661 prev
= htab
->sec_info
[tail
->id
].u
.list
;
11662 /* Set up this stub group. */
11663 htab
->sec_info
[tail
->id
].u
.group
= group
;
11665 while (tail
!= curr
&& (tail
= prev
) != NULL
);
11667 /* But wait, there's more! Input sections up to group_size
11668 bytes before the stub section can be handled by it too.
11669 Don't do this if we have a really large section after the
11670 stubs, as adding more stubs increases the chance that
11671 branches may not reach into the stub section. */
11672 if (!stubs_always_before_branch
&& !big_sec
)
11675 while (prev
!= NULL
11676 && ((total
+= tail
->output_offset
- prev
->output_offset
)
11677 < (ppc64_elf_section_data (prev
) != NULL
11678 && ppc64_elf_section_data (prev
)->has_14bit_branch
11679 ? (group_size
= stub_group_size
>> 10)
11681 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
11684 prev
= htab
->sec_info
[tail
->id
].u
.list
;
11685 htab
->sec_info
[tail
->id
].u
.group
= group
;
11694 static const unsigned char glink_eh_frame_cie
[] =
11696 0, 0, 0, 16, /* length. */
11697 0, 0, 0, 0, /* id. */
11698 1, /* CIE version. */
11699 'z', 'R', 0, /* Augmentation string. */
11700 4, /* Code alignment. */
11701 0x78, /* Data alignment. */
11703 1, /* Augmentation size. */
11704 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
11705 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
11708 /* Stripping output sections is normally done before dynamic section
11709 symbols have been allocated. This function is called later, and
11710 handles cases like htab->brlt which is mapped to its own output
11714 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
11716 if (isec
->size
== 0
11717 && isec
->output_section
->size
== 0
11718 && !(isec
->output_section
->flags
& SEC_KEEP
)
11719 && !bfd_section_removed_from_list (info
->output_bfd
,
11720 isec
->output_section
)
11721 && elf_section_data (isec
->output_section
)->dynindx
== 0)
11723 isec
->output_section
->flags
|= SEC_EXCLUDE
;
11724 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
11725 info
->output_bfd
->section_count
--;
11729 /* Determine and set the size of the stub section for a final link.
11731 The basic idea here is to examine all the relocations looking for
11732 PC-relative calls to a target that is unreachable with a "bl"
11736 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
11738 bfd_size_type stub_group_size
;
11739 bfd_boolean stubs_always_before_branch
;
11740 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11745 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
11746 htab
->params
->plt_thread_safe
= 1;
11747 if (!htab
->opd_abi
)
11748 htab
->params
->plt_thread_safe
= 0;
11749 else if (htab
->params
->plt_thread_safe
== -1)
11751 static const char *const thread_starter
[] =
11755 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
11757 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
11758 "mq_notify", "create_timer",
11763 "GOMP_parallel_start",
11764 "GOMP_parallel_loop_static",
11765 "GOMP_parallel_loop_static_start",
11766 "GOMP_parallel_loop_dynamic",
11767 "GOMP_parallel_loop_dynamic_start",
11768 "GOMP_parallel_loop_guided",
11769 "GOMP_parallel_loop_guided_start",
11770 "GOMP_parallel_loop_runtime",
11771 "GOMP_parallel_loop_runtime_start",
11772 "GOMP_parallel_sections",
11773 "GOMP_parallel_sections_start",
11779 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
11781 struct elf_link_hash_entry
*h
;
11782 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
11783 FALSE
, FALSE
, TRUE
);
11784 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
11785 if (htab
->params
->plt_thread_safe
)
11789 stubs_always_before_branch
= htab
->params
->group_size
< 0;
11790 if (htab
->params
->group_size
< 0)
11791 stub_group_size
= -htab
->params
->group_size
;
11793 stub_group_size
= htab
->params
->group_size
;
11795 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
11798 #define STUB_SHRINK_ITER 20
11799 /* Loop until no stubs added. After iteration 20 of this loop we may
11800 exit on a stub section shrinking. This is to break out of a
11801 pathological case where adding stubs on one iteration decreases
11802 section gaps (perhaps due to alignment), which then requires
11803 fewer or smaller stubs on the next iteration. */
11808 unsigned int bfd_indx
;
11809 struct map_stub
*group
;
11811 htab
->stub_iteration
+= 1;
11813 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
11815 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
11817 Elf_Internal_Shdr
*symtab_hdr
;
11819 Elf_Internal_Sym
*local_syms
= NULL
;
11821 if (!is_ppc64_elf (input_bfd
))
11824 /* We'll need the symbol table in a second. */
11825 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
11826 if (symtab_hdr
->sh_info
== 0)
11829 /* Walk over each section attached to the input bfd. */
11830 for (section
= input_bfd
->sections
;
11832 section
= section
->next
)
11834 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
11836 /* If there aren't any relocs, then there's nothing more
11838 if ((section
->flags
& SEC_RELOC
) == 0
11839 || (section
->flags
& SEC_ALLOC
) == 0
11840 || (section
->flags
& SEC_LOAD
) == 0
11841 || (section
->flags
& SEC_CODE
) == 0
11842 || section
->reloc_count
== 0)
11845 /* If this section is a link-once section that will be
11846 discarded, then don't create any stubs. */
11847 if (section
->output_section
== NULL
11848 || section
->output_section
->owner
!= info
->output_bfd
)
11851 /* Get the relocs. */
11853 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
11854 info
->keep_memory
);
11855 if (internal_relocs
== NULL
)
11856 goto error_ret_free_local
;
11858 /* Now examine each relocation. */
11859 irela
= internal_relocs
;
11860 irelaend
= irela
+ section
->reloc_count
;
11861 for (; irela
< irelaend
; irela
++)
11863 enum elf_ppc64_reloc_type r_type
;
11864 unsigned int r_indx
;
11865 enum ppc_stub_type stub_type
;
11866 struct ppc_stub_hash_entry
*stub_entry
;
11867 asection
*sym_sec
, *code_sec
;
11868 bfd_vma sym_value
, code_value
;
11869 bfd_vma destination
;
11870 unsigned long local_off
;
11871 bfd_boolean ok_dest
;
11872 struct ppc_link_hash_entry
*hash
;
11873 struct ppc_link_hash_entry
*fdh
;
11874 struct elf_link_hash_entry
*h
;
11875 Elf_Internal_Sym
*sym
;
11877 const asection
*id_sec
;
11878 struct _opd_sec_data
*opd
;
11879 struct plt_entry
*plt_ent
;
11881 r_type
= ELF64_R_TYPE (irela
->r_info
);
11882 r_indx
= ELF64_R_SYM (irela
->r_info
);
11884 if (r_type
>= R_PPC64_max
)
11886 bfd_set_error (bfd_error_bad_value
);
11887 goto error_ret_free_internal
;
11890 /* Only look for stubs on branch instructions. */
11891 if (r_type
!= R_PPC64_REL24
11892 && r_type
!= R_PPC64_REL24_NOTOC
11893 && r_type
!= R_PPC64_REL14
11894 && r_type
!= R_PPC64_REL14_BRTAKEN
11895 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11898 /* Now determine the call target, its name, value,
11900 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
11901 r_indx
, input_bfd
))
11902 goto error_ret_free_internal
;
11903 hash
= (struct ppc_link_hash_entry
*) h
;
11910 sym_value
= sym
->st_value
;
11911 if (sym_sec
!= NULL
11912 && sym_sec
->output_section
!= NULL
)
11915 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
11916 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
11918 sym_value
= hash
->elf
.root
.u
.def
.value
;
11919 if (sym_sec
->output_section
!= NULL
)
11922 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
11923 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
11925 /* Recognise an old ABI func code entry sym, and
11926 use the func descriptor sym instead if it is
11928 if (hash
->elf
.root
.root
.string
[0] == '.'
11929 && hash
->oh
!= NULL
)
11931 fdh
= ppc_follow_link (hash
->oh
);
11932 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
11933 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
11935 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
11936 sym_value
= fdh
->elf
.root
.u
.def
.value
;
11937 if (sym_sec
->output_section
!= NULL
)
11946 bfd_set_error (bfd_error_bad_value
);
11947 goto error_ret_free_internal
;
11954 sym_value
+= irela
->r_addend
;
11955 destination
= (sym_value
11956 + sym_sec
->output_offset
11957 + sym_sec
->output_section
->vma
);
11958 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
11963 code_sec
= sym_sec
;
11964 code_value
= sym_value
;
11965 opd
= get_opd_info (sym_sec
);
11970 if (hash
== NULL
&& opd
->adjust
!= NULL
)
11972 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11975 code_value
+= adjust
;
11976 sym_value
+= adjust
;
11978 dest
= opd_entry_value (sym_sec
, sym_value
,
11979 &code_sec
, &code_value
, FALSE
);
11980 if (dest
!= (bfd_vma
) -1)
11982 destination
= dest
;
11985 /* Fixup old ABI sym to point at code
11987 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
11988 hash
->elf
.root
.u
.def
.section
= code_sec
;
11989 hash
->elf
.root
.u
.def
.value
= code_value
;
11994 /* Determine what (if any) linker stub is needed. */
11996 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
11997 &plt_ent
, destination
,
12000 if (r_type
== R_PPC64_REL24_NOTOC
)
12002 if (stub_type
== ppc_stub_plt_call
)
12003 stub_type
= ppc_stub_plt_call_notoc
;
12004 else if (stub_type
== ppc_stub_long_branch
12005 || (code_sec
!= NULL
12006 && code_sec
->output_section
!= NULL
12007 && (((hash
? hash
->elf
.other
: sym
->st_other
)
12008 & STO_PPC64_LOCAL_MASK
)
12009 != 1 << STO_PPC64_LOCAL_BIT
)))
12010 stub_type
= ppc_stub_long_branch_notoc
;
12012 else if (stub_type
!= ppc_stub_plt_call
)
12014 /* Check whether we need a TOC adjusting stub.
12015 Since the linker pastes together pieces from
12016 different object files when creating the
12017 _init and _fini functions, it may be that a
12018 call to what looks like a local sym is in
12019 fact a call needing a TOC adjustment. */
12020 if ((code_sec
!= NULL
12021 && code_sec
->output_section
!= NULL
12022 && (htab
->sec_info
[code_sec
->id
].toc_off
12023 != htab
->sec_info
[section
->id
].toc_off
)
12024 && (code_sec
->has_toc_reloc
12025 || code_sec
->makes_toc_func_call
))
12026 || (((hash
? hash
->elf
.other
: sym
->st_other
)
12027 & STO_PPC64_LOCAL_MASK
)
12028 == 1 << STO_PPC64_LOCAL_BIT
))
12029 stub_type
= ppc_stub_long_branch_r2off
;
12032 if (stub_type
== ppc_stub_none
)
12035 /* __tls_get_addr calls might be eliminated. */
12036 if (stub_type
!= ppc_stub_plt_call
12037 && stub_type
!= ppc_stub_plt_call_notoc
12039 && (hash
== htab
->tls_get_addr
12040 || hash
== htab
->tls_get_addr_fd
)
12041 && section
->has_tls_reloc
12042 && irela
!= internal_relocs
)
12044 /* Get tls info. */
12045 unsigned char *tls_mask
;
12047 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12048 irela
- 1, input_bfd
))
12049 goto error_ret_free_internal
;
12050 if ((*tls_mask
& TLS_TLS
) != 0)
12054 if (stub_type
== ppc_stub_plt_call
)
12057 && htab
->params
->plt_localentry0
!= 0
12058 && is_elfv2_localentry0 (&hash
->elf
))
12059 htab
->has_plt_localentry0
= 1;
12060 else if (irela
+ 1 < irelaend
12061 && irela
[1].r_offset
== irela
->r_offset
+ 4
12062 && (ELF64_R_TYPE (irela
[1].r_info
)
12063 == R_PPC64_TOCSAVE
))
12065 if (!tocsave_find (htab
, INSERT
,
12066 &local_syms
, irela
+ 1, input_bfd
))
12067 goto error_ret_free_internal
;
12070 stub_type
= ppc_stub_plt_call_r2save
;
12073 /* Support for grouping stub sections. */
12074 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12076 /* Get the name of this stub. */
12077 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12079 goto error_ret_free_internal
;
12081 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12082 stub_name
, FALSE
, FALSE
);
12083 if (stub_entry
!= NULL
)
12085 enum ppc_stub_type old_type
;
12086 /* A stub has already been created, but it may
12087 not be the required type. We shouldn't be
12088 transitioning from plt_call to long_branch
12089 stubs or vice versa, but we might be
12090 upgrading from plt_call to plt_call_r2save or
12091 from long_branch to long_branch_r2off. */
12093 old_type
= stub_entry
->stub_type
;
12099 case ppc_stub_save_res
:
12102 case ppc_stub_plt_call
:
12103 case ppc_stub_plt_call_r2save
:
12104 case ppc_stub_plt_call_notoc
:
12105 case ppc_stub_plt_call_both
:
12106 if (stub_type
== ppc_stub_plt_call
)
12108 else if (stub_type
== ppc_stub_plt_call_r2save
)
12110 if (old_type
== ppc_stub_plt_call_notoc
)
12111 stub_type
= ppc_stub_plt_call_both
;
12113 else if (stub_type
== ppc_stub_plt_call_notoc
)
12115 if (old_type
== ppc_stub_plt_call_r2save
)
12116 stub_type
= ppc_stub_plt_call_both
;
12122 case ppc_stub_plt_branch
:
12123 case ppc_stub_plt_branch_r2off
:
12124 case ppc_stub_plt_branch_notoc
:
12125 case ppc_stub_plt_branch_both
:
12126 old_type
+= (ppc_stub_long_branch
12127 - ppc_stub_plt_branch
);
12128 /* Fall through. */
12129 case ppc_stub_long_branch
:
12130 case ppc_stub_long_branch_r2off
:
12131 case ppc_stub_long_branch_notoc
:
12132 case ppc_stub_long_branch_both
:
12133 if (stub_type
== ppc_stub_long_branch
)
12135 else if (stub_type
== ppc_stub_long_branch_r2off
)
12137 if (old_type
== ppc_stub_long_branch_notoc
)
12138 stub_type
= ppc_stub_long_branch_both
;
12140 else if (stub_type
== ppc_stub_long_branch_notoc
)
12142 if (old_type
== ppc_stub_long_branch_r2off
)
12143 stub_type
= ppc_stub_long_branch_both
;
12149 if (old_type
< stub_type
)
12150 stub_entry
->stub_type
= stub_type
;
12154 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12155 if (stub_entry
== NULL
)
12158 error_ret_free_internal
:
12159 if (elf_section_data (section
)->relocs
== NULL
)
12160 free (internal_relocs
);
12161 error_ret_free_local
:
12162 if (local_syms
!= NULL
12163 && (symtab_hdr
->contents
12164 != (unsigned char *) local_syms
))
12169 stub_entry
->stub_type
= stub_type
;
12170 if (stub_type
>= ppc_stub_plt_call
12171 && stub_type
<= ppc_stub_plt_call_both
)
12173 stub_entry
->target_value
= sym_value
;
12174 stub_entry
->target_section
= sym_sec
;
12178 stub_entry
->target_value
= code_value
;
12179 stub_entry
->target_section
= code_sec
;
12181 stub_entry
->h
= hash
;
12182 stub_entry
->plt_ent
= plt_ent
;
12183 stub_entry
->symtype
12184 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
12185 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12187 if (stub_entry
->h
!= NULL
)
12188 htab
->stub_globals
+= 1;
12191 /* We're done with the internal relocs, free them. */
12192 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12193 free (internal_relocs
);
12196 if (local_syms
!= NULL
12197 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12199 if (!info
->keep_memory
)
12202 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12206 /* We may have added some stubs. Find out the new size of the
12208 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12210 group
->lr_restore
= 0;
12211 group
->eh_size
= 0;
12212 if (group
->stub_sec
!= NULL
)
12214 asection
*stub_sec
= group
->stub_sec
;
12216 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12217 || stub_sec
->rawsize
< stub_sec
->size
)
12218 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12219 stub_sec
->rawsize
= stub_sec
->size
;
12220 stub_sec
->size
= 0;
12221 stub_sec
->reloc_count
= 0;
12222 stub_sec
->flags
&= ~SEC_RELOC
;
12226 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12227 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
12228 htab
->brlt
->rawsize
= htab
->brlt
->size
;
12229 htab
->brlt
->size
= 0;
12230 htab
->brlt
->reloc_count
= 0;
12231 htab
->brlt
->flags
&= ~SEC_RELOC
;
12232 if (htab
->relbrlt
!= NULL
)
12233 htab
->relbrlt
->size
= 0;
12235 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12237 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12238 if (group
->needs_save_res
)
12239 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12241 if (info
->emitrelocations
12242 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12244 htab
->glink
->reloc_count
= 1;
12245 htab
->glink
->flags
|= SEC_RELOC
;
12248 if (htab
->glink_eh_frame
!= NULL
12249 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12250 && htab
->glink_eh_frame
->output_section
->size
> 8)
12252 size_t size
= 0, align
= 4;
12254 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12255 if (group
->eh_size
!= 0)
12256 size
+= (group
->eh_size
+ 17 + align
- 1) & -align
;
12257 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12258 size
+= (24 + align
- 1) & -align
;
12260 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
12261 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12262 size
= (size
+ align
- 1) & -align
;
12263 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12264 htab
->glink_eh_frame
->size
= size
;
12267 if (htab
->params
->plt_stub_align
!= 0)
12268 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12269 if (group
->stub_sec
!= NULL
)
12271 int align
= abs (htab
->params
->plt_stub_align
);
12272 group
->stub_sec
->size
12273 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12276 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12277 if (group
->stub_sec
!= NULL
12278 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
12279 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
12280 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
12284 && (htab
->brlt
->rawsize
== htab
->brlt
->size
12285 || (htab
->stub_iteration
> STUB_SHRINK_ITER
12286 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
12287 && (htab
->glink_eh_frame
== NULL
12288 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12291 /* Ask the linker to do its stuff. */
12292 (*htab
->params
->layout_sections_again
) ();
12295 if (htab
->glink_eh_frame
!= NULL
12296 && htab
->glink_eh_frame
->size
!= 0)
12299 bfd_byte
*p
, *last_fde
;
12300 size_t last_fde_len
, size
, align
, pad
;
12301 struct map_stub
*group
;
12303 /* It is necessary to at least have a rough outline of the
12304 linker generated CIEs and FDEs written before
12305 bfd_elf_discard_info is run, in order for these FDEs to be
12306 indexed in .eh_frame_hdr. */
12307 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12310 htab
->glink_eh_frame
->contents
= p
;
12314 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12315 /* CIE length (rewrite in case little-endian). */
12316 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
12317 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12318 p
+= last_fde_len
+ 4;
12320 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12321 if (group
->eh_size
!= 0)
12323 group
->eh_base
= p
- htab
->glink_eh_frame
->contents
;
12325 last_fde_len
= ((group
->eh_size
+ 17 + align
- 1) & -align
) - 4;
12327 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12330 val
= p
- htab
->glink_eh_frame
->contents
;
12331 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12333 /* Offset to stub section, written later. */
12335 /* stub section size. */
12336 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
12338 /* Augmentation. */
12340 /* Make sure we don't have all nops. This is enough for
12341 elf-eh-frame.c to detect the last non-nop opcode. */
12342 p
[group
->eh_size
- 1] = DW_CFA_advance_loc
+ 1;
12343 p
= last_fde
+ last_fde_len
+ 4;
12345 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12348 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
12350 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12353 val
= p
- htab
->glink_eh_frame
->contents
;
12354 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12356 /* Offset to .glink, written later. */
12359 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12361 /* Augmentation. */
12364 *p
++ = DW_CFA_advance_loc
+ 1;
12365 *p
++ = DW_CFA_register
;
12367 *p
++ = htab
->opd_abi
? 12 : 0;
12368 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
12369 *p
++ = DW_CFA_restore_extended
;
12371 p
+= ((24 + align
- 1) & -align
) - 24;
12373 /* Subsume any padding into the last FDE if user .eh_frame
12374 sections are aligned more than glink_eh_frame. Otherwise any
12375 zero padding will be seen as a terminator. */
12376 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12377 size
= p
- htab
->glink_eh_frame
->contents
;
12378 pad
= ((size
+ align
- 1) & -align
) - size
;
12379 htab
->glink_eh_frame
->size
= size
+ pad
;
12380 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
12383 maybe_strip_output (info
, htab
->brlt
);
12384 if (htab
->glink_eh_frame
!= NULL
)
12385 maybe_strip_output (info
, htab
->glink_eh_frame
);
12390 /* Called after we have determined section placement. If sections
12391 move, we'll be called again. Provide a value for TOCstart. */
12394 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
12397 bfd_vma TOCstart
, adjust
;
12401 struct elf_link_hash_entry
*h
;
12402 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
12404 if (is_elf_hash_table (htab
)
12405 && htab
->hgot
!= NULL
)
12409 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
12410 if (is_elf_hash_table (htab
))
12414 && h
->root
.type
== bfd_link_hash_defined
12415 && !h
->root
.linker_def
12416 && (!is_elf_hash_table (htab
)
12417 || h
->def_regular
))
12419 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
12420 + h
->root
.u
.def
.section
->output_offset
12421 + h
->root
.u
.def
.section
->output_section
->vma
);
12422 _bfd_set_gp_value (obfd
, TOCstart
);
12427 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12428 order. The TOC starts where the first of these sections starts. */
12429 s
= bfd_get_section_by_name (obfd
, ".got");
12430 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12431 s
= bfd_get_section_by_name (obfd
, ".toc");
12432 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12433 s
= bfd_get_section_by_name (obfd
, ".tocbss");
12434 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12435 s
= bfd_get_section_by_name (obfd
, ".plt");
12436 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12438 /* This may happen for
12439 o references to TOC base (SYM@toc / TOC[tc0]) without a
12441 o bad linker script
12442 o --gc-sections and empty TOC sections
12444 FIXME: Warn user? */
12446 /* Look for a likely section. We probably won't even be
12448 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12449 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
12451 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12454 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12455 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
12456 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12459 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12460 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
12464 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12465 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
12471 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
12473 /* Force alignment. */
12474 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
12475 TOCstart
-= adjust
;
12476 _bfd_set_gp_value (obfd
, TOCstart
);
12478 if (info
!= NULL
&& s
!= NULL
)
12480 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12484 if (htab
->elf
.hgot
!= NULL
)
12486 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
12487 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
12492 struct bfd_link_hash_entry
*bh
= NULL
;
12493 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
12494 s
, TOC_BASE_OFF
- adjust
,
12495 NULL
, FALSE
, FALSE
, &bh
);
12501 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
12502 write out any global entry stubs, and PLT relocations. */
12505 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
12507 struct bfd_link_info
*info
;
12508 struct ppc_link_hash_table
*htab
;
12509 struct plt_entry
*ent
;
12512 if (h
->root
.type
== bfd_link_hash_indirect
)
12516 htab
= ppc_hash_table (info
);
12520 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12521 if (ent
->plt
.offset
!= (bfd_vma
) -1)
12523 /* This symbol has an entry in the procedure linkage
12524 table. Set it up. */
12525 Elf_Internal_Rela rela
;
12526 asection
*plt
, *relplt
;
12529 if (!htab
->elf
.dynamic_sections_created
12530 || h
->dynindx
== -1)
12532 if (!(h
->def_regular
12533 && (h
->root
.type
== bfd_link_hash_defined
12534 || h
->root
.type
== bfd_link_hash_defweak
)))
12536 if (h
->type
== STT_GNU_IFUNC
)
12538 plt
= htab
->elf
.iplt
;
12539 relplt
= htab
->elf
.irelplt
;
12540 htab
->local_ifunc_resolver
= 1;
12542 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
12544 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12548 plt
= htab
->pltlocal
;
12549 if (bfd_link_pic (info
))
12551 relplt
= htab
->relpltlocal
;
12553 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
12555 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12560 rela
.r_addend
= (h
->root
.u
.def
.value
12561 + h
->root
.u
.def
.section
->output_offset
12562 + h
->root
.u
.def
.section
->output_section
->vma
12565 if (relplt
== NULL
)
12567 loc
= plt
->contents
+ ent
->plt
.offset
;
12568 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
12571 bfd_vma toc
= elf_gp (info
->output_bfd
);
12572 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
12573 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
12578 rela
.r_offset
= (plt
->output_section
->vma
12579 + plt
->output_offset
12580 + ent
->plt
.offset
);
12581 loc
= relplt
->contents
+ (relplt
->reloc_count
++
12582 * sizeof (Elf64_External_Rela
));
12583 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12588 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
12589 + htab
->elf
.splt
->output_offset
12590 + ent
->plt
.offset
);
12591 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
12592 rela
.r_addend
= ent
->addend
;
12593 loc
= (htab
->elf
.srelplt
->contents
12594 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
12595 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
12596 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
12597 htab
->maybe_local_ifunc_resolver
= 1;
12598 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12602 if (!h
->pointer_equality_needed
)
12605 if (h
->def_regular
)
12608 s
= htab
->global_entry
;
12609 if (s
== NULL
|| s
->size
== 0)
12612 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
12613 if (ent
->plt
.offset
!= (bfd_vma
) -1
12614 && ent
->addend
== 0)
12620 p
= s
->contents
+ h
->root
.u
.def
.value
;
12621 plt
= htab
->elf
.splt
;
12622 if (!htab
->elf
.dynamic_sections_created
12623 || h
->dynindx
== -1)
12625 if (h
->type
== STT_GNU_IFUNC
)
12626 plt
= htab
->elf
.iplt
;
12628 plt
= htab
->pltlocal
;
12630 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
12631 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
12633 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
12635 info
->callbacks
->einfo
12636 (_("%P: linkage table error against `%pT'\n"),
12637 h
->root
.root
.string
);
12638 bfd_set_error (bfd_error_bad_value
);
12639 htab
->stub_error
= TRUE
;
12642 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
12643 if (htab
->params
->emit_stub_syms
)
12645 size_t len
= strlen (h
->root
.root
.string
);
12646 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
12651 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
12652 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
12655 if (h
->root
.type
== bfd_link_hash_new
)
12657 h
->root
.type
= bfd_link_hash_defined
;
12658 h
->root
.u
.def
.section
= s
;
12659 h
->root
.u
.def
.value
= p
- s
->contents
;
12660 h
->ref_regular
= 1;
12661 h
->def_regular
= 1;
12662 h
->ref_regular_nonweak
= 1;
12663 h
->forced_local
= 1;
12665 h
->root
.linker_def
= 1;
12669 if (PPC_HA (off
) != 0)
12671 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
12674 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
12676 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
12678 bfd_put_32 (s
->owner
, BCTR
, p
);
12684 /* Write PLT relocs for locals. */
12687 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
12689 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12692 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12694 struct got_entry
**lgot_ents
, **end_lgot_ents
;
12695 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
12696 Elf_Internal_Shdr
*symtab_hdr
;
12697 bfd_size_type locsymcount
;
12698 Elf_Internal_Sym
*local_syms
= NULL
;
12699 struct plt_entry
*ent
;
12701 if (!is_ppc64_elf (ibfd
))
12704 lgot_ents
= elf_local_got_ents (ibfd
);
12708 symtab_hdr
= &elf_symtab_hdr (ibfd
);
12709 locsymcount
= symtab_hdr
->sh_info
;
12710 end_lgot_ents
= lgot_ents
+ locsymcount
;
12711 local_plt
= (struct plt_entry
**) end_lgot_ents
;
12712 end_local_plt
= local_plt
+ locsymcount
;
12713 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
12714 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
12715 if (ent
->plt
.offset
!= (bfd_vma
) -1)
12717 Elf_Internal_Sym
*sym
;
12719 asection
*plt
, *relplt
;
12723 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
12724 lplt
- local_plt
, ibfd
))
12726 if (local_syms
!= NULL
12727 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12732 val
= sym
->st_value
+ ent
->addend
;
12733 val
+= PPC64_LOCAL_ENTRY_OFFSET (sym
->st_other
);
12734 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
12735 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
12737 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
12739 htab
->local_ifunc_resolver
= 1;
12740 plt
= htab
->elf
.iplt
;
12741 relplt
= htab
->elf
.irelplt
;
12745 plt
= htab
->pltlocal
;
12746 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
12749 if (relplt
== NULL
)
12751 loc
= plt
->contents
+ ent
->plt
.offset
;
12752 bfd_put_64 (info
->output_bfd
, val
, loc
);
12755 bfd_vma toc
= elf_gp (ibfd
);
12756 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
12761 Elf_Internal_Rela rela
;
12762 rela
.r_offset
= (ent
->plt
.offset
12763 + plt
->output_offset
12764 + plt
->output_section
->vma
);
12765 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
12768 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
12770 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
12775 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
12777 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
12779 rela
.r_addend
= val
;
12780 loc
= relplt
->contents
+ (relplt
->reloc_count
++
12781 * sizeof (Elf64_External_Rela
));
12782 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
12786 if (local_syms
!= NULL
12787 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12789 if (!info
->keep_memory
)
12792 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12798 /* Build all the stubs associated with the current output file.
12799 The stubs are kept in a hash table attached to the main linker
12800 hash table. This function is called via gldelf64ppc_finish. */
12803 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
12806 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12807 struct map_stub
*group
;
12808 asection
*stub_sec
;
12810 int stub_sec_count
= 0;
12815 /* Allocate memory to hold the linker stubs. */
12816 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12818 group
->eh_size
= 0;
12819 group
->lr_restore
= 0;
12820 if ((stub_sec
= group
->stub_sec
) != NULL
12821 && stub_sec
->size
!= 0)
12823 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
,
12825 if (stub_sec
->contents
== NULL
)
12827 stub_sec
->size
= 0;
12831 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12836 /* Build the .glink plt call stub. */
12837 if (htab
->params
->emit_stub_syms
)
12839 struct elf_link_hash_entry
*h
;
12840 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
12841 TRUE
, FALSE
, FALSE
);
12844 if (h
->root
.type
== bfd_link_hash_new
)
12846 h
->root
.type
= bfd_link_hash_defined
;
12847 h
->root
.u
.def
.section
= htab
->glink
;
12848 h
->root
.u
.def
.value
= 8;
12849 h
->ref_regular
= 1;
12850 h
->def_regular
= 1;
12851 h
->ref_regular_nonweak
= 1;
12852 h
->forced_local
= 1;
12854 h
->root
.linker_def
= 1;
12857 plt0
= (htab
->elf
.splt
->output_section
->vma
12858 + htab
->elf
.splt
->output_offset
12860 if (info
->emitrelocations
)
12862 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
12865 r
->r_offset
= (htab
->glink
->output_offset
12866 + htab
->glink
->output_section
->vma
);
12867 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
12868 r
->r_addend
= plt0
;
12870 p
= htab
->glink
->contents
;
12871 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
12872 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
12876 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
12878 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
12880 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
12882 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
12884 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
12886 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
12888 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
12890 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
12892 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
12894 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
12899 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
12901 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
12903 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
12905 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
12907 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
12909 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
12911 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
12913 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
12915 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
12917 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
12919 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
12921 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
12923 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
12926 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
12928 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
12930 /* Build the .glink lazy link call stubs. */
12932 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
12938 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
12943 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
12945 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
12950 bfd_put_32 (htab
->glink
->owner
,
12951 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
12957 /* Build .glink global entry stubs, and PLT relocs for globals. */
12958 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
12960 if (!write_plt_relocs_for_local_syms (info
))
12963 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
12965 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
12967 if (htab
->brlt
->contents
== NULL
)
12970 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
12972 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
12973 htab
->relbrlt
->size
);
12974 if (htab
->relbrlt
->contents
== NULL
)
12978 /* Build the stubs as directed by the stub hash table. */
12979 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
12981 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12982 if (group
->needs_save_res
)
12983 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12985 if (htab
->relbrlt
!= NULL
)
12986 htab
->relbrlt
->reloc_count
= 0;
12988 if (htab
->params
->plt_stub_align
!= 0)
12989 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12990 if ((stub_sec
= group
->stub_sec
) != NULL
)
12992 int align
= abs (htab
->params
->plt_stub_align
);
12993 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12996 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12997 if (group
->needs_save_res
)
12999 stub_sec
= group
->stub_sec
;
13000 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
13001 htab
->sfpr
->contents
, htab
->sfpr
->size
);
13002 if (htab
->params
->emit_stub_syms
)
13006 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13007 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13012 if (htab
->glink_eh_frame
!= NULL
13013 && htab
->glink_eh_frame
->size
!= 0)
13018 p
= htab
->glink_eh_frame
->contents
;
13019 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
13021 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13022 if (group
->eh_size
!= 0)
13024 /* Offset to stub section. */
13025 val
= (group
->stub_sec
->output_section
->vma
13026 + group
->stub_sec
->output_offset
);
13027 val
-= (htab
->glink_eh_frame
->output_section
->vma
13028 + htab
->glink_eh_frame
->output_offset
13029 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
13030 if (val
+ 0x80000000 > 0xffffffff)
13033 (_("%s offset too large for .eh_frame sdata4 encoding"),
13034 group
->stub_sec
->name
);
13037 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
13038 p
+= (group
->eh_size
+ 17 + 3) & -4;
13040 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13042 /* Offset to .glink. */
13043 val
= (htab
->glink
->output_section
->vma
13044 + htab
->glink
->output_offset
13046 val
-= (htab
->glink_eh_frame
->output_section
->vma
13047 + htab
->glink_eh_frame
->output_offset
13048 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
13049 if (val
+ 0x80000000 > 0xffffffff)
13052 (_("%s offset too large for .eh_frame sdata4 encoding"),
13053 htab
->glink
->name
);
13056 bfd_put_32 (htab
->elf
.dynobj
, val
, p
+ 8);
13057 p
+= (24 + align
- 1) & -align
;
13061 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13062 if ((stub_sec
= group
->stub_sec
) != NULL
)
13064 stub_sec_count
+= 1;
13065 if (stub_sec
->rawsize
!= stub_sec
->size
13066 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13067 || stub_sec
->rawsize
< stub_sec
->size
))
13073 htab
->stub_error
= TRUE
;
13074 _bfd_error_handler (_("stubs don't match calculated size"));
13077 if (htab
->stub_error
)
13083 *stats
= bfd_malloc (500);
13084 if (*stats
== NULL
)
13087 len
= sprintf (*stats
,
13088 ngettext ("linker stubs in %u group\n",
13089 "linker stubs in %u groups\n",
13092 sprintf (*stats
+ len
, _(" branch %lu\n"
13093 " branch toc adj %lu\n"
13094 " branch notoc %lu\n"
13095 " branch both %lu\n"
13096 " long branch %lu\n"
13097 " long toc adj %lu\n"
13098 " long notoc %lu\n"
13101 " plt call save %lu\n"
13102 " plt call notoc %lu\n"
13103 " plt call both %lu\n"
13104 " global entry %lu"),
13105 htab
->stub_count
[ppc_stub_long_branch
- 1],
13106 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13107 htab
->stub_count
[ppc_stub_long_branch_notoc
- 1],
13108 htab
->stub_count
[ppc_stub_long_branch_both
- 1],
13109 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13110 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13111 htab
->stub_count
[ppc_stub_plt_branch_notoc
- 1],
13112 htab
->stub_count
[ppc_stub_plt_branch_both
- 1],
13113 htab
->stub_count
[ppc_stub_plt_call
- 1],
13114 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13115 htab
->stub_count
[ppc_stub_plt_call_notoc
- 1],
13116 htab
->stub_count
[ppc_stub_plt_call_both
- 1],
13117 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13122 /* What to do when ld finds relocations against symbols defined in
13123 discarded sections. */
13125 static unsigned int
13126 ppc64_elf_action_discarded (asection
*sec
)
13128 if (strcmp (".opd", sec
->name
) == 0)
13131 if (strcmp (".toc", sec
->name
) == 0)
13134 if (strcmp (".toc1", sec
->name
) == 0)
13137 return _bfd_elf_default_action_discarded (sec
);
13140 /* The RELOCATE_SECTION function is called by the ELF backend linker
13141 to handle the relocations for a section.
13143 The relocs are always passed as Rela structures; if the section
13144 actually uses Rel structures, the r_addend field will always be
13147 This function is responsible for adjust the section contents as
13148 necessary, and (if using Rela relocs and generating a
13149 relocatable output file) adjusting the reloc addend as
13152 This function does not have to worry about setting the reloc
13153 address or the reloc symbol index.
13155 LOCAL_SYMS is a pointer to the swapped in local symbols.
13157 LOCAL_SECTIONS is an array giving the section in the input file
13158 corresponding to the st_shndx field of each local symbol.
13160 The global hash table entry for the global symbols can be found
13161 via elf_sym_hashes (input_bfd).
13163 When generating relocatable output, this function must handle
13164 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13165 going to be the section symbol corresponding to the output
13166 section, which means that the addend must be adjusted
13170 ppc64_elf_relocate_section (bfd
*output_bfd
,
13171 struct bfd_link_info
*info
,
13173 asection
*input_section
,
13174 bfd_byte
*contents
,
13175 Elf_Internal_Rela
*relocs
,
13176 Elf_Internal_Sym
*local_syms
,
13177 asection
**local_sections
)
13179 struct ppc_link_hash_table
*htab
;
13180 Elf_Internal_Shdr
*symtab_hdr
;
13181 struct elf_link_hash_entry
**sym_hashes
;
13182 Elf_Internal_Rela
*rel
;
13183 Elf_Internal_Rela
*wrel
;
13184 Elf_Internal_Rela
*relend
;
13185 Elf_Internal_Rela outrel
;
13187 struct got_entry
**local_got_ents
;
13189 bfd_boolean ret
= TRUE
;
13190 bfd_boolean is_opd
;
13191 /* Assume 'at' branch hints. */
13192 bfd_boolean is_isa_v2
= TRUE
;
13193 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13195 /* Initialize howto table if needed. */
13196 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13199 htab
= ppc_hash_table (info
);
13203 /* Don't relocate stub sections. */
13204 if (input_section
->owner
== htab
->params
->stub_bfd
)
13207 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13209 local_got_ents
= elf_local_got_ents (input_bfd
);
13210 TOCstart
= elf_gp (output_bfd
);
13211 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13212 sym_hashes
= elf_sym_hashes (input_bfd
);
13213 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13215 rel
= wrel
= relocs
;
13216 relend
= relocs
+ input_section
->reloc_count
;
13217 for (; rel
< relend
; wrel
++, rel
++)
13219 enum elf_ppc64_reloc_type r_type
;
13221 bfd_reloc_status_type r
;
13222 Elf_Internal_Sym
*sym
;
13224 struct elf_link_hash_entry
*h_elf
;
13225 struct ppc_link_hash_entry
*h
;
13226 struct ppc_link_hash_entry
*fdh
;
13227 const char *sym_name
;
13228 unsigned long r_symndx
, toc_symndx
;
13229 bfd_vma toc_addend
;
13230 unsigned char tls_mask
, tls_gd
, tls_type
;
13231 unsigned char sym_type
;
13232 bfd_vma relocation
;
13233 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
13234 bfd_boolean warned
;
13235 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13238 struct ppc_stub_hash_entry
*stub_entry
;
13239 bfd_vma max_br_offset
;
13241 Elf_Internal_Rela orig_rel
;
13242 reloc_howto_type
*howto
;
13243 struct reloc_howto_struct alt_howto
;
13248 r_type
= ELF64_R_TYPE (rel
->r_info
);
13249 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13251 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13252 symbol of the previous ADDR64 reloc. The symbol gives us the
13253 proper TOC base to use. */
13254 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13256 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13258 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13264 unresolved_reloc
= FALSE
;
13267 if (r_symndx
< symtab_hdr
->sh_info
)
13269 /* It's a local symbol. */
13270 struct _opd_sec_data
*opd
;
13272 sym
= local_syms
+ r_symndx
;
13273 sec
= local_sections
[r_symndx
];
13274 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13275 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13276 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13277 opd
= get_opd_info (sec
);
13278 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13280 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13286 /* If this is a relocation against the opd section sym
13287 and we have edited .opd, adjust the reloc addend so
13288 that ld -r and ld --emit-relocs output is correct.
13289 If it is a reloc against some other .opd symbol,
13290 then the symbol value will be adjusted later. */
13291 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13292 rel
->r_addend
+= adjust
;
13294 relocation
+= adjust
;
13300 bfd_boolean ignored
;
13302 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13303 r_symndx
, symtab_hdr
, sym_hashes
,
13304 h_elf
, sec
, relocation
,
13305 unresolved_reloc
, warned
, ignored
);
13306 sym_name
= h_elf
->root
.root
.string
;
13307 sym_type
= h_elf
->type
;
13309 && sec
->owner
== output_bfd
13310 && strcmp (sec
->name
, ".opd") == 0)
13312 /* This is a symbol defined in a linker script. All
13313 such are defined in output sections, even those
13314 defined by simple assignment from a symbol defined in
13315 an input section. Transfer the symbol to an
13316 appropriate input .opd section, so that a branch to
13317 this symbol will be mapped to the location specified
13318 by the opd entry. */
13319 struct bfd_link_order
*lo
;
13320 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13321 if (lo
->type
== bfd_indirect_link_order
)
13323 asection
*isec
= lo
->u
.indirect
.section
;
13324 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13325 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13328 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13329 h_elf
->root
.u
.def
.section
= isec
;
13336 h
= (struct ppc_link_hash_entry
*) h_elf
;
13338 if (sec
!= NULL
&& discarded_section (sec
))
13340 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
13341 input_bfd
, input_section
,
13342 contents
+ rel
->r_offset
);
13343 wrel
->r_offset
= rel
->r_offset
;
13345 wrel
->r_addend
= 0;
13347 /* For ld -r, remove relocations in debug sections against
13348 symbols defined in discarded sections. Not done for
13349 non-debug to preserve relocs in .eh_frame which the
13350 eh_frame editing code expects to be present. */
13351 if (bfd_link_relocatable (info
)
13352 && (input_section
->flags
& SEC_DEBUGGING
))
13358 if (bfd_link_relocatable (info
))
13361 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13363 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13364 sec
= bfd_abs_section_ptr
;
13365 unresolved_reloc
= FALSE
;
13368 /* TLS optimizations. Replace instruction sequences and relocs
13369 based on information we collected in tls_optimize. We edit
13370 RELOCS so that --emit-relocs will output something sensible
13371 for the final instruction stream. */
13376 tls_mask
= h
->tls_mask
;
13377 else if (local_got_ents
!= NULL
)
13379 struct plt_entry
**local_plt
= (struct plt_entry
**)
13380 (local_got_ents
+ symtab_hdr
->sh_info
);
13381 unsigned char *lgot_masks
= (unsigned char *)
13382 (local_plt
+ symtab_hdr
->sh_info
);
13383 tls_mask
= lgot_masks
[r_symndx
];
13385 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
13386 && (r_type
== R_PPC64_TLS
13387 || r_type
== R_PPC64_TLSGD
13388 || r_type
== R_PPC64_TLSLD
))
13390 /* Check for toc tls entries. */
13391 unsigned char *toc_tls
;
13393 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13394 &local_syms
, rel
, input_bfd
))
13398 tls_mask
= *toc_tls
;
13401 /* Check that tls relocs are used with tls syms, and non-tls
13402 relocs are used with non-tls syms. */
13403 if (r_symndx
!= STN_UNDEF
13404 && r_type
!= R_PPC64_NONE
13406 || h
->elf
.root
.type
== bfd_link_hash_defined
13407 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13408 && (IS_PPC64_TLS_RELOC (r_type
)
13409 != (sym_type
== STT_TLS
13410 || (sym_type
== STT_SECTION
13411 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13413 if ((tls_mask
& TLS_TLS
) != 0
13414 && (r_type
== R_PPC64_TLS
13415 || r_type
== R_PPC64_TLSGD
13416 || r_type
== R_PPC64_TLSLD
))
13417 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13420 info
->callbacks
->einfo
13421 (!IS_PPC64_TLS_RELOC (r_type
)
13422 /* xgettext:c-format */
13423 ? _("%H: %s used with TLS symbol `%pT'\n")
13424 /* xgettext:c-format */
13425 : _("%H: %s used with non-TLS symbol `%pT'\n"),
13426 input_bfd
, input_section
, rel
->r_offset
,
13427 ppc64_elf_howto_table
[r_type
]->name
,
13431 /* Ensure reloc mapping code below stays sane. */
13432 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13433 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13434 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13435 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13436 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13437 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13438 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13439 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13440 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13441 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
13449 case R_PPC64_LO_DS_OPT
:
13450 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
13451 if ((insn
& (0x3f << 26)) != 58u << 26)
13453 insn
+= (14u << 26) - (58u << 26);
13454 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13455 r_type
= R_PPC64_TOC16_LO
;
13456 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13459 case R_PPC64_TOC16
:
13460 case R_PPC64_TOC16_LO
:
13461 case R_PPC64_TOC16_DS
:
13462 case R_PPC64_TOC16_LO_DS
:
13464 /* Check for toc tls entries. */
13465 unsigned char *toc_tls
;
13468 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13469 &local_syms
, rel
, input_bfd
);
13475 tls_mask
= *toc_tls
;
13476 if (r_type
== R_PPC64_TOC16_DS
13477 || r_type
== R_PPC64_TOC16_LO_DS
)
13479 if ((tls_mask
& TLS_TLS
) != 0
13480 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
13485 /* If we found a GD reloc pair, then we might be
13486 doing a GD->IE transition. */
13489 tls_gd
= TLS_TPRELGD
;
13490 if ((tls_mask
& TLS_TLS
) != 0
13491 && (tls_mask
& TLS_GD
) == 0)
13494 else if (retval
== 3)
13496 if ((tls_mask
& TLS_TLS
) != 0
13497 && (tls_mask
& TLS_LD
) == 0)
13505 case R_PPC64_GOT_TPREL16_HI
:
13506 case R_PPC64_GOT_TPREL16_HA
:
13507 if ((tls_mask
& TLS_TLS
) != 0
13508 && (tls_mask
& TLS_TPREL
) == 0)
13510 rel
->r_offset
-= d_offset
;
13511 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13512 r_type
= R_PPC64_NONE
;
13513 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13517 case R_PPC64_GOT_TPREL16_DS
:
13518 case R_PPC64_GOT_TPREL16_LO_DS
:
13519 if ((tls_mask
& TLS_TLS
) != 0
13520 && (tls_mask
& TLS_TPREL
) == 0)
13523 insn
= bfd_get_32 (input_bfd
,
13524 contents
+ rel
->r_offset
- d_offset
);
13526 insn
|= 0x3c0d0000; /* addis 0,13,0 */
13527 bfd_put_32 (input_bfd
, insn
,
13528 contents
+ rel
->r_offset
- d_offset
);
13529 r_type
= R_PPC64_TPREL16_HA
;
13530 if (toc_symndx
!= 0)
13532 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13533 rel
->r_addend
= toc_addend
;
13534 /* We changed the symbol. Start over in order to
13535 get h, sym, sec etc. right. */
13539 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13544 if ((tls_mask
& TLS_TLS
) != 0
13545 && (tls_mask
& TLS_TPREL
) == 0)
13547 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13548 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
13551 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
13552 /* Was PPC64_TLS which sits on insn boundary, now
13553 PPC64_TPREL16_LO which is at low-order half-word. */
13554 rel
->r_offset
+= d_offset
;
13555 r_type
= R_PPC64_TPREL16_LO
;
13556 if (toc_symndx
!= 0)
13558 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13559 rel
->r_addend
= toc_addend
;
13560 /* We changed the symbol. Start over in order to
13561 get h, sym, sec etc. right. */
13565 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13569 case R_PPC64_GOT_TLSGD16_HI
:
13570 case R_PPC64_GOT_TLSGD16_HA
:
13571 tls_gd
= TLS_TPRELGD
;
13572 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13576 case R_PPC64_GOT_TLSLD16_HI
:
13577 case R_PPC64_GOT_TLSLD16_HA
:
13578 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13581 if ((tls_mask
& tls_gd
) != 0)
13582 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13583 + R_PPC64_GOT_TPREL16_DS
);
13586 rel
->r_offset
-= d_offset
;
13587 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13588 r_type
= R_PPC64_NONE
;
13590 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13594 case R_PPC64_GOT_TLSGD16
:
13595 case R_PPC64_GOT_TLSGD16_LO
:
13596 tls_gd
= TLS_TPRELGD
;
13597 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
13601 case R_PPC64_GOT_TLSLD16
:
13602 case R_PPC64_GOT_TLSLD16_LO
:
13603 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
13605 unsigned int insn1
, insn2
;
13609 offset
= (bfd_vma
) -1;
13610 /* If not using the newer R_PPC64_TLSGD/LD to mark
13611 __tls_get_addr calls, we must trust that the call
13612 stays with its arg setup insns, ie. that the next
13613 reloc is the __tls_get_addr call associated with
13614 the current reloc. Edit both insns. */
13615 if (input_section
->has_tls_get_addr_call
13616 && rel
+ 1 < relend
13617 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
13618 htab
->tls_get_addr
,
13619 htab
->tls_get_addr_fd
))
13620 offset
= rel
[1].r_offset
;
13621 /* We read the low GOT_TLS (or TOC16) insn because we
13622 need to keep the destination reg. It may be
13623 something other than the usual r3, and moved to r3
13624 before the call by intervening code. */
13625 insn1
= bfd_get_32 (input_bfd
,
13626 contents
+ rel
->r_offset
- d_offset
);
13627 if ((tls_mask
& tls_gd
) != 0)
13630 insn1
&= (0x1f << 21) | (0x1f << 16);
13631 insn1
|= 58 << 26; /* ld */
13632 insn2
= 0x7c636a14; /* add 3,3,13 */
13633 if (offset
!= (bfd_vma
) -1)
13634 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13635 if ((tls_mask
& TLS_EXPLICIT
) == 0)
13636 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13637 + R_PPC64_GOT_TPREL16_DS
);
13639 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
13640 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13645 insn1
&= 0x1f << 21;
13646 insn1
|= 0x3c0d0000; /* addis r,13,0 */
13647 insn2
= 0x38630000; /* addi 3,3,0 */
13650 /* Was an LD reloc. */
13652 sec
= local_sections
[toc_symndx
];
13654 r_symndx
< symtab_hdr
->sh_info
;
13656 if (local_sections
[r_symndx
] == sec
)
13658 if (r_symndx
>= symtab_hdr
->sh_info
)
13659 r_symndx
= STN_UNDEF
;
13660 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13661 if (r_symndx
!= STN_UNDEF
)
13662 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13663 + sec
->output_offset
13664 + sec
->output_section
->vma
);
13666 else if (toc_symndx
!= 0)
13668 r_symndx
= toc_symndx
;
13669 rel
->r_addend
= toc_addend
;
13671 r_type
= R_PPC64_TPREL16_HA
;
13672 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13673 if (offset
!= (bfd_vma
) -1)
13675 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
13676 R_PPC64_TPREL16_LO
);
13677 rel
[1].r_offset
= offset
+ d_offset
;
13678 rel
[1].r_addend
= rel
->r_addend
;
13681 bfd_put_32 (input_bfd
, insn1
,
13682 contents
+ rel
->r_offset
- d_offset
);
13683 if (offset
!= (bfd_vma
) -1)
13684 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13685 if ((tls_mask
& tls_gd
) == 0
13686 && (tls_gd
== 0 || toc_symndx
!= 0))
13688 /* We changed the symbol. Start over in order
13689 to get h, sym, sec etc. right. */
13695 case R_PPC64_TLSGD
:
13696 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
13697 && rel
+ 1 < relend
)
13699 unsigned int insn2
;
13700 bfd_vma offset
= rel
->r_offset
;
13702 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
13704 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
13705 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13709 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
13710 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
13712 if ((tls_mask
& TLS_TPRELGD
) != 0)
13715 r_type
= R_PPC64_NONE
;
13716 insn2
= 0x7c636a14; /* add 3,3,13 */
13721 if (toc_symndx
!= 0)
13723 r_symndx
= toc_symndx
;
13724 rel
->r_addend
= toc_addend
;
13726 r_type
= R_PPC64_TPREL16_LO
;
13727 rel
->r_offset
= offset
+ d_offset
;
13728 insn2
= 0x38630000; /* addi 3,3,0 */
13730 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13731 /* Zap the reloc on the _tls_get_addr call too. */
13732 BFD_ASSERT (offset
== rel
[1].r_offset
);
13733 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13734 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13735 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
13740 case R_PPC64_TLSLD
:
13741 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
13742 && rel
+ 1 < relend
)
13744 unsigned int insn2
;
13745 bfd_vma offset
= rel
->r_offset
;
13747 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
13749 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
13750 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13754 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
13755 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
13758 sec
= local_sections
[toc_symndx
];
13760 r_symndx
< symtab_hdr
->sh_info
;
13762 if (local_sections
[r_symndx
] == sec
)
13764 if (r_symndx
>= symtab_hdr
->sh_info
)
13765 r_symndx
= STN_UNDEF
;
13766 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13767 if (r_symndx
!= STN_UNDEF
)
13768 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13769 + sec
->output_offset
13770 + sec
->output_section
->vma
);
13772 r_type
= R_PPC64_TPREL16_LO
;
13773 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13774 rel
->r_offset
= offset
+ d_offset
;
13775 /* Zap the reloc on the _tls_get_addr call too. */
13776 BFD_ASSERT (offset
== rel
[1].r_offset
);
13777 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13778 insn2
= 0x38630000; /* addi 3,3,0 */
13779 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13784 case R_PPC64_DTPMOD64
:
13785 if (rel
+ 1 < relend
13786 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
13787 && rel
[1].r_offset
== rel
->r_offset
+ 8)
13789 if ((tls_mask
& TLS_GD
) == 0)
13791 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
13792 if ((tls_mask
& TLS_TPRELGD
) != 0)
13793 r_type
= R_PPC64_TPREL64
;
13796 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13797 r_type
= R_PPC64_NONE
;
13799 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13804 if ((tls_mask
& TLS_LD
) == 0)
13806 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13807 r_type
= R_PPC64_NONE
;
13808 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13813 case R_PPC64_TPREL64
:
13814 if ((tls_mask
& TLS_TPREL
) == 0)
13816 r_type
= R_PPC64_NONE
;
13817 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13821 case R_PPC64_ENTRY
:
13822 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13823 if (!bfd_link_pic (info
)
13824 && !info
->traditional_format
13825 && relocation
+ 0x80008000 <= 0xffffffff)
13827 unsigned int insn1
, insn2
;
13829 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13830 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
13831 if ((insn1
& ~0xfffc) == LD_R2_0R12
13832 && insn2
== ADD_R2_R2_R12
)
13834 bfd_put_32 (input_bfd
,
13835 LIS_R2
+ PPC_HA (relocation
),
13836 contents
+ rel
->r_offset
);
13837 bfd_put_32 (input_bfd
,
13838 ADDI_R2_R2
+ PPC_LO (relocation
),
13839 contents
+ rel
->r_offset
+ 4);
13844 relocation
-= (rel
->r_offset
13845 + input_section
->output_offset
13846 + input_section
->output_section
->vma
);
13847 if (relocation
+ 0x80008000 <= 0xffffffff)
13849 unsigned int insn1
, insn2
;
13851 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13852 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
13853 if ((insn1
& ~0xfffc) == LD_R2_0R12
13854 && insn2
== ADD_R2_R2_R12
)
13856 bfd_put_32 (input_bfd
,
13857 ADDIS_R2_R12
+ PPC_HA (relocation
),
13858 contents
+ rel
->r_offset
);
13859 bfd_put_32 (input_bfd
,
13860 ADDI_R2_R2
+ PPC_LO (relocation
),
13861 contents
+ rel
->r_offset
+ 4);
13867 case R_PPC64_REL16_HA
:
13868 /* If we are generating a non-PIC executable, edit
13869 . 0: addis 2,12,.TOC.-0b@ha
13870 . addi 2,2,.TOC.-0b@l
13871 used by ELFv2 global entry points to set up r2, to
13874 if .TOC. is in range. */
13875 if (!bfd_link_pic (info
)
13876 && !info
->traditional_format
13878 && rel
->r_addend
== d_offset
13879 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
13880 && rel
+ 1 < relend
13881 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
13882 && rel
[1].r_offset
== rel
->r_offset
+ 4
13883 && rel
[1].r_addend
== rel
->r_addend
+ 4
13884 && relocation
+ 0x80008000 <= 0xffffffff)
13886 unsigned int insn1
, insn2
;
13887 bfd_vma offset
= rel
->r_offset
- d_offset
;
13888 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
13889 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
13890 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
13891 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
13893 r_type
= R_PPC64_ADDR16_HA
;
13894 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13895 rel
->r_addend
-= d_offset
;
13896 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
13897 rel
[1].r_addend
-= d_offset
+ 4;
13898 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
13904 /* Handle other relocations that tweak non-addend part of insn. */
13906 max_br_offset
= 1 << 25;
13907 addend
= rel
->r_addend
;
13908 reloc_dest
= DEST_NORMAL
;
13914 case R_PPC64_TOCSAVE
:
13915 if (relocation
+ addend
== (rel
->r_offset
13916 + input_section
->output_offset
13917 + input_section
->output_section
->vma
)
13918 && tocsave_find (htab
, NO_INSERT
,
13919 &local_syms
, rel
, input_bfd
))
13921 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13923 || insn
== CROR_151515
|| insn
== CROR_313131
)
13924 bfd_put_32 (input_bfd
,
13925 STD_R2_0R1
+ STK_TOC (htab
),
13926 contents
+ rel
->r_offset
);
13930 /* Branch taken prediction relocations. */
13931 case R_PPC64_ADDR14_BRTAKEN
:
13932 case R_PPC64_REL14_BRTAKEN
:
13933 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
13934 /* Fall through. */
13936 /* Branch not taken prediction relocations. */
13937 case R_PPC64_ADDR14_BRNTAKEN
:
13938 case R_PPC64_REL14_BRNTAKEN
:
13939 insn
|= bfd_get_32 (input_bfd
,
13940 contents
+ rel
->r_offset
) & ~(0x01 << 21);
13941 /* Fall through. */
13943 case R_PPC64_REL14
:
13944 max_br_offset
= 1 << 15;
13945 /* Fall through. */
13947 case R_PPC64_REL24
:
13948 case R_PPC64_REL24_NOTOC
:
13949 case R_PPC64_PLTCALL
:
13950 /* Calls to functions with a different TOC, such as calls to
13951 shared objects, need to alter the TOC pointer. This is
13952 done using a linkage stub. A REL24 branching to these
13953 linkage stubs needs to be followed by a nop, as the nop
13954 will be replaced with an instruction to restore the TOC
13959 && h
->oh
->is_func_descriptor
)
13960 fdh
= ppc_follow_link (h
->oh
);
13961 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
13963 if (r_type
== R_PPC64_PLTCALL
13964 && stub_entry
!= NULL
13965 && stub_entry
->stub_type
>= ppc_stub_plt_call
13966 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
13969 if (stub_entry
!= NULL
13970 && ((stub_entry
->stub_type
>= ppc_stub_plt_call
13971 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
13972 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
13973 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
13974 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
13975 || stub_entry
->stub_type
== ppc_stub_long_branch_both
))
13977 bfd_boolean can_plt_call
= FALSE
;
13979 if (stub_entry
->stub_type
== ppc_stub_plt_call
13981 && htab
->params
->plt_localentry0
!= 0
13982 && is_elfv2_localentry0 (&h
->elf
))
13984 /* The function doesn't use or change r2. */
13985 can_plt_call
= TRUE
;
13987 else if (r_type
== R_PPC64_REL24_NOTOC
)
13989 /* NOTOC calls don't need to restore r2. */
13990 can_plt_call
= TRUE
;
13993 /* All of these stubs may modify r2, so there must be a
13994 branch and link followed by a nop. The nop is
13995 replaced by an insn to restore r2. */
13996 else if (rel
->r_offset
+ 8 <= input_section
->size
)
14000 br
= bfd_get_32 (input_bfd
,
14001 contents
+ rel
->r_offset
);
14006 nop
= bfd_get_32 (input_bfd
,
14007 contents
+ rel
->r_offset
+ 4);
14008 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
14009 can_plt_call
= TRUE
;
14010 else if (nop
== NOP
14011 || nop
== CROR_151515
14012 || nop
== CROR_313131
)
14015 && (h
== htab
->tls_get_addr_fd
14016 || h
== htab
->tls_get_addr
)
14017 && htab
->params
->tls_get_addr_opt
)
14019 /* Special stub used, leave nop alone. */
14022 bfd_put_32 (input_bfd
,
14023 LD_R2_0R1
+ STK_TOC (htab
),
14024 contents
+ rel
->r_offset
+ 4);
14025 can_plt_call
= TRUE
;
14030 if (!can_plt_call
&& h
!= NULL
)
14032 const char *name
= h
->elf
.root
.root
.string
;
14037 if (strncmp (name
, "__libc_start_main", 17) == 0
14038 && (name
[17] == 0 || name
[17] == '@'))
14040 /* Allow crt1 branch to go via a toc adjusting
14041 stub. Other calls that never return could do
14042 the same, if we could detect such. */
14043 can_plt_call
= TRUE
;
14049 /* g++ as of 20130507 emits self-calls without a
14050 following nop. This is arguably wrong since we
14051 have conflicting information. On the one hand a
14052 global symbol and on the other a local call
14053 sequence, but don't error for this special case.
14054 It isn't possible to cheaply verify we have
14055 exactly such a call. Allow all calls to the same
14057 asection
*code_sec
= sec
;
14059 if (get_opd_info (sec
) != NULL
)
14061 bfd_vma off
= (relocation
+ addend
14062 - sec
->output_section
->vma
14063 - sec
->output_offset
);
14065 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14067 if (code_sec
== input_section
)
14068 can_plt_call
= TRUE
;
14073 if (stub_entry
->stub_type
>= ppc_stub_plt_call
14074 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14075 info
->callbacks
->einfo
14076 /* xgettext:c-format */
14077 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14078 "(plt call stub)\n"),
14079 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14081 info
->callbacks
->einfo
14082 /* xgettext:c-format */
14083 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14084 "(toc save/adjust stub)\n"),
14085 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14087 bfd_set_error (bfd_error_bad_value
);
14092 && stub_entry
->stub_type
>= ppc_stub_plt_call
14093 && stub_entry
->stub_type
<= ppc_stub_plt_call_both
)
14094 unresolved_reloc
= FALSE
;
14097 if ((stub_entry
== NULL
14098 || stub_entry
->stub_type
== ppc_stub_long_branch
14099 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14100 && get_opd_info (sec
) != NULL
)
14102 /* The branch destination is the value of the opd entry. */
14103 bfd_vma off
= (relocation
+ addend
14104 - sec
->output_section
->vma
14105 - sec
->output_offset
);
14106 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14107 if (dest
!= (bfd_vma
) -1)
14111 reloc_dest
= DEST_OPD
;
14115 /* If the branch is out of reach we ought to have a long
14117 from
= (rel
->r_offset
14118 + input_section
->output_offset
14119 + input_section
->output_section
->vma
);
14121 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14125 if (stub_entry
!= NULL
14126 && (stub_entry
->stub_type
== ppc_stub_long_branch
14127 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14128 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14129 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14130 || (relocation
+ addend
- from
+ max_br_offset
14131 < 2 * max_br_offset
)))
14132 /* Don't use the stub if this branch is in range. */
14135 if (stub_entry
!= NULL
14136 && (stub_entry
->stub_type
== ppc_stub_long_branch_notoc
14137 || stub_entry
->stub_type
== ppc_stub_long_branch_both
14138 || stub_entry
->stub_type
== ppc_stub_plt_branch_notoc
14139 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
14140 && (r_type
!= R_PPC64_REL24_NOTOC
14141 || ((fdh
? fdh
->elf
.other
: sym
->st_other
)
14142 & STO_PPC64_LOCAL_MASK
) == 1 << STO_PPC64_LOCAL_BIT
)
14143 && (relocation
+ addend
- from
+ max_br_offset
14144 < 2 * max_br_offset
))
14147 if (stub_entry
!= NULL
14148 && (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
14149 || stub_entry
->stub_type
== ppc_stub_long_branch_both
14150 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14151 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
)
14152 && r_type
== R_PPC64_REL24_NOTOC
14153 && (relocation
+ addend
- from
+ max_br_offset
14154 < 2 * max_br_offset
))
14157 if (stub_entry
!= NULL
)
14159 /* Munge up the value and addend so that we call the stub
14160 rather than the procedure directly. */
14161 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14163 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14164 relocation
+= (stub_sec
->output_offset
14165 + stub_sec
->output_section
->vma
14166 + stub_sec
->size
- htab
->sfpr
->size
14167 - htab
->sfpr
->output_offset
14168 - htab
->sfpr
->output_section
->vma
);
14170 relocation
= (stub_entry
->stub_offset
14171 + stub_sec
->output_offset
14172 + stub_sec
->output_section
->vma
);
14174 reloc_dest
= DEST_STUB
;
14176 if (((stub_entry
->stub_type
== ppc_stub_plt_call
14177 && ALWAYS_EMIT_R2SAVE
)
14178 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14179 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
14181 && (h
== htab
->tls_get_addr_fd
14182 || h
== htab
->tls_get_addr
)
14183 && htab
->params
->tls_get_addr_opt
)
14184 && rel
+ 1 < relend
14185 && rel
[1].r_offset
== rel
->r_offset
+ 4
14186 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14188 else if ((stub_entry
->stub_type
== ppc_stub_long_branch_both
14189 || stub_entry
->stub_type
== ppc_stub_plt_branch_both
14190 || stub_entry
->stub_type
== ppc_stub_plt_call_both
)
14191 && r_type
== R_PPC64_REL24_NOTOC
)
14199 /* Set 'a' bit. This is 0b00010 in BO field for branch
14200 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14201 for branch on CTR insns (BO == 1a00t or 1a01t). */
14202 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14203 insn
|= 0x02 << 21;
14204 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14205 insn
|= 0x08 << 21;
14211 /* Invert 'y' bit if not the default. */
14212 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14213 insn
^= 0x01 << 21;
14216 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14219 /* NOP out calls to undefined weak functions.
14220 We can thus call a weak function without first
14221 checking whether the function is defined. */
14223 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14224 && h
->elf
.dynindx
== -1
14225 && (r_type
== R_PPC64_REL24
14226 || r_type
== R_PPC64_REL24_NOTOC
)
14230 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14236 /* Set `addend'. */
14238 save_unresolved_reloc
= unresolved_reloc
;
14242 /* xgettext:c-format */
14243 _bfd_error_handler (_("%pB: %s unsupported"),
14244 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
14246 bfd_set_error (bfd_error_bad_value
);
14252 case R_PPC64_TLSGD
:
14253 case R_PPC64_TLSLD
:
14254 case R_PPC64_TOCSAVE
:
14255 case R_PPC64_GNU_VTINHERIT
:
14256 case R_PPC64_GNU_VTENTRY
:
14257 case R_PPC64_ENTRY
:
14260 /* GOT16 relocations. Like an ADDR16 using the symbol's
14261 address in the GOT as relocation value instead of the
14262 symbol's value itself. Also, create a GOT entry for the
14263 symbol and put the symbol value there. */
14264 case R_PPC64_GOT_TLSGD16
:
14265 case R_PPC64_GOT_TLSGD16_LO
:
14266 case R_PPC64_GOT_TLSGD16_HI
:
14267 case R_PPC64_GOT_TLSGD16_HA
:
14268 tls_type
= TLS_TLS
| TLS_GD
;
14271 case R_PPC64_GOT_TLSLD16
:
14272 case R_PPC64_GOT_TLSLD16_LO
:
14273 case R_PPC64_GOT_TLSLD16_HI
:
14274 case R_PPC64_GOT_TLSLD16_HA
:
14275 tls_type
= TLS_TLS
| TLS_LD
;
14278 case R_PPC64_GOT_TPREL16_DS
:
14279 case R_PPC64_GOT_TPREL16_LO_DS
:
14280 case R_PPC64_GOT_TPREL16_HI
:
14281 case R_PPC64_GOT_TPREL16_HA
:
14282 tls_type
= TLS_TLS
| TLS_TPREL
;
14285 case R_PPC64_GOT_DTPREL16_DS
:
14286 case R_PPC64_GOT_DTPREL16_LO_DS
:
14287 case R_PPC64_GOT_DTPREL16_HI
:
14288 case R_PPC64_GOT_DTPREL16_HA
:
14289 tls_type
= TLS_TLS
| TLS_DTPREL
;
14292 case R_PPC64_GOT16
:
14293 case R_PPC64_GOT16_LO
:
14294 case R_PPC64_GOT16_HI
:
14295 case R_PPC64_GOT16_HA
:
14296 case R_PPC64_GOT16_DS
:
14297 case R_PPC64_GOT16_LO_DS
:
14300 /* Relocation is to the entry for this symbol in the global
14305 unsigned long indx
= 0;
14306 struct got_entry
*ent
;
14308 if (tls_type
== (TLS_TLS
| TLS_LD
)
14310 || !h
->elf
.def_dynamic
))
14311 ent
= ppc64_tlsld_got (input_bfd
);
14316 if (!htab
->elf
.dynamic_sections_created
14317 || h
->elf
.dynindx
== -1
14318 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14319 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
14320 /* This is actually a static link, or it is a
14321 -Bsymbolic link and the symbol is defined
14322 locally, or the symbol was forced to be local
14323 because of a version file. */
14327 indx
= h
->elf
.dynindx
;
14328 unresolved_reloc
= FALSE
;
14330 ent
= h
->elf
.got
.glist
;
14334 if (local_got_ents
== NULL
)
14336 ent
= local_got_ents
[r_symndx
];
14339 for (; ent
!= NULL
; ent
= ent
->next
)
14340 if (ent
->addend
== orig_rel
.r_addend
14341 && ent
->owner
== input_bfd
14342 && ent
->tls_type
== tls_type
)
14348 if (ent
->is_indirect
)
14349 ent
= ent
->got
.ent
;
14350 offp
= &ent
->got
.offset
;
14351 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14355 /* The offset must always be a multiple of 8. We use the
14356 least significant bit to record whether we have already
14357 processed this entry. */
14359 if ((off
& 1) != 0)
14363 /* Generate relocs for the dynamic linker, except in
14364 the case of TLSLD where we'll use one entry per
14372 ? h
->elf
.type
== STT_GNU_IFUNC
14373 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14376 relgot
= htab
->elf
.irelplt
;
14378 htab
->local_ifunc_resolver
= 1;
14379 else if (is_static_defined (&h
->elf
))
14380 htab
->maybe_local_ifunc_resolver
= 1;
14383 || (bfd_link_pic (info
)
14385 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
)
14386 || (tls_type
== (TLS_TLS
| TLS_LD
)
14387 && !h
->elf
.def_dynamic
))
14388 && !(tls_type
== (TLS_TLS
| TLS_TPREL
)
14389 && bfd_link_executable (info
)
14390 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
14391 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14392 if (relgot
!= NULL
)
14394 outrel
.r_offset
= (got
->output_section
->vma
14395 + got
->output_offset
14397 outrel
.r_addend
= addend
;
14398 if (tls_type
& (TLS_LD
| TLS_GD
))
14400 outrel
.r_addend
= 0;
14401 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14402 if (tls_type
== (TLS_TLS
| TLS_GD
))
14404 loc
= relgot
->contents
;
14405 loc
+= (relgot
->reloc_count
++
14406 * sizeof (Elf64_External_Rela
));
14407 bfd_elf64_swap_reloca_out (output_bfd
,
14409 outrel
.r_offset
+= 8;
14410 outrel
.r_addend
= addend
;
14412 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14415 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14416 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14417 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14418 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14419 else if (indx
!= 0)
14420 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14424 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14426 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14428 /* Write the .got section contents for the sake
14430 loc
= got
->contents
+ off
;
14431 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14435 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14437 outrel
.r_addend
+= relocation
;
14438 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14440 if (htab
->elf
.tls_sec
== NULL
)
14441 outrel
.r_addend
= 0;
14443 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14446 loc
= relgot
->contents
;
14447 loc
+= (relgot
->reloc_count
++
14448 * sizeof (Elf64_External_Rela
));
14449 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14452 /* Init the .got section contents here if we're not
14453 emitting a reloc. */
14456 relocation
+= addend
;
14459 if (htab
->elf
.tls_sec
== NULL
)
14463 if (tls_type
& TLS_LD
)
14466 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14467 if (tls_type
& TLS_TPREL
)
14468 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14471 if (tls_type
& (TLS_GD
| TLS_LD
))
14473 bfd_put_64 (output_bfd
, relocation
,
14474 got
->contents
+ off
+ 8);
14478 bfd_put_64 (output_bfd
, relocation
,
14479 got
->contents
+ off
);
14483 if (off
>= (bfd_vma
) -2)
14486 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
14487 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
14491 case R_PPC64_PLT16_HA
:
14492 case R_PPC64_PLT16_HI
:
14493 case R_PPC64_PLT16_LO
:
14494 case R_PPC64_PLT16_LO_DS
:
14495 case R_PPC64_PLT32
:
14496 case R_PPC64_PLT64
:
14497 case R_PPC64_PLTSEQ
:
14498 case R_PPC64_PLTCALL
:
14499 /* Relocation is to the entry for this symbol in the
14500 procedure linkage table. */
14501 unresolved_reloc
= TRUE
;
14503 struct plt_entry
**plt_list
= NULL
;
14505 plt_list
= &h
->elf
.plt
.plist
;
14506 else if (local_got_ents
!= NULL
)
14508 struct plt_entry
**local_plt
= (struct plt_entry
**)
14509 (local_got_ents
+ symtab_hdr
->sh_info
);
14510 plt_list
= local_plt
+ r_symndx
;
14514 struct plt_entry
*ent
;
14516 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
14517 if (ent
->plt
.offset
!= (bfd_vma
) -1
14518 && ent
->addend
== orig_rel
.r_addend
)
14523 plt
= htab
->elf
.splt
;
14524 if (!htab
->elf
.dynamic_sections_created
14526 || h
->elf
.dynindx
== -1)
14529 ? h
->elf
.type
== STT_GNU_IFUNC
14530 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14531 plt
= htab
->elf
.iplt
;
14533 plt
= htab
->pltlocal
;
14535 relocation
= (plt
->output_section
->vma
14536 + plt
->output_offset
14537 + ent
->plt
.offset
);
14538 if (r_type
== R_PPC64_PLT16_HA
14539 || r_type
== R_PPC64_PLT16_HI
14540 || r_type
== R_PPC64_PLT16_LO
14541 || r_type
== R_PPC64_PLT16_LO_DS
)
14543 got
= (elf_gp (output_bfd
)
14544 + htab
->sec_info
[input_section
->id
].toc_off
);
14548 unresolved_reloc
= FALSE
;
14556 /* Relocation value is TOC base. */
14557 relocation
= TOCstart
;
14558 if (r_symndx
== STN_UNDEF
)
14559 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
14560 else if (unresolved_reloc
)
14562 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
14563 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
14565 unresolved_reloc
= TRUE
;
14568 /* TOC16 relocs. We want the offset relative to the TOC base,
14569 which is the address of the start of the TOC plus 0x8000.
14570 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14572 case R_PPC64_TOC16
:
14573 case R_PPC64_TOC16_LO
:
14574 case R_PPC64_TOC16_HI
:
14575 case R_PPC64_TOC16_DS
:
14576 case R_PPC64_TOC16_LO_DS
:
14577 case R_PPC64_TOC16_HA
:
14578 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14581 /* Relocate against the beginning of the section. */
14582 case R_PPC64_SECTOFF
:
14583 case R_PPC64_SECTOFF_LO
:
14584 case R_PPC64_SECTOFF_HI
:
14585 case R_PPC64_SECTOFF_DS
:
14586 case R_PPC64_SECTOFF_LO_DS
:
14587 case R_PPC64_SECTOFF_HA
:
14589 addend
-= sec
->output_section
->vma
;
14592 case R_PPC64_REL16
:
14593 case R_PPC64_REL16_LO
:
14594 case R_PPC64_REL16_HI
:
14595 case R_PPC64_REL16_HA
:
14596 case R_PPC64_REL16_HIGH
:
14597 case R_PPC64_REL16_HIGHA
:
14598 case R_PPC64_REL16_HIGHER
:
14599 case R_PPC64_REL16_HIGHERA
:
14600 case R_PPC64_REL16_HIGHEST
:
14601 case R_PPC64_REL16_HIGHESTA
:
14602 case R_PPC64_REL16DX_HA
:
14605 case R_PPC64_REL14
:
14606 case R_PPC64_REL14_BRNTAKEN
:
14607 case R_PPC64_REL14_BRTAKEN
:
14608 case R_PPC64_REL24
:
14609 case R_PPC64_REL24_NOTOC
:
14612 case R_PPC64_TPREL16
:
14613 case R_PPC64_TPREL16_LO
:
14614 case R_PPC64_TPREL16_HI
:
14615 case R_PPC64_TPREL16_HA
:
14616 case R_PPC64_TPREL16_DS
:
14617 case R_PPC64_TPREL16_LO_DS
:
14618 case R_PPC64_TPREL16_HIGH
:
14619 case R_PPC64_TPREL16_HIGHA
:
14620 case R_PPC64_TPREL16_HIGHER
:
14621 case R_PPC64_TPREL16_HIGHERA
:
14622 case R_PPC64_TPREL16_HIGHEST
:
14623 case R_PPC64_TPREL16_HIGHESTA
:
14625 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14626 && h
->elf
.dynindx
== -1)
14628 /* Make this relocation against an undefined weak symbol
14629 resolve to zero. This is really just a tweak, since
14630 code using weak externs ought to check that they are
14631 defined before using them. */
14632 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
14634 insn
= bfd_get_32 (input_bfd
, p
);
14635 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
14637 bfd_put_32 (input_bfd
, insn
, p
);
14640 if (htab
->elf
.tls_sec
!= NULL
)
14641 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14642 /* The TPREL16 relocs shouldn't really be used in shared
14643 libs or with non-local symbols as that will result in
14644 DT_TEXTREL being set, but support them anyway. */
14647 case R_PPC64_DTPREL16
:
14648 case R_PPC64_DTPREL16_LO
:
14649 case R_PPC64_DTPREL16_HI
:
14650 case R_PPC64_DTPREL16_HA
:
14651 case R_PPC64_DTPREL16_DS
:
14652 case R_PPC64_DTPREL16_LO_DS
:
14653 case R_PPC64_DTPREL16_HIGH
:
14654 case R_PPC64_DTPREL16_HIGHA
:
14655 case R_PPC64_DTPREL16_HIGHER
:
14656 case R_PPC64_DTPREL16_HIGHERA
:
14657 case R_PPC64_DTPREL16_HIGHEST
:
14658 case R_PPC64_DTPREL16_HIGHESTA
:
14659 if (htab
->elf
.tls_sec
!= NULL
)
14660 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14663 case R_PPC64_ADDR64_LOCAL
:
14664 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
14669 case R_PPC64_DTPMOD64
:
14674 case R_PPC64_TPREL64
:
14675 if (htab
->elf
.tls_sec
!= NULL
)
14676 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14679 case R_PPC64_DTPREL64
:
14680 if (htab
->elf
.tls_sec
!= NULL
)
14681 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14682 /* Fall through. */
14684 /* Relocations that may need to be propagated if this is a
14686 case R_PPC64_REL30
:
14687 case R_PPC64_REL32
:
14688 case R_PPC64_REL64
:
14689 case R_PPC64_ADDR14
:
14690 case R_PPC64_ADDR14_BRNTAKEN
:
14691 case R_PPC64_ADDR14_BRTAKEN
:
14692 case R_PPC64_ADDR16
:
14693 case R_PPC64_ADDR16_DS
:
14694 case R_PPC64_ADDR16_HA
:
14695 case R_PPC64_ADDR16_HI
:
14696 case R_PPC64_ADDR16_HIGH
:
14697 case R_PPC64_ADDR16_HIGHA
:
14698 case R_PPC64_ADDR16_HIGHER
:
14699 case R_PPC64_ADDR16_HIGHERA
:
14700 case R_PPC64_ADDR16_HIGHEST
:
14701 case R_PPC64_ADDR16_HIGHESTA
:
14702 case R_PPC64_ADDR16_LO
:
14703 case R_PPC64_ADDR16_LO_DS
:
14704 case R_PPC64_ADDR24
:
14705 case R_PPC64_ADDR32
:
14706 case R_PPC64_ADDR64
:
14707 case R_PPC64_UADDR16
:
14708 case R_PPC64_UADDR32
:
14709 case R_PPC64_UADDR64
:
14711 if ((input_section
->flags
& SEC_ALLOC
) == 0)
14714 if (NO_OPD_RELOCS
&& is_opd
)
14717 if (bfd_link_pic (info
)
14719 || h
->dyn_relocs
!= NULL
)
14720 && ((h
!= NULL
&& pc_dynrelocs (h
))
14721 || must_be_dyn_reloc (info
, r_type
)))
14723 ? h
->dyn_relocs
!= NULL
14724 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14726 bfd_boolean skip
, relocate
;
14731 /* When generating a dynamic object, these relocations
14732 are copied into the output file to be resolved at run
14738 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
14739 input_section
, rel
->r_offset
);
14740 if (out_off
== (bfd_vma
) -1)
14742 else if (out_off
== (bfd_vma
) -2)
14743 skip
= TRUE
, relocate
= TRUE
;
14744 out_off
+= (input_section
->output_section
->vma
14745 + input_section
->output_offset
);
14746 outrel
.r_offset
= out_off
;
14747 outrel
.r_addend
= rel
->r_addend
;
14749 /* Optimize unaligned reloc use. */
14750 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
14751 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
14752 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
14753 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
14754 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
14755 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
14756 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
14757 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
14758 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
14761 memset (&outrel
, 0, sizeof outrel
);
14762 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14764 && r_type
!= R_PPC64_TOC
)
14766 indx
= h
->elf
.dynindx
;
14767 BFD_ASSERT (indx
!= -1);
14768 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14772 /* This symbol is local, or marked to become local,
14773 or this is an opd section reloc which must point
14774 at a local function. */
14775 outrel
.r_addend
+= relocation
;
14776 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
14778 if (is_opd
&& h
!= NULL
)
14780 /* Lie about opd entries. This case occurs
14781 when building shared libraries and we
14782 reference a function in another shared
14783 lib. The same thing happens for a weak
14784 definition in an application that's
14785 overridden by a strong definition in a
14786 shared lib. (I believe this is a generic
14787 bug in binutils handling of weak syms.)
14788 In these cases we won't use the opd
14789 entry in this lib. */
14790 unresolved_reloc
= FALSE
;
14793 && r_type
== R_PPC64_ADDR64
14795 ? h
->elf
.type
== STT_GNU_IFUNC
14796 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14797 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14800 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14802 /* We need to relocate .opd contents for ld.so.
14803 Prelink also wants simple and consistent rules
14804 for relocs. This make all RELATIVE relocs have
14805 *r_offset equal to r_addend. */
14812 ? h
->elf
.type
== STT_GNU_IFUNC
14813 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14815 info
->callbacks
->einfo
14816 /* xgettext:c-format */
14817 (_("%H: %s for indirect "
14818 "function `%pT' unsupported\n"),
14819 input_bfd
, input_section
, rel
->r_offset
,
14820 ppc64_elf_howto_table
[r_type
]->name
,
14824 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
14826 else if (sec
== NULL
|| sec
->owner
== NULL
)
14828 bfd_set_error (bfd_error_bad_value
);
14835 osec
= sec
->output_section
;
14836 indx
= elf_section_data (osec
)->dynindx
;
14840 if ((osec
->flags
& SEC_READONLY
) == 0
14841 && htab
->elf
.data_index_section
!= NULL
)
14842 osec
= htab
->elf
.data_index_section
;
14844 osec
= htab
->elf
.text_index_section
;
14845 indx
= elf_section_data (osec
)->dynindx
;
14847 BFD_ASSERT (indx
!= 0);
14849 /* We are turning this relocation into one
14850 against a section symbol, so subtract out
14851 the output section's address but not the
14852 offset of the input section in the output
14854 outrel
.r_addend
-= osec
->vma
;
14857 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14861 sreloc
= elf_section_data (input_section
)->sreloc
;
14863 ? h
->elf
.type
== STT_GNU_IFUNC
14864 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14866 sreloc
= htab
->elf
.irelplt
;
14868 htab
->local_ifunc_resolver
= 1;
14869 else if (is_static_defined (&h
->elf
))
14870 htab
->maybe_local_ifunc_resolver
= 1;
14872 if (sreloc
== NULL
)
14875 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
14878 loc
= sreloc
->contents
;
14879 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
14880 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14882 /* If this reloc is against an external symbol, it will
14883 be computed at runtime, so there's no need to do
14884 anything now. However, for the sake of prelink ensure
14885 that the section contents are a known value. */
14888 unresolved_reloc
= FALSE
;
14889 /* The value chosen here is quite arbitrary as ld.so
14890 ignores section contents except for the special
14891 case of .opd where the contents might be accessed
14892 before relocation. Choose zero, as that won't
14893 cause reloc overflow. */
14896 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
14897 to improve backward compatibility with older
14899 if (r_type
== R_PPC64_ADDR64
)
14900 addend
= outrel
.r_addend
;
14901 /* Adjust pc_relative relocs to have zero in *r_offset. */
14902 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
14903 addend
= outrel
.r_offset
;
14909 case R_PPC64_GLOB_DAT
:
14910 case R_PPC64_JMP_SLOT
:
14911 case R_PPC64_JMP_IREL
:
14912 case R_PPC64_RELATIVE
:
14913 /* We shouldn't ever see these dynamic relocs in relocatable
14915 /* Fall through. */
14917 case R_PPC64_PLTGOT16
:
14918 case R_PPC64_PLTGOT16_DS
:
14919 case R_PPC64_PLTGOT16_HA
:
14920 case R_PPC64_PLTGOT16_HI
:
14921 case R_PPC64_PLTGOT16_LO
:
14922 case R_PPC64_PLTGOT16_LO_DS
:
14923 case R_PPC64_PLTREL32
:
14924 case R_PPC64_PLTREL64
:
14925 /* These ones haven't been implemented yet. */
14927 info
->callbacks
->einfo
14928 /* xgettext:c-format */
14929 (_("%P: %pB: %s is not supported for `%pT'\n"),
14931 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
14933 bfd_set_error (bfd_error_invalid_operation
);
14938 /* Multi-instruction sequences that access the TOC can be
14939 optimized, eg. addis ra,r2,0; addi rb,ra,x;
14940 to nop; addi rb,r2,x; */
14946 case R_PPC64_GOT_TLSLD16_HI
:
14947 case R_PPC64_GOT_TLSGD16_HI
:
14948 case R_PPC64_GOT_TPREL16_HI
:
14949 case R_PPC64_GOT_DTPREL16_HI
:
14950 case R_PPC64_GOT16_HI
:
14951 case R_PPC64_TOC16_HI
:
14952 /* These relocs would only be useful if building up an
14953 offset to later add to r2, perhaps in an indexed
14954 addressing mode instruction. Don't try to optimize.
14955 Unfortunately, the possibility of someone building up an
14956 offset like this or even with the HA relocs, means that
14957 we need to check the high insn when optimizing the low
14961 case R_PPC64_PLTCALL
:
14962 if (unresolved_reloc
)
14964 /* No plt entry. Make this into a direct call. */
14965 bfd_byte
*p
= contents
+ rel
->r_offset
;
14966 insn
= bfd_get_32 (input_bfd
, p
);
14968 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
14969 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
14970 unresolved_reloc
= save_unresolved_reloc
;
14971 r_type
= R_PPC64_REL24
;
14975 case R_PPC64_PLTSEQ
:
14976 if (unresolved_reloc
)
14978 unresolved_reloc
= FALSE
;
14983 case R_PPC64_PLT16_HA
:
14984 if (unresolved_reloc
)
14986 unresolved_reloc
= FALSE
;
14989 /* Fall through. */
14990 case R_PPC64_GOT_TLSLD16_HA
:
14991 case R_PPC64_GOT_TLSGD16_HA
:
14992 case R_PPC64_GOT_TPREL16_HA
:
14993 case R_PPC64_GOT_DTPREL16_HA
:
14994 case R_PPC64_GOT16_HA
:
14995 case R_PPC64_TOC16_HA
:
14996 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
14997 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15001 p
= contents
+ (rel
->r_offset
& ~3);
15002 bfd_put_32 (input_bfd
, NOP
, p
);
15007 case R_PPC64_PLT16_LO
:
15008 case R_PPC64_PLT16_LO_DS
:
15009 if (unresolved_reloc
)
15011 unresolved_reloc
= FALSE
;
15014 /* Fall through. */
15015 case R_PPC64_GOT_TLSLD16_LO
:
15016 case R_PPC64_GOT_TLSGD16_LO
:
15017 case R_PPC64_GOT_TPREL16_LO_DS
:
15018 case R_PPC64_GOT_DTPREL16_LO_DS
:
15019 case R_PPC64_GOT16_LO
:
15020 case R_PPC64_GOT16_LO_DS
:
15021 case R_PPC64_TOC16_LO
:
15022 case R_PPC64_TOC16_LO_DS
:
15023 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15024 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15026 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15027 insn
= bfd_get_32 (input_bfd
, p
);
15028 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
15030 /* Transform addic to addi when we change reg. */
15031 insn
&= ~((0x3f << 26) | (0x1f << 16));
15032 insn
|= (14u << 26) | (2 << 16);
15036 insn
&= ~(0x1f << 16);
15039 bfd_put_32 (input_bfd
, insn
, p
);
15043 case R_PPC64_TPREL16_HA
:
15044 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15046 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15047 insn
= bfd_get_32 (input_bfd
, p
);
15048 if ((insn
& ((0x3f << 26) | 0x1f << 16))
15049 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15050 /* xgettext:c-format */
15051 info
->callbacks
->minfo
15052 (_("%H: warning: %s unexpected insn %#x.\n"),
15053 input_bfd
, input_section
, rel
->r_offset
,
15054 ppc64_elf_howto_table
[r_type
]->name
, insn
);
15057 bfd_put_32 (input_bfd
, NOP
, p
);
15063 case R_PPC64_TPREL16_LO
:
15064 case R_PPC64_TPREL16_LO_DS
:
15065 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15067 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15068 insn
= bfd_get_32 (input_bfd
, p
);
15069 insn
&= ~(0x1f << 16);
15071 bfd_put_32 (input_bfd
, insn
, p
);
15076 /* Do any further special processing. */
15082 case R_PPC64_REL16_HA
:
15083 case R_PPC64_REL16_HIGHA
:
15084 case R_PPC64_REL16_HIGHERA
:
15085 case R_PPC64_REL16_HIGHESTA
:
15086 case R_PPC64_REL16DX_HA
:
15087 case R_PPC64_ADDR16_HA
:
15088 case R_PPC64_ADDR16_HIGHA
:
15089 case R_PPC64_ADDR16_HIGHERA
:
15090 case R_PPC64_ADDR16_HIGHESTA
:
15091 case R_PPC64_TOC16_HA
:
15092 case R_PPC64_SECTOFF_HA
:
15093 case R_PPC64_TPREL16_HA
:
15094 case R_PPC64_TPREL16_HIGHA
:
15095 case R_PPC64_TPREL16_HIGHERA
:
15096 case R_PPC64_TPREL16_HIGHESTA
:
15097 case R_PPC64_DTPREL16_HA
:
15098 case R_PPC64_DTPREL16_HIGHA
:
15099 case R_PPC64_DTPREL16_HIGHERA
:
15100 case R_PPC64_DTPREL16_HIGHESTA
:
15101 /* It's just possible that this symbol is a weak symbol
15102 that's not actually defined anywhere. In that case,
15103 'sec' would be NULL, and we should leave the symbol
15104 alone (it will be set to zero elsewhere in the link). */
15107 /* Fall through. */
15109 case R_PPC64_GOT16_HA
:
15110 case R_PPC64_PLTGOT16_HA
:
15111 case R_PPC64_PLT16_HA
:
15112 case R_PPC64_GOT_TLSGD16_HA
:
15113 case R_PPC64_GOT_TLSLD16_HA
:
15114 case R_PPC64_GOT_TPREL16_HA
:
15115 case R_PPC64_GOT_DTPREL16_HA
:
15116 /* Add 0x10000 if sign bit in 0:15 is set.
15117 Bits 0:15 are not used. */
15121 case R_PPC64_ADDR16_DS
:
15122 case R_PPC64_ADDR16_LO_DS
:
15123 case R_PPC64_GOT16_DS
:
15124 case R_PPC64_GOT16_LO_DS
:
15125 case R_PPC64_PLT16_LO_DS
:
15126 case R_PPC64_SECTOFF_DS
:
15127 case R_PPC64_SECTOFF_LO_DS
:
15128 case R_PPC64_TOC16_DS
:
15129 case R_PPC64_TOC16_LO_DS
:
15130 case R_PPC64_PLTGOT16_DS
:
15131 case R_PPC64_PLTGOT16_LO_DS
:
15132 case R_PPC64_GOT_TPREL16_DS
:
15133 case R_PPC64_GOT_TPREL16_LO_DS
:
15134 case R_PPC64_GOT_DTPREL16_DS
:
15135 case R_PPC64_GOT_DTPREL16_LO_DS
:
15136 case R_PPC64_TPREL16_DS
:
15137 case R_PPC64_TPREL16_LO_DS
:
15138 case R_PPC64_DTPREL16_DS
:
15139 case R_PPC64_DTPREL16_LO_DS
:
15140 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15142 /* If this reloc is against an lq, lxv, or stxv insn, then
15143 the value must be a multiple of 16. This is somewhat of
15144 a hack, but the "correct" way to do this by defining _DQ
15145 forms of all the _DS relocs bloats all reloc switches in
15146 this file. It doesn't make much sense to use these
15147 relocs in data, so testing the insn should be safe. */
15148 if ((insn
& (0x3f << 26)) == (56u << 26)
15149 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15151 relocation
+= addend
;
15152 addend
= insn
& (mask
^ 3);
15153 if ((relocation
& mask
) != 0)
15155 relocation
^= relocation
& mask
;
15156 info
->callbacks
->einfo
15157 /* xgettext:c-format */
15158 (_("%H: error: %s not a multiple of %u\n"),
15159 input_bfd
, input_section
, rel
->r_offset
,
15160 ppc64_elf_howto_table
[r_type
]->name
,
15162 bfd_set_error (bfd_error_bad_value
);
15169 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15170 because such sections are not SEC_ALLOC and thus ld.so will
15171 not process them. */
15172 howto
= ppc64_elf_howto_table
[(int) r_type
];
15173 if (unresolved_reloc
15174 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15175 && h
->elf
.def_dynamic
)
15176 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15177 rel
->r_offset
) != (bfd_vma
) -1)
15179 info
->callbacks
->einfo
15180 /* xgettext:c-format */
15181 (_("%H: unresolvable %s against `%pT'\n"),
15182 input_bfd
, input_section
, rel
->r_offset
,
15184 h
->elf
.root
.root
.string
);
15188 /* 16-bit fields in insns mostly have signed values, but a
15189 few insns have 16-bit unsigned values. Really, we should
15190 have different reloc types. */
15191 if (howto
->complain_on_overflow
!= complain_overflow_dont
15192 && howto
->dst_mask
== 0xffff
15193 && (input_section
->flags
& SEC_CODE
) != 0)
15195 enum complain_overflow complain
= complain_overflow_signed
;
15197 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15198 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15199 complain
= complain_overflow_bitfield
;
15200 else if (howto
->rightshift
== 0
15201 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15202 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15203 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15204 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15205 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15206 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15207 complain
= complain_overflow_unsigned
;
15208 if (howto
->complain_on_overflow
!= complain
)
15210 alt_howto
= *howto
;
15211 alt_howto
.complain_on_overflow
= complain
;
15212 howto
= &alt_howto
;
15216 if (r_type
== R_PPC64_REL16DX_HA
)
15218 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15219 if (rel
->r_offset
+ 4 > input_section
->size
)
15220 r
= bfd_reloc_outofrange
;
15223 relocation
+= addend
;
15224 relocation
-= (rel
->r_offset
15225 + input_section
->output_offset
15226 + input_section
->output_section
->vma
);
15227 relocation
= (bfd_signed_vma
) relocation
>> 16;
15228 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15230 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15231 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15233 if (relocation
+ 0x8000 > 0xffff)
15234 r
= bfd_reloc_overflow
;
15238 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15239 rel
->r_offset
, relocation
, addend
);
15241 if (r
!= bfd_reloc_ok
)
15243 char *more_info
= NULL
;
15244 const char *reloc_name
= howto
->name
;
15246 if (reloc_dest
!= DEST_NORMAL
)
15248 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15249 if (more_info
!= NULL
)
15251 strcpy (more_info
, reloc_name
);
15252 strcat (more_info
, (reloc_dest
== DEST_OPD
15253 ? " (OPD)" : " (stub)"));
15254 reloc_name
= more_info
;
15258 if (r
== bfd_reloc_overflow
)
15260 /* On code like "if (foo) foo();" don't report overflow
15261 on a branch to zero when foo is undefined. */
15263 && (reloc_dest
== DEST_STUB
15265 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15266 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15267 && is_branch_reloc (r_type
))))
15268 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15269 sym_name
, reloc_name
,
15271 input_bfd
, input_section
,
15276 info
->callbacks
->einfo
15277 /* xgettext:c-format */
15278 (_("%H: %s against `%pT': error %d\n"),
15279 input_bfd
, input_section
, rel
->r_offset
,
15280 reloc_name
, sym_name
, (int) r
);
15283 if (more_info
!= NULL
)
15293 Elf_Internal_Shdr
*rel_hdr
;
15294 size_t deleted
= rel
- wrel
;
15296 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15297 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15298 if (rel_hdr
->sh_size
== 0)
15300 /* It is too late to remove an empty reloc section. Leave
15302 ??? What is wrong with an empty section??? */
15303 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15306 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15307 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15308 input_section
->reloc_count
-= deleted
;
15311 /* If we're emitting relocations, then shortly after this function
15312 returns, reloc offsets and addends for this section will be
15313 adjusted. Worse, reloc symbol indices will be for the output
15314 file rather than the input. Save a copy of the relocs for
15315 opd_entry_value. */
15316 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15319 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15320 rel
= bfd_alloc (input_bfd
, amt
);
15321 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15322 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15325 memcpy (rel
, relocs
, amt
);
15330 /* Adjust the value of any local symbols in opd sections. */
15333 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15334 const char *name ATTRIBUTE_UNUSED
,
15335 Elf_Internal_Sym
*elfsym
,
15336 asection
*input_sec
,
15337 struct elf_link_hash_entry
*h
)
15339 struct _opd_sec_data
*opd
;
15346 opd
= get_opd_info (input_sec
);
15347 if (opd
== NULL
|| opd
->adjust
== NULL
)
15350 value
= elfsym
->st_value
- input_sec
->output_offset
;
15351 if (!bfd_link_relocatable (info
))
15352 value
-= input_sec
->output_section
->vma
;
15354 adjust
= opd
->adjust
[OPD_NDX (value
)];
15358 elfsym
->st_value
+= adjust
;
15362 /* Finish up dynamic symbol handling. We set the contents of various
15363 dynamic sections here. */
15366 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15367 struct bfd_link_info
*info
,
15368 struct elf_link_hash_entry
*h
,
15369 Elf_Internal_Sym
*sym
)
15371 struct ppc_link_hash_table
*htab
;
15372 struct plt_entry
*ent
;
15374 htab
= ppc_hash_table (info
);
15378 if (!htab
->opd_abi
&& !h
->def_regular
)
15379 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15380 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15382 /* Mark the symbol as undefined, rather than as
15383 defined in glink. Leave the value if there were
15384 any relocations where pointer equality matters
15385 (this is a clue for the dynamic linker, to make
15386 function pointer comparisons work between an
15387 application and shared library), otherwise set it
15389 sym
->st_shndx
= SHN_UNDEF
;
15390 if (!h
->pointer_equality_needed
)
15392 else if (!h
->ref_regular_nonweak
)
15394 /* This breaks function pointer comparisons, but
15395 that is better than breaking tests for a NULL
15396 function pointer. */
15404 /* This symbol needs a copy reloc. Set it up. */
15405 Elf_Internal_Rela rela
;
15409 if (h
->dynindx
== -1
15410 || (h
->root
.type
!= bfd_link_hash_defined
15411 && h
->root
.type
!= bfd_link_hash_defweak
)
15412 || htab
->elf
.srelbss
== NULL
15413 || htab
->elf
.sreldynrelro
== NULL
)
15416 rela
.r_offset
= (h
->root
.u
.def
.value
15417 + h
->root
.u
.def
.section
->output_section
->vma
15418 + h
->root
.u
.def
.section
->output_offset
);
15419 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15421 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
15422 srel
= htab
->elf
.sreldynrelro
;
15424 srel
= htab
->elf
.srelbss
;
15425 loc
= srel
->contents
;
15426 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15427 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15433 /* Used to decide how to sort relocs in an optimal manner for the
15434 dynamic linker, before writing them out. */
15436 static enum elf_reloc_type_class
15437 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15438 const asection
*rel_sec
,
15439 const Elf_Internal_Rela
*rela
)
15441 enum elf_ppc64_reloc_type r_type
;
15442 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15444 if (rel_sec
== htab
->elf
.irelplt
)
15445 return reloc_class_ifunc
;
15447 r_type
= ELF64_R_TYPE (rela
->r_info
);
15450 case R_PPC64_RELATIVE
:
15451 return reloc_class_relative
;
15452 case R_PPC64_JMP_SLOT
:
15453 return reloc_class_plt
;
15455 return reloc_class_copy
;
15457 return reloc_class_normal
;
15461 /* Finish up the dynamic sections. */
15464 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15465 struct bfd_link_info
*info
)
15467 struct ppc_link_hash_table
*htab
;
15471 htab
= ppc_hash_table (info
);
15475 dynobj
= htab
->elf
.dynobj
;
15476 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15478 if (htab
->elf
.dynamic_sections_created
)
15480 Elf64_External_Dyn
*dyncon
, *dynconend
;
15482 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15485 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15486 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15487 for (; dyncon
< dynconend
; dyncon
++)
15489 Elf_Internal_Dyn dyn
;
15492 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
15499 case DT_PPC64_GLINK
:
15501 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15502 /* We stupidly defined DT_PPC64_GLINK to be the start
15503 of glink rather than the first entry point, which is
15504 what ld.so needs, and now have a bigger stub to
15505 support automatic multiple TOCs. */
15506 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
15510 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15513 dyn
.d_un
.d_ptr
= s
->vma
;
15517 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
15518 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
15519 if (htab
->has_plt_localentry0
)
15520 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
15523 case DT_PPC64_OPDSZ
:
15524 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15527 dyn
.d_un
.d_val
= s
->size
;
15531 s
= htab
->elf
.splt
;
15532 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15536 s
= htab
->elf
.srelplt
;
15537 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15541 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
15545 if (htab
->local_ifunc_resolver
)
15546 info
->callbacks
->einfo
15547 (_("%X%P: text relocations and GNU indirect "
15548 "functions will result in a segfault at runtime\n"));
15549 else if (htab
->maybe_local_ifunc_resolver
)
15550 info
->callbacks
->einfo
15551 (_("%P: warning: text relocations and GNU indirect "
15552 "functions may result in a segfault at runtime\n"));
15556 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
15560 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
15561 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
15563 /* Fill in the first entry in the global offset table.
15564 We use it to hold the link-time TOCbase. */
15565 bfd_put_64 (output_bfd
,
15566 elf_gp (output_bfd
) + TOC_BASE_OFF
,
15567 htab
->elf
.sgot
->contents
);
15569 /* Set .got entry size. */
15570 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
15574 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
15575 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
15577 /* Set .plt entry size. */
15578 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
15579 = PLT_ENTRY_SIZE (htab
);
15582 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15583 brlt ourselves if emitrelocations. */
15584 if (htab
->brlt
!= NULL
15585 && htab
->brlt
->reloc_count
!= 0
15586 && !_bfd_elf_link_output_relocs (output_bfd
,
15588 elf_section_data (htab
->brlt
)->rela
.hdr
,
15589 elf_section_data (htab
->brlt
)->relocs
,
15593 if (htab
->glink
!= NULL
15594 && htab
->glink
->reloc_count
!= 0
15595 && !_bfd_elf_link_output_relocs (output_bfd
,
15597 elf_section_data (htab
->glink
)->rela
.hdr
,
15598 elf_section_data (htab
->glink
)->relocs
,
15603 if (htab
->glink_eh_frame
!= NULL
15604 && htab
->glink_eh_frame
->size
!= 0
15605 && htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
15606 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
15607 htab
->glink_eh_frame
,
15608 htab
->glink_eh_frame
->contents
))
15611 /* We need to handle writing out multiple GOT sections ourselves,
15612 since we didn't add them to DYNOBJ. We know dynobj is the first
15614 while ((dynobj
= dynobj
->link
.next
) != NULL
)
15618 if (!is_ppc64_elf (dynobj
))
15621 s
= ppc64_elf_tdata (dynobj
)->got
;
15624 && s
->output_section
!= bfd_abs_section_ptr
15625 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15626 s
->contents
, s
->output_offset
,
15629 s
= ppc64_elf_tdata (dynobj
)->relgot
;
15632 && s
->output_section
!= bfd_abs_section_ptr
15633 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15634 s
->contents
, s
->output_offset
,
15642 #include "elf64-target.h"
15644 /* FreeBSD support */
15646 #undef TARGET_LITTLE_SYM
15647 #undef TARGET_LITTLE_NAME
15649 #undef TARGET_BIG_SYM
15650 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
15651 #undef TARGET_BIG_NAME
15652 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
15655 #define ELF_OSABI ELFOSABI_FREEBSD
15658 #define elf64_bed elf64_powerpc_fbsd_bed
15660 #include "elf64-target.h"