1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright (C) 1999-2018 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5 Largely rewritten by Alan Modra.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24 /* The 64-bit PowerPC ELF ABI may be found at
25 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
26 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
34 #include "elf/ppc64.h"
35 #include "elf64-ppc.h"
38 static bfd_reloc_status_type ppc64_elf_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_branch_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_toc64_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_vma opd_entry_value
57 (asection
*, bfd_vma
, asection
**, bfd_vma
*, bfd_boolean
);
59 #define TARGET_LITTLE_SYM powerpc_elf64_le_vec
60 #define TARGET_LITTLE_NAME "elf64-powerpcle"
61 #define TARGET_BIG_SYM powerpc_elf64_vec
62 #define TARGET_BIG_NAME "elf64-powerpc"
63 #define ELF_ARCH bfd_arch_powerpc
64 #define ELF_TARGET_ID PPC64_ELF_DATA
65 #define ELF_MACHINE_CODE EM_PPC64
66 #define ELF_MAXPAGESIZE 0x10000
67 #define ELF_COMMONPAGESIZE 0x1000
68 #define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
69 #define elf_info_to_howto ppc64_elf_info_to_howto
71 #define elf_backend_want_got_sym 0
72 #define elf_backend_want_plt_sym 0
73 #define elf_backend_plt_alignment 3
74 #define elf_backend_plt_not_loaded 1
75 #define elf_backend_got_header_size 8
76 #define elf_backend_want_dynrelro 1
77 #define elf_backend_can_gc_sections 1
78 #define elf_backend_can_refcount 1
79 #define elf_backend_rela_normal 1
80 #define elf_backend_dtrel_excludes_plt 1
81 #define elf_backend_default_execstack 0
83 #define bfd_elf64_mkobject ppc64_elf_mkobject
84 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
85 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
86 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
87 #define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
88 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
89 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
90 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
91 #define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
92 #define bfd_elf64_bfd_gc_sections ppc64_elf_gc_sections
94 #define elf_backend_object_p ppc64_elf_object_p
95 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
96 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
97 #define elf_backend_write_core_note ppc64_elf_write_core_note
98 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
99 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
100 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
101 #define elf_backend_check_directives ppc64_elf_before_check_relocs
102 #define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
103 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
104 #define elf_backend_check_relocs ppc64_elf_check_relocs
105 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
106 #define elf_backend_gc_keep ppc64_elf_gc_keep
107 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
108 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
109 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
110 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
111 #define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
112 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
113 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
114 #define elf_backend_hash_symbol ppc64_elf_hash_symbol
115 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
116 #define elf_backend_action_discarded ppc64_elf_action_discarded
117 #define elf_backend_relocate_section ppc64_elf_relocate_section
118 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
119 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
120 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
121 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
122 #define elf_backend_special_sections ppc64_elf_special_sections
123 #define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
124 #define elf_backend_merge_symbol ppc64_elf_merge_symbol
125 #define elf_backend_get_reloc_section bfd_get_section_by_name
127 /* The name of the dynamic interpreter. This is put in the .interp
129 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
131 /* The size in bytes of an entry in the procedure linkage table. */
132 #define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
133 #define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
135 /* The initial size of the plt reserved for the dynamic linker. */
136 #define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
138 /* Offsets to some stack save slots. */
140 #define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
141 /* This one is dodgy. ELFv2 does not have a linker word, so use the
142 CR save slot. Used only by optimised __tls_get_addr call stub,
143 relying on __tls_get_addr_opt not saving CR.. */
144 #define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
146 /* TOC base pointers offset from start of TOC. */
147 #define TOC_BASE_OFF 0x8000
148 /* TOC base alignment. */
149 #define TOC_BASE_ALIGN 256
151 /* Offset of tp and dtp pointers from start of TLS block. */
152 #define TP_OFFSET 0x7000
153 #define DTP_OFFSET 0x8000
155 /* .plt call stub instructions. The normal stub is like this, but
156 sometimes the .plt entry crosses a 64k boundary and we need to
157 insert an addi to adjust r11. */
158 #define STD_R2_0R1 0xf8410000 /* std %r2,0+40(%r1) */
159 #define ADDIS_R11_R2 0x3d620000 /* addis %r11,%r2,xxx@ha */
160 #define LD_R12_0R11 0xe98b0000 /* ld %r12,xxx+0@l(%r11) */
161 #define MTCTR_R12 0x7d8903a6 /* mtctr %r12 */
162 #define LD_R2_0R11 0xe84b0000 /* ld %r2,xxx+8@l(%r11) */
163 #define LD_R11_0R11 0xe96b0000 /* ld %r11,xxx+16@l(%r11) */
164 #define BCTR 0x4e800420 /* bctr */
166 #define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
167 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
168 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
170 #define XOR_R2_R12_R12 0x7d826278 /* xor %r2,%r12,%r12 */
171 #define ADD_R11_R11_R2 0x7d6b1214 /* add %r11,%r11,%r2 */
172 #define XOR_R11_R12_R12 0x7d8b6278 /* xor %r11,%r12,%r12 */
173 #define ADD_R2_R2_R11 0x7c425a14 /* add %r2,%r2,%r11 */
174 #define CMPLDI_R2_0 0x28220000 /* cmpldi %r2,0 */
175 #define BNECTR 0x4ca20420 /* bnectr+ */
176 #define BNECTR_P4 0x4ce20420 /* bnectr+ */
178 #define LD_R12_0R2 0xe9820000 /* ld %r12,xxx+0(%r2) */
179 #define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */
180 #define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */
182 #define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
183 #define LD_R2_0R12 0xe84c0000 /* ld %r2,0(%r12) */
184 #define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
186 #define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
187 #define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
188 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
189 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
190 #define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
192 /* __glink_PLTresolve stub instructions. We enter with the index in R0. */
193 #define GLINK_PLTRESOLVE_SIZE(htab) \
194 (8u + (htab->opd_abi ? 11 * 4 : 14 * 4))
198 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
199 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
201 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
202 /* ld %2,(0b-1b)(%11) */
203 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
204 #define ADD_R11_R2_R11 0x7d625a14 /* add %11,%2,%11 */
210 #define MFLR_R0 0x7c0802a6 /* mflr %r0 */
211 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
212 #define SUB_R12_R12_R11 0x7d8b6050 /* subf %r12,%r11,%r12 */
213 #define ADDI_R0_R12 0x380c0000 /* addi %r0,%r12,0 */
214 #define SRDI_R0_R0_2 0x7800f082 /* rldicl %r0,%r0,62,2 */
217 #define NOP 0x60000000
219 /* Some other nops. */
220 #define CROR_151515 0x4def7b82
221 #define CROR_313131 0x4ffffb82
223 /* .glink entries for the first 32k functions are two instructions. */
224 #define LI_R0_0 0x38000000 /* li %r0,0 */
225 #define B_DOT 0x48000000 /* b . */
227 /* After that, we need two instructions to load the index, followed by
229 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
230 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
232 /* Instructions used by the save and restore reg functions. */
233 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
234 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
235 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
236 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
237 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
238 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
239 #define LI_R12_0 0x39800000 /* li %r12,0 */
240 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
241 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
242 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
243 #define BLR 0x4e800020 /* blr */
245 /* Since .opd is an array of descriptors and each entry will end up
246 with identical R_PPC64_RELATIVE relocs, there is really no need to
247 propagate .opd relocs; The dynamic linker should be taught to
248 relocate .opd without reloc entries. */
249 #ifndef NO_OPD_RELOCS
250 #define NO_OPD_RELOCS 0
254 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
258 abiversion (bfd
*abfd
)
260 return elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
;
264 set_abiversion (bfd
*abfd
, int ver
)
266 elf_elfheader (abfd
)->e_flags
&= ~EF_PPC64_ABI
;
267 elf_elfheader (abfd
)->e_flags
|= ver
& EF_PPC64_ABI
;
270 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
272 /* Relocation HOWTO's. */
273 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
275 static reloc_howto_type ppc64_elf_howto_raw
[] =
277 /* This reloc does nothing. */
278 HOWTO (R_PPC64_NONE
, /* type */
280 3, /* size (0 = byte, 1 = short, 2 = long) */
282 FALSE
, /* pc_relative */
284 complain_overflow_dont
, /* complain_on_overflow */
285 bfd_elf_generic_reloc
, /* special_function */
286 "R_PPC64_NONE", /* name */
287 FALSE
, /* partial_inplace */
290 FALSE
), /* pcrel_offset */
292 /* A standard 32 bit relocation. */
293 HOWTO (R_PPC64_ADDR32
, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 FALSE
, /* pc_relative */
299 complain_overflow_bitfield
, /* complain_on_overflow */
300 bfd_elf_generic_reloc
, /* special_function */
301 "R_PPC64_ADDR32", /* name */
302 FALSE
, /* partial_inplace */
304 0xffffffff, /* dst_mask */
305 FALSE
), /* pcrel_offset */
307 /* An absolute 26 bit branch; the lower two bits must be zero.
308 FIXME: we don't check that, we just clear them. */
309 HOWTO (R_PPC64_ADDR24
, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 FALSE
, /* pc_relative */
315 complain_overflow_bitfield
, /* complain_on_overflow */
316 bfd_elf_generic_reloc
, /* special_function */
317 "R_PPC64_ADDR24", /* name */
318 FALSE
, /* partial_inplace */
320 0x03fffffc, /* dst_mask */
321 FALSE
), /* pcrel_offset */
323 /* A standard 16 bit relocation. */
324 HOWTO (R_PPC64_ADDR16
, /* type */
326 1, /* size (0 = byte, 1 = short, 2 = long) */
328 FALSE
, /* pc_relative */
330 complain_overflow_bitfield
, /* complain_on_overflow */
331 bfd_elf_generic_reloc
, /* special_function */
332 "R_PPC64_ADDR16", /* name */
333 FALSE
, /* partial_inplace */
335 0xffff, /* dst_mask */
336 FALSE
), /* pcrel_offset */
338 /* A 16 bit relocation without overflow. */
339 HOWTO (R_PPC64_ADDR16_LO
, /* type */
341 1, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE
, /* pc_relative */
345 complain_overflow_dont
,/* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_PPC64_ADDR16_LO", /* name */
348 FALSE
, /* partial_inplace */
350 0xffff, /* dst_mask */
351 FALSE
), /* pcrel_offset */
353 /* Bits 16-31 of an address. */
354 HOWTO (R_PPC64_ADDR16_HI
, /* type */
356 1, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_signed
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_PPC64_ADDR16_HI", /* name */
363 FALSE
, /* partial_inplace */
365 0xffff, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
369 bits, treated as a signed number, is negative. */
370 HOWTO (R_PPC64_ADDR16_HA
, /* type */
372 1, /* size (0 = byte, 1 = short, 2 = long) */
374 FALSE
, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 ppc64_elf_ha_reloc
, /* special_function */
378 "R_PPC64_ADDR16_HA", /* name */
379 FALSE
, /* partial_inplace */
381 0xffff, /* dst_mask */
382 FALSE
), /* pcrel_offset */
384 /* An absolute 16 bit branch; the lower two bits must be zero.
385 FIXME: we don't check that, we just clear them. */
386 HOWTO (R_PPC64_ADDR14
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE
, /* pc_relative */
392 complain_overflow_signed
, /* complain_on_overflow */
393 ppc64_elf_branch_reloc
, /* special_function */
394 "R_PPC64_ADDR14", /* name */
395 FALSE
, /* partial_inplace */
397 0x0000fffc, /* dst_mask */
398 FALSE
), /* pcrel_offset */
400 /* An absolute 16 bit branch, for which bit 10 should be set to
401 indicate that the branch is expected to be taken. The lower two
402 bits must be zero. */
403 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
405 2, /* size (0 = byte, 1 = short, 2 = long) */
407 FALSE
, /* pc_relative */
409 complain_overflow_signed
, /* complain_on_overflow */
410 ppc64_elf_brtaken_reloc
, /* special_function */
411 "R_PPC64_ADDR14_BRTAKEN",/* name */
412 FALSE
, /* partial_inplace */
414 0x0000fffc, /* dst_mask */
415 FALSE
), /* pcrel_offset */
417 /* An absolute 16 bit branch, for which bit 10 should be set to
418 indicate that the branch is not expected to be taken. The lower
419 two bits must be zero. */
420 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
424 FALSE
, /* pc_relative */
426 complain_overflow_signed
, /* complain_on_overflow */
427 ppc64_elf_brtaken_reloc
, /* special_function */
428 "R_PPC64_ADDR14_BRNTAKEN",/* name */
429 FALSE
, /* partial_inplace */
431 0x0000fffc, /* dst_mask */
432 FALSE
), /* pcrel_offset */
434 /* A relative 26 bit branch; the lower two bits must be zero. */
435 HOWTO (R_PPC64_REL24
, /* type */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
439 TRUE
, /* pc_relative */
441 complain_overflow_signed
, /* complain_on_overflow */
442 ppc64_elf_branch_reloc
, /* special_function */
443 "R_PPC64_REL24", /* name */
444 FALSE
, /* partial_inplace */
446 0x03fffffc, /* dst_mask */
447 TRUE
), /* pcrel_offset */
449 /* A relative 16 bit branch; the lower two bits must be zero. */
450 HOWTO (R_PPC64_REL14
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 TRUE
, /* pc_relative */
456 complain_overflow_signed
, /* complain_on_overflow */
457 ppc64_elf_branch_reloc
, /* special_function */
458 "R_PPC64_REL14", /* name */
459 FALSE
, /* partial_inplace */
461 0x0000fffc, /* dst_mask */
462 TRUE
), /* pcrel_offset */
464 /* A relative 16 bit branch. Bit 10 should be set to indicate that
465 the branch is expected to be taken. The lower two bits must be
467 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
469 2, /* size (0 = byte, 1 = short, 2 = long) */
471 TRUE
, /* pc_relative */
473 complain_overflow_signed
, /* complain_on_overflow */
474 ppc64_elf_brtaken_reloc
, /* special_function */
475 "R_PPC64_REL14_BRTAKEN", /* name */
476 FALSE
, /* partial_inplace */
478 0x0000fffc, /* dst_mask */
479 TRUE
), /* pcrel_offset */
481 /* A relative 16 bit branch. Bit 10 should be set to indicate that
482 the branch is not expected to be taken. The lower two bits must
484 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 TRUE
, /* pc_relative */
490 complain_overflow_signed
, /* complain_on_overflow */
491 ppc64_elf_brtaken_reloc
, /* special_function */
492 "R_PPC64_REL14_BRNTAKEN",/* name */
493 FALSE
, /* partial_inplace */
495 0x0000fffc, /* dst_mask */
496 TRUE
), /* pcrel_offset */
498 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
500 HOWTO (R_PPC64_GOT16
, /* type */
502 1, /* size (0 = byte, 1 = short, 2 = long) */
504 FALSE
, /* pc_relative */
506 complain_overflow_signed
, /* complain_on_overflow */
507 ppc64_elf_unhandled_reloc
, /* special_function */
508 "R_PPC64_GOT16", /* name */
509 FALSE
, /* partial_inplace */
511 0xffff, /* dst_mask */
512 FALSE
), /* pcrel_offset */
514 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
516 HOWTO (R_PPC64_GOT16_LO
, /* type */
518 1, /* size (0 = byte, 1 = short, 2 = long) */
520 FALSE
, /* pc_relative */
522 complain_overflow_dont
, /* complain_on_overflow */
523 ppc64_elf_unhandled_reloc
, /* special_function */
524 "R_PPC64_GOT16_LO", /* name */
525 FALSE
, /* partial_inplace */
527 0xffff, /* dst_mask */
528 FALSE
), /* pcrel_offset */
530 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
532 HOWTO (R_PPC64_GOT16_HI
, /* type */
534 1, /* size (0 = byte, 1 = short, 2 = long) */
536 FALSE
, /* pc_relative */
538 complain_overflow_signed
,/* complain_on_overflow */
539 ppc64_elf_unhandled_reloc
, /* special_function */
540 "R_PPC64_GOT16_HI", /* name */
541 FALSE
, /* partial_inplace */
543 0xffff, /* dst_mask */
544 FALSE
), /* pcrel_offset */
546 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
548 HOWTO (R_PPC64_GOT16_HA
, /* type */
550 1, /* size (0 = byte, 1 = short, 2 = long) */
552 FALSE
, /* pc_relative */
554 complain_overflow_signed
,/* complain_on_overflow */
555 ppc64_elf_unhandled_reloc
, /* special_function */
556 "R_PPC64_GOT16_HA", /* name */
557 FALSE
, /* partial_inplace */
559 0xffff, /* dst_mask */
560 FALSE
), /* pcrel_offset */
562 /* This is used only by the dynamic linker. The symbol should exist
563 both in the object being run and in some shared library. The
564 dynamic linker copies the data addressed by the symbol from the
565 shared library into the object, because the object being
566 run has to have the data at some particular address. */
567 HOWTO (R_PPC64_COPY
, /* type */
569 0, /* this one is variable size */
571 FALSE
, /* pc_relative */
573 complain_overflow_dont
, /* complain_on_overflow */
574 ppc64_elf_unhandled_reloc
, /* special_function */
575 "R_PPC64_COPY", /* name */
576 FALSE
, /* partial_inplace */
579 FALSE
), /* pcrel_offset */
581 /* Like R_PPC64_ADDR64, but used when setting global offset table
583 HOWTO (R_PPC64_GLOB_DAT
, /* type */
585 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
587 FALSE
, /* pc_relative */
589 complain_overflow_dont
, /* complain_on_overflow */
590 ppc64_elf_unhandled_reloc
, /* special_function */
591 "R_PPC64_GLOB_DAT", /* name */
592 FALSE
, /* partial_inplace */
594 ONES (64), /* dst_mask */
595 FALSE
), /* pcrel_offset */
597 /* Created by the link editor. Marks a procedure linkage table
598 entry for a symbol. */
599 HOWTO (R_PPC64_JMP_SLOT
, /* type */
601 0, /* size (0 = byte, 1 = short, 2 = long) */
603 FALSE
, /* pc_relative */
605 complain_overflow_dont
, /* complain_on_overflow */
606 ppc64_elf_unhandled_reloc
, /* special_function */
607 "R_PPC64_JMP_SLOT", /* name */
608 FALSE
, /* partial_inplace */
611 FALSE
), /* pcrel_offset */
613 /* Used only by the dynamic linker. When the object is run, this
614 doubleword64 is set to the load address of the object, plus the
616 HOWTO (R_PPC64_RELATIVE
, /* type */
618 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
620 FALSE
, /* pc_relative */
622 complain_overflow_dont
, /* complain_on_overflow */
623 bfd_elf_generic_reloc
, /* special_function */
624 "R_PPC64_RELATIVE", /* name */
625 FALSE
, /* partial_inplace */
627 ONES (64), /* dst_mask */
628 FALSE
), /* pcrel_offset */
630 /* Like R_PPC64_ADDR32, but may be unaligned. */
631 HOWTO (R_PPC64_UADDR32
, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 FALSE
, /* pc_relative */
637 complain_overflow_bitfield
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 "R_PPC64_UADDR32", /* name */
640 FALSE
, /* partial_inplace */
642 0xffffffff, /* dst_mask */
643 FALSE
), /* pcrel_offset */
645 /* Like R_PPC64_ADDR16, but may be unaligned. */
646 HOWTO (R_PPC64_UADDR16
, /* type */
648 1, /* size (0 = byte, 1 = short, 2 = long) */
650 FALSE
, /* pc_relative */
652 complain_overflow_bitfield
, /* complain_on_overflow */
653 bfd_elf_generic_reloc
, /* special_function */
654 "R_PPC64_UADDR16", /* name */
655 FALSE
, /* partial_inplace */
657 0xffff, /* dst_mask */
658 FALSE
), /* pcrel_offset */
660 /* 32-bit PC relative. */
661 HOWTO (R_PPC64_REL32
, /* type */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
665 TRUE
, /* pc_relative */
667 complain_overflow_signed
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 "R_PPC64_REL32", /* name */
670 FALSE
, /* partial_inplace */
672 0xffffffff, /* dst_mask */
673 TRUE
), /* pcrel_offset */
675 /* 32-bit relocation to the symbol's procedure linkage table. */
676 HOWTO (R_PPC64_PLT32
, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE
, /* pc_relative */
682 complain_overflow_bitfield
, /* complain_on_overflow */
683 ppc64_elf_unhandled_reloc
, /* special_function */
684 "R_PPC64_PLT32", /* name */
685 FALSE
, /* partial_inplace */
687 0xffffffff, /* dst_mask */
688 FALSE
), /* pcrel_offset */
690 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
691 FIXME: R_PPC64_PLTREL32 not supported. */
692 HOWTO (R_PPC64_PLTREL32
, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 TRUE
, /* pc_relative */
698 complain_overflow_signed
, /* complain_on_overflow */
699 ppc64_elf_unhandled_reloc
, /* special_function */
700 "R_PPC64_PLTREL32", /* name */
701 FALSE
, /* partial_inplace */
703 0xffffffff, /* dst_mask */
704 TRUE
), /* pcrel_offset */
706 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
708 HOWTO (R_PPC64_PLT16_LO
, /* type */
710 1, /* size (0 = byte, 1 = short, 2 = long) */
712 FALSE
, /* pc_relative */
714 complain_overflow_dont
, /* complain_on_overflow */
715 ppc64_elf_unhandled_reloc
, /* special_function */
716 "R_PPC64_PLT16_LO", /* name */
717 FALSE
, /* partial_inplace */
719 0xffff, /* dst_mask */
720 FALSE
), /* pcrel_offset */
722 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
724 HOWTO (R_PPC64_PLT16_HI
, /* type */
726 1, /* size (0 = byte, 1 = short, 2 = long) */
728 FALSE
, /* pc_relative */
730 complain_overflow_signed
, /* complain_on_overflow */
731 ppc64_elf_unhandled_reloc
, /* special_function */
732 "R_PPC64_PLT16_HI", /* name */
733 FALSE
, /* partial_inplace */
735 0xffff, /* dst_mask */
736 FALSE
), /* pcrel_offset */
738 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
740 HOWTO (R_PPC64_PLT16_HA
, /* type */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE
, /* pc_relative */
746 complain_overflow_signed
, /* complain_on_overflow */
747 ppc64_elf_unhandled_reloc
, /* special_function */
748 "R_PPC64_PLT16_HA", /* name */
749 FALSE
, /* partial_inplace */
751 0xffff, /* dst_mask */
752 FALSE
), /* pcrel_offset */
754 /* 16-bit section relative relocation. */
755 HOWTO (R_PPC64_SECTOFF
, /* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_signed
, /* complain_on_overflow */
762 ppc64_elf_sectoff_reloc
, /* special_function */
763 "R_PPC64_SECTOFF", /* name */
764 FALSE
, /* partial_inplace */
766 0xffff, /* dst_mask */
767 FALSE
), /* pcrel_offset */
769 /* Like R_PPC64_SECTOFF, but no overflow warning. */
770 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
772 1, /* size (0 = byte, 1 = short, 2 = long) */
774 FALSE
, /* pc_relative */
776 complain_overflow_dont
, /* complain_on_overflow */
777 ppc64_elf_sectoff_reloc
, /* special_function */
778 "R_PPC64_SECTOFF_LO", /* name */
779 FALSE
, /* partial_inplace */
781 0xffff, /* dst_mask */
782 FALSE
), /* pcrel_offset */
784 /* 16-bit upper half section relative relocation. */
785 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
787 1, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE
, /* pc_relative */
791 complain_overflow_signed
, /* complain_on_overflow */
792 ppc64_elf_sectoff_reloc
, /* special_function */
793 "R_PPC64_SECTOFF_HI", /* name */
794 FALSE
, /* partial_inplace */
796 0xffff, /* dst_mask */
797 FALSE
), /* pcrel_offset */
799 /* 16-bit upper half adjusted section relative relocation. */
800 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
802 1, /* size (0 = byte, 1 = short, 2 = long) */
804 FALSE
, /* pc_relative */
806 complain_overflow_signed
, /* complain_on_overflow */
807 ppc64_elf_sectoff_ha_reloc
, /* special_function */
808 "R_PPC64_SECTOFF_HA", /* name */
809 FALSE
, /* partial_inplace */
811 0xffff, /* dst_mask */
812 FALSE
), /* pcrel_offset */
814 /* Like R_PPC64_REL24 without touching the two least significant bits. */
815 HOWTO (R_PPC64_REL30
, /* type */
817 2, /* size (0 = byte, 1 = short, 2 = long) */
819 TRUE
, /* pc_relative */
821 complain_overflow_dont
, /* complain_on_overflow */
822 bfd_elf_generic_reloc
, /* special_function */
823 "R_PPC64_REL30", /* name */
824 FALSE
, /* partial_inplace */
826 0xfffffffc, /* dst_mask */
827 TRUE
), /* pcrel_offset */
829 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
831 /* A standard 64-bit relocation. */
832 HOWTO (R_PPC64_ADDR64
, /* type */
834 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
836 FALSE
, /* pc_relative */
838 complain_overflow_dont
, /* complain_on_overflow */
839 bfd_elf_generic_reloc
, /* special_function */
840 "R_PPC64_ADDR64", /* name */
841 FALSE
, /* partial_inplace */
843 ONES (64), /* dst_mask */
844 FALSE
), /* pcrel_offset */
846 /* The bits 32-47 of an address. */
847 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
849 1, /* size (0 = byte, 1 = short, 2 = long) */
851 FALSE
, /* pc_relative */
853 complain_overflow_dont
, /* complain_on_overflow */
854 bfd_elf_generic_reloc
, /* special_function */
855 "R_PPC64_ADDR16_HIGHER", /* name */
856 FALSE
, /* partial_inplace */
858 0xffff, /* dst_mask */
859 FALSE
), /* pcrel_offset */
861 /* The bits 32-47 of an address, plus 1 if the contents of the low
862 16 bits, treated as a signed number, is negative. */
863 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
865 1, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE
, /* pc_relative */
869 complain_overflow_dont
, /* complain_on_overflow */
870 ppc64_elf_ha_reloc
, /* special_function */
871 "R_PPC64_ADDR16_HIGHERA", /* name */
872 FALSE
, /* partial_inplace */
874 0xffff, /* dst_mask */
875 FALSE
), /* pcrel_offset */
877 /* The bits 48-63 of an address. */
878 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
880 1, /* size (0 = byte, 1 = short, 2 = long) */
882 FALSE
, /* pc_relative */
884 complain_overflow_dont
, /* complain_on_overflow */
885 bfd_elf_generic_reloc
, /* special_function */
886 "R_PPC64_ADDR16_HIGHEST", /* name */
887 FALSE
, /* partial_inplace */
889 0xffff, /* dst_mask */
890 FALSE
), /* pcrel_offset */
892 /* The bits 48-63 of an address, plus 1 if the contents of the low
893 16 bits, treated as a signed number, is negative. */
894 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
896 1, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE
, /* pc_relative */
900 complain_overflow_dont
, /* complain_on_overflow */
901 ppc64_elf_ha_reloc
, /* special_function */
902 "R_PPC64_ADDR16_HIGHESTA", /* name */
903 FALSE
, /* partial_inplace */
905 0xffff, /* dst_mask */
906 FALSE
), /* pcrel_offset */
908 /* Like ADDR64, but may be unaligned. */
909 HOWTO (R_PPC64_UADDR64
, /* type */
911 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
913 FALSE
, /* pc_relative */
915 complain_overflow_dont
, /* complain_on_overflow */
916 bfd_elf_generic_reloc
, /* special_function */
917 "R_PPC64_UADDR64", /* name */
918 FALSE
, /* partial_inplace */
920 ONES (64), /* dst_mask */
921 FALSE
), /* pcrel_offset */
923 /* 64-bit relative relocation. */
924 HOWTO (R_PPC64_REL64
, /* type */
926 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
928 TRUE
, /* pc_relative */
930 complain_overflow_dont
, /* complain_on_overflow */
931 bfd_elf_generic_reloc
, /* special_function */
932 "R_PPC64_REL64", /* name */
933 FALSE
, /* partial_inplace */
935 ONES (64), /* dst_mask */
936 TRUE
), /* pcrel_offset */
938 /* 64-bit relocation to the symbol's procedure linkage table. */
939 HOWTO (R_PPC64_PLT64
, /* type */
941 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
943 FALSE
, /* pc_relative */
945 complain_overflow_dont
, /* complain_on_overflow */
946 ppc64_elf_unhandled_reloc
, /* special_function */
947 "R_PPC64_PLT64", /* name */
948 FALSE
, /* partial_inplace */
950 ONES (64), /* dst_mask */
951 FALSE
), /* pcrel_offset */
953 /* 64-bit PC relative relocation to the symbol's procedure linkage
955 /* FIXME: R_PPC64_PLTREL64 not supported. */
956 HOWTO (R_PPC64_PLTREL64
, /* type */
958 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
960 TRUE
, /* pc_relative */
962 complain_overflow_dont
, /* complain_on_overflow */
963 ppc64_elf_unhandled_reloc
, /* special_function */
964 "R_PPC64_PLTREL64", /* name */
965 FALSE
, /* partial_inplace */
967 ONES (64), /* dst_mask */
968 TRUE
), /* pcrel_offset */
970 /* 16 bit TOC-relative relocation. */
972 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
973 HOWTO (R_PPC64_TOC16
, /* type */
975 1, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE
, /* pc_relative */
979 complain_overflow_signed
, /* complain_on_overflow */
980 ppc64_elf_toc_reloc
, /* special_function */
981 "R_PPC64_TOC16", /* name */
982 FALSE
, /* partial_inplace */
984 0xffff, /* dst_mask */
985 FALSE
), /* pcrel_offset */
987 /* 16 bit TOC-relative relocation without overflow. */
989 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
990 HOWTO (R_PPC64_TOC16_LO
, /* type */
992 1, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE
, /* pc_relative */
996 complain_overflow_dont
, /* complain_on_overflow */
997 ppc64_elf_toc_reloc
, /* special_function */
998 "R_PPC64_TOC16_LO", /* name */
999 FALSE
, /* partial_inplace */
1001 0xffff, /* dst_mask */
1002 FALSE
), /* pcrel_offset */
1004 /* 16 bit TOC-relative relocation, high 16 bits. */
1006 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
1007 HOWTO (R_PPC64_TOC16_HI
, /* type */
1008 16, /* rightshift */
1009 1, /* size (0 = byte, 1 = short, 2 = long) */
1011 FALSE
, /* pc_relative */
1013 complain_overflow_signed
, /* complain_on_overflow */
1014 ppc64_elf_toc_reloc
, /* special_function */
1015 "R_PPC64_TOC16_HI", /* name */
1016 FALSE
, /* partial_inplace */
1018 0xffff, /* dst_mask */
1019 FALSE
), /* pcrel_offset */
1021 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
1022 contents of the low 16 bits, treated as a signed number, is
1025 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
1026 HOWTO (R_PPC64_TOC16_HA
, /* type */
1027 16, /* rightshift */
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE
, /* pc_relative */
1032 complain_overflow_signed
, /* complain_on_overflow */
1033 ppc64_elf_toc_ha_reloc
, /* special_function */
1034 "R_PPC64_TOC16_HA", /* name */
1035 FALSE
, /* partial_inplace */
1037 0xffff, /* dst_mask */
1038 FALSE
), /* pcrel_offset */
1040 /* 64-bit relocation; insert value of TOC base (.TOC.). */
1042 /* R_PPC64_TOC 51 doubleword64 .TOC. */
1043 HOWTO (R_PPC64_TOC
, /* type */
1045 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_dont
, /* complain_on_overflow */
1050 ppc64_elf_toc64_reloc
, /* special_function */
1051 "R_PPC64_TOC", /* name */
1052 FALSE
, /* partial_inplace */
1054 ONES (64), /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* Like R_PPC64_GOT16, but also informs the link editor that the
1058 value to relocate may (!) refer to a PLT entry which the link
1059 editor (a) may replace with the symbol value. If the link editor
1060 is unable to fully resolve the symbol, it may (b) create a PLT
1061 entry and store the address to the new PLT entry in the GOT.
1062 This permits lazy resolution of function symbols at run time.
1063 The link editor may also skip all of this and just (c) emit a
1064 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1065 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1066 HOWTO (R_PPC64_PLTGOT16
, /* type */
1068 1, /* size (0 = byte, 1 = short, 2 = long) */
1070 FALSE
, /* pc_relative */
1072 complain_overflow_signed
, /* complain_on_overflow */
1073 ppc64_elf_unhandled_reloc
, /* special_function */
1074 "R_PPC64_PLTGOT16", /* name */
1075 FALSE
, /* partial_inplace */
1077 0xffff, /* dst_mask */
1078 FALSE
), /* pcrel_offset */
1080 /* Like R_PPC64_PLTGOT16, but without overflow. */
1081 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1082 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1084 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 FALSE
, /* pc_relative */
1088 complain_overflow_dont
, /* complain_on_overflow */
1089 ppc64_elf_unhandled_reloc
, /* special_function */
1090 "R_PPC64_PLTGOT16_LO", /* name */
1091 FALSE
, /* partial_inplace */
1093 0xffff, /* dst_mask */
1094 FALSE
), /* pcrel_offset */
1096 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1097 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1098 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1099 16, /* rightshift */
1100 1, /* size (0 = byte, 1 = short, 2 = long) */
1102 FALSE
, /* pc_relative */
1104 complain_overflow_signed
, /* complain_on_overflow */
1105 ppc64_elf_unhandled_reloc
, /* special_function */
1106 "R_PPC64_PLTGOT16_HI", /* name */
1107 FALSE
, /* partial_inplace */
1109 0xffff, /* dst_mask */
1110 FALSE
), /* pcrel_offset */
1112 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1113 1 if the contents of the low 16 bits, treated as a signed number,
1115 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1116 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1117 16, /* rightshift */
1118 1, /* size (0 = byte, 1 = short, 2 = long) */
1120 FALSE
, /* pc_relative */
1122 complain_overflow_signed
, /* complain_on_overflow */
1123 ppc64_elf_unhandled_reloc
, /* special_function */
1124 "R_PPC64_PLTGOT16_HA", /* name */
1125 FALSE
, /* partial_inplace */
1127 0xffff, /* dst_mask */
1128 FALSE
), /* pcrel_offset */
1130 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1131 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1133 1, /* size (0 = byte, 1 = short, 2 = long) */
1135 FALSE
, /* pc_relative */
1137 complain_overflow_signed
, /* complain_on_overflow */
1138 bfd_elf_generic_reloc
, /* special_function */
1139 "R_PPC64_ADDR16_DS", /* name */
1140 FALSE
, /* partial_inplace */
1142 0xfffc, /* dst_mask */
1143 FALSE
), /* pcrel_offset */
1145 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1146 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1148 1, /* size (0 = byte, 1 = short, 2 = long) */
1150 FALSE
, /* pc_relative */
1152 complain_overflow_dont
,/* complain_on_overflow */
1153 bfd_elf_generic_reloc
, /* special_function */
1154 "R_PPC64_ADDR16_LO_DS",/* name */
1155 FALSE
, /* partial_inplace */
1157 0xfffc, /* dst_mask */
1158 FALSE
), /* pcrel_offset */
1160 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1161 HOWTO (R_PPC64_GOT16_DS
, /* type */
1163 1, /* size (0 = byte, 1 = short, 2 = long) */
1165 FALSE
, /* pc_relative */
1167 complain_overflow_signed
, /* complain_on_overflow */
1168 ppc64_elf_unhandled_reloc
, /* special_function */
1169 "R_PPC64_GOT16_DS", /* name */
1170 FALSE
, /* partial_inplace */
1172 0xfffc, /* dst_mask */
1173 FALSE
), /* pcrel_offset */
1175 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1176 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1178 1, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE
, /* pc_relative */
1182 complain_overflow_dont
, /* complain_on_overflow */
1183 ppc64_elf_unhandled_reloc
, /* special_function */
1184 "R_PPC64_GOT16_LO_DS", /* name */
1185 FALSE
, /* partial_inplace */
1187 0xfffc, /* dst_mask */
1188 FALSE
), /* pcrel_offset */
1190 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1191 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1193 1, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE
, /* pc_relative */
1197 complain_overflow_dont
, /* complain_on_overflow */
1198 ppc64_elf_unhandled_reloc
, /* special_function */
1199 "R_PPC64_PLT16_LO_DS", /* name */
1200 FALSE
, /* partial_inplace */
1202 0xfffc, /* dst_mask */
1203 FALSE
), /* pcrel_offset */
1205 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1206 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1208 1, /* size (0 = byte, 1 = short, 2 = long) */
1210 FALSE
, /* pc_relative */
1212 complain_overflow_signed
, /* complain_on_overflow */
1213 ppc64_elf_sectoff_reloc
, /* special_function */
1214 "R_PPC64_SECTOFF_DS", /* name */
1215 FALSE
, /* partial_inplace */
1217 0xfffc, /* dst_mask */
1218 FALSE
), /* pcrel_offset */
1220 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1221 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1223 1, /* size (0 = byte, 1 = short, 2 = long) */
1225 FALSE
, /* pc_relative */
1227 complain_overflow_dont
, /* complain_on_overflow */
1228 ppc64_elf_sectoff_reloc
, /* special_function */
1229 "R_PPC64_SECTOFF_LO_DS",/* name */
1230 FALSE
, /* partial_inplace */
1232 0xfffc, /* dst_mask */
1233 FALSE
), /* pcrel_offset */
1235 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1236 HOWTO (R_PPC64_TOC16_DS
, /* type */
1238 1, /* size (0 = byte, 1 = short, 2 = long) */
1240 FALSE
, /* pc_relative */
1242 complain_overflow_signed
, /* complain_on_overflow */
1243 ppc64_elf_toc_reloc
, /* special_function */
1244 "R_PPC64_TOC16_DS", /* name */
1245 FALSE
, /* partial_inplace */
1247 0xfffc, /* dst_mask */
1248 FALSE
), /* pcrel_offset */
1250 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1251 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1253 1, /* size (0 = byte, 1 = short, 2 = long) */
1255 FALSE
, /* pc_relative */
1257 complain_overflow_dont
, /* complain_on_overflow */
1258 ppc64_elf_toc_reloc
, /* special_function */
1259 "R_PPC64_TOC16_LO_DS", /* name */
1260 FALSE
, /* partial_inplace */
1262 0xfffc, /* dst_mask */
1263 FALSE
), /* pcrel_offset */
1265 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1266 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1267 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1269 1, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE
, /* pc_relative */
1273 complain_overflow_signed
, /* complain_on_overflow */
1274 ppc64_elf_unhandled_reloc
, /* special_function */
1275 "R_PPC64_PLTGOT16_DS", /* name */
1276 FALSE
, /* partial_inplace */
1278 0xfffc, /* dst_mask */
1279 FALSE
), /* pcrel_offset */
1281 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1282 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1283 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1285 1, /* size (0 = byte, 1 = short, 2 = long) */
1287 FALSE
, /* pc_relative */
1289 complain_overflow_dont
, /* complain_on_overflow */
1290 ppc64_elf_unhandled_reloc
, /* special_function */
1291 "R_PPC64_PLTGOT16_LO_DS",/* name */
1292 FALSE
, /* partial_inplace */
1294 0xfffc, /* dst_mask */
1295 FALSE
), /* pcrel_offset */
1297 /* Marker relocs for TLS. */
1300 2, /* size (0 = byte, 1 = short, 2 = long) */
1302 FALSE
, /* pc_relative */
1304 complain_overflow_dont
, /* complain_on_overflow */
1305 bfd_elf_generic_reloc
, /* special_function */
1306 "R_PPC64_TLS", /* name */
1307 FALSE
, /* partial_inplace */
1310 FALSE
), /* pcrel_offset */
1312 HOWTO (R_PPC64_TLSGD
,
1314 2, /* size (0 = byte, 1 = short, 2 = long) */
1316 FALSE
, /* pc_relative */
1318 complain_overflow_dont
, /* complain_on_overflow */
1319 bfd_elf_generic_reloc
, /* special_function */
1320 "R_PPC64_TLSGD", /* name */
1321 FALSE
, /* partial_inplace */
1324 FALSE
), /* pcrel_offset */
1326 HOWTO (R_PPC64_TLSLD
,
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1330 FALSE
, /* pc_relative */
1332 complain_overflow_dont
, /* complain_on_overflow */
1333 bfd_elf_generic_reloc
, /* special_function */
1334 "R_PPC64_TLSLD", /* name */
1335 FALSE
, /* partial_inplace */
1338 FALSE
), /* pcrel_offset */
1340 /* Marker reloc for optimizing r2 save in prologue rather than on
1341 each plt call stub. */
1342 HOWTO (R_PPC64_TOCSAVE
,
1344 2, /* size (0 = byte, 1 = short, 2 = long) */
1346 FALSE
, /* pc_relative */
1348 complain_overflow_dont
, /* complain_on_overflow */
1349 bfd_elf_generic_reloc
, /* special_function */
1350 "R_PPC64_TOCSAVE", /* name */
1351 FALSE
, /* partial_inplace */
1354 FALSE
), /* pcrel_offset */
1356 /* Marker relocs on inline plt call instructions. */
1357 HOWTO (R_PPC64_PLTSEQ
,
1359 2, /* size (0 = byte, 1 = short, 2 = long) */
1361 FALSE
, /* pc_relative */
1363 complain_overflow_dont
, /* complain_on_overflow */
1364 bfd_elf_generic_reloc
, /* special_function */
1365 "R_PPC64_PLTSEQ", /* name */
1366 FALSE
, /* partial_inplace */
1369 FALSE
), /* pcrel_offset */
1371 HOWTO (R_PPC64_PLTCALL
,
1373 2, /* size (0 = byte, 1 = short, 2 = long) */
1375 FALSE
, /* pc_relative */
1377 complain_overflow_dont
, /* complain_on_overflow */
1378 bfd_elf_generic_reloc
, /* special_function */
1379 "R_PPC64_PLTCALL", /* name */
1380 FALSE
, /* partial_inplace */
1383 FALSE
), /* pcrel_offset */
1385 /* Computes the load module index of the load module that contains the
1386 definition of its TLS sym. */
1387 HOWTO (R_PPC64_DTPMOD64
,
1389 4, /* size (0 = byte, 1 = short, 2 = long) */
1391 FALSE
, /* pc_relative */
1393 complain_overflow_dont
, /* complain_on_overflow */
1394 ppc64_elf_unhandled_reloc
, /* special_function */
1395 "R_PPC64_DTPMOD64", /* name */
1396 FALSE
, /* partial_inplace */
1398 ONES (64), /* dst_mask */
1399 FALSE
), /* pcrel_offset */
1401 /* Computes a dtv-relative displacement, the difference between the value
1402 of sym+add and the base address of the thread-local storage block that
1403 contains the definition of sym, minus 0x8000. */
1404 HOWTO (R_PPC64_DTPREL64
,
1406 4, /* size (0 = byte, 1 = short, 2 = long) */
1408 FALSE
, /* pc_relative */
1410 complain_overflow_dont
, /* complain_on_overflow */
1411 ppc64_elf_unhandled_reloc
, /* special_function */
1412 "R_PPC64_DTPREL64", /* name */
1413 FALSE
, /* partial_inplace */
1415 ONES (64), /* dst_mask */
1416 FALSE
), /* pcrel_offset */
1418 /* A 16 bit dtprel reloc. */
1419 HOWTO (R_PPC64_DTPREL16
,
1421 1, /* size (0 = byte, 1 = short, 2 = long) */
1423 FALSE
, /* pc_relative */
1425 complain_overflow_signed
, /* complain_on_overflow */
1426 ppc64_elf_unhandled_reloc
, /* special_function */
1427 "R_PPC64_DTPREL16", /* name */
1428 FALSE
, /* partial_inplace */
1430 0xffff, /* dst_mask */
1431 FALSE
), /* pcrel_offset */
1433 /* Like DTPREL16, but no overflow. */
1434 HOWTO (R_PPC64_DTPREL16_LO
,
1436 1, /* size (0 = byte, 1 = short, 2 = long) */
1438 FALSE
, /* pc_relative */
1440 complain_overflow_dont
, /* complain_on_overflow */
1441 ppc64_elf_unhandled_reloc
, /* special_function */
1442 "R_PPC64_DTPREL16_LO", /* name */
1443 FALSE
, /* partial_inplace */
1445 0xffff, /* dst_mask */
1446 FALSE
), /* pcrel_offset */
1448 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1449 HOWTO (R_PPC64_DTPREL16_HI
,
1450 16, /* rightshift */
1451 1, /* size (0 = byte, 1 = short, 2 = long) */
1453 FALSE
, /* pc_relative */
1455 complain_overflow_signed
, /* complain_on_overflow */
1456 ppc64_elf_unhandled_reloc
, /* special_function */
1457 "R_PPC64_DTPREL16_HI", /* name */
1458 FALSE
, /* partial_inplace */
1460 0xffff, /* dst_mask */
1461 FALSE
), /* pcrel_offset */
1463 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1464 HOWTO (R_PPC64_DTPREL16_HA
,
1465 16, /* rightshift */
1466 1, /* size (0 = byte, 1 = short, 2 = long) */
1468 FALSE
, /* pc_relative */
1470 complain_overflow_signed
, /* complain_on_overflow */
1471 ppc64_elf_unhandled_reloc
, /* special_function */
1472 "R_PPC64_DTPREL16_HA", /* name */
1473 FALSE
, /* partial_inplace */
1475 0xffff, /* dst_mask */
1476 FALSE
), /* pcrel_offset */
1478 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1479 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1480 32, /* rightshift */
1481 1, /* size (0 = byte, 1 = short, 2 = long) */
1483 FALSE
, /* pc_relative */
1485 complain_overflow_dont
, /* complain_on_overflow */
1486 ppc64_elf_unhandled_reloc
, /* special_function */
1487 "R_PPC64_DTPREL16_HIGHER", /* name */
1488 FALSE
, /* partial_inplace */
1490 0xffff, /* dst_mask */
1491 FALSE
), /* pcrel_offset */
1493 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1494 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1495 32, /* rightshift */
1496 1, /* size (0 = byte, 1 = short, 2 = long) */
1498 FALSE
, /* pc_relative */
1500 complain_overflow_dont
, /* complain_on_overflow */
1501 ppc64_elf_unhandled_reloc
, /* special_function */
1502 "R_PPC64_DTPREL16_HIGHERA", /* name */
1503 FALSE
, /* partial_inplace */
1505 0xffff, /* dst_mask */
1506 FALSE
), /* pcrel_offset */
1508 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1509 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1510 48, /* rightshift */
1511 1, /* size (0 = byte, 1 = short, 2 = long) */
1513 FALSE
, /* pc_relative */
1515 complain_overflow_dont
, /* complain_on_overflow */
1516 ppc64_elf_unhandled_reloc
, /* special_function */
1517 "R_PPC64_DTPREL16_HIGHEST", /* name */
1518 FALSE
, /* partial_inplace */
1520 0xffff, /* dst_mask */
1521 FALSE
), /* pcrel_offset */
1523 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1524 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1525 48, /* rightshift */
1526 1, /* size (0 = byte, 1 = short, 2 = long) */
1528 FALSE
, /* pc_relative */
1530 complain_overflow_dont
, /* complain_on_overflow */
1531 ppc64_elf_unhandled_reloc
, /* special_function */
1532 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1533 FALSE
, /* partial_inplace */
1535 0xffff, /* dst_mask */
1536 FALSE
), /* pcrel_offset */
1538 /* Like DTPREL16, but for insns with a DS field. */
1539 HOWTO (R_PPC64_DTPREL16_DS
,
1541 1, /* size (0 = byte, 1 = short, 2 = long) */
1543 FALSE
, /* pc_relative */
1545 complain_overflow_signed
, /* complain_on_overflow */
1546 ppc64_elf_unhandled_reloc
, /* special_function */
1547 "R_PPC64_DTPREL16_DS", /* name */
1548 FALSE
, /* partial_inplace */
1550 0xfffc, /* dst_mask */
1551 FALSE
), /* pcrel_offset */
1553 /* Like DTPREL16_DS, but no overflow. */
1554 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1556 1, /* size (0 = byte, 1 = short, 2 = long) */
1558 FALSE
, /* pc_relative */
1560 complain_overflow_dont
, /* complain_on_overflow */
1561 ppc64_elf_unhandled_reloc
, /* special_function */
1562 "R_PPC64_DTPREL16_LO_DS", /* name */
1563 FALSE
, /* partial_inplace */
1565 0xfffc, /* dst_mask */
1566 FALSE
), /* pcrel_offset */
1568 /* Computes a tp-relative displacement, the difference between the value of
1569 sym+add and the value of the thread pointer (r13). */
1570 HOWTO (R_PPC64_TPREL64
,
1572 4, /* size (0 = byte, 1 = short, 2 = long) */
1574 FALSE
, /* pc_relative */
1576 complain_overflow_dont
, /* complain_on_overflow */
1577 ppc64_elf_unhandled_reloc
, /* special_function */
1578 "R_PPC64_TPREL64", /* name */
1579 FALSE
, /* partial_inplace */
1581 ONES (64), /* dst_mask */
1582 FALSE
), /* pcrel_offset */
1584 /* A 16 bit tprel reloc. */
1585 HOWTO (R_PPC64_TPREL16
,
1587 1, /* size (0 = byte, 1 = short, 2 = long) */
1589 FALSE
, /* pc_relative */
1591 complain_overflow_signed
, /* complain_on_overflow */
1592 ppc64_elf_unhandled_reloc
, /* special_function */
1593 "R_PPC64_TPREL16", /* name */
1594 FALSE
, /* partial_inplace */
1596 0xffff, /* dst_mask */
1597 FALSE
), /* pcrel_offset */
1599 /* Like TPREL16, but no overflow. */
1600 HOWTO (R_PPC64_TPREL16_LO
,
1602 1, /* size (0 = byte, 1 = short, 2 = long) */
1604 FALSE
, /* pc_relative */
1606 complain_overflow_dont
, /* complain_on_overflow */
1607 ppc64_elf_unhandled_reloc
, /* special_function */
1608 "R_PPC64_TPREL16_LO", /* name */
1609 FALSE
, /* partial_inplace */
1611 0xffff, /* dst_mask */
1612 FALSE
), /* pcrel_offset */
1614 /* Like TPREL16_LO, but next higher group of 16 bits. */
1615 HOWTO (R_PPC64_TPREL16_HI
,
1616 16, /* rightshift */
1617 1, /* size (0 = byte, 1 = short, 2 = long) */
1619 FALSE
, /* pc_relative */
1621 complain_overflow_signed
, /* complain_on_overflow */
1622 ppc64_elf_unhandled_reloc
, /* special_function */
1623 "R_PPC64_TPREL16_HI", /* name */
1624 FALSE
, /* partial_inplace */
1626 0xffff, /* dst_mask */
1627 FALSE
), /* pcrel_offset */
1629 /* Like TPREL16_HI, but adjust for low 16 bits. */
1630 HOWTO (R_PPC64_TPREL16_HA
,
1631 16, /* rightshift */
1632 1, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE
, /* pc_relative */
1636 complain_overflow_signed
, /* complain_on_overflow */
1637 ppc64_elf_unhandled_reloc
, /* special_function */
1638 "R_PPC64_TPREL16_HA", /* name */
1639 FALSE
, /* partial_inplace */
1641 0xffff, /* dst_mask */
1642 FALSE
), /* pcrel_offset */
1644 /* Like TPREL16_HI, but next higher group of 16 bits. */
1645 HOWTO (R_PPC64_TPREL16_HIGHER
,
1646 32, /* rightshift */
1647 1, /* size (0 = byte, 1 = short, 2 = long) */
1649 FALSE
, /* pc_relative */
1651 complain_overflow_dont
, /* complain_on_overflow */
1652 ppc64_elf_unhandled_reloc
, /* special_function */
1653 "R_PPC64_TPREL16_HIGHER", /* name */
1654 FALSE
, /* partial_inplace */
1656 0xffff, /* dst_mask */
1657 FALSE
), /* pcrel_offset */
1659 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1660 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1661 32, /* rightshift */
1662 1, /* size (0 = byte, 1 = short, 2 = long) */
1664 FALSE
, /* pc_relative */
1666 complain_overflow_dont
, /* complain_on_overflow */
1667 ppc64_elf_unhandled_reloc
, /* special_function */
1668 "R_PPC64_TPREL16_HIGHERA", /* name */
1669 FALSE
, /* partial_inplace */
1671 0xffff, /* dst_mask */
1672 FALSE
), /* pcrel_offset */
1674 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1675 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1676 48, /* rightshift */
1677 1, /* size (0 = byte, 1 = short, 2 = long) */
1679 FALSE
, /* pc_relative */
1681 complain_overflow_dont
, /* complain_on_overflow */
1682 ppc64_elf_unhandled_reloc
, /* special_function */
1683 "R_PPC64_TPREL16_HIGHEST", /* name */
1684 FALSE
, /* partial_inplace */
1686 0xffff, /* dst_mask */
1687 FALSE
), /* pcrel_offset */
1689 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1690 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1691 48, /* rightshift */
1692 1, /* size (0 = byte, 1 = short, 2 = long) */
1694 FALSE
, /* pc_relative */
1696 complain_overflow_dont
, /* complain_on_overflow */
1697 ppc64_elf_unhandled_reloc
, /* special_function */
1698 "R_PPC64_TPREL16_HIGHESTA", /* name */
1699 FALSE
, /* partial_inplace */
1701 0xffff, /* dst_mask */
1702 FALSE
), /* pcrel_offset */
1704 /* Like TPREL16, but for insns with a DS field. */
1705 HOWTO (R_PPC64_TPREL16_DS
,
1707 1, /* size (0 = byte, 1 = short, 2 = long) */
1709 FALSE
, /* pc_relative */
1711 complain_overflow_signed
, /* complain_on_overflow */
1712 ppc64_elf_unhandled_reloc
, /* special_function */
1713 "R_PPC64_TPREL16_DS", /* name */
1714 FALSE
, /* partial_inplace */
1716 0xfffc, /* dst_mask */
1717 FALSE
), /* pcrel_offset */
1719 /* Like TPREL16_DS, but no overflow. */
1720 HOWTO (R_PPC64_TPREL16_LO_DS
,
1722 1, /* size (0 = byte, 1 = short, 2 = long) */
1724 FALSE
, /* pc_relative */
1726 complain_overflow_dont
, /* complain_on_overflow */
1727 ppc64_elf_unhandled_reloc
, /* special_function */
1728 "R_PPC64_TPREL16_LO_DS", /* name */
1729 FALSE
, /* partial_inplace */
1731 0xfffc, /* dst_mask */
1732 FALSE
), /* pcrel_offset */
1734 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1735 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1736 to the first entry relative to the TOC base (r2). */
1737 HOWTO (R_PPC64_GOT_TLSGD16
,
1739 1, /* size (0 = byte, 1 = short, 2 = long) */
1741 FALSE
, /* pc_relative */
1743 complain_overflow_signed
, /* complain_on_overflow */
1744 ppc64_elf_unhandled_reloc
, /* special_function */
1745 "R_PPC64_GOT_TLSGD16", /* name */
1746 FALSE
, /* partial_inplace */
1748 0xffff, /* dst_mask */
1749 FALSE
), /* pcrel_offset */
1751 /* Like GOT_TLSGD16, but no overflow. */
1752 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1754 1, /* size (0 = byte, 1 = short, 2 = long) */
1756 FALSE
, /* pc_relative */
1758 complain_overflow_dont
, /* complain_on_overflow */
1759 ppc64_elf_unhandled_reloc
, /* special_function */
1760 "R_PPC64_GOT_TLSGD16_LO", /* name */
1761 FALSE
, /* partial_inplace */
1763 0xffff, /* dst_mask */
1764 FALSE
), /* pcrel_offset */
1766 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1767 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1768 16, /* rightshift */
1769 1, /* size (0 = byte, 1 = short, 2 = long) */
1771 FALSE
, /* pc_relative */
1773 complain_overflow_signed
, /* complain_on_overflow */
1774 ppc64_elf_unhandled_reloc
, /* special_function */
1775 "R_PPC64_GOT_TLSGD16_HI", /* name */
1776 FALSE
, /* partial_inplace */
1778 0xffff, /* dst_mask */
1779 FALSE
), /* pcrel_offset */
1781 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1782 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1783 16, /* rightshift */
1784 1, /* size (0 = byte, 1 = short, 2 = long) */
1786 FALSE
, /* pc_relative */
1788 complain_overflow_signed
, /* complain_on_overflow */
1789 ppc64_elf_unhandled_reloc
, /* special_function */
1790 "R_PPC64_GOT_TLSGD16_HA", /* name */
1791 FALSE
, /* partial_inplace */
1793 0xffff, /* dst_mask */
1794 FALSE
), /* pcrel_offset */
1796 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1797 with values (sym+add)@dtpmod and zero, and computes the offset to the
1798 first entry relative to the TOC base (r2). */
1799 HOWTO (R_PPC64_GOT_TLSLD16
,
1801 1, /* size (0 = byte, 1 = short, 2 = long) */
1803 FALSE
, /* pc_relative */
1805 complain_overflow_signed
, /* complain_on_overflow */
1806 ppc64_elf_unhandled_reloc
, /* special_function */
1807 "R_PPC64_GOT_TLSLD16", /* name */
1808 FALSE
, /* partial_inplace */
1810 0xffff, /* dst_mask */
1811 FALSE
), /* pcrel_offset */
1813 /* Like GOT_TLSLD16, but no overflow. */
1814 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1816 1, /* size (0 = byte, 1 = short, 2 = long) */
1818 FALSE
, /* pc_relative */
1820 complain_overflow_dont
, /* complain_on_overflow */
1821 ppc64_elf_unhandled_reloc
, /* special_function */
1822 "R_PPC64_GOT_TLSLD16_LO", /* name */
1823 FALSE
, /* partial_inplace */
1825 0xffff, /* dst_mask */
1826 FALSE
), /* pcrel_offset */
1828 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1829 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1830 16, /* rightshift */
1831 1, /* size (0 = byte, 1 = short, 2 = long) */
1833 FALSE
, /* pc_relative */
1835 complain_overflow_signed
, /* complain_on_overflow */
1836 ppc64_elf_unhandled_reloc
, /* special_function */
1837 "R_PPC64_GOT_TLSLD16_HI", /* name */
1838 FALSE
, /* partial_inplace */
1840 0xffff, /* dst_mask */
1841 FALSE
), /* pcrel_offset */
1843 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1844 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1845 16, /* rightshift */
1846 1, /* size (0 = byte, 1 = short, 2 = long) */
1848 FALSE
, /* pc_relative */
1850 complain_overflow_signed
, /* complain_on_overflow */
1851 ppc64_elf_unhandled_reloc
, /* special_function */
1852 "R_PPC64_GOT_TLSLD16_HA", /* name */
1853 FALSE
, /* partial_inplace */
1855 0xffff, /* dst_mask */
1856 FALSE
), /* pcrel_offset */
1858 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1859 the offset to the entry relative to the TOC base (r2). */
1860 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1862 1, /* size (0 = byte, 1 = short, 2 = long) */
1864 FALSE
, /* pc_relative */
1866 complain_overflow_signed
, /* complain_on_overflow */
1867 ppc64_elf_unhandled_reloc
, /* special_function */
1868 "R_PPC64_GOT_DTPREL16_DS", /* name */
1869 FALSE
, /* partial_inplace */
1871 0xfffc, /* dst_mask */
1872 FALSE
), /* pcrel_offset */
1874 /* Like GOT_DTPREL16_DS, but no overflow. */
1875 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1877 1, /* size (0 = byte, 1 = short, 2 = long) */
1879 FALSE
, /* pc_relative */
1881 complain_overflow_dont
, /* complain_on_overflow */
1882 ppc64_elf_unhandled_reloc
, /* special_function */
1883 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1884 FALSE
, /* partial_inplace */
1886 0xfffc, /* dst_mask */
1887 FALSE
), /* pcrel_offset */
1889 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1890 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1891 16, /* rightshift */
1892 1, /* size (0 = byte, 1 = short, 2 = long) */
1894 FALSE
, /* pc_relative */
1896 complain_overflow_signed
, /* complain_on_overflow */
1897 ppc64_elf_unhandled_reloc
, /* special_function */
1898 "R_PPC64_GOT_DTPREL16_HI", /* name */
1899 FALSE
, /* partial_inplace */
1901 0xffff, /* dst_mask */
1902 FALSE
), /* pcrel_offset */
1904 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1905 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1906 16, /* rightshift */
1907 1, /* size (0 = byte, 1 = short, 2 = long) */
1909 FALSE
, /* pc_relative */
1911 complain_overflow_signed
, /* complain_on_overflow */
1912 ppc64_elf_unhandled_reloc
, /* special_function */
1913 "R_PPC64_GOT_DTPREL16_HA", /* name */
1914 FALSE
, /* partial_inplace */
1916 0xffff, /* dst_mask */
1917 FALSE
), /* pcrel_offset */
1919 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1920 offset to the entry relative to the TOC base (r2). */
1921 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1923 1, /* size (0 = byte, 1 = short, 2 = long) */
1925 FALSE
, /* pc_relative */
1927 complain_overflow_signed
, /* complain_on_overflow */
1928 ppc64_elf_unhandled_reloc
, /* special_function */
1929 "R_PPC64_GOT_TPREL16_DS", /* name */
1930 FALSE
, /* partial_inplace */
1932 0xfffc, /* dst_mask */
1933 FALSE
), /* pcrel_offset */
1935 /* Like GOT_TPREL16_DS, but no overflow. */
1936 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1938 1, /* size (0 = byte, 1 = short, 2 = long) */
1940 FALSE
, /* pc_relative */
1942 complain_overflow_dont
, /* complain_on_overflow */
1943 ppc64_elf_unhandled_reloc
, /* special_function */
1944 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1945 FALSE
, /* partial_inplace */
1947 0xfffc, /* dst_mask */
1948 FALSE
), /* pcrel_offset */
1950 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1951 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1952 16, /* rightshift */
1953 1, /* size (0 = byte, 1 = short, 2 = long) */
1955 FALSE
, /* pc_relative */
1957 complain_overflow_signed
, /* complain_on_overflow */
1958 ppc64_elf_unhandled_reloc
, /* special_function */
1959 "R_PPC64_GOT_TPREL16_HI", /* name */
1960 FALSE
, /* partial_inplace */
1962 0xffff, /* dst_mask */
1963 FALSE
), /* pcrel_offset */
1965 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1966 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1967 16, /* rightshift */
1968 1, /* size (0 = byte, 1 = short, 2 = long) */
1970 FALSE
, /* pc_relative */
1972 complain_overflow_signed
, /* complain_on_overflow */
1973 ppc64_elf_unhandled_reloc
, /* special_function */
1974 "R_PPC64_GOT_TPREL16_HA", /* name */
1975 FALSE
, /* partial_inplace */
1977 0xffff, /* dst_mask */
1978 FALSE
), /* pcrel_offset */
1980 HOWTO (R_PPC64_JMP_IREL
, /* type */
1982 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1984 FALSE
, /* pc_relative */
1986 complain_overflow_dont
, /* complain_on_overflow */
1987 ppc64_elf_unhandled_reloc
, /* special_function */
1988 "R_PPC64_JMP_IREL", /* name */
1989 FALSE
, /* partial_inplace */
1992 FALSE
), /* pcrel_offset */
1994 HOWTO (R_PPC64_IRELATIVE
, /* type */
1996 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
1998 FALSE
, /* pc_relative */
2000 complain_overflow_dont
, /* complain_on_overflow */
2001 bfd_elf_generic_reloc
, /* special_function */
2002 "R_PPC64_IRELATIVE", /* name */
2003 FALSE
, /* partial_inplace */
2005 ONES (64), /* dst_mask */
2006 FALSE
), /* pcrel_offset */
2008 /* A 16 bit relative relocation. */
2009 HOWTO (R_PPC64_REL16
, /* type */
2011 1, /* size (0 = byte, 1 = short, 2 = long) */
2013 TRUE
, /* pc_relative */
2015 complain_overflow_signed
, /* complain_on_overflow */
2016 bfd_elf_generic_reloc
, /* special_function */
2017 "R_PPC64_REL16", /* name */
2018 FALSE
, /* partial_inplace */
2020 0xffff, /* dst_mask */
2021 TRUE
), /* pcrel_offset */
2023 /* A 16 bit relative relocation without overflow. */
2024 HOWTO (R_PPC64_REL16_LO
, /* type */
2026 1, /* size (0 = byte, 1 = short, 2 = long) */
2028 TRUE
, /* pc_relative */
2030 complain_overflow_dont
,/* complain_on_overflow */
2031 bfd_elf_generic_reloc
, /* special_function */
2032 "R_PPC64_REL16_LO", /* name */
2033 FALSE
, /* partial_inplace */
2035 0xffff, /* dst_mask */
2036 TRUE
), /* pcrel_offset */
2038 /* The high order 16 bits of a relative address. */
2039 HOWTO (R_PPC64_REL16_HI
, /* type */
2040 16, /* rightshift */
2041 1, /* size (0 = byte, 1 = short, 2 = long) */
2043 TRUE
, /* pc_relative */
2045 complain_overflow_signed
, /* complain_on_overflow */
2046 bfd_elf_generic_reloc
, /* special_function */
2047 "R_PPC64_REL16_HI", /* name */
2048 FALSE
, /* partial_inplace */
2050 0xffff, /* dst_mask */
2051 TRUE
), /* pcrel_offset */
2053 /* The high order 16 bits of a relative address, plus 1 if the contents of
2054 the low 16 bits, treated as a signed number, is negative. */
2055 HOWTO (R_PPC64_REL16_HA
, /* type */
2056 16, /* rightshift */
2057 1, /* size (0 = byte, 1 = short, 2 = long) */
2059 TRUE
, /* pc_relative */
2061 complain_overflow_signed
, /* complain_on_overflow */
2062 ppc64_elf_ha_reloc
, /* special_function */
2063 "R_PPC64_REL16_HA", /* name */
2064 FALSE
, /* partial_inplace */
2066 0xffff, /* dst_mask */
2067 TRUE
), /* pcrel_offset */
2069 /* Like R_PPC64_REL16_HA but for split field in addpcis. */
2070 HOWTO (R_PPC64_REL16DX_HA
, /* type */
2071 16, /* rightshift */
2072 2, /* size (0 = byte, 1 = short, 2 = long) */
2074 TRUE
, /* pc_relative */
2076 complain_overflow_signed
, /* complain_on_overflow */
2077 ppc64_elf_ha_reloc
, /* special_function */
2078 "R_PPC64_REL16DX_HA", /* name */
2079 FALSE
, /* partial_inplace */
2081 0x1fffc1, /* dst_mask */
2082 TRUE
), /* pcrel_offset */
2084 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
2085 HOWTO (R_PPC64_16DX_HA
, /* type */
2086 16, /* rightshift */
2087 2, /* size (0 = byte, 1 = short, 2 = long) */
2089 FALSE
, /* pc_relative */
2091 complain_overflow_signed
, /* complain_on_overflow */
2092 ppc64_elf_ha_reloc
, /* special_function */
2093 "R_PPC64_16DX_HA", /* name */
2094 FALSE
, /* partial_inplace */
2096 0x1fffc1, /* dst_mask */
2097 FALSE
), /* pcrel_offset */
2099 /* Like R_PPC64_ADDR16_HI, but no overflow. */
2100 HOWTO (R_PPC64_ADDR16_HIGH
, /* type */
2101 16, /* rightshift */
2102 1, /* size (0 = byte, 1 = short, 2 = long) */
2104 FALSE
, /* pc_relative */
2106 complain_overflow_dont
, /* complain_on_overflow */
2107 bfd_elf_generic_reloc
, /* special_function */
2108 "R_PPC64_ADDR16_HIGH", /* name */
2109 FALSE
, /* partial_inplace */
2111 0xffff, /* dst_mask */
2112 FALSE
), /* pcrel_offset */
2114 /* Like R_PPC64_ADDR16_HA, but no overflow. */
2115 HOWTO (R_PPC64_ADDR16_HIGHA
, /* type */
2116 16, /* rightshift */
2117 1, /* size (0 = byte, 1 = short, 2 = long) */
2119 FALSE
, /* pc_relative */
2121 complain_overflow_dont
, /* complain_on_overflow */
2122 ppc64_elf_ha_reloc
, /* special_function */
2123 "R_PPC64_ADDR16_HIGHA", /* name */
2124 FALSE
, /* partial_inplace */
2126 0xffff, /* dst_mask */
2127 FALSE
), /* pcrel_offset */
2129 /* Like R_PPC64_DTPREL16_HI, but no overflow. */
2130 HOWTO (R_PPC64_DTPREL16_HIGH
,
2131 16, /* rightshift */
2132 1, /* size (0 = byte, 1 = short, 2 = long) */
2134 FALSE
, /* pc_relative */
2136 complain_overflow_dont
, /* complain_on_overflow */
2137 ppc64_elf_unhandled_reloc
, /* special_function */
2138 "R_PPC64_DTPREL16_HIGH", /* name */
2139 FALSE
, /* partial_inplace */
2141 0xffff, /* dst_mask */
2142 FALSE
), /* pcrel_offset */
2144 /* Like R_PPC64_DTPREL16_HA, but no overflow. */
2145 HOWTO (R_PPC64_DTPREL16_HIGHA
,
2146 16, /* rightshift */
2147 1, /* size (0 = byte, 1 = short, 2 = long) */
2149 FALSE
, /* pc_relative */
2151 complain_overflow_dont
, /* complain_on_overflow */
2152 ppc64_elf_unhandled_reloc
, /* special_function */
2153 "R_PPC64_DTPREL16_HIGHA", /* name */
2154 FALSE
, /* partial_inplace */
2156 0xffff, /* dst_mask */
2157 FALSE
), /* pcrel_offset */
2159 /* Like R_PPC64_TPREL16_HI, but no overflow. */
2160 HOWTO (R_PPC64_TPREL16_HIGH
,
2161 16, /* rightshift */
2162 1, /* size (0 = byte, 1 = short, 2 = long) */
2164 FALSE
, /* pc_relative */
2166 complain_overflow_dont
, /* complain_on_overflow */
2167 ppc64_elf_unhandled_reloc
, /* special_function */
2168 "R_PPC64_TPREL16_HIGH", /* name */
2169 FALSE
, /* partial_inplace */
2171 0xffff, /* dst_mask */
2172 FALSE
), /* pcrel_offset */
2174 /* Like R_PPC64_TPREL16_HA, but no overflow. */
2175 HOWTO (R_PPC64_TPREL16_HIGHA
,
2176 16, /* rightshift */
2177 1, /* size (0 = byte, 1 = short, 2 = long) */
2179 FALSE
, /* pc_relative */
2181 complain_overflow_dont
, /* complain_on_overflow */
2182 ppc64_elf_unhandled_reloc
, /* special_function */
2183 "R_PPC64_TPREL16_HIGHA", /* name */
2184 FALSE
, /* partial_inplace */
2186 0xffff, /* dst_mask */
2187 FALSE
), /* pcrel_offset */
2189 /* Marker reloc on ELFv2 large-model function entry. */
2190 HOWTO (R_PPC64_ENTRY
,
2192 2, /* size (0 = byte, 1 = short, 2 = long) */
2194 FALSE
, /* pc_relative */
2196 complain_overflow_dont
, /* complain_on_overflow */
2197 bfd_elf_generic_reloc
, /* special_function */
2198 "R_PPC64_ENTRY", /* name */
2199 FALSE
, /* partial_inplace */
2202 FALSE
), /* pcrel_offset */
2204 /* Like ADDR64, but use local entry point of function. */
2205 HOWTO (R_PPC64_ADDR64_LOCAL
, /* type */
2207 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
2209 FALSE
, /* pc_relative */
2211 complain_overflow_dont
, /* complain_on_overflow */
2212 bfd_elf_generic_reloc
, /* special_function */
2213 "R_PPC64_ADDR64_LOCAL", /* name */
2214 FALSE
, /* partial_inplace */
2216 ONES (64), /* dst_mask */
2217 FALSE
), /* pcrel_offset */
2219 /* GNU extension to record C++ vtable hierarchy. */
2220 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
2222 0, /* size (0 = byte, 1 = short, 2 = long) */
2224 FALSE
, /* pc_relative */
2226 complain_overflow_dont
, /* complain_on_overflow */
2227 NULL
, /* special_function */
2228 "R_PPC64_GNU_VTINHERIT", /* name */
2229 FALSE
, /* partial_inplace */
2232 FALSE
), /* pcrel_offset */
2234 /* GNU extension to record C++ vtable member usage. */
2235 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
2237 0, /* size (0 = byte, 1 = short, 2 = long) */
2239 FALSE
, /* pc_relative */
2241 complain_overflow_dont
, /* complain_on_overflow */
2242 NULL
, /* special_function */
2243 "R_PPC64_GNU_VTENTRY", /* name */
2244 FALSE
, /* partial_inplace */
2247 FALSE
), /* pcrel_offset */
2251 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
2255 ppc_howto_init (void)
2257 unsigned int i
, type
;
2259 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2261 type
= ppc64_elf_howto_raw
[i
].type
;
2262 BFD_ASSERT (type
< ARRAY_SIZE (ppc64_elf_howto_table
));
2263 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
2267 static reloc_howto_type
*
2268 ppc64_elf_reloc_type_lookup (bfd
*abfd
,
2269 bfd_reloc_code_real_type code
)
2271 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
2273 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2274 /* Initialize howto table if needed. */
2280 /* xgettext:c-format */
2281 _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd
, (int) code
);
2282 bfd_set_error (bfd_error_bad_value
);
2285 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
2287 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
2289 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
2291 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
2293 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
2295 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
2297 case BFD_RELOC_PPC64_ADDR16_HIGH
: r
= R_PPC64_ADDR16_HIGH
;
2299 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
2301 case BFD_RELOC_PPC64_ADDR16_HIGHA
: r
= R_PPC64_ADDR16_HIGHA
;
2303 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
2305 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
2307 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
2309 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
2311 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
2313 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
2315 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
2317 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
2319 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
2321 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
2323 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
2325 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
2327 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
2329 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
2331 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
2333 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
2335 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
2337 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
2339 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
2341 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
2343 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
2345 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
2347 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
2349 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
2351 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
2353 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
2355 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
2357 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
2359 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
2361 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
2363 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
2365 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
2367 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
2369 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
2371 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
2373 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
2375 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
2377 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
2379 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2381 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2383 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2385 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2387 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2389 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2391 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2393 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2395 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2397 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2399 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2401 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2403 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2405 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2407 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2409 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC64_TLSGD
;
2411 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC64_TLSLD
;
2413 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2415 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2417 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2419 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2421 case BFD_RELOC_PPC64_TPREL16_HIGH
: r
= R_PPC64_TPREL16_HIGH
;
2423 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2425 case BFD_RELOC_PPC64_TPREL16_HIGHA
: r
= R_PPC64_TPREL16_HIGHA
;
2427 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2429 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2431 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2433 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2435 case BFD_RELOC_PPC64_DTPREL16_HIGH
: r
= R_PPC64_DTPREL16_HIGH
;
2437 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2439 case BFD_RELOC_PPC64_DTPREL16_HIGHA
: r
= R_PPC64_DTPREL16_HIGHA
;
2441 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2443 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2445 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2447 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2449 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2451 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2453 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2455 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2457 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2459 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2461 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2463 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2465 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2467 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2469 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2471 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2473 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2475 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2477 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2479 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2481 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2483 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2485 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2487 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2489 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2491 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2493 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2495 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2497 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2499 case BFD_RELOC_16_PCREL
: r
= R_PPC64_REL16
;
2501 case BFD_RELOC_LO16_PCREL
: r
= R_PPC64_REL16_LO
;
2503 case BFD_RELOC_HI16_PCREL
: r
= R_PPC64_REL16_HI
;
2505 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC64_REL16_HA
;
2507 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC64_16DX_HA
;
2509 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC64_REL16DX_HA
;
2511 case BFD_RELOC_PPC64_ENTRY
: r
= R_PPC64_ENTRY
;
2513 case BFD_RELOC_PPC64_ADDR64_LOCAL
: r
= R_PPC64_ADDR64_LOCAL
;
2515 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2517 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2521 return ppc64_elf_howto_table
[r
];
2524 static reloc_howto_type
*
2525 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2530 for (i
= 0; i
< ARRAY_SIZE (ppc64_elf_howto_raw
); i
++)
2531 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2532 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2533 return &ppc64_elf_howto_raw
[i
];
2539 /* Set the howto pointer for a PowerPC ELF reloc. */
2542 ppc64_elf_info_to_howto (bfd
*abfd
, arelent
*cache_ptr
,
2543 Elf_Internal_Rela
*dst
)
2547 /* Initialize howto table if needed. */
2548 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2551 type
= ELF64_R_TYPE (dst
->r_info
);
2552 if (type
>= ARRAY_SIZE (ppc64_elf_howto_table
))
2554 /* xgettext:c-format */
2555 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2557 bfd_set_error (bfd_error_bad_value
);
2560 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2561 if (cache_ptr
->howto
== NULL
|| cache_ptr
->howto
->name
== NULL
)
2563 /* xgettext:c-format */
2564 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2566 bfd_set_error (bfd_error_bad_value
);
2573 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2575 static bfd_reloc_status_type
2576 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2577 void *data
, asection
*input_section
,
2578 bfd
*output_bfd
, char **error_message
)
2580 enum elf_ppc64_reloc_type r_type
;
2582 bfd_size_type octets
;
2585 /* If this is a relocatable link (output_bfd test tells us), just
2586 call the generic function. Any adjustment will be done at final
2588 if (output_bfd
!= NULL
)
2589 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2590 input_section
, output_bfd
, error_message
);
2592 /* Adjust the addend for sign extension of the low 16 bits.
2593 We won't actually be using the low 16 bits, so trashing them
2595 reloc_entry
->addend
+= 0x8000;
2596 r_type
= reloc_entry
->howto
->type
;
2597 if (r_type
!= R_PPC64_REL16DX_HA
)
2598 return bfd_reloc_continue
;
2601 if (!bfd_is_com_section (symbol
->section
))
2602 value
= symbol
->value
;
2603 value
+= (reloc_entry
->addend
2604 + symbol
->section
->output_offset
2605 + symbol
->section
->output_section
->vma
);
2606 value
-= (reloc_entry
->address
2607 + input_section
->output_offset
2608 + input_section
->output_section
->vma
);
2609 value
= (bfd_signed_vma
) value
>> 16;
2611 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2612 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2614 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
2615 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2616 if (value
+ 0x8000 > 0xffff)
2617 return bfd_reloc_overflow
;
2618 return bfd_reloc_ok
;
2621 static bfd_reloc_status_type
2622 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2623 void *data
, asection
*input_section
,
2624 bfd
*output_bfd
, char **error_message
)
2626 if (output_bfd
!= NULL
)
2627 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2628 input_section
, output_bfd
, error_message
);
2630 if (strcmp (symbol
->section
->name
, ".opd") == 0
2631 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2633 bfd_vma dest
= opd_entry_value (symbol
->section
,
2634 symbol
->value
+ reloc_entry
->addend
,
2636 if (dest
!= (bfd_vma
) -1)
2637 reloc_entry
->addend
= dest
- (symbol
->value
2638 + symbol
->section
->output_section
->vma
2639 + symbol
->section
->output_offset
);
2643 elf_symbol_type
*elfsym
= (elf_symbol_type
*) symbol
;
2645 if (symbol
->section
->owner
!= abfd
2646 && symbol
->section
->owner
!= NULL
2647 && abiversion (symbol
->section
->owner
) >= 2)
2651 for (i
= 0; i
< symbol
->section
->owner
->symcount
; ++i
)
2653 asymbol
*symdef
= symbol
->section
->owner
->outsymbols
[i
];
2655 if (strcmp (symdef
->name
, symbol
->name
) == 0)
2657 elfsym
= (elf_symbol_type
*) symdef
;
2663 += PPC64_LOCAL_ENTRY_OFFSET (elfsym
->internal_elf_sym
.st_other
);
2665 return bfd_reloc_continue
;
2668 static bfd_reloc_status_type
2669 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2670 void *data
, asection
*input_section
,
2671 bfd
*output_bfd
, char **error_message
)
2674 enum elf_ppc64_reloc_type r_type
;
2675 bfd_size_type octets
;
2676 /* Assume 'at' branch hints. */
2677 bfd_boolean is_isa_v2
= TRUE
;
2679 /* If this is a relocatable link (output_bfd test tells us), just
2680 call the generic function. Any adjustment will be done at final
2682 if (output_bfd
!= NULL
)
2683 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2684 input_section
, output_bfd
, error_message
);
2686 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2687 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2688 insn
&= ~(0x01 << 21);
2689 r_type
= reloc_entry
->howto
->type
;
2690 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2691 || r_type
== R_PPC64_REL14_BRTAKEN
)
2692 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2696 /* Set 'a' bit. This is 0b00010 in BO field for branch
2697 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2698 for branch on CTR insns (BO == 1a00t or 1a01t). */
2699 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2701 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2711 if (!bfd_is_com_section (symbol
->section
))
2712 target
= symbol
->value
;
2713 target
+= symbol
->section
->output_section
->vma
;
2714 target
+= symbol
->section
->output_offset
;
2715 target
+= reloc_entry
->addend
;
2717 from
= (reloc_entry
->address
2718 + input_section
->output_offset
2719 + input_section
->output_section
->vma
);
2721 /* Invert 'y' bit if not the default. */
2722 if ((bfd_signed_vma
) (target
- from
) < 0)
2725 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2727 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2728 input_section
, output_bfd
, error_message
);
2731 static bfd_reloc_status_type
2732 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2733 void *data
, asection
*input_section
,
2734 bfd
*output_bfd
, char **error_message
)
2736 /* If this is a relocatable link (output_bfd test tells us), just
2737 call the generic function. Any adjustment will be done at final
2739 if (output_bfd
!= NULL
)
2740 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2741 input_section
, output_bfd
, error_message
);
2743 /* Subtract the symbol section base address. */
2744 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2745 return bfd_reloc_continue
;
2748 static bfd_reloc_status_type
2749 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2750 void *data
, asection
*input_section
,
2751 bfd
*output_bfd
, char **error_message
)
2753 /* If this is a relocatable link (output_bfd test tells us), just
2754 call the generic function. Any adjustment will be done at final
2756 if (output_bfd
!= NULL
)
2757 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2758 input_section
, output_bfd
, error_message
);
2760 /* Subtract the symbol section base address. */
2761 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2763 /* Adjust the addend for sign extension of the low 16 bits. */
2764 reloc_entry
->addend
+= 0x8000;
2765 return bfd_reloc_continue
;
2768 static bfd_reloc_status_type
2769 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2770 void *data
, asection
*input_section
,
2771 bfd
*output_bfd
, char **error_message
)
2775 /* If this is a relocatable link (output_bfd test tells us), just
2776 call the generic function. Any adjustment will be done at final
2778 if (output_bfd
!= NULL
)
2779 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2780 input_section
, output_bfd
, error_message
);
2782 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2784 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2786 /* Subtract the TOC base address. */
2787 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2788 return bfd_reloc_continue
;
2791 static bfd_reloc_status_type
2792 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2793 void *data
, asection
*input_section
,
2794 bfd
*output_bfd
, char **error_message
)
2798 /* If this is a relocatable link (output_bfd test tells us), just
2799 call the generic function. Any adjustment will be done at final
2801 if (output_bfd
!= NULL
)
2802 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2803 input_section
, output_bfd
, error_message
);
2805 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2807 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2809 /* Subtract the TOC base address. */
2810 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2812 /* Adjust the addend for sign extension of the low 16 bits. */
2813 reloc_entry
->addend
+= 0x8000;
2814 return bfd_reloc_continue
;
2817 static bfd_reloc_status_type
2818 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2819 void *data
, asection
*input_section
,
2820 bfd
*output_bfd
, char **error_message
)
2823 bfd_size_type octets
;
2825 /* If this is a relocatable link (output_bfd test tells us), just
2826 call the generic function. Any adjustment will be done at final
2828 if (output_bfd
!= NULL
)
2829 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2830 input_section
, output_bfd
, error_message
);
2832 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2834 TOCstart
= ppc64_elf_set_toc (NULL
, input_section
->output_section
->owner
);
2836 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2837 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2838 return bfd_reloc_ok
;
2841 static bfd_reloc_status_type
2842 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2843 void *data
, asection
*input_section
,
2844 bfd
*output_bfd
, char **error_message
)
2846 /* If this is a relocatable link (output_bfd test tells us), just
2847 call the generic function. Any adjustment will be done at final
2849 if (output_bfd
!= NULL
)
2850 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2851 input_section
, output_bfd
, error_message
);
2853 if (error_message
!= NULL
)
2855 static char buf
[60];
2856 sprintf (buf
, "generic linker can't handle %s",
2857 reloc_entry
->howto
->name
);
2858 *error_message
= buf
;
2860 return bfd_reloc_dangerous
;
2863 /* Track GOT entries needed for a given symbol. We might need more
2864 than one got entry per symbol. */
2867 struct got_entry
*next
;
2869 /* The symbol addend that we'll be placing in the GOT. */
2872 /* Unlike other ELF targets, we use separate GOT entries for the same
2873 symbol referenced from different input files. This is to support
2874 automatic multiple TOC/GOT sections, where the TOC base can vary
2875 from one input file to another. After partitioning into TOC groups
2876 we merge entries within the group.
2878 Point to the BFD owning this GOT entry. */
2881 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2882 TLS_TPREL or TLS_DTPREL for tls entries. */
2883 unsigned char tls_type
;
2885 /* Non-zero if got.ent points to real entry. */
2886 unsigned char is_indirect
;
2888 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2891 bfd_signed_vma refcount
;
2893 struct got_entry
*ent
;
2897 /* The same for PLT. */
2900 struct plt_entry
*next
;
2906 bfd_signed_vma refcount
;
2911 struct ppc64_elf_obj_tdata
2913 struct elf_obj_tdata elf
;
2915 /* Shortcuts to dynamic linker sections. */
2919 /* Used during garbage collection. We attach global symbols defined
2920 on removed .opd entries to this section so that the sym is removed. */
2921 asection
*deleted_section
;
2923 /* TLS local dynamic got entry handling. Support for multiple GOT
2924 sections means we potentially need one of these for each input bfd. */
2925 struct got_entry tlsld_got
;
2928 /* A copy of relocs before they are modified for --emit-relocs. */
2929 Elf_Internal_Rela
*relocs
;
2931 /* Section contents. */
2935 /* Nonzero if this bfd has small toc/got relocs, ie. that expect
2936 the reloc to be in the range -32768 to 32767. */
2937 unsigned int has_small_toc_reloc
: 1;
2939 /* Set if toc/got ha relocs detected not using r2, or lo reloc
2940 instruction not one we handle. */
2941 unsigned int unexpected_toc_insn
: 1;
2944 #define ppc64_elf_tdata(bfd) \
2945 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2947 #define ppc64_tlsld_got(bfd) \
2948 (&ppc64_elf_tdata (bfd)->tlsld_got)
2950 #define is_ppc64_elf(bfd) \
2951 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2952 && elf_object_id (bfd) == PPC64_ELF_DATA)
2954 /* Override the generic function because we store some extras. */
2957 ppc64_elf_mkobject (bfd
*abfd
)
2959 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc64_elf_obj_tdata
),
2963 /* Fix bad default arch selected for a 64 bit input bfd when the
2964 default is 32 bit. Also select arch based on apuinfo. */
2967 ppc64_elf_object_p (bfd
*abfd
)
2969 if (!abfd
->arch_info
->the_default
)
2972 if (abfd
->arch_info
->bits_per_word
== 32)
2974 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2976 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2978 /* Relies on arch after 32 bit default being 64 bit default. */
2979 abfd
->arch_info
= abfd
->arch_info
->next
;
2980 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2983 return _bfd_elf_ppc_set_arch (abfd
);
2986 /* Support for core dump NOTE sections. */
2989 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2991 size_t offset
, size
;
2993 if (note
->descsz
!= 504)
2997 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3000 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
3006 /* Make a ".reg/999" section. */
3007 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3008 size
, note
->descpos
+ offset
);
3012 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
3014 if (note
->descsz
!= 136)
3017 elf_tdata (abfd
)->core
->pid
3018 = bfd_get_32 (abfd
, note
->descdata
+ 24);
3019 elf_tdata (abfd
)->core
->program
3020 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
3021 elf_tdata (abfd
)->core
->command
3022 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
3028 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
3038 char data
[136] ATTRIBUTE_NONSTRING
;
3041 va_start (ap
, note_type
);
3042 memset (data
, 0, sizeof (data
));
3043 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
3045 /* GCC 8.1 warns about 80 equals destination size with
3046 -Wstringop-truncation:
3047 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
3049 #if GCC_VERSION == 8001
3050 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
3052 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
3055 return elfcore_write_note (abfd
, buf
, bufsiz
,
3056 "CORE", note_type
, data
, sizeof (data
));
3067 va_start (ap
, note_type
);
3068 memset (data
, 0, 112);
3069 pid
= va_arg (ap
, long);
3070 bfd_put_32 (abfd
, pid
, data
+ 32);
3071 cursig
= va_arg (ap
, int);
3072 bfd_put_16 (abfd
, cursig
, data
+ 12);
3073 greg
= va_arg (ap
, const void *);
3074 memcpy (data
+ 112, greg
, 384);
3075 memset (data
+ 496, 0, 8);
3077 return elfcore_write_note (abfd
, buf
, bufsiz
,
3078 "CORE", note_type
, data
, sizeof (data
));
3083 /* Add extra PPC sections. */
3085 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
3087 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
3088 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3089 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3090 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3091 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
3092 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
3093 { NULL
, 0, 0, 0, 0 }
3096 enum _ppc64_sec_type
{
3102 struct _ppc64_elf_section_data
3104 struct bfd_elf_section_data elf
;
3108 /* An array with one entry for each opd function descriptor,
3109 and some spares since opd entries may be either 16 or 24 bytes. */
3110 #define OPD_NDX(OFF) ((OFF) >> 4)
3111 struct _opd_sec_data
3113 /* Points to the function code section for local opd entries. */
3114 asection
**func_sec
;
3116 /* After editing .opd, adjust references to opd local syms. */
3120 /* An array for toc sections, indexed by offset/8. */
3121 struct _toc_sec_data
3123 /* Specifies the relocation symbol index used at a given toc offset. */
3126 /* And the relocation addend. */
3131 enum _ppc64_sec_type sec_type
:2;
3133 /* Flag set when small branches are detected. Used to
3134 select suitable defaults for the stub group size. */
3135 unsigned int has_14bit_branch
:1;
3137 /* Flag set when PLTCALL relocs are detected. */
3138 unsigned int has_pltcall
:1;
3141 #define ppc64_elf_section_data(sec) \
3142 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
3145 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
3147 if (!sec
->used_by_bfd
)
3149 struct _ppc64_elf_section_data
*sdata
;
3150 bfd_size_type amt
= sizeof (*sdata
);
3152 sdata
= bfd_zalloc (abfd
, amt
);
3155 sec
->used_by_bfd
= sdata
;
3158 return _bfd_elf_new_section_hook (abfd
, sec
);
3161 static struct _opd_sec_data
*
3162 get_opd_info (asection
* sec
)
3165 && ppc64_elf_section_data (sec
) != NULL
3166 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
3167 return &ppc64_elf_section_data (sec
)->u
.opd
;
3171 /* Parameters for the qsort hook. */
3172 static bfd_boolean synthetic_relocatable
;
3173 static asection
*synthetic_opd
;
3175 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
3178 compare_symbols (const void *ap
, const void *bp
)
3180 const asymbol
*a
= * (const asymbol
**) ap
;
3181 const asymbol
*b
= * (const asymbol
**) bp
;
3183 /* Section symbols first. */
3184 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
3186 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
3189 /* then .opd symbols. */
3190 if (synthetic_opd
!= NULL
)
3192 if (strcmp (a
->section
->name
, ".opd") == 0
3193 && strcmp (b
->section
->name
, ".opd") != 0)
3195 if (strcmp (a
->section
->name
, ".opd") != 0
3196 && strcmp (b
->section
->name
, ".opd") == 0)
3200 /* then other code symbols. */
3201 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3202 == (SEC_CODE
| SEC_ALLOC
)
3203 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3204 != (SEC_CODE
| SEC_ALLOC
))
3207 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3208 != (SEC_CODE
| SEC_ALLOC
)
3209 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3210 == (SEC_CODE
| SEC_ALLOC
))
3213 if (synthetic_relocatable
)
3215 if (a
->section
->id
< b
->section
->id
)
3218 if (a
->section
->id
> b
->section
->id
)
3222 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
3225 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
3228 /* For syms with the same value, prefer strong dynamic global function
3229 syms over other syms. */
3230 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
3233 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
3236 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
3239 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
3242 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
3245 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
3248 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
3251 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
3257 /* Search SYMS for a symbol of the given VALUE. */
3260 sym_exists_at (asymbol
**syms
, long lo
, long hi
, unsigned int id
, bfd_vma value
)
3264 if (id
== (unsigned) -1)
3268 mid
= (lo
+ hi
) >> 1;
3269 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
3271 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
3281 mid
= (lo
+ hi
) >> 1;
3282 if (syms
[mid
]->section
->id
< id
)
3284 else if (syms
[mid
]->section
->id
> id
)
3286 else if (syms
[mid
]->value
< value
)
3288 else if (syms
[mid
]->value
> value
)
3298 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
3300 bfd_vma vma
= *(bfd_vma
*) ptr
;
3301 return ((section
->flags
& SEC_ALLOC
) != 0
3302 && section
->vma
<= vma
3303 && vma
< section
->vma
+ section
->size
);
3306 /* Create synthetic symbols, effectively restoring "dot-symbol" function
3307 entry syms. Also generate @plt symbols for the glink branch table.
3308 Returns count of synthetic symbols in RET or -1 on error. */
3311 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
3312 long static_count
, asymbol
**static_syms
,
3313 long dyn_count
, asymbol
**dyn_syms
,
3319 size_t symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
3320 asection
*opd
= NULL
;
3321 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
3323 int abi
= abiversion (abfd
);
3329 opd
= bfd_get_section_by_name (abfd
, ".opd");
3330 if (opd
== NULL
&& abi
== 1)
3342 symcount
= static_count
;
3344 symcount
+= dyn_count
;
3348 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
3352 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
3354 /* Use both symbol tables. */
3355 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
3356 memcpy (syms
+ static_count
, dyn_syms
,
3357 (dyn_count
+ 1) * sizeof (*syms
));
3359 else if (!relocatable
&& static_count
== 0)
3360 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
3362 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
3364 /* Trim uninteresting symbols. Interesting symbols are section,
3365 function, and notype symbols. */
3366 for (i
= 0, j
= 0; i
< symcount
; ++i
)
3367 if ((syms
[i
]->flags
& (BSF_FILE
| BSF_OBJECT
| BSF_THREAD_LOCAL
3368 | BSF_RELC
| BSF_SRELC
)) == 0)
3369 syms
[j
++] = syms
[i
];
3372 synthetic_relocatable
= relocatable
;
3373 synthetic_opd
= opd
;
3374 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
3376 if (!relocatable
&& symcount
> 1)
3378 /* Trim duplicate syms, since we may have merged the normal
3379 and dynamic symbols. Actually, we only care about syms
3380 that have different values, so trim any with the same
3381 value. Don't consider ifunc and ifunc resolver symbols
3382 duplicates however, because GDB wants to know whether a
3383 text symbol is an ifunc resolver. */
3384 for (i
= 1, j
= 1; i
< symcount
; ++i
)
3386 const asymbol
*s0
= syms
[i
- 1];
3387 const asymbol
*s1
= syms
[i
];
3389 if ((s0
->value
+ s0
->section
->vma
3390 != s1
->value
+ s1
->section
->vma
)
3391 || ((s0
->flags
& BSF_GNU_INDIRECT_FUNCTION
)
3392 != (s1
->flags
& BSF_GNU_INDIRECT_FUNCTION
)))
3393 syms
[j
++] = syms
[i
];
3399 /* Note that here and in compare_symbols we can't compare opd and
3400 sym->section directly. With separate debug info files, the
3401 symbols will be extracted from the debug file while abfd passed
3402 to this function is the real binary. */
3403 if (strcmp (syms
[i
]->section
->name
, ".opd") == 0)
3407 for (; i
< symcount
; ++i
)
3408 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
3409 | SEC_THREAD_LOCAL
))
3410 != (SEC_CODE
| SEC_ALLOC
))
3411 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3415 for (; i
< symcount
; ++i
)
3416 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
3420 for (; i
< symcount
; ++i
)
3421 if (strcmp (syms
[i
]->section
->name
, ".opd") != 0)
3425 for (; i
< symcount
; ++i
)
3426 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
3427 != (SEC_CODE
| SEC_ALLOC
))
3435 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3440 if (opdsymend
== secsymend
)
3443 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3444 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
3448 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
3455 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3459 while (r
< opd
->relocation
+ relcount
3460 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3463 if (r
== opd
->relocation
+ relcount
)
3466 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3469 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3472 sym
= *r
->sym_ptr_ptr
;
3473 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3474 sym
->section
->id
, sym
->value
+ r
->addend
))
3477 size
+= sizeof (asymbol
);
3478 size
+= strlen (syms
[i
]->name
) + 2;
3484 s
= *ret
= bfd_malloc (size
);
3491 names
= (char *) (s
+ count
);
3493 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
3497 while (r
< opd
->relocation
+ relcount
3498 && r
->address
< syms
[i
]->value
+ opd
->vma
)
3501 if (r
== opd
->relocation
+ relcount
)
3504 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
3507 if (r
->howto
->type
!= R_PPC64_ADDR64
)
3510 sym
= *r
->sym_ptr_ptr
;
3511 if (!sym_exists_at (syms
, opdsymend
, symcount
,
3512 sym
->section
->id
, sym
->value
+ r
->addend
))
3517 s
->flags
|= BSF_SYNTHETIC
;
3518 s
->section
= sym
->section
;
3519 s
->value
= sym
->value
+ r
->addend
;
3522 len
= strlen (syms
[i
]->name
);
3523 memcpy (names
, syms
[i
]->name
, len
+ 1);
3525 /* Have udata.p point back to the original symbol this
3526 synthetic symbol was derived from. */
3527 s
->udata
.p
= syms
[i
];
3534 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
3535 bfd_byte
*contents
= NULL
;
3537 size_t plt_count
= 0;
3538 bfd_vma glink_vma
= 0, resolv_vma
= 0;
3539 asection
*dynamic
, *glink
= NULL
, *relplt
= NULL
;
3542 if (opd
!= NULL
&& !bfd_malloc_and_get_section (abfd
, opd
, &contents
))
3544 free_contents_and_exit_err
:
3546 free_contents_and_exit
:
3553 for (i
= secsymend
; i
< opdsymend
; ++i
)
3557 /* Ignore bogus symbols. */
3558 if (syms
[i
]->value
> opd
->size
- 8)
3561 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3562 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3565 size
+= sizeof (asymbol
);
3566 size
+= strlen (syms
[i
]->name
) + 2;
3570 /* Get start of .glink stubs from DT_PPC64_GLINK. */
3572 && (dynamic
= bfd_get_section_by_name (abfd
, ".dynamic")) != NULL
)
3574 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
3576 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
3578 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
3579 goto free_contents_and_exit_err
;
3581 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
3582 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
3585 extdynend
= extdyn
+ dynamic
->size
;
3586 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
3588 Elf_Internal_Dyn dyn
;
3589 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
3591 if (dyn
.d_tag
== DT_NULL
)
3594 if (dyn
.d_tag
== DT_PPC64_GLINK
)
3596 /* The first glink stub starts at DT_PPC64_GLINK plus 32.
3597 See comment in ppc64_elf_finish_dynamic_sections. */
3598 glink_vma
= dyn
.d_un
.d_val
+ 8 * 4;
3599 /* The .glink section usually does not survive the final
3600 link; search for the section (usually .text) where the
3601 glink stubs now reside. */
3602 glink
= bfd_sections_find_if (abfd
, section_covers_vma
,
3613 /* Determine __glink trampoline by reading the relative branch
3614 from the first glink stub. */
3616 unsigned int off
= 0;
3618 while (bfd_get_section_contents (abfd
, glink
, buf
,
3619 glink_vma
+ off
- glink
->vma
, 4))
3621 unsigned int insn
= bfd_get_32 (abfd
, buf
);
3623 if ((insn
& ~0x3fffffc) == 0)
3625 resolv_vma
= glink_vma
+ off
+ (insn
^ 0x2000000) - 0x2000000;
3634 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
3636 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
3639 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
3640 if (! (*slurp_relocs
) (abfd
, relplt
, dyn_syms
, TRUE
))
3641 goto free_contents_and_exit_err
;
3643 plt_count
= relplt
->size
/ sizeof (Elf64_External_Rela
);
3644 size
+= plt_count
* sizeof (asymbol
);
3646 p
= relplt
->relocation
;
3647 for (i
= 0; i
< plt_count
; i
++, p
++)
3649 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3651 size
+= sizeof ("+0x") - 1 + 16;
3657 goto free_contents_and_exit
;
3658 s
= *ret
= bfd_malloc (size
);
3660 goto free_contents_and_exit_err
;
3662 names
= (char *) (s
+ count
+ plt_count
+ (resolv_vma
!= 0));
3664 for (i
= secsymend
; i
< opdsymend
; ++i
)
3668 if (syms
[i
]->value
> opd
->size
- 8)
3671 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3672 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3676 asection
*sec
= abfd
->sections
;
3683 size_t mid
= (lo
+ hi
) >> 1;
3684 if (syms
[mid
]->section
->vma
< ent
)
3686 else if (syms
[mid
]->section
->vma
> ent
)
3690 sec
= syms
[mid
]->section
;
3695 if (lo
>= hi
&& lo
> codesecsym
)
3696 sec
= syms
[lo
- 1]->section
;
3698 for (; sec
!= NULL
; sec
= sec
->next
)
3702 /* SEC_LOAD may not be set if SEC is from a separate debug
3704 if ((sec
->flags
& SEC_ALLOC
) == 0)
3706 if ((sec
->flags
& SEC_CODE
) != 0)
3709 s
->flags
|= BSF_SYNTHETIC
;
3710 s
->value
= ent
- s
->section
->vma
;
3713 len
= strlen (syms
[i
]->name
);
3714 memcpy (names
, syms
[i
]->name
, len
+ 1);
3716 /* Have udata.p point back to the original symbol this
3717 synthetic symbol was derived from. */
3718 s
->udata
.p
= syms
[i
];
3724 if (glink
!= NULL
&& relplt
!= NULL
)
3728 /* Add a symbol for the main glink trampoline. */
3729 memset (s
, 0, sizeof *s
);
3731 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
3733 s
->value
= resolv_vma
- glink
->vma
;
3735 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
3736 names
+= sizeof ("__glink_PLTresolve");
3741 /* FIXME: It would be very much nicer to put sym@plt on the
3742 stub rather than on the glink branch table entry. The
3743 objdump disassembler would then use a sensible symbol
3744 name on plt calls. The difficulty in doing so is
3745 a) finding the stubs, and,
3746 b) matching stubs against plt entries, and,
3747 c) there can be multiple stubs for a given plt entry.
3749 Solving (a) could be done by code scanning, but older
3750 ppc64 binaries used different stubs to current code.
3751 (b) is the tricky one since you need to known the toc
3752 pointer for at least one function that uses a pic stub to
3753 be able to calculate the plt address referenced.
3754 (c) means gdb would need to set multiple breakpoints (or
3755 find the glink branch itself) when setting breakpoints
3756 for pending shared library loads. */
3757 p
= relplt
->relocation
;
3758 for (i
= 0; i
< plt_count
; i
++, p
++)
3762 *s
= **p
->sym_ptr_ptr
;
3763 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
3764 we are defining a symbol, ensure one of them is set. */
3765 if ((s
->flags
& BSF_LOCAL
) == 0)
3766 s
->flags
|= BSF_GLOBAL
;
3767 s
->flags
|= BSF_SYNTHETIC
;
3769 s
->value
= glink_vma
- glink
->vma
;
3772 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3773 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3777 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3778 names
+= sizeof ("+0x") - 1;
3779 bfd_sprintf_vma (abfd
, names
, p
->addend
);
3780 names
+= strlen (names
);
3782 memcpy (names
, "@plt", sizeof ("@plt"));
3783 names
+= sizeof ("@plt");
3803 /* The following functions are specific to the ELF linker, while
3804 functions above are used generally. Those named ppc64_elf_* are
3805 called by the main ELF linker code. They appear in this file more
3806 or less in the order in which they are called. eg.
3807 ppc64_elf_check_relocs is called early in the link process,
3808 ppc64_elf_finish_dynamic_sections is one of the last functions
3811 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3812 functions have both a function code symbol and a function descriptor
3813 symbol. A call to foo in a relocatable object file looks like:
3820 The function definition in another object file might be:
3824 . .quad .TOC.@tocbase
3830 When the linker resolves the call during a static link, the branch
3831 unsurprisingly just goes to .foo and the .opd information is unused.
3832 If the function definition is in a shared library, things are a little
3833 different: The call goes via a plt call stub, the opd information gets
3834 copied to the plt, and the linker patches the nop.
3842 . std 2,40(1) # in practice, the call stub
3843 . addis 11,2,Lfoo@toc@ha # is slightly optimized, but
3844 . addi 11,11,Lfoo@toc@l # this is the general idea
3852 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3854 The "reloc ()" notation is supposed to indicate that the linker emits
3855 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3858 What are the difficulties here? Well, firstly, the relocations
3859 examined by the linker in check_relocs are against the function code
3860 sym .foo, while the dynamic relocation in the plt is emitted against
3861 the function descriptor symbol, foo. Somewhere along the line, we need
3862 to carefully copy dynamic link information from one symbol to the other.
3863 Secondly, the generic part of the elf linker will make .foo a dynamic
3864 symbol as is normal for most other backends. We need foo dynamic
3865 instead, at least for an application final link. However, when
3866 creating a shared library containing foo, we need to have both symbols
3867 dynamic so that references to .foo are satisfied during the early
3868 stages of linking. Otherwise the linker might decide to pull in a
3869 definition from some other object, eg. a static library.
3871 Update: As of August 2004, we support a new convention. Function
3872 calls may use the function descriptor symbol, ie. "bl foo". This
3873 behaves exactly as "bl .foo". */
3875 /* Of those relocs that might be copied as dynamic relocs, this
3876 function selects those that must be copied when linking a shared
3877 library or PIE, even when the symbol is local. */
3880 must_be_dyn_reloc (struct bfd_link_info
*info
,
3881 enum elf_ppc64_reloc_type r_type
)
3886 /* Only relative relocs can be resolved when the object load
3887 address isn't fixed. DTPREL64 is excluded because the
3888 dynamic linker needs to differentiate global dynamic from
3889 local dynamic __tls_index pairs when PPC64_OPT_TLS is set. */
3897 case R_PPC64_TPREL16
:
3898 case R_PPC64_TPREL16_LO
:
3899 case R_PPC64_TPREL16_HI
:
3900 case R_PPC64_TPREL16_HA
:
3901 case R_PPC64_TPREL16_DS
:
3902 case R_PPC64_TPREL16_LO_DS
:
3903 case R_PPC64_TPREL16_HIGH
:
3904 case R_PPC64_TPREL16_HIGHA
:
3905 case R_PPC64_TPREL16_HIGHER
:
3906 case R_PPC64_TPREL16_HIGHERA
:
3907 case R_PPC64_TPREL16_HIGHEST
:
3908 case R_PPC64_TPREL16_HIGHESTA
:
3909 case R_PPC64_TPREL64
:
3910 /* These relocations are relative but in a shared library the
3911 linker doesn't know the thread pointer base. */
3912 return bfd_link_dll (info
);
3916 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3917 copying dynamic variables from a shared lib into an app's dynbss
3918 section, and instead use a dynamic relocation to point into the
3919 shared lib. With code that gcc generates, it's vital that this be
3920 enabled; In the PowerPC64 ABI, the address of a function is actually
3921 the address of a function descriptor, which resides in the .opd
3922 section. gcc uses the descriptor directly rather than going via the
3923 GOT as some other ABI's do, which means that initialized function
3924 pointers must reference the descriptor. Thus, a function pointer
3925 initialized to the address of a function in a shared library will
3926 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3927 redefines the function descriptor symbol to point to the copy. This
3928 presents a problem as a plt entry for that function is also
3929 initialized from the function descriptor symbol and the copy reloc
3930 may not be initialized first. */
3931 #define ELIMINATE_COPY_RELOCS 1
3933 /* Section name for stubs is the associated section name plus this
3935 #define STUB_SUFFIX ".stub"
3938 ppc_stub_long_branch:
3939 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3940 destination, but a 24 bit branch in a stub section will reach.
3943 ppc_stub_plt_branch:
3944 Similar to the above, but a 24 bit branch in the stub section won't
3945 reach its destination.
3946 . addis %r11,%r2,xxx@toc@ha
3947 . ld %r12,xxx@toc@l(%r11)
3952 Used to call a function in a shared library. If it so happens that
3953 the plt entry referenced crosses a 64k boundary, then an extra
3954 "addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
3956 . addis %r11,%r2,xxx@toc@ha
3957 . ld %r12,xxx+0@toc@l(%r11)
3959 . ld %r2,xxx+8@toc@l(%r11)
3960 . ld %r11,xxx+16@toc@l(%r11)
3963 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3964 code to adjust the value and save r2 to support multiple toc sections.
3965 A ppc_stub_long_branch with an r2 offset looks like:
3967 . addis %r2,%r2,off@ha
3968 . addi %r2,%r2,off@l
3971 A ppc_stub_plt_branch with an r2 offset looks like:
3973 . addis %r11,%r2,xxx@toc@ha
3974 . ld %r12,xxx@toc@l(%r11)
3975 . addis %r2,%r2,off@ha
3976 . addi %r2,%r2,off@l
3980 In cases where the "addis" instruction would add zero, the "addis" is
3981 omitted and following instructions modified slightly in some cases.
3984 enum ppc_stub_type
{
3986 ppc_stub_long_branch
,
3987 ppc_stub_long_branch_r2off
,
3988 ppc_stub_plt_branch
,
3989 ppc_stub_plt_branch_r2off
,
3991 ppc_stub_plt_call_r2save
,
3992 ppc_stub_global_entry
,
3996 /* Information on stub grouping. */
3999 /* The stub section. */
4001 /* This is the section to which stubs in the group will be attached. */
4004 struct map_stub
*next
;
4005 /* Whether to emit a copy of register save/restore functions in this
4008 /* The offset of the __tls_get_addr_opt plt stub bctrl in this group,
4009 or -1u if no such stub with bctrl exists. */
4010 unsigned int tls_get_addr_opt_bctrl
;
4013 struct ppc_stub_hash_entry
{
4015 /* Base hash table entry structure. */
4016 struct bfd_hash_entry root
;
4018 enum ppc_stub_type stub_type
;
4020 /* Group information. */
4021 struct map_stub
*group
;
4023 /* Offset within stub_sec of the beginning of this stub. */
4024 bfd_vma stub_offset
;
4026 /* Given the symbol's value and its section we can determine its final
4027 value when building the stubs (so the stub knows where to jump. */
4028 bfd_vma target_value
;
4029 asection
*target_section
;
4031 /* The symbol table entry, if any, that this was derived from. */
4032 struct ppc_link_hash_entry
*h
;
4033 struct plt_entry
*plt_ent
;
4036 unsigned char symtype
;
4038 /* Symbol st_other. */
4039 unsigned char other
;
4042 struct ppc_branch_hash_entry
{
4044 /* Base hash table entry structure. */
4045 struct bfd_hash_entry root
;
4047 /* Offset within branch lookup table. */
4048 unsigned int offset
;
4050 /* Generation marker. */
4054 /* Used to track dynamic relocations for local symbols. */
4055 struct ppc_dyn_relocs
4057 struct ppc_dyn_relocs
*next
;
4059 /* The input section of the reloc. */
4062 /* Total number of relocs copied for the input section. */
4063 unsigned int count
: 31;
4065 /* Whether this entry is for STT_GNU_IFUNC symbols. */
4066 unsigned int ifunc
: 1;
4069 struct ppc_link_hash_entry
4071 struct elf_link_hash_entry elf
;
4074 /* A pointer to the most recently used stub hash entry against this
4076 struct ppc_stub_hash_entry
*stub_cache
;
4078 /* A pointer to the next symbol starting with a '.' */
4079 struct ppc_link_hash_entry
*next_dot_sym
;
4082 /* Track dynamic relocs copied for this symbol. */
4083 struct elf_dyn_relocs
*dyn_relocs
;
4085 /* Link between function code and descriptor symbols. */
4086 struct ppc_link_hash_entry
*oh
;
4088 /* Flag function code and descriptor symbols. */
4089 unsigned int is_func
:1;
4090 unsigned int is_func_descriptor
:1;
4091 unsigned int fake
:1;
4093 /* Whether global opd/toc sym has been adjusted or not.
4094 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
4095 should be set for all globals defined in any opd/toc section. */
4096 unsigned int adjust_done
:1;
4098 /* Set if this is an out-of-line register save/restore function,
4099 with non-standard calling convention. */
4100 unsigned int save_res
:1;
4102 /* Set if a duplicate symbol with non-zero localentry is detected,
4103 even when the duplicate symbol does not provide a definition. */
4104 unsigned int non_zero_localentry
:1;
4106 /* Contexts in which symbol is used in the GOT (or TOC).
4107 Bits are or'd into the mask as the corresponding relocs are
4108 encountered during check_relocs, with TLS_TLS being set when any
4109 of the other TLS bits are set. tls_optimize clears bits when
4110 optimizing to indicate the corresponding GOT entry type is not
4111 needed. If set, TLS_TLS is never cleared. tls_optimize may also
4112 set TLS_TPRELGD when a GD reloc turns into a TPREL one. We use a
4113 separate flag rather than setting TPREL just for convenience in
4114 distinguishing the two cases.
4115 These flags are also kept for local symbols. */
4116 #define TLS_TLS 1 /* Any TLS reloc. */
4117 #define TLS_GD 2 /* GD reloc. */
4118 #define TLS_LD 4 /* LD reloc. */
4119 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
4120 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
4121 #define TLS_MARK 32 /* __tls_get_addr call marked. */
4122 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
4123 #define TLS_EXPLICIT 128 /* Marks TOC section TLS relocs. */
4124 unsigned char tls_mask
;
4126 /* The above field is also used to mark function symbols. In which
4127 case TLS_TLS will be 0. */
4128 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
4129 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
4130 #define NON_GOT 256 /* local symbol plt, not stored. */
4133 /* ppc64 ELF linker hash table. */
4135 struct ppc_link_hash_table
4137 struct elf_link_hash_table elf
;
4139 /* The stub hash table. */
4140 struct bfd_hash_table stub_hash_table
;
4142 /* Another hash table for plt_branch stubs. */
4143 struct bfd_hash_table branch_hash_table
;
4145 /* Hash table for function prologue tocsave. */
4146 htab_t tocsave_htab
;
4148 /* Various options and other info passed from the linker. */
4149 struct ppc64_elf_params
*params
;
4151 /* The size of sec_info below. */
4152 unsigned int sec_info_arr_size
;
4154 /* Per-section array of extra section info. Done this way rather
4155 than as part of ppc64_elf_section_data so we have the info for
4156 non-ppc64 sections. */
4159 /* Along with elf_gp, specifies the TOC pointer used by this section. */
4164 /* The section group that this section belongs to. */
4165 struct map_stub
*group
;
4166 /* A temp section list pointer. */
4171 /* Linked list of groups. */
4172 struct map_stub
*group
;
4174 /* Temp used when calculating TOC pointers. */
4177 asection
*toc_first_sec
;
4179 /* Used when adding symbols. */
4180 struct ppc_link_hash_entry
*dot_syms
;
4182 /* Shortcuts to get to dynamic linker sections. */
4184 asection
*global_entry
;
4187 asection
*relpltlocal
;
4190 asection
*glink_eh_frame
;
4192 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
4193 struct ppc_link_hash_entry
*tls_get_addr
;
4194 struct ppc_link_hash_entry
*tls_get_addr_fd
;
4196 /* The size of reliplt used by got entry relocs. */
4197 bfd_size_type got_reli_size
;
4200 unsigned long stub_count
[ppc_stub_global_entry
];
4202 /* Number of stubs against global syms. */
4203 unsigned long stub_globals
;
4205 /* Set if we're linking code with function descriptors. */
4206 unsigned int opd_abi
:1;
4208 /* Support for multiple toc sections. */
4209 unsigned int do_multi_toc
:1;
4210 unsigned int multi_toc_needed
:1;
4211 unsigned int second_toc_pass
:1;
4212 unsigned int do_toc_opt
:1;
4214 /* Set if tls optimization is enabled. */
4215 unsigned int do_tls_opt
:1;
4217 /* Set if inline plt calls should be converted to direct calls. */
4218 unsigned int can_convert_all_inline_plt
:1;
4221 unsigned int stub_error
:1;
4223 /* Whether func_desc_adjust needs to be run over symbols. */
4224 unsigned int need_func_desc_adj
:1;
4226 /* Whether there exist local gnu indirect function resolvers,
4227 referenced by dynamic relocations. */
4228 unsigned int local_ifunc_resolver
:1;
4229 unsigned int maybe_local_ifunc_resolver
:1;
4231 /* Whether plt calls for ELFv2 localentry:0 funcs have been optimized. */
4232 unsigned int has_plt_localentry0
:1;
4234 /* Incremented every time we size stubs. */
4235 unsigned int stub_iteration
;
4237 /* Small local sym cache. */
4238 struct sym_cache sym_cache
;
4241 /* Rename some of the generic section flags to better document how they
4244 /* Nonzero if this section has TLS related relocations. */
4245 #define has_tls_reloc sec_flg0
4247 /* Nonzero if this section has an old-style call to __tls_get_addr. */
4248 #define has_tls_get_addr_call sec_flg1
4250 /* Nonzero if this section has any toc or got relocs. */
4251 #define has_toc_reloc sec_flg2
4253 /* Nonzero if this section has a call to another section that uses
4255 #define makes_toc_func_call sec_flg3
4257 /* Recursion protection when determining above flag. */
4258 #define call_check_in_progress sec_flg4
4259 #define call_check_done sec_flg5
4261 /* Get the ppc64 ELF linker hash table from a link_info structure. */
4263 #define ppc_hash_table(p) \
4264 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
4265 == PPC64_ELF_DATA ? ((struct ppc_link_hash_table *) ((p)->hash)) : NULL)
4267 #define ppc_stub_hash_lookup(table, string, create, copy) \
4268 ((struct ppc_stub_hash_entry *) \
4269 bfd_hash_lookup ((table), (string), (create), (copy)))
4271 #define ppc_branch_hash_lookup(table, string, create, copy) \
4272 ((struct ppc_branch_hash_entry *) \
4273 bfd_hash_lookup ((table), (string), (create), (copy)))
4275 /* Create an entry in the stub hash table. */
4277 static struct bfd_hash_entry
*
4278 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
4279 struct bfd_hash_table
*table
,
4282 /* Allocate the structure if it has not already been allocated by a
4286 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
4291 /* Call the allocation method of the superclass. */
4292 entry
= bfd_hash_newfunc (entry
, table
, string
);
4295 struct ppc_stub_hash_entry
*eh
;
4297 /* Initialize the local fields. */
4298 eh
= (struct ppc_stub_hash_entry
*) entry
;
4299 eh
->stub_type
= ppc_stub_none
;
4301 eh
->stub_offset
= 0;
4302 eh
->target_value
= 0;
4303 eh
->target_section
= NULL
;
4312 /* Create an entry in the branch hash table. */
4314 static struct bfd_hash_entry
*
4315 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
4316 struct bfd_hash_table
*table
,
4319 /* Allocate the structure if it has not already been allocated by a
4323 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
4328 /* Call the allocation method of the superclass. */
4329 entry
= bfd_hash_newfunc (entry
, table
, string
);
4332 struct ppc_branch_hash_entry
*eh
;
4334 /* Initialize the local fields. */
4335 eh
= (struct ppc_branch_hash_entry
*) entry
;
4343 /* Create an entry in a ppc64 ELF linker hash table. */
4345 static struct bfd_hash_entry
*
4346 link_hash_newfunc (struct bfd_hash_entry
*entry
,
4347 struct bfd_hash_table
*table
,
4350 /* Allocate the structure if it has not already been allocated by a
4354 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
4359 /* Call the allocation method of the superclass. */
4360 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
4363 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
4365 memset (&eh
->u
.stub_cache
, 0,
4366 (sizeof (struct ppc_link_hash_entry
)
4367 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
4369 /* When making function calls, old ABI code references function entry
4370 points (dot symbols), while new ABI code references the function
4371 descriptor symbol. We need to make any combination of reference and
4372 definition work together, without breaking archive linking.
4374 For a defined function "foo" and an undefined call to "bar":
4375 An old object defines "foo" and ".foo", references ".bar" (possibly
4377 A new object defines "foo" and references "bar".
4379 A new object thus has no problem with its undefined symbols being
4380 satisfied by definitions in an old object. On the other hand, the
4381 old object won't have ".bar" satisfied by a new object.
4383 Keep a list of newly added dot-symbols. */
4385 if (string
[0] == '.')
4387 struct ppc_link_hash_table
*htab
;
4389 htab
= (struct ppc_link_hash_table
*) table
;
4390 eh
->u
.next_dot_sym
= htab
->dot_syms
;
4391 htab
->dot_syms
= eh
;
4398 struct tocsave_entry
{
4404 tocsave_htab_hash (const void *p
)
4406 const struct tocsave_entry
*e
= (const struct tocsave_entry
*) p
;
4407 return ((bfd_vma
) (intptr_t) e
->sec
^ e
->offset
) >> 3;
4411 tocsave_htab_eq (const void *p1
, const void *p2
)
4413 const struct tocsave_entry
*e1
= (const struct tocsave_entry
*) p1
;
4414 const struct tocsave_entry
*e2
= (const struct tocsave_entry
*) p2
;
4415 return e1
->sec
== e2
->sec
&& e1
->offset
== e2
->offset
;
4418 /* Destroy a ppc64 ELF linker hash table. */
4421 ppc64_elf_link_hash_table_free (bfd
*obfd
)
4423 struct ppc_link_hash_table
*htab
;
4425 htab
= (struct ppc_link_hash_table
*) obfd
->link
.hash
;
4426 if (htab
->tocsave_htab
)
4427 htab_delete (htab
->tocsave_htab
);
4428 bfd_hash_table_free (&htab
->branch_hash_table
);
4429 bfd_hash_table_free (&htab
->stub_hash_table
);
4430 _bfd_elf_link_hash_table_free (obfd
);
4433 /* Create a ppc64 ELF linker hash table. */
4435 static struct bfd_link_hash_table
*
4436 ppc64_elf_link_hash_table_create (bfd
*abfd
)
4438 struct ppc_link_hash_table
*htab
;
4439 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
4441 htab
= bfd_zmalloc (amt
);
4445 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
4446 sizeof (struct ppc_link_hash_entry
),
4453 /* Init the stub hash table too. */
4454 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
4455 sizeof (struct ppc_stub_hash_entry
)))
4457 _bfd_elf_link_hash_table_free (abfd
);
4461 /* And the branch hash table. */
4462 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
4463 sizeof (struct ppc_branch_hash_entry
)))
4465 bfd_hash_table_free (&htab
->stub_hash_table
);
4466 _bfd_elf_link_hash_table_free (abfd
);
4470 htab
->tocsave_htab
= htab_try_create (1024,
4474 if (htab
->tocsave_htab
== NULL
)
4476 ppc64_elf_link_hash_table_free (abfd
);
4479 htab
->elf
.root
.hash_table_free
= ppc64_elf_link_hash_table_free
;
4481 /* Initializing two fields of the union is just cosmetic. We really
4482 only care about glist, but when compiled on a 32-bit host the
4483 bfd_vma fields are larger. Setting the bfd_vma to zero makes
4484 debugger inspection of these fields look nicer. */
4485 htab
->elf
.init_got_refcount
.refcount
= 0;
4486 htab
->elf
.init_got_refcount
.glist
= NULL
;
4487 htab
->elf
.init_plt_refcount
.refcount
= 0;
4488 htab
->elf
.init_plt_refcount
.glist
= NULL
;
4489 htab
->elf
.init_got_offset
.offset
= 0;
4490 htab
->elf
.init_got_offset
.glist
= NULL
;
4491 htab
->elf
.init_plt_offset
.offset
= 0;
4492 htab
->elf
.init_plt_offset
.glist
= NULL
;
4494 return &htab
->elf
.root
;
4497 /* Create sections for linker generated code. */
4500 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
4502 struct ppc_link_hash_table
*htab
;
4505 htab
= ppc_hash_table (info
);
4507 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
4508 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4509 if (htab
->params
->save_restore_funcs
)
4511 /* Create .sfpr for code to save and restore fp regs. */
4512 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
4514 if (htab
->sfpr
== NULL
4515 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
4519 if (bfd_link_relocatable (info
))
4522 /* Create .glink for lazy dynamic linking support. */
4523 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4525 if (htab
->glink
== NULL
4526 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
4529 /* The part of .glink used by global entry stubs, separate so that
4530 it can be aligned appropriately without affecting htab->glink. */
4531 htab
->global_entry
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
4533 if (htab
->global_entry
== NULL
4534 || ! bfd_set_section_alignment (dynobj
, htab
->global_entry
, 2))
4537 if (!info
->no_ld_generated_unwind_info
)
4539 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
4540 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4541 htab
->glink_eh_frame
= bfd_make_section_anyway_with_flags (dynobj
,
4544 if (htab
->glink_eh_frame
== NULL
4545 || !bfd_set_section_alignment (dynobj
, htab
->glink_eh_frame
, 2))
4549 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
4550 htab
->elf
.iplt
= bfd_make_section_anyway_with_flags (dynobj
, ".iplt", flags
);
4551 if (htab
->elf
.iplt
== NULL
4552 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.iplt
, 3))
4555 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4556 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4558 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.iplt", flags
);
4559 if (htab
->elf
.irelplt
== NULL
4560 || ! bfd_set_section_alignment (dynobj
, htab
->elf
.irelplt
, 3))
4563 /* Create branch lookup table for plt_branch stubs. */
4564 flags
= (SEC_ALLOC
| SEC_LOAD
4565 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4566 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4568 if (htab
->brlt
== NULL
4569 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
4572 /* Local plt entries, put in .branch_lt but a separate section for
4574 htab
->pltlocal
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
4576 if (htab
->pltlocal
== NULL
4577 || ! bfd_set_section_alignment (dynobj
, htab
->pltlocal
, 3))
4580 if (!bfd_link_pic (info
))
4583 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4584 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4586 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
4587 if (htab
->relbrlt
== NULL
4588 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
4592 = bfd_make_section_anyway_with_flags (dynobj
, ".rela.branch_lt", flags
);
4593 if (htab
->relpltlocal
== NULL
4594 || ! bfd_set_section_alignment (dynobj
, htab
->relpltlocal
, 3))
4600 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
4603 ppc64_elf_init_stub_bfd (struct bfd_link_info
*info
,
4604 struct ppc64_elf_params
*params
)
4606 struct ppc_link_hash_table
*htab
;
4608 elf_elfheader (params
->stub_bfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
4610 /* Always hook our dynamic sections into the first bfd, which is the
4611 linker created stub bfd. This ensures that the GOT header is at
4612 the start of the output TOC section. */
4613 htab
= ppc_hash_table (info
);
4614 htab
->elf
.dynobj
= params
->stub_bfd
;
4615 htab
->params
= params
;
4617 return create_linkage_sections (htab
->elf
.dynobj
, info
);
4620 /* Build a name for an entry in the stub hash table. */
4623 ppc_stub_name (const asection
*input_section
,
4624 const asection
*sym_sec
,
4625 const struct ppc_link_hash_entry
*h
,
4626 const Elf_Internal_Rela
*rel
)
4631 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
4632 offsets from a sym as a branch target? In fact, we could
4633 probably assume the addend is always zero. */
4634 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
4638 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
4639 stub_name
= bfd_malloc (len
);
4640 if (stub_name
== NULL
)
4643 len
= sprintf (stub_name
, "%08x.%s+%x",
4644 input_section
->id
& 0xffffffff,
4645 h
->elf
.root
.root
.string
,
4646 (int) rel
->r_addend
& 0xffffffff);
4650 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
4651 stub_name
= bfd_malloc (len
);
4652 if (stub_name
== NULL
)
4655 len
= sprintf (stub_name
, "%08x.%x:%x+%x",
4656 input_section
->id
& 0xffffffff,
4657 sym_sec
->id
& 0xffffffff,
4658 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
4659 (int) rel
->r_addend
& 0xffffffff);
4661 if (len
> 2 && stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
4662 stub_name
[len
- 2] = 0;
4666 /* Look up an entry in the stub hash. Stub entries are cached because
4667 creating the stub name takes a bit of time. */
4669 static struct ppc_stub_hash_entry
*
4670 ppc_get_stub_entry (const asection
*input_section
,
4671 const asection
*sym_sec
,
4672 struct ppc_link_hash_entry
*h
,
4673 const Elf_Internal_Rela
*rel
,
4674 struct ppc_link_hash_table
*htab
)
4676 struct ppc_stub_hash_entry
*stub_entry
;
4677 struct map_stub
*group
;
4679 /* If this input section is part of a group of sections sharing one
4680 stub section, then use the id of the first section in the group.
4681 Stub names need to include a section id, as there may well be
4682 more than one stub used to reach say, printf, and we need to
4683 distinguish between them. */
4684 group
= htab
->sec_info
[input_section
->id
].u
.group
;
4688 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
4689 && h
->u
.stub_cache
->h
== h
4690 && h
->u
.stub_cache
->group
== group
)
4692 stub_entry
= h
->u
.stub_cache
;
4698 stub_name
= ppc_stub_name (group
->link_sec
, sym_sec
, h
, rel
);
4699 if (stub_name
== NULL
)
4702 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
4703 stub_name
, FALSE
, FALSE
);
4705 h
->u
.stub_cache
= stub_entry
;
4713 /* Add a new stub entry to the stub hash. Not all fields of the new
4714 stub entry are initialised. */
4716 static struct ppc_stub_hash_entry
*
4717 ppc_add_stub (const char *stub_name
,
4719 struct bfd_link_info
*info
)
4721 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4722 struct map_stub
*group
;
4725 struct ppc_stub_hash_entry
*stub_entry
;
4727 group
= htab
->sec_info
[section
->id
].u
.group
;
4728 link_sec
= group
->link_sec
;
4729 stub_sec
= group
->stub_sec
;
4730 if (stub_sec
== NULL
)
4736 namelen
= strlen (link_sec
->name
);
4737 len
= namelen
+ sizeof (STUB_SUFFIX
);
4738 s_name
= bfd_alloc (htab
->params
->stub_bfd
, len
);
4742 memcpy (s_name
, link_sec
->name
, namelen
);
4743 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
4744 stub_sec
= (*htab
->params
->add_stub_section
) (s_name
, link_sec
);
4745 if (stub_sec
== NULL
)
4747 group
->stub_sec
= stub_sec
;
4750 /* Enter this entry into the linker stub hash table. */
4751 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
4753 if (stub_entry
== NULL
)
4755 /* xgettext:c-format */
4756 _bfd_error_handler (_("%pB: cannot create stub entry %s"),
4757 section
->owner
, stub_name
);
4761 stub_entry
->group
= group
;
4762 stub_entry
->stub_offset
= 0;
4766 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
4767 not already done. */
4770 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4772 asection
*got
, *relgot
;
4774 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
4776 if (!is_ppc64_elf (abfd
))
4782 && !_bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
4785 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4786 | SEC_LINKER_CREATED
);
4788 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
4790 || !bfd_set_section_alignment (abfd
, got
, 3))
4793 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
4794 flags
| SEC_READONLY
);
4796 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
4799 ppc64_elf_tdata (abfd
)->got
= got
;
4800 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
4804 /* Follow indirect and warning symbol links. */
4806 static inline struct bfd_link_hash_entry
*
4807 follow_link (struct bfd_link_hash_entry
*h
)
4809 while (h
->type
== bfd_link_hash_indirect
4810 || h
->type
== bfd_link_hash_warning
)
4815 static inline struct elf_link_hash_entry
*
4816 elf_follow_link (struct elf_link_hash_entry
*h
)
4818 return (struct elf_link_hash_entry
*) follow_link (&h
->root
);
4821 static inline struct ppc_link_hash_entry
*
4822 ppc_follow_link (struct ppc_link_hash_entry
*h
)
4824 return (struct ppc_link_hash_entry
*) follow_link (&h
->elf
.root
);
4827 /* Merge PLT info on FROM with that on TO. */
4830 move_plt_plist (struct ppc_link_hash_entry
*from
,
4831 struct ppc_link_hash_entry
*to
)
4833 if (from
->elf
.plt
.plist
!= NULL
)
4835 if (to
->elf
.plt
.plist
!= NULL
)
4837 struct plt_entry
**entp
;
4838 struct plt_entry
*ent
;
4840 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
4842 struct plt_entry
*dent
;
4844 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
4845 if (dent
->addend
== ent
->addend
)
4847 dent
->plt
.refcount
+= ent
->plt
.refcount
;
4854 *entp
= to
->elf
.plt
.plist
;
4857 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
4858 from
->elf
.plt
.plist
= NULL
;
4862 /* Copy the extra info we tack onto an elf_link_hash_entry. */
4865 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
4866 struct elf_link_hash_entry
*dir
,
4867 struct elf_link_hash_entry
*ind
)
4869 struct ppc_link_hash_entry
*edir
, *eind
;
4871 edir
= (struct ppc_link_hash_entry
*) dir
;
4872 eind
= (struct ppc_link_hash_entry
*) ind
;
4874 edir
->is_func
|= eind
->is_func
;
4875 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4876 edir
->tls_mask
|= eind
->tls_mask
;
4877 if (eind
->oh
!= NULL
)
4878 edir
->oh
= ppc_follow_link (eind
->oh
);
4880 if (edir
->elf
.versioned
!= versioned_hidden
)
4881 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4882 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4883 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4884 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4885 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4886 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
4888 /* If we were called to copy over info for a weak sym, don't copy
4889 dyn_relocs, plt/got info, or dynindx. We used to copy dyn_relocs
4890 in order to simplify readonly_dynrelocs and save a field in the
4891 symbol hash entry, but that means dyn_relocs can't be used in any
4892 tests about a specific symbol, or affect other symbol flags which
4894 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4897 /* Copy over any dynamic relocs we may have on the indirect sym. */
4898 if (eind
->dyn_relocs
!= NULL
)
4900 if (edir
->dyn_relocs
!= NULL
)
4902 struct elf_dyn_relocs
**pp
;
4903 struct elf_dyn_relocs
*p
;
4905 /* Add reloc counts against the indirect sym to the direct sym
4906 list. Merge any entries against the same section. */
4907 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
4909 struct elf_dyn_relocs
*q
;
4911 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
4912 if (q
->sec
== p
->sec
)
4914 q
->pc_count
+= p
->pc_count
;
4915 q
->count
+= p
->count
;
4922 *pp
= edir
->dyn_relocs
;
4925 edir
->dyn_relocs
= eind
->dyn_relocs
;
4926 eind
->dyn_relocs
= NULL
;
4929 /* Copy over got entries that we may have already seen to the
4930 symbol which just became indirect. */
4931 if (eind
->elf
.got
.glist
!= NULL
)
4933 if (edir
->elf
.got
.glist
!= NULL
)
4935 struct got_entry
**entp
;
4936 struct got_entry
*ent
;
4938 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4940 struct got_entry
*dent
;
4942 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4943 if (dent
->addend
== ent
->addend
4944 && dent
->owner
== ent
->owner
4945 && dent
->tls_type
== ent
->tls_type
)
4947 dent
->got
.refcount
+= ent
->got
.refcount
;
4954 *entp
= edir
->elf
.got
.glist
;
4957 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4958 eind
->elf
.got
.glist
= NULL
;
4961 /* And plt entries. */
4962 move_plt_plist (eind
, edir
);
4964 if (eind
->elf
.dynindx
!= -1)
4966 if (edir
->elf
.dynindx
!= -1)
4967 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4968 edir
->elf
.dynstr_index
);
4969 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4970 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4971 eind
->elf
.dynindx
= -1;
4972 eind
->elf
.dynstr_index
= 0;
4976 /* Find the function descriptor hash entry from the given function code
4977 hash entry FH. Link the entries via their OH fields. */
4979 static struct ppc_link_hash_entry
*
4980 lookup_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4982 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4986 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4988 fdh
= (struct ppc_link_hash_entry
*)
4989 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4993 fdh
->is_func_descriptor
= 1;
4999 fdh
= ppc_follow_link (fdh
);
5000 fdh
->is_func_descriptor
= 1;
5005 /* Make a fake function descriptor sym for the undefined code sym FH. */
5007 static struct ppc_link_hash_entry
*
5008 make_fdh (struct bfd_link_info
*info
,
5009 struct ppc_link_hash_entry
*fh
)
5011 bfd
*abfd
= fh
->elf
.root
.u
.undef
.abfd
;
5012 struct bfd_link_hash_entry
*bh
= NULL
;
5013 struct ppc_link_hash_entry
*fdh
;
5014 flagword flags
= (fh
->elf
.root
.type
== bfd_link_hash_undefweak
5018 if (!_bfd_generic_link_add_one_symbol (info
, abfd
,
5019 fh
->elf
.root
.root
.string
+ 1,
5020 flags
, bfd_und_section_ptr
, 0,
5021 NULL
, FALSE
, FALSE
, &bh
))
5024 fdh
= (struct ppc_link_hash_entry
*) bh
;
5025 fdh
->elf
.non_elf
= 0;
5027 fdh
->is_func_descriptor
= 1;
5034 /* Fix function descriptor symbols defined in .opd sections to be
5038 ppc64_elf_add_symbol_hook (bfd
*ibfd
,
5039 struct bfd_link_info
*info
,
5040 Elf_Internal_Sym
*isym
,
5042 flagword
*flags ATTRIBUTE_UNUSED
,
5047 && strcmp ((*sec
)->name
, ".opd") == 0)
5051 if (!(ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
5052 || ELF_ST_TYPE (isym
->st_info
) == STT_FUNC
))
5053 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
5055 /* If the symbol is a function defined in .opd, and the function
5056 code is in a discarded group, let it appear to be undefined. */
5057 if (!bfd_link_relocatable (info
)
5058 && (*sec
)->reloc_count
!= 0
5059 && opd_entry_value (*sec
, *value
, &code_sec
, NULL
,
5060 FALSE
) != (bfd_vma
) -1
5061 && discarded_section (code_sec
))
5063 *sec
= bfd_und_section_ptr
;
5064 isym
->st_shndx
= SHN_UNDEF
;
5067 else if (*sec
!= NULL
5068 && strcmp ((*sec
)->name
, ".toc") == 0
5069 && ELF_ST_TYPE (isym
->st_info
) == STT_OBJECT
)
5071 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5073 htab
->params
->object_in_toc
= 1;
5076 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
5078 if (abiversion (ibfd
) == 0)
5079 set_abiversion (ibfd
, 2);
5080 else if (abiversion (ibfd
) == 1)
5082 _bfd_error_handler (_("symbol '%s' has invalid st_other"
5083 " for ABI version 1"), *name
);
5084 bfd_set_error (bfd_error_bad_value
);
5092 /* Merge non-visibility st_other attributes: local entry point. */
5095 ppc64_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
5096 const Elf_Internal_Sym
*isym
,
5097 bfd_boolean definition
,
5098 bfd_boolean dynamic
)
5100 if (definition
&& (!dynamic
|| !h
->def_regular
))
5101 h
->other
= ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1))
5102 | ELF_ST_VISIBILITY (h
->other
));
5105 /* Hook called on merging a symbol. We use this to clear "fake" since
5106 we now have a real symbol. */
5109 ppc64_elf_merge_symbol (struct elf_link_hash_entry
*h
,
5110 const Elf_Internal_Sym
*isym
,
5111 asection
**psec ATTRIBUTE_UNUSED
,
5112 bfd_boolean newdef ATTRIBUTE_UNUSED
,
5113 bfd_boolean olddef ATTRIBUTE_UNUSED
,
5114 bfd
*oldbfd ATTRIBUTE_UNUSED
,
5115 const asection
*oldsec ATTRIBUTE_UNUSED
)
5117 ((struct ppc_link_hash_entry
*) h
)->fake
= 0;
5118 if ((STO_PPC64_LOCAL_MASK
& isym
->st_other
) != 0)
5119 ((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
= 1;
5123 /* This function makes an old ABI object reference to ".bar" cause the
5124 inclusion of a new ABI object archive that defines "bar".
5125 NAME is a symbol defined in an archive. Return a symbol in the hash
5126 table that might be satisfied by the archive symbols. */
5128 static struct elf_link_hash_entry
*
5129 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
5130 struct bfd_link_info
*info
,
5133 struct elf_link_hash_entry
*h
;
5137 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
5139 /* Don't return this sym if it is a fake function descriptor
5140 created by add_symbol_adjust. */
5141 && !((struct ppc_link_hash_entry
*) h
)->fake
)
5147 len
= strlen (name
);
5148 dot_name
= bfd_alloc (abfd
, len
+ 2);
5149 if (dot_name
== NULL
)
5150 return (struct elf_link_hash_entry
*) -1;
5152 memcpy (dot_name
+ 1, name
, len
+ 1);
5153 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
5154 bfd_release (abfd
, dot_name
);
5158 /* This function satisfies all old ABI object references to ".bar" if a
5159 new ABI object defines "bar". Well, at least, undefined dot symbols
5160 are made weak. This stops later archive searches from including an
5161 object if we already have a function descriptor definition. It also
5162 prevents the linker complaining about undefined symbols.
5163 We also check and correct mismatched symbol visibility here. The
5164 most restrictive visibility of the function descriptor and the
5165 function entry symbol is used. */
5168 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
5170 struct ppc_link_hash_table
*htab
;
5171 struct ppc_link_hash_entry
*fdh
;
5173 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5174 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5176 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
5179 if (eh
->elf
.root
.root
.string
[0] != '.')
5182 htab
= ppc_hash_table (info
);
5186 fdh
= lookup_fdh (eh
, htab
);
5188 && !bfd_link_relocatable (info
)
5189 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
5190 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5191 && eh
->elf
.ref_regular
)
5193 /* Make an undefined function descriptor sym, in order to
5194 pull in an --as-needed shared lib. Archives are handled
5196 fdh
= make_fdh (info
, eh
);
5203 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
5204 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
5206 /* Make both descriptor and entry symbol have the most
5207 constraining visibility of either symbol. */
5208 if (entry_vis
< descr_vis
)
5209 fdh
->elf
.other
+= entry_vis
- descr_vis
;
5210 else if (entry_vis
> descr_vis
)
5211 eh
->elf
.other
+= descr_vis
- entry_vis
;
5213 /* Propagate reference flags from entry symbol to function
5214 descriptor symbol. */
5215 fdh
->elf
.root
.non_ir_ref_regular
|= eh
->elf
.root
.non_ir_ref_regular
;
5216 fdh
->elf
.root
.non_ir_ref_dynamic
|= eh
->elf
.root
.non_ir_ref_dynamic
;
5217 fdh
->elf
.ref_regular
|= eh
->elf
.ref_regular
;
5218 fdh
->elf
.ref_regular_nonweak
|= eh
->elf
.ref_regular_nonweak
;
5220 if (!fdh
->elf
.forced_local
5221 && fdh
->elf
.dynindx
== -1
5222 && fdh
->elf
.versioned
!= versioned_hidden
5223 && (bfd_link_dll (info
)
5224 || fdh
->elf
.def_dynamic
5225 || fdh
->elf
.ref_dynamic
)
5226 && (eh
->elf
.ref_regular
5227 || eh
->elf
.def_regular
))
5229 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5237 /* Set up opd section info and abiversion for IBFD, and process list
5238 of dot-symbols we made in link_hash_newfunc. */
5241 ppc64_elf_before_check_relocs (bfd
*ibfd
, struct bfd_link_info
*info
)
5243 struct ppc_link_hash_table
*htab
;
5244 struct ppc_link_hash_entry
**p
, *eh
;
5245 asection
*opd
= bfd_get_section_by_name (ibfd
, ".opd");
5247 if (opd
!= NULL
&& opd
->size
!= 0)
5249 BFD_ASSERT (ppc64_elf_section_data (opd
)->sec_type
== sec_normal
);
5250 ppc64_elf_section_data (opd
)->sec_type
= sec_opd
;
5252 if (abiversion (ibfd
) == 0)
5253 set_abiversion (ibfd
, 1);
5254 else if (abiversion (ibfd
) >= 2)
5256 /* xgettext:c-format */
5257 _bfd_error_handler (_("%pB .opd not allowed in ABI version %d"),
5258 ibfd
, abiversion (ibfd
));
5259 bfd_set_error (bfd_error_bad_value
);
5264 if (is_ppc64_elf (info
->output_bfd
))
5266 /* For input files without an explicit abiversion in e_flags
5267 we should have flagged any with symbol st_other bits set
5268 as ELFv1 and above flagged those with .opd as ELFv2.
5269 Set the output abiversion if not yet set, and for any input
5270 still ambiguous, take its abiversion from the output.
5271 Differences in ABI are reported later. */
5272 if (abiversion (info
->output_bfd
) == 0)
5273 set_abiversion (info
->output_bfd
, abiversion (ibfd
));
5274 else if (abiversion (ibfd
) == 0)
5275 set_abiversion (ibfd
, abiversion (info
->output_bfd
));
5278 htab
= ppc_hash_table (info
);
5282 if (opd
!= NULL
&& opd
->size
!= 0
5283 && (ibfd
->flags
& DYNAMIC
) == 0
5284 && (opd
->flags
& SEC_RELOC
) != 0
5285 && opd
->reloc_count
!= 0
5286 && !bfd_is_abs_section (opd
->output_section
)
5287 && info
->gc_sections
)
5289 /* Garbage collection needs some extra help with .opd sections.
5290 We don't want to necessarily keep everything referenced by
5291 relocs in .opd, as that would keep all functions. Instead,
5292 if we reference an .opd symbol (a function descriptor), we
5293 want to keep the function code symbol's section. This is
5294 easy for global symbols, but for local syms we need to keep
5295 information about the associated function section. */
5297 asection
**opd_sym_map
;
5298 Elf_Internal_Shdr
*symtab_hdr
;
5299 Elf_Internal_Rela
*relocs
, *rel_end
, *rel
;
5301 amt
= OPD_NDX (opd
->size
) * sizeof (*opd_sym_map
);
5302 opd_sym_map
= bfd_zalloc (ibfd
, amt
);
5303 if (opd_sym_map
== NULL
)
5305 ppc64_elf_section_data (opd
)->u
.opd
.func_sec
= opd_sym_map
;
5306 relocs
= _bfd_elf_link_read_relocs (ibfd
, opd
, NULL
, NULL
,
5310 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5311 rel_end
= relocs
+ opd
->reloc_count
- 1;
5312 for (rel
= relocs
; rel
< rel_end
; rel
++)
5314 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
5315 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
5317 if (r_type
== R_PPC64_ADDR64
5318 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
5319 && r_symndx
< symtab_hdr
->sh_info
)
5321 Elf_Internal_Sym
*isym
;
5324 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
, ibfd
, r_symndx
);
5327 if (elf_section_data (opd
)->relocs
!= relocs
)
5332 s
= bfd_section_from_elf_index (ibfd
, isym
->st_shndx
);
5333 if (s
!= NULL
&& s
!= opd
)
5334 opd_sym_map
[OPD_NDX (rel
->r_offset
)] = s
;
5337 if (elf_section_data (opd
)->relocs
!= relocs
)
5341 p
= &htab
->dot_syms
;
5342 while ((eh
= *p
) != NULL
)
5345 if (&eh
->elf
== htab
->elf
.hgot
)
5347 else if (htab
->elf
.hgot
== NULL
5348 && strcmp (eh
->elf
.root
.root
.string
, ".TOC.") == 0)
5349 htab
->elf
.hgot
= &eh
->elf
;
5350 else if (abiversion (ibfd
) <= 1)
5352 htab
->need_func_desc_adj
= 1;
5353 if (!add_symbol_adjust (eh
, info
))
5356 p
= &eh
->u
.next_dot_sym
;
5361 /* Undo hash table changes when an --as-needed input file is determined
5362 not to be needed. */
5365 ppc64_elf_notice_as_needed (bfd
*ibfd
,
5366 struct bfd_link_info
*info
,
5367 enum notice_asneeded_action act
)
5369 if (act
== notice_not_needed
)
5371 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5376 htab
->dot_syms
= NULL
;
5378 return _bfd_elf_notice_as_needed (ibfd
, info
, act
);
5381 /* If --just-symbols against a final linked binary, then assume we need
5382 toc adjusting stubs when calling functions defined there. */
5385 ppc64_elf_link_just_syms (asection
*sec
, struct bfd_link_info
*info
)
5387 if ((sec
->flags
& SEC_CODE
) != 0
5388 && (sec
->owner
->flags
& (EXEC_P
| DYNAMIC
)) != 0
5389 && is_ppc64_elf (sec
->owner
))
5391 if (abiversion (sec
->owner
) >= 2
5392 || bfd_get_section_by_name (sec
->owner
, ".opd") != NULL
)
5393 sec
->has_toc_reloc
= 1;
5395 _bfd_elf_link_just_syms (sec
, info
);
5398 static struct plt_entry
**
5399 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
5400 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
5402 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
5403 struct plt_entry
**local_plt
;
5404 unsigned char *local_got_tls_masks
;
5406 if (local_got_ents
== NULL
)
5408 bfd_size_type size
= symtab_hdr
->sh_info
;
5410 size
*= (sizeof (*local_got_ents
)
5411 + sizeof (*local_plt
)
5412 + sizeof (*local_got_tls_masks
));
5413 local_got_ents
= bfd_zalloc (abfd
, size
);
5414 if (local_got_ents
== NULL
)
5416 elf_local_got_ents (abfd
) = local_got_ents
;
5419 if ((tls_type
& (NON_GOT
| TLS_EXPLICIT
)) == 0)
5421 struct got_entry
*ent
;
5423 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
5424 if (ent
->addend
== r_addend
5425 && ent
->owner
== abfd
5426 && ent
->tls_type
== tls_type
)
5430 bfd_size_type amt
= sizeof (*ent
);
5431 ent
= bfd_alloc (abfd
, amt
);
5434 ent
->next
= local_got_ents
[r_symndx
];
5435 ent
->addend
= r_addend
;
5437 ent
->tls_type
= tls_type
;
5438 ent
->is_indirect
= FALSE
;
5439 ent
->got
.refcount
= 0;
5440 local_got_ents
[r_symndx
] = ent
;
5442 ent
->got
.refcount
+= 1;
5445 local_plt
= (struct plt_entry
**) (local_got_ents
+ symtab_hdr
->sh_info
);
5446 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
5447 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
5449 return local_plt
+ r_symndx
;
5453 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
, bfd_vma addend
)
5455 struct plt_entry
*ent
;
5457 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
5458 if (ent
->addend
== addend
)
5462 bfd_size_type amt
= sizeof (*ent
);
5463 ent
= bfd_alloc (abfd
, amt
);
5467 ent
->addend
= addend
;
5468 ent
->plt
.refcount
= 0;
5471 ent
->plt
.refcount
+= 1;
5476 is_branch_reloc (enum elf_ppc64_reloc_type r_type
)
5478 return (r_type
== R_PPC64_REL24
5479 || r_type
== R_PPC64_REL14
5480 || r_type
== R_PPC64_REL14_BRTAKEN
5481 || r_type
== R_PPC64_REL14_BRNTAKEN
5482 || r_type
== R_PPC64_ADDR24
5483 || r_type
== R_PPC64_ADDR14
5484 || r_type
== R_PPC64_ADDR14_BRTAKEN
5485 || r_type
== R_PPC64_ADDR14_BRNTAKEN
5486 || r_type
== R_PPC64_PLTCALL
);
5489 /* Relocs on inline plt call sequence insns prior to the call. */
5492 is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type
)
5494 return (r_type
== R_PPC64_PLT16_HA
5495 || r_type
== R_PPC64_PLT16_HI
5496 || r_type
== R_PPC64_PLT16_LO
5497 || r_type
== R_PPC64_PLT16_LO_DS
5498 || r_type
== R_PPC64_PLTSEQ
);
5501 /* Look through the relocs for a section during the first phase, and
5502 calculate needed space in the global offset table, procedure
5503 linkage table, and dynamic reloc sections. */
5506 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
5507 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5509 struct ppc_link_hash_table
*htab
;
5510 Elf_Internal_Shdr
*symtab_hdr
;
5511 struct elf_link_hash_entry
**sym_hashes
;
5512 const Elf_Internal_Rela
*rel
;
5513 const Elf_Internal_Rela
*rel_end
;
5515 struct elf_link_hash_entry
*tga
, *dottga
;
5518 if (bfd_link_relocatable (info
))
5521 /* Don't do anything special with non-loaded, non-alloced sections.
5522 In particular, any relocs in such sections should not affect GOT
5523 and PLT reference counting (ie. we don't allow them to create GOT
5524 or PLT entries), there's no possibility or desire to optimize TLS
5525 relocs, and there's not much point in propagating relocs to shared
5526 libs that the dynamic linker won't relocate. */
5527 if ((sec
->flags
& SEC_ALLOC
) == 0)
5530 BFD_ASSERT (is_ppc64_elf (abfd
));
5532 htab
= ppc_hash_table (info
);
5536 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
5537 FALSE
, FALSE
, TRUE
);
5538 dottga
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
5539 FALSE
, FALSE
, TRUE
);
5540 symtab_hdr
= &elf_symtab_hdr (abfd
);
5541 sym_hashes
= elf_sym_hashes (abfd
);
5543 is_opd
= ppc64_elf_section_data (sec
)->sec_type
== sec_opd
;
5544 rel_end
= relocs
+ sec
->reloc_count
;
5545 for (rel
= relocs
; rel
< rel_end
; rel
++)
5547 unsigned long r_symndx
;
5548 struct elf_link_hash_entry
*h
;
5549 enum elf_ppc64_reloc_type r_type
;
5551 struct _ppc64_elf_section_data
*ppc64_sec
;
5552 struct plt_entry
**ifunc
, **plt_list
;
5554 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5555 if (r_symndx
< symtab_hdr
->sh_info
)
5559 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5560 h
= elf_follow_link (h
);
5562 if (h
== htab
->elf
.hgot
)
5563 sec
->has_toc_reloc
= 1;
5570 if (h
->type
== STT_GNU_IFUNC
)
5573 ifunc
= &h
->plt
.plist
;
5578 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5583 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
5585 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5587 NON_GOT
| PLT_IFUNC
);
5593 r_type
= ELF64_R_TYPE (rel
->r_info
);
5598 /* These special tls relocs tie a call to __tls_get_addr with
5599 its parameter symbol. */
5601 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
5603 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5605 NON_GOT
| TLS_TLS
| TLS_MARK
))
5607 sec
->has_tls_reloc
= 1;
5610 case R_PPC64_GOT_TLSLD16
:
5611 case R_PPC64_GOT_TLSLD16_LO
:
5612 case R_PPC64_GOT_TLSLD16_HI
:
5613 case R_PPC64_GOT_TLSLD16_HA
:
5614 tls_type
= TLS_TLS
| TLS_LD
;
5617 case R_PPC64_GOT_TLSGD16
:
5618 case R_PPC64_GOT_TLSGD16_LO
:
5619 case R_PPC64_GOT_TLSGD16_HI
:
5620 case R_PPC64_GOT_TLSGD16_HA
:
5621 tls_type
= TLS_TLS
| TLS_GD
;
5624 case R_PPC64_GOT_TPREL16_DS
:
5625 case R_PPC64_GOT_TPREL16_LO_DS
:
5626 case R_PPC64_GOT_TPREL16_HI
:
5627 case R_PPC64_GOT_TPREL16_HA
:
5628 if (bfd_link_dll (info
))
5629 info
->flags
|= DF_STATIC_TLS
;
5630 tls_type
= TLS_TLS
| TLS_TPREL
;
5633 case R_PPC64_GOT_DTPREL16_DS
:
5634 case R_PPC64_GOT_DTPREL16_LO_DS
:
5635 case R_PPC64_GOT_DTPREL16_HI
:
5636 case R_PPC64_GOT_DTPREL16_HA
:
5637 tls_type
= TLS_TLS
| TLS_DTPREL
;
5639 sec
->has_tls_reloc
= 1;
5643 case R_PPC64_GOT16_DS
:
5644 case R_PPC64_GOT16_HA
:
5645 case R_PPC64_GOT16_HI
:
5646 case R_PPC64_GOT16_LO
:
5647 case R_PPC64_GOT16_LO_DS
:
5648 /* This symbol requires a global offset table entry. */
5649 sec
->has_toc_reloc
= 1;
5650 if (r_type
== R_PPC64_GOT_TLSLD16
5651 || r_type
== R_PPC64_GOT_TLSGD16
5652 || r_type
== R_PPC64_GOT_TPREL16_DS
5653 || r_type
== R_PPC64_GOT_DTPREL16_DS
5654 || r_type
== R_PPC64_GOT16
5655 || r_type
== R_PPC64_GOT16_DS
)
5657 htab
->do_multi_toc
= 1;
5658 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5661 if (ppc64_elf_tdata (abfd
)->got
== NULL
5662 && !create_got_section (abfd
, info
))
5667 struct ppc_link_hash_entry
*eh
;
5668 struct got_entry
*ent
;
5670 eh
= (struct ppc_link_hash_entry
*) h
;
5671 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5672 if (ent
->addend
== rel
->r_addend
5673 && ent
->owner
== abfd
5674 && ent
->tls_type
== tls_type
)
5678 bfd_size_type amt
= sizeof (*ent
);
5679 ent
= bfd_alloc (abfd
, amt
);
5682 ent
->next
= eh
->elf
.got
.glist
;
5683 ent
->addend
= rel
->r_addend
;
5685 ent
->tls_type
= tls_type
;
5686 ent
->is_indirect
= FALSE
;
5687 ent
->got
.refcount
= 0;
5688 eh
->elf
.got
.glist
= ent
;
5690 ent
->got
.refcount
+= 1;
5691 eh
->tls_mask
|= tls_type
;
5694 /* This is a global offset table entry for a local symbol. */
5695 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5696 rel
->r_addend
, tls_type
))
5699 /* We may also need a plt entry if the symbol turns out to be
5701 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1)
5703 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5708 case R_PPC64_PLT16_HA
:
5709 case R_PPC64_PLT16_HI
:
5710 case R_PPC64_PLT16_LO
:
5711 case R_PPC64_PLT16_LO_DS
:
5714 /* This symbol requires a procedure linkage table entry. */
5719 if (h
->root
.root
.string
[0] == '.'
5720 && h
->root
.root
.string
[1] != '\0')
5721 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5722 ((struct ppc_link_hash_entry
*) h
)->tls_mask
|= PLT_KEEP
;
5723 plt_list
= &h
->plt
.plist
;
5725 if (plt_list
== NULL
)
5726 plt_list
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5728 NON_GOT
| PLT_KEEP
);
5729 if (!update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5733 /* The following relocations don't need to propagate the
5734 relocation if linking a shared object since they are
5735 section relative. */
5736 case R_PPC64_SECTOFF
:
5737 case R_PPC64_SECTOFF_LO
:
5738 case R_PPC64_SECTOFF_HI
:
5739 case R_PPC64_SECTOFF_HA
:
5740 case R_PPC64_SECTOFF_DS
:
5741 case R_PPC64_SECTOFF_LO_DS
:
5742 case R_PPC64_DTPREL16
:
5743 case R_PPC64_DTPREL16_LO
:
5744 case R_PPC64_DTPREL16_HI
:
5745 case R_PPC64_DTPREL16_HA
:
5746 case R_PPC64_DTPREL16_DS
:
5747 case R_PPC64_DTPREL16_LO_DS
:
5748 case R_PPC64_DTPREL16_HIGH
:
5749 case R_PPC64_DTPREL16_HIGHA
:
5750 case R_PPC64_DTPREL16_HIGHER
:
5751 case R_PPC64_DTPREL16_HIGHERA
:
5752 case R_PPC64_DTPREL16_HIGHEST
:
5753 case R_PPC64_DTPREL16_HIGHESTA
:
5758 case R_PPC64_REL16_LO
:
5759 case R_PPC64_REL16_HI
:
5760 case R_PPC64_REL16_HA
:
5761 case R_PPC64_REL16DX_HA
:
5764 /* Not supported as a dynamic relocation. */
5765 case R_PPC64_ADDR64_LOCAL
:
5766 if (bfd_link_pic (info
))
5768 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
5770 /* xgettext:c-format */
5771 info
->callbacks
->einfo (_("%H: %s reloc unsupported "
5772 "in shared libraries and PIEs\n"),
5773 abfd
, sec
, rel
->r_offset
,
5774 ppc64_elf_howto_table
[r_type
]->name
);
5775 bfd_set_error (bfd_error_bad_value
);
5781 case R_PPC64_TOC16_DS
:
5782 htab
->do_multi_toc
= 1;
5783 ppc64_elf_tdata (abfd
)->has_small_toc_reloc
= 1;
5785 case R_PPC64_TOC16_LO
:
5786 case R_PPC64_TOC16_HI
:
5787 case R_PPC64_TOC16_HA
:
5788 case R_PPC64_TOC16_LO_DS
:
5789 sec
->has_toc_reloc
= 1;
5796 /* This relocation describes the C++ object vtable hierarchy.
5797 Reconstruct it for later use during GC. */
5798 case R_PPC64_GNU_VTINHERIT
:
5799 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
5803 /* This relocation describes which C++ vtable entries are actually
5804 used. Record for later use during GC. */
5805 case R_PPC64_GNU_VTENTRY
:
5806 BFD_ASSERT (h
!= NULL
);
5808 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
5813 case R_PPC64_REL14_BRTAKEN
:
5814 case R_PPC64_REL14_BRNTAKEN
:
5816 asection
*dest
= NULL
;
5818 /* Heuristic: If jumping outside our section, chances are
5819 we are going to need a stub. */
5822 /* If the sym is weak it may be overridden later, so
5823 don't assume we know where a weak sym lives. */
5824 if (h
->root
.type
== bfd_link_hash_defined
)
5825 dest
= h
->root
.u
.def
.section
;
5829 Elf_Internal_Sym
*isym
;
5831 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
5836 dest
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
5840 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
5844 case R_PPC64_PLTCALL
:
5845 ppc64_elf_section_data (sec
)->has_pltcall
= 1;
5854 if (h
->root
.root
.string
[0] == '.'
5855 && h
->root
.root
.string
[1] != '\0')
5856 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5858 if (h
== tga
|| h
== dottga
)
5860 sec
->has_tls_reloc
= 1;
5862 && (ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSGD
5863 || ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_TLSLD
))
5864 /* We have a new-style __tls_get_addr call with
5868 /* Mark this section as having an old-style call. */
5869 sec
->has_tls_get_addr_call
= 1;
5871 plt_list
= &h
->plt
.plist
;
5874 /* We may need a .plt entry if the function this reloc
5875 refers to is in a shared lib. */
5877 && !update_plt_info (abfd
, plt_list
, rel
->r_addend
))
5881 case R_PPC64_ADDR14
:
5882 case R_PPC64_ADDR14_BRNTAKEN
:
5883 case R_PPC64_ADDR14_BRTAKEN
:
5884 case R_PPC64_ADDR24
:
5887 case R_PPC64_TPREL64
:
5888 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
5889 if (bfd_link_dll (info
))
5890 info
->flags
|= DF_STATIC_TLS
;
5893 case R_PPC64_DTPMOD64
:
5894 if (rel
+ 1 < rel_end
5895 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
5896 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5897 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
5899 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
5902 case R_PPC64_DTPREL64
:
5903 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
5905 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
5906 && rel
[-1].r_offset
== rel
->r_offset
- 8)
5907 /* This is the second reloc of a dtpmod, dtprel pair.
5908 Don't mark with TLS_DTPREL. */
5912 sec
->has_tls_reloc
= 1;
5915 struct ppc_link_hash_entry
*eh
;
5916 eh
= (struct ppc_link_hash_entry
*) h
;
5917 eh
->tls_mask
|= tls_type
;
5920 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
5921 rel
->r_addend
, tls_type
))
5924 ppc64_sec
= ppc64_elf_section_data (sec
);
5925 if (ppc64_sec
->sec_type
!= sec_toc
)
5929 /* One extra to simplify get_tls_mask. */
5930 amt
= sec
->size
* sizeof (unsigned) / 8 + sizeof (unsigned);
5931 ppc64_sec
->u
.toc
.symndx
= bfd_zalloc (abfd
, amt
);
5932 if (ppc64_sec
->u
.toc
.symndx
== NULL
)
5934 amt
= sec
->size
* sizeof (bfd_vma
) / 8;
5935 ppc64_sec
->u
.toc
.add
= bfd_zalloc (abfd
, amt
);
5936 if (ppc64_sec
->u
.toc
.add
== NULL
)
5938 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
5939 ppc64_sec
->sec_type
= sec_toc
;
5941 BFD_ASSERT (rel
->r_offset
% 8 == 0);
5942 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8] = r_symndx
;
5943 ppc64_sec
->u
.toc
.add
[rel
->r_offset
/ 8] = rel
->r_addend
;
5945 /* Mark the second slot of a GD or LD entry.
5946 -1 to indicate GD and -2 to indicate LD. */
5947 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
5948 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -1;
5949 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
5950 ppc64_sec
->u
.toc
.symndx
[rel
->r_offset
/ 8 + 1] = -2;
5953 case R_PPC64_TPREL16
:
5954 case R_PPC64_TPREL16_LO
:
5955 case R_PPC64_TPREL16_HI
:
5956 case R_PPC64_TPREL16_HA
:
5957 case R_PPC64_TPREL16_DS
:
5958 case R_PPC64_TPREL16_LO_DS
:
5959 case R_PPC64_TPREL16_HIGH
:
5960 case R_PPC64_TPREL16_HIGHA
:
5961 case R_PPC64_TPREL16_HIGHER
:
5962 case R_PPC64_TPREL16_HIGHERA
:
5963 case R_PPC64_TPREL16_HIGHEST
:
5964 case R_PPC64_TPREL16_HIGHESTA
:
5965 if (bfd_link_dll (info
))
5966 info
->flags
|= DF_STATIC_TLS
;
5969 case R_PPC64_ADDR64
:
5971 && rel
+ 1 < rel_end
5972 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
5975 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
5979 case R_PPC64_ADDR16
:
5980 case R_PPC64_ADDR16_DS
:
5981 case R_PPC64_ADDR16_HA
:
5982 case R_PPC64_ADDR16_HI
:
5983 case R_PPC64_ADDR16_HIGH
:
5984 case R_PPC64_ADDR16_HIGHA
:
5985 case R_PPC64_ADDR16_HIGHER
:
5986 case R_PPC64_ADDR16_HIGHERA
:
5987 case R_PPC64_ADDR16_HIGHEST
:
5988 case R_PPC64_ADDR16_HIGHESTA
:
5989 case R_PPC64_ADDR16_LO
:
5990 case R_PPC64_ADDR16_LO_DS
:
5991 if (h
!= NULL
&& !bfd_link_pic (info
) && abiversion (abfd
) != 1
5992 && rel
->r_addend
== 0)
5994 /* We may need a .plt entry if this reloc refers to a
5995 function in a shared lib. */
5996 if (!update_plt_info (abfd
, &h
->plt
.plist
, rel
->r_addend
))
5998 h
->pointer_equality_needed
= 1;
6005 case R_PPC64_ADDR32
:
6006 case R_PPC64_UADDR16
:
6007 case R_PPC64_UADDR32
:
6008 case R_PPC64_UADDR64
:
6010 if (h
!= NULL
&& !bfd_link_pic (info
))
6011 /* We may need a copy reloc. */
6014 /* Don't propagate .opd relocs. */
6015 if (NO_OPD_RELOCS
&& is_opd
)
6018 /* If we are creating a shared library, and this is a reloc
6019 against a global symbol, or a non PC relative reloc
6020 against a local symbol, then we need to copy the reloc
6021 into the shared library. However, if we are linking with
6022 -Bsymbolic, we do not need to copy a reloc against a
6023 global symbol which is defined in an object we are
6024 including in the link (i.e., DEF_REGULAR is set). At
6025 this point we have not seen all the input files, so it is
6026 possible that DEF_REGULAR is not set now but will be set
6027 later (it is never cleared). In case of a weak definition,
6028 DEF_REGULAR may be cleared later by a strong definition in
6029 a shared library. We account for that possibility below by
6030 storing information in the dyn_relocs field of the hash
6031 table entry. A similar situation occurs when creating
6032 shared libraries and symbol visibility changes render the
6035 If on the other hand, we are creating an executable, we
6036 may need to keep relocations for symbols satisfied by a
6037 dynamic library if we manage to avoid copy relocs for the
6040 if ((bfd_link_pic (info
)
6041 && (must_be_dyn_reloc (info
, r_type
)
6043 && (!SYMBOLIC_BIND (info
, h
)
6044 || h
->root
.type
== bfd_link_hash_defweak
6045 || !h
->def_regular
))))
6046 || (ELIMINATE_COPY_RELOCS
6047 && !bfd_link_pic (info
)
6049 && (h
->root
.type
== bfd_link_hash_defweak
6050 || !h
->def_regular
))
6051 || (!bfd_link_pic (info
)
6054 /* We must copy these reloc types into the output file.
6055 Create a reloc section in dynobj and make room for
6059 sreloc
= _bfd_elf_make_dynamic_reloc_section
6060 (sec
, htab
->elf
.dynobj
, 3, abfd
, /*rela?*/ TRUE
);
6066 /* If this is a global symbol, we count the number of
6067 relocations we need for this symbol. */
6070 struct elf_dyn_relocs
*p
;
6071 struct elf_dyn_relocs
**head
;
6073 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6075 if (p
== NULL
|| p
->sec
!= sec
)
6077 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
6087 if (!must_be_dyn_reloc (info
, r_type
))
6092 /* Track dynamic relocs needed for local syms too.
6093 We really need local syms available to do this
6095 struct ppc_dyn_relocs
*p
;
6096 struct ppc_dyn_relocs
**head
;
6097 bfd_boolean is_ifunc
;
6100 Elf_Internal_Sym
*isym
;
6102 isym
= bfd_sym_from_r_symndx (&htab
->sym_cache
,
6107 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
6111 vpp
= &elf_section_data (s
)->local_dynrel
;
6112 head
= (struct ppc_dyn_relocs
**) vpp
;
6113 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
6115 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
6117 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
6119 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
6125 p
->ifunc
= is_ifunc
;
6141 /* Merge backend specific data from an object file to the output
6142 object file when linking. */
6145 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
6147 bfd
*obfd
= info
->output_bfd
;
6148 unsigned long iflags
, oflags
;
6150 if ((ibfd
->flags
& BFD_LINKER_CREATED
) != 0)
6153 if (!is_ppc64_elf (ibfd
) || !is_ppc64_elf (obfd
))
6156 if (!_bfd_generic_verify_endian_match (ibfd
, info
))
6159 iflags
= elf_elfheader (ibfd
)->e_flags
;
6160 oflags
= elf_elfheader (obfd
)->e_flags
;
6162 if (iflags
& ~EF_PPC64_ABI
)
6165 /* xgettext:c-format */
6166 (_("%pB uses unknown e_flags 0x%lx"), ibfd
, iflags
);
6167 bfd_set_error (bfd_error_bad_value
);
6170 else if (iflags
!= oflags
&& iflags
!= 0)
6173 /* xgettext:c-format */
6174 (_("%pB: ABI version %ld is not compatible with ABI version %ld output"),
6175 ibfd
, iflags
, oflags
);
6176 bfd_set_error (bfd_error_bad_value
);
6180 _bfd_elf_ppc_merge_fp_attributes (ibfd
, info
);
6182 /* Merge Tag_compatibility attributes and any common GNU ones. */
6183 _bfd_elf_merge_object_attributes (ibfd
, info
);
6189 ppc64_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
6191 /* Print normal ELF private data. */
6192 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
6194 if (elf_elfheader (abfd
)->e_flags
!= 0)
6198 fprintf (file
, _("private flags = 0x%lx:"),
6199 elf_elfheader (abfd
)->e_flags
);
6201 if ((elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
) != 0)
6202 fprintf (file
, _(" [abiv%ld]"),
6203 elf_elfheader (abfd
)->e_flags
& EF_PPC64_ABI
);
6210 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
6211 of the code entry point, and its section, which must be in the same
6212 object as OPD_SEC. Returns (bfd_vma) -1 on error. */
6215 opd_entry_value (asection
*opd_sec
,
6217 asection
**code_sec
,
6219 bfd_boolean in_code_sec
)
6221 bfd
*opd_bfd
= opd_sec
->owner
;
6222 Elf_Internal_Rela
*relocs
;
6223 Elf_Internal_Rela
*lo
, *hi
, *look
;
6226 /* No relocs implies we are linking a --just-symbols object, or looking
6227 at a final linked executable with addr2line or somesuch. */
6228 if (opd_sec
->reloc_count
== 0)
6230 bfd_byte
*contents
= ppc64_elf_tdata (opd_bfd
)->opd
.contents
;
6232 if (contents
== NULL
)
6234 if (!bfd_malloc_and_get_section (opd_bfd
, opd_sec
, &contents
))
6235 return (bfd_vma
) -1;
6236 ppc64_elf_tdata (opd_bfd
)->opd
.contents
= contents
;
6239 /* PR 17512: file: 64b9dfbb. */
6240 if (offset
+ 7 >= opd_sec
->size
|| offset
+ 7 < offset
)
6241 return (bfd_vma
) -1;
6243 val
= bfd_get_64 (opd_bfd
, contents
+ offset
);
6244 if (code_sec
!= NULL
)
6246 asection
*sec
, *likely
= NULL
;
6252 && val
< sec
->vma
+ sec
->size
)
6258 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6260 && (sec
->flags
& SEC_LOAD
) != 0
6261 && (sec
->flags
& SEC_ALLOC
) != 0)
6266 if (code_off
!= NULL
)
6267 *code_off
= val
- likely
->vma
;
6273 BFD_ASSERT (is_ppc64_elf (opd_bfd
));
6275 relocs
= ppc64_elf_tdata (opd_bfd
)->opd
.relocs
;
6277 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
6278 /* PR 17512: file: df8e1fd6. */
6280 return (bfd_vma
) -1;
6282 /* Go find the opd reloc at the sym address. */
6284 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
6288 look
= lo
+ (hi
- lo
) / 2;
6289 if (look
->r_offset
< offset
)
6291 else if (look
->r_offset
> offset
)
6295 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (opd_bfd
);
6297 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
6298 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
6300 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
6301 asection
*sec
= NULL
;
6303 if (symndx
>= symtab_hdr
->sh_info
6304 && elf_sym_hashes (opd_bfd
) != NULL
)
6306 struct elf_link_hash_entry
**sym_hashes
;
6307 struct elf_link_hash_entry
*rh
;
6309 sym_hashes
= elf_sym_hashes (opd_bfd
);
6310 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
6313 rh
= elf_follow_link (rh
);
6314 if (rh
->root
.type
!= bfd_link_hash_defined
6315 && rh
->root
.type
!= bfd_link_hash_defweak
)
6317 if (rh
->root
.u
.def
.section
->owner
== opd_bfd
)
6319 val
= rh
->root
.u
.def
.value
;
6320 sec
= rh
->root
.u
.def
.section
;
6327 Elf_Internal_Sym
*sym
;
6329 if (symndx
< symtab_hdr
->sh_info
)
6331 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6334 size_t symcnt
= symtab_hdr
->sh_info
;
6335 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6340 symtab_hdr
->contents
= (bfd_byte
*) sym
;
6346 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
6352 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
6355 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
6356 val
= sym
->st_value
;
6359 val
+= look
->r_addend
;
6360 if (code_off
!= NULL
)
6362 if (code_sec
!= NULL
)
6364 if (in_code_sec
&& *code_sec
!= sec
)
6369 if (sec
->output_section
!= NULL
)
6370 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
6379 /* If the ELF symbol SYM might be a function in SEC, return the
6380 function size and set *CODE_OFF to the function's entry point,
6381 otherwise return zero. */
6383 static bfd_size_type
6384 ppc64_elf_maybe_function_sym (const asymbol
*sym
, asection
*sec
,
6389 if ((sym
->flags
& (BSF_SECTION_SYM
| BSF_FILE
| BSF_OBJECT
6390 | BSF_THREAD_LOCAL
| BSF_RELC
| BSF_SRELC
)) != 0)
6394 if (!(sym
->flags
& BSF_SYNTHETIC
))
6395 size
= ((elf_symbol_type
*) sym
)->internal_elf_sym
.st_size
;
6397 if (strcmp (sym
->section
->name
, ".opd") == 0)
6399 struct _opd_sec_data
*opd
= get_opd_info (sym
->section
);
6400 bfd_vma symval
= sym
->value
;
6403 && opd
->adjust
!= NULL
6404 && elf_section_data (sym
->section
)->relocs
!= NULL
)
6406 /* opd_entry_value will use cached relocs that have been
6407 adjusted, but with raw symbols. That means both local
6408 and global symbols need adjusting. */
6409 long adjust
= opd
->adjust
[OPD_NDX (symval
)];
6415 if (opd_entry_value (sym
->section
, symval
,
6416 &sec
, code_off
, TRUE
) == (bfd_vma
) -1)
6418 /* An old ABI binary with dot-syms has a size of 24 on the .opd
6419 symbol. This size has nothing to do with the code size of the
6420 function, which is what we're supposed to return, but the
6421 code size isn't available without looking up the dot-sym.
6422 However, doing that would be a waste of time particularly
6423 since elf_find_function will look at the dot-sym anyway.
6424 Now, elf_find_function will keep the largest size of any
6425 function sym found at the code address of interest, so return
6426 1 here to avoid it incorrectly caching a larger function size
6427 for a small function. This does mean we return the wrong
6428 size for a new-ABI function of size 24, but all that does is
6429 disable caching for such functions. */
6435 if (sym
->section
!= sec
)
6437 *code_off
= sym
->value
;
6444 /* Return true if symbol is a strong function defined in an ELFv2
6445 object with st_other localentry bits of zero, ie. its local entry
6446 point coincides with its global entry point. */
6449 is_elfv2_localentry0 (struct elf_link_hash_entry
*h
)
6452 && h
->type
== STT_FUNC
6453 && h
->root
.type
== bfd_link_hash_defined
6454 && (STO_PPC64_LOCAL_MASK
& h
->other
) == 0
6455 && !((struct ppc_link_hash_entry
*) h
)->non_zero_localentry
6456 && is_ppc64_elf (h
->root
.u
.def
.section
->owner
)
6457 && abiversion (h
->root
.u
.def
.section
->owner
) >= 2);
6460 /* Return true if symbol is defined in a regular object file. */
6463 is_static_defined (struct elf_link_hash_entry
*h
)
6465 return ((h
->root
.type
== bfd_link_hash_defined
6466 || h
->root
.type
== bfd_link_hash_defweak
)
6467 && h
->root
.u
.def
.section
!= NULL
6468 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6471 /* If FDH is a function descriptor symbol, return the associated code
6472 entry symbol if it is defined. Return NULL otherwise. */
6474 static struct ppc_link_hash_entry
*
6475 defined_code_entry (struct ppc_link_hash_entry
*fdh
)
6477 if (fdh
->is_func_descriptor
)
6479 struct ppc_link_hash_entry
*fh
= ppc_follow_link (fdh
->oh
);
6480 if (fh
->elf
.root
.type
== bfd_link_hash_defined
6481 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
6487 /* If FH is a function code entry symbol, return the associated
6488 function descriptor symbol if it is defined. Return NULL otherwise. */
6490 static struct ppc_link_hash_entry
*
6491 defined_func_desc (struct ppc_link_hash_entry
*fh
)
6494 && fh
->oh
->is_func_descriptor
)
6496 struct ppc_link_hash_entry
*fdh
= ppc_follow_link (fh
->oh
);
6497 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
6498 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
6504 static bfd_boolean
func_desc_adjust (struct elf_link_hash_entry
*, void *);
6506 /* Garbage collect sections, after first dealing with dot-symbols. */
6509 ppc64_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6511 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6513 if (htab
!= NULL
&& htab
->need_func_desc_adj
)
6515 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
6516 htab
->need_func_desc_adj
= 0;
6518 return bfd_elf_gc_sections (abfd
, info
);
6521 /* Mark all our entry sym sections, both opd and code section. */
6524 ppc64_elf_gc_keep (struct bfd_link_info
*info
)
6526 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6527 struct bfd_sym_chain
*sym
;
6532 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
6534 struct ppc_link_hash_entry
*eh
, *fh
;
6537 eh
= (struct ppc_link_hash_entry
*)
6538 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, TRUE
);
6541 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
6542 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6545 fh
= defined_code_entry (eh
);
6548 sec
= fh
->elf
.root
.u
.def
.section
;
6549 sec
->flags
|= SEC_KEEP
;
6551 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6552 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6553 eh
->elf
.root
.u
.def
.value
,
6554 &sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6555 sec
->flags
|= SEC_KEEP
;
6557 sec
= eh
->elf
.root
.u
.def
.section
;
6558 sec
->flags
|= SEC_KEEP
;
6562 /* Mark sections containing dynamically referenced symbols. When
6563 building shared libraries, we must assume that any visible symbol is
6567 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
6569 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
6570 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
6571 struct ppc_link_hash_entry
*fdh
;
6572 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
6574 /* Dynamic linking info is on the func descriptor sym. */
6575 fdh
= defined_func_desc (eh
);
6579 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
6580 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
6581 && ((eh
->elf
.ref_dynamic
&& !eh
->elf
.forced_local
)
6582 || ((eh
->elf
.def_regular
|| ELF_COMMON_DEF_P (&eh
->elf
))
6583 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
6584 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
6585 && (!bfd_link_executable (info
)
6586 || info
->gc_keep_exported
6587 || info
->export_dynamic
6590 && (*d
->match
) (&d
->head
, NULL
, eh
->elf
.root
.root
.string
)))
6591 && (eh
->elf
.versioned
>= versioned
6592 || !bfd_hide_sym_by_version (info
->version_info
,
6593 eh
->elf
.root
.root
.string
)))))
6596 struct ppc_link_hash_entry
*fh
;
6598 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
6600 /* Function descriptor syms cause the associated
6601 function code sym section to be marked. */
6602 fh
= defined_code_entry (eh
);
6605 code_sec
= fh
->elf
.root
.u
.def
.section
;
6606 code_sec
->flags
|= SEC_KEEP
;
6608 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6609 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6610 eh
->elf
.root
.u
.def
.value
,
6611 &code_sec
, NULL
, FALSE
) != (bfd_vma
) -1)
6612 code_sec
->flags
|= SEC_KEEP
;
6618 /* Return the section that should be marked against GC for a given
6622 ppc64_elf_gc_mark_hook (asection
*sec
,
6623 struct bfd_link_info
*info
,
6624 Elf_Internal_Rela
*rel
,
6625 struct elf_link_hash_entry
*h
,
6626 Elf_Internal_Sym
*sym
)
6630 /* Syms return NULL if we're marking .opd, so we avoid marking all
6631 function sections, as all functions are referenced in .opd. */
6633 if (get_opd_info (sec
) != NULL
)
6638 enum elf_ppc64_reloc_type r_type
;
6639 struct ppc_link_hash_entry
*eh
, *fh
, *fdh
;
6641 r_type
= ELF64_R_TYPE (rel
->r_info
);
6644 case R_PPC64_GNU_VTINHERIT
:
6645 case R_PPC64_GNU_VTENTRY
:
6649 switch (h
->root
.type
)
6651 case bfd_link_hash_defined
:
6652 case bfd_link_hash_defweak
:
6653 eh
= (struct ppc_link_hash_entry
*) h
;
6654 fdh
= defined_func_desc (eh
);
6657 /* -mcall-aixdesc code references the dot-symbol on
6658 a call reloc. Mark the function descriptor too
6659 against garbage collection. */
6661 if (fdh
->elf
.is_weakalias
)
6662 weakdef (&fdh
->elf
)->mark
= 1;
6666 /* Function descriptor syms cause the associated
6667 function code sym section to be marked. */
6668 fh
= defined_code_entry (eh
);
6671 /* They also mark their opd section. */
6672 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6674 rsec
= fh
->elf
.root
.u
.def
.section
;
6676 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
6677 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
6678 eh
->elf
.root
.u
.def
.value
,
6679 &rsec
, NULL
, FALSE
) != (bfd_vma
) -1)
6680 eh
->elf
.root
.u
.def
.section
->gc_mark
= 1;
6682 rsec
= h
->root
.u
.def
.section
;
6685 case bfd_link_hash_common
:
6686 rsec
= h
->root
.u
.c
.p
->section
;
6690 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
6696 struct _opd_sec_data
*opd
;
6698 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
6699 opd
= get_opd_info (rsec
);
6700 if (opd
!= NULL
&& opd
->func_sec
!= NULL
)
6704 rsec
= opd
->func_sec
[OPD_NDX (sym
->st_value
+ rel
->r_addend
)];
6711 /* The maximum size of .sfpr. */
6712 #define SFPR_MAX (218*4)
6714 struct sfpr_def_parms
6716 const char name
[12];
6717 unsigned char lo
, hi
;
6718 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
6719 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
6722 /* Auto-generate _save*, _rest* functions in .sfpr.
6723 If STUB_SEC is non-null, define alias symbols in STUB_SEC
6727 sfpr_define (struct bfd_link_info
*info
,
6728 const struct sfpr_def_parms
*parm
,
6731 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6733 size_t len
= strlen (parm
->name
);
6734 bfd_boolean writing
= FALSE
;
6740 memcpy (sym
, parm
->name
, len
);
6743 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
6745 struct ppc_link_hash_entry
*h
;
6747 sym
[len
+ 0] = i
/ 10 + '0';
6748 sym
[len
+ 1] = i
% 10 + '0';
6749 h
= (struct ppc_link_hash_entry
*)
6750 elf_link_hash_lookup (&htab
->elf
, sym
, writing
, TRUE
, TRUE
);
6751 if (stub_sec
!= NULL
)
6754 && h
->elf
.root
.type
== bfd_link_hash_defined
6755 && h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
6757 struct elf_link_hash_entry
*s
;
6759 sprintf (buf
, "%08x.%s", stub_sec
->id
& 0xffffffff, sym
);
6760 s
= elf_link_hash_lookup (&htab
->elf
, buf
, TRUE
, TRUE
, FALSE
);
6763 if (s
->root
.type
== bfd_link_hash_new
6764 || (s
->root
.type
= bfd_link_hash_defined
6765 && s
->root
.u
.def
.section
== stub_sec
))
6767 s
->root
.type
= bfd_link_hash_defined
;
6768 s
->root
.u
.def
.section
= stub_sec
;
6769 s
->root
.u
.def
.value
= (stub_sec
->size
- htab
->sfpr
->size
6770 + h
->elf
.root
.u
.def
.value
);
6773 s
->ref_regular_nonweak
= 1;
6774 s
->forced_local
= 1;
6776 s
->root
.linker_def
= 1;
6784 if (!h
->elf
.def_regular
)
6786 h
->elf
.root
.type
= bfd_link_hash_defined
;
6787 h
->elf
.root
.u
.def
.section
= htab
->sfpr
;
6788 h
->elf
.root
.u
.def
.value
= htab
->sfpr
->size
;
6789 h
->elf
.type
= STT_FUNC
;
6790 h
->elf
.def_regular
= 1;
6792 _bfd_elf_link_hash_hide_symbol (info
, &h
->elf
, TRUE
);
6794 if (htab
->sfpr
->contents
== NULL
)
6796 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
6797 if (htab
->sfpr
->contents
== NULL
)
6804 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
6806 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
6808 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
6809 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
6817 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6819 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6824 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6826 p
= savegpr0 (abfd
, p
, r
);
6827 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6829 bfd_put_32 (abfd
, BLR
, p
);
6834 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
6836 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6841 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6843 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6845 p
= restgpr0 (abfd
, p
, r
);
6846 bfd_put_32 (abfd
, MTLR_R0
, p
);
6850 p
= restgpr0 (abfd
, p
, 30);
6851 p
= restgpr0 (abfd
, p
, 31);
6853 bfd_put_32 (abfd
, BLR
, p
);
6858 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6860 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6865 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6867 p
= savegpr1 (abfd
, p
, r
);
6868 bfd_put_32 (abfd
, BLR
, p
);
6873 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
6875 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6880 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6882 p
= restgpr1 (abfd
, p
, r
);
6883 bfd_put_32 (abfd
, BLR
, p
);
6888 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6890 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6895 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6897 p
= savefpr (abfd
, p
, r
);
6898 bfd_put_32 (abfd
, STD_R0_0R1
+ STK_LR
, p
);
6900 bfd_put_32 (abfd
, BLR
, p
);
6905 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
6907 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
6912 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6914 bfd_put_32 (abfd
, LD_R0_0R1
+ STK_LR
, p
);
6916 p
= restfpr (abfd
, p
, r
);
6917 bfd_put_32 (abfd
, MTLR_R0
, p
);
6921 p
= restfpr (abfd
, p
, 30);
6922 p
= restfpr (abfd
, p
, 31);
6924 bfd_put_32 (abfd
, BLR
, p
);
6929 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6931 p
= savefpr (abfd
, p
, r
);
6932 bfd_put_32 (abfd
, BLR
, p
);
6937 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6939 p
= restfpr (abfd
, p
, r
);
6940 bfd_put_32 (abfd
, BLR
, p
);
6945 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
6947 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6949 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
6954 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6956 p
= savevr (abfd
, p
, r
);
6957 bfd_put_32 (abfd
, BLR
, p
);
6962 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
6964 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
6966 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
6971 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
6973 p
= restvr (abfd
, p
, r
);
6974 bfd_put_32 (abfd
, BLR
, p
);
6978 /* Called via elf_link_hash_traverse to transfer dynamic linking
6979 information on function code symbol entries to their corresponding
6980 function descriptor symbol entries. */
6983 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
6985 struct bfd_link_info
*info
;
6986 struct ppc_link_hash_table
*htab
;
6987 struct ppc_link_hash_entry
*fh
;
6988 struct ppc_link_hash_entry
*fdh
;
6989 bfd_boolean force_local
;
6991 fh
= (struct ppc_link_hash_entry
*) h
;
6992 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
6998 if (fh
->elf
.root
.root
.string
[0] != '.'
6999 || fh
->elf
.root
.root
.string
[1] == '\0')
7003 htab
= ppc_hash_table (info
);
7007 /* Find the corresponding function descriptor symbol. */
7008 fdh
= lookup_fdh (fh
, htab
);
7010 /* Resolve undefined references to dot-symbols as the value
7011 in the function descriptor, if we have one in a regular object.
7012 This is to satisfy cases like ".quad .foo". Calls to functions
7013 in dynamic objects are handled elsewhere. */
7014 if ((fh
->elf
.root
.type
== bfd_link_hash_undefined
7015 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
7016 && (fdh
->elf
.root
.type
== bfd_link_hash_defined
7017 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
7018 && get_opd_info (fdh
->elf
.root
.u
.def
.section
) != NULL
7019 && opd_entry_value (fdh
->elf
.root
.u
.def
.section
,
7020 fdh
->elf
.root
.u
.def
.value
,
7021 &fh
->elf
.root
.u
.def
.section
,
7022 &fh
->elf
.root
.u
.def
.value
, FALSE
) != (bfd_vma
) -1)
7024 fh
->elf
.root
.type
= fdh
->elf
.root
.type
;
7025 fh
->elf
.forced_local
= 1;
7026 fh
->elf
.def_regular
= fdh
->elf
.def_regular
;
7027 fh
->elf
.def_dynamic
= fdh
->elf
.def_dynamic
;
7030 if (!fh
->elf
.dynamic
)
7032 struct plt_entry
*ent
;
7034 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7035 if (ent
->plt
.refcount
> 0)
7041 /* Create a descriptor as undefined if necessary. */
7043 && !bfd_link_executable (info
)
7044 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
7045 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
7047 fdh
= make_fdh (info
, fh
);
7052 /* We can't support overriding of symbols on a fake descriptor. */
7055 && (fh
->elf
.root
.type
== bfd_link_hash_defined
7056 || fh
->elf
.root
.type
== bfd_link_hash_defweak
))
7057 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
7059 /* Transfer dynamic linking information to the function descriptor. */
7062 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
7063 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
7064 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
7065 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
7066 fdh
->elf
.dynamic
|= fh
->elf
.dynamic
;
7067 fdh
->elf
.needs_plt
|= (fh
->elf
.needs_plt
7068 || fh
->elf
.type
== STT_FUNC
7069 || fh
->elf
.type
== STT_GNU_IFUNC
);
7070 move_plt_plist (fh
, fdh
);
7072 if (!fdh
->elf
.forced_local
7073 && fh
->elf
.dynindx
!= -1)
7074 if (!bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
7078 /* Now that the info is on the function descriptor, clear the
7079 function code sym info. Any function code syms for which we
7080 don't have a definition in a regular file, we force local.
7081 This prevents a shared library from exporting syms that have
7082 been imported from another library. Function code syms that
7083 are really in the library we must leave global to prevent the
7084 linker dragging in a definition from a static library. */
7085 force_local
= (!fh
->elf
.def_regular
7087 || !fdh
->elf
.def_regular
7088 || fdh
->elf
.forced_local
);
7089 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7094 static const struct sfpr_def_parms save_res_funcs
[] =
7096 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
7097 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
7098 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
7099 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
7100 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
7101 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
7102 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
7103 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
7104 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
7105 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
7106 { "_savevr_", 20, 31, savevr
, savevr_tail
},
7107 { "_restvr_", 20, 31, restvr
, restvr_tail
}
7110 /* Called near the start of bfd_elf_size_dynamic_sections. We use
7111 this hook to a) provide some gcc support functions, and b) transfer
7112 dynamic linking information gathered so far on function code symbol
7113 entries, to their corresponding function descriptor symbol entries. */
7116 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
7117 struct bfd_link_info
*info
)
7119 struct ppc_link_hash_table
*htab
;
7121 htab
= ppc_hash_table (info
);
7125 /* Provide any missing _save* and _rest* functions. */
7126 if (htab
->sfpr
!= NULL
)
7130 htab
->sfpr
->size
= 0;
7131 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
7132 if (!sfpr_define (info
, &save_res_funcs
[i
], NULL
))
7134 if (htab
->sfpr
->size
== 0)
7135 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
7138 if (bfd_link_relocatable (info
))
7141 if (htab
->elf
.hgot
!= NULL
)
7143 _bfd_elf_link_hash_hide_symbol (info
, htab
->elf
.hgot
, TRUE
);
7144 /* Make .TOC. defined so as to prevent it being made dynamic.
7145 The wrong value here is fixed later in ppc64_elf_set_toc. */
7146 if (!htab
->elf
.hgot
->def_regular
7147 || htab
->elf
.hgot
->root
.type
!= bfd_link_hash_defined
)
7149 htab
->elf
.hgot
->root
.type
= bfd_link_hash_defined
;
7150 htab
->elf
.hgot
->root
.u
.def
.value
= 0;
7151 htab
->elf
.hgot
->root
.u
.def
.section
= bfd_abs_section_ptr
;
7152 htab
->elf
.hgot
->def_regular
= 1;
7153 htab
->elf
.hgot
->root
.linker_def
= 1;
7155 htab
->elf
.hgot
->type
= STT_OBJECT
;
7156 htab
->elf
.hgot
->other
= ((htab
->elf
.hgot
->other
& ~ELF_ST_VISIBILITY (-1))
7160 if (htab
->need_func_desc_adj
)
7162 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
7163 htab
->need_func_desc_adj
= 0;
7169 /* Find dynamic relocs for H that apply to read-only sections. */
7172 readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7174 struct ppc_link_hash_entry
*eh
;
7175 struct elf_dyn_relocs
*p
;
7177 eh
= (struct ppc_link_hash_entry
*) h
;
7178 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7180 asection
*s
= p
->sec
->output_section
;
7182 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7188 /* Return true if we have dynamic relocs against H or any of its weak
7189 aliases, that apply to read-only sections. Cannot be used after
7190 size_dynamic_sections. */
7193 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
7195 struct ppc_link_hash_entry
*eh
;
7197 eh
= (struct ppc_link_hash_entry
*) h
;
7200 if (readonly_dynrelocs (&eh
->elf
))
7202 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.u
.alias
;
7203 } while (eh
!= NULL
&& &eh
->elf
!= h
);
7208 /* Return whether EH has pc-relative dynamic relocs. */
7211 pc_dynrelocs (struct ppc_link_hash_entry
*eh
)
7213 struct elf_dyn_relocs
*p
;
7215 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7216 if (p
->pc_count
!= 0)
7221 /* Return true if a global entry stub will be created for H. Valid
7222 for ELFv2 before plt entries have been allocated. */
7225 global_entry_stub (struct elf_link_hash_entry
*h
)
7227 struct plt_entry
*pent
;
7229 if (!h
->pointer_equality_needed
7233 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7234 if (pent
->plt
.refcount
> 0
7235 && pent
->addend
== 0)
7241 /* Adjust a symbol defined by a dynamic object and referenced by a
7242 regular object. The current definition is in some section of the
7243 dynamic object, but we're not including those sections. We have to
7244 change the definition to something the rest of the link can
7248 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
7249 struct elf_link_hash_entry
*h
)
7251 struct ppc_link_hash_table
*htab
;
7254 htab
= ppc_hash_table (info
);
7258 /* Deal with function syms. */
7259 if (h
->type
== STT_FUNC
7260 || h
->type
== STT_GNU_IFUNC
7263 bfd_boolean local
= (((struct ppc_link_hash_entry
*) h
)->save_res
7264 || SYMBOL_CALLS_LOCAL (info
, h
)
7265 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
7266 /* Discard dyn_relocs when non-pic if we've decided that a
7267 function symbol is local and not an ifunc. We keep dynamic
7268 relocs for ifuncs when local rather than always emitting a
7269 plt call stub for them and defining the symbol on the call
7270 stub. We can't do that for ELFv1 anyway (a function symbol
7271 is defined on a descriptor, not code) and it can be faster at
7272 run-time due to not needing to bounce through a stub. The
7273 dyn_relocs for ifuncs will be applied even in a static
7275 if (!bfd_link_pic (info
)
7276 && h
->type
!= STT_GNU_IFUNC
7278 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7280 /* Clear procedure linkage table information for any symbol that
7281 won't need a .plt entry. */
7282 struct plt_entry
*ent
;
7283 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
7284 if (ent
->plt
.refcount
> 0)
7287 || (h
->type
!= STT_GNU_IFUNC
7289 && (htab
->can_convert_all_inline_plt
7290 || (((struct ppc_link_hash_entry
*) h
)->tls_mask
7291 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
7293 h
->plt
.plist
= NULL
;
7295 h
->pointer_equality_needed
= 0;
7297 else if (abiversion (info
->output_bfd
) >= 2)
7299 /* Taking a function's address in a read/write section
7300 doesn't require us to define the function symbol in the
7301 executable on a global entry stub. A dynamic reloc can
7302 be used instead. The reason we prefer a few more dynamic
7303 relocs is that calling via a global entry stub costs a
7304 few more instructions, and pointer_equality_needed causes
7305 extra work in ld.so when resolving these symbols. */
7306 if (global_entry_stub (h
))
7308 if (!readonly_dynrelocs (h
))
7310 h
->pointer_equality_needed
= 0;
7311 /* If we haven't seen a branch reloc and the symbol
7312 isn't an ifunc then we don't need a plt entry. */
7314 h
->plt
.plist
= NULL
;
7316 else if (!bfd_link_pic (info
))
7317 /* We are going to be defining the function symbol on the
7318 plt stub, so no dyn_relocs needed when non-pic. */
7319 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7322 /* ELFv2 function symbols can't have copy relocs. */
7325 else if (!h
->needs_plt
7326 && !readonly_dynrelocs (h
))
7328 /* If we haven't seen a branch reloc and the symbol isn't an
7329 ifunc then we don't need a plt entry. */
7330 h
->plt
.plist
= NULL
;
7331 h
->pointer_equality_needed
= 0;
7336 h
->plt
.plist
= NULL
;
7338 /* If this is a weak symbol, and there is a real definition, the
7339 processor independent code will have arranged for us to see the
7340 real definition first, and we can just use the same value. */
7341 if (h
->is_weakalias
)
7343 struct elf_link_hash_entry
*def
= weakdef (h
);
7344 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
7345 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
7346 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
7347 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
7348 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
7349 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7353 /* If we are creating a shared library, we must presume that the
7354 only references to the symbol are via the global offset table.
7355 For such cases we need not do anything here; the relocations will
7356 be handled correctly by relocate_section. */
7357 if (bfd_link_pic (info
))
7360 /* If there are no references to this symbol that do not use the
7361 GOT, we don't need to generate a copy reloc. */
7362 if (!h
->non_got_ref
)
7365 /* Don't generate a copy reloc for symbols defined in the executable. */
7366 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
7368 /* If -z nocopyreloc was given, don't generate them either. */
7369 || info
->nocopyreloc
7371 /* If we don't find any dynamic relocs in read-only sections, then
7372 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
7373 || (ELIMINATE_COPY_RELOCS
&& !alias_readonly_dynrelocs (h
))
7375 /* Protected variables do not work with .dynbss. The copy in
7376 .dynbss won't be used by the shared library with the protected
7377 definition for the variable. Text relocations are preferable
7378 to an incorrect program. */
7379 || h
->protected_def
)
7382 if (h
->plt
.plist
!= NULL
)
7384 /* We should never get here, but unfortunately there are versions
7385 of gcc out there that improperly (for this ABI) put initialized
7386 function pointers, vtable refs and suchlike in read-only
7387 sections. Allow them to proceed, but warn that this might
7388 break at runtime. */
7389 info
->callbacks
->einfo
7390 (_("%P: copy reloc against `%pT' requires lazy plt linking; "
7391 "avoid setting LD_BIND_NOW=1 or upgrade gcc\n"),
7392 h
->root
.root
.string
);
7395 /* This is a reference to a symbol defined by a dynamic object which
7396 is not a function. */
7398 /* We must allocate the symbol in our .dynbss section, which will
7399 become part of the .bss section of the executable. There will be
7400 an entry for this symbol in the .dynsym section. The dynamic
7401 object will contain position independent code, so all references
7402 from the dynamic object to this symbol will go through the global
7403 offset table. The dynamic linker will use the .dynsym entry to
7404 determine the address it must put in the global offset table, so
7405 both the dynamic object and the regular object will refer to the
7406 same memory location for the variable. */
7407 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
7409 s
= htab
->elf
.sdynrelro
;
7410 srel
= htab
->elf
.sreldynrelro
;
7414 s
= htab
->elf
.sdynbss
;
7415 srel
= htab
->elf
.srelbss
;
7417 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
7419 /* We must generate a R_PPC64_COPY reloc to tell the dynamic
7420 linker to copy the initial value out of the dynamic object
7421 and into the runtime process image. */
7422 srel
->size
+= sizeof (Elf64_External_Rela
);
7426 /* We no longer want dyn_relocs. */
7427 ((struct ppc_link_hash_entry
*) h
)->dyn_relocs
= NULL
;
7428 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
7431 /* If given a function descriptor symbol, hide both the function code
7432 sym and the descriptor. */
7434 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
7435 struct elf_link_hash_entry
*h
,
7436 bfd_boolean force_local
)
7438 struct ppc_link_hash_entry
*eh
;
7439 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
7441 eh
= (struct ppc_link_hash_entry
*) h
;
7442 if (eh
->is_func_descriptor
)
7444 struct ppc_link_hash_entry
*fh
= eh
->oh
;
7449 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
7452 /* We aren't supposed to use alloca in BFD because on
7453 systems which do not have alloca the version in libiberty
7454 calls xmalloc, which might cause the program to crash
7455 when it runs out of memory. This function doesn't have a
7456 return status, so there's no way to gracefully return an
7457 error. So cheat. We know that string[-1] can be safely
7458 accessed; It's either a string in an ELF string table,
7459 or allocated in an objalloc structure. */
7461 p
= eh
->elf
.root
.root
.string
- 1;
7464 fh
= (struct ppc_link_hash_entry
*)
7465 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7468 /* Unfortunately, if it so happens that the string we were
7469 looking for was allocated immediately before this string,
7470 then we overwrote the string terminator. That's the only
7471 reason the lookup should fail. */
7474 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
7475 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
7477 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
7478 fh
= (struct ppc_link_hash_entry
*)
7479 elf_link_hash_lookup (htab
, p
, FALSE
, FALSE
, FALSE
);
7488 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
7493 get_sym_h (struct elf_link_hash_entry
**hp
,
7494 Elf_Internal_Sym
**symp
,
7496 unsigned char **tls_maskp
,
7497 Elf_Internal_Sym
**locsymsp
,
7498 unsigned long r_symndx
,
7501 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
7503 if (r_symndx
>= symtab_hdr
->sh_info
)
7505 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
7506 struct elf_link_hash_entry
*h
;
7508 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
7509 h
= elf_follow_link (h
);
7517 if (symsecp
!= NULL
)
7519 asection
*symsec
= NULL
;
7520 if (h
->root
.type
== bfd_link_hash_defined
7521 || h
->root
.type
== bfd_link_hash_defweak
)
7522 symsec
= h
->root
.u
.def
.section
;
7526 if (tls_maskp
!= NULL
)
7528 struct ppc_link_hash_entry
*eh
;
7530 eh
= (struct ppc_link_hash_entry
*) h
;
7531 *tls_maskp
= &eh
->tls_mask
;
7536 Elf_Internal_Sym
*sym
;
7537 Elf_Internal_Sym
*locsyms
= *locsymsp
;
7539 if (locsyms
== NULL
)
7541 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7542 if (locsyms
== NULL
)
7543 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
7544 symtab_hdr
->sh_info
,
7545 0, NULL
, NULL
, NULL
);
7546 if (locsyms
== NULL
)
7548 *locsymsp
= locsyms
;
7550 sym
= locsyms
+ r_symndx
;
7558 if (symsecp
!= NULL
)
7559 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
7561 if (tls_maskp
!= NULL
)
7563 struct got_entry
**lgot_ents
;
7564 unsigned char *tls_mask
;
7567 lgot_ents
= elf_local_got_ents (ibfd
);
7568 if (lgot_ents
!= NULL
)
7570 struct plt_entry
**local_plt
= (struct plt_entry
**)
7571 (lgot_ents
+ symtab_hdr
->sh_info
);
7572 unsigned char *lgot_masks
= (unsigned char *)
7573 (local_plt
+ symtab_hdr
->sh_info
);
7574 tls_mask
= &lgot_masks
[r_symndx
];
7576 *tls_maskp
= tls_mask
;
7582 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
7583 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
7584 type suitable for optimization, and 1 otherwise. */
7587 get_tls_mask (unsigned char **tls_maskp
,
7588 unsigned long *toc_symndx
,
7589 bfd_vma
*toc_addend
,
7590 Elf_Internal_Sym
**locsymsp
,
7591 const Elf_Internal_Rela
*rel
,
7594 unsigned long r_symndx
;
7596 struct elf_link_hash_entry
*h
;
7597 Elf_Internal_Sym
*sym
;
7601 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7602 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7605 if ((*tls_maskp
!= NULL
7606 && (**tls_maskp
& TLS_TLS
) != 0
7607 && **tls_maskp
!= (TLS_TLS
| TLS_MARK
))
7609 || ppc64_elf_section_data (sec
) == NULL
7610 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
7613 /* Look inside a TOC section too. */
7616 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
7617 off
= h
->root
.u
.def
.value
;
7620 off
= sym
->st_value
;
7621 off
+= rel
->r_addend
;
7622 BFD_ASSERT (off
% 8 == 0);
7623 r_symndx
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8];
7624 next_r
= ppc64_elf_section_data (sec
)->u
.toc
.symndx
[off
/ 8 + 1];
7625 if (toc_symndx
!= NULL
)
7626 *toc_symndx
= r_symndx
;
7627 if (toc_addend
!= NULL
)
7628 *toc_addend
= ppc64_elf_section_data (sec
)->u
.toc
.add
[off
/ 8];
7629 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
7631 if ((h
== NULL
|| is_static_defined (h
))
7632 && (next_r
== -1 || next_r
== -2))
7637 /* Find (or create) an entry in the tocsave hash table. */
7639 static struct tocsave_entry
*
7640 tocsave_find (struct ppc_link_hash_table
*htab
,
7641 enum insert_option insert
,
7642 Elf_Internal_Sym
**local_syms
,
7643 const Elf_Internal_Rela
*irela
,
7646 unsigned long r_indx
;
7647 struct elf_link_hash_entry
*h
;
7648 Elf_Internal_Sym
*sym
;
7649 struct tocsave_entry ent
, *p
;
7651 struct tocsave_entry
**slot
;
7653 r_indx
= ELF64_R_SYM (irela
->r_info
);
7654 if (!get_sym_h (&h
, &sym
, &ent
.sec
, NULL
, local_syms
, r_indx
, ibfd
))
7656 if (ent
.sec
== NULL
|| ent
.sec
->output_section
== NULL
)
7659 (_("%pB: undefined symbol on R_PPC64_TOCSAVE relocation"), ibfd
);
7664 ent
.offset
= h
->root
.u
.def
.value
;
7666 ent
.offset
= sym
->st_value
;
7667 ent
.offset
+= irela
->r_addend
;
7669 hash
= tocsave_htab_hash (&ent
);
7670 slot
= ((struct tocsave_entry
**)
7671 htab_find_slot_with_hash (htab
->tocsave_htab
, &ent
, hash
, insert
));
7677 p
= (struct tocsave_entry
*) bfd_alloc (ibfd
, sizeof (*p
));
7686 /* Adjust all global syms defined in opd sections. In gcc generated
7687 code for the old ABI, these will already have been done. */
7690 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
7692 struct ppc_link_hash_entry
*eh
;
7694 struct _opd_sec_data
*opd
;
7696 if (h
->root
.type
== bfd_link_hash_indirect
)
7699 if (h
->root
.type
!= bfd_link_hash_defined
7700 && h
->root
.type
!= bfd_link_hash_defweak
)
7703 eh
= (struct ppc_link_hash_entry
*) h
;
7704 if (eh
->adjust_done
)
7707 sym_sec
= eh
->elf
.root
.u
.def
.section
;
7708 opd
= get_opd_info (sym_sec
);
7709 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
7711 long adjust
= opd
->adjust
[OPD_NDX (eh
->elf
.root
.u
.def
.value
)];
7714 /* This entry has been deleted. */
7715 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
7718 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
7719 if (discarded_section (dsec
))
7721 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
7725 eh
->elf
.root
.u
.def
.value
= 0;
7726 eh
->elf
.root
.u
.def
.section
= dsec
;
7729 eh
->elf
.root
.u
.def
.value
+= adjust
;
7730 eh
->adjust_done
= 1;
7735 /* Handles decrementing dynamic reloc counts for the reloc specified by
7736 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM
7737 have already been determined. */
7740 dec_dynrel_count (bfd_vma r_info
,
7742 struct bfd_link_info
*info
,
7743 Elf_Internal_Sym
**local_syms
,
7744 struct elf_link_hash_entry
*h
,
7745 Elf_Internal_Sym
*sym
)
7747 enum elf_ppc64_reloc_type r_type
;
7748 asection
*sym_sec
= NULL
;
7750 /* Can this reloc be dynamic? This switch, and later tests here
7751 should be kept in sync with the code in check_relocs. */
7752 r_type
= ELF64_R_TYPE (r_info
);
7758 case R_PPC64_TPREL16
:
7759 case R_PPC64_TPREL16_LO
:
7760 case R_PPC64_TPREL16_HI
:
7761 case R_PPC64_TPREL16_HA
:
7762 case R_PPC64_TPREL16_DS
:
7763 case R_PPC64_TPREL16_LO_DS
:
7764 case R_PPC64_TPREL16_HIGH
:
7765 case R_PPC64_TPREL16_HIGHA
:
7766 case R_PPC64_TPREL16_HIGHER
:
7767 case R_PPC64_TPREL16_HIGHERA
:
7768 case R_PPC64_TPREL16_HIGHEST
:
7769 case R_PPC64_TPREL16_HIGHESTA
:
7770 case R_PPC64_TPREL64
:
7771 case R_PPC64_DTPMOD64
:
7772 case R_PPC64_DTPREL64
:
7773 case R_PPC64_ADDR64
:
7777 case R_PPC64_ADDR14
:
7778 case R_PPC64_ADDR14_BRNTAKEN
:
7779 case R_PPC64_ADDR14_BRTAKEN
:
7780 case R_PPC64_ADDR16
:
7781 case R_PPC64_ADDR16_DS
:
7782 case R_PPC64_ADDR16_HA
:
7783 case R_PPC64_ADDR16_HI
:
7784 case R_PPC64_ADDR16_HIGH
:
7785 case R_PPC64_ADDR16_HIGHA
:
7786 case R_PPC64_ADDR16_HIGHER
:
7787 case R_PPC64_ADDR16_HIGHERA
:
7788 case R_PPC64_ADDR16_HIGHEST
:
7789 case R_PPC64_ADDR16_HIGHESTA
:
7790 case R_PPC64_ADDR16_LO
:
7791 case R_PPC64_ADDR16_LO_DS
:
7792 case R_PPC64_ADDR24
:
7793 case R_PPC64_ADDR32
:
7794 case R_PPC64_UADDR16
:
7795 case R_PPC64_UADDR32
:
7796 case R_PPC64_UADDR64
:
7801 if (local_syms
!= NULL
)
7803 unsigned long r_symndx
;
7804 bfd
*ibfd
= sec
->owner
;
7806 r_symndx
= ELF64_R_SYM (r_info
);
7807 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
7811 if ((bfd_link_pic (info
)
7812 && (must_be_dyn_reloc (info
, r_type
)
7814 && (!SYMBOLIC_BIND (info
, h
)
7815 || h
->root
.type
== bfd_link_hash_defweak
7816 || !h
->def_regular
))))
7817 || (ELIMINATE_COPY_RELOCS
7818 && !bfd_link_pic (info
)
7820 && (h
->root
.type
== bfd_link_hash_defweak
7821 || !h
->def_regular
)))
7828 struct elf_dyn_relocs
*p
;
7829 struct elf_dyn_relocs
**pp
;
7830 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
7832 /* elf_gc_sweep may have already removed all dyn relocs associated
7833 with local syms for a given section. Also, symbol flags are
7834 changed by elf_gc_sweep_symbol, confusing the test above. Don't
7835 report a dynreloc miscount. */
7836 if (*pp
== NULL
&& info
->gc_sections
)
7839 while ((p
= *pp
) != NULL
)
7843 if (!must_be_dyn_reloc (info
, r_type
))
7855 struct ppc_dyn_relocs
*p
;
7856 struct ppc_dyn_relocs
**pp
;
7858 bfd_boolean is_ifunc
;
7860 if (local_syms
== NULL
)
7861 sym_sec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
7862 if (sym_sec
== NULL
)
7865 vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
7866 pp
= (struct ppc_dyn_relocs
**) vpp
;
7868 if (*pp
== NULL
&& info
->gc_sections
)
7871 is_ifunc
= ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
;
7872 while ((p
= *pp
) != NULL
)
7874 if (p
->sec
== sec
&& p
->ifunc
== is_ifunc
)
7885 /* xgettext:c-format */
7886 _bfd_error_handler (_("dynreloc miscount for %pB, section %pA"),
7888 bfd_set_error (bfd_error_bad_value
);
7892 /* Remove unused Official Procedure Descriptor entries. Currently we
7893 only remove those associated with functions in discarded link-once
7894 sections, or weakly defined functions that have been overridden. It
7895 would be possible to remove many more entries for statically linked
7899 ppc64_elf_edit_opd (struct bfd_link_info
*info
)
7902 bfd_boolean some_edited
= FALSE
;
7903 asection
*need_pad
= NULL
;
7904 struct ppc_link_hash_table
*htab
;
7906 htab
= ppc_hash_table (info
);
7910 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
7913 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
7914 Elf_Internal_Shdr
*symtab_hdr
;
7915 Elf_Internal_Sym
*local_syms
;
7916 struct _opd_sec_data
*opd
;
7917 bfd_boolean need_edit
, add_aux_fields
, broken
;
7918 bfd_size_type cnt_16b
= 0;
7920 if (!is_ppc64_elf (ibfd
))
7923 sec
= bfd_get_section_by_name (ibfd
, ".opd");
7924 if (sec
== NULL
|| sec
->size
== 0)
7927 if (sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
7930 if (sec
->output_section
== bfd_abs_section_ptr
)
7933 /* Look through the section relocs. */
7934 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
7938 symtab_hdr
= &elf_symtab_hdr (ibfd
);
7940 /* Read the relocations. */
7941 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7943 if (relstart
== NULL
)
7946 /* First run through the relocs to check they are sane, and to
7947 determine whether we need to edit this opd section. */
7951 relend
= relstart
+ sec
->reloc_count
;
7952 for (rel
= relstart
; rel
< relend
; )
7954 enum elf_ppc64_reloc_type r_type
;
7955 unsigned long r_symndx
;
7957 struct elf_link_hash_entry
*h
;
7958 Elf_Internal_Sym
*sym
;
7961 /* .opd contains an array of 16 or 24 byte entries. We're
7962 only interested in the reloc pointing to a function entry
7964 offset
= rel
->r_offset
;
7965 if (rel
+ 1 == relend
7966 || rel
[1].r_offset
!= offset
+ 8)
7968 /* If someone messes with .opd alignment then after a
7969 "ld -r" we might have padding in the middle of .opd.
7970 Also, there's nothing to prevent someone putting
7971 something silly in .opd with the assembler. No .opd
7972 optimization for them! */
7975 (_("%pB: .opd is not a regular array of opd entries"), ibfd
);
7980 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
7981 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
7984 /* xgettext:c-format */
7985 (_("%pB: unexpected reloc type %u in .opd section"),
7991 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7992 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7996 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
7998 const char *sym_name
;
8000 sym_name
= h
->root
.root
.string
;
8002 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
8006 /* xgettext:c-format */
8007 (_("%pB: undefined sym `%s' in .opd section"),
8013 /* opd entries are always for functions defined in the
8014 current input bfd. If the symbol isn't defined in the
8015 input bfd, then we won't be using the function in this
8016 bfd; It must be defined in a linkonce section in another
8017 bfd, or is weak. It's also possible that we are
8018 discarding the function due to a linker script /DISCARD/,
8019 which we test for via the output_section. */
8020 if (sym_sec
->owner
!= ibfd
8021 || sym_sec
->output_section
== bfd_abs_section_ptr
)
8025 if (rel
+ 1 == relend
8026 || (rel
+ 2 < relend
8027 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
))
8032 if (sec
->size
== offset
+ 24)
8037 if (sec
->size
== offset
+ 16)
8044 else if (rel
+ 1 < relend
8045 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
8046 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
8048 if (rel
[0].r_offset
== offset
+ 16)
8050 else if (rel
[0].r_offset
!= offset
+ 24)
8057 add_aux_fields
= htab
->params
->non_overlapping_opd
&& cnt_16b
> 0;
8059 if (!broken
&& (need_edit
|| add_aux_fields
))
8061 Elf_Internal_Rela
*write_rel
;
8062 Elf_Internal_Shdr
*rel_hdr
;
8063 bfd_byte
*rptr
, *wptr
;
8064 bfd_byte
*new_contents
;
8067 new_contents
= NULL
;
8068 amt
= OPD_NDX (sec
->size
) * sizeof (long);
8069 opd
= &ppc64_elf_section_data (sec
)->u
.opd
;
8070 opd
->adjust
= bfd_zalloc (sec
->owner
, amt
);
8071 if (opd
->adjust
== NULL
)
8074 /* This seems a waste of time as input .opd sections are all
8075 zeros as generated by gcc, but I suppose there's no reason
8076 this will always be so. We might start putting something in
8077 the third word of .opd entries. */
8078 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
8081 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
8086 if (local_syms
!= NULL
8087 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8089 if (elf_section_data (sec
)->relocs
!= relstart
)
8093 sec
->contents
= loc
;
8094 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8097 elf_section_data (sec
)->relocs
= relstart
;
8099 new_contents
= sec
->contents
;
8102 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
8103 if (new_contents
== NULL
)
8107 wptr
= new_contents
;
8108 rptr
= sec
->contents
;
8109 write_rel
= relstart
;
8110 for (rel
= relstart
; rel
< relend
; )
8112 unsigned long r_symndx
;
8114 struct elf_link_hash_entry
*h
;
8115 struct ppc_link_hash_entry
*fdh
= NULL
;
8116 Elf_Internal_Sym
*sym
;
8118 Elf_Internal_Rela
*next_rel
;
8121 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8122 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8127 if (next_rel
+ 1 == relend
8128 || (next_rel
+ 2 < relend
8129 && ELF64_R_TYPE (next_rel
[2].r_info
) == R_PPC64_TOC
))
8132 /* See if the .opd entry is full 24 byte or
8133 16 byte (with fd_aux entry overlapped with next
8136 if (next_rel
== relend
)
8138 if (sec
->size
== rel
->r_offset
+ 16)
8141 else if (next_rel
->r_offset
== rel
->r_offset
+ 16)
8145 && h
->root
.root
.string
[0] == '.')
8147 fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
8150 fdh
= ppc_follow_link (fdh
);
8151 if (fdh
->elf
.root
.type
!= bfd_link_hash_defined
8152 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8157 skip
= (sym_sec
->owner
!= ibfd
8158 || sym_sec
->output_section
== bfd_abs_section_ptr
);
8161 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
8163 /* Arrange for the function descriptor sym
8165 fdh
->elf
.root
.u
.def
.value
= 0;
8166 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
8168 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = -1;
8170 if (NO_OPD_RELOCS
|| bfd_link_relocatable (info
))
8175 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
8179 if (++rel
== next_rel
)
8182 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8183 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
8190 /* We'll be keeping this opd entry. */
8195 /* Redefine the function descriptor symbol to
8196 this location in the opd section. It is
8197 necessary to update the value here rather
8198 than using an array of adjustments as we do
8199 for local symbols, because various places
8200 in the generic ELF code use the value
8201 stored in u.def.value. */
8202 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
8203 fdh
->adjust_done
= 1;
8206 /* Local syms are a bit tricky. We could
8207 tweak them as they can be cached, but
8208 we'd need to look through the local syms
8209 for the function descriptor sym which we
8210 don't have at the moment. So keep an
8211 array of adjustments. */
8212 adjust
= (wptr
- new_contents
) - (rptr
- sec
->contents
);
8213 opd
->adjust
[OPD_NDX (rel
->r_offset
)] = adjust
;
8216 memcpy (wptr
, rptr
, opd_ent_size
);
8217 wptr
+= opd_ent_size
;
8218 if (add_aux_fields
&& opd_ent_size
== 16)
8220 memset (wptr
, '\0', 8);
8224 /* We need to adjust any reloc offsets to point to the
8226 for ( ; rel
!= next_rel
; ++rel
)
8228 rel
->r_offset
+= adjust
;
8229 if (write_rel
!= rel
)
8230 memcpy (write_rel
, rel
, sizeof (*rel
));
8235 rptr
+= opd_ent_size
;
8238 sec
->size
= wptr
- new_contents
;
8239 sec
->reloc_count
= write_rel
- relstart
;
8242 free (sec
->contents
);
8243 sec
->contents
= new_contents
;
8246 /* Fudge the header size too, as this is used later in
8247 elf_bfd_final_link if we are emitting relocs. */
8248 rel_hdr
= _bfd_elf_single_rel_hdr (sec
);
8249 rel_hdr
->sh_size
= sec
->reloc_count
* rel_hdr
->sh_entsize
;
8252 else if (elf_section_data (sec
)->relocs
!= relstart
)
8255 if (local_syms
!= NULL
8256 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8258 if (!info
->keep_memory
)
8261 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8266 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
8268 /* If we are doing a final link and the last .opd entry is just 16 byte
8269 long, add a 8 byte padding after it. */
8270 if (need_pad
!= NULL
&& !bfd_link_relocatable (info
))
8274 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
8276 BFD_ASSERT (need_pad
->size
> 0);
8278 p
= bfd_malloc (need_pad
->size
+ 8);
8282 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
8283 p
, 0, need_pad
->size
))
8286 need_pad
->contents
= p
;
8287 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
8291 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
8295 need_pad
->contents
= p
;
8298 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
8299 need_pad
->size
+= 8;
8305 /* Analyze inline PLT call relocations to see whether calls to locally
8306 defined functions can be converted to direct calls. */
8309 ppc64_elf_inline_plt (struct bfd_link_info
*info
)
8311 struct ppc_link_hash_table
*htab
;
8314 bfd_vma low_vma
, high_vma
, limit
;
8316 htab
= ppc_hash_table (info
);
8320 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
8321 reduced somewhat to cater for possible stubs that might be added
8322 between the call and its destination. */
8323 if (htab
->params
->group_size
< 0)
8325 limit
= -htab
->params
->group_size
;
8331 limit
= htab
->params
->group_size
;
8338 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8339 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
8341 if (low_vma
> sec
->vma
)
8343 if (high_vma
< sec
->vma
+ sec
->size
)
8344 high_vma
= sec
->vma
+ sec
->size
;
8347 /* If a "bl" can reach anywhere in local code sections, then we can
8348 convert all inline PLT sequences to direct calls when the symbol
8350 if (high_vma
- low_vma
< limit
)
8352 htab
->can_convert_all_inline_plt
= 1;
8356 /* Otherwise, go looking through relocs for cases where a direct
8357 call won't reach. Mark the symbol on any such reloc to disable
8358 the optimization and keep the PLT entry as it seems likely that
8359 this will be better than creating trampolines. Note that this
8360 will disable the optimization for all inline PLT calls to a
8361 particular symbol, not just those that won't reach. The
8362 difficulty in doing a more precise optimization is that the
8363 linker needs to make a decision depending on whether a
8364 particular R_PPC64_PLTCALL insn can be turned into a direct
8365 call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
8366 the sequence, and there is nothing that ties those relocs
8367 together except their symbol. */
8369 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8371 Elf_Internal_Shdr
*symtab_hdr
;
8372 Elf_Internal_Sym
*local_syms
;
8374 if (!is_ppc64_elf (ibfd
))
8378 symtab_hdr
= &elf_symtab_hdr (ibfd
);
8380 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8381 if (ppc64_elf_section_data (sec
)->has_pltcall
8382 && !bfd_is_abs_section (sec
->output_section
))
8384 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8386 /* Read the relocations. */
8387 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8389 if (relstart
== NULL
)
8392 relend
= relstart
+ sec
->reloc_count
;
8393 for (rel
= relstart
; rel
< relend
; )
8395 enum elf_ppc64_reloc_type r_type
;
8396 unsigned long r_symndx
;
8398 struct elf_link_hash_entry
*h
;
8399 Elf_Internal_Sym
*sym
;
8400 unsigned char *tls_maskp
;
8402 r_type
= ELF64_R_TYPE (rel
->r_info
);
8403 if (r_type
!= R_PPC64_PLTCALL
)
8406 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8407 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
8410 if (elf_section_data (sec
)->relocs
!= relstart
)
8412 if (local_syms
!= NULL
8413 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8418 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
8422 to
= h
->root
.u
.def
.value
;
8425 to
+= (rel
->r_addend
8426 + sym_sec
->output_offset
8427 + sym_sec
->output_section
->vma
);
8428 from
= (rel
->r_offset
8429 + sec
->output_offset
8430 + sec
->output_section
->vma
);
8431 if (to
- from
+ limit
< 2 * limit
)
8432 *tls_maskp
&= ~PLT_KEEP
;
8435 if (elf_section_data (sec
)->relocs
!= relstart
)
8439 if (local_syms
!= NULL
8440 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
8442 if (!info
->keep_memory
)
8445 symtab_hdr
->contents
= (unsigned char *) local_syms
;
8452 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
8455 ppc64_elf_tls_setup (struct bfd_link_info
*info
)
8457 struct ppc_link_hash_table
*htab
;
8459 htab
= ppc_hash_table (info
);
8463 if (abiversion (info
->output_bfd
) == 1)
8466 if (htab
->params
->no_multi_toc
)
8467 htab
->do_multi_toc
= 0;
8468 else if (!htab
->do_multi_toc
)
8469 htab
->params
->no_multi_toc
= 1;
8471 /* Default to --no-plt-localentry, as this option can cause problems
8472 with symbol interposition. For example, glibc libpthread.so and
8473 libc.so duplicate many pthread symbols, with a fallback
8474 implementation in libc.so. In some cases the fallback does more
8475 work than the pthread implementation. __pthread_condattr_destroy
8476 is one such symbol: the libpthread.so implementation is
8477 localentry:0 while the libc.so implementation is localentry:8.
8478 An app that "cleverly" uses dlopen to only load necessary
8479 libraries at runtime may omit loading libpthread.so when not
8480 running multi-threaded, which then results in the libc.so
8481 fallback symbols being used and ld.so complaining. Now there
8482 are workarounds in ld (see non_zero_localentry) to detect the
8483 pthread situation, but that may not be the only case where
8484 --plt-localentry can cause trouble. */
8485 if (htab
->params
->plt_localentry0
< 0)
8486 htab
->params
->plt_localentry0
= 0;
8487 if (htab
->params
->plt_localentry0
8488 && elf_link_hash_lookup (&htab
->elf
, "GLIBC_2.26",
8489 FALSE
, FALSE
, FALSE
) == NULL
)
8491 (_("warning: --plt-localentry is especially dangerous without "
8492 "ld.so support to detect ABI violations"));
8494 htab
->tls_get_addr
= ((struct ppc_link_hash_entry
*)
8495 elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr",
8496 FALSE
, FALSE
, TRUE
));
8497 /* Move dynamic linking info to the function descriptor sym. */
8498 if (htab
->tls_get_addr
!= NULL
)
8499 func_desc_adjust (&htab
->tls_get_addr
->elf
, info
);
8500 htab
->tls_get_addr_fd
= ((struct ppc_link_hash_entry
*)
8501 elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
8502 FALSE
, FALSE
, TRUE
));
8503 if (htab
->params
->tls_get_addr_opt
)
8505 struct elf_link_hash_entry
*opt
, *opt_fd
, *tga
, *tga_fd
;
8507 opt
= elf_link_hash_lookup (&htab
->elf
, ".__tls_get_addr_opt",
8508 FALSE
, FALSE
, TRUE
);
8510 func_desc_adjust (opt
, info
);
8511 opt_fd
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
8512 FALSE
, FALSE
, TRUE
);
8514 && (opt_fd
->root
.type
== bfd_link_hash_defined
8515 || opt_fd
->root
.type
== bfd_link_hash_defweak
))
8517 /* If glibc supports an optimized __tls_get_addr call stub,
8518 signalled by the presence of __tls_get_addr_opt, and we'll
8519 be calling __tls_get_addr via a plt call stub, then
8520 make __tls_get_addr point to __tls_get_addr_opt. */
8521 tga_fd
= &htab
->tls_get_addr_fd
->elf
;
8522 if (htab
->elf
.dynamic_sections_created
8524 && (tga_fd
->type
== STT_FUNC
8525 || tga_fd
->needs_plt
)
8526 && !(SYMBOL_CALLS_LOCAL (info
, tga_fd
)
8527 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga_fd
)))
8529 struct plt_entry
*ent
;
8531 for (ent
= tga_fd
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8532 if (ent
->plt
.refcount
> 0)
8536 tga_fd
->root
.type
= bfd_link_hash_indirect
;
8537 tga_fd
->root
.u
.i
.link
= &opt_fd
->root
;
8538 ppc64_elf_copy_indirect_symbol (info
, opt_fd
, tga_fd
);
8540 if (opt_fd
->dynindx
!= -1)
8542 /* Use __tls_get_addr_opt in dynamic relocations. */
8543 opt_fd
->dynindx
= -1;
8544 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
8545 opt_fd
->dynstr_index
);
8546 if (!bfd_elf_link_record_dynamic_symbol (info
, opt_fd
))
8549 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) opt_fd
;
8550 tga
= &htab
->tls_get_addr
->elf
;
8551 if (opt
!= NULL
&& tga
!= NULL
)
8553 tga
->root
.type
= bfd_link_hash_indirect
;
8554 tga
->root
.u
.i
.link
= &opt
->root
;
8555 ppc64_elf_copy_indirect_symbol (info
, opt
, tga
);
8557 _bfd_elf_link_hash_hide_symbol (info
, opt
,
8559 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) opt
;
8561 htab
->tls_get_addr_fd
->oh
= htab
->tls_get_addr
;
8562 htab
->tls_get_addr_fd
->is_func_descriptor
= 1;
8563 if (htab
->tls_get_addr
!= NULL
)
8565 htab
->tls_get_addr
->oh
= htab
->tls_get_addr_fd
;
8566 htab
->tls_get_addr
->is_func
= 1;
8571 else if (htab
->params
->tls_get_addr_opt
< 0)
8572 htab
->params
->tls_get_addr_opt
= 0;
8574 return _bfd_elf_tls_setup (info
->output_bfd
, info
);
8577 /* Return TRUE iff REL is a branch reloc with a global symbol matching
8581 branch_reloc_hash_match (const bfd
*ibfd
,
8582 const Elf_Internal_Rela
*rel
,
8583 const struct ppc_link_hash_entry
*hash1
,
8584 const struct ppc_link_hash_entry
*hash2
)
8586 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
8587 enum elf_ppc64_reloc_type r_type
= ELF64_R_TYPE (rel
->r_info
);
8588 unsigned int r_symndx
= ELF64_R_SYM (rel
->r_info
);
8590 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
8592 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
8593 struct elf_link_hash_entry
*h
;
8595 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
8596 h
= elf_follow_link (h
);
8597 if (h
== &hash1
->elf
|| h
== &hash2
->elf
)
8603 /* Run through all the TLS relocs looking for optimization
8604 opportunities. The linker has been hacked (see ppc64elf.em) to do
8605 a preliminary section layout so that we know the TLS segment
8606 offsets. We can't optimize earlier because some optimizations need
8607 to know the tp offset, and we need to optimize before allocating
8608 dynamic relocations. */
8611 ppc64_elf_tls_optimize (struct bfd_link_info
*info
)
8615 struct ppc_link_hash_table
*htab
;
8616 unsigned char *toc_ref
;
8619 if (!bfd_link_executable (info
))
8622 htab
= ppc_hash_table (info
);
8626 /* Make two passes over the relocs. On the first pass, mark toc
8627 entries involved with tls relocs, and check that tls relocs
8628 involved in setting up a tls_get_addr call are indeed followed by
8629 such a call. If they are not, we can't do any tls optimization.
8630 On the second pass twiddle tls_mask flags to notify
8631 relocate_section that optimization can be done, and adjust got
8632 and plt refcounts. */
8634 for (pass
= 0; pass
< 2; ++pass
)
8635 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
8637 Elf_Internal_Sym
*locsyms
= NULL
;
8638 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
8640 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
8641 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
8643 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
8644 bfd_boolean found_tls_get_addr_arg
= 0;
8646 /* Read the relocations. */
8647 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
8649 if (relstart
== NULL
)
8655 relend
= relstart
+ sec
->reloc_count
;
8656 for (rel
= relstart
; rel
< relend
; rel
++)
8658 enum elf_ppc64_reloc_type r_type
;
8659 unsigned long r_symndx
;
8660 struct elf_link_hash_entry
*h
;
8661 Elf_Internal_Sym
*sym
;
8663 unsigned char *tls_mask
;
8664 unsigned char tls_set
, tls_clear
, tls_type
= 0;
8666 bfd_boolean ok_tprel
, is_local
;
8667 long toc_ref_index
= 0;
8668 int expecting_tls_get_addr
= 0;
8669 bfd_boolean ret
= FALSE
;
8671 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8672 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
8676 if (elf_section_data (sec
)->relocs
!= relstart
)
8678 if (toc_ref
!= NULL
)
8681 && (elf_symtab_hdr (ibfd
).contents
8682 != (unsigned char *) locsyms
))
8689 if (h
->root
.type
== bfd_link_hash_defined
8690 || h
->root
.type
== bfd_link_hash_defweak
)
8691 value
= h
->root
.u
.def
.value
;
8692 else if (h
->root
.type
== bfd_link_hash_undefweak
)
8696 found_tls_get_addr_arg
= 0;
8701 /* Symbols referenced by TLS relocs must be of type
8702 STT_TLS. So no need for .opd local sym adjust. */
8703 value
= sym
->st_value
;
8712 && h
->root
.type
== bfd_link_hash_undefweak
)
8714 else if (sym_sec
!= NULL
8715 && sym_sec
->output_section
!= NULL
)
8717 value
+= sym_sec
->output_offset
;
8718 value
+= sym_sec
->output_section
->vma
;
8719 value
-= htab
->elf
.tls_sec
->vma
;
8720 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
8721 < (bfd_vma
) 1 << 32);
8725 r_type
= ELF64_R_TYPE (rel
->r_info
);
8726 /* If this section has old-style __tls_get_addr calls
8727 without marker relocs, then check that each
8728 __tls_get_addr call reloc is preceded by a reloc
8729 that conceivably belongs to the __tls_get_addr arg
8730 setup insn. If we don't find matching arg setup
8731 relocs, don't do any tls optimization. */
8733 && sec
->has_tls_get_addr_call
8735 && (h
== &htab
->tls_get_addr
->elf
8736 || h
== &htab
->tls_get_addr_fd
->elf
)
8737 && !found_tls_get_addr_arg
8738 && is_branch_reloc (r_type
))
8740 info
->callbacks
->minfo (_("%H __tls_get_addr lost arg, "
8741 "TLS optimization disabled\n"),
8742 ibfd
, sec
, rel
->r_offset
);
8747 found_tls_get_addr_arg
= 0;
8750 case R_PPC64_GOT_TLSLD16
:
8751 case R_PPC64_GOT_TLSLD16_LO
:
8752 expecting_tls_get_addr
= 1;
8753 found_tls_get_addr_arg
= 1;
8756 case R_PPC64_GOT_TLSLD16_HI
:
8757 case R_PPC64_GOT_TLSLD16_HA
:
8758 /* These relocs should never be against a symbol
8759 defined in a shared lib. Leave them alone if
8760 that turns out to be the case. */
8767 tls_type
= TLS_TLS
| TLS_LD
;
8770 case R_PPC64_GOT_TLSGD16
:
8771 case R_PPC64_GOT_TLSGD16_LO
:
8772 expecting_tls_get_addr
= 1;
8773 found_tls_get_addr_arg
= 1;
8776 case R_PPC64_GOT_TLSGD16_HI
:
8777 case R_PPC64_GOT_TLSGD16_HA
:
8783 tls_set
= TLS_TLS
| TLS_TPRELGD
;
8785 tls_type
= TLS_TLS
| TLS_GD
;
8788 case R_PPC64_GOT_TPREL16_DS
:
8789 case R_PPC64_GOT_TPREL16_LO_DS
:
8790 case R_PPC64_GOT_TPREL16_HI
:
8791 case R_PPC64_GOT_TPREL16_HA
:
8796 tls_clear
= TLS_TPREL
;
8797 tls_type
= TLS_TLS
| TLS_TPREL
;
8804 if (rel
+ 1 < relend
8805 && is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
8808 && ELF64_R_TYPE (rel
[1].r_info
) != R_PPC64_PLTSEQ
)
8810 r_symndx
= ELF64_R_SYM (rel
[1].r_info
);
8811 if (!get_sym_h (&h
, NULL
, NULL
, NULL
, &locsyms
,
8816 struct plt_entry
*ent
= NULL
;
8818 for (ent
= h
->plt
.plist
;
8821 if (ent
->addend
== rel
[1].r_addend
)
8825 && ent
->plt
.refcount
> 0)
8826 ent
->plt
.refcount
-= 1;
8831 found_tls_get_addr_arg
= 1;
8836 case R_PPC64_TOC16_LO
:
8837 if (sym_sec
== NULL
|| sym_sec
!= toc
)
8840 /* Mark this toc entry as referenced by a TLS
8841 code sequence. We can do that now in the
8842 case of R_PPC64_TLS, and after checking for
8843 tls_get_addr for the TOC16 relocs. */
8844 if (toc_ref
== NULL
)
8845 toc_ref
= bfd_zmalloc (toc
->output_section
->rawsize
/ 8);
8846 if (toc_ref
== NULL
)
8850 value
= h
->root
.u
.def
.value
;
8852 value
= sym
->st_value
;
8853 value
+= rel
->r_addend
;
8856 BFD_ASSERT (value
< toc
->size
8857 && toc
->output_offset
% 8 == 0);
8858 toc_ref_index
= (value
+ toc
->output_offset
) / 8;
8859 if (r_type
== R_PPC64_TLS
8860 || r_type
== R_PPC64_TLSGD
8861 || r_type
== R_PPC64_TLSLD
)
8863 toc_ref
[toc_ref_index
] = 1;
8867 if (pass
!= 0 && toc_ref
[toc_ref_index
] == 0)
8872 expecting_tls_get_addr
= 2;
8875 case R_PPC64_TPREL64
:
8879 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8884 tls_set
= TLS_EXPLICIT
;
8885 tls_clear
= TLS_TPREL
;
8890 case R_PPC64_DTPMOD64
:
8894 || !toc_ref
[(rel
->r_offset
+ toc
->output_offset
) / 8])
8896 if (rel
+ 1 < relend
8898 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
8899 && rel
[1].r_offset
== rel
->r_offset
+ 8)
8903 tls_set
= TLS_EXPLICIT
| TLS_GD
;
8906 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
8915 tls_set
= TLS_EXPLICIT
;
8926 if (!expecting_tls_get_addr
8927 || !sec
->has_tls_get_addr_call
)
8930 if (rel
+ 1 < relend
8931 && branch_reloc_hash_match (ibfd
, rel
+ 1,
8933 htab
->tls_get_addr_fd
))
8935 if (expecting_tls_get_addr
== 2)
8937 /* Check for toc tls entries. */
8938 unsigned char *toc_tls
;
8941 retval
= get_tls_mask (&toc_tls
, NULL
, NULL
,
8946 if (toc_tls
!= NULL
)
8948 if ((*toc_tls
& TLS_TLS
) != 0
8949 && ((*toc_tls
& (TLS_GD
| TLS_LD
)) != 0))
8950 found_tls_get_addr_arg
= 1;
8952 toc_ref
[toc_ref_index
] = 1;
8958 /* Uh oh, we didn't find the expected call. We
8959 could just mark this symbol to exclude it
8960 from tls optimization but it's safer to skip
8961 the entire optimization. */
8962 /* xgettext:c-format */
8963 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
8964 "TLS optimization disabled\n"),
8965 ibfd
, sec
, rel
->r_offset
);
8970 /* If we don't have old-style __tls_get_addr calls
8971 without TLSGD/TLSLD marker relocs, and we haven't
8972 found a new-style __tls_get_addr call with a
8973 marker for this symbol, then we either have a
8974 broken object file or an -mlongcall style
8975 indirect call to __tls_get_addr without a marker.
8976 Disable optimization in this case. */
8977 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
8978 && (tls_set
& TLS_EXPLICIT
) == 0
8979 && !sec
->has_tls_get_addr_call
8980 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
8981 != (TLS_TLS
| TLS_MARK
)))
8984 if (expecting_tls_get_addr
)
8986 struct plt_entry
*ent
= NULL
;
8988 if (htab
->tls_get_addr
!= NULL
)
8989 for (ent
= htab
->tls_get_addr
->elf
.plt
.plist
;
8992 if (ent
->addend
== 0)
8995 if (ent
== NULL
&& htab
->tls_get_addr_fd
!= NULL
)
8996 for (ent
= htab
->tls_get_addr_fd
->elf
.plt
.plist
;
8999 if (ent
->addend
== 0)
9003 && ent
->plt
.refcount
> 0)
9004 ent
->plt
.refcount
-= 1;
9010 if ((tls_set
& TLS_EXPLICIT
) == 0)
9012 struct got_entry
*ent
;
9014 /* Adjust got entry for this reloc. */
9018 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
9020 for (; ent
!= NULL
; ent
= ent
->next
)
9021 if (ent
->addend
== rel
->r_addend
9022 && ent
->owner
== ibfd
9023 && ent
->tls_type
== tls_type
)
9030 /* We managed to get rid of a got entry. */
9031 if (ent
->got
.refcount
> 0)
9032 ent
->got
.refcount
-= 1;
9037 /* If we got rid of a DTPMOD/DTPREL reloc pair then
9038 we'll lose one or two dyn relocs. */
9039 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
9043 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
9045 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
9051 *tls_mask
|= tls_set
;
9052 *tls_mask
&= ~tls_clear
;
9055 if (elf_section_data (sec
)->relocs
!= relstart
)
9060 && (elf_symtab_hdr (ibfd
).contents
!= (unsigned char *) locsyms
))
9062 if (!info
->keep_memory
)
9065 elf_symtab_hdr (ibfd
).contents
= (unsigned char *) locsyms
;
9069 if (toc_ref
!= NULL
)
9071 htab
->do_tls_opt
= 1;
9075 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
9076 the values of any global symbols in a toc section that has been
9077 edited. Globals in toc sections should be a rarity, so this function
9078 sets a flag if any are found in toc sections other than the one just
9079 edited, so that further hash table traversals can be avoided. */
9081 struct adjust_toc_info
9084 unsigned long *skip
;
9085 bfd_boolean global_toc_syms
;
9088 enum toc_skip_enum
{ ref_from_discarded
= 1, can_optimize
= 2 };
9091 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
9093 struct ppc_link_hash_entry
*eh
;
9094 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
9097 if (h
->root
.type
!= bfd_link_hash_defined
9098 && h
->root
.type
!= bfd_link_hash_defweak
)
9101 eh
= (struct ppc_link_hash_entry
*) h
;
9102 if (eh
->adjust_done
)
9105 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
9107 if (eh
->elf
.root
.u
.def
.value
> toc_inf
->toc
->rawsize
)
9108 i
= toc_inf
->toc
->rawsize
>> 3;
9110 i
= eh
->elf
.root
.u
.def
.value
>> 3;
9112 if ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9115 (_("%s defined on removed toc entry"), eh
->elf
.root
.root
.string
);
9118 while ((toc_inf
->skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0);
9119 eh
->elf
.root
.u
.def
.value
= (bfd_vma
) i
<< 3;
9122 eh
->elf
.root
.u
.def
.value
-= toc_inf
->skip
[i
];
9123 eh
->adjust_done
= 1;
9125 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
9126 toc_inf
->global_toc_syms
= TRUE
;
9131 /* Return TRUE iff INSN with a relocation of R_TYPE is one we expect
9132 on a _LO variety toc/got reloc. */
9135 ok_lo_toc_insn (unsigned int insn
, enum elf_ppc64_reloc_type r_type
)
9137 return ((insn
& (0x3f << 26)) == 12u << 26 /* addic */
9138 || (insn
& (0x3f << 26)) == 14u << 26 /* addi */
9139 || (insn
& (0x3f << 26)) == 32u << 26 /* lwz */
9140 || (insn
& (0x3f << 26)) == 34u << 26 /* lbz */
9141 || (insn
& (0x3f << 26)) == 36u << 26 /* stw */
9142 || (insn
& (0x3f << 26)) == 38u << 26 /* stb */
9143 || (insn
& (0x3f << 26)) == 40u << 26 /* lhz */
9144 || (insn
& (0x3f << 26)) == 42u << 26 /* lha */
9145 || (insn
& (0x3f << 26)) == 44u << 26 /* sth */
9146 || (insn
& (0x3f << 26)) == 46u << 26 /* lmw */
9147 || (insn
& (0x3f << 26)) == 47u << 26 /* stmw */
9148 || (insn
& (0x3f << 26)) == 48u << 26 /* lfs */
9149 || (insn
& (0x3f << 26)) == 50u << 26 /* lfd */
9150 || (insn
& (0x3f << 26)) == 52u << 26 /* stfs */
9151 || (insn
& (0x3f << 26)) == 54u << 26 /* stfd */
9152 || (insn
& (0x3f << 26)) == 56u << 26 /* lq,lfq */
9153 || ((insn
& (0x3f << 26)) == 57u << 26 /* lxsd,lxssp,lfdp */
9154 /* Exclude lfqu by testing reloc. If relocs are ever
9155 defined for the reduced D field in psq_lu then those
9156 will need testing too. */
9157 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
9158 || ((insn
& (0x3f << 26)) == 58u << 26 /* ld,lwa */
9160 || (insn
& (0x3f << 26)) == 60u << 26 /* stfq */
9161 || ((insn
& (0x3f << 26)) == 61u << 26 /* lxv,stx{v,sd,ssp},stfdp */
9162 /* Exclude stfqu. psq_stu as above for psq_lu. */
9163 && r_type
!= R_PPC64_TOC16_LO
&& r_type
!= R_PPC64_GOT16_LO
)
9164 || ((insn
& (0x3f << 26)) == 62u << 26 /* std,stq */
9165 && (insn
& 1) == 0));
9168 /* Examine all relocs referencing .toc sections in order to remove
9169 unused .toc entries. */
9172 ppc64_elf_edit_toc (struct bfd_link_info
*info
)
9175 struct adjust_toc_info toc_inf
;
9176 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9178 htab
->do_toc_opt
= 1;
9179 toc_inf
.global_toc_syms
= TRUE
;
9180 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9182 asection
*toc
, *sec
;
9183 Elf_Internal_Shdr
*symtab_hdr
;
9184 Elf_Internal_Sym
*local_syms
;
9185 Elf_Internal_Rela
*relstart
, *rel
, *toc_relocs
;
9186 unsigned long *skip
, *drop
;
9187 unsigned char *used
;
9188 unsigned char *keep
, last
, some_unused
;
9190 if (!is_ppc64_elf (ibfd
))
9193 toc
= bfd_get_section_by_name (ibfd
, ".toc");
9196 || toc
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
9197 || discarded_section (toc
))
9202 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9204 /* Look at sections dropped from the final link. */
9207 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9209 if (sec
->reloc_count
== 0
9210 || !discarded_section (sec
)
9211 || get_opd_info (sec
)
9212 || (sec
->flags
& SEC_ALLOC
) == 0
9213 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9216 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
9217 if (relstart
== NULL
)
9220 /* Run through the relocs to see which toc entries might be
9222 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9224 enum elf_ppc64_reloc_type r_type
;
9225 unsigned long r_symndx
;
9227 struct elf_link_hash_entry
*h
;
9228 Elf_Internal_Sym
*sym
;
9231 r_type
= ELF64_R_TYPE (rel
->r_info
);
9238 case R_PPC64_TOC16_LO
:
9239 case R_PPC64_TOC16_HI
:
9240 case R_PPC64_TOC16_HA
:
9241 case R_PPC64_TOC16_DS
:
9242 case R_PPC64_TOC16_LO_DS
:
9246 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9247 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9255 val
= h
->root
.u
.def
.value
;
9257 val
= sym
->st_value
;
9258 val
+= rel
->r_addend
;
9260 if (val
>= toc
->size
)
9263 /* Anything in the toc ought to be aligned to 8 bytes.
9264 If not, don't mark as unused. */
9270 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9275 skip
[val
>> 3] = ref_from_discarded
;
9278 if (elf_section_data (sec
)->relocs
!= relstart
)
9282 /* For largetoc loads of address constants, we can convert
9283 . addis rx,2,addr@got@ha
9284 . ld ry,addr@got@l(rx)
9286 . addis rx,2,addr@toc@ha
9287 . addi ry,rx,addr@toc@l
9288 when addr is within 2G of the toc pointer. This then means
9289 that the word storing "addr" in the toc is no longer needed. */
9291 if (!ppc64_elf_tdata (ibfd
)->has_small_toc_reloc
9292 && toc
->output_section
->rawsize
< (bfd_vma
) 1 << 31
9293 && toc
->reloc_count
!= 0)
9295 /* Read toc relocs. */
9296 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9298 if (toc_relocs
== NULL
)
9301 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9303 enum elf_ppc64_reloc_type r_type
;
9304 unsigned long r_symndx
;
9306 struct elf_link_hash_entry
*h
;
9307 Elf_Internal_Sym
*sym
;
9310 r_type
= ELF64_R_TYPE (rel
->r_info
);
9311 if (r_type
!= R_PPC64_ADDR64
)
9314 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9315 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9320 || sym_sec
->output_section
== NULL
9321 || discarded_section (sym_sec
))
9324 if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
9329 if (h
->type
== STT_GNU_IFUNC
)
9331 val
= h
->root
.u
.def
.value
;
9335 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9337 val
= sym
->st_value
;
9339 val
+= rel
->r_addend
;
9340 val
+= sym_sec
->output_section
->vma
+ sym_sec
->output_offset
;
9342 /* We don't yet know the exact toc pointer value, but we
9343 know it will be somewhere in the toc section. Don't
9344 optimize if the difference from any possible toc
9345 pointer is outside [ff..f80008000, 7fff7fff]. */
9346 addr
= toc
->output_section
->vma
+ TOC_BASE_OFF
;
9347 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9350 addr
= toc
->output_section
->vma
+ toc
->output_section
->rawsize
;
9351 if (val
- addr
+ (bfd_vma
) 0x80008000 >= (bfd_vma
) 1 << 32)
9356 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 15) / 8);
9361 skip
[rel
->r_offset
>> 3]
9362 |= can_optimize
| ((rel
- toc_relocs
) << 2);
9369 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
9373 if (local_syms
!= NULL
9374 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9378 && elf_section_data (sec
)->relocs
!= relstart
)
9380 if (toc_relocs
!= NULL
9381 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9388 /* Now check all kept sections that might reference the toc.
9389 Check the toc itself last. */
9390 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
9393 sec
= (sec
== toc
? NULL
9394 : sec
->next
== NULL
? toc
9395 : sec
->next
== toc
&& toc
->next
? toc
->next
9400 if (sec
->reloc_count
== 0
9401 || discarded_section (sec
)
9402 || get_opd_info (sec
)
9403 || (sec
->flags
& SEC_ALLOC
) == 0
9404 || (sec
->flags
& SEC_DEBUGGING
) != 0)
9407 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9409 if (relstart
== NULL
)
9415 /* Mark toc entries referenced as used. */
9419 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9421 enum elf_ppc64_reloc_type r_type
;
9422 unsigned long r_symndx
;
9424 struct elf_link_hash_entry
*h
;
9425 Elf_Internal_Sym
*sym
;
9427 enum {no_check
, check_lo
, check_ha
} insn_check
;
9429 r_type
= ELF64_R_TYPE (rel
->r_info
);
9433 insn_check
= no_check
;
9436 case R_PPC64_GOT_TLSLD16_HA
:
9437 case R_PPC64_GOT_TLSGD16_HA
:
9438 case R_PPC64_GOT_TPREL16_HA
:
9439 case R_PPC64_GOT_DTPREL16_HA
:
9440 case R_PPC64_GOT16_HA
:
9441 case R_PPC64_TOC16_HA
:
9442 insn_check
= check_ha
;
9445 case R_PPC64_GOT_TLSLD16_LO
:
9446 case R_PPC64_GOT_TLSGD16_LO
:
9447 case R_PPC64_GOT_TPREL16_LO_DS
:
9448 case R_PPC64_GOT_DTPREL16_LO_DS
:
9449 case R_PPC64_GOT16_LO
:
9450 case R_PPC64_GOT16_LO_DS
:
9451 case R_PPC64_TOC16_LO
:
9452 case R_PPC64_TOC16_LO_DS
:
9453 insn_check
= check_lo
;
9457 if (insn_check
!= no_check
)
9459 bfd_vma off
= rel
->r_offset
& ~3;
9460 unsigned char buf
[4];
9463 if (!bfd_get_section_contents (ibfd
, sec
, buf
, off
, 4))
9468 insn
= bfd_get_32 (ibfd
, buf
);
9469 if (insn_check
== check_lo
9470 ? !ok_lo_toc_insn (insn
, r_type
)
9471 : ((insn
& ((0x3f << 26) | 0x1f << 16))
9472 != ((15u << 26) | (2 << 16)) /* addis rt,2,imm */))
9476 ppc64_elf_tdata (ibfd
)->unexpected_toc_insn
= 1;
9477 sprintf (str
, "%#08x", insn
);
9478 info
->callbacks
->einfo
9479 /* xgettext:c-format */
9480 (_("%H: toc optimization is not supported for"
9481 " %s instruction\n"),
9482 ibfd
, sec
, rel
->r_offset
& ~3, str
);
9489 case R_PPC64_TOC16_LO
:
9490 case R_PPC64_TOC16_HI
:
9491 case R_PPC64_TOC16_HA
:
9492 case R_PPC64_TOC16_DS
:
9493 case R_PPC64_TOC16_LO_DS
:
9494 /* In case we're taking addresses of toc entries. */
9495 case R_PPC64_ADDR64
:
9502 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9503 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9514 val
= h
->root
.u
.def
.value
;
9516 val
= sym
->st_value
;
9517 val
+= rel
->r_addend
;
9519 if (val
>= toc
->size
)
9522 if ((skip
[val
>> 3] & can_optimize
) != 0)
9529 case R_PPC64_TOC16_HA
:
9532 case R_PPC64_TOC16_LO_DS
:
9533 off
= rel
->r_offset
;
9534 off
+= (bfd_big_endian (ibfd
) ? -2 : 3);
9535 if (!bfd_get_section_contents (ibfd
, sec
, &opc
,
9541 if ((opc
& (0x3f << 2)) == (58u << 2))
9546 /* Wrong sort of reloc, or not a ld. We may
9547 as well clear ref_from_discarded too. */
9554 /* For the toc section, we only mark as used if this
9555 entry itself isn't unused. */
9556 else if ((used
[rel
->r_offset
>> 3]
9557 || !(skip
[rel
->r_offset
>> 3] & ref_from_discarded
))
9560 /* Do all the relocs again, to catch reference
9569 if (elf_section_data (sec
)->relocs
!= relstart
)
9573 /* Merge the used and skip arrays. Assume that TOC
9574 doublewords not appearing as either used or unused belong
9575 to an entry more than one doubleword in size. */
9576 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
9577 drop
< skip
+ (toc
->size
+ 7) / 8;
9582 *drop
&= ~ref_from_discarded
;
9583 if ((*drop
& can_optimize
) != 0)
9587 else if ((*drop
& ref_from_discarded
) != 0)
9590 last
= ref_from_discarded
;
9600 bfd_byte
*contents
, *src
;
9602 Elf_Internal_Sym
*sym
;
9603 bfd_boolean local_toc_syms
= FALSE
;
9605 /* Shuffle the toc contents, and at the same time convert the
9606 skip array from booleans into offsets. */
9607 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
9610 elf_section_data (toc
)->this_hdr
.contents
= contents
;
9612 for (src
= contents
, off
= 0, drop
= skip
;
9613 src
< contents
+ toc
->size
;
9616 if ((*drop
& (can_optimize
| ref_from_discarded
)) != 0)
9621 memcpy (src
- off
, src
, 8);
9625 toc
->rawsize
= toc
->size
;
9626 toc
->size
= src
- contents
- off
;
9628 /* Adjust addends for relocs against the toc section sym,
9629 and optimize any accesses we can. */
9630 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
9632 if (sec
->reloc_count
== 0
9633 || discarded_section (sec
))
9636 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
9638 if (relstart
== NULL
)
9641 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
9643 enum elf_ppc64_reloc_type r_type
;
9644 unsigned long r_symndx
;
9646 struct elf_link_hash_entry
*h
;
9649 r_type
= ELF64_R_TYPE (rel
->r_info
);
9656 case R_PPC64_TOC16_LO
:
9657 case R_PPC64_TOC16_HI
:
9658 case R_PPC64_TOC16_HA
:
9659 case R_PPC64_TOC16_DS
:
9660 case R_PPC64_TOC16_LO_DS
:
9661 case R_PPC64_ADDR64
:
9665 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9666 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9674 val
= h
->root
.u
.def
.value
;
9677 val
= sym
->st_value
;
9679 local_toc_syms
= TRUE
;
9682 val
+= rel
->r_addend
;
9684 if (val
> toc
->rawsize
)
9686 else if ((skip
[val
>> 3] & ref_from_discarded
) != 0)
9688 else if ((skip
[val
>> 3] & can_optimize
) != 0)
9690 Elf_Internal_Rela
*tocrel
9691 = toc_relocs
+ (skip
[val
>> 3] >> 2);
9692 unsigned long tsym
= ELF64_R_SYM (tocrel
->r_info
);
9696 case R_PPC64_TOC16_HA
:
9697 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_TOC16_HA
);
9700 case R_PPC64_TOC16_LO_DS
:
9701 rel
->r_info
= ELF64_R_INFO (tsym
, R_PPC64_LO_DS_OPT
);
9705 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9707 info
->callbacks
->einfo
9708 /* xgettext:c-format */
9709 (_("%H: %s references "
9710 "optimized away TOC entry\n"),
9711 ibfd
, sec
, rel
->r_offset
,
9712 ppc64_elf_howto_table
[r_type
]->name
);
9713 bfd_set_error (bfd_error_bad_value
);
9716 rel
->r_addend
= tocrel
->r_addend
;
9717 elf_section_data (sec
)->relocs
= relstart
;
9721 if (h
!= NULL
|| sym
->st_value
!= 0)
9724 rel
->r_addend
-= skip
[val
>> 3];
9725 elf_section_data (sec
)->relocs
= relstart
;
9728 if (elf_section_data (sec
)->relocs
!= relstart
)
9732 /* We shouldn't have local or global symbols defined in the TOC,
9733 but handle them anyway. */
9734 if (local_syms
!= NULL
)
9735 for (sym
= local_syms
;
9736 sym
< local_syms
+ symtab_hdr
->sh_info
;
9738 if (sym
->st_value
!= 0
9739 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
9743 if (sym
->st_value
> toc
->rawsize
)
9744 i
= toc
->rawsize
>> 3;
9746 i
= sym
->st_value
>> 3;
9748 if ((skip
[i
] & (ref_from_discarded
| can_optimize
)) != 0)
9752 (_("%s defined on removed toc entry"),
9753 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
, NULL
));
9756 while ((skip
[i
] & (ref_from_discarded
| can_optimize
)));
9757 sym
->st_value
= (bfd_vma
) i
<< 3;
9760 sym
->st_value
-= skip
[i
];
9761 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9764 /* Adjust any global syms defined in this toc input section. */
9765 if (toc_inf
.global_toc_syms
)
9768 toc_inf
.skip
= skip
;
9769 toc_inf
.global_toc_syms
= FALSE
;
9770 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
9774 if (toc
->reloc_count
!= 0)
9776 Elf_Internal_Shdr
*rel_hdr
;
9777 Elf_Internal_Rela
*wrel
;
9780 /* Remove unused toc relocs, and adjust those we keep. */
9781 if (toc_relocs
== NULL
)
9782 toc_relocs
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
9784 if (toc_relocs
== NULL
)
9788 for (rel
= toc_relocs
; rel
< toc_relocs
+ toc
->reloc_count
; ++rel
)
9789 if ((skip
[rel
->r_offset
>> 3]
9790 & (ref_from_discarded
| can_optimize
)) == 0)
9792 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
9793 wrel
->r_info
= rel
->r_info
;
9794 wrel
->r_addend
= rel
->r_addend
;
9797 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
9798 &local_syms
, NULL
, NULL
))
9801 elf_section_data (toc
)->relocs
= toc_relocs
;
9802 toc
->reloc_count
= wrel
- toc_relocs
;
9803 rel_hdr
= _bfd_elf_single_rel_hdr (toc
);
9804 sz
= rel_hdr
->sh_entsize
;
9805 rel_hdr
->sh_size
= toc
->reloc_count
* sz
;
9808 else if (toc_relocs
!= NULL
9809 && elf_section_data (toc
)->relocs
!= toc_relocs
)
9812 if (local_syms
!= NULL
9813 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9815 if (!info
->keep_memory
)
9818 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9826 /* Return true iff input section I references the TOC using
9827 instructions limited to +/-32k offsets. */
9830 ppc64_elf_has_small_toc_reloc (asection
*i
)
9832 return (is_ppc64_elf (i
->owner
)
9833 && ppc64_elf_tdata (i
->owner
)->has_small_toc_reloc
);
9836 /* Allocate space for one GOT entry. */
9839 allocate_got (struct elf_link_hash_entry
*h
,
9840 struct bfd_link_info
*info
,
9841 struct got_entry
*gent
)
9843 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9844 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
9845 int entsize
= (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)
9847 int rentsize
= (gent
->tls_type
& eh
->tls_mask
& TLS_GD
9848 ? 2 : 1) * sizeof (Elf64_External_Rela
);
9849 asection
*got
= ppc64_elf_tdata (gent
->owner
)->got
;
9851 gent
->got
.offset
= got
->size
;
9852 got
->size
+= entsize
;
9854 if (h
->type
== STT_GNU_IFUNC
)
9856 htab
->elf
.irelplt
->size
+= rentsize
;
9857 htab
->got_reli_size
+= rentsize
;
9859 else if (((bfd_link_pic (info
)
9860 && !((gent
->tls_type
& TLS_TPREL
) != 0
9861 && bfd_link_executable (info
)
9862 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
9863 || (htab
->elf
.dynamic_sections_created
9865 && !SYMBOL_REFERENCES_LOCAL (info
, h
)))
9866 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
9868 asection
*relgot
= ppc64_elf_tdata (gent
->owner
)->relgot
;
9869 relgot
->size
+= rentsize
;
9873 /* This function merges got entries in the same toc group. */
9876 merge_got_entries (struct got_entry
**pent
)
9878 struct got_entry
*ent
, *ent2
;
9880 for (ent
= *pent
; ent
!= NULL
; ent
= ent
->next
)
9881 if (!ent
->is_indirect
)
9882 for (ent2
= ent
->next
; ent2
!= NULL
; ent2
= ent2
->next
)
9883 if (!ent2
->is_indirect
9884 && ent2
->addend
== ent
->addend
9885 && ent2
->tls_type
== ent
->tls_type
9886 && elf_gp (ent2
->owner
) == elf_gp (ent
->owner
))
9888 ent2
->is_indirect
= TRUE
;
9889 ent2
->got
.ent
= ent
;
9893 /* If H is undefined, make it dynamic if that makes sense. */
9896 ensure_undef_dynamic (struct bfd_link_info
*info
,
9897 struct elf_link_hash_entry
*h
)
9899 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
9901 if (htab
->dynamic_sections_created
9902 && ((info
->dynamic_undefined_weak
!= 0
9903 && h
->root
.type
== bfd_link_hash_undefweak
)
9904 || h
->root
.type
== bfd_link_hash_undefined
)
9907 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
9908 return bfd_elf_link_record_dynamic_symbol (info
, h
);
9912 /* Allocate space in .plt, .got and associated reloc sections for
9916 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
9918 struct bfd_link_info
*info
;
9919 struct ppc_link_hash_table
*htab
;
9921 struct ppc_link_hash_entry
*eh
;
9922 struct got_entry
**pgent
, *gent
;
9924 if (h
->root
.type
== bfd_link_hash_indirect
)
9927 info
= (struct bfd_link_info
*) inf
;
9928 htab
= ppc_hash_table (info
);
9932 eh
= (struct ppc_link_hash_entry
*) h
;
9933 /* Run through the TLS GD got entries first if we're changing them
9935 if ((eh
->tls_mask
& (TLS_TLS
| TLS_TPRELGD
)) == (TLS_TLS
| TLS_TPRELGD
))
9936 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9937 if (gent
->got
.refcount
> 0
9938 && (gent
->tls_type
& TLS_GD
) != 0)
9940 /* This was a GD entry that has been converted to TPREL. If
9941 there happens to be a TPREL entry we can use that one. */
9942 struct got_entry
*ent
;
9943 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
9944 if (ent
->got
.refcount
> 0
9945 && (ent
->tls_type
& TLS_TPREL
) != 0
9946 && ent
->addend
== gent
->addend
9947 && ent
->owner
== gent
->owner
)
9949 gent
->got
.refcount
= 0;
9953 /* If not, then we'll be using our own TPREL entry. */
9954 if (gent
->got
.refcount
!= 0)
9955 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
9958 /* Remove any list entry that won't generate a word in the GOT before
9959 we call merge_got_entries. Otherwise we risk merging to empty
9961 pgent
= &h
->got
.glist
;
9962 while ((gent
= *pgent
) != NULL
)
9963 if (gent
->got
.refcount
> 0)
9965 if ((gent
->tls_type
& TLS_LD
) != 0
9968 ppc64_tlsld_got (gent
->owner
)->got
.refcount
+= 1;
9969 *pgent
= gent
->next
;
9972 pgent
= &gent
->next
;
9975 *pgent
= gent
->next
;
9977 if (!htab
->do_multi_toc
)
9978 merge_got_entries (&h
->got
.glist
);
9980 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
9981 if (!gent
->is_indirect
)
9983 /* Make sure this symbol is output as a dynamic symbol. */
9984 if (!ensure_undef_dynamic (info
, h
))
9987 if (!is_ppc64_elf (gent
->owner
))
9990 allocate_got (h
, info
, gent
);
9993 /* If no dynamic sections we can't have dynamic relocs, except for
9994 IFUNCs which are handled even in static executables. */
9995 if (!htab
->elf
.dynamic_sections_created
9996 && h
->type
!= STT_GNU_IFUNC
)
9997 eh
->dyn_relocs
= NULL
;
9999 /* Discard relocs on undefined symbols that must be local. */
10000 else if (h
->root
.type
== bfd_link_hash_undefined
10001 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
10002 eh
->dyn_relocs
= NULL
;
10004 /* Also discard relocs on undefined weak syms with non-default
10005 visibility, or when dynamic_undefined_weak says so. */
10006 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
10007 eh
->dyn_relocs
= NULL
;
10009 if (eh
->dyn_relocs
!= NULL
)
10011 struct elf_dyn_relocs
*p
, **pp
;
10013 /* In the shared -Bsymbolic case, discard space allocated for
10014 dynamic pc-relative relocs against symbols which turn out to
10015 be defined in regular objects. For the normal shared case,
10016 discard space for relocs that have become local due to symbol
10017 visibility changes. */
10019 if (bfd_link_pic (info
))
10021 /* Relocs that use pc_count are those that appear on a call
10022 insn, or certain REL relocs (see must_be_dyn_reloc) that
10023 can be generated via assembly. We want calls to
10024 protected symbols to resolve directly to the function
10025 rather than going via the plt. If people want function
10026 pointer comparisons to work as expected then they should
10027 avoid writing weird assembly. */
10028 if (SYMBOL_CALLS_LOCAL (info
, h
))
10030 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
10032 p
->count
-= p
->pc_count
;
10041 if (eh
->dyn_relocs
!= NULL
)
10043 /* Make sure this symbol is output as a dynamic symbol. */
10044 if (!ensure_undef_dynamic (info
, h
))
10048 else if (ELIMINATE_COPY_RELOCS
&& h
->type
!= STT_GNU_IFUNC
)
10050 /* For the non-pic case, discard space for relocs against
10051 symbols which turn out to need copy relocs or are not
10053 if (h
->dynamic_adjusted
10055 && !ELF_COMMON_DEF_P (h
))
10057 /* Make sure this symbol is output as a dynamic symbol. */
10058 if (!ensure_undef_dynamic (info
, h
))
10061 if (h
->dynindx
== -1)
10062 eh
->dyn_relocs
= NULL
;
10065 eh
->dyn_relocs
= NULL
;
10068 /* Finally, allocate space. */
10069 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
10071 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
10072 if (eh
->elf
.type
== STT_GNU_IFUNC
)
10073 sreloc
= htab
->elf
.irelplt
;
10074 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10078 /* We might need a PLT entry when the symbol
10081 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
10082 d) has plt16 relocs and we are linking statically. */
10083 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
10084 || h
->type
== STT_GNU_IFUNC
10085 || (h
->needs_plt
&& h
->dynamic_adjusted
)
10088 && !htab
->elf
.dynamic_sections_created
10089 && !htab
->can_convert_all_inline_plt
10090 && (((struct ppc_link_hash_entry
*) h
)->tls_mask
10091 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
10093 struct plt_entry
*pent
;
10094 bfd_boolean doneone
= FALSE
;
10095 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10096 if (pent
->plt
.refcount
> 0)
10098 if (!htab
->elf
.dynamic_sections_created
10099 || h
->dynindx
== -1)
10101 if (h
->type
== STT_GNU_IFUNC
)
10103 s
= htab
->elf
.iplt
;
10104 pent
->plt
.offset
= s
->size
;
10105 s
->size
+= PLT_ENTRY_SIZE (htab
);
10106 s
= htab
->elf
.irelplt
;
10110 s
= htab
->pltlocal
;
10111 pent
->plt
.offset
= s
->size
;
10112 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10113 s
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
10118 /* If this is the first .plt entry, make room for the special
10120 s
= htab
->elf
.splt
;
10122 s
->size
+= PLT_INITIAL_ENTRY_SIZE (htab
);
10124 pent
->plt
.offset
= s
->size
;
10126 /* Make room for this entry. */
10127 s
->size
+= PLT_ENTRY_SIZE (htab
);
10129 /* Make room for the .glink code. */
10132 s
->size
+= GLINK_PLTRESOLVE_SIZE (htab
);
10135 /* We need bigger stubs past index 32767. */
10136 if (s
->size
>= GLINK_PLTRESOLVE_SIZE (htab
) + 32768*2*4)
10143 /* We also need to make an entry in the .rela.plt section. */
10144 s
= htab
->elf
.srelplt
;
10147 s
->size
+= sizeof (Elf64_External_Rela
);
10151 pent
->plt
.offset
= (bfd_vma
) -1;
10154 h
->plt
.plist
= NULL
;
10160 h
->plt
.plist
= NULL
;
10167 #define PPC_LO(v) ((v) & 0xffff)
10168 #define PPC_HI(v) (((v) >> 16) & 0xffff)
10169 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
10171 /* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
10172 to set up space for global entry stubs. These are put in glink,
10173 after the branch table. */
10176 size_global_entry_stubs (struct elf_link_hash_entry
*h
, void *inf
)
10178 struct bfd_link_info
*info
;
10179 struct ppc_link_hash_table
*htab
;
10180 struct plt_entry
*pent
;
10183 if (h
->root
.type
== bfd_link_hash_indirect
)
10186 if (!h
->pointer_equality_needed
)
10189 if (h
->def_regular
)
10193 htab
= ppc_hash_table (info
);
10197 s
= htab
->global_entry
;
10198 plt
= htab
->elf
.splt
;
10199 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
10200 if (pent
->plt
.offset
!= (bfd_vma
) -1
10201 && pent
->addend
== 0)
10203 /* For ELFv2, if this symbol is not defined in a regular file
10204 and we are not generating a shared library or pie, then we
10205 need to define the symbol in the executable on a call stub.
10206 This is to avoid text relocations. */
10207 bfd_vma off
, stub_align
, stub_off
, stub_size
;
10208 unsigned int align_power
;
10211 stub_off
= s
->size
;
10212 if (htab
->params
->plt_stub_align
>= 0)
10213 align_power
= htab
->params
->plt_stub_align
;
10215 align_power
= -htab
->params
->plt_stub_align
;
10216 /* Setting section alignment is delayed until we know it is
10217 non-empty. Otherwise the .text output section will be
10218 aligned at least to plt_stub_align even when no global
10219 entry stubs are needed. */
10220 if (s
->alignment_power
< align_power
)
10221 s
->alignment_power
= align_power
;
10222 stub_align
= (bfd_vma
) 1 << align_power
;
10223 if (htab
->params
->plt_stub_align
>= 0
10224 || ((((stub_off
+ stub_size
- 1) & -stub_align
)
10225 - (stub_off
& -stub_align
))
10226 > ((stub_size
- 1) & -stub_align
)))
10227 stub_off
= (stub_off
+ stub_align
- 1) & -stub_align
;
10228 off
= pent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
10229 off
-= stub_off
+ s
->output_offset
+ s
->output_section
->vma
;
10230 /* Note that for --plt-stub-align negative we have a possible
10231 dependency between stub offset and size. Break that
10232 dependency by assuming the max stub size when calculating
10233 the stub offset. */
10234 if (PPC_HA (off
) == 0)
10236 h
->root
.type
= bfd_link_hash_defined
;
10237 h
->root
.u
.def
.section
= s
;
10238 h
->root
.u
.def
.value
= stub_off
;
10239 s
->size
= stub_off
+ stub_size
;
10245 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
10246 read-only sections. */
10249 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
10253 if (h
->root
.type
== bfd_link_hash_indirect
)
10256 sec
= readonly_dynrelocs (h
);
10259 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
10261 info
->flags
|= DF_TEXTREL
;
10262 info
->callbacks
->minfo
10263 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
10264 sec
->owner
, h
->root
.root
.string
, sec
);
10266 /* Not an error, just cut short the traversal. */
10272 /* Set the sizes of the dynamic sections. */
10275 ppc64_elf_size_dynamic_sections (bfd
*output_bfd
,
10276 struct bfd_link_info
*info
)
10278 struct ppc_link_hash_table
*htab
;
10281 bfd_boolean relocs
;
10283 struct got_entry
*first_tlsld
;
10285 htab
= ppc_hash_table (info
);
10289 dynobj
= htab
->elf
.dynobj
;
10290 if (dynobj
== NULL
)
10293 if (htab
->elf
.dynamic_sections_created
)
10295 /* Set the contents of the .interp section to the interpreter. */
10296 if (bfd_link_executable (info
) && !info
->nointerp
)
10298 s
= bfd_get_linker_section (dynobj
, ".interp");
10301 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
10302 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
10306 /* Set up .got offsets for local syms, and space for local dynamic
10308 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10310 struct got_entry
**lgot_ents
;
10311 struct got_entry
**end_lgot_ents
;
10312 struct plt_entry
**local_plt
;
10313 struct plt_entry
**end_local_plt
;
10314 unsigned char *lgot_masks
;
10315 bfd_size_type locsymcount
;
10316 Elf_Internal_Shdr
*symtab_hdr
;
10318 if (!is_ppc64_elf (ibfd
))
10321 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
10323 struct ppc_dyn_relocs
*p
;
10325 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
10327 if (!bfd_is_abs_section (p
->sec
)
10328 && bfd_is_abs_section (p
->sec
->output_section
))
10330 /* Input section has been discarded, either because
10331 it is a copy of a linkonce section or due to
10332 linker script /DISCARD/, so we'll be discarding
10335 else if (p
->count
!= 0)
10337 asection
*srel
= elf_section_data (p
->sec
)->sreloc
;
10339 srel
= htab
->elf
.irelplt
;
10340 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
10341 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
10342 info
->flags
|= DF_TEXTREL
;
10347 lgot_ents
= elf_local_got_ents (ibfd
);
10351 symtab_hdr
= &elf_symtab_hdr (ibfd
);
10352 locsymcount
= symtab_hdr
->sh_info
;
10353 end_lgot_ents
= lgot_ents
+ locsymcount
;
10354 local_plt
= (struct plt_entry
**) end_lgot_ents
;
10355 end_local_plt
= local_plt
+ locsymcount
;
10356 lgot_masks
= (unsigned char *) end_local_plt
;
10357 s
= ppc64_elf_tdata (ibfd
)->got
;
10358 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
10360 struct got_entry
**pent
, *ent
;
10363 while ((ent
= *pent
) != NULL
)
10364 if (ent
->got
.refcount
> 0)
10366 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
10368 ppc64_tlsld_got (ibfd
)->got
.refcount
+= 1;
10373 unsigned int ent_size
= 8;
10374 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
10376 ent
->got
.offset
= s
->size
;
10377 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
10382 s
->size
+= ent_size
;
10383 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10385 htab
->elf
.irelplt
->size
+= rel_size
;
10386 htab
->got_reli_size
+= rel_size
;
10388 else if (bfd_link_pic (info
)
10389 && !((ent
->tls_type
& TLS_TPREL
) != 0
10390 && bfd_link_executable (info
)))
10392 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10393 srel
->size
+= rel_size
;
10402 /* Allocate space for plt calls to local syms. */
10403 lgot_masks
= (unsigned char *) end_local_plt
;
10404 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
10406 struct plt_entry
*ent
;
10408 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
10409 if (ent
->plt
.refcount
> 0)
10411 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
10413 s
= htab
->elf
.iplt
;
10414 ent
->plt
.offset
= s
->size
;
10415 s
->size
+= PLT_ENTRY_SIZE (htab
);
10416 htab
->elf
.irelplt
->size
+= sizeof (Elf64_External_Rela
);
10418 else if (htab
->can_convert_all_inline_plt
10419 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
10420 ent
->plt
.offset
= (bfd_vma
) -1;
10423 s
= htab
->pltlocal
;
10424 ent
->plt
.offset
= s
->size
;
10425 s
->size
+= LOCAL_PLT_ENTRY_SIZE (htab
);
10426 if (bfd_link_pic (info
))
10427 htab
->relpltlocal
->size
+= sizeof (Elf64_External_Rela
);
10431 ent
->plt
.offset
= (bfd_vma
) -1;
10435 /* Allocate global sym .plt and .got entries, and space for global
10436 sym dynamic relocs. */
10437 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
10439 if (!htab
->opd_abi
&& !bfd_link_pic (info
))
10440 elf_link_hash_traverse (&htab
->elf
, size_global_entry_stubs
, info
);
10442 first_tlsld
= NULL
;
10443 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10445 struct got_entry
*ent
;
10447 if (!is_ppc64_elf (ibfd
))
10450 ent
= ppc64_tlsld_got (ibfd
);
10451 if (ent
->got
.refcount
> 0)
10453 if (!htab
->do_multi_toc
&& first_tlsld
!= NULL
)
10455 ent
->is_indirect
= TRUE
;
10456 ent
->got
.ent
= first_tlsld
;
10460 if (first_tlsld
== NULL
)
10462 s
= ppc64_elf_tdata (ibfd
)->got
;
10463 ent
->got
.offset
= s
->size
;
10466 if (bfd_link_pic (info
))
10468 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
10469 srel
->size
+= sizeof (Elf64_External_Rela
);
10474 ent
->got
.offset
= (bfd_vma
) -1;
10477 /* We now have determined the sizes of the various dynamic sections.
10478 Allocate memory for them. */
10480 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
10482 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
10485 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
10486 /* These haven't been allocated yet; don't strip. */
10488 else if (s
== htab
->elf
.sgot
10489 || s
== htab
->elf
.splt
10490 || s
== htab
->elf
.iplt
10491 || s
== htab
->pltlocal
10492 || s
== htab
->glink
10493 || s
== htab
->global_entry
10494 || s
== htab
->elf
.sdynbss
10495 || s
== htab
->elf
.sdynrelro
)
10497 /* Strip this section if we don't need it; see the
10500 else if (s
== htab
->glink_eh_frame
)
10502 if (!bfd_is_abs_section (s
->output_section
))
10503 /* Not sized yet. */
10506 else if (CONST_STRNEQ (s
->name
, ".rela"))
10510 if (s
!= htab
->elf
.srelplt
)
10513 /* We use the reloc_count field as a counter if we need
10514 to copy relocs into the output file. */
10515 s
->reloc_count
= 0;
10520 /* It's not one of our sections, so don't allocate space. */
10526 /* If we don't need this section, strip it from the
10527 output file. This is mostly to handle .rela.bss and
10528 .rela.plt. We must create both sections in
10529 create_dynamic_sections, because they must be created
10530 before the linker maps input sections to output
10531 sections. The linker does that before
10532 adjust_dynamic_symbol is called, and it is that
10533 function which decides whether anything needs to go
10534 into these sections. */
10535 s
->flags
|= SEC_EXCLUDE
;
10539 if (bfd_is_abs_section (s
->output_section
))
10540 _bfd_error_handler (_("warning: discarding dynamic section %s"),
10543 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
10546 /* Allocate memory for the section contents. We use bfd_zalloc
10547 here in case unused entries are not reclaimed before the
10548 section's contents are written out. This should not happen,
10549 but this way if it does we get a R_PPC64_NONE reloc in .rela
10550 sections instead of garbage.
10551 We also rely on the section contents being zero when writing
10552 the GOT and .dynrelro. */
10553 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
10554 if (s
->contents
== NULL
)
10558 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
10560 if (!is_ppc64_elf (ibfd
))
10563 s
= ppc64_elf_tdata (ibfd
)->got
;
10564 if (s
!= NULL
&& s
!= htab
->elf
.sgot
)
10567 s
->flags
|= SEC_EXCLUDE
;
10570 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10571 if (s
->contents
== NULL
)
10575 s
= ppc64_elf_tdata (ibfd
)->relgot
;
10579 s
->flags
|= SEC_EXCLUDE
;
10582 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
10583 if (s
->contents
== NULL
)
10586 s
->reloc_count
= 0;
10591 if (htab
->elf
.dynamic_sections_created
)
10593 bfd_boolean tls_opt
;
10595 /* Add some entries to the .dynamic section. We fill in the
10596 values later, in ppc64_elf_finish_dynamic_sections, but we
10597 must add the entries now so that we get the correct size for
10598 the .dynamic section. The DT_DEBUG entry is filled in by the
10599 dynamic linker and used by the debugger. */
10600 #define add_dynamic_entry(TAG, VAL) \
10601 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10603 if (bfd_link_executable (info
))
10605 if (!add_dynamic_entry (DT_DEBUG
, 0))
10609 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0)
10611 if (!add_dynamic_entry (DT_PLTGOT
, 0)
10612 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
10613 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
10614 || !add_dynamic_entry (DT_JMPREL
, 0)
10615 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
10619 if (NO_OPD_RELOCS
&& abiversion (output_bfd
) <= 1)
10621 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
10622 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
10626 tls_opt
= (htab
->params
->tls_get_addr_opt
10627 && htab
->tls_get_addr_fd
!= NULL
10628 && htab
->tls_get_addr_fd
->elf
.plt
.plist
!= NULL
);
10629 if (tls_opt
|| !htab
->opd_abi
)
10631 if (!add_dynamic_entry (DT_PPC64_OPT
, tls_opt
? PPC64_OPT_TLS
: 0))
10637 if (!add_dynamic_entry (DT_RELA
, 0)
10638 || !add_dynamic_entry (DT_RELASZ
, 0)
10639 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
10642 /* If any dynamic relocs apply to a read-only section,
10643 then we need a DT_TEXTREL entry. */
10644 if ((info
->flags
& DF_TEXTREL
) == 0)
10645 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
10647 if ((info
->flags
& DF_TEXTREL
) != 0)
10649 if (!add_dynamic_entry (DT_TEXTREL
, 0))
10654 #undef add_dynamic_entry
10659 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
10662 ppc64_elf_hash_symbol (struct elf_link_hash_entry
*h
)
10664 if (h
->plt
.plist
!= NULL
10666 && !h
->pointer_equality_needed
)
10669 return _bfd_elf_hash_symbol (h
);
10672 /* Determine the type of stub needed, if any, for a call. */
10674 static inline enum ppc_stub_type
10675 ppc_type_of_stub (asection
*input_sec
,
10676 const Elf_Internal_Rela
*rel
,
10677 struct ppc_link_hash_entry
**hash
,
10678 struct plt_entry
**plt_ent
,
10679 bfd_vma destination
,
10680 unsigned long local_off
)
10682 struct ppc_link_hash_entry
*h
= *hash
;
10684 bfd_vma branch_offset
;
10685 bfd_vma max_branch_offset
;
10686 enum elf_ppc64_reloc_type r_type
;
10690 struct plt_entry
*ent
;
10691 struct ppc_link_hash_entry
*fdh
= h
;
10693 && h
->oh
->is_func_descriptor
)
10695 fdh
= ppc_follow_link (h
->oh
);
10699 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10700 if (ent
->addend
== rel
->r_addend
10701 && ent
->plt
.offset
!= (bfd_vma
) -1)
10704 return ppc_stub_plt_call
;
10707 /* Here, we know we don't have a plt entry. If we don't have a
10708 either a defined function descriptor or a defined entry symbol
10709 in a regular object file, then it is pointless trying to make
10710 any other type of stub. */
10711 if (!is_static_defined (&fdh
->elf
)
10712 && !is_static_defined (&h
->elf
))
10713 return ppc_stub_none
;
10715 else if (elf_local_got_ents (input_sec
->owner
) != NULL
)
10717 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (input_sec
->owner
);
10718 struct plt_entry
**local_plt
= (struct plt_entry
**)
10719 elf_local_got_ents (input_sec
->owner
) + symtab_hdr
->sh_info
;
10720 unsigned long r_symndx
= ELF64_R_SYM (rel
->r_info
);
10722 if (local_plt
[r_symndx
] != NULL
)
10724 struct plt_entry
*ent
;
10726 for (ent
= local_plt
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
10727 if (ent
->addend
== rel
->r_addend
10728 && ent
->plt
.offset
!= (bfd_vma
) -1)
10731 return ppc_stub_plt_call
;
10736 /* Determine where the call point is. */
10737 location
= (input_sec
->output_offset
10738 + input_sec
->output_section
->vma
10741 branch_offset
= destination
- location
;
10742 r_type
= ELF64_R_TYPE (rel
->r_info
);
10744 /* Determine if a long branch stub is needed. */
10745 max_branch_offset
= 1 << 25;
10746 if (r_type
== R_PPC64_REL14
10747 || r_type
== R_PPC64_REL14_BRTAKEN
10748 || r_type
== R_PPC64_REL14_BRNTAKEN
)
10749 max_branch_offset
= 1 << 15;
10751 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
- local_off
)
10752 /* We need a stub. Figure out whether a long_branch or plt_branch
10753 is needed later. */
10754 return ppc_stub_long_branch
;
10756 return ppc_stub_none
;
10759 /* With power7 weakly ordered memory model, it is possible for ld.so
10760 to update a plt entry in one thread and have another thread see a
10761 stale zero toc entry. To avoid this we need some sort of acquire
10762 barrier in the call stub. One solution is to make the load of the
10763 toc word seem to appear to depend on the load of the function entry
10764 word. Another solution is to test for r2 being zero, and branch to
10765 the appropriate glink entry if so.
10767 . fake dep barrier compare
10768 . ld 12,xxx(2) ld 12,xxx(2)
10769 . mtctr 12 mtctr 12
10770 . xor 11,12,12 ld 2,xxx+8(2)
10771 . add 2,2,11 cmpldi 2,0
10772 . ld 2,xxx+8(2) bnectr+
10773 . bctr b <glink_entry>
10775 The solution involving the compare turns out to be faster, so
10776 that's what we use unless the branch won't reach. */
10778 #define ALWAYS_USE_FAKE_DEP 0
10779 #define ALWAYS_EMIT_R2SAVE 0
10781 static inline unsigned int
10782 plt_stub_size (struct ppc_link_hash_table
*htab
,
10783 struct ppc_stub_hash_entry
*stub_entry
,
10786 unsigned size
= 12;
10788 if (ALWAYS_EMIT_R2SAVE
10789 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10791 if (PPC_HA (off
) != 0)
10796 if (htab
->params
->plt_static_chain
)
10798 if (htab
->params
->plt_thread_safe
10799 && htab
->elf
.dynamic_sections_created
10800 && stub_entry
->h
!= NULL
10801 && stub_entry
->h
->elf
.dynindx
!= -1)
10803 if (PPC_HA (off
+ 8 + 8 * htab
->params
->plt_static_chain
) != PPC_HA (off
))
10806 if (stub_entry
->h
!= NULL
10807 && (stub_entry
->h
== htab
->tls_get_addr_fd
10808 || stub_entry
->h
== htab
->tls_get_addr
)
10809 && htab
->params
->tls_get_addr_opt
)
10812 if (ALWAYS_EMIT_R2SAVE
10813 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10819 /* Depending on the sign of plt_stub_align:
10820 If positive, return the padding to align to a 2**plt_stub_align
10822 If negative, if this stub would cross fewer 2**plt_stub_align
10823 boundaries if we align, then return the padding needed to do so. */
10825 static inline unsigned int
10826 plt_stub_pad (struct ppc_link_hash_table
*htab
,
10827 struct ppc_stub_hash_entry
*stub_entry
,
10831 unsigned stub_size
= plt_stub_size (htab
, stub_entry
, plt_off
);
10832 bfd_vma stub_off
= stub_entry
->group
->stub_sec
->size
;
10834 if (htab
->params
->plt_stub_align
>= 0)
10836 stub_align
= 1 << htab
->params
->plt_stub_align
;
10837 if ((stub_off
& (stub_align
- 1)) != 0)
10838 return stub_align
- (stub_off
& (stub_align
- 1));
10842 stub_align
= 1 << -htab
->params
->plt_stub_align
;
10843 if (((stub_off
+ stub_size
- 1) & -stub_align
) - (stub_off
& -stub_align
)
10844 > ((stub_size
- 1) & -stub_align
))
10845 return stub_align
- (stub_off
& (stub_align
- 1));
10849 /* Build a .plt call stub. */
10851 static inline bfd_byte
*
10852 build_plt_stub (struct ppc_link_hash_table
*htab
,
10853 struct ppc_stub_hash_entry
*stub_entry
,
10854 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
10856 bfd
*obfd
= htab
->params
->stub_bfd
;
10857 bfd_boolean plt_load_toc
= htab
->opd_abi
;
10858 bfd_boolean plt_static_chain
= htab
->params
->plt_static_chain
;
10859 bfd_boolean plt_thread_safe
= (htab
->params
->plt_thread_safe
10860 && htab
->elf
.dynamic_sections_created
10861 && stub_entry
->h
!= NULL
10862 && stub_entry
->h
->elf
.dynindx
!= -1);
10863 bfd_boolean use_fake_dep
= plt_thread_safe
;
10864 bfd_vma cmp_branch_off
= 0;
10866 if (!ALWAYS_USE_FAKE_DEP
10869 && !((stub_entry
->h
== htab
->tls_get_addr_fd
10870 || stub_entry
->h
== htab
->tls_get_addr
)
10871 && htab
->params
->tls_get_addr_opt
))
10873 bfd_vma pltoff
= stub_entry
->plt_ent
->plt
.offset
& ~1;
10874 bfd_vma pltindex
= ((pltoff
- PLT_INITIAL_ENTRY_SIZE (htab
))
10875 / PLT_ENTRY_SIZE (htab
));
10876 bfd_vma glinkoff
= GLINK_PLTRESOLVE_SIZE (htab
) + pltindex
* 8;
10879 if (pltindex
> 32768)
10880 glinkoff
+= (pltindex
- 32768) * 4;
10882 + htab
->glink
->output_offset
10883 + htab
->glink
->output_section
->vma
);
10884 from
= (p
- stub_entry
->group
->stub_sec
->contents
10885 + 4 * (ALWAYS_EMIT_R2SAVE
10886 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10887 + 4 * (PPC_HA (offset
) != 0)
10888 + 4 * (PPC_HA (offset
+ 8 + 8 * plt_static_chain
)
10889 != PPC_HA (offset
))
10890 + 4 * (plt_static_chain
!= 0)
10892 + stub_entry
->group
->stub_sec
->output_offset
10893 + stub_entry
->group
->stub_sec
->output_section
->vma
);
10894 cmp_branch_off
= to
- from
;
10895 use_fake_dep
= cmp_branch_off
+ (1 << 25) >= (1 << 26);
10898 if (PPC_HA (offset
) != 0)
10902 if (ALWAYS_EMIT_R2SAVE
10903 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10904 r
[0].r_offset
+= 4;
10905 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
10906 r
[1].r_offset
= r
[0].r_offset
+ 4;
10907 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10908 r
[1].r_addend
= r
[0].r_addend
;
10911 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10913 r
[2].r_offset
= r
[1].r_offset
+ 4;
10914 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO
);
10915 r
[2].r_addend
= r
[0].r_addend
;
10919 r
[2].r_offset
= r
[1].r_offset
+ 8 + 8 * use_fake_dep
;
10920 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10921 r
[2].r_addend
= r
[0].r_addend
+ 8;
10922 if (plt_static_chain
)
10924 r
[3].r_offset
= r
[2].r_offset
+ 4;
10925 r
[3].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
10926 r
[3].r_addend
= r
[0].r_addend
+ 16;
10931 if (ALWAYS_EMIT_R2SAVE
10932 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10933 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10936 bfd_put_32 (obfd
, ADDIS_R11_R2
| PPC_HA (offset
), p
), p
+= 4;
10937 bfd_put_32 (obfd
, LD_R12_0R11
| PPC_LO (offset
), p
), p
+= 4;
10941 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
10942 bfd_put_32 (obfd
, LD_R12_0R12
| PPC_LO (offset
), p
), p
+= 4;
10945 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10947 bfd_put_32 (obfd
, ADDI_R11_R11
| PPC_LO (offset
), p
), p
+= 4;
10950 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
10955 bfd_put_32 (obfd
, XOR_R2_R12_R12
, p
), p
+= 4;
10956 bfd_put_32 (obfd
, ADD_R11_R11_R2
, p
), p
+= 4;
10958 bfd_put_32 (obfd
, LD_R2_0R11
| PPC_LO (offset
+ 8), p
), p
+= 4;
10959 if (plt_static_chain
)
10960 bfd_put_32 (obfd
, LD_R11_0R11
| PPC_LO (offset
+ 16), p
), p
+= 4;
10967 if (ALWAYS_EMIT_R2SAVE
10968 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10969 r
[0].r_offset
+= 4;
10970 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10973 if (PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
10975 r
[1].r_offset
= r
[0].r_offset
+ 4;
10976 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16
);
10977 r
[1].r_addend
= r
[0].r_addend
;
10981 r
[1].r_offset
= r
[0].r_offset
+ 8 + 8 * use_fake_dep
;
10982 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10983 r
[1].r_addend
= r
[0].r_addend
+ 8 + 8 * plt_static_chain
;
10984 if (plt_static_chain
)
10986 r
[2].r_offset
= r
[1].r_offset
+ 4;
10987 r
[2].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
10988 r
[2].r_addend
= r
[0].r_addend
+ 8;
10993 if (ALWAYS_EMIT_R2SAVE
10994 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
10995 bfd_put_32 (obfd
, STD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
10996 bfd_put_32 (obfd
, LD_R12_0R2
| PPC_LO (offset
), p
), p
+= 4;
10998 && PPC_HA (offset
+ 8 + 8 * plt_static_chain
) != PPC_HA (offset
))
11000 bfd_put_32 (obfd
, ADDI_R2_R2
| PPC_LO (offset
), p
), p
+= 4;
11003 bfd_put_32 (obfd
, MTCTR_R12
, p
), p
+= 4;
11008 bfd_put_32 (obfd
, XOR_R11_R12_R12
, p
), p
+= 4;
11009 bfd_put_32 (obfd
, ADD_R2_R2_R11
, p
), p
+= 4;
11011 if (plt_static_chain
)
11012 bfd_put_32 (obfd
, LD_R11_0R2
| PPC_LO (offset
+ 16), p
), p
+= 4;
11013 bfd_put_32 (obfd
, LD_R2_0R2
| PPC_LO (offset
+ 8), p
), p
+= 4;
11016 if (plt_load_toc
&& plt_thread_safe
&& !use_fake_dep
)
11018 bfd_put_32 (obfd
, CMPLDI_R2_0
, p
), p
+= 4;
11019 bfd_put_32 (obfd
, BNECTR_P4
, p
), p
+= 4;
11020 bfd_put_32 (obfd
, B_DOT
| (cmp_branch_off
& 0x3fffffc), p
), p
+= 4;
11023 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
11027 /* Build a special .plt call stub for __tls_get_addr. */
11029 #define LD_R11_0R3 0xe9630000
11030 #define LD_R12_0R3 0xe9830000
11031 #define MR_R0_R3 0x7c601b78
11032 #define CMPDI_R11_0 0x2c2b0000
11033 #define ADD_R3_R12_R13 0x7c6c6a14
11034 #define BEQLR 0x4d820020
11035 #define MR_R3_R0 0x7c030378
11036 #define STD_R11_0R1 0xf9610000
11037 #define BCTRL 0x4e800421
11038 #define LD_R11_0R1 0xe9610000
11039 #define MTLR_R11 0x7d6803a6
11041 static inline bfd_byte
*
11042 build_tls_get_addr_stub (struct ppc_link_hash_table
*htab
,
11043 struct ppc_stub_hash_entry
*stub_entry
,
11044 bfd_byte
*p
, bfd_vma offset
, Elf_Internal_Rela
*r
)
11046 bfd
*obfd
= htab
->params
->stub_bfd
;
11048 bfd_put_32 (obfd
, LD_R11_0R3
+ 0, p
), p
+= 4;
11049 bfd_put_32 (obfd
, LD_R12_0R3
+ 8, p
), p
+= 4;
11050 bfd_put_32 (obfd
, MR_R0_R3
, p
), p
+= 4;
11051 bfd_put_32 (obfd
, CMPDI_R11_0
, p
), p
+= 4;
11052 bfd_put_32 (obfd
, ADD_R3_R12_R13
, p
), p
+= 4;
11053 bfd_put_32 (obfd
, BEQLR
, p
), p
+= 4;
11054 bfd_put_32 (obfd
, MR_R3_R0
, p
), p
+= 4;
11056 r
[0].r_offset
+= 7 * 4;
11057 if (!ALWAYS_EMIT_R2SAVE
11058 && stub_entry
->stub_type
!= ppc_stub_plt_call_r2save
)
11059 return build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
11061 bfd_put_32 (obfd
, MFLR_R11
, p
), p
+= 4;
11062 bfd_put_32 (obfd
, STD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
11065 r
[0].r_offset
+= 2 * 4;
11066 p
= build_plt_stub (htab
, stub_entry
, p
, offset
, r
);
11067 bfd_put_32 (obfd
, BCTRL
, p
- 4);
11069 bfd_put_32 (obfd
, LD_R2_0R1
+ STK_TOC (htab
), p
), p
+= 4;
11070 bfd_put_32 (obfd
, LD_R11_0R1
+ STK_LINKER (htab
), p
), p
+= 4;
11071 bfd_put_32 (obfd
, MTLR_R11
, p
), p
+= 4;
11072 bfd_put_32 (obfd
, BLR
, p
), p
+= 4;
11077 static Elf_Internal_Rela
*
11078 get_relocs (asection
*sec
, int count
)
11080 Elf_Internal_Rela
*relocs
;
11081 struct bfd_elf_section_data
*elfsec_data
;
11083 elfsec_data
= elf_section_data (sec
);
11084 relocs
= elfsec_data
->relocs
;
11085 if (relocs
== NULL
)
11087 bfd_size_type relsize
;
11088 relsize
= sec
->reloc_count
* sizeof (*relocs
);
11089 relocs
= bfd_alloc (sec
->owner
, relsize
);
11090 if (relocs
== NULL
)
11092 elfsec_data
->relocs
= relocs
;
11093 elfsec_data
->rela
.hdr
= bfd_zalloc (sec
->owner
,
11094 sizeof (Elf_Internal_Shdr
));
11095 if (elfsec_data
->rela
.hdr
== NULL
)
11097 elfsec_data
->rela
.hdr
->sh_size
= (sec
->reloc_count
11098 * sizeof (Elf64_External_Rela
));
11099 elfsec_data
->rela
.hdr
->sh_entsize
= sizeof (Elf64_External_Rela
);
11100 sec
->reloc_count
= 0;
11102 relocs
+= sec
->reloc_count
;
11103 sec
->reloc_count
+= count
;
11108 get_r2off (struct bfd_link_info
*info
,
11109 struct ppc_stub_hash_entry
*stub_entry
)
11111 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11112 bfd_vma r2off
= htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
;
11116 /* Support linking -R objects. Get the toc pointer from the
11119 if (!htab
->opd_abi
)
11121 asection
*opd
= stub_entry
->h
->elf
.root
.u
.def
.section
;
11122 bfd_vma opd_off
= stub_entry
->h
->elf
.root
.u
.def
.value
;
11124 if (strcmp (opd
->name
, ".opd") != 0
11125 || opd
->reloc_count
!= 0)
11127 info
->callbacks
->einfo (_("%P: cannot find opd entry toc for `%pT'\n"),
11128 stub_entry
->h
->elf
.root
.root
.string
);
11129 bfd_set_error (bfd_error_bad_value
);
11130 return (bfd_vma
) -1;
11132 if (!bfd_get_section_contents (opd
->owner
, opd
, buf
, opd_off
+ 8, 8))
11133 return (bfd_vma
) -1;
11134 r2off
= bfd_get_64 (opd
->owner
, buf
);
11135 r2off
-= elf_gp (info
->output_bfd
);
11137 r2off
-= htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
;
11142 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11144 struct ppc_stub_hash_entry
*stub_entry
;
11145 struct ppc_branch_hash_entry
*br_entry
;
11146 struct bfd_link_info
*info
;
11147 struct ppc_link_hash_table
*htab
;
11151 Elf_Internal_Rela
*r
;
11154 /* Massage our args to the form they really have. */
11155 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11158 htab
= ppc_hash_table (info
);
11162 /* Make a note of the offset within the stubs for this entry. */
11163 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11164 loc
= stub_entry
->group
->stub_sec
->contents
+ stub_entry
->stub_offset
;
11166 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
11167 switch (stub_entry
->stub_type
)
11169 case ppc_stub_long_branch
:
11170 case ppc_stub_long_branch_r2off
:
11171 /* Branches are relative. This is where we are going to. */
11172 dest
= (stub_entry
->target_value
11173 + stub_entry
->target_section
->output_offset
11174 + stub_entry
->target_section
->output_section
->vma
);
11175 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11178 /* And this is where we are coming from. */
11179 off
-= (stub_entry
->stub_offset
11180 + stub_entry
->group
->stub_sec
->output_offset
11181 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11184 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11186 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11188 if (r2off
== (bfd_vma
) -1)
11190 htab
->stub_error
= TRUE
;
11193 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11195 if (PPC_HA (r2off
) != 0)
11197 bfd_put_32 (htab
->params
->stub_bfd
,
11198 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11201 if (PPC_LO (r2off
) != 0)
11203 bfd_put_32 (htab
->params
->stub_bfd
,
11204 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11209 bfd_put_32 (htab
->params
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), p
);
11212 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
11215 (_("long branch stub `%s' offset overflow"),
11216 stub_entry
->root
.string
);
11217 htab
->stub_error
= TRUE
;
11221 if (info
->emitrelocations
)
11223 r
= get_relocs (stub_entry
->group
->stub_sec
, 1);
11226 r
->r_offset
= p
- 4 - stub_entry
->group
->stub_sec
->contents
;
11227 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
11228 r
->r_addend
= dest
;
11229 if (stub_entry
->h
!= NULL
)
11231 struct elf_link_hash_entry
**hashes
;
11232 unsigned long symndx
;
11233 struct ppc_link_hash_entry
*h
;
11235 hashes
= elf_sym_hashes (htab
->params
->stub_bfd
);
11236 if (hashes
== NULL
)
11238 bfd_size_type hsize
;
11240 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
11241 hashes
= bfd_zalloc (htab
->params
->stub_bfd
, hsize
);
11242 if (hashes
== NULL
)
11244 elf_sym_hashes (htab
->params
->stub_bfd
) = hashes
;
11245 htab
->stub_globals
= 1;
11247 symndx
= htab
->stub_globals
++;
11249 hashes
[symndx
] = &h
->elf
;
11250 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
11251 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
11252 h
= ppc_follow_link (h
->oh
);
11253 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
11254 /* H is an opd symbol. The addend must be zero. */
11258 off
= (h
->elf
.root
.u
.def
.value
11259 + h
->elf
.root
.u
.def
.section
->output_offset
11260 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
11261 r
->r_addend
-= off
;
11267 case ppc_stub_plt_branch
:
11268 case ppc_stub_plt_branch_r2off
:
11269 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11270 stub_entry
->root
.string
+ 9,
11272 if (br_entry
== NULL
)
11274 _bfd_error_handler (_("can't find branch stub `%s'"),
11275 stub_entry
->root
.string
);
11276 htab
->stub_error
= TRUE
;
11280 dest
= (stub_entry
->target_value
11281 + stub_entry
->target_section
->output_offset
11282 + stub_entry
->target_section
->output_section
->vma
);
11283 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11284 dest
+= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11286 bfd_put_64 (htab
->brlt
->owner
, dest
,
11287 htab
->brlt
->contents
+ br_entry
->offset
);
11289 if (br_entry
->iter
== htab
->stub_iteration
)
11291 br_entry
->iter
= 0;
11293 if (htab
->relbrlt
!= NULL
)
11295 /* Create a reloc for the branch lookup table entry. */
11296 Elf_Internal_Rela rela
;
11299 rela
.r_offset
= (br_entry
->offset
11300 + htab
->brlt
->output_offset
11301 + htab
->brlt
->output_section
->vma
);
11302 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11303 rela
.r_addend
= dest
;
11305 rl
= htab
->relbrlt
->contents
;
11306 rl
+= (htab
->relbrlt
->reloc_count
++
11307 * sizeof (Elf64_External_Rela
));
11308 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
11310 else if (info
->emitrelocations
)
11312 r
= get_relocs (htab
->brlt
, 1);
11315 /* brlt, being SEC_LINKER_CREATED does not go through the
11316 normal reloc processing. Symbols and offsets are not
11317 translated from input file to output file form, so
11318 set up the offset per the output file. */
11319 r
->r_offset
= (br_entry
->offset
11320 + htab
->brlt
->output_offset
11321 + htab
->brlt
->output_section
->vma
);
11322 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
11323 r
->r_addend
= dest
;
11327 dest
= (br_entry
->offset
11328 + htab
->brlt
->output_offset
11329 + htab
->brlt
->output_section
->vma
);
11332 - elf_gp (info
->output_bfd
)
11333 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11335 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11337 info
->callbacks
->einfo
11338 (_("%P: linkage table error against `%pT'\n"),
11339 stub_entry
->root
.string
);
11340 bfd_set_error (bfd_error_bad_value
);
11341 htab
->stub_error
= TRUE
;
11345 if (info
->emitrelocations
)
11347 r
= get_relocs (stub_entry
->group
->stub_sec
, 1 + (PPC_HA (off
) != 0));
11350 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11351 if (bfd_big_endian (info
->output_bfd
))
11352 r
[0].r_offset
+= 2;
11353 if (stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
)
11354 r
[0].r_offset
+= 4;
11355 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_DS
);
11356 r
[0].r_addend
= dest
;
11357 if (PPC_HA (off
) != 0)
11359 r
[0].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_HA
);
11360 r
[1].r_offset
= r
[0].r_offset
+ 4;
11361 r
[1].r_info
= ELF64_R_INFO (0, R_PPC64_TOC16_LO_DS
);
11362 r
[1].r_addend
= r
[0].r_addend
;
11367 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11369 if (PPC_HA (off
) != 0)
11371 bfd_put_32 (htab
->params
->stub_bfd
,
11372 ADDIS_R12_R2
| PPC_HA (off
), p
);
11374 bfd_put_32 (htab
->params
->stub_bfd
,
11375 LD_R12_0R12
| PPC_LO (off
), p
);
11378 bfd_put_32 (htab
->params
->stub_bfd
,
11379 LD_R12_0R2
| PPC_LO (off
), p
);
11383 bfd_vma r2off
= get_r2off (info
, stub_entry
);
11385 if (r2off
== (bfd_vma
) -1)
11387 htab
->stub_error
= TRUE
;
11391 bfd_put_32 (htab
->params
->stub_bfd
, STD_R2_0R1
+ STK_TOC (htab
), p
);
11393 if (PPC_HA (off
) != 0)
11395 bfd_put_32 (htab
->params
->stub_bfd
,
11396 ADDIS_R12_R2
| PPC_HA (off
), p
);
11398 bfd_put_32 (htab
->params
->stub_bfd
,
11399 LD_R12_0R12
| PPC_LO (off
), p
);
11402 bfd_put_32 (htab
->params
->stub_bfd
, LD_R12_0R2
| PPC_LO (off
), p
);
11404 if (PPC_HA (r2off
) != 0)
11407 bfd_put_32 (htab
->params
->stub_bfd
,
11408 ADDIS_R2_R2
| PPC_HA (r2off
), p
);
11410 if (PPC_LO (r2off
) != 0)
11413 bfd_put_32 (htab
->params
->stub_bfd
,
11414 ADDI_R2_R2
| PPC_LO (r2off
), p
);
11418 bfd_put_32 (htab
->params
->stub_bfd
, MTCTR_R12
, p
);
11420 bfd_put_32 (htab
->params
->stub_bfd
, BCTR
, p
);
11424 case ppc_stub_plt_call
:
11425 case ppc_stub_plt_call_r2save
:
11426 if (stub_entry
->h
!= NULL
11427 && stub_entry
->h
->is_func_descriptor
11428 && stub_entry
->h
->oh
!= NULL
)
11430 struct ppc_link_hash_entry
*fh
= ppc_follow_link (stub_entry
->h
->oh
);
11432 /* If the old-ABI "dot-symbol" is undefined make it weak so
11433 we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL. */
11434 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
11435 && (stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11436 || stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defweak
))
11437 fh
->elf
.root
.type
= bfd_link_hash_undefweak
;
11440 /* Now build the stub. */
11441 dest
= stub_entry
->plt_ent
->plt
.offset
& ~1;
11442 if (dest
>= (bfd_vma
) -2)
11445 plt
= htab
->elf
.splt
;
11446 if (!htab
->elf
.dynamic_sections_created
11447 || stub_entry
->h
== NULL
11448 || stub_entry
->h
->elf
.dynindx
== -1)
11450 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11451 plt
= htab
->elf
.iplt
;
11453 plt
= htab
->pltlocal
;
11456 dest
+= plt
->output_offset
+ plt
->output_section
->vma
;
11459 - elf_gp (info
->output_bfd
)
11460 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11462 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
11464 info
->callbacks
->einfo
11465 /* xgettext:c-format */
11466 (_("%P: linkage table error against `%pT'\n"),
11467 stub_entry
->h
!= NULL
11468 ? stub_entry
->h
->elf
.root
.root
.string
11470 bfd_set_error (bfd_error_bad_value
);
11471 htab
->stub_error
= TRUE
;
11475 if (htab
->params
->plt_stub_align
!= 0)
11477 unsigned pad
= plt_stub_pad (htab
, stub_entry
, off
);
11479 stub_entry
->group
->stub_sec
->size
+= pad
;
11480 stub_entry
->stub_offset
= stub_entry
->group
->stub_sec
->size
;
11485 if (info
->emitrelocations
)
11487 r
= get_relocs (stub_entry
->group
->stub_sec
,
11488 ((PPC_HA (off
) != 0)
11490 ? 2 + (htab
->params
->plt_static_chain
11491 && PPC_HA (off
+ 16) == PPC_HA (off
))
11495 r
[0].r_offset
= loc
- stub_entry
->group
->stub_sec
->contents
;
11496 if (bfd_big_endian (info
->output_bfd
))
11497 r
[0].r_offset
+= 2;
11498 r
[0].r_addend
= dest
;
11500 if (stub_entry
->h
!= NULL
11501 && (stub_entry
->h
== htab
->tls_get_addr_fd
11502 || stub_entry
->h
== htab
->tls_get_addr
)
11503 && htab
->params
->tls_get_addr_opt
)
11504 p
= build_tls_get_addr_stub (htab
, stub_entry
, loc
, off
, r
);
11506 p
= build_plt_stub (htab
, stub_entry
, loc
, off
, r
);
11509 case ppc_stub_save_res
:
11517 stub_entry
->group
->stub_sec
->size
+= p
- loc
;
11519 if (htab
->params
->emit_stub_syms
)
11521 struct elf_link_hash_entry
*h
;
11524 const char *const stub_str
[] = { "long_branch",
11525 "long_branch_r2off",
11527 "plt_branch_r2off",
11531 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
11532 len2
= strlen (stub_entry
->root
.string
);
11533 name
= bfd_malloc (len1
+ len2
+ 2);
11536 memcpy (name
, stub_entry
->root
.string
, 9);
11537 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
11538 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
11539 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
11542 if (h
->root
.type
== bfd_link_hash_new
)
11544 h
->root
.type
= bfd_link_hash_defined
;
11545 h
->root
.u
.def
.section
= stub_entry
->group
->stub_sec
;
11546 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
11547 h
->ref_regular
= 1;
11548 h
->def_regular
= 1;
11549 h
->ref_regular_nonweak
= 1;
11550 h
->forced_local
= 1;
11552 h
->root
.linker_def
= 1;
11559 /* As above, but don't actually build the stub. Just bump offset so
11560 we know stub section sizes, and select plt_branch stubs where
11561 long_branch stubs won't do. */
11564 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
11566 struct ppc_stub_hash_entry
*stub_entry
;
11567 struct bfd_link_info
*info
;
11568 struct ppc_link_hash_table
*htab
;
11572 /* Massage our args to the form they really have. */
11573 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
11576 htab
= ppc_hash_table (info
);
11580 if (stub_entry
->h
!= NULL
11581 && stub_entry
->h
->save_res
11582 && stub_entry
->h
->elf
.root
.type
== bfd_link_hash_defined
11583 && stub_entry
->h
->elf
.root
.u
.def
.section
== htab
->sfpr
)
11585 /* Don't make stubs to out-of-line register save/restore
11586 functions. Instead, emit copies of the functions. */
11587 stub_entry
->group
->needs_save_res
= 1;
11588 stub_entry
->stub_type
= ppc_stub_save_res
;
11592 if (stub_entry
->stub_type
== ppc_stub_plt_call
11593 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
11596 off
= stub_entry
->plt_ent
->plt
.offset
& ~(bfd_vma
) 1;
11597 if (off
>= (bfd_vma
) -2)
11599 plt
= htab
->elf
.splt
;
11600 if (!htab
->elf
.dynamic_sections_created
11601 || stub_entry
->h
== NULL
11602 || stub_entry
->h
->elf
.dynindx
== -1)
11604 if (stub_entry
->symtype
== STT_GNU_IFUNC
)
11605 plt
= htab
->elf
.iplt
;
11607 plt
= htab
->pltlocal
;
11609 off
+= (plt
->output_offset
11610 + plt
->output_section
->vma
11611 - elf_gp (info
->output_bfd
)
11612 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11614 size
= plt_stub_size (htab
, stub_entry
, off
);
11615 if (stub_entry
->h
!= NULL
11616 && (stub_entry
->h
== htab
->tls_get_addr_fd
11617 || stub_entry
->h
== htab
->tls_get_addr
)
11618 && htab
->params
->tls_get_addr_opt
11619 && (ALWAYS_EMIT_R2SAVE
11620 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
11621 stub_entry
->group
->tls_get_addr_opt_bctrl
11622 = stub_entry
->group
->stub_sec
->size
+ size
- 5 * 4;
11624 if (htab
->params
->plt_stub_align
)
11625 size
+= plt_stub_pad (htab
, stub_entry
, off
);
11626 if (info
->emitrelocations
)
11628 stub_entry
->group
->stub_sec
->reloc_count
11629 += ((PPC_HA (off
) != 0)
11631 ? 2 + (htab
->params
->plt_static_chain
11632 && PPC_HA (off
+ 16) == PPC_HA (off
))
11634 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11639 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
11642 bfd_vma local_off
= 0;
11644 off
= (stub_entry
->target_value
11645 + stub_entry
->target_section
->output_offset
11646 + stub_entry
->target_section
->output_section
->vma
);
11647 off
-= (stub_entry
->group
->stub_sec
->size
11648 + stub_entry
->group
->stub_sec
->output_offset
11649 + stub_entry
->group
->stub_sec
->output_section
->vma
);
11651 /* Reset the stub type from the plt variant in case we now
11652 can reach with a shorter stub. */
11653 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
11654 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
11657 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
11659 r2off
= get_r2off (info
, stub_entry
);
11660 if (r2off
== (bfd_vma
) -1)
11662 htab
->stub_error
= TRUE
;
11666 if (PPC_HA (r2off
) != 0)
11668 if (PPC_LO (r2off
) != 0)
11673 local_off
= PPC64_LOCAL_ENTRY_OFFSET (stub_entry
->other
);
11675 /* If the branch offset is too big, use a ppc_stub_plt_branch.
11676 Do the same for -R objects without function descriptors. */
11677 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26) - local_off
11678 || (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
11680 && htab
->sec_info
[stub_entry
->target_section
->id
].toc_off
== 0))
11682 struct ppc_branch_hash_entry
*br_entry
;
11684 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
11685 stub_entry
->root
.string
+ 9,
11687 if (br_entry
== NULL
)
11689 _bfd_error_handler (_("can't build branch stub `%s'"),
11690 stub_entry
->root
.string
);
11691 htab
->stub_error
= TRUE
;
11695 if (br_entry
->iter
!= htab
->stub_iteration
)
11697 br_entry
->iter
= htab
->stub_iteration
;
11698 br_entry
->offset
= htab
->brlt
->size
;
11699 htab
->brlt
->size
+= 8;
11701 if (htab
->relbrlt
!= NULL
)
11702 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
11703 else if (info
->emitrelocations
)
11705 htab
->brlt
->reloc_count
+= 1;
11706 htab
->brlt
->flags
|= SEC_RELOC
;
11710 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
11711 off
= (br_entry
->offset
11712 + htab
->brlt
->output_offset
11713 + htab
->brlt
->output_section
->vma
11714 - elf_gp (info
->output_bfd
)
11715 - htab
->sec_info
[stub_entry
->group
->link_sec
->id
].toc_off
);
11717 if (info
->emitrelocations
)
11719 stub_entry
->group
->stub_sec
->reloc_count
11720 += 1 + (PPC_HA (off
) != 0);
11721 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11724 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
11727 if (PPC_HA (off
) != 0)
11733 if (PPC_HA (off
) != 0)
11736 if (PPC_HA (r2off
) != 0)
11738 if (PPC_LO (r2off
) != 0)
11742 else if (info
->emitrelocations
)
11744 stub_entry
->group
->stub_sec
->reloc_count
+= 1;
11745 stub_entry
->group
->stub_sec
->flags
|= SEC_RELOC
;
11749 stub_entry
->group
->stub_sec
->size
+= size
;
11753 /* Set up various things so that we can make a list of input sections
11754 for each output section included in the link. Returns -1 on error,
11755 0 when no stubs will be needed, and 1 on success. */
11758 ppc64_elf_setup_section_lists (struct bfd_link_info
*info
)
11762 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11767 htab
->sec_info_arr_size
= _bfd_section_id
;
11768 amt
= sizeof (*htab
->sec_info
) * (htab
->sec_info_arr_size
);
11769 htab
->sec_info
= bfd_zmalloc (amt
);
11770 if (htab
->sec_info
== NULL
)
11773 /* Set toc_off for com, und, abs and ind sections. */
11774 for (id
= 0; id
< 3; id
++)
11775 htab
->sec_info
[id
].toc_off
= TOC_BASE_OFF
;
11780 /* Set up for first pass at multitoc partitioning. */
11783 ppc64_elf_start_multitoc_partition (struct bfd_link_info
*info
)
11785 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11787 htab
->toc_curr
= ppc64_elf_set_toc (info
, info
->output_bfd
);
11788 htab
->toc_bfd
= NULL
;
11789 htab
->toc_first_sec
= NULL
;
11792 /* The linker repeatedly calls this function for each TOC input section
11793 and linker generated GOT section. Group input bfds such that the toc
11794 within a group is less than 64k in size. */
11797 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
11799 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11800 bfd_vma addr
, off
, limit
;
11805 if (!htab
->second_toc_pass
)
11807 /* Keep track of the first .toc or .got section for this input bfd. */
11808 bfd_boolean new_bfd
= htab
->toc_bfd
!= isec
->owner
;
11812 htab
->toc_bfd
= isec
->owner
;
11813 htab
->toc_first_sec
= isec
;
11816 addr
= isec
->output_offset
+ isec
->output_section
->vma
;
11817 off
= addr
- htab
->toc_curr
;
11818 limit
= 0x80008000;
11819 if (ppc64_elf_tdata (isec
->owner
)->has_small_toc_reloc
)
11821 if (off
+ isec
->size
> limit
)
11823 addr
= (htab
->toc_first_sec
->output_offset
11824 + htab
->toc_first_sec
->output_section
->vma
);
11825 htab
->toc_curr
= addr
;
11826 htab
->toc_curr
&= -TOC_BASE_ALIGN
;
11829 /* toc_curr is the base address of this toc group. Set elf_gp
11830 for the input section to be the offset relative to the
11831 output toc base plus 0x8000. Making the input elf_gp an
11832 offset allows us to move the toc as a whole without
11833 recalculating input elf_gp. */
11834 off
= htab
->toc_curr
- elf_gp (info
->output_bfd
);
11835 off
+= TOC_BASE_OFF
;
11837 /* Die if someone uses a linker script that doesn't keep input
11838 file .toc and .got together. */
11840 && elf_gp (isec
->owner
) != 0
11841 && elf_gp (isec
->owner
) != off
)
11844 elf_gp (isec
->owner
) = off
;
11848 /* During the second pass toc_first_sec points to the start of
11849 a toc group, and toc_curr is used to track the old elf_gp.
11850 We use toc_bfd to ensure we only look at each bfd once. */
11851 if (htab
->toc_bfd
== isec
->owner
)
11853 htab
->toc_bfd
= isec
->owner
;
11855 if (htab
->toc_first_sec
== NULL
11856 || htab
->toc_curr
!= elf_gp (isec
->owner
))
11858 htab
->toc_curr
= elf_gp (isec
->owner
);
11859 htab
->toc_first_sec
= isec
;
11861 addr
= (htab
->toc_first_sec
->output_offset
11862 + htab
->toc_first_sec
->output_section
->vma
);
11863 off
= addr
- elf_gp (info
->output_bfd
) + TOC_BASE_OFF
;
11864 elf_gp (isec
->owner
) = off
;
11869 /* Called via elf_link_hash_traverse to merge GOT entries for global
11873 merge_global_got (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
11875 if (h
->root
.type
== bfd_link_hash_indirect
)
11878 merge_got_entries (&h
->got
.glist
);
11883 /* Called via elf_link_hash_traverse to allocate GOT entries for global
11887 reallocate_got (struct elf_link_hash_entry
*h
, void *inf
)
11889 struct got_entry
*gent
;
11891 if (h
->root
.type
== bfd_link_hash_indirect
)
11894 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
11895 if (!gent
->is_indirect
)
11896 allocate_got (h
, (struct bfd_link_info
*) inf
, gent
);
11900 /* Called on the first multitoc pass after the last call to
11901 ppc64_elf_next_toc_section. This function removes duplicate GOT
11905 ppc64_elf_layout_multitoc (struct bfd_link_info
*info
)
11907 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
11908 struct bfd
*ibfd
, *ibfd2
;
11909 bfd_boolean done_something
;
11911 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (info
->output_bfd
);
11913 if (!htab
->do_multi_toc
)
11916 /* Merge global sym got entries within a toc group. */
11917 elf_link_hash_traverse (&htab
->elf
, merge_global_got
, info
);
11919 /* And tlsld_got. */
11920 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11922 struct got_entry
*ent
, *ent2
;
11924 if (!is_ppc64_elf (ibfd
))
11927 ent
= ppc64_tlsld_got (ibfd
);
11928 if (!ent
->is_indirect
11929 && ent
->got
.offset
!= (bfd_vma
) -1)
11931 for (ibfd2
= ibfd
->link
.next
; ibfd2
!= NULL
; ibfd2
= ibfd2
->link
.next
)
11933 if (!is_ppc64_elf (ibfd2
))
11936 ent2
= ppc64_tlsld_got (ibfd2
);
11937 if (!ent2
->is_indirect
11938 && ent2
->got
.offset
!= (bfd_vma
) -1
11939 && elf_gp (ibfd2
) == elf_gp (ibfd
))
11941 ent2
->is_indirect
= TRUE
;
11942 ent2
->got
.ent
= ent
;
11948 /* Zap sizes of got sections. */
11949 htab
->elf
.irelplt
->rawsize
= htab
->elf
.irelplt
->size
;
11950 htab
->elf
.irelplt
->size
-= htab
->got_reli_size
;
11951 htab
->got_reli_size
= 0;
11953 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11955 asection
*got
, *relgot
;
11957 if (!is_ppc64_elf (ibfd
))
11960 got
= ppc64_elf_tdata (ibfd
)->got
;
11963 got
->rawsize
= got
->size
;
11965 relgot
= ppc64_elf_tdata (ibfd
)->relgot
;
11966 relgot
->rawsize
= relgot
->size
;
11971 /* Now reallocate the got, local syms first. We don't need to
11972 allocate section contents again since we never increase size. */
11973 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
11975 struct got_entry
**lgot_ents
;
11976 struct got_entry
**end_lgot_ents
;
11977 struct plt_entry
**local_plt
;
11978 struct plt_entry
**end_local_plt
;
11979 unsigned char *lgot_masks
;
11980 bfd_size_type locsymcount
;
11981 Elf_Internal_Shdr
*symtab_hdr
;
11984 if (!is_ppc64_elf (ibfd
))
11987 lgot_ents
= elf_local_got_ents (ibfd
);
11991 symtab_hdr
= &elf_symtab_hdr (ibfd
);
11992 locsymcount
= symtab_hdr
->sh_info
;
11993 end_lgot_ents
= lgot_ents
+ locsymcount
;
11994 local_plt
= (struct plt_entry
**) end_lgot_ents
;
11995 end_local_plt
= local_plt
+ locsymcount
;
11996 lgot_masks
= (unsigned char *) end_local_plt
;
11997 s
= ppc64_elf_tdata (ibfd
)->got
;
11998 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
12000 struct got_entry
*ent
;
12002 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
12004 unsigned int ent_size
= 8;
12005 unsigned int rel_size
= sizeof (Elf64_External_Rela
);
12007 ent
->got
.offset
= s
->size
;
12008 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
12013 s
->size
+= ent_size
;
12014 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
12016 htab
->elf
.irelplt
->size
+= rel_size
;
12017 htab
->got_reli_size
+= rel_size
;
12019 else if (bfd_link_pic (info
)
12020 && !((ent
->tls_type
& TLS_TPREL
) != 0
12021 && bfd_link_executable (info
)))
12023 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12024 srel
->size
+= rel_size
;
12030 elf_link_hash_traverse (&htab
->elf
, reallocate_got
, info
);
12032 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12034 struct got_entry
*ent
;
12036 if (!is_ppc64_elf (ibfd
))
12039 ent
= ppc64_tlsld_got (ibfd
);
12040 if (!ent
->is_indirect
12041 && ent
->got
.offset
!= (bfd_vma
) -1)
12043 asection
*s
= ppc64_elf_tdata (ibfd
)->got
;
12044 ent
->got
.offset
= s
->size
;
12046 if (bfd_link_pic (info
))
12048 asection
*srel
= ppc64_elf_tdata (ibfd
)->relgot
;
12049 srel
->size
+= sizeof (Elf64_External_Rela
);
12054 done_something
= htab
->elf
.irelplt
->rawsize
!= htab
->elf
.irelplt
->size
;
12055 if (!done_something
)
12056 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
12060 if (!is_ppc64_elf (ibfd
))
12063 got
= ppc64_elf_tdata (ibfd
)->got
;
12066 done_something
= got
->rawsize
!= got
->size
;
12067 if (done_something
)
12072 if (done_something
)
12073 (*htab
->params
->layout_sections_again
) ();
12075 /* Set up for second pass over toc sections to recalculate elf_gp
12076 on input sections. */
12077 htab
->toc_bfd
= NULL
;
12078 htab
->toc_first_sec
= NULL
;
12079 htab
->second_toc_pass
= TRUE
;
12080 return done_something
;
12083 /* Called after second pass of multitoc partitioning. */
12086 ppc64_elf_finish_multitoc_partition (struct bfd_link_info
*info
)
12088 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12090 /* After the second pass, toc_curr tracks the TOC offset used
12091 for code sections below in ppc64_elf_next_input_section. */
12092 htab
->toc_curr
= TOC_BASE_OFF
;
12095 /* No toc references were found in ISEC. If the code in ISEC makes no
12096 calls, then there's no need to use toc adjusting stubs when branching
12097 into ISEC. Actually, indirect calls from ISEC are OK as they will
12098 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
12099 needed, and 2 if a cyclical call-graph was found but no other reason
12100 for a stub was detected. If called from the top level, a return of
12101 2 means the same as a return of 0. */
12104 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
12108 /* Mark this section as checked. */
12109 isec
->call_check_done
= 1;
12111 /* We know none of our code bearing sections will need toc stubs. */
12112 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
12115 if (isec
->size
== 0)
12118 if (isec
->output_section
== NULL
)
12122 if (isec
->reloc_count
!= 0)
12124 Elf_Internal_Rela
*relstart
, *rel
;
12125 Elf_Internal_Sym
*local_syms
;
12126 struct ppc_link_hash_table
*htab
;
12128 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
12129 info
->keep_memory
);
12130 if (relstart
== NULL
)
12133 /* Look for branches to outside of this section. */
12135 htab
= ppc_hash_table (info
);
12139 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
12141 enum elf_ppc64_reloc_type r_type
;
12142 unsigned long r_symndx
;
12143 struct elf_link_hash_entry
*h
;
12144 struct ppc_link_hash_entry
*eh
;
12145 Elf_Internal_Sym
*sym
;
12147 struct _opd_sec_data
*opd
;
12151 r_type
= ELF64_R_TYPE (rel
->r_info
);
12152 if (r_type
!= R_PPC64_REL24
12153 && r_type
!= R_PPC64_REL14
12154 && r_type
!= R_PPC64_REL14_BRTAKEN
12155 && r_type
!= R_PPC64_REL14_BRNTAKEN
12156 && r_type
!= R_PPC64_PLTCALL
)
12159 r_symndx
= ELF64_R_SYM (rel
->r_info
);
12160 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
12167 /* Calls to dynamic lib functions go through a plt call stub
12169 eh
= (struct ppc_link_hash_entry
*) h
;
12171 && (eh
->elf
.plt
.plist
!= NULL
12173 && ppc_follow_link (eh
->oh
)->elf
.plt
.plist
!= NULL
)))
12179 if (sym_sec
== NULL
)
12180 /* Ignore other undefined symbols. */
12183 /* Assume branches to other sections not included in the
12184 link need stubs too, to cover -R and absolute syms. */
12185 if (sym_sec
->output_section
== NULL
)
12192 sym_value
= sym
->st_value
;
12195 if (h
->root
.type
!= bfd_link_hash_defined
12196 && h
->root
.type
!= bfd_link_hash_defweak
)
12198 sym_value
= h
->root
.u
.def
.value
;
12200 sym_value
+= rel
->r_addend
;
12202 /* If this branch reloc uses an opd sym, find the code section. */
12203 opd
= get_opd_info (sym_sec
);
12206 if (h
== NULL
&& opd
->adjust
!= NULL
)
12210 adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12212 /* Assume deleted functions won't ever be called. */
12214 sym_value
+= adjust
;
12217 dest
= opd_entry_value (sym_sec
, sym_value
,
12218 &sym_sec
, NULL
, FALSE
);
12219 if (dest
== (bfd_vma
) -1)
12224 + sym_sec
->output_offset
12225 + sym_sec
->output_section
->vma
);
12227 /* Ignore branch to self. */
12228 if (sym_sec
== isec
)
12231 /* If the called function uses the toc, we need a stub. */
12232 if (sym_sec
->has_toc_reloc
12233 || sym_sec
->makes_toc_func_call
)
12239 /* Assume any branch that needs a long branch stub might in fact
12240 need a plt_branch stub. A plt_branch stub uses r2. */
12241 else if (dest
- (isec
->output_offset
12242 + isec
->output_section
->vma
12243 + rel
->r_offset
) + (1 << 25)
12244 >= (2u << 25) - PPC64_LOCAL_ENTRY_OFFSET (h
12252 /* If calling back to a section in the process of being
12253 tested, we can't say for sure that no toc adjusting stubs
12254 are needed, so don't return zero. */
12255 else if (sym_sec
->call_check_in_progress
)
12258 /* Branches to another section that itself doesn't have any TOC
12259 references are OK. Recursively call ourselves to check. */
12260 else if (!sym_sec
->call_check_done
)
12264 /* Mark current section as indeterminate, so that other
12265 sections that call back to current won't be marked as
12267 isec
->call_check_in_progress
= 1;
12268 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
12269 isec
->call_check_in_progress
= 0;
12280 if (local_syms
!= NULL
12281 && (elf_symtab_hdr (isec
->owner
).contents
12282 != (unsigned char *) local_syms
))
12284 if (elf_section_data (isec
)->relocs
!= relstart
)
12289 && isec
->map_head
.s
!= NULL
12290 && (strcmp (isec
->output_section
->name
, ".init") == 0
12291 || strcmp (isec
->output_section
->name
, ".fini") == 0))
12293 if (isec
->map_head
.s
->has_toc_reloc
12294 || isec
->map_head
.s
->makes_toc_func_call
)
12296 else if (!isec
->map_head
.s
->call_check_done
)
12299 isec
->call_check_in_progress
= 1;
12300 recur
= toc_adjusting_stub_needed (info
, isec
->map_head
.s
);
12301 isec
->call_check_in_progress
= 0;
12308 isec
->makes_toc_func_call
= 1;
12313 /* The linker repeatedly calls this function for each input section,
12314 in the order that input sections are linked into output sections.
12315 Build lists of input sections to determine groupings between which
12316 we may insert linker stubs. */
12319 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
12321 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12326 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
12327 && isec
->output_section
->id
< htab
->sec_info_arr_size
)
12329 /* This happens to make the list in reverse order,
12330 which is what we want. */
12331 htab
->sec_info
[isec
->id
].u
.list
12332 = htab
->sec_info
[isec
->output_section
->id
].u
.list
;
12333 htab
->sec_info
[isec
->output_section
->id
].u
.list
= isec
;
12336 if (htab
->multi_toc_needed
)
12338 /* Analyse sections that aren't already flagged as needing a
12339 valid toc pointer. Exclude .fixup for the linux kernel.
12340 .fixup contains branches, but only back to the function that
12341 hit an exception. */
12342 if (!(isec
->has_toc_reloc
12343 || (isec
->flags
& SEC_CODE
) == 0
12344 || strcmp (isec
->name
, ".fixup") == 0
12345 || isec
->call_check_done
))
12347 if (toc_adjusting_stub_needed (info
, isec
) < 0)
12350 /* Make all sections use the TOC assigned for this object file.
12351 This will be wrong for pasted sections; We fix that in
12352 check_pasted_section(). */
12353 if (elf_gp (isec
->owner
) != 0)
12354 htab
->toc_curr
= elf_gp (isec
->owner
);
12357 htab
->sec_info
[isec
->id
].toc_off
= htab
->toc_curr
;
12361 /* Check that all .init and .fini sections use the same toc, if they
12362 have toc relocs. */
12365 check_pasted_section (struct bfd_link_info
*info
, const char *name
)
12367 asection
*o
= bfd_get_section_by_name (info
->output_bfd
, name
);
12371 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12372 bfd_vma toc_off
= 0;
12375 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12376 if (i
->has_toc_reloc
)
12379 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12380 else if (toc_off
!= htab
->sec_info
[i
->id
].toc_off
)
12385 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12386 if (i
->makes_toc_func_call
)
12388 toc_off
= htab
->sec_info
[i
->id
].toc_off
;
12392 /* Make sure the whole pasted function uses the same toc offset. */
12394 for (i
= o
->map_head
.s
; i
!= NULL
; i
= i
->map_head
.s
)
12395 htab
->sec_info
[i
->id
].toc_off
= toc_off
;
12401 ppc64_elf_check_init_fini (struct bfd_link_info
*info
)
12403 return (check_pasted_section (info
, ".init")
12404 & check_pasted_section (info
, ".fini"));
12407 /* See whether we can group stub sections together. Grouping stub
12408 sections may result in fewer stubs. More importantly, we need to
12409 put all .init* and .fini* stubs at the beginning of the .init or
12410 .fini output sections respectively, because glibc splits the
12411 _init and _fini functions into multiple parts. Putting a stub in
12412 the middle of a function is not a good idea. */
12415 group_sections (struct bfd_link_info
*info
,
12416 bfd_size_type stub_group_size
,
12417 bfd_boolean stubs_always_before_branch
)
12419 struct ppc_link_hash_table
*htab
;
12421 bfd_boolean suppress_size_errors
;
12423 htab
= ppc_hash_table (info
);
12427 suppress_size_errors
= FALSE
;
12428 if (stub_group_size
== 1)
12430 /* Default values. */
12431 if (stubs_always_before_branch
)
12432 stub_group_size
= 0x1e00000;
12434 stub_group_size
= 0x1c00000;
12435 suppress_size_errors
= TRUE
;
12438 for (osec
= info
->output_bfd
->sections
; osec
!= NULL
; osec
= osec
->next
)
12442 if (osec
->id
>= htab
->sec_info_arr_size
)
12445 tail
= htab
->sec_info
[osec
->id
].u
.list
;
12446 while (tail
!= NULL
)
12450 bfd_size_type total
;
12451 bfd_boolean big_sec
;
12453 struct map_stub
*group
;
12454 bfd_size_type group_size
;
12457 total
= tail
->size
;
12458 group_size
= (ppc64_elf_section_data (tail
) != NULL
12459 && ppc64_elf_section_data (tail
)->has_14bit_branch
12460 ? stub_group_size
>> 10 : stub_group_size
);
12462 big_sec
= total
> group_size
;
12463 if (big_sec
&& !suppress_size_errors
)
12464 /* xgettext:c-format */
12465 _bfd_error_handler (_("%pB section %pA exceeds stub group size"),
12466 tail
->owner
, tail
);
12467 curr_toc
= htab
->sec_info
[tail
->id
].toc_off
;
12469 while ((prev
= htab
->sec_info
[curr
->id
].u
.list
) != NULL
12470 && ((total
+= curr
->output_offset
- prev
->output_offset
)
12471 < (ppc64_elf_section_data (prev
) != NULL
12472 && ppc64_elf_section_data (prev
)->has_14bit_branch
12473 ? (group_size
= stub_group_size
>> 10) : group_size
))
12474 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12477 /* OK, the size from the start of CURR to the end is less
12478 than group_size and thus can be handled by one stub
12479 section. (or the tail section is itself larger than
12480 group_size, in which case we may be toast.) We should
12481 really be keeping track of the total size of stubs added
12482 here, as stubs contribute to the final output section
12483 size. That's a little tricky, and this way will only
12484 break if stubs added make the total size more than 2^25,
12485 ie. for the default stub_group_size, if stubs total more
12486 than 2097152 bytes, or nearly 75000 plt call stubs. */
12487 group
= bfd_alloc (curr
->owner
, sizeof (*group
));
12490 group
->link_sec
= curr
;
12491 group
->stub_sec
= NULL
;
12492 group
->needs_save_res
= 0;
12493 group
->tls_get_addr_opt_bctrl
= -1u;
12494 group
->next
= htab
->group
;
12495 htab
->group
= group
;
12498 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12499 /* Set up this stub group. */
12500 htab
->sec_info
[tail
->id
].u
.group
= group
;
12502 while (tail
!= curr
&& (tail
= prev
) != NULL
);
12504 /* But wait, there's more! Input sections up to group_size
12505 bytes before the stub section can be handled by it too.
12506 Don't do this if we have a really large section after the
12507 stubs, as adding more stubs increases the chance that
12508 branches may not reach into the stub section. */
12509 if (!stubs_always_before_branch
&& !big_sec
)
12512 while (prev
!= NULL
12513 && ((total
+= tail
->output_offset
- prev
->output_offset
)
12514 < (ppc64_elf_section_data (prev
) != NULL
12515 && ppc64_elf_section_data (prev
)->has_14bit_branch
12516 ? (group_size
= stub_group_size
>> 10) : group_size
))
12517 && htab
->sec_info
[prev
->id
].toc_off
== curr_toc
)
12520 prev
= htab
->sec_info
[tail
->id
].u
.list
;
12521 htab
->sec_info
[tail
->id
].u
.group
= group
;
12530 static const unsigned char glink_eh_frame_cie
[] =
12532 0, 0, 0, 16, /* length. */
12533 0, 0, 0, 0, /* id. */
12534 1, /* CIE version. */
12535 'z', 'R', 0, /* Augmentation string. */
12536 4, /* Code alignment. */
12537 0x78, /* Data alignment. */
12539 1, /* Augmentation size. */
12540 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
12541 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
12545 stub_eh_frame_size (struct map_stub
*group
, size_t align
)
12547 size_t this_size
= 17;
12548 if (group
->tls_get_addr_opt_bctrl
!= -1u)
12550 unsigned int to_bctrl
= group
->tls_get_addr_opt_bctrl
/ 4;
12553 else if (to_bctrl
< 256)
12555 else if (to_bctrl
< 65536)
12561 this_size
= (this_size
+ align
- 1) & -align
;
12565 /* Stripping output sections is normally done before dynamic section
12566 symbols have been allocated. This function is called later, and
12567 handles cases like htab->brlt which is mapped to its own output
12571 maybe_strip_output (struct bfd_link_info
*info
, asection
*isec
)
12573 if (isec
->size
== 0
12574 && isec
->output_section
->size
== 0
12575 && !(isec
->output_section
->flags
& SEC_KEEP
)
12576 && !bfd_section_removed_from_list (info
->output_bfd
,
12577 isec
->output_section
)
12578 && elf_section_data (isec
->output_section
)->dynindx
== 0)
12580 isec
->output_section
->flags
|= SEC_EXCLUDE
;
12581 bfd_section_list_remove (info
->output_bfd
, isec
->output_section
);
12582 info
->output_bfd
->section_count
--;
12586 /* Determine and set the size of the stub section for a final link.
12588 The basic idea here is to examine all the relocations looking for
12589 PC-relative calls to a target that is unreachable with a "bl"
12593 ppc64_elf_size_stubs (struct bfd_link_info
*info
)
12595 bfd_size_type stub_group_size
;
12596 bfd_boolean stubs_always_before_branch
;
12597 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
12602 if (htab
->params
->plt_thread_safe
== -1 && !bfd_link_executable (info
))
12603 htab
->params
->plt_thread_safe
= 1;
12604 if (!htab
->opd_abi
)
12605 htab
->params
->plt_thread_safe
= 0;
12606 else if (htab
->params
->plt_thread_safe
== -1)
12608 static const char *const thread_starter
[] =
12612 "_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE",
12614 "aio_init", "aio_read", "aio_write", "aio_fsync", "lio_listio",
12615 "mq_notify", "create_timer",
12620 "GOMP_parallel_start",
12621 "GOMP_parallel_loop_static",
12622 "GOMP_parallel_loop_static_start",
12623 "GOMP_parallel_loop_dynamic",
12624 "GOMP_parallel_loop_dynamic_start",
12625 "GOMP_parallel_loop_guided",
12626 "GOMP_parallel_loop_guided_start",
12627 "GOMP_parallel_loop_runtime",
12628 "GOMP_parallel_loop_runtime_start",
12629 "GOMP_parallel_sections",
12630 "GOMP_parallel_sections_start",
12636 for (i
= 0; i
< ARRAY_SIZE (thread_starter
); i
++)
12638 struct elf_link_hash_entry
*h
;
12639 h
= elf_link_hash_lookup (&htab
->elf
, thread_starter
[i
],
12640 FALSE
, FALSE
, TRUE
);
12641 htab
->params
->plt_thread_safe
= h
!= NULL
&& h
->ref_regular
;
12642 if (htab
->params
->plt_thread_safe
)
12646 stubs_always_before_branch
= htab
->params
->group_size
< 0;
12647 if (htab
->params
->group_size
< 0)
12648 stub_group_size
= -htab
->params
->group_size
;
12650 stub_group_size
= htab
->params
->group_size
;
12652 if (!group_sections (info
, stub_group_size
, stubs_always_before_branch
))
12655 #define STUB_SHRINK_ITER 20
12656 /* Loop until no stubs added. After iteration 20 of this loop we may
12657 exit on a stub section shrinking. This is to break out of a
12658 pathological case where adding stubs on one iteration decreases
12659 section gaps (perhaps due to alignment), which then requires
12660 fewer or smaller stubs on the next iteration. */
12665 unsigned int bfd_indx
;
12666 struct map_stub
*group
;
12668 htab
->stub_iteration
+= 1;
12670 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
12672 input_bfd
= input_bfd
->link
.next
, bfd_indx
++)
12674 Elf_Internal_Shdr
*symtab_hdr
;
12676 Elf_Internal_Sym
*local_syms
= NULL
;
12678 if (!is_ppc64_elf (input_bfd
))
12681 /* We'll need the symbol table in a second. */
12682 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
12683 if (symtab_hdr
->sh_info
== 0)
12686 /* Walk over each section attached to the input bfd. */
12687 for (section
= input_bfd
->sections
;
12689 section
= section
->next
)
12691 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
12693 /* If there aren't any relocs, then there's nothing more
12695 if ((section
->flags
& SEC_RELOC
) == 0
12696 || (section
->flags
& SEC_ALLOC
) == 0
12697 || (section
->flags
& SEC_LOAD
) == 0
12698 || (section
->flags
& SEC_CODE
) == 0
12699 || section
->reloc_count
== 0)
12702 /* If this section is a link-once section that will be
12703 discarded, then don't create any stubs. */
12704 if (section
->output_section
== NULL
12705 || section
->output_section
->owner
!= info
->output_bfd
)
12708 /* Get the relocs. */
12710 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
12711 info
->keep_memory
);
12712 if (internal_relocs
== NULL
)
12713 goto error_ret_free_local
;
12715 /* Now examine each relocation. */
12716 irela
= internal_relocs
;
12717 irelaend
= irela
+ section
->reloc_count
;
12718 for (; irela
< irelaend
; irela
++)
12720 enum elf_ppc64_reloc_type r_type
;
12721 unsigned int r_indx
;
12722 enum ppc_stub_type stub_type
;
12723 struct ppc_stub_hash_entry
*stub_entry
;
12724 asection
*sym_sec
, *code_sec
;
12725 bfd_vma sym_value
, code_value
;
12726 bfd_vma destination
;
12727 unsigned long local_off
;
12728 bfd_boolean ok_dest
;
12729 struct ppc_link_hash_entry
*hash
;
12730 struct ppc_link_hash_entry
*fdh
;
12731 struct elf_link_hash_entry
*h
;
12732 Elf_Internal_Sym
*sym
;
12734 const asection
*id_sec
;
12735 struct _opd_sec_data
*opd
;
12736 struct plt_entry
*plt_ent
;
12738 r_type
= ELF64_R_TYPE (irela
->r_info
);
12739 r_indx
= ELF64_R_SYM (irela
->r_info
);
12741 if (r_type
>= R_PPC64_max
)
12743 bfd_set_error (bfd_error_bad_value
);
12744 goto error_ret_free_internal
;
12747 /* Only look for stubs on branch instructions. */
12748 if (r_type
!= R_PPC64_REL24
12749 && r_type
!= R_PPC64_REL14
12750 && r_type
!= R_PPC64_REL14_BRTAKEN
12751 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
12754 /* Now determine the call target, its name, value,
12756 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
12757 r_indx
, input_bfd
))
12758 goto error_ret_free_internal
;
12759 hash
= (struct ppc_link_hash_entry
*) h
;
12766 sym_value
= sym
->st_value
;
12767 if (sym_sec
!= NULL
12768 && sym_sec
->output_section
!= NULL
)
12771 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
12772 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
12774 sym_value
= hash
->elf
.root
.u
.def
.value
;
12775 if (sym_sec
->output_section
!= NULL
)
12778 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
12779 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
12781 /* Recognise an old ABI func code entry sym, and
12782 use the func descriptor sym instead if it is
12784 if (hash
->elf
.root
.root
.string
[0] == '.'
12785 && hash
->oh
!= NULL
)
12787 fdh
= ppc_follow_link (hash
->oh
);
12788 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
12789 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
12791 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
12792 sym_value
= fdh
->elf
.root
.u
.def
.value
;
12793 if (sym_sec
->output_section
!= NULL
)
12802 bfd_set_error (bfd_error_bad_value
);
12803 goto error_ret_free_internal
;
12810 sym_value
+= irela
->r_addend
;
12811 destination
= (sym_value
12812 + sym_sec
->output_offset
12813 + sym_sec
->output_section
->vma
);
12814 local_off
= PPC64_LOCAL_ENTRY_OFFSET (hash
12819 code_sec
= sym_sec
;
12820 code_value
= sym_value
;
12821 opd
= get_opd_info (sym_sec
);
12826 if (hash
== NULL
&& opd
->adjust
!= NULL
)
12828 long adjust
= opd
->adjust
[OPD_NDX (sym_value
)];
12831 code_value
+= adjust
;
12832 sym_value
+= adjust
;
12834 dest
= opd_entry_value (sym_sec
, sym_value
,
12835 &code_sec
, &code_value
, FALSE
);
12836 if (dest
!= (bfd_vma
) -1)
12838 destination
= dest
;
12841 /* Fixup old ABI sym to point at code
12843 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
12844 hash
->elf
.root
.u
.def
.section
= code_sec
;
12845 hash
->elf
.root
.u
.def
.value
= code_value
;
12850 /* Determine what (if any) linker stub is needed. */
12852 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
12853 &plt_ent
, destination
,
12856 if (stub_type
!= ppc_stub_plt_call
)
12858 /* Check whether we need a TOC adjusting stub.
12859 Since the linker pastes together pieces from
12860 different object files when creating the
12861 _init and _fini functions, it may be that a
12862 call to what looks like a local sym is in
12863 fact a call needing a TOC adjustment. */
12864 if (code_sec
!= NULL
12865 && code_sec
->output_section
!= NULL
12866 && (htab
->sec_info
[code_sec
->id
].toc_off
12867 != htab
->sec_info
[section
->id
].toc_off
)
12868 && (code_sec
->has_toc_reloc
12869 || code_sec
->makes_toc_func_call
))
12870 stub_type
= ppc_stub_long_branch_r2off
;
12873 if (stub_type
== ppc_stub_none
)
12876 /* __tls_get_addr calls might be eliminated. */
12877 if (stub_type
!= ppc_stub_plt_call
12879 && (hash
== htab
->tls_get_addr
12880 || hash
== htab
->tls_get_addr_fd
)
12881 && section
->has_tls_reloc
12882 && irela
!= internal_relocs
)
12884 /* Get tls info. */
12885 unsigned char *tls_mask
;
12887 if (!get_tls_mask (&tls_mask
, NULL
, NULL
, &local_syms
,
12888 irela
- 1, input_bfd
))
12889 goto error_ret_free_internal
;
12890 if ((*tls_mask
& TLS_TLS
) != 0)
12894 if (stub_type
== ppc_stub_plt_call
)
12897 && htab
->params
->plt_localentry0
!= 0
12898 && is_elfv2_localentry0 (&hash
->elf
))
12899 htab
->has_plt_localentry0
= 1;
12900 else if (irela
+ 1 < irelaend
12901 && irela
[1].r_offset
== irela
->r_offset
+ 4
12902 && (ELF64_R_TYPE (irela
[1].r_info
)
12903 == R_PPC64_TOCSAVE
))
12905 if (!tocsave_find (htab
, INSERT
,
12906 &local_syms
, irela
+ 1, input_bfd
))
12907 goto error_ret_free_internal
;
12910 stub_type
= ppc_stub_plt_call_r2save
;
12913 /* Support for grouping stub sections. */
12914 id_sec
= htab
->sec_info
[section
->id
].u
.group
->link_sec
;
12916 /* Get the name of this stub. */
12917 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
12919 goto error_ret_free_internal
;
12921 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
12922 stub_name
, FALSE
, FALSE
);
12923 if (stub_entry
!= NULL
)
12925 /* The proper stub has already been created. */
12927 if (stub_type
== ppc_stub_plt_call_r2save
)
12928 stub_entry
->stub_type
= stub_type
;
12932 stub_entry
= ppc_add_stub (stub_name
, section
, info
);
12933 if (stub_entry
== NULL
)
12936 error_ret_free_internal
:
12937 if (elf_section_data (section
)->relocs
== NULL
)
12938 free (internal_relocs
);
12939 error_ret_free_local
:
12940 if (local_syms
!= NULL
12941 && (symtab_hdr
->contents
12942 != (unsigned char *) local_syms
))
12947 stub_entry
->stub_type
= stub_type
;
12948 if (stub_type
!= ppc_stub_plt_call
12949 && stub_type
!= ppc_stub_plt_call_r2save
)
12951 stub_entry
->target_value
= code_value
;
12952 stub_entry
->target_section
= code_sec
;
12956 stub_entry
->target_value
= sym_value
;
12957 stub_entry
->target_section
= sym_sec
;
12959 stub_entry
->h
= hash
;
12960 stub_entry
->plt_ent
= plt_ent
;
12961 stub_entry
->symtype
12962 = hash
? hash
->elf
.type
: ELF_ST_TYPE (sym
->st_info
);
12963 stub_entry
->other
= hash
? hash
->elf
.other
: sym
->st_other
;
12965 if (stub_entry
->h
!= NULL
)
12966 htab
->stub_globals
+= 1;
12969 /* We're done with the internal relocs, free them. */
12970 if (elf_section_data (section
)->relocs
!= internal_relocs
)
12971 free (internal_relocs
);
12974 if (local_syms
!= NULL
12975 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
12977 if (!info
->keep_memory
)
12980 symtab_hdr
->contents
= (unsigned char *) local_syms
;
12984 /* We may have added some stubs. Find out the new size of the
12986 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
12987 if (group
->stub_sec
!= NULL
)
12989 asection
*stub_sec
= group
->stub_sec
;
12991 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
12992 || stub_sec
->rawsize
< stub_sec
->size
)
12993 /* Past STUB_SHRINK_ITER, rawsize is the max size seen. */
12994 stub_sec
->rawsize
= stub_sec
->size
;
12995 stub_sec
->size
= 0;
12996 stub_sec
->reloc_count
= 0;
12997 stub_sec
->flags
&= ~SEC_RELOC
;
13000 if (htab
->stub_iteration
<= STUB_SHRINK_ITER
13001 || htab
->brlt
->rawsize
< htab
->brlt
->size
)
13002 htab
->brlt
->rawsize
= htab
->brlt
->size
;
13003 htab
->brlt
->size
= 0;
13004 htab
->brlt
->reloc_count
= 0;
13005 htab
->brlt
->flags
&= ~SEC_RELOC
;
13006 if (htab
->relbrlt
!= NULL
)
13007 htab
->relbrlt
->size
= 0;
13009 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
13011 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13012 if (group
->needs_save_res
)
13013 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13015 if (info
->emitrelocations
13016 && htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13018 htab
->glink
->reloc_count
= 1;
13019 htab
->glink
->flags
|= SEC_RELOC
;
13022 if (htab
->glink_eh_frame
!= NULL
13023 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
13024 && htab
->glink_eh_frame
->output_section
->size
> 8)
13026 size_t size
= 0, align
= 4;
13028 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13029 if (group
->stub_sec
!= NULL
)
13030 size
+= stub_eh_frame_size (group
, align
);
13031 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13032 size
+= (24 + align
- 1) & -align
;
13034 size
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
13035 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13036 size
= (size
+ align
- 1) & -align
;
13037 htab
->glink_eh_frame
->rawsize
= htab
->glink_eh_frame
->size
;
13038 htab
->glink_eh_frame
->size
= size
;
13041 if (htab
->params
->plt_stub_align
!= 0)
13042 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13043 if (group
->stub_sec
!= NULL
)
13045 int align
= abs (htab
->params
->plt_stub_align
);
13046 group
->stub_sec
->size
13047 = (group
->stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13050 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13051 if (group
->stub_sec
!= NULL
13052 && group
->stub_sec
->rawsize
!= group
->stub_sec
->size
13053 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13054 || group
->stub_sec
->rawsize
< group
->stub_sec
->size
))
13058 && (htab
->brlt
->rawsize
== htab
->brlt
->size
13059 || (htab
->stub_iteration
> STUB_SHRINK_ITER
13060 && htab
->brlt
->rawsize
> htab
->brlt
->size
))
13061 && (htab
->glink_eh_frame
== NULL
13062 || htab
->glink_eh_frame
->rawsize
== htab
->glink_eh_frame
->size
))
13065 /* Ask the linker to do its stuff. */
13066 (*htab
->params
->layout_sections_again
) ();
13069 if (htab
->glink_eh_frame
!= NULL
13070 && htab
->glink_eh_frame
->size
!= 0)
13073 bfd_byte
*p
, *last_fde
;
13074 size_t last_fde_len
, size
, align
, pad
;
13075 struct map_stub
*group
;
13077 p
= bfd_zalloc (htab
->glink_eh_frame
->owner
, htab
->glink_eh_frame
->size
);
13080 htab
->glink_eh_frame
->contents
= p
;
13084 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
13085 /* CIE length (rewrite in case little-endian). */
13086 last_fde_len
= ((sizeof (glink_eh_frame_cie
) + align
- 1) & -align
) - 4;
13087 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13088 p
+= last_fde_len
+ 4;
13090 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13091 if (group
->stub_sec
!= NULL
)
13094 last_fde_len
= stub_eh_frame_size (group
, align
) - 4;
13096 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13099 val
= p
- htab
->glink_eh_frame
->contents
;
13100 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13102 /* Offset to stub section, written later. */
13104 /* stub section size. */
13105 bfd_put_32 (htab
->elf
.dynobj
, group
->stub_sec
->size
, p
);
13107 /* Augmentation. */
13109 if (group
->tls_get_addr_opt_bctrl
!= -1u)
13111 unsigned int to_bctrl
= group
->tls_get_addr_opt_bctrl
/ 4;
13113 /* This FDE needs more than just the default.
13114 Describe __tls_get_addr_opt stub LR. */
13116 *p
++ = DW_CFA_advance_loc
+ to_bctrl
;
13117 else if (to_bctrl
< 256)
13119 *p
++ = DW_CFA_advance_loc1
;
13122 else if (to_bctrl
< 65536)
13124 *p
++ = DW_CFA_advance_loc2
;
13125 bfd_put_16 (htab
->elf
.dynobj
, to_bctrl
, p
);
13130 *p
++ = DW_CFA_advance_loc4
;
13131 bfd_put_32 (htab
->elf
.dynobj
, to_bctrl
, p
);
13134 *p
++ = DW_CFA_offset_extended_sf
;
13136 *p
++ = -(STK_LINKER (htab
) / 8) & 0x7f;
13137 *p
++ = DW_CFA_advance_loc
+ 4;
13138 *p
++ = DW_CFA_restore_extended
;
13142 p
= last_fde
+ last_fde_len
+ 4;
13144 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13147 last_fde_len
= ((24 + align
- 1) & -align
) - 4;
13149 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
, p
);
13152 val
= p
- htab
->glink_eh_frame
->contents
;
13153 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
13155 /* Offset to .glink, written later. */
13158 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
- 8, p
);
13160 /* Augmentation. */
13163 *p
++ = DW_CFA_advance_loc
+ 1;
13164 *p
++ = DW_CFA_register
;
13166 *p
++ = htab
->opd_abi
? 12 : 0;
13167 *p
++ = DW_CFA_advance_loc
+ (htab
->opd_abi
? 5 : 7);
13168 *p
++ = DW_CFA_restore_extended
;
13170 p
+= ((24 + align
- 1) & -align
) - 24;
13172 /* Subsume any padding into the last FDE if user .eh_frame
13173 sections are aligned more than glink_eh_frame. Otherwise any
13174 zero padding will be seen as a terminator. */
13175 align
= 1ul << htab
->glink_eh_frame
->output_section
->alignment_power
;
13176 size
= p
- htab
->glink_eh_frame
->contents
;
13177 pad
= ((size
+ align
- 1) & -align
) - size
;
13178 htab
->glink_eh_frame
->size
= size
+ pad
;
13179 bfd_put_32 (htab
->elf
.dynobj
, last_fde_len
+ pad
, last_fde
);
13182 maybe_strip_output (info
, htab
->brlt
);
13183 if (htab
->glink_eh_frame
!= NULL
)
13184 maybe_strip_output (info
, htab
->glink_eh_frame
);
13189 /* Called after we have determined section placement. If sections
13190 move, we'll be called again. Provide a value for TOCstart. */
13193 ppc64_elf_set_toc (struct bfd_link_info
*info
, bfd
*obfd
)
13196 bfd_vma TOCstart
, adjust
;
13200 struct elf_link_hash_entry
*h
;
13201 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
13203 if (is_elf_hash_table (htab
)
13204 && htab
->hgot
!= NULL
)
13208 h
= elf_link_hash_lookup (htab
, ".TOC.", FALSE
, FALSE
, TRUE
);
13209 if (is_elf_hash_table (htab
))
13213 && h
->root
.type
== bfd_link_hash_defined
13214 && !h
->root
.linker_def
13215 && (!is_elf_hash_table (htab
)
13216 || h
->def_regular
))
13218 TOCstart
= (h
->root
.u
.def
.value
- TOC_BASE_OFF
13219 + h
->root
.u
.def
.section
->output_offset
13220 + h
->root
.u
.def
.section
->output_section
->vma
);
13221 _bfd_set_gp_value (obfd
, TOCstart
);
13226 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
13227 order. The TOC starts where the first of these sections starts. */
13228 s
= bfd_get_section_by_name (obfd
, ".got");
13229 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13230 s
= bfd_get_section_by_name (obfd
, ".toc");
13231 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13232 s
= bfd_get_section_by_name (obfd
, ".tocbss");
13233 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13234 s
= bfd_get_section_by_name (obfd
, ".plt");
13235 if (s
== NULL
|| (s
->flags
& SEC_EXCLUDE
) != 0)
13237 /* This may happen for
13238 o references to TOC base (SYM@toc / TOC[tc0]) without a
13240 o bad linker script
13241 o --gc-sections and empty TOC sections
13243 FIXME: Warn user? */
13245 /* Look for a likely section. We probably won't even be
13247 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13248 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
13250 == (SEC_ALLOC
| SEC_SMALL_DATA
))
13253 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13254 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_EXCLUDE
))
13255 == (SEC_ALLOC
| SEC_SMALL_DATA
))
13258 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13259 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
| SEC_EXCLUDE
))
13263 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
13264 if ((s
->flags
& (SEC_ALLOC
| SEC_EXCLUDE
)) == SEC_ALLOC
)
13270 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
13272 /* Force alignment. */
13273 adjust
= TOCstart
& (TOC_BASE_ALIGN
- 1);
13274 TOCstart
-= adjust
;
13275 _bfd_set_gp_value (obfd
, TOCstart
);
13277 if (info
!= NULL
&& s
!= NULL
)
13279 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13283 if (htab
->elf
.hgot
!= NULL
)
13285 htab
->elf
.hgot
->root
.u
.def
.value
= TOC_BASE_OFF
- adjust
;
13286 htab
->elf
.hgot
->root
.u
.def
.section
= s
;
13291 struct bfd_link_hash_entry
*bh
= NULL
;
13292 _bfd_generic_link_add_one_symbol (info
, obfd
, ".TOC.", BSF_GLOBAL
,
13293 s
, TOC_BASE_OFF
- adjust
,
13294 NULL
, FALSE
, FALSE
, &bh
);
13300 /* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
13301 write out any global entry stubs, and PLT relocations. */
13304 build_global_entry_stubs_and_plt (struct elf_link_hash_entry
*h
, void *inf
)
13306 struct bfd_link_info
*info
;
13307 struct ppc_link_hash_table
*htab
;
13308 struct plt_entry
*ent
;
13311 if (h
->root
.type
== bfd_link_hash_indirect
)
13315 htab
= ppc_hash_table (info
);
13319 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13320 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13322 /* This symbol has an entry in the procedure linkage
13323 table. Set it up. */
13324 Elf_Internal_Rela rela
;
13325 asection
*plt
, *relplt
;
13328 if (!htab
->elf
.dynamic_sections_created
13329 || h
->dynindx
== -1)
13331 if (!(h
->def_regular
13332 && (h
->root
.type
== bfd_link_hash_defined
13333 || h
->root
.type
== bfd_link_hash_defweak
)))
13335 if (h
->type
== STT_GNU_IFUNC
)
13337 plt
= htab
->elf
.iplt
;
13338 relplt
= htab
->elf
.irelplt
;
13339 htab
->local_ifunc_resolver
= 1;
13341 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13343 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13347 plt
= htab
->pltlocal
;
13348 if (bfd_link_pic (info
))
13350 relplt
= htab
->relpltlocal
;
13352 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13354 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13359 rela
.r_addend
= (h
->root
.u
.def
.value
13360 + h
->root
.u
.def
.section
->output_offset
13361 + h
->root
.u
.def
.section
->output_section
->vma
13364 if (relplt
== NULL
)
13366 loc
= plt
->contents
+ ent
->plt
.offset
;
13367 bfd_put_64 (info
->output_bfd
, rela
.r_addend
, loc
);
13370 bfd_vma toc
= elf_gp (info
->output_bfd
);
13371 toc
+= htab
->sec_info
[h
->root
.u
.def
.section
->id
].toc_off
;
13372 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13377 rela
.r_offset
= (plt
->output_section
->vma
13378 + plt
->output_offset
13379 + ent
->plt
.offset
);
13380 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13381 * sizeof (Elf64_External_Rela
));
13382 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13387 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
13388 + htab
->elf
.splt
->output_offset
13389 + ent
->plt
.offset
);
13390 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
13391 rela
.r_addend
= ent
->addend
;
13392 loc
= (htab
->elf
.srelplt
->contents
13393 + ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE (htab
))
13394 / PLT_ENTRY_SIZE (htab
) * sizeof (Elf64_External_Rela
)));
13395 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
13396 htab
->maybe_local_ifunc_resolver
= 1;
13397 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13401 if (!h
->pointer_equality_needed
)
13404 if (h
->def_regular
)
13407 s
= htab
->global_entry
;
13408 if (s
== NULL
|| s
->size
== 0)
13411 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
13412 if (ent
->plt
.offset
!= (bfd_vma
) -1
13413 && ent
->addend
== 0)
13419 p
= s
->contents
+ h
->root
.u
.def
.value
;
13420 plt
= htab
->elf
.splt
;
13421 if (!htab
->elf
.dynamic_sections_created
13422 || h
->dynindx
== -1)
13424 if (h
->type
== STT_GNU_IFUNC
)
13425 plt
= htab
->elf
.iplt
;
13427 plt
= htab
->pltlocal
;
13429 off
= ent
->plt
.offset
+ plt
->output_offset
+ plt
->output_section
->vma
;
13430 off
-= h
->root
.u
.def
.value
+ s
->output_offset
+ s
->output_section
->vma
;
13432 if (off
+ 0x80008000 > 0xffffffff || (off
& 3) != 0)
13434 info
->callbacks
->einfo
13435 (_("%P: linkage table error against `%pT'\n"),
13436 h
->root
.root
.string
);
13437 bfd_set_error (bfd_error_bad_value
);
13438 htab
->stub_error
= TRUE
;
13441 htab
->stub_count
[ppc_stub_global_entry
- 1] += 1;
13442 if (htab
->params
->emit_stub_syms
)
13444 size_t len
= strlen (h
->root
.root
.string
);
13445 char *name
= bfd_malloc (sizeof "12345678.global_entry." + len
);
13450 sprintf (name
, "%08x.global_entry.%s", s
->id
, h
->root
.root
.string
);
13451 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
13454 if (h
->root
.type
== bfd_link_hash_new
)
13456 h
->root
.type
= bfd_link_hash_defined
;
13457 h
->root
.u
.def
.section
= s
;
13458 h
->root
.u
.def
.value
= p
- s
->contents
;
13459 h
->ref_regular
= 1;
13460 h
->def_regular
= 1;
13461 h
->ref_regular_nonweak
= 1;
13462 h
->forced_local
= 1;
13464 h
->root
.linker_def
= 1;
13468 if (PPC_HA (off
) != 0)
13470 bfd_put_32 (s
->owner
, ADDIS_R12_R12
| PPC_HA (off
), p
);
13473 bfd_put_32 (s
->owner
, LD_R12_0R12
| PPC_LO (off
), p
);
13475 bfd_put_32 (s
->owner
, MTCTR_R12
, p
);
13477 bfd_put_32 (s
->owner
, BCTR
, p
);
13483 /* Write PLT relocs for locals. */
13486 write_plt_relocs_for_local_syms (struct bfd_link_info
*info
)
13488 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13491 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
13493 struct got_entry
**lgot_ents
, **end_lgot_ents
;
13494 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
13495 Elf_Internal_Shdr
*symtab_hdr
;
13496 bfd_size_type locsymcount
;
13497 Elf_Internal_Sym
*local_syms
= NULL
;
13498 struct plt_entry
*ent
;
13500 if (!is_ppc64_elf (ibfd
))
13503 lgot_ents
= elf_local_got_ents (ibfd
);
13507 symtab_hdr
= &elf_symtab_hdr (ibfd
);
13508 locsymcount
= symtab_hdr
->sh_info
;
13509 end_lgot_ents
= lgot_ents
+ locsymcount
;
13510 local_plt
= (struct plt_entry
**) end_lgot_ents
;
13511 end_local_plt
= local_plt
+ locsymcount
;
13512 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
13513 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
13514 if (ent
->plt
.offset
!= (bfd_vma
) -1)
13516 Elf_Internal_Sym
*sym
;
13518 asection
*plt
, *relplt
;
13522 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
13523 lplt
- local_plt
, ibfd
))
13525 if (local_syms
!= NULL
13526 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13531 val
= sym
->st_value
+ ent
->addend
;
13532 val
+= PPC64_LOCAL_ENTRY_OFFSET (sym
->st_other
);
13533 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
13534 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
13536 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13538 htab
->local_ifunc_resolver
= 1;
13539 plt
= htab
->elf
.iplt
;
13540 relplt
= htab
->elf
.irelplt
;
13544 plt
= htab
->pltlocal
;
13545 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
13548 if (relplt
== NULL
)
13550 loc
= plt
->contents
+ ent
->plt
.offset
;
13551 bfd_put_64 (info
->output_bfd
, val
, loc
);
13554 bfd_vma toc
= elf_gp (ibfd
);
13555 bfd_put_64 (info
->output_bfd
, toc
, loc
+ 8);
13560 Elf_Internal_Rela rela
;
13561 rela
.r_offset
= (ent
->plt
.offset
13562 + plt
->output_offset
13563 + plt
->output_section
->vma
);
13564 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
13567 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_IREL
);
13569 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
13574 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_JMP_SLOT
);
13576 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
13578 rela
.r_addend
= val
;
13579 loc
= relplt
->contents
+ (relplt
->reloc_count
++
13580 * sizeof (Elf64_External_Rela
));
13581 bfd_elf64_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
13585 if (local_syms
!= NULL
13586 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
13588 if (!info
->keep_memory
)
13591 symtab_hdr
->contents
= (unsigned char *) local_syms
;
13597 /* Build all the stubs associated with the current output file.
13598 The stubs are kept in a hash table attached to the main linker
13599 hash table. This function is called via gldelf64ppc_finish. */
13602 ppc64_elf_build_stubs (struct bfd_link_info
*info
,
13605 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
13606 struct map_stub
*group
;
13607 asection
*stub_sec
;
13609 int stub_sec_count
= 0;
13614 /* Allocate memory to hold the linker stubs. */
13615 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13616 if ((stub_sec
= group
->stub_sec
) != NULL
13617 && stub_sec
->size
!= 0)
13619 stub_sec
->contents
= bfd_zalloc (htab
->params
->stub_bfd
, stub_sec
->size
);
13620 if (stub_sec
->contents
== NULL
)
13622 stub_sec
->size
= 0;
13625 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
13630 /* Build the .glink plt call stub. */
13631 if (htab
->params
->emit_stub_syms
)
13633 struct elf_link_hash_entry
*h
;
13634 h
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
13635 TRUE
, FALSE
, FALSE
);
13638 if (h
->root
.type
== bfd_link_hash_new
)
13640 h
->root
.type
= bfd_link_hash_defined
;
13641 h
->root
.u
.def
.section
= htab
->glink
;
13642 h
->root
.u
.def
.value
= 8;
13643 h
->ref_regular
= 1;
13644 h
->def_regular
= 1;
13645 h
->ref_regular_nonweak
= 1;
13646 h
->forced_local
= 1;
13648 h
->root
.linker_def
= 1;
13651 plt0
= (htab
->elf
.splt
->output_section
->vma
13652 + htab
->elf
.splt
->output_offset
13654 if (info
->emitrelocations
)
13656 Elf_Internal_Rela
*r
= get_relocs (htab
->glink
, 1);
13659 r
->r_offset
= (htab
->glink
->output_offset
13660 + htab
->glink
->output_section
->vma
);
13661 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL64
);
13662 r
->r_addend
= plt0
;
13664 p
= htab
->glink
->contents
;
13665 plt0
-= htab
->glink
->output_section
->vma
+ htab
->glink
->output_offset
;
13666 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
13670 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
13672 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13674 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13676 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13678 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
13680 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13682 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13684 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| 8, p
);
13686 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13688 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 16, p
);
13693 bfd_put_32 (htab
->glink
->owner
, MFLR_R0
, p
);
13695 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
13697 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
13699 bfd_put_32 (htab
->glink
->owner
, STD_R2_0R1
+ 24, p
);
13701 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R11
| (-16 & 0xfffc), p
);
13703 bfd_put_32 (htab
->glink
->owner
, MTLR_R0
, p
);
13705 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
13707 bfd_put_32 (htab
->glink
->owner
, ADD_R11_R2_R11
, p
);
13709 bfd_put_32 (htab
->glink
->owner
, ADDI_R0_R12
| (-48 & 0xffff), p
);
13711 bfd_put_32 (htab
->glink
->owner
, LD_R12_0R11
, p
);
13713 bfd_put_32 (htab
->glink
->owner
, SRDI_R0_R0_2
, p
);
13715 bfd_put_32 (htab
->glink
->owner
, MTCTR_R12
, p
);
13717 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R11
| 8, p
);
13720 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
13722 BFD_ASSERT (p
== htab
->glink
->contents
+ GLINK_PLTRESOLVE_SIZE (htab
));
13724 /* Build the .glink lazy link call stubs. */
13726 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
13732 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
13737 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
13739 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
),
13744 bfd_put_32 (htab
->glink
->owner
,
13745 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
13751 /* Build .glink global entry stubs, and PLT relocs for globals. */
13752 elf_link_hash_traverse (&htab
->elf
, build_global_entry_stubs_and_plt
, info
);
13754 if (!write_plt_relocs_for_local_syms (info
))
13757 if (htab
->brlt
!= NULL
&& htab
->brlt
->size
!= 0)
13759 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
13761 if (htab
->brlt
->contents
== NULL
)
13764 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
13766 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
13767 htab
->relbrlt
->size
);
13768 if (htab
->relbrlt
->contents
== NULL
)
13772 /* Build the stubs as directed by the stub hash table. */
13773 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
13775 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13776 if (group
->needs_save_res
)
13777 group
->stub_sec
->size
+= htab
->sfpr
->size
;
13779 if (htab
->relbrlt
!= NULL
)
13780 htab
->relbrlt
->reloc_count
= 0;
13782 if (htab
->params
->plt_stub_align
!= 0)
13783 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13784 if ((stub_sec
= group
->stub_sec
) != NULL
)
13786 int align
= abs (htab
->params
->plt_stub_align
);
13787 stub_sec
->size
= (stub_sec
->size
+ (1 << align
) - 1) & -(1 << align
);
13790 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13791 if (group
->needs_save_res
)
13793 stub_sec
= group
->stub_sec
;
13794 memcpy (stub_sec
->contents
+ stub_sec
->size
- htab
->sfpr
->size
,
13795 htab
->sfpr
->contents
, htab
->sfpr
->size
);
13796 if (htab
->params
->emit_stub_syms
)
13800 for (i
= 0; i
< ARRAY_SIZE (save_res_funcs
); i
++)
13801 if (!sfpr_define (info
, &save_res_funcs
[i
], stub_sec
))
13806 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
13807 if ((stub_sec
= group
->stub_sec
) != NULL
)
13809 stub_sec_count
+= 1;
13810 if (stub_sec
->rawsize
!= stub_sec
->size
13811 && (htab
->stub_iteration
<= STUB_SHRINK_ITER
13812 || stub_sec
->rawsize
< stub_sec
->size
))
13818 htab
->stub_error
= TRUE
;
13819 _bfd_error_handler (_("stubs don't match calculated size"));
13822 if (htab
->stub_error
)
13828 *stats
= bfd_malloc (500);
13829 if (*stats
== NULL
)
13832 len
= sprintf (*stats
,
13833 ngettext ("linker stubs in %u group\n",
13834 "linker stubs in %u groups\n",
13837 sprintf (*stats
+ len
, _(" branch %lu\n"
13838 " toc adjust %lu\n"
13839 " long branch %lu\n"
13840 " long toc adj %lu\n"
13842 " plt call toc %lu\n"
13843 " global entry %lu"),
13844 htab
->stub_count
[ppc_stub_long_branch
- 1],
13845 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
13846 htab
->stub_count
[ppc_stub_plt_branch
- 1],
13847 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
13848 htab
->stub_count
[ppc_stub_plt_call
- 1],
13849 htab
->stub_count
[ppc_stub_plt_call_r2save
- 1],
13850 htab
->stub_count
[ppc_stub_global_entry
- 1]);
13855 /* What to do when ld finds relocations against symbols defined in
13856 discarded sections. */
13858 static unsigned int
13859 ppc64_elf_action_discarded (asection
*sec
)
13861 if (strcmp (".opd", sec
->name
) == 0)
13864 if (strcmp (".toc", sec
->name
) == 0)
13867 if (strcmp (".toc1", sec
->name
) == 0)
13870 return _bfd_elf_default_action_discarded (sec
);
13873 /* The RELOCATE_SECTION function is called by the ELF backend linker
13874 to handle the relocations for a section.
13876 The relocs are always passed as Rela structures; if the section
13877 actually uses Rel structures, the r_addend field will always be
13880 This function is responsible for adjust the section contents as
13881 necessary, and (if using Rela relocs and generating a
13882 relocatable output file) adjusting the reloc addend as
13885 This function does not have to worry about setting the reloc
13886 address or the reloc symbol index.
13888 LOCAL_SYMS is a pointer to the swapped in local symbols.
13890 LOCAL_SECTIONS is an array giving the section in the input file
13891 corresponding to the st_shndx field of each local symbol.
13893 The global hash table entry for the global symbols can be found
13894 via elf_sym_hashes (input_bfd).
13896 When generating relocatable output, this function must handle
13897 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
13898 going to be the section symbol corresponding to the output
13899 section, which means that the addend must be adjusted
13903 ppc64_elf_relocate_section (bfd
*output_bfd
,
13904 struct bfd_link_info
*info
,
13906 asection
*input_section
,
13907 bfd_byte
*contents
,
13908 Elf_Internal_Rela
*relocs
,
13909 Elf_Internal_Sym
*local_syms
,
13910 asection
**local_sections
)
13912 struct ppc_link_hash_table
*htab
;
13913 Elf_Internal_Shdr
*symtab_hdr
;
13914 struct elf_link_hash_entry
**sym_hashes
;
13915 Elf_Internal_Rela
*rel
;
13916 Elf_Internal_Rela
*wrel
;
13917 Elf_Internal_Rela
*relend
;
13918 Elf_Internal_Rela outrel
;
13920 struct got_entry
**local_got_ents
;
13922 bfd_boolean ret
= TRUE
;
13923 bfd_boolean is_opd
;
13924 /* Assume 'at' branch hints. */
13925 bfd_boolean is_isa_v2
= TRUE
;
13926 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
13928 /* Initialize howto table if needed. */
13929 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
13932 htab
= ppc_hash_table (info
);
13936 /* Don't relocate stub sections. */
13937 if (input_section
->owner
== htab
->params
->stub_bfd
)
13940 BFD_ASSERT (is_ppc64_elf (input_bfd
));
13942 local_got_ents
= elf_local_got_ents (input_bfd
);
13943 TOCstart
= elf_gp (output_bfd
);
13944 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
13945 sym_hashes
= elf_sym_hashes (input_bfd
);
13946 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
13948 rel
= wrel
= relocs
;
13949 relend
= relocs
+ input_section
->reloc_count
;
13950 for (; rel
< relend
; wrel
++, rel
++)
13952 enum elf_ppc64_reloc_type r_type
;
13954 bfd_reloc_status_type r
;
13955 Elf_Internal_Sym
*sym
;
13957 struct elf_link_hash_entry
*h_elf
;
13958 struct ppc_link_hash_entry
*h
;
13959 struct ppc_link_hash_entry
*fdh
;
13960 const char *sym_name
;
13961 unsigned long r_symndx
, toc_symndx
;
13962 bfd_vma toc_addend
;
13963 unsigned char tls_mask
, tls_gd
, tls_type
;
13964 unsigned char sym_type
;
13965 bfd_vma relocation
;
13966 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
13967 bfd_boolean warned
;
13968 enum { DEST_NORMAL
, DEST_OPD
, DEST_STUB
} reloc_dest
;
13971 struct ppc_stub_hash_entry
*stub_entry
;
13972 bfd_vma max_br_offset
;
13974 Elf_Internal_Rela orig_rel
;
13975 reloc_howto_type
*howto
;
13976 struct reloc_howto_struct alt_howto
;
13981 r_type
= ELF64_R_TYPE (rel
->r_info
);
13982 r_symndx
= ELF64_R_SYM (rel
->r_info
);
13984 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
13985 symbol of the previous ADDR64 reloc. The symbol gives us the
13986 proper TOC base to use. */
13987 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
13989 && ELF64_R_TYPE (wrel
[-1].r_info
) == R_PPC64_ADDR64
13991 r_symndx
= ELF64_R_SYM (wrel
[-1].r_info
);
13997 unresolved_reloc
= FALSE
;
14000 if (r_symndx
< symtab_hdr
->sh_info
)
14002 /* It's a local symbol. */
14003 struct _opd_sec_data
*opd
;
14005 sym
= local_syms
+ r_symndx
;
14006 sec
= local_sections
[r_symndx
];
14007 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
14008 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
14009 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
14010 opd
= get_opd_info (sec
);
14011 if (opd
!= NULL
&& opd
->adjust
!= NULL
)
14013 long adjust
= opd
->adjust
[OPD_NDX (sym
->st_value
14019 /* If this is a relocation against the opd section sym
14020 and we have edited .opd, adjust the reloc addend so
14021 that ld -r and ld --emit-relocs output is correct.
14022 If it is a reloc against some other .opd symbol,
14023 then the symbol value will be adjusted later. */
14024 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
14025 rel
->r_addend
+= adjust
;
14027 relocation
+= adjust
;
14033 bfd_boolean ignored
;
14035 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
14036 r_symndx
, symtab_hdr
, sym_hashes
,
14037 h_elf
, sec
, relocation
,
14038 unresolved_reloc
, warned
, ignored
);
14039 sym_name
= h_elf
->root
.root
.string
;
14040 sym_type
= h_elf
->type
;
14042 && sec
->owner
== output_bfd
14043 && strcmp (sec
->name
, ".opd") == 0)
14045 /* This is a symbol defined in a linker script. All
14046 such are defined in output sections, even those
14047 defined by simple assignment from a symbol defined in
14048 an input section. Transfer the symbol to an
14049 appropriate input .opd section, so that a branch to
14050 this symbol will be mapped to the location specified
14051 by the opd entry. */
14052 struct bfd_link_order
*lo
;
14053 for (lo
= sec
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
14054 if (lo
->type
== bfd_indirect_link_order
)
14056 asection
*isec
= lo
->u
.indirect
.section
;
14057 if (h_elf
->root
.u
.def
.value
>= isec
->output_offset
14058 && h_elf
->root
.u
.def
.value
< (isec
->output_offset
14061 h_elf
->root
.u
.def
.value
-= isec
->output_offset
;
14062 h_elf
->root
.u
.def
.section
= isec
;
14069 h
= (struct ppc_link_hash_entry
*) h_elf
;
14071 if (sec
!= NULL
&& discarded_section (sec
))
14073 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
],
14074 input_bfd
, input_section
,
14075 contents
+ rel
->r_offset
);
14076 wrel
->r_offset
= rel
->r_offset
;
14078 wrel
->r_addend
= 0;
14080 /* For ld -r, remove relocations in debug sections against
14081 symbols defined in discarded sections. Not done for
14082 non-debug to preserve relocs in .eh_frame which the
14083 eh_frame editing code expects to be present. */
14084 if (bfd_link_relocatable (info
)
14085 && (input_section
->flags
& SEC_DEBUGGING
))
14091 if (bfd_link_relocatable (info
))
14094 if (h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
)
14096 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14097 sec
= bfd_abs_section_ptr
;
14098 unresolved_reloc
= FALSE
;
14101 /* TLS optimizations. Replace instruction sequences and relocs
14102 based on information we collected in tls_optimize. We edit
14103 RELOCS so that --emit-relocs will output something sensible
14104 for the final instruction stream. */
14109 tls_mask
= h
->tls_mask
;
14110 else if (local_got_ents
!= NULL
)
14112 struct plt_entry
**local_plt
= (struct plt_entry
**)
14113 (local_got_ents
+ symtab_hdr
->sh_info
);
14114 unsigned char *lgot_masks
= (unsigned char *)
14115 (local_plt
+ symtab_hdr
->sh_info
);
14116 tls_mask
= lgot_masks
[r_symndx
];
14118 if (((tls_mask
& TLS_TLS
) == 0 || tls_mask
== (TLS_TLS
| TLS_MARK
))
14119 && (r_type
== R_PPC64_TLS
14120 || r_type
== R_PPC64_TLSGD
14121 || r_type
== R_PPC64_TLSLD
))
14123 /* Check for toc tls entries. */
14124 unsigned char *toc_tls
;
14126 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
14127 &local_syms
, rel
, input_bfd
))
14131 tls_mask
= *toc_tls
;
14134 /* Check that tls relocs are used with tls syms, and non-tls
14135 relocs are used with non-tls syms. */
14136 if (r_symndx
!= STN_UNDEF
14137 && r_type
!= R_PPC64_NONE
14139 || h
->elf
.root
.type
== bfd_link_hash_defined
14140 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
14141 && (IS_PPC64_TLS_RELOC (r_type
)
14142 != (sym_type
== STT_TLS
14143 || (sym_type
== STT_SECTION
14144 && (sec
->flags
& SEC_THREAD_LOCAL
) != 0))))
14146 if ((tls_mask
& TLS_TLS
) != 0
14147 && (r_type
== R_PPC64_TLS
14148 || r_type
== R_PPC64_TLSGD
14149 || r_type
== R_PPC64_TLSLD
))
14150 /* R_PPC64_TLS is OK against a symbol in the TOC. */
14153 info
->callbacks
->einfo
14154 (!IS_PPC64_TLS_RELOC (r_type
)
14155 /* xgettext:c-format */
14156 ? _("%H: %s used with TLS symbol `%pT'\n")
14157 /* xgettext:c-format */
14158 : _("%H: %s used with non-TLS symbol `%pT'\n"),
14159 input_bfd
, input_section
, rel
->r_offset
,
14160 ppc64_elf_howto_table
[r_type
]->name
,
14164 /* Ensure reloc mapping code below stays sane. */
14165 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
14166 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
14167 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
14168 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
14169 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
14170 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
14171 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
14172 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
14173 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
14174 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
14182 case R_PPC64_LO_DS_OPT
:
14183 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
- d_offset
);
14184 if ((insn
& (0x3f << 26)) != 58u << 26)
14186 insn
+= (14u << 26) - (58u << 26);
14187 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
14188 r_type
= R_PPC64_TOC16_LO
;
14189 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14192 case R_PPC64_TOC16
:
14193 case R_PPC64_TOC16_LO
:
14194 case R_PPC64_TOC16_DS
:
14195 case R_PPC64_TOC16_LO_DS
:
14197 /* Check for toc tls entries. */
14198 unsigned char *toc_tls
;
14201 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &toc_addend
,
14202 &local_syms
, rel
, input_bfd
);
14208 tls_mask
= *toc_tls
;
14209 if (r_type
== R_PPC64_TOC16_DS
14210 || r_type
== R_PPC64_TOC16_LO_DS
)
14212 if ((tls_mask
& TLS_TLS
) != 0
14213 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
14218 /* If we found a GD reloc pair, then we might be
14219 doing a GD->IE transition. */
14222 tls_gd
= TLS_TPRELGD
;
14223 if ((tls_mask
& TLS_TLS
) != 0
14224 && (tls_mask
& TLS_GD
) == 0)
14227 else if (retval
== 3)
14229 if ((tls_mask
& TLS_TLS
) != 0
14230 && (tls_mask
& TLS_LD
) == 0)
14238 case R_PPC64_GOT_TPREL16_HI
:
14239 case R_PPC64_GOT_TPREL16_HA
:
14240 if ((tls_mask
& TLS_TLS
) != 0
14241 && (tls_mask
& TLS_TPREL
) == 0)
14243 rel
->r_offset
-= d_offset
;
14244 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14245 r_type
= R_PPC64_NONE
;
14246 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14250 case R_PPC64_GOT_TPREL16_DS
:
14251 case R_PPC64_GOT_TPREL16_LO_DS
:
14252 if ((tls_mask
& TLS_TLS
) != 0
14253 && (tls_mask
& TLS_TPREL
) == 0)
14256 insn
= bfd_get_32 (input_bfd
,
14257 contents
+ rel
->r_offset
- d_offset
);
14259 insn
|= 0x3c0d0000; /* addis 0,13,0 */
14260 bfd_put_32 (input_bfd
, insn
,
14261 contents
+ rel
->r_offset
- d_offset
);
14262 r_type
= R_PPC64_TPREL16_HA
;
14263 if (toc_symndx
!= 0)
14265 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
14266 rel
->r_addend
= toc_addend
;
14267 /* We changed the symbol. Start over in order to
14268 get h, sym, sec etc. right. */
14272 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14277 if ((tls_mask
& TLS_TLS
) != 0
14278 && (tls_mask
& TLS_TPREL
) == 0)
14280 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14281 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 13);
14284 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14285 /* Was PPC64_TLS which sits on insn boundary, now
14286 PPC64_TPREL16_LO which is at low-order half-word. */
14287 rel
->r_offset
+= d_offset
;
14288 r_type
= R_PPC64_TPREL16_LO
;
14289 if (toc_symndx
!= 0)
14291 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
14292 rel
->r_addend
= toc_addend
;
14293 /* We changed the symbol. Start over in order to
14294 get h, sym, sec etc. right. */
14298 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14302 case R_PPC64_GOT_TLSGD16_HI
:
14303 case R_PPC64_GOT_TLSGD16_HA
:
14304 tls_gd
= TLS_TPRELGD
;
14305 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14309 case R_PPC64_GOT_TLSLD16_HI
:
14310 case R_PPC64_GOT_TLSLD16_HA
:
14311 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14314 if ((tls_mask
& tls_gd
) != 0)
14315 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
14316 + R_PPC64_GOT_TPREL16_DS
);
14319 rel
->r_offset
-= d_offset
;
14320 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14321 r_type
= R_PPC64_NONE
;
14323 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14327 case R_PPC64_GOT_TLSGD16
:
14328 case R_PPC64_GOT_TLSGD16_LO
:
14329 tls_gd
= TLS_TPRELGD
;
14330 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
14334 case R_PPC64_GOT_TLSLD16
:
14335 case R_PPC64_GOT_TLSLD16_LO
:
14336 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
14338 unsigned int insn1
, insn2
;
14342 offset
= (bfd_vma
) -1;
14343 /* If not using the newer R_PPC64_TLSGD/LD to mark
14344 __tls_get_addr calls, we must trust that the call
14345 stays with its arg setup insns, ie. that the next
14346 reloc is the __tls_get_addr call associated with
14347 the current reloc. Edit both insns. */
14348 if (input_section
->has_tls_get_addr_call
14349 && rel
+ 1 < relend
14350 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
14351 htab
->tls_get_addr
,
14352 htab
->tls_get_addr_fd
))
14353 offset
= rel
[1].r_offset
;
14354 /* We read the low GOT_TLS (or TOC16) insn because we
14355 need to keep the destination reg. It may be
14356 something other than the usual r3, and moved to r3
14357 before the call by intervening code. */
14358 insn1
= bfd_get_32 (input_bfd
,
14359 contents
+ rel
->r_offset
- d_offset
);
14360 if ((tls_mask
& tls_gd
) != 0)
14363 insn1
&= (0x1f << 21) | (0x1f << 16);
14364 insn1
|= 58 << 26; /* ld */
14365 insn2
= 0x7c636a14; /* add 3,3,13 */
14366 if (offset
!= (bfd_vma
) -1)
14367 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14368 if ((tls_mask
& TLS_EXPLICIT
) == 0)
14369 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
14370 + R_PPC64_GOT_TPREL16_DS
);
14372 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
14373 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14378 insn1
&= 0x1f << 21;
14379 insn1
|= 0x3c0d0000; /* addis r,13,0 */
14380 insn2
= 0x38630000; /* addi 3,3,0 */
14383 /* Was an LD reloc. */
14385 sec
= local_sections
[toc_symndx
];
14387 r_symndx
< symtab_hdr
->sh_info
;
14389 if (local_sections
[r_symndx
] == sec
)
14391 if (r_symndx
>= symtab_hdr
->sh_info
)
14392 r_symndx
= STN_UNDEF
;
14393 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14394 if (r_symndx
!= STN_UNDEF
)
14395 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
14396 + sec
->output_offset
14397 + sec
->output_section
->vma
);
14399 else if (toc_symndx
!= 0)
14401 r_symndx
= toc_symndx
;
14402 rel
->r_addend
= toc_addend
;
14404 r_type
= R_PPC64_TPREL16_HA
;
14405 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14406 if (offset
!= (bfd_vma
) -1)
14408 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
14409 R_PPC64_TPREL16_LO
);
14410 rel
[1].r_offset
= offset
+ d_offset
;
14411 rel
[1].r_addend
= rel
->r_addend
;
14414 bfd_put_32 (input_bfd
, insn1
,
14415 contents
+ rel
->r_offset
- d_offset
);
14416 if (offset
!= (bfd_vma
) -1)
14417 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14418 if ((tls_mask
& tls_gd
) == 0
14419 && (tls_gd
== 0 || toc_symndx
!= 0))
14421 /* We changed the symbol. Start over in order
14422 to get h, sym, sec etc. right. */
14428 case R_PPC64_TLSGD
:
14429 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
14430 && rel
+ 1 < relend
)
14432 unsigned int insn2
;
14433 bfd_vma offset
= rel
->r_offset
;
14435 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
14437 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14438 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14442 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14443 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14445 if ((tls_mask
& TLS_TPRELGD
) != 0)
14448 r_type
= R_PPC64_NONE
;
14449 insn2
= 0x7c636a14; /* add 3,3,13 */
14454 if (toc_symndx
!= 0)
14456 r_symndx
= toc_symndx
;
14457 rel
->r_addend
= toc_addend
;
14459 r_type
= R_PPC64_TPREL16_LO
;
14460 rel
->r_offset
= offset
+ d_offset
;
14461 insn2
= 0x38630000; /* addi 3,3,0 */
14463 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14464 /* Zap the reloc on the _tls_get_addr call too. */
14465 BFD_ASSERT (offset
== rel
[1].r_offset
);
14466 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14467 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14468 if ((tls_mask
& TLS_TPRELGD
) == 0 && toc_symndx
!= 0)
14473 case R_PPC64_TLSLD
:
14474 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
14475 && rel
+ 1 < relend
)
14477 unsigned int insn2
;
14478 bfd_vma offset
= rel
->r_offset
;
14480 if (is_plt_seq_reloc (ELF64_R_TYPE (rel
[1].r_info
)))
14482 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
);
14483 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14487 if (ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_PLTCALL
)
14488 bfd_put_32 (output_bfd
, NOP
, contents
+ offset
+ 4);
14491 sec
= local_sections
[toc_symndx
];
14493 r_symndx
< symtab_hdr
->sh_info
;
14495 if (local_sections
[r_symndx
] == sec
)
14497 if (r_symndx
>= symtab_hdr
->sh_info
)
14498 r_symndx
= STN_UNDEF
;
14499 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
14500 if (r_symndx
!= STN_UNDEF
)
14501 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
14502 + sec
->output_offset
14503 + sec
->output_section
->vma
);
14505 r_type
= R_PPC64_TPREL16_LO
;
14506 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14507 rel
->r_offset
= offset
+ d_offset
;
14508 /* Zap the reloc on the _tls_get_addr call too. */
14509 BFD_ASSERT (offset
== rel
[1].r_offset
);
14510 rel
[1].r_info
= ELF64_R_INFO (STN_UNDEF
, R_PPC64_NONE
);
14511 insn2
= 0x38630000; /* addi 3,3,0 */
14512 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
14517 case R_PPC64_DTPMOD64
:
14518 if (rel
+ 1 < relend
14519 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
14520 && rel
[1].r_offset
== rel
->r_offset
+ 8)
14522 if ((tls_mask
& TLS_GD
) == 0)
14524 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
14525 if ((tls_mask
& TLS_TPRELGD
) != 0)
14526 r_type
= R_PPC64_TPREL64
;
14529 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14530 r_type
= R_PPC64_NONE
;
14532 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14537 if ((tls_mask
& TLS_LD
) == 0)
14539 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
14540 r_type
= R_PPC64_NONE
;
14541 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14546 case R_PPC64_TPREL64
:
14547 if ((tls_mask
& TLS_TPREL
) == 0)
14549 r_type
= R_PPC64_NONE
;
14550 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14554 case R_PPC64_ENTRY
:
14555 relocation
= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
14556 if (!bfd_link_pic (info
)
14557 && !info
->traditional_format
14558 && relocation
+ 0x80008000 <= 0xffffffff)
14560 unsigned int insn1
, insn2
;
14562 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14563 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14564 if ((insn1
& ~0xfffc) == LD_R2_0R12
14565 && insn2
== ADD_R2_R2_R12
)
14567 bfd_put_32 (input_bfd
,
14568 LIS_R2
+ PPC_HA (relocation
),
14569 contents
+ rel
->r_offset
);
14570 bfd_put_32 (input_bfd
,
14571 ADDI_R2_R2
+ PPC_LO (relocation
),
14572 contents
+ rel
->r_offset
+ 4);
14577 relocation
-= (rel
->r_offset
14578 + input_section
->output_offset
14579 + input_section
->output_section
->vma
);
14580 if (relocation
+ 0x80008000 <= 0xffffffff)
14582 unsigned int insn1
, insn2
;
14584 insn1
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14585 insn2
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
14586 if ((insn1
& ~0xfffc) == LD_R2_0R12
14587 && insn2
== ADD_R2_R2_R12
)
14589 bfd_put_32 (input_bfd
,
14590 ADDIS_R2_R12
+ PPC_HA (relocation
),
14591 contents
+ rel
->r_offset
);
14592 bfd_put_32 (input_bfd
,
14593 ADDI_R2_R2
+ PPC_LO (relocation
),
14594 contents
+ rel
->r_offset
+ 4);
14600 case R_PPC64_REL16_HA
:
14601 /* If we are generating a non-PIC executable, edit
14602 . 0: addis 2,12,.TOC.-0b@ha
14603 . addi 2,2,.TOC.-0b@l
14604 used by ELFv2 global entry points to set up r2, to
14607 if .TOC. is in range. */
14608 if (!bfd_link_pic (info
)
14609 && !info
->traditional_format
14611 && rel
->r_addend
== d_offset
14612 && h
!= NULL
&& &h
->elf
== htab
->elf
.hgot
14613 && rel
+ 1 < relend
14614 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_REL16_LO
)
14615 && rel
[1].r_offset
== rel
->r_offset
+ 4
14616 && rel
[1].r_addend
== rel
->r_addend
+ 4
14617 && relocation
+ 0x80008000 <= 0xffffffff)
14619 unsigned int insn1
, insn2
;
14620 bfd_vma offset
= rel
->r_offset
- d_offset
;
14621 insn1
= bfd_get_32 (input_bfd
, contents
+ offset
);
14622 insn2
= bfd_get_32 (input_bfd
, contents
+ offset
+ 4);
14623 if ((insn1
& 0xffff0000) == ADDIS_R2_R12
14624 && (insn2
& 0xffff0000) == ADDI_R2_R2
)
14626 r_type
= R_PPC64_ADDR16_HA
;
14627 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
14628 rel
->r_addend
-= d_offset
;
14629 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_ADDR16_LO
);
14630 rel
[1].r_addend
-= d_offset
+ 4;
14631 bfd_put_32 (input_bfd
, LIS_R2
, contents
+ offset
);
14637 /* Handle other relocations that tweak non-addend part of insn. */
14639 max_br_offset
= 1 << 25;
14640 addend
= rel
->r_addend
;
14641 reloc_dest
= DEST_NORMAL
;
14647 case R_PPC64_TOCSAVE
:
14648 if (relocation
+ addend
== (rel
->r_offset
14649 + input_section
->output_offset
14650 + input_section
->output_section
->vma
)
14651 && tocsave_find (htab
, NO_INSERT
,
14652 &local_syms
, rel
, input_bfd
))
14654 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
14656 || insn
== CROR_151515
|| insn
== CROR_313131
)
14657 bfd_put_32 (input_bfd
,
14658 STD_R2_0R1
+ STK_TOC (htab
),
14659 contents
+ rel
->r_offset
);
14663 /* Branch taken prediction relocations. */
14664 case R_PPC64_ADDR14_BRTAKEN
:
14665 case R_PPC64_REL14_BRTAKEN
:
14666 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
14667 /* Fall through. */
14669 /* Branch not taken prediction relocations. */
14670 case R_PPC64_ADDR14_BRNTAKEN
:
14671 case R_PPC64_REL14_BRNTAKEN
:
14672 insn
|= bfd_get_32 (input_bfd
,
14673 contents
+ rel
->r_offset
) & ~(0x01 << 21);
14674 /* Fall through. */
14676 case R_PPC64_REL14
:
14677 max_br_offset
= 1 << 15;
14678 /* Fall through. */
14680 case R_PPC64_REL24
:
14681 case R_PPC64_PLTCALL
:
14682 /* Calls to functions with a different TOC, such as calls to
14683 shared objects, need to alter the TOC pointer. This is
14684 done using a linkage stub. A REL24 branching to these
14685 linkage stubs needs to be followed by a nop, as the nop
14686 will be replaced with an instruction to restore the TOC
14691 && h
->oh
->is_func_descriptor
)
14692 fdh
= ppc_follow_link (h
->oh
);
14693 stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
, &orig_rel
,
14695 if (r_type
== R_PPC64_PLTCALL
14696 && stub_entry
!= NULL
14697 && (stub_entry
->stub_type
== ppc_stub_plt_call
14698 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
14701 if (stub_entry
!= NULL
14702 && (stub_entry
->stub_type
== ppc_stub_plt_call
14703 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
14704 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
14705 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
14707 bfd_boolean can_plt_call
= FALSE
;
14709 if (stub_entry
->stub_type
== ppc_stub_plt_call
14711 && htab
->params
->plt_localentry0
!= 0
14712 && is_elfv2_localentry0 (&h
->elf
))
14714 /* The function doesn't use or change r2. */
14715 can_plt_call
= TRUE
;
14718 /* All of these stubs may modify r2, so there must be a
14719 branch and link followed by a nop. The nop is
14720 replaced by an insn to restore r2. */
14721 else if (rel
->r_offset
+ 8 <= input_section
->size
)
14725 br
= bfd_get_32 (input_bfd
,
14726 contents
+ rel
->r_offset
);
14731 nop
= bfd_get_32 (input_bfd
,
14732 contents
+ rel
->r_offset
+ 4);
14733 if (nop
== LD_R2_0R1
+ STK_TOC (htab
))
14734 can_plt_call
= TRUE
;
14735 else if (nop
== NOP
14736 || nop
== CROR_151515
14737 || nop
== CROR_313131
)
14740 && (h
== htab
->tls_get_addr_fd
14741 || h
== htab
->tls_get_addr
)
14742 && htab
->params
->tls_get_addr_opt
)
14744 /* Special stub used, leave nop alone. */
14747 bfd_put_32 (input_bfd
,
14748 LD_R2_0R1
+ STK_TOC (htab
),
14749 contents
+ rel
->r_offset
+ 4);
14750 can_plt_call
= TRUE
;
14755 if (!can_plt_call
&& h
!= NULL
)
14757 const char *name
= h
->elf
.root
.root
.string
;
14762 if (strncmp (name
, "__libc_start_main", 17) == 0
14763 && (name
[17] == 0 || name
[17] == '@'))
14765 /* Allow crt1 branch to go via a toc adjusting
14766 stub. Other calls that never return could do
14767 the same, if we could detect such. */
14768 can_plt_call
= TRUE
;
14774 /* g++ as of 20130507 emits self-calls without a
14775 following nop. This is arguably wrong since we
14776 have conflicting information. On the one hand a
14777 global symbol and on the other a local call
14778 sequence, but don't error for this special case.
14779 It isn't possible to cheaply verify we have
14780 exactly such a call. Allow all calls to the same
14782 asection
*code_sec
= sec
;
14784 if (get_opd_info (sec
) != NULL
)
14786 bfd_vma off
= (relocation
+ addend
14787 - sec
->output_section
->vma
14788 - sec
->output_offset
);
14790 opd_entry_value (sec
, off
, &code_sec
, NULL
, FALSE
);
14792 if (code_sec
== input_section
)
14793 can_plt_call
= TRUE
;
14798 if (stub_entry
->stub_type
== ppc_stub_plt_call
14799 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14800 info
->callbacks
->einfo
14801 /* xgettext:c-format */
14802 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14803 "recompile with -fPIC\n"),
14804 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14806 info
->callbacks
->einfo
14807 /* xgettext:c-format */
14808 (_("%H: call to `%pT' lacks nop, can't restore toc; "
14809 "(-mcmodel=small toc adjust stub)\n"),
14810 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
14812 bfd_set_error (bfd_error_bad_value
);
14817 && (stub_entry
->stub_type
== ppc_stub_plt_call
14818 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
))
14819 unresolved_reloc
= FALSE
;
14822 if ((stub_entry
== NULL
14823 || stub_entry
->stub_type
== ppc_stub_long_branch
14824 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14825 && get_opd_info (sec
) != NULL
)
14827 /* The branch destination is the value of the opd entry. */
14828 bfd_vma off
= (relocation
+ addend
14829 - sec
->output_section
->vma
14830 - sec
->output_offset
);
14831 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
, FALSE
);
14832 if (dest
!= (bfd_vma
) -1)
14836 reloc_dest
= DEST_OPD
;
14840 /* If the branch is out of reach we ought to have a long
14842 from
= (rel
->r_offset
14843 + input_section
->output_offset
14844 + input_section
->output_section
->vma
);
14846 relocation
+= PPC64_LOCAL_ENTRY_OFFSET (fdh
14850 if (stub_entry
!= NULL
14851 && (stub_entry
->stub_type
== ppc_stub_long_branch
14852 || stub_entry
->stub_type
== ppc_stub_plt_branch
)
14853 && (r_type
== R_PPC64_ADDR14_BRTAKEN
14854 || r_type
== R_PPC64_ADDR14_BRNTAKEN
14855 || (relocation
+ addend
- from
+ max_br_offset
14856 < 2 * max_br_offset
)))
14857 /* Don't use the stub if this branch is in range. */
14860 if (stub_entry
!= NULL
)
14862 /* Munge up the value and addend so that we call the stub
14863 rather than the procedure directly. */
14864 asection
*stub_sec
= stub_entry
->group
->stub_sec
;
14866 if (stub_entry
->stub_type
== ppc_stub_save_res
)
14867 relocation
+= (stub_sec
->output_offset
14868 + stub_sec
->output_section
->vma
14869 + stub_sec
->size
- htab
->sfpr
->size
14870 - htab
->sfpr
->output_offset
14871 - htab
->sfpr
->output_section
->vma
);
14873 relocation
= (stub_entry
->stub_offset
14874 + stub_sec
->output_offset
14875 + stub_sec
->output_section
->vma
);
14877 reloc_dest
= DEST_STUB
;
14879 if ((stub_entry
->stub_type
== ppc_stub_plt_call
14880 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14881 && (ALWAYS_EMIT_R2SAVE
14882 || stub_entry
->stub_type
== ppc_stub_plt_call_r2save
)
14883 && rel
+ 1 < relend
14884 && rel
[1].r_offset
== rel
->r_offset
+ 4
14885 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOCSAVE
)
14893 /* Set 'a' bit. This is 0b00010 in BO field for branch
14894 on CR(BI) insns (BO == 001at or 011at), and 0b01000
14895 for branch on CTR insns (BO == 1a00t or 1a01t). */
14896 if ((insn
& (0x14 << 21)) == (0x04 << 21))
14897 insn
|= 0x02 << 21;
14898 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
14899 insn
|= 0x08 << 21;
14905 /* Invert 'y' bit if not the default. */
14906 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
14907 insn
^= 0x01 << 21;
14910 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
14913 /* NOP out calls to undefined weak functions.
14914 We can thus call a weak function without first
14915 checking whether the function is defined. */
14917 && h
->elf
.root
.type
== bfd_link_hash_undefweak
14918 && h
->elf
.dynindx
== -1
14919 && r_type
== R_PPC64_REL24
14923 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
14929 /* Set `addend'. */
14931 save_unresolved_reloc
= unresolved_reloc
;
14935 /* xgettext:c-format */
14936 _bfd_error_handler (_("%pB: %s unsupported"),
14937 input_bfd
, ppc64_elf_howto_table
[r_type
]->name
);
14939 bfd_set_error (bfd_error_bad_value
);
14945 case R_PPC64_TLSGD
:
14946 case R_PPC64_TLSLD
:
14947 case R_PPC64_TOCSAVE
:
14948 case R_PPC64_GNU_VTINHERIT
:
14949 case R_PPC64_GNU_VTENTRY
:
14950 case R_PPC64_ENTRY
:
14953 /* GOT16 relocations. Like an ADDR16 using the symbol's
14954 address in the GOT as relocation value instead of the
14955 symbol's value itself. Also, create a GOT entry for the
14956 symbol and put the symbol value there. */
14957 case R_PPC64_GOT_TLSGD16
:
14958 case R_PPC64_GOT_TLSGD16_LO
:
14959 case R_PPC64_GOT_TLSGD16_HI
:
14960 case R_PPC64_GOT_TLSGD16_HA
:
14961 tls_type
= TLS_TLS
| TLS_GD
;
14964 case R_PPC64_GOT_TLSLD16
:
14965 case R_PPC64_GOT_TLSLD16_LO
:
14966 case R_PPC64_GOT_TLSLD16_HI
:
14967 case R_PPC64_GOT_TLSLD16_HA
:
14968 tls_type
= TLS_TLS
| TLS_LD
;
14971 case R_PPC64_GOT_TPREL16_DS
:
14972 case R_PPC64_GOT_TPREL16_LO_DS
:
14973 case R_PPC64_GOT_TPREL16_HI
:
14974 case R_PPC64_GOT_TPREL16_HA
:
14975 tls_type
= TLS_TLS
| TLS_TPREL
;
14978 case R_PPC64_GOT_DTPREL16_DS
:
14979 case R_PPC64_GOT_DTPREL16_LO_DS
:
14980 case R_PPC64_GOT_DTPREL16_HI
:
14981 case R_PPC64_GOT_DTPREL16_HA
:
14982 tls_type
= TLS_TLS
| TLS_DTPREL
;
14985 case R_PPC64_GOT16
:
14986 case R_PPC64_GOT16_LO
:
14987 case R_PPC64_GOT16_HI
:
14988 case R_PPC64_GOT16_HA
:
14989 case R_PPC64_GOT16_DS
:
14990 case R_PPC64_GOT16_LO_DS
:
14993 /* Relocation is to the entry for this symbol in the global
14998 unsigned long indx
= 0;
14999 struct got_entry
*ent
;
15001 if (tls_type
== (TLS_TLS
| TLS_LD
)
15003 || !h
->elf
.def_dynamic
))
15004 ent
= ppc64_tlsld_got (input_bfd
);
15009 if (!htab
->elf
.dynamic_sections_created
15010 || h
->elf
.dynindx
== -1
15011 || SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
15012 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
))
15013 /* This is actually a static link, or it is a
15014 -Bsymbolic link and the symbol is defined
15015 locally, or the symbol was forced to be local
15016 because of a version file. */
15020 indx
= h
->elf
.dynindx
;
15021 unresolved_reloc
= FALSE
;
15023 ent
= h
->elf
.got
.glist
;
15027 if (local_got_ents
== NULL
)
15029 ent
= local_got_ents
[r_symndx
];
15032 for (; ent
!= NULL
; ent
= ent
->next
)
15033 if (ent
->addend
== orig_rel
.r_addend
15034 && ent
->owner
== input_bfd
15035 && ent
->tls_type
== tls_type
)
15041 if (ent
->is_indirect
)
15042 ent
= ent
->got
.ent
;
15043 offp
= &ent
->got
.offset
;
15044 got
= ppc64_elf_tdata (ent
->owner
)->got
;
15048 /* The offset must always be a multiple of 8. We use the
15049 least significant bit to record whether we have already
15050 processed this entry. */
15052 if ((off
& 1) != 0)
15056 /* Generate relocs for the dynamic linker, except in
15057 the case of TLSLD where we'll use one entry per
15065 ? h
->elf
.type
== STT_GNU_IFUNC
15066 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
);
15069 relgot
= htab
->elf
.irelplt
;
15071 htab
->local_ifunc_resolver
= 1;
15072 else if (is_static_defined (&h
->elf
))
15073 htab
->maybe_local_ifunc_resolver
= 1;
15076 || (bfd_link_pic (info
)
15078 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &h
->elf
)
15079 || (tls_type
== (TLS_TLS
| TLS_LD
)
15080 && !h
->elf
.def_dynamic
))
15081 && !(tls_type
== (TLS_TLS
| TLS_TPREL
)
15082 && bfd_link_executable (info
)
15083 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
))))
15084 relgot
= ppc64_elf_tdata (ent
->owner
)->relgot
;
15085 if (relgot
!= NULL
)
15087 outrel
.r_offset
= (got
->output_section
->vma
15088 + got
->output_offset
15090 outrel
.r_addend
= addend
;
15091 if (tls_type
& (TLS_LD
| TLS_GD
))
15093 outrel
.r_addend
= 0;
15094 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
15095 if (tls_type
== (TLS_TLS
| TLS_GD
))
15097 loc
= relgot
->contents
;
15098 loc
+= (relgot
->reloc_count
++
15099 * sizeof (Elf64_External_Rela
));
15100 bfd_elf64_swap_reloca_out (output_bfd
,
15102 outrel
.r_offset
+= 8;
15103 outrel
.r_addend
= addend
;
15105 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
15108 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
15109 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
15110 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
15111 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
15112 else if (indx
!= 0)
15113 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
15117 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15119 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
15121 /* Write the .got section contents for the sake
15123 loc
= got
->contents
+ off
;
15124 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
15128 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
15130 outrel
.r_addend
+= relocation
;
15131 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
15133 if (htab
->elf
.tls_sec
== NULL
)
15134 outrel
.r_addend
= 0;
15136 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
15139 loc
= relgot
->contents
;
15140 loc
+= (relgot
->reloc_count
++
15141 * sizeof (Elf64_External_Rela
));
15142 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
15145 /* Init the .got section contents here if we're not
15146 emitting a reloc. */
15149 relocation
+= addend
;
15152 if (htab
->elf
.tls_sec
== NULL
)
15156 if (tls_type
& TLS_LD
)
15159 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15160 if (tls_type
& TLS_TPREL
)
15161 relocation
+= DTP_OFFSET
- TP_OFFSET
;
15164 if (tls_type
& (TLS_GD
| TLS_LD
))
15166 bfd_put_64 (output_bfd
, relocation
,
15167 got
->contents
+ off
+ 8);
15171 bfd_put_64 (output_bfd
, relocation
,
15172 got
->contents
+ off
);
15176 if (off
>= (bfd_vma
) -2)
15179 relocation
= got
->output_section
->vma
+ got
->output_offset
+ off
;
15180 addend
= -(TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
);
15184 case R_PPC64_PLT16_HA
:
15185 case R_PPC64_PLT16_HI
:
15186 case R_PPC64_PLT16_LO
:
15187 case R_PPC64_PLT16_LO_DS
:
15188 case R_PPC64_PLT32
:
15189 case R_PPC64_PLT64
:
15190 case R_PPC64_PLTSEQ
:
15191 case R_PPC64_PLTCALL
:
15192 /* Relocation is to the entry for this symbol in the
15193 procedure linkage table. */
15194 unresolved_reloc
= TRUE
;
15196 struct plt_entry
**plt_list
= NULL
;
15198 plt_list
= &h
->elf
.plt
.plist
;
15199 else if (local_got_ents
!= NULL
)
15201 struct plt_entry
**local_plt
= (struct plt_entry
**)
15202 (local_got_ents
+ symtab_hdr
->sh_info
);
15203 plt_list
= local_plt
+ r_symndx
;
15207 struct plt_entry
*ent
;
15209 for (ent
= *plt_list
; ent
!= NULL
; ent
= ent
->next
)
15210 if (ent
->plt
.offset
!= (bfd_vma
) -1
15211 && ent
->addend
== orig_rel
.r_addend
)
15216 plt
= htab
->elf
.splt
;
15217 if (!htab
->elf
.dynamic_sections_created
15219 || h
->elf
.dynindx
== -1)
15222 ? h
->elf
.type
== STT_GNU_IFUNC
15223 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15224 plt
= htab
->elf
.iplt
;
15226 plt
= htab
->pltlocal
;
15228 relocation
= (plt
->output_section
->vma
15229 + plt
->output_offset
15230 + ent
->plt
.offset
);
15231 if (r_type
== R_PPC64_PLT16_HA
15232 || r_type
==R_PPC64_PLT16_HI
15233 || r_type
==R_PPC64_PLT16_LO
15234 || r_type
==R_PPC64_PLT16_LO_DS
)
15236 got
= (elf_gp (output_bfd
)
15237 + htab
->sec_info
[input_section
->id
].toc_off
);
15241 unresolved_reloc
= FALSE
;
15249 /* Relocation value is TOC base. */
15250 relocation
= TOCstart
;
15251 if (r_symndx
== STN_UNDEF
)
15252 relocation
+= htab
->sec_info
[input_section
->id
].toc_off
;
15253 else if (unresolved_reloc
)
15255 else if (sec
!= NULL
&& sec
->id
< htab
->sec_info_arr_size
)
15256 relocation
+= htab
->sec_info
[sec
->id
].toc_off
;
15258 unresolved_reloc
= TRUE
;
15261 /* TOC16 relocs. We want the offset relative to the TOC base,
15262 which is the address of the start of the TOC plus 0x8000.
15263 The TOC consists of sections .got, .toc, .tocbss, and .plt,
15265 case R_PPC64_TOC16
:
15266 case R_PPC64_TOC16_LO
:
15267 case R_PPC64_TOC16_HI
:
15268 case R_PPC64_TOC16_DS
:
15269 case R_PPC64_TOC16_LO_DS
:
15270 case R_PPC64_TOC16_HA
:
15271 addend
-= TOCstart
+ htab
->sec_info
[input_section
->id
].toc_off
;
15274 /* Relocate against the beginning of the section. */
15275 case R_PPC64_SECTOFF
:
15276 case R_PPC64_SECTOFF_LO
:
15277 case R_PPC64_SECTOFF_HI
:
15278 case R_PPC64_SECTOFF_DS
:
15279 case R_PPC64_SECTOFF_LO_DS
:
15280 case R_PPC64_SECTOFF_HA
:
15282 addend
-= sec
->output_section
->vma
;
15285 case R_PPC64_REL16
:
15286 case R_PPC64_REL16_LO
:
15287 case R_PPC64_REL16_HI
:
15288 case R_PPC64_REL16_HA
:
15289 case R_PPC64_REL16DX_HA
:
15292 case R_PPC64_REL14
:
15293 case R_PPC64_REL14_BRNTAKEN
:
15294 case R_PPC64_REL14_BRTAKEN
:
15295 case R_PPC64_REL24
:
15298 case R_PPC64_TPREL16
:
15299 case R_PPC64_TPREL16_LO
:
15300 case R_PPC64_TPREL16_HI
:
15301 case R_PPC64_TPREL16_HA
:
15302 case R_PPC64_TPREL16_DS
:
15303 case R_PPC64_TPREL16_LO_DS
:
15304 case R_PPC64_TPREL16_HIGH
:
15305 case R_PPC64_TPREL16_HIGHA
:
15306 case R_PPC64_TPREL16_HIGHER
:
15307 case R_PPC64_TPREL16_HIGHERA
:
15308 case R_PPC64_TPREL16_HIGHEST
:
15309 case R_PPC64_TPREL16_HIGHESTA
:
15311 && h
->elf
.root
.type
== bfd_link_hash_undefweak
15312 && h
->elf
.dynindx
== -1)
15314 /* Make this relocation against an undefined weak symbol
15315 resolve to zero. This is really just a tweak, since
15316 code using weak externs ought to check that they are
15317 defined before using them. */
15318 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
15320 insn
= bfd_get_32 (input_bfd
, p
);
15321 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 13);
15323 bfd_put_32 (input_bfd
, insn
, p
);
15326 if (htab
->elf
.tls_sec
!= NULL
)
15327 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15328 /* The TPREL16 relocs shouldn't really be used in shared
15329 libs or with non-local symbols as that will result in
15330 DT_TEXTREL being set, but support them anyway. */
15333 case R_PPC64_DTPREL16
:
15334 case R_PPC64_DTPREL16_LO
:
15335 case R_PPC64_DTPREL16_HI
:
15336 case R_PPC64_DTPREL16_HA
:
15337 case R_PPC64_DTPREL16_DS
:
15338 case R_PPC64_DTPREL16_LO_DS
:
15339 case R_PPC64_DTPREL16_HIGH
:
15340 case R_PPC64_DTPREL16_HIGHA
:
15341 case R_PPC64_DTPREL16_HIGHER
:
15342 case R_PPC64_DTPREL16_HIGHERA
:
15343 case R_PPC64_DTPREL16_HIGHEST
:
15344 case R_PPC64_DTPREL16_HIGHESTA
:
15345 if (htab
->elf
.tls_sec
!= NULL
)
15346 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15349 case R_PPC64_ADDR64_LOCAL
:
15350 addend
+= PPC64_LOCAL_ENTRY_OFFSET (h
!= NULL
15355 case R_PPC64_DTPMOD64
:
15360 case R_PPC64_TPREL64
:
15361 if (htab
->elf
.tls_sec
!= NULL
)
15362 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
15365 case R_PPC64_DTPREL64
:
15366 if (htab
->elf
.tls_sec
!= NULL
)
15367 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
15368 /* Fall through. */
15370 /* Relocations that may need to be propagated if this is a
15372 case R_PPC64_REL30
:
15373 case R_PPC64_REL32
:
15374 case R_PPC64_REL64
:
15375 case R_PPC64_ADDR14
:
15376 case R_PPC64_ADDR14_BRNTAKEN
:
15377 case R_PPC64_ADDR14_BRTAKEN
:
15378 case R_PPC64_ADDR16
:
15379 case R_PPC64_ADDR16_DS
:
15380 case R_PPC64_ADDR16_HA
:
15381 case R_PPC64_ADDR16_HI
:
15382 case R_PPC64_ADDR16_HIGH
:
15383 case R_PPC64_ADDR16_HIGHA
:
15384 case R_PPC64_ADDR16_HIGHER
:
15385 case R_PPC64_ADDR16_HIGHERA
:
15386 case R_PPC64_ADDR16_HIGHEST
:
15387 case R_PPC64_ADDR16_HIGHESTA
:
15388 case R_PPC64_ADDR16_LO
:
15389 case R_PPC64_ADDR16_LO_DS
:
15390 case R_PPC64_ADDR24
:
15391 case R_PPC64_ADDR32
:
15392 case R_PPC64_ADDR64
:
15393 case R_PPC64_UADDR16
:
15394 case R_PPC64_UADDR32
:
15395 case R_PPC64_UADDR64
:
15397 if ((input_section
->flags
& SEC_ALLOC
) == 0)
15400 if (NO_OPD_RELOCS
&& is_opd
)
15403 if (bfd_link_pic (info
)
15405 || h
->dyn_relocs
!= NULL
)
15406 && ((h
!= NULL
&& pc_dynrelocs (h
))
15407 || must_be_dyn_reloc (info
, r_type
)))
15409 ? h
->dyn_relocs
!= NULL
15410 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
15412 bfd_boolean skip
, relocate
;
15417 /* When generating a dynamic object, these relocations
15418 are copied into the output file to be resolved at run
15424 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
15425 input_section
, rel
->r_offset
);
15426 if (out_off
== (bfd_vma
) -1)
15428 else if (out_off
== (bfd_vma
) -2)
15429 skip
= TRUE
, relocate
= TRUE
;
15430 out_off
+= (input_section
->output_section
->vma
15431 + input_section
->output_offset
);
15432 outrel
.r_offset
= out_off
;
15433 outrel
.r_addend
= rel
->r_addend
;
15435 /* Optimize unaligned reloc use. */
15436 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
15437 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
15438 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
15439 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
15440 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
15441 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
15442 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
15443 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
15444 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
15447 memset (&outrel
, 0, sizeof outrel
);
15448 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
15450 && r_type
!= R_PPC64_TOC
)
15452 indx
= h
->elf
.dynindx
;
15453 BFD_ASSERT (indx
!= -1);
15454 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15458 /* This symbol is local, or marked to become local,
15459 or this is an opd section reloc which must point
15460 at a local function. */
15461 outrel
.r_addend
+= relocation
;
15462 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
15464 if (is_opd
&& h
!= NULL
)
15466 /* Lie about opd entries. This case occurs
15467 when building shared libraries and we
15468 reference a function in another shared
15469 lib. The same thing happens for a weak
15470 definition in an application that's
15471 overridden by a strong definition in a
15472 shared lib. (I believe this is a generic
15473 bug in binutils handling of weak syms.)
15474 In these cases we won't use the opd
15475 entry in this lib. */
15476 unresolved_reloc
= FALSE
;
15479 && r_type
== R_PPC64_ADDR64
15481 ? h
->elf
.type
== STT_GNU_IFUNC
15482 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
))
15483 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_IRELATIVE
);
15486 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
15488 /* We need to relocate .opd contents for ld.so.
15489 Prelink also wants simple and consistent rules
15490 for relocs. This make all RELATIVE relocs have
15491 *r_offset equal to r_addend. */
15498 ? h
->elf
.type
== STT_GNU_IFUNC
15499 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15501 info
->callbacks
->einfo
15502 /* xgettext:c-format */
15503 (_("%H: %s for indirect "
15504 "function `%pT' unsupported\n"),
15505 input_bfd
, input_section
, rel
->r_offset
,
15506 ppc64_elf_howto_table
[r_type
]->name
,
15510 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
15512 else if (sec
== NULL
|| sec
->owner
== NULL
)
15514 bfd_set_error (bfd_error_bad_value
);
15521 osec
= sec
->output_section
;
15522 indx
= elf_section_data (osec
)->dynindx
;
15526 if ((osec
->flags
& SEC_READONLY
) == 0
15527 && htab
->elf
.data_index_section
!= NULL
)
15528 osec
= htab
->elf
.data_index_section
;
15530 osec
= htab
->elf
.text_index_section
;
15531 indx
= elf_section_data (osec
)->dynindx
;
15533 BFD_ASSERT (indx
!= 0);
15535 /* We are turning this relocation into one
15536 against a section symbol, so subtract out
15537 the output section's address but not the
15538 offset of the input section in the output
15540 outrel
.r_addend
-= osec
->vma
;
15543 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
15547 sreloc
= elf_section_data (input_section
)->sreloc
;
15549 ? h
->elf
.type
== STT_GNU_IFUNC
15550 : ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
15552 sreloc
= htab
->elf
.irelplt
;
15554 htab
->local_ifunc_resolver
= 1;
15555 else if (is_static_defined (&h
->elf
))
15556 htab
->maybe_local_ifunc_resolver
= 1;
15558 if (sreloc
== NULL
)
15561 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
15564 loc
= sreloc
->contents
;
15565 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
15566 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
15568 /* If this reloc is against an external symbol, it will
15569 be computed at runtime, so there's no need to do
15570 anything now. However, for the sake of prelink ensure
15571 that the section contents are a known value. */
15574 unresolved_reloc
= FALSE
;
15575 /* The value chosen here is quite arbitrary as ld.so
15576 ignores section contents except for the special
15577 case of .opd where the contents might be accessed
15578 before relocation. Choose zero, as that won't
15579 cause reloc overflow. */
15582 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
15583 to improve backward compatibility with older
15585 if (r_type
== R_PPC64_ADDR64
)
15586 addend
= outrel
.r_addend
;
15587 /* Adjust pc_relative relocs to have zero in *r_offset. */
15588 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
15589 addend
= outrel
.r_offset
;
15595 case R_PPC64_GLOB_DAT
:
15596 case R_PPC64_JMP_SLOT
:
15597 case R_PPC64_JMP_IREL
:
15598 case R_PPC64_RELATIVE
:
15599 /* We shouldn't ever see these dynamic relocs in relocatable
15601 /* Fall through. */
15603 case R_PPC64_PLTGOT16
:
15604 case R_PPC64_PLTGOT16_DS
:
15605 case R_PPC64_PLTGOT16_HA
:
15606 case R_PPC64_PLTGOT16_HI
:
15607 case R_PPC64_PLTGOT16_LO
:
15608 case R_PPC64_PLTGOT16_LO_DS
:
15609 case R_PPC64_PLTREL32
:
15610 case R_PPC64_PLTREL64
:
15611 /* These ones haven't been implemented yet. */
15613 info
->callbacks
->einfo
15614 /* xgettext:c-format */
15615 (_("%P: %pB: %s is not supported for `%pT'\n"),
15617 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
15619 bfd_set_error (bfd_error_invalid_operation
);
15624 /* Multi-instruction sequences that access the TOC can be
15625 optimized, eg. addis ra,r2,0; addi rb,ra,x;
15626 to nop; addi rb,r2,x; */
15632 case R_PPC64_GOT_TLSLD16_HI
:
15633 case R_PPC64_GOT_TLSGD16_HI
:
15634 case R_PPC64_GOT_TPREL16_HI
:
15635 case R_PPC64_GOT_DTPREL16_HI
:
15636 case R_PPC64_GOT16_HI
:
15637 case R_PPC64_TOC16_HI
:
15638 /* These relocs would only be useful if building up an
15639 offset to later add to r2, perhaps in an indexed
15640 addressing mode instruction. Don't try to optimize.
15641 Unfortunately, the possibility of someone building up an
15642 offset like this or even with the HA relocs, means that
15643 we need to check the high insn when optimizing the low
15647 case R_PPC64_PLTCALL
:
15648 if (unresolved_reloc
)
15650 /* No plt entry. Make this into a direct call. */
15651 bfd_byte
*p
= contents
+ rel
->r_offset
;
15652 insn
= bfd_get_32 (input_bfd
, p
);
15654 bfd_put_32 (input_bfd
, B_DOT
| insn
, p
);
15655 bfd_put_32 (input_bfd
, NOP
, p
+ 4);
15656 unresolved_reloc
= save_unresolved_reloc
;
15657 r_type
= R_PPC64_REL24
;
15661 case R_PPC64_PLTSEQ
:
15662 if (unresolved_reloc
)
15664 unresolved_reloc
= FALSE
;
15669 case R_PPC64_PLT16_HA
:
15670 if (unresolved_reloc
)
15672 unresolved_reloc
= FALSE
;
15675 /* Fall through. */
15676 case R_PPC64_GOT_TLSLD16_HA
:
15677 case R_PPC64_GOT_TLSGD16_HA
:
15678 case R_PPC64_GOT_TPREL16_HA
:
15679 case R_PPC64_GOT_DTPREL16_HA
:
15680 case R_PPC64_GOT16_HA
:
15681 case R_PPC64_TOC16_HA
:
15682 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15683 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15687 p
= contents
+ (rel
->r_offset
& ~3);
15688 bfd_put_32 (input_bfd
, NOP
, p
);
15693 case R_PPC64_PLT16_LO
:
15694 case R_PPC64_PLT16_LO_DS
:
15695 if (unresolved_reloc
)
15697 unresolved_reloc
= FALSE
;
15700 /* Fall through. */
15701 case R_PPC64_GOT_TLSLD16_LO
:
15702 case R_PPC64_GOT_TLSGD16_LO
:
15703 case R_PPC64_GOT_TPREL16_LO_DS
:
15704 case R_PPC64_GOT_DTPREL16_LO_DS
:
15705 case R_PPC64_GOT16_LO
:
15706 case R_PPC64_GOT16_LO_DS
:
15707 case R_PPC64_TOC16_LO
:
15708 case R_PPC64_TOC16_LO_DS
:
15709 if (htab
->do_toc_opt
&& relocation
+ addend
+ 0x8000 < 0x10000
15710 && !ppc64_elf_tdata (input_bfd
)->unexpected_toc_insn
)
15712 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15713 insn
= bfd_get_32 (input_bfd
, p
);
15714 if ((insn
& (0x3f << 26)) == 12u << 26 /* addic */)
15716 /* Transform addic to addi when we change reg. */
15717 insn
&= ~((0x3f << 26) | (0x1f << 16));
15718 insn
|= (14u << 26) | (2 << 16);
15722 insn
&= ~(0x1f << 16);
15725 bfd_put_32 (input_bfd
, insn
, p
);
15729 case R_PPC64_TPREL16_HA
:
15730 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15732 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15733 insn
= bfd_get_32 (input_bfd
, p
);
15734 if ((insn
& ((0x3f << 26) | 0x1f << 16))
15735 != ((15u << 26) | (13 << 16)) /* addis rt,13,imm */)
15736 /* xgettext:c-format */
15737 info
->callbacks
->minfo
15738 (_("%H: warning: %s unexpected insn %#x.\n"),
15739 input_bfd
, input_section
, rel
->r_offset
,
15740 ppc64_elf_howto_table
[r_type
]->name
, insn
);
15743 bfd_put_32 (input_bfd
, NOP
, p
);
15749 case R_PPC64_TPREL16_LO
:
15750 case R_PPC64_TPREL16_LO_DS
:
15751 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
15753 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
15754 insn
= bfd_get_32 (input_bfd
, p
);
15755 insn
&= ~(0x1f << 16);
15757 bfd_put_32 (input_bfd
, insn
, p
);
15762 /* Do any further special processing. */
15768 case R_PPC64_REL16_HA
:
15769 case R_PPC64_REL16DX_HA
:
15770 case R_PPC64_ADDR16_HA
:
15771 case R_PPC64_ADDR16_HIGHA
:
15772 case R_PPC64_ADDR16_HIGHERA
:
15773 case R_PPC64_ADDR16_HIGHESTA
:
15774 case R_PPC64_TOC16_HA
:
15775 case R_PPC64_SECTOFF_HA
:
15776 case R_PPC64_TPREL16_HA
:
15777 case R_PPC64_TPREL16_HIGHA
:
15778 case R_PPC64_TPREL16_HIGHERA
:
15779 case R_PPC64_TPREL16_HIGHESTA
:
15780 case R_PPC64_DTPREL16_HA
:
15781 case R_PPC64_DTPREL16_HIGHA
:
15782 case R_PPC64_DTPREL16_HIGHERA
:
15783 case R_PPC64_DTPREL16_HIGHESTA
:
15784 /* It's just possible that this symbol is a weak symbol
15785 that's not actually defined anywhere. In that case,
15786 'sec' would be NULL, and we should leave the symbol
15787 alone (it will be set to zero elsewhere in the link). */
15790 /* Fall through. */
15792 case R_PPC64_GOT16_HA
:
15793 case R_PPC64_PLTGOT16_HA
:
15794 case R_PPC64_PLT16_HA
:
15795 case R_PPC64_GOT_TLSGD16_HA
:
15796 case R_PPC64_GOT_TLSLD16_HA
:
15797 case R_PPC64_GOT_TPREL16_HA
:
15798 case R_PPC64_GOT_DTPREL16_HA
:
15799 /* Add 0x10000 if sign bit in 0:15 is set.
15800 Bits 0:15 are not used. */
15804 case R_PPC64_ADDR16_DS
:
15805 case R_PPC64_ADDR16_LO_DS
:
15806 case R_PPC64_GOT16_DS
:
15807 case R_PPC64_GOT16_LO_DS
:
15808 case R_PPC64_PLT16_LO_DS
:
15809 case R_PPC64_SECTOFF_DS
:
15810 case R_PPC64_SECTOFF_LO_DS
:
15811 case R_PPC64_TOC16_DS
:
15812 case R_PPC64_TOC16_LO_DS
:
15813 case R_PPC64_PLTGOT16_DS
:
15814 case R_PPC64_PLTGOT16_LO_DS
:
15815 case R_PPC64_GOT_TPREL16_DS
:
15816 case R_PPC64_GOT_TPREL16_LO_DS
:
15817 case R_PPC64_GOT_DTPREL16_DS
:
15818 case R_PPC64_GOT_DTPREL16_LO_DS
:
15819 case R_PPC64_TPREL16_DS
:
15820 case R_PPC64_TPREL16_LO_DS
:
15821 case R_PPC64_DTPREL16_DS
:
15822 case R_PPC64_DTPREL16_LO_DS
:
15823 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15825 /* If this reloc is against an lq, lxv, or stxv insn, then
15826 the value must be a multiple of 16. This is somewhat of
15827 a hack, but the "correct" way to do this by defining _DQ
15828 forms of all the _DS relocs bloats all reloc switches in
15829 this file. It doesn't make much sense to use these
15830 relocs in data, so testing the insn should be safe. */
15831 if ((insn
& (0x3f << 26)) == (56u << 26)
15832 || ((insn
& (0x3f << 26)) == (61u << 26) && (insn
& 3) == 1))
15834 relocation
+= addend
;
15835 addend
= insn
& (mask
^ 3);
15836 if ((relocation
& mask
) != 0)
15838 relocation
^= relocation
& mask
;
15839 info
->callbacks
->einfo
15840 /* xgettext:c-format */
15841 (_("%H: error: %s not a multiple of %u\n"),
15842 input_bfd
, input_section
, rel
->r_offset
,
15843 ppc64_elf_howto_table
[r_type
]->name
,
15845 bfd_set_error (bfd_error_bad_value
);
15852 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
15853 because such sections are not SEC_ALLOC and thus ld.so will
15854 not process them. */
15855 howto
= ppc64_elf_howto_table
[(int) r_type
];
15856 if (unresolved_reloc
15857 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
15858 && h
->elf
.def_dynamic
)
15859 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
15860 rel
->r_offset
) != (bfd_vma
) -1)
15862 info
->callbacks
->einfo
15863 /* xgettext:c-format */
15864 (_("%H: unresolvable %s against `%pT'\n"),
15865 input_bfd
, input_section
, rel
->r_offset
,
15867 h
->elf
.root
.root
.string
);
15871 /* 16-bit fields in insns mostly have signed values, but a
15872 few insns have 16-bit unsigned values. Really, we should
15873 have different reloc types. */
15874 if (howto
->complain_on_overflow
!= complain_overflow_dont
15875 && howto
->dst_mask
== 0xffff
15876 && (input_section
->flags
& SEC_CODE
) != 0)
15878 enum complain_overflow complain
= complain_overflow_signed
;
15880 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
15881 if ((insn
& (0x3f << 26)) == 10u << 26 /* cmpli */)
15882 complain
= complain_overflow_bitfield
;
15883 else if (howto
->rightshift
== 0
15884 ? ((insn
& (0x3f << 26)) == 28u << 26 /* andi */
15885 || (insn
& (0x3f << 26)) == 24u << 26 /* ori */
15886 || (insn
& (0x3f << 26)) == 26u << 26 /* xori */)
15887 : ((insn
& (0x3f << 26)) == 29u << 26 /* andis */
15888 || (insn
& (0x3f << 26)) == 25u << 26 /* oris */
15889 || (insn
& (0x3f << 26)) == 27u << 26 /* xoris */))
15890 complain
= complain_overflow_unsigned
;
15891 if (howto
->complain_on_overflow
!= complain
)
15893 alt_howto
= *howto
;
15894 alt_howto
.complain_on_overflow
= complain
;
15895 howto
= &alt_howto
;
15899 if (r_type
== R_PPC64_REL16DX_HA
)
15901 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
15902 if (rel
->r_offset
+ 4 > input_section
->size
)
15903 r
= bfd_reloc_outofrange
;
15906 relocation
+= addend
;
15907 relocation
-= (rel
->r_offset
15908 + input_section
->output_offset
15909 + input_section
->output_section
->vma
);
15910 relocation
= (bfd_signed_vma
) relocation
>> 16;
15911 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
15913 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
15914 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
15916 if (relocation
+ 0x8000 > 0xffff)
15917 r
= bfd_reloc_overflow
;
15921 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
15922 rel
->r_offset
, relocation
, addend
);
15924 if (r
!= bfd_reloc_ok
)
15926 char *more_info
= NULL
;
15927 const char *reloc_name
= howto
->name
;
15929 if (reloc_dest
!= DEST_NORMAL
)
15931 more_info
= bfd_malloc (strlen (reloc_name
) + 8);
15932 if (more_info
!= NULL
)
15934 strcpy (more_info
, reloc_name
);
15935 strcat (more_info
, (reloc_dest
== DEST_OPD
15936 ? " (OPD)" : " (stub)"));
15937 reloc_name
= more_info
;
15941 if (r
== bfd_reloc_overflow
)
15943 /* On code like "if (foo) foo();" don't report overflow
15944 on a branch to zero when foo is undefined. */
15946 && (reloc_dest
== DEST_STUB
15948 && (h
->elf
.root
.type
== bfd_link_hash_undefweak
15949 || h
->elf
.root
.type
== bfd_link_hash_undefined
)
15950 && is_branch_reloc (r_type
))))
15951 info
->callbacks
->reloc_overflow (info
, &h
->elf
.root
,
15952 sym_name
, reloc_name
,
15954 input_bfd
, input_section
,
15959 info
->callbacks
->einfo
15960 /* xgettext:c-format */
15961 (_("%H: %s against `%pT': error %d\n"),
15962 input_bfd
, input_section
, rel
->r_offset
,
15963 reloc_name
, sym_name
, (int) r
);
15966 if (more_info
!= NULL
)
15976 Elf_Internal_Shdr
*rel_hdr
;
15977 size_t deleted
= rel
- wrel
;
15979 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
15980 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15981 if (rel_hdr
->sh_size
== 0)
15983 /* It is too late to remove an empty reloc section. Leave
15985 ??? What is wrong with an empty section??? */
15986 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
15989 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
15990 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
15991 input_section
->reloc_count
-= deleted
;
15994 /* If we're emitting relocations, then shortly after this function
15995 returns, reloc offsets and addends for this section will be
15996 adjusted. Worse, reloc symbol indices will be for the output
15997 file rather than the input. Save a copy of the relocs for
15998 opd_entry_value. */
15999 if (is_opd
&& (info
->emitrelocations
|| bfd_link_relocatable (info
)))
16002 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
16003 rel
= bfd_alloc (input_bfd
, amt
);
16004 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd
.relocs
== NULL
);
16005 ppc64_elf_tdata (input_bfd
)->opd
.relocs
= rel
;
16008 memcpy (rel
, relocs
, amt
);
16013 /* Adjust the value of any local symbols in opd sections. */
16016 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
16017 const char *name ATTRIBUTE_UNUSED
,
16018 Elf_Internal_Sym
*elfsym
,
16019 asection
*input_sec
,
16020 struct elf_link_hash_entry
*h
)
16022 struct _opd_sec_data
*opd
;
16029 opd
= get_opd_info (input_sec
);
16030 if (opd
== NULL
|| opd
->adjust
== NULL
)
16033 value
= elfsym
->st_value
- input_sec
->output_offset
;
16034 if (!bfd_link_relocatable (info
))
16035 value
-= input_sec
->output_section
->vma
;
16037 adjust
= opd
->adjust
[OPD_NDX (value
)];
16041 elfsym
->st_value
+= adjust
;
16045 /* Finish up dynamic symbol handling. We set the contents of various
16046 dynamic sections here. */
16049 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
16050 struct bfd_link_info
*info
,
16051 struct elf_link_hash_entry
*h
,
16052 Elf_Internal_Sym
*sym
)
16054 struct ppc_link_hash_table
*htab
;
16055 struct plt_entry
*ent
;
16057 htab
= ppc_hash_table (info
);
16061 if (!htab
->opd_abi
&& !h
->def_regular
)
16062 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
16063 if (ent
->plt
.offset
!= (bfd_vma
) -1)
16065 /* Mark the symbol as undefined, rather than as
16066 defined in glink. Leave the value if there were
16067 any relocations where pointer equality matters
16068 (this is a clue for the dynamic linker, to make
16069 function pointer comparisons work between an
16070 application and shared library), otherwise set it
16072 sym
->st_shndx
= SHN_UNDEF
;
16073 if (!h
->pointer_equality_needed
)
16075 else if (!h
->ref_regular_nonweak
)
16077 /* This breaks function pointer comparisons, but
16078 that is better than breaking tests for a NULL
16079 function pointer. */
16087 /* This symbol needs a copy reloc. Set it up. */
16088 Elf_Internal_Rela rela
;
16092 if (h
->dynindx
== -1
16093 || (h
->root
.type
!= bfd_link_hash_defined
16094 && h
->root
.type
!= bfd_link_hash_defweak
)
16095 || htab
->elf
.srelbss
== NULL
16096 || htab
->elf
.sreldynrelro
== NULL
)
16099 rela
.r_offset
= (h
->root
.u
.def
.value
16100 + h
->root
.u
.def
.section
->output_section
->vma
16101 + h
->root
.u
.def
.section
->output_offset
);
16102 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
16104 if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
16105 srel
= htab
->elf
.sreldynrelro
;
16107 srel
= htab
->elf
.srelbss
;
16108 loc
= srel
->contents
;
16109 loc
+= srel
->reloc_count
++ * sizeof (Elf64_External_Rela
);
16110 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
16116 /* Used to decide how to sort relocs in an optimal manner for the
16117 dynamic linker, before writing them out. */
16119 static enum elf_reloc_type_class
16120 ppc64_elf_reloc_type_class (const struct bfd_link_info
*info
,
16121 const asection
*rel_sec
,
16122 const Elf_Internal_Rela
*rela
)
16124 enum elf_ppc64_reloc_type r_type
;
16125 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
16127 if (rel_sec
== htab
->elf
.irelplt
)
16128 return reloc_class_ifunc
;
16130 r_type
= ELF64_R_TYPE (rela
->r_info
);
16133 case R_PPC64_RELATIVE
:
16134 return reloc_class_relative
;
16135 case R_PPC64_JMP_SLOT
:
16136 return reloc_class_plt
;
16138 return reloc_class_copy
;
16140 return reloc_class_normal
;
16144 /* Finish up the dynamic sections. */
16147 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
16148 struct bfd_link_info
*info
)
16150 struct ppc_link_hash_table
*htab
;
16154 htab
= ppc_hash_table (info
);
16158 dynobj
= htab
->elf
.dynobj
;
16159 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
16161 if (htab
->elf
.dynamic_sections_created
)
16163 Elf64_External_Dyn
*dyncon
, *dynconend
;
16165 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
16168 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
16169 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
16170 for (; dyncon
< dynconend
; dyncon
++)
16172 Elf_Internal_Dyn dyn
;
16175 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
16182 case DT_PPC64_GLINK
:
16184 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16185 /* We stupidly defined DT_PPC64_GLINK to be the start
16186 of glink rather than the first entry point, which is
16187 what ld.so needs, and now have a bigger stub to
16188 support automatic multiple TOCs. */
16189 dyn
.d_un
.d_ptr
+= GLINK_PLTRESOLVE_SIZE (htab
) - 8 * 4;
16193 s
= bfd_get_section_by_name (output_bfd
, ".opd");
16196 dyn
.d_un
.d_ptr
= s
->vma
;
16200 if (htab
->do_multi_toc
&& htab
->multi_toc_needed
)
16201 dyn
.d_un
.d_val
|= PPC64_OPT_MULTI_TOC
;
16202 if (htab
->has_plt_localentry0
)
16203 dyn
.d_un
.d_val
|= PPC64_OPT_LOCALENTRY
;
16206 case DT_PPC64_OPDSZ
:
16207 s
= bfd_get_section_by_name (output_bfd
, ".opd");
16210 dyn
.d_un
.d_val
= s
->size
;
16214 s
= htab
->elf
.splt
;
16215 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16219 s
= htab
->elf
.srelplt
;
16220 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
16224 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
16228 if (htab
->local_ifunc_resolver
)
16229 info
->callbacks
->einfo
16230 (_("%X%P: text relocations and GNU indirect "
16231 "functions will result in a segfault at runtime\n"));
16232 else if (htab
->maybe_local_ifunc_resolver
)
16233 info
->callbacks
->einfo
16234 (_("%P: warning: text relocations and GNU indirect "
16235 "functions may result in a segfault at runtime\n"));
16239 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
16243 if (htab
->elf
.sgot
!= NULL
&& htab
->elf
.sgot
->size
!= 0
16244 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
16246 /* Fill in the first entry in the global offset table.
16247 We use it to hold the link-time TOCbase. */
16248 bfd_put_64 (output_bfd
,
16249 elf_gp (output_bfd
) + TOC_BASE_OFF
,
16250 htab
->elf
.sgot
->contents
);
16252 /* Set .got entry size. */
16253 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
16256 if (htab
->elf
.splt
!= NULL
&& htab
->elf
.splt
->size
!= 0
16257 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
16259 /* Set .plt entry size. */
16260 elf_section_data (htab
->elf
.splt
->output_section
)->this_hdr
.sh_entsize
16261 = PLT_ENTRY_SIZE (htab
);
16264 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
16265 brlt ourselves if emitrelocations. */
16266 if (htab
->brlt
!= NULL
16267 && htab
->brlt
->reloc_count
!= 0
16268 && !_bfd_elf_link_output_relocs (output_bfd
,
16270 elf_section_data (htab
->brlt
)->rela
.hdr
,
16271 elf_section_data (htab
->brlt
)->relocs
,
16275 if (htab
->glink
!= NULL
16276 && htab
->glink
->reloc_count
!= 0
16277 && !_bfd_elf_link_output_relocs (output_bfd
,
16279 elf_section_data (htab
->glink
)->rela
.hdr
,
16280 elf_section_data (htab
->glink
)->relocs
,
16284 if (htab
->glink_eh_frame
!= NULL
16285 && htab
->glink_eh_frame
->size
!= 0)
16289 struct map_stub
*group
;
16292 p
= htab
->glink_eh_frame
->contents
;
16293 p
+= (sizeof (glink_eh_frame_cie
) + align
- 1) & -align
;
16295 for (group
= htab
->group
; group
!= NULL
; group
= group
->next
)
16296 if (group
->stub_sec
!= NULL
)
16298 /* Offset to stub section. */
16299 val
= (group
->stub_sec
->output_section
->vma
16300 + group
->stub_sec
->output_offset
);
16301 val
-= (htab
->glink_eh_frame
->output_section
->vma
16302 + htab
->glink_eh_frame
->output_offset
16303 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
16304 if (val
+ 0x80000000 > 0xffffffff)
16307 (_("%s offset too large for .eh_frame sdata4 encoding"),
16308 group
->stub_sec
->name
);
16311 bfd_put_32 (dynobj
, val
, p
+ 8);
16312 p
+= stub_eh_frame_size (group
, align
);
16314 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
16316 /* Offset to .glink. */
16317 val
= (htab
->glink
->output_section
->vma
16318 + htab
->glink
->output_offset
16320 val
-= (htab
->glink_eh_frame
->output_section
->vma
16321 + htab
->glink_eh_frame
->output_offset
16322 + (p
+ 8 - htab
->glink_eh_frame
->contents
));
16323 if (val
+ 0x80000000 > 0xffffffff)
16326 (_("%s offset too large for .eh_frame sdata4 encoding"),
16327 htab
->glink
->name
);
16330 bfd_put_32 (dynobj
, val
, p
+ 8);
16331 p
+= (24 + align
- 1) & -align
;
16334 if (htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
16335 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
16336 htab
->glink_eh_frame
,
16337 htab
->glink_eh_frame
->contents
))
16341 /* We need to handle writing out multiple GOT sections ourselves,
16342 since we didn't add them to DYNOBJ. We know dynobj is the first
16344 while ((dynobj
= dynobj
->link
.next
) != NULL
)
16348 if (!is_ppc64_elf (dynobj
))
16351 s
= ppc64_elf_tdata (dynobj
)->got
;
16354 && s
->output_section
!= bfd_abs_section_ptr
16355 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
16356 s
->contents
, s
->output_offset
,
16359 s
= ppc64_elf_tdata (dynobj
)->relgot
;
16362 && s
->output_section
!= bfd_abs_section_ptr
16363 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
16364 s
->contents
, s
->output_offset
,
16372 #include "elf64-target.h"
16374 /* FreeBSD support */
16376 #undef TARGET_LITTLE_SYM
16377 #undef TARGET_LITTLE_NAME
16379 #undef TARGET_BIG_SYM
16380 #define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
16381 #undef TARGET_BIG_NAME
16382 #define TARGET_BIG_NAME "elf64-powerpc-freebsd"
16385 #define ELF_OSABI ELFOSABI_FREEBSD
16388 #define elf64_bed elf64_powerpc_fbsd_bed
16390 #include "elf64-target.h"