1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2015 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_default_execstack 0
80 #define bfd_elf64_mkobject ppc64_elf_mkobject
81 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
82 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
83 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
84 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
85 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
86 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
87 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
88 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
90 #define elf_backend_object_p ppc64_elf_object_p
91 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
92 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
93 #define elf_backend_write_core_note ppc64_elf_write_core_note
94 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
95 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
96 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
97 #define elf_backend_check_directives ppc64_elf_before_check_relocs
98 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
99 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
100 #define elf_backend_check_relocs ppc64_elf_check_relocs
101 #define elf_backend_gc_keep ppc64_elf_gc_keep
102 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
103 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
104 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
105 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
106 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
107 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
108 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
109 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
110 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
111 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
112 #define elf_backend_action_discarded ppc64_elf_action_discarded
113 #define elf_backend_relocate_section ppc64_elf_relocate_section
114 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
115 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
116 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
117 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
118 #define elf_backend_special_sections ppc64_elf_special_sections
119 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
121 /* The name of the dynamic interpreter. This is put in the .interp
123 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
125 /* The size in bytes of an entry in the procedure linkage table. */
126 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
128 /* The initial size of the plt reserved for the dynamic linker. */
129 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
131 /* Offsets to some stack save slots. */
133 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
134 /* This one is dodgy. ELFv2 does not have a linker word, so use the
135 CR save slot. Used only by optimised __tls_get_addr call stub,
136 relying on __tls_get_addr_opt not saving CR.. */
137 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
139 /* TOC base pointers offset from start of TOC. */
140 #define TOC_BASE_OFF 0x8000
141 /* TOC base alignment. */
142 #define TOC_BASE_ALIGN 256
144 /* Offset of tp and dtp pointers from start of TLS block. */
145 #define TP_OFFSET 0x7000
146 #define DTP_OFFSET 0x8000
148 /* .plt call stub instructions. The normal stub is like this, but
149 sometimes the .plt entry crosses a 64k boundary and we need to
150 insert an addi to adjust r11. */
151 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
152 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
153 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
154 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
155 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
156 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
157 #define BCTR 0x4e800420 /* bctr */
159 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
160 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
161 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
163 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
164 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
165 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
166 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
167 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
168 #define BNECTR 0x4ca20420 /* bnectr+ */
169 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
171 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
172 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
173 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
175 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
177 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
178 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
179 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
181 /* glink call stub instructions. We enter with the index in R0. */
182 #define GLINK_CALL_STUB_SIZE (16*4)
186 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
187 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
189 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
190 /* ld %2,(0b-1b)(%11) */
191 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
192 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
198 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
199 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
200 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
201 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
202 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
205 #define NOP 0x60000000
207 /* Some other nops. */
208 #define CROR_151515 0x4def7b82
209 #define CROR_313131 0x4ffffb82
211 /* .glink entries for the first 32k functions are two instructions. */
212 #define LI_R0_0 0x38000000 /* li %r0,0 */
213 #define B_DOT 0x48000000 /* b . */
215 /* After that, we need two instructions to load the index, followed by
217 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
218 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
220 /* Instructions used by the save and restore reg functions. */
221 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
222 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
223 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
224 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
225 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
226 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
227 #define LI_R12_0 0x39800000 /* li %r12,0 */
228 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
229 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
230 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
231 #define BLR 0x4e800020 /* blr */
233 /* Since .opd is an array of descriptors and each entry will end up
234 with identical R_PPC64_RELATIVE relocs, there is really no need to
235 propagate .opd relocs; The dynamic linker should be taught to
236 relocate .opd without reloc entries. */
237 #ifndef NO_OPD_RELOCS
238 #define NO_OPD_RELOCS 0
242 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
246 abiversion (bfd
*abfd
)
248 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
252 set_abiversion (bfd
*abfd
, int ver
)
254 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
255 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
258 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
260 /* Relocation HOWTO's. */
261 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
263 static reloc_howto_type ppc64_elf_howto_raw
[] = {
264 /* This reloc does nothing. */
265 HOWTO (R_PPC64_NONE
, /* type */
267 3, /* size (0 = byte, 1 = short, 2 = long) */
269 FALSE
, /* pc_relative */
271 complain_overflow_dont
, /* complain_on_overflow */
272 bfd_elf_generic_reloc
, /* special_function */
273 "R_PPC64_NONE", /* name */
274 FALSE
, /* partial_inplace */
277 FALSE
), /* pcrel_offset */
279 /* A standard 32 bit relocation. */
280 HOWTO (R_PPC64_ADDR32
, /* type */
282 2, /* size (0 = byte, 1 = short, 2 = long) */
284 FALSE
, /* pc_relative */
286 complain_overflow_bitfield
, /* complain_on_overflow */
287 bfd_elf_generic_reloc
, /* special_function */
288 "R_PPC64_ADDR32", /* name */
289 FALSE
, /* partial_inplace */
291 0xffffffff, /* dst_mask */
292 FALSE
), /* pcrel_offset */
294 /* An absolute 26 bit branch; the lower two bits must be zero.
295 FIXME: we don't check that, we just clear them. */
296 HOWTO (R_PPC64_ADDR24
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 FALSE
, /* pc_relative */
302 complain_overflow_bitfield
, /* complain_on_overflow */
303 bfd_elf_generic_reloc
, /* special_function */
304 "R_PPC64_ADDR24", /* name */
305 FALSE
, /* partial_inplace */
307 0x03fffffc, /* dst_mask */
308 FALSE
), /* pcrel_offset */
310 /* A standard 16 bit relocation. */
311 HOWTO (R_PPC64_ADDR16
, /* type */
313 1, /* size (0 = byte, 1 = short, 2 = long) */
315 FALSE
, /* pc_relative */
317 complain_overflow_bitfield
, /* complain_on_overflow */
318 bfd_elf_generic_reloc
, /* special_function */
319 "R_PPC64_ADDR16", /* name */
320 FALSE
, /* partial_inplace */
322 0xffff, /* dst_mask */
323 FALSE
), /* pcrel_offset */
325 /* A 16 bit relocation without overflow. */
326 HOWTO (R_PPC64_ADDR16_LO
, /* type */
328 1, /* size (0 = byte, 1 = short, 2 = long) */
330 FALSE
, /* pc_relative */
332 complain_overflow_dont
,/* complain_on_overflow */
333 bfd_elf_generic_reloc
, /* special_function */
334 "R_PPC64_ADDR16_LO", /* name */
335 FALSE
, /* partial_inplace */
337 0xffff, /* dst_mask */
338 FALSE
), /* pcrel_offset */
340 /* Bits 16-31 of an address. */
341 HOWTO (R_PPC64_ADDR16_HI
, /* type */
343 1, /* size (0 = byte, 1 = short, 2 = long) */
345 FALSE
, /* pc_relative */
347 complain_overflow_signed
, /* complain_on_overflow */
348 bfd_elf_generic_reloc
, /* special_function */
349 "R_PPC64_ADDR16_HI", /* name */
350 FALSE
, /* partial_inplace */
352 0xffff, /* dst_mask */
353 FALSE
), /* pcrel_offset */
355 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
356 bits, treated as a signed number, is negative. */
357 HOWTO (R_PPC64_ADDR16_HA
, /* type */
359 1, /* size (0 = byte, 1 = short, 2 = long) */
361 FALSE
, /* pc_relative */
363 complain_overflow_signed
, /* complain_on_overflow */
364 ppc64_elf_ha_reloc
, /* special_function */
365 "R_PPC64_ADDR16_HA", /* name */
366 FALSE
, /* partial_inplace */
368 0xffff, /* dst_mask */
369 FALSE
), /* pcrel_offset */
371 /* An absolute 16 bit branch; the lower two bits must be zero.
372 FIXME: we don't check that, we just clear them. */
373 HOWTO (R_PPC64_ADDR14
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 FALSE
, /* pc_relative */
379 complain_overflow_signed
, /* complain_on_overflow */
380 ppc64_elf_branch_reloc
, /* special_function */
381 "R_PPC64_ADDR14", /* name */
382 FALSE
, /* partial_inplace */
384 0x0000fffc, /* dst_mask */
385 FALSE
), /* pcrel_offset */
387 /* An absolute 16 bit branch, for which bit 10 should be set to
388 indicate that the branch is expected to be taken. The lower two
389 bits must be zero. */
390 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 FALSE
, /* pc_relative */
396 complain_overflow_signed
, /* complain_on_overflow */
397 ppc64_elf_brtaken_reloc
, /* special_function */
398 "R_PPC64_ADDR14_BRTAKEN",/* name */
399 FALSE
, /* partial_inplace */
401 0x0000fffc, /* dst_mask */
402 FALSE
), /* pcrel_offset */
404 /* An absolute 16 bit branch, for which bit 10 should be set to
405 indicate that the branch is not expected to be taken. The lower
406 two bits must be zero. */
407 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
411 FALSE
, /* pc_relative */
413 complain_overflow_signed
, /* complain_on_overflow */
414 ppc64_elf_brtaken_reloc
, /* special_function */
415 "R_PPC64_ADDR14_BRNTAKEN",/* name */
416 FALSE
, /* partial_inplace */
418 0x0000fffc, /* dst_mask */
419 FALSE
), /* pcrel_offset */
421 /* A relative 26 bit branch; the lower two bits must be zero. */
422 HOWTO (R_PPC64_REL24
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 TRUE
, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 ppc64_elf_branch_reloc
, /* special_function */
430 "R_PPC64_REL24", /* name */
431 FALSE
, /* partial_inplace */
433 0x03fffffc, /* dst_mask */
434 TRUE
), /* pcrel_offset */
436 /* A relative 16 bit branch; the lower two bits must be zero. */
437 HOWTO (R_PPC64_REL14
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 TRUE
, /* pc_relative */
443 complain_overflow_signed
, /* complain_on_overflow */
444 ppc64_elf_branch_reloc
, /* special_function */
445 "R_PPC64_REL14", /* name */
446 FALSE
, /* partial_inplace */
448 0x0000fffc, /* dst_mask */
449 TRUE
), /* pcrel_offset */
451 /* A relative 16 bit branch. Bit 10 should be set to indicate that
452 the branch is expected to be taken. The lower two bits must be
454 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 TRUE
, /* pc_relative */
460 complain_overflow_signed
, /* complain_on_overflow */
461 ppc64_elf_brtaken_reloc
, /* special_function */
462 "R_PPC64_REL14_BRTAKEN", /* name */
463 FALSE
, /* partial_inplace */
465 0x0000fffc, /* dst_mask */
466 TRUE
), /* pcrel_offset */
468 /* A relative 16 bit branch. Bit 10 should be set to indicate that
469 the branch is not expected to be taken. The lower two bits must
471 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
473 2, /* size (0 = byte, 1 = short, 2 = long) */
475 TRUE
, /* pc_relative */
477 complain_overflow_signed
, /* complain_on_overflow */
478 ppc64_elf_brtaken_reloc
, /* special_function */
479 "R_PPC64_REL14_BRNTAKEN",/* name */
480 FALSE
, /* partial_inplace */
482 0x0000fffc, /* dst_mask */
483 TRUE
), /* pcrel_offset */
485 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
487 HOWTO (R_PPC64_GOT16
, /* type */
489 1, /* size (0 = byte, 1 = short, 2 = long) */
491 FALSE
, /* pc_relative */
493 complain_overflow_signed
, /* complain_on_overflow */
494 ppc64_elf_unhandled_reloc
, /* special_function */
495 "R_PPC64_GOT16", /* name */
496 FALSE
, /* partial_inplace */
498 0xffff, /* dst_mask */
499 FALSE
), /* pcrel_offset */
501 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
503 HOWTO (R_PPC64_GOT16_LO
, /* type */
505 1, /* size (0 = byte, 1 = short, 2 = long) */
507 FALSE
, /* pc_relative */
509 complain_overflow_dont
, /* complain_on_overflow */
510 ppc64_elf_unhandled_reloc
, /* special_function */
511 "R_PPC64_GOT16_LO", /* name */
512 FALSE
, /* partial_inplace */
514 0xffff, /* dst_mask */
515 FALSE
), /* pcrel_offset */
517 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
519 HOWTO (R_PPC64_GOT16_HI
, /* type */
521 1, /* size (0 = byte, 1 = short, 2 = long) */
523 FALSE
, /* pc_relative */
525 complain_overflow_signed
,/* complain_on_overflow */
526 ppc64_elf_unhandled_reloc
, /* special_function */
527 "R_PPC64_GOT16_HI", /* name */
528 FALSE
, /* partial_inplace */
530 0xffff, /* dst_mask */
531 FALSE
), /* pcrel_offset */
533 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
535 HOWTO (R_PPC64_GOT16_HA
, /* type */
537 1, /* size (0 = byte, 1 = short, 2 = long) */
539 FALSE
, /* pc_relative */
541 complain_overflow_signed
,/* complain_on_overflow */
542 ppc64_elf_unhandled_reloc
, /* special_function */
543 "R_PPC64_GOT16_HA", /* name */
544 FALSE
, /* partial_inplace */
546 0xffff, /* dst_mask */
547 FALSE
), /* pcrel_offset */
549 /* This is used only by the dynamic linker. The symbol should exist
550 both in the object being run and in some shared library. The
551 dynamic linker copies the data addressed by the symbol from the
552 shared library into the object, because the object being
553 run has to have the data at some particular address. */
554 HOWTO (R_PPC64_COPY
, /* type */
556 0, /* this one is variable size */
558 FALSE
, /* pc_relative */
560 complain_overflow_dont
, /* complain_on_overflow */
561 ppc64_elf_unhandled_reloc
, /* special_function */
562 "R_PPC64_COPY", /* name */
563 FALSE
, /* partial_inplace */
566 FALSE
), /* pcrel_offset */
568 /* Like R_PPC64_ADDR64, but used when setting global offset table
570 HOWTO (R_PPC64_GLOB_DAT
, /* type */
572 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
574 FALSE
, /* pc_relative */
576 complain_overflow_dont
, /* complain_on_overflow */
577 ppc64_elf_unhandled_reloc
, /* special_function */
578 "R_PPC64_GLOB_DAT", /* name */
579 FALSE
, /* partial_inplace */
581 ONES (64), /* dst_mask */
582 FALSE
), /* pcrel_offset */
584 /* Created by the link editor. Marks a procedure linkage table
585 entry for a symbol. */
586 HOWTO (R_PPC64_JMP_SLOT
, /* type */
588 0, /* size (0 = byte, 1 = short, 2 = long) */
590 FALSE
, /* pc_relative */
592 complain_overflow_dont
, /* complain_on_overflow */
593 ppc64_elf_unhandled_reloc
, /* special_function */
594 "R_PPC64_JMP_SLOT", /* name */
595 FALSE
, /* partial_inplace */
598 FALSE
), /* pcrel_offset */
600 /* Used only by the dynamic linker. When the object is run, this
601 doubleword64 is set to the load address of the object, plus the
603 HOWTO (R_PPC64_RELATIVE
, /* type */
605 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
607 FALSE
, /* pc_relative */
609 complain_overflow_dont
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_PPC64_RELATIVE", /* name */
612 FALSE
, /* partial_inplace */
614 ONES (64), /* dst_mask */
615 FALSE
), /* pcrel_offset */
617 /* Like R_PPC64_ADDR32, but may be unaligned. */
618 HOWTO (R_PPC64_UADDR32
, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 FALSE
, /* pc_relative */
624 complain_overflow_bitfield
, /* complain_on_overflow */
625 bfd_elf_generic_reloc
, /* special_function */
626 "R_PPC64_UADDR32", /* name */
627 FALSE
, /* partial_inplace */
629 0xffffffff, /* dst_mask */
630 FALSE
), /* pcrel_offset */
632 /* Like R_PPC64_ADDR16, but may be unaligned. */
633 HOWTO (R_PPC64_UADDR16
, /* type */
635 1, /* size (0 = byte, 1 = short, 2 = long) */
637 FALSE
, /* pc_relative */
639 complain_overflow_bitfield
, /* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_PPC64_UADDR16", /* name */
642 FALSE
, /* partial_inplace */
644 0xffff, /* dst_mask */
645 FALSE
), /* pcrel_offset */
647 /* 32-bit PC relative. */
648 HOWTO (R_PPC64_REL32
, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 TRUE
, /* pc_relative */
654 complain_overflow_signed
, /* complain_on_overflow */
655 bfd_elf_generic_reloc
, /* special_function */
656 "R_PPC64_REL32", /* name */
657 FALSE
, /* partial_inplace */
659 0xffffffff, /* dst_mask */
660 TRUE
), /* pcrel_offset */
662 /* 32-bit relocation to the symbol's procedure linkage table. */
663 HOWTO (R_PPC64_PLT32
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 FALSE
, /* pc_relative */
669 complain_overflow_bitfield
, /* complain_on_overflow */
670 ppc64_elf_unhandled_reloc
, /* special_function */
671 "R_PPC64_PLT32", /* name */
672 FALSE
, /* partial_inplace */
674 0xffffffff, /* dst_mask */
675 FALSE
), /* pcrel_offset */
677 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
678 FIXME: R_PPC64_PLTREL32 not supported. */
679 HOWTO (R_PPC64_PLTREL32
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 TRUE
, /* pc_relative */
685 complain_overflow_signed
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC64_PLTREL32", /* name */
688 FALSE
, /* partial_inplace */
690 0xffffffff, /* dst_mask */
691 TRUE
), /* pcrel_offset */
693 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
695 HOWTO (R_PPC64_PLT16_LO
, /* type */
697 1, /* size (0 = byte, 1 = short, 2 = long) */
699 FALSE
, /* pc_relative */
701 complain_overflow_dont
, /* complain_on_overflow */
702 ppc64_elf_unhandled_reloc
, /* special_function */
703 "R_PPC64_PLT16_LO", /* name */
704 FALSE
, /* partial_inplace */
706 0xffff, /* dst_mask */
707 FALSE
), /* pcrel_offset */
709 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
711 HOWTO (R_PPC64_PLT16_HI
, /* type */
713 1, /* size (0 = byte, 1 = short, 2 = long) */
715 FALSE
, /* pc_relative */
717 complain_overflow_signed
, /* complain_on_overflow */
718 ppc64_elf_unhandled_reloc
, /* special_function */
719 "R_PPC64_PLT16_HI", /* name */
720 FALSE
, /* partial_inplace */
722 0xffff, /* dst_mask */
723 FALSE
), /* pcrel_offset */
725 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
727 HOWTO (R_PPC64_PLT16_HA
, /* type */
729 1, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_signed
, /* complain_on_overflow */
734 ppc64_elf_unhandled_reloc
, /* special_function */
735 "R_PPC64_PLT16_HA", /* name */
736 FALSE
, /* partial_inplace */
738 0xffff, /* dst_mask */
739 FALSE
), /* pcrel_offset */
741 /* 16-bit section relative relocation. */
742 HOWTO (R_PPC64_SECTOFF
, /* type */
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 FALSE
, /* pc_relative */
748 complain_overflow_signed
, /* complain_on_overflow */
749 ppc64_elf_sectoff_reloc
, /* special_function */
750 "R_PPC64_SECTOFF", /* name */
751 FALSE
, /* partial_inplace */
753 0xffff, /* dst_mask */
754 FALSE
), /* pcrel_offset */
756 /* Like R_PPC64_SECTOFF, but no overflow warning. */
757 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
759 1, /* size (0 = byte, 1 = short, 2 = long) */
761 FALSE
, /* pc_relative */
763 complain_overflow_dont
, /* complain_on_overflow */
764 ppc64_elf_sectoff_reloc
, /* special_function */
765 "R_PPC64_SECTOFF_LO", /* name */
766 FALSE
, /* partial_inplace */
768 0xffff, /* dst_mask */
769 FALSE
), /* pcrel_offset */
771 /* 16-bit upper half section relative relocation. */
772 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
774 1, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE
, /* pc_relative */
778 complain_overflow_signed
, /* complain_on_overflow */
779 ppc64_elf_sectoff_reloc
, /* special_function */
780 "R_PPC64_SECTOFF_HI", /* name */
781 FALSE
, /* partial_inplace */
783 0xffff, /* dst_mask */
784 FALSE
), /* pcrel_offset */
786 /* 16-bit upper half adjusted section relative relocation. */
787 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
789 1, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE
, /* pc_relative */
793 complain_overflow_signed
, /* complain_on_overflow */
794 ppc64_elf_sectoff_ha_reloc
, /* special_function */
795 "R_PPC64_SECTOFF_HA", /* name */
796 FALSE
, /* partial_inplace */
798 0xffff, /* dst_mask */
799 FALSE
), /* pcrel_offset */
801 /* Like R_PPC64_REL24 without touching the two least significant bits. */
802 HOWTO (R_PPC64_REL30
, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 TRUE
, /* pc_relative */
808 complain_overflow_dont
, /* complain_on_overflow */
809 bfd_elf_generic_reloc
, /* special_function */
810 "R_PPC64_REL30", /* name */
811 FALSE
, /* partial_inplace */
813 0xfffffffc, /* dst_mask */
814 TRUE
), /* pcrel_offset */
816 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
818 /* A standard 64-bit relocation. */
819 HOWTO (R_PPC64_ADDR64
, /* type */
821 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
823 FALSE
, /* pc_relative */
825 complain_overflow_dont
, /* complain_on_overflow */
826 bfd_elf_generic_reloc
, /* special_function */
827 "R_PPC64_ADDR64", /* name */
828 FALSE
, /* partial_inplace */
830 ONES (64), /* dst_mask */
831 FALSE
), /* pcrel_offset */
833 /* The bits 32-47 of an address. */
834 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
836 1, /* size (0 = byte, 1 = short, 2 = long) */
838 FALSE
, /* pc_relative */
840 complain_overflow_dont
, /* complain_on_overflow */
841 bfd_elf_generic_reloc
, /* special_function */
842 "R_PPC64_ADDR16_HIGHER", /* name */
843 FALSE
, /* partial_inplace */
845 0xffff, /* dst_mask */
846 FALSE
), /* pcrel_offset */
848 /* The bits 32-47 of an address, plus 1 if the contents of the low
849 16 bits, treated as a signed number, is negative. */
850 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
852 1, /* size (0 = byte, 1 = short, 2 = long) */
854 FALSE
, /* pc_relative */
856 complain_overflow_dont
, /* complain_on_overflow */
857 ppc64_elf_ha_reloc
, /* special_function */
858 "R_PPC64_ADDR16_HIGHERA", /* name */
859 FALSE
, /* partial_inplace */
861 0xffff, /* dst_mask */
862 FALSE
), /* pcrel_offset */
864 /* The bits 48-63 of an address. */
865 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
867 1, /* size (0 = byte, 1 = short, 2 = long) */
869 FALSE
, /* pc_relative */
871 complain_overflow_dont
, /* complain_on_overflow */
872 bfd_elf_generic_reloc
, /* special_function */
873 "R_PPC64_ADDR16_HIGHEST", /* name */
874 FALSE
, /* partial_inplace */
876 0xffff, /* dst_mask */
877 FALSE
), /* pcrel_offset */
879 /* The bits 48-63 of an address, plus 1 if the contents of the low
880 16 bits, treated as a signed number, is negative. */
881 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
883 1, /* size (0 = byte, 1 = short, 2 = long) */
885 FALSE
, /* pc_relative */
887 complain_overflow_dont
, /* complain_on_overflow */
888 ppc64_elf_ha_reloc
, /* special_function */
889 "R_PPC64_ADDR16_HIGHESTA", /* name */
890 FALSE
, /* partial_inplace */
892 0xffff, /* dst_mask */
893 FALSE
), /* pcrel_offset */
895 /* Like ADDR64, but may be unaligned. */
896 HOWTO (R_PPC64_UADDR64
, /* type */
898 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
900 FALSE
, /* pc_relative */
902 complain_overflow_dont
, /* complain_on_overflow */
903 bfd_elf_generic_reloc
, /* special_function */
904 "R_PPC64_UADDR64", /* name */
905 FALSE
, /* partial_inplace */
907 ONES (64), /* dst_mask */
908 FALSE
), /* pcrel_offset */
910 /* 64-bit relative relocation. */
911 HOWTO (R_PPC64_REL64
, /* type */
913 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
915 TRUE
, /* pc_relative */
917 complain_overflow_dont
, /* complain_on_overflow */
918 bfd_elf_generic_reloc
, /* special_function */
919 "R_PPC64_REL64", /* name */
920 FALSE
, /* partial_inplace */
922 ONES (64), /* dst_mask */
923 TRUE
), /* pcrel_offset */
925 /* 64-bit relocation to the symbol's procedure linkage table. */
926 HOWTO (R_PPC64_PLT64
, /* type */
928 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
930 FALSE
, /* pc_relative */
932 complain_overflow_dont
, /* complain_on_overflow */
933 ppc64_elf_unhandled_reloc
, /* special_function */
934 "R_PPC64_PLT64", /* name */
935 FALSE
, /* partial_inplace */
937 ONES (64), /* dst_mask */
938 FALSE
), /* pcrel_offset */
940 /* 64-bit PC relative relocation to the symbol's procedure linkage
942 /* FIXME: R_PPC64_PLTREL64 not supported. */
943 HOWTO (R_PPC64_PLTREL64
, /* type */
945 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
947 TRUE
, /* pc_relative */
949 complain_overflow_dont
, /* complain_on_overflow */
950 ppc64_elf_unhandled_reloc
, /* special_function */
951 "R_PPC64_PLTREL64", /* name */
952 FALSE
, /* partial_inplace */
954 ONES (64), /* dst_mask */
955 TRUE
), /* pcrel_offset */
957 /* 16 bit TOC-relative relocation. */
959 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
960 HOWTO (R_PPC64_TOC16
, /* type */
962 1, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_signed
, /* complain_on_overflow */
967 ppc64_elf_toc_reloc
, /* special_function */
968 "R_PPC64_TOC16", /* name */
969 FALSE
, /* partial_inplace */
971 0xffff, /* dst_mask */
972 FALSE
), /* pcrel_offset */
974 /* 16 bit TOC-relative relocation without overflow. */
976 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
977 HOWTO (R_PPC64_TOC16_LO
, /* type */
979 1, /* size (0 = byte, 1 = short, 2 = long) */
981 FALSE
, /* pc_relative */
983 complain_overflow_dont
, /* complain_on_overflow */
984 ppc64_elf_toc_reloc
, /* special_function */
985 "R_PPC64_TOC16_LO", /* name */
986 FALSE
, /* partial_inplace */
988 0xffff, /* dst_mask */
989 FALSE
), /* pcrel_offset */
991 /* 16 bit TOC-relative relocation, high 16 bits. */
993 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
994 HOWTO (R_PPC64_TOC16_HI
, /* type */
996 1, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE
, /* pc_relative */
1000 complain_overflow_signed
, /* complain_on_overflow */
1001 ppc64_elf_toc_reloc
, /* special_function */
1002 "R_PPC64_TOC16_HI", /* name */
1003 FALSE
, /* partial_inplace */
1005 0xffff, /* dst_mask */
1006 FALSE
), /* pcrel_offset */
1008 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1009 contents of the low 16 bits, treated as a signed number, is
1012 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1013 HOWTO (R_PPC64_TOC16_HA
, /* type */
1014 16, /* rightshift */
1015 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_signed
, /* complain_on_overflow */
1020 ppc64_elf_toc_ha_reloc
, /* special_function */
1021 "R_PPC64_TOC16_HA", /* name */
1022 FALSE
, /* partial_inplace */
1024 0xffff, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1029 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1030 HOWTO (R_PPC64_TOC
, /* type */
1032 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1034 FALSE
, /* pc_relative */
1036 complain_overflow_dont
, /* complain_on_overflow */
1037 ppc64_elf_toc64_reloc
, /* special_function */
1038 "R_PPC64_TOC", /* name */
1039 FALSE
, /* partial_inplace */
1041 ONES (64), /* dst_mask */
1042 FALSE
), /* pcrel_offset */
1044 /* Like R_PPC64_GOT16, but also informs the link editor that the
1045 value to relocate may (!) refer to a PLT entry which the link
1046 editor (a) may replace with the symbol value. If the link editor
1047 is unable to fully resolve the symbol, it may (b) create a PLT
1048 entry and store the address to the new PLT entry in the GOT.
1049 This permits lazy resolution of function symbols at run time.
1050 The link editor may also skip all of this and just (c) emit a
1051 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1052 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1053 HOWTO (R_PPC64_PLTGOT16
, /* type */
1055 1, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE
, /* pc_relative */
1059 complain_overflow_signed
, /* complain_on_overflow */
1060 ppc64_elf_unhandled_reloc
, /* special_function */
1061 "R_PPC64_PLTGOT16", /* name */
1062 FALSE
, /* partial_inplace */
1064 0xffff, /* dst_mask */
1065 FALSE
), /* pcrel_offset */
1067 /* Like R_PPC64_PLTGOT16, but without overflow. */
1068 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1069 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1071 1, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE
, /* pc_relative */
1075 complain_overflow_dont
, /* complain_on_overflow */
1076 ppc64_elf_unhandled_reloc
, /* special_function */
1077 "R_PPC64_PLTGOT16_LO", /* name */
1078 FALSE
, /* partial_inplace */
1080 0xffff, /* dst_mask */
1081 FALSE
), /* pcrel_offset */
1083 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1084 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1085 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1086 16, /* rightshift */
1087 1, /* size (0 = byte, 1 = short, 2 = long) */
1089 FALSE
, /* pc_relative */
1091 complain_overflow_signed
, /* complain_on_overflow */
1092 ppc64_elf_unhandled_reloc
, /* special_function */
1093 "R_PPC64_PLTGOT16_HI", /* name */
1094 FALSE
, /* partial_inplace */
1096 0xffff, /* dst_mask */
1097 FALSE
), /* pcrel_offset */
1099 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1100 1 if the contents of the low 16 bits, treated as a signed number,
1102 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1103 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1104 16, /* rightshift */
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 FALSE
, /* pc_relative */
1109 complain_overflow_signed
, /* complain_on_overflow */
1110 ppc64_elf_unhandled_reloc
, /* special_function */
1111 "R_PPC64_PLTGOT16_HA", /* name */
1112 FALSE
, /* partial_inplace */
1114 0xffff, /* dst_mask */
1115 FALSE
), /* pcrel_offset */
1117 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1118 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1120 1, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE
, /* pc_relative */
1124 complain_overflow_signed
, /* complain_on_overflow */
1125 bfd_elf_generic_reloc
, /* special_function */
1126 "R_PPC64_ADDR16_DS", /* name */
1127 FALSE
, /* partial_inplace */
1129 0xfffc, /* dst_mask */
1130 FALSE
), /* pcrel_offset */
1132 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1133 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1135 1, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE
, /* pc_relative */
1139 complain_overflow_dont
,/* complain_on_overflow */
1140 bfd_elf_generic_reloc
, /* special_function */
1141 "R_PPC64_ADDR16_LO_DS",/* name */
1142 FALSE
, /* partial_inplace */
1144 0xfffc, /* dst_mask */
1145 FALSE
), /* pcrel_offset */
1147 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1148 HOWTO (R_PPC64_GOT16_DS
, /* type */
1150 1, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_signed
, /* complain_on_overflow */
1155 ppc64_elf_unhandled_reloc
, /* special_function */
1156 "R_PPC64_GOT16_DS", /* name */
1157 FALSE
, /* partial_inplace */
1159 0xfffc, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1163 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE
, /* pc_relative */
1169 complain_overflow_dont
, /* complain_on_overflow */
1170 ppc64_elf_unhandled_reloc
, /* special_function */
1171 "R_PPC64_GOT16_LO_DS", /* name */
1172 FALSE
, /* partial_inplace */
1174 0xfffc, /* dst_mask */
1175 FALSE
), /* pcrel_offset */
1177 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1178 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1180 1, /* size (0 = byte, 1 = short, 2 = long) */
1182 FALSE
, /* pc_relative */
1184 complain_overflow_dont
, /* complain_on_overflow */
1185 ppc64_elf_unhandled_reloc
, /* special_function */
1186 "R_PPC64_PLT16_LO_DS", /* name */
1187 FALSE
, /* partial_inplace */
1189 0xfffc, /* dst_mask */
1190 FALSE
), /* pcrel_offset */
1192 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1193 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1195 1, /* size (0 = byte, 1 = short, 2 = long) */
1197 FALSE
, /* pc_relative */
1199 complain_overflow_signed
, /* complain_on_overflow */
1200 ppc64_elf_sectoff_reloc
, /* special_function */
1201 "R_PPC64_SECTOFF_DS", /* name */
1202 FALSE
, /* partial_inplace */
1204 0xfffc, /* dst_mask */
1205 FALSE
), /* pcrel_offset */
1207 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1208 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE
, /* pc_relative */
1214 complain_overflow_dont
, /* complain_on_overflow */
1215 ppc64_elf_sectoff_reloc
, /* special_function */
1216 "R_PPC64_SECTOFF_LO_DS",/* name */
1217 FALSE
, /* partial_inplace */
1219 0xfffc, /* dst_mask */
1220 FALSE
), /* pcrel_offset */
1222 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1223 HOWTO (R_PPC64_TOC16_DS
, /* type */
1225 1, /* size (0 = byte, 1 = short, 2 = long) */
1227 FALSE
, /* pc_relative */
1229 complain_overflow_signed
, /* complain_on_overflow */
1230 ppc64_elf_toc_reloc
, /* special_function */
1231 "R_PPC64_TOC16_DS", /* name */
1232 FALSE
, /* partial_inplace */
1234 0xfffc, /* dst_mask */
1235 FALSE
), /* pcrel_offset */
1237 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1238 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1240 1, /* size (0 = byte, 1 = short, 2 = long) */
1242 FALSE
, /* pc_relative */
1244 complain_overflow_dont
, /* complain_on_overflow */
1245 ppc64_elf_toc_reloc
, /* special_function */
1246 "R_PPC64_TOC16_LO_DS", /* name */
1247 FALSE
, /* partial_inplace */
1249 0xfffc, /* dst_mask */
1250 FALSE
), /* pcrel_offset */
1252 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1253 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1254 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1256 1, /* size (0 = byte, 1 = short, 2 = long) */
1258 FALSE
, /* pc_relative */
1260 complain_overflow_signed
, /* complain_on_overflow */
1261 ppc64_elf_unhandled_reloc
, /* special_function */
1262 "R_PPC64_PLTGOT16_DS", /* name */
1263 FALSE
, /* partial_inplace */
1265 0xfffc, /* dst_mask */
1266 FALSE
), /* pcrel_offset */
1268 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1269 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1270 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1272 1, /* size (0 = byte, 1 = short, 2 = long) */
1274 FALSE
, /* pc_relative */
1276 complain_overflow_dont
, /* complain_on_overflow */
1277 ppc64_elf_unhandled_reloc
, /* special_function */
1278 "R_PPC64_PLTGOT16_LO_DS",/* name */
1279 FALSE
, /* partial_inplace */
1281 0xfffc, /* dst_mask */
1282 FALSE
), /* pcrel_offset */
1284 /* Marker relocs for TLS. */
1287 2, /* size (0 = byte, 1 = short, 2 = long) */
1289 FALSE
, /* pc_relative */
1291 complain_overflow_dont
, /* complain_on_overflow */
1292 bfd_elf_generic_reloc
, /* special_function */
1293 "R_PPC64_TLS", /* name */
1294 FALSE
, /* partial_inplace */
1297 FALSE
), /* pcrel_offset */
1299 HOWTO (R_PPC64_TLSGD
,
1301 2, /* size (0 = byte, 1 = short, 2 = long) */
1303 FALSE
, /* pc_relative */
1305 complain_overflow_dont
, /* complain_on_overflow */
1306 bfd_elf_generic_reloc
, /* special_function */
1307 "R_PPC64_TLSGD", /* name */
1308 FALSE
, /* partial_inplace */
1311 FALSE
), /* pcrel_offset */
1313 HOWTO (R_PPC64_TLSLD
,
1315 2, /* size (0 = byte, 1 = short, 2 = long) */
1317 FALSE
, /* pc_relative */
1319 complain_overflow_dont
, /* complain_on_overflow */
1320 bfd_elf_generic_reloc
, /* special_function */
1321 "R_PPC64_TLSLD", /* name */
1322 FALSE
, /* partial_inplace */
1325 FALSE
), /* pcrel_offset */
1327 HOWTO (R_PPC64_TOCSAVE
,
1329 2, /* size (0 = byte, 1 = short, 2 = long) */
1331 FALSE
, /* pc_relative */
1333 complain_overflow_dont
, /* complain_on_overflow */
1334 bfd_elf_generic_reloc
, /* special_function */
1335 "R_PPC64_TOCSAVE", /* name */
1336 FALSE
, /* partial_inplace */
1339 FALSE
), /* pcrel_offset */
1341 /* Computes the load module index of the load module that contains the
1342 definition of its TLS sym. */
1343 HOWTO (R_PPC64_DTPMOD64
,
1345 4, /* size (0 = byte, 1 = short, 2 = long) */
1347 FALSE
, /* pc_relative */
1349 complain_overflow_dont
, /* complain_on_overflow */
1350 ppc64_elf_unhandled_reloc
, /* special_function */
1351 "R_PPC64_DTPMOD64", /* name */
1352 FALSE
, /* partial_inplace */
1354 ONES (64), /* dst_mask */
1355 FALSE
), /* pcrel_offset */
1357 /* Computes a dtv-relative displacement, the difference between the value
1358 of sym+add and the base address of the thread-local storage block that
1359 contains the definition of sym, minus 0x8000. */
1360 HOWTO (R_PPC64_DTPREL64
,
1362 4, /* size (0 = byte, 1 = short, 2 = long) */
1364 FALSE
, /* pc_relative */
1366 complain_overflow_dont
, /* complain_on_overflow */
1367 ppc64_elf_unhandled_reloc
, /* special_function */
1368 "R_PPC64_DTPREL64", /* name */
1369 FALSE
, /* partial_inplace */
1371 ONES (64), /* dst_mask */
1372 FALSE
), /* pcrel_offset */
1374 /* A 16 bit dtprel reloc. */
1375 HOWTO (R_PPC64_DTPREL16
,
1377 1, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE
, /* pc_relative */
1381 complain_overflow_signed
, /* complain_on_overflow */
1382 ppc64_elf_unhandled_reloc
, /* special_function */
1383 "R_PPC64_DTPREL16", /* name */
1384 FALSE
, /* partial_inplace */
1386 0xffff, /* dst_mask */
1387 FALSE
), /* pcrel_offset */
1389 /* Like DTPREL16, but no overflow. */
1390 HOWTO (R_PPC64_DTPREL16_LO
,
1392 1, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE
, /* pc_relative */
1396 complain_overflow_dont
, /* complain_on_overflow */
1397 ppc64_elf_unhandled_reloc
, /* special_function */
1398 "R_PPC64_DTPREL16_LO", /* name */
1399 FALSE
, /* partial_inplace */
1401 0xffff, /* dst_mask */
1402 FALSE
), /* pcrel_offset */
1404 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1405 HOWTO (R_PPC64_DTPREL16_HI
,
1406 16, /* rightshift */
1407 1, /* size (0 = byte, 1 = short, 2 = long) */
1409 FALSE
, /* pc_relative */
1411 complain_overflow_signed
, /* complain_on_overflow */
1412 ppc64_elf_unhandled_reloc
, /* special_function */
1413 "R_PPC64_DTPREL16_HI", /* name */
1414 FALSE
, /* partial_inplace */
1416 0xffff, /* dst_mask */
1417 FALSE
), /* pcrel_offset */
1419 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1420 HOWTO (R_PPC64_DTPREL16_HA
,
1421 16, /* rightshift */
1422 1, /* size (0 = byte, 1 = short, 2 = long) */
1424 FALSE
, /* pc_relative */
1426 complain_overflow_signed
, /* complain_on_overflow */
1427 ppc64_elf_unhandled_reloc
, /* special_function */
1428 "R_PPC64_DTPREL16_HA", /* name */
1429 FALSE
, /* partial_inplace */
1431 0xffff, /* dst_mask */
1432 FALSE
), /* pcrel_offset */
1434 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1435 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1436 32, /* rightshift */
1437 1, /* size (0 = byte, 1 = short, 2 = long) */
1439 FALSE
, /* pc_relative */
1441 complain_overflow_dont
, /* complain_on_overflow */
1442 ppc64_elf_unhandled_reloc
, /* special_function */
1443 "R_PPC64_DTPREL16_HIGHER", /* name */
1444 FALSE
, /* partial_inplace */
1446 0xffff, /* dst_mask */
1447 FALSE
), /* pcrel_offset */
1449 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1450 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1451 32, /* rightshift */
1452 1, /* size (0 = byte, 1 = short, 2 = long) */
1454 FALSE
, /* pc_relative */
1456 complain_overflow_dont
, /* complain_on_overflow */
1457 ppc64_elf_unhandled_reloc
, /* special_function */
1458 "R_PPC64_DTPREL16_HIGHERA", /* name */
1459 FALSE
, /* partial_inplace */
1461 0xffff, /* dst_mask */
1462 FALSE
), /* pcrel_offset */
1464 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1465 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1466 48, /* rightshift */
1467 1, /* size (0 = byte, 1 = short, 2 = long) */
1469 FALSE
, /* pc_relative */
1471 complain_overflow_dont
, /* complain_on_overflow */
1472 ppc64_elf_unhandled_reloc
, /* special_function */
1473 "R_PPC64_DTPREL16_HIGHEST", /* name */
1474 FALSE
, /* partial_inplace */
1476 0xffff, /* dst_mask */
1477 FALSE
), /* pcrel_offset */
1479 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1480 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1481 48, /* rightshift */
1482 1, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE
, /* pc_relative */
1486 complain_overflow_dont
, /* complain_on_overflow */
1487 ppc64_elf_unhandled_reloc
, /* special_function */
1488 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1489 FALSE
, /* partial_inplace */
1491 0xffff, /* dst_mask */
1492 FALSE
), /* pcrel_offset */
1494 /* Like DTPREL16, but for insns with a DS field. */
1495 HOWTO (R_PPC64_DTPREL16_DS
,
1497 1, /* size (0 = byte, 1 = short, 2 = long) */
1499 FALSE
, /* pc_relative */
1501 complain_overflow_signed
, /* complain_on_overflow */
1502 ppc64_elf_unhandled_reloc
, /* special_function */
1503 "R_PPC64_DTPREL16_DS", /* name */
1504 FALSE
, /* partial_inplace */
1506 0xfffc, /* dst_mask */
1507 FALSE
), /* pcrel_offset */
1509 /* Like DTPREL16_DS, but no overflow. */
1510 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1512 1, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE
, /* pc_relative */
1516 complain_overflow_dont
, /* complain_on_overflow */
1517 ppc64_elf_unhandled_reloc
, /* special_function */
1518 "R_PPC64_DTPREL16_LO_DS", /* name */
1519 FALSE
, /* partial_inplace */
1521 0xfffc, /* dst_mask */
1522 FALSE
), /* pcrel_offset */
1524 /* Computes a tp-relative displacement, the difference between the value of
1525 sym+add and the value of the thread pointer (r13). */
1526 HOWTO (R_PPC64_TPREL64
,
1528 4, /* size (0 = byte, 1 = short, 2 = long) */
1530 FALSE
, /* pc_relative */
1532 complain_overflow_dont
, /* complain_on_overflow */
1533 ppc64_elf_unhandled_reloc
, /* special_function */
1534 "R_PPC64_TPREL64", /* name */
1535 FALSE
, /* partial_inplace */
1537 ONES (64), /* dst_mask */
1538 FALSE
), /* pcrel_offset */
1540 /* A 16 bit tprel reloc. */
1541 HOWTO (R_PPC64_TPREL16
,
1543 1, /* size (0 = byte, 1 = short, 2 = long) */
1545 FALSE
, /* pc_relative */
1547 complain_overflow_signed
, /* complain_on_overflow */
1548 ppc64_elf_unhandled_reloc
, /* special_function */
1549 "R_PPC64_TPREL16", /* name */
1550 FALSE
, /* partial_inplace */
1552 0xffff, /* dst_mask */
1553 FALSE
), /* pcrel_offset */
1555 /* Like TPREL16, but no overflow. */
1556 HOWTO (R_PPC64_TPREL16_LO
,
1558 1, /* size (0 = byte, 1 = short, 2 = long) */
1560 FALSE
, /* pc_relative */
1562 complain_overflow_dont
, /* complain_on_overflow */
1563 ppc64_elf_unhandled_reloc
, /* special_function */
1564 "R_PPC64_TPREL16_LO", /* name */
1565 FALSE
, /* partial_inplace */
1567 0xffff, /* dst_mask */
1568 FALSE
), /* pcrel_offset */
1570 /* Like TPREL16_LO, but next higher group of 16 bits. */
1571 HOWTO (R_PPC64_TPREL16_HI
,
1572 16, /* rightshift */
1573 1, /* size (0 = byte, 1 = short, 2 = long) */
1575 FALSE
, /* pc_relative */
1577 complain_overflow_signed
, /* complain_on_overflow */
1578 ppc64_elf_unhandled_reloc
, /* special_function */
1579 "R_PPC64_TPREL16_HI", /* name */
1580 FALSE
, /* partial_inplace */
1582 0xffff, /* dst_mask */
1583 FALSE
), /* pcrel_offset */
1585 /* Like TPREL16_HI, but adjust for low 16 bits. */
1586 HOWTO (R_PPC64_TPREL16_HA
,
1587 16, /* rightshift */
1588 1, /* size (0 = byte, 1 = short, 2 = long) */
1590 FALSE
, /* pc_relative */
1592 complain_overflow_signed
, /* complain_on_overflow */
1593 ppc64_elf_unhandled_reloc
, /* special_function */
1594 "R_PPC64_TPREL16_HA", /* name */
1595 FALSE
, /* partial_inplace */
1597 0xffff, /* dst_mask */
1598 FALSE
), /* pcrel_offset */
1600 /* Like TPREL16_HI, but next higher group of 16 bits. */
1601 HOWTO (R_PPC64_TPREL16_HIGHER
,
1602 32, /* rightshift */
1603 1, /* size (0 = byte, 1 = short, 2 = long) */
1605 FALSE
, /* pc_relative */
1607 complain_overflow_dont
, /* complain_on_overflow */
1608 ppc64_elf_unhandled_reloc
, /* special_function */
1609 "R_PPC64_TPREL16_HIGHER", /* name */
1610 FALSE
, /* partial_inplace */
1612 0xffff, /* dst_mask */
1613 FALSE
), /* pcrel_offset */
1615 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1616 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1617 32, /* rightshift */
1618 1, /* size (0 = byte, 1 = short, 2 = long) */
1620 FALSE
, /* pc_relative */
1622 complain_overflow_dont
, /* complain_on_overflow */
1623 ppc64_elf_unhandled_reloc
, /* special_function */
1624 "R_PPC64_TPREL16_HIGHERA", /* name */
1625 FALSE
, /* partial_inplace */
1627 0xffff, /* dst_mask */
1628 FALSE
), /* pcrel_offset */
1630 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1631 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1632 48, /* rightshift */
1633 1, /* size (0 = byte, 1 = short, 2 = long) */
1635 FALSE
, /* pc_relative */
1637 complain_overflow_dont
, /* complain_on_overflow */
1638 ppc64_elf_unhandled_reloc
, /* special_function */
1639 "R_PPC64_TPREL16_HIGHEST", /* name */
1640 FALSE
, /* partial_inplace */
1642 0xffff, /* dst_mask */
1643 FALSE
), /* pcrel_offset */
1645 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1646 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1647 48, /* rightshift */
1648 1, /* size (0 = byte, 1 = short, 2 = long) */
1650 FALSE
, /* pc_relative */
1652 complain_overflow_dont
, /* complain_on_overflow */
1653 ppc64_elf_unhandled_reloc
, /* special_function */
1654 "R_PPC64_TPREL16_HIGHESTA", /* name */
1655 FALSE
, /* partial_inplace */
1657 0xffff, /* dst_mask */
1658 FALSE
), /* pcrel_offset */
1660 /* Like TPREL16, but for insns with a DS field. */
1661 HOWTO (R_PPC64_TPREL16_DS
,
1663 1, /* size (0 = byte, 1 = short, 2 = long) */
1665 FALSE
, /* pc_relative */
1667 complain_overflow_signed
, /* complain_on_overflow */
1668 ppc64_elf_unhandled_reloc
, /* special_function */
1669 "R_PPC64_TPREL16_DS", /* name */
1670 FALSE
, /* partial_inplace */
1672 0xfffc, /* dst_mask */
1673 FALSE
), /* pcrel_offset */
1675 /* Like TPREL16_DS, but no overflow. */
1676 HOWTO (R_PPC64_TPREL16_LO_DS
,
1678 1, /* size (0 = byte, 1 = short, 2 = long) */
1680 FALSE
, /* pc_relative */
1682 complain_overflow_dont
, /* complain_on_overflow */
1683 ppc64_elf_unhandled_reloc
, /* special_function */
1684 "R_PPC64_TPREL16_LO_DS", /* name */
1685 FALSE
, /* partial_inplace */
1687 0xfffc, /* dst_mask */
1688 FALSE
), /* pcrel_offset */
1690 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1691 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1692 to the first entry relative to the TOC base (r2). */
1693 HOWTO (R_PPC64_GOT_TLSGD16
,
1695 1, /* size (0 = byte, 1 = short, 2 = long) */
1697 FALSE
, /* pc_relative */
1699 complain_overflow_signed
, /* complain_on_overflow */
1700 ppc64_elf_unhandled_reloc
, /* special_function */
1701 "R_PPC64_GOT_TLSGD16", /* name */
1702 FALSE
, /* partial_inplace */
1704 0xffff, /* dst_mask */
1705 FALSE
), /* pcrel_offset */
1707 /* Like GOT_TLSGD16, but no overflow. */
1708 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1710 1, /* size (0 = byte, 1 = short, 2 = long) */
1712 FALSE
, /* pc_relative */
1714 complain_overflow_dont
, /* complain_on_overflow */
1715 ppc64_elf_unhandled_reloc
, /* special_function */
1716 "R_PPC64_GOT_TLSGD16_LO", /* name */
1717 FALSE
, /* partial_inplace */
1719 0xffff, /* dst_mask */
1720 FALSE
), /* pcrel_offset */
1722 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1723 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1724 16, /* rightshift */
1725 1, /* size (0 = byte, 1 = short, 2 = long) */
1727 FALSE
, /* pc_relative */
1729 complain_overflow_signed
, /* complain_on_overflow */
1730 ppc64_elf_unhandled_reloc
, /* special_function */
1731 "R_PPC64_GOT_TLSGD16_HI", /* name */
1732 FALSE
, /* partial_inplace */
1734 0xffff, /* dst_mask */
1735 FALSE
), /* pcrel_offset */
1737 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1738 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1739 16, /* rightshift */
1740 1, /* size (0 = byte, 1 = short, 2 = long) */
1742 FALSE
, /* pc_relative */
1744 complain_overflow_signed
, /* complain_on_overflow */
1745 ppc64_elf_unhandled_reloc
, /* special_function */
1746 "R_PPC64_GOT_TLSGD16_HA", /* name */
1747 FALSE
, /* partial_inplace */
1749 0xffff, /* dst_mask */
1750 FALSE
), /* pcrel_offset */
1752 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1753 with values (sym+add)@dtpmod and zero, and computes the offset to the
1754 first entry relative to the TOC base (r2). */
1755 HOWTO (R_PPC64_GOT_TLSLD16
,
1757 1, /* size (0 = byte, 1 = short, 2 = long) */
1759 FALSE
, /* pc_relative */
1761 complain_overflow_signed
, /* complain_on_overflow */
1762 ppc64_elf_unhandled_reloc
, /* special_function */
1763 "R_PPC64_GOT_TLSLD16", /* name */
1764 FALSE
, /* partial_inplace */
1766 0xffff, /* dst_mask */
1767 FALSE
), /* pcrel_offset */
1769 /* Like GOT_TLSLD16, but no overflow. */
1770 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1772 1, /* size (0 = byte, 1 = short, 2 = long) */
1774 FALSE
, /* pc_relative */
1776 complain_overflow_dont
, /* complain_on_overflow */
1777 ppc64_elf_unhandled_reloc
, /* special_function */
1778 "R_PPC64_GOT_TLSLD16_LO", /* name */
1779 FALSE
, /* partial_inplace */
1781 0xffff, /* dst_mask */
1782 FALSE
), /* pcrel_offset */
1784 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1785 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1786 16, /* rightshift */
1787 1, /* size (0 = byte, 1 = short, 2 = long) */
1789 FALSE
, /* pc_relative */
1791 complain_overflow_signed
, /* complain_on_overflow */
1792 ppc64_elf_unhandled_reloc
, /* special_function */
1793 "R_PPC64_GOT_TLSLD16_HI", /* name */
1794 FALSE
, /* partial_inplace */
1796 0xffff, /* dst_mask */
1797 FALSE
), /* pcrel_offset */
1799 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1800 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1801 16, /* rightshift */
1802 1, /* size (0 = byte, 1 = short, 2 = long) */
1804 FALSE
, /* pc_relative */
1806 complain_overflow_signed
, /* complain_on_overflow */
1807 ppc64_elf_unhandled_reloc
, /* special_function */
1808 "R_PPC64_GOT_TLSLD16_HA", /* name */
1809 FALSE
, /* partial_inplace */
1811 0xffff, /* dst_mask */
1812 FALSE
), /* pcrel_offset */
1814 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1815 the offset to the entry relative to the TOC base (r2). */
1816 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1818 1, /* size (0 = byte, 1 = short, 2 = long) */
1820 FALSE
, /* pc_relative */
1822 complain_overflow_signed
, /* complain_on_overflow */
1823 ppc64_elf_unhandled_reloc
, /* special_function */
1824 "R_PPC64_GOT_DTPREL16_DS", /* name */
1825 FALSE
, /* partial_inplace */
1827 0xfffc, /* dst_mask */
1828 FALSE
), /* pcrel_offset */
1830 /* Like GOT_DTPREL16_DS, but no overflow. */
1831 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1833 1, /* size (0 = byte, 1 = short, 2 = long) */
1835 FALSE
, /* pc_relative */
1837 complain_overflow_dont
, /* complain_on_overflow */
1838 ppc64_elf_unhandled_reloc
, /* special_function */
1839 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1840 FALSE
, /* partial_inplace */
1842 0xfffc, /* dst_mask */
1843 FALSE
), /* pcrel_offset */
1845 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1846 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1847 16, /* rightshift */
1848 1, /* size (0 = byte, 1 = short, 2 = long) */
1850 FALSE
, /* pc_relative */
1852 complain_overflow_signed
, /* complain_on_overflow */
1853 ppc64_elf_unhandled_reloc
, /* special_function */
1854 "R_PPC64_GOT_DTPREL16_HI", /* name */
1855 FALSE
, /* partial_inplace */
1857 0xffff, /* dst_mask */
1858 FALSE
), /* pcrel_offset */
1860 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1861 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1862 16, /* rightshift */
1863 1, /* size (0 = byte, 1 = short, 2 = long) */
1865 FALSE
, /* pc_relative */
1867 complain_overflow_signed
, /* complain_on_overflow */
1868 ppc64_elf_unhandled_reloc
, /* special_function */
1869 "R_PPC64_GOT_DTPREL16_HA", /* name */
1870 FALSE
, /* partial_inplace */
1872 0xffff, /* dst_mask */
1873 FALSE
), /* pcrel_offset */
1875 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1876 offset to the entry relative to the TOC base (r2). */
1877 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1879 1, /* size (0 = byte, 1 = short, 2 = long) */
1881 FALSE
, /* pc_relative */
1883 complain_overflow_signed
, /* complain_on_overflow */
1884 ppc64_elf_unhandled_reloc
, /* special_function */
1885 "R_PPC64_GOT_TPREL16_DS", /* name */
1886 FALSE
, /* partial_inplace */
1888 0xfffc, /* dst_mask */
1889 FALSE
), /* pcrel_offset */
1891 /* Like GOT_TPREL16_DS, but no overflow. */
1892 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1894 1, /* size (0 = byte, 1 = short, 2 = long) */
1896 FALSE
, /* pc_relative */
1898 complain_overflow_dont
, /* complain_on_overflow */
1899 ppc64_elf_unhandled_reloc
, /* special_function */
1900 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1901 FALSE
, /* partial_inplace */
1903 0xfffc, /* dst_mask */
1904 FALSE
), /* pcrel_offset */
1906 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1907 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1908 16, /* rightshift */
1909 1, /* size (0 = byte, 1 = short, 2 = long) */
1911 FALSE
, /* pc_relative */
1913 complain_overflow_signed
, /* complain_on_overflow */
1914 ppc64_elf_unhandled_reloc
, /* special_function */
1915 "R_PPC64_GOT_TPREL16_HI", /* name */
1916 FALSE
, /* partial_inplace */
1918 0xffff, /* dst_mask */
1919 FALSE
), /* pcrel_offset */
1921 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1922 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1923 16, /* rightshift */
1924 1, /* size (0 = byte, 1 = short, 2 = long) */
1926 FALSE
, /* pc_relative */
1928 complain_overflow_signed
, /* complain_on_overflow */
1929 ppc64_elf_unhandled_reloc
, /* special_function */
1930 "R_PPC64_GOT_TPREL16_HA", /* name */
1931 FALSE
, /* partial_inplace */
1933 0xffff, /* dst_mask */
1934 FALSE
), /* pcrel_offset */
1936 HOWTO (R_PPC64_JMP_IREL
, /* type */
1938 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1940 FALSE
, /* pc_relative */
1942 complain_overflow_dont
, /* complain_on_overflow */
1943 ppc64_elf_unhandled_reloc
, /* special_function */
1944 "R_PPC64_JMP_IREL", /* name */
1945 FALSE
, /* partial_inplace */
1948 FALSE
), /* pcrel_offset */
1950 HOWTO (R_PPC64_IRELATIVE
, /* type */
1952 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1954 FALSE
, /* pc_relative */
1956 complain_overflow_dont
, /* complain_on_overflow */
1957 bfd_elf_generic_reloc
, /* special_function */
1958 "R_PPC64_IRELATIVE", /* name */
1959 FALSE
, /* partial_inplace */
1961 ONES (64), /* dst_mask */
1962 FALSE
), /* pcrel_offset */
1964 /* A 16 bit relative relocation. */
1965 HOWTO (R_PPC64_REL16
, /* type */
1967 1, /* size (0 = byte, 1 = short, 2 = long) */
1969 TRUE
, /* pc_relative */
1971 complain_overflow_signed
, /* complain_on_overflow */
1972 bfd_elf_generic_reloc
, /* special_function */
1973 "R_PPC64_REL16", /* name */
1974 FALSE
, /* partial_inplace */
1976 0xffff, /* dst_mask */
1977 TRUE
), /* pcrel_offset */
1979 /* A 16 bit relative relocation without overflow. */
1980 HOWTO (R_PPC64_REL16_LO
, /* type */
1982 1, /* size (0 = byte, 1 = short, 2 = long) */
1984 TRUE
, /* pc_relative */
1986 complain_overflow_dont
,/* complain_on_overflow */
1987 bfd_elf_generic_reloc
, /* special_function */
1988 "R_PPC64_REL16_LO", /* name */
1989 FALSE
, /* partial_inplace */
1991 0xffff, /* dst_mask */
1992 TRUE
), /* pcrel_offset */
1994 /* The high order 16 bits of a relative address. */
1995 HOWTO (R_PPC64_REL16_HI
, /* type */
1996 16, /* rightshift */
1997 1, /* size (0 = byte, 1 = short, 2 = long) */
1999 TRUE
, /* pc_relative */
2001 complain_overflow_signed
, /* complain_on_overflow */
2002 bfd_elf_generic_reloc
, /* special_function */
2003 "R_PPC64_REL16_HI", /* name */
2004 FALSE
, /* partial_inplace */
2006 0xffff, /* dst_mask */
2007 TRUE
), /* pcrel_offset */
2009 /* The high order 16 bits of a relative address, plus 1 if the contents of
2010 the low 16 bits, treated as a signed number, is negative. */
2011 HOWTO (R_PPC64_REL16_HA
, /* type */
2012 16, /* rightshift */
2013 1, /* size (0 = byte, 1 = short, 2 = long) */
2015 TRUE
, /* pc_relative */
2017 complain_overflow_signed
, /* complain_on_overflow */
2018 ppc64_elf_ha_reloc
, /* special_function */
2019 "R_PPC64_REL16_HA", /* name */
2020 FALSE
, /* partial_inplace */
2022 0xffff, /* dst_mask */
2023 TRUE
), /* pcrel_offset */
2025 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2026 HOWTO (R_PPC64_ADDR16_HIGH
, /* type */
2027 16, /* rightshift */
2028 1, /* size (0 = byte, 1 = short, 2 = long) */
2030 FALSE
, /* pc_relative */
2032 complain_overflow_dont
, /* complain_on_overflow */
2033 bfd_elf_generic_reloc
, /* special_function */
2034 "R_PPC64_ADDR16_HIGH", /* name */
2035 FALSE
, /* partial_inplace */
2037 0xffff, /* dst_mask */
2038 FALSE
), /* pcrel_offset */
2040 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2041 HOWTO (R_PPC64_ADDR16_HIGHA
, /* type */
2042 16, /* rightshift */
2043 1, /* size (0 = byte, 1 = short, 2 = long) */
2045 FALSE
, /* pc_relative */
2047 complain_overflow_dont
, /* complain_on_overflow */
2048 ppc64_elf_ha_reloc
, /* special_function */
2049 "R_PPC64_ADDR16_HIGHA", /* name */
2050 FALSE
, /* partial_inplace */
2052 0xffff, /* dst_mask */
2053 FALSE
), /* pcrel_offset */
2055 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2056 HOWTO (R_PPC64_DTPREL16_HIGH
,
2057 16, /* rightshift */
2058 1, /* size (0 = byte, 1 = short, 2 = long) */
2060 FALSE
, /* pc_relative */
2062 complain_overflow_dont
, /* complain_on_overflow */
2063 ppc64_elf_unhandled_reloc
, /* special_function */
2064 "R_PPC64_DTPREL16_HIGH", /* name */
2065 FALSE
, /* partial_inplace */
2067 0xffff, /* dst_mask */
2068 FALSE
), /* pcrel_offset */
2070 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2071 HOWTO (R_PPC64_DTPREL16_HIGHA
,
2072 16, /* rightshift */
2073 1, /* size (0 = byte, 1 = short, 2 = long) */
2075 FALSE
, /* pc_relative */
2077 complain_overflow_dont
, /* complain_on_overflow */
2078 ppc64_elf_unhandled_reloc
, /* special_function */
2079 "R_PPC64_DTPREL16_HIGHA", /* name */
2080 FALSE
, /* partial_inplace */
2082 0xffff, /* dst_mask */
2083 FALSE
), /* pcrel_offset */
2085 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2086 HOWTO (R_PPC64_TPREL16_HIGH
,
2087 16, /* rightshift */
2088 1, /* size (0 = byte, 1 = short, 2 = long) */
2090 FALSE
, /* pc_relative */
2092 complain_overflow_dont
, /* complain_on_overflow */
2093 ppc64_elf_unhandled_reloc
, /* special_function */
2094 "R_PPC64_TPREL16_HIGH", /* name */
2095 FALSE
, /* partial_inplace */
2097 0xffff, /* dst_mask */
2098 FALSE
), /* pcrel_offset */
2100 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2101 HOWTO (R_PPC64_TPREL16_HIGHA
,
2102 16, /* rightshift */
2103 1, /* size (0 = byte, 1 = short, 2 = long) */
2105 FALSE
, /* pc_relative */
2107 complain_overflow_dont
, /* complain_on_overflow */
2108 ppc64_elf_unhandled_reloc
, /* special_function */
2109 "R_PPC64_TPREL16_HIGHA", /* name */
2110 FALSE
, /* partial_inplace */
2112 0xffff, /* dst_mask */
2113 FALSE
), /* pcrel_offset */
2115 /* Like ADDR64, but use local entry point of function. */
2116 HOWTO (R_PPC64_ADDR64_LOCAL
, /* type */
2118 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2120 FALSE
, /* pc_relative */
2122 complain_overflow_dont
, /* complain_on_overflow */
2123 bfd_elf_generic_reloc
, /* special_function */
2124 "R_PPC64_ADDR64_LOCAL", /* name */
2125 FALSE
, /* partial_inplace */
2127 ONES (64), /* dst_mask */
2128 FALSE
), /* pcrel_offset */
2130 /* GNU extension to record C++ vtable hierarchy. */
2131 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
2133 0, /* size (0 = byte, 1 = short, 2 = long) */
2135 FALSE
, /* pc_relative */
2137 complain_overflow_dont
, /* complain_on_overflow */
2138 NULL
, /* special_function */
2139 "R_PPC64_GNU_VTINHERIT", /* name */
2140 FALSE
, /* partial_inplace */
2143 FALSE
), /* pcrel_offset */
2145 /* GNU extension to record C++ vtable member usage. */
2146 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
2148 0, /* size (0 = byte, 1 = short, 2 = long) */
2150 FALSE
, /* pc_relative */
2152 complain_overflow_dont
, /* complain_on_overflow */
2153 NULL
, /* special_function */
2154 "R_PPC64_GNU_VTENTRY", /* name */
2155 FALSE
, /* partial_inplace */
2158 FALSE
), /* pcrel_offset */
2162 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2166 ppc_howto_init (void)
2168 unsigned int i
, type
;
2170 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2172 type
= ppc64_elf_howto_raw
[i
].type
;
2173 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
2174 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2178 static reloc_howto_type
*
2179 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2180 bfd_reloc_code_real_type code
)
2182 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2184 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2185 /* Initialize howto table if needed. */
2193 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2195 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2197 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2199 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2201 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2203 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2205 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
2207 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2209 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
2211 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2213 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2215 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2217 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2219 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2221 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2223 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2225 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2227 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2229 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2231 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2233 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2235 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2237 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2239 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2241 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2243 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2245 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2247 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2249 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2251 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2253 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2255 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2257 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2259 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2261 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2263 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2265 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2267 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2269 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2271 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2273 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2275 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2277 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2279 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2281 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2283 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2285 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2287 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2289 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2291 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2293 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2295 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2297 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2299 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2301 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2303 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2305 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2307 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2309 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2311 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2313 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2315 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2317 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2319 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2321 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2323 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2325 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2327 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2329 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
2331 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2333 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
2335 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2337 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2339 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2341 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2343 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
2345 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2347 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
2349 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2351 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2353 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2355 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2357 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2359 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2361 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2363 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2365 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2367 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2369 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2371 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2373 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2375 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2377 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2379 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2381 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2383 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2385 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2387 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2389 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2391 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2393 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2395 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2397 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2399 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2401 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2403 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2405 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2407 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2409 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2411 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2413 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2415 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
2417 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2419 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2423 return ppc64_elf_howto_table
[r
];
2426 static reloc_howto_type
*
2427 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2432 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2433 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2434 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2435 return &ppc64_elf_howto_raw
[i
];
2440 /* Set the howto pointer for a PowerPC ELF reloc. */
2443 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2444 Elf_Internal_Rela
*dst
)
2448 /* Initialize howto table if needed. */
2449 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2452 type
= ELF64_R_TYPE (dst
->r_info
);
2453 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
2455 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2457 type
= R_PPC64_NONE
;
2459 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2462 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2464 static bfd_reloc_status_type
2465 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2466 void *data
, asection
*input_section
,
2467 bfd
*output_bfd
, char **error_message
)
2469 /* If this is a relocatable link (output_bfd test tells us), just
2470 call the generic function. Any adjustment will be done at final
2472 if (output_bfd
!= NULL
)
2473 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2474 input_section
, output_bfd
, error_message
);
2476 /* Adjust the addend for sign extension of the low 16 bits.
2477 We won't actually be using the low 16 bits, so trashing them
2479 reloc_entry
->addend
+= 0x8000;
2480 return bfd_reloc_continue
;
2483 static bfd_reloc_status_type
2484 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2485 void *data
, asection
*input_section
,
2486 bfd
*output_bfd
, char **error_message
)
2488 if (output_bfd
!= NULL
)
2489 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2490 input_section
, output_bfd
, error_message
);
2492 if (strcmp (symbol
->section
->name
, ".opd") == 0
2493 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2495 bfd_vma dest
= opd_entry_value (symbol
->section
,
2496 symbol
->value
+ reloc_entry
->addend
,
2498 if (dest
!= (bfd_vma
) -1)
2499 reloc_entry
->addend
= dest
- (symbol
->value
2500 + symbol
->section
->output_section
->vma
2501 + symbol
->section
->output_offset
);
2505 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
2507 if (symbol
->section
->owner
!= abfd
2508 && abiversion (symbol
->section
->owner
) >= 2)
2512 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
2514 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
2516 if (strcmp (symdef
->name
, symbol
->name
) == 0)
2518 elfsym
= (elf_symbol_type
*) symdef
;
2524 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
2526 return bfd_reloc_continue
;
2529 static bfd_reloc_status_type
2530 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2531 void *data
, asection
*input_section
,
2532 bfd
*output_bfd
, char **error_message
)
2535 enum elf_ppc64_reloc_type r_type
;
2536 bfd_size_type octets
;
2537 /* Assume 'at' branch hints. */
2538 bfd_boolean is_isa_v2
= TRUE
;
2540 /* If this is a relocatable link (output_bfd test tells us), just
2541 call the generic function. Any adjustment will be done at final
2543 if (output_bfd
!= NULL
)
2544 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2545 input_section
, output_bfd
, error_message
);
2547 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2548 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2549 insn
&= ~(0x01 << 21);
2550 r_type
= reloc_entry
->howto
->type
;
2551 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2552 || r_type
== R_PPC64_REL14_BRTAKEN
)
2553 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2557 /* Set 'a' bit. This is 0b00010 in BO field for branch
2558 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2559 for branch on CTR insns (BO == 1a00t or 1a01t). */
2560 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2562 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2572 if (!bfd_is_com_section (symbol
->section
))
2573 target
= symbol
->value
;
2574 target
+= symbol
->section
->output_section
->vma
;
2575 target
+= symbol
->section
->output_offset
;
2576 target
+= reloc_entry
->addend
;
2578 from
= (reloc_entry
->address
2579 + input_section
->output_offset
2580 + input_section
->output_section
->vma
);
2582 /* Invert 'y' bit if not the default. */
2583 if ((bfd_signed_vma
) (target
- from
) < 0)
2586 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2588 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2589 input_section
, output_bfd
, error_message
);
2592 static bfd_reloc_status_type
2593 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2594 void *data
, asection
*input_section
,
2595 bfd
*output_bfd
, char **error_message
)
2597 /* If this is a relocatable link (output_bfd test tells us), just
2598 call the generic function. Any adjustment will be done at final
2600 if (output_bfd
!= NULL
)
2601 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2602 input_section
, output_bfd
, error_message
);
2604 /* Subtract the symbol section base address. */
2605 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2606 return bfd_reloc_continue
;
2609 static bfd_reloc_status_type
2610 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2611 void *data
, asection
*input_section
,
2612 bfd
*output_bfd
, char **error_message
)
2614 /* If this is a relocatable link (output_bfd test tells us), just
2615 call the generic function. Any adjustment will be done at final
2617 if (output_bfd
!= NULL
)
2618 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2619 input_section
, output_bfd
, error_message
);
2621 /* Subtract the symbol section base address. */
2622 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2624 /* Adjust the addend for sign extension of the low 16 bits. */
2625 reloc_entry
->addend
+= 0x8000;
2626 return bfd_reloc_continue
;
2629 static bfd_reloc_status_type
2630 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2631 void *data
, asection
*input_section
,
2632 bfd
*output_bfd
, char **error_message
)
2636 /* If this is a relocatable link (output_bfd test tells us), just
2637 call the generic function. Any adjustment will be done at final
2639 if (output_bfd
!= NULL
)
2640 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2641 input_section
, output_bfd
, error_message
);
2643 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2645 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2647 /* Subtract the TOC base address. */
2648 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2649 return bfd_reloc_continue
;
2652 static bfd_reloc_status_type
2653 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2654 void *data
, asection
*input_section
,
2655 bfd
*output_bfd
, char **error_message
)
2659 /* If this is a relocatable link (output_bfd test tells us), just
2660 call the generic function. Any adjustment will be done at final
2662 if (output_bfd
!= NULL
)
2663 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2664 input_section
, output_bfd
, error_message
);
2666 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2668 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2670 /* Subtract the TOC base address. */
2671 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2673 /* Adjust the addend for sign extension of the low 16 bits. */
2674 reloc_entry
->addend
+= 0x8000;
2675 return bfd_reloc_continue
;
2678 static bfd_reloc_status_type
2679 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2680 void *data
, asection
*input_section
,
2681 bfd
*output_bfd
, char **error_message
)
2684 bfd_size_type octets
;
2686 /* If this is a relocatable link (output_bfd test tells us), just
2687 call the generic function. Any adjustment will be done at final
2689 if (output_bfd
!= NULL
)
2690 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2691 input_section
, output_bfd
, error_message
);
2693 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2695 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2697 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2698 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2699 return bfd_reloc_ok
;
2702 static bfd_reloc_status_type
2703 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2704 void *data
, asection
*input_section
,
2705 bfd
*output_bfd
, char **error_message
)
2707 /* If this is a relocatable link (output_bfd test tells us), just
2708 call the generic function. Any adjustment will be done at final
2710 if (output_bfd
!= NULL
)
2711 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2712 input_section
, output_bfd
, error_message
);
2714 if (error_message
!= NULL
)
2716 static char buf
[60];
2717 sprintf (buf
, "generic linker can't handle %s",
2718 reloc_entry
->howto
->name
);
2719 *error_message
= buf
;
2721 return bfd_reloc_dangerous
;
2724 /* Track GOT entries needed for a given symbol. We might need more
2725 than one got entry per symbol. */
2728 struct got_entry
*next
;
2730 /* The symbol addend that we'll be placing in the GOT. */
2733 /* Unlike other ELF targets, we use separate GOT entries for the same
2734 symbol referenced from different input files. This is to support
2735 automatic multiple TOC/GOT sections, where the TOC base can vary
2736 from one input file to another. After partitioning into TOC groups
2737 we merge entries within the group.
2739 Point to the BFD owning this GOT entry. */
2742 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2743 TLS_TPREL or TLS_DTPREL for tls entries. */
2744 unsigned char tls_type
;
2746 /* Non-zero if got.ent points to real entry. */
2747 unsigned char is_indirect
;
2749 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2752 bfd_signed_vma refcount
;
2754 struct got_entry
*ent
;
2758 /* The same for PLT. */
2761 struct plt_entry
*next
;
2767 bfd_signed_vma refcount
;
2772 struct ppc64_elf_obj_tdata
2774 struct elf_obj_tdata elf
;
2776 /* Shortcuts to dynamic linker sections. */
2780 /* Used during garbage collection. We attach global symbols defined
2781 on removed .opd entries to this section so that the sym is removed. */
2782 asection
*deleted_section
;
2784 /* TLS local dynamic got entry handling. Support for multiple GOT
2785 sections means we potentially need one of these for each input bfd. */
2786 struct got_entry tlsld_got
;
2789 /* A copy of relocs before they are modified for --emit-relocs. */
2790 Elf_Internal_Rela
*relocs
;
2792 /* Section contents. */
2796 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2797 the reloc to be in the range -32768 to 32767. */
2798 unsigned int has_small_toc_reloc
: 1;
2800 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2801 instruction not one we handle. */
2802 unsigned int unexpected_toc_insn
: 1;
2805 #define ppc64_elf_tdata(bfd) \
2806 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2808 #define ppc64_tlsld_got(bfd) \
2809 (&ppc64_elf_tdata (bfd)->tlsld_got)
2811 #define is_ppc64_elf(bfd) \
2812 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2813 && elf_object_id (bfd) == PPC64_ELF_DATA)
2815 /* Override the generic function because we store some extras. */
2818 ppc64_elf_mkobject (bfd
*abfd
)
2820 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2824 /* Fix bad default arch selected for a 64 bit input bfd when the
2825 default is 32 bit. */
2828 ppc64_elf_object_p (bfd
*abfd
)
2830 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2832 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2834 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2836 /* Relies on arch after 32 bit default being 64 bit default. */
2837 abfd
->arch_info
= abfd
->arch_info
->next
;
2838 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2844 /* Support for core dump NOTE sections. */
2847 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2849 size_t offset
, size
;
2851 if (note
->descsz
!= 504)
2855 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2858 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2864 /* Make a ".reg/999" section. */
2865 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2866 size
, note
->descpos
+ offset
);
2870 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2872 if (note
->descsz
!= 136)
2875 elf_tdata (abfd
)->core
->pid
2876 = bfd_get_32 (abfd
, note
->descdata
+ 24);
2877 elf_tdata (abfd
)->core
->program
2878 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2879 elf_tdata (abfd
)->core
->command
2880 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2886 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2899 va_start (ap
, note_type
);
2900 memset (data
, 0, sizeof (data
));
2901 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2902 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2904 return elfcore_write_note (abfd
, buf
, bufsiz
,
2905 "CORE", note_type
, data
, sizeof (data
));
2916 va_start (ap
, note_type
);
2917 memset (data
, 0, 112);
2918 pid
= va_arg (ap
, long);
2919 bfd_put_32 (abfd
, pid
, data
+ 32);
2920 cursig
= va_arg (ap
, int);
2921 bfd_put_16 (abfd
, cursig
, data
+ 12);
2922 greg
= va_arg (ap
, const void *);
2923 memcpy (data
+ 112, greg
, 384);
2924 memset (data
+ 496, 0, 8);
2926 return elfcore_write_note (abfd
, buf
, bufsiz
,
2927 "CORE", note_type
, data
, sizeof (data
));
2932 /* Add extra PPC sections. */
2934 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2936 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2937 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2938 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2939 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2940 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2941 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2942 { NULL
, 0, 0, 0, 0 }
2945 enum _ppc64_sec_type
{
2951 struct _ppc64_elf_section_data
2953 struct bfd_elf_section_data elf
;
2957 /* An array with one entry for each opd function descriptor,
2958 and some spares since opd entries may be either 16 or 24 bytes. */
2959 #define OPD_NDX(OFF) ((OFF) >> 4)
2960 struct _opd_sec_data
2962 /* Points to the function code section for local opd entries. */
2963 asection
**func_sec
;
2965 /* After editing .opd, adjust references to opd local syms. */
2969 /* An array for toc sections, indexed by offset/8. */
2970 struct _toc_sec_data
2972 /* Specifies the relocation symbol index used at a given toc offset. */
2975 /* And the relocation addend. */
2980 enum _ppc64_sec_type sec_type
:2;
2982 /* Flag set when small branches are detected. Used to
2983 select suitable defaults for the stub group size. */
2984 unsigned int has_14bit_branch
:1;
2987 #define ppc64_elf_section_data(sec) \
2988 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2991 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2993 if (!sec
->used_by_bfd
)
2995 struct _ppc64_elf_section_data
*sdata
;
2996 bfd_size_type amt
= sizeof (*sdata
);
2998 sdata
= bfd_zalloc (abfd
, amt
);
3001 sec
->used_by_bfd
= sdata
;
3004 return _bfd_elf_new_section_hook (abfd
, sec
);
3007 static struct _opd_sec_data
*
3008 get_opd_info (asection
* sec
)
3011 && ppc64_elf_section_data (sec
) != NULL
3012 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
3013 return &ppc64_elf_section_data (sec
)->u
.opd
;
3017 /* Parameters for the qsort hook. */
3018 static bfd_boolean synthetic_relocatable
;
3020 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3023 compare_symbols (const void *ap
, const void *bp
)
3025 const asymbol
*a
= * (const asymbol
**) ap
;
3026 const asymbol
*b
= * (const asymbol
**) bp
;
3028 /* Section symbols first. */
3029 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
3031 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
3034 /* then .opd symbols. */
3035 if (strcmp (a
->section
->name
, ".opd") == 0
3036 && strcmp (b
->section
->name
, ".opd") != 0)
3038 if (strcmp (a
->section
->name
, ".opd") != 0
3039 && strcmp (b
->section
->name
, ".opd") == 0)
3042 /* then other code symbols. */
3043 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3044 == (SEC_CODE
| SEC_ALLOC
)
3045 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3046 != (SEC_CODE
| SEC_ALLOC
))
3049 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3050 != (SEC_CODE
| SEC_ALLOC
)
3051 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3052 == (SEC_CODE
| SEC_ALLOC
))
3055 if (synthetic_relocatable
)
3057 if (a
->section
->id
< b
->section
->id
)
3060 if (a
->section
->id
> b
->section
->id
)
3064 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
3067 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
3070 /* For syms with the same value, prefer strong dynamic global function
3071 syms over other syms. */
3072 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
3075 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
3078 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
3081 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
3084 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
3087 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
3090 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
3093 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
3099 /* Search SYMS for a symbol of the given VALUE. */
3102 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
3106 if (id
== (unsigned) -1)
3110 mid
= (lo
+ hi
) >> 1;
3111 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
3113 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
3123 mid
= (lo
+ hi
) >> 1;
3124 if (syms
[mid
]->section
->id
< id
)
3126 else if (syms
[mid
]->section
->id
> id
)
3128 else if (syms
[mid
]->value
< value
)
3130 else if (syms
[mid
]->value
> value
)
3140 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
3142 bfd_vma vma
= *(bfd_vma
*) ptr
;
3143 return ((section
->flags
& SEC_ALLOC
) != 0
3144 && section
->vma
<= vma
3145 && vma
< section
->vma
+ section
->size
);
3148 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3149 entry syms. Also generate @plt symbols for the glink branch table.
3150 Returns count of synthetic symbols in RET or -1 on error. */
3153 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
3154 long static_count
, asymbol
**static_syms
,
3155 long dyn_count
, asymbol
**dyn_syms
,
3162 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
3163 asection
*opd
= NULL
;
3164 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
3166 int abi
= abiversion (abfd
);
3172 opd
= bfd_get_section_by_name (abfd
, ".opd");
3173 if (opd
== NULL
&& abi
== 1)
3177 symcount
= static_count
;
3179 symcount
+= dyn_count
;
3183 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
3187 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
3189 /* Use both symbol tables. */
3190 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
3191 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
3193 else if (!relocatable
&& static_count
== 0)
3194 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
3196 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
3198 synthetic_relocatable
= relocatable
;
3199 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
3201 if (!relocatable
&& symcount
> 1)
3204 /* Trim duplicate syms, since we may have merged the normal and
3205 dynamic symbols. Actually, we only care about syms that have
3206 different values, so trim any with the same value. */
3207 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3208 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
3209 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
3210 syms
[j
++] = syms
[i
];
3215 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3219 for (; i
< symcount
; ++i
)
3220 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3221 != (SEC_CODE
| SEC_ALLOC
))
3222 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3226 for (; i
< symcount
; ++i
)
3227 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3231 for (; i
< symcount
; ++i
)
3232 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3236 for (; i
< symcount
; ++i
)
3237 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3238 != (SEC_CODE
| SEC_ALLOC
))
3246 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3251 if (opdsymend
== secsymend
)
3254 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3255 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3259 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3266 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3270 while (r
< opd
->relocation
+ relcount
3271 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3274 if (r
== opd
->relocation
+ relcount
)
3277 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3280 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3283 sym
= *r
->sym_ptr_ptr
;
3284 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3285 sym
->section
->id
, sym
->value
+ r
->addend
))
3288 size
+= sizeof (asymbol
);
3289 size
+= strlen (syms
[i
]->name
) + 2;
3295 s
= *ret
= bfd_malloc (size
);
3302 names
= (char *) (s
+ count
);
3304 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3308 while (r
< opd
->relocation
+ relcount
3309 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3312 if (r
== opd
->relocation
+ relcount
)
3315 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3318 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3321 sym
= *r
->sym_ptr_ptr
;
3322 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3323 sym
->section
->id
, sym
->value
+ r
->addend
))
3328 s
->flags
|= BSF_SYNTHETIC
;
3329 s
->section
= sym
->section
;
3330 s
->value
= sym
->value
+ r
->addend
;
3333 len
= strlen (syms
[i
]->name
);
3334 memcpy (names
, syms
[i
]->name
, len
+ 1);
3336 /* Have udata.p point back to the original symbol this
3337 synthetic symbol was derived from. */
3338 s
->udata
.p
= syms
[i
];
3345 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3346 bfd_byte
*contents
= NULL
;
3349 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3350 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3353 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3355 free_contents_and_exit_err
:
3357 free_contents_and_exit
:
3364 for (i
= secsymend
; i
< opdsymend
; ++i
)
3368 /* Ignore bogus symbols. */
3369 if (syms
[i
]->value
> opd
->size
- 8)
3372 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3373 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3376 size
+= sizeof (asymbol
);
3377 size
+= strlen (syms
[i
]->name
) + 2;
3381 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3383 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3385 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3387 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3389 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3390 goto free_contents_and_exit_err
;
3392 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3393 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3396 extdynend
= extdyn
+ dynamic
->size
;
3397 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3399 Elf_Internal_Dyn dyn
;
3400 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3402 if (dyn
.d_tag
== DT_NULL
)
3405 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3407 /* The first glink stub starts at offset 32; see
3408 comment in ppc64_elf_finish_dynamic_sections. */
3409 glink_vma
= dyn
.d_un
.d_val
+ GLINK_CALL_STUB_SIZE
- 8 * 4;
3410 /* The .glink section usually does not survive the final
3411 link; search for the section (usually .text) where the
3412 glink stubs now reside. */
3413 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3424 /* Determine __glink trampoline by reading the relative branch
3425 from the first glink stub. */
3427 unsigned int off
= 0;
3429 while (bfd_get_section_contents (abfd
, glink
, buf
,
3430 glink_vma
+ off
- glink
->vma
, 4))
3432 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3434 if ((insn
& ~0x3fffffc) == 0)
3436 resolv_vma
= glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
3445 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3447 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3450 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3451 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3452 goto free_contents_and_exit_err
;
3454 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3455 size
+= plt_count
* sizeof (asymbol
);
3457 p
= relplt
->relocation
;
3458 for (i
= 0; i
< plt_count
; i
++, p
++)
3460 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3462 size
+= sizeof ("+0x") - 1 + 16;
3468 goto free_contents_and_exit
;
3469 s
= *ret
= bfd_malloc (size
);
3471 goto free_contents_and_exit_err
;
3473 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3475 for (i
= secsymend
; i
< opdsymend
; ++i
)
3479 if (syms
[i
]->value
> opd
->size
- 8)
3482 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3483 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3487 asection
*sec
= abfd
->sections
;
3494 long mid
= (lo
+ hi
) >> 1;
3495 if (syms
[mid
]->section
->vma
< ent
)
3497 else if (syms
[mid
]->section
->vma
> ent
)
3501 sec
= syms
[mid
]->section
;
3506 if (lo
>= hi
&& lo
> codesecsym
)
3507 sec
= syms
[lo
- 1]->section
;
3509 for (; sec
!= NULL
; sec
= sec
->next
)
3513 /* SEC_LOAD may not be set if SEC is from a separate debug
3515 if ((sec
->flags
& SEC_ALLOC
) == 0)
3517 if ((sec
->flags
& SEC_CODE
) != 0)
3520 s
->flags
|= BSF_SYNTHETIC
;
3521 s
->value
= ent
- s
->section
->vma
;
3524 len
= strlen (syms
[i
]->name
);
3525 memcpy (names
, syms
[i
]->name
, len
+ 1);
3527 /* Have udata.p point back to the original symbol this
3528 synthetic symbol was derived from. */
3529 s
->udata
.p
= syms
[i
];
3535 if (glink
!= NULL
&& relplt
!= NULL
)
3539 /* Add a symbol for the main glink trampoline. */
3540 memset (s
, 0, sizeof *s
);
3542 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3544 s
->value
= resolv_vma
- glink
->vma
;
3546 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3547 names
+= sizeof ("__glink_PLTresolve");
3552 /* FIXME: It would be very much nicer to put sym@plt on the
3553 stub rather than on the glink branch table entry. The
3554 objdump disassembler would then use a sensible symbol
3555 name on plt calls. The difficulty in doing so is
3556 a) finding the stubs, and,
3557 b) matching stubs against plt entries, and,
3558 c) there can be multiple stubs for a given plt entry.
3560 Solving (a) could be done by code scanning, but older
3561 ppc64 binaries used different stubs to current code.
3562 (b) is the tricky one since you need to known the toc
3563 pointer for at least one function that uses a pic stub to
3564 be able to calculate the plt address referenced.
3565 (c) means gdb would need to set multiple breakpoints (or
3566 find the glink branch itself) when setting breakpoints
3567 for pending shared library loads. */
3568 p
= relplt
->relocation
;
3569 for (i
= 0; i
< plt_count
; i
++, p
++)
3573 *s
= **p
->sym_ptr_ptr
;
3574 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3575 we are defining a symbol, ensure one of them is set. */
3576 if ((s
->flags
& BSF_LOCAL
) == 0)
3577 s
->flags
|= BSF_GLOBAL
;
3578 s
->flags
|= BSF_SYNTHETIC
;
3580 s
->value
= glink_vma
- glink
->vma
;
3583 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3584 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3588 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3589 names
+= sizeof ("+0x") - 1;
3590 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3591 names
+= strlen (names
);
3593 memcpy (names
, "@plt", sizeof ("@plt"));
3594 names
+= sizeof ("@plt");
3614 /* The following functions are specific to the ELF linker, while
3615 functions above are used generally. Those named ppc64_elf_* are
3616 called by the main ELF linker code. They appear in this file more
3617 or less in the order in which they are called. eg.
3618 ppc64_elf_check_relocs is called early in the link process,
3619 ppc64_elf_finish_dynamic_sections is one of the last functions
3622 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3623 functions have both a function code symbol and a function descriptor
3624 symbol. A call to foo in a relocatable object file looks like:
3631 The function definition in another object file might be:
3635 . .quad .TOC.@tocbase
3641 When the linker resolves the call during a static link, the branch
3642 unsurprisingly just goes to .foo and the .opd information is unused.
3643 If the function definition is in a shared library, things are a little
3644 different: The call goes via a plt call stub, the opd information gets
3645 copied to the plt, and the linker patches the nop.
3653 . std 2,40(1) # in practice, the call stub
3654 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3655 . addi 11,11,Lfoo@toc@l # this is the general idea
3663 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3665 The "reloc ()" notation is supposed to indicate that the linker emits
3666 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3669 What are the difficulties here? Well, firstly, the relocations
3670 examined by the linker in check_relocs are against the function code
3671 sym .foo, while the dynamic relocation in the plt is emitted against
3672 the function descriptor symbol, foo. Somewhere along the line, we need
3673 to carefully copy dynamic link information from one symbol to the other.
3674 Secondly, the generic part of the elf linker will make .foo a dynamic
3675 symbol as is normal for most other backends. We need foo dynamic
3676 instead, at least for an application final link. However, when
3677 creating a shared library containing foo, we need to have both symbols
3678 dynamic so that references to .foo are satisfied during the early
3679 stages of linking. Otherwise the linker might decide to pull in a
3680 definition from some other object, eg. a static library.
3682 Update: As of August 2004, we support a new convention. Function
3683 calls may use the function descriptor symbol, ie. "bl foo". This
3684 behaves exactly as "bl .foo". */
3686 /* Of those relocs that might be copied as dynamic relocs, this function
3687 selects those that must be copied when linking a shared library,
3688 even when the symbol is local. */
3691 must_be_dyn_reloc (struct bfd_link_info
*info
,
3692 enum elf_ppc64_reloc_type r_type
)
3704 case R_PPC64_TPREL16
:
3705 case R_PPC64_TPREL16_LO
:
3706 case R_PPC64_TPREL16_HI
:
3707 case R_PPC64_TPREL16_HA
:
3708 case R_PPC64_TPREL16_DS
:
3709 case R_PPC64_TPREL16_LO_DS
:
3710 case R_PPC64_TPREL16_HIGH
:
3711 case R_PPC64_TPREL16_HIGHA
:
3712 case R_PPC64_TPREL16_HIGHER
:
3713 case R_PPC64_TPREL16_HIGHERA
:
3714 case R_PPC64_TPREL16_HIGHEST
:
3715 case R_PPC64_TPREL16_HIGHESTA
:
3716 case R_PPC64_TPREL64
:
3717 return !bfd_link_executable (info
);
3721 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3722 copying dynamic variables from a shared lib into an app's dynbss
3723 section, and instead use a dynamic relocation to point into the
3724 shared lib. With code that gcc generates, it's vital that this be
3725 enabled; In the PowerPC64 ABI, the address of a function is actually
3726 the address of a function descriptor, which resides in the .opd
3727 section. gcc uses the descriptor directly rather than going via the
3728 GOT as some other ABI's do, which means that initialized function
3729 pointers must reference the descriptor. Thus, a function pointer
3730 initialized to the address of a function in a shared library will
3731 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3732 redefines the function descriptor symbol to point to the copy. This
3733 presents a problem as a plt entry for that function is also
3734 initialized from the function descriptor symbol and the copy reloc
3735 may not be initialized first. */
3736 #define ELIMINATE_COPY_RELOCS 1
3738 /* Section name for stubs is the associated section name plus this
3740 #define STUB_SUFFIX ".stub"
3743 ppc_stub_long_branch:
3744 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3745 destination, but a 24 bit branch in a stub section will reach.
3748 ppc_stub_plt_branch:
3749 Similar to the above, but a 24 bit branch in the stub section won't
3750 reach its destination.
3751 . addis %r11,%r2,xxx@toc@ha
3752 . ld %r12,xxx@toc@l(%r11)
3757 Used to call a function in a shared library. If it so happens that
3758 the plt entry referenced crosses a 64k boundary, then an extra
3759 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3761 . addis %r11,%r2,xxx@toc@ha
3762 . ld %r12,xxx+0@toc@l(%r11)
3764 . ld %r2,xxx+8@toc@l(%r11)
3765 . ld %r11,xxx+16@toc@l(%r11)
3768 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3769 code to adjust the value and save r2 to support multiple toc sections.
3770 A ppc_stub_long_branch with an r2 offset looks like:
3772 . addis %r2,%r2,off@ha
3773 . addi %r2,%r2,off@l
3776 A ppc_stub_plt_branch with an r2 offset looks like:
3778 . addis %r11,%r2,xxx@toc@ha
3779 . ld %r12,xxx@toc@l(%r11)
3780 . addis %r2,%r2,off@ha
3781 . addi %r2,%r2,off@l
3785 In cases where the "addis" instruction would add zero, the "addis" is
3786 omitted and following instructions modified slightly in some cases.
3789 enum ppc_stub_type
{
3791 ppc_stub_long_branch
,
3792 ppc_stub_long_branch_r2off
,
3793 ppc_stub_plt_branch
,
3794 ppc_stub_plt_branch_r2off
,
3796 ppc_stub_plt_call_r2save
,
3797 ppc_stub_global_entry
,
3801 /* Information on stub grouping. */
3804 /* The stub section. */
3806 /* This is the section to which stubs in the group will be attached. */
3809 struct map_stub
*next
;
3810 /* Whether to emit a copy of register save/restore functions in this
3815 struct ppc_stub_hash_entry
{
3817 /* Base hash table entry structure. */
3818 struct bfd_hash_entry root
;
3820 enum ppc_stub_type stub_type
;
3822 /* Group information. */
3823 struct map_stub
*group
;
3825 /* Offset within stub_sec of the beginning of this stub. */
3826 bfd_vma stub_offset
;
3828 /* Given the symbol's value and its section we can determine its final
3829 value when building the stubs (so the stub knows where to jump. */
3830 bfd_vma target_value
;
3831 asection
*target_section
;
3833 /* The symbol table entry, if any, that this was derived from. */
3834 struct ppc_link_hash_entry
*h
;
3835 struct plt_entry
*plt_ent
;
3837 /* Symbol st_other. */
3838 unsigned char other
;
3841 struct ppc_branch_hash_entry
{
3843 /* Base hash table entry structure. */
3844 struct bfd_hash_entry root
;
3846 /* Offset within branch lookup table. */
3847 unsigned int offset
;
3849 /* Generation marker. */
3853 /* Used to track dynamic relocations for local symbols. */
3854 struct ppc_dyn_relocs
3856 struct ppc_dyn_relocs
*next
;
3858 /* The input section of the reloc. */
3861 /* Total number of relocs copied for the input section. */
3862 unsigned int count
: 31;
3864 /* Whether this entry is for STT_GNU_IFUNC symbols. */
3865 unsigned int ifunc
: 1;
3868 struct ppc_link_hash_entry
3870 struct elf_link_hash_entry elf
;
3873 /* A pointer to the most recently used stub hash entry against this
3875 struct ppc_stub_hash_entry
*stub_cache
;
3877 /* A pointer to the next symbol starting with a '.' */
3878 struct ppc_link_hash_entry
*next_dot_sym
;
3881 /* Track dynamic relocs copied for this symbol. */
3882 struct elf_dyn_relocs
*dyn_relocs
;
3884 /* Link between function code and descriptor symbols. */
3885 struct ppc_link_hash_entry
*oh
;
3887 /* Flag function code and descriptor symbols. */
3888 unsigned int is_func
:1;
3889 unsigned int is_func_descriptor
:1;
3890 unsigned int fake
:1;
3892 /* Whether global opd/toc sym has been adjusted or not.
3893 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3894 should be set for all globals defined in any opd/toc section. */
3895 unsigned int adjust_done
:1;
3897 /* Set if we twiddled this symbol to weak at some stage. */
3898 unsigned int was_undefined
:1;
3900 /* Set if this is an out-of-line register save/restore function,
3901 with non-standard calling convention. */
3902 unsigned int save_res
:1;
3904 /* Contexts in which symbol is used in the GOT (or TOC).
3905 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3906 corresponding relocs are encountered during check_relocs.
3907 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3908 indicate the corresponding GOT entry type is not needed.
3909 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3910 a TPREL one. We use a separate flag rather than setting TPREL
3911 just for convenience in distinguishing the two cases. */
3912 #define TLS_GD 1 /* GD reloc. */
3913 #define TLS_LD 2 /* LD reloc. */
3914 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3915 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3916 #define TLS_TLS 16 /* Any TLS reloc. */
3917 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3918 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3919 #define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
3920 unsigned char tls_mask
;
3923 /* ppc64 ELF linker hash table. */
3925 struct ppc_link_hash_table
3927 struct elf_link_hash_table elf
;
3929 /* The stub hash table. */
3930 struct bfd_hash_table stub_hash_table
;
3932 /* Another hash table for plt_branch stubs. */
3933 struct bfd_hash_table branch_hash_table
;
3935 /* Hash table for function prologue tocsave. */
3936 htab_t tocsave_htab
;
3938 /* Various options and other info passed from the linker. */
3939 struct ppc64_elf_params
*params
;
3941 /* The size of sec_info below. */
3942 unsigned int sec_info_arr_size
;
3944 /* Per-section array of extra section info. Done this way rather
3945 than as part of ppc64_elf_section_data so we have the info for
3946 non-ppc64 sections. */
3949 /* Along with elf_gp, specifies the TOC pointer used by this section. */
3954 /* The section group that this section belongs to. */
3955 struct map_stub
*group
;
3956 /* A temp section list pointer. */
3961 /* Linked list of groups. */
3962 struct map_stub
*group
;
3964 /* Temp used when calculating TOC pointers. */
3967 asection
*toc_first_sec
;
3969 /* Used when adding symbols. */
3970 struct ppc_link_hash_entry
*dot_syms
;
3972 /* Shortcuts to get to dynamic linker sections. */
3979 asection
*glink_eh_frame
;
3981 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3982 struct ppc_link_hash_entry
*tls_get_addr
;
3983 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3985 /* The size of reliplt used by got entry relocs. */
3986 bfd_size_type got_reli_size
;
3989 unsigned long stub_count
[ppc_stub_global_entry
];
3991 /* Number of stubs against global syms. */
3992 unsigned long stub_globals
;
3994 /* Set if we're linking code with function descriptors. */
3995 unsigned int opd_abi
:1;
3997 /* Support for multiple toc sections. */
3998 unsigned int do_multi_toc
:1;
3999 unsigned int multi_toc_needed
:1;
4000 unsigned int second_toc_pass
:1;
4001 unsigned int do_toc_opt
:1;
4004 unsigned int stub_error
:1;
4006 /* Temp used by ppc64_elf_before_check_relocs. */
4007 unsigned int twiddled_syms
:1;
4009 /* Incremented every time we size stubs. */
4010 unsigned int stub_iteration
;
4012 /* Small local sym cache. */
4013 struct sym_cache sym_cache
;
4016 /* Rename some of the generic section flags to better document how they
4019 /* Nonzero if this section has TLS related relocations. */
4020 #define has_tls_reloc sec_flg0
4022 /* Nonzero if this section has a call to __tls_get_addr. */
4023 #define has_tls_get_addr_call sec_flg1
4025 /* Nonzero if this section has any toc or got relocs. */
4026 #define has_toc_reloc sec_flg2
4028 /* Nonzero if this section has a call to another section that uses
4030 #define makes_toc_func_call sec_flg3
4032 /* Recursion protection when determining above flag. */
4033 #define call_check_in_progress sec_flg4
4034 #define call_check_done sec_flg5
4036 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4038 #define ppc_hash_table(p) \
4039 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4040 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4042 #define ppc_stub_hash_lookup(table, string, create, copy) \
4043 ((struct ppc_stub_hash_entry *) \
4044 bfd_hash_lookup ((table), (string), (create), (copy)))
4046 #define ppc_branch_hash_lookup(table, string, create, copy) \
4047 ((struct ppc_branch_hash_entry *) \
4048 bfd_hash_lookup ((table), (string), (create), (copy)))
4050 /* Create an entry in the stub hash table. */
4052 static struct bfd_hash_entry
*
4053 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
4054 struct bfd_hash_table
*table
,
4057 /* Allocate the structure if it has not already been allocated by a
4061 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
4066 /* Call the allocation method of the superclass. */
4067 entry
= bfd_hash_newfunc (entry
, table
, string
);
4070 struct ppc_stub_hash_entry
*eh
;
4072 /* Initialize the local fields. */
4073 eh
= (struct ppc_stub_hash_entry
*) entry
;
4074 eh
->stub_type
= ppc_stub_none
;
4076 eh
->stub_offset
= 0;
4077 eh
->target_value
= 0;
4078 eh
->target_section
= NULL
;
4087 /* Create an entry in the branch hash table. */
4089 static struct bfd_hash_entry
*
4090 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
4091 struct bfd_hash_table
*table
,
4094 /* Allocate the structure if it has not already been allocated by a
4098 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
4103 /* Call the allocation method of the superclass. */
4104 entry
= bfd_hash_newfunc (entry
, table
, string
);
4107 struct ppc_branch_hash_entry
*eh
;
4109 /* Initialize the local fields. */
4110 eh
= (struct ppc_branch_hash_entry
*) entry
;
4118 /* Create an entry in a ppc64 ELF linker hash table. */
4120 static struct bfd_hash_entry
*
4121 link_hash_newfunc (struct bfd_hash_entry
*entry
,
4122 struct bfd_hash_table
*table
,
4125 /* Allocate the structure if it has not already been allocated by a
4129 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
4134 /* Call the allocation method of the superclass. */
4135 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
4138 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
4140 memset (&eh
->u
.stub_cache
, 0,
4141 (sizeof (struct ppc_link_hash_entry
)
4142 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
4144 /* When making function calls, old ABI code references function entry
4145 points (dot symbols), while new ABI code references the function
4146 descriptor symbol. We need to make any combination of reference and
4147 definition work together, without breaking archive linking.
4149 For a defined function "foo" and an undefined call to "bar":
4150 An old object defines "foo" and ".foo", references ".bar" (possibly
4152 A new object defines "foo" and references "bar".
4154 A new object thus has no problem with its undefined symbols being
4155 satisfied by definitions in an old object. On the other hand, the
4156 old object won't have ".bar" satisfied by a new object.
4158 Keep a list of newly added dot-symbols. */
4160 if (string
[0] == '.')
4162 struct ppc_link_hash_table
*htab
;
4164 htab
= (struct ppc_link_hash_table
*) table
;
4165 eh
->u
.next_dot_sym
= htab
->dot_syms
;
4166 htab
->dot_syms
= eh
;
4173 struct tocsave_entry
{
4179 tocsave_htab_hash (const void *p
)
4181 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
4182 return ((bfd_vma
)(intptr_t) e
->sec
^ e
->offset
) >> 3;
4186 tocsave_htab_eq (const void *p1
, const void *p2
)
4188 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
4189 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
4190 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
4193 /* Destroy a ppc64 ELF linker hash table. */
4196 ppc64_elf_link_hash_table_free (bfd
*obfd
)
4198 struct ppc_link_hash_table
*htab
;
4200 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
4201 if (htab
->tocsave_htab
)
4202 htab_delete (htab
->tocsave_htab
);
4203 bfd_hash_table_free (&htab
->branch_hash_table
);
4204 bfd_hash_table_free (&htab
->stub_hash_table
);
4205 _bfd_elf_link_hash_table_free (obfd
);
4208 /* Create a ppc64 ELF linker hash table. */
4210 static struct bfd_link_hash_table
*
4211 ppc64_elf_link_hash_table_create (bfd
*abfd
)
4213 struct ppc_link_hash_table
*htab
;
4214 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
4216 htab
= bfd_zmalloc (amt
);
4220 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
4221 sizeof (struct ppc_link_hash_entry
),
4228 /* Init the stub hash table too. */
4229 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
4230 sizeof (struct ppc_stub_hash_entry
)))
4232 _bfd_elf_link_hash_table_free (abfd
);
4236 /* And the branch hash table. */
4237 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
4238 sizeof (struct ppc_branch_hash_entry
)))
4240 bfd_hash_table_free (&htab
->stub_hash_table
);
4241 _bfd_elf_link_hash_table_free (abfd
);
4245 htab
->tocsave_htab
= htab_try_create (1024,
4249 if (htab
->tocsave_htab
== NULL
)
4251 ppc64_elf_link_hash_table_free (abfd
);
4254 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
4256 /* Initializing two fields of the union is just cosmetic. We really
4257 only care about glist, but when compiled on a 32-bit host the
4258 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4259 debugger inspection of these fields look nicer. */
4260 htab
->elf
.init_got_refcount
.refcount
= 0;
4261 htab
->elf
.init_got_refcount
.glist
= NULL
;
4262 htab
->elf
.init_plt_refcount
.refcount
= 0;
4263 htab
->elf
.init_plt_refcount
.glist
= NULL
;
4264 htab
->elf
.init_got_offset
.offset
= 0;
4265 htab
->elf
.init_got_offset
.glist
= NULL
;
4266 htab
->elf
.init_plt_offset
.offset
= 0;
4267 htab
->elf
.init_plt_offset
.glist
= NULL
;
4269 return &htab
->elf
.root
;
4272 /* Create sections for linker generated code. */
4275 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4277 struct ppc_link_hash_table
*htab
;
4280 htab
= ppc_hash_table (info
);
4282 /* Create .sfpr for code to save and restore fp regs. */
4283 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4284 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4285 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4287 if (htab
->sfpr
== NULL
4288 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4291 /* Create .glink for lazy dynamic linking support. */
4292 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4294 if (htab
->glink
== NULL
4295 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4298 if (!info
->no_ld_generated_unwind_info
)
4300 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4301 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4302 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4305 if (htab
->glink_eh_frame
== NULL
4306 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
4310 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4311 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4312 if (htab
->elf
.iplt
== NULL
4313 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
4316 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4317 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4319 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
4320 if (htab
->elf
.irelplt
== NULL
4321 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
4324 /* Create branch lookup table for plt_branch stubs. */
4325 flags
= (SEC_ALLOC
| SEC_LOAD
4326 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4327 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4329 if (htab
->brlt
== NULL
4330 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4333 if (!bfd_link_pic (info
))
4336 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4337 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4338 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
4341 if (htab
->relbrlt
== NULL
4342 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4348 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4351 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
4352 struct ppc64_elf_params
*params
)
4354 struct ppc_link_hash_table
*htab
;
4356 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
4358 /* Always hook our dynamic sections into the first bfd, which is the
4359 linker created stub bfd. This ensures that the GOT header is at
4360 the start of the output TOC section. */
4361 htab
= ppc_hash_table (info
);
4364 htab
->elf
.dynobj
= params
->stub_bfd
;
4365 htab
->params
= params
;
4367 if (bfd_link_relocatable (info
))
4370 return create_linkage_sections (htab
->elf
.dynobj
, info
);
4373 /* Build a name for an entry in the stub hash table. */
4376 ppc_stub_name (const asection
*input_section
,
4377 const asection
*sym_sec
,
4378 const struct ppc_link_hash_entry
*h
,
4379 const Elf_Internal_Rela
*rel
)
4384 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4385 offsets from a sym as a branch target? In fact, we could
4386 probably assume the addend is always zero. */
4387 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4391 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4392 stub_name
= bfd_malloc (len
);
4393 if (stub_name
== NULL
)
4396 len
= sprintf (stub_name
, "%08x.%s+%x",
4397 input_section
->id
& 0xffffffff,
4398 h
->elf
.root
.root
.string
,
4399 (int) rel
->r_addend
& 0xffffffff);
4403 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4404 stub_name
= bfd_malloc (len
);
4405 if (stub_name
== NULL
)
4408 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
4409 input_section
->id
& 0xffffffff,
4410 sym_sec
->id
& 0xffffffff,
4411 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4412 (int) rel
->r_addend
& 0xffffffff);
4414 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4415 stub_name
[len
- 2] = 0;
4419 /* Look up an entry in the stub hash. Stub entries are cached because
4420 creating the stub name takes a bit of time. */
4422 static struct ppc_stub_hash_entry
*
4423 ppc_get_stub_entry (const asection
*input_section
,
4424 const asection
*sym_sec
,
4425 struct ppc_link_hash_entry
*h
,
4426 const Elf_Internal_Rela
*rel
,
4427 struct ppc_link_hash_table
*htab
)
4429 struct ppc_stub_hash_entry
*stub_entry
;
4430 struct map_stub
*group
;
4432 /* If this input section is part of a group of sections sharing one
4433 stub section, then use the id of the first section in the group.
4434 Stub names need to include a section id, as there may well be
4435 more than one stub used to reach say, printf, and we need to
4436 distinguish between them. */
4437 group
= htab
->sec_info
[input_section
->id
].u
.group
;
4439 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4440 && h
->u
.stub_cache
->h
== h
4441 && h
->u
.stub_cache
->group
== group
)
4443 stub_entry
= h
->u
.stub_cache
;
4449 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
4450 if (stub_name
== NULL
)
4453 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4454 stub_name
, FALSE
, FALSE
);
4456 h
->u
.stub_cache
= stub_entry
;
4464 /* Add a new stub entry to the stub hash. Not all fields of the new
4465 stub entry are initialised. */
4467 static struct ppc_stub_hash_entry
*
4468 ppc_add_stub (const char *stub_name
,
4470 struct bfd_link_info
*info
)
4472 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4473 struct map_stub
*group
;
4476 struct ppc_stub_hash_entry
*stub_entry
;
4478 group
= htab
->sec_info
[section
->id
].u
.group
;
4479 link_sec
= group
->link_sec
;
4480 stub_sec
= group
->stub_sec
;
4481 if (stub_sec
== NULL
)
4487 namelen
= strlen (link_sec
->name
);
4488 len
= namelen
+ sizeof (STUB_SUFFIX
);
4489 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
4493 memcpy (s_name
, link_sec
->name
, namelen
);
4494 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4495 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
4496 if (stub_sec
== NULL
)
4498 group
->stub_sec
= stub_sec
;
4501 /* Enter this entry into the linker stub hash table. */
4502 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4504 if (stub_entry
== NULL
)
4506 info
->callbacks
->einfo (_("%P: %B: cannot create stub entry %s\n"),
4507 section
->owner
, stub_name
);
4511 stub_entry
->group
= group
;
4512 stub_entry
->stub_offset
= 0;
4516 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4517 not already done. */
4520 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4522 asection
*got
, *relgot
;
4524 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4526 if (!is_ppc64_elf (abfd
))
4532 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4535 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4536 | SEC_LINKER_CREATED
);
4538 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4540 || !bfd_set_section_alignment (abfd
, got
, 3))
4543 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4544 flags
| SEC_READONLY
);
4546 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4549 ppc64_elf_tdata (abfd
)->got
= got
;
4550 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4554 /* Create the dynamic sections, and set up shortcuts. */
4557 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4559 struct ppc_link_hash_table
*htab
;
4561 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
4564 htab
= ppc_hash_table (info
);
4568 htab
->dynbss
= bfd_get_linker_section (dynobj
, ".dynbss");
4569 if (!bfd_link_pic (info
))
4570 htab
->relbss
= bfd_get_linker_section (dynobj
, ".rela.bss");
4572 if (!htab
->elf
.sgot
|| !htab
->elf
.splt
|| !htab
->elf
.srelplt
|| !htab
->dynbss
4573 || (!bfd_link_pic (info
) && !htab
->relbss
))
4579 /* Follow indirect and warning symbol links. */
4581 static inline struct bfd_link_hash_entry
*
4582 follow_link (struct bfd_link_hash_entry
*h
)
4584 while (h
->type
== bfd_link_hash_indirect
4585 || h
->type
== bfd_link_hash_warning
)
4590 static inline struct elf_link_hash_entry
*
4591 elf_follow_link (struct elf_link_hash_entry
*h
)
4593 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4596 static inline struct ppc_link_hash_entry
*
4597 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4599 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4602 /* Merge PLT info on FROM with that on TO. */
4605 move_plt_plist (struct ppc_link_hash_entry
*from
,
4606 struct ppc_link_hash_entry
*to
)
4608 if (from
->elf
.plt
.plist
!= NULL
)
4610 if (to
->elf
.plt
.plist
!= NULL
)
4612 struct plt_entry
**entp
;
4613 struct plt_entry
*ent
;
4615 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4617 struct plt_entry
*dent
;
4619 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4620 if (dent
->addend
== ent
->addend
)
4622 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4629 *entp
= to
->elf
.plt
.plist
;
4632 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4633 from
->elf
.plt
.plist
= NULL
;
4637 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4640 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4641 struct elf_link_hash_entry
*dir
,
4642 struct elf_link_hash_entry
*ind
)
4644 struct ppc_link_hash_entry
*edir
, *eind
;
4646 edir
= (struct ppc_link_hash_entry
*) dir
;
4647 eind
= (struct ppc_link_hash_entry
*) ind
;
4649 edir
->is_func
|= eind
->is_func
;
4650 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4651 edir
->tls_mask
|= eind
->tls_mask
;
4652 if (eind
->oh
!= NULL
)
4653 edir
->oh
= ppc_follow_link (eind
->oh
);
4655 /* If called to transfer flags for a weakdef during processing
4656 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4657 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4658 if (!(ELIMINATE_COPY_RELOCS
4659 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4660 && edir
->elf
.dynamic_adjusted
))
4661 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4663 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4664 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4665 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4666 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4667 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4669 /* Copy over any dynamic relocs we may have on the indirect sym. */
4670 if (eind
->dyn_relocs
!= NULL
)
4672 if (edir
->dyn_relocs
!= NULL
)
4674 struct elf_dyn_relocs
**pp
;
4675 struct elf_dyn_relocs
*p
;
4677 /* Add reloc counts against the indirect sym to the direct sym
4678 list. Merge any entries against the same section. */
4679 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4681 struct elf_dyn_relocs
*q
;
4683 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4684 if (q
->sec
== p
->sec
)
4686 q
->pc_count
+= p
->pc_count
;
4687 q
->count
+= p
->count
;
4694 *pp
= edir
->dyn_relocs
;
4697 edir
->dyn_relocs
= eind
->dyn_relocs
;
4698 eind
->dyn_relocs
= NULL
;
4701 /* If we were called to copy over info for a weak sym, that's all.
4702 You might think dyn_relocs need not be copied over; After all,
4703 both syms will be dynamic or both non-dynamic so we're just
4704 moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
4705 code in ppc64_elf_adjust_dynamic_symbol needs to check for
4706 dyn_relocs in read-only sections, and it does so on what is the
4708 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4711 /* Copy over got entries that we may have already seen to the
4712 symbol which just became indirect. */
4713 if (eind
->elf
.got
.glist
!= NULL
)
4715 if (edir
->elf
.got
.glist
!= NULL
)
4717 struct got_entry
**entp
;
4718 struct got_entry
*ent
;
4720 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4722 struct got_entry
*dent
;
4724 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4725 if (dent
->addend
== ent
->addend
4726 && dent
->owner
== ent
->owner
4727 && dent
->tls_type
== ent
->tls_type
)
4729 dent
->got
.refcount
+= ent
->got
.refcount
;
4736 *entp
= edir
->elf
.got
.glist
;
4739 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4740 eind
->elf
.got
.glist
= NULL
;
4743 /* And plt entries. */
4744 move_plt_plist (eind
, edir
);
4746 if (eind
->elf
.dynindx
!= -1)
4748 if (edir
->elf
.dynindx
!= -1)
4749 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4750 edir
->elf
.dynstr_index
);
4751 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4752 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4753 eind
->elf
.dynindx
= -1;
4754 eind
->elf
.dynstr_index
= 0;
4758 /* Find the function descriptor hash entry from the given function code
4759 hash entry FH. Link the entries via their OH fields. */
4761 static struct ppc_link_hash_entry
*
4762 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4764 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4768 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4770 fdh
= (struct ppc_link_hash_entry
*)
4771 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4775 fdh
->is_func_descriptor
= 1;
4781 return ppc_follow_link (fdh
);
4784 /* Make a fake function descriptor sym for the code sym FH. */
4786 static struct ppc_link_hash_entry
*
4787 make_fdh (struct bfd_link_info
*info
,
4788 struct ppc_link_hash_entry
*fh
)
4792 struct bfd_link_hash_entry
*bh
;
4793 struct ppc_link_hash_entry
*fdh
;
4795 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4796 newsym
= bfd_make_empty_symbol (abfd
);
4797 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4798 newsym
->section
= bfd_und_section_ptr
;
4800 newsym
->flags
= BSF_WEAK
;
4803 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4804 newsym
->flags
, newsym
->section
,
4805 newsym
->value
, NULL
, FALSE
, FALSE
,
4809 fdh
= (struct ppc_link_hash_entry
*) bh
;
4810 fdh
->elf
.non_elf
= 0;
4812 fdh
->is_func_descriptor
= 1;
4819 /* Fix function descriptor symbols defined in .opd sections to be
4823 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
4824 struct bfd_link_info
*info
,
4825 Elf_Internal_Sym
*isym
,
4827 flagword
*flags ATTRIBUTE_UNUSED
,
4831 if ((ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4832 || ELF_ST_BIND (isym
->st_info
) == STB_GNU_UNIQUE
)
4833 && (ibfd
->flags
& DYNAMIC
) == 0
4834 && bfd_get_flavour (info
->output_bfd
) == bfd_target_elf_flavour
)
4835 elf_tdata (info
->output_bfd
)->has_gnu_symbols
= elf_gnu_symbol_any
;
4838 && strcmp ((*sec
)->name
, ".opd") == 0)
4842 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
4843 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
4844 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4846 /* If the symbol is a function defined in .opd, and the function
4847 code is in a discarded group, let it appear to be undefined. */
4848 if (!bfd_link_relocatable (info
)
4849 && (*sec
)->reloc_count
!= 0
4850 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
4851 FALSE
) != (bfd_vma
) -1
4852 && discarded_section (code_sec
))
4854 *sec
= bfd_und_section_ptr
;
4855 isym
->st_shndx
= SHN_UNDEF
;
4858 else if (*sec
!= NULL
4859 && strcmp ((*sec
)->name
, ".toc") == 0
4860 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
4862 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4864 htab
->params
->object_in_toc
= 1;
4867 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
4869 if (abiversion (ibfd
) == 0)
4870 set_abiversion (ibfd
, 2);
4871 else if (abiversion (ibfd
) == 1)
4873 info
->callbacks
->einfo (_("%P: symbol '%s' has invalid st_other"
4874 " for ABI version 1\n"), name
);
4875 bfd_set_error (bfd_error_bad_value
);
4883 /* Merge non-visibility st_other attributes: local entry point. */
4886 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
4887 const Elf_Internal_Sym
*isym
,
4888 bfd_boolean definition
,
4889 bfd_boolean dynamic
)
4891 if (definition
&& !dynamic
)
4892 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
4893 | ELF_ST_VISIBILITY (h
->other
));
4896 /* This function makes an old ABI object reference to ".bar" cause the
4897 inclusion of a new ABI object archive that defines "bar".
4898 NAME is a symbol defined in an archive. Return a symbol in the hash
4899 table that might be satisfied by the archive symbols. */
4901 static struct elf_link_hash_entry
*
4902 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4903 struct bfd_link_info
*info
,
4906 struct elf_link_hash_entry
*h
;
4910 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4912 /* Don't return this sym if it is a fake function descriptor
4913 created by add_symbol_adjust. */
4914 && !(h
->root
.type
== bfd_link_hash_undefweak
4915 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4921 len
= strlen (name
);
4922 dot_name
= bfd_alloc (abfd
, len
+ 2);
4923 if (dot_name
== NULL
)
4924 return (struct elf_link_hash_entry
*) 0 - 1;
4926 memcpy (dot_name
+ 1, name
, len
+ 1);
4927 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4928 bfd_release (abfd
, dot_name
);
4932 /* This function satisfies all old ABI object references to ".bar" if a
4933 new ABI object defines "bar". Well, at least, undefined dot symbols
4934 are made weak. This stops later archive searches from including an
4935 object if we already have a function descriptor definition. It also
4936 prevents the linker complaining about undefined symbols.
4937 We also check and correct mismatched symbol visibility here. The
4938 most restrictive visibility of the function descriptor and the
4939 function entry symbol is used. */
4942 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4944 struct ppc_link_hash_table
*htab
;
4945 struct ppc_link_hash_entry
*fdh
;
4947 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4950 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4951 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4953 if (eh
->elf
.root
.root
.string
[0] != '.')
4956 htab
= ppc_hash_table (info
);
4960 fdh
= lookup_fdh (eh
, htab
);
4963 if (!bfd_link_relocatable (info
)
4964 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4965 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4966 && eh
->elf
.ref_regular
)
4968 /* Make an undefweak function descriptor sym, which is enough to
4969 pull in an --as-needed shared lib, but won't cause link
4970 errors. Archives are handled elsewhere. */
4971 fdh
= make_fdh (info
, eh
);
4974 fdh
->elf
.ref_regular
= 1;
4979 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4980 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4981 if (entry_vis
< descr_vis
)
4982 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4983 else if (entry_vis
> descr_vis
)
4984 eh
->elf
.other
+= descr_vis
- entry_vis
;
4986 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4987 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4988 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4990 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4991 eh
->was_undefined
= 1;
4992 htab
->twiddled_syms
= 1;
4999 /* Set up opd section info and abiversion for IBFD, and process list
5000 of dot-symbols we made in link_hash_newfunc. */
5003 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
5005 struct ppc_link_hash_table
*htab
;
5006 struct ppc_link_hash_entry
**p
, *eh
;
5007 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
5009 if (opd
!= NULL
&& opd
->size
!= 0)
5011 if (abiversion (ibfd
) == 0)
5012 set_abiversion (ibfd
, 1);
5013 else if (abiversion (ibfd
) == 2)
5015 info
->callbacks
->einfo (_("%P: %B .opd not allowed in ABI"
5017 ibfd
, abiversion (ibfd
));
5018 bfd_set_error (bfd_error_bad_value
);
5022 if ((ibfd
->flags
& DYNAMIC
) == 0
5023 && (opd
->flags
& SEC_RELOC
) != 0
5024 && opd
->reloc_count
!= 0
5025 && !bfd_is_abs_section (opd
->output_section
))
5027 /* Garbage collection needs some extra help with .opd sections.
5028 We don't want to necessarily keep everything referenced by
5029 relocs in .opd, as that would keep all functions. Instead,
5030 if we reference an .opd symbol (a function descriptor), we
5031 want to keep the function code symbol's section. This is
5032 easy for global symbols, but for local syms we need to keep
5033 information about the associated function section. */
5035 asection
**opd_sym_map
;
5037 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
5038 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
5039 if (opd_sym_map
== NULL
)
5041 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
5042 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
5043 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
5047 if (!is_ppc64_elf (info
->output_bfd
))
5049 htab
= ppc_hash_table (info
);
5053 /* For input files without an explicit abiversion in e_flags
5054 we should have flagged any with symbol st_other bits set
5055 as ELFv1 and above flagged those with .opd as ELFv2.
5056 Set the output abiversion if not yet set, and for any input
5057 still ambiguous, take its abiversion from the output.
5058 Differences in ABI are reported later. */
5059 if (abiversion (info
->output_bfd
) == 0)
5060 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
5061 else if (abiversion (ibfd
) == 0)
5062 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
5064 p
= &htab
->dot_syms
;
5065 while ((eh
= *p
) != NULL
)
5068 if (&eh
->elf
== htab
->elf
.hgot
)
5070 else if (htab
->elf
.hgot
== NULL
5071 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
5072 htab
->elf
.hgot
= &eh
->elf
;
5073 else if (!add_symbol_adjust (eh
, info
))
5075 p
= &eh
->u
.next_dot_sym
;
5078 /* Clear the list for non-ppc64 input files. */
5079 p
= &htab
->dot_syms
;
5080 while ((eh
= *p
) != NULL
)
5083 p
= &eh
->u
.next_dot_sym
;
5086 /* We need to fix the undefs list for any syms we have twiddled to
5088 if (htab
->twiddled_syms
)
5090 bfd_link_repair_undef_list (&htab
->elf
.root
);
5091 htab
->twiddled_syms
= 0;
5096 /* Undo hash table changes when an --as-needed input file is determined
5097 not to be needed. */
5100 ppc64_elf_notice_as_needed (bfd
*ibfd
,
5101 struct bfd_link_info
*info
,
5102 enum notice_asneeded_action act
)
5104 if (act
== notice_not_needed
)
5106 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5111 htab
->dot_syms
= NULL
;
5113 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
5116 /* If --just-symbols against a final linked binary, then assume we need
5117 toc adjusting stubs when calling functions defined there. */
5120 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
5122 if ((sec
->flags
& SEC_CODE
) != 0
5123 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
5124 && is_ppc64_elf (sec
->owner
))
5126 if (abiversion (sec
->owner
) >= 2
5127 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
5128 sec
->has_toc_reloc
= 1;
5130 _bfd_elf_link_just_syms (sec
, info
);
5133 static struct plt_entry
**
5134 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
5135 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
5137 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
5138 struct plt_entry
**local_plt
;
5139 unsigned char *local_got_tls_masks
;
5141 if (local_got_ents
== NULL
)
5143 bfd_size_type size
= symtab_hdr
->sh_info
;
5145 size
*= (sizeof (*local_got_ents
)
5146 + sizeof (*local_plt
)
5147 + sizeof (*local_got_tls_masks
));
5148 local_got_ents
= bfd_zalloc (abfd
, size
);
5149 if (local_got_ents
== NULL
)
5151 elf_local_got_ents (abfd
) = local_got_ents
;
5154 if ((tls_type
& (PLT_IFUNC
| TLS_EXPLICIT
)) == 0)
5156 struct got_entry
*ent
;
5158 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
5159 if (ent
->addend
== r_addend
5160 && ent
->owner
== abfd
5161 && ent
->tls_type
== tls_type
)
5165 bfd_size_type amt
= sizeof (*ent
);
5166 ent
= bfd_alloc (abfd
, amt
);
5169 ent
->next
= local_got_ents
[r_symndx
];
5170 ent
->addend
= r_addend
;
5172 ent
->tls_type
= tls_type
;
5173 ent
->is_indirect
= FALSE
;
5174 ent
->got
.refcount
= 0;
5175 local_got_ents
[r_symndx
] = ent
;
5177 ent
->got
.refcount
+= 1;
5180 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
5181 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
5182 local_got_tls_masks
[r_symndx
] |= tls_type
;
5184 return local_plt
+ r_symndx
;
5188 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
5190 struct plt_entry
*ent
;
5192 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
5193 if (ent
->addend
== addend
)
5197 bfd_size_type amt
= sizeof (*ent
);
5198 ent
= bfd_alloc (abfd
, amt
);
5202 ent
->addend
= addend
;
5203 ent
->plt
.refcount
= 0;
5206 ent
->plt
.refcount
+= 1;
5211 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
5213 return (r_type
== R_PPC64_REL24
5214 || r_type
== R_PPC64_REL14
5215 || r_type
== R_PPC64_REL14_BRTAKEN
5216 || r_type
== R_PPC64_REL14_BRNTAKEN
5217 || r_type
== R_PPC64_ADDR24
5218 || r_type
== R_PPC64_ADDR14
5219 || r_type
== R_PPC64_ADDR14_BRTAKEN
5220 || r_type
== R_PPC64_ADDR14_BRNTAKEN
);
5223 /* Look through the relocs for a section during the first phase, and
5224 calculate needed space in the global offset table, procedure
5225 linkage table, and dynamic reloc sections. */
5228 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5229 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5231 struct ppc_link_hash_table
*htab
;
5232 Elf_Internal_Shdr
*symtab_hdr
;
5233 struct elf_link_hash_entry
**sym_hashes
;
5234 const Elf_Internal_Rela
*rel
;
5235 const Elf_Internal_Rela
*rel_end
;
5237 asection
**opd_sym_map
;
5238 struct elf_link_hash_entry
*tga
, *dottga
;
5240 if (bfd_link_relocatable (info
))
5243 /* Don't do anything special with non-loaded, non-alloced sections.
5244 In particular, any relocs in such sections should not affect GOT
5245 and PLT reference counting (ie. we don't allow them to create GOT
5246 or PLT entries), there's no possibility or desire to optimize TLS
5247 relocs, and there's not much point in propagating relocs to shared
5248 libs that the dynamic linker won't relocate. */
5249 if ((sec
->flags
& SEC_ALLOC
) == 0)
5252 BFD_ASSERT (is_ppc64_elf (abfd
));
5254 htab
= ppc_hash_table (info
);
5258 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
5259 FALSE
, FALSE
, TRUE
);
5260 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
5261 FALSE
, FALSE
, TRUE
);
5262 symtab_hdr
= &elf_symtab_hdr (abfd
);
5263 sym_hashes
= elf_sym_hashes (abfd
);
5266 if (ppc64_elf_section_data (sec
) != NULL
5267 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
5268 opd_sym_map
= ppc64_elf_section_data (sec
)->u
.opd
.func_sec
;
5270 rel_end
= relocs
+ sec
->reloc_count
;
5271 for (rel
= relocs
; rel
< rel_end
; rel
++)
5273 unsigned long r_symndx
;
5274 struct elf_link_hash_entry
*h
;
5275 enum elf_ppc64_reloc_type r_type
;
5277 struct _ppc64_elf_section_data
*ppc64_sec
;
5278 struct plt_entry
**ifunc
;
5280 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5281 if (r_symndx
< symtab_hdr
->sh_info
)
5285 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5286 h
= elf_follow_link (h
);
5288 /* PR15323, ref flags aren't set for references in the same
5290 h
->root
.non_ir_ref
= 1;
5292 if (h
== htab
->elf
.hgot
)
5293 sec
->has_toc_reloc
= 1;
5300 if (h
->type
== STT_GNU_IFUNC
)
5303 ifunc
= &h
->plt
.plist
;
5308 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5313 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5315 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5316 rel
->r_addend
, PLT_IFUNC
);
5321 r_type
= ELF64_R_TYPE (rel
->r_info
);
5322 if (is_branch_reloc (r_type
))
5324 if (h
!= NULL
&& (h
== tga
|| h
== dottga
))
5327 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5328 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5329 /* We have a new-style __tls_get_addr call with a marker
5333 /* Mark this section as having an old-style call. */
5334 sec
->has_tls_get_addr_call
= 1;
5337 /* STT_GNU_IFUNC symbols must have a PLT entry. */
5339 && !update_plt_info (abfd
, ifunc
, rel
->r_addend
))
5347 /* These special tls relocs tie a call to __tls_get_addr with
5348 its parameter symbol. */
5351 case R_PPC64_GOT_TLSLD16
:
5352 case R_PPC64_GOT_TLSLD16_LO
:
5353 case R_PPC64_GOT_TLSLD16_HI
:
5354 case R_PPC64_GOT_TLSLD16_HA
:
5355 tls_type
= TLS_TLS
| TLS_LD
;
5358 case R_PPC64_GOT_TLSGD16
:
5359 case R_PPC64_GOT_TLSGD16_LO
:
5360 case R_PPC64_GOT_TLSGD16_HI
:
5361 case R_PPC64_GOT_TLSGD16_HA
:
5362 tls_type
= TLS_TLS
| TLS_GD
;
5365 case R_PPC64_GOT_TPREL16_DS
:
5366 case R_PPC64_GOT_TPREL16_LO_DS
:
5367 case R_PPC64_GOT_TPREL16_HI
:
5368 case R_PPC64_GOT_TPREL16_HA
:
5369 if (bfd_link_pic (info
))
5370 info
->flags
|= DF_STATIC_TLS
;
5371 tls_type
= TLS_TLS
| TLS_TPREL
;
5374 case R_PPC64_GOT_DTPREL16_DS
:
5375 case R_PPC64_GOT_DTPREL16_LO_DS
:
5376 case R_PPC64_GOT_DTPREL16_HI
:
5377 case R_PPC64_GOT_DTPREL16_HA
:
5378 tls_type
= TLS_TLS
| TLS_DTPREL
;
5380 sec
->has_tls_reloc
= 1;
5384 case R_PPC64_GOT16_DS
:
5385 case R_PPC64_GOT16_HA
:
5386 case R_PPC64_GOT16_HI
:
5387 case R_PPC64_GOT16_LO
:
5388 case R_PPC64_GOT16_LO_DS
:
5389 /* This symbol requires a global offset table entry. */
5390 sec
->has_toc_reloc
= 1;
5391 if (r_type
== R_PPC64_GOT_TLSLD16
5392 || r_type
== R_PPC64_GOT_TLSGD16
5393 || r_type
== R_PPC64_GOT_TPREL16_DS
5394 || r_type
== R_PPC64_GOT_DTPREL16_DS
5395 || r_type
== R_PPC64_GOT16
5396 || r_type
== R_PPC64_GOT16_DS
)
5398 htab
->do_multi_toc
= 1;
5399 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5402 if (ppc64_elf_tdata (abfd
)->got
== NULL
5403 && !create_got_section (abfd
, info
))
5408 struct ppc_link_hash_entry
*eh
;
5409 struct got_entry
*ent
;
5411 eh
= (struct ppc_link_hash_entry
*) h
;
5412 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5413 if (ent
->addend
== rel
->r_addend
5414 && ent
->owner
== abfd
5415 && ent
->tls_type
== tls_type
)
5419 bfd_size_type amt
= sizeof (*ent
);
5420 ent
= bfd_alloc (abfd
, amt
);
5423 ent
->next
= eh
->elf
.got
.glist
;
5424 ent
->addend
= rel
->r_addend
;
5426 ent
->tls_type
= tls_type
;
5427 ent
->is_indirect
= FALSE
;
5428 ent
->got
.refcount
= 0;
5429 eh
->elf
.got
.glist
= ent
;
5431 ent
->got
.refcount
+= 1;
5432 eh
->tls_mask
|= tls_type
;
5435 /* This is a global offset table entry for a local symbol. */
5436 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5437 rel
->r_addend
, tls_type
))
5440 /* We may also need a plt entry if the symbol turns out to be
5442 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
5444 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5449 case R_PPC64_PLT16_HA
:
5450 case R_PPC64_PLT16_HI
:
5451 case R_PPC64_PLT16_LO
:
5454 /* This symbol requires a procedure linkage table entry. We
5455 actually build the entry in adjust_dynamic_symbol,
5456 because this might be a case of linking PIC code without
5457 linking in any dynamic objects, in which case we don't
5458 need to generate a procedure linkage table after all. */
5461 /* It does not make sense to have a procedure linkage
5462 table entry for a local symbol. */
5463 bfd_set_error (bfd_error_bad_value
);
5468 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5471 if (h
->root
.root
.string
[0] == '.'
5472 && h
->root
.root
.string
[1] != '\0')
5473 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5477 /* The following relocations don't need to propagate the
5478 relocation if linking a shared object since they are
5479 section relative. */
5480 case R_PPC64_SECTOFF
:
5481 case R_PPC64_SECTOFF_LO
:
5482 case R_PPC64_SECTOFF_HI
:
5483 case R_PPC64_SECTOFF_HA
:
5484 case R_PPC64_SECTOFF_DS
:
5485 case R_PPC64_SECTOFF_LO_DS
:
5486 case R_PPC64_DTPREL16
:
5487 case R_PPC64_DTPREL16_LO
:
5488 case R_PPC64_DTPREL16_HI
:
5489 case R_PPC64_DTPREL16_HA
:
5490 case R_PPC64_DTPREL16_DS
:
5491 case R_PPC64_DTPREL16_LO_DS
:
5492 case R_PPC64_DTPREL16_HIGH
:
5493 case R_PPC64_DTPREL16_HIGHA
:
5494 case R_PPC64_DTPREL16_HIGHER
:
5495 case R_PPC64_DTPREL16_HIGHERA
:
5496 case R_PPC64_DTPREL16_HIGHEST
:
5497 case R_PPC64_DTPREL16_HIGHESTA
:
5502 case R_PPC64_REL16_LO
:
5503 case R_PPC64_REL16_HI
:
5504 case R_PPC64_REL16_HA
:
5507 /* Not supported as a dynamic relocation. */
5508 case R_PPC64_ADDR64_LOCAL
:
5509 if (bfd_link_pic (info
))
5511 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5513 info
->callbacks
->einfo (_("%P: %H: %s reloc unsupported "
5514 "in shared libraries and PIEs.\n"),
5515 abfd
, sec
, rel
->r_offset
,
5516 ppc64_elf_howto_table
[r_type
]->name
);
5517 bfd_set_error (bfd_error_bad_value
);
5523 case R_PPC64_TOC16_DS
:
5524 htab
->do_multi_toc
= 1;
5525 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5526 case R_PPC64_TOC16_LO
:
5527 case R_PPC64_TOC16_HI
:
5528 case R_PPC64_TOC16_HA
:
5529 case R_PPC64_TOC16_LO_DS
:
5530 sec
->has_toc_reloc
= 1;
5533 /* This relocation describes the C++ object vtable hierarchy.
5534 Reconstruct it for later use during GC. */
5535 case R_PPC64_GNU_VTINHERIT
:
5536 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5540 /* This relocation describes which C++ vtable entries are actually
5541 used. Record for later use during GC. */
5542 case R_PPC64_GNU_VTENTRY
:
5543 BFD_ASSERT (h
!= NULL
);
5545 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5550 case R_PPC64_REL14_BRTAKEN
:
5551 case R_PPC64_REL14_BRNTAKEN
:
5553 asection
*dest
= NULL
;
5555 /* Heuristic: If jumping outside our section, chances are
5556 we are going to need a stub. */
5559 /* If the sym is weak it may be overridden later, so
5560 don't assume we know where a weak sym lives. */
5561 if (h
->root
.type
== bfd_link_hash_defined
)
5562 dest
= h
->root
.u
.def
.section
;
5566 Elf_Internal_Sym
*isym
;
5568 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5573 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5577 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5582 if (h
!= NULL
&& ifunc
== NULL
)
5584 /* We may need a .plt entry if the function this reloc
5585 refers to is in a shared lib. */
5586 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5589 if (h
->root
.root
.string
[0] == '.'
5590 && h
->root
.root
.string
[1] != '\0')
5591 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5592 if (h
== tga
|| h
== dottga
)
5593 sec
->has_tls_reloc
= 1;
5597 case R_PPC64_TPREL64
:
5598 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5599 if (bfd_link_pic (info
))
5600 info
->flags
|= DF_STATIC_TLS
;
5603 case R_PPC64_DTPMOD64
:
5604 if (rel
+ 1 < rel_end
5605 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5606 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5607 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5609 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5612 case R_PPC64_DTPREL64
:
5613 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5615 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5616 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5617 /* This is the second reloc of a dtpmod, dtprel pair.
5618 Don't mark with TLS_DTPREL. */
5622 sec
->has_tls_reloc
= 1;
5625 struct ppc_link_hash_entry
*eh
;
5626 eh
= (struct ppc_link_hash_entry
*) h
;
5627 eh
->tls_mask
|= tls_type
;
5630 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5631 rel
->r_addend
, tls_type
))
5634 ppc64_sec
= ppc64_elf_section_data (sec
);
5635 if (ppc64_sec
->sec_type
!= sec_toc
)
5639 /* One extra to simplify get_tls_mask. */
5640 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5641 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5642 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5644 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5645 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5646 if (ppc64_sec
->u
.toc
.add
== NULL
)
5648 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5649 ppc64_sec
->sec_type
= sec_toc
;
5651 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5652 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5653 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5655 /* Mark the second slot of a GD or LD entry.
5656 -1 to indicate GD and -2 to indicate LD. */
5657 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5658 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5659 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5660 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5663 case R_PPC64_TPREL16
:
5664 case R_PPC64_TPREL16_LO
:
5665 case R_PPC64_TPREL16_HI
:
5666 case R_PPC64_TPREL16_HA
:
5667 case R_PPC64_TPREL16_DS
:
5668 case R_PPC64_TPREL16_LO_DS
:
5669 case R_PPC64_TPREL16_HIGH
:
5670 case R_PPC64_TPREL16_HIGHA
:
5671 case R_PPC64_TPREL16_HIGHER
:
5672 case R_PPC64_TPREL16_HIGHERA
:
5673 case R_PPC64_TPREL16_HIGHEST
:
5674 case R_PPC64_TPREL16_HIGHESTA
:
5675 if (bfd_link_pic (info
))
5677 info
->flags
|= DF_STATIC_TLS
;
5682 case R_PPC64_ADDR64
:
5683 if (opd_sym_map
!= NULL
5684 && rel
+ 1 < rel_end
5685 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5689 if (h
->root
.root
.string
[0] == '.'
5690 && h
->root
.root
.string
[1] != 0
5691 && lookup_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
5694 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5699 Elf_Internal_Sym
*isym
;
5701 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5706 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5707 if (s
!= NULL
&& s
!= sec
)
5708 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
5713 case R_PPC64_ADDR16
:
5714 case R_PPC64_ADDR16_DS
:
5715 case R_PPC64_ADDR16_HA
:
5716 case R_PPC64_ADDR16_HI
:
5717 case R_PPC64_ADDR16_HIGH
:
5718 case R_PPC64_ADDR16_HIGHA
:
5719 case R_PPC64_ADDR16_HIGHER
:
5720 case R_PPC64_ADDR16_HIGHERA
:
5721 case R_PPC64_ADDR16_HIGHEST
:
5722 case R_PPC64_ADDR16_HIGHESTA
:
5723 case R_PPC64_ADDR16_LO
:
5724 case R_PPC64_ADDR16_LO_DS
:
5725 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5726 && rel
->r_addend
== 0)
5728 /* We may need a .plt entry if this reloc refers to a
5729 function in a shared lib. */
5730 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5732 h
->pointer_equality_needed
= 1;
5739 case R_PPC64_ADDR14
:
5740 case R_PPC64_ADDR14_BRNTAKEN
:
5741 case R_PPC64_ADDR14_BRTAKEN
:
5742 case R_PPC64_ADDR24
:
5743 case R_PPC64_ADDR32
:
5744 case R_PPC64_UADDR16
:
5745 case R_PPC64_UADDR32
:
5746 case R_PPC64_UADDR64
:
5748 if (h
!= NULL
&& !bfd_link_pic (info
))
5749 /* We may need a copy reloc. */
5752 /* Don't propagate .opd relocs. */
5753 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
5756 /* If we are creating a shared library, and this is a reloc
5757 against a global symbol, or a non PC relative reloc
5758 against a local symbol, then we need to copy the reloc
5759 into the shared library. However, if we are linking with
5760 -Bsymbolic, we do not need to copy a reloc against a
5761 global symbol which is defined in an object we are
5762 including in the link (i.e., DEF_REGULAR is set). At
5763 this point we have not seen all the input files, so it is
5764 possible that DEF_REGULAR is not set now but will be set
5765 later (it is never cleared). In case of a weak definition,
5766 DEF_REGULAR may be cleared later by a strong definition in
5767 a shared library. We account for that possibility below by
5768 storing information in the dyn_relocs field of the hash
5769 table entry. A similar situation occurs when creating
5770 shared libraries and symbol visibility changes render the
5773 If on the other hand, we are creating an executable, we
5774 may need to keep relocations for symbols satisfied by a
5775 dynamic library if we manage to avoid copy relocs for the
5778 if ((bfd_link_pic (info
)
5779 && (must_be_dyn_reloc (info
, r_type
)
5781 && (!SYMBOLIC_BIND (info
, h
)
5782 || h
->root
.type
== bfd_link_hash_defweak
5783 || !h
->def_regular
))))
5784 || (ELIMINATE_COPY_RELOCS
5785 && !bfd_link_pic (info
)
5787 && (h
->root
.type
== bfd_link_hash_defweak
5788 || !h
->def_regular
))
5789 || (!bfd_link_pic (info
)
5792 /* We must copy these reloc types into the output file.
5793 Create a reloc section in dynobj and make room for
5797 sreloc
= _bfd_elf_make_dynamic_reloc_section
5798 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
5804 /* If this is a global symbol, we count the number of
5805 relocations we need for this symbol. */
5808 struct elf_dyn_relocs
*p
;
5809 struct elf_dyn_relocs
**head
;
5811 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5813 if (p
== NULL
|| p
->sec
!= sec
)
5815 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5825 if (!must_be_dyn_reloc (info
, r_type
))
5830 /* Track dynamic relocs needed for local syms too.
5831 We really need local syms available to do this
5833 struct ppc_dyn_relocs
*p
;
5834 struct ppc_dyn_relocs
**head
;
5835 bfd_boolean is_ifunc
;
5838 Elf_Internal_Sym
*isym
;
5840 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5845 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5849 vpp
= &elf_section_data (s
)->local_dynrel
;
5850 head
= (struct ppc_dyn_relocs
**) vpp
;
5851 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
5853 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
5855 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
5857 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
5863 p
->ifunc
= is_ifunc
;
5879 /* Merge backend specific data from an object file to the output
5880 object file when linking. */
5883 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
5885 unsigned long iflags
, oflags
;
5887 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
5890 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
5893 if (!_bfd_generic_verify_endian_match (ibfd
, obfd
))
5896 iflags
= elf_elfheader (ibfd
)->e_flags
;
5897 oflags
= elf_elfheader (obfd
)->e_flags
;
5899 if (iflags
& ~EF_PPC64_ABI
)
5901 (*_bfd_error_handler
)
5902 (_("%B uses unknown e_flags 0x%lx"), ibfd
, iflags
);
5903 bfd_set_error (bfd_error_bad_value
);
5906 else if (iflags
!= oflags
&& iflags
!= 0)
5908 (*_bfd_error_handler
)
5909 (_("%B: ABI version %ld is not compatible with ABI version %ld output"),
5910 ibfd
, iflags
, oflags
);
5911 bfd_set_error (bfd_error_bad_value
);
5915 /* Merge Tag_compatibility attributes and any common GNU ones. */
5916 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
5922 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
5924 /* Print normal ELF private data. */
5925 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
5927 if (elf_elfheader (abfd
)->e_flags
!= 0)
5931 /* xgettext:c-format */
5932 fprintf (file
, _("private flags = 0x%lx:"),
5933 elf_elfheader (abfd
)->e_flags
);
5935 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
5936 fprintf (file
, _(" [abiv%ld]"),
5937 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
5944 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
5945 of the code entry point, and its section, which must be in the same
5946 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
5949 opd_entry_value (asection
*opd_sec
,
5951 asection
**code_sec
,
5953 bfd_boolean in_code_sec
)
5955 bfd
*opd_bfd
= opd_sec
->owner
;
5956 Elf_Internal_Rela
*relocs
;
5957 Elf_Internal_Rela
*lo
, *hi
, *look
;
5960 /* No relocs implies we are linking a --just-symbols object, or looking
5961 at a final linked executable with addr2line or somesuch. */
5962 if (opd_sec
->reloc_count
== 0)
5964 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
5966 if (contents
== NULL
)
5968 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
5969 return (bfd_vma
) -1;
5970 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
5973 /* PR 17512: file: 64b9dfbb. */
5974 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
5975 return (bfd_vma
) -1;
5977 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
5978 if (code_sec
!= NULL
)
5980 asection
*sec
, *likely
= NULL
;
5986 && val
< sec
->vma
+ sec
->size
)
5992 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5994 && (sec
->flags
& SEC_LOAD
) != 0
5995 && (sec
->flags
& SEC_ALLOC
) != 0)
6000 if (code_off
!= NULL
)
6001 *code_off
= val
- likely
->vma
;
6007 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
6009 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
6011 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
6012 /* PR 17512: file: df8e1fd6. */
6014 return (bfd_vma
) -1;
6016 /* Go find the opd reloc at the sym address. */
6018 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
6022 look
= lo
+ (hi
- lo
) / 2;
6023 if (look
->r_offset
< offset
)
6025 else if (look
->r_offset
> offset
)
6029 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
6031 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
6032 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
6034 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
6035 asection
*sec
= NULL
;
6037 if (symndx
>= symtab_hdr
->sh_info
6038 && elf_sym_hashes (opd_bfd
) != NULL
)
6040 struct elf_link_hash_entry
**sym_hashes
;
6041 struct elf_link_hash_entry
*rh
;
6043 sym_hashes
= elf_sym_hashes (opd_bfd
);
6044 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
6047 rh
= elf_follow_link (rh
);
6048 if (rh
->root
.type
!= bfd_link_hash_defined
6049 && rh
->root
.type
!= bfd_link_hash_defweak
)
6051 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
6053 val
= rh
->root
.u
.def
.value
;
6054 sec
= rh
->root
.u
.def
.section
;
6061 Elf_Internal_Sym
*sym
;
6063 if (symndx
< symtab_hdr
->sh_info
)
6065 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6068 size_t symcnt
= symtab_hdr
->sh_info
;
6069 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6074 symtab_hdr
->contents
= (bfd_byte
*) sym
;
6080 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6086 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
6089 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
6090 val
= sym
->st_value
;
6093 val
+= look
->r_addend
;
6094 if (code_off
!= NULL
)
6096 if (code_sec
!= NULL
)
6098 if (in_code_sec
&& *code_sec
!= sec
)
6103 if (sec
->output_section
!= NULL
)
6104 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
6113 /* If the ELF symbol SYM might be a function in SEC, return the
6114 function size and set *CODE_OFF to the function's entry point,
6115 otherwise return zero. */
6117 static bfd_size_type
6118 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
6123 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
6124 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
6128 if (!(sym
->flags
& BSF_SYNTHETIC
))
6129 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
6131 if (strcmp (sym
->section
->name
, ".opd") == 0)
6133 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
6134 bfd_vma symval
= sym
->value
;
6137 && opd
->adjust
!= NULL
6138 && elf_section_data (sym
->section
)->relocs
!= NULL
)
6140 /* opd_entry_value will use cached relocs that have been
6141 adjusted, but with raw symbols. That means both local
6142 and global symbols need adjusting. */
6143 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
6149 if (opd_entry_value (sym
->section
, symval
,
6150 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
6152 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6153 symbol. This size has nothing to do with the code size of the
6154 function, which is what we're supposed to return, but the
6155 code size isn't available without looking up the dot-sym.
6156 However, doing that would be a waste of time particularly
6157 since elf_find_function will look at the dot-sym anyway.
6158 Now, elf_find_function will keep the largest size of any
6159 function sym found at the code address of interest, so return
6160 1 here to avoid it incorrectly caching a larger function size
6161 for a small function. This does mean we return the wrong
6162 size for a new-ABI function of size 24, but all that does is
6163 disable caching for such functions. */
6169 if (sym
->section
!= sec
)
6171 *code_off
= sym
->value
;
6178 /* Return true if symbol is defined in a regular object file. */
6181 is_static_defined (struct elf_link_hash_entry
*h
)
6183 return ((h
->root
.type
== bfd_link_hash_defined
6184 || h
->root
.type
== bfd_link_hash_defweak
)
6185 && h
->root
.u
.def
.section
!= NULL
6186 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6189 /* If FDH is a function descriptor symbol, return the associated code
6190 entry symbol if it is defined. Return NULL otherwise. */
6192 static struct ppc_link_hash_entry
*
6193 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
6195 if (fdh
->is_func_descriptor
)
6197 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
6198 if (fh
->elf
.root
.type
== bfd_link_hash_defined
6199 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6205 /* If FH is a function code entry symbol, return the associated
6206 function descriptor symbol if it is defined. Return NULL otherwise. */
6208 static struct ppc_link_hash_entry
*
6209 defined_func_desc (struct ppc_link_hash_entry
*fh
)
6212 && fh
->oh
->is_func_descriptor
)
6214 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
6215 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
6216 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6222 /* Mark all our entry sym sections, both opd and code section. */
6225 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
6227 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6228 struct bfd_sym_chain
*sym
;
6233 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
6235 struct ppc_link_hash_entry
*eh
, *fh
;
6238 eh
= (struct ppc_link_hash_entry
*)
6239 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
6242 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
6243 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6246 fh
= defined_code_entry (eh
);
6249 sec
= fh
->elf
.root
.u
.def
.section
;
6250 sec
->flags
|= SEC_KEEP
;
6252 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6253 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6254 eh
->elf
.root
.u
.def
.value
,
6255 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6256 sec
->flags
|= SEC_KEEP
;
6258 sec
= eh
->elf
.root
.u
.def
.section
;
6259 sec
->flags
|= SEC_KEEP
;
6263 /* Mark sections containing dynamically referenced symbols. When
6264 building shared libraries, we must assume that any visible symbol is
6268 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
6270 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6271 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
6272 struct ppc_link_hash_entry
*fdh
;
6273 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
6275 /* Dynamic linking info is on the func descriptor sym. */
6276 fdh
= defined_func_desc (eh
);
6280 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
6281 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
6282 && (eh
->elf
.ref_dynamic
6283 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
6284 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
6285 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
6286 && (!bfd_link_executable (info
)
6287 || info
->export_dynamic
6290 && (*d
->match
) (&d
->head
, NULL
, eh
->elf
.root
.root
.string
)))
6291 && (strchr (eh
->elf
.root
.root
.string
, ELF_VER_CHR
) != NULL
6292 || !bfd_hide_sym_by_version (info
->version_info
,
6293 eh
->elf
.root
.root
.string
)))))
6296 struct ppc_link_hash_entry
*fh
;
6298 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
6300 /* Function descriptor syms cause the associated
6301 function code sym section to be marked. */
6302 fh
= defined_code_entry (eh
);
6305 code_sec
= fh
->elf
.root
.u
.def
.section
;
6306 code_sec
->flags
|= SEC_KEEP
;
6308 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6309 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6310 eh
->elf
.root
.u
.def
.value
,
6311 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6312 code_sec
->flags
|= SEC_KEEP
;
6318 /* Return the section that should be marked against GC for a given
6322 ppc64_elf_gc_mark_hook (asection
*sec
,
6323 struct bfd_link_info
*info
,
6324 Elf_Internal_Rela
*rel
,
6325 struct elf_link_hash_entry
*h
,
6326 Elf_Internal_Sym
*sym
)
6330 /* Syms return NULL if we're marking .opd, so we avoid marking all
6331 function sections, as all functions are referenced in .opd. */
6333 if (get_opd_info (sec
) != NULL
)
6338 enum elf_ppc64_reloc_type r_type
;
6339 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
6341 r_type
= ELF64_R_TYPE (rel
->r_info
);
6344 case R_PPC64_GNU_VTINHERIT
:
6345 case R_PPC64_GNU_VTENTRY
:
6349 switch (h
->root
.type
)
6351 case bfd_link_hash_defined
:
6352 case bfd_link_hash_defweak
:
6353 eh
= (struct ppc_link_hash_entry
*) h
;
6354 fdh
= defined_func_desc (eh
);
6358 /* Function descriptor syms cause the associated
6359 function code sym section to be marked. */
6360 fh
= defined_code_entry (eh
);
6363 /* They also mark their opd section. */
6364 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6366 rsec
= fh
->elf
.root
.u
.def
.section
;
6368 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6369 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6370 eh
->elf
.root
.u
.def
.value
,
6371 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
6372 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6374 rsec
= h
->root
.u
.def
.section
;
6377 case bfd_link_hash_common
:
6378 rsec
= h
->root
.u
.c
.p
->section
;
6382 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6388 struct _opd_sec_data
*opd
;
6390 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6391 opd
= get_opd_info (rsec
);
6392 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6396 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6403 /* Update the .got, .plt. and dynamic reloc reference counts for the
6404 section being removed. */
6407 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6408 asection
*sec
, const Elf_Internal_Rela
*relocs
)
6410 struct ppc_link_hash_table
*htab
;
6411 Elf_Internal_Shdr
*symtab_hdr
;
6412 struct elf_link_hash_entry
**sym_hashes
;
6413 struct got_entry
**local_got_ents
;
6414 const Elf_Internal_Rela
*rel
, *relend
;
6416 if (bfd_link_relocatable (info
))
6419 if ((sec
->flags
& SEC_ALLOC
) == 0)
6422 elf_section_data (sec
)->local_dynrel
= NULL
;
6424 htab
= ppc_hash_table (info
);
6428 symtab_hdr
= &elf_symtab_hdr (abfd
);
6429 sym_hashes
= elf_sym_hashes (abfd
);
6430 local_got_ents
= elf_local_got_ents (abfd
);
6432 relend
= relocs
+ sec
->reloc_count
;
6433 for (rel
= relocs
; rel
< relend
; rel
++)
6435 unsigned long r_symndx
;
6436 enum elf_ppc64_reloc_type r_type
;
6437 struct elf_link_hash_entry
*h
= NULL
;
6438 unsigned char tls_type
= 0;
6440 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6441 r_type
= ELF64_R_TYPE (rel
->r_info
);
6442 if (r_symndx
>= symtab_hdr
->sh_info
)
6444 struct ppc_link_hash_entry
*eh
;
6445 struct elf_dyn_relocs
**pp
;
6446 struct elf_dyn_relocs
*p
;
6448 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6449 h
= elf_follow_link (h
);
6450 eh
= (struct ppc_link_hash_entry
*) h
;
6452 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
6455 /* Everything must go for SEC. */
6461 if (is_branch_reloc (r_type
))
6463 struct plt_entry
**ifunc
= NULL
;
6466 if (h
->type
== STT_GNU_IFUNC
)
6467 ifunc
= &h
->plt
.plist
;
6469 else if (local_got_ents
!= NULL
)
6471 struct plt_entry
**local_plt
= (struct plt_entry
**)
6472 (local_got_ents
+ symtab_hdr
->sh_info
);
6473 unsigned char *local_got_tls_masks
= (unsigned char *)
6474 (local_plt
+ symtab_hdr
->sh_info
);
6475 if ((local_got_tls_masks
[r_symndx
] & PLT_IFUNC
) != 0)
6476 ifunc
= local_plt
+ r_symndx
;
6480 struct plt_entry
*ent
;
6482 for (ent
= *ifunc
; ent
!= NULL
; ent
= ent
->next
)
6483 if (ent
->addend
== rel
->r_addend
)
6487 if (ent
->plt
.refcount
> 0)
6488 ent
->plt
.refcount
-= 1;
6495 case R_PPC64_GOT_TLSLD16
:
6496 case R_PPC64_GOT_TLSLD16_LO
:
6497 case R_PPC64_GOT_TLSLD16_HI
:
6498 case R_PPC64_GOT_TLSLD16_HA
:
6499 tls_type
= TLS_TLS
| TLS_LD
;
6502 case R_PPC64_GOT_TLSGD16
:
6503 case R_PPC64_GOT_TLSGD16_LO
:
6504 case R_PPC64_GOT_TLSGD16_HI
:
6505 case R_PPC64_GOT_TLSGD16_HA
:
6506 tls_type
= TLS_TLS
| TLS_GD
;
6509 case R_PPC64_GOT_TPREL16_DS
:
6510 case R_PPC64_GOT_TPREL16_LO_DS
:
6511 case R_PPC64_GOT_TPREL16_HI
:
6512 case R_PPC64_GOT_TPREL16_HA
:
6513 tls_type
= TLS_TLS
| TLS_TPREL
;
6516 case R_PPC64_GOT_DTPREL16_DS
:
6517 case R_PPC64_GOT_DTPREL16_LO_DS
:
6518 case R_PPC64_GOT_DTPREL16_HI
:
6519 case R_PPC64_GOT_DTPREL16_HA
:
6520 tls_type
= TLS_TLS
| TLS_DTPREL
;
6524 case R_PPC64_GOT16_DS
:
6525 case R_PPC64_GOT16_HA
:
6526 case R_PPC64_GOT16_HI
:
6527 case R_PPC64_GOT16_LO
:
6528 case R_PPC64_GOT16_LO_DS
:
6531 struct got_entry
*ent
;
6536 ent
= local_got_ents
[r_symndx
];
6538 for (; ent
!= NULL
; ent
= ent
->next
)
6539 if (ent
->addend
== rel
->r_addend
6540 && ent
->owner
== abfd
6541 && ent
->tls_type
== tls_type
)
6545 if (ent
->got
.refcount
> 0)
6546 ent
->got
.refcount
-= 1;
6550 case R_PPC64_PLT16_HA
:
6551 case R_PPC64_PLT16_HI
:
6552 case R_PPC64_PLT16_LO
:
6556 case R_PPC64_REL14_BRNTAKEN
:
6557 case R_PPC64_REL14_BRTAKEN
:
6561 struct plt_entry
*ent
;
6563 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6564 if (ent
->addend
== rel
->r_addend
)
6566 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
6567 ent
->plt
.refcount
-= 1;
6578 /* The maximum size of .sfpr. */
6579 #define SFPR_MAX (218*4)
6581 struct sfpr_def_parms
6583 const char name
[12];
6584 unsigned char lo
, hi
;
6585 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
6586 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
6589 /* Auto-generate _save*, _rest* functions in .sfpr.
6590 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6594 sfpr_define (struct bfd_link_info
*info
,
6595 const struct sfpr_def_parms
*parm
,
6598 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6600 size_t len
= strlen (parm
->name
);
6601 bfd_boolean writing
= FALSE
;
6607 memcpy (sym
, parm
->name
, len
);
6610 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6612 struct ppc_link_hash_entry
*h
;
6614 sym
[len
+ 0] = i
/ 10 + '0';
6615 sym
[len
+ 1] = i
% 10 + '0';
6616 h
= (struct ppc_link_hash_entry
*)
6617 elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
6618 if (stub_sec
!= NULL
)
6621 && h
->elf
.root
.type
== bfd_link_hash_defined
6622 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6624 struct elf_link_hash_entry
*s
;
6626 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6627 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
6630 if (s
->root
.type
== bfd_link_hash_new
6631 || (s
->root
.type
= bfd_link_hash_defined
6632 && s
->root
.u
.def
.section
== stub_sec
))
6634 s
->root
.type
= bfd_link_hash_defined
;
6635 s
->root
.u
.def
.section
= stub_sec
;
6636 s
->root
.u
.def
.value
= (stub_sec
->size
6637 + h
->elf
.root
.u
.def
.value
);
6640 s
->ref_regular_nonweak
= 1;
6641 s
->forced_local
= 1;
6643 s
->root
.linker_def
= 1;
6651 if (!h
->elf
.def_regular
)
6653 h
->elf
.root
.type
= bfd_link_hash_defined
;
6654 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6655 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6656 h
->elf
.type
= STT_FUNC
;
6657 h
->elf
.def_regular
= 1;
6658 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
6660 if (htab
->sfpr
->contents
== NULL
)
6662 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6663 if (htab
->sfpr
->contents
== NULL
)
6670 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6672 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6674 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6675 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6683 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6685 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6690 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6692 p
= savegpr0 (abfd
, p
, r
);
6693 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6695 bfd_put_32 (abfd
, BLR
, p
);
6700 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6702 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6707 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6709 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6711 p
= restgpr0 (abfd
, p
, r
);
6712 bfd_put_32 (abfd
, MTLR_R0
, p
);
6716 p
= restgpr0 (abfd
, p
, 30);
6717 p
= restgpr0 (abfd
, p
, 31);
6719 bfd_put_32 (abfd
, BLR
, p
);
6724 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6726 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6731 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6733 p
= savegpr1 (abfd
, p
, r
);
6734 bfd_put_32 (abfd
, BLR
, p
);
6739 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6741 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6746 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6748 p
= restgpr1 (abfd
, p
, r
);
6749 bfd_put_32 (abfd
, BLR
, p
);
6754 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6756 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6761 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6763 p
= savefpr (abfd
, p
, r
);
6764 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6766 bfd_put_32 (abfd
, BLR
, p
);
6771 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6773 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6778 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6780 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6782 p
= restfpr (abfd
, p
, r
);
6783 bfd_put_32 (abfd
, MTLR_R0
, p
);
6787 p
= restfpr (abfd
, p
, 30);
6788 p
= restfpr (abfd
, p
, 31);
6790 bfd_put_32 (abfd
, BLR
, p
);
6795 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6797 p
= savefpr (abfd
, p
, r
);
6798 bfd_put_32 (abfd
, BLR
, p
);
6803 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6805 p
= restfpr (abfd
, p
, r
);
6806 bfd_put_32 (abfd
, BLR
, p
);
6811 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6813 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6815 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6820 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6822 p
= savevr (abfd
, p
, r
);
6823 bfd_put_32 (abfd
, BLR
, p
);
6828 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6830 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6832 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6837 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6839 p
= restvr (abfd
, p
, r
);
6840 bfd_put_32 (abfd
, BLR
, p
);
6844 /* Called via elf_link_hash_traverse to transfer dynamic linking
6845 information on function code symbol entries to their corresponding
6846 function descriptor symbol entries. */
6849 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6851 struct bfd_link_info
*info
;
6852 struct ppc_link_hash_table
*htab
;
6853 struct plt_entry
*ent
;
6854 struct ppc_link_hash_entry
*fh
;
6855 struct ppc_link_hash_entry
*fdh
;
6856 bfd_boolean force_local
;
6858 fh
= (struct ppc_link_hash_entry
*) h
;
6859 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6863 htab
= ppc_hash_table (info
);
6867 /* Resolve undefined references to dot-symbols as the value
6868 in the function descriptor, if we have one in a regular object.
6869 This is to satisfy cases like ".quad .foo". Calls to functions
6870 in dynamic objects are handled elsewhere. */
6871 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
6872 && fh
->was_undefined
6873 && (fdh
= defined_func_desc (fh
)) != NULL
6874 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
6875 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
6876 fdh
->elf
.root
.u
.def
.value
,
6877 &fh
->elf
.root
.u
.def
.section
,
6878 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
6880 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
6881 fh
->elf
.forced_local
= 1;
6882 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
6883 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
6886 /* If this is a function code symbol, transfer dynamic linking
6887 information to the function descriptor symbol. */
6891 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6892 if (ent
->plt
.refcount
> 0)
6895 || fh
->elf
.root
.root
.string
[0] != '.'
6896 || fh
->elf
.root
.root
.string
[1] == '\0')
6899 /* Find the corresponding function descriptor symbol. Create it
6900 as undefined if necessary. */
6902 fdh
= lookup_fdh (fh
, htab
);
6904 && !bfd_link_executable (info
)
6905 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
6906 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
6908 fdh
= make_fdh (info
, fh
);
6913 /* Fake function descriptors are made undefweak. If the function
6914 code symbol is strong undefined, make the fake sym the same.
6915 If the function code symbol is defined, then force the fake
6916 descriptor local; We can't support overriding of symbols in a
6917 shared library on a fake descriptor. */
6921 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
6923 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
6925 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
6926 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
6928 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
6929 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6931 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
6936 && !fdh
->elf
.forced_local
6937 && (!bfd_link_executable (info
)
6938 || fdh
->elf
.def_dynamic
6939 || fdh
->elf
.ref_dynamic
6940 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
6941 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
6943 if (fdh
->elf
.dynindx
== -1)
6944 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
6946 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
6947 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
6948 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
6949 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
6950 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
6952 move_plt_plist (fh
, fdh
);
6953 fdh
->elf
.needs_plt
= 1;
6955 fdh
->is_func_descriptor
= 1;
6960 /* Now that the info is on the function descriptor, clear the
6961 function code sym info. Any function code syms for which we
6962 don't have a definition in a regular file, we force local.
6963 This prevents a shared library from exporting syms that have
6964 been imported from another library. Function code syms that
6965 are really in the library we must leave global to prevent the
6966 linker dragging in a definition from a static library. */
6967 force_local
= (!fh
->elf
.def_regular
6969 || !fdh
->elf
.def_regular
6970 || fdh
->elf
.forced_local
);
6971 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
6976 static const struct sfpr_def_parms save_res_funcs
[] =
6978 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
6979 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
6980 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
6981 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
6982 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
6983 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
6984 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
6985 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
6986 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
6987 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
6988 { "_savevr_", 20, 31, savevr
, savevr_tail
},
6989 { "_restvr_", 20, 31, restvr
, restvr_tail
}
6992 /* Called near the start of bfd_elf_size_dynamic_sections. We use
6993 this hook to a) provide some gcc support functions, and b) transfer
6994 dynamic linking information gathered so far on function code symbol
6995 entries, to their corresponding function descriptor symbol entries. */
6998 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
6999 struct bfd_link_info
*info
)
7001 struct ppc_link_hash_table
*htab
;
7004 htab
= ppc_hash_table (info
);
7008 if (!bfd_link_relocatable (info
)
7009 && htab
->elf
.hgot
!= NULL
)
7011 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
7012 /* Make .TOC. defined so as to prevent it being made dynamic.
7013 The wrong value here is fixed later in ppc64_elf_set_toc. */
7014 if (!htab
->elf
.hgot
->def_regular
7015 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
7017 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
7018 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
7019 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
7020 htab
->elf
.hgot
->def_regular
= 1;
7021 htab
->elf
.hgot
->root
.linker_def
= 1;
7023 htab
->elf
.hgot
->type
= STT_OBJECT
;
7024 htab
->elf
.hgot
->other
= ((htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1))
7028 if (htab
->sfpr
== NULL
)
7029 /* We don't have any relocs. */
7032 /* Provide any missing _save* and _rest* functions. */
7033 htab
->sfpr
->size
= 0;
7034 if (htab
->params
->save_restore_funcs
)
7035 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
7036 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
7039 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7041 if (htab
->sfpr
->size
== 0)
7042 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
7047 /* Return true if we have dynamic relocs that apply to read-only sections. */
7050 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7052 struct ppc_link_hash_entry
*eh
;
7053 struct elf_dyn_relocs
*p
;
7055 eh
= (struct ppc_link_hash_entry
*) h
;
7056 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7058 asection
*s
= p
->sec
->output_section
;
7060 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7066 /* Adjust a symbol defined by a dynamic object and referenced by a
7067 regular object. The current definition is in some section of the
7068 dynamic object, but we're not including those sections. We have to
7069 change the definition to something the rest of the link can
7073 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7074 struct elf_link_hash_entry
*h
)
7076 struct ppc_link_hash_table
*htab
;
7079 htab
= ppc_hash_table (info
);
7083 /* Deal with function syms. */
7084 if (h
->type
== STT_FUNC
7085 || h
->type
== STT_GNU_IFUNC
7088 /* Clear procedure linkage table information for any symbol that
7089 won't need a .plt entry. */
7090 struct plt_entry
*ent
;
7091 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7092 if (ent
->plt
.refcount
> 0)
7095 || (h
->type
!= STT_GNU_IFUNC
7096 && (SYMBOL_CALLS_LOCAL (info
, h
)
7097 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
7098 && h
->root
.type
== bfd_link_hash_undefweak
)))
7099 || ((struct ppc_link_hash_entry
*) h
)->save_res
)
7101 h
->plt
.plist
= NULL
;
7103 h
->pointer_equality_needed
= 0;
7105 else if (abiversion (info
->output_bfd
) == 2)
7107 /* Taking a function's address in a read/write section
7108 doesn't require us to define the function symbol in the
7109 executable on a global entry stub. A dynamic reloc can
7111 if (h
->pointer_equality_needed
7112 && h
->type
!= STT_GNU_IFUNC
7113 && !readonly_dynrelocs (h
))
7115 h
->pointer_equality_needed
= 0;
7119 /* After adjust_dynamic_symbol, non_got_ref set in the
7120 non-shared case means that we have allocated space in
7121 .dynbss for the symbol and thus dyn_relocs for this
7122 symbol should be discarded.
7123 If we get here we know we are making a PLT entry for this
7124 symbol, and in an executable we'd normally resolve
7125 relocations against this symbol to the PLT entry. Allow
7126 dynamic relocs if the reference is weak, and the dynamic
7127 relocs will not cause text relocation. */
7128 else if (!h
->ref_regular_nonweak
7130 && h
->type
!= STT_GNU_IFUNC
7131 && !readonly_dynrelocs (h
))
7134 /* If making a plt entry, then we don't need copy relocs. */
7139 h
->plt
.plist
= NULL
;
7141 /* If this is a weak symbol, and there is a real definition, the
7142 processor independent code will have arranged for us to see the
7143 real definition first, and we can just use the same value. */
7144 if (h
->u
.weakdef
!= NULL
)
7146 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
7147 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
7148 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
7149 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
7150 if (ELIMINATE_COPY_RELOCS
)
7151 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
7155 /* If we are creating a shared library, we must presume that the
7156 only references to the symbol are via the global offset table.
7157 For such cases we need not do anything here; the relocations will
7158 be handled correctly by relocate_section. */
7159 if (bfd_link_pic (info
))
7162 /* If there are no references to this symbol that do not use the
7163 GOT, we don't need to generate a copy reloc. */
7164 if (!h
->non_got_ref
)
7167 /* Don't generate a copy reloc for symbols defined in the executable. */
7168 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
)
7171 /* If -z nocopyreloc was given, don't generate them either. */
7172 if (info
->nocopyreloc
)
7178 /* If we didn't find any dynamic relocs in read-only sections, then
7179 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7180 if (ELIMINATE_COPY_RELOCS
&& !readonly_dynrelocs (h
))
7186 /* Protected variables do not work with .dynbss. The copy in
7187 .dynbss won't be used by the shared library with the protected
7188 definition for the variable. Text relocations are preferable
7189 to an incorrect program. */
7190 if (h
->protected_def
)
7196 if (h
->plt
.plist
!= NULL
)
7198 /* We should never get here, but unfortunately there are versions
7199 of gcc out there that improperly (for this ABI) put initialized
7200 function pointers, vtable refs and suchlike in read-only
7201 sections. Allow them to proceed, but warn that this might
7202 break at runtime. */
7203 info
->callbacks
->einfo
7204 (_("%P: copy reloc against `%T' requires lazy plt linking; "
7205 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7206 h
->root
.root
.string
);
7209 /* This is a reference to a symbol defined by a dynamic object which
7210 is not a function. */
7212 /* We must allocate the symbol in our .dynbss section, which will
7213 become part of the .bss section of the executable. There will be
7214 an entry for this symbol in the .dynsym section. The dynamic
7215 object will contain position independent code, so all references
7216 from the dynamic object to this symbol will go through the global
7217 offset table. The dynamic linker will use the .dynsym entry to
7218 determine the address it must put in the global offset table, so
7219 both the dynamic object and the regular object will refer to the
7220 same memory location for the variable. */
7222 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
7223 to copy the initial value out of the dynamic object and into the
7224 runtime process image. We need to remember the offset into the
7225 .rela.bss section we are going to use. */
7226 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7228 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
7234 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7237 /* If given a function descriptor symbol, hide both the function code
7238 sym and the descriptor. */
7240 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
7241 struct elf_link_hash_entry
*h
,
7242 bfd_boolean force_local
)
7244 struct ppc_link_hash_entry
*eh
;
7245 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
7247 eh
= (struct ppc_link_hash_entry
*) h
;
7248 if (eh
->is_func_descriptor
)
7250 struct ppc_link_hash_entry
*fh
= eh
->oh
;
7255 struct ppc_link_hash_table
*htab
;
7258 /* We aren't supposed to use alloca in BFD because on
7259 systems which do not have alloca the version in libiberty
7260 calls xmalloc, which might cause the program to crash
7261 when it runs out of memory. This function doesn't have a
7262 return status, so there's no way to gracefully return an
7263 error. So cheat. We know that string[-1] can be safely
7264 accessed; It's either a string in an ELF string table,
7265 or allocated in an objalloc structure. */
7267 p
= eh
->elf
.root
.root
.string
- 1;
7270 htab
= ppc_hash_table (info
);
7274 fh
= (struct ppc_link_hash_entry
*)
7275 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
7278 /* Unfortunately, if it so happens that the string we were
7279 looking for was allocated immediately before this string,
7280 then we overwrote the string terminator. That's the only
7281 reason the lookup should fail. */
7284 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
7285 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
7287 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
7288 fh
= (struct ppc_link_hash_entry
*)
7289 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
7298 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7303 get_sym_h (struct elf_link_hash_entry
**hp
,
7304 Elf_Internal_Sym
**symp
,
7306 unsigned char **tls_maskp
,
7307 Elf_Internal_Sym
**locsymsp
,
7308 unsigned long r_symndx
,
7311 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7313 if (r_symndx
>= symtab_hdr
->sh_info
)
7315 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7316 struct elf_link_hash_entry
*h
;
7318 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7319 h
= elf_follow_link (h
);
7327 if (symsecp
!= NULL
)
7329 asection
*symsec
= NULL
;
7330 if (h
->root
.type
== bfd_link_hash_defined
7331 || h
->root
.type
== bfd_link_hash_defweak
)
7332 symsec
= h
->root
.u
.def
.section
;
7336 if (tls_maskp
!= NULL
)
7338 struct ppc_link_hash_entry
*eh
;
7340 eh
= (struct ppc_link_hash_entry
*) h
;
7341 *tls_maskp
= &eh
->tls_mask
;
7346 Elf_Internal_Sym
*sym
;
7347 Elf_Internal_Sym
*locsyms
= *locsymsp
;
7349 if (locsyms
== NULL
)
7351 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7352 if (locsyms
== NULL
)
7353 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
7354 symtab_hdr
->sh_info
,
7355 0, NULL
, NULL
, NULL
);
7356 if (locsyms
== NULL
)
7358 *locsymsp
= locsyms
;
7360 sym
= locsyms
+ r_symndx
;
7368 if (symsecp
!= NULL
)
7369 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
7371 if (tls_maskp
!= NULL
)
7373 struct got_entry
**lgot_ents
;
7374 unsigned char *tls_mask
;
7377 lgot_ents
= elf_local_got_ents (ibfd
);
7378 if (lgot_ents
!= NULL
)
7380 struct plt_entry
**local_plt
= (struct plt_entry
**)
7381 (lgot_ents
+ symtab_hdr
->sh_info
);
7382 unsigned char *lgot_masks
= (unsigned char *)
7383 (local_plt
+ symtab_hdr
->sh_info
);
7384 tls_mask
= &lgot_masks
[r_symndx
];
7386 *tls_maskp
= tls_mask
;
7392 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7393 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7394 type suitable for optimization, and 1 otherwise. */
7397 get_tls_mask (unsigned char **tls_maskp
,
7398 unsigned long *toc_symndx
,
7399 bfd_vma
*toc_addend
,
7400 Elf_Internal_Sym
**locsymsp
,
7401 const Elf_Internal_Rela
*rel
,
7404 unsigned long r_symndx
;
7406 struct elf_link_hash_entry
*h
;
7407 Elf_Internal_Sym
*sym
;
7411 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7412 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7415 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
7417 || ppc64_elf_section_data (sec
) == NULL
7418 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7421 /* Look inside a TOC section too. */
7424 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7425 off
= h
->root
.u
.def
.value
;
7428 off
= sym
->st_value
;
7429 off
+= rel
->r_addend
;
7430 BFD_ASSERT (off
% 8 == 0);
7431 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7432 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7433 if (toc_symndx
!= NULL
)
7434 *toc_symndx
= r_symndx
;
7435 if (toc_addend
!= NULL
)
7436 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7437 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7439 if ((h
== NULL
|| is_static_defined (h
))
7440 && (next_r
== -1 || next_r
== -2))
7445 /* Find (or create) an entry in the tocsave hash table. */
7447 static struct tocsave_entry
*
7448 tocsave_find (struct ppc_link_hash_table
*htab
,
7449 enum insert_option insert
,
7450 Elf_Internal_Sym
**local_syms
,
7451 const Elf_Internal_Rela
*irela
,
7454 unsigned long r_indx
;
7455 struct elf_link_hash_entry
*h
;
7456 Elf_Internal_Sym
*sym
;
7457 struct tocsave_entry ent
, *p
;
7459 struct tocsave_entry
**slot
;
7461 r_indx
= ELF64_R_SYM (irela
->r_info
);
7462 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7464 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7466 (*_bfd_error_handler
)
7467 (_("%B: undefined symbol on R_PPC64_TOCSAVE relocation"));
7472 ent
.offset
= h
->root
.u
.def
.value
;
7474 ent
.offset
= sym
->st_value
;
7475 ent
.offset
+= irela
->r_addend
;
7477 hash
= tocsave_htab_hash (&ent
);
7478 slot
= ((struct tocsave_entry
**)
7479 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7485 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7494 /* Adjust all global syms defined in opd sections. In gcc generated
7495 code for the old ABI, these will already have been done. */
7498 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7500 struct ppc_link_hash_entry
*eh
;
7502 struct _opd_sec_data
*opd
;
7504 if (h
->root
.type
== bfd_link_hash_indirect
)
7507 if (h
->root
.type
!= bfd_link_hash_defined
7508 && h
->root
.type
!= bfd_link_hash_defweak
)
7511 eh
= (struct ppc_link_hash_entry
*) h
;
7512 if (eh
->adjust_done
)
7515 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7516 opd
= get_opd_info (sym_sec
);
7517 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7519 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7522 /* This entry has been deleted. */
7523 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7526 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7527 if (discarded_section (dsec
))
7529 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7533 eh
->elf
.root
.u
.def
.value
= 0;
7534 eh
->elf
.root
.u
.def
.section
= dsec
;
7537 eh
->elf
.root
.u
.def
.value
+= adjust
;
7538 eh
->adjust_done
= 1;
7543 /* Handles decrementing dynamic reloc counts for the reloc specified by
7544 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7545 have already been determined. */
7548 dec_dynrel_count (bfd_vma r_info
,
7550 struct bfd_link_info
*info
,
7551 Elf_Internal_Sym
**local_syms
,
7552 struct elf_link_hash_entry
*h
,
7553 Elf_Internal_Sym
*sym
)
7555 enum elf_ppc64_reloc_type r_type
;
7556 asection
*sym_sec
= NULL
;
7558 /* Can this reloc be dynamic? This switch, and later tests here
7559 should be kept in sync with the code in check_relocs. */
7560 r_type
= ELF64_R_TYPE (r_info
);
7566 case R_PPC64_TPREL16
:
7567 case R_PPC64_TPREL16_LO
:
7568 case R_PPC64_TPREL16_HI
:
7569 case R_PPC64_TPREL16_HA
:
7570 case R_PPC64_TPREL16_DS
:
7571 case R_PPC64_TPREL16_LO_DS
:
7572 case R_PPC64_TPREL16_HIGH
:
7573 case R_PPC64_TPREL16_HIGHA
:
7574 case R_PPC64_TPREL16_HIGHER
:
7575 case R_PPC64_TPREL16_HIGHERA
:
7576 case R_PPC64_TPREL16_HIGHEST
:
7577 case R_PPC64_TPREL16_HIGHESTA
:
7578 if (!bfd_link_pic (info
))
7581 case R_PPC64_TPREL64
:
7582 case R_PPC64_DTPMOD64
:
7583 case R_PPC64_DTPREL64
:
7584 case R_PPC64_ADDR64
:
7588 case R_PPC64_ADDR14
:
7589 case R_PPC64_ADDR14_BRNTAKEN
:
7590 case R_PPC64_ADDR14_BRTAKEN
:
7591 case R_PPC64_ADDR16
:
7592 case R_PPC64_ADDR16_DS
:
7593 case R_PPC64_ADDR16_HA
:
7594 case R_PPC64_ADDR16_HI
:
7595 case R_PPC64_ADDR16_HIGH
:
7596 case R_PPC64_ADDR16_HIGHA
:
7597 case R_PPC64_ADDR16_HIGHER
:
7598 case R_PPC64_ADDR16_HIGHERA
:
7599 case R_PPC64_ADDR16_HIGHEST
:
7600 case R_PPC64_ADDR16_HIGHESTA
:
7601 case R_PPC64_ADDR16_LO
:
7602 case R_PPC64_ADDR16_LO_DS
:
7603 case R_PPC64_ADDR24
:
7604 case R_PPC64_ADDR32
:
7605 case R_PPC64_UADDR16
:
7606 case R_PPC64_UADDR32
:
7607 case R_PPC64_UADDR64
:
7612 if (local_syms
!= NULL
)
7614 unsigned long r_symndx
;
7615 bfd
*ibfd
= sec
->owner
;
7617 r_symndx
= ELF64_R_SYM (r_info
);
7618 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7622 if ((bfd_link_pic (info
)
7623 && (must_be_dyn_reloc (info
, r_type
)
7625 && (!SYMBOLIC_BIND (info
, h
)
7626 || h
->root
.type
== bfd_link_hash_defweak
7627 || !h
->def_regular
))))
7628 || (ELIMINATE_COPY_RELOCS
7629 && !bfd_link_pic (info
)
7631 && (h
->root
.type
== bfd_link_hash_defweak
7632 || !h
->def_regular
)))
7639 struct elf_dyn_relocs
*p
;
7640 struct elf_dyn_relocs
**pp
;
7641 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
7643 /* elf_gc_sweep may have already removed all dyn relocs associated
7644 with local syms for a given section. Also, symbol flags are
7645 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7646 report a dynreloc miscount. */
7647 if (*pp
== NULL
&& info
->gc_sections
)
7650 while ((p
= *pp
) != NULL
)
7654 if (!must_be_dyn_reloc (info
, r_type
))
7666 struct ppc_dyn_relocs
*p
;
7667 struct ppc_dyn_relocs
**pp
;
7669 bfd_boolean is_ifunc
;
7671 if (local_syms
== NULL
)
7672 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7673 if (sym_sec
== NULL
)
7676 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7677 pp
= (struct ppc_dyn_relocs
**) vpp
;
7679 if (*pp
== NULL
&& info
->gc_sections
)
7682 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7683 while ((p
= *pp
) != NULL
)
7685 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7696 info
->callbacks
->einfo (_("%P: dynreloc miscount for %B, section %A\n"),
7698 bfd_set_error (bfd_error_bad_value
);
7702 /* Remove unused Official Procedure Descriptor entries. Currently we
7703 only remove those associated with functions in discarded link-once
7704 sections, or weakly defined functions that have been overridden. It
7705 would be possible to remove many more entries for statically linked
7709 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7712 bfd_boolean some_edited
= FALSE
;
7713 asection
*need_pad
= NULL
;
7714 struct ppc_link_hash_table
*htab
;
7716 htab
= ppc_hash_table (info
);
7720 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7723 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7724 Elf_Internal_Shdr
*symtab_hdr
;
7725 Elf_Internal_Sym
*local_syms
;
7726 struct _opd_sec_data
*opd
;
7727 bfd_boolean need_edit
, add_aux_fields
, broken
;
7728 bfd_size_type cnt_16b
= 0;
7730 if (!is_ppc64_elf (ibfd
))
7733 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7734 if (sec
== NULL
|| sec
->size
== 0)
7737 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7740 if (sec
->output_section
== bfd_abs_section_ptr
)
7743 /* Look through the section relocs. */
7744 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7748 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7750 /* Read the relocations. */
7751 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7753 if (relstart
== NULL
)
7756 /* First run through the relocs to check they are sane, and to
7757 determine whether we need to edit this opd section. */
7761 relend
= relstart
+ sec
->reloc_count
;
7762 for (rel
= relstart
; rel
< relend
; )
7764 enum elf_ppc64_reloc_type r_type
;
7765 unsigned long r_symndx
;
7767 struct elf_link_hash_entry
*h
;
7768 Elf_Internal_Sym
*sym
;
7771 /* .opd contains an array of 16 or 24 byte entries. We're
7772 only interested in the reloc pointing to a function entry
7774 offset
= rel
->r_offset
;
7775 if (rel
+ 1 == relend
7776 || rel
[1].r_offset
!= offset
+ 8)
7778 /* If someone messes with .opd alignment then after a
7779 "ld -r" we might have padding in the middle of .opd.
7780 Also, there's nothing to prevent someone putting
7781 something silly in .opd with the assembler. No .opd
7782 optimization for them! */
7784 (*_bfd_error_handler
)
7785 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
7790 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7791 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7793 (*_bfd_error_handler
)
7794 (_("%B: unexpected reloc type %u in .opd section"),
7800 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7801 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7805 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7807 const char *sym_name
;
7809 sym_name
= h
->root
.root
.string
;
7811 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7814 (*_bfd_error_handler
)
7815 (_("%B: undefined sym `%s' in .opd section"),
7821 /* opd entries are always for functions defined in the
7822 current input bfd. If the symbol isn't defined in the
7823 input bfd, then we won't be using the function in this
7824 bfd; It must be defined in a linkonce section in another
7825 bfd, or is weak. It's also possible that we are
7826 discarding the function due to a linker script /DISCARD/,
7827 which we test for via the output_section. */
7828 if (sym_sec
->owner
!= ibfd
7829 || sym_sec
->output_section
== bfd_abs_section_ptr
)
7833 if (rel
+ 1 == relend
7834 || (rel
+ 2 < relend
7835 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
7840 if (sec
->size
== offset
+ 24)
7845 if (sec
->size
== offset
+ 16)
7852 else if (rel
+ 1 < relend
7853 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
7854 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
7856 if (rel
[0].r_offset
== offset
+ 16)
7858 else if (rel
[0].r_offset
!= offset
+ 24)
7865 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
7867 if (!broken
&& (need_edit
|| add_aux_fields
))
7869 Elf_Internal_Rela
*write_rel
;
7870 Elf_Internal_Shdr
*rel_hdr
;
7871 bfd_byte
*rptr
, *wptr
;
7872 bfd_byte
*new_contents
;
7875 new_contents
= NULL
;
7876 amt
= OPD_NDX (sec
->size
) * sizeof (long);
7877 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
7878 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
7879 if (opd
->adjust
== NULL
)
7881 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
7883 /* This seems a waste of time as input .opd sections are all
7884 zeros as generated by gcc, but I suppose there's no reason
7885 this will always be so. We might start putting something in
7886 the third word of .opd entries. */
7887 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
7890 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
7895 if (local_syms
!= NULL
7896 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7898 if (elf_section_data (sec
)->relocs
!= relstart
)
7902 sec
->contents
= loc
;
7903 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
7906 elf_section_data (sec
)->relocs
= relstart
;
7908 new_contents
= sec
->contents
;
7911 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
7912 if (new_contents
== NULL
)
7916 wptr
= new_contents
;
7917 rptr
= sec
->contents
;
7918 write_rel
= relstart
;
7919 for (rel
= relstart
; rel
< relend
; )
7921 unsigned long r_symndx
;
7923 struct elf_link_hash_entry
*h
;
7924 struct ppc_link_hash_entry
*fdh
= NULL
;
7925 Elf_Internal_Sym
*sym
;
7927 Elf_Internal_Rela
*next_rel
;
7930 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7931 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7936 if (next_rel
+ 1 == relend
7937 || (next_rel
+ 2 < relend
7938 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
7941 /* See if the .opd entry is full 24 byte or
7942 16 byte (with fd_aux entry overlapped with next
7945 if (next_rel
== relend
)
7947 if (sec
->size
== rel
->r_offset
+ 16)
7950 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
7954 && h
->root
.root
.string
[0] == '.')
7956 fdh
= lookup_fdh ((struct ppc_link_hash_entry
*) h
, htab
);
7958 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
7959 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
7963 skip
= (sym_sec
->owner
!= ibfd
7964 || sym_sec
->output_section
== bfd_abs_section_ptr
);
7967 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
7969 /* Arrange for the function descriptor sym
7971 fdh
->elf
.root
.u
.def
.value
= 0;
7972 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
7974 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
7976 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
7981 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7985 if (++rel
== next_rel
)
7988 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7989 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7996 /* We'll be keeping this opd entry. */
8001 /* Redefine the function descriptor symbol to
8002 this location in the opd section. It is
8003 necessary to update the value here rather
8004 than using an array of adjustments as we do
8005 for local symbols, because various places
8006 in the generic ELF code use the value
8007 stored in u.def.value. */
8008 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
8009 fdh
->adjust_done
= 1;
8012 /* Local syms are a bit tricky. We could
8013 tweak them as they can be cached, but
8014 we'd need to look through the local syms
8015 for the function descriptor sym which we
8016 don't have at the moment. So keep an
8017 array of adjustments. */
8018 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
8019 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
8022 memcpy (wptr
, rptr
, opd_ent_size
);
8023 wptr
+= opd_ent_size
;
8024 if (add_aux_fields
&& opd_ent_size
== 16)
8026 memset (wptr
, '\0', 8);
8030 /* We need to adjust any reloc offsets to point to the
8032 for ( ; rel
!= next_rel
; ++rel
)
8034 rel
->r_offset
+= adjust
;
8035 if (write_rel
!= rel
)
8036 memcpy (write_rel
, rel
, sizeof (*rel
));
8041 rptr
+= opd_ent_size
;
8044 sec
->size
= wptr
- new_contents
;
8045 sec
->reloc_count
= write_rel
- relstart
;
8048 free (sec
->contents
);
8049 sec
->contents
= new_contents
;
8052 /* Fudge the header size too, as this is used later in
8053 elf_bfd_final_link if we are emitting relocs. */
8054 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
8055 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
8058 else if (elf_section_data (sec
)->relocs
!= relstart
)
8061 if (local_syms
!= NULL
8062 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8064 if (!info
->keep_memory
)
8067 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8072 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
8074 /* If we are doing a final link and the last .opd entry is just 16 byte
8075 long, add a 8 byte padding after it. */
8076 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
8080 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
8082 BFD_ASSERT (need_pad
->size
> 0);
8084 p
= bfd_malloc (need_pad
->size
+ 8);
8088 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
8089 p
, 0, need_pad
->size
))
8092 need_pad
->contents
= p
;
8093 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8097 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
8101 need_pad
->contents
= p
;
8104 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
8105 need_pad
->size
+= 8;
8111 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8114 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
8116 struct ppc_link_hash_table
*htab
;
8118 htab
= ppc_hash_table (info
);
8122 if (abiversion (info
->output_bfd
) == 1)
8125 if (htab
->params
->no_multi_toc
)
8126 htab
->do_multi_toc
= 0;
8127 else if (!htab
->do_multi_toc
)
8128 htab
->params
->no_multi_toc
= 1;
8130 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
8131 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
8132 FALSE
, FALSE
, TRUE
));
8133 /* Move dynamic linking info to the function descriptor sym. */
8134 if (htab
->tls_get_addr
!= NULL
)
8135 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
8136 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
8137 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
8138 FALSE
, FALSE
, TRUE
));
8139 if (!htab
->params
->no_tls_get_addr_opt
)
8141 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
8143 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
8144 FALSE
, FALSE
, TRUE
);
8146 func_desc_adjust (opt
, info
);
8147 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
8148 FALSE
, FALSE
, TRUE
);
8150 && (opt_fd
->root
.type
== bfd_link_hash_defined
8151 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8153 /* If glibc supports an optimized __tls_get_addr call stub,
8154 signalled by the presence of __tls_get_addr_opt, and we'll
8155 be calling __tls_get_addr via a plt call stub, then
8156 make __tls_get_addr point to __tls_get_addr_opt. */
8157 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
8158 if (htab
->elf
.dynamic_sections_created
8160 && (tga_fd
->type
== STT_FUNC
8161 || tga_fd
->needs_plt
)
8162 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8163 || (ELF_ST_VISIBILITY (tga_fd
->other
) != STV_DEFAULT
8164 && tga_fd
->root
.type
== bfd_link_hash_undefweak
)))
8166 struct plt_entry
*ent
;
8168 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8169 if (ent
->plt
.refcount
> 0)
8173 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8174 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8175 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8176 if (opt_fd
->dynindx
!= -1)
8178 /* Use __tls_get_addr_opt in dynamic relocations. */
8179 opt_fd
->dynindx
= -1;
8180 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8181 opt_fd
->dynstr_index
);
8182 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8185 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
8186 tga
= &htab
->tls_get_addr
->elf
;
8187 if (opt
!= NULL
&& tga
!= NULL
)
8189 tga
->root
.type
= bfd_link_hash_indirect
;
8190 tga
->root
.u
.i
.link
= &opt
->root
;
8191 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8192 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8194 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
8196 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8197 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8198 if (htab
->tls_get_addr
!= NULL
)
8200 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8201 htab
->tls_get_addr
->is_func
= 1;
8207 htab
->params
->no_tls_get_addr_opt
= TRUE
;
8209 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
8212 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8216 branch_reloc_hash_match (const bfd
*ibfd
,
8217 const Elf_Internal_Rela
*rel
,
8218 const struct ppc_link_hash_entry
*hash1
,
8219 const struct ppc_link_hash_entry
*hash2
)
8221 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8222 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8223 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8225 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8227 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8228 struct elf_link_hash_entry
*h
;
8230 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8231 h
= elf_follow_link (h
);
8232 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
8238 /* Run through all the TLS relocs looking for optimization
8239 opportunities. The linker has been hacked (see ppc64elf.em) to do
8240 a preliminary section layout so that we know the TLS segment
8241 offsets. We can't optimize earlier because some optimizations need
8242 to know the tp offset, and we need to optimize before allocating
8243 dynamic relocations. */
8246 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8250 struct ppc_link_hash_table
*htab
;
8251 unsigned char *toc_ref
;
8254 if (!bfd_link_executable (info
))
8257 htab
= ppc_hash_table (info
);
8261 /* Make two passes over the relocs. On the first pass, mark toc
8262 entries involved with tls relocs, and check that tls relocs
8263 involved in setting up a tls_get_addr call are indeed followed by
8264 such a call. If they are not, we can't do any tls optimization.
8265 On the second pass twiddle tls_mask flags to notify
8266 relocate_section that optimization can be done, and adjust got
8267 and plt refcounts. */
8269 for (pass
= 0; pass
< 2; ++pass
)
8270 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8272 Elf_Internal_Sym
*locsyms
= NULL
;
8273 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8275 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8276 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8278 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8279 bfd_boolean found_tls_get_addr_arg
= 0;
8281 /* Read the relocations. */
8282 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8284 if (relstart
== NULL
)
8290 relend
= relstart
+ sec
->reloc_count
;
8291 for (rel
= relstart
; rel
< relend
; rel
++)
8293 enum elf_ppc64_reloc_type r_type
;
8294 unsigned long r_symndx
;
8295 struct elf_link_hash_entry
*h
;
8296 Elf_Internal_Sym
*sym
;
8298 unsigned char *tls_mask
;
8299 unsigned char tls_set
, tls_clear
, tls_type
= 0;
8301 bfd_boolean ok_tprel
, is_local
;
8302 long toc_ref_index
= 0;
8303 int expecting_tls_get_addr
= 0;
8304 bfd_boolean ret
= FALSE
;
8306 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8307 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8311 if (elf_section_data (sec
)->relocs
!= relstart
)
8313 if (toc_ref
!= NULL
)
8316 && (elf_symtab_hdr (ibfd
).contents
8317 != (unsigned char *) locsyms
))
8324 if (h
->root
.type
== bfd_link_hash_defined
8325 || h
->root
.type
== bfd_link_hash_defweak
)
8326 value
= h
->root
.u
.def
.value
;
8327 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8331 found_tls_get_addr_arg
= 0;
8336 /* Symbols referenced by TLS relocs must be of type
8337 STT_TLS. So no need for .opd local sym adjust. */
8338 value
= sym
->st_value
;
8347 && h
->root
.type
== bfd_link_hash_undefweak
)
8351 value
+= sym_sec
->output_offset
;
8352 value
+= sym_sec
->output_section
->vma
;
8353 value
-= htab
->elf
.tls_sec
->vma
;
8354 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
8355 < (bfd_vma
) 1 << 32);
8359 r_type
= ELF64_R_TYPE (rel
->r_info
);
8360 /* If this section has old-style __tls_get_addr calls
8361 without marker relocs, then check that each
8362 __tls_get_addr call reloc is preceded by a reloc
8363 that conceivably belongs to the __tls_get_addr arg
8364 setup insn. If we don't find matching arg setup
8365 relocs, don't do any tls optimization. */
8367 && sec
->has_tls_get_addr_call
8369 && (h
== &htab
->tls_get_addr
->elf
8370 || h
== &htab
->tls_get_addr_fd
->elf
)
8371 && !found_tls_get_addr_arg
8372 && is_branch_reloc (r_type
))
8374 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8375 "TLS optimization disabled\n"),
8376 ibfd
, sec
, rel
->r_offset
);
8381 found_tls_get_addr_arg
= 0;
8384 case R_PPC64_GOT_TLSLD16
:
8385 case R_PPC64_GOT_TLSLD16_LO
:
8386 expecting_tls_get_addr
= 1;
8387 found_tls_get_addr_arg
= 1;
8390 case R_PPC64_GOT_TLSLD16_HI
:
8391 case R_PPC64_GOT_TLSLD16_HA
:
8392 /* These relocs should never be against a symbol
8393 defined in a shared lib. Leave them alone if
8394 that turns out to be the case. */
8401 tls_type
= TLS_TLS
| TLS_LD
;
8404 case R_PPC64_GOT_TLSGD16
:
8405 case R_PPC64_GOT_TLSGD16_LO
:
8406 expecting_tls_get_addr
= 1;
8407 found_tls_get_addr_arg
= 1;
8410 case R_PPC64_GOT_TLSGD16_HI
:
8411 case R_PPC64_GOT_TLSGD16_HA
:
8417 tls_set
= TLS_TLS
| TLS_TPRELGD
;
8419 tls_type
= TLS_TLS
| TLS_GD
;
8422 case R_PPC64_GOT_TPREL16_DS
:
8423 case R_PPC64_GOT_TPREL16_LO_DS
:
8424 case R_PPC64_GOT_TPREL16_HI
:
8425 case R_PPC64_GOT_TPREL16_HA
:
8430 tls_clear
= TLS_TPREL
;
8431 tls_type
= TLS_TLS
| TLS_TPREL
;
8438 found_tls_get_addr_arg
= 1;
8443 case R_PPC64_TOC16_LO
:
8444 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8447 /* Mark this toc entry as referenced by a TLS
8448 code sequence. We can do that now in the
8449 case of R_PPC64_TLS, and after checking for
8450 tls_get_addr for the TOC16 relocs. */
8451 if (toc_ref
== NULL
)
8452 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8453 if (toc_ref
== NULL
)
8457 value
= h
->root
.u
.def
.value
;
8459 value
= sym
->st_value
;
8460 value
+= rel
->r_addend
;
8463 BFD_ASSERT (value
< toc
->size
8464 && toc
->output_offset
% 8 == 0);
8465 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8466 if (r_type
== R_PPC64_TLS
8467 || r_type
== R_PPC64_TLSGD
8468 || r_type
== R_PPC64_TLSLD
)
8470 toc_ref
[toc_ref_index
] = 1;
8474 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8479 expecting_tls_get_addr
= 2;
8482 case R_PPC64_TPREL64
:
8486 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8491 tls_set
= TLS_EXPLICIT
;
8492 tls_clear
= TLS_TPREL
;
8497 case R_PPC64_DTPMOD64
:
8501 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8503 if (rel
+ 1 < relend
8505 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8506 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8510 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8513 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
8522 tls_set
= TLS_EXPLICIT
;
8533 if (!expecting_tls_get_addr
8534 || !sec
->has_tls_get_addr_call
)
8537 if (rel
+ 1 < relend
8538 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8540 htab
->tls_get_addr_fd
))
8542 if (expecting_tls_get_addr
== 2)
8544 /* Check for toc tls entries. */
8545 unsigned char *toc_tls
;
8548 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8553 if (toc_tls
!= NULL
)
8555 if ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0)
8556 found_tls_get_addr_arg
= 1;
8558 toc_ref
[toc_ref_index
] = 1;
8564 if (expecting_tls_get_addr
!= 1)
8567 /* Uh oh, we didn't find the expected call. We
8568 could just mark this symbol to exclude it
8569 from tls optimization but it's safer to skip
8570 the entire optimization. */
8571 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8572 "TLS optimization disabled\n"),
8573 ibfd
, sec
, rel
->r_offset
);
8578 if (expecting_tls_get_addr
&& htab
->tls_get_addr
!= NULL
)
8580 struct plt_entry
*ent
;
8581 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8584 if (ent
->addend
== 0)
8586 if (ent
->plt
.refcount
> 0)
8588 ent
->plt
.refcount
-= 1;
8589 expecting_tls_get_addr
= 0;
8595 if (expecting_tls_get_addr
&& htab
->tls_get_addr_fd
!= NULL
)
8597 struct plt_entry
*ent
;
8598 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8601 if (ent
->addend
== 0)
8603 if (ent
->plt
.refcount
> 0)
8604 ent
->plt
.refcount
-= 1;
8612 if ((tls_set
& TLS_EXPLICIT
) == 0)
8614 struct got_entry
*ent
;
8616 /* Adjust got entry for this reloc. */
8620 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
8622 for (; ent
!= NULL
; ent
= ent
->next
)
8623 if (ent
->addend
== rel
->r_addend
8624 && ent
->owner
== ibfd
8625 && ent
->tls_type
== tls_type
)
8632 /* We managed to get rid of a got entry. */
8633 if (ent
->got
.refcount
> 0)
8634 ent
->got
.refcount
-= 1;
8639 /* If we got rid of a DTPMOD/DTPREL reloc pair then
8640 we'll lose one or two dyn relocs. */
8641 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8645 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
8647 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
8653 *tls_mask
|= tls_set
;
8654 *tls_mask
&= ~tls_clear
;
8657 if (elf_section_data (sec
)->relocs
!= relstart
)
8662 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
8664 if (!info
->keep_memory
)
8667 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
8671 if (toc_ref
!= NULL
)
8676 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
8677 the values of any global symbols in a toc section that has been
8678 edited. Globals in toc sections should be a rarity, so this function
8679 sets a flag if any are found in toc sections other than the one just
8680 edited, so that futher hash table traversals can be avoided. */
8682 struct adjust_toc_info
8685 unsigned long *skip
;
8686 bfd_boolean global_toc_syms
;
8689 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
8692 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
8694 struct ppc_link_hash_entry
*eh
;
8695 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
8698 if (h
->root
.type
!= bfd_link_hash_defined
8699 && h
->root
.type
!= bfd_link_hash_defweak
)
8702 eh
= (struct ppc_link_hash_entry
*) h
;
8703 if (eh
->adjust_done
)
8706 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
8708 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
8709 i
= toc_inf
->toc
->rawsize
>> 3;
8711 i
= eh
->elf
.root
.u
.def
.value
>> 3;
8713 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
8715 (*_bfd_error_handler
)
8716 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
8719 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
8720 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
8723 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
8724 eh
->adjust_done
= 1;
8726 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
8727 toc_inf
->global_toc_syms
= TRUE
;
8732 /* Return TRUE iff INSN is one we expect on a _LO variety toc/got reloc. */
8735 ok_lo_toc_insn (unsigned int insn
)
8737 return ((insn
& (0x3f << 26)) == 14u << 26 /* addi */
8738 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
8739 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
8740 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
8741 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
8742 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
8743 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
8744 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
8745 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
8746 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
8747 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
8748 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
8749 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
8750 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
8751 || ((insn
& (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
8753 || ((insn
& (0x3f << 26)) == 62u << 26 /* std, stmd */
8754 && ((insn
& 3) == 0 || (insn
& 3) == 3))
8755 || (insn
& (0x3f << 26)) == 12u << 26 /* addic */);
8758 /* Examine all relocs referencing .toc sections in order to remove
8759 unused .toc entries. */
8762 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
8765 struct adjust_toc_info toc_inf
;
8766 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8768 htab
->do_toc_opt
= 1;
8769 toc_inf
.global_toc_syms
= TRUE
;
8770 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8772 asection
*toc
, *sec
;
8773 Elf_Internal_Shdr
*symtab_hdr
;
8774 Elf_Internal_Sym
*local_syms
;
8775 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
8776 unsigned long *skip
, *drop
;
8777 unsigned char *used
;
8778 unsigned char *keep
, last
, some_unused
;
8780 if (!is_ppc64_elf (ibfd
))
8783 toc
= bfd_get_section_by_name (ibfd
, ".toc");
8786 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
8787 || discarded_section (toc
))
8792 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8794 /* Look at sections dropped from the final link. */
8797 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8799 if (sec
->reloc_count
== 0
8800 || !discarded_section (sec
)
8801 || get_opd_info (sec
)
8802 || (sec
->flags
& SEC_ALLOC
) == 0
8803 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8806 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
8807 if (relstart
== NULL
)
8810 /* Run through the relocs to see which toc entries might be
8812 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
8814 enum elf_ppc64_reloc_type r_type
;
8815 unsigned long r_symndx
;
8817 struct elf_link_hash_entry
*h
;
8818 Elf_Internal_Sym
*sym
;
8821 r_type
= ELF64_R_TYPE (rel
->r_info
);
8828 case R_PPC64_TOC16_LO
:
8829 case R_PPC64_TOC16_HI
:
8830 case R_PPC64_TOC16_HA
:
8831 case R_PPC64_TOC16_DS
:
8832 case R_PPC64_TOC16_LO_DS
:
8836 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8837 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8845 val
= h
->root
.u
.def
.value
;
8847 val
= sym
->st_value
;
8848 val
+= rel
->r_addend
;
8850 if (val
>= toc
->size
)
8853 /* Anything in the toc ought to be aligned to 8 bytes.
8854 If not, don't mark as unused. */
8860 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8865 skip
[val
>> 3] = ref_from_discarded
;
8868 if (elf_section_data (sec
)->relocs
!= relstart
)
8872 /* For largetoc loads of address constants, we can convert
8873 . addis rx,2,addr@got@ha
8874 . ld ry,addr@got@l(rx)
8876 . addis rx,2,addr@toc@ha
8877 . addi ry,rx,addr@toc@l
8878 when addr is within 2G of the toc pointer. This then means
8879 that the word storing "addr" in the toc is no longer needed. */
8881 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
8882 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
8883 && toc
->reloc_count
!= 0)
8885 /* Read toc relocs. */
8886 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
8888 if (toc_relocs
== NULL
)
8891 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
8893 enum elf_ppc64_reloc_type r_type
;
8894 unsigned long r_symndx
;
8896 struct elf_link_hash_entry
*h
;
8897 Elf_Internal_Sym
*sym
;
8900 r_type
= ELF64_R_TYPE (rel
->r_info
);
8901 if (r_type
!= R_PPC64_ADDR64
)
8904 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8905 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8910 || discarded_section (sym_sec
))
8913 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8918 if (h
->type
== STT_GNU_IFUNC
)
8920 val
= h
->root
.u
.def
.value
;
8924 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
8926 val
= sym
->st_value
;
8928 val
+= rel
->r_addend
;
8929 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
8931 /* We don't yet know the exact toc pointer value, but we
8932 know it will be somewhere in the toc section. Don't
8933 optimize if the difference from any possible toc
8934 pointer is outside [ff..f80008000, 7fff7fff]. */
8935 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
8936 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8939 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
8940 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
8945 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
8950 skip
[rel
->r_offset
>> 3]
8951 |= can_optimize
| ((rel
- toc_relocs
) << 2);
8958 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
8962 if (local_syms
!= NULL
8963 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8967 && elf_section_data (sec
)->relocs
!= relstart
)
8969 if (toc_relocs
!= NULL
8970 && elf_section_data (toc
)->relocs
!= toc_relocs
)
8977 /* Now check all kept sections that might reference the toc.
8978 Check the toc itself last. */
8979 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
8982 sec
= (sec
== toc
? NULL
8983 : sec
->next
== NULL
? toc
8984 : sec
->next
== toc
&& toc
->next
? toc
->next
8989 if (sec
->reloc_count
== 0
8990 || discarded_section (sec
)
8991 || get_opd_info (sec
)
8992 || (sec
->flags
& SEC_ALLOC
) == 0
8993 || (sec
->flags
& SEC_DEBUGGING
) != 0)
8996 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8998 if (relstart
== NULL
)
9004 /* Mark toc entries referenced as used. */
9008 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9010 enum elf_ppc64_reloc_type r_type
;
9011 unsigned long r_symndx
;
9013 struct elf_link_hash_entry
*h
;
9014 Elf_Internal_Sym
*sym
;
9016 enum {no_check
, check_lo
, check_ha
} insn_check
;
9018 r_type
= ELF64_R_TYPE (rel
->r_info
);
9022 insn_check
= no_check
;
9025 case R_PPC64_GOT_TLSLD16_HA
:
9026 case R_PPC64_GOT_TLSGD16_HA
:
9027 case R_PPC64_GOT_TPREL16_HA
:
9028 case R_PPC64_GOT_DTPREL16_HA
:
9029 case R_PPC64_GOT16_HA
:
9030 case R_PPC64_TOC16_HA
:
9031 insn_check
= check_ha
;
9034 case R_PPC64_GOT_TLSLD16_LO
:
9035 case R_PPC64_GOT_TLSGD16_LO
:
9036 case R_PPC64_GOT_TPREL16_LO_DS
:
9037 case R_PPC64_GOT_DTPREL16_LO_DS
:
9038 case R_PPC64_GOT16_LO
:
9039 case R_PPC64_GOT16_LO_DS
:
9040 case R_PPC64_TOC16_LO
:
9041 case R_PPC64_TOC16_LO_DS
:
9042 insn_check
= check_lo
;
9046 if (insn_check
!= no_check
)
9048 bfd_vma off
= rel
->r_offset
& ~3;
9049 unsigned char buf
[4];
9052 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9057 insn
= bfd_get_32 (ibfd
, buf
);
9058 if (insn_check
== check_lo
9059 ? !ok_lo_toc_insn (insn
)
9060 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9061 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9065 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9066 sprintf (str
, "%#08x", insn
);
9067 info
->callbacks
->einfo
9068 (_("%P: %H: toc optimization is not supported for"
9069 " %s instruction.\n"),
9070 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9077 case R_PPC64_TOC16_LO
:
9078 case R_PPC64_TOC16_HI
:
9079 case R_PPC64_TOC16_HA
:
9080 case R_PPC64_TOC16_DS
:
9081 case R_PPC64_TOC16_LO_DS
:
9082 /* In case we're taking addresses of toc entries. */
9083 case R_PPC64_ADDR64
:
9090 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9091 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9102 val
= h
->root
.u
.def
.value
;
9104 val
= sym
->st_value
;
9105 val
+= rel
->r_addend
;
9107 if (val
>= toc
->size
)
9110 if ((skip
[val
>> 3] & can_optimize
) != 0)
9117 case R_PPC64_TOC16_HA
:
9120 case R_PPC64_TOC16_LO_DS
:
9121 off
= rel
->r_offset
;
9122 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9123 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9129 if ((opc
& (0x3f << 2)) == (58u << 2))
9134 /* Wrong sort of reloc, or not a ld. We may
9135 as well clear ref_from_discarded too. */
9142 /* For the toc section, we only mark as used if this
9143 entry itself isn't unused. */
9144 else if ((used
[rel
->r_offset
>> 3]
9145 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9148 /* Do all the relocs again, to catch reference
9157 if (elf_section_data (sec
)->relocs
!= relstart
)
9161 /* Merge the used and skip arrays. Assume that TOC
9162 doublewords not appearing as either used or unused belong
9163 to to an entry more than one doubleword in size. */
9164 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9165 drop
< skip
+ (toc
->size
+ 7) / 8;
9170 *drop
&= ~ref_from_discarded
;
9171 if ((*drop
& can_optimize
) != 0)
9175 else if ((*drop
& ref_from_discarded
) != 0)
9178 last
= ref_from_discarded
;
9188 bfd_byte
*contents
, *src
;
9190 Elf_Internal_Sym
*sym
;
9191 bfd_boolean local_toc_syms
= FALSE
;
9193 /* Shuffle the toc contents, and at the same time convert the
9194 skip array from booleans into offsets. */
9195 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9198 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9200 for (src
= contents
, off
= 0, drop
= skip
;
9201 src
< contents
+ toc
->size
;
9204 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9209 memcpy (src
- off
, src
, 8);
9213 toc
->rawsize
= toc
->size
;
9214 toc
->size
= src
- contents
- off
;
9216 /* Adjust addends for relocs against the toc section sym,
9217 and optimize any accesses we can. */
9218 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9220 if (sec
->reloc_count
== 0
9221 || discarded_section (sec
))
9224 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9226 if (relstart
== NULL
)
9229 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9231 enum elf_ppc64_reloc_type r_type
;
9232 unsigned long r_symndx
;
9234 struct elf_link_hash_entry
*h
;
9237 r_type
= ELF64_R_TYPE (rel
->r_info
);
9244 case R_PPC64_TOC16_LO
:
9245 case R_PPC64_TOC16_HI
:
9246 case R_PPC64_TOC16_HA
:
9247 case R_PPC64_TOC16_DS
:
9248 case R_PPC64_TOC16_LO_DS
:
9249 case R_PPC64_ADDR64
:
9253 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9254 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9262 val
= h
->root
.u
.def
.value
;
9265 val
= sym
->st_value
;
9267 local_toc_syms
= TRUE
;
9270 val
+= rel
->r_addend
;
9272 if (val
> toc
->rawsize
)
9274 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9276 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9278 Elf_Internal_Rela
*tocrel
9279 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9280 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9284 case R_PPC64_TOC16_HA
:
9285 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9288 case R_PPC64_TOC16_LO_DS
:
9289 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9293 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9295 info
->callbacks
->einfo
9296 (_("%P: %H: %s references "
9297 "optimized away TOC entry\n"),
9298 ibfd
, sec
, rel
->r_offset
,
9299 ppc64_elf_howto_table
[r_type
]->name
);
9300 bfd_set_error (bfd_error_bad_value
);
9303 rel
->r_addend
= tocrel
->r_addend
;
9304 elf_section_data (sec
)->relocs
= relstart
;
9308 if (h
!= NULL
|| sym
->st_value
!= 0)
9311 rel
->r_addend
-= skip
[val
>> 3];
9312 elf_section_data (sec
)->relocs
= relstart
;
9315 if (elf_section_data (sec
)->relocs
!= relstart
)
9319 /* We shouldn't have local or global symbols defined in the TOC,
9320 but handle them anyway. */
9321 if (local_syms
!= NULL
)
9322 for (sym
= local_syms
;
9323 sym
< local_syms
+ symtab_hdr
->sh_info
;
9325 if (sym
->st_value
!= 0
9326 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9330 if (sym
->st_value
> toc
->rawsize
)
9331 i
= toc
->rawsize
>> 3;
9333 i
= sym
->st_value
>> 3;
9335 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9338 (*_bfd_error_handler
)
9339 (_("%s defined on removed toc entry"),
9340 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9343 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9344 sym
->st_value
= (bfd_vma
) i
<< 3;
9347 sym
->st_value
-= skip
[i
];
9348 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9351 /* Adjust any global syms defined in this toc input section. */
9352 if (toc_inf
.global_toc_syms
)
9355 toc_inf
.skip
= skip
;
9356 toc_inf
.global_toc_syms
= FALSE
;
9357 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9361 if (toc
->reloc_count
!= 0)
9363 Elf_Internal_Shdr
*rel_hdr
;
9364 Elf_Internal_Rela
*wrel
;
9367 /* Remove unused toc relocs, and adjust those we keep. */
9368 if (toc_relocs
== NULL
)
9369 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9371 if (toc_relocs
== NULL
)
9375 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9376 if ((skip
[rel
->r_offset
>> 3]
9377 & (ref_from_discarded
| can_optimize
)) == 0)
9379 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9380 wrel
->r_info
= rel
->r_info
;
9381 wrel
->r_addend
= rel
->r_addend
;
9384 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9385 &local_syms
, NULL
, NULL
))
9388 elf_section_data (toc
)->relocs
= toc_relocs
;
9389 toc
->reloc_count
= wrel
- toc_relocs
;
9390 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9391 sz
= rel_hdr
->sh_entsize
;
9392 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9395 else if (toc_relocs
!= NULL
9396 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9399 if (local_syms
!= NULL
9400 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9402 if (!info
->keep_memory
)
9405 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9413 /* Return true iff input section I references the TOC using
9414 instructions limited to +/-32k offsets. */
9417 ppc64_elf_has_small_toc_reloc (asection
*i
)
9419 return (is_ppc64_elf (i
->owner
)
9420 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9423 /* Allocate space for one GOT entry. */
9426 allocate_got (struct elf_link_hash_entry
*h
,
9427 struct bfd_link_info
*info
,
9428 struct got_entry
*gent
)
9430 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9432 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
9433 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9435 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9436 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9437 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9439 gent
->got
.offset
= got
->size
;
9440 got
->size
+= entsize
;
9442 dyn
= htab
->elf
.dynamic_sections_created
;
9443 if (h
->type
== STT_GNU_IFUNC
)
9445 htab
->elf
.irelplt
->size
+= rentsize
;
9446 htab
->got_reli_size
+= rentsize
;
9448 else if ((bfd_link_pic (info
)
9449 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
9450 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
9451 || h
->root
.type
!= bfd_link_hash_undefweak
))
9453 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9454 relgot
->size
+= rentsize
;
9458 /* This function merges got entries in the same toc group. */
9461 merge_got_entries (struct got_entry
**pent
)
9463 struct got_entry
*ent
, *ent2
;
9465 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9466 if (!ent
->is_indirect
)
9467 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9468 if (!ent2
->is_indirect
9469 && ent2
->addend
== ent
->addend
9470 && ent2
->tls_type
== ent
->tls_type
9471 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9473 ent2
->is_indirect
= TRUE
;
9474 ent2
->got
.ent
= ent
;
9478 /* Allocate space in .plt, .got and associated reloc sections for
9482 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9484 struct bfd_link_info
*info
;
9485 struct ppc_link_hash_table
*htab
;
9487 struct ppc_link_hash_entry
*eh
;
9488 struct elf_dyn_relocs
*p
;
9489 struct got_entry
**pgent
, *gent
;
9491 if (h
->root
.type
== bfd_link_hash_indirect
)
9494 info
= (struct bfd_link_info
*) inf
;
9495 htab
= ppc_hash_table (info
);
9499 if ((htab
->elf
.dynamic_sections_created
9501 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info
), h
))
9502 || h
->type
== STT_GNU_IFUNC
)
9504 struct plt_entry
*pent
;
9505 bfd_boolean doneone
= FALSE
;
9506 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9507 if (pent
->plt
.refcount
> 0)
9509 if (!htab
->elf
.dynamic_sections_created
9510 || h
->dynindx
== -1)
9513 pent
->plt
.offset
= s
->size
;
9514 s
->size
+= PLT_ENTRY_SIZE (htab
);
9515 s
= htab
->elf
.irelplt
;
9519 /* If this is the first .plt entry, make room for the special
9523 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
9525 pent
->plt
.offset
= s
->size
;
9527 /* Make room for this entry. */
9528 s
->size
+= PLT_ENTRY_SIZE (htab
);
9530 /* Make room for the .glink code. */
9533 s
->size
+= GLINK_CALL_STUB_SIZE
;
9536 /* We need bigger stubs past index 32767. */
9537 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
9544 /* We also need to make an entry in the .rela.plt section. */
9545 s
= htab
->elf
.srelplt
;
9547 s
->size
+= sizeof (Elf64_External_Rela
);
9551 pent
->plt
.offset
= (bfd_vma
) -1;
9554 h
->plt
.plist
= NULL
;
9560 h
->plt
.plist
= NULL
;
9564 eh
= (struct ppc_link_hash_entry
*) h
;
9565 /* Run through the TLS GD got entries first if we're changing them
9567 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
9568 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9569 if (gent
->got
.refcount
> 0
9570 && (gent
->tls_type
& TLS_GD
) != 0)
9572 /* This was a GD entry that has been converted to TPREL. If
9573 there happens to be a TPREL entry we can use that one. */
9574 struct got_entry
*ent
;
9575 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9576 if (ent
->got
.refcount
> 0
9577 && (ent
->tls_type
& TLS_TPREL
) != 0
9578 && ent
->addend
== gent
->addend
9579 && ent
->owner
== gent
->owner
)
9581 gent
->got
.refcount
= 0;
9585 /* If not, then we'll be using our own TPREL entry. */
9586 if (gent
->got
.refcount
!= 0)
9587 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9590 /* Remove any list entry that won't generate a word in the GOT before
9591 we call merge_got_entries. Otherwise we risk merging to empty
9593 pgent
= &h
->got
.glist
;
9594 while ((gent
= *pgent
) != NULL
)
9595 if (gent
->got
.refcount
> 0)
9597 if ((gent
->tls_type
& TLS_LD
) != 0
9600 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9601 *pgent
= gent
->next
;
9604 pgent
= &gent
->next
;
9607 *pgent
= gent
->next
;
9609 if (!htab
->do_multi_toc
)
9610 merge_got_entries (&h
->got
.glist
);
9612 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9613 if (!gent
->is_indirect
)
9615 /* Make sure this symbol is output as a dynamic symbol.
9616 Undefined weak syms won't yet be marked as dynamic,
9617 nor will all TLS symbols. */
9618 if (h
->dynindx
== -1
9620 && h
->type
!= STT_GNU_IFUNC
9621 && htab
->elf
.dynamic_sections_created
)
9623 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9627 if (!is_ppc64_elf (gent
->owner
))
9630 allocate_got (h
, info
, gent
);
9633 if (eh
->dyn_relocs
== NULL
9634 || (!htab
->elf
.dynamic_sections_created
9635 && h
->type
!= STT_GNU_IFUNC
))
9638 /* In the shared -Bsymbolic case, discard space allocated for
9639 dynamic pc-relative relocs against symbols which turn out to be
9640 defined in regular objects. For the normal shared case, discard
9641 space for relocs that have become local due to symbol visibility
9644 if (bfd_link_pic (info
))
9646 /* Relocs that use pc_count are those that appear on a call insn,
9647 or certain REL relocs (see must_be_dyn_reloc) that can be
9648 generated via assembly. We want calls to protected symbols to
9649 resolve directly to the function rather than going via the plt.
9650 If people want function pointer comparisons to work as expected
9651 then they should avoid writing weird assembly. */
9652 if (SYMBOL_CALLS_LOCAL (info
, h
))
9654 struct elf_dyn_relocs
**pp
;
9656 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
9658 p
->count
-= p
->pc_count
;
9667 /* Also discard relocs on undefined weak syms with non-default
9669 if (eh
->dyn_relocs
!= NULL
9670 && h
->root
.type
== bfd_link_hash_undefweak
)
9672 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
9673 eh
->dyn_relocs
= NULL
;
9675 /* Make sure this symbol is output as a dynamic symbol.
9676 Undefined weak syms won't yet be marked as dynamic. */
9677 else if (h
->dynindx
== -1
9678 && !h
->forced_local
)
9680 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9685 else if (h
->type
== STT_GNU_IFUNC
)
9687 if (!h
->non_got_ref
)
9688 eh
->dyn_relocs
= NULL
;
9690 else if (ELIMINATE_COPY_RELOCS
)
9692 /* For the non-shared case, discard space for relocs against
9693 symbols which turn out to need copy relocs or are not
9699 /* Make sure this symbol is output as a dynamic symbol.
9700 Undefined weak syms won't yet be marked as dynamic. */
9701 if (h
->dynindx
== -1
9702 && !h
->forced_local
)
9704 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
9708 /* If that succeeded, we know we'll be keeping all the
9710 if (h
->dynindx
!= -1)
9714 eh
->dyn_relocs
= NULL
;
9719 /* Finally, allocate space. */
9720 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
9722 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
9723 if (eh
->elf
.type
== STT_GNU_IFUNC
)
9724 sreloc
= htab
->elf
.irelplt
;
9725 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9731 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
9732 to set up space for global entry stubs. These are put in glink,
9733 after the branch table. */
9736 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
9738 struct bfd_link_info
*info
;
9739 struct ppc_link_hash_table
*htab
;
9740 struct plt_entry
*pent
;
9743 if (h
->root
.type
== bfd_link_hash_indirect
)
9746 if (!h
->pointer_equality_needed
)
9753 htab
= ppc_hash_table (info
);
9758 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
9759 if (pent
->plt
.offset
!= (bfd_vma
) -1
9760 && pent
->addend
== 0)
9762 /* For ELFv2, if this symbol is not defined in a regular file
9763 and we are not generating a shared library or pie, then we
9764 need to define the symbol in the executable on a call stub.
9765 This is to avoid text relocations. */
9766 s
->size
= (s
->size
+ 15) & -16;
9767 h
->root
.u
.def
.section
= s
;
9768 h
->root
.u
.def
.value
= s
->size
;
9775 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
9776 read-only sections. */
9779 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *info
)
9781 if (h
->root
.type
== bfd_link_hash_indirect
)
9784 if (readonly_dynrelocs (h
))
9786 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
9788 /* Not an error, just cut short the traversal. */
9794 /* Set the sizes of the dynamic sections. */
9797 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
9798 struct bfd_link_info
*info
)
9800 struct ppc_link_hash_table
*htab
;
9805 struct got_entry
*first_tlsld
;
9807 htab
= ppc_hash_table (info
);
9811 dynobj
= htab
->elf
.dynobj
;
9815 if (htab
->elf
.dynamic_sections_created
)
9817 /* Set the contents of the .interp section to the interpreter. */
9818 if (bfd_link_executable (info
))
9820 s
= bfd_get_linker_section (dynobj
, ".interp");
9823 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
9824 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
9828 /* Set up .got offsets for local syms, and space for local dynamic
9830 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9832 struct got_entry
**lgot_ents
;
9833 struct got_entry
**end_lgot_ents
;
9834 struct plt_entry
**local_plt
;
9835 struct plt_entry
**end_local_plt
;
9836 unsigned char *lgot_masks
;
9837 bfd_size_type locsymcount
;
9838 Elf_Internal_Shdr
*symtab_hdr
;
9840 if (!is_ppc64_elf (ibfd
))
9843 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
9845 struct ppc_dyn_relocs
*p
;
9847 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
9849 if (!bfd_is_abs_section (p
->sec
)
9850 && bfd_is_abs_section (p
->sec
->output_section
))
9852 /* Input section has been discarded, either because
9853 it is a copy of a linkonce section or due to
9854 linker script /DISCARD/, so we'll be discarding
9857 else if (p
->count
!= 0)
9859 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
9861 srel
= htab
->elf
.irelplt
;
9862 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
9863 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
9864 info
->flags
|= DF_TEXTREL
;
9869 lgot_ents
= elf_local_got_ents (ibfd
);
9873 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9874 locsymcount
= symtab_hdr
->sh_info
;
9875 end_lgot_ents
= lgot_ents
+ locsymcount
;
9876 local_plt
= (struct plt_entry
**) end_lgot_ents
;
9877 end_local_plt
= local_plt
+ locsymcount
;
9878 lgot_masks
= (unsigned char *) end_local_plt
;
9879 s
= ppc64_elf_tdata (ibfd
)->got
;
9880 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
9882 struct got_entry
**pent
, *ent
;
9885 while ((ent
= *pent
) != NULL
)
9886 if (ent
->got
.refcount
> 0)
9888 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
9890 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
9895 unsigned int ent_size
= 8;
9896 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
9898 ent
->got
.offset
= s
->size
;
9899 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
9904 s
->size
+= ent_size
;
9905 if ((*lgot_masks
& PLT_IFUNC
) != 0)
9907 htab
->elf
.irelplt
->size
+= rel_size
;
9908 htab
->got_reli_size
+= rel_size
;
9910 else if (bfd_link_pic (info
))
9912 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9913 srel
->size
+= rel_size
;
9922 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
9923 for (; local_plt
< end_local_plt
; ++local_plt
)
9925 struct plt_entry
*ent
;
9927 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
9928 if (ent
->plt
.refcount
> 0)
9931 ent
->plt
.offset
= s
->size
;
9932 s
->size
+= PLT_ENTRY_SIZE (htab
);
9934 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
9937 ent
->plt
.offset
= (bfd_vma
) -1;
9941 /* Allocate global sym .plt and .got entries, and space for global
9942 sym dynamic relocs. */
9943 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
9944 /* Stash the end of glink branch table. */
9945 if (htab
->glink
!= NULL
)
9946 htab
->glink
->rawsize
= htab
->glink
->size
;
9948 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
9949 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
9952 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9954 struct got_entry
*ent
;
9956 if (!is_ppc64_elf (ibfd
))
9959 ent
= ppc64_tlsld_got (ibfd
);
9960 if (ent
->got
.refcount
> 0)
9962 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
9964 ent
->is_indirect
= TRUE
;
9965 ent
->got
.ent
= first_tlsld
;
9969 if (first_tlsld
== NULL
)
9971 s
= ppc64_elf_tdata (ibfd
)->got
;
9972 ent
->got
.offset
= s
->size
;
9975 if (bfd_link_pic (info
))
9977 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
9978 srel
->size
+= sizeof (Elf64_External_Rela
);
9983 ent
->got
.offset
= (bfd_vma
) -1;
9986 /* We now have determined the sizes of the various dynamic sections.
9987 Allocate memory for them. */
9989 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
9991 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
9994 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
9995 /* These haven't been allocated yet; don't strip. */
9997 else if (s
== htab
->elf
.sgot
9998 || s
== htab
->elf
.splt
9999 || s
== htab
->elf
.iplt
10000 || s
== htab
->glink
10001 || s
== htab
->dynbss
)
10003 /* Strip this section if we don't need it; see the
10006 else if (s
== htab
->glink_eh_frame
)
10008 if (!bfd_is_abs_section (s
->output_section
))
10009 /* Not sized yet. */
10012 else if (CONST_STRNEQ (s
->name
, ".rela"))
10016 if (s
!= htab
->elf
.srelplt
)
10019 /* We use the reloc_count field as a counter if we need
10020 to copy relocs into the output file. */
10021 s
->reloc_count
= 0;
10026 /* It's not one of our sections, so don't allocate space. */
10032 /* If we don't need this section, strip it from the
10033 output file. This is mostly to handle .rela.bss and
10034 .rela.plt. We must create both sections in
10035 create_dynamic_sections, because they must be created
10036 before the linker maps input sections to output
10037 sections. The linker does that before
10038 adjust_dynamic_symbol is called, and it is that
10039 function which decides whether anything needs to go
10040 into these sections. */
10041 s
->flags
|= SEC_EXCLUDE
;
10045 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10048 /* Allocate memory for the section contents. We use bfd_zalloc
10049 here in case unused entries are not reclaimed before the
10050 section's contents are written out. This should not happen,
10051 but this way if it does we get a R_PPC64_NONE reloc in .rela
10052 sections instead of garbage.
10053 We also rely on the section contents being zero when writing
10055 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10056 if (s
->contents
== NULL
)
10060 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10062 if (!is_ppc64_elf (ibfd
))
10065 s
= ppc64_elf_tdata (ibfd
)->got
;
10066 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10069 s
->flags
|= SEC_EXCLUDE
;
10072 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10073 if (s
->contents
== NULL
)
10077 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10081 s
->flags
|= SEC_EXCLUDE
;
10084 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10085 if (s
->contents
== NULL
)
10088 s
->reloc_count
= 0;
10093 if (htab
->elf
.dynamic_sections_created
)
10095 bfd_boolean tls_opt
;
10097 /* Add some entries to the .dynamic section. We fill in the
10098 values later, in ppc64_elf_finish_dynamic_sections, but we
10099 must add the entries now so that we get the correct size for
10100 the .dynamic section. The DT_DEBUG entry is filled in by the
10101 dynamic linker and used by the debugger. */
10102 #define add_dynamic_entry(TAG, VAL) \
10103 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10105 if (bfd_link_executable (info
))
10107 if (!add_dynamic_entry (DT_DEBUG
, 0))
10111 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10113 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10114 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10115 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10116 || !add_dynamic_entry (DT_JMPREL
, 0)
10117 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10121 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10123 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10124 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10128 tls_opt
= (!htab
->params
->no_tls_get_addr_opt
10129 && htab
->tls_get_addr_fd
!= NULL
10130 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
10131 if (tls_opt
|| !htab
->opd_abi
)
10133 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10139 if (!add_dynamic_entry (DT_RELA
, 0)
10140 || !add_dynamic_entry (DT_RELASZ
, 0)
10141 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10144 /* If any dynamic relocs apply to a read-only section,
10145 then we need a DT_TEXTREL entry. */
10146 if ((info
->flags
& DF_TEXTREL
) == 0)
10147 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
10149 if ((info
->flags
& DF_TEXTREL
) != 0)
10151 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10156 #undef add_dynamic_entry
10161 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10164 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10166 if (h
->plt
.plist
!= NULL
10168 && !h
->pointer_equality_needed
)
10171 return _bfd_elf_hash_symbol (h
);
10174 /* Determine the type of stub needed, if any, for a call. */
10176 static inline enum ppc_stub_type
10177 ppc_type_of_stub (asection
*input_sec
,
10178 const Elf_Internal_Rela
*rel
,
10179 struct ppc_link_hash_entry
**hash
,
10180 struct plt_entry
**plt_ent
,
10181 bfd_vma destination
,
10182 unsigned long local_off
)
10184 struct ppc_link_hash_entry
*h
= *hash
;
10186 bfd_vma branch_offset
;
10187 bfd_vma max_branch_offset
;
10188 enum elf_ppc64_reloc_type r_type
;
10192 struct plt_entry
*ent
;
10193 struct ppc_link_hash_entry
*fdh
= h
;
10195 && h
->oh
->is_func_descriptor
)
10197 fdh
= ppc_follow_link (h
->oh
);
10201 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10202 if (ent
->addend
== rel
->r_addend
10203 && ent
->plt
.offset
!= (bfd_vma
) -1)
10206 return ppc_stub_plt_call
;
10209 /* Here, we know we don't have a plt entry. If we don't have a
10210 either a defined function descriptor or a defined entry symbol
10211 in a regular object file, then it is pointless trying to make
10212 any other type of stub. */
10213 if (!is_static_defined (&fdh
->elf
)
10214 && !is_static_defined (&h
->elf
))
10215 return ppc_stub_none
;
10217 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10219 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10220 struct plt_entry
**local_plt
= (struct plt_entry
**)
10221 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10222 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10224 if (local_plt
[r_symndx
] != NULL
)
10226 struct plt_entry
*ent
;
10228 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10229 if (ent
->addend
== rel
->r_addend
10230 && ent
->plt
.offset
!= (bfd_vma
) -1)
10233 return ppc_stub_plt_call
;
10238 /* Determine where the call point is. */
10239 location
= (input_sec
->output_offset
10240 + input_sec
->output_section
->vma
10243 branch_offset
= destination
- location
;
10244 r_type
= ELF64_R_TYPE (rel
->r_info
);
10246 /* Determine if a long branch stub is needed. */
10247 max_branch_offset
= 1 << 25;
10248 if (r_type
!= R_PPC64_REL24
)
10249 max_branch_offset
= 1 << 15;
10251 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10252 /* We need a stub. Figure out whether a long_branch or plt_branch
10253 is needed later. */
10254 return ppc_stub_long_branch
;
10256 return ppc_stub_none
;
10259 /* With power7 weakly ordered memory model, it is possible for ld.so
10260 to update a plt entry in one thread and have another thread see a
10261 stale zero toc entry. To avoid this we need some sort of acquire
10262 barrier in the call stub. One solution is to make the load of the
10263 toc word seem to appear to depend on the load of the function entry
10264 word. Another solution is to test for r2 being zero, and branch to
10265 the appropriate glink entry if so.
10267 . fake dep barrier compare
10268 . ld 12,xxx(2) ld 12,xxx(2)
10269 . mtctr 12 mtctr 12
10270 . xor 11,12,12 ld 2,xxx+8(2)
10271 . add 2,2,11 cmpldi 2,0
10272 . ld 2,xxx+8(2) bnectr+
10273 . bctr b <glink_entry>
10275 The solution involving the compare turns out to be faster, so
10276 that's what we use unless the branch won't reach. */
10278 #define ALWAYS_USE_FAKE_DEP 0
10279 #define ALWAYS_EMIT_R2SAVE 0
10281 #define PPC_LO(v) ((v) & 0xffff)
10282 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10283 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10285 static inline unsigned int
10286 plt_stub_size (struct ppc_link_hash_table
*htab
,
10287 struct ppc_stub_hash_entry
*stub_entry
,
10290 unsigned size
= 12;
10292 if (ALWAYS_EMIT_R2SAVE
10293 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10295 if (PPC_HA (off
) != 0)
10300 if (htab
->params
->plt_static_chain
)
10302 if (htab
->params
->plt_thread_safe
10303 && htab
->elf
.dynamic_sections_created
10304 && stub_entry
->h
!= NULL
10305 && stub_entry
->h
->elf
.dynindx
!= -1)
10307 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
10310 if (stub_entry
->h
!= NULL
10311 && (stub_entry
->h
== htab
->tls_get_addr_fd
10312 || stub_entry
->h
== htab
->tls_get_addr
)
10313 && !htab
->params
->no_tls_get_addr_opt
)
10318 /* If this stub would cross fewer 2**plt_stub_align boundaries if we align,
10319 then return the padding needed to do so. */
10320 static inline unsigned int
10321 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10322 struct ppc_stub_hash_entry
*stub_entry
,
10325 int stub_align
= 1 << htab
->params
->plt_stub_align
;
10326 unsigned stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10327 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10329 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10330 > ((stub_size
- 1) & -stub_align
))
10331 return stub_align
- (stub_off
& (stub_align
- 1));
10335 /* Build a .plt call stub. */
10337 static inline bfd_byte
*
10338 build_plt_stub (struct ppc_link_hash_table
*htab
,
10339 struct ppc_stub_hash_entry
*stub_entry
,
10340 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10342 bfd
*obfd
= htab
->params
->stub_bfd
;
10343 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10344 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10345 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10346 && htab
->elf
.dynamic_sections_created
10347 && stub_entry
->h
!= NULL
10348 && stub_entry
->h
->elf
.dynindx
!= -1);
10349 bfd_boolean use_fake_dep
= plt_thread_safe
;
10350 bfd_vma cmp_branch_off
= 0;
10352 if (!ALWAYS_USE_FAKE_DEP
10355 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10356 || stub_entry
->h
== htab
->tls_get_addr
)
10357 && !htab
->params
->no_tls_get_addr_opt
))
10359 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10360 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10361 / PLT_ENTRY_SIZE (htab
));
10362 bfd_vma glinkoff
= GLINK_CALL_STUB_SIZE
+ pltindex
* 8;
10365 if (pltindex
> 32768)
10366 glinkoff
+= (pltindex
- 32768) * 4;
10368 + htab
->glink
->output_offset
10369 + htab
->glink
->output_section
->vma
);
10370 from
= (p
- stub_entry
->group
->stub_sec
->contents
10371 + 4 * (ALWAYS_EMIT_R2SAVE
10372 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10373 + 4 * (PPC_HA (offset
) != 0)
10374 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10375 != PPC_HA (offset
))
10376 + 4 * (plt_static_chain
!= 0)
10378 + stub_entry
->group
->stub_sec
->output_offset
10379 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10380 cmp_branch_off
= to
- from
;
10381 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10384 if (PPC_HA (offset
) != 0)
10388 if (ALWAYS_EMIT_R2SAVE
10389 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10390 r
[0].r_offset
+= 4;
10391 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10392 r
[1].r_offset
= r
[0].r_offset
+ 4;
10393 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10394 r
[1].r_addend
= r
[0].r_addend
;
10397 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10399 r
[2].r_offset
= r
[1].r_offset
+ 4;
10400 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10401 r
[2].r_addend
= r
[0].r_addend
;
10405 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10406 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10407 r
[2].r_addend
= r
[0].r_addend
+ 8;
10408 if (plt_static_chain
)
10410 r
[3].r_offset
= r
[2].r_offset
+ 4;
10411 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10412 r
[3].r_addend
= r
[0].r_addend
+ 16;
10417 if (ALWAYS_EMIT_R2SAVE
10418 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10419 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10422 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10423 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10427 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10428 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10431 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10433 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10436 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10441 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10442 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10444 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10445 if (plt_static_chain
)
10446 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10453 if (ALWAYS_EMIT_R2SAVE
10454 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10455 r
[0].r_offset
+= 4;
10456 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10459 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10461 r
[1].r_offset
= r
[0].r_offset
+ 4;
10462 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10463 r
[1].r_addend
= r
[0].r_addend
;
10467 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10468 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10469 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10470 if (plt_static_chain
)
10472 r
[2].r_offset
= r
[1].r_offset
+ 4;
10473 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10474 r
[2].r_addend
= r
[0].r_addend
+ 8;
10479 if (ALWAYS_EMIT_R2SAVE
10480 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10481 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10482 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10484 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10486 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
10489 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10494 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
10495 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
10497 if (plt_static_chain
)
10498 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
10499 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
10502 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
10504 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
10505 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
10506 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
10509 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
10513 /* Build a special .plt call stub for __tls_get_addr. */
10515 #define LD_R11_0R3 0xe9630000
10516 #define LD_R12_0R3 0xe9830000
10517 #define MR_R0_R3 0x7c601b78
10518 #define CMPDI_R11_0 0x2c2b0000
10519 #define ADD_R3_R12_R13 0x7c6c6a14
10520 #define BEQLR 0x4d820020
10521 #define MR_R3_R0 0x7c030378
10522 #define STD_R11_0R1 0xf9610000
10523 #define BCTRL 0x4e800421
10524 #define LD_R11_0R1 0xe9610000
10525 #define MTLR_R11 0x7d6803a6
10527 static inline bfd_byte
*
10528 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
10529 struct ppc_stub_hash_entry
*stub_entry
,
10530 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10532 bfd
*obfd
= htab
->params
->stub_bfd
;
10534 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
10535 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
10536 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
10537 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
10538 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
10539 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
10540 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
10541 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
10542 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10545 r
[0].r_offset
+= 9 * 4;
10546 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
10547 bfd_put_32 (obfd
, BCTRL
, p
- 4);
10549 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10550 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
10551 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
10552 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
10557 static Elf_Internal_Rela
*
10558 get_relocs (asection
*sec
, int count
)
10560 Elf_Internal_Rela
*relocs
;
10561 struct bfd_elf_section_data
*elfsec_data
;
10563 elfsec_data
= elf_section_data (sec
);
10564 relocs
= elfsec_data
->relocs
;
10565 if (relocs
== NULL
)
10567 bfd_size_type relsize
;
10568 relsize
= sec
->reloc_count
* sizeof (*relocs
);
10569 relocs
= bfd_alloc (sec
->owner
, relsize
);
10570 if (relocs
== NULL
)
10572 elfsec_data
->relocs
= relocs
;
10573 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
10574 sizeof (Elf_Internal_Shdr
));
10575 if (elfsec_data
->rela
.hdr
== NULL
)
10577 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
10578 * sizeof (Elf64_External_Rela
));
10579 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
10580 sec
->reloc_count
= 0;
10582 relocs
+= sec
->reloc_count
;
10583 sec
->reloc_count
+= count
;
10588 get_r2off (struct bfd_link_info
*info
,
10589 struct ppc_stub_hash_entry
*stub_entry
)
10591 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
10592 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
10596 /* Support linking -R objects. Get the toc pointer from the
10599 if (!htab
->opd_abi
)
10601 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
10602 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
10604 if (strcmp (opd
->name
, ".opd") != 0
10605 || opd
->reloc_count
!= 0)
10607 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for `%T'\n"),
10608 stub_entry
->h
->elf
.root
.root
.string
);
10609 bfd_set_error (bfd_error_bad_value
);
10610 return (bfd_vma
) -1;
10612 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
10613 return (bfd_vma
) -1;
10614 r2off
= bfd_get_64 (opd
->owner
, buf
);
10615 r2off
-= elf_gp (info
->output_bfd
);
10617 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
10622 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
10624 struct ppc_stub_hash_entry
*stub_entry
;
10625 struct ppc_branch_hash_entry
*br_entry
;
10626 struct bfd_link_info
*info
;
10627 struct ppc_link_hash_table
*htab
;
10632 Elf_Internal_Rela
*r
;
10635 /* Massage our args to the form they really have. */
10636 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
10639 htab
= ppc_hash_table (info
);
10643 /* Make a note of the offset within the stubs for this entry. */
10644 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10645 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
10647 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
10648 switch (stub_entry
->stub_type
)
10650 case ppc_stub_long_branch
:
10651 case ppc_stub_long_branch_r2off
:
10652 /* Branches are relative. This is where we are going to. */
10653 dest
= (stub_entry
->target_value
10654 + stub_entry
->target_section
->output_offset
10655 + stub_entry
->target_section
->output_section
->vma
);
10656 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10659 /* And this is where we are coming from. */
10660 off
-= (stub_entry
->stub_offset
10661 + stub_entry
->group
->stub_sec
->output_offset
10662 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10665 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
10667 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10669 if (r2off
== (bfd_vma
) -1)
10671 htab
->stub_error
= TRUE
;
10674 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), loc
);
10677 if (PPC_HA (r2off
) != 0)
10679 bfd_put_32 (htab
->params
->stub_bfd
,
10680 ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
10684 if (PPC_LO (r2off
) != 0)
10686 bfd_put_32 (htab
->params
->stub_bfd
,
10687 ADDI_R2_R2
| PPC_LO (r2off
), loc
);
10693 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
10695 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
10697 info
->callbacks
->einfo
10698 (_("%P: long branch stub `%s' offset overflow\n"),
10699 stub_entry
->root
.string
);
10700 htab
->stub_error
= TRUE
;
10704 if (info
->emitrelocations
)
10706 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
10709 r
->r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10710 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
10711 r
->r_addend
= dest
;
10712 if (stub_entry
->h
!= NULL
)
10714 struct elf_link_hash_entry
**hashes
;
10715 unsigned long symndx
;
10716 struct ppc_link_hash_entry
*h
;
10718 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
10719 if (hashes
== NULL
)
10721 bfd_size_type hsize
;
10723 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
10724 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
10725 if (hashes
== NULL
)
10727 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
10728 htab
->stub_globals
= 1;
10730 symndx
= htab
->stub_globals
++;
10732 hashes
[symndx
] = &h
->elf
;
10733 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
10734 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
10735 h
= ppc_follow_link (h
->oh
);
10736 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
10737 /* H is an opd symbol. The addend must be zero. */
10741 off
= (h
->elf
.root
.u
.def
.value
10742 + h
->elf
.root
.u
.def
.section
->output_offset
10743 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
10744 r
->r_addend
-= off
;
10750 case ppc_stub_plt_branch
:
10751 case ppc_stub_plt_branch_r2off
:
10752 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
10753 stub_entry
->root
.string
+ 9,
10755 if (br_entry
== NULL
)
10757 info
->callbacks
->einfo (_("%P: can't find branch stub `%s'\n"),
10758 stub_entry
->root
.string
);
10759 htab
->stub_error
= TRUE
;
10763 dest
= (stub_entry
->target_value
10764 + stub_entry
->target_section
->output_offset
10765 + stub_entry
->target_section
->output_section
->vma
);
10766 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10767 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
10769 bfd_put_64 (htab
->brlt
->owner
, dest
,
10770 htab
->brlt
->contents
+ br_entry
->offset
);
10772 if (br_entry
->iter
== htab
->stub_iteration
)
10774 br_entry
->iter
= 0;
10776 if (htab
->relbrlt
!= NULL
)
10778 /* Create a reloc for the branch lookup table entry. */
10779 Elf_Internal_Rela rela
;
10782 rela
.r_offset
= (br_entry
->offset
10783 + htab
->brlt
->output_offset
10784 + htab
->brlt
->output_section
->vma
);
10785 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10786 rela
.r_addend
= dest
;
10788 rl
= htab
->relbrlt
->contents
;
10789 rl
+= (htab
->relbrlt
->reloc_count
++
10790 * sizeof (Elf64_External_Rela
));
10791 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
10793 else if (info
->emitrelocations
)
10795 r
= get_relocs (htab
->brlt
, 1);
10798 /* brlt, being SEC_LINKER_CREATED does not go through the
10799 normal reloc processing. Symbols and offsets are not
10800 translated from input file to output file form, so
10801 set up the offset per the output file. */
10802 r
->r_offset
= (br_entry
->offset
10803 + htab
->brlt
->output_offset
10804 + htab
->brlt
->output_section
->vma
);
10805 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10806 r
->r_addend
= dest
;
10810 dest
= (br_entry
->offset
10811 + htab
->brlt
->output_offset
10812 + htab
->brlt
->output_section
->vma
);
10815 - elf_gp (htab
->brlt
->output_section
->owner
)
10816 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10818 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10820 info
->callbacks
->einfo
10821 (_("%P: linkage table error against `%T'\n"),
10822 stub_entry
->root
.string
);
10823 bfd_set_error (bfd_error_bad_value
);
10824 htab
->stub_error
= TRUE
;
10828 if (info
->emitrelocations
)
10830 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
10833 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
10834 if (bfd_big_endian (info
->output_bfd
))
10835 r
[0].r_offset
+= 2;
10836 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
10837 r
[0].r_offset
+= 4;
10838 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10839 r
[0].r_addend
= dest
;
10840 if (PPC_HA (off
) != 0)
10842 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10843 r
[1].r_offset
= r
[0].r_offset
+ 4;
10844 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10845 r
[1].r_addend
= r
[0].r_addend
;
10849 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
10851 if (PPC_HA (off
) != 0)
10854 bfd_put_32 (htab
->params
->stub_bfd
,
10855 ADDIS_R12_R2
| PPC_HA (off
), loc
);
10857 bfd_put_32 (htab
->params
->stub_bfd
,
10858 LD_R12_0R12
| PPC_LO (off
), loc
);
10863 bfd_put_32 (htab
->params
->stub_bfd
,
10864 LD_R12_0R2
| PPC_LO (off
), loc
);
10869 bfd_vma r2off
= get_r2off (info
, stub_entry
);
10871 if (r2off
== (bfd_vma
) -1)
10873 htab
->stub_error
= TRUE
;
10877 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), loc
);
10880 if (PPC_HA (off
) != 0)
10883 bfd_put_32 (htab
->params
->stub_bfd
,
10884 ADDIS_R12_R2
| PPC_HA (off
), loc
);
10886 bfd_put_32 (htab
->params
->stub_bfd
,
10887 LD_R12_0R12
| PPC_LO (off
), loc
);
10890 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), loc
);
10892 if (PPC_HA (r2off
) != 0)
10896 bfd_put_32 (htab
->params
->stub_bfd
,
10897 ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
10899 if (PPC_LO (r2off
) != 0)
10903 bfd_put_32 (htab
->params
->stub_bfd
,
10904 ADDI_R2_R2
| PPC_LO (r2off
), loc
);
10908 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, loc
);
10910 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, loc
);
10913 case ppc_stub_plt_call
:
10914 case ppc_stub_plt_call_r2save
:
10915 if (stub_entry
->h
!= NULL
10916 && stub_entry
->h
->is_func_descriptor
10917 && stub_entry
->h
->oh
!= NULL
)
10919 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
10921 /* If the old-ABI "dot-symbol" is undefined make it weak so
10922 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
10923 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
10924 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
10925 /* Stop undo_symbol_twiddle changing it back to undefined. */
10926 fh
->was_undefined
= 0;
10929 /* Now build the stub. */
10930 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10931 if (dest
>= (bfd_vma
) -2)
10934 plt
= htab
->elf
.splt
;
10935 if (!htab
->elf
.dynamic_sections_created
10936 || stub_entry
->h
== NULL
10937 || stub_entry
->h
->elf
.dynindx
== -1)
10938 plt
= htab
->elf
.iplt
;
10940 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
10942 if (stub_entry
->h
== NULL
10943 && (stub_entry
->plt_ent
->plt
.offset
& 1) == 0)
10945 Elf_Internal_Rela rela
;
10948 rela
.r_offset
= dest
;
10950 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
10952 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
10953 rela
.r_addend
= (stub_entry
->target_value
10954 + stub_entry
->target_section
->output_offset
10955 + stub_entry
->target_section
->output_section
->vma
);
10957 rl
= (htab
->elf
.irelplt
->contents
10958 + (htab
->elf
.irelplt
->reloc_count
++
10959 * sizeof (Elf64_External_Rela
)));
10960 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, rl
);
10961 stub_entry
->plt_ent
->plt
.offset
|= 1;
10965 - elf_gp (plt
->output_section
->owner
)
10966 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
10968 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
10970 info
->callbacks
->einfo
10971 (_("%P: linkage table error against `%T'\n"),
10972 stub_entry
->h
!= NULL
10973 ? stub_entry
->h
->elf
.root
.root
.string
10975 bfd_set_error (bfd_error_bad_value
);
10976 htab
->stub_error
= TRUE
;
10980 if (htab
->params
->plt_stub_align
!= 0)
10982 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
10984 stub_entry
->group
->stub_sec
->size
+= pad
;
10985 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
10990 if (info
->emitrelocations
)
10992 r
= get_relocs (stub_entry
->group
->stub_sec
,
10993 ((PPC_HA (off
) != 0)
10995 ? 2 + (htab
->params
->plt_static_chain
10996 && PPC_HA (off
+ 16) == PPC_HA (off
))
11000 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11001 if (bfd_big_endian (info
->output_bfd
))
11002 r
[0].r_offset
+= 2;
11003 r
[0].r_addend
= dest
;
11005 if (stub_entry
->h
!= NULL
11006 && (stub_entry
->h
== htab
->tls_get_addr_fd
11007 || stub_entry
->h
== htab
->tls_get_addr
)
11008 && !htab
->params
->no_tls_get_addr_opt
)
11009 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
11011 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
11015 case ppc_stub_save_res
:
11023 stub_entry
->group
->stub_sec
->size
+= size
;
11025 if (htab
->params
->emit_stub_syms
)
11027 struct elf_link_hash_entry
*h
;
11030 const char *const stub_str
[] = { "long_branch",
11031 "long_branch_r2off",
11033 "plt_branch_r2off",
11037 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11038 len2
= strlen (stub_entry
->root
.string
);
11039 name
= bfd_malloc (len1
+ len2
+ 2);
11042 memcpy (name
, stub_entry
->root
.string
, 9);
11043 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11044 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11045 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
11048 if (h
->root
.type
== bfd_link_hash_new
)
11050 h
->root
.type
= bfd_link_hash_defined
;
11051 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11052 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11053 h
->ref_regular
= 1;
11054 h
->def_regular
= 1;
11055 h
->ref_regular_nonweak
= 1;
11056 h
->forced_local
= 1;
11058 h
->root
.linker_def
= 1;
11065 /* As above, but don't actually build the stub. Just bump offset so
11066 we know stub section sizes, and select plt_branch stubs where
11067 long_branch stubs won't do. */
11070 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11072 struct ppc_stub_hash_entry
*stub_entry
;
11073 struct bfd_link_info
*info
;
11074 struct ppc_link_hash_table
*htab
;
11078 /* Massage our args to the form they really have. */
11079 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11082 htab
= ppc_hash_table (info
);
11086 if (stub_entry
->h
!= NULL
11087 && stub_entry
->h
->save_res
11088 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11089 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
11091 /* Don't make stubs to out-of-line register save/restore
11092 functions. Instead, emit copies of the functions. */
11093 stub_entry
->group
->needs_save_res
= 1;
11094 stub_entry
->stub_type
= ppc_stub_save_res
;
11098 if (stub_entry
->stub_type
== ppc_stub_plt_call
11099 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11102 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11103 if (off
>= (bfd_vma
) -2)
11105 plt
= htab
->elf
.splt
;
11106 if (!htab
->elf
.dynamic_sections_created
11107 || stub_entry
->h
== NULL
11108 || stub_entry
->h
->elf
.dynindx
== -1)
11109 plt
= htab
->elf
.iplt
;
11110 off
+= (plt
->output_offset
11111 + plt
->output_section
->vma
11112 - elf_gp (plt
->output_section
->owner
)
11113 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11115 size
= plt_stub_size (htab
, stub_entry
, off
);
11116 if (htab
->params
->plt_stub_align
)
11117 size
+= plt_stub_pad (htab
, stub_entry
, off
);
11118 if (info
->emitrelocations
)
11120 stub_entry
->group
->stub_sec
->reloc_count
11121 += ((PPC_HA (off
) != 0)
11123 ? 2 + (htab
->params
->plt_static_chain
11124 && PPC_HA (off
+ 16) == PPC_HA (off
))
11126 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11131 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11134 bfd_vma local_off
= 0;
11136 off
= (stub_entry
->target_value
11137 + stub_entry
->target_section
->output_offset
11138 + stub_entry
->target_section
->output_section
->vma
);
11139 off
-= (stub_entry
->group
->stub_sec
->size
11140 + stub_entry
->group
->stub_sec
->output_offset
11141 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11143 /* Reset the stub type from the plt variant in case we now
11144 can reach with a shorter stub. */
11145 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
11146 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11149 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11151 r2off
= get_r2off (info
, stub_entry
);
11152 if (r2off
== (bfd_vma
) -1)
11154 htab
->stub_error
= TRUE
;
11158 if (PPC_HA (r2off
) != 0)
11160 if (PPC_LO (r2off
) != 0)
11165 local_off
= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11167 /* If the branch offset if too big, use a ppc_stub_plt_branch.
11168 Do the same for -R objects without function descriptors. */
11169 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26) - local_off
11170 || (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
11172 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0))
11174 struct ppc_branch_hash_entry
*br_entry
;
11176 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11177 stub_entry
->root
.string
+ 9,
11179 if (br_entry
== NULL
)
11181 info
->callbacks
->einfo (_("%P: can't build branch stub `%s'\n"),
11182 stub_entry
->root
.string
);
11183 htab
->stub_error
= TRUE
;
11187 if (br_entry
->iter
!= htab
->stub_iteration
)
11189 br_entry
->iter
= htab
->stub_iteration
;
11190 br_entry
->offset
= htab
->brlt
->size
;
11191 htab
->brlt
->size
+= 8;
11193 if (htab
->relbrlt
!= NULL
)
11194 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
11195 else if (info
->emitrelocations
)
11197 htab
->brlt
->reloc_count
+= 1;
11198 htab
->brlt
->flags
|= SEC_RELOC
;
11202 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11203 off
= (br_entry
->offset
11204 + htab
->brlt
->output_offset
11205 + htab
->brlt
->output_section
->vma
11206 - elf_gp (htab
->brlt
->output_section
->owner
)
11207 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11209 if (info
->emitrelocations
)
11211 stub_entry
->group
->stub_sec
->reloc_count
11212 += 1 + (PPC_HA (off
) != 0);
11213 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11216 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11219 if (PPC_HA (off
) != 0)
11225 if (PPC_HA (off
) != 0)
11228 if (PPC_HA (r2off
) != 0)
11230 if (PPC_LO (r2off
) != 0)
11234 else if (info
->emitrelocations
)
11236 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11237 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11241 stub_entry
->group
->stub_sec
->size
+= size
;
11245 /* Set up various things so that we can make a list of input sections
11246 for each output section included in the link. Returns -1 on error,
11247 0 when no stubs will be needed, and 1 on success. */
11250 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11254 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11259 htab
->sec_info_arr_size
= bfd_get_next_section_id ();
11260 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11261 htab
->sec_info
= bfd_zmalloc (amt
);
11262 if (htab
->sec_info
== NULL
)
11265 /* Set toc_off for com, und, abs and ind sections. */
11266 for (id
= 0; id
< 3; id
++)
11267 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11272 /* Set up for first pass at multitoc partitioning. */
11275 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11277 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11279 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11280 htab
->toc_bfd
= NULL
;
11281 htab
->toc_first_sec
= NULL
;
11284 /* The linker repeatedly calls this function for each TOC input section
11285 and linker generated GOT section. Group input bfds such that the toc
11286 within a group is less than 64k in size. */
11289 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11291 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11292 bfd_vma addr
, off
, limit
;
11297 if (!htab
->second_toc_pass
)
11299 /* Keep track of the first .toc or .got section for this input bfd. */
11300 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11304 htab
->toc_bfd
= isec
->owner
;
11305 htab
->toc_first_sec
= isec
;
11308 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11309 off
= addr
- htab
->toc_curr
;
11310 limit
= 0x80008000;
11311 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11313 if (off
+ isec
->size
> limit
)
11315 addr
= (htab
->toc_first_sec
->output_offset
11316 + htab
->toc_first_sec
->output_section
->vma
);
11317 htab
->toc_curr
= addr
;
11318 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11321 /* toc_curr is the base address of this toc group. Set elf_gp
11322 for the input section to be the offset relative to the
11323 output toc base plus 0x8000. Making the input elf_gp an
11324 offset allows us to move the toc as a whole without
11325 recalculating input elf_gp. */
11326 off
= htab
->toc_curr
- elf_gp (isec
->output_section
->owner
);
11327 off
+= TOC_BASE_OFF
;
11329 /* Die if someone uses a linker script that doesn't keep input
11330 file .toc and .got together. */
11332 && elf_gp (isec
->owner
) != 0
11333 && elf_gp (isec
->owner
) != off
)
11336 elf_gp (isec
->owner
) = off
;
11340 /* During the second pass toc_first_sec points to the start of
11341 a toc group, and toc_curr is used to track the old elf_gp.
11342 We use toc_bfd to ensure we only look at each bfd once. */
11343 if (htab
->toc_bfd
== isec
->owner
)
11345 htab
->toc_bfd
= isec
->owner
;
11347 if (htab
->toc_first_sec
== NULL
11348 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11350 htab
->toc_curr
= elf_gp (isec
->owner
);
11351 htab
->toc_first_sec
= isec
;
11353 addr
= (htab
->toc_first_sec
->output_offset
11354 + htab
->toc_first_sec
->output_section
->vma
);
11355 off
= addr
- elf_gp (isec
->output_section
->owner
) + TOC_BASE_OFF
;
11356 elf_gp (isec
->owner
) = off
;
11361 /* Called via elf_link_hash_traverse to merge GOT entries for global
11365 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11367 if (h
->root
.type
== bfd_link_hash_indirect
)
11370 merge_got_entries (&h
->got
.glist
);
11375 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11379 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11381 struct got_entry
*gent
;
11383 if (h
->root
.type
== bfd_link_hash_indirect
)
11386 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11387 if (!gent
->is_indirect
)
11388 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11392 /* Called on the first multitoc pass after the last call to
11393 ppc64_elf_next_toc_section. This function removes duplicate GOT
11397 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11399 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11400 struct bfd
*ibfd
, *ibfd2
;
11401 bfd_boolean done_something
;
11403 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11405 if (!htab
->do_multi_toc
)
11408 /* Merge global sym got entries within a toc group. */
11409 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11411 /* And tlsld_got. */
11412 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11414 struct got_entry
*ent
, *ent2
;
11416 if (!is_ppc64_elf (ibfd
))
11419 ent
= ppc64_tlsld_got (ibfd
);
11420 if (!ent
->is_indirect
11421 && ent
->got
.offset
!= (bfd_vma
) -1)
11423 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11425 if (!is_ppc64_elf (ibfd2
))
11428 ent2
= ppc64_tlsld_got (ibfd2
);
11429 if (!ent2
->is_indirect
11430 && ent2
->got
.offset
!= (bfd_vma
) -1
11431 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11433 ent2
->is_indirect
= TRUE
;
11434 ent2
->got
.ent
= ent
;
11440 /* Zap sizes of got sections. */
11441 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11442 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11443 htab
->got_reli_size
= 0;
11445 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11447 asection
*got
, *relgot
;
11449 if (!is_ppc64_elf (ibfd
))
11452 got
= ppc64_elf_tdata (ibfd
)->got
;
11455 got
->rawsize
= got
->size
;
11457 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11458 relgot
->rawsize
= relgot
->size
;
11463 /* Now reallocate the got, local syms first. We don't need to
11464 allocate section contents again since we never increase size. */
11465 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11467 struct got_entry
**lgot_ents
;
11468 struct got_entry
**end_lgot_ents
;
11469 struct plt_entry
**local_plt
;
11470 struct plt_entry
**end_local_plt
;
11471 unsigned char *lgot_masks
;
11472 bfd_size_type locsymcount
;
11473 Elf_Internal_Shdr
*symtab_hdr
;
11476 if (!is_ppc64_elf (ibfd
))
11479 lgot_ents
= elf_local_got_ents (ibfd
);
11483 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11484 locsymcount
= symtab_hdr
->sh_info
;
11485 end_lgot_ents
= lgot_ents
+ locsymcount
;
11486 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11487 end_local_plt
= local_plt
+ locsymcount
;
11488 lgot_masks
= (unsigned char *) end_local_plt
;
11489 s
= ppc64_elf_tdata (ibfd
)->got
;
11490 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
11492 struct got_entry
*ent
;
11494 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
11496 unsigned int ent_size
= 8;
11497 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
11499 ent
->got
.offset
= s
->size
;
11500 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
11505 s
->size
+= ent_size
;
11506 if ((*lgot_masks
& PLT_IFUNC
) != 0)
11508 htab
->elf
.irelplt
->size
+= rel_size
;
11509 htab
->got_reli_size
+= rel_size
;
11511 else if (bfd_link_pic (info
))
11513 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11514 srel
->size
+= rel_size
;
11520 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
11522 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11524 struct got_entry
*ent
;
11526 if (!is_ppc64_elf (ibfd
))
11529 ent
= ppc64_tlsld_got (ibfd
);
11530 if (!ent
->is_indirect
11531 && ent
->got
.offset
!= (bfd_vma
) -1)
11533 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
11534 ent
->got
.offset
= s
->size
;
11536 if (bfd_link_pic (info
))
11538 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
11539 srel
->size
+= sizeof (Elf64_External_Rela
);
11544 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
11545 if (!done_something
)
11546 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11550 if (!is_ppc64_elf (ibfd
))
11553 got
= ppc64_elf_tdata (ibfd
)->got
;
11556 done_something
= got
->rawsize
!= got
->size
;
11557 if (done_something
)
11562 if (done_something
)
11563 (*htab
->params
->layout_sections_again
) ();
11565 /* Set up for second pass over toc sections to recalculate elf_gp
11566 on input sections. */
11567 htab
->toc_bfd
= NULL
;
11568 htab
->toc_first_sec
= NULL
;
11569 htab
->second_toc_pass
= TRUE
;
11570 return done_something
;
11573 /* Called after second pass of multitoc partitioning. */
11576 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
11578 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11580 /* After the second pass, toc_curr tracks the TOC offset used
11581 for code sections below in ppc64_elf_next_input_section. */
11582 htab
->toc_curr
= TOC_BASE_OFF
;
11585 /* No toc references were found in ISEC. If the code in ISEC makes no
11586 calls, then there's no need to use toc adjusting stubs when branching
11587 into ISEC. Actually, indirect calls from ISEC are OK as they will
11588 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
11589 needed, and 2 if a cyclical call-graph was found but no other reason
11590 for a stub was detected. If called from the top level, a return of
11591 2 means the same as a return of 0. */
11594 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
11598 /* Mark this section as checked. */
11599 isec
->call_check_done
= 1;
11601 /* We know none of our code bearing sections will need toc stubs. */
11602 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11605 if (isec
->size
== 0)
11608 if (isec
->output_section
== NULL
)
11612 if (isec
->reloc_count
!= 0)
11614 Elf_Internal_Rela
*relstart
, *rel
;
11615 Elf_Internal_Sym
*local_syms
;
11616 struct ppc_link_hash_table
*htab
;
11618 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
11619 info
->keep_memory
);
11620 if (relstart
== NULL
)
11623 /* Look for branches to outside of this section. */
11625 htab
= ppc_hash_table (info
);
11629 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
11631 enum elf_ppc64_reloc_type r_type
;
11632 unsigned long r_symndx
;
11633 struct elf_link_hash_entry
*h
;
11634 struct ppc_link_hash_entry
*eh
;
11635 Elf_Internal_Sym
*sym
;
11637 struct _opd_sec_data
*opd
;
11641 r_type
= ELF64_R_TYPE (rel
->r_info
);
11642 if (r_type
!= R_PPC64_REL24
11643 && r_type
!= R_PPC64_REL14
11644 && r_type
!= R_PPC64_REL14_BRTAKEN
11645 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
11648 r_symndx
= ELF64_R_SYM (rel
->r_info
);
11649 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
11656 /* Calls to dynamic lib functions go through a plt call stub
11658 eh
= (struct ppc_link_hash_entry
*) h
;
11660 && (eh
->elf
.plt
.plist
!= NULL
11662 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
11668 if (sym_sec
== NULL
)
11669 /* Ignore other undefined symbols. */
11672 /* Assume branches to other sections not included in the
11673 link need stubs too, to cover -R and absolute syms. */
11674 if (sym_sec
->output_section
== NULL
)
11681 sym_value
= sym
->st_value
;
11684 if (h
->root
.type
!= bfd_link_hash_defined
11685 && h
->root
.type
!= bfd_link_hash_defweak
)
11687 sym_value
= h
->root
.u
.def
.value
;
11689 sym_value
+= rel
->r_addend
;
11691 /* If this branch reloc uses an opd sym, find the code section. */
11692 opd
= get_opd_info (sym_sec
);
11695 if (h
== NULL
&& opd
->adjust
!= NULL
)
11699 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
11701 /* Assume deleted functions won't ever be called. */
11703 sym_value
+= adjust
;
11706 dest
= opd_entry_value (sym_sec
, sym_value
,
11707 &sym_sec
, NULL
, FALSE
);
11708 if (dest
== (bfd_vma
) -1)
11713 + sym_sec
->output_offset
11714 + sym_sec
->output_section
->vma
);
11716 /* Ignore branch to self. */
11717 if (sym_sec
== isec
)
11720 /* If the called function uses the toc, we need a stub. */
11721 if (sym_sec
->has_toc_reloc
11722 || sym_sec
->makes_toc_func_call
)
11728 /* Assume any branch that needs a long branch stub might in fact
11729 need a plt_branch stub. A plt_branch stub uses r2. */
11730 else if (dest
- (isec
->output_offset
11731 + isec
->output_section
->vma
11732 + rel
->r_offset
) + (1 << 25)
11733 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
11741 /* If calling back to a section in the process of being
11742 tested, we can't say for sure that no toc adjusting stubs
11743 are needed, so don't return zero. */
11744 else if (sym_sec
->call_check_in_progress
)
11747 /* Branches to another section that itself doesn't have any TOC
11748 references are OK. Recursively call ourselves to check. */
11749 else if (!sym_sec
->call_check_done
)
11753 /* Mark current section as indeterminate, so that other
11754 sections that call back to current won't be marked as
11756 isec
->call_check_in_progress
= 1;
11757 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
11758 isec
->call_check_in_progress
= 0;
11769 if (local_syms
!= NULL
11770 && (elf_symtab_hdr (isec
->owner
).contents
11771 != (unsigned char *) local_syms
))
11773 if (elf_section_data (isec
)->relocs
!= relstart
)
11778 && isec
->map_head
.s
!= NULL
11779 && (strcmp (isec
->output_section
->name
, ".init") == 0
11780 || strcmp (isec
->output_section
->name
, ".fini") == 0))
11782 if (isec
->map_head
.s
->has_toc_reloc
11783 || isec
->map_head
.s
->makes_toc_func_call
)
11785 else if (!isec
->map_head
.s
->call_check_done
)
11788 isec
->call_check_in_progress
= 1;
11789 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
11790 isec
->call_check_in_progress
= 0;
11797 isec
->makes_toc_func_call
= 1;
11802 /* The linker repeatedly calls this function for each input section,
11803 in the order that input sections are linked into output sections.
11804 Build lists of input sections to determine groupings between which
11805 we may insert linker stubs. */
11808 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
11810 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11815 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
11816 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
11818 /* This happens to make the list in reverse order,
11819 which is what we want. */
11820 htab
->sec_info
[isec
->id
].u
.list
11821 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
11822 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
11825 if (htab
->multi_toc_needed
)
11827 /* Analyse sections that aren't already flagged as needing a
11828 valid toc pointer. Exclude .fixup for the linux kernel.
11829 .fixup contains branches, but only back to the function that
11830 hit an exception. */
11831 if (!(isec
->has_toc_reloc
11832 || (isec
->flags
& SEC_CODE
) == 0
11833 || strcmp (isec
->name
, ".fixup") == 0
11834 || isec
->call_check_done
))
11836 if (toc_adjusting_stub_needed (info
, isec
) < 0)
11839 /* Make all sections use the TOC assigned for this object file.
11840 This will be wrong for pasted sections; We fix that in
11841 check_pasted_section(). */
11842 if (elf_gp (isec
->owner
) != 0)
11843 htab
->toc_curr
= elf_gp (isec
->owner
);
11846 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
11850 /* Check that all .init and .fini sections use the same toc, if they
11851 have toc relocs. */
11854 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
11856 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
11860 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11861 bfd_vma toc_off
= 0;
11864 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11865 if (i
->has_toc_reloc
)
11868 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11869 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
11874 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11875 if (i
->makes_toc_func_call
)
11877 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
11881 /* Make sure the whole pasted function uses the same toc offset. */
11883 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
11884 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
11890 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
11892 return (check_pasted_section (info
, ".init")
11893 & check_pasted_section (info
, ".fini"));
11896 /* See whether we can group stub sections together. Grouping stub
11897 sections may result in fewer stubs. More importantly, we need to
11898 put all .init* and .fini* stubs at the beginning of the .init or
11899 .fini output sections respectively, because glibc splits the
11900 _init and _fini functions into multiple parts. Putting a stub in
11901 the middle of a function is not a good idea. */
11904 group_sections (struct bfd_link_info
*info
,
11905 bfd_size_type stub_group_size
,
11906 bfd_boolean stubs_always_before_branch
)
11908 struct ppc_link_hash_table
*htab
;
11910 bfd_size_type stub14_group_size
;
11911 bfd_boolean suppress_size_errors
;
11913 htab
= ppc_hash_table (info
);
11917 suppress_size_errors
= FALSE
;
11918 stub14_group_size
= stub_group_size
>> 10;
11919 if (stub_group_size
== 1)
11921 /* Default values. */
11922 if (stubs_always_before_branch
)
11924 stub_group_size
= 0x1e00000;
11925 stub14_group_size
= 0x7800;
11929 stub_group_size
= 0x1c00000;
11930 stub14_group_size
= 0x7000;
11932 suppress_size_errors
= TRUE
;
11935 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
11939 if (osec
->id
>= htab
->sec_info_arr_size
)
11942 tail
= htab
->sec_info
[osec
->id
].u
.list
;
11943 while (tail
!= NULL
)
11947 bfd_size_type total
;
11948 bfd_boolean big_sec
;
11950 struct map_stub
*group
;
11953 total
= tail
->size
;
11954 big_sec
= total
> (ppc64_elf_section_data (tail
) != NULL
11955 && ppc64_elf_section_data (tail
)->has_14bit_branch
11956 ? stub14_group_size
: stub_group_size
);
11957 if (big_sec
&& !suppress_size_errors
)
11958 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
11959 tail
->owner
, tail
);
11960 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
11962 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
11963 && ((total
+= curr
->output_offset
- prev
->output_offset
)
11964 < (ppc64_elf_section_data (prev
) != NULL
11965 && ppc64_elf_section_data (prev
)->has_14bit_branch
11966 ? stub14_group_size
: stub_group_size
))
11967 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
11970 /* OK, the size from the start of CURR to the end is less
11971 than stub_group_size and thus can be handled by one stub
11972 section. (or the tail section is itself larger than
11973 stub_group_size, in which case we may be toast.) We
11974 should really be keeping track of the total size of stubs
11975 added here, as stubs contribute to the final output
11976 section size. That's a little tricky, and this way will
11977 only break if stubs added make the total size more than
11978 2^25, ie. for the default stub_group_size, if stubs total
11979 more than 2097152 bytes, or nearly 75000 plt call stubs. */
11980 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
11983 group
->link_sec
= curr
;
11984 group
->stub_sec
= NULL
;
11985 group
->needs_save_res
= 0;
11986 group
->next
= htab
->group
;
11987 htab
->group
= group
;
11990 prev
= htab
->sec_info
[tail
->id
].u
.list
;
11991 /* Set up this stub group. */
11992 htab
->sec_info
[tail
->id
].u
.group
= group
;
11994 while (tail
!= curr
&& (tail
= prev
) != NULL
);
11996 /* But wait, there's more! Input sections up to stub_group_size
11997 bytes before the stub section can be handled by it too.
11998 Don't do this if we have a really large section after the
11999 stubs, as adding more stubs increases the chance that
12000 branches may not reach into the stub section. */
12001 if (!stubs_always_before_branch
&& !big_sec
)
12004 while (prev
!= NULL
12005 && ((total
+= tail
->output_offset
- prev
->output_offset
)
12006 < (ppc64_elf_section_data (prev
) != NULL
12007 && ppc64_elf_section_data (prev
)->has_14bit_branch
12008 ? stub14_group_size
: stub_group_size
))
12009 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12012 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12013 htab
->sec_info
[tail
->id
].u
.group
= group
;
12022 static const unsigned char glink_eh_frame_cie
[] =
12024 0, 0, 0, 16, /* length. */
12025 0, 0, 0, 0, /* id. */
12026 1, /* CIE version. */
12027 'z', 'R', 0, /* Augmentation string. */
12028 4, /* Code alignment. */
12029 0x78, /* Data alignment. */
12031 1, /* Augmentation size. */
12032 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12033 DW_CFA_def_cfa
, 1, 0, /* def_cfa: r1 offset 0. */
12037 /* Stripping output sections is normally done before dynamic section
12038 symbols have been allocated. This function is called later, and
12039 handles cases like htab->brlt which is mapped to its own output
12043 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12045 if (isec
->size
== 0
12046 && isec
->output_section
->size
== 0
12047 && !(isec
->output_section
->flags
& SEC_KEEP
)
12048 && !bfd_section_removed_from_list (info
->output_bfd
,
12049 isec
->output_section
)
12050 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12052 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12053 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12054 info
->output_bfd
->section_count
--;
12058 /* Determine and set the size of the stub section for a final link.
12060 The basic idea here is to examine all the relocations looking for
12061 PC-relative calls to a target that is unreachable with a "bl"
12065 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12067 bfd_size_type stub_group_size
;
12068 bfd_boolean stubs_always_before_branch
;
12069 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12074 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12075 htab
->params
->plt_thread_safe
= 1;
12076 if (!htab
->opd_abi
)
12077 htab
->params
->plt_thread_safe
= 0;
12078 else if (htab
->params
->plt_thread_safe
== -1)
12080 static const char *const thread_starter
[] =
12084 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12086 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12087 "mq_notify", "create_timer",
12092 "GOMP_parallel_start",
12093 "GOMP_parallel_loop_static",
12094 "GOMP_parallel_loop_static_start",
12095 "GOMP_parallel_loop_dynamic",
12096 "GOMP_parallel_loop_dynamic_start",
12097 "GOMP_parallel_loop_guided",
12098 "GOMP_parallel_loop_guided_start",
12099 "GOMP_parallel_loop_runtime",
12100 "GOMP_parallel_loop_runtime_start",
12101 "GOMP_parallel_sections",
12102 "GOMP_parallel_sections_start",
12108 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12110 struct elf_link_hash_entry
*h
;
12111 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12112 FALSE
, FALSE
, TRUE
);
12113 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12114 if (htab
->params
->plt_thread_safe
)
12118 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12119 if (htab
->params
->group_size
< 0)
12120 stub_group_size
= -htab
->params
->group_size
;
12122 stub_group_size
= htab
->params
->group_size
;
12124 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12130 unsigned int bfd_indx
;
12131 struct map_stub
*group
;
12132 asection
*stub_sec
;
12134 htab
->stub_iteration
+= 1;
12136 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12138 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12140 Elf_Internal_Shdr
*symtab_hdr
;
12142 Elf_Internal_Sym
*local_syms
= NULL
;
12144 if (!is_ppc64_elf (input_bfd
))
12147 /* We'll need the symbol table in a second. */
12148 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12149 if (symtab_hdr
->sh_info
== 0)
12152 /* Walk over each section attached to the input bfd. */
12153 for (section
= input_bfd
->sections
;
12155 section
= section
->next
)
12157 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12159 /* If there aren't any relocs, then there's nothing more
12161 if ((section
->flags
& SEC_RELOC
) == 0
12162 || (section
->flags
& SEC_ALLOC
) == 0
12163 || (section
->flags
& SEC_LOAD
) == 0
12164 || (section
->flags
& SEC_CODE
) == 0
12165 || section
->reloc_count
== 0)
12168 /* If this section is a link-once section that will be
12169 discarded, then don't create any stubs. */
12170 if (section
->output_section
== NULL
12171 || section
->output_section
->owner
!= info
->output_bfd
)
12174 /* Get the relocs. */
12176 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12177 info
->keep_memory
);
12178 if (internal_relocs
== NULL
)
12179 goto error_ret_free_local
;
12181 /* Now examine each relocation. */
12182 irela
= internal_relocs
;
12183 irelaend
= irela
+ section
->reloc_count
;
12184 for (; irela
< irelaend
; irela
++)
12186 enum elf_ppc64_reloc_type r_type
;
12187 unsigned int r_indx
;
12188 enum ppc_stub_type stub_type
;
12189 struct ppc_stub_hash_entry
*stub_entry
;
12190 asection
*sym_sec
, *code_sec
;
12191 bfd_vma sym_value
, code_value
;
12192 bfd_vma destination
;
12193 unsigned long local_off
;
12194 bfd_boolean ok_dest
;
12195 struct ppc_link_hash_entry
*hash
;
12196 struct ppc_link_hash_entry
*fdh
;
12197 struct elf_link_hash_entry
*h
;
12198 Elf_Internal_Sym
*sym
;
12200 const asection
*id_sec
;
12201 struct _opd_sec_data
*opd
;
12202 struct plt_entry
*plt_ent
;
12204 r_type
= ELF64_R_TYPE (irela
->r_info
);
12205 r_indx
= ELF64_R_SYM (irela
->r_info
);
12207 if (r_type
>= R_PPC64_max
)
12209 bfd_set_error (bfd_error_bad_value
);
12210 goto error_ret_free_internal
;
12213 /* Only look for stubs on branch instructions. */
12214 if (r_type
!= R_PPC64_REL24
12215 && r_type
!= R_PPC64_REL14
12216 && r_type
!= R_PPC64_REL14_BRTAKEN
12217 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12220 /* Now determine the call target, its name, value,
12222 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12223 r_indx
, input_bfd
))
12224 goto error_ret_free_internal
;
12225 hash
= (struct ppc_link_hash_entry
*) h
;
12232 sym_value
= sym
->st_value
;
12235 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12236 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12238 sym_value
= hash
->elf
.root
.u
.def
.value
;
12239 if (sym_sec
->output_section
!= NULL
)
12242 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12243 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12245 /* Recognise an old ABI func code entry sym, and
12246 use the func descriptor sym instead if it is
12248 if (hash
->elf
.root
.root
.string
[0] == '.'
12249 && (fdh
= lookup_fdh (hash
, htab
)) != NULL
)
12251 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12252 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12254 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12255 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12256 if (sym_sec
->output_section
!= NULL
)
12265 bfd_set_error (bfd_error_bad_value
);
12266 goto error_ret_free_internal
;
12273 sym_value
+= irela
->r_addend
;
12274 destination
= (sym_value
12275 + sym_sec
->output_offset
12276 + sym_sec
->output_section
->vma
);
12277 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12282 code_sec
= sym_sec
;
12283 code_value
= sym_value
;
12284 opd
= get_opd_info (sym_sec
);
12289 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12291 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12294 code_value
+= adjust
;
12295 sym_value
+= adjust
;
12297 dest
= opd_entry_value (sym_sec
, sym_value
,
12298 &code_sec
, &code_value
, FALSE
);
12299 if (dest
!= (bfd_vma
) -1)
12301 destination
= dest
;
12304 /* Fixup old ABI sym to point at code
12306 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12307 hash
->elf
.root
.u
.def
.section
= code_sec
;
12308 hash
->elf
.root
.u
.def
.value
= code_value
;
12313 /* Determine what (if any) linker stub is needed. */
12315 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
12316 &plt_ent
, destination
,
12319 if (stub_type
!= ppc_stub_plt_call
)
12321 /* Check whether we need a TOC adjusting stub.
12322 Since the linker pastes together pieces from
12323 different object files when creating the
12324 _init and _fini functions, it may be that a
12325 call to what looks like a local sym is in
12326 fact a call needing a TOC adjustment. */
12327 if (code_sec
!= NULL
12328 && code_sec
->output_section
!= NULL
12329 && (htab
->sec_info
[code_sec
->id
].toc_off
12330 != htab
->sec_info
[section
->id
].toc_off
)
12331 && (code_sec
->has_toc_reloc
12332 || code_sec
->makes_toc_func_call
))
12333 stub_type
= ppc_stub_long_branch_r2off
;
12336 if (stub_type
== ppc_stub_none
)
12339 /* __tls_get_addr calls might be eliminated. */
12340 if (stub_type
!= ppc_stub_plt_call
12342 && (hash
== htab
->tls_get_addr
12343 || hash
== htab
->tls_get_addr_fd
)
12344 && section
->has_tls_reloc
12345 && irela
!= internal_relocs
)
12347 /* Get tls info. */
12348 unsigned char *tls_mask
;
12350 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12351 irela
- 1, input_bfd
))
12352 goto error_ret_free_internal
;
12353 if (*tls_mask
!= 0)
12357 if (stub_type
== ppc_stub_plt_call
12358 && irela
+ 1 < irelaend
12359 && irela
[1].r_offset
== irela
->r_offset
+ 4
12360 && ELF64_R_TYPE (irela
[1].r_info
) == R_PPC64_TOCSAVE
)
12362 if (!tocsave_find (htab
, INSERT
,
12363 &local_syms
, irela
+ 1, input_bfd
))
12364 goto error_ret_free_internal
;
12366 else if (stub_type
== ppc_stub_plt_call
)
12367 stub_type
= ppc_stub_plt_call_r2save
;
12369 /* Support for grouping stub sections. */
12370 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12372 /* Get the name of this stub. */
12373 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12375 goto error_ret_free_internal
;
12377 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12378 stub_name
, FALSE
, FALSE
);
12379 if (stub_entry
!= NULL
)
12381 /* The proper stub has already been created. */
12383 if (stub_type
== ppc_stub_plt_call_r2save
)
12384 stub_entry
->stub_type
= stub_type
;
12388 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12389 if (stub_entry
== NULL
)
12392 error_ret_free_internal
:
12393 if (elf_section_data (section
)->relocs
== NULL
)
12394 free (internal_relocs
);
12395 error_ret_free_local
:
12396 if (local_syms
!= NULL
12397 && (symtab_hdr
->contents
12398 != (unsigned char *) local_syms
))
12403 stub_entry
->stub_type
= stub_type
;
12404 if (stub_type
!= ppc_stub_plt_call
12405 && stub_type
!= ppc_stub_plt_call_r2save
)
12407 stub_entry
->target_value
= code_value
;
12408 stub_entry
->target_section
= code_sec
;
12412 stub_entry
->target_value
= sym_value
;
12413 stub_entry
->target_section
= sym_sec
;
12415 stub_entry
->h
= hash
;
12416 stub_entry
->plt_ent
= plt_ent
;
12417 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12419 if (stub_entry
->h
!= NULL
)
12420 htab
->stub_globals
+= 1;
12423 /* We're done with the internal relocs, free them. */
12424 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12425 free (internal_relocs
);
12428 if (local_syms
!= NULL
12429 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12431 if (!info
->keep_memory
)
12434 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12438 /* We may have added some stubs. Find out the new size of the
12440 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12442 stub_sec
= stub_sec
->next
)
12443 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12445 stub_sec
->rawsize
= stub_sec
->size
;
12446 stub_sec
->size
= 0;
12447 stub_sec
->reloc_count
= 0;
12448 stub_sec
->flags
&= ~SEC_RELOC
;
12451 htab
->brlt
->size
= 0;
12452 htab
->brlt
->reloc_count
= 0;
12453 htab
->brlt
->flags
&= ~SEC_RELOC
;
12454 if (htab
->relbrlt
!= NULL
)
12455 htab
->relbrlt
->size
= 0;
12457 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
12459 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12460 if (group
->needs_save_res
)
12461 group
->stub_sec
->size
+= htab
->sfpr
->size
;
12463 if (info
->emitrelocations
12464 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12466 htab
->glink
->reloc_count
= 1;
12467 htab
->glink
->flags
|= SEC_RELOC
;
12470 if (htab
->glink_eh_frame
!= NULL
12471 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
12472 && htab
->glink_eh_frame
->output_section
->size
!= 0)
12474 size_t size
= 0, align
;
12476 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12478 stub_sec
= stub_sec
->next
)
12479 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12481 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12484 size
+= sizeof (glink_eh_frame_cie
);
12486 align
<<= htab
->glink_eh_frame
->output_section
->alignment_power
;
12488 size
= (size
+ align
) & ~align
;
12489 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
12490 htab
->glink_eh_frame
->size
= size
;
12493 if (htab
->params
->plt_stub_align
!= 0)
12494 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12496 stub_sec
= stub_sec
->next
)
12497 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12498 stub_sec
->size
= ((stub_sec
->size
12499 + (1 << htab
->params
->plt_stub_align
) - 1)
12500 & (-1 << htab
->params
->plt_stub_align
));
12502 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12504 stub_sec
= stub_sec
->next
)
12505 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
12506 && stub_sec
->rawsize
!= stub_sec
->size
)
12509 /* Exit from this loop when no stubs have been added, and no stubs
12510 have changed size. */
12511 if (stub_sec
== NULL
12512 && (htab
->glink_eh_frame
== NULL
12513 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
12516 /* Ask the linker to do its stuff. */
12517 (*htab
->params
->layout_sections_again
) ();
12520 if (htab
->glink_eh_frame
!= NULL
12521 && htab
->glink_eh_frame
->size
!= 0)
12524 bfd_byte
*p
, *last_fde
;
12525 size_t last_fde_len
, size
, align
, pad
;
12526 asection
*stub_sec
;
12528 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
12531 htab
->glink_eh_frame
->contents
= p
;
12534 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
12535 /* CIE length (rewrite in case little-endian). */
12536 last_fde_len
= sizeof (glink_eh_frame_cie
) - 4;
12537 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
12538 p
+= sizeof (glink_eh_frame_cie
);
12540 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12542 stub_sec
= stub_sec
->next
)
12543 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
12548 bfd_put_32 (htab
->elf
.dynobj
, 20, p
);
12551 val
= p
- htab
->glink_eh_frame
->contents
;
12552 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12554 /* Offset to stub section, written later. */
12556 /* stub section size. */
12557 bfd_put_32 (htab
->elf
.dynobj
, stub_sec
->size
, p
);
12559 /* Augmentation. */
12564 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12569 bfd_put_32 (htab
->elf
.dynobj
, 20, p
);
12572 val
= p
- htab
->glink_eh_frame
->contents
;
12573 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
12575 /* Offset to .glink, written later. */
12578 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
12580 /* Augmentation. */
12583 *p
++ = DW_CFA_advance_loc
+ 1;
12584 *p
++ = DW_CFA_register
;
12587 *p
++ = DW_CFA_advance_loc
+ 4;
12588 *p
++ = DW_CFA_restore_extended
;
12591 /* Subsume any padding into the last FDE if user .eh_frame
12592 sections are aligned more than glink_eh_frame. Otherwise any
12593 zero padding will be seen as a terminator. */
12594 size
= p
- htab
->glink_eh_frame
->contents
;
12596 align
<<= htab
->glink_eh_frame
->output_section
->alignment_power
;
12598 pad
= ((size
+ align
) & ~align
) - size
;
12599 htab
->glink_eh_frame
->size
= size
+ pad
;
12600 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
12603 maybe_strip_output (info
, htab
->brlt
);
12604 if (htab
->glink_eh_frame
!= NULL
)
12605 maybe_strip_output (info
, htab
->glink_eh_frame
);
12610 /* Called after we have determined section placement. If sections
12611 move, we'll be called again. Provide a value for TOCstart. */
12614 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
12617 bfd_vma TOCstart
, adjust
;
12621 struct elf_link_hash_entry
*h
;
12622 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
12624 if (is_elf_hash_table (htab
)
12625 && htab
->hgot
!= NULL
)
12629 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
12630 if (is_elf_hash_table (htab
))
12634 && h
->root
.type
== bfd_link_hash_defined
12635 && !h
->root
.linker_def
12636 && (!is_elf_hash_table (htab
)
12637 || h
->def_regular
))
12639 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
12640 + h
->root
.u
.def
.section
->output_offset
12641 + h
->root
.u
.def
.section
->output_section
->vma
);
12642 _bfd_set_gp_value (obfd
, TOCstart
);
12647 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
12648 order. The TOC starts where the first of these sections starts. */
12649 s
= bfd_get_section_by_name (obfd
, ".got");
12650 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12651 s
= bfd_get_section_by_name (obfd
, ".toc");
12652 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12653 s
= bfd_get_section_by_name (obfd
, ".tocbss");
12654 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12655 s
= bfd_get_section_by_name (obfd
, ".plt");
12656 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
12658 /* This may happen for
12659 o references to TOC base (SYM@toc / TOC[tc0]) without a
12661 o bad linker script
12662 o --gc-sections and empty TOC sections
12664 FIXME: Warn user? */
12666 /* Look for a likely section. We probably won't even be
12668 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12669 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
12671 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12674 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12675 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
12676 == (SEC_ALLOC
| SEC_SMALL_DATA
))
12679 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12680 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
12684 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
12685 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
12691 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
12693 /* Force alignment. */
12694 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
12695 TOCstart
-= adjust
;
12696 _bfd_set_gp_value (obfd
, TOCstart
);
12698 if (info
!= NULL
&& s
!= NULL
)
12700 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12704 if (htab
->elf
.hgot
!= NULL
)
12706 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
12707 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
12712 struct bfd_link_hash_entry
*bh
= NULL
;
12713 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
12714 s
, TOC_BASE_OFF
- adjust
,
12715 NULL
, FALSE
, FALSE
, &bh
);
12721 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
12722 write out any global entry stubs. */
12725 build_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
12727 struct bfd_link_info
*info
;
12728 struct ppc_link_hash_table
*htab
;
12729 struct plt_entry
*pent
;
12732 if (h
->root
.type
== bfd_link_hash_indirect
)
12735 if (!h
->pointer_equality_needed
)
12738 if (h
->def_regular
)
12742 htab
= ppc_hash_table (info
);
12747 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
12748 if (pent
->plt
.offset
!= (bfd_vma
) -1
12749 && pent
->addend
== 0)
12755 p
= s
->contents
+ h
->root
.u
.def
.value
;
12756 plt
= htab
->elf
.splt
;
12757 if (!htab
->elf
.dynamic_sections_created
12758 || h
->dynindx
== -1)
12759 plt
= htab
->elf
.iplt
;
12760 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
12761 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
12763 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
12765 info
->callbacks
->einfo
12766 (_("%P: linkage table error against `%T'\n"),
12767 h
->root
.root
.string
);
12768 bfd_set_error (bfd_error_bad_value
);
12769 htab
->stub_error
= TRUE
;
12772 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
12773 if (htab
->params
->emit_stub_syms
)
12775 size_t len
= strlen (h
->root
.root
.string
);
12776 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
12781 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
12782 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
12785 if (h
->root
.type
== bfd_link_hash_new
)
12787 h
->root
.type
= bfd_link_hash_defined
;
12788 h
->root
.u
.def
.section
= s
;
12789 h
->root
.u
.def
.value
= p
- s
->contents
;
12790 h
->ref_regular
= 1;
12791 h
->def_regular
= 1;
12792 h
->ref_regular_nonweak
= 1;
12793 h
->forced_local
= 1;
12795 h
->root
.linker_def
= 1;
12799 if (PPC_HA (off
) != 0)
12801 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
12804 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
12806 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
12808 bfd_put_32 (s
->owner
, BCTR
, p
);
12814 /* Build all the stubs associated with the current output file.
12815 The stubs are kept in a hash table attached to the main linker
12816 hash table. This function is called via gldelf64ppc_finish. */
12819 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
12822 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12823 struct map_stub
*group
;
12824 asection
*stub_sec
;
12826 int stub_sec_count
= 0;
12831 /* Allocate memory to hold the linker stubs. */
12832 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
12834 stub_sec
= stub_sec
->next
)
12835 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
12836 && stub_sec
->size
!= 0)
12838 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
, stub_sec
->size
);
12839 if (stub_sec
->contents
== NULL
)
12841 /* We want to check that built size is the same as calculated
12842 size. rawsize is a convenient location to use. */
12843 stub_sec
->rawsize
= stub_sec
->size
;
12844 stub_sec
->size
= 0;
12847 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
12852 /* Build the .glink plt call stub. */
12853 if (htab
->params
->emit_stub_syms
)
12855 struct elf_link_hash_entry
*h
;
12856 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
12857 TRUE
, FALSE
, FALSE
);
12860 if (h
->root
.type
== bfd_link_hash_new
)
12862 h
->root
.type
= bfd_link_hash_defined
;
12863 h
->root
.u
.def
.section
= htab
->glink
;
12864 h
->root
.u
.def
.value
= 8;
12865 h
->ref_regular
= 1;
12866 h
->def_regular
= 1;
12867 h
->ref_regular_nonweak
= 1;
12868 h
->forced_local
= 1;
12870 h
->root
.linker_def
= 1;
12873 plt0
= (htab
->elf
.splt
->output_section
->vma
12874 + htab
->elf
.splt
->output_offset
12876 if (info
->emitrelocations
)
12878 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
12881 r
->r_offset
= (htab
->glink
->output_offset
12882 + htab
->glink
->output_section
->vma
);
12883 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
12884 r
->r_addend
= plt0
;
12886 p
= htab
->glink
->contents
;
12887 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
12888 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
12892 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
12894 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
12896 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
12898 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
12900 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
12902 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
12904 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
12906 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
12908 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
12910 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
12915 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
12917 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
12919 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
12921 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
12923 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
12925 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
12927 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
12929 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
12931 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
12933 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
12935 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
12937 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
12940 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
12942 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
12944 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
12948 /* Build the .glink lazy link call stubs. */
12950 while (p
< htab
->glink
->contents
+ htab
->glink
->rawsize
)
12956 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
12961 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
12963 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
12968 bfd_put_32 (htab
->glink
->owner
,
12969 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
12974 /* Build .glink global entry stubs. */
12975 if (htab
->glink
->size
> htab
->glink
->rawsize
)
12976 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs
, info
);
12979 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
12981 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
12983 if (htab
->brlt
->contents
== NULL
)
12986 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
12988 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
12989 htab
->relbrlt
->size
);
12990 if (htab
->relbrlt
->contents
== NULL
)
12994 /* Build the stubs as directed by the stub hash table. */
12995 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
12997 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12998 if (group
->needs_save_res
)
13000 stub_sec
= group
->stub_sec
;
13001 memcpy (stub_sec
->contents
+ stub_sec
->size
, htab
->sfpr
->contents
,
13003 if (htab
->params
->emit_stub_syms
)
13007 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13008 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13011 stub_sec
->size
+= htab
->sfpr
->size
;
13014 if (htab
->relbrlt
!= NULL
)
13015 htab
->relbrlt
->reloc_count
= 0;
13017 if (htab
->params
->plt_stub_align
!= 0)
13018 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
13020 stub_sec
= stub_sec
->next
)
13021 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
13022 stub_sec
->size
= ((stub_sec
->size
13023 + (1 << htab
->params
->plt_stub_align
) - 1)
13024 & (-1 << htab
->params
->plt_stub_align
));
13026 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
13028 stub_sec
= stub_sec
->next
)
13029 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
13031 stub_sec_count
+= 1;
13032 if (stub_sec
->rawsize
!= stub_sec
->size
)
13036 /* Note that the glink_eh_frame check here is not only testing that
13037 the generated size matched the calculated size but also that
13038 bfd_elf_discard_info didn't make any changes to the section. */
13039 if (stub_sec
!= NULL
13040 || (htab
->glink_eh_frame
!= NULL
13041 && htab
->glink_eh_frame
->rawsize
!= htab
->glink_eh_frame
->size
))
13043 htab
->stub_error
= TRUE
;
13044 info
->callbacks
->einfo (_("%P: stubs don't match calculated size\n"));
13047 if (htab
->stub_error
)
13052 *stats
= bfd_malloc (500);
13053 if (*stats
== NULL
)
13056 sprintf (*stats
, _("linker stubs in %u group%s\n"
13058 " toc adjust %lu\n"
13059 " long branch %lu\n"
13060 " long toc adj %lu\n"
13062 " plt call toc %lu\n"
13063 " global entry %lu"),
13065 stub_sec_count
== 1 ? "" : "s",
13066 htab
->stub_count
[ppc_stub_long_branch
- 1],
13067 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13068 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13069 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13070 htab
->stub_count
[ppc_stub_plt_call
- 1],
13071 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13072 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13077 /* This function undoes the changes made by add_symbol_adjust. */
13080 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
13082 struct ppc_link_hash_entry
*eh
;
13084 if (h
->root
.type
== bfd_link_hash_indirect
)
13087 eh
= (struct ppc_link_hash_entry
*) h
;
13088 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
13091 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
13096 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
13098 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13101 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
13104 /* What to do when ld finds relocations against symbols defined in
13105 discarded sections. */
13107 static unsigned int
13108 ppc64_elf_action_discarded (asection
*sec
)
13110 if (strcmp (".opd", sec
->name
) == 0)
13113 if (strcmp (".toc", sec
->name
) == 0)
13116 if (strcmp (".toc1", sec
->name
) == 0)
13119 return _bfd_elf_default_action_discarded (sec
);
13122 /* The RELOCATE_SECTION function is called by the ELF backend linker
13123 to handle the relocations for a section.
13125 The relocs are always passed as Rela structures; if the section
13126 actually uses Rel structures, the r_addend field will always be
13129 This function is responsible for adjust the section contents as
13130 necessary, and (if using Rela relocs and generating a
13131 relocatable output file) adjusting the reloc addend as
13134 This function does not have to worry about setting the reloc
13135 address or the reloc symbol index.
13137 LOCAL_SYMS is a pointer to the swapped in local symbols.
13139 LOCAL_SECTIONS is an array giving the section in the input file
13140 corresponding to the st_shndx field of each local symbol.
13142 The global hash table entry for the global symbols can be found
13143 via elf_sym_hashes (input_bfd).
13145 When generating relocatable output, this function must handle
13146 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13147 going to be the section symbol corresponding to the output
13148 section, which means that the addend must be adjusted
13152 ppc64_elf_relocate_section (bfd
*output_bfd
,
13153 struct bfd_link_info
*info
,
13155 asection
*input_section
,
13156 bfd_byte
*contents
,
13157 Elf_Internal_Rela
*relocs
,
13158 Elf_Internal_Sym
*local_syms
,
13159 asection
**local_sections
)
13161 struct ppc_link_hash_table
*htab
;
13162 Elf_Internal_Shdr
*symtab_hdr
;
13163 struct elf_link_hash_entry
**sym_hashes
;
13164 Elf_Internal_Rela
*rel
;
13165 Elf_Internal_Rela
*relend
;
13166 Elf_Internal_Rela outrel
;
13168 struct got_entry
**local_got_ents
;
13170 bfd_boolean ret
= TRUE
;
13171 bfd_boolean is_opd
;
13172 /* Assume 'at' branch hints. */
13173 bfd_boolean is_isa_v2
= TRUE
;
13174 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
13176 /* Initialize howto table if needed. */
13177 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13180 htab
= ppc_hash_table (info
);
13184 /* Don't relocate stub sections. */
13185 if (input_section
->owner
== htab
->params
->stub_bfd
)
13188 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13190 local_got_ents
= elf_local_got_ents (input_bfd
);
13191 TOCstart
= elf_gp (output_bfd
);
13192 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13193 sym_hashes
= elf_sym_hashes (input_bfd
);
13194 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13197 relend
= relocs
+ input_section
->reloc_count
;
13198 for (; rel
< relend
; rel
++)
13200 enum elf_ppc64_reloc_type r_type
;
13202 bfd_reloc_status_type r
;
13203 Elf_Internal_Sym
*sym
;
13205 struct elf_link_hash_entry
*h_elf
;
13206 struct ppc_link_hash_entry
*h
;
13207 struct ppc_link_hash_entry
*fdh
;
13208 const char *sym_name
;
13209 unsigned long r_symndx
, toc_symndx
;
13210 bfd_vma toc_addend
;
13211 unsigned char tls_mask
, tls_gd
, tls_type
;
13212 unsigned char sym_type
;
13213 bfd_vma relocation
;
13214 bfd_boolean unresolved_reloc
;
13215 bfd_boolean warned
;
13216 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13219 struct ppc_stub_hash_entry
*stub_entry
;
13220 bfd_vma max_br_offset
;
13222 const Elf_Internal_Rela orig_rel
= *rel
;
13223 reloc_howto_type
*howto
;
13224 struct reloc_howto_struct alt_howto
;
13226 r_type
= ELF64_R_TYPE (rel
->r_info
);
13227 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13229 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13230 symbol of the previous ADDR64 reloc. The symbol gives us the
13231 proper TOC base to use. */
13232 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13234 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
13236 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
13242 unresolved_reloc
= FALSE
;
13245 if (r_symndx
< symtab_hdr
->sh_info
)
13247 /* It's a local symbol. */
13248 struct _opd_sec_data
*opd
;
13250 sym
= local_syms
+ r_symndx
;
13251 sec
= local_sections
[r_symndx
];
13252 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
13253 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
13254 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
13255 opd
= get_opd_info (sec
);
13256 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
13258 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
13264 /* If this is a relocation against the opd section sym
13265 and we have edited .opd, adjust the reloc addend so
13266 that ld -r and ld --emit-relocs output is correct.
13267 If it is a reloc against some other .opd symbol,
13268 then the symbol value will be adjusted later. */
13269 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
13270 rel
->r_addend
+= adjust
;
13272 relocation
+= adjust
;
13278 bfd_boolean ignored
;
13280 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
13281 r_symndx
, symtab_hdr
, sym_hashes
,
13282 h_elf
, sec
, relocation
,
13283 unresolved_reloc
, warned
, ignored
);
13284 sym_name
= h_elf
->root
.root
.string
;
13285 sym_type
= h_elf
->type
;
13287 && sec
->owner
== output_bfd
13288 && strcmp (sec
->name
, ".opd") == 0)
13290 /* This is a symbol defined in a linker script. All
13291 such are defined in output sections, even those
13292 defined by simple assignment from a symbol defined in
13293 an input section. Transfer the symbol to an
13294 appropriate input .opd section, so that a branch to
13295 this symbol will be mapped to the location specified
13296 by the opd entry. */
13297 struct bfd_link_order
*lo
;
13298 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
13299 if (lo
->type
== bfd_indirect_link_order
)
13301 asection
*isec
= lo
->u
.indirect
.section
;
13302 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
13303 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
13306 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
13307 h_elf
->root
.u
.def
.section
= isec
;
13314 h
= (struct ppc_link_hash_entry
*) h_elf
;
13316 if (sec
!= NULL
&& discarded_section (sec
))
13317 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
13319 ppc64_elf_howto_table
[r_type
], 0,
13322 if (bfd_link_relocatable (info
))
13325 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
13327 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
13328 sec
= bfd_abs_section_ptr
;
13329 unresolved_reloc
= FALSE
;
13332 /* TLS optimizations. Replace instruction sequences and relocs
13333 based on information we collected in tls_optimize. We edit
13334 RELOCS so that --emit-relocs will output something sensible
13335 for the final instruction stream. */
13340 tls_mask
= h
->tls_mask
;
13341 else if (local_got_ents
!= NULL
)
13343 struct plt_entry
**local_plt
= (struct plt_entry
**)
13344 (local_got_ents
+ symtab_hdr
->sh_info
);
13345 unsigned char *lgot_masks
= (unsigned char *)
13346 (local_plt
+ symtab_hdr
->sh_info
);
13347 tls_mask
= lgot_masks
[r_symndx
];
13350 && (r_type
== R_PPC64_TLS
13351 || r_type
== R_PPC64_TLSGD
13352 || r_type
== R_PPC64_TLSLD
))
13354 /* Check for toc tls entries. */
13355 unsigned char *toc_tls
;
13357 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13358 &local_syms
, rel
, input_bfd
))
13362 tls_mask
= *toc_tls
;
13365 /* Check that tls relocs are used with tls syms, and non-tls
13366 relocs are used with non-tls syms. */
13367 if (r_symndx
!= STN_UNDEF
13368 && r_type
!= R_PPC64_NONE
13370 || h
->elf
.root
.type
== bfd_link_hash_defined
13371 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
13372 && (IS_PPC64_TLS_RELOC (r_type
)
13373 != (sym_type
== STT_TLS
13374 || (sym_type
== STT_SECTION
13375 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
13378 && (r_type
== R_PPC64_TLS
13379 || r_type
== R_PPC64_TLSGD
13380 || r_type
== R_PPC64_TLSLD
))
13381 /* R_PPC64_TLS is OK against a symbol in the TOC. */
13384 info
->callbacks
->einfo
13385 (!IS_PPC64_TLS_RELOC (r_type
)
13386 ? _("%P: %H: %s used with TLS symbol `%T'\n")
13387 : _("%P: %H: %s used with non-TLS symbol `%T'\n"),
13388 input_bfd
, input_section
, rel
->r_offset
,
13389 ppc64_elf_howto_table
[r_type
]->name
,
13393 /* Ensure reloc mapping code below stays sane. */
13394 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
13395 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
13396 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
13397 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
13398 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
13399 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
13400 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
13401 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
13402 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
13403 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
13411 case R_PPC64_LO_DS_OPT
:
13412 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
13413 if ((insn
& (0x3f << 26)) != 58u << 26)
13415 insn
+= (14u << 26) - (58u << 26);
13416 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13417 r_type
= R_PPC64_TOC16_LO
;
13418 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13421 case R_PPC64_TOC16
:
13422 case R_PPC64_TOC16_LO
:
13423 case R_PPC64_TOC16_DS
:
13424 case R_PPC64_TOC16_LO_DS
:
13426 /* Check for toc tls entries. */
13427 unsigned char *toc_tls
;
13430 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
13431 &local_syms
, rel
, input_bfd
);
13437 tls_mask
= *toc_tls
;
13438 if (r_type
== R_PPC64_TOC16_DS
13439 || r_type
== R_PPC64_TOC16_LO_DS
)
13442 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
13447 /* If we found a GD reloc pair, then we might be
13448 doing a GD->IE transition. */
13451 tls_gd
= TLS_TPRELGD
;
13452 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13455 else if (retval
== 3)
13457 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13465 case R_PPC64_GOT_TPREL16_HI
:
13466 case R_PPC64_GOT_TPREL16_HA
:
13468 && (tls_mask
& TLS_TPREL
) == 0)
13470 rel
->r_offset
-= d_offset
;
13471 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
13472 r_type
= R_PPC64_NONE
;
13473 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13477 case R_PPC64_GOT_TPREL16_DS
:
13478 case R_PPC64_GOT_TPREL16_LO_DS
:
13480 && (tls_mask
& TLS_TPREL
) == 0)
13483 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
13485 insn
|= 0x3c0d0000; /* addis 0,13,0 */
13486 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
13487 r_type
= R_PPC64_TPREL16_HA
;
13488 if (toc_symndx
!= 0)
13490 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13491 rel
->r_addend
= toc_addend
;
13492 /* We changed the symbol. Start over in order to
13493 get h, sym, sec etc. right. */
13498 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13504 && (tls_mask
& TLS_TPREL
) == 0)
13506 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
13507 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
13510 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
13511 /* Was PPC64_TLS which sits on insn boundary, now
13512 PPC64_TPREL16_LO which is at low-order half-word. */
13513 rel
->r_offset
+= d_offset
;
13514 r_type
= R_PPC64_TPREL16_LO
;
13515 if (toc_symndx
!= 0)
13517 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
13518 rel
->r_addend
= toc_addend
;
13519 /* We changed the symbol. Start over in order to
13520 get h, sym, sec etc. right. */
13525 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13529 case R_PPC64_GOT_TLSGD16_HI
:
13530 case R_PPC64_GOT_TLSGD16_HA
:
13531 tls_gd
= TLS_TPRELGD
;
13532 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13536 case R_PPC64_GOT_TLSLD16_HI
:
13537 case R_PPC64_GOT_TLSLD16_HA
:
13538 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13541 if ((tls_mask
& tls_gd
) != 0)
13542 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13543 + R_PPC64_GOT_TPREL16_DS
);
13546 rel
->r_offset
-= d_offset
;
13547 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
13548 r_type
= R_PPC64_NONE
;
13550 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13554 case R_PPC64_GOT_TLSGD16
:
13555 case R_PPC64_GOT_TLSGD16_LO
:
13556 tls_gd
= TLS_TPRELGD
;
13557 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13561 case R_PPC64_GOT_TLSLD16
:
13562 case R_PPC64_GOT_TLSLD16_LO
:
13563 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13565 unsigned int insn1
, insn2
, insn3
;
13569 offset
= (bfd_vma
) -1;
13570 /* If not using the newer R_PPC64_TLSGD/LD to mark
13571 __tls_get_addr calls, we must trust that the call
13572 stays with its arg setup insns, ie. that the next
13573 reloc is the __tls_get_addr call associated with
13574 the current reloc. Edit both insns. */
13575 if (input_section
->has_tls_get_addr_call
13576 && rel
+ 1 < relend
13577 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
13578 htab
->tls_get_addr
,
13579 htab
->tls_get_addr_fd
))
13580 offset
= rel
[1].r_offset
;
13581 /* We read the low GOT_TLS (or TOC16) insn because we
13582 need to keep the destination reg. It may be
13583 something other than the usual r3, and moved to r3
13584 before the call by intervening code. */
13585 insn1
= bfd_get_32 (output_bfd
,
13586 contents
+ rel
->r_offset
- d_offset
);
13587 if ((tls_mask
& tls_gd
) != 0)
13590 insn1
&= (0x1f << 21) | (0x1f << 16);
13591 insn1
|= 58 << 26; /* ld */
13592 insn2
= 0x7c636a14; /* add 3,3,13 */
13593 if (offset
!= (bfd_vma
) -1)
13594 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13595 if ((tls_mask
& TLS_EXPLICIT
) == 0)
13596 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
13597 + R_PPC64_GOT_TPREL16_DS
);
13599 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
13600 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13605 insn1
&= 0x1f << 21;
13606 insn1
|= 0x3c0d0000; /* addis r,13,0 */
13607 insn2
= 0x38630000; /* addi 3,3,0 */
13610 /* Was an LD reloc. */
13612 sec
= local_sections
[toc_symndx
];
13614 r_symndx
< symtab_hdr
->sh_info
;
13616 if (local_sections
[r_symndx
] == sec
)
13618 if (r_symndx
>= symtab_hdr
->sh_info
)
13619 r_symndx
= STN_UNDEF
;
13620 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13621 if (r_symndx
!= STN_UNDEF
)
13622 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13623 + sec
->output_offset
13624 + sec
->output_section
->vma
);
13626 else if (toc_symndx
!= 0)
13628 r_symndx
= toc_symndx
;
13629 rel
->r_addend
= toc_addend
;
13631 r_type
= R_PPC64_TPREL16_HA
;
13632 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13633 if (offset
!= (bfd_vma
) -1)
13635 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
13636 R_PPC64_TPREL16_LO
);
13637 rel
[1].r_offset
= offset
+ d_offset
;
13638 rel
[1].r_addend
= rel
->r_addend
;
13641 bfd_put_32 (output_bfd
, insn1
,
13642 contents
+ rel
->r_offset
- d_offset
);
13643 if (offset
!= (bfd_vma
) -1)
13645 insn3
= bfd_get_32 (output_bfd
,
13646 contents
+ offset
+ 4);
13648 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
13650 rel
[1].r_offset
+= 4;
13651 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
13654 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
13656 if ((tls_mask
& tls_gd
) == 0
13657 && (tls_gd
== 0 || toc_symndx
!= 0))
13659 /* We changed the symbol. Start over in order
13660 to get h, sym, sec etc. right. */
13667 case R_PPC64_TLSGD
:
13668 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
13670 unsigned int insn2
, insn3
;
13671 bfd_vma offset
= rel
->r_offset
;
13673 if ((tls_mask
& TLS_TPRELGD
) != 0)
13676 r_type
= R_PPC64_NONE
;
13677 insn2
= 0x7c636a14; /* add 3,3,13 */
13682 if (toc_symndx
!= 0)
13684 r_symndx
= toc_symndx
;
13685 rel
->r_addend
= toc_addend
;
13687 r_type
= R_PPC64_TPREL16_LO
;
13688 rel
->r_offset
= offset
+ d_offset
;
13689 insn2
= 0x38630000; /* addi 3,3,0 */
13691 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13692 /* Zap the reloc on the _tls_get_addr call too. */
13693 BFD_ASSERT (offset
== rel
[1].r_offset
);
13694 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13695 insn3
= bfd_get_32 (output_bfd
,
13696 contents
+ offset
+ 4);
13698 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
13700 rel
->r_offset
+= 4;
13701 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
13704 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
13705 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
13713 case R_PPC64_TLSLD
:
13714 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
13716 unsigned int insn2
, insn3
;
13717 bfd_vma offset
= rel
->r_offset
;
13720 sec
= local_sections
[toc_symndx
];
13722 r_symndx
< symtab_hdr
->sh_info
;
13724 if (local_sections
[r_symndx
] == sec
)
13726 if (r_symndx
>= symtab_hdr
->sh_info
)
13727 r_symndx
= STN_UNDEF
;
13728 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
13729 if (r_symndx
!= STN_UNDEF
)
13730 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
13731 + sec
->output_offset
13732 + sec
->output_section
->vma
);
13734 r_type
= R_PPC64_TPREL16_LO
;
13735 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13736 rel
->r_offset
= offset
+ d_offset
;
13737 /* Zap the reloc on the _tls_get_addr call too. */
13738 BFD_ASSERT (offset
== rel
[1].r_offset
);
13739 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
13740 insn2
= 0x38630000; /* addi 3,3,0 */
13741 insn3
= bfd_get_32 (output_bfd
,
13742 contents
+ offset
+ 4);
13744 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
13746 rel
->r_offset
+= 4;
13747 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
+ 4);
13750 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
13756 case R_PPC64_DTPMOD64
:
13757 if (rel
+ 1 < relend
13758 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
13759 && rel
[1].r_offset
== rel
->r_offset
+ 8)
13761 if ((tls_mask
& TLS_GD
) == 0)
13763 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
13764 if ((tls_mask
& TLS_TPRELGD
) != 0)
13765 r_type
= R_PPC64_TPREL64
;
13768 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13769 r_type
= R_PPC64_NONE
;
13771 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13776 if ((tls_mask
& TLS_LD
) == 0)
13778 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
13779 r_type
= R_PPC64_NONE
;
13780 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13785 case R_PPC64_TPREL64
:
13786 if ((tls_mask
& TLS_TPREL
) == 0)
13788 r_type
= R_PPC64_NONE
;
13789 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13793 case R_PPC64_REL16_HA
:
13794 /* If we are generating a non-PIC executable, edit
13795 . 0: addis 2,12,.TOC.-0b@ha
13796 . addi 2,2,.TOC.-0b@l
13797 used by ELFv2 global entry points to set up r2, to
13800 if .TOC. is in range. */
13801 if (!bfd_link_pic (info
)
13802 && !info
->traditional_format
13803 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
13804 && rel
+ 1 < relend
13805 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
13806 && rel
[1].r_offset
== rel
->r_offset
+ 4
13807 && rel
[1].r_addend
== rel
->r_addend
+ 4
13808 && relocation
+ 0x80008000 <= 0xffffffff)
13810 unsigned int insn1
, insn2
;
13811 bfd_vma offset
= rel
->r_offset
- d_offset
;
13812 insn1
= bfd_get_32 (output_bfd
, contents
+ offset
);
13813 insn2
= bfd_get_32 (output_bfd
, contents
+ offset
+ 4);
13814 if ((insn1
& 0xffff0000) == 0x3c4c0000 /* addis 2,12 */
13815 && (insn2
& 0xffff0000) == 0x38420000 /* addi 2,2 */)
13817 r_type
= R_PPC64_ADDR16_HA
;
13818 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
13819 rel
->r_addend
-= d_offset
;
13820 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
13821 rel
[1].r_addend
-= d_offset
+ 4;
13822 bfd_put_32 (output_bfd
, 0x3c400000, contents
+ offset
);
13828 /* Handle other relocations that tweak non-addend part of insn. */
13830 max_br_offset
= 1 << 25;
13831 addend
= rel
->r_addend
;
13832 reloc_dest
= DEST_NORMAL
;
13838 case R_PPC64_TOCSAVE
:
13839 if (relocation
+ addend
== (rel
->r_offset
13840 + input_section
->output_offset
13841 + input_section
->output_section
->vma
)
13842 && tocsave_find (htab
, NO_INSERT
,
13843 &local_syms
, rel
, input_bfd
))
13845 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
13847 || insn
== CROR_151515
|| insn
== CROR_313131
)
13848 bfd_put_32 (input_bfd
,
13849 STD_R2_0R1
+ STK_TOC (htab
),
13850 contents
+ rel
->r_offset
);
13854 /* Branch taken prediction relocations. */
13855 case R_PPC64_ADDR14_BRTAKEN
:
13856 case R_PPC64_REL14_BRTAKEN
:
13857 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
13860 /* Branch not taken prediction relocations. */
13861 case R_PPC64_ADDR14_BRNTAKEN
:
13862 case R_PPC64_REL14_BRNTAKEN
:
13863 insn
|= bfd_get_32 (output_bfd
,
13864 contents
+ rel
->r_offset
) & ~(0x01 << 21);
13867 case R_PPC64_REL14
:
13868 max_br_offset
= 1 << 15;
13871 case R_PPC64_REL24
:
13872 /* Calls to functions with a different TOC, such as calls to
13873 shared objects, need to alter the TOC pointer. This is
13874 done using a linkage stub. A REL24 branching to these
13875 linkage stubs needs to be followed by a nop, as the nop
13876 will be replaced with an instruction to restore the TOC
13881 && h
->oh
->is_func_descriptor
)
13882 fdh
= ppc_follow_link (h
->oh
);
13883 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
13885 if (stub_entry
!= NULL
13886 && (stub_entry
->stub_type
== ppc_stub_plt_call
13887 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
13888 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
13889 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
13891 bfd_boolean can_plt_call
= FALSE
;
13893 /* All of these stubs will modify r2, so there must be a
13894 branch and link followed by a nop. The nop is
13895 replaced by an insn to restore r2. */
13896 if (rel
->r_offset
+ 8 <= input_section
->size
)
13900 br
= bfd_get_32 (input_bfd
,
13901 contents
+ rel
->r_offset
);
13906 nop
= bfd_get_32 (input_bfd
,
13907 contents
+ rel
->r_offset
+ 4);
13909 || nop
== CROR_151515
|| nop
== CROR_313131
)
13912 && (h
== htab
->tls_get_addr_fd
13913 || h
== htab
->tls_get_addr
)
13914 && !htab
->params
->no_tls_get_addr_opt
)
13916 /* Special stub used, leave nop alone. */
13919 bfd_put_32 (input_bfd
,
13920 LD_R2_0R1
+ STK_TOC (htab
),
13921 contents
+ rel
->r_offset
+ 4);
13922 can_plt_call
= TRUE
;
13927 if (!can_plt_call
&& h
!= NULL
)
13929 const char *name
= h
->elf
.root
.root
.string
;
13934 if (strncmp (name
, "__libc_start_main", 17) == 0
13935 && (name
[17] == 0 || name
[17] == '@'))
13937 /* Allow crt1 branch to go via a toc adjusting
13938 stub. Other calls that never return could do
13939 the same, if we could detect such. */
13940 can_plt_call
= TRUE
;
13946 /* g++ as of 20130507 emits self-calls without a
13947 following nop. This is arguably wrong since we
13948 have conflicting information. On the one hand a
13949 global symbol and on the other a local call
13950 sequence, but don't error for this special case.
13951 It isn't possible to cheaply verify we have
13952 exactly such a call. Allow all calls to the same
13954 asection
*code_sec
= sec
;
13956 if (get_opd_info (sec
) != NULL
)
13958 bfd_vma off
= (relocation
+ addend
13959 - sec
->output_section
->vma
13960 - sec
->output_offset
);
13962 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
13964 if (code_sec
== input_section
)
13965 can_plt_call
= TRUE
;
13970 if (stub_entry
->stub_type
== ppc_stub_plt_call
13971 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
13972 info
->callbacks
->einfo
13973 (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
13974 "recompile with -fPIC\n"),
13975 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
13977 info
->callbacks
->einfo
13978 (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
13979 "(-mcmodel=small toc adjust stub)\n"),
13980 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
13982 bfd_set_error (bfd_error_bad_value
);
13987 && (stub_entry
->stub_type
== ppc_stub_plt_call
13988 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
13989 unresolved_reloc
= FALSE
;
13992 if ((stub_entry
== NULL
13993 || stub_entry
->stub_type
== ppc_stub_long_branch
13994 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
13995 && get_opd_info (sec
) != NULL
)
13997 /* The branch destination is the value of the opd entry. */
13998 bfd_vma off
= (relocation
+ addend
13999 - sec
->output_section
->vma
14000 - sec
->output_offset
);
14001 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14002 if (dest
!= (bfd_vma
) -1)
14006 reloc_dest
= DEST_OPD
;
14010 /* If the branch is out of reach we ought to have a long
14012 from
= (rel
->r_offset
14013 + input_section
->output_offset
14014 + input_section
->output_section
->vma
);
14016 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14020 if (stub_entry
!= NULL
14021 && (stub_entry
->stub_type
== ppc_stub_long_branch
14022 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14023 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14024 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14025 || (relocation
+ addend
- from
+ max_br_offset
14026 < 2 * max_br_offset
)))
14027 /* Don't use the stub if this branch is in range. */
14030 if (stub_entry
!= NULL
)
14032 /* Munge up the value and addend so that we call the stub
14033 rather than the procedure directly. */
14034 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14036 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14037 relocation
+= (stub_sec
->output_offset
14038 + stub_sec
->output_section
->vma
14039 + stub_sec
->size
- htab
->sfpr
->size
14040 - htab
->sfpr
->output_offset
14041 - htab
->sfpr
->output_section
->vma
);
14043 relocation
= (stub_entry
->stub_offset
14044 + stub_sec
->output_offset
14045 + stub_sec
->output_section
->vma
);
14047 reloc_dest
= DEST_STUB
;
14049 if ((stub_entry
->stub_type
== ppc_stub_plt_call
14050 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14051 && (ALWAYS_EMIT_R2SAVE
14052 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14053 && rel
+ 1 < relend
14054 && rel
[1].r_offset
== rel
->r_offset
+ 4
14055 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14063 /* Set 'a' bit. This is 0b00010 in BO field for branch
14064 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14065 for branch on CTR insns (BO == 1a00t or 1a01t). */
14066 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14067 insn
|= 0x02 << 21;
14068 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14069 insn
|= 0x08 << 21;
14075 /* Invert 'y' bit if not the default. */
14076 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14077 insn
^= 0x01 << 21;
14080 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
14083 /* NOP out calls to undefined weak functions.
14084 We can thus call a weak function without first
14085 checking whether the function is defined. */
14087 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14088 && h
->elf
.dynindx
== -1
14089 && r_type
== R_PPC64_REL24
14093 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
14099 /* Set `addend'. */
14104 info
->callbacks
->einfo
14105 (_("%P: %B: unknown relocation type %d for `%T'\n"),
14106 input_bfd
, (int) r_type
, sym_name
);
14108 bfd_set_error (bfd_error_bad_value
);
14114 case R_PPC64_TLSGD
:
14115 case R_PPC64_TLSLD
:
14116 case R_PPC64_TOCSAVE
:
14117 case R_PPC64_GNU_VTINHERIT
:
14118 case R_PPC64_GNU_VTENTRY
:
14121 /* GOT16 relocations. Like an ADDR16 using the symbol's
14122 address in the GOT as relocation value instead of the
14123 symbol's value itself. Also, create a GOT entry for the
14124 symbol and put the symbol value there. */
14125 case R_PPC64_GOT_TLSGD16
:
14126 case R_PPC64_GOT_TLSGD16_LO
:
14127 case R_PPC64_GOT_TLSGD16_HI
:
14128 case R_PPC64_GOT_TLSGD16_HA
:
14129 tls_type
= TLS_TLS
| TLS_GD
;
14132 case R_PPC64_GOT_TLSLD16
:
14133 case R_PPC64_GOT_TLSLD16_LO
:
14134 case R_PPC64_GOT_TLSLD16_HI
:
14135 case R_PPC64_GOT_TLSLD16_HA
:
14136 tls_type
= TLS_TLS
| TLS_LD
;
14139 case R_PPC64_GOT_TPREL16_DS
:
14140 case R_PPC64_GOT_TPREL16_LO_DS
:
14141 case R_PPC64_GOT_TPREL16_HI
:
14142 case R_PPC64_GOT_TPREL16_HA
:
14143 tls_type
= TLS_TLS
| TLS_TPREL
;
14146 case R_PPC64_GOT_DTPREL16_DS
:
14147 case R_PPC64_GOT_DTPREL16_LO_DS
:
14148 case R_PPC64_GOT_DTPREL16_HI
:
14149 case R_PPC64_GOT_DTPREL16_HA
:
14150 tls_type
= TLS_TLS
| TLS_DTPREL
;
14153 case R_PPC64_GOT16
:
14154 case R_PPC64_GOT16_LO
:
14155 case R_PPC64_GOT16_HI
:
14156 case R_PPC64_GOT16_HA
:
14157 case R_PPC64_GOT16_DS
:
14158 case R_PPC64_GOT16_LO_DS
:
14161 /* Relocation is to the entry for this symbol in the global
14166 unsigned long indx
= 0;
14167 struct got_entry
*ent
;
14169 if (tls_type
== (TLS_TLS
| TLS_LD
)
14171 || !h
->elf
.def_dynamic
))
14172 ent
= ppc64_tlsld_got (input_bfd
);
14178 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
14179 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, bfd_link_pic (info
),
14181 || (bfd_link_pic (info
)
14182 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
14183 /* This is actually a static link, or it is a
14184 -Bsymbolic link and the symbol is defined
14185 locally, or the symbol was forced to be local
14186 because of a version file. */
14190 BFD_ASSERT (h
->elf
.dynindx
!= -1);
14191 indx
= h
->elf
.dynindx
;
14192 unresolved_reloc
= FALSE
;
14194 ent
= h
->elf
.got
.glist
;
14198 if (local_got_ents
== NULL
)
14200 ent
= local_got_ents
[r_symndx
];
14203 for (; ent
!= NULL
; ent
= ent
->next
)
14204 if (ent
->addend
== orig_rel
.r_addend
14205 && ent
->owner
== input_bfd
14206 && ent
->tls_type
== tls_type
)
14212 if (ent
->is_indirect
)
14213 ent
= ent
->got
.ent
;
14214 offp
= &ent
->got
.offset
;
14215 got
= ppc64_elf_tdata (ent
->owner
)->got
;
14219 /* The offset must always be a multiple of 8. We use the
14220 least significant bit to record whether we have already
14221 processed this entry. */
14223 if ((off
& 1) != 0)
14227 /* Generate relocs for the dynamic linker, except in
14228 the case of TLSLD where we'll use one entry per
14236 ? h
->elf
.type
== STT_GNU_IFUNC
14237 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
14239 relgot
= htab
->elf
.irelplt
;
14240 else if ((bfd_link_pic (info
) || indx
!= 0)
14242 || (tls_type
== (TLS_TLS
| TLS_LD
)
14243 && !h
->elf
.def_dynamic
)
14244 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
14245 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
14246 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
14247 if (relgot
!= NULL
)
14249 outrel
.r_offset
= (got
->output_section
->vma
14250 + got
->output_offset
14252 outrel
.r_addend
= addend
;
14253 if (tls_type
& (TLS_LD
| TLS_GD
))
14255 outrel
.r_addend
= 0;
14256 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
14257 if (tls_type
== (TLS_TLS
| TLS_GD
))
14259 loc
= relgot
->contents
;
14260 loc
+= (relgot
->reloc_count
++
14261 * sizeof (Elf64_External_Rela
));
14262 bfd_elf64_swap_reloca_out (output_bfd
,
14264 outrel
.r_offset
+= 8;
14265 outrel
.r_addend
= addend
;
14267 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14270 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
14271 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
14272 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14273 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
14274 else if (indx
!= 0)
14275 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
14279 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14281 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14283 /* Write the .got section contents for the sake
14285 loc
= got
->contents
+ off
;
14286 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
14290 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
14292 outrel
.r_addend
+= relocation
;
14293 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
14295 if (htab
->elf
.tls_sec
== NULL
)
14296 outrel
.r_addend
= 0;
14298 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
14301 loc
= relgot
->contents
;
14302 loc
+= (relgot
->reloc_count
++
14303 * sizeof (Elf64_External_Rela
));
14304 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14307 /* Init the .got section contents here if we're not
14308 emitting a reloc. */
14311 relocation
+= addend
;
14312 if (tls_type
== (TLS_TLS
| TLS_LD
))
14314 else if (tls_type
!= 0)
14316 if (htab
->elf
.tls_sec
== NULL
)
14320 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14321 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
14322 relocation
+= DTP_OFFSET
- TP_OFFSET
;
14325 if (tls_type
== (TLS_TLS
| TLS_GD
))
14327 bfd_put_64 (output_bfd
, relocation
,
14328 got
->contents
+ off
+ 8);
14333 bfd_put_64 (output_bfd
, relocation
,
14334 got
->contents
+ off
);
14338 if (off
>= (bfd_vma
) -2)
14341 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
14342 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
14346 case R_PPC64_PLT16_HA
:
14347 case R_PPC64_PLT16_HI
:
14348 case R_PPC64_PLT16_LO
:
14349 case R_PPC64_PLT32
:
14350 case R_PPC64_PLT64
:
14351 /* Relocation is to the entry for this symbol in the
14352 procedure linkage table. */
14354 /* Resolve a PLT reloc against a local symbol directly,
14355 without using the procedure linkage table. */
14359 /* It's possible that we didn't make a PLT entry for this
14360 symbol. This happens when statically linking PIC code,
14361 or when using -Bsymbolic. Go find a match if there is a
14363 if (htab
->elf
.splt
!= NULL
)
14365 struct plt_entry
*ent
;
14366 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
14367 if (ent
->plt
.offset
!= (bfd_vma
) -1
14368 && ent
->addend
== orig_rel
.r_addend
)
14370 relocation
= (htab
->elf
.splt
->output_section
->vma
14371 + htab
->elf
.splt
->output_offset
14372 + ent
->plt
.offset
);
14373 unresolved_reloc
= FALSE
;
14380 /* Relocation value is TOC base. */
14381 relocation
= TOCstart
;
14382 if (r_symndx
== STN_UNDEF
)
14383 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
14384 else if (unresolved_reloc
)
14386 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
14387 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
14389 unresolved_reloc
= TRUE
;
14392 /* TOC16 relocs. We want the offset relative to the TOC base,
14393 which is the address of the start of the TOC plus 0x8000.
14394 The TOC consists of sections .got, .toc, .tocbss, and .plt,
14396 case R_PPC64_TOC16
:
14397 case R_PPC64_TOC16_LO
:
14398 case R_PPC64_TOC16_HI
:
14399 case R_PPC64_TOC16_DS
:
14400 case R_PPC64_TOC16_LO_DS
:
14401 case R_PPC64_TOC16_HA
:
14402 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14405 /* Relocate against the beginning of the section. */
14406 case R_PPC64_SECTOFF
:
14407 case R_PPC64_SECTOFF_LO
:
14408 case R_PPC64_SECTOFF_HI
:
14409 case R_PPC64_SECTOFF_DS
:
14410 case R_PPC64_SECTOFF_LO_DS
:
14411 case R_PPC64_SECTOFF_HA
:
14413 addend
-= sec
->output_section
->vma
;
14416 case R_PPC64_REL16
:
14417 case R_PPC64_REL16_LO
:
14418 case R_PPC64_REL16_HI
:
14419 case R_PPC64_REL16_HA
:
14422 case R_PPC64_REL14
:
14423 case R_PPC64_REL14_BRNTAKEN
:
14424 case R_PPC64_REL14_BRTAKEN
:
14425 case R_PPC64_REL24
:
14428 case R_PPC64_TPREL16
:
14429 case R_PPC64_TPREL16_LO
:
14430 case R_PPC64_TPREL16_HI
:
14431 case R_PPC64_TPREL16_HA
:
14432 case R_PPC64_TPREL16_DS
:
14433 case R_PPC64_TPREL16_LO_DS
:
14434 case R_PPC64_TPREL16_HIGH
:
14435 case R_PPC64_TPREL16_HIGHA
:
14436 case R_PPC64_TPREL16_HIGHER
:
14437 case R_PPC64_TPREL16_HIGHERA
:
14438 case R_PPC64_TPREL16_HIGHEST
:
14439 case R_PPC64_TPREL16_HIGHESTA
:
14441 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14442 && h
->elf
.dynindx
== -1)
14444 /* Make this relocation against an undefined weak symbol
14445 resolve to zero. This is really just a tweak, since
14446 code using weak externs ought to check that they are
14447 defined before using them. */
14448 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
14450 insn
= bfd_get_32 (output_bfd
, p
);
14451 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
14453 bfd_put_32 (output_bfd
, insn
, p
);
14456 if (htab
->elf
.tls_sec
!= NULL
)
14457 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14458 if (bfd_link_pic (info
))
14459 /* The TPREL16 relocs shouldn't really be used in shared
14460 libs as they will result in DT_TEXTREL being set, but
14461 support them anyway. */
14465 case R_PPC64_DTPREL16
:
14466 case R_PPC64_DTPREL16_LO
:
14467 case R_PPC64_DTPREL16_HI
:
14468 case R_PPC64_DTPREL16_HA
:
14469 case R_PPC64_DTPREL16_DS
:
14470 case R_PPC64_DTPREL16_LO_DS
:
14471 case R_PPC64_DTPREL16_HIGH
:
14472 case R_PPC64_DTPREL16_HIGHA
:
14473 case R_PPC64_DTPREL16_HIGHER
:
14474 case R_PPC64_DTPREL16_HIGHERA
:
14475 case R_PPC64_DTPREL16_HIGHEST
:
14476 case R_PPC64_DTPREL16_HIGHESTA
:
14477 if (htab
->elf
.tls_sec
!= NULL
)
14478 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14481 case R_PPC64_ADDR64_LOCAL
:
14482 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
14487 case R_PPC64_DTPMOD64
:
14492 case R_PPC64_TPREL64
:
14493 if (htab
->elf
.tls_sec
!= NULL
)
14494 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
14497 case R_PPC64_DTPREL64
:
14498 if (htab
->elf
.tls_sec
!= NULL
)
14499 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14502 /* Relocations that may need to be propagated if this is a
14504 case R_PPC64_REL30
:
14505 case R_PPC64_REL32
:
14506 case R_PPC64_REL64
:
14507 case R_PPC64_ADDR14
:
14508 case R_PPC64_ADDR14_BRNTAKEN
:
14509 case R_PPC64_ADDR14_BRTAKEN
:
14510 case R_PPC64_ADDR16
:
14511 case R_PPC64_ADDR16_DS
:
14512 case R_PPC64_ADDR16_HA
:
14513 case R_PPC64_ADDR16_HI
:
14514 case R_PPC64_ADDR16_HIGH
:
14515 case R_PPC64_ADDR16_HIGHA
:
14516 case R_PPC64_ADDR16_HIGHER
:
14517 case R_PPC64_ADDR16_HIGHERA
:
14518 case R_PPC64_ADDR16_HIGHEST
:
14519 case R_PPC64_ADDR16_HIGHESTA
:
14520 case R_PPC64_ADDR16_LO
:
14521 case R_PPC64_ADDR16_LO_DS
:
14522 case R_PPC64_ADDR24
:
14523 case R_PPC64_ADDR32
:
14524 case R_PPC64_ADDR64
:
14525 case R_PPC64_UADDR16
:
14526 case R_PPC64_UADDR32
:
14527 case R_PPC64_UADDR64
:
14529 if ((input_section
->flags
& SEC_ALLOC
) == 0)
14532 if (NO_OPD_RELOCS
&& is_opd
)
14535 if ((bfd_link_pic (info
)
14537 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
14538 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
14539 && (must_be_dyn_reloc (info
, r_type
)
14540 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
14541 || (ELIMINATE_COPY_RELOCS
14542 && !bfd_link_pic (info
)
14544 && h
->elf
.dynindx
!= -1
14545 && !h
->elf
.non_got_ref
14546 && !h
->elf
.def_regular
)
14547 || (!bfd_link_pic (info
)
14549 ? h
->elf
.type
== STT_GNU_IFUNC
14550 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)))
14552 bfd_boolean skip
, relocate
;
14556 /* When generating a dynamic object, these relocations
14557 are copied into the output file to be resolved at run
14563 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
14564 input_section
, rel
->r_offset
);
14565 if (out_off
== (bfd_vma
) -1)
14567 else if (out_off
== (bfd_vma
) -2)
14568 skip
= TRUE
, relocate
= TRUE
;
14569 out_off
+= (input_section
->output_section
->vma
14570 + input_section
->output_offset
);
14571 outrel
.r_offset
= out_off
;
14572 outrel
.r_addend
= rel
->r_addend
;
14574 /* Optimize unaligned reloc use. */
14575 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
14576 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
14577 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
14578 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
14579 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
14580 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
14581 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
14582 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
14583 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
14586 memset (&outrel
, 0, sizeof outrel
);
14587 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
14589 && r_type
!= R_PPC64_TOC
)
14591 BFD_ASSERT (h
->elf
.dynindx
!= -1);
14592 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
14596 /* This symbol is local, or marked to become local,
14597 or this is an opd section reloc which must point
14598 at a local function. */
14599 outrel
.r_addend
+= relocation
;
14600 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
14602 if (is_opd
&& h
!= NULL
)
14604 /* Lie about opd entries. This case occurs
14605 when building shared libraries and we
14606 reference a function in another shared
14607 lib. The same thing happens for a weak
14608 definition in an application that's
14609 overridden by a strong definition in a
14610 shared lib. (I believe this is a generic
14611 bug in binutils handling of weak syms.)
14612 In these cases we won't use the opd
14613 entry in this lib. */
14614 unresolved_reloc
= FALSE
;
14617 && r_type
== R_PPC64_ADDR64
14619 ? h
->elf
.type
== STT_GNU_IFUNC
14620 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
14621 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
14624 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
14626 /* We need to relocate .opd contents for ld.so.
14627 Prelink also wants simple and consistent rules
14628 for relocs. This make all RELATIVE relocs have
14629 *r_offset equal to r_addend. */
14638 ? h
->elf
.type
== STT_GNU_IFUNC
14639 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14641 info
->callbacks
->einfo
14642 (_("%P: %H: %s for indirect "
14643 "function `%T' unsupported\n"),
14644 input_bfd
, input_section
, rel
->r_offset
,
14645 ppc64_elf_howto_table
[r_type
]->name
,
14649 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
14651 else if (sec
== NULL
|| sec
->owner
== NULL
)
14653 bfd_set_error (bfd_error_bad_value
);
14660 osec
= sec
->output_section
;
14661 indx
= elf_section_data (osec
)->dynindx
;
14665 if ((osec
->flags
& SEC_READONLY
) == 0
14666 && htab
->elf
.data_index_section
!= NULL
)
14667 osec
= htab
->elf
.data_index_section
;
14669 osec
= htab
->elf
.text_index_section
;
14670 indx
= elf_section_data (osec
)->dynindx
;
14672 BFD_ASSERT (indx
!= 0);
14674 /* We are turning this relocation into one
14675 against a section symbol, so subtract out
14676 the output section's address but not the
14677 offset of the input section in the output
14679 outrel
.r_addend
-= osec
->vma
;
14682 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
14686 sreloc
= elf_section_data (input_section
)->sreloc
;
14688 ? h
->elf
.type
== STT_GNU_IFUNC
14689 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
14690 sreloc
= htab
->elf
.irelplt
;
14691 if (sreloc
== NULL
)
14694 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
14697 loc
= sreloc
->contents
;
14698 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
14699 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
14701 /* If this reloc is against an external symbol, it will
14702 be computed at runtime, so there's no need to do
14703 anything now. However, for the sake of prelink ensure
14704 that the section contents are a known value. */
14707 unresolved_reloc
= FALSE
;
14708 /* The value chosen here is quite arbitrary as ld.so
14709 ignores section contents except for the special
14710 case of .opd where the contents might be accessed
14711 before relocation. Choose zero, as that won't
14712 cause reloc overflow. */
14715 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
14716 to improve backward compatibility with older
14718 if (r_type
== R_PPC64_ADDR64
)
14719 addend
= outrel
.r_addend
;
14720 /* Adjust pc_relative relocs to have zero in *r_offset. */
14721 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
14722 addend
= (input_section
->output_section
->vma
14723 + input_section
->output_offset
14730 case R_PPC64_GLOB_DAT
:
14731 case R_PPC64_JMP_SLOT
:
14732 case R_PPC64_JMP_IREL
:
14733 case R_PPC64_RELATIVE
:
14734 /* We shouldn't ever see these dynamic relocs in relocatable
14736 /* Fall through. */
14738 case R_PPC64_PLTGOT16
:
14739 case R_PPC64_PLTGOT16_DS
:
14740 case R_PPC64_PLTGOT16_HA
:
14741 case R_PPC64_PLTGOT16_HI
:
14742 case R_PPC64_PLTGOT16_LO
:
14743 case R_PPC64_PLTGOT16_LO_DS
:
14744 case R_PPC64_PLTREL32
:
14745 case R_PPC64_PLTREL64
:
14746 /* These ones haven't been implemented yet. */
14748 info
->callbacks
->einfo
14749 (_("%P: %B: %s is not supported for `%T'\n"),
14751 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
14753 bfd_set_error (bfd_error_invalid_operation
);
14758 /* Multi-instruction sequences that access the TOC can be
14759 optimized, eg. addis ra,r2,0; addi rb,ra,x;
14760 to nop; addi rb,r2,x; */
14766 case R_PPC64_GOT_TLSLD16_HI
:
14767 case R_PPC64_GOT_TLSGD16_HI
:
14768 case R_PPC64_GOT_TPREL16_HI
:
14769 case R_PPC64_GOT_DTPREL16_HI
:
14770 case R_PPC64_GOT16_HI
:
14771 case R_PPC64_TOC16_HI
:
14772 /* These relocs would only be useful if building up an
14773 offset to later add to r2, perhaps in an indexed
14774 addressing mode instruction. Don't try to optimize.
14775 Unfortunately, the possibility of someone building up an
14776 offset like this or even with the HA relocs, means that
14777 we need to check the high insn when optimizing the low
14781 case R_PPC64_GOT_TLSLD16_HA
:
14782 case R_PPC64_GOT_TLSGD16_HA
:
14783 case R_PPC64_GOT_TPREL16_HA
:
14784 case R_PPC64_GOT_DTPREL16_HA
:
14785 case R_PPC64_GOT16_HA
:
14786 case R_PPC64_TOC16_HA
:
14787 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
14788 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
14790 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
14791 bfd_put_32 (input_bfd
, NOP
, p
);
14795 case R_PPC64_GOT_TLSLD16_LO
:
14796 case R_PPC64_GOT_TLSGD16_LO
:
14797 case R_PPC64_GOT_TPREL16_LO_DS
:
14798 case R_PPC64_GOT_DTPREL16_LO_DS
:
14799 case R_PPC64_GOT16_LO
:
14800 case R_PPC64_GOT16_LO_DS
:
14801 case R_PPC64_TOC16_LO
:
14802 case R_PPC64_TOC16_LO_DS
:
14803 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
14804 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
14806 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
14807 insn
= bfd_get_32 (input_bfd
, p
);
14808 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
14810 /* Transform addic to addi when we change reg. */
14811 insn
&= ~((0x3f << 26) | (0x1f << 16));
14812 insn
|= (14u << 26) | (2 << 16);
14816 insn
&= ~(0x1f << 16);
14819 bfd_put_32 (input_bfd
, insn
, p
);
14824 /* Do any further special processing. */
14825 howto
= ppc64_elf_howto_table
[(int) r_type
];
14831 case R_PPC64_REL16_HA
:
14832 case R_PPC64_ADDR16_HA
:
14833 case R_PPC64_ADDR16_HIGHA
:
14834 case R_PPC64_ADDR16_HIGHERA
:
14835 case R_PPC64_ADDR16_HIGHESTA
:
14836 case R_PPC64_TOC16_HA
:
14837 case R_PPC64_SECTOFF_HA
:
14838 case R_PPC64_TPREL16_HA
:
14839 case R_PPC64_TPREL16_HIGHA
:
14840 case R_PPC64_TPREL16_HIGHERA
:
14841 case R_PPC64_TPREL16_HIGHESTA
:
14842 case R_PPC64_DTPREL16_HA
:
14843 case R_PPC64_DTPREL16_HIGHA
:
14844 case R_PPC64_DTPREL16_HIGHERA
:
14845 case R_PPC64_DTPREL16_HIGHESTA
:
14846 /* It's just possible that this symbol is a weak symbol
14847 that's not actually defined anywhere. In that case,
14848 'sec' would be NULL, and we should leave the symbol
14849 alone (it will be set to zero elsewhere in the link). */
14854 case R_PPC64_GOT16_HA
:
14855 case R_PPC64_PLTGOT16_HA
:
14856 case R_PPC64_PLT16_HA
:
14857 case R_PPC64_GOT_TLSGD16_HA
:
14858 case R_PPC64_GOT_TLSLD16_HA
:
14859 case R_PPC64_GOT_TPREL16_HA
:
14860 case R_PPC64_GOT_DTPREL16_HA
:
14861 /* Add 0x10000 if sign bit in 0:15 is set.
14862 Bits 0:15 are not used. */
14866 case R_PPC64_ADDR16_DS
:
14867 case R_PPC64_ADDR16_LO_DS
:
14868 case R_PPC64_GOT16_DS
:
14869 case R_PPC64_GOT16_LO_DS
:
14870 case R_PPC64_PLT16_LO_DS
:
14871 case R_PPC64_SECTOFF_DS
:
14872 case R_PPC64_SECTOFF_LO_DS
:
14873 case R_PPC64_TOC16_DS
:
14874 case R_PPC64_TOC16_LO_DS
:
14875 case R_PPC64_PLTGOT16_DS
:
14876 case R_PPC64_PLTGOT16_LO_DS
:
14877 case R_PPC64_GOT_TPREL16_DS
:
14878 case R_PPC64_GOT_TPREL16_LO_DS
:
14879 case R_PPC64_GOT_DTPREL16_DS
:
14880 case R_PPC64_GOT_DTPREL16_LO_DS
:
14881 case R_PPC64_TPREL16_DS
:
14882 case R_PPC64_TPREL16_LO_DS
:
14883 case R_PPC64_DTPREL16_DS
:
14884 case R_PPC64_DTPREL16_LO_DS
:
14885 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
14887 /* If this reloc is against an lq insn, then the value must be
14888 a multiple of 16. This is somewhat of a hack, but the
14889 "correct" way to do this by defining _DQ forms of all the
14890 _DS relocs bloats all reloc switches in this file. It
14891 doesn't seem to make much sense to use any of these relocs
14892 in data, so testing the insn should be safe. */
14893 if ((insn
& (0x3f << 26)) == (56u << 26))
14895 if (((relocation
+ addend
) & mask
) != 0)
14897 info
->callbacks
->einfo
14898 (_("%P: %H: error: %s not a multiple of %u\n"),
14899 input_bfd
, input_section
, rel
->r_offset
,
14902 bfd_set_error (bfd_error_bad_value
);
14909 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
14910 because such sections are not SEC_ALLOC and thus ld.so will
14911 not process them. */
14912 if (unresolved_reloc
14913 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
14914 && h
->elf
.def_dynamic
)
14915 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
14916 rel
->r_offset
) != (bfd_vma
) -1)
14918 info
->callbacks
->einfo
14919 (_("%P: %H: unresolvable %s against `%T'\n"),
14920 input_bfd
, input_section
, rel
->r_offset
,
14922 h
->elf
.root
.root
.string
);
14926 /* 16-bit fields in insns mostly have signed values, but a
14927 few insns have 16-bit unsigned values. Really, we should
14928 have different reloc types. */
14929 if (howto
->complain_on_overflow
!= complain_overflow_dont
14930 && howto
->dst_mask
== 0xffff
14931 && (input_section
->flags
& SEC_CODE
) != 0)
14933 enum complain_overflow complain
= complain_overflow_signed
;
14935 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
14936 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
14937 complain
= complain_overflow_bitfield
;
14938 else if (howto
->rightshift
== 0
14939 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
14940 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
14941 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
14942 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
14943 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
14944 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
14945 complain
= complain_overflow_unsigned
;
14946 if (howto
->complain_on_overflow
!= complain
)
14948 alt_howto
= *howto
;
14949 alt_howto
.complain_on_overflow
= complain
;
14950 howto
= &alt_howto
;
14954 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
14955 rel
->r_offset
, relocation
, addend
);
14957 if (r
!= bfd_reloc_ok
)
14959 char *more_info
= NULL
;
14960 const char *reloc_name
= howto
->name
;
14962 if (reloc_dest
!= DEST_NORMAL
)
14964 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
14965 if (more_info
!= NULL
)
14967 strcpy (more_info
, reloc_name
);
14968 strcat (more_info
, (reloc_dest
== DEST_OPD
14969 ? " (OPD)" : " (stub)"));
14970 reloc_name
= more_info
;
14974 if (r
== bfd_reloc_overflow
)
14976 /* On code like "if (foo) foo();" don't report overflow
14977 on a branch to zero when foo is undefined. */
14979 && (reloc_dest
== DEST_STUB
14981 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
14982 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
14983 && is_branch_reloc (r_type
))))
14985 if (!((*info
->callbacks
->reloc_overflow
)
14986 (info
, &h
->elf
.root
, sym_name
,
14987 reloc_name
, orig_rel
.r_addend
,
14988 input_bfd
, input_section
, rel
->r_offset
)))
14994 info
->callbacks
->einfo
14995 (_("%P: %H: %s against `%T': error %d\n"),
14996 input_bfd
, input_section
, rel
->r_offset
,
14997 reloc_name
, sym_name
, (int) r
);
15000 if (more_info
!= NULL
)
15005 /* If we're emitting relocations, then shortly after this function
15006 returns, reloc offsets and addends for this section will be
15007 adjusted. Worse, reloc symbol indices will be for the output
15008 file rather than the input. Save a copy of the relocs for
15009 opd_entry_value. */
15010 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
15013 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
15014 rel
= bfd_alloc (input_bfd
, amt
);
15015 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
15016 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
15019 memcpy (rel
, relocs
, amt
);
15024 /* Adjust the value of any local symbols in opd sections. */
15027 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
15028 const char *name ATTRIBUTE_UNUSED
,
15029 Elf_Internal_Sym
*elfsym
,
15030 asection
*input_sec
,
15031 struct elf_link_hash_entry
*h
)
15033 struct _opd_sec_data
*opd
;
15040 opd
= get_opd_info (input_sec
);
15041 if (opd
== NULL
|| opd
->adjust
== NULL
)
15044 value
= elfsym
->st_value
- input_sec
->output_offset
;
15045 if (!bfd_link_relocatable (info
))
15046 value
-= input_sec
->output_section
->vma
;
15048 adjust
= opd
->adjust
[OPD_NDX (value
)];
15052 elfsym
->st_value
+= adjust
;
15056 /* Finish up dynamic symbol handling. We set the contents of various
15057 dynamic sections here. */
15060 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
15061 struct bfd_link_info
*info
,
15062 struct elf_link_hash_entry
*h
,
15063 Elf_Internal_Sym
*sym ATTRIBUTE_UNUSED
)
15065 struct ppc_link_hash_table
*htab
;
15066 struct plt_entry
*ent
;
15067 Elf_Internal_Rela rela
;
15070 htab
= ppc_hash_table (info
);
15074 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
15075 if (ent
->plt
.offset
!= (bfd_vma
) -1)
15077 /* This symbol has an entry in the procedure linkage
15078 table. Set it up. */
15079 if (!htab
->elf
.dynamic_sections_created
15080 || h
->dynindx
== -1)
15082 BFD_ASSERT (h
->type
== STT_GNU_IFUNC
15084 && (h
->root
.type
== bfd_link_hash_defined
15085 || h
->root
.type
== bfd_link_hash_defweak
));
15086 rela
.r_offset
= (htab
->elf
.iplt
->output_section
->vma
15087 + htab
->elf
.iplt
->output_offset
15088 + ent
->plt
.offset
);
15090 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
15092 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15093 rela
.r_addend
= (h
->root
.u
.def
.value
15094 + h
->root
.u
.def
.section
->output_offset
15095 + h
->root
.u
.def
.section
->output_section
->vma
15097 loc
= (htab
->elf
.irelplt
->contents
15098 + (htab
->elf
.irelplt
->reloc_count
++
15099 * sizeof (Elf64_External_Rela
)));
15103 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
15104 + htab
->elf
.splt
->output_offset
15105 + ent
->plt
.offset
);
15106 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
15107 rela
.r_addend
= ent
->addend
;
15108 loc
= (htab
->elf
.srelplt
->contents
15109 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
15110 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
15112 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15114 if (!htab
->opd_abi
)
15116 if (!h
->def_regular
)
15118 /* Mark the symbol as undefined, rather than as
15119 defined in glink. Leave the value if there were
15120 any relocations where pointer equality matters
15121 (this is a clue for the dynamic linker, to make
15122 function pointer comparisons work between an
15123 application and shared library), otherwise set it
15125 sym
->st_shndx
= SHN_UNDEF
;
15126 if (!h
->pointer_equality_needed
)
15128 else if (!h
->ref_regular_nonweak
)
15130 /* This breaks function pointer comparisons, but
15131 that is better than breaking tests for a NULL
15132 function pointer. */
15141 /* This symbol needs a copy reloc. Set it up. */
15143 if (h
->dynindx
== -1
15144 || (h
->root
.type
!= bfd_link_hash_defined
15145 && h
->root
.type
!= bfd_link_hash_defweak
)
15146 || htab
->relbss
== NULL
)
15149 rela
.r_offset
= (h
->root
.u
.def
.value
15150 + h
->root
.u
.def
.section
->output_section
->vma
15151 + h
->root
.u
.def
.section
->output_offset
);
15152 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
15154 loc
= htab
->relbss
->contents
;
15155 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15156 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
15162 /* Used to decide how to sort relocs in an optimal manner for the
15163 dynamic linker, before writing them out. */
15165 static enum elf_reloc_type_class
15166 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
15167 const asection
*rel_sec
,
15168 const Elf_Internal_Rela
*rela
)
15170 enum elf_ppc64_reloc_type r_type
;
15171 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
15173 if (rel_sec
== htab
->elf
.irelplt
)
15174 return reloc_class_ifunc
;
15176 r_type
= ELF64_R_TYPE (rela
->r_info
);
15179 case R_PPC64_RELATIVE
:
15180 return reloc_class_relative
;
15181 case R_PPC64_JMP_SLOT
:
15182 return reloc_class_plt
;
15184 return reloc_class_copy
;
15186 return reloc_class_normal
;
15190 /* Finish up the dynamic sections. */
15193 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
15194 struct bfd_link_info
*info
)
15196 struct ppc_link_hash_table
*htab
;
15200 htab
= ppc_hash_table (info
);
15204 dynobj
= htab
->elf
.dynobj
;
15205 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
15207 if (htab
->elf
.dynamic_sections_created
)
15209 Elf64_External_Dyn
*dyncon
, *dynconend
;
15211 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
15214 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
15215 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
15216 for (; dyncon
< dynconend
; dyncon
++)
15218 Elf_Internal_Dyn dyn
;
15221 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
15228 case DT_PPC64_GLINK
:
15230 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15231 /* We stupidly defined DT_PPC64_GLINK to be the start
15232 of glink rather than the first entry point, which is
15233 what ld.so needs, and now have a bigger stub to
15234 support automatic multiple TOCs. */
15235 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 8 * 4;
15239 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15242 dyn
.d_un
.d_ptr
= s
->vma
;
15246 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
15247 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
15250 case DT_PPC64_OPDSZ
:
15251 s
= bfd_get_section_by_name (output_bfd
, ".opd");
15254 dyn
.d_un
.d_val
= s
->size
;
15258 s
= htab
->elf
.splt
;
15259 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15263 s
= htab
->elf
.srelplt
;
15264 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
15268 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
15272 /* Don't count procedure linkage table relocs in the
15273 overall reloc count. */
15274 s
= htab
->elf
.srelplt
;
15277 dyn
.d_un
.d_val
-= s
->size
;
15281 /* We may not be using the standard ELF linker script.
15282 If .rela.plt is the first .rela section, we adjust
15283 DT_RELA to not include it. */
15284 s
= htab
->elf
.srelplt
;
15287 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
15289 dyn
.d_un
.d_ptr
+= s
->size
;
15293 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
15297 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0)
15299 /* Fill in the first entry in the global offset table.
15300 We use it to hold the link-time TOCbase. */
15301 bfd_put_64 (output_bfd
,
15302 elf_gp (output_bfd
) + TOC_BASE_OFF
,
15303 htab
->elf
.sgot
->contents
);
15305 /* Set .got entry size. */
15306 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
15309 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
15311 /* Set .plt entry size. */
15312 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
15313 = PLT_ENTRY_SIZE (htab
);
15316 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
15317 brlt ourselves if emitrelocations. */
15318 if (htab
->brlt
!= NULL
15319 && htab
->brlt
->reloc_count
!= 0
15320 && !_bfd_elf_link_output_relocs (output_bfd
,
15322 elf_section_data (htab
->brlt
)->rela
.hdr
,
15323 elf_section_data (htab
->brlt
)->relocs
,
15327 if (htab
->glink
!= NULL
15328 && htab
->glink
->reloc_count
!= 0
15329 && !_bfd_elf_link_output_relocs (output_bfd
,
15331 elf_section_data (htab
->glink
)->rela
.hdr
,
15332 elf_section_data (htab
->glink
)->relocs
,
15336 if (htab
->glink_eh_frame
!= NULL
15337 && htab
->glink_eh_frame
->size
!= 0)
15341 asection
*stub_sec
;
15343 p
= htab
->glink_eh_frame
->contents
+ sizeof (glink_eh_frame_cie
);
15344 for (stub_sec
= htab
->params
->stub_bfd
->sections
;
15346 stub_sec
= stub_sec
->next
)
15347 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
15353 /* Offset to stub section. */
15354 val
= (stub_sec
->output_section
->vma
15355 + stub_sec
->output_offset
);
15356 val
-= (htab
->glink_eh_frame
->output_section
->vma
15357 + htab
->glink_eh_frame
->output_offset
15358 + (p
- htab
->glink_eh_frame
->contents
));
15359 if (val
+ 0x80000000 > 0xffffffff)
15361 info
->callbacks
->einfo
15362 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
15366 bfd_put_32 (dynobj
, val
, p
);
15368 /* stub section size. */
15370 /* Augmentation. */
15375 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
15381 /* Offset to .glink. */
15382 val
= (htab
->glink
->output_section
->vma
15383 + htab
->glink
->output_offset
15385 val
-= (htab
->glink_eh_frame
->output_section
->vma
15386 + htab
->glink_eh_frame
->output_offset
15387 + (p
- htab
->glink_eh_frame
->contents
));
15388 if (val
+ 0x80000000 > 0xffffffff)
15390 info
->callbacks
->einfo
15391 (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
15392 htab
->glink
->name
);
15395 bfd_put_32 (dynobj
, val
, p
);
15399 /* Augmentation. */
15405 if (htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
15406 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
15407 htab
->glink_eh_frame
,
15408 htab
->glink_eh_frame
->contents
))
15412 /* We need to handle writing out multiple GOT sections ourselves,
15413 since we didn't add them to DYNOBJ. We know dynobj is the first
15415 while ((dynobj
= dynobj
->link
.next
) != NULL
)
15419 if (!is_ppc64_elf (dynobj
))
15422 s
= ppc64_elf_tdata (dynobj
)->got
;
15425 && s
->output_section
!= bfd_abs_section_ptr
15426 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15427 s
->contents
, s
->output_offset
,
15430 s
= ppc64_elf_tdata (dynobj
)->relgot
;
15433 && s
->output_section
!= bfd_abs_section_ptr
15434 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
15435 s
->contents
, s
->output_offset
,
15443 #include "elf64-target.h"
15445 /* FreeBSD support */
15447 #undef TARGET_LITTLE_SYM
15448 #undef TARGET_LITTLE_NAME
15450 #undef TARGET_BIG_SYM
15451 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
15452 #undef TARGET_BIG_NAME
15453 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
15456 #define ELF_OSABI ELFOSABI_FREEBSD
15459 #define elf64_bed elf64_powerpc_fbsd_bed
15461 #include "elf64-target.h"