1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2016 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_can_gc_sections 1
76 #define elf_backend_can_refcount 1
77 #define elf_backend_rela_normal 1
78 #define elf_backend_dtrel_excludes_plt 1
79 #define elf_backend_default_execstack 0
81 #define bfd_elf64_mkobject ppc64_elf_mkobject
82 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
83 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
84 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
85 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
86 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
87 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
88 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
89 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
90 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
92 #define elf_backend_object_p ppc64_elf_object_p
93 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
94 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
95 #define elf_backend_write_core_note ppc64_elf_write_core_note
96 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
97 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
98 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
99 #define elf_backend_check_directives ppc64_elf_before_check_relocs
100 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
101 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
102 #define elf_backend_check_relocs ppc64_elf_check_relocs
103 #define elf_backend_gc_keep ppc64_elf_gc_keep
104 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
105 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
106 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
107 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
108 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
109 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
110 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
111 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
112 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
113 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
114 #define elf_backend_action_discarded ppc64_elf_action_discarded
115 #define elf_backend_relocate_section ppc64_elf_relocate_section
116 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
117 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
118 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
119 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
120 #define elf_backend_special_sections ppc64_elf_special_sections
121 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
122 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
124 /* The name of the dynamic interpreter. This is put in the .interp
126 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
128 /* The size in bytes of an entry in the procedure linkage table. */
129 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
131 /* The initial size of the plt reserved for the dynamic linker. */
132 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
134 /* Offsets to some stack save slots. */
136 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
137 /* This one is dodgy. ELFv2 does not have a linker word, so use the
138 CR save slot. Used only by optimised __tls_get_addr call stub,
139 relying on __tls_get_addr_opt not saving CR.. */
140 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
142 /* TOC base pointers offset from start of TOC. */
143 #define TOC_BASE_OFF 0x8000
144 /* TOC base alignment. */
145 #define TOC_BASE_ALIGN 256
147 /* Offset of tp and dtp pointers from start of TLS block. */
148 #define TP_OFFSET 0x7000
149 #define DTP_OFFSET 0x8000
151 /* .plt call stub instructions. The normal stub is like this, but
152 sometimes the .plt entry crosses a 64k boundary and we need to
153 insert an addi to adjust r11. */
154 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
155 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
156 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
157 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
158 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
159 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
160 #define BCTR 0x4e800420 /* bctr */
162 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
163 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
164 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
166 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
167 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
168 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
169 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
170 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
171 #define BNECTR 0x4ca20420 /* bnectr+ */
172 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
174 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
175 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
176 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
178 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
179 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
180 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
182 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
183 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
184 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
185 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
186 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
188 /* glink call stub instructions. We enter with the index in R0. */
189 #define GLINK_CALL_STUB_SIZE (16*4)
193 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
194 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
196 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
197 /* ld %2,(0b-1b)(%11) */
198 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
199 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
205 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
206 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
207 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
208 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
209 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
212 #define NOP 0x60000000
214 /* Some other nops. */
215 #define CROR_151515 0x4def7b82
216 #define CROR_313131 0x4ffffb82
218 /* .glink entries for the first 32k functions are two instructions. */
219 #define LI_R0_0 0x38000000 /* li %r0,0 */
220 #define B_DOT 0x48000000 /* b . */
222 /* After that, we need two instructions to load the index, followed by
224 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
225 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
227 /* Instructions used by the save and restore reg functions. */
228 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
229 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
230 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
231 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
232 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
233 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
234 #define LI_R12_0 0x39800000 /* li %r12,0 */
235 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
236 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
237 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
238 #define BLR 0x4e800020 /* blr */
240 /* Since .opd is an array of descriptors and each entry will end up
241 with identical R_PPC64_RELATIVE relocs, there is really no need to
242 propagate .opd relocs; The dynamic linker should be taught to
243 relocate .opd without reloc entries. */
244 #ifndef NO_OPD_RELOCS
245 #define NO_OPD_RELOCS 0
249 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
253 abiversion (bfd
*abfd
)
255 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
259 set_abiversion (bfd
*abfd
, int ver
)
261 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
262 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
265 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
267 /* Relocation HOWTO's. */
268 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
270 static reloc_howto_type ppc64_elf_howto_raw
[] = {
271 /* This reloc does nothing. */
272 HOWTO (R_PPC64_NONE
, /* type */
274 3, /* size (0 = byte, 1 = short, 2 = long) */
276 FALSE
, /* pc_relative */
278 complain_overflow_dont
, /* complain_on_overflow */
279 bfd_elf_generic_reloc
, /* special_function */
280 "R_PPC64_NONE", /* name */
281 FALSE
, /* partial_inplace */
284 FALSE
), /* pcrel_offset */
286 /* A standard 32 bit relocation. */
287 HOWTO (R_PPC64_ADDR32
, /* type */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
291 FALSE
, /* pc_relative */
293 complain_overflow_bitfield
, /* complain_on_overflow */
294 bfd_elf_generic_reloc
, /* special_function */
295 "R_PPC64_ADDR32", /* name */
296 FALSE
, /* partial_inplace */
298 0xffffffff, /* dst_mask */
299 FALSE
), /* pcrel_offset */
301 /* An absolute 26 bit branch; the lower two bits must be zero.
302 FIXME: we don't check that, we just clear them. */
303 HOWTO (R_PPC64_ADDR24
, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 FALSE
, /* pc_relative */
309 complain_overflow_bitfield
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_PPC64_ADDR24", /* name */
312 FALSE
, /* partial_inplace */
314 0x03fffffc, /* dst_mask */
315 FALSE
), /* pcrel_offset */
317 /* A standard 16 bit relocation. */
318 HOWTO (R_PPC64_ADDR16
, /* type */
320 1, /* size (0 = byte, 1 = short, 2 = long) */
322 FALSE
, /* pc_relative */
324 complain_overflow_bitfield
, /* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_PPC64_ADDR16", /* name */
327 FALSE
, /* partial_inplace */
329 0xffff, /* dst_mask */
330 FALSE
), /* pcrel_offset */
332 /* A 16 bit relocation without overflow. */
333 HOWTO (R_PPC64_ADDR16_LO
, /* type */
335 1, /* size (0 = byte, 1 = short, 2 = long) */
337 FALSE
, /* pc_relative */
339 complain_overflow_dont
,/* complain_on_overflow */
340 bfd_elf_generic_reloc
, /* special_function */
341 "R_PPC64_ADDR16_LO", /* name */
342 FALSE
, /* partial_inplace */
344 0xffff, /* dst_mask */
345 FALSE
), /* pcrel_offset */
347 /* Bits 16-31 of an address. */
348 HOWTO (R_PPC64_ADDR16_HI
, /* type */
350 1, /* size (0 = byte, 1 = short, 2 = long) */
352 FALSE
, /* pc_relative */
354 complain_overflow_signed
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_PPC64_ADDR16_HI", /* name */
357 FALSE
, /* partial_inplace */
359 0xffff, /* dst_mask */
360 FALSE
), /* pcrel_offset */
362 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
363 bits, treated as a signed number, is negative. */
364 HOWTO (R_PPC64_ADDR16_HA
, /* type */
366 1, /* size (0 = byte, 1 = short, 2 = long) */
368 FALSE
, /* pc_relative */
370 complain_overflow_signed
, /* complain_on_overflow */
371 ppc64_elf_ha_reloc
, /* special_function */
372 "R_PPC64_ADDR16_HA", /* name */
373 FALSE
, /* partial_inplace */
375 0xffff, /* dst_mask */
376 FALSE
), /* pcrel_offset */
378 /* An absolute 16 bit branch; the lower two bits must be zero.
379 FIXME: we don't check that, we just clear them. */
380 HOWTO (R_PPC64_ADDR14
, /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 FALSE
, /* pc_relative */
386 complain_overflow_signed
, /* complain_on_overflow */
387 ppc64_elf_branch_reloc
, /* special_function */
388 "R_PPC64_ADDR14", /* name */
389 FALSE
, /* partial_inplace */
391 0x0000fffc, /* dst_mask */
392 FALSE
), /* pcrel_offset */
394 /* An absolute 16 bit branch, for which bit 10 should be set to
395 indicate that the branch is expected to be taken. The lower two
396 bits must be zero. */
397 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
399 2, /* size (0 = byte, 1 = short, 2 = long) */
401 FALSE
, /* pc_relative */
403 complain_overflow_signed
, /* complain_on_overflow */
404 ppc64_elf_brtaken_reloc
, /* special_function */
405 "R_PPC64_ADDR14_BRTAKEN",/* name */
406 FALSE
, /* partial_inplace */
408 0x0000fffc, /* dst_mask */
409 FALSE
), /* pcrel_offset */
411 /* An absolute 16 bit branch, for which bit 10 should be set to
412 indicate that the branch is not expected to be taken. The lower
413 two bits must be zero. */
414 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
418 FALSE
, /* pc_relative */
420 complain_overflow_signed
, /* complain_on_overflow */
421 ppc64_elf_brtaken_reloc
, /* special_function */
422 "R_PPC64_ADDR14_BRNTAKEN",/* name */
423 FALSE
, /* partial_inplace */
425 0x0000fffc, /* dst_mask */
426 FALSE
), /* pcrel_offset */
428 /* A relative 26 bit branch; the lower two bits must be zero. */
429 HOWTO (R_PPC64_REL24
, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 TRUE
, /* pc_relative */
435 complain_overflow_signed
, /* complain_on_overflow */
436 ppc64_elf_branch_reloc
, /* special_function */
437 "R_PPC64_REL24", /* name */
438 FALSE
, /* partial_inplace */
440 0x03fffffc, /* dst_mask */
441 TRUE
), /* pcrel_offset */
443 /* A relative 16 bit branch; the lower two bits must be zero. */
444 HOWTO (R_PPC64_REL14
, /* type */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
448 TRUE
, /* pc_relative */
450 complain_overflow_signed
, /* complain_on_overflow */
451 ppc64_elf_branch_reloc
, /* special_function */
452 "R_PPC64_REL14", /* name */
453 FALSE
, /* partial_inplace */
455 0x0000fffc, /* dst_mask */
456 TRUE
), /* pcrel_offset */
458 /* A relative 16 bit branch. Bit 10 should be set to indicate that
459 the branch is expected to be taken. The lower two bits must be
461 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
465 TRUE
, /* pc_relative */
467 complain_overflow_signed
, /* complain_on_overflow */
468 ppc64_elf_brtaken_reloc
, /* special_function */
469 "R_PPC64_REL14_BRTAKEN", /* name */
470 FALSE
, /* partial_inplace */
472 0x0000fffc, /* dst_mask */
473 TRUE
), /* pcrel_offset */
475 /* A relative 16 bit branch. Bit 10 should be set to indicate that
476 the branch is not expected to be taken. The lower two bits must
478 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 TRUE
, /* pc_relative */
484 complain_overflow_signed
, /* complain_on_overflow */
485 ppc64_elf_brtaken_reloc
, /* special_function */
486 "R_PPC64_REL14_BRNTAKEN",/* name */
487 FALSE
, /* partial_inplace */
489 0x0000fffc, /* dst_mask */
490 TRUE
), /* pcrel_offset */
492 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
494 HOWTO (R_PPC64_GOT16
, /* type */
496 1, /* size (0 = byte, 1 = short, 2 = long) */
498 FALSE
, /* pc_relative */
500 complain_overflow_signed
, /* complain_on_overflow */
501 ppc64_elf_unhandled_reloc
, /* special_function */
502 "R_PPC64_GOT16", /* name */
503 FALSE
, /* partial_inplace */
505 0xffff, /* dst_mask */
506 FALSE
), /* pcrel_offset */
508 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
510 HOWTO (R_PPC64_GOT16_LO
, /* type */
512 1, /* size (0 = byte, 1 = short, 2 = long) */
514 FALSE
, /* pc_relative */
516 complain_overflow_dont
, /* complain_on_overflow */
517 ppc64_elf_unhandled_reloc
, /* special_function */
518 "R_PPC64_GOT16_LO", /* name */
519 FALSE
, /* partial_inplace */
521 0xffff, /* dst_mask */
522 FALSE
), /* pcrel_offset */
524 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
526 HOWTO (R_PPC64_GOT16_HI
, /* type */
528 1, /* size (0 = byte, 1 = short, 2 = long) */
530 FALSE
, /* pc_relative */
532 complain_overflow_signed
,/* complain_on_overflow */
533 ppc64_elf_unhandled_reloc
, /* special_function */
534 "R_PPC64_GOT16_HI", /* name */
535 FALSE
, /* partial_inplace */
537 0xffff, /* dst_mask */
538 FALSE
), /* pcrel_offset */
540 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
542 HOWTO (R_PPC64_GOT16_HA
, /* type */
544 1, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE
, /* pc_relative */
548 complain_overflow_signed
,/* complain_on_overflow */
549 ppc64_elf_unhandled_reloc
, /* special_function */
550 "R_PPC64_GOT16_HA", /* name */
551 FALSE
, /* partial_inplace */
553 0xffff, /* dst_mask */
554 FALSE
), /* pcrel_offset */
556 /* This is used only by the dynamic linker. The symbol should exist
557 both in the object being run and in some shared library. The
558 dynamic linker copies the data addressed by the symbol from the
559 shared library into the object, because the object being
560 run has to have the data at some particular address. */
561 HOWTO (R_PPC64_COPY
, /* type */
563 0, /* this one is variable size */
565 FALSE
, /* pc_relative */
567 complain_overflow_dont
, /* complain_on_overflow */
568 ppc64_elf_unhandled_reloc
, /* special_function */
569 "R_PPC64_COPY", /* name */
570 FALSE
, /* partial_inplace */
573 FALSE
), /* pcrel_offset */
575 /* Like R_PPC64_ADDR64, but used when setting global offset table
577 HOWTO (R_PPC64_GLOB_DAT
, /* type */
579 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
581 FALSE
, /* pc_relative */
583 complain_overflow_dont
, /* complain_on_overflow */
584 ppc64_elf_unhandled_reloc
, /* special_function */
585 "R_PPC64_GLOB_DAT", /* name */
586 FALSE
, /* partial_inplace */
588 ONES (64), /* dst_mask */
589 FALSE
), /* pcrel_offset */
591 /* Created by the link editor. Marks a procedure linkage table
592 entry for a symbol. */
593 HOWTO (R_PPC64_JMP_SLOT
, /* type */
595 0, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE
, /* pc_relative */
599 complain_overflow_dont
, /* complain_on_overflow */
600 ppc64_elf_unhandled_reloc
, /* special_function */
601 "R_PPC64_JMP_SLOT", /* name */
602 FALSE
, /* partial_inplace */
605 FALSE
), /* pcrel_offset */
607 /* Used only by the dynamic linker. When the object is run, this
608 doubleword64 is set to the load address of the object, plus the
610 HOWTO (R_PPC64_RELATIVE
, /* type */
612 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
614 FALSE
, /* pc_relative */
616 complain_overflow_dont
, /* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_PPC64_RELATIVE", /* name */
619 FALSE
, /* partial_inplace */
621 ONES (64), /* dst_mask */
622 FALSE
), /* pcrel_offset */
624 /* Like R_PPC64_ADDR32, but may be unaligned. */
625 HOWTO (R_PPC64_UADDR32
, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 FALSE
, /* pc_relative */
631 complain_overflow_bitfield
, /* complain_on_overflow */
632 bfd_elf_generic_reloc
, /* special_function */
633 "R_PPC64_UADDR32", /* name */
634 FALSE
, /* partial_inplace */
636 0xffffffff, /* dst_mask */
637 FALSE
), /* pcrel_offset */
639 /* Like R_PPC64_ADDR16, but may be unaligned. */
640 HOWTO (R_PPC64_UADDR16
, /* type */
642 1, /* size (0 = byte, 1 = short, 2 = long) */
644 FALSE
, /* pc_relative */
646 complain_overflow_bitfield
, /* complain_on_overflow */
647 bfd_elf_generic_reloc
, /* special_function */
648 "R_PPC64_UADDR16", /* name */
649 FALSE
, /* partial_inplace */
651 0xffff, /* dst_mask */
652 FALSE
), /* pcrel_offset */
654 /* 32-bit PC relative. */
655 HOWTO (R_PPC64_REL32
, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 TRUE
, /* pc_relative */
661 complain_overflow_signed
, /* complain_on_overflow */
662 bfd_elf_generic_reloc
, /* special_function */
663 "R_PPC64_REL32", /* name */
664 FALSE
, /* partial_inplace */
666 0xffffffff, /* dst_mask */
667 TRUE
), /* pcrel_offset */
669 /* 32-bit relocation to the symbol's procedure linkage table. */
670 HOWTO (R_PPC64_PLT32
, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 FALSE
, /* pc_relative */
676 complain_overflow_bitfield
, /* complain_on_overflow */
677 ppc64_elf_unhandled_reloc
, /* special_function */
678 "R_PPC64_PLT32", /* name */
679 FALSE
, /* partial_inplace */
681 0xffffffff, /* dst_mask */
682 FALSE
), /* pcrel_offset */
684 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
685 FIXME: R_PPC64_PLTREL32 not supported. */
686 HOWTO (R_PPC64_PLTREL32
, /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 TRUE
, /* pc_relative */
692 complain_overflow_signed
, /* complain_on_overflow */
693 ppc64_elf_unhandled_reloc
, /* special_function */
694 "R_PPC64_PLTREL32", /* name */
695 FALSE
, /* partial_inplace */
697 0xffffffff, /* dst_mask */
698 TRUE
), /* pcrel_offset */
700 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
702 HOWTO (R_PPC64_PLT16_LO
, /* type */
704 1, /* size (0 = byte, 1 = short, 2 = long) */
706 FALSE
, /* pc_relative */
708 complain_overflow_dont
, /* complain_on_overflow */
709 ppc64_elf_unhandled_reloc
, /* special_function */
710 "R_PPC64_PLT16_LO", /* name */
711 FALSE
, /* partial_inplace */
713 0xffff, /* dst_mask */
714 FALSE
), /* pcrel_offset */
716 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
718 HOWTO (R_PPC64_PLT16_HI
, /* type */
720 1, /* size (0 = byte, 1 = short, 2 = long) */
722 FALSE
, /* pc_relative */
724 complain_overflow_signed
, /* complain_on_overflow */
725 ppc64_elf_unhandled_reloc
, /* special_function */
726 "R_PPC64_PLT16_HI", /* name */
727 FALSE
, /* partial_inplace */
729 0xffff, /* dst_mask */
730 FALSE
), /* pcrel_offset */
732 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
734 HOWTO (R_PPC64_PLT16_HA
, /* type */
736 1, /* size (0 = byte, 1 = short, 2 = long) */
738 FALSE
, /* pc_relative */
740 complain_overflow_signed
, /* complain_on_overflow */
741 ppc64_elf_unhandled_reloc
, /* special_function */
742 "R_PPC64_PLT16_HA", /* name */
743 FALSE
, /* partial_inplace */
745 0xffff, /* dst_mask */
746 FALSE
), /* pcrel_offset */
748 /* 16-bit section relative relocation. */
749 HOWTO (R_PPC64_SECTOFF
, /* type */
751 1, /* size (0 = byte, 1 = short, 2 = long) */
753 FALSE
, /* pc_relative */
755 complain_overflow_signed
, /* complain_on_overflow */
756 ppc64_elf_sectoff_reloc
, /* special_function */
757 "R_PPC64_SECTOFF", /* name */
758 FALSE
, /* partial_inplace */
760 0xffff, /* dst_mask */
761 FALSE
), /* pcrel_offset */
763 /* Like R_PPC64_SECTOFF, but no overflow warning. */
764 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
766 1, /* size (0 = byte, 1 = short, 2 = long) */
768 FALSE
, /* pc_relative */
770 complain_overflow_dont
, /* complain_on_overflow */
771 ppc64_elf_sectoff_reloc
, /* special_function */
772 "R_PPC64_SECTOFF_LO", /* name */
773 FALSE
, /* partial_inplace */
775 0xffff, /* dst_mask */
776 FALSE
), /* pcrel_offset */
778 /* 16-bit upper half section relative relocation. */
779 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
781 1, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE
, /* pc_relative */
785 complain_overflow_signed
, /* complain_on_overflow */
786 ppc64_elf_sectoff_reloc
, /* special_function */
787 "R_PPC64_SECTOFF_HI", /* name */
788 FALSE
, /* partial_inplace */
790 0xffff, /* dst_mask */
791 FALSE
), /* pcrel_offset */
793 /* 16-bit upper half adjusted section relative relocation. */
794 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
796 1, /* size (0 = byte, 1 = short, 2 = long) */
798 FALSE
, /* pc_relative */
800 complain_overflow_signed
, /* complain_on_overflow */
801 ppc64_elf_sectoff_ha_reloc
, /* special_function */
802 "R_PPC64_SECTOFF_HA", /* name */
803 FALSE
, /* partial_inplace */
805 0xffff, /* dst_mask */
806 FALSE
), /* pcrel_offset */
808 /* Like R_PPC64_REL24 without touching the two least significant bits. */
809 HOWTO (R_PPC64_REL30
, /* type */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
813 TRUE
, /* pc_relative */
815 complain_overflow_dont
, /* complain_on_overflow */
816 bfd_elf_generic_reloc
, /* special_function */
817 "R_PPC64_REL30", /* name */
818 FALSE
, /* partial_inplace */
820 0xfffffffc, /* dst_mask */
821 TRUE
), /* pcrel_offset */
823 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
825 /* A standard 64-bit relocation. */
826 HOWTO (R_PPC64_ADDR64
, /* type */
828 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
830 FALSE
, /* pc_relative */
832 complain_overflow_dont
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_PPC64_ADDR64", /* name */
835 FALSE
, /* partial_inplace */
837 ONES (64), /* dst_mask */
838 FALSE
), /* pcrel_offset */
840 /* The bits 32-47 of an address. */
841 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
843 1, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 bfd_elf_generic_reloc
, /* special_function */
849 "R_PPC64_ADDR16_HIGHER", /* name */
850 FALSE
, /* partial_inplace */
852 0xffff, /* dst_mask */
853 FALSE
), /* pcrel_offset */
855 /* The bits 32-47 of an address, plus 1 if the contents of the low
856 16 bits, treated as a signed number, is negative. */
857 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
859 1, /* size (0 = byte, 1 = short, 2 = long) */
861 FALSE
, /* pc_relative */
863 complain_overflow_dont
, /* complain_on_overflow */
864 ppc64_elf_ha_reloc
, /* special_function */
865 "R_PPC64_ADDR16_HIGHERA", /* name */
866 FALSE
, /* partial_inplace */
868 0xffff, /* dst_mask */
869 FALSE
), /* pcrel_offset */
871 /* The bits 48-63 of an address. */
872 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
874 1, /* size (0 = byte, 1 = short, 2 = long) */
876 FALSE
, /* pc_relative */
878 complain_overflow_dont
, /* complain_on_overflow */
879 bfd_elf_generic_reloc
, /* special_function */
880 "R_PPC64_ADDR16_HIGHEST", /* name */
881 FALSE
, /* partial_inplace */
883 0xffff, /* dst_mask */
884 FALSE
), /* pcrel_offset */
886 /* The bits 48-63 of an address, plus 1 if the contents of the low
887 16 bits, treated as a signed number, is negative. */
888 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
890 1, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_dont
, /* complain_on_overflow */
895 ppc64_elf_ha_reloc
, /* special_function */
896 "R_PPC64_ADDR16_HIGHESTA", /* name */
897 FALSE
, /* partial_inplace */
899 0xffff, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 /* Like ADDR64, but may be unaligned. */
903 HOWTO (R_PPC64_UADDR64
, /* type */
905 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
907 FALSE
, /* pc_relative */
909 complain_overflow_dont
, /* complain_on_overflow */
910 bfd_elf_generic_reloc
, /* special_function */
911 "R_PPC64_UADDR64", /* name */
912 FALSE
, /* partial_inplace */
914 ONES (64), /* dst_mask */
915 FALSE
), /* pcrel_offset */
917 /* 64-bit relative relocation. */
918 HOWTO (R_PPC64_REL64
, /* type */
920 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
922 TRUE
, /* pc_relative */
924 complain_overflow_dont
, /* complain_on_overflow */
925 bfd_elf_generic_reloc
, /* special_function */
926 "R_PPC64_REL64", /* name */
927 FALSE
, /* partial_inplace */
929 ONES (64), /* dst_mask */
930 TRUE
), /* pcrel_offset */
932 /* 64-bit relocation to the symbol's procedure linkage table. */
933 HOWTO (R_PPC64_PLT64
, /* type */
935 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
937 FALSE
, /* pc_relative */
939 complain_overflow_dont
, /* complain_on_overflow */
940 ppc64_elf_unhandled_reloc
, /* special_function */
941 "R_PPC64_PLT64", /* name */
942 FALSE
, /* partial_inplace */
944 ONES (64), /* dst_mask */
945 FALSE
), /* pcrel_offset */
947 /* 64-bit PC relative relocation to the symbol's procedure linkage
949 /* FIXME: R_PPC64_PLTREL64 not supported. */
950 HOWTO (R_PPC64_PLTREL64
, /* type */
952 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
954 TRUE
, /* pc_relative */
956 complain_overflow_dont
, /* complain_on_overflow */
957 ppc64_elf_unhandled_reloc
, /* special_function */
958 "R_PPC64_PLTREL64", /* name */
959 FALSE
, /* partial_inplace */
961 ONES (64), /* dst_mask */
962 TRUE
), /* pcrel_offset */
964 /* 16 bit TOC-relative relocation. */
966 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
967 HOWTO (R_PPC64_TOC16
, /* type */
969 1, /* size (0 = byte, 1 = short, 2 = long) */
971 FALSE
, /* pc_relative */
973 complain_overflow_signed
, /* complain_on_overflow */
974 ppc64_elf_toc_reloc
, /* special_function */
975 "R_PPC64_TOC16", /* name */
976 FALSE
, /* partial_inplace */
978 0xffff, /* dst_mask */
979 FALSE
), /* pcrel_offset */
981 /* 16 bit TOC-relative relocation without overflow. */
983 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
984 HOWTO (R_PPC64_TOC16_LO
, /* type */
986 1, /* size (0 = byte, 1 = short, 2 = long) */
988 FALSE
, /* pc_relative */
990 complain_overflow_dont
, /* complain_on_overflow */
991 ppc64_elf_toc_reloc
, /* special_function */
992 "R_PPC64_TOC16_LO", /* name */
993 FALSE
, /* partial_inplace */
995 0xffff, /* dst_mask */
996 FALSE
), /* pcrel_offset */
998 /* 16 bit TOC-relative relocation, high 16 bits. */
1000 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
1001 HOWTO (R_PPC64_TOC16_HI
, /* type */
1002 16, /* rightshift */
1003 1, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE
, /* pc_relative */
1007 complain_overflow_signed
, /* complain_on_overflow */
1008 ppc64_elf_toc_reloc
, /* special_function */
1009 "R_PPC64_TOC16_HI", /* name */
1010 FALSE
, /* partial_inplace */
1012 0xffff, /* dst_mask */
1013 FALSE
), /* pcrel_offset */
1015 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1016 contents of the low 16 bits, treated as a signed number, is
1019 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1020 HOWTO (R_PPC64_TOC16_HA
, /* type */
1021 16, /* rightshift */
1022 1, /* size (0 = byte, 1 = short, 2 = long) */
1024 FALSE
, /* pc_relative */
1026 complain_overflow_signed
, /* complain_on_overflow */
1027 ppc64_elf_toc_ha_reloc
, /* special_function */
1028 "R_PPC64_TOC16_HA", /* name */
1029 FALSE
, /* partial_inplace */
1031 0xffff, /* dst_mask */
1032 FALSE
), /* pcrel_offset */
1034 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1036 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1037 HOWTO (R_PPC64_TOC
, /* type */
1039 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1041 FALSE
, /* pc_relative */
1043 complain_overflow_dont
, /* complain_on_overflow */
1044 ppc64_elf_toc64_reloc
, /* special_function */
1045 "R_PPC64_TOC", /* name */
1046 FALSE
, /* partial_inplace */
1048 ONES (64), /* dst_mask */
1049 FALSE
), /* pcrel_offset */
1051 /* Like R_PPC64_GOT16, but also informs the link editor that the
1052 value to relocate may (!) refer to a PLT entry which the link
1053 editor (a) may replace with the symbol value. If the link editor
1054 is unable to fully resolve the symbol, it may (b) create a PLT
1055 entry and store the address to the new PLT entry in the GOT.
1056 This permits lazy resolution of function symbols at run time.
1057 The link editor may also skip all of this and just (c) emit a
1058 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1059 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1060 HOWTO (R_PPC64_PLTGOT16
, /* type */
1062 1, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE
, /* pc_relative */
1066 complain_overflow_signed
, /* complain_on_overflow */
1067 ppc64_elf_unhandled_reloc
, /* special_function */
1068 "R_PPC64_PLTGOT16", /* name */
1069 FALSE
, /* partial_inplace */
1071 0xffff, /* dst_mask */
1072 FALSE
), /* pcrel_offset */
1074 /* Like R_PPC64_PLTGOT16, but without overflow. */
1075 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1076 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE
, /* pc_relative */
1082 complain_overflow_dont
, /* complain_on_overflow */
1083 ppc64_elf_unhandled_reloc
, /* special_function */
1084 "R_PPC64_PLTGOT16_LO", /* name */
1085 FALSE
, /* partial_inplace */
1087 0xffff, /* dst_mask */
1088 FALSE
), /* pcrel_offset */
1090 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1091 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1092 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1093 16, /* rightshift */
1094 1, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE
, /* pc_relative */
1098 complain_overflow_signed
, /* complain_on_overflow */
1099 ppc64_elf_unhandled_reloc
, /* special_function */
1100 "R_PPC64_PLTGOT16_HI", /* name */
1101 FALSE
, /* partial_inplace */
1103 0xffff, /* dst_mask */
1104 FALSE
), /* pcrel_offset */
1106 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1107 1 if the contents of the low 16 bits, treated as a signed number,
1109 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1110 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1111 16, /* rightshift */
1112 1, /* size (0 = byte, 1 = short, 2 = long) */
1114 FALSE
, /* pc_relative */
1116 complain_overflow_signed
, /* complain_on_overflow */
1117 ppc64_elf_unhandled_reloc
, /* special_function */
1118 "R_PPC64_PLTGOT16_HA", /* name */
1119 FALSE
, /* partial_inplace */
1121 0xffff, /* dst_mask */
1122 FALSE
), /* pcrel_offset */
1124 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1125 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1127 1, /* size (0 = byte, 1 = short, 2 = long) */
1129 FALSE
, /* pc_relative */
1131 complain_overflow_signed
, /* complain_on_overflow */
1132 bfd_elf_generic_reloc
, /* special_function */
1133 "R_PPC64_ADDR16_DS", /* name */
1134 FALSE
, /* partial_inplace */
1136 0xfffc, /* dst_mask */
1137 FALSE
), /* pcrel_offset */
1139 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1140 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1142 1, /* size (0 = byte, 1 = short, 2 = long) */
1144 FALSE
, /* pc_relative */
1146 complain_overflow_dont
,/* complain_on_overflow */
1147 bfd_elf_generic_reloc
, /* special_function */
1148 "R_PPC64_ADDR16_LO_DS",/* name */
1149 FALSE
, /* partial_inplace */
1151 0xfffc, /* dst_mask */
1152 FALSE
), /* pcrel_offset */
1154 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1155 HOWTO (R_PPC64_GOT16_DS
, /* type */
1157 1, /* size (0 = byte, 1 = short, 2 = long) */
1159 FALSE
, /* pc_relative */
1161 complain_overflow_signed
, /* complain_on_overflow */
1162 ppc64_elf_unhandled_reloc
, /* special_function */
1163 "R_PPC64_GOT16_DS", /* name */
1164 FALSE
, /* partial_inplace */
1166 0xfffc, /* dst_mask */
1167 FALSE
), /* pcrel_offset */
1169 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1170 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1172 1, /* size (0 = byte, 1 = short, 2 = long) */
1174 FALSE
, /* pc_relative */
1176 complain_overflow_dont
, /* complain_on_overflow */
1177 ppc64_elf_unhandled_reloc
, /* special_function */
1178 "R_PPC64_GOT16_LO_DS", /* name */
1179 FALSE
, /* partial_inplace */
1181 0xfffc, /* dst_mask */
1182 FALSE
), /* pcrel_offset */
1184 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1185 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1187 1, /* size (0 = byte, 1 = short, 2 = long) */
1189 FALSE
, /* pc_relative */
1191 complain_overflow_dont
, /* complain_on_overflow */
1192 ppc64_elf_unhandled_reloc
, /* special_function */
1193 "R_PPC64_PLT16_LO_DS", /* name */
1194 FALSE
, /* partial_inplace */
1196 0xfffc, /* dst_mask */
1197 FALSE
), /* pcrel_offset */
1199 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1200 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1202 1, /* size (0 = byte, 1 = short, 2 = long) */
1204 FALSE
, /* pc_relative */
1206 complain_overflow_signed
, /* complain_on_overflow */
1207 ppc64_elf_sectoff_reloc
, /* special_function */
1208 "R_PPC64_SECTOFF_DS", /* name */
1209 FALSE
, /* partial_inplace */
1211 0xfffc, /* dst_mask */
1212 FALSE
), /* pcrel_offset */
1214 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1215 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1217 1, /* size (0 = byte, 1 = short, 2 = long) */
1219 FALSE
, /* pc_relative */
1221 complain_overflow_dont
, /* complain_on_overflow */
1222 ppc64_elf_sectoff_reloc
, /* special_function */
1223 "R_PPC64_SECTOFF_LO_DS",/* name */
1224 FALSE
, /* partial_inplace */
1226 0xfffc, /* dst_mask */
1227 FALSE
), /* pcrel_offset */
1229 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1230 HOWTO (R_PPC64_TOC16_DS
, /* type */
1232 1, /* size (0 = byte, 1 = short, 2 = long) */
1234 FALSE
, /* pc_relative */
1236 complain_overflow_signed
, /* complain_on_overflow */
1237 ppc64_elf_toc_reloc
, /* special_function */
1238 "R_PPC64_TOC16_DS", /* name */
1239 FALSE
, /* partial_inplace */
1241 0xfffc, /* dst_mask */
1242 FALSE
), /* pcrel_offset */
1244 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1245 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1247 1, /* size (0 = byte, 1 = short, 2 = long) */
1249 FALSE
, /* pc_relative */
1251 complain_overflow_dont
, /* complain_on_overflow */
1252 ppc64_elf_toc_reloc
, /* special_function */
1253 "R_PPC64_TOC16_LO_DS", /* name */
1254 FALSE
, /* partial_inplace */
1256 0xfffc, /* dst_mask */
1257 FALSE
), /* pcrel_offset */
1259 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1260 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1261 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1263 1, /* size (0 = byte, 1 = short, 2 = long) */
1265 FALSE
, /* pc_relative */
1267 complain_overflow_signed
, /* complain_on_overflow */
1268 ppc64_elf_unhandled_reloc
, /* special_function */
1269 "R_PPC64_PLTGOT16_DS", /* name */
1270 FALSE
, /* partial_inplace */
1272 0xfffc, /* dst_mask */
1273 FALSE
), /* pcrel_offset */
1275 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1276 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1277 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1279 1, /* size (0 = byte, 1 = short, 2 = long) */
1281 FALSE
, /* pc_relative */
1283 complain_overflow_dont
, /* complain_on_overflow */
1284 ppc64_elf_unhandled_reloc
, /* special_function */
1285 "R_PPC64_PLTGOT16_LO_DS",/* name */
1286 FALSE
, /* partial_inplace */
1288 0xfffc, /* dst_mask */
1289 FALSE
), /* pcrel_offset */
1291 /* Marker relocs for TLS. */
1294 2, /* size (0 = byte, 1 = short, 2 = long) */
1296 FALSE
, /* pc_relative */
1298 complain_overflow_dont
, /* complain_on_overflow */
1299 bfd_elf_generic_reloc
, /* special_function */
1300 "R_PPC64_TLS", /* name */
1301 FALSE
, /* partial_inplace */
1304 FALSE
), /* pcrel_offset */
1306 HOWTO (R_PPC64_TLSGD
,
1308 2, /* size (0 = byte, 1 = short, 2 = long) */
1310 FALSE
, /* pc_relative */
1312 complain_overflow_dont
, /* complain_on_overflow */
1313 bfd_elf_generic_reloc
, /* special_function */
1314 "R_PPC64_TLSGD", /* name */
1315 FALSE
, /* partial_inplace */
1318 FALSE
), /* pcrel_offset */
1320 HOWTO (R_PPC64_TLSLD
,
1322 2, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE
, /* pc_relative */
1326 complain_overflow_dont
, /* complain_on_overflow */
1327 bfd_elf_generic_reloc
, /* special_function */
1328 "R_PPC64_TLSLD", /* name */
1329 FALSE
, /* partial_inplace */
1332 FALSE
), /* pcrel_offset */
1334 HOWTO (R_PPC64_TOCSAVE
,
1336 2, /* size (0 = byte, 1 = short, 2 = long) */
1338 FALSE
, /* pc_relative */
1340 complain_overflow_dont
, /* complain_on_overflow */
1341 bfd_elf_generic_reloc
, /* special_function */
1342 "R_PPC64_TOCSAVE", /* name */
1343 FALSE
, /* partial_inplace */
1346 FALSE
), /* pcrel_offset */
1348 /* Computes the load module index of the load module that contains the
1349 definition of its TLS sym. */
1350 HOWTO (R_PPC64_DTPMOD64
,
1352 4, /* size (0 = byte, 1 = short, 2 = long) */
1354 FALSE
, /* pc_relative */
1356 complain_overflow_dont
, /* complain_on_overflow */
1357 ppc64_elf_unhandled_reloc
, /* special_function */
1358 "R_PPC64_DTPMOD64", /* name */
1359 FALSE
, /* partial_inplace */
1361 ONES (64), /* dst_mask */
1362 FALSE
), /* pcrel_offset */
1364 /* Computes a dtv-relative displacement, the difference between the value
1365 of sym+add and the base address of the thread-local storage block that
1366 contains the definition of sym, minus 0x8000. */
1367 HOWTO (R_PPC64_DTPREL64
,
1369 4, /* size (0 = byte, 1 = short, 2 = long) */
1371 FALSE
, /* pc_relative */
1373 complain_overflow_dont
, /* complain_on_overflow */
1374 ppc64_elf_unhandled_reloc
, /* special_function */
1375 "R_PPC64_DTPREL64", /* name */
1376 FALSE
, /* partial_inplace */
1378 ONES (64), /* dst_mask */
1379 FALSE
), /* pcrel_offset */
1381 /* A 16 bit dtprel reloc. */
1382 HOWTO (R_PPC64_DTPREL16
,
1384 1, /* size (0 = byte, 1 = short, 2 = long) */
1386 FALSE
, /* pc_relative */
1388 complain_overflow_signed
, /* complain_on_overflow */
1389 ppc64_elf_unhandled_reloc
, /* special_function */
1390 "R_PPC64_DTPREL16", /* name */
1391 FALSE
, /* partial_inplace */
1393 0xffff, /* dst_mask */
1394 FALSE
), /* pcrel_offset */
1396 /* Like DTPREL16, but no overflow. */
1397 HOWTO (R_PPC64_DTPREL16_LO
,
1399 1, /* size (0 = byte, 1 = short, 2 = long) */
1401 FALSE
, /* pc_relative */
1403 complain_overflow_dont
, /* complain_on_overflow */
1404 ppc64_elf_unhandled_reloc
, /* special_function */
1405 "R_PPC64_DTPREL16_LO", /* name */
1406 FALSE
, /* partial_inplace */
1408 0xffff, /* dst_mask */
1409 FALSE
), /* pcrel_offset */
1411 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1412 HOWTO (R_PPC64_DTPREL16_HI
,
1413 16, /* rightshift */
1414 1, /* size (0 = byte, 1 = short, 2 = long) */
1416 FALSE
, /* pc_relative */
1418 complain_overflow_signed
, /* complain_on_overflow */
1419 ppc64_elf_unhandled_reloc
, /* special_function */
1420 "R_PPC64_DTPREL16_HI", /* name */
1421 FALSE
, /* partial_inplace */
1423 0xffff, /* dst_mask */
1424 FALSE
), /* pcrel_offset */
1426 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1427 HOWTO (R_PPC64_DTPREL16_HA
,
1428 16, /* rightshift */
1429 1, /* size (0 = byte, 1 = short, 2 = long) */
1431 FALSE
, /* pc_relative */
1433 complain_overflow_signed
, /* complain_on_overflow */
1434 ppc64_elf_unhandled_reloc
, /* special_function */
1435 "R_PPC64_DTPREL16_HA", /* name */
1436 FALSE
, /* partial_inplace */
1438 0xffff, /* dst_mask */
1439 FALSE
), /* pcrel_offset */
1441 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1442 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1443 32, /* rightshift */
1444 1, /* size (0 = byte, 1 = short, 2 = long) */
1446 FALSE
, /* pc_relative */
1448 complain_overflow_dont
, /* complain_on_overflow */
1449 ppc64_elf_unhandled_reloc
, /* special_function */
1450 "R_PPC64_DTPREL16_HIGHER", /* name */
1451 FALSE
, /* partial_inplace */
1453 0xffff, /* dst_mask */
1454 FALSE
), /* pcrel_offset */
1456 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1457 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1458 32, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1461 FALSE
, /* pc_relative */
1463 complain_overflow_dont
, /* complain_on_overflow */
1464 ppc64_elf_unhandled_reloc
, /* special_function */
1465 "R_PPC64_DTPREL16_HIGHERA", /* name */
1466 FALSE
, /* partial_inplace */
1468 0xffff, /* dst_mask */
1469 FALSE
), /* pcrel_offset */
1471 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1472 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1473 48, /* rightshift */
1474 1, /* size (0 = byte, 1 = short, 2 = long) */
1476 FALSE
, /* pc_relative */
1478 complain_overflow_dont
, /* complain_on_overflow */
1479 ppc64_elf_unhandled_reloc
, /* special_function */
1480 "R_PPC64_DTPREL16_HIGHEST", /* name */
1481 FALSE
, /* partial_inplace */
1483 0xffff, /* dst_mask */
1484 FALSE
), /* pcrel_offset */
1486 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1487 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1488 48, /* rightshift */
1489 1, /* size (0 = byte, 1 = short, 2 = long) */
1491 FALSE
, /* pc_relative */
1493 complain_overflow_dont
, /* complain_on_overflow */
1494 ppc64_elf_unhandled_reloc
, /* special_function */
1495 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1496 FALSE
, /* partial_inplace */
1498 0xffff, /* dst_mask */
1499 FALSE
), /* pcrel_offset */
1501 /* Like DTPREL16, but for insns with a DS field. */
1502 HOWTO (R_PPC64_DTPREL16_DS
,
1504 1, /* size (0 = byte, 1 = short, 2 = long) */
1506 FALSE
, /* pc_relative */
1508 complain_overflow_signed
, /* complain_on_overflow */
1509 ppc64_elf_unhandled_reloc
, /* special_function */
1510 "R_PPC64_DTPREL16_DS", /* name */
1511 FALSE
, /* partial_inplace */
1513 0xfffc, /* dst_mask */
1514 FALSE
), /* pcrel_offset */
1516 /* Like DTPREL16_DS, but no overflow. */
1517 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1519 1, /* size (0 = byte, 1 = short, 2 = long) */
1521 FALSE
, /* pc_relative */
1523 complain_overflow_dont
, /* complain_on_overflow */
1524 ppc64_elf_unhandled_reloc
, /* special_function */
1525 "R_PPC64_DTPREL16_LO_DS", /* name */
1526 FALSE
, /* partial_inplace */
1528 0xfffc, /* dst_mask */
1529 FALSE
), /* pcrel_offset */
1531 /* Computes a tp-relative displacement, the difference between the value of
1532 sym+add and the value of the thread pointer (r13). */
1533 HOWTO (R_PPC64_TPREL64
,
1535 4, /* size (0 = byte, 1 = short, 2 = long) */
1537 FALSE
, /* pc_relative */
1539 complain_overflow_dont
, /* complain_on_overflow */
1540 ppc64_elf_unhandled_reloc
, /* special_function */
1541 "R_PPC64_TPREL64", /* name */
1542 FALSE
, /* partial_inplace */
1544 ONES (64), /* dst_mask */
1545 FALSE
), /* pcrel_offset */
1547 /* A 16 bit tprel reloc. */
1548 HOWTO (R_PPC64_TPREL16
,
1550 1, /* size (0 = byte, 1 = short, 2 = long) */
1552 FALSE
, /* pc_relative */
1554 complain_overflow_signed
, /* complain_on_overflow */
1555 ppc64_elf_unhandled_reloc
, /* special_function */
1556 "R_PPC64_TPREL16", /* name */
1557 FALSE
, /* partial_inplace */
1559 0xffff, /* dst_mask */
1560 FALSE
), /* pcrel_offset */
1562 /* Like TPREL16, but no overflow. */
1563 HOWTO (R_PPC64_TPREL16_LO
,
1565 1, /* size (0 = byte, 1 = short, 2 = long) */
1567 FALSE
, /* pc_relative */
1569 complain_overflow_dont
, /* complain_on_overflow */
1570 ppc64_elf_unhandled_reloc
, /* special_function */
1571 "R_PPC64_TPREL16_LO", /* name */
1572 FALSE
, /* partial_inplace */
1574 0xffff, /* dst_mask */
1575 FALSE
), /* pcrel_offset */
1577 /* Like TPREL16_LO, but next higher group of 16 bits. */
1578 HOWTO (R_PPC64_TPREL16_HI
,
1579 16, /* rightshift */
1580 1, /* size (0 = byte, 1 = short, 2 = long) */
1582 FALSE
, /* pc_relative */
1584 complain_overflow_signed
, /* complain_on_overflow */
1585 ppc64_elf_unhandled_reloc
, /* special_function */
1586 "R_PPC64_TPREL16_HI", /* name */
1587 FALSE
, /* partial_inplace */
1589 0xffff, /* dst_mask */
1590 FALSE
), /* pcrel_offset */
1592 /* Like TPREL16_HI, but adjust for low 16 bits. */
1593 HOWTO (R_PPC64_TPREL16_HA
,
1594 16, /* rightshift */
1595 1, /* size (0 = byte, 1 = short, 2 = long) */
1597 FALSE
, /* pc_relative */
1599 complain_overflow_signed
, /* complain_on_overflow */
1600 ppc64_elf_unhandled_reloc
, /* special_function */
1601 "R_PPC64_TPREL16_HA", /* name */
1602 FALSE
, /* partial_inplace */
1604 0xffff, /* dst_mask */
1605 FALSE
), /* pcrel_offset */
1607 /* Like TPREL16_HI, but next higher group of 16 bits. */
1608 HOWTO (R_PPC64_TPREL16_HIGHER
,
1609 32, /* rightshift */
1610 1, /* size (0 = byte, 1 = short, 2 = long) */
1612 FALSE
, /* pc_relative */
1614 complain_overflow_dont
, /* complain_on_overflow */
1615 ppc64_elf_unhandled_reloc
, /* special_function */
1616 "R_PPC64_TPREL16_HIGHER", /* name */
1617 FALSE
, /* partial_inplace */
1619 0xffff, /* dst_mask */
1620 FALSE
), /* pcrel_offset */
1622 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1623 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1624 32, /* rightshift */
1625 1, /* size (0 = byte, 1 = short, 2 = long) */
1627 FALSE
, /* pc_relative */
1629 complain_overflow_dont
, /* complain_on_overflow */
1630 ppc64_elf_unhandled_reloc
, /* special_function */
1631 "R_PPC64_TPREL16_HIGHERA", /* name */
1632 FALSE
, /* partial_inplace */
1634 0xffff, /* dst_mask */
1635 FALSE
), /* pcrel_offset */
1637 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1638 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1639 48, /* rightshift */
1640 1, /* size (0 = byte, 1 = short, 2 = long) */
1642 FALSE
, /* pc_relative */
1644 complain_overflow_dont
, /* complain_on_overflow */
1645 ppc64_elf_unhandled_reloc
, /* special_function */
1646 "R_PPC64_TPREL16_HIGHEST", /* name */
1647 FALSE
, /* partial_inplace */
1649 0xffff, /* dst_mask */
1650 FALSE
), /* pcrel_offset */
1652 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1653 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1654 48, /* rightshift */
1655 1, /* size (0 = byte, 1 = short, 2 = long) */
1657 FALSE
, /* pc_relative */
1659 complain_overflow_dont
, /* complain_on_overflow */
1660 ppc64_elf_unhandled_reloc
, /* special_function */
1661 "R_PPC64_TPREL16_HIGHESTA", /* name */
1662 FALSE
, /* partial_inplace */
1664 0xffff, /* dst_mask */
1665 FALSE
), /* pcrel_offset */
1667 /* Like TPREL16, but for insns with a DS field. */
1668 HOWTO (R_PPC64_TPREL16_DS
,
1670 1, /* size (0 = byte, 1 = short, 2 = long) */
1672 FALSE
, /* pc_relative */
1674 complain_overflow_signed
, /* complain_on_overflow */
1675 ppc64_elf_unhandled_reloc
, /* special_function */
1676 "R_PPC64_TPREL16_DS", /* name */
1677 FALSE
, /* partial_inplace */
1679 0xfffc, /* dst_mask */
1680 FALSE
), /* pcrel_offset */
1682 /* Like TPREL16_DS, but no overflow. */
1683 HOWTO (R_PPC64_TPREL16_LO_DS
,
1685 1, /* size (0 = byte, 1 = short, 2 = long) */
1687 FALSE
, /* pc_relative */
1689 complain_overflow_dont
, /* complain_on_overflow */
1690 ppc64_elf_unhandled_reloc
, /* special_function */
1691 "R_PPC64_TPREL16_LO_DS", /* name */
1692 FALSE
, /* partial_inplace */
1694 0xfffc, /* dst_mask */
1695 FALSE
), /* pcrel_offset */
1697 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1698 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1699 to the first entry relative to the TOC base (r2). */
1700 HOWTO (R_PPC64_GOT_TLSGD16
,
1702 1, /* size (0 = byte, 1 = short, 2 = long) */
1704 FALSE
, /* pc_relative */
1706 complain_overflow_signed
, /* complain_on_overflow */
1707 ppc64_elf_unhandled_reloc
, /* special_function */
1708 "R_PPC64_GOT_TLSGD16", /* name */
1709 FALSE
, /* partial_inplace */
1711 0xffff, /* dst_mask */
1712 FALSE
), /* pcrel_offset */
1714 /* Like GOT_TLSGD16, but no overflow. */
1715 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1717 1, /* size (0 = byte, 1 = short, 2 = long) */
1719 FALSE
, /* pc_relative */
1721 complain_overflow_dont
, /* complain_on_overflow */
1722 ppc64_elf_unhandled_reloc
, /* special_function */
1723 "R_PPC64_GOT_TLSGD16_LO", /* name */
1724 FALSE
, /* partial_inplace */
1726 0xffff, /* dst_mask */
1727 FALSE
), /* pcrel_offset */
1729 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1730 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1731 16, /* rightshift */
1732 1, /* size (0 = byte, 1 = short, 2 = long) */
1734 FALSE
, /* pc_relative */
1736 complain_overflow_signed
, /* complain_on_overflow */
1737 ppc64_elf_unhandled_reloc
, /* special_function */
1738 "R_PPC64_GOT_TLSGD16_HI", /* name */
1739 FALSE
, /* partial_inplace */
1741 0xffff, /* dst_mask */
1742 FALSE
), /* pcrel_offset */
1744 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1745 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1746 16, /* rightshift */
1747 1, /* size (0 = byte, 1 = short, 2 = long) */
1749 FALSE
, /* pc_relative */
1751 complain_overflow_signed
, /* complain_on_overflow */
1752 ppc64_elf_unhandled_reloc
, /* special_function */
1753 "R_PPC64_GOT_TLSGD16_HA", /* name */
1754 FALSE
, /* partial_inplace */
1756 0xffff, /* dst_mask */
1757 FALSE
), /* pcrel_offset */
1759 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1760 with values (sym+add)@dtpmod and zero, and computes the offset to the
1761 first entry relative to the TOC base (r2). */
1762 HOWTO (R_PPC64_GOT_TLSLD16
,
1764 1, /* size (0 = byte, 1 = short, 2 = long) */
1766 FALSE
, /* pc_relative */
1768 complain_overflow_signed
, /* complain_on_overflow */
1769 ppc64_elf_unhandled_reloc
, /* special_function */
1770 "R_PPC64_GOT_TLSLD16", /* name */
1771 FALSE
, /* partial_inplace */
1773 0xffff, /* dst_mask */
1774 FALSE
), /* pcrel_offset */
1776 /* Like GOT_TLSLD16, but no overflow. */
1777 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1779 1, /* size (0 = byte, 1 = short, 2 = long) */
1781 FALSE
, /* pc_relative */
1783 complain_overflow_dont
, /* complain_on_overflow */
1784 ppc64_elf_unhandled_reloc
, /* special_function */
1785 "R_PPC64_GOT_TLSLD16_LO", /* name */
1786 FALSE
, /* partial_inplace */
1788 0xffff, /* dst_mask */
1789 FALSE
), /* pcrel_offset */
1791 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1792 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1793 16, /* rightshift */
1794 1, /* size (0 = byte, 1 = short, 2 = long) */
1796 FALSE
, /* pc_relative */
1798 complain_overflow_signed
, /* complain_on_overflow */
1799 ppc64_elf_unhandled_reloc
, /* special_function */
1800 "R_PPC64_GOT_TLSLD16_HI", /* name */
1801 FALSE
, /* partial_inplace */
1803 0xffff, /* dst_mask */
1804 FALSE
), /* pcrel_offset */
1806 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1807 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1808 16, /* rightshift */
1809 1, /* size (0 = byte, 1 = short, 2 = long) */
1811 FALSE
, /* pc_relative */
1813 complain_overflow_signed
, /* complain_on_overflow */
1814 ppc64_elf_unhandled_reloc
, /* special_function */
1815 "R_PPC64_GOT_TLSLD16_HA", /* name */
1816 FALSE
, /* partial_inplace */
1818 0xffff, /* dst_mask */
1819 FALSE
), /* pcrel_offset */
1821 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1822 the offset to the entry relative to the TOC base (r2). */
1823 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1825 1, /* size (0 = byte, 1 = short, 2 = long) */
1827 FALSE
, /* pc_relative */
1829 complain_overflow_signed
, /* complain_on_overflow */
1830 ppc64_elf_unhandled_reloc
, /* special_function */
1831 "R_PPC64_GOT_DTPREL16_DS", /* name */
1832 FALSE
, /* partial_inplace */
1834 0xfffc, /* dst_mask */
1835 FALSE
), /* pcrel_offset */
1837 /* Like GOT_DTPREL16_DS, but no overflow. */
1838 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1840 1, /* size (0 = byte, 1 = short, 2 = long) */
1842 FALSE
, /* pc_relative */
1844 complain_overflow_dont
, /* complain_on_overflow */
1845 ppc64_elf_unhandled_reloc
, /* special_function */
1846 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1847 FALSE
, /* partial_inplace */
1849 0xfffc, /* dst_mask */
1850 FALSE
), /* pcrel_offset */
1852 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1853 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1854 16, /* rightshift */
1855 1, /* size (0 = byte, 1 = short, 2 = long) */
1857 FALSE
, /* pc_relative */
1859 complain_overflow_signed
, /* complain_on_overflow */
1860 ppc64_elf_unhandled_reloc
, /* special_function */
1861 "R_PPC64_GOT_DTPREL16_HI", /* name */
1862 FALSE
, /* partial_inplace */
1864 0xffff, /* dst_mask */
1865 FALSE
), /* pcrel_offset */
1867 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1868 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1869 16, /* rightshift */
1870 1, /* size (0 = byte, 1 = short, 2 = long) */
1872 FALSE
, /* pc_relative */
1874 complain_overflow_signed
, /* complain_on_overflow */
1875 ppc64_elf_unhandled_reloc
, /* special_function */
1876 "R_PPC64_GOT_DTPREL16_HA", /* name */
1877 FALSE
, /* partial_inplace */
1879 0xffff, /* dst_mask */
1880 FALSE
), /* pcrel_offset */
1882 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1883 offset to the entry relative to the TOC base (r2). */
1884 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1886 1, /* size (0 = byte, 1 = short, 2 = long) */
1888 FALSE
, /* pc_relative */
1890 complain_overflow_signed
, /* complain_on_overflow */
1891 ppc64_elf_unhandled_reloc
, /* special_function */
1892 "R_PPC64_GOT_TPREL16_DS", /* name */
1893 FALSE
, /* partial_inplace */
1895 0xfffc, /* dst_mask */
1896 FALSE
), /* pcrel_offset */
1898 /* Like GOT_TPREL16_DS, but no overflow. */
1899 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1901 1, /* size (0 = byte, 1 = short, 2 = long) */
1903 FALSE
, /* pc_relative */
1905 complain_overflow_dont
, /* complain_on_overflow */
1906 ppc64_elf_unhandled_reloc
, /* special_function */
1907 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1908 FALSE
, /* partial_inplace */
1910 0xfffc, /* dst_mask */
1911 FALSE
), /* pcrel_offset */
1913 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1914 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1915 16, /* rightshift */
1916 1, /* size (0 = byte, 1 = short, 2 = long) */
1918 FALSE
, /* pc_relative */
1920 complain_overflow_signed
, /* complain_on_overflow */
1921 ppc64_elf_unhandled_reloc
, /* special_function */
1922 "R_PPC64_GOT_TPREL16_HI", /* name */
1923 FALSE
, /* partial_inplace */
1925 0xffff, /* dst_mask */
1926 FALSE
), /* pcrel_offset */
1928 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1929 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1930 16, /* rightshift */
1931 1, /* size (0 = byte, 1 = short, 2 = long) */
1933 FALSE
, /* pc_relative */
1935 complain_overflow_signed
, /* complain_on_overflow */
1936 ppc64_elf_unhandled_reloc
, /* special_function */
1937 "R_PPC64_GOT_TPREL16_HA", /* name */
1938 FALSE
, /* partial_inplace */
1940 0xffff, /* dst_mask */
1941 FALSE
), /* pcrel_offset */
1943 HOWTO (R_PPC64_JMP_IREL
, /* type */
1945 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1947 FALSE
, /* pc_relative */
1949 complain_overflow_dont
, /* complain_on_overflow */
1950 ppc64_elf_unhandled_reloc
, /* special_function */
1951 "R_PPC64_JMP_IREL", /* name */
1952 FALSE
, /* partial_inplace */
1955 FALSE
), /* pcrel_offset */
1957 HOWTO (R_PPC64_IRELATIVE
, /* type */
1959 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1961 FALSE
, /* pc_relative */
1963 complain_overflow_dont
, /* complain_on_overflow */
1964 bfd_elf_generic_reloc
, /* special_function */
1965 "R_PPC64_IRELATIVE", /* name */
1966 FALSE
, /* partial_inplace */
1968 ONES (64), /* dst_mask */
1969 FALSE
), /* pcrel_offset */
1971 /* A 16 bit relative relocation. */
1972 HOWTO (R_PPC64_REL16
, /* type */
1974 1, /* size (0 = byte, 1 = short, 2 = long) */
1976 TRUE
, /* pc_relative */
1978 complain_overflow_signed
, /* complain_on_overflow */
1979 bfd_elf_generic_reloc
, /* special_function */
1980 "R_PPC64_REL16", /* name */
1981 FALSE
, /* partial_inplace */
1983 0xffff, /* dst_mask */
1984 TRUE
), /* pcrel_offset */
1986 /* A 16 bit relative relocation without overflow. */
1987 HOWTO (R_PPC64_REL16_LO
, /* type */
1989 1, /* size (0 = byte, 1 = short, 2 = long) */
1991 TRUE
, /* pc_relative */
1993 complain_overflow_dont
,/* complain_on_overflow */
1994 bfd_elf_generic_reloc
, /* special_function */
1995 "R_PPC64_REL16_LO", /* name */
1996 FALSE
, /* partial_inplace */
1998 0xffff, /* dst_mask */
1999 TRUE
), /* pcrel_offset */
2001 /* The high order 16 bits of a relative address. */
2002 HOWTO (R_PPC64_REL16_HI
, /* type */
2003 16, /* rightshift */
2004 1, /* size (0 = byte, 1 = short, 2 = long) */
2006 TRUE
, /* pc_relative */
2008 complain_overflow_signed
, /* complain_on_overflow */
2009 bfd_elf_generic_reloc
, /* special_function */
2010 "R_PPC64_REL16_HI", /* name */
2011 FALSE
, /* partial_inplace */
2013 0xffff, /* dst_mask */
2014 TRUE
), /* pcrel_offset */
2016 /* The high order 16 bits of a relative address, plus 1 if the contents of
2017 the low 16 bits, treated as a signed number, is negative. */
2018 HOWTO (R_PPC64_REL16_HA
, /* type */
2019 16, /* rightshift */
2020 1, /* size (0 = byte, 1 = short, 2 = long) */
2022 TRUE
, /* pc_relative */
2024 complain_overflow_signed
, /* complain_on_overflow */
2025 ppc64_elf_ha_reloc
, /* special_function */
2026 "R_PPC64_REL16_HA", /* name */
2027 FALSE
, /* partial_inplace */
2029 0xffff, /* dst_mask */
2030 TRUE
), /* pcrel_offset */
2032 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
2033 HOWTO (R_PPC64_REL16DX_HA
, /* type */
2034 16, /* rightshift */
2035 2, /* size (0 = byte, 1 = short, 2 = long) */
2037 TRUE
, /* pc_relative */
2039 complain_overflow_signed
, /* complain_on_overflow */
2040 ppc64_elf_ha_reloc
, /* special_function */
2041 "R_PPC64_REL16DX_HA", /* name */
2042 FALSE
, /* partial_inplace */
2044 0x1fffc1, /* dst_mask */
2045 TRUE
), /* pcrel_offset */
2047 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2048 HOWTO (R_PPC64_ADDR16_HIGH
, /* type */
2049 16, /* rightshift */
2050 1, /* size (0 = byte, 1 = short, 2 = long) */
2052 FALSE
, /* pc_relative */
2054 complain_overflow_dont
, /* complain_on_overflow */
2055 bfd_elf_generic_reloc
, /* special_function */
2056 "R_PPC64_ADDR16_HIGH", /* name */
2057 FALSE
, /* partial_inplace */
2059 0xffff, /* dst_mask */
2060 FALSE
), /* pcrel_offset */
2062 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2063 HOWTO (R_PPC64_ADDR16_HIGHA
, /* type */
2064 16, /* rightshift */
2065 1, /* size (0 = byte, 1 = short, 2 = long) */
2067 FALSE
, /* pc_relative */
2069 complain_overflow_dont
, /* complain_on_overflow */
2070 ppc64_elf_ha_reloc
, /* special_function */
2071 "R_PPC64_ADDR16_HIGHA", /* name */
2072 FALSE
, /* partial_inplace */
2074 0xffff, /* dst_mask */
2075 FALSE
), /* pcrel_offset */
2077 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2078 HOWTO (R_PPC64_DTPREL16_HIGH
,
2079 16, /* rightshift */
2080 1, /* size (0 = byte, 1 = short, 2 = long) */
2082 FALSE
, /* pc_relative */
2084 complain_overflow_dont
, /* complain_on_overflow */
2085 ppc64_elf_unhandled_reloc
, /* special_function */
2086 "R_PPC64_DTPREL16_HIGH", /* name */
2087 FALSE
, /* partial_inplace */
2089 0xffff, /* dst_mask */
2090 FALSE
), /* pcrel_offset */
2092 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2093 HOWTO (R_PPC64_DTPREL16_HIGHA
,
2094 16, /* rightshift */
2095 1, /* size (0 = byte, 1 = short, 2 = long) */
2097 FALSE
, /* pc_relative */
2099 complain_overflow_dont
, /* complain_on_overflow */
2100 ppc64_elf_unhandled_reloc
, /* special_function */
2101 "R_PPC64_DTPREL16_HIGHA", /* name */
2102 FALSE
, /* partial_inplace */
2104 0xffff, /* dst_mask */
2105 FALSE
), /* pcrel_offset */
2107 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2108 HOWTO (R_PPC64_TPREL16_HIGH
,
2109 16, /* rightshift */
2110 1, /* size (0 = byte, 1 = short, 2 = long) */
2112 FALSE
, /* pc_relative */
2114 complain_overflow_dont
, /* complain_on_overflow */
2115 ppc64_elf_unhandled_reloc
, /* special_function */
2116 "R_PPC64_TPREL16_HIGH", /* name */
2117 FALSE
, /* partial_inplace */
2119 0xffff, /* dst_mask */
2120 FALSE
), /* pcrel_offset */
2122 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2123 HOWTO (R_PPC64_TPREL16_HIGHA
,
2124 16, /* rightshift */
2125 1, /* size (0 = byte, 1 = short, 2 = long) */
2127 FALSE
, /* pc_relative */
2129 complain_overflow_dont
, /* complain_on_overflow */
2130 ppc64_elf_unhandled_reloc
, /* special_function */
2131 "R_PPC64_TPREL16_HIGHA", /* name */
2132 FALSE
, /* partial_inplace */
2134 0xffff, /* dst_mask */
2135 FALSE
), /* pcrel_offset */
2137 /* Marker reloc on ELFv2 large-model function entry. */
2138 HOWTO (R_PPC64_ENTRY
,
2140 2, /* size (0 = byte, 1 = short, 2 = long) */
2142 FALSE
, /* pc_relative */
2144 complain_overflow_dont
, /* complain_on_overflow */
2145 bfd_elf_generic_reloc
, /* special_function */
2146 "R_PPC64_ENTRY", /* name */
2147 FALSE
, /* partial_inplace */
2150 FALSE
), /* pcrel_offset */
2152 /* Like ADDR64, but use local entry point of function. */
2153 HOWTO (R_PPC64_ADDR64_LOCAL
, /* type */
2155 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2157 FALSE
, /* pc_relative */
2159 complain_overflow_dont
, /* complain_on_overflow */
2160 bfd_elf_generic_reloc
, /* special_function */
2161 "R_PPC64_ADDR64_LOCAL", /* name */
2162 FALSE
, /* partial_inplace */
2164 ONES (64), /* dst_mask */
2165 FALSE
), /* pcrel_offset */
2167 /* GNU extension to record C++ vtable hierarchy. */
2168 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
2170 0, /* size (0 = byte, 1 = short, 2 = long) */
2172 FALSE
, /* pc_relative */
2174 complain_overflow_dont
, /* complain_on_overflow */
2175 NULL
, /* special_function */
2176 "R_PPC64_GNU_VTINHERIT", /* name */
2177 FALSE
, /* partial_inplace */
2180 FALSE
), /* pcrel_offset */
2182 /* GNU extension to record C++ vtable member usage. */
2183 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
2185 0, /* size (0 = byte, 1 = short, 2 = long) */
2187 FALSE
, /* pc_relative */
2189 complain_overflow_dont
, /* complain_on_overflow */
2190 NULL
, /* special_function */
2191 "R_PPC64_GNU_VTENTRY", /* name */
2192 FALSE
, /* partial_inplace */
2195 FALSE
), /* pcrel_offset */
2199 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2203 ppc_howto_init (void)
2205 unsigned int i
, type
;
2207 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2209 type
= ppc64_elf_howto_raw
[i
].type
;
2210 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
2211 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2215 static reloc_howto_type
*
2216 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2217 bfd_reloc_code_real_type code
)
2219 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2221 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2222 /* Initialize howto table if needed. */
2230 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2232 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2234 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2236 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2238 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2240 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2242 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
2244 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2246 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
2248 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2250 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2252 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2254 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2256 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2258 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2260 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2262 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2264 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2266 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2268 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2270 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2272 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2274 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2276 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2278 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2280 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2282 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2284 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2286 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2288 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2290 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2292 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2294 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2296 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2298 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2300 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2302 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2304 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2306 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2308 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2310 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2312 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2314 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2316 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2318 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2320 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2322 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2324 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2326 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2328 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2330 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2332 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2334 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2336 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2338 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2340 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2342 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2344 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2346 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2348 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2350 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2352 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2354 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2356 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2358 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2360 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2362 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2364 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2366 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
2368 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2370 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
2372 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2374 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2376 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2378 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2380 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
2382 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2384 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
2386 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2388 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2390 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2392 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2394 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2396 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2398 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2400 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2402 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2404 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2406 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2408 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2410 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2412 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2414 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2416 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2418 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2420 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2422 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2424 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2426 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2428 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2430 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2432 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2434 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2436 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2438 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2440 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2442 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2444 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2446 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2448 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2450 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2452 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
2454 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
2456 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
2458 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2460 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2464 return ppc64_elf_howto_table
[r
];
2467 static reloc_howto_type
*
2468 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2473 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2474 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2475 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2476 return &ppc64_elf_howto_raw
[i
];
2481 /* Set the howto pointer for a PowerPC ELF reloc. */
2484 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2485 Elf_Internal_Rela
*dst
)
2489 /* Initialize howto table if needed. */
2490 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2493 type
= ELF64_R_TYPE (dst
->r_info
);
2494 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
2496 /* xgettext:c-format */
2497 _bfd_error_handler (_("%B: invalid relocation type %d"),
2499 type
= R_PPC64_NONE
;
2501 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2504 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2506 static bfd_reloc_status_type
2507 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2508 void *data
, asection
*input_section
,
2509 bfd
*output_bfd
, char **error_message
)
2511 enum elf_ppc64_reloc_type r_type
;
2513 bfd_size_type octets
;
2516 /* If this is a relocatable link (output_bfd test tells us), just
2517 call the generic function. Any adjustment will be done at final
2519 if (output_bfd
!= NULL
)
2520 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2521 input_section
, output_bfd
, error_message
);
2523 /* Adjust the addend for sign extension of the low 16 bits.
2524 We won't actually be using the low 16 bits, so trashing them
2526 reloc_entry
->addend
+= 0x8000;
2527 r_type
= reloc_entry
->howto
->type
;
2528 if (r_type
!= R_PPC64_REL16DX_HA
)
2529 return bfd_reloc_continue
;
2532 if (!bfd_is_com_section (symbol
->section
))
2533 value
= symbol
->value
;
2534 value
+= (reloc_entry
->addend
2535 + symbol
->section
->output_offset
2536 + symbol
->section
->output_section
->vma
);
2537 value
-= (reloc_entry
->address
2538 + input_section
->output_offset
2539 + input_section
->output_section
->vma
);
2540 value
= (bfd_signed_vma
) value
>> 16;
2542 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2543 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2545 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2546 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2547 if (value
+ 0x8000 > 0xffff)
2548 return bfd_reloc_overflow
;
2549 return bfd_reloc_ok
;
2552 static bfd_reloc_status_type
2553 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2554 void *data
, asection
*input_section
,
2555 bfd
*output_bfd
, char **error_message
)
2557 if (output_bfd
!= NULL
)
2558 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2559 input_section
, output_bfd
, error_message
);
2561 if (strcmp (symbol
->section
->name
, ".opd") == 0
2562 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2564 bfd_vma dest
= opd_entry_value (symbol
->section
,
2565 symbol
->value
+ reloc_entry
->addend
,
2567 if (dest
!= (bfd_vma
) -1)
2568 reloc_entry
->addend
= dest
- (symbol
->value
2569 + symbol
->section
->output_section
->vma
2570 + symbol
->section
->output_offset
);
2574 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
2576 if (symbol
->section
->owner
!= abfd
2577 && symbol
->section
->owner
!= NULL
2578 && abiversion (symbol
->section
->owner
) >= 2)
2582 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
2584 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
2586 if (strcmp (symdef
->name
, symbol
->name
) == 0)
2588 elfsym
= (elf_symbol_type
*) symdef
;
2594 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
2596 return bfd_reloc_continue
;
2599 static bfd_reloc_status_type
2600 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2601 void *data
, asection
*input_section
,
2602 bfd
*output_bfd
, char **error_message
)
2605 enum elf_ppc64_reloc_type r_type
;
2606 bfd_size_type octets
;
2607 /* Assume 'at' branch hints. */
2608 bfd_boolean is_isa_v2
= TRUE
;
2610 /* If this is a relocatable link (output_bfd test tells us), just
2611 call the generic function. Any adjustment will be done at final
2613 if (output_bfd
!= NULL
)
2614 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2615 input_section
, output_bfd
, error_message
);
2617 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2618 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2619 insn
&= ~(0x01 << 21);
2620 r_type
= reloc_entry
->howto
->type
;
2621 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2622 || r_type
== R_PPC64_REL14_BRTAKEN
)
2623 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2627 /* Set 'a' bit. This is 0b00010 in BO field for branch
2628 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2629 for branch on CTR insns (BO == 1a00t or 1a01t). */
2630 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2632 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2642 if (!bfd_is_com_section (symbol
->section
))
2643 target
= symbol
->value
;
2644 target
+= symbol
->section
->output_section
->vma
;
2645 target
+= symbol
->section
->output_offset
;
2646 target
+= reloc_entry
->addend
;
2648 from
= (reloc_entry
->address
2649 + input_section
->output_offset
2650 + input_section
->output_section
->vma
);
2652 /* Invert 'y' bit if not the default. */
2653 if ((bfd_signed_vma
) (target
- from
) < 0)
2656 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2658 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2659 input_section
, output_bfd
, error_message
);
2662 static bfd_reloc_status_type
2663 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2664 void *data
, asection
*input_section
,
2665 bfd
*output_bfd
, char **error_message
)
2667 /* If this is a relocatable link (output_bfd test tells us), just
2668 call the generic function. Any adjustment will be done at final
2670 if (output_bfd
!= NULL
)
2671 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2672 input_section
, output_bfd
, error_message
);
2674 /* Subtract the symbol section base address. */
2675 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2676 return bfd_reloc_continue
;
2679 static bfd_reloc_status_type
2680 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2681 void *data
, asection
*input_section
,
2682 bfd
*output_bfd
, char **error_message
)
2684 /* If this is a relocatable link (output_bfd test tells us), just
2685 call the generic function. Any adjustment will be done at final
2687 if (output_bfd
!= NULL
)
2688 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2689 input_section
, output_bfd
, error_message
);
2691 /* Subtract the symbol section base address. */
2692 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2694 /* Adjust the addend for sign extension of the low 16 bits. */
2695 reloc_entry
->addend
+= 0x8000;
2696 return bfd_reloc_continue
;
2699 static bfd_reloc_status_type
2700 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2701 void *data
, asection
*input_section
,
2702 bfd
*output_bfd
, char **error_message
)
2706 /* If this is a relocatable link (output_bfd test tells us), just
2707 call the generic function. Any adjustment will be done at final
2709 if (output_bfd
!= NULL
)
2710 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2711 input_section
, output_bfd
, error_message
);
2713 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2715 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2717 /* Subtract the TOC base address. */
2718 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2719 return bfd_reloc_continue
;
2722 static bfd_reloc_status_type
2723 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2724 void *data
, asection
*input_section
,
2725 bfd
*output_bfd
, char **error_message
)
2729 /* If this is a relocatable link (output_bfd test tells us), just
2730 call the generic function. Any adjustment will be done at final
2732 if (output_bfd
!= NULL
)
2733 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2734 input_section
, output_bfd
, error_message
);
2736 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2738 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2740 /* Subtract the TOC base address. */
2741 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2743 /* Adjust the addend for sign extension of the low 16 bits. */
2744 reloc_entry
->addend
+= 0x8000;
2745 return bfd_reloc_continue
;
2748 static bfd_reloc_status_type
2749 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2750 void *data
, asection
*input_section
,
2751 bfd
*output_bfd
, char **error_message
)
2754 bfd_size_type octets
;
2756 /* If this is a relocatable link (output_bfd test tells us), just
2757 call the generic function. Any adjustment will be done at final
2759 if (output_bfd
!= NULL
)
2760 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2761 input_section
, output_bfd
, error_message
);
2763 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2765 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2767 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2768 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2769 return bfd_reloc_ok
;
2772 static bfd_reloc_status_type
2773 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2774 void *data
, asection
*input_section
,
2775 bfd
*output_bfd
, char **error_message
)
2777 /* If this is a relocatable link (output_bfd test tells us), just
2778 call the generic function. Any adjustment will be done at final
2780 if (output_bfd
!= NULL
)
2781 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2782 input_section
, output_bfd
, error_message
);
2784 if (error_message
!= NULL
)
2786 static char buf
[60];
2787 sprintf (buf
, "generic linker can't handle %s",
2788 reloc_entry
->howto
->name
);
2789 *error_message
= buf
;
2791 return bfd_reloc_dangerous
;
2794 /* Track GOT entries needed for a given symbol. We might need more
2795 than one got entry per symbol. */
2798 struct got_entry
*next
;
2800 /* The symbol addend that we'll be placing in the GOT. */
2803 /* Unlike other ELF targets, we use separate GOT entries for the same
2804 symbol referenced from different input files. This is to support
2805 automatic multiple TOC/GOT sections, where the TOC base can vary
2806 from one input file to another. After partitioning into TOC groups
2807 we merge entries within the group.
2809 Point to the BFD owning this GOT entry. */
2812 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2813 TLS_TPREL or TLS_DTPREL for tls entries. */
2814 unsigned char tls_type
;
2816 /* Non-zero if got.ent points to real entry. */
2817 unsigned char is_indirect
;
2819 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2822 bfd_signed_vma refcount
;
2824 struct got_entry
*ent
;
2828 /* The same for PLT. */
2831 struct plt_entry
*next
;
2837 bfd_signed_vma refcount
;
2842 struct ppc64_elf_obj_tdata
2844 struct elf_obj_tdata elf
;
2846 /* Shortcuts to dynamic linker sections. */
2850 /* Used during garbage collection. We attach global symbols defined
2851 on removed .opd entries to this section so that the sym is removed. */
2852 asection
*deleted_section
;
2854 /* TLS local dynamic got entry handling. Support for multiple GOT
2855 sections means we potentially need one of these for each input bfd. */
2856 struct got_entry tlsld_got
;
2859 /* A copy of relocs before they are modified for --emit-relocs. */
2860 Elf_Internal_Rela
*relocs
;
2862 /* Section contents. */
2866 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2867 the reloc to be in the range -32768 to 32767. */
2868 unsigned int has_small_toc_reloc
: 1;
2870 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2871 instruction not one we handle. */
2872 unsigned int unexpected_toc_insn
: 1;
2875 #define ppc64_elf_tdata(bfd) \
2876 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2878 #define ppc64_tlsld_got(bfd) \
2879 (&ppc64_elf_tdata (bfd)->tlsld_got)
2881 #define is_ppc64_elf(bfd) \
2882 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2883 && elf_object_id (bfd) == PPC64_ELF_DATA)
2885 /* Override the generic function because we store some extras. */
2888 ppc64_elf_mkobject (bfd
*abfd
)
2890 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2894 /* Fix bad default arch selected for a 64 bit input bfd when the
2895 default is 32 bit. Also select arch based on apuinfo. */
2898 ppc64_elf_object_p (bfd
*abfd
)
2900 if (!abfd
->arch_info
->the_default
)
2903 if (abfd
->arch_info
->bits_per_word
== 32)
2905 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2907 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2909 /* Relies on arch after 32 bit default being 64 bit default. */
2910 abfd
->arch_info
= abfd
->arch_info
->next
;
2911 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2914 return _bfd_elf_ppc_set_arch (abfd
);
2917 /* Support for core dump NOTE sections. */
2920 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2922 size_t offset
, size
;
2924 if (note
->descsz
!= 504)
2928 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2931 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2937 /* Make a ".reg/999" section. */
2938 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2939 size
, note
->descpos
+ offset
);
2943 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2945 if (note
->descsz
!= 136)
2948 elf_tdata (abfd
)->core
->pid
2949 = bfd_get_32 (abfd
, note
->descdata
+ 24);
2950 elf_tdata (abfd
)->core
->program
2951 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2952 elf_tdata (abfd
)->core
->command
2953 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2959 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2972 va_start (ap
, note_type
);
2973 memset (data
, 0, sizeof (data
));
2974 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2975 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2977 return elfcore_write_note (abfd
, buf
, bufsiz
,
2978 "CORE", note_type
, data
, sizeof (data
));
2989 va_start (ap
, note_type
);
2990 memset (data
, 0, 112);
2991 pid
= va_arg (ap
, long);
2992 bfd_put_32 (abfd
, pid
, data
+ 32);
2993 cursig
= va_arg (ap
, int);
2994 bfd_put_16 (abfd
, cursig
, data
+ 12);
2995 greg
= va_arg (ap
, const void *);
2996 memcpy (data
+ 112, greg
, 384);
2997 memset (data
+ 496, 0, 8);
2999 return elfcore_write_note (abfd
, buf
, bufsiz
,
3000 "CORE", note_type
, data
, sizeof (data
));
3005 /* Add extra PPC sections. */
3007 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
3009 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
3010 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3011 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3012 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3013 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3014 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3015 { NULL
, 0, 0, 0, 0 }
3018 enum _ppc64_sec_type
{
3024 struct _ppc64_elf_section_data
3026 struct bfd_elf_section_data elf
;
3030 /* An array with one entry for each opd function descriptor,
3031 and some spares since opd entries may be either 16 or 24 bytes. */
3032 #define OPD_NDX(OFF) ((OFF) >> 4)
3033 struct _opd_sec_data
3035 /* Points to the function code section for local opd entries. */
3036 asection
**func_sec
;
3038 /* After editing .opd, adjust references to opd local syms. */
3042 /* An array for toc sections, indexed by offset/8. */
3043 struct _toc_sec_data
3045 /* Specifies the relocation symbol index used at a given toc offset. */
3048 /* And the relocation addend. */
3053 enum _ppc64_sec_type sec_type
:2;
3055 /* Flag set when small branches are detected. Used to
3056 select suitable defaults for the stub group size. */
3057 unsigned int has_14bit_branch
:1;
3060 #define ppc64_elf_section_data(sec) \
3061 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
3064 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
3066 if (!sec
->used_by_bfd
)
3068 struct _ppc64_elf_section_data
*sdata
;
3069 bfd_size_type amt
= sizeof (*sdata
);
3071 sdata
= bfd_zalloc (abfd
, amt
);
3074 sec
->used_by_bfd
= sdata
;
3077 return _bfd_elf_new_section_hook (abfd
, sec
);
3080 static struct _opd_sec_data
*
3081 get_opd_info (asection
* sec
)
3084 && ppc64_elf_section_data (sec
) != NULL
3085 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
3086 return &ppc64_elf_section_data (sec
)->u
.opd
;
3090 /* Parameters for the qsort hook. */
3091 static bfd_boolean synthetic_relocatable
;
3092 static asection
*synthetic_opd
;
3094 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3097 compare_symbols (const void *ap
, const void *bp
)
3099 const asymbol
*a
= * (const asymbol
**) ap
;
3100 const asymbol
*b
= * (const asymbol
**) bp
;
3102 /* Section symbols first. */
3103 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
3105 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
3108 /* then .opd symbols. */
3109 if (synthetic_opd
!= NULL
)
3111 if (strcmp (a
->section
->name
, ".opd") == 0
3112 && strcmp (b
->section
->name
, ".opd") != 0)
3114 if (strcmp (a
->section
->name
, ".opd") != 0
3115 && strcmp (b
->section
->name
, ".opd") == 0)
3119 /* then other code symbols. */
3120 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3121 == (SEC_CODE
| SEC_ALLOC
)
3122 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3123 != (SEC_CODE
| SEC_ALLOC
))
3126 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3127 != (SEC_CODE
| SEC_ALLOC
)
3128 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3129 == (SEC_CODE
| SEC_ALLOC
))
3132 if (synthetic_relocatable
)
3134 if (a
->section
->id
< b
->section
->id
)
3137 if (a
->section
->id
> b
->section
->id
)
3141 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
3144 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
3147 /* For syms with the same value, prefer strong dynamic global function
3148 syms over other syms. */
3149 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
3152 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
3155 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
3158 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
3161 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
3164 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
3167 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
3170 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
3176 /* Search SYMS for a symbol of the given VALUE. */
3179 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
3183 if (id
== (unsigned) -1)
3187 mid
= (lo
+ hi
) >> 1;
3188 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
3190 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
3200 mid
= (lo
+ hi
) >> 1;
3201 if (syms
[mid
]->section
->id
< id
)
3203 else if (syms
[mid
]->section
->id
> id
)
3205 else if (syms
[mid
]->value
< value
)
3207 else if (syms
[mid
]->value
> value
)
3217 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
3219 bfd_vma vma
= *(bfd_vma
*) ptr
;
3220 return ((section
->flags
& SEC_ALLOC
) != 0
3221 && section
->vma
<= vma
3222 && vma
< section
->vma
+ section
->size
);
3225 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3226 entry syms. Also generate @plt symbols for the glink branch table.
3227 Returns count of synthetic symbols in RET or -1 on error. */
3230 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
3231 long static_count
, asymbol
**static_syms
,
3232 long dyn_count
, asymbol
**dyn_syms
,
3239 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
3240 asection
*opd
= NULL
;
3241 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
3243 int abi
= abiversion (abfd
);
3249 opd
= bfd_get_section_by_name (abfd
, ".opd");
3250 if (opd
== NULL
&& abi
== 1)
3254 symcount
= static_count
;
3256 symcount
+= dyn_count
;
3260 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
3264 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
3266 /* Use both symbol tables. */
3267 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
3268 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
3270 else if (!relocatable
&& static_count
== 0)
3271 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
3273 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
3275 synthetic_relocatable
= relocatable
;
3276 synthetic_opd
= opd
;
3277 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
3279 if (!relocatable
&& symcount
> 1)
3282 /* Trim duplicate syms, since we may have merged the normal and
3283 dynamic symbols. Actually, we only care about syms that have
3284 different values, so trim any with the same value. */
3285 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3286 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3287 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3288 syms
[j
++] = syms
[i
];
3293 /* Note that here and in compare_symbols we can't compare opd and
3294 sym->section directly. With separate debug info files, the
3295 symbols will be extracted from the debug file while abfd passed
3296 to this function is the real binary. */
3297 if (opd
!= NULL
&& strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3301 for (; i
< symcount
; ++i
)
3302 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3303 != (SEC_CODE
| SEC_ALLOC
))
3304 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3308 for (; i
< symcount
; ++i
)
3309 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3314 for (; i
< symcount
; ++i
)
3315 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3319 for (; i
< symcount
; ++i
)
3320 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3321 != (SEC_CODE
| SEC_ALLOC
))
3329 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3334 if (opdsymend
== secsymend
)
3337 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3338 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3342 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3349 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3353 while (r
< opd
->relocation
+ relcount
3354 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3357 if (r
== opd
->relocation
+ relcount
)
3360 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3363 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3366 sym
= *r
->sym_ptr_ptr
;
3367 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3368 sym
->section
->id
, sym
->value
+ r
->addend
))
3371 size
+= sizeof (asymbol
);
3372 size
+= strlen (syms
[i
]->name
) + 2;
3378 s
= *ret
= bfd_malloc (size
);
3385 names
= (char *) (s
+ count
);
3387 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3391 while (r
< opd
->relocation
+ relcount
3392 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3395 if (r
== opd
->relocation
+ relcount
)
3398 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3401 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3404 sym
= *r
->sym_ptr_ptr
;
3405 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3406 sym
->section
->id
, sym
->value
+ r
->addend
))
3411 s
->flags
|= BSF_SYNTHETIC
;
3412 s
->section
= sym
->section
;
3413 s
->value
= sym
->value
+ r
->addend
;
3416 len
= strlen (syms
[i
]->name
);
3417 memcpy (names
, syms
[i
]->name
, len
+ 1);
3419 /* Have udata.p point back to the original symbol this
3420 synthetic symbol was derived from. */
3421 s
->udata
.p
= syms
[i
];
3428 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3429 bfd_byte
*contents
= NULL
;
3432 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3433 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3436 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3438 free_contents_and_exit_err
:
3440 free_contents_and_exit
:
3447 for (i
= secsymend
; i
< opdsymend
; ++i
)
3451 /* Ignore bogus symbols. */
3452 if (syms
[i
]->value
> opd
->size
- 8)
3455 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3456 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3459 size
+= sizeof (asymbol
);
3460 size
+= strlen (syms
[i
]->name
) + 2;
3464 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3466 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3468 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3470 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3472 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3473 goto free_contents_and_exit_err
;
3475 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3476 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3479 extdynend
= extdyn
+ dynamic
->size
;
3480 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3482 Elf_Internal_Dyn dyn
;
3483 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3485 if (dyn
.d_tag
== DT_NULL
)
3488 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3490 /* The first glink stub starts at offset 32; see
3491 comment in ppc64_elf_finish_dynamic_sections. */
3492 glink_vma
= dyn
.d_un
.d_val
+ GLINK_CALL_STUB_SIZE
- 8 * 4;
3493 /* The .glink section usually does not survive the final
3494 link; search for the section (usually .text) where the
3495 glink stubs now reside. */
3496 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3507 /* Determine __glink trampoline by reading the relative branch
3508 from the first glink stub. */
3510 unsigned int off
= 0;
3512 while (bfd_get_section_contents (abfd
, glink
, buf
,
3513 glink_vma
+ off
- glink
->vma
, 4))
3515 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3517 if ((insn
& ~0x3fffffc) == 0)
3519 resolv_vma
= glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
3528 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3530 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3533 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3534 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3535 goto free_contents_and_exit_err
;
3537 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3538 size
+= plt_count
* sizeof (asymbol
);
3540 p
= relplt
->relocation
;
3541 for (i
= 0; i
< plt_count
; i
++, p
++)
3543 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3545 size
+= sizeof ("+0x") - 1 + 16;
3551 goto free_contents_and_exit
;
3552 s
= *ret
= bfd_malloc (size
);
3554 goto free_contents_and_exit_err
;
3556 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3558 for (i
= secsymend
; i
< opdsymend
; ++i
)
3562 if (syms
[i
]->value
> opd
->size
- 8)
3565 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3566 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3570 asection
*sec
= abfd
->sections
;
3577 long mid
= (lo
+ hi
) >> 1;
3578 if (syms
[mid
]->section
->vma
< ent
)
3580 else if (syms
[mid
]->section
->vma
> ent
)
3584 sec
= syms
[mid
]->section
;
3589 if (lo
>= hi
&& lo
> codesecsym
)
3590 sec
= syms
[lo
- 1]->section
;
3592 for (; sec
!= NULL
; sec
= sec
->next
)
3596 /* SEC_LOAD may not be set if SEC is from a separate debug
3598 if ((sec
->flags
& SEC_ALLOC
) == 0)
3600 if ((sec
->flags
& SEC_CODE
) != 0)
3603 s
->flags
|= BSF_SYNTHETIC
;
3604 s
->value
= ent
- s
->section
->vma
;
3607 len
= strlen (syms
[i
]->name
);
3608 memcpy (names
, syms
[i
]->name
, len
+ 1);
3610 /* Have udata.p point back to the original symbol this
3611 synthetic symbol was derived from. */
3612 s
->udata
.p
= syms
[i
];
3618 if (glink
!= NULL
&& relplt
!= NULL
)
3622 /* Add a symbol for the main glink trampoline. */
3623 memset (s
, 0, sizeof *s
);
3625 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3627 s
->value
= resolv_vma
- glink
->vma
;
3629 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3630 names
+= sizeof ("__glink_PLTresolve");
3635 /* FIXME: It would be very much nicer to put sym@plt on the
3636 stub rather than on the glink branch table entry. The
3637 objdump disassembler would then use a sensible symbol
3638 name on plt calls. The difficulty in doing so is
3639 a) finding the stubs, and,
3640 b) matching stubs against plt entries, and,
3641 c) there can be multiple stubs for a given plt entry.
3643 Solving (a) could be done by code scanning, but older
3644 ppc64 binaries used different stubs to current code.
3645 (b) is the tricky one since you need to known the toc
3646 pointer for at least one function that uses a pic stub to
3647 be able to calculate the plt address referenced.
3648 (c) means gdb would need to set multiple breakpoints (or
3649 find the glink branch itself) when setting breakpoints
3650 for pending shared library loads. */
3651 p
= relplt
->relocation
;
3652 for (i
= 0; i
< plt_count
; i
++, p
++)
3656 *s
= **p
->sym_ptr_ptr
;
3657 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3658 we are defining a symbol, ensure one of them is set. */
3659 if ((s
->flags
& BSF_LOCAL
) == 0)
3660 s
->flags
|= BSF_GLOBAL
;
3661 s
->flags
|= BSF_SYNTHETIC
;
3663 s
->value
= glink_vma
- glink
->vma
;
3666 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3667 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3671 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3672 names
+= sizeof ("+0x") - 1;
3673 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3674 names
+= strlen (names
);
3676 memcpy (names
, "@plt", sizeof ("@plt"));
3677 names
+= sizeof ("@plt");
3697 /* The following functions are specific to the ELF linker, while
3698 functions above are used generally. Those named ppc64_elf_* are
3699 called by the main ELF linker code. They appear in this file more
3700 or less in the order in which they are called. eg.
3701 ppc64_elf_check_relocs is called early in the link process,
3702 ppc64_elf_finish_dynamic_sections is one of the last functions
3705 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3706 functions have both a function code symbol and a function descriptor
3707 symbol. A call to foo in a relocatable object file looks like:
3714 The function definition in another object file might be:
3718 . .quad .TOC.@tocbase
3724 When the linker resolves the call during a static link, the branch
3725 unsurprisingly just goes to .foo and the .opd information is unused.
3726 If the function definition is in a shared library, things are a little
3727 different: The call goes via a plt call stub, the opd information gets
3728 copied to the plt, and the linker patches the nop.
3736 . std 2,40(1) # in practice, the call stub
3737 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3738 . addi 11,11,Lfoo@toc@l # this is the general idea
3746 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3748 The "reloc ()" notation is supposed to indicate that the linker emits
3749 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3752 What are the difficulties here? Well, firstly, the relocations
3753 examined by the linker in check_relocs are against the function code
3754 sym .foo, while the dynamic relocation in the plt is emitted against
3755 the function descriptor symbol, foo. Somewhere along the line, we need
3756 to carefully copy dynamic link information from one symbol to the other.
3757 Secondly, the generic part of the elf linker will make .foo a dynamic
3758 symbol as is normal for most other backends. We need foo dynamic
3759 instead, at least for an application final link. However, when
3760 creating a shared library containing foo, we need to have both symbols
3761 dynamic so that references to .foo are satisfied during the early
3762 stages of linking. Otherwise the linker might decide to pull in a
3763 definition from some other object, eg. a static library.
3765 Update: As of August 2004, we support a new convention. Function
3766 calls may use the function descriptor symbol, ie. "bl foo". This
3767 behaves exactly as "bl .foo". */
3769 /* Of those relocs that might be copied as dynamic relocs, this function
3770 selects those that must be copied when linking a shared library,
3771 even when the symbol is local. */
3774 must_be_dyn_reloc (struct bfd_link_info
*info
,
3775 enum elf_ppc64_reloc_type r_type
)
3787 case R_PPC64_TPREL16
:
3788 case R_PPC64_TPREL16_LO
:
3789 case R_PPC64_TPREL16_HI
:
3790 case R_PPC64_TPREL16_HA
:
3791 case R_PPC64_TPREL16_DS
:
3792 case R_PPC64_TPREL16_LO_DS
:
3793 case R_PPC64_TPREL16_HIGH
:
3794 case R_PPC64_TPREL16_HIGHA
:
3795 case R_PPC64_TPREL16_HIGHER
:
3796 case R_PPC64_TPREL16_HIGHERA
:
3797 case R_PPC64_TPREL16_HIGHEST
:
3798 case R_PPC64_TPREL16_HIGHESTA
:
3799 case R_PPC64_TPREL64
:
3800 return !bfd_link_executable (info
);
3804 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3805 copying dynamic variables from a shared lib into an app's dynbss
3806 section, and instead use a dynamic relocation to point into the
3807 shared lib. With code that gcc generates, it's vital that this be
3808 enabled; In the PowerPC64 ABI, the address of a function is actually
3809 the address of a function descriptor, which resides in the .opd
3810 section. gcc uses the descriptor directly rather than going via the
3811 GOT as some other ABI's do, which means that initialized function
3812 pointers must reference the descriptor. Thus, a function pointer
3813 initialized to the address of a function in a shared library will
3814 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3815 redefines the function descriptor symbol to point to the copy. This
3816 presents a problem as a plt entry for that function is also
3817 initialized from the function descriptor symbol and the copy reloc
3818 may not be initialized first. */
3819 #define ELIMINATE_COPY_RELOCS 1
3821 /* Section name for stubs is the associated section name plus this
3823 #define STUB_SUFFIX ".stub"
3826 ppc_stub_long_branch:
3827 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3828 destination, but a 24 bit branch in a stub section will reach.
3831 ppc_stub_plt_branch:
3832 Similar to the above, but a 24 bit branch in the stub section won't
3833 reach its destination.
3834 . addis %r11,%r2,xxx@toc@ha
3835 . ld %r12,xxx@toc@l(%r11)
3840 Used to call a function in a shared library. If it so happens that
3841 the plt entry referenced crosses a 64k boundary, then an extra
3842 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3844 . addis %r11,%r2,xxx@toc@ha
3845 . ld %r12,xxx+0@toc@l(%r11)
3847 . ld %r2,xxx+8@toc@l(%r11)
3848 . ld %r11,xxx+16@toc@l(%r11)
3851 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3852 code to adjust the value and save r2 to support multiple toc sections.
3853 A ppc_stub_long_branch with an r2 offset looks like:
3855 . addis %r2,%r2,off@ha
3856 . addi %r2,%r2,off@l
3859 A ppc_stub_plt_branch with an r2 offset looks like:
3861 . addis %r11,%r2,xxx@toc@ha
3862 . ld %r12,xxx@toc@l(%r11)
3863 . addis %r2,%r2,off@ha
3864 . addi %r2,%r2,off@l
3868 In cases where the "addis" instruction would add zero, the "addis" is
3869 omitted and following instructions modified slightly in some cases.
3872 enum ppc_stub_type
{
3874 ppc_stub_long_branch
,
3875 ppc_stub_long_branch_r2off
,
3876 ppc_stub_plt_branch
,
3877 ppc_stub_plt_branch_r2off
,
3879 ppc_stub_plt_call_r2save
,
3880 ppc_stub_global_entry
,
3884 /* Information on stub grouping. */
3887 /* The stub section. */
3889 /* This is the section to which stubs in the group will be attached. */
3892 struct map_stub
*next
;
3893 /* Whether to emit a copy of register save/restore functions in this
3898 struct ppc_stub_hash_entry
{
3900 /* Base hash table entry structure. */
3901 struct bfd_hash_entry root
;
3903 enum ppc_stub_type stub_type
;
3905 /* Group information. */
3906 struct map_stub
*group
;
3908 /* Offset within stub_sec of the beginning of this stub. */
3909 bfd_vma stub_offset
;
3911 /* Given the symbol's value and its section we can determine its final
3912 value when building the stubs (so the stub knows where to jump. */
3913 bfd_vma target_value
;
3914 asection
*target_section
;
3916 /* The symbol table entry, if any, that this was derived from. */
3917 struct ppc_link_hash_entry
*h
;
3918 struct plt_entry
*plt_ent
;
3920 /* Symbol st_other. */
3921 unsigned char other
;
3924 struct ppc_branch_hash_entry
{
3926 /* Base hash table entry structure. */
3927 struct bfd_hash_entry root
;
3929 /* Offset within branch lookup table. */
3930 unsigned int offset
;
3932 /* Generation marker. */
3936 /* Used to track dynamic relocations for local symbols. */
3937 struct ppc_dyn_relocs
3939 struct ppc_dyn_relocs
*next
;
3941 /* The input section of the reloc. */
3944 /* Total number of relocs copied for the input section. */
3945 unsigned int count
: 31;
3947 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3948 unsigned int ifunc
: 1;
3951 struct ppc_link_hash_entry
3953 struct elf_link_hash_entry elf
;
3956 /* A pointer to the most recently used stub hash entry against this
3958 struct ppc_stub_hash_entry
*stub_cache
;
3960 /* A pointer to the next symbol starting with a '.' */
3961 struct ppc_link_hash_entry
*next_dot_sym
;
3964 /* Track dynamic relocs copied for this symbol. */
3965 struct elf_dyn_relocs
*dyn_relocs
;
3967 /* Chain of aliases referring to a weakdef. */
3968 struct ppc_link_hash_entry
*weakref
;
3970 /* Link between function code and descriptor symbols. */
3971 struct ppc_link_hash_entry
*oh
;
3973 /* Flag function code and descriptor symbols. */
3974 unsigned int is_func
:1;
3975 unsigned int is_func_descriptor
:1;
3976 unsigned int fake
:1;
3978 /* Whether global opd/toc sym has been adjusted or not.
3979 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3980 should be set for all globals defined in any opd/toc section. */
3981 unsigned int adjust_done
:1;
3983 /* Set if this is an out-of-line register save/restore function,
3984 with non-standard calling convention. */
3985 unsigned int save_res
:1;
3987 /* Contexts in which symbol is used in the GOT (or TOC).
3988 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3989 corresponding relocs are encountered during check_relocs.
3990 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3991 indicate the corresponding GOT entry type is not needed.
3992 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3993 a TPREL one. We use a separate flag rather than setting TPREL
3994 just for convenience in distinguishing the two cases. */
3995 #define TLS_GD 1 /* GD reloc. */
3996 #define TLS_LD 2 /* LD reloc. */
3997 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3998 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3999 #define TLS_TLS 16 /* Any TLS reloc. */
4000 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
4001 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
4002 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
4003 unsigned char tls_mask
;
4006 /* ppc64 ELF linker hash table. */
4008 struct ppc_link_hash_table
4010 struct elf_link_hash_table elf
;
4012 /* The stub hash table. */
4013 struct bfd_hash_table stub_hash_table
;
4015 /* Another hash table for plt_branch stubs. */
4016 struct bfd_hash_table branch_hash_table
;
4018 /* Hash table for function prologue tocsave. */
4019 htab_t tocsave_htab
;
4021 /* Various options and other info passed from the linker. */
4022 struct ppc64_elf_params
*params
;
4024 /* The size of sec_info below. */
4025 unsigned int sec_info_arr_size
;
4027 /* Per-section array of extra section info. Done this way rather
4028 than as part of ppc64_elf_section_data so we have the info for
4029 non-ppc64 sections. */
4032 /* Along with elf_gp, specifies the TOC pointer used by this section. */
4037 /* The section group that this section belongs to. */
4038 struct map_stub
*group
;
4039 /* A temp section list pointer. */
4044 /* Linked list of groups. */
4045 struct map_stub
*group
;
4047 /* Temp used when calculating TOC pointers. */
4050 asection
*toc_first_sec
;
4052 /* Used when adding symbols. */
4053 struct ppc_link_hash_entry
*dot_syms
;
4055 /* Shortcuts to get to dynamic linker sections. */
4062 asection
*glink_eh_frame
;
4064 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
4065 struct ppc_link_hash_entry
*tls_get_addr
;
4066 struct ppc_link_hash_entry
*tls_get_addr_fd
;
4068 /* The size of reliplt used by got entry relocs. */
4069 bfd_size_type got_reli_size
;
4072 unsigned long stub_count
[ppc_stub_global_entry
];
4074 /* Number of stubs against global syms. */
4075 unsigned long stub_globals
;
4077 /* Set if we're linking code with function descriptors. */
4078 unsigned int opd_abi
:1;
4080 /* Support for multiple toc sections. */
4081 unsigned int do_multi_toc
:1;
4082 unsigned int multi_toc_needed
:1;
4083 unsigned int second_toc_pass
:1;
4084 unsigned int do_toc_opt
:1;
4087 unsigned int stub_error
:1;
4089 /* Whether func_desc_adjust needs to be run over symbols. */
4090 unsigned int need_func_desc_adj
:1;
4092 /* Incremented every time we size stubs. */
4093 unsigned int stub_iteration
;
4095 /* Small local sym cache. */
4096 struct sym_cache sym_cache
;
4099 /* Rename some of the generic section flags to better document how they
4102 /* Nonzero if this section has TLS related relocations. */
4103 #define has_tls_reloc sec_flg0
4105 /* Nonzero if this section has a call to __tls_get_addr. */
4106 #define has_tls_get_addr_call sec_flg1
4108 /* Nonzero if this section has any toc or got relocs. */
4109 #define has_toc_reloc sec_flg2
4111 /* Nonzero if this section has a call to another section that uses
4113 #define makes_toc_func_call sec_flg3
4115 /* Recursion protection when determining above flag. */
4116 #define call_check_in_progress sec_flg4
4117 #define call_check_done sec_flg5
4119 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4121 #define ppc_hash_table(p) \
4122 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4123 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4125 #define ppc_stub_hash_lookup(table, string, create, copy) \
4126 ((struct ppc_stub_hash_entry *) \
4127 bfd_hash_lookup ((table), (string), (create), (copy)))
4129 #define ppc_branch_hash_lookup(table, string, create, copy) \
4130 ((struct ppc_branch_hash_entry *) \
4131 bfd_hash_lookup ((table), (string), (create), (copy)))
4133 /* Create an entry in the stub hash table. */
4135 static struct bfd_hash_entry
*
4136 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
4137 struct bfd_hash_table
*table
,
4140 /* Allocate the structure if it has not already been allocated by a
4144 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
4149 /* Call the allocation method of the superclass. */
4150 entry
= bfd_hash_newfunc (entry
, table
, string
);
4153 struct ppc_stub_hash_entry
*eh
;
4155 /* Initialize the local fields. */
4156 eh
= (struct ppc_stub_hash_entry
*) entry
;
4157 eh
->stub_type
= ppc_stub_none
;
4159 eh
->stub_offset
= 0;
4160 eh
->target_value
= 0;
4161 eh
->target_section
= NULL
;
4170 /* Create an entry in the branch hash table. */
4172 static struct bfd_hash_entry
*
4173 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
4174 struct bfd_hash_table
*table
,
4177 /* Allocate the structure if it has not already been allocated by a
4181 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
4186 /* Call the allocation method of the superclass. */
4187 entry
= bfd_hash_newfunc (entry
, table
, string
);
4190 struct ppc_branch_hash_entry
*eh
;
4192 /* Initialize the local fields. */
4193 eh
= (struct ppc_branch_hash_entry
*) entry
;
4201 /* Create an entry in a ppc64 ELF linker hash table. */
4203 static struct bfd_hash_entry
*
4204 link_hash_newfunc (struct bfd_hash_entry
*entry
,
4205 struct bfd_hash_table
*table
,
4208 /* Allocate the structure if it has not already been allocated by a
4212 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
4217 /* Call the allocation method of the superclass. */
4218 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
4221 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
4223 memset (&eh
->u
.stub_cache
, 0,
4224 (sizeof (struct ppc_link_hash_entry
)
4225 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
4227 /* When making function calls, old ABI code references function entry
4228 points (dot symbols), while new ABI code references the function
4229 descriptor symbol. We need to make any combination of reference and
4230 definition work together, without breaking archive linking.
4232 For a defined function "foo" and an undefined call to "bar":
4233 An old object defines "foo" and ".foo", references ".bar" (possibly
4235 A new object defines "foo" and references "bar".
4237 A new object thus has no problem with its undefined symbols being
4238 satisfied by definitions in an old object. On the other hand, the
4239 old object won't have ".bar" satisfied by a new object.
4241 Keep a list of newly added dot-symbols. */
4243 if (string
[0] == '.')
4245 struct ppc_link_hash_table
*htab
;
4247 htab
= (struct ppc_link_hash_table
*) table
;
4248 eh
->u
.next_dot_sym
= htab
->dot_syms
;
4249 htab
->dot_syms
= eh
;
4256 struct tocsave_entry
{
4262 tocsave_htab_hash (const void *p
)
4264 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
4265 return ((bfd_vma
)(intptr_t) e
->sec
^ e
->offset
) >> 3;
4269 tocsave_htab_eq (const void *p1
, const void *p2
)
4271 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
4272 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
4273 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
4276 /* Destroy a ppc64 ELF linker hash table. */
4279 ppc64_elf_link_hash_table_free (bfd
*obfd
)
4281 struct ppc_link_hash_table
*htab
;
4283 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
4284 if (htab
->tocsave_htab
)
4285 htab_delete (htab
->tocsave_htab
);
4286 bfd_hash_table_free (&htab
->branch_hash_table
);
4287 bfd_hash_table_free (&htab
->stub_hash_table
);
4288 _bfd_elf_link_hash_table_free (obfd
);
4291 /* Create a ppc64 ELF linker hash table. */
4293 static struct bfd_link_hash_table
*
4294 ppc64_elf_link_hash_table_create (bfd
*abfd
)
4296 struct ppc_link_hash_table
*htab
;
4297 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
4299 htab
= bfd_zmalloc (amt
);
4303 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
4304 sizeof (struct ppc_link_hash_entry
),
4311 /* Init the stub hash table too. */
4312 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
4313 sizeof (struct ppc_stub_hash_entry
)))
4315 _bfd_elf_link_hash_table_free (abfd
);
4319 /* And the branch hash table. */
4320 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
4321 sizeof (struct ppc_branch_hash_entry
)))
4323 bfd_hash_table_free (&htab
->stub_hash_table
);
4324 _bfd_elf_link_hash_table_free (abfd
);
4328 htab
->tocsave_htab
= htab_try_create (1024,
4332 if (htab
->tocsave_htab
== NULL
)
4334 ppc64_elf_link_hash_table_free (abfd
);
4337 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
4339 /* Initializing two fields of the union is just cosmetic. We really
4340 only care about glist, but when compiled on a 32-bit host the
4341 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4342 debugger inspection of these fields look nicer. */
4343 htab
->elf
.init_got_refcount
.refcount
= 0;
4344 htab
->elf
.init_got_refcount
.glist
= NULL
;
4345 htab
->elf
.init_plt_refcount
.refcount
= 0;
4346 htab
->elf
.init_plt_refcount
.glist
= NULL
;
4347 htab
->elf
.init_got_offset
.offset
= 0;
4348 htab
->elf
.init_got_offset
.glist
= NULL
;
4349 htab
->elf
.init_plt_offset
.offset
= 0;
4350 htab
->elf
.init_plt_offset
.glist
= NULL
;
4352 return &htab
->elf
.root
;
4355 /* Create sections for linker generated code. */
4358 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4360 struct ppc_link_hash_table
*htab
;
4363 htab
= ppc_hash_table (info
);
4365 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4366 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4367 if (htab
->params
->save_restore_funcs
)
4369 /* Create .sfpr for code to save and restore fp regs. */
4370 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4372 if (htab
->sfpr
== NULL
4373 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4377 if (bfd_link_relocatable (info
))
4380 /* Create .glink for lazy dynamic linking support. */
4381 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4383 if (htab
->glink
== NULL
4384 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4387 if (!info
->no_ld_generated_unwind_info
)
4389 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4390 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4391 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4394 if (htab
->glink_eh_frame
== NULL
4395 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
4399 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4400 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4401 if (htab
->elf
.iplt
== NULL
4402 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
4405 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4406 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4408 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
4409 if (htab
->elf
.irelplt
== NULL
4410 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
4413 /* Create branch lookup table for plt_branch stubs. */
4414 flags
= (SEC_ALLOC
| SEC_LOAD
4415 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4416 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4418 if (htab
->brlt
== NULL
4419 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4422 if (!bfd_link_pic (info
))
4425 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4426 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4427 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4430 if (htab
->relbrlt
== NULL
4431 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4437 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4440 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
4441 struct ppc64_elf_params
*params
)
4443 struct ppc_link_hash_table
*htab
;
4445 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
4447 /* Always hook our dynamic sections into the first bfd, which is the
4448 linker created stub bfd. This ensures that the GOT header is at
4449 the start of the output TOC section. */
4450 htab
= ppc_hash_table (info
);
4451 htab
->elf
.dynobj
= params
->stub_bfd
;
4452 htab
->params
= params
;
4454 return create_linkage_sections (htab
->elf
.dynobj
, info
);
4457 /* Build a name for an entry in the stub hash table. */
4460 ppc_stub_name (const asection
*input_section
,
4461 const asection
*sym_sec
,
4462 const struct ppc_link_hash_entry
*h
,
4463 const Elf_Internal_Rela
*rel
)
4468 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4469 offsets from a sym as a branch target? In fact, we could
4470 probably assume the addend is always zero. */
4471 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4475 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4476 stub_name
= bfd_malloc (len
);
4477 if (stub_name
== NULL
)
4480 len
= sprintf (stub_name
, "%08x.%s+%x",
4481 input_section
->id
& 0xffffffff,
4482 h
->elf
.root
.root
.string
,
4483 (int) rel
->r_addend
& 0xffffffff);
4487 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4488 stub_name
= bfd_malloc (len
);
4489 if (stub_name
== NULL
)
4492 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
4493 input_section
->id
& 0xffffffff,
4494 sym_sec
->id
& 0xffffffff,
4495 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4496 (int) rel
->r_addend
& 0xffffffff);
4498 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4499 stub_name
[len
- 2] = 0;
4503 /* Look up an entry in the stub hash. Stub entries are cached because
4504 creating the stub name takes a bit of time. */
4506 static struct ppc_stub_hash_entry
*
4507 ppc_get_stub_entry (const asection
*input_section
,
4508 const asection
*sym_sec
,
4509 struct ppc_link_hash_entry
*h
,
4510 const Elf_Internal_Rela
*rel
,
4511 struct ppc_link_hash_table
*htab
)
4513 struct ppc_stub_hash_entry
*stub_entry
;
4514 struct map_stub
*group
;
4516 /* If this input section is part of a group of sections sharing one
4517 stub section, then use the id of the first section in the group.
4518 Stub names need to include a section id, as there may well be
4519 more than one stub used to reach say, printf, and we need to
4520 distinguish between them. */
4521 group
= htab
->sec_info
[input_section
->id
].u
.group
;
4525 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4526 && h
->u
.stub_cache
->h
== h
4527 && h
->u
.stub_cache
->group
== group
)
4529 stub_entry
= h
->u
.stub_cache
;
4535 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
4536 if (stub_name
== NULL
)
4539 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4540 stub_name
, FALSE
, FALSE
);
4542 h
->u
.stub_cache
= stub_entry
;
4550 /* Add a new stub entry to the stub hash. Not all fields of the new
4551 stub entry are initialised. */
4553 static struct ppc_stub_hash_entry
*
4554 ppc_add_stub (const char *stub_name
,
4556 struct bfd_link_info
*info
)
4558 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4559 struct map_stub
*group
;
4562 struct ppc_stub_hash_entry
*stub_entry
;
4564 group
= htab
->sec_info
[section
->id
].u
.group
;
4565 link_sec
= group
->link_sec
;
4566 stub_sec
= group
->stub_sec
;
4567 if (stub_sec
== NULL
)
4573 namelen
= strlen (link_sec
->name
);
4574 len
= namelen
+ sizeof (STUB_SUFFIX
);
4575 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
4579 memcpy (s_name
, link_sec
->name
, namelen
);
4580 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4581 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
4582 if (stub_sec
== NULL
)
4584 group
->stub_sec
= stub_sec
;
4587 /* Enter this entry into the linker stub hash table. */
4588 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4590 if (stub_entry
== NULL
)
4592 /* xgettext:c-format */
4593 info
->callbacks
->einfo (_("%P: %B: cannot create stub entry %s\n"),
4594 section
->owner
, stub_name
);
4598 stub_entry
->group
= group
;
4599 stub_entry
->stub_offset
= 0;
4603 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4604 not already done. */
4607 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4609 asection
*got
, *relgot
;
4611 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4613 if (!is_ppc64_elf (abfd
))
4619 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4622 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4623 | SEC_LINKER_CREATED
);
4625 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4627 || !bfd_set_section_alignment (abfd
, got
, 3))
4630 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4631 flags
| SEC_READONLY
);
4633 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4636 ppc64_elf_tdata (abfd
)->got
= got
;
4637 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4641 /* Create the dynamic sections, and set up shortcuts. */
4644 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4646 struct ppc_link_hash_table
*htab
;
4648 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
4651 htab
= ppc_hash_table (info
);
4655 htab
->dynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
4656 if (!bfd_link_pic (info
))
4657 htab
->relbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
4659 if (!htab
->elf
.sgot
|| !htab
->elf
.splt
|| !htab
->elf
.srelplt
|| !htab
->dynbss
4660 || (!bfd_link_pic (info
) && !htab
->relbss
))
4666 /* Follow indirect and warning symbol links. */
4668 static inline struct bfd_link_hash_entry
*
4669 follow_link (struct bfd_link_hash_entry
*h
)
4671 while (h
->type
== bfd_link_hash_indirect
4672 || h
->type
== bfd_link_hash_warning
)
4677 static inline struct elf_link_hash_entry
*
4678 elf_follow_link (struct elf_link_hash_entry
*h
)
4680 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4683 static inline struct ppc_link_hash_entry
*
4684 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4686 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4689 /* Merge PLT info on FROM with that on TO. */
4692 move_plt_plist (struct ppc_link_hash_entry
*from
,
4693 struct ppc_link_hash_entry
*to
)
4695 if (from
->elf
.plt
.plist
!= NULL
)
4697 if (to
->elf
.plt
.plist
!= NULL
)
4699 struct plt_entry
**entp
;
4700 struct plt_entry
*ent
;
4702 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4704 struct plt_entry
*dent
;
4706 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4707 if (dent
->addend
== ent
->addend
)
4709 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4716 *entp
= to
->elf
.plt
.plist
;
4719 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4720 from
->elf
.plt
.plist
= NULL
;
4724 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4727 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4728 struct elf_link_hash_entry
*dir
,
4729 struct elf_link_hash_entry
*ind
)
4731 struct ppc_link_hash_entry
*edir
, *eind
;
4733 edir
= (struct ppc_link_hash_entry
*) dir
;
4734 eind
= (struct ppc_link_hash_entry
*) ind
;
4736 edir
->is_func
|= eind
->is_func
;
4737 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4738 edir
->tls_mask
|= eind
->tls_mask
;
4739 if (eind
->oh
!= NULL
)
4740 edir
->oh
= ppc_follow_link (eind
->oh
);
4742 if (edir
->elf
.versioned
!= versioned_hidden
)
4744 /* If called to transfer flags for a weakdef during processing
4745 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4746 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4747 if (!(ELIMINATE_COPY_RELOCS
4748 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4749 && edir
->elf
.dynamic_adjusted
))
4750 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4752 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4753 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4754 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4755 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4756 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4759 /* If we were called to copy over info for a weak sym, don't copy
4760 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4761 in order to simplify readonly_dynrelocs and save a field in the
4762 symbol hash entry, but that means dyn_relocs can't be used in any
4763 tests about a specific symbol, or affect other symbol flags which
4765 Chain weakdefs so we can get from the weakdef back to an alias.
4766 The list is circular so that we don't need to use u.weakdef as
4767 well as this list to look at all aliases. */
4768 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4770 struct ppc_link_hash_entry
*cur
, *add
, *next
;
4775 cur
= edir
->weakref
;
4780 /* We can be called twice for the same symbols.
4781 Don't make multiple loops. */
4785 } while (cur
!= edir
);
4787 next
= add
->weakref
;
4790 add
->weakref
= edir
->weakref
!= NULL
? edir
->weakref
: edir
;
4791 edir
->weakref
= add
;
4794 } while (add
!= NULL
&& add
!= eind
);
4798 /* Copy over any dynamic relocs we may have on the indirect sym. */
4799 if (eind
->dyn_relocs
!= NULL
)
4801 if (edir
->dyn_relocs
!= NULL
)
4803 struct elf_dyn_relocs
**pp
;
4804 struct elf_dyn_relocs
*p
;
4806 /* Add reloc counts against the indirect sym to the direct sym
4807 list. Merge any entries against the same section. */
4808 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4810 struct elf_dyn_relocs
*q
;
4812 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4813 if (q
->sec
== p
->sec
)
4815 q
->pc_count
+= p
->pc_count
;
4816 q
->count
+= p
->count
;
4823 *pp
= edir
->dyn_relocs
;
4826 edir
->dyn_relocs
= eind
->dyn_relocs
;
4827 eind
->dyn_relocs
= NULL
;
4830 /* Copy over got entries that we may have already seen to the
4831 symbol which just became indirect. */
4832 if (eind
->elf
.got
.glist
!= NULL
)
4834 if (edir
->elf
.got
.glist
!= NULL
)
4836 struct got_entry
**entp
;
4837 struct got_entry
*ent
;
4839 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4841 struct got_entry
*dent
;
4843 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4844 if (dent
->addend
== ent
->addend
4845 && dent
->owner
== ent
->owner
4846 && dent
->tls_type
== ent
->tls_type
)
4848 dent
->got
.refcount
+= ent
->got
.refcount
;
4855 *entp
= edir
->elf
.got
.glist
;
4858 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4859 eind
->elf
.got
.glist
= NULL
;
4862 /* And plt entries. */
4863 move_plt_plist (eind
, edir
);
4865 if (eind
->elf
.dynindx
!= -1)
4867 if (edir
->elf
.dynindx
!= -1)
4868 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4869 edir
->elf
.dynstr_index
);
4870 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4871 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4872 eind
->elf
.dynindx
= -1;
4873 eind
->elf
.dynstr_index
= 0;
4877 /* Find the function descriptor hash entry from the given function code
4878 hash entry FH. Link the entries via their OH fields. */
4880 static struct ppc_link_hash_entry
*
4881 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4883 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4887 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4889 fdh
= (struct ppc_link_hash_entry
*)
4890 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4894 fdh
->is_func_descriptor
= 1;
4900 fdh
= ppc_follow_link (fdh
);
4901 fdh
->is_func_descriptor
= 1;
4906 /* Make a fake function descriptor sym for the undefined code sym FH. */
4908 static struct ppc_link_hash_entry
*
4909 make_fdh (struct bfd_link_info
*info
,
4910 struct ppc_link_hash_entry
*fh
)
4912 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4913 struct bfd_link_hash_entry
*bh
= NULL
;
4914 struct ppc_link_hash_entry
*fdh
;
4915 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4919 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
4920 fh
->elf
.root
.root
.string
+ 1,
4921 flags
, bfd_und_section_ptr
, 0,
4922 NULL
, FALSE
, FALSE
, &bh
))
4925 fdh
= (struct ppc_link_hash_entry
*) bh
;
4926 fdh
->elf
.non_elf
= 0;
4928 fdh
->is_func_descriptor
= 1;
4935 /* Fix function descriptor symbols defined in .opd sections to be
4939 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4940 struct bfd_link_info
*info
,
4941 Elf_Internal_Sym
*isym
,
4943 flagword
*flags ATTRIBUTE_UNUSED
,
4947 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4948 && (ibfd
->flags
& DYNAMIC
) == 0
4949 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
4950 elf_tdata (info
->output_bfd
)->has_gnu_symbols
|= elf_gnu_symbol_ifunc
;
4953 && strcmp ((*sec
)->name
, ".opd") == 0)
4957 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4958 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4959 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4961 /* If the symbol is a function defined in .opd, and the function
4962 code is in a discarded group, let it appear to be undefined. */
4963 if (!bfd_link_relocatable (info
)
4964 && (*sec
)->reloc_count
!= 0
4965 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4966 FALSE
) != (bfd_vma
) -1
4967 && discarded_section (code_sec
))
4969 *sec
= bfd_und_section_ptr
;
4970 isym
->st_shndx
= SHN_UNDEF
;
4973 else if (*sec
!= NULL
4974 && strcmp ((*sec
)->name
, ".toc") == 0
4975 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4977 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4979 htab
->params
->object_in_toc
= 1;
4982 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4984 if (abiversion (ibfd
) == 0)
4985 set_abiversion (ibfd
, 2);
4986 else if (abiversion (ibfd
) == 1)
4988 info
->callbacks
->einfo (_("%P: symbol '%s' has invalid st_other"
4989 " for ABI version 1\n"), name
);
4990 bfd_set_error (bfd_error_bad_value
);
4998 /* Merge non-visibility st_other attributes: local entry point. */
5001 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
5002 const Elf_Internal_Sym
*isym
,
5003 bfd_boolean definition
,
5004 bfd_boolean dynamic
)
5006 if (definition
&& !dynamic
)
5007 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
5008 | ELF_ST_VISIBILITY (h
->other
));
5011 /* Hook called on merging a symbol. We use this to clear "fake" since
5012 we now have a real symbol. */
5015 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
5016 const Elf_Internal_Sym
*isym ATTRIBUTE_UNUSED
,
5017 asection
**psec ATTRIBUTE_UNUSED
,
5018 bfd_boolean newdef ATTRIBUTE_UNUSED
,
5019 bfd_boolean olddef ATTRIBUTE_UNUSED
,
5020 bfd
*oldbfd ATTRIBUTE_UNUSED
,
5021 const asection
*oldsec ATTRIBUTE_UNUSED
)
5023 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
5027 /* This function makes an old ABI object reference to ".bar" cause the
5028 inclusion of a new ABI object archive that defines "bar".
5029 NAME is a symbol defined in an archive. Return a symbol in the hash
5030 table that might be satisfied by the archive symbols. */
5032 static struct elf_link_hash_entry
*
5033 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
5034 struct bfd_link_info
*info
,
5037 struct elf_link_hash_entry
*h
;
5041 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
5043 /* Don't return this sym if it is a fake function descriptor
5044 created by add_symbol_adjust. */
5045 && !((struct ppc_link_hash_entry
*) h
)->fake
)
5051 len
= strlen (name
);
5052 dot_name
= bfd_alloc (abfd
, len
+ 2);
5053 if (dot_name
== NULL
)
5054 return (struct elf_link_hash_entry
*) 0 - 1;
5056 memcpy (dot_name
+ 1, name
, len
+ 1);
5057 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
5058 bfd_release (abfd
, dot_name
);
5062 /* This function satisfies all old ABI object references to ".bar" if a
5063 new ABI object defines "bar". Well, at least, undefined dot symbols
5064 are made weak. This stops later archive searches from including an
5065 object if we already have a function descriptor definition. It also
5066 prevents the linker complaining about undefined symbols.
5067 We also check and correct mismatched symbol visibility here. The
5068 most restrictive visibility of the function descriptor and the
5069 function entry symbol is used. */
5072 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
5074 struct ppc_link_hash_table
*htab
;
5075 struct ppc_link_hash_entry
*fdh
;
5077 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5078 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5080 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
5083 if (eh
->elf
.root
.root
.string
[0] != '.')
5086 htab
= ppc_hash_table (info
);
5090 fdh
= lookup_fdh (eh
, htab
);
5092 && !bfd_link_relocatable (info
)
5093 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
5094 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5095 && eh
->elf
.ref_regular
)
5097 /* Make an undefined function descriptor sym, in order to
5098 pull in an --as-needed shared lib. Archives are handled
5100 fdh
= make_fdh (info
, eh
);
5107 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
5108 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
5110 /* Make both descriptor and entry symbol have the most
5111 constraining visibility of either symbol. */
5112 if (entry_vis
< descr_vis
)
5113 fdh
->elf
.other
+= entry_vis
- descr_vis
;
5114 else if (entry_vis
> descr_vis
)
5115 eh
->elf
.other
+= descr_vis
- entry_vis
;
5117 /* Propagate reference flags from entry symbol to function
5118 descriptor symbol. */
5119 fdh
->elf
.root
.non_ir_ref
|= eh
->elf
.root
.non_ir_ref
;
5120 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
5121 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
5123 if (!fdh
->elf
.forced_local
5124 && fdh
->elf
.dynindx
== -1
5125 && fdh
->elf
.versioned
!= versioned_hidden
5126 && (bfd_link_dll (info
)
5127 || fdh
->elf
.def_dynamic
5128 || fdh
->elf
.ref_dynamic
)
5129 && (eh
->elf
.ref_regular
5130 || eh
->elf
.def_regular
))
5132 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5140 /* Set up opd section info and abiversion for IBFD, and process list
5141 of dot-symbols we made in link_hash_newfunc. */
5144 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
5146 struct ppc_link_hash_table
*htab
;
5147 struct ppc_link_hash_entry
**p
, *eh
;
5148 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
5150 if (opd
!= NULL
&& opd
->size
!= 0)
5152 if (abiversion (ibfd
) == 0)
5153 set_abiversion (ibfd
, 1);
5154 else if (abiversion (ibfd
) >= 2)
5156 /* xgettext:c-format */
5157 info
->callbacks
->einfo (_("%P: %B .opd not allowed in ABI"
5159 ibfd
, abiversion (ibfd
));
5160 bfd_set_error (bfd_error_bad_value
);
5164 if ((ibfd
->flags
& DYNAMIC
) == 0
5165 && (opd
->flags
& SEC_RELOC
) != 0
5166 && opd
->reloc_count
!= 0
5167 && !bfd_is_abs_section (opd
->output_section
))
5169 /* Garbage collection needs some extra help with .opd sections.
5170 We don't want to necessarily keep everything referenced by
5171 relocs in .opd, as that would keep all functions. Instead,
5172 if we reference an .opd symbol (a function descriptor), we
5173 want to keep the function code symbol's section. This is
5174 easy for global symbols, but for local syms we need to keep
5175 information about the associated function section. */
5177 asection
**opd_sym_map
;
5179 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
5180 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
5181 if (opd_sym_map
== NULL
)
5183 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
5184 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
5185 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
5189 if (!is_ppc64_elf (info
->output_bfd
))
5191 htab
= ppc_hash_table (info
);
5195 /* For input files without an explicit abiversion in e_flags
5196 we should have flagged any with symbol st_other bits set
5197 as ELFv1 and above flagged those with .opd as ELFv2.
5198 Set the output abiversion if not yet set, and for any input
5199 still ambiguous, take its abiversion from the output.
5200 Differences in ABI are reported later. */
5201 if (abiversion (info
->output_bfd
) == 0)
5202 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
5203 else if (abiversion (ibfd
) == 0)
5204 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
5206 p
= &htab
->dot_syms
;
5207 while ((eh
= *p
) != NULL
)
5210 if (&eh
->elf
== htab
->elf
.hgot
)
5212 else if (htab
->elf
.hgot
== NULL
5213 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
5214 htab
->elf
.hgot
= &eh
->elf
;
5215 else if (abiversion (ibfd
) <= 1)
5217 htab
->need_func_desc_adj
= 1;
5218 if (!add_symbol_adjust (eh
, info
))
5221 p
= &eh
->u
.next_dot_sym
;
5226 /* Undo hash table changes when an --as-needed input file is determined
5227 not to be needed. */
5230 ppc64_elf_notice_as_needed (bfd
*ibfd
,
5231 struct bfd_link_info
*info
,
5232 enum notice_asneeded_action act
)
5234 if (act
== notice_not_needed
)
5236 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5241 htab
->dot_syms
= NULL
;
5243 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
5246 /* If --just-symbols against a final linked binary, then assume we need
5247 toc adjusting stubs when calling functions defined there. */
5250 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
5252 if ((sec
->flags
& SEC_CODE
) != 0
5253 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
5254 && is_ppc64_elf (sec
->owner
))
5256 if (abiversion (sec
->owner
) >= 2
5257 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
5258 sec
->has_toc_reloc
= 1;
5260 _bfd_elf_link_just_syms (sec
, info
);
5263 static struct plt_entry
**
5264 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
5265 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
5267 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
5268 struct plt_entry
**local_plt
;
5269 unsigned char *local_got_tls_masks
;
5271 if (local_got_ents
== NULL
)
5273 bfd_size_type size
= symtab_hdr
->sh_info
;
5275 size
*= (sizeof (*local_got_ents
)
5276 + sizeof (*local_plt
)
5277 + sizeof (*local_got_tls_masks
));
5278 local_got_ents
= bfd_zalloc (abfd
, size
);
5279 if (local_got_ents
== NULL
)
5281 elf_local_got_ents (abfd
) = local_got_ents
;
5284 if ((tls_type
& (PLT_IFUNC
| TLS_EXPLICIT
)) == 0)
5286 struct got_entry
*ent
;
5288 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
5289 if (ent
->addend
== r_addend
5290 && ent
->owner
== abfd
5291 && ent
->tls_type
== tls_type
)
5295 bfd_size_type amt
= sizeof (*ent
);
5296 ent
= bfd_alloc (abfd
, amt
);
5299 ent
->next
= local_got_ents
[r_symndx
];
5300 ent
->addend
= r_addend
;
5302 ent
->tls_type
= tls_type
;
5303 ent
->is_indirect
= FALSE
;
5304 ent
->got
.refcount
= 0;
5305 local_got_ents
[r_symndx
] = ent
;
5307 ent
->got
.refcount
+= 1;
5310 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
5311 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
5312 local_got_tls_masks
[r_symndx
] |= tls_type
;
5314 return local_plt
+ r_symndx
;
5318 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
5320 struct plt_entry
*ent
;
5322 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
5323 if (ent
->addend
== addend
)
5327 bfd_size_type amt
= sizeof (*ent
);
5328 ent
= bfd_alloc (abfd
, amt
);
5332 ent
->addend
= addend
;
5333 ent
->plt
.refcount
= 0;
5336 ent
->plt
.refcount
+= 1;
5341 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
5343 return (r_type
== R_PPC64_REL24
5344 || r_type
== R_PPC64_REL14
5345 || r_type
== R_PPC64_REL14_BRTAKEN
5346 || r_type
== R_PPC64_REL14_BRNTAKEN
5347 || r_type
== R_PPC64_ADDR24
5348 || r_type
== R_PPC64_ADDR14
5349 || r_type
== R_PPC64_ADDR14_BRTAKEN
5350 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
5353 /* Look through the relocs for a section during the first phase, and
5354 calculate needed space in the global offset table, procedure
5355 linkage table, and dynamic reloc sections. */
5358 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5359 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5361 struct ppc_link_hash_table
*htab
;
5362 Elf_Internal_Shdr
*symtab_hdr
;
5363 struct elf_link_hash_entry
**sym_hashes
;
5364 const Elf_Internal_Rela
*rel
;
5365 const Elf_Internal_Rela
*rel_end
;
5367 asection
**opd_sym_map
;
5368 struct elf_link_hash_entry
*tga
, *dottga
;
5370 if (bfd_link_relocatable (info
))
5373 /* Don't do anything special with non-loaded, non-alloced sections.
5374 In particular, any relocs in such sections should not affect GOT
5375 and PLT reference counting (ie. we don't allow them to create GOT
5376 or PLT entries), there's no possibility or desire to optimize TLS
5377 relocs, and there's not much point in propagating relocs to shared
5378 libs that the dynamic linker won't relocate. */
5379 if ((sec
->flags
& SEC_ALLOC
) == 0)
5382 BFD_ASSERT (is_ppc64_elf (abfd
));
5384 htab
= ppc_hash_table (info
);
5388 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
5389 FALSE
, FALSE
, TRUE
);
5390 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
5391 FALSE
, FALSE
, TRUE
);
5392 symtab_hdr
= &elf_symtab_hdr (abfd
);
5393 sym_hashes
= elf_sym_hashes (abfd
);
5396 if (ppc64_elf_section_data (sec
) != NULL
5397 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
5398 opd_sym_map
= ppc64_elf_section_data (sec
)->u
.opd
.func_sec
;
5400 rel_end
= relocs
+ sec
->reloc_count
;
5401 for (rel
= relocs
; rel
< rel_end
; rel
++)
5403 unsigned long r_symndx
;
5404 struct elf_link_hash_entry
*h
;
5405 enum elf_ppc64_reloc_type r_type
;
5407 struct _ppc64_elf_section_data
*ppc64_sec
;
5408 struct plt_entry
**ifunc
, **plt_list
;
5410 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5411 if (r_symndx
< symtab_hdr
->sh_info
)
5415 struct ppc_link_hash_entry
*eh
;
5417 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5418 h
= elf_follow_link (h
);
5419 eh
= (struct ppc_link_hash_entry
*) h
;
5421 /* PR15323, ref flags aren't set for references in the same
5423 h
->root
.non_ir_ref
= 1;
5424 if (eh
->is_func
&& eh
->oh
!= NULL
)
5425 eh
->oh
->elf
.root
.non_ir_ref
= 1;
5427 if (h
== htab
->elf
.hgot
)
5428 sec
->has_toc_reloc
= 1;
5435 if (h
->type
== STT_GNU_IFUNC
)
5438 ifunc
= &h
->plt
.plist
;
5443 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5448 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5450 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5451 rel
->r_addend
, PLT_IFUNC
);
5457 r_type
= ELF64_R_TYPE (rel
->r_info
);
5462 /* These special tls relocs tie a call to __tls_get_addr with
5463 its parameter symbol. */
5466 case R_PPC64_GOT_TLSLD16
:
5467 case R_PPC64_GOT_TLSLD16_LO
:
5468 case R_PPC64_GOT_TLSLD16_HI
:
5469 case R_PPC64_GOT_TLSLD16_HA
:
5470 tls_type
= TLS_TLS
| TLS_LD
;
5473 case R_PPC64_GOT_TLSGD16
:
5474 case R_PPC64_GOT_TLSGD16_LO
:
5475 case R_PPC64_GOT_TLSGD16_HI
:
5476 case R_PPC64_GOT_TLSGD16_HA
:
5477 tls_type
= TLS_TLS
| TLS_GD
;
5480 case R_PPC64_GOT_TPREL16_DS
:
5481 case R_PPC64_GOT_TPREL16_LO_DS
:
5482 case R_PPC64_GOT_TPREL16_HI
:
5483 case R_PPC64_GOT_TPREL16_HA
:
5484 if (bfd_link_pic (info
))
5485 info
->flags
|= DF_STATIC_TLS
;
5486 tls_type
= TLS_TLS
| TLS_TPREL
;
5489 case R_PPC64_GOT_DTPREL16_DS
:
5490 case R_PPC64_GOT_DTPREL16_LO_DS
:
5491 case R_PPC64_GOT_DTPREL16_HI
:
5492 case R_PPC64_GOT_DTPREL16_HA
:
5493 tls_type
= TLS_TLS
| TLS_DTPREL
;
5495 sec
->has_tls_reloc
= 1;
5499 case R_PPC64_GOT16_DS
:
5500 case R_PPC64_GOT16_HA
:
5501 case R_PPC64_GOT16_HI
:
5502 case R_PPC64_GOT16_LO
:
5503 case R_PPC64_GOT16_LO_DS
:
5504 /* This symbol requires a global offset table entry. */
5505 sec
->has_toc_reloc
= 1;
5506 if (r_type
== R_PPC64_GOT_TLSLD16
5507 || r_type
== R_PPC64_GOT_TLSGD16
5508 || r_type
== R_PPC64_GOT_TPREL16_DS
5509 || r_type
== R_PPC64_GOT_DTPREL16_DS
5510 || r_type
== R_PPC64_GOT16
5511 || r_type
== R_PPC64_GOT16_DS
)
5513 htab
->do_multi_toc
= 1;
5514 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5517 if (ppc64_elf_tdata (abfd
)->got
== NULL
5518 && !create_got_section (abfd
, info
))
5523 struct ppc_link_hash_entry
*eh
;
5524 struct got_entry
*ent
;
5526 eh
= (struct ppc_link_hash_entry
*) h
;
5527 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5528 if (ent
->addend
== rel
->r_addend
5529 && ent
->owner
== abfd
5530 && ent
->tls_type
== tls_type
)
5534 bfd_size_type amt
= sizeof (*ent
);
5535 ent
= bfd_alloc (abfd
, amt
);
5538 ent
->next
= eh
->elf
.got
.glist
;
5539 ent
->addend
= rel
->r_addend
;
5541 ent
->tls_type
= tls_type
;
5542 ent
->is_indirect
= FALSE
;
5543 ent
->got
.refcount
= 0;
5544 eh
->elf
.got
.glist
= ent
;
5546 ent
->got
.refcount
+= 1;
5547 eh
->tls_mask
|= tls_type
;
5550 /* This is a global offset table entry for a local symbol. */
5551 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5552 rel
->r_addend
, tls_type
))
5555 /* We may also need a plt entry if the symbol turns out to be
5557 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
5559 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5564 case R_PPC64_PLT16_HA
:
5565 case R_PPC64_PLT16_HI
:
5566 case R_PPC64_PLT16_LO
:
5569 /* This symbol requires a procedure linkage table entry. */
5574 if (h
->root
.root
.string
[0] == '.'
5575 && h
->root
.root
.string
[1] != '\0')
5576 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5577 plt_list
= &h
->plt
.plist
;
5579 if (plt_list
== NULL
)
5581 /* It does not make sense to have a procedure linkage
5582 table entry for a non-ifunc local symbol. */
5583 info
->callbacks
->einfo
5584 /* xgettext:c-format */
5585 (_("%P: %H: %s reloc against local symbol\n"),
5586 abfd
, sec
, rel
->r_offset
,
5587 ppc64_elf_howto_table
[r_type
]->name
);
5588 bfd_set_error (bfd_error_bad_value
);
5591 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5595 /* The following relocations don't need to propagate the
5596 relocation if linking a shared object since they are
5597 section relative. */
5598 case R_PPC64_SECTOFF
:
5599 case R_PPC64_SECTOFF_LO
:
5600 case R_PPC64_SECTOFF_HI
:
5601 case R_PPC64_SECTOFF_HA
:
5602 case R_PPC64_SECTOFF_DS
:
5603 case R_PPC64_SECTOFF_LO_DS
:
5604 case R_PPC64_DTPREL16
:
5605 case R_PPC64_DTPREL16_LO
:
5606 case R_PPC64_DTPREL16_HI
:
5607 case R_PPC64_DTPREL16_HA
:
5608 case R_PPC64_DTPREL16_DS
:
5609 case R_PPC64_DTPREL16_LO_DS
:
5610 case R_PPC64_DTPREL16_HIGH
:
5611 case R_PPC64_DTPREL16_HIGHA
:
5612 case R_PPC64_DTPREL16_HIGHER
:
5613 case R_PPC64_DTPREL16_HIGHERA
:
5614 case R_PPC64_DTPREL16_HIGHEST
:
5615 case R_PPC64_DTPREL16_HIGHESTA
:
5620 case R_PPC64_REL16_LO
:
5621 case R_PPC64_REL16_HI
:
5622 case R_PPC64_REL16_HA
:
5623 case R_PPC64_REL16DX_HA
:
5626 /* Not supported as a dynamic relocation. */
5627 case R_PPC64_ADDR64_LOCAL
:
5628 if (bfd_link_pic (info
))
5630 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5632 /* xgettext:c-format */
5633 info
->callbacks
->einfo (_("%P: %H: %s reloc unsupported "
5634 "in shared libraries and PIEs.\n"),
5635 abfd
, sec
, rel
->r_offset
,
5636 ppc64_elf_howto_table
[r_type
]->name
);
5637 bfd_set_error (bfd_error_bad_value
);
5643 case R_PPC64_TOC16_DS
:
5644 htab
->do_multi_toc
= 1;
5645 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5647 case R_PPC64_TOC16_LO
:
5648 case R_PPC64_TOC16_HI
:
5649 case R_PPC64_TOC16_HA
:
5650 case R_PPC64_TOC16_LO_DS
:
5651 sec
->has_toc_reloc
= 1;
5658 /* This relocation describes the C++ object vtable hierarchy.
5659 Reconstruct it for later use during GC. */
5660 case R_PPC64_GNU_VTINHERIT
:
5661 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5665 /* This relocation describes which C++ vtable entries are actually
5666 used. Record for later use during GC. */
5667 case R_PPC64_GNU_VTENTRY
:
5668 BFD_ASSERT (h
!= NULL
);
5670 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5675 case R_PPC64_REL14_BRTAKEN
:
5676 case R_PPC64_REL14_BRNTAKEN
:
5678 asection
*dest
= NULL
;
5680 /* Heuristic: If jumping outside our section, chances are
5681 we are going to need a stub. */
5684 /* If the sym is weak it may be overridden later, so
5685 don't assume we know where a weak sym lives. */
5686 if (h
->root
.type
== bfd_link_hash_defined
)
5687 dest
= h
->root
.u
.def
.section
;
5691 Elf_Internal_Sym
*isym
;
5693 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5698 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5702 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5711 if (h
->root
.root
.string
[0] == '.'
5712 && h
->root
.root
.string
[1] != '\0')
5713 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5715 if (h
== tga
|| h
== dottga
)
5717 sec
->has_tls_reloc
= 1;
5719 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5720 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5721 /* We have a new-style __tls_get_addr call with
5725 /* Mark this section as having an old-style call. */
5726 sec
->has_tls_get_addr_call
= 1;
5728 plt_list
= &h
->plt
.plist
;
5731 /* We may need a .plt entry if the function this reloc
5732 refers to is in a shared lib. */
5734 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5738 case R_PPC64_ADDR14
:
5739 case R_PPC64_ADDR14_BRNTAKEN
:
5740 case R_PPC64_ADDR14_BRTAKEN
:
5741 case R_PPC64_ADDR24
:
5744 case R_PPC64_TPREL64
:
5745 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5746 if (bfd_link_pic (info
))
5747 info
->flags
|= DF_STATIC_TLS
;
5750 case R_PPC64_DTPMOD64
:
5751 if (rel
+ 1 < rel_end
5752 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5753 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5754 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5756 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5759 case R_PPC64_DTPREL64
:
5760 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5762 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5763 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5764 /* This is the second reloc of a dtpmod, dtprel pair.
5765 Don't mark with TLS_DTPREL. */
5769 sec
->has_tls_reloc
= 1;
5772 struct ppc_link_hash_entry
*eh
;
5773 eh
= (struct ppc_link_hash_entry
*) h
;
5774 eh
->tls_mask
|= tls_type
;
5777 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5778 rel
->r_addend
, tls_type
))
5781 ppc64_sec
= ppc64_elf_section_data (sec
);
5782 if (ppc64_sec
->sec_type
!= sec_toc
)
5786 /* One extra to simplify get_tls_mask. */
5787 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5788 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5789 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5791 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5792 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5793 if (ppc64_sec
->u
.toc
.add
== NULL
)
5795 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5796 ppc64_sec
->sec_type
= sec_toc
;
5798 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5799 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5800 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5802 /* Mark the second slot of a GD or LD entry.
5803 -1 to indicate GD and -2 to indicate LD. */
5804 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5805 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5806 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5807 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5810 case R_PPC64_TPREL16
:
5811 case R_PPC64_TPREL16_LO
:
5812 case R_PPC64_TPREL16_HI
:
5813 case R_PPC64_TPREL16_HA
:
5814 case R_PPC64_TPREL16_DS
:
5815 case R_PPC64_TPREL16_LO_DS
:
5816 case R_PPC64_TPREL16_HIGH
:
5817 case R_PPC64_TPREL16_HIGHA
:
5818 case R_PPC64_TPREL16_HIGHER
:
5819 case R_PPC64_TPREL16_HIGHERA
:
5820 case R_PPC64_TPREL16_HIGHEST
:
5821 case R_PPC64_TPREL16_HIGHESTA
:
5822 if (bfd_link_pic (info
))
5824 info
->flags
|= DF_STATIC_TLS
;
5829 case R_PPC64_ADDR64
:
5830 if (opd_sym_map
!= NULL
5831 && rel
+ 1 < rel_end
5832 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5835 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5839 Elf_Internal_Sym
*isym
;
5841 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5846 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5847 if (s
!= NULL
&& s
!= sec
)
5848 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
5853 case R_PPC64_ADDR16
:
5854 case R_PPC64_ADDR16_DS
:
5855 case R_PPC64_ADDR16_HA
:
5856 case R_PPC64_ADDR16_HI
:
5857 case R_PPC64_ADDR16_HIGH
:
5858 case R_PPC64_ADDR16_HIGHA
:
5859 case R_PPC64_ADDR16_HIGHER
:
5860 case R_PPC64_ADDR16_HIGHERA
:
5861 case R_PPC64_ADDR16_HIGHEST
:
5862 case R_PPC64_ADDR16_HIGHESTA
:
5863 case R_PPC64_ADDR16_LO
:
5864 case R_PPC64_ADDR16_LO_DS
:
5865 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5866 && rel
->r_addend
== 0)
5868 /* We may need a .plt entry if this reloc refers to a
5869 function in a shared lib. */
5870 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5872 h
->pointer_equality_needed
= 1;
5879 case R_PPC64_ADDR32
:
5880 case R_PPC64_UADDR16
:
5881 case R_PPC64_UADDR32
:
5882 case R_PPC64_UADDR64
:
5884 if (h
!= NULL
&& !bfd_link_pic (info
))
5885 /* We may need a copy reloc. */
5888 /* Don't propagate .opd relocs. */
5889 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
5892 /* If we are creating a shared library, and this is a reloc
5893 against a global symbol, or a non PC relative reloc
5894 against a local symbol, then we need to copy the reloc
5895 into the shared library. However, if we are linking with
5896 -Bsymbolic, we do not need to copy a reloc against a
5897 global symbol which is defined in an object we are
5898 including in the link (i.e., DEF_REGULAR is set). At
5899 this point we have not seen all the input files, so it is
5900 possible that DEF_REGULAR is not set now but will be set
5901 later (it is never cleared). In case of a weak definition,
5902 DEF_REGULAR may be cleared later by a strong definition in
5903 a shared library. We account for that possibility below by
5904 storing information in the dyn_relocs field of the hash
5905 table entry. A similar situation occurs when creating
5906 shared libraries and symbol visibility changes render the
5909 If on the other hand, we are creating an executable, we
5910 may need to keep relocations for symbols satisfied by a
5911 dynamic library if we manage to avoid copy relocs for the
5914 if ((bfd_link_pic (info
)
5915 && (must_be_dyn_reloc (info
, r_type
)
5917 && (!SYMBOLIC_BIND (info
, h
)
5918 || h
->root
.type
== bfd_link_hash_defweak
5919 || !h
->def_regular
))))
5920 || (ELIMINATE_COPY_RELOCS
5921 && !bfd_link_pic (info
)
5923 && (h
->root
.type
== bfd_link_hash_defweak
5924 || !h
->def_regular
))
5925 || (!bfd_link_pic (info
)
5928 /* We must copy these reloc types into the output file.
5929 Create a reloc section in dynobj and make room for
5933 sreloc
= _bfd_elf_make_dynamic_reloc_section
5934 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5940 /* If this is a global symbol, we count the number of
5941 relocations we need for this symbol. */
5944 struct elf_dyn_relocs
*p
;
5945 struct elf_dyn_relocs
**head
;
5947 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5949 if (p
== NULL
|| p
->sec
!= sec
)
5951 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5961 if (!must_be_dyn_reloc (info
, r_type
))
5966 /* Track dynamic relocs needed for local syms too.
5967 We really need local syms available to do this
5969 struct ppc_dyn_relocs
*p
;
5970 struct ppc_dyn_relocs
**head
;
5971 bfd_boolean is_ifunc
;
5974 Elf_Internal_Sym
*isym
;
5976 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5981 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5985 vpp
= &elf_section_data (s
)->local_dynrel
;
5986 head
= (struct ppc_dyn_relocs
**) vpp
;
5987 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5989 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5991 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5993 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5999 p
->ifunc
= is_ifunc
;
6015 /* Merge backend specific data from an object file to the output
6016 object file when linking. */
6019 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6021 bfd
*obfd
= info
->output_bfd
;
6022 unsigned long iflags
, oflags
;
6024 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
6027 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
6030 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6033 iflags
= elf_elfheader (ibfd
)->e_flags
;
6034 oflags
= elf_elfheader (obfd
)->e_flags
;
6036 if (iflags
& ~EF_PPC64_ABI
)
6039 /* xgettext:c-format */
6040 (_("%B uses unknown e_flags 0x%lx"), ibfd
, iflags
);
6041 bfd_set_error (bfd_error_bad_value
);
6044 else if (iflags
!= oflags
&& iflags
!= 0)
6047 /* xgettext:c-format */
6048 (_("%B: ABI version %ld is not compatible with ABI version %ld output"),
6049 ibfd
, iflags
, oflags
);
6050 bfd_set_error (bfd_error_bad_value
);
6054 _bfd_elf_ppc_merge_fp_attributes (ibfd
, info
);
6056 /* Merge Tag_compatibility attributes and any common GNU ones. */
6057 _bfd_elf_merge_object_attributes (ibfd
, info
);
6063 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6065 /* Print normal ELF private data. */
6066 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6068 if (elf_elfheader (abfd
)->e_flags
!= 0)
6072 fprintf (file
, _("private flags = 0x%lx:"),
6073 elf_elfheader (abfd
)->e_flags
);
6075 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
6076 fprintf (file
, _(" [abiv%ld]"),
6077 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
6084 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
6085 of the code entry point, and its section, which must be in the same
6086 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
6089 opd_entry_value (asection
*opd_sec
,
6091 asection
**code_sec
,
6093 bfd_boolean in_code_sec
)
6095 bfd
*opd_bfd
= opd_sec
->owner
;
6096 Elf_Internal_Rela
*relocs
;
6097 Elf_Internal_Rela
*lo
, *hi
, *look
;
6100 /* No relocs implies we are linking a --just-symbols object, or looking
6101 at a final linked executable with addr2line or somesuch. */
6102 if (opd_sec
->reloc_count
== 0)
6104 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
6106 if (contents
== NULL
)
6108 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
6109 return (bfd_vma
) -1;
6110 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
6113 /* PR 17512: file: 64b9dfbb. */
6114 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
6115 return (bfd_vma
) -1;
6117 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
6118 if (code_sec
!= NULL
)
6120 asection
*sec
, *likely
= NULL
;
6126 && val
< sec
->vma
+ sec
->size
)
6132 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6134 && (sec
->flags
& SEC_LOAD
) != 0
6135 && (sec
->flags
& SEC_ALLOC
) != 0)
6140 if (code_off
!= NULL
)
6141 *code_off
= val
- likely
->vma
;
6147 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
6149 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
6151 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
6152 /* PR 17512: file: df8e1fd6. */
6154 return (bfd_vma
) -1;
6156 /* Go find the opd reloc at the sym address. */
6158 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
6162 look
= lo
+ (hi
- lo
) / 2;
6163 if (look
->r_offset
< offset
)
6165 else if (look
->r_offset
> offset
)
6169 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
6171 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
6172 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
6174 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
6175 asection
*sec
= NULL
;
6177 if (symndx
>= symtab_hdr
->sh_info
6178 && elf_sym_hashes (opd_bfd
) != NULL
)
6180 struct elf_link_hash_entry
**sym_hashes
;
6181 struct elf_link_hash_entry
*rh
;
6183 sym_hashes
= elf_sym_hashes (opd_bfd
);
6184 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
6187 rh
= elf_follow_link (rh
);
6188 if (rh
->root
.type
!= bfd_link_hash_defined
6189 && rh
->root
.type
!= bfd_link_hash_defweak
)
6191 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
6193 val
= rh
->root
.u
.def
.value
;
6194 sec
= rh
->root
.u
.def
.section
;
6201 Elf_Internal_Sym
*sym
;
6203 if (symndx
< symtab_hdr
->sh_info
)
6205 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6208 size_t symcnt
= symtab_hdr
->sh_info
;
6209 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6214 symtab_hdr
->contents
= (bfd_byte
*) sym
;
6220 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6226 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
6229 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
6230 val
= sym
->st_value
;
6233 val
+= look
->r_addend
;
6234 if (code_off
!= NULL
)
6236 if (code_sec
!= NULL
)
6238 if (in_code_sec
&& *code_sec
!= sec
)
6243 if (sec
->output_section
!= NULL
)
6244 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
6253 /* If the ELF symbol SYM might be a function in SEC, return the
6254 function size and set *CODE_OFF to the function's entry point,
6255 otherwise return zero. */
6257 static bfd_size_type
6258 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
6263 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
6264 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
6268 if (!(sym
->flags
& BSF_SYNTHETIC
))
6269 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
6271 if (strcmp (sym
->section
->name
, ".opd") == 0)
6273 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
6274 bfd_vma symval
= sym
->value
;
6277 && opd
->adjust
!= NULL
6278 && elf_section_data (sym
->section
)->relocs
!= NULL
)
6280 /* opd_entry_value will use cached relocs that have been
6281 adjusted, but with raw symbols. That means both local
6282 and global symbols need adjusting. */
6283 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
6289 if (opd_entry_value (sym
->section
, symval
,
6290 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
6292 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6293 symbol. This size has nothing to do with the code size of the
6294 function, which is what we're supposed to return, but the
6295 code size isn't available without looking up the dot-sym.
6296 However, doing that would be a waste of time particularly
6297 since elf_find_function will look at the dot-sym anyway.
6298 Now, elf_find_function will keep the largest size of any
6299 function sym found at the code address of interest, so return
6300 1 here to avoid it incorrectly caching a larger function size
6301 for a small function. This does mean we return the wrong
6302 size for a new-ABI function of size 24, but all that does is
6303 disable caching for such functions. */
6309 if (sym
->section
!= sec
)
6311 *code_off
= sym
->value
;
6318 /* Return true if symbol is defined in a regular object file. */
6321 is_static_defined (struct elf_link_hash_entry
*h
)
6323 return ((h
->root
.type
== bfd_link_hash_defined
6324 || h
->root
.type
== bfd_link_hash_defweak
)
6325 && h
->root
.u
.def
.section
!= NULL
6326 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6329 /* If FDH is a function descriptor symbol, return the associated code
6330 entry symbol if it is defined. Return NULL otherwise. */
6332 static struct ppc_link_hash_entry
*
6333 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
6335 if (fdh
->is_func_descriptor
)
6337 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
6338 if (fh
->elf
.root
.type
== bfd_link_hash_defined
6339 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6345 /* If FH is a function code entry symbol, return the associated
6346 function descriptor symbol if it is defined. Return NULL otherwise. */
6348 static struct ppc_link_hash_entry
*
6349 defined_func_desc (struct ppc_link_hash_entry
*fh
)
6352 && fh
->oh
->is_func_descriptor
)
6354 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
6355 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
6356 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6362 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
6364 /* Garbage collect sections, after first dealing with dot-symbols. */
6367 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6369 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6371 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
6373 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6374 htab
->need_func_desc_adj
= 0;
6376 return bfd_elf_gc_sections (abfd
, info
);
6379 /* Mark all our entry sym sections, both opd and code section. */
6382 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
6384 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6385 struct bfd_sym_chain
*sym
;
6390 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
6392 struct ppc_link_hash_entry
*eh
, *fh
;
6395 eh
= (struct ppc_link_hash_entry
*)
6396 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
6399 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
6400 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6403 fh
= defined_code_entry (eh
);
6406 sec
= fh
->elf
.root
.u
.def
.section
;
6407 sec
->flags
|= SEC_KEEP
;
6409 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6410 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6411 eh
->elf
.root
.u
.def
.value
,
6412 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6413 sec
->flags
|= SEC_KEEP
;
6415 sec
= eh
->elf
.root
.u
.def
.section
;
6416 sec
->flags
|= SEC_KEEP
;
6420 /* Mark sections containing dynamically referenced symbols. When
6421 building shared libraries, we must assume that any visible symbol is
6425 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
6427 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6428 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
6429 struct ppc_link_hash_entry
*fdh
;
6430 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
6432 /* Dynamic linking info is on the func descriptor sym. */
6433 fdh
= defined_func_desc (eh
);
6437 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
6438 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
6439 && (eh
->elf
.ref_dynamic
6440 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
6441 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
6442 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
6443 && (!bfd_link_executable (info
)
6444 || info
->export_dynamic
6447 && (*d
->match
) (&d
->head
, NULL
, eh
->elf
.root
.root
.string
)))
6448 && (strchr (eh
->elf
.root
.root
.string
, ELF_VER_CHR
) != NULL
6449 || !bfd_hide_sym_by_version (info
->version_info
,
6450 eh
->elf
.root
.root
.string
)))))
6453 struct ppc_link_hash_entry
*fh
;
6455 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
6457 /* Function descriptor syms cause the associated
6458 function code sym section to be marked. */
6459 fh
= defined_code_entry (eh
);
6462 code_sec
= fh
->elf
.root
.u
.def
.section
;
6463 code_sec
->flags
|= SEC_KEEP
;
6465 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6466 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6467 eh
->elf
.root
.u
.def
.value
,
6468 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6469 code_sec
->flags
|= SEC_KEEP
;
6475 /* Return the section that should be marked against GC for a given
6479 ppc64_elf_gc_mark_hook (asection
*sec
,
6480 struct bfd_link_info
*info
,
6481 Elf_Internal_Rela
*rel
,
6482 struct elf_link_hash_entry
*h
,
6483 Elf_Internal_Sym
*sym
)
6487 /* Syms return NULL if we're marking .opd, so we avoid marking all
6488 function sections, as all functions are referenced in .opd. */
6490 if (get_opd_info (sec
) != NULL
)
6495 enum elf_ppc64_reloc_type r_type
;
6496 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
6498 r_type
= ELF64_R_TYPE (rel
->r_info
);
6501 case R_PPC64_GNU_VTINHERIT
:
6502 case R_PPC64_GNU_VTENTRY
:
6506 switch (h
->root
.type
)
6508 case bfd_link_hash_defined
:
6509 case bfd_link_hash_defweak
:
6510 eh
= (struct ppc_link_hash_entry
*) h
;
6511 fdh
= defined_func_desc (eh
);
6514 /* -mcall-aixdesc code references the dot-symbol on
6515 a call reloc. Mark the function descriptor too
6516 against garbage collection. */
6518 if (fdh
->elf
.u
.weakdef
!= NULL
)
6519 fdh
->elf
.u
.weakdef
->mark
= 1;
6523 /* Function descriptor syms cause the associated
6524 function code sym section to be marked. */
6525 fh
= defined_code_entry (eh
);
6528 /* They also mark their opd section. */
6529 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6531 rsec
= fh
->elf
.root
.u
.def
.section
;
6533 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6534 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6535 eh
->elf
.root
.u
.def
.value
,
6536 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
6537 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6539 rsec
= h
->root
.u
.def
.section
;
6542 case bfd_link_hash_common
:
6543 rsec
= h
->root
.u
.c
.p
->section
;
6547 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6553 struct _opd_sec_data
*opd
;
6555 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6556 opd
= get_opd_info (rsec
);
6557 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6561 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6568 /* Update the .got, .plt. and dynamic reloc reference counts for the
6569 section being removed. */
6572 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6573 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6575 struct ppc_link_hash_table
*htab
;
6576 Elf_Internal_Shdr
*symtab_hdr
;
6577 struct elf_link_hash_entry
**sym_hashes
;
6578 struct got_entry
**local_got_ents
;
6579 const Elf_Internal_Rela
*rel
, *relend
;
6581 if (bfd_link_relocatable (info
))
6584 if ((sec
->flags
& SEC_ALLOC
) == 0)
6587 elf_section_data (sec
)->local_dynrel
= NULL
;
6589 htab
= ppc_hash_table (info
);
6593 symtab_hdr
= &elf_symtab_hdr (abfd
);
6594 sym_hashes
= elf_sym_hashes (abfd
);
6595 local_got_ents
= elf_local_got_ents (abfd
);
6597 relend
= relocs
+ sec
->reloc_count
;
6598 for (rel
= relocs
; rel
< relend
; rel
++)
6600 unsigned long r_symndx
;
6601 enum elf_ppc64_reloc_type r_type
;
6602 struct elf_link_hash_entry
*h
= NULL
;
6603 struct plt_entry
**plt_list
;
6604 unsigned char tls_type
= 0;
6606 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6607 r_type
= ELF64_R_TYPE (rel
->r_info
);
6608 if (r_symndx
>= symtab_hdr
->sh_info
)
6610 struct ppc_link_hash_entry
*eh
;
6611 struct elf_dyn_relocs
**pp
;
6612 struct elf_dyn_relocs
*p
;
6614 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6615 h
= elf_follow_link (h
);
6616 eh
= (struct ppc_link_hash_entry
*) h
;
6618 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6621 /* Everything must go for SEC. */
6629 case R_PPC64_GOT_TLSLD16
:
6630 case R_PPC64_GOT_TLSLD16_LO
:
6631 case R_PPC64_GOT_TLSLD16_HI
:
6632 case R_PPC64_GOT_TLSLD16_HA
:
6633 tls_type
= TLS_TLS
| TLS_LD
;
6636 case R_PPC64_GOT_TLSGD16
:
6637 case R_PPC64_GOT_TLSGD16_LO
:
6638 case R_PPC64_GOT_TLSGD16_HI
:
6639 case R_PPC64_GOT_TLSGD16_HA
:
6640 tls_type
= TLS_TLS
| TLS_GD
;
6643 case R_PPC64_GOT_TPREL16_DS
:
6644 case R_PPC64_GOT_TPREL16_LO_DS
:
6645 case R_PPC64_GOT_TPREL16_HI
:
6646 case R_PPC64_GOT_TPREL16_HA
:
6647 tls_type
= TLS_TLS
| TLS_TPREL
;
6650 case R_PPC64_GOT_DTPREL16_DS
:
6651 case R_PPC64_GOT_DTPREL16_LO_DS
:
6652 case R_PPC64_GOT_DTPREL16_HI
:
6653 case R_PPC64_GOT_DTPREL16_HA
:
6654 tls_type
= TLS_TLS
| TLS_DTPREL
;
6658 case R_PPC64_GOT16_DS
:
6659 case R_PPC64_GOT16_HA
:
6660 case R_PPC64_GOT16_HI
:
6661 case R_PPC64_GOT16_LO
:
6662 case R_PPC64_GOT16_LO_DS
:
6665 struct got_entry
*ent
;
6670 ent
= local_got_ents
[r_symndx
];
6672 for (; ent
!= NULL
; ent
= ent
->next
)
6673 if (ent
->addend
== rel
->r_addend
6674 && ent
->owner
== abfd
6675 && ent
->tls_type
== tls_type
)
6679 if (ent
->got
.refcount
> 0)
6680 ent
->got
.refcount
-= 1;
6684 case R_PPC64_PLT16_HA
:
6685 case R_PPC64_PLT16_HI
:
6686 case R_PPC64_PLT16_LO
:
6690 case R_PPC64_REL14_BRNTAKEN
:
6691 case R_PPC64_REL14_BRTAKEN
:
6695 plt_list
= &h
->plt
.plist
;
6696 else if (local_got_ents
!= NULL
)
6698 struct plt_entry
**local_plt
= (struct plt_entry
**)
6699 (local_got_ents
+ symtab_hdr
->sh_info
);
6700 unsigned char *local_got_tls_masks
= (unsigned char *)
6701 (local_plt
+ symtab_hdr
->sh_info
);
6702 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
6703 plt_list
= local_plt
+ r_symndx
;
6707 struct plt_entry
*ent
;
6709 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
6710 if (ent
->addend
== rel
->r_addend
)
6712 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
6713 ent
->plt
.refcount
-= 1;
6724 /* The maximum size of .sfpr. */
6725 #define SFPR_MAX (218*4)
6727 struct sfpr_def_parms
6729 const char name
[12];
6730 unsigned char lo
, hi
;
6731 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
6732 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
6735 /* Auto-generate _save*, _rest* functions in .sfpr.
6736 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6740 sfpr_define (struct bfd_link_info
*info
,
6741 const struct sfpr_def_parms
*parm
,
6744 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6746 size_t len
= strlen (parm
->name
);
6747 bfd_boolean writing
= FALSE
;
6753 memcpy (sym
, parm
->name
, len
);
6756 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6758 struct ppc_link_hash_entry
*h
;
6760 sym
[len
+ 0] = i
/ 10 + '0';
6761 sym
[len
+ 1] = i
% 10 + '0';
6762 h
= (struct ppc_link_hash_entry
*)
6763 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
6764 if (stub_sec
!= NULL
)
6767 && h
->elf
.root
.type
== bfd_link_hash_defined
6768 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6770 struct elf_link_hash_entry
*s
;
6772 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6773 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
6776 if (s
->root
.type
== bfd_link_hash_new
6777 || (s
->root
.type
= bfd_link_hash_defined
6778 && s
->root
.u
.def
.section
== stub_sec
))
6780 s
->root
.type
= bfd_link_hash_defined
;
6781 s
->root
.u
.def
.section
= stub_sec
;
6782 s
->root
.u
.def
.value
= (stub_sec
->size
6783 + h
->elf
.root
.u
.def
.value
);
6786 s
->ref_regular_nonweak
= 1;
6787 s
->forced_local
= 1;
6789 s
->root
.linker_def
= 1;
6797 if (!h
->elf
.def_regular
)
6799 h
->elf
.root
.type
= bfd_link_hash_defined
;
6800 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6801 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6802 h
->elf
.type
= STT_FUNC
;
6803 h
->elf
.def_regular
= 1;
6805 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
6807 if (htab
->sfpr
->contents
== NULL
)
6809 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6810 if (htab
->sfpr
->contents
== NULL
)
6817 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6819 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6821 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6822 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6830 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6832 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6837 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6839 p
= savegpr0 (abfd
, p
, r
);
6840 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6842 bfd_put_32 (abfd
, BLR
, p
);
6847 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6849 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6854 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6856 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6858 p
= restgpr0 (abfd
, p
, r
);
6859 bfd_put_32 (abfd
, MTLR_R0
, p
);
6863 p
= restgpr0 (abfd
, p
, 30);
6864 p
= restgpr0 (abfd
, p
, 31);
6866 bfd_put_32 (abfd
, BLR
, p
);
6871 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6873 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6878 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6880 p
= savegpr1 (abfd
, p
, r
);
6881 bfd_put_32 (abfd
, BLR
, p
);
6886 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6888 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6893 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6895 p
= restgpr1 (abfd
, p
, r
);
6896 bfd_put_32 (abfd
, BLR
, p
);
6901 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6903 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6908 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6910 p
= savefpr (abfd
, p
, r
);
6911 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6913 bfd_put_32 (abfd
, BLR
, p
);
6918 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6920 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6925 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6927 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6929 p
= restfpr (abfd
, p
, r
);
6930 bfd_put_32 (abfd
, MTLR_R0
, p
);
6934 p
= restfpr (abfd
, p
, 30);
6935 p
= restfpr (abfd
, p
, 31);
6937 bfd_put_32 (abfd
, BLR
, p
);
6942 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6944 p
= savefpr (abfd
, p
, r
);
6945 bfd_put_32 (abfd
, BLR
, p
);
6950 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6952 p
= restfpr (abfd
, p
, r
);
6953 bfd_put_32 (abfd
, BLR
, p
);
6958 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6960 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6962 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6967 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6969 p
= savevr (abfd
, p
, r
);
6970 bfd_put_32 (abfd
, BLR
, p
);
6975 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6977 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6979 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6984 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6986 p
= restvr (abfd
, p
, r
);
6987 bfd_put_32 (abfd
, BLR
, p
);
6991 /* Called via elf_link_hash_traverse to transfer dynamic linking
6992 information on function code symbol entries to their corresponding
6993 function descriptor symbol entries. */
6996 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6998 struct bfd_link_info
*info
;
6999 struct ppc_link_hash_table
*htab
;
7000 struct ppc_link_hash_entry
*fh
;
7001 struct ppc_link_hash_entry
*fdh
;
7002 bfd_boolean force_local
;
7004 fh
= (struct ppc_link_hash_entry
*) h
;
7005 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
7011 if (fh
->elf
.root
.root
.string
[0] != '.'
7012 || fh
->elf
.root
.root
.string
[1] == '\0')
7016 htab
= ppc_hash_table (info
);
7020 /* Find the corresponding function descriptor symbol. */
7021 fdh
= lookup_fdh (fh
, htab
);
7023 /* Resolve undefined references to dot-symbols as the value
7024 in the function descriptor, if we have one in a regular object.
7025 This is to satisfy cases like ".quad .foo". Calls to functions
7026 in dynamic objects are handled elsewhere. */
7027 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
7028 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
7029 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
7030 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
7031 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
7032 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
7033 fdh
->elf
.root
.u
.def
.value
,
7034 &fh
->elf
.root
.u
.def
.section
,
7035 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
7037 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
7038 fh
->elf
.forced_local
= 1;
7039 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
7040 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
7043 if (!fh
->elf
.dynamic
)
7045 struct plt_entry
*ent
;
7047 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7048 if (ent
->plt
.refcount
> 0)
7054 /* Create a descriptor as undefined if necessary. */
7056 && !bfd_link_executable (info
)
7057 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
7058 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
7060 fdh
= make_fdh (info
, fh
);
7065 /* We can't support overriding of symbols on a fake descriptor. */
7068 && (fh
->elf
.root
.type
== bfd_link_hash_defined
7069 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
7070 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
7072 /* Transfer dynamic linking information to the function descriptor. */
7075 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
7076 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
7077 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
7078 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
7079 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
7080 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
7081 || fh
->elf
.type
== STT_FUNC
7082 || fh
->elf
.type
== STT_GNU_IFUNC
);
7083 move_plt_plist (fh
, fdh
);
7085 if (!fdh
->elf
.forced_local
7086 && fh
->elf
.dynindx
!= -1)
7087 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
7091 /* Now that the info is on the function descriptor, clear the
7092 function code sym info. Any function code syms for which we
7093 don't have a definition in a regular file, we force local.
7094 This prevents a shared library from exporting syms that have
7095 been imported from another library. Function code syms that
7096 are really in the library we must leave global to prevent the
7097 linker dragging in a definition from a static library. */
7098 force_local
= (!fh
->elf
.def_regular
7100 || !fdh
->elf
.def_regular
7101 || fdh
->elf
.forced_local
);
7102 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7107 static const struct sfpr_def_parms save_res_funcs
[] =
7109 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
7110 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
7111 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
7112 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
7113 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
7114 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
7115 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
7116 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
7117 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
7118 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
7119 { "_savevr_", 20, 31, savevr
, savevr_tail
},
7120 { "_restvr_", 20, 31, restvr
, restvr_tail
}
7123 /* Called near the start of bfd_elf_size_dynamic_sections. We use
7124 this hook to a) provide some gcc support functions, and b) transfer
7125 dynamic linking information gathered so far on function code symbol
7126 entries, to their corresponding function descriptor symbol entries. */
7129 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
7130 struct bfd_link_info
*info
)
7132 struct ppc_link_hash_table
*htab
;
7134 htab
= ppc_hash_table (info
);
7138 /* Provide any missing _save* and _rest* functions. */
7139 if (htab
->sfpr
!= NULL
)
7143 htab
->sfpr
->size
= 0;
7144 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
7145 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
7147 if (htab
->sfpr
->size
== 0)
7148 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
7151 if (bfd_link_relocatable (info
))
7154 if (htab
->elf
.hgot
!= NULL
)
7156 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
7157 /* Make .TOC. defined so as to prevent it being made dynamic.
7158 The wrong value here is fixed later in ppc64_elf_set_toc. */
7159 if (!htab
->elf
.hgot
->def_regular
7160 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
7162 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
7163 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
7164 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
7165 htab
->elf
.hgot
->def_regular
= 1;
7166 htab
->elf
.hgot
->root
.linker_def
= 1;
7168 htab
->elf
.hgot
->type
= STT_OBJECT
;
7169 htab
->elf
.hgot
->other
= ((htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1))
7173 if (htab
->need_func_desc_adj
)
7175 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7176 htab
->need_func_desc_adj
= 0;
7182 /* Return true if we have dynamic relocs against H that apply to
7183 read-only sections. */
7186 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7188 struct ppc_link_hash_entry
*eh
;
7189 struct elf_dyn_relocs
*p
;
7191 eh
= (struct ppc_link_hash_entry
*) h
;
7192 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7194 asection
*s
= p
->sec
->output_section
;
7196 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7202 /* Return true if we have dynamic relocs against H or any of its weak
7203 aliases, that apply to read-only sections. */
7206 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7208 struct ppc_link_hash_entry
*eh
;
7210 eh
= (struct ppc_link_hash_entry
*) h
;
7213 if (readonly_dynrelocs (&eh
->elf
))
7216 } while (eh
!= NULL
&& &eh
->elf
!= h
);
7221 /* Return whether EH has pc-relative dynamic relocs. */
7224 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
7226 struct elf_dyn_relocs
*p
;
7228 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7229 if (p
->pc_count
!= 0)
7234 /* Return true if a global entry stub will be created for H. Valid
7235 for ELFv2 before plt entries have been allocated. */
7238 global_entry_stub (struct elf_link_hash_entry
*h
)
7240 struct plt_entry
*pent
;
7242 if (!h
->pointer_equality_needed
7246 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7247 if (pent
->plt
.refcount
> 0
7248 && pent
->addend
== 0)
7254 /* Adjust a symbol defined by a dynamic object and referenced by a
7255 regular object. The current definition is in some section of the
7256 dynamic object, but we're not including those sections. We have to
7257 change the definition to something the rest of the link can
7261 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7262 struct elf_link_hash_entry
*h
)
7264 struct ppc_link_hash_table
*htab
;
7267 htab
= ppc_hash_table (info
);
7271 /* Deal with function syms. */
7272 if (h
->type
== STT_FUNC
7273 || h
->type
== STT_GNU_IFUNC
7276 /* Clear procedure linkage table information for any symbol that
7277 won't need a .plt entry. */
7278 struct plt_entry
*ent
;
7279 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7280 if (ent
->plt
.refcount
> 0)
7283 || (h
->type
!= STT_GNU_IFUNC
7284 && (SYMBOL_CALLS_LOCAL (info
, h
)
7285 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7286 && h
->root
.type
== bfd_link_hash_undefweak
)))
7287 || ((struct ppc_link_hash_entry
*) h
)->save_res
)
7289 h
->plt
.plist
= NULL
;
7291 h
->pointer_equality_needed
= 0;
7293 else if (abiversion (info
->output_bfd
) >= 2)
7295 /* Taking a function's address in a read/write section
7296 doesn't require us to define the function symbol in the
7297 executable on a global entry stub. A dynamic reloc can
7298 be used instead. The reason we prefer a few more dynamic
7299 relocs is that calling via a global entry stub costs a
7300 few more instructions, and pointer_equality_needed causes
7301 extra work in ld.so when resolving these symbols. */
7302 if (global_entry_stub (h
)
7303 && !alias_readonly_dynrelocs (h
))
7305 h
->pointer_equality_needed
= 0;
7306 /* After adjust_dynamic_symbol, non_got_ref set in
7307 the non-pic case means that dyn_relocs for this
7308 symbol should be discarded. */
7312 /* If making a plt entry, then we don't need copy relocs. */
7317 h
->plt
.plist
= NULL
;
7319 /* If this is a weak symbol, and there is a real definition, the
7320 processor independent code will have arranged for us to see the
7321 real definition first, and we can just use the same value. */
7322 if (h
->u
.weakdef
!= NULL
)
7324 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7325 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7326 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7327 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7328 if (ELIMINATE_COPY_RELOCS
)
7329 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
7333 /* If we are creating a shared library, we must presume that the
7334 only references to the symbol are via the global offset table.
7335 For such cases we need not do anything here; the relocations will
7336 be handled correctly by relocate_section. */
7337 if (bfd_link_pic (info
))
7340 /* If there are no references to this symbol that do not use the
7341 GOT, we don't need to generate a copy reloc. */
7342 if (!h
->non_got_ref
)
7345 /* Don't generate a copy reloc for symbols defined in the executable. */
7346 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
7348 /* If -z nocopyreloc was given, don't generate them either. */
7349 || info
->nocopyreloc
7351 /* If we didn't find any dynamic relocs in read-only sections, then
7352 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7353 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
7355 /* Protected variables do not work with .dynbss. The copy in
7356 .dynbss won't be used by the shared library with the protected
7357 definition for the variable. Text relocations are preferable
7358 to an incorrect program. */
7359 || h
->protected_def
)
7365 if (h
->plt
.plist
!= NULL
)
7367 /* We should never get here, but unfortunately there are versions
7368 of gcc out there that improperly (for this ABI) put initialized
7369 function pointers, vtable refs and suchlike in read-only
7370 sections. Allow them to proceed, but warn that this might
7371 break at runtime. */
7372 info
->callbacks
->einfo
7373 (_("%P: copy reloc against `%T' requires lazy plt linking; "
7374 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7375 h
->root
.root
.string
);
7378 /* This is a reference to a symbol defined by a dynamic object which
7379 is not a function. */
7381 /* We must allocate the symbol in our .dynbss section, which will
7382 become part of the .bss section of the executable. There will be
7383 an entry for this symbol in the .dynsym section. The dynamic
7384 object will contain position independent code, so all references
7385 from the dynamic object to this symbol will go through the global
7386 offset table. The dynamic linker will use the .dynsym entry to
7387 determine the address it must put in the global offset table, so
7388 both the dynamic object and the regular object will refer to the
7389 same memory location for the variable. */
7391 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
7392 to copy the initial value out of the dynamic object and into the
7393 runtime process image. We need to remember the offset into the
7394 .rela.bss section we are going to use. */
7395 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7397 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
7403 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7406 /* If given a function descriptor symbol, hide both the function code
7407 sym and the descriptor. */
7409 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
7410 struct elf_link_hash_entry
*h
,
7411 bfd_boolean force_local
)
7413 struct ppc_link_hash_entry
*eh
;
7414 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
7416 eh
= (struct ppc_link_hash_entry
*) h
;
7417 if (eh
->is_func_descriptor
)
7419 struct ppc_link_hash_entry
*fh
= eh
->oh
;
7424 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7427 /* We aren't supposed to use alloca in BFD because on
7428 systems which do not have alloca the version in libiberty
7429 calls xmalloc, which might cause the program to crash
7430 when it runs out of memory. This function doesn't have a
7431 return status, so there's no way to gracefully return an
7432 error. So cheat. We know that string[-1] can be safely
7433 accessed; It's either a string in an ELF string table,
7434 or allocated in an objalloc structure. */
7436 p
= eh
->elf
.root
.root
.string
- 1;
7439 fh
= (struct ppc_link_hash_entry
*)
7440 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7443 /* Unfortunately, if it so happens that the string we were
7444 looking for was allocated immediately before this string,
7445 then we overwrote the string terminator. That's the only
7446 reason the lookup should fail. */
7449 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
7450 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
7452 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
7453 fh
= (struct ppc_link_hash_entry
*)
7454 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7463 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7468 get_sym_h (struct elf_link_hash_entry
**hp
,
7469 Elf_Internal_Sym
**symp
,
7471 unsigned char **tls_maskp
,
7472 Elf_Internal_Sym
**locsymsp
,
7473 unsigned long r_symndx
,
7476 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7478 if (r_symndx
>= symtab_hdr
->sh_info
)
7480 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7481 struct elf_link_hash_entry
*h
;
7483 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7484 h
= elf_follow_link (h
);
7492 if (symsecp
!= NULL
)
7494 asection
*symsec
= NULL
;
7495 if (h
->root
.type
== bfd_link_hash_defined
7496 || h
->root
.type
== bfd_link_hash_defweak
)
7497 symsec
= h
->root
.u
.def
.section
;
7501 if (tls_maskp
!= NULL
)
7503 struct ppc_link_hash_entry
*eh
;
7505 eh
= (struct ppc_link_hash_entry
*) h
;
7506 *tls_maskp
= &eh
->tls_mask
;
7511 Elf_Internal_Sym
*sym
;
7512 Elf_Internal_Sym
*locsyms
= *locsymsp
;
7514 if (locsyms
== NULL
)
7516 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7517 if (locsyms
== NULL
)
7518 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
7519 symtab_hdr
->sh_info
,
7520 0, NULL
, NULL
, NULL
);
7521 if (locsyms
== NULL
)
7523 *locsymsp
= locsyms
;
7525 sym
= locsyms
+ r_symndx
;
7533 if (symsecp
!= NULL
)
7534 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
7536 if (tls_maskp
!= NULL
)
7538 struct got_entry
**lgot_ents
;
7539 unsigned char *tls_mask
;
7542 lgot_ents
= elf_local_got_ents (ibfd
);
7543 if (lgot_ents
!= NULL
)
7545 struct plt_entry
**local_plt
= (struct plt_entry
**)
7546 (lgot_ents
+ symtab_hdr
->sh_info
);
7547 unsigned char *lgot_masks
= (unsigned char *)
7548 (local_plt
+ symtab_hdr
->sh_info
);
7549 tls_mask
= &lgot_masks
[r_symndx
];
7551 *tls_maskp
= tls_mask
;
7557 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7558 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7559 type suitable for optimization, and 1 otherwise. */
7562 get_tls_mask (unsigned char **tls_maskp
,
7563 unsigned long *toc_symndx
,
7564 bfd_vma
*toc_addend
,
7565 Elf_Internal_Sym
**locsymsp
,
7566 const Elf_Internal_Rela
*rel
,
7569 unsigned long r_symndx
;
7571 struct elf_link_hash_entry
*h
;
7572 Elf_Internal_Sym
*sym
;
7576 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7577 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7580 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
7582 || ppc64_elf_section_data (sec
) == NULL
7583 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7586 /* Look inside a TOC section too. */
7589 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7590 off
= h
->root
.u
.def
.value
;
7593 off
= sym
->st_value
;
7594 off
+= rel
->r_addend
;
7595 BFD_ASSERT (off
% 8 == 0);
7596 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7597 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7598 if (toc_symndx
!= NULL
)
7599 *toc_symndx
= r_symndx
;
7600 if (toc_addend
!= NULL
)
7601 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7602 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7604 if ((h
== NULL
|| is_static_defined (h
))
7605 && (next_r
== -1 || next_r
== -2))
7610 /* Find (or create) an entry in the tocsave hash table. */
7612 static struct tocsave_entry
*
7613 tocsave_find (struct ppc_link_hash_table
*htab
,
7614 enum insert_option insert
,
7615 Elf_Internal_Sym
**local_syms
,
7616 const Elf_Internal_Rela
*irela
,
7619 unsigned long r_indx
;
7620 struct elf_link_hash_entry
*h
;
7621 Elf_Internal_Sym
*sym
;
7622 struct tocsave_entry ent
, *p
;
7624 struct tocsave_entry
**slot
;
7626 r_indx
= ELF64_R_SYM (irela
->r_info
);
7627 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7629 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7632 (_("%B: undefined symbol on R_PPC64_TOCSAVE relocation"));
7637 ent
.offset
= h
->root
.u
.def
.value
;
7639 ent
.offset
= sym
->st_value
;
7640 ent
.offset
+= irela
->r_addend
;
7642 hash
= tocsave_htab_hash (&ent
);
7643 slot
= ((struct tocsave_entry
**)
7644 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7650 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7659 /* Adjust all global syms defined in opd sections. In gcc generated
7660 code for the old ABI, these will already have been done. */
7663 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7665 struct ppc_link_hash_entry
*eh
;
7667 struct _opd_sec_data
*opd
;
7669 if (h
->root
.type
== bfd_link_hash_indirect
)
7672 if (h
->root
.type
!= bfd_link_hash_defined
7673 && h
->root
.type
!= bfd_link_hash_defweak
)
7676 eh
= (struct ppc_link_hash_entry
*) h
;
7677 if (eh
->adjust_done
)
7680 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7681 opd
= get_opd_info (sym_sec
);
7682 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7684 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7687 /* This entry has been deleted. */
7688 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7691 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7692 if (discarded_section (dsec
))
7694 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7698 eh
->elf
.root
.u
.def
.value
= 0;
7699 eh
->elf
.root
.u
.def
.section
= dsec
;
7702 eh
->elf
.root
.u
.def
.value
+= adjust
;
7703 eh
->adjust_done
= 1;
7708 /* Handles decrementing dynamic reloc counts for the reloc specified by
7709 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7710 have already been determined. */
7713 dec_dynrel_count (bfd_vma r_info
,
7715 struct bfd_link_info
*info
,
7716 Elf_Internal_Sym
**local_syms
,
7717 struct elf_link_hash_entry
*h
,
7718 Elf_Internal_Sym
*sym
)
7720 enum elf_ppc64_reloc_type r_type
;
7721 asection
*sym_sec
= NULL
;
7723 /* Can this reloc be dynamic? This switch, and later tests here
7724 should be kept in sync with the code in check_relocs. */
7725 r_type
= ELF64_R_TYPE (r_info
);
7731 case R_PPC64_TPREL16
:
7732 case R_PPC64_TPREL16_LO
:
7733 case R_PPC64_TPREL16_HI
:
7734 case R_PPC64_TPREL16_HA
:
7735 case R_PPC64_TPREL16_DS
:
7736 case R_PPC64_TPREL16_LO_DS
:
7737 case R_PPC64_TPREL16_HIGH
:
7738 case R_PPC64_TPREL16_HIGHA
:
7739 case R_PPC64_TPREL16_HIGHER
:
7740 case R_PPC64_TPREL16_HIGHERA
:
7741 case R_PPC64_TPREL16_HIGHEST
:
7742 case R_PPC64_TPREL16_HIGHESTA
:
7743 if (!bfd_link_pic (info
))
7746 case R_PPC64_TPREL64
:
7747 case R_PPC64_DTPMOD64
:
7748 case R_PPC64_DTPREL64
:
7749 case R_PPC64_ADDR64
:
7753 case R_PPC64_ADDR14
:
7754 case R_PPC64_ADDR14_BRNTAKEN
:
7755 case R_PPC64_ADDR14_BRTAKEN
:
7756 case R_PPC64_ADDR16
:
7757 case R_PPC64_ADDR16_DS
:
7758 case R_PPC64_ADDR16_HA
:
7759 case R_PPC64_ADDR16_HI
:
7760 case R_PPC64_ADDR16_HIGH
:
7761 case R_PPC64_ADDR16_HIGHA
:
7762 case R_PPC64_ADDR16_HIGHER
:
7763 case R_PPC64_ADDR16_HIGHERA
:
7764 case R_PPC64_ADDR16_HIGHEST
:
7765 case R_PPC64_ADDR16_HIGHESTA
:
7766 case R_PPC64_ADDR16_LO
:
7767 case R_PPC64_ADDR16_LO_DS
:
7768 case R_PPC64_ADDR24
:
7769 case R_PPC64_ADDR32
:
7770 case R_PPC64_UADDR16
:
7771 case R_PPC64_UADDR32
:
7772 case R_PPC64_UADDR64
:
7777 if (local_syms
!= NULL
)
7779 unsigned long r_symndx
;
7780 bfd
*ibfd
= sec
->owner
;
7782 r_symndx
= ELF64_R_SYM (r_info
);
7783 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7787 if ((bfd_link_pic (info
)
7788 && (must_be_dyn_reloc (info
, r_type
)
7790 && (!SYMBOLIC_BIND (info
, h
)
7791 || h
->root
.type
== bfd_link_hash_defweak
7792 || !h
->def_regular
))))
7793 || (ELIMINATE_COPY_RELOCS
7794 && !bfd_link_pic (info
)
7796 && (h
->root
.type
== bfd_link_hash_defweak
7797 || !h
->def_regular
)))
7804 struct elf_dyn_relocs
*p
;
7805 struct elf_dyn_relocs
**pp
;
7806 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
7808 /* elf_gc_sweep may have already removed all dyn relocs associated
7809 with local syms for a given section. Also, symbol flags are
7810 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7811 report a dynreloc miscount. */
7812 if (*pp
== NULL
&& info
->gc_sections
)
7815 while ((p
= *pp
) != NULL
)
7819 if (!must_be_dyn_reloc (info
, r_type
))
7831 struct ppc_dyn_relocs
*p
;
7832 struct ppc_dyn_relocs
**pp
;
7834 bfd_boolean is_ifunc
;
7836 if (local_syms
== NULL
)
7837 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7838 if (sym_sec
== NULL
)
7841 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7842 pp
= (struct ppc_dyn_relocs
**) vpp
;
7844 if (*pp
== NULL
&& info
->gc_sections
)
7847 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7848 while ((p
= *pp
) != NULL
)
7850 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7861 /* xgettext:c-format */
7862 info
->callbacks
->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
7864 bfd_set_error (bfd_error_bad_value
);
7868 /* Remove unused Official Procedure Descriptor entries. Currently we
7869 only remove those associated with functions in discarded link-once
7870 sections, or weakly defined functions that have been overridden. It
7871 would be possible to remove many more entries for statically linked
7875 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7878 bfd_boolean some_edited
= FALSE
;
7879 asection
*need_pad
= NULL
;
7880 struct ppc_link_hash_table
*htab
;
7882 htab
= ppc_hash_table (info
);
7886 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7889 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7890 Elf_Internal_Shdr
*symtab_hdr
;
7891 Elf_Internal_Sym
*local_syms
;
7892 struct _opd_sec_data
*opd
;
7893 bfd_boolean need_edit
, add_aux_fields
, broken
;
7894 bfd_size_type cnt_16b
= 0;
7896 if (!is_ppc64_elf (ibfd
))
7899 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7900 if (sec
== NULL
|| sec
->size
== 0)
7903 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7906 if (sec
->output_section
== bfd_abs_section_ptr
)
7909 /* Look through the section relocs. */
7910 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7914 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7916 /* Read the relocations. */
7917 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7919 if (relstart
== NULL
)
7922 /* First run through the relocs to check they are sane, and to
7923 determine whether we need to edit this opd section. */
7927 relend
= relstart
+ sec
->reloc_count
;
7928 for (rel
= relstart
; rel
< relend
; )
7930 enum elf_ppc64_reloc_type r_type
;
7931 unsigned long r_symndx
;
7933 struct elf_link_hash_entry
*h
;
7934 Elf_Internal_Sym
*sym
;
7937 /* .opd contains an array of 16 or 24 byte entries. We're
7938 only interested in the reloc pointing to a function entry
7940 offset
= rel
->r_offset
;
7941 if (rel
+ 1 == relend
7942 || rel
[1].r_offset
!= offset
+ 8)
7944 /* If someone messes with .opd alignment then after a
7945 "ld -r" we might have padding in the middle of .opd.
7946 Also, there's nothing to prevent someone putting
7947 something silly in .opd with the assembler. No .opd
7948 optimization for them! */
7951 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
7956 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7957 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7960 /* xgettext:c-format */
7961 (_("%B: unexpected reloc type %u in .opd section"),
7967 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7968 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7972 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7974 const char *sym_name
;
7976 sym_name
= h
->root
.root
.string
;
7978 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7982 /* xgettext:c-format */
7983 (_("%B: undefined sym `%s' in .opd section"),
7989 /* opd entries are always for functions defined in the
7990 current input bfd. If the symbol isn't defined in the
7991 input bfd, then we won't be using the function in this
7992 bfd; It must be defined in a linkonce section in another
7993 bfd, or is weak. It's also possible that we are
7994 discarding the function due to a linker script /DISCARD/,
7995 which we test for via the output_section. */
7996 if (sym_sec
->owner
!= ibfd
7997 || sym_sec
->output_section
== bfd_abs_section_ptr
)
8001 if (rel
+ 1 == relend
8002 || (rel
+ 2 < relend
8003 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
8008 if (sec
->size
== offset
+ 24)
8013 if (sec
->size
== offset
+ 16)
8020 else if (rel
+ 1 < relend
8021 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
8022 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
8024 if (rel
[0].r_offset
== offset
+ 16)
8026 else if (rel
[0].r_offset
!= offset
+ 24)
8033 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
8035 if (!broken
&& (need_edit
|| add_aux_fields
))
8037 Elf_Internal_Rela
*write_rel
;
8038 Elf_Internal_Shdr
*rel_hdr
;
8039 bfd_byte
*rptr
, *wptr
;
8040 bfd_byte
*new_contents
;
8043 new_contents
= NULL
;
8044 amt
= OPD_NDX (sec
->size
) * sizeof (long);
8045 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
8046 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
8047 if (opd
->adjust
== NULL
)
8049 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
8051 /* This seems a waste of time as input .opd sections are all
8052 zeros as generated by gcc, but I suppose there's no reason
8053 this will always be so. We might start putting something in
8054 the third word of .opd entries. */
8055 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
8058 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
8063 if (local_syms
!= NULL
8064 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8066 if (elf_section_data (sec
)->relocs
!= relstart
)
8070 sec
->contents
= loc
;
8071 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8074 elf_section_data (sec
)->relocs
= relstart
;
8076 new_contents
= sec
->contents
;
8079 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
8080 if (new_contents
== NULL
)
8084 wptr
= new_contents
;
8085 rptr
= sec
->contents
;
8086 write_rel
= relstart
;
8087 for (rel
= relstart
; rel
< relend
; )
8089 unsigned long r_symndx
;
8091 struct elf_link_hash_entry
*h
;
8092 struct ppc_link_hash_entry
*fdh
= NULL
;
8093 Elf_Internal_Sym
*sym
;
8095 Elf_Internal_Rela
*next_rel
;
8098 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8099 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8104 if (next_rel
+ 1 == relend
8105 || (next_rel
+ 2 < relend
8106 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
8109 /* See if the .opd entry is full 24 byte or
8110 16 byte (with fd_aux entry overlapped with next
8113 if (next_rel
== relend
)
8115 if (sec
->size
== rel
->r_offset
+ 16)
8118 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
8122 && h
->root
.root
.string
[0] == '.')
8124 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
8127 fdh
= ppc_follow_link (fdh
);
8128 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
8129 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8134 skip
= (sym_sec
->owner
!= ibfd
8135 || sym_sec
->output_section
== bfd_abs_section_ptr
);
8138 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
8140 /* Arrange for the function descriptor sym
8142 fdh
->elf
.root
.u
.def
.value
= 0;
8143 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
8145 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
8147 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
8152 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8156 if (++rel
== next_rel
)
8159 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8160 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8167 /* We'll be keeping this opd entry. */
8172 /* Redefine the function descriptor symbol to
8173 this location in the opd section. It is
8174 necessary to update the value here rather
8175 than using an array of adjustments as we do
8176 for local symbols, because various places
8177 in the generic ELF code use the value
8178 stored in u.def.value. */
8179 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
8180 fdh
->adjust_done
= 1;
8183 /* Local syms are a bit tricky. We could
8184 tweak them as they can be cached, but
8185 we'd need to look through the local syms
8186 for the function descriptor sym which we
8187 don't have at the moment. So keep an
8188 array of adjustments. */
8189 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
8190 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
8193 memcpy (wptr
, rptr
, opd_ent_size
);
8194 wptr
+= opd_ent_size
;
8195 if (add_aux_fields
&& opd_ent_size
== 16)
8197 memset (wptr
, '\0', 8);
8201 /* We need to adjust any reloc offsets to point to the
8203 for ( ; rel
!= next_rel
; ++rel
)
8205 rel
->r_offset
+= adjust
;
8206 if (write_rel
!= rel
)
8207 memcpy (write_rel
, rel
, sizeof (*rel
));
8212 rptr
+= opd_ent_size
;
8215 sec
->size
= wptr
- new_contents
;
8216 sec
->reloc_count
= write_rel
- relstart
;
8219 free (sec
->contents
);
8220 sec
->contents
= new_contents
;
8223 /* Fudge the header size too, as this is used later in
8224 elf_bfd_final_link if we are emitting relocs. */
8225 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
8226 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
8229 else if (elf_section_data (sec
)->relocs
!= relstart
)
8232 if (local_syms
!= NULL
8233 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8235 if (!info
->keep_memory
)
8238 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8243 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
8245 /* If we are doing a final link and the last .opd entry is just 16 byte
8246 long, add a 8 byte padding after it. */
8247 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
8251 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
8253 BFD_ASSERT (need_pad
->size
> 0);
8255 p
= bfd_malloc (need_pad
->size
+ 8);
8259 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
8260 p
, 0, need_pad
->size
))
8263 need_pad
->contents
= p
;
8264 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8268 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
8272 need_pad
->contents
= p
;
8275 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
8276 need_pad
->size
+= 8;
8282 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8285 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
8287 struct ppc_link_hash_table
*htab
;
8289 htab
= ppc_hash_table (info
);
8293 if (abiversion (info
->output_bfd
) == 1)
8296 if (htab
->params
->no_multi_toc
)
8297 htab
->do_multi_toc
= 0;
8298 else if (!htab
->do_multi_toc
)
8299 htab
->params
->no_multi_toc
= 1;
8301 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
8302 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
8303 FALSE
, FALSE
, TRUE
));
8304 /* Move dynamic linking info to the function descriptor sym. */
8305 if (htab
->tls_get_addr
!= NULL
)
8306 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
8307 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
8308 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
8309 FALSE
, FALSE
, TRUE
));
8310 if (htab
->params
->tls_get_addr_opt
)
8312 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
8314 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
8315 FALSE
, FALSE
, TRUE
);
8317 func_desc_adjust (opt
, info
);
8318 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
8319 FALSE
, FALSE
, TRUE
);
8321 && (opt_fd
->root
.type
== bfd_link_hash_defined
8322 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8324 /* If glibc supports an optimized __tls_get_addr call stub,
8325 signalled by the presence of __tls_get_addr_opt, and we'll
8326 be calling __tls_get_addr via a plt call stub, then
8327 make __tls_get_addr point to __tls_get_addr_opt. */
8328 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
8329 if (htab
->elf
.dynamic_sections_created
8331 && (tga_fd
->type
== STT_FUNC
8332 || tga_fd
->needs_plt
)
8333 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8334 || (ELF_ST_VISIBILITY (tga_fd
->other
) != STV_DEFAULT
8335 && tga_fd
->root
.type
== bfd_link_hash_undefweak
)))
8337 struct plt_entry
*ent
;
8339 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8340 if (ent
->plt
.refcount
> 0)
8344 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8345 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8346 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8347 opt_fd
->forced_local
= 0;
8348 if (opt_fd
->dynindx
!= -1)
8350 /* Use __tls_get_addr_opt in dynamic relocations. */
8351 opt_fd
->dynindx
= -1;
8352 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8353 opt_fd
->dynstr_index
);
8354 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8357 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
8358 tga
= &htab
->tls_get_addr
->elf
;
8359 if (opt
!= NULL
&& tga
!= NULL
)
8361 tga
->root
.type
= bfd_link_hash_indirect
;
8362 tga
->root
.u
.i
.link
= &opt
->root
;
8363 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8364 opt
->forced_local
= 0;
8365 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8367 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
8369 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8370 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8371 if (htab
->tls_get_addr
!= NULL
)
8373 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8374 htab
->tls_get_addr
->is_func
= 1;
8379 else if (htab
->params
->tls_get_addr_opt
< 0)
8380 htab
->params
->tls_get_addr_opt
= 0;
8382 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
8385 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8389 branch_reloc_hash_match (const bfd
*ibfd
,
8390 const Elf_Internal_Rela
*rel
,
8391 const struct ppc_link_hash_entry
*hash1
,
8392 const struct ppc_link_hash_entry
*hash2
)
8394 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8395 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8396 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8398 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8400 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8401 struct elf_link_hash_entry
*h
;
8403 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8404 h
= elf_follow_link (h
);
8405 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
8411 /* Run through all the TLS relocs looking for optimization
8412 opportunities. The linker has been hacked (see ppc64elf.em) to do
8413 a preliminary section layout so that we know the TLS segment
8414 offsets. We can't optimize earlier because some optimizations need
8415 to know the tp offset, and we need to optimize before allocating
8416 dynamic relocations. */
8419 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8423 struct ppc_link_hash_table
*htab
;
8424 unsigned char *toc_ref
;
8427 if (!bfd_link_executable (info
))
8430 htab
= ppc_hash_table (info
);
8434 /* Make two passes over the relocs. On the first pass, mark toc
8435 entries involved with tls relocs, and check that tls relocs
8436 involved in setting up a tls_get_addr call are indeed followed by
8437 such a call. If they are not, we can't do any tls optimization.
8438 On the second pass twiddle tls_mask flags to notify
8439 relocate_section that optimization can be done, and adjust got
8440 and plt refcounts. */
8442 for (pass
= 0; pass
< 2; ++pass
)
8443 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8445 Elf_Internal_Sym
*locsyms
= NULL
;
8446 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8448 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8449 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8451 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8452 bfd_boolean found_tls_get_addr_arg
= 0;
8454 /* Read the relocations. */
8455 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8457 if (relstart
== NULL
)
8463 relend
= relstart
+ sec
->reloc_count
;
8464 for (rel
= relstart
; rel
< relend
; rel
++)
8466 enum elf_ppc64_reloc_type r_type
;
8467 unsigned long r_symndx
;
8468 struct elf_link_hash_entry
*h
;
8469 Elf_Internal_Sym
*sym
;
8471 unsigned char *tls_mask
;
8472 unsigned char tls_set
, tls_clear
, tls_type
= 0;
8474 bfd_boolean ok_tprel
, is_local
;
8475 long toc_ref_index
= 0;
8476 int expecting_tls_get_addr
= 0;
8477 bfd_boolean ret
= FALSE
;
8479 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8480 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8484 if (elf_section_data (sec
)->relocs
!= relstart
)
8486 if (toc_ref
!= NULL
)
8489 && (elf_symtab_hdr (ibfd
).contents
8490 != (unsigned char *) locsyms
))
8497 if (h
->root
.type
== bfd_link_hash_defined
8498 || h
->root
.type
== bfd_link_hash_defweak
)
8499 value
= h
->root
.u
.def
.value
;
8500 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8504 found_tls_get_addr_arg
= 0;
8509 /* Symbols referenced by TLS relocs must be of type
8510 STT_TLS. So no need for .opd local sym adjust. */
8511 value
= sym
->st_value
;
8520 && h
->root
.type
== bfd_link_hash_undefweak
)
8522 else if (sym_sec
!= NULL
8523 && sym_sec
->output_section
!= NULL
)
8525 value
+= sym_sec
->output_offset
;
8526 value
+= sym_sec
->output_section
->vma
;
8527 value
-= htab
->elf
.tls_sec
->vma
;
8528 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
8529 < (bfd_vma
) 1 << 32);
8533 r_type
= ELF64_R_TYPE (rel
->r_info
);
8534 /* If this section has old-style __tls_get_addr calls
8535 without marker relocs, then check that each
8536 __tls_get_addr call reloc is preceded by a reloc
8537 that conceivably belongs to the __tls_get_addr arg
8538 setup insn. If we don't find matching arg setup
8539 relocs, don't do any tls optimization. */
8541 && sec
->has_tls_get_addr_call
8543 && (h
== &htab
->tls_get_addr
->elf
8544 || h
== &htab
->tls_get_addr_fd
->elf
)
8545 && !found_tls_get_addr_arg
8546 && is_branch_reloc (r_type
))
8548 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8549 "TLS optimization disabled\n"),
8550 ibfd
, sec
, rel
->r_offset
);
8555 found_tls_get_addr_arg
= 0;
8558 case R_PPC64_GOT_TLSLD16
:
8559 case R_PPC64_GOT_TLSLD16_LO
:
8560 expecting_tls_get_addr
= 1;
8561 found_tls_get_addr_arg
= 1;
8564 case R_PPC64_GOT_TLSLD16_HI
:
8565 case R_PPC64_GOT_TLSLD16_HA
:
8566 /* These relocs should never be against a symbol
8567 defined in a shared lib. Leave them alone if
8568 that turns out to be the case. */
8575 tls_type
= TLS_TLS
| TLS_LD
;
8578 case R_PPC64_GOT_TLSGD16
:
8579 case R_PPC64_GOT_TLSGD16_LO
:
8580 expecting_tls_get_addr
= 1;
8581 found_tls_get_addr_arg
= 1;
8584 case R_PPC64_GOT_TLSGD16_HI
:
8585 case R_PPC64_GOT_TLSGD16_HA
:
8591 tls_set
= TLS_TLS
| TLS_TPRELGD
;
8593 tls_type
= TLS_TLS
| TLS_GD
;
8596 case R_PPC64_GOT_TPREL16_DS
:
8597 case R_PPC64_GOT_TPREL16_LO_DS
:
8598 case R_PPC64_GOT_TPREL16_HI
:
8599 case R_PPC64_GOT_TPREL16_HA
:
8604 tls_clear
= TLS_TPREL
;
8605 tls_type
= TLS_TLS
| TLS_TPREL
;
8612 found_tls_get_addr_arg
= 1;
8617 case R_PPC64_TOC16_LO
:
8618 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8621 /* Mark this toc entry as referenced by a TLS
8622 code sequence. We can do that now in the
8623 case of R_PPC64_TLS, and after checking for
8624 tls_get_addr for the TOC16 relocs. */
8625 if (toc_ref
== NULL
)
8626 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8627 if (toc_ref
== NULL
)
8631 value
= h
->root
.u
.def
.value
;
8633 value
= sym
->st_value
;
8634 value
+= rel
->r_addend
;
8637 BFD_ASSERT (value
< toc
->size
8638 && toc
->output_offset
% 8 == 0);
8639 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8640 if (r_type
== R_PPC64_TLS
8641 || r_type
== R_PPC64_TLSGD
8642 || r_type
== R_PPC64_TLSLD
)
8644 toc_ref
[toc_ref_index
] = 1;
8648 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8653 expecting_tls_get_addr
= 2;
8656 case R_PPC64_TPREL64
:
8660 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8665 tls_set
= TLS_EXPLICIT
;
8666 tls_clear
= TLS_TPREL
;
8671 case R_PPC64_DTPMOD64
:
8675 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8677 if (rel
+ 1 < relend
8679 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8680 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8684 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8687 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
8696 tls_set
= TLS_EXPLICIT
;
8707 if (!expecting_tls_get_addr
8708 || !sec
->has_tls_get_addr_call
)
8711 if (rel
+ 1 < relend
8712 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8714 htab
->tls_get_addr_fd
))
8716 if (expecting_tls_get_addr
== 2)
8718 /* Check for toc tls entries. */
8719 unsigned char *toc_tls
;
8722 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8727 if (toc_tls
!= NULL
)
8729 if ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0)
8730 found_tls_get_addr_arg
= 1;
8732 toc_ref
[toc_ref_index
] = 1;
8738 if (expecting_tls_get_addr
!= 1)
8741 /* Uh oh, we didn't find the expected call. We
8742 could just mark this symbol to exclude it
8743 from tls optimization but it's safer to skip
8744 the entire optimization. */
8745 /* xgettext:c-format */
8746 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8747 "TLS optimization disabled\n"),
8748 ibfd
, sec
, rel
->r_offset
);
8753 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
8755 struct plt_entry
*ent
;
8756 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8759 if (ent
->addend
== 0)
8761 if (ent
->plt
.refcount
> 0)
8763 ent
->plt
.refcount
-= 1;
8764 expecting_tls_get_addr
= 0;
8770 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
8772 struct plt_entry
*ent
;
8773 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8776 if (ent
->addend
== 0)
8778 if (ent
->plt
.refcount
> 0)
8779 ent
->plt
.refcount
-= 1;
8787 if ((tls_set
& TLS_EXPLICIT
) == 0)
8789 struct got_entry
*ent
;
8791 /* Adjust got entry for this reloc. */
8795 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8797 for (; ent
!= NULL
; ent
= ent
->next
)
8798 if (ent
->addend
== rel
->r_addend
8799 && ent
->owner
== ibfd
8800 && ent
->tls_type
== tls_type
)
8807 /* We managed to get rid of a got entry. */
8808 if (ent
->got
.refcount
> 0)
8809 ent
->got
.refcount
-= 1;
8814 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8815 we'll lose one or two dyn relocs. */
8816 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8820 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8822 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8828 *tls_mask
|= tls_set
;
8829 *tls_mask
&= ~tls_clear
;
8832 if (elf_section_data (sec
)->relocs
!= relstart
)
8837 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8839 if (!info
->keep_memory
)
8842 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8846 if (toc_ref
!= NULL
)
8851 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8852 the values of any global symbols in a toc section that has been
8853 edited. Globals in toc sections should be a rarity, so this function
8854 sets a flag if any are found in toc sections other than the one just
8855 edited, so that futher hash table traversals can be avoided. */
8857 struct adjust_toc_info
8860 unsigned long *skip
;
8861 bfd_boolean global_toc_syms
;
8864 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8867 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8869 struct ppc_link_hash_entry
*eh
;
8870 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8873 if (h
->root
.type
!= bfd_link_hash_defined
8874 && h
->root
.type
!= bfd_link_hash_defweak
)
8877 eh
= (struct ppc_link_hash_entry
*) h
;
8878 if (eh
->adjust_done
)
8881 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8883 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8884 i
= toc_inf
->toc
->rawsize
>> 3;
8886 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8888 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8891 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8894 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8895 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8898 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8899 eh
->adjust_done
= 1;
8901 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8902 toc_inf
->global_toc_syms
= TRUE
;
8907 /* Return TRUE iff INSN is one we expect on a _LO variety toc/got reloc. */
8910 ok_lo_toc_insn (unsigned int insn
)
8912 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
8913 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8914 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8915 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8916 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8917 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8918 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8919 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8920 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8921 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8922 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8923 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8924 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8925 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8926 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
8928 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
8929 && ((insn
& 3) == 0 || (insn
& 3) == 3))
8930 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
8933 /* Examine all relocs referencing .toc sections in order to remove
8934 unused .toc entries. */
8937 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8940 struct adjust_toc_info toc_inf
;
8941 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8943 htab
->do_toc_opt
= 1;
8944 toc_inf
.global_toc_syms
= TRUE
;
8945 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8947 asection
*toc
, *sec
;
8948 Elf_Internal_Shdr
*symtab_hdr
;
8949 Elf_Internal_Sym
*local_syms
;
8950 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8951 unsigned long *skip
, *drop
;
8952 unsigned char *used
;
8953 unsigned char *keep
, last
, some_unused
;
8955 if (!is_ppc64_elf (ibfd
))
8958 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8961 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8962 || discarded_section (toc
))
8967 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8969 /* Look at sections dropped from the final link. */
8972 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8974 if (sec
->reloc_count
== 0
8975 || !discarded_section (sec
)
8976 || get_opd_info (sec
)
8977 || (sec
->flags
& SEC_ALLOC
) == 0
8978 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8981 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
8982 if (relstart
== NULL
)
8985 /* Run through the relocs to see which toc entries might be
8987 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8989 enum elf_ppc64_reloc_type r_type
;
8990 unsigned long r_symndx
;
8992 struct elf_link_hash_entry
*h
;
8993 Elf_Internal_Sym
*sym
;
8996 r_type
= ELF64_R_TYPE (rel
->r_info
);
9003 case R_PPC64_TOC16_LO
:
9004 case R_PPC64_TOC16_HI
:
9005 case R_PPC64_TOC16_HA
:
9006 case R_PPC64_TOC16_DS
:
9007 case R_PPC64_TOC16_LO_DS
:
9011 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9012 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9020 val
= h
->root
.u
.def
.value
;
9022 val
= sym
->st_value
;
9023 val
+= rel
->r_addend
;
9025 if (val
>= toc
->size
)
9028 /* Anything in the toc ought to be aligned to 8 bytes.
9029 If not, don't mark as unused. */
9035 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9040 skip
[val
>> 3] = ref_from_discarded
;
9043 if (elf_section_data (sec
)->relocs
!= relstart
)
9047 /* For largetoc loads of address constants, we can convert
9048 . addis rx,2,addr@got@ha
9049 . ld ry,addr@got@l(rx)
9051 . addis rx,2,addr@toc@ha
9052 . addi ry,rx,addr@toc@l
9053 when addr is within 2G of the toc pointer. This then means
9054 that the word storing "addr" in the toc is no longer needed. */
9056 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9057 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9058 && toc
->reloc_count
!= 0)
9060 /* Read toc relocs. */
9061 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9063 if (toc_relocs
== NULL
)
9066 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9068 enum elf_ppc64_reloc_type r_type
;
9069 unsigned long r_symndx
;
9071 struct elf_link_hash_entry
*h
;
9072 Elf_Internal_Sym
*sym
;
9075 r_type
= ELF64_R_TYPE (rel
->r_info
);
9076 if (r_type
!= R_PPC64_ADDR64
)
9079 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9080 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9085 || sym_sec
->output_section
== NULL
9086 || discarded_section (sym_sec
))
9089 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9094 if (h
->type
== STT_GNU_IFUNC
)
9096 val
= h
->root
.u
.def
.value
;
9100 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9102 val
= sym
->st_value
;
9104 val
+= rel
->r_addend
;
9105 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9107 /* We don't yet know the exact toc pointer value, but we
9108 know it will be somewhere in the toc section. Don't
9109 optimize if the difference from any possible toc
9110 pointer is outside [ff..f80008000, 7fff7fff]. */
9111 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9112 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9115 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9116 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9121 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9126 skip
[rel
->r_offset
>> 3]
9127 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9134 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9138 if (local_syms
!= NULL
9139 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9143 && elf_section_data (sec
)->relocs
!= relstart
)
9145 if (toc_relocs
!= NULL
9146 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9153 /* Now check all kept sections that might reference the toc.
9154 Check the toc itself last. */
9155 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9158 sec
= (sec
== toc
? NULL
9159 : sec
->next
== NULL
? toc
9160 : sec
->next
== toc
&& toc
->next
? toc
->next
9165 if (sec
->reloc_count
== 0
9166 || discarded_section (sec
)
9167 || get_opd_info (sec
)
9168 || (sec
->flags
& SEC_ALLOC
) == 0
9169 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9172 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9174 if (relstart
== NULL
)
9180 /* Mark toc entries referenced as used. */
9184 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9186 enum elf_ppc64_reloc_type r_type
;
9187 unsigned long r_symndx
;
9189 struct elf_link_hash_entry
*h
;
9190 Elf_Internal_Sym
*sym
;
9192 enum {no_check
, check_lo
, check_ha
} insn_check
;
9194 r_type
= ELF64_R_TYPE (rel
->r_info
);
9198 insn_check
= no_check
;
9201 case R_PPC64_GOT_TLSLD16_HA
:
9202 case R_PPC64_GOT_TLSGD16_HA
:
9203 case R_PPC64_GOT_TPREL16_HA
:
9204 case R_PPC64_GOT_DTPREL16_HA
:
9205 case R_PPC64_GOT16_HA
:
9206 case R_PPC64_TOC16_HA
:
9207 insn_check
= check_ha
;
9210 case R_PPC64_GOT_TLSLD16_LO
:
9211 case R_PPC64_GOT_TLSGD16_LO
:
9212 case R_PPC64_GOT_TPREL16_LO_DS
:
9213 case R_PPC64_GOT_DTPREL16_LO_DS
:
9214 case R_PPC64_GOT16_LO
:
9215 case R_PPC64_GOT16_LO_DS
:
9216 case R_PPC64_TOC16_LO
:
9217 case R_PPC64_TOC16_LO_DS
:
9218 insn_check
= check_lo
;
9222 if (insn_check
!= no_check
)
9224 bfd_vma off
= rel
->r_offset
& ~3;
9225 unsigned char buf
[4];
9228 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9233 insn
= bfd_get_32 (ibfd
, buf
);
9234 if (insn_check
== check_lo
9235 ? !ok_lo_toc_insn (insn
)
9236 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9237 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9241 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9242 sprintf (str
, "%#08x", insn
);
9243 info
->callbacks
->einfo
9244 /* xgettext:c-format */
9245 (_("%P: %H: toc optimization is not supported for"
9246 " %s instruction.\n"),
9247 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9254 case R_PPC64_TOC16_LO
:
9255 case R_PPC64_TOC16_HI
:
9256 case R_PPC64_TOC16_HA
:
9257 case R_PPC64_TOC16_DS
:
9258 case R_PPC64_TOC16_LO_DS
:
9259 /* In case we're taking addresses of toc entries. */
9260 case R_PPC64_ADDR64
:
9267 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9268 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9279 val
= h
->root
.u
.def
.value
;
9281 val
= sym
->st_value
;
9282 val
+= rel
->r_addend
;
9284 if (val
>= toc
->size
)
9287 if ((skip
[val
>> 3] & can_optimize
) != 0)
9294 case R_PPC64_TOC16_HA
:
9297 case R_PPC64_TOC16_LO_DS
:
9298 off
= rel
->r_offset
;
9299 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9300 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9306 if ((opc
& (0x3f << 2)) == (58u << 2))
9311 /* Wrong sort of reloc, or not a ld. We may
9312 as well clear ref_from_discarded too. */
9319 /* For the toc section, we only mark as used if this
9320 entry itself isn't unused. */
9321 else if ((used
[rel
->r_offset
>> 3]
9322 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9325 /* Do all the relocs again, to catch reference
9334 if (elf_section_data (sec
)->relocs
!= relstart
)
9338 /* Merge the used and skip arrays. Assume that TOC
9339 doublewords not appearing as either used or unused belong
9340 to to an entry more than one doubleword in size. */
9341 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9342 drop
< skip
+ (toc
->size
+ 7) / 8;
9347 *drop
&= ~ref_from_discarded
;
9348 if ((*drop
& can_optimize
) != 0)
9352 else if ((*drop
& ref_from_discarded
) != 0)
9355 last
= ref_from_discarded
;
9365 bfd_byte
*contents
, *src
;
9367 Elf_Internal_Sym
*sym
;
9368 bfd_boolean local_toc_syms
= FALSE
;
9370 /* Shuffle the toc contents, and at the same time convert the
9371 skip array from booleans into offsets. */
9372 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9375 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9377 for (src
= contents
, off
= 0, drop
= skip
;
9378 src
< contents
+ toc
->size
;
9381 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9386 memcpy (src
- off
, src
, 8);
9390 toc
->rawsize
= toc
->size
;
9391 toc
->size
= src
- contents
- off
;
9393 /* Adjust addends for relocs against the toc section sym,
9394 and optimize any accesses we can. */
9395 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9397 if (sec
->reloc_count
== 0
9398 || discarded_section (sec
))
9401 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9403 if (relstart
== NULL
)
9406 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9408 enum elf_ppc64_reloc_type r_type
;
9409 unsigned long r_symndx
;
9411 struct elf_link_hash_entry
*h
;
9414 r_type
= ELF64_R_TYPE (rel
->r_info
);
9421 case R_PPC64_TOC16_LO
:
9422 case R_PPC64_TOC16_HI
:
9423 case R_PPC64_TOC16_HA
:
9424 case R_PPC64_TOC16_DS
:
9425 case R_PPC64_TOC16_LO_DS
:
9426 case R_PPC64_ADDR64
:
9430 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9431 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9439 val
= h
->root
.u
.def
.value
;
9442 val
= sym
->st_value
;
9444 local_toc_syms
= TRUE
;
9447 val
+= rel
->r_addend
;
9449 if (val
> toc
->rawsize
)
9451 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9453 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9455 Elf_Internal_Rela
*tocrel
9456 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9457 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9461 case R_PPC64_TOC16_HA
:
9462 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9465 case R_PPC64_TOC16_LO_DS
:
9466 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9470 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9472 info
->callbacks
->einfo
9473 /* xgettext:c-format */
9474 (_("%P: %H: %s references "
9475 "optimized away TOC entry\n"),
9476 ibfd
, sec
, rel
->r_offset
,
9477 ppc64_elf_howto_table
[r_type
]->name
);
9478 bfd_set_error (bfd_error_bad_value
);
9481 rel
->r_addend
= tocrel
->r_addend
;
9482 elf_section_data (sec
)->relocs
= relstart
;
9486 if (h
!= NULL
|| sym
->st_value
!= 0)
9489 rel
->r_addend
-= skip
[val
>> 3];
9490 elf_section_data (sec
)->relocs
= relstart
;
9493 if (elf_section_data (sec
)->relocs
!= relstart
)
9497 /* We shouldn't have local or global symbols defined in the TOC,
9498 but handle them anyway. */
9499 if (local_syms
!= NULL
)
9500 for (sym
= local_syms
;
9501 sym
< local_syms
+ symtab_hdr
->sh_info
;
9503 if (sym
->st_value
!= 0
9504 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9508 if (sym
->st_value
> toc
->rawsize
)
9509 i
= toc
->rawsize
>> 3;
9511 i
= sym
->st_value
>> 3;
9513 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9517 (_("%s defined on removed toc entry"),
9518 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9521 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9522 sym
->st_value
= (bfd_vma
) i
<< 3;
9525 sym
->st_value
-= skip
[i
];
9526 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9529 /* Adjust any global syms defined in this toc input section. */
9530 if (toc_inf
.global_toc_syms
)
9533 toc_inf
.skip
= skip
;
9534 toc_inf
.global_toc_syms
= FALSE
;
9535 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9539 if (toc
->reloc_count
!= 0)
9541 Elf_Internal_Shdr
*rel_hdr
;
9542 Elf_Internal_Rela
*wrel
;
9545 /* Remove unused toc relocs, and adjust those we keep. */
9546 if (toc_relocs
== NULL
)
9547 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9549 if (toc_relocs
== NULL
)
9553 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9554 if ((skip
[rel
->r_offset
>> 3]
9555 & (ref_from_discarded
| can_optimize
)) == 0)
9557 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9558 wrel
->r_info
= rel
->r_info
;
9559 wrel
->r_addend
= rel
->r_addend
;
9562 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9563 &local_syms
, NULL
, NULL
))
9566 elf_section_data (toc
)->relocs
= toc_relocs
;
9567 toc
->reloc_count
= wrel
- toc_relocs
;
9568 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9569 sz
= rel_hdr
->sh_entsize
;
9570 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9573 else if (toc_relocs
!= NULL
9574 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9577 if (local_syms
!= NULL
9578 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9580 if (!info
->keep_memory
)
9583 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9591 /* Return true iff input section I references the TOC using
9592 instructions limited to +/-32k offsets. */
9595 ppc64_elf_has_small_toc_reloc (asection
*i
)
9597 return (is_ppc64_elf (i
->owner
)
9598 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9601 /* Allocate space for one GOT entry. */
9604 allocate_got (struct elf_link_hash_entry
*h
,
9605 struct bfd_link_info
*info
,
9606 struct got_entry
*gent
)
9608 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9610 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
9611 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9613 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9614 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9615 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9617 gent
->got
.offset
= got
->size
;
9618 got
->size
+= entsize
;
9620 dyn
= htab
->elf
.dynamic_sections_created
;
9621 if (h
->type
== STT_GNU_IFUNC
)
9623 htab
->elf
.irelplt
->size
+= rentsize
;
9624 htab
->got_reli_size
+= rentsize
;
9626 else if ((bfd_link_pic (info
)
9627 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
9628 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9629 || h
->root
.type
!= bfd_link_hash_undefweak
))
9631 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9632 relgot
->size
+= rentsize
;
9636 /* This function merges got entries in the same toc group. */
9639 merge_got_entries (struct got_entry
**pent
)
9641 struct got_entry
*ent
, *ent2
;
9643 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9644 if (!ent
->is_indirect
)
9645 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9646 if (!ent2
->is_indirect
9647 && ent2
->addend
== ent
->addend
9648 && ent2
->tls_type
== ent
->tls_type
9649 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9651 ent2
->is_indirect
= TRUE
;
9652 ent2
->got
.ent
= ent
;
9656 /* Allocate space in .plt, .got and associated reloc sections for
9660 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9662 struct bfd_link_info
*info
;
9663 struct ppc_link_hash_table
*htab
;
9665 struct ppc_link_hash_entry
*eh
;
9666 struct got_entry
**pgent
, *gent
;
9668 if (h
->root
.type
== bfd_link_hash_indirect
)
9671 info
= (struct bfd_link_info
*) inf
;
9672 htab
= ppc_hash_table (info
);
9676 eh
= (struct ppc_link_hash_entry
*) h
;
9677 /* Run through the TLS GD got entries first if we're changing them
9679 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
9680 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9681 if (gent
->got
.refcount
> 0
9682 && (gent
->tls_type
& TLS_GD
) != 0)
9684 /* This was a GD entry that has been converted to TPREL. If
9685 there happens to be a TPREL entry we can use that one. */
9686 struct got_entry
*ent
;
9687 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9688 if (ent
->got
.refcount
> 0
9689 && (ent
->tls_type
& TLS_TPREL
) != 0
9690 && ent
->addend
== gent
->addend
9691 && ent
->owner
== gent
->owner
)
9693 gent
->got
.refcount
= 0;
9697 /* If not, then we'll be using our own TPREL entry. */
9698 if (gent
->got
.refcount
!= 0)
9699 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9702 /* Remove any list entry that won't generate a word in the GOT before
9703 we call merge_got_entries. Otherwise we risk merging to empty
9705 pgent
= &h
->got
.glist
;
9706 while ((gent
= *pgent
) != NULL
)
9707 if (gent
->got
.refcount
> 0)
9709 if ((gent
->tls_type
& TLS_LD
) != 0
9712 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9713 *pgent
= gent
->next
;
9716 pgent
= &gent
->next
;
9719 *pgent
= gent
->next
;
9721 if (!htab
->do_multi_toc
)
9722 merge_got_entries (&h
->got
.glist
);
9724 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9725 if (!gent
->is_indirect
)
9727 /* Make sure this symbol is output as a dynamic symbol.
9728 Undefined weak syms won't yet be marked as dynamic,
9729 nor will all TLS symbols. */
9730 if (h
->dynindx
== -1
9732 && h
->type
!= STT_GNU_IFUNC
9733 && htab
->elf
.dynamic_sections_created
)
9735 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9739 if (!is_ppc64_elf (gent
->owner
))
9742 allocate_got (h
, info
, gent
);
9745 if (!htab
->elf
.dynamic_sections_created
9746 && h
->type
!= STT_GNU_IFUNC
)
9747 eh
->dyn_relocs
= NULL
;
9749 if (eh
->dyn_relocs
!= NULL
)
9751 struct elf_dyn_relocs
*p
, **pp
;
9753 /* In the shared -Bsymbolic case, discard space allocated for
9754 dynamic pc-relative relocs against symbols which turn out to
9755 be defined in regular objects. For the normal shared case,
9756 discard space for relocs that have become local due to symbol
9757 visibility changes. */
9759 if (bfd_link_pic (info
))
9761 /* Relocs that use pc_count are those that appear on a call
9762 insn, or certain REL relocs (see must_be_dyn_reloc) that
9763 can be generated via assembly. We want calls to
9764 protected symbols to resolve directly to the function
9765 rather than going via the plt. If people want function
9766 pointer comparisons to work as expected then they should
9767 avoid writing weird assembly. */
9768 if (SYMBOL_CALLS_LOCAL (info
, h
))
9770 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
9772 p
->count
-= p
->pc_count
;
9781 /* Also discard relocs on undefined weak syms with
9782 non-default visibility. */
9783 if (eh
->dyn_relocs
!= NULL
9784 && h
->root
.type
== bfd_link_hash_undefweak
)
9786 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9787 eh
->dyn_relocs
= NULL
;
9789 /* Make sure this symbol is output as a dynamic symbol.
9790 Undefined weak syms won't yet be marked as dynamic. */
9791 else if (h
->dynindx
== -1
9792 && !h
->forced_local
)
9794 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9799 else if (h
->type
== STT_GNU_IFUNC
)
9801 /* A plt entry is always created when making direct calls to
9802 an ifunc, even when building a static executable, but
9803 that doesn't cover all cases. We may have only an ifunc
9804 initialised function pointer for a given ifunc symbol.
9806 For ELFv2, dynamic relocations are not required when
9807 generating a global entry PLT stub. */
9808 if (abiversion (info
->output_bfd
) >= 2)
9810 if (global_entry_stub (h
))
9811 eh
->dyn_relocs
= NULL
;
9814 /* For ELFv1 we have function descriptors. Descriptors need
9815 to be treated like PLT entries and thus have dynamic
9816 relocations. One exception is when the function
9817 descriptor is copied into .dynbss (which should only
9818 happen with ancient versions of gcc). */
9819 else if (h
->needs_copy
)
9820 eh
->dyn_relocs
= NULL
;
9822 else if (ELIMINATE_COPY_RELOCS
)
9824 /* For the non-pic case, discard space for relocs against
9825 symbols which turn out to need copy relocs or are not
9828 /* First make sure this symbol is output as a dynamic symbol.
9829 Undefined weak syms won't yet be marked as dynamic. */
9830 if (h
->root
.type
== bfd_link_hash_undefweak
9835 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
9840 || h
->dynindx
== -1)
9841 eh
->dyn_relocs
= NULL
;
9844 /* Finally, allocate space. */
9845 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9847 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9848 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9849 sreloc
= htab
->elf
.irelplt
;
9850 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9854 if ((htab
->elf
.dynamic_sections_created
9856 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info
), h
))
9857 || h
->type
== STT_GNU_IFUNC
)
9859 struct plt_entry
*pent
;
9860 bfd_boolean doneone
= FALSE
;
9861 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9862 if (pent
->plt
.refcount
> 0)
9864 if (!htab
->elf
.dynamic_sections_created
9865 || h
->dynindx
== -1)
9868 pent
->plt
.offset
= s
->size
;
9869 s
->size
+= PLT_ENTRY_SIZE (htab
);
9870 s
= htab
->elf
.irelplt
;
9874 /* If this is the first .plt entry, make room for the special
9878 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9880 pent
->plt
.offset
= s
->size
;
9882 /* Make room for this entry. */
9883 s
->size
+= PLT_ENTRY_SIZE (htab
);
9885 /* Make room for the .glink code. */
9888 s
->size
+= GLINK_CALL_STUB_SIZE
;
9891 /* We need bigger stubs past index 32767. */
9892 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
9899 /* We also need to make an entry in the .rela.plt section. */
9900 s
= htab
->elf
.srelplt
;
9902 s
->size
+= sizeof (Elf64_External_Rela
);
9906 pent
->plt
.offset
= (bfd_vma
) -1;
9909 h
->plt
.plist
= NULL
;
9915 h
->plt
.plist
= NULL
;
9922 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9923 to set up space for global entry stubs. These are put in glink,
9924 after the branch table. */
9927 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
9929 struct bfd_link_info
*info
;
9930 struct ppc_link_hash_table
*htab
;
9931 struct plt_entry
*pent
;
9934 if (h
->root
.type
== bfd_link_hash_indirect
)
9937 if (!h
->pointer_equality_needed
)
9944 htab
= ppc_hash_table (info
);
9949 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9950 if (pent
->plt
.offset
!= (bfd_vma
) -1
9951 && pent
->addend
== 0)
9953 /* For ELFv2, if this symbol is not defined in a regular file
9954 and we are not generating a shared library or pie, then we
9955 need to define the symbol in the executable on a call stub.
9956 This is to avoid text relocations. */
9957 s
->size
= (s
->size
+ 15) & -16;
9958 h
->root
.type
= bfd_link_hash_defined
;
9959 h
->root
.u
.def
.section
= s
;
9960 h
->root
.u
.def
.value
= s
->size
;
9967 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9968 read-only sections. */
9971 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info
)
9973 if (h
->root
.type
== bfd_link_hash_indirect
)
9976 if (readonly_dynrelocs (h
))
9978 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
9980 /* Not an error, just cut short the traversal. */
9986 /* Set the sizes of the dynamic sections. */
9989 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
9990 struct bfd_link_info
*info
)
9992 struct ppc_link_hash_table
*htab
;
9997 struct got_entry
*first_tlsld
;
9999 htab
= ppc_hash_table (info
);
10003 dynobj
= htab
->elf
.dynobj
;
10004 if (dynobj
== NULL
)
10007 if (htab
->elf
.dynamic_sections_created
)
10009 /* Set the contents of the .interp section to the interpreter. */
10010 if (bfd_link_executable (info
) && !info
->nointerp
)
10012 s
= bfd_get_linker_section (dynobj
, ".interp");
10015 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10016 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10020 /* Set up .got offsets for local syms, and space for local dynamic
10022 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10024 struct got_entry
**lgot_ents
;
10025 struct got_entry
**end_lgot_ents
;
10026 struct plt_entry
**local_plt
;
10027 struct plt_entry
**end_local_plt
;
10028 unsigned char *lgot_masks
;
10029 bfd_size_type locsymcount
;
10030 Elf_Internal_Shdr
*symtab_hdr
;
10032 if (!is_ppc64_elf (ibfd
))
10035 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10037 struct ppc_dyn_relocs
*p
;
10039 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10041 if (!bfd_is_abs_section (p
->sec
)
10042 && bfd_is_abs_section (p
->sec
->output_section
))
10044 /* Input section has been discarded, either because
10045 it is a copy of a linkonce section or due to
10046 linker script /DISCARD/, so we'll be discarding
10049 else if (p
->count
!= 0)
10051 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
10053 srel
= htab
->elf
.irelplt
;
10054 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10055 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10056 info
->flags
|= DF_TEXTREL
;
10061 lgot_ents
= elf_local_got_ents (ibfd
);
10065 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10066 locsymcount
= symtab_hdr
->sh_info
;
10067 end_lgot_ents
= lgot_ents
+ locsymcount
;
10068 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10069 end_local_plt
= local_plt
+ locsymcount
;
10070 lgot_masks
= (unsigned char *) end_local_plt
;
10071 s
= ppc64_elf_tdata (ibfd
)->got
;
10072 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10074 struct got_entry
**pent
, *ent
;
10077 while ((ent
= *pent
) != NULL
)
10078 if (ent
->got
.refcount
> 0)
10080 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10082 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10087 unsigned int ent_size
= 8;
10088 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10090 ent
->got
.offset
= s
->size
;
10091 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10096 s
->size
+= ent_size
;
10097 if ((*lgot_masks
& PLT_IFUNC
) != 0)
10099 htab
->elf
.irelplt
->size
+= rel_size
;
10100 htab
->got_reli_size
+= rel_size
;
10102 else if (bfd_link_pic (info
))
10104 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10105 srel
->size
+= rel_size
;
10114 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
10115 for (; local_plt
< end_local_plt
; ++local_plt
)
10117 struct plt_entry
*ent
;
10119 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10120 if (ent
->plt
.refcount
> 0)
10122 s
= htab
->elf
.iplt
;
10123 ent
->plt
.offset
= s
->size
;
10124 s
->size
+= PLT_ENTRY_SIZE (htab
);
10126 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10129 ent
->plt
.offset
= (bfd_vma
) -1;
10133 /* Allocate global sym .plt and .got entries, and space for global
10134 sym dynamic relocs. */
10135 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10136 /* Stash the end of glink branch table. */
10137 if (htab
->glink
!= NULL
)
10138 htab
->glink
->rawsize
= htab
->glink
->size
;
10140 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10141 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10143 first_tlsld
= NULL
;
10144 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10146 struct got_entry
*ent
;
10148 if (!is_ppc64_elf (ibfd
))
10151 ent
= ppc64_tlsld_got (ibfd
);
10152 if (ent
->got
.refcount
> 0)
10154 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10156 ent
->is_indirect
= TRUE
;
10157 ent
->got
.ent
= first_tlsld
;
10161 if (first_tlsld
== NULL
)
10163 s
= ppc64_elf_tdata (ibfd
)->got
;
10164 ent
->got
.offset
= s
->size
;
10167 if (bfd_link_pic (info
))
10169 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10170 srel
->size
+= sizeof (Elf64_External_Rela
);
10175 ent
->got
.offset
= (bfd_vma
) -1;
10178 /* We now have determined the sizes of the various dynamic sections.
10179 Allocate memory for them. */
10181 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10183 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10186 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
10187 /* These haven't been allocated yet; don't strip. */
10189 else if (s
== htab
->elf
.sgot
10190 || s
== htab
->elf
.splt
10191 || s
== htab
->elf
.iplt
10192 || s
== htab
->glink
10193 || s
== htab
->dynbss
)
10195 /* Strip this section if we don't need it; see the
10198 else if (s
== htab
->glink_eh_frame
)
10200 if (!bfd_is_abs_section (s
->output_section
))
10201 /* Not sized yet. */
10204 else if (CONST_STRNEQ (s
->name
, ".rela"))
10208 if (s
!= htab
->elf
.srelplt
)
10211 /* We use the reloc_count field as a counter if we need
10212 to copy relocs into the output file. */
10213 s
->reloc_count
= 0;
10218 /* It's not one of our sections, so don't allocate space. */
10224 /* If we don't need this section, strip it from the
10225 output file. This is mostly to handle .rela.bss and
10226 .rela.plt. We must create both sections in
10227 create_dynamic_sections, because they must be created
10228 before the linker maps input sections to output
10229 sections. The linker does that before
10230 adjust_dynamic_symbol is called, and it is that
10231 function which decides whether anything needs to go
10232 into these sections. */
10233 s
->flags
|= SEC_EXCLUDE
;
10237 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10240 /* Allocate memory for the section contents. We use bfd_zalloc
10241 here in case unused entries are not reclaimed before the
10242 section's contents are written out. This should not happen,
10243 but this way if it does we get a R_PPC64_NONE reloc in .rela
10244 sections instead of garbage.
10245 We also rely on the section contents being zero when writing
10247 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10248 if (s
->contents
== NULL
)
10252 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10254 if (!is_ppc64_elf (ibfd
))
10257 s
= ppc64_elf_tdata (ibfd
)->got
;
10258 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10261 s
->flags
|= SEC_EXCLUDE
;
10264 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10265 if (s
->contents
== NULL
)
10269 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10273 s
->flags
|= SEC_EXCLUDE
;
10276 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10277 if (s
->contents
== NULL
)
10280 s
->reloc_count
= 0;
10285 if (htab
->elf
.dynamic_sections_created
)
10287 bfd_boolean tls_opt
;
10289 /* Add some entries to the .dynamic section. We fill in the
10290 values later, in ppc64_elf_finish_dynamic_sections, but we
10291 must add the entries now so that we get the correct size for
10292 the .dynamic section. The DT_DEBUG entry is filled in by the
10293 dynamic linker and used by the debugger. */
10294 #define add_dynamic_entry(TAG, VAL) \
10295 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10297 if (bfd_link_executable (info
))
10299 if (!add_dynamic_entry (DT_DEBUG
, 0))
10303 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10305 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10306 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10307 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10308 || !add_dynamic_entry (DT_JMPREL
, 0)
10309 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10313 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10315 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10316 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10320 tls_opt
= (htab
->params
->tls_get_addr_opt
10321 && htab
->tls_get_addr_fd
!= NULL
10322 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
10323 if (tls_opt
|| !htab
->opd_abi
)
10325 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10331 if (!add_dynamic_entry (DT_RELA
, 0)
10332 || !add_dynamic_entry (DT_RELASZ
, 0)
10333 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10336 /* If any dynamic relocs apply to a read-only section,
10337 then we need a DT_TEXTREL entry. */
10338 if ((info
->flags
& DF_TEXTREL
) == 0)
10339 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
10341 if ((info
->flags
& DF_TEXTREL
) != 0)
10343 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10348 #undef add_dynamic_entry
10353 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10356 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10358 if (h
->plt
.plist
!= NULL
10360 && !h
->pointer_equality_needed
)
10363 return _bfd_elf_hash_symbol (h
);
10366 /* Determine the type of stub needed, if any, for a call. */
10368 static inline enum ppc_stub_type
10369 ppc_type_of_stub (asection
*input_sec
,
10370 const Elf_Internal_Rela
*rel
,
10371 struct ppc_link_hash_entry
**hash
,
10372 struct plt_entry
**plt_ent
,
10373 bfd_vma destination
,
10374 unsigned long local_off
)
10376 struct ppc_link_hash_entry
*h
= *hash
;
10378 bfd_vma branch_offset
;
10379 bfd_vma max_branch_offset
;
10380 enum elf_ppc64_reloc_type r_type
;
10384 struct plt_entry
*ent
;
10385 struct ppc_link_hash_entry
*fdh
= h
;
10387 && h
->oh
->is_func_descriptor
)
10389 fdh
= ppc_follow_link (h
->oh
);
10393 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10394 if (ent
->addend
== rel
->r_addend
10395 && ent
->plt
.offset
!= (bfd_vma
) -1)
10398 return ppc_stub_plt_call
;
10401 /* Here, we know we don't have a plt entry. If we don't have a
10402 either a defined function descriptor or a defined entry symbol
10403 in a regular object file, then it is pointless trying to make
10404 any other type of stub. */
10405 if (!is_static_defined (&fdh
->elf
)
10406 && !is_static_defined (&h
->elf
))
10407 return ppc_stub_none
;
10409 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10411 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10412 struct plt_entry
**local_plt
= (struct plt_entry
**)
10413 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10414 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10416 if (local_plt
[r_symndx
] != NULL
)
10418 struct plt_entry
*ent
;
10420 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10421 if (ent
->addend
== rel
->r_addend
10422 && ent
->plt
.offset
!= (bfd_vma
) -1)
10425 return ppc_stub_plt_call
;
10430 /* Determine where the call point is. */
10431 location
= (input_sec
->output_offset
10432 + input_sec
->output_section
->vma
10435 branch_offset
= destination
- location
;
10436 r_type
= ELF64_R_TYPE (rel
->r_info
);
10438 /* Determine if a long branch stub is needed. */
10439 max_branch_offset
= 1 << 25;
10440 if (r_type
!= R_PPC64_REL24
)
10441 max_branch_offset
= 1 << 15;
10443 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10444 /* We need a stub. Figure out whether a long_branch or plt_branch
10445 is needed later. */
10446 return ppc_stub_long_branch
;
10448 return ppc_stub_none
;
10451 /* With power7 weakly ordered memory model, it is possible for ld.so
10452 to update a plt entry in one thread and have another thread see a
10453 stale zero toc entry. To avoid this we need some sort of acquire
10454 barrier in the call stub. One solution is to make the load of the
10455 toc word seem to appear to depend on the load of the function entry
10456 word. Another solution is to test for r2 being zero, and branch to
10457 the appropriate glink entry if so.
10459 . fake dep barrier compare
10460 . ld 12,xxx(2) ld 12,xxx(2)
10461 . mtctr 12 mtctr 12
10462 . xor 11,12,12 ld 2,xxx+8(2)
10463 . add 2,2,11 cmpldi 2,0
10464 . ld 2,xxx+8(2) bnectr+
10465 . bctr b <glink_entry>
10467 The solution involving the compare turns out to be faster, so
10468 that's what we use unless the branch won't reach. */
10470 #define ALWAYS_USE_FAKE_DEP 0
10471 #define ALWAYS_EMIT_R2SAVE 0
10473 #define PPC_LO(v) ((v) & 0xffff)
10474 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10475 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10477 static inline unsigned int
10478 plt_stub_size (struct ppc_link_hash_table
*htab
,
10479 struct ppc_stub_hash_entry
*stub_entry
,
10482 unsigned size
= 12;
10484 if (ALWAYS_EMIT_R2SAVE
10485 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10487 if (PPC_HA (off
) != 0)
10492 if (htab
->params
->plt_static_chain
)
10494 if (htab
->params
->plt_thread_safe
10495 && htab
->elf
.dynamic_sections_created
10496 && stub_entry
->h
!= NULL
10497 && stub_entry
->h
->elf
.dynindx
!= -1)
10499 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
10502 if (stub_entry
->h
!= NULL
10503 && (stub_entry
->h
== htab
->tls_get_addr_fd
10504 || stub_entry
->h
== htab
->tls_get_addr
)
10505 && htab
->params
->tls_get_addr_opt
)
10510 /* If this stub would cross fewer 2**plt_stub_align boundaries if we align,
10511 then return the padding needed to do so. */
10512 static inline unsigned int
10513 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10514 struct ppc_stub_hash_entry
*stub_entry
,
10517 int stub_align
= 1 << htab
->params
->plt_stub_align
;
10518 unsigned stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10519 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10521 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10522 > ((stub_size
- 1) & -stub_align
))
10523 return stub_align
- (stub_off
& (stub_align
- 1));
10527 /* Build a .plt call stub. */
10529 static inline bfd_byte
*
10530 build_plt_stub (struct ppc_link_hash_table
*htab
,
10531 struct ppc_stub_hash_entry
*stub_entry
,
10532 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10534 bfd
*obfd
= htab
->params
->stub_bfd
;
10535 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10536 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10537 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10538 && htab
->elf
.dynamic_sections_created
10539 && stub_entry
->h
!= NULL
10540 && stub_entry
->h
->elf
.dynindx
!= -1);
10541 bfd_boolean use_fake_dep
= plt_thread_safe
;
10542 bfd_vma cmp_branch_off
= 0;
10544 if (!ALWAYS_USE_FAKE_DEP
10547 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10548 || stub_entry
->h
== htab
->tls_get_addr
)
10549 && htab
->params
->tls_get_addr_opt
))
10551 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10552 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10553 / PLT_ENTRY_SIZE (htab
));
10554 bfd_vma glinkoff
= GLINK_CALL_STUB_SIZE
+ pltindex
* 8;
10557 if (pltindex
> 32768)
10558 glinkoff
+= (pltindex
- 32768) * 4;
10560 + htab
->glink
->output_offset
10561 + htab
->glink
->output_section
->vma
);
10562 from
= (p
- stub_entry
->group
->stub_sec
->contents
10563 + 4 * (ALWAYS_EMIT_R2SAVE
10564 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10565 + 4 * (PPC_HA (offset
) != 0)
10566 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10567 != PPC_HA (offset
))
10568 + 4 * (plt_static_chain
!= 0)
10570 + stub_entry
->group
->stub_sec
->output_offset
10571 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10572 cmp_branch_off
= to
- from
;
10573 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10576 if (PPC_HA (offset
) != 0)
10580 if (ALWAYS_EMIT_R2SAVE
10581 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10582 r
[0].r_offset
+= 4;
10583 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10584 r
[1].r_offset
= r
[0].r_offset
+ 4;
10585 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10586 r
[1].r_addend
= r
[0].r_addend
;
10589 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10591 r
[2].r_offset
= r
[1].r_offset
+ 4;
10592 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10593 r
[2].r_addend
= r
[0].r_addend
;
10597 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10598 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10599 r
[2].r_addend
= r
[0].r_addend
+ 8;
10600 if (plt_static_chain
)
10602 r
[3].r_offset
= r
[2].r_offset
+ 4;
10603 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10604 r
[3].r_addend
= r
[0].r_addend
+ 16;
10609 if (ALWAYS_EMIT_R2SAVE
10610 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10611 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10614 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10615 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10619 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10620 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10623 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10625 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10628 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10633 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10634 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10636 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10637 if (plt_static_chain
)
10638 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10645 if (ALWAYS_EMIT_R2SAVE
10646 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10647 r
[0].r_offset
+= 4;
10648 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10651 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10653 r
[1].r_offset
= r
[0].r_offset
+ 4;
10654 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10655 r
[1].r_addend
= r
[0].r_addend
;
10659 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10660 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10661 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10662 if (plt_static_chain
)
10664 r
[2].r_offset
= r
[1].r_offset
+ 4;
10665 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10666 r
[2].r_addend
= r
[0].r_addend
+ 8;
10671 if (ALWAYS_EMIT_R2SAVE
10672 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10673 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10674 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10676 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10678 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
10681 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10686 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
10687 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
10689 if (plt_static_chain
)
10690 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
10691 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
10694 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
10696 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
10697 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
10698 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
10701 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
10705 /* Build a special .plt call stub for __tls_get_addr. */
10707 #define LD_R11_0R3 0xe9630000
10708 #define LD_R12_0R3 0xe9830000
10709 #define MR_R0_R3 0x7c601b78
10710 #define CMPDI_R11_0 0x2c2b0000
10711 #define ADD_R3_R12_R13 0x7c6c6a14
10712 #define BEQLR 0x4d820020
10713 #define MR_R3_R0 0x7c030378
10714 #define STD_R11_0R1 0xf9610000
10715 #define BCTRL 0x4e800421
10716 #define LD_R11_0R1 0xe9610000
10717 #define MTLR_R11 0x7d6803a6
10719 static inline bfd_byte
*
10720 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
10721 struct ppc_stub_hash_entry
*stub_entry
,
10722 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10724 bfd
*obfd
= htab
->params
->stub_bfd
;
10726 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
10727 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
10728 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
10729 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
10730 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
10731 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
10732 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
10733 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
10734 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10737 r
[0].r_offset
+= 9 * 4;
10738 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10739 bfd_put_32 (obfd
, BCTRL
, p
- 4);
10741 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10742 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10743 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
10744 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
10749 static Elf_Internal_Rela
*
10750 get_relocs (asection
*sec
, int count
)
10752 Elf_Internal_Rela
*relocs
;
10753 struct bfd_elf_section_data
*elfsec_data
;
10755 elfsec_data
= elf_section_data (sec
);
10756 relocs
= elfsec_data
->relocs
;
10757 if (relocs
== NULL
)
10759 bfd_size_type relsize
;
10760 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10761 relocs
= bfd_alloc (sec
->owner
, relsize
);
10762 if (relocs
== NULL
)
10764 elfsec_data
->relocs
= relocs
;
10765 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10766 sizeof (Elf_Internal_Shdr
));
10767 if (elfsec_data
->rela
.hdr
== NULL
)
10769 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10770 * sizeof (Elf64_External_Rela
));
10771 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10772 sec
->reloc_count
= 0;
10774 relocs
+= sec
->reloc_count
;
10775 sec
->reloc_count
+= count
;
10780 get_r2off (struct bfd_link_info
*info
,
10781 struct ppc_stub_hash_entry
*stub_entry
)
10783 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10784 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10788 /* Support linking -R objects. Get the toc pointer from the
10791 if (!htab
->opd_abi
)
10793 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10794 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10796 if (strcmp (opd
->name
, ".opd") != 0
10797 || opd
->reloc_count
!= 0)
10799 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for `%T'\n"),
10800 stub_entry
->h
->elf
.root
.root
.string
);
10801 bfd_set_error (bfd_error_bad_value
);
10802 return (bfd_vma
) -1;
10804 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10805 return (bfd_vma
) -1;
10806 r2off
= bfd_get_64 (opd
->owner
, buf
);
10807 r2off
-= elf_gp (info
->output_bfd
);
10809 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10814 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10816 struct ppc_stub_hash_entry
*stub_entry
;
10817 struct ppc_branch_hash_entry
*br_entry
;
10818 struct bfd_link_info
*info
;
10819 struct ppc_link_hash_table
*htab
;
10824 Elf_Internal_Rela
*r
;
10827 /* Massage our args to the form they really have. */
10828 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10831 htab
= ppc_hash_table (info
);
10835 /* Make a note of the offset within the stubs for this entry. */
10836 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10837 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10839 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10840 switch (stub_entry
->stub_type
)
10842 case ppc_stub_long_branch
:
10843 case ppc_stub_long_branch_r2off
:
10844 /* Branches are relative. This is where we are going to. */
10845 dest
= (stub_entry
->target_value
10846 + stub_entry
->target_section
->output_offset
10847 + stub_entry
->target_section
->output_section
->vma
);
10848 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10851 /* And this is where we are coming from. */
10852 off
-= (stub_entry
->stub_offset
10853 + stub_entry
->group
->stub_sec
->output_offset
10854 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10857 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10859 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10861 if (r2off
== (bfd_vma
) -1)
10863 htab
->stub_error
= TRUE
;
10866 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), loc
);
10869 if (PPC_HA (r2off
) != 0)
10871 bfd_put_32 (htab
->params
->stub_bfd
,
10872 ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
10876 if (PPC_LO (r2off
) != 0)
10878 bfd_put_32 (htab
->params
->stub_bfd
,
10879 ADDI_R2_R2
| PPC_LO (r2off
), loc
);
10885 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
10887 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10889 info
->callbacks
->einfo
10890 (_("%P: long branch stub `%s' offset overflow\n"),
10891 stub_entry
->root
.string
);
10892 htab
->stub_error
= TRUE
;
10896 if (info
->emitrelocations
)
10898 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
10901 r
->r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10902 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10903 r
->r_addend
= dest
;
10904 if (stub_entry
->h
!= NULL
)
10906 struct elf_link_hash_entry
**hashes
;
10907 unsigned long symndx
;
10908 struct ppc_link_hash_entry
*h
;
10910 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10911 if (hashes
== NULL
)
10913 bfd_size_type hsize
;
10915 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10916 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10917 if (hashes
== NULL
)
10919 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10920 htab
->stub_globals
= 1;
10922 symndx
= htab
->stub_globals
++;
10924 hashes
[symndx
] = &h
->elf
;
10925 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
10926 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10927 h
= ppc_follow_link (h
->oh
);
10928 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
10929 /* H is an opd symbol. The addend must be zero. */
10933 off
= (h
->elf
.root
.u
.def
.value
10934 + h
->elf
.root
.u
.def
.section
->output_offset
10935 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10936 r
->r_addend
-= off
;
10942 case ppc_stub_plt_branch
:
10943 case ppc_stub_plt_branch_r2off
:
10944 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10945 stub_entry
->root
.string
+ 9,
10947 if (br_entry
== NULL
)
10949 info
->callbacks
->einfo (_("%P: can't find branch stub `%s'\n"),
10950 stub_entry
->root
.string
);
10951 htab
->stub_error
= TRUE
;
10955 dest
= (stub_entry
->target_value
10956 + stub_entry
->target_section
->output_offset
10957 + stub_entry
->target_section
->output_section
->vma
);
10958 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10959 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10961 bfd_put_64 (htab
->brlt
->owner
, dest
,
10962 htab
->brlt
->contents
+ br_entry
->offset
);
10964 if (br_entry
->iter
== htab
->stub_iteration
)
10966 br_entry
->iter
= 0;
10968 if (htab
->relbrlt
!= NULL
)
10970 /* Create a reloc for the branch lookup table entry. */
10971 Elf_Internal_Rela rela
;
10974 rela
.r_offset
= (br_entry
->offset
10975 + htab
->brlt
->output_offset
10976 + htab
->brlt
->output_section
->vma
);
10977 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10978 rela
.r_addend
= dest
;
10980 rl
= htab
->relbrlt
->contents
;
10981 rl
+= (htab
->relbrlt
->reloc_count
++
10982 * sizeof (Elf64_External_Rela
));
10983 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
10985 else if (info
->emitrelocations
)
10987 r
= get_relocs (htab
->brlt
, 1);
10990 /* brlt, being SEC_LINKER_CREATED does not go through the
10991 normal reloc processing. Symbols and offsets are not
10992 translated from input file to output file form, so
10993 set up the offset per the output file. */
10994 r
->r_offset
= (br_entry
->offset
10995 + htab
->brlt
->output_offset
10996 + htab
->brlt
->output_section
->vma
);
10997 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10998 r
->r_addend
= dest
;
11002 dest
= (br_entry
->offset
11003 + htab
->brlt
->output_offset
11004 + htab
->brlt
->output_section
->vma
);
11007 - elf_gp (htab
->brlt
->output_section
->owner
)
11008 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11010 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11012 info
->callbacks
->einfo
11013 (_("%P: linkage table error against `%T'\n"),
11014 stub_entry
->root
.string
);
11015 bfd_set_error (bfd_error_bad_value
);
11016 htab
->stub_error
= TRUE
;
11020 if (info
->emitrelocations
)
11022 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11025 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11026 if (bfd_big_endian (info
->output_bfd
))
11027 r
[0].r_offset
+= 2;
11028 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
11029 r
[0].r_offset
+= 4;
11030 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11031 r
[0].r_addend
= dest
;
11032 if (PPC_HA (off
) != 0)
11034 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11035 r
[1].r_offset
= r
[0].r_offset
+ 4;
11036 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11037 r
[1].r_addend
= r
[0].r_addend
;
11041 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11043 if (PPC_HA (off
) != 0)
11046 bfd_put_32 (htab
->params
->stub_bfd
,
11047 ADDIS_R12_R2
| PPC_HA (off
), loc
);
11049 bfd_put_32 (htab
->params
->stub_bfd
,
11050 LD_R12_0R12
| PPC_LO (off
), loc
);
11055 bfd_put_32 (htab
->params
->stub_bfd
,
11056 LD_R12_0R2
| PPC_LO (off
), loc
);
11061 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11063 if (r2off
== (bfd_vma
) -1)
11065 htab
->stub_error
= TRUE
;
11069 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), loc
);
11072 if (PPC_HA (off
) != 0)
11075 bfd_put_32 (htab
->params
->stub_bfd
,
11076 ADDIS_R12_R2
| PPC_HA (off
), loc
);
11078 bfd_put_32 (htab
->params
->stub_bfd
,
11079 LD_R12_0R12
| PPC_LO (off
), loc
);
11082 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), loc
);
11084 if (PPC_HA (r2off
) != 0)
11088 bfd_put_32 (htab
->params
->stub_bfd
,
11089 ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
11091 if (PPC_LO (r2off
) != 0)
11095 bfd_put_32 (htab
->params
->stub_bfd
,
11096 ADDI_R2_R2
| PPC_LO (r2off
), loc
);
11100 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, loc
);
11102 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, loc
);
11105 case ppc_stub_plt_call
:
11106 case ppc_stub_plt_call_r2save
:
11107 if (stub_entry
->h
!= NULL
11108 && stub_entry
->h
->is_func_descriptor
11109 && stub_entry
->h
->oh
!= NULL
)
11111 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11113 /* If the old-ABI "dot-symbol" is undefined make it weak so
11114 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11115 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11116 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11117 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11118 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11121 /* Now build the stub. */
11122 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11123 if (dest
>= (bfd_vma
) -2)
11126 plt
= htab
->elf
.splt
;
11127 if (!htab
->elf
.dynamic_sections_created
11128 || stub_entry
->h
== NULL
11129 || stub_entry
->h
->elf
.dynindx
== -1)
11130 plt
= htab
->elf
.iplt
;
11132 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
11134 if (stub_entry
->h
== NULL
11135 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
11137 Elf_Internal_Rela rela
;
11140 rela
.r_offset
= dest
;
11142 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
11144 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
11145 rela
.r_addend
= (stub_entry
->target_value
11146 + stub_entry
->target_section
->output_offset
11147 + stub_entry
->target_section
->output_section
->vma
);
11149 rl
= (htab
->elf
.irelplt
->contents
11150 + (htab
->elf
.irelplt
->reloc_count
++
11151 * sizeof (Elf64_External_Rela
)));
11152 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
11153 stub_entry
->plt_ent
->plt
.offset
|= 1;
11157 - elf_gp (plt
->output_section
->owner
)
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 /* xgettext:c-format */
11164 (_("%P: linkage table error against `%T'\n"),
11165 stub_entry
->h
!= NULL
11166 ? stub_entry
->h
->elf
.root
.root
.string
11168 bfd_set_error (bfd_error_bad_value
);
11169 htab
->stub_error
= TRUE
;
11173 if (htab
->params
->plt_stub_align
!= 0)
11175 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11177 stub_entry
->group
->stub_sec
->size
+= pad
;
11178 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11183 if (info
->emitrelocations
)
11185 r
= get_relocs (stub_entry
->group
->stub_sec
,
11186 ((PPC_HA (off
) != 0)
11188 ? 2 + (htab
->params
->plt_static_chain
11189 && PPC_HA (off
+ 16) == PPC_HA (off
))
11193 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11194 if (bfd_big_endian (info
->output_bfd
))
11195 r
[0].r_offset
+= 2;
11196 r
[0].r_addend
= dest
;
11198 if (stub_entry
->h
!= NULL
11199 && (stub_entry
->h
== htab
->tls_get_addr_fd
11200 || stub_entry
->h
== htab
->tls_get_addr
)
11201 && htab
->params
->tls_get_addr_opt
)
11202 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
11204 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
11208 case ppc_stub_save_res
:
11216 stub_entry
->group
->stub_sec
->size
+= size
;
11218 if (htab
->params
->emit_stub_syms
)
11220 struct elf_link_hash_entry
*h
;
11223 const char *const stub_str
[] = { "long_branch",
11224 "long_branch_r2off",
11226 "plt_branch_r2off",
11230 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11231 len2
= strlen (stub_entry
->root
.string
);
11232 name
= bfd_malloc (len1
+ len2
+ 2);
11235 memcpy (name
, stub_entry
->root
.string
, 9);
11236 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11237 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11238 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
11241 if (h
->root
.type
== bfd_link_hash_new
)
11243 h
->root
.type
= bfd_link_hash_defined
;
11244 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11245 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11246 h
->ref_regular
= 1;
11247 h
->def_regular
= 1;
11248 h
->ref_regular_nonweak
= 1;
11249 h
->forced_local
= 1;
11251 h
->root
.linker_def
= 1;
11258 /* As above, but don't actually build the stub. Just bump offset so
11259 we know stub section sizes, and select plt_branch stubs where
11260 long_branch stubs won't do. */
11263 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11265 struct ppc_stub_hash_entry
*stub_entry
;
11266 struct bfd_link_info
*info
;
11267 struct ppc_link_hash_table
*htab
;
11271 /* Massage our args to the form they really have. */
11272 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11275 htab
= ppc_hash_table (info
);
11279 if (stub_entry
->h
!= NULL
11280 && stub_entry
->h
->save_res
11281 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11282 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
11284 /* Don't make stubs to out-of-line register save/restore
11285 functions. Instead, emit copies of the functions. */
11286 stub_entry
->group
->needs_save_res
= 1;
11287 stub_entry
->stub_type
= ppc_stub_save_res
;
11291 if (stub_entry
->stub_type
== ppc_stub_plt_call
11292 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11295 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11296 if (off
>= (bfd_vma
) -2)
11298 plt
= htab
->elf
.splt
;
11299 if (!htab
->elf
.dynamic_sections_created
11300 || stub_entry
->h
== NULL
11301 || stub_entry
->h
->elf
.dynindx
== -1)
11302 plt
= htab
->elf
.iplt
;
11303 off
+= (plt
->output_offset
11304 + plt
->output_section
->vma
11305 - elf_gp (plt
->output_section
->owner
)
11306 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11308 size
= plt_stub_size (htab
, stub_entry
, off
);
11309 if (htab
->params
->plt_stub_align
)
11310 size
+= plt_stub_pad (htab
, stub_entry
, off
);
11311 if (info
->emitrelocations
)
11313 stub_entry
->group
->stub_sec
->reloc_count
11314 += ((PPC_HA (off
) != 0)
11316 ? 2 + (htab
->params
->plt_static_chain
11317 && PPC_HA (off
+ 16) == PPC_HA (off
))
11319 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11324 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11327 bfd_vma local_off
= 0;
11329 off
= (stub_entry
->target_value
11330 + stub_entry
->target_section
->output_offset
11331 + stub_entry
->target_section
->output_section
->vma
);
11332 off
-= (stub_entry
->group
->stub_sec
->size
11333 + stub_entry
->group
->stub_sec
->output_offset
11334 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11336 /* Reset the stub type from the plt variant in case we now
11337 can reach with a shorter stub. */
11338 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
11339 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11342 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11344 r2off
= get_r2off (info
, stub_entry
);
11345 if (r2off
== (bfd_vma
) -1)
11347 htab
->stub_error
= TRUE
;
11351 if (PPC_HA (r2off
) != 0)
11353 if (PPC_LO (r2off
) != 0)
11358 local_off
= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11360 /* If the branch offset if too big, use a ppc_stub_plt_branch.
11361 Do the same for -R objects without function descriptors. */
11362 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26) - local_off
11363 || (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
11365 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0))
11367 struct ppc_branch_hash_entry
*br_entry
;
11369 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11370 stub_entry
->root
.string
+ 9,
11372 if (br_entry
== NULL
)
11374 info
->callbacks
->einfo (_("%P: can't build branch stub `%s'\n"),
11375 stub_entry
->root
.string
);
11376 htab
->stub_error
= TRUE
;
11380 if (br_entry
->iter
!= htab
->stub_iteration
)
11382 br_entry
->iter
= htab
->stub_iteration
;
11383 br_entry
->offset
= htab
->brlt
->size
;
11384 htab
->brlt
->size
+= 8;
11386 if (htab
->relbrlt
!= NULL
)
11387 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
11388 else if (info
->emitrelocations
)
11390 htab
->brlt
->reloc_count
+= 1;
11391 htab
->brlt
->flags
|= SEC_RELOC
;
11395 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11396 off
= (br_entry
->offset
11397 + htab
->brlt
->output_offset
11398 + htab
->brlt
->output_section
->vma
11399 - elf_gp (htab
->brlt
->output_section
->owner
)
11400 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11402 if (info
->emitrelocations
)
11404 stub_entry
->group
->stub_sec
->reloc_count
11405 += 1 + (PPC_HA (off
) != 0);
11406 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11409 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11412 if (PPC_HA (off
) != 0)
11418 if (PPC_HA (off
) != 0)
11421 if (PPC_HA (r2off
) != 0)
11423 if (PPC_LO (r2off
) != 0)
11427 else if (info
->emitrelocations
)
11429 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11430 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11434 stub_entry
->group
->stub_sec
->size
+= size
;
11438 /* Set up various things so that we can make a list of input sections
11439 for each output section included in the link. Returns -1 on error,
11440 0 when no stubs will be needed, and 1 on success. */
11443 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11447 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11452 htab
->sec_info_arr_size
= bfd_get_next_section_id ();
11453 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11454 htab
->sec_info
= bfd_zmalloc (amt
);
11455 if (htab
->sec_info
== NULL
)
11458 /* Set toc_off for com, und, abs and ind sections. */
11459 for (id
= 0; id
< 3; id
++)
11460 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11465 /* Set up for first pass at multitoc partitioning. */
11468 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11470 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11472 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11473 htab
->toc_bfd
= NULL
;
11474 htab
->toc_first_sec
= NULL
;
11477 /* The linker repeatedly calls this function for each TOC input section
11478 and linker generated GOT section. Group input bfds such that the toc
11479 within a group is less than 64k in size. */
11482 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11484 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11485 bfd_vma addr
, off
, limit
;
11490 if (!htab
->second_toc_pass
)
11492 /* Keep track of the first .toc or .got section for this input bfd. */
11493 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11497 htab
->toc_bfd
= isec
->owner
;
11498 htab
->toc_first_sec
= isec
;
11501 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11502 off
= addr
- htab
->toc_curr
;
11503 limit
= 0x80008000;
11504 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11506 if (off
+ isec
->size
> limit
)
11508 addr
= (htab
->toc_first_sec
->output_offset
11509 + htab
->toc_first_sec
->output_section
->vma
);
11510 htab
->toc_curr
= addr
;
11511 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11514 /* toc_curr is the base address of this toc group. Set elf_gp
11515 for the input section to be the offset relative to the
11516 output toc base plus 0x8000. Making the input elf_gp an
11517 offset allows us to move the toc as a whole without
11518 recalculating input elf_gp. */
11519 off
= htab
->toc_curr
- elf_gp (isec
->output_section
->owner
);
11520 off
+= TOC_BASE_OFF
;
11522 /* Die if someone uses a linker script that doesn't keep input
11523 file .toc and .got together. */
11525 && elf_gp (isec
->owner
) != 0
11526 && elf_gp (isec
->owner
) != off
)
11529 elf_gp (isec
->owner
) = off
;
11533 /* During the second pass toc_first_sec points to the start of
11534 a toc group, and toc_curr is used to track the old elf_gp.
11535 We use toc_bfd to ensure we only look at each bfd once. */
11536 if (htab
->toc_bfd
== isec
->owner
)
11538 htab
->toc_bfd
= isec
->owner
;
11540 if (htab
->toc_first_sec
== NULL
11541 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11543 htab
->toc_curr
= elf_gp (isec
->owner
);
11544 htab
->toc_first_sec
= isec
;
11546 addr
= (htab
->toc_first_sec
->output_offset
11547 + htab
->toc_first_sec
->output_section
->vma
);
11548 off
= addr
- elf_gp (isec
->output_section
->owner
) + TOC_BASE_OFF
;
11549 elf_gp (isec
->owner
) = off
;
11554 /* Called via elf_link_hash_traverse to merge GOT entries for global
11558 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11560 if (h
->root
.type
== bfd_link_hash_indirect
)
11563 merge_got_entries (&h
->got
.glist
);
11568 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11572 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11574 struct got_entry
*gent
;
11576 if (h
->root
.type
== bfd_link_hash_indirect
)
11579 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11580 if (!gent
->is_indirect
)
11581 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11585 /* Called on the first multitoc pass after the last call to
11586 ppc64_elf_next_toc_section. This function removes duplicate GOT
11590 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11592 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11593 struct bfd
*ibfd
, *ibfd2
;
11594 bfd_boolean done_something
;
11596 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11598 if (!htab
->do_multi_toc
)
11601 /* Merge global sym got entries within a toc group. */
11602 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11604 /* And tlsld_got. */
11605 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11607 struct got_entry
*ent
, *ent2
;
11609 if (!is_ppc64_elf (ibfd
))
11612 ent
= ppc64_tlsld_got (ibfd
);
11613 if (!ent
->is_indirect
11614 && ent
->got
.offset
!= (bfd_vma
) -1)
11616 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11618 if (!is_ppc64_elf (ibfd2
))
11621 ent2
= ppc64_tlsld_got (ibfd2
);
11622 if (!ent2
->is_indirect
11623 && ent2
->got
.offset
!= (bfd_vma
) -1
11624 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11626 ent2
->is_indirect
= TRUE
;
11627 ent2
->got
.ent
= ent
;
11633 /* Zap sizes of got sections. */
11634 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11635 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11636 htab
->got_reli_size
= 0;
11638 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11640 asection
*got
, *relgot
;
11642 if (!is_ppc64_elf (ibfd
))
11645 got
= ppc64_elf_tdata (ibfd
)->got
;
11648 got
->rawsize
= got
->size
;
11650 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11651 relgot
->rawsize
= relgot
->size
;
11656 /* Now reallocate the got, local syms first. We don't need to
11657 allocate section contents again since we never increase size. */
11658 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11660 struct got_entry
**lgot_ents
;
11661 struct got_entry
**end_lgot_ents
;
11662 struct plt_entry
**local_plt
;
11663 struct plt_entry
**end_local_plt
;
11664 unsigned char *lgot_masks
;
11665 bfd_size_type locsymcount
;
11666 Elf_Internal_Shdr
*symtab_hdr
;
11669 if (!is_ppc64_elf (ibfd
))
11672 lgot_ents
= elf_local_got_ents (ibfd
);
11676 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11677 locsymcount
= symtab_hdr
->sh_info
;
11678 end_lgot_ents
= lgot_ents
+ locsymcount
;
11679 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11680 end_local_plt
= local_plt
+ locsymcount
;
11681 lgot_masks
= (unsigned char *) end_local_plt
;
11682 s
= ppc64_elf_tdata (ibfd
)->got
;
11683 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11685 struct got_entry
*ent
;
11687 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11689 unsigned int ent_size
= 8;
11690 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11692 ent
->got
.offset
= s
->size
;
11693 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11698 s
->size
+= ent_size
;
11699 if ((*lgot_masks
& PLT_IFUNC
) != 0)
11701 htab
->elf
.irelplt
->size
+= rel_size
;
11702 htab
->got_reli_size
+= rel_size
;
11704 else if (bfd_link_pic (info
))
11706 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11707 srel
->size
+= rel_size
;
11713 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11715 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11717 struct got_entry
*ent
;
11719 if (!is_ppc64_elf (ibfd
))
11722 ent
= ppc64_tlsld_got (ibfd
);
11723 if (!ent
->is_indirect
11724 && ent
->got
.offset
!= (bfd_vma
) -1)
11726 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11727 ent
->got
.offset
= s
->size
;
11729 if (bfd_link_pic (info
))
11731 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11732 srel
->size
+= sizeof (Elf64_External_Rela
);
11737 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11738 if (!done_something
)
11739 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11743 if (!is_ppc64_elf (ibfd
))
11746 got
= ppc64_elf_tdata (ibfd
)->got
;
11749 done_something
= got
->rawsize
!= got
->size
;
11750 if (done_something
)
11755 if (done_something
)
11756 (*htab
->params
->layout_sections_again
) ();
11758 /* Set up for second pass over toc sections to recalculate elf_gp
11759 on input sections. */
11760 htab
->toc_bfd
= NULL
;
11761 htab
->toc_first_sec
= NULL
;
11762 htab
->second_toc_pass
= TRUE
;
11763 return done_something
;
11766 /* Called after second pass of multitoc partitioning. */
11769 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11771 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11773 /* After the second pass, toc_curr tracks the TOC offset used
11774 for code sections below in ppc64_elf_next_input_section. */
11775 htab
->toc_curr
= TOC_BASE_OFF
;
11778 /* No toc references were found in ISEC. If the code in ISEC makes no
11779 calls, then there's no need to use toc adjusting stubs when branching
11780 into ISEC. Actually, indirect calls from ISEC are OK as they will
11781 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11782 needed, and 2 if a cyclical call-graph was found but no other reason
11783 for a stub was detected. If called from the top level, a return of
11784 2 means the same as a return of 0. */
11787 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11791 /* Mark this section as checked. */
11792 isec
->call_check_done
= 1;
11794 /* We know none of our code bearing sections will need toc stubs. */
11795 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11798 if (isec
->size
== 0)
11801 if (isec
->output_section
== NULL
)
11805 if (isec
->reloc_count
!= 0)
11807 Elf_Internal_Rela
*relstart
, *rel
;
11808 Elf_Internal_Sym
*local_syms
;
11809 struct ppc_link_hash_table
*htab
;
11811 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11812 info
->keep_memory
);
11813 if (relstart
== NULL
)
11816 /* Look for branches to outside of this section. */
11818 htab
= ppc_hash_table (info
);
11822 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11824 enum elf_ppc64_reloc_type r_type
;
11825 unsigned long r_symndx
;
11826 struct elf_link_hash_entry
*h
;
11827 struct ppc_link_hash_entry
*eh
;
11828 Elf_Internal_Sym
*sym
;
11830 struct _opd_sec_data
*opd
;
11834 r_type
= ELF64_R_TYPE (rel
->r_info
);
11835 if (r_type
!= R_PPC64_REL24
11836 && r_type
!= R_PPC64_REL14
11837 && r_type
!= R_PPC64_REL14_BRTAKEN
11838 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11841 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11842 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11849 /* Calls to dynamic lib functions go through a plt call stub
11851 eh
= (struct ppc_link_hash_entry
*) h
;
11853 && (eh
->elf
.plt
.plist
!= NULL
11855 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
11861 if (sym_sec
== NULL
)
11862 /* Ignore other undefined symbols. */
11865 /* Assume branches to other sections not included in the
11866 link need stubs too, to cover -R and absolute syms. */
11867 if (sym_sec
->output_section
== NULL
)
11874 sym_value
= sym
->st_value
;
11877 if (h
->root
.type
!= bfd_link_hash_defined
11878 && h
->root
.type
!= bfd_link_hash_defweak
)
11880 sym_value
= h
->root
.u
.def
.value
;
11882 sym_value
+= rel
->r_addend
;
11884 /* If this branch reloc uses an opd sym, find the code section. */
11885 opd
= get_opd_info (sym_sec
);
11888 if (h
== NULL
&& opd
->adjust
!= NULL
)
11892 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11894 /* Assume deleted functions won't ever be called. */
11896 sym_value
+= adjust
;
11899 dest
= opd_entry_value (sym_sec
, sym_value
,
11900 &sym_sec
, NULL
, FALSE
);
11901 if (dest
== (bfd_vma
) -1)
11906 + sym_sec
->output_offset
11907 + sym_sec
->output_section
->vma
);
11909 /* Ignore branch to self. */
11910 if (sym_sec
== isec
)
11913 /* If the called function uses the toc, we need a stub. */
11914 if (sym_sec
->has_toc_reloc
11915 || sym_sec
->makes_toc_func_call
)
11921 /* Assume any branch that needs a long branch stub might in fact
11922 need a plt_branch stub. A plt_branch stub uses r2. */
11923 else if (dest
- (isec
->output_offset
11924 + isec
->output_section
->vma
11925 + rel
->r_offset
) + (1 << 25)
11926 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11934 /* If calling back to a section in the process of being
11935 tested, we can't say for sure that no toc adjusting stubs
11936 are needed, so don't return zero. */
11937 else if (sym_sec
->call_check_in_progress
)
11940 /* Branches to another section that itself doesn't have any TOC
11941 references are OK. Recursively call ourselves to check. */
11942 else if (!sym_sec
->call_check_done
)
11946 /* Mark current section as indeterminate, so that other
11947 sections that call back to current won't be marked as
11949 isec
->call_check_in_progress
= 1;
11950 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
11951 isec
->call_check_in_progress
= 0;
11962 if (local_syms
!= NULL
11963 && (elf_symtab_hdr (isec
->owner
).contents
11964 != (unsigned char *) local_syms
))
11966 if (elf_section_data (isec
)->relocs
!= relstart
)
11971 && isec
->map_head
.s
!= NULL
11972 && (strcmp (isec
->output_section
->name
, ".init") == 0
11973 || strcmp (isec
->output_section
->name
, ".fini") == 0))
11975 if (isec
->map_head
.s
->has_toc_reloc
11976 || isec
->map_head
.s
->makes_toc_func_call
)
11978 else if (!isec
->map_head
.s
->call_check_done
)
11981 isec
->call_check_in_progress
= 1;
11982 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
11983 isec
->call_check_in_progress
= 0;
11990 isec
->makes_toc_func_call
= 1;
11995 /* The linker repeatedly calls this function for each input section,
11996 in the order that input sections are linked into output sections.
11997 Build lists of input sections to determine groupings between which
11998 we may insert linker stubs. */
12001 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
12003 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12008 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
12009 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
12011 /* This happens to make the list in reverse order,
12012 which is what we want. */
12013 htab
->sec_info
[isec
->id
].u
.list
12014 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
12015 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
12018 if (htab
->multi_toc_needed
)
12020 /* Analyse sections that aren't already flagged as needing a
12021 valid toc pointer. Exclude .fixup for the linux kernel.
12022 .fixup contains branches, but only back to the function that
12023 hit an exception. */
12024 if (!(isec
->has_toc_reloc
12025 || (isec
->flags
& SEC_CODE
) == 0
12026 || strcmp (isec
->name
, ".fixup") == 0
12027 || isec
->call_check_done
))
12029 if (toc_adjusting_stub_needed (info
, isec
) < 0)
12032 /* Make all sections use the TOC assigned for this object file.
12033 This will be wrong for pasted sections; We fix that in
12034 check_pasted_section(). */
12035 if (elf_gp (isec
->owner
) != 0)
12036 htab
->toc_curr
= elf_gp (isec
->owner
);
12039 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
12043 /* Check that all .init and .fini sections use the same toc, if they
12044 have toc relocs. */
12047 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
12049 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
12053 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12054 bfd_vma toc_off
= 0;
12057 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12058 if (i
->has_toc_reloc
)
12061 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12062 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
12067 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12068 if (i
->makes_toc_func_call
)
12070 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12074 /* Make sure the whole pasted function uses the same toc offset. */
12076 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12077 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
12083 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
12085 return (check_pasted_section (info
, ".init")
12086 & check_pasted_section (info
, ".fini"));
12089 /* See whether we can group stub sections together. Grouping stub
12090 sections may result in fewer stubs. More importantly, we need to
12091 put all .init* and .fini* stubs at the beginning of the .init or
12092 .fini output sections respectively, because glibc splits the
12093 _init and _fini functions into multiple parts. Putting a stub in
12094 the middle of a function is not a good idea. */
12097 group_sections (struct bfd_link_info
*info
,
12098 bfd_size_type stub_group_size
,
12099 bfd_boolean stubs_always_before_branch
)
12101 struct ppc_link_hash_table
*htab
;
12103 bfd_boolean suppress_size_errors
;
12105 htab
= ppc_hash_table (info
);
12109 suppress_size_errors
= FALSE
;
12110 if (stub_group_size
== 1)
12112 /* Default values. */
12113 if (stubs_always_before_branch
)
12114 stub_group_size
= 0x1e00000;
12116 stub_group_size
= 0x1c00000;
12117 suppress_size_errors
= TRUE
;
12120 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
12124 if (osec
->id
>= htab
->sec_info_arr_size
)
12127 tail
= htab
->sec_info
[osec
->id
].u
.list
;
12128 while (tail
!= NULL
)
12132 bfd_size_type total
;
12133 bfd_boolean big_sec
;
12135 struct map_stub
*group
;
12136 bfd_size_type group_size
;
12139 total
= tail
->size
;
12140 group_size
= (ppc64_elf_section_data (tail
) != NULL
12141 && ppc64_elf_section_data (tail
)->has_14bit_branch
12142 ? stub_group_size
>> 10 : stub_group_size
);
12144 big_sec
= total
> group_size
;
12145 if (big_sec
&& !suppress_size_errors
)
12146 /* xgettext:c-format */
12147 _bfd_error_handler (_("%B section %A exceeds stub group size"),
12148 tail
->owner
, tail
);
12149 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
12151 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
12152 && ((total
+= curr
->output_offset
- prev
->output_offset
)
12153 < (ppc64_elf_section_data (prev
) != NULL
12154 && ppc64_elf_section_data (prev
)->has_14bit_branch
12155 ? (group_size
= stub_group_size
>> 10) : group_size
))
12156 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12159 /* OK, the size from the start of CURR to the end is less
12160 than group_size and thus can be handled by one stub
12161 section. (or the tail section is itself larger than
12162 group_size, in which case we may be toast.) We should
12163 really be keeping track of the total size of stubs added
12164 here, as stubs contribute to the final output section
12165 size. That's a little tricky, and this way will only
12166 break if stubs added make the total size more than 2^25,
12167 ie. for the default stub_group_size, if stubs total more
12168 than 2097152 bytes, or nearly 75000 plt call stubs. */
12169 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
12172 group
->link_sec
= curr
;
12173 group
->stub_sec
= NULL
;
12174 group
->needs_save_res
= 0;
12175 group
->next
= htab
->group
;
12176 htab
->group
= group
;
12179 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12180 /* Set up this stub group. */
12181 htab
->sec_info
[tail
->id
].u
.group
= group
;
12183 while (tail
!= curr
&& (tail
= prev
) != NULL
);
12185 /* But wait, there's more! Input sections up to group_size
12186 bytes before the stub section can be handled by it too.
12187 Don't do this if we have a really large section after the
12188 stubs, as adding more stubs increases the chance that
12189 branches may not reach into the stub section. */
12190 if (!stubs_always_before_branch
&& !big_sec
)
12193 while (prev
!= NULL
12194 && ((total
+= tail
->output_offset
- prev
->output_offset
)
12195 < (ppc64_elf_section_data (prev
) != NULL
12196 && ppc64_elf_section_data (prev
)->has_14bit_branch
12197 ? (group_size
= stub_group_size
>> 10) : group_size
))
12198 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12201 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12202 htab
->sec_info
[tail
->id
].u
.group
= group
;
12211 static const unsigned char glink_eh_frame_cie
[] =
12213 0, 0, 0, 16, /* length. */
12214 0, 0, 0, 0, /* id. */
12215 1, /* CIE version. */
12216 'z', 'R', 0, /* Augmentation string. */
12217 4, /* Code alignment. */
12218 0x78, /* Data alignment. */
12220 1, /* Augmentation size. */
12221 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12222 DW_CFA_def_cfa
, 1, 0, /* def_cfa: r1 offset 0. */
12226 /* Stripping output sections is normally done before dynamic section
12227 symbols have been allocated. This function is called later, and
12228 handles cases like htab->brlt which is mapped to its own output
12232 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12234 if (isec
->size
== 0
12235 && isec
->output_section
->size
== 0
12236 && !(isec
->output_section
->flags
& SEC_KEEP
)
12237 && !bfd_section_removed_from_list (info
->output_bfd
,
12238 isec
->output_section
)
12239 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12241 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12242 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12243 info
->output_bfd
->section_count
--;
12247 /* Determine and set the size of the stub section for a final link.
12249 The basic idea here is to examine all the relocations looking for
12250 PC-relative calls to a target that is unreachable with a "bl"
12254 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12256 bfd_size_type stub_group_size
;
12257 bfd_boolean stubs_always_before_branch
;
12258 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12263 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12264 htab
->params
->plt_thread_safe
= 1;
12265 if (!htab
->opd_abi
)
12266 htab
->params
->plt_thread_safe
= 0;
12267 else if (htab
->params
->plt_thread_safe
== -1)
12269 static const char *const thread_starter
[] =
12273 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12275 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12276 "mq_notify", "create_timer",
12281 "GOMP_parallel_start",
12282 "GOMP_parallel_loop_static",
12283 "GOMP_parallel_loop_static_start",
12284 "GOMP_parallel_loop_dynamic",
12285 "GOMP_parallel_loop_dynamic_start",
12286 "GOMP_parallel_loop_guided",
12287 "GOMP_parallel_loop_guided_start",
12288 "GOMP_parallel_loop_runtime",
12289 "GOMP_parallel_loop_runtime_start",
12290 "GOMP_parallel_sections",
12291 "GOMP_parallel_sections_start",
12297 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12299 struct elf_link_hash_entry
*h
;
12300 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12301 FALSE
, FALSE
, TRUE
);
12302 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12303 if (htab
->params
->plt_thread_safe
)
12307 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12308 if (htab
->params
->group_size
< 0)
12309 stub_group_size
= -htab
->params
->group_size
;
12311 stub_group_size
= htab
->params
->group_size
;
12313 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12316 #define STUB_SHRINK_ITER 20
12317 /* Loop until no stubs added. After iteration 20 of this loop we may
12318 exit on a stub section shrinking. This is to break out of a
12319 pathological case where adding stubs on one iteration decreases
12320 section gaps (perhaps due to alignment), which then requires
12321 fewer or smaller stubs on the next iteration. */
12326 unsigned int bfd_indx
;
12327 struct map_stub
*group
;
12328 asection
*stub_sec
;
12330 htab
->stub_iteration
+= 1;
12332 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12334 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12336 Elf_Internal_Shdr
*symtab_hdr
;
12338 Elf_Internal_Sym
*local_syms
= NULL
;
12340 if (!is_ppc64_elf (input_bfd
))
12343 /* We'll need the symbol table in a second. */
12344 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12345 if (symtab_hdr
->sh_info
== 0)
12348 /* Walk over each section attached to the input bfd. */
12349 for (section
= input_bfd
->sections
;
12351 section
= section
->next
)
12353 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12355 /* If there aren't any relocs, then there's nothing more
12357 if ((section
->flags
& SEC_RELOC
) == 0
12358 || (section
->flags
& SEC_ALLOC
) == 0
12359 || (section
->flags
& SEC_LOAD
) == 0
12360 || (section
->flags
& SEC_CODE
) == 0
12361 || section
->reloc_count
== 0)
12364 /* If this section is a link-once section that will be
12365 discarded, then don't create any stubs. */
12366 if (section
->output_section
== NULL
12367 || section
->output_section
->owner
!= info
->output_bfd
)
12370 /* Get the relocs. */
12372 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12373 info
->keep_memory
);
12374 if (internal_relocs
== NULL
)
12375 goto error_ret_free_local
;
12377 /* Now examine each relocation. */
12378 irela
= internal_relocs
;
12379 irelaend
= irela
+ section
->reloc_count
;
12380 for (; irela
< irelaend
; irela
++)
12382 enum elf_ppc64_reloc_type r_type
;
12383 unsigned int r_indx
;
12384 enum ppc_stub_type stub_type
;
12385 struct ppc_stub_hash_entry
*stub_entry
;
12386 asection
*sym_sec
, *code_sec
;
12387 bfd_vma sym_value
, code_value
;
12388 bfd_vma destination
;
12389 unsigned long local_off
;
12390 bfd_boolean ok_dest
;
12391 struct ppc_link_hash_entry
*hash
;
12392 struct ppc_link_hash_entry
*fdh
;
12393 struct elf_link_hash_entry
*h
;
12394 Elf_Internal_Sym
*sym
;
12396 const asection
*id_sec
;
12397 struct _opd_sec_data
*opd
;
12398 struct plt_entry
*plt_ent
;
12400 r_type
= ELF64_R_TYPE (irela
->r_info
);
12401 r_indx
= ELF64_R_SYM (irela
->r_info
);
12403 if (r_type
>= R_PPC64_max
)
12405 bfd_set_error (bfd_error_bad_value
);
12406 goto error_ret_free_internal
;
12409 /* Only look for stubs on branch instructions. */
12410 if (r_type
!= R_PPC64_REL24
12411 && r_type
!= R_PPC64_REL14
12412 && r_type
!= R_PPC64_REL14_BRTAKEN
12413 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12416 /* Now determine the call target, its name, value,
12418 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12419 r_indx
, input_bfd
))
12420 goto error_ret_free_internal
;
12421 hash
= (struct ppc_link_hash_entry
*) h
;
12428 sym_value
= sym
->st_value
;
12429 if (sym_sec
!= NULL
12430 && sym_sec
->output_section
!= NULL
)
12433 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12434 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12436 sym_value
= hash
->elf
.root
.u
.def
.value
;
12437 if (sym_sec
->output_section
!= NULL
)
12440 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12441 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12443 /* Recognise an old ABI func code entry sym, and
12444 use the func descriptor sym instead if it is
12446 if (hash
->elf
.root
.root
.string
[0] == '.'
12447 && hash
->oh
!= NULL
)
12449 fdh
= ppc_follow_link (hash
->oh
);
12450 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12451 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12453 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12454 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12455 if (sym_sec
->output_section
!= NULL
)
12464 bfd_set_error (bfd_error_bad_value
);
12465 goto error_ret_free_internal
;
12472 sym_value
+= irela
->r_addend
;
12473 destination
= (sym_value
12474 + sym_sec
->output_offset
12475 + sym_sec
->output_section
->vma
);
12476 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12481 code_sec
= sym_sec
;
12482 code_value
= sym_value
;
12483 opd
= get_opd_info (sym_sec
);
12488 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12490 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12493 code_value
+= adjust
;
12494 sym_value
+= adjust
;
12496 dest
= opd_entry_value (sym_sec
, sym_value
,
12497 &code_sec
, &code_value
, FALSE
);
12498 if (dest
!= (bfd_vma
) -1)
12500 destination
= dest
;
12503 /* Fixup old ABI sym to point at code
12505 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12506 hash
->elf
.root
.u
.def
.section
= code_sec
;
12507 hash
->elf
.root
.u
.def
.value
= code_value
;
12512 /* Determine what (if any) linker stub is needed. */
12514 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
12515 &plt_ent
, destination
,
12518 if (stub_type
!= ppc_stub_plt_call
)
12520 /* Check whether we need a TOC adjusting stub.
12521 Since the linker pastes together pieces from
12522 different object files when creating the
12523 _init and _fini functions, it may be that a
12524 call to what looks like a local sym is in
12525 fact a call needing a TOC adjustment. */
12526 if (code_sec
!= NULL
12527 && code_sec
->output_section
!= NULL
12528 && (htab
->sec_info
[code_sec
->id
].toc_off
12529 != htab
->sec_info
[section
->id
].toc_off
)
12530 && (code_sec
->has_toc_reloc
12531 || code_sec
->makes_toc_func_call
))
12532 stub_type
= ppc_stub_long_branch_r2off
;
12535 if (stub_type
== ppc_stub_none
)
12538 /* __tls_get_addr calls might be eliminated. */
12539 if (stub_type
!= ppc_stub_plt_call
12541 && (hash
== htab
->tls_get_addr
12542 || hash
== htab
->tls_get_addr_fd
)
12543 && section
->has_tls_reloc
12544 && irela
!= internal_relocs
)
12546 /* Get tls info. */
12547 unsigned char *tls_mask
;
12549 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12550 irela
- 1, input_bfd
))
12551 goto error_ret_free_internal
;
12552 if (*tls_mask
!= 0)
12556 if (stub_type
== ppc_stub_plt_call
12557 && irela
+ 1 < irelaend
12558 && irela
[1].r_offset
== irela
->r_offset
+ 4
12559 && ELF64_R_TYPE (irela
[1].r_info
) == R_PPC64_TOCSAVE
)
12561 if (!tocsave_find (htab
, INSERT
,
12562 &local_syms
, irela
+ 1, input_bfd
))
12563 goto error_ret_free_internal
;
12565 else if (stub_type
== ppc_stub_plt_call
)
12566 stub_type
= ppc_stub_plt_call_r2save
;
12568 /* Support for grouping stub sections. */
12569 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12571 /* Get the name of this stub. */
12572 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12574 goto error_ret_free_internal
;
12576 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12577 stub_name
, FALSE
, FALSE
);
12578 if (stub_entry
!= NULL
)
12580 /* The proper stub has already been created. */
12582 if (stub_type
== ppc_stub_plt_call_r2save
)
12583 stub_entry
->stub_type
= stub_type
;
12587 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12588 if (stub_entry
== NULL
)
12591 error_ret_free_internal
:
12592 if (elf_section_data (section
)->relocs
== NULL
)
12593 free (internal_relocs
);
12594 error_ret_free_local
:
12595 if (local_syms
!= NULL
12596 && (symtab_hdr
->contents
12597 != (unsigned char *) local_syms
))
12602 stub_entry
->stub_type
= stub_type
;
12603 if (stub_type
!= ppc_stub_plt_call
12604 && stub_type
!= ppc_stub_plt_call_r2save
)
12606 stub_entry
->target_value
= code_value
;
12607 stub_entry
->target_section
= code_sec
;
12611 stub_entry
->target_value
= sym_value
;
12612 stub_entry
->target_section
= sym_sec
;
12614 stub_entry
->h
= hash
;
12615 stub_entry
->plt_ent
= plt_ent
;
12616 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12618 if (stub_entry
->h
!= NULL
)
12619 htab
->stub_globals
+= 1;
12622 /* We're done with the internal relocs, free them. */
12623 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12624 free (internal_relocs
);
12627 if (local_syms
!= NULL
12628 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12630 if (!info
->keep_memory
)
12633 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12637 /* We may have added some stubs. Find out the new size of the
12639 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12641 stub_sec
= stub_sec
->next
)
12642 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12644 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12645 || stub_sec
->rawsize
< stub_sec
->size
)
12646 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12647 stub_sec
->rawsize
= stub_sec
->size
;
12648 stub_sec
->size
= 0;
12649 stub_sec
->reloc_count
= 0;
12650 stub_sec
->flags
&= ~SEC_RELOC
;
12653 htab
->brlt
->size
= 0;
12654 htab
->brlt
->reloc_count
= 0;
12655 htab
->brlt
->flags
&= ~SEC_RELOC
;
12656 if (htab
->relbrlt
!= NULL
)
12657 htab
->relbrlt
->size
= 0;
12659 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12661 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12662 if (group
->needs_save_res
)
12663 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12665 if (info
->emitrelocations
12666 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12668 htab
->glink
->reloc_count
= 1;
12669 htab
->glink
->flags
|= SEC_RELOC
;
12672 if (htab
->glink_eh_frame
!= NULL
12673 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12674 && htab
->glink_eh_frame
->output_section
->size
!= 0)
12676 size_t size
= 0, align
;
12678 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12680 stub_sec
= stub_sec
->next
)
12681 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12683 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12686 size
+= sizeof (glink_eh_frame_cie
);
12688 align
<<= htab
->glink_eh_frame
->output_section
->alignment_power
;
12690 size
= (size
+ align
) & ~align
;
12691 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12692 htab
->glink_eh_frame
->size
= size
;
12695 if (htab
->params
->plt_stub_align
!= 0)
12696 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12698 stub_sec
= stub_sec
->next
)
12699 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12700 stub_sec
->size
= ((stub_sec
->size
12701 + (1 << htab
->params
->plt_stub_align
) - 1)
12702 & -(1 << htab
->params
->plt_stub_align
));
12704 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12706 stub_sec
= stub_sec
->next
)
12707 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
12708 && stub_sec
->rawsize
!= stub_sec
->size
12709 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
12710 || stub_sec
->rawsize
< stub_sec
->size
))
12713 if (stub_sec
== NULL
12714 && (htab
->glink_eh_frame
== NULL
12715 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12718 /* Ask the linker to do its stuff. */
12719 (*htab
->params
->layout_sections_again
) ();
12722 if (htab
->glink_eh_frame
!= NULL
12723 && htab
->glink_eh_frame
->size
!= 0)
12726 bfd_byte
*p
, *last_fde
;
12727 size_t last_fde_len
, size
, align
, pad
;
12728 asection
*stub_sec
;
12730 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12733 htab
->glink_eh_frame
->contents
= p
;
12736 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12737 /* CIE length (rewrite in case little-endian). */
12738 last_fde_len
= sizeof (glink_eh_frame_cie
) - 4;
12739 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12740 p
+= sizeof (glink_eh_frame_cie
);
12742 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12744 stub_sec
= stub_sec
->next
)
12745 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12750 bfd_put_32 (htab
->elf
.dynobj
, 20, p
);
12753 val
= p
- htab
->glink_eh_frame
->contents
;
12754 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12756 /* Offset to stub section, written later. */
12758 /* stub section size. */
12759 bfd_put_32 (htab
->elf
.dynobj
, stub_sec
->size
, p
);
12761 /* Augmentation. */
12766 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12771 bfd_put_32 (htab
->elf
.dynobj
, 20, p
);
12774 val
= p
- htab
->glink_eh_frame
->contents
;
12775 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12777 /* Offset to .glink, written later. */
12780 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12782 /* Augmentation. */
12785 *p
++ = DW_CFA_advance_loc
+ 1;
12786 *p
++ = DW_CFA_register
;
12788 *p
++ = htab
->opd_abi
? 12 : 0;
12789 *p
++ = DW_CFA_advance_loc
+ 4;
12790 *p
++ = DW_CFA_restore_extended
;
12793 /* Subsume any padding into the last FDE if user .eh_frame
12794 sections are aligned more than glink_eh_frame. Otherwise any
12795 zero padding will be seen as a terminator. */
12796 size
= p
- htab
->glink_eh_frame
->contents
;
12798 align
<<= htab
->glink_eh_frame
->output_section
->alignment_power
;
12800 pad
= ((size
+ align
) & ~align
) - size
;
12801 htab
->glink_eh_frame
->size
= size
+ pad
;
12802 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
12805 maybe_strip_output (info
, htab
->brlt
);
12806 if (htab
->glink_eh_frame
!= NULL
)
12807 maybe_strip_output (info
, htab
->glink_eh_frame
);
12812 /* Called after we have determined section placement. If sections
12813 move, we'll be called again. Provide a value for TOCstart. */
12816 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
12819 bfd_vma TOCstart
, adjust
;
12823 struct elf_link_hash_entry
*h
;
12824 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
12826 if (is_elf_hash_table (htab
)
12827 && htab
->hgot
!= NULL
)
12831 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
12832 if (is_elf_hash_table (htab
))
12836 && h
->root
.type
== bfd_link_hash_defined
12837 && !h
->root
.linker_def
12838 && (!is_elf_hash_table (htab
)
12839 || h
->def_regular
))
12841 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
12842 + h
->root
.u
.def
.section
->output_offset
12843 + h
->root
.u
.def
.section
->output_section
->vma
);
12844 _bfd_set_gp_value (obfd
, TOCstart
);
12849 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12850 order. The TOC starts where the first of these sections starts. */
12851 s
= bfd_get_section_by_name (obfd
, ".got");
12852 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12853 s
= bfd_get_section_by_name (obfd
, ".toc");
12854 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12855 s
= bfd_get_section_by_name (obfd
, ".tocbss");
12856 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12857 s
= bfd_get_section_by_name (obfd
, ".plt");
12858 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12860 /* This may happen for
12861 o references to TOC base (SYM@toc / TOC[tc0]) without a
12863 o bad linker script
12864 o --gc-sections and empty TOC sections
12866 FIXME: Warn user? */
12868 /* Look for a likely section. We probably won't even be
12870 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12871 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
12873 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12876 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12877 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
12878 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12881 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12882 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
12886 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12887 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
12893 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
12895 /* Force alignment. */
12896 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
12897 TOCstart
-= adjust
;
12898 _bfd_set_gp_value (obfd
, TOCstart
);
12900 if (info
!= NULL
&& s
!= NULL
)
12902 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12906 if (htab
->elf
.hgot
!= NULL
)
12908 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
12909 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
12914 struct bfd_link_hash_entry
*bh
= NULL
;
12915 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
12916 s
, TOC_BASE_OFF
- adjust
,
12917 NULL
, FALSE
, FALSE
, &bh
);
12923 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
12924 write out any global entry stubs. */
12927 build_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
12929 struct bfd_link_info
*info
;
12930 struct ppc_link_hash_table
*htab
;
12931 struct plt_entry
*pent
;
12934 if (h
->root
.type
== bfd_link_hash_indirect
)
12937 if (!h
->pointer_equality_needed
)
12940 if (h
->def_regular
)
12944 htab
= ppc_hash_table (info
);
12949 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
12950 if (pent
->plt
.offset
!= (bfd_vma
) -1
12951 && pent
->addend
== 0)
12957 p
= s
->contents
+ h
->root
.u
.def
.value
;
12958 plt
= htab
->elf
.splt
;
12959 if (!htab
->elf
.dynamic_sections_created
12960 || h
->dynindx
== -1)
12961 plt
= htab
->elf
.iplt
;
12962 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
12963 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
12965 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
12967 info
->callbacks
->einfo
12968 (_("%P: linkage table error against `%T'\n"),
12969 h
->root
.root
.string
);
12970 bfd_set_error (bfd_error_bad_value
);
12971 htab
->stub_error
= TRUE
;
12974 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
12975 if (htab
->params
->emit_stub_syms
)
12977 size_t len
= strlen (h
->root
.root
.string
);
12978 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
12983 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
12984 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
12987 if (h
->root
.type
== bfd_link_hash_new
)
12989 h
->root
.type
= bfd_link_hash_defined
;
12990 h
->root
.u
.def
.section
= s
;
12991 h
->root
.u
.def
.value
= p
- s
->contents
;
12992 h
->ref_regular
= 1;
12993 h
->def_regular
= 1;
12994 h
->ref_regular_nonweak
= 1;
12995 h
->forced_local
= 1;
12997 h
->root
.linker_def
= 1;
13001 if (PPC_HA (off
) != 0)
13003 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
13006 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
13008 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
13010 bfd_put_32 (s
->owner
, BCTR
, p
);
13016 /* Build all the stubs associated with the current output file.
13017 The stubs are kept in a hash table attached to the main linker
13018 hash table. This function is called via gldelf64ppc_finish. */
13021 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
13024 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13025 struct map_stub
*group
;
13026 asection
*stub_sec
;
13028 int stub_sec_count
= 0;
13033 /* Allocate memory to hold the linker stubs. */
13034 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
13036 stub_sec
= stub_sec
->next
)
13037 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
13038 && stub_sec
->size
!= 0)
13040 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
, stub_sec
->size
);
13041 if (stub_sec
->contents
== NULL
)
13043 stub_sec
->size
= 0;
13046 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13051 /* Build the .glink plt call stub. */
13052 if (htab
->params
->emit_stub_syms
)
13054 struct elf_link_hash_entry
*h
;
13055 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
13056 TRUE
, FALSE
, FALSE
);
13059 if (h
->root
.type
== bfd_link_hash_new
)
13061 h
->root
.type
= bfd_link_hash_defined
;
13062 h
->root
.u
.def
.section
= htab
->glink
;
13063 h
->root
.u
.def
.value
= 8;
13064 h
->ref_regular
= 1;
13065 h
->def_regular
= 1;
13066 h
->ref_regular_nonweak
= 1;
13067 h
->forced_local
= 1;
13069 h
->root
.linker_def
= 1;
13072 plt0
= (htab
->elf
.splt
->output_section
->vma
13073 + htab
->elf
.splt
->output_offset
13075 if (info
->emitrelocations
)
13077 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
13080 r
->r_offset
= (htab
->glink
->output_offset
13081 + htab
->glink
->output_section
->vma
);
13082 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
13083 r
->r_addend
= plt0
;
13085 p
= htab
->glink
->contents
;
13086 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
13087 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
13091 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
13093 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13095 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13097 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13099 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
13101 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13103 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13105 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
13107 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13109 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
13114 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
13116 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13118 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13120 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13122 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
13124 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
13126 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13128 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
13130 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13132 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
13134 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13136 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
13139 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
13141 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
13143 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
13147 /* Build the .glink lazy link call stubs. */
13149 while (p
< htab
->glink
->contents
+ htab
->glink
->rawsize
)
13155 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
13160 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
13162 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
13167 bfd_put_32 (htab
->glink
->owner
,
13168 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
13173 /* Build .glink global entry stubs. */
13174 if (htab
->glink
->size
> htab
->glink
->rawsize
)
13175 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs
, info
);
13178 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
13180 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
13182 if (htab
->brlt
->contents
== NULL
)
13185 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
13187 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
13188 htab
->relbrlt
->size
);
13189 if (htab
->relbrlt
->contents
== NULL
)
13193 /* Build the stubs as directed by the stub hash table. */
13194 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
13196 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13197 if (group
->needs_save_res
)
13199 stub_sec
= group
->stub_sec
;
13200 memcpy (stub_sec
->contents
+ stub_sec
->size
, htab
->sfpr
->contents
,
13202 if (htab
->params
->emit_stub_syms
)
13206 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13207 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13210 stub_sec
->size
+= htab
->sfpr
->size
;
13213 if (htab
->relbrlt
!= NULL
)
13214 htab
->relbrlt
->reloc_count
= 0;
13216 if (htab
->params
->plt_stub_align
!= 0)
13217 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
13219 stub_sec
= stub_sec
->next
)
13220 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
13221 stub_sec
->size
= ((stub_sec
->size
13222 + (1 << htab
->params
->plt_stub_align
) - 1)
13223 & -(1 << htab
->params
->plt_stub_align
));
13225 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
13227 stub_sec
= stub_sec
->next
)
13228 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
13230 stub_sec_count
+= 1;
13231 if (stub_sec
->rawsize
!= stub_sec
->size
13232 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13233 || stub_sec
->rawsize
< stub_sec
->size
))
13237 /* Note that the glink_eh_frame check here is not only testing that
13238 the generated size matched the calculated size but also that
13239 bfd_elf_discard_info didn't make any changes to the section. */
13240 if (stub_sec
!= NULL
13241 || (htab
->glink_eh_frame
!= NULL
13242 && htab
->glink_eh_frame
->rawsize
!= htab
->glink_eh_frame
->size
))
13244 htab
->stub_error
= TRUE
;
13245 info
->callbacks
->einfo (_("%P: stubs don't match calculated size\n"));
13248 if (htab
->stub_error
)
13253 *stats
= bfd_malloc (500);
13254 if (*stats
== NULL
)
13257 sprintf (*stats
, _("linker stubs in %u group%s\n"
13259 " toc adjust %lu\n"
13260 " long branch %lu\n"
13261 " long toc adj %lu\n"
13263 " plt call toc %lu\n"
13264 " global entry %lu"),
13266 stub_sec_count
== 1 ? "" : "s",
13267 htab
->stub_count
[ppc_stub_long_branch
- 1],
13268 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13269 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13270 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13271 htab
->stub_count
[ppc_stub_plt_call
- 1],
13272 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13273 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13278 /* What to do when ld finds relocations against symbols defined in
13279 discarded sections. */
13281 static unsigned int
13282 ppc64_elf_action_discarded (asection
*sec
)
13284 if (strcmp (".opd", sec
->name
) == 0)
13287 if (strcmp (".toc", sec
->name
) == 0)
13290 if (strcmp (".toc1", sec
->name
) == 0)
13293 return _bfd_elf_default_action_discarded (sec
);
13296 /* The RELOCATE_SECTION function is called by the ELF backend linker
13297 to handle the relocations for a section.
13299 The relocs are always passed as Rela structures; if the section
13300 actually uses Rel structures, the r_addend field will always be
13303 This function is responsible for adjust the section contents as
13304 necessary, and (if using Rela relocs and generating a
13305 relocatable output file) adjusting the reloc addend as
13308 This function does not have to worry about setting the reloc
13309 address or the reloc symbol index.
13311 LOCAL_SYMS is a pointer to the swapped in local symbols.
13313 LOCAL_SECTIONS is an array giving the section in the input file
13314 corresponding to the st_shndx field of each local symbol.
13316 The global hash table entry for the global symbols can be found
13317 via elf_sym_hashes (input_bfd).
13319 When generating relocatable output, this function must handle
13320 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13321 going to be the section symbol corresponding to the output
13322 section, which means that the addend must be adjusted
13326 ppc64_elf_relocate_section (bfd
*output_bfd
,
13327 struct bfd_link_info
*info
,
13329 asection
*input_section
,
13330 bfd_byte
*contents
,
13331 Elf_Internal_Rela
*relocs
,
13332 Elf_Internal_Sym
*local_syms
,
13333 asection
**local_sections
)
13335 struct ppc_link_hash_table
*htab
;
13336 Elf_Internal_Shdr
*symtab_hdr
;
13337 struct elf_link_hash_entry
**sym_hashes
;
13338 Elf_Internal_Rela
*rel
;
13339 Elf_Internal_Rela
*wrel
;
13340 Elf_Internal_Rela
*relend
;
13341 Elf_Internal_Rela outrel
;
13343 struct got_entry
**local_got_ents
;
13345 bfd_boolean ret
= TRUE
;
13346 bfd_boolean is_opd
;
13347 /* Assume 'at' branch hints. */
13348 bfd_boolean is_isa_v2
= TRUE
;
13349 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13351 /* Initialize howto table if needed. */
13352 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13355 htab
= ppc_hash_table (info
);
13359 /* Don't relocate stub sections. */
13360 if (input_section
->owner
== htab
->params
->stub_bfd
)
13363 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13365 local_got_ents
= elf_local_got_ents (input_bfd
);
13366 TOCstart
= elf_gp (output_bfd
);
13367 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13368 sym_hashes
= elf_sym_hashes (input_bfd
);
13369 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13371 rel
= wrel
= relocs
;
13372 relend
= relocs
+ input_section
->reloc_count
;
13373 for (; rel
< relend
; wrel
++, rel
++)
13375 enum elf_ppc64_reloc_type r_type
;
13377 bfd_reloc_status_type r
;
13378 Elf_Internal_Sym
*sym
;
13380 struct elf_link_hash_entry
*h_elf
;
13381 struct ppc_link_hash_entry
*h
;
13382 struct ppc_link_hash_entry
*fdh
;
13383 const char *sym_name
;
13384 unsigned long r_symndx
, toc_symndx
;
13385 bfd_vma toc_addend
;
13386 unsigned char tls_mask
, tls_gd
, tls_type
;
13387 unsigned char sym_type
;
13388 bfd_vma relocation
;
13389 bfd_boolean unresolved_reloc
;
13390 bfd_boolean warned
;
13391 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13394 struct ppc_stub_hash_entry
*stub_entry
;
13395 bfd_vma max_br_offset
;
13397 Elf_Internal_Rela orig_rel
;
13398 reloc_howto_type
*howto
;
13399 struct reloc_howto_struct alt_howto
;
13404 r_type
= ELF64_R_TYPE (rel
->r_info
);
13405 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13407 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13408 symbol of the previous ADDR64 reloc. The symbol gives us the
13409 proper TOC base to use. */
13410 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13412 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13414 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13420 unresolved_reloc
= FALSE
;
13423 if (r_symndx
< symtab_hdr
->sh_info
)
13425 /* It's a local symbol. */
13426 struct _opd_sec_data
*opd
;
13428 sym
= local_syms
+ r_symndx
;
13429 sec
= local_sections
[r_symndx
];
13430 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13431 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13432 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13433 opd
= get_opd_info (sec
);
13434 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13436 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13442 /* If this is a relocation against the opd section sym
13443 and we have edited .opd, adjust the reloc addend so
13444 that ld -r and ld --emit-relocs output is correct.
13445 If it is a reloc against some other .opd symbol,
13446 then the symbol value will be adjusted later. */
13447 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13448 rel
->r_addend
+= adjust
;
13450 relocation
+= adjust
;
13456 bfd_boolean ignored
;
13458 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13459 r_symndx
, symtab_hdr
, sym_hashes
,
13460 h_elf
, sec
, relocation
,
13461 unresolved_reloc
, warned
, ignored
);
13462 sym_name
= h_elf
->root
.root
.string
;
13463 sym_type
= h_elf
->type
;
13465 && sec
->owner
== output_bfd
13466 && strcmp (sec
->name
, ".opd") == 0)
13468 /* This is a symbol defined in a linker script. All
13469 such are defined in output sections, even those
13470 defined by simple assignment from a symbol defined in
13471 an input section. Transfer the symbol to an
13472 appropriate input .opd section, so that a branch to
13473 this symbol will be mapped to the location specified
13474 by the opd entry. */
13475 struct bfd_link_order
*lo
;
13476 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13477 if (lo
->type
== bfd_indirect_link_order
)
13479 asection
*isec
= lo
->u
.indirect
.section
;
13480 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13481 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13484 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13485 h_elf
->root
.u
.def
.section
= isec
;
13492 h
= (struct ppc_link_hash_entry
*) h_elf
;
13494 if (sec
!= NULL
&& discarded_section (sec
))
13496 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
13497 input_bfd
, input_section
,
13498 contents
+ rel
->r_offset
);
13499 wrel
->r_offset
= rel
->r_offset
;
13501 wrel
->r_addend
= 0;
13503 /* For ld -r, remove relocations in debug sections against
13504 sections defined in discarded sections. Not done for
13505 non-debug to preserve relocs in .eh_frame which the
13506 eh_frame editing code expects to be present. */
13507 if (bfd_link_relocatable (info
)
13508 && (input_section
->flags
& SEC_DEBUGGING
))
13514 if (bfd_link_relocatable (info
))
13517 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13519 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13520 sec
= bfd_abs_section_ptr
;
13521 unresolved_reloc
= FALSE
;
13524 /* TLS optimizations. Replace instruction sequences and relocs
13525 based on information we collected in tls_optimize. We edit
13526 RELOCS so that --emit-relocs will output something sensible
13527 for the final instruction stream. */
13532 tls_mask
= h
->tls_mask
;
13533 else if (local_got_ents
!= NULL
)
13535 struct plt_entry
**local_plt
= (struct plt_entry
**)
13536 (local_got_ents
+ symtab_hdr
->sh_info
);
13537 unsigned char *lgot_masks
= (unsigned char *)
13538 (local_plt
+ symtab_hdr
->sh_info
);
13539 tls_mask
= lgot_masks
[r_symndx
];
13542 && (r_type
== R_PPC64_TLS
13543 || r_type
== R_PPC64_TLSGD
13544 || r_type
== R_PPC64_TLSLD
))
13546 /* Check for toc tls entries. */
13547 unsigned char *toc_tls
;
13549 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13550 &local_syms
, rel
, input_bfd
))
13554 tls_mask
= *toc_tls
;
13557 /* Check that tls relocs are used with tls syms, and non-tls
13558 relocs are used with non-tls syms. */
13559 if (r_symndx
!= STN_UNDEF
13560 && r_type
!= R_PPC64_NONE
13562 || h
->elf
.root
.type
== bfd_link_hash_defined
13563 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13564 && (IS_PPC64_TLS_RELOC (r_type
)
13565 != (sym_type
== STT_TLS
13566 || (sym_type
== STT_SECTION
13567 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13570 && (r_type
== R_PPC64_TLS
13571 || r_type
== R_PPC64_TLSGD
13572 || r_type
== R_PPC64_TLSLD
))
13573 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13576 info
->callbacks
->einfo
13577 (!IS_PPC64_TLS_RELOC (r_type
)
13578 /* xgettext:c-format */
13579 ? _("%P: %H: %s used with TLS symbol `%T'\n")
13580 /* xgettext:c-format */
13581 : _("%P: %H: %s used with non-TLS symbol `%T'\n"),
13582 input_bfd
, input_section
, rel
->r_offset
,
13583 ppc64_elf_howto_table
[r_type
]->name
,
13587 /* Ensure reloc mapping code below stays sane. */
13588 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13589 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13590 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13591 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13592 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13593 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13594 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13595 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13596 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13597 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
13605 case R_PPC64_LO_DS_OPT
:
13606 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
13607 if ((insn
& (0x3f << 26)) != 58u << 26)
13609 insn
+= (14u << 26) - (58u << 26);
13610 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13611 r_type
= R_PPC64_TOC16_LO
;
13612 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13615 case R_PPC64_TOC16
:
13616 case R_PPC64_TOC16_LO
:
13617 case R_PPC64_TOC16_DS
:
13618 case R_PPC64_TOC16_LO_DS
:
13620 /* Check for toc tls entries. */
13621 unsigned char *toc_tls
;
13624 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13625 &local_syms
, rel
, input_bfd
);
13631 tls_mask
= *toc_tls
;
13632 if (r_type
== R_PPC64_TOC16_DS
13633 || r_type
== R_PPC64_TOC16_LO_DS
)
13636 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
13641 /* If we found a GD reloc pair, then we might be
13642 doing a GD->IE transition. */
13645 tls_gd
= TLS_TPRELGD
;
13646 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13649 else if (retval
== 3)
13651 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13659 case R_PPC64_GOT_TPREL16_HI
:
13660 case R_PPC64_GOT_TPREL16_HA
:
13662 && (tls_mask
& TLS_TPREL
) == 0)
13664 rel
->r_offset
-= d_offset
;
13665 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13666 r_type
= R_PPC64_NONE
;
13667 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13671 case R_PPC64_GOT_TPREL16_DS
:
13672 case R_PPC64_GOT_TPREL16_LO_DS
:
13674 && (tls_mask
& TLS_TPREL
) == 0)
13677 insn
= bfd_get_32 (input_bfd
,
13678 contents
+ rel
->r_offset
- d_offset
);
13680 insn
|= 0x3c0d0000; /* addis 0,13,0 */
13681 bfd_put_32 (input_bfd
, insn
,
13682 contents
+ rel
->r_offset
- d_offset
);
13683 r_type
= R_PPC64_TPREL16_HA
;
13684 if (toc_symndx
!= 0)
13686 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13687 rel
->r_addend
= toc_addend
;
13688 /* We changed the symbol. Start over in order to
13689 get h, sym, sec etc. right. */
13693 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13699 && (tls_mask
& TLS_TPREL
) == 0)
13701 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13702 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
13705 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
13706 /* Was PPC64_TLS which sits on insn boundary, now
13707 PPC64_TPREL16_LO which is at low-order half-word. */
13708 rel
->r_offset
+= d_offset
;
13709 r_type
= R_PPC64_TPREL16_LO
;
13710 if (toc_symndx
!= 0)
13712 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13713 rel
->r_addend
= toc_addend
;
13714 /* We changed the symbol. Start over in order to
13715 get h, sym, sec etc. right. */
13719 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13723 case R_PPC64_GOT_TLSGD16_HI
:
13724 case R_PPC64_GOT_TLSGD16_HA
:
13725 tls_gd
= TLS_TPRELGD
;
13726 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13730 case R_PPC64_GOT_TLSLD16_HI
:
13731 case R_PPC64_GOT_TLSLD16_HA
:
13732 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13735 if ((tls_mask
& tls_gd
) != 0)
13736 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13737 + R_PPC64_GOT_TPREL16_DS
);
13740 rel
->r_offset
-= d_offset
;
13741 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
13742 r_type
= R_PPC64_NONE
;
13744 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13748 case R_PPC64_GOT_TLSGD16
:
13749 case R_PPC64_GOT_TLSGD16_LO
:
13750 tls_gd
= TLS_TPRELGD
;
13751 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13755 case R_PPC64_GOT_TLSLD16
:
13756 case R_PPC64_GOT_TLSLD16_LO
:
13757 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13759 unsigned int insn1
, insn2
, insn3
;
13763 offset
= (bfd_vma
) -1;
13764 /* If not using the newer R_PPC64_TLSGD/LD to mark
13765 __tls_get_addr calls, we must trust that the call
13766 stays with its arg setup insns, ie. that the next
13767 reloc is the __tls_get_addr call associated with
13768 the current reloc. Edit both insns. */
13769 if (input_section
->has_tls_get_addr_call
13770 && rel
+ 1 < relend
13771 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
13772 htab
->tls_get_addr
,
13773 htab
->tls_get_addr_fd
))
13774 offset
= rel
[1].r_offset
;
13775 /* We read the low GOT_TLS (or TOC16) insn because we
13776 need to keep the destination reg. It may be
13777 something other than the usual r3, and moved to r3
13778 before the call by intervening code. */
13779 insn1
= bfd_get_32 (input_bfd
,
13780 contents
+ rel
->r_offset
- d_offset
);
13781 if ((tls_mask
& tls_gd
) != 0)
13784 insn1
&= (0x1f << 21) | (0x1f << 16);
13785 insn1
|= 58 << 26; /* ld */
13786 insn2
= 0x7c636a14; /* add 3,3,13 */
13787 if (offset
!= (bfd_vma
) -1)
13788 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13789 if ((tls_mask
& TLS_EXPLICIT
) == 0)
13790 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13791 + R_PPC64_GOT_TPREL16_DS
);
13793 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
13794 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13799 insn1
&= 0x1f << 21;
13800 insn1
|= 0x3c0d0000; /* addis r,13,0 */
13801 insn2
= 0x38630000; /* addi 3,3,0 */
13804 /* Was an LD reloc. */
13806 sec
= local_sections
[toc_symndx
];
13808 r_symndx
< symtab_hdr
->sh_info
;
13810 if (local_sections
[r_symndx
] == sec
)
13812 if (r_symndx
>= symtab_hdr
->sh_info
)
13813 r_symndx
= STN_UNDEF
;
13814 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13815 if (r_symndx
!= STN_UNDEF
)
13816 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13817 + sec
->output_offset
13818 + sec
->output_section
->vma
);
13820 else if (toc_symndx
!= 0)
13822 r_symndx
= toc_symndx
;
13823 rel
->r_addend
= toc_addend
;
13825 r_type
= R_PPC64_TPREL16_HA
;
13826 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13827 if (offset
!= (bfd_vma
) -1)
13829 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
13830 R_PPC64_TPREL16_LO
);
13831 rel
[1].r_offset
= offset
+ d_offset
;
13832 rel
[1].r_addend
= rel
->r_addend
;
13835 bfd_put_32 (input_bfd
, insn1
,
13836 contents
+ rel
->r_offset
- d_offset
);
13837 if (offset
!= (bfd_vma
) -1)
13839 insn3
= bfd_get_32 (input_bfd
,
13840 contents
+ offset
+ 4);
13842 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
13844 rel
[1].r_offset
+= 4;
13845 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
+ 4);
13848 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13850 if ((tls_mask
& tls_gd
) == 0
13851 && (tls_gd
== 0 || toc_symndx
!= 0))
13853 /* We changed the symbol. Start over in order
13854 to get h, sym, sec etc. right. */
13860 case R_PPC64_TLSGD
:
13861 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13863 unsigned int insn2
, insn3
;
13864 bfd_vma offset
= rel
->r_offset
;
13866 if ((tls_mask
& TLS_TPRELGD
) != 0)
13869 r_type
= R_PPC64_NONE
;
13870 insn2
= 0x7c636a14; /* add 3,3,13 */
13875 if (toc_symndx
!= 0)
13877 r_symndx
= toc_symndx
;
13878 rel
->r_addend
= toc_addend
;
13880 r_type
= R_PPC64_TPREL16_LO
;
13881 rel
->r_offset
= offset
+ d_offset
;
13882 insn2
= 0x38630000; /* addi 3,3,0 */
13884 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13885 /* Zap the reloc on the _tls_get_addr call too. */
13886 BFD_ASSERT (offset
== rel
[1].r_offset
);
13887 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13888 insn3
= bfd_get_32 (input_bfd
,
13889 contents
+ offset
+ 4);
13891 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
13893 rel
->r_offset
+= 4;
13894 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
+ 4);
13897 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13898 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
13903 case R_PPC64_TLSLD
:
13904 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13906 unsigned int insn2
, insn3
;
13907 bfd_vma offset
= rel
->r_offset
;
13910 sec
= local_sections
[toc_symndx
];
13912 r_symndx
< symtab_hdr
->sh_info
;
13914 if (local_sections
[r_symndx
] == sec
)
13916 if (r_symndx
>= symtab_hdr
->sh_info
)
13917 r_symndx
= STN_UNDEF
;
13918 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13919 if (r_symndx
!= STN_UNDEF
)
13920 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13921 + sec
->output_offset
13922 + sec
->output_section
->vma
);
13924 r_type
= R_PPC64_TPREL16_LO
;
13925 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13926 rel
->r_offset
= offset
+ d_offset
;
13927 /* Zap the reloc on the _tls_get_addr call too. */
13928 BFD_ASSERT (offset
== rel
[1].r_offset
);
13929 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13930 insn2
= 0x38630000; /* addi 3,3,0 */
13931 insn3
= bfd_get_32 (input_bfd
,
13932 contents
+ offset
+ 4);
13934 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
13936 rel
->r_offset
+= 4;
13937 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
+ 4);
13940 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
13945 case R_PPC64_DTPMOD64
:
13946 if (rel
+ 1 < relend
13947 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
13948 && rel
[1].r_offset
== rel
->r_offset
+ 8)
13950 if ((tls_mask
& TLS_GD
) == 0)
13952 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
13953 if ((tls_mask
& TLS_TPRELGD
) != 0)
13954 r_type
= R_PPC64_TPREL64
;
13957 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13958 r_type
= R_PPC64_NONE
;
13960 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13965 if ((tls_mask
& TLS_LD
) == 0)
13967 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13968 r_type
= R_PPC64_NONE
;
13969 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13974 case R_PPC64_TPREL64
:
13975 if ((tls_mask
& TLS_TPREL
) == 0)
13977 r_type
= R_PPC64_NONE
;
13978 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13982 case R_PPC64_ENTRY
:
13983 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13984 if (!bfd_link_pic (info
)
13985 && !info
->traditional_format
13986 && relocation
+ 0x80008000 <= 0xffffffff)
13988 unsigned int insn1
, insn2
;
13990 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13991 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
13992 if ((insn1
& ~0xfffc) == LD_R2_0R12
13993 && insn2
== ADD_R2_R2_R12
)
13995 bfd_put_32 (input_bfd
,
13996 LIS_R2
+ PPC_HA (relocation
),
13997 contents
+ rel
->r_offset
);
13998 bfd_put_32 (input_bfd
,
13999 ADDI_R2_R2
+ PPC_LO (relocation
),
14000 contents
+ rel
->r_offset
+ 4);
14005 relocation
-= (rel
->r_offset
14006 + input_section
->output_offset
14007 + input_section
->output_section
->vma
);
14008 if (relocation
+ 0x80008000 <= 0xffffffff)
14010 unsigned int insn1
, insn2
;
14012 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14013 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14014 if ((insn1
& ~0xfffc) == LD_R2_0R12
14015 && insn2
== ADD_R2_R2_R12
)
14017 bfd_put_32 (input_bfd
,
14018 ADDIS_R2_R12
+ PPC_HA (relocation
),
14019 contents
+ rel
->r_offset
);
14020 bfd_put_32 (input_bfd
,
14021 ADDI_R2_R2
+ PPC_LO (relocation
),
14022 contents
+ rel
->r_offset
+ 4);
14028 case R_PPC64_REL16_HA
:
14029 /* If we are generating a non-PIC executable, edit
14030 . 0: addis 2,12,.TOC.-0b@ha
14031 . addi 2,2,.TOC.-0b@l
14032 used by ELFv2 global entry points to set up r2, to
14035 if .TOC. is in range. */
14036 if (!bfd_link_pic (info
)
14037 && !info
->traditional_format
14039 && rel
->r_addend
== d_offset
14040 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
14041 && rel
+ 1 < relend
14042 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
14043 && rel
[1].r_offset
== rel
->r_offset
+ 4
14044 && rel
[1].r_addend
== rel
->r_addend
+ 4
14045 && relocation
+ 0x80008000 <= 0xffffffff)
14047 unsigned int insn1
, insn2
;
14048 bfd_vma offset
= rel
->r_offset
- d_offset
;
14049 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
14050 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14051 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
14052 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
14054 r_type
= R_PPC64_ADDR16_HA
;
14055 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14056 rel
->r_addend
-= d_offset
;
14057 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
14058 rel
[1].r_addend
-= d_offset
+ 4;
14059 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
14065 /* Handle other relocations that tweak non-addend part of insn. */
14067 max_br_offset
= 1 << 25;
14068 addend
= rel
->r_addend
;
14069 reloc_dest
= DEST_NORMAL
;
14075 case R_PPC64_TOCSAVE
:
14076 if (relocation
+ addend
== (rel
->r_offset
14077 + input_section
->output_offset
14078 + input_section
->output_section
->vma
)
14079 && tocsave_find (htab
, NO_INSERT
,
14080 &local_syms
, rel
, input_bfd
))
14082 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14084 || insn
== CROR_151515
|| insn
== CROR_313131
)
14085 bfd_put_32 (input_bfd
,
14086 STD_R2_0R1
+ STK_TOC (htab
),
14087 contents
+ rel
->r_offset
);
14091 /* Branch taken prediction relocations. */
14092 case R_PPC64_ADDR14_BRTAKEN
:
14093 case R_PPC64_REL14_BRTAKEN
:
14094 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14095 /* Fall through. */
14097 /* Branch not taken prediction relocations. */
14098 case R_PPC64_ADDR14_BRNTAKEN
:
14099 case R_PPC64_REL14_BRNTAKEN
:
14100 insn
|= bfd_get_32 (input_bfd
,
14101 contents
+ rel
->r_offset
) & ~(0x01 << 21);
14102 /* Fall through. */
14104 case R_PPC64_REL14
:
14105 max_br_offset
= 1 << 15;
14106 /* Fall through. */
14108 case R_PPC64_REL24
:
14109 /* Calls to functions with a different TOC, such as calls to
14110 shared objects, need to alter the TOC pointer. This is
14111 done using a linkage stub. A REL24 branching to these
14112 linkage stubs needs to be followed by a nop, as the nop
14113 will be replaced with an instruction to restore the TOC
14118 && h
->oh
->is_func_descriptor
)
14119 fdh
= ppc_follow_link (h
->oh
);
14120 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
14122 if (stub_entry
!= NULL
14123 && (stub_entry
->stub_type
== ppc_stub_plt_call
14124 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14125 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14126 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
14128 bfd_boolean can_plt_call
= FALSE
;
14130 /* All of these stubs will modify r2, so there must be a
14131 branch and link followed by a nop. The nop is
14132 replaced by an insn to restore r2. */
14133 if (rel
->r_offset
+ 8 <= input_section
->size
)
14137 br
= bfd_get_32 (input_bfd
,
14138 contents
+ rel
->r_offset
);
14143 nop
= bfd_get_32 (input_bfd
,
14144 contents
+ rel
->r_offset
+ 4);
14146 || nop
== CROR_151515
|| nop
== CROR_313131
)
14149 && (h
== htab
->tls_get_addr_fd
14150 || h
== htab
->tls_get_addr
)
14151 && htab
->params
->tls_get_addr_opt
)
14153 /* Special stub used, leave nop alone. */
14156 bfd_put_32 (input_bfd
,
14157 LD_R2_0R1
+ STK_TOC (htab
),
14158 contents
+ rel
->r_offset
+ 4);
14159 can_plt_call
= TRUE
;
14164 if (!can_plt_call
&& h
!= NULL
)
14166 const char *name
= h
->elf
.root
.root
.string
;
14171 if (strncmp (name
, "__libc_start_main", 17) == 0
14172 && (name
[17] == 0 || name
[17] == '@'))
14174 /* Allow crt1 branch to go via a toc adjusting
14175 stub. Other calls that never return could do
14176 the same, if we could detect such. */
14177 can_plt_call
= TRUE
;
14183 /* g++ as of 20130507 emits self-calls without a
14184 following nop. This is arguably wrong since we
14185 have conflicting information. On the one hand a
14186 global symbol and on the other a local call
14187 sequence, but don't error for this special case.
14188 It isn't possible to cheaply verify we have
14189 exactly such a call. Allow all calls to the same
14191 asection
*code_sec
= sec
;
14193 if (get_opd_info (sec
) != NULL
)
14195 bfd_vma off
= (relocation
+ addend
14196 - sec
->output_section
->vma
14197 - sec
->output_offset
);
14199 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14201 if (code_sec
== input_section
)
14202 can_plt_call
= TRUE
;
14207 if (stub_entry
->stub_type
== ppc_stub_plt_call
14208 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14209 info
->callbacks
->einfo
14210 /* xgettext:c-format */
14211 (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
14212 "recompile with -fPIC\n"),
14213 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14215 info
->callbacks
->einfo
14216 /* xgettext:c-format */
14217 (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
14218 "(-mcmodel=small toc adjust stub)\n"),
14219 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14221 bfd_set_error (bfd_error_bad_value
);
14226 && (stub_entry
->stub_type
== ppc_stub_plt_call
14227 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
14228 unresolved_reloc
= FALSE
;
14231 if ((stub_entry
== NULL
14232 || stub_entry
->stub_type
== ppc_stub_long_branch
14233 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14234 && get_opd_info (sec
) != NULL
)
14236 /* The branch destination is the value of the opd entry. */
14237 bfd_vma off
= (relocation
+ addend
14238 - sec
->output_section
->vma
14239 - sec
->output_offset
);
14240 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14241 if (dest
!= (bfd_vma
) -1)
14245 reloc_dest
= DEST_OPD
;
14249 /* If the branch is out of reach we ought to have a long
14251 from
= (rel
->r_offset
14252 + input_section
->output_offset
14253 + input_section
->output_section
->vma
);
14255 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14259 if (stub_entry
!= NULL
14260 && (stub_entry
->stub_type
== ppc_stub_long_branch
14261 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14262 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14263 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14264 || (relocation
+ addend
- from
+ max_br_offset
14265 < 2 * max_br_offset
)))
14266 /* Don't use the stub if this branch is in range. */
14269 if (stub_entry
!= NULL
)
14271 /* Munge up the value and addend so that we call the stub
14272 rather than the procedure directly. */
14273 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14275 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14276 relocation
+= (stub_sec
->output_offset
14277 + stub_sec
->output_section
->vma
14278 + stub_sec
->size
- htab
->sfpr
->size
14279 - htab
->sfpr
->output_offset
14280 - htab
->sfpr
->output_section
->vma
);
14282 relocation
= (stub_entry
->stub_offset
14283 + stub_sec
->output_offset
14284 + stub_sec
->output_section
->vma
);
14286 reloc_dest
= DEST_STUB
;
14288 if ((stub_entry
->stub_type
== ppc_stub_plt_call
14289 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14290 && (ALWAYS_EMIT_R2SAVE
14291 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14292 && rel
+ 1 < relend
14293 && rel
[1].r_offset
== rel
->r_offset
+ 4
14294 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14302 /* Set 'a' bit. This is 0b00010 in BO field for branch
14303 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14304 for branch on CTR insns (BO == 1a00t or 1a01t). */
14305 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14306 insn
|= 0x02 << 21;
14307 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14308 insn
|= 0x08 << 21;
14314 /* Invert 'y' bit if not the default. */
14315 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14316 insn
^= 0x01 << 21;
14319 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14322 /* NOP out calls to undefined weak functions.
14323 We can thus call a weak function without first
14324 checking whether the function is defined. */
14326 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14327 && h
->elf
.dynindx
== -1
14328 && r_type
== R_PPC64_REL24
14332 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14338 /* Set `addend'. */
14343 info
->callbacks
->einfo
14344 /* xgettext:c-format */
14345 (_("%P: %B: unknown relocation type %d for `%T'\n"),
14346 input_bfd
, (int) r_type
, sym_name
);
14348 bfd_set_error (bfd_error_bad_value
);
14354 case R_PPC64_TLSGD
:
14355 case R_PPC64_TLSLD
:
14356 case R_PPC64_TOCSAVE
:
14357 case R_PPC64_GNU_VTINHERIT
:
14358 case R_PPC64_GNU_VTENTRY
:
14359 case R_PPC64_ENTRY
:
14362 /* GOT16 relocations. Like an ADDR16 using the symbol's
14363 address in the GOT as relocation value instead of the
14364 symbol's value itself. Also, create a GOT entry for the
14365 symbol and put the symbol value there. */
14366 case R_PPC64_GOT_TLSGD16
:
14367 case R_PPC64_GOT_TLSGD16_LO
:
14368 case R_PPC64_GOT_TLSGD16_HI
:
14369 case R_PPC64_GOT_TLSGD16_HA
:
14370 tls_type
= TLS_TLS
| TLS_GD
;
14373 case R_PPC64_GOT_TLSLD16
:
14374 case R_PPC64_GOT_TLSLD16_LO
:
14375 case R_PPC64_GOT_TLSLD16_HI
:
14376 case R_PPC64_GOT_TLSLD16_HA
:
14377 tls_type
= TLS_TLS
| TLS_LD
;
14380 case R_PPC64_GOT_TPREL16_DS
:
14381 case R_PPC64_GOT_TPREL16_LO_DS
:
14382 case R_PPC64_GOT_TPREL16_HI
:
14383 case R_PPC64_GOT_TPREL16_HA
:
14384 tls_type
= TLS_TLS
| TLS_TPREL
;
14387 case R_PPC64_GOT_DTPREL16_DS
:
14388 case R_PPC64_GOT_DTPREL16_LO_DS
:
14389 case R_PPC64_GOT_DTPREL16_HI
:
14390 case R_PPC64_GOT_DTPREL16_HA
:
14391 tls_type
= TLS_TLS
| TLS_DTPREL
;
14394 case R_PPC64_GOT16
:
14395 case R_PPC64_GOT16_LO
:
14396 case R_PPC64_GOT16_HI
:
14397 case R_PPC64_GOT16_HA
:
14398 case R_PPC64_GOT16_DS
:
14399 case R_PPC64_GOT16_LO_DS
:
14402 /* Relocation is to the entry for this symbol in the global
14407 unsigned long indx
= 0;
14408 struct got_entry
*ent
;
14410 if (tls_type
== (TLS_TLS
| TLS_LD
)
14412 || !h
->elf
.def_dynamic
))
14413 ent
= ppc64_tlsld_got (input_bfd
);
14419 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
14420 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
),
14422 || (bfd_link_pic (info
)
14423 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
14424 /* This is actually a static link, or it is a
14425 -Bsymbolic link and the symbol is defined
14426 locally, or the symbol was forced to be local
14427 because of a version file. */
14431 BFD_ASSERT (h
->elf
.dynindx
!= -1);
14432 indx
= h
->elf
.dynindx
;
14433 unresolved_reloc
= FALSE
;
14435 ent
= h
->elf
.got
.glist
;
14439 if (local_got_ents
== NULL
)
14441 ent
= local_got_ents
[r_symndx
];
14444 for (; ent
!= NULL
; ent
= ent
->next
)
14445 if (ent
->addend
== orig_rel
.r_addend
14446 && ent
->owner
== input_bfd
14447 && ent
->tls_type
== tls_type
)
14453 if (ent
->is_indirect
)
14454 ent
= ent
->got
.ent
;
14455 offp
= &ent
->got
.offset
;
14456 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14460 /* The offset must always be a multiple of 8. We use the
14461 least significant bit to record whether we have already
14462 processed this entry. */
14464 if ((off
& 1) != 0)
14468 /* Generate relocs for the dynamic linker, except in
14469 the case of TLSLD where we'll use one entry per
14477 ? h
->elf
.type
== STT_GNU_IFUNC
14478 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14480 relgot
= htab
->elf
.irelplt
;
14481 else if ((bfd_link_pic (info
) || indx
!= 0)
14483 || (tls_type
== (TLS_TLS
| TLS_LD
)
14484 && !h
->elf
.def_dynamic
)
14485 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
14486 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
14487 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14488 if (relgot
!= NULL
)
14490 outrel
.r_offset
= (got
->output_section
->vma
14491 + got
->output_offset
14493 outrel
.r_addend
= addend
;
14494 if (tls_type
& (TLS_LD
| TLS_GD
))
14496 outrel
.r_addend
= 0;
14497 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14498 if (tls_type
== (TLS_TLS
| TLS_GD
))
14500 loc
= relgot
->contents
;
14501 loc
+= (relgot
->reloc_count
++
14502 * sizeof (Elf64_External_Rela
));
14503 bfd_elf64_swap_reloca_out (output_bfd
,
14505 outrel
.r_offset
+= 8;
14506 outrel
.r_addend
= addend
;
14508 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14511 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14512 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14513 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14514 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14515 else if (indx
!= 0)
14516 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14520 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14522 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14524 /* Write the .got section contents for the sake
14526 loc
= got
->contents
+ off
;
14527 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14531 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14533 outrel
.r_addend
+= relocation
;
14534 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14536 if (htab
->elf
.tls_sec
== NULL
)
14537 outrel
.r_addend
= 0;
14539 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14542 loc
= relgot
->contents
;
14543 loc
+= (relgot
->reloc_count
++
14544 * sizeof (Elf64_External_Rela
));
14545 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14548 /* Init the .got section contents here if we're not
14549 emitting a reloc. */
14552 relocation
+= addend
;
14553 if (tls_type
== (TLS_TLS
| TLS_LD
))
14555 else if (tls_type
!= 0)
14557 if (htab
->elf
.tls_sec
== NULL
)
14561 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14562 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14563 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14566 if (tls_type
== (TLS_TLS
| TLS_GD
))
14568 bfd_put_64 (output_bfd
, relocation
,
14569 got
->contents
+ off
+ 8);
14574 bfd_put_64 (output_bfd
, relocation
,
14575 got
->contents
+ off
);
14579 if (off
>= (bfd_vma
) -2)
14582 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
14583 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
14587 case R_PPC64_PLT16_HA
:
14588 case R_PPC64_PLT16_HI
:
14589 case R_PPC64_PLT16_LO
:
14590 case R_PPC64_PLT32
:
14591 case R_PPC64_PLT64
:
14592 /* Relocation is to the entry for this symbol in the
14593 procedure linkage table. */
14595 struct plt_entry
**plt_list
= NULL
;
14597 plt_list
= &h
->elf
.plt
.plist
;
14598 else if (local_got_ents
!= NULL
)
14600 struct plt_entry
**local_plt
= (struct plt_entry
**)
14601 (local_got_ents
+ symtab_hdr
->sh_info
);
14602 unsigned char *local_got_tls_masks
= (unsigned char *)
14603 (local_plt
+ symtab_hdr
->sh_info
);
14604 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
14605 plt_list
= local_plt
+ r_symndx
;
14609 struct plt_entry
*ent
;
14611 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
14612 if (ent
->plt
.offset
!= (bfd_vma
) -1
14613 && ent
->addend
== orig_rel
.r_addend
)
14617 plt
= htab
->elf
.splt
;
14618 if (!htab
->elf
.dynamic_sections_created
14620 || h
->elf
.dynindx
== -1)
14621 plt
= htab
->elf
.iplt
;
14622 relocation
= (plt
->output_section
->vma
14623 + plt
->output_offset
14624 + ent
->plt
.offset
);
14626 unresolved_reloc
= FALSE
;
14634 /* Relocation value is TOC base. */
14635 relocation
= TOCstart
;
14636 if (r_symndx
== STN_UNDEF
)
14637 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
14638 else if (unresolved_reloc
)
14640 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
14641 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
14643 unresolved_reloc
= TRUE
;
14646 /* TOC16 relocs. We want the offset relative to the TOC base,
14647 which is the address of the start of the TOC plus 0x8000.
14648 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14650 case R_PPC64_TOC16
:
14651 case R_PPC64_TOC16_LO
:
14652 case R_PPC64_TOC16_HI
:
14653 case R_PPC64_TOC16_DS
:
14654 case R_PPC64_TOC16_LO_DS
:
14655 case R_PPC64_TOC16_HA
:
14656 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14659 /* Relocate against the beginning of the section. */
14660 case R_PPC64_SECTOFF
:
14661 case R_PPC64_SECTOFF_LO
:
14662 case R_PPC64_SECTOFF_HI
:
14663 case R_PPC64_SECTOFF_DS
:
14664 case R_PPC64_SECTOFF_LO_DS
:
14665 case R_PPC64_SECTOFF_HA
:
14667 addend
-= sec
->output_section
->vma
;
14670 case R_PPC64_REL16
:
14671 case R_PPC64_REL16_LO
:
14672 case R_PPC64_REL16_HI
:
14673 case R_PPC64_REL16_HA
:
14674 case R_PPC64_REL16DX_HA
:
14677 case R_PPC64_REL14
:
14678 case R_PPC64_REL14_BRNTAKEN
:
14679 case R_PPC64_REL14_BRTAKEN
:
14680 case R_PPC64_REL24
:
14683 case R_PPC64_TPREL16
:
14684 case R_PPC64_TPREL16_LO
:
14685 case R_PPC64_TPREL16_HI
:
14686 case R_PPC64_TPREL16_HA
:
14687 case R_PPC64_TPREL16_DS
:
14688 case R_PPC64_TPREL16_LO_DS
:
14689 case R_PPC64_TPREL16_HIGH
:
14690 case R_PPC64_TPREL16_HIGHA
:
14691 case R_PPC64_TPREL16_HIGHER
:
14692 case R_PPC64_TPREL16_HIGHERA
:
14693 case R_PPC64_TPREL16_HIGHEST
:
14694 case R_PPC64_TPREL16_HIGHESTA
:
14696 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14697 && h
->elf
.dynindx
== -1)
14699 /* Make this relocation against an undefined weak symbol
14700 resolve to zero. This is really just a tweak, since
14701 code using weak externs ought to check that they are
14702 defined before using them. */
14703 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
14705 insn
= bfd_get_32 (input_bfd
, p
);
14706 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
14708 bfd_put_32 (input_bfd
, insn
, p
);
14711 if (htab
->elf
.tls_sec
!= NULL
)
14712 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14713 if (bfd_link_pic (info
))
14714 /* The TPREL16 relocs shouldn't really be used in shared
14715 libs as they will result in DT_TEXTREL being set, but
14716 support them anyway. */
14720 case R_PPC64_DTPREL16
:
14721 case R_PPC64_DTPREL16_LO
:
14722 case R_PPC64_DTPREL16_HI
:
14723 case R_PPC64_DTPREL16_HA
:
14724 case R_PPC64_DTPREL16_DS
:
14725 case R_PPC64_DTPREL16_LO_DS
:
14726 case R_PPC64_DTPREL16_HIGH
:
14727 case R_PPC64_DTPREL16_HIGHA
:
14728 case R_PPC64_DTPREL16_HIGHER
:
14729 case R_PPC64_DTPREL16_HIGHERA
:
14730 case R_PPC64_DTPREL16_HIGHEST
:
14731 case R_PPC64_DTPREL16_HIGHESTA
:
14732 if (htab
->elf
.tls_sec
!= NULL
)
14733 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14736 case R_PPC64_ADDR64_LOCAL
:
14737 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
14742 case R_PPC64_DTPMOD64
:
14747 case R_PPC64_TPREL64
:
14748 if (htab
->elf
.tls_sec
!= NULL
)
14749 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14752 case R_PPC64_DTPREL64
:
14753 if (htab
->elf
.tls_sec
!= NULL
)
14754 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14755 /* Fall through. */
14757 /* Relocations that may need to be propagated if this is a
14759 case R_PPC64_REL30
:
14760 case R_PPC64_REL32
:
14761 case R_PPC64_REL64
:
14762 case R_PPC64_ADDR14
:
14763 case R_PPC64_ADDR14_BRNTAKEN
:
14764 case R_PPC64_ADDR14_BRTAKEN
:
14765 case R_PPC64_ADDR16
:
14766 case R_PPC64_ADDR16_DS
:
14767 case R_PPC64_ADDR16_HA
:
14768 case R_PPC64_ADDR16_HI
:
14769 case R_PPC64_ADDR16_HIGH
:
14770 case R_PPC64_ADDR16_HIGHA
:
14771 case R_PPC64_ADDR16_HIGHER
:
14772 case R_PPC64_ADDR16_HIGHERA
:
14773 case R_PPC64_ADDR16_HIGHEST
:
14774 case R_PPC64_ADDR16_HIGHESTA
:
14775 case R_PPC64_ADDR16_LO
:
14776 case R_PPC64_ADDR16_LO_DS
:
14777 case R_PPC64_ADDR24
:
14778 case R_PPC64_ADDR32
:
14779 case R_PPC64_ADDR64
:
14780 case R_PPC64_UADDR16
:
14781 case R_PPC64_UADDR32
:
14782 case R_PPC64_UADDR64
:
14784 if ((input_section
->flags
& SEC_ALLOC
) == 0)
14787 if (NO_OPD_RELOCS
&& is_opd
)
14790 if (bfd_link_pic (info
)
14791 ? ((h
!= NULL
&& pc_dynrelocs (h
))
14792 || must_be_dyn_reloc (info
, r_type
))
14794 ? h
->dyn_relocs
!= NULL
14795 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14797 bfd_boolean skip
, relocate
;
14801 /* When generating a dynamic object, these relocations
14802 are copied into the output file to be resolved at run
14808 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
14809 input_section
, rel
->r_offset
);
14810 if (out_off
== (bfd_vma
) -1)
14812 else if (out_off
== (bfd_vma
) -2)
14813 skip
= TRUE
, relocate
= TRUE
;
14814 out_off
+= (input_section
->output_section
->vma
14815 + input_section
->output_offset
);
14816 outrel
.r_offset
= out_off
;
14817 outrel
.r_addend
= rel
->r_addend
;
14819 /* Optimize unaligned reloc use. */
14820 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
14821 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
14822 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
14823 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
14824 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
14825 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
14826 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
14827 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
14828 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
14831 memset (&outrel
, 0, sizeof outrel
);
14832 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14834 && r_type
!= R_PPC64_TOC
)
14836 BFD_ASSERT (h
->elf
.dynindx
!= -1);
14837 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
14841 /* This symbol is local, or marked to become local,
14842 or this is an opd section reloc which must point
14843 at a local function. */
14844 outrel
.r_addend
+= relocation
;
14845 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
14847 if (is_opd
&& h
!= NULL
)
14849 /* Lie about opd entries. This case occurs
14850 when building shared libraries and we
14851 reference a function in another shared
14852 lib. The same thing happens for a weak
14853 definition in an application that's
14854 overridden by a strong definition in a
14855 shared lib. (I believe this is a generic
14856 bug in binutils handling of weak syms.)
14857 In these cases we won't use the opd
14858 entry in this lib. */
14859 unresolved_reloc
= FALSE
;
14862 && r_type
== R_PPC64_ADDR64
14864 ? h
->elf
.type
== STT_GNU_IFUNC
14865 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14866 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14869 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14871 /* We need to relocate .opd contents for ld.so.
14872 Prelink also wants simple and consistent rules
14873 for relocs. This make all RELATIVE relocs have
14874 *r_offset equal to r_addend. */
14883 ? h
->elf
.type
== STT_GNU_IFUNC
14884 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14886 info
->callbacks
->einfo
14887 /* xgettext:c-format */
14888 (_("%P: %H: %s for indirect "
14889 "function `%T' unsupported\n"),
14890 input_bfd
, input_section
, rel
->r_offset
,
14891 ppc64_elf_howto_table
[r_type
]->name
,
14895 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
14897 else if (sec
== NULL
|| sec
->owner
== NULL
)
14899 bfd_set_error (bfd_error_bad_value
);
14906 osec
= sec
->output_section
;
14907 indx
= elf_section_data (osec
)->dynindx
;
14911 if ((osec
->flags
& SEC_READONLY
) == 0
14912 && htab
->elf
.data_index_section
!= NULL
)
14913 osec
= htab
->elf
.data_index_section
;
14915 osec
= htab
->elf
.text_index_section
;
14916 indx
= elf_section_data (osec
)->dynindx
;
14918 BFD_ASSERT (indx
!= 0);
14920 /* We are turning this relocation into one
14921 against a section symbol, so subtract out
14922 the output section's address but not the
14923 offset of the input section in the output
14925 outrel
.r_addend
-= osec
->vma
;
14928 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14932 sreloc
= elf_section_data (input_section
)->sreloc
;
14934 ? h
->elf
.type
== STT_GNU_IFUNC
14935 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14936 sreloc
= htab
->elf
.irelplt
;
14937 if (sreloc
== NULL
)
14940 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
14943 loc
= sreloc
->contents
;
14944 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
14945 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14947 /* If this reloc is against an external symbol, it will
14948 be computed at runtime, so there's no need to do
14949 anything now. However, for the sake of prelink ensure
14950 that the section contents are a known value. */
14953 unresolved_reloc
= FALSE
;
14954 /* The value chosen here is quite arbitrary as ld.so
14955 ignores section contents except for the special
14956 case of .opd where the contents might be accessed
14957 before relocation. Choose zero, as that won't
14958 cause reloc overflow. */
14961 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
14962 to improve backward compatibility with older
14964 if (r_type
== R_PPC64_ADDR64
)
14965 addend
= outrel
.r_addend
;
14966 /* Adjust pc_relative relocs to have zero in *r_offset. */
14967 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
14968 addend
= (input_section
->output_section
->vma
14969 + input_section
->output_offset
14976 case R_PPC64_GLOB_DAT
:
14977 case R_PPC64_JMP_SLOT
:
14978 case R_PPC64_JMP_IREL
:
14979 case R_PPC64_RELATIVE
:
14980 /* We shouldn't ever see these dynamic relocs in relocatable
14982 /* Fall through. */
14984 case R_PPC64_PLTGOT16
:
14985 case R_PPC64_PLTGOT16_DS
:
14986 case R_PPC64_PLTGOT16_HA
:
14987 case R_PPC64_PLTGOT16_HI
:
14988 case R_PPC64_PLTGOT16_LO
:
14989 case R_PPC64_PLTGOT16_LO_DS
:
14990 case R_PPC64_PLTREL32
:
14991 case R_PPC64_PLTREL64
:
14992 /* These ones haven't been implemented yet. */
14994 info
->callbacks
->einfo
14995 /* xgettext:c-format */
14996 (_("%P: %B: %s is not supported for `%T'\n"),
14998 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
15000 bfd_set_error (bfd_error_invalid_operation
);
15005 /* Multi-instruction sequences that access the TOC can be
15006 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15007 to nop; addi rb,r2,x; */
15013 case R_PPC64_GOT_TLSLD16_HI
:
15014 case R_PPC64_GOT_TLSGD16_HI
:
15015 case R_PPC64_GOT_TPREL16_HI
:
15016 case R_PPC64_GOT_DTPREL16_HI
:
15017 case R_PPC64_GOT16_HI
:
15018 case R_PPC64_TOC16_HI
:
15019 /* These relocs would only be useful if building up an
15020 offset to later add to r2, perhaps in an indexed
15021 addressing mode instruction. Don't try to optimize.
15022 Unfortunately, the possibility of someone building up an
15023 offset like this or even with the HA relocs, means that
15024 we need to check the high insn when optimizing the low
15028 case R_PPC64_GOT_TLSLD16_HA
:
15029 case R_PPC64_GOT_TLSGD16_HA
:
15030 case R_PPC64_GOT_TPREL16_HA
:
15031 case R_PPC64_GOT_DTPREL16_HA
:
15032 case R_PPC64_GOT16_HA
:
15033 case R_PPC64_TOC16_HA
:
15034 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15035 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15037 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15038 bfd_put_32 (input_bfd
, NOP
, p
);
15042 case R_PPC64_GOT_TLSLD16_LO
:
15043 case R_PPC64_GOT_TLSGD16_LO
:
15044 case R_PPC64_GOT_TPREL16_LO_DS
:
15045 case R_PPC64_GOT_DTPREL16_LO_DS
:
15046 case R_PPC64_GOT16_LO
:
15047 case R_PPC64_GOT16_LO_DS
:
15048 case R_PPC64_TOC16_LO
:
15049 case R_PPC64_TOC16_LO_DS
:
15050 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15051 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15053 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15054 insn
= bfd_get_32 (input_bfd
, p
);
15055 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
15057 /* Transform addic to addi when we change reg. */
15058 insn
&= ~((0x3f << 26) | (0x1f << 16));
15059 insn
|= (14u << 26) | (2 << 16);
15063 insn
&= ~(0x1f << 16);
15066 bfd_put_32 (input_bfd
, insn
, p
);
15071 /* Do any further special processing. */
15072 howto
= ppc64_elf_howto_table
[(int) r_type
];
15078 case R_PPC64_REL16_HA
:
15079 case R_PPC64_REL16DX_HA
:
15080 case R_PPC64_ADDR16_HA
:
15081 case R_PPC64_ADDR16_HIGHA
:
15082 case R_PPC64_ADDR16_HIGHERA
:
15083 case R_PPC64_ADDR16_HIGHESTA
:
15084 case R_PPC64_TOC16_HA
:
15085 case R_PPC64_SECTOFF_HA
:
15086 case R_PPC64_TPREL16_HA
:
15087 case R_PPC64_TPREL16_HIGHA
:
15088 case R_PPC64_TPREL16_HIGHERA
:
15089 case R_PPC64_TPREL16_HIGHESTA
:
15090 case R_PPC64_DTPREL16_HA
:
15091 case R_PPC64_DTPREL16_HIGHA
:
15092 case R_PPC64_DTPREL16_HIGHERA
:
15093 case R_PPC64_DTPREL16_HIGHESTA
:
15094 /* It's just possible that this symbol is a weak symbol
15095 that's not actually defined anywhere. In that case,
15096 'sec' would be NULL, and we should leave the symbol
15097 alone (it will be set to zero elsewhere in the link). */
15100 /* Fall through. */
15102 case R_PPC64_GOT16_HA
:
15103 case R_PPC64_PLTGOT16_HA
:
15104 case R_PPC64_PLT16_HA
:
15105 case R_PPC64_GOT_TLSGD16_HA
:
15106 case R_PPC64_GOT_TLSLD16_HA
:
15107 case R_PPC64_GOT_TPREL16_HA
:
15108 case R_PPC64_GOT_DTPREL16_HA
:
15109 /* Add 0x10000 if sign bit in 0:15 is set.
15110 Bits 0:15 are not used. */
15114 case R_PPC64_ADDR16_DS
:
15115 case R_PPC64_ADDR16_LO_DS
:
15116 case R_PPC64_GOT16_DS
:
15117 case R_PPC64_GOT16_LO_DS
:
15118 case R_PPC64_PLT16_LO_DS
:
15119 case R_PPC64_SECTOFF_DS
:
15120 case R_PPC64_SECTOFF_LO_DS
:
15121 case R_PPC64_TOC16_DS
:
15122 case R_PPC64_TOC16_LO_DS
:
15123 case R_PPC64_PLTGOT16_DS
:
15124 case R_PPC64_PLTGOT16_LO_DS
:
15125 case R_PPC64_GOT_TPREL16_DS
:
15126 case R_PPC64_GOT_TPREL16_LO_DS
:
15127 case R_PPC64_GOT_DTPREL16_DS
:
15128 case R_PPC64_GOT_DTPREL16_LO_DS
:
15129 case R_PPC64_TPREL16_DS
:
15130 case R_PPC64_TPREL16_LO_DS
:
15131 case R_PPC64_DTPREL16_DS
:
15132 case R_PPC64_DTPREL16_LO_DS
:
15133 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15135 /* If this reloc is against an lq, lxv, or stxv insn, then
15136 the value must be a multiple of 16. This is somewhat of
15137 a hack, but the "correct" way to do this by defining _DQ
15138 forms of all the _DS relocs bloats all reloc switches in
15139 this file. It doesn't make much sense to use these
15140 relocs in data, so testing the insn should be safe. */
15141 if ((insn
& (0x3f << 26)) == (56u << 26)
15142 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15144 relocation
+= addend
;
15145 addend
= insn
& (mask
^ 3);
15146 if ((relocation
& mask
) != 0)
15148 relocation
^= relocation
& mask
;
15149 info
->callbacks
->einfo
15150 /* xgettext:c-format */
15151 (_("%P: %H: error: %s not a multiple of %u\n"),
15152 input_bfd
, input_section
, rel
->r_offset
,
15155 bfd_set_error (bfd_error_bad_value
);
15162 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15163 because such sections are not SEC_ALLOC and thus ld.so will
15164 not process them. */
15165 if (unresolved_reloc
15166 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15167 && h
->elf
.def_dynamic
)
15168 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15169 rel
->r_offset
) != (bfd_vma
) -1)
15171 info
->callbacks
->einfo
15172 /* xgettext:c-format */
15173 (_("%P: %H: unresolvable %s against `%T'\n"),
15174 input_bfd
, input_section
, rel
->r_offset
,
15176 h
->elf
.root
.root
.string
);
15180 /* 16-bit fields in insns mostly have signed values, but a
15181 few insns have 16-bit unsigned values. Really, we should
15182 have different reloc types. */
15183 if (howto
->complain_on_overflow
!= complain_overflow_dont
15184 && howto
->dst_mask
== 0xffff
15185 && (input_section
->flags
& SEC_CODE
) != 0)
15187 enum complain_overflow complain
= complain_overflow_signed
;
15189 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15190 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15191 complain
= complain_overflow_bitfield
;
15192 else if (howto
->rightshift
== 0
15193 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15194 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15195 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15196 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15197 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15198 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15199 complain
= complain_overflow_unsigned
;
15200 if (howto
->complain_on_overflow
!= complain
)
15202 alt_howto
= *howto
;
15203 alt_howto
.complain_on_overflow
= complain
;
15204 howto
= &alt_howto
;
15208 if (r_type
== R_PPC64_REL16DX_HA
)
15210 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15211 if (rel
->r_offset
+ 4 > input_section
->size
)
15212 r
= bfd_reloc_outofrange
;
15215 relocation
+= addend
;
15216 relocation
-= (rel
->r_offset
15217 + input_section
->output_offset
15218 + input_section
->output_section
->vma
);
15219 relocation
= (bfd_signed_vma
) relocation
>> 16;
15220 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15222 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15223 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15225 if (relocation
+ 0x8000 > 0xffff)
15226 r
= bfd_reloc_overflow
;
15230 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15231 rel
->r_offset
, relocation
, addend
);
15233 if (r
!= bfd_reloc_ok
)
15235 char *more_info
= NULL
;
15236 const char *reloc_name
= howto
->name
;
15238 if (reloc_dest
!= DEST_NORMAL
)
15240 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15241 if (more_info
!= NULL
)
15243 strcpy (more_info
, reloc_name
);
15244 strcat (more_info
, (reloc_dest
== DEST_OPD
15245 ? " (OPD)" : " (stub)"));
15246 reloc_name
= more_info
;
15250 if (r
== bfd_reloc_overflow
)
15252 /* On code like "if (foo) foo();" don't report overflow
15253 on a branch to zero when foo is undefined. */
15255 && (reloc_dest
== DEST_STUB
15257 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15258 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15259 && is_branch_reloc (r_type
))))
15260 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15261 sym_name
, reloc_name
,
15263 input_bfd
, input_section
,
15268 info
->callbacks
->einfo
15269 /* xgettext:c-format */
15270 (_("%P: %H: %s against `%T': error %d\n"),
15271 input_bfd
, input_section
, rel
->r_offset
,
15272 reloc_name
, sym_name
, (int) r
);
15275 if (more_info
!= NULL
)
15285 Elf_Internal_Shdr
*rel_hdr
;
15286 size_t deleted
= rel
- wrel
;
15288 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15289 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15290 if (rel_hdr
->sh_size
== 0)
15292 /* It is too late to remove an empty reloc section. Leave
15294 ??? What is wrong with an empty section??? */
15295 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15298 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15299 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15300 input_section
->reloc_count
-= deleted
;
15303 /* If we're emitting relocations, then shortly after this function
15304 returns, reloc offsets and addends for this section will be
15305 adjusted. Worse, reloc symbol indices will be for the output
15306 file rather than the input. Save a copy of the relocs for
15307 opd_entry_value. */
15308 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15311 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15312 rel
= bfd_alloc (input_bfd
, amt
);
15313 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15314 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15317 memcpy (rel
, relocs
, amt
);
15322 /* Adjust the value of any local symbols in opd sections. */
15325 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15326 const char *name ATTRIBUTE_UNUSED
,
15327 Elf_Internal_Sym
*elfsym
,
15328 asection
*input_sec
,
15329 struct elf_link_hash_entry
*h
)
15331 struct _opd_sec_data
*opd
;
15338 opd
= get_opd_info (input_sec
);
15339 if (opd
== NULL
|| opd
->adjust
== NULL
)
15342 value
= elfsym
->st_value
- input_sec
->output_offset
;
15343 if (!bfd_link_relocatable (info
))
15344 value
-= input_sec
->output_section
->vma
;
15346 adjust
= opd
->adjust
[OPD_NDX (value
)];
15350 elfsym
->st_value
+= adjust
;
15354 /* Finish up dynamic symbol handling. We set the contents of various
15355 dynamic sections here. */
15358 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15359 struct bfd_link_info
*info
,
15360 struct elf_link_hash_entry
*h
,
15361 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
15363 struct ppc_link_hash_table
*htab
;
15364 struct plt_entry
*ent
;
15365 Elf_Internal_Rela rela
;
15368 htab
= ppc_hash_table (info
);
15372 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15373 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15375 /* This symbol has an entry in the procedure linkage
15376 table. Set it up. */
15377 if (!htab
->elf
.dynamic_sections_created
15378 || h
->dynindx
== -1)
15380 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
15382 && (h
->root
.type
== bfd_link_hash_defined
15383 || h
->root
.type
== bfd_link_hash_defweak
));
15384 rela
.r_offset
= (htab
->elf
.iplt
->output_section
->vma
15385 + htab
->elf
.iplt
->output_offset
15386 + ent
->plt
.offset
);
15388 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
15390 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15391 rela
.r_addend
= (h
->root
.u
.def
.value
15392 + h
->root
.u
.def
.section
->output_offset
15393 + h
->root
.u
.def
.section
->output_section
->vma
15395 loc
= (htab
->elf
.irelplt
->contents
15396 + (htab
->elf
.irelplt
->reloc_count
++
15397 * sizeof (Elf64_External_Rela
)));
15401 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
15402 + htab
->elf
.splt
->output_offset
15403 + ent
->plt
.offset
);
15404 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
15405 rela
.r_addend
= ent
->addend
;
15406 loc
= (htab
->elf
.srelplt
->contents
15407 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
15408 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
15410 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15412 if (!htab
->opd_abi
)
15414 if (!h
->def_regular
)
15416 /* Mark the symbol as undefined, rather than as
15417 defined in glink. Leave the value if there were
15418 any relocations where pointer equality matters
15419 (this is a clue for the dynamic linker, to make
15420 function pointer comparisons work between an
15421 application and shared library), otherwise set it
15423 sym
->st_shndx
= SHN_UNDEF
;
15424 if (!h
->pointer_equality_needed
)
15426 else if (!h
->ref_regular_nonweak
)
15428 /* This breaks function pointer comparisons, but
15429 that is better than breaking tests for a NULL
15430 function pointer. */
15439 /* This symbol needs a copy reloc. Set it up. */
15441 if (h
->dynindx
== -1
15442 || (h
->root
.type
!= bfd_link_hash_defined
15443 && h
->root
.type
!= bfd_link_hash_defweak
)
15444 || htab
->relbss
== NULL
)
15447 rela
.r_offset
= (h
->root
.u
.def
.value
15448 + h
->root
.u
.def
.section
->output_section
->vma
15449 + h
->root
.u
.def
.section
->output_offset
);
15450 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15452 loc
= htab
->relbss
->contents
;
15453 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15454 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15460 /* Used to decide how to sort relocs in an optimal manner for the
15461 dynamic linker, before writing them out. */
15463 static enum elf_reloc_type_class
15464 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15465 const asection
*rel_sec
,
15466 const Elf_Internal_Rela
*rela
)
15468 enum elf_ppc64_reloc_type r_type
;
15469 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15471 if (rel_sec
== htab
->elf
.irelplt
)
15472 return reloc_class_ifunc
;
15474 r_type
= ELF64_R_TYPE (rela
->r_info
);
15477 case R_PPC64_RELATIVE
:
15478 return reloc_class_relative
;
15479 case R_PPC64_JMP_SLOT
:
15480 return reloc_class_plt
;
15482 return reloc_class_copy
;
15484 return reloc_class_normal
;
15488 /* Finish up the dynamic sections. */
15491 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15492 struct bfd_link_info
*info
)
15494 struct ppc_link_hash_table
*htab
;
15498 htab
= ppc_hash_table (info
);
15502 dynobj
= htab
->elf
.dynobj
;
15503 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15505 if (htab
->elf
.dynamic_sections_created
)
15507 Elf64_External_Dyn
*dyncon
, *dynconend
;
15509 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15512 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15513 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15514 for (; dyncon
< dynconend
; dyncon
++)
15516 Elf_Internal_Dyn dyn
;
15519 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
15526 case DT_PPC64_GLINK
:
15528 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15529 /* We stupidly defined DT_PPC64_GLINK to be the start
15530 of glink rather than the first entry point, which is
15531 what ld.so needs, and now have a bigger stub to
15532 support automatic multiple TOCs. */
15533 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 8 * 4;
15537 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15540 dyn
.d_un
.d_ptr
= s
->vma
;
15544 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
15545 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
15548 case DT_PPC64_OPDSZ
:
15549 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15552 dyn
.d_un
.d_val
= s
->size
;
15556 s
= htab
->elf
.splt
;
15557 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15561 s
= htab
->elf
.srelplt
;
15562 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15566 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
15570 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
15574 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0)
15576 /* Fill in the first entry in the global offset table.
15577 We use it to hold the link-time TOCbase. */
15578 bfd_put_64 (output_bfd
,
15579 elf_gp (output_bfd
) + TOC_BASE_OFF
,
15580 htab
->elf
.sgot
->contents
);
15582 /* Set .got entry size. */
15583 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
15586 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
15588 /* Set .plt entry size. */
15589 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
15590 = PLT_ENTRY_SIZE (htab
);
15593 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15594 brlt ourselves if emitrelocations. */
15595 if (htab
->brlt
!= NULL
15596 && htab
->brlt
->reloc_count
!= 0
15597 && !_bfd_elf_link_output_relocs (output_bfd
,
15599 elf_section_data (htab
->brlt
)->rela
.hdr
,
15600 elf_section_data (htab
->brlt
)->relocs
,
15604 if (htab
->glink
!= NULL
15605 && htab
->glink
->reloc_count
!= 0
15606 && !_bfd_elf_link_output_relocs (output_bfd
,
15608 elf_section_data (htab
->glink
)->rela
.hdr
,
15609 elf_section_data (htab
->glink
)->relocs
,
15613 if (htab
->glink_eh_frame
!= NULL
15614 && htab
->glink_eh_frame
->size
!= 0)
15618 asection
*stub_sec
;
15620 p
= htab
->glink_eh_frame
->contents
+ sizeof (glink_eh_frame_cie
);
15621 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
15623 stub_sec
= stub_sec
->next
)
15624 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
15630 /* Offset to stub section. */
15631 val
= (stub_sec
->output_section
->vma
15632 + stub_sec
->output_offset
);
15633 val
-= (htab
->glink_eh_frame
->output_section
->vma
15634 + htab
->glink_eh_frame
->output_offset
15635 + (p
- htab
->glink_eh_frame
->contents
));
15636 if (val
+ 0x80000000 > 0xffffffff)
15638 info
->callbacks
->einfo
15639 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
15643 bfd_put_32 (dynobj
, val
, p
);
15645 /* stub section size. */
15647 /* Augmentation. */
15652 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
15658 /* Offset to .glink. */
15659 val
= (htab
->glink
->output_section
->vma
15660 + htab
->glink
->output_offset
15662 val
-= (htab
->glink_eh_frame
->output_section
->vma
15663 + htab
->glink_eh_frame
->output_offset
15664 + (p
- htab
->glink_eh_frame
->contents
));
15665 if (val
+ 0x80000000 > 0xffffffff)
15667 info
->callbacks
->einfo
15668 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
15669 htab
->glink
->name
);
15672 bfd_put_32 (dynobj
, val
, p
);
15676 /* Augmentation. */
15682 if (htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
15683 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
15684 htab
->glink_eh_frame
,
15685 htab
->glink_eh_frame
->contents
))
15689 /* We need to handle writing out multiple GOT sections ourselves,
15690 since we didn't add them to DYNOBJ. We know dynobj is the first
15692 while ((dynobj
= dynobj
->link
.next
) != NULL
)
15696 if (!is_ppc64_elf (dynobj
))
15699 s
= ppc64_elf_tdata (dynobj
)->got
;
15702 && s
->output_section
!= bfd_abs_section_ptr
15703 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15704 s
->contents
, s
->output_offset
,
15707 s
= ppc64_elf_tdata (dynobj
)->relgot
;
15710 && s
->output_section
!= bfd_abs_section_ptr
15711 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15712 s
->contents
, s
->output_offset
,
15720 #include "elf64-target.h"
15722 /* FreeBSD support */
15724 #undef TARGET_LITTLE_SYM
15725 #undef TARGET_LITTLE_NAME
15727 #undef TARGET_BIG_SYM
15728 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
15729 #undef TARGET_BIG_NAME
15730 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
15733 #define ELF_OSABI ELFOSABI_FREEBSD
15736 #define elf64_bed elf64_powerpc_fbsd_bed
15738 #include "elf64-target.h"