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 0x10000
68 #define elf_info_to_howto ppc64_elf_info_to_howto
70 #define elf_backend_want_got_sym 0
71 #define elf_backend_want_plt_sym 0
72 #define elf_backend_plt_alignment 3
73 #define elf_backend_plt_not_loaded 1
74 #define elf_backend_got_header_size 8
75 #define elf_backend_want_dynrelro 1
76 #define elf_backend_can_gc_sections 1
77 #define elf_backend_can_refcount 1
78 #define elf_backend_rela_normal 1
79 #define elf_backend_dtrel_excludes_plt 1
80 #define elf_backend_default_execstack 0
82 #define bfd_elf64_mkobject ppc64_elf_mkobject
83 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
84 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
85 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
86 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
87 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
88 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
89 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
90 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
91 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
93 #define elf_backend_object_p ppc64_elf_object_p
94 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
95 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
96 #define elf_backend_write_core_note ppc64_elf_write_core_note
97 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
98 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
99 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
100 #define elf_backend_check_directives ppc64_elf_before_check_relocs
101 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
102 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
103 #define elf_backend_check_relocs ppc64_elf_check_relocs
104 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
105 #define elf_backend_gc_keep ppc64_elf_gc_keep
106 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
107 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
108 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
109 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
110 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
111 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
112 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
113 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
114 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
115 #define elf_backend_action_discarded ppc64_elf_action_discarded
116 #define elf_backend_relocate_section ppc64_elf_relocate_section
117 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
118 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
119 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
120 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
121 #define elf_backend_special_sections ppc64_elf_special_sections
122 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
123 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
124 #define elf_backend_get_reloc_section bfd_get_section_by_name
126 /* The name of the dynamic interpreter. This is put in the .interp
128 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
130 /* The size in bytes of an entry in the procedure linkage table. */
131 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
132 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
134 /* The initial size of the plt reserved for the dynamic linker. */
135 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
137 /* Offsets to some stack save slots. */
139 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
140 /* This one is dodgy. ELFv2 does not have a linker word, so use the
141 CR save slot. Used only by optimised __tls_get_addr call stub,
142 relying on __tls_get_addr_opt not saving CR.. */
143 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
145 /* TOC base pointers offset from start of TOC. */
146 #define TOC_BASE_OFF 0x8000
147 /* TOC base alignment. */
148 #define TOC_BASE_ALIGN 256
150 /* Offset of tp and dtp pointers from start of TLS block. */
151 #define TP_OFFSET 0x7000
152 #define DTP_OFFSET 0x8000
154 /* .plt call stub instructions. The normal stub is like this, but
155 sometimes the .plt entry crosses a 64k boundary and we need to
156 insert an addi to adjust r11. */
157 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
158 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
159 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
160 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
161 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
162 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
163 #define BCTR 0x4e800420 /* bctr */
165 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
166 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
167 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
169 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
170 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
171 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
172 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
173 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
174 #define BNECTR 0x4ca20420 /* bnectr+ */
175 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
177 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
178 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
179 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
181 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
182 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
183 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
185 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
186 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
187 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
188 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
189 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
191 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
192 #define GLINK_PLTRESOLVE_SIZE(htab) \
193 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
197 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
198 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
200 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
201 /* ld %2,(0b-1b)(%11) */
202 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
203 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
209 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
210 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
211 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
212 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
213 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
216 #define NOP 0x60000000
218 /* Some other nops. */
219 #define CROR_151515 0x4def7b82
220 #define CROR_313131 0x4ffffb82
222 /* .glink entries for the first 32k functions are two instructions. */
223 #define LI_R0_0 0x38000000 /* li %r0,0 */
224 #define B_DOT 0x48000000 /* b . */
226 /* After that, we need two instructions to load the index, followed by
228 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
229 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
231 /* Instructions used by the save and restore reg functions. */
232 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
233 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
234 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
235 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
236 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
237 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
238 #define LI_R12_0 0x39800000 /* li %r12,0 */
239 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
240 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
241 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
242 #define BLR 0x4e800020 /* blr */
244 /* Since .opd is an array of descriptors and each entry will end up
245 with identical R_PPC64_RELATIVE relocs, there is really no need to
246 propagate .opd relocs; The dynamic linker should be taught to
247 relocate .opd without reloc entries. */
248 #ifndef NO_OPD_RELOCS
249 #define NO_OPD_RELOCS 0
253 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
257 abiversion (bfd
*abfd
)
259 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
263 set_abiversion (bfd
*abfd
, int ver
)
265 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
266 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
269 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
271 /* Relocation HOWTO's. */
272 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
274 static reloc_howto_type ppc64_elf_howto_raw
[] =
276 /* This reloc does nothing. */
277 HOWTO (R_PPC64_NONE
, /* type */
279 3, /* size (0 = byte, 1 = short, 2 = long) */
281 FALSE
, /* pc_relative */
283 complain_overflow_dont
, /* complain_on_overflow */
284 bfd_elf_generic_reloc
, /* special_function */
285 "R_PPC64_NONE", /* name */
286 FALSE
, /* partial_inplace */
289 FALSE
), /* pcrel_offset */
291 /* A standard 32 bit relocation. */
292 HOWTO (R_PPC64_ADDR32
, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 FALSE
, /* pc_relative */
298 complain_overflow_bitfield
, /* complain_on_overflow */
299 bfd_elf_generic_reloc
, /* special_function */
300 "R_PPC64_ADDR32", /* name */
301 FALSE
, /* partial_inplace */
303 0xffffffff, /* dst_mask */
304 FALSE
), /* pcrel_offset */
306 /* An absolute 26 bit branch; the lower two bits must be zero.
307 FIXME: we don't check that, we just clear them. */
308 HOWTO (R_PPC64_ADDR24
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 FALSE
, /* pc_relative */
314 complain_overflow_bitfield
, /* complain_on_overflow */
315 bfd_elf_generic_reloc
, /* special_function */
316 "R_PPC64_ADDR24", /* name */
317 FALSE
, /* partial_inplace */
319 0x03fffffc, /* dst_mask */
320 FALSE
), /* pcrel_offset */
322 /* A standard 16 bit relocation. */
323 HOWTO (R_PPC64_ADDR16
, /* type */
325 1, /* size (0 = byte, 1 = short, 2 = long) */
327 FALSE
, /* pc_relative */
329 complain_overflow_bitfield
, /* complain_on_overflow */
330 bfd_elf_generic_reloc
, /* special_function */
331 "R_PPC64_ADDR16", /* name */
332 FALSE
, /* partial_inplace */
334 0xffff, /* dst_mask */
335 FALSE
), /* pcrel_offset */
337 /* A 16 bit relocation without overflow. */
338 HOWTO (R_PPC64_ADDR16_LO
, /* type */
340 1, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_dont
,/* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_PPC64_ADDR16_LO", /* name */
347 FALSE
, /* partial_inplace */
349 0xffff, /* dst_mask */
350 FALSE
), /* pcrel_offset */
352 /* Bits 16-31 of an address. */
353 HOWTO (R_PPC64_ADDR16_HI
, /* type */
355 1, /* size (0 = byte, 1 = short, 2 = long) */
357 FALSE
, /* pc_relative */
359 complain_overflow_signed
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_PPC64_ADDR16_HI", /* name */
362 FALSE
, /* partial_inplace */
364 0xffff, /* dst_mask */
365 FALSE
), /* pcrel_offset */
367 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
368 bits, treated as a signed number, is negative. */
369 HOWTO (R_PPC64_ADDR16_HA
, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE
, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 ppc64_elf_ha_reloc
, /* special_function */
377 "R_PPC64_ADDR16_HA", /* name */
378 FALSE
, /* partial_inplace */
380 0xffff, /* dst_mask */
381 FALSE
), /* pcrel_offset */
383 /* An absolute 16 bit branch; the lower two bits must be zero.
384 FIXME: we don't check that, we just clear them. */
385 HOWTO (R_PPC64_ADDR14
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE
, /* pc_relative */
391 complain_overflow_signed
, /* complain_on_overflow */
392 ppc64_elf_branch_reloc
, /* special_function */
393 "R_PPC64_ADDR14", /* name */
394 FALSE
, /* partial_inplace */
396 0x0000fffc, /* dst_mask */
397 FALSE
), /* pcrel_offset */
399 /* An absolute 16 bit branch, for which bit 10 should be set to
400 indicate that the branch is expected to be taken. The lower two
401 bits must be zero. */
402 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE
, /* pc_relative */
408 complain_overflow_signed
, /* complain_on_overflow */
409 ppc64_elf_brtaken_reloc
, /* special_function */
410 "R_PPC64_ADDR14_BRTAKEN",/* name */
411 FALSE
, /* partial_inplace */
413 0x0000fffc, /* dst_mask */
414 FALSE
), /* pcrel_offset */
416 /* An absolute 16 bit branch, for which bit 10 should be set to
417 indicate that the branch is not expected to be taken. The lower
418 two bits must be zero. */
419 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 FALSE
, /* pc_relative */
425 complain_overflow_signed
, /* complain_on_overflow */
426 ppc64_elf_brtaken_reloc
, /* special_function */
427 "R_PPC64_ADDR14_BRNTAKEN",/* name */
428 FALSE
, /* partial_inplace */
430 0x0000fffc, /* dst_mask */
431 FALSE
), /* pcrel_offset */
433 /* A relative 26 bit branch; the lower two bits must be zero. */
434 HOWTO (R_PPC64_REL24
, /* type */
436 2, /* size (0 = byte, 1 = short, 2 = long) */
438 TRUE
, /* pc_relative */
440 complain_overflow_signed
, /* complain_on_overflow */
441 ppc64_elf_branch_reloc
, /* special_function */
442 "R_PPC64_REL24", /* name */
443 FALSE
, /* partial_inplace */
445 0x03fffffc, /* dst_mask */
446 TRUE
), /* pcrel_offset */
448 /* A relative 16 bit branch; the lower two bits must be zero. */
449 HOWTO (R_PPC64_REL14
, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 TRUE
, /* pc_relative */
455 complain_overflow_signed
, /* complain_on_overflow */
456 ppc64_elf_branch_reloc
, /* special_function */
457 "R_PPC64_REL14", /* name */
458 FALSE
, /* partial_inplace */
460 0x0000fffc, /* dst_mask */
461 TRUE
), /* pcrel_offset */
463 /* A relative 16 bit branch. Bit 10 should be set to indicate that
464 the branch is expected to be taken. The lower two bits must be
466 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 TRUE
, /* pc_relative */
472 complain_overflow_signed
, /* complain_on_overflow */
473 ppc64_elf_brtaken_reloc
, /* special_function */
474 "R_PPC64_REL14_BRTAKEN", /* name */
475 FALSE
, /* partial_inplace */
477 0x0000fffc, /* dst_mask */
478 TRUE
), /* pcrel_offset */
480 /* A relative 16 bit branch. Bit 10 should be set to indicate that
481 the branch is not expected to be taken. The lower two bits must
483 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
485 2, /* size (0 = byte, 1 = short, 2 = long) */
487 TRUE
, /* pc_relative */
489 complain_overflow_signed
, /* complain_on_overflow */
490 ppc64_elf_brtaken_reloc
, /* special_function */
491 "R_PPC64_REL14_BRNTAKEN",/* name */
492 FALSE
, /* partial_inplace */
494 0x0000fffc, /* dst_mask */
495 TRUE
), /* pcrel_offset */
497 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
499 HOWTO (R_PPC64_GOT16
, /* type */
501 1, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_signed
, /* complain_on_overflow */
506 ppc64_elf_unhandled_reloc
, /* special_function */
507 "R_PPC64_GOT16", /* name */
508 FALSE
, /* partial_inplace */
510 0xffff, /* dst_mask */
511 FALSE
), /* pcrel_offset */
513 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
515 HOWTO (R_PPC64_GOT16_LO
, /* type */
517 1, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE
, /* pc_relative */
521 complain_overflow_dont
, /* complain_on_overflow */
522 ppc64_elf_unhandled_reloc
, /* special_function */
523 "R_PPC64_GOT16_LO", /* name */
524 FALSE
, /* partial_inplace */
526 0xffff, /* dst_mask */
527 FALSE
), /* pcrel_offset */
529 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
531 HOWTO (R_PPC64_GOT16_HI
, /* type */
533 1, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE
, /* pc_relative */
537 complain_overflow_signed
,/* complain_on_overflow */
538 ppc64_elf_unhandled_reloc
, /* special_function */
539 "R_PPC64_GOT16_HI", /* name */
540 FALSE
, /* partial_inplace */
542 0xffff, /* dst_mask */
543 FALSE
), /* pcrel_offset */
545 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
547 HOWTO (R_PPC64_GOT16_HA
, /* type */
549 1, /* size (0 = byte, 1 = short, 2 = long) */
551 FALSE
, /* pc_relative */
553 complain_overflow_signed
,/* complain_on_overflow */
554 ppc64_elf_unhandled_reloc
, /* special_function */
555 "R_PPC64_GOT16_HA", /* name */
556 FALSE
, /* partial_inplace */
558 0xffff, /* dst_mask */
559 FALSE
), /* pcrel_offset */
561 /* This is used only by the dynamic linker. The symbol should exist
562 both in the object being run and in some shared library. The
563 dynamic linker copies the data addressed by the symbol from the
564 shared library into the object, because the object being
565 run has to have the data at some particular address. */
566 HOWTO (R_PPC64_COPY
, /* type */
568 0, /* this one is variable size */
570 FALSE
, /* pc_relative */
572 complain_overflow_dont
, /* complain_on_overflow */
573 ppc64_elf_unhandled_reloc
, /* special_function */
574 "R_PPC64_COPY", /* name */
575 FALSE
, /* partial_inplace */
578 FALSE
), /* pcrel_offset */
580 /* Like R_PPC64_ADDR64, but used when setting global offset table
582 HOWTO (R_PPC64_GLOB_DAT
, /* type */
584 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
586 FALSE
, /* pc_relative */
588 complain_overflow_dont
, /* complain_on_overflow */
589 ppc64_elf_unhandled_reloc
, /* special_function */
590 "R_PPC64_GLOB_DAT", /* name */
591 FALSE
, /* partial_inplace */
593 ONES (64), /* dst_mask */
594 FALSE
), /* pcrel_offset */
596 /* Created by the link editor. Marks a procedure linkage table
597 entry for a symbol. */
598 HOWTO (R_PPC64_JMP_SLOT
, /* type */
600 0, /* size (0 = byte, 1 = short, 2 = long) */
602 FALSE
, /* pc_relative */
604 complain_overflow_dont
, /* complain_on_overflow */
605 ppc64_elf_unhandled_reloc
, /* special_function */
606 "R_PPC64_JMP_SLOT", /* name */
607 FALSE
, /* partial_inplace */
610 FALSE
), /* pcrel_offset */
612 /* Used only by the dynamic linker. When the object is run, this
613 doubleword64 is set to the load address of the object, plus the
615 HOWTO (R_PPC64_RELATIVE
, /* type */
617 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
619 FALSE
, /* pc_relative */
621 complain_overflow_dont
, /* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 "R_PPC64_RELATIVE", /* name */
624 FALSE
, /* partial_inplace */
626 ONES (64), /* dst_mask */
627 FALSE
), /* pcrel_offset */
629 /* Like R_PPC64_ADDR32, but may be unaligned. */
630 HOWTO (R_PPC64_UADDR32
, /* type */
632 2, /* size (0 = byte, 1 = short, 2 = long) */
634 FALSE
, /* pc_relative */
636 complain_overflow_bitfield
, /* complain_on_overflow */
637 bfd_elf_generic_reloc
, /* special_function */
638 "R_PPC64_UADDR32", /* name */
639 FALSE
, /* partial_inplace */
641 0xffffffff, /* dst_mask */
642 FALSE
), /* pcrel_offset */
644 /* Like R_PPC64_ADDR16, but may be unaligned. */
645 HOWTO (R_PPC64_UADDR16
, /* type */
647 1, /* size (0 = byte, 1 = short, 2 = long) */
649 FALSE
, /* pc_relative */
651 complain_overflow_bitfield
, /* complain_on_overflow */
652 bfd_elf_generic_reloc
, /* special_function */
653 "R_PPC64_UADDR16", /* name */
654 FALSE
, /* partial_inplace */
656 0xffff, /* dst_mask */
657 FALSE
), /* pcrel_offset */
659 /* 32-bit PC relative. */
660 HOWTO (R_PPC64_REL32
, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 TRUE
, /* pc_relative */
666 complain_overflow_signed
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_PPC64_REL32", /* name */
669 FALSE
, /* partial_inplace */
671 0xffffffff, /* dst_mask */
672 TRUE
), /* pcrel_offset */
674 /* 32-bit relocation to the symbol's procedure linkage table. */
675 HOWTO (R_PPC64_PLT32
, /* type */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
679 FALSE
, /* pc_relative */
681 complain_overflow_bitfield
, /* complain_on_overflow */
682 ppc64_elf_unhandled_reloc
, /* special_function */
683 "R_PPC64_PLT32", /* name */
684 FALSE
, /* partial_inplace */
686 0xffffffff, /* dst_mask */
687 FALSE
), /* pcrel_offset */
689 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
690 FIXME: R_PPC64_PLTREL32 not supported. */
691 HOWTO (R_PPC64_PLTREL32
, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 TRUE
, /* pc_relative */
697 complain_overflow_signed
, /* complain_on_overflow */
698 ppc64_elf_unhandled_reloc
, /* special_function */
699 "R_PPC64_PLTREL32", /* name */
700 FALSE
, /* partial_inplace */
702 0xffffffff, /* dst_mask */
703 TRUE
), /* pcrel_offset */
705 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
707 HOWTO (R_PPC64_PLT16_LO
, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE
, /* pc_relative */
713 complain_overflow_dont
, /* complain_on_overflow */
714 ppc64_elf_unhandled_reloc
, /* special_function */
715 "R_PPC64_PLT16_LO", /* name */
716 FALSE
, /* partial_inplace */
718 0xffff, /* dst_mask */
719 FALSE
), /* pcrel_offset */
721 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
723 HOWTO (R_PPC64_PLT16_HI
, /* type */
725 1, /* size (0 = byte, 1 = short, 2 = long) */
727 FALSE
, /* pc_relative */
729 complain_overflow_signed
, /* complain_on_overflow */
730 ppc64_elf_unhandled_reloc
, /* special_function */
731 "R_PPC64_PLT16_HI", /* name */
732 FALSE
, /* partial_inplace */
734 0xffff, /* dst_mask */
735 FALSE
), /* pcrel_offset */
737 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
739 HOWTO (R_PPC64_PLT16_HA
, /* type */
741 1, /* size (0 = byte, 1 = short, 2 = long) */
743 FALSE
, /* pc_relative */
745 complain_overflow_signed
, /* complain_on_overflow */
746 ppc64_elf_unhandled_reloc
, /* special_function */
747 "R_PPC64_PLT16_HA", /* name */
748 FALSE
, /* partial_inplace */
750 0xffff, /* dst_mask */
751 FALSE
), /* pcrel_offset */
753 /* 16-bit section relative relocation. */
754 HOWTO (R_PPC64_SECTOFF
, /* type */
756 1, /* size (0 = byte, 1 = short, 2 = long) */
758 FALSE
, /* pc_relative */
760 complain_overflow_signed
, /* complain_on_overflow */
761 ppc64_elf_sectoff_reloc
, /* special_function */
762 "R_PPC64_SECTOFF", /* name */
763 FALSE
, /* partial_inplace */
765 0xffff, /* dst_mask */
766 FALSE
), /* pcrel_offset */
768 /* Like R_PPC64_SECTOFF, but no overflow warning. */
769 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
771 1, /* size (0 = byte, 1 = short, 2 = long) */
773 FALSE
, /* pc_relative */
775 complain_overflow_dont
, /* complain_on_overflow */
776 ppc64_elf_sectoff_reloc
, /* special_function */
777 "R_PPC64_SECTOFF_LO", /* name */
778 FALSE
, /* partial_inplace */
780 0xffff, /* dst_mask */
781 FALSE
), /* pcrel_offset */
783 /* 16-bit upper half section relative relocation. */
784 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
788 FALSE
, /* pc_relative */
790 complain_overflow_signed
, /* complain_on_overflow */
791 ppc64_elf_sectoff_reloc
, /* special_function */
792 "R_PPC64_SECTOFF_HI", /* name */
793 FALSE
, /* partial_inplace */
795 0xffff, /* dst_mask */
796 FALSE
), /* pcrel_offset */
798 /* 16-bit upper half adjusted section relative relocation. */
799 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE
, /* pc_relative */
805 complain_overflow_signed
, /* complain_on_overflow */
806 ppc64_elf_sectoff_ha_reloc
, /* special_function */
807 "R_PPC64_SECTOFF_HA", /* name */
808 FALSE
, /* partial_inplace */
810 0xffff, /* dst_mask */
811 FALSE
), /* pcrel_offset */
813 /* Like R_PPC64_REL24 without touching the two least significant bits. */
814 HOWTO (R_PPC64_REL30
, /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 TRUE
, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_PPC64_REL30", /* name */
823 FALSE
, /* partial_inplace */
825 0xfffffffc, /* dst_mask */
826 TRUE
), /* pcrel_offset */
828 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
830 /* A standard 64-bit relocation. */
831 HOWTO (R_PPC64_ADDR64
, /* type */
833 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
835 FALSE
, /* pc_relative */
837 complain_overflow_dont
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_PPC64_ADDR64", /* name */
840 FALSE
, /* partial_inplace */
842 ONES (64), /* dst_mask */
843 FALSE
), /* pcrel_offset */
845 /* The bits 32-47 of an address. */
846 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE
, /* pc_relative */
852 complain_overflow_dont
, /* complain_on_overflow */
853 bfd_elf_generic_reloc
, /* special_function */
854 "R_PPC64_ADDR16_HIGHER", /* name */
855 FALSE
, /* partial_inplace */
857 0xffff, /* dst_mask */
858 FALSE
), /* pcrel_offset */
860 /* The bits 32-47 of an address, plus 1 if the contents of the low
861 16 bits, treated as a signed number, is negative. */
862 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
864 1, /* size (0 = byte, 1 = short, 2 = long) */
866 FALSE
, /* pc_relative */
868 complain_overflow_dont
, /* complain_on_overflow */
869 ppc64_elf_ha_reloc
, /* special_function */
870 "R_PPC64_ADDR16_HIGHERA", /* name */
871 FALSE
, /* partial_inplace */
873 0xffff, /* dst_mask */
874 FALSE
), /* pcrel_offset */
876 /* The bits 48-63 of an address. */
877 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
879 1, /* size (0 = byte, 1 = short, 2 = long) */
881 FALSE
, /* pc_relative */
883 complain_overflow_dont
, /* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 "R_PPC64_ADDR16_HIGHEST", /* name */
886 FALSE
, /* partial_inplace */
888 0xffff, /* dst_mask */
889 FALSE
), /* pcrel_offset */
891 /* The bits 48-63 of an address, plus 1 if the contents of the low
892 16 bits, treated as a signed number, is negative. */
893 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
895 1, /* size (0 = byte, 1 = short, 2 = long) */
897 FALSE
, /* pc_relative */
899 complain_overflow_dont
, /* complain_on_overflow */
900 ppc64_elf_ha_reloc
, /* special_function */
901 "R_PPC64_ADDR16_HIGHESTA", /* name */
902 FALSE
, /* partial_inplace */
904 0xffff, /* dst_mask */
905 FALSE
), /* pcrel_offset */
907 /* Like ADDR64, but may be unaligned. */
908 HOWTO (R_PPC64_UADDR64
, /* type */
910 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
912 FALSE
, /* pc_relative */
914 complain_overflow_dont
, /* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* special_function */
916 "R_PPC64_UADDR64", /* name */
917 FALSE
, /* partial_inplace */
919 ONES (64), /* dst_mask */
920 FALSE
), /* pcrel_offset */
922 /* 64-bit relative relocation. */
923 HOWTO (R_PPC64_REL64
, /* type */
925 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
927 TRUE
, /* pc_relative */
929 complain_overflow_dont
, /* complain_on_overflow */
930 bfd_elf_generic_reloc
, /* special_function */
931 "R_PPC64_REL64", /* name */
932 FALSE
, /* partial_inplace */
934 ONES (64), /* dst_mask */
935 TRUE
), /* pcrel_offset */
937 /* 64-bit relocation to the symbol's procedure linkage table. */
938 HOWTO (R_PPC64_PLT64
, /* type */
940 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
942 FALSE
, /* pc_relative */
944 complain_overflow_dont
, /* complain_on_overflow */
945 ppc64_elf_unhandled_reloc
, /* special_function */
946 "R_PPC64_PLT64", /* name */
947 FALSE
, /* partial_inplace */
949 ONES (64), /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* 64-bit PC relative relocation to the symbol's procedure linkage
954 /* FIXME: R_PPC64_PLTREL64 not supported. */
955 HOWTO (R_PPC64_PLTREL64
, /* type */
957 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
959 TRUE
, /* pc_relative */
961 complain_overflow_dont
, /* complain_on_overflow */
962 ppc64_elf_unhandled_reloc
, /* special_function */
963 "R_PPC64_PLTREL64", /* name */
964 FALSE
, /* partial_inplace */
966 ONES (64), /* dst_mask */
967 TRUE
), /* pcrel_offset */
969 /* 16 bit TOC-relative relocation. */
971 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
972 HOWTO (R_PPC64_TOC16
, /* type */
974 1, /* size (0 = byte, 1 = short, 2 = long) */
976 FALSE
, /* pc_relative */
978 complain_overflow_signed
, /* complain_on_overflow */
979 ppc64_elf_toc_reloc
, /* special_function */
980 "R_PPC64_TOC16", /* name */
981 FALSE
, /* partial_inplace */
983 0xffff, /* dst_mask */
984 FALSE
), /* pcrel_offset */
986 /* 16 bit TOC-relative relocation without overflow. */
988 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
989 HOWTO (R_PPC64_TOC16_LO
, /* type */
991 1, /* size (0 = byte, 1 = short, 2 = long) */
993 FALSE
, /* pc_relative */
995 complain_overflow_dont
, /* complain_on_overflow */
996 ppc64_elf_toc_reloc
, /* special_function */
997 "R_PPC64_TOC16_LO", /* name */
998 FALSE
, /* partial_inplace */
1000 0xffff, /* dst_mask */
1001 FALSE
), /* pcrel_offset */
1003 /* 16 bit TOC-relative relocation, high 16 bits. */
1005 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
1006 HOWTO (R_PPC64_TOC16_HI
, /* type */
1007 16, /* rightshift */
1008 1, /* size (0 = byte, 1 = short, 2 = long) */
1010 FALSE
, /* pc_relative */
1012 complain_overflow_signed
, /* complain_on_overflow */
1013 ppc64_elf_toc_reloc
, /* special_function */
1014 "R_PPC64_TOC16_HI", /* name */
1015 FALSE
, /* partial_inplace */
1017 0xffff, /* dst_mask */
1018 FALSE
), /* pcrel_offset */
1020 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1021 contents of the low 16 bits, treated as a signed number, is
1024 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1025 HOWTO (R_PPC64_TOC16_HA
, /* type */
1026 16, /* rightshift */
1027 1, /* size (0 = byte, 1 = short, 2 = long) */
1029 FALSE
, /* pc_relative */
1031 complain_overflow_signed
, /* complain_on_overflow */
1032 ppc64_elf_toc_ha_reloc
, /* special_function */
1033 "R_PPC64_TOC16_HA", /* name */
1034 FALSE
, /* partial_inplace */
1036 0xffff, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1041 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1042 HOWTO (R_PPC64_TOC
, /* type */
1044 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1046 FALSE
, /* pc_relative */
1048 complain_overflow_dont
, /* complain_on_overflow */
1049 ppc64_elf_toc64_reloc
, /* special_function */
1050 "R_PPC64_TOC", /* name */
1051 FALSE
, /* partial_inplace */
1053 ONES (64), /* dst_mask */
1054 FALSE
), /* pcrel_offset */
1056 /* Like R_PPC64_GOT16, but also informs the link editor that the
1057 value to relocate may (!) refer to a PLT entry which the link
1058 editor (a) may replace with the symbol value. If the link editor
1059 is unable to fully resolve the symbol, it may (b) create a PLT
1060 entry and store the address to the new PLT entry in the GOT.
1061 This permits lazy resolution of function symbols at run time.
1062 The link editor may also skip all of this and just (c) emit a
1063 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1064 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1065 HOWTO (R_PPC64_PLTGOT16
, /* type */
1067 1, /* size (0 = byte, 1 = short, 2 = long) */
1069 FALSE
, /* pc_relative */
1071 complain_overflow_signed
, /* complain_on_overflow */
1072 ppc64_elf_unhandled_reloc
, /* special_function */
1073 "R_PPC64_PLTGOT16", /* name */
1074 FALSE
, /* partial_inplace */
1076 0xffff, /* dst_mask */
1077 FALSE
), /* pcrel_offset */
1079 /* Like R_PPC64_PLTGOT16, but without overflow. */
1080 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1081 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1085 FALSE
, /* pc_relative */
1087 complain_overflow_dont
, /* complain_on_overflow */
1088 ppc64_elf_unhandled_reloc
, /* special_function */
1089 "R_PPC64_PLTGOT16_LO", /* name */
1090 FALSE
, /* partial_inplace */
1092 0xffff, /* dst_mask */
1093 FALSE
), /* pcrel_offset */
1095 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1096 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1097 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1098 16, /* rightshift */
1099 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 FALSE
, /* pc_relative */
1103 complain_overflow_signed
, /* complain_on_overflow */
1104 ppc64_elf_unhandled_reloc
, /* special_function */
1105 "R_PPC64_PLTGOT16_HI", /* name */
1106 FALSE
, /* partial_inplace */
1108 0xffff, /* dst_mask */
1109 FALSE
), /* pcrel_offset */
1111 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1112 1 if the contents of the low 16 bits, treated as a signed number,
1114 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1115 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1116 16, /* rightshift */
1117 1, /* size (0 = byte, 1 = short, 2 = long) */
1119 FALSE
, /* pc_relative */
1121 complain_overflow_signed
, /* complain_on_overflow */
1122 ppc64_elf_unhandled_reloc
, /* special_function */
1123 "R_PPC64_PLTGOT16_HA", /* name */
1124 FALSE
, /* partial_inplace */
1126 0xffff, /* dst_mask */
1127 FALSE
), /* pcrel_offset */
1129 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1130 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1132 1, /* size (0 = byte, 1 = short, 2 = long) */
1134 FALSE
, /* pc_relative */
1136 complain_overflow_signed
, /* complain_on_overflow */
1137 bfd_elf_generic_reloc
, /* special_function */
1138 "R_PPC64_ADDR16_DS", /* name */
1139 FALSE
, /* partial_inplace */
1141 0xfffc, /* dst_mask */
1142 FALSE
), /* pcrel_offset */
1144 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1145 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1147 1, /* size (0 = byte, 1 = short, 2 = long) */
1149 FALSE
, /* pc_relative */
1151 complain_overflow_dont
,/* complain_on_overflow */
1152 bfd_elf_generic_reloc
, /* special_function */
1153 "R_PPC64_ADDR16_LO_DS",/* name */
1154 FALSE
, /* partial_inplace */
1156 0xfffc, /* dst_mask */
1157 FALSE
), /* pcrel_offset */
1159 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1160 HOWTO (R_PPC64_GOT16_DS
, /* type */
1162 1, /* size (0 = byte, 1 = short, 2 = long) */
1164 FALSE
, /* pc_relative */
1166 complain_overflow_signed
, /* complain_on_overflow */
1167 ppc64_elf_unhandled_reloc
, /* special_function */
1168 "R_PPC64_GOT16_DS", /* name */
1169 FALSE
, /* partial_inplace */
1171 0xfffc, /* dst_mask */
1172 FALSE
), /* pcrel_offset */
1174 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1175 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1177 1, /* size (0 = byte, 1 = short, 2 = long) */
1179 FALSE
, /* pc_relative */
1181 complain_overflow_dont
, /* complain_on_overflow */
1182 ppc64_elf_unhandled_reloc
, /* special_function */
1183 "R_PPC64_GOT16_LO_DS", /* name */
1184 FALSE
, /* partial_inplace */
1186 0xfffc, /* dst_mask */
1187 FALSE
), /* pcrel_offset */
1189 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1190 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1192 1, /* size (0 = byte, 1 = short, 2 = long) */
1194 FALSE
, /* pc_relative */
1196 complain_overflow_dont
, /* complain_on_overflow */
1197 ppc64_elf_unhandled_reloc
, /* special_function */
1198 "R_PPC64_PLT16_LO_DS", /* name */
1199 FALSE
, /* partial_inplace */
1201 0xfffc, /* dst_mask */
1202 FALSE
), /* pcrel_offset */
1204 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1205 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1207 1, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE
, /* pc_relative */
1211 complain_overflow_signed
, /* complain_on_overflow */
1212 ppc64_elf_sectoff_reloc
, /* special_function */
1213 "R_PPC64_SECTOFF_DS", /* name */
1214 FALSE
, /* partial_inplace */
1216 0xfffc, /* dst_mask */
1217 FALSE
), /* pcrel_offset */
1219 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1220 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1222 1, /* size (0 = byte, 1 = short, 2 = long) */
1224 FALSE
, /* pc_relative */
1226 complain_overflow_dont
, /* complain_on_overflow */
1227 ppc64_elf_sectoff_reloc
, /* special_function */
1228 "R_PPC64_SECTOFF_LO_DS",/* name */
1229 FALSE
, /* partial_inplace */
1231 0xfffc, /* dst_mask */
1232 FALSE
), /* pcrel_offset */
1234 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1235 HOWTO (R_PPC64_TOC16_DS
, /* type */
1237 1, /* size (0 = byte, 1 = short, 2 = long) */
1239 FALSE
, /* pc_relative */
1241 complain_overflow_signed
, /* complain_on_overflow */
1242 ppc64_elf_toc_reloc
, /* special_function */
1243 "R_PPC64_TOC16_DS", /* name */
1244 FALSE
, /* partial_inplace */
1246 0xfffc, /* dst_mask */
1247 FALSE
), /* pcrel_offset */
1249 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1250 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1252 1, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE
, /* pc_relative */
1256 complain_overflow_dont
, /* complain_on_overflow */
1257 ppc64_elf_toc_reloc
, /* special_function */
1258 "R_PPC64_TOC16_LO_DS", /* name */
1259 FALSE
, /* partial_inplace */
1261 0xfffc, /* dst_mask */
1262 FALSE
), /* pcrel_offset */
1264 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1265 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1266 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1268 1, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE
, /* pc_relative */
1272 complain_overflow_signed
, /* complain_on_overflow */
1273 ppc64_elf_unhandled_reloc
, /* special_function */
1274 "R_PPC64_PLTGOT16_DS", /* name */
1275 FALSE
, /* partial_inplace */
1277 0xfffc, /* dst_mask */
1278 FALSE
), /* pcrel_offset */
1280 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1281 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1282 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1284 1, /* size (0 = byte, 1 = short, 2 = long) */
1286 FALSE
, /* pc_relative */
1288 complain_overflow_dont
, /* complain_on_overflow */
1289 ppc64_elf_unhandled_reloc
, /* special_function */
1290 "R_PPC64_PLTGOT16_LO_DS",/* name */
1291 FALSE
, /* partial_inplace */
1293 0xfffc, /* dst_mask */
1294 FALSE
), /* pcrel_offset */
1296 /* Marker relocs for TLS. */
1299 2, /* size (0 = byte, 1 = short, 2 = long) */
1301 FALSE
, /* pc_relative */
1303 complain_overflow_dont
, /* complain_on_overflow */
1304 bfd_elf_generic_reloc
, /* special_function */
1305 "R_PPC64_TLS", /* name */
1306 FALSE
, /* partial_inplace */
1309 FALSE
), /* pcrel_offset */
1311 HOWTO (R_PPC64_TLSGD
,
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1315 FALSE
, /* pc_relative */
1317 complain_overflow_dont
, /* complain_on_overflow */
1318 bfd_elf_generic_reloc
, /* special_function */
1319 "R_PPC64_TLSGD", /* name */
1320 FALSE
, /* partial_inplace */
1323 FALSE
), /* pcrel_offset */
1325 HOWTO (R_PPC64_TLSLD
,
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 FALSE
, /* pc_relative */
1331 complain_overflow_dont
, /* complain_on_overflow */
1332 bfd_elf_generic_reloc
, /* special_function */
1333 "R_PPC64_TLSLD", /* name */
1334 FALSE
, /* partial_inplace */
1337 FALSE
), /* pcrel_offset */
1339 /* Marker reloc for optimizing r2 save in prologue rather than on
1340 each plt call stub. */
1341 HOWTO (R_PPC64_TOCSAVE
,
1343 2, /* size (0 = byte, 1 = short, 2 = long) */
1345 FALSE
, /* pc_relative */
1347 complain_overflow_dont
, /* complain_on_overflow */
1348 bfd_elf_generic_reloc
, /* special_function */
1349 "R_PPC64_TOCSAVE", /* name */
1350 FALSE
, /* partial_inplace */
1353 FALSE
), /* pcrel_offset */
1355 /* Marker relocs on inline plt call instructions. */
1356 HOWTO (R_PPC64_PLTSEQ
,
1358 2, /* size (0 = byte, 1 = short, 2 = long) */
1360 FALSE
, /* pc_relative */
1362 complain_overflow_dont
, /* complain_on_overflow */
1363 bfd_elf_generic_reloc
, /* special_function */
1364 "R_PPC64_PLTSEQ", /* name */
1365 FALSE
, /* partial_inplace */
1368 FALSE
), /* pcrel_offset */
1370 HOWTO (R_PPC64_PLTCALL
,
1372 2, /* size (0 = byte, 1 = short, 2 = long) */
1374 FALSE
, /* pc_relative */
1376 complain_overflow_dont
, /* complain_on_overflow */
1377 bfd_elf_generic_reloc
, /* special_function */
1378 "R_PPC64_PLTCALL", /* name */
1379 FALSE
, /* partial_inplace */
1382 FALSE
), /* pcrel_offset */
1384 /* Computes the load module index of the load module that contains the
1385 definition of its TLS sym. */
1386 HOWTO (R_PPC64_DTPMOD64
,
1388 4, /* size (0 = byte, 1 = short, 2 = long) */
1390 FALSE
, /* pc_relative */
1392 complain_overflow_dont
, /* complain_on_overflow */
1393 ppc64_elf_unhandled_reloc
, /* special_function */
1394 "R_PPC64_DTPMOD64", /* name */
1395 FALSE
, /* partial_inplace */
1397 ONES (64), /* dst_mask */
1398 FALSE
), /* pcrel_offset */
1400 /* Computes a dtv-relative displacement, the difference between the value
1401 of sym+add and the base address of the thread-local storage block that
1402 contains the definition of sym, minus 0x8000. */
1403 HOWTO (R_PPC64_DTPREL64
,
1405 4, /* size (0 = byte, 1 = short, 2 = long) */
1407 FALSE
, /* pc_relative */
1409 complain_overflow_dont
, /* complain_on_overflow */
1410 ppc64_elf_unhandled_reloc
, /* special_function */
1411 "R_PPC64_DTPREL64", /* name */
1412 FALSE
, /* partial_inplace */
1414 ONES (64), /* dst_mask */
1415 FALSE
), /* pcrel_offset */
1417 /* A 16 bit dtprel reloc. */
1418 HOWTO (R_PPC64_DTPREL16
,
1420 1, /* size (0 = byte, 1 = short, 2 = long) */
1422 FALSE
, /* pc_relative */
1424 complain_overflow_signed
, /* complain_on_overflow */
1425 ppc64_elf_unhandled_reloc
, /* special_function */
1426 "R_PPC64_DTPREL16", /* name */
1427 FALSE
, /* partial_inplace */
1429 0xffff, /* dst_mask */
1430 FALSE
), /* pcrel_offset */
1432 /* Like DTPREL16, but no overflow. */
1433 HOWTO (R_PPC64_DTPREL16_LO
,
1435 1, /* size (0 = byte, 1 = short, 2 = long) */
1437 FALSE
, /* pc_relative */
1439 complain_overflow_dont
, /* complain_on_overflow */
1440 ppc64_elf_unhandled_reloc
, /* special_function */
1441 "R_PPC64_DTPREL16_LO", /* name */
1442 FALSE
, /* partial_inplace */
1444 0xffff, /* dst_mask */
1445 FALSE
), /* pcrel_offset */
1447 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1448 HOWTO (R_PPC64_DTPREL16_HI
,
1449 16, /* rightshift */
1450 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE
, /* pc_relative */
1454 complain_overflow_signed
, /* complain_on_overflow */
1455 ppc64_elf_unhandled_reloc
, /* special_function */
1456 "R_PPC64_DTPREL16_HI", /* name */
1457 FALSE
, /* partial_inplace */
1459 0xffff, /* dst_mask */
1460 FALSE
), /* pcrel_offset */
1462 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1463 HOWTO (R_PPC64_DTPREL16_HA
,
1464 16, /* rightshift */
1465 1, /* size (0 = byte, 1 = short, 2 = long) */
1467 FALSE
, /* pc_relative */
1469 complain_overflow_signed
, /* complain_on_overflow */
1470 ppc64_elf_unhandled_reloc
, /* special_function */
1471 "R_PPC64_DTPREL16_HA", /* name */
1472 FALSE
, /* partial_inplace */
1474 0xffff, /* dst_mask */
1475 FALSE
), /* pcrel_offset */
1477 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1478 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1479 32, /* rightshift */
1480 1, /* size (0 = byte, 1 = short, 2 = long) */
1482 FALSE
, /* pc_relative */
1484 complain_overflow_dont
, /* complain_on_overflow */
1485 ppc64_elf_unhandled_reloc
, /* special_function */
1486 "R_PPC64_DTPREL16_HIGHER", /* name */
1487 FALSE
, /* partial_inplace */
1489 0xffff, /* dst_mask */
1490 FALSE
), /* pcrel_offset */
1492 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1493 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1494 32, /* rightshift */
1495 1, /* size (0 = byte, 1 = short, 2 = long) */
1497 FALSE
, /* pc_relative */
1499 complain_overflow_dont
, /* complain_on_overflow */
1500 ppc64_elf_unhandled_reloc
, /* special_function */
1501 "R_PPC64_DTPREL16_HIGHERA", /* name */
1502 FALSE
, /* partial_inplace */
1504 0xffff, /* dst_mask */
1505 FALSE
), /* pcrel_offset */
1507 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1508 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1509 48, /* rightshift */
1510 1, /* size (0 = byte, 1 = short, 2 = long) */
1512 FALSE
, /* pc_relative */
1514 complain_overflow_dont
, /* complain_on_overflow */
1515 ppc64_elf_unhandled_reloc
, /* special_function */
1516 "R_PPC64_DTPREL16_HIGHEST", /* name */
1517 FALSE
, /* partial_inplace */
1519 0xffff, /* dst_mask */
1520 FALSE
), /* pcrel_offset */
1522 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1523 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1524 48, /* rightshift */
1525 1, /* size (0 = byte, 1 = short, 2 = long) */
1527 FALSE
, /* pc_relative */
1529 complain_overflow_dont
, /* complain_on_overflow */
1530 ppc64_elf_unhandled_reloc
, /* special_function */
1531 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1532 FALSE
, /* partial_inplace */
1534 0xffff, /* dst_mask */
1535 FALSE
), /* pcrel_offset */
1537 /* Like DTPREL16, but for insns with a DS field. */
1538 HOWTO (R_PPC64_DTPREL16_DS
,
1540 1, /* size (0 = byte, 1 = short, 2 = long) */
1542 FALSE
, /* pc_relative */
1544 complain_overflow_signed
, /* complain_on_overflow */
1545 ppc64_elf_unhandled_reloc
, /* special_function */
1546 "R_PPC64_DTPREL16_DS", /* name */
1547 FALSE
, /* partial_inplace */
1549 0xfffc, /* dst_mask */
1550 FALSE
), /* pcrel_offset */
1552 /* Like DTPREL16_DS, but no overflow. */
1553 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1555 1, /* size (0 = byte, 1 = short, 2 = long) */
1557 FALSE
, /* pc_relative */
1559 complain_overflow_dont
, /* complain_on_overflow */
1560 ppc64_elf_unhandled_reloc
, /* special_function */
1561 "R_PPC64_DTPREL16_LO_DS", /* name */
1562 FALSE
, /* partial_inplace */
1564 0xfffc, /* dst_mask */
1565 FALSE
), /* pcrel_offset */
1567 /* Computes a tp-relative displacement, the difference between the value of
1568 sym+add and the value of the thread pointer (r13). */
1569 HOWTO (R_PPC64_TPREL64
,
1571 4, /* size (0 = byte, 1 = short, 2 = long) */
1573 FALSE
, /* pc_relative */
1575 complain_overflow_dont
, /* complain_on_overflow */
1576 ppc64_elf_unhandled_reloc
, /* special_function */
1577 "R_PPC64_TPREL64", /* name */
1578 FALSE
, /* partial_inplace */
1580 ONES (64), /* dst_mask */
1581 FALSE
), /* pcrel_offset */
1583 /* A 16 bit tprel reloc. */
1584 HOWTO (R_PPC64_TPREL16
,
1586 1, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE
, /* pc_relative */
1590 complain_overflow_signed
, /* complain_on_overflow */
1591 ppc64_elf_unhandled_reloc
, /* special_function */
1592 "R_PPC64_TPREL16", /* name */
1593 FALSE
, /* partial_inplace */
1595 0xffff, /* dst_mask */
1596 FALSE
), /* pcrel_offset */
1598 /* Like TPREL16, but no overflow. */
1599 HOWTO (R_PPC64_TPREL16_LO
,
1601 1, /* size (0 = byte, 1 = short, 2 = long) */
1603 FALSE
, /* pc_relative */
1605 complain_overflow_dont
, /* complain_on_overflow */
1606 ppc64_elf_unhandled_reloc
, /* special_function */
1607 "R_PPC64_TPREL16_LO", /* name */
1608 FALSE
, /* partial_inplace */
1610 0xffff, /* dst_mask */
1611 FALSE
), /* pcrel_offset */
1613 /* Like TPREL16_LO, but next higher group of 16 bits. */
1614 HOWTO (R_PPC64_TPREL16_HI
,
1615 16, /* rightshift */
1616 1, /* size (0 = byte, 1 = short, 2 = long) */
1618 FALSE
, /* pc_relative */
1620 complain_overflow_signed
, /* complain_on_overflow */
1621 ppc64_elf_unhandled_reloc
, /* special_function */
1622 "R_PPC64_TPREL16_HI", /* name */
1623 FALSE
, /* partial_inplace */
1625 0xffff, /* dst_mask */
1626 FALSE
), /* pcrel_offset */
1628 /* Like TPREL16_HI, but adjust for low 16 bits. */
1629 HOWTO (R_PPC64_TPREL16_HA
,
1630 16, /* rightshift */
1631 1, /* size (0 = byte, 1 = short, 2 = long) */
1633 FALSE
, /* pc_relative */
1635 complain_overflow_signed
, /* complain_on_overflow */
1636 ppc64_elf_unhandled_reloc
, /* special_function */
1637 "R_PPC64_TPREL16_HA", /* name */
1638 FALSE
, /* partial_inplace */
1640 0xffff, /* dst_mask */
1641 FALSE
), /* pcrel_offset */
1643 /* Like TPREL16_HI, but next higher group of 16 bits. */
1644 HOWTO (R_PPC64_TPREL16_HIGHER
,
1645 32, /* rightshift */
1646 1, /* size (0 = byte, 1 = short, 2 = long) */
1648 FALSE
, /* pc_relative */
1650 complain_overflow_dont
, /* complain_on_overflow */
1651 ppc64_elf_unhandled_reloc
, /* special_function */
1652 "R_PPC64_TPREL16_HIGHER", /* name */
1653 FALSE
, /* partial_inplace */
1655 0xffff, /* dst_mask */
1656 FALSE
), /* pcrel_offset */
1658 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1659 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1660 32, /* rightshift */
1661 1, /* size (0 = byte, 1 = short, 2 = long) */
1663 FALSE
, /* pc_relative */
1665 complain_overflow_dont
, /* complain_on_overflow */
1666 ppc64_elf_unhandled_reloc
, /* special_function */
1667 "R_PPC64_TPREL16_HIGHERA", /* name */
1668 FALSE
, /* partial_inplace */
1670 0xffff, /* dst_mask */
1671 FALSE
), /* pcrel_offset */
1673 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1674 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1675 48, /* rightshift */
1676 1, /* size (0 = byte, 1 = short, 2 = long) */
1678 FALSE
, /* pc_relative */
1680 complain_overflow_dont
, /* complain_on_overflow */
1681 ppc64_elf_unhandled_reloc
, /* special_function */
1682 "R_PPC64_TPREL16_HIGHEST", /* name */
1683 FALSE
, /* partial_inplace */
1685 0xffff, /* dst_mask */
1686 FALSE
), /* pcrel_offset */
1688 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1689 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1690 48, /* rightshift */
1691 1, /* size (0 = byte, 1 = short, 2 = long) */
1693 FALSE
, /* pc_relative */
1695 complain_overflow_dont
, /* complain_on_overflow */
1696 ppc64_elf_unhandled_reloc
, /* special_function */
1697 "R_PPC64_TPREL16_HIGHESTA", /* name */
1698 FALSE
, /* partial_inplace */
1700 0xffff, /* dst_mask */
1701 FALSE
), /* pcrel_offset */
1703 /* Like TPREL16, but for insns with a DS field. */
1704 HOWTO (R_PPC64_TPREL16_DS
,
1706 1, /* size (0 = byte, 1 = short, 2 = long) */
1708 FALSE
, /* pc_relative */
1710 complain_overflow_signed
, /* complain_on_overflow */
1711 ppc64_elf_unhandled_reloc
, /* special_function */
1712 "R_PPC64_TPREL16_DS", /* name */
1713 FALSE
, /* partial_inplace */
1715 0xfffc, /* dst_mask */
1716 FALSE
), /* pcrel_offset */
1718 /* Like TPREL16_DS, but no overflow. */
1719 HOWTO (R_PPC64_TPREL16_LO_DS
,
1721 1, /* size (0 = byte, 1 = short, 2 = long) */
1723 FALSE
, /* pc_relative */
1725 complain_overflow_dont
, /* complain_on_overflow */
1726 ppc64_elf_unhandled_reloc
, /* special_function */
1727 "R_PPC64_TPREL16_LO_DS", /* name */
1728 FALSE
, /* partial_inplace */
1730 0xfffc, /* dst_mask */
1731 FALSE
), /* pcrel_offset */
1733 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1734 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1735 to the first entry relative to the TOC base (r2). */
1736 HOWTO (R_PPC64_GOT_TLSGD16
,
1738 1, /* size (0 = byte, 1 = short, 2 = long) */
1740 FALSE
, /* pc_relative */
1742 complain_overflow_signed
, /* complain_on_overflow */
1743 ppc64_elf_unhandled_reloc
, /* special_function */
1744 "R_PPC64_GOT_TLSGD16", /* name */
1745 FALSE
, /* partial_inplace */
1747 0xffff, /* dst_mask */
1748 FALSE
), /* pcrel_offset */
1750 /* Like GOT_TLSGD16, but no overflow. */
1751 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1753 1, /* size (0 = byte, 1 = short, 2 = long) */
1755 FALSE
, /* pc_relative */
1757 complain_overflow_dont
, /* complain_on_overflow */
1758 ppc64_elf_unhandled_reloc
, /* special_function */
1759 "R_PPC64_GOT_TLSGD16_LO", /* name */
1760 FALSE
, /* partial_inplace */
1762 0xffff, /* dst_mask */
1763 FALSE
), /* pcrel_offset */
1765 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1766 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1767 16, /* rightshift */
1768 1, /* size (0 = byte, 1 = short, 2 = long) */
1770 FALSE
, /* pc_relative */
1772 complain_overflow_signed
, /* complain_on_overflow */
1773 ppc64_elf_unhandled_reloc
, /* special_function */
1774 "R_PPC64_GOT_TLSGD16_HI", /* name */
1775 FALSE
, /* partial_inplace */
1777 0xffff, /* dst_mask */
1778 FALSE
), /* pcrel_offset */
1780 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1781 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1782 16, /* rightshift */
1783 1, /* size (0 = byte, 1 = short, 2 = long) */
1785 FALSE
, /* pc_relative */
1787 complain_overflow_signed
, /* complain_on_overflow */
1788 ppc64_elf_unhandled_reloc
, /* special_function */
1789 "R_PPC64_GOT_TLSGD16_HA", /* name */
1790 FALSE
, /* partial_inplace */
1792 0xffff, /* dst_mask */
1793 FALSE
), /* pcrel_offset */
1795 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1796 with values (sym+add)@dtpmod and zero, and computes the offset to the
1797 first entry relative to the TOC base (r2). */
1798 HOWTO (R_PPC64_GOT_TLSLD16
,
1800 1, /* size (0 = byte, 1 = short, 2 = long) */
1802 FALSE
, /* pc_relative */
1804 complain_overflow_signed
, /* complain_on_overflow */
1805 ppc64_elf_unhandled_reloc
, /* special_function */
1806 "R_PPC64_GOT_TLSLD16", /* name */
1807 FALSE
, /* partial_inplace */
1809 0xffff, /* dst_mask */
1810 FALSE
), /* pcrel_offset */
1812 /* Like GOT_TLSLD16, but no overflow. */
1813 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1815 1, /* size (0 = byte, 1 = short, 2 = long) */
1817 FALSE
, /* pc_relative */
1819 complain_overflow_dont
, /* complain_on_overflow */
1820 ppc64_elf_unhandled_reloc
, /* special_function */
1821 "R_PPC64_GOT_TLSLD16_LO", /* name */
1822 FALSE
, /* partial_inplace */
1824 0xffff, /* dst_mask */
1825 FALSE
), /* pcrel_offset */
1827 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1828 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1829 16, /* rightshift */
1830 1, /* size (0 = byte, 1 = short, 2 = long) */
1832 FALSE
, /* pc_relative */
1834 complain_overflow_signed
, /* complain_on_overflow */
1835 ppc64_elf_unhandled_reloc
, /* special_function */
1836 "R_PPC64_GOT_TLSLD16_HI", /* name */
1837 FALSE
, /* partial_inplace */
1839 0xffff, /* dst_mask */
1840 FALSE
), /* pcrel_offset */
1842 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1843 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1844 16, /* rightshift */
1845 1, /* size (0 = byte, 1 = short, 2 = long) */
1847 FALSE
, /* pc_relative */
1849 complain_overflow_signed
, /* complain_on_overflow */
1850 ppc64_elf_unhandled_reloc
, /* special_function */
1851 "R_PPC64_GOT_TLSLD16_HA", /* name */
1852 FALSE
, /* partial_inplace */
1854 0xffff, /* dst_mask */
1855 FALSE
), /* pcrel_offset */
1857 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1858 the offset to the entry relative to the TOC base (r2). */
1859 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1861 1, /* size (0 = byte, 1 = short, 2 = long) */
1863 FALSE
, /* pc_relative */
1865 complain_overflow_signed
, /* complain_on_overflow */
1866 ppc64_elf_unhandled_reloc
, /* special_function */
1867 "R_PPC64_GOT_DTPREL16_DS", /* name */
1868 FALSE
, /* partial_inplace */
1870 0xfffc, /* dst_mask */
1871 FALSE
), /* pcrel_offset */
1873 /* Like GOT_DTPREL16_DS, but no overflow. */
1874 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1876 1, /* size (0 = byte, 1 = short, 2 = long) */
1878 FALSE
, /* pc_relative */
1880 complain_overflow_dont
, /* complain_on_overflow */
1881 ppc64_elf_unhandled_reloc
, /* special_function */
1882 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1883 FALSE
, /* partial_inplace */
1885 0xfffc, /* dst_mask */
1886 FALSE
), /* pcrel_offset */
1888 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1889 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1890 16, /* rightshift */
1891 1, /* size (0 = byte, 1 = short, 2 = long) */
1893 FALSE
, /* pc_relative */
1895 complain_overflow_signed
, /* complain_on_overflow */
1896 ppc64_elf_unhandled_reloc
, /* special_function */
1897 "R_PPC64_GOT_DTPREL16_HI", /* name */
1898 FALSE
, /* partial_inplace */
1900 0xffff, /* dst_mask */
1901 FALSE
), /* pcrel_offset */
1903 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1904 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1905 16, /* rightshift */
1906 1, /* size (0 = byte, 1 = short, 2 = long) */
1908 FALSE
, /* pc_relative */
1910 complain_overflow_signed
, /* complain_on_overflow */
1911 ppc64_elf_unhandled_reloc
, /* special_function */
1912 "R_PPC64_GOT_DTPREL16_HA", /* name */
1913 FALSE
, /* partial_inplace */
1915 0xffff, /* dst_mask */
1916 FALSE
), /* pcrel_offset */
1918 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1919 offset to the entry relative to the TOC base (r2). */
1920 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1922 1, /* size (0 = byte, 1 = short, 2 = long) */
1924 FALSE
, /* pc_relative */
1926 complain_overflow_signed
, /* complain_on_overflow */
1927 ppc64_elf_unhandled_reloc
, /* special_function */
1928 "R_PPC64_GOT_TPREL16_DS", /* name */
1929 FALSE
, /* partial_inplace */
1931 0xfffc, /* dst_mask */
1932 FALSE
), /* pcrel_offset */
1934 /* Like GOT_TPREL16_DS, but no overflow. */
1935 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1937 1, /* size (0 = byte, 1 = short, 2 = long) */
1939 FALSE
, /* pc_relative */
1941 complain_overflow_dont
, /* complain_on_overflow */
1942 ppc64_elf_unhandled_reloc
, /* special_function */
1943 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1944 FALSE
, /* partial_inplace */
1946 0xfffc, /* dst_mask */
1947 FALSE
), /* pcrel_offset */
1949 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1950 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1951 16, /* rightshift */
1952 1, /* size (0 = byte, 1 = short, 2 = long) */
1954 FALSE
, /* pc_relative */
1956 complain_overflow_signed
, /* complain_on_overflow */
1957 ppc64_elf_unhandled_reloc
, /* special_function */
1958 "R_PPC64_GOT_TPREL16_HI", /* name */
1959 FALSE
, /* partial_inplace */
1961 0xffff, /* dst_mask */
1962 FALSE
), /* pcrel_offset */
1964 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1965 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1966 16, /* rightshift */
1967 1, /* size (0 = byte, 1 = short, 2 = long) */
1969 FALSE
, /* pc_relative */
1971 complain_overflow_signed
, /* complain_on_overflow */
1972 ppc64_elf_unhandled_reloc
, /* special_function */
1973 "R_PPC64_GOT_TPREL16_HA", /* name */
1974 FALSE
, /* partial_inplace */
1976 0xffff, /* dst_mask */
1977 FALSE
), /* pcrel_offset */
1979 HOWTO (R_PPC64_JMP_IREL
, /* type */
1981 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1983 FALSE
, /* pc_relative */
1985 complain_overflow_dont
, /* complain_on_overflow */
1986 ppc64_elf_unhandled_reloc
, /* special_function */
1987 "R_PPC64_JMP_IREL", /* name */
1988 FALSE
, /* partial_inplace */
1991 FALSE
), /* pcrel_offset */
1993 HOWTO (R_PPC64_IRELATIVE
, /* type */
1995 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1997 FALSE
, /* pc_relative */
1999 complain_overflow_dont
, /* complain_on_overflow */
2000 bfd_elf_generic_reloc
, /* special_function */
2001 "R_PPC64_IRELATIVE", /* name */
2002 FALSE
, /* partial_inplace */
2004 ONES (64), /* dst_mask */
2005 FALSE
), /* pcrel_offset */
2007 /* A 16 bit relative relocation. */
2008 HOWTO (R_PPC64_REL16
, /* type */
2010 1, /* size (0 = byte, 1 = short, 2 = long) */
2012 TRUE
, /* pc_relative */
2014 complain_overflow_signed
, /* complain_on_overflow */
2015 bfd_elf_generic_reloc
, /* special_function */
2016 "R_PPC64_REL16", /* name */
2017 FALSE
, /* partial_inplace */
2019 0xffff, /* dst_mask */
2020 TRUE
), /* pcrel_offset */
2022 /* A 16 bit relative relocation without overflow. */
2023 HOWTO (R_PPC64_REL16_LO
, /* type */
2025 1, /* size (0 = byte, 1 = short, 2 = long) */
2027 TRUE
, /* pc_relative */
2029 complain_overflow_dont
,/* complain_on_overflow */
2030 bfd_elf_generic_reloc
, /* special_function */
2031 "R_PPC64_REL16_LO", /* name */
2032 FALSE
, /* partial_inplace */
2034 0xffff, /* dst_mask */
2035 TRUE
), /* pcrel_offset */
2037 /* The high order 16 bits of a relative address. */
2038 HOWTO (R_PPC64_REL16_HI
, /* type */
2039 16, /* rightshift */
2040 1, /* size (0 = byte, 1 = short, 2 = long) */
2042 TRUE
, /* pc_relative */
2044 complain_overflow_signed
, /* complain_on_overflow */
2045 bfd_elf_generic_reloc
, /* special_function */
2046 "R_PPC64_REL16_HI", /* name */
2047 FALSE
, /* partial_inplace */
2049 0xffff, /* dst_mask */
2050 TRUE
), /* pcrel_offset */
2052 /* The high order 16 bits of a relative address, plus 1 if the contents of
2053 the low 16 bits, treated as a signed number, is negative. */
2054 HOWTO (R_PPC64_REL16_HA
, /* type */
2055 16, /* rightshift */
2056 1, /* size (0 = byte, 1 = short, 2 = long) */
2058 TRUE
, /* pc_relative */
2060 complain_overflow_signed
, /* complain_on_overflow */
2061 ppc64_elf_ha_reloc
, /* special_function */
2062 "R_PPC64_REL16_HA", /* name */
2063 FALSE
, /* partial_inplace */
2065 0xffff, /* dst_mask */
2066 TRUE
), /* pcrel_offset */
2068 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
2069 HOWTO (R_PPC64_REL16DX_HA
, /* type */
2070 16, /* rightshift */
2071 2, /* size (0 = byte, 1 = short, 2 = long) */
2073 TRUE
, /* pc_relative */
2075 complain_overflow_signed
, /* complain_on_overflow */
2076 ppc64_elf_ha_reloc
, /* special_function */
2077 "R_PPC64_REL16DX_HA", /* name */
2078 FALSE
, /* partial_inplace */
2080 0x1fffc1, /* dst_mask */
2081 TRUE
), /* pcrel_offset */
2083 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
2084 HOWTO (R_PPC64_16DX_HA
, /* type */
2085 16, /* rightshift */
2086 2, /* size (0 = byte, 1 = short, 2 = long) */
2088 FALSE
, /* pc_relative */
2090 complain_overflow_signed
, /* complain_on_overflow */
2091 ppc64_elf_ha_reloc
, /* special_function */
2092 "R_PPC64_16DX_HA", /* name */
2093 FALSE
, /* partial_inplace */
2095 0x1fffc1, /* dst_mask */
2096 FALSE
), /* pcrel_offset */
2098 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2099 HOWTO (R_PPC64_ADDR16_HIGH
, /* type */
2100 16, /* rightshift */
2101 1, /* size (0 = byte, 1 = short, 2 = long) */
2103 FALSE
, /* pc_relative */
2105 complain_overflow_dont
, /* complain_on_overflow */
2106 bfd_elf_generic_reloc
, /* special_function */
2107 "R_PPC64_ADDR16_HIGH", /* name */
2108 FALSE
, /* partial_inplace */
2110 0xffff, /* dst_mask */
2111 FALSE
), /* pcrel_offset */
2113 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2114 HOWTO (R_PPC64_ADDR16_HIGHA
, /* type */
2115 16, /* rightshift */
2116 1, /* size (0 = byte, 1 = short, 2 = long) */
2118 FALSE
, /* pc_relative */
2120 complain_overflow_dont
, /* complain_on_overflow */
2121 ppc64_elf_ha_reloc
, /* special_function */
2122 "R_PPC64_ADDR16_HIGHA", /* name */
2123 FALSE
, /* partial_inplace */
2125 0xffff, /* dst_mask */
2126 FALSE
), /* pcrel_offset */
2128 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2129 HOWTO (R_PPC64_DTPREL16_HIGH
,
2130 16, /* rightshift */
2131 1, /* size (0 = byte, 1 = short, 2 = long) */
2133 FALSE
, /* pc_relative */
2135 complain_overflow_dont
, /* complain_on_overflow */
2136 ppc64_elf_unhandled_reloc
, /* special_function */
2137 "R_PPC64_DTPREL16_HIGH", /* name */
2138 FALSE
, /* partial_inplace */
2140 0xffff, /* dst_mask */
2141 FALSE
), /* pcrel_offset */
2143 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2144 HOWTO (R_PPC64_DTPREL16_HIGHA
,
2145 16, /* rightshift */
2146 1, /* size (0 = byte, 1 = short, 2 = long) */
2148 FALSE
, /* pc_relative */
2150 complain_overflow_dont
, /* complain_on_overflow */
2151 ppc64_elf_unhandled_reloc
, /* special_function */
2152 "R_PPC64_DTPREL16_HIGHA", /* name */
2153 FALSE
, /* partial_inplace */
2155 0xffff, /* dst_mask */
2156 FALSE
), /* pcrel_offset */
2158 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2159 HOWTO (R_PPC64_TPREL16_HIGH
,
2160 16, /* rightshift */
2161 1, /* size (0 = byte, 1 = short, 2 = long) */
2163 FALSE
, /* pc_relative */
2165 complain_overflow_dont
, /* complain_on_overflow */
2166 ppc64_elf_unhandled_reloc
, /* special_function */
2167 "R_PPC64_TPREL16_HIGH", /* name */
2168 FALSE
, /* partial_inplace */
2170 0xffff, /* dst_mask */
2171 FALSE
), /* pcrel_offset */
2173 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2174 HOWTO (R_PPC64_TPREL16_HIGHA
,
2175 16, /* rightshift */
2176 1, /* size (0 = byte, 1 = short, 2 = long) */
2178 FALSE
, /* pc_relative */
2180 complain_overflow_dont
, /* complain_on_overflow */
2181 ppc64_elf_unhandled_reloc
, /* special_function */
2182 "R_PPC64_TPREL16_HIGHA", /* name */
2183 FALSE
, /* partial_inplace */
2185 0xffff, /* dst_mask */
2186 FALSE
), /* pcrel_offset */
2188 /* Marker reloc on ELFv2 large-model function entry. */
2189 HOWTO (R_PPC64_ENTRY
,
2191 2, /* size (0 = byte, 1 = short, 2 = long) */
2193 FALSE
, /* pc_relative */
2195 complain_overflow_dont
, /* complain_on_overflow */
2196 bfd_elf_generic_reloc
, /* special_function */
2197 "R_PPC64_ENTRY", /* name */
2198 FALSE
, /* partial_inplace */
2201 FALSE
), /* pcrel_offset */
2203 /* Like ADDR64, but use local entry point of function. */
2204 HOWTO (R_PPC64_ADDR64_LOCAL
, /* type */
2206 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2208 FALSE
, /* pc_relative */
2210 complain_overflow_dont
, /* complain_on_overflow */
2211 bfd_elf_generic_reloc
, /* special_function */
2212 "R_PPC64_ADDR64_LOCAL", /* name */
2213 FALSE
, /* partial_inplace */
2215 ONES (64), /* dst_mask */
2216 FALSE
), /* pcrel_offset */
2218 /* GNU extension to record C++ vtable hierarchy. */
2219 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
2221 0, /* size (0 = byte, 1 = short, 2 = long) */
2223 FALSE
, /* pc_relative */
2225 complain_overflow_dont
, /* complain_on_overflow */
2226 NULL
, /* special_function */
2227 "R_PPC64_GNU_VTINHERIT", /* name */
2228 FALSE
, /* partial_inplace */
2231 FALSE
), /* pcrel_offset */
2233 /* GNU extension to record C++ vtable member usage. */
2234 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
2236 0, /* size (0 = byte, 1 = short, 2 = long) */
2238 FALSE
, /* pc_relative */
2240 complain_overflow_dont
, /* complain_on_overflow */
2241 NULL
, /* special_function */
2242 "R_PPC64_GNU_VTENTRY", /* name */
2243 FALSE
, /* partial_inplace */
2246 FALSE
), /* pcrel_offset */
2250 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2254 ppc_howto_init (void)
2256 unsigned int i
, type
;
2258 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2260 type
= ppc64_elf_howto_raw
[i
].type
;
2261 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
2262 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2266 static reloc_howto_type
*
2267 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
2268 bfd_reloc_code_real_type code
)
2270 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2272 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2273 /* Initialize howto table if needed. */
2279 /* xgettext:c-format */
2280 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, (int) code
);
2281 bfd_set_error (bfd_error_bad_value
);
2284 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2286 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2288 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2290 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2292 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2294 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2296 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
2298 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2300 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
2302 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2304 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2306 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2308 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2310 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2312 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2314 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2316 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2318 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2320 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2322 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2324 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2326 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2328 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2330 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2332 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2334 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2336 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2338 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2340 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2342 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2344 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2346 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2348 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2350 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2352 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2354 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2356 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2358 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2360 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2362 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2364 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2366 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2368 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2370 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2372 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2374 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2376 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2378 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2380 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2382 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2384 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2386 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2388 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2390 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2392 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2394 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2396 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2398 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2400 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2402 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2404 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2406 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2408 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2410 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2412 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2414 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2416 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2418 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2420 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
2422 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2424 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
2426 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2428 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2430 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2432 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2434 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
2436 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2438 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
2440 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2442 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2444 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2446 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2448 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2450 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2452 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2454 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2456 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2458 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2460 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2462 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2464 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2466 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2468 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2470 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2472 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2474 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2476 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2478 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2480 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2482 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2484 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2486 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2488 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2490 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2492 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2494 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2496 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2498 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2500 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2502 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2504 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2506 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
2508 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
2510 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
2512 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
2514 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2516 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2520 return ppc64_elf_howto_table
[r
];
2523 static reloc_howto_type
*
2524 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2529 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2530 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2531 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2532 return &ppc64_elf_howto_raw
[i
];
2538 /* Set the howto pointer for a PowerPC ELF reloc. */
2541 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
2542 Elf_Internal_Rela
*dst
)
2546 /* Initialize howto table if needed. */
2547 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2550 type
= ELF64_R_TYPE (dst
->r_info
);
2551 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
2553 /* xgettext:c-format */
2554 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2556 bfd_set_error (bfd_error_bad_value
);
2559 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2560 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
2562 /* xgettext:c-format */
2563 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2565 bfd_set_error (bfd_error_bad_value
);
2572 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2574 static bfd_reloc_status_type
2575 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2576 void *data
, asection
*input_section
,
2577 bfd
*output_bfd
, char **error_message
)
2579 enum elf_ppc64_reloc_type r_type
;
2581 bfd_size_type octets
;
2584 /* If this is a relocatable link (output_bfd test tells us), just
2585 call the generic function. Any adjustment will be done at final
2587 if (output_bfd
!= NULL
)
2588 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2589 input_section
, output_bfd
, error_message
);
2591 /* Adjust the addend for sign extension of the low 16 bits.
2592 We won't actually be using the low 16 bits, so trashing them
2594 reloc_entry
->addend
+= 0x8000;
2595 r_type
= reloc_entry
->howto
->type
;
2596 if (r_type
!= R_PPC64_REL16DX_HA
)
2597 return bfd_reloc_continue
;
2600 if (!bfd_is_com_section (symbol
->section
))
2601 value
= symbol
->value
;
2602 value
+= (reloc_entry
->addend
2603 + symbol
->section
->output_offset
2604 + symbol
->section
->output_section
->vma
);
2605 value
-= (reloc_entry
->address
2606 + input_section
->output_offset
2607 + input_section
->output_section
->vma
);
2608 value
= (bfd_signed_vma
) value
>> 16;
2610 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2611 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2613 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2614 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2615 if (value
+ 0x8000 > 0xffff)
2616 return bfd_reloc_overflow
;
2617 return bfd_reloc_ok
;
2620 static bfd_reloc_status_type
2621 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2622 void *data
, asection
*input_section
,
2623 bfd
*output_bfd
, char **error_message
)
2625 if (output_bfd
!= NULL
)
2626 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2627 input_section
, output_bfd
, error_message
);
2629 if (strcmp (symbol
->section
->name
, ".opd") == 0
2630 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2632 bfd_vma dest
= opd_entry_value (symbol
->section
,
2633 symbol
->value
+ reloc_entry
->addend
,
2635 if (dest
!= (bfd_vma
) -1)
2636 reloc_entry
->addend
= dest
- (symbol
->value
2637 + symbol
->section
->output_section
->vma
2638 + symbol
->section
->output_offset
);
2642 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
2644 if (symbol
->section
->owner
!= abfd
2645 && symbol
->section
->owner
!= NULL
2646 && abiversion (symbol
->section
->owner
) >= 2)
2650 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
2652 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
2654 if (strcmp (symdef
->name
, symbol
->name
) == 0)
2656 elfsym
= (elf_symbol_type
*) symdef
;
2662 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
2664 return bfd_reloc_continue
;
2667 static bfd_reloc_status_type
2668 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2669 void *data
, asection
*input_section
,
2670 bfd
*output_bfd
, char **error_message
)
2673 enum elf_ppc64_reloc_type r_type
;
2674 bfd_size_type octets
;
2675 /* Assume 'at' branch hints. */
2676 bfd_boolean is_isa_v2
= TRUE
;
2678 /* If this is a relocatable link (output_bfd test tells us), just
2679 call the generic function. Any adjustment will be done at final
2681 if (output_bfd
!= NULL
)
2682 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2683 input_section
, output_bfd
, error_message
);
2685 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2686 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2687 insn
&= ~(0x01 << 21);
2688 r_type
= reloc_entry
->howto
->type
;
2689 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2690 || r_type
== R_PPC64_REL14_BRTAKEN
)
2691 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2695 /* Set 'a' bit. This is 0b00010 in BO field for branch
2696 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2697 for branch on CTR insns (BO == 1a00t or 1a01t). */
2698 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2700 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2710 if (!bfd_is_com_section (symbol
->section
))
2711 target
= symbol
->value
;
2712 target
+= symbol
->section
->output_section
->vma
;
2713 target
+= symbol
->section
->output_offset
;
2714 target
+= reloc_entry
->addend
;
2716 from
= (reloc_entry
->address
2717 + input_section
->output_offset
2718 + input_section
->output_section
->vma
);
2720 /* Invert 'y' bit if not the default. */
2721 if ((bfd_signed_vma
) (target
- from
) < 0)
2724 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2726 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2727 input_section
, output_bfd
, error_message
);
2730 static bfd_reloc_status_type
2731 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2732 void *data
, asection
*input_section
,
2733 bfd
*output_bfd
, char **error_message
)
2735 /* If this is a relocatable link (output_bfd test tells us), just
2736 call the generic function. Any adjustment will be done at final
2738 if (output_bfd
!= NULL
)
2739 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2740 input_section
, output_bfd
, error_message
);
2742 /* Subtract the symbol section base address. */
2743 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2744 return bfd_reloc_continue
;
2747 static bfd_reloc_status_type
2748 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2749 void *data
, asection
*input_section
,
2750 bfd
*output_bfd
, char **error_message
)
2752 /* If this is a relocatable link (output_bfd test tells us), just
2753 call the generic function. Any adjustment will be done at final
2755 if (output_bfd
!= NULL
)
2756 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2757 input_section
, output_bfd
, error_message
);
2759 /* Subtract the symbol section base address. */
2760 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2762 /* Adjust the addend for sign extension of the low 16 bits. */
2763 reloc_entry
->addend
+= 0x8000;
2764 return bfd_reloc_continue
;
2767 static bfd_reloc_status_type
2768 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2769 void *data
, asection
*input_section
,
2770 bfd
*output_bfd
, char **error_message
)
2774 /* If this is a relocatable link (output_bfd test tells us), just
2775 call the generic function. Any adjustment will be done at final
2777 if (output_bfd
!= NULL
)
2778 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2779 input_section
, output_bfd
, error_message
);
2781 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2783 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2785 /* Subtract the TOC base address. */
2786 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2787 return bfd_reloc_continue
;
2790 static bfd_reloc_status_type
2791 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2792 void *data
, asection
*input_section
,
2793 bfd
*output_bfd
, char **error_message
)
2797 /* If this is a relocatable link (output_bfd test tells us), just
2798 call the generic function. Any adjustment will be done at final
2800 if (output_bfd
!= NULL
)
2801 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2802 input_section
, output_bfd
, error_message
);
2804 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2806 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2808 /* Subtract the TOC base address. */
2809 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2811 /* Adjust the addend for sign extension of the low 16 bits. */
2812 reloc_entry
->addend
+= 0x8000;
2813 return bfd_reloc_continue
;
2816 static bfd_reloc_status_type
2817 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2818 void *data
, asection
*input_section
,
2819 bfd
*output_bfd
, char **error_message
)
2822 bfd_size_type octets
;
2824 /* If this is a relocatable link (output_bfd test tells us), just
2825 call the generic function. Any adjustment will be done at final
2827 if (output_bfd
!= NULL
)
2828 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2829 input_section
, output_bfd
, error_message
);
2831 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2833 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2835 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2836 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2837 return bfd_reloc_ok
;
2840 static bfd_reloc_status_type
2841 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2842 void *data
, asection
*input_section
,
2843 bfd
*output_bfd
, char **error_message
)
2845 /* If this is a relocatable link (output_bfd test tells us), just
2846 call the generic function. Any adjustment will be done at final
2848 if (output_bfd
!= NULL
)
2849 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2850 input_section
, output_bfd
, error_message
);
2852 if (error_message
!= NULL
)
2854 static char buf
[60];
2855 sprintf (buf
, "generic linker can't handle %s",
2856 reloc_entry
->howto
->name
);
2857 *error_message
= buf
;
2859 return bfd_reloc_dangerous
;
2862 /* Track GOT entries needed for a given symbol. We might need more
2863 than one got entry per symbol. */
2866 struct got_entry
*next
;
2868 /* The symbol addend that we'll be placing in the GOT. */
2871 /* Unlike other ELF targets, we use separate GOT entries for the same
2872 symbol referenced from different input files. This is to support
2873 automatic multiple TOC/GOT sections, where the TOC base can vary
2874 from one input file to another. After partitioning into TOC groups
2875 we merge entries within the group.
2877 Point to the BFD owning this GOT entry. */
2880 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2881 TLS_TPREL or TLS_DTPREL for tls entries. */
2882 unsigned char tls_type
;
2884 /* Non-zero if got.ent points to real entry. */
2885 unsigned char is_indirect
;
2887 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2890 bfd_signed_vma refcount
;
2892 struct got_entry
*ent
;
2896 /* The same for PLT. */
2899 struct plt_entry
*next
;
2905 bfd_signed_vma refcount
;
2910 struct ppc64_elf_obj_tdata
2912 struct elf_obj_tdata elf
;
2914 /* Shortcuts to dynamic linker sections. */
2918 /* Used during garbage collection. We attach global symbols defined
2919 on removed .opd entries to this section so that the sym is removed. */
2920 asection
*deleted_section
;
2922 /* TLS local dynamic got entry handling. Support for multiple GOT
2923 sections means we potentially need one of these for each input bfd. */
2924 struct got_entry tlsld_got
;
2927 /* A copy of relocs before they are modified for --emit-relocs. */
2928 Elf_Internal_Rela
*relocs
;
2930 /* Section contents. */
2934 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2935 the reloc to be in the range -32768 to 32767. */
2936 unsigned int has_small_toc_reloc
: 1;
2938 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2939 instruction not one we handle. */
2940 unsigned int unexpected_toc_insn
: 1;
2943 #define ppc64_elf_tdata(bfd) \
2944 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2946 #define ppc64_tlsld_got(bfd) \
2947 (&ppc64_elf_tdata (bfd)->tlsld_got)
2949 #define is_ppc64_elf(bfd) \
2950 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2951 && elf_object_id (bfd) == PPC64_ELF_DATA)
2953 /* Override the generic function because we store some extras. */
2956 ppc64_elf_mkobject (bfd
*abfd
)
2958 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2962 /* Fix bad default arch selected for a 64 bit input bfd when the
2963 default is 32 bit. Also select arch based on apuinfo. */
2966 ppc64_elf_object_p (bfd
*abfd
)
2968 if (!abfd
->arch_info
->the_default
)
2971 if (abfd
->arch_info
->bits_per_word
== 32)
2973 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2975 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2977 /* Relies on arch after 32 bit default being 64 bit default. */
2978 abfd
->arch_info
= abfd
->arch_info
->next
;
2979 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2982 return _bfd_elf_ppc_set_arch (abfd
);
2985 /* Support for core dump NOTE sections. */
2988 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2990 size_t offset
, size
;
2992 if (note
->descsz
!= 504)
2996 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2999 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
3005 /* Make a ".reg/999" section. */
3006 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3007 size
, note
->descpos
+ offset
);
3011 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
3013 if (note
->descsz
!= 136)
3016 elf_tdata (abfd
)->core
->pid
3017 = bfd_get_32 (abfd
, note
->descdata
+ 24);
3018 elf_tdata (abfd
)->core
->program
3019 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
3020 elf_tdata (abfd
)->core
->command
3021 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
3027 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
3040 va_start (ap
, note_type
);
3041 memset (data
, 0, sizeof (data
));
3042 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
3043 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
3045 return elfcore_write_note (abfd
, buf
, bufsiz
,
3046 "CORE", note_type
, data
, sizeof (data
));
3057 va_start (ap
, note_type
);
3058 memset (data
, 0, 112);
3059 pid
= va_arg (ap
, long);
3060 bfd_put_32 (abfd
, pid
, data
+ 32);
3061 cursig
= va_arg (ap
, int);
3062 bfd_put_16 (abfd
, cursig
, data
+ 12);
3063 greg
= va_arg (ap
, const void *);
3064 memcpy (data
+ 112, greg
, 384);
3065 memset (data
+ 496, 0, 8);
3067 return elfcore_write_note (abfd
, buf
, bufsiz
,
3068 "CORE", note_type
, data
, sizeof (data
));
3073 /* Add extra PPC sections. */
3075 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
3077 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
3078 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3079 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3080 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3081 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3082 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3083 { NULL
, 0, 0, 0, 0 }
3086 enum _ppc64_sec_type
{
3092 struct _ppc64_elf_section_data
3094 struct bfd_elf_section_data elf
;
3098 /* An array with one entry for each opd function descriptor,
3099 and some spares since opd entries may be either 16 or 24 bytes. */
3100 #define OPD_NDX(OFF) ((OFF) >> 4)
3101 struct _opd_sec_data
3103 /* Points to the function code section for local opd entries. */
3104 asection
**func_sec
;
3106 /* After editing .opd, adjust references to opd local syms. */
3110 /* An array for toc sections, indexed by offset/8. */
3111 struct _toc_sec_data
3113 /* Specifies the relocation symbol index used at a given toc offset. */
3116 /* And the relocation addend. */
3121 enum _ppc64_sec_type sec_type
:2;
3123 /* Flag set when small branches are detected. Used to
3124 select suitable defaults for the stub group size. */
3125 unsigned int has_14bit_branch
:1;
3128 #define ppc64_elf_section_data(sec) \
3129 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
3132 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
3134 if (!sec
->used_by_bfd
)
3136 struct _ppc64_elf_section_data
*sdata
;
3137 bfd_size_type amt
= sizeof (*sdata
);
3139 sdata
= bfd_zalloc (abfd
, amt
);
3142 sec
->used_by_bfd
= sdata
;
3145 return _bfd_elf_new_section_hook (abfd
, sec
);
3148 static struct _opd_sec_data
*
3149 get_opd_info (asection
* sec
)
3152 && ppc64_elf_section_data (sec
) != NULL
3153 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
3154 return &ppc64_elf_section_data (sec
)->u
.opd
;
3158 /* Parameters for the qsort hook. */
3159 static bfd_boolean synthetic_relocatable
;
3160 static asection
*synthetic_opd
;
3162 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3165 compare_symbols (const void *ap
, const void *bp
)
3167 const asymbol
*a
= * (const asymbol
**) ap
;
3168 const asymbol
*b
= * (const asymbol
**) bp
;
3170 /* Section symbols first. */
3171 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
3173 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
3176 /* then .opd symbols. */
3177 if (synthetic_opd
!= NULL
)
3179 if (strcmp (a
->section
->name
, ".opd") == 0
3180 && strcmp (b
->section
->name
, ".opd") != 0)
3182 if (strcmp (a
->section
->name
, ".opd") != 0
3183 && strcmp (b
->section
->name
, ".opd") == 0)
3187 /* then other code symbols. */
3188 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3189 == (SEC_CODE
| SEC_ALLOC
)
3190 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3191 != (SEC_CODE
| SEC_ALLOC
))
3194 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3195 != (SEC_CODE
| SEC_ALLOC
)
3196 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3197 == (SEC_CODE
| SEC_ALLOC
))
3200 if (synthetic_relocatable
)
3202 if (a
->section
->id
< b
->section
->id
)
3205 if (a
->section
->id
> b
->section
->id
)
3209 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
3212 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
3215 /* For syms with the same value, prefer strong dynamic global function
3216 syms over other syms. */
3217 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
3220 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
3223 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
3226 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
3229 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
3232 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
3235 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
3238 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
3244 /* Search SYMS for a symbol of the given VALUE. */
3247 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
3251 if (id
== (unsigned) -1)
3255 mid
= (lo
+ hi
) >> 1;
3256 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
3258 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
3268 mid
= (lo
+ hi
) >> 1;
3269 if (syms
[mid
]->section
->id
< id
)
3271 else if (syms
[mid
]->section
->id
> id
)
3273 else if (syms
[mid
]->value
< value
)
3275 else if (syms
[mid
]->value
> value
)
3285 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
3287 bfd_vma vma
= *(bfd_vma
*) ptr
;
3288 return ((section
->flags
& SEC_ALLOC
) != 0
3289 && section
->vma
<= vma
3290 && vma
< section
->vma
+ section
->size
);
3293 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3294 entry syms. Also generate @plt symbols for the glink branch table.
3295 Returns count of synthetic symbols in RET or -1 on error. */
3298 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
3299 long static_count
, asymbol
**static_syms
,
3300 long dyn_count
, asymbol
**dyn_syms
,
3306 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
3307 asection
*opd
= NULL
;
3308 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
3310 int abi
= abiversion (abfd
);
3316 opd
= bfd_get_section_by_name (abfd
, ".opd");
3317 if (opd
== NULL
&& abi
== 1)
3329 symcount
= static_count
;
3331 symcount
+= dyn_count
;
3335 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
3339 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
3341 /* Use both symbol tables. */
3342 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
3343 memcpy (syms
+ static_count
, dyn_syms
,
3344 (dyn_count
+ 1) * sizeof (*syms
));
3346 else if (!relocatable
&& static_count
== 0)
3347 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
3349 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
3351 /* Trim uninteresting symbols. Interesting symbols are section,
3352 function, and notype symbols. */
3353 for (i
= 0, j
= 0; i
< symcount
; ++i
)
3354 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
3355 | BSF_RELC
| BSF_SRELC
)) == 0)
3356 syms
[j
++] = syms
[i
];
3359 synthetic_relocatable
= relocatable
;
3360 synthetic_opd
= opd
;
3361 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
3363 if (!relocatable
&& symcount
> 1)
3365 /* Trim duplicate syms, since we may have merged the normal and
3366 dynamic symbols. Actually, we only care about syms that have
3367 different values, so trim any with the same value. */
3368 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3369 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3370 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3371 syms
[j
++] = syms
[i
];
3376 /* Note that here and in compare_symbols we can't compare opd and
3377 sym->section directly. With separate debug info files, the
3378 symbols will be extracted from the debug file while abfd passed
3379 to this function is the real binary. */
3380 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3384 for (; i
< symcount
; ++i
)
3385 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
3386 | SEC_THREAD_LOCAL
))
3387 != (SEC_CODE
| SEC_ALLOC
))
3388 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3392 for (; i
< symcount
; ++i
)
3393 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3397 for (; i
< symcount
; ++i
)
3398 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3402 for (; i
< symcount
; ++i
)
3403 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3404 != (SEC_CODE
| SEC_ALLOC
))
3412 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3417 if (opdsymend
== secsymend
)
3420 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3421 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3425 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3432 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3436 while (r
< opd
->relocation
+ relcount
3437 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3440 if (r
== opd
->relocation
+ relcount
)
3443 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3446 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3449 sym
= *r
->sym_ptr_ptr
;
3450 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3451 sym
->section
->id
, sym
->value
+ r
->addend
))
3454 size
+= sizeof (asymbol
);
3455 size
+= strlen (syms
[i
]->name
) + 2;
3461 s
= *ret
= bfd_malloc (size
);
3468 names
= (char *) (s
+ count
);
3470 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3474 while (r
< opd
->relocation
+ relcount
3475 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3478 if (r
== opd
->relocation
+ relcount
)
3481 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3484 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3487 sym
= *r
->sym_ptr_ptr
;
3488 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3489 sym
->section
->id
, sym
->value
+ r
->addend
))
3494 s
->flags
|= BSF_SYNTHETIC
;
3495 s
->section
= sym
->section
;
3496 s
->value
= sym
->value
+ r
->addend
;
3499 len
= strlen (syms
[i
]->name
);
3500 memcpy (names
, syms
[i
]->name
, len
+ 1);
3502 /* Have udata.p point back to the original symbol this
3503 synthetic symbol was derived from. */
3504 s
->udata
.p
= syms
[i
];
3511 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3512 bfd_byte
*contents
= NULL
;
3514 size_t plt_count
= 0;
3515 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3516 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3519 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3521 free_contents_and_exit_err
:
3523 free_contents_and_exit
:
3530 for (i
= secsymend
; i
< opdsymend
; ++i
)
3534 /* Ignore bogus symbols. */
3535 if (syms
[i
]->value
> opd
->size
- 8)
3538 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3539 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3542 size
+= sizeof (asymbol
);
3543 size
+= strlen (syms
[i
]->name
) + 2;
3547 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3549 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3551 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3553 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3555 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3556 goto free_contents_and_exit_err
;
3558 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3559 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3562 extdynend
= extdyn
+ dynamic
->size
;
3563 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3565 Elf_Internal_Dyn dyn
;
3566 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3568 if (dyn
.d_tag
== DT_NULL
)
3571 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3573 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
3574 See comment in ppc64_elf_finish_dynamic_sections. */
3575 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
3576 /* The .glink section usually does not survive the final
3577 link; search for the section (usually .text) where the
3578 glink stubs now reside. */
3579 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3590 /* Determine __glink trampoline by reading the relative branch
3591 from the first glink stub. */
3593 unsigned int off
= 0;
3595 while (bfd_get_section_contents (abfd
, glink
, buf
,
3596 glink_vma
+ off
- glink
->vma
, 4))
3598 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3600 if ((insn
& ~0x3fffffc) == 0)
3602 resolv_vma
= glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
3611 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3613 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3616 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3617 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3618 goto free_contents_and_exit_err
;
3620 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3621 size
+= plt_count
* sizeof (asymbol
);
3623 p
= relplt
->relocation
;
3624 for (i
= 0; i
< plt_count
; i
++, p
++)
3626 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3628 size
+= sizeof ("+0x") - 1 + 16;
3634 goto free_contents_and_exit
;
3635 s
= *ret
= bfd_malloc (size
);
3637 goto free_contents_and_exit_err
;
3639 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3641 for (i
= secsymend
; i
< opdsymend
; ++i
)
3645 if (syms
[i
]->value
> opd
->size
- 8)
3648 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3649 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3653 asection
*sec
= abfd
->sections
;
3660 size_t mid
= (lo
+ hi
) >> 1;
3661 if (syms
[mid
]->section
->vma
< ent
)
3663 else if (syms
[mid
]->section
->vma
> ent
)
3667 sec
= syms
[mid
]->section
;
3672 if (lo
>= hi
&& lo
> codesecsym
)
3673 sec
= syms
[lo
- 1]->section
;
3675 for (; sec
!= NULL
; sec
= sec
->next
)
3679 /* SEC_LOAD may not be set if SEC is from a separate debug
3681 if ((sec
->flags
& SEC_ALLOC
) == 0)
3683 if ((sec
->flags
& SEC_CODE
) != 0)
3686 s
->flags
|= BSF_SYNTHETIC
;
3687 s
->value
= ent
- s
->section
->vma
;
3690 len
= strlen (syms
[i
]->name
);
3691 memcpy (names
, syms
[i
]->name
, len
+ 1);
3693 /* Have udata.p point back to the original symbol this
3694 synthetic symbol was derived from. */
3695 s
->udata
.p
= syms
[i
];
3701 if (glink
!= NULL
&& relplt
!= NULL
)
3705 /* Add a symbol for the main glink trampoline. */
3706 memset (s
, 0, sizeof *s
);
3708 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3710 s
->value
= resolv_vma
- glink
->vma
;
3712 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3713 names
+= sizeof ("__glink_PLTresolve");
3718 /* FIXME: It would be very much nicer to put sym@plt on the
3719 stub rather than on the glink branch table entry. The
3720 objdump disassembler would then use a sensible symbol
3721 name on plt calls. The difficulty in doing so is
3722 a) finding the stubs, and,
3723 b) matching stubs against plt entries, and,
3724 c) there can be multiple stubs for a given plt entry.
3726 Solving (a) could be done by code scanning, but older
3727 ppc64 binaries used different stubs to current code.
3728 (b) is the tricky one since you need to known the toc
3729 pointer for at least one function that uses a pic stub to
3730 be able to calculate the plt address referenced.
3731 (c) means gdb would need to set multiple breakpoints (or
3732 find the glink branch itself) when setting breakpoints
3733 for pending shared library loads. */
3734 p
= relplt
->relocation
;
3735 for (i
= 0; i
< plt_count
; i
++, p
++)
3739 *s
= **p
->sym_ptr_ptr
;
3740 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3741 we are defining a symbol, ensure one of them is set. */
3742 if ((s
->flags
& BSF_LOCAL
) == 0)
3743 s
->flags
|= BSF_GLOBAL
;
3744 s
->flags
|= BSF_SYNTHETIC
;
3746 s
->value
= glink_vma
- glink
->vma
;
3749 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3750 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3754 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3755 names
+= sizeof ("+0x") - 1;
3756 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3757 names
+= strlen (names
);
3759 memcpy (names
, "@plt", sizeof ("@plt"));
3760 names
+= sizeof ("@plt");
3780 /* The following functions are specific to the ELF linker, while
3781 functions above are used generally. Those named ppc64_elf_* are
3782 called by the main ELF linker code. They appear in this file more
3783 or less in the order in which they are called. eg.
3784 ppc64_elf_check_relocs is called early in the link process,
3785 ppc64_elf_finish_dynamic_sections is one of the last functions
3788 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3789 functions have both a function code symbol and a function descriptor
3790 symbol. A call to foo in a relocatable object file looks like:
3797 The function definition in another object file might be:
3801 . .quad .TOC.@tocbase
3807 When the linker resolves the call during a static link, the branch
3808 unsurprisingly just goes to .foo and the .opd information is unused.
3809 If the function definition is in a shared library, things are a little
3810 different: The call goes via a plt call stub, the opd information gets
3811 copied to the plt, and the linker patches the nop.
3819 . std 2,40(1) # in practice, the call stub
3820 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3821 . addi 11,11,Lfoo@toc@l # this is the general idea
3829 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3831 The "reloc ()" notation is supposed to indicate that the linker emits
3832 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3835 What are the difficulties here? Well, firstly, the relocations
3836 examined by the linker in check_relocs are against the function code
3837 sym .foo, while the dynamic relocation in the plt is emitted against
3838 the function descriptor symbol, foo. Somewhere along the line, we need
3839 to carefully copy dynamic link information from one symbol to the other.
3840 Secondly, the generic part of the elf linker will make .foo a dynamic
3841 symbol as is normal for most other backends. We need foo dynamic
3842 instead, at least for an application final link. However, when
3843 creating a shared library containing foo, we need to have both symbols
3844 dynamic so that references to .foo are satisfied during the early
3845 stages of linking. Otherwise the linker might decide to pull in a
3846 definition from some other object, eg. a static library.
3848 Update: As of August 2004, we support a new convention. Function
3849 calls may use the function descriptor symbol, ie. "bl foo". This
3850 behaves exactly as "bl .foo". */
3852 /* Of those relocs that might be copied as dynamic relocs, this
3853 function selects those that must be copied when linking a shared
3854 library or PIE, even when the symbol is local. */
3857 must_be_dyn_reloc (struct bfd_link_info
*info
,
3858 enum elf_ppc64_reloc_type r_type
)
3863 /* Only relative relocs can be resolved when the object load
3864 address isn't fixed. DTPREL64 is excluded because the
3865 dynamic linker needs to differentiate global dynamic from
3866 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
3874 case R_PPC64_TPREL16
:
3875 case R_PPC64_TPREL16_LO
:
3876 case R_PPC64_TPREL16_HI
:
3877 case R_PPC64_TPREL16_HA
:
3878 case R_PPC64_TPREL16_DS
:
3879 case R_PPC64_TPREL16_LO_DS
:
3880 case R_PPC64_TPREL16_HIGH
:
3881 case R_PPC64_TPREL16_HIGHA
:
3882 case R_PPC64_TPREL16_HIGHER
:
3883 case R_PPC64_TPREL16_HIGHERA
:
3884 case R_PPC64_TPREL16_HIGHEST
:
3885 case R_PPC64_TPREL16_HIGHESTA
:
3886 case R_PPC64_TPREL64
:
3887 /* These relocations are relative but in a shared library the
3888 linker doesn't know the thread pointer base. */
3889 return bfd_link_dll (info
);
3893 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3894 copying dynamic variables from a shared lib into an app's dynbss
3895 section, and instead use a dynamic relocation to point into the
3896 shared lib. With code that gcc generates, it's vital that this be
3897 enabled; In the PowerPC64 ABI, the address of a function is actually
3898 the address of a function descriptor, which resides in the .opd
3899 section. gcc uses the descriptor directly rather than going via the
3900 GOT as some other ABI's do, which means that initialized function
3901 pointers must reference the descriptor. Thus, a function pointer
3902 initialized to the address of a function in a shared library will
3903 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3904 redefines the function descriptor symbol to point to the copy. This
3905 presents a problem as a plt entry for that function is also
3906 initialized from the function descriptor symbol and the copy reloc
3907 may not be initialized first. */
3908 #define ELIMINATE_COPY_RELOCS 1
3910 /* Section name for stubs is the associated section name plus this
3912 #define STUB_SUFFIX ".stub"
3915 ppc_stub_long_branch:
3916 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3917 destination, but a 24 bit branch in a stub section will reach.
3920 ppc_stub_plt_branch:
3921 Similar to the above, but a 24 bit branch in the stub section won't
3922 reach its destination.
3923 . addis %r11,%r2,xxx@toc@ha
3924 . ld %r12,xxx@toc@l(%r11)
3929 Used to call a function in a shared library. If it so happens that
3930 the plt entry referenced crosses a 64k boundary, then an extra
3931 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3933 . addis %r11,%r2,xxx@toc@ha
3934 . ld %r12,xxx+0@toc@l(%r11)
3936 . ld %r2,xxx+8@toc@l(%r11)
3937 . ld %r11,xxx+16@toc@l(%r11)
3940 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3941 code to adjust the value and save r2 to support multiple toc sections.
3942 A ppc_stub_long_branch with an r2 offset looks like:
3944 . addis %r2,%r2,off@ha
3945 . addi %r2,%r2,off@l
3948 A ppc_stub_plt_branch with an r2 offset looks like:
3950 . addis %r11,%r2,xxx@toc@ha
3951 . ld %r12,xxx@toc@l(%r11)
3952 . addis %r2,%r2,off@ha
3953 . addi %r2,%r2,off@l
3957 In cases where the "addis" instruction would add zero, the "addis" is
3958 omitted and following instructions modified slightly in some cases.
3961 enum ppc_stub_type
{
3963 ppc_stub_long_branch
,
3964 ppc_stub_long_branch_r2off
,
3965 ppc_stub_plt_branch
,
3966 ppc_stub_plt_branch_r2off
,
3968 ppc_stub_plt_call_r2save
,
3969 ppc_stub_global_entry
,
3973 /* Information on stub grouping. */
3976 /* The stub section. */
3978 /* This is the section to which stubs in the group will be attached. */
3981 struct map_stub
*next
;
3982 /* Whether to emit a copy of register save/restore functions in this
3985 /* The offset of the __tls_get_addr_opt plt stub bctrl in this group,
3986 or -1u if no such stub with bctrl exists. */
3987 unsigned int tls_get_addr_opt_bctrl
;
3990 struct ppc_stub_hash_entry
{
3992 /* Base hash table entry structure. */
3993 struct bfd_hash_entry root
;
3995 enum ppc_stub_type stub_type
;
3997 /* Group information. */
3998 struct map_stub
*group
;
4000 /* Offset within stub_sec of the beginning of this stub. */
4001 bfd_vma stub_offset
;
4003 /* Given the symbol's value and its section we can determine its final
4004 value when building the stubs (so the stub knows where to jump. */
4005 bfd_vma target_value
;
4006 asection
*target_section
;
4008 /* The symbol table entry, if any, that this was derived from. */
4009 struct ppc_link_hash_entry
*h
;
4010 struct plt_entry
*plt_ent
;
4013 unsigned char symtype
;
4015 /* Symbol st_other. */
4016 unsigned char other
;
4019 struct ppc_branch_hash_entry
{
4021 /* Base hash table entry structure. */
4022 struct bfd_hash_entry root
;
4024 /* Offset within branch lookup table. */
4025 unsigned int offset
;
4027 /* Generation marker. */
4031 /* Used to track dynamic relocations for local symbols. */
4032 struct ppc_dyn_relocs
4034 struct ppc_dyn_relocs
*next
;
4036 /* The input section of the reloc. */
4039 /* Total number of relocs copied for the input section. */
4040 unsigned int count
: 31;
4042 /* Whether this entry is for STT_GNU_IFUNC symbols. */
4043 unsigned int ifunc
: 1;
4046 struct ppc_link_hash_entry
4048 struct elf_link_hash_entry elf
;
4051 /* A pointer to the most recently used stub hash entry against this
4053 struct ppc_stub_hash_entry
*stub_cache
;
4055 /* A pointer to the next symbol starting with a '.' */
4056 struct ppc_link_hash_entry
*next_dot_sym
;
4059 /* Track dynamic relocs copied for this symbol. */
4060 struct elf_dyn_relocs
*dyn_relocs
;
4062 /* Link between function code and descriptor symbols. */
4063 struct ppc_link_hash_entry
*oh
;
4065 /* Flag function code and descriptor symbols. */
4066 unsigned int is_func
:1;
4067 unsigned int is_func_descriptor
:1;
4068 unsigned int fake
:1;
4070 /* Whether global opd/toc sym has been adjusted or not.
4071 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
4072 should be set for all globals defined in any opd/toc section. */
4073 unsigned int adjust_done
:1;
4075 /* Set if this is an out-of-line register save/restore function,
4076 with non-standard calling convention. */
4077 unsigned int save_res
:1;
4079 /* Set if a duplicate symbol with non-zero localentry is detected,
4080 even when the duplicate symbol does not provide a definition. */
4081 unsigned int non_zero_localentry
:1;
4083 /* Contexts in which symbol is used in the GOT (or TOC).
4084 Bits are or'd into the mask as the corresponding relocs are
4085 encountered during check_relocs, with TLS_TLS being set when any
4086 of the other TLS bits are set. tls_optimize clears bits when
4087 optimizing to indicate the corresponding GOT entry type is not
4088 needed. If set, TLS_TLS is never cleared. tls_optimize may also
4089 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
4090 separate flag rather than setting TPREL just for convenience in
4091 distinguishing the two cases.
4092 These flags are also kept for local symbols. */
4093 #define TLS_TLS 1 /* Any TLS reloc. */
4094 #define TLS_GD 2 /* GD reloc. */
4095 #define TLS_LD 4 /* LD reloc. */
4096 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
4097 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
4098 #define TLS_MARK 32 /* __tls_get_addr call marked. */
4099 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
4100 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
4101 unsigned char tls_mask
;
4103 /* The above field is also used to mark function symbols. In which
4104 case TLS_TLS will be 0. */
4105 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
4106 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
4107 #define NON_GOT 256 /* local symbol plt, not stored. */
4110 /* ppc64 ELF linker hash table. */
4112 struct ppc_link_hash_table
4114 struct elf_link_hash_table elf
;
4116 /* The stub hash table. */
4117 struct bfd_hash_table stub_hash_table
;
4119 /* Another hash table for plt_branch stubs. */
4120 struct bfd_hash_table branch_hash_table
;
4122 /* Hash table for function prologue tocsave. */
4123 htab_t tocsave_htab
;
4125 /* Various options and other info passed from the linker. */
4126 struct ppc64_elf_params
*params
;
4128 /* The size of sec_info below. */
4129 unsigned int sec_info_arr_size
;
4131 /* Per-section array of extra section info. Done this way rather
4132 than as part of ppc64_elf_section_data so we have the info for
4133 non-ppc64 sections. */
4136 /* Along with elf_gp, specifies the TOC pointer used by this section. */
4141 /* The section group that this section belongs to. */
4142 struct map_stub
*group
;
4143 /* A temp section list pointer. */
4148 /* Linked list of groups. */
4149 struct map_stub
*group
;
4151 /* Temp used when calculating TOC pointers. */
4154 asection
*toc_first_sec
;
4156 /* Used when adding symbols. */
4157 struct ppc_link_hash_entry
*dot_syms
;
4159 /* Shortcuts to get to dynamic linker sections. */
4161 asection
*global_entry
;
4164 asection
*relpltlocal
;
4167 asection
*glink_eh_frame
;
4169 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
4170 struct ppc_link_hash_entry
*tls_get_addr
;
4171 struct ppc_link_hash_entry
*tls_get_addr_fd
;
4173 /* The size of reliplt used by got entry relocs. */
4174 bfd_size_type got_reli_size
;
4177 unsigned long stub_count
[ppc_stub_global_entry
];
4179 /* Number of stubs against global syms. */
4180 unsigned long stub_globals
;
4182 /* Set if we're linking code with function descriptors. */
4183 unsigned int opd_abi
:1;
4185 /* Support for multiple toc sections. */
4186 unsigned int do_multi_toc
:1;
4187 unsigned int multi_toc_needed
:1;
4188 unsigned int second_toc_pass
:1;
4189 unsigned int do_toc_opt
:1;
4191 /* Set if tls optimization is enabled. */
4192 unsigned int do_tls_opt
:1;
4195 unsigned int stub_error
:1;
4197 /* Whether func_desc_adjust needs to be run over symbols. */
4198 unsigned int need_func_desc_adj
:1;
4200 /* Whether there exist local gnu indirect function resolvers,
4201 referenced by dynamic relocations. */
4202 unsigned int local_ifunc_resolver
:1;
4203 unsigned int maybe_local_ifunc_resolver
:1;
4205 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
4206 unsigned int has_plt_localentry0
:1;
4208 /* Incremented every time we size stubs. */
4209 unsigned int stub_iteration
;
4211 /* Small local sym cache. */
4212 struct sym_cache sym_cache
;
4215 /* Rename some of the generic section flags to better document how they
4218 /* Nonzero if this section has TLS related relocations. */
4219 #define has_tls_reloc sec_flg0
4221 /* Nonzero if this section has an old-style call to __tls_get_addr. */
4222 #define has_tls_get_addr_call sec_flg1
4224 /* Nonzero if this section has any toc or got relocs. */
4225 #define has_toc_reloc sec_flg2
4227 /* Nonzero if this section has a call to another section that uses
4229 #define makes_toc_func_call sec_flg3
4231 /* Recursion protection when determining above flag. */
4232 #define call_check_in_progress sec_flg4
4233 #define call_check_done sec_flg5
4235 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4237 #define ppc_hash_table(p) \
4238 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4239 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4241 #define ppc_stub_hash_lookup(table, string, create, copy) \
4242 ((struct ppc_stub_hash_entry *) \
4243 bfd_hash_lookup ((table), (string), (create), (copy)))
4245 #define ppc_branch_hash_lookup(table, string, create, copy) \
4246 ((struct ppc_branch_hash_entry *) \
4247 bfd_hash_lookup ((table), (string), (create), (copy)))
4249 /* Create an entry in the stub hash table. */
4251 static struct bfd_hash_entry
*
4252 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
4253 struct bfd_hash_table
*table
,
4256 /* Allocate the structure if it has not already been allocated by a
4260 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
4265 /* Call the allocation method of the superclass. */
4266 entry
= bfd_hash_newfunc (entry
, table
, string
);
4269 struct ppc_stub_hash_entry
*eh
;
4271 /* Initialize the local fields. */
4272 eh
= (struct ppc_stub_hash_entry
*) entry
;
4273 eh
->stub_type
= ppc_stub_none
;
4275 eh
->stub_offset
= 0;
4276 eh
->target_value
= 0;
4277 eh
->target_section
= NULL
;
4286 /* Create an entry in the branch hash table. */
4288 static struct bfd_hash_entry
*
4289 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
4290 struct bfd_hash_table
*table
,
4293 /* Allocate the structure if it has not already been allocated by a
4297 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
4302 /* Call the allocation method of the superclass. */
4303 entry
= bfd_hash_newfunc (entry
, table
, string
);
4306 struct ppc_branch_hash_entry
*eh
;
4308 /* Initialize the local fields. */
4309 eh
= (struct ppc_branch_hash_entry
*) entry
;
4317 /* Create an entry in a ppc64 ELF linker hash table. */
4319 static struct bfd_hash_entry
*
4320 link_hash_newfunc (struct bfd_hash_entry
*entry
,
4321 struct bfd_hash_table
*table
,
4324 /* Allocate the structure if it has not already been allocated by a
4328 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
4333 /* Call the allocation method of the superclass. */
4334 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
4337 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
4339 memset (&eh
->u
.stub_cache
, 0,
4340 (sizeof (struct ppc_link_hash_entry
)
4341 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
4343 /* When making function calls, old ABI code references function entry
4344 points (dot symbols), while new ABI code references the function
4345 descriptor symbol. We need to make any combination of reference and
4346 definition work together, without breaking archive linking.
4348 For a defined function "foo" and an undefined call to "bar":
4349 An old object defines "foo" and ".foo", references ".bar" (possibly
4351 A new object defines "foo" and references "bar".
4353 A new object thus has no problem with its undefined symbols being
4354 satisfied by definitions in an old object. On the other hand, the
4355 old object won't have ".bar" satisfied by a new object.
4357 Keep a list of newly added dot-symbols. */
4359 if (string
[0] == '.')
4361 struct ppc_link_hash_table
*htab
;
4363 htab
= (struct ppc_link_hash_table
*) table
;
4364 eh
->u
.next_dot_sym
= htab
->dot_syms
;
4365 htab
->dot_syms
= eh
;
4372 struct tocsave_entry
{
4378 tocsave_htab_hash (const void *p
)
4380 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
4381 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
4385 tocsave_htab_eq (const void *p1
, const void *p2
)
4387 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
4388 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
4389 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
4392 /* Destroy a ppc64 ELF linker hash table. */
4395 ppc64_elf_link_hash_table_free (bfd
*obfd
)
4397 struct ppc_link_hash_table
*htab
;
4399 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
4400 if (htab
->tocsave_htab
)
4401 htab_delete (htab
->tocsave_htab
);
4402 bfd_hash_table_free (&htab
->branch_hash_table
);
4403 bfd_hash_table_free (&htab
->stub_hash_table
);
4404 _bfd_elf_link_hash_table_free (obfd
);
4407 /* Create a ppc64 ELF linker hash table. */
4409 static struct bfd_link_hash_table
*
4410 ppc64_elf_link_hash_table_create (bfd
*abfd
)
4412 struct ppc_link_hash_table
*htab
;
4413 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
4415 htab
= bfd_zmalloc (amt
);
4419 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
4420 sizeof (struct ppc_link_hash_entry
),
4427 /* Init the stub hash table too. */
4428 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
4429 sizeof (struct ppc_stub_hash_entry
)))
4431 _bfd_elf_link_hash_table_free (abfd
);
4435 /* And the branch hash table. */
4436 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
4437 sizeof (struct ppc_branch_hash_entry
)))
4439 bfd_hash_table_free (&htab
->stub_hash_table
);
4440 _bfd_elf_link_hash_table_free (abfd
);
4444 htab
->tocsave_htab
= htab_try_create (1024,
4448 if (htab
->tocsave_htab
== NULL
)
4450 ppc64_elf_link_hash_table_free (abfd
);
4453 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
4455 /* Initializing two fields of the union is just cosmetic. We really
4456 only care about glist, but when compiled on a 32-bit host the
4457 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4458 debugger inspection of these fields look nicer. */
4459 htab
->elf
.init_got_refcount
.refcount
= 0;
4460 htab
->elf
.init_got_refcount
.glist
= NULL
;
4461 htab
->elf
.init_plt_refcount
.refcount
= 0;
4462 htab
->elf
.init_plt_refcount
.glist
= NULL
;
4463 htab
->elf
.init_got_offset
.offset
= 0;
4464 htab
->elf
.init_got_offset
.glist
= NULL
;
4465 htab
->elf
.init_plt_offset
.offset
= 0;
4466 htab
->elf
.init_plt_offset
.glist
= NULL
;
4468 return &htab
->elf
.root
;
4471 /* Create sections for linker generated code. */
4474 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4476 struct ppc_link_hash_table
*htab
;
4479 htab
= ppc_hash_table (info
);
4481 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4482 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4483 if (htab
->params
->save_restore_funcs
)
4485 /* Create .sfpr for code to save and restore fp regs. */
4486 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4488 if (htab
->sfpr
== NULL
4489 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4493 if (bfd_link_relocatable (info
))
4496 /* Create .glink for lazy dynamic linking support. */
4497 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4499 if (htab
->glink
== NULL
4500 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4503 /* The part of .glink used by global entry stubs, separate so that
4504 it can be aligned appropriately without affecting htab->glink. */
4505 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4507 if (htab
->global_entry
== NULL
4508 || ! bfd_set_section_alignment (dynobj
, htab
->global_entry
, 2))
4511 if (!info
->no_ld_generated_unwind_info
)
4513 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4514 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4515 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4518 if (htab
->glink_eh_frame
== NULL
4519 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
4523 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4524 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4525 if (htab
->elf
.iplt
== NULL
4526 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
4529 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4530 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4532 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
4533 if (htab
->elf
.irelplt
== NULL
4534 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
4537 /* Create branch lookup table for plt_branch stubs. */
4538 flags
= (SEC_ALLOC
| SEC_LOAD
4539 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4540 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4542 if (htab
->brlt
== NULL
4543 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4546 /* Local plt entries, put in .branch_lt but a separate section for
4548 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4550 if (htab
->pltlocal
== NULL
4551 || ! bfd_set_section_alignment (dynobj
, htab
->pltlocal
, 3))
4554 if (!bfd_link_pic (info
))
4557 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4558 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4560 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
4561 if (htab
->relbrlt
== NULL
4562 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4566 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
4567 if (htab
->relpltlocal
== NULL
4568 || ! bfd_set_section_alignment (dynobj
, htab
->relpltlocal
, 3))
4574 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4577 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
4578 struct ppc64_elf_params
*params
)
4580 struct ppc_link_hash_table
*htab
;
4582 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
4584 /* Always hook our dynamic sections into the first bfd, which is the
4585 linker created stub bfd. This ensures that the GOT header is at
4586 the start of the output TOC section. */
4587 htab
= ppc_hash_table (info
);
4588 htab
->elf
.dynobj
= params
->stub_bfd
;
4589 htab
->params
= params
;
4591 return create_linkage_sections (htab
->elf
.dynobj
, info
);
4594 /* Build a name for an entry in the stub hash table. */
4597 ppc_stub_name (const asection
*input_section
,
4598 const asection
*sym_sec
,
4599 const struct ppc_link_hash_entry
*h
,
4600 const Elf_Internal_Rela
*rel
)
4605 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4606 offsets from a sym as a branch target? In fact, we could
4607 probably assume the addend is always zero. */
4608 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4612 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4613 stub_name
= bfd_malloc (len
);
4614 if (stub_name
== NULL
)
4617 len
= sprintf (stub_name
, "%08x.%s+%x",
4618 input_section
->id
& 0xffffffff,
4619 h
->elf
.root
.root
.string
,
4620 (int) rel
->r_addend
& 0xffffffff);
4624 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4625 stub_name
= bfd_malloc (len
);
4626 if (stub_name
== NULL
)
4629 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
4630 input_section
->id
& 0xffffffff,
4631 sym_sec
->id
& 0xffffffff,
4632 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4633 (int) rel
->r_addend
& 0xffffffff);
4635 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4636 stub_name
[len
- 2] = 0;
4640 /* Look up an entry in the stub hash. Stub entries are cached because
4641 creating the stub name takes a bit of time. */
4643 static struct ppc_stub_hash_entry
*
4644 ppc_get_stub_entry (const asection
*input_section
,
4645 const asection
*sym_sec
,
4646 struct ppc_link_hash_entry
*h
,
4647 const Elf_Internal_Rela
*rel
,
4648 struct ppc_link_hash_table
*htab
)
4650 struct ppc_stub_hash_entry
*stub_entry
;
4651 struct map_stub
*group
;
4653 /* If this input section is part of a group of sections sharing one
4654 stub section, then use the id of the first section in the group.
4655 Stub names need to include a section id, as there may well be
4656 more than one stub used to reach say, printf, and we need to
4657 distinguish between them. */
4658 group
= htab
->sec_info
[input_section
->id
].u
.group
;
4662 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4663 && h
->u
.stub_cache
->h
== h
4664 && h
->u
.stub_cache
->group
== group
)
4666 stub_entry
= h
->u
.stub_cache
;
4672 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
4673 if (stub_name
== NULL
)
4676 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4677 stub_name
, FALSE
, FALSE
);
4679 h
->u
.stub_cache
= stub_entry
;
4687 /* Add a new stub entry to the stub hash. Not all fields of the new
4688 stub entry are initialised. */
4690 static struct ppc_stub_hash_entry
*
4691 ppc_add_stub (const char *stub_name
,
4693 struct bfd_link_info
*info
)
4695 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4696 struct map_stub
*group
;
4699 struct ppc_stub_hash_entry
*stub_entry
;
4701 group
= htab
->sec_info
[section
->id
].u
.group
;
4702 link_sec
= group
->link_sec
;
4703 stub_sec
= group
->stub_sec
;
4704 if (stub_sec
== NULL
)
4710 namelen
= strlen (link_sec
->name
);
4711 len
= namelen
+ sizeof (STUB_SUFFIX
);
4712 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
4716 memcpy (s_name
, link_sec
->name
, namelen
);
4717 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4718 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
4719 if (stub_sec
== NULL
)
4721 group
->stub_sec
= stub_sec
;
4724 /* Enter this entry into the linker stub hash table. */
4725 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4727 if (stub_entry
== NULL
)
4729 /* xgettext:c-format */
4730 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
4731 section
->owner
, stub_name
);
4735 stub_entry
->group
= group
;
4736 stub_entry
->stub_offset
= 0;
4740 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4741 not already done. */
4744 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4746 asection
*got
, *relgot
;
4748 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4750 if (!is_ppc64_elf (abfd
))
4756 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4759 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4760 | SEC_LINKER_CREATED
);
4762 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4764 || !bfd_set_section_alignment (abfd
, got
, 3))
4767 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4768 flags
| SEC_READONLY
);
4770 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4773 ppc64_elf_tdata (abfd
)->got
= got
;
4774 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4778 /* Follow indirect and warning symbol links. */
4780 static inline struct bfd_link_hash_entry
*
4781 follow_link (struct bfd_link_hash_entry
*h
)
4783 while (h
->type
== bfd_link_hash_indirect
4784 || h
->type
== bfd_link_hash_warning
)
4789 static inline struct elf_link_hash_entry
*
4790 elf_follow_link (struct elf_link_hash_entry
*h
)
4792 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4795 static inline struct ppc_link_hash_entry
*
4796 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4798 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4801 /* Merge PLT info on FROM with that on TO. */
4804 move_plt_plist (struct ppc_link_hash_entry
*from
,
4805 struct ppc_link_hash_entry
*to
)
4807 if (from
->elf
.plt
.plist
!= NULL
)
4809 if (to
->elf
.plt
.plist
!= NULL
)
4811 struct plt_entry
**entp
;
4812 struct plt_entry
*ent
;
4814 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4816 struct plt_entry
*dent
;
4818 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4819 if (dent
->addend
== ent
->addend
)
4821 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4828 *entp
= to
->elf
.plt
.plist
;
4831 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4832 from
->elf
.plt
.plist
= NULL
;
4836 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4839 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4840 struct elf_link_hash_entry
*dir
,
4841 struct elf_link_hash_entry
*ind
)
4843 struct ppc_link_hash_entry
*edir
, *eind
;
4845 edir
= (struct ppc_link_hash_entry
*) dir
;
4846 eind
= (struct ppc_link_hash_entry
*) ind
;
4848 edir
->is_func
|= eind
->is_func
;
4849 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4850 edir
->tls_mask
|= eind
->tls_mask
;
4851 if (eind
->oh
!= NULL
)
4852 edir
->oh
= ppc_follow_link (eind
->oh
);
4854 if (edir
->elf
.versioned
!= versioned_hidden
)
4855 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4856 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4857 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4858 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4859 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4860 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4862 /* If we were called to copy over info for a weak sym, don't copy
4863 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4864 in order to simplify readonly_dynrelocs and save a field in the
4865 symbol hash entry, but that means dyn_relocs can't be used in any
4866 tests about a specific symbol, or affect other symbol flags which
4868 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4871 /* Copy over any dynamic relocs we may have on the indirect sym. */
4872 if (eind
->dyn_relocs
!= NULL
)
4874 if (edir
->dyn_relocs
!= NULL
)
4876 struct elf_dyn_relocs
**pp
;
4877 struct elf_dyn_relocs
*p
;
4879 /* Add reloc counts against the indirect sym to the direct sym
4880 list. Merge any entries against the same section. */
4881 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4883 struct elf_dyn_relocs
*q
;
4885 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4886 if (q
->sec
== p
->sec
)
4888 q
->pc_count
+= p
->pc_count
;
4889 q
->count
+= p
->count
;
4896 *pp
= edir
->dyn_relocs
;
4899 edir
->dyn_relocs
= eind
->dyn_relocs
;
4900 eind
->dyn_relocs
= NULL
;
4903 /* Copy over got entries that we may have already seen to the
4904 symbol which just became indirect. */
4905 if (eind
->elf
.got
.glist
!= NULL
)
4907 if (edir
->elf
.got
.glist
!= NULL
)
4909 struct got_entry
**entp
;
4910 struct got_entry
*ent
;
4912 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4914 struct got_entry
*dent
;
4916 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4917 if (dent
->addend
== ent
->addend
4918 && dent
->owner
== ent
->owner
4919 && dent
->tls_type
== ent
->tls_type
)
4921 dent
->got
.refcount
+= ent
->got
.refcount
;
4928 *entp
= edir
->elf
.got
.glist
;
4931 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4932 eind
->elf
.got
.glist
= NULL
;
4935 /* And plt entries. */
4936 move_plt_plist (eind
, edir
);
4938 if (eind
->elf
.dynindx
!= -1)
4940 if (edir
->elf
.dynindx
!= -1)
4941 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4942 edir
->elf
.dynstr_index
);
4943 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4944 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4945 eind
->elf
.dynindx
= -1;
4946 eind
->elf
.dynstr_index
= 0;
4950 /* Find the function descriptor hash entry from the given function code
4951 hash entry FH. Link the entries via their OH fields. */
4953 static struct ppc_link_hash_entry
*
4954 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4956 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4960 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4962 fdh
= (struct ppc_link_hash_entry
*)
4963 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4967 fdh
->is_func_descriptor
= 1;
4973 fdh
= ppc_follow_link (fdh
);
4974 fdh
->is_func_descriptor
= 1;
4979 /* Make a fake function descriptor sym for the undefined code sym FH. */
4981 static struct ppc_link_hash_entry
*
4982 make_fdh (struct bfd_link_info
*info
,
4983 struct ppc_link_hash_entry
*fh
)
4985 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4986 struct bfd_link_hash_entry
*bh
= NULL
;
4987 struct ppc_link_hash_entry
*fdh
;
4988 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4992 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4993 fh
->elf
.root
.root
.string
+ 1,
4994 flags
, bfd_und_section_ptr
, 0,
4995 NULL
, FALSE
, FALSE
, &bh
))
4998 fdh
= (struct ppc_link_hash_entry
*) bh
;
4999 fdh
->elf
.non_elf
= 0;
5001 fdh
->is_func_descriptor
= 1;
5008 /* Fix function descriptor symbols defined in .opd sections to be
5012 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
5013 struct bfd_link_info
*info
,
5014 Elf_Internal_Sym
*isym
,
5016 flagword
*flags ATTRIBUTE_UNUSED
,
5020 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
5021 && (ibfd
->flags
& DYNAMIC
) == 0
5022 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
5023 elf_tdata (info
->output_bfd
)->has_gnu_symbols
|= elf_gnu_symbol_ifunc
;
5026 && strcmp ((*sec
)->name
, ".opd") == 0)
5030 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
5031 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
5032 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
5034 /* If the symbol is a function defined in .opd, and the function
5035 code is in a discarded group, let it appear to be undefined. */
5036 if (!bfd_link_relocatable (info
)
5037 && (*sec
)->reloc_count
!= 0
5038 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
5039 FALSE
) != (bfd_vma
) -1
5040 && discarded_section (code_sec
))
5042 *sec
= bfd_und_section_ptr
;
5043 isym
->st_shndx
= SHN_UNDEF
;
5046 else if (*sec
!= NULL
5047 && strcmp ((*sec
)->name
, ".toc") == 0
5048 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
5050 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5052 htab
->params
->object_in_toc
= 1;
5055 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
5057 if (abiversion (ibfd
) == 0)
5058 set_abiversion (ibfd
, 2);
5059 else if (abiversion (ibfd
) == 1)
5061 _bfd_error_handler (_("symbol '%s' has invalid st_other"
5062 " for ABI version 1"), *name
);
5063 bfd_set_error (bfd_error_bad_value
);
5071 /* Merge non-visibility st_other attributes: local entry point. */
5074 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
5075 const Elf_Internal_Sym
*isym
,
5076 bfd_boolean definition
,
5077 bfd_boolean dynamic
)
5079 if (definition
&& (!dynamic
|| !h
->def_regular
))
5080 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
5081 | ELF_ST_VISIBILITY (h
->other
));
5084 /* Hook called on merging a symbol. We use this to clear "fake" since
5085 we now have a real symbol. */
5088 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
5089 const Elf_Internal_Sym
*isym
,
5090 asection
**psec ATTRIBUTE_UNUSED
,
5091 bfd_boolean newdef ATTRIBUTE_UNUSED
,
5092 bfd_boolean olddef ATTRIBUTE_UNUSED
,
5093 bfd
*oldbfd ATTRIBUTE_UNUSED
,
5094 const asection
*oldsec ATTRIBUTE_UNUSED
)
5096 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
5097 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
5098 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
5102 /* This function makes an old ABI object reference to ".bar" cause the
5103 inclusion of a new ABI object archive that defines "bar".
5104 NAME is a symbol defined in an archive. Return a symbol in the hash
5105 table that might be satisfied by the archive symbols. */
5107 static struct elf_link_hash_entry
*
5108 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
5109 struct bfd_link_info
*info
,
5112 struct elf_link_hash_entry
*h
;
5116 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
5118 /* Don't return this sym if it is a fake function descriptor
5119 created by add_symbol_adjust. */
5120 && !((struct ppc_link_hash_entry
*) h
)->fake
)
5126 len
= strlen (name
);
5127 dot_name
= bfd_alloc (abfd
, len
+ 2);
5128 if (dot_name
== NULL
)
5129 return (struct elf_link_hash_entry
*) -1;
5131 memcpy (dot_name
+ 1, name
, len
+ 1);
5132 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
5133 bfd_release (abfd
, dot_name
);
5137 /* This function satisfies all old ABI object references to ".bar" if a
5138 new ABI object defines "bar". Well, at least, undefined dot symbols
5139 are made weak. This stops later archive searches from including an
5140 object if we already have a function descriptor definition. It also
5141 prevents the linker complaining about undefined symbols.
5142 We also check and correct mismatched symbol visibility here. The
5143 most restrictive visibility of the function descriptor and the
5144 function entry symbol is used. */
5147 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
5149 struct ppc_link_hash_table
*htab
;
5150 struct ppc_link_hash_entry
*fdh
;
5152 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5153 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5155 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
5158 if (eh
->elf
.root
.root
.string
[0] != '.')
5161 htab
= ppc_hash_table (info
);
5165 fdh
= lookup_fdh (eh
, htab
);
5167 && !bfd_link_relocatable (info
)
5168 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
5169 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5170 && eh
->elf
.ref_regular
)
5172 /* Make an undefined function descriptor sym, in order to
5173 pull in an --as-needed shared lib. Archives are handled
5175 fdh
= make_fdh (info
, eh
);
5182 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
5183 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
5185 /* Make both descriptor and entry symbol have the most
5186 constraining visibility of either symbol. */
5187 if (entry_vis
< descr_vis
)
5188 fdh
->elf
.other
+= entry_vis
- descr_vis
;
5189 else if (entry_vis
> descr_vis
)
5190 eh
->elf
.other
+= descr_vis
- entry_vis
;
5192 /* Propagate reference flags from entry symbol to function
5193 descriptor symbol. */
5194 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
5195 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
5196 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
5197 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
5199 if (!fdh
->elf
.forced_local
5200 && fdh
->elf
.dynindx
== -1
5201 && fdh
->elf
.versioned
!= versioned_hidden
5202 && (bfd_link_dll (info
)
5203 || fdh
->elf
.def_dynamic
5204 || fdh
->elf
.ref_dynamic
)
5205 && (eh
->elf
.ref_regular
5206 || eh
->elf
.def_regular
))
5208 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5216 /* Set up opd section info and abiversion for IBFD, and process list
5217 of dot-symbols we made in link_hash_newfunc. */
5220 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
5222 struct ppc_link_hash_table
*htab
;
5223 struct ppc_link_hash_entry
**p
, *eh
;
5224 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
5226 if (opd
!= NULL
&& opd
->size
!= 0)
5228 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
5229 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
5231 if (abiversion (ibfd
) == 0)
5232 set_abiversion (ibfd
, 1);
5233 else if (abiversion (ibfd
) >= 2)
5235 /* xgettext:c-format */
5236 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
5237 ibfd
, abiversion (ibfd
));
5238 bfd_set_error (bfd_error_bad_value
);
5243 if (is_ppc64_elf (info
->output_bfd
))
5245 /* For input files without an explicit abiversion in e_flags
5246 we should have flagged any with symbol st_other bits set
5247 as ELFv1 and above flagged those with .opd as ELFv2.
5248 Set the output abiversion if not yet set, and for any input
5249 still ambiguous, take its abiversion from the output.
5250 Differences in ABI are reported later. */
5251 if (abiversion (info
->output_bfd
) == 0)
5252 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
5253 else if (abiversion (ibfd
) == 0)
5254 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
5257 htab
= ppc_hash_table (info
);
5261 if (opd
!= NULL
&& opd
->size
!= 0
5262 && (ibfd
->flags
& DYNAMIC
) == 0
5263 && (opd
->flags
& SEC_RELOC
) != 0
5264 && opd
->reloc_count
!= 0
5265 && !bfd_is_abs_section (opd
->output_section
)
5266 && info
->gc_sections
)
5268 /* Garbage collection needs some extra help with .opd sections.
5269 We don't want to necessarily keep everything referenced by
5270 relocs in .opd, as that would keep all functions. Instead,
5271 if we reference an .opd symbol (a function descriptor), we
5272 want to keep the function code symbol's section. This is
5273 easy for global symbols, but for local syms we need to keep
5274 information about the associated function section. */
5276 asection
**opd_sym_map
;
5277 Elf_Internal_Shdr
*symtab_hdr
;
5278 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
5280 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
5281 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
5282 if (opd_sym_map
== NULL
)
5284 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
5285 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
5289 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5290 rel_end
= relocs
+ opd
->reloc_count
- 1;
5291 for (rel
= relocs
; rel
< rel_end
; rel
++)
5293 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
5294 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
5296 if (r_type
== R_PPC64_ADDR64
5297 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
5298 && r_symndx
< symtab_hdr
->sh_info
)
5300 Elf_Internal_Sym
*isym
;
5303 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
5306 if (elf_section_data (opd
)->relocs
!= relocs
)
5311 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
5312 if (s
!= NULL
&& s
!= opd
)
5313 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
5316 if (elf_section_data (opd
)->relocs
!= relocs
)
5320 p
= &htab
->dot_syms
;
5321 while ((eh
= *p
) != NULL
)
5324 if (&eh
->elf
== htab
->elf
.hgot
)
5326 else if (htab
->elf
.hgot
== NULL
5327 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
5328 htab
->elf
.hgot
= &eh
->elf
;
5329 else if (abiversion (ibfd
) <= 1)
5331 htab
->need_func_desc_adj
= 1;
5332 if (!add_symbol_adjust (eh
, info
))
5335 p
= &eh
->u
.next_dot_sym
;
5340 /* Undo hash table changes when an --as-needed input file is determined
5341 not to be needed. */
5344 ppc64_elf_notice_as_needed (bfd
*ibfd
,
5345 struct bfd_link_info
*info
,
5346 enum notice_asneeded_action act
)
5348 if (act
== notice_not_needed
)
5350 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5355 htab
->dot_syms
= NULL
;
5357 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
5360 /* If --just-symbols against a final linked binary, then assume we need
5361 toc adjusting stubs when calling functions defined there. */
5364 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
5366 if ((sec
->flags
& SEC_CODE
) != 0
5367 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
5368 && is_ppc64_elf (sec
->owner
))
5370 if (abiversion (sec
->owner
) >= 2
5371 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
5372 sec
->has_toc_reloc
= 1;
5374 _bfd_elf_link_just_syms (sec
, info
);
5377 static struct plt_entry
**
5378 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
5379 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
5381 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
5382 struct plt_entry
**local_plt
;
5383 unsigned char *local_got_tls_masks
;
5385 if (local_got_ents
== NULL
)
5387 bfd_size_type size
= symtab_hdr
->sh_info
;
5389 size
*= (sizeof (*local_got_ents
)
5390 + sizeof (*local_plt
)
5391 + sizeof (*local_got_tls_masks
));
5392 local_got_ents
= bfd_zalloc (abfd
, size
);
5393 if (local_got_ents
== NULL
)
5395 elf_local_got_ents (abfd
) = local_got_ents
;
5398 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
5400 struct got_entry
*ent
;
5402 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
5403 if (ent
->addend
== r_addend
5404 && ent
->owner
== abfd
5405 && ent
->tls_type
== tls_type
)
5409 bfd_size_type amt
= sizeof (*ent
);
5410 ent
= bfd_alloc (abfd
, amt
);
5413 ent
->next
= local_got_ents
[r_symndx
];
5414 ent
->addend
= r_addend
;
5416 ent
->tls_type
= tls_type
;
5417 ent
->is_indirect
= FALSE
;
5418 ent
->got
.refcount
= 0;
5419 local_got_ents
[r_symndx
] = ent
;
5421 ent
->got
.refcount
+= 1;
5424 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
5425 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
5426 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
5428 return local_plt
+ r_symndx
;
5432 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
5434 struct plt_entry
*ent
;
5436 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
5437 if (ent
->addend
== addend
)
5441 bfd_size_type amt
= sizeof (*ent
);
5442 ent
= bfd_alloc (abfd
, amt
);
5446 ent
->addend
= addend
;
5447 ent
->plt
.refcount
= 0;
5450 ent
->plt
.refcount
+= 1;
5455 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
5457 return (r_type
== R_PPC64_REL24
5458 || r_type
== R_PPC64_REL14
5459 || r_type
== R_PPC64_REL14_BRTAKEN
5460 || r_type
== R_PPC64_REL14_BRNTAKEN
5461 || r_type
== R_PPC64_ADDR24
5462 || r_type
== R_PPC64_ADDR14
5463 || r_type
== R_PPC64_ADDR14_BRTAKEN
5464 || r_type
== R_PPC64_ADDR14_BRNTAKEN
5465 || r_type
== R_PPC64_PLTCALL
);
5468 /* Relocs on inline plt call sequence insns prior to the call. */
5471 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
5473 return (r_type
== R_PPC64_PLT16_HA
5474 || r_type
== R_PPC64_PLT16_HI
5475 || r_type
== R_PPC64_PLT16_LO
5476 || r_type
== R_PPC64_PLT16_LO_DS
5477 || r_type
== R_PPC64_PLTSEQ
);
5480 /* Look through the relocs for a section during the first phase, and
5481 calculate needed space in the global offset table, procedure
5482 linkage table, and dynamic reloc sections. */
5485 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5486 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5488 struct ppc_link_hash_table
*htab
;
5489 Elf_Internal_Shdr
*symtab_hdr
;
5490 struct elf_link_hash_entry
**sym_hashes
;
5491 const Elf_Internal_Rela
*rel
;
5492 const Elf_Internal_Rela
*rel_end
;
5494 struct elf_link_hash_entry
*tga
, *dottga
;
5497 if (bfd_link_relocatable (info
))
5500 /* Don't do anything special with non-loaded, non-alloced sections.
5501 In particular, any relocs in such sections should not affect GOT
5502 and PLT reference counting (ie. we don't allow them to create GOT
5503 or PLT entries), there's no possibility or desire to optimize TLS
5504 relocs, and there's not much point in propagating relocs to shared
5505 libs that the dynamic linker won't relocate. */
5506 if ((sec
->flags
& SEC_ALLOC
) == 0)
5509 BFD_ASSERT (is_ppc64_elf (abfd
));
5511 htab
= ppc_hash_table (info
);
5515 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
5516 FALSE
, FALSE
, TRUE
);
5517 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
5518 FALSE
, FALSE
, TRUE
);
5519 symtab_hdr
= &elf_symtab_hdr (abfd
);
5520 sym_hashes
= elf_sym_hashes (abfd
);
5522 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
5523 rel_end
= relocs
+ sec
->reloc_count
;
5524 for (rel
= relocs
; rel
< rel_end
; rel
++)
5526 unsigned long r_symndx
;
5527 struct elf_link_hash_entry
*h
;
5528 enum elf_ppc64_reloc_type r_type
;
5530 struct _ppc64_elf_section_data
*ppc64_sec
;
5531 struct plt_entry
**ifunc
, **plt_list
;
5533 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5534 if (r_symndx
< symtab_hdr
->sh_info
)
5538 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5539 h
= elf_follow_link (h
);
5541 if (h
== htab
->elf
.hgot
)
5542 sec
->has_toc_reloc
= 1;
5549 if (h
->type
== STT_GNU_IFUNC
)
5552 ifunc
= &h
->plt
.plist
;
5557 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5562 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5564 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5566 NON_GOT
| PLT_IFUNC
);
5572 r_type
= ELF64_R_TYPE (rel
->r_info
);
5577 /* These special tls relocs tie a call to __tls_get_addr with
5578 its parameter symbol. */
5580 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
5582 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5584 NON_GOT
| TLS_TLS
| TLS_MARK
))
5586 sec
->has_tls_reloc
= 1;
5589 case R_PPC64_GOT_TLSLD16
:
5590 case R_PPC64_GOT_TLSLD16_LO
:
5591 case R_PPC64_GOT_TLSLD16_HI
:
5592 case R_PPC64_GOT_TLSLD16_HA
:
5593 tls_type
= TLS_TLS
| TLS_LD
;
5596 case R_PPC64_GOT_TLSGD16
:
5597 case R_PPC64_GOT_TLSGD16_LO
:
5598 case R_PPC64_GOT_TLSGD16_HI
:
5599 case R_PPC64_GOT_TLSGD16_HA
:
5600 tls_type
= TLS_TLS
| TLS_GD
;
5603 case R_PPC64_GOT_TPREL16_DS
:
5604 case R_PPC64_GOT_TPREL16_LO_DS
:
5605 case R_PPC64_GOT_TPREL16_HI
:
5606 case R_PPC64_GOT_TPREL16_HA
:
5607 if (bfd_link_dll (info
))
5608 info
->flags
|= DF_STATIC_TLS
;
5609 tls_type
= TLS_TLS
| TLS_TPREL
;
5612 case R_PPC64_GOT_DTPREL16_DS
:
5613 case R_PPC64_GOT_DTPREL16_LO_DS
:
5614 case R_PPC64_GOT_DTPREL16_HI
:
5615 case R_PPC64_GOT_DTPREL16_HA
:
5616 tls_type
= TLS_TLS
| TLS_DTPREL
;
5618 sec
->has_tls_reloc
= 1;
5622 case R_PPC64_GOT16_DS
:
5623 case R_PPC64_GOT16_HA
:
5624 case R_PPC64_GOT16_HI
:
5625 case R_PPC64_GOT16_LO
:
5626 case R_PPC64_GOT16_LO_DS
:
5627 /* This symbol requires a global offset table entry. */
5628 sec
->has_toc_reloc
= 1;
5629 if (r_type
== R_PPC64_GOT_TLSLD16
5630 || r_type
== R_PPC64_GOT_TLSGD16
5631 || r_type
== R_PPC64_GOT_TPREL16_DS
5632 || r_type
== R_PPC64_GOT_DTPREL16_DS
5633 || r_type
== R_PPC64_GOT16
5634 || r_type
== R_PPC64_GOT16_DS
)
5636 htab
->do_multi_toc
= 1;
5637 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5640 if (ppc64_elf_tdata (abfd
)->got
== NULL
5641 && !create_got_section (abfd
, info
))
5646 struct ppc_link_hash_entry
*eh
;
5647 struct got_entry
*ent
;
5649 eh
= (struct ppc_link_hash_entry
*) h
;
5650 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5651 if (ent
->addend
== rel
->r_addend
5652 && ent
->owner
== abfd
5653 && ent
->tls_type
== tls_type
)
5657 bfd_size_type amt
= sizeof (*ent
);
5658 ent
= bfd_alloc (abfd
, amt
);
5661 ent
->next
= eh
->elf
.got
.glist
;
5662 ent
->addend
= rel
->r_addend
;
5664 ent
->tls_type
= tls_type
;
5665 ent
->is_indirect
= FALSE
;
5666 ent
->got
.refcount
= 0;
5667 eh
->elf
.got
.glist
= ent
;
5669 ent
->got
.refcount
+= 1;
5670 eh
->tls_mask
|= tls_type
;
5673 /* This is a global offset table entry for a local symbol. */
5674 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5675 rel
->r_addend
, tls_type
))
5678 /* We may also need a plt entry if the symbol turns out to be
5680 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
5682 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5687 case R_PPC64_PLT16_HA
:
5688 case R_PPC64_PLT16_HI
:
5689 case R_PPC64_PLT16_LO
:
5690 case R_PPC64_PLT16_LO_DS
:
5693 /* This symbol requires a procedure linkage table entry. */
5698 if (h
->root
.root
.string
[0] == '.'
5699 && h
->root
.root
.string
[1] != '\0')
5700 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5701 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= PLT_KEEP
;
5702 plt_list
= &h
->plt
.plist
;
5704 if (plt_list
== NULL
)
5705 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5707 NON_GOT
| PLT_KEEP
);
5708 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5712 /* The following relocations don't need to propagate the
5713 relocation if linking a shared object since they are
5714 section relative. */
5715 case R_PPC64_SECTOFF
:
5716 case R_PPC64_SECTOFF_LO
:
5717 case R_PPC64_SECTOFF_HI
:
5718 case R_PPC64_SECTOFF_HA
:
5719 case R_PPC64_SECTOFF_DS
:
5720 case R_PPC64_SECTOFF_LO_DS
:
5721 case R_PPC64_DTPREL16
:
5722 case R_PPC64_DTPREL16_LO
:
5723 case R_PPC64_DTPREL16_HI
:
5724 case R_PPC64_DTPREL16_HA
:
5725 case R_PPC64_DTPREL16_DS
:
5726 case R_PPC64_DTPREL16_LO_DS
:
5727 case R_PPC64_DTPREL16_HIGH
:
5728 case R_PPC64_DTPREL16_HIGHA
:
5729 case R_PPC64_DTPREL16_HIGHER
:
5730 case R_PPC64_DTPREL16_HIGHERA
:
5731 case R_PPC64_DTPREL16_HIGHEST
:
5732 case R_PPC64_DTPREL16_HIGHESTA
:
5737 case R_PPC64_REL16_LO
:
5738 case R_PPC64_REL16_HI
:
5739 case R_PPC64_REL16_HA
:
5740 case R_PPC64_REL16DX_HA
:
5743 /* Not supported as a dynamic relocation. */
5744 case R_PPC64_ADDR64_LOCAL
:
5745 if (bfd_link_pic (info
))
5747 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5749 /* xgettext:c-format */
5750 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
5751 "in shared libraries and PIEs\n"),
5752 abfd
, sec
, rel
->r_offset
,
5753 ppc64_elf_howto_table
[r_type
]->name
);
5754 bfd_set_error (bfd_error_bad_value
);
5760 case R_PPC64_TOC16_DS
:
5761 htab
->do_multi_toc
= 1;
5762 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5764 case R_PPC64_TOC16_LO
:
5765 case R_PPC64_TOC16_HI
:
5766 case R_PPC64_TOC16_HA
:
5767 case R_PPC64_TOC16_LO_DS
:
5768 sec
->has_toc_reloc
= 1;
5775 /* This relocation describes the C++ object vtable hierarchy.
5776 Reconstruct it for later use during GC. */
5777 case R_PPC64_GNU_VTINHERIT
:
5778 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5782 /* This relocation describes which C++ vtable entries are actually
5783 used. Record for later use during GC. */
5784 case R_PPC64_GNU_VTENTRY
:
5785 BFD_ASSERT (h
!= NULL
);
5787 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5792 case R_PPC64_REL14_BRTAKEN
:
5793 case R_PPC64_REL14_BRNTAKEN
:
5795 asection
*dest
= NULL
;
5797 /* Heuristic: If jumping outside our section, chances are
5798 we are going to need a stub. */
5801 /* If the sym is weak it may be overridden later, so
5802 don't assume we know where a weak sym lives. */
5803 if (h
->root
.type
== bfd_link_hash_defined
)
5804 dest
= h
->root
.u
.def
.section
;
5808 Elf_Internal_Sym
*isym
;
5810 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5815 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5819 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5824 case R_PPC64_PLTCALL
:
5829 if (h
->root
.root
.string
[0] == '.'
5830 && h
->root
.root
.string
[1] != '\0')
5831 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5833 if (h
== tga
|| h
== dottga
)
5835 sec
->has_tls_reloc
= 1;
5837 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5838 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5839 /* We have a new-style __tls_get_addr call with
5843 /* Mark this section as having an old-style call. */
5844 sec
->has_tls_get_addr_call
= 1;
5846 plt_list
= &h
->plt
.plist
;
5849 /* We may need a .plt entry if the function this reloc
5850 refers to is in a shared lib. */
5852 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5856 case R_PPC64_ADDR14
:
5857 case R_PPC64_ADDR14_BRNTAKEN
:
5858 case R_PPC64_ADDR14_BRTAKEN
:
5859 case R_PPC64_ADDR24
:
5862 case R_PPC64_TPREL64
:
5863 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5864 if (bfd_link_dll (info
))
5865 info
->flags
|= DF_STATIC_TLS
;
5868 case R_PPC64_DTPMOD64
:
5869 if (rel
+ 1 < rel_end
5870 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5871 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5872 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5874 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5877 case R_PPC64_DTPREL64
:
5878 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5880 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5881 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5882 /* This is the second reloc of a dtpmod, dtprel pair.
5883 Don't mark with TLS_DTPREL. */
5887 sec
->has_tls_reloc
= 1;
5890 struct ppc_link_hash_entry
*eh
;
5891 eh
= (struct ppc_link_hash_entry
*) h
;
5892 eh
->tls_mask
|= tls_type
;
5895 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5896 rel
->r_addend
, tls_type
))
5899 ppc64_sec
= ppc64_elf_section_data (sec
);
5900 if (ppc64_sec
->sec_type
!= sec_toc
)
5904 /* One extra to simplify get_tls_mask. */
5905 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5906 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5907 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5909 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5910 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5911 if (ppc64_sec
->u
.toc
.add
== NULL
)
5913 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5914 ppc64_sec
->sec_type
= sec_toc
;
5916 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5917 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5918 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5920 /* Mark the second slot of a GD or LD entry.
5921 -1 to indicate GD and -2 to indicate LD. */
5922 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5923 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5924 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5925 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5928 case R_PPC64_TPREL16
:
5929 case R_PPC64_TPREL16_LO
:
5930 case R_PPC64_TPREL16_HI
:
5931 case R_PPC64_TPREL16_HA
:
5932 case R_PPC64_TPREL16_DS
:
5933 case R_PPC64_TPREL16_LO_DS
:
5934 case R_PPC64_TPREL16_HIGH
:
5935 case R_PPC64_TPREL16_HIGHA
:
5936 case R_PPC64_TPREL16_HIGHER
:
5937 case R_PPC64_TPREL16_HIGHERA
:
5938 case R_PPC64_TPREL16_HIGHEST
:
5939 case R_PPC64_TPREL16_HIGHESTA
:
5940 if (bfd_link_dll (info
))
5941 info
->flags
|= DF_STATIC_TLS
;
5944 case R_PPC64_ADDR64
:
5946 && rel
+ 1 < rel_end
5947 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5950 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5954 case R_PPC64_ADDR16
:
5955 case R_PPC64_ADDR16_DS
:
5956 case R_PPC64_ADDR16_HA
:
5957 case R_PPC64_ADDR16_HI
:
5958 case R_PPC64_ADDR16_HIGH
:
5959 case R_PPC64_ADDR16_HIGHA
:
5960 case R_PPC64_ADDR16_HIGHER
:
5961 case R_PPC64_ADDR16_HIGHERA
:
5962 case R_PPC64_ADDR16_HIGHEST
:
5963 case R_PPC64_ADDR16_HIGHESTA
:
5964 case R_PPC64_ADDR16_LO
:
5965 case R_PPC64_ADDR16_LO_DS
:
5966 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5967 && rel
->r_addend
== 0)
5969 /* We may need a .plt entry if this reloc refers to a
5970 function in a shared lib. */
5971 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5973 h
->pointer_equality_needed
= 1;
5980 case R_PPC64_ADDR32
:
5981 case R_PPC64_UADDR16
:
5982 case R_PPC64_UADDR32
:
5983 case R_PPC64_UADDR64
:
5985 if (h
!= NULL
&& !bfd_link_pic (info
))
5986 /* We may need a copy reloc. */
5989 /* Don't propagate .opd relocs. */
5990 if (NO_OPD_RELOCS
&& is_opd
)
5993 /* If we are creating a shared library, and this is a reloc
5994 against a global symbol, or a non PC relative reloc
5995 against a local symbol, then we need to copy the reloc
5996 into the shared library. However, if we are linking with
5997 -Bsymbolic, we do not need to copy a reloc against a
5998 global symbol which is defined in an object we are
5999 including in the link (i.e., DEF_REGULAR is set). At
6000 this point we have not seen all the input files, so it is
6001 possible that DEF_REGULAR is not set now but will be set
6002 later (it is never cleared). In case of a weak definition,
6003 DEF_REGULAR may be cleared later by a strong definition in
6004 a shared library. We account for that possibility below by
6005 storing information in the dyn_relocs field of the hash
6006 table entry. A similar situation occurs when creating
6007 shared libraries and symbol visibility changes render the
6010 If on the other hand, we are creating an executable, we
6011 may need to keep relocations for symbols satisfied by a
6012 dynamic library if we manage to avoid copy relocs for the
6015 if ((bfd_link_pic (info
)
6016 && (must_be_dyn_reloc (info
, r_type
)
6018 && (!SYMBOLIC_BIND (info
, h
)
6019 || h
->root
.type
== bfd_link_hash_defweak
6020 || !h
->def_regular
))))
6021 || (ELIMINATE_COPY_RELOCS
6022 && !bfd_link_pic (info
)
6024 && (h
->root
.type
== bfd_link_hash_defweak
6025 || !h
->def_regular
))
6026 || (!bfd_link_pic (info
)
6029 /* We must copy these reloc types into the output file.
6030 Create a reloc section in dynobj and make room for
6034 sreloc
= _bfd_elf_make_dynamic_reloc_section
6035 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
6041 /* If this is a global symbol, we count the number of
6042 relocations we need for this symbol. */
6045 struct elf_dyn_relocs
*p
;
6046 struct elf_dyn_relocs
**head
;
6048 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6050 if (p
== NULL
|| p
->sec
!= sec
)
6052 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
6062 if (!must_be_dyn_reloc (info
, r_type
))
6067 /* Track dynamic relocs needed for local syms too.
6068 We really need local syms available to do this
6070 struct ppc_dyn_relocs
*p
;
6071 struct ppc_dyn_relocs
**head
;
6072 bfd_boolean is_ifunc
;
6075 Elf_Internal_Sym
*isym
;
6077 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6082 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6086 vpp
= &elf_section_data (s
)->local_dynrel
;
6087 head
= (struct ppc_dyn_relocs
**) vpp
;
6088 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
6090 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
6092 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
6094 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
6100 p
->ifunc
= is_ifunc
;
6116 /* Merge backend specific data from an object file to the output
6117 object file when linking. */
6120 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6122 bfd
*obfd
= info
->output_bfd
;
6123 unsigned long iflags
, oflags
;
6125 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
6128 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
6131 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6134 iflags
= elf_elfheader (ibfd
)->e_flags
;
6135 oflags
= elf_elfheader (obfd
)->e_flags
;
6137 if (iflags
& ~EF_PPC64_ABI
)
6140 /* xgettext:c-format */
6141 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
6142 bfd_set_error (bfd_error_bad_value
);
6145 else if (iflags
!= oflags
&& iflags
!= 0)
6148 /* xgettext:c-format */
6149 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
6150 ibfd
, iflags
, oflags
);
6151 bfd_set_error (bfd_error_bad_value
);
6155 _bfd_elf_ppc_merge_fp_attributes (ibfd
, info
);
6157 /* Merge Tag_compatibility attributes and any common GNU ones. */
6158 _bfd_elf_merge_object_attributes (ibfd
, info
);
6164 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6166 /* Print normal ELF private data. */
6167 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6169 if (elf_elfheader (abfd
)->e_flags
!= 0)
6173 fprintf (file
, _("private flags = 0x%lx:"),
6174 elf_elfheader (abfd
)->e_flags
);
6176 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
6177 fprintf (file
, _(" [abiv%ld]"),
6178 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
6185 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
6186 of the code entry point, and its section, which must be in the same
6187 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
6190 opd_entry_value (asection
*opd_sec
,
6192 asection
**code_sec
,
6194 bfd_boolean in_code_sec
)
6196 bfd
*opd_bfd
= opd_sec
->owner
;
6197 Elf_Internal_Rela
*relocs
;
6198 Elf_Internal_Rela
*lo
, *hi
, *look
;
6201 /* No relocs implies we are linking a --just-symbols object, or looking
6202 at a final linked executable with addr2line or somesuch. */
6203 if (opd_sec
->reloc_count
== 0)
6205 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
6207 if (contents
== NULL
)
6209 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
6210 return (bfd_vma
) -1;
6211 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
6214 /* PR 17512: file: 64b9dfbb. */
6215 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
6216 return (bfd_vma
) -1;
6218 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
6219 if (code_sec
!= NULL
)
6221 asection
*sec
, *likely
= NULL
;
6227 && val
< sec
->vma
+ sec
->size
)
6233 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6235 && (sec
->flags
& SEC_LOAD
) != 0
6236 && (sec
->flags
& SEC_ALLOC
) != 0)
6241 if (code_off
!= NULL
)
6242 *code_off
= val
- likely
->vma
;
6248 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
6250 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
6252 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
6253 /* PR 17512: file: df8e1fd6. */
6255 return (bfd_vma
) -1;
6257 /* Go find the opd reloc at the sym address. */
6259 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
6263 look
= lo
+ (hi
- lo
) / 2;
6264 if (look
->r_offset
< offset
)
6266 else if (look
->r_offset
> offset
)
6270 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
6272 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
6273 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
6275 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
6276 asection
*sec
= NULL
;
6278 if (symndx
>= symtab_hdr
->sh_info
6279 && elf_sym_hashes (opd_bfd
) != NULL
)
6281 struct elf_link_hash_entry
**sym_hashes
;
6282 struct elf_link_hash_entry
*rh
;
6284 sym_hashes
= elf_sym_hashes (opd_bfd
);
6285 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
6288 rh
= elf_follow_link (rh
);
6289 if (rh
->root
.type
!= bfd_link_hash_defined
6290 && rh
->root
.type
!= bfd_link_hash_defweak
)
6292 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
6294 val
= rh
->root
.u
.def
.value
;
6295 sec
= rh
->root
.u
.def
.section
;
6302 Elf_Internal_Sym
*sym
;
6304 if (symndx
< symtab_hdr
->sh_info
)
6306 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6309 size_t symcnt
= symtab_hdr
->sh_info
;
6310 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6315 symtab_hdr
->contents
= (bfd_byte
*) sym
;
6321 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6327 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
6330 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
6331 val
= sym
->st_value
;
6334 val
+= look
->r_addend
;
6335 if (code_off
!= NULL
)
6337 if (code_sec
!= NULL
)
6339 if (in_code_sec
&& *code_sec
!= sec
)
6344 if (sec
->output_section
!= NULL
)
6345 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
6354 /* If the ELF symbol SYM might be a function in SEC, return the
6355 function size and set *CODE_OFF to the function's entry point,
6356 otherwise return zero. */
6358 static bfd_size_type
6359 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
6364 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
6365 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
6369 if (!(sym
->flags
& BSF_SYNTHETIC
))
6370 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
6372 if (strcmp (sym
->section
->name
, ".opd") == 0)
6374 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
6375 bfd_vma symval
= sym
->value
;
6378 && opd
->adjust
!= NULL
6379 && elf_section_data (sym
->section
)->relocs
!= NULL
)
6381 /* opd_entry_value will use cached relocs that have been
6382 adjusted, but with raw symbols. That means both local
6383 and global symbols need adjusting. */
6384 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
6390 if (opd_entry_value (sym
->section
, symval
,
6391 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
6393 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6394 symbol. This size has nothing to do with the code size of the
6395 function, which is what we're supposed to return, but the
6396 code size isn't available without looking up the dot-sym.
6397 However, doing that would be a waste of time particularly
6398 since elf_find_function will look at the dot-sym anyway.
6399 Now, elf_find_function will keep the largest size of any
6400 function sym found at the code address of interest, so return
6401 1 here to avoid it incorrectly caching a larger function size
6402 for a small function. This does mean we return the wrong
6403 size for a new-ABI function of size 24, but all that does is
6404 disable caching for such functions. */
6410 if (sym
->section
!= sec
)
6412 *code_off
= sym
->value
;
6419 /* Return true if symbol is a strong function defined in an ELFv2
6420 object with st_other localentry bits of zero, ie. its local entry
6421 point coincides with its global entry point. */
6424 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
6427 && h
->type
== STT_FUNC
6428 && h
->root
.type
== bfd_link_hash_defined
6429 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
6430 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
6431 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
6432 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
6435 /* Return true if symbol is defined in a regular object file. */
6438 is_static_defined (struct elf_link_hash_entry
*h
)
6440 return ((h
->root
.type
== bfd_link_hash_defined
6441 || h
->root
.type
== bfd_link_hash_defweak
)
6442 && h
->root
.u
.def
.section
!= NULL
6443 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6446 /* If FDH is a function descriptor symbol, return the associated code
6447 entry symbol if it is defined. Return NULL otherwise. */
6449 static struct ppc_link_hash_entry
*
6450 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
6452 if (fdh
->is_func_descriptor
)
6454 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
6455 if (fh
->elf
.root
.type
== bfd_link_hash_defined
6456 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6462 /* If FH is a function code entry symbol, return the associated
6463 function descriptor symbol if it is defined. Return NULL otherwise. */
6465 static struct ppc_link_hash_entry
*
6466 defined_func_desc (struct ppc_link_hash_entry
*fh
)
6469 && fh
->oh
->is_func_descriptor
)
6471 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
6472 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
6473 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6479 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
6481 /* Garbage collect sections, after first dealing with dot-symbols. */
6484 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6486 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6488 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
6490 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6491 htab
->need_func_desc_adj
= 0;
6493 return bfd_elf_gc_sections (abfd
, info
);
6496 /* Mark all our entry sym sections, both opd and code section. */
6499 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
6501 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6502 struct bfd_sym_chain
*sym
;
6507 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
6509 struct ppc_link_hash_entry
*eh
, *fh
;
6512 eh
= (struct ppc_link_hash_entry
*)
6513 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
6516 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
6517 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6520 fh
= defined_code_entry (eh
);
6523 sec
= fh
->elf
.root
.u
.def
.section
;
6524 sec
->flags
|= SEC_KEEP
;
6526 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6527 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6528 eh
->elf
.root
.u
.def
.value
,
6529 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6530 sec
->flags
|= SEC_KEEP
;
6532 sec
= eh
->elf
.root
.u
.def
.section
;
6533 sec
->flags
|= SEC_KEEP
;
6537 /* Mark sections containing dynamically referenced symbols. When
6538 building shared libraries, we must assume that any visible symbol is
6542 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
6544 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6545 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
6546 struct ppc_link_hash_entry
*fdh
;
6547 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
6549 /* Dynamic linking info is on the func descriptor sym. */
6550 fdh
= defined_func_desc (eh
);
6554 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
6555 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
6556 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
6557 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
6558 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
6559 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
6560 && (!bfd_link_executable (info
)
6561 || info
->gc_keep_exported
6562 || info
->export_dynamic
6565 && (*d
->match
) (&d
->head
, NULL
, eh
->elf
.root
.root
.string
)))
6566 && (eh
->elf
.versioned
>= versioned
6567 || !bfd_hide_sym_by_version (info
->version_info
,
6568 eh
->elf
.root
.root
.string
)))))
6571 struct ppc_link_hash_entry
*fh
;
6573 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
6575 /* Function descriptor syms cause the associated
6576 function code sym section to be marked. */
6577 fh
= defined_code_entry (eh
);
6580 code_sec
= fh
->elf
.root
.u
.def
.section
;
6581 code_sec
->flags
|= SEC_KEEP
;
6583 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6584 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6585 eh
->elf
.root
.u
.def
.value
,
6586 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6587 code_sec
->flags
|= SEC_KEEP
;
6593 /* Return the section that should be marked against GC for a given
6597 ppc64_elf_gc_mark_hook (asection
*sec
,
6598 struct bfd_link_info
*info
,
6599 Elf_Internal_Rela
*rel
,
6600 struct elf_link_hash_entry
*h
,
6601 Elf_Internal_Sym
*sym
)
6605 /* Syms return NULL if we're marking .opd, so we avoid marking all
6606 function sections, as all functions are referenced in .opd. */
6608 if (get_opd_info (sec
) != NULL
)
6613 enum elf_ppc64_reloc_type r_type
;
6614 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
6616 r_type
= ELF64_R_TYPE (rel
->r_info
);
6619 case R_PPC64_GNU_VTINHERIT
:
6620 case R_PPC64_GNU_VTENTRY
:
6624 switch (h
->root
.type
)
6626 case bfd_link_hash_defined
:
6627 case bfd_link_hash_defweak
:
6628 eh
= (struct ppc_link_hash_entry
*) h
;
6629 fdh
= defined_func_desc (eh
);
6632 /* -mcall-aixdesc code references the dot-symbol on
6633 a call reloc. Mark the function descriptor too
6634 against garbage collection. */
6636 if (fdh
->elf
.is_weakalias
)
6637 weakdef (&fdh
->elf
)->mark
= 1;
6641 /* Function descriptor syms cause the associated
6642 function code sym section to be marked. */
6643 fh
= defined_code_entry (eh
);
6646 /* They also mark their opd section. */
6647 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6649 rsec
= fh
->elf
.root
.u
.def
.section
;
6651 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6652 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6653 eh
->elf
.root
.u
.def
.value
,
6654 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
6655 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6657 rsec
= h
->root
.u
.def
.section
;
6660 case bfd_link_hash_common
:
6661 rsec
= h
->root
.u
.c
.p
->section
;
6665 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6671 struct _opd_sec_data
*opd
;
6673 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6674 opd
= get_opd_info (rsec
);
6675 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6679 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6686 /* The maximum size of .sfpr. */
6687 #define SFPR_MAX (218*4)
6689 struct sfpr_def_parms
6691 const char name
[12];
6692 unsigned char lo
, hi
;
6693 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
6694 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
6697 /* Auto-generate _save*, _rest* functions in .sfpr.
6698 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6702 sfpr_define (struct bfd_link_info
*info
,
6703 const struct sfpr_def_parms
*parm
,
6706 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6708 size_t len
= strlen (parm
->name
);
6709 bfd_boolean writing
= FALSE
;
6715 memcpy (sym
, parm
->name
, len
);
6718 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6720 struct ppc_link_hash_entry
*h
;
6722 sym
[len
+ 0] = i
/ 10 + '0';
6723 sym
[len
+ 1] = i
% 10 + '0';
6724 h
= (struct ppc_link_hash_entry
*)
6725 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
6726 if (stub_sec
!= NULL
)
6729 && h
->elf
.root
.type
== bfd_link_hash_defined
6730 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6732 struct elf_link_hash_entry
*s
;
6734 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6735 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
6738 if (s
->root
.type
== bfd_link_hash_new
6739 || (s
->root
.type
= bfd_link_hash_defined
6740 && s
->root
.u
.def
.section
== stub_sec
))
6742 s
->root
.type
= bfd_link_hash_defined
;
6743 s
->root
.u
.def
.section
= stub_sec
;
6744 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6745 + h
->elf
.root
.u
.def
.value
);
6748 s
->ref_regular_nonweak
= 1;
6749 s
->forced_local
= 1;
6751 s
->root
.linker_def
= 1;
6759 if (!h
->elf
.def_regular
)
6761 h
->elf
.root
.type
= bfd_link_hash_defined
;
6762 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6763 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6764 h
->elf
.type
= STT_FUNC
;
6765 h
->elf
.def_regular
= 1;
6767 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
6769 if (htab
->sfpr
->contents
== NULL
)
6771 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6772 if (htab
->sfpr
->contents
== NULL
)
6779 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6781 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6783 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6784 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6792 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6794 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6799 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6801 p
= savegpr0 (abfd
, p
, r
);
6802 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6804 bfd_put_32 (abfd
, BLR
, p
);
6809 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6811 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6816 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6818 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6820 p
= restgpr0 (abfd
, p
, r
);
6821 bfd_put_32 (abfd
, MTLR_R0
, p
);
6825 p
= restgpr0 (abfd
, p
, 30);
6826 p
= restgpr0 (abfd
, p
, 31);
6828 bfd_put_32 (abfd
, BLR
, p
);
6833 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6835 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6840 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6842 p
= savegpr1 (abfd
, p
, r
);
6843 bfd_put_32 (abfd
, BLR
, p
);
6848 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6850 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6855 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6857 p
= restgpr1 (abfd
, p
, r
);
6858 bfd_put_32 (abfd
, BLR
, p
);
6863 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6865 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6870 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6872 p
= savefpr (abfd
, p
, r
);
6873 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6875 bfd_put_32 (abfd
, BLR
, p
);
6880 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6882 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6887 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6889 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6891 p
= restfpr (abfd
, p
, r
);
6892 bfd_put_32 (abfd
, MTLR_R0
, p
);
6896 p
= restfpr (abfd
, p
, 30);
6897 p
= restfpr (abfd
, p
, 31);
6899 bfd_put_32 (abfd
, BLR
, p
);
6904 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6906 p
= savefpr (abfd
, p
, r
);
6907 bfd_put_32 (abfd
, BLR
, p
);
6912 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6914 p
= restfpr (abfd
, p
, r
);
6915 bfd_put_32 (abfd
, BLR
, p
);
6920 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6922 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6924 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6929 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6931 p
= savevr (abfd
, p
, r
);
6932 bfd_put_32 (abfd
, BLR
, p
);
6937 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6939 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6941 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6946 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6948 p
= restvr (abfd
, p
, r
);
6949 bfd_put_32 (abfd
, BLR
, p
);
6953 /* Called via elf_link_hash_traverse to transfer dynamic linking
6954 information on function code symbol entries to their corresponding
6955 function descriptor symbol entries. */
6958 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6960 struct bfd_link_info
*info
;
6961 struct ppc_link_hash_table
*htab
;
6962 struct ppc_link_hash_entry
*fh
;
6963 struct ppc_link_hash_entry
*fdh
;
6964 bfd_boolean force_local
;
6966 fh
= (struct ppc_link_hash_entry
*) h
;
6967 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6973 if (fh
->elf
.root
.root
.string
[0] != '.'
6974 || fh
->elf
.root
.root
.string
[1] == '\0')
6978 htab
= ppc_hash_table (info
);
6982 /* Find the corresponding function descriptor symbol. */
6983 fdh
= lookup_fdh (fh
, htab
);
6985 /* Resolve undefined references to dot-symbols as the value
6986 in the function descriptor, if we have one in a regular object.
6987 This is to satisfy cases like ".quad .foo". Calls to functions
6988 in dynamic objects are handled elsewhere. */
6989 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
6990 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6991 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
6992 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6993 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6994 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6995 fdh
->elf
.root
.u
.def
.value
,
6996 &fh
->elf
.root
.u
.def
.section
,
6997 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
6999 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
7000 fh
->elf
.forced_local
= 1;
7001 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
7002 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
7005 if (!fh
->elf
.dynamic
)
7007 struct plt_entry
*ent
;
7009 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7010 if (ent
->plt
.refcount
> 0)
7016 /* Create a descriptor as undefined if necessary. */
7018 && !bfd_link_executable (info
)
7019 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
7020 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
7022 fdh
= make_fdh (info
, fh
);
7027 /* We can't support overriding of symbols on a fake descriptor. */
7030 && (fh
->elf
.root
.type
== bfd_link_hash_defined
7031 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
7032 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
7034 /* Transfer dynamic linking information to the function descriptor. */
7037 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
7038 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
7039 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
7040 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
7041 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
7042 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
7043 || fh
->elf
.type
== STT_FUNC
7044 || fh
->elf
.type
== STT_GNU_IFUNC
);
7045 move_plt_plist (fh
, fdh
);
7047 if (!fdh
->elf
.forced_local
7048 && fh
->elf
.dynindx
!= -1)
7049 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
7053 /* Now that the info is on the function descriptor, clear the
7054 function code sym info. Any function code syms for which we
7055 don't have a definition in a regular file, we force local.
7056 This prevents a shared library from exporting syms that have
7057 been imported from another library. Function code syms that
7058 are really in the library we must leave global to prevent the
7059 linker dragging in a definition from a static library. */
7060 force_local
= (!fh
->elf
.def_regular
7062 || !fdh
->elf
.def_regular
7063 || fdh
->elf
.forced_local
);
7064 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7069 static const struct sfpr_def_parms save_res_funcs
[] =
7071 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
7072 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
7073 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
7074 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
7075 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
7076 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
7077 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
7078 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
7079 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
7080 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
7081 { "_savevr_", 20, 31, savevr
, savevr_tail
},
7082 { "_restvr_", 20, 31, restvr
, restvr_tail
}
7085 /* Called near the start of bfd_elf_size_dynamic_sections. We use
7086 this hook to a) provide some gcc support functions, and b) transfer
7087 dynamic linking information gathered so far on function code symbol
7088 entries, to their corresponding function descriptor symbol entries. */
7091 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
7092 struct bfd_link_info
*info
)
7094 struct ppc_link_hash_table
*htab
;
7096 htab
= ppc_hash_table (info
);
7100 /* Provide any missing _save* and _rest* functions. */
7101 if (htab
->sfpr
!= NULL
)
7105 htab
->sfpr
->size
= 0;
7106 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
7107 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
7109 if (htab
->sfpr
->size
== 0)
7110 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
7113 if (bfd_link_relocatable (info
))
7116 if (htab
->elf
.hgot
!= NULL
)
7118 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
7119 /* Make .TOC. defined so as to prevent it being made dynamic.
7120 The wrong value here is fixed later in ppc64_elf_set_toc. */
7121 if (!htab
->elf
.hgot
->def_regular
7122 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
7124 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
7125 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
7126 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
7127 htab
->elf
.hgot
->def_regular
= 1;
7128 htab
->elf
.hgot
->root
.linker_def
= 1;
7130 htab
->elf
.hgot
->type
= STT_OBJECT
;
7131 htab
->elf
.hgot
->other
= ((htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1))
7135 if (htab
->need_func_desc_adj
)
7137 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7138 htab
->need_func_desc_adj
= 0;
7144 /* Find dynamic relocs for H that apply to read-only sections. */
7147 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7149 struct ppc_link_hash_entry
*eh
;
7150 struct elf_dyn_relocs
*p
;
7152 eh
= (struct ppc_link_hash_entry
*) h
;
7153 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7155 asection
*s
= p
->sec
->output_section
;
7157 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7163 /* Return true if we have dynamic relocs against H or any of its weak
7164 aliases, that apply to read-only sections. Cannot be used after
7165 size_dynamic_sections. */
7168 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7170 struct ppc_link_hash_entry
*eh
;
7172 eh
= (struct ppc_link_hash_entry
*) h
;
7175 if (readonly_dynrelocs (&eh
->elf
))
7177 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
7178 } while (eh
!= NULL
&& &eh
->elf
!= h
);
7183 /* Return whether EH has pc-relative dynamic relocs. */
7186 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
7188 struct elf_dyn_relocs
*p
;
7190 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7191 if (p
->pc_count
!= 0)
7196 /* Return true if a global entry stub will be created for H. Valid
7197 for ELFv2 before plt entries have been allocated. */
7200 global_entry_stub (struct elf_link_hash_entry
*h
)
7202 struct plt_entry
*pent
;
7204 if (!h
->pointer_equality_needed
7208 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7209 if (pent
->plt
.refcount
> 0
7210 && pent
->addend
== 0)
7216 /* Adjust a symbol defined by a dynamic object and referenced by a
7217 regular object. The current definition is in some section of the
7218 dynamic object, but we're not including those sections. We have to
7219 change the definition to something the rest of the link can
7223 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7224 struct elf_link_hash_entry
*h
)
7226 struct ppc_link_hash_table
*htab
;
7229 htab
= ppc_hash_table (info
);
7233 /* Deal with function syms. */
7234 if (h
->type
== STT_FUNC
7235 || h
->type
== STT_GNU_IFUNC
7238 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
7239 || SYMBOL_CALLS_LOCAL (info
, h
)
7240 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
7241 /* Discard dyn_relocs when non-pic if we've decided that a
7242 function symbol is local and not an ifunc. We keep dynamic
7243 relocs for ifuncs when local rather than always emitting a
7244 plt call stub for them and defining the symbol on the call
7245 stub. We can't do that for ELFv1 anyway (a function symbol
7246 is defined on a descriptor, not code) and it can be faster at
7247 run-time due to not needing to bounce through a stub. The
7248 dyn_relocs for ifuncs will be applied even in a static
7250 if (!bfd_link_pic (info
)
7251 && h
->type
!= STT_GNU_IFUNC
7253 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7255 /* Clear procedure linkage table information for any symbol that
7256 won't need a .plt entry. */
7257 struct plt_entry
*ent
;
7258 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7259 if (ent
->plt
.refcount
> 0)
7262 || (h
->type
!= STT_GNU_IFUNC
7264 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
7265 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
))
7267 h
->plt
.plist
= NULL
;
7269 h
->pointer_equality_needed
= 0;
7271 else if (abiversion (info
->output_bfd
) >= 2)
7273 /* Taking a function's address in a read/write section
7274 doesn't require us to define the function symbol in the
7275 executable on a global entry stub. A dynamic reloc can
7276 be used instead. The reason we prefer a few more dynamic
7277 relocs is that calling via a global entry stub costs a
7278 few more instructions, and pointer_equality_needed causes
7279 extra work in ld.so when resolving these symbols. */
7280 if (global_entry_stub (h
))
7282 if (!readonly_dynrelocs (h
))
7284 h
->pointer_equality_needed
= 0;
7285 /* If we haven't seen a branch reloc then we don't need
7288 h
->plt
.plist
= NULL
;
7290 else if (!bfd_link_pic (info
))
7291 /* We are going to be defining the function symbol on the
7292 plt stub, so no dyn_relocs needed when non-pic. */
7293 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7296 /* ELFv2 function symbols can't have copy relocs. */
7299 else if (!h
->needs_plt
7300 && !readonly_dynrelocs (h
))
7302 /* If we haven't seen a branch reloc then we don't need a
7304 h
->plt
.plist
= NULL
;
7305 h
->pointer_equality_needed
= 0;
7310 h
->plt
.plist
= NULL
;
7312 /* If this is a weak symbol, and there is a real definition, the
7313 processor independent code will have arranged for us to see the
7314 real definition first, and we can just use the same value. */
7315 if (h
->is_weakalias
)
7317 struct elf_link_hash_entry
*def
= weakdef (h
);
7318 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
7319 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
7320 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
7321 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
7322 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
7323 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7327 /* If we are creating a shared library, we must presume that the
7328 only references to the symbol are via the global offset table.
7329 For such cases we need not do anything here; the relocations will
7330 be handled correctly by relocate_section. */
7331 if (bfd_link_pic (info
))
7334 /* If there are no references to this symbol that do not use the
7335 GOT, we don't need to generate a copy reloc. */
7336 if (!h
->non_got_ref
)
7339 /* Don't generate a copy reloc for symbols defined in the executable. */
7340 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
7342 /* If -z nocopyreloc was given, don't generate them either. */
7343 || info
->nocopyreloc
7345 /* If we don't find any dynamic relocs in read-only sections, then
7346 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7347 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
7349 /* Protected variables do not work with .dynbss. The copy in
7350 .dynbss won't be used by the shared library with the protected
7351 definition for the variable. Text relocations are preferable
7352 to an incorrect program. */
7353 || h
->protected_def
)
7356 if (h
->plt
.plist
!= NULL
)
7358 /* We should never get here, but unfortunately there are versions
7359 of gcc out there that improperly (for this ABI) put initialized
7360 function pointers, vtable refs and suchlike in read-only
7361 sections. Allow them to proceed, but warn that this might
7362 break at runtime. */
7363 info
->callbacks
->einfo
7364 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
7365 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7366 h
->root
.root
.string
);
7369 /* This is a reference to a symbol defined by a dynamic object which
7370 is not a function. */
7372 /* We must allocate the symbol in our .dynbss section, which will
7373 become part of the .bss section of the executable. There will be
7374 an entry for this symbol in the .dynsym section. The dynamic
7375 object will contain position independent code, so all references
7376 from the dynamic object to this symbol will go through the global
7377 offset table. The dynamic linker will use the .dynsym entry to
7378 determine the address it must put in the global offset table, so
7379 both the dynamic object and the regular object will refer to the
7380 same memory location for the variable. */
7381 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
7383 s
= htab
->elf
.sdynrelro
;
7384 srel
= htab
->elf
.sreldynrelro
;
7388 s
= htab
->elf
.sdynbss
;
7389 srel
= htab
->elf
.srelbss
;
7391 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7393 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
7394 linker to copy the initial value out of the dynamic object
7395 and into the runtime process image. */
7396 srel
->size
+= sizeof (Elf64_External_Rela
);
7400 /* We no longer want dyn_relocs. */
7401 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7402 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7405 /* If given a function descriptor symbol, hide both the function code
7406 sym and the descriptor. */
7408 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
7409 struct elf_link_hash_entry
*h
,
7410 bfd_boolean force_local
)
7412 struct ppc_link_hash_entry
*eh
;
7413 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
7415 eh
= (struct ppc_link_hash_entry
*) h
;
7416 if (eh
->is_func_descriptor
)
7418 struct ppc_link_hash_entry
*fh
= eh
->oh
;
7423 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7426 /* We aren't supposed to use alloca in BFD because on
7427 systems which do not have alloca the version in libiberty
7428 calls xmalloc, which might cause the program to crash
7429 when it runs out of memory. This function doesn't have a
7430 return status, so there's no way to gracefully return an
7431 error. So cheat. We know that string[-1] can be safely
7432 accessed; It's either a string in an ELF string table,
7433 or allocated in an objalloc structure. */
7435 p
= eh
->elf
.root
.root
.string
- 1;
7438 fh
= (struct ppc_link_hash_entry
*)
7439 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7442 /* Unfortunately, if it so happens that the string we were
7443 looking for was allocated immediately before this string,
7444 then we overwrote the string terminator. That's the only
7445 reason the lookup should fail. */
7448 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
7449 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
7451 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
7452 fh
= (struct ppc_link_hash_entry
*)
7453 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7462 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7467 get_sym_h (struct elf_link_hash_entry
**hp
,
7468 Elf_Internal_Sym
**symp
,
7470 unsigned char **tls_maskp
,
7471 Elf_Internal_Sym
**locsymsp
,
7472 unsigned long r_symndx
,
7475 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7477 if (r_symndx
>= symtab_hdr
->sh_info
)
7479 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7480 struct elf_link_hash_entry
*h
;
7482 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7483 h
= elf_follow_link (h
);
7491 if (symsecp
!= NULL
)
7493 asection
*symsec
= NULL
;
7494 if (h
->root
.type
== bfd_link_hash_defined
7495 || h
->root
.type
== bfd_link_hash_defweak
)
7496 symsec
= h
->root
.u
.def
.section
;
7500 if (tls_maskp
!= NULL
)
7502 struct ppc_link_hash_entry
*eh
;
7504 eh
= (struct ppc_link_hash_entry
*) h
;
7505 *tls_maskp
= &eh
->tls_mask
;
7510 Elf_Internal_Sym
*sym
;
7511 Elf_Internal_Sym
*locsyms
= *locsymsp
;
7513 if (locsyms
== NULL
)
7515 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7516 if (locsyms
== NULL
)
7517 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
7518 symtab_hdr
->sh_info
,
7519 0, NULL
, NULL
, NULL
);
7520 if (locsyms
== NULL
)
7522 *locsymsp
= locsyms
;
7524 sym
= locsyms
+ r_symndx
;
7532 if (symsecp
!= NULL
)
7533 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
7535 if (tls_maskp
!= NULL
)
7537 struct got_entry
**lgot_ents
;
7538 unsigned char *tls_mask
;
7541 lgot_ents
= elf_local_got_ents (ibfd
);
7542 if (lgot_ents
!= NULL
)
7544 struct plt_entry
**local_plt
= (struct plt_entry
**)
7545 (lgot_ents
+ symtab_hdr
->sh_info
);
7546 unsigned char *lgot_masks
= (unsigned char *)
7547 (local_plt
+ symtab_hdr
->sh_info
);
7548 tls_mask
= &lgot_masks
[r_symndx
];
7550 *tls_maskp
= tls_mask
;
7556 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7557 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7558 type suitable for optimization, and 1 otherwise. */
7561 get_tls_mask (unsigned char **tls_maskp
,
7562 unsigned long *toc_symndx
,
7563 bfd_vma
*toc_addend
,
7564 Elf_Internal_Sym
**locsymsp
,
7565 const Elf_Internal_Rela
*rel
,
7568 unsigned long r_symndx
;
7570 struct elf_link_hash_entry
*h
;
7571 Elf_Internal_Sym
*sym
;
7575 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7576 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7579 if ((*tls_maskp
!= NULL
7580 && (**tls_maskp
& TLS_TLS
) != 0
7581 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
7583 || ppc64_elf_section_data (sec
) == NULL
7584 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7587 /* Look inside a TOC section too. */
7590 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7591 off
= h
->root
.u
.def
.value
;
7594 off
= sym
->st_value
;
7595 off
+= rel
->r_addend
;
7596 BFD_ASSERT (off
% 8 == 0);
7597 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7598 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7599 if (toc_symndx
!= NULL
)
7600 *toc_symndx
= r_symndx
;
7601 if (toc_addend
!= NULL
)
7602 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7603 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7605 if ((h
== NULL
|| is_static_defined (h
))
7606 && (next_r
== -1 || next_r
== -2))
7611 /* Find (or create) an entry in the tocsave hash table. */
7613 static struct tocsave_entry
*
7614 tocsave_find (struct ppc_link_hash_table
*htab
,
7615 enum insert_option insert
,
7616 Elf_Internal_Sym
**local_syms
,
7617 const Elf_Internal_Rela
*irela
,
7620 unsigned long r_indx
;
7621 struct elf_link_hash_entry
*h
;
7622 Elf_Internal_Sym
*sym
;
7623 struct tocsave_entry ent
, *p
;
7625 struct tocsave_entry
**slot
;
7627 r_indx
= ELF64_R_SYM (irela
->r_info
);
7628 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7630 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7633 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7638 ent
.offset
= h
->root
.u
.def
.value
;
7640 ent
.offset
= sym
->st_value
;
7641 ent
.offset
+= irela
->r_addend
;
7643 hash
= tocsave_htab_hash (&ent
);
7644 slot
= ((struct tocsave_entry
**)
7645 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7651 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7660 /* Adjust all global syms defined in opd sections. In gcc generated
7661 code for the old ABI, these will already have been done. */
7664 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7666 struct ppc_link_hash_entry
*eh
;
7668 struct _opd_sec_data
*opd
;
7670 if (h
->root
.type
== bfd_link_hash_indirect
)
7673 if (h
->root
.type
!= bfd_link_hash_defined
7674 && h
->root
.type
!= bfd_link_hash_defweak
)
7677 eh
= (struct ppc_link_hash_entry
*) h
;
7678 if (eh
->adjust_done
)
7681 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7682 opd
= get_opd_info (sym_sec
);
7683 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7685 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7688 /* This entry has been deleted. */
7689 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7692 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7693 if (discarded_section (dsec
))
7695 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7699 eh
->elf
.root
.u
.def
.value
= 0;
7700 eh
->elf
.root
.u
.def
.section
= dsec
;
7703 eh
->elf
.root
.u
.def
.value
+= adjust
;
7704 eh
->adjust_done
= 1;
7709 /* Handles decrementing dynamic reloc counts for the reloc specified by
7710 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7711 have already been determined. */
7714 dec_dynrel_count (bfd_vma r_info
,
7716 struct bfd_link_info
*info
,
7717 Elf_Internal_Sym
**local_syms
,
7718 struct elf_link_hash_entry
*h
,
7719 Elf_Internal_Sym
*sym
)
7721 enum elf_ppc64_reloc_type r_type
;
7722 asection
*sym_sec
= NULL
;
7724 /* Can this reloc be dynamic? This switch, and later tests here
7725 should be kept in sync with the code in check_relocs. */
7726 r_type
= ELF64_R_TYPE (r_info
);
7732 case R_PPC64_TPREL16
:
7733 case R_PPC64_TPREL16_LO
:
7734 case R_PPC64_TPREL16_HI
:
7735 case R_PPC64_TPREL16_HA
:
7736 case R_PPC64_TPREL16_DS
:
7737 case R_PPC64_TPREL16_LO_DS
:
7738 case R_PPC64_TPREL16_HIGH
:
7739 case R_PPC64_TPREL16_HIGHA
:
7740 case R_PPC64_TPREL16_HIGHER
:
7741 case R_PPC64_TPREL16_HIGHERA
:
7742 case R_PPC64_TPREL16_HIGHEST
:
7743 case R_PPC64_TPREL16_HIGHESTA
:
7744 case R_PPC64_TPREL64
:
7745 case R_PPC64_DTPMOD64
:
7746 case R_PPC64_DTPREL64
:
7747 case R_PPC64_ADDR64
:
7751 case R_PPC64_ADDR14
:
7752 case R_PPC64_ADDR14_BRNTAKEN
:
7753 case R_PPC64_ADDR14_BRTAKEN
:
7754 case R_PPC64_ADDR16
:
7755 case R_PPC64_ADDR16_DS
:
7756 case R_PPC64_ADDR16_HA
:
7757 case R_PPC64_ADDR16_HI
:
7758 case R_PPC64_ADDR16_HIGH
:
7759 case R_PPC64_ADDR16_HIGHA
:
7760 case R_PPC64_ADDR16_HIGHER
:
7761 case R_PPC64_ADDR16_HIGHERA
:
7762 case R_PPC64_ADDR16_HIGHEST
:
7763 case R_PPC64_ADDR16_HIGHESTA
:
7764 case R_PPC64_ADDR16_LO
:
7765 case R_PPC64_ADDR16_LO_DS
:
7766 case R_PPC64_ADDR24
:
7767 case R_PPC64_ADDR32
:
7768 case R_PPC64_UADDR16
:
7769 case R_PPC64_UADDR32
:
7770 case R_PPC64_UADDR64
:
7775 if (local_syms
!= NULL
)
7777 unsigned long r_symndx
;
7778 bfd
*ibfd
= sec
->owner
;
7780 r_symndx
= ELF64_R_SYM (r_info
);
7781 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7785 if ((bfd_link_pic (info
)
7786 && (must_be_dyn_reloc (info
, r_type
)
7788 && (!SYMBOLIC_BIND (info
, h
)
7789 || h
->root
.type
== bfd_link_hash_defweak
7790 || !h
->def_regular
))))
7791 || (ELIMINATE_COPY_RELOCS
7792 && !bfd_link_pic (info
)
7794 && (h
->root
.type
== bfd_link_hash_defweak
7795 || !h
->def_regular
)))
7802 struct elf_dyn_relocs
*p
;
7803 struct elf_dyn_relocs
**pp
;
7804 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
7806 /* elf_gc_sweep may have already removed all dyn relocs associated
7807 with local syms for a given section. Also, symbol flags are
7808 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7809 report a dynreloc miscount. */
7810 if (*pp
== NULL
&& info
->gc_sections
)
7813 while ((p
= *pp
) != NULL
)
7817 if (!must_be_dyn_reloc (info
, r_type
))
7829 struct ppc_dyn_relocs
*p
;
7830 struct ppc_dyn_relocs
**pp
;
7832 bfd_boolean is_ifunc
;
7834 if (local_syms
== NULL
)
7835 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7836 if (sym_sec
== NULL
)
7839 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7840 pp
= (struct ppc_dyn_relocs
**) vpp
;
7842 if (*pp
== NULL
&& info
->gc_sections
)
7845 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7846 while ((p
= *pp
) != NULL
)
7848 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7859 /* xgettext:c-format */
7860 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7862 bfd_set_error (bfd_error_bad_value
);
7866 /* Remove unused Official Procedure Descriptor entries. Currently we
7867 only remove those associated with functions in discarded link-once
7868 sections, or weakly defined functions that have been overridden. It
7869 would be possible to remove many more entries for statically linked
7873 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7876 bfd_boolean some_edited
= FALSE
;
7877 asection
*need_pad
= NULL
;
7878 struct ppc_link_hash_table
*htab
;
7880 htab
= ppc_hash_table (info
);
7884 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7887 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7888 Elf_Internal_Shdr
*symtab_hdr
;
7889 Elf_Internal_Sym
*local_syms
;
7890 struct _opd_sec_data
*opd
;
7891 bfd_boolean need_edit
, add_aux_fields
, broken
;
7892 bfd_size_type cnt_16b
= 0;
7894 if (!is_ppc64_elf (ibfd
))
7897 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7898 if (sec
== NULL
|| sec
->size
== 0)
7901 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7904 if (sec
->output_section
== bfd_abs_section_ptr
)
7907 /* Look through the section relocs. */
7908 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7912 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7914 /* Read the relocations. */
7915 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7917 if (relstart
== NULL
)
7920 /* First run through the relocs to check they are sane, and to
7921 determine whether we need to edit this opd section. */
7925 relend
= relstart
+ sec
->reloc_count
;
7926 for (rel
= relstart
; rel
< relend
; )
7928 enum elf_ppc64_reloc_type r_type
;
7929 unsigned long r_symndx
;
7931 struct elf_link_hash_entry
*h
;
7932 Elf_Internal_Sym
*sym
;
7935 /* .opd contains an array of 16 or 24 byte entries. We're
7936 only interested in the reloc pointing to a function entry
7938 offset
= rel
->r_offset
;
7939 if (rel
+ 1 == relend
7940 || rel
[1].r_offset
!= offset
+ 8)
7942 /* If someone messes with .opd alignment then after a
7943 "ld -r" we might have padding in the middle of .opd.
7944 Also, there's nothing to prevent someone putting
7945 something silly in .opd with the assembler. No .opd
7946 optimization for them! */
7949 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7954 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7955 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7958 /* xgettext:c-format */
7959 (_("%pB: unexpected reloc type %u in .opd section"),
7965 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7966 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7970 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7972 const char *sym_name
;
7974 sym_name
= h
->root
.root
.string
;
7976 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7980 /* xgettext:c-format */
7981 (_("%pB: undefined sym `%s' in .opd section"),
7987 /* opd entries are always for functions defined in the
7988 current input bfd. If the symbol isn't defined in the
7989 input bfd, then we won't be using the function in this
7990 bfd; It must be defined in a linkonce section in another
7991 bfd, or is weak. It's also possible that we are
7992 discarding the function due to a linker script /DISCARD/,
7993 which we test for via the output_section. */
7994 if (sym_sec
->owner
!= ibfd
7995 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7999 if (rel
+ 1 == relend
8000 || (rel
+ 2 < relend
8001 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
8006 if (sec
->size
== offset
+ 24)
8011 if (sec
->size
== offset
+ 16)
8018 else if (rel
+ 1 < relend
8019 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
8020 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
8022 if (rel
[0].r_offset
== offset
+ 16)
8024 else if (rel
[0].r_offset
!= offset
+ 24)
8031 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
8033 if (!broken
&& (need_edit
|| add_aux_fields
))
8035 Elf_Internal_Rela
*write_rel
;
8036 Elf_Internal_Shdr
*rel_hdr
;
8037 bfd_byte
*rptr
, *wptr
;
8038 bfd_byte
*new_contents
;
8041 new_contents
= NULL
;
8042 amt
= OPD_NDX (sec
->size
) * sizeof (long);
8043 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
8044 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
8045 if (opd
->adjust
== NULL
)
8048 /* This seems a waste of time as input .opd sections are all
8049 zeros as generated by gcc, but I suppose there's no reason
8050 this will always be so. We might start putting something in
8051 the third word of .opd entries. */
8052 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
8055 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
8060 if (local_syms
!= NULL
8061 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8063 if (elf_section_data (sec
)->relocs
!= relstart
)
8067 sec
->contents
= loc
;
8068 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8071 elf_section_data (sec
)->relocs
= relstart
;
8073 new_contents
= sec
->contents
;
8076 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
8077 if (new_contents
== NULL
)
8081 wptr
= new_contents
;
8082 rptr
= sec
->contents
;
8083 write_rel
= relstart
;
8084 for (rel
= relstart
; rel
< relend
; )
8086 unsigned long r_symndx
;
8088 struct elf_link_hash_entry
*h
;
8089 struct ppc_link_hash_entry
*fdh
= NULL
;
8090 Elf_Internal_Sym
*sym
;
8092 Elf_Internal_Rela
*next_rel
;
8095 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8096 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8101 if (next_rel
+ 1 == relend
8102 || (next_rel
+ 2 < relend
8103 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
8106 /* See if the .opd entry is full 24 byte or
8107 16 byte (with fd_aux entry overlapped with next
8110 if (next_rel
== relend
)
8112 if (sec
->size
== rel
->r_offset
+ 16)
8115 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
8119 && h
->root
.root
.string
[0] == '.')
8121 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
8124 fdh
= ppc_follow_link (fdh
);
8125 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
8126 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8131 skip
= (sym_sec
->owner
!= ibfd
8132 || sym_sec
->output_section
== bfd_abs_section_ptr
);
8135 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
8137 /* Arrange for the function descriptor sym
8139 fdh
->elf
.root
.u
.def
.value
= 0;
8140 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
8142 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
8144 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
8149 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8153 if (++rel
== next_rel
)
8156 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8157 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8164 /* We'll be keeping this opd entry. */
8169 /* Redefine the function descriptor symbol to
8170 this location in the opd section. It is
8171 necessary to update the value here rather
8172 than using an array of adjustments as we do
8173 for local symbols, because various places
8174 in the generic ELF code use the value
8175 stored in u.def.value. */
8176 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
8177 fdh
->adjust_done
= 1;
8180 /* Local syms are a bit tricky. We could
8181 tweak them as they can be cached, but
8182 we'd need to look through the local syms
8183 for the function descriptor sym which we
8184 don't have at the moment. So keep an
8185 array of adjustments. */
8186 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
8187 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
8190 memcpy (wptr
, rptr
, opd_ent_size
);
8191 wptr
+= opd_ent_size
;
8192 if (add_aux_fields
&& opd_ent_size
== 16)
8194 memset (wptr
, '\0', 8);
8198 /* We need to adjust any reloc offsets to point to the
8200 for ( ; rel
!= next_rel
; ++rel
)
8202 rel
->r_offset
+= adjust
;
8203 if (write_rel
!= rel
)
8204 memcpy (write_rel
, rel
, sizeof (*rel
));
8209 rptr
+= opd_ent_size
;
8212 sec
->size
= wptr
- new_contents
;
8213 sec
->reloc_count
= write_rel
- relstart
;
8216 free (sec
->contents
);
8217 sec
->contents
= new_contents
;
8220 /* Fudge the header size too, as this is used later in
8221 elf_bfd_final_link if we are emitting relocs. */
8222 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
8223 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
8226 else if (elf_section_data (sec
)->relocs
!= relstart
)
8229 if (local_syms
!= NULL
8230 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8232 if (!info
->keep_memory
)
8235 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8240 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
8242 /* If we are doing a final link and the last .opd entry is just 16 byte
8243 long, add a 8 byte padding after it. */
8244 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
8248 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
8250 BFD_ASSERT (need_pad
->size
> 0);
8252 p
= bfd_malloc (need_pad
->size
+ 8);
8256 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
8257 p
, 0, need_pad
->size
))
8260 need_pad
->contents
= p
;
8261 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8265 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
8269 need_pad
->contents
= p
;
8272 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
8273 need_pad
->size
+= 8;
8279 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8282 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
8284 struct ppc_link_hash_table
*htab
;
8286 htab
= ppc_hash_table (info
);
8290 if (abiversion (info
->output_bfd
) == 1)
8293 if (htab
->params
->no_multi_toc
)
8294 htab
->do_multi_toc
= 0;
8295 else if (!htab
->do_multi_toc
)
8296 htab
->params
->no_multi_toc
= 1;
8298 /* Default to --no-plt-localentry, as this option can cause problems
8299 with symbol interposition. For example, glibc libpthread.so and
8300 libc.so duplicate many pthread symbols, with a fallback
8301 implementation in libc.so. In some cases the fallback does more
8302 work than the pthread implementation. __pthread_condattr_destroy
8303 is one such symbol: the libpthread.so implementation is
8304 localentry:0 while the libc.so implementation is localentry:8.
8305 An app that "cleverly" uses dlopen to only load necessary
8306 libraries at runtime may omit loading libpthread.so when not
8307 running multi-threaded, which then results in the libc.so
8308 fallback symbols being used and ld.so complaining. Now there
8309 are workarounds in ld (see non_zero_localentry) to detect the
8310 pthread situation, but that may not be the only case where
8311 --plt-localentry can cause trouble. */
8312 if (htab
->params
->plt_localentry0
< 0)
8313 htab
->params
->plt_localentry0
= 0;
8314 if (htab
->params
->plt_localentry0
8315 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
8316 FALSE
, FALSE
, FALSE
) == NULL
)
8318 (_("warning: --plt-localentry is especially dangerous without "
8319 "ld.so support to detect ABI violations"));
8321 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
8322 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
8323 FALSE
, FALSE
, TRUE
));
8324 /* Move dynamic linking info to the function descriptor sym. */
8325 if (htab
->tls_get_addr
!= NULL
)
8326 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
8327 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
8328 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
8329 FALSE
, FALSE
, TRUE
));
8330 if (htab
->params
->tls_get_addr_opt
)
8332 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
8334 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
8335 FALSE
, FALSE
, TRUE
);
8337 func_desc_adjust (opt
, info
);
8338 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
8339 FALSE
, FALSE
, TRUE
);
8341 && (opt_fd
->root
.type
== bfd_link_hash_defined
8342 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8344 /* If glibc supports an optimized __tls_get_addr call stub,
8345 signalled by the presence of __tls_get_addr_opt, and we'll
8346 be calling __tls_get_addr via a plt call stub, then
8347 make __tls_get_addr point to __tls_get_addr_opt. */
8348 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
8349 if (htab
->elf
.dynamic_sections_created
8351 && (tga_fd
->type
== STT_FUNC
8352 || tga_fd
->needs_plt
)
8353 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8354 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
8356 struct plt_entry
*ent
;
8358 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8359 if (ent
->plt
.refcount
> 0)
8363 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8364 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8365 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8367 if (opt_fd
->dynindx
!= -1)
8369 /* Use __tls_get_addr_opt in dynamic relocations. */
8370 opt_fd
->dynindx
= -1;
8371 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8372 opt_fd
->dynstr_index
);
8373 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8376 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
8377 tga
= &htab
->tls_get_addr
->elf
;
8378 if (opt
!= NULL
&& tga
!= NULL
)
8380 tga
->root
.type
= bfd_link_hash_indirect
;
8381 tga
->root
.u
.i
.link
= &opt
->root
;
8382 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8384 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8386 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
8388 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8389 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8390 if (htab
->tls_get_addr
!= NULL
)
8392 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8393 htab
->tls_get_addr
->is_func
= 1;
8398 else if (htab
->params
->tls_get_addr_opt
< 0)
8399 htab
->params
->tls_get_addr_opt
= 0;
8401 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
8404 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8408 branch_reloc_hash_match (const bfd
*ibfd
,
8409 const Elf_Internal_Rela
*rel
,
8410 const struct ppc_link_hash_entry
*hash1
,
8411 const struct ppc_link_hash_entry
*hash2
)
8413 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8414 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8415 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8417 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8419 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8420 struct elf_link_hash_entry
*h
;
8422 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8423 h
= elf_follow_link (h
);
8424 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
8430 /* Run through all the TLS relocs looking for optimization
8431 opportunities. The linker has been hacked (see ppc64elf.em) to do
8432 a preliminary section layout so that we know the TLS segment
8433 offsets. We can't optimize earlier because some optimizations need
8434 to know the tp offset, and we need to optimize before allocating
8435 dynamic relocations. */
8438 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8442 struct ppc_link_hash_table
*htab
;
8443 unsigned char *toc_ref
;
8446 if (!bfd_link_executable (info
))
8449 htab
= ppc_hash_table (info
);
8453 /* Make two passes over the relocs. On the first pass, mark toc
8454 entries involved with tls relocs, and check that tls relocs
8455 involved in setting up a tls_get_addr call are indeed followed by
8456 such a call. If they are not, we can't do any tls optimization.
8457 On the second pass twiddle tls_mask flags to notify
8458 relocate_section that optimization can be done, and adjust got
8459 and plt refcounts. */
8461 for (pass
= 0; pass
< 2; ++pass
)
8462 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8464 Elf_Internal_Sym
*locsyms
= NULL
;
8465 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8467 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8468 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8470 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8471 bfd_boolean found_tls_get_addr_arg
= 0;
8473 /* Read the relocations. */
8474 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8476 if (relstart
== NULL
)
8482 relend
= relstart
+ sec
->reloc_count
;
8483 for (rel
= relstart
; rel
< relend
; rel
++)
8485 enum elf_ppc64_reloc_type r_type
;
8486 unsigned long r_symndx
;
8487 struct elf_link_hash_entry
*h
;
8488 Elf_Internal_Sym
*sym
;
8490 unsigned char *tls_mask
;
8491 unsigned char tls_set
, tls_clear
, tls_type
= 0;
8493 bfd_boolean ok_tprel
, is_local
;
8494 long toc_ref_index
= 0;
8495 int expecting_tls_get_addr
= 0;
8496 bfd_boolean ret
= FALSE
;
8498 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8499 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8503 if (elf_section_data (sec
)->relocs
!= relstart
)
8505 if (toc_ref
!= NULL
)
8508 && (elf_symtab_hdr (ibfd
).contents
8509 != (unsigned char *) locsyms
))
8516 if (h
->root
.type
== bfd_link_hash_defined
8517 || h
->root
.type
== bfd_link_hash_defweak
)
8518 value
= h
->root
.u
.def
.value
;
8519 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8523 found_tls_get_addr_arg
= 0;
8528 /* Symbols referenced by TLS relocs must be of type
8529 STT_TLS. So no need for .opd local sym adjust. */
8530 value
= sym
->st_value
;
8539 && h
->root
.type
== bfd_link_hash_undefweak
)
8541 else if (sym_sec
!= NULL
8542 && sym_sec
->output_section
!= NULL
)
8544 value
+= sym_sec
->output_offset
;
8545 value
+= sym_sec
->output_section
->vma
;
8546 value
-= htab
->elf
.tls_sec
->vma
;
8547 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
8548 < (bfd_vma
) 1 << 32);
8552 r_type
= ELF64_R_TYPE (rel
->r_info
);
8553 /* If this section has old-style __tls_get_addr calls
8554 without marker relocs, then check that each
8555 __tls_get_addr call reloc is preceded by a reloc
8556 that conceivably belongs to the __tls_get_addr arg
8557 setup insn. If we don't find matching arg setup
8558 relocs, don't do any tls optimization. */
8560 && sec
->has_tls_get_addr_call
8562 && (h
== &htab
->tls_get_addr
->elf
8563 || h
== &htab
->tls_get_addr_fd
->elf
)
8564 && !found_tls_get_addr_arg
8565 && is_branch_reloc (r_type
))
8567 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8568 "TLS optimization disabled\n"),
8569 ibfd
, sec
, rel
->r_offset
);
8574 found_tls_get_addr_arg
= 0;
8577 case R_PPC64_GOT_TLSLD16
:
8578 case R_PPC64_GOT_TLSLD16_LO
:
8579 expecting_tls_get_addr
= 1;
8580 found_tls_get_addr_arg
= 1;
8583 case R_PPC64_GOT_TLSLD16_HI
:
8584 case R_PPC64_GOT_TLSLD16_HA
:
8585 /* These relocs should never be against a symbol
8586 defined in a shared lib. Leave them alone if
8587 that turns out to be the case. */
8594 tls_type
= TLS_TLS
| TLS_LD
;
8597 case R_PPC64_GOT_TLSGD16
:
8598 case R_PPC64_GOT_TLSGD16_LO
:
8599 expecting_tls_get_addr
= 1;
8600 found_tls_get_addr_arg
= 1;
8603 case R_PPC64_GOT_TLSGD16_HI
:
8604 case R_PPC64_GOT_TLSGD16_HA
:
8610 tls_set
= TLS_TLS
| TLS_TPRELGD
;
8612 tls_type
= TLS_TLS
| TLS_GD
;
8615 case R_PPC64_GOT_TPREL16_DS
:
8616 case R_PPC64_GOT_TPREL16_LO_DS
:
8617 case R_PPC64_GOT_TPREL16_HI
:
8618 case R_PPC64_GOT_TPREL16_HA
:
8623 tls_clear
= TLS_TPREL
;
8624 tls_type
= TLS_TLS
| TLS_TPREL
;
8631 if (rel
+ 1 < relend
8632 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8635 && ELF64_R_TYPE (rel
[1].r_info
) != R_PPC64_PLTSEQ
)
8637 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8638 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8643 struct plt_entry
*ent
= NULL
;
8645 for (ent
= h
->plt
.plist
;
8648 if (ent
->addend
== rel
[1].r_addend
)
8652 && ent
->plt
.refcount
> 0)
8653 ent
->plt
.refcount
-= 1;
8658 found_tls_get_addr_arg
= 1;
8663 case R_PPC64_TOC16_LO
:
8664 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8667 /* Mark this toc entry as referenced by a TLS
8668 code sequence. We can do that now in the
8669 case of R_PPC64_TLS, and after checking for
8670 tls_get_addr for the TOC16 relocs. */
8671 if (toc_ref
== NULL
)
8672 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8673 if (toc_ref
== NULL
)
8677 value
= h
->root
.u
.def
.value
;
8679 value
= sym
->st_value
;
8680 value
+= rel
->r_addend
;
8683 BFD_ASSERT (value
< toc
->size
8684 && toc
->output_offset
% 8 == 0);
8685 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8686 if (r_type
== R_PPC64_TLS
8687 || r_type
== R_PPC64_TLSGD
8688 || r_type
== R_PPC64_TLSLD
)
8690 toc_ref
[toc_ref_index
] = 1;
8694 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8699 expecting_tls_get_addr
= 2;
8702 case R_PPC64_TPREL64
:
8706 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8711 tls_set
= TLS_EXPLICIT
;
8712 tls_clear
= TLS_TPREL
;
8717 case R_PPC64_DTPMOD64
:
8721 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8723 if (rel
+ 1 < relend
8725 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8726 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8730 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8733 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
8742 tls_set
= TLS_EXPLICIT
;
8753 if (!expecting_tls_get_addr
8754 || !sec
->has_tls_get_addr_call
)
8757 if (rel
+ 1 < relend
8758 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8760 htab
->tls_get_addr_fd
))
8762 if (expecting_tls_get_addr
== 2)
8764 /* Check for toc tls entries. */
8765 unsigned char *toc_tls
;
8768 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8773 if (toc_tls
!= NULL
)
8775 if ((*toc_tls
& TLS_TLS
) != 0
8776 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8777 found_tls_get_addr_arg
= 1;
8779 toc_ref
[toc_ref_index
] = 1;
8785 /* Uh oh, we didn't find the expected call. We
8786 could just mark this symbol to exclude it
8787 from tls optimization but it's safer to skip
8788 the entire optimization. */
8789 /* xgettext:c-format */
8790 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8791 "TLS optimization disabled\n"),
8792 ibfd
, sec
, rel
->r_offset
);
8797 /* If we don't have old-style __tls_get_addr calls
8798 without TLSGD/TLSLD marker relocs, and we haven't
8799 found a new-style __tls_get_addr call with a
8800 marker for this symbol, then we either have a
8801 broken object file or an -mlongcall style
8802 indirect call to __tls_get_addr without a marker.
8803 Disable optimization in this case. */
8804 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8805 && (tls_set
& TLS_EXPLICIT
) == 0
8806 && !sec
->has_tls_get_addr_call
8807 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8808 != (TLS_TLS
| TLS_MARK
)))
8811 if (expecting_tls_get_addr
)
8813 struct plt_entry
*ent
= NULL
;
8815 if (htab
->tls_get_addr
!= NULL
)
8816 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8819 if (ent
->addend
== 0)
8822 if (ent
== NULL
&& htab
->tls_get_addr_fd
!= NULL
)
8823 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8826 if (ent
->addend
== 0)
8830 && ent
->plt
.refcount
> 0)
8831 ent
->plt
.refcount
-= 1;
8837 if ((tls_set
& TLS_EXPLICIT
) == 0)
8839 struct got_entry
*ent
;
8841 /* Adjust got entry for this reloc. */
8845 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8847 for (; ent
!= NULL
; ent
= ent
->next
)
8848 if (ent
->addend
== rel
->r_addend
8849 && ent
->owner
== ibfd
8850 && ent
->tls_type
== tls_type
)
8857 /* We managed to get rid of a got entry. */
8858 if (ent
->got
.refcount
> 0)
8859 ent
->got
.refcount
-= 1;
8864 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8865 we'll lose one or two dyn relocs. */
8866 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8870 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8872 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8878 *tls_mask
|= tls_set
;
8879 *tls_mask
&= ~tls_clear
;
8882 if (elf_section_data (sec
)->relocs
!= relstart
)
8887 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8889 if (!info
->keep_memory
)
8892 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8896 if (toc_ref
!= NULL
)
8898 htab
->do_tls_opt
= 1;
8902 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8903 the values of any global symbols in a toc section that has been
8904 edited. Globals in toc sections should be a rarity, so this function
8905 sets a flag if any are found in toc sections other than the one just
8906 edited, so that further hash table traversals can be avoided. */
8908 struct adjust_toc_info
8911 unsigned long *skip
;
8912 bfd_boolean global_toc_syms
;
8915 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8918 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8920 struct ppc_link_hash_entry
*eh
;
8921 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8924 if (h
->root
.type
!= bfd_link_hash_defined
8925 && h
->root
.type
!= bfd_link_hash_defweak
)
8928 eh
= (struct ppc_link_hash_entry
*) h
;
8929 if (eh
->adjust_done
)
8932 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8934 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8935 i
= toc_inf
->toc
->rawsize
>> 3;
8937 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8939 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8942 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8945 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8946 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8949 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8950 eh
->adjust_done
= 1;
8952 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8953 toc_inf
->global_toc_syms
= TRUE
;
8958 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
8959 on a _LO variety toc/got reloc. */
8962 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
8964 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
8965 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
8966 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8967 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8968 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8969 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8970 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8971 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8972 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8973 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8974 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8975 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8976 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8977 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8978 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8979 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
8980 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
8981 /* Exclude lfqu by testing reloc. If relocs are ever
8982 defined for the reduced D field in psq_lu then those
8983 will need testing too. */
8984 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8985 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
8987 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
8988 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
8989 /* Exclude stfqu. psq_stu as above for psq_lu. */
8990 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
8991 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
8992 && (insn
& 1) == 0));
8995 /* Examine all relocs referencing .toc sections in order to remove
8996 unused .toc entries. */
8999 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
9002 struct adjust_toc_info toc_inf
;
9003 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9005 htab
->do_toc_opt
= 1;
9006 toc_inf
.global_toc_syms
= TRUE
;
9007 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9009 asection
*toc
, *sec
;
9010 Elf_Internal_Shdr
*symtab_hdr
;
9011 Elf_Internal_Sym
*local_syms
;
9012 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
9013 unsigned long *skip
, *drop
;
9014 unsigned char *used
;
9015 unsigned char *keep
, last
, some_unused
;
9017 if (!is_ppc64_elf (ibfd
))
9020 toc
= bfd_get_section_by_name (ibfd
, ".toc");
9023 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
9024 || discarded_section (toc
))
9029 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9031 /* Look at sections dropped from the final link. */
9034 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9036 if (sec
->reloc_count
== 0
9037 || !discarded_section (sec
)
9038 || get_opd_info (sec
)
9039 || (sec
->flags
& SEC_ALLOC
) == 0
9040 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9043 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
9044 if (relstart
== NULL
)
9047 /* Run through the relocs to see which toc entries might be
9049 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9051 enum elf_ppc64_reloc_type r_type
;
9052 unsigned long r_symndx
;
9054 struct elf_link_hash_entry
*h
;
9055 Elf_Internal_Sym
*sym
;
9058 r_type
= ELF64_R_TYPE (rel
->r_info
);
9065 case R_PPC64_TOC16_LO
:
9066 case R_PPC64_TOC16_HI
:
9067 case R_PPC64_TOC16_HA
:
9068 case R_PPC64_TOC16_DS
:
9069 case R_PPC64_TOC16_LO_DS
:
9073 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9074 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9082 val
= h
->root
.u
.def
.value
;
9084 val
= sym
->st_value
;
9085 val
+= rel
->r_addend
;
9087 if (val
>= toc
->size
)
9090 /* Anything in the toc ought to be aligned to 8 bytes.
9091 If not, don't mark as unused. */
9097 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9102 skip
[val
>> 3] = ref_from_discarded
;
9105 if (elf_section_data (sec
)->relocs
!= relstart
)
9109 /* For largetoc loads of address constants, we can convert
9110 . addis rx,2,addr@got@ha
9111 . ld ry,addr@got@l(rx)
9113 . addis rx,2,addr@toc@ha
9114 . addi ry,rx,addr@toc@l
9115 when addr is within 2G of the toc pointer. This then means
9116 that the word storing "addr" in the toc is no longer needed. */
9118 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9119 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9120 && toc
->reloc_count
!= 0)
9122 /* Read toc relocs. */
9123 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9125 if (toc_relocs
== NULL
)
9128 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9130 enum elf_ppc64_reloc_type r_type
;
9131 unsigned long r_symndx
;
9133 struct elf_link_hash_entry
*h
;
9134 Elf_Internal_Sym
*sym
;
9137 r_type
= ELF64_R_TYPE (rel
->r_info
);
9138 if (r_type
!= R_PPC64_ADDR64
)
9141 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9142 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9147 || sym_sec
->output_section
== NULL
9148 || discarded_section (sym_sec
))
9151 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9156 if (h
->type
== STT_GNU_IFUNC
)
9158 val
= h
->root
.u
.def
.value
;
9162 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9164 val
= sym
->st_value
;
9166 val
+= rel
->r_addend
;
9167 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9169 /* We don't yet know the exact toc pointer value, but we
9170 know it will be somewhere in the toc section. Don't
9171 optimize if the difference from any possible toc
9172 pointer is outside [ff..f80008000, 7fff7fff]. */
9173 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9174 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9177 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9178 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9183 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9188 skip
[rel
->r_offset
>> 3]
9189 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9196 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9200 if (local_syms
!= NULL
9201 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9205 && elf_section_data (sec
)->relocs
!= relstart
)
9207 if (toc_relocs
!= NULL
9208 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9215 /* Now check all kept sections that might reference the toc.
9216 Check the toc itself last. */
9217 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9220 sec
= (sec
== toc
? NULL
9221 : sec
->next
== NULL
? toc
9222 : sec
->next
== toc
&& toc
->next
? toc
->next
9227 if (sec
->reloc_count
== 0
9228 || discarded_section (sec
)
9229 || get_opd_info (sec
)
9230 || (sec
->flags
& SEC_ALLOC
) == 0
9231 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9234 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9236 if (relstart
== NULL
)
9242 /* Mark toc entries referenced as used. */
9246 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9248 enum elf_ppc64_reloc_type r_type
;
9249 unsigned long r_symndx
;
9251 struct elf_link_hash_entry
*h
;
9252 Elf_Internal_Sym
*sym
;
9254 enum {no_check
, check_lo
, check_ha
} insn_check
;
9256 r_type
= ELF64_R_TYPE (rel
->r_info
);
9260 insn_check
= no_check
;
9263 case R_PPC64_GOT_TLSLD16_HA
:
9264 case R_PPC64_GOT_TLSGD16_HA
:
9265 case R_PPC64_GOT_TPREL16_HA
:
9266 case R_PPC64_GOT_DTPREL16_HA
:
9267 case R_PPC64_GOT16_HA
:
9268 case R_PPC64_TOC16_HA
:
9269 insn_check
= check_ha
;
9272 case R_PPC64_GOT_TLSLD16_LO
:
9273 case R_PPC64_GOT_TLSGD16_LO
:
9274 case R_PPC64_GOT_TPREL16_LO_DS
:
9275 case R_PPC64_GOT_DTPREL16_LO_DS
:
9276 case R_PPC64_GOT16_LO
:
9277 case R_PPC64_GOT16_LO_DS
:
9278 case R_PPC64_TOC16_LO
:
9279 case R_PPC64_TOC16_LO_DS
:
9280 insn_check
= check_lo
;
9284 if (insn_check
!= no_check
)
9286 bfd_vma off
= rel
->r_offset
& ~3;
9287 unsigned char buf
[4];
9290 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9295 insn
= bfd_get_32 (ibfd
, buf
);
9296 if (insn_check
== check_lo
9297 ? !ok_lo_toc_insn (insn
, r_type
)
9298 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9299 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9303 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9304 sprintf (str
, "%#08x", insn
);
9305 info
->callbacks
->einfo
9306 /* xgettext:c-format */
9307 (_("%H: toc optimization is not supported for"
9308 " %s instruction\n"),
9309 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9316 case R_PPC64_TOC16_LO
:
9317 case R_PPC64_TOC16_HI
:
9318 case R_PPC64_TOC16_HA
:
9319 case R_PPC64_TOC16_DS
:
9320 case R_PPC64_TOC16_LO_DS
:
9321 /* In case we're taking addresses of toc entries. */
9322 case R_PPC64_ADDR64
:
9329 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9330 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9341 val
= h
->root
.u
.def
.value
;
9343 val
= sym
->st_value
;
9344 val
+= rel
->r_addend
;
9346 if (val
>= toc
->size
)
9349 if ((skip
[val
>> 3] & can_optimize
) != 0)
9356 case R_PPC64_TOC16_HA
:
9359 case R_PPC64_TOC16_LO_DS
:
9360 off
= rel
->r_offset
;
9361 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9362 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9368 if ((opc
& (0x3f << 2)) == (58u << 2))
9373 /* Wrong sort of reloc, or not a ld. We may
9374 as well clear ref_from_discarded too. */
9381 /* For the toc section, we only mark as used if this
9382 entry itself isn't unused. */
9383 else if ((used
[rel
->r_offset
>> 3]
9384 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9387 /* Do all the relocs again, to catch reference
9396 if (elf_section_data (sec
)->relocs
!= relstart
)
9400 /* Merge the used and skip arrays. Assume that TOC
9401 doublewords not appearing as either used or unused belong
9402 to an entry more than one doubleword in size. */
9403 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9404 drop
< skip
+ (toc
->size
+ 7) / 8;
9409 *drop
&= ~ref_from_discarded
;
9410 if ((*drop
& can_optimize
) != 0)
9414 else if ((*drop
& ref_from_discarded
) != 0)
9417 last
= ref_from_discarded
;
9427 bfd_byte
*contents
, *src
;
9429 Elf_Internal_Sym
*sym
;
9430 bfd_boolean local_toc_syms
= FALSE
;
9432 /* Shuffle the toc contents, and at the same time convert the
9433 skip array from booleans into offsets. */
9434 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9437 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9439 for (src
= contents
, off
= 0, drop
= skip
;
9440 src
< contents
+ toc
->size
;
9443 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9448 memcpy (src
- off
, src
, 8);
9452 toc
->rawsize
= toc
->size
;
9453 toc
->size
= src
- contents
- off
;
9455 /* Adjust addends for relocs against the toc section sym,
9456 and optimize any accesses we can. */
9457 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9459 if (sec
->reloc_count
== 0
9460 || discarded_section (sec
))
9463 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9465 if (relstart
== NULL
)
9468 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9470 enum elf_ppc64_reloc_type r_type
;
9471 unsigned long r_symndx
;
9473 struct elf_link_hash_entry
*h
;
9476 r_type
= ELF64_R_TYPE (rel
->r_info
);
9483 case R_PPC64_TOC16_LO
:
9484 case R_PPC64_TOC16_HI
:
9485 case R_PPC64_TOC16_HA
:
9486 case R_PPC64_TOC16_DS
:
9487 case R_PPC64_TOC16_LO_DS
:
9488 case R_PPC64_ADDR64
:
9492 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9493 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9501 val
= h
->root
.u
.def
.value
;
9504 val
= sym
->st_value
;
9506 local_toc_syms
= TRUE
;
9509 val
+= rel
->r_addend
;
9511 if (val
> toc
->rawsize
)
9513 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9515 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9517 Elf_Internal_Rela
*tocrel
9518 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9519 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9523 case R_PPC64_TOC16_HA
:
9524 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9527 case R_PPC64_TOC16_LO_DS
:
9528 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9532 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9534 info
->callbacks
->einfo
9535 /* xgettext:c-format */
9536 (_("%H: %s references "
9537 "optimized away TOC entry\n"),
9538 ibfd
, sec
, rel
->r_offset
,
9539 ppc64_elf_howto_table
[r_type
]->name
);
9540 bfd_set_error (bfd_error_bad_value
);
9543 rel
->r_addend
= tocrel
->r_addend
;
9544 elf_section_data (sec
)->relocs
= relstart
;
9548 if (h
!= NULL
|| sym
->st_value
!= 0)
9551 rel
->r_addend
-= skip
[val
>> 3];
9552 elf_section_data (sec
)->relocs
= relstart
;
9555 if (elf_section_data (sec
)->relocs
!= relstart
)
9559 /* We shouldn't have local or global symbols defined in the TOC,
9560 but handle them anyway. */
9561 if (local_syms
!= NULL
)
9562 for (sym
= local_syms
;
9563 sym
< local_syms
+ symtab_hdr
->sh_info
;
9565 if (sym
->st_value
!= 0
9566 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9570 if (sym
->st_value
> toc
->rawsize
)
9571 i
= toc
->rawsize
>> 3;
9573 i
= sym
->st_value
>> 3;
9575 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9579 (_("%s defined on removed toc entry"),
9580 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9583 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9584 sym
->st_value
= (bfd_vma
) i
<< 3;
9587 sym
->st_value
-= skip
[i
];
9588 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9591 /* Adjust any global syms defined in this toc input section. */
9592 if (toc_inf
.global_toc_syms
)
9595 toc_inf
.skip
= skip
;
9596 toc_inf
.global_toc_syms
= FALSE
;
9597 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9601 if (toc
->reloc_count
!= 0)
9603 Elf_Internal_Shdr
*rel_hdr
;
9604 Elf_Internal_Rela
*wrel
;
9607 /* Remove unused toc relocs, and adjust those we keep. */
9608 if (toc_relocs
== NULL
)
9609 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9611 if (toc_relocs
== NULL
)
9615 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9616 if ((skip
[rel
->r_offset
>> 3]
9617 & (ref_from_discarded
| can_optimize
)) == 0)
9619 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9620 wrel
->r_info
= rel
->r_info
;
9621 wrel
->r_addend
= rel
->r_addend
;
9624 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9625 &local_syms
, NULL
, NULL
))
9628 elf_section_data (toc
)->relocs
= toc_relocs
;
9629 toc
->reloc_count
= wrel
- toc_relocs
;
9630 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9631 sz
= rel_hdr
->sh_entsize
;
9632 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9635 else if (toc_relocs
!= NULL
9636 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9639 if (local_syms
!= NULL
9640 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9642 if (!info
->keep_memory
)
9645 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9653 /* Return true iff input section I references the TOC using
9654 instructions limited to +/-32k offsets. */
9657 ppc64_elf_has_small_toc_reloc (asection
*i
)
9659 return (is_ppc64_elf (i
->owner
)
9660 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9663 /* Allocate space for one GOT entry. */
9666 allocate_got (struct elf_link_hash_entry
*h
,
9667 struct bfd_link_info
*info
,
9668 struct got_entry
*gent
)
9670 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9671 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
9672 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9674 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9675 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9676 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9678 gent
->got
.offset
= got
->size
;
9679 got
->size
+= entsize
;
9681 if (h
->type
== STT_GNU_IFUNC
)
9683 htab
->elf
.irelplt
->size
+= rentsize
;
9684 htab
->got_reli_size
+= rentsize
;
9686 else if (((bfd_link_pic (info
)
9687 && !((gent
->tls_type
& TLS_TPREL
) != 0
9688 && bfd_link_executable (info
)
9689 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9690 || (htab
->elf
.dynamic_sections_created
9692 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9693 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9695 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9696 relgot
->size
+= rentsize
;
9700 /* This function merges got entries in the same toc group. */
9703 merge_got_entries (struct got_entry
**pent
)
9705 struct got_entry
*ent
, *ent2
;
9707 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9708 if (!ent
->is_indirect
)
9709 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9710 if (!ent2
->is_indirect
9711 && ent2
->addend
== ent
->addend
9712 && ent2
->tls_type
== ent
->tls_type
9713 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9715 ent2
->is_indirect
= TRUE
;
9716 ent2
->got
.ent
= ent
;
9720 /* If H is undefined, make it dynamic if that makes sense. */
9723 ensure_undef_dynamic (struct bfd_link_info
*info
,
9724 struct elf_link_hash_entry
*h
)
9726 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9728 if (htab
->dynamic_sections_created
9729 && ((info
->dynamic_undefined_weak
!= 0
9730 && h
->root
.type
== bfd_link_hash_undefweak
)
9731 || h
->root
.type
== bfd_link_hash_undefined
)
9734 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9735 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9739 /* Allocate space in .plt, .got and associated reloc sections for
9743 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9745 struct bfd_link_info
*info
;
9746 struct ppc_link_hash_table
*htab
;
9748 struct ppc_link_hash_entry
*eh
;
9749 struct got_entry
**pgent
, *gent
;
9751 if (h
->root
.type
== bfd_link_hash_indirect
)
9754 info
= (struct bfd_link_info
*) inf
;
9755 htab
= ppc_hash_table (info
);
9759 eh
= (struct ppc_link_hash_entry
*) h
;
9760 /* Run through the TLS GD got entries first if we're changing them
9762 if ((eh
->tls_mask
& (TLS_TLS
| TLS_TPRELGD
)) == (TLS_TLS
| TLS_TPRELGD
))
9763 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9764 if (gent
->got
.refcount
> 0
9765 && (gent
->tls_type
& TLS_GD
) != 0)
9767 /* This was a GD entry that has been converted to TPREL. If
9768 there happens to be a TPREL entry we can use that one. */
9769 struct got_entry
*ent
;
9770 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9771 if (ent
->got
.refcount
> 0
9772 && (ent
->tls_type
& TLS_TPREL
) != 0
9773 && ent
->addend
== gent
->addend
9774 && ent
->owner
== gent
->owner
)
9776 gent
->got
.refcount
= 0;
9780 /* If not, then we'll be using our own TPREL entry. */
9781 if (gent
->got
.refcount
!= 0)
9782 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9785 /* Remove any list entry that won't generate a word in the GOT before
9786 we call merge_got_entries. Otherwise we risk merging to empty
9788 pgent
= &h
->got
.glist
;
9789 while ((gent
= *pgent
) != NULL
)
9790 if (gent
->got
.refcount
> 0)
9792 if ((gent
->tls_type
& TLS_LD
) != 0
9795 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9796 *pgent
= gent
->next
;
9799 pgent
= &gent
->next
;
9802 *pgent
= gent
->next
;
9804 if (!htab
->do_multi_toc
)
9805 merge_got_entries (&h
->got
.glist
);
9807 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9808 if (!gent
->is_indirect
)
9810 /* Make sure this symbol is output as a dynamic symbol. */
9811 if (!ensure_undef_dynamic (info
, h
))
9814 if (!is_ppc64_elf (gent
->owner
))
9817 allocate_got (h
, info
, gent
);
9820 /* If no dynamic sections we can't have dynamic relocs, except for
9821 IFUNCs which are handled even in static executables. */
9822 if (!htab
->elf
.dynamic_sections_created
9823 && h
->type
!= STT_GNU_IFUNC
)
9824 eh
->dyn_relocs
= NULL
;
9826 /* Discard relocs on undefined symbols that must be local. */
9827 else if (h
->root
.type
== bfd_link_hash_undefined
9828 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9829 eh
->dyn_relocs
= NULL
;
9831 /* Also discard relocs on undefined weak syms with non-default
9832 visibility, or when dynamic_undefined_weak says so. */
9833 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9834 eh
->dyn_relocs
= NULL
;
9836 if (eh
->dyn_relocs
!= NULL
)
9838 struct elf_dyn_relocs
*p
, **pp
;
9840 /* In the shared -Bsymbolic case, discard space allocated for
9841 dynamic pc-relative relocs against symbols which turn out to
9842 be defined in regular objects. For the normal shared case,
9843 discard space for relocs that have become local due to symbol
9844 visibility changes. */
9846 if (bfd_link_pic (info
))
9848 /* Relocs that use pc_count are those that appear on a call
9849 insn, or certain REL relocs (see must_be_dyn_reloc) that
9850 can be generated via assembly. We want calls to
9851 protected symbols to resolve directly to the function
9852 rather than going via the plt. If people want function
9853 pointer comparisons to work as expected then they should
9854 avoid writing weird assembly. */
9855 if (SYMBOL_CALLS_LOCAL (info
, h
))
9857 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
9859 p
->count
-= p
->pc_count
;
9868 if (eh
->dyn_relocs
!= NULL
)
9870 /* Make sure this symbol is output as a dynamic symbol. */
9871 if (!ensure_undef_dynamic (info
, h
))
9875 else if (ELIMINATE_COPY_RELOCS
&& h
->type
!= STT_GNU_IFUNC
)
9877 /* For the non-pic case, discard space for relocs against
9878 symbols which turn out to need copy relocs or are not
9880 if (h
->dynamic_adjusted
9882 && !ELF_COMMON_DEF_P (h
))
9884 /* Make sure this symbol is output as a dynamic symbol. */
9885 if (!ensure_undef_dynamic (info
, h
))
9888 if (h
->dynindx
== -1)
9889 eh
->dyn_relocs
= NULL
;
9892 eh
->dyn_relocs
= NULL
;
9895 /* Finally, allocate space. */
9896 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9898 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9899 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9900 sreloc
= htab
->elf
.irelplt
;
9901 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9905 /* We might need a PLT entry when the symbol
9908 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
9909 d) has plt16 relocs and we are linking statically. */
9910 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
9911 || h
->type
== STT_GNU_IFUNC
9912 || (h
->needs_plt
&& h
->dynamic_adjusted
)
9915 && !htab
->elf
.dynamic_sections_created
9916 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
9917 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
9919 struct plt_entry
*pent
;
9920 bfd_boolean doneone
= FALSE
;
9921 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9922 if (pent
->plt
.refcount
> 0)
9924 if (!htab
->elf
.dynamic_sections_created
9925 || h
->dynindx
== -1)
9927 if (h
->type
== STT_GNU_IFUNC
)
9930 pent
->plt
.offset
= s
->size
;
9931 s
->size
+= PLT_ENTRY_SIZE (htab
);
9932 s
= htab
->elf
.irelplt
;
9937 pent
->plt
.offset
= s
->size
;
9938 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
9939 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
9944 /* If this is the first .plt entry, make room for the special
9948 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9950 pent
->plt
.offset
= s
->size
;
9952 /* Make room for this entry. */
9953 s
->size
+= PLT_ENTRY_SIZE (htab
);
9955 /* Make room for the .glink code. */
9958 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
9961 /* We need bigger stubs past index 32767. */
9962 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
9969 /* We also need to make an entry in the .rela.plt section. */
9970 s
= htab
->elf
.srelplt
;
9973 s
->size
+= sizeof (Elf64_External_Rela
);
9977 pent
->plt
.offset
= (bfd_vma
) -1;
9980 h
->plt
.plist
= NULL
;
9986 h
->plt
.plist
= NULL
;
9993 #define PPC_LO(v) ((v) & 0xffff)
9994 #define PPC_HI(v) (((v) >> 16) & 0xffff)
9995 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
9997 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9998 to set up space for global entry stubs. These are put in glink,
9999 after the branch table. */
10002 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
10004 struct bfd_link_info
*info
;
10005 struct ppc_link_hash_table
*htab
;
10006 struct plt_entry
*pent
;
10009 if (h
->root
.type
== bfd_link_hash_indirect
)
10012 if (!h
->pointer_equality_needed
)
10015 if (h
->def_regular
)
10019 htab
= ppc_hash_table (info
);
10023 s
= htab
->global_entry
;
10024 plt
= htab
->elf
.splt
;
10025 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10026 if (pent
->plt
.offset
!= (bfd_vma
) -1
10027 && pent
->addend
== 0)
10029 /* For ELFv2, if this symbol is not defined in a regular file
10030 and we are not generating a shared library or pie, then we
10031 need to define the symbol in the executable on a call stub.
10032 This is to avoid text relocations. */
10033 bfd_vma off
, stub_align
, stub_off
, stub_size
;
10034 unsigned int align_power
;
10037 stub_off
= s
->size
;
10038 if (htab
->params
->plt_stub_align
>= 0)
10039 align_power
= htab
->params
->plt_stub_align
;
10041 align_power
= -htab
->params
->plt_stub_align
;
10042 /* Setting section alignment is delayed until we know it is
10043 non-empty. Otherwise the .text output section will be
10044 aligned at least to plt_stub_align even when no global
10045 entry stubs are needed. */
10046 if (s
->alignment_power
< align_power
)
10047 s
->alignment_power
= align_power
;
10048 stub_align
= (bfd_vma
) 1 << align_power
;
10049 if (htab
->params
->plt_stub_align
>= 0
10050 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
10051 - (stub_off
& -stub_align
))
10052 > ((stub_size
- 1) & -stub_align
)))
10053 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
10054 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
10055 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
10056 /* Note that for --plt-stub-align negative we have a possible
10057 dependency between stub offset and size. Break that
10058 dependency by assuming the max stub size when calculating
10059 the stub offset. */
10060 if (PPC_HA (off
) == 0)
10062 h
->root
.type
= bfd_link_hash_defined
;
10063 h
->root
.u
.def
.section
= s
;
10064 h
->root
.u
.def
.value
= stub_off
;
10065 s
->size
= stub_off
+ stub_size
;
10071 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
10072 read-only sections. */
10075 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
10079 if (h
->root
.type
== bfd_link_hash_indirect
)
10082 sec
= readonly_dynrelocs (h
);
10085 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
10087 info
->flags
|= DF_TEXTREL
;
10088 info
->callbacks
->minfo
10089 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
10090 sec
->owner
, h
->root
.root
.string
, sec
);
10092 /* Not an error, just cut short the traversal. */
10098 /* Set the sizes of the dynamic sections. */
10101 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10102 struct bfd_link_info
*info
)
10104 struct ppc_link_hash_table
*htab
;
10107 bfd_boolean relocs
;
10109 struct got_entry
*first_tlsld
;
10111 htab
= ppc_hash_table (info
);
10115 dynobj
= htab
->elf
.dynobj
;
10116 if (dynobj
== NULL
)
10119 if (htab
->elf
.dynamic_sections_created
)
10121 /* Set the contents of the .interp section to the interpreter. */
10122 if (bfd_link_executable (info
) && !info
->nointerp
)
10124 s
= bfd_get_linker_section (dynobj
, ".interp");
10127 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10128 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10132 /* Set up .got offsets for local syms, and space for local dynamic
10134 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10136 struct got_entry
**lgot_ents
;
10137 struct got_entry
**end_lgot_ents
;
10138 struct plt_entry
**local_plt
;
10139 struct plt_entry
**end_local_plt
;
10140 unsigned char *lgot_masks
;
10141 bfd_size_type locsymcount
;
10142 Elf_Internal_Shdr
*symtab_hdr
;
10144 if (!is_ppc64_elf (ibfd
))
10147 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10149 struct ppc_dyn_relocs
*p
;
10151 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10153 if (!bfd_is_abs_section (p
->sec
)
10154 && bfd_is_abs_section (p
->sec
->output_section
))
10156 /* Input section has been discarded, either because
10157 it is a copy of a linkonce section or due to
10158 linker script /DISCARD/, so we'll be discarding
10161 else if (p
->count
!= 0)
10163 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
10165 srel
= htab
->elf
.irelplt
;
10166 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10167 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10168 info
->flags
|= DF_TEXTREL
;
10173 lgot_ents
= elf_local_got_ents (ibfd
);
10177 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10178 locsymcount
= symtab_hdr
->sh_info
;
10179 end_lgot_ents
= lgot_ents
+ locsymcount
;
10180 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10181 end_local_plt
= local_plt
+ locsymcount
;
10182 lgot_masks
= (unsigned char *) end_local_plt
;
10183 s
= ppc64_elf_tdata (ibfd
)->got
;
10184 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10186 struct got_entry
**pent
, *ent
;
10189 while ((ent
= *pent
) != NULL
)
10190 if (ent
->got
.refcount
> 0)
10192 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10194 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10199 unsigned int ent_size
= 8;
10200 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10202 ent
->got
.offset
= s
->size
;
10203 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10208 s
->size
+= ent_size
;
10209 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10211 htab
->elf
.irelplt
->size
+= rel_size
;
10212 htab
->got_reli_size
+= rel_size
;
10214 else if (bfd_link_pic (info
)
10215 && !((ent
->tls_type
& TLS_TPREL
) != 0
10216 && bfd_link_executable (info
)))
10218 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10219 srel
->size
+= rel_size
;
10228 /* Allocate space for plt calls to local syms. */
10229 lgot_masks
= (unsigned char *) end_local_plt
;
10230 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10232 struct plt_entry
*ent
;
10234 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10235 if (ent
->plt
.refcount
> 0)
10237 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10239 s
= htab
->elf
.iplt
;
10240 ent
->plt
.offset
= s
->size
;
10241 s
->size
+= PLT_ENTRY_SIZE (htab
);
10242 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10244 else if ((*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10245 ent
->plt
.offset
= (bfd_vma
) -1;
10248 s
= htab
->pltlocal
;
10249 ent
->plt
.offset
= s
->size
;
10250 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10251 if (bfd_link_pic (info
))
10252 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
10256 ent
->plt
.offset
= (bfd_vma
) -1;
10260 /* Allocate global sym .plt and .got entries, and space for global
10261 sym dynamic relocs. */
10262 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10264 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10265 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10267 first_tlsld
= NULL
;
10268 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10270 struct got_entry
*ent
;
10272 if (!is_ppc64_elf (ibfd
))
10275 ent
= ppc64_tlsld_got (ibfd
);
10276 if (ent
->got
.refcount
> 0)
10278 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10280 ent
->is_indirect
= TRUE
;
10281 ent
->got
.ent
= first_tlsld
;
10285 if (first_tlsld
== NULL
)
10287 s
= ppc64_elf_tdata (ibfd
)->got
;
10288 ent
->got
.offset
= s
->size
;
10291 if (bfd_link_pic (info
))
10293 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10294 srel
->size
+= sizeof (Elf64_External_Rela
);
10299 ent
->got
.offset
= (bfd_vma
) -1;
10302 /* We now have determined the sizes of the various dynamic sections.
10303 Allocate memory for them. */
10305 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10307 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10310 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
10311 /* These haven't been allocated yet; don't strip. */
10313 else if (s
== htab
->elf
.sgot
10314 || s
== htab
->elf
.splt
10315 || s
== htab
->elf
.iplt
10316 || s
== htab
->pltlocal
10317 || s
== htab
->glink
10318 || s
== htab
->global_entry
10319 || s
== htab
->elf
.sdynbss
10320 || s
== htab
->elf
.sdynrelro
)
10322 /* Strip this section if we don't need it; see the
10325 else if (s
== htab
->glink_eh_frame
)
10327 if (!bfd_is_abs_section (s
->output_section
))
10328 /* Not sized yet. */
10331 else if (CONST_STRNEQ (s
->name
, ".rela"))
10335 if (s
!= htab
->elf
.srelplt
)
10338 /* We use the reloc_count field as a counter if we need
10339 to copy relocs into the output file. */
10340 s
->reloc_count
= 0;
10345 /* It's not one of our sections, so don't allocate space. */
10351 /* If we don't need this section, strip it from the
10352 output file. This is mostly to handle .rela.bss and
10353 .rela.plt. We must create both sections in
10354 create_dynamic_sections, because they must be created
10355 before the linker maps input sections to output
10356 sections. The linker does that before
10357 adjust_dynamic_symbol is called, and it is that
10358 function which decides whether anything needs to go
10359 into these sections. */
10360 s
->flags
|= SEC_EXCLUDE
;
10364 if (bfd_is_abs_section (s
->output_section
))
10365 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10368 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10371 /* Allocate memory for the section contents. We use bfd_zalloc
10372 here in case unused entries are not reclaimed before the
10373 section's contents are written out. This should not happen,
10374 but this way if it does we get a R_PPC64_NONE reloc in .rela
10375 sections instead of garbage.
10376 We also rely on the section contents being zero when writing
10377 the GOT and .dynrelro. */
10378 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10379 if (s
->contents
== NULL
)
10383 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10385 if (!is_ppc64_elf (ibfd
))
10388 s
= ppc64_elf_tdata (ibfd
)->got
;
10389 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10392 s
->flags
|= SEC_EXCLUDE
;
10395 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10396 if (s
->contents
== NULL
)
10400 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10404 s
->flags
|= SEC_EXCLUDE
;
10407 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10408 if (s
->contents
== NULL
)
10411 s
->reloc_count
= 0;
10416 if (htab
->elf
.dynamic_sections_created
)
10418 bfd_boolean tls_opt
;
10420 /* Add some entries to the .dynamic section. We fill in the
10421 values later, in ppc64_elf_finish_dynamic_sections, but we
10422 must add the entries now so that we get the correct size for
10423 the .dynamic section. The DT_DEBUG entry is filled in by the
10424 dynamic linker and used by the debugger. */
10425 #define add_dynamic_entry(TAG, VAL) \
10426 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10428 if (bfd_link_executable (info
))
10430 if (!add_dynamic_entry (DT_DEBUG
, 0))
10434 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10436 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10437 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10438 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10439 || !add_dynamic_entry (DT_JMPREL
, 0)
10440 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10444 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10446 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10447 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10451 tls_opt
= (htab
->params
->tls_get_addr_opt
10452 && htab
->tls_get_addr_fd
!= NULL
10453 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
10454 if (tls_opt
|| !htab
->opd_abi
)
10456 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10462 if (!add_dynamic_entry (DT_RELA
, 0)
10463 || !add_dynamic_entry (DT_RELASZ
, 0)
10464 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10467 /* If any dynamic relocs apply to a read-only section,
10468 then we need a DT_TEXTREL entry. */
10469 if ((info
->flags
& DF_TEXTREL
) == 0)
10470 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
10472 if ((info
->flags
& DF_TEXTREL
) != 0)
10474 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10479 #undef add_dynamic_entry
10484 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10487 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10489 if (h
->plt
.plist
!= NULL
10491 && !h
->pointer_equality_needed
)
10494 return _bfd_elf_hash_symbol (h
);
10497 /* Determine the type of stub needed, if any, for a call. */
10499 static inline enum ppc_stub_type
10500 ppc_type_of_stub (asection
*input_sec
,
10501 const Elf_Internal_Rela
*rel
,
10502 struct ppc_link_hash_entry
**hash
,
10503 struct plt_entry
**plt_ent
,
10504 bfd_vma destination
,
10505 unsigned long local_off
)
10507 struct ppc_link_hash_entry
*h
= *hash
;
10509 bfd_vma branch_offset
;
10510 bfd_vma max_branch_offset
;
10511 enum elf_ppc64_reloc_type r_type
;
10515 struct plt_entry
*ent
;
10516 struct ppc_link_hash_entry
*fdh
= h
;
10518 && h
->oh
->is_func_descriptor
)
10520 fdh
= ppc_follow_link (h
->oh
);
10524 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10525 if (ent
->addend
== rel
->r_addend
10526 && ent
->plt
.offset
!= (bfd_vma
) -1)
10529 return ppc_stub_plt_call
;
10532 /* Here, we know we don't have a plt entry. If we don't have a
10533 either a defined function descriptor or a defined entry symbol
10534 in a regular object file, then it is pointless trying to make
10535 any other type of stub. */
10536 if (!is_static_defined (&fdh
->elf
)
10537 && !is_static_defined (&h
->elf
))
10538 return ppc_stub_none
;
10540 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10542 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10543 struct plt_entry
**local_plt
= (struct plt_entry
**)
10544 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10545 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10547 if (local_plt
[r_symndx
] != NULL
)
10549 struct plt_entry
*ent
;
10551 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10552 if (ent
->addend
== rel
->r_addend
10553 && ent
->plt
.offset
!= (bfd_vma
) -1)
10556 return ppc_stub_plt_call
;
10561 /* Determine where the call point is. */
10562 location
= (input_sec
->output_offset
10563 + input_sec
->output_section
->vma
10566 branch_offset
= destination
- location
;
10567 r_type
= ELF64_R_TYPE (rel
->r_info
);
10569 /* Determine if a long branch stub is needed. */
10570 max_branch_offset
= 1 << 25;
10571 if (r_type
== R_PPC64_REL14
10572 || r_type
== R_PPC64_REL14_BRTAKEN
10573 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10574 max_branch_offset
= 1 << 15;
10576 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10577 /* We need a stub. Figure out whether a long_branch or plt_branch
10578 is needed later. */
10579 return ppc_stub_long_branch
;
10581 return ppc_stub_none
;
10584 /* With power7 weakly ordered memory model, it is possible for ld.so
10585 to update a plt entry in one thread and have another thread see a
10586 stale zero toc entry. To avoid this we need some sort of acquire
10587 barrier in the call stub. One solution is to make the load of the
10588 toc word seem to appear to depend on the load of the function entry
10589 word. Another solution is to test for r2 being zero, and branch to
10590 the appropriate glink entry if so.
10592 . fake dep barrier compare
10593 . ld 12,xxx(2) ld 12,xxx(2)
10594 . mtctr 12 mtctr 12
10595 . xor 11,12,12 ld 2,xxx+8(2)
10596 . add 2,2,11 cmpldi 2,0
10597 . ld 2,xxx+8(2) bnectr+
10598 . bctr b <glink_entry>
10600 The solution involving the compare turns out to be faster, so
10601 that's what we use unless the branch won't reach. */
10603 #define ALWAYS_USE_FAKE_DEP 0
10604 #define ALWAYS_EMIT_R2SAVE 0
10606 static inline unsigned int
10607 plt_stub_size (struct ppc_link_hash_table
*htab
,
10608 struct ppc_stub_hash_entry
*stub_entry
,
10611 unsigned size
= 12;
10613 if (ALWAYS_EMIT_R2SAVE
10614 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10616 if (PPC_HA (off
) != 0)
10621 if (htab
->params
->plt_static_chain
)
10623 if (htab
->params
->plt_thread_safe
10624 && htab
->elf
.dynamic_sections_created
10625 && stub_entry
->h
!= NULL
10626 && stub_entry
->h
->elf
.dynindx
!= -1)
10628 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
10631 if (stub_entry
->h
!= NULL
10632 && (stub_entry
->h
== htab
->tls_get_addr_fd
10633 || stub_entry
->h
== htab
->tls_get_addr
)
10634 && htab
->params
->tls_get_addr_opt
)
10637 if (ALWAYS_EMIT_R2SAVE
10638 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10644 /* Depending on the sign of plt_stub_align:
10645 If positive, return the padding to align to a 2**plt_stub_align
10647 If negative, if this stub would cross fewer 2**plt_stub_align
10648 boundaries if we align, then return the padding needed to do so. */
10650 static inline unsigned int
10651 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10652 struct ppc_stub_hash_entry
*stub_entry
,
10656 unsigned stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10657 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10659 if (htab
->params
->plt_stub_align
>= 0)
10661 stub_align
= 1 << htab
->params
->plt_stub_align
;
10662 if ((stub_off
& (stub_align
- 1)) != 0)
10663 return stub_align
- (stub_off
& (stub_align
- 1));
10667 stub_align
= 1 << -htab
->params
->plt_stub_align
;
10668 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10669 > ((stub_size
- 1) & -stub_align
))
10670 return stub_align
- (stub_off
& (stub_align
- 1));
10674 /* Build a .plt call stub. */
10676 static inline bfd_byte
*
10677 build_plt_stub (struct ppc_link_hash_table
*htab
,
10678 struct ppc_stub_hash_entry
*stub_entry
,
10679 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10681 bfd
*obfd
= htab
->params
->stub_bfd
;
10682 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10683 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10684 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10685 && htab
->elf
.dynamic_sections_created
10686 && stub_entry
->h
!= NULL
10687 && stub_entry
->h
->elf
.dynindx
!= -1);
10688 bfd_boolean use_fake_dep
= plt_thread_safe
;
10689 bfd_vma cmp_branch_off
= 0;
10691 if (!ALWAYS_USE_FAKE_DEP
10694 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10695 || stub_entry
->h
== htab
->tls_get_addr
)
10696 && htab
->params
->tls_get_addr_opt
))
10698 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10699 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10700 / PLT_ENTRY_SIZE (htab
));
10701 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
10704 if (pltindex
> 32768)
10705 glinkoff
+= (pltindex
- 32768) * 4;
10707 + htab
->glink
->output_offset
10708 + htab
->glink
->output_section
->vma
);
10709 from
= (p
- stub_entry
->group
->stub_sec
->contents
10710 + 4 * (ALWAYS_EMIT_R2SAVE
10711 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10712 + 4 * (PPC_HA (offset
) != 0)
10713 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10714 != PPC_HA (offset
))
10715 + 4 * (plt_static_chain
!= 0)
10717 + stub_entry
->group
->stub_sec
->output_offset
10718 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10719 cmp_branch_off
= to
- from
;
10720 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10723 if (PPC_HA (offset
) != 0)
10727 if (ALWAYS_EMIT_R2SAVE
10728 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10729 r
[0].r_offset
+= 4;
10730 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10731 r
[1].r_offset
= r
[0].r_offset
+ 4;
10732 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10733 r
[1].r_addend
= r
[0].r_addend
;
10736 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10738 r
[2].r_offset
= r
[1].r_offset
+ 4;
10739 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10740 r
[2].r_addend
= r
[0].r_addend
;
10744 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10745 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10746 r
[2].r_addend
= r
[0].r_addend
+ 8;
10747 if (plt_static_chain
)
10749 r
[3].r_offset
= r
[2].r_offset
+ 4;
10750 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10751 r
[3].r_addend
= r
[0].r_addend
+ 16;
10756 if (ALWAYS_EMIT_R2SAVE
10757 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10758 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10761 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10762 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10766 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10767 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10770 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10772 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10775 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10780 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10781 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10783 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10784 if (plt_static_chain
)
10785 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10792 if (ALWAYS_EMIT_R2SAVE
10793 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10794 r
[0].r_offset
+= 4;
10795 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10798 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10800 r
[1].r_offset
= r
[0].r_offset
+ 4;
10801 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10802 r
[1].r_addend
= r
[0].r_addend
;
10806 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10807 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10808 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10809 if (plt_static_chain
)
10811 r
[2].r_offset
= r
[1].r_offset
+ 4;
10812 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10813 r
[2].r_addend
= r
[0].r_addend
+ 8;
10818 if (ALWAYS_EMIT_R2SAVE
10819 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10820 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10821 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10823 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10825 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
10828 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10833 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
10834 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
10836 if (plt_static_chain
)
10837 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
10838 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
10841 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
10843 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
10844 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
10845 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
10848 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
10852 /* Build a special .plt call stub for __tls_get_addr. */
10854 #define LD_R11_0R3 0xe9630000
10855 #define LD_R12_0R3 0xe9830000
10856 #define MR_R0_R3 0x7c601b78
10857 #define CMPDI_R11_0 0x2c2b0000
10858 #define ADD_R3_R12_R13 0x7c6c6a14
10859 #define BEQLR 0x4d820020
10860 #define MR_R3_R0 0x7c030378
10861 #define STD_R11_0R1 0xf9610000
10862 #define BCTRL 0x4e800421
10863 #define LD_R11_0R1 0xe9610000
10864 #define MTLR_R11 0x7d6803a6
10866 static inline bfd_byte
*
10867 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
10868 struct ppc_stub_hash_entry
*stub_entry
,
10869 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10871 bfd
*obfd
= htab
->params
->stub_bfd
;
10873 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
10874 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
10875 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
10876 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
10877 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
10878 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
10879 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
10881 r
[0].r_offset
+= 7 * 4;
10882 if (!ALWAYS_EMIT_R2SAVE
10883 && stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
10884 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10886 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
10887 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10890 r
[0].r_offset
+= 2 * 4;
10891 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10892 bfd_put_32 (obfd
, BCTRL
, p
- 4);
10894 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10895 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10896 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
10897 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
10902 static Elf_Internal_Rela
*
10903 get_relocs (asection
*sec
, int count
)
10905 Elf_Internal_Rela
*relocs
;
10906 struct bfd_elf_section_data
*elfsec_data
;
10908 elfsec_data
= elf_section_data (sec
);
10909 relocs
= elfsec_data
->relocs
;
10910 if (relocs
== NULL
)
10912 bfd_size_type relsize
;
10913 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10914 relocs
= bfd_alloc (sec
->owner
, relsize
);
10915 if (relocs
== NULL
)
10917 elfsec_data
->relocs
= relocs
;
10918 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10919 sizeof (Elf_Internal_Shdr
));
10920 if (elfsec_data
->rela
.hdr
== NULL
)
10922 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10923 * sizeof (Elf64_External_Rela
));
10924 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10925 sec
->reloc_count
= 0;
10927 relocs
+= sec
->reloc_count
;
10928 sec
->reloc_count
+= count
;
10933 get_r2off (struct bfd_link_info
*info
,
10934 struct ppc_stub_hash_entry
*stub_entry
)
10936 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10937 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10941 /* Support linking -R objects. Get the toc pointer from the
10944 if (!htab
->opd_abi
)
10946 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10947 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10949 if (strcmp (opd
->name
, ".opd") != 0
10950 || opd
->reloc_count
!= 0)
10952 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for `%pT'\n"),
10953 stub_entry
->h
->elf
.root
.root
.string
);
10954 bfd_set_error (bfd_error_bad_value
);
10955 return (bfd_vma
) -1;
10957 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10958 return (bfd_vma
) -1;
10959 r2off
= bfd_get_64 (opd
->owner
, buf
);
10960 r2off
-= elf_gp (info
->output_bfd
);
10962 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10967 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10969 struct ppc_stub_hash_entry
*stub_entry
;
10970 struct ppc_branch_hash_entry
*br_entry
;
10971 struct bfd_link_info
*info
;
10972 struct ppc_link_hash_table
*htab
;
10976 Elf_Internal_Rela
*r
;
10979 /* Massage our args to the form they really have. */
10980 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10983 htab
= ppc_hash_table (info
);
10987 /* Make a note of the offset within the stubs for this entry. */
10988 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10989 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10991 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10992 switch (stub_entry
->stub_type
)
10994 case ppc_stub_long_branch
:
10995 case ppc_stub_long_branch_r2off
:
10996 /* Branches are relative. This is where we are going to. */
10997 dest
= (stub_entry
->target_value
10998 + stub_entry
->target_section
->output_offset
10999 + stub_entry
->target_section
->output_section
->vma
);
11000 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11003 /* And this is where we are coming from. */
11004 off
-= (stub_entry
->stub_offset
11005 + stub_entry
->group
->stub_sec
->output_offset
11006 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11009 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11011 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11013 if (r2off
== (bfd_vma
) -1)
11015 htab
->stub_error
= TRUE
;
11018 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11020 if (PPC_HA (r2off
) != 0)
11022 bfd_put_32 (htab
->params
->stub_bfd
,
11023 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11026 if (PPC_LO (r2off
) != 0)
11028 bfd_put_32 (htab
->params
->stub_bfd
,
11029 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11034 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
11037 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11040 (_("long branch stub `%s' offset overflow"),
11041 stub_entry
->root
.string
);
11042 htab
->stub_error
= TRUE
;
11046 if (info
->emitrelocations
)
11048 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11051 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11052 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11053 r
->r_addend
= dest
;
11054 if (stub_entry
->h
!= NULL
)
11056 struct elf_link_hash_entry
**hashes
;
11057 unsigned long symndx
;
11058 struct ppc_link_hash_entry
*h
;
11060 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
11061 if (hashes
== NULL
)
11063 bfd_size_type hsize
;
11065 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
11066 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
11067 if (hashes
== NULL
)
11069 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
11070 htab
->stub_globals
= 1;
11072 symndx
= htab
->stub_globals
++;
11074 hashes
[symndx
] = &h
->elf
;
11075 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
11076 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
11077 h
= ppc_follow_link (h
->oh
);
11078 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11079 /* H is an opd symbol. The addend must be zero. */
11083 off
= (h
->elf
.root
.u
.def
.value
11084 + h
->elf
.root
.u
.def
.section
->output_offset
11085 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
11086 r
->r_addend
-= off
;
11092 case ppc_stub_plt_branch
:
11093 case ppc_stub_plt_branch_r2off
:
11094 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11095 stub_entry
->root
.string
+ 9,
11097 if (br_entry
== NULL
)
11099 _bfd_error_handler (_("can't find branch stub `%s'"),
11100 stub_entry
->root
.string
);
11101 htab
->stub_error
= TRUE
;
11105 dest
= (stub_entry
->target_value
11106 + stub_entry
->target_section
->output_offset
11107 + stub_entry
->target_section
->output_section
->vma
);
11108 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11109 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11111 bfd_put_64 (htab
->brlt
->owner
, dest
,
11112 htab
->brlt
->contents
+ br_entry
->offset
);
11114 if (br_entry
->iter
== htab
->stub_iteration
)
11116 br_entry
->iter
= 0;
11118 if (htab
->relbrlt
!= NULL
)
11120 /* Create a reloc for the branch lookup table entry. */
11121 Elf_Internal_Rela rela
;
11124 rela
.r_offset
= (br_entry
->offset
11125 + htab
->brlt
->output_offset
11126 + htab
->brlt
->output_section
->vma
);
11127 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11128 rela
.r_addend
= dest
;
11130 rl
= htab
->relbrlt
->contents
;
11131 rl
+= (htab
->relbrlt
->reloc_count
++
11132 * sizeof (Elf64_External_Rela
));
11133 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11135 else if (info
->emitrelocations
)
11137 r
= get_relocs (htab
->brlt
, 1);
11140 /* brlt, being SEC_LINKER_CREATED does not go through the
11141 normal reloc processing. Symbols and offsets are not
11142 translated from input file to output file form, so
11143 set up the offset per the output file. */
11144 r
->r_offset
= (br_entry
->offset
11145 + htab
->brlt
->output_offset
11146 + htab
->brlt
->output_section
->vma
);
11147 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11148 r
->r_addend
= dest
;
11152 dest
= (br_entry
->offset
11153 + htab
->brlt
->output_offset
11154 + htab
->brlt
->output_section
->vma
);
11157 - elf_gp (info
->output_bfd
)
11158 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11160 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11162 info
->callbacks
->einfo
11163 (_("%P: linkage table error against `%pT'\n"),
11164 stub_entry
->root
.string
);
11165 bfd_set_error (bfd_error_bad_value
);
11166 htab
->stub_error
= TRUE
;
11170 if (info
->emitrelocations
)
11172 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11175 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11176 if (bfd_big_endian (info
->output_bfd
))
11177 r
[0].r_offset
+= 2;
11178 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
11179 r
[0].r_offset
+= 4;
11180 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11181 r
[0].r_addend
= dest
;
11182 if (PPC_HA (off
) != 0)
11184 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11185 r
[1].r_offset
= r
[0].r_offset
+ 4;
11186 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11187 r
[1].r_addend
= r
[0].r_addend
;
11192 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11194 if (PPC_HA (off
) != 0)
11196 bfd_put_32 (htab
->params
->stub_bfd
,
11197 ADDIS_R12_R2
| PPC_HA (off
), p
);
11199 bfd_put_32 (htab
->params
->stub_bfd
,
11200 LD_R12_0R12
| PPC_LO (off
), p
);
11203 bfd_put_32 (htab
->params
->stub_bfd
,
11204 LD_R12_0R2
| PPC_LO (off
), p
);
11208 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11210 if (r2off
== (bfd_vma
) -1)
11212 htab
->stub_error
= TRUE
;
11216 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11218 if (PPC_HA (off
) != 0)
11220 bfd_put_32 (htab
->params
->stub_bfd
,
11221 ADDIS_R12_R2
| PPC_HA (off
), p
);
11223 bfd_put_32 (htab
->params
->stub_bfd
,
11224 LD_R12_0R12
| PPC_LO (off
), p
);
11227 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11229 if (PPC_HA (r2off
) != 0)
11232 bfd_put_32 (htab
->params
->stub_bfd
,
11233 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11235 if (PPC_LO (r2off
) != 0)
11238 bfd_put_32 (htab
->params
->stub_bfd
,
11239 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11243 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
11245 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
11249 case ppc_stub_plt_call
:
11250 case ppc_stub_plt_call_r2save
:
11251 if (stub_entry
->h
!= NULL
11252 && stub_entry
->h
->is_func_descriptor
11253 && stub_entry
->h
->oh
!= NULL
)
11255 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11257 /* If the old-ABI "dot-symbol" is undefined make it weak so
11258 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11259 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11260 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11261 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11262 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11265 /* Now build the stub. */
11266 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11267 if (dest
>= (bfd_vma
) -2)
11270 plt
= htab
->elf
.splt
;
11271 if (!htab
->elf
.dynamic_sections_created
11272 || stub_entry
->h
== NULL
11273 || stub_entry
->h
->elf
.dynindx
== -1)
11275 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11276 plt
= htab
->elf
.iplt
;
11278 plt
= htab
->pltlocal
;
11281 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
11284 - elf_gp (info
->output_bfd
)
11285 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11287 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11289 info
->callbacks
->einfo
11290 /* xgettext:c-format */
11291 (_("%P: linkage table error against `%pT'\n"),
11292 stub_entry
->h
!= NULL
11293 ? stub_entry
->h
->elf
.root
.root
.string
11295 bfd_set_error (bfd_error_bad_value
);
11296 htab
->stub_error
= TRUE
;
11300 if (htab
->params
->plt_stub_align
!= 0)
11302 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11304 stub_entry
->group
->stub_sec
->size
+= pad
;
11305 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11310 if (info
->emitrelocations
)
11312 r
= get_relocs (stub_entry
->group
->stub_sec
,
11313 ((PPC_HA (off
) != 0)
11315 ? 2 + (htab
->params
->plt_static_chain
11316 && PPC_HA (off
+ 16) == PPC_HA (off
))
11320 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11321 if (bfd_big_endian (info
->output_bfd
))
11322 r
[0].r_offset
+= 2;
11323 r
[0].r_addend
= dest
;
11325 if (stub_entry
->h
!= NULL
11326 && (stub_entry
->h
== htab
->tls_get_addr_fd
11327 || stub_entry
->h
== htab
->tls_get_addr
)
11328 && htab
->params
->tls_get_addr_opt
)
11329 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
11331 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
11334 case ppc_stub_save_res
:
11342 stub_entry
->group
->stub_sec
->size
+= p
- loc
;
11344 if (htab
->params
->emit_stub_syms
)
11346 struct elf_link_hash_entry
*h
;
11349 const char *const stub_str
[] = { "long_branch",
11350 "long_branch_r2off",
11352 "plt_branch_r2off",
11356 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11357 len2
= strlen (stub_entry
->root
.string
);
11358 name
= bfd_malloc (len1
+ len2
+ 2);
11361 memcpy (name
, stub_entry
->root
.string
, 9);
11362 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11363 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11364 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
11367 if (h
->root
.type
== bfd_link_hash_new
)
11369 h
->root
.type
= bfd_link_hash_defined
;
11370 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11371 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11372 h
->ref_regular
= 1;
11373 h
->def_regular
= 1;
11374 h
->ref_regular_nonweak
= 1;
11375 h
->forced_local
= 1;
11377 h
->root
.linker_def
= 1;
11384 /* As above, but don't actually build the stub. Just bump offset so
11385 we know stub section sizes, and select plt_branch stubs where
11386 long_branch stubs won't do. */
11389 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11391 struct ppc_stub_hash_entry
*stub_entry
;
11392 struct bfd_link_info
*info
;
11393 struct ppc_link_hash_table
*htab
;
11397 /* Massage our args to the form they really have. */
11398 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11401 htab
= ppc_hash_table (info
);
11405 if (stub_entry
->h
!= NULL
11406 && stub_entry
->h
->save_res
11407 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11408 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
11410 /* Don't make stubs to out-of-line register save/restore
11411 functions. Instead, emit copies of the functions. */
11412 stub_entry
->group
->needs_save_res
= 1;
11413 stub_entry
->stub_type
= ppc_stub_save_res
;
11417 if (stub_entry
->stub_type
== ppc_stub_plt_call
11418 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11421 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11422 if (off
>= (bfd_vma
) -2)
11424 plt
= htab
->elf
.splt
;
11425 if (!htab
->elf
.dynamic_sections_created
11426 || stub_entry
->h
== NULL
11427 || stub_entry
->h
->elf
.dynindx
== -1)
11429 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11430 plt
= htab
->elf
.iplt
;
11432 plt
= htab
->pltlocal
;
11434 off
+= (plt
->output_offset
11435 + plt
->output_section
->vma
11436 - elf_gp (info
->output_bfd
)
11437 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11439 size
= plt_stub_size (htab
, stub_entry
, off
);
11440 if (stub_entry
->h
!= NULL
11441 && (stub_entry
->h
== htab
->tls_get_addr_fd
11442 || stub_entry
->h
== htab
->tls_get_addr
)
11443 && htab
->params
->tls_get_addr_opt
11444 && (ALWAYS_EMIT_R2SAVE
11445 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
11446 stub_entry
->group
->tls_get_addr_opt_bctrl
11447 = stub_entry
->group
->stub_sec
->size
+ size
- 5 * 4;
11449 if (htab
->params
->plt_stub_align
)
11450 size
+= plt_stub_pad (htab
, stub_entry
, off
);
11451 if (info
->emitrelocations
)
11453 stub_entry
->group
->stub_sec
->reloc_count
11454 += ((PPC_HA (off
) != 0)
11456 ? 2 + (htab
->params
->plt_static_chain
11457 && PPC_HA (off
+ 16) == PPC_HA (off
))
11459 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11464 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11467 bfd_vma local_off
= 0;
11469 off
= (stub_entry
->target_value
11470 + stub_entry
->target_section
->output_offset
11471 + stub_entry
->target_section
->output_section
->vma
);
11472 off
-= (stub_entry
->group
->stub_sec
->size
11473 + stub_entry
->group
->stub_sec
->output_offset
11474 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11476 /* Reset the stub type from the plt variant in case we now
11477 can reach with a shorter stub. */
11478 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
11479 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11482 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11484 r2off
= get_r2off (info
, stub_entry
);
11485 if (r2off
== (bfd_vma
) -1)
11487 htab
->stub_error
= TRUE
;
11491 if (PPC_HA (r2off
) != 0)
11493 if (PPC_LO (r2off
) != 0)
11498 local_off
= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11500 /* If the branch offset is too big, use a ppc_stub_plt_branch.
11501 Do the same for -R objects without function descriptors. */
11502 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26) - local_off
11503 || (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
11505 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0))
11507 struct ppc_branch_hash_entry
*br_entry
;
11509 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11510 stub_entry
->root
.string
+ 9,
11512 if (br_entry
== NULL
)
11514 _bfd_error_handler (_("can't build branch stub `%s'"),
11515 stub_entry
->root
.string
);
11516 htab
->stub_error
= TRUE
;
11520 if (br_entry
->iter
!= htab
->stub_iteration
)
11522 br_entry
->iter
= htab
->stub_iteration
;
11523 br_entry
->offset
= htab
->brlt
->size
;
11524 htab
->brlt
->size
+= 8;
11526 if (htab
->relbrlt
!= NULL
)
11527 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
11528 else if (info
->emitrelocations
)
11530 htab
->brlt
->reloc_count
+= 1;
11531 htab
->brlt
->flags
|= SEC_RELOC
;
11535 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11536 off
= (br_entry
->offset
11537 + htab
->brlt
->output_offset
11538 + htab
->brlt
->output_section
->vma
11539 - elf_gp (info
->output_bfd
)
11540 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11542 if (info
->emitrelocations
)
11544 stub_entry
->group
->stub_sec
->reloc_count
11545 += 1 + (PPC_HA (off
) != 0);
11546 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11549 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11552 if (PPC_HA (off
) != 0)
11558 if (PPC_HA (off
) != 0)
11561 if (PPC_HA (r2off
) != 0)
11563 if (PPC_LO (r2off
) != 0)
11567 else if (info
->emitrelocations
)
11569 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11570 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11574 stub_entry
->group
->stub_sec
->size
+= size
;
11578 /* Set up various things so that we can make a list of input sections
11579 for each output section included in the link. Returns -1 on error,
11580 0 when no stubs will be needed, and 1 on success. */
11583 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11587 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11592 htab
->sec_info_arr_size
= bfd_get_next_section_id ();
11593 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11594 htab
->sec_info
= bfd_zmalloc (amt
);
11595 if (htab
->sec_info
== NULL
)
11598 /* Set toc_off for com, und, abs and ind sections. */
11599 for (id
= 0; id
< 3; id
++)
11600 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11605 /* Set up for first pass at multitoc partitioning. */
11608 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11610 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11612 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11613 htab
->toc_bfd
= NULL
;
11614 htab
->toc_first_sec
= NULL
;
11617 /* The linker repeatedly calls this function for each TOC input section
11618 and linker generated GOT section. Group input bfds such that the toc
11619 within a group is less than 64k in size. */
11622 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11624 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11625 bfd_vma addr
, off
, limit
;
11630 if (!htab
->second_toc_pass
)
11632 /* Keep track of the first .toc or .got section for this input bfd. */
11633 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11637 htab
->toc_bfd
= isec
->owner
;
11638 htab
->toc_first_sec
= isec
;
11641 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11642 off
= addr
- htab
->toc_curr
;
11643 limit
= 0x80008000;
11644 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11646 if (off
+ isec
->size
> limit
)
11648 addr
= (htab
->toc_first_sec
->output_offset
11649 + htab
->toc_first_sec
->output_section
->vma
);
11650 htab
->toc_curr
= addr
;
11651 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11654 /* toc_curr is the base address of this toc group. Set elf_gp
11655 for the input section to be the offset relative to the
11656 output toc base plus 0x8000. Making the input elf_gp an
11657 offset allows us to move the toc as a whole without
11658 recalculating input elf_gp. */
11659 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
11660 off
+= TOC_BASE_OFF
;
11662 /* Die if someone uses a linker script that doesn't keep input
11663 file .toc and .got together. */
11665 && elf_gp (isec
->owner
) != 0
11666 && elf_gp (isec
->owner
) != off
)
11669 elf_gp (isec
->owner
) = off
;
11673 /* During the second pass toc_first_sec points to the start of
11674 a toc group, and toc_curr is used to track the old elf_gp.
11675 We use toc_bfd to ensure we only look at each bfd once. */
11676 if (htab
->toc_bfd
== isec
->owner
)
11678 htab
->toc_bfd
= isec
->owner
;
11680 if (htab
->toc_first_sec
== NULL
11681 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11683 htab
->toc_curr
= elf_gp (isec
->owner
);
11684 htab
->toc_first_sec
= isec
;
11686 addr
= (htab
->toc_first_sec
->output_offset
11687 + htab
->toc_first_sec
->output_section
->vma
);
11688 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
11689 elf_gp (isec
->owner
) = off
;
11694 /* Called via elf_link_hash_traverse to merge GOT entries for global
11698 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11700 if (h
->root
.type
== bfd_link_hash_indirect
)
11703 merge_got_entries (&h
->got
.glist
);
11708 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11712 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11714 struct got_entry
*gent
;
11716 if (h
->root
.type
== bfd_link_hash_indirect
)
11719 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11720 if (!gent
->is_indirect
)
11721 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11725 /* Called on the first multitoc pass after the last call to
11726 ppc64_elf_next_toc_section. This function removes duplicate GOT
11730 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11732 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11733 struct bfd
*ibfd
, *ibfd2
;
11734 bfd_boolean done_something
;
11736 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11738 if (!htab
->do_multi_toc
)
11741 /* Merge global sym got entries within a toc group. */
11742 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11744 /* And tlsld_got. */
11745 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11747 struct got_entry
*ent
, *ent2
;
11749 if (!is_ppc64_elf (ibfd
))
11752 ent
= ppc64_tlsld_got (ibfd
);
11753 if (!ent
->is_indirect
11754 && ent
->got
.offset
!= (bfd_vma
) -1)
11756 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11758 if (!is_ppc64_elf (ibfd2
))
11761 ent2
= ppc64_tlsld_got (ibfd2
);
11762 if (!ent2
->is_indirect
11763 && ent2
->got
.offset
!= (bfd_vma
) -1
11764 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11766 ent2
->is_indirect
= TRUE
;
11767 ent2
->got
.ent
= ent
;
11773 /* Zap sizes of got sections. */
11774 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11775 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11776 htab
->got_reli_size
= 0;
11778 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11780 asection
*got
, *relgot
;
11782 if (!is_ppc64_elf (ibfd
))
11785 got
= ppc64_elf_tdata (ibfd
)->got
;
11788 got
->rawsize
= got
->size
;
11790 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11791 relgot
->rawsize
= relgot
->size
;
11796 /* Now reallocate the got, local syms first. We don't need to
11797 allocate section contents again since we never increase size. */
11798 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11800 struct got_entry
**lgot_ents
;
11801 struct got_entry
**end_lgot_ents
;
11802 struct plt_entry
**local_plt
;
11803 struct plt_entry
**end_local_plt
;
11804 unsigned char *lgot_masks
;
11805 bfd_size_type locsymcount
;
11806 Elf_Internal_Shdr
*symtab_hdr
;
11809 if (!is_ppc64_elf (ibfd
))
11812 lgot_ents
= elf_local_got_ents (ibfd
);
11816 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11817 locsymcount
= symtab_hdr
->sh_info
;
11818 end_lgot_ents
= lgot_ents
+ locsymcount
;
11819 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11820 end_local_plt
= local_plt
+ locsymcount
;
11821 lgot_masks
= (unsigned char *) end_local_plt
;
11822 s
= ppc64_elf_tdata (ibfd
)->got
;
11823 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11825 struct got_entry
*ent
;
11827 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11829 unsigned int ent_size
= 8;
11830 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11832 ent
->got
.offset
= s
->size
;
11833 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11838 s
->size
+= ent_size
;
11839 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
11841 htab
->elf
.irelplt
->size
+= rel_size
;
11842 htab
->got_reli_size
+= rel_size
;
11844 else if (bfd_link_pic (info
)
11845 && !((ent
->tls_type
& TLS_TPREL
) != 0
11846 && bfd_link_executable (info
)))
11848 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11849 srel
->size
+= rel_size
;
11855 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11857 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11859 struct got_entry
*ent
;
11861 if (!is_ppc64_elf (ibfd
))
11864 ent
= ppc64_tlsld_got (ibfd
);
11865 if (!ent
->is_indirect
11866 && ent
->got
.offset
!= (bfd_vma
) -1)
11868 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11869 ent
->got
.offset
= s
->size
;
11871 if (bfd_link_pic (info
))
11873 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11874 srel
->size
+= sizeof (Elf64_External_Rela
);
11879 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11880 if (!done_something
)
11881 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11885 if (!is_ppc64_elf (ibfd
))
11888 got
= ppc64_elf_tdata (ibfd
)->got
;
11891 done_something
= got
->rawsize
!= got
->size
;
11892 if (done_something
)
11897 if (done_something
)
11898 (*htab
->params
->layout_sections_again
) ();
11900 /* Set up for second pass over toc sections to recalculate elf_gp
11901 on input sections. */
11902 htab
->toc_bfd
= NULL
;
11903 htab
->toc_first_sec
= NULL
;
11904 htab
->second_toc_pass
= TRUE
;
11905 return done_something
;
11908 /* Called after second pass of multitoc partitioning. */
11911 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11913 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11915 /* After the second pass, toc_curr tracks the TOC offset used
11916 for code sections below in ppc64_elf_next_input_section. */
11917 htab
->toc_curr
= TOC_BASE_OFF
;
11920 /* No toc references were found in ISEC. If the code in ISEC makes no
11921 calls, then there's no need to use toc adjusting stubs when branching
11922 into ISEC. Actually, indirect calls from ISEC are OK as they will
11923 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11924 needed, and 2 if a cyclical call-graph was found but no other reason
11925 for a stub was detected. If called from the top level, a return of
11926 2 means the same as a return of 0. */
11929 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11933 /* Mark this section as checked. */
11934 isec
->call_check_done
= 1;
11936 /* We know none of our code bearing sections will need toc stubs. */
11937 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11940 if (isec
->size
== 0)
11943 if (isec
->output_section
== NULL
)
11947 if (isec
->reloc_count
!= 0)
11949 Elf_Internal_Rela
*relstart
, *rel
;
11950 Elf_Internal_Sym
*local_syms
;
11951 struct ppc_link_hash_table
*htab
;
11953 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11954 info
->keep_memory
);
11955 if (relstart
== NULL
)
11958 /* Look for branches to outside of this section. */
11960 htab
= ppc_hash_table (info
);
11964 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11966 enum elf_ppc64_reloc_type r_type
;
11967 unsigned long r_symndx
;
11968 struct elf_link_hash_entry
*h
;
11969 struct ppc_link_hash_entry
*eh
;
11970 Elf_Internal_Sym
*sym
;
11972 struct _opd_sec_data
*opd
;
11976 r_type
= ELF64_R_TYPE (rel
->r_info
);
11977 if (r_type
!= R_PPC64_REL24
11978 && r_type
!= R_PPC64_REL14
11979 && r_type
!= R_PPC64_REL14_BRTAKEN
11980 && r_type
!= R_PPC64_REL14_BRNTAKEN
11981 && r_type
!= R_PPC64_PLTCALL
)
11984 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11985 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11992 /* Calls to dynamic lib functions go through a plt call stub
11994 eh
= (struct ppc_link_hash_entry
*) h
;
11996 && (eh
->elf
.plt
.plist
!= NULL
11998 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12004 if (sym_sec
== NULL
)
12005 /* Ignore other undefined symbols. */
12008 /* Assume branches to other sections not included in the
12009 link need stubs too, to cover -R and absolute syms. */
12010 if (sym_sec
->output_section
== NULL
)
12017 sym_value
= sym
->st_value
;
12020 if (h
->root
.type
!= bfd_link_hash_defined
12021 && h
->root
.type
!= bfd_link_hash_defweak
)
12023 sym_value
= h
->root
.u
.def
.value
;
12025 sym_value
+= rel
->r_addend
;
12027 /* If this branch reloc uses an opd sym, find the code section. */
12028 opd
= get_opd_info (sym_sec
);
12031 if (h
== NULL
&& opd
->adjust
!= NULL
)
12035 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12037 /* Assume deleted functions won't ever be called. */
12039 sym_value
+= adjust
;
12042 dest
= opd_entry_value (sym_sec
, sym_value
,
12043 &sym_sec
, NULL
, FALSE
);
12044 if (dest
== (bfd_vma
) -1)
12049 + sym_sec
->output_offset
12050 + sym_sec
->output_section
->vma
);
12052 /* Ignore branch to self. */
12053 if (sym_sec
== isec
)
12056 /* If the called function uses the toc, we need a stub. */
12057 if (sym_sec
->has_toc_reloc
12058 || sym_sec
->makes_toc_func_call
)
12064 /* Assume any branch that needs a long branch stub might in fact
12065 need a plt_branch stub. A plt_branch stub uses r2. */
12066 else if (dest
- (isec
->output_offset
12067 + isec
->output_section
->vma
12068 + rel
->r_offset
) + (1 << 25)
12069 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
12077 /* If calling back to a section in the process of being
12078 tested, we can't say for sure that no toc adjusting stubs
12079 are needed, so don't return zero. */
12080 else if (sym_sec
->call_check_in_progress
)
12083 /* Branches to another section that itself doesn't have any TOC
12084 references are OK. Recursively call ourselves to check. */
12085 else if (!sym_sec
->call_check_done
)
12089 /* Mark current section as indeterminate, so that other
12090 sections that call back to current won't be marked as
12092 isec
->call_check_in_progress
= 1;
12093 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
12094 isec
->call_check_in_progress
= 0;
12105 if (local_syms
!= NULL
12106 && (elf_symtab_hdr (isec
->owner
).contents
12107 != (unsigned char *) local_syms
))
12109 if (elf_section_data (isec
)->relocs
!= relstart
)
12114 && isec
->map_head
.s
!= NULL
12115 && (strcmp (isec
->output_section
->name
, ".init") == 0
12116 || strcmp (isec
->output_section
->name
, ".fini") == 0))
12118 if (isec
->map_head
.s
->has_toc_reloc
12119 || isec
->map_head
.s
->makes_toc_func_call
)
12121 else if (!isec
->map_head
.s
->call_check_done
)
12124 isec
->call_check_in_progress
= 1;
12125 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
12126 isec
->call_check_in_progress
= 0;
12133 isec
->makes_toc_func_call
= 1;
12138 /* The linker repeatedly calls this function for each input section,
12139 in the order that input sections are linked into output sections.
12140 Build lists of input sections to determine groupings between which
12141 we may insert linker stubs. */
12144 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
12146 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12151 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
12152 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
12154 /* This happens to make the list in reverse order,
12155 which is what we want. */
12156 htab
->sec_info
[isec
->id
].u
.list
12157 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
12158 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
12161 if (htab
->multi_toc_needed
)
12163 /* Analyse sections that aren't already flagged as needing a
12164 valid toc pointer. Exclude .fixup for the linux kernel.
12165 .fixup contains branches, but only back to the function that
12166 hit an exception. */
12167 if (!(isec
->has_toc_reloc
12168 || (isec
->flags
& SEC_CODE
) == 0
12169 || strcmp (isec
->name
, ".fixup") == 0
12170 || isec
->call_check_done
))
12172 if (toc_adjusting_stub_needed (info
, isec
) < 0)
12175 /* Make all sections use the TOC assigned for this object file.
12176 This will be wrong for pasted sections; We fix that in
12177 check_pasted_section(). */
12178 if (elf_gp (isec
->owner
) != 0)
12179 htab
->toc_curr
= elf_gp (isec
->owner
);
12182 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
12186 /* Check that all .init and .fini sections use the same toc, if they
12187 have toc relocs. */
12190 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
12192 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
12196 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12197 bfd_vma toc_off
= 0;
12200 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12201 if (i
->has_toc_reloc
)
12204 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12205 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
12210 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12211 if (i
->makes_toc_func_call
)
12213 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12217 /* Make sure the whole pasted function uses the same toc offset. */
12219 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12220 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
12226 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
12228 return (check_pasted_section (info
, ".init")
12229 & check_pasted_section (info
, ".fini"));
12232 /* See whether we can group stub sections together. Grouping stub
12233 sections may result in fewer stubs. More importantly, we need to
12234 put all .init* and .fini* stubs at the beginning of the .init or
12235 .fini output sections respectively, because glibc splits the
12236 _init and _fini functions into multiple parts. Putting a stub in
12237 the middle of a function is not a good idea. */
12240 group_sections (struct bfd_link_info
*info
,
12241 bfd_size_type stub_group_size
,
12242 bfd_boolean stubs_always_before_branch
)
12244 struct ppc_link_hash_table
*htab
;
12246 bfd_boolean suppress_size_errors
;
12248 htab
= ppc_hash_table (info
);
12252 suppress_size_errors
= FALSE
;
12253 if (stub_group_size
== 1)
12255 /* Default values. */
12256 if (stubs_always_before_branch
)
12257 stub_group_size
= 0x1e00000;
12259 stub_group_size
= 0x1c00000;
12260 suppress_size_errors
= TRUE
;
12263 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
12267 if (osec
->id
>= htab
->sec_info_arr_size
)
12270 tail
= htab
->sec_info
[osec
->id
].u
.list
;
12271 while (tail
!= NULL
)
12275 bfd_size_type total
;
12276 bfd_boolean big_sec
;
12278 struct map_stub
*group
;
12279 bfd_size_type group_size
;
12282 total
= tail
->size
;
12283 group_size
= (ppc64_elf_section_data (tail
) != NULL
12284 && ppc64_elf_section_data (tail
)->has_14bit_branch
12285 ? stub_group_size
>> 10 : stub_group_size
);
12287 big_sec
= total
> group_size
;
12288 if (big_sec
&& !suppress_size_errors
)
12289 /* xgettext:c-format */
12290 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
12291 tail
->owner
, tail
);
12292 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
12294 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
12295 && ((total
+= curr
->output_offset
- prev
->output_offset
)
12296 < (ppc64_elf_section_data (prev
) != NULL
12297 && ppc64_elf_section_data (prev
)->has_14bit_branch
12298 ? (group_size
= stub_group_size
>> 10) : group_size
))
12299 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12302 /* OK, the size from the start of CURR to the end is less
12303 than group_size and thus can be handled by one stub
12304 section. (or the tail section is itself larger than
12305 group_size, in which case we may be toast.) We should
12306 really be keeping track of the total size of stubs added
12307 here, as stubs contribute to the final output section
12308 size. That's a little tricky, and this way will only
12309 break if stubs added make the total size more than 2^25,
12310 ie. for the default stub_group_size, if stubs total more
12311 than 2097152 bytes, or nearly 75000 plt call stubs. */
12312 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
12315 group
->link_sec
= curr
;
12316 group
->stub_sec
= NULL
;
12317 group
->needs_save_res
= 0;
12318 group
->tls_get_addr_opt_bctrl
= -1u;
12319 group
->next
= htab
->group
;
12320 htab
->group
= group
;
12323 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12324 /* Set up this stub group. */
12325 htab
->sec_info
[tail
->id
].u
.group
= group
;
12327 while (tail
!= curr
&& (tail
= prev
) != NULL
);
12329 /* But wait, there's more! Input sections up to group_size
12330 bytes before the stub section can be handled by it too.
12331 Don't do this if we have a really large section after the
12332 stubs, as adding more stubs increases the chance that
12333 branches may not reach into the stub section. */
12334 if (!stubs_always_before_branch
&& !big_sec
)
12337 while (prev
!= NULL
12338 && ((total
+= tail
->output_offset
- prev
->output_offset
)
12339 < (ppc64_elf_section_data (prev
) != NULL
12340 && ppc64_elf_section_data (prev
)->has_14bit_branch
12341 ? (group_size
= stub_group_size
>> 10) : group_size
))
12342 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12345 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12346 htab
->sec_info
[tail
->id
].u
.group
= group
;
12355 static const unsigned char glink_eh_frame_cie
[] =
12357 0, 0, 0, 16, /* length. */
12358 0, 0, 0, 0, /* id. */
12359 1, /* CIE version. */
12360 'z', 'R', 0, /* Augmentation string. */
12361 4, /* Code alignment. */
12362 0x78, /* Data alignment. */
12364 1, /* Augmentation size. */
12365 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12366 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
12370 stub_eh_frame_size (struct map_stub
*group
, size_t align
)
12372 size_t this_size
= 17;
12373 if (group
->tls_get_addr_opt_bctrl
!= -1u)
12375 unsigned int to_bctrl
= group
->tls_get_addr_opt_bctrl
/ 4;
12378 else if (to_bctrl
< 256)
12380 else if (to_bctrl
< 65536)
12386 this_size
= (this_size
+ align
- 1) & -align
;
12390 /* Stripping output sections is normally done before dynamic section
12391 symbols have been allocated. This function is called later, and
12392 handles cases like htab->brlt which is mapped to its own output
12396 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12398 if (isec
->size
== 0
12399 && isec
->output_section
->size
== 0
12400 && !(isec
->output_section
->flags
& SEC_KEEP
)
12401 && !bfd_section_removed_from_list (info
->output_bfd
,
12402 isec
->output_section
)
12403 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12405 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12406 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12407 info
->output_bfd
->section_count
--;
12411 /* Determine and set the size of the stub section for a final link.
12413 The basic idea here is to examine all the relocations looking for
12414 PC-relative calls to a target that is unreachable with a "bl"
12418 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12420 bfd_size_type stub_group_size
;
12421 bfd_boolean stubs_always_before_branch
;
12422 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12427 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12428 htab
->params
->plt_thread_safe
= 1;
12429 if (!htab
->opd_abi
)
12430 htab
->params
->plt_thread_safe
= 0;
12431 else if (htab
->params
->plt_thread_safe
== -1)
12433 static const char *const thread_starter
[] =
12437 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12439 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12440 "mq_notify", "create_timer",
12445 "GOMP_parallel_start",
12446 "GOMP_parallel_loop_static",
12447 "GOMP_parallel_loop_static_start",
12448 "GOMP_parallel_loop_dynamic",
12449 "GOMP_parallel_loop_dynamic_start",
12450 "GOMP_parallel_loop_guided",
12451 "GOMP_parallel_loop_guided_start",
12452 "GOMP_parallel_loop_runtime",
12453 "GOMP_parallel_loop_runtime_start",
12454 "GOMP_parallel_sections",
12455 "GOMP_parallel_sections_start",
12461 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12463 struct elf_link_hash_entry
*h
;
12464 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12465 FALSE
, FALSE
, TRUE
);
12466 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12467 if (htab
->params
->plt_thread_safe
)
12471 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12472 if (htab
->params
->group_size
< 0)
12473 stub_group_size
= -htab
->params
->group_size
;
12475 stub_group_size
= htab
->params
->group_size
;
12477 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12480 #define STUB_SHRINK_ITER 20
12481 /* Loop until no stubs added. After iteration 20 of this loop we may
12482 exit on a stub section shrinking. This is to break out of a
12483 pathological case where adding stubs on one iteration decreases
12484 section gaps (perhaps due to alignment), which then requires
12485 fewer or smaller stubs on the next iteration. */
12490 unsigned int bfd_indx
;
12491 struct map_stub
*group
;
12493 htab
->stub_iteration
+= 1;
12495 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12497 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12499 Elf_Internal_Shdr
*symtab_hdr
;
12501 Elf_Internal_Sym
*local_syms
= NULL
;
12503 if (!is_ppc64_elf (input_bfd
))
12506 /* We'll need the symbol table in a second. */
12507 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12508 if (symtab_hdr
->sh_info
== 0)
12511 /* Walk over each section attached to the input bfd. */
12512 for (section
= input_bfd
->sections
;
12514 section
= section
->next
)
12516 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12518 /* If there aren't any relocs, then there's nothing more
12520 if ((section
->flags
& SEC_RELOC
) == 0
12521 || (section
->flags
& SEC_ALLOC
) == 0
12522 || (section
->flags
& SEC_LOAD
) == 0
12523 || (section
->flags
& SEC_CODE
) == 0
12524 || section
->reloc_count
== 0)
12527 /* If this section is a link-once section that will be
12528 discarded, then don't create any stubs. */
12529 if (section
->output_section
== NULL
12530 || section
->output_section
->owner
!= info
->output_bfd
)
12533 /* Get the relocs. */
12535 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12536 info
->keep_memory
);
12537 if (internal_relocs
== NULL
)
12538 goto error_ret_free_local
;
12540 /* Now examine each relocation. */
12541 irela
= internal_relocs
;
12542 irelaend
= irela
+ section
->reloc_count
;
12543 for (; irela
< irelaend
; irela
++)
12545 enum elf_ppc64_reloc_type r_type
;
12546 unsigned int r_indx
;
12547 enum ppc_stub_type stub_type
;
12548 struct ppc_stub_hash_entry
*stub_entry
;
12549 asection
*sym_sec
, *code_sec
;
12550 bfd_vma sym_value
, code_value
;
12551 bfd_vma destination
;
12552 unsigned long local_off
;
12553 bfd_boolean ok_dest
;
12554 struct ppc_link_hash_entry
*hash
;
12555 struct ppc_link_hash_entry
*fdh
;
12556 struct elf_link_hash_entry
*h
;
12557 Elf_Internal_Sym
*sym
;
12559 const asection
*id_sec
;
12560 struct _opd_sec_data
*opd
;
12561 struct plt_entry
*plt_ent
;
12563 r_type
= ELF64_R_TYPE (irela
->r_info
);
12564 r_indx
= ELF64_R_SYM (irela
->r_info
);
12566 if (r_type
>= R_PPC64_max
)
12568 bfd_set_error (bfd_error_bad_value
);
12569 goto error_ret_free_internal
;
12572 /* Only look for stubs on branch instructions. */
12573 if (r_type
!= R_PPC64_REL24
12574 && r_type
!= R_PPC64_REL14
12575 && r_type
!= R_PPC64_REL14_BRTAKEN
12576 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12579 /* Now determine the call target, its name, value,
12581 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12582 r_indx
, input_bfd
))
12583 goto error_ret_free_internal
;
12584 hash
= (struct ppc_link_hash_entry
*) h
;
12591 sym_value
= sym
->st_value
;
12592 if (sym_sec
!= NULL
12593 && sym_sec
->output_section
!= NULL
)
12596 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12597 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12599 sym_value
= hash
->elf
.root
.u
.def
.value
;
12600 if (sym_sec
->output_section
!= NULL
)
12603 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12604 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12606 /* Recognise an old ABI func code entry sym, and
12607 use the func descriptor sym instead if it is
12609 if (hash
->elf
.root
.root
.string
[0] == '.'
12610 && hash
->oh
!= NULL
)
12612 fdh
= ppc_follow_link (hash
->oh
);
12613 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12614 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12616 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12617 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12618 if (sym_sec
->output_section
!= NULL
)
12627 bfd_set_error (bfd_error_bad_value
);
12628 goto error_ret_free_internal
;
12635 sym_value
+= irela
->r_addend
;
12636 destination
= (sym_value
12637 + sym_sec
->output_offset
12638 + sym_sec
->output_section
->vma
);
12639 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12644 code_sec
= sym_sec
;
12645 code_value
= sym_value
;
12646 opd
= get_opd_info (sym_sec
);
12651 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12653 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12656 code_value
+= adjust
;
12657 sym_value
+= adjust
;
12659 dest
= opd_entry_value (sym_sec
, sym_value
,
12660 &code_sec
, &code_value
, FALSE
);
12661 if (dest
!= (bfd_vma
) -1)
12663 destination
= dest
;
12666 /* Fixup old ABI sym to point at code
12668 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12669 hash
->elf
.root
.u
.def
.section
= code_sec
;
12670 hash
->elf
.root
.u
.def
.value
= code_value
;
12675 /* Determine what (if any) linker stub is needed. */
12677 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
12678 &plt_ent
, destination
,
12681 if (stub_type
!= ppc_stub_plt_call
)
12683 /* Check whether we need a TOC adjusting stub.
12684 Since the linker pastes together pieces from
12685 different object files when creating the
12686 _init and _fini functions, it may be that a
12687 call to what looks like a local sym is in
12688 fact a call needing a TOC adjustment. */
12689 if (code_sec
!= NULL
12690 && code_sec
->output_section
!= NULL
12691 && (htab
->sec_info
[code_sec
->id
].toc_off
12692 != htab
->sec_info
[section
->id
].toc_off
)
12693 && (code_sec
->has_toc_reloc
12694 || code_sec
->makes_toc_func_call
))
12695 stub_type
= ppc_stub_long_branch_r2off
;
12698 if (stub_type
== ppc_stub_none
)
12701 /* __tls_get_addr calls might be eliminated. */
12702 if (stub_type
!= ppc_stub_plt_call
12704 && (hash
== htab
->tls_get_addr
12705 || hash
== htab
->tls_get_addr_fd
)
12706 && section
->has_tls_reloc
12707 && irela
!= internal_relocs
)
12709 /* Get tls info. */
12710 unsigned char *tls_mask
;
12712 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12713 irela
- 1, input_bfd
))
12714 goto error_ret_free_internal
;
12715 if ((*tls_mask
& TLS_TLS
) != 0)
12719 if (stub_type
== ppc_stub_plt_call
)
12722 && htab
->params
->plt_localentry0
!= 0
12723 && is_elfv2_localentry0 (&hash
->elf
))
12724 htab
->has_plt_localentry0
= 1;
12725 else if (irela
+ 1 < irelaend
12726 && irela
[1].r_offset
== irela
->r_offset
+ 4
12727 && (ELF64_R_TYPE (irela
[1].r_info
)
12728 == R_PPC64_TOCSAVE
))
12730 if (!tocsave_find (htab
, INSERT
,
12731 &local_syms
, irela
+ 1, input_bfd
))
12732 goto error_ret_free_internal
;
12735 stub_type
= ppc_stub_plt_call_r2save
;
12738 /* Support for grouping stub sections. */
12739 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12741 /* Get the name of this stub. */
12742 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12744 goto error_ret_free_internal
;
12746 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12747 stub_name
, FALSE
, FALSE
);
12748 if (stub_entry
!= NULL
)
12750 /* The proper stub has already been created. */
12752 if (stub_type
== ppc_stub_plt_call_r2save
)
12753 stub_entry
->stub_type
= stub_type
;
12757 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12758 if (stub_entry
== NULL
)
12761 error_ret_free_internal
:
12762 if (elf_section_data (section
)->relocs
== NULL
)
12763 free (internal_relocs
);
12764 error_ret_free_local
:
12765 if (local_syms
!= NULL
12766 && (symtab_hdr
->contents
12767 != (unsigned char *) local_syms
))
12772 stub_entry
->stub_type
= stub_type
;
12773 if (stub_type
!= ppc_stub_plt_call
12774 && stub_type
!= ppc_stub_plt_call_r2save
)
12776 stub_entry
->target_value
= code_value
;
12777 stub_entry
->target_section
= code_sec
;
12781 stub_entry
->target_value
= sym_value
;
12782 stub_entry
->target_section
= sym_sec
;
12784 stub_entry
->h
= hash
;
12785 stub_entry
->plt_ent
= plt_ent
;
12786 stub_entry
->symtype
12787 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
12788 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12790 if (stub_entry
->h
!= NULL
)
12791 htab
->stub_globals
+= 1;
12794 /* We're done with the internal relocs, free them. */
12795 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12796 free (internal_relocs
);
12799 if (local_syms
!= NULL
12800 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12802 if (!info
->keep_memory
)
12805 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12809 /* We may have added some stubs. Find out the new size of the
12811 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12812 if (group
->stub_sec
!= NULL
)
12814 asection
*stub_sec
= group
->stub_sec
;
12816 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12817 || stub_sec
->rawsize
< stub_sec
->size
)
12818 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12819 stub_sec
->rawsize
= stub_sec
->size
;
12820 stub_sec
->size
= 0;
12821 stub_sec
->reloc_count
= 0;
12822 stub_sec
->flags
&= ~SEC_RELOC
;
12825 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12826 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
12827 htab
->brlt
->rawsize
= htab
->brlt
->size
;
12828 htab
->brlt
->size
= 0;
12829 htab
->brlt
->reloc_count
= 0;
12830 htab
->brlt
->flags
&= ~SEC_RELOC
;
12831 if (htab
->relbrlt
!= NULL
)
12832 htab
->relbrlt
->size
= 0;
12834 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12836 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12837 if (group
->needs_save_res
)
12838 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12840 if (info
->emitrelocations
12841 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12843 htab
->glink
->reloc_count
= 1;
12844 htab
->glink
->flags
|= SEC_RELOC
;
12847 if (htab
->glink_eh_frame
!= NULL
12848 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12849 && htab
->glink_eh_frame
->output_section
->size
> 8)
12851 size_t size
= 0, align
= 4;
12853 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12854 if (group
->stub_sec
!= NULL
)
12855 size
+= stub_eh_frame_size (group
, align
);
12856 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12857 size
+= (24 + align
- 1) & -align
;
12859 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
12860 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
12861 size
= (size
+ align
- 1) & -align
;
12862 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12863 htab
->glink_eh_frame
->size
= size
;
12866 if (htab
->params
->plt_stub_align
!= 0)
12867 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12868 if (group
->stub_sec
!= NULL
)
12870 int align
= abs (htab
->params
->plt_stub_align
);
12871 group
->stub_sec
->size
12872 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
12875 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12876 if (group
->stub_sec
!= NULL
12877 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
12878 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
12879 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
12883 && (htab
->brlt
->rawsize
== htab
->brlt
->size
12884 || (htab
->stub_iteration
> STUB_SHRINK_ITER
12885 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
12886 && (htab
->glink_eh_frame
== NULL
12887 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12890 /* Ask the linker to do its stuff. */
12891 (*htab
->params
->layout_sections_again
) ();
12894 if (htab
->glink_eh_frame
!= NULL
12895 && htab
->glink_eh_frame
->size
!= 0)
12898 bfd_byte
*p
, *last_fde
;
12899 size_t last_fde_len
, size
, align
, pad
;
12900 struct map_stub
*group
;
12902 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12905 htab
->glink_eh_frame
->contents
= p
;
12909 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12910 /* CIE length (rewrite in case little-endian). */
12911 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
12912 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12913 p
+= last_fde_len
+ 4;
12915 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12916 if (group
->stub_sec
!= NULL
)
12919 last_fde_len
= stub_eh_frame_size (group
, align
) - 4;
12921 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12924 val
= p
- htab
->glink_eh_frame
->contents
;
12925 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12927 /* Offset to stub section, written later. */
12929 /* stub section size. */
12930 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
12932 /* Augmentation. */
12934 if (group
->tls_get_addr_opt_bctrl
!= -1u)
12936 unsigned int to_bctrl
= group
->tls_get_addr_opt_bctrl
/ 4;
12938 /* This FDE needs more than just the default.
12939 Describe __tls_get_addr_opt stub LR. */
12941 *p
++ = DW_CFA_advance_loc
+ to_bctrl
;
12942 else if (to_bctrl
< 256)
12944 *p
++ = DW_CFA_advance_loc1
;
12947 else if (to_bctrl
< 65536)
12949 *p
++ = DW_CFA_advance_loc2
;
12950 bfd_put_16 (htab
->elf
.dynobj
, to_bctrl
, p
);
12955 *p
++ = DW_CFA_advance_loc4
;
12956 bfd_put_32 (htab
->elf
.dynobj
, to_bctrl
, p
);
12959 *p
++ = DW_CFA_offset_extended_sf
;
12961 *p
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
12962 *p
++ = DW_CFA_advance_loc
+ 4;
12963 *p
++ = DW_CFA_restore_extended
;
12967 p
= last_fde
+ last_fde_len
+ 4;
12969 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12972 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
12974 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12977 val
= p
- htab
->glink_eh_frame
->contents
;
12978 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12980 /* Offset to .glink, written later. */
12983 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12985 /* Augmentation. */
12988 *p
++ = DW_CFA_advance_loc
+ 1;
12989 *p
++ = DW_CFA_register
;
12991 *p
++ = htab
->opd_abi
? 12 : 0;
12992 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
12993 *p
++ = DW_CFA_restore_extended
;
12995 p
+= ((24 + align
- 1) & -align
) - 24;
12997 /* Subsume any padding into the last FDE if user .eh_frame
12998 sections are aligned more than glink_eh_frame. Otherwise any
12999 zero padding will be seen as a terminator. */
13000 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13001 size
= p
- htab
->glink_eh_frame
->contents
;
13002 pad
= ((size
+ align
- 1) & -align
) - size
;
13003 htab
->glink_eh_frame
->size
= size
+ pad
;
13004 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
13007 maybe_strip_output (info
, htab
->brlt
);
13008 if (htab
->glink_eh_frame
!= NULL
)
13009 maybe_strip_output (info
, htab
->glink_eh_frame
);
13014 /* Called after we have determined section placement. If sections
13015 move, we'll be called again. Provide a value for TOCstart. */
13018 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
13021 bfd_vma TOCstart
, adjust
;
13025 struct elf_link_hash_entry
*h
;
13026 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
13028 if (is_elf_hash_table (htab
)
13029 && htab
->hgot
!= NULL
)
13033 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
13034 if (is_elf_hash_table (htab
))
13038 && h
->root
.type
== bfd_link_hash_defined
13039 && !h
->root
.linker_def
13040 && (!is_elf_hash_table (htab
)
13041 || h
->def_regular
))
13043 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
13044 + h
->root
.u
.def
.section
->output_offset
13045 + h
->root
.u
.def
.section
->output_section
->vma
);
13046 _bfd_set_gp_value (obfd
, TOCstart
);
13051 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
13052 order. The TOC starts where the first of these sections starts. */
13053 s
= bfd_get_section_by_name (obfd
, ".got");
13054 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13055 s
= bfd_get_section_by_name (obfd
, ".toc");
13056 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13057 s
= bfd_get_section_by_name (obfd
, ".tocbss");
13058 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13059 s
= bfd_get_section_by_name (obfd
, ".plt");
13060 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13062 /* This may happen for
13063 o references to TOC base (SYM@toc / TOC[tc0]) without a
13065 o bad linker script
13066 o --gc-sections and empty TOC sections
13068 FIXME: Warn user? */
13070 /* Look for a likely section. We probably won't even be
13072 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13073 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
13075 == (SEC_ALLOC
| SEC_SMALL_DATA
))
13078 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13079 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
13080 == (SEC_ALLOC
| SEC_SMALL_DATA
))
13083 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13084 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
13088 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13089 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
13095 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
13097 /* Force alignment. */
13098 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
13099 TOCstart
-= adjust
;
13100 _bfd_set_gp_value (obfd
, TOCstart
);
13102 if (info
!= NULL
&& s
!= NULL
)
13104 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13108 if (htab
->elf
.hgot
!= NULL
)
13110 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
13111 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
13116 struct bfd_link_hash_entry
*bh
= NULL
;
13117 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
13118 s
, TOC_BASE_OFF
- adjust
,
13119 NULL
, FALSE
, FALSE
, &bh
);
13125 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
13126 write out any global entry stubs, and PLT relocations. */
13129 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
13131 struct bfd_link_info
*info
;
13132 struct ppc_link_hash_table
*htab
;
13133 struct plt_entry
*ent
;
13136 if (h
->root
.type
== bfd_link_hash_indirect
)
13140 htab
= ppc_hash_table (info
);
13144 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13145 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13147 /* This symbol has an entry in the procedure linkage
13148 table. Set it up. */
13149 Elf_Internal_Rela rela
;
13150 asection
*plt
, *relplt
;
13153 if (!htab
->elf
.dynamic_sections_created
13154 || h
->dynindx
== -1)
13156 if (!(h
->def_regular
13157 && (h
->root
.type
== bfd_link_hash_defined
13158 || h
->root
.type
== bfd_link_hash_defweak
)))
13160 if (h
->type
== STT_GNU_IFUNC
)
13162 plt
= htab
->elf
.iplt
;
13163 relplt
= htab
->elf
.irelplt
;
13164 htab
->local_ifunc_resolver
= 1;
13166 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13168 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13172 plt
= htab
->pltlocal
;
13173 if (bfd_link_pic (info
))
13175 relplt
= htab
->relpltlocal
;
13177 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13179 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13184 rela
.r_addend
= (h
->root
.u
.def
.value
13185 + h
->root
.u
.def
.section
->output_offset
13186 + h
->root
.u
.def
.section
->output_section
->vma
13189 if (relplt
== NULL
)
13191 loc
= plt
->contents
+ ent
->plt
.offset
;
13192 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
13195 bfd_vma toc
= elf_gp (info
->output_bfd
);
13196 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
13197 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13202 rela
.r_offset
= (plt
->output_section
->vma
13203 + plt
->output_offset
13204 + ent
->plt
.offset
);
13205 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13206 * sizeof (Elf64_External_Rela
));
13207 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13212 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
13213 + htab
->elf
.splt
->output_offset
13214 + ent
->plt
.offset
);
13215 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13216 rela
.r_addend
= ent
->addend
;
13217 loc
= (htab
->elf
.srelplt
->contents
13218 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
13219 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
13220 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
13221 htab
->maybe_local_ifunc_resolver
= 1;
13222 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13226 if (!h
->pointer_equality_needed
)
13229 if (h
->def_regular
)
13232 s
= htab
->global_entry
;
13233 if (s
== NULL
|| s
->size
== 0)
13236 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13237 if (ent
->plt
.offset
!= (bfd_vma
) -1
13238 && ent
->addend
== 0)
13244 p
= s
->contents
+ h
->root
.u
.def
.value
;
13245 plt
= htab
->elf
.splt
;
13246 if (!htab
->elf
.dynamic_sections_created
13247 || h
->dynindx
== -1)
13249 if (h
->type
== STT_GNU_IFUNC
)
13250 plt
= htab
->elf
.iplt
;
13252 plt
= htab
->pltlocal
;
13254 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
13255 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
13257 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
13259 info
->callbacks
->einfo
13260 (_("%P: linkage table error against `%pT'\n"),
13261 h
->root
.root
.string
);
13262 bfd_set_error (bfd_error_bad_value
);
13263 htab
->stub_error
= TRUE
;
13266 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
13267 if (htab
->params
->emit_stub_syms
)
13269 size_t len
= strlen (h
->root
.root
.string
);
13270 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
13275 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
13276 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
13279 if (h
->root
.type
== bfd_link_hash_new
)
13281 h
->root
.type
= bfd_link_hash_defined
;
13282 h
->root
.u
.def
.section
= s
;
13283 h
->root
.u
.def
.value
= p
- s
->contents
;
13284 h
->ref_regular
= 1;
13285 h
->def_regular
= 1;
13286 h
->ref_regular_nonweak
= 1;
13287 h
->forced_local
= 1;
13289 h
->root
.linker_def
= 1;
13293 if (PPC_HA (off
) != 0)
13295 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
13298 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
13300 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
13302 bfd_put_32 (s
->owner
, BCTR
, p
);
13308 /* Write PLT relocs for locals. */
13311 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
13313 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13316 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13318 struct got_entry
**lgot_ents
, **end_lgot_ents
;
13319 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13320 Elf_Internal_Shdr
*symtab_hdr
;
13321 bfd_size_type locsymcount
;
13322 Elf_Internal_Sym
*local_syms
= NULL
;
13323 struct plt_entry
*ent
;
13325 if (!is_ppc64_elf (ibfd
))
13328 lgot_ents
= elf_local_got_ents (ibfd
);
13332 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13333 locsymcount
= symtab_hdr
->sh_info
;
13334 end_lgot_ents
= lgot_ents
+ locsymcount
;
13335 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13336 end_local_plt
= local_plt
+ locsymcount
;
13337 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
13338 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
13339 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13341 Elf_Internal_Sym
*sym
;
13343 asection
*plt
, *relplt
;
13347 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
13348 lplt
- local_plt
, ibfd
))
13350 if (local_syms
!= NULL
13351 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13356 val
= sym
->st_value
+ ent
->addend
;
13357 val
+= PPC64_LOCAL_ENTRY_OFFSET (sym
->st_other
);
13358 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
13359 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
13361 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13363 htab
->local_ifunc_resolver
= 1;
13364 plt
= htab
->elf
.iplt
;
13365 relplt
= htab
->elf
.irelplt
;
13369 plt
= htab
->pltlocal
;
13370 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
13373 if (relplt
== NULL
)
13375 loc
= plt
->contents
+ ent
->plt
.offset
;
13376 bfd_put_64 (info
->output_bfd
, val
, loc
);
13379 bfd_vma toc
= elf_gp (ibfd
);
13380 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13385 Elf_Internal_Rela rela
;
13386 rela
.r_offset
= (ent
->plt
.offset
13387 + plt
->output_offset
13388 + plt
->output_section
->vma
);
13389 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13392 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13394 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13399 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13401 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13403 rela
.r_addend
= val
;
13404 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13405 * sizeof (Elf64_External_Rela
));
13406 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13410 if (local_syms
!= NULL
13411 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13413 if (!info
->keep_memory
)
13416 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13422 /* Build all the stubs associated with the current output file.
13423 The stubs are kept in a hash table attached to the main linker
13424 hash table. This function is called via gldelf64ppc_finish. */
13427 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
13430 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13431 struct map_stub
*group
;
13432 asection
*stub_sec
;
13434 int stub_sec_count
= 0;
13439 /* Allocate memory to hold the linker stubs. */
13440 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13441 if ((stub_sec
= group
->stub_sec
) != NULL
13442 && stub_sec
->size
!= 0)
13444 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
, stub_sec
->size
);
13445 if (stub_sec
->contents
== NULL
)
13447 stub_sec
->size
= 0;
13450 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13455 /* Build the .glink plt call stub. */
13456 if (htab
->params
->emit_stub_syms
)
13458 struct elf_link_hash_entry
*h
;
13459 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
13460 TRUE
, FALSE
, FALSE
);
13463 if (h
->root
.type
== bfd_link_hash_new
)
13465 h
->root
.type
= bfd_link_hash_defined
;
13466 h
->root
.u
.def
.section
= htab
->glink
;
13467 h
->root
.u
.def
.value
= 8;
13468 h
->ref_regular
= 1;
13469 h
->def_regular
= 1;
13470 h
->ref_regular_nonweak
= 1;
13471 h
->forced_local
= 1;
13473 h
->root
.linker_def
= 1;
13476 plt0
= (htab
->elf
.splt
->output_section
->vma
13477 + htab
->elf
.splt
->output_offset
13479 if (info
->emitrelocations
)
13481 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
13484 r
->r_offset
= (htab
->glink
->output_offset
13485 + htab
->glink
->output_section
->vma
);
13486 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
13487 r
->r_addend
= plt0
;
13489 p
= htab
->glink
->contents
;
13490 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
13491 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
13495 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
13497 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13499 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13501 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13503 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
13505 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13507 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13509 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
13511 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13513 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
13518 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
13520 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13522 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13524 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
13526 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13528 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
13530 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
13532 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13534 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
13536 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13538 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
13540 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13542 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
13545 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
13547 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
13549 /* Build the .glink lazy link call stubs. */
13551 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
13557 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
13562 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
13564 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
13569 bfd_put_32 (htab
->glink
->owner
,
13570 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
13576 /* Build .glink global entry stubs, and PLT relocs for globals. */
13577 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
13579 if (!write_plt_relocs_for_local_syms (info
))
13582 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
13584 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
13586 if (htab
->brlt
->contents
== NULL
)
13589 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
13591 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
13592 htab
->relbrlt
->size
);
13593 if (htab
->relbrlt
->contents
== NULL
)
13597 /* Build the stubs as directed by the stub hash table. */
13598 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
13600 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13601 if (group
->needs_save_res
)
13602 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13604 if (htab
->relbrlt
!= NULL
)
13605 htab
->relbrlt
->reloc_count
= 0;
13607 if (htab
->params
->plt_stub_align
!= 0)
13608 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13609 if ((stub_sec
= group
->stub_sec
) != NULL
)
13611 int align
= abs (htab
->params
->plt_stub_align
);
13612 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13615 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13616 if (group
->needs_save_res
)
13618 stub_sec
= group
->stub_sec
;
13619 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
13620 htab
->sfpr
->contents
, htab
->sfpr
->size
);
13621 if (htab
->params
->emit_stub_syms
)
13625 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13626 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13631 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13632 if ((stub_sec
= group
->stub_sec
) != NULL
)
13634 stub_sec_count
+= 1;
13635 if (stub_sec
->rawsize
!= stub_sec
->size
13636 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13637 || stub_sec
->rawsize
< stub_sec
->size
))
13643 htab
->stub_error
= TRUE
;
13644 _bfd_error_handler (_("stubs don't match calculated size"));
13647 if (htab
->stub_error
)
13653 *stats
= bfd_malloc (500);
13654 if (*stats
== NULL
)
13657 len
= sprintf (*stats
,
13658 ngettext ("linker stubs in %u group\n",
13659 "linker stubs in %u groups\n",
13662 sprintf (*stats
+ len
, _(" branch %lu\n"
13663 " toc adjust %lu\n"
13664 " long branch %lu\n"
13665 " long toc adj %lu\n"
13667 " plt call toc %lu\n"
13668 " global entry %lu"),
13669 htab
->stub_count
[ppc_stub_long_branch
- 1],
13670 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13671 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13672 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13673 htab
->stub_count
[ppc_stub_plt_call
- 1],
13674 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13675 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13680 /* What to do when ld finds relocations against symbols defined in
13681 discarded sections. */
13683 static unsigned int
13684 ppc64_elf_action_discarded (asection
*sec
)
13686 if (strcmp (".opd", sec
->name
) == 0)
13689 if (strcmp (".toc", sec
->name
) == 0)
13692 if (strcmp (".toc1", sec
->name
) == 0)
13695 return _bfd_elf_default_action_discarded (sec
);
13698 /* The RELOCATE_SECTION function is called by the ELF backend linker
13699 to handle the relocations for a section.
13701 The relocs are always passed as Rela structures; if the section
13702 actually uses Rel structures, the r_addend field will always be
13705 This function is responsible for adjust the section contents as
13706 necessary, and (if using Rela relocs and generating a
13707 relocatable output file) adjusting the reloc addend as
13710 This function does not have to worry about setting the reloc
13711 address or the reloc symbol index.
13713 LOCAL_SYMS is a pointer to the swapped in local symbols.
13715 LOCAL_SECTIONS is an array giving the section in the input file
13716 corresponding to the st_shndx field of each local symbol.
13718 The global hash table entry for the global symbols can be found
13719 via elf_sym_hashes (input_bfd).
13721 When generating relocatable output, this function must handle
13722 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13723 going to be the section symbol corresponding to the output
13724 section, which means that the addend must be adjusted
13728 ppc64_elf_relocate_section (bfd
*output_bfd
,
13729 struct bfd_link_info
*info
,
13731 asection
*input_section
,
13732 bfd_byte
*contents
,
13733 Elf_Internal_Rela
*relocs
,
13734 Elf_Internal_Sym
*local_syms
,
13735 asection
**local_sections
)
13737 struct ppc_link_hash_table
*htab
;
13738 Elf_Internal_Shdr
*symtab_hdr
;
13739 struct elf_link_hash_entry
**sym_hashes
;
13740 Elf_Internal_Rela
*rel
;
13741 Elf_Internal_Rela
*wrel
;
13742 Elf_Internal_Rela
*relend
;
13743 Elf_Internal_Rela outrel
;
13745 struct got_entry
**local_got_ents
;
13747 bfd_boolean ret
= TRUE
;
13748 bfd_boolean is_opd
;
13749 /* Assume 'at' branch hints. */
13750 bfd_boolean is_isa_v2
= TRUE
;
13751 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13753 /* Initialize howto table if needed. */
13754 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13757 htab
= ppc_hash_table (info
);
13761 /* Don't relocate stub sections. */
13762 if (input_section
->owner
== htab
->params
->stub_bfd
)
13765 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13767 local_got_ents
= elf_local_got_ents (input_bfd
);
13768 TOCstart
= elf_gp (output_bfd
);
13769 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13770 sym_hashes
= elf_sym_hashes (input_bfd
);
13771 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13773 rel
= wrel
= relocs
;
13774 relend
= relocs
+ input_section
->reloc_count
;
13775 for (; rel
< relend
; wrel
++, rel
++)
13777 enum elf_ppc64_reloc_type r_type
;
13779 bfd_reloc_status_type r
;
13780 Elf_Internal_Sym
*sym
;
13782 struct elf_link_hash_entry
*h_elf
;
13783 struct ppc_link_hash_entry
*h
;
13784 struct ppc_link_hash_entry
*fdh
;
13785 const char *sym_name
;
13786 unsigned long r_symndx
, toc_symndx
;
13787 bfd_vma toc_addend
;
13788 unsigned char tls_mask
, tls_gd
, tls_type
;
13789 unsigned char sym_type
;
13790 bfd_vma relocation
;
13791 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
13792 bfd_boolean warned
;
13793 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13796 struct ppc_stub_hash_entry
*stub_entry
;
13797 bfd_vma max_br_offset
;
13799 Elf_Internal_Rela orig_rel
;
13800 reloc_howto_type
*howto
;
13801 struct reloc_howto_struct alt_howto
;
13806 r_type
= ELF64_R_TYPE (rel
->r_info
);
13807 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13809 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13810 symbol of the previous ADDR64 reloc. The symbol gives us the
13811 proper TOC base to use. */
13812 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13814 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13816 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13822 unresolved_reloc
= FALSE
;
13825 if (r_symndx
< symtab_hdr
->sh_info
)
13827 /* It's a local symbol. */
13828 struct _opd_sec_data
*opd
;
13830 sym
= local_syms
+ r_symndx
;
13831 sec
= local_sections
[r_symndx
];
13832 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13833 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13834 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13835 opd
= get_opd_info (sec
);
13836 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13838 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13844 /* If this is a relocation against the opd section sym
13845 and we have edited .opd, adjust the reloc addend so
13846 that ld -r and ld --emit-relocs output is correct.
13847 If it is a reloc against some other .opd symbol,
13848 then the symbol value will be adjusted later. */
13849 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13850 rel
->r_addend
+= adjust
;
13852 relocation
+= adjust
;
13858 bfd_boolean ignored
;
13860 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13861 r_symndx
, symtab_hdr
, sym_hashes
,
13862 h_elf
, sec
, relocation
,
13863 unresolved_reloc
, warned
, ignored
);
13864 sym_name
= h_elf
->root
.root
.string
;
13865 sym_type
= h_elf
->type
;
13867 && sec
->owner
== output_bfd
13868 && strcmp (sec
->name
, ".opd") == 0)
13870 /* This is a symbol defined in a linker script. All
13871 such are defined in output sections, even those
13872 defined by simple assignment from a symbol defined in
13873 an input section. Transfer the symbol to an
13874 appropriate input .opd section, so that a branch to
13875 this symbol will be mapped to the location specified
13876 by the opd entry. */
13877 struct bfd_link_order
*lo
;
13878 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13879 if (lo
->type
== bfd_indirect_link_order
)
13881 asection
*isec
= lo
->u
.indirect
.section
;
13882 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13883 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13886 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13887 h_elf
->root
.u
.def
.section
= isec
;
13894 h
= (struct ppc_link_hash_entry
*) h_elf
;
13896 if (sec
!= NULL
&& discarded_section (sec
))
13898 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
13899 input_bfd
, input_section
,
13900 contents
+ rel
->r_offset
);
13901 wrel
->r_offset
= rel
->r_offset
;
13903 wrel
->r_addend
= 0;
13905 /* For ld -r, remove relocations in debug sections against
13906 symbols defined in discarded sections. Not done for
13907 non-debug to preserve relocs in .eh_frame which the
13908 eh_frame editing code expects to be present. */
13909 if (bfd_link_relocatable (info
)
13910 && (input_section
->flags
& SEC_DEBUGGING
))
13916 if (bfd_link_relocatable (info
))
13919 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13921 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13922 sec
= bfd_abs_section_ptr
;
13923 unresolved_reloc
= FALSE
;
13926 /* TLS optimizations. Replace instruction sequences and relocs
13927 based on information we collected in tls_optimize. We edit
13928 RELOCS so that --emit-relocs will output something sensible
13929 for the final instruction stream. */
13934 tls_mask
= h
->tls_mask
;
13935 else if (local_got_ents
!= NULL
)
13937 struct plt_entry
**local_plt
= (struct plt_entry
**)
13938 (local_got_ents
+ symtab_hdr
->sh_info
);
13939 unsigned char *lgot_masks
= (unsigned char *)
13940 (local_plt
+ symtab_hdr
->sh_info
);
13941 tls_mask
= lgot_masks
[r_symndx
];
13943 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
13944 && (r_type
== R_PPC64_TLS
13945 || r_type
== R_PPC64_TLSGD
13946 || r_type
== R_PPC64_TLSLD
))
13948 /* Check for toc tls entries. */
13949 unsigned char *toc_tls
;
13951 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13952 &local_syms
, rel
, input_bfd
))
13956 tls_mask
= *toc_tls
;
13959 /* Check that tls relocs are used with tls syms, and non-tls
13960 relocs are used with non-tls syms. */
13961 if (r_symndx
!= STN_UNDEF
13962 && r_type
!= R_PPC64_NONE
13964 || h
->elf
.root
.type
== bfd_link_hash_defined
13965 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13966 && (IS_PPC64_TLS_RELOC (r_type
)
13967 != (sym_type
== STT_TLS
13968 || (sym_type
== STT_SECTION
13969 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13971 if ((tls_mask
& TLS_TLS
) != 0
13972 && (r_type
== R_PPC64_TLS
13973 || r_type
== R_PPC64_TLSGD
13974 || r_type
== R_PPC64_TLSLD
))
13975 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13978 info
->callbacks
->einfo
13979 (!IS_PPC64_TLS_RELOC (r_type
)
13980 /* xgettext:c-format */
13981 ? _("%H: %s used with TLS symbol `%pT'\n")
13982 /* xgettext:c-format */
13983 : _("%H: %s used with non-TLS symbol `%pT'\n"),
13984 input_bfd
, input_section
, rel
->r_offset
,
13985 ppc64_elf_howto_table
[r_type
]->name
,
13989 /* Ensure reloc mapping code below stays sane. */
13990 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13991 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13992 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13993 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13994 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13995 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13996 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13997 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13998 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13999 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
14007 case R_PPC64_LO_DS_OPT
:
14008 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
14009 if ((insn
& (0x3f << 26)) != 58u << 26)
14011 insn
+= (14u << 26) - (58u << 26);
14012 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
14013 r_type
= R_PPC64_TOC16_LO
;
14014 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14017 case R_PPC64_TOC16
:
14018 case R_PPC64_TOC16_LO
:
14019 case R_PPC64_TOC16_DS
:
14020 case R_PPC64_TOC16_LO_DS
:
14022 /* Check for toc tls entries. */
14023 unsigned char *toc_tls
;
14026 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
14027 &local_syms
, rel
, input_bfd
);
14033 tls_mask
= *toc_tls
;
14034 if (r_type
== R_PPC64_TOC16_DS
14035 || r_type
== R_PPC64_TOC16_LO_DS
)
14037 if ((tls_mask
& TLS_TLS
) != 0
14038 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
14043 /* If we found a GD reloc pair, then we might be
14044 doing a GD->IE transition. */
14047 tls_gd
= TLS_TPRELGD
;
14048 if ((tls_mask
& TLS_TLS
) != 0
14049 && (tls_mask
& TLS_GD
) == 0)
14052 else if (retval
== 3)
14054 if ((tls_mask
& TLS_TLS
) != 0
14055 && (tls_mask
& TLS_LD
) == 0)
14063 case R_PPC64_GOT_TPREL16_HI
:
14064 case R_PPC64_GOT_TPREL16_HA
:
14065 if ((tls_mask
& TLS_TLS
) != 0
14066 && (tls_mask
& TLS_TPREL
) == 0)
14068 rel
->r_offset
-= d_offset
;
14069 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14070 r_type
= R_PPC64_NONE
;
14071 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14075 case R_PPC64_GOT_TPREL16_DS
:
14076 case R_PPC64_GOT_TPREL16_LO_DS
:
14077 if ((tls_mask
& TLS_TLS
) != 0
14078 && (tls_mask
& TLS_TPREL
) == 0)
14081 insn
= bfd_get_32 (input_bfd
,
14082 contents
+ rel
->r_offset
- d_offset
);
14084 insn
|= 0x3c0d0000; /* addis 0,13,0 */
14085 bfd_put_32 (input_bfd
, insn
,
14086 contents
+ rel
->r_offset
- d_offset
);
14087 r_type
= R_PPC64_TPREL16_HA
;
14088 if (toc_symndx
!= 0)
14090 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
14091 rel
->r_addend
= toc_addend
;
14092 /* We changed the symbol. Start over in order to
14093 get h, sym, sec etc. right. */
14097 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14102 if ((tls_mask
& TLS_TLS
) != 0
14103 && (tls_mask
& TLS_TPREL
) == 0)
14105 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14106 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
14109 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14110 /* Was PPC64_TLS which sits on insn boundary, now
14111 PPC64_TPREL16_LO which is at low-order half-word. */
14112 rel
->r_offset
+= d_offset
;
14113 r_type
= R_PPC64_TPREL16_LO
;
14114 if (toc_symndx
!= 0)
14116 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
14117 rel
->r_addend
= toc_addend
;
14118 /* We changed the symbol. Start over in order to
14119 get h, sym, sec etc. right. */
14123 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14127 case R_PPC64_GOT_TLSGD16_HI
:
14128 case R_PPC64_GOT_TLSGD16_HA
:
14129 tls_gd
= TLS_TPRELGD
;
14130 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14134 case R_PPC64_GOT_TLSLD16_HI
:
14135 case R_PPC64_GOT_TLSLD16_HA
:
14136 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14139 if ((tls_mask
& tls_gd
) != 0)
14140 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
14141 + R_PPC64_GOT_TPREL16_DS
);
14144 rel
->r_offset
-= d_offset
;
14145 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14146 r_type
= R_PPC64_NONE
;
14148 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14152 case R_PPC64_GOT_TLSGD16
:
14153 case R_PPC64_GOT_TLSGD16_LO
:
14154 tls_gd
= TLS_TPRELGD
;
14155 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14159 case R_PPC64_GOT_TLSLD16
:
14160 case R_PPC64_GOT_TLSLD16_LO
:
14161 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14163 unsigned int insn1
, insn2
;
14167 offset
= (bfd_vma
) -1;
14168 /* If not using the newer R_PPC64_TLSGD/LD to mark
14169 __tls_get_addr calls, we must trust that the call
14170 stays with its arg setup insns, ie. that the next
14171 reloc is the __tls_get_addr call associated with
14172 the current reloc. Edit both insns. */
14173 if (input_section
->has_tls_get_addr_call
14174 && rel
+ 1 < relend
14175 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
14176 htab
->tls_get_addr
,
14177 htab
->tls_get_addr_fd
))
14178 offset
= rel
[1].r_offset
;
14179 /* We read the low GOT_TLS (or TOC16) insn because we
14180 need to keep the destination reg. It may be
14181 something other than the usual r3, and moved to r3
14182 before the call by intervening code. */
14183 insn1
= bfd_get_32 (input_bfd
,
14184 contents
+ rel
->r_offset
- d_offset
);
14185 if ((tls_mask
& tls_gd
) != 0)
14188 insn1
&= (0x1f << 21) | (0x1f << 16);
14189 insn1
|= 58 << 26; /* ld */
14190 insn2
= 0x7c636a14; /* add 3,3,13 */
14191 if (offset
!= (bfd_vma
) -1)
14192 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14193 if ((tls_mask
& TLS_EXPLICIT
) == 0)
14194 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
14195 + R_PPC64_GOT_TPREL16_DS
);
14197 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
14198 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14203 insn1
&= 0x1f << 21;
14204 insn1
|= 0x3c0d0000; /* addis r,13,0 */
14205 insn2
= 0x38630000; /* addi 3,3,0 */
14208 /* Was an LD reloc. */
14210 sec
= local_sections
[toc_symndx
];
14212 r_symndx
< symtab_hdr
->sh_info
;
14214 if (local_sections
[r_symndx
] == sec
)
14216 if (r_symndx
>= symtab_hdr
->sh_info
)
14217 r_symndx
= STN_UNDEF
;
14218 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14219 if (r_symndx
!= STN_UNDEF
)
14220 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
14221 + sec
->output_offset
14222 + sec
->output_section
->vma
);
14224 else if (toc_symndx
!= 0)
14226 r_symndx
= toc_symndx
;
14227 rel
->r_addend
= toc_addend
;
14229 r_type
= R_PPC64_TPREL16_HA
;
14230 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14231 if (offset
!= (bfd_vma
) -1)
14233 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
14234 R_PPC64_TPREL16_LO
);
14235 rel
[1].r_offset
= offset
+ d_offset
;
14236 rel
[1].r_addend
= rel
->r_addend
;
14239 bfd_put_32 (input_bfd
, insn1
,
14240 contents
+ rel
->r_offset
- d_offset
);
14241 if (offset
!= (bfd_vma
) -1)
14242 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14243 if ((tls_mask
& tls_gd
) == 0
14244 && (tls_gd
== 0 || toc_symndx
!= 0))
14246 /* We changed the symbol. Start over in order
14247 to get h, sym, sec etc. right. */
14253 case R_PPC64_TLSGD
:
14254 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
14255 && rel
+ 1 < relend
)
14257 unsigned int insn2
;
14258 bfd_vma offset
= rel
->r_offset
;
14260 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
14262 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14263 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14267 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14268 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14270 if ((tls_mask
& TLS_TPRELGD
) != 0)
14273 r_type
= R_PPC64_NONE
;
14274 insn2
= 0x7c636a14; /* add 3,3,13 */
14279 if (toc_symndx
!= 0)
14281 r_symndx
= toc_symndx
;
14282 rel
->r_addend
= toc_addend
;
14284 r_type
= R_PPC64_TPREL16_LO
;
14285 rel
->r_offset
= offset
+ d_offset
;
14286 insn2
= 0x38630000; /* addi 3,3,0 */
14288 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14289 /* Zap the reloc on the _tls_get_addr call too. */
14290 BFD_ASSERT (offset
== rel
[1].r_offset
);
14291 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14292 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14293 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
14298 case R_PPC64_TLSLD
:
14299 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
14300 && rel
+ 1 < relend
)
14302 unsigned int insn2
;
14303 bfd_vma offset
= rel
->r_offset
;
14305 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
14307 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14308 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14312 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14313 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14316 sec
= local_sections
[toc_symndx
];
14318 r_symndx
< symtab_hdr
->sh_info
;
14320 if (local_sections
[r_symndx
] == sec
)
14322 if (r_symndx
>= symtab_hdr
->sh_info
)
14323 r_symndx
= STN_UNDEF
;
14324 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14325 if (r_symndx
!= STN_UNDEF
)
14326 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
14327 + sec
->output_offset
14328 + sec
->output_section
->vma
);
14330 r_type
= R_PPC64_TPREL16_LO
;
14331 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14332 rel
->r_offset
= offset
+ d_offset
;
14333 /* Zap the reloc on the _tls_get_addr call too. */
14334 BFD_ASSERT (offset
== rel
[1].r_offset
);
14335 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14336 insn2
= 0x38630000; /* addi 3,3,0 */
14337 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14342 case R_PPC64_DTPMOD64
:
14343 if (rel
+ 1 < relend
14344 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
14345 && rel
[1].r_offset
== rel
->r_offset
+ 8)
14347 if ((tls_mask
& TLS_GD
) == 0)
14349 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
14350 if ((tls_mask
& TLS_TPRELGD
) != 0)
14351 r_type
= R_PPC64_TPREL64
;
14354 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14355 r_type
= R_PPC64_NONE
;
14357 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14362 if ((tls_mask
& TLS_LD
) == 0)
14364 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14365 r_type
= R_PPC64_NONE
;
14366 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14371 case R_PPC64_TPREL64
:
14372 if ((tls_mask
& TLS_TPREL
) == 0)
14374 r_type
= R_PPC64_NONE
;
14375 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14379 case R_PPC64_ENTRY
:
14380 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14381 if (!bfd_link_pic (info
)
14382 && !info
->traditional_format
14383 && relocation
+ 0x80008000 <= 0xffffffff)
14385 unsigned int insn1
, insn2
;
14387 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14388 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14389 if ((insn1
& ~0xfffc) == LD_R2_0R12
14390 && insn2
== ADD_R2_R2_R12
)
14392 bfd_put_32 (input_bfd
,
14393 LIS_R2
+ PPC_HA (relocation
),
14394 contents
+ rel
->r_offset
);
14395 bfd_put_32 (input_bfd
,
14396 ADDI_R2_R2
+ PPC_LO (relocation
),
14397 contents
+ rel
->r_offset
+ 4);
14402 relocation
-= (rel
->r_offset
14403 + input_section
->output_offset
14404 + input_section
->output_section
->vma
);
14405 if (relocation
+ 0x80008000 <= 0xffffffff)
14407 unsigned int insn1
, insn2
;
14409 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14410 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14411 if ((insn1
& ~0xfffc) == LD_R2_0R12
14412 && insn2
== ADD_R2_R2_R12
)
14414 bfd_put_32 (input_bfd
,
14415 ADDIS_R2_R12
+ PPC_HA (relocation
),
14416 contents
+ rel
->r_offset
);
14417 bfd_put_32 (input_bfd
,
14418 ADDI_R2_R2
+ PPC_LO (relocation
),
14419 contents
+ rel
->r_offset
+ 4);
14425 case R_PPC64_REL16_HA
:
14426 /* If we are generating a non-PIC executable, edit
14427 . 0: addis 2,12,.TOC.-0b@ha
14428 . addi 2,2,.TOC.-0b@l
14429 used by ELFv2 global entry points to set up r2, to
14432 if .TOC. is in range. */
14433 if (!bfd_link_pic (info
)
14434 && !info
->traditional_format
14436 && rel
->r_addend
== d_offset
14437 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
14438 && rel
+ 1 < relend
14439 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
14440 && rel
[1].r_offset
== rel
->r_offset
+ 4
14441 && rel
[1].r_addend
== rel
->r_addend
+ 4
14442 && relocation
+ 0x80008000 <= 0xffffffff)
14444 unsigned int insn1
, insn2
;
14445 bfd_vma offset
= rel
->r_offset
- d_offset
;
14446 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
14447 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14448 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
14449 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
14451 r_type
= R_PPC64_ADDR16_HA
;
14452 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14453 rel
->r_addend
-= d_offset
;
14454 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
14455 rel
[1].r_addend
-= d_offset
+ 4;
14456 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
14462 /* Handle other relocations that tweak non-addend part of insn. */
14464 max_br_offset
= 1 << 25;
14465 addend
= rel
->r_addend
;
14466 reloc_dest
= DEST_NORMAL
;
14472 case R_PPC64_TOCSAVE
:
14473 if (relocation
+ addend
== (rel
->r_offset
14474 + input_section
->output_offset
14475 + input_section
->output_section
->vma
)
14476 && tocsave_find (htab
, NO_INSERT
,
14477 &local_syms
, rel
, input_bfd
))
14479 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14481 || insn
== CROR_151515
|| insn
== CROR_313131
)
14482 bfd_put_32 (input_bfd
,
14483 STD_R2_0R1
+ STK_TOC (htab
),
14484 contents
+ rel
->r_offset
);
14488 /* Branch taken prediction relocations. */
14489 case R_PPC64_ADDR14_BRTAKEN
:
14490 case R_PPC64_REL14_BRTAKEN
:
14491 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14492 /* Fall through. */
14494 /* Branch not taken prediction relocations. */
14495 case R_PPC64_ADDR14_BRNTAKEN
:
14496 case R_PPC64_REL14_BRNTAKEN
:
14497 insn
|= bfd_get_32 (input_bfd
,
14498 contents
+ rel
->r_offset
) & ~(0x01 << 21);
14499 /* Fall through. */
14501 case R_PPC64_REL14
:
14502 max_br_offset
= 1 << 15;
14503 /* Fall through. */
14505 case R_PPC64_REL24
:
14506 case R_PPC64_PLTCALL
:
14507 /* Calls to functions with a different TOC, such as calls to
14508 shared objects, need to alter the TOC pointer. This is
14509 done using a linkage stub. A REL24 branching to these
14510 linkage stubs needs to be followed by a nop, as the nop
14511 will be replaced with an instruction to restore the TOC
14516 && h
->oh
->is_func_descriptor
)
14517 fdh
= ppc_follow_link (h
->oh
);
14518 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
14520 if (r_type
== R_PPC64_PLTCALL
14521 && stub_entry
!= NULL
14522 && (stub_entry
->stub_type
== ppc_stub_plt_call
14523 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
14526 if (stub_entry
!= NULL
14527 && (stub_entry
->stub_type
== ppc_stub_plt_call
14528 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14529 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14530 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
14532 bfd_boolean can_plt_call
= FALSE
;
14534 if (stub_entry
->stub_type
== ppc_stub_plt_call
14536 && htab
->params
->plt_localentry0
!= 0
14537 && is_elfv2_localentry0 (&h
->elf
))
14539 /* The function doesn't use or change r2. */
14540 can_plt_call
= TRUE
;
14543 /* All of these stubs may modify r2, so there must be a
14544 branch and link followed by a nop. The nop is
14545 replaced by an insn to restore r2. */
14546 else if (rel
->r_offset
+ 8 <= input_section
->size
)
14550 br
= bfd_get_32 (input_bfd
,
14551 contents
+ rel
->r_offset
);
14556 nop
= bfd_get_32 (input_bfd
,
14557 contents
+ rel
->r_offset
+ 4);
14558 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
14559 can_plt_call
= TRUE
;
14560 else if (nop
== NOP
14561 || nop
== CROR_151515
14562 || nop
== CROR_313131
)
14565 && (h
== htab
->tls_get_addr_fd
14566 || h
== htab
->tls_get_addr
)
14567 && htab
->params
->tls_get_addr_opt
)
14569 /* Special stub used, leave nop alone. */
14572 bfd_put_32 (input_bfd
,
14573 LD_R2_0R1
+ STK_TOC (htab
),
14574 contents
+ rel
->r_offset
+ 4);
14575 can_plt_call
= TRUE
;
14580 if (!can_plt_call
&& h
!= NULL
)
14582 const char *name
= h
->elf
.root
.root
.string
;
14587 if (strncmp (name
, "__libc_start_main", 17) == 0
14588 && (name
[17] == 0 || name
[17] == '@'))
14590 /* Allow crt1 branch to go via a toc adjusting
14591 stub. Other calls that never return could do
14592 the same, if we could detect such. */
14593 can_plt_call
= TRUE
;
14599 /* g++ as of 20130507 emits self-calls without a
14600 following nop. This is arguably wrong since we
14601 have conflicting information. On the one hand a
14602 global symbol and on the other a local call
14603 sequence, but don't error for this special case.
14604 It isn't possible to cheaply verify we have
14605 exactly such a call. Allow all calls to the same
14607 asection
*code_sec
= sec
;
14609 if (get_opd_info (sec
) != NULL
)
14611 bfd_vma off
= (relocation
+ addend
14612 - sec
->output_section
->vma
14613 - sec
->output_offset
);
14615 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14617 if (code_sec
== input_section
)
14618 can_plt_call
= TRUE
;
14623 if (stub_entry
->stub_type
== ppc_stub_plt_call
14624 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14625 info
->callbacks
->einfo
14626 /* xgettext:c-format */
14627 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14628 "recompile with -fPIC\n"),
14629 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14631 info
->callbacks
->einfo
14632 /* xgettext:c-format */
14633 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14634 "(-mcmodel=small toc adjust stub)\n"),
14635 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14637 bfd_set_error (bfd_error_bad_value
);
14642 && (stub_entry
->stub_type
== ppc_stub_plt_call
14643 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
14644 unresolved_reloc
= FALSE
;
14647 if ((stub_entry
== NULL
14648 || stub_entry
->stub_type
== ppc_stub_long_branch
14649 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14650 && get_opd_info (sec
) != NULL
)
14652 /* The branch destination is the value of the opd entry. */
14653 bfd_vma off
= (relocation
+ addend
14654 - sec
->output_section
->vma
14655 - sec
->output_offset
);
14656 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14657 if (dest
!= (bfd_vma
) -1)
14661 reloc_dest
= DEST_OPD
;
14665 /* If the branch is out of reach we ought to have a long
14667 from
= (rel
->r_offset
14668 + input_section
->output_offset
14669 + input_section
->output_section
->vma
);
14671 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14675 if (stub_entry
!= NULL
14676 && (stub_entry
->stub_type
== ppc_stub_long_branch
14677 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14678 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14679 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14680 || (relocation
+ addend
- from
+ max_br_offset
14681 < 2 * max_br_offset
)))
14682 /* Don't use the stub if this branch is in range. */
14685 if (stub_entry
!= NULL
)
14687 /* Munge up the value and addend so that we call the stub
14688 rather than the procedure directly. */
14689 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14691 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14692 relocation
+= (stub_sec
->output_offset
14693 + stub_sec
->output_section
->vma
14694 + stub_sec
->size
- htab
->sfpr
->size
14695 - htab
->sfpr
->output_offset
14696 - htab
->sfpr
->output_section
->vma
);
14698 relocation
= (stub_entry
->stub_offset
14699 + stub_sec
->output_offset
14700 + stub_sec
->output_section
->vma
);
14702 reloc_dest
= DEST_STUB
;
14704 if ((stub_entry
->stub_type
== ppc_stub_plt_call
14705 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14706 && (ALWAYS_EMIT_R2SAVE
14707 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14708 && rel
+ 1 < relend
14709 && rel
[1].r_offset
== rel
->r_offset
+ 4
14710 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14718 /* Set 'a' bit. This is 0b00010 in BO field for branch
14719 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14720 for branch on CTR insns (BO == 1a00t or 1a01t). */
14721 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14722 insn
|= 0x02 << 21;
14723 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14724 insn
|= 0x08 << 21;
14730 /* Invert 'y' bit if not the default. */
14731 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14732 insn
^= 0x01 << 21;
14735 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14738 /* NOP out calls to undefined weak functions.
14739 We can thus call a weak function without first
14740 checking whether the function is defined. */
14742 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14743 && h
->elf
.dynindx
== -1
14744 && r_type
== R_PPC64_REL24
14748 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14754 /* Set `addend'. */
14756 save_unresolved_reloc
= unresolved_reloc
;
14760 /* xgettext:c-format */
14761 _bfd_error_handler (_("%pB: %s unsupported"),
14762 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
14764 bfd_set_error (bfd_error_bad_value
);
14770 case R_PPC64_TLSGD
:
14771 case R_PPC64_TLSLD
:
14772 case R_PPC64_TOCSAVE
:
14773 case R_PPC64_GNU_VTINHERIT
:
14774 case R_PPC64_GNU_VTENTRY
:
14775 case R_PPC64_ENTRY
:
14778 /* GOT16 relocations. Like an ADDR16 using the symbol's
14779 address in the GOT as relocation value instead of the
14780 symbol's value itself. Also, create a GOT entry for the
14781 symbol and put the symbol value there. */
14782 case R_PPC64_GOT_TLSGD16
:
14783 case R_PPC64_GOT_TLSGD16_LO
:
14784 case R_PPC64_GOT_TLSGD16_HI
:
14785 case R_PPC64_GOT_TLSGD16_HA
:
14786 tls_type
= TLS_TLS
| TLS_GD
;
14789 case R_PPC64_GOT_TLSLD16
:
14790 case R_PPC64_GOT_TLSLD16_LO
:
14791 case R_PPC64_GOT_TLSLD16_HI
:
14792 case R_PPC64_GOT_TLSLD16_HA
:
14793 tls_type
= TLS_TLS
| TLS_LD
;
14796 case R_PPC64_GOT_TPREL16_DS
:
14797 case R_PPC64_GOT_TPREL16_LO_DS
:
14798 case R_PPC64_GOT_TPREL16_HI
:
14799 case R_PPC64_GOT_TPREL16_HA
:
14800 tls_type
= TLS_TLS
| TLS_TPREL
;
14803 case R_PPC64_GOT_DTPREL16_DS
:
14804 case R_PPC64_GOT_DTPREL16_LO_DS
:
14805 case R_PPC64_GOT_DTPREL16_HI
:
14806 case R_PPC64_GOT_DTPREL16_HA
:
14807 tls_type
= TLS_TLS
| TLS_DTPREL
;
14810 case R_PPC64_GOT16
:
14811 case R_PPC64_GOT16_LO
:
14812 case R_PPC64_GOT16_HI
:
14813 case R_PPC64_GOT16_HA
:
14814 case R_PPC64_GOT16_DS
:
14815 case R_PPC64_GOT16_LO_DS
:
14818 /* Relocation is to the entry for this symbol in the global
14823 unsigned long indx
= 0;
14824 struct got_entry
*ent
;
14826 if (tls_type
== (TLS_TLS
| TLS_LD
)
14828 || !h
->elf
.def_dynamic
))
14829 ent
= ppc64_tlsld_got (input_bfd
);
14834 if (!htab
->elf
.dynamic_sections_created
14835 || h
->elf
.dynindx
== -1
14836 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14837 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
14838 /* This is actually a static link, or it is a
14839 -Bsymbolic link and the symbol is defined
14840 locally, or the symbol was forced to be local
14841 because of a version file. */
14845 indx
= h
->elf
.dynindx
;
14846 unresolved_reloc
= FALSE
;
14848 ent
= h
->elf
.got
.glist
;
14852 if (local_got_ents
== NULL
)
14854 ent
= local_got_ents
[r_symndx
];
14857 for (; ent
!= NULL
; ent
= ent
->next
)
14858 if (ent
->addend
== orig_rel
.r_addend
14859 && ent
->owner
== input_bfd
14860 && ent
->tls_type
== tls_type
)
14866 if (ent
->is_indirect
)
14867 ent
= ent
->got
.ent
;
14868 offp
= &ent
->got
.offset
;
14869 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14873 /* The offset must always be a multiple of 8. We use the
14874 least significant bit to record whether we have already
14875 processed this entry. */
14877 if ((off
& 1) != 0)
14881 /* Generate relocs for the dynamic linker, except in
14882 the case of TLSLD where we'll use one entry per
14890 ? h
->elf
.type
== STT_GNU_IFUNC
14891 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14894 relgot
= htab
->elf
.irelplt
;
14896 htab
->local_ifunc_resolver
= 1;
14897 else if (is_static_defined (&h
->elf
))
14898 htab
->maybe_local_ifunc_resolver
= 1;
14901 || (bfd_link_pic (info
)
14903 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
)
14904 || (tls_type
== (TLS_TLS
| TLS_LD
)
14905 && !h
->elf
.def_dynamic
))
14906 && !(tls_type
== (TLS_TLS
| TLS_TPREL
)
14907 && bfd_link_executable (info
)
14908 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
14909 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14910 if (relgot
!= NULL
)
14912 outrel
.r_offset
= (got
->output_section
->vma
14913 + got
->output_offset
14915 outrel
.r_addend
= addend
;
14916 if (tls_type
& (TLS_LD
| TLS_GD
))
14918 outrel
.r_addend
= 0;
14919 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14920 if (tls_type
== (TLS_TLS
| TLS_GD
))
14922 loc
= relgot
->contents
;
14923 loc
+= (relgot
->reloc_count
++
14924 * sizeof (Elf64_External_Rela
));
14925 bfd_elf64_swap_reloca_out (output_bfd
,
14927 outrel
.r_offset
+= 8;
14928 outrel
.r_addend
= addend
;
14930 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14933 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14934 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14935 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14936 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14937 else if (indx
!= 0)
14938 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14942 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14944 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14946 /* Write the .got section contents for the sake
14948 loc
= got
->contents
+ off
;
14949 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14953 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14955 outrel
.r_addend
+= relocation
;
14956 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14958 if (htab
->elf
.tls_sec
== NULL
)
14959 outrel
.r_addend
= 0;
14961 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14964 loc
= relgot
->contents
;
14965 loc
+= (relgot
->reloc_count
++
14966 * sizeof (Elf64_External_Rela
));
14967 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14970 /* Init the .got section contents here if we're not
14971 emitting a reloc. */
14974 relocation
+= addend
;
14977 if (htab
->elf
.tls_sec
== NULL
)
14981 if (tls_type
& TLS_LD
)
14984 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14985 if (tls_type
& TLS_TPREL
)
14986 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14989 if (tls_type
& (TLS_GD
| TLS_LD
))
14991 bfd_put_64 (output_bfd
, relocation
,
14992 got
->contents
+ off
+ 8);
14996 bfd_put_64 (output_bfd
, relocation
,
14997 got
->contents
+ off
);
15001 if (off
>= (bfd_vma
) -2)
15004 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
15005 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
15009 case R_PPC64_PLT16_HA
:
15010 case R_PPC64_PLT16_HI
:
15011 case R_PPC64_PLT16_LO
:
15012 case R_PPC64_PLT16_LO_DS
:
15013 case R_PPC64_PLT32
:
15014 case R_PPC64_PLT64
:
15015 case R_PPC64_PLTSEQ
:
15016 case R_PPC64_PLTCALL
:
15017 /* Relocation is to the entry for this symbol in the
15018 procedure linkage table. */
15019 unresolved_reloc
= TRUE
;
15021 struct plt_entry
**plt_list
= NULL
;
15023 plt_list
= &h
->elf
.plt
.plist
;
15024 else if (local_got_ents
!= NULL
)
15026 struct plt_entry
**local_plt
= (struct plt_entry
**)
15027 (local_got_ents
+ symtab_hdr
->sh_info
);
15028 plt_list
= local_plt
+ r_symndx
;
15032 struct plt_entry
*ent
;
15034 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
15035 if (ent
->plt
.offset
!= (bfd_vma
) -1
15036 && ent
->addend
== orig_rel
.r_addend
)
15041 plt
= htab
->elf
.splt
;
15042 if (!htab
->elf
.dynamic_sections_created
15044 || h
->elf
.dynindx
== -1)
15047 ? h
->elf
.type
== STT_GNU_IFUNC
15048 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15049 plt
= htab
->elf
.iplt
;
15051 plt
= htab
->pltlocal
;
15053 relocation
= (plt
->output_section
->vma
15054 + plt
->output_offset
15055 + ent
->plt
.offset
);
15056 if (r_type
== R_PPC64_PLT16_HA
15057 || r_type
==R_PPC64_PLT16_HI
15058 || r_type
==R_PPC64_PLT16_LO
15059 || r_type
==R_PPC64_PLT16_LO_DS
)
15061 got
= (elf_gp (output_bfd
)
15062 + htab
->sec_info
[input_section
->id
].toc_off
);
15066 unresolved_reloc
= FALSE
;
15074 /* Relocation value is TOC base. */
15075 relocation
= TOCstart
;
15076 if (r_symndx
== STN_UNDEF
)
15077 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
15078 else if (unresolved_reloc
)
15080 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
15081 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
15083 unresolved_reloc
= TRUE
;
15086 /* TOC16 relocs. We want the offset relative to the TOC base,
15087 which is the address of the start of the TOC plus 0x8000.
15088 The TOC consists of sections .got, .toc, .tocbss, and .plt,
15090 case R_PPC64_TOC16
:
15091 case R_PPC64_TOC16_LO
:
15092 case R_PPC64_TOC16_HI
:
15093 case R_PPC64_TOC16_DS
:
15094 case R_PPC64_TOC16_LO_DS
:
15095 case R_PPC64_TOC16_HA
:
15096 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15099 /* Relocate against the beginning of the section. */
15100 case R_PPC64_SECTOFF
:
15101 case R_PPC64_SECTOFF_LO
:
15102 case R_PPC64_SECTOFF_HI
:
15103 case R_PPC64_SECTOFF_DS
:
15104 case R_PPC64_SECTOFF_LO_DS
:
15105 case R_PPC64_SECTOFF_HA
:
15107 addend
-= sec
->output_section
->vma
;
15110 case R_PPC64_REL16
:
15111 case R_PPC64_REL16_LO
:
15112 case R_PPC64_REL16_HI
:
15113 case R_PPC64_REL16_HA
:
15114 case R_PPC64_REL16DX_HA
:
15117 case R_PPC64_REL14
:
15118 case R_PPC64_REL14_BRNTAKEN
:
15119 case R_PPC64_REL14_BRTAKEN
:
15120 case R_PPC64_REL24
:
15123 case R_PPC64_TPREL16
:
15124 case R_PPC64_TPREL16_LO
:
15125 case R_PPC64_TPREL16_HI
:
15126 case R_PPC64_TPREL16_HA
:
15127 case R_PPC64_TPREL16_DS
:
15128 case R_PPC64_TPREL16_LO_DS
:
15129 case R_PPC64_TPREL16_HIGH
:
15130 case R_PPC64_TPREL16_HIGHA
:
15131 case R_PPC64_TPREL16_HIGHER
:
15132 case R_PPC64_TPREL16_HIGHERA
:
15133 case R_PPC64_TPREL16_HIGHEST
:
15134 case R_PPC64_TPREL16_HIGHESTA
:
15136 && h
->elf
.root
.type
== bfd_link_hash_undefweak
15137 && h
->elf
.dynindx
== -1)
15139 /* Make this relocation against an undefined weak symbol
15140 resolve to zero. This is really just a tweak, since
15141 code using weak externs ought to check that they are
15142 defined before using them. */
15143 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
15145 insn
= bfd_get_32 (input_bfd
, p
);
15146 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
15148 bfd_put_32 (input_bfd
, insn
, p
);
15151 if (htab
->elf
.tls_sec
!= NULL
)
15152 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15153 /* The TPREL16 relocs shouldn't really be used in shared
15154 libs or with non-local symbols as that will result in
15155 DT_TEXTREL being set, but support them anyway. */
15158 case R_PPC64_DTPREL16
:
15159 case R_PPC64_DTPREL16_LO
:
15160 case R_PPC64_DTPREL16_HI
:
15161 case R_PPC64_DTPREL16_HA
:
15162 case R_PPC64_DTPREL16_DS
:
15163 case R_PPC64_DTPREL16_LO_DS
:
15164 case R_PPC64_DTPREL16_HIGH
:
15165 case R_PPC64_DTPREL16_HIGHA
:
15166 case R_PPC64_DTPREL16_HIGHER
:
15167 case R_PPC64_DTPREL16_HIGHERA
:
15168 case R_PPC64_DTPREL16_HIGHEST
:
15169 case R_PPC64_DTPREL16_HIGHESTA
:
15170 if (htab
->elf
.tls_sec
!= NULL
)
15171 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15174 case R_PPC64_ADDR64_LOCAL
:
15175 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
15180 case R_PPC64_DTPMOD64
:
15185 case R_PPC64_TPREL64
:
15186 if (htab
->elf
.tls_sec
!= NULL
)
15187 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15190 case R_PPC64_DTPREL64
:
15191 if (htab
->elf
.tls_sec
!= NULL
)
15192 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15193 /* Fall through. */
15195 /* Relocations that may need to be propagated if this is a
15197 case R_PPC64_REL30
:
15198 case R_PPC64_REL32
:
15199 case R_PPC64_REL64
:
15200 case R_PPC64_ADDR14
:
15201 case R_PPC64_ADDR14_BRNTAKEN
:
15202 case R_PPC64_ADDR14_BRTAKEN
:
15203 case R_PPC64_ADDR16
:
15204 case R_PPC64_ADDR16_DS
:
15205 case R_PPC64_ADDR16_HA
:
15206 case R_PPC64_ADDR16_HI
:
15207 case R_PPC64_ADDR16_HIGH
:
15208 case R_PPC64_ADDR16_HIGHA
:
15209 case R_PPC64_ADDR16_HIGHER
:
15210 case R_PPC64_ADDR16_HIGHERA
:
15211 case R_PPC64_ADDR16_HIGHEST
:
15212 case R_PPC64_ADDR16_HIGHESTA
:
15213 case R_PPC64_ADDR16_LO
:
15214 case R_PPC64_ADDR16_LO_DS
:
15215 case R_PPC64_ADDR24
:
15216 case R_PPC64_ADDR32
:
15217 case R_PPC64_ADDR64
:
15218 case R_PPC64_UADDR16
:
15219 case R_PPC64_UADDR32
:
15220 case R_PPC64_UADDR64
:
15222 if ((input_section
->flags
& SEC_ALLOC
) == 0)
15225 if (NO_OPD_RELOCS
&& is_opd
)
15228 if (bfd_link_pic (info
)
15230 || h
->dyn_relocs
!= NULL
)
15231 && ((h
!= NULL
&& pc_dynrelocs (h
))
15232 || must_be_dyn_reloc (info
, r_type
)))
15234 ? h
->dyn_relocs
!= NULL
15235 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
15237 bfd_boolean skip
, relocate
;
15242 /* When generating a dynamic object, these relocations
15243 are copied into the output file to be resolved at run
15249 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
15250 input_section
, rel
->r_offset
);
15251 if (out_off
== (bfd_vma
) -1)
15253 else if (out_off
== (bfd_vma
) -2)
15254 skip
= TRUE
, relocate
= TRUE
;
15255 out_off
+= (input_section
->output_section
->vma
15256 + input_section
->output_offset
);
15257 outrel
.r_offset
= out_off
;
15258 outrel
.r_addend
= rel
->r_addend
;
15260 /* Optimize unaligned reloc use. */
15261 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
15262 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
15263 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
15264 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
15265 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
15266 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
15267 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
15268 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
15269 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
15272 memset (&outrel
, 0, sizeof outrel
);
15273 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
15275 && r_type
!= R_PPC64_TOC
)
15277 indx
= h
->elf
.dynindx
;
15278 BFD_ASSERT (indx
!= -1);
15279 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15283 /* This symbol is local, or marked to become local,
15284 or this is an opd section reloc which must point
15285 at a local function. */
15286 outrel
.r_addend
+= relocation
;
15287 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
15289 if (is_opd
&& h
!= NULL
)
15291 /* Lie about opd entries. This case occurs
15292 when building shared libraries and we
15293 reference a function in another shared
15294 lib. The same thing happens for a weak
15295 definition in an application that's
15296 overridden by a strong definition in a
15297 shared lib. (I believe this is a generic
15298 bug in binutils handling of weak syms.)
15299 In these cases we won't use the opd
15300 entry in this lib. */
15301 unresolved_reloc
= FALSE
;
15304 && r_type
== R_PPC64_ADDR64
15306 ? h
->elf
.type
== STT_GNU_IFUNC
15307 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
15308 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15311 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
15313 /* We need to relocate .opd contents for ld.so.
15314 Prelink also wants simple and consistent rules
15315 for relocs. This make all RELATIVE relocs have
15316 *r_offset equal to r_addend. */
15323 ? h
->elf
.type
== STT_GNU_IFUNC
15324 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15326 info
->callbacks
->einfo
15327 /* xgettext:c-format */
15328 (_("%H: %s for indirect "
15329 "function `%pT' unsupported\n"),
15330 input_bfd
, input_section
, rel
->r_offset
,
15331 ppc64_elf_howto_table
[r_type
]->name
,
15335 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
15337 else if (sec
== NULL
|| sec
->owner
== NULL
)
15339 bfd_set_error (bfd_error_bad_value
);
15346 osec
= sec
->output_section
;
15347 indx
= elf_section_data (osec
)->dynindx
;
15351 if ((osec
->flags
& SEC_READONLY
) == 0
15352 && htab
->elf
.data_index_section
!= NULL
)
15353 osec
= htab
->elf
.data_index_section
;
15355 osec
= htab
->elf
.text_index_section
;
15356 indx
= elf_section_data (osec
)->dynindx
;
15358 BFD_ASSERT (indx
!= 0);
15360 /* We are turning this relocation into one
15361 against a section symbol, so subtract out
15362 the output section's address but not the
15363 offset of the input section in the output
15365 outrel
.r_addend
-= osec
->vma
;
15368 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15372 sreloc
= elf_section_data (input_section
)->sreloc
;
15374 ? h
->elf
.type
== STT_GNU_IFUNC
15375 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15377 sreloc
= htab
->elf
.irelplt
;
15379 htab
->local_ifunc_resolver
= 1;
15380 else if (is_static_defined (&h
->elf
))
15381 htab
->maybe_local_ifunc_resolver
= 1;
15383 if (sreloc
== NULL
)
15386 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
15389 loc
= sreloc
->contents
;
15390 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15391 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
15393 /* If this reloc is against an external symbol, it will
15394 be computed at runtime, so there's no need to do
15395 anything now. However, for the sake of prelink ensure
15396 that the section contents are a known value. */
15399 unresolved_reloc
= FALSE
;
15400 /* The value chosen here is quite arbitrary as ld.so
15401 ignores section contents except for the special
15402 case of .opd where the contents might be accessed
15403 before relocation. Choose zero, as that won't
15404 cause reloc overflow. */
15407 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
15408 to improve backward compatibility with older
15410 if (r_type
== R_PPC64_ADDR64
)
15411 addend
= outrel
.r_addend
;
15412 /* Adjust pc_relative relocs to have zero in *r_offset. */
15413 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
15414 addend
= outrel
.r_offset
;
15420 case R_PPC64_GLOB_DAT
:
15421 case R_PPC64_JMP_SLOT
:
15422 case R_PPC64_JMP_IREL
:
15423 case R_PPC64_RELATIVE
:
15424 /* We shouldn't ever see these dynamic relocs in relocatable
15426 /* Fall through. */
15428 case R_PPC64_PLTGOT16
:
15429 case R_PPC64_PLTGOT16_DS
:
15430 case R_PPC64_PLTGOT16_HA
:
15431 case R_PPC64_PLTGOT16_HI
:
15432 case R_PPC64_PLTGOT16_LO
:
15433 case R_PPC64_PLTGOT16_LO_DS
:
15434 case R_PPC64_PLTREL32
:
15435 case R_PPC64_PLTREL64
:
15436 /* These ones haven't been implemented yet. */
15438 info
->callbacks
->einfo
15439 /* xgettext:c-format */
15440 (_("%P: %pB: %s is not supported for `%pT'\n"),
15442 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
15444 bfd_set_error (bfd_error_invalid_operation
);
15449 /* Multi-instruction sequences that access the TOC can be
15450 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15451 to nop; addi rb,r2,x; */
15457 case R_PPC64_GOT_TLSLD16_HI
:
15458 case R_PPC64_GOT_TLSGD16_HI
:
15459 case R_PPC64_GOT_TPREL16_HI
:
15460 case R_PPC64_GOT_DTPREL16_HI
:
15461 case R_PPC64_GOT16_HI
:
15462 case R_PPC64_TOC16_HI
:
15463 /* These relocs would only be useful if building up an
15464 offset to later add to r2, perhaps in an indexed
15465 addressing mode instruction. Don't try to optimize.
15466 Unfortunately, the possibility of someone building up an
15467 offset like this or even with the HA relocs, means that
15468 we need to check the high insn when optimizing the low
15472 case R_PPC64_PLTCALL
:
15473 if (unresolved_reloc
)
15475 /* No plt entry. Make this into a direct call. */
15476 bfd_byte
*p
= contents
+ rel
->r_offset
;
15477 insn
= bfd_get_32 (input_bfd
, p
);
15479 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
15480 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
15481 unresolved_reloc
= save_unresolved_reloc
;
15482 r_type
= R_PPC64_REL24
;
15486 case R_PPC64_PLTSEQ
:
15487 if (unresolved_reloc
)
15489 unresolved_reloc
= FALSE
;
15494 case R_PPC64_PLT16_HA
:
15495 if (unresolved_reloc
)
15497 unresolved_reloc
= FALSE
;
15500 /* Fall through. */
15501 case R_PPC64_GOT_TLSLD16_HA
:
15502 case R_PPC64_GOT_TLSGD16_HA
:
15503 case R_PPC64_GOT_TPREL16_HA
:
15504 case R_PPC64_GOT_DTPREL16_HA
:
15505 case R_PPC64_GOT16_HA
:
15506 case R_PPC64_TOC16_HA
:
15507 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15508 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15512 p
= contents
+ (rel
->r_offset
& ~3);
15513 bfd_put_32 (input_bfd
, NOP
, p
);
15518 case R_PPC64_PLT16_LO
:
15519 case R_PPC64_PLT16_LO_DS
:
15520 if (unresolved_reloc
)
15522 unresolved_reloc
= FALSE
;
15525 /* Fall through. */
15526 case R_PPC64_GOT_TLSLD16_LO
:
15527 case R_PPC64_GOT_TLSGD16_LO
:
15528 case R_PPC64_GOT_TPREL16_LO_DS
:
15529 case R_PPC64_GOT_DTPREL16_LO_DS
:
15530 case R_PPC64_GOT16_LO
:
15531 case R_PPC64_GOT16_LO_DS
:
15532 case R_PPC64_TOC16_LO
:
15533 case R_PPC64_TOC16_LO_DS
:
15534 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15535 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15537 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15538 insn
= bfd_get_32 (input_bfd
, p
);
15539 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
15541 /* Transform addic to addi when we change reg. */
15542 insn
&= ~((0x3f << 26) | (0x1f << 16));
15543 insn
|= (14u << 26) | (2 << 16);
15547 insn
&= ~(0x1f << 16);
15550 bfd_put_32 (input_bfd
, insn
, p
);
15554 case R_PPC64_TPREL16_HA
:
15555 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15557 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15558 insn
= bfd_get_32 (input_bfd
, p
);
15559 if ((insn
& ((0x3f << 26) | 0x1f << 16))
15560 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15561 /* xgettext:c-format */
15562 info
->callbacks
->minfo
15563 (_("%H: warning: %s unexpected insn %#x.\n"),
15564 input_bfd
, input_section
, rel
->r_offset
,
15565 ppc64_elf_howto_table
[r_type
]->name
, insn
);
15568 bfd_put_32 (input_bfd
, NOP
, p
);
15574 case R_PPC64_TPREL16_LO
:
15575 case R_PPC64_TPREL16_LO_DS
:
15576 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15578 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15579 insn
= bfd_get_32 (input_bfd
, p
);
15580 insn
&= ~(0x1f << 16);
15582 bfd_put_32 (input_bfd
, insn
, p
);
15587 /* Do any further special processing. */
15593 case R_PPC64_REL16_HA
:
15594 case R_PPC64_REL16DX_HA
:
15595 case R_PPC64_ADDR16_HA
:
15596 case R_PPC64_ADDR16_HIGHA
:
15597 case R_PPC64_ADDR16_HIGHERA
:
15598 case R_PPC64_ADDR16_HIGHESTA
:
15599 case R_PPC64_TOC16_HA
:
15600 case R_PPC64_SECTOFF_HA
:
15601 case R_PPC64_TPREL16_HA
:
15602 case R_PPC64_TPREL16_HIGHA
:
15603 case R_PPC64_TPREL16_HIGHERA
:
15604 case R_PPC64_TPREL16_HIGHESTA
:
15605 case R_PPC64_DTPREL16_HA
:
15606 case R_PPC64_DTPREL16_HIGHA
:
15607 case R_PPC64_DTPREL16_HIGHERA
:
15608 case R_PPC64_DTPREL16_HIGHESTA
:
15609 /* It's just possible that this symbol is a weak symbol
15610 that's not actually defined anywhere. In that case,
15611 'sec' would be NULL, and we should leave the symbol
15612 alone (it will be set to zero elsewhere in the link). */
15615 /* Fall through. */
15617 case R_PPC64_GOT16_HA
:
15618 case R_PPC64_PLTGOT16_HA
:
15619 case R_PPC64_PLT16_HA
:
15620 case R_PPC64_GOT_TLSGD16_HA
:
15621 case R_PPC64_GOT_TLSLD16_HA
:
15622 case R_PPC64_GOT_TPREL16_HA
:
15623 case R_PPC64_GOT_DTPREL16_HA
:
15624 /* Add 0x10000 if sign bit in 0:15 is set.
15625 Bits 0:15 are not used. */
15629 case R_PPC64_ADDR16_DS
:
15630 case R_PPC64_ADDR16_LO_DS
:
15631 case R_PPC64_GOT16_DS
:
15632 case R_PPC64_GOT16_LO_DS
:
15633 case R_PPC64_PLT16_LO_DS
:
15634 case R_PPC64_SECTOFF_DS
:
15635 case R_PPC64_SECTOFF_LO_DS
:
15636 case R_PPC64_TOC16_DS
:
15637 case R_PPC64_TOC16_LO_DS
:
15638 case R_PPC64_PLTGOT16_DS
:
15639 case R_PPC64_PLTGOT16_LO_DS
:
15640 case R_PPC64_GOT_TPREL16_DS
:
15641 case R_PPC64_GOT_TPREL16_LO_DS
:
15642 case R_PPC64_GOT_DTPREL16_DS
:
15643 case R_PPC64_GOT_DTPREL16_LO_DS
:
15644 case R_PPC64_TPREL16_DS
:
15645 case R_PPC64_TPREL16_LO_DS
:
15646 case R_PPC64_DTPREL16_DS
:
15647 case R_PPC64_DTPREL16_LO_DS
:
15648 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15650 /* If this reloc is against an lq, lxv, or stxv insn, then
15651 the value must be a multiple of 16. This is somewhat of
15652 a hack, but the "correct" way to do this by defining _DQ
15653 forms of all the _DS relocs bloats all reloc switches in
15654 this file. It doesn't make much sense to use these
15655 relocs in data, so testing the insn should be safe. */
15656 if ((insn
& (0x3f << 26)) == (56u << 26)
15657 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15659 relocation
+= addend
;
15660 addend
= insn
& (mask
^ 3);
15661 if ((relocation
& mask
) != 0)
15663 relocation
^= relocation
& mask
;
15664 info
->callbacks
->einfo
15665 /* xgettext:c-format */
15666 (_("%H: error: %s not a multiple of %u\n"),
15667 input_bfd
, input_section
, rel
->r_offset
,
15668 ppc64_elf_howto_table
[r_type
]->name
,
15670 bfd_set_error (bfd_error_bad_value
);
15677 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15678 because such sections are not SEC_ALLOC and thus ld.so will
15679 not process them. */
15680 howto
= ppc64_elf_howto_table
[(int) r_type
];
15681 if (unresolved_reloc
15682 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15683 && h
->elf
.def_dynamic
)
15684 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15685 rel
->r_offset
) != (bfd_vma
) -1)
15687 info
->callbacks
->einfo
15688 /* xgettext:c-format */
15689 (_("%H: unresolvable %s against `%pT'\n"),
15690 input_bfd
, input_section
, rel
->r_offset
,
15692 h
->elf
.root
.root
.string
);
15696 /* 16-bit fields in insns mostly have signed values, but a
15697 few insns have 16-bit unsigned values. Really, we should
15698 have different reloc types. */
15699 if (howto
->complain_on_overflow
!= complain_overflow_dont
15700 && howto
->dst_mask
== 0xffff
15701 && (input_section
->flags
& SEC_CODE
) != 0)
15703 enum complain_overflow complain
= complain_overflow_signed
;
15705 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15706 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15707 complain
= complain_overflow_bitfield
;
15708 else if (howto
->rightshift
== 0
15709 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15710 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15711 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15712 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15713 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15714 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15715 complain
= complain_overflow_unsigned
;
15716 if (howto
->complain_on_overflow
!= complain
)
15718 alt_howto
= *howto
;
15719 alt_howto
.complain_on_overflow
= complain
;
15720 howto
= &alt_howto
;
15724 if (r_type
== R_PPC64_REL16DX_HA
)
15726 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15727 if (rel
->r_offset
+ 4 > input_section
->size
)
15728 r
= bfd_reloc_outofrange
;
15731 relocation
+= addend
;
15732 relocation
-= (rel
->r_offset
15733 + input_section
->output_offset
15734 + input_section
->output_section
->vma
);
15735 relocation
= (bfd_signed_vma
) relocation
>> 16;
15736 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15738 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15739 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15741 if (relocation
+ 0x8000 > 0xffff)
15742 r
= bfd_reloc_overflow
;
15746 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15747 rel
->r_offset
, relocation
, addend
);
15749 if (r
!= bfd_reloc_ok
)
15751 char *more_info
= NULL
;
15752 const char *reloc_name
= howto
->name
;
15754 if (reloc_dest
!= DEST_NORMAL
)
15756 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15757 if (more_info
!= NULL
)
15759 strcpy (more_info
, reloc_name
);
15760 strcat (more_info
, (reloc_dest
== DEST_OPD
15761 ? " (OPD)" : " (stub)"));
15762 reloc_name
= more_info
;
15766 if (r
== bfd_reloc_overflow
)
15768 /* On code like "if (foo) foo();" don't report overflow
15769 on a branch to zero when foo is undefined. */
15771 && (reloc_dest
== DEST_STUB
15773 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15774 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15775 && is_branch_reloc (r_type
))))
15776 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15777 sym_name
, reloc_name
,
15779 input_bfd
, input_section
,
15784 info
->callbacks
->einfo
15785 /* xgettext:c-format */
15786 (_("%H: %s against `%pT': error %d\n"),
15787 input_bfd
, input_section
, rel
->r_offset
,
15788 reloc_name
, sym_name
, (int) r
);
15791 if (more_info
!= NULL
)
15801 Elf_Internal_Shdr
*rel_hdr
;
15802 size_t deleted
= rel
- wrel
;
15804 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15805 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15806 if (rel_hdr
->sh_size
== 0)
15808 /* It is too late to remove an empty reloc section. Leave
15810 ??? What is wrong with an empty section??? */
15811 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15814 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15815 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15816 input_section
->reloc_count
-= deleted
;
15819 /* If we're emitting relocations, then shortly after this function
15820 returns, reloc offsets and addends for this section will be
15821 adjusted. Worse, reloc symbol indices will be for the output
15822 file rather than the input. Save a copy of the relocs for
15823 opd_entry_value. */
15824 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15827 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15828 rel
= bfd_alloc (input_bfd
, amt
);
15829 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15830 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15833 memcpy (rel
, relocs
, amt
);
15838 /* Adjust the value of any local symbols in opd sections. */
15841 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15842 const char *name ATTRIBUTE_UNUSED
,
15843 Elf_Internal_Sym
*elfsym
,
15844 asection
*input_sec
,
15845 struct elf_link_hash_entry
*h
)
15847 struct _opd_sec_data
*opd
;
15854 opd
= get_opd_info (input_sec
);
15855 if (opd
== NULL
|| opd
->adjust
== NULL
)
15858 value
= elfsym
->st_value
- input_sec
->output_offset
;
15859 if (!bfd_link_relocatable (info
))
15860 value
-= input_sec
->output_section
->vma
;
15862 adjust
= opd
->adjust
[OPD_NDX (value
)];
15866 elfsym
->st_value
+= adjust
;
15870 /* Finish up dynamic symbol handling. We set the contents of various
15871 dynamic sections here. */
15874 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15875 struct bfd_link_info
*info
,
15876 struct elf_link_hash_entry
*h
,
15877 Elf_Internal_Sym
*sym
)
15879 struct ppc_link_hash_table
*htab
;
15880 struct plt_entry
*ent
;
15882 htab
= ppc_hash_table (info
);
15886 if (!htab
->opd_abi
&& !h
->def_regular
)
15887 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15888 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15890 /* Mark the symbol as undefined, rather than as
15891 defined in glink. Leave the value if there were
15892 any relocations where pointer equality matters
15893 (this is a clue for the dynamic linker, to make
15894 function pointer comparisons work between an
15895 application and shared library), otherwise set it
15897 sym
->st_shndx
= SHN_UNDEF
;
15898 if (!h
->pointer_equality_needed
)
15900 else if (!h
->ref_regular_nonweak
)
15902 /* This breaks function pointer comparisons, but
15903 that is better than breaking tests for a NULL
15904 function pointer. */
15912 /* This symbol needs a copy reloc. Set it up. */
15913 Elf_Internal_Rela rela
;
15917 if (h
->dynindx
== -1
15918 || (h
->root
.type
!= bfd_link_hash_defined
15919 && h
->root
.type
!= bfd_link_hash_defweak
)
15920 || htab
->elf
.srelbss
== NULL
15921 || htab
->elf
.sreldynrelro
== NULL
)
15924 rela
.r_offset
= (h
->root
.u
.def
.value
15925 + h
->root
.u
.def
.section
->output_section
->vma
15926 + h
->root
.u
.def
.section
->output_offset
);
15927 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15929 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
15930 srel
= htab
->elf
.sreldynrelro
;
15932 srel
= htab
->elf
.srelbss
;
15933 loc
= srel
->contents
;
15934 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15935 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15941 /* Used to decide how to sort relocs in an optimal manner for the
15942 dynamic linker, before writing them out. */
15944 static enum elf_reloc_type_class
15945 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15946 const asection
*rel_sec
,
15947 const Elf_Internal_Rela
*rela
)
15949 enum elf_ppc64_reloc_type r_type
;
15950 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15952 if (rel_sec
== htab
->elf
.irelplt
)
15953 return reloc_class_ifunc
;
15955 r_type
= ELF64_R_TYPE (rela
->r_info
);
15958 case R_PPC64_RELATIVE
:
15959 return reloc_class_relative
;
15960 case R_PPC64_JMP_SLOT
:
15961 return reloc_class_plt
;
15963 return reloc_class_copy
;
15965 return reloc_class_normal
;
15969 /* Finish up the dynamic sections. */
15972 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15973 struct bfd_link_info
*info
)
15975 struct ppc_link_hash_table
*htab
;
15979 htab
= ppc_hash_table (info
);
15983 dynobj
= htab
->elf
.dynobj
;
15984 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15986 if (htab
->elf
.dynamic_sections_created
)
15988 Elf64_External_Dyn
*dyncon
, *dynconend
;
15990 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15993 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15994 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15995 for (; dyncon
< dynconend
; dyncon
++)
15997 Elf_Internal_Dyn dyn
;
16000 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
16007 case DT_PPC64_GLINK
:
16009 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16010 /* We stupidly defined DT_PPC64_GLINK to be the start
16011 of glink rather than the first entry point, which is
16012 what ld.so needs, and now have a bigger stub to
16013 support automatic multiple TOCs. */
16014 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
16018 s
= bfd_get_section_by_name (output_bfd
, ".opd");
16021 dyn
.d_un
.d_ptr
= s
->vma
;
16025 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
16026 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
16027 if (htab
->has_plt_localentry0
)
16028 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
16031 case DT_PPC64_OPDSZ
:
16032 s
= bfd_get_section_by_name (output_bfd
, ".opd");
16035 dyn
.d_un
.d_val
= s
->size
;
16039 s
= htab
->elf
.splt
;
16040 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16044 s
= htab
->elf
.srelplt
;
16045 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16049 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
16053 if (htab
->local_ifunc_resolver
)
16054 info
->callbacks
->einfo
16055 (_("%X%P: text relocations and GNU indirect "
16056 "functions will result in a segfault at runtime\n"));
16057 else if (htab
->maybe_local_ifunc_resolver
)
16058 info
->callbacks
->einfo
16059 (_("%P: warning: text relocations and GNU indirect "
16060 "functions may result in a segfault at runtime\n"));
16064 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
16068 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
16069 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
16071 /* Fill in the first entry in the global offset table.
16072 We use it to hold the link-time TOCbase. */
16073 bfd_put_64 (output_bfd
,
16074 elf_gp (output_bfd
) + TOC_BASE_OFF
,
16075 htab
->elf
.sgot
->contents
);
16077 /* Set .got entry size. */
16078 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
16081 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
16082 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
16084 /* Set .plt entry size. */
16085 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
16086 = PLT_ENTRY_SIZE (htab
);
16089 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
16090 brlt ourselves if emitrelocations. */
16091 if (htab
->brlt
!= NULL
16092 && htab
->brlt
->reloc_count
!= 0
16093 && !_bfd_elf_link_output_relocs (output_bfd
,
16095 elf_section_data (htab
->brlt
)->rela
.hdr
,
16096 elf_section_data (htab
->brlt
)->relocs
,
16100 if (htab
->glink
!= NULL
16101 && htab
->glink
->reloc_count
!= 0
16102 && !_bfd_elf_link_output_relocs (output_bfd
,
16104 elf_section_data (htab
->glink
)->rela
.hdr
,
16105 elf_section_data (htab
->glink
)->relocs
,
16109 if (htab
->glink_eh_frame
!= NULL
16110 && htab
->glink_eh_frame
->size
!= 0)
16114 struct map_stub
*group
;
16117 p
= htab
->glink_eh_frame
->contents
;
16118 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
16120 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
16121 if (group
->stub_sec
!= NULL
)
16123 /* Offset to stub section. */
16124 val
= (group
->stub_sec
->output_section
->vma
16125 + group
->stub_sec
->output_offset
);
16126 val
-= (htab
->glink_eh_frame
->output_section
->vma
16127 + htab
->glink_eh_frame
->output_offset
16128 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
16129 if (val
+ 0x80000000 > 0xffffffff)
16132 (_("%s offset too large for .eh_frame sdata4 encoding"),
16133 group
->stub_sec
->name
);
16136 bfd_put_32 (dynobj
, val
, p
+ 8);
16137 p
+= stub_eh_frame_size (group
, align
);
16139 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
16141 /* Offset to .glink. */
16142 val
= (htab
->glink
->output_section
->vma
16143 + htab
->glink
->output_offset
16145 val
-= (htab
->glink_eh_frame
->output_section
->vma
16146 + htab
->glink_eh_frame
->output_offset
16147 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
16148 if (val
+ 0x80000000 > 0xffffffff)
16151 (_("%s offset too large for .eh_frame sdata4 encoding"),
16152 htab
->glink
->name
);
16155 bfd_put_32 (dynobj
, val
, p
+ 8);
16156 p
+= (24 + align
- 1) & -align
;
16159 if (htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
16160 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
16161 htab
->glink_eh_frame
,
16162 htab
->glink_eh_frame
->contents
))
16166 /* We need to handle writing out multiple GOT sections ourselves,
16167 since we didn't add them to DYNOBJ. We know dynobj is the first
16169 while ((dynobj
= dynobj
->link
.next
) != NULL
)
16173 if (!is_ppc64_elf (dynobj
))
16176 s
= ppc64_elf_tdata (dynobj
)->got
;
16179 && s
->output_section
!= bfd_abs_section_ptr
16180 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
16181 s
->contents
, s
->output_offset
,
16184 s
= ppc64_elf_tdata (dynobj
)->relgot
;
16187 && s
->output_section
!= bfd_abs_section_ptr
16188 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
16189 s
->contents
, s
->output_offset
,
16197 #include "elf64-target.h"
16199 /* FreeBSD support */
16201 #undef TARGET_LITTLE_SYM
16202 #undef TARGET_LITTLE_NAME
16204 #undef TARGET_BIG_SYM
16205 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
16206 #undef TARGET_BIG_NAME
16207 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
16210 #define ELF_OSABI ELFOSABI_FREEBSD
16213 #define elf64_bed elf64_powerpc_fbsd_bed
16215 #include "elf64-target.h"